From 62d1e90a608ba9bb4878cb2448ce5523e7a85f60 Mon Sep 17 00:00:00 2001 From: ChefMist <133624774+ChefMist@users.noreply.github.com> Date: Fri, 28 Jun 2024 11:51:04 +0800 Subject: [PATCH] [Feat] feat: add poolId -> poolKey mapping (#91) * feat: add poolId -> poolKey mapping * feat: include poolIdToPoolKey for BinPoolManager --- .../BinHookTest#testBurnSucceedsWithHook.snap | 2 +- .../BinHookTest#testDonateSucceedsWithHook.snap | 2 +- ...inHookTest#testInitializeSucceedsWithHook.snap | 2 +- .../BinHookTest#testMintSucceedsWithHook.snap | 2 +- .../BinHookTest#testSwapSucceedsWithHook.snap | 2 +- .forge-snapshots/BinPoolManagerBytecodeSize.snap | 2 +- ...BinPoolManagerTest#testBurnNativeCurrency.snap | 2 +- ...inPoolManagerTest#testExtLoadPoolActiveId.snap | 2 +- ...oolManagerTest#testFuzzUpdateDynamicLPFee.snap | 2 +- ...BinPoolManagerTest#testFuzz_SetMaxBinStep.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 +- ...inPoolManagerTest#testGasSwapMultipleBins.snap | 2 +- ...olManagerTest#testGasSwapOverBigBinIdGate.snap | 2 +- .../BinPoolManagerTest#testGasSwapSingleBin.snap | 2 +- ...Test#testInitialize_gasCheck_withoutHooks.snap | 1 + ...BinPoolManagerTest#testMintNativeCurrency.snap | 2 +- .../BinPoolManagerTest#testSetProtocolFee.snap | 2 +- .forge-snapshots/CLPoolManagerBytecodeSize.snap | 2 +- .../CLPoolManagerTest#addLiquidity_fromEmpty.snap | 2 +- ...PoolManagerTest#addLiquidity_fromNonEmpty.snap | 2 +- ...LPoolManagerTest#addLiquidity_nativeToken.snap | 2 +- .../CLPoolManagerTest#donateBothTokens.snap | 2 +- .../CLPoolManagerTest#gasDonateOneToken.snap | 2 +- .../CLPoolManagerTest#initializeWithoutHooks.snap | 2 +- ...oolManagerTest#removeLiquidity_toNonEmpty.snap | 2 +- .../CLPoolManagerTest#swap_againstLiquidity.snap | 2 +- ...ManagerTest#swap_leaveSurplusTokenInVault.snap | 2 +- .../CLPoolManagerTest#swap_runOutOfLiquidity.snap | 2 +- .../CLPoolManagerTest#swap_simple.snap | 2 +- ...olManagerTest#swap_useSurplusTokenAsInput.snap | 2 +- .../CLPoolManagerTest#swap_withHooks.snap | 2 +- .../CLPoolManagerTest#swap_withNative.snap | 2 +- ...oolManagerTest#testFuzzUpdateDynamicLPFee.snap | 2 +- .forge-snapshots/ExtsloadTest#extsload.snap | 2 +- .../ExtsloadTest#extsloadInBatch.snap | 2 +- .../VaultTest#lockSettledWhenAddLiquidity.snap | 2 +- .../VaultTest#lockSettledWhenMultiHopSwap.snap | 2 +- .../VaultTest#lockSettledWhenSwap.snap | 2 +- src/interfaces/IPoolManager.sol | 15 +++++++++++++++ src/pool-bin/BinPoolManager.sol | 4 ++++ src/pool-cl/CLPoolManager.sol | 4 ++++ test/pool-bin/BinPoolManager.t.sol | 15 +++++++++++++++ test/pool-cl/CLPoolManager.t.sol | 9 +++++++++ test/vault/FakePoolManager.sol | 3 +++ 51 files changed, 95 insertions(+), 44 deletions(-) create mode 100644 .forge-snapshots/BinPoolManagerTest#testInitialize_gasCheck_withoutHooks.snap diff --git a/.forge-snapshots/BinHookTest#testBurnSucceedsWithHook.snap b/.forge-snapshots/BinHookTest#testBurnSucceedsWithHook.snap index 19f5b3ba..e5ae9359 100644 --- a/.forge-snapshots/BinHookTest#testBurnSucceedsWithHook.snap +++ b/.forge-snapshots/BinHookTest#testBurnSucceedsWithHook.snap @@ -1 +1 @@ -178488 \ No newline at end of file +178510 \ No newline at end of file diff --git a/.forge-snapshots/BinHookTest#testDonateSucceedsWithHook.snap b/.forge-snapshots/BinHookTest#testDonateSucceedsWithHook.snap index 2c42e12c..a9c414a9 100644 --- a/.forge-snapshots/BinHookTest#testDonateSucceedsWithHook.snap +++ b/.forge-snapshots/BinHookTest#testDonateSucceedsWithHook.snap @@ -1 +1 @@ -181749 \ No newline at end of file +181771 \ No newline at end of file diff --git a/.forge-snapshots/BinHookTest#testInitializeSucceedsWithHook.snap b/.forge-snapshots/BinHookTest#testInitializeSucceedsWithHook.snap index a3aba86a..b48bc474 100644 --- a/.forge-snapshots/BinHookTest#testInitializeSucceedsWithHook.snap +++ b/.forge-snapshots/BinHookTest#testInitializeSucceedsWithHook.snap @@ -1 +1 @@ -136508 \ No newline at end of file +247511 diff --git a/.forge-snapshots/BinHookTest#testMintSucceedsWithHook.snap b/.forge-snapshots/BinHookTest#testMintSucceedsWithHook.snap index 0dd5208f..62809a53 100644 --- a/.forge-snapshots/BinHookTest#testMintSucceedsWithHook.snap +++ b/.forge-snapshots/BinHookTest#testMintSucceedsWithHook.snap @@ -1 +1 @@ -328264 \ No newline at end of file +328286 \ No newline at end of file diff --git a/.forge-snapshots/BinHookTest#testSwapSucceedsWithHook.snap b/.forge-snapshots/BinHookTest#testSwapSucceedsWithHook.snap index bacf35aa..8b63c1bc 100644 --- a/.forge-snapshots/BinHookTest#testSwapSucceedsWithHook.snap +++ b/.forge-snapshots/BinHookTest#testSwapSucceedsWithHook.snap @@ -1 +1 @@ -189292 \ No newline at end of file +189314 \ No newline at end of file diff --git a/.forge-snapshots/BinPoolManagerBytecodeSize.snap b/.forge-snapshots/BinPoolManagerBytecodeSize.snap index 840b36c2..1572975a 100644 --- a/.forge-snapshots/BinPoolManagerBytecodeSize.snap +++ b/.forge-snapshots/BinPoolManagerBytecodeSize.snap @@ -1 +1 @@ -24280 \ No newline at end of file +24762 diff --git a/.forge-snapshots/BinPoolManagerTest#testBurnNativeCurrency.snap b/.forge-snapshots/BinPoolManagerTest#testBurnNativeCurrency.snap index a2ef7fcc..d2693889 100644 --- a/.forge-snapshots/BinPoolManagerTest#testBurnNativeCurrency.snap +++ b/.forge-snapshots/BinPoolManagerTest#testBurnNativeCurrency.snap @@ -1 +1 @@ -133558 \ No newline at end of file +133576 \ No newline at end of file diff --git a/.forge-snapshots/BinPoolManagerTest#testExtLoadPoolActiveId.snap b/.forge-snapshots/BinPoolManagerTest#testExtLoadPoolActiveId.snap index af27f188..b0e318fa 100644 --- a/.forge-snapshots/BinPoolManagerTest#testExtLoadPoolActiveId.snap +++ b/.forge-snapshots/BinPoolManagerTest#testExtLoadPoolActiveId.snap @@ -1 +1 @@ -1873 \ No newline at end of file +1895 \ No newline at end of file diff --git a/.forge-snapshots/BinPoolManagerTest#testFuzzUpdateDynamicLPFee.snap b/.forge-snapshots/BinPoolManagerTest#testFuzzUpdateDynamicLPFee.snap index 00a54739..01b4887a 100644 --- a/.forge-snapshots/BinPoolManagerTest#testFuzzUpdateDynamicLPFee.snap +++ b/.forge-snapshots/BinPoolManagerTest#testFuzzUpdateDynamicLPFee.snap @@ -1 +1 @@ -32236 \ No newline at end of file +32258 \ No newline at end of file diff --git a/.forge-snapshots/BinPoolManagerTest#testFuzz_SetMaxBinStep.snap b/.forge-snapshots/BinPoolManagerTest#testFuzz_SetMaxBinStep.snap index 5c4021d1..21f4dac0 100644 --- a/.forge-snapshots/BinPoolManagerTest#testFuzz_SetMaxBinStep.snap +++ b/.forge-snapshots/BinPoolManagerTest#testFuzz_SetMaxBinStep.snap @@ -1 +1 @@ -34993 \ No newline at end of file +35015 \ No newline at end of file diff --git a/.forge-snapshots/BinPoolManagerTest#testGasBurnHalfBin.snap b/.forge-snapshots/BinPoolManagerTest#testGasBurnHalfBin.snap index 042a8a7d..70c95ed9 100644 --- a/.forge-snapshots/BinPoolManagerTest#testGasBurnHalfBin.snap +++ b/.forge-snapshots/BinPoolManagerTest#testGasBurnHalfBin.snap @@ -1 +1 @@ -142318 \ No newline at end of file +142340 \ No newline at end of file diff --git a/.forge-snapshots/BinPoolManagerTest#testGasBurnNineBins.snap b/.forge-snapshots/BinPoolManagerTest#testGasBurnNineBins.snap index f3011825..1768679d 100644 --- a/.forge-snapshots/BinPoolManagerTest#testGasBurnNineBins.snap +++ b/.forge-snapshots/BinPoolManagerTest#testGasBurnNineBins.snap @@ -1 +1 @@ -288084 \ No newline at end of file +288101 \ No newline at end of file diff --git a/.forge-snapshots/BinPoolManagerTest#testGasBurnOneBin.snap b/.forge-snapshots/BinPoolManagerTest#testGasBurnOneBin.snap index 75800488..b2cc8d2f 100644 --- a/.forge-snapshots/BinPoolManagerTest#testGasBurnOneBin.snap +++ b/.forge-snapshots/BinPoolManagerTest#testGasBurnOneBin.snap @@ -1 +1 @@ -126663 \ No newline at end of file +126681 \ No newline at end of file diff --git a/.forge-snapshots/BinPoolManagerTest#testGasDonate.snap b/.forge-snapshots/BinPoolManagerTest#testGasDonate.snap index d3c4f4a4..ecbbbad2 100644 --- a/.forge-snapshots/BinPoolManagerTest#testGasDonate.snap +++ b/.forge-snapshots/BinPoolManagerTest#testGasDonate.snap @@ -1 +1 @@ -114357 \ No newline at end of file +114379 \ No newline at end of file diff --git a/.forge-snapshots/BinPoolManagerTest#testGasMintNneBins-1.snap b/.forge-snapshots/BinPoolManagerTest#testGasMintNneBins-1.snap index a05c10f8..6d6bbe41 100644 --- a/.forge-snapshots/BinPoolManagerTest#testGasMintNneBins-1.snap +++ b/.forge-snapshots/BinPoolManagerTest#testGasMintNneBins-1.snap @@ -1 +1 @@ -967527 \ No newline at end of file +967549 \ No newline at end of file diff --git a/.forge-snapshots/BinPoolManagerTest#testGasMintNneBins-2.snap b/.forge-snapshots/BinPoolManagerTest#testGasMintNneBins-2.snap index 41a64e37..5710d86c 100644 --- a/.forge-snapshots/BinPoolManagerTest#testGasMintNneBins-2.snap +++ b/.forge-snapshots/BinPoolManagerTest#testGasMintNneBins-2.snap @@ -1 +1 @@ -325744 \ No newline at end of file +325766 \ No newline at end of file diff --git a/.forge-snapshots/BinPoolManagerTest#testGasMintOneBin-1.snap b/.forge-snapshots/BinPoolManagerTest#testGasMintOneBin-1.snap index 8429c455..607525b7 100644 --- a/.forge-snapshots/BinPoolManagerTest#testGasMintOneBin-1.snap +++ b/.forge-snapshots/BinPoolManagerTest#testGasMintOneBin-1.snap @@ -1 +1 @@ -337226 \ No newline at end of file +337248 \ No newline at end of file diff --git a/.forge-snapshots/BinPoolManagerTest#testGasMintOneBin-2.snap b/.forge-snapshots/BinPoolManagerTest#testGasMintOneBin-2.snap index 276cb335..9e1d1c59 100644 --- a/.forge-snapshots/BinPoolManagerTest#testGasMintOneBin-2.snap +++ b/.forge-snapshots/BinPoolManagerTest#testGasMintOneBin-2.snap @@ -1 +1 @@ -139628 \ No newline at end of file +139650 \ No newline at end of file diff --git a/.forge-snapshots/BinPoolManagerTest#testGasSwapMultipleBins.snap b/.forge-snapshots/BinPoolManagerTest#testGasSwapMultipleBins.snap index 1a367f15..0f44a535 100644 --- a/.forge-snapshots/BinPoolManagerTest#testGasSwapMultipleBins.snap +++ b/.forge-snapshots/BinPoolManagerTest#testGasSwapMultipleBins.snap @@ -1 +1 @@ -171592 \ No newline at end of file +171614 \ No newline at end of file diff --git a/.forge-snapshots/BinPoolManagerTest#testGasSwapOverBigBinIdGate.snap b/.forge-snapshots/BinPoolManagerTest#testGasSwapOverBigBinIdGate.snap index 60f2f15c..8d2927e1 100644 --- a/.forge-snapshots/BinPoolManagerTest#testGasSwapOverBigBinIdGate.snap +++ b/.forge-snapshots/BinPoolManagerTest#testGasSwapOverBigBinIdGate.snap @@ -1 +1 @@ -177473 \ No newline at end of file +177495 \ No newline at end of file diff --git a/.forge-snapshots/BinPoolManagerTest#testGasSwapSingleBin.snap b/.forge-snapshots/BinPoolManagerTest#testGasSwapSingleBin.snap index de4e3d96..c8ab0679 100644 --- a/.forge-snapshots/BinPoolManagerTest#testGasSwapSingleBin.snap +++ b/.forge-snapshots/BinPoolManagerTest#testGasSwapSingleBin.snap @@ -1 +1 @@ -132459 \ No newline at end of file +132481 \ No newline at end of file diff --git a/.forge-snapshots/BinPoolManagerTest#testInitialize_gasCheck_withoutHooks.snap b/.forge-snapshots/BinPoolManagerTest#testInitialize_gasCheck_withoutHooks.snap new file mode 100644 index 00000000..feb78d4b --- /dev/null +++ b/.forge-snapshots/BinPoolManagerTest#testInitialize_gasCheck_withoutHooks.snap @@ -0,0 +1 @@ +162167 \ No newline at end of file diff --git a/.forge-snapshots/BinPoolManagerTest#testMintNativeCurrency.snap b/.forge-snapshots/BinPoolManagerTest#testMintNativeCurrency.snap index a5374287..8d976032 100644 --- a/.forge-snapshots/BinPoolManagerTest#testMintNativeCurrency.snap +++ b/.forge-snapshots/BinPoolManagerTest#testMintNativeCurrency.snap @@ -1 +1 @@ -304183 \ No newline at end of file +304205 \ No newline at end of file diff --git a/.forge-snapshots/BinPoolManagerTest#testSetProtocolFee.snap b/.forge-snapshots/BinPoolManagerTest#testSetProtocolFee.snap index 7b5959d0..8830ba11 100644 --- a/.forge-snapshots/BinPoolManagerTest#testSetProtocolFee.snap +++ b/.forge-snapshots/BinPoolManagerTest#testSetProtocolFee.snap @@ -1 +1 @@ -34319 \ No newline at end of file +34341 \ No newline at end of file diff --git a/.forge-snapshots/CLPoolManagerBytecodeSize.snap b/.forge-snapshots/CLPoolManagerBytecodeSize.snap index 4df7aa43..6981f87e 100644 --- a/.forge-snapshots/CLPoolManagerBytecodeSize.snap +++ b/.forge-snapshots/CLPoolManagerBytecodeSize.snap @@ -1 +1 @@ -24256 \ No newline at end of file +24839 \ No newline at end of file diff --git a/.forge-snapshots/CLPoolManagerTest#addLiquidity_fromEmpty.snap b/.forge-snapshots/CLPoolManagerTest#addLiquidity_fromEmpty.snap index b2277962..3a7fcc7f 100644 --- a/.forge-snapshots/CLPoolManagerTest#addLiquidity_fromEmpty.snap +++ b/.forge-snapshots/CLPoolManagerTest#addLiquidity_fromEmpty.snap @@ -1 +1 @@ -351833 \ No newline at end of file +351855 \ No newline at end of file diff --git a/.forge-snapshots/CLPoolManagerTest#addLiquidity_fromNonEmpty.snap b/.forge-snapshots/CLPoolManagerTest#addLiquidity_fromNonEmpty.snap index ea8e029c..d32a3954 100644 --- a/.forge-snapshots/CLPoolManagerTest#addLiquidity_fromNonEmpty.snap +++ b/.forge-snapshots/CLPoolManagerTest#addLiquidity_fromNonEmpty.snap @@ -1 +1 @@ -167274 \ No newline at end of file +167296 \ No newline at end of file diff --git a/.forge-snapshots/CLPoolManagerTest#addLiquidity_nativeToken.snap b/.forge-snapshots/CLPoolManagerTest#addLiquidity_nativeToken.snap index 28a1449a..1c8fb171 100644 --- a/.forge-snapshots/CLPoolManagerTest#addLiquidity_nativeToken.snap +++ b/.forge-snapshots/CLPoolManagerTest#addLiquidity_nativeToken.snap @@ -1 +1 @@ -238701 \ No newline at end of file +238723 \ No newline at end of file diff --git a/.forge-snapshots/CLPoolManagerTest#donateBothTokens.snap b/.forge-snapshots/CLPoolManagerTest#donateBothTokens.snap index 28d724ed..dcb6b904 100644 --- a/.forge-snapshots/CLPoolManagerTest#donateBothTokens.snap +++ b/.forge-snapshots/CLPoolManagerTest#donateBothTokens.snap @@ -1 +1 @@ -164176 \ No newline at end of file +164198 \ No newline at end of file diff --git a/.forge-snapshots/CLPoolManagerTest#gasDonateOneToken.snap b/.forge-snapshots/CLPoolManagerTest#gasDonateOneToken.snap index 82e53809..cce44f3b 100644 --- a/.forge-snapshots/CLPoolManagerTest#gasDonateOneToken.snap +++ b/.forge-snapshots/CLPoolManagerTest#gasDonateOneToken.snap @@ -1 +1 @@ -109028 \ No newline at end of file +109050 \ No newline at end of file diff --git a/.forge-snapshots/CLPoolManagerTest#initializeWithoutHooks.snap b/.forge-snapshots/CLPoolManagerTest#initializeWithoutHooks.snap index 87a9cb92..d43a864a 100644 --- a/.forge-snapshots/CLPoolManagerTest#initializeWithoutHooks.snap +++ b/.forge-snapshots/CLPoolManagerTest#initializeWithoutHooks.snap @@ -1 +1 @@ -58707 \ No newline at end of file +149801 \ No newline at end of file diff --git a/.forge-snapshots/CLPoolManagerTest#removeLiquidity_toNonEmpty.snap b/.forge-snapshots/CLPoolManagerTest#removeLiquidity_toNonEmpty.snap index 2993078c..90515beb 100644 --- a/.forge-snapshots/CLPoolManagerTest#removeLiquidity_toNonEmpty.snap +++ b/.forge-snapshots/CLPoolManagerTest#removeLiquidity_toNonEmpty.snap @@ -1 +1 @@ -115249 \ No newline at end of file +115271 \ No newline at end of file diff --git a/.forge-snapshots/CLPoolManagerTest#swap_againstLiquidity.snap b/.forge-snapshots/CLPoolManagerTest#swap_againstLiquidity.snap index fd3f960f..4436a822 100644 --- a/.forge-snapshots/CLPoolManagerTest#swap_againstLiquidity.snap +++ b/.forge-snapshots/CLPoolManagerTest#swap_againstLiquidity.snap @@ -1 +1 @@ -131684 \ No newline at end of file +131706 \ No newline at end of file diff --git a/.forge-snapshots/CLPoolManagerTest#swap_leaveSurplusTokenInVault.snap b/.forge-snapshots/CLPoolManagerTest#swap_leaveSurplusTokenInVault.snap index d9d77ac5..1aedcca2 100644 --- a/.forge-snapshots/CLPoolManagerTest#swap_leaveSurplusTokenInVault.snap +++ b/.forge-snapshots/CLPoolManagerTest#swap_leaveSurplusTokenInVault.snap @@ -1 +1 @@ -164270 \ No newline at end of file +164292 \ No newline at end of file diff --git a/.forge-snapshots/CLPoolManagerTest#swap_runOutOfLiquidity.snap b/.forge-snapshots/CLPoolManagerTest#swap_runOutOfLiquidity.snap index 97c22d38..dd832b24 100644 --- a/.forge-snapshots/CLPoolManagerTest#swap_runOutOfLiquidity.snap +++ b/.forge-snapshots/CLPoolManagerTest#swap_runOutOfLiquidity.snap @@ -1 +1 @@ -151715 \ No newline at end of file +151737 \ No newline at end of file diff --git a/.forge-snapshots/CLPoolManagerTest#swap_simple.snap b/.forge-snapshots/CLPoolManagerTest#swap_simple.snap index 7434734f..49d08f5b 100644 --- a/.forge-snapshots/CLPoolManagerTest#swap_simple.snap +++ b/.forge-snapshots/CLPoolManagerTest#swap_simple.snap @@ -1 +1 @@ -72014 \ No newline at end of file +72036 \ No newline at end of file diff --git a/.forge-snapshots/CLPoolManagerTest#swap_useSurplusTokenAsInput.snap b/.forge-snapshots/CLPoolManagerTest#swap_useSurplusTokenAsInput.snap index 9f008da8..c335bec6 100644 --- a/.forge-snapshots/CLPoolManagerTest#swap_useSurplusTokenAsInput.snap +++ b/.forge-snapshots/CLPoolManagerTest#swap_useSurplusTokenAsInput.snap @@ -1 +1 @@ -143900 \ No newline at end of file +143922 \ No newline at end of file diff --git a/.forge-snapshots/CLPoolManagerTest#swap_withHooks.snap b/.forge-snapshots/CLPoolManagerTest#swap_withHooks.snap index eb1d7edc..d6268876 100644 --- a/.forge-snapshots/CLPoolManagerTest#swap_withHooks.snap +++ b/.forge-snapshots/CLPoolManagerTest#swap_withHooks.snap @@ -1 +1 @@ -87989 \ No newline at end of file +88011 \ No newline at end of file diff --git a/.forge-snapshots/CLPoolManagerTest#swap_withNative.snap b/.forge-snapshots/CLPoolManagerTest#swap_withNative.snap index e60bb23e..5610a843 100644 --- a/.forge-snapshots/CLPoolManagerTest#swap_withNative.snap +++ b/.forge-snapshots/CLPoolManagerTest#swap_withNative.snap @@ -1 +1 @@ -72017 \ No newline at end of file +72039 \ No newline at end of file diff --git a/.forge-snapshots/CLPoolManagerTest#testFuzzUpdateDynamicLPFee.snap b/.forge-snapshots/CLPoolManagerTest#testFuzzUpdateDynamicLPFee.snap index 11d783d8..400447fa 100644 --- a/.forge-snapshots/CLPoolManagerTest#testFuzzUpdateDynamicLPFee.snap +++ b/.forge-snapshots/CLPoolManagerTest#testFuzzUpdateDynamicLPFee.snap @@ -1 +1 @@ -31987 \ No newline at end of file +32009 \ No newline at end of file diff --git a/.forge-snapshots/ExtsloadTest#extsload.snap b/.forge-snapshots/ExtsloadTest#extsload.snap index 4027b7a7..a7f164ce 100644 --- a/.forge-snapshots/ExtsloadTest#extsload.snap +++ b/.forge-snapshots/ExtsloadTest#extsload.snap @@ -1 +1 @@ -7315 \ No newline at end of file +7337 \ No newline at end of file diff --git a/.forge-snapshots/ExtsloadTest#extsloadInBatch.snap b/.forge-snapshots/ExtsloadTest#extsloadInBatch.snap index bf5286ab..c20afdd0 100644 --- a/.forge-snapshots/ExtsloadTest#extsloadInBatch.snap +++ b/.forge-snapshots/ExtsloadTest#extsloadInBatch.snap @@ -1 +1 @@ -11028 \ No newline at end of file +11050 \ No newline at end of file diff --git a/.forge-snapshots/VaultTest#lockSettledWhenAddLiquidity.snap b/.forge-snapshots/VaultTest#lockSettledWhenAddLiquidity.snap index 69d73bb5..11cf91c0 100644 --- a/.forge-snapshots/VaultTest#lockSettledWhenAddLiquidity.snap +++ b/.forge-snapshots/VaultTest#lockSettledWhenAddLiquidity.snap @@ -1 +1 @@ -82036 \ No newline at end of file +82069 \ No newline at end of file diff --git a/.forge-snapshots/VaultTest#lockSettledWhenMultiHopSwap.snap b/.forge-snapshots/VaultTest#lockSettledWhenMultiHopSwap.snap index e0f82713..f57ae412 100644 --- a/.forge-snapshots/VaultTest#lockSettledWhenMultiHopSwap.snap +++ b/.forge-snapshots/VaultTest#lockSettledWhenMultiHopSwap.snap @@ -1 +1 @@ -42809 \ No newline at end of file +42842 \ No newline at end of file diff --git a/.forge-snapshots/VaultTest#lockSettledWhenSwap.snap b/.forge-snapshots/VaultTest#lockSettledWhenSwap.snap index 19635d5a..f83e3ffb 100644 --- a/.forge-snapshots/VaultTest#lockSettledWhenSwap.snap +++ b/.forge-snapshots/VaultTest#lockSettledWhenSwap.snap @@ -1 +1 @@ -42805 \ No newline at end of file +42838 \ No newline at end of file diff --git a/src/interfaces/IPoolManager.sol b/src/interfaces/IPoolManager.sol index e88489e5..878be21c 100644 --- a/src/interfaces/IPoolManager.sol +++ b/src/interfaces/IPoolManager.sol @@ -1,8 +1,10 @@ //SPDX-License-Identifier: MIT pragma solidity ^0.8.24; +import {IHooks} from "./IHooks.sol"; import {PoolKey} from "../types/PoolKey.sol"; import {PoolId} from "../types/PoolId.sol"; +import {Currency} from "../types/Currency.sol"; interface IPoolManager { /// @notice Thrown when trying to interact with a non-initialized pool @@ -25,4 +27,17 @@ interface IPoolManager { /// 2) For BinPool only, when hook#beforeMint() is called and hook call this function to update the lp fee /// 3) other use case where the hook might want to on an ad-hoc basis increase/reduce lp fee function updateDynamicLPFee(PoolKey memory key, uint24 newDynamicLPFee) external; + + /// @notice Return PoolKey for a given PoolId + function poolIdToPoolKey(PoolId id) + external + view + returns ( + Currency currency0, + Currency currency1, + IHooks hooks, + IPoolManager poolManager, + uint24 fee, + bytes32 parameters + ); } diff --git a/src/pool-bin/BinPoolManager.sol b/src/pool-bin/BinPoolManager.sol index 1681ae72..4d83e74e 100644 --- a/src/pool-bin/BinPoolManager.sol +++ b/src/pool-bin/BinPoolManager.sol @@ -40,6 +40,8 @@ contract BinPoolManager is IBinPoolManager, ProtocolFees, Extsload { mapping(PoolId id => BinPool.State) public pools; + mapping(PoolId id => PoolKey) public poolIdToPoolKey; + constructor(IVault vault, uint256 controllerGasLimit) ProtocolFees(vault, controllerGasLimit) {} /// @notice pool manager specified in the pool key must match current contract @@ -117,6 +119,8 @@ contract BinPoolManager is IBinPoolManager, ProtocolFees, Extsload { (, uint24 protocolFee) = _fetchProtocolFee(key); pools[id].initialize(activeId, protocolFee, lpFee); + poolIdToPoolKey[id] = key; + /// @notice Make sure the first event is noted, so that later events from afterHook won't get mixed up with this one emit Initialize(id, key.currency0, key.currency1, key.hooks, key.fee, key.parameters); diff --git a/src/pool-cl/CLPoolManager.sol b/src/pool-cl/CLPoolManager.sol index 1c0d37bc..c9b37f8d 100644 --- a/src/pool-cl/CLPoolManager.sol +++ b/src/pool-cl/CLPoolManager.sol @@ -42,6 +42,8 @@ contract CLPoolManager is ICLPoolManager, ProtocolFees, Extsload { mapping(PoolId id => CLPool.State) public pools; + mapping(PoolId id => PoolKey) public poolIdToPoolKey; + constructor(IVault _vault, uint256 controllerGasLimit) ProtocolFees(_vault, controllerGasLimit) {} /// @notice pool manager specified in the pool key must match current contract @@ -114,6 +116,8 @@ contract CLPoolManager is ICLPoolManager, ProtocolFees, Extsload { (, uint24 protocolFee) = _fetchProtocolFee(key); tick = pools[id].initialize(sqrtPriceX96, protocolFee, lpFee); + poolIdToPoolKey[id] = key; + /// @notice Make sure the first event is noted, so that later events from afterHook won't get mixed up with this one emit Initialize(id, key.currency0, key.currency1, key.hooks, key.fee, key.parameters); diff --git a/test/pool-bin/BinPoolManager.t.sol b/test/pool-bin/BinPoolManager.t.sol index 97a8bb43..7426676a 100644 --- a/test/pool-bin/BinPoolManager.t.sol +++ b/test/pool-bin/BinPoolManager.t.sol @@ -138,6 +138,12 @@ contract BinPoolManagerTest is Test, GasSnapshot, BinTestHelper { snapSize("BinPoolManagerBytecodeSize", address(poolManager)); } + function testInitialize_gasCheck_withoutHooks() public { + snapStart("BinPoolManagerTest#testInitialize_gasCheck_withoutHooks"); + poolManager.initialize(key, activeId, new bytes(0)); + snapEnd(); + } + function test_FuzzInitializePool(uint16 binStep) public { binStep = uint16(bound(binStep, poolManager.MIN_BIN_STEP(), poolManager.MAX_BIN_STEP())); @@ -159,6 +165,15 @@ contract BinPoolManagerTest is Test, GasSnapshot, BinTestHelper { emit Initialize(key.toId(), key.currency0, key.currency1, IHooks(address(mockHooks)), key.fee, key.parameters); poolManager.initialize(key, activeId, new bytes(0)); + + (Currency curr0, Currency curr1, IHooks hooks, IPoolManager pm, uint24 fee, bytes32 parameters) = + poolManager.poolIdToPoolKey(key.toId()); + assertEq(Currency.unwrap(curr0), Currency.unwrap(key.currency0)); + assertEq(Currency.unwrap(curr1), Currency.unwrap(key.currency1)); + assertEq(address(hooks), address(key.hooks)); + assertEq(address(pm), address(key.poolManager)); + assertEq(fee, key.fee); + assertEq(parameters, key.parameters); } function test_FuzzInitializePoolUnusedBits(uint256 randomOneBitOffset) external { diff --git a/test/pool-cl/CLPoolManager.t.sol b/test/pool-cl/CLPoolManager.t.sol index 6c351002..d63b4d2d 100644 --- a/test/pool-cl/CLPoolManager.t.sol +++ b/test/pool-cl/CLPoolManager.t.sol @@ -493,6 +493,15 @@ contract CLPoolManagerTest is Test, NoIsolate, Deployers, TokenFixture, GasSnaps poolManager.initialize(key, sqrtPriceX96, ZERO_BYTES); (CLPool.Slot0 memory slot0,,,) = poolManager.pools(key.toId()); assertEq(slot0.sqrtPriceX96, sqrtPriceX96); + + (Currency curr0, Currency curr1, IHooks hooks, IPoolManager pm, uint24 fee, bytes32 parameters) = + poolManager.poolIdToPoolKey(key.toId()); + assertEq(Currency.unwrap(curr0), Currency.unwrap(key.currency0)); + assertEq(Currency.unwrap(curr1), Currency.unwrap(key.currency1)); + assertEq(address(hooks), address(key.hooks)); + assertEq(address(pm), address(key.poolManager)); + assertEq(fee, key.fee); + assertEq(parameters, key.parameters); } function test_initialize_succeedsWithMaxTickSpacing(uint160 sqrtPriceX96) public { diff --git a/test/vault/FakePoolManager.sol b/test/vault/FakePoolManager.sol index e3f9a0e8..11a562a2 100644 --- a/test/vault/FakePoolManager.sol +++ b/test/vault/FakePoolManager.sol @@ -2,6 +2,7 @@ pragma solidity ^0.8.24; import {PoolKey} from "../../src/types/PoolKey.sol"; +import {PoolId} from "../../src/types/PoolId.sol"; import {IVault} from "../../src/interfaces/IVault.sol"; import {BalanceDelta, toBalanceDelta} from "../../src/types/BalanceDelta.sol"; import {IPoolManager} from "../../src/interfaces/IPoolManager.sol"; @@ -9,6 +10,8 @@ import {IPoolManager} from "../../src/interfaces/IPoolManager.sol"; contract FakePoolManager is IPoolManager { IVault public vault; + mapping(PoolId id => PoolKey) public poolIdToPoolKey; + constructor(IVault _vault) { vault = _vault; }