@zerodev/sdk 4.1.4 → 4.1.5
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/dist/cjs/kernel-zerodev/provider.d.ts +3 -1
- package/dist/cjs/kernel-zerodev/provider.js +56 -0
- package/dist/cjs/kernel-zerodev/provider.js.map +1 -1
- package/dist/esm/kernel-zerodev/provider.d.ts +3 -1
- package/dist/esm/kernel-zerodev/provider.js +56 -0
- package/dist/esm/kernel-zerodev/provider.js.map +1 -1
- package/dist/types/kernel-zerodev/provider.d.ts +3 -1
- package/dist/types/kernel-zerodev/provider.d.ts.map +1 -1
- package/package.json +1 -1
- package/src/kernel-zerodev/provider.ts +74 -0
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { type Address, type Chain, type Hash, type HttpTransport, type RpcTransactionRequest } from "viem";
|
|
2
|
-
import { type SmartAccountProviderOpts, type UserOperationCallData, type BatchUserOperationCallData, type SendUserOperationResult, SmartAccountProvider, type AccountMiddlewareFn, type UserOperationOverrides } from "@alchemy/aa-core";
|
|
2
|
+
import { type SmartAccountProviderOpts, type UserOperationCallData, type BatchUserOperationCallData, type SendUserOperationResult, type UserOperationStruct, SmartAccountProvider, type AccountMiddlewareFn, type UserOperationOverrides } from "@alchemy/aa-core";
|
|
3
3
|
import { KernelSmartContractAccount } from "./account.js";
|
|
4
4
|
import type { PaymasterAndBundlerProviders, PaymasterConfig, PaymasterPolicy } from "./paymaster/types.js";
|
|
5
5
|
export type ZeroDevProviderConfig = {
|
|
@@ -26,6 +26,8 @@ export declare class ZeroDevProvider extends SmartAccountProvider<HttpTransport>
|
|
|
26
26
|
constructor({ projectId, chain, entryPointAddress, rpcUrl, account, bundlerProvider, opts, }: ZeroDevProviderConfig);
|
|
27
27
|
getProjectId: () => string;
|
|
28
28
|
sendTransaction: (request: RpcTransactionRequest, operation?: UserOpDataOperationTypes<UserOperationCallData>) => Promise<Hash>;
|
|
29
|
+
buildUserOperation: <T extends UserOperationCallData | BatchUserOperationCallData>(data: T, overrides?: UserOperationOverrides, operation?: UserOpDataOperationTypes<T>) => Promise<UserOperationStruct>;
|
|
30
|
+
private _runMiddlewareStack;
|
|
29
31
|
sendUserOperation: <T extends UserOperationCallData | BatchUserOperationCallData>(data: T, overrides?: UserOperationOverrides, operation?: UserOpDataOperationTypes<T>) => Promise<SendUserOperationResult>;
|
|
30
32
|
isReplacementOpError(errorIn: any): boolean;
|
|
31
33
|
unwrapError(errorIn: any): Error;
|
|
@@ -78,6 +78,62 @@ class ZeroDevProvider extends aa_core_1.SmartAccountProvider {
|
|
|
78
78
|
return await this.waitForUserOperationTransaction(hash);
|
|
79
79
|
}
|
|
80
80
|
});
|
|
81
|
+
Object.defineProperty(this, "buildUserOperation", {
|
|
82
|
+
enumerable: true,
|
|
83
|
+
configurable: true,
|
|
84
|
+
writable: true,
|
|
85
|
+
value: async (data, overrides, operation = Operation.Call) => {
|
|
86
|
+
if (!(0, account_js_1.isKernelAccount)(this.account)) {
|
|
87
|
+
throw new Error("account not connected!");
|
|
88
|
+
}
|
|
89
|
+
if (!this.account.validator) {
|
|
90
|
+
throw new Error("validator not connected!");
|
|
91
|
+
}
|
|
92
|
+
let callData = "0x";
|
|
93
|
+
if (Array.isArray(data)) {
|
|
94
|
+
if (operation === Operation.Call) {
|
|
95
|
+
callData = await this.account.encodeBatchExecute(data);
|
|
96
|
+
}
|
|
97
|
+
else {
|
|
98
|
+
throw errors_js_1.InvalidOperation;
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
else if ((0, account_js_1.isKernelAccount)(this.account)) {
|
|
102
|
+
if (operation === Operation.DelegateCall) {
|
|
103
|
+
callData = await this.account.encodeExecuteDelegate(data.target, data.value ?? 0n, data.data);
|
|
104
|
+
}
|
|
105
|
+
else if (operation === Operation.Call) {
|
|
106
|
+
callData = await this.account.encodeExecute(data.target, data.value ?? 0n, data.data);
|
|
107
|
+
}
|
|
108
|
+
else {
|
|
109
|
+
throw errors_js_1.InvalidOperation;
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
else {
|
|
113
|
+
throw errors_js_1.InvalidOperation;
|
|
114
|
+
}
|
|
115
|
+
const initCode = await this.account.getInitCode();
|
|
116
|
+
const nonce = await this.account.getNonce();
|
|
117
|
+
return await this._runMiddlewareStack({
|
|
118
|
+
initCode,
|
|
119
|
+
sender: this.getAddress(),
|
|
120
|
+
nonce,
|
|
121
|
+
callData,
|
|
122
|
+
signature: await this.account
|
|
123
|
+
.getValidator()
|
|
124
|
+
.getDynamicDummySignature(await this.getAddress(), callData),
|
|
125
|
+
}, overrides);
|
|
126
|
+
}
|
|
127
|
+
});
|
|
128
|
+
Object.defineProperty(this, "_runMiddlewareStack", {
|
|
129
|
+
enumerable: true,
|
|
130
|
+
configurable: true,
|
|
131
|
+
writable: true,
|
|
132
|
+
value: async (uo, overrides) => {
|
|
133
|
+
const result = await (0, aa_core_1.asyncPipe)(this.dummyPaymasterDataMiddleware, this.feeDataGetter, this.paymasterDataMiddleware, this.gasEstimator, this.customMiddleware ?? aa_core_1.noOpMiddleware, async (struct) => ({ ...struct, ...overrides }))(uo);
|
|
134
|
+
return (0, aa_core_1.deepHexlify)(await (0, aa_core_1.resolveProperties)(result));
|
|
135
|
+
}
|
|
136
|
+
});
|
|
81
137
|
Object.defineProperty(this, "sendUserOperation", {
|
|
82
138
|
enumerable: true,
|
|
83
139
|
configurable: true,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"provider.js","sourceRoot":"","sources":["../../../src/kernel-zerodev/provider.ts"],"names":[],"mappings":";;;AAAA,+BAQc;AACd,8CAe0B;AAC1B,iDAMwB;AACxB,6CAA2E;AAC3E,oEAAwE;AACxE,+DAA0D;AAC1D,2CAA+C;AAC/C,4DAAwE;AACxE,gEAA6E;AAoB7E,IAAY,SAGX;AAHD,WAAY,SAAS;IACnB,yCAAQ,CAAA;IACR,yDAAgB,CAAA;AAClB,CAAC,EAHW,SAAS,yBAAT,SA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C,CAAC;oBACpC,aAAa,GAAG,uBAAuB,KAAK,CAAC,CAAC,CAAC,GAAG,CAAC;oBACnD,eAAe,GAAG,KAAK,CAAC,CAAC,CAAC,CAAC;iBAC5B;aACF;YACD,MAAM,KAAK,GAAG,IAAI,KAAK,CACrB,+DAA+D,eAAe,IAAI,aAAa,EAAE,CAClG,CAAC;YACF,KAAK,CAAC,KAAK,GAAG,OAAO,CAAC,KAAK,CAAC;YAC5B,OAAO,KAAK,CAAC;SACd;QACD,OAAO,OAAO,CAAC;IACjB,CAAC;IAgBD,2BAA2B,CAAC,MAAwC;QAClE,IAAI,CAAC,IAAI,CAAC,WAAW,EAAE,EAAE;YACvB,MAAM,IAAI,KAAK,CACb,oEAAoE,CACrE,CAAC;SACH;QAED,OAAO,IAAA,0CAA2B,EAAC,IAAI,EAAE,MAAM,CAAC,CAAC;IACnD,CAAC;CAgCF;AApRD,0CAoRC","sourcesContent":["import {\n fromHex,\n type Address,\n type Chain,\n type Hash,\n type Hex,\n type HttpTransport,\n type RpcTransactionRequest,\n} from \"viem\";\nimport {\n deepHexlify,\n resolveProperties,\n type SmartAccountProviderOpts,\n getChain,\n type UserOperationCallData,\n type BatchUserOperationCallData,\n type SendUserOperationResult,\n asyncPipe,\n noOpMiddleware,\n type UserOperationStruct,\n type BytesLike,\n SmartAccountProvider,\n type AccountMiddlewareFn,\n type UserOperationOverrides,\n} from \"@alchemy/aa-core\";\nimport {\n BUNDLER_URL,\n DEFAULT_SEND_TX_MAX_RETRIES,\n DEFAULT_SEND_TX_RETRY_INTERVAL_MS,\n ENTRYPOINT_ADDRESS,\n minPriorityFeePerBidDefaults,\n} from \"./constants.js\";\nimport { KernelSmartContractAccount, isKernelAccount } from \"./account.js\";\nimport { withZeroDevGasEstimator } from \"./middleware/gas-estimator.js\";\nimport { isValidRequest } from \"./utils/ERC4337-utils.js\";\nimport { InvalidOperation } from \"./errors.js\";\nimport { withZeroDevPaymasterAndData } from \"./middleware/paymaster.js\";\nimport { createZeroDevPublicErc4337Client } from \"./client/create-client.js\";\nimport type {\n PaymasterAndBundlerProviders,\n PaymasterConfig,\n PaymasterPolicy,\n} from \"./paymaster/types.js\";\n\nexport type ZeroDevProviderConfig = {\n projectId: string;\n chain: Chain | number;\n entryPointAddress?: Address;\n rpcUrl?: string;\n account?: KernelSmartContractAccount;\n bundlerProvider?: PaymasterAndBundlerProviders;\n opts?: SmartAccountProviderOpts & {\n sendTxMaxRetries?: number;\n sendTxRetryIntervalMs?: number;\n };\n};\n\nexport enum Operation {\n Call = 0,\n DelegateCall = 1,\n}\n\ntype UserOpDataOperationTypes<T> = T extends UserOperationCallData\n ? Operation.Call | Operation.DelegateCall\n : T extends BatchUserOperationCallData\n ? Operation.Call\n : never;\n\nexport class ZeroDevProvider extends SmartAccountProvider<HttpTransport> {\n protected projectId: string;\n protected sendTxMaxRetries: number;\n protected sendTxRetryIntervalMs: number;\n\n constructor({\n projectId,\n chain,\n entryPointAddress = ENTRYPOINT_ADDRESS,\n rpcUrl = BUNDLER_URL,\n account,\n bundlerProvider,\n opts,\n }: ZeroDevProviderConfig) {\n const _chain = typeof chain === \"number\" ? getChain(chain) : chain;\n const rpcClient = createZeroDevPublicErc4337Client({\n chain: _chain,\n rpcUrl,\n projectId,\n bundlerProvider,\n });\n\n super(rpcClient, entryPointAddress, _chain, account, {\n ...opts,\n txMaxRetries: opts?.txMaxRetries ?? 10,\n txRetryIntervalMs: opts?.txRetryIntervalMs ?? 10000,\n minPriorityFeePerBid:\n opts?.minPriorityFeePerBid ??\n minPriorityFeePerBidDefaults.get(_chain.id),\n });\n\n this.projectId = projectId;\n this.sendTxMaxRetries =\n opts?.sendTxMaxRetries ?? DEFAULT_SEND_TX_MAX_RETRIES;\n this.sendTxRetryIntervalMs =\n opts?.sendTxRetryIntervalMs ?? DEFAULT_SEND_TX_RETRY_INTERVAL_MS;\n\n withZeroDevGasEstimator(this);\n }\n\n getProjectId = (): string => this.projectId;\n\n sendTransaction = async (\n request: RpcTransactionRequest,\n operation: UserOpDataOperationTypes<UserOperationCallData> = Operation.Call\n ): Promise<Hash> => {\n if (!request.to) {\n throw new Error(\"transaction is missing to address\");\n }\n\n const overrides: UserOperationOverrides = {};\n if (request.maxFeePerGas) {\n overrides.maxFeePerGas = request.maxFeePerGas;\n }\n if (request.maxPriorityFeePerGas) {\n overrides.maxPriorityFeePerGas = request.maxPriorityFeePerGas;\n }\n\n const { hash } = await this.sendUserOperation(\n {\n target: request.to,\n data: request.data ?? \"0x\",\n value: request.value ? fromHex(request.value, \"bigint\") : 0n,\n },\n overrides,\n operation\n );\n\n return await this.waitForUserOperationTransaction(hash as Hash);\n };\n\n sendUserOperation = async <\n T extends UserOperationCallData | BatchUserOperationCallData\n >(\n data: T,\n overrides?: UserOperationOverrides,\n operation: UserOpDataOperationTypes<T> = Operation.Call as UserOpDataOperationTypes<T>\n ): Promise<SendUserOperationResult> => {\n if (!isKernelAccount(this.account)) {\n throw new Error(\"account not connected!\");\n }\n if (!this.account.validator) {\n throw new Error(\"validator not connected!\");\n }\n\n let callData: BytesLike = \"0x\";\n\n if (Array.isArray(data)) {\n if (operation === Operation.Call) {\n callData = await this.account.encodeBatchExecute(data);\n } else {\n throw InvalidOperation;\n }\n } else if (isKernelAccount(this.account)) {\n if (operation === Operation.DelegateCall) {\n callData = await this.account.encodeExecuteDelegate(\n data.target,\n data.value ?? 0n,\n data.data\n );\n } else if (operation === Operation.Call) {\n callData = await this.account.encodeExecute(\n data.target,\n data.value ?? 0n,\n data.data\n );\n } else {\n throw InvalidOperation;\n }\n } else {\n throw InvalidOperation;\n }\n\n const initCode = await this.account.getInitCode();\n let hash: string = \"\";\n let i = 0;\n const nonce = await this.account.getNonce();\n let uoStruct: UserOperationStruct;\n let request: UserOperationStruct;\n let maxFeePerGas, maxPriorityFeePerGas;\n do {\n uoStruct = await asyncPipe(\n this.dummyPaymasterDataMiddleware,\n this.feeDataGetter,\n this.paymasterDataMiddleware,\n this.gasEstimator,\n this.customMiddleware ?? noOpMiddleware,\n async (struct) => ({ ...struct, ...overrides })\n )({\n initCode,\n sender: this.getAddress(),\n nonce,\n callData,\n signature: await this.account\n .getValidator()\n .getDynamicDummySignature(await this.getAddress(), callData as Hex),\n maxFeePerGas,\n maxPriorityFeePerGas,\n } as UserOperationStruct);\n request = deepHexlify(await resolveProperties(uoStruct));\n\n if (!isValidRequest(request)) {\n // this pretty prints the uo\n throw new Error(\n `Request is missing parameters. All properties on UserOperationStruct must be set. uo: ${JSON.stringify(\n request,\n null,\n 2\n )}`\n );\n }\n\n await this.account.approvePlugin();\n\n request.signature = await this.account.validator.getSignature(request);\n try {\n hash = await this.rpcClient.sendUserOperation(\n request,\n this.entryPointAddress\n );\n } catch (error: any) {\n if (this.isReplacementOpError(error) && i++ < this.sendTxMaxRetries) {\n maxFeePerGas = (BigInt(request.maxFeePerGas) * 113n) / 100n;\n maxPriorityFeePerGas =\n (BigInt(request.maxPriorityFeePerGas) * 113n) / 100n;\n\n console.log(\n `After ${\n this.sendTxRetryIntervalMs / 60000\n } minutes, resending tx with Increased Gas fees: maxFeePerGas: ${maxFeePerGas}, maxPriorityFeePerGas: ${maxPriorityFeePerGas}`\n );\n await new Promise((resolve) =>\n setTimeout(resolve, this.sendTxRetryIntervalMs)\n );\n continue;\n }\n throw this.unwrapError(error);\n }\n } while (hash === \"\");\n\n return {\n hash,\n request,\n };\n };\n\n isReplacementOpError(errorIn: any): boolean {\n if (errorIn.cause != null) {\n const failedOpMessage: string | undefined = errorIn?.cause?.message;\n return (\n (failedOpMessage?.includes(\n \"replacement op must increase maxFeePerGas and MaxPriorityFeePerGas\"\n ) ||\n failedOpMessage?.match(/.*replacement.*underpriced.*/) !== null) ??\n false\n );\n }\n return false;\n }\n\n unwrapError(errorIn: any): Error {\n if (errorIn?.cause != null) {\n let paymasterInfo: string = \"\";\n let failedOpMessage: string | undefined = errorIn?.cause?.message;\n if (failedOpMessage?.includes(\"FailedOp\") === true) {\n // TODO: better error extraction methods will be needed\n const matched = failedOpMessage.match(/FailedOp\\((.*)\\)/);\n if (matched != null) {\n const split = matched[1].split(\",\");\n paymasterInfo = `(paymaster address: ${split[1]})`;\n failedOpMessage = split[2];\n }\n }\n const error = new Error(\n `The bundler has failed to include UserOperation in a batch: ${failedOpMessage} ${paymasterInfo}`\n );\n error.stack = errorIn.stack;\n return error;\n }\n return errorIn;\n }\n\n getAccount: () => KernelSmartContractAccount = () => {\n if (!isKernelAccount(this.account)) {\n throw new Error(\"account not connected!\");\n }\n return this.account;\n };\n\n dummyPaymasterDataMiddleware: AccountMiddlewareFn = async (\n struct: UserOperationStruct\n ): Promise<UserOperationStruct> => {\n struct.paymasterAndData = \"0x\";\n return struct;\n };\n\n withZeroDevPaymasterAndData(config: PaymasterConfig<PaymasterPolicy>) {\n if (!this.isConnected()) {\n throw new Error(\n \"ZeroDevProvider: account is not set, did you call `connect` first?\"\n );\n }\n\n return withZeroDevPaymasterAndData(this, config);\n }\n\n request: (args: { method: string; params?: any[] }) => Promise<any> = async (\n args\n ) => {\n const { method, params } = args;\n switch (method) {\n case \"eth_chainId\":\n return this.chain.id;\n case \"eth_sendTransaction\":\n const [tx] = params as [RpcTransactionRequest];\n return this.sendTransaction(tx);\n case \"eth_signTypedData_v4\":\n //@ts-expect-error\n return this.signTypedData(JSON.parse(params[1]));\n case \"personal_sign\":\n if (!this.account) {\n throw new Error(\"account not connected!\");\n }\n const [data, address] = params!;\n if (address.toLowerCase() !== (await this.getAddress()).toLowerCase()) {\n throw new Error(\n \"cannot sign for address that is not the current account\"\n );\n }\n // @ts-ignore\n return this.account.signMessageWith6492(data);\n default:\n // @ts-ignore\n return this.rpcClient.request(args);\n }\n };\n}\n"]}
|
|
1
|
+
{"version":3,"file":"provider.js","sourceRoot":"","sources":["../../../src/kernel-zerodev/provider.ts"],"names":[],"mappings":";;;AAAA,+BAQc;AACd,8CAe0B;AAC1B,iDAMwB;AACxB,6CAA2E;AAC3E,oEAAwE;AACxE,+DAA0D;AAC1D,2CAA+C;AAC/C,4D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ClG,CAAC;YACF,KAAK,CAAC,KAAK,GAAG,OAAO,CAAC,KAAK,CAAC;YAC5B,OAAO,KAAK,CAAC;SACd;QACD,OAAO,OAAO,CAAC;IACjB,CAAC;IAgBD,2BAA2B,CAAC,MAAwC;QAClE,IAAI,CAAC,IAAI,CAAC,WAAW,EAAE,EAAE;YACvB,MAAM,IAAI,KAAK,CACb,oEAAoE,CACrE,CAAC;SACH;QAED,OAAO,IAAA,0CAA2B,EAAC,IAAI,EAAE,MAAM,CAAC,CAAC;IACnD,CAAC;CAgCF;AA9VD,0CA8VC","sourcesContent":["import {\n fromHex,\n type Address,\n type Chain,\n type Hash,\n type Hex,\n type HttpTransport,\n type RpcTransactionRequest,\n} from \"viem\";\nimport {\n deepHexlify,\n resolveProperties,\n type SmartAccountProviderOpts,\n getChain,\n type UserOperationCallData,\n type BatchUserOperationCallData,\n type SendUserOperationResult,\n asyncPipe,\n noOpMiddleware,\n type UserOperationStruct,\n type BytesLike,\n SmartAccountProvider,\n type AccountMiddlewareFn,\n type UserOperationOverrides,\n} from \"@alchemy/aa-core\";\nimport {\n BUNDLER_URL,\n DEFAULT_SEND_TX_MAX_RETRIES,\n DEFAULT_SEND_TX_RETRY_INTERVAL_MS,\n ENTRYPOINT_ADDRESS,\n minPriorityFeePerBidDefaults,\n} from \"./constants.js\";\nimport { KernelSmartContractAccount, isKernelAccount } from \"./account.js\";\nimport { withZeroDevGasEstimator } from \"./middleware/gas-estimator.js\";\nimport { isValidRequest } from \"./utils/ERC4337-utils.js\";\nimport { InvalidOperation } from \"./errors.js\";\nimport { withZeroDevPaymasterAndData } from \"./middleware/paymaster.js\";\nimport { createZeroDevPublicErc4337Client } from \"./client/create-client.js\";\nimport type {\n PaymasterAndBundlerProviders,\n PaymasterConfig,\n PaymasterPolicy,\n} from \"./paymaster/types.js\";\n\nexport type ZeroDevProviderConfig = {\n projectId: string;\n chain: Chain | number;\n entryPointAddress?: Address;\n rpcUrl?: string;\n account?: KernelSmartContractAccount;\n bundlerProvider?: PaymasterAndBundlerProviders;\n opts?: SmartAccountProviderOpts & {\n sendTxMaxRetries?: number;\n sendTxRetryIntervalMs?: number;\n };\n};\n\nexport enum Operation {\n Call = 0,\n DelegateCall = 1,\n}\n\ntype UserOpDataOperationTypes<T> = T extends UserOperationCallData\n ? Operation.Call | Operation.DelegateCall\n : T extends BatchUserOperationCallData\n ? Operation.Call\n : never;\n\nexport class ZeroDevProvider extends SmartAccountProvider<HttpTransport> {\n protected projectId: string;\n protected sendTxMaxRetries: number;\n protected sendTxRetryIntervalMs: number;\n\n constructor({\n projectId,\n chain,\n entryPointAddress = ENTRYPOINT_ADDRESS,\n rpcUrl = BUNDLER_URL,\n account,\n bundlerProvider,\n opts,\n }: ZeroDevProviderConfig) {\n const _chain = typeof chain === \"number\" ? getChain(chain) : chain;\n const rpcClient = createZeroDevPublicErc4337Client({\n chain: _chain,\n rpcUrl,\n projectId,\n bundlerProvider,\n });\n\n super(rpcClient, entryPointAddress, _chain, account, {\n ...opts,\n txMaxRetries: opts?.txMaxRetries ?? 10,\n txRetryIntervalMs: opts?.txRetryIntervalMs ?? 10000,\n minPriorityFeePerBid:\n opts?.minPriorityFeePerBid ??\n minPriorityFeePerBidDefaults.get(_chain.id),\n });\n\n this.projectId = projectId;\n this.sendTxMaxRetries =\n opts?.sendTxMaxRetries ?? DEFAULT_SEND_TX_MAX_RETRIES;\n this.sendTxRetryIntervalMs =\n opts?.sendTxRetryIntervalMs ?? DEFAULT_SEND_TX_RETRY_INTERVAL_MS;\n\n withZeroDevGasEstimator(this);\n }\n\n getProjectId = (): string => this.projectId;\n\n sendTransaction = async (\n request: RpcTransactionRequest,\n operation: UserOpDataOperationTypes<UserOperationCallData> = Operation.Call\n ): Promise<Hash> => {\n if (!request.to) {\n throw new Error(\"transaction is missing to address\");\n }\n\n const overrides: UserOperationOverrides = {};\n if (request.maxFeePerGas) {\n overrides.maxFeePerGas = request.maxFeePerGas;\n }\n if (request.maxPriorityFeePerGas) {\n overrides.maxPriorityFeePerGas = request.maxPriorityFeePerGas;\n }\n\n const { hash } = await this.sendUserOperation(\n {\n target: request.to,\n data: request.data ?? \"0x\",\n value: request.value ? fromHex(request.value, \"bigint\") : 0n,\n },\n overrides,\n operation\n );\n\n return await this.waitForUserOperationTransaction(hash as Hash);\n };\n\n buildUserOperation = async <\n T extends UserOperationCallData | BatchUserOperationCallData\n >(\n data: T,\n overrides?: UserOperationOverrides,\n operation: UserOpDataOperationTypes<T> = Operation.Call as UserOpDataOperationTypes<T>\n ): Promise<UserOperationStruct> => {\n if (!isKernelAccount(this.account)) {\n throw new Error(\"account not connected!\");\n }\n if (!this.account.validator) {\n throw new Error(\"validator not connected!\");\n }\n\n let callData: BytesLike = \"0x\";\n\n if (Array.isArray(data)) {\n if (operation === Operation.Call) {\n callData = await this.account.encodeBatchExecute(data);\n } else {\n throw InvalidOperation;\n }\n } else if (isKernelAccount(this.account)) {\n if (operation === Operation.DelegateCall) {\n callData = await this.account.encodeExecuteDelegate(\n data.target,\n data.value ?? 0n,\n data.data\n );\n } else if (operation === Operation.Call) {\n callData = await this.account.encodeExecute(\n data.target,\n data.value ?? 0n,\n data.data\n );\n } else {\n throw InvalidOperation;\n }\n } else {\n throw InvalidOperation;\n }\n\n const initCode = await this.account.getInitCode();\n const nonce = await this.account.getNonce();\n return await this._runMiddlewareStack(\n {\n initCode,\n sender: this.getAddress(),\n nonce,\n callData,\n signature: await this.account\n .getValidator()\n .getDynamicDummySignature(await this.getAddress(), callData as Hex),\n } as UserOperationStruct,\n overrides\n );\n };\n\n private _runMiddlewareStack = async (\n uo: UserOperationStruct,\n overrides?: UserOperationOverrides\n ): Promise<UserOperationStruct> => {\n const result = await asyncPipe(\n this.dummyPaymasterDataMiddleware,\n this.feeDataGetter,\n this.paymasterDataMiddleware,\n this.gasEstimator,\n this.customMiddleware ?? noOpMiddleware,\n async (struct) => ({ ...struct, ...overrides })\n )(uo);\n\n return deepHexlify(await resolveProperties<UserOperationStruct>(result));\n };\n\n sendUserOperation = async <\n T extends UserOperationCallData | BatchUserOperationCallData\n >(\n data: T,\n overrides?: UserOperationOverrides,\n operation: UserOpDataOperationTypes<T> = Operation.Call as UserOpDataOperationTypes<T>\n ): Promise<SendUserOperationResult> => {\n if (!isKernelAccount(this.account)) {\n throw new Error(\"account not connected!\");\n }\n if (!this.account.validator) {\n throw new Error(\"validator not connected!\");\n }\n\n let callData: BytesLike = \"0x\";\n\n if (Array.isArray(data)) {\n if (operation === Operation.Call) {\n callData = await this.account.encodeBatchExecute(data);\n } else {\n throw InvalidOperation;\n }\n } else if (isKernelAccount(this.account)) {\n if (operation === Operation.DelegateCall) {\n callData = await this.account.encodeExecuteDelegate(\n data.target,\n data.value ?? 0n,\n data.data\n );\n } else if (operation === Operation.Call) {\n callData = await this.account.encodeExecute(\n data.target,\n data.value ?? 0n,\n data.data\n );\n } else {\n throw InvalidOperation;\n }\n } else {\n throw InvalidOperation;\n }\n\n const initCode = await this.account.getInitCode();\n let hash: string = \"\";\n let i = 0;\n const nonce = await this.account.getNonce();\n let uoStruct: UserOperationStruct;\n let request: UserOperationStruct;\n let maxFeePerGas, maxPriorityFeePerGas;\n do {\n uoStruct = await asyncPipe(\n this.dummyPaymasterDataMiddleware,\n this.feeDataGetter,\n this.paymasterDataMiddleware,\n this.gasEstimator,\n this.customMiddleware ?? noOpMiddleware,\n async (struct) => ({ ...struct, ...overrides })\n )({\n initCode,\n sender: this.getAddress(),\n nonce,\n callData,\n signature: await this.account\n .getValidator()\n .getDynamicDummySignature(await this.getAddress(), callData as Hex),\n maxFeePerGas,\n maxPriorityFeePerGas,\n } as UserOperationStruct);\n request = deepHexlify(await resolveProperties(uoStruct));\n\n if (!isValidRequest(request)) {\n // this pretty prints the uo\n throw new Error(\n `Request is missing parameters. All properties on UserOperationStruct must be set. uo: ${JSON.stringify(\n request,\n null,\n 2\n )}`\n );\n }\n\n await this.account.approvePlugin();\n\n request.signature = await this.account.validator.getSignature(request);\n try {\n hash = await this.rpcClient.sendUserOperation(\n request,\n this.entryPointAddress\n );\n } catch (error: any) {\n if (this.isReplacementOpError(error) && i++ < this.sendTxMaxRetries) {\n maxFeePerGas = (BigInt(request.maxFeePerGas) * 113n) / 100n;\n maxPriorityFeePerGas =\n (BigInt(request.maxPriorityFeePerGas) * 113n) / 100n;\n\n console.log(\n `After ${\n this.sendTxRetryIntervalMs / 60000\n } minutes, resending tx with Increased Gas fees: maxFeePerGas: ${maxFeePerGas}, maxPriorityFeePerGas: ${maxPriorityFeePerGas}`\n );\n await new Promise((resolve) =>\n setTimeout(resolve, this.sendTxRetryIntervalMs)\n );\n continue;\n }\n throw this.unwrapError(error);\n }\n } while (hash === \"\");\n\n return {\n hash,\n request,\n };\n };\n\n isReplacementOpError(errorIn: any): boolean {\n if (errorIn.cause != null) {\n const failedOpMessage: string | undefined = errorIn?.cause?.message;\n return (\n (failedOpMessage?.includes(\n \"replacement op must increase maxFeePerGas and MaxPriorityFeePerGas\"\n ) ||\n failedOpMessage?.match(/.*replacement.*underpriced.*/) !== null) ??\n false\n );\n }\n return false;\n }\n\n unwrapError(errorIn: any): Error {\n if (errorIn?.cause != null) {\n let paymasterInfo: string = \"\";\n let failedOpMessage: string | undefined = errorIn?.cause?.message;\n if (failedOpMessage?.includes(\"FailedOp\") === true) {\n // TODO: better error extraction methods will be needed\n const matched = failedOpMessage.match(/FailedOp\\((.*)\\)/);\n if (matched != null) {\n const split = matched[1].split(\",\");\n paymasterInfo = `(paymaster address: ${split[1]})`;\n failedOpMessage = split[2];\n }\n }\n const error = new Error(\n `The bundler has failed to include UserOperation in a batch: ${failedOpMessage} ${paymasterInfo}`\n );\n error.stack = errorIn.stack;\n return error;\n }\n return errorIn;\n }\n\n getAccount: () => KernelSmartContractAccount = () => {\n if (!isKernelAccount(this.account)) {\n throw new Error(\"account not connected!\");\n }\n return this.account;\n };\n\n dummyPaymasterDataMiddleware: AccountMiddlewareFn = async (\n struct: UserOperationStruct\n ): Promise<UserOperationStruct> => {\n struct.paymasterAndData = \"0x\";\n return struct;\n };\n\n withZeroDevPaymasterAndData(config: PaymasterConfig<PaymasterPolicy>) {\n if (!this.isConnected()) {\n throw new Error(\n \"ZeroDevProvider: account is not set, did you call `connect` first?\"\n );\n }\n\n return withZeroDevPaymasterAndData(this, config);\n }\n\n request: (args: { method: string; params?: any[] }) => Promise<any> = async (\n args\n ) => {\n const { method, params } = args;\n switch (method) {\n case \"eth_chainId\":\n return this.chain.id;\n case \"eth_sendTransaction\":\n const [tx] = params as [RpcTransactionRequest];\n return this.sendTransaction(tx);\n case \"eth_signTypedData_v4\":\n //@ts-expect-error\n return this.signTypedData(JSON.parse(params[1]));\n case \"personal_sign\":\n if (!this.account) {\n throw new Error(\"account not connected!\");\n }\n const [data, address] = params!;\n if (address.toLowerCase() !== (await this.getAddress()).toLowerCase()) {\n throw new Error(\n \"cannot sign for address that is not the current account\"\n );\n }\n // @ts-ignore\n return this.account.signMessageWith6492(data);\n default:\n // @ts-ignore\n return this.rpcClient.request(args);\n }\n };\n}\n"]}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { type Address, type Chain, type Hash, type HttpTransport, type RpcTransactionRequest } from "viem";
|
|
2
|
-
import { type SmartAccountProviderOpts, type UserOperationCallData, type BatchUserOperationCallData, type SendUserOperationResult, SmartAccountProvider, type AccountMiddlewareFn, type UserOperationOverrides } from "@alchemy/aa-core";
|
|
2
|
+
import { type SmartAccountProviderOpts, type UserOperationCallData, type BatchUserOperationCallData, type SendUserOperationResult, type UserOperationStruct, SmartAccountProvider, type AccountMiddlewareFn, type UserOperationOverrides } from "@alchemy/aa-core";
|
|
3
3
|
import { KernelSmartContractAccount } from "./account.js";
|
|
4
4
|
import type { PaymasterAndBundlerProviders, PaymasterConfig, PaymasterPolicy } from "./paymaster/types.js";
|
|
5
5
|
export type ZeroDevProviderConfig = {
|
|
@@ -26,6 +26,8 @@ export declare class ZeroDevProvider extends SmartAccountProvider<HttpTransport>
|
|
|
26
26
|
constructor({ projectId, chain, entryPointAddress, rpcUrl, account, bundlerProvider, opts, }: ZeroDevProviderConfig);
|
|
27
27
|
getProjectId: () => string;
|
|
28
28
|
sendTransaction: (request: RpcTransactionRequest, operation?: UserOpDataOperationTypes<UserOperationCallData>) => Promise<Hash>;
|
|
29
|
+
buildUserOperation: <T extends UserOperationCallData | BatchUserOperationCallData>(data: T, overrides?: UserOperationOverrides, operation?: UserOpDataOperationTypes<T>) => Promise<UserOperationStruct>;
|
|
30
|
+
private _runMiddlewareStack;
|
|
29
31
|
sendUserOperation: <T extends UserOperationCallData | BatchUserOperationCallData>(data: T, overrides?: UserOperationOverrides, operation?: UserOpDataOperationTypes<T>) => Promise<SendUserOperationResult>;
|
|
30
32
|
isReplacementOpError(errorIn: any): boolean;
|
|
31
33
|
unwrapError(errorIn: any): Error;
|
|
@@ -75,6 +75,62 @@ export class ZeroDevProvider extends SmartAccountProvider {
|
|
|
75
75
|
return await this.waitForUserOperationTransaction(hash);
|
|
76
76
|
}
|
|
77
77
|
});
|
|
78
|
+
Object.defineProperty(this, "buildUserOperation", {
|
|
79
|
+
enumerable: true,
|
|
80
|
+
configurable: true,
|
|
81
|
+
writable: true,
|
|
82
|
+
value: async (data, overrides, operation = Operation.Call) => {
|
|
83
|
+
if (!isKernelAccount(this.account)) {
|
|
84
|
+
throw new Error("account not connected!");
|
|
85
|
+
}
|
|
86
|
+
if (!this.account.validator) {
|
|
87
|
+
throw new Error("validator not connected!");
|
|
88
|
+
}
|
|
89
|
+
let callData = "0x";
|
|
90
|
+
if (Array.isArray(data)) {
|
|
91
|
+
if (operation === Operation.Call) {
|
|
92
|
+
callData = await this.account.encodeBatchExecute(data);
|
|
93
|
+
}
|
|
94
|
+
else {
|
|
95
|
+
throw InvalidOperation;
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
else if (isKernelAccount(this.account)) {
|
|
99
|
+
if (operation === Operation.DelegateCall) {
|
|
100
|
+
callData = await this.account.encodeExecuteDelegate(data.target, data.value ?? 0n, data.data);
|
|
101
|
+
}
|
|
102
|
+
else if (operation === Operation.Call) {
|
|
103
|
+
callData = await this.account.encodeExecute(data.target, data.value ?? 0n, data.data);
|
|
104
|
+
}
|
|
105
|
+
else {
|
|
106
|
+
throw InvalidOperation;
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
else {
|
|
110
|
+
throw InvalidOperation;
|
|
111
|
+
}
|
|
112
|
+
const initCode = await this.account.getInitCode();
|
|
113
|
+
const nonce = await this.account.getNonce();
|
|
114
|
+
return await this._runMiddlewareStack({
|
|
115
|
+
initCode,
|
|
116
|
+
sender: this.getAddress(),
|
|
117
|
+
nonce,
|
|
118
|
+
callData,
|
|
119
|
+
signature: await this.account
|
|
120
|
+
.getValidator()
|
|
121
|
+
.getDynamicDummySignature(await this.getAddress(), callData),
|
|
122
|
+
}, overrides);
|
|
123
|
+
}
|
|
124
|
+
});
|
|
125
|
+
Object.defineProperty(this, "_runMiddlewareStack", {
|
|
126
|
+
enumerable: true,
|
|
127
|
+
configurable: true,
|
|
128
|
+
writable: true,
|
|
129
|
+
value: async (uo, overrides) => {
|
|
130
|
+
const result = await asyncPipe(this.dummyPaymasterDataMiddleware, this.feeDataGetter, this.paymasterDataMiddleware, this.gasEstimator, this.customMiddleware ?? noOpMiddleware, async (struct) => ({ ...struct, ...overrides }))(uo);
|
|
131
|
+
return deepHexlify(await resolveProperties(result));
|
|
132
|
+
}
|
|
133
|
+
});
|
|
78
134
|
Object.defineProperty(this, "sendUserOperation", {
|
|
79
135
|
enumerable: true,
|
|
80
136
|
configurable: true,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"provider.js","sourceRoot":"","sources":["../../../src/kernel-zerodev/provider.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,OAAO,GAOR,MAAM,MAAM,CAAC;AACd,OAAO,EACL,WAAW,EACX,iBAAiB,EAEjB,QAAQ,EAIR,SAAS,EACT,cAAc,EAGd,oBAAoB,GAGrB,MAAM,kBAAkB,CAAC;AAC1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ClE,KAAK,CACN,CAAC;SACH;QACD,OAAO,KAAK,CAAC;IACf,CAAC;IAED,WAAW,CAAC,OAAY;QACtB,IAAI,OAAO,EAAE,KAAK,IAAI,IAAI,EAAE;YAC1B,IAAI,aAAa,GAAW,EAAE,CAAC;YAC/B,IAAI,eAAe,GAAuB,OAAO,EAAE,KAAK,EAAE,OAAO,CAAC;YAClE,IAAI,eAAe,EAAE,QAAQ,CAAC,UAAU,CAAC,KAAK,IAAI,EAAE;gBAElD,MAAM,OAAO,GAAG,eAAe,CAAC,KAAK,CAAC,kBAAkB,CAAC,CAAC;gBAC1D,IAAI,OAAO,IAAI,IAAI,EAAE;oBACnB,MAAM,KAAK,GAAG,OAAO,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC;oBACpC,aAAa,GAAG,uBAAuB,KAAK,CAAC,CAAC,CAAC,GAAG,CAAC;oBACnD,eAAe,GAAG,KAAK,CAAC,CAAC,CAAC,CAAC;iBAC5B;aACF;YACD,MAAM,KAAK,GAAG,IAAI,KAAK,CACrB,+DAA+D,eAAe,IAAI,aAAa,EAAE,CAClG,CAAC;YACF,KAAK,CAAC,KAAK,GAAG,OAAO,CAAC,KAAK,CAAC;YAC5B,OAAO,KAAK,CAAC;SACd;QACD,OAAO,OAAO,CAAC;IACjB,CAAC;IAgBD,2BAA2B,CAAC,MAAwC;QAClE,IAAI,CAAC,IAAI,CAAC,WAAW,EAAE,EAAE;YACvB,MAAM,IAAI,KAAK,CACb,oEAAoE,CACrE,CAAC;SACH;QAED,OAAO,2BAA2B,CAAC,IAAI,EAAE,MAAM,CAAC,CAAC;IACnD,CAAC;CAgCF","sourcesContent":["import {\n fromHex,\n type Address,\n type Chain,\n type Hash,\n type Hex,\n type HttpTransport,\n type RpcTransactionRequest,\n} from \"viem\";\nimport {\n deepHexlify,\n resolveProperties,\n type SmartAccountProviderOpts,\n getChain,\n type UserOperationCallData,\n type BatchUserOperationCallData,\n type SendUserOperationResult,\n asyncPipe,\n noOpMiddleware,\n type UserOperationStruct,\n type BytesLike,\n SmartAccountProvider,\n type AccountMiddlewareFn,\n type UserOperationOverrides,\n} from \"@alchemy/aa-core\";\nimport {\n BUNDLER_URL,\n DEFAULT_SEND_TX_MAX_RETRIES,\n DEFAULT_SEND_TX_RETRY_INTERVAL_MS,\n ENTRYPOINT_ADDRESS,\n minPriorityFeePerBidDefaults,\n} from \"./constants.js\";\nimport { KernelSmartContractAccount, isKernelAccount } from \"./account.js\";\nimport { withZeroDevGasEstimator } from \"./middleware/gas-estimator.js\";\nimport { isValidRequest } from \"./utils/ERC4337-utils.js\";\nimport { InvalidOperation } from \"./errors.js\";\nimport { withZeroDevPaymasterAndData } from \"./middleware/paymaster.js\";\nimport { createZeroDevPublicErc4337Client } from \"./client/create-client.js\";\nimport type {\n PaymasterAndBundlerProviders,\n PaymasterConfig,\n PaymasterPolicy,\n} from \"./paymaster/types.js\";\n\nexport type ZeroDevProviderConfig = {\n projectId: string;\n chain: Chain | number;\n entryPointAddress?: Address;\n rpcUrl?: string;\n account?: KernelSmartContractAccount;\n bundlerProvider?: PaymasterAndBundlerProviders;\n opts?: SmartAccountProviderOpts & {\n sendTxMaxRetries?: number;\n sendTxRetryIntervalMs?: number;\n };\n};\n\nexport enum Operation {\n Call = 0,\n DelegateCall = 1,\n}\n\ntype UserOpDataOperationTypes<T> = T extends UserOperationCallData\n ? Operation.Call | Operation.DelegateCall\n : T extends BatchUserOperationCallData\n ? Operation.Call\n : never;\n\nexport class ZeroDevProvider extends SmartAccountProvider<HttpTransport> {\n protected projectId: string;\n protected sendTxMaxRetries: number;\n protected sendTxRetryIntervalMs: number;\n\n constructor({\n projectId,\n chain,\n entryPointAddress = ENTRYPOINT_ADDRESS,\n rpcUrl = BUNDLER_URL,\n account,\n bundlerProvider,\n opts,\n }: ZeroDevProviderConfig) {\n const _chain = typeof chain === \"number\" ? getChain(chain) : chain;\n const rpcClient = createZeroDevPublicErc4337Client({\n chain: _chain,\n rpcUrl,\n projectId,\n bundlerProvider,\n });\n\n super(rpcClient, entryPointAddress, _chain, account, {\n ...opts,\n txMaxRetries: opts?.txMaxRetries ?? 10,\n txRetryIntervalMs: opts?.txRetryIntervalMs ?? 10000,\n minPriorityFeePerBid:\n opts?.minPriorityFeePerBid ??\n minPriorityFeePerBidDefaults.get(_chain.id),\n });\n\n this.projectId = projectId;\n this.sendTxMaxRetries =\n opts?.sendTxMaxRetries ?? DEFAULT_SEND_TX_MAX_RETRIES;\n this.sendTxRetryIntervalMs =\n opts?.sendTxRetryIntervalMs ?? DEFAULT_SEND_TX_RETRY_INTERVAL_MS;\n\n withZeroDevGasEstimator(this);\n }\n\n getProjectId = (): string => this.projectId;\n\n sendTransaction = async (\n request: RpcTransactionRequest,\n operation: UserOpDataOperationTypes<UserOperationCallData> = Operation.Call\n ): Promise<Hash> => {\n if (!request.to) {\n throw new Error(\"transaction is missing to address\");\n }\n\n const overrides: UserOperationOverrides = {};\n if (request.maxFeePerGas) {\n overrides.maxFeePerGas = request.maxFeePerGas;\n }\n if (request.maxPriorityFeePerGas) {\n overrides.maxPriorityFeePerGas = request.maxPriorityFeePerGas;\n }\n\n const { hash } = await this.sendUserOperation(\n {\n target: request.to,\n data: request.data ?? \"0x\",\n value: request.value ? fromHex(request.value, \"bigint\") : 0n,\n },\n overrides,\n operation\n );\n\n return await this.waitForUserOperationTransaction(hash as Hash);\n };\n\n sendUserOperation = async <\n T extends UserOperationCallData | BatchUserOperationCallData\n >(\n data: T,\n overrides?: UserOperationOverrides,\n operation: UserOpDataOperationTypes<T> = Operation.Call as UserOpDataOperationTypes<T>\n ): Promise<SendUserOperationResult> => {\n if (!isKernelAccount(this.account)) {\n throw new Error(\"account not connected!\");\n }\n if (!this.account.validator) {\n throw new Error(\"validator not connected!\");\n }\n\n let callData: BytesLike = \"0x\";\n\n if (Array.isArray(data)) {\n if (operation === Operation.Call) {\n callData = await this.account.encodeBatchExecute(data);\n } else {\n throw InvalidOperation;\n }\n } else if (isKernelAccount(this.account)) {\n if (operation === Operation.DelegateCall) {\n callData = await this.account.encodeExecuteDelegate(\n data.target,\n data.value ?? 0n,\n data.data\n );\n } else if (operation === Operation.Call) {\n callData = await this.account.encodeExecute(\n data.target,\n data.value ?? 0n,\n data.data\n );\n } else {\n throw InvalidOperation;\n }\n } else {\n throw InvalidOperation;\n }\n\n const initCode = await this.account.getInitCode();\n let hash: string = \"\";\n let i = 0;\n const nonce = await this.account.getNonce();\n let uoStruct: UserOperationStruct;\n let request: UserOperationStruct;\n let maxFeePerGas, maxPriorityFeePerGas;\n do {\n uoStruct = await asyncPipe(\n this.dummyPaymasterDataMiddleware,\n this.feeDataGetter,\n this.paymasterDataMiddleware,\n this.gasEstimator,\n this.customMiddleware ?? noOpMiddleware,\n async (struct) => ({ ...struct, ...overrides })\n )({\n initCode,\n sender: this.getAddress(),\n nonce,\n callData,\n signature: await this.account\n .getValidator()\n .getDynamicDummySignature(await this.getAddress(), callData as Hex),\n maxFeePerGas,\n maxPriorityFeePerGas,\n } as UserOperationStruct);\n request = deepHexlify(await resolveProperties(uoStruct));\n\n if (!isValidRequest(request)) {\n // this pretty prints the uo\n throw new Error(\n `Request is missing parameters. All properties on UserOperationStruct must be set. uo: ${JSON.stringify(\n request,\n null,\n 2\n )}`\n );\n }\n\n await this.account.approvePlugin();\n\n request.signature = await this.account.validator.getSignature(request);\n try {\n hash = await this.rpcClient.sendUserOperation(\n request,\n this.entryPointAddress\n );\n } catch (error: any) {\n if (this.isReplacementOpError(error) && i++ < this.sendTxMaxRetries) {\n maxFeePerGas = (BigInt(request.maxFeePerGas) * 113n) / 100n;\n maxPriorityFeePerGas =\n (BigInt(request.maxPriorityFeePerGas) * 113n) / 100n;\n\n console.log(\n `After ${\n this.sendTxRetryIntervalMs / 60000\n } minutes, resending tx with Increased Gas fees: maxFeePerGas: ${maxFeePerGas}, maxPriorityFeePerGas: ${maxPriorityFeePerGas}`\n );\n await new Promise((resolve) =>\n setTimeout(resolve, this.sendTxRetryIntervalMs)\n );\n continue;\n }\n throw this.unwrapError(error);\n }\n } while (hash === \"\");\n\n return {\n hash,\n request,\n };\n };\n\n isReplacementOpError(errorIn: any): boolean {\n if (errorIn.cause != null) {\n const failedOpMessage: string | undefined = errorIn?.cause?.message;\n return (\n (failedOpMessage?.includes(\n \"replacement op must increase maxFeePerGas and MaxPriorityFeePerGas\"\n ) ||\n failedOpMessage?.match(/.*replacement.*underpriced.*/) !== null) ??\n false\n );\n }\n return false;\n }\n\n unwrapError(errorIn: any): Error {\n if (errorIn?.cause != null) {\n let paymasterInfo: string = \"\";\n let failedOpMessage: string | undefined = errorIn?.cause?.message;\n if (failedOpMessage?.includes(\"FailedOp\") === true) {\n // TODO: better error extraction methods will be needed\n const matched = failedOpMessage.match(/FailedOp\\((.*)\\)/);\n if (matched != null) {\n const split = matched[1].split(\",\");\n paymasterInfo = `(paymaster address: ${split[1]})`;\n failedOpMessage = split[2];\n }\n }\n const error = new Error(\n `The bundler has failed to include UserOperation in a batch: ${failedOpMessage} ${paymasterInfo}`\n );\n error.stack = errorIn.stack;\n return error;\n }\n return errorIn;\n }\n\n getAccount: () => KernelSmartContractAccount = () => {\n if (!isKernelAccount(this.account)) {\n throw new Error(\"account not connected!\");\n }\n return this.account;\n };\n\n dummyPaymasterDataMiddleware: AccountMiddlewareFn = async (\n struct: UserOperationStruct\n ): Promise<UserOperationStruct> => {\n struct.paymasterAndData = \"0x\";\n return struct;\n };\n\n withZeroDevPaymasterAndData(config: PaymasterConfig<PaymasterPolicy>) {\n if (!this.isConnected()) {\n throw new Error(\n \"ZeroDevProvider: account is not set, did you call `connect` first?\"\n );\n }\n\n return withZeroDevPaymasterAndData(this, config);\n }\n\n request: (args: { method: string; params?: any[] }) => Promise<any> = async (\n args\n ) => {\n const { method, params } = args;\n switch (method) {\n case \"eth_chainId\":\n return this.chain.id;\n case \"eth_sendTransaction\":\n const [tx] = params as [RpcTransactionRequest];\n return this.sendTransaction(tx);\n case \"eth_signTypedData_v4\":\n //@ts-expect-error\n return this.signTypedData(JSON.parse(params[1]));\n case \"personal_sign\":\n if (!this.account) {\n throw new Error(\"account not connected!\");\n }\n const [data, address] = params!;\n if (address.toLowerCase() !== (await this.getAddress()).toLowerCase()) {\n throw new Error(\n \"cannot sign for address that is not the current account\"\n );\n }\n // @ts-ignore\n return this.account.signMessageWith6492(data);\n default:\n // @ts-ignore\n return this.rpcClient.request(args);\n }\n };\n}\n"]}
|
|
1
|
+
{"version":3,"file":"provider.js","sourceRoot":"","sources":["../../../src/kernel-zerodev/provider.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,OAAO,GAOR,MAAM,MAAM,CAAC;AACd,OAAO,EACL,WAAW,EACX,iBAAiB,EAEjB,QAAQ,EAIR,SAAS,EACT,cAAc,EAGd,oBAAoB,GAGrB,MAAM,kBAAkB,CAAC;AAC1B,OAAO,EACL,WAAW,EACX,2BAA2B,EAC3B,iCAAiC,EACjC,kBAAkB,EAClB,4BAA4B,GAC7B,MAAM,gBAAgB,CAAC;AACxB,OAAO,EAAE,0BAA0B,EAAE,eAAe,EAAE,MAAM,cAAc,CAAC;AAC3E,OAAO,EAAE,uBAAuB,EAAE,MAAM,+BAA+B,CAAC;AACxE,OAAO,EAAE,cAAc,EAAE,MAAM,0BAA0B,CAAC;AAC1D,OAAO,EAAE,gBAAgB,EAAE,MAAM,aAAa,CAAC;AAC/C,OAAO,EAAE,2BAA2B,EAAE,MAAM,2BAA2B,CAAC;AACxE,OAAO,EAAE,gCAAgC,EAAE,MAAM,2BAA2B,CAAC;AAoB7E,MAAM,CAAN,IAAY,SAGX;AAHD,WAAY,SAAS;IACnB,yCAAQ,CAAA;IACR,yDAAgB,CAAA;AAClB,CAAC,EAHW,SAAS,KAAT,SAAS,QAGpB;AAQD,MAAM,OAAO,eAAgB,SAAQ,oBAAmC;IAKtE,YAAY,EACV,SAAS,EACT,KAAK,EACL,iBAAiB,GAAG,kBAAkB,EACtC,MAAM,GAAG,WAAW,EACpB,OAAO,EACP,eAAe,EACf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cTransactionRequest,\n} from \"viem\";\nimport {\n deepHexlify,\n resolveProperties,\n type SmartAccountProviderOpts,\n getChain,\n type UserOperationCallData,\n type BatchUserOperationCallData,\n type SendUserOperationResult,\n asyncPipe,\n noOpMiddleware,\n type UserOperationStruct,\n type BytesLike,\n SmartAccountProvider,\n type AccountMiddlewareFn,\n type UserOperationOverrides,\n} from \"@alchemy/aa-core\";\nimport {\n BUNDLER_URL,\n DEFAULT_SEND_TX_MAX_RETRIES,\n DEFAULT_SEND_TX_RETRY_INTERVAL_MS,\n ENTRYPOINT_ADDRESS,\n minPriorityFeePerBidDefaults,\n} from \"./constants.js\";\nimport { KernelSmartContractAccount, isKernelAccount } from \"./account.js\";\nimport { withZeroDevGasEstimator } from \"./middleware/gas-estimator.js\";\nimport { isValidRequest } from \"./utils/ERC4337-utils.js\";\nimport { InvalidOperation } from \"./errors.js\";\nimport { withZeroDevPaymasterAndData } from \"./middleware/paymaster.js\";\nimport { createZeroDevPublicErc4337Client } from \"./client/create-client.js\";\nimport type {\n PaymasterAndBundlerProviders,\n PaymasterConfig,\n PaymasterPolicy,\n} from \"./paymaster/types.js\";\n\nexport type ZeroDevProviderConfig = {\n projectId: string;\n chain: Chain | number;\n entryPointAddress?: Address;\n rpcUrl?: string;\n account?: KernelSmartContractAccount;\n bundlerProvider?: PaymasterAndBundlerProviders;\n opts?: SmartAccountProviderOpts & {\n sendTxMaxRetries?: number;\n sendTxRetryIntervalMs?: number;\n };\n};\n\nexport enum Operation {\n Call = 0,\n DelegateCall = 1,\n}\n\ntype UserOpDataOperationTypes<T> = T extends UserOperationCallData\n ? Operation.Call | Operation.DelegateCall\n : T extends BatchUserOperationCallData\n ? Operation.Call\n : never;\n\nexport class ZeroDevProvider extends SmartAccountProvider<HttpTransport> {\n protected projectId: string;\n protected sendTxMaxRetries: number;\n protected sendTxRetryIntervalMs: number;\n\n constructor({\n projectId,\n chain,\n entryPointAddress = ENTRYPOINT_ADDRESS,\n rpcUrl = BUNDLER_URL,\n account,\n bundlerProvider,\n opts,\n }: ZeroDevProviderConfig) {\n const _chain = typeof chain === \"number\" ? getChain(chain) : chain;\n const rpcClient = createZeroDevPublicErc4337Client({\n chain: _chain,\n rpcUrl,\n projectId,\n bundlerProvider,\n });\n\n super(rpcClient, entryPointAddress, _chain, account, {\n ...opts,\n txMaxRetries: opts?.txMaxRetries ?? 10,\n txRetryIntervalMs: opts?.txRetryIntervalMs ?? 10000,\n minPriorityFeePerBid:\n opts?.minPriorityFeePerBid ??\n minPriorityFeePerBidDefaults.get(_chain.id),\n });\n\n this.projectId = projectId;\n this.sendTxMaxRetries =\n opts?.sendTxMaxRetries ?? DEFAULT_SEND_TX_MAX_RETRIES;\n this.sendTxRetryIntervalMs =\n opts?.sendTxRetryIntervalMs ?? DEFAULT_SEND_TX_RETRY_INTERVAL_MS;\n\n withZeroDevGasEstimator(this);\n }\n\n getProjectId = (): string => this.projectId;\n\n sendTransaction = async (\n request: RpcTransactionRequest,\n operation: UserOpDataOperationTypes<UserOperationCallData> = Operation.Call\n ): Promise<Hash> => {\n if (!request.to) {\n throw new Error(\"transaction is missing to address\");\n }\n\n const overrides: UserOperationOverrides = {};\n if (request.maxFeePerGas) {\n overrides.maxFeePerGas = request.maxFeePerGas;\n }\n if (request.maxPriorityFeePerGas) {\n overrides.maxPriorityFeePerGas = request.maxPriorityFeePerGas;\n }\n\n const { hash } = await this.sendUserOperation(\n {\n target: request.to,\n data: request.data ?? \"0x\",\n value: request.value ? fromHex(request.value, \"bigint\") : 0n,\n },\n overrides,\n operation\n );\n\n return await this.waitForUserOperationTransaction(hash as Hash);\n };\n\n buildUserOperation = async <\n T extends UserOperationCallData | BatchUserOperationCallData\n >(\n data: T,\n overrides?: UserOperationOverrides,\n operation: UserOpDataOperationTypes<T> = Operation.Call as UserOpDataOperationTypes<T>\n ): Promise<UserOperationStruct> => {\n if (!isKernelAccount(this.account)) {\n throw new Error(\"account not connected!\");\n }\n if (!this.account.validator) {\n throw new Error(\"validator not connected!\");\n }\n\n let callData: BytesLike = \"0x\";\n\n if (Array.isArray(data)) {\n if (operation === Operation.Call) {\n callData = await this.account.encodeBatchExecute(data);\n } else {\n throw InvalidOperation;\n }\n } else if (isKernelAccount(this.account)) {\n if (operation === Operation.DelegateCall) {\n callData = await this.account.encodeExecuteDelegate(\n data.target,\n data.value ?? 0n,\n data.data\n );\n } else if (operation === Operation.Call) {\n callData = await this.account.encodeExecute(\n data.target,\n data.value ?? 0n,\n data.data\n );\n } else {\n throw InvalidOperation;\n }\n } else {\n throw InvalidOperation;\n }\n\n const initCode = await this.account.getInitCode();\n const nonce = await this.account.getNonce();\n return await this._runMiddlewareStack(\n {\n initCode,\n sender: this.getAddress(),\n nonce,\n callData,\n signature: await this.account\n .getValidator()\n .getDynamicDummySignature(await this.getAddress(), callData as Hex),\n } as UserOperationStruct,\n overrides\n );\n };\n\n private _runMiddlewareStack = async (\n uo: UserOperationStruct,\n overrides?: UserOperationOverrides\n ): Promise<UserOperationStruct> => {\n const result = await asyncPipe(\n this.dummyPaymasterDataMiddleware,\n this.feeDataGetter,\n this.paymasterDataMiddleware,\n this.gasEstimator,\n this.customMiddleware ?? noOpMiddleware,\n async (struct) => ({ ...struct, ...overrides })\n )(uo);\n\n return deepHexlify(await resolveProperties<UserOperationStruct>(result));\n };\n\n sendUserOperation = async <\n T extends UserOperationCallData | BatchUserOperationCallData\n >(\n data: T,\n overrides?: UserOperationOverrides,\n operation: UserOpDataOperationTypes<T> = Operation.Call as UserOpDataOperationTypes<T>\n ): Promise<SendUserOperationResult> => {\n if (!isKernelAccount(this.account)) {\n throw new Error(\"account not connected!\");\n }\n if (!this.account.validator) {\n throw new Error(\"validator not connected!\");\n }\n\n let callData: BytesLike = \"0x\";\n\n if (Array.isArray(data)) {\n if (operation === Operation.Call) {\n callData = await this.account.encodeBatchExecute(data);\n } else {\n throw InvalidOperation;\n }\n } else if (isKernelAccount(this.account)) {\n if (operation === Operation.DelegateCall) {\n callData = await this.account.encodeExecuteDelegate(\n data.target,\n data.value ?? 0n,\n data.data\n );\n } else if (operation === Operation.Call) {\n callData = await this.account.encodeExecute(\n data.target,\n data.value ?? 0n,\n data.data\n );\n } else {\n throw InvalidOperation;\n }\n } else {\n throw InvalidOperation;\n }\n\n const initCode = await this.account.getInitCode();\n let hash: string = \"\";\n let i = 0;\n const nonce = await this.account.getNonce();\n let uoStruct: UserOperationStruct;\n let request: UserOperationStruct;\n let maxFeePerGas, maxPriorityFeePerGas;\n do {\n uoStruct = await asyncPipe(\n this.dummyPaymasterDataMiddleware,\n this.feeDataGetter,\n this.paymasterDataMiddleware,\n this.gasEstimator,\n this.customMiddleware ?? noOpMiddleware,\n async (struct) => ({ ...struct, ...overrides })\n )({\n initCode,\n sender: this.getAddress(),\n nonce,\n callData,\n signature: await this.account\n .getValidator()\n .getDynamicDummySignature(await this.getAddress(), callData as Hex),\n maxFeePerGas,\n maxPriorityFeePerGas,\n } as UserOperationStruct);\n request = deepHexlify(await resolveProperties(uoStruct));\n\n if (!isValidRequest(request)) {\n // this pretty prints the uo\n throw new Error(\n `Request is missing parameters. All properties on UserOperationStruct must be set. uo: ${JSON.stringify(\n request,\n null,\n 2\n )}`\n );\n }\n\n await this.account.approvePlugin();\n\n request.signature = await this.account.validator.getSignature(request);\n try {\n hash = await this.rpcClient.sendUserOperation(\n request,\n this.entryPointAddress\n );\n } catch (error: any) {\n if (this.isReplacementOpError(error) && i++ < this.sendTxMaxRetries) {\n maxFeePerGas = (BigInt(request.maxFeePerGas) * 113n) / 100n;\n maxPriorityFeePerGas =\n (BigInt(request.maxPriorityFeePerGas) * 113n) / 100n;\n\n console.log(\n `After ${\n this.sendTxRetryIntervalMs / 60000\n } minutes, resending tx with Increased Gas fees: maxFeePerGas: ${maxFeePerGas}, maxPriorityFeePerGas: ${maxPriorityFeePerGas}`\n );\n await new Promise((resolve) =>\n setTimeout(resolve, this.sendTxRetryIntervalMs)\n );\n continue;\n }\n throw this.unwrapError(error);\n }\n } while (hash === \"\");\n\n return {\n hash,\n request,\n };\n };\n\n isReplacementOpError(errorIn: any): boolean {\n if (errorIn.cause != null) {\n const failedOpMessage: string | undefined = errorIn?.cause?.message;\n return (\n (failedOpMessage?.includes(\n \"replacement op must increase maxFeePerGas and MaxPriorityFeePerGas\"\n ) ||\n failedOpMessage?.match(/.*replacement.*underpriced.*/) !== null) ??\n false\n );\n }\n return false;\n }\n\n unwrapError(errorIn: any): Error {\n if (errorIn?.cause != null) {\n let paymasterInfo: string = \"\";\n let failedOpMessage: string | undefined = errorIn?.cause?.message;\n if (failedOpMessage?.includes(\"FailedOp\") === true) {\n // TODO: better error extraction methods will be needed\n const matched = failedOpMessage.match(/FailedOp\\((.*)\\)/);\n if (matched != null) {\n const split = matched[1].split(\",\");\n paymasterInfo = `(paymaster address: ${split[1]})`;\n failedOpMessage = split[2];\n }\n }\n const error = new Error(\n `The bundler has failed to include UserOperation in a batch: ${failedOpMessage} ${paymasterInfo}`\n );\n error.stack = errorIn.stack;\n return error;\n }\n return errorIn;\n }\n\n getAccount: () => KernelSmartContractAccount = () => {\n if (!isKernelAccount(this.account)) {\n throw new Error(\"account not connected!\");\n }\n return this.account;\n };\n\n dummyPaymasterDataMiddleware: AccountMiddlewareFn = async (\n struct: UserOperationStruct\n ): Promise<UserOperationStruct> => {\n struct.paymasterAndData = \"0x\";\n return struct;\n };\n\n withZeroDevPaymasterAndData(config: PaymasterConfig<PaymasterPolicy>) {\n if (!this.isConnected()) {\n throw new Error(\n \"ZeroDevProvider: account is not set, did you call `connect` first?\"\n );\n }\n\n return withZeroDevPaymasterAndData(this, config);\n }\n\n request: (args: { method: string; params?: any[] }) => Promise<any> = async (\n args\n ) => {\n const { method, params } = args;\n switch (method) {\n case \"eth_chainId\":\n return this.chain.id;\n case \"eth_sendTransaction\":\n const [tx] = params as [RpcTransactionRequest];\n return this.sendTransaction(tx);\n case \"eth_signTypedData_v4\":\n //@ts-expect-error\n return this.signTypedData(JSON.parse(params[1]));\n case \"personal_sign\":\n if (!this.account) {\n throw new Error(\"account not connected!\");\n }\n const [data, address] = params!;\n if (address.toLowerCase() !== (await this.getAddress()).toLowerCase()) {\n throw new Error(\n \"cannot sign for address that is not the current account\"\n );\n }\n // @ts-ignore\n return this.account.signMessageWith6492(data);\n default:\n // @ts-ignore\n return this.rpcClient.request(args);\n }\n };\n}\n"]}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { type Address, type Chain, type Hash, type HttpTransport, type RpcTransactionRequest } from "viem";
|
|
2
|
-
import { type SmartAccountProviderOpts, type UserOperationCallData, type BatchUserOperationCallData, type SendUserOperationResult, SmartAccountProvider, type AccountMiddlewareFn, type UserOperationOverrides } from "@alchemy/aa-core";
|
|
2
|
+
import { type SmartAccountProviderOpts, type UserOperationCallData, type BatchUserOperationCallData, type SendUserOperationResult, type UserOperationStruct, SmartAccountProvider, type AccountMiddlewareFn, type UserOperationOverrides } from "@alchemy/aa-core";
|
|
3
3
|
import { KernelSmartContractAccount } from "./account.js";
|
|
4
4
|
import type { PaymasterAndBundlerProviders, PaymasterConfig, PaymasterPolicy } from "./paymaster/types.js";
|
|
5
5
|
export type ZeroDevProviderConfig = {
|
|
@@ -26,6 +26,8 @@ export declare class ZeroDevProvider extends SmartAccountProvider<HttpTransport>
|
|
|
26
26
|
constructor({ projectId, chain, entryPointAddress, rpcUrl, account, bundlerProvider, opts, }: ZeroDevProviderConfig);
|
|
27
27
|
getProjectId: () => string;
|
|
28
28
|
sendTransaction: (request: RpcTransactionRequest, operation?: UserOpDataOperationTypes<UserOperationCallData>) => Promise<Hash>;
|
|
29
|
+
buildUserOperation: <T extends UserOperationCallData | BatchUserOperationCallData>(data: T, overrides?: UserOperationOverrides, operation?: UserOpDataOperationTypes<T>) => Promise<UserOperationStruct>;
|
|
30
|
+
private _runMiddlewareStack;
|
|
29
31
|
sendUserOperation: <T extends UserOperationCallData | BatchUserOperationCallData>(data: T, overrides?: UserOperationOverrides, operation?: UserOpDataOperationTypes<T>) => Promise<SendUserOperationResult>;
|
|
30
32
|
isReplacementOpError(errorIn: any): boolean;
|
|
31
33
|
unwrapError(errorIn: any): Error;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"provider.d.ts","sourceRoot":"","sources":["../../../src/kernel-zerodev/provider.ts"],"names":[],"mappings":"AAAA,OAAO,EAEL,KAAK,OAAO,EACZ,KAAK,KAAK,EACV,KAAK,IAAI,EAET,KAAK,aAAa,EAClB,KAAK,qBAAqB,EAC3B,MAAM,MAAM,CAAC;AACd,OAAO,EAGL,KAAK,wBAAwB,EAE7B,KAAK,qBAAqB,EAC1B,KAAK,0BAA0B,EAC/B,KAAK,uBAAuB,
|
|
1
|
+
{"version":3,"file":"provider.d.ts","sourceRoot":"","sources":["../../../src/kernel-zerodev/provider.ts"],"names":[],"mappings":"AAAA,OAAO,EAEL,KAAK,OAAO,EACZ,KAAK,KAAK,EACV,KAAK,IAAI,EAET,KAAK,aAAa,EAClB,KAAK,qBAAqB,EAC3B,MAAM,MAAM,CAAC;AACd,OAAO,EAGL,KAAK,wBAAwB,EAE7B,KAAK,qBAAqB,EAC1B,KAAK,0BAA0B,EAC/B,KAAK,uBAAuB,EAG5B,KAAK,mBAAmB,EAExB,oBAAoB,EACpB,KAAK,mBAAmB,EACxB,KAAK,sBAAsB,EAC5B,MAAM,kBAAkB,CAAC;AAQ1B,OAAO,EAAE,0BAA0B,EAAmB,MAAM,cAAc,CAAC;AAM3E,OAAO,KAAK,EACV,4BAA4B,EAC5B,eAAe,EACf,eAAe,EAChB,MAAM,sBAAsB,CAAC;AAE9B,MAAM,MAAM,qBAAqB,GAAG;IAClC,SAAS,EAAE,MAAM,CAAC;IAClB,KAAK,EAAE,KAAK,GAAG,MAAM,CAAC;IACtB,iBAAiB,CAAC,EAAE,OAAO,CAAC;IAC5B,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,OAAO,CAAC,EAAE,0BAA0B,CAAC;IACrC,eAAe,CAAC,EAAE,4BAA4B,CAAC;IAC/C,IAAI,CAA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M,EAAE,MAAM,CAAC;QAAC,MAAM,CAAC,EAAE,GAAG,EAAE,CAAA;KAAE,KAAK,OAAO,CAAC,GAAG,CAAC,CA6BjE;CACH"}
|
package/package.json
CHANGED
|
@@ -137,6 +137,80 @@ export class ZeroDevProvider extends SmartAccountProvider<HttpTransport> {
|
|
|
137
137
|
return await this.waitForUserOperationTransaction(hash as Hash);
|
|
138
138
|
};
|
|
139
139
|
|
|
140
|
+
buildUserOperation = async <
|
|
141
|
+
T extends UserOperationCallData | BatchUserOperationCallData
|
|
142
|
+
>(
|
|
143
|
+
data: T,
|
|
144
|
+
overrides?: UserOperationOverrides,
|
|
145
|
+
operation: UserOpDataOperationTypes<T> = Operation.Call as UserOpDataOperationTypes<T>
|
|
146
|
+
): Promise<UserOperationStruct> => {
|
|
147
|
+
if (!isKernelAccount(this.account)) {
|
|
148
|
+
throw new Error("account not connected!");
|
|
149
|
+
}
|
|
150
|
+
if (!this.account.validator) {
|
|
151
|
+
throw new Error("validator not connected!");
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
let callData: BytesLike = "0x";
|
|
155
|
+
|
|
156
|
+
if (Array.isArray(data)) {
|
|
157
|
+
if (operation === Operation.Call) {
|
|
158
|
+
callData = await this.account.encodeBatchExecute(data);
|
|
159
|
+
} else {
|
|
160
|
+
throw InvalidOperation;
|
|
161
|
+
}
|
|
162
|
+
} else if (isKernelAccount(this.account)) {
|
|
163
|
+
if (operation === Operation.DelegateCall) {
|
|
164
|
+
callData = await this.account.encodeExecuteDelegate(
|
|
165
|
+
data.target,
|
|
166
|
+
data.value ?? 0n,
|
|
167
|
+
data.data
|
|
168
|
+
);
|
|
169
|
+
} else if (operation === Operation.Call) {
|
|
170
|
+
callData = await this.account.encodeExecute(
|
|
171
|
+
data.target,
|
|
172
|
+
data.value ?? 0n,
|
|
173
|
+
data.data
|
|
174
|
+
);
|
|
175
|
+
} else {
|
|
176
|
+
throw InvalidOperation;
|
|
177
|
+
}
|
|
178
|
+
} else {
|
|
179
|
+
throw InvalidOperation;
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
const initCode = await this.account.getInitCode();
|
|
183
|
+
const nonce = await this.account.getNonce();
|
|
184
|
+
return await this._runMiddlewareStack(
|
|
185
|
+
{
|
|
186
|
+
initCode,
|
|
187
|
+
sender: this.getAddress(),
|
|
188
|
+
nonce,
|
|
189
|
+
callData,
|
|
190
|
+
signature: await this.account
|
|
191
|
+
.getValidator()
|
|
192
|
+
.getDynamicDummySignature(await this.getAddress(), callData as Hex),
|
|
193
|
+
} as UserOperationStruct,
|
|
194
|
+
overrides
|
|
195
|
+
);
|
|
196
|
+
};
|
|
197
|
+
|
|
198
|
+
private _runMiddlewareStack = async (
|
|
199
|
+
uo: UserOperationStruct,
|
|
200
|
+
overrides?: UserOperationOverrides
|
|
201
|
+
): Promise<UserOperationStruct> => {
|
|
202
|
+
const result = await asyncPipe(
|
|
203
|
+
this.dummyPaymasterDataMiddleware,
|
|
204
|
+
this.feeDataGetter,
|
|
205
|
+
this.paymasterDataMiddleware,
|
|
206
|
+
this.gasEstimator,
|
|
207
|
+
this.customMiddleware ?? noOpMiddleware,
|
|
208
|
+
async (struct) => ({ ...struct, ...overrides })
|
|
209
|
+
)(uo);
|
|
210
|
+
|
|
211
|
+
return deepHexlify(await resolveProperties<UserOperationStruct>(result));
|
|
212
|
+
};
|
|
213
|
+
|
|
140
214
|
sendUserOperation = async <
|
|
141
215
|
T extends UserOperationCallData | BatchUserOperationCallData
|
|
142
216
|
>(
|