Calculate Swap Output
Prerequisites
Basic Output Calculation
// Calculate output for a swap
const result = sdk.Swap.calculateRates(pair, {
amount: bigint,
swapBins: LbPairBinData[],
xtoy: boolean,
});Example
async function estimateSwap() {
const pair = await sdk.Pair.getPair(pairId);
const bins = await sdk.Pair.getPairBinsData(pairId);
const decimals = a2b ? coinA.decimals : coinB.decimals;
const parsedAmount = parseUnits(amount.toString(), decimals);
const result = sdk.Swap.calculateRates(pair, {
amount: parsedAmount,
swapBins: bins,
xtoy: a2b,
});
}Name
Type
Description
Property
Type
Description
Important Notes
Related Topics
Last updated