forked from blockworks-foundation/voter-stake-registry
-
Notifications
You must be signed in to change notification settings - Fork 0
/
update_max_vote_weight.rs
28 lines (26 loc) · 1.24 KB
/
update_max_vote_weight.rs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
use crate::state::*;
use anchor_lang::prelude::*;
// Remaining accounts should all the token mints that have registered
// exchange rates.
#[derive(Accounts)]
pub struct UpdateMaxVoteWeight<'info> {
pub registrar: AccountLoader<'info, Registrar>,
// TODO: SPL governance has not yet implemented this.
/// CHECK: TODO. Will be implemented when max_vote_weight_record is rolled out.
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(ctx: Context<UpdateMaxVoteWeight>) -> Result<()> {
let registrar = &ctx.accounts.registrar.load()?;
let _max_vote_weight = registrar.max_vote_weight(ctx.remaining_accounts)?;
// 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(())
}