Skip to content

Commit

Permalink
feat: Base & Zora (reown-com#292)
Browse files Browse the repository at this point in the history
* feat: Base   Zora

* fix: eip155

* fix: WebSocket caps

* chore: test Sepolia, Base, and Zora

* chore: Base   Zora tests, run unit tests in CI, nightly clippy fmt to match CI
  • Loading branch information
chris13524 authored Aug 18, 2023
1 parent 14f9ce9 commit d364ba4
Show file tree
Hide file tree
Showing 28 changed files with 575 additions and 69 deletions.
13 changes: 12 additions & 1 deletion .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -42,12 42,23 @@ jobs:
cmd: clippy
args: --all-features --tests -- -D clippy::all
cache: {}
rust: stable
rust: nightly
- name: "Formatting"
cmd: fmt
args: -- --check
cache: {}
rust: nightly
# See `just test` for why this is disabled
# - name: "Unit Tests"
# cmd: test
# args: --lib --bins
# cache: {}
# rust: nightly
- name: "Unit Tests (all features)"
cmd: test
args: --all-features --lib --bins
cache: {}
rust: nightly
include:
- os: ubuntu-latest
sccache-path: /home/runner/.cache/sccache
Expand Down
1 change: 0 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 76,6 @@ vergen = { version = "6", default-features = false, features = ["build", "cargo"

[features]
test-localhost = []
dynamic-weights = []

[profile.release-debug]
inherits = "release"
Expand Down
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 25,12 @@ just run
curl -X POST "http://localhost:3000/v1?chainId=eip155:5&projectId=someid" -d '{"id":"1660887896683","jsonrpc":"2.0","method":"eth_chainId","params":[]}'
```

## Testing

```bash
just amigood
```

### Docker

```console
Expand Down
12 changes: 9 additions & 3 deletions SUPPORTED_CHAINS.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 4,7 @@ Chain name with associated `chainId` query param to use.

## HTTP RPC

- Ethereum (`eip115:1`)
- Ethereum (`eip155:1`)
- Ethereum Goerli (`eip155:5`)
- Ethereum Sepolia (`eip155:11155111`)
- Optimism (`eip155:10`)
Expand All @@ -23,10 23,14 @@ Chain name with associated `chainId` query param to use.
- Near (`near`)
- Gnosis Chain (`eip155:100`)
- Solana (`solana:4sgjmw1sunhzsxgspuhpqldx6wiyjntz` or `solana-mainnet`)
- Base (`eip155:8453`)
- Base Goerli (`eip155:84531`)
- Zora (`eip155:7777777`)
- Zora Goerli (`eip155:999`)

## Websocket RPC
## WebSocket RPC

- Ethereum (`eip115:1`)
- Ethereum (`eip155:1`)
- Ethereum Goerli (`eip155:5`)
- Ethereum Sepolia (`eip155:11155111`)
- Optimism (`eip155:10`)
Expand All @@ -35,3 39,5 @@ Chain name with associated `chainId` query param to use.
- Arbitrum Goerli (`eip155:421613`)
- Aurora (`eip155:1313161554`)
- Aurora Testnet (`eip155:1313161555`)
- Zora (`eip155:7777777`)
- Zora Goerli (`eip155:999`)
33 changes: 19 additions & 14 deletions justfile
Original file line number Diff line number Diff line change
Expand Up @@ -22,15 22,17 @@ run: build
@echo '==> Running project (ctrl c to exit)'
cargo run

# Run project test suite, skipping storage tests
test:
@echo '==> Testing project (default)'
cargo test

# Run project test suite, including storage tests (requires storage docker services to be running)
# Run project test suite
# Note: Currently broken as lack of test-localhost feature will run integration tests against staging and this uses a different env variable
# This is redundnat with test-all or the integration tests run in CI anyway and will be cleaned up later
# test:
# @echo '==> Testing project (default)'
# cargo nightly test

# Run project test suite
test-all:
@echo '==> Testing project (all features)'
cargo test --all-features
cargo nightly test --all-features

# Clean build artifacts
clean:
Expand All @@ -40,14 42,16 @@ clean:
# Lint the project for any quality issues
lint: check fmt clippy commit-check

amigood: lint test-all

# Run project linter
clippy:
#!/bin/bash
set -euo pipefail

if command -v cargo-clippy >/dev/null; then
echo '==> Running clippy'
cargo clippy --all-features --tests -- -D clippy::all
cargo nightly clippy --all-features --tests -- -D clippy::all
else
echo '==> clippy not found in PATH, skipping'
fi
Expand Down Expand Up @@ -76,12 80,13 @@ commit-check:
#!/bin/bash
set -euo pipefail

if command -v cog >/dev/null; then
echo '==> Running cog check'
cog check --from-latest-tag
else
echo '==> cog not found in PATH, skipping'
fi
# FIXME commit check doesn't exist in CI & no tagging takes place (see #53)
# if command -v cog >/dev/null; then
# echo '==> Running cog check'
# cog check --from-latest-tag
# else
# echo '==> cog not found in PATH, skipping'
# fi

lint-tf: tf-validate tf-fmt tfsec tflint

Expand Down
55 changes: 55 additions & 0 deletions src/env/base.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 BaseConfig {
pub supported_chains: HashMap<String, (String, Weight)>,
}

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

impl ProviderConfig for BaseConfig {
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::Base
}
}

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

HashMap::from([
// Base Mainnet
(
"eip155:8453".into(),
(
"https://mainnet.base.org".into(),
Weight::new(Priority::Normal).unwrap(),
),
),
// Base Goerli
(
"eip155:84531".into(),
(
"https://goerli.base.org".into(),
Weight::new(Priority::Normal).unwrap(),
),
),
])
}
4 changes: 4 additions & 0 deletions src/env/binance.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 14,10 @@ impl ProviderConfig for BinanceConfig {
self.supported_chains
}

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

fn provider_kind(&self) -> crate::providers::ProviderKind {
crate::providers::ProviderKind::Binance
}
Expand Down
4 changes: 4 additions & 0 deletions src/env/infura.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 28,10 @@ impl ProviderConfig for InfuraConfig {
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::Infura
}
Expand Down
15 changes: 14 additions & 1 deletion src/env/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 10,27 @@ use {
std::{collections::HashMap, fmt::Display},
};

mod base;
mod binance;
mod infura;
mod omnia;
mod pokt;
mod publicnode;
mod server;
mod zksync;
mod zora;

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

#[derive(Debug, Clone, PartialEq, Eq, Hash)]
pub struct ChainId(pub String);
Expand Down Expand Up @@ -56,5 68,6 @@ fn from_env<T: DeserializeOwned>(prefix: &str) -> Result<T, envy::Error> {

pub trait ProviderConfig {
fn supported_chains(self) -> HashMap<String, (String, Weight)>;
fn supported_ws_chains(self) -> HashMap<String, (String, Weight)>;
fn provider_kind(&self) -> ProviderKind;
}
4 changes: 4 additions & 0 deletions src/env/omnia.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 22,10 @@ impl ProviderConfig for OmniatechConfig {
self.supported_chains
}

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

fn provider_kind(&self) -> crate::providers::ProviderKind {
crate::providers::ProviderKind::Omniatech
}
Expand Down
4 changes: 4 additions & 0 deletions src/env/pokt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 25,10 @@ impl ProviderConfig for PoktConfig {
self.supported_chains
}

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

fn provider_kind(&self) -> crate::providers::ProviderKind {
crate::providers::ProviderKind::Pokt
}
Expand Down
4 changes: 4 additions & 0 deletions src/env/publicnode.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 22,10 @@ impl ProviderConfig for PublicnodeConfig {
self.supported_chains
}

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

fn provider_kind(&self) -> crate::providers::ProviderKind {
crate::providers::ProviderKind::Publicnode
}
Expand Down
4 changes: 4 additions & 0 deletions src/env/zksync.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 22,10 @@ impl ProviderConfig for ZKSyncConfig {
self.supported_chains
}

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

fn provider_kind(&self) -> crate::providers::ProviderKind {
crate::providers::ProviderKind::ZKSync
}
Expand Down
80 changes: 80 additions & 0 deletions src/env/zora.rs
Original file line number Diff line number Diff line change
@@ -0,0 1,80 @@
use {
super::ProviderConfig,
crate::providers::{Priority, Weight},
std::collections::HashMap,
};

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

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

impl ProviderConfig for ZoraConfig {
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::Zora
}
}

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

HashMap::from([
// Zora Mainnet
(
"eip155:7777777".into(),
(
"https://rpc.zora.energy".into(),
Weight::new(Priority::Normal).unwrap(),
),
),
// Zora Goerli
(
"eip155:999".into(),
(
"https://testnet.rpc.zora.energy".into(),
Weight::new(Priority::Normal).unwrap(),
),
),
])
}

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

HashMap::from([
// Zora Mainnet
(
"eip155:7777777".into(),
(
"wss://rpc.zora.energy".into(),
Weight::new(Priority::Normal).unwrap(),
),
),
// Zora Goerli
(
"eip155:999".into(),
(
"wss://testnet.rpc.zora.energy".into(),
Weight::new(Priority::Normal).unwrap(),
),
),
])
}
Loading

0 comments on commit d364ba4

Please sign in to comment.