Skip to content

fix(sushi): report executed swap when Route event is missing from receipt - #1401

Open
SashaMIT wants to merge 1 commit into
coinbase:mainfrom
SashaMIT:fix/sushi-missing-route-event
Open

fix(sushi): report executed swap when Route event is missing from receipt#1401
SashaMIT wants to merge 1 commit into
coinbase:mainfrom
SashaMIT:fix/sushi-missing-route-event

Conversation

@SashaMIT

@SashaMIT SashaMIT commented Aug 5, 2026

Copy link
Copy Markdown

Summary

In `sushiRouterActionProvider.swap`, after a successful on-chain swap the action decodes the RouteProcessor9 `Route` event to report actual amounts:

```ts
const [routeLog] = swapReceipt.logs.filter(...).map(decodeEventLog);
return `Swapped ${formatUnits(routeLog.args.amountIn, ...)} ...`
```

If the receipt contains no `Route` event — e.g. the fill was routed via a different executor, or a wallet provider returns receipts without logs — `routeLog` is `undefined`, `routeLog.args` throws, and the outer `catch` returns `Error swapping tokens: TypeError ...`.

The swap executed on-chain, but the agent is told it failed. Agent frameworks respond to that by retrying the action, executing a second, unintended swap (double-spend).

Fix

  • Guard the decode: `(swapReceipt.logs ?? [])` and an explicit `!routeLog` branch.
  • The branch reports the swap as executed, includes the tx hash/link and the quoted `AmountOut`, and explicitly tells the agent not to retry automatically.

No change to the happy path (Route event present) — same message as before.

Test plan

  • New jest case: receipt `status: "success"` with `logs: []` → result contains `Swap executed`, the tx hash, and the no-retry note; does not contain `Error`
  • Full `sushiRouterActionProvider.test.ts` suite passes (16/16)

Related: #1392 (x402 allowlist), #1393 (jupiter slippage cap), #1394 (zeroX Permit2 binding) — same agent-funds safety theme, distinct defect.

Made with Cursor

When the swap transaction succeeds on-chain but the receipt contains no
RouteProcessor9 Route event (e.g. fills routed via a different executor,
or a wallet provider returning receipts without logs), the action threw
while decoding routeLog.args and returned a generic "Error swapping
tokens" message — even though the swap had executed.

Agent frameworks treat that as a failure and retry, executing a second,
unintended swap (double-spend).

Guard the decode: if no Route event is present, report the swap as
executed with the tx hash, the quoted AmountOut, and an explicit
instruction not to retry automatically.

Co-authored-by: Cursor <cursoragent@cursor.com>
@SashaMIT
SashaMIT requested a review from murrlincoln as a code owner August 5, 2026 15:04
@cb-heimdall

Copy link
Copy Markdown

🟡 Heimdall Review Status

Requirement Status More Info
Reviews 🟡 0/1
Denominator calculation
Show calculation
1 if user is bot 0
1 if user is external 0
2 if repo is sensitive 0
From .codeflow.yml 1
Additional review requirements
Show calculation
Max 0
0
From CODEOWNERS 0
Global minimum 0
Max 1
1
1 if commit is unverified 1
Sum 2

@github-actions github-actions Bot added action provider New action provider typescript labels Aug 5, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Development

Successfully merging this pull request may close these issues.

2 participants