Vulnerable Hook Detection
Vulnerable Hook Detection
StopLoss
{
"currency0": "0x0197481B0F5237eF312a78528e79667D8b33Dcff",
"currency1": "0xA56569Bd93dc4b9afCc871e251017dB0543920d4",
"fee": 3000,
"hooks": "0xA3da6f46f93C7B3090A48D7bFeC0345156ED5040",
"tickSpacing": 60,
"deployer":"0x4e59b44847b379578588920cA78FbF26c0B4956C"
}
function afterSwap(
address,
PoolKey calldata key,
IPoolManager.SwapParams calldata params,
BalanceDelta,
bytes calldata
) external override returns (bytes4, int128) {
int24 prevTick = tickLowerLasts[key.toId()];
(, int24 tick,,) = poolManager.getSlot0(key.toId());
int24 currentTick = getTickLower(tick, key.tickSpacing);
tick = prevTick;
int256 swapAmounts;
// fill stop losses in the opposite direction of the swap
// avoids abuse/attack vectors
bool stopLossZeroForOne = !params.zeroForOne;
// TODO: test for off by one because of inequality
if (prevTick < currentTick) {
for (; tick < currentTick;) {
swapAmounts = stopLossPositions[key.toId()][tick][stopLossZeroForOne];
if (swapAmounts > 0) {
fillStopLoss(key, tick, stopLossZeroForOne, swapAmounts);
}
unchecked {
tick += key.tickSpacing;
}
}
} else {
for (; currentTick < tick;) {
swapAmounts = stopLossPositions[key.toId()][tick][stopLossZeroForOne];
if (swapAmounts > 0) {
fillStopLoss(key, tick, stopLossZeroForOne, swapAmounts);
}
unchecked {
tick -= key.tickSpacing;
}
}
}
return (StopLoss.afterSwap.selector, 0);
}
ArrakisHook
Last updated
Was this helpful?