mirror of
https://github.com/luxfi/dex.git
synced 2026-09-24 00:26:31 +00:00
The arriving-trader path: bring value across from C and place an order with it in one D transition. The semantics look wrong until you see the failure they prevent. The tempting design makes the pair atomic in the strong sense, so a trader never ends up funded without the order they wanted. That strands people. A deadline can expire in transit — C accepts the export at t, D imports at t+d, and an order whose deadline fell in between is dead on arrival through nobody's fault. Failing as a unit leaves the value in the in-flight state with its only consuming transaction permanently invalid, and the trader has to be rescued by hand. So the import is unconditional and the order is best effort. Order failure is DATA, not transaction failure: expired deadline, bad signature, consumed nonce, wrong asset, insufficient balance all come back as a Rejected Result carrying a Reason, with the value sitting available on D — a state the trader can act on alone, by placing another order or exporting home. The one real failure is an inadmissible claim. That is not an order problem; there is nothing to land, so it is an error rather than a Result. Two details that follow. A rejected order does not burn the nonce — the trader never used it, and an unordered nonce is a position they chose; a test re-signs with the same nonce afterwards and it works. And Cancel derives its refund from the lots it actually retired, never from a caller-supplied amount, which is how a cancel comes to refund more than the order ever committed; with three of ten lots committed to a match, cancelling refunds seven and leaves the three held. 83 tests, including the full arriving-trader round trip: import and place, partially trade, cancel the remainder, export home — one boundary crossing in, one out, everything between it purely local. Co-authored-by: Hanzo Dev <[email protected]>