feat: Refactor TychoEncoder
We have a trait TychoEncoder and then two implementations: TychoRouterEncoder and TychoExecutorEncoder. This way we go a level above with the decision if it is a direct execution or if it should use the tycho router. - Created two builders: one for each tycho encoder - Delete ExecutorStrategyEncoder and move code straight into the TychoExecutorEncoder - Add validate_solution to trait TychoEncoder - Move group_swaps.rs a level up - Update tests and usage cases Doing this we get rid of all that weird stuff we were doing before --- don't change below this line --- ENG-4306 Took 2 hours 6 minutes Took 12 seconds
This commit is contained in:
@@ -6,9 +6,8 @@ use tycho_common::{
|
||||
Bytes,
|
||||
};
|
||||
use tycho_execution::encoding::{
|
||||
evm::encoder_builder::EVMEncoderBuilder,
|
||||
evm::encoder_builders::TychoRouterEncoderBuilder,
|
||||
models::{Solution, Swap},
|
||||
tycho_encoder::TychoEncoder,
|
||||
};
|
||||
|
||||
fn main() {
|
||||
@@ -19,10 +18,9 @@ fn main() {
|
||||
.expect("Failed to create user address");
|
||||
|
||||
// Initialize the encoder
|
||||
let encoder = EVMEncoderBuilder::new()
|
||||
let encoder = TychoRouterEncoderBuilder::new()
|
||||
.chain(Chain::Ethereum)
|
||||
.initialize_tycho_router_with_permit2(swapper_pk)
|
||||
.expect("Failed to create encoder builder")
|
||||
.swapper_pk(swapper_pk)
|
||||
.build()
|
||||
.expect("Failed to build encoder");
|
||||
|
||||
@@ -64,7 +62,7 @@ fn main() {
|
||||
|
||||
// Encode the solution
|
||||
let tx = encoder
|
||||
.encode_router_calldata(vec![solution.clone()])
|
||||
.encode_calldata(vec![solution.clone()])
|
||||
.expect("Failed to encode router calldata")[0]
|
||||
.clone();
|
||||
println!(" ====== Simple swap WETH -> USDC ======");
|
||||
@@ -137,7 +135,7 @@ fn main() {
|
||||
|
||||
// Encode the solution
|
||||
let complex_tx = encoder
|
||||
.encode_router_calldata(vec![complex_solution])
|
||||
.encode_calldata(vec![complex_solution])
|
||||
.expect("Failed to encode router calldata")[0]
|
||||
.clone();
|
||||
|
||||
|
||||
Reference in New Issue
Block a user