Skip to content

Commit

Permalink
feat: enable hooks to return deltas to influence pool behavior
Browse files Browse the repository at this point in the history
  • Loading branch information
chefburger committed May 15, 2024
1 parent 8c19261 commit ea853f2
Show file tree
Hide file tree
Showing 119 changed files with 424 additions and 486 deletions.
1 change: 0 additions & 1 deletion .forge-snapshots/BinHookTest#testBurnSucceedsWithHook.snap

This file was deleted.

This file was deleted.

This file was deleted.

1 change: 0 additions & 1 deletion .forge-snapshots/BinHookTest#testMintSucceedsWithHook.snap

This file was deleted.

1 change: 0 additions & 1 deletion .forge-snapshots/BinHookTest#testSwapSucceedsWithHook.snap

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

1 change: 0 additions & 1 deletion .forge-snapshots/BinPoolManagerTest#testGasBurnOneBin.snap

This file was deleted.

1 change: 0 additions & 1 deletion .forge-snapshots/BinPoolManagerTest#testGasDonate.snap

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

1 change: 0 additions & 1 deletion .forge-snapshots/BinPoolManagerTest#testNoOpGas_Burn.snap

This file was deleted.

This file was deleted.

This file was deleted.

1 change: 0 additions & 1 deletion .forge-snapshots/BinPoolManagerTest#testNoOpGas_Mint.snap

This file was deleted.

1 change: 0 additions & 1 deletion .forge-snapshots/BinPoolManagerTest#testNoOpGas_Swap.snap

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

1 change: 0 additions & 1 deletion .forge-snapshots/CLPoolManagerTest#donateBothTokens.snap

This file was deleted.

1 change: 0 additions & 1 deletion .forge-snapshots/CLPoolManagerTest#gasDonateOneToken.snap

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

1 change: 0 additions & 1 deletion .forge-snapshots/CLPoolManagerTest#swap_simple.snap

This file was deleted.

This file was deleted.

1 change: 0 additions & 1 deletion .forge-snapshots/CLPoolManagerTest#swap_withHooks.snap

This file was deleted.

1 change: 0 additions & 1 deletion .forge-snapshots/CLPoolManagerTest#swap_withNative.snap

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

1 change: 0 additions & 1 deletion .forge-snapshots/CLPoolManagerTest#testNoOp_gas_Swap.snap

This file was deleted.

This file was deleted.

1 change: 0 additions & 1 deletion .forge-snapshots/CLPositionTest#Position_update_add.snap

This file was deleted.

This file was deleted.

1 change: 0 additions & 1 deletion .forge-snapshots/ExtsloadTest#extsload.snap

This file was deleted.

1 change: 0 additions & 1 deletion .forge-snapshots/ExtsloadTest#extsloadInBatch.snap

This file was deleted.

1 change: 0 additions & 1 deletion .forge-snapshots/LiquidityMathTest#addDeltaNegtive.snap

This file was deleted.

1 change: 0 additions & 1 deletion .forge-snapshots/LiquidityMathTest#addDeltaPositive.snap

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

1 change: 0 additions & 1 deletion .forge-snapshots/TickTest#checkTicks.snap

This file was deleted.

1 change: 0 additions & 1 deletion .forge-snapshots/TickTest#getFeeGrowthInside.snap

This file was deleted.

This file was deleted.

1 change: 0 additions & 1 deletion .forge-snapshots/TickTest#update.snap

This file was deleted.

1 change: 0 additions & 1 deletion .forge-snapshots/VaultTest#Vault.snap

This file was deleted.

1 change: 0 additions & 1 deletion .forge-snapshots/VaultTest#collectFee.snap

This file was deleted.

This file was deleted.

1 change: 0 additions & 1 deletion .forge-snapshots/VaultTest#lockSettledWhenFlashloan.snap

This file was deleted.

This file was deleted.

1 change: 0 additions & 1 deletion .forge-snapshots/VaultTest#lockSettledWhenSwap.snap

This file was deleted.

1 change: 0 additions & 1 deletion .forge-snapshots/VaultTest#registerPoolManager.snap

This file was deleted.

1 change: 0 additions & 1 deletion .forge-snapshots/VaultTest#testLock_NoOp.snap

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

19 changes: 10 additions & 9 deletions src/libraries/Hooks.sol
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,13 @@ library Hooks {

bytes4 constant NO_OP_SELECTOR = bytes4(keccak256(abi.encodePacked("NoOp")));

/// @notice Hook has no-op defined, but lacking before* call
error NoOpHookMissingBeforeCall();
/// @notice Hook permissions contain conflict
/// 1. has no-op defined, but lacking before* call
/// 2. has before swap returns delta, but lacking beforeSwap call
/// 3. has after swap returns delta, but lacking afterSwap call
/// 4. has add liquidity returns delta, but lacking add liquidity call
/// 5. has remove liquidity returns delta, but lacking remove liquidity call
error HookPermissionsValidationError();

/// @notice Hook config validation failed
/// 1. either registration bitmap mismatch
Expand All @@ -27,6 +32,9 @@ library Hooks {
/// @notice Hook did not return its selector
error InvalidHookResponse();

/// @notice Hook delta exceeds swap amount
error HookDeltaExceedsSwapAmount();

/// @notice Utility function intended to be used in pool initialization to ensure
/// the hook contract's hooks registration bitmap match the configration in the pool key
function validateHookConfig(PoolKey memory poolKey) internal view {
Expand Down Expand Up @@ -56,11 +64,4 @@ library Hooks {
function shouldCall(bytes32 parameters, uint8 offset, IHooks hook) internal view returns (bool) {
return hasOffsetEnabled(parameters, offset) && address(hook) != msg.sender;
}

/// @dev Verify hook return value matches no-op when these 2 conditions are met
/// 1) Hook have permission for no-op
/// 2) Return value is no-op selector
function isValidNoOpCall(bytes32 parameters, uint8 noOpOffset, bytes4 selector) internal pure returns (bool) {
return hasOffsetEnabled(parameters, noOpOffset) && selector == NO_OP_SELECTOR;
}
}
Loading

0 comments on commit ea853f2

Please sign in to comment.