dloom_flow/amm/state/pool.rs
1// FILE: programs/dloom_flow/src/state/amm_pool.rs
2
3use anchor_lang::prelude::*;
4
5/// State for a permissionless, constant-product AMM pool.
6///
7/// Follows the x * y = k model.
8#[account]
9#[derive(Default, Debug)]
10pub struct AmmPool {
11 /// The PDA bump.
12 pub bump: u8,
13
14 /// The authority that can update protocol fees or other admin-only parameters.
15 /// Can be a multi-sig or DAO.
16 pub authority: Pubkey,
17
18 // --- Mint and Vault Keys ---
19 pub token_a_mint: Pubkey,
20 pub token_b_mint: Pubkey,
21 pub token_a_vault: Pubkey,
22 pub token_b_vault: Pubkey,
23 pub lp_mint: Pubkey,
24
25 // --- Fee Parameters ---
26 pub fee_rate: u16,
27 pub protocol_fee_share: u16,
28 pub referrer_fee_share: u16,
29 pub protocol_fee_vault_a: Pubkey,
30 pub protocol_fee_vault_b: Pubkey,
31
32 // --- Liquidity State ---
33 pub reserves_a: u64,
34 pub reserves_b: u64,
35
36 // --- Fee Growth Accumulators (NEW) ---
37 /// Total fees of token A accrued per LP token.
38 pub fee_growth_per_lp_token_a: u128,
39 /// Total fees of token B accrued per LP token.
40 pub fee_growth_per_lp_token_b: u128,
41
42 // --- Oracle Fields ---
43 /// The cumulative price of token A in terms of token B.
44 pub price_a_cumulative: u128,
45 /// The cumulative price of token B in terms of token A.
46 pub price_b_cumulative: u128,
47 /// The timestamp of the last update to the reserves and oracle.
48 pub last_update_timestamp: i64,
49 pub last_fee_update_timestamp: i64,
50 /// Snapshot of the cumulative price at the last fee update, used for volatility calculation.
51 pub price_a_cumulative_last_fee_update: u128,
52}