What you’ll build
Step 1: Index settlement activity
FxEscrow’s events record each trade’s lifecycle:TradeRecorded, TakerFunded, MakerDelegateFunded, and TradeStatusChanged. They carry the trade ID and the parties, but not the currencies or amounts. The money moves as ordinary ERC-20 Transfer events into and out of FxEscrow. The pipeline below captures both and writes them to two ClickHouse tables that you join on transaction_hash.
FxEscrow addresses (from Arc’s contract addresses):
stablefx-settlements.yaml
arc_testnet to arc_mainnet and use the mainnet FxEscrow address, in lowercase, in both filters.
The ABI covers the four events FxEscrow emits during a trade. The decoder drops any event that isn’t in it, so add new events to the ABI if Circle adds them. Amounts are raw token units. Divide by the token’s
decimals(): USDC and EURC use 6.Step 2: Analyze FX flows
With trade events and token movements in your warehouse, flows per currency are SQL:TakerFunded or MakerDelegateFunded event for that trade:
trade_id. Maintain live per-token totals with the PostgreSQL aggregate sink.
Step 3: Publish an FX rate oracle
Other contracts and apps need an FX rate. A scheduled Compose task reads the rate your desk computes from these flows and publishes it onchain, the same mechanism as the NAV oracle, pointed at an FX pair.src/tasks/publish-fx-rate.ts
Step 4: Monitor exposure and enforce limits
FX desks live and die by position limits. Because you have every funding and payout, net exposure per currency is a running sum, and a Compose task can watch it and act (alert, hedge, or halt quoting) when a limit is breached. Compose’s durable execution guarantees the control fires, and every decision is traced for the desk’s risk review. This is a live version of the circuit-breaker pattern.Business outcomes
- Every settlement is data: funding and payout flows per currency and corridor, not a dealer’s end-of-day summary.
- Multi-currency treasury: real-time positions across USD, EUR, and regional stablecoins in one warehouse.
- A rate you can publish and defend: an onchain FX oracle sourced from actual settlements, with an audit trail.
- Automated limit enforcement: exposure breaches trigger controls in seconds.
Resources
- Circle StableFX
- StableFX technical guide
- Arc contract addresses
- Build a multi-chain NAV oracle
- ClickHouse sink