gmsol_store/events/
glv.rs

1use anchor_lang::prelude::*;
2use borsh::BorshSerialize;
3
4use gmsol_utils::InitSpace;
5
6use crate::states::common::action::ActionState;
7
8use super::Event;
9
10/// GLV Deposit removed event.
11#[event]
12#[cfg_attr(feature = "debug", derive(Debug))]
13#[derive(Clone, InitSpace)]
14pub struct GlvDepositRemoved {
15    /// Action id.
16    pub id: u64,
17    /// Timestamp.
18    pub ts: i64,
19    /// Slot.
20    pub slot: u64,
21    /// Store.
22    pub store: Pubkey,
23    /// GLV Deposit.
24    pub glv_deposit: Pubkey,
25    /// Market token.
26    pub market_token: Pubkey,
27    /// GLV token.
28    pub glv_token: Pubkey,
29    /// Owner.
30    pub owner: Pubkey,
31    /// Final state.
32    pub state: ActionState,
33    /// Reason.
34    #[max_len(32)]
35    pub reason: String,
36}
37
38impl GlvDepositRemoved {
39    pub(crate) fn new(
40        id: u64,
41        store: Pubkey,
42        glv_deposit: Pubkey,
43        market_token: Pubkey,
44        glv_token: Pubkey,
45        owner: Pubkey,
46        state: ActionState,
47        reason: impl ToString,
48    ) -> Result<Self> {
49        let clock = Clock::get()?;
50        Ok(Self {
51            id,
52            ts: clock.unix_timestamp,
53            slot: clock.slot,
54            store,
55            glv_deposit,
56            glv_token,
57            market_token,
58            owner,
59            state,
60            reason: reason.to_string(),
61        })
62    }
63}
64
65impl InitSpace for GlvDepositRemoved {
66    const INIT_SPACE: usize = <Self as Space>::INIT_SPACE;
67}
68
69impl Event for GlvDepositRemoved {}
70
71/// GLV Withdrawal removed event.
72#[event]
73#[cfg_attr(feature = "debug", derive(Debug))]
74#[derive(Clone, InitSpace)]
75pub struct GlvWithdrawalRemoved {
76    /// Action id.
77    pub id: u64,
78    /// Timestamp.
79    pub ts: i64,
80    /// Slot.
81    pub slot: u64,
82    /// Store.
83    pub store: Pubkey,
84    /// GLV Withdrawal
85    pub glv_withdrawal: Pubkey,
86    /// Market token.
87    pub market_token: Pubkey,
88    /// GLV token.
89    pub glv_token: Pubkey,
90    /// Owner.
91    pub owner: Pubkey,
92    /// Final state.
93    pub state: ActionState,
94    /// Reason.
95    #[max_len(32)]
96    pub reason: String,
97}
98
99impl GlvWithdrawalRemoved {
100    pub(crate) fn new(
101        id: u64,
102        store: Pubkey,
103        glv_withdrawal: Pubkey,
104        market_token: Pubkey,
105        glv_token: Pubkey,
106        owner: Pubkey,
107        state: ActionState,
108        reason: impl ToString,
109    ) -> Result<Self> {
110        let clock = Clock::get()?;
111        Ok(Self {
112            id,
113            ts: clock.unix_timestamp,
114            slot: clock.slot,
115            store,
116            glv_withdrawal,
117            glv_token,
118            market_token,
119            owner,
120            state,
121            reason: reason.to_string(),
122        })
123    }
124}
125
126impl InitSpace for GlvWithdrawalRemoved {
127    const INIT_SPACE: usize = <Self as Space>::INIT_SPACE;
128}
129
130impl Event for GlvWithdrawalRemoved {}
131
132/// GLV pricing event.
133#[event]
134#[cfg_attr(feature = "debug", derive(Debug))]
135#[derive(Clone, InitSpace)]
136pub struct GlvPricing {
137    /// GLV token.
138    pub glv_token: Pubkey,
139    /// Market token.
140    pub market_token: Pubkey,
141    /// The supply of the GLV tokens.
142    pub supply: u64,
143    /// Whether the `value` is maximized.
144    pub value_maximized: bool,
145    /// Total value of the GLV.
146    pub value: u128,
147    /// Input amount.
148    /// - For GLV deposit, this is the total amount of market tokens received.
149    /// - For GLV withdrawal, this is the amount of GLV tokens received.
150    pub input_amount: u64,
151    /// The value of the input amount.
152    pub input_value: u128,
153    /// Output amount.
154    /// - For GLV deposit, this will be the amount of GLV tokens to be minted.
155    /// - For GLV withdrawal, this will be the amount of market tokens to be burned.
156    pub output_amount: u64,
157    /// The type of GLV pricing.
158    pub kind: GlvPricingKind,
159}
160
161impl InitSpace for GlvPricing {
162    const INIT_SPACE: usize = <Self as Space>::INIT_SPACE;
163}
164
165impl Event for GlvPricing {}
166
167/// Pricing kind.
168#[cfg_attr(feature = "debug", derive(Debug))]
169#[derive(Clone, InitSpace, AnchorSerialize, AnchorDeserialize)]
170#[non_exhaustive]
171pub enum GlvPricingKind {
172    /// Deposit.
173    Deposit,
174    /// Withdrawal.
175    Withdrawal,
176}