@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
@@ -1,16 +1,9 @@
1
- function $importDefault(module) {
2
- if (module?.__esModule) {
3
- return module.default;
4
- }
5
- return module;
6
- }
7
- import { hexToBN } from "@metamask/controller-utils";
8
- import { add0x } from "@metamask/utils";
9
- import $BN from "bn.js";
10
- const BN = $importDefault($BN);
11
- import { VALUE_ZERO } from "../constants.mjs";
12
- import { Bundler } from "../helpers/Bundler.mjs";
13
- import { createModuleLogger, projectLogger } from "../logger.mjs";
1
+ import { hexToBN } from '@metamask/controller-utils';
2
+ import { add0x } from '@metamask/utils';
3
+ import BN from 'bn.js';
4
+ import { VALUE_ZERO } from '../constants.js';
5
+ import { Bundler } from '../helpers/Bundler.js';
6
+ import { createModuleLogger, projectLogger } from '../logger.js';
14
7
  const log = createModuleLogger(projectLogger, 'gas');
15
8
  /**
16
9
  * A multiplier to apply to all gas estimate values returned from the bundler.
@@ -69,4 +62,4 @@ function normalizeGasEstimate(rawValue) {
69
62
  const bufferedValue = value.muln(GAS_ESTIMATE_MULTIPLIER);
70
63
  return add0x(bufferedValue.toString(16));
71
64
  }
72
- //# source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AAU;QAChC,YAAY,EAAE,UAAU;QACxB,kBAAkB,EAAE,UAAU;QAC9B,oBAAoB,EAAE,SAAS;KAChC,CAAC;IAEF,MAAM,OAAO,GAAG,IAAI,OAAO,CAAC,QAAQ,CAAC,UAAoB,CAAC,CAAC;IAC3D,MAAM,QAAQ,GAAG,MAAM,OAAO,CAAC,wBAAwB,CAAC,OAAO,EAAE,UAAU,CAAC,CAAC;IAE7E,aAAa,CAAC,YAAY,GAAG,oBAAoB,CAAC,QAAQ,CAAC,YAAY,CAAC,CAAC;IACzE,aAAa,CAAC,kBAAkB,GAAG,oBAAoB,CACrD,QAAQ,CAAC,kBAAkB,CAC5B,CAAC;IACF,aAAa,CAAC,oBAAoB,GAAG,oBAAoB,CACvD,CAAC,QAAQ,CAAC,oBAAoB,IAAI,QAAQ,CAAC,eAAe,CAEhD,CACX,CAAC;IAEF,GAAG,CAAC,iDAAiD,EAAE;QACrD,YAAY,EAAE,aAAa,CAAC,YAAY;QACxC,kBAAkB,EAAE,aAAa,CAAC,kBAAkB;QACpD,oBAAoB,EAAE,aAAa,CAAC,oBAAoB;QACxD,UAAU,EAAE,uBAAuB;QACnC,QAAQ;KACT,CAAC,CAAC;AACL,CAAC;AAED;;;;;GAKG;AACH,SAAS,oBAAoB,CAAC,QAAyB;IACrD,MAAM,KAAK,GACT,OAAO,QAAQ,KAAK,QAAQ,CAAC,CAAC,CAAC,OAAO,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC,IAAI,EAAE,CAAC,QAAQ,CAAC,CAAC;IAEtE,MAAM,aAAa,GAAG,KAAK,CAAC,IAAI,CAAC,uBAAuB,CAAC,CAAC;IAE1D,OAAO,KAAK,CAAC,aAAa,CAAC,QAAQ,CAAC,EAAE,CAAC,CAAC,CAAC;AAC3C,CAAC","sourcesContent":["import { hexToBN } from '@metamask/controller-utils';\nimport { add0x } from '@metamask/utils';\nimport BN from 'bn.js';\n\nimport { VALUE_ZERO } from '../constants.js';\nimport { Bundler } from '../helpers/Bundler.js';\nimport { createModuleLogger, projectLogger } from '../logger.js';\nimport type {\n PrepareUserOperationResponse,\n UserOperationMetadata,\n} from '../types.js';\n\nconst log = createModuleLogger(projectLogger, 'gas');\n\n/**\n * A multiplier to apply to all gas estimate values returned from the bundler.\n */\nconst GAS_ESTIMATE_MULTIPLIER = 1.5;\n\n/**\n * Populates the gas properties for a user operation.\n *\n * @param metadata - The metadata for the user operation.\n * @param prepareResponse - The prepare response from the smart contract account.\n * @param entrypoint - Address of the entrypoint contract.\n */\nexport async function updateGas(\n metadata: UserOperationMetadata,\n prepareResponse: PrepareUserOperationResponse,\n entrypoint: string,\n) {\n const { userOperation } = metadata;\n\n if (prepareResponse.gas) {\n userOperation.callGasLimit = prepareResponse.gas.callGasLimit;\n userOperation.preVerificationGas = prepareResponse.gas.preVerificationGas;\n userOperation.verificationGasLimit =\n prepareResponse.gas.verificationGasLimit;\n\n log('Using gas values from smart contract account', {\n callGasLimit: userOperation.callGasLimit,\n preVerificationGas: userOperation.preVerificationGas,\n verificationGasLimit: userOperation.verificationGasLimit,\n });\n\n return;\n }\n\n const payload = {\n ...userOperation,\n maxFeePerGas: VALUE_ZERO,\n maxPriorityFeePerGas: VALUE_ZERO,\n callGasLimit: VALUE_ZERO,\n preVerificationGas: VALUE_ZERO,\n verificationGasLimit: '0xF4240',\n };\n\n const bundler = new Bundler(metadata.bundlerUrl as string);\n const estimate = await bundler.estimateUserOperationGas(payload, entrypoint);\n\n userOperation.callGasLimit = normalizeGasEstimate(estimate.callGasLimit);\n userOperation.preVerificationGas = normalizeGasEstimate(\n estimate.preVerificationGas,\n );\n userOperation.verificationGasLimit = normalizeGasEstimate(\n (estimate.verificationGasLimit ?? estimate.verificationGas) as\n | string\n | number,\n );\n\n log('Using buffered gas values from bundler estimate', {\n callGasLimit: userOperation.callGasLimit,\n preVerificationGas: userOperation.preVerificationGas,\n verificationGasLimit: userOperation.verificationGasLimit,\n multiplier: GAS_ESTIMATE_MULTIPLIER,\n estimate,\n });\n}\n\n/**\n * Normalizes a gas estimate value from the bundler.\n *\n * @param rawValue - The raw value to normalize.\n * @returns The normalized value as a hexadecimal string.\n */\nfunction normalizeGasEstimate(rawValue: string | number): string {\n const value =\n typeof rawValue === 'string' ? hexToBN(rawValue) : new BN(rawValue);\n\n const bufferedValue = value.muln(GAS_ESTIMATE_MULTIPLIER);\n\n return add0x(bufferedValue.toString(16));\n}\n"]}
@@ -1,5 +1,5 @@
1
- import type { TransactionMeta } from "@metamask/transaction-controller";
2
- import type { UserOperationMetadata } from "../types.cjs";
1
+ import type { TransactionMeta } from '@metamask/transaction-controller';
2
+ import type { UserOperationMetadata } from '../types.js';
3
3
  /**
4
4
  * Converts a user operation metadata object into a transaction metadata object.
5
5
  *
@@ -7,4 +7,4 @@ import type { UserOperationMetadata } from "../types.cjs";
7
7
  * @returns The equivalent transaction metadata object.
8
8
  */
9
9
  export declare function getTransactionMetadata(metadata: UserOperationMetadata): TransactionMeta | undefined;
10
- //# sourceMappingURL=transaction.d.cts.map
10
+ //# sourceMappingURL=transaction.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"transaction.d.ts","sourceRoot":"","sources":["../../src/utils/transaction.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAEV,eAAe,EAEhB,MAAM,kCAAkC,CAAC;AAW1C,OAAO,KAAK,EAAE,qBAAqB,EAAE,MAAM,aAAa,CAAC;AAEzD;;;;;GAKG;AACH,wBAAgB,sBAAsB,CACpC,QAAQ,EAAE,qBAAqB,GAC9B,eAAe,GAAG,SAAS,CA0H7B"}
@@ -1,15 +1,8 @@
1
- function $importDefault(module) {
2
- if (module?.__esModule) {
3
- return module.default;
4
- }
5
- return module;
6
- }
7
- import { TransactionStatus, UserFeeLevel } from "@metamask/transaction-controller";
8
- import { add0x, remove0x } from "@metamask/utils";
9
- import $BN from "bn.js";
10
- const BN = $importDefault($BN);
11
- import { EMPTY_BYTES, VALUE_ZERO } from "../constants.mjs";
12
- import { UserOperationStatus } from "../types.mjs";
1
+ import { TransactionStatus, UserFeeLevel, } from '@metamask/transaction-controller';
2
+ import { add0x, remove0x } from '@metamask/utils';
3
+ import BN from 'bn.js';
4
+ import { EMPTY_BYTES, VALUE_ZERO } from '../constants.js';
5
+ import { UserOperationStatus } from '../types.js';
13
6
  /**
14
7
  * Converts a user operation metadata object into a transaction metadata object.
15
8
  *
@@ -114,4 +107,4 @@ function addHex(...values) {
114
107
  }
115
108
  return add0x(total.toString(16));
116
109
  }
117
- //# sourceMappingURL=transaction.mjs.map
110
+ //# sourceMappingURL=transaction.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"transaction.js","sourceRoot":"","sources":["../../src/utils/transaction.ts"],"names":[],"mappings":"AAKA,OAAO,EACL,iBAAiB,EACjB,YAAY,GACb,MAAM,kCAAkC,CAAC;AAE1C,OAAO,EAAE,KAAK,EAAE,QAAQ,EAAE,MAAM,iBAAiB,CAAC;AAClD,OAAO,EAAE,MAAM,OAAO,CAAC;AAEvB,OAAO,EAAE,WAAW,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAC;AAC1D,OAAO,EAAE,mBAAmB,EAAE,MAAM,aAAa,CAAC;AAGlD;;;;;GAKG;AACH,MAAM,UAAU,sBAAsB,CACpC,QAA+B;IAE/B,MAAM,EACJ,aAAa,EACb,aAAa,EACb,aAAa,EACb,OAAO,EACP,KAAK,EAAE,QAAQ,EACf,MAAM,EACN,eAAe,EACf,EAAE,EACF,aAAa,EACb,IAAI,EACJ,iBAAiB,EACjB,eAAe,EACf,YAAY,EAAE,eAAe,EAC7B,aAAa,GACd,GAAG,QAAQ,CAAC;IAEb,IAAI,CAAC,iBAAiB,EAAE,CAAC;QACvB,OAAO,SAAS,CAAC;IACnB,CAAC;IAED,oDAAoD;IACpD,MAAM,iBAAiB,GACrB,aAAa,IAAI,aAAa;QAC5B,CAAC,CAAC,KAAK,CACH,IAAI,EAAE,CAAC,QAAQ,CAAC,aAAa,CAAC,EAAE,EAAE,CAAC;aAChC,G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,EAAE,OAAc;QACvB,KAAK;QACL,IAAI,EAAE,eAAe,IAAI,SAAS;QAClC,EAAE;QACF,eAAe,EAAE,IAAI;QACrB,eAAe,EAAE,gBAAgB;QACjC,MAAM;QACN,MAAM;QACN,IAAI;QACJ,QAAQ;QACR,SAAS,EAAE;YACT,iBAAiB,EAAE,iBAAiB,IAAI,SAAS;YACjD,OAAO,EAAE,aAAa,IAAI,SAAS;SACpC;QACD,IAAI,EAAE,eAAe,IAAI,SAAS;QAClC,YAAY,EAAE,YAAsB;QACpC,GAAG,KAAK;KACT,CAAC;AACJ,CAAC;AAED;;;;;GAKG;AACH,SAAS,MAAM,CAAC,GAAG,MAA8B;IAC/C,MAAM,KAAK,GAAG,IAAI,EAAE,CAAC,CAAC,CAAC,CAAC;IAExB,KAAK,MAAM,KAAK,IAAI,MAAM,EAAE,CAAC;QAC3B,IAAI,CAAC,KAAK,EAAE,CAAC;YACX,SAAS;QACX,CAAC;QAED,KAAK,CAAC,IAAI,CAAC,IAAI,EAAE,CAAC,QAAQ,CAAC,KAAK,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC;IAC1C,CAAC;IAED,OAAO,KAAK,CAAC,KAAK,CAAC,QAAQ,CAAC,EAAE,CAAC,CAAC,CAAC;AACnC,CAAC","sourcesContent":["import type {\n TransactionError,\n TransactionMeta,\n TransactionParams,\n} from '@metamask/transaction-controller';\nimport {\n TransactionStatus,\n UserFeeLevel,\n} from '@metamask/transaction-controller';\nimport type { Hex } from '@metamask/utils';\nimport { add0x, remove0x } from '@metamask/utils';\nimport BN from 'bn.js';\n\nimport { EMPTY_BYTES, VALUE_ZERO } from '../constants.js';\nimport { UserOperationStatus } from '../types.js';\nimport type { UserOperationMetadata } from '../types.js';\n\n/**\n * Converts a user operation metadata object into a transaction metadata object.\n *\n * @param metadata - The user operation metadata object to convert.\n * @returns The equivalent transaction metadata object.\n */\nexport function getTransactionMetadata(\n metadata: UserOperationMetadata,\n): TransactionMeta | undefined {\n const {\n actualGasCost,\n actualGasUsed,\n baseFeePerGas,\n chainId,\n error: rawError,\n origin,\n transactionHash,\n id,\n swapsMetadata,\n time,\n transactionParams,\n transactionType,\n userFeeLevel: rawUserFeeLevel,\n userOperation,\n } = metadata;\n\n if (!transactionParams) {\n return undefined;\n }\n\n // effectiveGasPrice = actualGasCost / actualGasUsed\n const effectiveGasPrice =\n actualGasCost && actualGasUsed\n ? add0x(\n new BN(remove0x(actualGasCost), 16)\n .div(new BN(remove0x(actualGasUsed), 16))\n .toString(16),\n )\n : undefined;\n\n const error = (\n rawError\n ? {\n name: rawError.name,\n message: rawError.message,\n stack: rawError.stack,\n code: rawError.code,\n rpc: rawError.rpc,\n }\n : undefined\n ) as TransactionError;\n\n const status: TransactionStatus = {\n [UserOperationStatus.Unapproved]: TransactionStatus.unapproved,\n [UserOperationStatus.Approved]: TransactionStatus.approved,\n [UserOperationStatus.Signed]: TransactionStatus.signed,\n [UserOperationStatus.Submitted]: TransactionStatus.submitted,\n [UserOperationStatus.Confirmed]: TransactionStatus.confirmed,\n [UserOperationStatus.Failed]: TransactionStatus.failed,\n }[metadata.status];\n\n const gas = addHex(\n userOperation.preVerificationGas,\n userOperation.verificationGasLimit,\n userOperation.callGasLimit,\n );\n\n const hasPaymaster = userOperation.paymasterAndData !== EMPTY_BYTES;\n\n const maxFeePerGas = hasPaymaster ? VALUE_ZERO : userOperation.maxFeePerGas;\n\n const maxPriorityFeePerGas = hasPaymaster\n ? VALUE_ZERO\n : userOperation.maxPriorityFeePerGas;\n\n const nonce =\n userOperation.nonce === EMPTY_BYTES ? undefined : userOperation.nonce;\n\n const txParams = {\n ...transactionParams,\n from: userOperation.sender,\n gas,\n nonce,\n maxFeePerGas,\n maxPriorityFeePerGas,\n } as TransactionParams;\n\n // User operations only support EIP-1559 gas fee properties.\n delete txParams.gasPrice;\n\n const swaps = {\n approvalTxId: swapsMetadata?.approvalTxId ?? undefined,\n destinationTokenAddress:\n swapsMetadata?.destinationTokenAddress ?? undefined,\n destinationTokenAmount: swapsMetadata?.destinationTokenAmount ?? undefined,\n destinationTokenDecimals:\n swapsMetadata?.destinationTokenDecimals ?? undefined,\n destinationTokenSymbol: swapsMetadata?.destinationTokenSymbol ?? undefined,\n estimatedBaseFee: swapsMetadata?.estimatedBaseFee ?? undefined,\n sourceTokenAddress: swapsMetadata?.sourceTokenAddress ?? undefined,\n sourceTokenAmount: swapsMetadata?.sourceTokenAmount ?? undefined,\n sourceTokenDecimals: swapsMetadata?.sourceTokenDecimals ?? undefined,\n sourceTokenSymbol: swapsMetadata?.sourceTokenSymbol ?? undefined,\n swapAndSendRecipient: swapsMetadata?.swapAndSendRecipient ?? undefined,\n swapMetaData: swapsMetadata?.swapMetaData ?? undefined,\n swapTokenValue: swapsMetadata?.swapTokenValue ?? undefined,\n };\n\n const userFeeLevel = hasPaymaster ? UserFeeLevel.CUSTOM : rawUserFeeLevel;\n\n return {\n baseFeePerGas: (baseFeePerGas as Hex) ?? undefined,\n chainId: chainId as Hex,\n error,\n hash: transactionHash ?? undefined,\n id,\n isUserOperation: true,\n networkClientId: 'user-operation',\n origin,\n status,\n time,\n txParams,\n txReceipt: {\n effectiveGasPrice: effectiveGasPrice ?? undefined,\n gasUsed: actualGasUsed ?? undefined,\n },\n type: transactionType ?? undefined,\n userFeeLevel: userFeeLevel as string,\n ...swaps,\n };\n}\n\n/**\n * Adds the given hexadecimal values together.\n *\n * @param values - The hexadecimal values to add together.\n * @returns The sum of the given hexadecimal values.\n */\nfunction addHex(...values: (string | undefined)[]) {\n const total = new BN(0);\n\n for (const value of values) {\n if (!value) {\n continue;\n }\n\n total.iadd(new BN(remove0x(value), 16));\n }\n\n return add0x(total.toString(16));\n}\n"]}
@@ -1,5 +1,5 @@
1
- import type { PrepareUserOperationResponse, SignUserOperationResponse, UpdateUserOperationResponse } from "../types.cjs";
2
- import type { AddUserOperationOptions, AddUserOperationRequest } from "../UserOperationController.cjs";
1
+ import type { PrepareUserOperationResponse, SignUserOperationResponse, UpdateUserOperationResponse } from '../types.js';
2
+ import type { AddUserOperationOptions, AddUserOperationRequest } from '../UserOperationController.js';
3
3
  /**
4
4
  * Validate a request to add a user operation.
5
5
  *
@@ -30,4 +30,4 @@ export declare function validateUpdateUserOperationResponse(response: UpdateUser
30
30
  * @param response - The response to validate.
31
31
  */
32
32
  export declare function validateSignUserOperationResponse(response: SignUserOperationResponse): void;
33
- //# sourceMappingURL=validation.d.cts.map
33
+ //# sourceMappingURL=validation.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"validation.d.ts","sourceRoot":"","sources":["../../src/utils/validation.ts"],"names":[],"mappings":"AAiBA,OAAO,KAAK,EACV,4BAA4B,EAC5B,yBAAyB,EACzB,2BAA2B,EAC5B,MAAM,aAAa,CAAC;AACrB,OAAO,KAAK,EACV,uBAAuB,EACvB,uBAAuB,EACxB,MAAM,+BAA+B,CAAC;AAEvC;;;;GAIG;AACH,wBAAgB,+BAA+B,CAC7C,OAAO,EAAE,uBAAuB,QAejC;AAED;;;;GAIG;AACH,wBAAgB,+BAA+B,CAC7C,OAAO,EAAE,uBAAuB,QAkCjC;AAED;;;;GAIG;AACH,wBAAgB,oCAAoC,CAClD,QAAQ,EAAE,4BAA4B,QAsCvC;AAED;;;;GAIG;AACH,wBAAgB,mCAAmC,CACjD,QAAQ,EAAE,2BAA2B,QAgBtC;AAED;;;;GAIG;AACH,wBAAgB,iCAAiC,CAC/C,QAAQ,EAAE,yBAAyB,QAapC"}
@@ -1,7 +1,7 @@
1
- import { assert, boolean, define, enums, func, number, object, optional, refine, string } from "@metamask/superstruct";
2
- import { TransactionType } from "@metamask/transaction-controller";
3
- import { isStrictHexString } from "@metamask/utils";
4
- import { EMPTY_BYTES } from "../constants.mjs";
1
+ import { assert, boolean, define, enums, func, number, object, optional, refine, string, } from '@metamask/superstruct';
2
+ import { TransactionType } from '@metamask/transaction-controller';
3
+ import { isStrictHexString } from '@metamask/utils';
4
+ import { EMPTY_BYTES } from '../constants.js';
5
5
  /**
6
6
  * Validate a request to add a user operation.
7
7
  *
@@ -151,4 +151,4 @@ function defineHex() {
151
151
  function defineHexOrEmptyBytes() {
152
152
  return define('Hexadecimal String or 0x', (value) => isStrictHexString(value) || value === EMPTY_BYTES);
153
153
  }
154
- //# sourceMappingURL=validation.mjs.map
154
+ //# sourceMappingURL=validation.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"validation.js","sourceRoot":"","sources":["../../src/utils/validation.ts"],"names":[],"mappings":"AACA,OAAO,EACL,MAAM,EACN,OAAO,EACP,MAAM,EACN,KAAK,EACL,IAAI,EACJ,MAAM,EACN,MAAM,EACN,QAAQ,EACR,MAAM,EACN,MAAM,GACP,MAAM,uBAAuB,CAAC;AAC/B,OAAO,EAAE,eAAe,EAAE,MAAM,kCAAkC,CAAC;AACnE,OAAO,EAAE,iBAAiB,EAAE,MAAM,iBAAiB,CAAC;AAEpD,OAAO,EAAE,WAAW,EAAE,MAAM,iBAAiB,CAAC;AAW9C;;;;GAIG;AACH,MAAM,UAAU,+BAA+B,CAC7C,OAAgC;IAEhC,MAAM,GAAG,GAAG,SAAS,EAAE,CAAC;IACxB,MAAM,eAAe,GAAG,qBAAqB,EAAE,CAAC;IAEhD,MAAM,YAAY,GAAG,MAAM,CAAC;QAC1B,IAAI,EAAE,QAAQ,CAAC,eAAe,CAAC;QAC/B,IAAI,EAAE,GAAG;QACT,YAAY,EAAE,QAAQ,CAAC,GAAG,CAAC;QAC3B,oBAAoB,EAAE,QAAQ,CAAC,GAAG,CAAC;QACnC,EAAE,EAAE,QAAQ,CAAC,GAAG,CAAC;QACjB,KAAK,EAAE,QAAQ,CAAC,GAAG,CAAC;KACrB,CAAC,CAAC;IAEH,QAAQ,CAAC,OAAO,EAAE,YAAY,EAAE,uCAAuC,CAAC,CAAC;AAC3E,CAAC;AAED;;;;GAIG;AACH,MAAM,UAAU,+BAA+B,CAC7C,OAAgC;IAEhC,MAAM,YAAY,GAAG,MAAM,CAAC;QAC1B,eAAe,EAAE,MAAM,EA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KAAK,WAAW,CAC7D,CAAC;AACJ,CAAC","sourcesContent":["import type { Struct, StructError } from '@metamask/superstruct';\nimport {\n assert,\n boolean,\n define,\n enums,\n func,\n number,\n object,\n optional,\n refine,\n string,\n} from '@metamask/superstruct';\nimport { TransactionType } from '@metamask/transaction-controller';\nimport { isStrictHexString } from '@metamask/utils';\n\nimport { EMPTY_BYTES } from '../constants.js';\nimport type {\n PrepareUserOperationResponse,\n SignUserOperationResponse,\n UpdateUserOperationResponse,\n} from '../types.js';\nimport type {\n AddUserOperationOptions,\n AddUserOperationRequest,\n} from '../UserOperationController.js';\n\n/**\n * Validate a request to add a user operation.\n *\n * @param request - The request to validate.\n */\nexport function validateAddUserOperationRequest(\n request: AddUserOperationRequest,\n) {\n const Hex = defineHex();\n const HexOrEmptyBytes = defineHexOrEmptyBytes();\n\n const ValidRequest = object({\n data: optional(HexOrEmptyBytes),\n from: Hex,\n maxFeePerGas: optional(Hex),\n maxPriorityFeePerGas: optional(Hex),\n to: optional(Hex),\n value: optional(Hex),\n });\n\n validate(request, ValidRequest, 'Invalid request to add user operation');\n}\n\n/**\n * Validate the options when adding a user operation.\n *\n * @param options - The options to validate.\n */\nexport function validateAddUserOperationOptions(\n options: AddUserOperationOptions,\n) {\n const ValidOptions = object({\n networkClientId: string(),\n origin: string(),\n requireApproval: optional(boolean()),\n smartContractAccount: optional(\n object({\n prepareUserOperation: func(),\n updateUserOperation: func(),\n signUserOperation: func(),\n }),\n ),\n swaps: optional(\n object({\n approvalTxId: optional(string()),\n destinationTokenAddress: optional(string()),\n destinationTokenDecimals: optional(number()),\n destinationTokenSymbol: optional(string()),\n estimatedBaseFee: optional(string()),\n sourceTokenSymbol: optional(string()),\n swapMetaData: optional(object()),\n swapTokenValue: optional(string()),\n destinationTokenAmount: optional(string()),\n sourceTokenAddress: optional(string()),\n sourceTokenAmount: optional(string()),\n sourceTokenDecimals: optional(number()),\n swapAndSendRecipient: optional(string()),\n }),\n ),\n type: optional(enums(Object.values(TransactionType))),\n });\n\n validate(options, ValidOptions, 'Invalid options to add user operation');\n}\n\n/**\n * Validate the response from a smart contract account when preparing the user operation.\n *\n * @param response - The response to validate.\n */\nexport function validatePrepareUserOperationResponse(\n response: PrepareUserOperationResponse,\n) {\n const Hex = defineHex();\n const HexOrEmptyBytes = defineHexOrEmptyBytes();\n\n const ValidResponse = refine(\n object({\n bundler: string(),\n callData: Hex,\n dummyPaymasterAndData: optional(HexOrEmptyBytes),\n dummySignature: optional(HexOrEmptyBytes),\n gas: optional(\n object({\n callGasLimit: Hex,\n preVerificationGas: Hex,\n verificationGasLimit: Hex,\n }),\n ),\n initCode: optional(HexOrEmptyBytes),\n nonce: Hex,\n sender: Hex,\n }),\n 'ValidPrepareUserOperationResponse',\n ({ gas, dummySignature }) => {\n if (!gas && (!dummySignature || dummySignature === EMPTY_BYTES)) {\n return 'Must specify dummySignature if not specifying gas';\n }\n\n /* istanbul ignore next */\n return true;\n },\n );\n\n validate(\n response,\n ValidResponse,\n 'Invalid response when preparing user operation',\n );\n}\n\n/**\n * Validate the response from a smart contract account when updating the user operation.\n *\n * @param response - The response to validate.\n */\nexport function validateUpdateUserOperationResponse(\n response: UpdateUserOperationResponse,\n) {\n const ValidResponse = optional(\n object({\n paymasterAndData: optional(defineHexOrEmptyBytes()),\n callGasLimit: optional(defineHexOrEmptyBytes()),\n preVerificationGas: optional(defineHexOrEmptyBytes()),\n verificationGasLimit: optional(defineHexOrEmptyBytes()),\n }),\n );\n\n validate(\n response,\n ValidResponse,\n 'Invalid response when updating user operation',\n );\n}\n\n/**\n * Validate the response from a smart contract account when signing the user operation.\n *\n * @param response - The response to validate.\n */\nexport function validateSignUserOperationResponse(\n response: SignUserOperationResponse,\n) {\n const Hex = defineHex();\n\n const ValidResponse = object({\n signature: Hex,\n });\n\n validate(\n response,\n ValidResponse,\n 'Invalid response when signing user operation',\n );\n}\n\n/**\n * Validate data against a struct.\n *\n * @param data - The data to validate.\n * @param struct - The struct to validate against.\n * @param message - The message to throw if validation fails.\n */\nfunction validate<T>(data: unknown, struct: Struct<T>, message: string) {\n try {\n assert(data, struct, message);\n } catch (error) {\n const causes = (error as StructError)\n .failures()\n .map((failure) => {\n if (!failure.path.length) {\n return failure.message;\n }\n\n return `${failure.path.join('.')} - ${failure.message}`;\n })\n .join('\\n');\n\n const finalMessage = `${message}\\n${causes}`;\n\n throw new Error(finalMessage);\n }\n}\n\n/**\n * Define the Hex type used by superstruct.\n *\n * @returns The Hex superstruct type.\n */\nfunction defineHex() {\n return define<string>('Hexadecimal String', (value) =>\n isStrictHexString(value),\n );\n}\n\n/**\n * Define the HexOrEmptyBytes type used by superstruct.\n *\n * @returns The HexOrEmptyBytes superstruct type.\n */\nfunction defineHexOrEmptyBytes() {\n return define<string>(\n 'Hexadecimal String or 0x',\n (value) => isStrictHexString(value) || value === EMPTY_BYTES,\n );\n}\n"]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@metamask-previews/user-operation-controller",
3
- "version": "41.2.9-preview-8bfa290fb",
3
+ "version": "42.0.0-preview-0a30e47",
4
4
  "description": "Creates user operations and manages their life cycle",
5
5
  "keywords": [
6
6
  "Ethereum",
@@ -18,19 +18,12 @@
18
18
  "files": [
19
19
  "dist/"
20
20
  ],
21
+ "type": "module",
21
22
  "sideEffects": false,
22
- "main": "./dist/index.cjs",
23
- "types": "./dist/index.d.cts",
24
23
  "exports": {
25
24
  ".": {
26
- "import": {
27
- "types": "./dist/index.d.mts",
28
- "default": "./dist/index.mjs"
29
- },
30
- "require": {
31
- "types": "./dist/index.d.cts",
32
- "default": "./dist/index.cjs"
33
- }
25
+ "types": "./dist/index.d.ts",
26
+ "default": "./dist/index.js"
34
27
  },
35
28
  "./package.json": "./package.json"
36
29
  },
@@ -39,9 +32,11 @@
39
32
  "registry": "https://registry.npmjs.org/"
40
33
  },
41
34
  "scripts": {
42
- "build": "ts-bridge --project tsconfig.build.json --verbose --clean --no-references",
43
- "build:all": "ts-bridge --project tsconfig.build.json --verbose --clean",
35
+ "build": "tsc --project tsconfig.build.json",
36
+ "build:all": "tsc --build tsconfig.build.json --verbose",
37
+ "build:clean": "yarn build:only-clean && yarn build",
44
38
  "build:docs": "typedoc",
39
+ "build:only-clean": "rimraf './dist' './tsconfig.build.tsbuildinfo'",
45
40
  "changelog:update": "../../scripts/update-changelog.sh @metamask/user-operation-controller",
46
41
  "changelog:validate": "../../scripts/validate-changelog.sh @metamask/user-operation-controller",
47
42
  "lint:tsconfigs": "tsx ../../scripts/lint-tsconfigs/lint-tsconfigs.mts",
@@ -56,41 +51,42 @@
56
51
  "test:watch": "NODE_OPTIONS=--experimental-vm-modules jest --watch"
57
52
  },
58
53
  "dependencies": {
59
- "@metamask/approval-controller": "^9.0.2",
60
- "@metamask/base-controller": "^9.1.0",
61
- "@metamask/controller-utils": "^12.3.0",
54
+ "@metamask/approval-controller": "^10.0.0",
55
+ "@metamask/base-controller": "^10.0.0",
56
+ "@metamask/controller-utils": "^13.0.0",
62
57
  "@metamask/eth-query": "^4.0.0",
63
- "@metamask/gas-fee-controller": "^26.3.2",
64
- "@metamask/keyring-controller": "^27.1.1",
65
- "@metamask/messenger": "^2.0.0",
66
- "@metamask/network-controller": "^36.0.0",
67
- "@metamask/polling-controller": "^16.0.9",
58
+ "@metamask/gas-fee-controller": "^27.0.0",
59
+ "@metamask/keyring-controller": "^28.0.0",
60
+ "@metamask/messenger": "^3.0.0",
61
+ "@metamask/network-controller": "^37.0.0",
62
+ "@metamask/polling-controller": "^17.0.0",
68
63
  "@metamask/rpc-errors": "^7.0.2",
69
64
  "@metamask/superstruct": "^3.4.1",
70
- "@metamask/transaction-controller": "^69.7.0",
65
+ "@metamask/transaction-controller": "^70.0.0",
71
66
  "@metamask/utils": "^11.12.0",
72
67
  "bn.js": "^5.2.1",
73
68
  "immer": "^9.0.6",
74
- "lodash": "^4.17.21",
75
- "uuid": "^8.3.2"
69
+ "lodash-es": "^4.17.21",
70
+ "uuid": "^9.0.1"
76
71
  },
77
72
  "devDependencies": {
78
73
  "@metamask/auto-changelog": "^6.1.0",
79
- "@metamask/eth-block-tracker": "^15.0.0",
80
- "@ts-bridge/cli": "^0.6.4",
74
+ "@metamask/eth-block-tracker": "^16.0.0",
81
75
  "@types/jest": "^30.0.0",
76
+ "@typescript/native": "npm:typescript@^7.0.2",
82
77
  "deepmerge": "^4.2.2",
83
78
  "jest": "^30.4.2",
79
+ "rimraf": "^5.0.5",
84
80
  "ts-jest": "^29.4.11",
85
81
  "tsx": "^4.20.5",
86
82
  "typedoc": "^0.25.13",
87
83
  "typedoc-plugin-missing-exports": "^2.0.0",
88
- "typescript": "~5.3.3"
84
+ "typescript": "npm:@typescript/typescript6@^6.0.2"
89
85
  },
90
86
  "peerDependencies": {
91
87
  "@metamask/eth-block-tracker": ">=9"
92
88
  },
93
89
  "engines": {
94
- "node": "^18.18 || >=20"
90
+ "node": "^22.14.0 || ^24"
95
91
  }
96
92
  }
@@ -1,68 +0,0 @@
1
- "use strict";
2
- var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) {
3
- if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
4
- if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
5
- return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
6
- };
7
- Object.defineProperty(exports, "__esModule", { value: true });
8
- exports.BlockTrackerPollingController = exports.BlockTrackerPollingControllerOnly = void 0;
9
- const base_controller_1 = require("@metamask/base-controller");
10
- const polling_controller_1 = require("@metamask/polling-controller");
11
- /**
12
- * BlockTrackerPollingControllerMixin
13
- * A polling controller that polls using a block tracker.
14
- *
15
- * @param Base - The base class to mix onto.
16
- * @returns The composed class.
17
- */
18
- // This is a function that's used as class, and the return type is inferred from
19
- // the class defined inside the function scope, so this can't be easily typed.
20
- // eslint-disable-next-line @typescript-eslint/explicit-function-return-type, @typescript-eslint/naming-convention
21
- function BlockTrackerPollingControllerMixin(Base) {
22
- var _BlockTrackerPollingController_activeListeners;
23
- class BlockTrackerPollingController extends (0, polling_controller_1.AbstractPollingControllerBaseMixin)(Base) {
24
- constructor() {
25
- super(...arguments);
26
- _BlockTrackerPollingController_activeListeners.set(this, {});
27
- }
28
- _startPolling(input) {
29
- const key = (0, polling_controller_1.getKey)(input);
30
- if (__classPrivateFieldGet(this, _BlockTrackerPollingController_activeListeners, "f")[key]) {
31
- return;
32
- }
33
- const networkClient = this._getNetworkClientById(input.networkClientId);
34
- if (networkClient) {
35
- const updateOnNewBlock = this._executePoll.bind(this, input);
36
- // TODO: Either fix this lint violation or explain why it's necessary to ignore.
37
- // eslint-disable-next-line @typescript-eslint/no-misused-promises
38
- networkClient.blockTracker.addListener('latest', updateOnNewBlock);
39
- __classPrivateFieldGet(this, _BlockTrackerPollingController_activeListeners, "f")[key] = updateOnNewBlock;
40
- }
41
- else {
42
- throw new Error(`Unable to retrieve blockTracker for networkClientId ${input.networkClientId}`);
43
- }
44
- }
45
- _stopPollingByPollingTokenSetId(key) {
46
- const { networkClientId } = JSON.parse(key);
47
- const networkClient = this._getNetworkClientById(networkClientId);
48
- if (networkClient && __classPrivateFieldGet(this, _BlockTrackerPollingController_activeListeners, "f")[key]) {
49
- const listener = __classPrivateFieldGet(this, _BlockTrackerPollingController_activeListeners, "f")[key];
50
- if (listener) {
51
- // TODO: Either fix this lint violation or explain why it's necessary to ignore.
52
- // eslint-disable-next-line @typescript-eslint/no-misused-promises
53
- networkClient.blockTracker.removeListener('latest', listener);
54
- delete __classPrivateFieldGet(this, _BlockTrackerPollingController_activeListeners, "f")[key];
55
- }
56
- }
57
- }
58
- }
59
- _BlockTrackerPollingController_activeListeners = new WeakMap();
60
- return BlockTrackerPollingController;
61
- }
62
- class Empty {
63
- }
64
- const BlockTrackerPollingControllerOnly = () => BlockTrackerPollingControllerMixin(Empty);
65
- exports.BlockTrackerPollingControllerOnly = BlockTrackerPollingControllerOnly;
66
- const BlockTrackerPollingController = () => BlockTrackerPollingControllerMixin(base_controller_1.BaseController);
67
- exports.BlockTrackerPollingController = BlockTrackerPollingController;
68
- //# sourceMappingURL=BlockTrackerPollingController.cjs.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"BlockTrackerPollingController.cjs","sourceRoot":"","sources":["../src/BlockTrackerPollingController.ts"],"names":[],"mappings":";;;;;;;;AAAA,+DAA2D;AAK3D,qEAKsC;AAWtC;;;;;;GAMG;AACH,gFAAgF;AAChF,8EAA8E;AAC9E,kHAAkH;AAClH,SAAS,kCAAkC,CAGzC,IAAW;;IACX,MAAe,6BAA8B,SAAQ,IAAA,uDAAkC,EAGrF,IAAI,CAAC;QAHP;;YAIE,yDAAqE,EAAE,EAAC;QA2C1E,CAAC;QArCC,aAAa,CAAC,KAAmB;YAC/B,MAAM,GAAG,GAAG,IAAA,2BAAM,EAAC,KAAK,CAAC,CAAC;YAE1B,IAAI,uBAAA,IAAI,sDAAiB,CAAC,GAAG,CAAC,EAAE,CAAC;gBAC/B,OAAO;YACT,CAAC;YAED,MAAM,aAAa,GAAG,IAAI,CAAC,qBAAqB,CAAC,KAAK,CAAC,eAAe,CAAC,CAAC;YACxE,IAAI,aAAa,EAAE,CAAC;gBAClB,MAAM,gBAAgB,GAAG,IAAI,CAAC,YAAY,CAAC,IAAI,CAAC,IAAI,EAAE,KAAK,CAAC,CAAC;gBAC7D,gFAAgF;gBAChF,kEAAkE;gBAClE,aAAa,CAAC,YAAY,CAAC,WAAW,CAAC,QAAQ,EAAE,gBAAgB,CAAC,CAAC;gBACnE,uBAAA,IAAI,sDAAiB,CAAC,GAAG,CAAC,GAAG,gBAAgB,CAAC;YAChD,CAAC;iBAAM,CAAC;gBACN,MAAM,IAAI,KAAK,CACb,uDAAuD,KAAK,CAAC,eAAe,EAAE,CAC/E,CAAC;YACJ,CAAC;QACH,CAAC;QAED,+BAA+B,CAAC,GAAsB;YACpD,MAAM,EAAE,eAAe,EAAE,GAAG,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC;YAC5C,MAAM,aAAa,GAAG,IAAI,CAAC,qBAAqB,CAC9C,eAAkC,CACnC,CAAC;YAEF,IAAI,aAAa,IAAI,uBAAA,IAAI,sDAAiB,CAAC,GAAG,CAAC,EAAE,CAAC;gBAChD,MAAM,QAAQ,GAAG,uBAAA,IAAI,sDAAiB,CAAC,GAAG,CAAC,CAAC;gBAC5C,IAAI,QAAQ,EAAE,CAAC;oBACb,gFAAgF;oBAChF,kEAAkE;oBAClE,aAAa,CAAC,YAAY,CAAC,cAAc,CAAC,QAAQ,EAAE,QAAQ,CAAC,CAAC;oBAC9D,OAAO,uBAAA,IAAI,sDAAiB,CAAC,GAAG,CAAC,CAAC;gBACpC,CAAC;YACH,CAAC;QACH,CAAC;KACF;;IAED,OAAO,6BAA6B,CAAC;AACvC,CAAC;AAED,MAAM,KAAK;CAAG;AAEP,MAAM,iCAAiC,GAAG,GAK7C,EAAE,CAAC,kCAAkC,CAA6B,KAAK,CAAC,CAAC;AALhE,QAAA,iCAAiC,qCAK+B;AAEtE,MAAM,6BAA6B,GAAG,GAKzC,EAAE,CACJ,kCAAkC,CAChC,gCAAc,CACf,CAAC;AARS,QAAA,6BAA6B,iCAQtC","sourcesContent":["import { BaseController } from '@metamask/base-controller';\nimport type {\n NetworkClientId,\n NetworkClient,\n} from '@metamask/network-controller';\nimport {\n AbstractPollingControllerBaseMixin,\n getKey,\n Constructor,\n PollingTokenSetId,\n} from '@metamask/polling-controller';\nimport type { Json } from '@metamask/utils';\n\n/**\n * The minimum input required to start polling for a {@link BlockTrackerPollingController}.\n * Implementing classes may provide additional properties.\n */\nexport type BlockTrackerPollingInput = {\n networkClientId: NetworkClientId;\n};\n\n/**\n * BlockTrackerPollingControllerMixin\n * A polling controller that polls using a block tracker.\n *\n * @param Base - The base class to mix onto.\n * @returns The composed class.\n */\n// This is a function that's used as class, and the return type is inferred from\n// the class defined inside the function scope, so this can't be easily typed.\n// eslint-disable-next-line @typescript-eslint/explicit-function-return-type, @typescript-eslint/naming-convention\nfunction BlockTrackerPollingControllerMixin<\n TBase extends Constructor,\n PollingInput extends BlockTrackerPollingInput,\n>(Base: TBase) {\n abstract class BlockTrackerPollingController extends AbstractPollingControllerBaseMixin<\n TBase,\n PollingInput\n >(Base) {\n #activeListeners: Record<string, (options: Json) => Promise<void>> = {};\n\n abstract _getNetworkClientById(\n networkClientId: NetworkClientId,\n ): NetworkClient | undefined;\n\n _startPolling(input: PollingInput): void {\n const key = getKey(input);\n\n if (this.#activeListeners[key]) {\n return;\n }\n\n const networkClient = this._getNetworkClientById(input.networkClientId);\n if (networkClient) {\n const updateOnNewBlock = this._executePoll.bind(this, input);\n // TODO: Either fix this lint violation or explain why it's necessary to ignore.\n // eslint-disable-next-line @typescript-eslint/no-misused-promises\n networkClient.blockTracker.addListener('latest', updateOnNewBlock);\n this.#activeListeners[key] = updateOnNewBlock;\n } else {\n throw new Error(\n `Unable to retrieve blockTracker for networkClientId ${input.networkClientId}`,\n );\n }\n }\n\n _stopPollingByPollingTokenSetId(key: PollingTokenSetId): void {\n const { networkClientId } = JSON.parse(key);\n const networkClient = this._getNetworkClientById(\n networkClientId as NetworkClientId,\n );\n\n if (networkClient && this.#activeListeners[key]) {\n const listener = this.#activeListeners[key];\n if (listener) {\n // TODO: Either fix this lint violation or explain why it's necessary to ignore.\n // eslint-disable-next-line @typescript-eslint/no-misused-promises\n networkClient.blockTracker.removeListener('latest', listener);\n delete this.#activeListeners[key];\n }\n }\n }\n }\n\n return BlockTrackerPollingController;\n}\n\nclass Empty {}\n\nexport const BlockTrackerPollingControllerOnly = <\n PollingInput extends BlockTrackerPollingInput,\n // The return type is inferred from the class defined inside the function\n // scope, so this can't be easily typed.\n // eslint-disable-next-line @typescript-eslint/explicit-function-return-type\n>() => BlockTrackerPollingControllerMixin<typeof Empty, PollingInput>(Empty);\n\nexport const BlockTrackerPollingController = <\n PollingInput extends BlockTrackerPollingInput,\n // The return type is inferred from the class defined inside the function\n // scope, so this can't be easily typed.\n // eslint-disable-next-line @typescript-eslint/explicit-function-return-type\n>() =>\n BlockTrackerPollingControllerMixin<typeof BaseController, PollingInput>(\n BaseController,\n );\n"]}
@@ -1,41 +0,0 @@
1
- import { BaseController } from "@metamask/base-controller";
2
- import type { NetworkClientId, NetworkClient } from "@metamask/network-controller";
3
- import { PollingTokenSetId } from "@metamask/polling-controller";
4
- import type { Json } from "@metamask/utils";
5
- /**
6
- * The minimum input required to start polling for a {@link BlockTrackerPollingController}.
7
- * Implementing classes may provide additional properties.
8
- */
9
- export type BlockTrackerPollingInput = {
10
- networkClientId: NetworkClientId;
11
- };
12
- declare class Empty {
13
- }
14
- export declare const BlockTrackerPollingControllerOnly: <PollingInput extends BlockTrackerPollingInput>() => (abstract new (...args: any[]) => {
15
- "__#21@#activeListeners": Record<string, (options: Json) => Promise<void>>;
16
- _getNetworkClientById(networkClientId: NetworkClientId): NetworkClient | undefined;
17
- _startPolling(input: PollingInput): void;
18
- _stopPollingByPollingTokenSetId(key: PollingTokenSetId): void;
19
- readonly "__#3@#pollingTokenSets": Map<string, Set<string>>;
20
- readonly "__#3@#callbacks": Map<string, Set<(input: PollingInput) => void>>;
21
- _executePoll(input: PollingInput): Promise<void>;
22
- startPolling(input: PollingInput): string;
23
- stopAllPolling(): void;
24
- stopPollingByPollingToken(pollingToken: string): void;
25
- onPollingComplete(input: PollingInput, callback: (input: PollingInput) => void): void;
26
- }) & typeof Empty;
27
- export declare const BlockTrackerPollingController: <PollingInput extends BlockTrackerPollingInput>() => (abstract new (...args: any[]) => {
28
- "__#21@#activeListeners": Record<string, (options: Json) => Promise<void>>;
29
- _getNetworkClientById(networkClientId: NetworkClientId): NetworkClient | undefined;
30
- _startPolling(input: PollingInput): void;
31
- _stopPollingByPollingTokenSetId(key: PollingTokenSetId): void;
32
- readonly "__#3@#pollingTokenSets": Map<string, Set<string>>;
33
- readonly "__#3@#callbacks": Map<string, Set<(input: PollingInput) => void>>;
34
- _executePoll(input: PollingInput): Promise<void>;
35
- startPolling(input: PollingInput): string;
36
- stopAllPolling(): void;
37
- stopPollingByPollingToken(pollingToken: string): void;
38
- onPollingComplete(input: PollingInput, callback: (input: PollingInput) => void): void;
39
- }) & typeof BaseController;
40
- export {};
41
- //# sourceMappingURL=BlockTrackerPollingController.d.cts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"BlockTrackerPollingController.d.cts","sourceRoot":"","sources":["../src/BlockTrackerPollingController.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,kCAAkC;AAC3D,OAAO,KAAK,EACV,eAAe,EACf,aAAa,EACd,qCAAqC;AACtC,OAAO,EAIL,iBAAiB,EAClB,qCAAqC;AACtC,OAAO,KAAK,EAAE,IAAI,EAAE,wBAAwB;AAE5C;;;GAGG;AACH,MAAM,MAAM,wBAAwB,GAAG;IACrC,eAAe,EAAE,eAAe,CAAC;CAClC,CAAC;AAoEF,cAAM,KAAK;CAAG;AAEd,eAAO,MAAM,iCAAiC;uDAlDC,IAAI,KAAK,QAAQ,IAAI,CAAC;2CAG9C,eAAe,GAC/B,aAAa,GAAG,SAAS;wCAEQ,IAAI;yCAqBH,iBAAiB,GAAG,IAAI;;;;;;;;iBA4BW,CAAC;AAE7E,eAAO,MAAM,6BAA6B;uDAzDK,IAAI,KAAK,QAAQ,IAAI,CAAC;2CAG9C,eAAe,GAC/B,aAAa,GAAG,SAAS;wCAEQ,IAAI;yCAqBH,iBAAiB,GAAG,IAAI;;;;;;;;0BAsC9D,CAAC"}
@@ -1 +0,0 @@
1
- {"version":3,"file":"BlockTrackerPollingController.d.mts","sourceRoot":"","sources":["../src/BlockTrackerPollingController.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,kCAAkC;AAC3D,OAAO,KAAK,EACV,eAAe,EACf,aAAa,EACd,qCAAqC;AACtC,OAAO,EAIL,iBAAiB,EAClB,qCAAqC;AACtC,OAAO,KAAK,EAAE,IAAI,EAAE,wBAAwB;AAE5C;;;GAGG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FAAgF;gBAChF,kEAAkE;gBAClE,aAAa,CAAC,YAAY,CAAC,WAAW,CAAC,QAAQ,EAAE,gBAAgB,CAAC,CAAC;gBACnE,uBAAA,IAAI,sDAAiB,CAAC,GAAG,CAAC,GAAG,gBAAgB,CAAC;YAChD,CAAC;iBAAM,CAAC;gBACN,MAAM,IAAI,KAAK,CACb,uDAAuD,KAAK,CAAC,eAAe,EAAE,CAC/E,CAAC;YACJ,CAAC;QACH,CAAC;QAED,+BAA+B,CAAC,GAAsB;YACpD,MAAM,EAAE,eAAe,EAAE,GAAG,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC;YAC5C,MAAM,aAAa,GAAG,IAAI,CAAC,qBAAqB,CAC9C,eAAkC,CACnC,CAAC;YAEF,IAAI,aAAa,IAAI,uBAAA,IAAI,sDAAiB,CAAC,GAAG,CAAC,EAAE,CAAC;gBAChD,MAAM,QAAQ,GAAG,uBAAA,IAAI,sDAAiB,CAAC,GAAG,CAAC,CAAC;gBAC5C,IAAI,QAAQ,EAAE,CAAC;oBACb,gFAAgF;oBAChF,kEAAkE;oBAClE,aAAa,CAAC,YAAY,CAAC,cAAc,CAAC,QAAQ,EAAE,QAAQ,CAAC,CAAC;oBAC9D,OAAO,uBAAA,IAAI,sDAAiB,CAAC,GAAG,CAAC,CAAC;gBACpC,CAAC;YACH,CAAC;QACH,CAAC;KACF;;IAED,OAAO,6BAA6B,CAAC;AACvC,CAAC;AAED,MAAM,KAAK;CAAG;AAEd,MAAM,CAAC,MAAM,iCAAiC,GAAG,GAK7C,EAAE,CAAC,kCAAkC,CAA6B,KAAK,CAAC,CAAC;AAE7E,MAAM,CAAC,MAAM,6BAA6B,GAAG,GAKzC,EAAE,CACJ,kCAAkC,CAChC,cAAc,CACf,CAAC","sourcesContent":["import { BaseController } from '@metamask/base-controller';\nimport type {\n NetworkClientId,\n NetworkClient,\n} from '@metamask/network-controller';\nimport {\n AbstractPollingControllerBaseMixin,\n getKey,\n Constructor,\n PollingTokenSetId,\n} from '@metamask/polling-controller';\nimport type { Json } from '@metamask/utils';\n\n/**\n * The minimum input required to start polling for a {@link BlockTrackerPollingController}.\n * Implementing classes may provide additional properties.\n */\nexport type BlockTrackerPollingInput = {\n networkClientId: NetworkClientId;\n};\n\n/**\n * BlockTrackerPollingControllerMixin\n * A polling controller that polls using a block tracker.\n *\n * @param Base - The base class to mix onto.\n * @returns The composed class.\n */\n// This is a function that's used as class, and the return type is inferred from\n// the class defined inside the function scope, so this can't be easily typed.\n// eslint-disable-next-line @typescript-eslint/explicit-function-return-type, @typescript-eslint/naming-convention\nfunction BlockTrackerPollingControllerMixin<\n TBase extends Constructor,\n PollingInput extends BlockTrackerPollingInput,\n>(Base: TBase) {\n abstract class BlockTrackerPollingController extends AbstractPollingControllerBaseMixin<\n TBase,\n PollingInput\n >(Base) {\n #activeListeners: Record<string, (options: Json) => Promise<void>> = {};\n\n abstract _getNetworkClientById(\n networkClientId: NetworkClientId,\n ): NetworkClient | undefined;\n\n _startPolling(input: PollingInput): void {\n const key = getKey(input);\n\n if (this.#activeListeners[key]) {\n return;\n }\n\n const networkClient = this._getNetworkClientById(input.networkClientId);\n if (networkClient) {\n const updateOnNewBlock = this._executePoll.bind(this, input);\n // TODO: Either fix this lint violation or explain why it's necessary to ignore.\n // eslint-disable-next-line @typescript-eslint/no-misused-promises\n networkClient.blockTracker.addListener('latest', updateOnNewBlock);\n this.#activeListeners[key] = updateOnNewBlock;\n } else {\n throw new Error(\n `Unable to retrieve blockTracker for networkClientId ${input.networkClientId}`,\n );\n }\n }\n\n _stopPollingByPollingTokenSetId(key: PollingTokenSetId): void {\n const { networkClientId } = JSON.parse(key);\n const networkClient = this._getNetworkClientById(\n networkClientId as NetworkClientId,\n );\n\n if (networkClient && this.#activeListeners[key]) {\n const listener = this.#activeListeners[key];\n if (listener) {\n // TODO: Either fix this lint violation or explain why it's necessary to ignore.\n // eslint-disable-next-line @typescript-eslint/no-misused-promises\n networkClient.blockTracker.removeListener('latest', listener);\n delete this.#activeListeners[key];\n }\n }\n }\n }\n\n return BlockTrackerPollingController;\n}\n\nclass Empty {}\n\nexport const BlockTrackerPollingControllerOnly = <\n PollingInput extends BlockTrackerPollingInput,\n // The return type is inferred from the class defined inside the function\n // scope, so this can't be easily typed.\n // eslint-disable-next-line @typescript-eslint/explicit-function-return-type\n>() => BlockTrackerPollingControllerMixin<typeof Empty, PollingInput>(Empty);\n\nexport const BlockTrackerPollingController = <\n PollingInput extends BlockTrackerPollingInput,\n // The return type is inferred from the class defined inside the function\n // scope, so this can't be easily typed.\n // eslint-disable-next-line @typescript-eslint/explicit-function-return-type\n>() =>\n BlockTrackerPollingControllerMixin<typeof BaseController, PollingInput>(\n BaseController,\n );\n"]}
@@ -1,7 +0,0 @@
1
- "use strict";
2
- /**
3
- * This file is auto generated.
4
- * Do not edit manually.
5
- */
6
- Object.defineProperty(exports, "__esModule", { value: true });
7
- //# sourceMappingURL=UserOperationController-method-action-types.cjs.map
@@ -1 +0,0 @@
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.\n * Do not edit manually.\n */\n\nimport type { UserOperationController } from './UserOperationController.js';\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"]}
@@ -1 +0,0 @@
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,sCAAqC;AAE5E;;;;;;;;;;;;;;;;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"}
@@ -1,57 +0,0 @@
1
- /**
2
- * This file is auto generated.
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
@@ -1 +0,0 @@
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,sCAAqC;AAE5E;;;;;;;;;;;;;;;;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"}
@@ -1 +0,0 @@
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.\n * Do not edit manually.\n */\n\nimport type { UserOperationController } from './UserOperationController.js';\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"]}