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

Commit

Permalink
token-haver: Enforce uniqueness of token account mints (#96)
Browse files Browse the repository at this point in the history
* init

* .

* start tests

* more test updates

* check locked

* typo

* typo

* pubkey

* rn

* answer comments

* shift by 9 decimals

* use 7gobfUihgoxA14RUnVaseoah89ggCgYAzgz1JoaPAXam

* use 6 decimals to match realms default

* Enforce unique mints

* bump ver
  • Loading branch information
asktree authored Jul 15, 2024
1 parent b117178 commit 994d598
Show file tree
Hide file tree
Showing 6 changed files with 20 additions and 6 deletions.
2 changes: 1 addition & 1 deletion Anchor.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ seeds = false
nft_voter = "GnftV5kLjd67tvHpNGyodwWveEKivz3ZWvvE3Z4xi2iw"
gateway = "GgathUhdrCWRHowoRKACjgWhYHfxCEdBi5ViqYN6HVxk"
solana-gateway-program = "gatem74V238djXdzWnJf94Wo1DcnuGkfijbf3AuBhfs"
token-haver = "vo65JQC6U8HCDPfoJxRrr17n7RZ5fKdfyjHm3erHJ2V"
token-haver = "7gobfUihgoxA14RUnVaseoah89ggCgYAzgz1JoaPAXam"

[registry]
url = "https://anchor.projectserum.com"
Expand Down
2 changes: 1 addition & 1 deletion Cargo.lock

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

2 changes: 1 addition & 1 deletion programs/token-haver/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "gpl-token-haver"
version = "0.0.1"
version = "0.0.2"
description = "SPL Governance plugin granting governance power based on the nonzero presence of locked tokens"
license = "Apache-2.0"
edition = "2018"
Expand Down
5 changes: 4 additions & 1 deletion programs/token-haver/src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,9 @@ pub enum TokenHaverError {
#[msg("All token accounts' mints must be included in the registrar")]
TokenAccountWrongMint,

#[msg("All token accounts' mints must be included in the registrar")]
#[msg("All token accounts must be locked")]
TokenAccountNotLocked,

#[msg("All token accounts' mints must be unique")]
TokenAccountDuplicateMint,
}
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,17 @@ pub fn update_voter_weight_record(ctx: Context<UpdateVoterWeightRecord>) -> Resu
voter_weight_record.governing_token_owner,
TokenHaverError::TokenAccountWrongOwner
);

// Throw an error if a token account's mint is not unique amount the accounts
require!(
nonzero_token_accounts
.iter()
.filter(|a| a.mint == account.mint)
.count()
== 1,
TokenHaverError::TokenAccountDuplicateMint
);

// Throw an error if a token account's mint isn't in registrar.mints
require!(
registrar.mints.contains(&account.mint),
Expand All @@ -52,7 +63,7 @@ pub fn update_voter_weight_record(ctx: Context<UpdateVoterWeightRecord>) -> Resu
}

// Setup voter_weight
voter_weight_record.voter_weight = nonzero_token_accounts.len() as u64;
voter_weight_record.voter_weight = (nonzero_token_accounts.len() as u64) * 1_000_000;

// Record is only valid as of the current slot
voter_weight_record.voter_weight_expiry = Some(Clock::get()?.slot);
Expand Down
2 changes: 1 addition & 1 deletion programs/token-haver/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ pub mod state;

pub mod tools;

declare_id!("vo65JQC6U8HCDPfoJxRrr17n7RZ5fKdfyjHm3erHJ2V");
declare_id!("7gobfUihgoxA14RUnVaseoah89ggCgYAzgz1JoaPAXam");

#[program]
pub mod token_haver {
Expand Down

0 comments on commit 994d598

Please sign in to comment.