fix(sushi): report executed swap when Route event is missing from receipt - #1401
Open
SashaMIT wants to merge 1 commit into
Open
fix(sushi): report executed swap when Route event is missing from receipt#1401SashaMIT wants to merge 1 commit into
SashaMIT wants to merge 1 commit into
Conversation
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>
🟡 Heimdall Review Status
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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
No change to the happy path (Route event present) — same message as before.
Test plan
Related: #1392 (x402 allowlist), #1393 (jupiter slippage cap), #1394 (zeroX Permit2 binding) — same agent-funds safety theme, distinct defect.
Made with Cursor