Skip to content

Commit ee05771

Browse files
authored
Change native EVM asset to USD (#83)
* "wip" * refactor: introduce SysOutput, SysAction, and SysTx traits * fix: remove unused TX impls * chore: improve visibility * lint: clippy * fix: remove unnecessary bound * refactor: rename SysOutput to SysBase * feat: add max_fee_per_gas and max_fee to MeteredSysTx * refactor: remove pecorino * fix: account for decimals in minting * fix: host_amount vs mint_amount * lint: clippy * refactor: move callee and input into systx * refactor: use iterator in mints_inner * nit: move variable declaration down * refactor: add with nonce methods * refactor: add some good tracing spans * doc: update NB * test: add USD record ser test * test: expand usd records test * chore: PascalCase * doc: improve one * fix: is_host_token includes ether * fix: native token address
1 parent 31b6df1 commit ee05771

File tree

31 files changed

+1998
-877
lines changed

31 files changed

+1998
-877
lines changed

crates/constants/src/chains/mod.rs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,2 @@
1-
pub mod pecorino;
2-
31
#[cfg(any(test, feature = "test-utils"))]
42
pub mod test_utils;

crates/constants/src/chains/pecorino.rs

Lines changed: 0 additions & 87 deletions
This file was deleted.

crates/constants/src/chains/test_utils.rs

Lines changed: 29 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,11 @@
11
//! Constants for local testnet chains.
22
33
use crate::{
4-
HostConstants, PredeployTokens, RollupConstants, SignetConstants, SignetEnvironmentConstants,
5-
SignetSystemConstants,
4+
types::{
5+
HostConstants, HostTokens, HostUsdRecord, RollupConstants, RollupTokens, SignetConstants,
6+
SignetEnvironmentConstants, SignetSystemConstants,
7+
},
8+
UsdRecords,
69
};
710
use alloy::primitives::{address, Address};
811
use std::borrow::Cow;
@@ -25,19 +28,33 @@ pub const HOST_PASSAGE: Address = Address::repeat_byte(0x33);
2528
/// Test address for the host transactor
2629
pub const HOST_TRANSACTOR: Address = Address::repeat_byte(0x44);
2730

28-
/// Test address for predeployed USDC
31+
/// Test address for host USDC
2932
pub const HOST_USDC: Address = Address::repeat_byte(0x55);
30-
/// Test address for predeployed USDT
33+
/// Test address for host USDT
3134
pub const HOST_USDT: Address = Address::repeat_byte(0x66);
32-
/// Test address for predeployed WBTC
35+
/// Test address for host WBTC
3336
pub const HOST_WBTC: Address = Address::repeat_byte(0x77);
37+
/// Test address for host WETH
38+
pub const HOST_WETH: Address = Address::repeat_byte(0x88);
39+
40+
/// Test record for host USDC.
41+
pub const USDC_RECORD: HostUsdRecord = HostUsdRecord::new(HOST_USDC, Cow::Borrowed("USDC"), 6);
42+
43+
/// Test record for host USDT.
44+
pub const USDT_RECORD: HostUsdRecord = HostUsdRecord::new(HOST_USDT, Cow::Borrowed("USDT"), 12);
45+
46+
/// Test records for host USD tokens.
47+
pub const HOST_USDS: UsdRecords = {
48+
let mut records = UsdRecords::new();
49+
records.push(USDC_RECORD);
50+
records.push(USDT_RECORD);
51+
records
52+
};
3453

35-
/// Test address for predeployed USDC
36-
pub const RU_USDC: Address = address!("0x0B8BC5e60EE10957E0d1A0d95598fA63E65605e2");
37-
/// Test address for predeployed USDT
38-
pub const RU_USDT: Address = address!("0xF34326d3521F1b07d1aa63729cB14A372f8A737C");
3954
/// Test address for predeployed WBTC
40-
pub const RU_WBTC: Address = address!("0xE3d7066115f7d6b65F88Dff86288dB4756a7D733");
55+
pub const RU_WBTC: Address = Address::repeat_byte(0x99);
56+
/// Test address for predeployed WETH
57+
pub const RU_WETH: Address = Address::repeat_byte(0xaa);
4158

4259
/// Name for the network.
4360
pub const RU_NAME: &str = "Test Rollup";
@@ -51,10 +68,10 @@ pub const RU_PASSAGE: Address = address!("0xB043BdD3d91376A76078c361bb82496Fdb80
5168
pub const BASE_FEE_RECIPIENT: Address = Address::repeat_byte(0xab);
5269

5370
/// Host system tokens.
54-
pub const HOST_TOKENS: PredeployTokens = PredeployTokens::new(HOST_USDC, HOST_USDT, HOST_WBTC);
71+
pub const HOST_TOKENS: HostTokens = HostTokens::new(HOST_USDS, HOST_WBTC, HOST_WETH);
5572

5673
/// RU system tokens.
57-
pub const RU_TOKENS: PredeployTokens = PredeployTokens::new(RU_USDC, RU_USDT, RU_WBTC);
74+
pub const RU_TOKENS: RollupTokens = RollupTokens::new(RU_WBTC, RU_WETH);
5875

5976
/// The URL of the Transaction Cache endpoint.
6077
pub const TX_CACHE_URL: &str = "localhost:8080/txcache";

crates/constants/src/lib.rs

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,13 +17,16 @@
1717
#![cfg_attr(docsrs, feature(doc_cfg, doc_auto_cfg))]
1818

1919
mod chains;
20-
pub use chains::pecorino;
2120
#[cfg(any(test, feature = "test-utils"))]
2221
pub use chains::test_utils;
2322

2423
mod types;
2524
pub use types::{
26-
ConfigError, HostConstants, KnownChains, PairedHeights, ParseChainError, PermissionedToken,
27-
PredeployTokens, RollupConstants, SignetConstants, SignetEnvironmentConstants,
28-
SignetSystemConstants, MINTER_ADDRESS,
25+
ConfigError, HostConstants, HostPermitted, HostTokens, HostUsdRecord, KnownChains,
26+
PairedHeights, ParseChainError, RollupConstants, RollupPermitted, RollupTokens,
27+
SignetConstants, SignetEnvironmentConstants, SignetSystemConstants, UsdRecords, MINTER_ADDRESS,
2928
};
29+
30+
/// Placeholder address for the native token of the current chain. By convention this is `0xee...`.
31+
pub const NATIVE_TOKEN_ADDRESS: alloy::primitives::Address =
32+
alloy::primitives::Address::repeat_byte(0xee);

crates/constants/src/types/chains.rs

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,6 @@ pub enum ParseChainError {
1414
/// Known chains for the Signet system.
1515
#[derive(Debug, Copy, Clone, PartialEq, Eq)]
1616
pub enum KnownChains {
17-
/// Pecorino chain.
18-
Pecorino,
1917
/// Test chain.
2018
#[cfg(any(test, feature = "test-utils"))]
2119
Test,
@@ -27,7 +25,6 @@ impl FromStr for KnownChains {
2725
fn from_str(s: &str) -> Result<Self, Self::Err> {
2826
let s = s.trim().to_lowercase();
2927
match s.as_str() {
30-
"pecorino" => Ok(Self::Pecorino),
3128
#[cfg(any(test, feature = "test-utils"))]
3229
"test" => Ok(Self::Test),
3330
_ => Err(ParseChainError::ChainNotSupported(s)),

crates/constants/src/types/environment.rs

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -22,11 +22,6 @@ impl SignetEnvironmentConstants {
2222
Self { host_name, rollup_name, transaction_cache }
2323
}
2424

25-
/// Get the hard-coded pecorino rollup constants.
26-
pub const fn pecorino() -> Self {
27-
crate::chains::pecorino::PECORINO_ENV
28-
}
29-
3025
/// Get the hard-coded local test rollup constants.
3126
#[cfg(any(test, feature = "test-utils"))]
3227
pub const fn test() -> Self {
@@ -55,7 +50,6 @@ impl FromStr for SignetEnvironmentConstants {
5550
fn from_str(s: &str) -> Result<Self, Self::Err> {
5651
let chain: KnownChains = s.parse()?;
5752
match chain {
58-
KnownChains::Pecorino => Ok(Self::pecorino()),
5953
#[cfg(any(test, feature = "test-utils"))]
6054
KnownChains::Test => Ok(Self::test()),
6155
}

crates/constants/src/types/host.rs

Lines changed: 22 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
1-
use crate::types::{ConfigError, KnownChains, ParseChainError, PredeployTokens};
1+
use crate::{
2+
types::{ConfigError, HostTokens, KnownChains, ParseChainError},
3+
HostUsdRecord,
4+
};
25
use alloy::{genesis::Genesis, primitives::Address};
36
use serde_json::Value;
47
use std::str::FromStr;
@@ -8,7 +11,7 @@ use std::str::FromStr;
811
/// These are system constants which may vary between chains, and are used to
912
/// determine the behavior of the chain, such as which contracts the Signet
1013
/// node should listen to, and the addresses of system-priveleged tokens.
11-
#[derive(Debug, Clone, Copy, PartialEq, Eq, serde::Deserialize, serde::Serialize)]
14+
#[derive(Debug, Clone, PartialEq, Eq, serde::Deserialize, serde::Serialize)]
1215
#[serde(rename_all = "camelCase")]
1316
pub struct HostConstants {
1417
/// Host chain ID.
@@ -23,8 +26,10 @@ pub struct HostConstants {
2326
passage: Address,
2427
/// Host address for the transactor contract
2528
transactor: Address,
26-
/// Host chain tokens that are predeployed on the rollup.
27-
tokens: PredeployTokens,
29+
/// Host chain tokens that are special-cased on the rollup. This includes
30+
/// USD tokens for the native asset, and permissioned tokens for bridged
31+
/// assets.
32+
tokens: HostTokens,
2833
}
2934

3035
impl std::fmt::Display for HostConstants {
@@ -46,16 +51,11 @@ impl HostConstants {
4651
orders: Address,
4752
passage: Address,
4853
transactor: Address,
49-
tokens: PredeployTokens,
54+
tokens: HostTokens,
5055
) -> Self {
5156
Self { chain_id, deploy_height, zenith, orders, passage, transactor, tokens }
5257
}
5358

54-
/// Get the hard-coded pecorino host constants.
55-
pub const fn pecorino() -> Self {
56-
crate::chains::pecorino::HOST
57-
}
58-
5959
/// Get the hard-coded local test host constants.
6060
#[cfg(any(test, feature = "test-utils"))]
6161
pub const fn test() -> Self {
@@ -121,8 +121,18 @@ impl HostConstants {
121121
}
122122

123123
/// Get the host tokens.
124-
pub const fn tokens(&self) -> PredeployTokens {
125-
self.tokens
124+
pub const fn tokens(&self) -> &HostTokens {
125+
&self.tokens
126+
}
127+
128+
/// Get the host USD record for the given address, if it is a host USD.
129+
pub fn usd_record(&self, address: Address) -> Option<&HostUsdRecord> {
130+
self.tokens.usd_record(address)
131+
}
132+
133+
/// Return true if the address is an approved USD token.
134+
pub fn is_usd(&self, address: Address) -> bool {
135+
self.tokens.is_usd(address)
126136
}
127137
}
128138

@@ -132,7 +142,6 @@ impl FromStr for HostConstants {
132142
fn from_str(s: &str) -> Result<Self, Self::Err> {
133143
let chain: KnownChains = s.parse()?;
134144
match chain {
135-
KnownChains::Pecorino => Ok(Self::pecorino()),
136145
#[cfg(any(test, feature = "test-utils"))]
137146
KnownChains::Test => Ok(Self::test()),
138147
}

0 commit comments

Comments
 (0)