Skip to main content

Swap

toJSONString​

You can use this function to convert market object into string.

const sdk = await SDK.initialize(endpoint);

const res = await sdk.models.getAllMarkets();

res.forEach((market) => console.log(market.toJSONString()));

getSpotPrice​

You can use this function to get spot price in the specified block.

const price = await pool.getSpotPrice(AssetIn, AssetOut, blockHash);

Arguments

NameTypeIntroduction
inAssetstring/Asset
outAssetstring/Asset
blockHashanynot necessarily. The unique identifier for the block to fetch asset spot prices.

Code snippet

assetSpotPricesInZtg​

You can use this function to fetch spot prices of all assets in this market. Can be used to find prices at a particular block using unique identifier.

const res = market.assetSpotPricesInZtg(blockHash);

Arguments

NameTypeIntroduction
blockHashanynot necessarily. The unique identifier for the block to fetch asset spot prices.

Code snippet

fetchPoolSpotPrices​

You can use this function to fetch spot prices of specified blocks.

const prices = await pool.fetchPoolSpotPrices(
assetIn,
assetOut,
blocksAsNumArray
);

Arguments

NameTypeIntroduction
inAssetstring/Asset
outAssetstring/Asset
blockNumbersnumber[]The block numbers you want to check

Code snippet

sharesId​

You can use this function to fetch all shares' ids.

const sharesId = await pool.sharesId();

Code snippet

accountId​

You can use this function to fetch account id in this pool.

const account = await pool.getAccountId();

Code snippet

joinPool​

You can use this function to join pool.

const res = await pool.joinPool(signer, poolAmountOut, maxAmountsIn, false);

Arguments

NameTypeIntroduction
signerKeyringPairOrExtSignerThe actual signer provider to sign the transaction.
poolAmountOutstringThe amount of LP shares for this pool that should be minted to the provider.
maxAmountsInstring[]List of asset upper bounds. The values are maximum limit for the assets.
callbackOrPaymentInfoboolean"true" to get txn fee estimation otherwise callback to capture transaction result.

Code snippet

poolJoinWithExactAssetAmount​

You can use this function to join exact asset amount to the pool.

const res = await pool.poolJoinWithExactAssetAmount(
signer,
JSON.parse(assetIn),
assetAmount,
minPoolAmount,
false
);

Arguments

NameTypeIntroduction
signerKeyringPairOrExtSignerThe actual signer provider to sign the transaction.
assetInanyAsset entering the pool.
assetAmountanyAsset amount that is entering the pool.
minPoolAmountanyThe calculated amount for the pool must be equal or greater than the given value.
callbackOrPaymentInfoany"true" to get txn fee estimation otherwise callback to capture transaction result.

Code snippet

joinPoolMultifunc​

You can use this function to join pool. Three substrate join_pool_xxx functions in one

const res = await pool.joinPoolMultifunc(
signer,
{
bounds: trimmedBounds as any,
},
false
);

Arguments

NameTypeIntroduction
signerKeyringPairOrExtSignerThe actual signer provider to sign the transaction.
optspoolJoinOptsTo be provided with asset, bounds.assetAmount, bounds.poolMin for MinPool and with asset, bounds.poolAmount, bounds.AssetMin for MaxAsset and with bounds.poolAmount, bounds.AssetMin for sdk.models.swaps.joinPool.
callbackOrPaymentInfoboolean"true" to get txn fee estimation otherwise callback to capture transaction result.

Code snippet

exitPool​

You can use this function to retrieve a given set of assets from pool to the signer.

const res = await pool.exitPool(signer, poolAmountOut, maxAmountsIn, false);

Arguments

NameTypeIntroduction
signerKeyringPairOrExtSignerThe actual signer provider to sign the transaction.
poolAmountInstringThe amount of LP shares of this pool being burned based on the retrieved assets.
minPoolAmountstring[]List of asset lower bounds. The values are minimum limit for the assets.
callbackOrPaymentInfoboolean"true" to get txn fee estimation otherwise callback to capture transaction result.

Code snippet

swapExactAmountIn​

You can use this function to swap a given assetAmountIn of the assetIn/assetOut pair to pool.

const res = await pool.swapExactAmountIn({
signer,
assetIn,
assetAmountIn,
assetOut,
minAmountOut,
maxPrice,
callbackOrPaymentInfo: false,
});

Object Arguments

NameTypeDescription
signerKeyringPairOrExtSignerThe actual signer provider to sign the transaction
assetInstringAsset entering the pool
assetAmountInstringAmount that will be transferred from the provider to the pool
assetOutstringAsset leaving the pool
minAmountOutstring(optional) Minimum asset amount that can leave the pool
maxPricestring(optional) Market price must be equal or less than the provided value
callbackOrPaymentInfobooleantrue to get txn fee estimation otherwise callback to capture transaction result

Code snippet

swapExactAmountOut​

You can use this function to swap a given assetAmountOut of the assetIn/assetOut pair to pool.

const res = await pool.swapExactAmountOut({
signer,
assetIn,
maxAmountIn,
assetOut,
assetAmountOut,
maxPrice,
callbackOrPaymentInfo: false,
});

Object Arguments

NameTypeIntroduction
signerKeyringPairOrExtSignerThe actual signer provider to sign the transaction
assetInstringAsset entering the pool
maxAmountInstring(optional) Maximum asset amount that can enter the pool
assetOutstringAsset leaving the pool
assetAmountOutstringAmount that will be transferred from the pool to the provider
maxPricestring(optional) Market price must be equal or less than the provided value
callbackOrPaymentInfobooleantrue to get txn fee estimation otherwise callback to capture transaction result

Code snippet