Skip to main content

df_hyperliquid_core/deploy/
aligned.rs

1//! Aligned quote assets: a validator's vote on the risk-free rate (`validatorL1Stream`) and an
2//! AQAv2 deployer authorizing its role from its staking account (`authorizeAqav2Role`). Both are
3//! L1 actions.
4
5use crate::deploy::error::BadDeploy;
6use crate::utils::Dec;
7use crate::utils::sign::{L1Action, Map};
8
9/// `{"type":"validatorL1Stream","riskFreeRate"}`: a validator's vote on the
10/// risk-free rate for aligned quote assets, `0.04` for 4%. The rate used is
11/// the stake-weighted median of the votes.
12#[derive(Debug, Clone, Copy, PartialEq, Eq)]
13pub struct ValidatorL1Stream {
14    risk_free_rate: Dec,
15}
16
17impl ValidatorL1Stream {
18    /// Refuses a negative rate.
19    pub fn new(risk_free_rate: Dec) -> Result<Self, BadDeploy> {
20        if risk_free_rate.is_negative() {
21            return Err(BadDeploy::OutOfRange {
22                what: "a risk-free rate",
23                least: "0",
24                most: "any",
25                value: risk_free_rate.to_wire(),
26            });
27        }
28        Ok(ValidatorL1Stream { risk_free_rate })
29    }
30
31    /// The rate voted for, as a fraction.
32    #[must_use]
33    pub const fn risk_free_rate(self) -> Dec {
34        self.risk_free_rate
35    }
36}
37
38impl L1Action for ValidatorL1Stream {
39    fn action(&self) -> Map {
40        Map::new().put("type", "validatorL1Stream").put("riskFreeRate", self.risk_free_rate.to_wire())
41    }
42}
43
44/// The two AQAv2 deployer roles. Each stakes 500k HYPE.
45#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
46pub enum AqaRole {
47    /// `technical`: runs minting, redemption and cross-chain transfers.
48    Technical,
49    /// `treasury`: names the treasury address that shares the AQA rate with
50    /// the protocol.
51    Treasury,
52}
53
54impl AqaRole {
55    /// The name sent.
56    #[must_use]
57    pub const fn wire(self) -> &'static str {
58        match self {
59            AqaRole::Technical => "technical",
60            AqaRole::Treasury => "treasury",
61        }
62    }
63}
64
65/// `{"type":"authorizeAqav2Role","token","role"}`: sent from a deployer's
66/// staking account to take an AQAv2 role for `token` (0 for USDC).
67/// Activation then goes to a validator vote.
68#[derive(Debug, Clone, Copy, PartialEq, Eq)]
69pub struct AuthorizeAqav2Role {
70    /// The token the role is for, by spot token index; 0 for USDC.
71    pub token: u32,
72    /// The role taken.
73    pub role: AqaRole,
74}
75
76impl L1Action for AuthorizeAqav2Role {
77    fn action(&self) -> Map {
78        Map::new().put("type", "authorizeAqav2Role").put("token", self.token).put("role", self.role.wire())
79    }
80}
81
82#[cfg(test)]
83#[path = "tests/aligned.rs"]
84mod tests;