02 · The hooks
Twap guard
A trade fails if the price ends too far from a slow anchor.
Twap guard is a speed limit on price. It is not a moving cap that resets on every swap.
What a trader sees
The anchor starts as the price at initialization. After a swap, the hook looks at the new price. If it is outside a band around the anchor, the swap reverts. Every trade in the window is checked against that same anchor, so a series of small trades cannot walk the price further than one move. When the stride elapses, the anchor becomes the last price that stayed inside the old band. The next window can walk one more band from there. A second trade in that window does not get a second band.
The stride is 20 blocks and the band is tight. One large sell moves the price past the band and reverts. Twenty small sells in those same blocks also fail once they would leave the band, because they share one anchor. After the stride, the anchor moves to the last price that was allowed, and the next window can take one more step.
What you set
- The stride, in blocks. It has to be at least 1.
- The band, in basis points of the anchor sqrt price. 0 means any price change reverts. 10,000 lets the sqrt price double, which is about a four-times move in the token price. It does not switch the guard off.
Anyone can buy the launch token with their own quote and send it to a sink.