@metamask-previews/user-operation-controller 41.2.7-preview-064aea96d → 41.2.7-preview-ec4680201

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 (55) hide show
  1. package/CHANGELOG.md +1 -0
  2. package/dist/UserOperationController-method-action-types.cjs.map +1 -1
  3. package/dist/UserOperationController-method-action-types.d.cts.map +1 -1
  4. package/dist/UserOperationController-method-action-types.d.mts.map +1 -1
  5. package/dist/UserOperationController-method-action-types.mjs.map +1 -1
  6. package/dist/UserOperationController.cjs +68 -68
  7. package/dist/UserOperationController.cjs.map +1 -1
  8. package/dist/UserOperationController.d.cts +1 -1
  9. package/dist/UserOperationController.d.cts.map +1 -1
  10. package/dist/UserOperationController.d.mts +1 -1
  11. package/dist/UserOperationController.d.mts.map +1 -1
  12. package/dist/UserOperationController.mjs +1 -1
  13. package/dist/UserOperationController.mjs.map +1 -1
  14. package/dist/helpers/Bundler.cjs +2 -2
  15. package/dist/helpers/Bundler.cjs.map +1 -1
  16. package/dist/helpers/Bundler.d.cts.map +1 -1
  17. package/dist/helpers/Bundler.d.mts.map +1 -1
  18. package/dist/helpers/Bundler.mjs.map +1 -1
  19. package/dist/helpers/PendingUserOperationTracker.cjs +8 -8
  20. package/dist/helpers/PendingUserOperationTracker.cjs.map +1 -1
  21. package/dist/helpers/PendingUserOperationTracker.d.cts +1 -1
  22. package/dist/helpers/PendingUserOperationTracker.d.cts.map +1 -1
  23. package/dist/helpers/PendingUserOperationTracker.d.mts +1 -1
  24. package/dist/helpers/PendingUserOperationTracker.d.mts.map +1 -1
  25. package/dist/helpers/PendingUserOperationTracker.mjs.map +1 -1
  26. package/dist/helpers/SnapSmartContractAccount.cjs +9 -9
  27. package/dist/helpers/SnapSmartContractAccount.cjs.map +1 -1
  28. package/dist/helpers/SnapSmartContractAccount.d.cts.map +1 -1
  29. package/dist/helpers/SnapSmartContractAccount.d.mts.map +1 -1
  30. package/dist/helpers/SnapSmartContractAccount.mjs.map +1 -1
  31. package/dist/index.cjs.map +1 -1
  32. package/dist/index.d.cts.map +1 -1
  33. package/dist/index.d.mts.map +1 -1
  34. package/dist/index.mjs.map +1 -1
  35. package/dist/utils/gas-fees.cjs +4 -4
  36. package/dist/utils/gas-fees.cjs.map +1 -1
  37. package/dist/utils/gas-fees.d.cts.map +1 -1
  38. package/dist/utils/gas-fees.d.mts.map +1 -1
  39. package/dist/utils/gas-fees.mjs.map +1 -1
  40. package/dist/utils/gas.cjs +9 -9
  41. package/dist/utils/gas.cjs.map +1 -1
  42. package/dist/utils/gas.d.cts.map +1 -1
  43. package/dist/utils/gas.d.mts.map +1 -1
  44. package/dist/utils/gas.mjs.map +1 -1
  45. package/dist/utils/transaction.cjs +12 -12
  46. package/dist/utils/transaction.cjs.map +1 -1
  47. package/dist/utils/transaction.d.cts.map +1 -1
  48. package/dist/utils/transaction.d.mts.map +1 -1
  49. package/dist/utils/transaction.mjs.map +1 -1
  50. package/dist/utils/validation.cjs +3 -3
  51. package/dist/utils/validation.cjs.map +1 -1
  52. package/dist/utils/validation.d.cts.map +1 -1
  53. package/dist/utils/validation.d.mts.map +1 -1
  54. package/dist/utils/validation.mjs.map +1 -1
  55. package/package.json +4 -4
@@ -13,8 +13,8 @@ var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (
13
13
  var _SnapSmartContractAccount_messenger;
14
14
  Object.defineProperty(exports, "__esModule", { value: true });
15
15
  exports.SnapSmartContractAccount = void 0;
16
- const constants_1 = require("../constants.cjs");
17
- const chain_id_1 = require("../utils/chain-id.cjs");
16
+ const constants_js_1 = require("../constants.cjs");
17
+ const chain_id_js_1 = require("../utils/chain-id.cjs");
18
18
  class SnapSmartContractAccount {
19
19
  constructor(messenger) {
20
20
  _SnapSmartContractAccount_messenger.set(this, void 0);
@@ -22,10 +22,10 @@ class SnapSmartContractAccount {
22
22
  }
23
23
  async prepareUserOperation(request) {
24
24
  const { chainId, data: requestData, from: sender, to: requestTo, value: requestValue, } = request;
25
- const data = requestData ?? constants_1.EMPTY_BYTES;
26
- const to = requestTo ?? constants_1.ADDRESS_ZERO;
27
- const value = requestValue ?? constants_1.VALUE_ZERO;
28
- const response = await __classPrivateFieldGet(this, _SnapSmartContractAccount_messenger, "f").call('KeyringController:prepareUserOperation', sender, [{ data, to, value }], { chainId: (0, chain_id_1.toEip155ChainId)(chainId) });
25
+ const data = requestData ?? constants_js_1.EMPTY_BYTES;
26
+ const to = requestTo ?? constants_js_1.ADDRESS_ZERO;
27
+ const value = requestValue ?? constants_js_1.VALUE_ZERO;
28
+ const response = await __classPrivateFieldGet(this, _SnapSmartContractAccount_messenger, "f").call('KeyringController:prepareUserOperation', sender, [{ data, to, value }], { chainId: (0, chain_id_js_1.toEip155ChainId)(chainId) });
29
29
  const { bundlerUrl: bundler, callData, dummyPaymasterAndData, dummySignature, gasLimits: gas, initCode, nonce, } = response;
30
30
  return {
31
31
  bundler,
@@ -41,8 +41,8 @@ class SnapSmartContractAccount {
41
41
  async updateUserOperation(request) {
42
42
  const { userOperation, chainId } = request;
43
43
  const { sender } = userOperation;
44
- const { paymasterAndData: responsePaymasterAndData, verificationGasLimit, preVerificationGas, callGasLimit, } = await __classPrivateFieldGet(this, _SnapSmartContractAccount_messenger, "f").call('KeyringController:patchUserOperation', sender, userOperation, { chainId: (0, chain_id_1.toEip155ChainId)(chainId) });
45
- const paymasterAndData = responsePaymasterAndData === constants_1.EMPTY_BYTES
44
+ const { paymasterAndData: responsePaymasterAndData, verificationGasLimit, preVerificationGas, callGasLimit, } = await __classPrivateFieldGet(this, _SnapSmartContractAccount_messenger, "f").call('KeyringController:patchUserOperation', sender, userOperation, { chainId: (0, chain_id_js_1.toEip155ChainId)(chainId) });
45
+ const paymasterAndData = responsePaymasterAndData === constants_js_1.EMPTY_BYTES
46
46
  ? undefined
47
47
  : responsePaymasterAndData;
48
48
  return {
@@ -55,7 +55,7 @@ class SnapSmartContractAccount {
55
55
  async signUserOperation(request) {
56
56
  const { userOperation, chainId } = request;
57
57
  const { sender } = userOperation;
58
- const signature = await __classPrivateFieldGet(this, _SnapSmartContractAccount_messenger, "f").call('KeyringController:signUserOperation', sender, userOperation, { chainId: (0, chain_id_1.toEip155ChainId)(chainId) });
58
+ const signature = await __classPrivateFieldGet(this, _SnapSmartContractAccount_messenger, "f").call('KeyringController:signUserOperation', sender, userOperation, { chainId: (0, chain_id_js_1.toEip155ChainId)(chainId) });
59
59
  return { signature };
60
60
  }
61
61
  }
@@ -1 +1 @@
1
- {"version":3,"file":"SnapSmartContractAccount.cjs","sourceRoot":"","sources":["../../src/helpers/SnapSmartContractAccount.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;AAAA,gDAAqE;AAWrE,oDAAoD;AAEpD,MAAa,wBAAwB;IAGnC,YAAY,SAA2C;QAF9C,sDAA6C;QAGpD,uBAAA,IAAI,uCAAc,SAAS,MAAA,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,uBAAW,CAAC;QACxC,MAAM,EAAE,GAAG,SAAS,IAAI,wBAAY,CAAC;QACrC,MAAM,KAAK,GAAG,YAAY,IAAI,sBAAU,CAAC;QAEzC,MAAM,QAAQ,GAAG,MAAM,uBAAA,IAAI,2CAAW,CAAC,IAAI,CACzC,wCAAwC,EACxC,MAAM,EACN,CAAC,EAAE,IAAI,EAAE,EAAE,EAAE,KAAK,EAAE,CAAC,EACrB,EAAE,OAAO,EAAE,IAAA,0BAAe,EAAC,OAAO,CAAC,EAAE,CACtC,CAAC;QAEF,MAAM,EACJ,UAAU,EAAE,OAAO,EACnB,QAAQ,EACR,qBAAqB,EACrB,cAAc,EACd,SAAS,EAAE,GAAG,EACd,QAAQ,EAC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serOperationResponse,\n SignUserOperationRequest,\n SignUserOperationResponse,\n SmartContractAccount,\n UpdateUserOperationRequest,\n UpdateUserOperationResponse,\n} from '../types';\nimport type { UserOperationControllerMessenger } from '../UserOperationController';\nimport { toEip155ChainId } from '../utils/chain-id';\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"]}
1
+ {"version":3,"file":"SnapSmartContractAccount.cjs","sourceRoot":"","sources":["../../src/helpers/SnapSmartContractAccount.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;AAAA,mDAAwE;AAWxE,uDAAuD;AAEvD,MAAa,wBAAwB;IAGnC,YAAY,SAA2C;QAF9C,sDAA6C;QAGpD,uBAAA,IAAI,uCAAc,SAAS,MAAA,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,0BAAW,CAAC;QACxC,MAAM,EAAE,GAAG,SAAS,IAAI,2BAAY,CAAC;QACrC,MAAM,KAAK,GAAG,YAAY,IAAI,yBAAU,CAAC;QAEzC,MAAM,QAAQ,GAAG,MAAM,uBAAA,IAAI,2CAAW,CAAC,IAAI,CACzC,wCAAwC,EACxC,MAAM,EACN,CAAC,EAAE,IAAI,EAAE,EAAE,EAAE,KAAK,EAAE,CAAC,EACrB,EAAE,OAAO,EAAE,IAAA,6BAAe,EAAC,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,uBAAA,IAAI,2CAAW,CAAC,IAAI,CAC5B,sCAAsC,EACtC,MAAM,EACN,aAAa,EACb,EAAE,OAAO,EAAE,IAAA,6BAAe,EAAC,OAAO,CAAC,EAAE,CACtC,CAAC;QAEF,MAAM,gBAAgB,GACpB,wBAAwB,KAAK,0BAAW;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,uBAAA,IAAI,2CAAW,CAAC,IAAI,CAC1C,qCAAqC,EACrC,MAAM,EACN,aAAa,EACb,EAAE,OAAO,EAAE,IAAA,6BAAe,EAAC,OAAO,CAAC,EAAE,CACtC,CAAC;QAEF,OAAO,EAAE,SAAS,EAAE,CAAC;IACvB,CAAC;CACF;AAjGD,4DAiGC","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"]}
@@ -1 +1 @@
1
- {"version":3,"file":"SnapSmartContractAccount.d.cts","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,qBAAiB;AAClB,OAAO,KAAK,EAAE,gCAAgC,EAAE,uCAAmC;AAGnF,qBAAa,wBAAyB,YAAW,oBAAoB;;gBAGvD,SAAS,EAAE,gCAAgC;IAIjD,oBAAoB,CACxB,OAAO,EAAE,2BAA2B,GACnC,OAAO,CAAC,4BAA4B,CAAC;IA0ClC,mBAAmB,CACvB,OAAO,EAAE,0BAA0B,GAClC,OAAO,CAAC,2BAA2B,CAAC;IA6BjC,iBAAiB,CACrB,OAAO,EAAE,wBAAwB,GAChC,OAAO,CAAC,yBAAyB,CAAC;CAatC"}
1
+ {"version":3,"file":"SnapSmartContractAccount.d.cts","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,qBAAoB;AACrB,OAAO,KAAK,EAAE,gCAAgC,EAAE,uCAAsC;AAGtF,qBAAa,wBAAyB,YAAW,oBAAoB;;gBAGvD,SAAS,EAAE,gCAAgC;IAIjD,oBAAoB,CACxB,OAAO,EAAE,2BAA2B,GACnC,OAAO,CAAC,4BAA4B,CAAC;IA0ClC,mBAAmB,CACvB,OAAO,EAAE,0BAA0B,GAClC,OAAO,CAAC,2BAA2B,CAAC;IA6BjC,iBAAiB,CACrB,OAAO,EAAE,wBAAwB,GAChC,OAAO,CAAC,yBAAyB,CAAC;CAatC"}
@@ -1 +1 @@
1
- {"version":3,"file":"SnapSmartContractAccount.d.mts","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,qBAAiB;AAClB,OAAO,KAAK,EAAE,gCAAgC,EAAE,uCAAmC;AAGnF,qBAAa,wBAAyB,YAAW,oBAAoB;;gBAGvD,SAAS,EAAE,gCAAgC;IAIjD,oBAAoB,CACxB,OAAO,EAAE,2BAA2B,GACnC,OAAO,CAAC,4BAA4B,CAAC;IA0ClC,mBAAmB,CACvB,OAAO,EAAE,0BAA0B,GAClC,OAAO,CAAC,2BAA2B,CAAC;IA6BjC,iBAAiB,CACrB,OAAO,EAAE,wBAAwB,GAChC,OAAO,CAAC,yBAAyB,CAAC;CAatC"}
1
+ {"version":3,"file":"SnapSmartContractAccount.d.mts","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,qBAAoB;AACrB,OAAO,KAAK,EAAE,gCAAgC,EAAE,uCAAsC;AAGtF,qBAAa,wBAAyB,YAAW,oBAAoB;;gBAGvD,SAAS,EAAE,gCAAgC;IAIjD,oBAAoB,CACxB,OAAO,EAAE,2BAA2B,GACnC,OAAO,CAAC,4BAA4B,CAAC;IA0ClC,mBAAmB,CACvB,OAAO,EAAE,0BAA0B,GAClC,OAAO,CAAC,2BAA2B,CAAC;IA6BjC,iBAAiB,CACrB,OAAO,EAAE,wBAAwB,GAChC,OAAO,CAAC,yBAAyB,CAAC;CAatC"}
@@ -1 +1 @@
1
- {"version":3,"file":"SnapSmartContractAccount.mjs","sourceRoot":"","sources":["../../src/helpers/SnapSmartContractAccount.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,OAAO,EAAE,YAAY,EAAE,WAAW,EAAE,UAAU,EAAE,yBAAqB;AAWrE,OAAO,EAAE,eAAe,EAAE,8BAA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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,uBAAA,IAAI,2CAAW,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';\nimport type {\n PrepareUserOperationRequest,\n PrepareUserOperationResponse,\n SignUserOperationRequest,\n SignUserOperationResponse,\n SmartContractAccount,\n UpdateUserOperationRequest,\n UpdateUserOperationResponse,\n} from '../types';\nimport type { UserOperationControllerMessenger } from '../UserOperationController';\nimport { toEip155ChainId } from '../utils/chain-id';\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"]}
1
+ {"version":3,"file":"SnapSmartContractAccount.mjs","sourceRoot":"","sources":["../../src/helpers/SnapSmartContractAccount.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,OAAO,EAAE,YAAY,EAAE,WAAW,EAAE,UAAU,EAAE,yBAAwB;AAWxE,OAAO,EAAE,eAAe,EAAE,8BAA6B;AAEvD,MAAM,OAAO,wBAAwB;IAGnC,YAAY,SAA2C;QAF9C,sDAA6C;QAGpD,uBAAA,IAAI,uCAAc,SAAS,MAAA,CAAC;IAC9B,CAAC;IAED,KAAK,CAAC,oBAAoB,CACxB,OAAoC;QAEpC,MAAM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,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,uBAAA,IAAI,2CAAW,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"]}
@@ -1 +1 @@
1
- {"version":3,"file":"index.cjs","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,gEAA0C;AAM1C,8CAAwB","sourcesContent":["export * from './UserOperationController';\nexport type {\n UserOperationControllerAddUserOperationAction,\n UserOperationControllerAddUserOperationFromTransactionAction,\n UserOperationControllerStartPollingByNetworkClientIdAction,\n} from './UserOperationController-method-action-types';\nexport * from './types';\n"]}
1
+ {"version":3,"file":"index.cjs","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,gEAA6C;AAM7C,8CAA2B","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"]}
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.cts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,8CAA0C;AAC1C,YAAY,EACV,6CAA6C,EAC7C,4DAA4D,EAC5D,0DAA0D,GAC3D,0DAAsD;AACvD,4BAAwB"}
1
+ {"version":3,"file":"index.d.cts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,8CAA6C;AAC7C,YAAY,EACV,6CAA6C,EAC7C,4DAA4D,EAC5D,0DAA0D,GAC3D,0DAAyD;AAC1D,4BAA2B"}
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.mts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,8CAA0C;AAC1C,YAAY,EACV,6CAA6C,EAC7C,4DAA4D,EAC5D,0DAA0D,GAC3D,0DAAsD;AACvD,4BAAwB"}
1
+ {"version":3,"file":"index.d.mts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,8CAA6C;AAC7C,YAAY,EACV,6CAA6C,EAC7C,4DAA4D,EAC5D,0DAA0D,GAC3D,0DAAyD;AAC1D,4BAA2B"}
@@ -1 +1 @@
1
- {"version":3,"file":"index.mjs","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,8CAA0C;AAM1C,4BAAwB","sourcesContent":["export * from './UserOperationController';\nexport type {\n UserOperationControllerAddUserOperationAction,\n UserOperationControllerAddUserOperationFromTransactionAction,\n UserOperationControllerStartPollingByNetworkClientIdAction,\n} from './UserOperationController-method-action-types';\nexport * from './types';\n"]}
1
+ {"version":3,"file":"index.mjs","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,8CAA6C;AAM7C,4BAA2B","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"]}
@@ -9,9 +9,9 @@ const eth_query_1 = __importDefault(require("@metamask/eth-query"));
9
9
  const gas_fee_controller_1 = require("@metamask/gas-fee-controller");
10
10
  const transaction_controller_1 = require("@metamask/transaction-controller");
11
11
  const utils_1 = require("@metamask/utils");
12
- const constants_1 = require("../constants.cjs");
13
- const logger_1 = require("../logger.cjs");
14
- const log = (0, logger_1.createModuleLogger)(logger_1.projectLogger, 'gas-fees');
12
+ const constants_js_1 = require("../constants.cjs");
13
+ const logger_js_1 = require("../logger.cjs");
14
+ const log = (0, logger_js_1.createModuleLogger)(logger_js_1.projectLogger, 'gas-fees');
15
15
  /**
16
16
  * Populates the gas fee properties for a user operation.
17
17
  *
@@ -189,6 +189,6 @@ function gweiDecimalToWeiHex(value) {
189
189
  * @returns Whether the gas fee property is empty.
190
190
  */
191
191
  function isGasFeeEmpty(value) {
192
- return !value || value === constants_1.EMPTY_BYTES;
192
+ return !value || value === constants_js_1.EMPTY_BYTES;
193
193
  }
194
194
  //# sourceMappingURL=gas-fees.cjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"gas-fees.cjs","sourceRoot":"","sources":["../../src/utils/gas-fees.ts"],"names":[],"mappings":";;;;;;AAAA,iEAKoC;AACpC,oEAA2C;AAC3C,qEAAkE;AAIlE,6EAAgE;AAEhE,2CAAwC;AAExC,gDAA2C;AAC3C,0CAA8D;AAI9D,MAAM,GAAG,GAAG,IAAA,2BAAkB,EAAC,sBAAa,EAAE,UAAU,CAAC,CAAC;AAe1D;;;;;;;;;GASG;AACI,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,KAAK,IAAI,EAAE;QACpC,IAAI,CAAC,gBAAgB,EAAE,CAAC;YACtB,gBAAgB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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,uCAAkB,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,IAAA,wBAAK,EAAC,IAAI,mBAAQ,CAAC,QAAQ,CAAC,EAAE,UAAU,CAAC,CAE3D,CAAC;IAEd,IAAI,CAAC,eAAe,EAAE,CAAC;QACrB,OAAO,EAAE,CAAC;IACZ,CAAC;IAED,MAAM,YAAY,GAAG,IAAA,aAAK,EAAC,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,IAAA,wBAAK,EAAC,IAAA,iCAAc,EAAC,KAAK,CAAC,CAAC,CAAC;AACtC,CAAC;AAED;;;;;GAKG;AACH,SAAS,aAAa,CAAC,KAAc;IACnC,OAAO,CAAC,KAAK,IAAI,KAAK,KAAK,uBAAW,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';\nimport { createModuleLogger, projectLogger } from '../logger';\nimport type { UserOperation, UserOperationMetadata } from '../types';\nimport type { AddUserOperationRequest } from '../UserOperationController';\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
+ {"version":3,"file":"gas-fees.cjs","sourceRoot":"","sources":["../../src/utils/gas-fees.ts"],"names":[],"mappings":";;;;;;AAAA,iEAKoC;AACpC,oEAA2C;AAC3C,qEAAkE;AAIlE,6EAAgE;AAEhE,2CAAwC;AAExC,mDAA8C;AAC9C,6CAAiE;AAIjE,MAAM,GAAG,GAAG,IAAA,8BAAkB,EAAC,yBAAa,EAAE,UAAU,CAAC,CAAC;AAe1D;;;;;;;;;GASG;AACI,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,KAAK,IAAI,EAAE;QACpC,IAAI,CAAC,gBAAgB,EAAE,CAAC;YACtB,gBAAgB,GAAG,MAAM,mBAAmB,CAAC,OAAO,CAAC,CAAC;QACxD,CAAC;QAED,OAAO,gBAAgB,CAAC;IAC1B,CAAC,CAAC;IAEF,aAAa,CAAC,YAAY,GAAG,MAAM,eAAe,CAChD,eAAe,EACf,kBAAkB,EAClB,WAAW,CACZ,CAAC;IAEF,aAAa,CAAC,oBAAoB,GAAG,MAAM,uBAAuB,CAChE,eAAe,EACf,kBAAkB,EAClB,aAAa,EACb,WAAW,CACZ,CAAC;IAEF,QAAQ,CAAC,YAAY,GAAG,eAAe,CACrC,QAAQ,EACR,eAAe,EACf,gBAAgB,EAChB,WAAW,CACZ,CAAC;AACJ,CAAC;AAhCD,sCAgCC;AAED;;;;;;;GAOG;AACH,KAAK,UAAU,eAAe,CAC5B,eAAwC,EACxC,kBAAmD,EACnD,WAA+B;IAE/B,MAAM,EAAE,YAAY,EAAE,oBAAoB,EAAE,GAAG,eAA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C,CAE3D,CAAC;IAEd,IAAI,CAAC,eAAe,EAAE,CAAC;QACrB,OAAO,EAAE,CAAC;IACZ,CAAC;IAED,MAAM,YAAY,GAAG,IAAA,aAAK,EAAC,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,IAAA,wBAAK,EAAC,IAAA,iCAAc,EAAC,KAAK,CAAC,CAAC,CAAC;AACtC,CAAC;AAED;;;;;GAKG;AACH,SAAS,aAAa,CAAC,KAAc;IACnC,OAAO,CAAC,KAAK,IAAI,KAAK,KAAK,0BAAW,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 +1 @@
1
- {"version":3,"file":"gas-fees.d.cts","sourceRoot":"","sources":["../../src/utils/gas-fees.ts"],"names":[],"mappings":"AAQA,OAAO,KAAK,EAAE,WAAW,EAAE,qCAAqC;AAChE,OAAO,KAAK,EAAE,QAAQ,EAAE,qCAAqC;AAC7D,OAAO,KAAK,EAAE,iBAAiB,EAAE,yCAAyC;AAO1E,OAAO,KAAK,EAAiB,qBAAqB,EAAE,qBAAiB;AACrE,OAAO,KAAK,EAAE,uBAAuB,EAAE,uCAAmC;AAI1E,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
+ {"version":3,"file":"gas-fees.d.cts","sourceRoot":"","sources":["../../src/utils/gas-fees.ts"],"names":[],"mappings":"AAQA,OAAO,KAAK,EAAE,WAAW,EAAE,qCAAqC;AAChE,OAAO,KAAK,EAAE,QAAQ,EAAE,qCAAqC;AAC7D,OAAO,KAAK,EAAE,iBAAiB,EAAE,yCAAyC;AAO1E,OAAO,KAAK,EAAiB,qBAAqB,EAAE,qBAAoB;AACxE,OAAO,KAAK,EAAE,uBAAuB,EAAE,uCAAsC;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 +1 @@
1
- {"version":3,"file":"gas-fees.d.mts","sourceRoot":"","sources":["../../src/utils/gas-fees.ts"],"names":[],"mappings":"AAQA,OAAO,KAAK,EAAE,WAAW,EAAE,qCAAqC;AAChE,OAAO,KAAK,EAAE,QAAQ,EAAE,qCAAqC;AAC7D,OAAO,KAAK,EAAE,iBAAiB,EAAE,yCAAyC;AAO1E,OAAO,KAAK,EAAiB,qBAAqB,EAAE,qBAAiB;AACrE,OAAO,KAAK,EAAE,uBAAuB,EAAE,uCAAmC;AAI1E,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
+ {"version":3,"file":"gas-fees.d.mts","sourceRoot":"","sources":["../../src/utils/gas-fees.ts"],"names":[],"mappings":"AAQA,OAAO,KAAK,EAAE,WAAW,EAAE,qCAAqC;AAChE,OAAO,KAAK,EAAE,QAAQ,EAAE,qCAAqC;AAC7D,OAAO,KAAK,EAAE,iBAAiB,EAAE,yCAAyC;AAO1E,OAAO,KAAK,EAAiB,qBAAqB,EAAE,qBAAoB;AACxE,OAAO,KAAK,EAAE,uBAAuB,EAAE,uCAAsC;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 +1 @@
1
- {"version":3,"file":"gas-fees.mjs","sourceRoot":"","sources":["../../src/utils/gas-fees.ts"],"names":[],"mappings":";;;;;;AAAA,OAAO,EACL,cAAc,EACd,eAAe,EACf,KAAK,EACL,KAAK,EACN,mCAAmC;AACpC,OAAO,SAAQ,4BAA4B;;AAC3C,OAAO,EAAE,kBAAkB,EAAE,qCAAqC;AAIlE,OAAO,EAAE,YAAY,EAAE,yCAAyC;AAEhE,OAAO,EAAE,KAAK,EAAE,wBAAwB;AAExC,OAAO,EAAE,WAAW,EAAE,yBAAqB;AAC3C,OAAO,EAAE,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AED;;;;;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';\nimport { createModuleLogger, projectLogger } from '../logger';\nimport type { UserOperation, UserOperationMetadata } from '../types';\nimport type { AddUserOperationRequest } from '../UserOperationController';\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
+ {"version":3,"file":"gas-fees.mjs","sourceRoot":"","sources":["../../src/utils/gas-fees.ts"],"names":[],"mappings":";;;;;;AAAA,OAAO,EACL,cAAc,EACd,eAAe,EACf,KAAK,EACL,KAAK,EACN,mCAAmC;AACpC,OAAO,SAAQ,4BAA4B;;AAC3C,OAAO,EAAE,kBAAkB,EAAE,qCAAqC;AAIlE,OAAO,EAAE,YAAY,EAAE,yCAAyC;AAEhE,OAAO,EAAE,KAAK,EAAE,wBAAwB;AAExC,OAAO,EAAE,WAAW,EAAE,yBAAwB;AAC9C,OAAO,EAAE,kBAAkB,EAAE,aAAa,EAAE,sBAAqB;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,KAAK,IAAI,EAAE;QACpC,IAAI,CAAC,gBAAgB,EAAE,CAAC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e,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"]}
@@ -7,10 +7,10 @@ exports.updateGas = void 0;
7
7
  const controller_utils_1 = require("@metamask/controller-utils");
8
8
  const utils_1 = require("@metamask/utils");
9
9
  const bn_js_1 = __importDefault(require("bn.js"));
10
- const constants_1 = require("../constants.cjs");
11
- const Bundler_1 = require("../helpers/Bundler.cjs");
12
- const logger_1 = require("../logger.cjs");
13
- const log = (0, logger_1.createModuleLogger)(logger_1.projectLogger, 'gas');
10
+ const constants_js_1 = require("../constants.cjs");
11
+ const Bundler_js_1 = require("../helpers/Bundler.cjs");
12
+ const logger_js_1 = require("../logger.cjs");
13
+ const log = (0, logger_js_1.createModuleLogger)(logger_js_1.projectLogger, 'gas');
14
14
  /**
15
15
  * A multiplier to apply to all gas estimate values returned from the bundler.
16
16
  */
@@ -38,13 +38,13 @@ async function updateGas(metadata, prepareResponse, entrypoint) {
38
38
  }
39
39
  const payload = {
40
40
  ...userOperation,
41
- maxFeePerGas: constants_1.VALUE_ZERO,
42
- maxPriorityFeePerGas: constants_1.VALUE_ZERO,
43
- callGasLimit: constants_1.VALUE_ZERO,
44
- preVerificationGas: constants_1.VALUE_ZERO,
41
+ maxFeePerGas: constants_js_1.VALUE_ZERO,
42
+ maxPriorityFeePerGas: constants_js_1.VALUE_ZERO,
43
+ callGasLimit: constants_js_1.VALUE_ZERO,
44
+ preVerificationGas: constants_js_1.VALUE_ZERO,
45
45
  verificationGasLimit: '0xF4240',
46
46
  };
47
- const bundler = new Bundler_1.Bundler(metadata.bundlerUrl);
47
+ const bundler = new Bundler_js_1.Bundler(metadata.bundlerUrl);
48
48
  const estimate = await bundler.estimateUserOperationGas(payload, entrypoint);
49
49
  userOperation.callGasLimit = normalizeGasEstimate(estimate.callGasLimit);
50
50
  userOperation.preVerificationGas = normalizeGasEstimate(estimate.preVerificationGas);
@@ -1 +1 @@
1
- {"version":3,"file":"gas.cjs","sourceRoot":"","sources":["../../src/utils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AAC,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;AAnDD,8BAmDC;AAED;;;;;GAKG;AACH,SAAS,oBAAoB,CAAC,QAAyB;IACrD,MAAM,KAAK,GACT,OAAO,QAAQ,KAAK,QAAQ,CAAC,CAAC,CAAC,IAAA,0BAAO,EAAC,QAAQ,CAAC,CAAC,CAAC,CAAC,IAAI,eAAE,CAAC,QAAQ,CAAC,CAAC;IAEtE,MAAM,aAAa,GAAG,KAAK,CAAC,IAAI,CAAC,uBAAuB,CAAC,CAAC;IAE1D,OAAO,IAAA,aAAK,EAAC,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';\nimport { Bundler } from '../helpers/Bundler';\nimport { createModuleLogger, projectLogger } from '../logger';\nimport type {\n PrepareUserOperationResponse,\n UserOperationMetadata,\n} from '../types';\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
+ {"version":3,"file":"gas.cjs","sourceRoot":"","sources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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;AAnDD,8BAmDC;AAED;;;;;GAKG;AACH,SAAS,oBAAoB,CAAC,QAAyB;IACrD,MAAM,KAAK,GACT,OAAO,QAAQ,KAAK,QAAQ,CAAC,CAAC,CAAC,IAAA,0BAAO,EAAC,QAAQ,CAAC,CAAC,CAAC,CAAC,IAAI,eAAE,CAAC,QAAQ,CAAC,CAAC;IAEtE,MAAM,aAAa,GAAG,KAAK,CAAC,IAAI,CAAC,uBAAuB,CAAC,CAAC;IAE1D,OAAO,IAAA,aAAK,EAAC,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 +1 @@
1
- {"version":3,"file":"gas.d.cts","sourceRoot":"","sources":["../../src/utils/gas.ts"],"names":[],"mappings":"AAOA,OAAO,KAAK,EACV,4BAA4B,EAC5B,qBAAqB,EACtB,qBAAiB;AASlB;;;;;;GAMG;AACH,wBAAsB,SAAS,CAC7B,QAAQ,EAAE,qBAAqB,EAC/B,eAAe,EAAE,4BAA4B,EAC7C,UAAU,EAAE,MAAM,iBAgDnB"}
1
+ {"version":3,"file":"gas.d.cts","sourceRoot":"","sources":["../../src/utils/gas.ts"],"names":[],"mappings":"AAOA,OAAO,KAAK,EACV,4BAA4B,EAC5B,qBAAqB,EACtB,qBAAoB;AASrB;;;;;;GAMG;AACH,wBAAsB,SAAS,CAC7B,QAAQ,EAAE,qBAAqB,EAC/B,eAAe,EAAE,4BAA4B,EAC7C,UAAU,EAAE,MAAM,iBAgDnB"}
@@ -1 +1 @@
1
- {"version":3,"file":"gas.d.mts","sourceRoot":"","sources":["../../src/utils/gas.ts"],"names":[],"mappings":"AAOA,OAAO,KAAK,EACV,4BAA4B,EAC5B,qBAAqB,EACtB,qBAAiB;AASlB;;;;;;GAMG;AACH,wBAAsB,SAAS,CAC7B,QAAQ,EAAE,qBAAqB,EAC/B,eAAe,EAAE,4BAA4B,EAC7C,UAAU,EAAE,MAAM,iBAgDnB"}
1
+ {"version":3,"file":"gas.d.mts","sourceRoot":"","sources":["../../src/utils/gas.ts"],"names":[],"mappings":"AAOA,OAAO,KAAK,EACV,4BAA4B,EAC5B,qBAAqB,EACtB,qBAAoB;AASrB;;;;;;GAMG;AACH,wBAAsB,SAAS,CAC7B,QAAQ,EAAE,qBAAqB,EAC/B,eAAe,EAAE,4BAA4B,EAC7C,UAAU,EAAE,MAAM,iBAgDnB"}
@@ -1 +1 @@
1
- {"version":3,"file":"gas.mjs","sourceRoot":"","sources":["../../src/utils/gas.ts"],"names":[],"mappings":";;;;;;AAAA,OAAO,EAAE,OAAO,EAAE,mCAAmC;AACrD,OAAO,EAAE,KAAK,EAAE,wBAAwB;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AC,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';\nimport { Bundler } from '../helpers/Bundler';\nimport { createModuleLogger, projectLogger } from '../logger';\nimport type {\n PrepareUserOperationResponse,\n UserOperationMetadata,\n} from '../types';\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
+ {"version":3,"file":"gas.mjs","source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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"]}
@@ -7,8 +7,8 @@ exports.getTransactionMetadata = void 0;
7
7
  const transaction_controller_1 = require("@metamask/transaction-controller");
8
8
  const utils_1 = require("@metamask/utils");
9
9
  const bn_js_1 = __importDefault(require("bn.js"));
10
- const constants_1 = require("../constants.cjs");
11
- const types_1 = require("../types.cjs");
10
+ const constants_js_1 = require("../constants.cjs");
11
+ const types_js_1 = require("../types.cjs");
12
12
  /**
13
13
  * Converts a user operation metadata object into a transaction metadata object.
14
14
  *
@@ -36,20 +36,20 @@ function getTransactionMetadata(metadata) {
36
36
  }
37
37
  : undefined);
38
38
  const status = {
39
- [types_1.UserOperationStatus.Unapproved]: transaction_controller_1.TransactionStatus.unapproved,
40
- [types_1.UserOperationStatus.Approved]: transaction_controller_1.TransactionStatus.approved,
41
- [types_1.UserOperationStatus.Signed]: transaction_controller_1.TransactionStatus.signed,
42
- [types_1.UserOperationStatus.Submitted]: transaction_controller_1.TransactionStatus.submitted,
43
- [types_1.UserOperationStatus.Confirmed]: transaction_controller_1.TransactionStatus.confirmed,
44
- [types_1.UserOperationStatus.Failed]: transaction_controller_1.TransactionStatus.failed,
39
+ [types_js_1.UserOperationStatus.Unapproved]: transaction_controller_1.TransactionStatus.unapproved,
40
+ [types_js_1.UserOperationStatus.Approved]: transaction_controller_1.TransactionStatus.approved,
41
+ [types_js_1.UserOperationStatus.Signed]: transaction_controller_1.TransactionStatus.signed,
42
+ [types_js_1.UserOperationStatus.Submitted]: transaction_controller_1.TransactionStatus.submitted,
43
+ [types_js_1.UserOperationStatus.Confirmed]: transaction_controller_1.TransactionStatus.confirmed,
44
+ [types_js_1.UserOperationStatus.Failed]: transaction_controller_1.TransactionStatus.failed,
45
45
  }[metadata.status];
46
46
  const gas = addHex(userOperation.preVerificationGas, userOperation.verificationGasLimit, userOperation.callGasLimit);
47
- const hasPaymaster = userOperation.paymasterAndData !== constants_1.EMPTY_BYTES;
48
- const maxFeePerGas = hasPaymaster ? constants_1.VALUE_ZERO : userOperation.maxFeePerGas;
47
+ const hasPaymaster = userOperation.paymasterAndData !== constants_js_1.EMPTY_BYTES;
48
+ const maxFeePerGas = hasPaymaster ? constants_js_1.VALUE_ZERO : userOperation.maxFeePerGas;
49
49
  const maxPriorityFeePerGas = hasPaymaster
50
- ? constants_1.VALUE_ZERO
50
+ ? constants_js_1.VALUE_ZERO
51
51
  : userOperation.maxPriorityFeePerGas;
52
- const nonce = userOperation.nonce === constants_1.EMPTY_BYTES ? undefined : userOperation.nonce;
52
+ const nonce = userOperation.nonce === constants_js_1.EMPTY_BYTES ? undefined : userOperation.nonce;
53
53
  const txParams = {
54
54
  ...transactionParams,
55
55
  from: userOperation.sender,
@@ -1 +1 @@
1
- {"version":3,"file":"transaction.cjs","sourceRoot":"","sources":["../../src/utils/transaction.ts"],"names":[],"mappings":";;;;;;AAKA,6EAG0C;AAE1C,2CAAkD;AAClD,kDAAuB;AAEvB,gDAAuD;AACvD,wCAA+C;AAG/C;;;;;GAKG;AACH,SAAgB,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,IAAA,aAAK,EACH,IAAI,eAAE,CAAC,IAAA,gBAAQ,EAAC,aAAa,CAAC,EAAE,EAAE,CAAC;aAChC,GAAG,CAAC,IAAI,eAAE,CAAC,IAAA,gB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;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;AA5HD,wDA4HC;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,IAAA,gBAAQ,EAAC,KAAK,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC;IAC1C,CAAC;IAED,OAAO,IAAA,aAAK,EAAC,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';\nimport { UserOperationStatus } from '../types';\nimport type { UserOperationMetadata } from '../types';\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
+ {"version":3,"file":"transaction.cjs","sourceRoot":"","sources":["../../src/utils/transaction.ts"],"names":[],"mappings":";;;;;;AAKA,6EAG0C;AAE1C,2CAAkD;AAClD,kDAAuB;AAEvB,mDAA0D;AAC1D,2CAAkD;AAGlD;;;;;GAKG;AACH,SAAgB,sB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AAO,IAAA,aAAK,EAAC,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 +1 @@
1
- {"version":3,"file":"transaction.d.cts","sourceRoot":"","sources":["../../src/utils/transaction.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAEV,eAAe,EAEhB,yCAAyC;AAW1C,OAAO,KAAK,EAAE,qBAAqB,EAAE,qBAAiB;AAEtD;;;;;GAKG;AACH,wBAAgB,sBAAsB,CACpC,QAAQ,EAAE,qBAAqB,GAC9B,eAAe,GAAG,SAAS,CA0H7B"}
1
+ {"version":3,"file":"transaction.d.cts","sourceRoot":"","sources":["../../src/utils/transaction.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAEV,eAAe,EAEhB,yCAAyC;AAW1C,OAAO,KAAK,EAAE,qBAAqB,EAAE,qBAAoB;AAEzD;;;;;GAKG;AACH,wBAAgB,sBAAsB,CACpC,QAAQ,EAAE,qBAAqB,GAC9B,eAAe,GAAG,SAAS,CA0H7B"}
@@ -1 +1 @@
1
- {"version":3,"file":"transaction.d.mts","sourceRoot":"","sources":["../../src/utils/transaction.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAEV,eAAe,EAEhB,yCAAyC;AAW1C,OAAO,KAAK,EAAE,qBAAqB,EAAE,qBAAiB;AAEtD;;;;;GAKG;AACH,wBAAgB,sBAAsB,CACpC,QAAQ,EAAE,qBAAqB,GAC9B,eAAe,GAAG,SAAS,CA0H7B"}
1
+ {"version":3,"file":"transaction.d.mts","sourceRoot":"","sources":["../../src/utils/transaction.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAEV,eAAe,EAEhB,yCAAyC;AAW1C,OAAO,KAAK,EAAE,qBAAqB,EAAE,qBAAoB;AAEzD;;;;;GAKG;AACH,wBAAgB,sBAAsB,CACpC,QAAQ,EAAE,qBAAqB,GAC9B,eAAe,GAAG,SAAS,CA0H7B"}
@@ -1 +1 @@
1
- {"version":3,"file":"transaction.mjs","sourceRoot":"","sources":["../../src/utils/transaction.ts"],"names":[],"mappings":";;;;;;AAKA,OAAO,EACL,iBAAiB,EACjB,YAAY,EACb,yCAAyC;AAE1C,OAAO,EAAE,KAAK,EAAE,QAAQ,EAAE,wBAAwB;AAClD,OAAO,GAAE,cAAc;;AAEvB,OAAO,EAAE,WAAW,EAAE,UAAU,EAAE,yBAAqB;AACvD,OAAO,EAAE,mBAAmB,EAAE,qBAAiB;AAG/C;;;;;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,GAAG,CAAC,IAAI,EAAE,CAAC,QAAQ,CAAC,aAAa,CAAC,EAAE,EAAE,CAAC,CAAC;aACxC,QAAQ,CAAC,EAAE,CAAC,CAChB;QACH,CAAC,CAAC,SAAS,CAAC;IAEhB,MAAM,KAAK,GAAG,CACZ,QAAQ;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E;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';\nimport { UserOperationStatus } from '../types';\nimport type { UserOperationMetadata } from '../types';\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
+ {"version":3,"file":"transaction.mjs","sourceRoot":"","sources":["../../src/utils/transaction.ts"],"names":[],"mappings":";;;;;;AAKA,OAAO,EACL,iBAAiB,EACjB,YAAY,EACb,yCAAyC;AAE1C,OAAO,EAAE,KAAK,EAAE,QAAQ,EAAE,wBAAwB;AAClD,OAAO,GAAE,cAAc;;AAEvB,OAAO,EAAE,WAAW,EAAE,UAAU,EAAE,yBAAwB;AAC1D,OAAO,EAAE,mBAAmB,EAAE,qBAAoB;AAGlD;;;;;GAKG;AACH,MAAM,UAAU,sBAAsB,CACpC,QAA+B;IAE/B,MAAM,EACJ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":["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"]}
@@ -4,7 +4,7 @@ exports.validateSignUserOperationResponse = exports.validateUpdateUserOperationR
4
4
  const superstruct_1 = require("@metamask/superstruct");
5
5
  const transaction_controller_1 = require("@metamask/transaction-controller");
6
6
  const utils_1 = require("@metamask/utils");
7
- const constants_1 = require("../constants.cjs");
7
+ const constants_js_1 = require("../constants.cjs");
8
8
  /**
9
9
  * Validate a request to add a user operation.
10
10
  *
@@ -81,7 +81,7 @@ function validatePrepareUserOperationResponse(response) {
81
81
  nonce: Hex,
82
82
  sender: Hex,
83
83
  }), 'ValidPrepareUserOperationResponse', ({ gas, dummySignature }) => {
84
- if (!gas && (!dummySignature || dummySignature === constants_1.EMPTY_BYTES)) {
84
+ if (!gas && (!dummySignature || dummySignature === constants_js_1.EMPTY_BYTES)) {
85
85
  return 'Must specify dummySignature if not specifying gas';
86
86
  }
87
87
  /* istanbul ignore next */
@@ -157,6 +157,6 @@ function defineHex() {
157
157
  * @returns The HexOrEmptyBytes superstruct type.
158
158
  */
159
159
  function defineHexOrEmptyBytes() {
160
- return (0, superstruct_1.define)('Hexadecimal String or 0x', (value) => (0, utils_1.isStrictHexString)(value) || value === constants_1.EMPTY_BYTES);
160
+ return (0, superstruct_1.define)('Hexadecimal String or 0x', (value) => (0, utils_1.isStrictHexString)(value) || value === constants_js_1.EMPTY_BYTES);
161
161
  }
162
162
  //# sourceMappingURL=validation.cjs.map