gmsol_store/events/
order.rs1use anchor_lang::prelude::*;
2use borsh::BorshSerialize;
3
4use gmsol_model::action::{
5 decrease_position::DecreasePositionReport, increase_position::IncreasePositionReport,
6};
7use gmsol_utils::InitSpace;
8
9use crate::states::{common::action::ActionState, order::OrderKind};
10
11use super::Event;
12
13#[event]
15#[cfg_attr(feature = "debug", derive(Debug))]
16pub struct OrderCreated {
17 pub ts: i64,
19 pub store: Pubkey,
21 pub order: Pubkey,
23 pub position: Option<Pubkey>,
25}
26
27impl OrderCreated {
28 pub(crate) fn new(store: Pubkey, order: Pubkey, position: Option<Pubkey>) -> Result<Self> {
29 Ok(Self {
30 ts: Clock::get()?.unix_timestamp,
31 store,
32 order,
33 position,
34 })
35 }
36}
37
38#[event]
40#[cfg_attr(feature = "debug", derive(Debug))]
41pub struct PositionIncreased {
42 pub rev: u64,
44 pub market_token: Pubkey,
46 pub report: IncreasePositionReport<u128, i128>,
48}
49
50impl gmsol_utils::InitSpace for PositionIncreased {
51 const INIT_SPACE: usize = 8 + 32 + IncreasePositionReport::<u128, i128>::INIT_SPACE;
52}
53
54impl Event for PositionIncreased {}
55
56impl PositionIncreased {
57 pub(crate) fn from_report(
58 rev: u64,
59 market_token: Pubkey,
60 report: IncreasePositionReport<u128, i128>,
61 ) -> Self {
62 Self {
63 rev,
64 market_token,
65 report,
66 }
67 }
68}
69
70#[event]
72#[cfg_attr(feature = "debug", derive(Debug))]
73pub struct PositionDecreased {
74 pub rev: u64,
76 pub market_token: Pubkey,
78 pub report: Box<DecreasePositionReport<u128, i128>>,
80}
81
82impl gmsol_utils::InitSpace for PositionDecreased {
83 const INIT_SPACE: usize = 8 + 32 + DecreasePositionReport::<u128, i128>::INIT_SPACE;
84}
85
86impl Event for PositionDecreased {}
87
88impl PositionDecreased {
89 pub(crate) fn from_report(
90 rev: u64,
91 market_token: Pubkey,
92 report: Box<DecreasePositionReport<u128, i128>>,
93 ) -> Self {
94 Self {
95 rev,
96 market_token,
97 report,
98 }
99 }
100}
101
102#[event]
104#[cfg_attr(feature = "debug", derive(Debug))]
105#[derive(Clone, InitSpace)]
106pub struct OrderRemoved {
107 pub id: u64,
109 pub ts: i64,
111 pub slot: u64,
113 pub store: Pubkey,
115 pub order: Pubkey,
117 pub kind: OrderKind,
119 pub market_token: Pubkey,
121 pub owner: Pubkey,
123 pub state: ActionState,
125 #[max_len(32)]
127 pub reason: String,
128}
129
130impl OrderRemoved {
131 pub(crate) fn new(
132 id: u64,
133 store: Pubkey,
134 order: Pubkey,
135 kind: OrderKind,
136 market_token: Pubkey,
137 owner: Pubkey,
138 state: ActionState,
139 reason: impl ToString,
140 ) -> Result<Self> {
141 let clock = Clock::get()?;
142 Ok(Self {
143 id,
144 ts: clock.unix_timestamp,
145 slot: clock.slot,
146 store,
147 kind,
148 order,
149 market_token,
150 owner,
151 state,
152 reason: reason.to_string(),
153 })
154 }
155}
156
157impl InitSpace for OrderRemoved {
158 const INIT_SPACE: usize = <Self as Space>::INIT_SPACE;
159}
160
161impl Event for OrderRemoved {}