Skip to main content

df_hyperliquid_core/deploy/spot/
evm.rs

1//! `finalizeEvmContract`: the second half of linking a spot token to a HyperEVM ERC-20, sent by
2//! the contract's deployer or the finalizer its storage names.
3
4use crate::utils::sign::{L1Action, Map, Value};
5
6/// How the sender of [`FinalizeEvmContract`] shows it deployed the
7/// contract.
8#[derive(Debug, Clone, Copy, PartialEq, Eq)]
9pub enum EvmFinalizer {
10    /// `{"create":{"nonce"}}`: the contract was deployed from an account,
11    /// which sends this with the EVM nonce it deployed at.
12    Create {
13        /// The EVM nonce the deploying account used.
14        nonce: u64,
15    },
16    /// `"firstStorageSlot"`: the contract's first storage slot holds the
17    /// sender's address.
18    FirstStorageSlot,
19    /// `"customStorageSlot"`: the slot at `keccak256("HyperCore deployer")`
20    /// holds the sender's address.
21    CustomStorageSlot,
22}
23
24impl EvmFinalizer {
25    /// The `input` as sent.
26    #[must_use]
27    pub fn wire(self) -> Value {
28        match self {
29            EvmFinalizer::Create { nonce } => Map::new().put("create", Map::new().put("nonce", nonce)).into(),
30            EvmFinalizer::FirstStorageSlot => "firstStorageSlot".into(),
31            EvmFinalizer::CustomStorageSlot => "customStorageSlot".into(),
32        }
33    }
34}
35
36/// `{"type":"finalizeEvmContract","token","input"}`: completes the link a
37/// [`RequestEvmContract`](crate::deploy::spot::SpotDeploy::RequestEvmContract)
38/// asked for. Not nested in `spotDeploy`. Linking cannot be undone.
39#[derive(Debug, Clone, Copy, PartialEq, Eq)]
40pub struct FinalizeEvmContract {
41    /// The spot token index being linked.
42    pub token: u32,
43    /// How the sender shows it deployed the contract.
44    pub input: EvmFinalizer,
45}
46
47impl L1Action for FinalizeEvmContract {
48    fn action(&self) -> Map {
49        Map::new().put("type", "finalizeEvmContract").put("token", self.token).put("input", self.input.wire())
50    }
51}