Two-hop swap (advanced)
Goal: swap A → USDC → B in one orchestration flow — read the intermediate token balance on-chain, then patch hop 2 so the second leg uses the real amount (not a stale RPC quote).
Pattern
- Unconditional templates for each venue hop (builder owns pool accounts / ix bytes).
ifx_let — read hop-1 output (e.g. SPL token amount / account data slice).
- Math / cast on the Frame tape if needed (
asU64, etc.).
- Patched CPI — Structured for official SPL/System fields; RawPatched for DEX layouts (
data_offset + $N).
- Optional
ifx_if_else — skip / revert when balance too low.
Prefer Structured CPI when the registry covers the ix; use Raw for DEX / custom layouts (raw CPI patches).
Reference example
Venue demos (integrator-owned, outside the core SDK):
Verify in Explorer
After you build a tx, paste the wire into Explorer. For RawPatched steps, the instruction detail shows a byte patch map (offset → $N) under the text decode.
Related