Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update governance #11

Merged
merged 3 commits into from
Jul 12, 2024
Merged
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
426 changes: 223 additions & 203 deletions Cargo.lock

Large diffs are not rendered by default.

8 changes: 8 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,13 @@ members = [
# Otherwise the build will fail since Anchor uploads only parts of the source tree.
]

[workspace.dependencies]
solana-program = "1.14.10"
solana-sdk = "1.14.10"
solana-program-test = "1.14.10"
anchor-lang = "0.26.0"
anchor-spl = "0.26.0"
static_assertions = "1.1"

[profile.release]
overflow-checks = true
8 changes: 4 additions & 4 deletions program-states/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
cargo-features = ["workspace-inheritance"]
[package]
name = "mplx-staking-states"
version = "0.0.1"
Expand All @@ -14,7 +15,6 @@ crate-type = ["cdylib", "lib"]
test-sbf = []

[dependencies]
anchor-lang = { version = "0.26.0", features = ["init-if-needed"] }
anchor-spl = { version = "0.26.0" }
static_assertions = "1.1"
bytemuck = "1.9.1"
anchor-lang = { workspace = true, features = ["init-if-needed"] }
anchor-spl = { workspace = true }
static_assertions = { workspace = true }
29 changes: 9 additions & 20 deletions programs/voter-stake-registry/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
cargo-features = ["workspace-inheritance"]
[package]
name = "voter-stake-registry"
version = "0.2.4"
Expand All @@ -21,31 +22,19 @@ test-sbf = []

[dependencies]
# a) for deployment use these
anchor-lang = { version = "0.26.0", features = ["init-if-needed"] }
anchor-spl = { version = "0.26.0" }
# b) while testing, use below dependencies for debugging instead of above ones
# anchor-lang = { git = "https://github.com/microwavedcola1/anchor.git", branch = "master-debug" }
# anchor-spl = { git = "https://github.com/microwavedcola1/anchor.git", branch = "master-debug", features = ["governance"]}

# The rev used for spl-governance must match what the fixture binary
# programs/voter-stake-registry/tests/fixtures/spl_governance.so is built from.
anchor-lang = { workspace = true, features = ["init-if-needed"] }
anchor-spl = { workspace = true }
solana-program = { workspace = true }
static_assertions = { workspace = true }

bytemuck = "1.9.1"

# WARNING: Be careful about upgrading the spl-governance dependency!
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is this warning not relevant anymore?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think it was even the case for our instance

# 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"

solana-program = "1.14.10"
static_assertions = "1.1"
spl-governance = { version = "3.1.1", features = ["no-entrypoint"] }
spl-governance-addin-api = "0.1.3"
mplx-staking-states = { path="../../program-states" }

[dev-dependencies]
solana-sdk = "1.14.10"
solana-program-test = "1.14.10"
solana-sdk = { workspace = true }
solana-program-test = { workspace = true }
spl-token = { version = "^3.0.0", features = ["no-entrypoint"] }
spl-associated-token-account = { version = "^1.0.3", features = ["no-entrypoint"] }
log = "0.4.14"
Expand Down
Binary file not shown.
Binary file not shown.
51 changes: 37 additions & 14 deletions programs/voter-stake-registry/tests/program_test/governance.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ use solana_sdk::{
pubkey::Pubkey,
signature::{Keypair, Signer},
};
use spl_governance::state::realm::GoverningTokenConfigAccountArgs;
use spl_governance::state::realm_config::GoverningTokenType;
use spl_governance::state::{proposal, vote_record};
use std::rc::Rc;

Expand Down Expand Up @@ -73,17 +75,22 @@ 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 +173,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::Disabled,
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 +235,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 +280,12 @@ impl GovernanceRealmCookie {
payer: &Keypair,
vwr_instruction: Instruction,
) -> std::result::Result<ProposalCookie, TransportError> {
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 +304,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 +389,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 @@ -121,7 +121,7 @@ impl TestContext {
let governance_program_id =
Pubkey::from_str("GovernanceProgramTest1111111111111111111111").unwrap();
test.add_program(
"spl_governance",
"spl_governance_3_1_1",
governance_program_id,
processor!(spl_governance::processor::process_instruction),
);
Expand Down
Loading