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: realm authority to:
1. Deploy an instance of the voter-stake-registry. 1. Deploy an instance of the voter-stake-registry.
2. Create a registrar for the realm with the `CreateRegistrar` instruction. 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. instruction as often as desired.
4. Call the `SetRealmConfig` instruction on spl-governance to set the 4. Call the `SetRealmConfig` instruction on spl-governance to set the
voter-weight-addin program id and thereby enable the addin. voter-weight-addin program id and thereby enable the addin.

View File

@ -7,7 +7,7 @@ pub enum ErrorCode {
#[msg("")] #[msg("")]
RatesFull, RatesFull,
#[msg("")] #[msg("")]
ExchangeRateEntryNotFound, // 302 VotingMintNotFound, // 302
#[msg("")] #[msg("")]
DepositEntryNotFound, DepositEntryNotFound,
#[msg("")] #[msg("")]
@ -29,9 +29,9 @@ pub enum ErrorCode {
#[msg("")] #[msg("")]
InvalidDays, InvalidDays,
#[msg("")] #[msg("")]
RatesIndexAlreadyInUse, VotingMintConfigIndexAlreadyInUse,
#[msg("")] #[msg("")]
OutOfBoundsRatesIndex, OutOfBoundsVotingMintConfigIndex,
#[msg("Exchange rate decimals cannot be larger than registrar decimals")] #[msg("Exchange rate decimals cannot be larger than registrar decimals")]
InvalidDecimals, InvalidDecimals,
#[msg("")] #[msg("")]

View File

@ -6,7 +6,7 @@ use anchor_spl::token::{Mint, Token, TokenAccount};
#[derive(Accounts)] #[derive(Accounts)]
#[instruction(idx: u16, rate: u64, decimals: u8)] #[instruction(idx: u16, rate: u64, decimals: u8)]
pub struct CreateExchangeRate<'info> { pub struct ConfigureVotingMint<'info> {
#[account(mut, has_one = realm_authority)] #[account(mut, has_one = realm_authority)]
pub registrar: Box<Account<'info, Registrar>>, pub registrar: Box<Account<'info, Registrar>>,
pub realm_authority: Signer<'info>, pub realm_authority: Signer<'info>,
@ -43,23 +43,24 @@ pub struct CreateExchangeRate<'info> {
/// ``` /// ```
/// rate * 10^vote_weight_decimals / 10^decimals /// rate * 10^vote_weight_decimals / 10^decimals
/// ``` /// ```
pub fn create_exchange_rate( pub fn configure_voting_mint(
ctx: Context<CreateExchangeRate>, ctx: Context<ConfigureVotingMint>,
idx: u16, idx: u16,
rate: u64, rate: u64,
decimals: u8, decimals: u8,
) -> Result<()> { ) -> Result<()> {
msg!("--------create_exchange_rate--------"); msg!("--------configure_voting_mint--------");
require!(rate > 0, InvalidRate); require!(rate > 0, InvalidRate);
let registrar = &mut ctx.accounts.registrar; let registrar = &mut ctx.accounts.registrar;
require!( require!(
(idx as usize) < registrar.rates.len(), (idx as usize) < registrar.voting_mints.len(),
OutOfBoundsRatesIndex OutOfBoundsVotingMintConfigIndex
); );
require!( require!(
registrar.rates[idx as usize].rate == 0, registrar.voting_mints[idx as usize].rate == 0,
RatesIndexAlreadyInUse 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(()) Ok(())
} }

View File

@ -37,7 +37,7 @@ pub fn create_deposit_entry(
let voter = &mut ctx.accounts.voter.load_mut()?; let voter = &mut ctx.accounts.voter.load_mut()?;
// Get the exchange rate entry associated with this deposit. // 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. // Get and set up the deposit entry.
require!( require!(
@ -49,7 +49,7 @@ pub fn create_deposit_entry(
*d_entry = DepositEntry::default(); *d_entry = DepositEntry::default();
d_entry.is_used = true; 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_deposited_native = 0;
d_entry.amount_initially_locked_native = 0; d_entry.amount_initially_locked_native = 0;
d_entry.allow_clawback = allow_clawback; 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 /// `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. /// 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. /// used for voting.
pub fn create_registrar( pub fn create_registrar(
ctx: Context<CreateRegistrar>, 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)?; let d_entry = voter.active_deposit_mut(deposit_entry_index)?;
// Get the exchange rate entry associated with this deposit. // Get the exchange rate entry associated with this deposit.
let er_idx = registrar.exchange_rate_index_for_mint(ctx.accounts.deposit_token.mint)?; let mint_idx = registrar.voting_mint_config_index(ctx.accounts.deposit_token.mint)?;
require!(er_idx == d_entry.rate_idx as usize, InvalidMint); require!(
mint_idx == d_entry.voting_mint_config_idx as usize,
InvalidMint
);
// Deposit tokens into the registrar. // Deposit tokens into the registrar.
token::transfer(ctx.accounts.transfer_ctx(), amount)?; token::transfer(ctx.accounts.transfer_ctx(), amount)?;

View File

@ -1,8 +1,8 @@
pub use clawback::*; pub use clawback::*;
pub use close_deposit_entry::*; pub use close_deposit_entry::*;
pub use close_voter::*; pub use close_voter::*;
pub use configure_voting_mint::*;
pub use create_deposit_entry::*; pub use create_deposit_entry::*;
pub use create_exchange_rate::*;
pub use create_registrar::*; pub use create_registrar::*;
pub use create_voter::*; pub use create_voter::*;
pub use deposit::*; pub use deposit::*;
@ -15,8 +15,8 @@ pub use withdraw::*;
mod clawback; mod clawback;
mod close_deposit_entry; mod close_deposit_entry;
mod close_voter; mod close_voter;
mod configure_voting_mint;
mod create_deposit_entry; mod create_deposit_entry;
mod create_exchange_rate;
mod create_registrar; mod create_registrar;
mod create_voter; mod create_voter;
mod deposit; 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>>()? .collect::<std::result::Result<Vec<Account<Mint>>, ProgramError>>()?
.iter() .iter()
.try_fold(0u64, |sum, m| { .try_fold(0u64, |sum, m| {
let er_idx = registrar.exchange_rate_index_for_mint(m.key())?; let mint_idx = registrar.voting_mint_config_index(m.key())?;
let er_entry = registrar.rates[er_idx]; let mint_config = registrar.voting_mints[mint_idx];
let amount = er_entry.convert(m.supply); let amount = mint_config.convert(m.supply);
let total = sum.checked_add(amount).unwrap(); let total = sum.checked_add(amount).unwrap();
Ok(total) Ok(total)
}); });

View File

@ -102,9 +102,9 @@ pub fn withdraw(
); );
// Get the exchange rate for the token being withdrawn. // 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!( require!(
er_idx == deposit_entry.rate_idx as usize, mint_idx == deposit_entry.voting_mint_config_idx as usize,
ErrorCode::InvalidMint ErrorCode::InvalidMint
); );

View File

@ -66,13 +66,13 @@ pub mod voter_stake_registry {
instructions::create_registrar(ctx, vote_weight_decimals, registrar_bump) instructions::create_registrar(ctx, vote_weight_decimals, registrar_bump)
} }
pub fn create_exchange_rate( pub fn configure_voting_mint(
ctx: Context<CreateExchangeRate>, ctx: Context<ConfigureVotingMint>,
idx: u16, idx: u16,
rate: u64, rate: u64,
decimals: u8, decimals: u8,
) -> Result<()> { ) -> Result<()> {
instructions::create_exchange_rate(ctx, idx, rate, decimals) instructions::configure_voting_mint(ctx, idx, rate, decimals)
} }
pub fn create_voter( pub fn create_voter(

View File

@ -1,6 +1,6 @@
use crate::error::*; use crate::error::*;
use crate::state::exchange_entry::ExchangeRateEntry;
use crate::state::lockup::{Lockup, LockupKind}; use crate::state::lockup::{Lockup, LockupKind};
use crate::state::voting_mint_config::VotingMintConfig;
use anchor_lang::prelude::*; use anchor_lang::prelude::*;
/// Vote weight is amount * FIXED_VOTE_WEIGHT_FACTOR + /// Vote weight is amount * FIXED_VOTE_WEIGHT_FACTOR +
@ -15,8 +15,8 @@ pub struct DepositEntry {
// True if the deposit entry is being used. // True if the deposit entry is being used.
pub is_used: bool, pub is_used: bool,
// Points to the ExchangeRate this deposit uses. // Points to the VotingMintConfig this deposit uses.
pub rate_idx: u8, pub voting_mint_config_idx: u8,
/// Amount in deposited, in native currency. Withdraws of vested tokens /// Amount in deposited, in native currency. Withdraws of vested tokens
/// directly reduce this amount. /// directly reduce this amount.
@ -137,8 +137,8 @@ impl DepositEntry {
/// a time factor of 1/2555. /// a time factor of 1/2555.
/// ///
/// The computation below uses 1 + 2 + ... + n = n * (n + 1) / 2. /// The computation below uses 1 + 2 + ... + n = n * (n + 1) / 2.
pub fn voting_power(&self, rate: &ExchangeRateEntry, curr_ts: i64) -> Result<u64> { pub fn voting_power(&self, voting_mint_config: &VotingMintConfig, curr_ts: i64) -> Result<u64> {
let fixed_contribution = rate let fixed_contribution = voting_mint_config
.convert(self.amount_deposited_native) .convert(self.amount_deposited_native)
.checked_mul(FIXED_VOTE_WEIGHT_FACTOR) .checked_mul(FIXED_VOTE_WEIGHT_FACTOR)
.unwrap(); .unwrap();
@ -146,7 +146,8 @@ impl DepositEntry {
return Ok(fixed_contribution); 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 Ok(fixed_contribution
+ self + self
.voting_power_locked(curr_ts, max_locked_contribution)? .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 end_ts = start_ts + days_to_secs(t.days_total);
let d = DepositEntry { let d = DepositEntry {
is_used: true, is_used: true,
rate_idx: 0, voting_mint_config_idx: 0,
amount_deposited_native: t.amount_deposited, amount_deposited_native: t.amount_deposited,
amount_initially_locked_native: t.amount_deposited, amount_initially_locked_native: t.amount_deposited,
allow_clawback: false, allow_clawback: false,

View File

@ -1,11 +1,11 @@
pub use deposit_entry::*; pub use deposit_entry::*;
pub use exchange_entry::*;
pub use lockup::*; pub use lockup::*;
pub use registrar::*; pub use registrar::*;
pub use voter::*; pub use voter::*;
pub use voting_mint_config::*;
mod deposit_entry; mod deposit_entry;
mod exchange_entry;
mod lockup; mod lockup;
mod registrar; mod registrar;
mod voter; mod voter;
mod voting_mint_config;

View File

@ -1,5 +1,5 @@
use crate::error::*; use crate::error::*;
use crate::state::exchange_entry::ExchangeRateEntry; use crate::state::voting_mint_config::VotingMintConfig;
use anchor_lang::prelude::*; use anchor_lang::prelude::*;
/// Instance of a voting rights distributor. /// Instance of a voting rights distributor.
@ -13,7 +13,7 @@ pub struct Registrar {
pub clawback_authority: Pubkey, pub clawback_authority: Pubkey,
pub bump: u8, pub bump: u8,
// The length should be adjusted for one's use case. // 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. /// The decimals to use when converting deposits into a common currency.
/// ///
@ -26,18 +26,13 @@ pub struct Registrar {
} }
impl Registrar { impl Registrar {
pub fn new_rate( pub fn new_rate(&self, mint: Pubkey, mint_decimals: u8, rate: u64) -> Result<VotingMintConfig> {
&self,
mint: Pubkey,
mint_decimals: u8,
rate: u64,
) -> Result<ExchangeRateEntry> {
require!(self.vote_weight_decimals >= mint_decimals, InvalidDecimals); require!(self.vote_weight_decimals >= mint_decimals, InvalidDecimals);
let decimal_diff = self let decimal_diff = self
.vote_weight_decimals .vote_weight_decimals
.checked_sub(mint_decimals) .checked_sub(mint_decimals)
.unwrap(); .unwrap();
Ok(ExchangeRateEntry { Ok(VotingMintConfig {
mint, mint,
rate, rate,
mint_decimals, mint_decimals,
@ -49,11 +44,11 @@ impl Registrar {
Clock::get().unwrap().unix_timestamp + self.time_offset Clock::get().unwrap().unix_timestamp + self.time_offset
} }
pub fn exchange_rate_index_for_mint(&self, mint: Pubkey) -> Result<usize> { pub fn voting_mint_config_index(&self, mint: Pubkey) -> Result<usize> {
self.rates self.voting_mints
.iter() .iter()
.position(|r| r.mint == mint) .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() .iter()
.filter(|d| d.is_used) .filter(|d| d.is_used)
.try_fold(0, |sum, d| { .try_fold(0, |sum, d| {
d.voting_power(&registrar.rates[d.rate_idx as usize], curr_ts) d.voting_power(
.map(|vp| sum + vp) &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. /// Exchange rate for an asset that can be used to mint voting rights.
#[zero_copy] #[zero_copy]
#[derive(AnchorSerialize, AnchorDeserialize, Default)] #[derive(AnchorSerialize, AnchorDeserialize, Default)]
pub struct ExchangeRateEntry { pub struct VotingMintConfig {
/// Mint for this entry. /// Mint for this entry.
pub mint: Pubkey, pub mint: Pubkey,
@ -28,12 +28,12 @@ pub struct ExchangeRateEntry {
pub conversion_factor: u64, pub conversion_factor: u64,
} }
impl ExchangeRateEntry { impl VotingMintConfig {
/// Converts an amount in this ExchangeRateEntry's mint's native currency /// Converts an amount in this voting mints's native currency
/// to the equivalent common registrar vote currency amount. /// to the equivalent common registrar vote currency amount.
pub fn convert(&self, amount_native: u64) -> u64 { pub fn convert(&self, amount_native: u64) -> u64 {
amount_native.checked_mul(self.conversion_factor).unwrap() 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)] #[derive(Clone, Copy)]
pub struct ExchangeRateCookie { pub struct VotingMintConfigCookie {
pub mint: MintCookie, pub mint: MintCookie,
pub vault: Pubkey, pub vault: Pubkey,
} }
@ -96,7 +96,7 @@ impl AddinCookie {
} }
} }
pub async fn create_exchange_rate( pub async fn configure_voting_mint(
&self, &self,
registrar: &RegistrarCookie, registrar: &RegistrarCookie,
authority: &Keypair, authority: &Keypair,
@ -104,7 +104,7 @@ impl AddinCookie {
index: u16, index: u16,
mint: &MintCookie, mint: &MintCookie,
rate: u64, rate: u64,
) -> ExchangeRateCookie { ) -> VotingMintConfigCookie {
let deposit_mint = mint.pubkey.unwrap(); let deposit_mint = mint.pubkey.unwrap();
let vault = spl_associated_token_account::get_associated_token_address( let vault = spl_associated_token_account::get_associated_token_address(
&registrar.address, &registrar.address,
@ -112,7 +112,7 @@ impl AddinCookie {
); );
let data = anchor_lang::InstructionData::data( let data = anchor_lang::InstructionData::data(
&voter_stake_registry::instruction::CreateExchangeRate { &voter_stake_registry::instruction::ConfigureVotingMint {
idx: index, idx: index,
rate, rate,
decimals: mint.decimals, decimals: mint.decimals,
@ -120,7 +120,7 @@ impl AddinCookie {
); );
let accounts = anchor_lang::ToAccountMetas::to_account_metas( let accounts = anchor_lang::ToAccountMetas::to_account_metas(
&voter_stake_registry::accounts::CreateExchangeRate { &voter_stake_registry::accounts::ConfigureVotingMint {
vault, vault,
mint: deposit_mint, mint: deposit_mint,
registrar: registrar.address, registrar: registrar.address,
@ -149,7 +149,7 @@ impl AddinCookie {
.await .await
.unwrap(); .unwrap();
ExchangeRateCookie { VotingMintConfigCookie {
mint: mint.clone(), mint: mint.clone(),
vault, vault,
} }
@ -227,7 +227,7 @@ impl AddinCookie {
registrar: &RegistrarCookie, registrar: &RegistrarCookie,
voter: &VoterCookie, voter: &VoterCookie,
voter_authority: &Keypair, voter_authority: &Keypair,
exchange_rate: &ExchangeRateCookie, voting_mint: &VotingMintConfigCookie,
deposit_entry_index: u8, deposit_entry_index: u8,
lockup_kind: voter_stake_registry::state::LockupKind, lockup_kind: voter_stake_registry::state::LockupKind,
periods: u32, periods: u32,
@ -247,7 +247,7 @@ impl AddinCookie {
registrar: registrar.address, registrar: registrar.address,
voter: voter.address, voter: voter.address,
voter_authority: voter_authority.pubkey(), voter_authority: voter_authority.pubkey(),
deposit_mint: exchange_rate.mint.pubkey.unwrap(), deposit_mint: voting_mint.mint.pubkey.unwrap(),
}, },
None, None,
); );
@ -270,7 +270,7 @@ impl AddinCookie {
&self, &self,
registrar: &RegistrarCookie, registrar: &RegistrarCookie,
voter: &VoterCookie, voter: &VoterCookie,
exchange_rate: &ExchangeRateCookie, voting_mint: &VotingMintConfigCookie,
authority: &Keypair, authority: &Keypair,
token_address: Pubkey, token_address: Pubkey,
deposit_entry_index: u8, deposit_entry_index: u8,
@ -286,7 +286,7 @@ impl AddinCookie {
&voter_stake_registry::accounts::Deposit { &voter_stake_registry::accounts::Deposit {
registrar: registrar.address, registrar: registrar.address,
voter: voter.address, voter: voter.address,
vault: exchange_rate.vault, vault: voting_mint.vault,
deposit_token: token_address, deposit_token: token_address,
deposit_authority: authority.pubkey(), deposit_authority: authority.pubkey(),
token_program: spl_token::id(), token_program: spl_token::id(),
@ -314,7 +314,7 @@ impl AddinCookie {
registrar: &RegistrarCookie, registrar: &RegistrarCookie,
voter: &VoterCookie, voter: &VoterCookie,
token_owner_record: &TokenOwnerRecordCookie, token_owner_record: &TokenOwnerRecordCookie,
exchange_rate: &ExchangeRateCookie, voting_mint: &VotingMintConfigCookie,
clawback_authority: &Keypair, clawback_authority: &Keypair,
token_address: Pubkey, token_address: Pubkey,
deposit_entry_index: u8, deposit_entry_index: u8,
@ -329,7 +329,7 @@ impl AddinCookie {
registrar: registrar.address, registrar: registrar.address,
voter: voter.address, voter: voter.address,
token_owner_record: token_owner_record.address, token_owner_record: token_owner_record.address,
vault: exchange_rate.vault, vault: voting_mint.vault,
destination: token_address, destination: token_address,
authority: clawback_authority.pubkey(), authority: clawback_authority.pubkey(),
token_program: spl_token::id(), token_program: spl_token::id(),
@ -356,7 +356,7 @@ impl AddinCookie {
registrar: &RegistrarCookie, registrar: &RegistrarCookie,
voter: &VoterCookie, voter: &VoterCookie,
token_owner_record: &TokenOwnerRecordCookie, token_owner_record: &TokenOwnerRecordCookie,
exchange_rate: &ExchangeRateCookie, voting_mint: &VotingMintConfigCookie,
authority: &Keypair, authority: &Keypair,
token_address: Pubkey, token_address: Pubkey,
deposit_entry_index: u8, deposit_entry_index: u8,
@ -373,7 +373,7 @@ impl AddinCookie {
registrar: registrar.address, registrar: registrar.address,
voter: voter.address, voter: voter.address,
token_owner_record: token_owner_record.address, token_owner_record: token_owner_record.address,
vault: exchange_rate.vault, vault: voting_mint.vault,
destination: token_address, destination: token_address,
authority: authority.pubkey(), authority: authority.pubkey(),
token_program: spl_token::id(), token_program: spl_token::id(),
@ -540,7 +540,7 @@ impl AddinCookie {
} }
} }
impl ExchangeRateCookie { impl VotingMintConfigCookie {
pub async fn vault_balance(&self, solana: &SolanaCookie) -> u64 { pub async fn vault_balance(&self, solana: &SolanaCookie) -> u64 {
solana.get_account::<TokenAccount>(self.vault).await.amount solana.get_account::<TokenAccount>(self.vault).await.amount
} }

View File

@ -33,9 +33,9 @@ async fn test_basic() -> Result<(), TransportError> {
.addin .addin
.create_registrar(&realm, &realm_authority, payer) .create_registrar(&realm, &realm_authority, payer)
.await; .await;
let mngo_rate = context let mngo_voting_mint = context
.addin .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; .await;
let voter = context let voter = context
@ -50,7 +50,7 @@ async fn test_basic() -> Result<(), TransportError> {
.solana .solana
.token_account_balance(reference_account) .token_account_balance(reference_account)
.await; .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); assert_eq!(vault_initial, 0);
let balance_initial = voter.deposit_amount(&context.solana, 0).await; let balance_initial = voter.deposit_amount(&context.solana, 0).await;
assert_eq!(balance_initial, 0); assert_eq!(balance_initial, 0);
@ -61,7 +61,7 @@ async fn test_basic() -> Result<(), TransportError> {
&registrar, &registrar,
&voter, &voter,
voter_authority, voter_authority,
&mngo_rate, &mngo_voting_mint,
0, 0,
voter_stake_registry::state::LockupKind::Cliff, voter_stake_registry::state::LockupKind::Cliff,
0, 0,
@ -73,7 +73,7 @@ async fn test_basic() -> Result<(), TransportError> {
.deposit( .deposit(
&registrar, &registrar,
&voter, &voter,
&mngo_rate, &mngo_voting_mint,
&voter_authority, &voter_authority,
reference_account, reference_account,
0, 0,
@ -86,7 +86,7 @@ async fn test_basic() -> Result<(), TransportError> {
.token_account_balance(reference_account) .token_account_balance(reference_account)
.await; .await;
assert_eq!(reference_initial, reference_after_deposit + 10000); 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); assert_eq!(vault_after_deposit, 10000);
let balance_after_deposit = voter.deposit_amount(&context.solana, 0).await; let balance_after_deposit = voter.deposit_amount(&context.solana, 0).await;
assert_eq!(balance_after_deposit, 10000); assert_eq!(balance_after_deposit, 10000);
@ -97,7 +97,7 @@ async fn test_basic() -> Result<(), TransportError> {
&registrar, &registrar,
&voter, &voter,
&token_owner_record, &token_owner_record,
&mngo_rate, &mngo_voting_mint,
&voter_authority, &voter_authority,
reference_account, reference_account,
0, 0,
@ -115,7 +115,7 @@ async fn test_basic() -> Result<(), TransportError> {
&registrar, &registrar,
&voter, &voter,
&token_owner_record, &token_owner_record,
&mngo_rate, &mngo_voting_mint,
&voter_authority, &voter_authority,
reference_account, reference_account,
0, 0,
@ -128,7 +128,7 @@ async fn test_basic() -> Result<(), TransportError> {
.token_account_balance(reference_account) .token_account_balance(reference_account)
.await; .await;
assert_eq!(reference_initial, reference_after_withdraw); 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); assert_eq!(vault_after_withdraw, 0);
let balance_after_withdraw = voter.deposit_amount(&context.solana, 0).await; let balance_after_withdraw = voter.deposit_amount(&context.solana, 0).await;
assert_eq!(balance_after_withdraw, 0); 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) .create_registrar(&realm, realm_authority, realm_authority)
.await; .await;
println!("create_exchange_rate"); println!("configure_voting_mint");
let mngo_rate = context let mngo_voting_mint = context
.addin .addin
.create_exchange_rate( .configure_voting_mint(
&registrar, &registrar,
&realm_authority, &realm_authority,
realm_authority, realm_authority,
@ -72,7 +72,7 @@ async fn test_clawback() -> Result<(), TransportError> {
.solana .solana
.token_account_balance(voter_authority_ata) .token_account_balance(voter_authority_ata)
.await; .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); assert_eq!(vault_initial, 0);
let voter_balance_initial = voter.deposit_amount(&context.solana, 0).await; let voter_balance_initial = voter.deposit_amount(&context.solana, 0).await;
assert_eq!(voter_balance_initial, 0); assert_eq!(voter_balance_initial, 0);
@ -84,7 +84,7 @@ async fn test_clawback() -> Result<(), TransportError> {
&registrar, &registrar,
&voter, &voter,
voter_authority, voter_authority,
&mngo_rate, &mngo_voting_mint,
0, 0,
voter_stake_registry::state::LockupKind::Daily, voter_stake_registry::state::LockupKind::Daily,
10, 10,
@ -96,7 +96,7 @@ async fn test_clawback() -> Result<(), TransportError> {
.deposit( .deposit(
&registrar, &registrar,
&voter, &voter,
&mngo_rate, &mngo_voting_mint,
&realm_authority, &realm_authority,
realm_authority_ata, realm_authority_ata,
0, 0,
@ -109,7 +109,7 @@ async fn test_clawback() -> Result<(), TransportError> {
.token_account_balance(realm_authority_ata) .token_account_balance(realm_authority_ata)
.await; .await;
assert_eq!(realm_ata_initial, realm_ata_after_deposit + 10000); 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); assert_eq!(vault_after_deposit, 10000);
let voter_balance_after_deposit = voter.deposit_amount(&context.solana, 0).await; let voter_balance_after_deposit = voter.deposit_amount(&context.solana, 0).await;
assert_eq!(voter_balance_after_deposit, 10000); assert_eq!(voter_balance_after_deposit, 10000);
@ -121,7 +121,7 @@ async fn test_clawback() -> Result<(), TransportError> {
&registrar, &registrar,
&voter, &voter,
&token_owner_record, &token_owner_record,
&mngo_rate, &mngo_voting_mint,
&voter_authority, &voter_authority,
voter_authority_ata, voter_authority_ata,
0, 0,
@ -145,7 +145,7 @@ async fn test_clawback() -> Result<(), TransportError> {
&registrar, &registrar,
&voter, &voter,
&token_owner_record, &token_owner_record,
&mngo_rate, &mngo_voting_mint,
&voter_authority, &voter_authority,
voter_authority_ata, voter_authority_ata,
0, 0,
@ -160,7 +160,7 @@ async fn test_clawback() -> Result<(), TransportError> {
&registrar, &registrar,
&voter, &voter,
&token_owner_record, &token_owner_record,
&mngo_rate, &mngo_voting_mint,
&realm_authority, &realm_authority,
realm_authority_ata, realm_authority_ata,
0, 0,
@ -174,7 +174,7 @@ async fn test_clawback() -> Result<(), TransportError> {
&registrar, &registrar,
&voter, &voter,
&token_owner_record, &token_owner_record,
&mngo_rate, &mngo_voting_mint,
&voter_authority, &voter_authority,
voter_authority_ata, voter_authority_ata,
0, 0,
@ -192,7 +192,7 @@ async fn test_clawback() -> Result<(), TransportError> {
.token_account_balance(voter_authority_ata) .token_account_balance(voter_authority_ata)
.await; .await;
assert_eq!(voter_after_withdraw, voter_ata_initial + 2000); 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); assert_eq!(vault_after_withdraw, 0);
let voter_balance_after_withdraw = voter.deposit_amount(&context.solana, 0).await; let voter_balance_after_withdraw = voter.deposit_amount(&context.solana, 0).await;
assert_eq!(voter_balance_after_withdraw, 0); assert_eq!(voter_balance_after_withdraw, 0);

View File

@ -17,7 +17,7 @@ async fn balances(
registrar: &RegistrarCookie, registrar: &RegistrarCookie,
address: Pubkey, address: Pubkey,
voter: &VoterCookie, voter: &VoterCookie,
rate: &ExchangeRateCookie, voting_mint: &VotingMintConfigCookie,
deposit_id: u8, deposit_id: u8,
) -> Balances { ) -> Balances {
// Advance slots to avoid caching of the UpdateVoterWeightRecord call // Advance slots to avoid caching of the UpdateVoterWeightRecord call
@ -25,7 +25,7 @@ async fn balances(
context.solana.advance_clock_by_slots(2).await; context.solana.advance_clock_by_slots(2).await;
let token = context.solana.token_account_balance(address).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 deposit = voter.deposit_amount(&context.solana, deposit_id).await;
let vwr = context let vwr = context
.addin .addin
@ -67,8 +67,8 @@ async fn test_deposit_cliff() -> Result<(), TransportError> {
let registrar = addin let registrar = addin
.create_registrar(&realm, &realm_authority, payer) .create_registrar(&realm, &realm_authority, payer)
.await; .await;
let mngo_rate = addin let mngo_voting_mint = 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; .await;
let voter = addin let voter = addin
@ -82,7 +82,7 @@ async fn test_deposit_cliff() -> Result<(), TransportError> {
&registrar, &registrar,
reference_account, reference_account,
&voter, &voter,
&mngo_rate, &mngo_voting_mint,
depot_id, depot_id,
) )
}; };
@ -91,7 +91,7 @@ async fn test_deposit_cliff() -> Result<(), TransportError> {
&registrar, &registrar,
&voter, &voter,
&token_owner_record, &token_owner_record,
&mngo_rate, &mngo_voting_mint,
&voter_authority, &voter_authority,
reference_account, reference_account,
0, 0,
@ -102,7 +102,7 @@ async fn test_deposit_cliff() -> Result<(), TransportError> {
addin.deposit( addin.deposit(
&registrar, &registrar,
&voter, &voter,
&mngo_rate, &mngo_voting_mint,
&voter_authority, &voter_authority,
reference_account, reference_account,
0, 0,
@ -121,7 +121,7 @@ async fn test_deposit_cliff() -> Result<(), TransportError> {
&registrar, &registrar,
&voter, &voter,
&voter_authority, &voter_authority,
&mngo_rate, &mngo_voting_mint,
0, 0,
voter_stake_registry::state::LockupKind::Cliff, voter_stake_registry::state::LockupKind::Cliff,
3, // days 3, // days

View File

@ -17,7 +17,7 @@ async fn balances(
registrar: &RegistrarCookie, registrar: &RegistrarCookie,
address: Pubkey, address: Pubkey,
voter: &VoterCookie, voter: &VoterCookie,
rate: &ExchangeRateCookie, voting_mint: &VotingMintConfigCookie,
deposit_id: u8, deposit_id: u8,
) -> Balances { ) -> Balances {
// Advance slots to avoid caching of the UpdateVoterWeightRecord call // Advance slots to avoid caching of the UpdateVoterWeightRecord call
@ -25,7 +25,7 @@ async fn balances(
context.solana.advance_clock_by_slots(2).await; context.solana.advance_clock_by_slots(2).await;
let token = context.solana.token_account_balance(address).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 deposit = voter.deposit_amount(&context.solana, deposit_id).await;
let vwr = context let vwr = context
.addin .addin
@ -67,8 +67,8 @@ async fn test_deposit_daily_vesting() -> Result<(), TransportError> {
let registrar = addin let registrar = addin
.create_registrar(&realm, &realm_authority, payer) .create_registrar(&realm, &realm_authority, payer)
.await; .await;
let mngo_rate = addin let mngo_voting_mint = 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; .await;
let voter = addin let voter = addin
@ -82,7 +82,7 @@ async fn test_deposit_daily_vesting() -> Result<(), TransportError> {
&registrar, &registrar,
reference_account, reference_account,
&voter, &voter,
&mngo_rate, &mngo_voting_mint,
depot_id, depot_id,
) )
}; };
@ -91,7 +91,7 @@ async fn test_deposit_daily_vesting() -> Result<(), TransportError> {
&registrar, &registrar,
&voter, &voter,
&token_owner_record, &token_owner_record,
&mngo_rate, &mngo_voting_mint,
&voter_authority, &voter_authority,
reference_account, reference_account,
0, 0,
@ -102,7 +102,7 @@ async fn test_deposit_daily_vesting() -> Result<(), TransportError> {
addin.deposit( addin.deposit(
&registrar, &registrar,
&voter, &voter,
&mngo_rate, &mngo_voting_mint,
&voter_authority, &voter_authority,
reference_account, reference_account,
0, 0,
@ -121,7 +121,7 @@ async fn test_deposit_daily_vesting() -> Result<(), TransportError> {
&registrar, &registrar,
&voter, &voter,
&voter_authority, &voter_authority,
&mngo_rate, &mngo_voting_mint,
0, 0,
voter_stake_registry::state::LockupKind::Daily, voter_stake_registry::state::LockupKind::Daily,
3, 3,

View File

@ -17,7 +17,7 @@ async fn balances(
registrar: &RegistrarCookie, registrar: &RegistrarCookie,
address: Pubkey, address: Pubkey,
voter: &VoterCookie, voter: &VoterCookie,
rate: &ExchangeRateCookie, rate: &VotingMintConfigCookie,
deposit_id: u8, deposit_id: u8,
) -> Balances { ) -> Balances {
// Advance slots to avoid caching of the UpdateVoterWeightRecord call // Advance slots to avoid caching of the UpdateVoterWeightRecord call
@ -67,8 +67,8 @@ async fn test_deposit_monthly_vesting() -> Result<(), TransportError> {
let registrar = addin let registrar = addin
.create_registrar(&realm, &realm_authority, payer) .create_registrar(&realm, &realm_authority, payer)
.await; .await;
let mngo_rate = addin let mngo_voting_mint = 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; .await;
let voter = addin let voter = addin
@ -82,7 +82,7 @@ async fn test_deposit_monthly_vesting() -> Result<(), TransportError> {
&registrar, &registrar,
reference_account, reference_account,
&voter, &voter,
&mngo_rate, &mngo_voting_mint,
depot_id, depot_id,
) )
}; };
@ -91,7 +91,7 @@ async fn test_deposit_monthly_vesting() -> Result<(), TransportError> {
&registrar, &registrar,
&voter, &voter,
&token_owner_record, &token_owner_record,
&mngo_rate, &mngo_voting_mint,
&voter_authority, &voter_authority,
reference_account, reference_account,
0, 0,
@ -102,7 +102,7 @@ async fn test_deposit_monthly_vesting() -> Result<(), TransportError> {
addin.deposit( addin.deposit(
&registrar, &registrar,
&voter, &voter,
&mngo_rate, &mngo_voting_mint,
&voter_authority, &voter_authority,
reference_account, reference_account,
0, 0,
@ -121,7 +121,7 @@ async fn test_deposit_monthly_vesting() -> Result<(), TransportError> {
&registrar, &registrar,
&voter, &voter,
&voter_authority, &voter_authority,
&mngo_rate, &mngo_voting_mint,
0, 0,
voter_stake_registry::state::LockupKind::Monthly, voter_stake_registry::state::LockupKind::Monthly,
3, 3,

View File

@ -19,7 +19,7 @@ async fn balances(
registrar: &RegistrarCookie, registrar: &RegistrarCookie,
address: Pubkey, address: Pubkey,
voter: &VoterCookie, voter: &VoterCookie,
rate: &ExchangeRateCookie, voting_mint: &VotingMintConfigCookie,
deposit_id: u8, deposit_id: u8,
) -> Balances { ) -> Balances {
// Advance slots to avoid caching of the UpdateVoterWeightRecord call // Advance slots to avoid caching of the UpdateVoterWeightRecord call
@ -27,7 +27,7 @@ async fn balances(
context.solana.advance_clock_by_slots(2).await; context.solana.advance_clock_by_slots(2).await;
let token = context.solana.token_account_balance(address).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 deposit = voter.deposit_amount(&context.solana, deposit_id).await;
let vwr = context let vwr = context
.addin .addin
@ -73,8 +73,8 @@ async fn test_deposit_no_locking() -> Result<(), TransportError> {
let registrar = addin let registrar = addin
.create_registrar(&realm, &realm_authority, payer) .create_registrar(&realm, &realm_authority, payer)
.await; .await;
let mngo_rate = addin let mngo_voting_mint = 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; .await;
let voter = addin let voter = addin
@ -92,7 +92,7 @@ async fn test_deposit_no_locking() -> Result<(), TransportError> {
&registrar, &registrar,
reference_account, reference_account,
&voter, &voter,
&mngo_rate, &mngo_voting_mint,
depot_id, depot_id,
) )
}; };
@ -101,7 +101,7 @@ async fn test_deposit_no_locking() -> Result<(), TransportError> {
&registrar, &registrar,
&voter, &voter,
&token_owner_record, &token_owner_record,
&mngo_rate, &mngo_voting_mint,
&voter_authority, &voter_authority,
reference_account, reference_account,
0, 0,
@ -112,7 +112,7 @@ async fn test_deposit_no_locking() -> Result<(), TransportError> {
addin.deposit( addin.deposit(
&registrar, &registrar,
&voter, &voter,
&mngo_rate, &mngo_voting_mint,
&voter_authority, &voter_authority,
reference_account, reference_account,
deposit_id, deposit_id,
@ -130,7 +130,7 @@ async fn test_deposit_no_locking() -> Result<(), TransportError> {
&registrar, &registrar,
&voter, &voter,
&voter_authority, &voter_authority,
&mngo_rate, &mngo_voting_mint,
0, 0,
LockupKind::None, LockupKind::None,
0, 0,
@ -161,7 +161,7 @@ async fn test_deposit_no_locking() -> Result<(), TransportError> {
&registrar, &registrar,
&voter, &voter,
&voter_authority, &voter_authority,
&mngo_rate, &mngo_voting_mint,
1, 1,
LockupKind::None, LockupKind::None,
0, 0,
@ -226,7 +226,7 @@ async fn test_deposit_no_locking() -> Result<(), TransportError> {
&registrar, &registrar,
reference_account, reference_account,
&voter2, &voter2,
&mngo_rate, &mngo_voting_mint,
0, 0,
) )
.await; .await;
@ -239,7 +239,7 @@ async fn test_deposit_no_locking() -> Result<(), TransportError> {
&registrar, &registrar,
&voter2, &voter2,
&voter2_authority, &voter2_authority,
&mngo_rate, &mngo_voting_mint,
5, 5,
LockupKind::None, LockupKind::None,
0, 0,
@ -251,7 +251,7 @@ async fn test_deposit_no_locking() -> Result<(), TransportError> {
.deposit( .deposit(
&registrar, &registrar,
&voter2, &voter2,
&mngo_rate, &mngo_voting_mint,
&voter2_authority, &voter2_authority,
context.users[2].token_accounts[0], context.users[2].token_accounts[0],
5, 5,
@ -265,7 +265,7 @@ async fn test_deposit_no_locking() -> Result<(), TransportError> {
&registrar, &registrar,
reference_account, reference_account,
&voter2, &voter2,
&mngo_rate, &mngo_voting_mint,
5, 5,
) )
.await; .await;
@ -279,7 +279,7 @@ async fn test_deposit_no_locking() -> Result<(), TransportError> {
&registrar, &registrar,
&voter, &voter,
&voter_authority, &voter_authority,
&mngo_rate, &mngo_voting_mint,
0, 0,
LockupKind::None, LockupKind::None,
0, 0,

View File

@ -56,8 +56,8 @@ async fn test_reset_lockup() -> Result<(), TransportError> {
let registrar = addin let registrar = addin
.create_registrar(&realm, &realm_authority, payer) .create_registrar(&realm, &realm_authority, payer)
.await; .await;
let mngo_rate = addin let mngo_voting_mint = 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; .await;
let voter = addin let voter = addin
@ -70,7 +70,7 @@ async fn test_reset_lockup() -> Result<(), TransportError> {
&registrar, &registrar,
&voter, &voter,
&token_owner_record, &token_owner_record,
&mngo_rate, &mngo_voting_mint,
&voter_authority, &voter_authority,
reference_account, reference_account,
index, index,
@ -81,7 +81,7 @@ async fn test_reset_lockup() -> Result<(), TransportError> {
addin.deposit( addin.deposit(
&registrar, &registrar,
&voter, &voter,
&mngo_rate, &mngo_voting_mint,
&voter_authority, &voter_authority,
reference_account, reference_account,
index, index,
@ -108,7 +108,7 @@ async fn test_reset_lockup() -> Result<(), TransportError> {
&registrar, &registrar,
&voter, &voter,
&voter_authority, &voter_authority,
&mngo_rate, &mngo_voting_mint,
7, 7,
voter_stake_registry::state::LockupKind::Daily, voter_stake_registry::state::LockupKind::Daily,
3, 3,
@ -181,7 +181,7 @@ async fn test_reset_lockup() -> Result<(), TransportError> {
&registrar, &registrar,
&voter, &voter,
&voter_authority, &voter_authority,
&mngo_rate, &mngo_voting_mint,
5, 5,
voter_stake_registry::state::LockupKind::Cliff, voter_stake_registry::state::LockupKind::Cliff,
3, 3,