Skip to content

Commit

Permalink
feat: add sepolia network
Browse files Browse the repository at this point in the history
  • Loading branch information
xJonathanLEI committed Dec 19, 2023
1 parent 426ef54 commit 7ddb0fd
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 4 deletions.
1 change: 1 addition & 0 deletions book/src/providers.md
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ To use the sequencer gateway anyways, use the `--network <NETWORK>` option, wher
- `mainnet`
- `goerli`
- `sepolia`
- `integration`
For example, to check the latest block number on `mainnet`:
Expand Down
4 changes: 3 additions & 1 deletion src/casm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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!(
Expand Down
17 changes: 15 additions & 2 deletions src/network.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,15 @@ 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;

#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum Network {
Mainnet,
Goerli,
Sepolia,
Integration,
}

Expand All @@ -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<PossibleValue> {
Expand All @@ -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")),
}
}
Expand All @@ -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)),
}
Expand All @@ -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"),
}
}
Expand All @@ -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
})
Expand Down
8 changes: 7 additions & 1 deletion src/provider.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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")
Expand All @@ -76,7 +82,7 @@ impl ProviderArgs {
),
}),
match network {
Network::Mainnet | Network::Goerli => false,
Network::Mainnet | Network::Goerli | Network::Sepolia => false,
Network::Integration => true,
},
)
Expand Down

0 comments on commit 7ddb0fd

Please sign in to comment.