bullet_exchange_interface/message/keeper/mod.rs
1//! Keeper operations.
2
3use crate::decimals::PositiveDecimal;
4use crate::define_enum;
5use crate::time::UnixTimestampMicros;
6use crate::types::{AdminType, AssetId, FeeTier, MarketId};
7
8mod args;
9pub use args::*;
10
11define_enum! {
12 /// Keeper operations requiring specific admin privileges.
13 ///
14 /// These operations are typically called by automated keepers/bots
15 /// and require specific admin types (Pricing, Funding, Credits,
16 /// FeeTier, Referrals). However, one can also update all admin
17 /// addresses with it.
18 enum KeeperAction<Address> {
19 // =========================================================================
20 // Pricing Admin Operations (0-9)
21 // =========================================================================
22 /// Update oracle prices (PricingAdmin).
23 UpdateOraclePrices {
24 prices: Vec<OraclePriceUpdateArgs>,
25 publish_timestamp: UnixTimestampMicros,
26 } = 0,
27
28 /// Update mark prices (PricingAdmin).
29 UpdateMarkPrices {
30 prices: Vec<MarkPriceUpdateArgs>,
31 publish_timestamp: UnixTimestampMicros,
32 } = 1,
33
34 /// Update premium indexes for markets (PricingAdmin).
35 UpdatePremiumIndexes { market_ids: Vec<MarketId> } = 2,
36 // Reserved: 3-9
37
38 // =========================================================================
39 // Funding Admin Operations (10-19)
40 // =========================================================================
41 /// Update funding rates for markets (FundingAdmin).
42 UpdateFunding { market_ids: Vec<MarketId> } = 10,
43 // Reserved: 11-19
44
45 // =========================================================================
46 // Credits Admin Operations (20-29)
47 // =========================================================================
48 /// Add trading credits to a user (CreditsAdmin).
49 AddTradingCredits {
50 user_address: Address,
51 amount: PositiveDecimal,
52 } = 20,
53
54 /// Remove trading credits from a user (CreditsAdmin).
55 RemoveTradingCredits {
56 user_address: Address,
57 amount: PositiveDecimal,
58 } = 21,
59 // Reserved: 22-29
60
61 // =========================================================================
62 // FeeTier Admin Operations (30-39)
63 // =========================================================================
64 /// Update user's fee tier (FeeTierAdmin).
65 UpdateUserFeeTier { address: Address, fee_tier: FeeTier } = 30,
66
67 /// Update a given user's fee discount (in bps) (FeeTierAdmin).
68 UpdateUserFeeDiscountBps {
69 address: Address,
70 fee_discount_bps: u16,
71 } = 31,
72 // Reserved: 32-39
73
74 // =========================================================================
75 // Referrals Admin Operations (40-49)
76 // =========================================================================
77 /// Set a user's cumulative referral rewards to an absolute amount (ReferralsAdmin).
78 SetCumulativeReferralRewards {
79 address: Address,
80 asset_id: AssetId,
81 amount: PositiveDecimal,
82 } = 40,
83 // Reserved: 41-49
84 }
85}
86impl<Address> KeeperAction<Address> {
87 /// Returns the specific admin type required for this keeper operation.
88 #[must_use]
89 pub fn required_admin_type(&self) -> AdminType {
90 match self {
91 Self::UpdateOraclePrices { .. }
92 | Self::UpdateMarkPrices { .. }
93 | Self::UpdatePremiumIndexes { .. } => AdminType::Pricing,
94 Self::UpdateFunding { .. } => AdminType::Funding,
95 Self::AddTradingCredits { .. } | Self::RemoveTradingCredits { .. } => {
96 AdminType::Credits
97 }
98 Self::UpdateUserFeeTier { .. } | Self::UpdateUserFeeDiscountBps { .. } => {
99 AdminType::FeeTier
100 }
101 Self::SetCumulativeReferralRewards { .. } => AdminType::Referrals,
102 }
103 }
104}