Skip to content

Commit

Permalink
erc20: add Sepolia Ethereum testnet
Browse files Browse the repository at this point in the history
  • Loading branch information
kamirr committed Aug 8, 2024
1 parent 9ab634a commit 2a28d5f
Show file tree
Hide file tree
Showing 7 changed files with 110 additions and 21 deletions.
4 changes: 3 additions & 1 deletion core/model/src/payment.rs
Original file line number Diff line number Diff line change
Expand Up @@ -559,6 +559,8 @@ pub mod local {
#[strum(props(token = "GLM"))]
Mainnet,
#[strum(props(token = "tGLM"))]
Sepolia,
#[strum(props(token = "tGLM"))]
Rinkeby,
#[strum(props(token = "tGLM"))]
Goerli,
Expand Down Expand Up @@ -587,7 +589,7 @@ pub mod local {
impl NetworkName {
pub fn is_fundable(&self) -> bool {
use NetworkName::*;
matches!(self, Goerli | Holesky | Amoy)
matches!(self, Sepolia | Goerli | Holesky | Amoy)
}

pub fn all_fundable() -> Vec<NetworkName> {
Expand Down
15 changes: 9 additions & 6 deletions core/payment-driver/base/src/db/models.rs
Original file line number Diff line number Diff line change
Expand Up @@ -112,14 +112,15 @@ pub struct PaymentEntity {
)]
#[sql_type = "Integer"]
pub enum Network {
Mainnet = 1, //Main Ethereum chain
Rinkeby = 4, //Rinkeby is Ethereum testnet
Goerli = 5, //Goerli is another Ethereum testnet
Mainnet = 1, //Main Ethereum chain
Rinkeby = 4, //Rinkeby is an Ethereum testnet
Goerli = 5, //Goerli is an Ethereum testnet
Sepolia = 11155111, //Sepolia is an Ethereum testnet
#[default]
Holesky = 17000, //Holesky is testnet for Holesky network
Polygon = 137, //Polygon is Polygon production network
Mumbai = 80001, //Mumbai is the legacy testnet for Polygon network
Amoy = 80002, //Amoy is the new testnet for Polygon network
Polygon = 137, //Polygon is Polygon production network
Mumbai = 80001, //Mumbai is the legacy testnet for Polygon network
Amoy = 80002, //Amoy is the new testnet for Polygon network
}

impl FromStr for Network {
Expand All @@ -128,6 +129,7 @@ impl FromStr for Network {
fn from_str(s: &str) -> DbResult<Self> {
match s.to_lowercase().as_str() {
"mainnet" => Ok(Network::Mainnet),
"sepolia" => Ok(Network::Sepolia),
"rinkeby" => Ok(Network::Rinkeby),
"goerli" => Ok(Network::Goerli),
"holesky" => Ok(Network::Holesky),
Expand All @@ -143,6 +145,7 @@ impl Display for Network {
fn fmt(&self, f: &mut Formatter<'_>) -> FmtResult {
match *self {
Network::Mainnet => f.write_str("mainnet"),
Network::Sepolia => f.write_str("sepolia"),
Network::Rinkeby => f.write_str("rinkeby"),
Network::Goerli => f.write_str("goerli"),
Network::Holesky => f.write_str("holesky"),
Expand Down
38 changes: 38 additions & 0 deletions core/payment-driver/erc20/config-payments.toml
Original file line number Diff line number Diff line change
Expand Up @@ -188,3 +188,41 @@ endpoints = """
-max-timeout-ms = 5000
-verify-interval-secs = 300
-allowed-head-behind-secs = 60

[chain.sepolia]
chain-name = "Sepolia"
chain-id = 11155111
currency-symbol = "tETH"
priority-fee = 0.000001
max-fee-per-gas = 20.0
transaction-timeout = 100
token = { address = "0x167b15ada84c63427c6c813B915a42eFC72E7175", symbol = "tGLM" }
mint-contract = { address = "0x31A2a20956a40c2F358Fa5cec59D55a9C5d6fF9A", max-glm-allowed = 400 }
attestation-contract = { address = "0xC2679fBD37d54388Ce493F1DB75320D236e1815e" }
schema-registry-contract = { address = "0x0a7E2Ff54e76B8E6659aedc9103FB21c038050D0" }
confirmation-blocks = 0
block-explorer-url = "https://sepolia.etherscan.io"
external-source-check-interval = 300

[[chain.sepolia.rpc-endpoints]]
names = """
endpoints.omniatech.io/v1/eth/sepolia/public
ethereum-sepolia.blockpi.network/v1/rpc/public
eth-sepolia.public.blastapi.io
eth-sepolia-public.unifra.io
sepolia.gateway.tenderly.co
gateway.tenderly.co/public/sepolia
"""

endpoints = """
https://endpoints.omniatech.io/v1/eth/sepolia/public
https://ethereum-sepolia.blockpi.network/v1/rpc/public
https://eth-sepolia.public.blastapi.io
https://eth-sepolia-public.unifra.io
https://sepolia.gateway.tenderly.co
https://gateway.tenderly.co/public/sepolia
"""
priority = 0
max-timeout-ms = 5000
verify-interval-secs = 60
allowed-head-behind-secs = 120
52 changes: 39 additions & 13 deletions core/payment-driver/erc20/src/erc20/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,20 @@ pub struct EnvConfiguration {
}

lazy_static! {
pub static ref MAINNET_CONFIG: EnvConfiguration = EnvConfiguration {
glm_contract_address: utils::str_to_addr(
&env::var("MAINNET_GLM_CONTRACT_ADDRESS")
.unwrap_or_else(|_| "0x7DD9c5Cba05E151C895FDe1CF355C9A1D5DA6429".to_string())
)
.unwrap(),
glm_faucet_address: None,
required_confirmations: {
match env::var("ERC20_MAINNET_REQUIRED_CONFIRMATIONS").map(|s| s.parse()) {
Ok(Ok(x)) => x,
_ => 5,
}
}
};
pub static ref RINKEBY_CONFIG: EnvConfiguration = EnvConfiguration {
glm_contract_address: utils::str_to_addr(
&env::var("RINKEBY_TGLM_CONTRACT_ADDRESS")
Expand All @@ -40,35 +54,41 @@ lazy_static! {
}
}
};
pub static ref MAINNET_CONFIG: EnvConfiguration = EnvConfiguration {
pub static ref GOERLI_CONFIG: EnvConfiguration = EnvConfiguration {
glm_contract_address: utils::str_to_addr(
&env::var("MAINNET_GLM_CONTRACT_ADDRESS")
.unwrap_or_else(|_| "0x7DD9c5Cba05E151C895FDe1CF355C9A1D5DA6429".to_string())
&env::var("GOERLI_TGLM_CONTRACT_ADDRESS")
.unwrap_or_else(|_| "0x33af15c79d64b85ba14aaffaa4577949104b22e8".to_string())
)
.unwrap(),
glm_faucet_address: None,
glm_faucet_address: Some(
utils::str_to_addr(
&env::var("GOERLI_TGLM_FAUCET_ADDRESS")
.unwrap_or_else(|_| "0xCCA41b09C1F50320bFB41BD6822BD0cdBDC7d85C".to_string())
)
.unwrap()
),
required_confirmations: {
match env::var("ERC20_MAINNET_REQUIRED_CONFIRMATIONS").map(|s| s.parse()) {
match env::var("ERC20_GOERLI_REQUIRED_CONFIRMATIONS").map(|s| s.parse()) {
Ok(Ok(x)) => x,
_ => 5,
_ => 3,
}
}
};
pub static ref GOERLI_CONFIG: EnvConfiguration = EnvConfiguration {
pub static ref SEPOLIA_CONFIG: EnvConfiguration = EnvConfiguration {
glm_contract_address: utils::str_to_addr(
&env::var("GOERLI_TGLM_CONTRACT_ADDRESS")
.unwrap_or_else(|_| "0x33af15c79d64b85ba14aaffaa4577949104b22e8".to_string())
&env::var("SEPOLIA_TGLM_CONTRACT_ADDRESS")
.unwrap_or_else(|_| "0x167b15ada84c63427c6c813B915a42eFC72E7175".to_string())
)
.unwrap(),
glm_faucet_address: Some(
utils::str_to_addr(
&env::var("GOERLI_TGLM_FAUCET_ADDRESS")
.unwrap_or_else(|_| "0xCCA41b09C1F50320bFB41BD6822BD0cdBDC7d85C".to_string())
&env::var("SEPOLIA_TGLM_FAUCET_ADDRESS")
.unwrap_or_else(|_| "0x31A2a20956a40c2F358Fa5cec59D55a9C5d6fF9A".to_string())
)
.unwrap()
),
required_confirmations: {
match env::var("ERC20_GOERLI_REQUIRED_CONFIRMATIONS").map(|s| s.parse()) {
match env::var("ERC20_SEPOLIA_REQUIRED_CONFIRMATIONS").map(|s| s.parse()) {
Ok(Ok(x)) => x,
_ => 3,
}
Expand Down Expand Up @@ -114,7 +134,13 @@ lazy_static! {
.unwrap_or_else(|_| "0x2b60e60d3fb0b36a7ccb388f9e71570da4c4594f".to_string())
)
.unwrap(),
glm_faucet_address: None,
glm_faucet_address: Some(
utils::str_to_addr(
&env::var("AMOY_TGLM_FAUCET_ADDRESS")
.unwrap_or_else(|_| "0xf29ff8a13211ac33861986e407190ae5c773d53c".to_string())
)
.unwrap()
),
required_confirmations: {
match env::var("ERC20_AMOY_REQUIRED_CONFIRMATIONS").map(|s| s.parse()) {
Ok(Ok(x)) => x,
Expand Down
5 changes: 5 additions & 0 deletions core/payment-driver/erc20/src/erc20/ethereum.rs
Original file line number Diff line number Diff line change
Expand Up @@ -530,6 +530,10 @@ fn get_rpc_addr_from_env(network: Network) -> Vec<String> {
Network::Mainnet => {
collect_rpc_addr_from("MAINNET_GETH_ADDR", "https://geth.golem.network:55555")
}
Network::Sepolia => collect_rpc_addr_from(
"SEPOLIA_GETH_ADDR",
"https://ethereum-sepolia.blockpi.network/v1/rpc/public",
),
Network::Rinkeby => collect_rpc_addr_from(
"RINKEBY_GETH_ADDR",
"http://geth.testnet.golem.network:55555",
Expand Down Expand Up @@ -598,6 +602,7 @@ fn get_env(network: Network) -> config::EnvConfiguration {
Network::Mainnet => *config::MAINNET_CONFIG,
Network::Rinkeby => *config::RINKEBY_CONFIG,
Network::Goerli => *config::GOERLI_CONFIG,
Network::Sepolia => *config::SEPOLIA_CONFIG,
Network::Holesky => *config::HOLESKY_CONFIG,
Network::Mumbai => *config::MUMBAI_CONFIG,
Network::Polygon => *config::POLYGON_MAINNET_CONFIG,
Expand Down
6 changes: 6 additions & 0 deletions core/payment-driver/erc20/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,12 @@ pub const AMOY_PLATFORM: &str = "erc20-amoy-tglm";
pub const AMOY_CURRENCY_SHORT: &str = "tMATIC";
pub const AMOY_CURRENCY_LONG: &str = "Test MATIC";

pub const SEPOLIA_NETWORK: &str = "sepolia";
pub const SEPOLIA_TOKEN: &str = "tGLM";
pub const SEPOLIA_PLATFORM: &str = "erc20-sepolia-tglm";
pub const SEPOLIA_CURRENCY_SHORT: &str = "tETH";
pub const SEPOLIA_CURRENCY_LONG: &str = "Sepolia Ether";

pub const MAINNET_NETWORK: &str = "mainnet";
pub const MAINNET_TOKEN: &str = "GLM";
pub const MAINNET_PLATFORM: &str = "erc20-mainnet-glm";
Expand Down
11 changes: 10 additions & 1 deletion core/payment-driver/erc20/src/network.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@ use crate::{
MUMBAI_PLATFORM, MUMBAI_TOKEN, POLYGON_MAINNET_CURRENCY_LONG, POLYGON_MAINNET_CURRENCY_SHORT,
POLYGON_MAINNET_NETWORK, POLYGON_MAINNET_PLATFORM, POLYGON_MAINNET_TOKEN,
RINKEBY_CURRENCY_LONG, RINKEBY_CURRENCY_SHORT, RINKEBY_NETWORK, RINKEBY_PLATFORM,
RINKEBY_TOKEN,
RINKEBY_TOKEN, SEPOLIA_CURRENCY_LONG, SEPOLIA_CURRENCY_SHORT, SEPOLIA_NETWORK,
SEPOLIA_PLATFORM, SEPOLIA_TOKEN,
};

lazy_static::lazy_static! {
Expand All @@ -38,6 +39,10 @@ lazy_static::lazy_static! {
HOLESKY_TOKEN.to_string() => HOLESKY_PLATFORM.to_string()
}
},
SEPOLIA_NETWORK.to_string() => Network {
default_token: SEPOLIA_TOKEN.to_string(),
tokens: hashmap! {SEPOLIA_TOKEN.to_string() => SEPOLIA_PLATFORM.to_string()}
},
MAINNET_NETWORK.to_string() => Network {
default_token: MAINNET_TOKEN.to_string(),
tokens: hashmap! {
Expand Down Expand Up @@ -105,6 +110,10 @@ pub fn platform_to_currency(platform: String) -> Result<(String, String), Generi
HOLESKY_CURRENCY_SHORT.to_owned(),
HOLESKY_CURRENCY_LONG.to_owned(),
)),
SEPOLIA_PLATFORM => Ok((
SEPOLIA_CURRENCY_SHORT.to_owned(),
SEPOLIA_CURRENCY_LONG.to_string(),
)),
MAINNET_PLATFORM => Ok((
MAINNET_CURRENCY_SHORT.to_owned(),
MAINNET_CURRENCY_LONG.to_owned(),
Expand Down

0 comments on commit 2a28d5f

Please sign in to comment.