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.
43///
44/// The balances are whole tokens as the venue renders them through a 64-bit float, so a large
45/// one is rounded: `184467440737.0955200195` for a total of `18446744073709551615` wei. Only
46/// [`total_genesis_balance_wei`](DeployingToken::total_genesis_balance_wei) is exact. Confirmed
47/// against testnet deploys in progress and the `userGenesis` actions behind them.
48#[derive(Debug, Clone, PartialEq, Eq, Deserialize)]
49#[serde(rename_all = "camelCase")]
50pub struct DeployingToken {
51 /// Its index, claimed by the first step.
52 pub token: u32,
53 /// The name, size decimals and wei decimals registered.
54 pub spec: TokenSpec,
55 /// The full name (`fullName`), when one was registered.
56 #[serde(default)]
57 pub full_name: Option<String>,
58 /// The deployer's share of trading fees (`deployerTradingFeeShare`), as a fraction.
59 #[serde(default)]
60 pub deployer_trading_fee_share: Option<Dec>,
61 /// The pairs registered for it so far, by pair index.
62 #[serde(default)]
63 pub spots: Vec<u32>,
64 /// Set by genesis, in whole tokens; `None` before.
65 #[serde(default)]
66 pub max_supply: Option<Dec>,
67 /// The supply kept for hyperliquidity at genesis (`hyperliquidityGenesisBalance`), in whole tokens.
68 #[serde(default)]
69 pub hyperliquidity_genesis_balance: Option<Dec>,
70 /// The total given out at genesis, in the token's wei (`totalGenesisBalanceWei`): exact.
71 #[serde(default)]
72 pub total_genesis_balance_wei: Option<Dec>,
73 /// What each address was given by the user genesis steps (`userGenesisBalances`), in whole
74 /// tokens. Emptied once genesis is done.
75 #[serde(default)]
76 pub user_genesis_balances: Vec<(Address, Dec)>,
77 /// What was shared among the holders of each existing token (`existingTokenGenesisBalances`), by
78 /// token index, in whole tokens.
79 #[serde(default)]
80 pub existing_token_genesis_balances: Vec<(u32, Dec)>,
81 /// Addresses blacklisted from holding the token (`blacklistUsers`).
82 #[serde(default)]
83 pub blacklist_users: Vec<Address>,
84}
85
86/// What the first step registered: fixed for good.
87#[derive(Debug, Clone, PartialEq, Eq, Deserialize)]
88#[serde(rename_all = "camelCase")]
89pub struct TokenSpec {
90 /// The token's name.
91 pub name: String,
92 /// Size decimals (`szDecimals`): how many decimal places a spot order size may have.
93 pub sz_decimals: u32,
94 /// Wei decimals (`weiDecimals`): how many decimal places a balance is kept to.
95 pub wei_decimals: u32,
96}
97
98#[cfg(test)]
99#[path = "tests/tokens.rs"]
100mod tests;