feat: resolve pr comments

This commit is contained in:
royvardhan
2025-01-30 18:07:07 +05:30
parent a50c31203b
commit 1b8bf56c75
5 changed files with 18 additions and 18 deletions

View File

@@ -95,7 +95,7 @@ contract UniswapV2ExecutorTest is UniswapV2ExecutorExposed, Test, Constants {
}
function testSwapExecutorEncoderData() public {
// Generated by the strategy encoder
// Generated by the ExecutorStrategyEncoder - test_executor_encoder
bytes memory protocolData =
hex"c02aaa39b223fe8d0a0e5c4f27ead9083c756cc288e6a0c2ddd26feeb64f039a2c41296fcb3f564000000000000000000000000000000000000000010000";
@@ -109,7 +109,7 @@ contract UniswapV2ExecutorTest is UniswapV2ExecutorExposed, Test, Constants {
}
function testSwapExecutorSwap() public {
// Generated by the strategy encoder
// Generated by the ExecutorStrategyEncoder - test_executor_encoder
bytes memory protocolData =
hex"c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2a478c2975ab1ea89e8196811f51a7b7ade33eb111d96f2f6bef1202e4ce1ff6dad0c2cb002861d3e0000";
uint256 amountIn = 10 ** 18;

View File

@@ -2,6 +2,7 @@ use std::str::FromStr;
use alloy_primitives::Address;
use alloy_sol_types::SolValue;
use tycho_core::Bytes;
use crate::encoding::{
errors::EncodingError,
@@ -29,7 +30,7 @@ pub trait EVMStrategyEncoder: StrategyEncoder {
pub struct SplitSwapStrategyEncoder {}
impl EVMStrategyEncoder for SplitSwapStrategyEncoder {}
impl StrategyEncoder for SplitSwapStrategyEncoder {
fn encode_strategy(&self, _solution: Solution) -> Result<(Vec<u8>, Address), EncodingError> {
fn encode_strategy(&self, _solution: Solution) -> Result<(Vec<u8>, Bytes), EncodingError> {
todo!()
}
fn selector(&self, _exact_out: bool) -> &str {
@@ -39,10 +40,10 @@ impl StrategyEncoder for SplitSwapStrategyEncoder {
/// This strategy encoder is used for solutions that are sent directly to the pool.
/// Only 1 solution with 1 swap is supported.
pub struct ExecutorEncoder {}
impl EVMStrategyEncoder for ExecutorEncoder {}
impl StrategyEncoder for ExecutorEncoder {
fn encode_strategy(&self, solution: Solution) -> Result<(Vec<u8>, Address), EncodingError> {
pub struct ExecutorStrategyEncoder {}
impl EVMStrategyEncoder for ExecutorStrategyEncoder {}
impl StrategyEncoder for ExecutorStrategyEncoder {
fn encode_strategy(&self, solution: Solution) -> Result<(Vec<u8>, Bytes), EncodingError> {
if solution.router_address.is_none() {
return Err(EncodingError::InvalidInput(
"Router address is required for straight to pool solutions".to_string(),
@@ -72,7 +73,7 @@ impl StrategyEncoder for ExecutorEncoder {
let protocol_data = swap_encoder.encode_swap(swap.clone(), encoding_context)?;
let executor_address = Address::from_str(swap_encoder.executor_address())
.map_err(|_| EncodingError::FatalError("Invalid executor address".to_string()))?;
Ok((protocol_data, executor_address))
Ok((protocol_data, Bytes::from(executor_address.as_slice())))
}
fn selector(&self, _exact_out: bool) -> &str {
"swap(uint256, bytes)"
@@ -90,7 +91,7 @@ mod tests {
#[test]
fn test_executor_encoder() {
let encoder = ExecutorEncoder {};
let encoder = ExecutorStrategyEncoder {};
let token_in = Bytes::from("0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2");
let token_out = Bytes::from("0x6b175474e89094c44da98b954eedeac495271d0f");
@@ -114,6 +115,7 @@ mod tests {
checked_token: token_out,
check_amount: None,
sender: Bytes::from_str("0x0000000000000000000000000000000000000000").unwrap(),
// The receiver was generated with `makeAddr("bob") using forge`
receiver: Bytes::from_str("0x1d96f2f6bef1202e4ce1ff6dad0c2cb002861d3e").unwrap(),
swaps: vec![swap],
straight_to_pool: true,
@@ -126,10 +128,9 @@ mod tests {
.encode_strategy(solution)
.unwrap();
let hex_protocol_data = encode(&protocol_data);
println!("{}", hex_protocol_data);
assert_eq!(
executor_address,
Address::from_str("0x5c2f5a71f67c01775180adc06909288b4c329308").unwrap()
Bytes::from_str("0x5c2f5a71f67c01775180adc06909288b4c329308").unwrap()
);
assert_eq!(
hex_protocol_data,
@@ -150,7 +151,7 @@ mod tests {
#[test]
fn test_selector() {
let encoder = ExecutorEncoder {};
let encoder = ExecutorStrategyEncoder {};
assert_eq!(encoder.selector(false), "swap(uint256, bytes)");
}
}

View File

@@ -1,5 +1,5 @@
use crate::encoding::{
evm::strategy_encoder::encoder::{ExecutorEncoder, SplitSwapStrategyEncoder},
evm::strategy_encoder::encoder::{ExecutorStrategyEncoder, SplitSwapStrategyEncoder},
models::Solution,
strategy_encoder::{StrategyEncoder, StrategySelector},
};
@@ -9,7 +9,7 @@ pub struct EVMStrategySelector;
impl StrategySelector for EVMStrategySelector {
fn select_strategy(&self, solution: &Solution) -> Box<dyn StrategyEncoder> {
if solution.straight_to_pool {
Box::new(ExecutorEncoder {})
Box::new(ExecutorStrategyEncoder {})
} else {
Box::new(SplitSwapStrategyEncoder {})
}

View File

@@ -1,4 +1,3 @@
use alloy_primitives::Address;
use num_bigint::BigUint;
use tycho_core::{dto::ProtocolComponent, Bytes};
@@ -62,7 +61,7 @@ pub struct Transaction {
// ETH value to be sent with the transaction.
pub value: BigUint,
// Address of the contract to call with the calldata
pub to: Address,
pub to: Bytes,
}
#[allow(dead_code)]

View File

@@ -1,10 +1,10 @@
use alloy_primitives::Address;
use tycho_core::Bytes;
use crate::encoding::{errors::EncodingError, models::Solution};
#[allow(dead_code)]
pub trait StrategyEncoder {
fn encode_strategy(&self, to_encode: Solution) -> Result<(Vec<u8>, Address), EncodingError>;
fn encode_strategy(&self, to_encode: Solution) -> Result<(Vec<u8>, Bytes), EncodingError>;
fn selector(&self, exact_out: bool) -> &str;
}