Skip to main content

03 - Template Cookbook

A collection of template examples by lane. For detailed rules, see docs/reference/compiler/plan-compilation.md.

If you select a preset on the dashboard’s Templates page (/routes), you do not need to write JSON by hand:
  1. Click the lane card you want in the Presets grid at the bottom of the Templates page
  2. In Customize, change only the core fields such as asset, exchange, and network
  3. Check the result in Graph Preview and JSON Preview
  4. Register it with the Register Template button
Currently available presets: CEX Transfer, CCTP Bridge, Gateway Transfer, Multi-hop (CEX->CEX->Chain->Gateway)
For a custom template that is not covered by a preset, use the JSON examples below and register it directly through the API.

Register Directly Through the API

Template Structure at a Glance

Required node fields: node_key, node_kind, action_type, executor_selector, has_side_effect Required edge fields: from, to, edge_type (usually "on_success")

1. CEX 3-Node (Upbit -> Bybit XRP)

The simplest shape: withdrawal -> withdrawal observe -> deposit observe.
Key points:
  • completion_assurance: "destination_credited" -> the terminal node is cex_deposit_status (the destination_provider_observe family)
  • match_mode is required on the terminal node
  • risk_controls is free-form and only max_amount binds (fail-closed at dispatch). The asset_allowlist in every template below is descriptive — hash-pinned, but not enforced. See the v3 endpoints reference

2. CCTP 5-Node (Base Sepolia -> Arbitrum Sepolia)

Cross-chain USDC transfer via CCTP. Requires a signer.
Key points:
  • Put the signer address in destination_caller (you can confirm it through signer health)
  • signer_selector: {"chain_family": "evm"} -> matches the active signer registry row
  • confirmations_required is required on the terminal node
  • Environment variables: MG_EVM_RPC_ENDPOINTS_JSON, MG_LOCAL_SIGNER_*

3. Gateway 3-Node (Base Sepolia -> Arbitrum Sepolia)

Immediate cross-chain transfer through the Gateway unified balance.
Key points:
  • Gateway is faster than CCTP (no attestation polling; burn intent signature -> immediate mint)
  • Contract addresses differ by network - check Circle’s official docs
  • Environment variables: MG_GATEWAY_API_BASE_URL, MG_EVM_RPC_ENDPOINTS_JSON, MG_LOCAL_SIGNER_*

4. Multi-Hop 9-Node (Upbit -> Binance -> Base -> Gateway)

A composite CEX-to-CEX-to-chain-to-Gateway route. $ref: dynamically references output from earlier nodes.

Why multi-hop

  • Upbit does not support direct withdrawals to Base (only routes such as Tron/ERC-20 are available)
  • Route through Binance for the Base withdrawal, then deposit into Gateway

Graph Structure

$ref: Usage Points

Template JSON

Runtime Data Flow

How $ref: resolves during movement execution:
If the target key for $ref: does not exist, the node immediately becomes FAILED (error_code: CONFIG_REF_UNRESOLVED).

$ref: Rules Summary


Common Pitfalls

Full compilation behavior: docs/reference/compiler/plan-compilation.md

Next: 04-going-live.md - prepare for production deployment