Deposit
Adds liquidity to a pool on the CoolDEX.
Instruction
Parameters
max_coin_amount
u64
Maximum amount of coin token to deposit
max_pc_amount
u64
Maximum amount of PC token to deposit
base_side
u64
Indicates which token is the base for the deposit (0 for coin, 1 for PC)
other_amount_min
Option<u64>
Minimum acceptable amount of the other token (slippage protection)
Account Setup
1
Token program
SPL Token program
TOKEN_PROGRAM_ID
2
AMM info
AMM account
[program.toBuffer(), marketId.toBuffer(), "amm_associated_seed"]
3
AMM authority
AMM authority PDA
[Buffer.from("amm authority")]
4
AMM LP mint
LP token mint
[program.toBuffer(), marketId.toBuffer(), "lp_mint_associated_seed"]
5
AMM coin vault
Token vault
[program.toBuffer(), marketId.toBuffer(), "coin_vault_associated_seed"]
6
AMM PC vault
SOL vault
[program.toBuffer(), marketId.toBuffer(), "pc_vault_associated_seed"]
7
User source coin
User's token account
getAssociatedTokenAddress(tokenMint, userWallet, false)
8
User source PC
User's SOL account
getAssociatedTokenAddress(NATIVE_MINT, userWallet, false)
9
User dest LP
User's LP token account
getAssociatedTokenAddress(lpMint, userWallet, false)
10
Source owner
Transaction signer (User wallet)
-
Function Logic
Verifies the transaction is signed by the source owner
Checks that the AMM is in a valid state for deposits
Verifies that the deposit amounts are not zero
Calculates the deposit amounts based on the current pool ratio:
If base_side is 0 (coin): Calculates PC amount based on provided coin amount
If base_side is 1 (PC): Calculates coin amount based on provided PC amount
Verifies amounts are within specified limits and match minimum requirements
Calculates LP tokens to mint based on the proportion of assets being added
Transfers coin and PC tokens from user to respective vaults
Mints LP tokens to the user
Updates the AMM's LP token supply
LP Token Calculation
The amount of LP tokens minted is calculated using the proportion of assets being added to the pool:
For base_side = 0 (coin base):
For base_side = 1 (PC base):
Where:
total_coin_without_take_pnl
is the total coin amount in the pooltotal_pc_without_take_pnl
is the total PC amount in the poolamm.lp_amount
is the current total supply of LP tokens
Notes
Deposits must maintain the current ratio of assets in the pool
Using base_side allows specifying which token amount is fixed
The other token amount is calculated to maintain the pool ratio
LP tokens represent a proportional share of the pool
Slippage protection can be used to set minimum acceptable amounts
Example Usage
Last updated