0

I'm working on building an interface for liquidity baking and am encountering the error: Error during estimation when I submit the calculations for the swap tokenToXtz or xtzToToken on the swap function.

After trying to use both https://tezostaquito.io/docs/next/liquidity_baking/ and https://gitlab.com/camlcase-dev/dexter-calculations/-/tree/2a5b30e5edc00b6f4faa17fdae8590bfad428649/ along with random other resources I have found online, I'm not getting anywhere.

Anyone encounter this issue / know where there is a detailed guide to interacting with the liquidity baking contract?

I'm using v13.0.0 of taquito.

Example:

Using the current storage data for the LB dex contract with the https://github.com/kukai-wallet/kukai-dex-calculations and Kukai's implementation of it in their wallet, here is what I am getting:

Storage used: xtz_pool: 5535658327002 token_pool: 41689853021 xtz_in: 1000000

Returns:

minsTokenBought: 7478

And then when calling the xtzToToken entrypoint on the contract, I get:

Raw:

[
    {
      destination: 'KT1TxqZ8QtKvLu3V3JH7Gx58n7Co8pgtpQU5',
      kind: 'transaction',
      amount: 0,
      parameters: {
        entrypoint: 'xtzToToken',
        value: {
          prim: 'Pair',
          args: [
            { string: 'tz1ezDb77a9jaFMHDWs8QXrKEDkpgGdgsjPD' },
            { prim: 'Pair', args: [{ int: '7478' }, { string: '2022-09-14T12:34:57.270Z' }] },
          ],
        },
      },
    },
  ]

Error Warning Received:

{
error: [
  {
    errors: [
      {
        kind: 'temporary',
        id: 'proto.013-PtJakart.michelson_v1.runtime_error',
        contract_handle: 'KT1TxqZ8QtKvLu3V3JH7Gx58n7Co8pgtpQU5',
        contract_code: 'Deprecated',
      },
      {
        kind: 'temporary',
        id: 'proto.013-PtJakart.michelson_v1.script_rejected',
        location: 1492,
        with: { int: '18' },
      },
    ],
    errorDetails: 'Error occurred during estimation',
    name: 'TezosOperationError',
    id: 'proto.013-PtJakart.michelson_v1.script_rejected',
    kind: 'temporary',
    message: '18',
    isError: true,
  },
  {
    errors: [
      {
        kind: 'temporary',
        id: 'proto.013-PtJakart.michelson_v1.runtime_error',
        contract_handle: 'KT1TxqZ8QtKvLu3V3JH7Gx58n7Co8pgtpQU5',
        contract_code: 'Deprecated',
      },
      {
        kind: 'temporary',
        id: 'proto.013-PtJakart.michelson_v1.script_rejected',
        location: 1492,
        with: { int: '18' },
      },
    ],
    errorDetails: 'Error occurred during estimation',
    name: 'TezosOperationError',
    id: 'proto.013-PtJakart.michelson_v1.script_rejected',
    kind: 'temporary',
    message: '18',
    isError: true,
  },
],

}

Thanks in advance!

1
  • If any answer solves your issue, don't forget to mark it as "top answer" in order to close the question. If none have, please add more comments to the answer / details to your question
    – Simon McLoughlin
    Sep 19, 2022 at 9:38

1 Answer 1

1

The Dexter calculations are out of date for the Liquidity baking contract, as the calculations don't take into account the new subsidy. It was forked by the liquidity baking team, and I forked that again to fix a bug and make it work for either LB or Quipuswap calculations. You can use this one instead: https://github.com/kukai-wallet/kukai-dex-calculations

Updated based on code sample:

So it looks like you are running the right code. Where are you getting the storage values of the pools though? and how fresh are they when you inject that operation? When using the minimum slippage they need to be fetched, calculated and injected as soon as possible. Most UI's will auto refresh while the screen is open

Also worth noting that users can still sometimes receive such an error if someone else gets a transaction ahead of them. Users are frequently given slippage controls in a UI and encouraged to increase it to 1% or 2% to increase the likelihood of it going through, if they encounter such errors

I've done another test and you can see from the inbuilt Dex in TzKT that the calculation code is producing the same value that they display.

Compare yours to TzKT (or Kukai) and try doubling the slippage

enter image description here enter image description here

5
  • So I tried these ones also along with Claude's forked version as well which he updated for taquito: github.com/claudebarde/kukai-dex-calculations This is the one I'm currently using.
    – Sam Morrow
    Sep 13, 2022 at 12:49
  • @SamMorrow yes claude contacted me about migrating it from using the BigIntegar library to using BigNumber. Told him ill accept such a PR if he builds it, eventually he'll merge that one into mine when its done. The current one I pointed to is actively being used in the kukai web app and is working as expected. If you have used these, then its not the libraries. Post a lot more details about the transaction you tried to send
    – Simon McLoughlin
    Sep 13, 2022 at 12:59
  • Added an example to the question
    – Sam Morrow
    Sep 14, 2022 at 11:45
  • @SamMorrow edited my answer
    – Simon McLoughlin
    Sep 14, 2022 at 14:25
  • Thanks so much! The storage values are taken from how the Kukai wallet does it, the tzkt api. I didn't implement the refresh/update so that's probably the issue
    – Sam Morrow
    Sep 15, 2022 at 9:30

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.