chore: Move ple_encode to EVMStrategyEncoder

--- don't change below this line ---
ENG-4081 Took 3 minutes
This commit is contained in:
Diana Carvalho
2025-01-30 19:47:36 +00:00
parent 575c5bea5e
commit 01d101acb5
2 changed files with 13 additions and 17 deletions

View File

@@ -10,9 +10,7 @@ use crate::encoding::{
evm::{
approvals::permit2::Permit2,
swap_encoder::SWAP_ENCODER_REGISTRY,
utils::{
biguint_to_u256, bytes_to_address, encode_input, percentage_to_uint24, ple_encode,
},
utils::{biguint_to_u256, bytes_to_address, encode_input, percentage_to_uint24},
},
models::{EncodingContext, NativeAction, Solution},
strategy_encoder::StrategyEncoder,
@@ -42,6 +40,17 @@ pub trait EVMStrategyEncoder: StrategyEncoder {
let hash = keccak256(selector.as_bytes());
FixedBytes::<4>::from([hash[0], hash[1], hash[2], hash[3]])
}
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
}
}
pub struct SplitSwapStrategyEncoder {
@@ -139,7 +148,7 @@ impl StrategyEncoder for SplitSwapStrategyEncoder {
swaps.push(swap_data);
}
let encoded_swaps = ple_encode(swaps);
let encoded_swaps = self.ple_encode(swaps);
let (mut unwrap, mut wrap) = (false, false);
if solution.native_action.is_some() {
match solution.native_action.unwrap() {

View File

@@ -1,5 +1,4 @@
use alloy_primitives::{aliases::U24, Address, Keccak256, U256};
use alloy_sol_types::SolValue;
use num_bigint::BigUint;
use tycho_core::Bytes;
@@ -23,18 +22,6 @@ pub fn biguint_to_u256(value: &BigUint) -> U256 {
U256::from_be_slice(&bytes)
}
#[allow(dead_code)]
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
}
#[allow(dead_code)]
pub fn encode_input(selector: &str, mut encoded_args: Vec<u8>) -> Vec<u8> {
let mut hasher = Keccak256::new();