Skip to content

Conversation

@AugmentedMode
Copy link
Contributor

@AugmentedMode AugmentedMode commented Sep 16, 2025

Explanation

This PR integrates the bulk token screening functionality from the PhishingController into the TransactionController's transaction simulation workflow. When a transaction simulation completes with received tokens, those tokens are scanned in a fire and forget method.

Changes introduced

  • Added #bulkScanReceivedTokens method that scans tokens received during transaction simulation
  • Added PhishingController:bulkScanTokens to the TransactionController's allowed actions
  • Integrated token screening into the #afterSimulate workflow as a fire and forget
  • Filters received tokens from simulation data and passes them to PhishingController for bulk screening

Screenshot showcasing the tokenScanCache is implemented as expected

This is grabbed via the extension console using await stateHooks.getPersistedState() after triggering a swap in uniswap. You will notice i was doing a swap for USDC which is the only token address stored in the cache.

Screenshot 2025-09-15 at 10 28 15 AM

References

Checklist

  • I've updated the test suite for new or updated code as appropriate
  • I've updated documentation (JSDoc, Markdown, etc.) for new or updated code as appropriate
  • I've communicated my changes to consumers by updating changelogs for packages I've changed, highlighting breaking changes as necessary
  • I've prepared draft pull requests for clients and consumer packages to resolve any breaking changes

…se resultType instead of isMalicious and metadata
…_ENDPOINT and update related comments for clarity
AugmentedMode added a commit that referenced this pull request Sep 22, 2025
#6483)

## Explanation

This PR extends the **PhishingController** to support bulk token
screening with caching, similar to the existing URL scanning
functionality. This PR also replaces the `urlScanCache` with a reusable
`cacheManager` class that is shared between both `urlScanCache` and now
`tokenScanCache`

**Changes introduced**  
- Added a new `bulkScanTokens` method that can screen up to 100 tokens
per batch
- Implemented a new `cacheManager` class that handles caching logic with
a 15-minute TTL.
  - Replaced `urlScanCache` with `cacheManager`.  
- Introduced `tokenScanCache` using the same `cacheManager` for
consistency and reuse.
- Defined cache key format as `${chainId}:${tokenAddress}` for token
scans.
- Registered `bulkScanTokens` as a controller action under
`PhishingControllerBulkScanTokensAction`.
- Exported new types for extension consumption and exposed the scanning
functionality via the messenger.

Screenshot showcasing the `tokenScanCache` is implemented as expected 

This is grabbed via the extension console using await
stateHooks.getPersistedState() after triggering a swap in uniswap. You
will notice i was doing a swap for USDC which is the only token address
stored in the cache.

<img width="548" height="250" alt="Screenshot 2025-09-15 at 10 28 15 AM"
src="https://github.com/user-attachments/assets/8b465d07-b4a4-4d55-890e-543d5600931b"
/>



<!--
Thanks for your contribution! Take a moment to answer these questions so
that reviewers have the information they need to properly understand
your changes:

* What is the current state of things and why does it need to change?
* What is the solution your changes offer and how does it work?
* Are there any changes whose purpose might not obvious to those
unfamiliar with the domain?
* If your primary goal was to update one package but you found you had
to update another one along the way, why did you do so?
* If you had to upgrade a dependency, why did you do so?
-->

## References

<!--
Are there any issues that this pull request is tied to?
Are there other links that reviewers should consult to understand these
changes better?
Are there client or consumer pull requests to adopt any breaking
changes?

For example:

* Fixes #12345
* Related to #67890
-->

## Checklist

- [ ] I've updated the test suite for new or updated code as appropriate
- [ ] I've updated documentation (JSDoc, Markdown, etc.) for new or
updated code as appropriate
- [ ] I've communicated my changes to consumers by [updating changelogs
for packages I've
changed](https://github.com/MetaMask/core/tree/main/docs/contributing.md#updating-changelogs),
highlighting breaking changes as necessary
- [ ] I've prepared draft pull requests for clients and consumer
packages to resolve any breaking changes
Base automatically changed from feat/add-bulk-token-screening to main September 22, 2025 19:02
cursor[bot]

This comment was marked as outdated.

cursor[bot]

This comment was marked as outdated.

cursor[bot]

This comment was marked as outdated.

@AugmentedMode AugmentedMode enabled auto-merge (squash) September 24, 2025 18:07
@AugmentedMode AugmentedMode merged commit 9b71a82 into main Sep 24, 2025
239 checks passed
@AugmentedMode AugmentedMode deleted the feat/add-token-screening-tx-controller branch September 24, 2025 18:14
@AugmentedMode AugmentedMode mentioned this pull request Sep 24, 2025
4 tasks
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.

3 participants