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 #[non_exhaustive]
19 enum KeeperAction<Address> {
20 // =========================================================================
21 // Pricing Admin Operations (0-9)
22 // =========================================================================
23 /// Update oracle prices (PricingAdmin).
24 UpdateOraclePrices {
25 prices: Vec<OraclePriceUpdateArgs>,
26 publish_timestamp: UnixTimestampMicros,
27 } = 0,
28
29 /// Update mark prices (PricingAdmin).
30 UpdateMarkPrices {
31 prices: Vec<MarkPriceUpdateArgs>,
32 publish_timestamp: UnixTimestampMicros,
33 } = 1,
34
35 /// Update premium indexes for markets (PricingAdmin).
36 UpdatePremiumIndexes { market_ids: Vec<MarketId> } = 2,
37
38 /// Update oracle prices using signed Pyth payloads (PricingAdmin).
39 UpdateOraclePricesWithPythProofs {
40 prices: Vec<OraclePriceUpdateWithPythProofArgs>,
41 publish_timestamp: UnixTimestampMicros,
42 } = 3,
43 // Reserved: 4-9
44
45 // =========================================================================
46 // Funding Admin Operations (10-19)
47 // =========================================================================
48 /// Update funding rates for markets (FundingAdmin).
49 UpdateFunding { market_ids: Vec<MarketId> } = 10,
50 // Reserved: 11-19
51
52 // =========================================================================
53 // Credits Admin Operations (20-29)
54 // =========================================================================
55 /// Add trading credits to a user (CreditsAdmin).
56 AddTradingCredits {
57 user_address: Address,
58 amount: PositiveDecimal,
59 } = 20,
60
61 /// Remove trading credits from a user (CreditsAdmin).
62 RemoveTradingCredits {
63 user_address: Address,
64 amount: PositiveDecimal,
65 } = 21,
66 // Reserved: 22-29
67
68 // =========================================================================
69 // FeeTier Admin Operations (30-39)
70 // =========================================================================
71 /// Update user's fee tier (FeeTierAdmin).
72 UpdateUserFeeTier { address: Address, fee_tier: FeeTier } = 30,
73
74 /// Update a given user's fee discount (in bps) (FeeTierAdmin).
75 UpdateUserFeeDiscountBps {
76 address: Address,
77 fee_discount_bps: u16,
78 } = 31,
79 // Reserved: 32-39
80
81 // =========================================================================
82 // Referrals Admin Operations (40-49)
83 // =========================================================================
84 /// Set a user's cumulative referral rewards to an absolute amount (ReferralsAdmin).
85 SetCumulativeReferralRewards {
86 address: Address,
87 asset_id: AssetId,
88 amount: PositiveDecimal,
89 } = 40,
90 // Reserved: 41-49
91 }
92}
93impl<Address> KeeperAction<Address> {
94 /// Returns the specific admin type required for this keeper operation.
95 #[must_use]
96 pub fn required_admin_type(&self) -> AdminType {
97 match self {
98 Self::UpdateOraclePrices { .. }
99 | Self::UpdateMarkPrices { .. }
100 | Self::UpdatePremiumIndexes { .. }
101 | Self::UpdateOraclePricesWithPythProofs { .. } => AdminType::Pricing,
102 Self::UpdateFunding { .. } => AdminType::Funding,
103 Self::AddTradingCredits { .. } | Self::RemoveTradingCredits { .. } => {
104 AdminType::Credits
105 }
106 Self::UpdateUserFeeTier { .. } | Self::UpdateUserFeeDiscountBps { .. } => {
107 AdminType::FeeTier
108 }
109 Self::SetCumulativeReferralRewards { .. } => AdminType::Referrals,
110 }
111 }
112}