Rename ExchangeRate -> VotingMintConfig

This commit is contained in:
Christian Kamm 2021-12-03 20:36:42 +01:00
parent 0f4a0a40c9
commit 3374f6c09c
24 changed files with 137 additions and 134 deletions

View File

@ -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.

View File

@ -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("")]

View File

@ -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<Account<'info, Registrar>>,
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<CreateExchangeRate>,
pub fn configure_voting_mint(
ctx: Context<ConfigureVotingMint>,
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(())
}

View File

@ -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;

View File

@ -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<CreateRegistrar>,

View File

@ -57,8 +57,11 @@ pub fn deposit(ctx: Context<Deposit>, 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)?;

View File

@ -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;

View File

@ -30,9 +30,9 @@ pub fn update_max_vote_weight<'info>(ctx: Context<UpdateMaxVoteWeight>) -> Resul
.collect::<std::result::Result<Vec<Account<Mint>>, 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)
});

View File

@ -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
);

View File

@ -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<CreateExchangeRate>,
pub fn configure_voting_mint(
ctx: Context<ConfigureVotingMint>,
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(

View File

@ -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<u64> {
let fixed_contribution = rate
pub fn voting_power(&self, voting_mint_config: &VotingMintConfig, curr_ts: i64) -> Result<u64> {
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)?

View File

@ -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,

View File

@ -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;

View File

@ -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<ExchangeRateEntry> {
pub fn new_rate(&self, mint: Pubkey, mint_decimals: u8, rate: u64) -> Result<VotingMintConfig> {
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<usize> {
self.rates
pub fn voting_mint_config_index(&self, mint: Pubkey) -> Result<usize> {
self.voting_mints
.iter()
.position(|r| r.mint == mint)
.ok_or(Error::ErrorCode(ErrorCode::ExchangeRateEntryNotFound))
.ok_or(Error::ErrorCode(ErrorCode::VotingMintNotFound))
}
}

View File

@ -27,8 +27,11 @@ impl Voter {
.iter()
.filter(|d| d.is_used)
.try_fold(0, |sum, d| {
d.voting_power(&registrar.rates[d.rate_idx as usize], curr_ts)
.map(|vp| sum + vp)
d.voting_power(
&registrar.voting_mints[d.voting_mint_config_idx as usize],
curr_ts,
)
.map(|vp| sum + vp)
})
}

View File

@ -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 {}

View File

@ -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(
&registrar.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::<TokenAccount>(self.vault).await.amount
}

View File

@ -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(&registrar, &realm_authority, payer, 0, &context.mints[0], 1)
.configure_voting_mint(&registrar, &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> {
&registrar,
&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(
&registrar,
&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> {
&registrar,
&voter,
&token_owner_record,
&mngo_rate,
&mngo_voting_mint,
&voter_authority,
reference_account,
0,
@ -115,7 +115,7 @@ async fn test_basic() -> Result<(), TransportError> {
&registrar,
&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);

View File

@ -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(
&registrar,
&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> {
&registrar,
&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(
&registrar,
&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> {
&registrar,
&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> {
&registrar,
&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> {
&registrar,
&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> {
&registrar,
&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);

View File

@ -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(&registrar, &realm_authority, payer, 0, &context.mints[0], 1)
let mngo_voting_mint = addin
.configure_voting_mint(&registrar, &realm_authority, payer, 0, &context.mints[0], 1)
.await;
let voter = addin
@ -82,7 +82,7 @@ async fn test_deposit_cliff() -> Result<(), TransportError> {
&registrar,
reference_account,
&voter,
&mngo_rate,
&mngo_voting_mint,
depot_id,
)
};
@ -91,7 +91,7 @@ async fn test_deposit_cliff() -> Result<(), TransportError> {
&registrar,
&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(
&registrar,
&voter,
&mngo_rate,
&mngo_voting_mint,
&voter_authority,
reference_account,
0,
@ -121,7 +121,7 @@ async fn test_deposit_cliff() -> Result<(), TransportError> {
&registrar,
&voter,
&voter_authority,
&mngo_rate,
&mngo_voting_mint,
0,
voter_stake_registry::state::LockupKind::Cliff,
3, // days

View File

@ -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(&registrar, &realm_authority, payer, 0, &context.mints[0], 1)
let mngo_voting_mint = addin
.configure_voting_mint(&registrar, &realm_authority, payer, 0, &context.mints[0], 1)
.await;
let voter = addin
@ -82,7 +82,7 @@ async fn test_deposit_daily_vesting() -> Result<(), TransportError> {
&registrar,
reference_account,
&voter,
&mngo_rate,
&mngo_voting_mint,
depot_id,
)
};
@ -91,7 +91,7 @@ async fn test_deposit_daily_vesting() -> Result<(), TransportError> {
&registrar,
&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(
&registrar,
&voter,
&mngo_rate,
&mngo_voting_mint,
&voter_authority,
reference_account,
0,
@ -121,7 +121,7 @@ async fn test_deposit_daily_vesting() -> Result<(), TransportError> {
&registrar,
&voter,
&voter_authority,
&mngo_rate,
&mngo_voting_mint,
0,
voter_stake_registry::state::LockupKind::Daily,
3,

View File

@ -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(&registrar, &realm_authority, payer, 0, &context.mints[0], 1)
let mngo_voting_mint = addin
.configure_voting_mint(&registrar, &realm_authority, payer, 0, &context.mints[0], 1)
.await;
let voter = addin
@ -82,7 +82,7 @@ async fn test_deposit_monthly_vesting() -> Result<(), TransportError> {
&registrar,
reference_account,
&voter,
&mngo_rate,
&mngo_voting_mint,
depot_id,
)
};
@ -91,7 +91,7 @@ async fn test_deposit_monthly_vesting() -> Result<(), TransportError> {
&registrar,
&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(
&registrar,
&voter,
&mngo_rate,
&mngo_voting_mint,
&voter_authority,
reference_account,
0,
@ -121,7 +121,7 @@ async fn test_deposit_monthly_vesting() -> Result<(), TransportError> {
&registrar,
&voter,
&voter_authority,
&mngo_rate,
&mngo_voting_mint,
0,
voter_stake_registry::state::LockupKind::Monthly,
3,

View File

@ -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(&registrar, &realm_authority, payer, 0, &context.mints[0], 1)
let mngo_voting_mint = addin
.configure_voting_mint(&registrar, &realm_authority, payer, 0, &context.mints[0], 1)
.await;
let voter = addin
@ -92,7 +92,7 @@ async fn test_deposit_no_locking() -> Result<(), TransportError> {
&registrar,
reference_account,
&voter,
&mngo_rate,
&mngo_voting_mint,
depot_id,
)
};
@ -101,7 +101,7 @@ async fn test_deposit_no_locking() -> Result<(), TransportError> {
&registrar,
&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(
&registrar,
&voter,
&mngo_rate,
&mngo_voting_mint,
&voter_authority,
reference_account,
deposit_id,
@ -130,7 +130,7 @@ async fn test_deposit_no_locking() -> Result<(), TransportError> {
&registrar,
&voter,
&voter_authority,
&mngo_rate,
&mngo_voting_mint,
0,
LockupKind::None,
0,
@ -161,7 +161,7 @@ async fn test_deposit_no_locking() -> Result<(), TransportError> {
&registrar,
&voter,
&voter_authority,
&mngo_rate,
&mngo_voting_mint,
1,
LockupKind::None,
0,
@ -226,7 +226,7 @@ async fn test_deposit_no_locking() -> Result<(), TransportError> {
&registrar,
reference_account,
&voter2,
&mngo_rate,
&mngo_voting_mint,
0,
)
.await;
@ -239,7 +239,7 @@ async fn test_deposit_no_locking() -> Result<(), TransportError> {
&registrar,
&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(
&registrar,
&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> {
&registrar,
reference_account,
&voter2,
&mngo_rate,
&mngo_voting_mint,
5,
)
.await;
@ -279,7 +279,7 @@ async fn test_deposit_no_locking() -> Result<(), TransportError> {
&registrar,
&voter,
&voter_authority,
&mngo_rate,
&mngo_voting_mint,
0,
LockupKind::None,
0,

View File

@ -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(&registrar, &realm_authority, payer, 0, &context.mints[0], 1)
let mngo_voting_mint = addin
.configure_voting_mint(&registrar, &realm_authority, payer, 0, &context.mints[0], 1)
.await;
let voter = addin
@ -70,7 +70,7 @@ async fn test_reset_lockup() -> Result<(), TransportError> {
&registrar,
&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(
&registrar,
&voter,
&mngo_rate,
&mngo_voting_mint,
&voter_authority,
reference_account,
index,
@ -108,7 +108,7 @@ async fn test_reset_lockup() -> Result<(), TransportError> {
&registrar,
&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> {
&registrar,
&voter,
&voter_authority,
&mngo_rate,
&mngo_voting_mint,
5,
voter_stake_registry::state::LockupKind::Cliff,
3,