Skip to main content

multisig/
lib.rs

1#![allow(unexpected_cfgs)]
2
3use anchor_lang::prelude::*;
4
5pub mod state;
6pub use state::*;
7pub mod utils;
8pub use utils::*;
9pub mod instructions;
10use instructions::*;
11
12declare_id!("HDtNkcgMfN4CARCF4DgFo7BGBqyNjQ6LGNYKwQLkshTR");
13
14#[program]
15pub mod multisig {
16    use super::*;
17
18    /// Registers a new token mint that is controlled by the multisig
19    pub fn add_asset_mint(
20        ctx: Context<AddAssetMintInstructionAccounts>,
21        args: AddAssetMintInstructionArgs,
22    ) -> Result<()> {
23        add_asset_mint_handler(ctx, args)
24    }
25
26    /// Registers a new token account that is controlled by the multisig
27    pub fn add_asset_token(
28        ctx: Context<AddAssetTokenInstructionAccounts>,
29        args: AddAssetTokenInstructionArgs,
30    ) -> Result<()> {
31        add_asset_token_handler(ctx, args)
32    }
33
34    /// Adds a group member to a group, storing their key and weight
35    ///  and permissions, as well as the group key for indexing.
36    pub fn add_group_member(
37        ctx: Context<AddGroupMemberInstructionAccounts>,
38        args: AddGroupMemberInstructionArgs,
39    ) -> Result<()> {
40        add_group_member_handler(ctx, args)
41    }
42
43    /// Adds a pre-existing group member to govern an existing asset, storing their key and weight
44    ///  and permissions, as well as the group key and asset key for indexing.
45    pub fn add_asset_member(
46        ctx: Context<AddAssetMemberInstructionAccounts>,
47        args: AddAssetMemberInstructionArgs,
48    ) -> Result<()> {
49        add_asset_member_handler(ctx, args)
50    }
51
52    /// Updates group-wide configuration (e.g, timelock, thresholds, expiry),
53    /// it must be triggered by an approved proposal.
54    pub fn change_group_config(ctx: Context<ChangeGroupConfigInstructionAccounts>) -> Result<()> {
55        change_group_config_handler(ctx)
56    }
57
58    /// Updates asset-wide configuration (e.g, timelock, thresholds, expiry),
59    /// it must be triggered by an approved proposal.
60    pub fn change_asset_config(ctx: Context<ChangeAssetConfigInstructionAccounts>) -> Result<()> {
61        change_asset_config_handler(ctx)
62    }
63
64    /// Initializes a new governance group account with its initial configuration, seeds,
65    /// and proposal index tracking as well as other state for maintaining the multisig.
66    pub fn create_group(
67        ctx: Context<CreateGroupInstructionAccounts>,
68        args: CreateGroupInstructionArgs,
69    ) -> Result<()> {
70        create_group_handler(ctx, args)
71    }
72
73    /// Create a transaction associated with a particular proposal
74    pub fn create_proposal_transaction(
75        ctx: Context<CreateProposalTransactionInstructionAccounts>,
76        args: CreateProposalTransactionInstructionArgs,
77    ) -> Result<()> {
78        create_proposal_transaction_handler(ctx, args)
79    }
80
81    /// Creates a proposal with a transaction that uses specific assets and requires
82    /// meeting a quorom for each individual asset.
83    pub fn create_normal_proposal(
84        ctx: Context<CreateNormalProposalInstructionAccounts>,
85        args: CreateNormalProposalInstructionArgs,
86    ) -> Result<()> {
87        create_normal_proposal_handler(ctx, args)
88    }
89
90    /// Creates a proposal that targets a group or a specific asset and requires
91    /// meeting a quorom for that group or asset to change it's config
92    pub fn create_config_proposal(
93        ctx: Context<CreateConfigProposalInstructionAccounts>,
94        args: CreateConfigProposalInstructionArgs,
95    ) -> Result<()> {
96        create_config_proposal_handler(ctx, args)
97    }
98
99    /// Execute a transaction associated with a particular proposal
100    pub fn execute_proposal_transaction(
101        ctx: Context<ExecuteProposalTransactionInstructionAccounts>,
102    ) -> Result<()> {
103        execute_proposal_transaction_handler(ctx)
104    }
105
106    /// Removes an existing group member once a proposal to remove them has passed,
107    /// closes their GroupMember account and sends the rent to the rent_collector.
108    pub fn remove_group_member(ctx: Context<RemoveGroupMemberInstructionAccounts>) -> Result<()> {
109        remove_group_member_handler(ctx)
110    }
111
112    /// Removes an existing asset member once a proposal to remove them has passed,
113    /// closes their AssetMember account and sends the rent to the rent_collector.
114    /// It is not checked that they have a corresponding group account since one(AssetMember) could
115    /// exist without the other(GroupMember).
116    pub fn remove_asset_member(ctx: Context<RemoveAssetMemberInstructionAccounts>) -> Result<()> {
117        remove_asset_member_handler(ctx)
118    }
119
120    /// Vote on a proposal that would execute a transaction and uses assets
121    /// controlled by the multisig if passed.
122    pub fn vote_on_normal_proposal(
123        ctx: Context<VoteOnNormalProposalInstructionAccounts>,
124        args: VoteOnNormalProposalInstructionArgs,
125    ) -> Result<()> {
126        vote_on_normal_proposal_handler(ctx, args)
127    }
128
129    /// Vote on a proposal that changes the configuration of a group or asset if passed.
130    pub fn vote_on_config_proposal(
131        ctx: Context<VoteOnConfigProposalInstructionAccounts>,
132        args: VoteOnConfigProposalInstructionArgs,
133    ) -> Result<()> {
134        vote_on_config_proposal_handler(ctx, args)
135    }
136
137    /// Close a proposal transaction that though was finalized after the proposal was passed
138    /// and active(no config had changed), execution was delayed till after a config changed
139    /// and refund the rent to the proposal
140    pub fn close_proposal_transaction_instruction(
141        ctx: Context<CloseProposalTransactionInstructionAccounts>,
142    ) -> Result<()> {
143        close_proposal_transaction_handler(ctx)
144    }
145
146    /// Close a config proposal that failed or expired and refund the rent to the proposer
147    pub fn close_proposal_instruction(
148        ctx: Context<CloseProposalInstructionAccounts>,
149    ) -> Result<()> {
150        close_proposal_handler(ctx)
151    }
152
153    /// Close a normal proposal that failed, expired, or became stale and refund the rent to the proposer
154    pub fn close_normal_proposal_instruction(
155        ctx: Context<CloseNormalProposalInstructionAccounts>,
156    ) -> Result<()> {
157        close_normal_proposal_handler(ctx)
158    }
159
160    /// Close an asset member account that has had it's group member account removed(by a proposal)
161    /// the rent is sent to the rent collector
162    pub fn clean_up_asset_member_instruction(
163        ctx: Context<CleanUpAssetMemberInstructionAccounts>,
164    ) -> Result<()> {
165        clean_up_asset_member_handler(ctx)
166    }
167
168    /// Close a vote record for a normal proposal, the rent is refunded to the voter
169    pub fn close_normal_vote_record_instruction(
170        ctx: Context<CloseNormalVoteRecordInstructionAccounts>,
171        args: CloseNormalVoteRecordInstructionArgs,
172    ) -> Result<()> {
173        close_normal_vote_record_handler(ctx, args)
174    }
175
176    /// Close a vote record for a config proposal, the rent is refunded to the voter
177    pub fn close_config_vote_record_instruction(
178        ctx: Context<CloseConfigVoteRecordInstructionAccounts>,
179    ) -> Result<()> {
180        close_config_vote_record_handler(ctx)
181    }
182
183    /// Creates an emergency reset proposal with three designated trusted members.
184    /// If all group members vote For it passes; if all vote Against it fails.
185    /// No stake checks are bypassed - the proposal simply requires unanimous agreement.
186    pub fn create_emergency_reset_proposal(
187        ctx: Context<CreateEmergencyResetProposalAccounts>,
188        args: CreateEmergencyResetProposalArgs,
189    ) -> Result<()> {
190        create_emergency_reset_proposal_handler(ctx, args)
191    }
192
193    /// Cast or change a vote on an emergency reset proposal.
194    pub fn vote_on_emergency_reset_proposal(
195        ctx: Context<VoteOnEmergencyResetAccounts>,
196        args: VoteOnEmergencyResetArgs,
197    ) -> Result<()> {
198        vote_on_emergency_reset_handler(ctx, args)
199    }
200
201    /// Execute a passed emergency reset proposal, pausing the group and
202    /// storing the three trusted member keys for pause-mode governance.
203    pub fn execute_emergency_reset(ctx: Context<ExecuteEmergencyResetAccounts>) -> Result<()> {
204        execute_emergency_reset_handler(ctx)
205    }
206
207    /// Close an emergency reset proposal that has failed or expired, refunding rent.
208    pub fn close_emergency_reset_proposal(
209        ctx: Context<CloseEmergencyResetProposalAccounts>,
210    ) -> Result<()> {
211        close_emergency_reset_proposal_handler(ctx)
212    }
213
214    /// Close a vote record for an emergency reset proposal, refunding rent to the voter.
215    pub fn close_emergency_reset_vote_record(
216        ctx: Context<CloseEmergencyResetVoteRecordAccounts>,
217    ) -> Result<()> {
218        close_emergency_reset_vote_record_handler(ctx)
219    }
220
221    /// Add a group member while the group is in emergency pause mode.
222    /// Requires all three trusted members to sign.
223    pub fn add_member_in_reset_mode(
224        ctx: Context<AddMemberInResetModeAccounts>,
225        args: AddMemberInResetModeArgs,
226    ) -> Result<()> {
227        add_member_in_reset_mode_handler(ctx, args)
228    }
229
230    /// Remove a group member while the group is in emergency pause mode.
231    /// Requires all three trusted members to sign.
232    pub fn remove_member_in_reset_mode(
233        ctx: Context<RemoveMemberInResetModeAccounts>,
234    ) -> Result<()> {
235        remove_member_in_reset_mode_handler(ctx)
236    }
237
238    /// Lift the emergency pause mode, restoring normal group operation.
239    /// Requires all three trusted members to sign and the group to pass validity checks.
240    pub fn exit_pause_mode(
241        ctx: Context<ExitPauseModeAccounts>,
242        args: ExitPauseModeArgs,
243    ) -> Result<()> {
244        exit_pause_mode_handler(ctx, args)
245    }
246}