add fallback oracles to bank and mintinfo
This commit is contained in:
parent
eceef44a96
commit
6288f2dd7d
|
@ -21,4 +21,9 @@ pub struct TokenEdit<'info> {
|
|||
///
|
||||
/// CHECK: The oracle can be one of several different account types
|
||||
pub oracle: UncheckedAccount<'info>,
|
||||
|
||||
/// The oracle account is optional and only used when reset_stable_price is set.
|
||||
///
|
||||
/// CHECK: The oracle can be one of several different account types
|
||||
pub fallback_oracle: UncheckedAccount<'info>,
|
||||
}
|
||||
|
|
|
@ -51,6 +51,9 @@ pub struct TokenRegister<'info> {
|
|||
/// CHECK: The oracle can be one of several different account types
|
||||
pub oracle: UncheckedAccount<'info>,
|
||||
|
||||
/// CHECK: The oracle can be one of several different account types
|
||||
pub fallback_oracle: UncheckedAccount<'info>,
|
||||
|
||||
#[account(mut)]
|
||||
pub payer: Signer<'info>,
|
||||
|
||||
|
|
|
@ -51,6 +51,9 @@ pub struct TokenRegisterTrustless<'info> {
|
|||
/// CHECK: The oracle can be one of several different account types
|
||||
pub oracle: UncheckedAccount<'info>,
|
||||
|
||||
/// CHECK: The oracle can be one of several different account types
|
||||
pub fallback_oracle: UncheckedAccount<'info>,
|
||||
|
||||
#[account(mut)]
|
||||
pub payer: Signer<'info>,
|
||||
|
||||
|
|
|
@ -8,7 +8,7 @@ use crate::error::MangoError;
|
|||
use crate::state::*;
|
||||
|
||||
use crate::accounts_ix::*;
|
||||
use crate::logs::{emit_stack, TokenMetaDataLog};
|
||||
use crate::logs::{emit_stack, TokenMetaDataLogV2};
|
||||
use crate::util::fill_from_str;
|
||||
|
||||
#[allow(unused_variables)]
|
||||
|
@ -49,6 +49,7 @@ pub fn token_edit(
|
|||
maint_weight_shift_asset_target_opt: Option<f32>,
|
||||
maint_weight_shift_liab_target_opt: Option<f32>,
|
||||
maint_weight_shift_abort: bool,
|
||||
fallback_oracle_opt: Option<Pubkey>,
|
||||
) -> Result<()> {
|
||||
let group = ctx.accounts.group.load()?;
|
||||
|
||||
|
@ -76,6 +77,16 @@ pub fn token_edit(
|
|||
mint_info.oracle = oracle;
|
||||
require_group_admin = true;
|
||||
}
|
||||
if let Some(fallback_oracle) = fallback_oracle_opt {
|
||||
msg!(
|
||||
"Fallback oracle old {:?}, new {:?}",
|
||||
bank.fallback_oracle,
|
||||
fallback_oracle
|
||||
);
|
||||
bank.fallback_oracle = fallback_oracle;
|
||||
mint_info.fallback_oracle = fallback_oracle;
|
||||
require_group_admin = true;
|
||||
}
|
||||
if reset_stable_price {
|
||||
msg!("Stable price reset");
|
||||
require_keys_eq!(bank.oracle, ctx.accounts.oracle.key());
|
||||
|
@ -456,12 +467,13 @@ pub fn token_edit(
|
|||
let bank = ctx.remaining_accounts.first().unwrap().load_mut::<Bank>()?;
|
||||
bank.verify()?;
|
||||
|
||||
emit_stack(TokenMetaDataLog {
|
||||
emit_stack!(TokenMetaDataLogV2 {
|
||||
mango_group: ctx.accounts.group.key(),
|
||||
mint: mint_info.mint.key(),
|
||||
token_index: bank.token_index,
|
||||
mint_decimals: bank.mint_decimals,
|
||||
oracle: mint_info.oracle.key(),
|
||||
fallback_oracle: ctx.accounts.fallback_oracle.key(),
|
||||
mint_info: ctx.accounts.mint_info.key(),
|
||||
});
|
||||
|
||||
|
|
|
@ -6,7 +6,7 @@ use crate::error::*;
|
|||
use crate::state::*;
|
||||
use crate::util::fill_from_str;
|
||||
|
||||
use crate::logs::{emit_stack, TokenMetaDataLog};
|
||||
use crate::logs::{emit_stack, TokenMetaDataLogV2};
|
||||
|
||||
pub const INDEX_START: I80F48 = I80F48::from_bits(1_000_000 * I80F48::ONE.to_bits());
|
||||
|
||||
|
@ -119,7 +119,8 @@ pub fn token_register(
|
|||
maint_weight_shift_duration_inv: I80F48::ZERO,
|
||||
maint_weight_shift_asset_target: I80F48::ZERO,
|
||||
maint_weight_shift_liab_target: I80F48::ZERO,
|
||||
reserved: [0; 2008],
|
||||
fallback_oracle: ctx.accounts.fallback_oracle.key(),
|
||||
reserved: [0; 1976],
|
||||
};
|
||||
|
||||
if let Ok(oracle_price) =
|
||||
|
@ -143,19 +144,21 @@ pub fn token_register(
|
|||
banks: Default::default(),
|
||||
vaults: Default::default(),
|
||||
oracle: ctx.accounts.oracle.key(),
|
||||
fallback_oracle: ctx.accounts.fallback_oracle.key(),
|
||||
registration_time: Clock::get()?.unix_timestamp.try_into().unwrap(),
|
||||
reserved: [0; 2560],
|
||||
reserved: [0; 2528],
|
||||
};
|
||||
|
||||
mint_info.banks[0] = ctx.accounts.bank.key();
|
||||
mint_info.vaults[0] = ctx.accounts.vault.key();
|
||||
|
||||
emit_stack(TokenMetaDataLog {
|
||||
emit_stack!(TokenMetaDataLogV2 {
|
||||
mango_group: ctx.accounts.group.key(),
|
||||
mint: ctx.accounts.mint.key(),
|
||||
token_index,
|
||||
mint_decimals: ctx.accounts.mint.decimals,
|
||||
oracle: ctx.accounts.oracle.key(),
|
||||
fallback_oracle: ctx.accounts.fallback_oracle.key(),
|
||||
mint_info: ctx.accounts.mint_info.key(),
|
||||
});
|
||||
|
||||
|
|
|
@ -7,7 +7,7 @@ use crate::instructions::INDEX_START;
|
|||
use crate::state::*;
|
||||
use crate::util::fill_from_str;
|
||||
|
||||
use crate::logs::{emit_stack, TokenMetaDataLog};
|
||||
use crate::logs::{emit_stack, TokenMetaDataLogV2};
|
||||
|
||||
use crate::accounts_ix::*;
|
||||
|
||||
|
@ -102,7 +102,8 @@ pub fn token_register_trustless(
|
|||
maint_weight_shift_duration_inv: I80F48::ZERO,
|
||||
maint_weight_shift_asset_target: I80F48::ZERO,
|
||||
maint_weight_shift_liab_target: I80F48::ZERO,
|
||||
reserved: [0; 2008],
|
||||
fallback_oracle: ctx.accounts.fallback_oracle.key(),
|
||||
reserved: [0; 1976],
|
||||
};
|
||||
|
||||
if let Ok(oracle_price) =
|
||||
|
@ -126,19 +127,21 @@ pub fn token_register_trustless(
|
|||
banks: Default::default(),
|
||||
vaults: Default::default(),
|
||||
oracle: ctx.accounts.oracle.key(),
|
||||
fallback_oracle: ctx.accounts.fallback_oracle.key(),
|
||||
registration_time: Clock::get()?.unix_timestamp.try_into().unwrap(),
|
||||
reserved: [0; 2560],
|
||||
reserved: [0; 2528],
|
||||
};
|
||||
|
||||
mint_info.banks[0] = ctx.accounts.bank.key();
|
||||
mint_info.vaults[0] = ctx.accounts.vault.key();
|
||||
|
||||
emit_stack(TokenMetaDataLog {
|
||||
emit_stack!(TokenMetaDataLogV2 {
|
||||
mango_group: ctx.accounts.group.key(),
|
||||
mint: ctx.accounts.mint.key(),
|
||||
token_index,
|
||||
mint_decimals: ctx.accounts.mint.decimals,
|
||||
oracle: ctx.accounts.oracle.key(),
|
||||
fallback_oracle: ctx.accounts.fallback_oracle.key(),
|
||||
mint_info: ctx.accounts.mint_info.key(),
|
||||
});
|
||||
|
||||
|
|
|
@ -234,6 +234,7 @@ pub mod mango_v4 {
|
|||
maint_weight_shift_asset_target_opt: Option<f32>,
|
||||
maint_weight_shift_liab_target_opt: Option<f32>,
|
||||
maint_weight_shift_abort: bool,
|
||||
fallback_oracle_opt: Option<Pubkey>,
|
||||
) -> Result<()> {
|
||||
#[cfg(feature = "enable-gpl")]
|
||||
instructions::token_edit(
|
||||
|
@ -272,6 +273,7 @@ pub mod mango_v4 {
|
|||
maint_weight_shift_asset_target_opt,
|
||||
maint_weight_shift_liab_target_opt,
|
||||
maint_weight_shift_abort,
|
||||
fallback_oracle_opt,
|
||||
)?;
|
||||
Ok(())
|
||||
}
|
||||
|
|
|
@ -450,6 +450,17 @@ pub struct TokenMetaDataLog {
|
|||
pub mint_info: Pubkey,
|
||||
}
|
||||
|
||||
#[event]
|
||||
pub struct TokenMetaDataLogV2 {
|
||||
pub mango_group: Pubkey,
|
||||
pub mint: Pubkey,
|
||||
pub token_index: u16,
|
||||
pub mint_decimals: u8,
|
||||
pub oracle: Pubkey,
|
||||
pub fallback_oracle: Pubkey,
|
||||
pub mint_info: Pubkey,
|
||||
}
|
||||
|
||||
#[event]
|
||||
pub struct PerpMarketMetaDataLog {
|
||||
pub mango_group: Pubkey,
|
||||
|
|
|
@ -167,8 +167,10 @@ pub struct Bank {
|
|||
pub maint_weight_shift_asset_target: I80F48,
|
||||
pub maint_weight_shift_liab_target: I80F48,
|
||||
|
||||
pub fallback_oracle: Pubkey,
|
||||
|
||||
#[derivative(Debug = "ignore")]
|
||||
pub reserved: [u8; 2008],
|
||||
pub reserved: [u8; 1976],
|
||||
}
|
||||
const_assert_eq!(
|
||||
size_of::<Bank>(),
|
||||
|
@ -292,7 +294,8 @@ impl Bank {
|
|||
maint_weight_shift_duration_inv: existing_bank.maint_weight_shift_duration_inv,
|
||||
maint_weight_shift_asset_target: existing_bank.maint_weight_shift_asset_target,
|
||||
maint_weight_shift_liab_target: existing_bank.maint_weight_shift_liab_target,
|
||||
reserved: [0; 2008],
|
||||
fallback_oracle: existing_bank.oracle, // bongo
|
||||
reserved: [0; 1976],
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -33,8 +33,10 @@ pub struct MintInfo {
|
|||
|
||||
pub registration_time: u64,
|
||||
|
||||
pub fallback_oracle: Pubkey,
|
||||
|
||||
#[derivative(Debug = "ignore")]
|
||||
pub reserved: [u8; 2560],
|
||||
pub reserved: [u8; 2528],
|
||||
}
|
||||
const_assert_eq!(
|
||||
size_of::<MintInfo>(),
|
||||
|
|
Loading…
Reference in New Issue