Skip to content

adding support to edeXa Network #1068

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions SUPPORTED_CHAINS.md
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,8 @@ Chain name with associated `chainId` query param to use.
| Zora Sepolia <sup>[1](#footnote1)</sup> | eip155:999999999 |
| Aurora <sup>[1](#footnote1)</sup> | eip155:1313161554 |
| Aurora Testnet <sup>[1](#footnote1)</sup> | eip155:1313161555 |
| edeXa Mainnet <sup>[1](#footnote1)</sup> | eip155:5424 |
| edeXa Testnet <sup>[1](#footnote1)</sup> | eip155:1995 |
| Near Mainnet | near:mainnet |

### Solana
Expand Down
55 changes: 55 additions & 0 deletions src/env/edexa.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
use {
super::ProviderConfig,
crate::providers::{Priority, Weight},
std::collections::HashMap,
};

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

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

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

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

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

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

HashMap::from([
// edeXa Mainnet
(
"eip155:5424".into(),
(
"https://rpc.edexa.network".into(),
Weight::new(Priority::Normal).unwrap(),
),
),
// edeXa Testnet
(
"eip155:1995".into(),
(
"https://rpc.testnet.edexa.network".into(),
Weight::new(Priority::Normal).unwrap(),
),
),
])
}
3 changes: 2 additions & 1 deletion src/env/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ use {
std::{collections::HashMap, fmt::Display},
};
pub use {
allnodes::*, arbitrum::*, aurora::*, base::*, binance::*, drpc::*, dune::*, getblock::*,
allnodes::*, arbitrum::*, aurora::*, base::*, binance::*, drpc::*, dune::*, edexa::*, getblock::*,
mantle::*, monad::*, morph::*, near::*, odyssey::*, pokt::*, publicnode::*, quicknode::*,
server::*, solscan::*, syndica::*, unichain::*, wemix::*, zerion::*, zksync::*, zora::*,
};
Expand All @@ -27,6 +27,7 @@ mod base;
mod binance;
mod drpc;
mod dune;
mod edexa;
mod getblock;
mod mantle;
mod monad;
Expand Down
5 changes: 3 additions & 2 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ use {
},
env::{
AllnodesConfig, ArbitrumConfig, AuroraConfig, BaseConfig, BinanceConfig, DrpcConfig,
DuneConfig, GetBlockConfig, MantleConfig, MonadConfig, MorphConfig, NearConfig,
DuneConfig, EdexaConfig, GetBlockConfig, MantleConfig, MonadConfig, MorphConfig, NearConfig,
OdysseyConfig, PoktConfig, PublicnodeConfig, QuicknodeConfig, SolScanConfig, SyndicaConfig,
UnichainConfig, WemixConfig, ZKSyncConfig, ZerionConfig, ZoraConfig,
},
Expand All @@ -30,7 +30,7 @@ use {
hyper::{header::HeaderName, http, server::conn::AddrIncoming, Body, Server},
providers::{
AllnodesProvider, ArbitrumProvider, AuroraProvider, BaseProvider, BinanceProvider,
DrpcProvider, DuneProvider, GetBlockProvider, MantleProvider, MonadProvider, MorphProvider,
DrpcProvider, DuneProvider, EdexaProvider, GetBlockProvider, MantleProvider, MonadProvider, MorphProvider,
NearProvider, OdysseyProvider, PoktProvider, ProviderRepository, PublicnodeProvider,
QuicknodeProvider, SolScanProvider, SyndicaProvider, UnichainProvider, WemixProvider,
ZKSyncProvider, ZerionProvider, ZoraProvider, ZoraWsProvider,
Expand Down Expand Up @@ -530,6 +530,7 @@ fn init_providers(config: &ProvidersConfig) -> ProviderRepository {
providers.add_rpc_provider::<WemixProvider, WemixConfig>(WemixConfig::default());
providers.add_rpc_provider::<DrpcProvider, DrpcConfig>(DrpcConfig::default());
providers.add_rpc_provider::<OdysseyProvider, OdysseyConfig>(OdysseyConfig::default());
providers.add_rpc_provider::<EdexaProvider, EdexaConfig>(EdexaConfig::default());
providers.add_rpc_provider::<AllnodesProvider, AllnodesConfig>(AllnodesConfig::new(
config.allnodes_api_key.clone(),
));
Expand Down
99 changes: 99 additions & 0 deletions src/providers/edexa.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
use {
super::{Provider, ProviderKind, RateLimited, RpcProvider, RpcProviderFactory},
crate::{
env::EdexaConfig,
error::{RpcError, RpcResult},
},
async_trait::async_trait,
axum::{
http::HeaderValue,
response::{IntoResponse, Response},
},
hyper::{client::HttpConnector, http, Client, Method},
hyper_tls::HttpsConnector,
std::collections::HashMap,
tracing::debug,
};

#[derive(Debug)]
pub struct EdexaProvider {
pub client: Client<HttpsConnector<HttpConnector>>,
pub supported_chains: HashMap<String, String>,
}

impl Provider for EdexaProvider {
fn supports_caip_chainid(&self, chain_id: &str) -> bool {
self.supported_chains.contains_key(chain_id)
}

fn supported_caip_chains(&self) -> Vec<String> {
self.supported_chains.keys().cloned().collect()
}

fn provider_kind(&self) -> ProviderKind {
ProviderKind::Edexa
}
}

#[async_trait]
impl RateLimited for EdexaProvider {
async fn is_rate_limited(&self, response: &mut Response) -> bool
where
Self: Sized,
{
response.status() == http::StatusCode::TOO_MANY_REQUESTS
}
}

#[async_trait]
impl RpcProvider for EdexaProvider {
#[tracing::instrument(skip(self, body), fields(provider = %self.provider_kind()), level = "debug")]
async fn proxy(&self, chain_id: &str, body: hyper::body::Bytes) -> RpcResult<Response> {
let uri = self
.supported_chains
.get(chain_id)
.ok_or(RpcError::ChainNotFound)?;

let hyper_request = hyper::http::Request::builder()
.method(Method::POST)
.uri(uri)
.header("Content-Type", "application/json")
.body(hyper::body::Body::from(body))?;

let response = self.client.request(hyper_request).await?;
let status = response.status();
let body = hyper::body::to_bytes(response.into_body()).await?;

if let Ok(response) = serde_json::from_slice::<jsonrpc::Response>(&body) {
if response.error.is_some() && status.is_success() {
debug!(
"Strange: provider returned JSON RPC error, but status {status} is success: \
Edexa: {response:?}"
);
}
}

let mut response = (status, body).into_response();
response
.headers_mut()
.insert("Content-Type", HeaderValue::from_static("application/json"));
Ok(response)
}
}

impl RpcProviderFactory<EdexaConfig> for EdexaProvider {
#[tracing::instrument(level = "debug")]
fn new(provider_config: &EdexaConfig) -> Self {
let forward_proxy_client = Client::builder().build::<_, hyper::Body>(HttpsConnector::new());
let supported_chains: HashMap<String, String> = provider_config
.supported_chains
.iter()
.map(|(k, v)| (k.clone(), v.0.clone()))
.collect();

EdexaProvider {
client: forward_proxy_client,
supported_chains,
}
}
}
5 changes: 5 additions & 0 deletions src/providers/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ mod bungee;
mod coinbase;
mod drpc;
mod dune;
mod edexa;
mod getblock;
mod mantle;
mod meld;
Expand Down Expand Up @@ -104,6 +105,7 @@ pub use {
bungee::BungeeProvider,
drpc::DrpcProvider,
dune::DuneProvider,
edexa::EdexaProvider,
getblock::GetBlockProvider,
mantle::MantleProvider,
meld::MeldProvider,
Expand Down Expand Up @@ -687,6 +689,7 @@ pub enum ProviderKind {
Allnodes,
Meld,
Monad,
Edexa,
}

impl Display for ProviderKind {
Expand Down Expand Up @@ -723,6 +726,7 @@ impl Display for ProviderKind {
ProviderKind::Allnodes => "Allnodes",
ProviderKind::Meld => "Meld",
ProviderKind::Monad => "Monad",
ProviderKind::Edexa => "edeXa",
}
)
}
Expand Down Expand Up @@ -760,6 +764,7 @@ impl ProviderKind {
"Allnodes" => Some(Self::Allnodes),
"Meld" => Some(Self::Meld),
"Monad" => Some(Self::Monad),
"edeXa" => Some(Self::Edexa),
_ => None,
}
}
Expand Down
3 changes: 3 additions & 0 deletions terraform/monitoring/dashboard.jsonnet
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@ dashboard.new(
panels.usage.provider(ds, vars, 'Morph', alert_period_free_tier) { gridPos: pos._4 },
panels.usage.provider(ds, vars, 'Wemix', alert_period_free_tier) { gridPos: pos._4 },
panels.usage.provider(ds, vars, 'Drpc', alert_period_free_tier) { gridPos: pos._4 },
panels.usage.provider(ds, vars, 'edeXa', alert_period_free_tier) { gridPos: pos._4 },
panels.usage.provider(ds, vars, 'Odyssey', alert_period_free_tier) { gridPos: pos._4 },
panels.usage.provider(ds, vars, 'Syndica', alert_period_free_tier) { gridPos: pos._4 },
panels.usage.provider(ds, vars, 'Monad', alert_period_free_tier) { gridPos: pos._4 },
Expand All @@ -112,6 +113,7 @@ dashboard.new(
panels.weights.provider(ds, vars, 'Morph') { gridPos: pos._4 },
panels.weights.provider(ds, vars, 'Wemix') { gridPos: pos._4 },
panels.weights.provider(ds, vars, 'Drpc') { gridPos: pos._4 },
panels.weights.provider(ds, vars, 'edeXa') { gridPos: pos._4 },
panels.weights.provider(ds, vars, 'Odyssey') { gridPos: pos._4 },
panels.weights.provider(ds, vars, 'Syndica') { gridPos: pos._4 },
panels.weights.provider(ds, vars, 'Monad') { gridPos: pos._4 },
Expand All @@ -134,6 +136,7 @@ dashboard.new(
panels.status.provider(ds, vars, 'Morph') { gridPos: pos._4 },
panels.status.provider(ds, vars, 'Wemix') { gridPos: pos._4 },
panels.status.provider(ds, vars, 'Drpc') { gridPos: pos._4 },
panels.status.provider(ds, vars, 'edeXa') { gridPos: pos._4 },
panels.status.provider(ds, vars, 'Odyssey') { gridPos: pos._4 },
panels.status.provider(ds, vars, 'Syndica') { gridPos: pos._4 },
panels.status.provider(ds, vars, 'Monad') { gridPos: pos._4 },
Expand Down
27 changes: 27 additions & 0 deletions tests/functional/http/edexa.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
use {
super::check_if_rpc_is_responding_correctly_for_supported_chain, crate::context::ServerContext,
rpc_proxy::providers::ProviderKind, test_context::test_context,
};

#[test_context(ServerContext)]
#[tokio::test]
#[ignore]
async fn edexa_provider(ctx: &mut ServerContext) {
// tests/functional/http/edexa.rs Mainnet
check_if_rpc_is_responding_correctly_for_supported_chain(
ctx,
&ProviderKind::Edexa,
"eip155:5424",
"0x1530",
)
.await;

// edeXa Testnet
check_if_rpc_is_responding_correctly_for_supported_chain(
ctx,
&ProviderKind::Edexa,
"eip155:1995",
"0x7cb",
)
.await
}
1 change: 1 addition & 0 deletions tests/functional/http/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ pub(crate) mod aurora;
pub(crate) mod base;
pub(crate) mod binance;
pub(crate) mod drpc;
pub(crate) mod edexa;
pub(crate) mod getblock;
pub(crate) mod mantle;
pub(crate) mod monad;
Expand Down