From 9c8fa74a7e2dd712bd3e3dcd981bbda1d7aa29f0 Mon Sep 17 00:00:00 2001 From: chefburger Date: Mon, 11 Nov 2024 16:24:51 +0800 Subject: [PATCH] fix: forge coverage stack too deep --- .../BinHookTest#testSwapSucceedsWithHook.snap | 2 +- .forge-snapshots/BinPoolManagerBytecodeSize.snap | 2 +- .../BinPoolManagerTest#testGasSwapMultipleBins.snap | 2 +- ...inPoolManagerTest#testGasSwapOverBigBinIdGate.snap | 2 +- .../BinPoolManagerTest#testGasSwapSingleBin.snap | 2 +- src/pool-bin/libraries/BinPool.sol | 11 +++++------ 6 files changed, 10 insertions(+), 11 deletions(-) diff --git a/.forge-snapshots/BinHookTest#testSwapSucceedsWithHook.snap b/.forge-snapshots/BinHookTest#testSwapSucceedsWithHook.snap index 211df2eb..78731c4c 100644 --- a/.forge-snapshots/BinHookTest#testSwapSucceedsWithHook.snap +++ b/.forge-snapshots/BinHookTest#testSwapSucceedsWithHook.snap @@ -1 +1 @@ -189959 \ No newline at end of file +190198 \ No newline at end of file diff --git a/.forge-snapshots/BinPoolManagerBytecodeSize.snap b/.forge-snapshots/BinPoolManagerBytecodeSize.snap index 07534292..270abcbb 100644 --- a/.forge-snapshots/BinPoolManagerBytecodeSize.snap +++ b/.forge-snapshots/BinPoolManagerBytecodeSize.snap @@ -1 +1 @@ -23548 \ No newline at end of file +23602 \ No newline at end of file diff --git a/.forge-snapshots/BinPoolManagerTest#testGasSwapMultipleBins.snap b/.forge-snapshots/BinPoolManagerTest#testGasSwapMultipleBins.snap index d1be9631..192e1ca9 100644 --- a/.forge-snapshots/BinPoolManagerTest#testGasSwapMultipleBins.snap +++ b/.forge-snapshots/BinPoolManagerTest#testGasSwapMultipleBins.snap @@ -1 +1 @@ -177927 \ No newline at end of file +178883 \ No newline at end of file diff --git a/.forge-snapshots/BinPoolManagerTest#testGasSwapOverBigBinIdGate.snap b/.forge-snapshots/BinPoolManagerTest#testGasSwapOverBigBinIdGate.snap index 7802c629..b2772897 100644 --- a/.forge-snapshots/BinPoolManagerTest#testGasSwapOverBigBinIdGate.snap +++ b/.forge-snapshots/BinPoolManagerTest#testGasSwapOverBigBinIdGate.snap @@ -1 +1 @@ -184209 \ No newline at end of file +185165 \ No newline at end of file diff --git a/.forge-snapshots/BinPoolManagerTest#testGasSwapSingleBin.snap b/.forge-snapshots/BinPoolManagerTest#testGasSwapSingleBin.snap index ba7cd49d..95111a71 100644 --- a/.forge-snapshots/BinPoolManagerTest#testGasSwapSingleBin.snap +++ b/.forge-snapshots/BinPoolManagerTest#testGasSwapSingleBin.snap @@ -1 +1 @@ -133637 \ No newline at end of file +133876 \ No newline at end of file diff --git a/src/pool-bin/libraries/BinPool.sol b/src/pool-bin/libraries/BinPool.sol index 410e2397..b16ababa 100644 --- a/src/pool-bin/libraries/BinPool.sol +++ b/src/pool-bin/libraries/BinPool.sol @@ -169,15 +169,15 @@ library BinPool { amountsInWithFees = amountsInWithFees.sub(pFee); } - bytes32 newReserve = binReserves.add(amountsInWithFees).sub(amountsOutOfBin); if ( - newReserve.getLiquidity(swapState.activeId.getPriceFromId(params.binStep)) - > Constants.MAX_LIQUIDITY_PER_BIN + (binReserves.add(amountsInWithFees).sub(amountsOutOfBin)).getLiquidity( + swapState.activeId.getPriceFromId(params.binStep) + ) > Constants.MAX_LIQUIDITY_PER_BIN ) { revert BinPool__MaxLiquidityPerBinExceeded(); } - self.reserveOfBin[swapState.activeId] = newReserve; + self.reserveOfBin[swapState.activeId] = binReserves.add(amountsInWithFees).sub(amountsOutOfBin); } } @@ -357,8 +357,7 @@ library BinPool { /// @dev overflow check on total reserves and the resulting liquidity uint256 price = activeId.getPriceFromId(binStep); bytes32 newReserves = binReserves.add(amountIn); - uint256 liquidity = newReserves.getLiquidity(price); - if (liquidity > Constants.MAX_LIQUIDITY_PER_BIN) { + if (newReserves.getLiquidity(price) > Constants.MAX_LIQUIDITY_PER_BIN) { revert BinPool__MaxLiquidityPerBinExceeded(); }