Skip to content

Commit

Permalink
add tenderly provider and tests from #301
Browse files Browse the repository at this point in the history
  • Loading branch information
geekbrother committed Sep 26, 2023
1 parent b8ebcf4 commit 28dba08
Show file tree
Hide file tree
Showing 11 changed files with 465 additions and 38 deletions.
10 changes: 10 additions & 0 deletions SUPPORTED_CHAINS.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,9 @@ Chain name with associated `chainId` query param to use.
- Base Goerli (`eip155:84531`)
- Zora (`eip155:7777777`)
- Zora Goerli (`eip155:999`)
- Boba Ethereum (`eip155:288`)
- Boba BNB (`eip155:56288`)
- Boba BNB Testnet (`eip155:9728`)

## WebSocket RPC

Expand All @@ -41,7 +44,14 @@ WebSocket RPC is not recommended for production use, and may be removed in the f
- Optimism Goerli (`eip155:420`)
- Arbitrum (`eip155:42161`)
- Arbitrum Goerli (`eip155:421613`)
- Polygon (`eip155:137`)
- Polygon Mumbai (`eip155:80001`)
- Aurora (`eip155:1313161554`)
- Aurora Testnet (`eip155:1313161555`)
- Base (`eip155:8453`)
- Base Goerli (`eip155:84531`)
- Zora (`eip155:7777777`)
- Zora Goerli (`eip155:999`)
- Boba Ethereum (`eip155:288`)
- Boba BNB (`eip155:56288`)
- Boba BNB Testnet (`eip155:9728`)
12 changes: 3 additions & 9 deletions src/env/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,19 +17,13 @@ mod omnia;
mod pokt;
mod publicnode;
mod server;
mod tenderly;
mod zksync;
mod zora;

pub use {
base::*,
binance::*,
infura::*,
omnia::*,
pokt::*,
publicnode::*,
server::*,
zksync::*,
zora::*,
base::*, binance::*, infura::*, omnia::*, pokt::*, publicnode::*, server::*, tenderly::*,
zksync::*, zora::*,
};

#[derive(Debug, Clone, PartialEq, Eq, Hash)]
Expand Down
180 changes: 180 additions & 0 deletions src/env/tenderly.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,180 @@
use {
super::ProviderConfig,
crate::providers::{Priority, Weight},
std::collections::HashMap,
};

#[derive(Debug)]
pub struct TenderlyConfig {
pub supported_chains: HashMap<String, (String, Weight)>,
pub supported_ws_chains: HashMap<String, (String, Weight)>,
}

impl Default for TenderlyConfig {
fn default() -> Self {
Self {
supported_chains: default_supported_chains(),
supported_ws_chains: default_ws_supported_chains(),
}
}
}

impl ProviderConfig for TenderlyConfig {
fn supported_chains(self) -> HashMap<String, (String, Weight)> {
self.supported_chains
}

fn supported_ws_chains(self) -> HashMap<String, (String, Weight)> {
self.supported_ws_chains
}

fn provider_kind(&self) -> crate::providers::ProviderKind {
crate::providers::ProviderKind::Tenderly
}
}

fn default_supported_chains() -> HashMap<String, (String, Weight)> {
// Keep in-sync with SUPPORTED_CHAINS.md

HashMap::from([
// Ethereum Mainnet
(
"eip155:1".into(),
("mainnet".into(), Weight::new(Priority::Low).unwrap()),
),
// Ethereum Görli
(
"eip155:5".into(),
("goerli".into(), Weight::new(Priority::Low).unwrap()),
),
// Ethereum Sepolia
(
"eip155:11155111".into(),
("sepolia".into(), Weight::new(Priority::Low).unwrap()),
),
// Optimism Mainnet
(
"eip155:10".into(),
("optimism".into(), Weight::new(Priority::Low).unwrap()),
),
// Optimism Görli
(
"eip155:420".into(),
(
"optimism-goerli".into(),
Weight::new(Priority::Low).unwrap(),
),
),
// Polygon Mainnet
(
"eip155:137".into(),
("polygon".into(), Weight::new(Priority::Low).unwrap()),
),
// Polygon Mumbai
(
"eip155:80001".into(),
("polygon-mumbai".into(), Weight::new(Priority::Low).unwrap()),
),
// Base Mainnet
(
"eip155:8453".into(),
("base".into(), Weight::new(Priority::Low).unwrap()),
),
// Base Görli
(
"eip155:84531".into(),
("base-goerli".into(), Weight::new(Priority::Low).unwrap()),
),
// Boba Ethereum Mainnet
(
"eip155:288".into(),
("boba-ethereum".into(), Weight::new(Priority::Low).unwrap()),
),
// Boba BNB Mainnet
(
"eip155:56288".into(),
("boba-bnb".into(), Weight::new(Priority::Low).unwrap()),
),
// Boba BNB Testnet
(
"eip155:9728".into(),
(
"boba-bnb-testnet".into(),
Weight::new(Priority::Low).unwrap(),
),
),
])
}

fn default_ws_supported_chains() -> HashMap<String, (String, Weight)> {
// Keep in-sync with SUPPORTED_CHAINS.md

HashMap::from([
// Ethereum Mainnet
(
"eip155:1".into(),
("mainnet".into(), Weight::new(Priority::Low).unwrap()),
),
// Ethereum Görli
(
"eip155:5".into(),
("goerli".into(), Weight::new(Priority::Low).unwrap()),
),
// Ethereum Sepolia
(
"eip155:11155111".into(),
("sepolia".into(), Weight::new(Priority::Low).unwrap()),
),
// Optimism Mainnet
(
"eip155:10".into(),
("optimism".into(), Weight::new(Priority::Low).unwrap()),
),
// Optimism Görli
(
"eip155:420".into(),
(
"optimism-goerli".into(),
Weight::new(Priority::Low).unwrap(),
),
),
// Polygon Mainnet
(
"eip155:137".into(),
("polygon".into(), Weight::new(Priority::Low).unwrap()),
),
// Polygon Mumbai
(
"eip155:80001".into(),
("polygon-mumbai".into(), Weight::new(Priority::Low).unwrap()),
),
// Base Mainnet
(
"eip155:8453".into(),
("base".into(), Weight::new(Priority::Low).unwrap()),
),
// Base Görli
(
"eip155:84531".into(),
("base-goerli".into(), Weight::new(Priority::Low).unwrap()),
),
// Boba Ethereum Mainnet
(
"eip155:288".into(),
("boba-ethereum".into(), Weight::new(Priority::Low).unwrap()),
),
// Boba BNB Mainnet
(
"eip155:56288".into(),
("boba-bnb".into(), Weight::new(Priority::Low).unwrap()),
),
// Boba BNB Testnet
(
"eip155:9728".into(),
(
"boba-bnb-testnet".into(),
Weight::new(Priority::Low).unwrap(),
),
),
])
}
26 changes: 7 additions & 19 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,30 +13,16 @@ use {
Router,
},
env::{
BaseConfig,
BinanceConfig,
InfuraConfig,
OmniatechConfig,
PoktConfig,
PublicnodeConfig,
ZKSyncConfig,
ZoraConfig,
BaseConfig, BinanceConfig, InfuraConfig, OmniatechConfig, PoktConfig, PublicnodeConfig,
TenderlyConfig, ZKSyncConfig, ZoraConfig,
},
error::RpcResult,
http::Request,
hyper::{header::HeaderName, http, Body},
providers::{
BaseProvider,
BinanceProvider,
InfuraProvider,
InfuraWsProvider,
OmniatechProvider,
PoktProvider,
ProviderRepository,
PublicnodeProvider,
ZKSyncProvider,
ZoraProvider,
ZoraWsProvider,
BaseProvider, BinanceProvider, InfuraProvider, InfuraWsProvider, OmniatechProvider,
PoktProvider, ProviderRepository, PublicnodeProvider, TenderlyProvider, TenderlyWsProvider,
ZKSyncProvider, ZoraProvider, ZoraWsProvider,
},
std::{
net::{IpAddr, Ipv4Addr, SocketAddr},
Expand Down Expand Up @@ -246,10 +232,12 @@ fn init_providers() -> ProviderRepository {
providers
.add_provider::<InfuraProvider, InfuraConfig>(InfuraConfig::new(infura_project_id.clone()));
providers.add_provider::<ZoraProvider, ZoraConfig>(ZoraConfig::default());
providers.add_provider::<TenderlyProvider, TenderlyConfig>(TenderlyConfig::default());

providers
.add_ws_provider::<InfuraWsProvider, InfuraConfig>(InfuraConfig::new(infura_project_id));
providers.add_ws_provider::<ZoraWsProvider, ZoraConfig>(ZoraConfig::default());
providers.add_ws_provider::<TenderlyWsProvider, TenderlyConfig>(TenderlyConfig::default());

providers
}
29 changes: 19 additions & 10 deletions src/providers/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ mod infura;
mod omnia;
mod pokt;
mod publicnode;
mod tenderly;
mod weights;
mod zerion;
mod zksync;
Expand All @@ -37,6 +38,7 @@ pub use {
omnia::OmniatechProvider,
pokt::PoktProvider,
publicnode::PublicnodeProvider,
tenderly::{TenderlyProvider, TenderlyWsProvider},
zksync::ZKSyncProvider,
zora::{ZoraProvider, ZoraWsProvider},
};
Expand Down Expand Up @@ -227,23 +229,29 @@ pub enum ProviderKind {
Binance,
ZKSync,
Publicnode,
Tenderly,
Omniatech,
Base,
Zora,
}

impl Display for ProviderKind {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
write!(f, "{}", match self {
ProviderKind::Infura => "Infura",
ProviderKind::Pokt => "Pokt",
ProviderKind::Binance => "Binance",
ProviderKind::ZKSync => "zkSync",
ProviderKind::Publicnode => "Publicnode",
ProviderKind::Omniatech => "Omniatech",
ProviderKind::Base => "Base",
ProviderKind::Zora => "Zora",
})
write!(
f,
"{}",
match self {
ProviderKind::Infura => "Infura",
ProviderKind::Pokt => "Pokt",
ProviderKind::Binance => "Binance",
ProviderKind::ZKSync => "zkSync",
ProviderKind::Publicnode => "Publicnode",
ProviderKind::Tenderly => "Tenderly",
ProviderKind::Omniatech => "Omniatech",
ProviderKind::Base => "Base",
ProviderKind::Zora => "Zora",
}
)
}
}

Expand All @@ -255,6 +263,7 @@ impl ProviderKind {
"Binance" => Some(Self::Binance),
"zkSync" => Some(Self::ZKSync),
"Publicnode" => Some(Self::Publicnode),
"Tenderly" => Some(Self::Tenderly),
"Omniatech" => Some(Self::Omniatech),
"Base" => Some(Self::Base),
"Zora" => Some(Self::Zora),
Expand Down
Loading

0 comments on commit 28dba08

Please sign in to comment.