use anchor_lang::prelude::*;
use borsh::BorshSerialize;
use gmsol_model::action::withdraw::WithdrawReport;
use gmsol_utils::InitSpace;
use crate::states::common::action::ActionState;
use super::Event;
#[event]
#[cfg_attr(feature = "debug", derive(Debug))]
pub struct WithdrawalCreated {
pub ts: i64,
pub store: Pubkey,
pub withdrawal: Pubkey,
}
impl WithdrawalCreated {
pub(crate) fn new(store: Pubkey, withdrawal: Pubkey) -> Result<Self> {
Ok(Self {
ts: Clock::get()?.unix_timestamp,
store,
withdrawal,
})
}
}
#[event]
#[cfg_attr(feature = "debug", derive(Debug))]
pub struct WithdrawalExecuted {
pub rev: u64,
pub market_token: Pubkey,
pub report: WithdrawReport<u128>,
}
impl gmsol_utils::InitSpace for WithdrawalExecuted {
const INIT_SPACE: usize = 8 + 32 + WithdrawReport::<u128>::INIT_SPACE;
}
impl Event for WithdrawalExecuted {}
impl WithdrawalExecuted {
pub(crate) fn from_report(
rev: u64,
market_token: Pubkey,
report: WithdrawReport<u128>,
) -> Self {
Self {
rev,
market_token,
report,
}
}
}
#[event]
#[cfg_attr(feature = "debug", derive(Debug))]
#[derive(Clone, InitSpace)]
pub struct WithdrawalRemoved {
pub id: u64,
pub ts: i64,
pub slot: u64,
pub store: Pubkey,
pub withdrawal: Pubkey,
pub market_token: Pubkey,
pub owner: Pubkey,
pub state: ActionState,
#[max_len(32)]
pub reason: String,
}
impl InitSpace for WithdrawalRemoved {
const INIT_SPACE: usize = <Self as Space>::INIT_SPACE;
}
impl Event for WithdrawalRemoved {}
impl WithdrawalRemoved {
pub(crate) fn new(
id: u64,
store: Pubkey,
withdrawal: 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,
withdrawal,
market_token,
owner,
state,
reason: reason.to_string(),
})
}
}