Skip to content

Commit

Permalink
feat: support type 4 transactions (#5285)
Browse files Browse the repository at this point in the history
## Explanation

Support EIP-7702 / type 4 transactions including `authorizationList` via
the `TransactionController`.

Specifically:

- Upgrade `ethereumjs/tx` and `ethereumjs/common`.
- Add `setCode` to `TransactionEnvelopeType`.
- Add `authorizationList` to `TransactionParams`.
- Complete and sign all authorizations using `KeyringController` before
signing transaction.
- Prevent type 4 transactions if origin is not `ORIGIN_METAMASK`.
- Validate `authorizationList` property before approval request.
- Centralise prepare and serialization logic into `prepare.ts` utils.
- Encapsulate all EIP-7702 specific logic in new `eip7702.ts` util.

_Currently using a local messenger action type for the signing. To be
replaced once available in the `KeyringController`._

## References

Fixes [#4095](MetaMask/MetaMask-planning#4095)

## Changelog

### `@metamask/transaction-controller`

- **ADDED**: Add `setCode` to `TransactionEnvelopeType`.
- **ADDED**: Add `authorizationList` to `TransactionParams`.
- **CHANGED**: Bump `ethereumjs/tx` to `^5.4.0`.
- **CHANGED**: Bump `ethereumjs/common` to `^4.4.0`.

## 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
- [x] I've prepared draft pull requests for clients and consumer
packages to resolve any breaking changes
  • Loading branch information
matthewwalsh0 authored Feb 7, 2025
1 parent 1fbade9 commit c2a4312
Show file tree
Hide file tree
Showing 16 changed files with 1,075 additions and 282 deletions.
19 changes: 1 addition & 18 deletions eslint-warning-thresholds.json
Original file line number Diff line number Diff line change
Expand Up @@ -575,12 +575,8 @@
"promise/always-return": 2
},
"packages/transaction-controller/src/TransactionController.ts": {
"@typescript-eslint/prefer-readonly": 11,
"jsdoc/check-tag-names": 35,
"jsdoc/require-returns": 5,
"jsdoc/tag-lines": 1,
"prettier/prettier": 1,
"no-unused-private-class-members": 1
"jsdoc/require-returns": 5
},
"packages/transaction-controller/src/TransactionControllerIntegration.test.ts": {
"import-x/order": 4,
Expand Down Expand Up @@ -612,9 +608,6 @@
"import-x/order": 1,
"jsdoc/tag-lines": 1
},
"packages/transaction-controller/src/gas-flows/OracleLayer1GasFeeFlow.ts": {
"@typescript-eslint/prefer-readonly": 2
},
"packages/transaction-controller/src/gas-flows/ScrollLayer1GasFeeFlow.test.ts": {
"import-x/order": 1
},
Expand Down Expand Up @@ -673,9 +666,6 @@
"@typescript-eslint/prefer-readonly": 1,
"jsdoc/tag-lines": 2
},
"packages/transaction-controller/src/types.ts": {
"jsdoc/tag-lines": 4
},
"packages/transaction-controller/src/utils/external-transactions.test.ts": {
"import-x/order": 1
},
Expand Down Expand Up @@ -764,13 +754,6 @@
"packages/transaction-controller/src/utils/utils.test.ts": {
"import-x/order": 1
},
"packages/transaction-controller/src/utils/validation.test.ts": {
"import-x/order": 1
},
"packages/transaction-controller/src/utils/validation.ts": {
"@typescript-eslint/no-unsafe-enum-comparison": 2,
"import-x/order": 1
},
"packages/user-operation-controller/src/UserOperationController.test.ts": {
"jsdoc/tag-lines": 4
},
Expand Down
2 changes: 1 addition & 1 deletion packages/transaction-controller/jest.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ module.exports = merge(baseConfig, {
coverageThreshold: {
global: {
branches: 91.76,
functions: 94.76,
functions: 94.62,
lines: 96.83,
statements: 96.82,
},
Expand Down
4 changes: 2 additions & 2 deletions packages/transaction-controller/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,8 @@
"test:watch": "NODE_OPTIONS=--experimental-vm-modules jest --watch"
},
"dependencies": {
"@ethereumjs/common": "^3.2.0",
"@ethereumjs/tx": "^4.2.0",
"@ethereumjs/common": "^4.4.0",
"@ethereumjs/tx": "^5.4.0",
"@ethereumjs/util": "^8.1.0",
"@ethersproject/abi": "^5.7.0",
"@ethersproject/contracts": "^5.7.0",
Expand Down
Loading

0 comments on commit c2a4312

Please sign in to comment.