use anchor_lang::prelude::*;
use borsh::BorshSerialize;
use gmsol_model::action::deposit::DepositReport;
use gmsol_utils::InitSpace;
use crate::states::common::action::ActionState;
use super::Event;
#[event]
#[cfg_attr(feature = "debug", derive(Debug))]
pub struct DepositCreated {
pub ts: i64,
pub store: Pubkey,
pub deposit: Pubkey,
}
impl DepositCreated {
pub(crate) fn new(store: Pubkey, deposit: Pubkey) -> Result<Self> {
Ok(Self {
ts: Clock::get()?.unix_timestamp,
store,
deposit,
})
}
}
#[event]
#[cfg_attr(feature = "debug", derive(Debug))]
pub struct DepositExecuted {
pub rev: u64,
pub market_token: Pubkey,
pub report: DepositReport<u128, i128>,
}
impl gmsol_utils::InitSpace for DepositExecuted {
const INIT_SPACE: usize = 8 + 32 + DepositReport::<u128, i128>::INIT_SPACE;
}
impl Event for DepositExecuted {}
impl DepositExecuted {
pub(crate) fn from_report(
rev: u64,
market_token: Pubkey,
report: DepositReport<u128, i128>,
) -> Self {
Self {
rev,
market_token,
report,
}
}
}
#[event]
#[cfg_attr(feature = "debug", derive(Debug))]
#[derive(Clone, InitSpace)]
pub struct DepositRemoved {
pub id: u64,
pub ts: i64,
pub slot: u64,
pub store: Pubkey,
pub deposit: Pubkey,
pub market_token: Pubkey,
pub owner: Pubkey,
pub state: ActionState,
#[max_len(32)]
pub reason: String,
}
impl DepositRemoved {
pub(crate) fn new(
id: u64,
store: Pubkey,
deposit: Pubkey,
market_token: Pubkey,
owner: Pubkey,
state: ActionState,
reason: impl ToString,
) -> Result<Self> {
let clock = Clock::get()?;
Ok(Self {
id,
ts: clock.unix_timestamp,
slot: clock.slot,
store,
deposit,
market_token,
owner,
state,
reason: reason.to_string(),
})
}
}
impl InitSpace for DepositRemoved {
const INIT_SPACE: usize = <Self as Space>::INIT_SPACE;
}
impl Event for DepositRemoved {}