diff --git a/Cargo.lock b/Cargo.lock index 2315882..378aa43 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2941,7 +2941,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "157c5a9d7ea5c2ed2d9fb8f495b64759f7816c7eaea54ba3978f0d63000162e3" dependencies = [ "anyhow", - "itertools 0.10.5", + "itertools 0.13.0", "proc-macro2", "quote", "syn 2.0.96", @@ -3011,7 +3011,7 @@ dependencies = [ "once_cell", "socket2", "tracing", - "windows-sys 0.52.0", + "windows-sys 0.59.0", ] [[package]] diff --git a/src/encoding/evm/strategy_encoder/encoder.rs b/src/encoding/evm/strategy_encoder/encoder.rs index 35c1b19..fb71261 100644 --- a/src/encoding/evm/strategy_encoder/encoder.rs +++ b/src/encoding/evm/strategy_encoder/encoder.rs @@ -78,3 +78,58 @@ impl StrategyEncoder for ExecutorEncoder { "swap(uint256, bytes)" } } + +#[cfg(test)] +mod tests { + use num_bigint::BigUint; + use tycho_core::{dto::ProtocolComponent, Bytes}; + + use super::*; + use crate::encoding::models::Swap; + + #[test] + fn test_executor_encoder() { + let encoder = ExecutorEncoder {}; + + let token_in = Bytes::from("0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2"); + let token_out = Bytes::from("0x2791Bca1f2de4661ED88A30C99A7a9449Aa84174"); + + let swap = Swap { + component: ProtocolComponent { + id: "0x5c6ee304399dbdb9c8ef030ab642b10820db8f56000200000000000000000014" + .to_string(), + protocol_system: "vm:balancer_v2".to_string(), + ..Default::default() + }, + token_in: token_in.clone(), + token_out: token_out.clone(), + split: 0.5, + }; + + let solution = Solution { + exact_out: false, + given_token: token_in, + given_amount: BigUint::from(1000000000000000000u64), + expected_amount: BigUint::from(1000000000000000000u64), + checked_token: token_out, + check_amount: None, + sender: Bytes::from_str("0x0000000000000000000000000000000000000000").unwrap(), + receiver: Bytes::from_str("0x0000000000000000000000000000000000000000").unwrap(), + swaps: vec![swap], + straight_to_pool: true, + router_address: Some( + Bytes::from_str("0x0000000000000000000000000000000000000002").unwrap(), + ), + slippage: None, + native_action: None, + }; + + let (_, executor_address) = encoder + .encode_strategy(solution) + .unwrap(); + assert_eq!( + executor_address, + Address::from_str("0x543778987b293C7E8Cf0722BB2e935ba6f4068D4").unwrap() + ); + } +} diff --git a/src/encoding/models.rs b/src/encoding/models.rs index 431cdc5..7a93105 100644 --- a/src/encoding/models.rs +++ b/src/encoding/models.rs @@ -12,7 +12,7 @@ pub struct Solution { /// Amount of the given token. pub given_amount: BigUint, /// The token being bought (exact in) or sold (exact out). - checked_token: Bytes, + pub checked_token: Bytes, /// Expected amount of the bought token (exact in) or sold token (exact out). pub expected_amount: BigUint, /// Minimum amount to be checked for the solution to be valid.