fix: Add expected_amount to Solution
This commit is contained in:
@@ -21,7 +21,9 @@ pub struct Solution {
|
|||||||
pub given_amount: BigUint,
|
pub given_amount: BigUint,
|
||||||
/// The token being bought (exact in) or sold (exact out).
|
/// The token being bought (exact in) or sold (exact out).
|
||||||
checked_token: Bytes,
|
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,
|
pub check_amount: BigUint,
|
||||||
/// Address of the sender.
|
/// Address of the sender.
|
||||||
pub sender: Bytes,
|
pub sender: Bytes,
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
use alloy_sol_types::SolValue;
|
use alloy_sol_types::SolValue;
|
||||||
use anyhow::Error;
|
use anyhow::Error;
|
||||||
use num_bigint::BigUint;
|
use num_bigint::BigUint;
|
||||||
|
use std::cmp::min;
|
||||||
|
|
||||||
use crate::encoding::models::{
|
use crate::encoding::models::{
|
||||||
ActionType, EncodingContext, NativeAction, Solution, PROPELLER_ROUTER_ADDRESS,
|
ActionType, EncodingContext, NativeAction, Solution, PROPELLER_ROUTER_ADDRESS,
|
||||||
@@ -62,7 +63,9 @@ impl StrategyEncoder for SequentialStrategyEncoder {
|
|||||||
let one_hundred = BigUint::from(100u32);
|
let one_hundred = BigUint::from(100u32);
|
||||||
let slippage_percent = BigUint::from((solution.slippage.unwrap() * 100.0) as u32);
|
let slippage_percent = BigUint::from((solution.slippage.unwrap() * 100.0) as u32);
|
||||||
let multiplier = &one_hundred - slippage_percent;
|
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![];
|
let mut swaps = vec![];
|
||||||
for (index, swap) in solution.swaps.iter().enumerate() {
|
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> {
|
fn encode_strategy(&self, solution: Solution) -> Result<Vec<u8>, Error> {
|
||||||
todo!()
|
todo!()
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
use crate::encoding::models::Solution;
|
use crate::encoding::models::Solution;
|
||||||
use crate::encoding::strategy_encoder::{
|
use crate::encoding::strategy_encoder::{
|
||||||
SequentialStrategyEncoder, SingleSwapStrategyEncoder, SlipSwapStrategyEncoder,
|
SequentialStrategyEncoder, SingleSwapStrategyEncoder, SplitSwapStrategyEncoder,
|
||||||
StraightToPoolStrategyEncoder, StrategyEncoder,
|
StraightToPoolStrategyEncoder, StrategyEncoder,
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -19,7 +19,7 @@ impl StrategySelector for DefaultStrategySelector {
|
|||||||
} else if solution.swaps.iter().all(|s| s.split == 0.0) {
|
} else if solution.swaps.iter().all(|s| s.split == 0.0) {
|
||||||
Box::new(SequentialStrategyEncoder {})
|
Box::new(SequentialStrategyEncoder {})
|
||||||
} else {
|
} else {
|
||||||
Box::new(SlipSwapStrategyEncoder {})
|
Box::new(SplitSwapStrategyEncoder {})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user