API

Extrinsic

add_liquidity

Allow users to add liquidity to a given pool

const firstTokenId = 100;
const secondTokenId = 1001;
const pair = [firstTokenId, secondTokenId];
const desiredLiquidity = ["100","100"];
const minLiquidity = ["100","100"];
const hash = await api.tx.amm.addLiquidity(pair, desiredLiquidity, minLiquidity).signAndSend(currentAccount)

remove_liquidity

Allow users to remove liquidity from a given pool

const firstTokenId = 100;
const secondTokenId = 1001;
const pair = [firstTokenId, secondTokenId];
const hash = await api.tx.amm.removeLiquidity(pair, "100").signAndSend(currentAccount)

swap_exact_tokens_for_tokens

Given input amount is fixed, the output token amount is not known in advance.

const fromTokenId = 100;
const toTokenId = 1001;
const pair = [fromTokenId, toTokenId];
const hash = api.tx.ammRoute.swapExactTokensForTokens(pair,"100","1000").signAndSend(currentAccount)

swap_tokens_for_exact_tokens

Given the output token amount is fixed, the input token amount is not known.

const fromTokenId = 100;
const toTokenId = 1001;
const pair = [fromTokenId, toTokenId];
const hash = api.tx.ammRoute.swapTokensForExactTokens(pair,"100","1000").signAndSend(currentAccount)

Storage

Pools

const baseTokenId = 100;
const quoteTokenId = 0;
const pool = await api.query.amm.pools(baseTokenId, quoteTokenId);

Last updated