0

I'm trying to call addLiquidity on the Liquidity Baking CPMM. I've already called xtzToToken on the CPMM and given my address tzBTC. I can see that my address has tokens on the tzBTC contract when I look at that contracts storage. The CPMM tells me I have 300000004 tokens I believe.

My address also has allowances declared on the tzBTC contract that allow the CPMM to spend it's tokens., the allowance is only 10 and when I try to chance it I get an UnsafeAllowanceChange error.

I want to make my allowance something super high that I don't have to worry about reaching the allowance when I call addLiquidity. How can I get past this error?

Here is what I'm trying to run:

# call approve on the tzBTC contract
tezos-client transfer 0 from alice to KT1VqarPDicMFn1ejmQqqshUkUXTCTXwmkCN \
                        --entrypoint approve \
                        --arg '(Pair "KT1VqarPDicMFn1ejmQqqshUkUXTCTXwmkCN" 99954268)'  \
                        --burn-cap 999 
2

the allowance is only 10 and when I try to chance it I get an UnsafeAllowanceChange error.

This error is raised because the allowance is already 10, from the UnsafeAllowanceChange documentation:

Fires if: Allowance change from non-zero value to non-zero value is performed. This contract does not allow such an update, see the corresponding attack vector for explanation.

See the section #3 of the linked document for an example/scenario explanation.

I want to make my allowance something super high that I don't have to worry about reaching the allowance when I call addLiquidity. How can I get past this error?

The approve documentation explains why it's prohibited and how to perform this change safely:

It is not safe to change the approval from a non-zero value to a non-zero value. This is the reason why performing such a change directly is not allowed by the contract. However this is not enough on its own, a token holder that intends to safely change the allowance for X to K token must:

  1. read the current allowance M for X from the latest transaction S.
  2. send a transaction T that sets the allowance to 0.
  3. wait for the blockchain to confirm that T is included.
  4. scan all transactions between S and T.
  5. calculate the allowance N <= M spent by X in those transactions.
  6. set the allowance to K - N iff N < K.

In other words, the allowance needs to be set from 10 to 0 first and then from 0 to the new value, accounting for allowance uses that may have happened in the meanwhile.

2
  • 1
    Thank you for linking to the official docs. I tried reading three Michaelson and the docs of the CPMM and couldn't find it, I didn't even realize it could be passed back from the tzBTC contact.
    – Whirlybird
    Jul 28 at 9:30
  • No problem, I see how that could be confusing.
    – P. Pinto
    Jul 29 at 10:28

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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