use solana_pubkey::Pubkey;
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
#[derive(Debug, Clone, borsh::BorshSerialize, borsh::BorshDeserialize, PartialEq)]
pub struct TradedEvent {
pub whirlpool: Pubkey,
pub a_to_b: bool,
pub pre_sqrt_price: u128,
pub post_sqrt_price: u128,
pub input_amount: u64,
pub output_amount: u64,
pub input_transfer_fee: u64,
pub output_transfer_fee: u64,
pub lp_fee: u64,
pub protocol_fee: u64,
}
impl TradedEvent {
pub fn decode(data: &[u8]) -> Option<Self> {
if data.len() < 8 {
return None;
}
let discriminator = &data[0..8];
if discriminator != [225, 202, 73, 175, 147, 43, 160, 150] {
return None;
}
let mut data_slice = data;
data_slice = &data_slice[8..];
borsh::BorshDeserialize::deserialize(&mut data_slice).ok()
}
}