Skip to content

Commit

Permalink
Update to core-next latest (currency order + arb hook data) (#50)
Browse files Browse the repository at this point in the history
* updating to next core-next

* finish up

* don't change submodules

* update to latest v4-core with currency order & arb data

* PR comments
  • Loading branch information
ewilz authored Aug 22, 2023
1 parent 028e7b6 commit fbe8376
Show file tree
Hide file tree
Showing 20 changed files with 393 additions and 228 deletions.
2 changes: 1 addition & 1 deletion .forge-snapshots/FullRangeAddInitialLiquidity.snap
Original file line number Diff line number Diff line change
@@ -1 +1 @@
412012
413016
2 changes: 1 addition & 1 deletion .forge-snapshots/FullRangeAddLiquidity.snap
Original file line number Diff line number Diff line change
@@ -1 +1 @@
206278
207282
2 changes: 1 addition & 1 deletion .forge-snapshots/FullRangeFirstSwap.snap
Original file line number Diff line number Diff line change
@@ -1 +1 @@
152057
153143
2 changes: 1 addition & 1 deletion .forge-snapshots/FullRangeInitialize.snap
Original file line number Diff line number Diff line change
@@ -1 +1 @@
878152
879088
2 changes: 1 addition & 1 deletion .forge-snapshots/FullRangeRemoveLiquidity.snap
Original file line number Diff line number Diff line change
@@ -1 +1 @@
199416
200439
2 changes: 1 addition & 1 deletion .forge-snapshots/FullRangeRemoveLiquidityAndRebalance.snap
Original file line number Diff line number Diff line change
@@ -1 +1 @@
375677
380062
2 changes: 1 addition & 1 deletion .forge-snapshots/FullRangeSecondSwap.snap
Original file line number Diff line number Diff line change
@@ -1 +1 @@
109596
110682
2 changes: 1 addition & 1 deletion .forge-snapshots/FullRangeSwap.snap
Original file line number Diff line number Diff line change
@@ -1 +1 @@
150064
151418
2 changes: 1 addition & 1 deletion .forge-snapshots/TWAMMSubmitOrder.snap
Original file line number Diff line number Diff line change
@@ -1 +1 @@
124175
123914
36 changes: 25 additions & 11 deletions contracts/BaseHook.sol
Original file line number Diff line number Diff line change
Expand Up @@ -60,51 +60,65 @@ abstract contract BaseHook is IHooks {
}
}

function beforeInitialize(address, PoolKey calldata, uint160) external virtual returns (bytes4) {
function beforeInitialize(address, PoolKey calldata, uint160, bytes calldata) external virtual returns (bytes4) {
revert HookNotImplemented();
}

function afterInitialize(address, PoolKey calldata, uint160, int24) external virtual returns (bytes4) {
revert HookNotImplemented();
}

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

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

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

function beforeSwap(address, PoolKey calldata, IPoolManager.SwapParams calldata, bytes calldata)
external
virtual
returns (bytes4)
{
revert HookNotImplemented();
}

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

function beforeDonate(address, PoolKey calldata, uint256, uint256) external virtual returns (bytes4) {
function beforeDonate(address, PoolKey calldata, uint256, uint256, bytes calldata)
external
virtual
returns (bytes4)
{
revert HookNotImplemented();
}

function afterDonate(address, PoolKey calldata, uint256, uint256) external virtual returns (bytes4) {
function afterDonate(address, PoolKey calldata, uint256, uint256, bytes calldata)
external
virtual
returns (bytes4)
{
revert HookNotImplemented();
}
}
37 changes: 23 additions & 14 deletions contracts/hooks/examples/FullRange.sol
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@ contract FullRange is BaseHook, ILockCallback {
error ExpiredPastDeadline();
error TooMuchSlippage();

bytes internal constant ZERO_BYTES = bytes("");

/// @dev Min tick for full range with tick spacing of 60
int24 internal constant MIN_TICK = -887220;
/// @dev Max tick for full range with tick spacing of 60
Expand Down Expand Up @@ -188,7 +190,11 @@ contract FullRange is BaseHook, ILockCallback {
erc20.burn(msg.sender, params.liquidity);
}

function beforeInitialize(address, PoolKey calldata key, uint160) external override returns (bytes4) {
function beforeInitialize(address, PoolKey calldata key, uint160, bytes calldata)
external
override
returns (bytes4)
{
if (key.tickSpacing != 60) revert TickSpacingNotDefault();

PoolId poolId = key.toId();
Expand All @@ -211,18 +217,18 @@ contract FullRange is BaseHook, ILockCallback {
return FullRange.beforeInitialize.selector;
}

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

return FullRange.beforeModifyPosition.selector;
}

function beforeSwap(address, PoolKey calldata key, IPoolManager.SwapParams calldata)
function beforeSwap(address, PoolKey calldata key, IPoolManager.SwapParams calldata, bytes calldata)
external
override
returns (bytes4)
Expand Down Expand Up @@ -285,7 +291,7 @@ contract FullRange is BaseHook, ILockCallback {
);

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

Expand All @@ -302,7 +308,7 @@ 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);
delta = poolManager.modifyPosition(data.key, data.params, ZERO_BYTES);
_settleDeltas(data.sender, data.key, delta);
}
return abi.encode(delta);
Expand All @@ -316,7 +322,8 @@ contract FullRange is BaseHook, ILockCallback {
tickLower: MIN_TICK,
tickUpper: MAX_TICK,
liquidityDelta: -(poolManager.getLiquidity(poolId).toInt256())
})
}),
ZERO_BYTES
);

uint160 newSqrtPriceX96 = (
Expand All @@ -333,7 +340,8 @@ contract FullRange is BaseHook, ILockCallback {
zeroForOne: newSqrtPriceX96 < sqrtPriceX96,
amountSpecified: MAX_INT,
sqrtPriceLimitX96: newSqrtPriceX96
})
}),
ZERO_BYTES
);

uint128 liquidity = LiquidityAmounts.getLiquidityForAmounts(
Expand All @@ -350,13 +358,14 @@ contract FullRange is BaseHook, ILockCallback {
tickLower: MIN_TICK,
tickUpper: MAX_TICK,
liquidityDelta: liquidity.toInt256()
})
}),
ZERO_BYTES
);

// Donate any "dust" from the sqrtRatio change as fees
uint128 donateAmount0 = uint128(-balanceDelta.amount0() - balanceDeltaAfter.amount0());
uint128 donateAmount1 = uint128(-balanceDelta.amount1() - balanceDeltaAfter.amount1());

poolManager.donate(key, donateAmount0, donateAmount1);
poolManager.donate(key, donateAmount0, donateAmount1, ZERO_BYTES);
}
}
18 changes: 9 additions & 9 deletions contracts/hooks/examples/GeomeanOracle.sol
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ contract GeomeanOracle is BaseHook {
});
}

function beforeInitialize(address, PoolKey calldata key, uint160)
function beforeInitialize(address, PoolKey calldata key, uint160, bytes calldata)
external
view
override
Expand All @@ -87,7 +87,7 @@ contract GeomeanOracle is BaseHook {
return GeomeanOracle.beforeInitialize.selector;
}

function afterInitialize(address, PoolKey calldata key, uint160, int24)
function afterInitialize(address, PoolKey calldata key, uint160, int24, bytes calldata)
external
override
poolManagerOnly
Expand All @@ -110,12 +110,12 @@ contract GeomeanOracle is BaseHook {
);
}

function beforeModifyPosition(address, PoolKey calldata key, IPoolManager.ModifyPositionParams calldata params)
external
override
poolManagerOnly
returns (bytes4)
{
function beforeModifyPosition(
address,
PoolKey calldata key,
IPoolManager.ModifyPositionParams calldata params,
bytes calldata
) external override poolManagerOnly returns (bytes4) {
if (params.liquidityDelta < 0) revert OraclePoolMustLockLiquidity();
int24 maxTickSpacing = poolManager.MAX_TICK_SPACING();
if (
Expand All @@ -126,7 +126,7 @@ contract GeomeanOracle is BaseHook {
return GeomeanOracle.beforeModifyPosition.selector;
}

function beforeSwap(address, PoolKey calldata key, IPoolManager.SwapParams calldata)
function beforeSwap(address, PoolKey calldata key, IPoolManager.SwapParams calldata, bytes calldata)
external
override
poolManagerOnly
Expand Down
Loading

0 comments on commit fbe8376

Please sign in to comment.