Skip to content
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

Version bump alloy #73

Merged
merged 4 commits into from
Apr 27, 2024
Merged
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
1,598 changes: 1,184 additions & 414 deletions Cargo.lock

Large diffs are not rendered by default.

53 changes: 25 additions & 28 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,14 @@ name = "mintpool"
version = "0.1.0"
edition = "2021"

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[lib]
name = "mintpool"
path = "src/lib.rs"

[[bin]]
name = "mintpool"
path = "src/main.rs"


[dependencies]
const-hex = "1.11.3"
Expand Down Expand Up @@ -54,33 +61,29 @@ futures = "0.3.30"
sha256 = "1.5.0"
tower = { version = "0.4.13", features = ["full"] }
tower-http = { version = "0.5.2", features = ["cors", "compression-full", "trace"] }
alloy = { git = "https://github.com/alloy-rs/alloy", rev = "17633df", features = [
alloy = { git = "https://github.com/alloy-rs/alloy", rev = "bbef8de", features = [
"sol-types",
"network",
"rpc-types-eth",
"pubsub",
] }

alloy-transport = { git = "https://github.com/alloy-rs/alloy", rev = "17633df" }
alloy-rpc-client = { git = "https://github.com/alloy-rs/alloy", rev = "17633df", features = [
"pubsub",
"ws",
"reqwest"
] }
alloy-provider = { git = "https://github.com/alloy-rs/alloy", rev = "17633df", features = [
"pubsub",
"ws"
] }
alloy-signer = { git = "https://github.com/alloy-rs/alloy", rev = "17633df", features = [
"json",
"rpc-client",
"provider-http",
"provider-ws",
"json-rpc",
"rpc-client-ws",
"rpc-types-json",
"signers",
"transport-ws",
"eip712",
"serde",
"json",
"json-abi",
"node-bindings",
"contract",
"signer-wallet"
] }
alloy-json-rpc = { git = "https://github.com/alloy-rs/alloy", rev = "17633df" }
alloy-signer-wallet = { git = "https://github.com/alloy-rs/alloy", rev = "17633df" }
alloy-contract = { git = "https://github.com/alloy-rs/alloy", rev = "17633df" }
alloy-core = { git = "https://github.com/alloy-rs/core", rev = "7574bfc" }
alloy-sol-types = { git = "https://github.com/alloy-rs/core", rev = "7574bfc", features = ["eip712-serde"] }
alloy-primitives = { git = "https://github.com/alloy-rs/core", rev = "7574bfc", features = ["serde"] }
alloy-sol-macro = { git = "https://github.com/alloy-rs/core", rev = "7574bfc", features = ["json"] }

chrono = { version = "0.4.38", features = ["serde"] }
tracing-opentelemetry = "0.23.0"
opentelemetry = { version = "0.22.0", features = ["metrics"] }
Expand All @@ -91,16 +94,10 @@ opentelemetry-prometheus = "0.15.0"
prometheus = "0.13.3"
built = "0.7.2"

[patch.crates-io]
alloy-primitives = { git = "https://github.com/alloy-rs/core", rev = "7574bfc" }


[profile.dev.package.sqlx-macros]
opt-level = 3

[dev-dependencies]
alloy-node-bindings = { git = "https://github.com/alloy-rs/alloy", rev = "17633df" }


[build-dependencies]
built = { version = "0.7.2", features = ["git2"] }
20 changes: 9 additions & 11 deletions src/chain.rs
Original file line number Diff line number Diff line change
@@ -1,16 +1,14 @@
use std::sync::Arc;

use alloy::rpc::types::eth::{Filter, TransactionInput, TransactionRequest};
use alloy_primitives::{address, Address, Bytes};
use alloy_provider::Provider;
use alloy_sol_macro::sol;
use alloy_sol_types::{SolCall, SolEvent};
use futures_util::StreamExt;

use crate::chain_list::{ChainListProvider, CHAINS};
use crate::controller::{ControllerCommands, ControllerInterface};
use crate::premints::zora_premint_v2::types::PREMINT_FACTORY_ADDR;
use crate::types::{InclusionClaim, Premint, PremintTypes};
use alloy::primitives::{address, Address, Bytes, TxKind};
use alloy::providers::Provider;
use alloy::rpc::types::eth::{BlockId, Filter, TransactionInput, TransactionRequest};
use alloy::sol;
use alloy::sol_types::{SolCall, SolEvent};
use futures_util::StreamExt;
use std::sync::Arc;

/// Helper function for calling view functions for SolCall types
pub async fn view_contract_call<T>(
Expand All @@ -24,11 +22,11 @@ where
provider
.call(
&TransactionRequest {
to: Some(address),
to: Some(TxKind::Call(address)),
input: TransactionInput::new(Bytes::from(call.abi_encode())),
..Default::default()
},
None,
BlockId::latest(),
)
.await
.map_err(|err| eyre::eyre!("Error calling contract: {:?}", err))
Expand Down
42 changes: 14 additions & 28 deletions src/chain_list.rs
Original file line number Diff line number Diff line change
@@ -1,36 +1,25 @@
use std::sync::Arc;
use std::time::Duration;

use alloy::network::{Ethereum, Network};
use alloy::network::Network;
use alloy::providers::{ProviderBuilder, RootProvider};
use alloy::pubsub::PubSubFrontend;
use alloy_provider::layers::{GasEstimatorProvider, ManagedNonceProvider};
use alloy_provider::{Identity, ProviderBuilder, RootProvider};
use alloy_rpc_client::WsConnect;
use alloy::rpc::client::WsConnect;
use eyre::ContextCompat;
use mini_moka::sync::Cache;
use once_cell::sync::Lazy;
use regex::Regex;
use serde::{Deserialize, Serialize};
use std::sync::Arc;
use std::time::Duration;

const CHAINS_JSON: &str = include_str!("../data/chains.json");

pub type ChainListProvider<N = Ethereum> = GasEstimatorProvider<
PubSubFrontend,
ManagedNonceProvider<PubSubFrontend, RootProvider<PubSubFrontend, N>, N>,
N,
>;
pub type ChainListProvider = RootProvider<PubSubFrontend>;

pub struct Chains<N>(Vec<Chain>, Cache<String, Arc<ChainListProvider<N>>>)
where
N: Network;
pub struct Chains(Vec<Chain>, Cache<String, Arc<ChainListProvider>>);

pub static CHAINS: Lazy<Chains<Ethereum>> = Lazy::new(Chains::new);
pub static CHAINS: Lazy<Chains> = Lazy::new(Chains::new);
static VARIABLE_REGEX: Lazy<Regex> = Lazy::new(|| Regex::new(r"\$\{(.+?)}").unwrap());

impl<N: Network> Chains<N>
where
N: Network,
{
impl Chains {
fn new() -> Self {
Chains(
serde_json::from_str::<Vec<Chain>>(CHAINS_JSON).unwrap(),
Expand Down Expand Up @@ -69,14 +58,14 @@ where
Err(eyre::eyre!("No suitable RPC URL found for chain"))
}

pub async fn get_rpc(&self, chain_id: u64) -> eyre::Result<Arc<ChainListProvider<N>>> {
pub async fn get_rpc(&self, chain_id: u64) -> eyre::Result<Arc<ChainListProvider>> {
match self.get_rpc_url(chain_id) {
Ok(url) => self.connect(&url).await,
Err(e) => Err(e),
}
}

async fn connect(&self, url: &String) -> eyre::Result<Arc<ChainListProvider<N>>> {
async fn connect(&self, url: &String) -> eyre::Result<Arc<ChainListProvider>> {
if VARIABLE_REGEX.is_match(url) {
return Err(eyre::eyre!("URL contains variables"));
}
Expand All @@ -86,10 +75,7 @@ where
Some(provider) => Ok(provider),
None => {
let conn = WsConnect::new(url);
let provider: ChainListProvider<N> = ProviderBuilder::<Identity, N>::default()
.with_recommended_layers()
.on_ws(conn)
.await?;
let provider = ProviderBuilder::new().on_ws(conn).await?;

let arc = Arc::new(provider);

Expand All @@ -116,11 +102,11 @@ pub struct Chain {
#[cfg(test)]
mod test {
use super::*;
use alloy_provider::Provider;
use alloy::providers::Provider;

#[test]
fn test_chains_new() {
let _chains = Chains::<Ethereum>::new();
let _chains = Chains::new();
}

#[test]
Expand Down
8 changes: 3 additions & 5 deletions src/premints/zora_premint_v2/rules.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,3 @@
use std::str::FromStr;

use alloy_primitives::Signature;
use alloy_sol_types::SolStruct;

use crate::chain::view_contract_call;
use crate::premints::zora_premint_v2::types::{
IZoraPremintV2, ZoraPremintV2, PREMINT_FACTORY_ADDR,
Expand All @@ -12,6 +7,9 @@ use crate::rules::{Evaluation, Rule, RuleContext};
use crate::storage::Reader;
use crate::types::PremintTypes;
use crate::{ignore, reject, typed_rule};
use alloy::primitives::Signature;
use alloy::sol_types::SolStruct;
use std::str::FromStr;

// create premint v2 rule implementations here

Expand Down
8 changes: 4 additions & 4 deletions src/premints/zora_premint_v2/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@ use std::borrow::Cow;

use crate::premints::zora_premint_v2::types::IZoraPremintV2::PremintedV2;
use crate::types::{InclusionClaim, Premint, PremintMetadata, PremintName};
use alloy::primitives::{address, Address, U256};
use alloy::rpc::types::eth::{Filter, Log, TransactionReceipt};
use alloy::sol_types::private::U256;
use alloy_primitives::{address, Address};
use alloy_sol_macro::sol;
use alloy_sol_types::{Eip712Domain, SolEvent};
use alloy::sol;
use alloy::sol_types::{Eip712Domain, SolEvent};
// use alloy_sol_types::SolEvent;
use async_trait::async_trait;
use serde::{Deserialize, Serialize};

Expand Down
4 changes: 2 additions & 2 deletions src/rules.rs
Original file line number Diff line number Diff line change
Expand Up @@ -145,14 +145,14 @@ impl Display for Results {
pub struct RuleContext<T: Reader> {
pub storage: T,
pub existing: Option<PremintTypes>,
pub rpc: Option<Arc<ChainListProvider<Ethereum>>>,
pub rpc: Option<Arc<ChainListProvider>>,
}

impl<T: Reader> RuleContext<T> {
pub fn new(
storage: T,
existing: Option<PremintTypes>,
rpc: Option<Arc<ChainListProvider<Ethereum>>>,
rpc: Option<Arc<ChainListProvider>>,
) -> Self {
Self {
storage,
Expand Down
12 changes: 5 additions & 7 deletions src/storage.rs
Original file line number Diff line number Diff line change
@@ -1,15 +1,13 @@
use std::str::FromStr;

use alloy_primitives::Address;
use crate::config::Config;
use crate::types::{InclusionClaim, Premint, PremintName, PremintTypes};
use alloy::primitives::Address;
use async_trait::async_trait;
use eyre::WrapErr;
use serde::{Deserialize, Serialize};
use sqlx::sqlite::SqliteConnectOptions;
use sqlx::Row;
use sqlx::{QueryBuilder, Sqlite, SqlitePool};

use crate::config::Config;
use crate::types::{InclusionClaim, Premint, PremintName, PremintTypes};
use std::str::FromStr;

async fn init_db(config: &Config) -> SqlitePool {
let expect_msg =
Expand Down Expand Up @@ -322,7 +320,7 @@ fn build_query(options: &QueryOptions) -> QueryBuilder<Sqlite> {

#[cfg(test)]
mod test {
use alloy_primitives::Address;
use alloy::primitives::Address;
use chrono::{Duration, Utc};
use sqlx::Row;
use std::ops::Sub;
Expand Down
14 changes: 7 additions & 7 deletions src/types.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use crate::premints::zora_premint_v2::types::ZoraPremintV2;
use alloy::primitives::{Address, B256, U256};
use alloy::rpc::types::eth::{Filter, Log, TransactionReceipt};
use alloy_primitives::{Address, B256, U256};
use async_trait::async_trait;
use libp2p::gossipsub::TopicHash;
use libp2p::{gossipsub, Multiaddr, PeerId};
Expand Down Expand Up @@ -182,9 +182,9 @@ mod test {
ContractCreationConfig, CreatorAttribution, TokenCreationConfig,
};
use crate::premints::zora_premint_v2::types::{IZoraPremintV2, PREMINT_FACTORY_ADDR};
use alloy::primitives::{Bytes, LogData};
use alloy::rpc::types::eth::ReceiptEnvelope;
use alloy_primitives::{Bytes, LogData};
use alloy_sol_types::SolEvent;
use alloy::sol_types::SolEvent;
use std::str::FromStr;

#[test]
Expand Down Expand Up @@ -214,7 +214,7 @@ mod test {
#[test]
fn test_map_premintv2_claim() {
let log = Log {
inner: alloy_primitives::Log {
inner: alloy::primitives::Log {
address: PREMINT_FACTORY_ADDR.clone(),
data: LogData::new(vec![B256::from_str("0xd7f3736994092942aacd1d75026379ceeaf4e28b6183b15f2decc9237334429b").unwrap(),
B256::from_str("0x00000000000000000000000065aae9d752ecac4965015664d0a6d0951e28d757").unwrap(),
Expand Down Expand Up @@ -265,10 +265,10 @@ mod test {
.unwrap(),
),
block_number: Some(12387768),
gas_used: None,
gas_used: 0,
effective_gas_price: 0,
blob_gas_used: None,
transaction_index: 4,
transaction_index: Some(4),
from: Address::from_str("0xeDB81aFaecC2379635B25A752b787f821a46644c").unwrap(),
to: Some(PREMINT_FACTORY_ADDR.clone()),

Expand All @@ -278,7 +278,7 @@ mod test {
};

let log = Log {
inner: alloy_primitives::Log {
inner: alloy::primitives::Log {
address: PREMINT_FACTORY_ADDR.clone(),
data: LogData::new(vec![B256::from_str("0xd7f3736994092942aacd1d75026379ceeaf4e28b6183b15f2decc9237334429b").unwrap(),
B256::from_str("0x00000000000000000000000065aae9d752ecac4965015664d0a6d0951e28d757").unwrap(),
Expand Down
2 changes: 1 addition & 1 deletion tests/common/factories.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use alloy_primitives::{Address, U256};
use alloy::primitives::{Address, U256};
use mintpool::types::SimplePremint;
use rand::{Rng, RngCore};

Expand Down
Loading
Loading