@metamask-previews/user-operation-controller 41.2.9-preview-4f4c98e → 41.2.9-preview-eb263b0ee
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 +0 -4
- package/dist/BlockTrackerPollingController.cjs +68 -0
- package/dist/BlockTrackerPollingController.cjs.map +1 -0
- package/dist/{BlockTrackerPollingController.d.ts → BlockTrackerPollingController.d.cts} +11 -11
- package/dist/BlockTrackerPollingController.d.cts.map +1 -0
- package/dist/BlockTrackerPollingController.d.mts +41 -0
- package/dist/BlockTrackerPollingController.d.mts.map +1 -0
- package/dist/{BlockTrackerPollingController.js → BlockTrackerPollingController.mjs} +16 -17
- package/dist/BlockTrackerPollingController.mjs.map +1 -0
- package/dist/UserOperationController-method-action-types.cjs +7 -0
- package/dist/UserOperationController-method-action-types.cjs.map +1 -0
- package/dist/{UserOperationController-method-action-types.d.ts → UserOperationController-method-action-types.d.cts} +2 -2
- package/dist/UserOperationController-method-action-types.d.cts.map +1 -0
- package/dist/UserOperationController-method-action-types.d.mts +57 -0
- package/dist/UserOperationController-method-action-types.d.mts.map +1 -0
- package/dist/{UserOperationController-method-action-types.js → UserOperationController-method-action-types.mjs} +1 -1
- package/dist/UserOperationController-method-action-types.mjs.map +1 -0
- package/dist/UserOperationController.cjs +495 -0
- package/dist/UserOperationController.cjs.map +1 -0
- package/dist/{UserOperationController.d.ts → UserOperationController.d.cts} +15 -13
- package/dist/UserOperationController.d.cts.map +1 -0
- package/dist/UserOperationController.d.mts +136 -0
- package/dist/UserOperationController.d.mts.map +1 -0
- package/dist/{UserOperationController.js → UserOperationController.mjs} +20 -19
- package/dist/UserOperationController.mjs.map +1 -0
- package/dist/constants.cjs +7 -0
- package/dist/constants.cjs.map +1 -0
- package/dist/{constants.d.ts → constants.d.cts} +1 -1
- package/dist/constants.d.cts.map +1 -0
- package/dist/constants.d.mts +4 -0
- package/dist/constants.d.mts.map +1 -0
- package/dist/{constants.js → constants.mjs} +1 -1
- package/dist/constants.mjs.map +1 -0
- package/dist/helpers/Bundler.cjs +91 -0
- package/dist/helpers/Bundler.cjs.map +1 -0
- package/dist/helpers/{Bundler.d.ts → Bundler.d.cts} +2 -2
- package/dist/helpers/Bundler.d.cts.map +1 -0
- package/dist/helpers/Bundler.d.mts +46 -0
- package/dist/helpers/Bundler.d.mts.map +1 -0
- package/dist/helpers/{Bundler.js → Bundler.mjs} +2 -2
- package/dist/helpers/Bundler.mjs.map +1 -0
- package/dist/helpers/PendingUserOperationTracker.cjs +127 -0
- package/dist/helpers/PendingUserOperationTracker.cjs.map +1 -0
- package/dist/helpers/{PendingUserOperationTracker.d.ts → PendingUserOperationTracker.d.cts} +12 -10
- package/dist/helpers/PendingUserOperationTracker.d.cts.map +1 -0
- package/dist/helpers/PendingUserOperationTracker.d.mts +51 -0
- package/dist/helpers/PendingUserOperationTracker.d.mts.map +1 -0
- package/dist/helpers/{PendingUserOperationTracker.js → PendingUserOperationTracker.mjs} +16 -9
- package/dist/helpers/PendingUserOperationTracker.mjs.map +1 -0
- package/dist/helpers/SnapSmartContractAccount.cjs +64 -0
- package/dist/helpers/SnapSmartContractAccount.cjs.map +1 -0
- package/dist/helpers/{SnapSmartContractAccount.d.ts → SnapSmartContractAccount.d.cts} +3 -3
- package/dist/helpers/SnapSmartContractAccount.d.cts.map +1 -0
- package/dist/helpers/SnapSmartContractAccount.d.mts +10 -0
- package/dist/helpers/SnapSmartContractAccount.d.mts.map +1 -0
- package/dist/helpers/{SnapSmartContractAccount.js → SnapSmartContractAccount.mjs} +3 -3
- package/dist/helpers/SnapSmartContractAccount.mjs.map +1 -0
- package/dist/index.cjs +19 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +4 -0
- package/dist/index.d.cts.map +1 -0
- package/dist/index.d.mts +4 -0
- package/dist/index.d.mts.map +1 -0
- package/dist/index.mjs +3 -0
- package/dist/index.mjs.map +1 -0
- package/dist/logger.cjs +8 -0
- package/dist/logger.cjs.map +1 -0
- package/dist/logger.d.cts +5 -0
- package/dist/logger.d.cts.map +1 -0
- package/dist/logger.d.mts +5 -0
- package/dist/logger.d.mts.map +1 -0
- package/dist/{logger.js → logger.mjs} +2 -2
- package/dist/logger.mjs.map +1 -0
- package/dist/types.cjs +16 -0
- package/dist/types.cjs.map +1 -0
- package/dist/{types.d.ts → types.d.cts} +3 -3
- package/dist/types.d.cts.map +1 -0
- package/dist/types.d.mts +294 -0
- package/dist/types.d.mts.map +1 -0
- package/dist/{types.js → types.mjs} +1 -1
- package/dist/types.mjs.map +1 -0
- package/dist/utils/chain-id.cjs +17 -0
- package/dist/utils/chain-id.cjs.map +1 -0
- package/dist/utils/{chain-id.d.ts → chain-id.d.cts} +1 -1
- package/dist/utils/chain-id.d.cts.map +1 -0
- package/dist/utils/chain-id.d.mts +8 -0
- package/dist/utils/chain-id.d.mts.map +1 -0
- package/dist/utils/{chain-id.js → chain-id.mjs} +1 -1
- package/dist/utils/chain-id.mjs.map +1 -0
- package/dist/utils/gas-fees.cjs +194 -0
- package/dist/utils/gas-fees.cjs.map +1 -0
- package/dist/utils/{gas-fees.d.ts → gas-fees.d.cts} +6 -6
- package/dist/utils/gas-fees.d.cts.map +1 -0
- package/dist/utils/gas-fees.d.mts +24 -0
- package/dist/utils/gas-fees.d.mts.map +1 -0
- package/dist/utils/{gas-fees.js → gas-fees.mjs} +15 -8
- package/dist/utils/gas-fees.mjs.map +1 -0
- package/dist/utils/gas.cjs +72 -0
- package/dist/utils/gas.cjs.map +1 -0
- package/dist/utils/{gas.d.ts → gas.d.cts} +2 -2
- package/dist/utils/gas.d.cts.map +1 -0
- package/dist/utils/gas.d.mts +10 -0
- package/dist/utils/gas.d.mts.map +1 -0
- package/dist/utils/{gas.js → gas.mjs} +14 -7
- package/dist/utils/gas.mjs.map +1 -0
- package/dist/utils/transaction.cjs +117 -0
- package/dist/utils/transaction.cjs.map +1 -0
- package/dist/utils/{transaction.d.ts → transaction.d.cts} +3 -3
- package/dist/utils/transaction.d.cts.map +1 -0
- package/dist/utils/transaction.d.mts +10 -0
- package/dist/utils/transaction.d.mts.map +1 -0
- package/dist/utils/{transaction.js → transaction.mjs} +13 -6
- package/dist/utils/transaction.mjs.map +1 -0
- package/dist/utils/validation.cjs +162 -0
- package/dist/utils/validation.cjs.map +1 -0
- package/dist/utils/{validation.d.ts → validation.d.cts} +3 -3
- package/dist/utils/validation.d.cts.map +1 -0
- package/dist/utils/validation.d.mts +33 -0
- package/dist/utils/validation.d.mts.map +1 -0
- package/dist/utils/{validation.js → validation.mjs} +5 -5
- package/dist/utils/validation.mjs.map +1 -0
- package/package.json +17 -13
- package/dist/BlockTrackerPollingController.d.ts.map +0 -1
- package/dist/BlockTrackerPollingController.js.map +0 -1
- package/dist/UserOperationController-method-action-types.d.ts.map +0 -1
- package/dist/UserOperationController-method-action-types.js.map +0 -1
- package/dist/UserOperationController.d.ts.map +0 -1
- package/dist/UserOperationController.js.map +0 -1
- package/dist/constants.d.ts.map +0 -1
- package/dist/constants.js.map +0 -1
- package/dist/helpers/Bundler.d.ts.map +0 -1
- package/dist/helpers/Bundler.js.map +0 -1
- package/dist/helpers/PendingUserOperationTracker.d.ts.map +0 -1
- package/dist/helpers/PendingUserOperationTracker.js.map +0 -1
- package/dist/helpers/SnapSmartContractAccount.d.ts.map +0 -1
- package/dist/helpers/SnapSmartContractAccount.js.map +0 -1
- package/dist/index.d.ts +0 -4
- package/dist/index.d.ts.map +0 -1
- package/dist/index.js +0 -3
- package/dist/index.js.map +0 -1
- package/dist/logger.d.ts +0 -4
- package/dist/logger.d.ts.map +0 -1
- package/dist/logger.js.map +0 -1
- package/dist/types.d.ts.map +0 -1
- package/dist/types.js.map +0 -1
- package/dist/utils/chain-id.d.ts.map +0 -1
- package/dist/utils/chain-id.js.map +0 -1
- package/dist/utils/gas-fees.d.ts.map +0 -1
- package/dist/utils/gas-fees.js.map +0 -1
- package/dist/utils/gas.d.ts.map +0 -1
- package/dist/utils/gas.js.map +0 -1
- package/dist/utils/transaction.d.ts.map +0 -1
- package/dist/utils/transaction.js.map +0 -1
- package/dist/utils/validation.d.ts.map +0 -1
- package/dist/utils/validation.js.map +0 -1
|
@@ -0,0 +1,136 @@
|
|
|
1
|
+
/// <reference types="node" />
|
|
2
|
+
/// <reference types="npm-which/node_modules/@types/node/events.js" />
|
|
3
|
+
import type { ApprovalControllerAddRequestAction } from "@metamask/approval-controller";
|
|
4
|
+
import { BaseController } from "@metamask/base-controller";
|
|
5
|
+
import type { ControllerGetStateAction, ControllerStateChangeEvent } from "@metamask/base-controller";
|
|
6
|
+
import type { GasFeeState } from "@metamask/gas-fee-controller";
|
|
7
|
+
import type { KeyringControllerPrepareUserOperationAction, KeyringControllerPatchUserOperationAction, KeyringControllerSignUserOperationAction } from "@metamask/keyring-controller";
|
|
8
|
+
import type { Messenger } from "@metamask/messenger";
|
|
9
|
+
import type { NetworkControllerGetNetworkClientByIdAction } from "@metamask/network-controller";
|
|
10
|
+
import { TransactionType } from "@metamask/transaction-controller";
|
|
11
|
+
import type { TransactionMeta, TransactionParams } from "@metamask/transaction-controller";
|
|
12
|
+
import EventEmitter from "events";
|
|
13
|
+
import type { SmartContractAccount, UserOperationMetadata } from "./types.mjs";
|
|
14
|
+
import type { UserOperationControllerMethodActions } from "./UserOperationController-method-action-types.mjs";
|
|
15
|
+
declare const controllerName = "UserOperationController";
|
|
16
|
+
type Events = {
|
|
17
|
+
'transaction-updated': [metadata: TransactionMeta];
|
|
18
|
+
'user-operation-added': [metadata: UserOperationMetadata];
|
|
19
|
+
'user-operation-confirmed': [metadata: UserOperationMetadata];
|
|
20
|
+
'user-operation-failed': [metadata: UserOperationMetadata, error: Error];
|
|
21
|
+
[key: `${string}:confirmed`]: [metadata: UserOperationMetadata];
|
|
22
|
+
[key: `${string}:failed`]: [metadata: UserOperationMetadata, error: Error];
|
|
23
|
+
};
|
|
24
|
+
export type UserOperationControllerEventEmitter = EventEmitter & {
|
|
25
|
+
on<T extends keyof Events>(eventName: T, listener: (...args: Events[T]) => void): UserOperationControllerEventEmitter;
|
|
26
|
+
once<T extends keyof Events>(eventName: T, listener: (...args: Events[T]) => void): UserOperationControllerEventEmitter;
|
|
27
|
+
emit<T extends keyof Events>(eventName: T, ...args: Events[T]): boolean;
|
|
28
|
+
};
|
|
29
|
+
export type UserOperationControllerState = {
|
|
30
|
+
userOperations: Record<string, UserOperationMetadata>;
|
|
31
|
+
};
|
|
32
|
+
export type GetUserOperationState = ControllerGetStateAction<typeof controllerName, UserOperationControllerState>;
|
|
33
|
+
export type UserOperationStateChange = ControllerStateChangeEvent<typeof controllerName, UserOperationControllerState>;
|
|
34
|
+
export type UserOperationControllerActions = GetUserOperationState | UserOperationControllerMethodActions | NetworkControllerGetNetworkClientByIdAction | ApprovalControllerAddRequestAction | KeyringControllerPrepareUserOperationAction | KeyringControllerPatchUserOperationAction | KeyringControllerSignUserOperationAction;
|
|
35
|
+
export type UserOperationControllerEvents = UserOperationStateChange;
|
|
36
|
+
export type UserOperationControllerMessenger = Messenger<typeof controllerName, UserOperationControllerActions, UserOperationControllerEvents>;
|
|
37
|
+
export type UserOperationControllerOptions = {
|
|
38
|
+
entrypoint: string;
|
|
39
|
+
getGasFeeEstimates: () => Promise<GasFeeState>;
|
|
40
|
+
interval?: number;
|
|
41
|
+
messenger: UserOperationControllerMessenger;
|
|
42
|
+
state?: Partial<UserOperationControllerState>;
|
|
43
|
+
};
|
|
44
|
+
export type AddUserOperationRequest = {
|
|
45
|
+
data?: string;
|
|
46
|
+
from: string;
|
|
47
|
+
maxFeePerGas?: string;
|
|
48
|
+
maxPriorityFeePerGas?: string;
|
|
49
|
+
to?: string;
|
|
50
|
+
value?: string;
|
|
51
|
+
};
|
|
52
|
+
export type AddUserOperationSwapOptions = {
|
|
53
|
+
approvalTxId?: string;
|
|
54
|
+
destinationTokenAddress?: string;
|
|
55
|
+
destinationTokenAmount?: string;
|
|
56
|
+
destinationTokenDecimals?: number;
|
|
57
|
+
destinationTokenSymbol?: string;
|
|
58
|
+
estimatedBaseFee?: string;
|
|
59
|
+
sourceTokenAddress?: string;
|
|
60
|
+
sourceTokenAmount?: string;
|
|
61
|
+
sourceTokenDecimals?: number;
|
|
62
|
+
sourceTokenSymbol?: string;
|
|
63
|
+
swapAndSendRecipient?: string;
|
|
64
|
+
swapMetaData?: Record<string, unknown>;
|
|
65
|
+
swapTokenValue?: string;
|
|
66
|
+
};
|
|
67
|
+
export type AddUserOperationOptions = {
|
|
68
|
+
networkClientId: string;
|
|
69
|
+
origin: string;
|
|
70
|
+
requireApproval?: boolean;
|
|
71
|
+
smartContractAccount?: SmartContractAccount;
|
|
72
|
+
swaps?: AddUserOperationSwapOptions;
|
|
73
|
+
type?: TransactionType;
|
|
74
|
+
};
|
|
75
|
+
export type AddUserOperationResponse = {
|
|
76
|
+
id: string;
|
|
77
|
+
hash: () => Promise<string | undefined>;
|
|
78
|
+
transactionHash: () => Promise<string | undefined>;
|
|
79
|
+
};
|
|
80
|
+
/**
|
|
81
|
+
* Controller for creating and managing the life cycle of user operations.
|
|
82
|
+
*/
|
|
83
|
+
export declare class UserOperationController extends BaseController<typeof controllerName, UserOperationControllerState, UserOperationControllerMessenger> {
|
|
84
|
+
#private;
|
|
85
|
+
hub: UserOperationControllerEventEmitter;
|
|
86
|
+
/**
|
|
87
|
+
* Construct a UserOperationController instance.
|
|
88
|
+
*
|
|
89
|
+
* @param options - Controller options.
|
|
90
|
+
* @param options.entrypoint - Address of the entrypoint contract.
|
|
91
|
+
* @param options.getGasFeeEstimates - Callback to get gas fee estimates.
|
|
92
|
+
* @param options.messenger - Restricted messenger for the user operation controller.
|
|
93
|
+
* @param options.state - Initial state to set on the controller.
|
|
94
|
+
*/
|
|
95
|
+
constructor({ entrypoint, getGasFeeEstimates, messenger, state, }: UserOperationControllerOptions);
|
|
96
|
+
/**
|
|
97
|
+
* Create and submit a user operation.
|
|
98
|
+
*
|
|
99
|
+
* @param request - Information required to create a user operation.
|
|
100
|
+
* @param request.data - Data to include in the resulting transaction.
|
|
101
|
+
* @param request.maxFeePerGas - Maximum fee per gas to pay towards the transaction.
|
|
102
|
+
* @param request.maxPriorityFeePerGas - Maximum priority fee per gas to pay towards the transaction.
|
|
103
|
+
* @param request.to - Destination address of the resulting transaction.
|
|
104
|
+
* @param request.value - Value to include in the resulting transaction.
|
|
105
|
+
* @param options - Configuration options when creating a user operation.
|
|
106
|
+
* @param options.networkClientId - ID of the network client used to query the chain.
|
|
107
|
+
* @param options.origin - Origin of the user operation, such as the hostname of a dApp.
|
|
108
|
+
* @param options.requireApproval - Whether to require user approval before submitting the user operation. Defaults to true.
|
|
109
|
+
* @param options.smartContractAccount - Smart contract abstraction to provide the contract specific values such as call data and nonce. Defaults to the current snap account.
|
|
110
|
+
* @param options.swaps - Swap metadata to record with the user operation.
|
|
111
|
+
* @param options.type - Type of the transaction.
|
|
112
|
+
*/
|
|
113
|
+
addUserOperation(request: AddUserOperationRequest, options: AddUserOperationOptions): Promise<AddUserOperationResponse>;
|
|
114
|
+
/**
|
|
115
|
+
* Create and submit a user operation equivalent to the provided transaction.
|
|
116
|
+
*
|
|
117
|
+
* @param transaction - Transaction to use as the basis for the user operation.
|
|
118
|
+
* @param options - Configuration options when creating a user operation.
|
|
119
|
+
* @param options.networkClientId - ID of the network client used to query the chain.
|
|
120
|
+
* @param options.origin - Origin of the user operation, such as the hostname of a dApp.
|
|
121
|
+
* @param options.requireApproval - Whether to require user approval before submitting the user operation. Defaults to true.
|
|
122
|
+
* @param options.smartContractAccount - Smart contract abstraction to provide the contract specific values such as call data and nonce. Defaults to the current snap account.
|
|
123
|
+
* @param options.swaps - Swap metadata to record with the user operation.
|
|
124
|
+
* @param options.type - Type of the transaction.
|
|
125
|
+
*/
|
|
126
|
+
addUserOperationFromTransaction(transaction: TransactionParams, options: AddUserOperationOptions): Promise<AddUserOperationResponse>;
|
|
127
|
+
/**
|
|
128
|
+
* Starts polling for pending user operations on the given network.
|
|
129
|
+
*
|
|
130
|
+
* @param networkClientId - The ID of the network client to poll.
|
|
131
|
+
* @returns The polling token that can be used to stop polling.
|
|
132
|
+
*/
|
|
133
|
+
startPollingByNetworkClientId(networkClientId: string): string;
|
|
134
|
+
}
|
|
135
|
+
export {};
|
|
136
|
+
//# sourceMappingURL=UserOperationController.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"UserOperationController.d.mts","sourceRoot":"","sources":["../src/UserOperationController.ts"],"names":[],"mappings":";;AAAA,OAAO,KAAK,EAEV,kCAAkC,EAEnC,sCAAsC;AACvC,OAAO,EAAE,cAAc,EAAE,kCAAkC;AAC3D,OAAO,KAAK,EACV,wBAAwB,EACxB,0BAA0B,EAC3B,kCAAkC;AAEnC,OAAO,KAAK,EAAE,WAAW,EAAE,qCAAqC;AAChE,OAAO,KAAK,EACV,2CAA2C,EAC3C,yCAAyC,EACzC,wCAAwC,EACzC,qCAAqC;AACtC,OAAO,KAAK,EAAE,SAAS,EAAE,4BAA4B;AACrD,OAAO,KAAK,EACV,2CAA2C,EAE5C,qCAAqC;AAEtC,OAAO,EAAE,eAAe,EAAE,yCAAyC;AACnE,OAAO,KAAK,EACV,eAAe,EACf,iBAAiB,EAClB,yCAAyC;AAI1C,OAAO,YAAY,eAAe;AASlC,OAAO,KAAK,EACV,oBAAoB,EAEpB,qBAAqB,EACtB,oBAAmB;AAEpB,OAAO,KAAK,EAAE,oCAAoC,EAAE,0DAAyD;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,CAAC;IAC1D,0BAA0B,EAAE,CAAC,QAAQ,EAAE,qBAAqB,CAAC,CAAC;IAC9D,uBAAuB,EAAE,CAAC,QAAQ,EAAE,qBAAqB,EAAE,KAAK,EAAE,KAAK,CAAC,CAAC;IACzE,CAAC,GAAG,EA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CAAC;IACf,eAAe,CAAC,EAAE,OAAO,CAAC;IAC1B,oBAAoB,CAAC,EAAE,oBAAoB,CAAC;IAC5C,KAAK,CAAC,EAAE,2BAA2B,CAAC;IACpC,IAAI,CAAC,EAAE,eAAe,CAAC;CACxB,CAAC;AAEF,MAAM,MAAM,wBAAwB,GAAG;IACrC,EAAE,EAAE,MAAM,CAAC;IACX,IAAI,EAAE,MAAM,OAAO,CAAC,MAAM,GAAG,SAAS,CAAC,CAAC;IACxC,eAAe,EAAE,MAAM,OAAO,CAAC,MAAM,GAAG,SAAS,CAAC,CAAC;CACpD,CAAC;AAkBF;;GAEG;AACH,qBAAa,uBAAwB,SAAQ,cAAc,CACzD,OAAO,cAAc,EACrB,4BAA4B,EAC5B,gCAAgC,CACjC;;IACC,GAAG,EAAE,mCAAmC,CAAC;IAQzC;;;;;;;;OAQG;gBACS,EACV,UAAU,EACV,kBAAkB,EAClB,SAAS,EACT,KAAK,GACN,EAAE,8BAA8B;IA2BjC;;;;;;;;;;;;;;;;OAgBG;IACG,gBAAgB,CACpB,OAAO,EAAE,uBAAuB,EAChC,OAAO,EAAE,uBAAuB,GAC/B,OAAO,CAAC,wBAAwB,CAAC;IAOpC;;;;;;;;;;;OAWG;IACG,+BAA+B,CACnC,WAAW,EAAE,iBAAiB,EAC9B,OAAO,EAAE,uBAAuB,GAC/B,OAAO,CAAC,wBAAwB,CAAC;IAoBpC;;;;;OAKG;IACH,6BAA6B,CAAC,eAAe,EAAE,MAAM,GAAG,MAAM;CAqjB/D"}
|
|
@@ -10,26 +10,27 @@ 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 _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 {
|
|
20
|
+
import EventEmitter from "events";
|
|
21
|
+
import $lodash from "lodash";
|
|
22
|
+
const { cloneDeep } = $lodash;
|
|
23
|
+
import { v1 as random } from "uuid";
|
|
24
|
+
import { ADDRESS_ZERO, EMPTY_BYTES, VALUE_ZERO } from "./constants.mjs";
|
|
25
|
+
import { Bundler } from "./helpers/Bundler.mjs";
|
|
26
|
+
import { PendingUserOperationTracker } from "./helpers/PendingUserOperationTracker.mjs";
|
|
27
|
+
import { SnapSmartContractAccount } from "./helpers/SnapSmartContractAccount.mjs";
|
|
28
|
+
import { projectLogger as log } from "./logger.mjs";
|
|
29
|
+
import { UserOperationStatus } from "./types.mjs";
|
|
30
|
+
import { updateGasFees } from "./utils/gas-fees.mjs";
|
|
31
|
+
import { updateGas } from "./utils/gas.mjs";
|
|
32
|
+
import { getTransactionMetadata } from "./utils/transaction.mjs";
|
|
33
|
+
import { validateAddUserOperationOptions, validateAddUserOperationRequest, validatePrepareUserOperationResponse, validateSignUserOperationResponse, validateUpdateUserOperationResponse } from "./utils/validation.mjs";
|
|
33
34
|
const controllerName = 'UserOperationController';
|
|
34
35
|
const MESSENGER_EXPOSED_METHODS = [
|
|
35
36
|
'addUserOperation',
|
|
@@ -485,4 +486,4 @@ _UserOperationController_entrypoint = new WeakMap(), _UserOperationController_ge
|
|
|
485
486
|
await __classPrivateFieldGet(this, _UserOperationController_instances, "m", _UserOperationController_addPaymasterData).call(this, metadata, smartContractAccount);
|
|
486
487
|
log('Regenerated user operation', metadata.userOperation);
|
|
487
488
|
};
|
|
488
|
-
//# sourceMappingURL=UserOperationController.
|
|
489
|
+
//# sourceMappingURL=UserOperationController.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"UserOperationController.mjs","sourceRoot":"","sources":["../src/UserOperationController.ts"],"names":[],"mappings":";;;;;;;;;;;;AAKA,OAAO,EAAE,cAAc,EAAE,kCAAkC;AAK3D,OAAO,EAAE,YAAY,EAAE,mCAAmC;AAY1D,OAAO,EAAE,UAAU,EAAE,6BAA6B;AAClD,OAAO,EAAE,eAAe,EAAE,yCAAyC;AAKnE,OAAO,EAAE,KAAK,EAAE,wBAAwB;AACxC,kEAAkE;AAClE,sDAAsD;AACtD,OAAO,YAAY,eAAe;;;AAElC,OAAO,EAAE,EAAE,IAAI,MAAM,EAAE,aAAa;AAEpC,OAAO,EAAE,YAAY,EAAE,WAAW,EAAE,UAAU,EAAE,wBAAuB;AACvE,O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,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';\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,7 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.VALUE_ZERO = exports.ADDRESS_ZERO = exports.EMPTY_BYTES = void 0;
|
|
4
|
+
exports.EMPTY_BYTES = '0x';
|
|
5
|
+
exports.ADDRESS_ZERO = '0x0000000000000000000000000000000000000000';
|
|
6
|
+
exports.VALUE_ZERO = '0x0';
|
|
7
|
+
//# sourceMappingURL=constants.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"constants.cjs","sourceRoot":"","sources":["../src/constants.ts"],"names":[],"mappings":";;;AAAa,QAAA,WAAW,GAAG,IAAI,CAAC;AACnB,QAAA,YAAY,GAAG,4CAA4C,CAAC;AAC5D,QAAA,UAAU,GAAG,KAAK,CAAC","sourcesContent":["export const EMPTY_BYTES = '0x';\nexport const ADDRESS_ZERO = '0x0000000000000000000000000000000000000000';\nexport const VALUE_ZERO = '0x0';\n"]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"constants.d.cts","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.d.mts","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.mjs","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"]}
|
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function (receiver, state, value, kind, f) {
|
|
3
|
+
if (kind === "m") throw new TypeError("Private method is not writable");
|
|
4
|
+
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter");
|
|
5
|
+
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot write private member to an object whose class did not declare it");
|
|
6
|
+
return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
|
|
7
|
+
};
|
|
8
|
+
var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) {
|
|
9
|
+
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
|
|
10
|
+
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");
|
|
11
|
+
return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
|
|
12
|
+
};
|
|
13
|
+
var _Bundler_instances, _Bundler_url, _Bundler_query;
|
|
14
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
|
+
exports.Bundler = void 0;
|
|
16
|
+
const logger_js_1 = require("../logger.cjs");
|
|
17
|
+
const log = (0, logger_js_1.createModuleLogger)(logger_js_1.projectLogger, 'bundler');
|
|
18
|
+
/**
|
|
19
|
+
* A helper class for interacting with a bundler.
|
|
20
|
+
*/
|
|
21
|
+
class Bundler {
|
|
22
|
+
constructor(url) {
|
|
23
|
+
_Bundler_instances.add(this);
|
|
24
|
+
_Bundler_url.set(this, void 0);
|
|
25
|
+
__classPrivateFieldSet(this, _Bundler_url, url, "f");
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* Estimate the gas required to execute a user operation.
|
|
29
|
+
*
|
|
30
|
+
* @param userOperation - The user operation to estimate gas for.
|
|
31
|
+
* @param entrypoint - The address of entrypoint to use for the user operation.
|
|
32
|
+
* @returns The estimated gas limits for the user operation.
|
|
33
|
+
*/
|
|
34
|
+
async estimateUserOperationGas(userOperation, entrypoint) {
|
|
35
|
+
log('Estimating gas', { url: __classPrivateFieldGet(this, _Bundler_url, "f"), userOperation, entrypoint });
|
|
36
|
+
const response = await __classPrivateFieldGet(this, _Bundler_instances, "m", _Bundler_query).call(this, 'eth_estimateUserOperationGas', [userOperation, entrypoint]);
|
|
37
|
+
log('Estimated gas', { response });
|
|
38
|
+
return response;
|
|
39
|
+
}
|
|
40
|
+
/**
|
|
41
|
+
* Retrieve the receipt for a user operation.
|
|
42
|
+
*
|
|
43
|
+
* @param hash - The hash of the user operation.
|
|
44
|
+
* @returns The receipt for the user operation, or `undefined` if the user operation is pending.
|
|
45
|
+
*/
|
|
46
|
+
async getUserOperationReceipt(hash) {
|
|
47
|
+
log('Getting user operation receipt', { url: __classPrivateFieldGet(this, _Bundler_url, "f"), hash });
|
|
48
|
+
return await __classPrivateFieldGet(this, _Bundler_instances, "m", _Bundler_query).call(this, 'eth_getUserOperationReceipt', [hash]);
|
|
49
|
+
}
|
|
50
|
+
/**
|
|
51
|
+
* Submit a user operation to the bundler.
|
|
52
|
+
*
|
|
53
|
+
* @param userOperation - The signed user operation to submit.
|
|
54
|
+
* @param entrypoint - The address of entrypoint to use for the user operation.
|
|
55
|
+
* @returns The hash of the user operation.
|
|
56
|
+
*/
|
|
57
|
+
async sendUserOperation(userOperation, entrypoint) {
|
|
58
|
+
log('Sending user operation', {
|
|
59
|
+
url: __classPrivateFieldGet(this, _Bundler_url, "f"),
|
|
60
|
+
userOperation,
|
|
61
|
+
entrypoint,
|
|
62
|
+
});
|
|
63
|
+
const hash = await __classPrivateFieldGet(this, _Bundler_instances, "m", _Bundler_query).call(this, 'eth_sendUserOperation', [
|
|
64
|
+
userOperation,
|
|
65
|
+
entrypoint,
|
|
66
|
+
]);
|
|
67
|
+
log('Sent user operation', hash);
|
|
68
|
+
return hash;
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
exports.Bundler = Bundler;
|
|
72
|
+
_Bundler_url = new WeakMap(), _Bundler_instances = new WeakSet(), _Bundler_query = async function _Bundler_query(method, params) {
|
|
73
|
+
const request = {
|
|
74
|
+
method: 'POST',
|
|
75
|
+
headers: {
|
|
76
|
+
Accept: 'application/json',
|
|
77
|
+
'Content-Type': 'application/json',
|
|
78
|
+
},
|
|
79
|
+
body: JSON.stringify({ jsonrpc: '2.0', id: 1, method, params }),
|
|
80
|
+
};
|
|
81
|
+
const response = await fetch(__classPrivateFieldGet(this, _Bundler_url, "f"), request);
|
|
82
|
+
const responseJson = await response.json();
|
|
83
|
+
if (responseJson.error) {
|
|
84
|
+
const error = new Error(responseJson.error.message || responseJson.error);
|
|
85
|
+
error.code =
|
|
86
|
+
responseJson.error.code;
|
|
87
|
+
throw error;
|
|
88
|
+
}
|
|
89
|
+
return responseJson.result;
|
|
90
|
+
};
|
|
91
|
+
//# sourceMappingURL=Bundler.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Bundler.cjs","sourceRoot":"","sources":["../../src/helpers/Bundler.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;AAAA,6CAAiE;AAGjE,MAAM,GAAG,GAAG,IAAA,8BAAkB,EAAC,yBAAa,EAAE,SAAS,CAAC,CAAC;AAoBzD;;GAEG;AACH,MAAa,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,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AI,EAAE,CAAC;IAE3C,IAAI,YAAY,CAAC,KAAK,EAAE,CAAC;QACvB,MAAM,KAAK,GAAG,IAAI,KAAK,CAAC,YAAY,CAAC,KAAK,CAAC,OAAO,IAAI,YAAY,CAAC,KAAK,CAAC,CAAC;QAEzE,KAA2C,CAAC,IAAI;YAC/C,YAAY,CAAC,KAAK,CAAC,IAAI,CAAC;QAE1B,MAAM,KAAK,CAAC;IACd,CAAC;IAED,OAAO,YAAY,CAAC,MAAM,CAAC;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,4 +1,4 @@
|
|
|
1
|
-
import type { UserOperation, UserOperationReceipt } from
|
|
1
|
+
import type { UserOperation, UserOperationReceipt } from "../types.cjs";
|
|
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.cts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Bundler.d.cts","sourceRoot":"","sources":["../../src/helpers/Bundler.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,aAAa,EAAE,oBAAoB,EAAE,qBAAoB;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;;gBAGN,GAAG,EAAE,MAAM;IAIvB;;;;;;OAMG;IACG,wBAAwB,CAC5B,aAAa,EAAE,aAAa,EAC5B,UAAU,EAAE,MAAM,GACjB,OAAO,CAAC,uCAAuC,CAAC;IAanD;;;;;OAKG;IACG,uBAAuB,CAC3B,IAAI,CAAC,EAAE,MAAM,GACZ,OAAO,CAAC,oBAAoB,GAAG,SAAS,CAAC;IAS5C;;;;;;OAMG;IACG,iBAAiB,CACrB,aAAa,EAAE,aAAa,EAC5B,UAAU,EAAE,MAAM,GACjB,OAAO,CAAC,MAAM,CAAC;CAyCnB"}
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import type { UserOperation, UserOperationReceipt } from "../types.mjs";
|
|
2
|
+
/**
|
|
3
|
+
* Response from the `eth_estimateUserOperationGas` bundler method.
|
|
4
|
+
* Includes the estimated gas limits required by a user operation.
|
|
5
|
+
*/
|
|
6
|
+
export type BundlerEstimateUserOperationGasResponse = {
|
|
7
|
+
/** Estimated gas required to compensate the bundler for any pre-verification. */
|
|
8
|
+
preVerificationGas: number | string;
|
|
9
|
+
/** Estimated gas required to verify the user operation. */
|
|
10
|
+
verificationGas?: number | string;
|
|
11
|
+
/** Estimated gas required to verify the user operation. */
|
|
12
|
+
verificationGasLimit?: number | string;
|
|
13
|
+
/** Estimated gas required for the execution of the user operation. */
|
|
14
|
+
callGasLimit: number | string;
|
|
15
|
+
};
|
|
16
|
+
/**
|
|
17
|
+
* A helper class for interacting with a bundler.
|
|
18
|
+
*/
|
|
19
|
+
export declare class Bundler {
|
|
20
|
+
#private;
|
|
21
|
+
constructor(url: string);
|
|
22
|
+
/**
|
|
23
|
+
* Estimate the gas required to execute a user operation.
|
|
24
|
+
*
|
|
25
|
+
* @param userOperation - The user operation to estimate gas for.
|
|
26
|
+
* @param entrypoint - The address of entrypoint to use for the user operation.
|
|
27
|
+
* @returns The estimated gas limits for the user operation.
|
|
28
|
+
*/
|
|
29
|
+
estimateUserOperationGas(userOperation: UserOperation, entrypoint: string): Promise<BundlerEstimateUserOperationGasResponse>;
|
|
30
|
+
/**
|
|
31
|
+
* Retrieve the receipt for a user operation.
|
|
32
|
+
*
|
|
33
|
+
* @param hash - The hash of the user operation.
|
|
34
|
+
* @returns The receipt for the user operation, or `undefined` if the user operation is pending.
|
|
35
|
+
*/
|
|
36
|
+
getUserOperationReceipt(hash?: string): Promise<UserOperationReceipt | undefined>;
|
|
37
|
+
/**
|
|
38
|
+
* Submit a user operation to the bundler.
|
|
39
|
+
*
|
|
40
|
+
* @param userOperation - The signed user operation to submit.
|
|
41
|
+
* @param entrypoint - The address of entrypoint to use for the user operation.
|
|
42
|
+
* @returns The hash of the user operation.
|
|
43
|
+
*/
|
|
44
|
+
sendUserOperation(userOperation: UserOperation, entrypoint: string): Promise<string>;
|
|
45
|
+
}
|
|
46
|
+
//# sourceMappingURL=Bundler.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Bundler.d.mts","sourceRoot":"","sources":["../../src/helpers/Bundler.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,aAAa,EAAE,oBAAoB,EAAE,qBAAoB;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;;gBAGN,GAAG,EAAE,MAAM;IAIvB;;;;;;OAMG;IACG,wBAAwB,CAC5B,aAAa,EAAE,aAAa,EAC5B,UAAU,EAAE,MAAM,GACjB,OAAO,CAAC,uCAAuC,CAAC;IAanD;;;;;OAKG;IACG,uBAAuB,CAC3B,IAAI,CAAC,EAAE,MAAM,GACZ,OAAO,CAAC,oBAAoB,GAAG,SAAS,CAAC;IAS5C;;;;;;OAMG;IACG,iBAAiB,CACrB,aAAa,EAAE,aAAa,EAC5B,UAAU,EAAE,MAAM,GACjB,OAAO,CAAC,MAAM,CAAC;CAyCnB"}
|
|
@@ -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.mjs";
|
|
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.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":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A,IAAI,0CAAO,MAAX,IAAI,EAAQ,uBAAuB,EAAE;YAC9D,aAAa;YACb,UAAU;SACX,CAAC,CAAC;QAEH,GAAG,CAAC,qBAAqB,EAAE,IAAI,CAAC,CAAC;QAEjC,OAAO,IAAI,CAAC;IACd,CAAC;CA0BF;mFAxBC,KAAK,yBAAW,MAAc,EAAE,MAAiB;IAC/C,MAAM,OAAO,GAAG;QACd,MAAM,EAAE,MAAM;QACd,OAAO,EAAE;YACP,MAAM,EAAE,kBAAkB;YAC1B,cAAc,EAAE,kBAAkB;SACnC;QACD,IAAI,EAAE,IAAI,CAAC,SAAS,CAAC,EAAE,OAAO,EAAE,KAAK,EAAE,EAAE,EAAE,CAAC,EAAE,MAAM,EAAE,MAAM,EAAE,CAAC;KAChE,CAAC;IAEF,MAAM,QAAQ,GAAG,MAAM,KAAK,CAAC,uBAAA,IAAI,oBAAK,EAAE,OAAO,CAAC,CAAC;IACjD,MAAM,YAAY,GAAG,MAAM,QAAQ,CAAC,IAAI,EAAE,CAAC;IAE3C,IAAI,YAAY,CAAC,KAAK,EAAE,CAAC;QACvB,MAAM,KAAK,GAAG,IAAI,KAAK,CAAC,YAAY,CAAC,KAAK,CAAC,OAAO,IAAI,YAAY,CAAC,KAAK,CAAC,CAAC;QAEzE,KAA2C,CAAC,IAAI;YAC/C,YAAY,CAAC,KAAK,CAAC,IAAI,CAAC;QAE1B,MAAM,KAAK,CAAC;IACd,CAAC;IAED,OAAO,YAAY,CAAC,MAAM,CAAC;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"]}
|