From 755774fee2b59e2fe7f27767cd2ccbdb8b1c6380 Mon Sep 17 00:00:00 2001 From: IliaAzhel Date: Fri, 19 Jul 2024 15:17:38 +0300 Subject: [PATCH] [Core] some fixes --- src/core/contracts/AlgebraFactory.sol | 2 +- src/core/contracts/AlgebraPool.sol | 4 ++-- src/core/contracts/base/SwapCalculation.sol | 1 - src/core/contracts/interfaces/pool/IAlgebraPoolErrors.sol | 3 --- src/core/test/AlgebraPool.spec.ts | 4 ++-- src/periphery/contracts/libraries/PoolAddress.sol | 2 +- 6 files changed, 6 insertions(+), 10 deletions(-) diff --git a/src/core/contracts/AlgebraFactory.sol b/src/core/contracts/AlgebraFactory.sol index f6312e6e..837aa19e 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 = 0x36e775f5fbc9f609c551e523f028f19fdafde4c7a92470b6319566f8c8a6ba40; + bytes32 public constant POOL_INIT_CODE_HASH = 0xcdb51997e6f36c9b2b26d23cc291ed7d71f87ad7cf09ecf1a9654d8dd1b2569f; constructor(address _poolDeployer) { require(_poolDeployer != address(0)); diff --git a/src/core/contracts/AlgebraPool.sol b/src/core/contracts/AlgebraPool.sol index 7b41d1b5..fadd0373 100644 --- a/src/core/contracts/AlgebraPool.sol +++ b/src/core/contracts/AlgebraPool.sol @@ -134,7 +134,6 @@ contract AlgebraPool is AlgebraPoolBase, TickStructure, ReentrancyGuard, Positio int128 liquidityDelta = -int128(amount); uint24 pluginFee = _beforeModifyPos(msg.sender, bottomTick, topTick, liquidityDelta, data); - if (pluginFee > 1e6) revert incorrectOverrideFee(); _lock(); _updateReserves(); @@ -179,6 +178,7 @@ contract AlgebraPool is AlgebraPoolBase, TickStructure, ReentrancyGuard, Positio if (globalState.pluginConfig.hasFlag(Plugins.BEFORE_POSITION_MODIFY_FLAG)) { bytes4 selector; (selector, pluginFee) = IAlgebraPlugin(plugin).beforeModifyPosition(msg.sender, owner, bottomTick, topTick, liquidityDelta, data); + if (pluginFee >= 1e6) revert incorrectPluginFee(); selector.shouldReturn(IAlgebraPlugin.beforeModifyPosition.selector); } } @@ -239,7 +239,6 @@ contract AlgebraPool is AlgebraPoolBase, TickStructure, ReentrancyGuard, Positio bytes calldata data ) external override returns (int256 amount0, int256 amount1) { (uint24 overrideFee, uint24 pluginFee) = _beforeSwap(recipient, zeroToOne, amountRequired, limitSqrtPrice, false, data); - if (overrideFee > 1e6) revert incorrectOverrideFee(); _lock(); { @@ -364,6 +363,7 @@ contract AlgebraPool is AlgebraPoolBase, TickStructure, ReentrancyGuard, Positio if (globalState.pluginConfig.hasFlag(Plugins.BEFORE_SWAP_FLAG)) { bytes4 selector; (selector, overrideFee, pluginFee) = IAlgebraPlugin(plugin).beforeSwap(msg.sender, recipient, zto, amount, limitPrice, payInAdvance, data); + if (overrideFee >= 1e6 || pluginFee > overrideFee) revert incorrectPluginFee(); selector.shouldReturn(IAlgebraPlugin.beforeSwap.selector); } } diff --git a/src/core/contracts/base/SwapCalculation.sol b/src/core/contracts/base/SwapCalculation.sol index 84349cfd..75fb28a6 100644 --- a/src/core/contracts/base/SwapCalculation.sol +++ b/src/core/contracts/base/SwapCalculation.sol @@ -48,7 +48,6 @@ abstract contract SwapCalculation is AlgebraPoolBase { int256 amountRequired, uint160 limitSqrtPrice ) internal returns (int256 amount0, int256 amount1, uint160 currentPrice, int24 currentTick, uint128 currentLiquidity, FeesAmount memory fees) { - if (pluginFee > overrideFee) revert incorrectPluginFee(); if (amountRequired == 0) revert zeroAmountRequired(); if (amountRequired == type(int256).min) revert invalidAmountRequired(); // to avoid problems when changing sign diff --git a/src/core/contracts/interfaces/pool/IAlgebraPoolErrors.sol b/src/core/contracts/interfaces/pool/IAlgebraPoolErrors.sol index fbc1ebb6..d91bf4d1 100644 --- a/src/core/contracts/interfaces/pool/IAlgebraPoolErrors.sol +++ b/src/core/contracts/interfaces/pool/IAlgebraPoolErrors.sol @@ -31,9 +31,6 @@ interface IAlgebraPoolErrors { /// @notice Emitted if a plugin returns invalid selector after pluginFeeHandle call error invalidPluginResponce(); - /// @notice Emitted if override fee param greater than 1e6 - error incorrectOverrideFee(); - /// @notice Emitted if the pool received fewer tokens than it should have error insufficientInputAmount(); diff --git a/src/core/test/AlgebraPool.spec.ts b/src/core/test/AlgebraPool.spec.ts index 2039f263..954d7323 100644 --- a/src/core/test/AlgebraPool.spec.ts +++ b/src/core/test/AlgebraPool.spec.ts @@ -2449,8 +2449,8 @@ describe('AlgebraPool', () => { it('swap fails if plugin fee exceeds max value', async () => { await poolPlugin.setPluginFees(1000001, 4000); - await expect(swapExact0For1(expandTo18Decimals(1), wallet.address)).to.be.revertedWithCustomError(pool, 'incorrectOverrideFee'); - await expect(pool.burn(minTick, maxTick, expandTo18Decimals(1), '0x')).to.be.revertedWithCustomError(pool, 'incorrectOverrideFee'); + await expect(swapExact0For1(expandTo18Decimals(1), wallet.address)).to.be.revertedWithCustomError(pool, 'incorrectPluginFee'); + await expect(pool.burn(minTick, maxTick, expandTo18Decimals(1), '0x')).to.be.revertedWithCustomError(pool, 'incorrectPluginFee'); }) it('swap fails if plugin return incorrect selector', async () => { diff --git a/src/periphery/contracts/libraries/PoolAddress.sol b/src/periphery/contracts/libraries/PoolAddress.sol index 3db69c42..65a517e5 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 = 0x36e775f5fbc9f609c551e523f028f19fdafde4c7a92470b6319566f8c8a6ba40; + bytes32 internal constant POOL_INIT_CODE_HASH = 0xcdb51997e6f36c9b2b26d23cc291ed7d71f87ad7cf09ecf1a9654d8dd1b2569f; /// @notice The identifying key of the pool struct PoolKey {