Plan the route
planSwap resolves token metadata, requests a route and quote, checks each pool against current chain controls, applies a slippage floor, and fetches the required program imports.
50 basis points means 0.5 percent slippage.
Submit the request
Useswap for one pool and swapMultiHop for a route with two or more pools.
fileBlindedIdentityStore records it before the action returns. If you do not use that store, persist the handle in your own database before leaving the request flow.
Do not submit another request because a confirmation wait timed out. Check the transaction and mapping state first. A second submission can spend another record and create another trade.
Claim the output
The pending output becomes readable after the request finalizes. Both route types useclaimSwapOutput.
amountOut is the received output. amountRemaining is the unused portion of the original input. Wrapped assets are paid out as records of the underlying asset.
For a multi-hop route, each later hop must consume its intermediate input. A partial fill in a later hop rejects the route. Only unused original input can appear as the final refund.
Recover pending claims
Long-running local clients should inspect the configured identity store after startup.getUnclaimedSwaps reads swap_outputs from chain. It returns per-token totals and handles that can be claimed from the store alone. Older records without a complete handle may require reconcileSwapHistory().