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

Token-Voter Plugin PR #98

Merged
merged 4 commits into from
Aug 31, 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
1 change: 1 addition & 0 deletions Anchor.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ gateway = "GgathUhdrCWRHowoRKACjgWhYHfxCEdBi5ViqYN6HVxk"
quadratic = "quadCSapU8nTdLg73KHDnmdxKnJQsh7GUbu5tZfnRRr"
solana-gateway = "gatem74V238djXdzWnJf94Wo1DcnuGkfijbf3AuBhfs"
token-haver = "7gobfUihgoxA14RUnVaseoah89ggCgYAzgz1JoaPAXam"
token_voter = "3JhBg9bSPcfWGFa3t8LH7ooVtrjm45yCkHpxYXMXstUM"

[registry]
url = "https://anchor.projectserum.com"
Expand Down
8 changes: 4 additions & 4 deletions Cargo.lock

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

44 changes: 44 additions & 0 deletions programs/token-voter/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
[package]
name = "gpl-token-voter"
version = "0.0.1"
description = "SPL Governance plugin implementing token based governance power"
license = "Apache-2.0"
edition = "2018"

[lib]
crate-type = ["cdylib", "lib"]
name = "gpl_token_voter"

[features]
no-entrypoint = []
no-idl = []
no-log-ix-name = []
cpi = ["no-entrypoint"]
default = []
idl-build = ["anchor-lang/idl-build", "anchor-spl/idl-build"]

[dependencies]
anchor-lang = { version = "0.30.1", features = ["init-if-needed"] }
anchor-spl = "0.30.1"
arrayref = "0.3.7"
solana-program = "1.18.18"
spl-governance = { version = "4.0.0", features = ["no-entrypoint"] }
spl-tlv-account-resolution = { version = "0.6.3" }
spl-transfer-hook-interface = { version = "0.6.3" }
spl-governance-tools = "0.1.4"
spl-token = { version = "4.0.0", features = [ "no-entrypoint" ] }
spl-token-2022 = { version = "3.0.4", features = [ "no-entrypoint" ] }
ahash = "=0.8.7"
static_assertions = "1.1"
spl-governance-addin-api = "0.1.4"


[dev-dependencies]
borsh = "0.10.3"
spl-associated-token-account = { version = "^3.0.2", features = ["no-entrypoint"] }
spl-transfer-hook-example = { version = "0.6.0", features = ["no-entrypoint"] }
solana-sdk = "1.18.18"
solana-program-test = "1.18.18"
log = "0.4.14"
env_logger = "0.9.0"
spl-token-client = "0.10.0"
2 changes: 2 additions & 0 deletions programs/token-voter/Xargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
[target.bpfel-unknown-unknown.dependencies.std]
features = []
102 changes: 102 additions & 0 deletions programs/token-voter/src/error.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
use anchor_lang::prelude::*;

#[error_code]
pub enum TokenVoterError {
#[msg("Invalid Realm Authority")]
InvalidRealmAuthority,

#[msg("Invalid Realm for Registrar")]
InvalidRealmForRegistrar,

#[msg("Invalid MaxVoterWeightRecord Realm")]
InvalidMaxVoterWeightRecordRealm,

#[msg("Invalid MaxVoterWeightRecord Mint")]
InvalidMaxVoterWeightRecordMint,

#[msg("Invalid VoterWeightRecord Realm")]
InvalidVoterWeightRecordRealm,

#[msg("Invalid VoterWeightRecord Mint")]
InvalidVoterWeightRecordMint,

#[msg("Invalid TokenOwner for VoterWeightRecord")]
InvalidTokenOwnerForVoterWeightRecord,

#[msg("Mathematical Overflow")]
Overflow,

/// Invalid Token account owner
#[msg("Invalid Token account owner")]
SplTokenAccountWithInvalidOwner,

/// Invalid Mint account owner
#[msg("Invalid Mint account owner")]
SplTokenMintWithInvalidOwner,

/// Token Account doesn't exist
#[msg("Token Account doesn't exist")]
SplTokenAccountDoesNotExist,

/// Token account data is invalid
#[msg("Token account data is invalid")]
SplTokenInvalidTokenAccountData,

/// Token mint account data is invalid
#[msg("Token mint account data is invalid")]
SplTokenInvalidMintAccountData,

/// Token Mint is not initialized
#[msg("Token Mint account is not initialized")]
SplTokenMintNotInitialized,

/// Token Mint account doesn't exist
#[msg("Token Mint account doesn't exist")]
SplTokenMintDoesNotExist,

/// Account data is empty or invalid
#[msg("Account Data is empty or invalid")]
InvalidAccountData,

/// Math Overflow in VoterWeight
#[msg("Math Overflow in VoterWeight")]
VoterWeightOverflow,

#[msg("Mint Not Found in Mint Configs")]
MintNotFound,

#[msg("Governing TokenOwner must match")]
GoverningTokenOwnerMustMatch,

#[msg("Invalid Token Owner Records")]
InvalidTokenOwnerRecord,

#[msg("Index is out of Deposit Entry bounds")]
OutOfBoundsDepositEntryIndex,

#[msg("No Cpi Allowed")]
ForbiddenCpi,

#[msg("Voting Tokens are not withdrawn")]
VotingTokenNonZero,

#[msg("Vault Tokens are not withdrawn")]
VaultTokenNonZero,

#[msg("Invalid Voter Token Authority")]
InvalidAuthority,

/// Token Amount Overflow
#[msg("Math Overflow in Token Amount")]
TokenAmountOverflow,

/// Withdrawal in the same slot.
#[msg("Cannot Withdraw in the same slot")]
CannotWithdraw,

#[msg("Resizing Max Mints cannot be smaller than Configure Mint Configs")]
InvalidResizeMaxMints,

#[msg("Mint Index mismatch!")]
MintIndexMismatch,
}
Loading
Loading