Skip to content

Commit dd20380

Browse files
feat: predict deposit account created metric (#22366)
## **Description** Add `polymarket_account_created` property to transaction events if Predict deposit creates Safe proxy. ## **Changelog** CHANGELOG entry: null ## **Related issues** Fixes: [#5944](MetaMask/MetaMask-planning#5944) ## **Manual testing steps** ## **Screenshots/Recordings** ### **Before** ### **After** ## **Pre-merge author checklist** - [x] I’ve followed [MetaMask Contributor Docs](https://github.com/MetaMask/contributor-docs) and [MetaMask Mobile Coding Standards](https://github.com/MetaMask/metamask-mobile/blob/main/.github/guidelines/CODING_GUIDELINES.md). - [x] I've completed the PR template to the best of my ability - [x] I’ve included tests if applicable - [x] I’ve documented my code using [JSDoc](https://jsdoc.app/) format if applicable - [x] I’ve applied the right labels on the PR (see [labeling guidelines](https://github.com/MetaMask/metamask-mobile/blob/main/.github/guidelines/LABELING_GUIDELINES.md)). Not required for external contributors. ## **Pre-merge reviewer checklist** - [ ] I've manually tested the PR (e.g. pull and build branch, run the app, test code being changed). - [ ] I confirm that this PR addresses all acceptance criteria described in the ticket it closes and includes the necessary testing evidence such as recordings and or screenshots. <!-- CURSOR_SUMMARY --> --- > [!NOTE] > Adds `polymarket_account_created` metric to Predict deposit transactions by detecting Safe proxy creation via 4-byte prefix, with accompanying tests. > > - **Metrics**: > - Add `polymarket_account_created` to `getMetaMaskPayProperties` for `predictDeposit` based on nested tx data starting with `0xa1884d2c`. > - Introduce `FOUR_BYTE_SAFE_PROXY_CREATE` constant for detection. > - **Tests**: > - Add tests asserting `polymarket_account_created` is set to `true`/`false` depending on presence of matching nested transaction. > > <sup>Written by [Cursor Bugbot](https://cursor.com/dashboard?tab=bugbot) for commit 0092914. This will update automatically on new commits. Configure [here](https://cursor.com/dashboard?tab=bugbot).</sup> <!-- /CURSOR_SUMMARY -->
1 parent 5ba96c6 commit dd20380

File tree

2 files changed

+40
-13
lines changed

2 files changed

+40
-13
lines changed

app/core/Engine/controllers/transaction-controller/event_properties/metamask-pay.test.ts

Lines changed: 32 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -74,19 +74,6 @@ describe('Metamask Pay Metrics', () => {
7474
});
7575
});
7676

77-
it('returns nothing if predict_deposit', () => {
78-
request.transactionMeta.nestedTransactions = [
79-
{ type: TransactionType.predictDeposit },
80-
];
81-
82-
const result = getMetaMaskPayProperties(request);
83-
84-
expect(result).toStrictEqual({
85-
properties: {},
86-
sensitiveProperties: {},
87-
});
88-
});
89-
9077
it('copies properties from parent transaction if bridge', () => {
9178
getUIMetricsMock.mockReturnValue({
9279
properties: {
@@ -348,4 +335,36 @@ describe('Metamask Pay Metrics', () => {
348335

349336
expect(result.properties.mm_pay_dust_usd).toBeUndefined();
350337
});
338+
339+
it('sets polymarket_account_created as true if predict deposit and matching nested transaction', () => {
340+
request.transactionMeta.nestedTransactions = [
341+
{ type: TransactionType.predictDeposit },
342+
{ data: '0xa1884d2c1234' },
343+
];
344+
345+
const result = getMetaMaskPayProperties(request);
346+
347+
expect(result).toStrictEqual({
348+
properties: {
349+
polymarket_account_created: true,
350+
},
351+
sensitiveProperties: {},
352+
});
353+
});
354+
355+
it('sets polymarket_account_created as false if predict deposit with no matching nested transaction', () => {
356+
request.transactionMeta.nestedTransactions = [
357+
{ type: TransactionType.predictDeposit },
358+
{ data: '0xa1884d2d' },
359+
];
360+
361+
const result = getMetaMaskPayProperties(request);
362+
363+
expect(result).toStrictEqual({
364+
properties: {
365+
polymarket_account_created: false,
366+
},
367+
sensitiveProperties: {},
368+
});
369+
});
351370
});

app/core/Engine/controllers/transaction-controller/event_properties/metamask-pay.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@ import {
1010
TransactionPayStrategy,
1111
} from '@metamask/transaction-pay-controller';
1212

13+
const FOUR_BYTE_SAFE_PROXY_CREATE = '0xa1884d2c';
14+
1315
const COPY_METRICS = [
1416
'mm_pay',
1517
'mm_pay_use_case',
@@ -37,6 +39,12 @@ export const getMetaMaskPayProperties: TransactionMetricsBuilder = ({
3739
(batchId && hasTransactionType(tx, PAY_TYPES) && tx.batchId === batchId),
3840
);
3941

42+
if (hasTransactionType(transactionMeta, [TransactionType.predictDeposit])) {
43+
properties.polymarket_account_created = (
44+
transactionMeta?.nestedTransactions ?? []
45+
).some((t) => t.data?.startsWith(FOUR_BYTE_SAFE_PROXY_CREATE));
46+
}
47+
4048
if (hasTransactionType(transactionMeta, PAY_TYPES) || !parentTransaction) {
4149
return {
4250
properties,

0 commit comments

Comments
 (0)