@metamask-previews/user-operation-controller 41.0.3-preview-25d2d4502 → 41.1.0-preview-152e02d
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +16 -2
- package/dist/UserOperationController-method-action-types.cjs +7 -0
- package/dist/UserOperationController-method-action-types.cjs.map +1 -0
- package/dist/UserOperationController-method-action-types.d.cts +57 -0
- package/dist/UserOperationController-method-action-types.d.cts.map +1 -0
- package/dist/UserOperationController-method-action-types.d.mts +57 -0
- package/dist/UserOperationController-method-action-types.d.mts.map +1 -0
- package/dist/UserOperationController-method-action-types.mjs +6 -0
- package/dist/UserOperationController-method-action-types.mjs.map +1 -0
- package/dist/UserOperationController.cjs +12 -0
- package/dist/UserOperationController.cjs.map +1 -1
- package/dist/UserOperationController.d.cts +9 -2
- package/dist/UserOperationController.d.cts.map +1 -1
- package/dist/UserOperationController.d.mts +9 -2
- package/dist/UserOperationController.d.mts.map +1 -1
- package/dist/UserOperationController.mjs +12 -0
- package/dist/UserOperationController.mjs.map +1 -1
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +1 -0
- package/dist/index.d.cts.map +1 -1
- package/dist/index.d.mts +1 -0
- package/dist/index.d.mts.map +1 -1
- package/dist/index.mjs.map +1 -1
- package/package.json +6 -4
package/CHANGELOG.md
CHANGED
|
@@ -7,9 +7,22 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|
|
7
7
|
|
|
8
8
|
## [Unreleased]
|
|
9
9
|
|
|
10
|
+
## [41.1.0]
|
|
11
|
+
|
|
12
|
+
### Added
|
|
13
|
+
|
|
14
|
+
- Expose missing public `UserOperationController` methods through its messenger ([#8183](https://github.com/MetaMask/core/pull/8183))
|
|
15
|
+
- The following actions are now available:
|
|
16
|
+
- `UserOperationController:addUserOperation`
|
|
17
|
+
- `UserOperationController:addUserOperationFromTransaction`
|
|
18
|
+
- `UserOperationController:startPollingByNetworkClientId`
|
|
19
|
+
- Corresponding action types (e.g. `UserOperationControllerAddUserOperationAction`) are available as well.
|
|
20
|
+
|
|
10
21
|
### Changed
|
|
11
22
|
|
|
12
|
-
- Bump `@metamask/
|
|
23
|
+
- Bump `@metamask/approval-controller` from `^8.0.0` to `^9.0.0` ([#8225](https://github.com/MetaMask/core/pull/8225))
|
|
24
|
+
- Bump `@metamask/gas-fee-controller` from `^26.0.3` to `^26.1.0` ([#8225](https://github.com/MetaMask/core/pull/8225))
|
|
25
|
+
- Bump `@metamask/transaction-controller` from `^62.17.1` to `^63.0.0` ([#8005](https://github.com/MetaMask/core/pull/8005), [#8031](https://github.com/MetaMask/core/pull/8031), [#8104](https://github.com/MetaMask/core/pull/8104), [#8140](https://github.com/MetaMask/core/pull/8140), [#8217](https://github.com/MetaMask/core/pull/8217), [#8225](https://github.com/MetaMask/core/pull/8225))
|
|
13
26
|
|
|
14
27
|
## [41.0.3]
|
|
15
28
|
|
|
@@ -542,7 +555,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|
|
542
555
|
|
|
543
556
|
- Initial Release ([#3749](https://github.com/MetaMask/core/pull/3749))
|
|
544
557
|
|
|
545
|
-
[Unreleased]: https://github.com/MetaMask/core/compare/@metamask/user-operation-controller@41.0
|
|
558
|
+
[Unreleased]: https://github.com/MetaMask/core/compare/@metamask/user-operation-controller@41.1.0...HEAD
|
|
559
|
+
[41.1.0]: https://github.com/MetaMask/core/compare/@metamask/user-operation-controller@41.0.3...@metamask/user-operation-controller@41.1.0
|
|
546
560
|
[41.0.3]: https://github.com/MetaMask/core/compare/@metamask/user-operation-controller@41.0.2...@metamask/user-operation-controller@41.0.3
|
|
547
561
|
[41.0.2]: https://github.com/MetaMask/core/compare/@metamask/user-operation-controller@41.0.1...@metamask/user-operation-controller@41.0.2
|
|
548
562
|
[41.0.1]: https://github.com/MetaMask/core/compare/@metamask/user-operation-controller@41.0.0...@metamask/user-operation-controller@41.0.1
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* This file is auto generated by `scripts/generate-method-action-types.ts`.
|
|
4
|
+
* Do not edit manually.
|
|
5
|
+
*/
|
|
6
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
7
|
+
//# sourceMappingURL=UserOperationController-method-action-types.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"UserOperationController-method-action-types.cjs","sourceRoot":"","sources":["../src/UserOperationController-method-action-types.ts"],"names":[],"mappings":";AAAA;;;GAGG","sourcesContent":["/**\n * This file is auto generated by `scripts/generate-method-action-types.ts`.\n * Do not edit manually.\n */\n\nimport type { UserOperationController } from './UserOperationController';\n\n/**\n * Create and submit a user operation.\n *\n * @param request - Information required to create a user operation.\n * @param request.data - Data to include in the resulting transaction.\n * @param request.maxFeePerGas - Maximum fee per gas to pay towards the transaction.\n * @param request.maxPriorityFeePerGas - Maximum priority fee per gas to pay towards the transaction.\n * @param request.to - Destination address of the resulting transaction.\n * @param request.value - Value to include in the resulting transaction.\n * @param options - Configuration options when creating a user operation.\n * @param options.networkClientId - ID of the network client used to query the chain.\n * @param options.origin - Origin of the user operation, such as the hostname of a dApp.\n * @param options.requireApproval - Whether to require user approval before submitting the user operation. Defaults to true.\n * @param options.smartContractAccount - Smart contract abstraction to provide the contract specific values such as call data and nonce. Defaults to the current snap account.\n * @param options.swaps - Swap metadata to record with the user operation.\n * @param options.type - Type of the transaction.\n */\nexport type UserOperationControllerAddUserOperationAction = {\n type: `UserOperationController:addUserOperation`;\n handler: UserOperationController['addUserOperation'];\n};\n\n/**\n * Create and submit a user operation equivalent to the provided transaction.\n *\n * @param transaction - Transaction to use as the basis for the user operation.\n * @param options - Configuration options when creating a user operation.\n * @param options.networkClientId - ID of the network client used to query the chain.\n * @param options.origin - Origin of the user operation, such as the hostname of a dApp.\n * @param options.requireApproval - Whether to require user approval before submitting the user operation. Defaults to true.\n * @param options.smartContractAccount - Smart contract abstraction to provide the contract specific values such as call data and nonce. Defaults to the current snap account.\n * @param options.swaps - Swap metadata to record with the user operation.\n * @param options.type - Type of the transaction.\n */\nexport type UserOperationControllerAddUserOperationFromTransactionAction = {\n type: `UserOperationController:addUserOperationFromTransaction`;\n handler: UserOperationController['addUserOperationFromTransaction'];\n};\n\n/**\n * Starts polling for pending user operations on the given network.\n *\n * @param networkClientId - The ID of the network client to poll.\n * @returns The polling token that can be used to stop polling.\n */\nexport type UserOperationControllerStartPollingByNetworkClientIdAction = {\n type: `UserOperationController:startPollingByNetworkClientId`;\n handler: UserOperationController['startPollingByNetworkClientId'];\n};\n\n/**\n * Union of all UserOperationController action types.\n */\nexport type UserOperationControllerMethodActions =\n | UserOperationControllerAddUserOperationAction\n | UserOperationControllerAddUserOperationFromTransactionAction\n | UserOperationControllerStartPollingByNetworkClientIdAction;\n"]}
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* This file is auto generated by `scripts/generate-method-action-types.ts`.
|
|
3
|
+
* Do not edit manually.
|
|
4
|
+
*/
|
|
5
|
+
import type { UserOperationController } from "./UserOperationController.cjs";
|
|
6
|
+
/**
|
|
7
|
+
* Create and submit a user operation.
|
|
8
|
+
*
|
|
9
|
+
* @param request - Information required to create a user operation.
|
|
10
|
+
* @param request.data - Data to include in the resulting transaction.
|
|
11
|
+
* @param request.maxFeePerGas - Maximum fee per gas to pay towards the transaction.
|
|
12
|
+
* @param request.maxPriorityFeePerGas - Maximum priority fee per gas to pay towards the transaction.
|
|
13
|
+
* @param request.to - Destination address of the resulting transaction.
|
|
14
|
+
* @param request.value - Value to include in the resulting transaction.
|
|
15
|
+
* @param options - Configuration options when creating a user operation.
|
|
16
|
+
* @param options.networkClientId - ID of the network client used to query the chain.
|
|
17
|
+
* @param options.origin - Origin of the user operation, such as the hostname of a dApp.
|
|
18
|
+
* @param options.requireApproval - Whether to require user approval before submitting the user operation. Defaults to true.
|
|
19
|
+
* @param options.smartContractAccount - Smart contract abstraction to provide the contract specific values such as call data and nonce. Defaults to the current snap account.
|
|
20
|
+
* @param options.swaps - Swap metadata to record with the user operation.
|
|
21
|
+
* @param options.type - Type of the transaction.
|
|
22
|
+
*/
|
|
23
|
+
export type UserOperationControllerAddUserOperationAction = {
|
|
24
|
+
type: `UserOperationController:addUserOperation`;
|
|
25
|
+
handler: UserOperationController['addUserOperation'];
|
|
26
|
+
};
|
|
27
|
+
/**
|
|
28
|
+
* Create and submit a user operation equivalent to the provided transaction.
|
|
29
|
+
*
|
|
30
|
+
* @param transaction - Transaction to use as the basis for the user operation.
|
|
31
|
+
* @param options - Configuration options when creating a user operation.
|
|
32
|
+
* @param options.networkClientId - ID of the network client used to query the chain.
|
|
33
|
+
* @param options.origin - Origin of the user operation, such as the hostname of a dApp.
|
|
34
|
+
* @param options.requireApproval - Whether to require user approval before submitting the user operation. Defaults to true.
|
|
35
|
+
* @param options.smartContractAccount - Smart contract abstraction to provide the contract specific values such as call data and nonce. Defaults to the current snap account.
|
|
36
|
+
* @param options.swaps - Swap metadata to record with the user operation.
|
|
37
|
+
* @param options.type - Type of the transaction.
|
|
38
|
+
*/
|
|
39
|
+
export type UserOperationControllerAddUserOperationFromTransactionAction = {
|
|
40
|
+
type: `UserOperationController:addUserOperationFromTransaction`;
|
|
41
|
+
handler: UserOperationController['addUserOperationFromTransaction'];
|
|
42
|
+
};
|
|
43
|
+
/**
|
|
44
|
+
* Starts polling for pending user operations on the given network.
|
|
45
|
+
*
|
|
46
|
+
* @param networkClientId - The ID of the network client to poll.
|
|
47
|
+
* @returns The polling token that can be used to stop polling.
|
|
48
|
+
*/
|
|
49
|
+
export type UserOperationControllerStartPollingByNetworkClientIdAction = {
|
|
50
|
+
type: `UserOperationController:startPollingByNetworkClientId`;
|
|
51
|
+
handler: UserOperationController['startPollingByNetworkClientId'];
|
|
52
|
+
};
|
|
53
|
+
/**
|
|
54
|
+
* Union of all UserOperationController action types.
|
|
55
|
+
*/
|
|
56
|
+
export type UserOperationControllerMethodActions = UserOperationControllerAddUserOperationAction | UserOperationControllerAddUserOperationFromTransactionAction | UserOperationControllerStartPollingByNetworkClientIdAction;
|
|
57
|
+
//# sourceMappingURL=UserOperationController-method-action-types.d.cts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"UserOperationController-method-action-types.d.cts","sourceRoot":"","sources":["../src/UserOperationController-method-action-types.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,KAAK,EAAE,uBAAuB,EAAE,sCAAkC;AAEzE;;;;;;;;;;;;;;;;GAgBG;AACH,MAAM,MAAM,6CAA6C,GAAG;IAC1D,IAAI,EAAE,0CAA0C,CAAC;IACjD,OAAO,EAAE,uBAAuB,CAAC,kBAAkB,CAAC,CAAC;CACtD,CAAC;AAEF;;;;;;;;;;;GAWG;AACH,MAAM,MAAM,4DAA4D,GAAG;IACzE,IAAI,EAAE,yDAAyD,CAAC;IAChE,OAAO,EAAE,uBAAuB,CAAC,iCAAiC,CAAC,CAAC;CACrE,CAAC;AAEF;;;;;GAKG;AACH,MAAM,MAAM,0DAA0D,GAAG;IACvE,IAAI,EAAE,uDAAuD,CAAC;IAC9D,OAAO,EAAE,uBAAuB,CAAC,+BAA+B,CAAC,CAAC;CACnE,CAAC;AAEF;;GAEG;AACH,MAAM,MAAM,oCAAoC,GAC5C,6CAA6C,GAC7C,4DAA4D,GAC5D,0DAA0D,CAAC"}
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* This file is auto generated by `scripts/generate-method-action-types.ts`.
|
|
3
|
+
* Do not edit manually.
|
|
4
|
+
*/
|
|
5
|
+
import type { UserOperationController } from "./UserOperationController.mjs";
|
|
6
|
+
/**
|
|
7
|
+
* Create and submit a user operation.
|
|
8
|
+
*
|
|
9
|
+
* @param request - Information required to create a user operation.
|
|
10
|
+
* @param request.data - Data to include in the resulting transaction.
|
|
11
|
+
* @param request.maxFeePerGas - Maximum fee per gas to pay towards the transaction.
|
|
12
|
+
* @param request.maxPriorityFeePerGas - Maximum priority fee per gas to pay towards the transaction.
|
|
13
|
+
* @param request.to - Destination address of the resulting transaction.
|
|
14
|
+
* @param request.value - Value to include in the resulting transaction.
|
|
15
|
+
* @param options - Configuration options when creating a user operation.
|
|
16
|
+
* @param options.networkClientId - ID of the network client used to query the chain.
|
|
17
|
+
* @param options.origin - Origin of the user operation, such as the hostname of a dApp.
|
|
18
|
+
* @param options.requireApproval - Whether to require user approval before submitting the user operation. Defaults to true.
|
|
19
|
+
* @param options.smartContractAccount - Smart contract abstraction to provide the contract specific values such as call data and nonce. Defaults to the current snap account.
|
|
20
|
+
* @param options.swaps - Swap metadata to record with the user operation.
|
|
21
|
+
* @param options.type - Type of the transaction.
|
|
22
|
+
*/
|
|
23
|
+
export type UserOperationControllerAddUserOperationAction = {
|
|
24
|
+
type: `UserOperationController:addUserOperation`;
|
|
25
|
+
handler: UserOperationController['addUserOperation'];
|
|
26
|
+
};
|
|
27
|
+
/**
|
|
28
|
+
* Create and submit a user operation equivalent to the provided transaction.
|
|
29
|
+
*
|
|
30
|
+
* @param transaction - Transaction to use as the basis for the user operation.
|
|
31
|
+
* @param options - Configuration options when creating a user operation.
|
|
32
|
+
* @param options.networkClientId - ID of the network client used to query the chain.
|
|
33
|
+
* @param options.origin - Origin of the user operation, such as the hostname of a dApp.
|
|
34
|
+
* @param options.requireApproval - Whether to require user approval before submitting the user operation. Defaults to true.
|
|
35
|
+
* @param options.smartContractAccount - Smart contract abstraction to provide the contract specific values such as call data and nonce. Defaults to the current snap account.
|
|
36
|
+
* @param options.swaps - Swap metadata to record with the user operation.
|
|
37
|
+
* @param options.type - Type of the transaction.
|
|
38
|
+
*/
|
|
39
|
+
export type UserOperationControllerAddUserOperationFromTransactionAction = {
|
|
40
|
+
type: `UserOperationController:addUserOperationFromTransaction`;
|
|
41
|
+
handler: UserOperationController['addUserOperationFromTransaction'];
|
|
42
|
+
};
|
|
43
|
+
/**
|
|
44
|
+
* Starts polling for pending user operations on the given network.
|
|
45
|
+
*
|
|
46
|
+
* @param networkClientId - The ID of the network client to poll.
|
|
47
|
+
* @returns The polling token that can be used to stop polling.
|
|
48
|
+
*/
|
|
49
|
+
export type UserOperationControllerStartPollingByNetworkClientIdAction = {
|
|
50
|
+
type: `UserOperationController:startPollingByNetworkClientId`;
|
|
51
|
+
handler: UserOperationController['startPollingByNetworkClientId'];
|
|
52
|
+
};
|
|
53
|
+
/**
|
|
54
|
+
* Union of all UserOperationController action types.
|
|
55
|
+
*/
|
|
56
|
+
export type UserOperationControllerMethodActions = UserOperationControllerAddUserOperationAction | UserOperationControllerAddUserOperationFromTransactionAction | UserOperationControllerStartPollingByNetworkClientIdAction;
|
|
57
|
+
//# sourceMappingURL=UserOperationController-method-action-types.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"UserOperationController-method-action-types.d.mts","sourceRoot":"","sources":["../src/UserOperationController-method-action-types.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,KAAK,EAAE,uBAAuB,EAAE,sCAAkC;AAEzE;;;;;;;;;;;;;;;;GAgBG;AACH,MAAM,MAAM,6CAA6C,GAAG;IAC1D,IAAI,EAAE,0CAA0C,CAAC;IACjD,OAAO,EAAE,uBAAuB,CAAC,kBAAkB,CAAC,CAAC;CACtD,CAAC;AAEF;;;;;;;;;;;GAWG;AACH,MAAM,MAAM,4DAA4D,GAAG;IACzE,IAAI,EAAE,yDAAyD,CAAC;IAChE,OAAO,EAAE,uBAAuB,CAAC,iCAAiC,CAAC,CAAC;CACrE,CAAC;AAEF;;;;;GAKG;AACH,MAAM,MAAM,0DAA0D,GAAG;IACvE,IAAI,EAAE,uDAAuD,CAAC;IAC9D,OAAO,EAAE,uBAAuB,CAAC,+BAA+B,CAAC,CAAC;CACnE,CAAC;AAEF;;GAEG;AACH,MAAM,MAAM,oCAAoC,GAC5C,6CAA6C,GAC7C,4DAA4D,GAC5D,0DAA0D,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"UserOperationController-method-action-types.mjs","sourceRoot":"","sources":["../src/UserOperationController-method-action-types.ts"],"names":[],"mappings":"AAAA;;;GAGG","sourcesContent":["/**\n * This file is auto generated by `scripts/generate-method-action-types.ts`.\n * Do not edit manually.\n */\n\nimport type { UserOperationController } from './UserOperationController';\n\n/**\n * Create and submit a user operation.\n *\n * @param request - Information required to create a user operation.\n * @param request.data - Data to include in the resulting transaction.\n * @param request.maxFeePerGas - Maximum fee per gas to pay towards the transaction.\n * @param request.maxPriorityFeePerGas - Maximum priority fee per gas to pay towards the transaction.\n * @param request.to - Destination address of the resulting transaction.\n * @param request.value - Value to include in the resulting transaction.\n * @param options - Configuration options when creating a user operation.\n * @param options.networkClientId - ID of the network client used to query the chain.\n * @param options.origin - Origin of the user operation, such as the hostname of a dApp.\n * @param options.requireApproval - Whether to require user approval before submitting the user operation. Defaults to true.\n * @param options.smartContractAccount - Smart contract abstraction to provide the contract specific values such as call data and nonce. Defaults to the current snap account.\n * @param options.swaps - Swap metadata to record with the user operation.\n * @param options.type - Type of the transaction.\n */\nexport type UserOperationControllerAddUserOperationAction = {\n type: `UserOperationController:addUserOperation`;\n handler: UserOperationController['addUserOperation'];\n};\n\n/**\n * Create and submit a user operation equivalent to the provided transaction.\n *\n * @param transaction - Transaction to use as the basis for the user operation.\n * @param options - Configuration options when creating a user operation.\n * @param options.networkClientId - ID of the network client used to query the chain.\n * @param options.origin - Origin of the user operation, such as the hostname of a dApp.\n * @param options.requireApproval - Whether to require user approval before submitting the user operation. Defaults to true.\n * @param options.smartContractAccount - Smart contract abstraction to provide the contract specific values such as call data and nonce. Defaults to the current snap account.\n * @param options.swaps - Swap metadata to record with the user operation.\n * @param options.type - Type of the transaction.\n */\nexport type UserOperationControllerAddUserOperationFromTransactionAction = {\n type: `UserOperationController:addUserOperationFromTransaction`;\n handler: UserOperationController['addUserOperationFromTransaction'];\n};\n\n/**\n * Starts polling for pending user operations on the given network.\n *\n * @param networkClientId - The ID of the network client to poll.\n * @returns The polling token that can be used to stop polling.\n */\nexport type UserOperationControllerStartPollingByNetworkClientIdAction = {\n type: `UserOperationController:startPollingByNetworkClientId`;\n handler: UserOperationController['startPollingByNetworkClientId'];\n};\n\n/**\n * Union of all UserOperationController action types.\n */\nexport type UserOperationControllerMethodActions =\n | UserOperationControllerAddUserOperationAction\n | UserOperationControllerAddUserOperationFromTransactionAction\n | UserOperationControllerStartPollingByNetworkClientIdAction;\n"]}
|
|
@@ -38,6 +38,11 @@ const gas_fees_1 = require("./utils/gas-fees.cjs");
|
|
|
38
38
|
const transaction_1 = require("./utils/transaction.cjs");
|
|
39
39
|
const validation_1 = require("./utils/validation.cjs");
|
|
40
40
|
const controllerName = 'UserOperationController';
|
|
41
|
+
const MESSENGER_EXPOSED_METHODS = [
|
|
42
|
+
'addUserOperation',
|
|
43
|
+
'addUserOperationFromTransaction',
|
|
44
|
+
'startPollingByNetworkClientId',
|
|
45
|
+
];
|
|
41
46
|
const stateMetadata = {
|
|
42
47
|
userOperations: {
|
|
43
48
|
includeInStateLogs: true,
|
|
@@ -74,6 +79,7 @@ class UserOperationController extends base_controller_1.BaseController {
|
|
|
74
79
|
_UserOperationController_getGasFeeEstimates.set(this, void 0);
|
|
75
80
|
_UserOperationController_pendingUserOperationTracker.set(this, void 0);
|
|
76
81
|
this.hub = new events_1.default();
|
|
82
|
+
this.messenger.registerMethodActionHandlers(this, MESSENGER_EXPOSED_METHODS);
|
|
77
83
|
__classPrivateFieldSet(this, _UserOperationController_entrypoint, entrypoint, "f");
|
|
78
84
|
__classPrivateFieldSet(this, _UserOperationController_getGasFeeEstimates, getGasFeeEstimates, "f");
|
|
79
85
|
__classPrivateFieldSet(this, _UserOperationController_pendingUserOperationTracker, new PendingUserOperationTracker_1.PendingUserOperationTracker({
|
|
@@ -130,6 +136,12 @@ class UserOperationController extends base_controller_1.BaseController {
|
|
|
130
136
|
(0, validation_1.validateAddUserOperationRequest)(request);
|
|
131
137
|
return await __classPrivateFieldGet(this, _UserOperationController_instances, "m", _UserOperationController_addUserOperation).call(this, request, { ...options, transaction });
|
|
132
138
|
}
|
|
139
|
+
/**
|
|
140
|
+
* Starts polling for pending user operations on the given network.
|
|
141
|
+
*
|
|
142
|
+
* @param networkClientId - The ID of the network client to poll.
|
|
143
|
+
* @returns The polling token that can be used to stop polling.
|
|
144
|
+
*/
|
|
133
145
|
startPollingByNetworkClientId(networkClientId) {
|
|
134
146
|
return __classPrivateFieldGet(this, _UserOperationController_pendingUserOperationTracker, "f").startPolling({
|
|
135
147
|
networkClientId,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"UserOperationController.cjs","sourceRoot":"","sources":["../src/UserOperationController.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;AAKA,+DAA2D;AAK3D,iEAA0D;AAC1D,oEAA2C;AAY3C,qDAAkD;AAClD,6EAA4E;AAM5E,2CAAwC;AACxC,kEAAkE;AAClE,sDAAsD;AACtD,oDAAkC;AAClC,mCAAmC;AACnC,+BAAoC;AAEpC,+CAAoE;AACpE,mDAA4C;AAC5C,2FAAoF;AACpF,qFAA8E;AAC9E,yCAAgD;AAMhD,uCAA8C;AAC9C,yCAAwC;AACxC,mDAAiD;AACjD,yDAA6D;AAC7D,uDAM4B;AAE5B,MAAM,cAAc,GAAG,yBAAyB,CAAC;AAEjD,MAAM,aAAa,GAAG;IACpB,cAAc,EAAE;QACd,kBAAkB,EAAE,IAAI;QACxB,OAAO,EAAE,IAAI;QACb,sBAAsB,EAAE,KAAK;QAC7B,QAAQ,EAAE,IAAI;KACf;CACF,CAAC;AAEF,MAAM,eAAe,GAAG,GAAG,EAAE,CAAC,CAAC;IAC7B,cAAc,EAAE,EAAE;CACnB,CAAC,CAAC;AAuHH;;GAEG;AACH,MAAa,uBAAwB,SAAQ,gCAI5C;IASC;;;;;;;;OAQG;IACH,YAAY,EACV,UAAU,EACV,kBAAkB,EAClB,SAAS,EACT,KAAK,GAC0B;QAC/B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AG,IAAI,CAAC;IACjC,CAAC;IAED,IAAI,uBAAuB,EAAE,CAAC;QAC5B,MAAM,cAAc,GAAG;YACrB,GAAG,OAAO;YACV,IAAI,EAAE,WAAW;YACjB,YAAY,EAAE,mBAAmB;YACjC,oBAAoB,EAAE,2BAA2B;YACjD,KAAK,EAAE,YAAY;SACpB,CAAC;QAEF,MAAM,uBAAA,IAAI,4FAAyB,MAA7B,IAAI,EAA0B;YAClC,GAAG,KAAK;YACR,OAAO,EAAE,cAAc;SACxB,CAAC,CAAC;IACL,CAAC;AACH,CAAC,qDAED,KAAK,2DAA0B,KAAyB;IACtD,IAAA,sBAAG,EACD,wEAAwE,CACzE,CAAC;IAEF,MAAM,EACJ,OAAO,EAAE,EAAE,oBAAoB,EAAE,EACjC,QAAQ,GACT,GAAG,KAAK,CAAC;IAEV,MAAM,uBAAA,IAAI,yFAAsB,MAA1B,IAAI,EAAuB,KAAK,CAAC,CAAC;IACxC,MAAM,uBAAA,IAAI,qFAAkB,MAAtB,IAAI,EAAmB,QAAQ,EAAE,oBAAoB,CAAC,CAAC;IAE7D,IAAA,sBAAG,EAAC,4BAA4B,EAAE,QAAQ,CAAC,aAAa,CAAC,CAAC;AAC5D,CAAC","sourcesContent":["import type {\n AcceptResultCallbacks,\n AddApprovalRequest,\n AddResult,\n} from '@metamask/approval-controller';\nimport { BaseController } from '@metamask/base-controller';\nimport type {\n ControllerGetStateAction,\n ControllerStateChangeEvent,\n} from '@metamask/base-controller';\nimport { ApprovalType } from '@metamask/controller-utils';\nimport EthQuery from '@metamask/eth-query';\nimport type { GasFeeState } from '@metamask/gas-fee-controller';\nimport type {\n KeyringControllerPrepareUserOperationAction,\n KeyringControllerPatchUserOperationAction,\n KeyringControllerSignUserOperationAction,\n} from '@metamask/keyring-controller';\nimport type { Messenger } from '@metamask/messenger';\nimport type {\n NetworkControllerGetNetworkClientByIdAction,\n Provider,\n} from '@metamask/network-controller';\nimport { errorCodes } from '@metamask/rpc-errors';\nimport { determineTransactionType } from '@metamask/transaction-controller';\nimport type {\n TransactionMeta,\n TransactionParams,\n TransactionType,\n} from '@metamask/transaction-controller';\nimport { add0x } from '@metamask/utils';\n// This package purposefully relies on Node's EventEmitter module.\n// eslint-disable-next-line import-x/no-nodejs-modules\nimport EventEmitter from 'events';\nimport { cloneDeep } from 'lodash';\nimport { v1 as random } from 'uuid';\n\nimport { ADDRESS_ZERO, EMPTY_BYTES, VALUE_ZERO } from './constants';\nimport { Bundler } from './helpers/Bundler';\nimport { PendingUserOperationTracker } from './helpers/PendingUserOperationTracker';\nimport { SnapSmartContractAccount } from './helpers/SnapSmartContractAccount';\nimport { projectLogger as log } from './logger';\nimport type {\n SmartContractAccount,\n UserOperation,\n UserOperationMetadata,\n} from './types';\nimport { UserOperationStatus } from './types';\nimport { updateGas } from './utils/gas';\nimport { updateGasFees } from './utils/gas-fees';\nimport { getTransactionMetadata } from './utils/transaction';\nimport {\n validateAddUserOperationOptions,\n validateAddUserOperationRequest,\n validatePrepareUserOperationResponse,\n validateSignUserOperationResponse,\n validateUpdateUserOperationResponse,\n} from './utils/validation';\n\nconst controllerName = 'UserOperationController';\n\nconst stateMetadata = {\n userOperations: {\n includeInStateLogs: true,\n persist: true,\n includeInDebugSnapshot: false,\n usedInUi: true,\n },\n};\n\nconst getDefaultState = () => ({\n userOperations: {},\n});\n\ntype Events = {\n 'transaction-updated': [metadata: TransactionMeta];\n 'user-operation-added': [metadata: UserOperationMetadata];\n 'user-operation-confirmed': [metadata: UserOperationMetadata];\n 'user-operation-failed': [metadata: UserOperationMetadata, error: Error];\n [key: `${string}:confirmed`]: [metadata: UserOperationMetadata];\n [key: `${string}:failed`]: [metadata: UserOperationMetadata, error: Error];\n};\n\nexport type UserOperationControllerEventEmitter = EventEmitter & {\n on<T extends keyof Events>(\n eventName: T,\n listener: (...args: Events[T]) => void,\n ): UserOperationControllerEventEmitter;\n\n once<T extends keyof Events>(\n eventName: T,\n listener: (...args: Events[T]) => void,\n ): UserOperationControllerEventEmitter;\n\n emit<T extends keyof Events>(eventName: T, ...args: Events[T]): boolean;\n};\n\nexport type UserOperationControllerState = {\n userOperations: Record<string, UserOperationMetadata>;\n};\n\nexport type GetUserOperationState = ControllerGetStateAction<\n typeof controllerName,\n UserOperationControllerState\n>;\n\nexport type UserOperationStateChange = ControllerStateChangeEvent<\n typeof controllerName,\n UserOperationControllerState\n>;\n\nexport type UserOperationControllerActions =\n | GetUserOperationState\n | NetworkControllerGetNetworkClientByIdAction\n | AddApprovalRequest\n | KeyringControllerPrepareUserOperationAction\n | KeyringControllerPatchUserOperationAction\n | KeyringControllerSignUserOperationAction;\n\nexport type UserOperationControllerEvents = UserOperationStateChange;\n\nexport type UserOperationControllerMessenger = Messenger<\n typeof controllerName,\n UserOperationControllerActions,\n UserOperationControllerEvents\n>;\n\nexport type UserOperationControllerOptions = {\n entrypoint: string;\n getGasFeeEstimates: () => Promise<GasFeeState>;\n interval?: number;\n messenger: UserOperationControllerMessenger;\n state?: Partial<UserOperationControllerState>;\n};\n\nexport type AddUserOperationRequest = {\n data?: string;\n from: string;\n maxFeePerGas?: string;\n maxPriorityFeePerGas?: string;\n to?: string;\n value?: string;\n};\n\nexport type AddUserOperationSwapOptions = {\n approvalTxId?: string;\n destinationTokenAddress?: string;\n destinationTokenAmount?: string;\n destinationTokenDecimals?: number;\n destinationTokenSymbol?: string;\n estimatedBaseFee?: string;\n sourceTokenAddress?: string;\n sourceTokenAmount?: string;\n sourceTokenDecimals?: number;\n sourceTokenSymbol?: string;\n swapAndSendRecipient?: string;\n swapMetaData?: Record<string, unknown>;\n swapTokenValue?: string;\n};\n\nexport type AddUserOperationOptions = {\n networkClientId: string;\n origin: string;\n requireApproval?: boolean;\n smartContractAccount?: SmartContractAccount;\n swaps?: AddUserOperationSwapOptions;\n type?: TransactionType;\n};\n\nexport type AddUserOperationResponse = {\n id: string;\n hash: () => Promise<string | undefined>;\n transactionHash: () => Promise<string | undefined>;\n};\n\n/**\n * All the objects related to a pending user operation in order to:\n * - Avoid duplicated effort to derive the same properties.\n * - Minimise duplicate arguments in private methods.\n */\ntype UserOperationCache = {\n chainId: string;\n metadata: UserOperationMetadata;\n options: AddUserOperationOptions & {\n smartContractAccount: SmartContractAccount;\n };\n provider: Provider;\n request: AddUserOperationRequest;\n transaction?: TransactionParams;\n};\n\n/**\n * Controller for creating and managing the life cycle of user operations.\n */\nexport class UserOperationController extends BaseController<\n typeof controllerName,\n UserOperationControllerState,\n UserOperationControllerMessenger\n> {\n hub: UserOperationControllerEventEmitter;\n\n readonly #entrypoint: string;\n\n readonly #getGasFeeEstimates: () => Promise<GasFeeState>;\n\n readonly #pendingUserOperationTracker: PendingUserOperationTracker;\n\n /**\n * Construct a UserOperationController instance.\n *\n * @param options - Controller options.\n * @param options.entrypoint - Address of the entrypoint contract.\n * @param options.getGasFeeEstimates - Callback to get gas fee estimates.\n * @param options.messenger - Restricted messenger for the user operation controller.\n * @param options.state - Initial state to set on the controller.\n */\n constructor({\n entrypoint,\n getGasFeeEstimates,\n messenger,\n state,\n }: UserOperationControllerOptions) {\n super({\n name: controllerName,\n metadata: stateMetadata,\n messenger,\n state: { ...getDefaultState(), ...state },\n });\n\n this.hub = new EventEmitter() as UserOperationControllerEventEmitter;\n\n this.#entrypoint = entrypoint;\n this.#getGasFeeEstimates = getGasFeeEstimates;\n\n this.#pendingUserOperationTracker = new PendingUserOperationTracker({\n getUserOperations: () =>\n cloneDeep(Object.values(this.state.userOperations)),\n messenger,\n });\n\n this.#addPendingUserOperationTrackerListeners();\n }\n\n /**\n * Create and submit a user operation.\n *\n * @param request - Information required to create a user operation.\n * @param request.data - Data to include in the resulting transaction.\n * @param request.maxFeePerGas - Maximum fee per gas to pay towards the transaction.\n * @param request.maxPriorityFeePerGas - Maximum priority fee per gas to pay towards the transaction.\n * @param request.to - Destination address of the resulting transaction.\n * @param request.value - Value to include in the resulting transaction.\n * @param options - Configuration options when creating a user operation.\n * @param options.networkClientId - ID of the network client used to query the chain.\n * @param options.origin - Origin of the user operation, such as the hostname of a dApp.\n * @param options.requireApproval - Whether to require user approval before submitting the user operation. Defaults to true.\n * @param options.smartContractAccount - Smart contract abstraction to provide the contract specific values such as call data and nonce. Defaults to the current snap account.\n * @param options.swaps - Swap metadata to record with the user operation.\n * @param options.type - Type of the transaction.\n */\n async addUserOperation(\n request: AddUserOperationRequest,\n options: AddUserOperationOptions,\n ): Promise<AddUserOperationResponse> {\n validateAddUserOperationRequest(request);\n validateAddUserOperationOptions(options);\n\n return await this.#addUserOperation(request, options);\n }\n\n /**\n * Create and submit a user operation equivalent to the provided transaction.\n *\n * @param transaction - Transaction to use as the basis for the user operation.\n * @param options - Configuration options when creating a user operation.\n * @param options.networkClientId - ID of the network client used to query the chain.\n * @param options.origin - Origin of the user operation, such as the hostname of a dApp.\n * @param options.requireApproval - Whether to require user approval before submitting the user operation. Defaults to true.\n * @param options.smartContractAccount - Smart contract abstraction to provide the contract specific values such as call data and nonce. Defaults to the current snap account.\n * @param options.swaps - Swap metadata to record with the user operation.\n * @param options.type - Type of the transaction.\n */\n async addUserOperationFromTransaction(\n transaction: TransactionParams,\n options: AddUserOperationOptions,\n ): Promise<AddUserOperationResponse> {\n validateAddUserOperationOptions(options);\n\n const { data, from, maxFeePerGas, maxPriorityFeePerGas, to, value } =\n transaction;\n\n const request: AddUserOperationRequest = {\n data: data === '' ? undefined : data,\n from,\n maxFeePerGas,\n maxPriorityFeePerGas,\n to,\n value,\n };\n\n validateAddUserOperationRequest(request);\n\n return await this.#addUserOperation(request, { ...options, transaction });\n }\n\n startPollingByNetworkClientId(networkClientId: string): string {\n return this.#pendingUserOperationTracker.startPolling({\n networkClientId,\n });\n }\n\n async #addUserOperation(\n request: AddUserOperationRequest,\n options: AddUserOperationOptions & { transaction?: TransactionParams },\n ): Promise<AddUserOperationResponse> {\n log('Adding user operation', { request, options });\n\n const {\n networkClientId,\n origin,\n smartContractAccount: requestSmartContractAccount,\n swaps,\n transaction,\n } = options;\n\n const { chainId, provider } = await this.#getProvider(networkClientId);\n\n const metadata = await this.#createMetadata(\n chainId,\n origin,\n transaction,\n swaps,\n );\n\n const smartContractAccount =\n requestSmartContractAccount ??\n new SnapSmartContractAccount(this.messenger);\n\n const cache: UserOperationCache = {\n chainId,\n metadata,\n options: { ...options, smartContractAccount },\n provider,\n request,\n transaction,\n };\n\n const { id } = metadata;\n let throwError = false;\n\n const hashValue = (async () => {\n try {\n return await this.#prepareAndSubmitUserOperation(cache);\n } catch (error) {\n this.#failUserOperation(metadata, error);\n\n if (throwError) {\n throw error;\n }\n\n return undefined;\n }\n })();\n\n const hash = async () => {\n throwError = true;\n return await hashValue;\n };\n\n const transactionHash = async () => {\n await hash();\n\n const { transactionHash: finalTransactionHash } =\n await this.#waitForConfirmation(metadata);\n\n return finalTransactionHash as string;\n };\n\n return {\n id,\n hash,\n transactionHash,\n };\n }\n\n async #prepareAndSubmitUserOperation(cache: UserOperationCache) {\n const { metadata, options } = cache;\n const { requireApproval, smartContractAccount } = options;\n let resultCallbacks: AcceptResultCallbacks | undefined;\n\n try {\n await this.#prepareUserOperation(cache);\n await this.#addPaymasterData(metadata, smartContractAccount);\n\n this.hub.emit('user-operation-added', metadata);\n\n if (requireApproval !== false) {\n resultCallbacks = await this.#approveUserOperation(cache);\n }\n\n await this.#signUserOperation(metadata, smartContractAccount);\n await this.#submitUserOperation(metadata);\n\n resultCallbacks?.success();\n\n return metadata.hash as string;\n } catch (error) {\n /* istanbul ignore next */\n resultCallbacks?.error(error as Error);\n throw error;\n }\n }\n\n async #waitForConfirmation(\n metadata: UserOperationMetadata,\n ): Promise<UserOperationMetadata> {\n const { id, hash } = metadata;\n\n log('Waiting for confirmation', id, hash);\n\n return new Promise((resolve, reject) => {\n this.hub.once(`${id}:confirmed`, (finalMetadata) => {\n resolve(finalMetadata);\n });\n\n this.hub.once(`${id}:failed`, (_finalMetadata, error) => {\n reject(error);\n });\n });\n }\n\n async #createMetadata(\n chainId: string,\n origin: string,\n transaction?: TransactionParams,\n swaps?: AddUserOperationSwapOptions,\n ): Promise<UserOperationMetadata> {\n const metadata: UserOperationMetadata = {\n actualGasCost: null,\n actualGasUsed: null,\n baseFeePerGas: null,\n bundlerUrl: null,\n chainId,\n error: null,\n hash: null,\n id: random(),\n origin,\n status: UserOperationStatus.Unapproved,\n swapsMetadata: swaps\n ? {\n approvalTxId: swaps.approvalTxId ?? null,\n destinationTokenAddress: swaps.destinationTokenAddress ?? null,\n destinationTokenAmount: swaps.destinationTokenAmount ?? null,\n destinationTokenDecimals: swaps.destinationTokenDecimals ?? null,\n destinationTokenSymbol: swaps.destinationTokenSymbol ?? null,\n estimatedBaseFee: swaps.estimatedBaseFee ?? null,\n sourceTokenAddress: swaps.sourceTokenAddress ?? null,\n sourceTokenAmount: swaps.sourceTokenAmount ?? null,\n sourceTokenDecimals: swaps.sourceTokenDecimals ?? null,\n sourceTokenSymbol: swaps.sourceTokenSymbol ?? null,\n swapAndSendRecipient: swaps.swapAndSendRecipient ?? null,\n swapMetaData: (swaps.swapMetaData as Record<string, never>) ?? null,\n swapTokenValue: swaps.swapTokenValue ?? null,\n }\n : null,\n time: Date.now(),\n transactionHash: null,\n transactionParams: (transaction as Required<TransactionParams>) ?? null,\n transactionType: null,\n userFeeLevel: null,\n userOperation: this.#createEmptyUserOperation(transaction),\n };\n\n this.#updateMetadata(metadata);\n\n log('Added user operation', metadata.id);\n\n return metadata;\n }\n\n async #prepareUserOperation(cache: UserOperationCache) {\n const { chainId, metadata, options, provider, request, transaction } =\n cache;\n\n const { data, from, to, value } = request;\n const { id, transactionParams, userOperation } = metadata;\n const { smartContractAccount } = options;\n\n log('Preparing user operation', { id });\n\n const transactionType = await this.#getTransactionType(\n transaction,\n provider,\n options,\n );\n\n metadata.transactionType = transactionType ?? null;\n\n log('Determined transaction type', transactionType);\n\n await updateGasFees({\n getGasFeeEstimates: this.#getGasFeeEstimates,\n metadata,\n originalRequest: request,\n provider,\n transaction: transactionParams ?? undefined,\n });\n\n const response = await smartContractAccount.prepareUserOperation({\n chainId,\n data,\n from,\n to,\n value,\n });\n\n validatePrepareUserOperationResponse(response);\n\n const {\n bundler: bundlerUrl,\n callData,\n dummyPaymasterAndData,\n dummySignature,\n initCode,\n nonce,\n sender,\n } = response;\n\n userOperation.callData = callData;\n userOperation.initCode = initCode ?? EMPTY_BYTES;\n userOperation.nonce = nonce;\n userOperation.paymasterAndData = dummyPaymasterAndData ?? EMPTY_BYTES;\n userOperation.sender = sender;\n userOperation.signature = dummySignature ?? EMPTY_BYTES;\n\n metadata.bundlerUrl = bundlerUrl;\n\n await updateGas(metadata, response, this.#entrypoint);\n\n this.#updateMetadata(metadata);\n }\n\n async #addPaymasterData(\n metadata: UserOperationMetadata,\n smartContractAccount: SmartContractAccount,\n ) {\n const { id, userOperation, chainId } = metadata;\n\n log('Requesting paymaster data', { id });\n\n const response = await smartContractAccount.updateUserOperation({\n userOperation,\n chainId,\n });\n\n validateUpdateUserOperationResponse(response);\n\n userOperation.paymasterAndData = response.paymasterAndData ?? EMPTY_BYTES;\n if (response.callGasLimit) {\n userOperation.callGasLimit = response.callGasLimit;\n }\n if (response.preVerificationGas) {\n userOperation.preVerificationGas = response.preVerificationGas;\n }\n if (response.verificationGasLimit) {\n userOperation.verificationGasLimit = response.verificationGasLimit;\n }\n\n this.#updateMetadata(metadata);\n }\n\n async #approveUserOperation(cache: UserOperationCache) {\n log('Requesting approval');\n\n const { metadata } = cache;\n\n const { resultCallbacks, value } = await this.#requestApproval(metadata);\n const updatedTransaction = value?.txMeta;\n\n if (updatedTransaction) {\n await this.#updateUserOperationAfterApproval(cache, updatedTransaction);\n }\n\n metadata.status = UserOperationStatus.Approved;\n\n this.#updateMetadata(metadata);\n\n return resultCallbacks;\n }\n\n async #signUserOperation(\n metadata: UserOperationMetadata,\n smartContractAccount: SmartContractAccount,\n ) {\n const { id, chainId, userOperation } = metadata;\n\n log('Signing user operation', id, userOperation);\n\n const response = await smartContractAccount.signUserOperation({\n userOperation,\n chainId,\n });\n\n validateSignUserOperationResponse(response);\n\n const { signature } = response;\n\n userOperation.signature = signature;\n\n log('Signed user operation', signature);\n\n metadata.status = UserOperationStatus.Signed;\n\n this.#updateMetadata(metadata);\n }\n\n async #submitUserOperation(metadata: UserOperationMetadata) {\n const { userOperation } = metadata;\n\n log('Submitting user operation', userOperation);\n\n const bundler = new Bundler(metadata.bundlerUrl as string);\n\n const hash = await bundler.sendUserOperation(\n userOperation,\n this.#entrypoint,\n );\n\n metadata.hash = hash;\n metadata.status = UserOperationStatus.Submitted;\n\n this.#updateMetadata(metadata);\n }\n\n #failUserOperation(metadata: UserOperationMetadata, error: unknown) {\n const { id } = metadata;\n const rawError = error as Record<string, string>;\n\n log('User operation failed', id, error);\n\n metadata.error = {\n name: rawError.name,\n message: rawError.message,\n stack: rawError.stack,\n code: rawError.code,\n rpc: rawError.value,\n };\n\n metadata.status = UserOperationStatus.Failed;\n\n this.#updateMetadata(metadata);\n\n if (\n String(rawError.code) === String(errorCodes.provider.userRejectedRequest)\n ) {\n this.#deleteMetadata(id);\n }\n }\n\n #createEmptyUserOperation(transaction?: TransactionParams): UserOperation {\n return {\n callData: EMPTY_BYTES,\n callGasLimit: EMPTY_BYTES,\n initCode: EMPTY_BYTES,\n maxFeePerGas: transaction?.maxFeePerGas ?? EMPTY_BYTES,\n maxPriorityFeePerGas: transaction?.maxPriorityFeePerGas ?? EMPTY_BYTES,\n nonce: EMPTY_BYTES,\n paymasterAndData: EMPTY_BYTES,\n preVerificationGas: EMPTY_BYTES,\n sender: ADDRESS_ZERO,\n signature: EMPTY_BYTES,\n verificationGasLimit: EMPTY_BYTES,\n };\n }\n\n #updateMetadata(metadata: UserOperationMetadata) {\n const { id } = metadata;\n\n this.update((state) => {\n state.userOperations[id] = cloneDeep(metadata);\n });\n\n this.#updateTransaction(metadata);\n }\n\n #deleteMetadata(id: string) {\n this.update((state) => {\n delete state.userOperations[id];\n });\n }\n\n #updateTransaction(metadata: UserOperationMetadata) {\n if (!metadata.transactionParams) {\n return;\n }\n\n const transactionMetadata = getTransactionMetadata(metadata);\n\n this.hub.emit('transaction-updated', transactionMetadata);\n }\n\n #addPendingUserOperationTrackerListeners() {\n this.#pendingUserOperationTracker.hub.on(\n 'user-operation-confirmed',\n (metadata) => {\n log('In listener...');\n this.hub.emit('user-operation-confirmed', metadata);\n this.hub.emit(`${metadata.id}:confirmed`, metadata);\n },\n );\n\n this.#pendingUserOperationTracker.hub.on(\n 'user-operation-failed',\n (metadata, error) => {\n this.hub.emit('user-operation-failed', metadata, error);\n this.hub.emit(`${metadata.id}:failed`, metadata, error);\n },\n );\n\n this.#pendingUserOperationTracker.hub.on(\n 'user-operation-updated',\n (metadata) => {\n this.#updateMetadata(metadata);\n },\n );\n }\n\n async #requestApproval(metadata: UserOperationMetadata) {\n const { id, origin } = metadata;\n const type = ApprovalType.Transaction;\n const requestData = { txId: id };\n\n return (await this.messenger.call(\n 'ApprovalController:addRequest',\n {\n id,\n origin,\n type,\n requestData,\n expectsResult: true,\n },\n true, // Should display approval request to user\n )) as AddResult & { value?: { txMeta?: TransactionMeta } };\n }\n\n async #getTransactionType(\n transaction: TransactionParams | undefined,\n provider: Provider,\n options: AddUserOperationOptions,\n ): Promise<TransactionType | undefined> {\n if (!transaction) {\n return undefined;\n }\n\n if (options.type) {\n return options.type;\n }\n\n const ethQuery = new EthQuery(provider);\n const result = determineTransactionType(transaction, ethQuery);\n\n return (await result).type;\n }\n\n async #getProvider(\n networkClientId: string,\n ): Promise<{ provider: Provider; chainId: string }> {\n const { provider, configuration } = this.messenger.call(\n 'NetworkController:getNetworkClientById',\n networkClientId,\n );\n\n const { chainId } = configuration;\n\n return { provider, chainId };\n }\n\n async #updateUserOperationAfterApproval(\n cache: UserOperationCache,\n updatedTransaction: TransactionMeta,\n ) {\n log('Found updated transaction in approval', { updatedTransaction });\n\n const { metadata, request } = cache;\n\n const { userOperation } = metadata;\n const usingPaymaster = userOperation.paymasterAndData !== EMPTY_BYTES;\n\n const updatedMaxFeePerGas = add0x(\n updatedTransaction.txParams.maxFeePerGas as string,\n );\n\n const updatedMaxPriorityFeePerGas = add0x(\n updatedTransaction.txParams.maxPriorityFeePerGas as string,\n );\n\n let regenerateUserOperation = false;\n const previousMaxFeePerGas = userOperation.maxFeePerGas;\n const previousMaxPriorityFeePerGas = userOperation.maxPriorityFeePerGas;\n\n const gasFeesUpdated =\n previousMaxFeePerGas !== updatedMaxFeePerGas ||\n previousMaxPriorityFeePerGas !== updatedMaxPriorityFeePerGas;\n\n /**\n * true when we detect {@link getTransactionMetadata} has set the gas fees to zero\n * because the userOperation has a paymaster. This should not be mistaken for gas\n * fees being updated during the approval process.\n */\n const areGasFeesZeroBecauseOfPaymaster =\n usingPaymaster &&\n updatedMaxFeePerGas === VALUE_ZERO &&\n updatedMaxPriorityFeePerGas === VALUE_ZERO;\n\n if (gasFeesUpdated && !areGasFeesZeroBecauseOfPaymaster) {\n log('Gas fees updated during approval', {\n previousMaxFeePerGas,\n previousMaxPriorityFeePerGas,\n updatedMaxFeePerGas,\n updatedMaxPriorityFeePerGas,\n });\n\n userOperation.maxFeePerGas = updatedMaxFeePerGas;\n userOperation.maxPriorityFeePerGas = updatedMaxPriorityFeePerGas;\n\n regenerateUserOperation = usingPaymaster;\n }\n\n const previousData = request.data ?? EMPTY_BYTES;\n const updatedData = updatedTransaction.txParams.data ?? EMPTY_BYTES;\n\n if (previousData !== updatedData) {\n log('Data updated during approval', { previousData, updatedData });\n regenerateUserOperation = true;\n }\n\n const previousValue = request.value ?? VALUE_ZERO;\n const updatedValue = updatedTransaction.txParams.value ?? VALUE_ZERO;\n\n if (previousValue !== updatedValue) {\n log('Value updated during approval', { previousValue, updatedValue });\n regenerateUserOperation = true;\n }\n\n if (regenerateUserOperation) {\n const updatedRequest = {\n ...request,\n data: updatedData,\n maxFeePerGas: updatedMaxFeePerGas,\n maxPriorityFeePerGas: updatedMaxPriorityFeePerGas,\n value: updatedValue,\n };\n\n await this.#regenerateUserOperation({\n ...cache,\n request: updatedRequest,\n });\n }\n }\n\n async #regenerateUserOperation(cache: UserOperationCache) {\n log(\n 'Regenerating user operation as parameters were updated during approval',\n );\n\n const {\n options: { smartContractAccount },\n metadata,\n } = cache;\n\n await this.#prepareUserOperation(cache);\n await this.#addPaymasterData(metadata, smartContractAccount);\n\n log('Regenerated user operation', metadata.userOperation);\n }\n}\n"]}
|
|
1
|
+
{"version":3,"file":"UserOperationController.cjs","sourceRoot":"","sources":["../src/UserOperationController.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;AAKA,+DAA2D;AAK3D,iEAA0D;AAC1D,oEAA2C;AAY3C,qDAAkD;AAClD,6EAA4E;AAM5E,2CAAwC;AACxC,kEAAkE;AAClE,sDAAsD;AACtD,oDAAkC;AAClC,mCAAmC;AACnC,+BAAoC;AAEpC,+CAAoE;AACpE,mDAA4C;AAC5C,2FAAoF;AACpF,qFAA8E;AAC9E,yCAAgD;AAMhD,uCAA8C;AAE9C,yCAAwC;AACxC,mDAAiD;AACjD,yDAA6D;AAC7D,uDAM4B;AAE5B,MAAM,cAAc,GAAG,yBAAyB,CAAC;AAEjD,MAAM,yBAAyB,GAAG;IAChC,kBAAkB;IAClB,iCAAiC;IACjC,+BAA+B;CACvB,CAAC;AAEX,MAAM,aAAa,GAAG;IACpB,cAAc,EAAE;QACd,kBAAkB,EAAE,IAAI;QACxB,OAAO,EAAE,IAAI;QACb,sBAAsB,EAAE,KAAK;QAC7B,QAAQ,EAAE,IAAI;KACf;CACF,CAAC;AAEF,MAAM,eAAe,GAAG,GAAG,EAAE,CAAC,CAAC;IAC7B,cAAc,EAAE,EAAE;CACnB,CAAC,CAAC;AAwHH;;GAEG;AACH,MAAa,uBAAwB,SAAQ,gCAI5C;IASC;;;;;;;;OAQG;IACH,YAAY,EACV,UAAU,EACV,kBAAkB,EAClB,SAAS,EACT,KAAK,GAC0B;QAC/B,KAAK,CAAC;YACJ,IAAI,EAAE,cAAc;YACpB,QAAQ,EAAE,aAAa;YACvB,SAAS;YACT,KAAK,EAAE,EAA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IAAI,CAAC;IACjC,CAAC;IAED,IAAI,uBAAuB,EAAE,CAAC;QAC5B,MAAM,cAAc,GAAG;YACrB,GAAG,OAAO;YACV,IAAI,EAAE,WAAW;YACjB,YAAY,EAAE,mBAAmB;YACjC,oBAAoB,EAAE,2BAA2B;YACjD,KAAK,EAAE,YAAY;SACpB,CAAC;QAEF,MAAM,uBAAA,IAAI,4FAAyB,MAA7B,IAAI,EAA0B;YAClC,GAAG,KAAK;YACR,OAAO,EAAE,cAAc;SACxB,CAAC,CAAC;IACL,CAAC;AACH,CAAC,qDAED,KAAK,2DAA0B,KAAyB;IACtD,IAAA,sBAAG,EACD,wEAAwE,CACzE,CAAC;IAEF,MAAM,EACJ,OAAO,EAAE,EAAE,oBAAoB,EAAE,EACjC,QAAQ,GACT,GAAG,KAAK,CAAC;IAEV,MAAM,uBAAA,IAAI,yFAAsB,MAA1B,IAAI,EAAuB,KAAK,CAAC,CAAC;IACxC,MAAM,uBAAA,IAAI,qFAAkB,MAAtB,IAAI,EAAmB,QAAQ,EAAE,oBAAoB,CAAC,CAAC;IAE7D,IAAA,sBAAG,EAAC,4BAA4B,EAAE,QAAQ,CAAC,aAAa,CAAC,CAAC;AAC5D,CAAC","sourcesContent":["import type {\n AcceptResultCallbacks,\n ApprovalControllerAddRequestAction,\n AddResult,\n} from '@metamask/approval-controller';\nimport { BaseController } from '@metamask/base-controller';\nimport type {\n ControllerGetStateAction,\n ControllerStateChangeEvent,\n} from '@metamask/base-controller';\nimport { ApprovalType } from '@metamask/controller-utils';\nimport EthQuery from '@metamask/eth-query';\nimport type { GasFeeState } from '@metamask/gas-fee-controller';\nimport type {\n KeyringControllerPrepareUserOperationAction,\n KeyringControllerPatchUserOperationAction,\n KeyringControllerSignUserOperationAction,\n} from '@metamask/keyring-controller';\nimport type { Messenger } from '@metamask/messenger';\nimport type {\n NetworkControllerGetNetworkClientByIdAction,\n Provider,\n} from '@metamask/network-controller';\nimport { errorCodes } from '@metamask/rpc-errors';\nimport { determineTransactionType } from '@metamask/transaction-controller';\nimport type {\n TransactionMeta,\n TransactionParams,\n TransactionType,\n} from '@metamask/transaction-controller';\nimport { add0x } from '@metamask/utils';\n// This package purposefully relies on Node's EventEmitter module.\n// eslint-disable-next-line import-x/no-nodejs-modules\nimport EventEmitter from 'events';\nimport { cloneDeep } from 'lodash';\nimport { v1 as random } from 'uuid';\n\nimport { ADDRESS_ZERO, EMPTY_BYTES, VALUE_ZERO } from './constants';\nimport { Bundler } from './helpers/Bundler';\nimport { PendingUserOperationTracker } from './helpers/PendingUserOperationTracker';\nimport { SnapSmartContractAccount } from './helpers/SnapSmartContractAccount';\nimport { projectLogger as log } from './logger';\nimport type {\n SmartContractAccount,\n UserOperation,\n UserOperationMetadata,\n} from './types';\nimport { UserOperationStatus } from './types';\nimport type { UserOperationControllerMethodActions } from './UserOperationController-method-action-types';\nimport { updateGas } from './utils/gas';\nimport { updateGasFees } from './utils/gas-fees';\nimport { getTransactionMetadata } from './utils/transaction';\nimport {\n validateAddUserOperationOptions,\n validateAddUserOperationRequest,\n validatePrepareUserOperationResponse,\n validateSignUserOperationResponse,\n validateUpdateUserOperationResponse,\n} from './utils/validation';\n\nconst controllerName = 'UserOperationController';\n\nconst MESSENGER_EXPOSED_METHODS = [\n 'addUserOperation',\n 'addUserOperationFromTransaction',\n 'startPollingByNetworkClientId',\n] as const;\n\nconst stateMetadata = {\n userOperations: {\n includeInStateLogs: true,\n persist: true,\n includeInDebugSnapshot: false,\n usedInUi: true,\n },\n};\n\nconst getDefaultState = () => ({\n userOperations: {},\n});\n\ntype Events = {\n 'transaction-updated': [metadata: TransactionMeta];\n 'user-operation-added': [metadata: UserOperationMetadata];\n 'user-operation-confirmed': [metadata: UserOperationMetadata];\n 'user-operation-failed': [metadata: UserOperationMetadata, error: Error];\n [key: `${string}:confirmed`]: [metadata: UserOperationMetadata];\n [key: `${string}:failed`]: [metadata: UserOperationMetadata, error: Error];\n};\n\nexport type UserOperationControllerEventEmitter = EventEmitter & {\n on<T extends keyof Events>(\n eventName: T,\n listener: (...args: Events[T]) => void,\n ): UserOperationControllerEventEmitter;\n\n once<T extends keyof Events>(\n eventName: T,\n listener: (...args: Events[T]) => void,\n ): UserOperationControllerEventEmitter;\n\n emit<T extends keyof Events>(eventName: T, ...args: Events[T]): boolean;\n};\n\nexport type UserOperationControllerState = {\n userOperations: Record<string, UserOperationMetadata>;\n};\n\nexport type GetUserOperationState = ControllerGetStateAction<\n typeof controllerName,\n UserOperationControllerState\n>;\n\nexport type UserOperationStateChange = ControllerStateChangeEvent<\n typeof controllerName,\n UserOperationControllerState\n>;\n\nexport type UserOperationControllerActions =\n | GetUserOperationState\n | UserOperationControllerMethodActions\n | NetworkControllerGetNetworkClientByIdAction\n | ApprovalControllerAddRequestAction\n | KeyringControllerPrepareUserOperationAction\n | KeyringControllerPatchUserOperationAction\n | KeyringControllerSignUserOperationAction;\n\nexport type UserOperationControllerEvents = UserOperationStateChange;\n\nexport type UserOperationControllerMessenger = Messenger<\n typeof controllerName,\n UserOperationControllerActions,\n UserOperationControllerEvents\n>;\n\nexport type UserOperationControllerOptions = {\n entrypoint: string;\n getGasFeeEstimates: () => Promise<GasFeeState>;\n interval?: number;\n messenger: UserOperationControllerMessenger;\n state?: Partial<UserOperationControllerState>;\n};\n\nexport type AddUserOperationRequest = {\n data?: string;\n from: string;\n maxFeePerGas?: string;\n maxPriorityFeePerGas?: string;\n to?: string;\n value?: string;\n};\n\nexport type AddUserOperationSwapOptions = {\n approvalTxId?: string;\n destinationTokenAddress?: string;\n destinationTokenAmount?: string;\n destinationTokenDecimals?: number;\n destinationTokenSymbol?: string;\n estimatedBaseFee?: string;\n sourceTokenAddress?: string;\n sourceTokenAmount?: string;\n sourceTokenDecimals?: number;\n sourceTokenSymbol?: string;\n swapAndSendRecipient?: string;\n swapMetaData?: Record<string, unknown>;\n swapTokenValue?: string;\n};\n\nexport type AddUserOperationOptions = {\n networkClientId: string;\n origin: string;\n requireApproval?: boolean;\n smartContractAccount?: SmartContractAccount;\n swaps?: AddUserOperationSwapOptions;\n type?: TransactionType;\n};\n\nexport type AddUserOperationResponse = {\n id: string;\n hash: () => Promise<string | undefined>;\n transactionHash: () => Promise<string | undefined>;\n};\n\n/**\n * All the objects related to a pending user operation in order to:\n * - Avoid duplicated effort to derive the same properties.\n * - Minimise duplicate arguments in private methods.\n */\ntype UserOperationCache = {\n chainId: string;\n metadata: UserOperationMetadata;\n options: AddUserOperationOptions & {\n smartContractAccount: SmartContractAccount;\n };\n provider: Provider;\n request: AddUserOperationRequest;\n transaction?: TransactionParams;\n};\n\n/**\n * Controller for creating and managing the life cycle of user operations.\n */\nexport class UserOperationController extends BaseController<\n typeof controllerName,\n UserOperationControllerState,\n UserOperationControllerMessenger\n> {\n hub: UserOperationControllerEventEmitter;\n\n readonly #entrypoint: string;\n\n readonly #getGasFeeEstimates: () => Promise<GasFeeState>;\n\n readonly #pendingUserOperationTracker: PendingUserOperationTracker;\n\n /**\n * Construct a UserOperationController instance.\n *\n * @param options - Controller options.\n * @param options.entrypoint - Address of the entrypoint contract.\n * @param options.getGasFeeEstimates - Callback to get gas fee estimates.\n * @param options.messenger - Restricted messenger for the user operation controller.\n * @param options.state - Initial state to set on the controller.\n */\n constructor({\n entrypoint,\n getGasFeeEstimates,\n messenger,\n state,\n }: UserOperationControllerOptions) {\n super({\n name: controllerName,\n metadata: stateMetadata,\n messenger,\n state: { ...getDefaultState(), ...state },\n });\n\n this.hub = new EventEmitter() as UserOperationControllerEventEmitter;\n\n this.messenger.registerMethodActionHandlers(\n this,\n MESSENGER_EXPOSED_METHODS,\n );\n\n this.#entrypoint = entrypoint;\n this.#getGasFeeEstimates = getGasFeeEstimates;\n\n this.#pendingUserOperationTracker = new PendingUserOperationTracker({\n getUserOperations: () =>\n cloneDeep(Object.values(this.state.userOperations)),\n messenger,\n });\n\n this.#addPendingUserOperationTrackerListeners();\n }\n\n /**\n * Create and submit a user operation.\n *\n * @param request - Information required to create a user operation.\n * @param request.data - Data to include in the resulting transaction.\n * @param request.maxFeePerGas - Maximum fee per gas to pay towards the transaction.\n * @param request.maxPriorityFeePerGas - Maximum priority fee per gas to pay towards the transaction.\n * @param request.to - Destination address of the resulting transaction.\n * @param request.value - Value to include in the resulting transaction.\n * @param options - Configuration options when creating a user operation.\n * @param options.networkClientId - ID of the network client used to query the chain.\n * @param options.origin - Origin of the user operation, such as the hostname of a dApp.\n * @param options.requireApproval - Whether to require user approval before submitting the user operation. Defaults to true.\n * @param options.smartContractAccount - Smart contract abstraction to provide the contract specific values such as call data and nonce. Defaults to the current snap account.\n * @param options.swaps - Swap metadata to record with the user operation.\n * @param options.type - Type of the transaction.\n */\n async addUserOperation(\n request: AddUserOperationRequest,\n options: AddUserOperationOptions,\n ): Promise<AddUserOperationResponse> {\n validateAddUserOperationRequest(request);\n validateAddUserOperationOptions(options);\n\n return await this.#addUserOperation(request, options);\n }\n\n /**\n * Create and submit a user operation equivalent to the provided transaction.\n *\n * @param transaction - Transaction to use as the basis for the user operation.\n * @param options - Configuration options when creating a user operation.\n * @param options.networkClientId - ID of the network client used to query the chain.\n * @param options.origin - Origin of the user operation, such as the hostname of a dApp.\n * @param options.requireApproval - Whether to require user approval before submitting the user operation. Defaults to true.\n * @param options.smartContractAccount - Smart contract abstraction to provide the contract specific values such as call data and nonce. Defaults to the current snap account.\n * @param options.swaps - Swap metadata to record with the user operation.\n * @param options.type - Type of the transaction.\n */\n async addUserOperationFromTransaction(\n transaction: TransactionParams,\n options: AddUserOperationOptions,\n ): Promise<AddUserOperationResponse> {\n validateAddUserOperationOptions(options);\n\n const { data, from, maxFeePerGas, maxPriorityFeePerGas, to, value } =\n transaction;\n\n const request: AddUserOperationRequest = {\n data: data === '' ? undefined : data,\n from,\n maxFeePerGas,\n maxPriorityFeePerGas,\n to,\n value,\n };\n\n validateAddUserOperationRequest(request);\n\n return await this.#addUserOperation(request, { ...options, transaction });\n }\n\n /**\n * Starts polling for pending user operations on the given network.\n *\n * @param networkClientId - The ID of the network client to poll.\n * @returns The polling token that can be used to stop polling.\n */\n startPollingByNetworkClientId(networkClientId: string): string {\n return this.#pendingUserOperationTracker.startPolling({\n networkClientId,\n });\n }\n\n async #addUserOperation(\n request: AddUserOperationRequest,\n options: AddUserOperationOptions & { transaction?: TransactionParams },\n ): Promise<AddUserOperationResponse> {\n log('Adding user operation', { request, options });\n\n const {\n networkClientId,\n origin,\n smartContractAccount: requestSmartContractAccount,\n swaps,\n transaction,\n } = options;\n\n const { chainId, provider } = await this.#getProvider(networkClientId);\n\n const metadata = await this.#createMetadata(\n chainId,\n origin,\n transaction,\n swaps,\n );\n\n const smartContractAccount =\n requestSmartContractAccount ??\n new SnapSmartContractAccount(this.messenger);\n\n const cache: UserOperationCache = {\n chainId,\n metadata,\n options: { ...options, smartContractAccount },\n provider,\n request,\n transaction,\n };\n\n const { id } = metadata;\n let throwError = false;\n\n const hashValue = (async () => {\n try {\n return await this.#prepareAndSubmitUserOperation(cache);\n } catch (error) {\n this.#failUserOperation(metadata, error);\n\n if (throwError) {\n throw error;\n }\n\n return undefined;\n }\n })();\n\n const hash = async () => {\n throwError = true;\n return await hashValue;\n };\n\n const transactionHash = async () => {\n await hash();\n\n const { transactionHash: finalTransactionHash } =\n await this.#waitForConfirmation(metadata);\n\n return finalTransactionHash as string;\n };\n\n return {\n id,\n hash,\n transactionHash,\n };\n }\n\n async #prepareAndSubmitUserOperation(cache: UserOperationCache) {\n const { metadata, options } = cache;\n const { requireApproval, smartContractAccount } = options;\n let resultCallbacks: AcceptResultCallbacks | undefined;\n\n try {\n await this.#prepareUserOperation(cache);\n await this.#addPaymasterData(metadata, smartContractAccount);\n\n this.hub.emit('user-operation-added', metadata);\n\n if (requireApproval !== false) {\n resultCallbacks = await this.#approveUserOperation(cache);\n }\n\n await this.#signUserOperation(metadata, smartContractAccount);\n await this.#submitUserOperation(metadata);\n\n resultCallbacks?.success();\n\n return metadata.hash as string;\n } catch (error) {\n /* istanbul ignore next */\n resultCallbacks?.error(error as Error);\n throw error;\n }\n }\n\n async #waitForConfirmation(\n metadata: UserOperationMetadata,\n ): Promise<UserOperationMetadata> {\n const { id, hash } = metadata;\n\n log('Waiting for confirmation', id, hash);\n\n return new Promise((resolve, reject) => {\n this.hub.once(`${id}:confirmed`, (finalMetadata) => {\n resolve(finalMetadata);\n });\n\n this.hub.once(`${id}:failed`, (_finalMetadata, error) => {\n reject(error);\n });\n });\n }\n\n async #createMetadata(\n chainId: string,\n origin: string,\n transaction?: TransactionParams,\n swaps?: AddUserOperationSwapOptions,\n ): Promise<UserOperationMetadata> {\n const metadata: UserOperationMetadata = {\n actualGasCost: null,\n actualGasUsed: null,\n baseFeePerGas: null,\n bundlerUrl: null,\n chainId,\n error: null,\n hash: null,\n id: random(),\n origin,\n status: UserOperationStatus.Unapproved,\n swapsMetadata: swaps\n ? {\n approvalTxId: swaps.approvalTxId ?? null,\n destinationTokenAddress: swaps.destinationTokenAddress ?? null,\n destinationTokenAmount: swaps.destinationTokenAmount ?? null,\n destinationTokenDecimals: swaps.destinationTokenDecimals ?? null,\n destinationTokenSymbol: swaps.destinationTokenSymbol ?? null,\n estimatedBaseFee: swaps.estimatedBaseFee ?? null,\n sourceTokenAddress: swaps.sourceTokenAddress ?? null,\n sourceTokenAmount: swaps.sourceTokenAmount ?? null,\n sourceTokenDecimals: swaps.sourceTokenDecimals ?? null,\n sourceTokenSymbol: swaps.sourceTokenSymbol ?? null,\n swapAndSendRecipient: swaps.swapAndSendRecipient ?? null,\n swapMetaData: (swaps.swapMetaData as Record<string, never>) ?? null,\n swapTokenValue: swaps.swapTokenValue ?? null,\n }\n : null,\n time: Date.now(),\n transactionHash: null,\n transactionParams: (transaction as Required<TransactionParams>) ?? null,\n transactionType: null,\n userFeeLevel: null,\n userOperation: this.#createEmptyUserOperation(transaction),\n };\n\n this.#updateMetadata(metadata);\n\n log('Added user operation', metadata.id);\n\n return metadata;\n }\n\n async #prepareUserOperation(cache: UserOperationCache) {\n const { chainId, metadata, options, provider, request, transaction } =\n cache;\n\n const { data, from, to, value } = request;\n const { id, transactionParams, userOperation } = metadata;\n const { smartContractAccount } = options;\n\n log('Preparing user operation', { id });\n\n const transactionType = await this.#getTransactionType(\n transaction,\n provider,\n options,\n );\n\n metadata.transactionType = transactionType ?? null;\n\n log('Determined transaction type', transactionType);\n\n await updateGasFees({\n getGasFeeEstimates: this.#getGasFeeEstimates,\n metadata,\n originalRequest: request,\n provider,\n transaction: transactionParams ?? undefined,\n });\n\n const response = await smartContractAccount.prepareUserOperation({\n chainId,\n data,\n from,\n to,\n value,\n });\n\n validatePrepareUserOperationResponse(response);\n\n const {\n bundler: bundlerUrl,\n callData,\n dummyPaymasterAndData,\n dummySignature,\n initCode,\n nonce,\n sender,\n } = response;\n\n userOperation.callData = callData;\n userOperation.initCode = initCode ?? EMPTY_BYTES;\n userOperation.nonce = nonce;\n userOperation.paymasterAndData = dummyPaymasterAndData ?? EMPTY_BYTES;\n userOperation.sender = sender;\n userOperation.signature = dummySignature ?? EMPTY_BYTES;\n\n metadata.bundlerUrl = bundlerUrl;\n\n await updateGas(metadata, response, this.#entrypoint);\n\n this.#updateMetadata(metadata);\n }\n\n async #addPaymasterData(\n metadata: UserOperationMetadata,\n smartContractAccount: SmartContractAccount,\n ) {\n const { id, userOperation, chainId } = metadata;\n\n log('Requesting paymaster data', { id });\n\n const response = await smartContractAccount.updateUserOperation({\n userOperation,\n chainId,\n });\n\n validateUpdateUserOperationResponse(response);\n\n userOperation.paymasterAndData = response.paymasterAndData ?? EMPTY_BYTES;\n if (response.callGasLimit) {\n userOperation.callGasLimit = response.callGasLimit;\n }\n if (response.preVerificationGas) {\n userOperation.preVerificationGas = response.preVerificationGas;\n }\n if (response.verificationGasLimit) {\n userOperation.verificationGasLimit = response.verificationGasLimit;\n }\n\n this.#updateMetadata(metadata);\n }\n\n async #approveUserOperation(cache: UserOperationCache) {\n log('Requesting approval');\n\n const { metadata } = cache;\n\n const { resultCallbacks, value } = await this.#requestApproval(metadata);\n const updatedTransaction = value?.txMeta;\n\n if (updatedTransaction) {\n await this.#updateUserOperationAfterApproval(cache, updatedTransaction);\n }\n\n metadata.status = UserOperationStatus.Approved;\n\n this.#updateMetadata(metadata);\n\n return resultCallbacks;\n }\n\n async #signUserOperation(\n metadata: UserOperationMetadata,\n smartContractAccount: SmartContractAccount,\n ) {\n const { id, chainId, userOperation } = metadata;\n\n log('Signing user operation', id, userOperation);\n\n const response = await smartContractAccount.signUserOperation({\n userOperation,\n chainId,\n });\n\n validateSignUserOperationResponse(response);\n\n const { signature } = response;\n\n userOperation.signature = signature;\n\n log('Signed user operation', signature);\n\n metadata.status = UserOperationStatus.Signed;\n\n this.#updateMetadata(metadata);\n }\n\n async #submitUserOperation(metadata: UserOperationMetadata) {\n const { userOperation } = metadata;\n\n log('Submitting user operation', userOperation);\n\n const bundler = new Bundler(metadata.bundlerUrl as string);\n\n const hash = await bundler.sendUserOperation(\n userOperation,\n this.#entrypoint,\n );\n\n metadata.hash = hash;\n metadata.status = UserOperationStatus.Submitted;\n\n this.#updateMetadata(metadata);\n }\n\n #failUserOperation(metadata: UserOperationMetadata, error: unknown) {\n const { id } = metadata;\n const rawError = error as Record<string, string>;\n\n log('User operation failed', id, error);\n\n metadata.error = {\n name: rawError.name,\n message: rawError.message,\n stack: rawError.stack,\n code: rawError.code,\n rpc: rawError.value,\n };\n\n metadata.status = UserOperationStatus.Failed;\n\n this.#updateMetadata(metadata);\n\n if (\n String(rawError.code) === String(errorCodes.provider.userRejectedRequest)\n ) {\n this.#deleteMetadata(id);\n }\n }\n\n #createEmptyUserOperation(transaction?: TransactionParams): UserOperation {\n return {\n callData: EMPTY_BYTES,\n callGasLimit: EMPTY_BYTES,\n initCode: EMPTY_BYTES,\n maxFeePerGas: transaction?.maxFeePerGas ?? EMPTY_BYTES,\n maxPriorityFeePerGas: transaction?.maxPriorityFeePerGas ?? EMPTY_BYTES,\n nonce: EMPTY_BYTES,\n paymasterAndData: EMPTY_BYTES,\n preVerificationGas: EMPTY_BYTES,\n sender: ADDRESS_ZERO,\n signature: EMPTY_BYTES,\n verificationGasLimit: EMPTY_BYTES,\n };\n }\n\n #updateMetadata(metadata: UserOperationMetadata) {\n const { id } = metadata;\n\n this.update((state) => {\n state.userOperations[id] = cloneDeep(metadata);\n });\n\n this.#updateTransaction(metadata);\n }\n\n #deleteMetadata(id: string) {\n this.update((state) => {\n delete state.userOperations[id];\n });\n }\n\n #updateTransaction(metadata: UserOperationMetadata) {\n if (!metadata.transactionParams) {\n return;\n }\n\n const transactionMetadata = getTransactionMetadata(metadata);\n\n this.hub.emit('transaction-updated', transactionMetadata);\n }\n\n #addPendingUserOperationTrackerListeners() {\n this.#pendingUserOperationTracker.hub.on(\n 'user-operation-confirmed',\n (metadata) => {\n log('In listener...');\n this.hub.emit('user-operation-confirmed', metadata);\n this.hub.emit(`${metadata.id}:confirmed`, metadata);\n },\n );\n\n this.#pendingUserOperationTracker.hub.on(\n 'user-operation-failed',\n (metadata, error) => {\n this.hub.emit('user-operation-failed', metadata, error);\n this.hub.emit(`${metadata.id}:failed`, metadata, error);\n },\n );\n\n this.#pendingUserOperationTracker.hub.on(\n 'user-operation-updated',\n (metadata) => {\n this.#updateMetadata(metadata);\n },\n );\n }\n\n async #requestApproval(metadata: UserOperationMetadata) {\n const { id, origin } = metadata;\n const type = ApprovalType.Transaction;\n const requestData = { txId: id };\n\n return (await this.messenger.call(\n 'ApprovalController:addRequest',\n {\n id,\n origin,\n type,\n requestData,\n expectsResult: true,\n },\n true, // Should display approval request to user\n )) as AddResult & { value?: { txMeta?: TransactionMeta } };\n }\n\n async #getTransactionType(\n transaction: TransactionParams | undefined,\n provider: Provider,\n options: AddUserOperationOptions,\n ): Promise<TransactionType | undefined> {\n if (!transaction) {\n return undefined;\n }\n\n if (options.type) {\n return options.type;\n }\n\n const ethQuery = new EthQuery(provider);\n const result = determineTransactionType(transaction, ethQuery);\n\n return (await result).type;\n }\n\n async #getProvider(\n networkClientId: string,\n ): Promise<{ provider: Provider; chainId: string }> {\n const { provider, configuration } = this.messenger.call(\n 'NetworkController:getNetworkClientById',\n networkClientId,\n );\n\n const { chainId } = configuration;\n\n return { provider, chainId };\n }\n\n async #updateUserOperationAfterApproval(\n cache: UserOperationCache,\n updatedTransaction: TransactionMeta,\n ) {\n log('Found updated transaction in approval', { updatedTransaction });\n\n const { metadata, request } = cache;\n\n const { userOperation } = metadata;\n const usingPaymaster = userOperation.paymasterAndData !== EMPTY_BYTES;\n\n const updatedMaxFeePerGas = add0x(\n updatedTransaction.txParams.maxFeePerGas as string,\n );\n\n const updatedMaxPriorityFeePerGas = add0x(\n updatedTransaction.txParams.maxPriorityFeePerGas as string,\n );\n\n let regenerateUserOperation = false;\n const previousMaxFeePerGas = userOperation.maxFeePerGas;\n const previousMaxPriorityFeePerGas = userOperation.maxPriorityFeePerGas;\n\n const gasFeesUpdated =\n previousMaxFeePerGas !== updatedMaxFeePerGas ||\n previousMaxPriorityFeePerGas !== updatedMaxPriorityFeePerGas;\n\n /**\n * true when we detect {@link getTransactionMetadata} has set the gas fees to zero\n * because the userOperation has a paymaster. This should not be mistaken for gas\n * fees being updated during the approval process.\n */\n const areGasFeesZeroBecauseOfPaymaster =\n usingPaymaster &&\n updatedMaxFeePerGas === VALUE_ZERO &&\n updatedMaxPriorityFeePerGas === VALUE_ZERO;\n\n if (gasFeesUpdated && !areGasFeesZeroBecauseOfPaymaster) {\n log('Gas fees updated during approval', {\n previousMaxFeePerGas,\n previousMaxPriorityFeePerGas,\n updatedMaxFeePerGas,\n updatedMaxPriorityFeePerGas,\n });\n\n userOperation.maxFeePerGas = updatedMaxFeePerGas;\n userOperation.maxPriorityFeePerGas = updatedMaxPriorityFeePerGas;\n\n regenerateUserOperation = usingPaymaster;\n }\n\n const previousData = request.data ?? EMPTY_BYTES;\n const updatedData = updatedTransaction.txParams.data ?? EMPTY_BYTES;\n\n if (previousData !== updatedData) {\n log('Data updated during approval', { previousData, updatedData });\n regenerateUserOperation = true;\n }\n\n const previousValue = request.value ?? VALUE_ZERO;\n const updatedValue = updatedTransaction.txParams.value ?? VALUE_ZERO;\n\n if (previousValue !== updatedValue) {\n log('Value updated during approval', { previousValue, updatedValue });\n regenerateUserOperation = true;\n }\n\n if (regenerateUserOperation) {\n const updatedRequest = {\n ...request,\n data: updatedData,\n maxFeePerGas: updatedMaxFeePerGas,\n maxPriorityFeePerGas: updatedMaxPriorityFeePerGas,\n value: updatedValue,\n };\n\n await this.#regenerateUserOperation({\n ...cache,\n request: updatedRequest,\n });\n }\n }\n\n async #regenerateUserOperation(cache: UserOperationCache) {\n log(\n 'Regenerating user operation as parameters were updated during approval',\n );\n\n const {\n options: { smartContractAccount },\n metadata,\n } = cache;\n\n await this.#prepareUserOperation(cache);\n await this.#addPaymasterData(metadata, smartContractAccount);\n\n log('Regenerated user operation', metadata.userOperation);\n }\n}\n"]}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/// <reference types="node" />
|
|
2
|
-
import type {
|
|
2
|
+
import type { ApprovalControllerAddRequestAction } from "@metamask/approval-controller";
|
|
3
3
|
import { BaseController } from "@metamask/base-controller";
|
|
4
4
|
import type { ControllerGetStateAction, ControllerStateChangeEvent } from "@metamask/base-controller";
|
|
5
5
|
import type { GasFeeState } from "@metamask/gas-fee-controller";
|
|
@@ -9,6 +9,7 @@ import type { NetworkControllerGetNetworkClientByIdAction } from "@metamask/netw
|
|
|
9
9
|
import type { TransactionMeta, TransactionParams, TransactionType } from "@metamask/transaction-controller";
|
|
10
10
|
import EventEmitter from "events";
|
|
11
11
|
import type { SmartContractAccount, UserOperationMetadata } from "./types.cjs";
|
|
12
|
+
import type { UserOperationControllerMethodActions } from "./UserOperationController-method-action-types.cjs";
|
|
12
13
|
declare const controllerName = "UserOperationController";
|
|
13
14
|
type Events = {
|
|
14
15
|
'transaction-updated': [metadata: TransactionMeta];
|
|
@@ -28,7 +29,7 @@ export type UserOperationControllerState = {
|
|
|
28
29
|
};
|
|
29
30
|
export type GetUserOperationState = ControllerGetStateAction<typeof controllerName, UserOperationControllerState>;
|
|
30
31
|
export type UserOperationStateChange = ControllerStateChangeEvent<typeof controllerName, UserOperationControllerState>;
|
|
31
|
-
export type UserOperationControllerActions = GetUserOperationState | NetworkControllerGetNetworkClientByIdAction |
|
|
32
|
+
export type UserOperationControllerActions = GetUserOperationState | UserOperationControllerMethodActions | NetworkControllerGetNetworkClientByIdAction | ApprovalControllerAddRequestAction | KeyringControllerPrepareUserOperationAction | KeyringControllerPatchUserOperationAction | KeyringControllerSignUserOperationAction;
|
|
32
33
|
export type UserOperationControllerEvents = UserOperationStateChange;
|
|
33
34
|
export type UserOperationControllerMessenger = Messenger<typeof controllerName, UserOperationControllerActions, UserOperationControllerEvents>;
|
|
34
35
|
export type UserOperationControllerOptions = {
|
|
@@ -121,6 +122,12 @@ export declare class UserOperationController extends BaseController<typeof contr
|
|
|
121
122
|
* @param options.type - Type of the transaction.
|
|
122
123
|
*/
|
|
123
124
|
addUserOperationFromTransaction(transaction: TransactionParams, options: AddUserOperationOptions): Promise<AddUserOperationResponse>;
|
|
125
|
+
/**
|
|
126
|
+
* Starts polling for pending user operations on the given network.
|
|
127
|
+
*
|
|
128
|
+
* @param networkClientId - The ID of the network client to poll.
|
|
129
|
+
* @returns The polling token that can be used to stop polling.
|
|
130
|
+
*/
|
|
124
131
|
startPollingByNetworkClientId(networkClientId: string): string;
|
|
125
132
|
}
|
|
126
133
|
export {};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"UserOperationController.d.cts","sourceRoot":"","sources":["../src/UserOperationController.ts"],"names":[],"mappings":";AAAA,OAAO,KAAK,EAEV,
|
|
1
|
+
{"version":3,"file":"UserOperationController.d.cts","sourceRoot":"","sources":["../src/UserOperationController.ts"],"names":[],"mappings":";AAAA,OAAO,KAAK,EAEV,kCAAkC,EAEnC,sCAAsC;AACvC,OAAO,EAAE,cAAc,EAAE,kCAAkC;AAC3D,OAAO,KAAK,EACV,wBAAwB,EACxB,0BAA0B,EAC3B,kCAAkC;AA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CAAgC,CACjC;;IACC,GAAG,EAAE,mCAAmC,CAAC;IAQzC;;;;;;;;OAQG;gBACS,EACV,UAAU,EACV,kBAAkB,EAClB,SAAS,EACT,KAAK,GACN,EAAE,8BAA8B;IA2BjC;;;;;;;;;;;;;;;;OAgBG;IACG,gBAAgB,CACpB,OAAO,EAAE,uBAAuB,EAChC,OAAO,EAAE,uBAAuB,GAC/B,OAAO,CAAC,wBAAwB,CAAC;IAOpC;;;;;;;;;;;OAWG;IACG,+BAA+B,CACnC,WAAW,EAAE,iBAAiB,EAC9B,OAAO,EAAE,uBAAuB,GAC/B,OAAO,CAAC,wBAAwB,CAAC;IAoBpC;;;;;OAKG;IACH,6BAA6B,CAAC,eAAe,EAAE,MAAM,GAAG,MAAM;CA0jB/D"}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/// <reference types="node" />
|
|
2
|
-
import type {
|
|
2
|
+
import type { ApprovalControllerAddRequestAction } from "@metamask/approval-controller";
|
|
3
3
|
import { BaseController } from "@metamask/base-controller";
|
|
4
4
|
import type { ControllerGetStateAction, ControllerStateChangeEvent } from "@metamask/base-controller";
|
|
5
5
|
import type { GasFeeState } from "@metamask/gas-fee-controller";
|
|
@@ -9,6 +9,7 @@ import type { NetworkControllerGetNetworkClientByIdAction } from "@metamask/netw
|
|
|
9
9
|
import type { TransactionMeta, TransactionParams, TransactionType } from "@metamask/transaction-controller";
|
|
10
10
|
import EventEmitter from "events";
|
|
11
11
|
import type { SmartContractAccount, UserOperationMetadata } from "./types.mjs";
|
|
12
|
+
import type { UserOperationControllerMethodActions } from "./UserOperationController-method-action-types.mjs";
|
|
12
13
|
declare const controllerName = "UserOperationController";
|
|
13
14
|
type Events = {
|
|
14
15
|
'transaction-updated': [metadata: TransactionMeta];
|
|
@@ -28,7 +29,7 @@ export type UserOperationControllerState = {
|
|
|
28
29
|
};
|
|
29
30
|
export type GetUserOperationState = ControllerGetStateAction<typeof controllerName, UserOperationControllerState>;
|
|
30
31
|
export type UserOperationStateChange = ControllerStateChangeEvent<typeof controllerName, UserOperationControllerState>;
|
|
31
|
-
export type UserOperationControllerActions = GetUserOperationState | NetworkControllerGetNetworkClientByIdAction |
|
|
32
|
+
export type UserOperationControllerActions = GetUserOperationState | UserOperationControllerMethodActions | NetworkControllerGetNetworkClientByIdAction | ApprovalControllerAddRequestAction | KeyringControllerPrepareUserOperationAction | KeyringControllerPatchUserOperationAction | KeyringControllerSignUserOperationAction;
|
|
32
33
|
export type UserOperationControllerEvents = UserOperationStateChange;
|
|
33
34
|
export type UserOperationControllerMessenger = Messenger<typeof controllerName, UserOperationControllerActions, UserOperationControllerEvents>;
|
|
34
35
|
export type UserOperationControllerOptions = {
|
|
@@ -121,6 +122,12 @@ export declare class UserOperationController extends BaseController<typeof contr
|
|
|
121
122
|
* @param options.type - Type of the transaction.
|
|
122
123
|
*/
|
|
123
124
|
addUserOperationFromTransaction(transaction: TransactionParams, options: AddUserOperationOptions): Promise<AddUserOperationResponse>;
|
|
125
|
+
/**
|
|
126
|
+
* Starts polling for pending user operations on the given network.
|
|
127
|
+
*
|
|
128
|
+
* @param networkClientId - The ID of the network client to poll.
|
|
129
|
+
* @returns The polling token that can be used to stop polling.
|
|
130
|
+
*/
|
|
124
131
|
startPollingByNetworkClientId(networkClientId: string): string;
|
|
125
132
|
}
|
|
126
133
|
export {};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"UserOperationController.d.mts","sourceRoot":"","sources":["../src/UserOperationController.ts"],"names":[],"mappings":";AAAA,OAAO,KAAK,EAEV,
|
|
1
|
+
{"version":3,"file":"UserOperationController.d.mts","sourceRoot":"","sources":["../src/UserOperationController.ts"],"names":[],"mappings":";AAAA,OAAO,KAAK,EAEV,kCAAkC,EAEnC,sCAAsC;AACvC,OAAO,EAAE,cAAc,EAAE,kCAAkC;AAC3D,OAAO,KAAK,EACV,wBAAwB,EACxB,0BAA0B,EAC3B,kCAAkC;AAGnC,OAAO,KAAK,EAAE,WAAW,EAAE,q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mC,CAAC;IAQzC;;;;;;;;OAQG;gBACS,EACV,UAAU,EACV,kBAAkB,EAClB,SAAS,EACT,KAAK,GACN,EAAE,8BAA8B;IA2BjC;;;;;;;;;;;;;;;;OAgBG;IACG,gBAAgB,CACpB,OAAO,EAAE,uBAAuB,EAChC,OAAO,EAAE,uBAAuB,GAC/B,OAAO,CAAC,wBAAwB,CAAC;IAOpC;;;;;;;;;;;OAWG;IACG,+BAA+B,CACnC,WAAW,EAAE,iBAAiB,EAC9B,OAAO,EAAE,uBAAuB,GAC/B,OAAO,CAAC,wBAAwB,CAAC;IAoBpC;;;;;OAKG;IACH,6BAA6B,CAAC,eAAe,EAAE,MAAM,GAAG,MAAM;CA0jB/D"}
|
|
@@ -40,6 +40,11 @@ import { updateGasFees } from "./utils/gas-fees.mjs";
|
|
|
40
40
|
import { getTransactionMetadata } from "./utils/transaction.mjs";
|
|
41
41
|
import { validateAddUserOperationOptions, validateAddUserOperationRequest, validatePrepareUserOperationResponse, validateSignUserOperationResponse, validateUpdateUserOperationResponse } from "./utils/validation.mjs";
|
|
42
42
|
const controllerName = 'UserOperationController';
|
|
43
|
+
const MESSENGER_EXPOSED_METHODS = [
|
|
44
|
+
'addUserOperation',
|
|
45
|
+
'addUserOperationFromTransaction',
|
|
46
|
+
'startPollingByNetworkClientId',
|
|
47
|
+
];
|
|
43
48
|
const stateMetadata = {
|
|
44
49
|
userOperations: {
|
|
45
50
|
includeInStateLogs: true,
|
|
@@ -76,6 +81,7 @@ export class UserOperationController extends BaseController {
|
|
|
76
81
|
_UserOperationController_getGasFeeEstimates.set(this, void 0);
|
|
77
82
|
_UserOperationController_pendingUserOperationTracker.set(this, void 0);
|
|
78
83
|
this.hub = new EventEmitter();
|
|
84
|
+
this.messenger.registerMethodActionHandlers(this, MESSENGER_EXPOSED_METHODS);
|
|
79
85
|
__classPrivateFieldSet(this, _UserOperationController_entrypoint, entrypoint, "f");
|
|
80
86
|
__classPrivateFieldSet(this, _UserOperationController_getGasFeeEstimates, getGasFeeEstimates, "f");
|
|
81
87
|
__classPrivateFieldSet(this, _UserOperationController_pendingUserOperationTracker, new PendingUserOperationTracker({
|
|
@@ -132,6 +138,12 @@ export class UserOperationController extends BaseController {
|
|
|
132
138
|
validateAddUserOperationRequest(request);
|
|
133
139
|
return await __classPrivateFieldGet(this, _UserOperationController_instances, "m", _UserOperationController_addUserOperation).call(this, request, { ...options, transaction });
|
|
134
140
|
}
|
|
141
|
+
/**
|
|
142
|
+
* Starts polling for pending user operations on the given network.
|
|
143
|
+
*
|
|
144
|
+
* @param networkClientId - The ID of the network client to poll.
|
|
145
|
+
* @returns The polling token that can be used to stop polling.
|
|
146
|
+
*/
|
|
135
147
|
startPollingByNetworkClientId(networkClientId) {
|
|
136
148
|
return __classPrivateFieldGet(this, _UserOperationController_pendingUserOperationTracker, "f").startPolling({
|
|
137
149
|
networkClientId,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"UserOperationController.mjs","sourceRoot":"","sources":["../src/UserOperationController.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;AAKA,OAAO,EAAE,cAAc,EAAE,kCAAkC;AAK3D,OAAO,EAAE,YAAY,EAAE,mCAAmC;AAC1D,OAAO,SAAQ,4BAA4B;;AAY3C,OAAO,EAAE,UAAU,EAAE,6BAA6B;AAClD,OAAO,EAAE,wBAAwB,EAAE,yCAAyC;AAM5E,OAAO,EAAE,KAAK,EAAE,wBAAwB;AACxC,kEAAkE;AAClE,sDAAsD;AACtD,OAAO,YAAY,eAAe;;;AAElC,OAAO,EAAE,EAAE,IAAI,MAAM,EAAE,aAAa;AAEpC,OAAO,EAAE,YAAY,EAAE,WAAW,EAAE,UAAU,EAAE,wBAAoB;AACpE,OAAO,EAAE,OAAO,EAAE,8BAA0B;AAC5C,OAAO,EAAE,2BAA2B,EAAE,kDAA8C;AACpF,OAAO,EAAE,wBAAwB,EAAE,+CAA2C;AAC9E,OAAO,EAAE,aAAa,IAAI,GAAG,EAAE,qBA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n} from '@metamask/approval-controller';\nimport { BaseController } from '@metamask/base-controller';\nimport type {\n ControllerGetStateAction,\n ControllerStateChangeEvent,\n} from '@metamask/base-controller';\nimport { ApprovalType } from '@metamask/controller-utils';\nimport EthQuery from '@metamask/eth-query';\nimport type { GasFeeState } from '@metamask/gas-fee-controller';\nimport type {\n KeyringControllerPrepareUserOperationAction,\n KeyringControllerPatchUserOperationAction,\n KeyringControllerSignUserOperationAction,\n} from '@metamask/keyring-controller';\nimport type { Messenger } from '@metamask/messenger';\nimport type {\n NetworkControllerGetNetworkClientByIdAction,\n Provider,\n} from '@metamask/network-controller';\nimport { errorCodes } from '@metamask/rpc-errors';\nimport { determineTransactionType } from '@metamask/transaction-controller';\nimport type {\n TransactionMeta,\n TransactionParams,\n TransactionType,\n} from '@metamask/transaction-controller';\nimport { add0x } from '@metamask/utils';\n// This package purposefully relies on Node's EventEmitter module.\n// eslint-disable-next-line import-x/no-nodejs-modules\nimport EventEmitter from 'events';\nimport { cloneDeep } from 'lodash';\nimport { v1 as random } from 'uuid';\n\nimport { ADDRESS_ZERO, EMPTY_BYTES, VALUE_ZERO } from './constants';\nimport { Bundler } from './helpers/Bundler';\nimport { PendingUserOperationTracker } from './helpers/PendingUserOperationTracker';\nimport { SnapSmartContractAccount } from './helpers/SnapSmartContractAccount';\nimport { projectLogger as log } from './logger';\nimport type {\n SmartContractAccount,\n UserOperation,\n UserOperationMetadata,\n} from './types';\nimport { UserOperationStatus } from './types';\nimport { updateGas } from './utils/gas';\nimport { updateGasFees } from './utils/gas-fees';\nimport { getTransactionMetadata } from './utils/transaction';\nimport {\n validateAddUserOperationOptions,\n validateAddUserOperationRequest,\n validatePrepareUserOperationResponse,\n validateSignUserOperationResponse,\n validateUpdateUserOperationResponse,\n} from './utils/validation';\n\nconst controllerName = 'UserOperationController';\n\nconst stateMetadata = {\n userOperations: {\n includeInStateLogs: true,\n persist: true,\n includeInDebugSnapshot: false,\n usedInUi: true,\n },\n};\n\nconst getDefaultState = () => ({\n userOperations: {},\n});\n\ntype Events = {\n 'transaction-updated': [metadata: TransactionMeta];\n 'user-operation-added': [metadata: UserOperationMetadata];\n 'user-operation-confirmed': [metadata: UserOperationMetadata];\n 'user-operation-failed': [metadata: UserOperationMetadata, error: Error];\n [key: `${string}:confirmed`]: [metadata: UserOperationMetadata];\n [key: `${string}:failed`]: [metadata: UserOperationMetadata, error: Error];\n};\n\nexport type UserOperationControllerEventEmitter = EventEmitter & {\n on<T extends keyof Events>(\n eventName: T,\n listener: (...args: Events[T]) => void,\n ): UserOperationControllerEventEmitter;\n\n once<T extends keyof Events>(\n eventName: T,\n listener: (...args: Events[T]) => void,\n ): UserOperationControllerEventEmitter;\n\n emit<T extends keyof Events>(eventName: T, ...args: Events[T]): boolean;\n};\n\nexport type UserOperationControllerState = {\n userOperations: Record<string, UserOperationMetadata>;\n};\n\nexport type GetUserOperationState = ControllerGetStateAction<\n typeof controllerName,\n UserOperationControllerState\n>;\n\nexport type UserOperationStateChange = ControllerStateChangeEvent<\n typeof controllerName,\n UserOperationControllerState\n>;\n\nexport type UserOperationControllerActions =\n | GetUserOperationState\n | NetworkControllerGetNetworkClientByIdAction\n | AddApprovalRequest\n | KeyringControllerPrepareUserOperationAction\n | KeyringControllerPatchUserOperationAction\n | KeyringControllerSignUserOperationAction;\n\nexport type UserOperationControllerEvents = UserOperationStateChange;\n\nexport type UserOperationControllerMessenger = Messenger<\n typeof controllerName,\n UserOperationControllerActions,\n UserOperationControllerEvents\n>;\n\nexport type UserOperationControllerOptions = {\n entrypoint: string;\n getGasFeeEstimates: () => Promise<GasFeeState>;\n interval?: number;\n messenger: UserOperationControllerMessenger;\n state?: Partial<UserOperationControllerState>;\n};\n\nexport type AddUserOperationRequest = {\n data?: string;\n from: string;\n maxFeePerGas?: string;\n maxPriorityFeePerGas?: string;\n to?: string;\n value?: string;\n};\n\nexport type AddUserOperationSwapOptions = {\n approvalTxId?: string;\n destinationTokenAddress?: string;\n destinationTokenAmount?: string;\n destinationTokenDecimals?: number;\n destinationTokenSymbol?: string;\n estimatedBaseFee?: string;\n sourceTokenAddress?: string;\n sourceTokenAmount?: string;\n sourceTokenDecimals?: number;\n sourceTokenSymbol?: string;\n swapAndSendRecipient?: string;\n swapMetaData?: Record<string, unknown>;\n swapTokenValue?: string;\n};\n\nexport type AddUserOperationOptions = {\n networkClientId: string;\n origin: string;\n requireApproval?: boolean;\n smartContractAccount?: SmartContractAccount;\n swaps?: AddUserOperationSwapOptions;\n type?: TransactionType;\n};\n\nexport type AddUserOperationResponse = {\n id: string;\n hash: () => Promise<string | undefined>;\n transactionHash: () => Promise<string | undefined>;\n};\n\n/**\n * All the objects related to a pending user operation in order to:\n * - Avoid duplicated effort to derive the same properties.\n * - Minimise duplicate arguments in private methods.\n */\ntype UserOperationCache = {\n chainId: string;\n metadata: UserOperationMetadata;\n options: AddUserOperationOptions & {\n smartContractAccount: SmartContractAccount;\n };\n provider: Provider;\n request: AddUserOperationRequest;\n transaction?: TransactionParams;\n};\n\n/**\n * Controller for creating and managing the life cycle of user operations.\n */\nexport class UserOperationController extends BaseController<\n typeof controllerName,\n UserOperationControllerState,\n UserOperationControllerMessenger\n> {\n hub: UserOperationControllerEventEmitter;\n\n readonly #entrypoint: string;\n\n readonly #getGasFeeEstimates: () => Promise<GasFeeState>;\n\n readonly #pendingUserOperationTracker: PendingUserOperationTracker;\n\n /**\n * Construct a UserOperationController instance.\n *\n * @param options - Controller options.\n * @param options.entrypoint - Address of the entrypoint contract.\n * @param options.getGasFeeEstimates - Callback to get gas fee estimates.\n * @param options.messenger - Restricted messenger for the user operation controller.\n * @param options.state - Initial state to set on the controller.\n */\n constructor({\n entrypoint,\n getGasFeeEstimates,\n messenger,\n state,\n }: UserOperationControllerOptions) {\n super({\n name: controllerName,\n metadata: stateMetadata,\n messenger,\n state: { ...getDefaultState(), ...state },\n });\n\n this.hub = new EventEmitter() as UserOperationControllerEventEmitter;\n\n this.#entrypoint = entrypoint;\n this.#getGasFeeEstimates = getGasFeeEstimates;\n\n this.#pendingUserOperationTracker = new PendingUserOperationTracker({\n getUserOperations: () =>\n cloneDeep(Object.values(this.state.userOperations)),\n messenger,\n });\n\n this.#addPendingUserOperationTrackerListeners();\n }\n\n /**\n * Create and submit a user operation.\n *\n * @param request - Information required to create a user operation.\n * @param request.data - Data to include in the resulting transaction.\n * @param request.maxFeePerGas - Maximum fee per gas to pay towards the transaction.\n * @param request.maxPriorityFeePerGas - Maximum priority fee per gas to pay towards the transaction.\n * @param request.to - Destination address of the resulting transaction.\n * @param request.value - Value to include in the resulting transaction.\n * @param options - Configuration options when creating a user operation.\n * @param options.networkClientId - ID of the network client used to query the chain.\n * @param options.origin - Origin of the user operation, such as the hostname of a dApp.\n * @param options.requireApproval - Whether to require user approval before submitting the user operation. Defaults to true.\n * @param options.smartContractAccount - Smart contract abstraction to provide the contract specific values such as call data and nonce. Defaults to the current snap account.\n * @param options.swaps - Swap metadata to record with the user operation.\n * @param options.type - Type of the transaction.\n */\n async addUserOperation(\n request: AddUserOperationRequest,\n options: AddUserOperationOptions,\n ): Promise<AddUserOperationResponse> {\n validateAddUserOperationRequest(request);\n validateAddUserOperationOptions(options);\n\n return await this.#addUserOperation(request, options);\n }\n\n /**\n * Create and submit a user operation equivalent to the provided transaction.\n *\n * @param transaction - Transaction to use as the basis for the user operation.\n * @param options - Configuration options when creating a user operation.\n * @param options.networkClientId - ID of the network client used to query the chain.\n * @param options.origin - Origin of the user operation, such as the hostname of a dApp.\n * @param options.requireApproval - Whether to require user approval before submitting the user operation. Defaults to true.\n * @param options.smartContractAccount - Smart contract abstraction to provide the contract specific values such as call data and nonce. Defaults to the current snap account.\n * @param options.swaps - Swap metadata to record with the user operation.\n * @param options.type - Type of the transaction.\n */\n async addUserOperationFromTransaction(\n transaction: TransactionParams,\n options: AddUserOperationOptions,\n ): Promise<AddUserOperationResponse> {\n validateAddUserOperationOptions(options);\n\n const { data, from, maxFeePerGas, maxPriorityFeePerGas, to, value } =\n transaction;\n\n const request: AddUserOperationRequest = {\n data: data === '' ? undefined : data,\n from,\n maxFeePerGas,\n maxPriorityFeePerGas,\n to,\n value,\n };\n\n validateAddUserOperationRequest(request);\n\n return await this.#addUserOperation(request, { ...options, transaction });\n }\n\n startPollingByNetworkClientId(networkClientId: string): string {\n return this.#pendingUserOperationTracker.startPolling({\n networkClientId,\n });\n }\n\n async #addUserOperation(\n request: AddUserOperationRequest,\n options: AddUserOperationOptions & { transaction?: TransactionParams },\n ): Promise<AddUserOperationResponse> {\n log('Adding user operation', { request, options });\n\n const {\n networkClientId,\n origin,\n smartContractAccount: requestSmartContractAccount,\n swaps,\n transaction,\n } = options;\n\n const { chainId, provider } = await this.#getProvider(networkClientId);\n\n const metadata = await this.#createMetadata(\n chainId,\n origin,\n transaction,\n swaps,\n );\n\n const smartContractAccount =\n requestSmartContractAccount ??\n new SnapSmartContractAccount(this.messenger);\n\n const cache: UserOperationCache = {\n chainId,\n metadata,\n options: { ...options, smartContractAccount },\n provider,\n request,\n transaction,\n };\n\n const { id } = metadata;\n let throwError = false;\n\n const hashValue = (async () => {\n try {\n return await this.#prepareAndSubmitUserOperation(cache);\n } catch (error) {\n this.#failUserOperation(metadata, error);\n\n if (throwError) {\n throw error;\n }\n\n return undefined;\n }\n })();\n\n const hash = async () => {\n throwError = true;\n return await hashValue;\n };\n\n const transactionHash = async () => {\n await hash();\n\n const { transactionHash: finalTransactionHash } =\n await this.#waitForConfirmation(metadata);\n\n return finalTransactionHash as string;\n };\n\n return {\n id,\n hash,\n transactionHash,\n };\n }\n\n async #prepareAndSubmitUserOperation(cache: UserOperationCache) {\n const { metadata, options } = cache;\n const { requireApproval, smartContractAccount } = options;\n let resultCallbacks: AcceptResultCallbacks | undefined;\n\n try {\n await this.#prepareUserOperation(cache);\n await this.#addPaymasterData(metadata, smartContractAccount);\n\n this.hub.emit('user-operation-added', metadata);\n\n if (requireApproval !== false) {\n resultCallbacks = await this.#approveUserOperation(cache);\n }\n\n await this.#signUserOperation(metadata, smartContractAccount);\n await this.#submitUserOperation(metadata);\n\n resultCallbacks?.success();\n\n return metadata.hash as string;\n } catch (error) {\n /* istanbul ignore next */\n resultCallbacks?.error(error as Error);\n throw error;\n }\n }\n\n async #waitForConfirmation(\n metadata: UserOperationMetadata,\n ): Promise<UserOperationMetadata> {\n const { id, hash } = metadata;\n\n log('Waiting for confirmation', id, hash);\n\n return new Promise((resolve, reject) => {\n this.hub.once(`${id}:confirmed`, (finalMetadata) => {\n resolve(finalMetadata);\n });\n\n this.hub.once(`${id}:failed`, (_finalMetadata, error) => {\n reject(error);\n });\n });\n }\n\n async #createMetadata(\n chainId: string,\n origin: string,\n transaction?: TransactionParams,\n swaps?: AddUserOperationSwapOptions,\n ): Promise<UserOperationMetadata> {\n const metadata: UserOperationMetadata = {\n actualGasCost: null,\n actualGasUsed: null,\n baseFeePerGas: null,\n bundlerUrl: null,\n chainId,\n error: null,\n hash: null,\n id: random(),\n origin,\n status: UserOperationStatus.Unapproved,\n swapsMetadata: swaps\n ? {\n approvalTxId: swaps.approvalTxId ?? null,\n destinationTokenAddress: swaps.destinationTokenAddress ?? null,\n destinationTokenAmount: swaps.destinationTokenAmount ?? null,\n destinationTokenDecimals: swaps.destinationTokenDecimals ?? null,\n destinationTokenSymbol: swaps.destinationTokenSymbol ?? null,\n estimatedBaseFee: swaps.estimatedBaseFee ?? null,\n sourceTokenAddress: swaps.sourceTokenAddress ?? null,\n sourceTokenAmount: swaps.sourceTokenAmount ?? null,\n sourceTokenDecimals: swaps.sourceTokenDecimals ?? null,\n sourceTokenSymbol: swaps.sourceTokenSymbol ?? null,\n swapAndSendRecipient: swaps.swapAndSendRecipient ?? null,\n swapMetaData: (swaps.swapMetaData as Record<string, never>) ?? null,\n swapTokenValue: swaps.swapTokenValue ?? null,\n }\n : null,\n time: Date.now(),\n transactionHash: null,\n transactionParams: (transaction as Required<TransactionParams>) ?? null,\n transactionType: null,\n userFeeLevel: null,\n userOperation: this.#createEmptyUserOperation(transaction),\n };\n\n this.#updateMetadata(metadata);\n\n log('Added user operation', metadata.id);\n\n return metadata;\n }\n\n async #prepareUserOperation(cache: UserOperationCache) {\n const { chainId, metadata, options, provider, request, transaction } =\n cache;\n\n const { data, from, to, value } = request;\n const { id, transactionParams, userOperation } = metadata;\n const { smartContractAccount } = options;\n\n log('Preparing user operation', { id });\n\n const transactionType = await this.#getTransactionType(\n transaction,\n provider,\n options,\n );\n\n metadata.transactionType = transactionType ?? null;\n\n log('Determined transaction type', transactionType);\n\n await updateGasFees({\n getGasFeeEstimates: this.#getGasFeeEstimates,\n metadata,\n originalRequest: request,\n provider,\n transaction: transactionParams ?? undefined,\n });\n\n const response = await smartContractAccount.prepareUserOperation({\n chainId,\n data,\n from,\n to,\n value,\n });\n\n validatePrepareUserOperationResponse(response);\n\n const {\n bundler: bundlerUrl,\n callData,\n dummyPaymasterAndData,\n dummySignature,\n initCode,\n nonce,\n sender,\n } = response;\n\n userOperation.callData = callData;\n userOperation.initCode = initCode ?? EMPTY_BYTES;\n userOperation.nonce = nonce;\n userOperation.paymasterAndData = dummyPaymasterAndData ?? EMPTY_BYTES;\n userOperation.sender = sender;\n userOperation.signature = dummySignature ?? EMPTY_BYTES;\n\n metadata.bundlerUrl = bundlerUrl;\n\n await updateGas(metadata, response, this.#entrypoint);\n\n this.#updateMetadata(metadata);\n }\n\n async #addPaymasterData(\n metadata: UserOperationMetadata,\n smartContractAccount: SmartContractAccount,\n ) {\n const { id, userOperation, chainId } = metadata;\n\n log('Requesting paymaster data', { id });\n\n const response = await smartContractAccount.updateUserOperation({\n userOperation,\n chainId,\n });\n\n validateUpdateUserOperationResponse(response);\n\n userOperation.paymasterAndData = response.paymasterAndData ?? EMPTY_BYTES;\n if (response.callGasLimit) {\n userOperation.callGasLimit = response.callGasLimit;\n }\n if (response.preVerificationGas) {\n userOperation.preVerificationGas = response.preVerificationGas;\n }\n if (response.verificationGasLimit) {\n userOperation.verificationGasLimit = response.verificationGasLimit;\n }\n\n this.#updateMetadata(metadata);\n }\n\n async #approveUserOperation(cache: UserOperationCache) {\n log('Requesting approval');\n\n const { metadata } = cache;\n\n const { resultCallbacks, value } = await this.#requestApproval(metadata);\n const updatedTransaction = value?.txMeta;\n\n if (updatedTransaction) {\n await this.#updateUserOperationAfterApproval(cache, updatedTransaction);\n }\n\n metadata.status = UserOperationStatus.Approved;\n\n this.#updateMetadata(metadata);\n\n return resultCallbacks;\n }\n\n async #signUserOperation(\n metadata: UserOperationMetadata,\n smartContractAccount: SmartContractAccount,\n ) {\n const { id, chainId, userOperation } = metadata;\n\n log('Signing user operation', id, userOperation);\n\n const response = await smartContractAccount.signUserOperation({\n userOperation,\n chainId,\n });\n\n validateSignUserOperationResponse(response);\n\n const { signature } = response;\n\n userOperation.signature = signature;\n\n log('Signed user operation', signature);\n\n metadata.status = UserOperationStatus.Signed;\n\n this.#updateMetadata(metadata);\n }\n\n async #submitUserOperation(metadata: UserOperationMetadata) {\n const { userOperation } = metadata;\n\n log('Submitting user operation', userOperation);\n\n const bundler = new Bundler(metadata.bundlerUrl as string);\n\n const hash = await bundler.sendUserOperation(\n userOperation,\n this.#entrypoint,\n );\n\n metadata.hash = hash;\n metadata.status = UserOperationStatus.Submitted;\n\n this.#updateMetadata(metadata);\n }\n\n #failUserOperation(metadata: UserOperationMetadata, error: unknown) {\n const { id } = metadata;\n const rawError = error as Record<string, string>;\n\n log('User operation failed', id, error);\n\n metadata.error = {\n name: rawError.name,\n message: rawError.message,\n stack: rawError.stack,\n code: rawError.code,\n rpc: rawError.value,\n };\n\n metadata.status = UserOperationStatus.Failed;\n\n this.#updateMetadata(metadata);\n\n if (\n String(rawError.code) === String(errorCodes.provider.userRejectedRequest)\n ) {\n this.#deleteMetadata(id);\n }\n }\n\n #createEmptyUserOperation(transaction?: TransactionParams): UserOperation {\n return {\n callData: EMPTY_BYTES,\n callGasLimit: EMPTY_BYTES,\n initCode: EMPTY_BYTES,\n maxFeePerGas: transaction?.maxFeePerGas ?? EMPTY_BYTES,\n maxPriorityFeePerGas: transaction?.maxPriorityFeePerGas ?? EMPTY_BYTES,\n nonce: EMPTY_BYTES,\n paymasterAndData: EMPTY_BYTES,\n preVerificationGas: EMPTY_BYTES,\n sender: ADDRESS_ZERO,\n signature: EMPTY_BYTES,\n verificationGasLimit: EMPTY_BYTES,\n };\n }\n\n #updateMetadata(metadata: UserOperationMetadata) {\n const { id } = metadata;\n\n this.update((state) => {\n state.userOperations[id] = cloneDeep(metadata);\n });\n\n this.#updateTransaction(metadata);\n }\n\n #deleteMetadata(id: string) {\n this.update((state) => {\n delete state.userOperations[id];\n });\n }\n\n #updateTransaction(metadata: UserOperationMetadata) {\n if (!metadata.transactionParams) {\n return;\n }\n\n const transactionMetadata = getTransactionMetadata(metadata);\n\n this.hub.emit('transaction-updated', transactionMetadata);\n }\n\n #addPendingUserOperationTrackerListeners() {\n this.#pendingUserOperationTracker.hub.on(\n 'user-operation-confirmed',\n (metadata) => {\n log('In listener...');\n this.hub.emit('user-operation-confirmed', metadata);\n this.hub.emit(`${metadata.id}:confirmed`, metadata);\n },\n );\n\n this.#pendingUserOperationTracker.hub.on(\n 'user-operation-failed',\n (metadata, error) => {\n this.hub.emit('user-operation-failed', metadata, error);\n this.hub.emit(`${metadata.id}:failed`, metadata, error);\n },\n );\n\n this.#pendingUserOperationTracker.hub.on(\n 'user-operation-updated',\n (metadata) => {\n this.#updateMetadata(metadata);\n },\n );\n }\n\n async #requestApproval(metadata: UserOperationMetadata) {\n const { id, origin } = metadata;\n const type = ApprovalType.Transaction;\n const requestData = { txId: id };\n\n return (await this.messenger.call(\n 'ApprovalController:addRequest',\n {\n id,\n origin,\n type,\n requestData,\n expectsResult: true,\n },\n true, // Should display approval request to user\n )) as AddResult & { value?: { txMeta?: TransactionMeta } };\n }\n\n async #getTransactionType(\n transaction: TransactionParams | undefined,\n provider: Provider,\n options: AddUserOperationOptions,\n ): Promise<TransactionType | undefined> {\n if (!transaction) {\n return undefined;\n }\n\n if (options.type) {\n return options.type;\n }\n\n const ethQuery = new EthQuery(provider);\n const result = determineTransactionType(transaction, ethQuery);\n\n return (await result).type;\n }\n\n async #getProvider(\n networkClientId: string,\n ): Promise<{ provider: Provider; chainId: string }> {\n const { provider, configuration } = this.messenger.call(\n 'NetworkController:getNetworkClientById',\n networkClientId,\n );\n\n const { chainId } = configuration;\n\n return { provider, chainId };\n }\n\n async #updateUserOperationAfterApproval(\n cache: UserOperationCache,\n updatedTransaction: TransactionMeta,\n ) {\n log('Found updated transaction in approval', { updatedTransaction });\n\n const { metadata, request } = cache;\n\n const { userOperation } = metadata;\n const usingPaymaster = userOperation.paymasterAndData !== EMPTY_BYTES;\n\n const updatedMaxFeePerGas = add0x(\n updatedTransaction.txParams.maxFeePerGas as string,\n );\n\n const updatedMaxPriorityFeePerGas = add0x(\n updatedTransaction.txParams.maxPriorityFeePerGas as string,\n );\n\n let regenerateUserOperation = false;\n const previousMaxFeePerGas = userOperation.maxFeePerGas;\n const previousMaxPriorityFeePerGas = userOperation.maxPriorityFeePerGas;\n\n const gasFeesUpdated =\n previousMaxFeePerGas !== updatedMaxFeePerGas ||\n previousMaxPriorityFeePerGas !== updatedMaxPriorityFeePerGas;\n\n /**\n * true when we detect {@link getTransactionMetadata} has set the gas fees to zero\n * because the userOperation has a paymaster. This should not be mistaken for gas\n * fees being updated during the approval process.\n */\n const areGasFeesZeroBecauseOfPaymaster =\n usingPaymaster &&\n updatedMaxFeePerGas === VALUE_ZERO &&\n updatedMaxPriorityFeePerGas === VALUE_ZERO;\n\n if (gasFeesUpdated && !areGasFeesZeroBecauseOfPaymaster) {\n log('Gas fees updated during approval', {\n previousMaxFeePerGas,\n previousMaxPriorityFeePerGas,\n updatedMaxFeePerGas,\n updatedMaxPriorityFeePerGas,\n });\n\n userOperation.maxFeePerGas = updatedMaxFeePerGas;\n userOperation.maxPriorityFeePerGas = updatedMaxPriorityFeePerGas;\n\n regenerateUserOperation = usingPaymaster;\n }\n\n const previousData = request.data ?? EMPTY_BYTES;\n const updatedData = updatedTransaction.txParams.data ?? EMPTY_BYTES;\n\n if (previousData !== updatedData) {\n log('Data updated during approval', { previousData, updatedData });\n regenerateUserOperation = true;\n }\n\n const previousValue = request.value ?? VALUE_ZERO;\n const updatedValue = updatedTransaction.txParams.value ?? VALUE_ZERO;\n\n if (previousValue !== updatedValue) {\n log('Value updated during approval', { previousValue, updatedValue });\n regenerateUserOperation = true;\n }\n\n if (regenerateUserOperation) {\n const updatedRequest = {\n ...request,\n data: updatedData,\n maxFeePerGas: updatedMaxFeePerGas,\n maxPriorityFeePerGas: updatedMaxPriorityFeePerGas,\n value: updatedValue,\n };\n\n await this.#regenerateUserOperation({\n ...cache,\n request: updatedRequest,\n });\n }\n }\n\n async #regenerateUserOperation(cache: UserOperationCache) {\n log(\n 'Regenerating user operation as parameters were updated during approval',\n );\n\n const {\n options: { smartContractAccount },\n metadata,\n } = cache;\n\n await this.#prepareUserOperation(cache);\n await this.#addPaymasterData(metadata, smartContractAccount);\n\n log('Regenerated user operation', metadata.userOperation);\n }\n}\n"]}
|
|
1
|
+
{"version":3,"file":"UserOperationController.mjs","sourceRoot":"","sources":["../src/UserOperationController.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;AAKA,OAAO,EAAE,cAAc,EAAE,kCAAkC;AAK3D,OAAO,EAAE,YAAY,EAAE,mCAAmC;AAC1D,OAAO,SAAQ,4BAA4B;;AAY3C,OAAO,EAAE,UAAU,EAAE,6BAA6B;AAClD,OAAO,EAAE,wBAAwB,EAAE,yCAAyC;AAM5E,OAAO,EAAE,KAAK,EAAE,wBAAwB;AACxC,kEAAkE;AAClE,sDAAsD;AACtD,OAAO,YAAY,eAAe;;;AAElC,OAAO,EAAE,EAAE,IAAI,MAAM,EAAE,aAAa;AAEpC,OAAO,EAAE,YAAY,EAAE,WAAW,EAAE,UAAU,EAAE,wBAAoB;AACpE,OAAO,EAAE,OAAO,EAAE,8BAA0B;AAC5C,OAAO,EAAE,2BAA2B,EAAE,kDAA8C;AACpF,OAAO,EAAE,wBAAw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,KAAK,CAAC,CAAC;IACxC,MAAM,uBAAA,IAAI,qFAAkB,MAAtB,IAAI,EAAmB,QAAQ,EAAE,oBAAoB,CAAC,CAAC;IAE7D,GAAG,CAAC,4BAA4B,EAAE,QAAQ,CAAC,aAAa,CAAC,CAAC;AAC5D,CAAC","sourcesContent":["import type {\n AcceptResultCallbacks,\n ApprovalControllerAddRequestAction,\n AddResult,\n} from '@metamask/approval-controller';\nimport { BaseController } from '@metamask/base-controller';\nimport type {\n ControllerGetStateAction,\n ControllerStateChangeEvent,\n} from '@metamask/base-controller';\nimport { ApprovalType } from '@metamask/controller-utils';\nimport EthQuery from '@metamask/eth-query';\nimport type { GasFeeState } from '@metamask/gas-fee-controller';\nimport type {\n KeyringControllerPrepareUserOperationAction,\n KeyringControllerPatchUserOperationAction,\n KeyringControllerSignUserOperationAction,\n} from '@metamask/keyring-controller';\nimport type { Messenger } from '@metamask/messenger';\nimport type {\n NetworkControllerGetNetworkClientByIdAction,\n Provider,\n} from '@metamask/network-controller';\nimport { errorCodes } from '@metamask/rpc-errors';\nimport { determineTransactionType } from '@metamask/transaction-controller';\nimport type {\n TransactionMeta,\n TransactionParams,\n TransactionType,\n} from '@metamask/transaction-controller';\nimport { add0x } from '@metamask/utils';\n// This package purposefully relies on Node's EventEmitter module.\n// eslint-disable-next-line import-x/no-nodejs-modules\nimport EventEmitter from 'events';\nimport { cloneDeep } from 'lodash';\nimport { v1 as random } from 'uuid';\n\nimport { ADDRESS_ZERO, EMPTY_BYTES, VALUE_ZERO } from './constants';\nimport { Bundler } from './helpers/Bundler';\nimport { PendingUserOperationTracker } from './helpers/PendingUserOperationTracker';\nimport { SnapSmartContractAccount } from './helpers/SnapSmartContractAccount';\nimport { projectLogger as log } from './logger';\nimport type {\n SmartContractAccount,\n UserOperation,\n UserOperationMetadata,\n} from './types';\nimport { UserOperationStatus } from './types';\nimport type { UserOperationControllerMethodActions } from './UserOperationController-method-action-types';\nimport { updateGas } from './utils/gas';\nimport { updateGasFees } from './utils/gas-fees';\nimport { getTransactionMetadata } from './utils/transaction';\nimport {\n validateAddUserOperationOptions,\n validateAddUserOperationRequest,\n validatePrepareUserOperationResponse,\n validateSignUserOperationResponse,\n validateUpdateUserOperationResponse,\n} from './utils/validation';\n\nconst controllerName = 'UserOperationController';\n\nconst MESSENGER_EXPOSED_METHODS = [\n 'addUserOperation',\n 'addUserOperationFromTransaction',\n 'startPollingByNetworkClientId',\n] as const;\n\nconst stateMetadata = {\n userOperations: {\n includeInStateLogs: true,\n persist: true,\n includeInDebugSnapshot: false,\n usedInUi: true,\n },\n};\n\nconst getDefaultState = () => ({\n userOperations: {},\n});\n\ntype Events = {\n 'transaction-updated': [metadata: TransactionMeta];\n 'user-operation-added': [metadata: UserOperationMetadata];\n 'user-operation-confirmed': [metadata: UserOperationMetadata];\n 'user-operation-failed': [metadata: UserOperationMetadata, error: Error];\n [key: `${string}:confirmed`]: [metadata: UserOperationMetadata];\n [key: `${string}:failed`]: [metadata: UserOperationMetadata, error: Error];\n};\n\nexport type UserOperationControllerEventEmitter = EventEmitter & {\n on<T extends keyof Events>(\n eventName: T,\n listener: (...args: Events[T]) => void,\n ): UserOperationControllerEventEmitter;\n\n once<T extends keyof Events>(\n eventName: T,\n listener: (...args: Events[T]) => void,\n ): UserOperationControllerEventEmitter;\n\n emit<T extends keyof Events>(eventName: T, ...args: Events[T]): boolean;\n};\n\nexport type UserOperationControllerState = {\n userOperations: Record<string, UserOperationMetadata>;\n};\n\nexport type GetUserOperationState = ControllerGetStateAction<\n typeof controllerName,\n UserOperationControllerState\n>;\n\nexport type UserOperationStateChange = ControllerStateChangeEvent<\n typeof controllerName,\n UserOperationControllerState\n>;\n\nexport type UserOperationControllerActions =\n | GetUserOperationState\n | UserOperationControllerMethodActions\n | NetworkControllerGetNetworkClientByIdAction\n | ApprovalControllerAddRequestAction\n | KeyringControllerPrepareUserOperationAction\n | KeyringControllerPatchUserOperationAction\n | KeyringControllerSignUserOperationAction;\n\nexport type UserOperationControllerEvents = UserOperationStateChange;\n\nexport type UserOperationControllerMessenger = Messenger<\n typeof controllerName,\n UserOperationControllerActions,\n UserOperationControllerEvents\n>;\n\nexport type UserOperationControllerOptions = {\n entrypoint: string;\n getGasFeeEstimates: () => Promise<GasFeeState>;\n interval?: number;\n messenger: UserOperationControllerMessenger;\n state?: Partial<UserOperationControllerState>;\n};\n\nexport type AddUserOperationRequest = {\n data?: string;\n from: string;\n maxFeePerGas?: string;\n maxPriorityFeePerGas?: string;\n to?: string;\n value?: string;\n};\n\nexport type AddUserOperationSwapOptions = {\n approvalTxId?: string;\n destinationTokenAddress?: string;\n destinationTokenAmount?: string;\n destinationTokenDecimals?: number;\n destinationTokenSymbol?: string;\n estimatedBaseFee?: string;\n sourceTokenAddress?: string;\n sourceTokenAmount?: string;\n sourceTokenDecimals?: number;\n sourceTokenSymbol?: string;\n swapAndSendRecipient?: string;\n swapMetaData?: Record<string, unknown>;\n swapTokenValue?: string;\n};\n\nexport type AddUserOperationOptions = {\n networkClientId: string;\n origin: string;\n requireApproval?: boolean;\n smartContractAccount?: SmartContractAccount;\n swaps?: AddUserOperationSwapOptions;\n type?: TransactionType;\n};\n\nexport type AddUserOperationResponse = {\n id: string;\n hash: () => Promise<string | undefined>;\n transactionHash: () => Promise<string | undefined>;\n};\n\n/**\n * All the objects related to a pending user operation in order to:\n * - Avoid duplicated effort to derive the same properties.\n * - Minimise duplicate arguments in private methods.\n */\ntype UserOperationCache = {\n chainId: string;\n metadata: UserOperationMetadata;\n options: AddUserOperationOptions & {\n smartContractAccount: SmartContractAccount;\n };\n provider: Provider;\n request: AddUserOperationRequest;\n transaction?: TransactionParams;\n};\n\n/**\n * Controller for creating and managing the life cycle of user operations.\n */\nexport class UserOperationController extends BaseController<\n typeof controllerName,\n UserOperationControllerState,\n UserOperationControllerMessenger\n> {\n hub: UserOperationControllerEventEmitter;\n\n readonly #entrypoint: string;\n\n readonly #getGasFeeEstimates: () => Promise<GasFeeState>;\n\n readonly #pendingUserOperationTracker: PendingUserOperationTracker;\n\n /**\n * Construct a UserOperationController instance.\n *\n * @param options - Controller options.\n * @param options.entrypoint - Address of the entrypoint contract.\n * @param options.getGasFeeEstimates - Callback to get gas fee estimates.\n * @param options.messenger - Restricted messenger for the user operation controller.\n * @param options.state - Initial state to set on the controller.\n */\n constructor({\n entrypoint,\n getGasFeeEstimates,\n messenger,\n state,\n }: UserOperationControllerOptions) {\n super({\n name: controllerName,\n metadata: stateMetadata,\n messenger,\n state: { ...getDefaultState(), ...state },\n });\n\n this.hub = new EventEmitter() as UserOperationControllerEventEmitter;\n\n this.messenger.registerMethodActionHandlers(\n this,\n MESSENGER_EXPOSED_METHODS,\n );\n\n this.#entrypoint = entrypoint;\n this.#getGasFeeEstimates = getGasFeeEstimates;\n\n this.#pendingUserOperationTracker = new PendingUserOperationTracker({\n getUserOperations: () =>\n cloneDeep(Object.values(this.state.userOperations)),\n messenger,\n });\n\n this.#addPendingUserOperationTrackerListeners();\n }\n\n /**\n * Create and submit a user operation.\n *\n * @param request - Information required to create a user operation.\n * @param request.data - Data to include in the resulting transaction.\n * @param request.maxFeePerGas - Maximum fee per gas to pay towards the transaction.\n * @param request.maxPriorityFeePerGas - Maximum priority fee per gas to pay towards the transaction.\n * @param request.to - Destination address of the resulting transaction.\n * @param request.value - Value to include in the resulting transaction.\n * @param options - Configuration options when creating a user operation.\n * @param options.networkClientId - ID of the network client used to query the chain.\n * @param options.origin - Origin of the user operation, such as the hostname of a dApp.\n * @param options.requireApproval - Whether to require user approval before submitting the user operation. Defaults to true.\n * @param options.smartContractAccount - Smart contract abstraction to provide the contract specific values such as call data and nonce. Defaults to the current snap account.\n * @param options.swaps - Swap metadata to record with the user operation.\n * @param options.type - Type of the transaction.\n */\n async addUserOperation(\n request: AddUserOperationRequest,\n options: AddUserOperationOptions,\n ): Promise<AddUserOperationResponse> {\n validateAddUserOperationRequest(request);\n validateAddUserOperationOptions(options);\n\n return await this.#addUserOperation(request, options);\n }\n\n /**\n * Create and submit a user operation equivalent to the provided transaction.\n *\n * @param transaction - Transaction to use as the basis for the user operation.\n * @param options - Configuration options when creating a user operation.\n * @param options.networkClientId - ID of the network client used to query the chain.\n * @param options.origin - Origin of the user operation, such as the hostname of a dApp.\n * @param options.requireApproval - Whether to require user approval before submitting the user operation. Defaults to true.\n * @param options.smartContractAccount - Smart contract abstraction to provide the contract specific values such as call data and nonce. Defaults to the current snap account.\n * @param options.swaps - Swap metadata to record with the user operation.\n * @param options.type - Type of the transaction.\n */\n async addUserOperationFromTransaction(\n transaction: TransactionParams,\n options: AddUserOperationOptions,\n ): Promise<AddUserOperationResponse> {\n validateAddUserOperationOptions(options);\n\n const { data, from, maxFeePerGas, maxPriorityFeePerGas, to, value } =\n transaction;\n\n const request: AddUserOperationRequest = {\n data: data === '' ? undefined : data,\n from,\n maxFeePerGas,\n maxPriorityFeePerGas,\n to,\n value,\n };\n\n validateAddUserOperationRequest(request);\n\n return await this.#addUserOperation(request, { ...options, transaction });\n }\n\n /**\n * Starts polling for pending user operations on the given network.\n *\n * @param networkClientId - The ID of the network client to poll.\n * @returns The polling token that can be used to stop polling.\n */\n startPollingByNetworkClientId(networkClientId: string): string {\n return this.#pendingUserOperationTracker.startPolling({\n networkClientId,\n });\n }\n\n async #addUserOperation(\n request: AddUserOperationRequest,\n options: AddUserOperationOptions & { transaction?: TransactionParams },\n ): Promise<AddUserOperationResponse> {\n log('Adding user operation', { request, options });\n\n const {\n networkClientId,\n origin,\n smartContractAccount: requestSmartContractAccount,\n swaps,\n transaction,\n } = options;\n\n const { chainId, provider } = await this.#getProvider(networkClientId);\n\n const metadata = await this.#createMetadata(\n chainId,\n origin,\n transaction,\n swaps,\n );\n\n const smartContractAccount =\n requestSmartContractAccount ??\n new SnapSmartContractAccount(this.messenger);\n\n const cache: UserOperationCache = {\n chainId,\n metadata,\n options: { ...options, smartContractAccount },\n provider,\n request,\n transaction,\n };\n\n const { id } = metadata;\n let throwError = false;\n\n const hashValue = (async () => {\n try {\n return await this.#prepareAndSubmitUserOperation(cache);\n } catch (error) {\n this.#failUserOperation(metadata, error);\n\n if (throwError) {\n throw error;\n }\n\n return undefined;\n }\n })();\n\n const hash = async () => {\n throwError = true;\n return await hashValue;\n };\n\n const transactionHash = async () => {\n await hash();\n\n const { transactionHash: finalTransactionHash } =\n await this.#waitForConfirmation(metadata);\n\n return finalTransactionHash as string;\n };\n\n return {\n id,\n hash,\n transactionHash,\n };\n }\n\n async #prepareAndSubmitUserOperation(cache: UserOperationCache) {\n const { metadata, options } = cache;\n const { requireApproval, smartContractAccount } = options;\n let resultCallbacks: AcceptResultCallbacks | undefined;\n\n try {\n await this.#prepareUserOperation(cache);\n await this.#addPaymasterData(metadata, smartContractAccount);\n\n this.hub.emit('user-operation-added', metadata);\n\n if (requireApproval !== false) {\n resultCallbacks = await this.#approveUserOperation(cache);\n }\n\n await this.#signUserOperation(metadata, smartContractAccount);\n await this.#submitUserOperation(metadata);\n\n resultCallbacks?.success();\n\n return metadata.hash as string;\n } catch (error) {\n /* istanbul ignore next */\n resultCallbacks?.error(error as Error);\n throw error;\n }\n }\n\n async #waitForConfirmation(\n metadata: UserOperationMetadata,\n ): Promise<UserOperationMetadata> {\n const { id, hash } = metadata;\n\n log('Waiting for confirmation', id, hash);\n\n return new Promise((resolve, reject) => {\n this.hub.once(`${id}:confirmed`, (finalMetadata) => {\n resolve(finalMetadata);\n });\n\n this.hub.once(`${id}:failed`, (_finalMetadata, error) => {\n reject(error);\n });\n });\n }\n\n async #createMetadata(\n chainId: string,\n origin: string,\n transaction?: TransactionParams,\n swaps?: AddUserOperationSwapOptions,\n ): Promise<UserOperationMetadata> {\n const metadata: UserOperationMetadata = {\n actualGasCost: null,\n actualGasUsed: null,\n baseFeePerGas: null,\n bundlerUrl: null,\n chainId,\n error: null,\n hash: null,\n id: random(),\n origin,\n status: UserOperationStatus.Unapproved,\n swapsMetadata: swaps\n ? {\n approvalTxId: swaps.approvalTxId ?? null,\n destinationTokenAddress: swaps.destinationTokenAddress ?? null,\n destinationTokenAmount: swaps.destinationTokenAmount ?? null,\n destinationTokenDecimals: swaps.destinationTokenDecimals ?? null,\n destinationTokenSymbol: swaps.destinationTokenSymbol ?? null,\n estimatedBaseFee: swaps.estimatedBaseFee ?? null,\n sourceTokenAddress: swaps.sourceTokenAddress ?? null,\n sourceTokenAmount: swaps.sourceTokenAmount ?? null,\n sourceTokenDecimals: swaps.sourceTokenDecimals ?? null,\n sourceTokenSymbol: swaps.sourceTokenSymbol ?? null,\n swapAndSendRecipient: swaps.swapAndSendRecipient ?? null,\n swapMetaData: (swaps.swapMetaData as Record<string, never>) ?? null,\n swapTokenValue: swaps.swapTokenValue ?? null,\n }\n : null,\n time: Date.now(),\n transactionHash: null,\n transactionParams: (transaction as Required<TransactionParams>) ?? null,\n transactionType: null,\n userFeeLevel: null,\n userOperation: this.#createEmptyUserOperation(transaction),\n };\n\n this.#updateMetadata(metadata);\n\n log('Added user operation', metadata.id);\n\n return metadata;\n }\n\n async #prepareUserOperation(cache: UserOperationCache) {\n const { chainId, metadata, options, provider, request, transaction } =\n cache;\n\n const { data, from, to, value } = request;\n const { id, transactionParams, userOperation } = metadata;\n const { smartContractAccount } = options;\n\n log('Preparing user operation', { id });\n\n const transactionType = await this.#getTransactionType(\n transaction,\n provider,\n options,\n );\n\n metadata.transactionType = transactionType ?? null;\n\n log('Determined transaction type', transactionType);\n\n await updateGasFees({\n getGasFeeEstimates: this.#getGasFeeEstimates,\n metadata,\n originalRequest: request,\n provider,\n transaction: transactionParams ?? undefined,\n });\n\n const response = await smartContractAccount.prepareUserOperation({\n chainId,\n data,\n from,\n to,\n value,\n });\n\n validatePrepareUserOperationResponse(response);\n\n const {\n bundler: bundlerUrl,\n callData,\n dummyPaymasterAndData,\n dummySignature,\n initCode,\n nonce,\n sender,\n } = response;\n\n userOperation.callData = callData;\n userOperation.initCode = initCode ?? EMPTY_BYTES;\n userOperation.nonce = nonce;\n userOperation.paymasterAndData = dummyPaymasterAndData ?? EMPTY_BYTES;\n userOperation.sender = sender;\n userOperation.signature = dummySignature ?? EMPTY_BYTES;\n\n metadata.bundlerUrl = bundlerUrl;\n\n await updateGas(metadata, response, this.#entrypoint);\n\n this.#updateMetadata(metadata);\n }\n\n async #addPaymasterData(\n metadata: UserOperationMetadata,\n smartContractAccount: SmartContractAccount,\n ) {\n const { id, userOperation, chainId } = metadata;\n\n log('Requesting paymaster data', { id });\n\n const response = await smartContractAccount.updateUserOperation({\n userOperation,\n chainId,\n });\n\n validateUpdateUserOperationResponse(response);\n\n userOperation.paymasterAndData = response.paymasterAndData ?? EMPTY_BYTES;\n if (response.callGasLimit) {\n userOperation.callGasLimit = response.callGasLimit;\n }\n if (response.preVerificationGas) {\n userOperation.preVerificationGas = response.preVerificationGas;\n }\n if (response.verificationGasLimit) {\n userOperation.verificationGasLimit = response.verificationGasLimit;\n }\n\n this.#updateMetadata(metadata);\n }\n\n async #approveUserOperation(cache: UserOperationCache) {\n log('Requesting approval');\n\n const { metadata } = cache;\n\n const { resultCallbacks, value } = await this.#requestApproval(metadata);\n const updatedTransaction = value?.txMeta;\n\n if (updatedTransaction) {\n await this.#updateUserOperationAfterApproval(cache, updatedTransaction);\n }\n\n metadata.status = UserOperationStatus.Approved;\n\n this.#updateMetadata(metadata);\n\n return resultCallbacks;\n }\n\n async #signUserOperation(\n metadata: UserOperationMetadata,\n smartContractAccount: SmartContractAccount,\n ) {\n const { id, chainId, userOperation } = metadata;\n\n log('Signing user operation', id, userOperation);\n\n const response = await smartContractAccount.signUserOperation({\n userOperation,\n chainId,\n });\n\n validateSignUserOperationResponse(response);\n\n const { signature } = response;\n\n userOperation.signature = signature;\n\n log('Signed user operation', signature);\n\n metadata.status = UserOperationStatus.Signed;\n\n this.#updateMetadata(metadata);\n }\n\n async #submitUserOperation(metadata: UserOperationMetadata) {\n const { userOperation } = metadata;\n\n log('Submitting user operation', userOperation);\n\n const bundler = new Bundler(metadata.bundlerUrl as string);\n\n const hash = await bundler.sendUserOperation(\n userOperation,\n this.#entrypoint,\n );\n\n metadata.hash = hash;\n metadata.status = UserOperationStatus.Submitted;\n\n this.#updateMetadata(metadata);\n }\n\n #failUserOperation(metadata: UserOperationMetadata, error: unknown) {\n const { id } = metadata;\n const rawError = error as Record<string, string>;\n\n log('User operation failed', id, error);\n\n metadata.error = {\n name: rawError.name,\n message: rawError.message,\n stack: rawError.stack,\n code: rawError.code,\n rpc: rawError.value,\n };\n\n metadata.status = UserOperationStatus.Failed;\n\n this.#updateMetadata(metadata);\n\n if (\n String(rawError.code) === String(errorCodes.provider.userRejectedRequest)\n ) {\n this.#deleteMetadata(id);\n }\n }\n\n #createEmptyUserOperation(transaction?: TransactionParams): UserOperation {\n return {\n callData: EMPTY_BYTES,\n callGasLimit: EMPTY_BYTES,\n initCode: EMPTY_BYTES,\n maxFeePerGas: transaction?.maxFeePerGas ?? EMPTY_BYTES,\n maxPriorityFeePerGas: transaction?.maxPriorityFeePerGas ?? EMPTY_BYTES,\n nonce: EMPTY_BYTES,\n paymasterAndData: EMPTY_BYTES,\n preVerificationGas: EMPTY_BYTES,\n sender: ADDRESS_ZERO,\n signature: EMPTY_BYTES,\n verificationGasLimit: EMPTY_BYTES,\n };\n }\n\n #updateMetadata(metadata: UserOperationMetadata) {\n const { id } = metadata;\n\n this.update((state) => {\n state.userOperations[id] = cloneDeep(metadata);\n });\n\n this.#updateTransaction(metadata);\n }\n\n #deleteMetadata(id: string) {\n this.update((state) => {\n delete state.userOperations[id];\n });\n }\n\n #updateTransaction(metadata: UserOperationMetadata) {\n if (!metadata.transactionParams) {\n return;\n }\n\n const transactionMetadata = getTransactionMetadata(metadata);\n\n this.hub.emit('transaction-updated', transactionMetadata);\n }\n\n #addPendingUserOperationTrackerListeners() {\n this.#pendingUserOperationTracker.hub.on(\n 'user-operation-confirmed',\n (metadata) => {\n log('In listener...');\n this.hub.emit('user-operation-confirmed', metadata);\n this.hub.emit(`${metadata.id}:confirmed`, metadata);\n },\n );\n\n this.#pendingUserOperationTracker.hub.on(\n 'user-operation-failed',\n (metadata, error) => {\n this.hub.emit('user-operation-failed', metadata, error);\n this.hub.emit(`${metadata.id}:failed`, metadata, error);\n },\n );\n\n this.#pendingUserOperationTracker.hub.on(\n 'user-operation-updated',\n (metadata) => {\n this.#updateMetadata(metadata);\n },\n );\n }\n\n async #requestApproval(metadata: UserOperationMetadata) {\n const { id, origin } = metadata;\n const type = ApprovalType.Transaction;\n const requestData = { txId: id };\n\n return (await this.messenger.call(\n 'ApprovalController:addRequest',\n {\n id,\n origin,\n type,\n requestData,\n expectsResult: true,\n },\n true, // Should display approval request to user\n )) as AddResult & { value?: { txMeta?: TransactionMeta } };\n }\n\n async #getTransactionType(\n transaction: TransactionParams | undefined,\n provider: Provider,\n options: AddUserOperationOptions,\n ): Promise<TransactionType | undefined> {\n if (!transaction) {\n return undefined;\n }\n\n if (options.type) {\n return options.type;\n }\n\n const ethQuery = new EthQuery(provider);\n const result = determineTransactionType(transaction, ethQuery);\n\n return (await result).type;\n }\n\n async #getProvider(\n networkClientId: string,\n ): Promise<{ provider: Provider; chainId: string }> {\n const { provider, configuration } = this.messenger.call(\n 'NetworkController:getNetworkClientById',\n networkClientId,\n );\n\n const { chainId } = configuration;\n\n return { provider, chainId };\n }\n\n async #updateUserOperationAfterApproval(\n cache: UserOperationCache,\n updatedTransaction: TransactionMeta,\n ) {\n log('Found updated transaction in approval', { updatedTransaction });\n\n const { metadata, request } = cache;\n\n const { userOperation } = metadata;\n const usingPaymaster = userOperation.paymasterAndData !== EMPTY_BYTES;\n\n const updatedMaxFeePerGas = add0x(\n updatedTransaction.txParams.maxFeePerGas as string,\n );\n\n const updatedMaxPriorityFeePerGas = add0x(\n updatedTransaction.txParams.maxPriorityFeePerGas as string,\n );\n\n let regenerateUserOperation = false;\n const previousMaxFeePerGas = userOperation.maxFeePerGas;\n const previousMaxPriorityFeePerGas = userOperation.maxPriorityFeePerGas;\n\n const gasFeesUpdated =\n previousMaxFeePerGas !== updatedMaxFeePerGas ||\n previousMaxPriorityFeePerGas !== updatedMaxPriorityFeePerGas;\n\n /**\n * true when we detect {@link getTransactionMetadata} has set the gas fees to zero\n * because the userOperation has a paymaster. This should not be mistaken for gas\n * fees being updated during the approval process.\n */\n const areGasFeesZeroBecauseOfPaymaster =\n usingPaymaster &&\n updatedMaxFeePerGas === VALUE_ZERO &&\n updatedMaxPriorityFeePerGas === VALUE_ZERO;\n\n if (gasFeesUpdated && !areGasFeesZeroBecauseOfPaymaster) {\n log('Gas fees updated during approval', {\n previousMaxFeePerGas,\n previousMaxPriorityFeePerGas,\n updatedMaxFeePerGas,\n updatedMaxPriorityFeePerGas,\n });\n\n userOperation.maxFeePerGas = updatedMaxFeePerGas;\n userOperation.maxPriorityFeePerGas = updatedMaxPriorityFeePerGas;\n\n regenerateUserOperation = usingPaymaster;\n }\n\n const previousData = request.data ?? EMPTY_BYTES;\n const updatedData = updatedTransaction.txParams.data ?? EMPTY_BYTES;\n\n if (previousData !== updatedData) {\n log('Data updated during approval', { previousData, updatedData });\n regenerateUserOperation = true;\n }\n\n const previousValue = request.value ?? VALUE_ZERO;\n const updatedValue = updatedTransaction.txParams.value ?? VALUE_ZERO;\n\n if (previousValue !== updatedValue) {\n log('Value updated during approval', { previousValue, updatedValue });\n regenerateUserOperation = true;\n }\n\n if (regenerateUserOperation) {\n const updatedRequest = {\n ...request,\n data: updatedData,\n maxFeePerGas: updatedMaxFeePerGas,\n maxPriorityFeePerGas: updatedMaxPriorityFeePerGas,\n value: updatedValue,\n };\n\n await this.#regenerateUserOperation({\n ...cache,\n request: updatedRequest,\n });\n }\n }\n\n async #regenerateUserOperation(cache: UserOperationCache) {\n log(\n 'Regenerating user operation as parameters were updated during approval',\n );\n\n const {\n options: { smartContractAccount },\n metadata,\n } = cache;\n\n await this.#prepareUserOperation(cache);\n await this.#addPaymasterData(metadata, smartContractAccount);\n\n log('Regenerated user operation', metadata.userOperation);\n }\n}\n"]}
|
package/dist/index.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.cjs","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,gEAA0C;
|
|
1
|
+
{"version":3,"file":"index.cjs","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,gEAA0C;AAM1C,8CAAwB","sourcesContent":["export * from './UserOperationController';\nexport type {\n UserOperationControllerAddUserOperationAction,\n UserOperationControllerAddUserOperationFromTransactionAction,\n UserOperationControllerStartPollingByNetworkClientIdAction,\n} from './UserOperationController-method-action-types';\nexport * from './types';\n"]}
|
package/dist/index.d.cts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
1
|
export * from "./UserOperationController.cjs";
|
|
2
|
+
export type { UserOperationControllerAddUserOperationAction, UserOperationControllerAddUserOperationFromTransactionAction, UserOperationControllerStartPollingByNetworkClientIdAction, } from "./UserOperationController-method-action-types.cjs";
|
|
2
3
|
export * from "./types.cjs";
|
|
3
4
|
//# sourceMappingURL=index.d.cts.map
|
package/dist/index.d.cts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.cts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,8CAA0C;AAC1C,4BAAwB"}
|
|
1
|
+
{"version":3,"file":"index.d.cts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,8CAA0C;AAC1C,YAAY,EACV,6CAA6C,EAC7C,4DAA4D,EAC5D,0DAA0D,GAC3D,0DAAsD;AACvD,4BAAwB"}
|
package/dist/index.d.mts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
1
|
export * from "./UserOperationController.mjs";
|
|
2
|
+
export type { UserOperationControllerAddUserOperationAction, UserOperationControllerAddUserOperationFromTransactionAction, UserOperationControllerStartPollingByNetworkClientIdAction, } from "./UserOperationController-method-action-types.mjs";
|
|
2
3
|
export * from "./types.mjs";
|
|
3
4
|
//# sourceMappingURL=index.d.mts.map
|
package/dist/index.d.mts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.mts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,8CAA0C;AAC1C,4BAAwB"}
|
|
1
|
+
{"version":3,"file":"index.d.mts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,8CAA0C;AAC1C,YAAY,EACV,6CAA6C,EAC7C,4DAA4D,EAC5D,0DAA0D,GAC3D,0DAAsD;AACvD,4BAAwB"}
|
package/dist/index.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.mjs","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,8CAA0C;
|
|
1
|
+
{"version":3,"file":"index.mjs","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,8CAA0C;AAM1C,4BAAwB","sourcesContent":["export * from './UserOperationController';\nexport type {\n UserOperationControllerAddUserOperationAction,\n UserOperationControllerAddUserOperationFromTransactionAction,\n UserOperationControllerStartPollingByNetworkClientIdAction,\n} from './UserOperationController-method-action-types';\nexport * from './types';\n"]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@metamask-previews/user-operation-controller",
|
|
3
|
-
"version": "41.0
|
|
3
|
+
"version": "41.1.0-preview-152e02d",
|
|
4
4
|
"description": "Creates user operations and manages their life cycle",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"MetaMask",
|
|
@@ -40,6 +40,7 @@
|
|
|
40
40
|
"build:docs": "typedoc",
|
|
41
41
|
"changelog:update": "../../scripts/update-changelog.sh @metamask/user-operation-controller",
|
|
42
42
|
"changelog:validate": "../../scripts/validate-changelog.sh @metamask/user-operation-controller",
|
|
43
|
+
"generate-method-action-types": "tsx ../../scripts/generate-method-action-types.ts",
|
|
43
44
|
"prepare-manifest:preview": "../../scripts/prepare-preview-manifest.sh",
|
|
44
45
|
"since-latest-release": "../../scripts/since-latest-release.sh",
|
|
45
46
|
"test": "NODE_OPTIONS=--experimental-vm-modules jest --reporters=jest-silent-reporter",
|
|
@@ -48,18 +49,18 @@
|
|
|
48
49
|
"test:watch": "NODE_OPTIONS=--experimental-vm-modules jest --watch"
|
|
49
50
|
},
|
|
50
51
|
"dependencies": {
|
|
51
|
-
"@metamask/approval-controller": "^
|
|
52
|
+
"@metamask/approval-controller": "^9.0.0",
|
|
52
53
|
"@metamask/base-controller": "^9.0.0",
|
|
53
54
|
"@metamask/controller-utils": "^11.19.0",
|
|
54
55
|
"@metamask/eth-query": "^4.0.0",
|
|
55
|
-
"@metamask/gas-fee-controller": "^26.0
|
|
56
|
+
"@metamask/gas-fee-controller": "^26.1.0",
|
|
56
57
|
"@metamask/keyring-controller": "^25.1.0",
|
|
57
58
|
"@metamask/messenger": "^0.3.0",
|
|
58
59
|
"@metamask/network-controller": "^30.0.0",
|
|
59
60
|
"@metamask/polling-controller": "^16.0.3",
|
|
60
61
|
"@metamask/rpc-errors": "^7.0.2",
|
|
61
62
|
"@metamask/superstruct": "^3.1.0",
|
|
62
|
-
"@metamask/transaction-controller": "^
|
|
63
|
+
"@metamask/transaction-controller": "^63.0.0",
|
|
63
64
|
"@metamask/utils": "^11.9.0",
|
|
64
65
|
"bn.js": "^5.2.1",
|
|
65
66
|
"immer": "^9.0.6",
|
|
@@ -74,6 +75,7 @@
|
|
|
74
75
|
"deepmerge": "^4.2.2",
|
|
75
76
|
"jest": "^29.7.0",
|
|
76
77
|
"ts-jest": "^29.2.5",
|
|
78
|
+
"tsx": "^4.20.5",
|
|
77
79
|
"typedoc": "^0.25.13",
|
|
78
80
|
"typedoc-plugin-missing-exports": "^2.0.0",
|
|
79
81
|
"typescript": "~5.3.3"
|