Build liquidity transactions
Create AMMs, add and remove liquidity, and execute authorized graduation.
Create a direct AMM
Reuse the Launch account map with existing mints. Prepare empty vaults and funded source accounts. The base mint must have no mint or freeze authority.
Set PoolInit.amount_a and amount_b to gross deposits. Set minimum_lp to the minimum LP tokens you accept. The program mints floor(sqrt(net_a × net_b)) LP units. A direct pool has no locked LP allocation.
Use an enabled configuration for stored quote mint B. You may omit the council signer only when neither mint is USDC and the configuration has an approved reference pool; otherwise, supply Some(council_address) and obtain that signer. The example shows the non-USDC path. It also requires the fresh user_lp signer from Launch.
Liquidity account map
AddLiquidity and RemoveLiquidity both contain a nested Liquidity group. Read the current global treasury for the action fee. Accrued trade fees remain separate in pool accounting.
The user owns user_a, user_b, and user_lp. Prepare the LP token account before adding liquidity. Unlike a launch, these actions do not initialize it or require its keypair to sign.
Add liquidity
Set amount to exact LP units requested. Set bound_a and bound_b to maximum gross inputs. For a nonempty pool, required net inputs are ceil(reserve × requested_lp / total_lp). total_lp includes both circulating supply and locked_lp. Gross each input up for transfer tax.
If circulating LP supply and locked_lp are both zero while both reserves remain positive, the next deposit first records floor(sqrt(reserve_a × reserve_b)) locked LP units. This preserves the existing reserves after all issued LP tokens were burned externally. Quote the new deposit proportionally against those locked units. A one-sided reserve state is rejected.
For an empty direct pool with both reserves zero, both bounds become exact gross deposits. The requested LP amount must equal the geometric mean of their net amounts. Both net deposits must be positive.
The user signs and pays 0.025 SOL to the global DEX treasury. These amounts use LP atomic units, not displayed LP tokens.
Remove liquidity
Set amount to LP units to burn. Set each bound to its minimum net received amount after transfer tax. The handler calculates floor(reserve × burned_lp / total_lp) for each asset. Both outputs must be positive.
The user signs and pays the same 0.025 SOL action fee. The program burns user LP tokens and transfers the underlying assets. Locked LP units cannot be supplied from a user account. The final holder can withdraw all trading reserves only when locked_lp is zero. A fully withdrawn direct pool can be reseeded under the empty-pool deposit rules.
Rebuild the Liquidity group for each example if your Rust code has moved it into an earlier instruction.
Execute graduation
Require curve status, a funded quote target, sufficient base inventory, and zero circulating LP supply. The operator account must sign and equal the pool’s current distributor. The fee payer also signs the transaction.
The handler keeps real quote reserves, burns excess base, records locked LP units, clears virtual reserves, and changes status to AMM. It does not mint withdrawable founding LP receipts. Re-read state after confirmation.
The builder below uses mint owners and account addresses from the current pool.