Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion packages/assets-controllers/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@
"@metamask/controller-utils": "^9.0.2",
"@metamask/eth-query": "^4.0.0",
"@metamask/keyring-controller": "^14.0.1",
"@metamask/metamask-eth-abis": "3.0.0",
"@metamask/metamask-eth-abis": "^3.1.1",
"@metamask/network-controller": "^18.0.1",
"@metamask/polling-controller": "^6.0.1",
"@metamask/preferences-controller": "^9.0.1",
Expand Down
2 changes: 1 addition & 1 deletion packages/transaction-controller/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@
"@metamask/controller-utils": "^9.0.2",
"@metamask/eth-query": "^4.0.0",
"@metamask/gas-fee-controller": "^14.0.1",
"@metamask/metamask-eth-abis": "^3.0.0",
"@metamask/metamask-eth-abis": "^3.1.1",
"@metamask/network-controller": "^18.0.1",
"@metamask/rpc-errors": "^6.2.1",
"@metamask/utils": "^8.3.0",
Expand Down
5 changes: 5 additions & 0 deletions packages/transaction-controller/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -566,6 +566,11 @@ export enum TransactionType {
* spend on behalf of the user.
*/
tokenMethodSetApprovalForAll = 'setapprovalforall',

/**
* Increase the allowance by a given increment
*/
tokenMethodIncreaseAllowance = 'increaseAllowance',
}

/**
Expand Down
19 changes: 17 additions & 2 deletions packages/transaction-controller/src/utils/transaction-type.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,12 @@ import type { TransactionDescription } from '@ethersproject/abi';
import { Interface } from '@ethersproject/abi';
import { query } from '@metamask/controller-utils';
import type EthQuery from '@metamask/eth-query';
import { abiERC721, abiERC20, abiERC1155 } from '@metamask/metamask-eth-abis';
import {
abiERC721,
abiERC20,
abiERC1155,
abiFiatTokenV2,
} from '@metamask/metamask-eth-abis';

import type { InferTransactionTypeResult, TransactionParams } from '../types';
import { TransactionType } from '../types';
Expand All @@ -12,6 +17,7 @@ export const ESTIMATE_GAS_ERROR = 'eth_estimateGas rpc method error';
const ERC20Interface = new Interface(abiERC20);
const ERC721Interface = new Interface(abiERC721);
const ERC1155Interface = new Interface(abiERC1155);
const USDCInterface = new Interface(abiFiatTokenV2);

/**
* Determines the type of the transaction by analyzing the txParams.
Expand Down Expand Up @@ -62,7 +68,10 @@ export async function determineTransactionType(
TransactionType.tokenMethodTransfer,
TransactionType.tokenMethodTransferFrom,
TransactionType.tokenMethodSafeTransferFrom,
].find((methodName) => methodName.toLowerCase() === name.toLowerCase());
TransactionType.tokenMethodIncreaseAllowance,
].find(
(methodName) => methodName.toLowerCase() === (name as string).toLowerCase(),
);

if (tokenMethodName) {
return { type: tokenMethodName, getCodeResponse };
Expand Down Expand Up @@ -104,6 +113,12 @@ function parseStandardTokenTransactionData(
// ignore and return undefined
}

try {
return USDCInterface.parseTransaction({ data });
Copy link
Member

@matthewwalsh0 matthewwalsh0 Mar 22, 2024

Choose a reason for hiding this comment

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

I'd recommend a unit test usually for this extra logic, but it doesn't seem we have method specific tests yet so happy to approve without.

Copy link
Member

Choose a reason for hiding this comment

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

Not needed now, but if we expect more of these in future, we could loop through a list of interfaces to remove some duplication.

} catch {
// ignore and return undefined
}

return undefined;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -307,7 +307,7 @@ describe('validation', () => {
'type',
'wrong type',
123,
'Expected one of `"cancel","contractInteraction","contractDeployment","eth_decrypt","eth_getEncryptionPublicKey","incoming","personal_sign","retry","simpleSend","eth_sign","eth_signTypedData","smart","swap","swapApproval","approve","safetransferfrom","transfer","transferfrom","setapprovalforall"`, but received: 123',
'Expected one of `"cancel","contractInteraction","contractDeployment","eth_decrypt","eth_getEncryptionPublicKey","incoming","personal_sign","retry","simpleSend","eth_sign","eth_signTypedData","smart","swap","swapApproval","approve","safetransferfrom","transfer","transferfrom","setapprovalforall","increaseAllowance"`, but received: 123',
],
])(
'throws if %s is %s',
Expand Down
12 changes: 6 additions & 6 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -1766,7 +1766,7 @@ __metadata:
"@metamask/ethjs-provider-http": ^0.3.0
"@metamask/keyring-api": ^3.0.0
"@metamask/keyring-controller": ^14.0.1
"@metamask/metamask-eth-abis": 3.0.0
"@metamask/metamask-eth-abis": ^3.1.1
"@metamask/network-controller": ^18.0.1
"@metamask/polling-controller": ^6.0.1
"@metamask/preferences-controller": ^9.0.1
Expand Down Expand Up @@ -2527,10 +2527,10 @@ __metadata:
languageName: unknown
linkType: soft

"@metamask/metamask-eth-abis@npm:3.0.0, @metamask/metamask-eth-abis@npm:^3.0.0":
version: 3.0.0
resolution: "@metamask/metamask-eth-abis@npm:3.0.0"
checksum: a9e3020dd8deda91b4957cc38f0041944fd60a374d7f9d19b3bc2706c5ca70b3c2a5f679b5ef390b722a2c047a2852ebecd3aaa91c054cf5a60d9ca02ee45fe6
"@metamask/metamask-eth-abis@npm:^3.1.1":
version: 3.1.1
resolution: "@metamask/metamask-eth-abis@npm:3.1.1"
checksum: b453fafbcf43462af0deae44182bbf4a7b0a2c4e7bc36e80c4a6cc854a8a87be28cf60e8203f1b5ec21bd53d996f6a379cd8f4268facd2bb042af211b3db83dc
languageName: node
linkType: hard

Expand Down Expand Up @@ -3143,7 +3143,7 @@ __metadata:
"@metamask/eth-query": ^4.0.0
"@metamask/ethjs-provider-http": ^0.3.0
"@metamask/gas-fee-controller": ^14.0.1
"@metamask/metamask-eth-abis": ^3.0.0
"@metamask/metamask-eth-abis": ^3.1.1
"@metamask/network-controller": ^18.0.1
"@metamask/rpc-errors": ^6.2.1
"@metamask/utils": ^8.3.0
Expand Down