feat: track token_security_type_destination in Unified SwapBridge metrics#8595
Open
infiniteflower wants to merge 10 commits intomainfrom
Open
feat: track token_security_type_destination in Unified SwapBridge metrics#8595infiniteflower wants to merge 10 commits intomainfrom
infiniteflower wants to merge 10 commits intomainfrom
Conversation
4 tasks
…tyTypeDestination
…for enhanced transaction tracking
micaelae
reviewed
Apr 27, 2026
micaelae
reviewed
Apr 27, 2026
micaelae
approved these changes
Apr 27, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Explanation
Adds a new
token_security_type_destinationfield to every Unified SwapBridge analytics event that already carriestoken_address_destination. This lets the product team measure how often users swap into flagged tokens and quantify the impact of the destination-token security badge UI.Current state. Unified SwapBridge events report which token a user is swapping into (
token_address_destination) but not whether the client surfaced any security warning for that token. Without this signal we can't correlate the security badge with user behavior (e.g. drop-off after a "Malicious" classification).Solution. A single string-or-
nullvalue is threaded through the metric pipeline:token_security_type_destinationonce when callingBridgeController.updateBridgeQuoteRequestParams(via thecontextarg).BridgeControllerstores it on state (tokenSecurityTypeDestination: string | null, defaultnull) so all pre-submit events (InputChanged,QuotesRequested,QuotesReceived,QuotesError,QuotesValidationFailed, etc.) automatically include it viagetRequestParams.BridgeStatusController.submitTx/submitIntent. The value is persisted onto theBridgeHistoryItemso post-submit events fired hours later (Submitted,Completed,Failed,PollingStatusUpdated,StatusValidationFailed) can read it back viagetRequestParamFromHistorywithout depending onBridgeControllerstate, which may have moved on by then.Non-obvious choices.
string | null, notstring | undefined.BridgeControllerStatemust satisfy@metamask/base-controller'sStateConstraint, whose values areJson-compatible — andJsondoes not allowundefined.nullalso matches the existing convention inRequestParams(e.g.token_address_destination: CaipAssetType | null). The controller defensively coercesundefined → nullat theupdateBridgeQuoteRequestParamsboundary so JS callers passingundefineddon't end up with"token_security_type_destination": undefinedkeys getting dropped byJSON.stringify.BridgeHistoryItem. Persisting unconditionally would have broken everyMockTxHistorysnapshot. The history item uses...(tokenSecurityTypeDestination !== undefined && { tokenSecurityTypeDestination })(matches the existingabTests/activeAbTestspattern); metric output is normalized with?? nullat emit time.StatusValidationFailedneeds an explicit add. Most post-confirm events spreadrequestParamProperties, butStatusValidationFailedbuilds its payload with explicitPicks. The new field had to be added in two places:getRequestParamFromHistoryAND the explicit pick in#trackUnifiedSwapBridgeEvent.submitTxinstead of reading fromBridgeControllerstate at submit time? Considered but rejected. Reading state would require wideningbridge-status-controller's messengerAllowedActionswithBridgeController:getState(a heavy permission) plus client wiring updates. The explicit-arg approach matches the existing pattern for every other analytics context piece onsubmitTx(abTests,activeAbTests,location,quotesReceivedContext) and keeps the cross-controller surface narrow.Screen.Recording.2026-04-27.at.4.30.49.PM.mov
References
Checklist
Note
Medium Risk
Medium risk due to breaking metrics type/signature changes (
RequestParams,getRequestParams, andupdateBridgeQuoteRequestParamscontext) and new optional parameters onBridgeStatusControllersubmission methods that downstream clients must wire correctly to keep analytics consistent.Overview
Adds a new
token_security_type_destinationanalytics property and threads it through the Unified SwapBridge metrics pipeline.BridgeControllernow stores a client-provided destination-token security classification (tokenSecurityTypeDestination) fromupdateBridgeQuoteRequestParamscontext, resets it withresetState, and includes it in all pre-submit tracked events via a breakinggetRequestParams(quoteRequest, tokenSecurityTypeDestination)API.BridgeStatusControlleraccepts an optionaltokenSecurityTypeDestinationonsubmitTx/submitIntent, persists it onBridgeHistoryItem, and emits it on post-submit status/completion/failure analytics. Tests and snapshots are updated across both packages, and changelogs document the breaking changes.Reviewed by Cursor Bugbot for commit 71fe3dc. Bugbot is set up for automated code reviews on this repo. Configure here.