For the complete documentation index, see llms.txt. This page is also available as Markdown.

LP Interactions

Note

Pick one before you deposit:

  • sFLP (staked LP)addLiquidityAndStake mints LP and stakes it in one tx. Pool fees accrue as a claimable USDC balance you collect via collectStakeFees. Unstaking goes through unstakeInstant + withdrawStake before the underlying tokens can be returned.

  • FLP (compounding LP)addCompoundingLiquidity mints a rebasing SPL token whose price grows as fees accrue. Burn it with removeCompoundingLiquidity. No manual claim step.

Unless you specifically want manual control over rewards, prefer FLP.

Liquidity is pool-scoped — each pool has its own sFLP / FLP mints and its own custodies. The examples below use a single POOL_CONFIG (e.g. PoolConfig.fromIdsByName('Crypto.1', 'mainnet-beta')). Set this up the same way as the Flash SDK landing page, but pick one pool instead of loading the full POOL_CONFIGS array.

Creating LP Transactions

Add Liquidity / Mint sFLP

const addLiquidityAndStake = async () => {
    const usdcInputAmount = new BN(1_000_000); // $1

    // this can be any other token available in the pool, for instance SOL, BTC and ETH
    const usdcCustody = POOL_CONFIG.custodies.find(c => c.symbol === 'USDC')!;
    const slippageBps: number = 800 // 0.8%
    let instructions: TransactionInstruction[] = []
    let additionalSigners: Signer[] = []

    await flashClient.loadAddressLookupTable(POOL_CONFIG)

    // flash-sdk version >= 2.31.6
    const { amount: minLpAmountOut, fee } = await flashClient.getAddLiquidityAmountAndFeeView(
        usdcInputAmount, POOL_CONFIG.poolAddress, usdcCustody.custodyAccount, POOL_CONFIG,
    );

    const minLpAmountOutAfterSlippage = minLpAmountOut
        .mul(new BN(10 ** BPS_DECIMALS - slippageBps))
        .div(new BN(10 ** BPS_DECIMALS))

    const setCULimitIx = ComputeBudgetProgram.setComputeUnitLimit({ units: 400_000 })

    const addLiquidityAndStakeData = await flashClient.addLiquidityAndStake(
        'USDC', usdcInputAmount, minLpAmountOutAfterSlippage, POOL_CONFIG,
    );
    instructions.push(...addLiquidityAndStakeData.instructions)
    additionalSigners.push(...addLiquidityAndStakeData.additionalSigners)

    const flpStakeAccountPK = PublicKey.findProgramAddressSync(
        [Buffer.from('stake'), flashClient.provider.publicKey.toBuffer(), POOL_CONFIG.poolAddress.toBuffer()],
        POOL_CONFIG.programId,
    )[0]

    const refreshStakeInstruction = await flashClient.refreshStake('USDC', POOL_CONFIG, [flpStakeAccountPK])
    instructions.push(refreshStakeInstruction)

    const trxId = await flashClient.sendTransaction([setCULimitIx, ...instructions])
    console.log('addLiquidityAndStake trx :>> ', trxId);
}

Add Compounding Liquidity / Mint FLP

Remove Liquidity / Burn sFLP

Collect sFLP stake fees

sFLP holders accrue USDC rewards in their stake account. Use collectStakeFees to sweep them to your USDC ATA. (FLP holders don't need this — fees auto-compound into the token's price.)

Remove Compounding Liquidity / Burn FLP

Update FLP/sFLP Price

Composing Program Calls for Add/Remove Liquidity

Solana transaction instructions have strict size limits, and current runtime constraints prevent using Address Lookup Tables (LUTs) within inner instructions. To work around this, split the Add/Remove Liquidity flow into two separate instruction sequences that execute in order.

Overview

  1. Prepare LP Token Price

    • Use the setLpTokenPrice instruction to update or initialise the price data for your pool's LP token.

    • This instruction must run before any liquidity operations that depend on the latest price.

    • Example: refer to the Update FLP/sFLP Price section above.

  2. Add or Remove Liquidity

    • Invoke the AddLiquidityAndStake, AddCompoundingLiquidity, RemoveLiquidity, or RemoveCompoundingLiquidity instruction after the LP token price instruction.

    • By separating the price-setting logic, you avoid passing large lists of remaining accounts in a single instruction, keeping each instruction well under the size limit.

Example: Add Compounding Liquidity instruction without passing any remaining accounts:

Get FLP/sFLP token prices

1) Using SDK (Advanced Integration)

2) Using API (Quick & Easy)

Query the following endpoint to get price data for all pools:

The response is a JSON object containing an array of pools, each representing a unique FLP pool.

Last updated

Was this helpful?