Skip to content

Commit

Permalink
Fixing hook address constants (#689)
Browse files Browse the repository at this point in the history
* Fixing hook address constants

* change variable name
  • Loading branch information
hensha256 authored May 22, 2024
1 parent e26ed2b commit f975e60
Show file tree
Hide file tree
Showing 8 changed files with 28 additions and 28 deletions.
2 changes: 1 addition & 1 deletion .forge-snapshots/addLiquidity with empty hook.snap
Original file line number Diff line number Diff line change
@@ -1 +1 @@
285659
285662
2 changes: 1 addition & 1 deletion .forge-snapshots/removeLiquidity with empty hook.snap
Original file line number Diff line number Diff line change
@@ -1 +1 @@
122628
141425
2 changes: 1 addition & 1 deletion .forge-snapshots/swap with hooks.snap
Original file line number Diff line number Diff line change
@@ -1 +1 @@
123297
142010
24 changes: 12 additions & 12 deletions test/PoolManager.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -249,7 +249,7 @@ contract PoolManagerTest is Test, Deployers, GasSnapshot {

address payable mockAddr =
payable(address(uint160(Hooks.BEFORE_ADD_LIQUIDITY_FLAG | Hooks.AFTER_ADD_LIQUIDITY_FLAG)));
address payable hookAddr = payable(Constants.MOCK_HOOKS);
address payable hookAddr = payable(Constants.ALL_HOOKS);

vm.etch(hookAddr, vm.getDeployedCode("EmptyTestHooks.sol:EmptyTestHooks"));
MockContract mockContract = new MockContract();
Expand Down Expand Up @@ -278,7 +278,7 @@ contract PoolManagerTest is Test, Deployers, GasSnapshot {

address payable mockAddr =
payable(address(uint160(Hooks.BEFORE_REMOVE_LIQUIDITY_FLAG | Hooks.AFTER_REMOVE_LIQUIDITY_FLAG)));
address payable hookAddr = payable(Constants.MOCK_HOOKS);
address payable hookAddr = payable(Constants.ALL_HOOKS);

vm.etch(hookAddr, vm.getDeployedCode("EmptyTestHooks.sol:EmptyTestHooks"));
MockContract mockContract = new MockContract();
Expand Down Expand Up @@ -508,10 +508,10 @@ contract PoolManagerTest is Test, Deployers, GasSnapshot {
}

function test_addLiquidity_withHooks_gas() public {
address hookEmptyAddr = Constants.EMPTY_HOOKS;
address allHooksAddr = Constants.ALL_HOOKS;
MockHooks impl = new MockHooks();
vm.etch(hookEmptyAddr, address(impl).code);
MockHooks mockHooks = MockHooks(hookEmptyAddr);
vm.etch(allHooksAddr, address(impl).code);
MockHooks mockHooks = MockHooks(allHooksAddr);

(key,) = initPool(currency0, currency1, mockHooks, 3000, SQRT_PRICE_1_1, ZERO_BYTES);

Expand All @@ -520,10 +520,10 @@ contract PoolManagerTest is Test, Deployers, GasSnapshot {
}

function test_removeLiquidity_withHooks_gas() public {
address hookEmptyAddr = Constants.EMPTY_HOOKS;
address allHooksAddr = Constants.ALL_HOOKS;
MockHooks impl = new MockHooks();
vm.etch(hookEmptyAddr, address(impl).code);
MockHooks mockHooks = MockHooks(hookEmptyAddr);
vm.etch(allHooksAddr, address(impl).code);
MockHooks mockHooks = MockHooks(allHooksAddr);

(key,) = initPool(currency0, currency1, mockHooks, 3000, SQRT_PRICE_1_1, ZERO_BYTES);
modifyLiquidityRouter.modifyLiquidity(key, LIQUIDITY_PARAMS, ZERO_BYTES);
Expand Down Expand Up @@ -584,7 +584,7 @@ contract PoolManagerTest is Test, Deployers, GasSnapshot {

function test_swap_succeedsWithHooksIfInitialized() public {
address payable mockAddr = payable(address(uint160(Hooks.BEFORE_SWAP_FLAG | Hooks.AFTER_SWAP_FLAG)));
address payable hookAddr = payable(Constants.MOCK_HOOKS);
address payable hookAddr = payable(Constants.ALL_HOOKS);

vm.etch(hookAddr, vm.getDeployedCode("EmptyTestHooks.sol:EmptyTestHooks"));
MockContract mockContract = new MockContract();
Expand Down Expand Up @@ -688,11 +688,11 @@ contract PoolManagerTest is Test, Deployers, GasSnapshot {
}

function test_swap_withHooks_gas() public {
address hookEmptyAddr = Constants.EMPTY_HOOKS;
address allHooksAddr = Constants.ALL_HOOKS;

MockHooks impl = new MockHooks();
vm.etch(hookEmptyAddr, address(impl).code);
MockHooks mockHooks = MockHooks(hookEmptyAddr);
vm.etch(allHooksAddr, address(impl).code);
MockHooks mockHooks = MockHooks(allHooksAddr);

(key,) = initPoolAndAddLiquidity(currency0, currency1, mockHooks, 3000, SQRT_PRICE_1_1, ZERO_BYTES);

Expand Down
8 changes: 4 additions & 4 deletions test/PoolManagerInitialize.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ contract PoolManagerInitializeTest is Test, Deployers, GasSnapshot {
sqrtPriceX96 = uint160(bound(sqrtPriceX96, TickMath.MIN_SQRT_PRICE, TickMath.MAX_SQRT_PRICE - 1));

address payable mockAddr = payable(address(uint160(Hooks.BEFORE_INITIALIZE_FLAG | Hooks.AFTER_INITIALIZE_FLAG)));
address payable hookAddr = payable(Constants.MOCK_HOOKS);
address payable hookAddr = payable(Constants.ALL_HOOKS);

vm.etch(hookAddr, vm.getDeployedCode("EmptyTestHooks.sol:EmptyTestHooks"));
MockContract mockContract = new MockContract();
Expand Down Expand Up @@ -163,11 +163,11 @@ contract PoolManagerInitializeTest is Test, Deployers, GasSnapshot {
// Assumptions tested in Pool.t.sol
sqrtPriceX96 = uint160(bound(sqrtPriceX96, TickMath.MIN_SQRT_PRICE, TickMath.MAX_SQRT_PRICE - 1));

address hookEmptyAddr = Constants.EMPTY_HOOKS;
address allHooksAddr = Constants.ALL_HOOKS;

MockHooks impl = new MockHooks();
vm.etch(hookEmptyAddr, address(impl).code);
MockHooks mockHooks = MockHooks(hookEmptyAddr);
vm.etch(allHooksAddr, address(impl).code);
MockHooks mockHooks = MockHooks(allHooksAddr);

uninitializedKey.hooks = mockHooks;

Expand Down
7 changes: 3 additions & 4 deletions test/libraries/Hooks.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -23,21 +23,20 @@ import {BalanceDelta} from "../../src/types/BalanceDelta.sol";
import {BaseTestHooks} from "../../src/test/BaseTestHooks.sol";
import {EmptyRevertHook} from "../../src/test/EmptyRevertHook.sol";
import {StateLibrary} from "../../src/libraries/StateLibrary.sol";
import {Constants} from "../utils/Constants.sol";

contract HooksTest is Test, Deployers, GasSnapshot {
using PoolIdLibrary for PoolKey;
using Hooks for IHooks;
using StateLibrary for IPoolManager;

/// 0011 1111 1111 1111
address payable ALL_HOOKS_ADDRESS = payable(0x0000000000000000000000000000000000003fFF);
MockHooks mockHooks;
BaseTestHooks revertingHookImpl;

function setUp() public {
MockHooks impl = new MockHooks();
vm.etch(ALL_HOOKS_ADDRESS, address(impl).code);
mockHooks = MockHooks(ALL_HOOKS_ADDRESS);
vm.etch(Constants.ALL_HOOKS, address(impl).code);
mockHooks = MockHooks(Constants.ALL_HOOKS);

revertingHookImpl = new BaseTestHooks();

Expand Down
5 changes: 3 additions & 2 deletions test/utils/Constants.sol
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,9 @@ library Constants {
uint160 constant MAX_UINT160 = type(uint160).max;

address constant ADDRESS_ZERO = address(0);
address constant EMPTY_HOOKS = address(0x0000000000000000000000000000000000003c00);
address constant MOCK_HOOKS = address(0x0000000000000000000000000000000000003Fc0);

/// 0011 1111 1111 1111
address payable constant ALL_HOOKS = payable(0x0000000000000000000000000000000000003fFF);

uint256 constant POOL_SLOT = 10;
uint256 constant TICKS_OFFSET = 4;
Expand Down
6 changes: 3 additions & 3 deletions test/utils/SwapHelper.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -19,19 +19,19 @@ import {PoolId, PoolIdLibrary} from "../../src/types/PoolId.sol";
import {PoolKey} from "../../src/types/PoolKey.sol";
import {IERC20Minimal} from "../../src/interfaces/external/IERC20Minimal.sol";
import {BalanceDelta} from "../../src/types/BalanceDelta.sol";
import {Constants} from "../utils/Constants.sol";

/// @notice Testing Deployers.swap() and Deployers.swapNativeInput()
contract SwapHelperTest is Test, Deployers, GasSnapshot {
using PoolIdLibrary for PoolKey;
using Hooks for IHooks;

address payable ALL_HOOKS_ADDRESS = payable(0x0000000000000000000000000000000000003fFF);
MockHooks mockHooks;

function setUp() public {
MockHooks impl = new MockHooks();
vm.etch(ALL_HOOKS_ADDRESS, address(impl).code);
mockHooks = MockHooks(ALL_HOOKS_ADDRESS);
vm.etch(Constants.ALL_HOOKS, address(impl).code);
mockHooks = MockHooks(Constants.ALL_HOOKS);

initializeManagerRoutersAndPoolsWithLiq(mockHooks);
}
Expand Down

0 comments on commit f975e60

Please sign in to comment.