-
Notifications
You must be signed in to change notification settings - Fork 36
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(program-config): add ProgramConfig and instructions that work wi…
…th it
- Loading branch information
Showing
43 changed files
with
2,955 additions
and
360 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
80 changes: 80 additions & 0 deletions
80
programs/squads_multisig_program/src/instructions/program_config.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
use anchor_lang::prelude::*; | ||
|
||
use crate::errors::MultisigError; | ||
|
||
#[derive(AnchorSerialize, AnchorDeserialize)] | ||
pub struct ProgramConfigSetAuthorityArgs { | ||
pub new_authority: Pubkey, | ||
} | ||
|
||
#[derive(AnchorSerialize, AnchorDeserialize)] | ||
pub struct ProgramConfigSetMultisigCreationFeeArgs { | ||
pub new_multisig_creation_fee: u64, | ||
} | ||
|
||
#[derive(AnchorSerialize, AnchorDeserialize)] | ||
pub struct ProgramConfigSetTreasuryArgs { | ||
pub new_treasury: Pubkey, | ||
} | ||
|
||
#[derive(Accounts)] | ||
pub struct ProgramConfig<'info> { | ||
#[account(mut)] | ||
pub program_config: Account<'info, crate::state::ProgramConfig>, | ||
|
||
pub authority: Signer<'info>, | ||
} | ||
|
||
impl ProgramConfig<'_> { | ||
fn validate(&self) -> Result<()> { | ||
let Self { | ||
program_config, | ||
authority, | ||
} = self; | ||
|
||
// authority | ||
require_keys_eq!( | ||
program_config.authority, | ||
authority.key(), | ||
MultisigError::Unauthorized | ||
); | ||
|
||
Ok(()) | ||
} | ||
|
||
#[access_control(ctx.accounts.validate())] | ||
pub fn program_config_set_authority( | ||
ctx: Context<Self>, | ||
args: ProgramConfigSetAuthorityArgs, | ||
) -> Result<()> { | ||
let program_config = &mut ctx.accounts.program_config; | ||
|
||
program_config.authority = args.new_authority; | ||
|
||
Ok(()) | ||
} | ||
|
||
#[access_control(ctx.accounts.validate())] | ||
pub fn program_config_set_multisig_creation_fee( | ||
ctx: Context<Self>, | ||
args: ProgramConfigSetMultisigCreationFeeArgs, | ||
) -> Result<()> { | ||
let program_config = &mut ctx.accounts.program_config; | ||
|
||
program_config.multisig_creation_fee = args.new_multisig_creation_fee; | ||
|
||
Ok(()) | ||
} | ||
|
||
#[access_control(ctx.accounts.validate())] | ||
pub fn program_config_set_treasury( | ||
ctx: Context<Self>, | ||
args: ProgramConfigSetTreasuryArgs, | ||
) -> Result<()> { | ||
let program_config = &mut ctx.accounts.program_config; | ||
|
||
program_config.treasury = args.new_treasury; | ||
|
||
Ok(()) | ||
} | ||
} |
59 changes: 59 additions & 0 deletions
59
programs/squads_multisig_program/src/instructions/program_config_init.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
use crate::errors::MultisigError; | ||
use anchor_lang::prelude::*; | ||
use anchor_lang::solana_program::pubkey; | ||
|
||
use crate::state::*; | ||
|
||
/// This is a key controlled by the Squads team and is intended to use for the single | ||
/// transaction that initializes the global program config. It is not used for anything else. | ||
#[cfg(not(feature = "testing"))] | ||
const INITIALIZER: Pubkey = pubkey!("HM5y4mz3Bt9JY9mr1hkyhnvqxSH4H2u2451j7Hc2dtvK"); | ||
|
||
#[cfg(feature = "testing")] | ||
const INITIALIZER: Pubkey = pubkey!("BrQAbGdWQ9YUHmWWgKFdFe4miTURH71jkYFPXfaosqDv"); | ||
|
||
#[derive(AnchorSerialize, AnchorDeserialize)] | ||
pub struct ProgramConfigInitArgs { | ||
/// The authority that can configure the program config: change the treasury, etc. | ||
pub authority: Pubkey, | ||
/// The fee that is charged for creating a new multisig. | ||
pub multisig_creation_fee: u64, | ||
/// The treasury where the creation fee is transferred to. | ||
pub treasury: Pubkey, | ||
} | ||
|
||
#[derive(Accounts)] | ||
pub struct ProgramConfigInit<'info> { | ||
#[account( | ||
init, | ||
payer = initializer, | ||
space = 8 + ProgramConfig::INIT_SPACE, | ||
seeds = [SEED_PREFIX, SEED_PROGRAM_CONFIG], | ||
bump | ||
)] | ||
pub program_config: Account<'info, ProgramConfig>, | ||
|
||
/// The hard-coded account that is used to initialize the program config once. | ||
#[account( | ||
mut, | ||
address = INITIALIZER @ MultisigError::Unauthorized | ||
)] | ||
pub initializer: Signer<'info>, | ||
|
||
pub system_program: Program<'info, System>, | ||
} | ||
|
||
impl ProgramConfigInit<'_> { | ||
/// A one-time instruction that initializes the global program config. | ||
pub fn program_config_init(ctx: Context<Self>, args: ProgramConfigInitArgs) -> Result<()> { | ||
let program_config = &mut ctx.accounts.program_config; | ||
|
||
program_config.authority = args.authority; | ||
program_config.multisig_creation_fee = args.multisig_creation_fee; | ||
program_config.treasury = args.treasury; | ||
|
||
program_config.invariant()?; | ||
|
||
Ok(()) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.