#![allow(
clippy::all,
clippy::pedantic,
clippy::nursery,
clippy::expect_used,
clippy::unwrap_used,
clippy::indexing_slicing,
clippy::allow_attributes,
clippy::allow_attributes_without_reason,
clippy::mem_forget,
unfulfilled_lint_expectations,
unexpected_cfgs,
unused_imports
)]
use crate::nexus::generated::events::ANCHOR_EVENT_CPI_DISCRIMINATOR;
use borsh::BorshDeserialize;
use borsh::BorshSerialize;
use solana_address::Address;
#[derive(BorshSerialize, BorshDeserialize, Clone, Debug, Eq, PartialEq)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
#[cfg_attr(feature = "serde", serde(rename_all = "camelCase"))]
pub struct StakeEvent {
#[cfg_attr(
feature = "serde",
serde(with = "serde_with::As::<serde_with::DisplayFromStr>")
)]
pub user: Address,
#[cfg_attr(
feature = "serde",
serde(with = "serde_with::As::<serde_with::DisplayFromStr>")
)]
pub staking_config: Address,
#[cfg_attr(
feature = "serde",
serde(with = "serde_with::As::<serde_with::DisplayFromStr>")
)]
pub amount: u64,
#[cfg_attr(
feature = "serde",
serde(with = "serde_with::As::<serde_with::DisplayFromStr>")
)]
pub total_staked: u64,
#[cfg_attr(
feature = "serde",
serde(with = "serde_with::As::<serde_with::DisplayFromStr>")
)]
pub timestamp: i64,
}
pub const STAKE_EVENT_DISCRIMINATOR: [u8; 8] =
[226, 134, 188, 173, 19, 33, 75, 175];
impl StakeEvent {
#[inline(always)]
pub fn matches(program_id: &solana_address::Address, data: &[u8]) -> bool {
program_id == &crate::nexus::generated::SEND_NEXUS_ID
&& data.get(..ANCHOR_EVENT_CPI_DISCRIMINATOR.len())
== Some(&ANCHOR_EVENT_CPI_DISCRIMINATOR[..])
&& data.get(8..16) == Some(&STAKE_EVENT_DISCRIMINATOR[..])
}
#[inline(always)]
pub fn try_parse(
program_id: &solana_address::Address,
data: &[u8],
) -> Option<Result<Self, std::io::Error>> {
if !Self::matches(program_id, data) {
return None;
}
let mut data = &data[16..];
Some(Self::deserialize(&mut data))
}
}