Integration engineering

Build an order state machine for intent-based swaps

Track intent submission, acceptance and settlement as separate states with distinct order and transaction identities.

An intent order can be accepted without being filled, and a fill can be observed before the application's status service catches up. A useful state machine must represent both facts without declaring success too early.

Separate authorization from observation

A proposed application lifecycle includes draft, awaiting signature, signed, submitting, accepted, partially filled and terminal outcome. Add an unknown-submission state for a request whose acknowledgement was lost. Exact provider states differ, so map them rather than assuming they match your internal names.

The PancakeSwap Unified API, for example, distinguishes order submission from a later status lookup keyed by order hash. That order identity should not be replaced by a quote identifier or a settlement transaction hash.

Store evidence with transitions

TransitionEvidence to retain
SignedOrder digest and original account context
AcceptedProvider acknowledgement and order identity
Fill observedFill identifier and settlement reference
TerminalDocumented status plus reconciled settled amounts

Do not let a delayed “open” response overwrite a newer confirmed fill. Track observation time and provider ordering information where available. If evidence conflicts, retain an explicit reconciliation state.

Recover without multiplying orders

After a timeout, look up the known order before creating another signature. A lost HTTP response does not show that submission failed. Repeated orders may authorize multiple independent fills.

Keep lifecycle tracking alive when the wallet disconnects or the review screen closes. These events remove interaction context, not necessarily the order's validity.

Test acknowledgement loss, status lag, duplicate fill notifications and expiry after a partial fill. Each has a different result from a clean rejection before the order was accepted.

Sources & verification (1)

Source-check date is recorded in the article details. URLs are provided for manual verification. Use Copy to keep this page open.

  1. Endpoints

    Quote, calldata, submit and status contracts

    https://developer.pancakeswap.finance/contracts/unified-swap-api/endpoints

Continue reading

Cancellation requests need their own confirmation state Account for partial fills without double counting Keep a local ledger of swap attempts and outcomes