For the complete documentation index, see llms.txt. This page is also available as Markdown.
Preswap
Before do really swap, you need can do per swap to get the swap result. Then you can set amount limt by swap result and slippage.
This text describes two primary methods for performing a swap function, each with distinct steps and calculation methods. The first method involves initially obtaining tick data, followed by performing calculations locally. The second method involves conducting a simulated swap and then obtaining the resultant data through an event on Sui.
There are three pre-calculation strategies for executing a swap:
Local Calculate
local calculate swap result: use sdk.Swap.calculateRates()
Simulate swap then get result
only calculate one pool swap result: use sdk.Swap.preswap().
calculate multi pool at the same time, use sdk.Swap.preSwapWithMultiPool(). It will select one best pool to do swap.
Local calculate swap result
This method need to get ticks data and pool object first.
use sdk.Swap.calculateRates method.
Function input param
Please refer to the original function for specific parameter types.
params: CalculateRatesParams object.
decimalsA: the decimal of coinA.
decimalsB: the decimal of coinB.
a2b: swap direction, true means swap from coinA to coinB, false means swap from coinB to CoinA.
byAmountIn: true means fixed the amount of input, false means fixed the amount of output.
amount: the amount of input (byAmountIn = true) or output (byAmountIn = false).