Skip to content

feat(tron): classify swap, bridge, and send transactions in analytics - #434

Merged
Battambang merged 4 commits into
mainfrom
feat/tron-flow-classification-analytics
Oct 12, 2026
Merged

Battambang merged 4 commits into
mainfrom
feat/tron-flow-classification-analytics

Conversation

@Battambang

Copy link
Copy Markdown
Contributor

Explanation

Current state

The Tron Snap reports transaction_type on its transaction lifecycle analytics events, but the value is derived only from the raw Tron contract type. Every TriggerSmartContract — which covers unified swap, unified bridge, and TRC20 token sends — therefore reports unknown. As a result the three non-EVM user flows (unified swap/bridge, unified send, dApp send) cannot be told apart from the Snap payload alone.

Solution

Add resolveTransactionType, which classifies a transaction in two ways:

  • When the unified swap/bridge flow passes options.sourceAssetId and options.destAssetId, their CAIP-2 chains are compared: a cross-chain pair reports bridgeSend, a same-chain pair reports swap. This mirrors the Stellar Snap.
  • Otherwise (unified send, dApp transactions) it falls back to the contract type and, for smart-contract calls, the function selector: TRC20 transfer (0xa9059cbb) reports send, TRC20 approve (0x095ea7b3) reports tokenApprove, and anything else stays unknown.

The optional sourceAssetId/destAssetId fields are added to the signAndSendTransaction options struct, and the resolver is used at all three emission sites (client request, keyring sign, and unified send). The classification is resolved at submit time and already carried through the TrackTransaction background event, so Transaction Finalized reports the same value.

Non-obvious points

  • The new options are optional, so existing callers keep validating; the Snap is backward compatible with clients that do not send asset ids yet.
  • This also fixes a latent gap: a unified TRC20 send previously reported unknown and now reports send.
  • The core bridge-status-controller only starts sending the asset ids for Tron trades after this Snap ships, so this change must land first.

References

  • Related to the Non-EVM flow analytics work for Tron, Solana, Bitcoin, and Stellar.

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

@Battambang
Battambang force-pushed the feat/tron-flow-classification-analytics branch from 3d867df to aa682db Compare October 9, 2026 14:41
@Battambang
Battambang requested a balanced review from Copilot October 9, 2026 14:48

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Changes recommended

The unified TRC20 send path lacks a service-level regression test, and the changelog omits part of the shipped behavior.

2 open findings
What changed in this PR

Adds Tron analytics classification for swaps, bridges, TRC20 sends, and approvals.

Changes:

  • Adds transaction classification using asset chains and TRC20 selectors.
  • Propagates classifications through submission, confirmation, and finalization events.
  • Extends request validation and analytics tests.
File Description
packages/​tron-wallet-snap/​src/​utils/​transactionType.ts Adds transaction-type resolution.
packages/​tron-wallet-snap/​src/​utils/​transactionType.test.ts Tests resolver classifications.
packages/​tron-wallet-snap/​src/​services/​send/​SendService.ts Classifies unified sends.
packages/​tron-wallet-snap/​src/​services/​confirmation/​ConfirmationHandler.ts Classifies keyring transactions.
packages/​tron-wallet-snap/​src/​services/​confirmation/​ConfirmationHandler.test.ts Tests dApp classifications.
packages/​tron-wallet-snap/​src/​handlers/​cronjob/​cronjob.test.tsx Tests finalized classification propagation.
packages/​tron-wallet-snap/​src/​handlers/​clientRequest/​validation.ts Accepts optional asset IDs.
packages/​tron-wallet-snap/​src/​handlers/​clientRequest/​clientRequest.ts Classifies swaps and bridges.
packages/​tron-wallet-snap/​src/​handlers/​clientRequest/​clientRequest.test.ts Tests submission classifications.
packages/​tron-wallet-snap/​CHANGELOG.md Documents analytics changes.

🧠 Review effort: Balanced


💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment thread packages/tron-wallet-snap/src/services/send/SendService.ts
Comment thread packages/tron-wallet-snap/CHANGELOG.md Outdated
@Battambang
Battambang force-pushed the feat/tron-flow-classification-analytics branch 2 times, most recently from c78d685 to f85e565 Compare October 9, 2026 15:11
@Battambang
Battambang requested a balanced review from Copilot October 9, 2026 15:17
@Battambang

Copy link
Copy Markdown
Contributor Author

@metamaskbot publish-preview

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟢 Approval recommended

The classification logic is consistent across analytics paths and is covered by focused tests.

0 open findings

2 resolved since last review

🧠 Review effort: Balanced

@github-actions

github-actions Bot commented Oct 9, 2026

Copy link
Copy Markdown
Contributor

Preview builds have been published. Learn how to use preview builds in other projects.

Expand for full list of packages and versions.
@metamask-previews/bitcoin-wallet-snap@3.1.0-preview-f85e565
@metamask-previews/snap-networks-utils@1.0.0-preview-f85e565
@metamask-previews/solana-wallet-snap@7.0.0-preview-f85e565
@metamask-previews/stellar-wallet-snap@1.1.1-preview-f85e565
@metamask-previews/tron-wallet-snap@4.0.0-preview-f85e565

@Battambang
Battambang marked this pull request as ready for review October 9, 2026 15:26
@Battambang
Battambang requested review from a team as code owners October 9, 2026 15:26
@Battambang
Battambang deployed to default-branch October 9, 2026 15:26 — with GitHub Actions Active
@Battambang
Battambang force-pushed the feat/tron-flow-classification-analytics branch from e065093 to 62e7473 Compare October 12, 2026 09:16
Add resolveTransactionType, which classifies a transaction from the
unified swap/bridge sourceAssetId/destAssetId options (cross-chain ->
bridgeSend, same-chain -> swap) and otherwise falls back to the contract
type and TRC20 call selector (transfer -> send, approve -> tokenApprove).

Accept the optional sourceAssetId/destAssetId on signAndSendTransaction
and use the resolver at the client request, keyring sign, and unified
send emission sites so the classification is carried from submit through
Transaction Finalized. This also fixes TRC20 sends, which previously
reported unknown.
@Battambang
Battambang force-pushed the feat/tron-flow-classification-analytics branch from 62e7473 to 0bc67e1 Compare October 12, 2026 09:21
@Battambang
Battambang requested a balanced review from Copilot October 12, 2026 09:22

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟢 Approval recommended

The classification logic is consistently integrated and comprehensively tested across all analytics paths.

0 open findings

🧠 Review effort: Balanced

@Battambang

Copy link
Copy Markdown
Contributor Author

@metamaskbot publish-preview

@github-actions

Copy link
Copy Markdown
Contributor

Preview builds have been published. Learn how to use preview builds in other projects.

Expand for full list of packages and versions.
@metamask-previews/bitcoin-wallet-snap@3.1.0-preview-0bc67e1
@metamask-previews/snap-networks-utils@1.0.0-preview-0bc67e1
@metamask-previews/solana-wallet-snap@7.0.0-preview-0bc67e1
@metamask-previews/stellar-wallet-snap@1.1.1-preview-0bc67e1
@metamask-previews/tron-wallet-snap@4.0.0-preview-0bc67e1

return undefined;
}

return callData.slice(0, 8).toLowerCase();

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are we sure the callData does not come with a 0x prefix ? Because if it does we won't get the right data selector, maybe we could strip it first to make sure ?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Battambang
Battambang requested a review from Julink-eth October 12, 2026 12:10
@Battambang

Copy link
Copy Markdown
Contributor Author

@metamaskbot publish-preview

@sonarqubecloud

Copy link
Copy Markdown

@github-actions

Copy link
Copy Markdown
Contributor

Preview builds have been published. Learn how to use preview builds in other projects.

Expand for full list of packages and versions.
@metamask-previews/bitcoin-wallet-snap@3.1.0-preview-d52c8001
@metamask-previews/snap-networks-utils@1.0.0-preview-d52c8001
@metamask-previews/solana-wallet-snap@7.0.0-preview-d52c8001
@metamask-previews/stellar-wallet-snap@1.1.1-preview-d52c8001
@metamask-previews/tron-wallet-snap@4.0.0-preview-d52c8001

@Battambang
Battambang added this pull request to the merge queue Oct 12, 2026
Merged via the queue into main with commit 47158da Oct 12, 2026
56 checks passed
@Battambang
Battambang deleted the feat/tron-flow-classification-analytics branch October 12, 2026 12:17
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