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