2021-12-02 07:28:12 -08:00
|
|
|
use crate::error::*;
|
2021-12-03 00:52:48 -08:00
|
|
|
use crate::state::*;
|
2021-12-02 07:28:12 -08:00
|
|
|
use anchor_lang::prelude::*;
|
|
|
|
|
|
|
|
// Remaining accounts should all the token mints that have registered
|
|
|
|
// exchange rates.
|
|
|
|
#[derive(Accounts)]
|
|
|
|
pub struct UpdateMaxVoteWeight<'info> {
|
2021-12-08 23:22:22 -08:00
|
|
|
pub registrar: AccountLoader<'info, Registrar>,
|
2021-12-02 07:28:12 -08:00
|
|
|
// TODO: SPL governance has not yet implemented this.
|
|
|
|
pub max_vote_weight_record: UncheckedAccount<'info>,
|
|
|
|
}
|
|
|
|
|
|
|
|
/// Calculates the max vote weight for the registry. This is a function
|
|
|
|
/// of the total supply of all exchange rate mints, converted into a
|
|
|
|
/// common currency with a common number of decimals.
|
|
|
|
///
|
|
|
|
/// Note that this method is only safe to use if the cumulative supply for
|
|
|
|
/// all tokens fits into a u64 *after* converting into common decimals, as
|
|
|
|
/// defined by the registrar's `rate_decimal` field.
|
|
|
|
pub fn update_max_vote_weight<'info>(ctx: Context<UpdateMaxVoteWeight>) -> Result<()> {
|
2021-12-08 23:22:22 -08:00
|
|
|
let registrar = &ctx.accounts.registrar.load()?;
|
2021-12-09 02:58:15 -08:00
|
|
|
let _max_vote_weight = registrar.max_vote_weight(ctx.remaining_accounts)?;
|
2021-12-02 07:28:12 -08:00
|
|
|
// TODO: SPL governance has not yet implemented this feature.
|
|
|
|
// When it has, probably need to write the result into an account,
|
|
|
|
// similar to VoterWeightRecord.
|
|
|
|
Ok(())
|
|
|
|
}
|