1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
use crate::{
state::{
enums::GovernanceAccountType,
governance::{
assert_valid_create_governance_args, get_mint_governance_address_seeds, Governance,
GovernanceConfig,
},
},
tools::{
account::create_and_serialize_account_signed,
spl_token::{assert_spl_token_mint_authority_is_signer, set_spl_token_mint_authority},
},
};
use solana_program::{
account_info::{next_account_info, AccountInfo},
entrypoint::ProgramResult,
pubkey::Pubkey,
rent::Rent,
sysvar::Sysvar,
};
pub fn process_create_mint_governance(
program_id: &Pubkey,
accounts: &[AccountInfo],
config: GovernanceConfig,
transfer_mint_authority: bool,
) -> ProgramResult {
let account_info_iter = &mut accounts.iter();
let realm_info = next_account_info(account_info_iter)?;
let mint_governance_info = next_account_info(account_info_iter)?;
let governed_mint_info = next_account_info(account_info_iter)?;
let governed_mint_authority_info = next_account_info(account_info_iter)?;
let payer_info = next_account_info(account_info_iter)?;
let spl_token_info = next_account_info(account_info_iter)?;
let system_info = next_account_info(account_info_iter)?;
let rent_sysvar_info = next_account_info(account_info_iter)?;
let rent = &Rent::from_account_info(rent_sysvar_info)?;
assert_valid_create_governance_args(program_id, &config, realm_info)?;
let mint_governance_data = Governance {
account_type: GovernanceAccountType::MintGovernance,
realm: *realm_info.key,
governed_account: *governed_mint_info.key,
config,
proposals_count: 0,
reserved: [0; 8],
};
create_and_serialize_account_signed::<Governance>(
payer_info,
mint_governance_info,
&mint_governance_data,
&get_mint_governance_address_seeds(realm_info.key, governed_mint_info.key),
program_id,
system_info,
rent,
)?;
if transfer_mint_authority {
set_spl_token_mint_authority(
governed_mint_info,
governed_mint_authority_info,
mint_governance_info.key,
spl_token_info,
)?;
} else {
assert_spl_token_mint_authority_is_signer(
governed_mint_info,
governed_mint_authority_info,
)?;
}
Ok(())
}