diff --git a/client/src/chain_data_fetcher.rs b/client/src/chain_data_fetcher.rs index 8d46b0c5b..68ccec7ec 100644 --- a/client/src/chain_data_fetcher.rs +++ b/client/src/chain_data_fetcher.rs @@ -2,8 +2,10 @@ use std::sync::{Arc, RwLock}; use crate::chain_data::*; +use anchor_lang::Discriminator; + use mango_v4::accounts_zerocopy::LoadZeroCopy; -use mango_v4::state::MangoAccountValue; +use mango_v4::state::{MangoAccount, MangoAccountValue}; use anyhow::Context; @@ -31,7 +33,14 @@ impl AccountFetcher { pub fn fetch_mango_account(&self, address: &Pubkey) -> anyhow::Result { let acc = self.fetch_raw(address)?; - Ok(MangoAccountValue::from_bytes(acc.data()) + + let data = acc.data(); + let disc_bytes = &data[0..8]; + if disc_bytes != &MangoAccount::discriminator() { + anyhow::bail!("not a mango account at {}", address); + } + + Ok(MangoAccountValue::from_bytes(&data[8..]) .with_context(|| format!("loading mango account {}", address))?) } diff --git a/liquidator/src/util.rs b/liquidator/src/util.rs index 84f64bffa..95b87abc5 100644 --- a/liquidator/src/util.rs +++ b/liquidator/src/util.rs @@ -21,11 +21,14 @@ pub fn is_mango_account<'a>( return None; } - let mango_account = MangoAccountRefWithHeader::from_bytes(&data[8..]).expect("always ok"); - if mango_account.fixed.group != *group_id { - return None; + if let Ok(mango_account) = MangoAccountRefWithHeader::from_bytes(&data[8..]) { + if mango_account.fixed.group != *group_id { + return None; + } + Some(mango_account) + } else { + None } - Some(mango_account) } pub fn is_mango_bank<'a>(