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