Skip to content

feat: add chain names & tx cache URL #48

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 15 commits into from
May 19, 2025
1 change: 0 additions & 1 deletion crates/constants/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ serde.workspace = true
serde_json.workspace = true
thiserror.workspace = true


[features]
default = []
test-utils = []
25 changes: 23 additions & 2 deletions crates/constants/src/chains/pecorino.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,14 @@
//! Constants for the Pecorino testnet.

use crate::{HostConstants, PredeployTokens, RollupConstants, SignetSystemConstants};
use crate::{
HostConstants, PredeployTokens, RollupConstants, SignetConstants, SignetEnvironmentConstants,
SignetSystemConstants,
};
use alloy::primitives::{address, Address};
use std::borrow::Cow;

/// Name for the host chain.
pub const HOST_NAME: &str = "Pecorino Host";
/// Chain ID for the Pecorino testnet host chain.
pub const HOST_CHAIN_ID: u64 = 3151908;
/// Deployment height for the Pecorino testnet host chain.
Expand Down Expand Up @@ -30,6 +36,8 @@ pub const RU_USDT: Address = address!("0xF34326d3521F1b07d1aa63729cB14A372f8A737
/// WBTC token for the Pecorino testnet RU chain.
pub const RU_WBTC: Address = address!("0xE3d7066115f7d6b65F88Dff86288dB4756a7D733");

/// Name for the network.
pub const RU_NAME: &str = "Pecorino";
/// Chain ID for the Pecorino testnet RU chain.
pub const RU_CHAIN_ID: u64 = 14174;
/// `Orders` contract address for the Pecorino testnet RU chain.
Expand All @@ -46,6 +54,9 @@ pub const HOST_TOKENS: PredeployTokens =
/// RU system tokens for Pecorino.
pub const RU_TOKENS: PredeployTokens = crate::PredeployTokens::new(RU_USDC, RU_USDT, RU_WBTC);

/// The URL of the Transaction Cache endpoint.
pub const TX_CACHE_URL: &str = "https://transactions.pecorino.signet.sh";

/// Host system constants for Pecorino.
pub const HOST: HostConstants = crate::HostConstants::new(
HOST_CHAIN_ID,
Expand All @@ -62,4 +73,14 @@ pub const ROLLUP: RollupConstants =
crate::RollupConstants::new(RU_CHAIN_ID, RU_ORDERS, RU_PASSAGE, BASE_FEE_RECIPIENT, RU_TOKENS);

/// Signet system constants for Pecorino.
pub const PECORINO: SignetSystemConstants = crate::SignetSystemConstants::new(HOST, ROLLUP);
pub const PECORINO_SYS: SignetSystemConstants = crate::SignetSystemConstants::new(HOST, ROLLUP);

/// Signet environment constants for Pecorino.
pub const PECORINO_ENV: SignetEnvironmentConstants = SignetEnvironmentConstants::new(
Cow::Borrowed(HOST_NAME),
Cow::Borrowed(RU_NAME),
Cow::Borrowed(TX_CACHE_URL),
);

/// Signet constants for Pecorino.
pub const PECORINO: SignetConstants = SignetConstants::new(PECORINO_SYS, PECORINO_ENV);
27 changes: 24 additions & 3 deletions crates/constants/src/chains/test_utils.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,17 @@
//! Constants for local testnet chains.

use crate::{HostConstants, PredeployTokens, RollupConstants, SignetSystemConstants};
use crate::{
HostConstants, PredeployTokens, RollupConstants, SignetConstants, SignetEnvironmentConstants,
SignetSystemConstants,
};
use alloy::primitives::{address, Address};
use std::borrow::Cow;

/// Default reward address used in tests when no other is specified.
pub const DEFAULT_REWARD_ADDRESS: Address = Address::repeat_byte(0x81);

/// Name for the host chain.
pub const HOST_NAME: &str = "Test Host";
/// Test chain id for the host chain.
pub const HOST_CHAIN_ID: u64 = 1;
/// Test deployment height.
Expand Down Expand Up @@ -33,6 +39,8 @@ pub const RU_USDT: Address = address!("0xF34326d3521F1b07d1aa63729cB14A372f8A737
/// Test address for predeployed WBTC
pub const RU_WBTC: Address = address!("0xE3d7066115f7d6b65F88Dff86288dB4756a7D733");

/// Name for the network.
pub const RU_NAME: &str = "Test Rollup";
/// Test chain id for the RU chain.
pub const RU_CHAIN_ID: u64 = 15;
/// Test address for the RU zenith.
Expand All @@ -48,6 +56,9 @@ pub const HOST_TOKENS: PredeployTokens = PredeployTokens::new(HOST_USDC, HOST_US
/// RU system tokens.
pub const RU_TOKENS: PredeployTokens = PredeployTokens::new(RU_USDC, RU_USDT, RU_WBTC);

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

/// Host config
pub const HOST: HostConstants = HostConstants::new(
HOST_CHAIN_ID,
Expand All @@ -63,5 +74,15 @@ pub const HOST: HostConstants = HostConstants::new(
pub const ROLLUP: RollupConstants =
RollupConstants::new(RU_CHAIN_ID, RU_ORDERS, RU_PASSAGE, BASE_FEE_RECIPIENT, RU_TOKENS);

/// Test constants for unit tests.
pub const TEST_CONSTANTS: SignetSystemConstants = SignetSystemConstants::new(HOST, ROLLUP);
/// System constants for unit tests.
pub const TEST_SYS: SignetSystemConstants = SignetSystemConstants::new(HOST, ROLLUP);

/// Environment constants for unit tests.
pub const TEST_ENV: SignetEnvironmentConstants = SignetEnvironmentConstants::new(
Cow::Borrowed(HOST_NAME),
Cow::Borrowed(RU_NAME),
Cow::Borrowed(TX_CACHE_URL),
);

/// Signet constants for Pecorino.
pub const TEST: SignetConstants = SignetConstants::new(TEST_SYS, TEST_ENV);
2 changes: 1 addition & 1 deletion crates/constants/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,5 +24,5 @@ pub use chains::test_utils;
mod types;
pub use types::{
ConfigError, HostConstants, PairedHeights, PermissionedToken, PredeployTokens, RollupConstants,
SignetSystemConstants, MINTER_ADDRESS,
SignetConstants, SignetEnvironmentConstants, SignetSystemConstants, MINTER_ADDRESS,
};
68 changes: 68 additions & 0 deletions crates/constants/src/types/environment.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
use std::borrow::Cow;

/// Signet Environment constants.
#[derive(Debug, Clone, PartialEq, Eq, serde::Deserialize, serde::Serialize)]
pub struct SignetEnvironmentConstants {
/// Name of the host chain.
host_name: Cow<'static, str>,
/// Name of the rollup.
rollup_name: Cow<'static, str>,
/// URL of the Transaction Cache
transaction_cache: Cow<'static, str>,
}

impl SignetEnvironmentConstants {
/// Create a new set of environment constants.
pub const fn new(
host_name: Cow<'static, str>,
rollup_name: Cow<'static, str>,
transaction_cache: Cow<'static, str>,
) -> Self {
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 {
crate::chains::test_utils::TEST_ENV
}

/// Get the host name.
pub fn host_name(&self) -> &str {
self.host_name.as_ref()
}

/// Get the rollup name.
pub fn rollup_name(&self) -> &str {
self.rollup_name.as_ref()
}

/// Get the transaction cache URL.
pub fn transaction_cache(&self) -> &str {
self.transaction_cache.as_ref()
}
}

#[cfg(test)]
mod test {
use super::*;

#[test]
fn load_built_ins() {
// deserialize json

let json = serde_json::json!({
"host_name": "pecorino",
"rollup_name": "pecorino",
"transaction_cache": "https://pecorino.com"
});

let s = serde_json::from_value::<SignetEnvironmentConstants>(json.clone()).unwrap();
assert_eq!(serde_json::to_value(&s).unwrap(), json)
}
}
57 changes: 55 additions & 2 deletions crates/constants/src/types/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@ pub use rollup::{RollupConstants, MINTER_ADDRESS};
mod tokens;
pub use tokens::{PermissionedToken, PredeployTokens};

mod environment;
pub use environment::SignetEnvironmentConstants;

use alloy::{
genesis::Genesis,
primitives::{Address, U256},
Expand Down Expand Up @@ -40,13 +43,13 @@ impl SignetSystemConstants {

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

/// Get the hard-coded local test constants.
#[cfg(any(test, feature = "test-utils"))]
pub const fn test() -> Self {
crate::chains::test_utils::TEST_CONSTANTS
crate::chains::test_utils::TEST_SYS
}

/// Load the constants from a [`Genesis`].
Expand Down Expand Up @@ -209,3 +212,53 @@ impl SignetSystemConstants {
self.rollup.minter()
}
}

/// All constants pertaining to the Signet system.
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct SignetConstants {
/// System constants for a Signet chain.
system: SignetSystemConstants,
/// Environment constants for a Signet chain.
environment: SignetEnvironmentConstants,
}

impl SignetConstants {
/// Create a new set of Signet constants.
pub const fn new(
system: SignetSystemConstants,
environment: SignetEnvironmentConstants,
) -> Self {
Self { system, environment }
}

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

/// Get the hard-coded local test rollup constants.
#[cfg(any(test, feature = "test-utils"))]
pub const fn test() -> Self {
crate::chains::test_utils::TEST
}

/// Get the system constants.
pub const fn system(&self) -> SignetSystemConstants {
self.system
}

/// Get the host constants.
pub const fn host(&self) -> HostConstants {
self.system.host
}

/// Get the rollup constants.
pub const fn rollup(&self) -> RollupConstants {
self.system.rollup
}

/// Get the environment constants.
pub const fn environment(&self) -> &SignetEnvironmentConstants {
&self.environment
}
}
3 changes: 2 additions & 1 deletion crates/evm/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -81,14 +81,15 @@ where
/// Test utilities for the Signet EVM impl.
#[cfg(any(test, feature = "test-utils"))]
pub mod test_utils {
use crate::signet_evm;
use reth::revm::{context::CfgEnv, primitives::hardfork::SpecId};
use signet_types::test_utils::*;
use trevm::revm::database::in_memory_db::InMemoryDB;

/// Create a new Signet EVM with an in-memory database for testing.
pub fn test_signet_evm() -> super::EvmNeedsBlock<trevm::revm::database::in_memory_db::InMemoryDB>
{
super::signet_evm(InMemoryDB::default(), TEST_CONSTANTS).fill_cfg(&TestCfg)
signet_evm(InMemoryDB::default(), TEST_SYS).fill_cfg(&TestCfg)
}

/// Test configuration for the Signet EVM.
Expand Down
2 changes: 1 addition & 1 deletion crates/extract/src/extractor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@ mod test {
.submit_block(ru_block);
let (chain, _) = hbs.to_chain();

let extractor = Extractor::new(TEST_CONSTANTS);
let extractor = Extractor::new(TEST_SYS);
let extracts = extractor.extract_signet(&chain).next().unwrap();

hbs.assert_conforms(&extracts);
Expand Down
19 changes: 12 additions & 7 deletions crates/rpc/examples/filler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ use alloy::{
};
use eyre::{eyre, Error};
use signet_bundle::SignetEthBundle;
use signet_constants::SignetSystemConstants;
use signet_constants::SignetConstants;
use signet_tx_cache::{client::TxCache, types::TxCacheSendBundleResponse};
use signet_types::{AggregateOrders, SignedFill, SignedOrder, UnsignedFill};
use std::{collections::HashMap, slice::from_ref};
Expand Down Expand Up @@ -45,21 +45,25 @@ pub struct Filler<S: Signer> {
/// The transaction cache endpoint.
tx_cache: TxCache,
/// The system constants.
constants: SignetSystemConstants,
constants: SignetConstants,
}

impl<S> Filler<S>
where
S: Signer,
{
/// Create a new Filler with the given signer, provider, and transaction cache endpoint.
pub const fn new(
pub fn new(
signer: S,
ru_provider: Provider,
tx_cache: TxCache,
constants: SignetSystemConstants,
) -> Self {
Self { signer, ru_provider, tx_cache, constants }
constants: SignetConstants,
) -> Result<Self, Error> {
Ok(Self {
signer,
ru_provider,
tx_cache: TxCache::new_from_string(constants.environment().transaction_cache())?,
constants,
})
}

/// Query the transaction cache to get all possible orders.
Expand Down Expand Up @@ -159,6 +163,7 @@ where
unsigned_fill = unsigned_fill.with_chain(
chain_id,
self.constants
.system()
.orders_for(chain_id)
.ok_or(eyre!("invalid target chain id {}", chain_id))?,
);
Expand Down
12 changes: 8 additions & 4 deletions crates/rpc/examples/order.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use alloy::{
};
use chrono::Utc;
use eyre::Error;
use signet_constants::SignetSystemConstants;
use signet_constants::SignetConstants;
use signet_tx_cache::client::TxCache;
use signet_types::UnsignedOrder;
use signet_zenith::RollupOrders::{Input, Order, Output};
Expand All @@ -19,16 +19,20 @@ pub struct SendOrder<S: Signer> {
/// The transaction cache endpoint.
tx_cache: TxCache,
/// The system constants.
constants: SignetSystemConstants,
constants: SignetConstants,
}

impl<S> SendOrder<S>
where
S: Signer,
{
/// Create a new SendOrder instance.
pub const fn new(signer: S, tx_cache: TxCache, constants: SignetSystemConstants) -> Self {
Self { signer, tx_cache, constants }
pub fn new(signer: S, constants: SignetConstants) -> Result<Self, Error> {
Ok(Self {
signer,
tx_cache: TxCache::new_from_string(constants.environment().transaction_cache())?,
constants,
})
}

/// Construct a simple example Order, sign it, and send it.
Expand Down
2 changes: 1 addition & 1 deletion crates/sim/tests/basic_sim.rs
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ pub async fn test_simulator() {
// Set up the simulator
let built = BlockBuild::<_, NoOpInspector>::new(
db,
TEST_CONSTANTS,
TEST_SYS,
TestCfg,
NoopBlock,
std::time::Instant::now() + std::time::Duration::from_millis(200),
Expand Down
1 change: 1 addition & 0 deletions crates/tx-cache/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ repository.workspace = true
[dependencies]
signet-bundle.workspace = true
signet-types.workspace = true
signet-constants.workspace = true

alloy.workspace = true

Expand Down
Loading
Loading