fix: Add expected_amount to Solution

This commit is contained in:
Diana Carvalho
2025-01-14 17:59:59 +00:00
parent a25c56e667
commit f9f83b439f
3 changed files with 11 additions and 6 deletions

View File

@@ -21,7 +21,9 @@ pub struct Solution {
pub given_amount: BigUint,
/// The token being bought (exact in) or sold (exact out).
checked_token: Bytes,
/// Amount of the checked token.
/// Expected amount of the bought token (exact in) or sold token (exact out).
pub expected_amount: BigUint,
/// Minimum amount to be checked for the solution to be valid.
pub check_amount: BigUint,
/// Address of the sender.
pub sender: Bytes,

View File

@@ -1,6 +1,7 @@
use alloy_sol_types::SolValue;
use anyhow::Error;
use num_bigint::BigUint;
use std::cmp::min;
use crate::encoding::models::{
ActionType, EncodingContext, NativeAction, Solution, PROPELLER_ROUTER_ADDRESS,
@@ -62,7 +63,9 @@ impl StrategyEncoder for SequentialStrategyEncoder {
let one_hundred = BigUint::from(100u32);
let slippage_percent = BigUint::from((solution.slippage.unwrap() * 100.0) as u32);
let multiplier = &one_hundred - slippage_percent;
check_amount = (&solution.check_amount * multiplier) / one_hundred;
let expected_amount_with_slippage =
(&solution.expected_amount * multiplier) / one_hundred;
check_amount = min(check_amount, expected_amount_with_slippage);
}
let mut swaps = vec![];
for (index, swap) in solution.swaps.iter().enumerate() {
@@ -127,9 +130,9 @@ impl StrategyEncoder for SequentialStrategyEncoder {
}
}
pub struct SlipSwapStrategyEncoder {}
pub struct SplitSwapStrategyEncoder {}
impl StrategyEncoder for SlipSwapStrategyEncoder {
impl StrategyEncoder for SplitSwapStrategyEncoder {
fn encode_strategy(&self, solution: Solution) -> Result<Vec<u8>, Error> {
todo!()
}

View File

@@ -1,6 +1,6 @@
use crate::encoding::models::Solution;
use crate::encoding::strategy_encoder::{
SequentialStrategyEncoder, SingleSwapStrategyEncoder, SlipSwapStrategyEncoder,
SequentialStrategyEncoder, SingleSwapStrategyEncoder, SplitSwapStrategyEncoder,
StraightToPoolStrategyEncoder, StrategyEncoder,
};
@@ -19,7 +19,7 @@ impl StrategySelector for DefaultStrategySelector {
} else if solution.swaps.iter().all(|s| s.split == 0.0) {
Box::new(SequentialStrategyEncoder {})
} else {
Box::new(SlipSwapStrategyEncoder {})
Box::new(SplitSwapStrategyEncoder {})
}
}
}