fix(stellar-wallet-snap): Fill crosschain swap receive side transaction history info instead of using contract interaction - #255
Conversation
There was a problem hiding this comment.
🟡 Changes recommended
parseContractEventsFromResultMeta contains a confirmed switch fallthrough bug that breaks V3 meta parsing and can cause valid contract events to be dropped.
Once you've addressed the issues Copilot identified, you can request another Copilot review.
Pull request overview
This PR improves @metamask/stellar-wallet-snap transaction history mapping for Soroban invoke-host-function transactions by detecting wallet-credited SAC transfer contract events in result_meta_xdr, allowing these credits (native and classic CODE:ISSUER) to be surfaced as Receive transactions rather than Unknown.
Changes:
- Add generic parsing utilities to walk contract events from Horizon
result_meta_xdrand safely parse SACtransferevents credited to a given account. - Extend
TransactionMapperto map eligible invoke-host-function transactions as receives based on parsed contract events (native + classic assets). - Add fixtures and unit tests covering receive mapping for contract swap credits; update the package changelog.
File summaries
| File | Description |
|---|---|
| packages/stellar-wallet-snap/src/services/transaction/xdrParser.ts | Adds contract-event extraction from result_meta_xdr and a safe SAC transfer parser for receive detection. |
| packages/stellar-wallet-snap/src/services/transaction/xdrParser.test.ts | Adds unit tests for parsing credited SAC transfers from transaction meta. |
| packages/stellar-wallet-snap/src/services/transaction/TransactionMapper.ts | Adds invoke-host-function receive fallback mapping driven by meta contract events. |
| packages/stellar-wallet-snap/src/services/transaction/TransactionMapper.test.ts | Adds mapping coverage for native + USDC contract-swap receive scenarios. |
| packages/stellar-wallet-snap/src/services/transaction/mocks/horizon-transaction-responses.fixtures.ts | Introduces Horizon fixtures containing result_meta_xdr with SAC transfer events. |
| packages/stellar-wallet-snap/CHANGELOG.md | Adds an Unreleased “Fixed” entry describing the improved receive mapping. |
Review details
- Files reviewed: 6/6 changed files
- Comments generated: 2
- Review effort level: Lite
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
| describe('parseContractEventsFromResultMeta', () => { | ||
| it('accumulates native SAC transfers credited to the wallet', () => { | ||
| const results = parseContractEventsFromResultMeta({ |
There was a problem hiding this comment.
we cover it via fixture already
There was a problem hiding this comment.
🟡 Changes recommended
The new XDR parsing introduces multiple unexplained magic-number union discriminants that should be replaced with named switch values/SDK enums to reduce brittleness and improve maintainability.
Once you've addressed the issues Copilot identified, you can request another Copilot review.
Review details
Suppressed comments (2)
packages/stellar-wallet-snap/src/services/transaction/xdrParser.ts:597
- This V4 branch also relies on a numeric meta version (
case 4). For readability/consistency with the rest ofxdrParser.ts(which uses.switch().namechecks), consider using the named discriminant or an SDK enum constant here as well to avoid unexplained magic numbers.
case 4: {
events = meta
.v4()
.operations()
.flatMap((op) => [...op.events()]);
break;
packages/stellar-wallet-snap/src/services/transaction/xdrParser.ts:637
parseTransferContractEventSafechecksbody.switch() !== 0, which is an unexplained magic number. For consistency with the rest of this file (which typically usesswitch().name), consider comparing against the named contract event body type or the SDK enum constant instead of0so it’s obvious which event-body variant is being parsed.
const body = event.body();
if (body.switch() !== 0) {
return null;
}
- Files reviewed: 6/6 changed files
- Comments generated: 1
- Review effort level: Lite
| typeof toAddress !== 'string' || | ||
| typeof token !== 'string' || | ||
| toAddress !== accountAddress | ||
| ) { |
There was a problem hiding this comment.
@Julink-eth we can just add
toAddress !== fromAddress as safe guard to ensure the txn is a receive txn
There was a problem hiding this comment.
Yes I think we should add it after our discussion.
|
@metamaskbot publish-preview |
|
Preview builds have been published. Learn how to use preview builds in other projects. Expand for full list of packages and versions. |
Explanation
This PR improves @metamask/stellar-wallet-snap transaction history mapping for Soroban invoke-host-function transactions by detecting wallet-credited SAC transfer contract events in result_meta_xdr, allowing these credits (native and classic CODE:ISSUER) to be surfaced as Receive transactions rather than Unknown.
Changes:
Video reference:
https://www.loom.com/share/967c2716a3d14cf085c140fdea5376eb
References
Checklist