solana_central/protocol_idls/
raydium.rs

1/*
2This is pulled from Raydium io Raydium SDK:
3https://github.com/raydium-io/raydium-sdk/blob/f4b7f47e744c12a8b0119b85e16d0d8274aa5ba9/src/liquidity/layout.ts
4The official Raydium IDL on their site did not contain all this info
5*/
6use borsh::BorshDeserialize;
7use solana_sdk::pubkey::Pubkey;
8
9#[derive(BorshDeserialize)]
10pub struct AmmV4PoolInfoIdl {
11  status: u64,
12  nonce: u64,
13  max_order: u64,
14  depth: u64,
15  pub base_decimal: u64,
16  pub quote_decimal: u64,
17  state: u64,
18  reset_flag: u64,
19  min_size: u64,
20  vol_max_cut_ratio: u64,
21  amount_wave_ratio: u64,
22  base_lot_size: u64,
23  quote_lot_size: u64,
24  min_price_multiplier: u64,
25  max_price_multiplier: u64,
26  system_decimal_value: u64,
27  min_separate_numerator: u64,
28  min_separate_denominator: u64,
29  trade_fee_numerator: u64,
30  trade_fee_denominator: u64,
31  pnl_numerator: u64,
32  pnl_denominator: u64,
33  pub swap_fee_numerator: u64,
34  pub swap_fee_denominator: u64,
35  base_need_take_pnl: u64,
36  quote_need_take_pnl: u64,
37  quote_total_pnl: u64,
38  base_total_pnl: u64,
39  pool_open_time: u64,
40  punish_pc_amount: u64,
41  punish_coin_amount: u64,
42  orderbook_to_init_time: u64,
43  swap_base_in_amount: u128,
44  swap_quote_out_amount: u128,
45  swap_base2quote_fee: u64,
46  swap_quote_in_amount: u128,
47  swap_base_out_amount: u128,
48  swap_quote2base_fee: u64,
49  // amm vault
50  pub base_vault: Pubkey,
51  pub quote_vault: Pubkey,
52  // mint
53  pub base_mint: Pubkey,
54  pub quote_mint: Pubkey,
55  lp_mint: Pubkey,
56  // market
57  open_orders: Pubkey,
58  market_id: Pubkey,
59  market_program_id: Pubkey,
60  target_orders: Pubkey,
61  withdraw_queue: Pubkey,
62  lp_vault: Pubkey,
63  owner: Pubkey,
64  lp_reserve: u64,
65  padding: [u64; 3],
66}
67
68/*
69Pulled from Raydium SDK V2. Confirmed by the IDL to be accurate minus some discriminator and buffer
70value differences.
71https://github.com/raydium-io/raydium-sdk-V2/blob/45d37d45460f4948d61762e8e4b149706778c217/src/raydium/cpmm/layout.ts
72*/
73#[derive(BorshDeserialize)]
74pub struct CpmmPoolConfigIdl {
75  /// Account discriminator / reserved blob
76  pub discriminator: [u8; 8],
77  /// Bump to identify PDA
78  pub bump: u8,
79  /// Status to control if new pool can be created
80  pub disable_create_pool: bool,
81  /// Config index
82  pub index: u16,
83  /// The trade fee, denominated in hundredths of a bip (10^-6)
84  pub trade_fee_rate: u64,
85  /// The protocol fee
86  pub protocol_fee_rate: u64,
87  /// The fund fee, denominated in hundredths of a bip (10^-6)
88  pub fund_fee_rate: u64,
89  /// Fee for creating a new pool
90  pub create_pool_fee: u64,
91  /// Address of the protocol fee owner
92  pub protocol_owner: Pubkey,
93  /// Address of the fund fee owner
94  pub fund_owner: Pubkey,
95  /// Sequence of 16 u64 values
96  pub extra: [u64; 16],
97}
98
99/*
100Directly from the protocol source code:
101https://github.com/raydium-io/raydium-cp-swap/blob/master/programs/cp-swap/src/states/pool.rs
102Added in instruction discriminator for anchor accounts
103*/
104#[derive(BorshDeserialize)]
105pub struct CpmmPoolInfoIdl {
106  pub discriminator: [u8; 8],
107  /// Which config the pool belongs
108  pub amm_config: Pubkey,
109  /// pool creator
110  pub pool_creator: Pubkey,
111  /// Token A
112  pub token_0_vault: Pubkey,
113  /// Token B
114  pub token_1_vault: Pubkey,
115
116  /// Pool tokens are issued when A or B tokens are deposited.
117  /// Pool tokens can be withdrawn back to the original A or B token.
118  pub lp_mint: Pubkey,
119  /// Mint information for token A
120  pub token_0_mint: Pubkey,
121  /// Mint information for token B
122  pub token_1_mint: Pubkey,
123
124  /// token_0 program
125  pub token_0_program: Pubkey,
126  /// token_1 program
127  pub token_1_program: Pubkey,
128
129  /// observation account to store oracle data
130  pub observation_key: Pubkey,
131
132  pub auth_bump: u8,
133  /// Bitwise representation of the state of the pool
134  /// bit0, 1: disable deposit(value is 1), 0: normal
135  /// bit1, 1: disable withdraw(value is 2), 0: normal
136  /// bit2, 1: disable swap(value is 4), 0: normal
137  pub status: u8,
138
139  pub lp_mint_decimals: u8,
140  /// mint0 and mint1 decimals
141  pub mint_0_decimals: u8,
142  pub mint_1_decimals: u8,
143
144  /// True circulating supply without burns and lock ups
145  pub lp_supply: u64,
146  /// The amounts of token_0 and token_1 that are owed to the liquidity provider.
147  pub protocol_fees_token_0: u64,
148  pub protocol_fees_token_1: u64,
149
150  pub fund_fees_token_0: u64,
151  pub fund_fees_token_1: u64,
152
153  /// The timestamp allowed for swap in the pool.
154  pub open_time: u64,
155  /// recent epoch
156  pub recent_epoch: u64,
157
158  /// Creator fee collect mode
159  /// 0: both token_0 and token_1 can be used as trade fees. It depends on what the input token is when swapping
160  /// 1: only token_0 as trade fee
161  /// 2: only token_1 as trade fee
162  pub creator_fee_on: u8,
163  pub enable_creator_fee: bool,
164  pub padding1: [u8; 6],
165  pub creator_fees_token_0: u64,
166  pub creator_fees_token_1: u64,
167  /// padding for future updates
168  pub padding: [u64; 28],
169}
170
171#[derive(BorshDeserialize)]
172pub struct LaunchpadPoolIdl {
173  discriminator: [u8; 8],
174  pub epoch: u64,
175  pub auth_bump: u8,
176  pub status: u8,
177  pub base_decimals: u8,
178  pub quote_decimals: u8,
179  pub migrate_type: u8,
180  pub supply: u64,
181  pub total_base_sell: u64,
182  pub virtual_base: u64,
183  pub virtual_quote: u64,
184  pub real_base: u64,
185  pub real_quote: u64,
186  pub total_quote_fund_raising: u64,
187  pub quote_protocol_fee: u64,
188  // This platform fee isn't a percent its the sum of all fees collected or something
189  pub platform_fee: u64,
190  pub migrate_fee: u64,
191  pub vesting_schedule: [u64; 5],
192  pub global_config: Pubkey,
193  pub platform_config: Pubkey,
194  pub base_mint: Pubkey,
195  pub quote_mint: Pubkey,
196  pub base_vault: Pubkey,
197  pub quote_vault: Pubkey,
198  pub creator: Pubkey,
199  padding: [u8; 64],
200}
201
202#[derive(BorshDeserialize)]
203pub struct LaunchpadTradeEventIdl {
204  discriminator: [u8; 16],
205  pub pool_state: Pubkey,
206  pub total_base_sell: u64,
207  pub virtual_base: u64,
208  pub virtual_quote: u64,
209  pub real_base_before: u64,
210  pub real_quote_before: u64,
211  pub real_base_after: u64,
212  pub real_quote_after: u64,
213  pub amount_in: u64,
214  pub amount_out: u64,
215  pub protocol_fee: u64,
216  pub platform_fee: u64,
217  pub creator_fee: u64,
218  pub share_fee: u64,
219  // 0 means buy, 1 means sell in this enum
220  pub trade_direction: u8,
221  pub pool_status: u8,
222  pub exact_in: bool,
223}
224
225
226#[derive(BorshDeserialize)]
227pub struct CpmmInitializeInstructionDataIdl {
228  discriminator: [u8; 8],
229  pub init_amount_0: u64,
230  pub init_amount_1: u64,
231  pub open_time: u64,
232}
233
234#[derive(BorshDeserialize)]
235pub struct AmmV4Initialize2InstructionDataIdl {
236  pub discriminator: u8,
237  pub nonce: u8,
238  pub open_time: u64,
239  pub init_pc_amount: u64,
240  pub init_coin_amount: u64,
241}