Skip to main content
The contract refuses bad fills — but a refusal costs gas and reads as a failure. An interface must perform every check below so the user does not sign a transaction that was already known to revert.

Market identity first

Treat (chainId, swapperAddress, orderId) as the order identity. Every market starts its own ids at 1, so orderId alone collides across books. Switching the UI market must replace the proxy, base token, feed, deployment block and lens together, clear any selected order and reset form input. Persist one of jpyc-usdt, idrx-usdt, or idrp-usdt and support direct links with ?market=. Read token decimals and symbols on-chain; never reuse JPYC’s 18-decimal assumption for IDRX (2) or IDRP (6).
A UI that rounds differently quotes a number the chain will not honour. Mirror every quote path with the same Ceil/Floor choices as the contract, and still confirm displayed quotes against previewFill before building a transaction.
Past sellRemaining the fill clamps anyway, so a larger figure on screen states a payment that will not happen. Cap the field instead of showing a number the settlement will contradict.
sellAmountOut is the argument, so pinning it to sellRemaining lands on the remainder exactly. Buffering the payment instead only lands near it and leaves dust in the order.
A pegged fill may cost anything up to the ceiling. Comparing the balance to the quote lets a taker whose balance sits between the two approve and sign a fill that reverts on transferFrom — gas spent on a failure the ticket could see coming. For a fixed order the quote is the exposure, because it cannot move.
It is their exposure, so it is their number. Offer explicit choices such as 0.1% / 0.5% / 1% and feed the selected value into maxAmountIn.
An order that lapses while the transaction is in flight reverts on arrival. Warn rather than block — the window is the taker’s to judge.
EnumerableSet swap-and-pop means an order cancelled between two page reads slides backwards into a page you already passed and is never seen. Read count, id pages and order data at a single block number.
Hide a below-floor PEG order on a best-offer route, or mark it PAUSED in a full order book; either way, prevent submission and explain that it resumes when the oracle recovers. When a size is below the minimum, show take the minimum and take it all with their real payment amounts instead of a neutral error alone.

Reading the book

Quoting a fill

Approve maxAmountIn, not amountIn. An ordinary oracle tick between approving and filling would otherwise leave the allowance a few wei short.