0

In quipuswap dex v2, when we call invest_liquidity, there is parameter called shares. I want to know how to calculate those shares.

I know that there is view in contract called get_toks_per_share but it gives 2 values token_a_amt and token_b_amt.

If this values are used to calculate shares then is there any formula to calculate the shares using this?

1 Answer 1

0

Let's say you have an amount_a of the token a and amount_b of token b, you want to invest.

  1. Call the view get_total_supply to get the current supply of shares.
  2. Call the view to get the reserves get_reserves, you will receive reserves_a anount of token a and reserves_b of token b in the pool .
  3. Then calculate the shares required:
    shares_a = amount_a * total_supply / reserves_a
    shares_b = amount_b * total_supply / reserves_b

Then calculate min (shares_a, shares_b) and it will be the answer.

But note: if shares_a =/= shares_b, then the smaller amount of one of the tokens will be used. if shares_a > shares_b, then smaller amount of token a will be invested than you wanted and versa versa.

Your Answer

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