Skip to content

Commit 6392fde

Browse files
Adds 'tokenMethodIncreaseAllowance' (#4069)
## Explanation Creates the `tokenMethodIncreaseAllowance` transaction type, and adds the FiatTokenV2 token to be able to parse transactions with the increaseAllowance method, since it's not part of the ERC20 standard. ## References * Related to [#2224](MetaMask/MetaMask-planning#2224) ## Changelog <!-- If you're making any consumer-facing changes, list those changes here as if you were updating a changelog, using the template below as a guide. (CATEGORY is one of BREAKING, ADDED, CHANGED, DEPRECATED, REMOVED, or FIXED. For security-related issues, follow the Security Advisory process.) Please take care to name the exact pieces of the API you've added or changed (e.g. types, interfaces, functions, or methods). If there are any breaking changes, make sure to offer a solution for consumers to follow once they upgrade to the changes. Finally, if you're only making changes to development scripts or tests, you may replace the template below with "None". --> ### `@metamask/transaction-controller` - **ADDED**: Adds support for `increaseAllowance` token method and corresponding transaction type. ## Checklist - [x] I've updated the test suite for new or updated code as appropriate - [x] I've updated documentation (JSDoc, Markdown, etc.) for new or updated code as appropriate - [x] I've highlighted breaking changes using the "BREAKING" category above as appropriate
1 parent 040abb5 commit 6392fde

File tree

6 files changed

+31
-11
lines changed

6 files changed

+31
-11
lines changed

packages/assets-controllers/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@
5454
"@metamask/controller-utils": "^9.0.2",
5555
"@metamask/eth-query": "^4.0.0",
5656
"@metamask/keyring-controller": "^14.0.1",
57-
"@metamask/metamask-eth-abis": "3.0.0",
57+
"@metamask/metamask-eth-abis": "^3.1.1",
5858
"@metamask/network-controller": "^18.0.1",
5959
"@metamask/polling-controller": "^6.0.1",
6060
"@metamask/preferences-controller": "^9.0.1",

packages/transaction-controller/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@
5050
"@metamask/controller-utils": "^9.0.2",
5151
"@metamask/eth-query": "^4.0.0",
5252
"@metamask/gas-fee-controller": "^14.0.1",
53-
"@metamask/metamask-eth-abis": "^3.0.0",
53+
"@metamask/metamask-eth-abis": "^3.1.1",
5454
"@metamask/network-controller": "^18.0.1",
5555
"@metamask/rpc-errors": "^6.2.1",
5656
"@metamask/utils": "^8.3.0",

packages/transaction-controller/src/types.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -566,6 +566,11 @@ export enum TransactionType {
566566
* spend on behalf of the user.
567567
*/
568568
tokenMethodSetApprovalForAll = 'setapprovalforall',
569+
570+
/**
571+
* Increase the allowance by a given increment
572+
*/
573+
tokenMethodIncreaseAllowance = 'increaseAllowance',
569574
}
570575

571576
/**

packages/transaction-controller/src/utils/transaction-type.ts

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,12 @@ import type { TransactionDescription } from '@ethersproject/abi';
22
import { Interface } from '@ethersproject/abi';
33
import { query } from '@metamask/controller-utils';
44
import type EthQuery from '@metamask/eth-query';
5-
import { abiERC721, abiERC20, abiERC1155 } from '@metamask/metamask-eth-abis';
5+
import {
6+
abiERC721,
7+
abiERC20,
8+
abiERC1155,
9+
abiFiatTokenV2,
10+
} from '@metamask/metamask-eth-abis';
611

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

1622
/**
1723
* Determines the type of the transaction by analyzing the txParams.
@@ -62,7 +68,10 @@ export async function determineTransactionType(
6268
TransactionType.tokenMethodTransfer,
6369
TransactionType.tokenMethodTransferFrom,
6470
TransactionType.tokenMethodSafeTransferFrom,
65-
].find((methodName) => methodName.toLowerCase() === name.toLowerCase());
71+
TransactionType.tokenMethodIncreaseAllowance,
72+
].find(
73+
(methodName) => methodName.toLowerCase() === (name as string).toLowerCase(),
74+
);
6675

6776
if (tokenMethodName) {
6877
return { type: tokenMethodName, getCodeResponse };
@@ -104,6 +113,12 @@ function parseStandardTokenTransactionData(
104113
// ignore and return undefined
105114
}
106115

116+
try {
117+
return USDCInterface.parseTransaction({ data });
118+
} catch {
119+
// ignore and return undefined
120+
}
121+
107122
return undefined;
108123
}
109124

packages/user-operation-controller/src/utils/validation.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -307,7 +307,7 @@ describe('validation', () => {
307307
'type',
308308
'wrong type',
309309
123,
310-
'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',
310+
'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',
311311
],
312312
])(
313313
'throws if %s is %s',

yarn.lock

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1766,7 +1766,7 @@ __metadata:
17661766
"@metamask/ethjs-provider-http": ^0.3.0
17671767
"@metamask/keyring-api": ^3.0.0
17681768
"@metamask/keyring-controller": ^14.0.1
1769-
"@metamask/metamask-eth-abis": 3.0.0
1769+
"@metamask/metamask-eth-abis": ^3.1.1
17701770
"@metamask/network-controller": ^18.0.1
17711771
"@metamask/polling-controller": ^6.0.1
17721772
"@metamask/preferences-controller": ^9.0.1
@@ -2527,10 +2527,10 @@ __metadata:
25272527
languageName: unknown
25282528
linkType: soft
25292529

2530-
"@metamask/metamask-eth-abis@npm:3.0.0, @metamask/metamask-eth-abis@npm:^3.0.0":
2531-
version: 3.0.0
2532-
resolution: "@metamask/metamask-eth-abis@npm:3.0.0"
2533-
checksum: a9e3020dd8deda91b4957cc38f0041944fd60a374d7f9d19b3bc2706c5ca70b3c2a5f679b5ef390b722a2c047a2852ebecd3aaa91c054cf5a60d9ca02ee45fe6
2530+
"@metamask/metamask-eth-abis@npm:^3.1.1":
2531+
version: 3.1.1
2532+
resolution: "@metamask/metamask-eth-abis@npm:3.1.1"
2533+
checksum: b453fafbcf43462af0deae44182bbf4a7b0a2c4e7bc36e80c4a6cc854a8a87be28cf60e8203f1b5ec21bd53d996f6a379cd8f4268facd2bb042af211b3db83dc
25342534
languageName: node
25352535
linkType: hard
25362536

@@ -3143,7 +3143,7 @@ __metadata:
31433143
"@metamask/eth-query": ^4.0.0
31443144
"@metamask/ethjs-provider-http": ^0.3.0
31453145
"@metamask/gas-fee-controller": ^14.0.1
3146-
"@metamask/metamask-eth-abis": ^3.0.0
3146+
"@metamask/metamask-eth-abis": ^3.1.1
31473147
"@metamask/network-controller": ^18.0.1
31483148
"@metamask/rpc-errors": ^6.2.1
31493149
"@metamask/utils": ^8.3.0

0 commit comments

Comments
 (0)