-
Notifications
You must be signed in to change notification settings - Fork 5.4k
feat: Adding code to capture metrics for dapp swaps #36885
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
base: main
Are you sure you want to change the base?
Conversation
CLA Signature Action: All authors have signed the CLA. You may need to manually re-run the blocking PR check if it doesn't pass in a few minutes. |
ui/pages/confirmations/components/confirm/info/hooks/useUniswapShieldInfo.ts
Outdated
Show resolved
Hide resolved
ui/pages/confirmations/components/confirm/info/hooks/useUniswapShieldInfo.ts
Outdated
Show resolved
Hide resolved
ui/pages/confirmations/components/confirm/info/hooks/useUniswapShieldInfo.ts
Outdated
Show resolved
Hide resolved
ui/pages/confirmations/components/confirm/info/hooks/useUniswapShieldInfo.ts
Outdated
Show resolved
Hide resolved
✨ Files requiring CODEOWNER review ✨✅ @MetaMask/confirmations (10 files, +888 -18)
|
ui/pages/confirmations/components/confirm/info/hooks/useUniswapShieldInfo.ts
Outdated
Show resolved
Hide resolved
return; | ||
} | ||
|
||
const commands = parsedTransactionData.args.commands as string; |
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.
However we extract the necessary data, should all the Uniswap logic remain encapsulated in app/scripts/lib/transaction/decode/uniswap.ts
?
Maybe with a new getUniswapSwapData
function?
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.
This is not standard parsing of abi data and will not be re-used I think. Additionally putting data in uniswap.ts
will then need for a controller action to be called from the client.
ui/pages/confirmations/components/confirm/info/hooks/useDappSwapComparisonInfo.ts
Outdated
Show resolved
Hide resolved
ui/pages/confirmations/components/confirm/info/hooks/useUniswapShieldInfo.ts
Outdated
Show resolved
Hide resolved
quotes[selectedQuoteIndex].quote.minDestTokenAmount, | ||
10, | ||
) | ||
.minus(new Numeric(amountMin, 10)) |
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.
Is it best we provide slippage
in our requests to fetchQuotes
to be explicit?
Maybe we could control via feature flag?
As that will influence our minimums.
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.
@bschorchit : do you have a suggestion for slippage
amount ?
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.
If we don't pass a slippage, does it uses the our swaps defaults?
I believe they will be in a better position to define the ideal slippage than us as ideal slippage varies based on the token pair being swapped.
A feature flag for this doesn't seem ideal as we would have to accomodate logic for specific token pairs there as well.
ui/pages/confirmations/components/confirm/info/hooks/useUniswapShieldInfo.ts
Outdated
Show resolved
Hide resolved
ui/pages/confirmations/components/confirm/info/hooks/useUniswapShieldInfo.ts
Outdated
Show resolved
Hide resolved
percentage_change_in_token_amount: percentageChangeInTokenAmount, | ||
percentage_change_in_token_min_amount: | ||
percentageChangeInTokenMinAmount, | ||
percentage_change_in_gas: percentageChangeInGas, |
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.
Are percentages sufficient for the metrics?
If we got loads of positive results, of higher increases, they may only amount to pennies, so should we also calculate fiat values for the total gas, amount changes, and total difference?
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.
@bschorchit : can you please detail what all field will be useful in metrics.
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.
We should get the usd values instead of percentages. We can calculate percentages later within Mixpanel.
Note: these should be usd values, not user preferred fiat values.
Properties proposed are the following:
swap_dapp_from_token_simulated_value_usd
- $ usd simulated value for the sending token for the Uniswap swap
swap_dapp_to_token_simulated_value_usd
- $ usd simulated value for the receiving token for the Uniswap swap
swap_dapp_minimum_received_value_usd
- $ usd minimum value received for the receiving token for the Uniswap swap
swap_dapp_network_fee_usd
- $ usd value for the total cost of that transaction. If it's a batch transaction that includes approve transactions, those should accounted too as part of the network fee.
swap_mm_from_token_simulated_value_usd
- $ usd simulated value for the sending token for the MM swap
swap_mm_to_token_simulated_value_usd
- $ usd simulated value for the receiving token for the MM swap
swap_mm_minimum_received_value_usd
- $ usd minimum value received for the receiving token for the MM swap
swap_mm_network_fee
- $ usd value for the total cost of that transaction. It should account for the approve transaction as well, if applicable and possible.
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.
PR is updated
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.
📊 Page Load Benchmark ResultsCurrent Commit: 📄 Localhost MetaMask Test DappSamples: 100 Summary
📈 Detailed Results
Results generated automatically by MetaMask CI |
Builds ready [c50cf29]
UI Startup Metrics (1137 ± 83 ms)
Bundle size diffs [🚨 Warning! Bundle size has increased!]
|
this.controllerMessenger, | ||
`${BRIDGE_CONTROLLER_NAME}:${BridgeBackgroundAction.TRACK_METAMETRICS_EVENT}`, | ||
), | ||
[BridgeBackgroundAction.FETCH_QUOTES]: this.controllerMessenger.call.bind( |
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.
Ideally this would go in the bridge-controller-init
file in the api
property.
02c4771
to
c060e20
Compare
📊 Page Load Benchmark ResultsCurrent Commit: 📄 Localhost MetaMask Test DappSamples: 100 Summary
📈 Detailed Results
Results generated automatically by MetaMask CI |
Builds ready [c6e3040]
UI Startup Metrics (1243 ± 75 ms)
Bundle size diffs [🚨 Warning! Bundle size has increased!]
|
} | ||
}); | ||
|
||
return selectedQuoteIndex; |
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.
use use the quote with highest value of minDestTokenAmount
Builds ready [c7f4536]
UI Startup Metrics (1230 ± 74 ms)
Bundle size diffs [🚨 Warning! Bundle size has increased!]
|
📊 Page Load Benchmark ResultsCurrent Commit: 📄 Localhost MetaMask Test DappSamples: 100 Summary
📈 Detailed Results
Results generated automatically by MetaMask CI |
Builds ready [54ce7ff]
UI Startup Metrics (1231 ± 63 ms)
Bundle size diffs [🚨 Warning! Bundle size has increased!]
|
📊 Page Load Benchmark ResultsCurrent Commit: 📄 Localhost MetaMask Test DappSamples: 100 Summary
📈 Detailed Results
Results generated automatically by MetaMask CI |
Builds ready [e8c1115]
UI Startup Metrics (1208 ± 82 ms)
Bundle size diffs [🚨 Warning! Bundle size has increased!]
|
} | ||
const amount = word?.replace(/^0+/u, '') ?? ''; | ||
return addHexPrefix(amount); | ||
}; |
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.
Bug: Hex Conversion Error for Zero Input
The wordToAmount
function returns "0x" when the input word is all zeros. This happens because removing all leading zeros leaves an empty string, which addHexPrefix
converts to "0x". This "0x" value is not a valid hex representation for zero, potentially causing errors in BigNumber calculations or numeric parsing downstream, where "0x0" is expected.
❌ test-e2e-chrome-api-specs failed. View the html report here. |
📊 Page Load Benchmark ResultsCurrent Commit: 📄 Localhost MetaMask Test DappSamples: 100 Summary
📈 Detailed Results
Results generated automatically by MetaMask CI |
Builds ready [7333da1]
UI Startup Metrics (1230 ± 67 ms)
Bundle size diffs [🚨 Warning! Bundle size has increased!]
|
Description
Capturing DAPP Swap metrics
Changelog
CHANGELOG entry:
Related issues
Fixes: https://github.com/MetaMask/MetaMask-planning/issues/5974
Manual testing steps
Screenshots/Recordings
NA
Pre-merge author checklist
Pre-merge reviewer checklist
Note
Adds a Uniswap-origin swap comparison flow that parses tx data, fetches quotes/rates, computes USD metrics, and records them; introduces shared ERC20 decimals util and exposes background quote fetching.
DappSwapComparisonBanner
(no-UI) gated toorigin === "https://app.uniswap.org"
inbase-transaction-info
.useDappSwapComparisonInfo
to parse swap tx data, fetch quotes, compute USD values, and update MetaMetrics (dapp_swap_comparison
props).dapp-swap-comparison-utils
(getDataFromSwap
,getBestQuote
,getTokenValueFromRecord
) with ABI parsing.fetchAllErc20Decimals
to sharedui/pages/confirmations/utils/token.ts
; updateuseBalanceChanges
to use it.FETCH_QUOTES
via controller messenger and addfetchQuotes
Redux action.Written by Cursor Bugbot for commit 7333da1. This will update automatically on new commits. Configure here.