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

chore(evmlib): update alloy to 0.4.2 #2191

Merged
merged 1 commit into from
Oct 4, 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
255 changes: 173 additions & 82 deletions Cargo.lock

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion evmlib/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ repository = "https://github.com/maidsafe/safe_network"
version = "0.1.0"

[dependencies]
alloy = { version = "0.2", default-features = false, features = ["std", "reqwest-rustls-tls", "provider-anvil-node", "sol-types", "json", "signers", "contract", "signer-local", "network"] }
alloy = { version = "0.4.2", default-features = false, features = ["std", "reqwest-rustls-tls", "provider-anvil-node", "sol-types", "json", "signers", "contract", "signer-local", "network"] }
serde = "1.0"
thiserror = "1.0"
tokio = "1.38.0"
Expand Down
2 changes: 2 additions & 0 deletions evmlib/src/contract/chunk_payments/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ pub enum Error {
RpcError(#[from] RpcError<TransportErrorKind>),
#[error(transparent)]
NetworkTokenError(#[from] network_token::Error),
#[error(transparent)]
PendingTransactionError(#[from] alloy::providers::PendingTransactionError),
#[error("The transfer limit of 256 has been exceeded")]
TransferLimitExceeded,
}
24 changes: 12 additions & 12 deletions evmlib/src/contract/chunk_payments/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ pub mod error;
use crate::common;
use crate::common::{Address, TxHash};
use crate::contract::chunk_payments::error::Error;
use crate::contract::chunk_payments::ChunkPaymentsContract::ChunkPaymentsContractInstance;
use crate::contract::chunk_payments::DataPaymentsContract::DataPaymentsContractInstance;
use alloy::providers::{Network, Provider};
use alloy::sol;
use alloy::transports::Transport;
Expand All @@ -15,39 +15,39 @@ sol!(
#[allow(clippy::too_many_arguments)]
#[allow(missing_docs)]
#[sol(rpc)]
ChunkPaymentsContract,
DataPaymentsContract,
"artifacts/ChunkPayments.json"
);

pub struct ChunkPayments<T: Transport + Clone, P: Provider<T, N>, N: Network> {
pub contract: ChunkPaymentsContractInstance<T, P, N>,
pub struct DataPayments<T: Transport + Clone, P: Provider<T, N>, N: Network> {
pub contract: DataPaymentsContractInstance<T, P, N>,
}

impl<T, P, N> ChunkPayments<T, P, N>
impl<T, P, N> DataPayments<T, P, N>
where
T: Transport + Clone,
P: Provider<T, N>,
N: Network,
{
/// Create a new ChunkPayments contract instance.
pub fn new(contract_address: Address, provider: P) -> Self {
let contract = ChunkPaymentsContract::new(contract_address, provider);
ChunkPayments { contract }
let contract = DataPaymentsContract::new(contract_address, provider);
DataPayments { contract }
}

/// Deploys the ChunkPayments smart contract to the network of the provider.
/// ONLY DO THIS IF YOU KNOW WHAT YOU ARE DOING!
pub async fn deploy(provider: P, payment_token_address: Address) -> Self {
let contract = ChunkPaymentsContract::deploy(provider, payment_token_address)
let contract = DataPaymentsContract::deploy(provider, payment_token_address)
.await
.expect("Could not deploy contract");

ChunkPayments { contract }
DataPayments { contract }
}

pub fn set_provider(&mut self, provider: P) {
let address = *self.contract.address();
self.contract = ChunkPaymentsContract::new(address, provider);
self.contract = DataPaymentsContract::new(address, provider);
}

/// Pay for quotes.
Expand All @@ -56,9 +56,9 @@ where
&self,
chunk_payments: I,
) -> Result<TxHash, Error> {
let chunk_payments: Vec<ChunkPaymentsContract::ChunkPayment> = chunk_payments
let chunk_payments: Vec<ChunkPayments::ChunkPayment> = chunk_payments
.into_iter()
.map(|(hash, addr, amount)| ChunkPaymentsContract::ChunkPayment {
.map(|(hash, addr, amount)| ChunkPayments::ChunkPayment {
rewardAddress: addr,
amount,
quoteHash: hash,
Expand Down
2 changes: 2 additions & 0 deletions evmlib/src/contract/network_token.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ pub enum Error {
ContractError(#[from] alloy::contract::Error),
#[error(transparent)]
RpcError(#[from] RpcError<TransportErrorKind>),
#[error(transparent)]
PendingTransactionError(#[from] alloy::providers::PendingTransactionError),
}

pub struct NetworkToken<T: Transport + Clone, P: Provider<T, N>, N: Network> {
Expand Down
28 changes: 21 additions & 7 deletions evmlib/src/testnet.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
use crate::common::Address;
use crate::contract::chunk_payments::ChunkPayments;
use crate::contract::chunk_payments::DataPayments;
use crate::contract::network_token::NetworkToken;
use crate::{CustomNetwork, Network};
use alloy::hex::ToHexExt;
use alloy::network::{Ethereum, EthereumWallet};
use alloy::node_bindings::{Anvil, AnvilInstance};
use alloy::providers::fillers::{FillProvider, JoinFill, RecommendedFiller, WalletFiller};
use alloy::providers::{ProviderBuilder, ReqwestProvider};
use alloy::providers::fillers::{
BlobGasFiller, ChainIdFiller, FillProvider, GasFiller, JoinFill, NonceFiller, WalletFiller,
};
use alloy::providers::{Identity, ProviderBuilder, ReqwestProvider};
use alloy::signers::local::PrivateKeySigner;
use alloy::transports::http::{Client, Http};

Expand Down Expand Up @@ -67,7 +69,13 @@ pub async fn deploy_network_token_contract(
) -> NetworkToken<
Http<Client>,
FillProvider<
JoinFill<RecommendedFiller, WalletFiller<EthereumWallet>>,
JoinFill<
JoinFill<
Identity,
JoinFill<GasFiller, JoinFill<BlobGasFiller, JoinFill<NonceFiller, ChainIdFiller>>>,
>,
WalletFiller<EthereumWallet>,
>,
ReqwestProvider,
Http<Client>,
Ethereum,
Expand All @@ -92,10 +100,16 @@ pub async fn deploy_network_token_contract(
pub async fn deploy_chunk_payments_contract(
anvil: &AnvilInstance,
token_address: Address,
) -> ChunkPayments<
) -> DataPayments<
Http<Client>,
FillProvider<
JoinFill<RecommendedFiller, WalletFiller<EthereumWallet>>,
JoinFill<
JoinFill<
Identity,
JoinFill<GasFiller, JoinFill<BlobGasFiller, JoinFill<NonceFiller, ChainIdFiller>>>,
>,
WalletFiller<EthereumWallet>,
>,
ReqwestProvider,
Http<Client>,
Ethereum,
Expand All @@ -114,5 +128,5 @@ pub async fn deploy_chunk_payments_contract(
.on_http(rpc_url);

// Deploy the contract.
ChunkPayments::deploy(provider, token_address).await
DataPayments::deploy(provider, token_address).await
}
20 changes: 15 additions & 5 deletions evmlib/src/wallet.rs
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
use std::collections::BTreeMap;

use crate::common::{Address, QuoteHash, QuotePayment, TxHash, U256};
use crate::contract::chunk_payments::{ChunkPayments, MAX_TRANSFERS_PER_TRANSACTION};
use crate::contract::chunk_payments::{DataPayments, MAX_TRANSFERS_PER_TRANSACTION};
use crate::contract::network_token::NetworkToken;
use crate::contract::{chunk_payments, network_token};
use crate::Network;
use alloy::network::{Ethereum, EthereumWallet, NetworkWallet, TransactionBuilder};
use alloy::providers::fillers::{
ChainIdFiller, FillProvider, GasFiller, JoinFill, NonceFiller, RecommendedFiller, WalletFiller,
BlobGasFiller, ChainIdFiller, FillProvider, GasFiller, JoinFill, NonceFiller, WalletFiller,
};
use alloy::providers::{Identity, Provider, ProviderBuilder, ReqwestProvider};
use alloy::rpc::types::TransactionRequest;
Expand Down Expand Up @@ -123,7 +123,10 @@ fn from_private_key(private_key: &str) -> Result<EthereumWallet, Error> {
fn http_provider(
rpc_url: reqwest::Url,
) -> FillProvider<
JoinFill<JoinFill<JoinFill<Identity, GasFiller>, NonceFiller>, ChainIdFiller>,
JoinFill<
Identity,
JoinFill<GasFiller, JoinFill<BlobGasFiller, JoinFill<NonceFiller, ChainIdFiller>>>,
>,
ReqwestProvider,
Http<Client>,
Ethereum,
Expand All @@ -133,11 +136,18 @@ fn http_provider(
.on_http(rpc_url)
}

#[allow(clippy::type_complexity)]
fn http_provider_with_wallet(
rpc_url: reqwest::Url,
wallet: EthereumWallet,
) -> FillProvider<
JoinFill<RecommendedFiller, WalletFiller<EthereumWallet>>,
JoinFill<
JoinFill<
Identity,
JoinFill<GasFiller, JoinFill<BlobGasFiller, JoinFill<NonceFiller, ChainIdFiller>>>,
>,
WalletFiller<EthereumWallet>,
>,
ReqwestProvider,
Http<Client>,
Ethereum,
Expand Down Expand Up @@ -241,7 +251,7 @@ pub async fn pay_for_quotes<T: IntoIterator<Item = QuotePayment>>(
.map_err(|err| PayForQuotesError(Error::from(err), tx_hashes_by_quote.clone()))?;

let provider = http_provider_with_wallet(network.rpc_url().clone(), wallet);
let chunk_payments = ChunkPayments::new(*network.chunk_payments_address(), provider);
let chunk_payments = DataPayments::new(*network.chunk_payments_address(), provider);

// Divide transfers over multiple transactions if they exceed the max per transaction.
let chunks = payments.chunks(MAX_TRANSFERS_PER_TRANSACTION);
Expand Down
40 changes: 33 additions & 7 deletions evmlib/tests/chunk_payments.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,14 @@ use alloy::network::{Ethereum, EthereumWallet};
use alloy::node_bindings::AnvilInstance;
use alloy::primitives::utils::parse_ether;
use alloy::providers::ext::AnvilApi;
use alloy::providers::fillers::{FillProvider, JoinFill, RecommendedFiller, WalletFiller};
use alloy::providers::{ProviderBuilder, ReqwestProvider, WalletProvider};
use alloy::providers::fillers::{
BlobGasFiller, ChainIdFiller, FillProvider, GasFiller, JoinFill, NonceFiller, WalletFiller,
};
use alloy::providers::{Identity, ProviderBuilder, ReqwestProvider, WalletProvider};
use alloy::signers::local::{LocalSigner, PrivateKeySigner};
use alloy::transports::http::{Client, Http};
use evmlib::common::U256;
use evmlib::contract::chunk_payments::{ChunkPayments, MAX_TRANSFERS_PER_TRANSACTION};
use evmlib::contract::chunk_payments::{DataPayments, MAX_TRANSFERS_PER_TRANSACTION};
use evmlib::contract::network_token::NetworkToken;
use evmlib::testnet::{deploy_chunk_payments_contract, deploy_network_token_contract, start_node};
use evmlib::wallet::wallet_address;
Expand All @@ -20,17 +22,35 @@ async fn setup() -> (
NetworkToken<
Http<Client>,
FillProvider<
JoinFill<RecommendedFiller, WalletFiller<EthereumWallet>>,
JoinFill<
JoinFill<
Identity,
JoinFill<
GasFiller,
JoinFill<BlobGasFiller, JoinFill<NonceFiller, ChainIdFiller>>,
>,
>,
WalletFiller<EthereumWallet>,
>,
ReqwestProvider,
Http<Client>,
Ethereum,
>,
Ethereum,
>,
ChunkPayments<
DataPayments<
Http<Client>,
FillProvider<
JoinFill<RecommendedFiller, WalletFiller<EthereumWallet>>,
JoinFill<
JoinFill<
Identity,
JoinFill<
GasFiller,
JoinFill<BlobGasFiller, JoinFill<NonceFiller, ChainIdFiller>>,
>,
>,
WalletFiller<EthereumWallet>,
>,
ReqwestProvider,
Http<Client>,
Ethereum,
Expand All @@ -54,7 +74,13 @@ async fn setup() -> (
async fn provider_with_gas_funded_wallet(
anvil: &AnvilInstance,
) -> FillProvider<
JoinFill<RecommendedFiller, WalletFiller<EthereumWallet>>,
JoinFill<
JoinFill<
Identity,
JoinFill<GasFiller, JoinFill<BlobGasFiller, JoinFill<NonceFiller, ChainIdFiller>>>,
>,
WalletFiller<EthereumWallet>,
>,
ReqwestProvider,
Http<Client>,
Ethereum,
Expand Down
17 changes: 14 additions & 3 deletions evmlib/tests/network_token.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,10 @@ mod common;
use alloy::network::{Ethereum, EthereumWallet, NetworkWallet};
use alloy::node_bindings::AnvilInstance;
use alloy::primitives::U256;
use alloy::providers::fillers::{FillProvider, JoinFill, RecommendedFiller, WalletFiller};
use alloy::providers::{ReqwestProvider, WalletProvider};
use alloy::providers::fillers::{
BlobGasFiller, ChainIdFiller, FillProvider, GasFiller, JoinFill, NonceFiller, WalletFiller,
};
use alloy::providers::{Identity, ReqwestProvider, WalletProvider};
use alloy::signers::local::PrivateKeySigner;
use alloy::transports::http::{Client, Http};
use evmlib::contract::network_token::NetworkToken;
Expand All @@ -17,7 +19,16 @@ async fn setup() -> (
NetworkToken<
Http<Client>,
FillProvider<
JoinFill<RecommendedFiller, WalletFiller<EthereumWallet>>,
JoinFill<
JoinFill<
Identity,
JoinFill<
GasFiller,
JoinFill<BlobGasFiller, JoinFill<NonceFiller, ChainIdFiller>>,
>,
>,
WalletFiller<EthereumWallet>,
>,
ReqwestProvider,
Http<Client>,
Ethereum,
Expand Down
Loading