Skip to content

Commit

Permalink
feat(multisig_add_member): use opional accounts
Browse files Browse the repository at this point in the history
  • Loading branch information
vovacodes committed Apr 19, 2023
1 parent d40c01a commit 5f98a23
Show file tree
Hide file tree
Showing 14 changed files with 182 additions and 52 deletions.
2 changes: 1 addition & 1 deletion programs/multisig/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,5 +16,5 @@ cpi = ["no-entrypoint"]
default = []

[dependencies]
anchor-lang = "=0.27.0"
anchor-lang = { version = "=0.27.0", features = ["allow-missing-optionals"] }
solana-address-lookup-table-program = "=1.14.16"
2 changes: 2 additions & 0 deletions programs/multisig/src/errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,4 +46,6 @@ pub enum MultisigError {
TimeLockNotReleased,
#[msg("Config transaction must have at least one action")]
NoActions,
#[msg("Missing account")]
MissingAccount,
}
17 changes: 12 additions & 5 deletions programs/multisig/src/instructions/multisig_config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -50,15 +50,14 @@ pub struct MultisigConfig<'info> {
/// Multisig `config_authority` that must authorize the configuration change.
pub config_authority: Signer<'info>,

// TODO: Since this account only needed for add_member, we should create a separate Accounts struct for it.
/// The account that will be charged in case the multisig account needs to reallocate space,
/// for example when adding a new member.
/// This is usually the same as `config_authority`, but can be a different account if needed.
#[account(mut)]
pub rent_payer: Signer<'info>,
pub rent_payer: Option<Signer<'info>>,

/// We might need it in case reallocation is needed.
pub system_program: Program<'info, System>,
pub system_program: Option<Program<'info, System>>,
}

impl MultisigConfig<'_> {
Expand All @@ -77,8 +76,16 @@ impl MultisigConfig<'_> {
pub fn multisig_add_member(ctx: Context<Self>, args: MultisigAddMemberArgs) -> Result<()> {
let MultisigAddMemberArgs { new_member, .. } = args;

let system_program = &ctx.accounts.system_program;
let rent_payer = &ctx.accounts.rent_payer;
let system_program = &ctx
.accounts
.system_program
.as_ref()
.ok_or(MultisigError::MissingAccount)?;
let rent_payer = &ctx
.accounts
.rent_payer
.as_ref()
.ok_or(MultisigError::MissingAccount)?;
let multisig = &mut ctx.accounts.multisig;

// Check if we need to reallocate space.
Expand Down
13 changes: 13 additions & 0 deletions sdk/multisig/idl/multisig.json
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@
"name": "rentPayer",
"isMut": true,
"isSigner": true,
"isOptional": true,
"docs": [
"The account that will be charged in case the multisig account needs to reallocate space,",
"for example when adding a new member.",
Expand All @@ -78,6 +79,7 @@
"name": "systemProgram",
"isMut": false,
"isSigner": false,
"isOptional": true,
"docs": [
"We might need it in case reallocation is needed."
]
Expand Down Expand Up @@ -115,6 +117,7 @@
"name": "rentPayer",
"isMut": true,
"isSigner": true,
"isOptional": true,
"docs": [
"The account that will be charged in case the multisig account needs to reallocate space,",
"for example when adding a new member.",
Expand All @@ -125,6 +128,7 @@
"name": "systemProgram",
"isMut": false,
"isSigner": false,
"isOptional": true,
"docs": [
"We might need it in case reallocation is needed."
]
Expand Down Expand Up @@ -162,6 +166,7 @@
"name": "rentPayer",
"isMut": true,
"isSigner": true,
"isOptional": true,
"docs": [
"The account that will be charged in case the multisig account needs to reallocate space,",
"for example when adding a new member.",
Expand All @@ -172,6 +177,7 @@
"name": "systemProgram",
"isMut": false,
"isSigner": false,
"isOptional": true,
"docs": [
"We might need it in case reallocation is needed."
]
Expand Down Expand Up @@ -209,6 +215,7 @@
"name": "rentPayer",
"isMut": true,
"isSigner": true,
"isOptional": true,
"docs": [
"The account that will be charged in case the multisig account needs to reallocate space,",
"for example when adding a new member.",
Expand All @@ -219,6 +226,7 @@
"name": "systemProgram",
"isMut": false,
"isSigner": false,
"isOptional": true,
"docs": [
"We might need it in case reallocation is needed."
]
Expand Down Expand Up @@ -1797,6 +1805,11 @@
"code": 6021,
"name": "NoActions",
"msg": "Config transaction must have at least one action"
},
{
"code": 6022,
"name": "MissingAccount",
"msg": "Missing account"
}
],
"metadata": {
Expand Down
2 changes: 1 addition & 1 deletion sdk/multisig/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
"invariant": "2.2.4"
},
"devDependencies": {
"@metaplex-foundation/solita": "0.19.3",
"@metaplex-foundation/solita": "0.19.4",
"@types/invariant": "2.2.35",
"@types/node": "18.11.17",
"typescript": "*"
Expand Down
20 changes: 20 additions & 0 deletions sdk/multisig/src/generated/errors/index.ts

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

31 changes: 23 additions & 8 deletions sdk/multisig/src/generated/instructions/multisigAddMember.ts

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

31 changes: 23 additions & 8 deletions sdk/multisig/src/generated/instructions/multisigRemoveMember.ts

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 5f98a23

Please sign in to comment.