meteora_pools_sdk/instructions/
create_config.rs

1//! This code was AUTOGENERATED using the codama library.
2//! Please DO NOT EDIT THIS FILE, instead use visitors
3//! to add features, then rerun codama to update it.
4//!
5//! <https://github.com/codama-idl/codama>
6//!
7
8use borsh::BorshDeserialize;
9use borsh::BorshSerialize;
10use solana_program::pubkey::Pubkey;
11
12/// Accounts.
13pub struct CreateConfig {
14    pub config: solana_program::pubkey::Pubkey,
15
16    pub admin: solana_program::pubkey::Pubkey,
17
18    pub system_program: solana_program::pubkey::Pubkey,
19}
20
21impl CreateConfig {
22    pub fn instruction(
23        &self,
24        args: CreateConfigInstructionArgs,
25    ) -> solana_program::instruction::Instruction {
26        self.instruction_with_remaining_accounts(args, &[])
27    }
28    #[allow(clippy::vec_init_then_push)]
29    pub fn instruction_with_remaining_accounts(
30        &self,
31        args: CreateConfigInstructionArgs,
32        remaining_accounts: &[solana_program::instruction::AccountMeta],
33    ) -> solana_program::instruction::Instruction {
34        let mut accounts = Vec::with_capacity(3 + remaining_accounts.len());
35        accounts.push(solana_program::instruction::AccountMeta::new(
36            self.config,
37            false,
38        ));
39        accounts.push(solana_program::instruction::AccountMeta::new(
40            self.admin, true,
41        ));
42        accounts.push(solana_program::instruction::AccountMeta::new_readonly(
43            self.system_program,
44            false,
45        ));
46        accounts.extend_from_slice(remaining_accounts);
47        let mut data = CreateConfigInstructionData::new().try_to_vec().unwrap();
48        let mut args = args.try_to_vec().unwrap();
49        data.append(&mut args);
50
51        solana_program::instruction::Instruction {
52            program_id: crate::AMM_ID,
53            accounts,
54            data,
55        }
56    }
57}
58
59#[derive(BorshSerialize, BorshDeserialize, Clone, Debug, Eq, PartialEq)]
60#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
61pub struct CreateConfigInstructionData {
62    discriminator: [u8; 8],
63}
64
65impl CreateConfigInstructionData {
66    pub fn new() -> Self {
67        Self {
68            discriminator: [201, 207, 243, 114, 75, 111, 47, 189],
69        }
70    }
71}
72
73impl Default for CreateConfigInstructionData {
74    fn default() -> Self {
75        Self::new()
76    }
77}
78
79#[derive(BorshSerialize, BorshDeserialize, Clone, Debug, Eq, PartialEq)]
80#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
81pub struct CreateConfigInstructionArgs {
82    pub trade_fee_numerator: u64,
83    pub protocol_trade_fee_numerator: u64,
84    pub activation_duration: u64,
85    pub vault_config_key: Pubkey,
86    pub pool_creator_authority: Pubkey,
87    pub activation_type: u8,
88    pub index: u64,
89    pub partner_fee_numerator: u64,
90}
91
92/// Instruction builder for `CreateConfig`.
93///
94/// ### Accounts:
95///
96///   0. `[writable]` config
97///   1. `[writable, signer]` admin
98///   2. `[optional]` system_program (default to `11111111111111111111111111111111`)
99#[derive(Clone, Debug, Default)]
100pub struct CreateConfigBuilder {
101    config: Option<solana_program::pubkey::Pubkey>,
102    admin: Option<solana_program::pubkey::Pubkey>,
103    system_program: Option<solana_program::pubkey::Pubkey>,
104    trade_fee_numerator: Option<u64>,
105    protocol_trade_fee_numerator: Option<u64>,
106    activation_duration: Option<u64>,
107    vault_config_key: Option<Pubkey>,
108    pool_creator_authority: Option<Pubkey>,
109    activation_type: Option<u8>,
110    index: Option<u64>,
111    partner_fee_numerator: Option<u64>,
112    __remaining_accounts: Vec<solana_program::instruction::AccountMeta>,
113}
114
115impl CreateConfigBuilder {
116    pub fn new() -> Self {
117        Self::default()
118    }
119    #[inline(always)]
120    pub fn config(&mut self, config: solana_program::pubkey::Pubkey) -> &mut Self {
121        self.config = Some(config);
122        self
123    }
124    #[inline(always)]
125    pub fn admin(&mut self, admin: solana_program::pubkey::Pubkey) -> &mut Self {
126        self.admin = Some(admin);
127        self
128    }
129    /// `[optional account, default to '11111111111111111111111111111111']`
130    #[inline(always)]
131    pub fn system_program(&mut self, system_program: solana_program::pubkey::Pubkey) -> &mut Self {
132        self.system_program = Some(system_program);
133        self
134    }
135    #[inline(always)]
136    pub fn trade_fee_numerator(&mut self, trade_fee_numerator: u64) -> &mut Self {
137        self.trade_fee_numerator = Some(trade_fee_numerator);
138        self
139    }
140    #[inline(always)]
141    pub fn protocol_trade_fee_numerator(&mut self, protocol_trade_fee_numerator: u64) -> &mut Self {
142        self.protocol_trade_fee_numerator = Some(protocol_trade_fee_numerator);
143        self
144    }
145    #[inline(always)]
146    pub fn activation_duration(&mut self, activation_duration: u64) -> &mut Self {
147        self.activation_duration = Some(activation_duration);
148        self
149    }
150    #[inline(always)]
151    pub fn vault_config_key(&mut self, vault_config_key: Pubkey) -> &mut Self {
152        self.vault_config_key = Some(vault_config_key);
153        self
154    }
155    #[inline(always)]
156    pub fn pool_creator_authority(&mut self, pool_creator_authority: Pubkey) -> &mut Self {
157        self.pool_creator_authority = Some(pool_creator_authority);
158        self
159    }
160    #[inline(always)]
161    pub fn activation_type(&mut self, activation_type: u8) -> &mut Self {
162        self.activation_type = Some(activation_type);
163        self
164    }
165    #[inline(always)]
166    pub fn index(&mut self, index: u64) -> &mut Self {
167        self.index = Some(index);
168        self
169    }
170    #[inline(always)]
171    pub fn partner_fee_numerator(&mut self, partner_fee_numerator: u64) -> &mut Self {
172        self.partner_fee_numerator = Some(partner_fee_numerator);
173        self
174    }
175    /// Add an additional account to the instruction.
176    #[inline(always)]
177    pub fn add_remaining_account(
178        &mut self,
179        account: solana_program::instruction::AccountMeta,
180    ) -> &mut Self {
181        self.__remaining_accounts.push(account);
182        self
183    }
184    /// Add additional accounts to the instruction.
185    #[inline(always)]
186    pub fn add_remaining_accounts(
187        &mut self,
188        accounts: &[solana_program::instruction::AccountMeta],
189    ) -> &mut Self {
190        self.__remaining_accounts.extend_from_slice(accounts);
191        self
192    }
193    #[allow(clippy::clone_on_copy)]
194    pub fn instruction(&self) -> solana_program::instruction::Instruction {
195        let accounts = CreateConfig {
196            config: self.config.expect("config is not set"),
197            admin: self.admin.expect("admin is not set"),
198            system_program: self
199                .system_program
200                .unwrap_or(solana_program::pubkey!("11111111111111111111111111111111")),
201        };
202        let args = CreateConfigInstructionArgs {
203            trade_fee_numerator: self
204                .trade_fee_numerator
205                .clone()
206                .expect("trade_fee_numerator is not set"),
207            protocol_trade_fee_numerator: self
208                .protocol_trade_fee_numerator
209                .clone()
210                .expect("protocol_trade_fee_numerator is not set"),
211            activation_duration: self
212                .activation_duration
213                .clone()
214                .expect("activation_duration is not set"),
215            vault_config_key: self
216                .vault_config_key
217                .clone()
218                .expect("vault_config_key is not set"),
219            pool_creator_authority: self
220                .pool_creator_authority
221                .clone()
222                .expect("pool_creator_authority is not set"),
223            activation_type: self
224                .activation_type
225                .clone()
226                .expect("activation_type is not set"),
227            index: self.index.clone().expect("index is not set"),
228            partner_fee_numerator: self
229                .partner_fee_numerator
230                .clone()
231                .expect("partner_fee_numerator is not set"),
232        };
233
234        accounts.instruction_with_remaining_accounts(args, &self.__remaining_accounts)
235    }
236}
237
238/// `create_config` CPI accounts.
239pub struct CreateConfigCpiAccounts<'a, 'b> {
240    pub config: &'b solana_program::account_info::AccountInfo<'a>,
241
242    pub admin: &'b solana_program::account_info::AccountInfo<'a>,
243
244    pub system_program: &'b solana_program::account_info::AccountInfo<'a>,
245}
246
247/// `create_config` CPI instruction.
248pub struct CreateConfigCpi<'a, 'b> {
249    /// The program to invoke.
250    pub __program: &'b solana_program::account_info::AccountInfo<'a>,
251
252    pub config: &'b solana_program::account_info::AccountInfo<'a>,
253
254    pub admin: &'b solana_program::account_info::AccountInfo<'a>,
255
256    pub system_program: &'b solana_program::account_info::AccountInfo<'a>,
257    /// The arguments for the instruction.
258    pub __args: CreateConfigInstructionArgs,
259}
260
261impl<'a, 'b> CreateConfigCpi<'a, 'b> {
262    pub fn new(
263        program: &'b solana_program::account_info::AccountInfo<'a>,
264        accounts: CreateConfigCpiAccounts<'a, 'b>,
265        args: CreateConfigInstructionArgs,
266    ) -> Self {
267        Self {
268            __program: program,
269            config: accounts.config,
270            admin: accounts.admin,
271            system_program: accounts.system_program,
272            __args: args,
273        }
274    }
275    #[inline(always)]
276    pub fn invoke(&self) -> solana_program::entrypoint::ProgramResult {
277        self.invoke_signed_with_remaining_accounts(&[], &[])
278    }
279    #[inline(always)]
280    pub fn invoke_with_remaining_accounts(
281        &self,
282        remaining_accounts: &[(
283            &'b solana_program::account_info::AccountInfo<'a>,
284            bool,
285            bool,
286        )],
287    ) -> solana_program::entrypoint::ProgramResult {
288        self.invoke_signed_with_remaining_accounts(&[], remaining_accounts)
289    }
290    #[inline(always)]
291    pub fn invoke_signed(
292        &self,
293        signers_seeds: &[&[&[u8]]],
294    ) -> solana_program::entrypoint::ProgramResult {
295        self.invoke_signed_with_remaining_accounts(signers_seeds, &[])
296    }
297    #[allow(clippy::clone_on_copy)]
298    #[allow(clippy::vec_init_then_push)]
299    pub fn invoke_signed_with_remaining_accounts(
300        &self,
301        signers_seeds: &[&[&[u8]]],
302        remaining_accounts: &[(
303            &'b solana_program::account_info::AccountInfo<'a>,
304            bool,
305            bool,
306        )],
307    ) -> solana_program::entrypoint::ProgramResult {
308        let mut accounts = Vec::with_capacity(3 + remaining_accounts.len());
309        accounts.push(solana_program::instruction::AccountMeta::new(
310            *self.config.key,
311            false,
312        ));
313        accounts.push(solana_program::instruction::AccountMeta::new(
314            *self.admin.key,
315            true,
316        ));
317        accounts.push(solana_program::instruction::AccountMeta::new_readonly(
318            *self.system_program.key,
319            false,
320        ));
321        remaining_accounts.iter().for_each(|remaining_account| {
322            accounts.push(solana_program::instruction::AccountMeta {
323                pubkey: *remaining_account.0.key,
324                is_signer: remaining_account.1,
325                is_writable: remaining_account.2,
326            })
327        });
328        let mut data = CreateConfigInstructionData::new().try_to_vec().unwrap();
329        let mut args = self.__args.try_to_vec().unwrap();
330        data.append(&mut args);
331
332        let instruction = solana_program::instruction::Instruction {
333            program_id: crate::AMM_ID,
334            accounts,
335            data,
336        };
337        let mut account_infos = Vec::with_capacity(4 + remaining_accounts.len());
338        account_infos.push(self.__program.clone());
339        account_infos.push(self.config.clone());
340        account_infos.push(self.admin.clone());
341        account_infos.push(self.system_program.clone());
342        remaining_accounts
343            .iter()
344            .for_each(|remaining_account| account_infos.push(remaining_account.0.clone()));
345
346        if signers_seeds.is_empty() {
347            solana_program::program::invoke(&instruction, &account_infos)
348        } else {
349            solana_program::program::invoke_signed(&instruction, &account_infos, signers_seeds)
350        }
351    }
352}
353
354/// Instruction builder for `CreateConfig` via CPI.
355///
356/// ### Accounts:
357///
358///   0. `[writable]` config
359///   1. `[writable, signer]` admin
360///   2. `[]` system_program
361#[derive(Clone, Debug)]
362pub struct CreateConfigCpiBuilder<'a, 'b> {
363    instruction: Box<CreateConfigCpiBuilderInstruction<'a, 'b>>,
364}
365
366impl<'a, 'b> CreateConfigCpiBuilder<'a, 'b> {
367    pub fn new(program: &'b solana_program::account_info::AccountInfo<'a>) -> Self {
368        let instruction = Box::new(CreateConfigCpiBuilderInstruction {
369            __program: program,
370            config: None,
371            admin: None,
372            system_program: None,
373            trade_fee_numerator: None,
374            protocol_trade_fee_numerator: None,
375            activation_duration: None,
376            vault_config_key: None,
377            pool_creator_authority: None,
378            activation_type: None,
379            index: None,
380            partner_fee_numerator: None,
381            __remaining_accounts: Vec::new(),
382        });
383        Self { instruction }
384    }
385    #[inline(always)]
386    pub fn config(
387        &mut self,
388        config: &'b solana_program::account_info::AccountInfo<'a>,
389    ) -> &mut Self {
390        self.instruction.config = Some(config);
391        self
392    }
393    #[inline(always)]
394    pub fn admin(&mut self, admin: &'b solana_program::account_info::AccountInfo<'a>) -> &mut Self {
395        self.instruction.admin = Some(admin);
396        self
397    }
398    #[inline(always)]
399    pub fn system_program(
400        &mut self,
401        system_program: &'b solana_program::account_info::AccountInfo<'a>,
402    ) -> &mut Self {
403        self.instruction.system_program = Some(system_program);
404        self
405    }
406    #[inline(always)]
407    pub fn trade_fee_numerator(&mut self, trade_fee_numerator: u64) -> &mut Self {
408        self.instruction.trade_fee_numerator = Some(trade_fee_numerator);
409        self
410    }
411    #[inline(always)]
412    pub fn protocol_trade_fee_numerator(&mut self, protocol_trade_fee_numerator: u64) -> &mut Self {
413        self.instruction.protocol_trade_fee_numerator = Some(protocol_trade_fee_numerator);
414        self
415    }
416    #[inline(always)]
417    pub fn activation_duration(&mut self, activation_duration: u64) -> &mut Self {
418        self.instruction.activation_duration = Some(activation_duration);
419        self
420    }
421    #[inline(always)]
422    pub fn vault_config_key(&mut self, vault_config_key: Pubkey) -> &mut Self {
423        self.instruction.vault_config_key = Some(vault_config_key);
424        self
425    }
426    #[inline(always)]
427    pub fn pool_creator_authority(&mut self, pool_creator_authority: Pubkey) -> &mut Self {
428        self.instruction.pool_creator_authority = Some(pool_creator_authority);
429        self
430    }
431    #[inline(always)]
432    pub fn activation_type(&mut self, activation_type: u8) -> &mut Self {
433        self.instruction.activation_type = Some(activation_type);
434        self
435    }
436    #[inline(always)]
437    pub fn index(&mut self, index: u64) -> &mut Self {
438        self.instruction.index = Some(index);
439        self
440    }
441    #[inline(always)]
442    pub fn partner_fee_numerator(&mut self, partner_fee_numerator: u64) -> &mut Self {
443        self.instruction.partner_fee_numerator = Some(partner_fee_numerator);
444        self
445    }
446    /// Add an additional account to the instruction.
447    #[inline(always)]
448    pub fn add_remaining_account(
449        &mut self,
450        account: &'b solana_program::account_info::AccountInfo<'a>,
451        is_writable: bool,
452        is_signer: bool,
453    ) -> &mut Self {
454        self.instruction
455            .__remaining_accounts
456            .push((account, is_writable, is_signer));
457        self
458    }
459    /// Add additional accounts to the instruction.
460    ///
461    /// Each account is represented by a tuple of the `AccountInfo`, a `bool` indicating whether the account is writable or not,
462    /// and a `bool` indicating whether the account is a signer or not.
463    #[inline(always)]
464    pub fn add_remaining_accounts(
465        &mut self,
466        accounts: &[(
467            &'b solana_program::account_info::AccountInfo<'a>,
468            bool,
469            bool,
470        )],
471    ) -> &mut Self {
472        self.instruction
473            .__remaining_accounts
474            .extend_from_slice(accounts);
475        self
476    }
477    #[inline(always)]
478    pub fn invoke(&self) -> solana_program::entrypoint::ProgramResult {
479        self.invoke_signed(&[])
480    }
481    #[allow(clippy::clone_on_copy)]
482    #[allow(clippy::vec_init_then_push)]
483    pub fn invoke_signed(
484        &self,
485        signers_seeds: &[&[&[u8]]],
486    ) -> solana_program::entrypoint::ProgramResult {
487        let args = CreateConfigInstructionArgs {
488            trade_fee_numerator: self
489                .instruction
490                .trade_fee_numerator
491                .clone()
492                .expect("trade_fee_numerator is not set"),
493            protocol_trade_fee_numerator: self
494                .instruction
495                .protocol_trade_fee_numerator
496                .clone()
497                .expect("protocol_trade_fee_numerator is not set"),
498            activation_duration: self
499                .instruction
500                .activation_duration
501                .clone()
502                .expect("activation_duration is not set"),
503            vault_config_key: self
504                .instruction
505                .vault_config_key
506                .clone()
507                .expect("vault_config_key is not set"),
508            pool_creator_authority: self
509                .instruction
510                .pool_creator_authority
511                .clone()
512                .expect("pool_creator_authority is not set"),
513            activation_type: self
514                .instruction
515                .activation_type
516                .clone()
517                .expect("activation_type is not set"),
518            index: self.instruction.index.clone().expect("index is not set"),
519            partner_fee_numerator: self
520                .instruction
521                .partner_fee_numerator
522                .clone()
523                .expect("partner_fee_numerator is not set"),
524        };
525        let instruction = CreateConfigCpi {
526            __program: self.instruction.__program,
527
528            config: self.instruction.config.expect("config is not set"),
529
530            admin: self.instruction.admin.expect("admin is not set"),
531
532            system_program: self
533                .instruction
534                .system_program
535                .expect("system_program is not set"),
536            __args: args,
537        };
538        instruction.invoke_signed_with_remaining_accounts(
539            signers_seeds,
540            &self.instruction.__remaining_accounts,
541        )
542    }
543}
544
545#[derive(Clone, Debug)]
546struct CreateConfigCpiBuilderInstruction<'a, 'b> {
547    __program: &'b solana_program::account_info::AccountInfo<'a>,
548    config: Option<&'b solana_program::account_info::AccountInfo<'a>>,
549    admin: Option<&'b solana_program::account_info::AccountInfo<'a>>,
550    system_program: Option<&'b solana_program::account_info::AccountInfo<'a>>,
551    trade_fee_numerator: Option<u64>,
552    protocol_trade_fee_numerator: Option<u64>,
553    activation_duration: Option<u64>,
554    vault_config_key: Option<Pubkey>,
555    pool_creator_authority: Option<Pubkey>,
556    activation_type: Option<u8>,
557    index: Option<u64>,
558    partner_fee_numerator: Option<u64>,
559    /// Additional instruction accounts `(AccountInfo, is_writable, is_signer)`.
560    __remaining_accounts: Vec<(
561        &'b solana_program::account_info::AccountInfo<'a>,
562        bool,
563        bool,
564    )>,
565}