Swap
Key Parameters Explained
Example
// Get pool information
const pool = await sdk.Pool.getPool(pool_id)
const { coin_type_a, coin_type_b } = pool
// Get swap quote
const quote_obj = await sdk.Swap.preSwapQuote({
pool_id,
a2b: true, // true for A to B, false for B to A
by_amount_in: true, // true for exact input, false for exact output
in_amount: '2000000',
coin_type_a,
coin_type_b
})
// Build and send swap transaction
const tx = sdk.Swap.swapPayload({
coin_type_a,
coin_type_b,
quote_obj,
by_amount_in: true,
slippage: 0.01
})Last updated