bullet_exchange_interface/message/user/mod.rs
1//! User operations.
2
3use crate::decimals::PositiveDecimal;
4use crate::define_enum;
5use crate::string::CustomString;
6use crate::time::UnixTimestampMicros;
7use crate::types::{
8 AssetId, MarketId, OrderIdKind, SpotCollateralTransferDirection, TradingMode, TriggerOrderId,
9 TwapId,
10};
11mod args;
12pub use args::*;
13
14define_enum! {
15 /// User operations requiring account ownership or delegation.
16 ///
17 /// These operations are authorized via `context.sender()` with optional delegate resolution.
18 /// Operations include account management, trading, vault deposits, and user-initiated liquidations.
19 #[non_exhaustive]
20 enum UserAction<Address> {
21 // =========================================================================
22 // Account Operations (0-19)
23 // =========================================================================
24 /// Deposit assets to perp margin account.
25 Deposit {
26 asset_id: AssetId,
27 amount: PositiveDecimal,
28 } = 0,
29
30 /// Withdraw assets from perp margin account.
31 Withdraw {
32 asset_id: AssetId,
33 amount: PositiveDecimal,
34 } = 1,
35
36 /// Deposit assets to spot collateral.
37 DepositSpotCollateral {
38 asset_id: AssetId,
39 amount: PositiveDecimal,
40 } = 2,
41
42 /// Withdraw assets from spot collateral.
43 WithdrawSpotCollateral {
44 asset_id: AssetId,
45 amount: PositiveDecimal,
46 } = 3,
47
48 /// Transfer assets between perp margin and spot collateral.
49 TransferSpotCollateral {
50 asset_id: AssetId,
51 amount: PositiveDecimal,
52 direction: SpotCollateralTransferDirection,
53 sub_account_index: Option<u8>,
54 } = 4,
55
56 /// Borrow assets from spot pool.
57 BorrowSpot {
58 asset_id: AssetId,
59 amount: PositiveDecimal,
60 sub_account_index: Option<u8>,
61 } = 5,
62
63 /// Create a new sub-account.
64 CreateSubAccount { index: u8 } = 6,
65
66 /// Transfer assets between main account and sub-account.
67 TransferToSubAccount {
68 asset_id: AssetId,
69 amount: PositiveDecimal,
70 sub_account_index: u8,
71 to_sub_account: bool,
72 } = 7,
73
74 /// Delegate trading permissions to another address.
75 DelegateUser { delegate: Address, name: CustomString } = 8,
76
77 /// Revoke delegation from an address.
78 RevokeDelegation { delegate: Address } = 9,
79
80 /// Update maximum leverage for a market.
81 UpdateMaxLeverage {
82 market_id: MarketId,
83 max_leverage: u16,
84 sub_account_index: Option<u8>,
85 } = 10,
86
87 /// Claim your own referral rewards.
88 ClaimReferralRewards { asset_id: AssetId } = 11,
89
90 /// Deposit USDC into an isolated market / isolated margin position.
91 DepositIso {
92 market_id: MarketId,
93 amount: PositiveDecimal,
94 } = 12,
95
96 /// Withdraw USDC from an isolated market / isolated margin position.
97 WithdrawIso {
98 market_id: MarketId,
99 amount: PositiveDecimal,
100 } = 13,
101
102 /// Set the trading mode of a perp ledger to cross or iso.
103 SetPerpLedgerTradingMode {
104 market_id: MarketId,
105 trading_mode: TradingMode,
106 sub_account_index: Option<u8>,
107 } = 14,
108
109 /// Delegate trading permissions to another address allowing for sub accounts to be delegated.
110 DelegateUserV1 {
111 delegate: Address,
112 name: CustomString,
113 sub_account_index: Option<u8>,
114 } = 15,
115
116 /// Revoke delegation from an address allowing for sub accounts to revoke delegation.
117 RevokeDelegationV1 {
118 delegate: Address,
119 sub_account_index: Option<u8>,
120 } = 16,
121
122 /// Delegate trading permissions with optional expiry and flags
123 DelegateUserV2 {
124 delegate: Address,
125 name: CustomString,
126 sub_account_index: Option<u8>,
127 expires_at: Option<UnixTimestampMicros>,
128 flags: u32,
129 } = 17,
130
131 // Reserved: 18-19
132
133 // =========================================================================
134 // Order Operations (20-39)
135 // =========================================================================
136 /// Place new orders on a market.
137 PlaceOrders {
138 market_id: MarketId,
139 orders: Vec<NewOrderArgs>,
140 replace: bool,
141 sub_account_index: Option<u8>,
142 } = 20,
143
144 /// Amend existing orders (cancel + place).
145 AmendOrders {
146 market_id: MarketId,
147 orders: Vec<AmendOrderArgs>,
148 sub_account_index: Option<u8>,
149 } = 21,
150
151 /// Cancel specific orders.
152 CancelOrders {
153 market_id: MarketId,
154 orders: Vec<CancelOrderArgs>,
155 sub_account_index: Option<u8>,
156 } = 22,
157
158 /// Cancel all orders on a market.
159 CancelMarketOrders {
160 market_id: MarketId,
161 sub_account_index: Option<u8>,
162 } = 23,
163
164 /// Create trigger orders for spot markets.
165 CreateTriggerOrders {
166 market_id: MarketId,
167 trigger_orders: Vec<NewTriggerOrderArgs>,
168 sub_account_index: Option<u8>,
169 } = 24,
170
171 /// Create take-profit/stop-loss for a perp position.
172 CreatePositionTpsl {
173 market_id: MarketId,
174 tpsl_pair: TpslPair,
175 size: Option<PositiveDecimal>,
176 sub_account_index: Option<u8>,
177 } = 25,
178
179 /// Cancel trigger orders.
180 CancelTriggerOrders {
181 market_id: MarketId,
182 trigger_order_ids: Vec<TriggerOrderId>,
183 sub_account_index: Option<u8>,
184 } = 26,
185
186 /// Create TWAP orders
187 CreateTwapOrder {
188 market_id: MarketId,
189 twap_order_args: NewTwapOrderArgs,
190 sub_account_index: Option<u8>,
191 } = 27,
192
193 /// Cancel a TWAP order
194 CancelTwapOrder {
195 market_id: MarketId,
196 twap_id: TwapId,
197 sub_account_index: Option<u8>,
198 } = 28,
199
200 /// Cancel all orders for perp or spot
201 CancelAllOrders { sub_account_index: Option<u8> } = 29,
202
203 /// Place (expiring) orders after canceling a list of orders.
204 CancelAndPlaceOrders {
205 market_id: MarketId,
206 cancels: Vec<OrderIdKind>,
207 places: Vec<NewOrderArgs>,
208 expiry_timestamp: Option<UnixTimestampMicros>,
209 sub_account_index: Option<u8>,
210 } = 30,
211
212 // Reserved: 31-39
213
214
215 // =========================================================================
216 // Pool Operations (40-49)
217 // =========================================================================
218 /// Deposit USDC to the PnL pool.
219 DepositToPnlPool { usdc_amount: PositiveDecimal } = 40,
220
221 /// Settle user's PnL from the pool.
222 SettleFromPnlPool { sub_account_index: Option<u8> } = 41,
223
224 /// Deposit to the insurance fund.
225 DepositToInsuranceFund { usdc_amount: PositiveDecimal } = 42,
226
227 /// Deposit to protocol treasury.
228 DepositToTreasury {
229 asset_id: AssetId,
230 amount: PositiveDecimal,
231 } = 43,
232
233 /// Claim accumulated borrow/lend protocol fees.
234 ClaimBorrowLendFees {} = 44,
235
236 /// Deposit to the iso insurance fund.
237 DepositToIsoInsuranceFund { market_id: MarketId, amount: PositiveDecimal } = 45,
238 // Reserved: 46-49
239
240 // =========================================================================
241 // Vault User Operations (50-59)
242 // =========================================================================
243 /// Create a new vault (caller becomes the vault leader).
244 CreateVault { args: CreateVaultArgs<Address> } = 50,
245
246 /// Deposit assets to a vault.
247 DepositToVault {
248 vault_address: Address,
249 asset_id: AssetId,
250 amount: PositiveDecimal,
251 } = 51,
252
253 /// Queue a withdrawal from a vault.
254 QueueWithdrawal {
255 vault_address: Address,
256 shares: PositiveDecimal,
257 } = 52,
258
259 /// Cancel a queued withdrawal.
260 CancelQueuedWithdrawal { vault_address: Address } = 53,
261
262 /// Force withdraw from a vault (bypasses queue).
263 ForceWithdrawVault {
264 vault_address: Address,
265 shares: PositiveDecimal,
266 } = 54,
267
268 // Reserved: 55-59
269
270 // =========================================================================
271 // User-Initiated Liquidation Operations (60-69)
272 // =========================================================================
273 /// Backstop liquidation for perp positions (user provides capital).
274 BackstopLiquidatePerpPositions {
275 address: Address,
276 positions: Option<Vec<BackstopLiquidatePerpPositionArgs>>,
277 sub_account_index: Option<u8>,
278 } = 60,
279
280 /// Liquidate borrow/lend liability (user provides capital).
281 LiquidateBorrowLendLiability {
282 liquidatee_address: Address,
283 liability_asset_id: AssetId,
284 collateral_asset_id: AssetId,
285 liability_amount: PositiveDecimal,
286 sub_account_index: Option<u8>,
287 } = 61,
288
289 BackstopLiquidateIsoPerpPosition {
290 address: Address,
291 position: BackstopLiquidatePerpPositionArgs,
292 sub_account_index: Option<u8>,
293 } = 62,
294 // Reserved: 63-255
295 }
296}