squads_multisig_program/state/
config_transaction.rs

1use anchor_lang::prelude::*;
2use anchor_lang::solana_program::borsh0_10::get_instance_packed_len;
3
4use super::*;
5
6/// Stores data required for execution of a multisig configuration transaction.
7/// Config transaction can perform a predefined set of actions on the Multisig PDA, such as adding/removing members,
8/// changing the threshold, etc.
9#[account]
10pub struct ConfigTransaction {
11    /// The multisig this belongs to.
12    pub multisig: Pubkey,
13    /// Member of the Multisig who submitted the transaction.
14    pub creator: Pubkey,
15    /// Index of this transaction within the multisig.
16    pub index: u64,
17    /// bump for the transaction seeds.
18    pub bump: u8,
19    /// Action to be performed on the multisig.
20    pub actions: Vec<ConfigAction>,
21}
22
23impl ConfigTransaction {
24    pub fn size(actions: &[ConfigAction]) -> usize {
25        let actions_size: usize = actions
26            .iter()
27            .map(|action| get_instance_packed_len(action).unwrap())
28            .sum();
29
30        8 +   // anchor account discriminator
31        32 +  // multisig
32        32 +  // creator
33        8 +   // index
34        1 +   // bump 
35        4 +  // actions vector length
36        actions_size
37    }
38}
39
40#[derive(AnchorSerialize, AnchorDeserialize, Clone, PartialEq, Eq)]
41#[non_exhaustive]
42pub enum ConfigAction {
43    /// Add a new member to the multisig.
44    AddMember { new_member: Member },
45    /// Remove a member from the multisig.
46    RemoveMember { old_member: Pubkey },
47    /// Change the `threshold` of the multisig.
48    ChangeThreshold { new_threshold: u16 },
49    /// Change the `time_lock` of the multisig.
50    SetTimeLock { new_time_lock: u32 },
51    /// Change the `time_lock` of the multisig.
52    AddSpendingLimit {
53        /// Key that is used to seed the SpendingLimit PDA.
54        create_key: Pubkey,
55        /// The index of the vault that the spending limit is for.
56        vault_index: u8,
57        /// The token mint the spending limit is for.
58        mint: Pubkey,
59        /// The amount of tokens that can be spent in a period.
60        /// This amount is in decimals of the mint,
61        /// so 1 SOL would be `1_000_000_000` and 1 USDC would be `1_000_000`.
62        amount: u64,
63        /// The reset period of the spending limit.
64        /// When it passes, the remaining amount is reset, unless it's `Period::OneTime`.
65        period: Period,
66        /// Members of the multisig that can use the spending limit.
67        /// In case a member is removed from the multisig, the spending limit will remain existent
68        /// (until explicitly deleted), but the removed member will not be able to use it anymore.
69        members: Vec<Pubkey>,
70        /// The destination addresses the spending limit is allowed to sent funds to.
71        /// If empty, funds can be sent to any address.
72        destinations: Vec<Pubkey>,
73    },
74    /// Remove a spending limit from the multisig.
75    RemoveSpendingLimit { spending_limit: Pubkey },
76    /// Set the `rent_collector` config parameter of the multisig.
77    SetRentCollector { new_rent_collector: Option<Pubkey> },
78}