feat: update ExecutorEncoder interface and relevant types
This commit is contained in:
@@ -30,7 +30,7 @@ impl<S: StrategySelector, A: UserApprovalsManager> RouterEncoder<S, A> for EVMRo
|
||||
&self,
|
||||
solutions: Vec<Solution>,
|
||||
) -> Result<Vec<Transaction>, EncodingError> {
|
||||
let _approvals_calldata = self.handle_approvals(&solutions)?; // TODO: where should we append this?
|
||||
let _approvals_calldata = self.handle_approvals(&solutions)?;
|
||||
let mut transactions: Vec<Transaction> = Vec::new();
|
||||
for solution in solutions.iter() {
|
||||
let exact_out = solution.exact_out;
|
||||
@@ -39,7 +39,8 @@ impl<S: StrategySelector, A: UserApprovalsManager> RouterEncoder<S, A> for EVMRo
|
||||
let strategy = self
|
||||
.strategy_selector
|
||||
.select_strategy(solution);
|
||||
let method_calldata = strategy.encode_strategy((*solution).clone())?;
|
||||
let (method_calldata, target_address) =
|
||||
strategy.encode_strategy((*solution).clone())?;
|
||||
|
||||
let contract_interaction = if straight_to_pool {
|
||||
method_calldata
|
||||
@@ -52,7 +53,11 @@ impl<S: StrategySelector, A: UserApprovalsManager> RouterEncoder<S, A> for EVMRo
|
||||
} else {
|
||||
BigUint::ZERO
|
||||
};
|
||||
transactions.push(Transaction { value, data: contract_interaction });
|
||||
transactions.push(Transaction {
|
||||
value,
|
||||
data: contract_interaction,
|
||||
to: target_address,
|
||||
});
|
||||
}
|
||||
Ok(transactions)
|
||||
}
|
||||
|
||||
@@ -1,3 +1,5 @@
|
||||
use std::str::FromStr;
|
||||
|
||||
use alloy_primitives::Address;
|
||||
use alloy_sol_types::SolValue;
|
||||
|
||||
@@ -27,7 +29,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>, EncodingError> {
|
||||
fn encode_strategy(&self, _solution: Solution) -> Result<(Vec<u8>, Address), EncodingError> {
|
||||
todo!()
|
||||
}
|
||||
fn selector(&self, _exact_out: bool) -> &str {
|
||||
@@ -37,10 +39,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 StraightToPoolStrategyEncoder {}
|
||||
impl EVMStrategyEncoder for StraightToPoolStrategyEncoder {}
|
||||
impl StrategyEncoder for StraightToPoolStrategyEncoder {
|
||||
fn encode_strategy(&self, solution: Solution) -> Result<Vec<u8>, EncodingError> {
|
||||
pub struct ExecutorEncoder {}
|
||||
impl EVMStrategyEncoder for ExecutorEncoder {}
|
||||
impl StrategyEncoder for ExecutorEncoder {
|
||||
fn encode_strategy(&self, solution: Solution) -> Result<(Vec<u8>, Address), EncodingError> {
|
||||
if solution.router_address.is_none() {
|
||||
return Err(EncodingError::InvalidInput(
|
||||
"Router address is required for straight to pool solutions".to_string(),
|
||||
@@ -68,10 +70,11 @@ impl StrategyEncoder for StraightToPoolStrategyEncoder {
|
||||
router_address,
|
||||
};
|
||||
let protocol_data = swap_encoder.encode_swap(swap.clone(), encoding_context)?;
|
||||
// TODO: here we need to pass also the address of the executor to be used
|
||||
Ok(protocol_data)
|
||||
let executor_address = Address::from_str(swap_encoder.executor_address())
|
||||
.map_err(|_| EncodingError::FatalError("Invalid executor address".to_string()))?;
|
||||
Ok((protocol_data, executor_address))
|
||||
}
|
||||
fn selector(&self, _exact_out: bool) -> &str {
|
||||
unimplemented!();
|
||||
"swap(uint256, bytes)"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
use crate::encoding::{
|
||||
evm::strategy_encoder::encoder::{SplitSwapStrategyEncoder, StraightToPoolStrategyEncoder},
|
||||
evm::strategy_encoder::encoder::{ExecutorEncoder, 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(StraightToPoolStrategyEncoder {})
|
||||
Box::new(ExecutorEncoder {})
|
||||
} else {
|
||||
Box::new(SplitSwapStrategyEncoder {})
|
||||
}
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
use alloy_primitives::Address;
|
||||
use num_bigint::BigUint;
|
||||
use tycho_core::{dto::ProtocolComponent, Bytes};
|
||||
|
||||
@@ -60,6 +61,8 @@ pub struct Transaction {
|
||||
pub data: Vec<u8>,
|
||||
// ETH value to be sent with the transaction.
|
||||
pub value: BigUint,
|
||||
// Address of the contract to call with the calldata
|
||||
pub to: Address,
|
||||
}
|
||||
|
||||
#[allow(dead_code)]
|
||||
|
||||
@@ -1,8 +1,10 @@
|
||||
use alloy_primitives::Address;
|
||||
|
||||
use crate::encoding::{errors::EncodingError, models::Solution};
|
||||
|
||||
#[allow(dead_code)]
|
||||
pub trait StrategyEncoder {
|
||||
fn encode_strategy(&self, to_encode: Solution) -> Result<Vec<u8>, EncodingError>;
|
||||
fn encode_strategy(&self, to_encode: Solution) -> Result<(Vec<u8>, Address), EncodingError>;
|
||||
fn selector(&self, exact_out: bool) -> &str;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user