Old swap params - V2
These parameters will not be deprecated.
1. Build fast swap transaction
This method will send swaped coins to user directly. Here are three type fast swap params:
BuildFastRouterSwapParamsV2
Required Params
routers
RouterData Object
returned by find router method
slippage
Number
A value between 0 and 1, representing the maximum allowed price slippage as a percentage. A value of 0.01 allows up to 1% price slippage. This parameter is crucial for protecting your assets in a rapidly changing market.
txb
Transaction
The programmable transaction builder.
Optional parameters
partner
String
The partner address. Details about partner can be found here. You can now set the partner directly during client initialization. This parameter will soon be deprecated; please migrate your configuration.
refreshAllCoins
Boolean
If true, retrieves all coin types when setting up the swap; if false, uses the existing coins.
payDeepFeeAmount
Number
The deep amount for pay deep fee in deepbookv3 path. Currently, all pools that charge a swap fee are covered by Cetus.
Example
import { AggregatorClient } from "@cetusprotocol/aggregator-sdk"
import { Transaction } from '@mysten/sui/transactions';
const client = new AggregatorClient({})
const amount = new BN(1000000)
const from = "0x2::sui::SUI"
const target = "0x06864a6f921804860930db6ddbe2e16acdf8504495ea7481637a1c8b9a8fe54b::cetus::CETUS"
const routers = await client.findRouters({
from,
target,
amount,
byAmountIn: true, // `true` means fix input amount, `false` means fix output amount
})
const txb = new Transaction()
await client.fastRouterSwap({
routers,
txb,
slippage: 0.01,
})
2. Build swap transaction and return target coin object
This method will build transaction and return coin objects, used to build ptb.
BuildRouterSwapParamsV2
Required Params
routers
RouterData Object
Returned by find router method
inputCoin
TransactionObjectArgument
This represents the input coin object. If you only support swaps with a fixed input, simply extract a fixed amount from the coin object. If you support fixed output, you need to extract an amount limited by the specified constraints from the coin object.
slippage
Number
A value between 0 and 1, representing the maximum allowed price slippage as a percentage. A value of 0.01 allows up to 1% price slippage. This parameter is crucial for protecting your assets in a rapidly changing market.
txb
Transaction
The programmable transaction builder.
Optional parameters
partner
String
The partner address. Details about partner can be found here. You can now set the partner directly during client initialization. This parameter will soon be deprecated; please migrate your configuration.
refreshAllCoins
Boolean
If true, retrieves all coin types when setting up the swap; if false, uses the existing coins.
deepbookv3DeepFee
TransactionObjectArgument
The deep fee obejct argument for pay deep fee in deepbookv3 path. Currently, all pools that charge a swap fee are covered by Cetus.
Example
import { AggregatorClient } from "@cetusprotocol/aggregator-sdk"
import { Transaction } from '@mysten/sui/transactions';
const client = new AggregatorClient({})
const amount = new BN(1000000)
const from = "0x2::sui::SUI"
const target = "0x06864a6f921804860930db6ddbe2e16acdf8504495ea7481637a1c8b9a8fe54b::cetus::CETUS"
const routers = await client.findRouters({
from,
target,
amount,
byAmountIn: true, // `true` means fix input amount, `false` means fix output amount
})
const txb = new Transaction()
const targetCoin = await client.routerSwap({
routers,
txb,
inputCoin,
slippage: 0.01,
})
// you can use this target coin object argument to build your ptb.
client.transferOrDestoryCoin(
txb,
targetCoin,
target
)
Last updated