A
A
AcalaSwap
Search
⌃K

SDK

Swap SDK is meant to provide simple interfaces for calculating all parameters needed for token swaps: slippage, price impact, exact supply/target, etc.
Before making any swap there needed to few calls to check liquidity and to calculate some basic parameters to make swaps safer and to avoid malicious operations as front-running or sandwich-attacks.
First, you need to create an instance of either SwapPromise or SwapRx:
const swapPromise = new SwapPromise(api);
After setup arguments of swap:
const acaToken = walletPromise.getToken("ACA");
const ausdToken = walletPromise.getToken("AUSD");
const path = [acaToken, kusdToken] as [Token, Token];
const supplyAmount = new FixedPointNumber(1, acaToken.decimal);
// set slippage 1 %
const slippage = new FixedPointNumber(0.01);
And make calculate parameters with next interface:
const parameters = swapPromise.swap(path: Token[], amount: FixedPointNumber, type: "EXACT_INPUT" | "EXACT_OUTPUT");
type defines whether the swap should be with exact supply or exact target.
You can find the full code sample here: swapWithSDK.ts
Last modified 1yr ago