Anchor-Protocol / anchor-earn

The Earn JavaScript SDK for Anchor Protocol.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

fabricateMarketRedeemStable redeemed amount in aUST and not UST

corymsmith opened this issue · comments

I would expect this to withdraw 0.5 UST and not 0.5 aUST

This was with 1.1.0-alpha.2 and using bombay-12.

This is how I was calling the function:

    address: 'terra1cq8l6fxx5gfs9qde80f2rcp7n0j020zwffrlx0',
    currency: DENOMS.UST,
    amount: '0.5'

And here is the tx:

Screen Shot 2021-09-29 at 10 30 58 AM

It looks like within the withdraw function itself the amount is changed based on the exchange rate here:

withdrawOption.amount = getNaturalDecimals(

But the docs indicate that the amount being passed into that function are denominated in the currency you are specifying.

Hello there, thanks for your report. As far as I understood, you are using message fabricators not anchor-earn itself. But, using the anchor-earn withdraw function will always lead to a withdrawal of less than the amount that you specified (as the doc notes), here is one example
The withdrawal amount here is 0.5.
here is the code for the above example:

const withdraw = await anchorEarn.withdraw({
      amount: '0.5',
      currency: DENOMS.UST,

I think you are using message fabricators that withdraw aUST and the denom there, represent market denomination, not currency. Please instantiate anchor-earn and use withdraw function like the above code snippet.

Yes, we are using fabricators on purpose since we are generating the tx to be serialized and signed elsewhere. We require specifying the UST amount to be withdrawn vs. the aUST amount. The confusing part is that both deposit and withdraw take an amount and currency param but only deposit actually uses that currency for the amount.

If you use anchor-earn for only fabricators, I recommend using anchor.js.
If you want to have your own customSigner or customBroadcaster, anchor-earn supports that.
Besides that, fabricators have nothing to do with this function that you mentioned.

withdrawOption.amount = getNaturalDecimals(

For the confusion, the currency related to fabricators is market currencies, which for now, we have only UST.

My main question is:

How would I specify that I want to withdraw 100 UST for example (knowing that I would get less after fees).
is the only way to calculate the exchangeRate between aUST and UST like anchor-earn is doing here:

withdrawOption.amount = getNaturalDecimals(

yes exactly like that. My point was, fabricateMarketRedeemStable withdraws the amount you specified in aUST denom; if you need to get it in UST denom, you have to calculate it like that function you mentioned.

Thanks for clarifying. My point was that the way the params are documented in the code and the inconsistency between deposit and redeem fabricators made that confusing :)

Thanks for the report, We will reflect that on the document. May I close this issue?