@metamask-previews/user-operation-controller 41.2.9-preview-8bfa290fb → 42.0.0-preview-0a30e47

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.
Files changed (159) hide show
  1. package/CHANGELOG.md +22 -2
  2. package/dist/{BlockTrackerPollingController.d.mts → BlockTrackerPollingController.d.ts} +11 -11
  3. package/dist/BlockTrackerPollingController.d.ts.map +1 -0
  4. package/dist/{BlockTrackerPollingController.mjs → BlockTrackerPollingController.js} +17 -19
  5. package/dist/BlockTrackerPollingController.js.map +1 -0
  6. package/dist/{UserOperationController-method-action-types.d.cts → UserOperationController-method-action-types.d.ts} +2 -2
  7. package/dist/UserOperationController-method-action-types.d.ts.map +1 -0
  8. package/dist/{UserOperationController-method-action-types.mjs → UserOperationController-method-action-types.js} +1 -1
  9. package/dist/UserOperationController-method-action-types.js.map +1 -0
  10. package/dist/{UserOperationController.d.cts → UserOperationController.d.ts} +13 -15
  11. package/dist/UserOperationController.d.ts.map +1 -0
  12. package/dist/UserOperationController.js +495 -0
  13. package/dist/UserOperationController.js.map +1 -0
  14. package/dist/{constants.d.cts → constants.d.ts} +1 -1
  15. package/dist/constants.d.ts.map +1 -0
  16. package/dist/{constants.mjs → constants.js} +1 -1
  17. package/dist/constants.js.map +1 -0
  18. package/dist/helpers/{Bundler.d.cts → Bundler.d.ts} +2 -2
  19. package/dist/helpers/Bundler.d.ts.map +1 -0
  20. package/dist/helpers/Bundler.js +74 -0
  21. package/dist/helpers/Bundler.js.map +1 -0
  22. package/dist/helpers/{PendingUserOperationTracker.d.cts → PendingUserOperationTracker.d.ts} +10 -12
  23. package/dist/helpers/PendingUserOperationTracker.d.ts.map +1 -0
  24. package/dist/helpers/PendingUserOperationTracker.js +115 -0
  25. package/dist/helpers/PendingUserOperationTracker.js.map +1 -0
  26. package/dist/helpers/{SnapSmartContractAccount.d.cts → SnapSmartContractAccount.d.ts} +3 -3
  27. package/dist/helpers/SnapSmartContractAccount.d.ts.map +1 -0
  28. package/dist/helpers/SnapSmartContractAccount.js +47 -0
  29. package/dist/helpers/SnapSmartContractAccount.js.map +1 -0
  30. package/dist/index.d.ts +4 -0
  31. package/dist/index.d.ts.map +1 -0
  32. package/dist/index.js +3 -0
  33. package/dist/index.js.map +1 -0
  34. package/dist/logger.d.ts +4 -0
  35. package/dist/logger.d.ts.map +1 -0
  36. package/dist/{logger.mjs → logger.js} +2 -2
  37. package/dist/logger.js.map +1 -0
  38. package/dist/{types.d.mts → types.d.ts} +3 -3
  39. package/dist/types.d.ts.map +1 -0
  40. package/dist/{types.mjs → types.js} +1 -1
  41. package/dist/types.js.map +1 -0
  42. package/dist/utils/{chain-id.d.cts → chain-id.d.ts} +1 -1
  43. package/dist/utils/chain-id.d.ts.map +1 -0
  44. package/dist/utils/{chain-id.mjs → chain-id.js} +1 -1
  45. package/dist/utils/chain-id.js.map +1 -0
  46. package/dist/utils/{gas-fees.d.cts → gas-fees.d.ts} +6 -6
  47. package/dist/utils/gas-fees.d.ts.map +1 -0
  48. package/dist/utils/{gas-fees.mjs → gas-fees.js} +8 -15
  49. package/dist/utils/gas-fees.js.map +1 -0
  50. package/dist/utils/{gas.d.mts → gas.d.ts} +2 -2
  51. package/dist/utils/gas.d.ts.map +1 -0
  52. package/dist/utils/{gas.mjs → gas.js} +7 -14
  53. package/dist/utils/gas.js.map +1 -0
  54. package/dist/utils/{transaction.d.cts → transaction.d.ts} +3 -3
  55. package/dist/utils/transaction.d.ts.map +1 -0
  56. package/dist/utils/{transaction.mjs → transaction.js} +6 -13
  57. package/dist/utils/transaction.js.map +1 -0
  58. package/dist/utils/{validation.d.cts → validation.d.ts} +3 -3
  59. package/dist/utils/validation.d.ts.map +1 -0
  60. package/dist/utils/{validation.mjs → validation.js} +5 -5
  61. package/dist/utils/validation.js.map +1 -0
  62. package/package.json +24 -28
  63. package/dist/BlockTrackerPollingController.cjs +0 -68
  64. package/dist/BlockTrackerPollingController.cjs.map +0 -1
  65. package/dist/BlockTrackerPollingController.d.cts +0 -41
  66. package/dist/BlockTrackerPollingController.d.cts.map +0 -1
  67. package/dist/BlockTrackerPollingController.d.mts.map +0 -1
  68. package/dist/BlockTrackerPollingController.mjs.map +0 -1
  69. package/dist/UserOperationController-method-action-types.cjs +0 -7
  70. package/dist/UserOperationController-method-action-types.cjs.map +0 -1
  71. package/dist/UserOperationController-method-action-types.d.cts.map +0 -1
  72. package/dist/UserOperationController-method-action-types.d.mts +0 -57
  73. package/dist/UserOperationController-method-action-types.d.mts.map +0 -1
  74. package/dist/UserOperationController-method-action-types.mjs.map +0 -1
  75. package/dist/UserOperationController.cjs +0 -495
  76. package/dist/UserOperationController.cjs.map +0 -1
  77. package/dist/UserOperationController.d.cts.map +0 -1
  78. package/dist/UserOperationController.d.mts +0 -136
  79. package/dist/UserOperationController.d.mts.map +0 -1
  80. package/dist/UserOperationController.mjs +0 -489
  81. package/dist/UserOperationController.mjs.map +0 -1
  82. package/dist/constants.cjs +0 -7
  83. package/dist/constants.cjs.map +0 -1
  84. package/dist/constants.d.cts.map +0 -1
  85. package/dist/constants.d.mts +0 -4
  86. package/dist/constants.d.mts.map +0 -1
  87. package/dist/constants.mjs.map +0 -1
  88. package/dist/helpers/Bundler.cjs +0 -91
  89. package/dist/helpers/Bundler.cjs.map +0 -1
  90. package/dist/helpers/Bundler.d.cts.map +0 -1
  91. package/dist/helpers/Bundler.d.mts +0 -46
  92. package/dist/helpers/Bundler.d.mts.map +0 -1
  93. package/dist/helpers/Bundler.mjs +0 -87
  94. package/dist/helpers/Bundler.mjs.map +0 -1
  95. package/dist/helpers/PendingUserOperationTracker.cjs +0 -127
  96. package/dist/helpers/PendingUserOperationTracker.cjs.map +0 -1
  97. package/dist/helpers/PendingUserOperationTracker.d.cts.map +0 -1
  98. package/dist/helpers/PendingUserOperationTracker.d.mts +0 -51
  99. package/dist/helpers/PendingUserOperationTracker.d.mts.map +0 -1
  100. package/dist/helpers/PendingUserOperationTracker.mjs +0 -127
  101. package/dist/helpers/PendingUserOperationTracker.mjs.map +0 -1
  102. package/dist/helpers/SnapSmartContractAccount.cjs +0 -64
  103. package/dist/helpers/SnapSmartContractAccount.cjs.map +0 -1
  104. package/dist/helpers/SnapSmartContractAccount.d.cts.map +0 -1
  105. package/dist/helpers/SnapSmartContractAccount.d.mts +0 -10
  106. package/dist/helpers/SnapSmartContractAccount.d.mts.map +0 -1
  107. package/dist/helpers/SnapSmartContractAccount.mjs +0 -60
  108. package/dist/helpers/SnapSmartContractAccount.mjs.map +0 -1
  109. package/dist/index.cjs +0 -19
  110. package/dist/index.cjs.map +0 -1
  111. package/dist/index.d.cts +0 -4
  112. package/dist/index.d.cts.map +0 -1
  113. package/dist/index.d.mts +0 -4
  114. package/dist/index.d.mts.map +0 -1
  115. package/dist/index.mjs +0 -3
  116. package/dist/index.mjs.map +0 -1
  117. package/dist/logger.cjs +0 -8
  118. package/dist/logger.cjs.map +0 -1
  119. package/dist/logger.d.cts +0 -5
  120. package/dist/logger.d.cts.map +0 -1
  121. package/dist/logger.d.mts +0 -5
  122. package/dist/logger.d.mts.map +0 -1
  123. package/dist/logger.mjs.map +0 -1
  124. package/dist/types.cjs +0 -16
  125. package/dist/types.cjs.map +0 -1
  126. package/dist/types.d.cts +0 -294
  127. package/dist/types.d.cts.map +0 -1
  128. package/dist/types.d.mts.map +0 -1
  129. package/dist/types.mjs.map +0 -1
  130. package/dist/utils/chain-id.cjs +0 -17
  131. package/dist/utils/chain-id.cjs.map +0 -1
  132. package/dist/utils/chain-id.d.cts.map +0 -1
  133. package/dist/utils/chain-id.d.mts +0 -8
  134. package/dist/utils/chain-id.d.mts.map +0 -1
  135. package/dist/utils/chain-id.mjs.map +0 -1
  136. package/dist/utils/gas-fees.cjs +0 -194
  137. package/dist/utils/gas-fees.cjs.map +0 -1
  138. package/dist/utils/gas-fees.d.cts.map +0 -1
  139. package/dist/utils/gas-fees.d.mts +0 -24
  140. package/dist/utils/gas-fees.d.mts.map +0 -1
  141. package/dist/utils/gas-fees.mjs.map +0 -1
  142. package/dist/utils/gas.cjs +0 -72
  143. package/dist/utils/gas.cjs.map +0 -1
  144. package/dist/utils/gas.d.cts +0 -10
  145. package/dist/utils/gas.d.cts.map +0 -1
  146. package/dist/utils/gas.d.mts.map +0 -1
  147. package/dist/utils/gas.mjs.map +0 -1
  148. package/dist/utils/transaction.cjs +0 -117
  149. package/dist/utils/transaction.cjs.map +0 -1
  150. package/dist/utils/transaction.d.cts.map +0 -1
  151. package/dist/utils/transaction.d.mts +0 -10
  152. package/dist/utils/transaction.d.mts.map +0 -1
  153. package/dist/utils/transaction.mjs.map +0 -1
  154. package/dist/utils/validation.cjs +0 -162
  155. package/dist/utils/validation.cjs.map +0 -1
  156. package/dist/utils/validation.d.cts.map +0 -1
  157. package/dist/utils/validation.d.mts +0 -33
  158. package/dist/utils/validation.d.mts.map +0 -1
  159. package/dist/utils/validation.mjs.map +0 -1
@@ -0,0 +1,74 @@
1
+ import { createModuleLogger, projectLogger } from '../logger.js';
2
+ const log = createModuleLogger(projectLogger, 'bundler');
3
+ /**
4
+ * A helper class for interacting with a bundler.
5
+ */
6
+ export class Bundler {
7
+ #url;
8
+ constructor(url) {
9
+ this.#url = url;
10
+ }
11
+ /**
12
+ * Estimate the gas required to execute a user operation.
13
+ *
14
+ * @param userOperation - The user operation to estimate gas for.
15
+ * @param entrypoint - The address of entrypoint to use for the user operation.
16
+ * @returns The estimated gas limits for the user operation.
17
+ */
18
+ async estimateUserOperationGas(userOperation, entrypoint) {
19
+ log('Estimating gas', { url: this.#url, userOperation, entrypoint });
20
+ const response = await this.#query('eth_estimateUserOperationGas', [userOperation, entrypoint]);
21
+ log('Estimated gas', { response });
22
+ return response;
23
+ }
24
+ /**
25
+ * Retrieve the receipt for a user operation.
26
+ *
27
+ * @param hash - The hash of the user operation.
28
+ * @returns The receipt for the user operation, or `undefined` if the user operation is pending.
29
+ */
30
+ async getUserOperationReceipt(hash) {
31
+ log('Getting user operation receipt', { url: this.#url, hash });
32
+ return await this.#query('eth_getUserOperationReceipt', [hash]);
33
+ }
34
+ /**
35
+ * Submit a user operation to the bundler.
36
+ *
37
+ * @param userOperation - The signed user operation to submit.
38
+ * @param entrypoint - The address of entrypoint to use for the user operation.
39
+ * @returns The hash of the user operation.
40
+ */
41
+ async sendUserOperation(userOperation, entrypoint) {
42
+ log('Sending user operation', {
43
+ url: this.#url,
44
+ userOperation,
45
+ entrypoint,
46
+ });
47
+ const hash = await this.#query('eth_sendUserOperation', [
48
+ userOperation,
49
+ entrypoint,
50
+ ]);
51
+ log('Sent user operation', hash);
52
+ return hash;
53
+ }
54
+ async #query(method, params) {
55
+ const request = {
56
+ method: 'POST',
57
+ headers: {
58
+ Accept: 'application/json',
59
+ 'Content-Type': 'application/json',
60
+ },
61
+ body: JSON.stringify({ jsonrpc: '2.0', id: 1, method, params }),
62
+ };
63
+ const response = await fetch(this.#url, request);
64
+ const responseJson = await response.json();
65
+ if (responseJson.error) {
66
+ const error = new Error(responseJson.error.message || responseJson.error);
67
+ error.code =
68
+ responseJson.error.code;
69
+ throw error;
70
+ }
71
+ return responseJson.result;
72
+ }
73
+ }
74
+ //# sourceMappingURL=Bundler.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Bundler.js","sourceRoot":"","sources":["../../src/helpers/Bundler.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,kBAAkB,EAAE,aAAa,EAAE,MAAM,cAAc,CAAC;AAGjE,MAAM,GAAG,GAAG,kBAAkB,CAAC,aAAa,EAAE,SAAS,CAAC,CAAC;AAoBzD;;GAEG;AACH,MAAM,OAAO,OAAO;IACT,IAAI,CAAS;IAEtB,YAAY,GAAW;QACrB,IAAI,CAAC,IAAI,GAAG,GAAG,CAAC;IAClB,CAAC;IAED;;;;;;OAMG;IACH,KAAK,CAAC,wBAAwB,CAC5B,aAA4B,EAC5B,UAAkB;QAElB,GAAG,CAAC,gBAAgB,EAAE,EAAE,GAAG,EAAE,IAAI,CAAC,IAAI,EAAE,aAAa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I,CAAC,IAAI,EAAE,OAAO,CAAC,CAAC;QACjD,MAAM,YAAY,GAAG,MAAM,QAAQ,CAAC,IAAI,EAAE,CAAC;QAE3C,IAAI,YAAY,CAAC,KAAK,EAAE,CAAC;YACvB,MAAM,KAAK,GAAG,IAAI,KAAK,CAAC,YAAY,CAAC,KAAK,CAAC,OAAO,IAAI,YAAY,CAAC,KAAK,CAAC,CAAC;YAEzE,KAA2C,CAAC,IAAI;gBAC/C,YAAY,CAAC,KAAK,CAAC,IAAI,CAAC;YAE1B,MAAM,KAAK,CAAC;QACd,CAAC;QAED,OAAO,YAAY,CAAC,MAAM,CAAC;IAC7B,CAAC;CACF","sourcesContent":["import { createModuleLogger, projectLogger } from '../logger.js';\nimport type { UserOperation, UserOperationReceipt } from '../types.js';\n\nconst log = createModuleLogger(projectLogger, 'bundler');\n\n/**\n * Response from the `eth_estimateUserOperationGas` bundler method.\n * Includes the estimated gas limits required by a user operation.\n */\nexport type BundlerEstimateUserOperationGasResponse = {\n /** Estimated gas required to compensate the bundler for any pre-verification. */\n preVerificationGas: number | string;\n\n /** Estimated gas required to verify the user operation. */\n verificationGas?: number | string;\n\n /** Estimated gas required to verify the user operation. */\n verificationGasLimit?: number | string;\n\n /** Estimated gas required for the execution of the user operation. */\n callGasLimit: number | string;\n};\n\n/**\n * A helper class for interacting with a bundler.\n */\nexport class Bundler {\n readonly #url: string;\n\n constructor(url: string) {\n this.#url = url;\n }\n\n /**\n * Estimate the gas required to execute a user operation.\n *\n * @param userOperation - The user operation to estimate gas for.\n * @param entrypoint - The address of entrypoint to use for the user operation.\n * @returns The estimated gas limits for the user operation.\n */\n async estimateUserOperationGas(\n userOperation: UserOperation,\n entrypoint: string,\n ): Promise<BundlerEstimateUserOperationGasResponse> {\n log('Estimating gas', { url: this.#url, userOperation, entrypoint });\n\n const response: BundlerEstimateUserOperationGasResponse = await this.#query(\n 'eth_estimateUserOperationGas',\n [userOperation, entrypoint],\n );\n\n log('Estimated gas', { response });\n\n return response;\n }\n\n /**\n * Retrieve the receipt for a user operation.\n *\n * @param hash - The hash of the user operation.\n * @returns The receipt for the user operation, or `undefined` if the user operation is pending.\n */\n async getUserOperationReceipt(\n hash?: string,\n ): Promise<UserOperationReceipt | undefined> {\n log('Getting user operation receipt', { url: this.#url, hash });\n\n return await this.#query<UserOperationReceipt | undefined>(\n 'eth_getUserOperationReceipt',\n [hash],\n );\n }\n\n /**\n * Submit a user operation to the bundler.\n *\n * @param userOperation - The signed user operation to submit.\n * @param entrypoint - The address of entrypoint to use for the user operation.\n * @returns The hash of the user operation.\n */\n async sendUserOperation(\n userOperation: UserOperation,\n entrypoint: string,\n ): Promise<string> {\n log('Sending user operation', {\n url: this.#url,\n userOperation,\n entrypoint,\n });\n\n const hash: string = await this.#query('eth_sendUserOperation', [\n userOperation,\n entrypoint,\n ]);\n\n log('Sent user operation', hash);\n\n return hash;\n }\n\n async #query<T>(method: string, params: unknown[]): Promise<T> {\n const request = {\n method: 'POST',\n headers: {\n Accept: 'application/json',\n 'Content-Type': 'application/json',\n },\n body: JSON.stringify({ jsonrpc: '2.0', id: 1, method, params }),\n };\n\n const response = await fetch(this.#url, request);\n const responseJson = await response.json();\n\n if (responseJson.error) {\n const error = new Error(responseJson.error.message || responseJson.error);\n\n (error as unknown as Record<string, string>).code =\n responseJson.error.code;\n\n throw error;\n }\n\n return responseJson.result;\n }\n}\n"]}
@@ -1,9 +1,7 @@
1
- /// <reference types="node" />
2
- /// <reference types="npm-which/node_modules/@types/node/events.js" />
3
- import type { NetworkClient, NetworkClientId } from "@metamask/network-controller";
4
- import EventEmitter from "events";
5
- import type { UserOperationMetadata } from "../types.cjs";
6
- import type { UserOperationControllerMessenger } from "../UserOperationController.cjs";
1
+ import type { NetworkClient, NetworkClientId } from '@metamask/network-controller';
2
+ import EventEmitter from 'events';
3
+ import type { UserOperationMetadata } from '../types.js';
4
+ import type { UserOperationControllerMessenger } from '../UserOperationController.js';
7
5
  type Events = {
8
6
  'user-operation-confirmed': [metadata: UserOperationMetadata];
9
7
  'user-operation-failed': [txMeta: UserOperationMetadata, error: Error];
@@ -19,12 +17,12 @@ type PendingUserOperationPollingInput = {
19
17
  networkClientId: NetworkClientId;
20
18
  };
21
19
  declare const PendingUserOperationTracker_base: (abstract new (...args: any[]) => {
22
- "__#21@#activeListeners": Record<string, (options: import("@metamask/utils").Json) => Promise<void>>;
23
- _getNetworkClientById(networkClientId: string): NetworkClient | undefined;
20
+ _activeListeners: Record<string, (options: import("@metamask/utils").Json) => Promise<void>>;
21
+ _getNetworkClientById(networkClientId: NetworkClientId): NetworkClient | undefined;
24
22
  _startPolling(input: PendingUserOperationPollingInput): void;
25
- _stopPollingByPollingTokenSetId(key: string): void;
26
- readonly "__#3@#pollingTokenSets": Map<string, Set<string>>;
27
- readonly "__#3@#callbacks": Map<string, Set<(input: PendingUserOperationPollingInput) => void>>;
23
+ _stopPollingByPollingTokenSetId(key: import("@metamask/polling-controller").PollingTokenSetId): void;
24
+ readonly _pollingTokenSets: Map<import("@metamask/polling-controller").PollingTokenSetId, Set<string>>;
25
+ readonly _callbacks: Map<string, Set<(input: PendingUserOperationPollingInput) => void>>;
28
26
  _executePoll(input: PendingUserOperationPollingInput): Promise<void>;
29
27
  startPolling(input: PendingUserOperationPollingInput): string;
30
28
  stopAllPolling(): void;
@@ -48,4 +46,4 @@ export declare class PendingUserOperationTracker extends PendingUserOperationTra
48
46
  _getNetworkClientById(networkClientId: string): NetworkClient | undefined;
49
47
  }
50
48
  export {};
51
- //# sourceMappingURL=PendingUserOperationTracker.d.cts.map
49
+ //# sourceMappingURL=PendingUserOperationTracker.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"PendingUserOperationTracker.d.ts","sourceRoot":"","sources":["../../src/helpers/PendingUserOperationTracker.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EACV,aAAa,EACb,eAAe,EAEhB,MAAM,8BAA8B,CAAC;AAKtC,OAAO,YAAY,MAAM,QAAQ,CAAC;AAIlC,OAA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AAE,EAAE,gCAAgC,iBAevE;IAED,qBAAqB,CAAC,eAAe,EAAE,MAAM,GAAG,aAAa,GAAG,SAAS,CAKxE;CAkIF"}
@@ -0,0 +1,115 @@
1
+ import { query, toHex } from '@metamask/controller-utils';
2
+ import EthQuery from '@metamask/eth-query';
3
+ import { createModuleLogger } from '@metamask/utils';
4
+ // This package purposefully relies on Node's EventEmitter module.
5
+ // eslint-disable-next-line import-x/no-nodejs-modules
6
+ import EventEmitter from 'events';
7
+ import { BlockTrackerPollingControllerOnly } from '../BlockTrackerPollingController.js';
8
+ import { projectLogger } from '../logger.js';
9
+ import { UserOperationStatus } from '../types.js';
10
+ import { Bundler } from './Bundler.js';
11
+ const log = createModuleLogger(projectLogger, 'pending-user-operations');
12
+ /**
13
+ * A helper class to periodically query the bundlers
14
+ * and update the status of any submitted user operations.
15
+ */
16
+ export class PendingUserOperationTracker extends BlockTrackerPollingControllerOnly() {
17
+ hub;
18
+ #getUserOperations;
19
+ #messenger;
20
+ constructor({ getUserOperations, messenger, }) {
21
+ super();
22
+ this.hub = new EventEmitter();
23
+ this.#getUserOperations = getUserOperations;
24
+ this.#messenger = messenger;
25
+ }
26
+ async _executePoll({ networkClientId }) {
27
+ try {
28
+ const { blockTracker, configuration, provider } = this._getNetworkClientById(networkClientId);
29
+ log('Polling', {
30
+ blockNumber: blockTracker.getCurrentBlock(),
31
+ chainId: configuration.chainId,
32
+ });
33
+ await this.#checkUserOperations(configuration.chainId, provider);
34
+ }
35
+ catch (error) {
36
+ /* istanbul ignore next */
37
+ log('Failed to check user operations', error);
38
+ }
39
+ }
40
+ _getNetworkClientById(networkClientId) {
41
+ return this.#messenger.call('NetworkController:getNetworkClientById', networkClientId);
42
+ }
43
+ async #checkUserOperations(chainId, provider) {
44
+ const pendingUserOperations = this.#getPendingUserOperations().filter((metadata) => metadata.chainId === chainId);
45
+ if (!pendingUserOperations.length) {
46
+ log('No pending user operations to check');
47
+ return;
48
+ }
49
+ log('Found pending user operations to check', {
50
+ count: pendingUserOperations.length,
51
+ ids: pendingUserOperations.map((userOperation) => userOperation.id),
52
+ });
53
+ await Promise.all(pendingUserOperations.map((userOperation) => this.#checkUserOperation(userOperation, provider)));
54
+ }
55
+ async #checkUserOperation(metadata, provider) {
56
+ const { bundlerUrl, hash, id } = metadata;
57
+ if (!hash || !bundlerUrl) {
58
+ log('Skipping user operation as missing hash or bundler', id);
59
+ return;
60
+ }
61
+ try {
62
+ const receipt = await this.#getUserOperationReceipt(hash, bundlerUrl);
63
+ const isSuccess = receipt?.success;
64
+ if (receipt && !isSuccess) {
65
+ this.#onUserOperationFailed(metadata, receipt);
66
+ return;
67
+ }
68
+ if (isSuccess) {
69
+ await this.#onUserOperationConfirmed(metadata, receipt, provider);
70
+ return;
71
+ }
72
+ log('No receipt found for user operation', { id, hash });
73
+ }
74
+ catch (error) {
75
+ log('Failed to check user operation', id, error);
76
+ }
77
+ }
78
+ async #onUserOperationConfirmed(metadata, receipt, provider) {
79
+ const { id } = metadata;
80
+ const { actualGasCost, actualGasUsed, receipt: { blockHash, transactionHash }, } = receipt;
81
+ log('User operation confirmed', id, transactionHash);
82
+ const { baseFeePerGas } = await query(new EthQuery(provider), 'getBlockByHash', [blockHash, false]);
83
+ metadata.actualGasCost = this.#normalizeGasValue(actualGasCost);
84
+ metadata.actualGasUsed = this.#normalizeGasValue(actualGasUsed);
85
+ metadata.baseFeePerGas = baseFeePerGas;
86
+ metadata.status = UserOperationStatus.Confirmed;
87
+ metadata.transactionHash = transactionHash;
88
+ this.#updateUserOperation(metadata);
89
+ this.hub.emit('user-operation-confirmed', metadata);
90
+ }
91
+ #onUserOperationFailed(metadata, _receipt) {
92
+ const { id } = metadata;
93
+ log('User operation failed', id);
94
+ metadata.status = UserOperationStatus.Failed;
95
+ this.#updateUserOperation(metadata);
96
+ this.hub.emit('user-operation-failed', metadata, new Error('User operation receipt has failed status'));
97
+ }
98
+ #getPendingUserOperations() {
99
+ return this.#getUserOperations().filter((userOperation) => userOperation.status === UserOperationStatus.Submitted);
100
+ }
101
+ #updateUserOperation(metadata) {
102
+ this.hub.emit('user-operation-updated', metadata);
103
+ }
104
+ async #getUserOperationReceipt(hash, bundlerUrl) {
105
+ const bundler = new Bundler(bundlerUrl);
106
+ return bundler.getUserOperationReceipt(hash);
107
+ }
108
+ #normalizeGasValue(gasValue) {
109
+ if (typeof gasValue === 'number') {
110
+ return toHex(gasValue);
111
+ }
112
+ return gasValue;
113
+ }
114
+ }
115
+ //# sourceMappingURL=PendingUserOperationTracker.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"PendingUserOperationTracker.js","sourceRoot":"","sources":["../../src/helpers/PendingUserOperationTracker.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,KAAK,EAAE,MAAM,4BAA4B,CAAC;AAC1D,OAAO,QAAQ,MAAM,qBAAqB,CAAC;AAM3C,OAAO,EAAE,kBAAkB,EAAE,MAAM,iBAAiB,CAAC;AAErD,kEAAkE;AAClE,sDAAsD;AACtD,OAAO,YAAY,MAAM,QAAQ,CAAC;AAElC,OAAO,EAAE,iCAAiC,EAAE,MAAM,qCAAqC,CAAC;AACxF,OAAO,EAAE,aAAa,EAAE,MAAM,cAAc,CAAC;AAE7C,OAAO,EAAE,mBAAmB,EAAE,MAAM,aAAa,CAAC;AAElD,OAAO,EAAE,OAAO,EAAE,MAAM,cAAc,CAAC;AAEvC,MAAM,GAAG,GAAG,kBAAkB,CAAC,aAAa,EAAE,yBAAyB,CAAC,CAAC;AA2BzE;;;GAGG;AACH,MAAM,OAAO,2BAA4B,SAAQ,iCAAiC,EAAoC;IACpH,GAAG,CAA0C;IAEpC,kBAAkB,CAAgC;IAElD,UAAU,CAAmC;IAEtD,YAAY,EACV,iBAAiB,EACjB,SAAS,GAIV;QACC,KAAK,EAAE,CAAC;QAER,IAAI,CAAC,GAAG,GAAG,IAAI,YAAY,EAA6C,CAAC;QAEzE,IAAI,CAAC,kBAAkB,GAAG,iBAAiB,CAAC;QAC5C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ClD,IAAI,CAAC,GAAG,CAAC,IAAI,CAAC,wBAAwB,EAAE,QAAQ,CAAC,CAAC;IACpD,CAAC;IAED,KAAK,CAAC,wBAAwB,CAC5B,IAAY,EACZ,UAAkB;QAElB,MAAM,OAAO,GAAG,IAAI,OAAO,CAAC,UAAU,CAAC,CAAC;QACxC,OAAO,OAAO,CAAC,uBAAuB,CAAC,IAAI,CAAC,CAAC;IAC/C,CAAC;IAED,kBAAkB,CAAC,QAAsB;QACvC,IAAI,OAAO,QAAQ,KAAK,QAAQ,EAAE,CAAC;YACjC,OAAO,KAAK,CAAC,QAAQ,CAAC,CAAC;QACzB,CAAC;QACD,OAAO,QAAQ,CAAC;IAClB,CAAC;CACF","sourcesContent":["import { query, toHex } from '@metamask/controller-utils';\nimport EthQuery from '@metamask/eth-query';\nimport type {\n NetworkClient,\n NetworkClientId,\n Provider,\n} from '@metamask/network-controller';\nimport { createModuleLogger } from '@metamask/utils';\nimport type { Hex } 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';\n\nimport { BlockTrackerPollingControllerOnly } from '../BlockTrackerPollingController.js';\nimport { projectLogger } from '../logger.js';\nimport type { UserOperationMetadata, UserOperationReceipt } from '../types.js';\nimport { UserOperationStatus } from '../types.js';\nimport type { UserOperationControllerMessenger } from '../UserOperationController.js';\nimport { Bundler } from './Bundler.js';\n\nconst log = createModuleLogger(projectLogger, 'pending-user-operations');\n\ntype Events = {\n 'user-operation-confirmed': [metadata: UserOperationMetadata];\n 'user-operation-failed': [txMeta: UserOperationMetadata, error: Error];\n 'user-operation-updated': [txMeta: UserOperationMetadata];\n};\n\nexport type PendingUserOperationTrackerEventEmitter = EventEmitter & {\n on<T extends keyof Events>(\n eventName: T,\n listener: (...args: Events[T]) => void,\n ): PendingUserOperationTrackerEventEmitter;\n\n once<T extends keyof Events>(\n eventName: T,\n listener: (...args: Events[T]) => void,\n ): PendingUserOperationTrackerEventEmitter;\n\n emit<T extends keyof Events>(eventName: T, ...args: Events[T]): boolean;\n};\n\n/** The input to start polling for the {@link PendingUserOperationTracker} */\ntype PendingUserOperationPollingInput = {\n networkClientId: NetworkClientId;\n};\n\n/**\n * A helper class to periodically query the bundlers\n * and update the status of any submitted user operations.\n */\nexport class PendingUserOperationTracker extends BlockTrackerPollingControllerOnly<PendingUserOperationPollingInput>() {\n hub: PendingUserOperationTrackerEventEmitter;\n\n readonly #getUserOperations: () => UserOperationMetadata[];\n\n readonly #messenger: UserOperationControllerMessenger;\n\n constructor({\n getUserOperations,\n messenger,\n }: {\n getUserOperations: () => UserOperationMetadata[];\n messenger: UserOperationControllerMessenger;\n }) {\n super();\n\n this.hub = new EventEmitter() as PendingUserOperationTrackerEventEmitter;\n\n this.#getUserOperations = getUserOperations;\n this.#messenger = messenger;\n }\n\n async _executePoll({ networkClientId }: PendingUserOperationPollingInput) {\n try {\n const { blockTracker, configuration, provider } =\n this._getNetworkClientById(networkClientId) as NetworkClient;\n\n log('Polling', {\n blockNumber: blockTracker.getCurrentBlock(),\n chainId: configuration.chainId,\n });\n\n await this.#checkUserOperations(configuration.chainId, provider);\n } catch (error) {\n /* istanbul ignore next */\n log('Failed to check user operations', error);\n }\n }\n\n _getNetworkClientById(networkClientId: string): NetworkClient | undefined {\n return this.#messenger.call(\n 'NetworkController:getNetworkClientById',\n networkClientId,\n );\n }\n\n async #checkUserOperations(chainId: string, provider: Provider) {\n const pendingUserOperations = this.#getPendingUserOperations().filter(\n (metadata) => metadata.chainId === chainId,\n );\n\n if (!pendingUserOperations.length) {\n log('No pending user operations to check');\n return;\n }\n\n log('Found pending user operations to check', {\n count: pendingUserOperations.length,\n ids: pendingUserOperations.map((userOperation) => userOperation.id),\n });\n\n await Promise.all(\n pendingUserOperations.map((userOperation) =>\n this.#checkUserOperation(userOperation, provider),\n ),\n );\n }\n\n async #checkUserOperation(\n metadata: UserOperationMetadata,\n provider: Provider,\n ) {\n const { bundlerUrl, hash, id } = metadata;\n\n if (!hash || !bundlerUrl) {\n log('Skipping user operation as missing hash or bundler', id);\n return;\n }\n\n try {\n const receipt = await this.#getUserOperationReceipt(hash, bundlerUrl);\n const isSuccess = receipt?.success;\n\n if (receipt && !isSuccess) {\n this.#onUserOperationFailed(metadata, receipt);\n return;\n }\n\n if (isSuccess) {\n await this.#onUserOperationConfirmed(metadata, receipt, provider);\n return;\n }\n\n log('No receipt found for user operation', { id, hash });\n } catch (error) {\n log('Failed to check user operation', id, error);\n }\n }\n\n async #onUserOperationConfirmed(\n metadata: UserOperationMetadata,\n receipt: UserOperationReceipt,\n provider: Provider,\n ) {\n const { id } = metadata;\n\n const {\n actualGasCost,\n actualGasUsed,\n receipt: { blockHash, transactionHash },\n } = receipt;\n\n log('User operation confirmed', id, transactionHash);\n\n const { baseFeePerGas } = await query(\n new EthQuery(provider),\n 'getBlockByHash',\n [blockHash, false],\n );\n\n metadata.actualGasCost = this.#normalizeGasValue(actualGasCost);\n metadata.actualGasUsed = this.#normalizeGasValue(actualGasUsed);\n metadata.baseFeePerGas = baseFeePerGas;\n metadata.status = UserOperationStatus.Confirmed;\n metadata.transactionHash = transactionHash;\n\n this.#updateUserOperation(metadata);\n\n this.hub.emit('user-operation-confirmed', metadata);\n }\n\n #onUserOperationFailed(\n metadata: UserOperationMetadata,\n _receipt: UserOperationReceipt,\n ) {\n const { id } = metadata;\n\n log('User operation failed', id);\n\n metadata.status = UserOperationStatus.Failed;\n\n this.#updateUserOperation(metadata);\n\n this.hub.emit(\n 'user-operation-failed',\n metadata,\n new Error('User operation receipt has failed status'),\n );\n }\n\n #getPendingUserOperations(): UserOperationMetadata[] {\n return this.#getUserOperations().filter(\n (userOperation) => userOperation.status === UserOperationStatus.Submitted,\n );\n }\n\n #updateUserOperation(metadata: UserOperationMetadata) {\n this.hub.emit('user-operation-updated', metadata);\n }\n\n async #getUserOperationReceipt(\n hash: string,\n bundlerUrl: string,\n ): Promise<UserOperationReceipt | undefined> {\n const bundler = new Bundler(bundlerUrl);\n return bundler.getUserOperationReceipt(hash);\n }\n\n #normalizeGasValue(gasValue: Hex | number): string {\n if (typeof gasValue === 'number') {\n return toHex(gasValue);\n }\n return gasValue;\n }\n}\n"]}
@@ -1,5 +1,5 @@
1
- import type { PrepareUserOperationRequest, PrepareUserOperationResponse, SignUserOperationRequest, SignUserOperationResponse, SmartContractAccount, UpdateUserOperationRequest, UpdateUserOperationResponse } from "../types.cjs";
2
- import type { UserOperationControllerMessenger } from "../UserOperationController.cjs";
1
+ import type { PrepareUserOperationRequest, PrepareUserOperationResponse, SignUserOperationRequest, SignUserOperationResponse, SmartContractAccount, UpdateUserOperationRequest, UpdateUserOperationResponse } from '../types.js';
2
+ import type { UserOperationControllerMessenger } from '../UserOperationController.js';
3
3
  export declare class SnapSmartContractAccount implements SmartContractAccount {
4
4
  #private;
5
5
  constructor(messenger: UserOperationControllerMessenger);
@@ -7,4 +7,4 @@ export declare class SnapSmartContractAccount implements SmartContractAccount {
7
7
  updateUserOperation(request: UpdateUserOperationRequest): Promise<UpdateUserOperationResponse>;
8
8
  signUserOperation(request: SignUserOperationRequest): Promise<SignUserOperationResponse>;
9
9
  }
10
- //# sourceMappingURL=SnapSmartContractAccount.d.cts.map
10
+ //# sourceMappingURL=SnapSmartContractAccount.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"SnapSmartContractAccount.d.ts","sourceRoot":"","sources":["../../src/helpers/SnapSmartContractAccount.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EACV,2BAA2B,EAC3B,4BAA4B,EAC5B,wBAAwB,EACxB,yBAAyB,EACzB,oBAAoB,EACpB,0BAA0B,EAC1B,2BAA2B,EAC5B,MAAM,aAAa,CAAC;AACrB,OAAO,KAAK,EAAE,gCAAgC,EAAE,MAAM,+BAA+B,CAAC;AAGtF,qBAAa,wBAAyB,YAAW,oBAAoB;;IAGnE,YAAY,SAAS,EAAE,gCAAgC,EAEtD;IAEK,oBAAoB,CACxB,OAAO,EAAE,2BAA2B,GACnC,OAAO,CAAC,4BAA4B,CAAC,CAwCvC;IAEK,mBAAmB,CACvB,OAAO,EAAE,0BAA0B,GAClC,OAAO,CAAC,2BAA2B,CAAC,CA2BtC;IAEK,iBAAiB,CACrB,OAAO,EAAE,wBAAwB,GAChC,OAAO,CAAC,yBAAyB,CAAC,CAYpC;CACF"}
@@ -0,0 +1,47 @@
1
+ import { ADDRESS_ZERO, EMPTY_BYTES, VALUE_ZERO } from '../constants.js';
2
+ import { toEip155ChainId } from '../utils/chain-id.js';
3
+ export class SnapSmartContractAccount {
4
+ #messenger;
5
+ constructor(messenger) {
6
+ this.#messenger = messenger;
7
+ }
8
+ async prepareUserOperation(request) {
9
+ const { chainId, data: requestData, from: sender, to: requestTo, value: requestValue, } = request;
10
+ const data = requestData ?? EMPTY_BYTES;
11
+ const to = requestTo ?? ADDRESS_ZERO;
12
+ const value = requestValue ?? VALUE_ZERO;
13
+ const response = await this.#messenger.call('KeyringController:prepareUserOperation', sender, [{ data, to, value }], { chainId: toEip155ChainId(chainId) });
14
+ const { bundlerUrl: bundler, callData, dummyPaymasterAndData, dummySignature, gasLimits: gas, initCode, nonce, } = response;
15
+ return {
16
+ bundler,
17
+ callData,
18
+ dummyPaymasterAndData,
19
+ dummySignature,
20
+ gas,
21
+ initCode,
22
+ nonce,
23
+ sender,
24
+ };
25
+ }
26
+ async updateUserOperation(request) {
27
+ const { userOperation, chainId } = request;
28
+ const { sender } = userOperation;
29
+ const { paymasterAndData: responsePaymasterAndData, verificationGasLimit, preVerificationGas, callGasLimit, } = await this.#messenger.call('KeyringController:patchUserOperation', sender, userOperation, { chainId: toEip155ChainId(chainId) });
30
+ const paymasterAndData = responsePaymasterAndData === EMPTY_BYTES
31
+ ? undefined
32
+ : responsePaymasterAndData;
33
+ return {
34
+ paymasterAndData,
35
+ verificationGasLimit,
36
+ preVerificationGas,
37
+ callGasLimit,
38
+ };
39
+ }
40
+ async signUserOperation(request) {
41
+ const { userOperation, chainId } = request;
42
+ const { sender } = userOperation;
43
+ const signature = await this.#messenger.call('KeyringController:signUserOperation', sender, userOperation, { chainId: toEip155ChainId(chainId) });
44
+ return { signature };
45
+ }
46
+ }
47
+ //# sourceMappingURL=SnapSmartContractAccount.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"SnapSmartContractAccount.js","sourceRoot":"","sources":["../../src/helpers/SnapSmartContractAccount.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,WAAW,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAC;AAWxE,OAAO,EAAE,eAAe,EAAE,MAAM,sBAAsB,CAAC;AAEvD,MAAM,OAAO,wBAAwB;IAC1B,UAAU,CAAmC;IAEtD,YAAY,SAA2C;QACrD,IAAI,CAAC,UAAU,GAAG,SAAS,CAAC;IAC9B,CAAC;IAED,KAAK,CAAC,oBAAoB,CACxB,OAAoC;QAEpC,MAAM,EACJ,OAAO,EACP,IAAI,EAAE,WAAW,EACjB,IAAI,EAAE,MAAM,EACZ,EAAE,EAAE,SAAS,EACb,KAAK,EAAE,YAAY,GACpB,GAAG,OAAO,CAAC;QAEZ,MAAM,IAAI,GAAG,WAAW,IAAI,WAAW,CAAC;QACxC,MAAM,EAAE,GAAG,SAAS,IAAI,YAAY,CAAC;QACrC,MAAM,KAAK,GAAG,YAAY,IAAI,UAAU,CAAC;QAEzC,MAAM,QAAQ,GAAG,MAAM,IAAI,CAAC,UAAU,CAAC,IAAI,CACzC,wCAAwC,EACxC,MAAM,EACN,CAAC,EAAE,IAAI,EAAE,EAAE,EAAE,KAAK,EAAE,CAAC,EACrB,EAAE,OAAO,EAAE,eAAe,CAAC,OAAO,CAAC,EAAE,CACtC,CAAC;QAEF,MAAM,EACJ,UAAU,EAAE,OAAO,EACnB,QAAQ,EACR,qBAAqB,EACrB,cAAc,EACd,SAAS,EAAE,GAAG,EACd,QAAQ,EACR,KAAK,GACN,GAAG,QAAQ,CAAC;QAEb,OAAO;YACL,OAAO;YACP,QAAQ;YACR,qBAAqB;YACrB,cAAc;YACd,GAAG;YACH,QAAQ;YACR,KAAK;YACL,MAAM;SACP,CAAC;IACJ,CAAC;IAED,KAAK,CAAC,mBAAmB,CACvB,OAAmC;QAEnC,MAAM,EAAE,aAAa,EAAE,OAAO,EAAE,GAAG,OAAO,CAAC;QAC3C,MAAM,EAAE,MAAM,EAAE,GAAG,aAAa,CAAC;QAEjC,MAAM,EACJ,gBAAgB,EAAE,wBAAwB,EAC1C,oBAAoB,EACpB,kBAAkB,EAClB,YAAY,GACb,GAAG,MAAM,IAAI,CAAC,UAAU,CAAC,IAAI,CAC5B,sCAAsC,EACtC,MAAM,EACN,aAAa,EACb,EAAE,OAAO,EAAE,eAAe,CAAC,OAAO,CAAC,EAAE,CACtC,CAAC;QAEF,MAAM,gBAAgB,GACpB,wBAAwB,KAAK,WAAW;YACtC,CAAC,CAAC,SAAS;YACX,CAAC,CAAC,wBAAwB,CAAC;QAE/B,OAAO;YACL,gBAAgB;YAChB,oBAAoB;YACpB,kBAAkB;YAClB,YAAY;SACb,CAAC;IACJ,CAAC;IAED,KAAK,CAAC,iBAAiB,CACrB,OAAiC;QAEjC,MAAM,EAAE,aAAa,EAAE,OAAO,EAAE,GAAG,OAAO,CAAC;QAC3C,MAAM,EAAE,MAAM,EAAE,GAAG,aAAa,CAAC;QAEjC,MAAM,SAAS,GAAG,MAAM,IAAI,CAAC,UAAU,CAAC,IAAI,CAC1C,qCAAqC,EACrC,MAAM,EACN,aAAa,EACb,EAAE,OAAO,EAAE,eAAe,CAAC,OAAO,CAAC,EAAE,CACtC,CAAC;QAEF,OAAO,EAAE,SAAS,EAAE,CAAC;IACvB,CAAC;CACF","sourcesContent":["import { ADDRESS_ZERO, EMPTY_BYTES, VALUE_ZERO } from '../constants.js';\nimport type {\n PrepareUserOperationRequest,\n PrepareUserOperationResponse,\n SignUserOperationRequest,\n SignUserOperationResponse,\n SmartContractAccount,\n UpdateUserOperationRequest,\n UpdateUserOperationResponse,\n} from '../types.js';\nimport type { UserOperationControllerMessenger } from '../UserOperationController.js';\nimport { toEip155ChainId } from '../utils/chain-id.js';\n\nexport class SnapSmartContractAccount implements SmartContractAccount {\n readonly #messenger: UserOperationControllerMessenger;\n\n constructor(messenger: UserOperationControllerMessenger) {\n this.#messenger = messenger;\n }\n\n async prepareUserOperation(\n request: PrepareUserOperationRequest,\n ): Promise<PrepareUserOperationResponse> {\n const {\n chainId,\n data: requestData,\n from: sender,\n to: requestTo,\n value: requestValue,\n } = request;\n\n const data = requestData ?? EMPTY_BYTES;\n const to = requestTo ?? ADDRESS_ZERO;\n const value = requestValue ?? VALUE_ZERO;\n\n const response = await this.#messenger.call(\n 'KeyringController:prepareUserOperation',\n sender,\n [{ data, to, value }],\n { chainId: toEip155ChainId(chainId) },\n );\n\n const {\n bundlerUrl: bundler,\n callData,\n dummyPaymasterAndData,\n dummySignature,\n gasLimits: gas,\n initCode,\n nonce,\n } = response;\n\n return {\n bundler,\n callData,\n dummyPaymasterAndData,\n dummySignature,\n gas,\n initCode,\n nonce,\n sender,\n };\n }\n\n async updateUserOperation(\n request: UpdateUserOperationRequest,\n ): Promise<UpdateUserOperationResponse> {\n const { userOperation, chainId } = request;\n const { sender } = userOperation;\n\n const {\n paymasterAndData: responsePaymasterAndData,\n verificationGasLimit,\n preVerificationGas,\n callGasLimit,\n } = await this.#messenger.call(\n 'KeyringController:patchUserOperation',\n sender,\n userOperation,\n { chainId: toEip155ChainId(chainId) },\n );\n\n const paymasterAndData =\n responsePaymasterAndData === EMPTY_BYTES\n ? undefined\n : responsePaymasterAndData;\n\n return {\n paymasterAndData,\n verificationGasLimit,\n preVerificationGas,\n callGasLimit,\n };\n }\n\n async signUserOperation(\n request: SignUserOperationRequest,\n ): Promise<SignUserOperationResponse> {\n const { userOperation, chainId } = request;\n const { sender } = userOperation;\n\n const signature = await this.#messenger.call(\n 'KeyringController:signUserOperation',\n sender,\n userOperation,\n { chainId: toEip155ChainId(chainId) },\n );\n\n return { signature };\n }\n}\n"]}
@@ -0,0 +1,4 @@
1
+ export * from './UserOperationController.js';
2
+ export type { UserOperationControllerAddUserOperationAction, UserOperationControllerAddUserOperationFromTransactionAction, UserOperationControllerStartPollingByNetworkClientIdAction, } from './UserOperationController-method-action-types.js';
3
+ export * from './types.js';
4
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,8BAA8B,CAAC;AAC7C,YAAY,EACV,6CAA6C,EAC7C,4DAA4D,EAC5D,0DAA0D,GAC3D,MAAM,kDAAkD,CAAC;AAC1D,cAAc,YAAY,CAAC"}
package/dist/index.js ADDED
@@ -0,0 +1,3 @@
1
+ export * from './UserOperationController.js';
2
+ export * from './types.js';
3
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,8BAA8B,CAAC;AAM7C,cAAc,YAAY,CAAC","sourcesContent":["export * from './UserOperationController.js';\nexport type {\n UserOperationControllerAddUserOperationAction,\n UserOperationControllerAddUserOperationFromTransactionAction,\n UserOperationControllerStartPollingByNetworkClientIdAction,\n} from './UserOperationController-method-action-types.js';\nexport * from './types.js';\n"]}
@@ -0,0 +1,4 @@
1
+ import { createModuleLogger } from '@metamask/utils';
2
+ export declare const projectLogger: import("debug").Debugger;
3
+ export { createModuleLogger };
4
+ //# sourceMappingURL=logger.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"logger.d.ts","sourceRoot":"","sources":["../src/logger.ts"],"names":[],"mappings":"AAEA,OAAO,EAAuB,kBAAkB,EAAE,MAAM,iBAAiB,CAAC;AAE1E,eAAO,MAAM,aAAa,0BAAmD,CAAC;AAE9E,OAAO,EAAE,kBAAkB,EAAE,CAAC"}
@@ -1,5 +1,5 @@
1
1
  /* istanbul ignore file */
2
- import { createProjectLogger, createModuleLogger } from "@metamask/utils";
2
+ import { createProjectLogger, createModuleLogger } from '@metamask/utils';
3
3
  export const projectLogger = createProjectLogger('user-operation-controller');
4
4
  export { createModuleLogger };
5
- //# sourceMappingURL=logger.mjs.map
5
+ //# sourceMappingURL=logger.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"logger.js","sourceRoot":"","sources":["../src/logger.ts"],"names":[],"mappings":"AAAA,0BAA0B;AAE1B,OAAO,EAAE,mBAAmB,EAAE,kBAAkB,EAAE,MAAM,iBAAiB,CAAC;AAE1E,MAAM,CAAC,MAAM,aAAa,GAAG,mBAAmB,CAAC,2BAA2B,CAAC,CAAC;AAE9E,OAAO,EAAE,kBAAkB,EAAE,CAAC","sourcesContent":["/* istanbul ignore file */\n\nimport { createProjectLogger, createModuleLogger } from '@metamask/utils';\n\nexport const projectLogger = createProjectLogger('user-operation-controller');\n\nexport { createModuleLogger };\n"]}
@@ -1,5 +1,5 @@
1
- import type { TransactionParams, TransactionType, UserFeeLevel } from "@metamask/transaction-controller";
2
- import type { Hex } from "@metamask/utils";
1
+ import type { TransactionParams, TransactionType, UserFeeLevel } from '@metamask/transaction-controller';
2
+ import type { Hex } from '@metamask/utils';
3
3
  /**
4
4
  * A complete user operation to be submitted to a bundler.
5
5
  * Defined in EIP-4337.
@@ -291,4 +291,4 @@ export type SwapsMetadata = {
291
291
  /** Value of the token being swapped. */
292
292
  swapTokenValue: string | null;
293
293
  };
294
- //# sourceMappingURL=types.d.mts.map
294
+ //# sourceMappingURL=types.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,iBAAiB,EACjB,eAAe,EACf,YAAY,EACb,MAAM,kCAAkC,CAAC;AAC1C,OAAO,KAAK,EAAE,GAAG,EAAE,MAAM,iBAAiB,CAAC;AAE3C;;;GAGG;AACH,MAAM,MAAM,aAAa,GAAG;IAC1B,qEAAqE;IACrE,QAAQ,EAAE,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MAAM,EAAE,KAAK,CAAC,GAAG,IAAI,CAAC;IAE3C,wCAAwC;IACxC,cAAc,EAAE,MAAM,GAAG,IAAI,CAAC;CAC/B,CAAC"}
@@ -10,4 +10,4 @@ export var UserOperationStatus;
10
10
  UserOperationStatus["Failed"] = "failed";
11
11
  UserOperationStatus["Confirmed"] = "confirmed";
12
12
  })(UserOperationStatus || (UserOperationStatus = {}));
13
- //# sourceMappingURL=types.mjs.map
13
+ //# sourceMappingURL=types.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.js","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AA0DA;;GAEG;AACH,MAAM,CAAN,IAAY,mBAOX;AAPD,WAAY,mBAAmB;IAC7B,gDAAyB,CAAA;IACzB,4CAAqB,CAAA;IACrB,wCAAiB,CAAA;IACjB,8CAAuB,CAAA;IACvB,wCAAiB,CAAA;IACjB,8CAAuB,CAAA;AACzB,CAAC,EAPW,mBAAmB,KAAnB,mBAAmB,QAO9B","sourcesContent":["import type {\n TransactionParams,\n TransactionType,\n UserFeeLevel,\n} from '@metamask/transaction-controller';\nimport type { Hex } from '@metamask/utils';\n\n/**\n * A complete user operation to be submitted to a bundler.\n * Defined in EIP-4337.\n */\nexport type UserOperation = {\n /** The data to pass to the sender during the main execution call. */\n callData: string;\n\n /** The amount of gas to allocate the main execution call. */\n callGasLimit: string;\n\n /**\n * The initCode of the account.\n * Needed if and only if the account is not yet on-chain and needs to be created.\n */\n initCode: string;\n\n /**\n * Maximum fee per gas.\n * Similar to EIP-1559 max_fee_per_gas.\n */\n maxFeePerGas: string;\n\n /**\n * Maximum priority fee per gas.\n * Similar to EIP-1559 max_priority_fee_per_gas.\n */\n maxPriorityFeePerGas: string;\n\n /** Anti-replay parameter. */\n nonce: string;\n\n /**\n * Address of paymaster sponsoring the transaction, followed by extra data to send to the paymaster.\n * Empty for self-sponsored transactions.\n */\n paymasterAndData: string;\n\n /** The amount of gas to pay to compensate the bundler for pre-verification execution, calldata and any gas overhead that cannot be tracked on-chain. */\n preVerificationGas: string;\n\n /** The account making the operation. */\n sender: string;\n\n /** Data passed into the account along with the nonce during the verification step. */\n signature: string;\n\n /** The amount of gas to allocate for the verification step. */\n verificationGasLimit: string;\n};\n\n/**\n * The possible statuses of a single user operation.\n */\nexport enum UserOperationStatus {\n Unapproved = 'unapproved',\n Approved = 'approved',\n Signed = 'signed',\n Submitted = 'submitted',\n Failed = 'failed',\n Confirmed = 'confirmed',\n}\n\n/** Information concerning an error while creating a user operation. */\nexport type UserOperationError = {\n /**\n * A descriptive error name.\n */\n name: string;\n\n /**\n * A descriptive error message providing details about the encountered error.\n */\n message: string;\n\n /**\n * The stack trace associated with the error, if available.\n */\n stack: string | null;\n\n /**\n * An optional error code associated with the error.\n */\n code: string | null;\n\n /**\n * Additional information related to the error.\n */\n rpc: string | null;\n};\n\n/**\n * Metadata concerning a single user operation, stored in the client state.\n */\nexport type UserOperationMetadata = {\n /** Confirmed total cost of the gas for the user operation. */\n actualGasCost: string | null;\n\n /** Confirmed total amount of gas used by the user operation. */\n actualGasUsed: string | null;\n\n /** Base fee of the transaction block as a hex value. */\n baseFeePerGas: string | null;\n\n /** URL of the bundler that the operation was submitted to. */\n bundlerUrl: string | null;\n\n /** Hexadecimal chain ID of the target network. */\n chainId: string;\n\n /** An error that occurred while creating the operation. */\n error: UserOperationError | null;\n\n /** Hash of the user operation, generated by the bundler. */\n hash: string | null;\n\n /** A unique ID used to identify a user operation in the client. */\n id: string;\n\n /** The origin of the user operation, such as the hostname of a dApp. */\n origin: string;\n\n /** Current status of the user operation. */\n status: UserOperationStatus;\n\n /** Metadata specific to swap transactions. */\n swapsMetadata: SwapsMetadata | null;\n\n /** Timestamp of when the user operation was created. */\n time: number;\n\n /** Hash of the transaction that submitted the user operation to the entrypoint. */\n transactionHash: string | null;\n\n /** The initial transaction parameters that the user operation was created from. */\n transactionParams: Required<TransactionParams> | null;\n\n /** The type of transaction that the user operation will create. */\n transactionType: TransactionType | null;\n\n /** The origin of the gas fee values. */\n userFeeLevel: UserFeeLevel | null;\n\n /** Resulting user operation object to be submitted to the bundler. */\n userOperation: UserOperation;\n};\n\n/**\n * The data provided to the smart contract account when preparing a user operation.\n */\nexport type PrepareUserOperationRequest = {\n /** The hexadecimal chain ID of the target network. */\n chainId: string;\n\n /** The data to include in the resulting transaction. */\n data?: string;\n\n /** Address of the account requesting the user operation. */\n from: string;\n\n /** The destination address of the resulting transaction. */\n to?: string;\n\n /** The value to send in the resulting transaction. */\n value?: string;\n};\n\n/**\n * The data provided to the smart contract account when updating a user operation.\n */\nexport type UpdateUserOperationRequest = {\n /** The user operation to update including the dummy signature and dummy paymasterAndData values. */\n userOperation: UserOperation;\n\n /** The hexadecimal chain ID of the target network. */\n chainId: string;\n};\n\n/**\n * The data provided to the smart contract account when signing a user operation.\n */\nexport type SignUserOperationRequest = {\n /** The user operation to sign including the dummy signature and final paymasterAndData values. */\n userOperation: UserOperation;\n\n /** The hexadecimal chain ID of the target network. */\n chainId: string;\n};\n\n/**\n * The data returned by the smart contract account when preparing a user operation.\n */\nexport type PrepareUserOperationResponse = {\n /** The URL of the bundler to submit the user operation to. */\n bundler: string;\n\n /** The data to pass to the sender during the main execution call. */\n callData: string;\n\n /**\n * A dummy paymasterAndData value required to estimate gas using the bundler.\n * Only required if the smart contract account is not providing gas values.\n */\n dummyPaymasterAndData?: string;\n\n /**\n * A dummy signature value required to estimate gas using the bundler.\n * Only required if the smart contract account is not providing gas values.\n */\n dummySignature?: string;\n\n /**\n * The estimated gas limits for the user operation.\n * Gas is automatically estimated using the bundler if not provided.\n */\n gas?: {\n /** The amount of gas to allocate to the main execution call. */\n callGasLimit: string;\n\n /** The amount of gas to pay to compensate the bundler for pre-verification execution, calldata and any gas overhead that cannot be tracked on-chain. */\n preVerificationGas: string;\n\n /** The amount of gas to allocate for the verification step. */\n verificationGasLimit: string;\n };\n\n /**\n * The initCode to include in the user operation.\n * Required only if the smart contract is not yet deployed.\n */\n initCode?: string;\n\n /**\n * The nonce to include in the user operation, specific to the smart contract account.\n */\n nonce: string;\n\n /**\n * The address of the smart contract account creating the user operation.\n */\n sender: string;\n};\n\n/**\n * The data returned by the smart contract account when updating a user operation.\n */\nexport type UpdateUserOperationResponse = {\n /**\n * The final paymasterAndData to include in the user operation.\n * Not required if a paymaster is not sponsoring the transaction.\n */\n paymasterAndData?: string;\n\n /**\n * The final gas limits for the user operation suggested by the smart contract account.\n * The simulated gas limits may be different after the bundler estimates gas with the use\n * of the paymaster.\n */\n callGasLimit?: string;\n preVerificationGas?: string;\n verificationGasLimit?: string;\n};\n\n/**\n * The data returned by the smart contract account when signing a user operation.\n */\nexport type SignUserOperationResponse = {\n /** The final signature of the user operation. */\n signature: string;\n};\n\n/**\n * An abstraction to provide smart contract and paymaster specific data when creating a user operation.\n * This will typically communicate with an account snap installed in the client.\n */\nexport type SmartContractAccount = {\n /**\n * Retrieve the initial values required to create a user operation.\n *\n * @param request - The data needed by the smart contract account to provide the initial user operation values.\n * @returns The initial values required to create a user operation.\n */\n prepareUserOperation: (\n request: PrepareUserOperationRequest,\n ) => Promise<PrepareUserOperationResponse>;\n\n /**\n * Retrieve additional data required to create a user operation, such as the paymasterAndData value.\n * If gas values were not provided in the prepare response, this will be called after estimating gas using the bundler.\n *\n * @param request - The data needed by the smart contract account to provide the additional user operation values.\n * @returns The additional values required to create a user operation.\n */\n updateUserOperation: (\n request: UpdateUserOperationRequest,\n ) => Promise<UpdateUserOperationResponse>;\n\n /**\n * Sign the final user operation.\n *\n * @param request - The data needed by the smart contract account to generate the signature.\n * @returns The final values required to sign a user operation.\n */\n signUserOperation: (\n request: SignUserOperationRequest,\n ) => Promise<SignUserOperationResponse>;\n};\n\n/**\n * Response from the `eth_getUserOperationReceipt` bundler method.\n * Includes the status of a completed user operation and the receipt of the transaction that submitted it.\n */\nexport type UserOperationReceipt = {\n /** Confirmed total cost of the gas for the user operation. */\n actualGasCost: Hex | number;\n\n /** Confirmed total amount of gas used by the user operation. */\n actualGasUsed: Hex | number;\n\n /** True if the user operation was successfully confirmed on chain. */\n success: boolean;\n\n /** Receipt for the associated transaction. */\n receipt: {\n /** Hash of the block the transaction was added to. */\n blockHash: string;\n\n /** Hash of the confirmed transaction. */\n transactionHash: string;\n };\n};\n\n/** Information specific to user operations created from swap transactions. */\nexport type SwapsMetadata = {\n /** ID of the associated approval transaction. */\n approvalTxId: string | null;\n\n /** Address of the destination token. */\n destinationTokenAddress: string | null;\n\n /** Number of decimals of the destination token. */\n destinationTokenDecimals: number | null;\n\n /** Symbol of the destination token. */\n destinationTokenSymbol: string | null;\n\n /** Amount of the destination token. */\n destinationTokenAmount: string | null;\n\n /** Estimated base fee of the swap. */\n estimatedBaseFee: string | null;\n\n /** Address of the source token. */\n sourceTokenAddress: string | null;\n\n /** Amount of the source token. */\n sourceTokenAmount: string | null;\n\n /** Number of decimals of the source token. */\n sourceTokenDecimals: number | null;\n\n /** Symbol of the source token. */\n sourceTokenSymbol: string | null;\n\n /** Recipient of the swap and send transaction. */\n swapAndSendRecipient: string | null;\n\n /** Untyped raw metadata values. */\n swapMetaData: Record<string, never> | null;\n\n /** Value of the token being swapped. */\n swapTokenValue: string | null;\n};\n"]}
@@ -5,4 +5,4 @@
5
5
  * @returns An CAIP-2 chain ID reference for EIP-155 chains.
6
6
  */
7
7
  export declare function toEip155ChainId(chainId: string): string;
8
- //# sourceMappingURL=chain-id.d.cts.map
8
+ //# sourceMappingURL=chain-id.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"chain-id.d.ts","sourceRoot":"","sources":["../../src/utils/chain-id.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AACH,wBAAgB,eAAe,CAAC,OAAO,EAAE,MAAM,GAAG,MAAM,CAMvD"}
@@ -10,4 +10,4 @@ export function toEip155ChainId(chainId) {
10
10
  // to the initial `chainId`.
11
11
  return Number.isInteger(chainIdNumber) ? chainIdNumber.toString() : chainId;
12
12
  }
13
- //# sourceMappingURL=chain-id.mjs.map
13
+ //# sourceMappingURL=chain-id.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"chain-id.js","sourceRoot":"","sources":["../../src/utils/chain-id.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AACH,MAAM,UAAU,eAAe,CAAC,OAAe;IAC7C,MAAM,aAAa,GAAG,MAAM,CAAC,OAAO,CAAC,CAAC;IAEtC,oGAAoG;IACpG,4BAA4B;IAC5B,OAAO,MAAM,CAAC,SAAS,CAAC,aAAa,CAAC,CAAC,CAAC,CAAC,aAAa,CAAC,QAAQ,EAAE,CAAC,CAAC,CAAC,OAAO,CAAC;AAC9E,CAAC","sourcesContent":["/**\n * Converts a chain ID string to a compliant CAIP-2 chain ID reference for EIP-155 chains.\n *\n * @param chainId - Chain ID string\n * @returns An CAIP-2 chain ID reference for EIP-155 chains.\n */\nexport function toEip155ChainId(chainId: string): string {\n const chainIdNumber = Number(chainId);\n\n // If for some reason the chainId isn't convertible to a decimal integer representation, we fallback\n // to the initial `chainId`.\n return Number.isInteger(chainIdNumber) ? chainIdNumber.toString() : chainId;\n}\n"]}
@@ -1,8 +1,8 @@
1
- import type { GasFeeState } from "@metamask/gas-fee-controller";
2
- import type { Provider } from "@metamask/network-controller";
3
- import type { TransactionParams } from "@metamask/transaction-controller";
4
- import type { UserOperationMetadata } from "../types.cjs";
5
- import type { AddUserOperationRequest } from "../UserOperationController.cjs";
1
+ import type { GasFeeState } from '@metamask/gas-fee-controller';
2
+ import type { Provider } from '@metamask/network-controller';
3
+ import type { TransactionParams } from '@metamask/transaction-controller';
4
+ import type { UserOperationMetadata } from '../types.js';
5
+ import type { AddUserOperationRequest } from '../UserOperationController.js';
6
6
  export type UpdateGasFeesRequest = {
7
7
  getGasFeeEstimates: () => Promise<GasFeeState>;
8
8
  metadata: UserOperationMetadata;
@@ -21,4 +21,4 @@ export type UpdateGasFeesRequest = {
21
21
  * @param request.transaction - The transaction that created the user operation.
22
22
  */
23
23
  export declare function updateGasFees(request: UpdateGasFeesRequest): Promise<void>;
24
- //# sourceMappingURL=gas-fees.d.cts.map
24
+ //# sourceMappingURL=gas-fees.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"gas-fees.d.ts","sourceRoot":"","sources":["../../src/utils/gas-fees.ts"],"names":[],"mappings":"AAQA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,8BAA8B,CAAC;AAChE,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,8BAA8B,CAAC;AAC7D,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,kCAAkC,CAAC;AAO1E,OAAO,KAAK,EAAiB,qBAAqB,EAAE,MAAM,aAAa,CAAC;AACxE,OAAO,KAAK,EAAE,uBAAuB,EAAE,MAAM,+BAA+B,CAAC;AAI7E,MAAM,MAAM,oBAAoB,GAAG;IACjC,kBAAkB,EAAE,MAAM,OAAO,CAAC,WAAW,CAAC,CAAC;IAC/C,QAAQ,EAAE,qBAAqB,CAAC;IAChC,eAAe,EAAE,uBAAuB,CAAC;IACzC,QAAQ,EAAE,QAAQ,CAAC;IACnB,WAAW,CAAC,EAAE,iBAAiB,CAAC;CACjC,CAAC;AAOF;;;;;;;;;GASG;AACH,wBAAsB,aAAa,CAAC,OAAO,EAAE,oBAAoB,iBAgChE"}
@@ -1,17 +1,10 @@
1
- function $importDefault(module) {
2
- if (module?.__esModule) {
3
- return module.default;
4
- }
5
- return module;
6
- }
7
- import { gweiDecToWEIBN, ORIGIN_METAMASK, query, toHex } from "@metamask/controller-utils";
8
- import $EthQuery from "@metamask/eth-query";
9
- const EthQuery = $importDefault($EthQuery);
10
- import { GAS_ESTIMATE_TYPES } from "@metamask/gas-fee-controller";
11
- import { UserFeeLevel } from "@metamask/transaction-controller";
12
- import { add0x } from "@metamask/utils";
13
- import { EMPTY_BYTES } from "../constants.mjs";
14
- import { createModuleLogger, projectLogger } from "../logger.mjs";
1
+ import { gweiDecToWEIBN, ORIGIN_METAMASK, query, toHex, } from '@metamask/controller-utils';
2
+ import EthQuery from '@metamask/eth-query';
3
+ import { GAS_ESTIMATE_TYPES } from '@metamask/gas-fee-controller';
4
+ import { UserFeeLevel } from '@metamask/transaction-controller';
5
+ import { add0x } from '@metamask/utils';
6
+ import { EMPTY_BYTES } from '../constants.js';
7
+ import { createModuleLogger, projectLogger } from '../logger.js';
15
8
  const log = createModuleLogger(projectLogger, 'gas-fees');
16
9
  /**
17
10
  * Populates the gas fee properties for a user operation.
@@ -191,4 +184,4 @@ function gweiDecimalToWeiHex(value) {
191
184
  function isGasFeeEmpty(value) {
192
185
  return !value || value === EMPTY_BYTES;
193
186
  }
194
- //# sourceMappingURL=gas-fees.mjs.map
187
+ //# sourceMappingURL=gas-fees.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"gas-fees.js","sourceRoot":"","sources":["../../src/utils/gas-fees.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,cAAc,EACd,eAAe,EACf,KAAK,EACL,KAAK,GACN,MAAM,4BAA4B,CAAC;AACpC,OAAO,QAAQ,MAAM,qBAAqB,CAAC;AAC3C,OAAO,EAAE,kBAAkB,EAAE,MAAM,8BAA8B,CAAC;AAIlE,OAAO,EAAE,YAAY,EAAE,MAAM,kCAAkC,CAAC;AAEhE,OAAO,EAAE,KAAK,EAAE,MAAM,iBAAiB,CAAC;AAExC,OAAO,EAAE,WAAW,EAAE,MAAM,iBAAiB,CAAC;AAC9C,OAAO,EAAE,kBAAkB,EAAE,aAAa,EAAE,MAAM,cAAc,CAAC;AAIjE,MAAM,GAAG,GAAG,kBAAkB,CAAC,aAAa,EAAE,UAAU,CAAC,CAAC;AAe1D;;;;;;;;;GASG;AACH,MAAM,CAAC,KAAK,UAAU,aAAa,CAAC,OAA6B;IAC/D,MAAM,EAAE,QAAQ,EAAE,eAAe,EAAE,WAAW,EAAE,GAAG,OAAO,CAAC;IAC3D,MAAM,EAAE,aAAa,EAAE,GAAG,QAAQ,CAAC;IACnC,IAAI,gBAA8C,CAAC;IAEnD,MAAM,kBAAkB,GAAG,KAA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AE,CAAC;YAClD,MAAM,YAAY,GAAG,mBAAmB,CAAC,eAAe,CAAC,MAAM,CAAC,CAAC;YAEjE,GAAG,CAAC,yCAAyC,EAAE,YAAY,CAAC,CAAC;YAE7D,OAAO;gBACL,YAAY;aACb,CAAC;QACJ,CAAC;QAED,IAAI,eAAe,KAAK,kBAAkB,CAAC,YAAY,EAAE,CAAC;YACxD,MAAM,YAAY,GAAG,mBAAmB,CAAC,eAAe,CAAC,QAAQ,CAAC,CAAC;YAEnE,GAAG,CAAC,8BAA8B,EAAE,YAAY,CAAC,CAAC;YAElD,OAAO;gBACL,YAAY;aACb,CAAC;QACJ,CAAC;IACH,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACf,GAAG,CAAC,wBAAwB,EAAE,KAAK,CAAC,CAAC;IACvC,CAAC;IAED,MAAM,eAAe,GAAG,CAAC,MAAM,KAAK,CAAC,IAAI,QAAQ,CAAC,QAAQ,CAAC,EAAE,UAAU,CAAC,CAE3D,CAAC;IAEd,IAAI,CAAC,eAAe,EAAE,CAAC;QACrB,OAAO,EAAE,CAAC;IACZ,CAAC;IAED,MAAM,YAAY,GAAG,KAAK,CAAC,eAAe,CAAC,QAAQ,CAAC,EAAE,CAAC,CAAC,CAAC;IAEzD,GAAG,CAAC,yCAAyC,EAAE,YAAY,CAAC,CAAC;IAE7D,OAAO,EAAE,YAAY,EAAE,CAAC;AAC1B,CAAC;AAED;;;;;GAKG;AACH,SAAS,mBAAmB,CAAC,KAAa;IACxC,OAAO,KAAK,CAAC,cAAc,CAAC,KAAK,CAAC,CAAC,CAAC;AACtC,CAAC;AAED;;;;;GAKG;AACH,SAAS,aAAa,CAAC,KAAc;IACnC,OAAO,CAAC,KAAK,IAAI,KAAK,KAAK,WAAW,CAAC;AACzC,CAAC","sourcesContent":["import {\n gweiDecToWEIBN,\n ORIGIN_METAMASK,\n query,\n toHex,\n} from '@metamask/controller-utils';\nimport EthQuery from '@metamask/eth-query';\nimport { GAS_ESTIMATE_TYPES } from '@metamask/gas-fee-controller';\nimport type { GasFeeState } from '@metamask/gas-fee-controller';\nimport type { Provider } from '@metamask/network-controller';\nimport type { TransactionParams } from '@metamask/transaction-controller';\nimport { UserFeeLevel } from '@metamask/transaction-controller';\nimport type { Hex } from '@metamask/utils';\nimport { add0x } from '@metamask/utils';\n\nimport { EMPTY_BYTES } from '../constants.js';\nimport { createModuleLogger, projectLogger } from '../logger.js';\nimport type { UserOperation, UserOperationMetadata } from '../types.js';\nimport type { AddUserOperationRequest } from '../UserOperationController.js';\n\nconst log = createModuleLogger(projectLogger, 'gas-fees');\n\nexport type UpdateGasFeesRequest = {\n getGasFeeEstimates: () => Promise<GasFeeState>;\n metadata: UserOperationMetadata;\n originalRequest: AddUserOperationRequest;\n provider: Provider;\n transaction?: TransactionParams;\n};\n\ntype SuggestedGasFees = {\n maxFeePerGas?: string;\n maxPriorityFeePerGas?: string;\n};\n\n/**\n * Populates the gas fee properties for a user operation.\n *\n * @param request - The request to update the gas fees.\n * @param request.getGasFeeEstimates - A callback to get gas fee estimates.\n * @param request.metadata - The metadata for the user operation.\n * @param request.originalRequest - The original request to add the user operation.\n * @param request.provider - A provider to query the network.\n * @param request.transaction - The transaction that created the user operation.\n */\nexport async function updateGasFees(request: UpdateGasFeesRequest) {\n const { metadata, originalRequest, transaction } = request;\n const { userOperation } = metadata;\n let suggestedGasFees: SuggestedGasFees | undefined;\n\n const getGasFeeEstimates = async () => {\n if (!suggestedGasFees) {\n suggestedGasFees = await getSuggestedGasFees(request);\n }\n\n return suggestedGasFees;\n };\n\n userOperation.maxFeePerGas = await getMaxFeePerGas(\n originalRequest,\n getGasFeeEstimates,\n transaction,\n );\n\n userOperation.maxPriorityFeePerGas = await getMaxPriorityFeePerGas(\n originalRequest,\n getGasFeeEstimates,\n userOperation,\n transaction,\n );\n\n metadata.userFeeLevel = getUserFeeLevel(\n metadata,\n originalRequest,\n suggestedGasFees,\n transaction,\n );\n}\n\n/**\n * Gets the maxFeePerGas for a user operation.\n *\n * @param originalRequest - The original request to add the user operation.\n * @param getGetFasEstimates - A callback to get gas fee estimates.\n * @param transaction - The transaction that created the user operation.\n * @returns The maxFeePerGas for the user operation.\n */\nasync function getMaxFeePerGas(\n originalRequest: AddUserOperationRequest,\n getGetFasEstimates: () => Promise<SuggestedGasFees>,\n transaction?: TransactionParams,\n) {\n const { maxFeePerGas, maxPriorityFeePerGas } = originalRequest;\n const { gasPrice } = transaction ?? {};\n\n if (!isGasFeeEmpty(maxFeePerGas)) {\n log('Using maxFeePerGas from request', maxFeePerGas);\n return maxFeePerGas as string;\n }\n\n if (isGasFeeEmpty(maxPriorityFeePerGas) && gasPrice) {\n log('Setting maxFeePerGas to transaction gasPrice', gasPrice);\n return gasPrice;\n }\n\n const { maxFeePerGas: suggestedMaxFeePerGas } = await getGetFasEstimates();\n\n if (!suggestedMaxFeePerGas) {\n throw new Error('Failed to get gas fee estimate for maxFeePerGas');\n }\n\n log('Using maxFeePerGas from estimate', suggestedMaxFeePerGas);\n\n return suggestedMaxFeePerGas;\n}\n\n/**\n * Gets the maxPriorityFeePerGas for a user operation.\n *\n * @param originalRequest - The original request to add the user operation.\n * @param getGetFasEstimates - A callback to get gas fee estimates.\n * @param userOperation - The user operation being updated.\n * @param transaction - The transaction that created the user operation.\n * @returns The maxPriorityFeePerGas for the user operation.\n */\nasync function getMaxPriorityFeePerGas(\n originalRequest: AddUserOperationRequest,\n getGetFasEstimates: () => Promise<SuggestedGasFees>,\n userOperation: UserOperation,\n transaction?: TransactionParams,\n) {\n const { maxFeePerGas, maxPriorityFeePerGas } = originalRequest;\n const { gasPrice } = transaction ?? {};\n const { maxFeePerGas: updatedMaxFeePerGas } = userOperation;\n\n if (!isGasFeeEmpty(maxPriorityFeePerGas)) {\n log('Using maxPriorityFeePerGas from request', maxPriorityFeePerGas);\n return maxPriorityFeePerGas as string;\n }\n\n if (isGasFeeEmpty(maxFeePerGas) && gasPrice) {\n log('Setting maxPriorityFeePerGas to transaction gasPrice', gasPrice);\n return gasPrice;\n }\n\n const { maxPriorityFeePerGas: suggestedMaxPriorityFeePerGas } =\n await getGetFasEstimates();\n\n if (suggestedMaxPriorityFeePerGas) {\n log(\n 'Using maxPriorityFeePerGas from estimate',\n suggestedMaxPriorityFeePerGas,\n );\n return suggestedMaxPriorityFeePerGas;\n }\n\n log('Setting maxPriorityFeePerGas to maxFeePerGas', updatedMaxFeePerGas);\n\n return updatedMaxFeePerGas;\n}\n\n/**\n * Gets the userFeeLevel for a user operation.\n *\n * @param metadata - The metadata for the user operation.\n * @param originalRequest - The original request to add the user operation.\n * @param suggestedGasFees - The suggested gas fees, if any.\n * @param transaction - The transaction that created the user operation.\n * @returns The userFeeLevel for the user operation.\n */\nfunction getUserFeeLevel(\n metadata: UserOperationMetadata,\n originalRequest: AddUserOperationRequest,\n suggestedGasFees?: SuggestedGasFees,\n transaction?: TransactionParams,\n): UserFeeLevel {\n const { origin } = metadata;\n const { maxFeePerGas, maxPriorityFeePerGas } = originalRequest;\n\n const {\n maxFeePerGas: suggestedMaxFeePerGas,\n maxPriorityFeePerGas: suggestedMaxPriorityFeePerGas,\n } = suggestedGasFees || {};\n\n if (\n isGasFeeEmpty(maxFeePerGas) &&\n isGasFeeEmpty(maxPriorityFeePerGas) &&\n transaction?.gasPrice\n ) {\n return origin === ORIGIN_METAMASK\n ? UserFeeLevel.CUSTOM\n : UserFeeLevel.DAPP_SUGGESTED;\n }\n\n if (\n isGasFeeEmpty(maxFeePerGas) &&\n isGasFeeEmpty(maxPriorityFeePerGas) &&\n suggestedMaxFeePerGas &&\n suggestedMaxPriorityFeePerGas\n ) {\n return UserFeeLevel.MEDIUM;\n }\n\n if (origin === ORIGIN_METAMASK) {\n return UserFeeLevel.CUSTOM;\n }\n\n return UserFeeLevel.DAPP_SUGGESTED;\n}\n\n/**\n * Gets suggested gas fees.\n *\n * @param request - The request to update the gas fees.\n * @param request.getGasFeeEstimates - A callback to get gas fee estimates.\n * @param request.provider - A provider to query the network.\n * @returns The suggested gas fees.\n */\nasync function getSuggestedGasFees(\n request: UpdateGasFeesRequest,\n): Promise<{ maxFeePerGas?: Hex; maxPriorityFeePerGas?: Hex }> {\n const { getGasFeeEstimates, provider } = request;\n\n try {\n const { gasFeeEstimates, gasEstimateType } = await getGasFeeEstimates();\n\n if (gasEstimateType === GAS_ESTIMATE_TYPES.FEE_MARKET) {\n /* istanbul ignore next */\n const {\n medium: { suggestedMaxPriorityFeePerGas, suggestedMaxFeePerGas } = {},\n } = gasFeeEstimates;\n\n if (suggestedMaxPriorityFeePerGas && suggestedMaxFeePerGas) {\n const values = {\n maxFeePerGas: gweiDecimalToWeiHex(suggestedMaxFeePerGas),\n maxPriorityFeePerGas: gweiDecimalToWeiHex(\n suggestedMaxPriorityFeePerGas,\n ),\n };\n\n log('Using medium values from fee market estimate', values);\n\n return values;\n }\n }\n\n if (gasEstimateType === GAS_ESTIMATE_TYPES.LEGACY) {\n const maxFeePerGas = gweiDecimalToWeiHex(gasFeeEstimates.medium);\n\n log('Using medium value from legacy estimate', maxFeePerGas);\n\n return {\n maxFeePerGas,\n };\n }\n\n if (gasEstimateType === GAS_ESTIMATE_TYPES.ETH_GASPRICE) {\n const maxFeePerGas = gweiDecimalToWeiHex(gasFeeEstimates.gasPrice);\n\n log('Using gasPrice from estimate', maxFeePerGas);\n\n return {\n maxFeePerGas,\n };\n }\n } catch (error) {\n log('Failed to get estimate', error);\n }\n\n const gasPriceDecimal = (await query(new EthQuery(provider), 'gasPrice')) as\n | number\n | undefined;\n\n if (!gasPriceDecimal) {\n return {};\n }\n\n const maxFeePerGas = add0x(gasPriceDecimal.toString(16));\n\n log('Using gasPrice from network as fallback', maxFeePerGas);\n\n return { maxFeePerGas };\n}\n\n/**\n * Converts a GWEI decimal string to a WEI hexadecimal string.\n *\n * @param value - The GWEI decimal string to convert.\n * @returns The WEI hexadecimal string.\n */\nfunction gweiDecimalToWeiHex(value: string) {\n return toHex(gweiDecToWEIBN(value));\n}\n\n/**\n * Checks if a gas fee property is empty.\n *\n * @param value - The gas fee value to check.\n * @returns Whether the gas fee property is empty.\n */\nfunction isGasFeeEmpty(value?: string): boolean {\n return !value || value === EMPTY_BYTES;\n}\n"]}
@@ -1,4 +1,4 @@
1
- import type { PrepareUserOperationResponse, UserOperationMetadata } from "../types.mjs";
1
+ import type { PrepareUserOperationResponse, UserOperationMetadata } from '../types.js';
2
2
  /**
3
3
  * Populates the gas properties for a user operation.
4
4
  *
@@ -7,4 +7,4 @@ import type { PrepareUserOperationResponse, UserOperationMetadata } from "../typ
7
7
  * @param entrypoint - Address of the entrypoint contract.
8
8
  */
9
9
  export declare function updateGas(metadata: UserOperationMetadata, prepareResponse: PrepareUserOperationResponse, entrypoint: string): Promise<void>;
10
- //# sourceMappingURL=gas.d.mts.map
10
+ //# sourceMappingURL=gas.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"gas.d.ts","sourceRoot":"","sources":["../../src/utils/gas.ts"],"names":[],"mappings":"AAOA,OAAO,KAAK,EACV,4BAA4B,EAC5B,qBAAqB,EACtB,MAAM,aAAa,CAAC;AASrB;;;;;;GAMG;AACH,wBAAsB,SAAS,CAC7B,QAAQ,EAAE,qBAAqB,EAC/B,eAAe,EAAE,4BAA4B,EAC7C,UAAU,EAAE,MAAM,iBAgDnB"}