Repository navigation
feat(bridge-status-controller): pass swap asset ids to Tron, Solana, and Bitcoin snap requests #10775
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Draft
Battambang
wants to merge
10
commits into
main
Choose a base branch
from
feat/tron-flow-classification-analytics
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
feat(bridge-status-controller): pass swap asset ids to Tron, Solana, and Bitcoin snap requests #10775
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
44b7ded
feat(bridge-status-controller): pass swap asset ids to Tron snap requ…
Battambang 1c15fb1
feat(bridge-status-controller): pass swap asset ids to Solana snap re…
Battambang 92368fa
feat(bridge-status-controller): pass swap asset ids to Bitcoin snap r…
Battambang 876ab41
Merge branch 'feat/tron-flow-classification-analytics' into feat/mult…
Battambang cb6b8a4
Merge branch 'feat/solana-flow-classification-analytics' into feat/mu…
Battambang 887625f
Merge branch 'feat/bitcoin-flow-classification-analytics' into feat/m…
Battambang 67548be
refactor(bridge-status-controller): use chain-id guards for snap asse…
Battambang dc886c9
docs(bridge-status-controller): reference the PR in the changelog
Battambang c9cc4be
test(bridge-status-controller): use a same-chain Solana asset id in t…
Battambang 131e5e6
fix(bridge-status-controller): omit swap asset ids from approval snap…
Battambang File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
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
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
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
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -9,8 +9,10 @@ import { | |
| extractTradeData, | ||
| formatChainIdToCaip, | ||
| formatChainIdToHex, | ||
| isBitcoinChainId, | ||
| isCrossChain, | ||
| isStellarTrade, | ||
| isSolanaChainId, | ||
| isStellarChainId, | ||
| isTronTrade, | ||
| } from '@metamask/bridge-controller'; | ||
| import { SnapController } from '@metamask/snaps-controllers'; | ||
|
|
@@ -91,10 +93,11 @@ export const getClientRequest = ( | |
|
|
||
| let options: Record<string, unknown> | undefined; | ||
|
|
||
| // Only Stellar trades expect asset IDs in the request options. Passing them | ||
| // for other non-EVM chains (e.g. Bitcoin) breaks strict snap request | ||
| // validation and prevents the transaction from being broadcast. | ||
| if (isStellarTrade(trade)) { | ||
| if ( | ||
| isStellarChainId(srcChainId) || | ||
| isSolanaChainId(srcChainId) || | ||
| isBitcoinChainId(srcChainId) | ||
| ) { | ||
| if (sourceAssetId !== undefined || destAssetId !== undefined) { | ||
| options = { | ||
| ...(sourceAssetId !== undefined && { | ||
|
|
@@ -108,10 +111,15 @@ export const getClientRequest = ( | |
| } | ||
|
|
||
| if (isTronTrade(trade)) { | ||
| // Tron trades need the visible flag and contract type to be included in the request options | ||
| options = { | ||
| visible: trade.visible, | ||
| type: trade.raw_data?.contract?.[0]?.type, | ||
| ...(sourceAssetId !== undefined && { | ||
| sourceAssetId, | ||
| }), | ||
| ...(destAssetId !== undefined && { | ||
| destAssetId, | ||
| }), | ||
|
Battambang marked this conversation as resolved.
Copilot marked this conversation as resolved.
Comment on lines
+117
to
+122
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
MetaMask/internal-snaps#434: feat(tron): classify swap, bridge, and send transactions in analytics
|
||
| }; | ||
| } | ||
|
|
||
|
|
@@ -254,27 +262,33 @@ export const handleNonEvmTxResponse = ( | |
| * @param trade - The trade data (can be approval or main trade) | ||
| * @param quoteResponse - The quote response containing metadata | ||
| * @param selectedAccount - The account to submit the transaction for | ||
| * @param isApproval - Whether the trade is the approval transaction rather than the main trade | ||
| * @returns The transaction meta | ||
| */ | ||
| export const handleNonEvmTx = async ( | ||
| messenger: BridgeStatusControllerMessenger, | ||
| trade: Trade, | ||
| quoteResponse: QuoteResponseV1<Trade, Trade> & QuoteMetadata, | ||
| selectedAccount: AccountsControllerState['internalAccounts']['accounts'][string], | ||
| isApproval = false, | ||
| ): Promise<TransactionMeta> => { | ||
| if (!selectedAccount.metadata?.snap?.id) { | ||
| throw new Error( | ||
| 'Failed to submit cross-chain swap transaction: undefined snap id', | ||
| ); | ||
| } | ||
|
|
||
| // The quote's asset ids describe the swap/bridge transaction, not the token | ||
| // approval that precedes it. Passing them for the approval would make the snap | ||
| // classify the approval as a swap or a bridge, so they are only attached to | ||
| // the main trade. | ||
| const request = getClientRequest( | ||
| trade, | ||
| quoteResponse.quote.srcChainId, | ||
| selectedAccount.id, | ||
| selectedAccount.metadata?.snap?.id, | ||
| quoteResponse.quote.srcAsset.assetId, | ||
| quoteResponse.quote.destAsset.assetId, | ||
| isApproval ? undefined : quoteResponse.quote.srcAsset.assetId, | ||
| isApproval ? undefined : quoteResponse.quote.destAsset.assetId, | ||
| ); | ||
| const requestResponse = (await messenger.call( | ||
| 'SnapController:handleRequest', | ||
|
|
||
Oops, something went wrong.
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why
srcChainIdinstead oftradeTwo reasons: consistency, and the trade shape does not always tell you the chain.
1. The trade shape is a lossy proxy for the chain
The strategy layer establishes that trade shape maps 1:1 to chain, but note the Stellar case in
strategy/index.ts:A Stellar trade is either a
stringor an{ xdr / xdrBase64 }object. SoisStellarTrade(trade)isfalsefor a string-shaped Stellar trade, and that string is indistinguishable from a Solana trade by shape alone. The chain id is the only reliable signal for Stellar-vs-Solana strings, which is exactly why the original Solana check usedisSolanaChainId(srcChainId)(there is noisSolanaTrade).2. Consistency: one condition, one kind of check
Before, the condition mixed two kinds of check:
getClientRequestalready hassrcChainIdin scope (it derivesscopefrom it on the first line), so using chain guards for all three makes the condition uniform:3. It is also slightly more accurate
isStellarChainIdaccepts both pubnet and testnet (XlmScope.Pubnet/XlmScope.Testnet), whereasisStellarTradeonly reflects the payload shape.Behavior equivalence
isStellarTrade-> trueisStellarChainId-> trueisStellarTrade-> falseisStellarChainId-> trueisSolanaChainId-> trueisSolanaChainId-> trueisBitcoinTrade-> trueisBitcoinChainId-> trueThe only behavioral difference is the string-shaped Stellar case, where the new version is correct and the old one would have silently omitted the asset ids.