You can construct your own swap method using this approach, but it is not a ready-to-use swap method.
In the Cetus CLMM contract, both the flash swap and the repay flash swap functions do not care for slippage. If you integrate these functions into your contract, you must implement your own slippage checks.
Function params (click to open)
config: the reference of clmm globalconfig object. you can see details at
pool : one mutable reference of the pool.
coin_a: mutable coin a object. this type is the same as the coin a of pool.
coin_b: mutable coin b object. this type is the same as the coin b of pool.
a2b: the swap direction, a2b equals true means sold coin a then get coin b.
by_amount_in: when it equal true means want to fix the amount of input coin. when it equal false means want to fix the amount of output coin.
amount: when by_amount_in equals true, amount means the quantity of input coin, when by_amount_in equals false, amount means the quantity of output coin.
amount_limit: the threshold value of coin. when by_amount_in equals true, it means the minimum amount about received coin, when by_amount_in equals false, it means the maximum amount abount sold.
sqrt_price_limit: two constant of sqrt price(x64 fixed-point number). When a2b equals true, it equals 4295048016, when a2b equals false, it equals 79226673515401279992447579055. Just use the default values.
clock: the sui clock object.
You can implement swaps like the following examples. This is divided into two instances: one with a partner and the other without. For a detailed introduction to the Cetus partner, you can refer to cetus partner.
If you just want to call the existing Cetus swap method using a Move call, we can use the swap method of the Cetus aggregator that has already been deployed on the sui mainnet.
This method simplifies the parameters required when calling it to accommodate the most common fixed-input swap scenarios for users. Below are the details of the simplifications:
This example uses a2b; if you want to perform b2a, please use a different method swap_b2a.
Function params (click to open)
pool : one mutable reference of the pool.
partner: cetus partner object.
coin_a: coin a object. this type is the same as the coin b of pool. This method will use all balance of this coin, it you want to swap 1000 a to b, you need to split 1000 a before swap.
coins_a: coins a object vector. this type is the same as the coin a of pool.Future it will be taken as Coin<CoinTypeA> and Coin<CoinTypeB>.
coins_b: coins b object vector. this type is the same as the coin b of pool.
a2b: the swap direction, a2b equals true means sold coin a then get coin b.
by_amount_in: when it equal true means want to fix the amount of input coin. when it equal false means want to fix the amount of output coin.
amount: when by_amount_in equals true, amount means the quantity of input coin, when by_amount_in equals false, amount means the quantity of output coin.
sqrt_price_limit: two constant of sqrt price(x64 fixed-point number). When a2b equals true, it equals 4295048016, when a2b equals false, it equals 79226673515401279992447579055. Just use the default values.
use_coin_value:This parameter determines whether to directly use the input coin value as the amount in. If so (i.e. true), it will ignore the passed-in amount and use the coin value as the amount instead; otherwise, it will use the input amount (i.e. amount of the 'input' coin). This parameter is only effective with fixed input (by_amount_in = true). Of course, this method is designed for our legacy router service, which is why this additional parameter is included.