Merge pull request #210 from propeller-heads/encoding/dc/ENG-4552-upgrade-alloy
feat: Upgrade alloy to "1.0.6"
This commit is contained in:
1298
Cargo.lock
generated
1298
Cargo.lock
generated
File diff suppressed because it is too large
Load Diff
10
Cargo.toml
10
Cargo.toml
@@ -28,19 +28,17 @@ thiserror = "1.0.69"
|
|||||||
tokio = { version = "1.38.0", features = ["full"] }
|
tokio = { version = "1.38.0", features = ["full"] }
|
||||||
chrono = "0.4.39"
|
chrono = "0.4.39"
|
||||||
clap = { version = "4.5.3", features = ["derive"] }
|
clap = { version = "4.5.3", features = ["derive"] }
|
||||||
|
|
||||||
alloy = { version = "0.9.2", features = ["providers", "rpc-types-eth", "eip712", "signer-local"], optional = true }
|
|
||||||
alloy-sol-types = { version = "0.8.14", optional = true }
|
|
||||||
alloy-primitives = { version = "0.8.9", optional = true }
|
|
||||||
tycho-common = ">0.66.4"
|
|
||||||
once_cell = "1.20.2"
|
once_cell = "1.20.2"
|
||||||
|
tycho-common = ">0.66.4"
|
||||||
|
|
||||||
|
alloy = { version = "1.0.6", features = ["providers", "rpc-types-eth", "eip712", "signer-local", "node-bindings"], optional = true }
|
||||||
|
|
||||||
[dev-dependencies]
|
[dev-dependencies]
|
||||||
rstest = "0.24.0"
|
rstest = "0.24.0"
|
||||||
|
|
||||||
[features]
|
[features]
|
||||||
default = ["evm"]
|
default = ["evm"]
|
||||||
evm = ["alloy", "alloy-sol-types", "alloy-primitives"]
|
evm = ["alloy"]
|
||||||
fork-tests = []
|
fork-tests = []
|
||||||
|
|
||||||
[profile.bench]
|
[profile.bench]
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
use std::io::{self, Read};
|
use std::io::{self, Read};
|
||||||
|
|
||||||
use alloy_sol_types::SolValue;
|
use alloy::sol_types::SolValue;
|
||||||
use clap::{Parser, Subcommand};
|
use clap::{Parser, Subcommand};
|
||||||
use tycho_common::{hex_bytes::Bytes, models::Chain};
|
use tycho_common::{hex_bytes::Bytes, models::Chain};
|
||||||
use tycho_execution::encoding::{
|
use tycho_execution::encoding::{
|
||||||
|
|||||||
@@ -1,12 +1,12 @@
|
|||||||
use std::{str::FromStr, sync::Arc};
|
use std::{str::FromStr, sync::Arc};
|
||||||
|
|
||||||
use alloy::{
|
use alloy::{
|
||||||
|
core::sol,
|
||||||
primitives::{aliases::U48, Address, Bytes as AlloyBytes, TxKind, U160, U256},
|
primitives::{aliases::U48, Address, Bytes as AlloyBytes, TxKind, U160, U256},
|
||||||
providers::{Provider, RootProvider},
|
providers::Provider,
|
||||||
rpc::types::{TransactionInput, TransactionRequest},
|
rpc::types::{TransactionInput, TransactionRequest},
|
||||||
transports::BoxTransport,
|
sol_types::SolValue,
|
||||||
};
|
};
|
||||||
use alloy_sol_types::{sol, SolValue};
|
|
||||||
use chrono::Utc;
|
use chrono::Utc;
|
||||||
use num_bigint::BigUint;
|
use num_bigint::BigUint;
|
||||||
use tokio::{
|
use tokio::{
|
||||||
@@ -19,7 +19,7 @@ use crate::encoding::{
|
|||||||
errors::EncodingError,
|
errors::EncodingError,
|
||||||
evm::{
|
evm::{
|
||||||
encoding_utils::encode_input,
|
encoding_utils::encode_input,
|
||||||
utils::{biguint_to_u256, bytes_to_address, get_client, get_runtime},
|
utils::{biguint_to_u256, bytes_to_address, get_client, get_runtime, EVMProvider},
|
||||||
},
|
},
|
||||||
models,
|
models,
|
||||||
};
|
};
|
||||||
@@ -29,7 +29,7 @@ use crate::encoding::{
|
|||||||
#[derive(Clone)]
|
#[derive(Clone)]
|
||||||
pub struct Permit2 {
|
pub struct Permit2 {
|
||||||
address: Address,
|
address: Address,
|
||||||
client: Arc<RootProvider<BoxTransport>>,
|
client: EVMProvider,
|
||||||
runtime_handle: Handle,
|
runtime_handle: Handle,
|
||||||
// Store the runtime to prevent it from being dropped before use.
|
// Store the runtime to prevent it from being dropped before use.
|
||||||
// This is required since tycho-execution does not have a pre-existing runtime.
|
// This is required since tycho-execution does not have a pre-existing runtime.
|
||||||
@@ -132,16 +132,15 @@ impl Permit2 {
|
|||||||
|
|
||||||
let output = block_in_place(|| {
|
let output = block_in_place(|| {
|
||||||
self.runtime_handle
|
self.runtime_handle
|
||||||
.block_on(async { self.client.call(&tx).await })
|
.block_on(async { self.client.call(tx).await })
|
||||||
});
|
});
|
||||||
match output {
|
match output {
|
||||||
Ok(response) => {
|
Ok(response) => {
|
||||||
let allowance: Allowance =
|
let allowance: Allowance = Allowance::abi_decode(&response).map_err(|_| {
|
||||||
Allowance::abi_decode(&response, true).map_err(|_| {
|
EncodingError::FatalError(
|
||||||
EncodingError::FatalError(
|
"Failed to decode response for permit2 allowance".to_string(),
|
||||||
"Failed to decode response for permit2 allowance".to_string(),
|
)
|
||||||
)
|
})?;
|
||||||
})?;
|
|
||||||
Ok(allowance)
|
Ok(allowance)
|
||||||
}
|
}
|
||||||
Err(err) => Err(EncodingError::RecoverableError(format!(
|
Err(err) => Err(EncodingError::RecoverableError(format!(
|
||||||
@@ -183,8 +182,10 @@ impl Permit2 {
|
|||||||
mod tests {
|
mod tests {
|
||||||
use std::str::FromStr;
|
use std::str::FromStr;
|
||||||
|
|
||||||
use alloy::signers::local::PrivateKeySigner;
|
use alloy::{
|
||||||
use alloy_primitives::{Uint, B256};
|
primitives::{Uint, B256},
|
||||||
|
signers::local::PrivateKeySigner,
|
||||||
|
};
|
||||||
use num_bigint::BigUint;
|
use num_bigint::BigUint;
|
||||||
use tycho_common::models::Chain as TychoCommonChain;
|
use tycho_common::models::Chain as TychoCommonChain;
|
||||||
|
|
||||||
|
|||||||
@@ -1,12 +1,11 @@
|
|||||||
use std::sync::Arc;
|
use std::sync::Arc;
|
||||||
|
|
||||||
use alloy::{
|
use alloy::{
|
||||||
providers::{Provider, RootProvider},
|
primitives::{Address, Bytes, TxKind, U256},
|
||||||
|
providers::Provider,
|
||||||
rpc::types::{TransactionInput, TransactionRequest},
|
rpc::types::{TransactionInput, TransactionRequest},
|
||||||
transports::BoxTransport,
|
sol_types::SolValue,
|
||||||
};
|
};
|
||||||
use alloy_primitives::{Address, Bytes, TxKind, U256};
|
|
||||||
use alloy_sol_types::SolValue;
|
|
||||||
use tokio::{
|
use tokio::{
|
||||||
runtime::{Handle, Runtime},
|
runtime::{Handle, Runtime},
|
||||||
task::block_in_place,
|
task::block_in_place,
|
||||||
@@ -16,13 +15,13 @@ use crate::encoding::{
|
|||||||
errors::EncodingError,
|
errors::EncodingError,
|
||||||
evm::{
|
evm::{
|
||||||
encoding_utils::encode_input,
|
encoding_utils::encode_input,
|
||||||
utils::{get_client, get_runtime},
|
utils::{get_client, get_runtime, EVMProvider},
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
/// A manager for checking if an approval is needed for interacting with a certain spender.
|
/// A manager for checking if an approval is needed for interacting with a certain spender.
|
||||||
pub struct ProtocolApprovalsManager {
|
pub struct ProtocolApprovalsManager {
|
||||||
client: Arc<RootProvider<BoxTransport>>,
|
client: EVMProvider,
|
||||||
runtime_handle: Handle,
|
runtime_handle: Handle,
|
||||||
// Store the runtime to prevent it from being dropped before use.
|
// Store the runtime to prevent it from being dropped before use.
|
||||||
// This is required since tycho-execution does not have a pre-existing runtime.
|
// This is required since tycho-execution does not have a pre-existing runtime.
|
||||||
@@ -56,11 +55,11 @@ impl ProtocolApprovalsManager {
|
|||||||
|
|
||||||
let output = block_in_place(|| {
|
let output = block_in_place(|| {
|
||||||
self.runtime_handle
|
self.runtime_handle
|
||||||
.block_on(async { self.client.call(&tx).await })
|
.block_on(async { self.client.call(tx).await })
|
||||||
});
|
});
|
||||||
match output {
|
match output {
|
||||||
Ok(response) => {
|
Ok(response) => {
|
||||||
let allowance: U256 = U256::abi_decode(&response, true).map_err(|_| {
|
let allowance: U256 = U256::abi_decode(&response).map_err(|_| {
|
||||||
EncodingError::FatalError("Failed to decode response for allowance".to_string())
|
EncodingError::FatalError("Failed to decode response for allowance".to_string())
|
||||||
})?;
|
})?;
|
||||||
|
|
||||||
|
|||||||
@@ -1,7 +1,6 @@
|
|||||||
use std::{collections::HashMap, str::FromStr};
|
use std::{collections::HashMap, str::FromStr};
|
||||||
|
|
||||||
use alloy::signers::local::PrivateKeySigner;
|
use alloy::{primitives::B256, signers::local::PrivateKeySigner};
|
||||||
use alloy_primitives::B256;
|
|
||||||
use tycho_common::{models::Chain as TychoCommonChain, Bytes};
|
use tycho_common::{models::Chain as TychoCommonChain, Bytes};
|
||||||
|
|
||||||
use crate::encoding::{
|
use crate::encoding::{
|
||||||
|
|||||||
@@ -1,11 +1,10 @@
|
|||||||
use std::str::FromStr;
|
use std::str::FromStr;
|
||||||
|
|
||||||
use alloy::{
|
use alloy::{
|
||||||
primitives::U256,
|
primitives::{Address, Keccak256, U256},
|
||||||
signers::{local::PrivateKeySigner, Signature, SignerSync},
|
signers::{local::PrivateKeySigner, Signature, SignerSync},
|
||||||
|
sol_types::{eip712_domain, SolStruct, SolValue},
|
||||||
};
|
};
|
||||||
use alloy_primitives::{Address, Keccak256};
|
|
||||||
use alloy_sol_types::{eip712_domain, SolStruct, SolValue};
|
|
||||||
use num_bigint::BigUint;
|
use num_bigint::BigUint;
|
||||||
use tycho_common::Bytes;
|
use tycho_common::Bytes;
|
||||||
|
|
||||||
|
|||||||
@@ -73,7 +73,7 @@ pub fn group_swaps(swaps: Vec<Swap>) -> Vec<SwapGroup> {
|
|||||||
mod tests {
|
mod tests {
|
||||||
use std::str::FromStr;
|
use std::str::FromStr;
|
||||||
|
|
||||||
use alloy_primitives::hex;
|
use alloy::primitives::hex;
|
||||||
use tycho_common::{models::protocol::ProtocolComponent, Bytes};
|
use tycho_common::{models::protocol::ProtocolComponent, Bytes};
|
||||||
|
|
||||||
use super::*;
|
use super::*;
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
use std::{collections::HashSet, str::FromStr};
|
use std::{collections::HashSet, str::FromStr};
|
||||||
|
|
||||||
use alloy_primitives::{aliases::U24, U8};
|
use alloy::primitives::{aliases::U24, U8};
|
||||||
use tycho_common::Bytes;
|
use tycho_common::Bytes;
|
||||||
|
|
||||||
use crate::encoding::{
|
use crate::encoding::{
|
||||||
@@ -510,8 +510,7 @@ impl StrategyEncoder for SplitSwapStrategyEncoder {
|
|||||||
mod tests {
|
mod tests {
|
||||||
use std::{collections::HashMap, str::FromStr};
|
use std::{collections::HashMap, str::FromStr};
|
||||||
|
|
||||||
use alloy::hex::encode;
|
use alloy::{hex::encode, primitives::hex};
|
||||||
use alloy_primitives::hex;
|
|
||||||
use num_bigint::{BigInt, BigUint};
|
use num_bigint::{BigInt, BigUint};
|
||||||
use tycho_common::{
|
use tycho_common::{
|
||||||
models::{protocol::ProtocolComponent, Chain as TychoCommonChain},
|
models::{protocol::ProtocolComponent, Chain as TychoCommonChain},
|
||||||
|
|||||||
@@ -111,7 +111,7 @@ impl TransferOptimization {
|
|||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod tests {
|
mod tests {
|
||||||
use alloy_primitives::hex;
|
use alloy::primitives::hex;
|
||||||
use rstest::rstest;
|
use rstest::rstest;
|
||||||
use tycho_common::models::protocol::ProtocolComponent;
|
use tycho_common::models::protocol::ProtocolComponent;
|
||||||
|
|
||||||
|
|||||||
@@ -1,7 +1,9 @@
|
|||||||
use std::{collections::HashMap, str::FromStr};
|
use std::{collections::HashMap, str::FromStr};
|
||||||
|
|
||||||
use alloy_primitives::{Address, Bytes as AlloyBytes, U8};
|
use alloy::{
|
||||||
use alloy_sol_types::SolValue;
|
primitives::{Address, Bytes as AlloyBytes, U8},
|
||||||
|
sol_types::SolValue,
|
||||||
|
};
|
||||||
use serde_json::from_str;
|
use serde_json::from_str;
|
||||||
use tycho_common::Bytes;
|
use tycho_common::Bytes;
|
||||||
|
|
||||||
|
|||||||
@@ -1221,9 +1221,12 @@ mod tests {
|
|||||||
mod integration {
|
mod integration {
|
||||||
use std::{collections::HashMap, str::FromStr};
|
use std::{collections::HashMap, str::FromStr};
|
||||||
|
|
||||||
use alloy::{hex::encode, signers::local::PrivateKeySigner};
|
use alloy::{
|
||||||
use alloy_primitives::{hex, Address, B256, U256};
|
hex::encode,
|
||||||
use alloy_sol_types::SolValue;
|
primitives::{hex, Address, B256, U256},
|
||||||
|
signers::local::PrivateKeySigner,
|
||||||
|
sol_types::SolValue,
|
||||||
|
};
|
||||||
use num_bigint::{BigInt, BigUint};
|
use num_bigint::{BigInt, BigUint};
|
||||||
use tycho_common::{models::protocol::ProtocolComponent, Bytes};
|
use tycho_common::{models::protocol::ProtocolComponent, Bytes};
|
||||||
|
|
||||||
|
|||||||
@@ -6,11 +6,13 @@ use std::{
|
|||||||
};
|
};
|
||||||
|
|
||||||
use alloy::{
|
use alloy::{
|
||||||
providers::{ProviderBuilder, RootProvider},
|
primitives::{aliases::U24, Address, U256, U8},
|
||||||
transports::BoxTransport,
|
providers::{
|
||||||
|
fillers::{BlobGasFiller, ChainIdFiller, FillProvider, GasFiller, JoinFill, NonceFiller},
|
||||||
|
ProviderBuilder, RootProvider,
|
||||||
|
},
|
||||||
|
sol_types::SolValue,
|
||||||
};
|
};
|
||||||
use alloy_primitives::{aliases::U24, Address, U256, U8};
|
|
||||||
use alloy_sol_types::SolValue;
|
|
||||||
use num_bigint::BigUint;
|
use num_bigint::BigUint;
|
||||||
use once_cell::sync::Lazy;
|
use once_cell::sync::Lazy;
|
||||||
use tokio::runtime::{Handle, Runtime};
|
use tokio::runtime::{Handle, Runtime};
|
||||||
@@ -88,13 +90,23 @@ pub fn get_runtime() -> Result<(Handle, Option<Arc<Runtime>>), EncodingError> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub type EVMProvider = Arc<
|
||||||
|
FillProvider<
|
||||||
|
JoinFill<
|
||||||
|
alloy::providers::Identity,
|
||||||
|
JoinFill<GasFiller, JoinFill<BlobGasFiller, JoinFill<NonceFiller, ChainIdFiller>>>,
|
||||||
|
>,
|
||||||
|
RootProvider,
|
||||||
|
>,
|
||||||
|
>;
|
||||||
|
|
||||||
/// Gets the client used for interacting with the EVM-compatible network.
|
/// Gets the client used for interacting with the EVM-compatible network.
|
||||||
pub async fn get_client() -> Result<Arc<RootProvider<BoxTransport>>, EncodingError> {
|
pub async fn get_client() -> Result<EVMProvider, EncodingError> {
|
||||||
dotenv::dotenv().ok();
|
dotenv::dotenv().ok();
|
||||||
let eth_rpc_url = env::var("RPC_URL")
|
let eth_rpc_url = env::var("RPC_URL")
|
||||||
.map_err(|_| EncodingError::FatalError("Missing RPC_URL in environment".to_string()))?;
|
.map_err(|_| EncodingError::FatalError("Missing RPC_URL in environment".to_string()))?;
|
||||||
let client = ProviderBuilder::new()
|
let client = ProviderBuilder::new()
|
||||||
.on_builtin(ð_rpc_url)
|
.connect(ð_rpc_url)
|
||||||
.await
|
.await
|
||||||
.map_err(|_| EncodingError::FatalError("Failed to build provider".to_string()))?;
|
.map_err(|_| EncodingError::FatalError("Failed to build provider".to_string()))?;
|
||||||
Ok(Arc::new(client))
|
Ok(Arc::new(client))
|
||||||
|
|||||||
Reference in New Issue
Block a user