feat: permissionless cancelExpiredSwap for stuck trading orders#180
Merged
Merged
Conversation
Once a stored swap passes its `order.deadline`, `executeSwap` can never succeed again (it reverts `OrderExpired`), yet the swap and its CashModule solvency hold sit locked until an owner signs `cancelSwap`. This blocks the one-active-order-per-safe slot and leaves the withdrawal hold in place, forcing the user to sign a cancel just to recover. Add `cancelExpiredSwap(address safe)` to both EnsoSwapModule and AcrossSwapModule (covers all trading order types: buy/sell/swap). It takes no signature and can be called by anyone (e.g. the backend keeper) once `block.timestamp > order.deadline`, mirroring `cancelSwap`'s clearing path (`cancelWithdrawalByModule`, or direct delete when `cashModule == 0`). Safe by construction: it can only run after expiry (when execution is already impossible) and merely refunds the safe's own funds back to the safe and clears state — there is no fund-movement authority to abuse. Reverts `OrderNotExpired` at/before the deadline and `NoActiveOrder` when nothing is stored. Adds forge coverage for both modules. Co-authored-by: Cursor <cursoragent@cursor.com>
|
Codex usage limits have been reached for code reviews. Please check with the admins of this repo to increase the limits by adding credits. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Stacked on #124 (
feat/eth-asset-support). Lets the backend keeper clear an expired trading order without a user signature, releasing the stuck CashModule solvency hold and freeing the one-active-order-per-safe slot.cancelExpiredSwap(address safe)to bothEnsoSwapModuleandAcrossSwapModule(covers all trading order types: buy / sell / swap).executeSwap) and gated onblock.timestamp > order.deadline. Once past the deadlineexecuteSwapcan only revertOrderExpired, so the order is already dead — this just cleans it up.cancelSwap's clearing path:cashModule.cancelWithdrawalByModule(safe)on OP, or a directdelete+SwapCancelledwherecashModule == 0(mainnet trading).OrderNotExpirederror for calls at/before the deadline;NoActiveOrderwhen nothing is stored.Why it's safe
requested(executeSwapdeletes it before dispatching), so this can never race a partially-executed/bridged order.Motivation
Today a quote can expire (deadline passes) before the keeper executes — e.g. route slippage moves — leaving the order permanently un-executable. The only recovery was the owner signing
cancelSwap, which blocked the next trade and left the withdrawal hold in place. This gives the BE reaper a signature-less way to release it.