← All posts

An exit that refuses to run at the wrong price

A close that only executes if the price is inside a window you signed. Outside it, the transaction reverts rather than selling your position into a spike.

Security3 min readDeFiLoops

In short: you set up a plan to close a liquidity position later, and you worry it will close at a bad price because the market moved in the meantime. You can sign a price window with the plan, and the close runs only if the price is inside that window when it lands; outside it, the transaction fails and nothing is closed or sold. It guards against normal price moves between signing and running, not against someone pushing the pool price on purpose, and a window set too narrow may never let the close run.

A plan written now might run in 10 minutes or next week. The price moves in between, and a close that executes regardless will occasionally execute at the worst moment available. One operation checks the price first and refuses to run if it has moved too far.

The window

You give it two numbers: a tick at the centre of an acceptable window, and a half-width in ticks. The position closes only if the current tick sits inside that band. Outside it, the transaction reverts.

The centre
A tick, which is a price. Zero is a range around the current price at the time of signing
The half-width
How far either way is acceptable, in ticks. Sixty ticks is a different width in every fee tier, because spacing differs
Outside the band
The whole transaction reverts. Nothing is closed, nothing is sold, and nothing is half-done

Both numbers are signed as part of the plan. They are in what you approved, and the chain enforces them; we do not hold them on our side and look them up at run time.

What it does and does not defend against

This part is easy to oversell.

The window is read from the pool’s spot tick: where the price is at the instant the transaction executes. So it defends against the thing that happens most: the market having moved between the moment you signed and the moment the transaction lands.

It is not a defence against someone manipulating the pool. A party who can push the price out of your window can equally push it into one, and spot-tick checks of this shape have a known history of being gamed (there are public audit findings against exactly this pattern elsewhere in the ecosystem). Treat it as a check that your signature still matches the market. It will not stop an adversary.

Why a revert is the right failure

A close that fails is an inconvenience. A close that succeeds at a price you would never have chosen is a loss you cannot undo.

Reverting costs you the network fee and leaves your position exactly as it was, which is a position you already own and understand. When the alternative can’t be undone, the cheaper failure is the one to pick.

Where it earns its keep

  • Scheduled exits. A plan that fires on a clock has no idea what the market is doing when it wakes up. The window is how you say “not if it looks like this”.
  • Price-triggered plans. A trigger fires on a price; by the time the transaction is mined the price can be somewhere else. The window closes the gap between the trigger and the fill.
  • Anything unattended. Automation runs when nobody is watching, and that is when an unconditional close is most dangerous.