add_liquidity
Deposit base and quote into a constant-product pool and mint LP tokens representing proportional ownership of pool reserves.
Supports first liquidity (pool creation path) and subsequent adds (must be proportional to current reserves). Emits a LiquidityAddedEvent for indexers/analytics.
Arguments
pub struct AddLiquidityArgs {
pub base_amount: u64, // user intends to deposit (base)
pub quote_amount: u64, // user intends to deposit (quote)
pub min_base_amount: u64, // post-slippage minimum actually deposited (base)
pub min_quote_amount: u64, // post-slippage minimum actually deposited (quote)
}Semantics
On initialization (first liquidity): deposits set the initial reserves and define the starting price
quote/base.On subsequent adds: deposits must respect the current price to keep
x·y=kinvariant; the program will clamp to proportional amounts and ensure>= min_*bounds.
Required Accounts
0
config
["global_config"] (PDA)
1
payer
✅
2
base_mint
Owner == SPL Token program
3
quote_mint
Owner == SPL Token program
4
curve_pool
["pool", base_mint] under TRADERSDEX_CURVE_PROGRAM, seeds::program = TRADERSDEX_CURVE_PROGRAM
5
pool
✅
init_if_needed; ["pool", base_mint, quote_mint] (PDA)
6
lp_mint
✅
init_if_needed; ["lp_mint", pool] (PDA); mint::authority = pool
7
base_vault
✅
init_if_needed; ["vault", pool, base_mint]; token::authority = pool
8
quote_vault
✅
init_if_needed; ["vault", pool, quote_mint]; token::authority = pool
9
user_base_account
✅
mint == base_mint, owner == payer
10
user_quote_account
✅
mint == quote_mint, owner == payer
11
user_lp_account
ATA created/verified in handler
12
token_program
Must equal SPL Token program ID
13
associated_token_program
14
system_program
15
launchpad_cap
If required: ["launchpad_cap"] under TRADERSDEX_CURVE_PROGRAM and must be signer
16
token_creator
Validated if needed
Event
#[event]
pub struct LiquidityAddedEvent {
pub pool: Pubkey,
pub provider: Pubkey,
pub base_amount: u64,
pub quote_amount: u64,
pub lp_tokens_minted: u64,
pub total_lp_supply: u64,
pub base_reserve_after: u64,
pub quote_reserve_after: u64,
pub is_initial: bool,
pub timestamp: i64,
}Emitted after successful add; indexers can use it to track LP behavior and TVL changes.
Last updated