Prerequisites
- A working USDC transfer integration
- Treasury wallets and source-chain RPC access
- A balance source that accounts for transfers already in progress
- Amount limits, gas reserves, and a policy for failed or delayed transfers
Define the balance policy
This example moves half the USDC balance difference when it exceeds your threshold. Both inputs must use the same decimals. It does not fetch balances or submit transactions.maxTransfer must be at least minTransfer. Choose thresholds based on your application’s needs; the example does not prescribe financial policy.
Quote and execute
Request anexact-in quote with the source treasury as source.funder, the destination treasury as destination.recipient, and the policy amount as the base-unit source.amount. Use the token address for each chain, not a shared token address.
Follow the Routes API integration to verify the quote and fund it. Check the quoted output and fees against your policy before submitting. Persist the quote ID, funded intent hash, delivery intent hashes, and funding transaction hash so that the next run can resume tracking.
Schedule without duplicate transfers
Run one active rebalance per policy at a time. Record an in-flight transfer before another scheduler run can authorize the same movement. If a submission times out, inspect its transaction or job status before requesting another transfer. Re-read balances after delivery. A timer alone is not enough: overlapping runs can act on the same balances and transfer twice.Troubleshooting
- If no quote is available, keep the treasury balance unchanged and record the failure for a later policy evaluation.
- If funding succeeds but delivery remains pending, continue tracking that transfer instead of treating the source balance decrease as a completed rebalance.
- If an intent becomes refundable, reconcile the refund transaction before counting the funds as available again.
