feat: Take Chain object containing native/wrapped addresses

- This way this chain object contains everything we need, we don't need to worry about doing any transformation or calling any supplementary functions inside any of the encoders
- Needed to move our new Chain object to a higher level since this is used in the higher-level encoder traits. This required some weird default values in the constants in order to avoid using alloy's hex literal. I could have instead opted to make Bytes parse a string I think, though this would mean possibly returning an error at the constants level, which is not nice either.

Question:
- Do we want the user to be in charge of passing the native and wrapped token every single time? This may be a bit annoying for the user. For now, I have defaulted to those in constants.rs, this would take 5 mins to remove though if you don't like it, and it would get rid of this complicated bytes initialization.
This commit is contained in:
TAMARA LIPOWSKI
2025-02-05 15:33:20 -05:00
parent f8b3baff55
commit e83b8d9aef
15 changed files with 190 additions and 103 deletions

View File

@@ -2,7 +2,7 @@ use std::str::FromStr;
use num_bigint::BigUint;
use tycho_core::{
dto::{Chain, ProtocolComponent},
dto::{Chain as TychoCoreChain, ProtocolComponent},
Bytes,
};
use tycho_execution::encoding::{
@@ -10,7 +10,7 @@ use tycho_execution::encoding::{
strategy_encoder::strategy_encoder_registry::EVMStrategyEncoderRegistry,
tycho_encoder::EVMTychoEncoder,
},
models::{Solution, Swap},
models::{Chain, Solution, Swap},
strategy_encoder::StrategyEncoderRegistry,
tycho_encoder::TychoEncoder,
};
@@ -24,11 +24,13 @@ fn main() {
.expect("Failed to create user address");
let executors_file_path = "src/encoding/config/executor_addresses.json";
let eth_chain = Chain::from_tycho_core_chain(TychoCoreChain::Ethereum, None, None)
.expect("Failed to create chain.");
// Initialize the encoder
let strategy_encoder_registry =
EVMStrategyEncoderRegistry::new(Chain::Ethereum, executors_file_path, signer_pk.clone())
EVMStrategyEncoderRegistry::new(eth_chain.clone(), executors_file_path, signer_pk.clone())
.expect("Failed to create strategy encoder registry");
let encoder = EVMTychoEncoder::new(strategy_encoder_registry, router_address, Chain::Ethereum)
let encoder = EVMTychoEncoder::new(strategy_encoder_registry, router_address, eth_chain)
.expect("Failed to create encoder");
// ------------------- Encode a simple swap -------------------