Skip to content

Commit

Permalink
[Core] some fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
IliaAzhel committed Jul 19, 2024
1 parent c8aa329 commit 755774f
Show file tree
Hide file tree
Showing 6 changed files with 6 additions and 10 deletions.
2 changes: 1 addition & 1 deletion src/core/contracts/AlgebraFactory.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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));
Expand Down
4 changes: 2 additions & 2 deletions src/core/contracts/AlgebraPool.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down Expand Up @@ -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);
}
}
Expand Down Expand Up @@ -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();

{
Expand Down Expand Up @@ -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);
}
}
Expand Down
1 change: 0 additions & 1 deletion src/core/contracts/base/SwapCalculation.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
3 changes: 0 additions & 3 deletions src/core/contracts/interfaces/pool/IAlgebraPoolErrors.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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();

Expand Down
4 changes: 2 additions & 2 deletions src/core/test/AlgebraPool.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 () => {
Expand Down
2 changes: 1 addition & 1 deletion src/periphery/contracts/libraries/PoolAddress.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down

0 comments on commit 755774f

Please sign in to comment.