Canonical post lives at https://agentbadge.xyz/blog/arc-c57-peach-dex - full text mirrored below for the dev.to audience.
Short answer: an AI agent that holds a budget in USDC should be
able to get funded in whatever the customer has - say EURC. So we
spiked the full path on Arc testnet: quote through the Peach Arc
Aggregator, swap EURC->USDC, deposit into a real BudgetVault, kill
the process mid-transaction, and make it prove it cannot resend
money. The swap itself took an afternoon. Making it safe under
crashes, retries and a second auditor took the rest of the week -
and the most interesting bugs we found were not in our code. They
were in the vendor's API.
This is part of the Arc campaign series. Previous episode: we shipped a
settlement layer for agents paying agents
(EPIC-227 - what decides when the money may move). This article is EPIC-254: plugging
an external DEX aggregator into our agent's funding path, without
trusting it.
The problem: "convert currency" is three problems wearing a trenchcoat
For a junior: our BudgetVault is a USDC piggy bank for AI agents -
it streams funds on a schedule, with a payee allowlist and per-tx
caps. Customers in Europe hold EURC. So the agent needs a conversion
step before the vault sees a cent.
That sounds like one API call. It is actually three separate
problems:
- The swap - easy part. Ask the aggregator for a quote, sign a transaction, collect USDC.
- The crash - hard part. Your process can die at any point between "I signed a transaction" and "I saw its receipt". A naive retry broadcasts the same intent twice. A naive "it failed, resend" pays twice. The only safe answer is a journal that knows exactly what was already signed and sent.
- The vendor - sneaky part. The SDK you depend on returns routers, quotes and flags. If any of them lie or drift shape, your checklist has to notice before the signature, not after the loss.
We proved all three live on Arc testnet (chain 5042002), in public,
with transactions anyone can verify on the explorer.
What actually shipped
The happy path, end to end. 5 EURC in, quote fetched, the router
verified against what the API advertises, intent + txHash + raw signed
bytes written to the journal in one atomic write, then - and only
then - broadcast. The swap returned 9.709 USDC, provenance-verified
against actual token movements (not just the receipt status), and the
full amount was deposited into the vault, which flipped to DEPOSITED
and started streaming. Three full cycles, all on-chain:
- swap
0x4e2669ae…2339006/ deposit0xa91b386f…dbc7b51 - swap
0x6d6a830f…df1355/ deposit0x04c485a9…85beb3 - swap
0x758710f6…f36b60/ deposit0xf29c17cc…c76651
The crash drill, for real this time. Not a mock - we killed the
process after the swap was broadcast, restarted, and ran resume.
It read the journal, found the signed intent, located the transaction
on-chain under its same hash, adopted it, and finished the deposit.
Zero resends. Then we did it again after all the audit fixes landed,
on the hardened code, and it still worked.
"Never sent" means provably never sent. This is the part most
retry logic gets wrong. An RPC timeout, a dropped connection, a
misleading error name - none of that proves a transaction died. Our
journal only marks an intent never-sent after a block-body proof:
binary-search the signer's nonce across archive blocks, read the
block where the nonce moved, and require the consuming transaction to
be physically present. Until that proof exists, the intent is
unknown - and unknown blocks the run, it does not guess.
The escape hatch is a loaded gun with a safety. If a transaction
is genuinely stuck, an operator can abandon the intent - but only
after two probes at least a block apart confirm it is not in any
mempool or block, and then the next signature is nonce-pinned so
two transactions can never fight over the same slot.
Seven rounds of review - and where the bugs actually were
We ran the same playbook as the settlement layer: adversarial audit
rounds in Arc Studio until converged, then a second reviewer on the
final tree. Six rounds went BLOCK -> FAIL x4 -> PASS (0 Critical /
0 High). The honest detail: several of the late-round findings were
bugs inside the previous round's fix - remediation is attack
surface, and it earns its keep.
Then Randy - the Peach-side reviewer - did something better than a
code read. He verified our transactions on-chain and sent back a
re-check with one High and three Mediums, all reproduced:
- High: we signed calldata we never decoded. The aggregator API builds the transaction; we were trusting its shape. If the layout ever shifts - a router upgrade, a different path count - we would happily sign a transaction sending money somewhere else. Now the pre-sign checklist pins the
0x02fcde22layout word by word: chainId, router, signer, tokenIn/Out, amountIn, amountOutMin, expectedOut, deadline, path echo. One word moves, we refuse to sign. - Medium: a lock race that reproduced 11/25 double-holders. Two processes could both believe they owned the journal lock. Fixed with an atomic rename - Randy literally reproduced the race and counted.
- Medium: a resume wedge on
dead:"reverted"entries, and an ABORTED state with no reclaim path for transactions that mined anyway. Both fixed; the post-fix drill re-ran live.
Plus a fresh independent checklist run by a different model family
(Nemotron 3.5 Lightning): PASS.
bun test scripts/lib/: 80 pass, 0 fail.
The twist: the vendor's API was the bug report
Here is the part worth reading twice. While auditing our handling
of their API, we found real issues on the Peach/Arc side:
1. Two routers, one advertisement. getStatus() proudly reports
the execution router 0x5FF5…0607. But the V2 swapAllowance()
endpoint returns a different router, 0xfcf781…0663 - an address
the status endpoint does not mention at all. Both are ERC1967 upgrade
proxies with different implementations. Our checklist aborted on
the mismatch (that is what it is for). Is 0xfcf781… legitimate?
We asked. If a checklist treats the API's own self-report as truth,
this is exactly the class of thing that becomes an incident.
2. quote_ts is in milliseconds. The field looks like seconds.
A naive age = now - quote_ts in seconds makes an expired quote look
fresh forever - we only caught it because a negative test fed a
stale quote and watched the deadline check wave it through. Units are
a security boundary.
3. deviation_ratio just isn't there. Testnet quotes for
EURC->USDC omit the field entirely. An earlier version of our code
silently treated missing as 0 - which is how "the API didn't say"
becomes "the API said zero". Now missing means unknown, and unknown
fails closed.
4. Arc's USDC is also the gas token. Gas is charged on the USDC
address itself and a second Transfer event fires on
0xffff…fffe at 18 decimals. Any verifier that diffs USDC Transfer
logs naively misreads every transaction. We subtract
gasUsed x effectiveGasPrice explicitly.
5. Testnet prices are synthetic and drifting. Our five executed
5-EURC swaps returned 15.514, 13.484, 11.829, 10.460, 9.709 USDC -
declining, consistent with our own price impact on a thin pool.
Nothing on testnet should ever be quoted as a price. On mainnet, the
read-only sweep says EURC->USDC sits at ~1.097 across 5-500 EURC,
median quote latency 799 ms.
What's honest vs what's pending
Verified and reproducible:
- The full EURC->USDC->vault path works live, three times.
- Crash recovery adopts the same hash; zero resends, proven twice.
- 80 tests, the audit trail, the on-chain receipts -
bun scripts/verify-evidence.mtsre-checks the four cited transactions against the chain itself.
Still open:
- Peach's answers on the V2 router,
quote_tsunits, the missingdeviation_ratio, whether the0x02fcde22layout is stable across router upgrades, and cirBTC on testnet. - A second model-family verifier (Luna) never ran - our org's weekly quota ran out. It's on the record as an open residual, not swept.
- ~18 USDC residue in the signer wallet from an early swap that mined after its pre-journaling run aborted. Reported, not hidden.
Decision: CONDITIONAL GO. The pipeline works and the engine is
protected. Production depends on the vendor answering five questions
and us confirming the calldata layout stays pinned.
Why this matters beyond one swap
The generic lesson is not "DEX aggregators work on Arc". It is that
plugging a third-party financial API into an autonomous agent is an
audit problem, not an integration problem. The API's self-reported
status lied by omission (the router). Its types lied by unit (the
timestamp). Its schema lied by absence (the ratio). None of that is
malice - it is just what production APIs do. The only defence is a
checklist that treats the vendor as an untrusted input, a journal
that treats every crash as survivable, and reviewers who verify on
the chain instead of believing the code.
Full evidence pack - transcripts, sweep JSON, audit findings, the
letter we sent the Peach team - is in the repo under
spike-evidence/ on branch spike/epic-254-peach.
Built on Arc. Testnet 5042002, mainnet 5042 (read-only). No
contracts harmed in the making of this spike.





