feat: Handle native actions

This commit is contained in:
Diana Carvalho
2025-01-13 17:11:21 +00:00
parent 36fe8f4b76
commit fa462ee9f3
3 changed files with 26 additions and 18 deletions

View File

@@ -8,6 +8,12 @@ pub struct Solution {
pub router_address: Option<Address>,
}
#[derive(Clone)]
pub enum NativeAction {
Wrap,
Unwrap,
}
pub struct Order {
/// True if the order is an exact output order.
pub exact_out: bool,
@@ -30,6 +36,7 @@ pub struct Order {
pub slippage: f64,
pub min_checked_amount: Option<BigUint>,
pub native_action: Option<NativeAction>,
}
#[derive(Clone)]

View File

@@ -28,8 +28,6 @@ impl RouterEncoder {
let encode_for_batch_execute = solution.orders.len() > 1;
for order in solution.orders {
let strategy = self.get_strategy(&order);
// TODO: handle native action??
let contract_interaction = strategy.encode_strategy(
order,
if solution.router_address.is_some() {

View File

@@ -4,7 +4,7 @@ use anyhow::Error;
use num_bigint::BigUint;
use std::cmp::min;
use crate::encoding::models::{ActionType, EncodingContext, Order};
use crate::encoding::models::{ActionType, EncodingContext, NativeAction, Order};
use crate::encoding::swap_encoder::{get_swap_encoder, get_swap_executor_address};
use crate::encoding::utils::{biguint_to_u256, bytes_to_address, encode_input, ple_encode};
@@ -94,24 +94,27 @@ impl StrategyEncoder for SequentialExactInStrategyEncoder {
)
};
let encoded_swaps = ple_encode(swaps);
let (mut unwrap, mut wrap) = (false, false);
if order.native_action.is_some() {
match order.native_action.unwrap() {
NativeAction::Wrap => wrap = true,
NativeAction::Unwrap => unwrap = true,
}
}
let method_calldata = (
wrap,
unwrap,
biguint_to_u256(&order.given_amount),
biguint_to_u256(&min_checked_amount),
encoded_swaps,
)
.abi_encode();
if encode_for_batch_execute {
let args = (
action_type as u16,
biguint_to_u256(&order.given_amount),
biguint_to_u256(&min_checked_amount),
encoded_swaps,
);
let args = (action_type as u16, method_calldata);
Ok(args.abi_encode())
} else {
Ok(encode_input(
selector,
(
biguint_to_u256(&order.given_amount),
biguint_to_u256(&min_checked_amount),
encoded_swaps,
)
.abi_encode(),
))
Ok(encode_input(selector, method_calldata))
}
}
}