Add Liquidity
Adds liquidity to an existing pair and receives LP tokens in return.
Accounts
The pair account. PDA derived from [PAIR_SEED_PREFIX, token0, token1, params_hash].
user_token0_account
InterfaceAccount<TokenAccount>
required
User’s token0 account. Must have sufficient balance for amount0_in.
user_token1_account
InterfaceAccount<TokenAccount>
required
User’s token1 account. Must have sufficient balance for amount1_in.
user_lp_token_account
InterfaceAccount<TokenAccount>
required
User’s LP token account. Will receive minted LP tokens.
The user adding liquidity. Must be a signer.
Arguments
Amount of token0 to deposit. Must be greater than 0.
Amount of token1 to deposit. Must be greater than 0.
Minimum LP tokens to receive. Used for slippage protection.
use anchor_lang::prelude::*;
use omnipair::program::Omnipair;
let add_liquidity_args = AddLiquidityArgs {
amount0_in: 100 * 10u64.pow(token0_decimals),
amount1_in: 200 * 10u64.pow(token1_decimals),
min_liquidity_out: 0,
};
let accounts = AdjustLiquidity {
pair: pair_pda,
user_token0_account: user_token0_account,
user_token1_account: user_token1_account,
user_lp_token_account: user_lp_token_account,
user: user.key(),
// ... other accounts
};
let ctx = CpiContext::new(program_id, accounts);
omnipair::cpi::add_liquidity(ctx, add_liquidity_args)?;
{
"signature": "5VERv8NMvzbJMEkV8xnrLkEaWRtSz9CosKDYjCJjBRnbJLgp8uirBgmG5Rk88jH2k9f4w3JHFf7Pjsk3bWqeXrC",
"slot": 123456789
}