From 09d4460e346547a3e4904f0ab1f95d1560c03a97 Mon Sep 17 00:00:00 2001 From: chefburger Date: Wed, 3 Apr 2024 10:12:23 +0800 Subject: [PATCH 1/3] optimization: inline literal number to avoid runtime hash calculation --- .../BinPoolManagerTest#testBurnNativeCurrency.snap | 2 +- .../BinPoolManagerTest#testGasBurnHalfBin.snap | 2 +- .../BinPoolManagerTest#testGasBurnNineBins.snap | 2 +- .../BinPoolManagerTest#testGasBurnOneBin.snap | 2 +- .../BinPoolManagerTest#testGasDonate.snap | 2 +- .../BinPoolManagerTest#testGasMintNneBins-1.snap | 2 +- .../BinPoolManagerTest#testGasMintNneBins-2.snap | 2 +- .../BinPoolManagerTest#testGasMintOneBin-1.snap | 2 +- .../BinPoolManagerTest#testGasMintOneBin-2.snap | 2 +- .../BinPoolManagerTest#testGasSwapMultipleBins.snap | 2 +- ...inPoolManagerTest#testGasSwapOverBigBinIdGate.snap | 2 +- .../BinPoolManagerTest#testGasSwapSingleBin.snap | 2 +- .../BinPoolManagerTest#testMintNativeCurrency.snap | 2 +- .../BinPoolManagerTest#testNoOpGas_Burn.snap | 2 +- .../BinPoolManagerTest#testNoOpGas_Donate.snap | 2 +- .../BinPoolManagerTest#testNoOpGas_Mint.snap | 2 +- .../BinPoolManagerTest#testNoOpGas_Swap.snap | 2 +- .../CLPoolManagerTest#addLiquidity_fromEmpty.snap | 2 +- .../CLPoolManagerTest#addLiquidity_fromNonEmpty.snap | 2 +- .../CLPoolManagerTest#addLiquidity_nativeToken.snap | 2 +- .../CLPoolManagerTest#donateBothTokens.snap | 2 +- .../CLPoolManagerTest#gasDonateOneToken.snap | 2 +- .../CLPoolManagerTest#removeLiquidity_toNonEmpty.snap | 2 +- .../CLPoolManagerTest#swap_againstLiquidity.snap | 2 +- ...PoolManagerTest#swap_leaveSurplusTokenInVault.snap | 2 +- .../CLPoolManagerTest#swap_runOutOfLiquidity.snap | 2 +- .forge-snapshots/CLPoolManagerTest#swap_simple.snap | 2 +- ...CLPoolManagerTest#swap_useSurplusTokenAsInput.snap | 2 +- .../CLPoolManagerTest#swap_withHooks.snap | 2 +- .../CLPoolManagerTest#swap_withNative.snap | 2 +- .../CLPoolManagerTest#testNoOp_gas_Donate.snap | 2 +- ...CLPoolManagerTest#testNoOp_gas_ModifyPosition.snap | 2 +- .../CLPoolManagerTest#testNoOp_gas_Swap.snap | 2 +- .forge-snapshots/VaultTest#Vault.snap | 2 +- .../VaultTest#lockSettledWhenAddLiquidity.snap | 2 +- .../VaultTest#lockSettledWhenFlashloan.snap | 2 +- .../VaultTest#lockSettledWhenMultiHopSwap.snap | 2 +- .forge-snapshots/VaultTest#lockSettledWhenSwap.snap | 2 +- .forge-snapshots/VaultTest#testLock_NoOp.snap | 2 +- .../VaultTest#testSettleAndMintRefund_WithMint.snap | 2 +- ...VaultTest#testSettleAndMintRefund_WithoutMint.snap | 2 +- src/libraries/SettlementGuard.sol | 11 ++++++++--- 42 files changed, 49 insertions(+), 44 deletions(-) diff --git a/.forge-snapshots/BinPoolManagerTest#testBurnNativeCurrency.snap b/.forge-snapshots/BinPoolManagerTest#testBurnNativeCurrency.snap index b6a0d9ab..50a28aa3 100644 --- a/.forge-snapshots/BinPoolManagerTest#testBurnNativeCurrency.snap +++ b/.forge-snapshots/BinPoolManagerTest#testBurnNativeCurrency.snap @@ -1 +1 @@ -92245 \ No newline at end of file +90458 \ No newline at end of file diff --git a/.forge-snapshots/BinPoolManagerTest#testGasBurnHalfBin.snap b/.forge-snapshots/BinPoolManagerTest#testGasBurnHalfBin.snap index e0a09995..8aa99939 100644 --- a/.forge-snapshots/BinPoolManagerTest#testGasBurnHalfBin.snap +++ b/.forge-snapshots/BinPoolManagerTest#testGasBurnHalfBin.snap @@ -1 +1 @@ -67437 \ No newline at end of file +65650 \ No newline at end of file diff --git a/.forge-snapshots/BinPoolManagerTest#testGasBurnNineBins.snap b/.forge-snapshots/BinPoolManagerTest#testGasBurnNineBins.snap index d570894d..fe24249b 100644 --- a/.forge-snapshots/BinPoolManagerTest#testGasBurnNineBins.snap +++ b/.forge-snapshots/BinPoolManagerTest#testGasBurnNineBins.snap @@ -1 +1 @@ -150992 \ No newline at end of file +149205 \ No newline at end of file diff --git a/.forge-snapshots/BinPoolManagerTest#testGasBurnOneBin.snap b/.forge-snapshots/BinPoolManagerTest#testGasBurnOneBin.snap index 33434dff..cfbc5c38 100644 --- a/.forge-snapshots/BinPoolManagerTest#testGasBurnOneBin.snap +++ b/.forge-snapshots/BinPoolManagerTest#testGasBurnOneBin.snap @@ -1 +1 @@ -68616 \ No newline at end of file +66829 \ No newline at end of file diff --git a/.forge-snapshots/BinPoolManagerTest#testGasDonate.snap b/.forge-snapshots/BinPoolManagerTest#testGasDonate.snap index 760655c0..2dbae6f8 100644 --- a/.forge-snapshots/BinPoolManagerTest#testGasDonate.snap +++ b/.forge-snapshots/BinPoolManagerTest#testGasDonate.snap @@ -1 +1 @@ -53952 \ No newline at end of file +52163 \ No newline at end of file diff --git a/.forge-snapshots/BinPoolManagerTest#testGasMintNneBins-1.snap b/.forge-snapshots/BinPoolManagerTest#testGasMintNneBins-1.snap index fcedea97..a5a07844 100644 --- a/.forge-snapshots/BinPoolManagerTest#testGasMintNneBins-1.snap +++ b/.forge-snapshots/BinPoolManagerTest#testGasMintNneBins-1.snap @@ -1 +1 @@ -968047 \ No newline at end of file +966258 \ No newline at end of file diff --git a/.forge-snapshots/BinPoolManagerTest#testGasMintNneBins-2.snap b/.forge-snapshots/BinPoolManagerTest#testGasMintNneBins-2.snap index 606a4052..495de64b 100644 --- a/.forge-snapshots/BinPoolManagerTest#testGasMintNneBins-2.snap +++ b/.forge-snapshots/BinPoolManagerTest#testGasMintNneBins-2.snap @@ -1 +1 @@ -121561 \ No newline at end of file +119772 \ No newline at end of file diff --git a/.forge-snapshots/BinPoolManagerTest#testGasMintOneBin-1.snap b/.forge-snapshots/BinPoolManagerTest#testGasMintOneBin-1.snap index 08f6d723..da90605c 100644 --- a/.forge-snapshots/BinPoolManagerTest#testGasMintOneBin-1.snap +++ b/.forge-snapshots/BinPoolManagerTest#testGasMintOneBin-1.snap @@ -1 +1 @@ -337237 \ No newline at end of file +335448 \ No newline at end of file diff --git a/.forge-snapshots/BinPoolManagerTest#testGasMintOneBin-2.snap b/.forge-snapshots/BinPoolManagerTest#testGasMintOneBin-2.snap index 46204462..dbbfb09c 100644 --- a/.forge-snapshots/BinPoolManagerTest#testGasMintOneBin-2.snap +++ b/.forge-snapshots/BinPoolManagerTest#testGasMintOneBin-2.snap @@ -1 +1 @@ -56298 \ No newline at end of file +54509 \ No newline at end of file diff --git a/.forge-snapshots/BinPoolManagerTest#testGasSwapMultipleBins.snap b/.forge-snapshots/BinPoolManagerTest#testGasSwapMultipleBins.snap index 2013546b..89bcec41 100644 --- a/.forge-snapshots/BinPoolManagerTest#testGasSwapMultipleBins.snap +++ b/.forge-snapshots/BinPoolManagerTest#testGasSwapMultipleBins.snap @@ -1 +1 @@ -93040 \ No newline at end of file +91252 \ No newline at end of file diff --git a/.forge-snapshots/BinPoolManagerTest#testGasSwapOverBigBinIdGate.snap b/.forge-snapshots/BinPoolManagerTest#testGasSwapOverBigBinIdGate.snap index 0ac0f030..21fd7032 100644 --- a/.forge-snapshots/BinPoolManagerTest#testGasSwapOverBigBinIdGate.snap +++ b/.forge-snapshots/BinPoolManagerTest#testGasSwapOverBigBinIdGate.snap @@ -1 +1 @@ -95025 \ No newline at end of file +93237 \ No newline at end of file diff --git a/.forge-snapshots/BinPoolManagerTest#testGasSwapSingleBin.snap b/.forge-snapshots/BinPoolManagerTest#testGasSwapSingleBin.snap index 5752d2a0..ca6b79a0 100644 --- a/.forge-snapshots/BinPoolManagerTest#testGasSwapSingleBin.snap +++ b/.forge-snapshots/BinPoolManagerTest#testGasSwapSingleBin.snap @@ -1 +1 @@ -74469 \ No newline at end of file +72681 \ No newline at end of file diff --git a/.forge-snapshots/BinPoolManagerTest#testMintNativeCurrency.snap b/.forge-snapshots/BinPoolManagerTest#testMintNativeCurrency.snap index 4a71833f..1044778c 100644 --- a/.forge-snapshots/BinPoolManagerTest#testMintNativeCurrency.snap +++ b/.forge-snapshots/BinPoolManagerTest#testMintNativeCurrency.snap @@ -1 +1 @@ -318945 \ No newline at end of file +317156 \ No newline at end of file diff --git a/.forge-snapshots/BinPoolManagerTest#testNoOpGas_Burn.snap b/.forge-snapshots/BinPoolManagerTest#testNoOpGas_Burn.snap index 644edbae..348354a5 100644 --- a/.forge-snapshots/BinPoolManagerTest#testNoOpGas_Burn.snap +++ b/.forge-snapshots/BinPoolManagerTest#testNoOpGas_Burn.snap @@ -1 +1 @@ -41876 \ No newline at end of file +41481 \ No newline at end of file diff --git a/.forge-snapshots/BinPoolManagerTest#testNoOpGas_Donate.snap b/.forge-snapshots/BinPoolManagerTest#testNoOpGas_Donate.snap index f17589cd..b87c2a40 100644 --- a/.forge-snapshots/BinPoolManagerTest#testNoOpGas_Donate.snap +++ b/.forge-snapshots/BinPoolManagerTest#testNoOpGas_Donate.snap @@ -1 +1 @@ -19493 \ No newline at end of file +19098 \ No newline at end of file diff --git a/.forge-snapshots/BinPoolManagerTest#testNoOpGas_Mint.snap b/.forge-snapshots/BinPoolManagerTest#testNoOpGas_Mint.snap index 78d7f8e8..ee7de557 100644 --- a/.forge-snapshots/BinPoolManagerTest#testNoOpGas_Mint.snap +++ b/.forge-snapshots/BinPoolManagerTest#testNoOpGas_Mint.snap @@ -1 +1 @@ -37345 \ No newline at end of file +36950 \ No newline at end of file diff --git a/.forge-snapshots/BinPoolManagerTest#testNoOpGas_Swap.snap b/.forge-snapshots/BinPoolManagerTest#testNoOpGas_Swap.snap index bbdca60d..b753e828 100644 --- a/.forge-snapshots/BinPoolManagerTest#testNoOpGas_Swap.snap +++ b/.forge-snapshots/BinPoolManagerTest#testNoOpGas_Swap.snap @@ -1 +1 @@ -22699 \ No newline at end of file +22304 \ No newline at end of file diff --git a/.forge-snapshots/CLPoolManagerTest#addLiquidity_fromEmpty.snap b/.forge-snapshots/CLPoolManagerTest#addLiquidity_fromEmpty.snap index a3b6d98b..26852b50 100644 --- a/.forge-snapshots/CLPoolManagerTest#addLiquidity_fromEmpty.snap +++ b/.forge-snapshots/CLPoolManagerTest#addLiquidity_fromEmpty.snap @@ -1 +1 @@ -348452 \ No newline at end of file +346663 \ No newline at end of file diff --git a/.forge-snapshots/CLPoolManagerTest#addLiquidity_fromNonEmpty.snap b/.forge-snapshots/CLPoolManagerTest#addLiquidity_fromNonEmpty.snap index 4bbcfa2c..27a19296 100644 --- a/.forge-snapshots/CLPoolManagerTest#addLiquidity_fromNonEmpty.snap +++ b/.forge-snapshots/CLPoolManagerTest#addLiquidity_fromNonEmpty.snap @@ -1 +1 @@ -61000 \ No newline at end of file +59211 \ No newline at end of file diff --git a/.forge-snapshots/CLPoolManagerTest#addLiquidity_nativeToken.snap b/.forge-snapshots/CLPoolManagerTest#addLiquidity_nativeToken.snap index 9d0018b5..707715ae 100644 --- a/.forge-snapshots/CLPoolManagerTest#addLiquidity_nativeToken.snap +++ b/.forge-snapshots/CLPoolManagerTest#addLiquidity_nativeToken.snap @@ -1 +1 @@ -241390 \ No newline at end of file +240256 \ No newline at end of file diff --git a/.forge-snapshots/CLPoolManagerTest#donateBothTokens.snap b/.forge-snapshots/CLPoolManagerTest#donateBothTokens.snap index ff632f9d..2536cff9 100644 --- a/.forge-snapshots/CLPoolManagerTest#donateBothTokens.snap +++ b/.forge-snapshots/CLPoolManagerTest#donateBothTokens.snap @@ -1 +1 @@ -84138 \ No newline at end of file +82349 \ No newline at end of file diff --git a/.forge-snapshots/CLPoolManagerTest#gasDonateOneToken.snap b/.forge-snapshots/CLPoolManagerTest#gasDonateOneToken.snap index ad879fda..7035f328 100644 --- a/.forge-snapshots/CLPoolManagerTest#gasDonateOneToken.snap +++ b/.forge-snapshots/CLPoolManagerTest#gasDonateOneToken.snap @@ -1 +1 @@ -53445 \ No newline at end of file +52311 \ No newline at end of file diff --git a/.forge-snapshots/CLPoolManagerTest#removeLiquidity_toNonEmpty.snap b/.forge-snapshots/CLPoolManagerTest#removeLiquidity_toNonEmpty.snap index beda75cb..285d5cdf 100644 --- a/.forge-snapshots/CLPoolManagerTest#removeLiquidity_toNonEmpty.snap +++ b/.forge-snapshots/CLPoolManagerTest#removeLiquidity_toNonEmpty.snap @@ -1 +1 @@ -43322 \ No newline at end of file +42189 \ No newline at end of file diff --git a/.forge-snapshots/CLPoolManagerTest#swap_againstLiquidity.snap b/.forge-snapshots/CLPoolManagerTest#swap_againstLiquidity.snap index 81cd8b6b..e31e4f1a 100644 --- a/.forge-snapshots/CLPoolManagerTest#swap_againstLiquidity.snap +++ b/.forge-snapshots/CLPoolManagerTest#swap_againstLiquidity.snap @@ -1 +1 @@ -56445 \ No newline at end of file +54657 \ No newline at end of file diff --git a/.forge-snapshots/CLPoolManagerTest#swap_leaveSurplusTokenInVault.snap b/.forge-snapshots/CLPoolManagerTest#swap_leaveSurplusTokenInVault.snap index cecfca2a..29acce68 100644 --- a/.forge-snapshots/CLPoolManagerTest#swap_leaveSurplusTokenInVault.snap +++ b/.forge-snapshots/CLPoolManagerTest#swap_leaveSurplusTokenInVault.snap @@ -1 +1 @@ -104543 \ No newline at end of file +102755 \ No newline at end of file diff --git a/.forge-snapshots/CLPoolManagerTest#swap_runOutOfLiquidity.snap b/.forge-snapshots/CLPoolManagerTest#swap_runOutOfLiquidity.snap index 4475c1ca..49f6c3f7 100644 --- a/.forge-snapshots/CLPoolManagerTest#swap_runOutOfLiquidity.snap +++ b/.forge-snapshots/CLPoolManagerTest#swap_runOutOfLiquidity.snap @@ -1 +1 @@ -25044269 \ No newline at end of file +25042481 \ No newline at end of file diff --git a/.forge-snapshots/CLPoolManagerTest#swap_simple.snap b/.forge-snapshots/CLPoolManagerTest#swap_simple.snap index 67c6dee8..e6662c09 100644 --- a/.forge-snapshots/CLPoolManagerTest#swap_simple.snap +++ b/.forge-snapshots/CLPoolManagerTest#swap_simple.snap @@ -1 +1 @@ -36336 \ No newline at end of file +35857 \ No newline at end of file diff --git a/.forge-snapshots/CLPoolManagerTest#swap_useSurplusTokenAsInput.snap b/.forge-snapshots/CLPoolManagerTest#swap_useSurplusTokenAsInput.snap index ac44f3fb..9ee1f8d8 100644 --- a/.forge-snapshots/CLPoolManagerTest#swap_useSurplusTokenAsInput.snap +++ b/.forge-snapshots/CLPoolManagerTest#swap_useSurplusTokenAsInput.snap @@ -1 +1 @@ -103041 \ No newline at end of file +101254 \ No newline at end of file diff --git a/.forge-snapshots/CLPoolManagerTest#swap_withHooks.snap b/.forge-snapshots/CLPoolManagerTest#swap_withHooks.snap index 0fd73b02..972b3462 100644 --- a/.forge-snapshots/CLPoolManagerTest#swap_withHooks.snap +++ b/.forge-snapshots/CLPoolManagerTest#swap_withHooks.snap @@ -1 +1 @@ -41986 \ No newline at end of file +41507 \ No newline at end of file diff --git a/.forge-snapshots/CLPoolManagerTest#swap_withNative.snap b/.forge-snapshots/CLPoolManagerTest#swap_withNative.snap index 0aecb1ad..982e70aa 100644 --- a/.forge-snapshots/CLPoolManagerTest#swap_withNative.snap +++ b/.forge-snapshots/CLPoolManagerTest#swap_withNative.snap @@ -1 +1 @@ -36339 \ No newline at end of file +35860 \ No newline at end of file diff --git a/.forge-snapshots/CLPoolManagerTest#testNoOp_gas_Donate.snap b/.forge-snapshots/CLPoolManagerTest#testNoOp_gas_Donate.snap index 7b7d760c..84f7479d 100644 --- a/.forge-snapshots/CLPoolManagerTest#testNoOp_gas_Donate.snap +++ b/.forge-snapshots/CLPoolManagerTest#testNoOp_gas_Donate.snap @@ -1 +1 @@ -19448 \ No newline at end of file +19053 \ No newline at end of file diff --git a/.forge-snapshots/CLPoolManagerTest#testNoOp_gas_ModifyPosition.snap b/.forge-snapshots/CLPoolManagerTest#testNoOp_gas_ModifyPosition.snap index 228723ef..97df4079 100644 --- a/.forge-snapshots/CLPoolManagerTest#testNoOp_gas_ModifyPosition.snap +++ b/.forge-snapshots/CLPoolManagerTest#testNoOp_gas_ModifyPosition.snap @@ -1 +1 @@ -27615 \ No newline at end of file +27220 \ No newline at end of file diff --git a/.forge-snapshots/CLPoolManagerTest#testNoOp_gas_Swap.snap b/.forge-snapshots/CLPoolManagerTest#testNoOp_gas_Swap.snap index 9e1e60bf..4f83ee50 100644 --- a/.forge-snapshots/CLPoolManagerTest#testNoOp_gas_Swap.snap +++ b/.forge-snapshots/CLPoolManagerTest#testNoOp_gas_Swap.snap @@ -1 +1 @@ -21897 \ No newline at end of file +21502 \ No newline at end of file diff --git a/.forge-snapshots/VaultTest#Vault.snap b/.forge-snapshots/VaultTest#Vault.snap index 6a3a44ed..85d18717 100644 --- a/.forge-snapshots/VaultTest#Vault.snap +++ b/.forge-snapshots/VaultTest#Vault.snap @@ -1 +1 @@ -7033 \ No newline at end of file +7180 \ No newline at end of file diff --git a/.forge-snapshots/VaultTest#lockSettledWhenAddLiquidity.snap b/.forge-snapshots/VaultTest#lockSettledWhenAddLiquidity.snap index cbf29f3c..830ad9f8 100644 --- a/.forge-snapshots/VaultTest#lockSettledWhenAddLiquidity.snap +++ b/.forge-snapshots/VaultTest#lockSettledWhenAddLiquidity.snap @@ -1 +1 @@ -122519 \ No newline at end of file +120730 \ No newline at end of file diff --git a/.forge-snapshots/VaultTest#lockSettledWhenFlashloan.snap b/.forge-snapshots/VaultTest#lockSettledWhenFlashloan.snap index 932d963e..02c149c9 100644 --- a/.forge-snapshots/VaultTest#lockSettledWhenFlashloan.snap +++ b/.forge-snapshots/VaultTest#lockSettledWhenFlashloan.snap @@ -1 +1 @@ -158811 \ No newline at end of file +156938 \ No newline at end of file diff --git a/.forge-snapshots/VaultTest#lockSettledWhenMultiHopSwap.snap b/.forge-snapshots/VaultTest#lockSettledWhenMultiHopSwap.snap index 37e2ed50..d816d6d9 100644 --- a/.forge-snapshots/VaultTest#lockSettledWhenMultiHopSwap.snap +++ b/.forge-snapshots/VaultTest#lockSettledWhenMultiHopSwap.snap @@ -1 +1 @@ -46974 \ No newline at end of file +45186 \ No newline at end of file diff --git a/.forge-snapshots/VaultTest#lockSettledWhenSwap.snap b/.forge-snapshots/VaultTest#lockSettledWhenSwap.snap index e6f87cf8..0a374883 100644 --- a/.forge-snapshots/VaultTest#lockSettledWhenSwap.snap +++ b/.forge-snapshots/VaultTest#lockSettledWhenSwap.snap @@ -1 +1 @@ -46973 \ No newline at end of file +45185 \ No newline at end of file diff --git a/.forge-snapshots/VaultTest#testLock_NoOp.snap b/.forge-snapshots/VaultTest#testLock_NoOp.snap index 8f91eb99..da1349a0 100644 --- a/.forge-snapshots/VaultTest#testLock_NoOp.snap +++ b/.forge-snapshots/VaultTest#testLock_NoOp.snap @@ -1 +1 @@ -11627 \ No newline at end of file +11232 \ No newline at end of file diff --git a/.forge-snapshots/VaultTest#testSettleAndMintRefund_WithMint.snap b/.forge-snapshots/VaultTest#testSettleAndMintRefund_WithMint.snap index 540ef842..7a0dcd43 100644 --- a/.forge-snapshots/VaultTest#testSettleAndMintRefund_WithMint.snap +++ b/.forge-snapshots/VaultTest#testSettleAndMintRefund_WithMint.snap @@ -1 +1 @@ -72506 \ No newline at end of file +71681 \ No newline at end of file diff --git a/.forge-snapshots/VaultTest#testSettleAndMintRefund_WithoutMint.snap b/.forge-snapshots/VaultTest#testSettleAndMintRefund_WithoutMint.snap index 6a51203d..fc54fab9 100644 --- a/.forge-snapshots/VaultTest#testSettleAndMintRefund_WithoutMint.snap +++ b/.forge-snapshots/VaultTest#testSettleAndMintRefund_WithoutMint.snap @@ -1 +1 @@ -34113 \ No newline at end of file +33288 \ No newline at end of file diff --git a/src/libraries/SettlementGuard.sol b/src/libraries/SettlementGuard.sol index 4cefceaa..f9f0f9e3 100644 --- a/src/libraries/SettlementGuard.sol +++ b/src/libraries/SettlementGuard.sol @@ -10,9 +10,14 @@ import {IVault} from "../interfaces/IVault.sol"; /// - 1: uint256 unsettledDeltasCount /// - 2: mapping(address, mapping(Currency => int256)) currencyDelta library SettlementGuard { - uint256 constant LOCKER_SLOT = uint256(keccak256("SETTLEMENT_LOCKER")) - 1; - uint256 constant UNSETTLED_DELTAS_COUNT = uint256(keccak256("SETTLEMENT_UNSETTLEMENTD_DELTAS_COUNT")) - 1; - uint256 constant CURRENCY_DELTA = uint256(keccak256("SETTLEMENT_CURRENCY_DELTA")) - 1; + // uint256 constant LOCKER_SLOT = uint256(keccak256("SETTLEMENT_LOCKER")) - 1; + uint256 constant LOCKER_SLOT = 0xedda7c051899c54dd66eaf5e13c031326ab4729812a579bed198ab93fd313d70; + + // uint256 constant UNSETTLED_DELTAS_COUNT = uint256(keccak256("SETTLEMENT_UNSETTLEMENTD_DELTAS_COUNT")) - 1; + uint256 constant UNSETTLED_DELTAS_COUNT = 0xa88ffc6a483ae852b901fb1c3a0df606e2e4461b493434e6643ebdc3ffabd151; + + // uint256 constant CURRENCY_DELTA = uint256(keccak256("SETTLEMENT_CURRENCY_DELTA")) - 1; + uint256 constant CURRENCY_DELTA = 0x6dc13502b9ba2a9e8e42c53a1856d632b29d5aab3bcb4a2476bfec06cbd9cf22; function setLocker(address newLocker) internal { address currentLocker = getLocker(); From 5276fae1cb5c9945a78e86b6e6d22841d540bba9 Mon Sep 17 00:00:00 2001 From: chefburger Date: Wed, 3 Apr 2024 10:34:14 +0800 Subject: [PATCH 2/3] optimization: uniform the swap fee boundry check rule (exclude to include) --- .../BinHookTest#testInitializeSucceedsWithHook.snap | 2 +- .../BinPoolManagerTest#testNoOpGas_Initialize.snap | 2 +- .../CLPoolManagerTest#initializeWithoutHooks.snap | 2 +- .../CLPoolManagerTest#testFuzzUpdateDynamicSwapFee.snap | 2 +- .../CLPoolManagerTest#testNoOp_gas_Initialize.snap | 2 +- src/libraries/FeeLibrary.sol | 2 +- src/pool-bin/BinPoolManager.sol | 4 ++-- src/pool-cl/CLPoolManager.sol | 2 +- test/libraries/FeeLibrary.sol | 2 +- test/pool-cl/CLPoolManager.t.sol | 6 +++--- test/pool-cl/libraries/CLPoolSwapFee.t.sol | 6 +++--- 11 files changed, 16 insertions(+), 16 deletions(-) diff --git a/.forge-snapshots/BinHookTest#testInitializeSucceedsWithHook.snap b/.forge-snapshots/BinHookTest#testInitializeSucceedsWithHook.snap index 87154c04..4e999170 100644 --- a/.forge-snapshots/BinHookTest#testInitializeSucceedsWithHook.snap +++ b/.forge-snapshots/BinHookTest#testInitializeSucceedsWithHook.snap @@ -1 +1 @@ -109021 \ No newline at end of file +108896 \ No newline at end of file diff --git a/.forge-snapshots/BinPoolManagerTest#testNoOpGas_Initialize.snap b/.forge-snapshots/BinPoolManagerTest#testNoOpGas_Initialize.snap index 5e68eac6..8b42096b 100644 --- a/.forge-snapshots/BinPoolManagerTest#testNoOpGas_Initialize.snap +++ b/.forge-snapshots/BinPoolManagerTest#testNoOpGas_Initialize.snap @@ -1 +1 @@ -37221 \ No newline at end of file +37096 \ No newline at end of file diff --git a/.forge-snapshots/CLPoolManagerTest#initializeWithoutHooks.snap b/.forge-snapshots/CLPoolManagerTest#initializeWithoutHooks.snap index a118ebd3..cfdb5d7c 100644 --- a/.forge-snapshots/CLPoolManagerTest#initializeWithoutHooks.snap +++ b/.forge-snapshots/CLPoolManagerTest#initializeWithoutHooks.snap @@ -1 +1 @@ -36477 \ No newline at end of file +36480 \ No newline at end of file diff --git a/.forge-snapshots/CLPoolManagerTest#testFuzzUpdateDynamicSwapFee.snap b/.forge-snapshots/CLPoolManagerTest#testFuzzUpdateDynamicSwapFee.snap index 752ba3d3..59641c57 100644 --- a/.forge-snapshots/CLPoolManagerTest#testFuzzUpdateDynamicSwapFee.snap +++ b/.forge-snapshots/CLPoolManagerTest#testFuzzUpdateDynamicSwapFee.snap @@ -1 +1 @@ -5496 \ No newline at end of file +5499 \ No newline at end of file diff --git a/.forge-snapshots/CLPoolManagerTest#testNoOp_gas_Initialize.snap b/.forge-snapshots/CLPoolManagerTest#testNoOp_gas_Initialize.snap index 023fdc04..c7a1b790 100644 --- a/.forge-snapshots/CLPoolManagerTest#testNoOp_gas_Initialize.snap +++ b/.forge-snapshots/CLPoolManagerTest#testNoOp_gas_Initialize.snap @@ -1 +1 @@ -37427 \ No newline at end of file +37430 \ No newline at end of file diff --git a/src/libraries/FeeLibrary.sol b/src/libraries/FeeLibrary.sol index c35a3282..f1503921 100644 --- a/src/libraries/FeeLibrary.sol +++ b/src/libraries/FeeLibrary.sol @@ -24,7 +24,7 @@ library FeeLibrary { } function isStaticFeeTooLarge(uint24 self, uint24 maxFee) internal pure returns (bool) { - return self & STATIC_FEE_MASK >= maxFee; + return self & STATIC_FEE_MASK > maxFee; } function getStaticFee(uint24 self) internal pure returns (uint24) { diff --git a/src/pool-bin/BinPoolManager.sol b/src/pool-bin/BinPoolManager.sol index 38c413d4..af1486c6 100644 --- a/src/pool-bin/BinPoolManager.sol +++ b/src/pool-bin/BinPoolManager.sol @@ -101,8 +101,8 @@ contract BinPoolManager is IBinPoolManager, Fees, Extsload { override poolManagerMatch(address(key.poolManager)) { - /// @dev Accept up to FeeLibrary.TEN_PERCENT_FEE for fee. Add +1 as isStaticFeeTooLarge function checks >= - if (key.fee.isStaticFeeTooLarge(FeeLibrary.TEN_PERCENT_FEE + 1)) revert FeeTooLarge(); + /// @dev Accept up to FeeLibrary.TEN_PERCENT_FEE for fee + if (key.fee.isStaticFeeTooLarge(FeeLibrary.TEN_PERCENT_FEE)) revert FeeTooLarge(); uint16 binStep = key.parameters.getBinStep(); if (binStep < MIN_BIN_STEP) revert BinStepTooSmall(); diff --git a/src/pool-cl/CLPoolManager.sol b/src/pool-cl/CLPoolManager.sol index 5b2324d3..daf47c8d 100644 --- a/src/pool-cl/CLPoolManager.sol +++ b/src/pool-cl/CLPoolManager.sol @@ -326,7 +326,7 @@ contract CLPoolManager is ICLPoolManager, Fees, Extsload { function _fetchDynamicSwapFee(PoolKey memory key) internal view returns (uint24 dynamicSwapFee) { dynamicSwapFee = ICLDynamicFeeManager(address(key.hooks)).getFee(msg.sender, key); - if (dynamicSwapFee >= FeeLibrary.ONE_HUNDRED_PERCENT_FEE) revert FeeTooLarge(); + if (dynamicSwapFee > FeeLibrary.ONE_HUNDRED_PERCENT_FEE) revert FeeTooLarge(); } function _checkPoolInitialized(PoolId id) internal view { diff --git a/test/libraries/FeeLibrary.sol b/test/libraries/FeeLibrary.sol index d8c44a9c..27dd7601 100644 --- a/test/libraries/FeeLibrary.sol +++ b/test/libraries/FeeLibrary.sol @@ -38,6 +38,6 @@ contract FeeLibraryTest is Test { } function testFuzzIsStaicFeeTooLarge(uint24 self, uint24 maxFee) public { - assertEq(FeeLibrary.getStaticFee(self) >= maxFee, FeeLibrary.isStaticFeeTooLarge(self, maxFee)); + assertEq(FeeLibrary.getStaticFee(self) > maxFee, FeeLibrary.isStaticFeeTooLarge(self, maxFee)); } } diff --git a/test/pool-cl/CLPoolManager.t.sol b/test/pool-cl/CLPoolManager.t.sol index 73be8265..e3995e6c 100644 --- a/test/pool-cl/CLPoolManager.t.sol +++ b/test/pool-cl/CLPoolManager.t.sol @@ -153,14 +153,14 @@ contract CLPoolManagerTest is Test, Deployers, TokenFixture, GasSnapshot { poolManager.initialize(key, TickMath.MIN_SQRT_RATIO, new bytes(0)); } - // 1000000 i.e. 100% overflow + // 1000000 i.e. 100% + 1 overflow { PoolKey memory key = PoolKey({ currency0: Currency.wrap(makeAddr("token0")), currency1: Currency.wrap(makeAddr("token1")), hooks: IHooks(address(0)), poolManager: poolManager, - fee: uint24(1000000), + fee: uint24(1000001), parameters: bytes32(uint256(0xa0000)) }); @@ -2339,7 +2339,7 @@ contract CLPoolManagerTest is Test, Deployers, TokenFixture, GasSnapshot { parameters: bytes32(uint256(10) << 16) }); - clFeeManagerHook.setFee(FeeLibrary.ONE_HUNDRED_PERCENT_FEE); + clFeeManagerHook.setFee(FeeLibrary.ONE_HUNDRED_PERCENT_FEE + 1); vm.expectRevert(IFees.FeeTooLarge.selector); poolManager.updateDynamicSwapFee(key); diff --git a/test/pool-cl/libraries/CLPoolSwapFee.t.sol b/test/pool-cl/libraries/CLPoolSwapFee.t.sol index d70cc875..3859fcaf 100644 --- a/test/pool-cl/libraries/CLPoolSwapFee.t.sol +++ b/test/pool-cl/libraries/CLPoolSwapFee.t.sol @@ -79,14 +79,14 @@ contract CLPoolSwapFeeTest is Deployers, TokenFixture, Test { function testPoolInitializeFailsWithTooLargeFee() public { // cl pool swap fee is capped at 1_000_000 - hook.setFee(FeeLibrary.ONE_HUNDRED_PERCENT_FEE); + hook.setFee(FeeLibrary.ONE_HUNDRED_PERCENT_FEE + 1); vm.expectRevert(IFees.FeeTooLarge.selector); poolManager.initialize(dynamicFeeKey, SQRT_RATIO_1_1, ZERO_BYTES); { vm.expectRevert(IFees.FeeTooLarge.selector); - staticFeeKey.fee = FeeLibrary.ONE_HUNDRED_PERCENT_FEE; + staticFeeKey.fee = FeeLibrary.ONE_HUNDRED_PERCENT_FEE + 1; poolManager.initialize(staticFeeKey, SQRT_RATIO_1_1, ZERO_BYTES); } } @@ -95,7 +95,7 @@ contract CLPoolSwapFeeTest is Deployers, TokenFixture, Test { hook.setFee(FeeLibrary.ONE_HUNDRED_PERCENT_FEE / 2); poolManager.initialize(dynamicFeeKey, SQRT_RATIO_1_1, ZERO_BYTES); - hook.setFee(FeeLibrary.ONE_HUNDRED_PERCENT_FEE); + hook.setFee(FeeLibrary.ONE_HUNDRED_PERCENT_FEE + 1); vm.expectRevert(IFees.FeeTooLarge.selector); poolManager.updateDynamicSwapFee(dynamicFeeKey); } From 11e86f491ca9ba3fb916c7aacbf5ce9fc769f755 Mon Sep 17 00:00:00 2001 From: chefburger Date: Tue, 9 Apr 2024 14:47:47 +0800 Subject: [PATCH 3/3] fix: test case test_initialize_fuzz --- test/pool-cl/CLPoolManager.t.sol | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/pool-cl/CLPoolManager.t.sol b/test/pool-cl/CLPoolManager.t.sol index c254804c..5c283385 100644 --- a/test/pool-cl/CLPoolManager.t.sol +++ b/test/pool-cl/CLPoolManager.t.sol @@ -300,7 +300,7 @@ contract CLPoolManagerTest is Test, Deployers, TokenFixture, GasSnapshot { key.hooks = IHooks(address(0)); key.poolManager = poolManager; - if (key.fee & FeeLibrary.STATIC_FEE_MASK >= FeeLibrary.ONE_HUNDRED_PERCENT_FEE) { + if (key.fee & FeeLibrary.STATIC_FEE_MASK > FeeLibrary.ONE_HUNDRED_PERCENT_FEE) { vm.expectRevert(abi.encodeWithSelector(IFees.FeeTooLarge.selector)); poolManager.initialize(key, sqrtPriceX96, ZERO_BYTES); } else if (key.parameters.getTickSpacing() > poolManager.MAX_TICK_SPACING()) {