Skip to content

Commit 76c1d5a

Browse files
committed
feat(multisig_set_time_lock, multisig_set_config_authority): implement ixs and sdk
1 parent 209c3c0 commit 76c1d5a

25 files changed

+769
-22
lines changed

programs/multisig/src/events.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,8 @@ pub enum ConfigUpdateType {
1616
AddMember { reallocated: bool },
1717
RemoveMember,
1818
ChangeThreshold,
19-
ChangeConfigAuthority,
20-
ChangeAllowExternalExecute,
19+
SetConfigAuthority,
20+
SetTimeLock,
2121
}
2222

2323
/// Multisig config is updated.

programs/multisig/src/instructions/multisig_config.rs

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,20 @@ pub struct MultisigChangeThresholdArgs {
2525
pub memo: Option<String>,
2626
}
2727

28+
#[derive(AnchorSerialize, AnchorDeserialize)]
29+
pub struct MultisigSetTimeLockArgs {
30+
time_lock: u32,
31+
/// Memo isn't used for anything, but is included in `ChangeThreshold` that can later be parsed and indexed.
32+
pub memo: Option<String>,
33+
}
34+
35+
#[derive(AnchorSerialize, AnchorDeserialize)]
36+
pub struct MultisigSetConfigAuthorityArgs {
37+
config_authority: Pubkey,
38+
/// Memo isn't used for anything, but is included in `ChangeThreshold` that can later be parsed and indexed.
39+
pub memo: Option<String>,
40+
}
41+
2842
#[derive(Accounts)]
2943
pub struct MultisigConfig<'info> {
3044
#[account(
@@ -37,6 +51,7 @@ pub struct MultisigConfig<'info> {
3751
/// Multisig `config_authority` that must authorize the configuration change.
3852
pub config_authority: Signer<'info>,
3953

54+
// TODO: Since this account only needed for add_member, we should create a separate Accounts struct for it.
4055
/// The account that will be charged in case the multisig account needs to reallocate space,
4156
/// for example when adding a new member.
4257
/// This is usually the same as `config_authority`, but can be a different account if needed.
@@ -143,4 +158,41 @@ impl MultisigConfig<'_> {
143158

144159
Ok(())
145160
}
161+
162+
/// Set the `time_lock` config parameter for the multisig.
163+
#[access_control(ctx.accounts.validate())]
164+
pub fn multisig_set_time_lock(ctx: Context<Self>, args: MultisigSetTimeLockArgs) -> Result<()> {
165+
let multisig = &mut ctx.accounts.multisig;
166+
let multisig_key = multisig.key();
167+
168+
multisig.time_lock = args.time_lock;
169+
170+
multisig.invariant()?;
171+
172+
multisig.config_updated(multisig_key, ConfigUpdateType::SetTimeLock, args.memo);
173+
174+
Ok(())
175+
}
176+
177+
/// Set the multisig `config_authority`.
178+
#[access_control(ctx.accounts.validate())]
179+
pub fn multisig_set_config_authority(
180+
ctx: Context<Self>,
181+
args: MultisigSetConfigAuthorityArgs,
182+
) -> Result<()> {
183+
let multisig = &mut ctx.accounts.multisig;
184+
let multisig_key = multisig.key();
185+
186+
multisig.config_authority = args.config_authority;
187+
188+
multisig.invariant()?;
189+
190+
multisig.config_updated(
191+
multisig_key,
192+
ConfigUpdateType::SetConfigAuthority,
193+
args.memo,
194+
);
195+
196+
Ok(())
197+
}
146198
}

programs/multisig/src/instructions/multisig_create.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ pub struct MultisigCreateArgs {
1313
/// The members of the multisig.
1414
pub members: Vec<Member>,
1515
/// How many seconds must pass between transaction voting settlement and execution.
16-
pub time_lock: i32,
16+
pub time_lock: u32,
1717
/// Memo isn't used for anything, but is included in `CreatedEvent` that can later be parsed and indexed.
1818
pub memo: Option<String>,
1919
}

programs/multisig/src/lib.rs

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,22 @@ pub mod multisig {
4444
MultisigConfig::multisig_remove_member(ctx, args)
4545
}
4646

47+
/// Set the `time_lock` config parameter for the multisig.
48+
pub fn multisig_set_time_lock(
49+
ctx: Context<MultisigConfig>,
50+
args: MultisigSetTimeLockArgs,
51+
) -> Result<()> {
52+
MultisigConfig::multisig_set_time_lock(ctx, args)
53+
}
54+
55+
/// Set the multisig `config_authority`.
56+
pub fn multisig_set_config_authority(
57+
ctx: Context<MultisigConfig>,
58+
args: MultisigSetConfigAuthorityArgs,
59+
) -> Result<()> {
60+
MultisigConfig::multisig_set_config_authority(ctx, args)
61+
}
62+
4763
/// Create a new config transaction.
4864
pub fn config_transaction_create(
4965
ctx: Context<ConfigTransactionCreate>,

programs/multisig/src/state/multisig.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,11 +23,11 @@ pub struct Multisig {
2323
/// Threshold for signatures.
2424
pub threshold: u16,
2525
/// How many seconds must pass between transaction voting settlement and execution.
26-
pub time_lock: i32,
26+
pub time_lock: u32,
2727
/// Last transaction index. 0 means no transactions have been created.
2828
pub transaction_index: u64,
2929
/// Last stale transaction index. All transactions up until this index are stale.
30-
/// This index is updated when multisig config (members/threshold) changes.
30+
/// This index is updated when multisig config (members/threshold/time_lock) changes.
3131
pub stale_transaction_index: u64,
3232
/// Index to track the last created vault for this multisig.
3333
pub vault_index: u8,

sdk/multisig/idl/multisig.json

Lines changed: 141 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,100 @@
139139
}
140140
]
141141
},
142+
{
143+
"name": "multisigSetTimeLock",
144+
"docs": [
145+
"Set the `time_lock` config parameter for the multisig."
146+
],
147+
"accounts": [
148+
{
149+
"name": "multisig",
150+
"isMut": true,
151+
"isSigner": false
152+
},
153+
{
154+
"name": "configAuthority",
155+
"isMut": false,
156+
"isSigner": true,
157+
"docs": [
158+
"Multisig `config_authority` that must authorize the configuration change."
159+
]
160+
},
161+
{
162+
"name": "rentPayer",
163+
"isMut": true,
164+
"isSigner": true,
165+
"docs": [
166+
"The account that will be charged in case the multisig account needs to reallocate space,",
167+
"for example when adding a new member.",
168+
"This is usually the same as `config_authority`, but can be a different account if needed."
169+
]
170+
},
171+
{
172+
"name": "systemProgram",
173+
"isMut": false,
174+
"isSigner": false,
175+
"docs": [
176+
"We might need it in case reallocation is needed."
177+
]
178+
}
179+
],
180+
"args": [
181+
{
182+
"name": "args",
183+
"type": {
184+
"defined": "MultisigSetTimeLockArgs"
185+
}
186+
}
187+
]
188+
},
189+
{
190+
"name": "multisigSetConfigAuthority",
191+
"docs": [
192+
"Set the multisig `config_authority`."
193+
],
194+
"accounts": [
195+
{
196+
"name": "multisig",
197+
"isMut": true,
198+
"isSigner": false
199+
},
200+
{
201+
"name": "configAuthority",
202+
"isMut": false,
203+
"isSigner": true,
204+
"docs": [
205+
"Multisig `config_authority` that must authorize the configuration change."
206+
]
207+
},
208+
{
209+
"name": "rentPayer",
210+
"isMut": true,
211+
"isSigner": true,
212+
"docs": [
213+
"The account that will be charged in case the multisig account needs to reallocate space,",
214+
"for example when adding a new member.",
215+
"This is usually the same as `config_authority`, but can be a different account if needed."
216+
]
217+
},
218+
{
219+
"name": "systemProgram",
220+
"isMut": false,
221+
"isSigner": false,
222+
"docs": [
223+
"We might need it in case reallocation is needed."
224+
]
225+
}
226+
],
227+
"args": [
228+
{
229+
"name": "args",
230+
"type": {
231+
"defined": "MultisigSetConfigAuthorityArgs"
232+
}
233+
}
234+
]
235+
},
142236
{
143237
"name": "configTransactionCreate",
144238
"docs": [
@@ -547,7 +641,7 @@
547641
"docs": [
548642
"How many seconds must pass between transaction voting settlement and execution."
549643
],
550-
"type": "i32"
644+
"type": "u32"
551645
},
552646
{
553647
"name": "transactionIndex",
@@ -560,7 +654,7 @@
560654
"name": "staleTransactionIndex",
561655
"docs": [
562656
"Last stale transaction index. All transactions up until this index are stale.",
563-
"This index is updated when multisig config (members/threshold) changes."
657+
"This index is updated when multisig config (members/threshold/time_lock) changes."
564658
],
565659
"type": "u64"
566660
},
@@ -828,6 +922,48 @@
828922
]
829923
}
830924
},
925+
{
926+
"name": "MultisigSetTimeLockArgs",
927+
"type": {
928+
"kind": "struct",
929+
"fields": [
930+
{
931+
"name": "timeLock",
932+
"type": "u32"
933+
},
934+
{
935+
"name": "memo",
936+
"docs": [
937+
"Memo isn't used for anything, but is included in `ChangeThreshold` that can later be parsed and indexed."
938+
],
939+
"type": {
940+
"option": "string"
941+
}
942+
}
943+
]
944+
}
945+
},
946+
{
947+
"name": "MultisigSetConfigAuthorityArgs",
948+
"type": {
949+
"kind": "struct",
950+
"fields": [
951+
{
952+
"name": "configAuthority",
953+
"type": "publicKey"
954+
},
955+
{
956+
"name": "memo",
957+
"docs": [
958+
"Memo isn't used for anything, but is included in `ChangeThreshold` that can later be parsed and indexed."
959+
],
960+
"type": {
961+
"option": "string"
962+
}
963+
}
964+
]
965+
}
966+
},
831967
{
832968
"name": "MultisigCreateArgs",
833969
"type": {
@@ -866,7 +1002,7 @@
8661002
"docs": [
8671003
"How many seconds must pass between transaction voting settlement and execution."
8681004
],
869-
"type": "i32"
1005+
"type": "u32"
8701006
},
8711007
{
8721008
"name": "memo",
@@ -1128,10 +1264,10 @@
11281264
"name": "ChangeThreshold"
11291265
},
11301266
{
1131-
"name": "ChangeConfigAuthority"
1267+
"name": "SetConfigAuthority"
11321268
},
11331269
{
1134-
"name": "ChangeAllowExternalExecute"
1270+
"name": "SetTimeLock"
11351271
}
11361272
]
11371273
}

sdk/multisig/src/generated/accounts/Multisig.ts

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

sdk/multisig/src/generated/instructions/index.ts

Lines changed: 2 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)