Skip to content

Commit

Permalink
Merge pull request #2257 from jacderida/feat-arbitrum_sepolia
Browse files Browse the repository at this point in the history
feat: support the arbitrum sepolia network
  • Loading branch information
jacderida authored Oct 16, 2024
2 parents b5b2efa + ca37ff7 commit edc02c5
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 0 deletions.
18 changes: 18 additions & 0 deletions evmlib/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,13 +33,25 @@ static PUBLIC_ARBITRUM_ONE_HTTP_RPC_URL: LazyLock<reqwest::Url> = LazyLock::new(
.expect("Invalid RPC URL")
});

static PUBLIC_ARBITRUM_SEPOLIA_HTTP_RPC_URL: LazyLock<reqwest::Url> = LazyLock::new(|| {
"https://sepolia-rollup.arbitrum.io/rpc"
.parse()
.expect("Invalid RPC URL")
});

const ARBITRUM_ONE_PAYMENT_TOKEN_ADDRESS: Address =
address!("4bc1aCE0E66170375462cB4E6Af42Ad4D5EC689C");

const ARBITRUM_SEPOLIA_PAYMENT_TOKEN_ADDRESS: Address =
address!("4bc1aCE0E66170375462cB4E6Af42Ad4D5EC689C");

// Should be updated when the smart contract changes!
const ARBITRUM_ONE_DATA_PAYMENTS_ADDRESS: Address =
address!("887930F30EDEb1B255Cd2273C3F4400919df2EFe");

const ARBITRUM_SEPOLIA_DATA_PAYMENTS_ADDRESS: Address =
address!("e6D6bB5Fa796baA8c1ADc439Ac0fd66fd2A1858b");

#[serde_as]
#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
pub struct CustomNetwork {
Expand All @@ -64,13 +76,15 @@ impl CustomNetwork {
#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
pub enum Network {
ArbitrumOne,
ArbitrumSepolia,
Custom(CustomNetwork),
}

impl std::fmt::Display for Network {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
match self {
Network::ArbitrumOne => write!(f, "evm-arbitrum-one"),
Network::ArbitrumSepolia => write!(f, "evm-arbitrum-sepolia"),
Network::Custom(_) => write!(f, "evm-custom"),
}
}
Expand All @@ -88,27 +102,31 @@ impl Network {
pub fn identifier(&self) -> &str {
match self {
Network::ArbitrumOne => "arbitrum-one",
Network::ArbitrumSepolia => "arbitrum-sepolia",
Network::Custom(_) => "custom",
}
}

pub fn rpc_url(&self) -> &reqwest::Url {
match self {
Network::ArbitrumOne => &PUBLIC_ARBITRUM_ONE_HTTP_RPC_URL,
Network::ArbitrumSepolia => &PUBLIC_ARBITRUM_SEPOLIA_HTTP_RPC_URL,
Network::Custom(custom) => &custom.rpc_url_http,
}
}

pub fn payment_token_address(&self) -> &Address {
match self {
Network::ArbitrumOne => &ARBITRUM_ONE_PAYMENT_TOKEN_ADDRESS,
Network::ArbitrumSepolia => &ARBITRUM_SEPOLIA_PAYMENT_TOKEN_ADDRESS,
Network::Custom(custom) => &custom.payment_token_address,
}
}

pub fn data_payments_address(&self) -> &Address {
match self {
Network::ArbitrumOne => &ARBITRUM_ONE_DATA_PAYMENTS_ADDRESS,
Network::ArbitrumSepolia => &ARBITRUM_SEPOLIA_DATA_PAYMENTS_ADDRESS,
Network::Custom(custom) => &custom.data_payments_address,
}
}
Expand Down
7 changes: 7 additions & 0 deletions evmlib/src/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -88,11 +88,18 @@ pub fn get_evm_network_from_env() -> Result<Network, Error> {
.map(|v| v == "arbitrum-one")
.unwrap_or(false);

let use_arbitrum_sepolia = std::env::var("EVM_NETWORK")
.map(|v| v == "arbitrum-sepolia")
.unwrap_or(false);

if use_local_evm {
local_evm_network_from_csv()
} else if use_arbitrum_one {
info!("Using Arbitrum One EVM network as EVM_NETWORK is set to 'arbitrum-one'");
Ok(Network::ArbitrumOne)
} else if use_arbitrum_sepolia {
info!("Using Arbitrum Sepolia EVM network as EVM_NETWORK is set to 'arbitrum-sepolia'");
Ok(Network::ArbitrumSepolia)
} else if let Ok(evm_vars) = evm_vars {
info!("Using custom EVM network from environment variables");
Ok(Network::Custom(CustomNetwork::new(
Expand Down
5 changes: 5 additions & 0 deletions sn_node/src/bin/safenode/subcommands.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,14 @@ use clap::Subcommand;
use sn_evm::EvmNetwork;

#[derive(Subcommand, Clone, Debug)]
#[allow(clippy::enum_variant_names)]
pub(crate) enum EvmNetworkCommand {
/// Use the Arbitrum One network
EvmArbitrumOne,

/// Use the Arbitrum Sepolia network
EvmArbitrumSepolia,

/// Use a custom network
EvmCustom {
/// The RPC URL for the custom network
Expand All @@ -27,6 +31,7 @@ impl Into<EvmNetwork> for EvmNetworkCommand {
fn into(self) -> EvmNetwork {
match self {
Self::EvmArbitrumOne => EvmNetwork::ArbitrumOne,
Self::EvmArbitrumSepolia => EvmNetwork::ArbitrumSepolia,
Self::EvmCustom {
rpc_url,
payment_token_address,
Expand Down
4 changes: 4 additions & 0 deletions sn_node_manager/src/bin/cli/subcommands/evm_network.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@ pub enum EvmNetworkCommand {
/// Use the Arbitrum One network
EvmArbitrumOne,

/// Use the Arbitrum Sepolia network
EvmArbitrumSepolia,

/// Use a custom network
EvmCustom {
/// The RPC URL for the custom network
Expand All @@ -41,6 +44,7 @@ impl TryInto<EvmNetwork> for EvmNetworkCommand {
fn try_into(self) -> Result<EvmNetwork> {
match self {
Self::EvmArbitrumOne => Ok(EvmNetwork::ArbitrumOne),
Self::EvmArbitrumSepolia => Ok(EvmNetwork::ArbitrumSepolia),
Self::EvmLocal => {
if !cfg!(feature = "local") {
return Err(color_eyre::eyre::eyre!(
Expand Down

0 comments on commit edc02c5

Please sign in to comment.