@getpara/aa-zerodev 2.16.0

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.
@@ -0,0 +1,24 @@
1
+ import { type KernelAccountClient } from '@zerodev/sdk';
2
+ import type { SmartAccount4337, SmartAccount7702 } from '@getpara/viem-v2-integration';
3
+ import type { CreateZeroDevSmartAccountParams } from './types.js';
4
+ export type { CreateZeroDevSmartAccountParams, ZeroDevTransactionOptions } from './types.js';
5
+ /**
6
+ * Returns the ZeroDev RPC URL for a given project ID and chain.
7
+ */
8
+ export declare function getZeroDevRpcUrl(projectId: string, chainId: number): string;
9
+ /**
10
+ * Creates a ZeroDev smart account using Para for signing.
11
+ *
12
+ * Returns a unified SmartAccount interface. Supports gas sponsorship via ZeroDev's
13
+ * paymaster with EntryPoint v0.7.
14
+ *
15
+ * @param params - Configuration parameters
16
+ * @returns Unified SmartAccount interface (4337 or 7702) or null if no EVM wallet exists
17
+ */
18
+ export declare function createZeroDevSmartAccount(params: CreateZeroDevSmartAccountParams & {
19
+ mode: '7702';
20
+ }): Promise<SmartAccount7702<KernelAccountClient> | null>;
21
+ export declare function createZeroDevSmartAccount(params: CreateZeroDevSmartAccountParams & {
22
+ mode?: '4337';
23
+ }): Promise<SmartAccount4337<KernelAccountClient> | null>;
24
+ export declare function createZeroDevSmartAccount(params: CreateZeroDevSmartAccountParams): Promise<SmartAccount4337<KernelAccountClient> | SmartAccount7702<KernelAccountClient> | null>;
package/dist/action.js ADDED
@@ -0,0 +1,104 @@
1
+ import {
2
+ createKernelAccount,
3
+ createKernelAccountClient,
4
+ createZeroDevPaymasterClient
5
+ } from "@zerodev/sdk";
6
+ import { KERNEL_V3_1, KERNEL_V3_3, KERNEL_7702_DELEGATION_ADDRESS } from "@zerodev/sdk/constants";
7
+ import { signerToEcdsaValidator } from "@zerodev/ecdsa-validator";
8
+ import { createParaAccount } from "@getpara/viem-v2-integration";
9
+ import { SmartAccountError, wrapProviderError, resolveWalletIdentifier } from "@getpara/viem-v2-integration";
10
+ import { createPublicClient, http } from "viem";
11
+ function getZeroDevRpcUrl(projectId, chainId) {
12
+ return `https://rpc.zerodev.app/api/v3/${projectId}/chain/${chainId}`;
13
+ }
14
+ const ENTRYPOINT_V07 = {
15
+ address: "0x0000000071727De22E5E9d8BAf0edAc6f37da032",
16
+ version: "0.7"
17
+ };
18
+ async function createZeroDevSmartAccount(params) {
19
+ const { para, projectId, chain, rpcUrl, bundlerUrl, paymasterUrl, mode } = params;
20
+ const walletAddress = resolveWalletIdentifier(para, params);
21
+ if (!walletAddress) return null;
22
+ const viemAccount = createParaAccount(para, walletAddress);
23
+ const _rpcUrl = rpcUrl || getZeroDevRpcUrl(projectId, chain.id);
24
+ const publicClient = createPublicClient({ chain, transport: http(_rpcUrl) });
25
+ const ecdsaValidator = await signerToEcdsaValidator(publicClient, {
26
+ signer: viemAccount,
27
+ entryPoint: ENTRYPOINT_V07,
28
+ kernelVersion: mode === "7702" ? KERNEL_V3_3 : KERNEL_V3_1
29
+ });
30
+ const kernelAccount = await createKernelAccount(publicClient, {
31
+ plugins: {
32
+ sudo: ecdsaValidator
33
+ },
34
+ entryPoint: ENTRYPOINT_V07,
35
+ kernelVersion: mode === "7702" ? KERNEL_V3_3 : KERNEL_V3_1,
36
+ ...mode === "7702" && {
37
+ eip7702Account: viemAccount
38
+ }
39
+ });
40
+ const zeroDevRpcUrl = getZeroDevRpcUrl(projectId, chain.id);
41
+ const _bundlerUrl = bundlerUrl || zeroDevRpcUrl;
42
+ const _paymasterUrl = paymasterUrl || zeroDevRpcUrl;
43
+ const kernelClient = createKernelAccountClient({
44
+ account: kernelAccount,
45
+ chain,
46
+ bundlerTransport: http(_bundlerUrl),
47
+ client: publicClient,
48
+ paymaster: {
49
+ getPaymasterData: async (userOperation) => {
50
+ const zerodevPaymaster = createZeroDevPaymasterClient({
51
+ chain,
52
+ transport: http(_paymasterUrl)
53
+ });
54
+ return zerodevPaymaster.sponsorUserOperation({ userOperation });
55
+ }
56
+ }
57
+ });
58
+ if (!kernelClient.account?.address) {
59
+ throw new SmartAccountError({
60
+ code: "MISSING_ACCOUNT_ADDRESS",
61
+ message: "ZeroDev client must have an account address",
62
+ provider: "ZERODEV"
63
+ });
64
+ }
65
+ const accountAddress = kernelClient.account.address;
66
+ const doSendAndWait = async (calls) => {
67
+ if (!("sendUserOperation" in kernelClient && typeof kernelClient.sendUserOperation === "function")) {
68
+ throw new SmartAccountError({
69
+ code: "INVALID_CONFIG",
70
+ message: "sendUserOperation not available on client",
71
+ provider: "ZERODEV"
72
+ });
73
+ }
74
+ try {
75
+ const hash = await kernelClient.sendUserOperation({ calls });
76
+ if ("waitForUserOperationReceipt" in kernelClient && typeof kernelClient.waitForUserOperationReceipt === "function") {
77
+ const result = await kernelClient.waitForUserOperationReceipt({ hash });
78
+ return result.receipt;
79
+ }
80
+ return publicClient.getTransactionReceipt({ hash });
81
+ } catch (error) {
82
+ throw wrapProviderError(error, "ZERODEV");
83
+ }
84
+ };
85
+ return {
86
+ smartAccountAddress: accountAddress,
87
+ signer: viemAccount,
88
+ chain,
89
+ mode: mode || "4337",
90
+ provider: "ZERODEV",
91
+ ...mode === "7702" && { delegationAddress: KERNEL_7702_DELEGATION_ADDRESS },
92
+ async sendTransaction({ to, value, data }) {
93
+ return doSendAndWait([{ to, value: value || BigInt(0), data: data || "0x" }]);
94
+ },
95
+ async sendBatchTransaction(calls) {
96
+ return doSendAndWait(calls.map((c) => ({ to: c.to, value: c.value || BigInt(0), data: c.data || "0x" })));
97
+ },
98
+ client: kernelClient
99
+ };
100
+ }
101
+ export {
102
+ createZeroDevSmartAccount,
103
+ getZeroDevRpcUrl
104
+ };
@@ -0,0 +1,2 @@
1
+ export { createZeroDevSmartAccount, getZeroDevRpcUrl } from './action.js';
2
+ export type { ZeroDevSmartAccountConfig, CreateZeroDevSmartAccountParams, UseZeroDevSmartAccountParams, ZeroDevTransactionOptions, } from './types.js';
package/dist/index.js ADDED
@@ -0,0 +1,5 @@
1
+ import { createZeroDevSmartAccount, getZeroDevRpcUrl } from "./action.js";
2
+ export {
3
+ createZeroDevSmartAccount,
4
+ getZeroDevRpcUrl
5
+ };
@@ -0,0 +1,3 @@
1
+ {
2
+ "type": "module"
3
+ }
@@ -0,0 +1,50 @@
1
+ import type { PaymasterSmartAccountConfig, CreateSmartAccountParams, SmartAccountModeParam } from '@getpara/viem-v2-integration';
2
+ /**
3
+ * Configuration for ZeroDev smart account.
4
+ *
5
+ * Supports both EIP-4337 and EIP-7702 modes. Uses ZeroDev's Kernel account
6
+ * with ECDSA validation and gas sponsorship via EntryPoint v0.7.
7
+ *
8
+ * @example
9
+ * ```ts
10
+ * const config: ZeroDevSmartAccountConfig = {
11
+ * projectId: 'YOUR_ZERODEV_PROJECT_ID',
12
+ * chain: sepolia,
13
+ * };
14
+ * ```
15
+ */
16
+ export interface ZeroDevSmartAccountConfig extends Omit<PaymasterSmartAccountConfig, 'rpcUrl'>, SmartAccountModeParam {
17
+ /** ZeroDev project ID */
18
+ projectId: string;
19
+ /**
20
+ * RPC URL for the chain. If not provided, defaults to ZeroDev's RPC
21
+ * (`https://rpc.zerodev.app/api/v3/{projectId}/chain/{chainId}`).
22
+ */
23
+ rpcUrl?: string;
24
+ }
25
+ /**
26
+ * Parameters for `createZeroDevSmartAccount`.
27
+ * Includes all config fields plus `para` (the Para SDK instance).
28
+ */
29
+ export type CreateZeroDevSmartAccountParams = CreateSmartAccountParams<ZeroDevSmartAccountConfig>;
30
+ /**
31
+ * Parameters for the `useZeroDevSmartAccount` hook.
32
+ * Same as {@link ZeroDevSmartAccountConfig} — `para` is provided automatically via context.
33
+ */
34
+ export type UseZeroDevSmartAccountParams = ZeroDevSmartAccountConfig;
35
+ /**
36
+ * ZeroDev-specific transaction options.
37
+ * Pass as the second argument to `sendTransaction` or `sendBatchTransaction`.
38
+ */
39
+ export interface ZeroDevTransactionOptions {
40
+ /** Custom sponsorship middleware */
41
+ middleware?: {
42
+ sponsorUserOperation?: (args: {
43
+ userOperation: any;
44
+ }) => Promise<any>;
45
+ };
46
+ /** Override paymaster address */
47
+ paymasterAddress?: `0x${string}`;
48
+ /** Override paymaster data */
49
+ paymasterData?: `0x${string}`;
50
+ }
package/dist/types.js ADDED
File without changes
package/package.json ADDED
@@ -0,0 +1,39 @@
1
+ {
2
+ "name": "@getpara/aa-zerodev",
3
+ "version": "2.16.0",
4
+ "description": "ZeroDev smart account integration for Para",
5
+ "type": "module",
6
+ "main": "dist/index.js",
7
+ "types": "dist/index.d.ts",
8
+ "sideEffects": false,
9
+ "files": [
10
+ "dist",
11
+ "package.json"
12
+ ],
13
+ "exports": {
14
+ ".": {
15
+ "types": "./dist/index.d.ts",
16
+ "import": "./dist/index.js"
17
+ }
18
+ },
19
+ "scripts": {
20
+ "build": "rm -rf dist && yarn typegen && node ./scripts/build.mjs",
21
+ "typegen": "tsc --emitDeclarationOnly --outDir dist",
22
+ "test": "vitest run --coverage"
23
+ },
24
+ "dependencies": {
25
+ "@getpara/viem-v2-integration": "2.16.0",
26
+ "@zerodev/ecdsa-validator": "^5.4.3",
27
+ "@zerodev/sdk": "^5.4.3"
28
+ },
29
+ "peerDependencies": {
30
+ "viem": ">=2.0.0"
31
+ },
32
+ "devDependencies": {
33
+ "typescript": "^5.8.3"
34
+ },
35
+ "publishConfig": {
36
+ "access": "public"
37
+ },
38
+ "gitHead": "fbe96a062b308d04105213378c12c38ee973c798"
39
+ }