Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions programs/drift/src/instructions/admin.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5023,6 +5023,11 @@ pub fn handle_update_mm_oracle_native(accounts: &[AccountInfo], data: &[u8]) ->
let perp_market_sequence_id = u64::from_le_bytes(perp_market[936..944].try_into().unwrap());
let incoming_sequence_id = u64::from_le_bytes(data[8..16].try_into().unwrap());

if &data[0..8] == &[0u8; 8] {
msg!("MM oracle price is zero, not updating");
return Err(ErrorCode::DefaultError.into());
}

if incoming_sequence_id > perp_market_sequence_id {
let clock_account = &accounts[2];
let clock_data = clock_account.data.borrow();
Expand Down
12 changes: 9 additions & 3 deletions programs/drift/src/instructions/pyth_lazer_oracle.rs
Original file line number Diff line number Diff line change
Expand Up @@ -88,22 +88,28 @@ pub fn handle_update_pyth_lazer_oracle<'c: 'info, 'info>(
}
}

let price = price.0.get();
if price == 0 {
msg!("Pyth lazer price is zero, not enough publishers");
return Err(ErrorCode::InvalidPythLazerMessage.into());
}

let exponent = exponent.ok_or(ErrorCode::InvalidPythLazerMessage)?;

// Default to 20bps of the price for conf if bid > ask or one-sided market
let mut conf: i64 = price.0.get().safe_div(500)?;
let mut conf: i64 = price.safe_div(500)?;
if let (Some(bid), Some(ask)) = (best_bid_price, best_ask_price) {
if bid.0.get() < ask.0.get() {
conf = ask.0.get() - bid.0.get();
}
}

pyth_lazer_oracle.price = price.0.get();
pyth_lazer_oracle.price = price;
pyth_lazer_oracle.posted_slot = Clock::get()?.slot;
pyth_lazer_oracle.publish_time = next_timestamp;
pyth_lazer_oracle.exponent = exponent.cast::<i32>()?;
pyth_lazer_oracle.conf = conf.cast::<u64>()?;
msg!("Price updated to {}", price.0.get());
msg!("Price updated to {}", price);

msg!(
"Posting new lazer update. current ts {} < next ts {}",
Expand Down
9 changes: 9 additions & 0 deletions tests/admin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -433,6 +433,15 @@ describe('admin', () => {
await driftClient.updateMmOracleNative(0, oraclePrice.addn(1), oracleTS);
assert(perpMarket.amm.mmOraclePrice.eq(oraclePrice));

// Errors if we try and update it with price of zero
try {
await driftClient.updateMmOracleNative(0, new BN(0), oracleTS);
assert.fail('Should have thrown');
} catch (e) {
console.log(e.message);
assert(e.message.includes('custom program error'));
}

// Doesnt update if we flip the admin switch
await driftClient.updateFeatureBitFlagsMMOracle(false);
try {
Expand Down
Loading