Skip to content

Commit

Permalink
Merge branch 'main' into update-v4-core-submodule
Browse files Browse the repository at this point in the history
  • Loading branch information
saucepoint authored Mar 4, 2024
2 parents 8c41793 + 6045e2e commit 5f94b22
Show file tree
Hide file tree
Showing 48 changed files with 210 additions and 150 deletions.
2 changes: 1 addition & 1 deletion .forge-snapshots/FullOracleObserve0After5Seconds.snap
Original file line number Diff line number Diff line change
@@ -1 +1 @@
1922
1912
2 changes: 1 addition & 1 deletion .forge-snapshots/FullOracleObserve200By13.snap
Original file line number Diff line number Diff line change
@@ -1 +1 @@
20282
20210
2 changes: 1 addition & 1 deletion .forge-snapshots/FullOracleObserve200By13Plus5.snap
Original file line number Diff line number Diff line change
@@ -1 +1 @@
20520
20443
2 changes: 1 addition & 1 deletion .forge-snapshots/FullOracleObserve5After5Seconds.snap
Original file line number Diff line number Diff line change
@@ -1 +1 @@
2034
2024
2 changes: 1 addition & 1 deletion .forge-snapshots/FullOracleObserveOldest.snap
Original file line number Diff line number Diff line change
@@ -1 +1 @@
19330
19279
2 changes: 1 addition & 1 deletion .forge-snapshots/FullOracleObserveOldestAfter5Seconds.snap
Original file line number Diff line number Diff line change
@@ -1 +1 @@
19612
19555
2 changes: 1 addition & 1 deletion .forge-snapshots/FullOracleObserveZero.snap
Original file line number Diff line number Diff line change
@@ -1 +1 @@
1483
1477
2 changes: 1 addition & 1 deletion .forge-snapshots/FullRangeAddInitialLiquidity.snap
Original file line number Diff line number Diff line change
@@ -1 +1 @@
393062
392772
2 changes: 1 addition & 1 deletion .forge-snapshots/FullRangeAddLiquidity.snap
Original file line number Diff line number Diff line change
@@ -1 +1 @@
187418
187139
2 changes: 1 addition & 1 deletion .forge-snapshots/FullRangeFirstSwap.snap
Original file line number Diff line number Diff line change
@@ -1 +1 @@
136762
136542
2 changes: 1 addition & 1 deletion .forge-snapshots/FullRangeInitialize.snap
Original file line number Diff line number Diff line change
@@ -1 +1 @@
1059719
1041060
2 changes: 1 addition & 1 deletion .forge-snapshots/FullRangeRemoveLiquidity.snap
Original file line number Diff line number Diff line change
@@ -1 +1 @@
180886
175903
2 changes: 1 addition & 1 deletion .forge-snapshots/FullRangeRemoveLiquidityAndRebalance.snap
Original file line number Diff line number Diff line change
@@ -1 +1 @@
373831
363995
2 changes: 1 addition & 1 deletion .forge-snapshots/FullRangeSecondSwap.snap
Original file line number Diff line number Diff line change
@@ -1 +1 @@
97479
97295
2 changes: 1 addition & 1 deletion .forge-snapshots/FullRangeSwap.snap
Original file line number Diff line number Diff line change
@@ -1 +1 @@
135037
134817
2 changes: 1 addition & 1 deletion .forge-snapshots/OracleGrow10Slots.snap
Original file line number Diff line number Diff line change
@@ -1 +1 @@
232968
232960
2 changes: 1 addition & 1 deletion .forge-snapshots/OracleGrow10SlotsCardinalityGreater.snap
Original file line number Diff line number Diff line change
@@ -1 +1 @@
223657
223649
2 changes: 1 addition & 1 deletion .forge-snapshots/OracleGrow1Slot.snap
Original file line number Diff line number Diff line change
@@ -1 +1 @@
32853
32845
2 changes: 1 addition & 1 deletion .forge-snapshots/OracleGrow1SlotCardinalityGreater.snap
Original file line number Diff line number Diff line change
@@ -1 +1 @@
23553
23545
2 changes: 1 addition & 1 deletion .forge-snapshots/OracleInitialize.snap
Original file line number Diff line number Diff line change
@@ -1 +1 @@
51321
51310
Original file line number Diff line number Diff line change
@@ -1 +1 @@
5397
5368
2 changes: 1 addition & 1 deletion .forge-snapshots/OracleObserveCurrentTime.snap
Original file line number Diff line number Diff line change
@@ -1 +1 @@
1483
1477
Original file line number Diff line number Diff line change
@@ -1 +1 @@
1483
1477
2 changes: 1 addition & 1 deletion .forge-snapshots/OracleObserveLast20Seconds.snap
Original file line number Diff line number Diff line change
@@ -1 +1 @@
73451
73037
2 changes: 1 addition & 1 deletion .forge-snapshots/OracleObserveLatestEqual.snap
Original file line number Diff line number Diff line change
@@ -1 +1 @@
1483
1477
2 changes: 1 addition & 1 deletion .forge-snapshots/OracleObserveLatestTransform.snap
Original file line number Diff line number Diff line change
@@ -1 +1 @@
1922
1912
2 changes: 1 addition & 1 deletion .forge-snapshots/OracleObserveMiddle.snap
Original file line number Diff line number Diff line change
@@ -1 +1 @@
5572
5541
2 changes: 1 addition & 1 deletion .forge-snapshots/OracleObserveOldest.snap
Original file line number Diff line number Diff line change
@@ -1 +1 @@
5115
5092
2 changes: 1 addition & 1 deletion .forge-snapshots/OracleObserveSinceMostRecent.snap
Original file line number Diff line number Diff line change
@@ -1 +1 @@
2537
2522
2 changes: 1 addition & 1 deletion .forge-snapshots/TWAMMSubmitOrder.snap
Original file line number Diff line number Diff line change
@@ -1 +1 @@
122817
122753
2 changes: 1 addition & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,6 @@ jobs:
version: nightly

- name: Run tests
run: forge test -vvv --via-ir
run: forge test -vvv
env:
FOUNDRY_PROFILE: ci
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ contract CoolHook is BaseHook {
function beforeModifyPosition(
address,
IPoolManager.PoolKey calldata key,
IPoolManager.ModifyPositionParams calldata params
IPoolManager.ModifyLiquidityParams calldata params
) external override poolManagerOnly returns (bytes4) {
// hook logic
return BaseHook.beforeModifyPosition.selector;
Expand Down
31 changes: 25 additions & 6 deletions contracts/BaseHook.sol
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// SPDX-License-Identifier: UNLICENSED
pragma solidity ^0.8.19;
pragma solidity ^0.8.24;

import {Hooks} from "@uniswap/v4-core/src/libraries/Hooks.sol";
import {IPoolManager} from "@uniswap/v4-core/src/interfaces/IPoolManager.sol";
Expand Down Expand Up @@ -40,13 +40,13 @@ abstract contract BaseHook is IHooks {
_;
}

function getHooksCalls() public pure virtual returns (Hooks.Permissions memory);
function getHookPermissions() public pure virtual returns (Hooks.Permissions memory);

// this function is virtual so that we can override it during testing,
// which allows us to deploy an implementation to any address
// and then etch the bytecode into the correct address
function validateHookAddress(BaseHook _this) internal pure virtual {
Hooks.validateHookPermissions(_this, getHooksCalls());
Hooks.validateHookPermissions(_this, getHookPermissions());
}

function lockAcquired(address, /*sender*/ bytes calldata data)
Expand Down Expand Up @@ -77,18 +77,37 @@ abstract contract BaseHook is IHooks {
revert HookNotImplemented();
}

function beforeModifyPosition(address, PoolKey calldata, IPoolManager.ModifyPositionParams calldata, bytes calldata)
function beforeAddLiquidity(address, PoolKey calldata, IPoolManager.ModifyLiquidityParams calldata, bytes calldata)
external
virtual
returns (bytes4)
{
revert HookNotImplemented();
}

function afterModifyPosition(
function beforeRemoveLiquidity(
address,
PoolKey calldata,
IPoolManager.ModifyPositionParams calldata,
IPoolManager.ModifyLiquidityParams calldata,
bytes calldata
) external virtual returns (bytes4) {
revert HookNotImplemented();
}

function afterAddLiquidity(
address,
PoolKey calldata,
IPoolManager.ModifyLiquidityParams calldata,
BalanceDelta,
bytes calldata
) external virtual returns (bytes4) {
revert HookNotImplemented();
}

function afterRemoveLiquidity(
address,
PoolKey calldata,
IPoolManager.ModifyLiquidityParams calldata,
BalanceDelta,
bytes calldata
) external virtual returns (bytes4) {
Expand Down
36 changes: 19 additions & 17 deletions contracts/hooks/examples/FullRange.sol
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ contract FullRange is BaseHook, ILockCallback {
struct CallbackData {
address sender;
PoolKey key;
IPoolManager.ModifyPositionParams params;
IPoolManager.ModifyLiquidityParams params;
}

struct PoolInfo {
Expand Down Expand Up @@ -87,12 +87,14 @@ contract FullRange is BaseHook, ILockCallback {
_;
}

function getHooksCalls() public pure override returns (Hooks.Permissions memory) {
function getHookPermissions() public pure override returns (Hooks.Permissions memory) {
return Hooks.Permissions({
beforeInitialize: true,
afterInitialize: false,
beforeModifyPosition: true,
afterModifyPosition: false,
beforeAddLiquidity: true,
beforeRemoveLiquidity: false,
afterAddLiquidity: false,
afterRemoveLiquidity: false,
beforeSwap: true,
afterSwap: false,
beforeDonate: false,
Expand Down Expand Up @@ -138,7 +140,7 @@ contract FullRange is BaseHook, ILockCallback {
}
BalanceDelta addedDelta = modifyPosition(
key,
IPoolManager.ModifyPositionParams({
IPoolManager.ModifyLiquidityParams({
tickLower: MIN_TICK,
tickUpper: MAX_TICK,
liquidityDelta: liquidity.toInt256()
Expand Down Expand Up @@ -182,7 +184,7 @@ contract FullRange is BaseHook, ILockCallback {

delta = modifyPosition(
key,
IPoolManager.ModifyPositionParams({
IPoolManager.ModifyLiquidityParams({
tickLower: MIN_TICK,
tickUpper: MAX_TICK,
liquidityDelta: -(params.liquidity.toInt256())
Expand Down Expand Up @@ -219,15 +221,15 @@ contract FullRange is BaseHook, ILockCallback {
return FullRange.beforeInitialize.selector;
}

function beforeModifyPosition(
function beforeAddLiquidity(
address sender,
PoolKey calldata,
IPoolManager.ModifyPositionParams calldata,
IPoolManager.ModifyLiquidityParams calldata,
bytes calldata
) external view override returns (bytes4) {
if (sender != address(this)) revert SenderMustBeHook();

return FullRange.beforeModifyPosition.selector;
return FullRange.beforeAddLiquidity.selector;
}

function beforeSwap(address, PoolKey calldata key, IPoolManager.SwapParams calldata, bytes calldata)
Expand All @@ -245,7 +247,7 @@ contract FullRange is BaseHook, ILockCallback {
return IHooks.beforeSwap.selector;
}

function modifyPosition(PoolKey memory key, IPoolManager.ModifyPositionParams memory params)
function modifyPosition(PoolKey memory key, IPoolManager.ModifyLiquidityParams memory params)
internal
returns (BalanceDelta delta)
{
Expand Down Expand Up @@ -277,7 +279,7 @@ contract FullRange is BaseHook, ILockCallback {
poolManager.take(key.currency1, sender, uint256(uint128(-delta.amount1())));
}

function _removeLiquidity(PoolKey memory key, IPoolManager.ModifyPositionParams memory params)
function _removeLiquidity(PoolKey memory key, IPoolManager.ModifyLiquidityParams memory params)
internal
returns (BalanceDelta delta)
{
Expand All @@ -295,7 +297,7 @@ contract FullRange is BaseHook, ILockCallback {
);

params.liquidityDelta = -(liquidityToRemove.toInt256());
delta = poolManager.modifyPosition(key, params, ZERO_BYTES);
delta = poolManager.modifyLiquidity(key, params, ZERO_BYTES);
pool.hasAccruedFees = false;
}

Expand All @@ -314,17 +316,17 @@ contract FullRange is BaseHook, ILockCallback {
delta = _removeLiquidity(data.key, data.params);
_takeDeltas(data.sender, data.key, delta);
} else {
delta = poolManager.modifyPosition(data.key, data.params, ZERO_BYTES);
delta = poolManager.modifyLiquidity(data.key, data.params, ZERO_BYTES);
_settleDeltas(data.sender, data.key, delta);
}
return abi.encode(delta);
}

function _rebalance(PoolKey memory key) public {
PoolId poolId = key.toId();
BalanceDelta balanceDelta = poolManager.modifyPosition(
BalanceDelta balanceDelta = poolManager.modifyLiquidity(
key,
IPoolManager.ModifyPositionParams({
IPoolManager.ModifyLiquidityParams({
tickLower: MIN_TICK,
tickUpper: MAX_TICK,
liquidityDelta: -(poolManager.getLiquidity(poolId).toInt256())
Expand Down Expand Up @@ -358,9 +360,9 @@ contract FullRange is BaseHook, ILockCallback {
uint256(uint128(-balanceDelta.amount1()))
);

BalanceDelta balanceDeltaAfter = poolManager.modifyPosition(
BalanceDelta balanceDeltaAfter = poolManager.modifyLiquidity(
key,
IPoolManager.ModifyPositionParams({
IPoolManager.ModifyLiquidityParams({
tickLower: MIN_TICK,
tickUpper: MAX_TICK,
liquidityDelta: liquidity.toInt256()
Expand Down
Loading

0 comments on commit 5f94b22

Please sign in to comment.