squads_multisig_program/instructions/
program_config_init.rs

1use crate::errors::MultisigError;
2use anchor_lang::prelude::*;
3use anchor_lang::solana_program::pubkey;
4
5use crate::state::*;
6
7/// This is a key controlled by the Squads team and is intended to use for the single
8/// transaction that initializes the global program config. It is not used for anything else.
9#[cfg(not(feature = "testing"))]
10const INITIALIZER: Pubkey = pubkey!("HM5y4mz3Bt9JY9mr1hkyhnvqxSH4H2u2451j7Hc2dtvK");
11
12#[cfg(feature = "testing")]
13const INITIALIZER: Pubkey = pubkey!("BrQAbGdWQ9YUHmWWgKFdFe4miTURH71jkYFPXfaosqDv");
14
15#[derive(AnchorSerialize, AnchorDeserialize)]
16pub struct ProgramConfigInitArgs {
17    /// The authority that can configure the program config: change the treasury, etc.
18    pub authority: Pubkey,
19    /// The fee that is charged for creating a new multisig.
20    pub multisig_creation_fee: u64,
21    /// The treasury where the creation fee is transferred to.
22    pub treasury: Pubkey,
23}
24
25#[derive(Accounts)]
26pub struct ProgramConfigInit<'info> {
27    #[account(
28        init,
29        payer = initializer,
30        space = 8 + ProgramConfig::INIT_SPACE,
31        seeds = [SEED_PREFIX, SEED_PROGRAM_CONFIG],
32        bump
33    )]
34    pub program_config: Account<'info, ProgramConfig>,
35
36    /// The hard-coded account that is used to initialize the program config once.
37    #[account(
38        mut,
39        address = INITIALIZER @ MultisigError::Unauthorized
40    )]
41    pub initializer: Signer<'info>,
42
43    pub system_program: Program<'info, System>,
44}
45
46impl ProgramConfigInit<'_> {
47    /// A one-time instruction that initializes the global program config.
48    pub fn program_config_init(ctx: Context<Self>, args: ProgramConfigInitArgs) -> Result<()> {
49        let program_config = &mut ctx.accounts.program_config;
50
51        program_config.authority = args.authority;
52        program_config.multisig_creation_fee = args.multisig_creation_fee;
53        program_config.treasury = args.treasury;
54
55        program_config.invariant()?;
56
57        Ok(())
58    }
59}