gmsol_store/events/
deposit.rs

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