Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 0 additions & 2 deletions crates/constants/src/chains/mod.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,2 @@
pub mod pecorino;

#[cfg(any(test, feature = "test-utils"))]
pub mod test_utils;
87 changes: 0 additions & 87 deletions crates/constants/src/chains/pecorino.rs

This file was deleted.

41 changes: 29 additions & 12 deletions crates/constants/src/chains/test_utils.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
//! Constants for local testnet chains.

use crate::{
HostConstants, PredeployTokens, RollupConstants, SignetConstants, SignetEnvironmentConstants,
SignetSystemConstants,
types::{
HostConstants, HostTokens, HostUsdRecord, RollupConstants, RollupTokens, SignetConstants,
SignetEnvironmentConstants, SignetSystemConstants,
},
UsdRecords,
};
use alloy::primitives::{address, Address};
use std::borrow::Cow;
Expand All @@ -25,19 +28,33 @@ pub const HOST_PASSAGE: Address = Address::repeat_byte(0x33);
/// Test address for the host transactor
pub const HOST_TRANSACTOR: Address = Address::repeat_byte(0x44);

/// Test address for predeployed USDC
/// Test address for host USDC
pub const HOST_USDC: Address = Address::repeat_byte(0x55);
/// Test address for predeployed USDT
/// Test address for host USDT
pub const HOST_USDT: Address = Address::repeat_byte(0x66);
/// Test address for predeployed WBTC
/// Test address for host WBTC
pub const HOST_WBTC: Address = Address::repeat_byte(0x77);
/// Test address for host WETH
pub const HOST_WETH: Address = Address::repeat_byte(0x88);

/// Test record for host USDC.
pub const USDC_RECORD: HostUsdRecord = HostUsdRecord::new(HOST_USDC, Cow::Borrowed("USDC"), 6);

/// Test record for host USDT.
pub const USDT_RECORD: HostUsdRecord = HostUsdRecord::new(HOST_USDT, Cow::Borrowed("USDT"), 12);

/// Test records for host USD tokens.
pub const HOST_USDS: UsdRecords = {
let mut records = UsdRecords::new();
records.push(USDC_RECORD);
records.push(USDT_RECORD);
records
};

/// Test address for predeployed USDC
pub const RU_USDC: Address = address!("0x0B8BC5e60EE10957E0d1A0d95598fA63E65605e2");
/// Test address for predeployed USDT
pub const RU_USDT: Address = address!("0xF34326d3521F1b07d1aa63729cB14A372f8A737C");
/// Test address for predeployed WBTC
pub const RU_WBTC: Address = address!("0xE3d7066115f7d6b65F88Dff86288dB4756a7D733");
pub const RU_WBTC: Address = Address::repeat_byte(0x99);
/// Test address for predeployed WETH
pub const RU_WETH: Address = Address::repeat_byte(0xaa);

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

/// Host system tokens.
pub const HOST_TOKENS: PredeployTokens = PredeployTokens::new(HOST_USDC, HOST_USDT, HOST_WBTC);
pub const HOST_TOKENS: HostTokens = HostTokens::new(HOST_USDS, HOST_WBTC, HOST_WETH);

/// RU system tokens.
pub const RU_TOKENS: PredeployTokens = PredeployTokens::new(RU_USDC, RU_USDT, RU_WBTC);
pub const RU_TOKENS: RollupTokens = RollupTokens::new(RU_WBTC, RU_WETH);

/// The URL of the Transaction Cache endpoint.
pub const TX_CACHE_URL: &str = "localhost:8080/txcache";
Expand Down
11 changes: 7 additions & 4 deletions crates/constants/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,16 @@
#![cfg_attr(docsrs, feature(doc_cfg, doc_auto_cfg))]

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

mod types;
pub use types::{
ConfigError, HostConstants, KnownChains, PairedHeights, ParseChainError, PermissionedToken,
PredeployTokens, RollupConstants, SignetConstants, SignetEnvironmentConstants,
SignetSystemConstants, MINTER_ADDRESS,
ConfigError, HostConstants, HostPermitted, HostTokens, HostUsdRecord, KnownChains,
PairedHeights, ParseChainError, RollupConstants, RollupPermitted, RollupTokens,
SignetConstants, SignetEnvironmentConstants, SignetSystemConstants, UsdRecords, MINTER_ADDRESS,
};

/// Placeholder address for the native token of the current chain. By convention this is `0xee...`.
pub const NATIVE_TOKEN_ADDRESS: alloy::primitives::Address =
alloy::primitives::Address::repeat_byte(0xee);
3 changes: 0 additions & 3 deletions crates/constants/src/types/chains.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,6 @@ pub enum ParseChainError {
/// Known chains for the Signet system.
#[derive(Debug, Copy, Clone, PartialEq, Eq)]
pub enum KnownChains {
/// Pecorino chain.
Pecorino,
/// Test chain.
#[cfg(any(test, feature = "test-utils"))]
Test,
Expand All @@ -27,7 +25,6 @@ impl FromStr for KnownChains {
fn from_str(s: &str) -> Result<Self, Self::Err> {
let s = s.trim().to_lowercase();
match s.as_str() {
"pecorino" => Ok(Self::Pecorino),
#[cfg(any(test, feature = "test-utils"))]
"test" => Ok(Self::Test),
_ => Err(ParseChainError::ChainNotSupported(s)),
Expand Down
6 changes: 0 additions & 6 deletions crates/constants/src/types/environment.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,6 @@ impl SignetEnvironmentConstants {
Self { host_name, rollup_name, transaction_cache }
}

/// Get the hard-coded pecorino rollup constants.
pub const fn pecorino() -> Self {
crate::chains::pecorino::PECORINO_ENV
}

/// Get the hard-coded local test rollup constants.
#[cfg(any(test, feature = "test-utils"))]
pub const fn test() -> Self {
Expand Down Expand Up @@ -55,7 +50,6 @@ impl FromStr for SignetEnvironmentConstants {
fn from_str(s: &str) -> Result<Self, Self::Err> {
let chain: KnownChains = s.parse()?;
match chain {
KnownChains::Pecorino => Ok(Self::pecorino()),
#[cfg(any(test, feature = "test-utils"))]
KnownChains::Test => Ok(Self::test()),
}
Expand Down
35 changes: 22 additions & 13 deletions crates/constants/src/types/host.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
use crate::types::{ConfigError, KnownChains, ParseChainError, PredeployTokens};
use crate::{
types::{ConfigError, HostTokens, KnownChains, ParseChainError},
HostUsdRecord,
};
use alloy::{genesis::Genesis, primitives::Address};
use serde_json::Value;
use std::str::FromStr;
Expand All @@ -8,7 +11,7 @@ use std::str::FromStr;
/// These are system constants which may vary between chains, and are used to
/// determine the behavior of the chain, such as which contracts the Signet
/// node should listen to, and the addresses of system-priveleged tokens.
#[derive(Debug, Clone, Copy, PartialEq, Eq, serde::Deserialize, serde::Serialize)]
#[derive(Debug, Clone, PartialEq, Eq, serde::Deserialize, serde::Serialize)]
#[serde(rename_all = "camelCase")]
pub struct HostConstants {
/// Host chain ID.
Expand All @@ -23,8 +26,10 @@ pub struct HostConstants {
passage: Address,
/// Host address for the transactor contract
transactor: Address,
/// Host chain tokens that are predeployed on the rollup.
tokens: PredeployTokens,
/// Host chain tokens that are special-cased on the rollup. This includes
/// USD tokens for the native asset, and permissioned tokens for bridged
/// assets.
tokens: HostTokens,
}

impl std::fmt::Display for HostConstants {
Expand All @@ -46,16 +51,11 @@ impl HostConstants {
orders: Address,
passage: Address,
transactor: Address,
tokens: PredeployTokens,
tokens: HostTokens,
) -> Self {
Self { chain_id, deploy_height, zenith, orders, passage, transactor, tokens }
}

/// Get the hard-coded pecorino host constants.
pub const fn pecorino() -> Self {
crate::chains::pecorino::HOST
}

/// Get the hard-coded local test host constants.
#[cfg(any(test, feature = "test-utils"))]
pub const fn test() -> Self {
Expand Down Expand Up @@ -121,8 +121,18 @@ impl HostConstants {
}

/// Get the host tokens.
pub const fn tokens(&self) -> PredeployTokens {
self.tokens
pub const fn tokens(&self) -> &HostTokens {
&self.tokens
}

/// Get the host USD record for the given address, if it is a host USD.
pub fn usd_record(&self, address: Address) -> Option<&HostUsdRecord> {
self.tokens.usd_record(address)
}

/// Return true if the address is an approved USD token.
pub fn is_usd(&self, address: Address) -> bool {
self.tokens.is_usd(address)
}
}

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