feat: resolve pr comments
This commit is contained in:
@@ -95,7 +95,7 @@ contract UniswapV2ExecutorTest is UniswapV2ExecutorExposed, Test, Constants {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function testSwapExecutorEncoderData() public {
|
function testSwapExecutorEncoderData() public {
|
||||||
// Generated by the strategy encoder
|
// Generated by the ExecutorStrategyEncoder - test_executor_encoder
|
||||||
bytes memory protocolData =
|
bytes memory protocolData =
|
||||||
hex"c02aaa39b223fe8d0a0e5c4f27ead9083c756cc288e6a0c2ddd26feeb64f039a2c41296fcb3f564000000000000000000000000000000000000000010000";
|
hex"c02aaa39b223fe8d0a0e5c4f27ead9083c756cc288e6a0c2ddd26feeb64f039a2c41296fcb3f564000000000000000000000000000000000000000010000";
|
||||||
|
|
||||||
@@ -109,7 +109,7 @@ contract UniswapV2ExecutorTest is UniswapV2ExecutorExposed, Test, Constants {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function testSwapExecutorSwap() public {
|
function testSwapExecutorSwap() public {
|
||||||
// Generated by the strategy encoder
|
// Generated by the ExecutorStrategyEncoder - test_executor_encoder
|
||||||
bytes memory protocolData =
|
bytes memory protocolData =
|
||||||
hex"c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2a478c2975ab1ea89e8196811f51a7b7ade33eb111d96f2f6bef1202e4ce1ff6dad0c2cb002861d3e0000";
|
hex"c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2a478c2975ab1ea89e8196811f51a7b7ade33eb111d96f2f6bef1202e4ce1ff6dad0c2cb002861d3e0000";
|
||||||
uint256 amountIn = 10 ** 18;
|
uint256 amountIn = 10 ** 18;
|
||||||
|
|||||||
@@ -2,6 +2,7 @@ use std::str::FromStr;
|
|||||||
|
|
||||||
use alloy_primitives::Address;
|
use alloy_primitives::Address;
|
||||||
use alloy_sol_types::SolValue;
|
use alloy_sol_types::SolValue;
|
||||||
|
use tycho_core::Bytes;
|
||||||
|
|
||||||
use crate::encoding::{
|
use crate::encoding::{
|
||||||
errors::EncodingError,
|
errors::EncodingError,
|
||||||
@@ -29,7 +30,7 @@ pub trait EVMStrategyEncoder: StrategyEncoder {
|
|||||||
pub struct SplitSwapStrategyEncoder {}
|
pub struct SplitSwapStrategyEncoder {}
|
||||||
impl EVMStrategyEncoder for SplitSwapStrategyEncoder {}
|
impl EVMStrategyEncoder for SplitSwapStrategyEncoder {}
|
||||||
impl StrategyEncoder 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!()
|
todo!()
|
||||||
}
|
}
|
||||||
fn selector(&self, _exact_out: bool) -> &str {
|
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.
|
/// This strategy encoder is used for solutions that are sent directly to the pool.
|
||||||
/// Only 1 solution with 1 swap is supported.
|
/// Only 1 solution with 1 swap is supported.
|
||||||
pub struct ExecutorEncoder {}
|
pub struct ExecutorStrategyEncoder {}
|
||||||
impl EVMStrategyEncoder for ExecutorEncoder {}
|
impl EVMStrategyEncoder for ExecutorStrategyEncoder {}
|
||||||
impl StrategyEncoder for ExecutorEncoder {
|
impl StrategyEncoder for ExecutorStrategyEncoder {
|
||||||
fn encode_strategy(&self, solution: Solution) -> Result<(Vec<u8>, Address), EncodingError> {
|
fn encode_strategy(&self, solution: Solution) -> Result<(Vec<u8>, Bytes), EncodingError> {
|
||||||
if solution.router_address.is_none() {
|
if solution.router_address.is_none() {
|
||||||
return Err(EncodingError::InvalidInput(
|
return Err(EncodingError::InvalidInput(
|
||||||
"Router address is required for straight to pool solutions".to_string(),
|
"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 protocol_data = swap_encoder.encode_swap(swap.clone(), encoding_context)?;
|
||||||
let executor_address = Address::from_str(swap_encoder.executor_address())
|
let executor_address = Address::from_str(swap_encoder.executor_address())
|
||||||
.map_err(|_| EncodingError::FatalError("Invalid executor address".to_string()))?;
|
.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 {
|
fn selector(&self, _exact_out: bool) -> &str {
|
||||||
"swap(uint256, bytes)"
|
"swap(uint256, bytes)"
|
||||||
@@ -90,7 +91,7 @@ mod tests {
|
|||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_executor_encoder() {
|
fn test_executor_encoder() {
|
||||||
let encoder = ExecutorEncoder {};
|
let encoder = ExecutorStrategyEncoder {};
|
||||||
|
|
||||||
let token_in = Bytes::from("0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2");
|
let token_in = Bytes::from("0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2");
|
||||||
let token_out = Bytes::from("0x6b175474e89094c44da98b954eedeac495271d0f");
|
let token_out = Bytes::from("0x6b175474e89094c44da98b954eedeac495271d0f");
|
||||||
@@ -114,6 +115,7 @@ mod tests {
|
|||||||
checked_token: token_out,
|
checked_token: token_out,
|
||||||
check_amount: None,
|
check_amount: None,
|
||||||
sender: Bytes::from_str("0x0000000000000000000000000000000000000000").unwrap(),
|
sender: Bytes::from_str("0x0000000000000000000000000000000000000000").unwrap(),
|
||||||
|
// The receiver was generated with `makeAddr("bob") using forge`
|
||||||
receiver: Bytes::from_str("0x1d96f2f6bef1202e4ce1ff6dad0c2cb002861d3e").unwrap(),
|
receiver: Bytes::from_str("0x1d96f2f6bef1202e4ce1ff6dad0c2cb002861d3e").unwrap(),
|
||||||
swaps: vec![swap],
|
swaps: vec![swap],
|
||||||
straight_to_pool: true,
|
straight_to_pool: true,
|
||||||
@@ -126,10 +128,9 @@ mod tests {
|
|||||||
.encode_strategy(solution)
|
.encode_strategy(solution)
|
||||||
.unwrap();
|
.unwrap();
|
||||||
let hex_protocol_data = encode(&protocol_data);
|
let hex_protocol_data = encode(&protocol_data);
|
||||||
println!("{}", hex_protocol_data);
|
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
executor_address,
|
executor_address,
|
||||||
Address::from_str("0x5c2f5a71f67c01775180adc06909288b4c329308").unwrap()
|
Bytes::from_str("0x5c2f5a71f67c01775180adc06909288b4c329308").unwrap()
|
||||||
);
|
);
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
hex_protocol_data,
|
hex_protocol_data,
|
||||||
@@ -150,7 +151,7 @@ mod tests {
|
|||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_selector() {
|
fn test_selector() {
|
||||||
let encoder = ExecutorEncoder {};
|
let encoder = ExecutorStrategyEncoder {};
|
||||||
assert_eq!(encoder.selector(false), "swap(uint256, bytes)");
|
assert_eq!(encoder.selector(false), "swap(uint256, bytes)");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
use crate::encoding::{
|
use crate::encoding::{
|
||||||
evm::strategy_encoder::encoder::{ExecutorEncoder, SplitSwapStrategyEncoder},
|
evm::strategy_encoder::encoder::{ExecutorStrategyEncoder, SplitSwapStrategyEncoder},
|
||||||
models::Solution,
|
models::Solution,
|
||||||
strategy_encoder::{StrategyEncoder, StrategySelector},
|
strategy_encoder::{StrategyEncoder, StrategySelector},
|
||||||
};
|
};
|
||||||
@@ -9,7 +9,7 @@ pub struct EVMStrategySelector;
|
|||||||
impl StrategySelector for EVMStrategySelector {
|
impl StrategySelector for EVMStrategySelector {
|
||||||
fn select_strategy(&self, solution: &Solution) -> Box<dyn StrategyEncoder> {
|
fn select_strategy(&self, solution: &Solution) -> Box<dyn StrategyEncoder> {
|
||||||
if solution.straight_to_pool {
|
if solution.straight_to_pool {
|
||||||
Box::new(ExecutorEncoder {})
|
Box::new(ExecutorStrategyEncoder {})
|
||||||
} else {
|
} else {
|
||||||
Box::new(SplitSwapStrategyEncoder {})
|
Box::new(SplitSwapStrategyEncoder {})
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,4 +1,3 @@
|
|||||||
use alloy_primitives::Address;
|
|
||||||
use num_bigint::BigUint;
|
use num_bigint::BigUint;
|
||||||
use tycho_core::{dto::ProtocolComponent, Bytes};
|
use tycho_core::{dto::ProtocolComponent, Bytes};
|
||||||
|
|
||||||
@@ -62,7 +61,7 @@ pub struct Transaction {
|
|||||||
// ETH value to be sent with the transaction.
|
// ETH value to be sent with the transaction.
|
||||||
pub value: BigUint,
|
pub value: BigUint,
|
||||||
// Address of the contract to call with the calldata
|
// Address of the contract to call with the calldata
|
||||||
pub to: Address,
|
pub to: Bytes,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[allow(dead_code)]
|
#[allow(dead_code)]
|
||||||
|
|||||||
@@ -1,10 +1,10 @@
|
|||||||
use alloy_primitives::Address;
|
use tycho_core::Bytes;
|
||||||
|
|
||||||
use crate::encoding::{errors::EncodingError, models::Solution};
|
use crate::encoding::{errors::EncodingError, models::Solution};
|
||||||
|
|
||||||
#[allow(dead_code)]
|
#[allow(dead_code)]
|
||||||
pub trait StrategyEncoder {
|
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;
|
fn selector(&self, exact_out: bool) -> &str;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user