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
Name | Type | Introduction |
---|---|---|
inAsset | string/Asset | |
outAsset | string/Asset | |
blockHash | any | not necessarily. The unique identifier for the block to fetch asset spot prices. |
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
Name | Type | Introduction |
---|---|---|
blockHash | any | not necessarily. The unique identifier for the block to fetch asset spot prices. |
fetchPoolSpotPrices
You can use this function to fetch spot prices of specified blocks.
const prices = await pool.fetchPoolSpotPrices(
assetIn,
assetOut,
blocksAsNumArray
);
Arguments
Name | Type | Introduction |
---|---|---|
inAsset | string/Asset | |
outAsset | string/Asset | |
blockNumbers | number[] | The block numbers you want to check |
sharesId
You can use this function to fetch all shares' ids.
const sharesId = await pool.sharesId();
accountId
You can use this function to fetch account id in this pool.
const account = await pool.accountId();
joinPool
You can use this function to join pool.
const res = await pool.joinPool(signer, poolAmountOut, maxAmountsIn, false);
Arguments
Name | Type | Introduction |
---|---|---|
signer | KeyringPairOrExtSigner | The actual signer provider to sign the transaction. |
poolAmountOut | string | The amount of LP shares for this pool that should be minted to the provider. |
maxAmountsIn | string[] | List of asset upper bounds. The values are maximum limit for the assets. |
callbackOrPaymentInfo | boolean | "true" to get txn fee estimation otherwise callback to capture transaction result. |
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
Name | Type | Introduction |
---|---|---|
signer | KeyringPairOrExtSigner | The actual signer provider to sign the transaction. |
assetIn | any | Asset entering the pool. |
assetAmount | any | Asset amount that is entering the pool. |
minPoolAmount | any | The calculated amount for the pool must be equal or greater than the given value. |
callbackOrPaymentInfo | any | "true" to get txn fee estimation otherwise callback to capture transaction result. |
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
Name | Type | Introduction |
---|---|---|
signer | KeyringPairOrExtSigner | The actual signer provider to sign the transaction. |
opts | poolJoinOpts | To 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 . |
callbackOrPaymentInfo | boolean | "true" to get txn fee estimation otherwise callback to capture transaction result. |
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
Name | Type | Introduction |
---|---|---|
signer | KeyringPairOrExtSigner | The actual signer provider to sign the transaction. |
poolAmountIn | string | The amount of LP shares of this pool being burned based on the retrieved assets. |
minPoolAmount | string[] | List of asset lower bounds. The values are minimum limit for the assets. |
callbackOrPaymentInfo | boolean | "true" to get txn fee estimation otherwise callback to capture transaction result. |
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
Name | Type | Description |
---|---|---|
signer | KeyringPairOrExtSigner | The actual signer provider to sign the transaction |
assetIn | string | Asset entering the pool |
assetAmountIn | string | Amount that will be transferred from the provider to the pool |
assetOut | string | Asset leaving the pool |
minAmountOut | string | (optional) Minimum asset amount that can leave the pool |
maxPrice | string | (optional) Market price must be equal or less than the provided value |
callbackOrPaymentInfo | boolean | true to get txn fee estimation otherwise callback to capture transaction result |
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
Name | Type | Introduction |
---|---|---|
signer | KeyringPairOrExtSigner | The actual signer provider to sign the transaction |
assetIn | string | Asset entering the pool |
maxAmountIn | string | (optional) Maximum asset amount that can enter the pool |
assetOut | string | Asset leaving the pool |
assetAmountOut | string | Amount that will be transferred from the pool to the provider |
maxPrice | string | (optional) Market price must be equal or less than the provided value |
callbackOrPaymentInfo | boolean | true to get txn fee estimation otherwise callback to capture transaction result |