osmosis-labs / osmojs

OsmosJS makes it easy to compose and broadcast Osmosis and Cosmos messages
https://cosmology.zone/products/osmojs
Apache License 2.0
63 stars 32 forks source link

calculated amount is lesser than min amount if multihop #27

Closed WaDadidou closed 1 year ago

WaDadidou commented 1 year ago

Hi, I try to do a Swap by making a correct MsgSwapExactAmountIn, then using swapExactAmountIn, imported with const { swapExactAmountIn } = osmosis.gamm.v1beta1.MessageComposer.withTypeUrl.

MsgSwapExactAmountIn requires a parameter tokenOutMinAmount. I suppose this is the amount with slippage, as mentionned here : https://www.npmjs.com/package/@cosmology/core : const tokenOutMinAmount = calculateAmountWithSlippage( buy.amount, slippage );

So, I send a tokenIn.amount "171925", and a tokenOutMinAmount "163329" (Slippage 5%). BUT I got the error : "failed to execute message; message index: 0: ibc/27394FB092D2ECCD56123C74F36E4C1F926001CEADA9CA97EA622B25F41E5EB2 token is lesser than min amount: calculated amount is lesser than min amount". (Same if I set slippage like 90%)

My tokenIn is TORI, and my tokenOut is ATOM. So I use multihop pattern ti display the correct data to the user. The 2 correct pools are used, the fee are correctly calculated. I just have some difference token dust regarding https://frontier.osmosis.zone/. But it's likely the same expected amounts.

Independently of the point just above, I hope the SwapAmountInRoute[] given to my MsgSwapExactAmountIn are found correctly. I make SwapAmountInRoute[] with lookupRoutesForTrade, using a Trade made from my two currencies and two amounts.

No issue with direct route like OSMO->ATOM.

Why ?

Here is MsgSwapExactAmountIn : https://github.com/osmosis-labs/osmojs/blob/main/packages/osmojs/src/codegen/osmosis/gamm/v1beta1/tx.ts#L68 Here is swapExactAmountIn : https://github.com/osmosis-labs/osmojs/blob/main/packages/osmojs/types/codegen/osmosis/bundle.d.ts#L188 Here is lookupRoutesForTrade : https://github.com/cosmology-tech/cosmology/blob/main/packages/core/src/utils/osmo/utils.ts#L725 Here is Trade : https://github.com/cosmology-tech/cosmology/blob/main/packages/core/src/types.ts#L140

Wdyt ? Thank you for your repo and your time.