Skip to main content

df_hyperliquid_core/deploy/perp/
sub.rs

1//! Sub-deployers: which `perpDeploy` variant another address may send for a dex ([`PerpKind`]), and
2//! one address let in to or shut out of it ([`SubDeployer`]).
3
4use crate::utils::Address;
5use crate::utils::sign::Map;
6
7/// A `perpDeploy` variant, by the key it travels under: what a
8/// sub-deployer grant names.
9#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
10pub enum PerpKind {
11    /// `registerAsset2`.
12    RegisterAsset2,
13    /// `registerAsset`.
14    RegisterAsset,
15    /// `setOracle`.
16    SetOracle,
17    /// `setFundingMultipliers`.
18    SetFundingMultipliers,
19    /// `setFundingInterestRates`.
20    SetFundingInterestRates,
21    /// `setFundingClamps`.
22    SetFundingClamps,
23    /// `haltTrading`.
24    HaltTrading,
25    /// `insertMarginTable`.
26    InsertMarginTable,
27    /// `setMarginTableIds`.
28    SetMarginTableIds,
29    /// `setFeeRecipient`.
30    SetFeeRecipient,
31    /// `setOpenInterestCaps`.
32    SetOpenInterestCaps,
33    /// `setSubDeployers`.
34    SetSubDeployers,
35    /// `setMarginModes`.
36    SetMarginModes,
37    /// `setDeployerFees`.
38    SetDeployerFees,
39    /// `setPerpAnnotation`.
40    SetPerpAnnotation,
41    /// `disableDex`.
42    DisableDex,
43}
44
45impl PerpKind {
46    /// Every variant, in the order the docs list them.
47    pub const ALL: [PerpKind; 16] = [
48        PerpKind::RegisterAsset2,
49        PerpKind::RegisterAsset,
50        PerpKind::SetOracle,
51        PerpKind::SetFundingMultipliers,
52        PerpKind::SetFundingInterestRates,
53        PerpKind::SetFundingClamps,
54        PerpKind::HaltTrading,
55        PerpKind::InsertMarginTable,
56        PerpKind::SetMarginTableIds,
57        PerpKind::SetFeeRecipient,
58        PerpKind::SetOpenInterestCaps,
59        PerpKind::SetSubDeployers,
60        PerpKind::SetMarginModes,
61        PerpKind::SetDeployerFees,
62        PerpKind::SetPerpAnnotation,
63        PerpKind::DisableDex,
64    ];
65
66    /// The key sent.
67    #[must_use]
68    pub const fn wire(self) -> &'static str {
69        match self {
70            PerpKind::RegisterAsset2 => "registerAsset2",
71            PerpKind::RegisterAsset => "registerAsset",
72            PerpKind::SetOracle => "setOracle",
73            PerpKind::SetFundingMultipliers => "setFundingMultipliers",
74            PerpKind::SetFundingInterestRates => "setFundingInterestRates",
75            PerpKind::SetFundingClamps => "setFundingClamps",
76            PerpKind::HaltTrading => "haltTrading",
77            PerpKind::InsertMarginTable => "insertMarginTable",
78            PerpKind::SetMarginTableIds => "setMarginTableIds",
79            PerpKind::SetFeeRecipient => "setFeeRecipient",
80            PerpKind::SetOpenInterestCaps => "setOpenInterestCaps",
81            PerpKind::SetSubDeployers => "setSubDeployers",
82            PerpKind::SetMarginModes => "setMarginModes",
83            PerpKind::SetDeployerFees => "setDeployerFees",
84            PerpKind::SetPerpAnnotation => "setPerpAnnotation",
85            PerpKind::DisableDex => "disableDex",
86        }
87    }
88}
89
90/// One address let in to (`allowed`), or shut out of, one variant on the
91/// dex.
92#[derive(Debug, Clone, Copy, PartialEq, Eq)]
93pub struct SubDeployer {
94    /// The `perpDeploy` variant granted or taken away.
95    pub variant: PerpKind,
96    /// The address the grant is for.
97    pub user: Address,
98    /// `true` lets the address send the variant, `false` stops it.
99    pub allowed: bool,
100}
101
102impl SubDeployer {
103    /// `{"variant","user","allowed"}`.
104    #[must_use]
105    pub fn wire(&self) -> Map {
106        Map::new().put("variant", self.variant.wire()).put("user", self.user.to_hex()).put("allowed", self.allowed)
107    }
108}