feat: Delete EVMStrategyEncoder (this is now unnecessary)

Moved ple_encode into utils.rs

--- don't change below this line ---
ENG-4306 Took 5 minutes
This commit is contained in:
Diana Carvalho
2025-04-04 15:47:30 +01:00
parent f12bebcdfb
commit 6430c99d76
2 changed files with 20 additions and 25 deletions

View File

@@ -16,7 +16,7 @@ use crate::encoding::{
swap_encoder::swap_encoder_registry::SwapEncoderRegistry, swap_encoder::swap_encoder_registry::SwapEncoderRegistry,
utils::{ utils::{
biguint_to_u256, bytes_to_address, encode_input, get_min_amount_for_solution, biguint_to_u256, bytes_to_address, encode_input, get_min_amount_for_solution,
get_token_position, percentage_to_uint24, get_token_position, percentage_to_uint24, ple_encode,
}, },
}, },
models::{Chain, EncodingContext, NativeAction, Solution}, models::{Chain, EncodingContext, NativeAction, Solution},
@@ -24,24 +24,6 @@ use crate::encoding::{
swap_encoder::SwapEncoder, swap_encoder::SwapEncoder,
}; };
/// Encodes a solution using a specific strategy for execution on the EVM-compatible network.
pub trait EVMStrategyEncoder: StrategyEncoder {
/// Uses prefix-length encoding to efficient encode action data.
///
/// Prefix-length encoding is a data encoding method where the beginning of a data segment
/// (the "prefix") contains information about the length of the following data.
fn ple_encode(&self, action_data_array: Vec<Vec<u8>>) -> Vec<u8> {
let mut encoded_action_data: Vec<u8> = Vec::new();
for action_data in action_data_array {
let args = (encoded_action_data, action_data.len() as u16, action_data);
encoded_action_data = args.abi_encode_packed();
}
encoded_action_data
}
}
/// Represents the encoder for a swap strategy which supports single swaps. /// Represents the encoder for a swap strategy which supports single swaps.
/// ///
/// # Fields /// # Fields
@@ -90,8 +72,6 @@ impl SingleSwapStrategyEncoder {
} }
} }
impl EVMStrategyEncoder for SingleSwapStrategyEncoder {}
impl StrategyEncoder for SingleSwapStrategyEncoder { impl StrategyEncoder for SingleSwapStrategyEncoder {
fn encode_strategy(&self, solution: Solution) -> Result<(Vec<u8>, Bytes), EncodingError> { fn encode_strategy(&self, solution: Solution) -> Result<(Vec<u8>, Bytes), EncodingError> {
let grouped_swaps = group_swaps(solution.clone().swaps); let grouped_swaps = group_swaps(solution.clone().swaps);
@@ -285,8 +265,6 @@ impl SplitSwapStrategyEncoder {
} }
} }
impl EVMStrategyEncoder for SplitSwapStrategyEncoder {}
impl StrategyEncoder for SplitSwapStrategyEncoder { impl StrategyEncoder for SplitSwapStrategyEncoder {
fn encode_strategy(&self, solution: Solution) -> Result<(Vec<u8>, Bytes), EncodingError> { fn encode_strategy(&self, solution: Solution) -> Result<(Vec<u8>, Bytes), EncodingError> {
self.split_swap_validator self.split_swap_validator
@@ -387,7 +365,7 @@ impl StrategyEncoder for SplitSwapStrategyEncoder {
swaps.push(swap_data); swaps.push(swap_data);
} }
let encoded_swaps = self.ple_encode(swaps); let encoded_swaps = ple_encode(swaps);
let tokens_len = if solution.given_token == solution.checked_token { let tokens_len = if solution.given_token == solution.checked_token {
tokens.len() - 1 tokens.len() - 1
} else { } else {
@@ -458,7 +436,7 @@ impl ExecutorStrategyEncoder {
Self { swap_encoder_registry } Self { swap_encoder_registry }
} }
} }
impl EVMStrategyEncoder for ExecutorStrategyEncoder {}
impl StrategyEncoder for ExecutorStrategyEncoder { impl StrategyEncoder for ExecutorStrategyEncoder {
fn encode_strategy(&self, solution: Solution) -> Result<(Vec<u8>, Bytes), EncodingError> { fn encode_strategy(&self, solution: Solution) -> Result<(Vec<u8>, Bytes), EncodingError> {
let grouped_swaps = group_swaps(solution.clone().swaps); let grouped_swaps = group_swaps(solution.clone().swaps);

View File

@@ -1,6 +1,7 @@
use std::{cmp::max, sync::Arc}; use std::{cmp::max, sync::Arc};
use alloy_primitives::{aliases::U24, keccak256, Address, FixedBytes, Keccak256, U256, U8}; use alloy_primitives::{aliases::U24, keccak256, Address, FixedBytes, Keccak256, U256, U8};
use alloy_sol_types::SolValue;
use num_bigint::BigUint; use num_bigint::BigUint;
use tokio::runtime::{Handle, Runtime}; use tokio::runtime::{Handle, Runtime};
use tycho_common::Bytes; use tycho_common::Bytes;
@@ -133,6 +134,22 @@ pub fn get_runtime() -> Result<(Handle, Option<Arc<Runtime>>), EncodingError> {
} }
} }
} }
/// Uses prefix-length encoding to efficient encode action data.
///
/// Prefix-length encoding is a data encoding method where the beginning of a data segment
/// (the "prefix") contains information about the length of the following data.
pub fn ple_encode(action_data_array: Vec<Vec<u8>>) -> Vec<u8> {
let mut encoded_action_data: Vec<u8> = Vec::new();
for action_data in action_data_array {
let args = (encoded_action_data, action_data.len() as u16, action_data);
encoded_action_data = args.abi_encode_packed();
}
encoded_action_data
}
#[cfg(test)] #[cfg(test)]
mod tests { mod tests {
use num_bigint::BigUint; use num_bigint::BigUint;