feat: Use Chain from tycho-core and remove current implementation
--- don't change below this line --- ENG-4705 Took 29 minutes
This commit is contained in:
2
Cargo.lock
generated
2
Cargo.lock
generated
@@ -4635,7 +4635,7 @@ checksum = "e421abadd41a4225275504ea4d6566923418b7f05506fbc9c0fe86ba7396114b"
|
||||
[[package]]
|
||||
name = "tycho-common"
|
||||
version = "0.75.0"
|
||||
source = "git+https://github.com/propeller-heads/tycho-indexer.git?rev=a30c046ac7b022f7a816545486af81e724863f07#a30c046ac7b022f7a816545486af81e724863f07"
|
||||
source = "git+https://github.com/propeller-heads/tycho-indexer.git?rev=9c79c8f7a3501e1edd2b86cff43460729b62991f#9c79c8f7a3501e1edd2b86cff43460729b62991f"
|
||||
dependencies = [
|
||||
"anyhow",
|
||||
"async-trait",
|
||||
|
||||
@@ -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 = { git = "https://github.com/propeller-heads/tycho-indexer.git", package = "tycho-common", rev = "a30c046ac7b022f7a816545486af81e724863f07" }
|
||||
tycho-common = { git = "https://github.com/propeller-heads/tycho-indexer.git", package = "tycho-common", rev = "9c79c8f7a3501e1edd2b86cff43460729b62991f" }
|
||||
|
||||
alloy = { version = "1.0.6", features = ["providers", "rpc-types-eth", "eip712", "signer-local", "node-bindings"], optional = true }
|
||||
|
||||
|
||||
@@ -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();
|
||||
|
||||
@@ -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<String, Bytes> =
|
||||
let default_routers: HashMap<Chain, Bytes> =
|
||||
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<Box<dyn TychoEncoder>, 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(
|
||||
|
||||
@@ -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 {
|
||||
|
||||
@@ -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,
|
||||
};
|
||||
|
||||
|
||||
@@ -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<String, HashMap<String, String>> = serde_json::from_str(&config_str)?;
|
||||
let config: HashMap<Chain, HashMap<String, String>> = 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<String, HashMap<String, HashMap<String, String>>> =
|
||||
let protocol_specific_config: HashMap<Chain, HashMap<String, HashMap<String, String>>> =
|
||||
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(),
|
||||
|
||||
@@ -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();
|
||||
|
||||
@@ -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 {
|
||||
|
||||
@@ -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<TychoCommonChain> 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<Bytes, EncodingError> {
|
||||
Ok(Bytes::from(
|
||||
hex::decode(hex_str).map_err(|_| EncodingError::FatalError(err_msg.to_string()))?,
|
||||
))
|
||||
}
|
||||
|
||||
pub fn native_token(&self) -> Result<Bytes, EncodingError> {
|
||||
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<Bytes, EncodingError> {
|
||||
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::*;
|
||||
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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 {
|
||||
|
||||
@@ -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,
|
||||
|
||||
@@ -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,
|
||||
|
||||
@@ -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,
|
||||
|
||||
@@ -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,
|
||||
|
||||
@@ -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,
|
||||
|
||||
Reference in New Issue
Block a user