solana_central/protocol_idls/
meteora.rs

1use borsh::{BorshDeserialize, BorshSerialize};
2use solana_sdk::pubkey::Pubkey;
3
4#[derive(BorshSerialize, BorshDeserialize, Debug)]
5pub struct LiquidityDistributionConfig {
6  pub sqrt_price: u128,
7  pub liquidity: u128,
8}
9
10#[derive(BorshSerialize, BorshDeserialize, Debug)]
11pub struct BaseFeeConfig {
12  pub cliff_fee_numerator: u64,
13  pub second_factor: u64,
14  pub third_factor: u64,
15  pub first_factor: u16,
16  pub base_fee_mode: u8,
17  pub padding_0: [u8; 5],
18}
19
20#[derive(BorshSerialize, BorshDeserialize, Debug)]
21pub struct DynamicFeeConfig {
22  pub initialized: u8,
23  pub padding: [u8; 7],
24  pub max_volatility_accumulator: u32,
25  pub variable_fee_control: u32,
26  pub bin_step: u16,
27  pub filter_period: u16,
28  pub decay_period: u16,
29  pub reduction_factor: u16,
30  pub padding2: [u8; 8],
31  pub bin_step_u128: u128,
32}
33
34#[derive(BorshSerialize, BorshDeserialize, Debug)]
35pub struct PoolFeesConfig {
36  pub base_fee: BaseFeeConfig,
37  pub dynamic_fee: DynamicFeeConfig,
38  pub padding_0: [u64; 5],
39  pub padding_1: [u8; 6],
40  pub protocol_fee_percent: u8,
41  pub referral_fee_percent: u8,
42}
43
44#[derive(BorshSerialize, BorshDeserialize, Debug)]
45pub struct LockedVestingConfig {
46  pub amount_per_period: u64,
47  pub cliff_duration_from_migration_time: u64,
48  pub frequency: u64,
49  pub number_of_period: u64,
50  pub cliff_unlock_amount: u64,
51  pub _padding: u64,
52}
53
54#[derive(BorshSerialize, BorshDeserialize, Debug)]
55pub struct VolatilityTracker {
56  pub last_update_timestamp: u64,
57  pub padding: [u8; 8],           // Add padding for u128 alignment
58  pub sqrt_price_reference: u128, // reference sqrt price
59  pub volatility_accumulator: u128,
60  pub volatility_reference: u128, // decayed volatility accumulator
61}
62
63#[derive(BorshSerialize, BorshDeserialize, Debug)]
64pub struct SwapParameters {
65  pub amount_in: u64,
66  pub minimum_amount_out: u64,
67}
68
69#[derive(BorshSerialize, BorshDeserialize, Debug)]
70pub struct SwapResult {
71  pub actual_input_amount: u64,
72  pub output_amount: u64,
73  pub next_sqrt_price: u128,
74  pub trading_fee: u64,
75  pub protocol_fee: u64,
76  pub referral_fee: u64,
77}
78
79// For big vaults like this one of length 10240: mPWBpKzzchEjitz7x4Q2d7cbQ3fHibF2BHWbWk8YGnH
80#[derive(BorshDeserialize)]
81pub struct VaultIdlBig {
82  pub discriminator: [u8; 8],
83  pub enabled: u8,
84  pub bumps: VaultBumps,
85  pub total_amount: u64,
86  pub token_vault: Pubkey,
87  pub fee_vault: Pubkey,
88  pub token_mint: Pubkey,
89  pub lp_mint: Pubkey,
90  pub strategies: [Pubkey; 30],
91  pub base: Pubkey,
92  pub admin: Pubkey,
93  pub operator: Pubkey,
94  pub locked_profit_tracker: LockedProfitTracker,
95  garbage: [u8; 9013],
96}
97
98// For small vaults like this one of length 1232: 12Q6qfukBF7KwbwxRvLnxhEnPdZPb7vjd8bPckCChf8
99#[derive(BorshDeserialize)]
100pub struct VaultIdlSmall {
101  pub discriminator: [u8; 8],
102  pub enabled: u8,
103  pub bumps: VaultBumps,
104  pub total_amount: u64,
105  pub token_vault: Pubkey,
106  pub fee_vault: Pubkey,
107  pub token_mint: Pubkey,
108  pub lp_mint: Pubkey,
109  pub strategies: [Pubkey; 30],
110  pub base: Pubkey,
111  pub admin: Pubkey,
112  pub operator: Pubkey,
113  pub locked_profit_tracker: LockedProfitTracker,
114  garbage: [u8; 5],
115}
116
117#[derive(BorshDeserialize)]
118pub struct LockedProfitTracker {
119  pub last_updated_locked_profit: u64,
120  pub last_report: u64,
121  pub locked_profit_degradation: u64,
122}
123
124#[derive(BorshDeserialize)]
125pub struct VaultBumps {
126  pub vault_bump: u8,
127  pub token_vault_bump: u8,
128}
129
130/*
131https://github.com/MeteoraAg/cp-amm/blob/main/programs/cp-amm/src/state/pool.rs
132Pulled directly of of Meteora DammV2 program src. All supporting types included below:
133*/
134#[derive(BorshDeserialize, Debug)]
135pub struct MeteoraDammv2PoolIdl {
136  pub discriminator: [u8; 8],
137  /// Pool fee
138  pub pool_fees: PoolFeesStruct,
139  /// token a mint
140  pub token_a_mint: Pubkey,
141  /// token b mint
142  pub token_b_mint: Pubkey,
143  /// token a vault
144  pub token_a_vault: Pubkey,
145  /// token b vault
146  pub token_b_vault: Pubkey,
147  /// Whitelisted vault to be able to buy pool before activation_point
148  pub whitelisted_vault: Pubkey,
149  /// partner
150  pub partner: Pubkey,
151  /// liquidity share
152  pub liquidity: u128,
153  /// padding, previous reserve amount, be careful to use that field
154  pub _padding: u128,
155  /// protocol a fee
156  pub protocol_a_fee: u64,
157  /// protocol b fee
158  pub protocol_b_fee: u64,
159  /// partner a fee
160  pub partner_a_fee: u64,
161  /// partner b fee
162  pub partner_b_fee: u64,
163  /// min price
164  pub sqrt_min_price: u128,
165  /// max price
166  pub sqrt_max_price: u128,
167  /// current price
168  pub sqrt_price: u128,
169  /// Activation point, can be slot or timestamp
170  pub activation_point: u64,
171  /// Activation type, 0 means by slot, 1 means by timestamp
172  pub activation_type: u8,
173  /// pool status, 0: enable, 1 disable
174  pub pool_status: u8,
175  /// token a flag
176  pub token_a_flag: u8,
177  /// token b flag
178  pub token_b_flag: u8,
179  /// 0 is collect fee in both token, 1 only collect fee in token a, 2 only collect fee in token b
180  pub collect_fee_mode: u8,
181  /// pool type
182  pub pool_type: u8,
183  /// pool version, 0: max_fee is still capped at 50%, 1: max_fee is capped at 99%
184  pub version: u8,
185  /// padding
186  pub _padding_0: u8,
187  /// cumulative
188  pub fee_a_per_liquidity: [u8; 32], // U256
189  /// cumulative
190  pub fee_b_per_liquidity: [u8; 32], // U256
191  // TODO: Is this large enough?
192  pub permanent_lock_liquidity: u128,
193  /// metrics
194  pub metrics: PoolMetrics,
195  /// pool creator
196  pub creator: Pubkey,
197  /// Padding for further use
198  pub _padding_1: [u64; 6],
199  /// Farming reward information
200  pub reward_infos: [RewardInfo; NUM_REWARDS],
201}
202
203const NUM_REWARDS: usize = 2;
204
205#[derive(BorshDeserialize, Debug)]
206pub struct PoolFeesStruct {
207  /// Trade fees are extra token amounts that are held inside the token
208  /// accounts during a trade, making the value of liquidity tokens rise.
209  /// Trade fee numerator
210  pub base_fee: BaseFeeStruct,
211
212  /// Protocol trading fees are extra token amounts that are held inside the token
213  /// accounts during a trade, with the equivalent in pool tokens minted to
214  /// the protocol of the program.
215  /// Protocol trade fee numerator
216  pub protocol_fee_percent: u8,
217  /// partner fee
218  pub partner_fee_percent: u8,
219  /// referral fee
220  pub referral_fee_percent: u8,
221  /// padding
222  pub padding_0: [u8; 5],
223
224  /// dynamic fee
225  pub dynamic_fee: DynamicFeeStruct,
226
227  /// padding
228  pub padding_1: [u64; 2],
229}
230
231#[derive(BorshDeserialize, Debug)]
232pub struct PoolMetrics {
233  pub total_lp_a_fee: u128,
234  pub total_lp_b_fee: u128,
235  pub total_protocol_a_fee: u64,
236  pub total_protocol_b_fee: u64,
237  pub total_partner_a_fee: u64,
238  pub total_partner_b_fee: u64,
239  pub total_position: u64,
240  pub padding: u64,
241}
242
243#[derive(BorshDeserialize, Debug)]
244pub struct RewardInfo {
245  /// Indicates if the reward has been initialized
246  pub initialized: u8,
247  /// reward token flag
248  pub reward_token_flag: u8,
249  /// padding
250  pub _padding_0: [u8; 6],
251  /// Padding to ensure `reward_rate: u128` is 16-byte aligned
252  pub _padding_1: [u8; 8], // 8 bytes
253  /// Reward token mint.
254  pub mint: Pubkey,
255  /// Reward vault token account.
256  pub vault: Pubkey,
257  /// Authority account that allows to fund rewards
258  pub funder: Pubkey,
259  /// reward duration
260  pub reward_duration: u64,
261  /// reward duration end
262  pub reward_duration_end: u64,
263  /// reward rate
264  pub reward_rate: u128,
265  /// Reward per token stored
266  pub reward_per_token_stored: [u8; 32], // U256
267  /// The last time reward states were updated.
268  pub last_update_time: u64,
269  /// Accumulated seconds when the farm distributed rewards but the bin was empty.
270  /// These rewards will be carried over to the next reward time window.
271  pub cumulative_seconds_with_empty_liquidity_reward: u64,
272}
273
274#[derive(BorshDeserialize, Debug)]
275pub struct BaseFeeStruct {
276  pub cliff_fee_numerator: u64,
277  // In fee scheduler first_factor: number_of_period, second_factor: period_frequency, third_factor: reduction_factor
278  // in rate limiter: first_factor: fee_increment_bps, second_factor: max_limiter_duration, max_fee_bps, third_factor: reference_amount
279  pub base_fee_mode: u8,
280  pub padding_0: [u8; 5],
281  pub first_factor: u16,
282  pub second_factor: [u8; 8],
283  pub third_factor: u64,
284  pub padding_1: u64,
285}
286
287#[derive(BorshDeserialize, Debug)]
288pub struct DynamicFeeStruct {
289  pub initialized: u8, // 0, ignore for dynamic fee
290  pub padding: [u8; 7],
291  pub max_volatility_accumulator: u32,
292  pub variable_fee_control: u32,
293  pub bin_step: u16,
294  pub filter_period: u16,
295  pub decay_period: u16,
296  pub reduction_factor: u16,
297  pub last_update_timestamp: u64,
298  pub bin_step_u128: u128,
299  pub sqrt_price_reference: u128, // reference sqrt price
300  pub volatility_accumulator: u128,
301  pub volatility_reference: u128, // decayed volatility accumulator
302}
303
304/*
305This layout is pulled from this guy's sdk but using his sdk creates manu cargo conficts so just
306copied over the chunks needed manually
307https://github.com/regolith-labs/meteora-pools-sdk/tree/master/src/types
308*/
309#[derive(BorshDeserialize)]
310pub struct AmmPoolFees {
311  /// Trade fees are extra token amounts that are held inside the token
312  /// accounts during a trade, making the value of liquidity tokens rise.
313  /// Trade fee numerator
314  pub trade_fee_numerator: u64,
315  /// Trade fee denominator
316  pub trade_fee_denominator: u64,
317  /// Protocol trading fees are extra token amounts that are held inside the token
318  /// accounts during a trade, with the equivalent in pool tokens minted to
319  /// the protocol of the program.
320  /// Protocol trade fee numerator
321  pub protocol_trade_fee_numerator: u64,
322  /// Protocol trade fee denominator
323  pub protocol_trade_fee_denominator: u64,
324}
325
326#[derive(BorshDeserialize)]
327struct Padding {
328  /// Padding 0
329  pub padding0: [u8; 6],
330  /// Padding 1
331  pub padding1: [u64; 21],
332  /// Padding 2
333  pub padding2: [u64; 21],
334}
335
336#[derive(BorshDeserialize)]
337enum CurveType {
338  ConstantProduct,
339  Stable {
340    /// Amplification coefficient
341    amp: u64,
342    /// Multiplier for the pool token. Used to normalized token with different decimal into the same precision.
343    token_multiplier: TokenMultiplier,
344    /// Depeg pool information. Contains functions to allow token amount to be repeg using stake / interest bearing token virtual price
345    depeg: Depeg,
346    /// The last amp updated timestamp. Used to prevent update_curve_info called infinitely many times within a short period
347    last_amp_updated_timestamp: u64,
348  },
349}
350
351#[derive(BorshDeserialize)]
352struct TokenMultiplier {
353  /// Multiplier for token A of the pool.
354  pub token_a_multiplier: u64,
355  /// Multiplier for token B of the pool.
356  pub token_b_multiplier: u64,
357  /// Record the highest token decimal in the pool. For example, Token A is 6 decimal, token B is 9 decimal. This will save value of 9.
358  pub precision_factor: u8,
359}
360
361#[derive(BorshDeserialize)]
362struct Depeg {
363  /// The virtual price of staking / interest bearing token
364  pub base_virtual_price: u64,
365  /// The last time base_virtual_price is updated
366  pub base_cache_updated: u64,
367  /// Type of the depeg pool
368  pub depeg_type: DepegType,
369}
370
371#[derive(BorshDeserialize)]
372enum DepegType {
373  None,
374  Marinade,
375  Lido,
376  SplStake,
377}
378
379#[derive(BorshSerialize, BorshDeserialize, Debug)]
380pub struct DbcPoolConfig {
381  /// Discriminator: [26, 108, 14, 123, 116, 230, 129, 43]
382  pub discriminator: [u8; 8],
383  pub quote_mint: Pubkey,
384  pub fee_claimer: Pubkey,
385  pub leftover_receiver: Pubkey,
386  pub pool_fees: PoolFeesConfig,
387  pub collect_fee_mode: u8,
388  pub migration_option: u8,
389  pub activation_type: u8,
390  pub token_decimal: u8,
391  pub version: u8,
392  pub token_type: u8,
393  pub quote_token_flag: u8,
394  pub partner_locked_lp_percentage: u8,
395  pub partner_lp_percentage: u8,
396  pub creator_locked_lp_percentage: u8,
397  pub creator_lp_percentage: u8,
398  pub migration_fee_option: u8,
399  pub fixed_token_supply_flag: u8,
400  pub creator_trading_fee_percentage: u8,
401  pub token_update_authority: u8,
402  pub migration_fee_percentage: u8,
403  pub creator_migration_fee_percentage: u8,
404  pub _padding_1: [u8; 7],
405  pub swap_base_amount: u64,
406  pub migration_quote_threshold: u64,
407  pub migration_base_threshold: u64,
408  pub migration_sqrt_price: u128,
409  pub locked_vesting_config: LockedVestingConfig,
410  pub pre_migration_token_supply: u64,
411  pub post_migration_token_supply: u64,
412  pub _padding_2: [u128; 2],
413  pub sqrt_start_price: u128,
414  pub curve: [LiquidityDistributionConfig; 20],
415}
416
417#[derive(BorshDeserialize, Debug)]
418pub struct DbcVirtualPool {
419  pub discriminator: [u8; 8],
420  pub volatility_tracker: VolatilityTracker,
421  pub config: Pubkey,
422  pub creator: Pubkey,
423  pub base_mint: Pubkey,
424  pub base_vault: Pubkey,
425  pub quote_vault: Pubkey,
426  pub base_reserve: u64,
427  pub quote_reserve: u64,
428  pub protocol_base_fee: u64,
429  pub protocol_quote_fee: u64,
430  pub partner_base_fee: u64,
431  pub partner_quote_fee: u64,
432  pub sqrt_price: u128,
433  pub activation_point: u64,
434  pub pool_type: u8,
435  pub is_migrated: u8,
436  pub is_partner_withdraw_surplus: u8,
437  pub is_protocol_withdraw_surplus: u8,
438  pub migration_progress: u8,
439  pub is_withdraw_leftover: u8,
440  pub is_creator_withdraw_surplus: u8,
441  pub migration_fee_withdraw_status: u8,
442  pub metrics: PoolMetrics,
443  pub finish_curve_timestamp: u64,
444  pub creator_base_fee: u64,
445  pub creator_quote_fee: u64,
446  pub _padding_1: [u64; 7],
447}
448
449#[derive(BorshDeserialize)]
450pub struct MeteoraAmmPoolIdl {
451  pub discriminator: [u8; 8],
452  /// LP token mint of the pool
453  pub lp_mint: Pubkey,
454  /// Token A mint of the pool. Eg: USDT
455  pub token_a_mint: Pubkey,
456  /// Token B mint of the pool. Eg: USDC
457  pub token_b_mint: Pubkey,
458  /// Vault account for token A. Token A of the pool will be deposit / withdraw from this vault account.
459  pub a_vault: Pubkey,
460  /// Vault account for token B. Token B of the pool will be deposit / withdraw from this vault account.
461  pub b_vault: Pubkey,
462  /// LP token account of vault A. Used to receive/burn the vault LP upon deposit/withdraw from the vault.
463  pub a_vault_lp: Pubkey,
464  /// LP token account of vault B. Used to receive/burn the vault LP upon deposit/withdraw from the vault.
465  pub b_vault_lp: Pubkey,
466  /// "A" vault lp bump. Used to create signer seeds.
467  pub a_vault_lp_bump: u8,
468  /// Flag to determine whether the pool is enabled, or disabled.
469  pub enabled: bool,
470  /// Protocol fee token account for token A. Used to receive trading fee.
471  pub protocol_token_a_fee: Pubkey,
472  /// Protocol fee token account for token B. Used to receive trading fee.
473  pub protocol_token_b_fee: Pubkey,
474  /// Fee last updated timestamp
475  pub fee_last_updated_at: u64,
476  pub padding0: [u8; 24],
477  /// Store the fee charges setting.
478  pub fees: AmmPoolFees,
479  pub garbage: [u8; 590],
480}