anchor-earn icon indicating copy to clipboard operation
anchor-earn copied to clipboard

fabricateMarketRedeemStable redeemed amount in aUST and not UST

Open corymsmith opened this issue 3 years ago • 8 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:

fabricateMarketRedeemStable({
    address: 'terra1cq8l6fxx5gfs9qde80f2rcp7n0j020zwffrlx0',
    currency: DENOMS.UST,
    amount: '0.5'
})(addressProvider);

And here is the tx: https://finder.terra.money/bombay-12/address/terra1cq8l6fxx5gfs9qde80f2rcp7n0j020zwffrlx0

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

corymsmith avatar Sep 29 '21 16:09 corymsmith

It looks like within the withdraw function itself the amount is changed based on the exchange rate here: https://github.com/Anchor-Protocol/anchor-earn/blob/cfddf82475ddd90323ce8770c2cf7f9dc3577843/src/facade/terra-anchor-earn.ts#L275

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

corymsmith avatar Sep 29 '21 17:09 corymsmith

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 https://finder.terra.money/bombay-12/tx/79236004282349B59A74B047E77454C8008DA29B38384C1990EF35B3F613E5A5. 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.

MSNTCS avatar Sep 30 '21 02:09 MSNTCS

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.

corymsmith avatar Sep 30 '21 02:09 corymsmith

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. https://github.com/Anchor-Protocol/anchor-earn/blob/cfddf82475ddd90323ce8770c2cf7f9dc3577843/src/facade/terra-anchor-earn.ts#L275

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

MSNTCS avatar Sep 30 '21 02:09 MSNTCS

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: https://github.com/Anchor-Protocol/anchor-earn/blob/cfddf82475ddd90323ce8770c2cf7f9dc3577843/src/facade/terra-anchor-earn.ts#L275

corymsmith avatar Sep 30 '21 02:09 corymsmith

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.

MSNTCS avatar Sep 30 '21 03:09 MSNTCS

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 :)

corymsmith avatar Sep 30 '21 03:09 corymsmith

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

MSNTCS avatar Sep 30 '21 03:09 MSNTCS