Skip to content

fix: evaluated positive or negative balanceDiff to put transactions in from or to - #108

Open
gabrieledm wants to merge 9 commits into
mainfrom
fix/WPN-1223_solana-incorrect-event-logged-for-swap-operation-from-usdc-to-sol
Open

fix: evaluated positive or negative balanceDiff to put transactions in from or to#108
gabrieledm wants to merge 9 commits into
mainfrom
fix/WPN-1223_solana-incorrect-event-logged-for-swap-operation-from-usdc-to-sol

Conversation

@gabrieledm

Copy link
Copy Markdown
Contributor

Explanation

Fixes incorrect transaction direction and type detection when the fee payer receives an amount of SOL that is less than or equal to the transaction fee.
Previously, native transfer direction was determined using the raw pre and post transaction balances.
For a USDC-to-SOL swap, the fee payer’s balance can still decrease when the received SOL is smaller than the fee.
This caused the incoming SOL to be classified as outgoing and could prevent the transaction from being identified as a swap.

The mapper now determines direction from the fee-adjusted balance difference:

  • Positive difference -> outgoing SOL
  • Negative difference -> incoming SOL
  • Zero difference -> fee-only balance change, not a transfer

References

Fixes MetaMask/metamask-extension#43164

Changes

  • Use the fee-adjusted SOL balance difference to determine native transfer direction.
  • Ignore SOL balance decreases caused exclusively by transaction fees.
  • Update the existing swap expectation to reflect the correct native SOL direction.
  • Add tests covering incoming SOL amounts that are:
    • Less than the transaction fee
    • Equal to the transaction fee
    • Greater than the transaction fee
  • Add equivalent coverage for SPL-token-to-native-SOL swaps.
  • Use fresh mapper dependencies in the new parameterized tests to prevent mock state from leaking between cases.

Testing

  • Added native SOL transfer boundary tests around the transaction fee.
  • Added a fee-only transaction test.
  • Added SPL-token-to-SOL swap classification tests for all fee boundary cases.

Before

WPN-1223  Before
WPN-1223.Before.mov

After

WPN-1223  After
WPN-1223.After.mp4

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
  • I've introduced breaking changes in this PR and have prepared draft pull requests for clients and consumer packages to resolve them

@gabrieledm
gabrieledm requested review from a team as code owners August 4, 2026 15:46
@gabrieledm gabrieledm changed the title Fix/wpn 1223 solana incorrect event logged for swap operation from usdc to sol fix: evaluated positive or negative balanceDiff to put transactions in from or to Aug 4, 2026
Base automatically changed from chore/solana-wallet-snap-integrate-packages to main August 4, 2026 16:11
@gabrieledm
gabrieledm force-pushed the fix/WPN-1223_solana-incorrect-event-logged-for-swap-operation-from-usdc-to-sol branch from b8e5575 to 70d0971 Compare August 4, 2026 20:10
ulissesferreira
ulissesferreira previously approved these changes Aug 5, 2026
jeremytsng pushed a commit that referenced this pull request Aug 5, 2026
## Explanation

This PR refactors synchronization so SEP-41 asset metadata is loaded
once per sync run and passed into downstream account/transaction sync
services, and introduces a dedicated cronjob to periodically synchronize
the asset catalog.

<!--
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/processes/updating-changelogs.md)
- [ ] I've introduced [breaking
changes](https://github.com/MetaMask/core/tree/main/docs/processes/breaking-changes.md)
in this PR and have prepared draft pull requests for clients and
consumer packages to resolve them
ulissesferreira
ulissesferreira previously approved these changes Aug 5, 2026
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.

2 participants