diff --git a/CHANGELOG.md b/CHANGELOG.md index 57f27d1..e9d50b4 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,27 @@ +## [0.108.0](https://github.com/propeller-heads/tycho-execution/compare/0.107.0...0.108.0) (2025-07-11) + + +### Features + +* Upgrade tycho-common ([8458b46](https://github.com/propeller-heads/tycho-execution/commit/8458b4628e351daaf4d4a639afc5099903107ff6)) +* Upgrade tycho-common ([effc25c](https://github.com/propeller-heads/tycho-execution/commit/effc25c2d723107a56260190d6f7b5c7b8c42e4e)) +* Upgrade tycho-common ([cb6042e](https://github.com/propeller-heads/tycho-execution/commit/cb6042ea7974faee93c1a87ca84fc6677c999548)) +* Use Chain from tycho-core and remove current implementation ([2c25b5a](https://github.com/propeller-heads/tycho-execution/commit/2c25b5a18f06beb61d93530660d9530bf0c46b36)) + +## [0.107.0](https://github.com/propeller-heads/tycho-execution/compare/0.106.0...0.107.0) (2025-07-10) + + +### Features + +* (WIP) Handle approvals in UniswapXFiller ([e243667](https://github.com/propeller-heads/tycho-execution/commit/e243667f9ee8ec8e79fc5196da6960b19cd120b7)) +* Handle native ETH outputs ([3752c15](https://github.com/propeller-heads/tycho-execution/commit/3752c155ea89d4d2d91be98f2c5fa79264a45999)) + + +### Bug Fixes + +* silence slither on native address setting ([1b6a24f](https://github.com/propeller-heads/tycho-execution/commit/1b6a24fd75b91de7570f110e87d81ed081639bb7)) +* use encodePacked to encode if approval needed ([9e2f228](https://github.com/propeller-heads/tycho-execution/commit/9e2f228a470d163b71cac22a0f95116716490772)) + ## [0.106.0](https://github.com/propeller-heads/tycho-execution/compare/0.105.0...0.106.0) (2025-07-09) diff --git a/Cargo.lock b/Cargo.lock index 099a723..c39cd08 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -4634,15 +4634,16 @@ checksum = "e421abadd41a4225275504ea4d6566923418b7f05506fbc9c0fe86ba7396114b" [[package]] name = "tycho-common" -version = "0.70.7" +version = "0.76.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c4da82c4239c76011b8edc19b5d2a2db989c9ff1f74ae6a3dea21486e9b53234" +checksum = "e72ed04dc9d41942c886fc3d58af5b0e23a3e4783ac7294ed7cea61e022a5c4d" dependencies = [ "anyhow", "async-trait", "bytes", "chrono", "hex", + "num-bigint", "rand 0.8.5", "serde", "serde_json", @@ -4658,7 +4659,7 @@ dependencies = [ [[package]] name = "tycho-execution" -version = "0.106.0" +version = "0.108.0" dependencies = [ "alloy", "chrono", diff --git a/Cargo.toml b/Cargo.toml index 65c9e61..63d9cec 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "tycho-execution" -version = "0.106.0" +version = "0.108.0" edition = "2021" description = "Provides tools for encoding and executing swaps against Tycho router and protocol executors." repository = "https://github.com/propeller-heads/tycho-execution" @@ -37,7 +37,7 @@ tokio = { version = "1.38.0", features = ["full"] } chrono = "0.4.39" clap = { version = "4.5.3", features = ["derive"] } once_cell = "1.20.2" -tycho-common = ">0.66.4" +tycho-common = ">0.75.1" alloy = { version = "1.0.6", features = ["providers", "rpc-types-eth", "eip712", "signer-local", "node-bindings"], optional = true } diff --git a/src/encoding/evm/approvals/permit2.rs b/src/encoding/evm/approvals/permit2.rs index 598cb9d..83610ce 100644 --- a/src/encoding/evm/approvals/permit2.rs +++ b/src/encoding/evm/approvals/permit2.rs @@ -187,10 +187,10 @@ mod tests { signers::local::PrivateKeySigner, }; use num_bigint::BigUint; - use tycho_common::models::Chain as TychoCommonChain; + use tycho_common::models::Chain; use super::*; - use crate::encoding::{evm::encoding_utils::sign_permit, models::Chain}; + use crate::encoding::evm::encoding_utils::sign_permit; // These two implementations are to avoid comparing the expiration and sig_deadline fields // because they are timestamps @@ -224,7 +224,7 @@ mod tests { } fn eth_chain() -> Chain { - TychoCommonChain::Ethereum.into() + Chain::Ethereum } #[test] @@ -334,7 +334,7 @@ mod tests { let sol_permit: PermitSingle = PermitSingle::try_from(&permit).expect("Failed to convert to PermitSingle"); - let signature = sign_permit(eth_chain().id, &permit, signer).unwrap(); + let signature = sign_permit(eth_chain().id(), &permit, signer).unwrap(); let encoded = (bytes_to_address(&anvil_account).unwrap(), sol_permit, signature.as_bytes().to_vec()) .abi_encode(); diff --git a/src/encoding/evm/encoder_builders.rs b/src/encoding/evm/encoder_builders.rs index 6ad4d24..b6b6497 100644 --- a/src/encoding/evm/encoder_builders.rs +++ b/src/encoding/evm/encoder_builders.rs @@ -1,7 +1,7 @@ use std::{collections::HashMap, str::FromStr}; use alloy::{primitives::B256, signers::local::PrivateKeySigner}; -use tycho_common::{models::Chain as TychoCommonChain, Bytes}; +use tycho_common::{models::Chain, Bytes}; use crate::encoding::{ errors::EncodingError, @@ -10,7 +10,7 @@ use crate::encoding::{ swap_encoder::swap_encoder_registry::SwapEncoderRegistry, tycho_encoders::{TychoExecutorEncoder, TychoRouterEncoder}, }, - models::{Chain, UserTransferType}, + models::UserTransferType, tycho_encoder::TychoEncoder, }; @@ -41,8 +41,8 @@ impl TychoRouterEncoderBuilder { user_transfer_type: None, } } - pub fn chain(mut self, chain: TychoCommonChain) -> Self { - self.chain = Some(chain.into()); + pub fn chain(mut self, chain: Chain) -> Self { + self.chain = Some(chain); self } @@ -85,10 +85,10 @@ impl TychoRouterEncoderBuilder { if let Some(address) = self.router_address { tycho_router_address = address; } else { - let default_routers: HashMap = + let default_routers: HashMap = serde_json::from_str(DEFAULT_ROUTERS_JSON)?; tycho_router_address = default_routers - .get(&chain.name) + .get(&chain) .ok_or(EncodingError::FatalError( "No default router address found for chain".to_string(), ))? @@ -96,7 +96,7 @@ impl TychoRouterEncoderBuilder { } let swap_encoder_registry = - SwapEncoderRegistry::new(self.executors_file_path.clone(), chain.clone())?; + SwapEncoderRegistry::new(self.executors_file_path.clone(), chain)?; let signer = if let Some(pk) = self.swapper_pk { let pk = B256::from_str(&pk).map_err(|_| { @@ -141,8 +141,8 @@ impl TychoExecutorEncoderBuilder { pub fn new() -> Self { TychoExecutorEncoderBuilder { chain: None, executors_file_path: None } } - pub fn chain(mut self, chain: TychoCommonChain) -> Self { - self.chain = Some(chain.into()); + pub fn chain(mut self, chain: Chain) -> Self { + self.chain = Some(chain); self } @@ -158,7 +158,7 @@ impl TychoExecutorEncoderBuilder { pub fn build(self) -> Result, EncodingError> { if let Some(chain) = self.chain { let swap_encoder_registry = - SwapEncoderRegistry::new(self.executors_file_path.clone(), chain.clone())?; + SwapEncoderRegistry::new(self.executors_file_path.clone(), chain)?; Ok(Box::new(TychoExecutorEncoder::new(swap_encoder_registry)?)) } else { Err(EncodingError::FatalError( diff --git a/src/encoding/evm/strategy_encoder/strategy_encoders.rs b/src/encoding/evm/strategy_encoder/strategy_encoders.rs index 7c551e0..88eb463 100644 --- a/src/encoding/evm/strategy_encoder/strategy_encoders.rs +++ b/src/encoding/evm/strategy_encoder/strategy_encoders.rs @@ -1,7 +1,7 @@ use std::{collections::HashSet, str::FromStr}; use alloy::primitives::{aliases::U24, U8}; -use tycho_common::Bytes; +use tycho_common::{models::Chain, Bytes}; use crate::encoding::{ errors::EncodingError, @@ -14,7 +14,7 @@ use crate::encoding::{ swap_encoder::swap_encoder_registry::SwapEncoderRegistry, utils::{get_token_position, percentage_to_uint24, ple_encode}, }, - models::{Chain, EncodedSolution, EncodingContext, NativeAction, Solution, UserTransferType}, + models::{EncodedSolution, EncodingContext, NativeAction, Solution, UserTransferType}, strategy_encoder::StrategyEncoder, swap_encoder::SwapEncoder, }; @@ -52,8 +52,8 @@ impl SingleSwapStrategyEncoder { swap_encoder_registry, router_address: router_address.clone(), transfer_optimization: TransferOptimization::new( - chain.native_token()?, - chain.wrapped_token()?, + chain.native_token().address, + chain.wrapped_native_token().address, user_transfer_type, router_address, ), @@ -186,16 +186,18 @@ impl SequentialSwapStrategyEncoder { "sequentialSwap(uint256,address,address,uint256,bool,bool,address,bool,bytes)" }.to_string(); + let native_token_address = chain.native_token().address; + let wrapped_token_address = chain.wrapped_native_token().address; Ok(Self { function_signature, swap_encoder_registry, router_address: router_address.clone(), - native_address: chain.native_token()?, - wrapped_address: chain.wrapped_token()?, + native_address: native_token_address.clone(), + wrapped_address: wrapped_token_address.clone(), sequential_swap_validator: SequentialSwapValidator, transfer_optimization: TransferOptimization::new( - chain.native_token()?, - chain.wrapped_token()?, + native_token_address, + wrapped_token_address, user_transfer_type, router_address, ), @@ -338,16 +340,18 @@ impl SplitSwapStrategyEncoder { } else { "splitSwap(uint256,address,address,uint256,bool,bool,uint256,address,bool,bytes)" }.to_string(); + let native_token_address = chain.native_token().address; + let wrapped_token_address = chain.wrapped_native_token().address; Ok(Self { function_signature, swap_encoder_registry, - native_address: chain.native_token()?, - wrapped_address: chain.wrapped_token()?, + native_address: native_token_address.clone(), + wrapped_address: wrapped_token_address.clone(), split_swap_validator: SplitSwapValidator, router_address: router_address.clone(), transfer_optimization: TransferOptimization::new( - chain.native_token()?, - chain.wrapped_token()?, + native_token_address, + wrapped_token_address, user_transfer_type, router_address, ), @@ -508,7 +512,7 @@ mod tests { use alloy::{hex::encode, primitives::hex}; use num_bigint::{BigInt, BigUint}; use tycho_common::{ - models::{protocol::ProtocolComponent, Chain as TychoCommonChain}, + models::{protocol::ProtocolComponent, Chain}, Bytes, }; @@ -516,7 +520,7 @@ mod tests { use crate::encoding::models::Swap; fn eth_chain() -> Chain { - TychoCommonChain::Ethereum.into() + Chain::Ethereum } fn weth() -> Bytes { diff --git a/src/encoding/evm/swap_encoder/builder.rs b/src/encoding/evm/swap_encoder/builder.rs index 165758f..0797930 100644 --- a/src/encoding/evm/swap_encoder/builder.rs +++ b/src/encoding/evm/swap_encoder/builder.rs @@ -1,12 +1,13 @@ use std::collections::HashMap; +use tycho_common::models::Chain; + use crate::encoding::{ errors::EncodingError, evm::swap_encoder::swap_encoders::{ BalancerV2SwapEncoder, BalancerV3SwapEncoder, CurveSwapEncoder, EkuboSwapEncoder, MaverickV2SwapEncoder, UniswapV2SwapEncoder, UniswapV3SwapEncoder, UniswapV4SwapEncoder, }, - models::Chain, swap_encoder::SwapEncoder, }; diff --git a/src/encoding/evm/swap_encoder/swap_encoder_registry.rs b/src/encoding/evm/swap_encoder/swap_encoder_registry.rs index a71e187..221ea76 100644 --- a/src/encoding/evm/swap_encoder/swap_encoder_registry.rs +++ b/src/encoding/evm/swap_encoder/swap_encoder_registry.rs @@ -1,12 +1,13 @@ use std::{collections::HashMap, fs}; +use tycho_common::models::Chain; + use crate::encoding::{ errors::EncodingError, evm::{ constants::{DEFAULT_EXECUTORS_JSON, PROTOCOL_SPECIFIC_CONFIG}, swap_encoder::builder::SwapEncoderBuilder, }, - models::Chain, swap_encoder::SwapEncoder, }; @@ -30,15 +31,15 @@ impl SwapEncoderRegistry { } else { DEFAULT_EXECUTORS_JSON.to_string() }; - let config: HashMap> = serde_json::from_str(&config_str)?; + let config: HashMap> = serde_json::from_str(&config_str)?; let executors = config - .get(&chain.name) + .get(&chain) .ok_or(EncodingError::FatalError("No executors found for chain".to_string()))?; - let protocol_specific_config: HashMap>> = + let protocol_specific_config: HashMap>> = serde_json::from_str(PROTOCOL_SPECIFIC_CONFIG)?; let protocol_specific_config = protocol_specific_config - .get(&chain.name) + .get(&chain) .ok_or(EncodingError::FatalError( "No protocol specific config found for chain".to_string(), ))?; @@ -47,7 +48,7 @@ impl SwapEncoderRegistry { let builder = SwapEncoderBuilder::new( protocol, executor_address, - chain.clone(), + chain, protocol_specific_config .get(protocol) .cloned(), diff --git a/src/encoding/evm/swap_encoder/swap_encoders.rs b/src/encoding/evm/swap_encoder/swap_encoders.rs index c7e30e6..ae79a26 100644 --- a/src/encoding/evm/swap_encoder/swap_encoders.rs +++ b/src/encoding/evm/swap_encoder/swap_encoders.rs @@ -5,7 +5,7 @@ use alloy::{ sol_types::SolValue, }; use serde_json::from_str; -use tycho_common::Bytes; +use tycho_common::{models::Chain, Bytes}; use crate::encoding::{ errors::EncodingError, @@ -13,7 +13,7 @@ use crate::encoding::{ approvals::protocol_approvals_manager::ProtocolApprovalsManager, utils::{bytes_to_address, get_static_attribute, pad_to_fixed_size}, }, - models::{Chain, EncodingContext, Swap}, + models::{EncodingContext, Swap}, swap_encoder::SwapEncoder, }; @@ -466,9 +466,9 @@ impl SwapEncoder for CurveSwapEncoder { .to_string(); Ok(Self { executor_address, - native_token_address: chain.native_token()?, + native_token_address: chain.native_token().address, native_token_curve_address, - wrapped_native_token_address: chain.wrapped_token()?, + wrapped_native_token_address: chain.wrapped_native_token().address, }) } @@ -646,7 +646,7 @@ mod tests { use alloy::hex::encode; use num_bigint::BigInt; use tycho_common::{ - models::{protocol::ProtocolComponent, Chain as TychoCoreChain}, + models::{protocol::ProtocolComponent, Chain}, Bytes, }; @@ -681,7 +681,7 @@ mod tests { }; let encoder = UniswapV2SwapEncoder::new( String::from("0x543778987b293C7E8Cf0722BB2e935ba6f4068D4"), - TychoCoreChain::Ethereum.into(), + Chain::Ethereum, None, ) .unwrap(); @@ -741,7 +741,7 @@ mod tests { }; let encoder = UniswapV3SwapEncoder::new( String::from("0x543778987b293C7E8Cf0722BB2e935ba6f4068D4"), - TychoCoreChain::Ethereum.into(), + Chain::Ethereum, None, ) .unwrap(); @@ -803,7 +803,7 @@ mod tests { }; let encoder = BalancerV2SwapEncoder::new( String::from("0x543778987b293C7E8Cf0722BB2e935ba6f4068D4"), - TychoCoreChain::Ethereum.into(), + Chain::Ethereum, Some(HashMap::from([( "vault_address".to_string(), "0xba12222222228d8ba445958a75a0704d566bf2c8".to_string(), @@ -878,7 +878,7 @@ mod tests { }; let encoder = UniswapV4SwapEncoder::new( String::from("0xF62849F9A0B5Bf2913b396098F7c7019b51A820a"), - TychoCoreChain::Ethereum.into(), + Chain::Ethereum, None, ) .unwrap(); @@ -951,7 +951,7 @@ mod tests { let encoder = UniswapV4SwapEncoder::new( String::from("0x543778987b293C7E8Cf0722BB2e935ba6f4068D4"), - TychoCoreChain::Ethereum.into(), + Chain::Ethereum, None, ) .unwrap(); @@ -1046,7 +1046,7 @@ mod tests { let encoder = UniswapV4SwapEncoder::new( String::from("0xF62849F9A0B5Bf2913b396098F7c7019b51A820a"), - TychoCoreChain::Ethereum.into(), + Chain::Ethereum, None, ) .unwrap(); @@ -1130,9 +1130,7 @@ mod tests { transfer_type: TransferType::Transfer, }; - let encoder = - EkuboSwapEncoder::new(String::default(), TychoCoreChain::Ethereum.into(), None) - .unwrap(); + let encoder = EkuboSwapEncoder::new(String::default(), Chain::Ethereum, None).unwrap(); let encoded_swap = encoder .encode_swap(&swap, &encoding_context) @@ -1163,9 +1161,7 @@ mod tests { let group_token_out = Bytes::from("0xdAC17F958D2ee523a2206206994597C13D831ec7"); // USDT let intermediary_token = Bytes::from("0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48"); // USDC - let encoder = - EkuboSwapEncoder::new(String::default(), TychoCoreChain::Ethereum.into(), None) - .unwrap(); + let encoder = EkuboSwapEncoder::new(String::default(), Chain::Ethereum, None).unwrap(); let encoding_context = EncodingContext { receiver: RECEIVER.into(), @@ -1329,12 +1325,8 @@ mod tests { split: 0f64, user_data: None, }; - let encoder = CurveSwapEncoder::new( - String::default(), - TychoCoreChain::Ethereum.into(), - curve_config(), - ) - .unwrap(); + let encoder = + CurveSwapEncoder::new(String::default(), Chain::Ethereum, curve_config()).unwrap(); let (i, j) = encoder .get_coin_indexes( &swap, @@ -1384,7 +1376,7 @@ mod tests { }; let encoder = CurveSwapEncoder::new( String::from("0x5615dEB798BB3E4dFa0139dFa1b3D433Cc23b72f"), - TychoCoreChain::Ethereum.into(), + Chain::Ethereum, curve_config(), ) .unwrap(); @@ -1456,7 +1448,7 @@ mod tests { }; let encoder = CurveSwapEncoder::new( String::from("0x5615dEB798BB3E4dFa0139dFa1b3D433Cc23b72f"), - TychoCoreChain::Ethereum.into(), + Chain::Ethereum, curve_config(), ) .unwrap(); @@ -1529,7 +1521,7 @@ mod tests { }; let encoder = CurveSwapEncoder::new( String::from("0x5615dEB798BB3E4dFa0139dFa1b3D433Cc23b72f"), - TychoCoreChain::Ethereum.into(), + Chain::Ethereum, Some(HashMap::from([ ( "native_token_address".to_string(), @@ -1603,7 +1595,7 @@ mod tests { }; let encoder = BalancerV3SwapEncoder::new( String::from("0x543778987b293C7E8Cf0722BB2e935ba6f4068D4"), - TychoCoreChain::Ethereum.into(), + Chain::Ethereum, None, ) .unwrap(); @@ -1661,7 +1653,7 @@ mod tests { }; let encoder = MaverickV2SwapEncoder::new( String::from("0x543778987b293C7E8Cf0722BB2e935ba6f4068D4"), - TychoCoreChain::Ethereum.into(), + Chain::Ethereum, None, ) .unwrap(); diff --git a/src/encoding/evm/tycho_encoders.rs b/src/encoding/evm/tycho_encoders.rs index 4ecc366..a317b85 100644 --- a/src/encoding/evm/tycho_encoders.rs +++ b/src/encoding/evm/tycho_encoders.rs @@ -1,7 +1,7 @@ use std::{collections::HashSet, str::FromStr}; use alloy::signers::local::PrivateKeySigner; -use tycho_common::Bytes; +use tycho_common::{models::Chain, Bytes}; use crate::encoding::{ errors::EncodingError, @@ -16,7 +16,7 @@ use crate::encoding::{ swap_encoder::swap_encoder_registry::SwapEncoderRegistry, }, models::{ - Chain, EncodedSolution, EncodingContext, NativeAction, Solution, Transaction, TransferType, + EncodedSolution, EncodingContext, NativeAction, Solution, Transaction, TransferType, UserTransferType, }, strategy_encoder::StrategyEncoder, @@ -61,19 +61,19 @@ impl TychoRouterEncoder { }; Ok(TychoRouterEncoder { single_swap_strategy: SingleSwapStrategyEncoder::new( - chain.clone(), + chain, swap_encoder_registry.clone(), user_transfer_type.clone(), router_address.clone(), )?, sequential_swap_strategy: SequentialSwapStrategyEncoder::new( - chain.clone(), + chain, swap_encoder_registry.clone(), user_transfer_type.clone(), router_address.clone(), )?, split_swap_strategy: SplitSwapStrategyEncoder::new( - chain.clone(), + chain, swap_encoder_registry, user_transfer_type.clone(), router_address.clone(), @@ -153,11 +153,11 @@ impl TychoEncoder for TychoRouterEncoder { let encoded_solution = self.encode_solution(solution)?; let transaction = encode_tycho_router_call( - self.chain.id, + self.chain.id(), encoded_solution, solution, &self.user_transfer_type, - &self.chain.native_token()?, + &self.chain.native_token().address, self.signer.clone(), )?; @@ -186,8 +186,11 @@ impl TychoEncoder for TychoRouterEncoder { if solution.swaps.is_empty() { return Err(EncodingError::FatalError("No swaps found in solution".to_string())); } - let native_address = self.chain.native_token()?; - let wrapped_address = self.chain.wrapped_token()?; + let native_address = self.chain.native_token().address; + let wrapped_address = self + .chain + .wrapped_native_token() + .address; if let Some(native_action) = &solution.native_action { if native_action == &NativeAction::Wrap { if solution.given_token != native_address { @@ -387,7 +390,7 @@ mod tests { use std::{collections::HashMap, str::FromStr}; use num_bigint::{BigInt, BigUint}; - use tycho_common::models::{protocol::ProtocolComponent, Chain as TychoCommonChain}; + use tycho_common::models::{protocol::ProtocolComponent, Chain}; use super::*; use crate::encoding::models::Swap; @@ -466,7 +469,7 @@ mod tests { } fn eth_chain() -> Chain { - TychoCommonChain::Ethereum.into() + Chain::Ethereum } fn get_swap_encoder_registry() -> SwapEncoderRegistry { diff --git a/src/encoding/models.rs b/src/encoding/models.rs index f26ce86..5f1df64 100644 --- a/src/encoding/models.rs +++ b/src/encoding/models.rs @@ -1,13 +1,9 @@ use clap::ValueEnum; -use hex; use num_bigint::BigUint; use serde::{Deserialize, Serialize}; -use tycho_common::{ - models::{protocol::ProtocolComponent, Chain as TychoCommonChain}, - Bytes, -}; +use tycho_common::{models::protocol::ProtocolComponent, Bytes}; -use crate::encoding::{errors::EncodingError, serde_primitives::biguint_string}; +use crate::encoding::serde_primitives::biguint_string; /// Specifies the method for transferring user funds into Tycho execution. /// @@ -210,63 +206,6 @@ pub enum TransferType { None = 2, } -#[derive(Clone, PartialEq, Eq, Hash)] -pub struct Chain { - pub id: u64, - pub name: String, -} - -impl From for Chain { - fn from(chain: TychoCommonChain) -> Self { - match chain { - TychoCommonChain::Ethereum => Chain { id: 1, name: chain.to_string() }, - TychoCommonChain::ZkSync => Chain { id: 324, name: chain.to_string() }, - TychoCommonChain::Arbitrum => Chain { id: 42161, name: chain.to_string() }, - TychoCommonChain::Starknet => Chain { id: 0, name: chain.to_string() }, - TychoCommonChain::Base => Chain { id: 8453, name: chain.to_string() }, - TychoCommonChain::Unichain => Chain { id: 130, name: chain.to_string() }, - } - } -} - -impl Chain { - fn decode_hex(&self, hex_str: &str, err_msg: &str) -> Result { - Ok(Bytes::from( - hex::decode(hex_str).map_err(|_| EncodingError::FatalError(err_msg.to_string()))?, - )) - } - - pub fn native_token(&self) -> Result { - let decode_err_msg = "Failed to decode native token"; - match self.id { - 1 | 8453 | 42161 => { - self.decode_hex("0000000000000000000000000000000000000000", decode_err_msg) - } - 324 => self.decode_hex("000000000000000000000000000000000000800A", decode_err_msg), - 130 => self.decode_hex("0000000000000000000000000000000000000000", decode_err_msg), - _ => Err(EncodingError::InvalidInput(format!( - "Native token not set for chain {:?}. Double check the chain is supported.", - self.name - ))), - } - } - - pub fn wrapped_token(&self) -> Result { - let decode_err_msg = "Failed to decode wrapped token"; - match self.id { - 1 => self.decode_hex("C02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2", decode_err_msg), - 8453 => self.decode_hex("4200000000000000000000000000000000000006", decode_err_msg), - 324 => self.decode_hex("5AEa5775959fBC2557Cc8789bC1bf90A239D9a91", decode_err_msg), - 42161 => self.decode_hex("82aF49447D8a07e3bd95BD0d56f35241523fBab1", decode_err_msg), - 130 => self.decode_hex("4200000000000000000000000000000000000006", decode_err_msg), - _ => Err(EncodingError::InvalidInput(format!( - "Wrapped token not set for chain {:?}. Double check the chain is supported.", - self.name - ))), - } - } -} - mod tests { use super::*; diff --git a/src/encoding/swap_encoder.rs b/src/encoding/swap_encoder.rs index 2b9c438..233ce58 100644 --- a/src/encoding/swap_encoder.rs +++ b/src/encoding/swap_encoder.rs @@ -1,8 +1,10 @@ use std::collections::HashMap; +use tycho_common::models::Chain; + use crate::encoding::{ errors::EncodingError, - models::{Chain, EncodingContext, Swap}, + models::{EncodingContext, Swap}, }; /// A trait for protocol-specific swap encoding, where each implementation should handle the diff --git a/tests/common/mod.rs b/tests/common/mod.rs index 9a0fb98..aad4116 100644 --- a/tests/common/mod.rs +++ b/tests/common/mod.rs @@ -4,10 +4,9 @@ pub mod encoding; use std::str::FromStr; use alloy::{primitives::B256, signers::local::PrivateKeySigner}; -use tycho_common::{models::Chain as TychoCommonChain, Bytes}; +use tycho_common::{models::Chain, Bytes}; use tycho_execution::encoding::{ - evm::encoder_builders::TychoRouterEncoderBuilder, - models::{Chain, UserTransferType}, + evm::encoder_builders::TychoRouterEncoderBuilder, models::UserTransferType, tycho_encoder::TychoEncoder, }; @@ -16,7 +15,7 @@ pub fn router_address() -> Bytes { } pub fn eth_chain() -> Chain { - TychoCommonChain::Ethereum.into() + Chain::Ethereum } pub fn eth() -> Bytes { diff --git a/tests/optimized_transfers_integration_tests.rs b/tests/optimized_transfers_integration_tests.rs index b348d99..7e7167f 100644 --- a/tests/optimized_transfers_integration_tests.rs +++ b/tests/optimized_transfers_integration_tests.rs @@ -80,7 +80,7 @@ fn test_uniswap_v3_uniswap_v2() { .clone(); let calldata = encode_tycho_router_call( - eth_chain().id, + eth_chain().id(), encoded_solution, &solution, &UserTransferType::TransferFrom, @@ -167,7 +167,7 @@ fn test_uniswap_v3_uniswap_v3() { .clone(); let calldata = encode_tycho_router_call( - eth_chain().id, + eth_chain().id(), encoded_solution, &solution, &UserTransferType::TransferFrom, @@ -263,7 +263,7 @@ fn test_uniswap_v3_curve() { .clone(); let calldata = encode_tycho_router_call( - eth_chain().id, + eth_chain().id(), encoded_solution, &solution, &UserTransferType::TransferFrom, @@ -334,7 +334,7 @@ fn test_balancer_v2_uniswap_v2() { .clone(); let calldata = encode_tycho_router_call( - eth_chain().id, + eth_chain().id(), encoded_solution, &solution, &UserTransferType::TransferFrom, @@ -490,7 +490,7 @@ fn test_multi_protocol() { .clone(); let calldata = encode_tycho_router_call( - eth_chain().id, + eth_chain().id(), encoded_solution, &solution, &UserTransferType::TransferFromPermit2, @@ -565,7 +565,7 @@ fn test_uniswap_v3_balancer_v3() { .clone(); let calldata = encode_tycho_router_call( - eth_chain().id, + eth_chain().id(), encoded_solution, &solution, &UserTransferType::TransferFrom, diff --git a/tests/protocol_integration_tests.rs b/tests/protocol_integration_tests.rs index c0cb2ee..5e55513 100644 --- a/tests/protocol_integration_tests.rs +++ b/tests/protocol_integration_tests.rs @@ -63,7 +63,7 @@ fn test_single_encoding_strategy_ekubo() { .clone(); let calldata = encode_tycho_router_call( - eth_chain().id, + eth_chain().id(), encoded_solution, &solution, &UserTransferType::TransferFrom, @@ -115,7 +115,7 @@ fn test_single_encoding_strategy_maverick() { .clone(); let calldata = encode_tycho_router_call( - eth_chain().id, + eth_chain().id(), encoded_solution, &solution, &UserTransferType::TransferFrom, @@ -177,7 +177,7 @@ fn test_single_encoding_strategy_usv4_eth_in() { .clone(); let calldata = encode_tycho_router_call( - eth_chain().id, + eth_chain().id(), encoded_solution, &solution, &UserTransferType::TransferFromPermit2, @@ -244,7 +244,7 @@ fn test_single_encoding_strategy_usv4_eth_out() { .clone(); let calldata = encode_tycho_router_call( - eth_chain().id, + eth_chain().id(), encoded_solution, &solution, &UserTransferType::TransferFromPermit2, @@ -330,7 +330,7 @@ fn test_single_encoding_strategy_usv4_grouped_swap() { .clone(); let calldata = encode_tycho_router_call( - eth_chain().id, + eth_chain().id(), encoded_solution, &solution, &UserTransferType::TransferFromPermit2, @@ -440,7 +440,7 @@ fn test_single_encoding_strategy_curve() { .clone(); let calldata = encode_tycho_router_call( - eth_chain().id, + eth_chain().id(), encoded_solution, &solution, &UserTransferType::TransferFrom, @@ -507,7 +507,7 @@ fn test_single_encoding_strategy_curve_st_eth() { .clone(); let calldata = encode_tycho_router_call( - eth_chain().id, + eth_chain().id(), encoded_solution, &solution, &UserTransferType::TransferFrom, @@ -560,7 +560,7 @@ fn test_single_encoding_strategy_balancer_v3() { .clone(); let calldata = encode_tycho_router_call( - eth_chain().id, + eth_chain().id(), encoded_solution, &solution, &UserTransferType::TransferFrom, diff --git a/tests/sequential_strategy_integration_tests.rs b/tests/sequential_strategy_integration_tests.rs index 8003854..b296d47 100644 --- a/tests/sequential_strategy_integration_tests.rs +++ b/tests/sequential_strategy_integration_tests.rs @@ -69,7 +69,7 @@ fn test_sequential_swap_strategy_encoder() { .clone(); let calldata = encode_tycho_router_call( - eth_chain().id, + eth_chain().id(), encoded_solution, &solution, &UserTransferType::TransferFromPermit2, @@ -135,7 +135,7 @@ fn test_sequential_swap_strategy_encoder_no_permit2() { .clone(); let calldata = encode_tycho_router_call( - eth_chain().id, + eth_chain().id(), encoded_solution, &solution, &UserTransferType::TransferFrom, @@ -260,7 +260,7 @@ fn test_sequential_strategy_cyclic_swap() { .clone(); let calldata = encode_tycho_router_call( - eth_chain().id, + eth_chain().id(), encoded_solution, &solution, &UserTransferType::TransferFromPermit2, diff --git a/tests/single_strategy_integration_tests.rs b/tests/single_strategy_integration_tests.rs index 70374ed..d252ae6 100644 --- a/tests/single_strategy_integration_tests.rs +++ b/tests/single_strategy_integration_tests.rs @@ -54,7 +54,7 @@ fn test_single_swap_strategy_encoder() { .unwrap(); let calldata = encode_tycho_router_call( - eth_chain().id, + eth_chain().id(), encoded_solutions[0].clone(), &solution, &UserTransferType::TransferFromPermit2, @@ -139,7 +139,7 @@ fn test_single_swap_strategy_encoder_no_permit2() { .unwrap()[0] .clone(); let calldata = encode_tycho_router_call( - eth_chain().id, + eth_chain().id(), encoded_solution, &solution, &UserTransferType::TransferFrom, @@ -221,7 +221,7 @@ fn test_single_swap_strategy_encoder_no_transfer_in() { .unwrap()[0] .clone(); let calldata = encode_tycho_router_call( - eth_chain().id, + eth_chain().id(), encoded_solution, &solution, &UserTransferType::None, @@ -305,7 +305,7 @@ fn test_single_swap_strategy_encoder_wrap() { .clone(); let calldata = encode_tycho_router_call( - eth_chain().id, + eth_chain().id(), encoded_solution, &solution, &UserTransferType::TransferFromPermit2, @@ -357,7 +357,7 @@ fn test_single_swap_strategy_encoder_unwrap() { .clone(); let calldata = encode_tycho_router_call( - eth_chain().id, + eth_chain().id(), encoded_solution, &solution, &UserTransferType::TransferFromPermit2, diff --git a/tests/split_strategy_integration_tests.rs b/tests/split_strategy_integration_tests.rs index b1d163d..13b9422 100644 --- a/tests/split_strategy_integration_tests.rs +++ b/tests/split_strategy_integration_tests.rs @@ -99,7 +99,7 @@ fn test_split_swap_strategy_encoder() { .clone(); let calldata = encode_tycho_router_call( - eth_chain().id, + eth_chain().id(), encoded_solution, &solution, &UserTransferType::TransferFromPermit2, @@ -212,7 +212,7 @@ fn test_split_input_cyclic_swap() { .clone(); let calldata = encode_tycho_router_call( - eth_chain().id, + eth_chain().id(), encoded_solution, &solution, &UserTransferType::TransferFromPermit2, @@ -372,7 +372,7 @@ fn test_split_output_cyclic_swap() { .clone(); let calldata = encode_tycho_router_call( - eth_chain().id, + eth_chain().id(), encoded_solution, &solution, &UserTransferType::TransferFromPermit2, diff --git a/tests/uniswap_x_integration_tests.rs b/tests/uniswap_x_integration_tests.rs index 5200578..8ea134f 100644 --- a/tests/uniswap_x_integration_tests.rs +++ b/tests/uniswap_x_integration_tests.rs @@ -89,7 +89,7 @@ fn test_sequential_swap_usx() { .clone(); let tycho_calldata = encode_tycho_router_call( - eth_chain().id, + eth_chain().id(), encoded_solution, &solution, &UserTransferType::TransferFrom,