gmsol_decode/
gmsol.rs

1/// Implement [`Decode`](crate::Decode) for types defined in [`gmsol-programs`].
2#[cfg(feature = "gmsol-programs")]
3pub mod programs {
4    use crate::{impl_decode_for_cpi_event, impl_decode_for_zero_copy};
5    use crate::{untagged, value::UnknownOwnedData};
6    use gmsol_programs::gmsol_store::{
7        accounts::{
8            Deposit, GlvDeposit, GlvShift, GlvWithdrawal, Market, Order, Position, Shift, Store,
9            Withdrawal,
10        },
11        events::{
12            BorrowingFeesUpdated, DepositExecuted, DepositRemoved, GlvDepositRemoved, GlvPricing,
13            GlvWithdrawalRemoved, GtUpdated, MarketFeesUpdated, MarketStateUpdated, OrderRemoved,
14            PositionDecreased, PositionIncreased, ShiftRemoved, SwapExecuted, TradeEvent,
15            WithdrawalExecuted, WithdrawalRemoved,
16        },
17    };
18
19    impl_decode_for_zero_copy!(Store);
20    impl_decode_for_zero_copy!(Position);
21    impl_decode_for_zero_copy!(Market);
22    impl_decode_for_zero_copy!(Deposit);
23    impl_decode_for_zero_copy!(Withdrawal);
24    impl_decode_for_zero_copy!(Shift);
25    impl_decode_for_zero_copy!(Order);
26    impl_decode_for_zero_copy!(GlvDeposit);
27    impl_decode_for_zero_copy!(GlvWithdrawal);
28    impl_decode_for_zero_copy!(GlvShift);
29
30    impl_decode_for_cpi_event!(DepositRemoved);
31    impl_decode_for_cpi_event!(DepositExecuted);
32    impl_decode_for_cpi_event!(WithdrawalRemoved);
33    impl_decode_for_cpi_event!(WithdrawalExecuted);
34    impl_decode_for_cpi_event!(ShiftRemoved);
35    impl_decode_for_cpi_event!(GlvDepositRemoved);
36    impl_decode_for_cpi_event!(GlvWithdrawalRemoved);
37    impl_decode_for_cpi_event!(GlvPricing);
38    impl_decode_for_cpi_event!(PositionIncreased);
39    impl_decode_for_cpi_event!(PositionDecreased);
40    impl_decode_for_cpi_event!(OrderRemoved);
41    impl_decode_for_cpi_event!(TradeEvent);
42    impl_decode_for_cpi_event!(MarketFeesUpdated);
43    impl_decode_for_cpi_event!(BorrowingFeesUpdated);
44    impl_decode_for_cpi_event!(MarketStateUpdated);
45    impl_decode_for_cpi_event!(SwapExecuted);
46    impl_decode_for_cpi_event!(GtUpdated);
47
48    untagged!(
49        GMSOLAccountData,
50        [
51            Deposit,
52            Withdrawal,
53            Shift,
54            Order,
55            GlvDeposit,
56            GlvWithdrawal,
57            GlvShift,
58            Store,
59            Market,
60            Position,
61            UnknownOwnedData
62        ]
63    );
64
65    type Account = crate::value::Account<GMSOLAccountData>;
66
67    untagged!(
68        GMSOLCPIEvent,
69        [
70            DepositExecuted,
71            DepositRemoved,
72            WithdrawalExecuted,
73            WithdrawalRemoved,
74            ShiftRemoved,
75            GlvDepositRemoved,
76            GlvWithdrawalRemoved,
77            GlvPricing,
78            PositionIncreased,
79            PositionDecreased,
80            OrderRemoved,
81            TradeEvent,
82            MarketFeesUpdated,
83            BorrowingFeesUpdated,
84            MarketStateUpdated,
85            SwapExecuted,
86            GtUpdated,
87            UnknownOwnedData
88        ]
89    );
90
91    type CPIEvents = crate::value::AnchorCPIEvents<GMSOLCPIEvent>;
92
93    untagged!(GMSOLData, [Account, CPIEvents]);
94}
95
96/// Implement [`Decode`](crate::Decode) for types defined in [`gmsol_store`].
97#[cfg(feature = "gmsol")]
98pub mod store {
99    use crate::{impl_decode_for_cpi_event, impl_decode_for_zero_copy};
100    use crate::{untagged, value::UnknownOwnedData};
101
102    use gmsol_store::{
103        events::{
104            BorrowingFeesUpdated, DepositExecuted, DepositRemoved, GlvDepositRemoved, GlvPricing,
105            GlvWithdrawalRemoved, GtUpdated, MarketFeesUpdated, MarketStateUpdated, OrderRemoved,
106            PositionDecreased, PositionIncreased, ShiftRemoved, SwapExecuted, TradeEvent,
107            WithdrawalExecuted, WithdrawalRemoved,
108        },
109        states::{
110            Deposit, GlvDeposit, GlvShift, GlvWithdrawal, Market, Order, Position, Shift, Store,
111            Withdrawal,
112        },
113    };
114
115    impl_decode_for_zero_copy!(Store);
116    impl_decode_for_zero_copy!(Position);
117    impl_decode_for_zero_copy!(Market);
118    impl_decode_for_zero_copy!(Deposit);
119    impl_decode_for_zero_copy!(Withdrawal);
120    impl_decode_for_zero_copy!(Shift);
121    impl_decode_for_zero_copy!(Order);
122    impl_decode_for_zero_copy!(GlvDeposit);
123    impl_decode_for_zero_copy!(GlvWithdrawal);
124    impl_decode_for_zero_copy!(GlvShift);
125
126    impl_decode_for_cpi_event!(DepositRemoved);
127    impl_decode_for_cpi_event!(DepositExecuted);
128    impl_decode_for_cpi_event!(WithdrawalRemoved);
129    impl_decode_for_cpi_event!(WithdrawalExecuted);
130    impl_decode_for_cpi_event!(ShiftRemoved);
131    impl_decode_for_cpi_event!(GlvDepositRemoved);
132    impl_decode_for_cpi_event!(GlvWithdrawalRemoved);
133    impl_decode_for_cpi_event!(GlvPricing);
134    impl_decode_for_cpi_event!(PositionIncreased);
135    impl_decode_for_cpi_event!(PositionDecreased);
136    impl_decode_for_cpi_event!(OrderRemoved);
137    impl_decode_for_cpi_event!(TradeEvent);
138    impl_decode_for_cpi_event!(MarketFeesUpdated);
139    impl_decode_for_cpi_event!(BorrowingFeesUpdated);
140    impl_decode_for_cpi_event!(MarketStateUpdated);
141    impl_decode_for_cpi_event!(SwapExecuted);
142    impl_decode_for_cpi_event!(GtUpdated);
143
144    untagged!(
145        GMSOLAccountData,
146        [
147            Deposit,
148            Withdrawal,
149            Shift,
150            Order,
151            GlvDeposit,
152            GlvWithdrawal,
153            GlvShift,
154            Store,
155            Market,
156            Position,
157            UnknownOwnedData
158        ]
159    );
160
161    type Account = crate::value::Account<GMSOLAccountData>;
162
163    untagged!(
164        GMSOLCPIEvent,
165        [
166            DepositExecuted,
167            DepositRemoved,
168            WithdrawalExecuted,
169            WithdrawalRemoved,
170            ShiftRemoved,
171            GlvDepositRemoved,
172            GlvWithdrawalRemoved,
173            GlvPricing,
174            PositionIncreased,
175            PositionDecreased,
176            OrderRemoved,
177            TradeEvent,
178            MarketFeesUpdated,
179            BorrowingFeesUpdated,
180            MarketStateUpdated,
181            SwapExecuted,
182            GtUpdated,
183            UnknownOwnedData
184        ]
185    );
186
187    type CPIEvents = crate::value::AnchorCPIEvents<GMSOLCPIEvent>;
188
189    untagged!(GMSOLData, [Account, CPIEvents]);
190}