Skip to content

feat: classify swaps via function selector matching#218

Closed
premiumjibles wants to merge 2 commits intomainfrom
sa-besp/improve-swap-classification
Closed

feat: classify swaps via function selector matching#218
premiumjibles wants to merge 2 commits intomainfrom
sa-besp/improve-swap-classification

Conversation

@premiumjibles
Copy link
Contributor

Summary

  • Add KNOWN_SWAP_SELECTORS set (~25 selectors covering Uniswap V2/V3, Universal Router, 1inch, 0x, CowSwap, Paraswap, THORChain) as a secondary classification signal when token transfers are empty
  • Fix null safety for selector-matched swaps (tokenTransfers!tokenTransfers ?? [])
  • Update enrichment guard to process swap-typed txs that lack token data, so they still get enriched from known transaction records

Test plan

  • Swap selector with no tokenTransfers → type swap, tokenTransfers []
  • Token-transfer classification takes priority over selector
  • Unknown selector → still contract
  • Short inputData (< 10 chars) → no crash, falls through
  • Case-insensitive selector matching
  • Selector-matched swap with empty tokenTransfers + known tx → gets enriched
  • Swap with existing tokenTransfers + known tx → preserves original data
  • All 842 tests pass

🤖 Generated with Claude Code

Swaps were misclassified as "Contract interaction" when Unchained
returned empty tokenTransfers. Add known DEX function selector matching
as a secondary classification signal, fix null safety for selector-
matched swaps, and update enrichment guard to process swap-typed txs
that lack token data.

Co-Authored-By: Claude Opus 4.6 (1M context) <[email protected]>
@vercel
Copy link

vercel bot commented Mar 19, 2026

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
shapeshift-agentic Ready Ready Preview, Comment Mar 19, 2026 2:35am

Request Review

@coderabbitai
Copy link

coderabbitai bot commented Mar 19, 2026

Important

Review skipped

Draft detected.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: daa0f77b-a72c-4388-a0f0-d4ecfb2d5230

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch sa-besp/improve-swap-classification
📝 Coding Plan
  • Generate coding plan for human review comments

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

…d tests

- Add self-send guard to selector check for consistency with contract check
- Add comment acknowledging multi-purpose selectors (Universal Router, THORChain)
- Add comment explaining enrichment guard intent
- Add test for self-send with swap selector (should not match)
- Add test for send with no tokenTransfers + matching known tx (should enrich)

Co-Authored-By: Claude Opus 4.6 (1M context) <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant