@metamask-previews/user-operation-controller 41.2.9-preview-3e34650c2 → 41.2.9-preview-4f4c98e
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +4 -0
- package/dist/{BlockTrackerPollingController.d.mts → BlockTrackerPollingController.d.ts} +11 -11
- package/dist/BlockTrackerPollingController.d.ts.map +1 -0
- package/dist/{BlockTrackerPollingController.mjs → BlockTrackerPollingController.js} +17 -16
- package/dist/BlockTrackerPollingController.js.map +1 -0
- package/dist/{UserOperationController-method-action-types.d.cts → UserOperationController-method-action-types.d.ts} +2 -2
- package/dist/UserOperationController-method-action-types.d.ts.map +1 -0
- package/dist/{UserOperationController-method-action-types.mjs → UserOperationController-method-action-types.js} +1 -1
- package/dist/UserOperationController-method-action-types.js.map +1 -0
- package/dist/{UserOperationController.d.cts → UserOperationController.d.ts} +13 -15
- package/dist/UserOperationController.d.ts.map +1 -0
- package/dist/{UserOperationController.mjs → UserOperationController.js} +19 -20
- package/dist/UserOperationController.js.map +1 -0
- package/dist/{constants.d.cts → constants.d.ts} +1 -1
- package/dist/constants.d.ts.map +1 -0
- package/dist/{constants.mjs → constants.js} +1 -1
- package/dist/constants.js.map +1 -0
- package/dist/helpers/{Bundler.d.cts → Bundler.d.ts} +2 -2
- package/dist/helpers/Bundler.d.ts.map +1 -0
- package/dist/helpers/{Bundler.mjs → Bundler.js} +2 -2
- package/dist/helpers/Bundler.js.map +1 -0
- package/dist/helpers/{PendingUserOperationTracker.d.cts → PendingUserOperationTracker.d.ts} +10 -12
- package/dist/helpers/PendingUserOperationTracker.d.ts.map +1 -0
- package/dist/helpers/{PendingUserOperationTracker.mjs → PendingUserOperationTracker.js} +9 -16
- package/dist/helpers/PendingUserOperationTracker.js.map +1 -0
- package/dist/helpers/{SnapSmartContractAccount.d.cts → SnapSmartContractAccount.d.ts} +3 -3
- package/dist/helpers/SnapSmartContractAccount.d.ts.map +1 -0
- package/dist/helpers/{SnapSmartContractAccount.mjs → SnapSmartContractAccount.js} +3 -3
- package/dist/helpers/SnapSmartContractAccount.js.map +1 -0
- package/dist/index.d.ts +4 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +3 -0
- package/dist/index.js.map +1 -0
- package/dist/logger.d.ts +4 -0
- package/dist/logger.d.ts.map +1 -0
- package/dist/{logger.mjs → logger.js} +2 -2
- package/dist/logger.js.map +1 -0
- package/dist/{types.d.mts → types.d.ts} +3 -3
- package/dist/types.d.ts.map +1 -0
- package/dist/{types.mjs → types.js} +1 -1
- package/dist/types.js.map +1 -0
- package/dist/utils/{chain-id.d.cts → chain-id.d.ts} +1 -1
- package/dist/utils/chain-id.d.ts.map +1 -0
- package/dist/utils/{chain-id.mjs → chain-id.js} +1 -1
- package/dist/utils/chain-id.js.map +1 -0
- package/dist/utils/{gas-fees.d.cts → gas-fees.d.ts} +6 -6
- package/dist/utils/gas-fees.d.ts.map +1 -0
- package/dist/utils/{gas-fees.mjs → gas-fees.js} +8 -15
- package/dist/utils/gas-fees.js.map +1 -0
- package/dist/utils/{gas.d.mts → gas.d.ts} +2 -2
- package/dist/utils/gas.d.ts.map +1 -0
- package/dist/utils/{gas.mjs → gas.js} +7 -14
- package/dist/utils/gas.js.map +1 -0
- package/dist/utils/{transaction.d.cts → transaction.d.ts} +3 -3
- package/dist/utils/transaction.d.ts.map +1 -0
- package/dist/utils/{transaction.mjs → transaction.js} +6 -13
- package/dist/utils/transaction.js.map +1 -0
- package/dist/utils/{validation.d.cts → validation.d.ts} +3 -3
- package/dist/utils/validation.d.ts.map +1 -0
- package/dist/utils/{validation.mjs → validation.js} +5 -5
- package/dist/utils/validation.js.map +1 -0
- package/package.json +13 -17
- package/dist/BlockTrackerPollingController.cjs +0 -68
- package/dist/BlockTrackerPollingController.cjs.map +0 -1
- package/dist/BlockTrackerPollingController.d.cts +0 -41
- package/dist/BlockTrackerPollingController.d.cts.map +0 -1
- package/dist/BlockTrackerPollingController.d.mts.map +0 -1
- package/dist/BlockTrackerPollingController.mjs.map +0 -1
- package/dist/UserOperationController-method-action-types.cjs +0 -7
- package/dist/UserOperationController-method-action-types.cjs.map +0 -1
- package/dist/UserOperationController-method-action-types.d.cts.map +0 -1
- package/dist/UserOperationController-method-action-types.d.mts +0 -57
- package/dist/UserOperationController-method-action-types.d.mts.map +0 -1
- package/dist/UserOperationController-method-action-types.mjs.map +0 -1
- package/dist/UserOperationController.cjs +0 -495
- package/dist/UserOperationController.cjs.map +0 -1
- package/dist/UserOperationController.d.cts.map +0 -1
- package/dist/UserOperationController.d.mts +0 -136
- package/dist/UserOperationController.d.mts.map +0 -1
- package/dist/UserOperationController.mjs.map +0 -1
- package/dist/constants.cjs +0 -7
- package/dist/constants.cjs.map +0 -1
- package/dist/constants.d.cts.map +0 -1
- package/dist/constants.d.mts +0 -4
- package/dist/constants.d.mts.map +0 -1
- package/dist/constants.mjs.map +0 -1
- package/dist/helpers/Bundler.cjs +0 -91
- package/dist/helpers/Bundler.cjs.map +0 -1
- package/dist/helpers/Bundler.d.cts.map +0 -1
- package/dist/helpers/Bundler.d.mts +0 -46
- package/dist/helpers/Bundler.d.mts.map +0 -1
- package/dist/helpers/Bundler.mjs.map +0 -1
- package/dist/helpers/PendingUserOperationTracker.cjs +0 -127
- package/dist/helpers/PendingUserOperationTracker.cjs.map +0 -1
- package/dist/helpers/PendingUserOperationTracker.d.cts.map +0 -1
- package/dist/helpers/PendingUserOperationTracker.d.mts +0 -51
- package/dist/helpers/PendingUserOperationTracker.d.mts.map +0 -1
- package/dist/helpers/PendingUserOperationTracker.mjs.map +0 -1
- package/dist/helpers/SnapSmartContractAccount.cjs +0 -64
- package/dist/helpers/SnapSmartContractAccount.cjs.map +0 -1
- package/dist/helpers/SnapSmartContractAccount.d.cts.map +0 -1
- package/dist/helpers/SnapSmartContractAccount.d.mts +0 -10
- package/dist/helpers/SnapSmartContractAccount.d.mts.map +0 -1
- package/dist/helpers/SnapSmartContractAccount.mjs.map +0 -1
- package/dist/index.cjs +0 -19
- package/dist/index.cjs.map +0 -1
- package/dist/index.d.cts +0 -4
- package/dist/index.d.cts.map +0 -1
- package/dist/index.d.mts +0 -4
- package/dist/index.d.mts.map +0 -1
- package/dist/index.mjs +0 -3
- package/dist/index.mjs.map +0 -1
- package/dist/logger.cjs +0 -8
- package/dist/logger.cjs.map +0 -1
- package/dist/logger.d.cts +0 -5
- package/dist/logger.d.cts.map +0 -1
- package/dist/logger.d.mts +0 -5
- package/dist/logger.d.mts.map +0 -1
- package/dist/logger.mjs.map +0 -1
- package/dist/types.cjs +0 -16
- package/dist/types.cjs.map +0 -1
- package/dist/types.d.cts +0 -294
- package/dist/types.d.cts.map +0 -1
- package/dist/types.d.mts.map +0 -1
- package/dist/types.mjs.map +0 -1
- package/dist/utils/chain-id.cjs +0 -17
- package/dist/utils/chain-id.cjs.map +0 -1
- package/dist/utils/chain-id.d.cts.map +0 -1
- package/dist/utils/chain-id.d.mts +0 -8
- package/dist/utils/chain-id.d.mts.map +0 -1
- package/dist/utils/chain-id.mjs.map +0 -1
- package/dist/utils/gas-fees.cjs +0 -194
- package/dist/utils/gas-fees.cjs.map +0 -1
- package/dist/utils/gas-fees.d.cts.map +0 -1
- package/dist/utils/gas-fees.d.mts +0 -24
- package/dist/utils/gas-fees.d.mts.map +0 -1
- package/dist/utils/gas-fees.mjs.map +0 -1
- package/dist/utils/gas.cjs +0 -72
- package/dist/utils/gas.cjs.map +0 -1
- package/dist/utils/gas.d.cts +0 -10
- package/dist/utils/gas.d.cts.map +0 -1
- package/dist/utils/gas.d.mts.map +0 -1
- package/dist/utils/gas.mjs.map +0 -1
- package/dist/utils/transaction.cjs +0 -117
- package/dist/utils/transaction.cjs.map +0 -1
- package/dist/utils/transaction.d.cts.map +0 -1
- package/dist/utils/transaction.d.mts +0 -10
- package/dist/utils/transaction.d.mts.map +0 -1
- package/dist/utils/transaction.mjs.map +0 -1
- package/dist/utils/validation.cjs +0 -162
- package/dist/utils/validation.cjs.map +0 -1
- package/dist/utils/validation.d.cts.map +0 -1
- package/dist/utils/validation.d.mts +0 -33
- package/dist/utils/validation.d.mts.map +0 -1
- package/dist/utils/validation.mjs.map +0 -1
package/CHANGELOG.md
CHANGED
|
@@ -7,6 +7,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|
|
7
7
|
|
|
8
8
|
## [Unreleased]
|
|
9
9
|
|
|
10
|
+
### Changed
|
|
11
|
+
|
|
12
|
+
- **BREAKING:** Bump minimum Node.js version to 22 ([#9168](https://github.com/MetaMask/core/pull/9168))
|
|
13
|
+
|
|
10
14
|
## [41.2.9]
|
|
11
15
|
|
|
12
16
|
### Changed
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import { BaseController } from
|
|
2
|
-
import type { NetworkClientId, NetworkClient } from
|
|
3
|
-
import { PollingTokenSetId } from
|
|
4
|
-
import type { Json } from
|
|
1
|
+
import { BaseController } from '@metamask/base-controller';
|
|
2
|
+
import type { NetworkClientId, NetworkClient } from '@metamask/network-controller';
|
|
3
|
+
import { PollingTokenSetId } from '@metamask/polling-controller';
|
|
4
|
+
import type { Json } from '@metamask/utils';
|
|
5
5
|
/**
|
|
6
6
|
* The minimum input required to start polling for a {@link BlockTrackerPollingController}.
|
|
7
7
|
* Implementing classes may provide additional properties.
|
|
@@ -12,12 +12,12 @@ export type BlockTrackerPollingInput = {
|
|
|
12
12
|
declare class Empty {
|
|
13
13
|
}
|
|
14
14
|
export declare const BlockTrackerPollingControllerOnly: <PollingInput extends BlockTrackerPollingInput>() => (abstract new (...args: any[]) => {
|
|
15
|
-
|
|
15
|
+
_activeListeners: Record<string, (options: Json) => Promise<void>>;
|
|
16
16
|
_getNetworkClientById(networkClientId: NetworkClientId): NetworkClient | undefined;
|
|
17
17
|
_startPolling(input: PollingInput): void;
|
|
18
18
|
_stopPollingByPollingTokenSetId(key: PollingTokenSetId): void;
|
|
19
|
-
readonly
|
|
20
|
-
readonly
|
|
19
|
+
readonly _pollingTokenSets: Map<PollingTokenSetId, Set<string>>;
|
|
20
|
+
readonly _callbacks: Map<string, Set<(input: PollingInput) => void>>;
|
|
21
21
|
_executePoll(input: PollingInput): Promise<void>;
|
|
22
22
|
startPolling(input: PollingInput): string;
|
|
23
23
|
stopAllPolling(): void;
|
|
@@ -25,12 +25,12 @@ export declare const BlockTrackerPollingControllerOnly: <PollingInput extends Bl
|
|
|
25
25
|
onPollingComplete(input: PollingInput, callback: (input: PollingInput) => void): void;
|
|
26
26
|
}) & typeof Empty;
|
|
27
27
|
export declare const BlockTrackerPollingController: <PollingInput extends BlockTrackerPollingInput>() => (abstract new (...args: any[]) => {
|
|
28
|
-
|
|
28
|
+
_activeListeners: Record<string, (options: Json) => Promise<void>>;
|
|
29
29
|
_getNetworkClientById(networkClientId: NetworkClientId): NetworkClient | undefined;
|
|
30
30
|
_startPolling(input: PollingInput): void;
|
|
31
31
|
_stopPollingByPollingTokenSetId(key: PollingTokenSetId): void;
|
|
32
|
-
readonly
|
|
33
|
-
readonly
|
|
32
|
+
readonly _pollingTokenSets: Map<PollingTokenSetId, Set<string>>;
|
|
33
|
+
readonly _callbacks: Map<string, Set<(input: PollingInput) => void>>;
|
|
34
34
|
_executePoll(input: PollingInput): Promise<void>;
|
|
35
35
|
startPolling(input: PollingInput): string;
|
|
36
36
|
stopAllPolling(): void;
|
|
@@ -38,4 +38,4 @@ export declare const BlockTrackerPollingController: <PollingInput extends BlockT
|
|
|
38
38
|
onPollingComplete(input: PollingInput, callback: (input: PollingInput) => void): void;
|
|
39
39
|
}) & typeof BaseController;
|
|
40
40
|
export {};
|
|
41
|
-
//# sourceMappingURL=BlockTrackerPollingController.d.
|
|
41
|
+
//# sourceMappingURL=BlockTrackerPollingController.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"BlockTrackerPollingController.d.ts","sourceRoot":"","sources":["../src/BlockTrackerPollingController.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,MAAM,2BAA2B,CAAC;AAC3D,OAAO,KAAK,EACV,eAAe,EACf,aAAa,EACd,MAAM,8BAA8B,CAAC;AACtC,OAAO,EAIL,iBAAiB,EAClB,MAAM,8BAA8B,CAAC;AACtC,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,iBAAiB,CAAC;AAE5C;;;GAGG;AACH,MAAM,MAAM,wBAAwB,GAAG;IACrC,eAAe,EAAE,eAAe,CAAC;CAClC,CAAC;AA4EF,cAAM,KAAK;CAAG;AAEd,eAAO,MAAM,iCAAiC,GAC5C,YAAY,SAAS,wBAAwB;+CAnDA,IAAI,KAAK,OAAO,CAAC,IAAI,CAAC;2CAG9C,eAAe,GAC/B,aAAa,GAAG,SAAS;wCAEQ,IAAI;yCAqBH,iBAAiB,GAAG,IAAI;;;;;;;;iBA4BW,CAAC;AAE7E,eAAO,MAAM,6BAA6B,GACxC,YAAY,SAAS,wBAAwB;+CA1DA,IAAI,KAAK,OAAO,CAAC,IAAI,CAAC;2CAG9C,eAAe,GAC/B,aAAa,GAAG,SAAS;wCAEQ,IAAI;yCAqBH,iBAAiB,GAAG,IAAI;;;;;;;;0BAsC9D,CAAC"}
|
|
@@ -1,10 +1,5 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
|
|
4
|
-
return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
|
|
5
|
-
};
|
|
6
|
-
import { BaseController } from "@metamask/base-controller";
|
|
7
|
-
import { AbstractPollingControllerBaseMixin, getKey } from "@metamask/polling-controller";
|
|
1
|
+
import { BaseController } from '@metamask/base-controller';
|
|
2
|
+
import { AbstractPollingControllerBaseMixin, getKey, } from '@metamask/polling-controller';
|
|
8
3
|
/**
|
|
9
4
|
* BlockTrackerPollingControllerMixin
|
|
10
5
|
* A polling controller that polls using a block tracker.
|
|
@@ -16,15 +11,22 @@ import { AbstractPollingControllerBaseMixin, getKey } from "@metamask/polling-co
|
|
|
16
11
|
// the class defined inside the function scope, so this can't be easily typed.
|
|
17
12
|
// eslint-disable-next-line @typescript-eslint/explicit-function-return-type, @typescript-eslint/naming-convention
|
|
18
13
|
function BlockTrackerPollingControllerMixin(Base) {
|
|
19
|
-
var _BlockTrackerPollingController_activeListeners;
|
|
20
14
|
class BlockTrackerPollingController extends AbstractPollingControllerBaseMixin(Base) {
|
|
21
15
|
constructor() {
|
|
22
16
|
super(...arguments);
|
|
23
|
-
|
|
17
|
+
// This field is public (rather than using `#`) so that declaration
|
|
18
|
+
// emission can describe it. Private/protected members on the class
|
|
19
|
+
// returned by an exported mixin function trigger TS4094, and giving the
|
|
20
|
+
// mixin an explicit return type to work around that breaks consumers
|
|
21
|
+
// that supply the base class's own type arguments via
|
|
22
|
+
// `BlockTrackerPollingController()<Name, State, Messenger>`. The
|
|
23
|
+
// leading underscore signals "internal, do not use" without needing
|
|
24
|
+
// true privacy.
|
|
25
|
+
this._activeListeners = {};
|
|
24
26
|
}
|
|
25
27
|
_startPolling(input) {
|
|
26
28
|
const key = getKey(input);
|
|
27
|
-
if (
|
|
29
|
+
if (this._activeListeners[key]) {
|
|
28
30
|
return;
|
|
29
31
|
}
|
|
30
32
|
const networkClient = this._getNetworkClientById(input.networkClientId);
|
|
@@ -33,7 +35,7 @@ function BlockTrackerPollingControllerMixin(Base) {
|
|
|
33
35
|
// TODO: Either fix this lint violation or explain why it's necessary to ignore.
|
|
34
36
|
// eslint-disable-next-line @typescript-eslint/no-misused-promises
|
|
35
37
|
networkClient.blockTracker.addListener('latest', updateOnNewBlock);
|
|
36
|
-
|
|
38
|
+
this._activeListeners[key] = updateOnNewBlock;
|
|
37
39
|
}
|
|
38
40
|
else {
|
|
39
41
|
throw new Error(`Unable to retrieve blockTracker for networkClientId ${input.networkClientId}`);
|
|
@@ -42,22 +44,21 @@ function BlockTrackerPollingControllerMixin(Base) {
|
|
|
42
44
|
_stopPollingByPollingTokenSetId(key) {
|
|
43
45
|
const { networkClientId } = JSON.parse(key);
|
|
44
46
|
const networkClient = this._getNetworkClientById(networkClientId);
|
|
45
|
-
if (networkClient &&
|
|
46
|
-
const listener =
|
|
47
|
+
if (networkClient && this._activeListeners[key]) {
|
|
48
|
+
const listener = this._activeListeners[key];
|
|
47
49
|
if (listener) {
|
|
48
50
|
// TODO: Either fix this lint violation or explain why it's necessary to ignore.
|
|
49
51
|
// eslint-disable-next-line @typescript-eslint/no-misused-promises
|
|
50
52
|
networkClient.blockTracker.removeListener('latest', listener);
|
|
51
|
-
delete
|
|
53
|
+
delete this._activeListeners[key];
|
|
52
54
|
}
|
|
53
55
|
}
|
|
54
56
|
}
|
|
55
57
|
}
|
|
56
|
-
_BlockTrackerPollingController_activeListeners = new WeakMap();
|
|
57
58
|
return BlockTrackerPollingController;
|
|
58
59
|
}
|
|
59
60
|
class Empty {
|
|
60
61
|
}
|
|
61
62
|
export const BlockTrackerPollingControllerOnly = () => BlockTrackerPollingControllerMixin(Empty);
|
|
62
63
|
export const BlockTrackerPollingController = () => BlockTrackerPollingControllerMixin(BaseController);
|
|
63
|
-
//# sourceMappingURL=BlockTrackerPollingController.
|
|
64
|
+
//# sourceMappingURL=BlockTrackerPollingController.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"BlockTrackerPollingController.js","sourceRoot":"","sources":["../src/BlockTrackerPollingController.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,MAAM,2BAA2B,CAAC;AAK3D,OAAO,EACL,kCAAkC,EAClC,MAAM,GAGP,MAAM,8BAA8B,CAAC;AAWtC;;;;;;GAMG;AACH,gFAAgF;AAChF,8EAA8E;AAC9E,kHAAkH;AAClH,SAAS,kCAAkC,CAGzC,IAAW;IACX,MAAe,6BAA8B,SAAQ,kCAAkC,CAGrF,IAAI,CAAC;QAHP;;YAIE,mEAAmE;YACnE,mEAAmE;YACnE,wEAAwE;YACxE,qEAAqE;YACrE,sDAAs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9D,OAAO,IAAI,CAAC,gBAAgB,CAAC,GAAG,CAAC,CAAC;gBACpC,CAAC;YACH,CAAC;QACH,CAAC;KACF;IAED,OAAO,6BAA6B,CAAC;AACvC,CAAC;AAED,MAAM,KAAK;CAAG;AAEd,MAAM,CAAC,MAAM,iCAAiC,GAAG,GAK7C,EAAE,CAAC,kCAAkC,CAA6B,KAAK,CAAC,CAAC;AAE7E,MAAM,CAAC,MAAM,6BAA6B,GAAG,GAKzC,EAAE,CACJ,kCAAkC,CAChC,cAAc,CACf,CAAC","sourcesContent":["import { BaseController } from '@metamask/base-controller';\nimport type {\n NetworkClientId,\n NetworkClient,\n} from '@metamask/network-controller';\nimport {\n AbstractPollingControllerBaseMixin,\n getKey,\n Constructor,\n PollingTokenSetId,\n} from '@metamask/polling-controller';\nimport type { Json } from '@metamask/utils';\n\n/**\n * The minimum input required to start polling for a {@link BlockTrackerPollingController}.\n * Implementing classes may provide additional properties.\n */\nexport type BlockTrackerPollingInput = {\n networkClientId: NetworkClientId;\n};\n\n/**\n * BlockTrackerPollingControllerMixin\n * A polling controller that polls using a block tracker.\n *\n * @param Base - The base class to mix onto.\n * @returns The composed class.\n */\n// This is a function that's used as class, and the return type is inferred from\n// the class defined inside the function scope, so this can't be easily typed.\n// eslint-disable-next-line @typescript-eslint/explicit-function-return-type, @typescript-eslint/naming-convention\nfunction BlockTrackerPollingControllerMixin<\n TBase extends Constructor,\n PollingInput extends BlockTrackerPollingInput,\n>(Base: TBase) {\n abstract class BlockTrackerPollingController extends AbstractPollingControllerBaseMixin<\n TBase,\n PollingInput\n >(Base) {\n // This field is public (rather than using `#`) so that declaration\n // emission can describe it. Private/protected members on the class\n // returned by an exported mixin function trigger TS4094, and giving the\n // mixin an explicit return type to work around that breaks consumers\n // that supply the base class's own type arguments via\n // `BlockTrackerPollingController()<Name, State, Messenger>`. The\n // leading underscore signals \"internal, do not use\" without needing\n // true privacy.\n _activeListeners: Record<string, (options: Json) => Promise<void>> = {};\n\n abstract _getNetworkClientById(\n networkClientId: NetworkClientId,\n ): NetworkClient | undefined;\n\n _startPolling(input: PollingInput): void {\n const key = getKey(input);\n\n if (this._activeListeners[key]) {\n return;\n }\n\n const networkClient = this._getNetworkClientById(input.networkClientId);\n if (networkClient) {\n const updateOnNewBlock = this._executePoll.bind(this, input);\n // TODO: Either fix this lint violation or explain why it's necessary to ignore.\n // eslint-disable-next-line @typescript-eslint/no-misused-promises\n networkClient.blockTracker.addListener('latest', updateOnNewBlock);\n this._activeListeners[key] = updateOnNewBlock;\n } else {\n throw new Error(\n `Unable to retrieve blockTracker for networkClientId ${input.networkClientId}`,\n );\n }\n }\n\n _stopPollingByPollingTokenSetId(key: PollingTokenSetId): void {\n const { networkClientId } = JSON.parse(key);\n const networkClient = this._getNetworkClientById(\n networkClientId as NetworkClientId,\n );\n\n if (networkClient && this._activeListeners[key]) {\n const listener = this._activeListeners[key];\n if (listener) {\n // TODO: Either fix this lint violation or explain why it's necessary to ignore.\n // eslint-disable-next-line @typescript-eslint/no-misused-promises\n networkClient.blockTracker.removeListener('latest', listener);\n delete this._activeListeners[key];\n }\n }\n }\n }\n\n return BlockTrackerPollingController;\n}\n\nclass Empty {}\n\nexport const BlockTrackerPollingControllerOnly = <\n PollingInput extends BlockTrackerPollingInput,\n // The return type is inferred from the class defined inside the function\n // scope, so this can't be easily typed.\n // eslint-disable-next-line @typescript-eslint/explicit-function-return-type\n>() => BlockTrackerPollingControllerMixin<typeof Empty, PollingInput>(Empty);\n\nexport const BlockTrackerPollingController = <\n PollingInput extends BlockTrackerPollingInput,\n // The return type is inferred from the class defined inside the function\n // scope, so this can't be easily typed.\n // eslint-disable-next-line @typescript-eslint/explicit-function-return-type\n>() =>\n BlockTrackerPollingControllerMixin<typeof BaseController, PollingInput>(\n BaseController,\n );\n"]}
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
* This file is auto generated.
|
|
3
3
|
* Do not edit manually.
|
|
4
4
|
*/
|
|
5
|
-
import type { UserOperationController } from
|
|
5
|
+
import type { UserOperationController } from './UserOperationController.js';
|
|
6
6
|
/**
|
|
7
7
|
* Create and submit a user operation.
|
|
8
8
|
*
|
|
@@ -54,4 +54,4 @@ export type UserOperationControllerStartPollingByNetworkClientIdAction = {
|
|
|
54
54
|
* Union of all UserOperationController action types.
|
|
55
55
|
*/
|
|
56
56
|
export type UserOperationControllerMethodActions = UserOperationControllerAddUserOperationAction | UserOperationControllerAddUserOperationFromTransactionAction | UserOperationControllerStartPollingByNetworkClientIdAction;
|
|
57
|
-
//# sourceMappingURL=UserOperationController-method-action-types.d.
|
|
57
|
+
//# sourceMappingURL=UserOperationController-method-action-types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"UserOperationController-method-action-types.d.ts","sourceRoot":"","sources":["../src/UserOperationController-method-action-types.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,KAAK,EAAE,uBAAuB,EAAE,MAAM,8BAA8B,CAAC;AAE5E;;;;;;;;;;;;;;;;GAgBG;AACH,MAAM,MAAM,6CAA6C,GAAG;IAC1D,IAAI,EAAE,0CAA0C,CAAC;IACjD,OAAO,EAAE,uBAAuB,CAAC,kBAAkB,CAAC,CAAC;CACtD,CAAC;AAEF;;;;;;;;;;;GAWG;AACH,MAAM,MAAM,4DAA4D,GAAG;IACzE,IAAI,EAAE,yDAAyD,CAAC;IAChE,OAAO,EAAE,uBAAuB,CAAC,iCAAiC,CAAC,CAAC;CACrE,CAAC;AAEF;;;;;GAKG;AACH,MAAM,MAAM,0DAA0D,GAAG;IACvE,IAAI,EAAE,uDAAuD,CAAC;IAC9D,OAAO,EAAE,uBAAuB,CAAC,+BAA+B,CAAC,CAAC;CACnE,CAAC;AAEF;;GAEG;AACH,MAAM,MAAM,oCAAoC,GAC5C,6CAA6C,GAC7C,4DAA4D,GAC5D,0DAA0D,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"UserOperationController-method-action-types.js","sourceRoot":"","sources":["../src/UserOperationController-method-action-types.ts"],"names":[],"mappings":"AAAA;;;GAGG","sourcesContent":["/**\n * This file is auto generated.\n * Do not edit manually.\n */\n\nimport type { UserOperationController } from './UserOperationController.js';\n\n/**\n * Create and submit a user operation.\n *\n * @param request - Information required to create a user operation.\n * @param request.data - Data to include in the resulting transaction.\n * @param request.maxFeePerGas - Maximum fee per gas to pay towards the transaction.\n * @param request.maxPriorityFeePerGas - Maximum priority fee per gas to pay towards the transaction.\n * @param request.to - Destination address of the resulting transaction.\n * @param request.value - Value to include in the resulting transaction.\n * @param options - Configuration options when creating a user operation.\n * @param options.networkClientId - ID of the network client used to query the chain.\n * @param options.origin - Origin of the user operation, such as the hostname of a dApp.\n * @param options.requireApproval - Whether to require user approval before submitting the user operation. Defaults to true.\n * @param options.smartContractAccount - Smart contract abstraction to provide the contract specific values such as call data and nonce. Defaults to the current snap account.\n * @param options.swaps - Swap metadata to record with the user operation.\n * @param options.type - Type of the transaction.\n */\nexport type UserOperationControllerAddUserOperationAction = {\n type: `UserOperationController:addUserOperation`;\n handler: UserOperationController['addUserOperation'];\n};\n\n/**\n * Create and submit a user operation equivalent to the provided transaction.\n *\n * @param transaction - Transaction to use as the basis for the user operation.\n * @param options - Configuration options when creating a user operation.\n * @param options.networkClientId - ID of the network client used to query the chain.\n * @param options.origin - Origin of the user operation, such as the hostname of a dApp.\n * @param options.requireApproval - Whether to require user approval before submitting the user operation. Defaults to true.\n * @param options.smartContractAccount - Smart contract abstraction to provide the contract specific values such as call data and nonce. Defaults to the current snap account.\n * @param options.swaps - Swap metadata to record with the user operation.\n * @param options.type - Type of the transaction.\n */\nexport type UserOperationControllerAddUserOperationFromTransactionAction = {\n type: `UserOperationController:addUserOperationFromTransaction`;\n handler: UserOperationController['addUserOperationFromTransaction'];\n};\n\n/**\n * Starts polling for pending user operations on the given network.\n *\n * @param networkClientId - The ID of the network client to poll.\n * @returns The polling token that can be used to stop polling.\n */\nexport type UserOperationControllerStartPollingByNetworkClientIdAction = {\n type: `UserOperationController:startPollingByNetworkClientId`;\n handler: UserOperationController['startPollingByNetworkClientId'];\n};\n\n/**\n * Union of all UserOperationController action types.\n */\nexport type UserOperationControllerMethodActions =\n | UserOperationControllerAddUserOperationAction\n | UserOperationControllerAddUserOperationFromTransactionAction\n | UserOperationControllerStartPollingByNetworkClientIdAction;\n"]}
|
|
@@ -1,17 +1,15 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
import type {
|
|
4
|
-
import {
|
|
5
|
-
import type {
|
|
6
|
-
import type {
|
|
7
|
-
import type {
|
|
8
|
-
import
|
|
9
|
-
import type {
|
|
10
|
-
import
|
|
11
|
-
import type {
|
|
12
|
-
import
|
|
13
|
-
import type { SmartContractAccount, UserOperationMetadata } from "./types.cjs";
|
|
14
|
-
import type { UserOperationControllerMethodActions } from "./UserOperationController-method-action-types.cjs";
|
|
1
|
+
import type { ApprovalControllerAddRequestAction } from '@metamask/approval-controller';
|
|
2
|
+
import { BaseController } from '@metamask/base-controller';
|
|
3
|
+
import type { ControllerGetStateAction, ControllerStateChangeEvent } from '@metamask/base-controller';
|
|
4
|
+
import type { GasFeeState } from '@metamask/gas-fee-controller';
|
|
5
|
+
import type { KeyringControllerPrepareUserOperationAction, KeyringControllerPatchUserOperationAction, KeyringControllerSignUserOperationAction } from '@metamask/keyring-controller';
|
|
6
|
+
import type { Messenger } from '@metamask/messenger';
|
|
7
|
+
import type { NetworkControllerGetNetworkClientByIdAction } from '@metamask/network-controller';
|
|
8
|
+
import { TransactionType } from '@metamask/transaction-controller';
|
|
9
|
+
import type { TransactionMeta, TransactionParams } from '@metamask/transaction-controller';
|
|
10
|
+
import EventEmitter from 'events';
|
|
11
|
+
import type { SmartContractAccount, UserOperationMetadata } from './types.js';
|
|
12
|
+
import type { UserOperationControllerMethodActions } from './UserOperationController-method-action-types.js';
|
|
15
13
|
declare const controllerName = "UserOperationController";
|
|
16
14
|
type Events = {
|
|
17
15
|
'transaction-updated': [metadata: TransactionMeta];
|
|
@@ -133,4 +131,4 @@ export declare class UserOperationController extends BaseController<typeof contr
|
|
|
133
131
|
startPollingByNetworkClientId(networkClientId: string): string;
|
|
134
132
|
}
|
|
135
133
|
export {};
|
|
136
|
-
//# sourceMappingURL=UserOperationController.d.
|
|
134
|
+
//# sourceMappingURL=UserOperationController.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"UserOperationController.d.ts","sourceRoot":"","sources":["../src/UserOperationController.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAEV,kCAAkC,EAEnC,MAAM,+BAA+B,CAAC;AACvC,OAAO,EAAE,cAAc,EAAE,MAAM,2BAA2B,CAAC;AAC3D,OAAO,KAAK,EACV,wBAAwB,EACxB,0BAA0B,EAC3B,MAAM,2BAA2B,CAAC;AAEnC,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,8BAA8B,CAAC;AAChE,OAAO,KAAK,EACV,2CAA2C,EAC3C,yCAAyC,EACzC,wCAAwC,EACzC,MAAM,8BAA8B,CAAC;AACtC,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,qBAAqB,CAAC;AACrD,OAAO,KAAK,EACV,2CAA2C,EAE5C,MAAM,8BAA8B,CAAC;AAEtC,OAAO,EAAE,eAAe,EAAE,MAAM,kCAAkC,CAAC;AACnE,OAAO,KAAK,EACV,eAAe,EACf,iBAAiB,EAClB,MAAM,kCAAkC,CAAC;AAI1C,OAAO,YAAY,MAAM,QAAQ,CAAC;AASlC,OAAO,KAAK,EACV,oBAAoB,EAEpB,qBAAqB,EACtB,MAAM,YAAY,CAAC;AAEpB,OAAO,KAAK,EAAE,oCAAoC,EAAE,MAAM,kDAAkD,CAAC;AAY7G,QAAA,MAAM,cAAc,4BAA4B,CAAC;AAqBjD,KAAK,MAAM,GAAG;IACZ,qBAAqB,EAAE,CAAC,QAAQ,EAAE,eAAe,CAAC,CAAC;IACnD,sBAAsB,EAAE,CAAC,QAAQ,EAAE,qBAAqB,CAAC,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? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
|
|
11
11
|
};
|
|
12
12
|
var _UserOperationController_instances, _UserOperationController_entrypoint, _UserOperationController_getGasFeeEstimates, _UserOperationController_pendingUserOperationTracker, _UserOperationController_addUserOperation, _UserOperationController_prepareAndSubmitUserOperation, _UserOperationController_waitForConfirmation, _UserOperationController_createMetadata, _UserOperationController_prepareUserOperation, _UserOperationController_addPaymasterData, _UserOperationController_approveUserOperation, _UserOperationController_signUserOperation, _UserOperationController_submitUserOperation, _UserOperationController_failUserOperation, _UserOperationController_createEmptyUserOperation, _UserOperationController_updateMetadata, _UserOperationController_deleteMetadata, _UserOperationController_updateTransaction, _UserOperationController_addPendingUserOperationTrackerListeners, _UserOperationController_requestApproval, _UserOperationController_getTransactionType, _UserOperationController_getProvider, _UserOperationController_updateUserOperationAfterApproval, _UserOperationController_regenerateUserOperation;
|
|
13
|
-
import { BaseController } from
|
|
14
|
-
import { ApprovalType } from
|
|
15
|
-
import { errorCodes } from
|
|
16
|
-
import { TransactionType } from
|
|
17
|
-
import { add0x } from
|
|
13
|
+
import { BaseController } from '@metamask/base-controller';
|
|
14
|
+
import { ApprovalType } from '@metamask/controller-utils';
|
|
15
|
+
import { errorCodes } from '@metamask/rpc-errors';
|
|
16
|
+
import { TransactionType } from '@metamask/transaction-controller';
|
|
17
|
+
import { add0x } from '@metamask/utils';
|
|
18
18
|
// This package purposefully relies on Node's EventEmitter module.
|
|
19
19
|
// eslint-disable-next-line import-x/no-nodejs-modules
|
|
20
|
-
import EventEmitter from
|
|
21
|
-
import
|
|
22
|
-
|
|
23
|
-
import {
|
|
24
|
-
import {
|
|
25
|
-
import {
|
|
26
|
-
import {
|
|
27
|
-
import {
|
|
28
|
-
import {
|
|
29
|
-
import {
|
|
30
|
-
import {
|
|
31
|
-
import {
|
|
32
|
-
import {
|
|
33
|
-
import { validateAddUserOperationOptions, validateAddUserOperationRequest, validatePrepareUserOperationResponse, validateSignUserOperationResponse, validateUpdateUserOperationResponse } from "./utils/validation.mjs";
|
|
20
|
+
import EventEmitter from 'events';
|
|
21
|
+
import { cloneDeep } from 'lodash-es';
|
|
22
|
+
import { v1 as random } from 'uuid';
|
|
23
|
+
import { ADDRESS_ZERO, EMPTY_BYTES, VALUE_ZERO } from './constants.js';
|
|
24
|
+
import { Bundler } from './helpers/Bundler.js';
|
|
25
|
+
import { PendingUserOperationTracker } from './helpers/PendingUserOperationTracker.js';
|
|
26
|
+
import { SnapSmartContractAccount } from './helpers/SnapSmartContractAccount.js';
|
|
27
|
+
import { projectLogger as log } from './logger.js';
|
|
28
|
+
import { UserOperationStatus } from './types.js';
|
|
29
|
+
import { updateGasFees } from './utils/gas-fees.js';
|
|
30
|
+
import { updateGas } from './utils/gas.js';
|
|
31
|
+
import { getTransactionMetadata } from './utils/transaction.js';
|
|
32
|
+
import { validateAddUserOperationOptions, validateAddUserOperationRequest, validatePrepareUserOperationResponse, validateSignUserOperationResponse, validateUpdateUserOperationResponse, } from './utils/validation.js';
|
|
34
33
|
const controllerName = 'UserOperationController';
|
|
35
34
|
const MESSENGER_EXPOSED_METHODS = [
|
|
36
35
|
'addUserOperation',
|
|
@@ -486,4 +485,4 @@ _UserOperationController_entrypoint = new WeakMap(), _UserOperationController_ge
|
|
|
486
485
|
await __classPrivateFieldGet(this, _UserOperationController_instances, "m", _UserOperationController_addPaymasterData).call(this, metadata, smartContractAccount);
|
|
487
486
|
log('Regenerated user operation', metadata.userOperation);
|
|
488
487
|
};
|
|
489
|
-
//# sourceMappingURL=UserOperationController.
|
|
488
|
+
//# sourceMappingURL=UserOperationController.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"UserOperationController.js","sourceRoot":"","sources":["../src/UserOperationController.ts"],"names":[],"mappings":";;;;;;;;;;;;AAKA,OAAO,EAAE,cAAc,EAAE,MAAM,2BAA2B,CAAC;AAK3D,OAAO,EAAE,YAAY,EAAE,MAAM,4BAA4B,CAAC;AAY1D,OAAO,EAA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EAAE,mBAAmB;YACjC,oBAAoB,EAAE,2BAA2B;YACjD,KAAK,EAAE,YAAY;SACpB,CAAC;QAEF,MAAM,uBAAA,IAAI,4FAAyB,MAA7B,IAAI,EAA0B;YAClC,GAAG,KAAK;YACR,OAAO,EAAE,cAAc;SACxB,CAAC,CAAC;IACL,CAAC;AACH,CAAC,qDAED,KAAK,2DAA0B,KAAyB;IACtD,GAAG,CACD,wEAAwE,CACzE,CAAC;IAEF,MAAM,EACJ,OAAO,EAAE,EAAE,oBAAoB,EAAE,EACjC,QAAQ,GACT,GAAG,KAAK,CAAC;IAEV,MAAM,uBAAA,IAAI,yFAAsB,MAA1B,IAAI,EAAuB,KAAK,CAAC,CAAC;IACxC,MAAM,uBAAA,IAAI,qFAAkB,MAAtB,IAAI,EAAmB,QAAQ,EAAE,oBAAoB,CAAC,CAAC;IAE7D,GAAG,CAAC,4BAA4B,EAAE,QAAQ,CAAC,aAAa,CAAC,CAAC;AAC5D,CAAC","sourcesContent":["import type {\n AcceptResultCallbacks,\n ApprovalControllerAddRequestAction,\n AddResult,\n} from '@metamask/approval-controller';\nimport { BaseController } from '@metamask/base-controller';\nimport type {\n ControllerGetStateAction,\n ControllerStateChangeEvent,\n} from '@metamask/base-controller';\nimport { ApprovalType } from '@metamask/controller-utils';\nimport type { GasFeeState } from '@metamask/gas-fee-controller';\nimport type {\n KeyringControllerPrepareUserOperationAction,\n KeyringControllerPatchUserOperationAction,\n KeyringControllerSignUserOperationAction,\n} from '@metamask/keyring-controller';\nimport type { Messenger } from '@metamask/messenger';\nimport type {\n NetworkControllerGetNetworkClientByIdAction,\n Provider,\n} from '@metamask/network-controller';\nimport { errorCodes } from '@metamask/rpc-errors';\nimport { TransactionType } from '@metamask/transaction-controller';\nimport type {\n TransactionMeta,\n TransactionParams,\n} from '@metamask/transaction-controller';\nimport { add0x } from '@metamask/utils';\n// This package purposefully relies on Node's EventEmitter module.\n// eslint-disable-next-line import-x/no-nodejs-modules\nimport EventEmitter from 'events';\nimport { cloneDeep } from 'lodash-es';\nimport { v1 as random } from 'uuid';\n\nimport { ADDRESS_ZERO, EMPTY_BYTES, VALUE_ZERO } from './constants.js';\nimport { Bundler } from './helpers/Bundler.js';\nimport { PendingUserOperationTracker } from './helpers/PendingUserOperationTracker.js';\nimport { SnapSmartContractAccount } from './helpers/SnapSmartContractAccount.js';\nimport { projectLogger as log } from './logger.js';\nimport type {\n SmartContractAccount,\n UserOperation,\n UserOperationMetadata,\n} from './types.js';\nimport { UserOperationStatus } from './types.js';\nimport type { UserOperationControllerMethodActions } from './UserOperationController-method-action-types.js';\nimport { updateGasFees } from './utils/gas-fees.js';\nimport { updateGas } from './utils/gas.js';\nimport { getTransactionMetadata } from './utils/transaction.js';\nimport {\n validateAddUserOperationOptions,\n validateAddUserOperationRequest,\n validatePrepareUserOperationResponse,\n validateSignUserOperationResponse,\n validateUpdateUserOperationResponse,\n} from './utils/validation.js';\n\nconst controllerName = 'UserOperationController';\n\nconst MESSENGER_EXPOSED_METHODS = [\n 'addUserOperation',\n 'addUserOperationFromTransaction',\n 'startPollingByNetworkClientId',\n] as const;\n\nconst stateMetadata = {\n userOperations: {\n includeInStateLogs: true,\n persist: true,\n includeInDebugSnapshot: false,\n usedInUi: true,\n },\n};\n\nconst getDefaultState = () => ({\n userOperations: {},\n});\n\ntype Events = {\n 'transaction-updated': [metadata: TransactionMeta];\n 'user-operation-added': [metadata: UserOperationMetadata];\n 'user-operation-confirmed': [metadata: UserOperationMetadata];\n 'user-operation-failed': [metadata: UserOperationMetadata, error: Error];\n [key: `${string}:confirmed`]: [metadata: UserOperationMetadata];\n [key: `${string}:failed`]: [metadata: UserOperationMetadata, error: Error];\n};\n\nexport type UserOperationControllerEventEmitter = EventEmitter & {\n on<T extends keyof Events>(\n eventName: T,\n listener: (...args: Events[T]) => void,\n ): UserOperationControllerEventEmitter;\n\n once<T extends keyof Events>(\n eventName: T,\n listener: (...args: Events[T]) => void,\n ): UserOperationControllerEventEmitter;\n\n emit<T extends keyof Events>(eventName: T, ...args: Events[T]): boolean;\n};\n\nexport type UserOperationControllerState = {\n userOperations: Record<string, UserOperationMetadata>;\n};\n\nexport type GetUserOperationState = ControllerGetStateAction<\n typeof controllerName,\n UserOperationControllerState\n>;\n\nexport type UserOperationStateChange = ControllerStateChangeEvent<\n typeof controllerName,\n UserOperationControllerState\n>;\n\nexport type UserOperationControllerActions =\n | GetUserOperationState\n | UserOperationControllerMethodActions\n | NetworkControllerGetNetworkClientByIdAction\n | ApprovalControllerAddRequestAction\n | KeyringControllerPrepareUserOperationAction\n | KeyringControllerPatchUserOperationAction\n | KeyringControllerSignUserOperationAction;\n\nexport type UserOperationControllerEvents = UserOperationStateChange;\n\nexport type UserOperationControllerMessenger = Messenger<\n typeof controllerName,\n UserOperationControllerActions,\n UserOperationControllerEvents\n>;\n\nexport type UserOperationControllerOptions = {\n entrypoint: string;\n getGasFeeEstimates: () => Promise<GasFeeState>;\n interval?: number;\n messenger: UserOperationControllerMessenger;\n state?: Partial<UserOperationControllerState>;\n};\n\nexport type AddUserOperationRequest = {\n data?: string;\n from: string;\n maxFeePerGas?: string;\n maxPriorityFeePerGas?: string;\n to?: string;\n value?: string;\n};\n\nexport type AddUserOperationSwapOptions = {\n approvalTxId?: string;\n destinationTokenAddress?: string;\n destinationTokenAmount?: string;\n destinationTokenDecimals?: number;\n destinationTokenSymbol?: string;\n estimatedBaseFee?: string;\n sourceTokenAddress?: string;\n sourceTokenAmount?: string;\n sourceTokenDecimals?: number;\n sourceTokenSymbol?: string;\n swapAndSendRecipient?: string;\n swapMetaData?: Record<string, unknown>;\n swapTokenValue?: string;\n};\n\nexport type AddUserOperationOptions = {\n networkClientId: string;\n origin: string;\n requireApproval?: boolean;\n smartContractAccount?: SmartContractAccount;\n swaps?: AddUserOperationSwapOptions;\n type?: TransactionType;\n};\n\nexport type AddUserOperationResponse = {\n id: string;\n hash: () => Promise<string | undefined>;\n transactionHash: () => Promise<string | undefined>;\n};\n\n/**\n * All the objects related to a pending user operation in order to:\n * - Avoid duplicated effort to derive the same properties.\n * - Minimise duplicate arguments in private methods.\n */\ntype UserOperationCache = {\n chainId: string;\n metadata: UserOperationMetadata;\n options: AddUserOperationOptions & {\n smartContractAccount: SmartContractAccount;\n };\n provider: Provider;\n request: AddUserOperationRequest;\n transaction?: TransactionParams;\n};\n\n/**\n * Controller for creating and managing the life cycle of user operations.\n */\nexport class UserOperationController extends BaseController<\n typeof controllerName,\n UserOperationControllerState,\n UserOperationControllerMessenger\n> {\n hub: UserOperationControllerEventEmitter;\n\n readonly #entrypoint: string;\n\n readonly #getGasFeeEstimates: () => Promise<GasFeeState>;\n\n readonly #pendingUserOperationTracker: PendingUserOperationTracker;\n\n /**\n * Construct a UserOperationController instance.\n *\n * @param options - Controller options.\n * @param options.entrypoint - Address of the entrypoint contract.\n * @param options.getGasFeeEstimates - Callback to get gas fee estimates.\n * @param options.messenger - Restricted messenger for the user operation controller.\n * @param options.state - Initial state to set on the controller.\n */\n constructor({\n entrypoint,\n getGasFeeEstimates,\n messenger,\n state,\n }: UserOperationControllerOptions) {\n super({\n name: controllerName,\n metadata: stateMetadata,\n messenger,\n state: { ...getDefaultState(), ...state },\n });\n\n this.hub = new EventEmitter() as UserOperationControllerEventEmitter;\n\n this.messenger.registerMethodActionHandlers(\n this,\n MESSENGER_EXPOSED_METHODS,\n );\n\n this.#entrypoint = entrypoint;\n this.#getGasFeeEstimates = getGasFeeEstimates;\n\n this.#pendingUserOperationTracker = new PendingUserOperationTracker({\n getUserOperations: () =>\n cloneDeep(Object.values(this.state.userOperations)),\n messenger,\n });\n\n this.#addPendingUserOperationTrackerListeners();\n }\n\n /**\n * Create and submit a user operation.\n *\n * @param request - Information required to create a user operation.\n * @param request.data - Data to include in the resulting transaction.\n * @param request.maxFeePerGas - Maximum fee per gas to pay towards the transaction.\n * @param request.maxPriorityFeePerGas - Maximum priority fee per gas to pay towards the transaction.\n * @param request.to - Destination address of the resulting transaction.\n * @param request.value - Value to include in the resulting transaction.\n * @param options - Configuration options when creating a user operation.\n * @param options.networkClientId - ID of the network client used to query the chain.\n * @param options.origin - Origin of the user operation, such as the hostname of a dApp.\n * @param options.requireApproval - Whether to require user approval before submitting the user operation. Defaults to true.\n * @param options.smartContractAccount - Smart contract abstraction to provide the contract specific values such as call data and nonce. Defaults to the current snap account.\n * @param options.swaps - Swap metadata to record with the user operation.\n * @param options.type - Type of the transaction.\n */\n async addUserOperation(\n request: AddUserOperationRequest,\n options: AddUserOperationOptions,\n ): Promise<AddUserOperationResponse> {\n validateAddUserOperationRequest(request);\n validateAddUserOperationOptions(options);\n\n return await this.#addUserOperation(request, options);\n }\n\n /**\n * Create and submit a user operation equivalent to the provided transaction.\n *\n * @param transaction - Transaction to use as the basis for the user operation.\n * @param options - Configuration options when creating a user operation.\n * @param options.networkClientId - ID of the network client used to query the chain.\n * @param options.origin - Origin of the user operation, such as the hostname of a dApp.\n * @param options.requireApproval - Whether to require user approval before submitting the user operation. Defaults to true.\n * @param options.smartContractAccount - Smart contract abstraction to provide the contract specific values such as call data and nonce. Defaults to the current snap account.\n * @param options.swaps - Swap metadata to record with the user operation.\n * @param options.type - Type of the transaction.\n */\n async addUserOperationFromTransaction(\n transaction: TransactionParams,\n options: AddUserOperationOptions,\n ): Promise<AddUserOperationResponse> {\n validateAddUserOperationOptions(options);\n\n const { data, from, maxFeePerGas, maxPriorityFeePerGas, to, value } =\n transaction;\n\n const request: AddUserOperationRequest = {\n data: data === '' ? undefined : data,\n from,\n maxFeePerGas,\n maxPriorityFeePerGas,\n to,\n value,\n };\n\n validateAddUserOperationRequest(request);\n\n return await this.#addUserOperation(request, { ...options, transaction });\n }\n\n /**\n * Starts polling for pending user operations on the given network.\n *\n * @param networkClientId - The ID of the network client to poll.\n * @returns The polling token that can be used to stop polling.\n */\n startPollingByNetworkClientId(networkClientId: string): string {\n return this.#pendingUserOperationTracker.startPolling({\n networkClientId,\n });\n }\n\n async #addUserOperation(\n request: AddUserOperationRequest,\n options: AddUserOperationOptions & { transaction?: TransactionParams },\n ): Promise<AddUserOperationResponse> {\n log('Adding user operation', { request, options });\n\n const {\n networkClientId,\n origin,\n smartContractAccount: requestSmartContractAccount,\n swaps,\n transaction,\n } = options;\n\n const { chainId, provider } = await this.#getProvider(networkClientId);\n\n const metadata = await this.#createMetadata(\n chainId,\n origin,\n transaction,\n swaps,\n );\n\n const smartContractAccount =\n requestSmartContractAccount ??\n new SnapSmartContractAccount(this.messenger);\n\n const cache: UserOperationCache = {\n chainId,\n metadata,\n options: { ...options, smartContractAccount },\n provider,\n request,\n transaction,\n };\n\n const { id } = metadata;\n let throwError = false;\n\n const hashValue = (async () => {\n try {\n return await this.#prepareAndSubmitUserOperation(cache);\n } catch (error) {\n this.#failUserOperation(metadata, error);\n\n if (throwError) {\n throw error;\n }\n\n return undefined;\n }\n })();\n\n const hash = async () => {\n throwError = true;\n return await hashValue;\n };\n\n const transactionHash = async () => {\n await hash();\n\n const { transactionHash: finalTransactionHash } =\n await this.#waitForConfirmation(metadata);\n\n return finalTransactionHash as string;\n };\n\n return {\n id,\n hash,\n transactionHash,\n };\n }\n\n async #prepareAndSubmitUserOperation(cache: UserOperationCache) {\n const { metadata, options } = cache;\n const { requireApproval, smartContractAccount } = options;\n let resultCallbacks: AcceptResultCallbacks | undefined;\n\n try {\n await this.#prepareUserOperation(cache);\n await this.#addPaymasterData(metadata, smartContractAccount);\n\n this.hub.emit('user-operation-added', metadata);\n\n if (requireApproval !== false) {\n resultCallbacks = await this.#approveUserOperation(cache);\n }\n\n await this.#signUserOperation(metadata, smartContractAccount);\n await this.#submitUserOperation(metadata);\n\n resultCallbacks?.success();\n\n return metadata.hash as string;\n } catch (error) {\n /* istanbul ignore next */\n resultCallbacks?.error(error as Error);\n throw error;\n }\n }\n\n async #waitForConfirmation(\n metadata: UserOperationMetadata,\n ): Promise<UserOperationMetadata> {\n const { id, hash } = metadata;\n\n log('Waiting for confirmation', id, hash);\n\n return new Promise((resolve, reject) => {\n this.hub.once(`${id}:confirmed`, (finalMetadata) => {\n resolve(finalMetadata);\n });\n\n this.hub.once(`${id}:failed`, (_finalMetadata, error) => {\n reject(error);\n });\n });\n }\n\n async #createMetadata(\n chainId: string,\n origin: string,\n transaction?: TransactionParams,\n swaps?: AddUserOperationSwapOptions,\n ): Promise<UserOperationMetadata> {\n const metadata: UserOperationMetadata = {\n actualGasCost: null,\n actualGasUsed: null,\n baseFeePerGas: null,\n bundlerUrl: null,\n chainId,\n error: null,\n hash: null,\n id: random(),\n origin,\n status: UserOperationStatus.Unapproved,\n swapsMetadata: swaps\n ? {\n approvalTxId: swaps.approvalTxId ?? null,\n destinationTokenAddress: swaps.destinationTokenAddress ?? null,\n destinationTokenAmount: swaps.destinationTokenAmount ?? null,\n destinationTokenDecimals: swaps.destinationTokenDecimals ?? null,\n destinationTokenSymbol: swaps.destinationTokenSymbol ?? null,\n estimatedBaseFee: swaps.estimatedBaseFee ?? null,\n sourceTokenAddress: swaps.sourceTokenAddress ?? null,\n sourceTokenAmount: swaps.sourceTokenAmount ?? null,\n sourceTokenDecimals: swaps.sourceTokenDecimals ?? null,\n sourceTokenSymbol: swaps.sourceTokenSymbol ?? null,\n swapAndSendRecipient: swaps.swapAndSendRecipient ?? null,\n swapMetaData: (swaps.swapMetaData as Record<string, never>) ?? null,\n swapTokenValue: swaps.swapTokenValue ?? null,\n }\n : null,\n time: Date.now(),\n transactionHash: null,\n transactionParams: (transaction as Required<TransactionParams>) ?? null,\n transactionType: null,\n userFeeLevel: null,\n userOperation: this.#createEmptyUserOperation(transaction),\n };\n\n this.#updateMetadata(metadata);\n\n log('Added user operation', metadata.id);\n\n return metadata;\n }\n\n async #prepareUserOperation(cache: UserOperationCache) {\n const { chainId, metadata, options, provider, request, transaction } =\n cache;\n\n const { data, from, to, value } = request;\n const { id, transactionParams, userOperation } = metadata;\n const { smartContractAccount } = options;\n\n log('Preparing user operation', { id });\n\n const transactionType = await this.#getTransactionType(\n transaction,\n options,\n );\n\n metadata.transactionType = transactionType ?? null;\n\n log('Determined transaction type', transactionType);\n\n await updateGasFees({\n getGasFeeEstimates: this.#getGasFeeEstimates,\n metadata,\n originalRequest: request,\n provider,\n transaction: transactionParams ?? undefined,\n });\n\n const response = await smartContractAccount.prepareUserOperation({\n chainId,\n data,\n from,\n to,\n value,\n });\n\n validatePrepareUserOperationResponse(response);\n\n const {\n bundler: bundlerUrl,\n callData,\n dummyPaymasterAndData,\n dummySignature,\n initCode,\n nonce,\n sender,\n } = response;\n\n userOperation.callData = callData;\n userOperation.initCode = initCode ?? EMPTY_BYTES;\n userOperation.nonce = nonce;\n userOperation.paymasterAndData = dummyPaymasterAndData ?? EMPTY_BYTES;\n userOperation.sender = sender;\n userOperation.signature = dummySignature ?? EMPTY_BYTES;\n\n metadata.bundlerUrl = bundlerUrl;\n\n await updateGas(metadata, response, this.#entrypoint);\n\n this.#updateMetadata(metadata);\n }\n\n async #addPaymasterData(\n metadata: UserOperationMetadata,\n smartContractAccount: SmartContractAccount,\n ) {\n const { id, userOperation, chainId } = metadata;\n\n log('Requesting paymaster data', { id });\n\n const response = await smartContractAccount.updateUserOperation({\n userOperation,\n chainId,\n });\n\n validateUpdateUserOperationResponse(response);\n\n userOperation.paymasterAndData = response.paymasterAndData ?? EMPTY_BYTES;\n if (response.callGasLimit) {\n userOperation.callGasLimit = response.callGasLimit;\n }\n if (response.preVerificationGas) {\n userOperation.preVerificationGas = response.preVerificationGas;\n }\n if (response.verificationGasLimit) {\n userOperation.verificationGasLimit = response.verificationGasLimit;\n }\n\n this.#updateMetadata(metadata);\n }\n\n async #approveUserOperation(cache: UserOperationCache) {\n log('Requesting approval');\n\n const { metadata } = cache;\n\n const { resultCallbacks, value } = await this.#requestApproval(metadata);\n const updatedTransaction = value?.txMeta;\n\n if (updatedTransaction) {\n await this.#updateUserOperationAfterApproval(cache, updatedTransaction);\n }\n\n metadata.status = UserOperationStatus.Approved;\n\n this.#updateMetadata(metadata);\n\n return resultCallbacks;\n }\n\n async #signUserOperation(\n metadata: UserOperationMetadata,\n smartContractAccount: SmartContractAccount,\n ) {\n const { id, chainId, userOperation } = metadata;\n\n log('Signing user operation', id, userOperation);\n\n const response = await smartContractAccount.signUserOperation({\n userOperation,\n chainId,\n });\n\n validateSignUserOperationResponse(response);\n\n const { signature } = response;\n\n userOperation.signature = signature;\n\n log('Signed user operation', signature);\n\n metadata.status = UserOperationStatus.Signed;\n\n this.#updateMetadata(metadata);\n }\n\n async #submitUserOperation(metadata: UserOperationMetadata) {\n const { userOperation } = metadata;\n\n log('Submitting user operation', userOperation);\n\n const bundler = new Bundler(metadata.bundlerUrl as string);\n\n const hash = await bundler.sendUserOperation(\n userOperation,\n this.#entrypoint,\n );\n\n metadata.hash = hash;\n metadata.status = UserOperationStatus.Submitted;\n\n this.#updateMetadata(metadata);\n }\n\n #failUserOperation(metadata: UserOperationMetadata, error: unknown) {\n const { id } = metadata;\n const rawError = error as Record<string, string>;\n\n log('User operation failed', id, error);\n\n metadata.error = {\n name: rawError.name,\n message: rawError.message,\n stack: rawError.stack,\n code: rawError.code,\n rpc: rawError.value,\n };\n\n metadata.status = UserOperationStatus.Failed;\n\n this.#updateMetadata(metadata);\n\n if (\n String(rawError.code) === String(errorCodes.provider.userRejectedRequest)\n ) {\n this.#deleteMetadata(id);\n }\n }\n\n #createEmptyUserOperation(transaction?: TransactionParams): UserOperation {\n return {\n callData: EMPTY_BYTES,\n callGasLimit: EMPTY_BYTES,\n initCode: EMPTY_BYTES,\n maxFeePerGas: transaction?.maxFeePerGas ?? EMPTY_BYTES,\n maxPriorityFeePerGas: transaction?.maxPriorityFeePerGas ?? EMPTY_BYTES,\n nonce: EMPTY_BYTES,\n paymasterAndData: EMPTY_BYTES,\n preVerificationGas: EMPTY_BYTES,\n sender: ADDRESS_ZERO,\n signature: EMPTY_BYTES,\n verificationGasLimit: EMPTY_BYTES,\n };\n }\n\n #updateMetadata(metadata: UserOperationMetadata) {\n const { id } = metadata;\n\n this.update((state) => {\n state.userOperations[id] = cloneDeep(metadata);\n });\n\n this.#updateTransaction(metadata);\n }\n\n #deleteMetadata(id: string) {\n this.update((state) => {\n delete state.userOperations[id];\n });\n }\n\n #updateTransaction(metadata: UserOperationMetadata) {\n if (!metadata.transactionParams) {\n return;\n }\n\n const transactionMetadata = getTransactionMetadata(metadata);\n\n this.hub.emit('transaction-updated', transactionMetadata);\n }\n\n #addPendingUserOperationTrackerListeners() {\n this.#pendingUserOperationTracker.hub.on(\n 'user-operation-confirmed',\n (metadata) => {\n log('In listener...');\n this.hub.emit('user-operation-confirmed', metadata);\n this.hub.emit(`${metadata.id}:confirmed`, metadata);\n },\n );\n\n this.#pendingUserOperationTracker.hub.on(\n 'user-operation-failed',\n (metadata, error) => {\n this.hub.emit('user-operation-failed', metadata, error);\n this.hub.emit(`${metadata.id}:failed`, metadata, error);\n },\n );\n\n this.#pendingUserOperationTracker.hub.on(\n 'user-operation-updated',\n (metadata) => {\n this.#updateMetadata(metadata);\n },\n );\n }\n\n async #requestApproval(metadata: UserOperationMetadata) {\n const { id, origin } = metadata;\n const type = ApprovalType.Transaction;\n const requestData = { txId: id };\n\n return (await this.messenger.call(\n 'ApprovalController:addRequest',\n {\n id,\n origin,\n type,\n requestData,\n expectsResult: true,\n },\n true, // Should display approval request to user\n )) as AddResult & { value?: { txMeta?: TransactionMeta } };\n }\n\n async #getTransactionType(\n transaction: TransactionParams | undefined,\n options: AddUserOperationOptions,\n ): Promise<TransactionType | undefined> {\n if (!transaction) {\n return undefined;\n }\n\n if (options.type) {\n return options.type;\n }\n\n return TransactionType.contractInteraction;\n }\n\n async #getProvider(\n networkClientId: string,\n ): Promise<{ provider: Provider; chainId: string }> {\n const { provider, configuration } = this.messenger.call(\n 'NetworkController:getNetworkClientById',\n networkClientId,\n );\n\n const { chainId } = configuration;\n\n return { provider, chainId };\n }\n\n async #updateUserOperationAfterApproval(\n cache: UserOperationCache,\n updatedTransaction: TransactionMeta,\n ) {\n log('Found updated transaction in approval', { updatedTransaction });\n\n const { metadata, request } = cache;\n\n const { userOperation } = metadata;\n const usingPaymaster = userOperation.paymasterAndData !== EMPTY_BYTES;\n\n const updatedMaxFeePerGas = add0x(\n updatedTransaction.txParams.maxFeePerGas as string,\n );\n\n const updatedMaxPriorityFeePerGas = add0x(\n updatedTransaction.txParams.maxPriorityFeePerGas as string,\n );\n\n let regenerateUserOperation = false;\n const previousMaxFeePerGas = userOperation.maxFeePerGas;\n const previousMaxPriorityFeePerGas = userOperation.maxPriorityFeePerGas;\n\n const gasFeesUpdated =\n previousMaxFeePerGas !== updatedMaxFeePerGas ||\n previousMaxPriorityFeePerGas !== updatedMaxPriorityFeePerGas;\n\n /**\n * true when we detect {@link getTransactionMetadata} has set the gas fees to zero\n * because the userOperation has a paymaster. This should not be mistaken for gas\n * fees being updated during the approval process.\n */\n const areGasFeesZeroBecauseOfPaymaster =\n usingPaymaster &&\n updatedMaxFeePerGas === VALUE_ZERO &&\n updatedMaxPriorityFeePerGas === VALUE_ZERO;\n\n if (gasFeesUpdated && !areGasFeesZeroBecauseOfPaymaster) {\n log('Gas fees updated during approval', {\n previousMaxFeePerGas,\n previousMaxPriorityFeePerGas,\n updatedMaxFeePerGas,\n updatedMaxPriorityFeePerGas,\n });\n\n userOperation.maxFeePerGas = updatedMaxFeePerGas;\n userOperation.maxPriorityFeePerGas = updatedMaxPriorityFeePerGas;\n\n regenerateUserOperation = usingPaymaster;\n }\n\n const previousData = request.data ?? EMPTY_BYTES;\n const updatedData = updatedTransaction.txParams.data ?? EMPTY_BYTES;\n\n if (previousData !== updatedData) {\n log('Data updated during approval', { previousData, updatedData });\n regenerateUserOperation = true;\n }\n\n const previousValue = request.value ?? VALUE_ZERO;\n const updatedValue = updatedTransaction.txParams.value ?? VALUE_ZERO;\n\n if (previousValue !== updatedValue) {\n log('Value updated during approval', { previousValue, updatedValue });\n regenerateUserOperation = true;\n }\n\n if (regenerateUserOperation) {\n const updatedRequest = {\n ...request,\n data: updatedData,\n maxFeePerGas: updatedMaxFeePerGas,\n maxPriorityFeePerGas: updatedMaxPriorityFeePerGas,\n value: updatedValue,\n };\n\n await this.#regenerateUserOperation({\n ...cache,\n request: updatedRequest,\n });\n }\n }\n\n async #regenerateUserOperation(cache: UserOperationCache) {\n log(\n 'Regenerating user operation as parameters were updated during approval',\n );\n\n const {\n options: { smartContractAccount },\n metadata,\n } = cache;\n\n await this.#prepareUserOperation(cache);\n await this.#addPaymasterData(metadata, smartContractAccount);\n\n log('Regenerated user operation', metadata.userOperation);\n }\n}\n"]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"constants.d.ts","sourceRoot":"","sources":["../src/constants.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,WAAW,OAAO,CAAC;AAChC,eAAO,MAAM,YAAY,+CAA+C,CAAC;AACzE,eAAO,MAAM,UAAU,QAAQ,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"constants.js","sourceRoot":"","sources":["../src/constants.ts"],"names":[],"mappings":"AAAA,MAAM,CAAC,MAAM,WAAW,GAAG,IAAI,CAAC;AAChC,MAAM,CAAC,MAAM,YAAY,GAAG,4CAA4C,CAAC;AACzE,MAAM,CAAC,MAAM,UAAU,GAAG,KAAK,CAAC","sourcesContent":["export const EMPTY_BYTES = '0x';\nexport const ADDRESS_ZERO = '0x0000000000000000000000000000000000000000';\nexport const VALUE_ZERO = '0x0';\n"]}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { UserOperation, UserOperationReceipt } from
|
|
1
|
+
import type { UserOperation, UserOperationReceipt } from '../types.js';
|
|
2
2
|
/**
|
|
3
3
|
* Response from the `eth_estimateUserOperationGas` bundler method.
|
|
4
4
|
* Includes the estimated gas limits required by a user operation.
|
|
@@ -43,4 +43,4 @@ export declare class Bundler {
|
|
|
43
43
|
*/
|
|
44
44
|
sendUserOperation(userOperation: UserOperation, entrypoint: string): Promise<string>;
|
|
45
45
|
}
|
|
46
|
-
//# sourceMappingURL=Bundler.d.
|
|
46
|
+
//# sourceMappingURL=Bundler.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Bundler.d.ts","sourceRoot":"","sources":["../../src/helpers/Bundler.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,aAAa,EAAE,oBAAoB,EAAE,MAAM,aAAa,CAAC;AAIvE;;;GAGG;AACH,MAAM,MAAM,uCAAuC,GAAG;IACpD,iFAAiF;IACjF,kBAAkB,EAAE,MAAM,GAAG,MAAM,CAAC;IAEpC,2DAA2D;IAC3D,eAAe,CAAC,EAAE,MAAM,GAAG,MAAM,CAAC;IAElC,2DAA2D;IAC3D,oBAAoB,CAAC,EAAE,MAAM,GAAG,MAAM,CAAC;IAEvC,sEAAsE;IACtE,YAAY,EAAE,MAAM,GAAG,MAAM,CAAC;CAC/B,CAAC;AAEF;;GAEG;AACH,qBAAa,OAAO;;IAGlB,YAAY,GAAG,EAAE,MAAM,EAEtB;IAED;;;;;;OAMG;IACG,wBAAwB,CAC5B,aAAa,EAAE,aAAa,EAC5B,UAAU,EAAE,MAAM,GACjB,OAAO,CAAC,uCAAuC,CAAC,CAWlD;IAED;;;;;OAKG;IACG,uBAAuB,CAC3B,IAAI,CAAC,EAAE,MAAM,GACZ,OAAO,CAAC,oBAAoB,GAAG,SAAS,CAAC,CAO3C;IAED;;;;;;OAMG;IACG,iBAAiB,CACrB,aAAa,EAAE,aAAa,EAC5B,UAAU,EAAE,MAAM,GACjB,OAAO,CAAC,MAAM,CAAC,CAejB;CA0BF"}
|
|
@@ -10,7 +10,7 @@ var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (
|
|
|
10
10
|
return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
|
|
11
11
|
};
|
|
12
12
|
var _Bundler_instances, _Bundler_url, _Bundler_query;
|
|
13
|
-
import { createModuleLogger, projectLogger } from
|
|
13
|
+
import { createModuleLogger, projectLogger } from '../logger.js';
|
|
14
14
|
const log = createModuleLogger(projectLogger, 'bundler');
|
|
15
15
|
/**
|
|
16
16
|
* A helper class for interacting with a bundler.
|
|
@@ -84,4 +84,4 @@ _Bundler_url = new WeakMap(), _Bundler_instances = new WeakSet(), _Bundler_query
|
|
|
84
84
|
}
|
|
85
85
|
return responseJson.result;
|
|
86
86
|
};
|
|
87
|
-
//# sourceMappingURL=Bundler.
|
|
87
|
+
//# sourceMappingURL=Bundler.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Bundler.js","sourceRoot":"","sources":["../../src/helpers/Bundler.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,OAAO,EAAE,kBAAkB,EAAE,aAAa,EAAE,MAAM,cAAc,CAAC;AAGjE,MAAM,GAAG,GAAG,kBAAkB,CAAC,aAAa,EAAE,SAAS,CAAC,CAAC;AAoBzD;;GAEG;AACH,MAAM,OAAO,OAAO;IAGlB,YAAY,GAAW;;QAFd,+BAAa;QAGpB,uBAAA,IAAI,gBAAQ,GAAG,MAAA,CAAC;IAClB,CAAC;IAED;;;;;;OAMG;IACH,KAAK,CAAC,wBAAwB,CAC5B,aAA4B,EAC5B,UAAkB;QAElB,GAAG,CAAC,gBAAgB,EAAE,EAAE,GAAG,EAAE,uBAAA,IAAI,oBAAK,EAAE,aAAa,EAAE,UAAU,EAAE,CAAC,CAAC;QAErE,MAAM,QAAQ,GAA4C,MAAM,uBAAA,IAAI,0CAAO,MAAX,IAAI,EAClE,8BAA8B,EAC9B,CAAC,aAAa,EAAE,UAAU,CAAC,CAC5B,CAAC;QAEF,GAAG,CAAC,eAAe,EAAE,EAAE,QAAQ,EAAE,CAAC,CAAC;QAEnC,OAAO,QAAQ,CAAC;IAClB,CAAC;IAED;;;;;OAKG;IACH,KAAK,CAAC,uBAAuB,CAC3B,IAAa;QAEb,GAAG,CAAC,gCAAgC,EAAE,EAAE,GAAG,EAAE,uBAAA,IAAI,oBAAK,EAAE,IAAI,EAAE,CAAC,CAAC;QAEhE,OAAO,MAAM,u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AC;AAC7B,CAAC","sourcesContent":["import { createModuleLogger, projectLogger } from '../logger.js';\nimport type { UserOperation, UserOperationReceipt } from '../types.js';\n\nconst log = createModuleLogger(projectLogger, 'bundler');\n\n/**\n * Response from the `eth_estimateUserOperationGas` bundler method.\n * Includes the estimated gas limits required by a user operation.\n */\nexport type BundlerEstimateUserOperationGasResponse = {\n /** Estimated gas required to compensate the bundler for any pre-verification. */\n preVerificationGas: number | string;\n\n /** Estimated gas required to verify the user operation. */\n verificationGas?: number | string;\n\n /** Estimated gas required to verify the user operation. */\n verificationGasLimit?: number | string;\n\n /** Estimated gas required for the execution of the user operation. */\n callGasLimit: number | string;\n};\n\n/**\n * A helper class for interacting with a bundler.\n */\nexport class Bundler {\n readonly #url: string;\n\n constructor(url: string) {\n this.#url = url;\n }\n\n /**\n * Estimate the gas required to execute a user operation.\n *\n * @param userOperation - The user operation to estimate gas for.\n * @param entrypoint - The address of entrypoint to use for the user operation.\n * @returns The estimated gas limits for the user operation.\n */\n async estimateUserOperationGas(\n userOperation: UserOperation,\n entrypoint: string,\n ): Promise<BundlerEstimateUserOperationGasResponse> {\n log('Estimating gas', { url: this.#url, userOperation, entrypoint });\n\n const response: BundlerEstimateUserOperationGasResponse = await this.#query(\n 'eth_estimateUserOperationGas',\n [userOperation, entrypoint],\n );\n\n log('Estimated gas', { response });\n\n return response;\n }\n\n /**\n * Retrieve the receipt for a user operation.\n *\n * @param hash - The hash of the user operation.\n * @returns The receipt for the user operation, or `undefined` if the user operation is pending.\n */\n async getUserOperationReceipt(\n hash?: string,\n ): Promise<UserOperationReceipt | undefined> {\n log('Getting user operation receipt', { url: this.#url, hash });\n\n return await this.#query<UserOperationReceipt | undefined>(\n 'eth_getUserOperationReceipt',\n [hash],\n );\n }\n\n /**\n * Submit a user operation to the bundler.\n *\n * @param userOperation - The signed user operation to submit.\n * @param entrypoint - The address of entrypoint to use for the user operation.\n * @returns The hash of the user operation.\n */\n async sendUserOperation(\n userOperation: UserOperation,\n entrypoint: string,\n ): Promise<string> {\n log('Sending user operation', {\n url: this.#url,\n userOperation,\n entrypoint,\n });\n\n const hash: string = await this.#query('eth_sendUserOperation', [\n userOperation,\n entrypoint,\n ]);\n\n log('Sent user operation', hash);\n\n return hash;\n }\n\n async #query<T>(method: string, params: unknown[]): Promise<T> {\n const request = {\n method: 'POST',\n headers: {\n Accept: 'application/json',\n 'Content-Type': 'application/json',\n },\n body: JSON.stringify({ jsonrpc: '2.0', id: 1, method, params }),\n };\n\n const response = await fetch(this.#url, request);\n const responseJson = await response.json();\n\n if (responseJson.error) {\n const error = new Error(responseJson.error.message || responseJson.error);\n\n (error as unknown as Record<string, string>).code =\n responseJson.error.code;\n\n throw error;\n }\n\n return responseJson.result;\n }\n}\n"]}
|
|
@@ -1,9 +1,7 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
import type {
|
|
4
|
-
import
|
|
5
|
-
import type { UserOperationMetadata } from "../types.cjs";
|
|
6
|
-
import type { UserOperationControllerMessenger } from "../UserOperationController.cjs";
|
|
1
|
+
import type { NetworkClient, NetworkClientId } from '@metamask/network-controller';
|
|
2
|
+
import EventEmitter from 'events';
|
|
3
|
+
import type { UserOperationMetadata } from '../types.js';
|
|
4
|
+
import type { UserOperationControllerMessenger } from '../UserOperationController.js';
|
|
7
5
|
type Events = {
|
|
8
6
|
'user-operation-confirmed': [metadata: UserOperationMetadata];
|
|
9
7
|
'user-operation-failed': [txMeta: UserOperationMetadata, error: Error];
|
|
@@ -19,12 +17,12 @@ type PendingUserOperationPollingInput = {
|
|
|
19
17
|
networkClientId: NetworkClientId;
|
|
20
18
|
};
|
|
21
19
|
declare const PendingUserOperationTracker_base: (abstract new (...args: any[]) => {
|
|
22
|
-
|
|
23
|
-
_getNetworkClientById(networkClientId:
|
|
20
|
+
_activeListeners: Record<string, (options: import("@metamask/utils").Json) => Promise<void>>;
|
|
21
|
+
_getNetworkClientById(networkClientId: NetworkClientId): NetworkClient | undefined;
|
|
24
22
|
_startPolling(input: PendingUserOperationPollingInput): void;
|
|
25
|
-
_stopPollingByPollingTokenSetId(key:
|
|
26
|
-
readonly
|
|
27
|
-
readonly
|
|
23
|
+
_stopPollingByPollingTokenSetId(key: import("@metamask/polling-controller").PollingTokenSetId): void;
|
|
24
|
+
readonly _pollingTokenSets: Map<import("@metamask/polling-controller").PollingTokenSetId, Set<string>>;
|
|
25
|
+
readonly _callbacks: Map<string, Set<(input: PendingUserOperationPollingInput) => void>>;
|
|
28
26
|
_executePoll(input: PendingUserOperationPollingInput): Promise<void>;
|
|
29
27
|
startPolling(input: PendingUserOperationPollingInput): string;
|
|
30
28
|
stopAllPolling(): void;
|
|
@@ -48,4 +46,4 @@ export declare class PendingUserOperationTracker extends PendingUserOperationTra
|
|
|
48
46
|
_getNetworkClientById(networkClientId: string): NetworkClient | undefined;
|
|
49
47
|
}
|
|
50
48
|
export {};
|
|
51
|
-
//# sourceMappingURL=PendingUserOperationTracker.d.
|
|
49
|
+
//# sourceMappingURL=PendingUserOperationTracker.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"PendingUserOperationTracker.d.ts","sourceRoot":"","sources":["../../src/helpers/PendingUserOperationTracker.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EACV,aAAa,EACb,eAAe,EAEhB,MAAM,8BAA8B,CAAC;AAKtC,OAAO,YAAY,MAAM,QAAQ,CAAC;AAIlC,OAAO,KAAK,EAAE,qBAAqB,EAAwB,MAAM,aAAa,CAAC;AAE/E,OAAO,KAAK,EAAE,gCAAgC,EAAE,MAAM,+BAA+B,CAAC;AAKtF,KAAK,MAAM,GAAG;IACZ,0BAA0B,EAAE,CAAC,QAAQ,EAAE,qBAAqB,CAAC,CAAC;IAC9D,uBAAuB,EAAE,CAAC,MAAM,EAAE,qBAAqB,EAAE,KAAK,EAAE,KAAK,CAAC,CAAC;IACvE,wBAAwB,EAAE,CAAC,MAAM,EAAE,qBAAqB,CAAC,CAAC;CAC3D,CAAC;AAEF,MAAM,MAAM,uCAAuC,GAAG,YAAY,GAAG;IACnE,EAAE,CAAC,CAAC,SAAS,MAAM,MAAM,EACvB,SAAS,EAAE,CAAC,EACZ,QAAQ,EAAE,CAAC,GAAG,IAAI,EAAE,MAAM,CAAC,CAAC,CAAC,KAAK,IAAI,GACrC,uCAAuC,CAAC;IAE3C,IAAI,CAAC,CAAC,SAAS,MAAM,MAAM,EACzB,SAAS,EAAE,CAAC,EACZ,QAAQ,EAAE,CAAC,GAAG,IAAI,EAAE,MAAM,CAAC,CAAC,CAAC,KAAK,IAAI,GACrC,uCAAuC,CAAC;IAE3C,IAAI,CAAC,CAAC,SAAS,MAAM,MAAM,EAAE,SAAS,EAAE,CAAC,EAAE,GAAG,IAAI,EAAE,MAAM,CAAC,CAAC,CAAC,GAAG,OAAO,CAAC;CACzE,CAAC;AAEF,6EAA6E;AAC7E,KAAK,gCAAgC,GAAG;IACtC,eAAe,EAAE,eAAe,CAAC;CAClC,CAAC;;;;;;;;;;;;;;;;AAEF;;;GAGG;AACH,qBAAa,2BAA4B,SAAQ,gCAAqE;;IACpH,GAAG,EAAE,uCAAuC,CAAC;IAM7C,YAAY,EACV,iBAAiB,EACjB,SAAS,GACV,EAAE;QACD,iBAAiB,EAAE,MAAM,qBAAqB,EAAE,CAAC;QACjD,SAAS,EAAE,gCAAgC,CAAC;KAC7C,EAOA;IAEK,YAAY,CAAC,EAAE,eAAe,EAAE,EAAE,gCAAgC,iBAevE;IAED,qBAAqB,CAAC,eAAe,EAAE,MAAM,GAAG,aAAa,GAAG,SAAS,CAKxE;CAkIF"}
|
|
@@ -10,23 +10,16 @@ var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (
|
|
|
10
10
|
return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
|
|
11
11
|
};
|
|
12
12
|
var _PendingUserOperationTracker_instances, _PendingUserOperationTracker_getUserOperations, _PendingUserOperationTracker_messenger, _PendingUserOperationTracker_checkUserOperations, _PendingUserOperationTracker_checkUserOperation, _PendingUserOperationTracker_onUserOperationConfirmed, _PendingUserOperationTracker_onUserOperationFailed, _PendingUserOperationTracker_getPendingUserOperations, _PendingUserOperationTracker_updateUserOperation, _PendingUserOperationTracker_getUserOperationReceipt, _PendingUserOperationTracker_normalizeGasValue;
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
}
|
|
17
|
-
return module;
|
|
18
|
-
}
|
|
19
|
-
import { query, toHex } from "@metamask/controller-utils";
|
|
20
|
-
import $EthQuery from "@metamask/eth-query";
|
|
21
|
-
const EthQuery = $importDefault($EthQuery);
|
|
22
|
-
import { createModuleLogger } from "@metamask/utils";
|
|
13
|
+
import { query, toHex } from '@metamask/controller-utils';
|
|
14
|
+
import EthQuery from '@metamask/eth-query';
|
|
15
|
+
import { createModuleLogger } from '@metamask/utils';
|
|
23
16
|
// This package purposefully relies on Node's EventEmitter module.
|
|
24
17
|
// eslint-disable-next-line import-x/no-nodejs-modules
|
|
25
|
-
import EventEmitter from
|
|
26
|
-
import { BlockTrackerPollingControllerOnly } from
|
|
27
|
-
import { projectLogger } from
|
|
28
|
-
import { UserOperationStatus } from
|
|
29
|
-
import { Bundler } from
|
|
18
|
+
import EventEmitter from 'events';
|
|
19
|
+
import { BlockTrackerPollingControllerOnly } from '../BlockTrackerPollingController.js';
|
|
20
|
+
import { projectLogger } from '../logger.js';
|
|
21
|
+
import { UserOperationStatus } from '../types.js';
|
|
22
|
+
import { Bundler } from './Bundler.js';
|
|
30
23
|
const log = createModuleLogger(projectLogger, 'pending-user-operations');
|
|
31
24
|
/**
|
|
32
25
|
* A helper class to periodically query the bundlers
|
|
@@ -124,4 +117,4 @@ _PendingUserOperationTracker_getUserOperations = new WeakMap(), _PendingUserOper
|
|
|
124
117
|
}
|
|
125
118
|
return gasValue;
|
|
126
119
|
};
|
|
127
|
-
//# sourceMappingURL=PendingUserOperationTracker.
|
|
120
|
+
//# sourceMappingURL=PendingUserOperationTracker.js.map
|
|
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AAI,CAAC,CAAC;AAC/C,CAAC,2GAEkB,QAAsB;IACvC,IAAI,OAAO,QAAQ,KAAK,QAAQ,EAAE,CAAC;QACjC,OAAO,KAAK,CAAC,QAAQ,CAAC,CAAC;IACzB,CAAC;IACD,OAAO,QAAQ,CAAC;AAClB,CAAC","sourcesContent":["import { query, toHex } from '@metamask/controller-utils';\nimport EthQuery from '@metamask/eth-query';\nimport type {\n NetworkClient,\n NetworkClientId,\n Provider,\n} from '@metamask/network-controller';\nimport { createModuleLogger } from '@metamask/utils';\nimport type { Hex } from '@metamask/utils';\n// This package purposefully relies on Node's EventEmitter module.\n// eslint-disable-next-line import-x/no-nodejs-modules\nimport EventEmitter from 'events';\n\nimport { BlockTrackerPollingControllerOnly } from '../BlockTrackerPollingController.js';\nimport { projectLogger } from '../logger.js';\nimport type { UserOperationMetadata, UserOperationReceipt } from '../types.js';\nimport { UserOperationStatus } from '../types.js';\nimport type { UserOperationControllerMessenger } from '../UserOperationController.js';\nimport { Bundler } from './Bundler.js';\n\nconst log = createModuleLogger(projectLogger, 'pending-user-operations');\n\ntype Events = {\n 'user-operation-confirmed': [metadata: UserOperationMetadata];\n 'user-operation-failed': [txMeta: UserOperationMetadata, error: Error];\n 'user-operation-updated': [txMeta: UserOperationMetadata];\n};\n\nexport type PendingUserOperationTrackerEventEmitter = EventEmitter & {\n on<T extends keyof Events>(\n eventName: T,\n listener: (...args: Events[T]) => void,\n ): PendingUserOperationTrackerEventEmitter;\n\n once<T extends keyof Events>(\n eventName: T,\n listener: (...args: Events[T]) => void,\n ): PendingUserOperationTrackerEventEmitter;\n\n emit<T extends keyof Events>(eventName: T, ...args: Events[T]): boolean;\n};\n\n/** The input to start polling for the {@link PendingUserOperationTracker} */\ntype PendingUserOperationPollingInput = {\n networkClientId: NetworkClientId;\n};\n\n/**\n * A helper class to periodically query the bundlers\n * and update the status of any submitted user operations.\n */\nexport class PendingUserOperationTracker extends BlockTrackerPollingControllerOnly<PendingUserOperationPollingInput>() {\n hub: PendingUserOperationTrackerEventEmitter;\n\n readonly #getUserOperations: () => UserOperationMetadata[];\n\n readonly #messenger: UserOperationControllerMessenger;\n\n constructor({\n getUserOperations,\n messenger,\n }: {\n getUserOperations: () => UserOperationMetadata[];\n messenger: UserOperationControllerMessenger;\n }) {\n super();\n\n this.hub = new EventEmitter() as PendingUserOperationTrackerEventEmitter;\n\n this.#getUserOperations = getUserOperations;\n this.#messenger = messenger;\n }\n\n async _executePoll({ networkClientId }: PendingUserOperationPollingInput) {\n try {\n const { blockTracker, configuration, provider } =\n this._getNetworkClientById(networkClientId) as NetworkClient;\n\n log('Polling', {\n blockNumber: blockTracker.getCurrentBlock(),\n chainId: configuration.chainId,\n });\n\n await this.#checkUserOperations(configuration.chainId, provider);\n } catch (error) {\n /* istanbul ignore next */\n log('Failed to check user operations', error);\n }\n }\n\n _getNetworkClientById(networkClientId: string): NetworkClient | undefined {\n return this.#messenger.call(\n 'NetworkController:getNetworkClientById',\n networkClientId,\n );\n }\n\n async #checkUserOperations(chainId: string, provider: Provider) {\n const pendingUserOperations = this.#getPendingUserOperations().filter(\n (metadata) => metadata.chainId === chainId,\n );\n\n if (!pendingUserOperations.length) {\n log('No pending user operations to check');\n return;\n }\n\n log('Found pending user operations to check', {\n count: pendingUserOperations.length,\n ids: pendingUserOperations.map((userOperation) => userOperation.id),\n });\n\n await Promise.all(\n pendingUserOperations.map((userOperation) =>\n this.#checkUserOperation(userOperation, provider),\n ),\n );\n }\n\n async #checkUserOperation(\n metadata: UserOperationMetadata,\n provider: Provider,\n ) {\n const { bundlerUrl, hash, id } = metadata;\n\n if (!hash || !bundlerUrl) {\n log('Skipping user operation as missing hash or bundler', id);\n return;\n }\n\n try {\n const receipt = await this.#getUserOperationReceipt(hash, bundlerUrl);\n const isSuccess = receipt?.success;\n\n if (receipt && !isSuccess) {\n this.#onUserOperationFailed(metadata, receipt);\n return;\n }\n\n if (isSuccess) {\n await this.#onUserOperationConfirmed(metadata, receipt, provider);\n return;\n }\n\n log('No receipt found for user operation', { id, hash });\n } catch (error) {\n log('Failed to check user operation', id, error);\n }\n }\n\n async #onUserOperationConfirmed(\n metadata: UserOperationMetadata,\n receipt: UserOperationReceipt,\n provider: Provider,\n ) {\n const { id } = metadata;\n\n const {\n actualGasCost,\n actualGasUsed,\n receipt: { blockHash, transactionHash },\n } = receipt;\n\n log('User operation confirmed', id, transactionHash);\n\n const { baseFeePerGas } = await query(\n new EthQuery(provider),\n 'getBlockByHash',\n [blockHash, false],\n );\n\n metadata.actualGasCost = this.#normalizeGasValue(actualGasCost);\n metadata.actualGasUsed = this.#normalizeGasValue(actualGasUsed);\n metadata.baseFeePerGas = baseFeePerGas;\n metadata.status = UserOperationStatus.Confirmed;\n metadata.transactionHash = transactionHash;\n\n this.#updateUserOperation(metadata);\n\n this.hub.emit('user-operation-confirmed', metadata);\n }\n\n #onUserOperationFailed(\n metadata: UserOperationMetadata,\n _receipt: UserOperationReceipt,\n ) {\n const { id } = metadata;\n\n log('User operation failed', id);\n\n metadata.status = UserOperationStatus.Failed;\n\n this.#updateUserOperation(metadata);\n\n this.hub.emit(\n 'user-operation-failed',\n metadata,\n new Error('User operation receipt has failed status'),\n );\n }\n\n #getPendingUserOperations(): UserOperationMetadata[] {\n return this.#getUserOperations().filter(\n (userOperation) => userOperation.status === UserOperationStatus.Submitted,\n );\n }\n\n #updateUserOperation(metadata: UserOperationMetadata) {\n this.hub.emit('user-operation-updated', metadata);\n }\n\n async #getUserOperationReceipt(\n hash: string,\n bundlerUrl: string,\n ): Promise<UserOperationReceipt | undefined> {\n const bundler = new Bundler(bundlerUrl);\n return bundler.getUserOperationReceipt(hash);\n }\n\n #normalizeGasValue(gasValue: Hex | number): string {\n if (typeof gasValue === 'number') {\n return toHex(gasValue);\n }\n return gasValue;\n }\n}\n"]}
|