feat: Handle native actions
This commit is contained in:
@@ -8,6 +8,12 @@ pub struct Solution {
|
|||||||
pub router_address: Option<Address>,
|
pub router_address: Option<Address>,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[derive(Clone)]
|
||||||
|
pub enum NativeAction {
|
||||||
|
Wrap,
|
||||||
|
Unwrap,
|
||||||
|
}
|
||||||
|
|
||||||
pub struct Order {
|
pub struct Order {
|
||||||
/// True if the order is an exact output order.
|
/// True if the order is an exact output order.
|
||||||
pub exact_out: bool,
|
pub exact_out: bool,
|
||||||
@@ -30,6 +36,7 @@ pub struct Order {
|
|||||||
|
|
||||||
pub slippage: f64,
|
pub slippage: f64,
|
||||||
pub min_checked_amount: Option<BigUint>,
|
pub min_checked_amount: Option<BigUint>,
|
||||||
|
pub native_action: Option<NativeAction>,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Clone)]
|
#[derive(Clone)]
|
||||||
|
|||||||
@@ -28,8 +28,6 @@ impl RouterEncoder {
|
|||||||
let encode_for_batch_execute = solution.orders.len() > 1;
|
let encode_for_batch_execute = solution.orders.len() > 1;
|
||||||
for order in solution.orders {
|
for order in solution.orders {
|
||||||
let strategy = self.get_strategy(&order);
|
let strategy = self.get_strategy(&order);
|
||||||
// TODO: handle native action??
|
|
||||||
|
|
||||||
let contract_interaction = strategy.encode_strategy(
|
let contract_interaction = strategy.encode_strategy(
|
||||||
order,
|
order,
|
||||||
if solution.router_address.is_some() {
|
if solution.router_address.is_some() {
|
||||||
|
|||||||
@@ -4,7 +4,7 @@ use anyhow::Error;
|
|||||||
use num_bigint::BigUint;
|
use num_bigint::BigUint;
|
||||||
use std::cmp::min;
|
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::swap_encoder::{get_swap_encoder, get_swap_executor_address};
|
||||||
use crate::encoding::utils::{biguint_to_u256, bytes_to_address, encode_input, ple_encode};
|
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 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 {
|
if encode_for_batch_execute {
|
||||||
let args = (
|
let args = (action_type as u16, method_calldata);
|
||||||
action_type as u16,
|
|
||||||
biguint_to_u256(&order.given_amount),
|
|
||||||
biguint_to_u256(&min_checked_amount),
|
|
||||||
encoded_swaps,
|
|
||||||
);
|
|
||||||
Ok(args.abi_encode())
|
Ok(args.abi_encode())
|
||||||
} else {
|
} else {
|
||||||
Ok(encode_input(
|
Ok(encode_input(selector, method_calldata))
|
||||||
selector,
|
|
||||||
(
|
|
||||||
biguint_to_u256(&order.given_amount),
|
|
||||||
biguint_to_u256(&min_checked_amount),
|
|
||||||
encoded_swaps,
|
|
||||||
)
|
|
||||||
.abi_encode(),
|
|
||||||
))
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user