From 36e4173bd7888e6727d5d57a6668bd2e6e642f26 Mon Sep 17 00:00:00 2001 From: IliaAzhel Date: Fri, 19 Jul 2024 18:07:12 +0300 Subject: [PATCH] [Core] add isPlugin check --- src/core/contracts/AlgebraFactory.sol | 2 +- src/core/contracts/AlgebraPool.sol | 8 ++++++++ src/periphery/contracts/libraries/PoolAddress.sol | 2 +- 3 files changed, 10 insertions(+), 2 deletions(-) diff --git a/src/core/contracts/AlgebraFactory.sol b/src/core/contracts/AlgebraFactory.sol index 837aa19e..e522ecda 100644 --- a/src/core/contracts/AlgebraFactory.sol +++ b/src/core/contracts/AlgebraFactory.sol @@ -57,7 +57,7 @@ contract AlgebraFactory is IAlgebraFactory, Ownable2Step, AccessControlEnumerabl /// @inheritdoc IAlgebraFactory /// @dev keccak256 of AlgebraPool init bytecode. Used to compute pool address deterministically - bytes32 public constant POOL_INIT_CODE_HASH = 0xcdb51997e6f36c9b2b26d23cc291ed7d71f87ad7cf09ecf1a9654d8dd1b2569f; + bytes32 public constant POOL_INIT_CODE_HASH = 0x53a254b73c7f4f4a23175de0908ad4b30f3bc60806bd69bba905db6f24b991a5; constructor(address _poolDeployer) { require(_poolDeployer != address(0)); diff --git a/src/core/contracts/AlgebraPool.sol b/src/core/contracts/AlgebraPool.sol index fadd0373..1663dea2 100644 --- a/src/core/contracts/AlgebraPool.sol +++ b/src/core/contracts/AlgebraPool.sol @@ -168,6 +168,10 @@ contract AlgebraPool is AlgebraPoolBase, TickStructure, ReentrancyGuard, Positio _afterModifyPos(msg.sender, bottomTick, topTick, liquidityDelta, amount0, amount1, data); } + function _isPlugin() internal view returns (bool) { + return msg.sender == plugin; + } + function _beforeModifyPos( address owner, int24 bottomTick, @@ -176,6 +180,7 @@ contract AlgebraPool is AlgebraPoolBase, TickStructure, ReentrancyGuard, Positio bytes calldata data ) internal returns (uint24 pluginFee) { if (globalState.pluginConfig.hasFlag(Plugins.BEFORE_POSITION_MODIFY_FLAG)) { + if (_isPlugin()) return 0; bytes4 selector; (selector, pluginFee) = IAlgebraPlugin(plugin).beforeModifyPosition(msg.sender, owner, bottomTick, topTick, liquidityDelta, data); if (pluginFee >= 1e6) revert incorrectPluginFee(); @@ -184,6 +189,7 @@ contract AlgebraPool is AlgebraPoolBase, TickStructure, ReentrancyGuard, Positio } function _afterModifyPos(address owner, int24 bTick, int24 tTick, int128 deltaL, uint256 amount0, uint256 amount1, bytes calldata data) internal { + if (_isPlugin()) return; if (globalState.pluginConfig.hasFlag(Plugins.AFTER_POSITION_MODIFY_FLAG)) { IAlgebraPlugin(plugin).afterModifyPosition(msg.sender, owner, bTick, tTick, deltaL, amount0, amount1, data).shouldReturn( IAlgebraPlugin.afterModifyPosition.selector @@ -361,6 +367,7 @@ contract AlgebraPool is AlgebraPoolBase, TickStructure, ReentrancyGuard, Positio bytes calldata data ) internal returns (uint24 overrideFee, uint24 pluginFee) { if (globalState.pluginConfig.hasFlag(Plugins.BEFORE_SWAP_FLAG)) { + if (_isPlugin()) return (0, 0); bytes4 selector; (selector, overrideFee, pluginFee) = IAlgebraPlugin(plugin).beforeSwap(msg.sender, recipient, zto, amount, limitPrice, payInAdvance, data); if (overrideFee >= 1e6 || pluginFee > overrideFee) revert incorrectPluginFee(); @@ -370,6 +377,7 @@ contract AlgebraPool is AlgebraPoolBase, TickStructure, ReentrancyGuard, Positio function _afterSwap(address recipient, bool zto, int256 amount, uint160 limitPrice, int256 amount0, int256 amount1, bytes calldata data) internal { if (globalState.pluginConfig.hasFlag(Plugins.AFTER_SWAP_FLAG)) { + if (_isPlugin()) return; IAlgebraPlugin(plugin).afterSwap(msg.sender, recipient, zto, amount, limitPrice, amount0, amount1, data).shouldReturn( IAlgebraPlugin.afterSwap.selector ); diff --git a/src/periphery/contracts/libraries/PoolAddress.sol b/src/periphery/contracts/libraries/PoolAddress.sol index 65a517e5..770ef4d4 100644 --- a/src/periphery/contracts/libraries/PoolAddress.sol +++ b/src/periphery/contracts/libraries/PoolAddress.sol @@ -5,7 +5,7 @@ pragma solidity >=0.5.0; /// @dev Credit to Uniswap Labs under GPL-2.0-or-later license: /// https://github.com/Uniswap/v3-periphery library PoolAddress { - bytes32 internal constant POOL_INIT_CODE_HASH = 0xcdb51997e6f36c9b2b26d23cc291ed7d71f87ad7cf09ecf1a9654d8dd1b2569f; + bytes32 internal constant POOL_INIT_CODE_HASH = 0x53a254b73c7f4f4a23175de0908ad4b30f3bc60806bd69bba905db6f24b991a5; /// @notice The identifying key of the pool struct PoolKey {