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)]
46#[non_exhaustive]
47pub enum AqaRole {
48    /// `technical`: runs minting, redemption and cross-chain transfers.
49    Technical,
50    /// `treasury`: names the treasury address that shares the AQA rate with
51    /// the protocol.
52    Treasury,
53}
54
55impl AqaRole {
56    /// The name sent.
57    #[must_use]
58    pub const fn wire(self) -> &'static str {
59        match self {
60            AqaRole::Technical => "technical",
61            AqaRole::Treasury => "treasury",
62        }
63    }
64}
65
66/// `{"type":"authorizeAqav2Role","token","role"}`: sent from a deployer's
67/// staking account to take an AQAv2 role for `token` (0 for USDC).
68/// Activation then goes to a validator vote.
69#[derive(Debug, Clone, Copy, PartialEq, Eq)]
70pub struct AuthorizeAqav2Role {
71    /// The token the role is for, by spot token index; 0 for USDC.
72    pub token: u32,
73    /// The role taken.
74    pub role: AqaRole,
75}
76
77impl L1Action for AuthorizeAqav2Role {
78    fn action(&self) -> Map {
79        Map::new().put("type", "authorizeAqav2Role").put("token", self.token).put("role", self.role.wire())
80    }
81}
82
83#[cfg(test)]
84#[path = "tests/aligned.rs"]
85mod tests;