gmsol_store/events/
withdrawal.rs

1use anchor_lang::prelude::*;
2use borsh::BorshSerialize;
3
4use gmsol_model::action::withdraw::WithdrawReport;
5use gmsol_utils::InitSpace;
6
7use crate::states::common::action::ActionState;
8
9use super::Event;
10
11/// Withdrawal created event.
12#[event]
13#[cfg_attr(feature = "debug", derive(Debug))]
14pub struct WithdrawalCreated {
15    /// Event time.
16    pub ts: i64,
17    /// Store account.
18    pub store: Pubkey,
19    /// Withdrawal account.
20    pub withdrawal: Pubkey,
21}
22
23impl WithdrawalCreated {
24    pub(crate) fn new(store: Pubkey, withdrawal: Pubkey) -> Result<Self> {
25        Ok(Self {
26            ts: Clock::get()?.unix_timestamp,
27            store,
28            withdrawal,
29        })
30    }
31}
32
33/// Withdrawal executed Event.
34#[event]
35#[cfg_attr(feature = "debug", derive(Debug))]
36pub struct WithdrawalExecuted {
37    /// Revision.
38    pub rev: u64,
39    /// Market token.
40    pub market_token: Pubkey,
41    /// Report.
42    pub report: WithdrawReport<u128>,
43}
44
45impl gmsol_utils::InitSpace for WithdrawalExecuted {
46    const INIT_SPACE: usize = 8 + 32 + WithdrawReport::<u128>::INIT_SPACE;
47}
48
49impl Event for WithdrawalExecuted {}
50
51impl WithdrawalExecuted {
52    pub(crate) fn from_report(
53        rev: u64,
54        market_token: Pubkey,
55        report: WithdrawReport<u128>,
56    ) -> Self {
57        Self {
58            rev,
59            market_token,
60            report,
61        }
62    }
63}
64
65/// Withdrawal removed event.
66#[event]
67#[cfg_attr(feature = "debug", derive(Debug))]
68#[derive(Clone, InitSpace)]
69pub struct WithdrawalRemoved {
70    /// Action id.
71    pub id: u64,
72    /// Timestamp.
73    pub ts: i64,
74    /// Slot.
75    pub slot: u64,
76    /// Store.
77    pub store: Pubkey,
78    /// Withdrawal.
79    pub withdrawal: Pubkey,
80    /// Market token.
81    pub market_token: Pubkey,
82    /// Owner.
83    pub owner: Pubkey,
84    /// Final state.
85    pub state: ActionState,
86    /// Reason.
87    #[max_len(32)]
88    pub reason: String,
89}
90
91impl InitSpace for WithdrawalRemoved {
92    const INIT_SPACE: usize = <Self as Space>::INIT_SPACE;
93}
94
95impl Event for WithdrawalRemoved {}
96
97impl WithdrawalRemoved {
98    pub(crate) fn new(
99        id: u64,
100        store: Pubkey,
101        withdrawal: Pubkey,
102        market_token: Pubkey,
103        owner: Pubkey,
104        state: ActionState,
105        reason: impl ToString,
106    ) -> Result<Self> {
107        let clock = Clock::get()?;
108        Ok(Self {
109            id,
110            ts: clock.unix_timestamp,
111            slot: clock.slot,
112            store,
113            withdrawal,
114            market_token,
115            owner,
116            state,
117            reason: reason.to_string(),
118        })
119    }
120}