add fallback_oracle to PerpMarket
This commit is contained in:
parent
4c3814c466
commit
5a37232c2b
|
@ -17,4 +17,9 @@ pub struct PerpEditMarket<'info> {
|
|||
///
|
||||
/// CHECK: The oracle can be one of several different account types
|
||||
pub oracle: UncheckedAccount<'info>,
|
||||
|
||||
/// The fallback oracle account is optional and only used when set_fallback_oracle is true.
|
||||
///
|
||||
/// CHECK: The fallback oracle can be one of several different account types
|
||||
pub fallback_oracle: UncheckedAccount<'info>,
|
||||
}
|
||||
|
|
|
@ -58,6 +58,7 @@ pub fn perp_create_market(
|
|||
event_queue: ctx.accounts.event_queue.key(),
|
||||
oracle: ctx.accounts.oracle.key(),
|
||||
oracle_config: oracle_config.to_oracle_config(),
|
||||
fallback_oracle: Pubkey::default(),
|
||||
stable_price_model: StablePriceModel::default(),
|
||||
quote_lot_size,
|
||||
base_lot_size,
|
||||
|
@ -95,7 +96,7 @@ pub fn perp_create_market(
|
|||
fees_withdrawn: 0,
|
||||
platform_liquidation_fee: I80F48::from_num(platform_liquidation_fee),
|
||||
accrued_liquidation_fees: I80F48::ZERO,
|
||||
reserved: [0; 1848],
|
||||
reserved: [0; 1816],
|
||||
};
|
||||
|
||||
let oracle_ref = &AccountInfoRef::borrow(ctx.accounts.oracle.as_ref())?;
|
||||
|
|
|
@ -40,6 +40,7 @@ pub fn perp_edit_market(
|
|||
name_opt: Option<String>,
|
||||
force_close_opt: Option<bool>,
|
||||
platform_liquidation_fee_opt: Option<f32>,
|
||||
set_fallback_oracle: bool,
|
||||
) -> Result<()> {
|
||||
let group = ctx.accounts.group.load()?;
|
||||
|
||||
|
@ -63,6 +64,18 @@ pub fn perp_edit_market(
|
|||
perp_market.oracle = oracle;
|
||||
require_group_admin = true;
|
||||
}
|
||||
if set_fallback_oracle {
|
||||
msg!(
|
||||
"Fallback oracle old {:?}, new {:?}",
|
||||
perp_market.fallback_oracle,
|
||||
ctx.accounts.fallback_oracle.key()
|
||||
);
|
||||
check_is_valid_fallback_oracle(&AccountInfoRef::borrow(
|
||||
ctx.accounts.fallback_oracle.as_ref(),
|
||||
)?)?;
|
||||
perp_market.fallback_oracle = ctx.accounts.fallback_oracle.key();
|
||||
require_group_admin = true;
|
||||
}
|
||||
if reset_stable_price {
|
||||
msg!("Stable price reset");
|
||||
require_keys_eq!(perp_market.oracle, ctx.accounts.oracle.key());
|
||||
|
|
|
@ -946,6 +946,7 @@ pub mod mango_v4 {
|
|||
name_opt: Option<String>,
|
||||
force_close_opt: Option<bool>,
|
||||
platform_liquidation_fee_opt: Option<f32>,
|
||||
set_fallback_oracle: bool,
|
||||
) -> Result<()> {
|
||||
#[cfg(feature = "enable-gpl")]
|
||||
instructions::perp_edit_market(
|
||||
|
@ -981,6 +982,7 @@ pub mod mango_v4 {
|
|||
name_opt,
|
||||
force_close_opt,
|
||||
platform_liquidation_fee_opt,
|
||||
set_fallback_oracle
|
||||
)?;
|
||||
Ok(())
|
||||
}
|
||||
|
|
|
@ -198,8 +198,12 @@ pub struct PerpMarket {
|
|||
/// liquidation fees that happened. So never decreases (different to fees_accrued).
|
||||
pub accrued_liquidation_fees: I80F48,
|
||||
|
||||
/// Oracle that may be used if the main oracle is stale or not confident enough.
|
||||
/// If this is Pubkey::default(), no fallback is available.
|
||||
pub fallback_oracle: Pubkey,
|
||||
|
||||
#[derivative(Debug = "ignore")]
|
||||
pub reserved: [u8; 1848],
|
||||
pub reserved: [u8; 1816],
|
||||
}
|
||||
|
||||
const_assert_eq!(
|
||||
|
@ -237,7 +241,8 @@ const_assert_eq!(
|
|||
+ 3 * 16
|
||||
+ 8
|
||||
+ 2 * 16
|
||||
+ 1848
|
||||
+ 32
|
||||
+ 1816
|
||||
);
|
||||
const_assert_eq!(size_of::<PerpMarket>(), 2808);
|
||||
const_assert_eq!(size_of::<PerpMarket>() % 8, 0);
|
||||
|
@ -500,6 +505,7 @@ impl PerpMarket {
|
|||
max_staleness_slots: -1,
|
||||
reserved: [0; 72],
|
||||
},
|
||||
fallback_oracle: Pubkey::default(),
|
||||
stable_price_model: StablePriceModel::default(),
|
||||
quote_lot_size: 1,
|
||||
base_lot_size: 1,
|
||||
|
@ -537,7 +543,7 @@ impl PerpMarket {
|
|||
fees_withdrawn: 0,
|
||||
platform_liquidation_fee: I80F48::ZERO,
|
||||
accrued_liquidation_fees: I80F48::ZERO,
|
||||
reserved: [0; 1848],
|
||||
reserved: [0; 1816],
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue