gmsol_store/events/
withdrawal.rs1use 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#[event]
13#[cfg_attr(feature = "debug", derive(Debug))]
14pub struct WithdrawalCreated {
15 pub ts: i64,
17 pub store: Pubkey,
19 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#[event]
35#[cfg_attr(feature = "debug", derive(Debug))]
36pub struct WithdrawalExecuted {
37 pub rev: u64,
39 pub market_token: Pubkey,
41 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#[event]
67#[cfg_attr(feature = "debug", derive(Debug))]
68#[derive(Clone, InitSpace)]
69pub struct WithdrawalRemoved {
70 pub id: u64,
72 pub ts: i64,
74 pub slot: u64,
76 pub store: Pubkey,
78 pub withdrawal: Pubkey,
80 pub market_token: Pubkey,
82 pub owner: Pubkey,
84 pub state: ActionState,
86 #[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}