diff --git a/README.md b/README.md index ae74167..8490c24 100644 --- a/README.md +++ b/README.md @@ -39,7 +39,7 @@ To start using the addin, make a governance proposal with the spl-governance realm authority to: 1. Deploy an instance of the voter-stake-registry. 2. Create a registrar for the realm with the `CreateRegistrar` instruction. -3. Add voting token mints to the registrar by calling the `CreateExchangeRate` +3. Add voting token mints to the registrar by calling the `ConfigureVotingMint` instruction as often as desired. 4. Call the `SetRealmConfig` instruction on spl-governance to set the voter-weight-addin program id and thereby enable the addin. diff --git a/programs/voter-stake-registry/src/error.rs b/programs/voter-stake-registry/src/error.rs index b2d1ae0..340172b 100644 --- a/programs/voter-stake-registry/src/error.rs +++ b/programs/voter-stake-registry/src/error.rs @@ -7,7 +7,7 @@ pub enum ErrorCode { #[msg("")] RatesFull, #[msg("")] - ExchangeRateEntryNotFound, // 302 + VotingMintNotFound, // 302 #[msg("")] DepositEntryNotFound, #[msg("")] @@ -29,9 +29,9 @@ pub enum ErrorCode { #[msg("")] InvalidDays, #[msg("")] - RatesIndexAlreadyInUse, + VotingMintConfigIndexAlreadyInUse, #[msg("")] - OutOfBoundsRatesIndex, + OutOfBoundsVotingMintConfigIndex, #[msg("Exchange rate decimals cannot be larger than registrar decimals")] InvalidDecimals, #[msg("")] diff --git a/programs/voter-stake-registry/src/instructions/create_exchange_rate.rs b/programs/voter-stake-registry/src/instructions/configure_voting_mint.rs similarity index 78% rename from programs/voter-stake-registry/src/instructions/create_exchange_rate.rs rename to programs/voter-stake-registry/src/instructions/configure_voting_mint.rs index f18392e..44a2e8e 100644 --- a/programs/voter-stake-registry/src/instructions/create_exchange_rate.rs +++ b/programs/voter-stake-registry/src/instructions/configure_voting_mint.rs @@ -6,7 +6,7 @@ use anchor_spl::token::{Mint, Token, TokenAccount}; #[derive(Accounts)] #[instruction(idx: u16, rate: u64, decimals: u8)] -pub struct CreateExchangeRate<'info> { +pub struct ConfigureVotingMint<'info> { #[account(mut, has_one = realm_authority)] pub registrar: Box>, pub realm_authority: Signer<'info>, @@ -43,23 +43,24 @@ pub struct CreateExchangeRate<'info> { /// ``` /// rate * 10^vote_weight_decimals / 10^decimals /// ``` -pub fn create_exchange_rate( - ctx: Context, +pub fn configure_voting_mint( + ctx: Context, idx: u16, rate: u64, decimals: u8, ) -> Result<()> { - msg!("--------create_exchange_rate--------"); + msg!("--------configure_voting_mint--------"); require!(rate > 0, InvalidRate); let registrar = &mut ctx.accounts.registrar; require!( - (idx as usize) < registrar.rates.len(), - OutOfBoundsRatesIndex + (idx as usize) < registrar.voting_mints.len(), + OutOfBoundsVotingMintConfigIndex ); require!( - registrar.rates[idx as usize].rate == 0, - RatesIndexAlreadyInUse + registrar.voting_mints[idx as usize].rate == 0, + VotingMintConfigIndexAlreadyInUse ); - registrar.rates[idx as usize] = registrar.new_rate(ctx.accounts.mint.key(), decimals, rate)?; + registrar.voting_mints[idx as usize] = + registrar.new_rate(ctx.accounts.mint.key(), decimals, rate)?; Ok(()) } diff --git a/programs/voter-stake-registry/src/instructions/create_deposit_entry.rs b/programs/voter-stake-registry/src/instructions/create_deposit_entry.rs index be7d182..64d4c4b 100644 --- a/programs/voter-stake-registry/src/instructions/create_deposit_entry.rs +++ b/programs/voter-stake-registry/src/instructions/create_deposit_entry.rs @@ -37,7 +37,7 @@ pub fn create_deposit_entry( let voter = &mut ctx.accounts.voter.load_mut()?; // Get the exchange rate entry associated with this deposit. - let er_idx = registrar.exchange_rate_index_for_mint(ctx.accounts.deposit_mint.key())?; + let mint_idx = registrar.voting_mint_config_index(ctx.accounts.deposit_mint.key())?; // Get and set up the deposit entry. require!( @@ -49,7 +49,7 @@ pub fn create_deposit_entry( *d_entry = DepositEntry::default(); d_entry.is_used = true; - d_entry.rate_idx = er_idx as u8; + d_entry.voting_mint_config_idx = mint_idx as u8; d_entry.amount_deposited_native = 0; d_entry.amount_initially_locked_native = 0; d_entry.allow_clawback = allow_clawback; diff --git a/programs/voter-stake-registry/src/instructions/create_registrar.rs b/programs/voter-stake-registry/src/instructions/create_registrar.rs index f90448a..4f0884b 100644 --- a/programs/voter-stake-registry/src/instructions/create_registrar.rs +++ b/programs/voter-stake-registry/src/instructions/create_registrar.rs @@ -49,7 +49,7 @@ pub struct CreateRegistrar<'info> { /// `vote_weight_decimals` is the number of decimals used on the vote weight. It must be /// larger or equal to all token mints used for voting. /// -/// To use the registrar, call CreateExchangeRate to register token mints that may be +/// To use the registrar, call ConfigVotingMint to register token mints that may be /// used for voting. pub fn create_registrar( ctx: Context, diff --git a/programs/voter-stake-registry/src/instructions/deposit.rs b/programs/voter-stake-registry/src/instructions/deposit.rs index ac5cae9..3682bb6 100644 --- a/programs/voter-stake-registry/src/instructions/deposit.rs +++ b/programs/voter-stake-registry/src/instructions/deposit.rs @@ -57,8 +57,11 @@ pub fn deposit(ctx: Context, deposit_entry_index: u8, amount: u64) -> R let d_entry = voter.active_deposit_mut(deposit_entry_index)?; // Get the exchange rate entry associated with this deposit. - let er_idx = registrar.exchange_rate_index_for_mint(ctx.accounts.deposit_token.mint)?; - require!(er_idx == d_entry.rate_idx as usize, InvalidMint); + let mint_idx = registrar.voting_mint_config_index(ctx.accounts.deposit_token.mint)?; + require!( + mint_idx == d_entry.voting_mint_config_idx as usize, + InvalidMint + ); // Deposit tokens into the registrar. token::transfer(ctx.accounts.transfer_ctx(), amount)?; diff --git a/programs/voter-stake-registry/src/instructions/mod.rs b/programs/voter-stake-registry/src/instructions/mod.rs index 7ca145b..30b5d93 100644 --- a/programs/voter-stake-registry/src/instructions/mod.rs +++ b/programs/voter-stake-registry/src/instructions/mod.rs @@ -1,8 +1,8 @@ pub use clawback::*; pub use close_deposit_entry::*; pub use close_voter::*; +pub use configure_voting_mint::*; pub use create_deposit_entry::*; -pub use create_exchange_rate::*; pub use create_registrar::*; pub use create_voter::*; pub use deposit::*; @@ -15,8 +15,8 @@ pub use withdraw::*; mod clawback; mod close_deposit_entry; mod close_voter; +mod configure_voting_mint; mod create_deposit_entry; -mod create_exchange_rate; mod create_registrar; mod create_voter; mod deposit; diff --git a/programs/voter-stake-registry/src/instructions/update_max_vote_weight.rs b/programs/voter-stake-registry/src/instructions/update_max_vote_weight.rs index f32628c..ed382ad 100644 --- a/programs/voter-stake-registry/src/instructions/update_max_vote_weight.rs +++ b/programs/voter-stake-registry/src/instructions/update_max_vote_weight.rs @@ -30,9 +30,9 @@ pub fn update_max_vote_weight<'info>(ctx: Context) -> Resul .collect::>, ProgramError>>()? .iter() .try_fold(0u64, |sum, m| { - let er_idx = registrar.exchange_rate_index_for_mint(m.key())?; - let er_entry = registrar.rates[er_idx]; - let amount = er_entry.convert(m.supply); + let mint_idx = registrar.voting_mint_config_index(m.key())?; + let mint_config = registrar.voting_mints[mint_idx]; + let amount = mint_config.convert(m.supply); let total = sum.checked_add(amount).unwrap(); Ok(total) }); diff --git a/programs/voter-stake-registry/src/instructions/withdraw.rs b/programs/voter-stake-registry/src/instructions/withdraw.rs index 3df034b..0dacf09 100644 --- a/programs/voter-stake-registry/src/instructions/withdraw.rs +++ b/programs/voter-stake-registry/src/instructions/withdraw.rs @@ -102,9 +102,9 @@ pub fn withdraw( ); // Get the exchange rate for the token being withdrawn. - let er_idx = registrar.exchange_rate_index_for_mint(ctx.accounts.destination.mint)?; + let mint_idx = registrar.voting_mint_config_index(ctx.accounts.destination.mint)?; require!( - er_idx == deposit_entry.rate_idx as usize, + mint_idx == deposit_entry.voting_mint_config_idx as usize, ErrorCode::InvalidMint ); diff --git a/programs/voter-stake-registry/src/lib.rs b/programs/voter-stake-registry/src/lib.rs index 13f9ea7..56f7c29 100644 --- a/programs/voter-stake-registry/src/lib.rs +++ b/programs/voter-stake-registry/src/lib.rs @@ -66,13 +66,13 @@ pub mod voter_stake_registry { instructions::create_registrar(ctx, vote_weight_decimals, registrar_bump) } - pub fn create_exchange_rate( - ctx: Context, + pub fn configure_voting_mint( + ctx: Context, idx: u16, rate: u64, decimals: u8, ) -> Result<()> { - instructions::create_exchange_rate(ctx, idx, rate, decimals) + instructions::configure_voting_mint(ctx, idx, rate, decimals) } pub fn create_voter( diff --git a/programs/voter-stake-registry/src/state/deposit_entry.rs b/programs/voter-stake-registry/src/state/deposit_entry.rs index 9ce795b..af564d5 100644 --- a/programs/voter-stake-registry/src/state/deposit_entry.rs +++ b/programs/voter-stake-registry/src/state/deposit_entry.rs @@ -1,6 +1,6 @@ use crate::error::*; -use crate::state::exchange_entry::ExchangeRateEntry; use crate::state::lockup::{Lockup, LockupKind}; +use crate::state::voting_mint_config::VotingMintConfig; use anchor_lang::prelude::*; /// Vote weight is amount * FIXED_VOTE_WEIGHT_FACTOR + @@ -15,8 +15,8 @@ pub struct DepositEntry { // True if the deposit entry is being used. pub is_used: bool, - // Points to the ExchangeRate this deposit uses. - pub rate_idx: u8, + // Points to the VotingMintConfig this deposit uses. + pub voting_mint_config_idx: u8, /// Amount in deposited, in native currency. Withdraws of vested tokens /// directly reduce this amount. @@ -137,8 +137,8 @@ impl DepositEntry { /// a time factor of 1/2555. /// /// The computation below uses 1 + 2 + ... + n = n * (n + 1) / 2. - pub fn voting_power(&self, rate: &ExchangeRateEntry, curr_ts: i64) -> Result { - let fixed_contribution = rate + pub fn voting_power(&self, voting_mint_config: &VotingMintConfig, curr_ts: i64) -> Result { + let fixed_contribution = voting_mint_config .convert(self.amount_deposited_native) .checked_mul(FIXED_VOTE_WEIGHT_FACTOR) .unwrap(); @@ -146,7 +146,8 @@ impl DepositEntry { return Ok(fixed_contribution); } - let max_locked_contribution = rate.convert(self.amount_initially_locked_native); + let max_locked_contribution = + voting_mint_config.convert(self.amount_initially_locked_native); Ok(fixed_contribution + self .voting_power_locked(curr_ts, max_locked_contribution)? diff --git a/programs/voter-stake-registry/src/state/lockup.rs b/programs/voter-stake-registry/src/state/lockup.rs index 4cdf400..69a9ceb 100644 --- a/programs/voter-stake-registry/src/state/lockup.rs +++ b/programs/voter-stake-registry/src/state/lockup.rs @@ -626,7 +626,7 @@ mod tests { let end_ts = start_ts + days_to_secs(t.days_total); let d = DepositEntry { is_used: true, - rate_idx: 0, + voting_mint_config_idx: 0, amount_deposited_native: t.amount_deposited, amount_initially_locked_native: t.amount_deposited, allow_clawback: false, diff --git a/programs/voter-stake-registry/src/state/mod.rs b/programs/voter-stake-registry/src/state/mod.rs index 293db08..995cc9b 100644 --- a/programs/voter-stake-registry/src/state/mod.rs +++ b/programs/voter-stake-registry/src/state/mod.rs @@ -1,11 +1,11 @@ pub use deposit_entry::*; -pub use exchange_entry::*; pub use lockup::*; pub use registrar::*; pub use voter::*; +pub use voting_mint_config::*; mod deposit_entry; -mod exchange_entry; mod lockup; mod registrar; mod voter; +mod voting_mint_config; diff --git a/programs/voter-stake-registry/src/state/registrar.rs b/programs/voter-stake-registry/src/state/registrar.rs index 345cf07..9dc01ad 100644 --- a/programs/voter-stake-registry/src/state/registrar.rs +++ b/programs/voter-stake-registry/src/state/registrar.rs @@ -1,5 +1,5 @@ use crate::error::*; -use crate::state::exchange_entry::ExchangeRateEntry; +use crate::state::voting_mint_config::VotingMintConfig; use anchor_lang::prelude::*; /// Instance of a voting rights distributor. @@ -13,7 +13,7 @@ pub struct Registrar { pub clawback_authority: Pubkey, pub bump: u8, // The length should be adjusted for one's use case. - pub rates: [ExchangeRateEntry; 2], + pub voting_mints: [VotingMintConfig; 2], /// The decimals to use when converting deposits into a common currency. /// @@ -26,18 +26,13 @@ pub struct Registrar { } impl Registrar { - pub fn new_rate( - &self, - mint: Pubkey, - mint_decimals: u8, - rate: u64, - ) -> Result { + pub fn new_rate(&self, mint: Pubkey, mint_decimals: u8, rate: u64) -> Result { require!(self.vote_weight_decimals >= mint_decimals, InvalidDecimals); let decimal_diff = self .vote_weight_decimals .checked_sub(mint_decimals) .unwrap(); - Ok(ExchangeRateEntry { + Ok(VotingMintConfig { mint, rate, mint_decimals, @@ -49,11 +44,11 @@ impl Registrar { Clock::get().unwrap().unix_timestamp + self.time_offset } - pub fn exchange_rate_index_for_mint(&self, mint: Pubkey) -> Result { - self.rates + pub fn voting_mint_config_index(&self, mint: Pubkey) -> Result { + self.voting_mints .iter() .position(|r| r.mint == mint) - .ok_or(Error::ErrorCode(ErrorCode::ExchangeRateEntryNotFound)) + .ok_or(Error::ErrorCode(ErrorCode::VotingMintNotFound)) } } diff --git a/programs/voter-stake-registry/src/state/voter.rs b/programs/voter-stake-registry/src/state/voter.rs index bc4f029..ae0f629 100644 --- a/programs/voter-stake-registry/src/state/voter.rs +++ b/programs/voter-stake-registry/src/state/voter.rs @@ -27,8 +27,11 @@ impl Voter { .iter() .filter(|d| d.is_used) .try_fold(0, |sum, d| { - d.voting_power(®istrar.rates[d.rate_idx as usize], curr_ts) - .map(|vp| sum + vp) + d.voting_power( + ®istrar.voting_mints[d.voting_mint_config_idx as usize], + curr_ts, + ) + .map(|vp| sum + vp) }) } diff --git a/programs/voter-stake-registry/src/state/exchange_entry.rs b/programs/voter-stake-registry/src/state/voting_mint_config.rs similarity index 86% rename from programs/voter-stake-registry/src/state/exchange_entry.rs rename to programs/voter-stake-registry/src/state/voting_mint_config.rs index 52619a8..a358dc9 100644 --- a/programs/voter-stake-registry/src/state/exchange_entry.rs +++ b/programs/voter-stake-registry/src/state/voting_mint_config.rs @@ -4,7 +4,7 @@ use anchor_lang::prelude::*; /// Exchange rate for an asset that can be used to mint voting rights. #[zero_copy] #[derive(AnchorSerialize, AnchorDeserialize, Default)] -pub struct ExchangeRateEntry { +pub struct VotingMintConfig { /// Mint for this entry. pub mint: Pubkey, @@ -28,12 +28,12 @@ pub struct ExchangeRateEntry { pub conversion_factor: u64, } -impl ExchangeRateEntry { - /// Converts an amount in this ExchangeRateEntry's mint's native currency +impl VotingMintConfig { + /// Converts an amount in this voting mints's native currency /// to the equivalent common registrar vote currency amount. pub fn convert(&self, amount_native: u64) -> u64 { amount_native.checked_mul(self.conversion_factor).unwrap() } } -unsafe impl Zeroable for ExchangeRateEntry {} +unsafe impl Zeroable for VotingMintConfig {} diff --git a/programs/voter-stake-registry/tests/program_test/addin.rs b/programs/voter-stake-registry/tests/program_test/addin.rs index 89d473d..b58819b 100644 --- a/programs/voter-stake-registry/tests/program_test/addin.rs +++ b/programs/voter-stake-registry/tests/program_test/addin.rs @@ -22,7 +22,7 @@ pub struct RegistrarCookie { } #[derive(Clone, Copy)] -pub struct ExchangeRateCookie { +pub struct VotingMintConfigCookie { pub mint: MintCookie, pub vault: Pubkey, } @@ -96,7 +96,7 @@ impl AddinCookie { } } - pub async fn create_exchange_rate( + pub async fn configure_voting_mint( &self, registrar: &RegistrarCookie, authority: &Keypair, @@ -104,7 +104,7 @@ impl AddinCookie { index: u16, mint: &MintCookie, rate: u64, - ) -> ExchangeRateCookie { + ) -> VotingMintConfigCookie { let deposit_mint = mint.pubkey.unwrap(); let vault = spl_associated_token_account::get_associated_token_address( ®istrar.address, @@ -112,7 +112,7 @@ impl AddinCookie { ); let data = anchor_lang::InstructionData::data( - &voter_stake_registry::instruction::CreateExchangeRate { + &voter_stake_registry::instruction::ConfigureVotingMint { idx: index, rate, decimals: mint.decimals, @@ -120,7 +120,7 @@ impl AddinCookie { ); let accounts = anchor_lang::ToAccountMetas::to_account_metas( - &voter_stake_registry::accounts::CreateExchangeRate { + &voter_stake_registry::accounts::ConfigureVotingMint { vault, mint: deposit_mint, registrar: registrar.address, @@ -149,7 +149,7 @@ impl AddinCookie { .await .unwrap(); - ExchangeRateCookie { + VotingMintConfigCookie { mint: mint.clone(), vault, } @@ -227,7 +227,7 @@ impl AddinCookie { registrar: &RegistrarCookie, voter: &VoterCookie, voter_authority: &Keypair, - exchange_rate: &ExchangeRateCookie, + voting_mint: &VotingMintConfigCookie, deposit_entry_index: u8, lockup_kind: voter_stake_registry::state::LockupKind, periods: u32, @@ -247,7 +247,7 @@ impl AddinCookie { registrar: registrar.address, voter: voter.address, voter_authority: voter_authority.pubkey(), - deposit_mint: exchange_rate.mint.pubkey.unwrap(), + deposit_mint: voting_mint.mint.pubkey.unwrap(), }, None, ); @@ -270,7 +270,7 @@ impl AddinCookie { &self, registrar: &RegistrarCookie, voter: &VoterCookie, - exchange_rate: &ExchangeRateCookie, + voting_mint: &VotingMintConfigCookie, authority: &Keypair, token_address: Pubkey, deposit_entry_index: u8, @@ -286,7 +286,7 @@ impl AddinCookie { &voter_stake_registry::accounts::Deposit { registrar: registrar.address, voter: voter.address, - vault: exchange_rate.vault, + vault: voting_mint.vault, deposit_token: token_address, deposit_authority: authority.pubkey(), token_program: spl_token::id(), @@ -314,7 +314,7 @@ impl AddinCookie { registrar: &RegistrarCookie, voter: &VoterCookie, token_owner_record: &TokenOwnerRecordCookie, - exchange_rate: &ExchangeRateCookie, + voting_mint: &VotingMintConfigCookie, clawback_authority: &Keypair, token_address: Pubkey, deposit_entry_index: u8, @@ -329,7 +329,7 @@ impl AddinCookie { registrar: registrar.address, voter: voter.address, token_owner_record: token_owner_record.address, - vault: exchange_rate.vault, + vault: voting_mint.vault, destination: token_address, authority: clawback_authority.pubkey(), token_program: spl_token::id(), @@ -356,7 +356,7 @@ impl AddinCookie { registrar: &RegistrarCookie, voter: &VoterCookie, token_owner_record: &TokenOwnerRecordCookie, - exchange_rate: &ExchangeRateCookie, + voting_mint: &VotingMintConfigCookie, authority: &Keypair, token_address: Pubkey, deposit_entry_index: u8, @@ -373,7 +373,7 @@ impl AddinCookie { registrar: registrar.address, voter: voter.address, token_owner_record: token_owner_record.address, - vault: exchange_rate.vault, + vault: voting_mint.vault, destination: token_address, authority: authority.pubkey(), token_program: spl_token::id(), @@ -540,7 +540,7 @@ impl AddinCookie { } } -impl ExchangeRateCookie { +impl VotingMintConfigCookie { pub async fn vault_balance(&self, solana: &SolanaCookie) -> u64 { solana.get_account::(self.vault).await.amount } diff --git a/programs/voter-stake-registry/tests/test_basic.rs b/programs/voter-stake-registry/tests/test_basic.rs index 160fa2c..d13982c 100644 --- a/programs/voter-stake-registry/tests/test_basic.rs +++ b/programs/voter-stake-registry/tests/test_basic.rs @@ -33,9 +33,9 @@ async fn test_basic() -> Result<(), TransportError> { .addin .create_registrar(&realm, &realm_authority, payer) .await; - let mngo_rate = context + let mngo_voting_mint = context .addin - .create_exchange_rate(®istrar, &realm_authority, payer, 0, &context.mints[0], 1) + .configure_voting_mint(®istrar, &realm_authority, payer, 0, &context.mints[0], 1) .await; let voter = context @@ -50,7 +50,7 @@ async fn test_basic() -> Result<(), TransportError> { .solana .token_account_balance(reference_account) .await; - let vault_initial = mngo_rate.vault_balance(&context.solana).await; + let vault_initial = mngo_voting_mint.vault_balance(&context.solana).await; assert_eq!(vault_initial, 0); let balance_initial = voter.deposit_amount(&context.solana, 0).await; assert_eq!(balance_initial, 0); @@ -61,7 +61,7 @@ async fn test_basic() -> Result<(), TransportError> { ®istrar, &voter, voter_authority, - &mngo_rate, + &mngo_voting_mint, 0, voter_stake_registry::state::LockupKind::Cliff, 0, @@ -73,7 +73,7 @@ async fn test_basic() -> Result<(), TransportError> { .deposit( ®istrar, &voter, - &mngo_rate, + &mngo_voting_mint, &voter_authority, reference_account, 0, @@ -86,7 +86,7 @@ async fn test_basic() -> Result<(), TransportError> { .token_account_balance(reference_account) .await; assert_eq!(reference_initial, reference_after_deposit + 10000); - let vault_after_deposit = mngo_rate.vault_balance(&context.solana).await; + let vault_after_deposit = mngo_voting_mint.vault_balance(&context.solana).await; assert_eq!(vault_after_deposit, 10000); let balance_after_deposit = voter.deposit_amount(&context.solana, 0).await; assert_eq!(balance_after_deposit, 10000); @@ -97,7 +97,7 @@ async fn test_basic() -> Result<(), TransportError> { ®istrar, &voter, &token_owner_record, - &mngo_rate, + &mngo_voting_mint, &voter_authority, reference_account, 0, @@ -115,7 +115,7 @@ async fn test_basic() -> Result<(), TransportError> { ®istrar, &voter, &token_owner_record, - &mngo_rate, + &mngo_voting_mint, &voter_authority, reference_account, 0, @@ -128,7 +128,7 @@ async fn test_basic() -> Result<(), TransportError> { .token_account_balance(reference_account) .await; assert_eq!(reference_initial, reference_after_withdraw); - let vault_after_withdraw = mngo_rate.vault_balance(&context.solana).await; + let vault_after_withdraw = mngo_voting_mint.vault_balance(&context.solana).await; assert_eq!(vault_after_withdraw, 0); let balance_after_withdraw = voter.deposit_amount(&context.solana, 0).await; assert_eq!(balance_after_withdraw, 0); diff --git a/programs/voter-stake-registry/tests/test_clawback.rs b/programs/voter-stake-registry/tests/test_clawback.rs index 46c85fb..4534237 100644 --- a/programs/voter-stake-registry/tests/test_clawback.rs +++ b/programs/voter-stake-registry/tests/test_clawback.rs @@ -40,10 +40,10 @@ async fn test_clawback() -> Result<(), TransportError> { .create_registrar(&realm, realm_authority, realm_authority) .await; - println!("create_exchange_rate"); - let mngo_rate = context + println!("configure_voting_mint"); + let mngo_voting_mint = context .addin - .create_exchange_rate( + .configure_voting_mint( ®istrar, &realm_authority, realm_authority, @@ -72,7 +72,7 @@ async fn test_clawback() -> Result<(), TransportError> { .solana .token_account_balance(voter_authority_ata) .await; - let vault_initial = mngo_rate.vault_balance(&context.solana).await; + let vault_initial = mngo_voting_mint.vault_balance(&context.solana).await; assert_eq!(vault_initial, 0); let voter_balance_initial = voter.deposit_amount(&context.solana, 0).await; assert_eq!(voter_balance_initial, 0); @@ -84,7 +84,7 @@ async fn test_clawback() -> Result<(), TransportError> { ®istrar, &voter, voter_authority, - &mngo_rate, + &mngo_voting_mint, 0, voter_stake_registry::state::LockupKind::Daily, 10, @@ -96,7 +96,7 @@ async fn test_clawback() -> Result<(), TransportError> { .deposit( ®istrar, &voter, - &mngo_rate, + &mngo_voting_mint, &realm_authority, realm_authority_ata, 0, @@ -109,7 +109,7 @@ async fn test_clawback() -> Result<(), TransportError> { .token_account_balance(realm_authority_ata) .await; assert_eq!(realm_ata_initial, realm_ata_after_deposit + 10000); - let vault_after_deposit = mngo_rate.vault_balance(&context.solana).await; + let vault_after_deposit = mngo_voting_mint.vault_balance(&context.solana).await; assert_eq!(vault_after_deposit, 10000); let voter_balance_after_deposit = voter.deposit_amount(&context.solana, 0).await; assert_eq!(voter_balance_after_deposit, 10000); @@ -121,7 +121,7 @@ async fn test_clawback() -> Result<(), TransportError> { ®istrar, &voter, &token_owner_record, - &mngo_rate, + &mngo_voting_mint, &voter_authority, voter_authority_ata, 0, @@ -145,7 +145,7 @@ async fn test_clawback() -> Result<(), TransportError> { ®istrar, &voter, &token_owner_record, - &mngo_rate, + &mngo_voting_mint, &voter_authority, voter_authority_ata, 0, @@ -160,7 +160,7 @@ async fn test_clawback() -> Result<(), TransportError> { ®istrar, &voter, &token_owner_record, - &mngo_rate, + &mngo_voting_mint, &realm_authority, realm_authority_ata, 0, @@ -174,7 +174,7 @@ async fn test_clawback() -> Result<(), TransportError> { ®istrar, &voter, &token_owner_record, - &mngo_rate, + &mngo_voting_mint, &voter_authority, voter_authority_ata, 0, @@ -192,7 +192,7 @@ async fn test_clawback() -> Result<(), TransportError> { .token_account_balance(voter_authority_ata) .await; assert_eq!(voter_after_withdraw, voter_ata_initial + 2000); - let vault_after_withdraw = mngo_rate.vault_balance(&context.solana).await; + let vault_after_withdraw = mngo_voting_mint.vault_balance(&context.solana).await; assert_eq!(vault_after_withdraw, 0); let voter_balance_after_withdraw = voter.deposit_amount(&context.solana, 0).await; assert_eq!(voter_balance_after_withdraw, 0); diff --git a/programs/voter-stake-registry/tests/test_deposit_cliff.rs b/programs/voter-stake-registry/tests/test_deposit_cliff.rs index 3f00d0f..0cec9c4 100644 --- a/programs/voter-stake-registry/tests/test_deposit_cliff.rs +++ b/programs/voter-stake-registry/tests/test_deposit_cliff.rs @@ -17,7 +17,7 @@ async fn balances( registrar: &RegistrarCookie, address: Pubkey, voter: &VoterCookie, - rate: &ExchangeRateCookie, + voting_mint: &VotingMintConfigCookie, deposit_id: u8, ) -> Balances { // Advance slots to avoid caching of the UpdateVoterWeightRecord call @@ -25,7 +25,7 @@ async fn balances( context.solana.advance_clock_by_slots(2).await; let token = context.solana.token_account_balance(address).await; - let vault = rate.vault_balance(&context.solana).await; + let vault = voting_mint.vault_balance(&context.solana).await; let deposit = voter.deposit_amount(&context.solana, deposit_id).await; let vwr = context .addin @@ -67,8 +67,8 @@ async fn test_deposit_cliff() -> Result<(), TransportError> { let registrar = addin .create_registrar(&realm, &realm_authority, payer) .await; - let mngo_rate = addin - .create_exchange_rate(®istrar, &realm_authority, payer, 0, &context.mints[0], 1) + let mngo_voting_mint = addin + .configure_voting_mint(®istrar, &realm_authority, payer, 0, &context.mints[0], 1) .await; let voter = addin @@ -82,7 +82,7 @@ async fn test_deposit_cliff() -> Result<(), TransportError> { ®istrar, reference_account, &voter, - &mngo_rate, + &mngo_voting_mint, depot_id, ) }; @@ -91,7 +91,7 @@ async fn test_deposit_cliff() -> Result<(), TransportError> { ®istrar, &voter, &token_owner_record, - &mngo_rate, + &mngo_voting_mint, &voter_authority, reference_account, 0, @@ -102,7 +102,7 @@ async fn test_deposit_cliff() -> Result<(), TransportError> { addin.deposit( ®istrar, &voter, - &mngo_rate, + &mngo_voting_mint, &voter_authority, reference_account, 0, @@ -121,7 +121,7 @@ async fn test_deposit_cliff() -> Result<(), TransportError> { ®istrar, &voter, &voter_authority, - &mngo_rate, + &mngo_voting_mint, 0, voter_stake_registry::state::LockupKind::Cliff, 3, // days diff --git a/programs/voter-stake-registry/tests/test_deposit_daily_vesting.rs b/programs/voter-stake-registry/tests/test_deposit_daily_vesting.rs index 71bd6ae..4881c29 100644 --- a/programs/voter-stake-registry/tests/test_deposit_daily_vesting.rs +++ b/programs/voter-stake-registry/tests/test_deposit_daily_vesting.rs @@ -17,7 +17,7 @@ async fn balances( registrar: &RegistrarCookie, address: Pubkey, voter: &VoterCookie, - rate: &ExchangeRateCookie, + voting_mint: &VotingMintConfigCookie, deposit_id: u8, ) -> Balances { // Advance slots to avoid caching of the UpdateVoterWeightRecord call @@ -25,7 +25,7 @@ async fn balances( context.solana.advance_clock_by_slots(2).await; let token = context.solana.token_account_balance(address).await; - let vault = rate.vault_balance(&context.solana).await; + let vault = voting_mint.vault_balance(&context.solana).await; let deposit = voter.deposit_amount(&context.solana, deposit_id).await; let vwr = context .addin @@ -67,8 +67,8 @@ async fn test_deposit_daily_vesting() -> Result<(), TransportError> { let registrar = addin .create_registrar(&realm, &realm_authority, payer) .await; - let mngo_rate = addin - .create_exchange_rate(®istrar, &realm_authority, payer, 0, &context.mints[0], 1) + let mngo_voting_mint = addin + .configure_voting_mint(®istrar, &realm_authority, payer, 0, &context.mints[0], 1) .await; let voter = addin @@ -82,7 +82,7 @@ async fn test_deposit_daily_vesting() -> Result<(), TransportError> { ®istrar, reference_account, &voter, - &mngo_rate, + &mngo_voting_mint, depot_id, ) }; @@ -91,7 +91,7 @@ async fn test_deposit_daily_vesting() -> Result<(), TransportError> { ®istrar, &voter, &token_owner_record, - &mngo_rate, + &mngo_voting_mint, &voter_authority, reference_account, 0, @@ -102,7 +102,7 @@ async fn test_deposit_daily_vesting() -> Result<(), TransportError> { addin.deposit( ®istrar, &voter, - &mngo_rate, + &mngo_voting_mint, &voter_authority, reference_account, 0, @@ -121,7 +121,7 @@ async fn test_deposit_daily_vesting() -> Result<(), TransportError> { ®istrar, &voter, &voter_authority, - &mngo_rate, + &mngo_voting_mint, 0, voter_stake_registry::state::LockupKind::Daily, 3, diff --git a/programs/voter-stake-registry/tests/test_deposit_monthly_vesting.rs b/programs/voter-stake-registry/tests/test_deposit_monthly_vesting.rs index b8e8b59..2793287 100644 --- a/programs/voter-stake-registry/tests/test_deposit_monthly_vesting.rs +++ b/programs/voter-stake-registry/tests/test_deposit_monthly_vesting.rs @@ -17,7 +17,7 @@ async fn balances( registrar: &RegistrarCookie, address: Pubkey, voter: &VoterCookie, - rate: &ExchangeRateCookie, + rate: &VotingMintConfigCookie, deposit_id: u8, ) -> Balances { // Advance slots to avoid caching of the UpdateVoterWeightRecord call @@ -67,8 +67,8 @@ async fn test_deposit_monthly_vesting() -> Result<(), TransportError> { let registrar = addin .create_registrar(&realm, &realm_authority, payer) .await; - let mngo_rate = addin - .create_exchange_rate(®istrar, &realm_authority, payer, 0, &context.mints[0], 1) + let mngo_voting_mint = addin + .configure_voting_mint(®istrar, &realm_authority, payer, 0, &context.mints[0], 1) .await; let voter = addin @@ -82,7 +82,7 @@ async fn test_deposit_monthly_vesting() -> Result<(), TransportError> { ®istrar, reference_account, &voter, - &mngo_rate, + &mngo_voting_mint, depot_id, ) }; @@ -91,7 +91,7 @@ async fn test_deposit_monthly_vesting() -> Result<(), TransportError> { ®istrar, &voter, &token_owner_record, - &mngo_rate, + &mngo_voting_mint, &voter_authority, reference_account, 0, @@ -102,7 +102,7 @@ async fn test_deposit_monthly_vesting() -> Result<(), TransportError> { addin.deposit( ®istrar, &voter, - &mngo_rate, + &mngo_voting_mint, &voter_authority, reference_account, 0, @@ -121,7 +121,7 @@ async fn test_deposit_monthly_vesting() -> Result<(), TransportError> { ®istrar, &voter, &voter_authority, - &mngo_rate, + &mngo_voting_mint, 0, voter_stake_registry::state::LockupKind::Monthly, 3, diff --git a/programs/voter-stake-registry/tests/test_deposit_no_locking.rs b/programs/voter-stake-registry/tests/test_deposit_no_locking.rs index ca444bd..d630268 100644 --- a/programs/voter-stake-registry/tests/test_deposit_no_locking.rs +++ b/programs/voter-stake-registry/tests/test_deposit_no_locking.rs @@ -19,7 +19,7 @@ async fn balances( registrar: &RegistrarCookie, address: Pubkey, voter: &VoterCookie, - rate: &ExchangeRateCookie, + voting_mint: &VotingMintConfigCookie, deposit_id: u8, ) -> Balances { // Advance slots to avoid caching of the UpdateVoterWeightRecord call @@ -27,7 +27,7 @@ async fn balances( context.solana.advance_clock_by_slots(2).await; let token = context.solana.token_account_balance(address).await; - let vault = rate.vault_balance(&context.solana).await; + let vault = voting_mint.vault_balance(&context.solana).await; let deposit = voter.deposit_amount(&context.solana, deposit_id).await; let vwr = context .addin @@ -73,8 +73,8 @@ async fn test_deposit_no_locking() -> Result<(), TransportError> { let registrar = addin .create_registrar(&realm, &realm_authority, payer) .await; - let mngo_rate = addin - .create_exchange_rate(®istrar, &realm_authority, payer, 0, &context.mints[0], 1) + let mngo_voting_mint = addin + .configure_voting_mint(®istrar, &realm_authority, payer, 0, &context.mints[0], 1) .await; let voter = addin @@ -92,7 +92,7 @@ async fn test_deposit_no_locking() -> Result<(), TransportError> { ®istrar, reference_account, &voter, - &mngo_rate, + &mngo_voting_mint, depot_id, ) }; @@ -101,7 +101,7 @@ async fn test_deposit_no_locking() -> Result<(), TransportError> { ®istrar, &voter, &token_owner_record, - &mngo_rate, + &mngo_voting_mint, &voter_authority, reference_account, 0, @@ -112,7 +112,7 @@ async fn test_deposit_no_locking() -> Result<(), TransportError> { addin.deposit( ®istrar, &voter, - &mngo_rate, + &mngo_voting_mint, &voter_authority, reference_account, deposit_id, @@ -130,7 +130,7 @@ async fn test_deposit_no_locking() -> Result<(), TransportError> { ®istrar, &voter, &voter_authority, - &mngo_rate, + &mngo_voting_mint, 0, LockupKind::None, 0, @@ -161,7 +161,7 @@ async fn test_deposit_no_locking() -> Result<(), TransportError> { ®istrar, &voter, &voter_authority, - &mngo_rate, + &mngo_voting_mint, 1, LockupKind::None, 0, @@ -226,7 +226,7 @@ async fn test_deposit_no_locking() -> Result<(), TransportError> { ®istrar, reference_account, &voter2, - &mngo_rate, + &mngo_voting_mint, 0, ) .await; @@ -239,7 +239,7 @@ async fn test_deposit_no_locking() -> Result<(), TransportError> { ®istrar, &voter2, &voter2_authority, - &mngo_rate, + &mngo_voting_mint, 5, LockupKind::None, 0, @@ -251,7 +251,7 @@ async fn test_deposit_no_locking() -> Result<(), TransportError> { .deposit( ®istrar, &voter2, - &mngo_rate, + &mngo_voting_mint, &voter2_authority, context.users[2].token_accounts[0], 5, @@ -265,7 +265,7 @@ async fn test_deposit_no_locking() -> Result<(), TransportError> { ®istrar, reference_account, &voter2, - &mngo_rate, + &mngo_voting_mint, 5, ) .await; @@ -279,7 +279,7 @@ async fn test_deposit_no_locking() -> Result<(), TransportError> { ®istrar, &voter, &voter_authority, - &mngo_rate, + &mngo_voting_mint, 0, LockupKind::None, 0, diff --git a/programs/voter-stake-registry/tests/test_reset_lockup.rs b/programs/voter-stake-registry/tests/test_reset_lockup.rs index 39e5409..2066f1e 100644 --- a/programs/voter-stake-registry/tests/test_reset_lockup.rs +++ b/programs/voter-stake-registry/tests/test_reset_lockup.rs @@ -56,8 +56,8 @@ async fn test_reset_lockup() -> Result<(), TransportError> { let registrar = addin .create_registrar(&realm, &realm_authority, payer) .await; - let mngo_rate = addin - .create_exchange_rate(®istrar, &realm_authority, payer, 0, &context.mints[0], 1) + let mngo_voting_mint = addin + .configure_voting_mint(®istrar, &realm_authority, payer, 0, &context.mints[0], 1) .await; let voter = addin @@ -70,7 +70,7 @@ async fn test_reset_lockup() -> Result<(), TransportError> { ®istrar, &voter, &token_owner_record, - &mngo_rate, + &mngo_voting_mint, &voter_authority, reference_account, index, @@ -81,7 +81,7 @@ async fn test_reset_lockup() -> Result<(), TransportError> { addin.deposit( ®istrar, &voter, - &mngo_rate, + &mngo_voting_mint, &voter_authority, reference_account, index, @@ -108,7 +108,7 @@ async fn test_reset_lockup() -> Result<(), TransportError> { ®istrar, &voter, &voter_authority, - &mngo_rate, + &mngo_voting_mint, 7, voter_stake_registry::state::LockupKind::Daily, 3, @@ -181,7 +181,7 @@ async fn test_reset_lockup() -> Result<(), TransportError> { ®istrar, &voter, &voter_authority, - &mngo_rate, + &mngo_voting_mint, 5, voter_stake_registry::state::LockupKind::Cliff, 3,