Skip to content

Commit

Permalink
format
Browse files Browse the repository at this point in the history
  • Loading branch information
dianakocsis committed Sep 5, 2024
1 parent ae71fc6 commit b17719a
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 10 deletions.
22 changes: 14 additions & 8 deletions src/V4Router.sol
Original file line number Diff line number Diff line change
Expand Up @@ -122,14 +122,18 @@ abstract contract V4Router is IV4Router, BaseActionsRouter, DeltaResolver {

function _swapExactOutputSingle(IV4Router.ExactOutputSingleParams calldata params) private {
uint128 amountIn = (
uint256(-int256(_swap(
params.poolKey,
params.zeroForOne,
int256(uint256(params.amountOut)),
params.sqrtPriceLimitX96,
params.hookData
uint256(
-int256(
_swap(
params.poolKey,
params.zeroForOne,
int256(uint256(params.amountOut)),
params.sqrtPriceLimitX96,
params.hookData
)
)
)
))).toUint128();
).toUint128();
if (amountIn > params.amountInMaximum) revert V4TooMuchRequested(params.amountInMaximum, amountIn);
}

Expand All @@ -146,7 +150,9 @@ abstract contract V4Router is IV4Router, BaseActionsRouter, DeltaResolver {
pathKey = params.path[i - 1];
(PoolKey memory poolKey, bool oneForZero) = pathKey.getPoolAndSwapDirection(currencyOut);
// The output delta will always be negative, except for when interacting with certain hook pools
amountIn = (uint256(-int256(_swap(poolKey, !oneForZero, int256(uint256(amountOut)), 0, pathKey.hookData)))).toUint128();
amountIn = (
uint256(-int256(_swap(poolKey, !oneForZero, int256(uint256(amountOut)), 0, pathKey.hookData)))
).toUint128();

amountOut = amountIn;
currencyOut = pathKey.intermediateCurrency;
Expand Down
8 changes: 6 additions & 2 deletions src/libraries/SlippageCheck.sol
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,11 @@ library SlippageCheck {
// This means this contract will NOT support _positive_ slippage checks (minAmountOut checks) on pools where the hook returns a positive delta on mint/increase.
int256 amount0 = delta.amount0();
int256 amount1 = delta.amount1();
if (amount0 < 0 && amount0Max < uint256(-amount0)) revert MaximumAmountExceeded(uint256(amount0Max), uint256(-amount0));
if (amount1 < 0 && amount1Max < uint256(-amount1)) revert MaximumAmountExceeded(uint256(amount1Max), uint256(-amount1));
if (amount0 < 0 && amount0Max < uint256(-amount0)) {
revert MaximumAmountExceeded(uint256(amount0Max), uint256(-amount0));
}
if (amount1 < 0 && amount1Max < uint256(-amount1)) {
revert MaximumAmountExceeded(uint256(amount1Max), uint256(-amount1));
}
}
}

0 comments on commit b17719a

Please sign in to comment.