# Pools and liquidity Read this file for pool queries, creation, ticks, and position liquidity changes. ## Query pools ```typescript import type { Pool } from 'turbos-clmm-sdk'; const unlocked: Pool.Pool[] = await sdk.pool.getPools(); const all: Pool.Pool[] = await sdk.pool.getPools(true); const pool = await sdk.pool.getPool(poolId); const [coinTypeA, coinTypeB, feeType] = await sdk.pool.getPoolTypeArguments(poolId); const ticks = await sdk.pool.fetchTicks(poolId); ``` In v4, parsed pool fields are direct BCS values. For example, the current tick is: ```typescript const tickIndex = sdk.math.bitsToNumber(pool.tick_current_index.bits); ``` Do not add old `.fields.bits` access. ## Create a pool ```typescript const fee = await sdk.contract.getFee(60); const tx = await sdk.pool.createPool({ fee, coinTypeA: '0x2::sui::SUI', coinTypeB, sqrtPrice: initialSqrtPriceX64, address: walletAddress, amountA: '1000000000', amountB: '1000000', tickLower, tickUpper, slippage: '1', }); ``` `fee` must come from `sdk.contract.getFee()` or `getFees()`. Validate `tickLower < tickUpper` and align both values to the fee tier's tick spacing. ## Estimate paired amounts ```typescript const [amountA, amountB] = sdk.pool.estimateAmountsFromOneAmount({ sqrtPrice: pool.sqrt_price, tickLower, tickUpper, amount: '1000000000', isAmountA: true, }); ``` The values are raw token units. They are estimates for transaction construction, not a fiat valuation. ## Open and increase a position ```typescript const openTx = await sdk.pool.addLiquidity({ pool: poolId, address: walletAddress, amountA, amountB, tickLower, tickUpper, slippage: '1', }); const increaseTx = await sdk.pool.increaseLiquidity({ pool: poolId, nft: positionNftId, address: walletAddress, amountA, amountB, slippage: '1', }); ``` Both methods accept an optional existing `txb` and optional `coinAObjectArguments` / `coinBObjectArguments` for programmable transaction composition. Prefer those explicit composition hooks when the caller already controls coin objects. ## Decrease or remove liquidity ```typescript const tx = await sdk.pool.decreaseLiquidity({ pool: poolId, nft: positionNftId, address: walletAddress, amountA: expectedAmountA, amountB: expectedAmountB, decreaseLiquidity: liquidityToRemove, slippage: '1', }); ``` For a full close that also collects fees and rewards and burns the NFT: ```typescript const tx = await sdk.pool.removeLiquidity({ pool: poolId, nft: positionNftId, address: walletAddress, amountA: expectedAmountA, amountB: expectedAmountB, decreaseLiquidity: allLiquidity, slippage: '1', collectAmountA, collectAmountB, rewardAmounts, }); ``` Use `decreaseLiquidityWithReturn` or `removeLiquidityWithReturn` when later commands in the same programmable transaction need the returned coin objects. ## Collect without closing ```typescript const feeTx = await sdk.pool.collectFee({ pool: poolId, nft: positionNftId, address: walletAddress, collectAmountA, collectAmountB, }); const rewardTx = await sdk.pool.collectReward({ pool: poolId, nft: positionNftId, address: walletAddress, rewardAmounts, }); ``` Quote current owed amounts immediately before constructing collection or removal transactions. Do not guess reward-array length or amounts; derive them from the pool and position state. ## Liquidity math ```typescript import { BN } from 'turbos-clmm-sdk'; const [rawA, rawB] = sdk.pool.getTokenAmountsFromLiquidity({ currentSqrtPrice: new BN(pool.sqrt_price), lowerSqrtPrice: sdk.math.tickIndexToSqrtPriceX64(tickLower), upperSqrtPrice: sdk.math.tickIndexToSqrtPriceX64(tickUpper), liquidity: new BN(position.liquidity), ceil: true, }); ```