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")]
34pub struct SpotDeployState {
35    /// The account's deployments that have not finished, each until it does.
36    #[serde(default)]
37    pub states: Vec<DeployingToken>,
38    /// The auction a new token's first step pays.
39    pub gas_auction: GasAuction,
40}
41
42/// One token being deployed. Every field but the token and its spec is read as optional: none has been seen live.
43#[derive(Debug, Clone, PartialEq, Eq, Deserialize)]
44#[serde(rename_all = "camelCase")]
45pub struct DeployingToken {
46    /// Its index, claimed by the first step.
47    pub token: u32,
48    /// The name, size decimals and wei decimals registered.
49    pub spec: TokenSpec,
50    /// The full name (`fullName`), when one was registered.
51    #[serde(default)]
52    pub full_name: Option<String>,
53    /// The deployer's share of trading fees (`deployerTradingFeeShare`), as a fraction.
54    #[serde(default)]
55    pub deployer_trading_fee_share: Option<Dec>,
56    /// The pairs registered for it so far, by pair index.
57    #[serde(default)]
58    pub spots: Vec<u32>,
59    /// Set by genesis.
60    #[serde(default)]
61    pub max_supply: Option<Dec>,
62    /// The supply kept for hyperliquidity at genesis (`hyperliquidityGenesisBalance`).
63    #[serde(default)]
64    pub hyperliquidity_genesis_balance: Option<Dec>,
65    /// The total given out at genesis, in wei (`totalGenesisBalanceWei`).
66    #[serde(default)]
67    pub total_genesis_balance_wei: Option<Dec>,
68    /// What each address was given by the user genesis steps (`userGenesisBalances`).
69    #[serde(default)]
70    pub user_genesis_balances: Vec<(Address, Dec)>,
71    /// What was shared among the holders of each existing token (`existingTokenGenesisBalances`), by
72    /// token index.
73    #[serde(default)]
74    pub existing_token_genesis_balances: Vec<(u32, Dec)>,
75    /// Addresses blacklisted from holding the token (`blacklistUsers`).
76    #[serde(default)]
77    pub blacklist_users: Vec<Address>,
78}
79
80/// What the first step registered: fixed for good.
81#[derive(Debug, Clone, PartialEq, Eq, Deserialize)]
82#[serde(rename_all = "camelCase")]
83pub struct TokenSpec {
84    /// The token's name.
85    pub name: String,
86    /// Size decimals (`szDecimals`): how many decimal places a spot order size may have.
87    pub sz_decimals: u32,
88    /// Wei decimals (`weiDecimals`): how many decimal places a balance is kept to.
89    pub wei_decimals: u32,
90}
91
92#[cfg(test)]
93#[path = "tests/tokens.rs"]
94mod tests;