From 7ddb0fd5daefdc8e6ac0622c3fe96cc0e667c668 Mon Sep 17 00:00:00 2001 From: Jonathan LEI Date: Tue, 19 Dec 2023 11:21:35 +0000 Subject: [PATCH] feat: add sepolia network --- book/src/providers.md | 1 + src/casm.rs | 4 +++- src/network.rs | 17 +++++++++++++++-- src/provider.rs | 8 +++++++- 4 files changed, 26 insertions(+), 4 deletions(-) diff --git a/book/src/providers.md b/book/src/providers.md index b9e8db3..b214661 100644 --- a/book/src/providers.md +++ b/book/src/providers.md @@ -59,6 +59,7 @@ To use the sequencer gateway anyways, use the `--network ` option, wher - `mainnet` - `goerli` +- `sepolia` - `integration` For example, to check the latest block number on `mainnet`: diff --git a/src/casm.rs b/src/casm.rs index 00b70b7..33a288a 100644 --- a/src/casm.rs +++ b/src/casm.rs @@ -73,7 +73,9 @@ impl CasmArgs { Some(network) => { let auto_version = match network { Network::Mainnet => CompilerVersion::V2_1_0, - Network::Goerli | Network::Integration => CompilerVersion::V2_4_0, + Network::Goerli | Network::Sepolia | Network::Integration => { + CompilerVersion::V2_4_0 + } }; eprintln!( diff --git a/src/network.rs b/src/network.rs index 22dfeba..cbb9680 100644 --- a/src/network.rs +++ b/src/network.rs @@ -4,7 +4,7 @@ use anyhow::Result; use async_trait::async_trait; use auto_impl::auto_impl; use clap::{builder::PossibleValue, ValueEnum}; -use starknet::providers::Provider; +use starknet::{macros::short_string, providers::Provider}; use crate::provider::ExtendedProvider; @@ -12,6 +12,7 @@ use crate::provider::ExtendedProvider; pub enum Network { Mainnet, Goerli, + Sepolia, Integration, } @@ -24,7 +25,12 @@ pub trait NetworkSource { impl ValueEnum for Network { fn value_variants<'a>() -> &'a [Self] { - &[Self::Mainnet, Self::Goerli, Self::Integration] + &[ + Self::Mainnet, + Self::Goerli, + Self::Sepolia, + Self::Integration, + ] } fn to_possible_value(&self) -> Option { @@ -37,6 +43,9 @@ impl ValueEnum for Network { "alpha-goerli1", "alpha-goerli-1", ])), + Network::Sepolia => { + Some(PossibleValue::new("sepolia").aliases(["alpha-sepolia", "sepolia-testnet"])) + } Network::Integration => Some(PossibleValue::new("integration")), } } @@ -50,6 +59,7 @@ impl FromStr for Network { "mainnet" | "alpha-mainnet" => Ok(Self::Mainnet), "goerli" | "goerli1" | "goerli-1" | "alpha-goerli" | "alpha-goerli1" | "alpha-goerli-1" => Ok(Self::Goerli), + "sepolia" | "alpha-sepolia" | "sepolia-testnet" => Ok(Self::Sepolia), "integration" => Ok(Self::Integration), _ => Err(anyhow::anyhow!("unknown network: {}", s)), } @@ -61,6 +71,7 @@ impl Display for Network { match self { Self::Mainnet => write!(f, "mainnet"), Self::Goerli => write!(f, "goerli"), + Self::Sepolia => write!(f, "sepolia"), Self::Integration => write!(f, "integration"), } } @@ -83,6 +94,8 @@ impl NetworkSource for ExtendedProvider { Some(Network::Mainnet) } else if chain_id == starknet::core::chain_id::TESTNET { Some(Network::Goerli) + } else if chain_id == short_string!("SN_SEPOLIA") { + Some(Network::Sepolia) } else { None }) diff --git a/src/provider.rs b/src/provider.rs index d02eb12..ed53b83 100644 --- a/src/provider.rs +++ b/src/provider.rs @@ -4,6 +4,7 @@ use clap::Parser; use colored::Colorize; use starknet::{ core::{chain_id, types::*}, + macros::short_string, providers::{ jsonrpc::HttpTransport, AnyProvider, JsonRpcClient, Provider, ProviderError, SequencerGatewayProvider, @@ -68,6 +69,11 @@ impl ProviderArgs { AnyProvider::SequencerGateway(match network { Network::Mainnet => SequencerGatewayProvider::starknet_alpha_mainnet(), Network::Goerli => SequencerGatewayProvider::starknet_alpha_goerli(), + Network::Sepolia => SequencerGatewayProvider::new( + Url::parse("https://alpha-sepolia.starknet.io/gateway").unwrap(), + Url::parse("https://alpha-sepolia.starknet.io/feeder_gateway").unwrap(), + short_string!("SN_SEPOLIA"), + ), Network::Integration => SequencerGatewayProvider::new( Url::parse("https://external.integration.starknet.io/gateway").unwrap(), Url::parse("https://external.integration.starknet.io/feeder_gateway") @@ -76,7 +82,7 @@ impl ProviderArgs { ), }), match network { - Network::Mainnet | Network::Goerli => false, + Network::Mainnet | Network::Goerli | Network::Sepolia => false, Network::Integration => true, }, )