@dynamic-labs/ethereum-aa 2.1.0-alpha.8 → 2.1.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.
- package/CHANGELOG.md +264 -0
- package/package.json +13 -13
- package/src/ZeroDevConnector.cjs +24 -14
- package/src/ZeroDevConnector.d.ts +2793 -10
- package/src/ZeroDevConnector.js +20 -10
- package/src/index.d.ts +1 -1
- package/src/utils/createEcsdaKernelAccountClient.cjs +76 -0
- package/src/utils/createEcsdaKernelAccountClient.d.ts +19 -0
- package/src/utils/createEcsdaKernelAccountClient.js +70 -0
- package/src/utils/index.d.ts +1 -0
package/src/ZeroDevConnector.js
CHANGED
|
@@ -1,18 +1,19 @@
|
|
|
1
1
|
'use client'
|
|
2
2
|
import { __awaiter } from '../_virtual/_tslib.js';
|
|
3
|
-
import { createEcdsaKernelAccountClient } from '@zerodev/presets';
|
|
4
3
|
import { publicActions, custom, createWalletClient, isHex, fromHex, formatEther } from 'viem';
|
|
5
|
-
import { walletClientToSmartAccountSigner } from 'permissionless';
|
|
4
|
+
import { ENTRYPOINT_ADDRESS_V06, ENTRYPOINT_ADDRESS_V07, walletClientToSmartAccountSigner } from 'permissionless/utils';
|
|
5
|
+
import { ProviderEntryPointVersionEnum } from '@dynamic-labs/sdk-api-core';
|
|
6
6
|
import { WalletConnectorBase } from '@dynamic-labs/wallet-connector-core';
|
|
7
7
|
import { confirmationTransport, chainsMap, unFormatTransaction, createViemUiTransaction } from '@dynamic-labs/viem-utils';
|
|
8
8
|
import { parseEvmNetworks, DynamicError, DeferredPromise, wrapMethodWithCallback, TransactionGasCannotBeSponsoredError, InsufficientFundsError } from '@dynamic-labs/utils';
|
|
9
9
|
import { isEthWalletConnector } from '@dynamic-labs/ethereum';
|
|
10
10
|
import { cachedChainIdKey, fetchChain } from './utils/fetchChain.js';
|
|
11
11
|
import { logger } from './utils/logger.js';
|
|
12
|
+
import { createEcdsaKernelAccountClient } from './utils/createEcsdaKernelAccountClient.js';
|
|
12
13
|
|
|
13
14
|
class ZeroDevConnector extends WalletConnectorBase {
|
|
14
15
|
constructor(opts) {
|
|
15
|
-
var _a;
|
|
16
|
+
var _a, _b;
|
|
16
17
|
super(opts);
|
|
17
18
|
this.connectedChain = 'EVM';
|
|
18
19
|
this.supportedChains = ['ETH', 'EVM'];
|
|
@@ -34,6 +35,11 @@ class ZeroDevConnector extends WalletConnectorBase {
|
|
|
34
35
|
this.projectId = zeroDevProjectId;
|
|
35
36
|
this._walletUiUtils = opts.walletUiUtils;
|
|
36
37
|
this.evmNetworks = parseEvmNetworks(opts.evmNetworks);
|
|
38
|
+
this.entryPoint =
|
|
39
|
+
((_b = opts.apiProviders.zerodev) === null || _b === void 0 ? void 0 : _b.entryPointVersion) ===
|
|
40
|
+
ProviderEntryPointVersionEnum.V6
|
|
41
|
+
? ENTRYPOINT_ADDRESS_V06
|
|
42
|
+
: ENTRYPOINT_ADDRESS_V07;
|
|
37
43
|
}
|
|
38
44
|
getEOAConnector() {
|
|
39
45
|
return this.eoaConnector;
|
|
@@ -65,6 +71,7 @@ class ZeroDevConnector extends WalletConnectorBase {
|
|
|
65
71
|
}
|
|
66
72
|
const kernelClient = yield createEcdsaKernelAccountClient({
|
|
67
73
|
chain: yield fetchChain(this.projectId),
|
|
74
|
+
entryPointAddress: this.entryPoint,
|
|
68
75
|
paymaster: 'NONE',
|
|
69
76
|
projectId: this.projectId,
|
|
70
77
|
provider: ZeroDevConnector.bundlerProvider,
|
|
@@ -102,6 +109,7 @@ class ZeroDevConnector extends WalletConnectorBase {
|
|
|
102
109
|
const signer = yield eoaConnector.getSigner();
|
|
103
110
|
this.kernelClientWithSponsorship = yield createEcdsaKernelAccountClient({
|
|
104
111
|
chain: yield fetchChain(this.projectId),
|
|
112
|
+
entryPointAddress: this.entryPoint,
|
|
105
113
|
paymaster: 'SPONSOR',
|
|
106
114
|
projectId: this.projectId,
|
|
107
115
|
provider: ZeroDevConnector.bundlerProvider,
|
|
@@ -201,7 +209,8 @@ class ZeroDevConnector extends WalletConnectorBase {
|
|
|
201
209
|
}
|
|
202
210
|
getPublicClient() {
|
|
203
211
|
return __awaiter(this, void 0, void 0, function* () {
|
|
204
|
-
|
|
212
|
+
var _a;
|
|
213
|
+
const provider = (_a = this.kernelClient) === null || _a === void 0 ? void 0 : _a.extend(publicActions);
|
|
205
214
|
if (!provider)
|
|
206
215
|
throw new DynamicError('No provider');
|
|
207
216
|
return provider;
|
|
@@ -215,9 +224,9 @@ class ZeroDevConnector extends WalletConnectorBase {
|
|
|
215
224
|
canSponsorTransactionGas(transaction) {
|
|
216
225
|
return __awaiter(this, void 0, void 0, function* () {
|
|
217
226
|
try {
|
|
218
|
-
yield this.getKernelClientWithSponsorshipValidation();
|
|
227
|
+
const kernelClientWithSponsorship = yield this.getKernelClientWithSponsorshipValidation();
|
|
219
228
|
const userOperation = {
|
|
220
|
-
callData: yield
|
|
229
|
+
callData: yield kernelClientWithSponsorship.account.encodeCallData({
|
|
221
230
|
data: transaction.data ? transaction.data : '0x',
|
|
222
231
|
to: transaction.to,
|
|
223
232
|
/**
|
|
@@ -226,11 +235,11 @@ class ZeroDevConnector extends WalletConnectorBase {
|
|
|
226
235
|
*/
|
|
227
236
|
value: transaction.value && isHex(transaction.value)
|
|
228
237
|
? fromHex(transaction.value, 'bigint')
|
|
229
|
-
: '0x0',
|
|
238
|
+
: fromHex('0x0', 'bigint'),
|
|
230
239
|
}),
|
|
231
240
|
};
|
|
232
|
-
const result = yield
|
|
233
|
-
account:
|
|
241
|
+
const result = yield kernelClientWithSponsorship.prepareUserOperationRequest({
|
|
242
|
+
account: kernelClientWithSponsorship.account,
|
|
234
243
|
userOperation,
|
|
235
244
|
});
|
|
236
245
|
if (!result)
|
|
@@ -248,7 +257,8 @@ class ZeroDevConnector extends WalletConnectorBase {
|
|
|
248
257
|
}
|
|
249
258
|
getBalance() {
|
|
250
259
|
return __awaiter(this, void 0, void 0, function* () {
|
|
251
|
-
|
|
260
|
+
var _a;
|
|
261
|
+
const rpcClient = (_a = this.kernelClient) === null || _a === void 0 ? void 0 : _a.extend(publicActions);
|
|
252
262
|
if (!rpcClient)
|
|
253
263
|
throw new DynamicError('No RPC client');
|
|
254
264
|
const address = yield this.getAddress();
|
package/src/index.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { Provider as BundlerProvider } from '@zerodev/presets';
|
|
2
1
|
import { WalletConnectorConstructor } from '@dynamic-labs/wallet-connector-core';
|
|
2
|
+
import { BundlerProvider } from './utils';
|
|
3
3
|
export * from './ethereum-aa';
|
|
4
4
|
export { isZeroDevConnector } from './utils/isZeroDevConnector';
|
|
5
5
|
export declare const ZeroDevSmartWalletConnectorsWithConfig: ({ bundlerProvider, }?: {
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
'use client'
|
|
2
|
+
'use strict';
|
|
3
|
+
|
|
4
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
|
5
|
+
|
|
6
|
+
var _tslib = require('../../_virtual/_tslib.cjs');
|
|
7
|
+
var ecdsaValidator = require('@zerodev/ecdsa-validator');
|
|
8
|
+
var accounts = require('@zerodev/sdk/accounts');
|
|
9
|
+
var clients = require('@zerodev/sdk/clients');
|
|
10
|
+
var viem = require('viem');
|
|
11
|
+
|
|
12
|
+
const getZeroDevBundlerRPC = (projectId, provider) => {
|
|
13
|
+
let rpc = `https://rpc.zerodev.app/api/v2/bundler/${projectId}`;
|
|
14
|
+
if (provider) {
|
|
15
|
+
rpc += `?bundlerProvider=${provider}`;
|
|
16
|
+
}
|
|
17
|
+
return rpc;
|
|
18
|
+
};
|
|
19
|
+
const getZeroDevPaymasterRPC = (projectId, provider) => {
|
|
20
|
+
let rpc = `https://rpc.zerodev.app/api/v2/paymaster/${projectId}`;
|
|
21
|
+
if (provider) {
|
|
22
|
+
rpc += `?paymasterProvider=${provider}`;
|
|
23
|
+
}
|
|
24
|
+
return rpc;
|
|
25
|
+
};
|
|
26
|
+
const isERC20 = (value) => viem.isAddress(value);
|
|
27
|
+
const createEcdsaKernelAccountClient = (_a) => _tslib.__awaiter(void 0, [_a], void 0, function* ({ chain, projectId, signer, provider, index, paymaster = 'SPONSOR', entryPointAddress, }) {
|
|
28
|
+
const publicClient = viem.createPublicClient({
|
|
29
|
+
transport: viem.http(getZeroDevBundlerRPC(projectId, provider)),
|
|
30
|
+
});
|
|
31
|
+
const ecdsaValidator$1 = yield ecdsaValidator.signerToEcdsaValidator(publicClient, {
|
|
32
|
+
entryPoint: entryPointAddress,
|
|
33
|
+
signer,
|
|
34
|
+
});
|
|
35
|
+
const account = yield accounts.createKernelAccount(publicClient, {
|
|
36
|
+
entryPoint: entryPointAddress,
|
|
37
|
+
index,
|
|
38
|
+
plugins: {
|
|
39
|
+
sudo: ecdsaValidator$1,
|
|
40
|
+
},
|
|
41
|
+
});
|
|
42
|
+
const zerodevPaymaster = clients.createZeroDevPaymasterClient({
|
|
43
|
+
chain: chain,
|
|
44
|
+
entryPoint: entryPointAddress,
|
|
45
|
+
transport: viem.http(getZeroDevPaymasterRPC(projectId, provider)),
|
|
46
|
+
});
|
|
47
|
+
const kernelClient = clients.createKernelAccountClient({
|
|
48
|
+
account,
|
|
49
|
+
bundlerTransport: viem.http(getZeroDevBundlerRPC(projectId, provider)),
|
|
50
|
+
chain,
|
|
51
|
+
entryPoint: entryPointAddress,
|
|
52
|
+
middleware: paymaster !== 'NONE'
|
|
53
|
+
? {
|
|
54
|
+
sponsorUserOperation: (_b) => _tslib.__awaiter(void 0, [_b], void 0, function* ({ userOperation }) {
|
|
55
|
+
const _userOperation = userOperation;
|
|
56
|
+
if (isERC20(paymaster)) {
|
|
57
|
+
return zerodevPaymaster.sponsorUserOperation({
|
|
58
|
+
entryPoint: entryPointAddress,
|
|
59
|
+
gasToken: paymaster,
|
|
60
|
+
userOperation: _userOperation,
|
|
61
|
+
});
|
|
62
|
+
}
|
|
63
|
+
return zerodevPaymaster.sponsorUserOperation({
|
|
64
|
+
entryPoint: entryPointAddress,
|
|
65
|
+
userOperation: _userOperation,
|
|
66
|
+
});
|
|
67
|
+
}),
|
|
68
|
+
}
|
|
69
|
+
: undefined,
|
|
70
|
+
});
|
|
71
|
+
return kernelClient;
|
|
72
|
+
});
|
|
73
|
+
|
|
74
|
+
exports.createEcdsaKernelAccountClient = createEcdsaKernelAccountClient;
|
|
75
|
+
exports.getZeroDevBundlerRPC = getZeroDevBundlerRPC;
|
|
76
|
+
exports.getZeroDevPaymasterRPC = getZeroDevPaymasterRPC;
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { KernelSmartAccount } from '@zerodev/sdk/accounts';
|
|
2
|
+
import { KernelAccountClient } from '@zerodev/sdk/clients';
|
|
3
|
+
import { SmartAccountSigner } from 'permissionless/accounts';
|
|
4
|
+
import { EntryPoint } from 'permissionless/types';
|
|
5
|
+
import { Address, HttpTransport, Chain } from 'viem';
|
|
6
|
+
export type BundlerProvider = 'STACKUP' | 'PIMLICO' | 'ALCHEMY' | 'GELATO';
|
|
7
|
+
export type ERC20Paymaster = Address;
|
|
8
|
+
export type PaymasterType = 'NONE' | 'SPONSOR' | ERC20Paymaster;
|
|
9
|
+
export declare const getZeroDevBundlerRPC: (projectId: string, provider?: BundlerProvider) => string;
|
|
10
|
+
export declare const getZeroDevPaymasterRPC: (projectId: string, provider?: BundlerProvider) => string;
|
|
11
|
+
export declare const createEcdsaKernelAccountClient: <entryPoint extends EntryPoint, TChain extends Chain | undefined = Chain | undefined, TSource extends string = "custom", TAddress extends `0x${string}` = `0x${string}`>({ chain, projectId, signer, provider, index, paymaster, entryPointAddress, }: {
|
|
12
|
+
chain: TChain;
|
|
13
|
+
projectId: string;
|
|
14
|
+
signer: SmartAccountSigner<TSource, TAddress>;
|
|
15
|
+
paymaster: PaymasterType;
|
|
16
|
+
entryPointAddress: entryPoint;
|
|
17
|
+
provider?: BundlerProvider;
|
|
18
|
+
index?: bigint;
|
|
19
|
+
}) => Promise<KernelAccountClient<entryPoint, HttpTransport, TChain, KernelSmartAccount<entryPoint, HttpTransport, TChain>>>;
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
'use client'
|
|
2
|
+
import { __awaiter } from '../../_virtual/_tslib.js';
|
|
3
|
+
import { signerToEcdsaValidator } from '@zerodev/ecdsa-validator';
|
|
4
|
+
import { createKernelAccount } from '@zerodev/sdk/accounts';
|
|
5
|
+
import { createZeroDevPaymasterClient, createKernelAccountClient } from '@zerodev/sdk/clients';
|
|
6
|
+
import { createPublicClient, http, isAddress } from 'viem';
|
|
7
|
+
|
|
8
|
+
const getZeroDevBundlerRPC = (projectId, provider) => {
|
|
9
|
+
let rpc = `https://rpc.zerodev.app/api/v2/bundler/${projectId}`;
|
|
10
|
+
if (provider) {
|
|
11
|
+
rpc += `?bundlerProvider=${provider}`;
|
|
12
|
+
}
|
|
13
|
+
return rpc;
|
|
14
|
+
};
|
|
15
|
+
const getZeroDevPaymasterRPC = (projectId, provider) => {
|
|
16
|
+
let rpc = `https://rpc.zerodev.app/api/v2/paymaster/${projectId}`;
|
|
17
|
+
if (provider) {
|
|
18
|
+
rpc += `?paymasterProvider=${provider}`;
|
|
19
|
+
}
|
|
20
|
+
return rpc;
|
|
21
|
+
};
|
|
22
|
+
const isERC20 = (value) => isAddress(value);
|
|
23
|
+
const createEcdsaKernelAccountClient = (_a) => __awaiter(void 0, [_a], void 0, function* ({ chain, projectId, signer, provider, index, paymaster = 'SPONSOR', entryPointAddress, }) {
|
|
24
|
+
const publicClient = createPublicClient({
|
|
25
|
+
transport: http(getZeroDevBundlerRPC(projectId, provider)),
|
|
26
|
+
});
|
|
27
|
+
const ecdsaValidator = yield signerToEcdsaValidator(publicClient, {
|
|
28
|
+
entryPoint: entryPointAddress,
|
|
29
|
+
signer,
|
|
30
|
+
});
|
|
31
|
+
const account = yield createKernelAccount(publicClient, {
|
|
32
|
+
entryPoint: entryPointAddress,
|
|
33
|
+
index,
|
|
34
|
+
plugins: {
|
|
35
|
+
sudo: ecdsaValidator,
|
|
36
|
+
},
|
|
37
|
+
});
|
|
38
|
+
const zerodevPaymaster = createZeroDevPaymasterClient({
|
|
39
|
+
chain: chain,
|
|
40
|
+
entryPoint: entryPointAddress,
|
|
41
|
+
transport: http(getZeroDevPaymasterRPC(projectId, provider)),
|
|
42
|
+
});
|
|
43
|
+
const kernelClient = createKernelAccountClient({
|
|
44
|
+
account,
|
|
45
|
+
bundlerTransport: http(getZeroDevBundlerRPC(projectId, provider)),
|
|
46
|
+
chain,
|
|
47
|
+
entryPoint: entryPointAddress,
|
|
48
|
+
middleware: paymaster !== 'NONE'
|
|
49
|
+
? {
|
|
50
|
+
sponsorUserOperation: (_b) => __awaiter(void 0, [_b], void 0, function* ({ userOperation }) {
|
|
51
|
+
const _userOperation = userOperation;
|
|
52
|
+
if (isERC20(paymaster)) {
|
|
53
|
+
return zerodevPaymaster.sponsorUserOperation({
|
|
54
|
+
entryPoint: entryPointAddress,
|
|
55
|
+
gasToken: paymaster,
|
|
56
|
+
userOperation: _userOperation,
|
|
57
|
+
});
|
|
58
|
+
}
|
|
59
|
+
return zerodevPaymaster.sponsorUserOperation({
|
|
60
|
+
entryPoint: entryPointAddress,
|
|
61
|
+
userOperation: _userOperation,
|
|
62
|
+
});
|
|
63
|
+
}),
|
|
64
|
+
}
|
|
65
|
+
: undefined,
|
|
66
|
+
});
|
|
67
|
+
return kernelClient;
|
|
68
|
+
});
|
|
69
|
+
|
|
70
|
+
export { createEcdsaKernelAccountClient, getZeroDevBundlerRPC, getZeroDevPaymasterRPC };
|
package/src/utils/index.d.ts
CHANGED