gmsol_store/events/
deposit.rs1use 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#[event]
12#[cfg_attr(feature = "debug", derive(Debug))]
13pub struct DepositCreated {
14 pub ts: i64,
16 pub store: Pubkey,
18 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#[event]
34#[cfg_attr(feature = "debug", derive(Debug))]
35pub struct DepositExecuted {
36 pub rev: u64,
38 pub market_token: Pubkey,
40 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#[event]
66#[cfg_attr(feature = "debug", derive(Debug))]
67#[derive(Clone, InitSpace)]
68pub struct DepositRemoved {
69 pub id: u64,
71 pub ts: i64,
73 pub slot: u64,
75 pub store: Pubkey,
77 pub deposit: Pubkey,
79 pub market_token: Pubkey,
81 pub owner: Pubkey,
83 pub state: ActionState,
85 #[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 {}