Skip to content

Commit

Permalink
Add holesky
Browse files Browse the repository at this point in the history
  • Loading branch information
scx1332 authored Nov 24, 2023
1 parent 3f4582f commit 012a440
Show file tree
Hide file tree
Showing 16 changed files with 129 additions and 79 deletions.
1 change: 1 addition & 0 deletions .env-template
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ YAGNA_DATADIR="."
## Setting any of these variables will disable DNS lookup mechanism and use custom list of nodes instead for chosen network.
#MAINNET_GETH_ADDR=https://geth.golem.network:55555
#GOERLI_GETH_ADDR=https://rpc.ankr.com/eth_goerli
#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

Expand Down
1 change: 1 addition & 0 deletions agent/provider/src/provider_agent.rs
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,7 @@ impl ProviderAgent {
NetworkName::Rinkeby => yansi::Color::Cyan,
NetworkName::Mumbai => yansi::Color::Cyan,
NetworkName::Goerli => yansi::Color::Cyan,
NetworkName::Holesky => yansi::Color::Cyan,
_ => yansi::Color::Red,
};
log::info!("Using payment network: {}", net_color.paint(&n));
Expand Down
12 changes: 7 additions & 5 deletions core/model/src/payment.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ pub mod local {
use ya_client_model::NodeId;

pub const BUS_ID: &str = "/local/payment";
pub const DEFAULT_PAYMENT_DRIVER: &str = "erc20";
pub const DEFAULT_PAYMENT_DRIVER: &str = "erc20next";

#[derive(Clone, Debug, Serialize, Deserialize)]
pub struct DebitNotePayment {
Expand Down Expand Up @@ -488,6 +488,8 @@ pub mod local {
Rinkeby,
#[strum(props(token = "tGLM"))]
Goerli,
#[strum(props(token = "tGLM"))]
Holesky,
#[strum(props(token = "GLM"))]
Polygon,
#[strum(props(token = "tGLM"))]
Expand Down Expand Up @@ -521,10 +523,10 @@ pub mod local {
#[structopt(long, env = "YA_ACCOUNT")]
pub account: Option<NodeId>,
/// Payment driver
#[structopt(long, possible_values = DriverName::VARIANTS, default_value = DriverName::Erc20.into())]
#[structopt(long, possible_values = DriverName::VARIANTS, default_value = DriverName::Erc20Next.into())]
pub driver: DriverName,
/// Payment network
#[structopt(long, possible_values = NetworkName::VARIANTS, default_value = NetworkName::Goerli.into())]
#[structopt(long, possible_values = NetworkName::VARIANTS, default_value = NetworkName::Holesky.into())]
pub network: NetworkName,
}

Expand Down Expand Up @@ -554,8 +556,8 @@ pub mod local {
fn test_cli_defaults() {
let a = AccountCli::from_iter(&[""]);
assert_eq!(None, a.address());
assert_eq!("erc20", a.driver());
assert_eq!("goerli", a.network());
assert_eq!("erc20next", a.driver());
assert_eq!("holesky", a.network());
assert_eq!("tGLM", a.token());
}
}
Expand Down
4 changes: 4 additions & 0 deletions core/payment-driver/base/src/db/models.rs
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,7 @@ pub enum Network {
Rinkeby = 4, //Rinkeby is Ethereum testnet
#[default]
Goerli = 5, //Goerli is another Ethereum testnet
Holesky = 17000, //Holesky is testnet for Holesky network
Mumbai = 80001, //Mumbai is testnet for Polygon network
Polygon = 137, //Polygon is Polygon production network
}
Expand All @@ -128,6 +129,7 @@ impl FromStr for Network {
"mainnet" => Ok(Network::Mainnet),
"rinkeby" => Ok(Network::Rinkeby),
"goerli" => Ok(Network::Goerli),
"holesky" => Ok(Network::Holesky),
"polygon" => Ok(Network::Polygon),
"mumbai" => Ok(Network::Mumbai),
_ => Err(DbError::InvalidData(format!("Invalid network: {}", s))),
Expand All @@ -141,6 +143,7 @@ impl Display for Network {
Network::Mainnet => f.write_str("mainnet"),
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"),
}
Expand All @@ -167,6 +170,7 @@ where
4 => Network::Rinkeby,
5 => Network::Goerli,
137 => Network::Polygon,
17000 => Network::Holesky,
80001 => Network::Mumbai,
_ => return Err(anyhow::anyhow!("invalid value").into()),
})
Expand Down
1 change: 1 addition & 0 deletions core/payment-driver/erc20/Readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ Networks currently supported:
* mainnnet (ETH mainnet, do not use)
* rinkeby (ETH testnet, good support)
* goerli (ETH testnet)
* holesky (ETH testnet)
* mumbai (Polygon testnet)
* polygon (Polygon mainnet)

Expand Down
4 changes: 2 additions & 2 deletions core/payment-driver/erc20/src/driver.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ use ya_payment_driver::{
};

// Local uses
use crate::{dao::Erc20Dao, network::SUPPORTED_NETWORKS, DRIVER_NAME, GOERLI_NETWORK};
use crate::{dao::Erc20Dao, network::SUPPORTED_NETWORKS, DRIVER_NAME, HOLESKY_NETWORK};

mod api;
mod cli;
Expand Down Expand Up @@ -146,7 +146,7 @@ impl PaymentDriver for Erc20Driver {
}

fn get_default_network(&self) -> String {
GOERLI_NETWORK.to_string()
HOLESKY_NETWORK.to_string()
}

fn get_networks(&self) -> HashMap<String, NetworkConfig> {
Expand Down
3 changes: 2 additions & 1 deletion core/payment-driver/erc20/src/driver/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ pub async fn fund(dao: &Erc20Dao, msg: Fund) -> Result<String, GenericError> {
let address = msg.address();
let network = network::network_like_to_network(msg.network());
let result = match network {
Network::Rinkeby | Network::Goerli => {
Network::Rinkeby | Network::Goerli | Network::Holesky => {
let address = utils::str_to_addr(&address)?;
log::info!(
"Handling fund request. network={}, address={}",
Expand Down Expand Up @@ -154,6 +154,7 @@ pub async fn transfer(dao: &Erc20Dao, msg: Transfer) -> Result<String, GenericEr
Network::Polygon => "https://polygonscan.com/tx/",
Network::Mainnet => "https://etherscan.io/tx/",
Network::Rinkeby => "https://rinkeby.etherscan.io/tx/",
Network::Holesky => "https://holesky.etherscan.io/tx/",
Network::Goerli => "https://goerli.etherscan.io/tx/",
Network::Mumbai => "https://mumbai.polygonscan.com/tx/",
};
Expand Down
20 changes: 20 additions & 0 deletions core/payment-driver/erc20/src/erc20/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,26 @@ lazy_static! {
}
}
};
pub static ref HOLESKY_CONFIG: EnvConfiguration = EnvConfiguration {
glm_contract_address: utils::str_to_addr(
&env::var("HOLESKY_TGLM_CONTRACT_ADDRESS")
.unwrap_or_else(|_| "0x8888888815bf4DB87e57B609A50f938311EEd068".to_string())
)
.unwrap(),
glm_faucet_address: Some(
utils::str_to_addr(
&env::var("HOLESKY_TGLM_FAUCET_ADDRESS")
.unwrap_or_else(|_| "0xFACe100969FF47EB58d2CF603321B581A84bcEaC".to_string())
)
.unwrap()
),
required_confirmations: {
match env::var("ERC20_HOLESKY_REQUIRED_CONFIRMATIONS").map(|s| s.parse()) {
Ok(Ok(x)) => x,
_ => 3,
}
}
};
pub static ref MUMBAI_CONFIG: EnvConfiguration = EnvConfiguration {
glm_contract_address: utils::str_to_addr(
&env::var("MUMBAI_TGLM_CONTRACT_ADDRESS")
Expand Down
62 changes: 1 addition & 61 deletions core/payment-driver/erc20/src/erc20/ethereum.rs
Original file line number Diff line number Diff line change
Expand Up @@ -534,73 +534,13 @@ async fn get_tx_receipt_with(
.await
.map_err(Into::into)
}
/*
fn get_rpc_addr_from_env(network: Network) -> Vec<String> {
match network {
Network::Mainnet => {
collect_rpc_addr_from("MAINNET_GETH_ADDR", "https://geth.golem.network:55555")
}
Network::Rinkeby => collect_rpc_addr_from(
"RINKEBY_GETH_ADDR",
"http://geth.testnet.golem.network:55555",
),
Network::Goerli => {
collect_rpc_addr_from("GOERLI_GETH_ADDR", "https://rpc.ankr.com/eth_goerli")
}
Network::Polygon => collect_rpc_addr_from(
"POLYGON_GETH_ADDR",
"https://bor.golem.network,https://polygon-rpc.com",
),
Network::Mumbai => collect_rpc_addr_from(
"MUMBAI_GETH_ADDR",
"https://matic-mumbai.chainstacklabs.com",
),
}
}
fn collect_rpc_addr_from(env: &str, default: &str) -> Vec<String> {
std::env::var(env)
.ok()
.unwrap_or_else(|| default.to_string())
.split(',')
.map(|path| path.to_string())
.collect()
}
async fn get_clients(network: Network) -> Result<Vec<Web3<Http>>, GenericError> {
let geth_addrs = get_rpc_addr_from_env(network);
let mut clients: Vec<Web3<Http>> = Default::default();
for geth_addr in geth_addrs {
{
let client_map = WEB3_CLIENT_MAP.read().await;
if let Some(client) = client_map.get(&geth_addr).cloned() {
clients.push(client);
continue;
}
}
let transport = match web3::transports::Http::new(&geth_addr) {
Ok(t) => t,
Err(_) => continue,
};
let client = Web3::new(transport);

let mut client_map = WEB3_CLIENT_MAP.write().await;
client_map.insert(geth_addr, client.clone());
clients.push(client);
}
Ok(clients)
}
*/
fn get_env(network: Network) -> config::EnvConfiguration {
match network {
Network::Mainnet => *config::MAINNET_CONFIG,
Network::Rinkeby => *config::RINKEBY_CONFIG,
Network::Goerli => *config::GOERLI_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 @@ -19,6 +19,12 @@ pub const GOERLI_PLATFORM: &str = "erc20-goerli-tglm";
pub const GOERLI_CURRENCY_SHORT: &str = "tETH";
pub const GOERLI_CURRENCY_LONG: &str = "Goerli Ether";

pub const HOLESKY_NETWORK: &str = "holesky";
pub const HOLESKY_TOKEN: &str = "tGLM";
pub const HOLESKY_PLATFORM: &str = "erc20-holesky-tglm";
pub const HOLESKY_CURRENCY_SHORT: &str = "tETH";
pub const HOLESKY_CURRENCY_LONG: &str = "Holesky Ether";

pub const MUMBAI_NETWORK: &str = "mumbai";
pub const MUMBAI_TOKEN: &str = "tGLM";
pub const MUMBAI_PLATFORM: &str = "erc20-mumbai-tglm";
Expand Down
23 changes: 18 additions & 5 deletions core/payment-driver/erc20/src/network.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,10 @@ use ya_payment_driver::{db::models::Network as DbNetwork, driver::Network, model
// Local uses
use crate::{
GOERLI_CURRENCY_LONG, GOERLI_CURRENCY_SHORT, GOERLI_NETWORK, GOERLI_PLATFORM, GOERLI_TOKEN,
MAINNET_CURRENCY_LONG, MAINNET_CURRENCY_SHORT, MAINNET_NETWORK, MAINNET_PLATFORM,
MAINNET_TOKEN, MUMBAI_CURRENCY_LONG, MUMBAI_CURRENCY_SHORT, MUMBAI_NETWORK, MUMBAI_PLATFORM,
MUMBAI_TOKEN, POLYGON_MAINNET_CURRENCY_LONG, POLYGON_MAINNET_CURRENCY_SHORT,
HOLESKY_CURRENCY_LONG, HOLESKY_CURRENCY_SHORT, HOLESKY_NETWORK, HOLESKY_PLATFORM,
HOLESKY_TOKEN, MAINNET_CURRENCY_LONG, MAINNET_CURRENCY_SHORT, MAINNET_NETWORK,
MAINNET_PLATFORM, MAINNET_TOKEN, MUMBAI_CURRENCY_LONG, MUMBAI_CURRENCY_SHORT, MUMBAI_NETWORK,
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,
Expand All @@ -30,6 +31,12 @@ lazy_static::lazy_static! {
GOERLI_TOKEN.to_string() => GOERLI_PLATFORM.to_string()
}
},
HOLESKY_NETWORK.to_string() => Network {
default_token: HOLESKY_TOKEN.to_string(),
tokens: hashmap! {
HOLESKY_TOKEN.to_string() => HOLESKY_PLATFORM.to_string()
}
},
MAINNET_NETWORK.to_string() => Network {
default_token: MAINNET_TOKEN.to_string(),
tokens: hashmap! {
Expand All @@ -51,6 +58,7 @@ lazy_static::lazy_static! {
};
pub static ref RINKEBY_DB_NETWORK: DbNetwork = DbNetwork::from_str(RINKEBY_NETWORK).unwrap();
pub static ref GOERLI_DB_NETWORK: DbNetwork = DbNetwork::from_str(GOERLI_NETWORK).unwrap();
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 POLYGON_MAINNET_DB_NETWORK: DbNetwork = DbNetwork::from_str(POLYGON_MAINNET_NETWORK).unwrap();
Expand All @@ -60,6 +68,7 @@ pub fn platform_to_network_token(platform: String) -> Result<(DbNetwork, String)
match platform.as_str() {
RINKEBY_PLATFORM => Ok((*RINKEBY_DB_NETWORK, RINKEBY_TOKEN.to_owned())),
GOERLI_PLATFORM => Ok((*GOERLI_DB_NETWORK, GOERLI_TOKEN.to_owned())),
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())),
POLYGON_MAINNET_PLATFORM => Ok((
Expand Down Expand Up @@ -102,6 +111,10 @@ pub fn platform_to_currency(platform: String) -> Result<(String, String), Generi
GOERLI_CURRENCY_SHORT.to_owned(),
GOERLI_CURRENCY_LONG.to_owned(),
)),
HOLESKY_PLATFORM => Ok((
HOLESKY_CURRENCY_SHORT.to_owned(),
HOLESKY_CURRENCY_LONG.to_owned(),
)),
MAINNET_PLATFORM => Ok((
MAINNET_CURRENCY_SHORT.to_owned(),
MAINNET_CURRENCY_LONG.to_owned(),
Expand Down Expand Up @@ -131,8 +144,8 @@ pub fn get_network_token(

pub fn network_like_to_network(network_like: Option<String>) -> DbNetwork {
match network_like {
Some(n) => DbNetwork::from_str(&n).unwrap_or(*GOERLI_DB_NETWORK),
None => *GOERLI_DB_NETWORK,
Some(n) => DbNetwork::from_str(&n).unwrap_or(*HOLESKY_DB_NETWORK),
None => *HOLESKY_DB_NETWORK,
}
}

Expand Down
20 changes: 20 additions & 0 deletions core/payment-driver/erc20next/src/erc20/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,26 @@ lazy_static! {
}
}
};
pub static ref HOLESKY_CONFIG: EnvConfiguration = EnvConfiguration {
glm_contract_address: utils::str_to_addr(
&env::var("HOLESKY_TGLM_CONTRACT_ADDRESS")
.unwrap_or_else(|_| "0x8888888815bf4DB87e57B609A50f938311EEd068".to_string())
)
.unwrap(),
glm_faucet_address: Some(
utils::str_to_addr(
&env::var("HOLESKY_TGLM_FAUCET_ADDRESS")
.unwrap_or_else(|_| "0xFACe100969FF47EB58d2CF603321B581A84bcEaC".to_string())
)
.unwrap()
),
required_confirmations: {
match env::var("ERC20_HOLESKY_REQUIRED_CONFIRMATIONS").map(|s| s.parse()) {
Ok(Ok(x)) => x,
_ => 3,
}
}
};
pub static ref MUMBAI_CONFIG: EnvConfiguration = EnvConfiguration {
glm_contract_address: utils::str_to_addr(
&env::var("MUMBAI_TGLM_CONTRACT_ADDRESS")
Expand Down
5 changes: 5 additions & 0 deletions core/payment-driver/erc20next/src/erc20/ethereum.rs
Original file line number Diff line number Diff line change
Expand Up @@ -538,6 +538,10 @@ fn get_rpc_addr_from_env(network: Network) -> Vec<String> {
Network::Goerli => {
collect_rpc_addr_from("GOERLI_GETH_ADDR", "https://rpc.ankr.com/eth_goerli")
}
Network::Holesky => collect_rpc_addr_from(
"HOLESKY_GETH_ADDR",
"https://ethereum-holesky.publicnode.com",
),
Network::Polygon => collect_rpc_addr_from(
"POLYGON_GETH_ADDR",
"https://bor.golem.network,https://polygon-rpc.com",
Expand Down Expand Up @@ -592,6 +596,7 @@ fn get_env(network: Network) -> config::EnvConfiguration {
Network::Mainnet => *config::MAINNET_CONFIG,
Network::Rinkeby => *config::RINKEBY_CONFIG,
Network::Goerli => *config::GOERLI_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/erc20next/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,12 @@ pub const GOERLI_PLATFORM: &str = "erc20next-goerli-tglm";
pub const GOERLI_CURRENCY_SHORT: &str = "tETH";
pub const GOERLI_CURRENCY_LONG: &str = "Goerli Ether";

pub const HOLESKY_NETWORK: &str = "holesky";
pub const HOLESKY_TOKEN: &str = "tGLM";
pub const HOLESKY_PLATFORM: &str = "erc20next-holesky-tglm";
pub const HOLESKY_CURRENCY_SHORT: &str = "tETH";
pub const HOLESKY_CURRENCY_LONG: &str = "Holesky Ether";

pub const MUMBAI_NETWORK: &str = "mumbai";
pub const MUMBAI_TOKEN: &str = "tGLM";
pub const MUMBAI_PLATFORM: &str = "erc20next-mumbai-tglm";
Expand Down
Loading

0 comments on commit 012a440

Please sign in to comment.