clmm_bindings/
lib.rs

1use anchor_lang::prelude::*;
2
3declare_id!("ArmN3Av2boBg8pkkeCK9UuCN9zSUVc2UQg1qR2sKwm8d");
4
5/// The maximum number of positions a vault could have. This dictates the space required for
6/// the CLP Vault. There is a separate constant for limiting active positions. These are
7/// separate because the max active positions will start at 1 for v1.0.0 of the protocol.
8pub const MAX_POSITIONS: usize = 5;
9
10/// The maximum number of active positions the CLP Vault could have on the underlying valut at a
11/// single time.
12pub const MAX_ACTIVE_POSITIONS: usize = MAX_POSITIONS;
13
14#[derive(Clone, Copy, Default, AnchorDeserialize, AnchorSerialize)]
15#[repr(C)]
16pub struct SwapCache {
17    pub source_status: SourceState,
18    pub cache_state: CacheState,
19    _padding1: [u8; 6],
20}
21#[derive(Clone, Copy, Debug, Default, AnchorDeserialize, AnchorSerialize)]
22#[repr(u8)]
23pub enum SourceState {
24    #[default]
25    Default,
26    SourceIsA,
27    SourceIsB,
28}
29#[derive(Clone, Copy, Debug, Default, AnchorDeserialize, AnchorSerialize)]
30#[repr(u8)]
31pub enum CacheState {
32    #[default]
33    Default,
34    Ready,
35    Consumed,
36}
37
38#[derive(Clone, Copy, Default, AnchorDeserialize, AnchorSerialize)]
39#[repr(C)]
40pub struct VaultPosition {
41    /// The underlying CLP position.
42    pub position_key: Pubkey,
43    /// The address of the lower TickArray
44    pub lower_tick: i32,
45    _padding0: [u8; 12],
46    /// The address of the upper TickArray
47    pub upper_tick: i32,
48    _padding1: [u8; 12],
49    _reserve: [u8; 32],
50    _reserve1: [u8; 32],
51    _reserve2: [u8; 32],
52    _reserve3: [u8; 32],
53    _reserve4: [u8; 32],
54    _reserve5: [u8; 32],
55    _reserve6: [u8; 32],
56    _reserve7: [u8; 32],
57}
58
59#[derive(Clone, Copy, AnchorDeserialize, AnchorSerialize)]
60#[repr(u8)]
61pub enum StrategyType {
62    /// Used for a brand volatile pair that has a brand new coin with no history,
63    PriceDiscovery,
64    /// Used for a pair like PSY/HXRO
65    VolatilePair,
66    /// Used for a pair like USDC-USDT
67    StablePair,
68    /// Used for a pair like SOL-jitoSOL
69    StableSlowlyDiverging,
70}
71
72#[derive(Clone, Copy, AnchorDeserialize, AnchorSerialize)]
73pub struct TokenRatio {
74    /// The amount of token a required for the initial deposit
75    pub token_a: u64,
76    /// The amount of token b required for the initial deposit
77    pub token_b: u64,
78}
79
80#[derive(Clone, Copy, AnchorDeserialize, AnchorSerialize)]
81#[repr(C)]
82pub struct VaultRatioCache {
83    /// Total amount of tokenA managed by the vault
84    pub total_token_a: u64,
85    /// Total amount of tokenB managed by the vault
86    pub total_token_b: u64,
87    /// The total supply of vault LP tokens
88    pub lp_supply: u64,
89    /// The Unix timestamp for when the cache was last updated
90    pub cached_at: i64,
91}
92
93#[derive(Clone, Copy, Default, AnchorDeserialize, AnchorSerialize)]
94#[repr(C)]
95pub struct SwapEventCache {
96    pub source_before: u64,
97    pub dest_before: u64,
98    pub source_after: u64,
99    pub dest_after: u64
100}
101
102#[account(zero_copy)]
103#[repr(C)]
104pub struct ClpVault {
105    pub bump_seed: u8,
106    pub features_enabled: u8,
107    pub swap_cache: SwapCache,
108    _padding0: [u8; 6],
109    /// A nonce to allow more than one CLP Vault with the same trading pair for the same admin
110    pub nonce: u16,
111    _padding1: [u8; 14],
112    /// The address of the concentrated liquidity pool. E.g. Orca Whirlpool address
113    pub clp: Pubkey,
114    /// The SPL token Mint address for the LP tokens
115    pub lp_mint: Pubkey,
116    pub lp_mint_bump: u8,
117    _padding2: [u8; 15],
118    /// SPL token Mint A of the trading pair
119    pub token_mint_a: Pubkey,
120    /// An SPL token Account for staging A tokens
121    pub token_vault_a: Pubkey,
122    /// SPL Token mint B of the trading pair
123    pub token_mint_b: Pubkey,
124    /// An SPL token Account for staging B tokens
125    pub token_vault_b: Pubkey,
126    /// A percentage of the trading fees and rewards taken by the CLP Vault
127    pub performance_fee: u32,
128    _padding3: [u8; 12],
129    /// A fee percentage taken upon withdrawing
130    pub withdrawal_fee: u32,
131    _padding4: [u8; 12],
132    /// A percentage of the performance_fee that gets paid to the market_maker.
133    pub market_making_fee: u32,
134    _padding5: [u8; 12],
135    /// The strategy that is enlisted by the vault
136    pub strategy: StrategyType,
137    _padding6: [u8; 15],
138    /// The key that has the ability to adjust positions and rebalance
139    pub market_making_key: Pubkey,
140    /// The key that has the ability to change the market_making_key and strategy.
141    pub admin_key: Pubkey,
142    /// The key that must be the owner of SPL Token Accounts that receive fees
143    pub fee_owner: Pubkey,
144    /// The number of active Positions the vault has on the CLP
145    pub num_active_positions: u8,
146    _padding7: [u8; 15],
147    /// The TokenAccount owned by the ClpVault that controls the PositionBundle
148    pub position_bundle_token_account: Pubkey,
149    /// The mint address of the whirlpool PositionBundle
150    pub position_bundle_mint: Pubkey,
151    /// The Whirlpool PositionBundle account
152    pub position_bundle: Pubkey,
153    /// A slice of the active position information
154    pub positions: [VaultPosition; MAX_POSITIONS],
155    /// The initial amount of tokenA to tokenB required per LP token when there is 0 liquidity on
156    ///  positions or in the reserve. This is only used for the inital deposit into the vault. 
157    ///  Without this, the vault would have no basis for calculating the amount of tokenA & tokenB
158    ///  required to mint 1 LP token.
159    pub initial_token_ratio: TokenRatio,
160    /// A key indicating the primary StakePool for the vault. This is used as reference for UIs.
161    pub stake_pool: Pubkey,
162
163    pub ratio_cache: VaultRatioCache,
164
165    pub swap_event_cache: SwapEventCache,
166
167    _reserved0: [u8; 416],
168    // added to give 16 bit spacing incase u128's are required in the future
169    _reserved1: [u8; 512],
170}