Documentation IndexFetch the complete documentation index at: /llms.txtUse this file to discover all available pages before exploring further.
Fetch the complete documentation index at: /llms.txt
Use this file to discover all available pages before exploring further.
Créer une paire, ajouter une liquidité équilibrée, suivre votre part et retirer.
const exists = await powfi.cpmm.poolExists(alph, usdt) if (!exists) { // preview: LP minted = sqrt(a*b) - 1000 const preview = CpmmModule.computeLiquidityAmounts({ tokenAId: alph, tokenBId: usdt, amountA: 1_000n * 10n ** 18n, amountB: 50n * 10n ** 6n }) const { poolId, result } = await powfi.cpmm.createPool({ tokenAId: alph, tokenBId: usdt, sender: address, initialLiquidity: { tokenAAmount: preview.amountA, tokenBAmount: preview.amountB } }) }
const pool = await powfi.cpmm.getPoolState(alph, usdt) const q = CpmmModule.computeLiquidityAmounts({ poolState: pool, tokenAId: alph, tokenBId: usdt, amountA: 200n * 10n ** 18n, inputType: 'TokenA' }) // q.amountB -> USDT needed // q.shareAmount -> LP tokens you'll receive // q.sharePercentage -> your % of the pool after deposit await powfi.cpmm.addLiquidity({ poolState: pool, tokenAId: alph, tokenBId: usdt, amountA: q.amountA, amountB: q.amountB, slippageBps: 50n, sender: address })
const lpTokenId = powfi.cpmm.getPoolId(alph, usdt) const bal = await powfi.nodeProvider.addresses.getAddressesAddressBalance(address) const lpBalance = BigInt(bal.tokenBalances?.find((t) => t.id === lpTokenId)?.amount ?? '0') const { token0, amount0, token1, amount1 } = await powfi.cpmm.computeClaimableAmounts(alph, usdt, lpBalance)
const pool = await powfi.cpmm.getPoolState(alph, usdt) const burn = lpBalance / 2n // withdraw 50% const preview = CpmmModule.computeRemoveLiquidityAmounts(pool, lpBalance, burn) // preview.amount0 / amount1 -> tokens you receive // preview.remainSharePercentage await powfi.cpmm.removeLiquidity({ poolState: pool, liquidity: burn, totalLiquidityAmount: lpBalance, slippageBps: 50n, sender: address })