mirror of
https://github.com/hl-archive-node/nanoreth.git
synced 2025-12-06 10:59:55 +00:00
first commit
This commit is contained in:
32
src/chainspec/genesis.json
Normal file
32
src/chainspec/genesis.json
Normal file
@ -0,0 +1,32 @@
|
||||
{
|
||||
"nonce": "0x0",
|
||||
"timestamp": "0x6490fdd2",
|
||||
"extraData": "0x",
|
||||
"gasLimit": "0x1c9c380",
|
||||
"difficulty": "0x0",
|
||||
"mixHash": "0x0000000000000000000000000000000000000000000000000000000000000000",
|
||||
"coinbase": "0x0000000000000000000000000000000000000000",
|
||||
"stateRoot": "0x5eb6e371a698b8d68f665192350ffcecbbbf322916f4b51bd79bb6887da3f494",
|
||||
"alloc": {
|
||||
"0x2222222222222222222222222222222222222222": {
|
||||
"nonce": 0,
|
||||
"balance": "0x33b2e3c9fd0803ce8000000",
|
||||
"code": "0x608060405236603f5760405134815233907f88a5966d370b9919b20f3e2c13ff65706f196a4e32cc2c12bf57088f885258749060200160405180910390a2005b600080fdfea2646970667358221220ca425db50898ac19f9e4676e86e8ebed9853baa048942f6306fe8a86b8d4abb964736f6c63430008090033",
|
||||
"storage": {}
|
||||
},
|
||||
"0x5555555555555555555555555555555555555555": {
|
||||
"nonce": 0,
|
||||
"balance": "0x0",
|
||||
"code": "0x6080604052600436106100bc5760003560e01c8063313ce56711610074578063a9059cbb1161004e578063a9059cbb146102cb578063d0e30db0146100bc578063dd62ed3e14610311576100bc565b8063313ce5671461024b57806370a082311461027657806395d89b41146102b6576100bc565b806318160ddd116100a557806318160ddd146101aa57806323b872dd146101d15780632e1a7d4d14610221576100bc565b806306fdde03146100c6578063095ea7b314610150575b6100c4610359565b005b3480156100d257600080fd5b506100db6103a8565b6040805160208082528351818301528351919283929083019185019080838360005b838110156101155781810151838201526020016100fd565b50505050905090810190601f1680156101425780820380516001836020036101000a031916815260200191505b509250505060405180910390f35b34801561015c57600080fd5b506101966004803603604081101561017357600080fd5b5073ffffffffffffffffffffffffffffffffffffffff8135169060200135610454565b604080519115158252519081900360200190f35b3480156101b657600080fd5b506101bf6104c7565b60408051918252519081900360200190f35b3480156101dd57600080fd5b50610196600480360360608110156101f457600080fd5b5073ffffffffffffffffffffffffffffffffffffffff8135811691602081013590911690604001356104cb565b34801561022d57600080fd5b506100c46004803603602081101561024457600080fd5b503561066b565b34801561025757600080fd5b50610260610700565b6040805160ff9092168252519081900360200190f35b34801561028257600080fd5b506101bf6004803603602081101561029957600080fd5b503573ffffffffffffffffffffffffffffffffffffffff16610709565b3480156102c257600080fd5b506100db61071b565b3480156102d757600080fd5b50610196600480360360408110156102ee57600080fd5b5073ffffffffffffffffffffffffffffffffffffffff8135169060200135610793565b34801561031d57600080fd5b506101bf6004803603604081101561033457600080fd5b5073ffffffffffffffffffffffffffffffffffffffff813581169160200135166107a7565b33600081815260036020908152604091829020805434908101909155825190815291517fe1fffcc4923d04b559f4d29a8bfc6cda04eb5b0d3c460751c2402c5c5cc9109c9281900390910190a2565b6000805460408051602060026001851615610100027fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff0190941693909304601f8101849004840282018401909252818152929183018282801561044c5780601f106104215761010080835404028352916020019161044c565b820191906000526020600020905b81548152906001019060200180831161042f57829003601f168201915b505050505081565b33600081815260046020908152604080832073ffffffffffffffffffffffffffffffffffffffff8716808552908352818420869055815186815291519394909390927f8c5be1e5ebec7d5bd14f71427d1e84f3dd0314c0f7b2291e5b200ac8c7c3b925928290030190a350600192915050565b4790565b73ffffffffffffffffffffffffffffffffffffffff83166000908152600360205260408120548211156104fd57600080fd5b73ffffffffffffffffffffffffffffffffffffffff84163314801590610573575073ffffffffffffffffffffffffffffffffffffffff841660009081526004602090815260408083203384529091529020547fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff14155b156105ed5773ffffffffffffffffffffffffffffffffffffffff841660009081526004602090815260408083203384529091529020548211156105b557600080fd5b73ffffffffffffffffffffffffffffffffffffffff841660009081526004602090815260408083203384529091529020805483900390555b73ffffffffffffffffffffffffffffffffffffffff808516600081815260036020908152604080832080548890039055938716808352918490208054870190558351868152935191937fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef929081900390910190a35060019392505050565b3360009081526003602052604090205481111561068757600080fd5b33600081815260036020526040808220805485900390555183156108fc0291849190818181858888f193505050501580156106c6573d6000803e3d6000fd5b5060408051828152905133917f7fcf532c15f0a6db0bd6d0e038bea71d30d808c7d98cb3bf7268a95bf5081b65919081900360200190a250565b60025460ff1681565b60036020526000908152604090205481565b60018054604080516020600284861615610100027fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff0190941693909304601f8101849004840282018401909252818152929183018282801561044c5780601f106104215761010080835404028352916020019161044c565b60006107a03384846104cb565b9392505050565b60046020908152600092835260408084209091529082529020548156fea265627a7a72315820e87684b404839c5657b1e7820bfa5ac4539ac8c83c21e28ec1086123db902cfe64736f6c63430005110032",
|
||||
"storage": {
|
||||
"0x0000000000000000000000000000000000000000000000000000000000000000": "0x5772617070656420485950450000000000000000000000000000000000000018",
|
||||
"0x0000000000000000000000000000000000000000000000000000000000000001": "0x574859504500000000000000000000000000000000000000000000000000000a",
|
||||
"0x0000000000000000000000000000000000000000000000000000000000000002": "0x0000000000000000000000000000000000000000000000000000000000000012"
|
||||
}
|
||||
}
|
||||
},
|
||||
"number": "0x0",
|
||||
"gasUsed": "0x0",
|
||||
"parentHash": "0x0000000000000000000000000000000000000000000000000000000000000000",
|
||||
"parentBeaconBlockRoot": "0x0000000000000000000000000000000000000000000000000000000000000000"
|
||||
}
|
||||
57
src/chainspec/hl.rs
Normal file
57
src/chainspec/hl.rs
Normal file
@ -0,0 +1,57 @@
|
||||
use alloy_chains::{Chain, NamedChain};
|
||||
use alloy_primitives::{b256, Address, Bytes, B256, B64, U256};
|
||||
use std::sync::Arc;
|
||||
use once_cell::sync::Lazy;
|
||||
use reth_chainspec::{ChainSpec, DEV_HARDFORKS};
|
||||
use reth_primitives::{Header, SealedHeader};
|
||||
|
||||
static GENESIS_HASH: B256 =
|
||||
b256!("d8fcc13b6a195b88b7b2da3722ff6cad767b13a8c1e9ffb1c73aa9d216d895f0");
|
||||
|
||||
/// The Hyperliqiud Mainnet spec
|
||||
pub static HL_MAINNET: Lazy<Arc<ChainSpec>> = Lazy::new(|| {
|
||||
ChainSpec {
|
||||
chain: Chain::from_named(NamedChain::Hyperliquid),
|
||||
genesis: serde_json::from_str(include_str!("genesis.json"))
|
||||
.expect("Can't deserialize Hyperliquid Mainnet genesis json"),
|
||||
genesis_header: empty_genesis_header(),
|
||||
paris_block_and_final_difficulty: Some((0, U256::from(0))),
|
||||
hardforks: DEV_HARDFORKS.clone(),
|
||||
prune_delete_limit: 10000,
|
||||
..Default::default()
|
||||
}
|
||||
.into()
|
||||
});
|
||||
|
||||
/// Empty genesis header for Hyperliquid Mainnet.
|
||||
///
|
||||
/// The exact value is not known per se, but the parent hash of block 1 is known to be
|
||||
/// [GENESIS_HASH].
|
||||
fn empty_genesis_header() -> SealedHeader {
|
||||
SealedHeader::new(
|
||||
Header {
|
||||
parent_hash: B256::ZERO,
|
||||
number: 0,
|
||||
timestamp: 0,
|
||||
transactions_root: B256::ZERO,
|
||||
receipts_root: B256::ZERO,
|
||||
state_root: B256::ZERO,
|
||||
gas_used: 0,
|
||||
gas_limit: 0x1c9c380,
|
||||
difficulty: U256::ZERO,
|
||||
mix_hash: B256::ZERO,
|
||||
extra_data: Bytes::new(),
|
||||
nonce: B64::ZERO,
|
||||
ommers_hash: B256::ZERO,
|
||||
beneficiary: Address::ZERO,
|
||||
logs_bloom: Default::default(),
|
||||
base_fee_per_gas: Some(0),
|
||||
withdrawals_root: Some(B256::ZERO),
|
||||
blob_gas_used: Some(0),
|
||||
excess_blob_gas: Some(0),
|
||||
parent_beacon_block_root: Some(B256::ZERO),
|
||||
requests_hash: Some(B256::ZERO),
|
||||
},
|
||||
GENESIS_HASH,
|
||||
)
|
||||
}
|
||||
139
src/chainspec/mod.rs
Normal file
139
src/chainspec/mod.rs
Normal file
@ -0,0 +1,139 @@
|
||||
//! Chain specification for HyperEVM.
|
||||
pub mod hl;
|
||||
pub mod parser;
|
||||
|
||||
use crate::hardforks::{hl::HlHardfork, HlHardforks};
|
||||
use alloy_consensus::Header;
|
||||
use alloy_eips::eip7840::BlobParams;
|
||||
use alloy_genesis::Genesis;
|
||||
use alloy_primitives::{Address, B256, U256};
|
||||
use reth_chainspec::{
|
||||
BaseFeeParams, ChainSpec, DepositContract, EthChainSpec, EthereumHardfork, EthereumHardforks,
|
||||
ForkCondition, ForkFilter, ForkId, Hardforks, Head,
|
||||
};
|
||||
use reth_discv4::NodeRecord;
|
||||
use reth_evm::eth::spec::EthExecutorSpec;
|
||||
use std::{fmt::Display, sync::Arc};
|
||||
|
||||
/// Hl chain spec type.
|
||||
#[derive(Debug, Default, Clone, PartialEq, Eq)]
|
||||
pub struct HlChainSpec {
|
||||
/// [`ChainSpec`].
|
||||
pub inner: ChainSpec,
|
||||
}
|
||||
|
||||
impl EthChainSpec for HlChainSpec {
|
||||
type Header = Header;
|
||||
|
||||
fn blob_params_at_timestamp(&self, timestamp: u64) -> Option<BlobParams> {
|
||||
self.inner.blob_params_at_timestamp(timestamp)
|
||||
}
|
||||
|
||||
fn final_paris_total_difficulty(&self) -> Option<U256> {
|
||||
self.inner.final_paris_total_difficulty()
|
||||
}
|
||||
|
||||
fn chain(&self) -> alloy_chains::Chain {
|
||||
self.inner.chain()
|
||||
}
|
||||
|
||||
fn base_fee_params_at_block(&self, block_number: u64) -> BaseFeeParams {
|
||||
self.inner.base_fee_params_at_block(block_number)
|
||||
}
|
||||
|
||||
fn base_fee_params_at_timestamp(&self, timestamp: u64) -> BaseFeeParams {
|
||||
self.inner.base_fee_params_at_timestamp(timestamp)
|
||||
}
|
||||
|
||||
fn deposit_contract(&self) -> Option<&DepositContract> {
|
||||
None
|
||||
}
|
||||
|
||||
fn genesis_hash(&self) -> B256 {
|
||||
self.inner.genesis_hash()
|
||||
}
|
||||
|
||||
fn prune_delete_limit(&self) -> usize {
|
||||
self.inner.prune_delete_limit()
|
||||
}
|
||||
|
||||
fn display_hardforks(&self) -> Box<dyn Display> {
|
||||
Box::new(self.inner.display_hardforks())
|
||||
}
|
||||
|
||||
fn genesis_header(&self) -> &Header {
|
||||
self.inner.genesis_header()
|
||||
}
|
||||
|
||||
fn genesis(&self) -> &Genesis {
|
||||
self.inner.genesis()
|
||||
}
|
||||
|
||||
fn bootnodes(&self) -> Option<Vec<NodeRecord>> {
|
||||
self.inner.bootnodes()
|
||||
}
|
||||
|
||||
fn is_optimism(&self) -> bool {
|
||||
false
|
||||
}
|
||||
}
|
||||
|
||||
impl Hardforks for HlChainSpec {
|
||||
fn fork<H: reth_chainspec::Hardfork>(&self, fork: H) -> reth_chainspec::ForkCondition {
|
||||
self.inner.fork(fork)
|
||||
}
|
||||
|
||||
fn forks_iter(
|
||||
&self,
|
||||
) -> impl Iterator<Item = (&dyn reth_chainspec::Hardfork, reth_chainspec::ForkCondition)> {
|
||||
self.inner.forks_iter()
|
||||
}
|
||||
|
||||
fn fork_id(&self, head: &Head) -> ForkId {
|
||||
self.inner.fork_id(head)
|
||||
}
|
||||
|
||||
fn latest_fork_id(&self) -> ForkId {
|
||||
self.inner.latest_fork_id()
|
||||
}
|
||||
|
||||
fn fork_filter(&self, head: Head) -> ForkFilter {
|
||||
self.inner.fork_filter(head)
|
||||
}
|
||||
}
|
||||
|
||||
impl From<ChainSpec> for HlChainSpec {
|
||||
fn from(value: ChainSpec) -> Self {
|
||||
Self { inner: value }
|
||||
}
|
||||
}
|
||||
|
||||
impl EthereumHardforks for HlChainSpec {
|
||||
fn ethereum_fork_activation(&self, fork: EthereumHardfork) -> ForkCondition {
|
||||
self.inner.ethereum_fork_activation(fork)
|
||||
}
|
||||
}
|
||||
|
||||
impl HlHardforks for HlChainSpec {
|
||||
fn hl_fork_activation(&self, fork: HlHardfork) -> ForkCondition {
|
||||
self.fork(fork)
|
||||
}
|
||||
}
|
||||
|
||||
impl EthExecutorSpec for HlChainSpec {
|
||||
fn deposit_contract_address(&self) -> Option<Address> {
|
||||
None
|
||||
}
|
||||
}
|
||||
|
||||
impl From<HlChainSpec> for ChainSpec {
|
||||
fn from(value: HlChainSpec) -> Self {
|
||||
value.inner
|
||||
}
|
||||
}
|
||||
|
||||
impl HlHardforks for Arc<HlChainSpec> {
|
||||
fn hl_fork_activation(&self, fork: HlHardfork) -> ForkCondition {
|
||||
self.as_ref().hl_fork_activation(fork)
|
||||
}
|
||||
}
|
||||
31
src/chainspec/parser.rs
Normal file
31
src/chainspec/parser.rs
Normal file
@ -0,0 +1,31 @@
|
||||
use super::hl::HL_MAINNET;
|
||||
use reth_chainspec::ChainSpec;
|
||||
use reth_cli::chainspec::ChainSpecParser;
|
||||
use std::sync::Arc;
|
||||
|
||||
/// Chains supported by HyperEVM. First value should be used as the default.
|
||||
pub const SUPPORTED_CHAINS: &[&str] = &["mainnet"];
|
||||
|
||||
/// Hyperliquid chain specification parser.
|
||||
#[derive(Debug, Clone, Default)]
|
||||
pub struct HlChainSpecParser;
|
||||
|
||||
impl ChainSpecParser for HlChainSpecParser {
|
||||
type ChainSpec = ChainSpec;
|
||||
|
||||
const SUPPORTED_CHAINS: &'static [&'static str] = SUPPORTED_CHAINS;
|
||||
|
||||
fn parse(s: &str) -> eyre::Result<Arc<ChainSpec>> {
|
||||
chain_value_parser(s)
|
||||
}
|
||||
}
|
||||
|
||||
/// Clap value parser for [`ChainSpec`]s.
|
||||
///
|
||||
/// Currently only mainnet is supported.
|
||||
pub fn chain_value_parser(s: &str) -> eyre::Result<Arc<ChainSpec>> {
|
||||
match s {
|
||||
"mainnet" => Ok(HL_MAINNET.clone().into()),
|
||||
_ => Err(eyre::eyre!("Unsupported chain: {}", s)),
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user