Skip to content

feat(solana): populate transaction_type on lifecycle events - #401

Open
Battambang wants to merge 2 commits into
mainfrom
feat/solana-non-evm-transaction-type-lifecycle-events
Open

Battambang wants to merge 2 commits into
mainfrom
feat/solana-non-evm-transaction-type-lifecycle-events

Conversation

@Battambang

Copy link
Copy Markdown
Contributor

Explanation

Stacked on #393. Transaction lifecycle events emitted by the Solana snap could not be attributed to a flow: the payload carried origin but no classification, so an in-app send, a card token approval, and a dApp transaction were indistinguishable.

This adopts the optional transaction_type property that #393 introduces in @metamask/snap-networks-utils, following the same pattern as the Bitcoin and Tron changes.

resolveTransactionType (new, src/core/utils/transactionType.ts) classifies a transaction before broadcast. A Solana transaction is only a raw unsigned message at that point, so it is not inferred from its instructions. The classification uses the @metamask/keyring-api TransactionType vocabulary:

Case transaction_type
MetaMask origin (metamask), including the unified send flow send
Card token approval token:approve
dApp transaction unknown

A caller-supplied classification wins over the origin. The card approval needs that override: it is also MetaMask-originated, so the origin rule alone would report it as send.

Call sites

  • ConfirmationHandler resolves the type once and carries it on the scheduled Transaction Added, Transaction Approved, and Transaction Rejected events, so all three agree.
  • The cron handlers validate transactionType and forward it. They do not classify again.
  • WalletService.signAndSendTransaction reports the type on Transaction Submitted. ClientRequestHandler passes token:approve for the card approval.
  • Transaction Finalized is unchanged. SignatureMonitor already reports the type taken from the on-chain transaction.

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

@Battambang
Battambang requested a review from a team as a code owner October 1, 2026 12:17
Base automatically changed from feat/non-evm-transaction-type-lifecycle-events to main October 1, 2026 14:09
Report send for MetaMask-originated transactions, token:approve for card
approvals, and unknown for dApp transactions until they are classified
from on-chain data.
@Battambang
Battambang force-pushed the feat/solana-non-evm-transaction-type-lifecycle-events branch from 929ccea to 005e610 Compare October 1, 2026 14:15
@sonarqubecloud

sonarqubecloud Bot commented Oct 1, 2026

Copy link
Copy Markdown

}

return origin === METAMASK_ORIGIN
? TransactionType.Send

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

wouldn't this mark a metamask-originated swap as Send?

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.

Yes for this first design, the resolver treats every metamask originated request as a send on this snap. The unified send is the only Metamask flow that is actually a send; a swap or bridge goes through the same signAndSendTransaction path with no type, so it would be reported as send.
As snaps are not equals in the send* method called with alternative paths, so for thus where an emitted event cannot distinct a send flow/swap, a following improvement will follow by passing the type in the snap caller.
Also this current one will allow supporting to distinct Dapp events flows with further updates.

@Battambang

Copy link
Copy Markdown
Contributor Author

@metamaskbot publish-preview

@github-actions

github-actions Bot commented Oct 1, 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-005e610
@metamask-previews/snap-networks-utils@1.0.0-preview-005e610
@metamask-previews/solana-wallet-snap@7.0.0-preview-005e610
@metamask-previews/stellar-wallet-snap@1.1.0-preview-005e610
@metamask-previews/tron-wallet-snap@4.0.0-preview-005e610

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.

Copilot review overview

🟢 Approval recommended

All reviewed changes have no unresolved blocking issues.

Review effort: Lite
Findings: None

What changed in this PR

Adds Solana transaction classification to lifecycle analytics events.

Changes:

  • Resolves transaction types with origin-based defaults and caller overrides.
  • Propagates classifications through confirmation, cron, submission, and card approval flows.
  • Adds tests and changelog documentation.
File Description
packages/​solana-wallet-snap/​src/​core/​utils/​transactionType.ts Resolves transaction classifications.
packages/​solana-wallet-snap/​src/​core/​utils/​transactionType.test.ts Tests classification behavior.
packages/​solana-wallet-snap/​src/​core/​services/​wallet/​WalletService.ts Reports submitted transaction types.
packages/​solana-wallet-snap/​src/​core/​services/​wallet/​WalletService.test.ts Tests submitted classifications.
packages/​solana-wallet-snap/​src/​core/​services/​confirmation/​ConfirmationHandler.ts Adds types to confirmation lifecycle events.
packages/​solana-wallet-snap/​src/​core/​services/​confirmation/​ConfirmationHandler.test.ts Tests confirmation classifications.
packages/​solana-wallet-snap/​src/​core/​handlers/​onCronjob/​backgroundEvents/​onTransactionRejected.ts Validates and forwards transaction types.
packages/​solana-wallet-snap/​src/​core/​handlers/​onCronjob/​backgroundEvents/​onTransactionBackgroundEvents.test.ts Tests background event forwarding.
packages/​solana-wallet-snap/​src/​core/​handlers/​onCronjob/​backgroundEvents/​onTransactionApproved.ts Validates and forwards transaction types.
packages/​solana-wallet-snap/​src/​core/​handlers/​onCronjob/​backgroundEvents/​onTransactionAdded.ts Validates and forwards transaction types.
packages/​solana-wallet-snap/​src/​core/​handlers/​onClientRequest/​ClientRequestHandler.ts Classifies card approvals.
packages/​solana-wallet-snap/​src/​core/​handlers/​onClientRequest/​ClientRequestHandler.test.ts Tests card approval propagation.
packages/​solana-wallet-snap/​CHANGELOG.md Documents the analytics change.

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

@Battambang
Battambang requested a review from Julink-eth October 1, 2026 20:03

This branch has not been deployed

No deployments
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