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

Commit 3b811a1

Browse files
authored
Use native Anchor accounts for governance addin api (#39)
* chore: use native Anchor accounts for governance addin api * chore: update and publish npm
1 parent a9db5b5 commit 3b811a1

21 files changed

+244
-391
lines changed

.vscode/settings.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
{
22
"cSpell.words": [
33
"addin",
4+
"arrayref",
45
"itertools",
56
"Keypair",
67
"Metaplex",

Cargo.lock

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

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@solana/governance-program-library",
3-
"version": "0.13.0",
3+
"version": "0.14.0",
44
"description": "Client for Governance Program Library which is a set of extensions for Solana's spl-governance program.",
55
"author": "Solana Maintainers <[email protected]>",
66
"license": "MIT",

programs/nft-voter/Cargo.toml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@ itertools = "0.10.2"
2323
mpl-token-metadata = { version = "1.1.0", features = ["no-entrypoint"] }
2424
solana-program = "1.9.5"
2525
spl-governance = { version = "2.2.2", features = ["no-entrypoint"] }
26-
spl-governance-addin-api = "0.1.1"
2726
spl-governance-tools= "0.1.2"
2827
spl-token = { version = "3.3", features = [ "no-entrypoint" ] }
2928

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

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
use anchor_lang::prelude::*;
22
use anchor_lang::{Accounts};
33
use itertools::Itertools;
4-
use spl_governance_addin_api::voter_weight::VoterWeightAction;
54
use spl_governance_tools::account::create_and_serialize_account_signed;
65
use crate::{state::*, id};
76
use crate::error::NftVoterError;

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@ use anchor_lang::prelude::*;
88
use anchor_spl::token::Mint;
99
use spl_governance::state::realm;
1010

11-
use crate::state::{CollectionConfig, Registrar};
12-
use crate::{error::NftVoterError, state::MaxVoterWeightRecord};
11+
use crate::state::{CollectionConfig, Registrar, max_voter_weight_record::MaxVoterWeightRecord};
12+
use crate::{error::NftVoterError};
1313

1414
/// Configures NFT voting collection which defines what NFTs can be used for governances
1515
/// and what weight they have

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

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ use anchor_lang::prelude::*;
22
use anchor_spl::token::Mint;
33
use spl_governance::state::realm;
44

5-
use crate::state::MaxVoterWeightRecord;
5+
use crate::state::max_voter_weight_record::MaxVoterWeightRecord;
66

77
/// Creates MaxVoterWeightRecord used by spl-gov
88
/// This instruction should only be executed once per realm/governing_token_mint to create the account
@@ -44,9 +44,6 @@ pub fn create_max_voter_weight_record(ctx: Context<CreateMaxVoterWeightRecord>)
4444

4545
let max_voter_weight_record = &mut ctx.accounts.max_voter_weight_record;
4646

47-
max_voter_weight_record.account_discriminator =
48-
spl_governance_addin_api::max_voter_weight::MaxVoterWeightRecord::ACCOUNT_DISCRIMINATOR;
49-
5047
max_voter_weight_record.realm = ctx.accounts.realm.key();
5148
max_voter_weight_record.governing_token_mint = ctx.accounts.realm_governing_token_mint.key();
5249

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

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
1+
use crate::state::*;
12
use anchor_lang::prelude::*;
23
use anchor_spl::token::Mint;
34
use spl_governance::state::realm;
45

5-
use crate::state::VoterWeightRecord;
6-
76
/// Creates VoterWeightRecord used by spl-gov
87
/// This instruction should only be executed once per realm/governing_token_mint/governing_token_owner
98
/// to create the account
@@ -50,9 +49,6 @@ pub fn create_voter_weight_record(
5049

5150
let voter_weight_record = &mut ctx.accounts.voter_weight_record;
5251

53-
voter_weight_record.account_discriminator =
54-
spl_governance_addin_api::voter_weight::VoterWeightRecord::ACCOUNT_DISCRIMINATOR;
55-
5652
voter_weight_record.realm = ctx.accounts.realm.key();
5753
voter_weight_record.governing_token_mint = ctx.accounts.realm_governing_token_mint.key();
5854
voter_weight_record.governing_token_owner = governing_token_owner;

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

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,8 @@ use anchor_lang::prelude::*;
22
use spl_governance::state::{enums::ProposalState, governance, proposal};
33
use spl_governance_tools::account::dispose_account;
44
use crate::error::NftVoterError;
5+
use crate::state::*;
56
use crate::tools::governance::get_vote_record_address;
6-
use crate::{state::*};
7-
87
use crate::state::{get_nft_vote_record_data_for_proposal_and_token_owner, Registrar};
98

109
/// Disposes NftVoteRecord and recovers the rent from the accounts

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

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,9 @@
11
use crate::{
2-
error::NftVoterError,
3-
state::{Registrar, VoterWeightRecord, resolve_nft_vote_weight_and_mint},
2+
error::NftVoterError
43
};
4+
use crate::state::*;
55
use anchor_lang::prelude::*;
66
use itertools::Itertools;
7-
use spl_governance_addin_api::voter_weight::VoterWeightAction;
8-
97

108

119
/// Updates VoterWeightRecord to evaluate governance power for non voting use cases: CreateProposal, CreateGovernance etc...

0 commit comments

Comments
 (0)