Skip to content

Commit

Permalink
fix(smart-contracts): update slippage tolerance to work with N coins
Browse files Browse the repository at this point in the history
  • Loading branch information
nseguias committed May 28, 2024
1 parent eab7ea1 commit 59e034a
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 0 deletions.
3 changes: 3 additions & 0 deletions contracts/liquidity_hub/pool-manager/src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,9 @@ pub enum ContractError {

#[error("Invalid swap route: {0}")]
InvalidSwapRoute(SwapRoute),

#[error("Invalid pool assets length, expected {expected} got {actual}")]
InvalidPoolAssetsLength { expected: usize, actual: usize },
}

impl From<semver::Error> for ContractError {
Expand Down
6 changes: 6 additions & 0 deletions contracts/liquidity_hub/pool-manager/src/helpers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -530,6 +530,12 @@ pub fn assert_slippage_tolerance(
}
}
PoolType::ConstantProduct => {
if deposits.len() != 2 || pools.len() != 2 {
return Err(ContractError::InvalidPoolAssetsLength {
expected: 2,
actual: deposits.len(),
});
}
if Decimal256::from_ratio(deposits[0], deposits[1]) * one_minus_slippage_tolerance
> Decimal256::from_ratio(pools[0], pools[1])
|| Decimal256::from_ratio(deposits[1], deposits[0])
Expand Down

0 comments on commit 59e034a

Please sign in to comment.