API Reference

Get Token Amounts from Position ID

You can use the getCoinAmountsFromPositionID() function to calculate the token amounts for a given position at the current point in time

Example

import { QueryChain } from "@firefly-exchange/library-sui/dist/src/spot"; import { SuiClient } from "@firefly-exchange/library-sui"; import { TickMath, ClmmPoolUtil } from "@firefly-exchange/library-sui/dist/src/spot/clmm"; import { BN } from "bn.js"; const client = new SuiClient({ url: "https://fullnode.mainnet.sui.io:443" }); async function getCoinAmountsFromPositionID(posID: string){ let qc = new QueryChain(client); let pos = await qc.getPositionDetails(posID) let pool = await qc.getPool(pos.pool_id); let lowerSqrtPrice = TickMath.tickIndexToSqrtPriceX64(pos.lower_tick) let upperSqrtPrice = TickMath.tickIndexToSqrtPriceX64(pos.upper_tick) const coinAmounts = ClmmPoolUtil.getCoinAmountFromLiquidity(new BN(pos.liquidity),new BN (pool.current_sqrt_price), lowerSqrtPrice, upperSqrtPrice, false) return { coinAAmount: coinAmounts.coinA.toString(), coinBAmount: coinAmounts.coinB.toString() }; } getCoinAmountsFromPositionID(args[0]) .then((resp) => console.log(JSON.stringify(resp))) .catch((err) => console.error("Error:", err));

Response