Program Instructions

Interacting with GAMMA pools and handling fee collection

In the spirit of web3, we are providing our codebase as open source for anyone to read and comment on. Here are some key details of the program code. We also have SDKs for anyone to integrate directly with the program.

create_amm_config

Creates and configures the AMM protocol parameters including trade fees, protocol fees, and more.

Parameters:

  • index: Index of the AMM configuration.

  • trade_fee_rate: Rate for trade fees.

  • protocol_fee_rate: Rate for protocol fees.

  • fund_fee_rate: Rate for fund fees.

  • create_pool_fee: Fee for creating a pool.

Context Accounts:

  • owner: Signer who is the address to be set as the protocol owner.

  • amm_config: Account to initialize and store protocol owner address and fee rates.

  • system_program: System program reference.

update_amm_config

Updates the AMM configuration owner or fee rates.

Parameters:

  • param: Parameter to update (0: trade fee, 1: protocol fee, 2: fund fee, 3: new owner, 4: new fund owner).

  • value: New value for the specified parameter.

Context Accounts:

  • owner: Signer who is the AMM config owner or admin.

  • amm_config: Account storing the AMM configuration.

update_pool_status

Updates the status of a pool (e.g., active, paused).

Parameters:

  • status: New status value for the pool.

Context Accounts:

  • authority: Signer who is the admin.

  • pool_state: AccountLoader for the pool state.

collect_protocol_fee

Collects the protocol fee accrued in the pool.

Parameters:

  • amount_0_requested: Maximum amount of token_0 to collect.

  • amount_1_requested: Maximum amount of token_1 to collect.

Context Accounts:

  • Accounts include owner, authority, pool_state, amm_config, token vaults, mint accounts, and recipient token accounts.

initialize

Initializes a pool for a token pair with an initial price.

Parameters:

  • init_amount_0: Initial amount of token_0.

  • init_amount_1: Initial amount of token_1.

  • open_time: Timestamp when swapping is enabled.

Context Accounts:

  • Various accounts related to token vaults, LP tokens, and observation states.

deposit

Deposits liquidity into the pool and mints LP tokens in return.

Parameters:

  • lp_token_amount: Pool token amount to transfer.

  • maximum_token_0_amount: Maximum token 0 amount to deposit to prevent excessive slippage.

  • maximum_token_1_amount: Maximum token 1 amount to deposit to prevent excessive slippage.

Context Accounts:

  • Accounts related to liquidity provider, vaults, and LP mint.

withdraw

Withdraws liquidity from the pool and burns LP tokens.

Parameters:

  • lp_token_amount: Amount of pool tokens to burn.

  • minimum_token_0_amount: Minimum amount of token 0 to receive to prevent excessive slippage.

  • minimum_token_1_amount: Minimum amount of token 1 to receive to prevent excessive slippage.

Context Accounts:

  • Accounts related to liquidity provider, vaults, and LP mint.

swap_base_input

Swaps tokens in the pool based on the input amount.

Parameters:

  • amount_in: Amount of input tokens to transfer.

  • minimum_amount_out: Minimum amount of output tokens to receive to prevent excessive slippage.

Context Accounts:

  • Accounts related to token inputs, outputs, vaults, and the observation state.

swap_base_output

Swaps tokens in the pool based on the output amount.

Parameters:

  • max_amount_in: Maximum amount of input tokens to transfer to prevent excessive slippage.

  • amount_out: Amount of output tokens to receive.

Context Accounts:

  • Accounts related to token inputs, outputs, vaults, and the observation state.

LpChangeEvent

Emitted during liquidity changes (deposits/withdrawals).

  • Fields:

    • pool_id: Pool ID.

    • lp_amount_before: LP tokens before operation.

    • token_0_vault_before: Token 0 amount in the vault before operation.

    • token_1_vault_before: Token 1 amount in the vault before operation.

    • token_0_amount: Calculated token 0 amount (excludes transfer fees).

    • token_1_amount: Calculated token 1 amount (excludes transfer fees).

    • change_type: Type of change (0 for deposit, 1 for withdrawal).

SwapEvent

Emitted during swaps.

  • Fields:

    • pool_id: Pool ID.

    • input_vault_before: Input token amount in vault before swap.

    • output_vault_before: Output token amount in vault before swap.

    • input_amount: Amount of input tokens swapped.

    • output_amount: Amount of output tokens received.

    • base_input: Indicates if the swap is based on input amount.

Last updated