Skip to main content

df_hyperliquid_core/deploy/
tokens.rs

1//! Spot deploys in progress: an account's unfinished token deployments and the token auction
2//! (`spotDeployState`), and the auction for a pair of existing tokens (`spotPairDeployAuctionStatus`).
3
4use crate::client::{ApiError, Transport, info, info_request, user_request};
5use crate::deploy::auction::GasAuction;
6use crate::utils::{Address, Dec};
7use serde::Deserialize;
8
9/// `{"type":"spotDeployState","user":..}`.
10#[must_use]
11pub fn spot_deploy_state_request(user: Address) -> String {
12    user_request("spotDeployState", user)
13}
14
15/// The account's unfinished spot token deployments and the current token auction.
16pub async fn spot_deploy_state(transport: &impl Transport, user: Address) -> Result<SpotDeployState, ApiError> {
17    info(transport, spot_deploy_state_request(user)).await
18}
19
20/// `{"type":"spotPairDeployAuctionStatus"}`.
21#[must_use]
22pub fn spot_pair_deploy_auction_request() -> String {
23    info_request("spotPairDeployAuctionStatus", &[])
24}
25
26/// The current round of the spot pair deploy auction.
27pub async fn spot_pair_deploy_auction(transport: &impl Transport) -> Result<GasAuction, ApiError> {
28    info(transport, spot_pair_deploy_auction_request()).await
29}
30
31/// What `spotDeployState` answers for one account.
32#[derive(Debug, Clone, PartialEq, Eq, Deserialize)]
33#[serde(rename_all = "camelCase")]
34#[non_exhaustive]
35pub struct SpotDeployState {
36    /// The account's deployments that have not finished, each until it does.
37    #[serde(default)]
38    pub states: Vec<DeployingToken>,
39    /// The auction a new token's first step pays.
40    pub gas_auction: GasAuction,
41}
42
43/// One token being deployed. Every field but the token and its spec is read as optional.
44///
45/// The balances are whole tokens as the venue renders them through a 64-bit float, so a large
46/// one is rounded: `184467440737.0955200195` for a total of `18446744073709551615` wei. Only
47/// [`total_genesis_balance_wei`](DeployingToken::total_genesis_balance_wei) is exact. Confirmed
48/// against testnet deploys in progress and the `userGenesis` actions behind them.
49#[derive(Debug, Clone, PartialEq, Eq, Deserialize)]
50#[serde(rename_all = "camelCase")]
51#[non_exhaustive]
52pub struct DeployingToken {
53    /// Its index, claimed by the first step.
54    pub token: u32,
55    /// The name, size decimals and wei decimals registered.
56    pub spec: TokenSpec,
57    /// The full name (`fullName`), when one was registered.
58    #[serde(default)]
59    pub full_name: Option<String>,
60    /// The deployer's share of trading fees (`deployerTradingFeeShare`), as a fraction.
61    #[serde(default)]
62    pub deployer_trading_fee_share: Option<Dec>,
63    /// The pairs registered for it so far, by pair index.
64    #[serde(default)]
65    pub spots: Vec<u32>,
66    /// Set by genesis, in whole tokens; `None` before.
67    #[serde(default)]
68    pub max_supply: Option<Dec>,
69    /// The supply kept for hyperliquidity at genesis (`hyperliquidityGenesisBalance`), in whole tokens.
70    #[serde(default)]
71    pub hyperliquidity_genesis_balance: Option<Dec>,
72    /// The total given out at genesis, in the token's wei (`totalGenesisBalanceWei`): exact.
73    #[serde(default)]
74    pub total_genesis_balance_wei: Option<Dec>,
75    /// What each address was given by the user genesis steps (`userGenesisBalances`), in whole
76    /// tokens. Emptied once genesis is done.
77    #[serde(default)]
78    pub user_genesis_balances: Vec<(Address, Dec)>,
79    /// What was shared among the holders of each existing token (`existingTokenGenesisBalances`), by
80    /// token index, in whole tokens.
81    #[serde(default)]
82    pub existing_token_genesis_balances: Vec<(u32, Dec)>,
83    /// Addresses blacklisted from holding the token (`blacklistUsers`).
84    #[serde(default)]
85    pub blacklist_users: Vec<Address>,
86}
87
88/// What the first step registered: fixed for good.
89#[derive(Debug, Clone, PartialEq, Eq, Deserialize)]
90#[serde(rename_all = "camelCase")]
91pub struct TokenSpec {
92    /// The token's name.
93    pub name: String,
94    /// Size decimals (`szDecimals`): how many decimal places a spot order size may have.
95    pub sz_decimals: u32,
96    /// Wei decimals (`weiDecimals`): how many decimal places a balance is kept to.
97    pub wei_decimals: u32,
98}
99
100#[cfg(test)]
101#[path = "tests/tokens.rs"]
102mod tests;