Skip to content
This repository was archived by the owner on Feb 9, 2025. It is now read-only.

Commit ff783ea

Browse files
authored
Upgrade spl-gov to 3.1.1 (#87)
* chore: Upgrade nft-voter to spl-gov 3.1.1 * chore: Upgrade gateway to spl-gov 3.1.1 * chore: Upgrade realm-voter to spl-gov 3.1.1
1 parent ffeeba3 commit ff783ea

File tree

16 files changed

+143
-148
lines changed

16 files changed

+143
-148
lines changed

Cargo.lock

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

programs/gateway/Cargo.toml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,13 +27,13 @@ num-derive = "0.3"
2727
num-traits = "0.2"
2828
solana-gateway = "0.2.2"
2929
solana-program = "1.14.16"
30-
spl-governance = { version = "2.2.4", features = ["no-entrypoint"] }
31-
spl-governance-tools= "0.1.2"
32-
spl-governance-addin-api = "0.1.2"
30+
spl-governance = { version = "3.1.1", features = ["no-entrypoint"] }
31+
spl-governance-tools= "0.1.3"
32+
spl-governance-addin-api = "0.1.3"
3333
spl-token = { version = "3.3", features = [ "no-entrypoint" ] }
3434

3535
[dev-dependencies]
3636
borsh = "0.9.1"
3737
solana-sdk = "1.14.16"
3838
solana-program-test = "1.14.16"
39-
spl-governance-addin-mock = "0.1.2"
39+
spl-governance-addin-mock = "0.1.3"
-189 KB
Binary file not shown.
Binary file not shown.

programs/gateway/tests/program_test/governance_test.rs

Lines changed: 41 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,16 @@ use spl_governance::{
1010
},
1111
state::{
1212
enums::{
13-
GovernanceAccountType, MintMaxVoteWeightSource, ProposalState, VoteThresholdPercentage,
13+
GovernanceAccountType, MintMaxVoterWeightSource, ProposalState, VoteThreshold,
1414
VoteTipping,
1515
},
1616
governance::get_governance_address,
1717
proposal::{get_proposal_address, ProposalV2},
18-
realm::{get_realm_address, RealmConfig, RealmV2},
19-
token_owner_record::{get_token_owner_record_address, TokenOwnerRecordV2},
18+
realm::{get_realm_address, GoverningTokenConfigAccountArgs, RealmConfig, RealmV2},
19+
realm_config::GoverningTokenType,
20+
token_owner_record::{
21+
get_token_owner_record_address, TokenOwnerRecordV2, TOKEN_OWNER_RECORD_LAYOUT_VERSION,
22+
},
2023
},
2124
};
2225

@@ -64,7 +67,7 @@ impl GovernanceTest {
6467

6568
#[allow(dead_code)]
6669
pub fn add_program(program_test: &mut ProgramTest) {
67-
program_test.add_program("spl_governance_deposit_allowed", Self::program_id(), None);
70+
program_test.add_program("spl_governance", Self::program_id(), None);
6871
}
6972

7073
#[allow(dead_code)]
@@ -93,21 +96,27 @@ impl GovernanceTest {
9396
let realm_name = format!("Realm #{}", self.next_id).to_string();
9497

9598
let min_community_weight_to_create_governance = 1;
96-
let community_mint_max_vote_weight_source = MintMaxVoteWeightSource::FULL_SUPPLY_FRACTION;
99+
let community_mint_max_voter_weight_source = MintMaxVoterWeightSource::FULL_SUPPLY_FRACTION;
97100

98101
let realm_key = get_realm_address(&self.program_id, &realm_name);
99102

103+
let community_token_config_args = GoverningTokenConfigAccountArgs {
104+
voter_weight_addin: self.community_voter_weight_addin,
105+
max_voter_weight_addin: None,
106+
token_type: GoverningTokenType::default(),
107+
};
108+
100109
let create_realm_ix = create_realm(
101110
&self.program_id,
102111
&realm_authority.pubkey(),
103112
&community_mint_cookie.address,
104113
&self.bench.payer.pubkey(),
105114
Some(council_mint_cookie.address),
106-
self.community_voter_weight_addin,
115+
Some(community_token_config_args),
107116
None,
108117
realm_name.clone(),
109118
min_community_weight_to_create_governance,
110-
community_mint_max_vote_weight_source.clone(),
119+
community_mint_max_voter_weight_source.clone(),
111120
);
112121

113122
self.bench
@@ -125,12 +134,13 @@ impl GovernanceTest {
125134
council_mint: Some(council_mint_cookie.address),
126135
reserved: [0; 6],
127136
min_community_weight_to_create_governance,
128-
community_mint_max_vote_weight_source,
129-
use_community_voter_weight_addin: false,
130-
use_max_community_voter_weight_addin: false,
137+
legacy1: 0,
138+
legacy2: 0,
139+
community_mint_max_voter_weight_source,
131140
},
132-
voting_proposal_count: 0,
141+
133142
reserved_v2: [0; 128],
143+
legacy1: 0,
134144
};
135145

136146
Ok(RealmCookie {
@@ -208,13 +218,19 @@ impl GovernanceTest {
208218
&realm_cookie.realm_authority.pubkey(),
209219
None,
210220
spl_governance::state::governance::GovernanceConfig {
211-
vote_threshold_percentage: VoteThresholdPercentage::YesVote(60),
212221
min_community_weight_to_create_proposal: 1,
213222
min_transaction_hold_up_time: 0,
214-
max_voting_time: 600,
215-
vote_tipping: VoteTipping::Disabled,
216-
proposal_cool_off_time: 0,
217223
min_council_weight_to_create_proposal: 1,
224+
225+
community_vote_threshold: VoteThreshold::YesVotePercentage(60),
226+
voting_base_time: 600,
227+
community_vote_tipping: VoteTipping::Strict,
228+
council_vote_threshold: VoteThreshold::YesVotePercentage(60),
229+
council_veto_vote_threshold: VoteThreshold::Disabled,
230+
council_vote_tipping: VoteTipping::Disabled,
231+
community_veto_vote_threshold: VoteThreshold::Disabled,
232+
voting_cool_off_time: 0,
233+
deposit_exempt_proposal_count: 10,
218234
},
219235
);
220236

@@ -225,14 +241,14 @@ impl GovernanceTest {
225241
)
226242
.await?;
227243

228-
let proposal_index: u32 = 0;
229244
let proposal_governing_token_mint = realm_cookie.account.community_mint;
245+
let proposal_seed = Pubkey::new_unique();
230246

231247
let proposal_key = get_proposal_address(
232248
&self.program_id,
233249
&governance_key,
234250
&proposal_governing_token_mint,
235-
&proposal_index.to_le_bytes(),
251+
&proposal_seed,
236252
);
237253

238254
let create_proposal_ix = create_proposal(
@@ -249,7 +265,7 @@ impl GovernanceTest {
249265
spl_governance::state::proposal::VoteType::SingleChoice,
250266
vec!["Yes".to_string()],
251267
true,
252-
0_u32,
268+
&proposal_seed,
253269
);
254270

255271
let sign_off_proposal_ix = sign_off_proposal(
@@ -276,7 +292,7 @@ impl GovernanceTest {
276292
vote_type: spl_governance::state::proposal::VoteType::SingleChoice,
277293
options: vec![],
278294
deny_vote_weight: Some(1),
279-
veto_vote_weight: None,
295+
veto_vote_weight: 0,
280296
abstain_vote_weight: None,
281297
start_voting_at: None,
282298
draft_at: 1,
@@ -289,10 +305,12 @@ impl GovernanceTest {
289305
execution_flags: spl_governance::state::enums::InstructionExecutionFlags::None,
290306
max_vote_weight: None,
291307
max_voting_time: None,
292-
vote_threshold_percentage: None,
308+
293309
reserved: [0; 64],
294310
name: String::from("Proposal #1"),
295311
description_link: String::from("Proposal #1 link"),
312+
reserved1: 0,
313+
vote_threshold: None,
296314
};
297315

298316
Ok(ProposalCookie {
@@ -362,11 +380,11 @@ impl GovernanceTest {
362380
governing_token_owner: token_owner_cookie.address,
363381
governing_token_deposit_amount: tokens_to_deposit,
364382
unrelinquished_votes_count: 0,
365-
total_votes_count: 0,
366383
outstanding_proposal_count: 0,
367-
reserved: [0; 7],
384+
reserved: [0; 6],
368385
governance_delegate: None,
369386
reserved_v2: [0; 128],
387+
version: TOKEN_OWNER_RECORD_LAYOUT_VERSION,
370388
};
371389

372390
Ok(TokenOwnerRecordCookie {
@@ -384,6 +402,7 @@ impl GovernanceTest {
384402
) -> Result<(), TransportError> {
385403
let relinquish_vote_ix = relinquish_vote(
386404
&self.program_id,
405+
&token_owner_record_cookie.account.realm,
387406
&proposal_cookie.account.governance,
388407
&proposal_cookie.address,
389408
&token_owner_record_cookie.address,

programs/nft-voter/Cargo.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,8 @@ anchor-spl = { version = "0.26.0", features = ["token"] }
2323
itertools = "0.10.2"
2424
mpl-token-metadata = { version = "=1.1.0", features = ["no-entrypoint"] }
2525
solana-program = "1.14.16"
26-
spl-governance = { version = "2.2.2", features = ["no-entrypoint"] }
27-
spl-governance-tools= "=0.1.2"
26+
spl-governance = { version = "3.1.1", features = ["no-entrypoint"] }
27+
spl-governance-tools= "0.1.3"
2828
spl-token = { version = "3.5", features = [ "no-entrypoint" ] }
2929

3030
# The explicit versions are required to compile Anchor <= 0.27.0

programs/nft-voter/src/error.rs

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,4 @@ pub enum NftVoterError {
7373

7474
#[msg("VoterWeightRecord must be expired")]
7575
VoterWeightRecordMustBeExpired,
76-
77-
#[msg("Cannot configure collection with voting proposals")]
78-
CannotConfigureCollectionWithVotingProposals,
7976
}

programs/nft-voter/src/instructions/cast_nft_vote.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,7 @@ pub fn cast_nft_vote<'a, 'b, 'c, 'info>(
116116
&id(),
117117
&ctx.accounts.system_program.to_account_info(),
118118
&rent,
119+
0,
119120
)?;
120121
}
121122

programs/nft-voter/src/instructions/configure_collection.rs

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -65,10 +65,13 @@ pub fn configure_collection(
6565
NftVoterError::InvalidRealmAuthority
6666
);
6767

68+
// spl-gov doesn't track voting_proposal_count any longer and we can't enforce the check here
69+
// It's not ideal but acceptable. The proper solution would require proposal queuing in spl-gov
70+
//
6871
// Changes to the collections config can accidentally tip the scales for outstanding proposals and hence we disallow it
69-
if realm.voting_proposal_count > 0 {
70-
return err!(NftVoterError::CannotConfigureCollectionWithVotingProposals);
71-
}
72+
// if realm.voting_proposal_count > 0 {
73+
// return err!(NftVoterError::CannotConfigureCollectionWithVotingProposals);
74+
// }
7275

7376
let collection = &ctx.accounts.collection;
7477

programs/nft-voter/src/instructions/relinquish_nft_vote.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,7 @@ pub fn relinquish_nft_vote(ctx: Context<RelinquishNftVote>) -> Result<()> {
136136
&governing_token_owner,
137137
)?;
138138

139-
dispose_account(nft_vote_record_info, &ctx.accounts.beneficiary);
139+
dispose_account(nft_vote_record_info, &ctx.accounts.beneficiary)?;
140140
}
141141

142142
// Reset VoterWeightRecord and set expiry to expired to prevent it from being used

0 commit comments

Comments
 (0)