Fraxfinance: TWAMM Order Cancellation and Expiry Limits
Last updated
Fraxfinance lets Fraxswap order owners cancel active TWAMM orders and recover unsold input plus unclaimed output tokens. On an unpaused pair, cancellation must execute before the order’s expiry. It stops future selling and returns both balances in the same transaction, while preserving trades that already executed.
Unsold input and unclaimed output
A partially executed TWAMM order holds unsold input tokens and a claim on output that its trades have purchased. TWAMM, or time-weighted average market maker, spreads Fraxswap’s sales over time against an automated liquidity pool. The unsold balance comes back in the input token. Unclaimed proceeds arrive in the output token, excluding proceeds that the owner previously withdrew. These amounts have different denominations, so adding their raw quantities does not measure a refund percentage or trading profit.
Who can cancel a Fraxswap TWAMM order?
Only the order’s recorded owner can cancel it through the pair contract. Fraxswap records the caller of its long-term order creation function as the order owner. A wallet that manages an owning smart contract does not automatically become the pair’s recognized caller. Cancellation must reach the pair through that owning contract. The order ID belongs to a particular pair, so the pair address and network identify the relevant record. The call also requires a positive unsold balance or positive unclaimed proceeds. Connecting a wallet changes none of these checks.
Expiry timestamps and settlement timing
Cancellation eligibility follows the TWAMM accounting timestamp, which normally advances to the execution block’s timestamp before cancellation. On an unpaused pair, the order’s expiry must be strictly later than that timestamp. Signing or broadcasting before expiry does not reserve cancellation rights, because a pending transaction can reach the contract too late. Equality with the expiry timestamp also fails the cancellation check.
Fraxswap’s pair contract aligns long-term order expiries to 3600-second intervals. This alignment sets the scheduled endpoint; it does not require a separate transaction every hour. The stored expiration timestamp gives the relevant deadline. Creation can occur between interval boundaries, so the duration need not equal whole hours measured from creation.
Virtual-order execution updates accumulated trades before the cancellation calculation on an unpaused pair. That update can increase purchased output and reduce unsold input compared with an earlier display. A stale preview therefore cannot promise the amount that the transaction will return.
The pair’s plain proceeds view can also lag behind virtual execution. On an unpaused pair, its updating proceeds function advances accounting before returning a proceeds amount. An integration that reads old accounting can show an incomplete output balance. This distinction concerns the displayed amount’s freshness; it does not create an additional mandatory withdrawal transaction.
A true newSwapsPaused flag skips virtual-order execution in Fraxswap’s pause-capable pair contract. Cancellation and proceeds withdrawal remain callable, subject to their ownership, amount, and accounting checks. Those calls use the last settled TWAMM timestamp, which can lag the current block timestamp. On a paused pair, cancellation can succeed after wall-clock expiry if expiry still exceeds the last settled TWAMM timestamp and the other checks pass.
Cancellation from order lookup to settlement
For an owned, active order on an unpaused pair, cancellation follows one transaction after the order record establishes eligibility. Preparation and later inspection surround that transaction. Virtual settlement, removal from future selling, and token transfers happen inside the call.
| Stage | Action | Relevant record or change | Timing or completion condition |
|---|---|---|---|
| Locate the order | Match its network, pair, and order ID. | Recorded owner, token addresses, and expiry. | Before preparing cancellation. |
| Confirm eligibility | Establish ownership and an active order. | The recorded owner must call the pair. | Eligibility must still hold when execution occurs. |
| Submit cancellation |
Call cancelLongTermSwap(orderId) through the owner.
|
A transaction targeting the relevant pair. | A submitted transaction does not establish success. |
| Settle elapsed trades | The pair advances virtual execution when needed. | Updated TWAMM balances and proceeds. | Through the execution block timestamp on an unpaused pair. |
| Remove future selling | The contract removes the order’s sale rate. | The order stops participating in future sales. | Expiry must exceed the settled TWAMM timestamp. |
| Return order balances | The pair transfers unclaimed output, then unsold input. | Both calculated transfers go to the calling owner. | Required transfers must succeed within the same transaction. |
| Confirm completed cancellation | Inspect the receipt, cancellation event, and order record. | Matching transfers and the order’s completion flag. | Successful execution establishes the completed cancellation. |
If the transaction reaches an unpaused pair at or after expiry, the cancellation call reverts. Proceeds withdrawal handles an expired order with a positive unclaimed output balance. That path collects the completed trade’s proceeds; it cannot restore input that the TWAMM already sold.
Completion requires a successful receipt and the cancellation event for the matching pair and order ID. The CancelLongTermOrder event identifies both token addresses and the calculated amounts. Token transfer records and the order’s completion flag establish the corresponding settlement. A pending hash or failed receipt does not establish cancellation.
Does withdrawing proceeds stop a TWAMM order?
Withdrawing positive proceeds from an ongoing TWAMM order leaves its sale rate and expiry unchanged. The withdrawal transfers available output and advances the accounting baseline for future proceeds. It leaves the input awaiting sale in the order. A later cancellation returns the remaining input plus output earned since that withdrawal. Previously withdrawn proceeds do not become claimable again.
Proceeds withdrawal also handles expired orders when a positive unclaimed output balance remains. For an ongoing order, it suits the narrower task of collecting acquired tokens while scheduled selling continues. Cancellation stops that selling. The distinction rests on what happens to the remaining input, even though both operations can transfer the output token.
Replacement orders and the limits of cancellation
Changing the remaining selling schedule requires canceling the active order and creating a replacement because the pair does not edit an existing order’s terms. A paused pair blocks new long-term orders, including replacements. A replacement establishes its own deposited amount, sale rate, and expiry. Its trades encounter the pool conditions that apply during their execution. The former order’s purchase price does not become a promised price for the replacement.
Network gas pays for cancellation’s computation, including any virtual-order catch-up and token transfers. Swap fees and pool prices have already affected output from earlier trades. The pair’s cancellation function adds no separate cancellation-fee calculation and accepts no minimum-output argument. An integration can impose additional conditions, so its behavior must remain distinct from the pair function.
Cancellation can leave a mix of input and output assets when the order has executed only partly. Converting either balance again creates another trade with its own pricing and costs. Stablecoin redemption and loan repayment remain outside the pair’s cancellation function.
Fraxfinance FAQs
-
Can a Fraxswap TWAMM cancellation send funds to a different wallet?
- The pair’s cancellation function sends its calculated balances to the calling order owner and has no recipient parameter. A different wallet cannot redirect those transfers by submitting the order ID. If a smart contract owns the order, that contract receives the tokens. Any onward transfer depends on the owning contract’s functionality.
-
Does canceling a TWAMM order revoke its token allowance?
- Canceling a TWAMM order does not revoke the token allowance that authorized its deposit. Cancellation transfers tokens out of the pair and does not change the owner’s approval record. An allowance controls future spending by the approved contract. Its remaining value belongs to the token’s allowance accounting, separately from the canceled order.
-
How does token rounding affect the unsold amount returned by cancellation?
- Fraxswap calculates the unsold balance with integer arithmetic, so rounding can affect the returned base units. The calculation combines remaining execution time with the stored, scaled sale rate. That rate derives from the original deposit and duration. Token decimals convert the resulting base-unit amount into the readable balance that a wallet displays.
-
What happens if a token transfer fails during TWAMM cancellation?
- The pair reverts cancellation if a required token transfer fails. Its completion flag, order accounting, and earlier transfers within that call revert with it. An included transaction can still consume gas when the cancellation call reverts. Token transfer restrictions can therefore prevent settlement even when ownership and timing are correct.
-
Will canceling one TWAMM order stop my other orders?
- Canceling one TWAMM order stops that order without canceling the owner’s other orders. The pair removes only the selected order’s sale rate from the pool of orders selling the same token. Separate orders retain their own rates and expiries. Pool prices can still change, so preserving a schedule does not freeze future execution prices.
-
Are TWAMM cancellation event amounts always the tokens received?
- A cancellation event reports the amounts that the pair instructs the token contracts to transfer. It does not independently measure the owner’s balance increase. If a token deducts a transfer fee, the credited amount can be lower. The event’s calculated amount and the wallet’s actual receipt then describe different quantities.