Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 2 additions & 6 deletions programs/voter-stake-registry/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -32,12 +32,8 @@ anchor-spl = { version = "0.26.0" }

bytemuck = "1.9.1"

# WARNING: Be careful about upgrading the spl-governance dependency!
# Recently the discriminator for new VoterWeightRecord accounts has changed, and upgrading
# this dependency here without also upgrading the spl-governance program instance beforehand
# would lead to VWR accounts that are unusable until the spl-governance program is upgraded.
spl-governance = { version = "=2.2.1", features = ["no-entrypoint"] }
spl-governance-addin-api = "=0.1.1"
spl-governance = { version = "3.1.0", features = ["no-entrypoint"] }
spl-governance-addin-api = "0.1.3"

solana-program = "1.14.10"
static_assertions = "1.1"
Expand Down
5 changes: 5 additions & 0 deletions programs/voter-stake-registry/src/governance.rs
Original file line number Diff line number Diff line change
Expand Up @@ -54,5 +54,10 @@ macro_rules! vote_weight_record {
&mut self.0
}
}

impl VoterWeightRecord {
// Use the legacy account discriminator for backward compatibility with pre v2.2.5 spl-gov instances
pub const VSR_ACCOUNT_DISCRIMINATOR: [u8; 8] = *b"2ef99b4b";
}
};
}
Original file line number Diff line number Diff line change
Expand Up @@ -85,8 +85,7 @@ pub fn create_voter(
voter.registrar = ctx.accounts.registrar.key();

let voter_weight_record = &mut ctx.accounts.voter_weight_record;
voter_weight_record.account_discriminator =
spl_governance_addin_api::voter_weight::VoterWeightRecord::ACCOUNT_DISCRIMINATOR;
voter_weight_record.account_discriminator = VoterWeightRecord::VSR_ACCOUNT_DISCRIMINATOR;
voter_weight_record.realm = registrar.realm;
voter_weight_record.governing_token_mint = registrar.realm_governing_token_mint;
voter_weight_record.governing_token_owner = voter_authority;
Expand Down
3 changes: 1 addition & 2 deletions programs/voter-stake-registry/src/instructions/grant.rs
Original file line number Diff line number Diff line change
Expand Up @@ -148,8 +148,7 @@ pub fn grant(
// Note that vote_weight_record is not an Anchor account, is_freshly_initialized()
// would not work.
let voter_weight_record = &mut ctx.accounts.voter_weight_record;
voter_weight_record.account_discriminator =
spl_governance_addin_api::voter_weight::VoterWeightRecord::ACCOUNT_DISCRIMINATOR;
voter_weight_record.account_discriminator = VoterWeightRecord::VSR_ACCOUNT_DISCRIMINATOR;
voter_weight_record.realm = registrar.realm;
voter_weight_record.governing_token_mint = registrar.realm_governing_token_mint;
voter_weight_record.governing_token_owner = voter_authority;
Expand Down
Binary file not shown.
Binary file not shown.
53 changes: 39 additions & 14 deletions programs/voter-stake-registry/tests/program_test/governance.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ use std::sync::Arc;
use solana_program::instruction::Instruction;
use solana_sdk::pubkey::Pubkey;
use solana_sdk::signature::{Keypair, Signer};
use spl_governance::state::realm::GoverningTokenConfigAccountArgs;
use spl_governance::state::realm_config::GoverningTokenType;
use spl_governance::state::{proposal, vote_record};

use crate::*;
Expand Down Expand Up @@ -73,17 +75,23 @@ impl GovernanceCookie {
)
.0;

let community_token_args = GoverningTokenConfigAccountArgs {
voter_weight_addin: Some(*voter_weight_addin),
max_voter_weight_addin: None,
token_type: GoverningTokenType::Liquid,
};

let instructions = vec![spl_governance::instruction::create_realm(
&self.program_id,
&realm_authority,
&community_token_mint.pubkey.unwrap(),
&payer.pubkey(),
None,
Some(*voter_weight_addin),
Some(community_token_args),
None,
name.to_string(),
0,
spl_governance::state::enums::MintMaxVoteWeightSource::SupplyFraction(10000000000),
spl_governance::state::enums::MintMaxVoterWeightSource::SupplyFraction(10000000000),
)];

let signer = Keypair::from_base58_string(&payer.to_base58_string());
Expand Down Expand Up @@ -166,14 +174,21 @@ impl GovernanceRealmCookie {
&authority.pubkey(),
Some(voter.voter_weight_record),
spl_governance::state::governance::GovernanceConfig {
vote_threshold_percentage:
spl_governance::state::enums::VoteThresholdPercentage::YesVote(50),
community_vote_threshold:
spl_governance::state::enums::VoteThreshold::YesVotePercentage(50),
min_community_weight_to_create_proposal: 1000,
min_transaction_hold_up_time: 0,
max_voting_time: 10,
vote_tipping: spl_governance::state::enums::VoteTipping::Disabled,
proposal_cool_off_time: 0,
voting_base_time: 10,
community_vote_tipping: spl_governance::state::enums::VoteTipping::Strict,
min_council_weight_to_create_proposal: 1,
council_vote_threshold: spl_governance::state::enums::VoteThreshold::Disabled,
council_veto_vote_threshold:
spl_governance::state::enums::VoteThreshold::Disabled,
council_vote_tipping: spl_governance::state::enums::VoteTipping::Disabled,
community_veto_vote_threshold:
spl_governance::state::enums::VoteThreshold::Disabled,
voting_cool_off_time: 0,
deposit_exempt_proposal_count: 10,
},
),
];
Expand Down Expand Up @@ -221,14 +236,21 @@ impl GovernanceRealmCookie {
&authority.pubkey(),
Some(voter.voter_weight_record),
spl_governance::state::governance::GovernanceConfig {
vote_threshold_percentage:
spl_governance::state::enums::VoteThresholdPercentage::YesVote(50),
community_vote_threshold:
spl_governance::state::enums::VoteThreshold::YesVotePercentage(50),
min_community_weight_to_create_proposal: 1000,
min_transaction_hold_up_time: 0,
max_voting_time: 10,
vote_tipping: spl_governance::state::enums::VoteTipping::Disabled,
proposal_cool_off_time: 0,
voting_base_time: 10,
community_vote_tipping: spl_governance::state::enums::VoteTipping::Strict,
min_council_weight_to_create_proposal: 1,
council_vote_threshold: spl_governance::state::enums::VoteThreshold::Disabled,
council_veto_vote_threshold:
spl_governance::state::enums::VoteThreshold::Disabled,
council_vote_tipping: spl_governance::state::enums::VoteTipping::Disabled,
community_veto_vote_threshold:
spl_governance::state::enums::VoteThreshold::Disabled,
voting_cool_off_time: 0,
deposit_exempt_proposal_count: 10,
},
true,
),
Expand Down Expand Up @@ -259,11 +281,13 @@ impl GovernanceRealmCookie {
payer: &Keypair,
vwr_instruction: Instruction,
) -> std::result::Result<ProposalCookie, BanksClientError> {
let proposal_seed = Pubkey::new_unique();

let proposal = spl_governance::state::proposal::get_proposal_address(
&self.governance.program_id,
&governance,
&self.community_token_mint.pubkey.unwrap(),
&0u32.to_le_bytes(),
&proposal_seed,
);

let instructions = vec![
Expand All @@ -282,7 +306,7 @@ impl GovernanceRealmCookie {
proposal::VoteType::SingleChoice,
vec!["yes".into()],
true,
0,
&proposal_seed,
),
spl_governance::instruction::add_signatory(
&self.governance.program_id,
Expand Down Expand Up @@ -367,6 +391,7 @@ impl GovernanceRealmCookie {
) -> std::result::Result<(), BanksClientError> {
let instructions = vec![spl_governance::instruction::relinquish_vote(
&self.governance.program_id,
&self.realm,
&governance,
&proposal.address,
&token_owner_record,
Expand Down
2 changes: 1 addition & 1 deletion programs/voter-stake-registry/tests/program_test/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ impl TestContext {
let governance_program_id =
Pubkey::from_str(&"GovernanceProgramTest1111111111111111111111").unwrap();
test.add_program(
"spl_governance",
"spl_governance_3_1_0",
governance_program_id,
processor!(spl_governance::processor::process_instruction),
);
Expand Down