> ## Documentation Index
> Fetch the complete documentation index at: https://docs.eco.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Cross-chain treasury rebalancing

> Apply a treasury balance policy to Routes API transfers and track each rebalance to delivery.

A treasury rebalancer compares balances across chains and requests a transfer when your policy calls for one. The Routes API supplies the quote and funding transaction; your application owns the policy, scheduling, wallet authorization, and accounting.

## Prerequisites

* A working [USDC transfer integration](/cookbook/send-usdc-cross-chain)
* 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.

```typescript theme={null}
interface RebalancePolicy {
  threshold: bigint;
  minTransfer: bigint;
  maxTransfer: bigint;
  sourceReserve: bigint;
}

function rebalanceAmount(
  sourceBalance: bigint,
  destinationBalance: bigint,
  policy: RebalancePolicy,
): bigint | null {
  const difference = sourceBalance - destinationBalance;
  if (difference <= 0n || difference < policy.threshold) return null;
  const available = sourceBalance > policy.sourceReserve
    ? sourceBalance - policy.sourceReserve
    : 0n;
  const amount = [difference / 2n, available, policy.maxTransfer]
    .reduce((smallest, value) => value < smallest ? value : smallest);
  return amount > 0n && amount >= policy.minTransfer ? amount : null;
}
```

Validate the policy when you load it: amounts must be nonnegative, and `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 an `exact-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](/get-started/integrate-routes-api) 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.

## Next steps

* [Intent status reference](/api-reference/v1/intent-status)
* [Errors and retries](/api-reference/errors)
