Skip to content

Commit

Permalink
erc20: add Amoy polygon testnet
Browse files Browse the repository at this point in the history
  • Loading branch information
kamirr committed Aug 8, 2024
1 parent 901a11f commit a42c71d
Show file tree
Hide file tree
Showing 8 changed files with 73 additions and 3 deletions.
1 change: 1 addition & 0 deletions .env-template
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ YAGNA_DATADIR="."
#HOLESKY_GETH_ADDR=https://rpc.ankr.com/eth_holesky
#POLYGON_GETH_ADDR=https://bor.golem.network,https://polygon-rpc.com
#MUMBAI_GETH_ADDR=https://matic-mumbai.chainstacklabs.com
#AMOY_GETH_ADDR=https://rpc-amoy.polygon.technology

## T/GLM contract addresses
#HOLESKY_TGLM_CONTRACT_ADDRESS=0xd94e3DC39d4Cad1DAd634e7eb585A57A19dC7EFE
Expand Down
4 changes: 3 additions & 1 deletion core/model/src/payment.rs
Original file line number Diff line number Diff line change
Expand Up @@ -568,6 +568,8 @@ pub mod local {
Polygon,
#[strum(props(token = "tGLM"))]
Mumbai,
#[strum(props(token = "tGLM"))]
Amoy,
}

impl NetworkName {
Expand All @@ -585,7 +587,7 @@ pub mod local {
impl NetworkName {
pub fn is_fundable(&self) -> bool {
use NetworkName::*;
matches!(self, Goerli | Holesky)
matches!(self, Goerli | Holesky | Amoy)
}

pub fn all_fundable() -> Vec<NetworkName> {
Expand Down
7 changes: 5 additions & 2 deletions core/payment-driver/base/src/db/models.rs
Original file line number Diff line number Diff line change
Expand Up @@ -117,8 +117,9 @@ pub enum Network {
Goerli = 5, //Goerli is another Ethereum testnet
#[default]
Holesky = 17000, //Holesky is testnet for Holesky network
Mumbai = 80001, //Mumbai is 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 @@ -132,6 +133,7 @@ impl FromStr for Network {
"holesky" => Ok(Network::Holesky),
"polygon" => Ok(Network::Polygon),
"mumbai" => Ok(Network::Mumbai),
"amoy" => Ok(Network::Amoy),
_ => Err(DbError::InvalidData(format!("Invalid network: {}", s))),
}
}
Expand All @@ -144,8 +146,9 @@ impl Display for Network {
Network::Rinkeby => f.write_str("rinkeby"),
Network::Goerli => f.write_str("goerli"),
Network::Holesky => f.write_str("holesky"),
Network::Mumbai => f.write_str("mumbai"),
Network::Polygon => f.write_str("polygon"),
Network::Mumbai => f.write_str("mumbai"),
Network::Amoy => f.write_str("amoy"),
}
}
}
Expand Down
27 changes: 27 additions & 0 deletions core/payment-driver/erc20/config-payments.toml
Original file line number Diff line number Diff line change
Expand Up @@ -161,3 +161,30 @@ max-timeout-ms = 5000
verify-interval-secs = 300
allowed-head-behind-secs = 60
dns-source = "polygon.rpc-node.dev.golem.network."

[chain.amoy]
chain-name = "Amoy testnet"
chain-id = 80002
currency-symbol = "tMATIC"
priority-fee = 30.111
max-fee-per-gas = 500.0
transaction-timeout = 100
token = { address = "0x2b60e60d3fb0b36a7ccb388f9e71570da4c4594f", symbol = "tGLM" }
mint-contract = { address = "0xf29ff8a13211ac33861986e407190ae5c773d53c", max-glm-allowed = 400 }
wrapper-contract = { address = "0xa7b4447c1447edeb40ebbb1943e90b169ff44560" }
multi-contract = { address = "0xa0a51642a594763d78091bf03ee6bf8e8d663bba", max-at-once = 10 }
confirmation-blocks = 1
block-explorer-url = "https://amoy.polygonscan.com"
external-source-check-interval = 300

[[chain.amoy.rpc-endpoints]]
names = """
rpc-amoy.polygon.technology,
"""
endpoints = """
https://rpc-amoy.polygon.technology,
"""
-priority = 0
-max-timeout-ms = 5000
-verify-interval-secs = 300
-allowed-head-behind-secs = 60
14 changes: 14 additions & 0 deletions core/payment-driver/erc20/src/erc20/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,20 @@ lazy_static! {
}
}
};
pub static ref AMOY_CONFIG: EnvConfiguration = EnvConfiguration {
glm_contract_address: utils::str_to_addr(
&env::var("AMOY_TGLM_CONTRACT_ADDRESS")
.unwrap_or_else(|_| "0x2b60e60d3fb0b36a7ccb388f9e71570da4c4594f".to_string())
)
.unwrap(),
glm_faucet_address: None,
required_confirmations: {
match env::var("ERC20_AMOY_REQUIRED_CONFIRMATIONS").map(|s| s.parse()) {
Ok(Ok(x)) => x,
_ => 3,
}
}
};
pub static ref POLYGON_MAINNET_CONFIG: EnvConfiguration = EnvConfiguration {
glm_contract_address: utils::str_to_addr(
&env::var("POLYGON_GLM_CONTRACT_ADDRESS")
Expand Down
4 changes: 4 additions & 0 deletions core/payment-driver/erc20/src/erc20/ethereum.rs
Original file line number Diff line number Diff line change
Expand Up @@ -549,6 +549,9 @@ fn get_rpc_addr_from_env(network: Network) -> Vec<String> {
"MUMBAI_GETH_ADDR",
"https://matic-mumbai.chainstacklabs.com",
),
Network::Amoy => {
collect_rpc_addr_from("AMOY_GETH_ADDR", "https://rpc-amoy.polygon.technology")
}
}
}

Expand Down Expand Up @@ -598,6 +601,7 @@ fn get_env(network: Network) -> config::EnvConfiguration {
Network::Holesky => *config::HOLESKY_CONFIG,
Network::Mumbai => *config::MUMBAI_CONFIG,
Network::Polygon => *config::POLYGON_MAINNET_CONFIG,
Network::Amoy => *config::AMOY_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 @@ -31,6 +31,12 @@ pub const MUMBAI_PLATFORM: &str = "erc20-mumbai-tglm";
pub const MUMBAI_CURRENCY_SHORT: &str = "tMATIC";
pub const MUMBAI_CURRENCY_LONG: &str = "Test MATIC";

pub const AMOY_NETWORK: &str = "amoy";
pub const AMOY_TOKEN: &str = "tGLM";
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 MAINNET_NETWORK: &str = "mainnet";
pub const MAINNET_TOKEN: &str = "GLM";
pub const MAINNET_PLATFORM: &str = "erc20-mainnet-glm";
Expand Down
13 changes: 13 additions & 0 deletions core/payment-driver/erc20/src/network.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ use ya_payment_driver::{db::models::Network as DbNetwork, driver::Network, model

// Local uses
use crate::{
AMOY_CURRENCY_LONG, AMOY_CURRENCY_SHORT, AMOY_NETWORK, AMOY_PLATFORM, AMOY_TOKEN,
GOERLI_CURRENCY_LONG, GOERLI_CURRENCY_SHORT, GOERLI_NETWORK, GOERLI_PLATFORM, GOERLI_TOKEN,
HOLESKY_CURRENCY_LONG, HOLESKY_CURRENCY_SHORT, HOLESKY_NETWORK, HOLESKY_PLATFORM,
HOLESKY_TOKEN, MAINNET_CURRENCY_LONG, MAINNET_CURRENCY_SHORT, MAINNET_NETWORK,
Expand Down Expand Up @@ -49,6 +50,12 @@ lazy_static::lazy_static! {
MUMBAI_TOKEN.to_string() => MUMBAI_PLATFORM.to_string()
}
},
AMOY_NETWORK.to_string() => Network {
default_token: AMOY_TOKEN.to_string(),
tokens: hashmap! {
AMOY_TOKEN.to_string() => AMOY_PLATFORM.to_string()
}
},
POLYGON_MAINNET_NETWORK.to_string() => Network {
default_token: POLYGON_MAINNET_TOKEN.to_string(),
tokens: hashmap! {
Expand All @@ -61,6 +68,7 @@ lazy_static::lazy_static! {
pub static ref HOLESKY_DB_NETWORK: DbNetwork = DbNetwork::from_str(HOLESKY_NETWORK).unwrap();
pub static ref MAINNET_DB_NETWORK: DbNetwork = DbNetwork::from_str(MAINNET_NETWORK).unwrap();
pub static ref MUMBAI_DB_NETWORK: DbNetwork = DbNetwork::from_str(MUMBAI_NETWORK).unwrap();
pub static ref AMOY_DB_NETWORK: DbNetwork = DbNetwork::from_str(AMOY_NETWORK).unwrap();
pub static ref POLYGON_MAINNET_DB_NETWORK: DbNetwork = DbNetwork::from_str(POLYGON_MAINNET_NETWORK).unwrap();
}

Expand All @@ -71,6 +79,7 @@ pub fn platform_to_network_token(platform: String) -> Result<(DbNetwork, String)
HOLESKY_PLATFORM => Ok((*HOLESKY_DB_NETWORK, HOLESKY_TOKEN.to_owned())),
MAINNET_PLATFORM => Ok((*MAINNET_DB_NETWORK, MAINNET_TOKEN.to_owned())),
MUMBAI_PLATFORM => Ok((*MUMBAI_DB_NETWORK, MUMBAI_TOKEN.to_owned())),
AMOY_PLATFORM => Ok((*AMOY_DB_NETWORK, AMOY_TOKEN.to_owned())),
POLYGON_MAINNET_PLATFORM => Ok((
*POLYGON_MAINNET_DB_NETWORK,
POLYGON_MAINNET_TOKEN.to_owned(),
Expand Down Expand Up @@ -104,6 +113,10 @@ pub fn platform_to_currency(platform: String) -> Result<(String, String), Generi
MUMBAI_CURRENCY_SHORT.to_owned(),
MUMBAI_CURRENCY_LONG.to_owned(),
)),
AMOY_PLATFORM => Ok((
AMOY_CURRENCY_SHORT.to_owned(),
AMOY_CURRENCY_LONG.to_owned(),
)),
POLYGON_MAINNET_PLATFORM => Ok((
POLYGON_MAINNET_CURRENCY_SHORT.to_owned(),
POLYGON_MAINNET_CURRENCY_LONG.to_owned(),
Expand Down

0 comments on commit a42c71d

Please sign in to comment.