|
3 | 3 | use crate::{ |
4 | 4 | state::{ |
5 | 5 | governance::{ |
6 | | - get_account_governance_address, get_program_governance_address, GovernanceConfig, |
| 6 | + get_account_governance_address, get_mint_governance_address, |
| 7 | + get_program_governance_address, GovernanceConfig, |
7 | 8 | }, |
8 | 9 | proposal::get_proposal_address, |
9 | 10 | proposal_instruction::{get_proposal_instruction_address, InstructionData}, |
@@ -126,7 +127,7 @@ pub enum GovernanceInstruction { |
126 | 127 | config: GovernanceConfig, |
127 | 128 |
|
128 | 129 | #[allow(dead_code)] |
129 | | - /// Indicate whether Program's upgrade_authority should be transferred to the Governance PDA |
| 130 | + /// Indicates whether Program's upgrade_authority should be transferred to the Governance PDA |
130 | 131 | /// If it's set to false then it can be done at a later time |
131 | 132 | /// However the instruction would validate the current upgrade_authority signed the transaction nonetheless |
132 | 133 | transfer_upgrade_authority: bool, |
@@ -290,6 +291,28 @@ pub enum GovernanceInstruction { |
290 | 291 | /// 2. `[]` Clock sysvar |
291 | 292 | /// 3+ Any extra accounts that are part of the instruction, in order |
292 | 293 | ExecuteInstruction, |
| 294 | + |
| 295 | + /// Creates Mint Governance account which governs a mint |
| 296 | + /// |
| 297 | + /// 0. `[]` Realm account the created Governance belongs to |
| 298 | + /// 1. `[writable]` Mint Governance account. PDA seeds: ['mint-governance', realm, governed_mint] |
| 299 | + /// 2. `[writable]` Mint governed by this Governance account |
| 300 | + /// 3. `[signer]` Current Mint Authority |
| 301 | + /// 4. `[signer]` Payer |
| 302 | + /// 5. `[]` SPL Token program |
| 303 | + /// 6. `[]` System program |
| 304 | + /// 7. `[]` Sysvar Rent |
| 305 | + CreateMintGovernance { |
| 306 | + #[allow(dead_code)] |
| 307 | + /// Governance config |
| 308 | + config: GovernanceConfig, |
| 309 | + |
| 310 | + #[allow(dead_code)] |
| 311 | + /// Indicates whether Mint's authority should be transferred to the Governance PDA |
| 312 | + /// If it's set to false then it can be done at a later time |
| 313 | + /// However the instruction would validate the current mint authority signed the transaction nonetheless |
| 314 | + transfer_mint_authority: bool, |
| 315 | + }, |
293 | 316 | } |
294 | 317 |
|
295 | 318 | /// Creates CreateRealm instruction |
@@ -514,6 +537,42 @@ pub fn create_program_governance( |
514 | 537 | } |
515 | 538 | } |
516 | 539 |
|
| 540 | +/// Creates CreateMintGovernance instruction |
| 541 | +pub fn create_mint_governance( |
| 542 | + program_id: &Pubkey, |
| 543 | + // Accounts |
| 544 | + governed_mint_authority: &Pubkey, |
| 545 | + payer: &Pubkey, |
| 546 | + // Args |
| 547 | + config: GovernanceConfig, |
| 548 | + transfer_mint_authority: bool, |
| 549 | +) -> Instruction { |
| 550 | + let mint_governance_address = |
| 551 | + get_mint_governance_address(program_id, &config.realm, &config.governed_account); |
| 552 | + |
| 553 | + let accounts = vec![ |
| 554 | + AccountMeta::new_readonly(config.realm, false), |
| 555 | + AccountMeta::new(mint_governance_address, false), |
| 556 | + AccountMeta::new(config.governed_account, false), |
| 557 | + AccountMeta::new_readonly(*governed_mint_authority, true), |
| 558 | + AccountMeta::new_readonly(*payer, true), |
| 559 | + AccountMeta::new_readonly(spl_token::id(), false), |
| 560 | + AccountMeta::new_readonly(system_program::id(), false), |
| 561 | + AccountMeta::new_readonly(sysvar::rent::id(), false), |
| 562 | + ]; |
| 563 | + |
| 564 | + let instruction = GovernanceInstruction::CreateMintGovernance { |
| 565 | + config, |
| 566 | + transfer_mint_authority, |
| 567 | + }; |
| 568 | + |
| 569 | + Instruction { |
| 570 | + program_id: *program_id, |
| 571 | + accounts, |
| 572 | + data: instruction.try_to_vec().unwrap(), |
| 573 | + } |
| 574 | +} |
| 575 | + |
517 | 576 | /// Creates CreateProposal instruction |
518 | 577 | #[allow(clippy::too_many_arguments)] |
519 | 578 | pub fn create_proposal( |
|
0 commit comments