Upgrade spl-governance version (#30)
Upgrade to latest spl-governance Co-authored-by: microwavedcola1 <microwavedcola@gmail.com>
This commit is contained in:
parent
e1980488bd
commit
1a577eb7bd
File diff suppressed because it is too large
Load Diff
|
@ -20,14 +20,15 @@ test-bpf = []
|
|||
[dependencies]
|
||||
# a) for deployment use these
|
||||
anchor-lang = "0.20.1"
|
||||
anchor-spl = { version = "0.20.1", features = ["governance"]}
|
||||
anchor-spl = { version = "0.20.1" }
|
||||
# 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.
|
||||
spl-governance = { git = "https://github.com/solana-labs/solana-program-library", rev = "1a0155e34bf96489db2cd498be79ca417c87c09f", features = ["no-entrypoint"] }
|
||||
spl-governance = { git = "https://github.com/solana-labs/solana-program-library", rev = "ebc91e871a0b39bf76fbce52c6da87c9b674cf4e", features = ["no-entrypoint"] }
|
||||
spl-governance-addin-api = { git = "https://github.com/solana-labs/solana-program-library", rev = "ebc91e871a0b39bf76fbce52c6da87c9b674cf4e" }
|
||||
|
||||
# refer solana to the same version anchor-lang 0.20.1 refers to
|
||||
solana-program = "1.8.5"
|
||||
|
|
|
@ -0,0 +1,63 @@
|
|||
/// A macro is exposed so that we can embed the program ID.
|
||||
#[macro_export]
|
||||
macro_rules! vote_weight_record {
|
||||
($id:expr) => {
|
||||
/// Anchor wrapper for the SPL governance program's VoterWeightRecord type.
|
||||
#[derive(Clone)]
|
||||
pub struct VoterWeightRecord(spl_governance_addin_api::voter_weight::VoterWeightRecord);
|
||||
|
||||
impl anchor_lang::AccountDeserialize for VoterWeightRecord {
|
||||
fn try_deserialize(buf: &mut &[u8]) -> std::result::Result<Self, ProgramError> {
|
||||
let mut data = buf;
|
||||
let vwr: spl_governance_addin_api::voter_weight::VoterWeightRecord =
|
||||
anchor_lang::AnchorDeserialize::deserialize(&mut data)
|
||||
.map_err(|_| anchor_lang::__private::ErrorCode::AccountDidNotDeserialize)?;
|
||||
if !solana_program::program_pack::IsInitialized::is_initialized(&vwr) {
|
||||
return Err(anchor_lang::__private::ErrorCode::AccountDidNotSerialize.into());
|
||||
}
|
||||
Ok(VoterWeightRecord(vwr))
|
||||
}
|
||||
|
||||
fn try_deserialize_unchecked(
|
||||
buf: &mut &[u8],
|
||||
) -> std::result::Result<Self, ProgramError> {
|
||||
let mut data = buf;
|
||||
let vwr: spl_governance_addin_api::voter_weight::VoterWeightRecord =
|
||||
anchor_lang::AnchorDeserialize::deserialize(&mut data)
|
||||
.map_err(|_| anchor_lang::__private::ErrorCode::AccountDidNotDeserialize)?;
|
||||
Ok(VoterWeightRecord(vwr))
|
||||
}
|
||||
}
|
||||
|
||||
impl anchor_lang::AccountSerialize for VoterWeightRecord {
|
||||
fn try_serialize<W: std::io::Write>(
|
||||
&self,
|
||||
writer: &mut W,
|
||||
) -> std::result::Result<(), ProgramError> {
|
||||
anchor_lang::AnchorSerialize::serialize(&self.0, writer)
|
||||
.map_err(|_| anchor_lang::__private::ErrorCode::AccountDidNotSerialize)?;
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
||||
impl anchor_lang::Owner for VoterWeightRecord {
|
||||
fn owner() -> Pubkey {
|
||||
$id
|
||||
}
|
||||
}
|
||||
|
||||
impl std::ops::Deref for VoterWeightRecord {
|
||||
type Target = spl_governance_addin_api::voter_weight::VoterWeightRecord;
|
||||
|
||||
fn deref(&self) -> &Self::Target {
|
||||
&self.0
|
||||
}
|
||||
}
|
||||
|
||||
impl std::ops::DerefMut for VoterWeightRecord {
|
||||
fn deref_mut(&mut self) -> &mut Self::Target {
|
||||
&mut self.0
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
|
@ -2,7 +2,6 @@ use crate::error::*;
|
|||
use crate::state::*;
|
||||
use anchor_lang::prelude::*;
|
||||
use anchor_lang::solana_program::sysvar::instructions as tx_instructions;
|
||||
use spl_governance::addins::voter_weight::VoterWeightAccountType;
|
||||
use std::mem::size_of;
|
||||
|
||||
#[derive(Accounts)]
|
||||
|
@ -33,7 +32,7 @@ pub struct CreateVoter<'info> {
|
|||
payer = payer,
|
||||
space = size_of::<VoterWeightRecord>(),
|
||||
)]
|
||||
pub voter_weight_record: Account<'info, VoterWeightRecord>,
|
||||
pub voter_weight_record: Box<Account<'info, VoterWeightRecord>>,
|
||||
|
||||
#[account(mut)]
|
||||
pub payer: Signer<'info>,
|
||||
|
@ -79,7 +78,8 @@ pub fn create_voter(
|
|||
voter.registrar = ctx.accounts.registrar.key();
|
||||
|
||||
let voter_weight_record = &mut ctx.accounts.voter_weight_record;
|
||||
voter_weight_record.account_type = VoterWeightAccountType::VoterWeightRecord;
|
||||
voter_weight_record.account_discriminator =
|
||||
spl_governance_addin_api::voter_weight::VoterWeightRecord::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;
|
||||
|
|
|
@ -3,7 +3,6 @@ use crate::state::*;
|
|||
use anchor_lang::prelude::*;
|
||||
use anchor_spl::associated_token::AssociatedToken;
|
||||
use anchor_spl::token::{self, Mint, Token, TokenAccount};
|
||||
use spl_governance::addins::voter_weight::VoterWeightAccountType;
|
||||
use std::convert::TryFrom;
|
||||
use std::mem::size_of;
|
||||
|
||||
|
@ -139,7 +138,8 @@ 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_type = VoterWeightAccountType::VoterWeightRecord;
|
||||
voter_weight_record.account_discriminator =
|
||||
spl_governance_addin_api::voter_weight::VoterWeightRecord::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;
|
||||
|
|
|
@ -5,6 +5,7 @@ use state::*;
|
|||
|
||||
mod error;
|
||||
pub mod events;
|
||||
mod governance;
|
||||
mod instructions;
|
||||
pub mod state;
|
||||
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
use crate::error::*;
|
||||
use crate::vote_weight_record;
|
||||
use anchor_lang::prelude::*;
|
||||
use anchor_spl::vote_weight_record;
|
||||
use std::convert::TryFrom;
|
||||
|
||||
// Generate a VoteWeightRecord Anchor wrapper, owned by the current program.
|
||||
|
|
|
@ -54,7 +54,7 @@ impl Voter {
|
|||
&self,
|
||||
account_info: &AccountInfo,
|
||||
registrar: &Registrar,
|
||||
) -> Result<token_owner_record::TokenOwnerRecord> {
|
||||
) -> Result<token_owner_record::TokenOwnerRecordV2> {
|
||||
let record = token_owner_record::get_token_owner_record_data_for_realm_and_governing_mint(
|
||||
®istrar.governance_program_id,
|
||||
account_info,
|
||||
|
|
Binary file not shown.
|
@ -80,6 +80,7 @@ impl GovernanceCookie {
|
|||
&payer.pubkey(),
|
||||
None,
|
||||
Some(*voter_weight_addin),
|
||||
None,
|
||||
name.to_string(),
|
||||
0,
|
||||
spl_governance::state::enums::MintMaxVoteWeightSource::SupplyFraction(10000000000),
|
||||
|
@ -148,7 +149,7 @@ impl GovernanceRealmCookie {
|
|||
payer: &Keypair,
|
||||
vwr_instruction: Instruction,
|
||||
) -> AccountGovernanceCookie {
|
||||
let account_governance = spl_governance::state::governance::get_account_governance_address(
|
||||
let account_governance = spl_governance::state::governance::get_governance_address(
|
||||
&self.governance.program_id,
|
||||
&self.realm,
|
||||
&governed_account,
|
||||
|
@ -156,10 +157,10 @@ impl GovernanceRealmCookie {
|
|||
|
||||
let instructions = vec![
|
||||
vwr_instruction,
|
||||
spl_governance::instruction::create_account_governance(
|
||||
spl_governance::instruction::create_governance(
|
||||
&self.governance.program_id,
|
||||
&self.realm,
|
||||
&governed_account,
|
||||
Some(&governed_account),
|
||||
&voter.token_owner_record,
|
||||
&payer.pubkey(),
|
||||
&authority.pubkey(),
|
||||
|
@ -167,12 +168,12 @@ impl GovernanceRealmCookie {
|
|||
spl_governance::state::governance::GovernanceConfig {
|
||||
vote_threshold_percentage:
|
||||
spl_governance::state::enums::VoteThresholdPercentage::YesVote(50),
|
||||
min_community_tokens_to_create_proposal: 1000,
|
||||
min_instruction_hold_up_time: 0,
|
||||
min_community_weight_to_create_proposal: 1000,
|
||||
min_transaction_hold_up_time: 0,
|
||||
max_voting_time: 10,
|
||||
vote_weight_source: spl_governance::state::enums::VoteWeightSource::Deposit,
|
||||
vote_tipping: spl_governance::state::enums::VoteTipping::Disabled,
|
||||
proposal_cool_off_time: 0,
|
||||
min_council_tokens_to_create_proposal: 1,
|
||||
min_council_weight_to_create_proposal: 1,
|
||||
},
|
||||
),
|
||||
];
|
||||
|
@ -222,12 +223,12 @@ impl GovernanceRealmCookie {
|
|||
spl_governance::state::governance::GovernanceConfig {
|
||||
vote_threshold_percentage:
|
||||
spl_governance::state::enums::VoteThresholdPercentage::YesVote(50),
|
||||
min_community_tokens_to_create_proposal: 1000,
|
||||
min_instruction_hold_up_time: 0,
|
||||
min_community_weight_to_create_proposal: 1000,
|
||||
min_transaction_hold_up_time: 0,
|
||||
max_voting_time: 10,
|
||||
vote_weight_source: spl_governance::state::enums::VoteWeightSource::Deposit,
|
||||
vote_tipping: spl_governance::state::enums::VoteTipping::Disabled,
|
||||
proposal_cool_off_time: 0,
|
||||
min_council_tokens_to_create_proposal: 1,
|
||||
min_council_weight_to_create_proposal: 1,
|
||||
},
|
||||
true,
|
||||
),
|
||||
|
@ -293,8 +294,11 @@ impl GovernanceRealmCookie {
|
|||
),
|
||||
spl_governance::instruction::sign_off_proposal(
|
||||
&self.governance.program_id,
|
||||
&self.realm,
|
||||
&governance,
|
||||
&proposal,
|
||||
&authority.pubkey(),
|
||||
None,
|
||||
),
|
||||
];
|
||||
|
||||
|
@ -335,6 +339,7 @@ impl GovernanceRealmCookie {
|
|||
&self.community_token_mint.pubkey.unwrap(),
|
||||
&payer.pubkey(),
|
||||
Some(voter.voter_weight_record),
|
||||
None,
|
||||
vote_record::Vote::Approve(vec![vote_record::VoteChoice {
|
||||
rank: 0,
|
||||
weight_percentage: 100,
|
||||
|
|
|
@ -57,7 +57,10 @@ impl Log for LoggerWrapper {
|
|||
}
|
||||
|
||||
fn log(&self, record: &log::Record) {
|
||||
if record.target() == "solana_runtime::message_processor" {
|
||||
if record
|
||||
.target()
|
||||
.starts_with("solana_runtime::message_processor")
|
||||
{
|
||||
let msg = record.args().to_string();
|
||||
if let Some(data) = msg.strip_prefix("Program log: ") {
|
||||
self.program_log.write().unwrap().push(data.into());
|
||||
|
|
|
@ -59,7 +59,7 @@ impl SolanaCookie {
|
|||
self.context
|
||||
.borrow_mut()
|
||||
.banks_client
|
||||
.get_clock()
|
||||
.get_sysvar::<solana_program::clock::Clock>()
|
||||
.await
|
||||
.unwrap()
|
||||
}
|
||||
|
|
|
@ -1,7 +1,6 @@
|
|||
use anchor_spl::token::TokenAccount;
|
||||
use solana_program_test::*;
|
||||
use solana_sdk::{signature::Keypair, signer::Signer, transport::TransportError};
|
||||
use std::borrow::BorrowMut;
|
||||
|
||||
use program_test::*;
|
||||
use voter_stake_registry::state::Voter;
|
||||
|
|
Loading…
Reference in New Issue