@dynamic-labs/ethereum-aa 4.0.0-alpha.8 → 4.0.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 +496 -1
- package/package.cjs +1 -1
- package/package.js +1 -1
- package/package.json +13 -14
- package/src/ZeroDevConnector.cjs +159 -56
- package/src/ZeroDevConnector.d.ts +5774 -1112
- package/src/ZeroDevConnector.js +161 -58
- package/src/utils/createEcsdaKernelAccountClient.cjs +13 -11
- package/src/utils/createEcsdaKernelAccountClient.d.ts +12 -13
- package/src/utils/createEcsdaKernelAccountClient.js +13 -11
- package/src/utils/getEntryPoint.cjs +4 -4
- package/src/utils/getEntryPoint.d.ts +1 -1
- package/src/utils/getEntryPoint.js +4 -4
- package/src/utils/getKernelVersion.cjs +2 -3
- package/src/utils/getKernelVersion.d.ts +1 -1
- package/src/utils/getKernelVersion.js +3 -4
package/src/ZeroDevConnector.js
CHANGED
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
'use client'
|
|
2
2
|
import { __awaiter } from '../_virtual/_tslib.js';
|
|
3
|
-
import { publicActions, custom, createWalletClient,
|
|
4
|
-
import {
|
|
3
|
+
import { publicActions, custom, createWalletClient, toHex, formatEther } from 'viem';
|
|
4
|
+
import { toAccount } from 'viem/accounts';
|
|
5
|
+
import { getEntryPoint as getEntryPoint$1 } from '@zerodev/sdk/constants';
|
|
5
6
|
import { EthereumWallet, isEthWalletConnector, chainsMap, confirmationTransport, unFormatTransaction, createViemUiTransaction } from '@dynamic-labs/ethereum-core';
|
|
6
|
-
import { WalletConnectorBase, eventListenerHandlers
|
|
7
|
+
import { WalletConnectorBase, eventListenerHandlers } from '@dynamic-labs/wallet-connector-core';
|
|
7
8
|
import { parseEvmNetworks, StorageService, DeferredPromise, parseChainId, DynamicError, wrapMethodWithCallback, TransactionGasCannotBeSponsoredError, InsufficientFundsError } from '@dynamic-labs/utils';
|
|
8
9
|
import { ZERO_DEV_LAST_USED_CHAIN_ID_KEY } from './constants.js';
|
|
9
10
|
import { logger } from './utils/logger.js';
|
|
@@ -16,7 +17,10 @@ class ZeroDevConnector extends WalletConnectorBase {
|
|
|
16
17
|
constructor(opts) {
|
|
17
18
|
var _a, _b, _c, _d;
|
|
18
19
|
super(opts);
|
|
20
|
+
// provider map maintains the kernel clients per chain
|
|
19
21
|
this.providerMap = {};
|
|
22
|
+
// eoa connector map maintains the eoa address and connector for each smart wallet address
|
|
23
|
+
this.eoaConnectorMap = {};
|
|
20
24
|
this.ChainWallet = EthereumWallet;
|
|
21
25
|
this.connectedChain = 'EVM';
|
|
22
26
|
this.supportedChains = ['ETH', 'EVM'];
|
|
@@ -109,23 +113,54 @@ class ZeroDevConnector extends WalletConnectorBase {
|
|
|
109
113
|
StorageService.removeItem(ZERO_DEV_LAST_USED_CHAIN_ID_KEY);
|
|
110
114
|
});
|
|
111
115
|
}
|
|
112
|
-
|
|
113
|
-
return __awaiter(this,
|
|
116
|
+
registerEoa(_a) {
|
|
117
|
+
return __awaiter(this, arguments, void 0, function* ({ smartWalletAddress, eoaAddress, eoaConnector, shouldSetEoaConnector = false, ecdsaProviderType, kernelVersion, entryPointVersion, }) {
|
|
118
|
+
const properties = {
|
|
119
|
+
ecdsaProviderType,
|
|
120
|
+
entryPointVersion,
|
|
121
|
+
kernelVersion,
|
|
122
|
+
};
|
|
123
|
+
this.eoaConnectorMap[smartWalletAddress] = {
|
|
124
|
+
eoaAddress,
|
|
125
|
+
eoaConnector,
|
|
126
|
+
properties,
|
|
127
|
+
};
|
|
128
|
+
// if this is the primary wallet, set the eoa connector and kernel clients
|
|
129
|
+
if (shouldSetEoaConnector && this.eoaAddress !== eoaAddress) {
|
|
130
|
+
yield this.setEoaConnector({
|
|
131
|
+
connector: eoaConnector,
|
|
132
|
+
eoaAddress,
|
|
133
|
+
properties,
|
|
134
|
+
});
|
|
135
|
+
}
|
|
136
|
+
});
|
|
137
|
+
}
|
|
138
|
+
setEoaConnector(_a) {
|
|
139
|
+
return __awaiter(this, arguments, void 0, function* ({ eoaAddress, connector, properties, }) {
|
|
140
|
+
var _b;
|
|
114
141
|
if (!connector) {
|
|
115
142
|
logger.error('No EOA connector provided');
|
|
116
143
|
return;
|
|
117
144
|
}
|
|
118
145
|
this.kernelClientDeferredPromise = new DeferredPromise();
|
|
119
146
|
this.eoaConnector = connector;
|
|
147
|
+
this.eoaAddress = eoaAddress;
|
|
148
|
+
if (properties) {
|
|
149
|
+
this.ecdsaProviderType =
|
|
150
|
+
(_b = properties.ecdsaProviderType) !== null && _b !== void 0 ? _b : this.ecdsaProviderType;
|
|
151
|
+
this.entryPoint = properties.entryPointVersion
|
|
152
|
+
? getEntryPoint(properties.entryPointVersion)
|
|
153
|
+
: this.entryPoint;
|
|
154
|
+
this.kernelVersion = properties.entryPointVersion
|
|
155
|
+
? getKernelVersion(properties.kernelVersion, this.entryPoint)
|
|
156
|
+
: this.kernelVersion;
|
|
157
|
+
}
|
|
120
158
|
if (isEthWalletConnector(this.eoaConnector) &&
|
|
121
159
|
!this.eoaConnector.getActiveAccount()) {
|
|
122
160
|
yield this.eoaConnector.getConnectedAccounts();
|
|
123
161
|
}
|
|
124
162
|
const signer = yield this.eoaConnector.getSigner();
|
|
125
|
-
|
|
126
|
-
logger.error('No signer account found');
|
|
127
|
-
return;
|
|
128
|
-
}
|
|
163
|
+
signer.account = toAccount(eoaAddress);
|
|
129
164
|
yield this.generateProviderMap(signer);
|
|
130
165
|
this.evmNetworks = this.evmNetworks.filter((network) => Boolean(this.providerMap[network.chainId]));
|
|
131
166
|
this.kernelClientDeferredPromise.resolve();
|
|
@@ -147,23 +182,29 @@ class ZeroDevConnector extends WalletConnectorBase {
|
|
|
147
182
|
}
|
|
148
183
|
generateProviderMap(signer) {
|
|
149
184
|
return __awaiter(this, void 0, void 0, function* () {
|
|
150
|
-
|
|
185
|
+
// reset the chains provider map when eoa connector changes
|
|
186
|
+
this.providerMap = {};
|
|
187
|
+
yield Promise.all(this.providersFromApi.map((provider) => __awaiter(this, void 0, void 0, function* () {
|
|
151
188
|
if (!this.providerMap[provider.chain]) {
|
|
152
|
-
|
|
153
|
-
|
|
189
|
+
const [kernelClient, kernelClientWithSponsorship] = yield Promise.all([
|
|
190
|
+
this.getKernelClientWithoutSponsorshipValidation({
|
|
154
191
|
chainId: provider.chain,
|
|
155
192
|
projectId: provider.clientId,
|
|
156
193
|
signer,
|
|
157
194
|
}),
|
|
158
|
-
|
|
195
|
+
this.getKernelClientWithSponsorshipValidation({
|
|
159
196
|
chainId: provider.chain,
|
|
160
197
|
projectId: provider.clientId,
|
|
161
198
|
signer,
|
|
162
199
|
}),
|
|
200
|
+
]);
|
|
201
|
+
this.providerMap[provider.chain] = {
|
|
202
|
+
kernelClient,
|
|
203
|
+
kernelClientWithSponsorship,
|
|
163
204
|
};
|
|
164
205
|
}
|
|
165
206
|
yield this.warnIfProjectChainNotEnabled(parseChainId(provider.chain));
|
|
166
|
-
}
|
|
207
|
+
})));
|
|
167
208
|
});
|
|
168
209
|
}
|
|
169
210
|
getKernelClientWithoutSponsorshipValidation(_a) {
|
|
@@ -178,13 +219,13 @@ class ZeroDevConnector extends WalletConnectorBase {
|
|
|
178
219
|
bundlerRpc: ZeroDevConnector.bundlerRpc,
|
|
179
220
|
chain: chainsMap[chainId],
|
|
180
221
|
ecdsaValidator: getEcdsaValidator(this.ecdsaProviderType),
|
|
181
|
-
|
|
222
|
+
entryPoint: this.entryPoint,
|
|
182
223
|
kernelVersion: this.kernelVersion,
|
|
183
224
|
paymaster: 'NONE',
|
|
184
225
|
paymasterRpc: ZeroDevConnector.paymasterRpc,
|
|
185
226
|
projectId,
|
|
186
227
|
provider: ZeroDevConnector.bundlerProvider,
|
|
187
|
-
signer
|
|
228
|
+
signer,
|
|
188
229
|
});
|
|
189
230
|
wrapMethodWithCallback(kernelClient, 'sendUserOperation', (original, ...args) => {
|
|
190
231
|
this._walletUiUtils.disabledConfirmationOnce();
|
|
@@ -205,13 +246,13 @@ class ZeroDevConnector extends WalletConnectorBase {
|
|
|
205
246
|
bundlerRpc: ZeroDevConnector.bundlerRpc,
|
|
206
247
|
chain: chainsMap[chainId],
|
|
207
248
|
ecdsaValidator: getEcdsaValidator(this.ecdsaProviderType),
|
|
208
|
-
|
|
249
|
+
entryPoint: this.entryPoint,
|
|
209
250
|
kernelVersion: this.kernelVersion,
|
|
210
251
|
paymaster: 'SPONSOR',
|
|
211
252
|
paymasterRpc: ZeroDevConnector.paymasterRpc,
|
|
212
253
|
projectId,
|
|
213
254
|
provider: ZeroDevConnector.bundlerProvider,
|
|
214
|
-
signer
|
|
255
|
+
signer,
|
|
215
256
|
});
|
|
216
257
|
wrapMethodWithCallback(kernelClientWithSponsorship, 'sendUserOperation', (original, ...args) => {
|
|
217
258
|
this._walletUiUtils.disabledConfirmationOnce();
|
|
@@ -249,7 +290,6 @@ class ZeroDevConnector extends WalletConnectorBase {
|
|
|
249
290
|
onPersonalSign: (_a) => __awaiter(this, [_a], void 0, function* ({ message }) {
|
|
250
291
|
this._walletUiUtils.disabledConfirmationOnce();
|
|
251
292
|
return provider.signMessage({
|
|
252
|
-
account: provider.account,
|
|
253
293
|
message,
|
|
254
294
|
});
|
|
255
295
|
}),
|
|
@@ -280,7 +320,6 @@ class ZeroDevConnector extends WalletConnectorBase {
|
|
|
280
320
|
this._walletUiUtils.disabledConfirmationOnce();
|
|
281
321
|
const signTypedData = JSON.parse(message);
|
|
282
322
|
return provider.signTypedData({
|
|
283
|
-
account: provider.account,
|
|
284
323
|
domain: signTypedData.domain,
|
|
285
324
|
message: signTypedData.message,
|
|
286
325
|
primaryType: signTypedData.primaryType,
|
|
@@ -296,14 +335,12 @@ class ZeroDevConnector extends WalletConnectorBase {
|
|
|
296
335
|
return transport;
|
|
297
336
|
}
|
|
298
337
|
getWalletClient(chainId) {
|
|
299
|
-
var _a;
|
|
300
338
|
const provider = this.kernelClient;
|
|
301
339
|
if (!provider)
|
|
302
340
|
return undefined;
|
|
303
341
|
const transport = this.getTransport(provider);
|
|
304
|
-
const address = (_a = provider.account) === null || _a === void 0 ? void 0 : _a.address;
|
|
305
342
|
const walletClient = createWalletClient({
|
|
306
|
-
account: address,
|
|
343
|
+
account: toAccount(provider.account.address),
|
|
307
344
|
chain: chainId ? chainsMap[chainId] : provider.chain,
|
|
308
345
|
transport,
|
|
309
346
|
});
|
|
@@ -323,38 +360,109 @@ class ZeroDevConnector extends WalletConnectorBase {
|
|
|
323
360
|
return this.getWalletClient();
|
|
324
361
|
});
|
|
325
362
|
}
|
|
326
|
-
|
|
363
|
+
formatUserOperation(params) {
|
|
364
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
365
|
+
var _a;
|
|
366
|
+
const kernelAccount = (_a = this.getAccountAbstractionProvider()) === null || _a === void 0 ? void 0 : _a.account;
|
|
367
|
+
const entryPoint = kernelAccount === null || kernelAccount === void 0 ? void 0 : kernelAccount.entryPoint;
|
|
368
|
+
const isV6 = (entryPoint === null || entryPoint === void 0 ? void 0 : entryPoint.address.toLowerCase()) ===
|
|
369
|
+
getEntryPoint$1('0.6').address.toLowerCase();
|
|
370
|
+
if (isV6) {
|
|
371
|
+
return {
|
|
372
|
+
callData: params.callData,
|
|
373
|
+
callGasLimit: toHex(params.callGasLimit),
|
|
374
|
+
// setting initCode to 0x since it is only used for transaction simulation
|
|
375
|
+
initCode: '0x',
|
|
376
|
+
maxFeePerGas: toHex(params.maxFeePerGas),
|
|
377
|
+
maxPriorityFeePerGas: toHex(params.maxPriorityFeePerGas),
|
|
378
|
+
nonce: toHex(params.nonce),
|
|
379
|
+
paymasterAndData: params.paymasterAndData.toLowerCase(),
|
|
380
|
+
preVerificationGas: toHex(params.preVerificationGas),
|
|
381
|
+
sender: params.sender,
|
|
382
|
+
signature: '0x',
|
|
383
|
+
verificationGasLimit: toHex(params.verificationGasLimit),
|
|
384
|
+
};
|
|
385
|
+
}
|
|
386
|
+
const accountGasLimits = '0x' +
|
|
387
|
+
'000000000000000000000000000' + // 27 zeros
|
|
388
|
+
toHex(params.verificationGasLimit).slice(2) +
|
|
389
|
+
'000000000000000000000000000' + // 27 zeros
|
|
390
|
+
toHex(params.callGasLimit).slice(2);
|
|
391
|
+
const preVerificationGas = toHex(params.preVerificationGas);
|
|
392
|
+
const gasFees = '0x' +
|
|
393
|
+
'00000000000000000000000000' + // 26 zeros
|
|
394
|
+
toHex(params.maxPriorityFeePerGas).slice(2).padStart(6, '0') +
|
|
395
|
+
'0000000000000000000000' + // 22 zeros
|
|
396
|
+
toHex(params.maxFeePerGas).slice(2).padStart(10, '0');
|
|
397
|
+
const paymasterAndData = params.paymaster
|
|
398
|
+
? '0x' +
|
|
399
|
+
params.paymaster.slice(2).toLowerCase() +
|
|
400
|
+
toHex(params.paymasterVerificationGasLimit).slice(2).padStart(32, '0') + // Make sure it's 32 chars
|
|
401
|
+
toHex(params.paymasterPostOpGasLimit).slice(2).padStart(32, '0') + // Make sure it's 32 chars
|
|
402
|
+
params.paymasterData.slice(2) // Include full paymaster data
|
|
403
|
+
: '0x';
|
|
404
|
+
return {
|
|
405
|
+
accountGasLimits: accountGasLimits,
|
|
406
|
+
callData: params.callData,
|
|
407
|
+
gasFees: gasFees,
|
|
408
|
+
// setting initCode to 0x since it is only used for transaction simulation
|
|
409
|
+
initCode: '0x',
|
|
410
|
+
nonce: toHex(params.nonce),
|
|
411
|
+
paymasterAndData: paymasterAndData.toLowerCase(),
|
|
412
|
+
preVerificationGas: preVerificationGas,
|
|
413
|
+
sender: params.sender,
|
|
414
|
+
signature: '0x',
|
|
415
|
+
};
|
|
416
|
+
});
|
|
417
|
+
}
|
|
418
|
+
getCurrentUserOperation(transaction) {
|
|
327
419
|
return __awaiter(this, void 0, void 0, function* () {
|
|
420
|
+
var _a, _b;
|
|
328
421
|
try {
|
|
329
422
|
const { kernelClientWithSponsorship } = this;
|
|
330
423
|
if (!kernelClientWithSponsorship) {
|
|
331
424
|
throw new DynamicError('No kernel client with sponsorship found');
|
|
332
425
|
}
|
|
333
|
-
const
|
|
334
|
-
|
|
426
|
+
const value = BigInt((_a = transaction.value) !== null && _a !== void 0 ? _a : 0);
|
|
427
|
+
const callData = yield kernelClientWithSponsorship.account.encodeCalls([
|
|
428
|
+
{
|
|
335
429
|
data: transaction.data ? transaction.data : '0x',
|
|
336
430
|
to: transaction.to,
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
431
|
+
value,
|
|
432
|
+
},
|
|
433
|
+
]);
|
|
434
|
+
let sponsorResult;
|
|
435
|
+
let unsponsoredResult;
|
|
436
|
+
try {
|
|
437
|
+
sponsorResult = yield kernelClientWithSponsorship.prepareUserOperation({
|
|
438
|
+
callData,
|
|
439
|
+
});
|
|
440
|
+
}
|
|
441
|
+
catch (err) {
|
|
442
|
+
logger.debug('[ZeroDevConnector] Sponsored UserOp Attempt Failed:', err);
|
|
443
|
+
unsponsoredResult = yield ((_b = this.kernelClient) === null || _b === void 0 ? void 0 : _b.prepareUserOperation({
|
|
444
|
+
callData,
|
|
445
|
+
}));
|
|
446
|
+
}
|
|
447
|
+
if ((sponsorResult === null || sponsorResult === void 0 ? void 0 : sponsorResult.paymasterAndData) === '0x')
|
|
448
|
+
return { sponsored: false, userOperation: sponsorResult };
|
|
449
|
+
return sponsorResult
|
|
450
|
+
? { sponsored: true, userOperation: sponsorResult }
|
|
451
|
+
: { sponsored: false, userOperation: unsponsoredResult };
|
|
353
452
|
}
|
|
354
453
|
catch (err) {
|
|
355
|
-
logger.debug(err);
|
|
454
|
+
logger.debug('[ZeroDevConnector] Error in getCurrentUserOperation:', err);
|
|
455
|
+
return { sponsored: false, userOperation: undefined };
|
|
456
|
+
}
|
|
457
|
+
});
|
|
458
|
+
}
|
|
459
|
+
canSponsorTransactionGas(transaction) {
|
|
460
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
461
|
+
const { sponsored } = yield this.getCurrentUserOperation(transaction);
|
|
462
|
+
if (!sponsored) {
|
|
356
463
|
return false;
|
|
357
464
|
}
|
|
465
|
+
return sponsored;
|
|
358
466
|
});
|
|
359
467
|
}
|
|
360
468
|
disableGasSponsorshipOnce() {
|
|
@@ -390,23 +498,18 @@ class ZeroDevConnector extends WalletConnectorBase {
|
|
|
390
498
|
});
|
|
391
499
|
}
|
|
392
500
|
validateActiveWallet(expectedAddress) {
|
|
393
|
-
const _super = Object.create(null, {
|
|
394
|
-
validateActiveWallet: { get: () => super.validateActiveWallet }
|
|
395
|
-
});
|
|
396
501
|
return __awaiter(this, void 0, void 0, function* () {
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
const verifiedCredentials = eoaConnector === null || eoaConnector === void 0 ? void 0 : eoaConnector.verifiedCredentials;
|
|
401
|
-
const expectedEoaAddress = (_a = verifiedCredentials === null || verifiedCredentials === void 0 ? void 0 : verifiedCredentials.find((vc) => vc.smartWalletRefAddress === expectedAddress)) === null || _a === void 0 ? void 0 : _a.address;
|
|
402
|
-
if (!expectedEoaAddress) {
|
|
403
|
-
throw new DynamicError('No EOA connector');
|
|
404
|
-
}
|
|
405
|
-
yield (eoaConnector === null || eoaConnector === void 0 ? void 0 : eoaConnector.validateActiveWallet(expectedEoaAddress));
|
|
406
|
-
}
|
|
407
|
-
else {
|
|
408
|
-
yield _super.validateActiveWallet.call(this, expectedAddress);
|
|
502
|
+
const eoa = this.eoaConnectorMap[expectedAddress];
|
|
503
|
+
if (!eoa) {
|
|
504
|
+
throw new DynamicError('No EOA connector');
|
|
409
505
|
}
|
|
506
|
+
const { eoaAddress, eoaConnector, properties } = eoa;
|
|
507
|
+
yield eoaConnector.validateActiveWallet(eoaAddress);
|
|
508
|
+
yield this.setEoaConnector({
|
|
509
|
+
connector: eoaConnector,
|
|
510
|
+
eoaAddress,
|
|
511
|
+
properties,
|
|
512
|
+
});
|
|
410
513
|
});
|
|
411
514
|
}
|
|
412
515
|
}
|
|
@@ -6,6 +6,7 @@ Object.defineProperty(exports, '__esModule', { value: true });
|
|
|
6
6
|
var _tslib = require('../../_virtual/_tslib.cjs');
|
|
7
7
|
var accounts = require('@zerodev/sdk/accounts');
|
|
8
8
|
var clients = require('@zerodev/sdk/clients');
|
|
9
|
+
var actions = require('@zerodev/sdk/actions');
|
|
9
10
|
var viem = require('viem');
|
|
10
11
|
|
|
11
12
|
const getZeroDevBundlerRPC = (projectId, provider) => {
|
|
@@ -23,19 +24,20 @@ const getZeroDevPaymasterRPC = (projectId, provider) => {
|
|
|
23
24
|
return rpc;
|
|
24
25
|
};
|
|
25
26
|
const isERC20 = (value) => viem.isAddress(value);
|
|
26
|
-
const createEcdsaKernelAccountClient = (_a) => _tslib.__awaiter(void 0, [_a], void 0, function* ({ bundlerRpc, chain, paymasterRpc, projectId, signer, provider, index, paymaster = 'SPONSOR',
|
|
27
|
+
const createEcdsaKernelAccountClient = (_a) => _tslib.__awaiter(void 0, [_a], void 0, function* ({ bundlerRpc, chain, paymasterRpc, projectId, signer, provider, index, paymaster = 'SPONSOR', entryPoint, kernelVersion, ecdsaValidator, }) {
|
|
27
28
|
const resolvedBundlerRpc = bundlerRpc !== null && bundlerRpc !== void 0 ? bundlerRpc : getZeroDevBundlerRPC(projectId, provider);
|
|
28
29
|
const resolvedPaymasterRpc = paymasterRpc !== null && paymasterRpc !== void 0 ? paymasterRpc : getZeroDevPaymasterRPC(projectId, provider);
|
|
29
30
|
const publicClient = viem.createPublicClient({
|
|
31
|
+
chain,
|
|
30
32
|
transport: viem.http(resolvedBundlerRpc),
|
|
31
33
|
});
|
|
32
34
|
const validator = yield ecdsaValidator(publicClient, {
|
|
33
|
-
entryPoint
|
|
35
|
+
entryPoint,
|
|
34
36
|
kernelVersion,
|
|
35
37
|
signer,
|
|
36
38
|
});
|
|
37
39
|
const account = yield accounts.createKernelAccount(publicClient, {
|
|
38
|
-
entryPoint
|
|
40
|
+
entryPoint,
|
|
39
41
|
index,
|
|
40
42
|
kernelVersion,
|
|
41
43
|
plugins: {
|
|
@@ -43,33 +45,33 @@ const createEcdsaKernelAccountClient = (_a) => _tslib.__awaiter(void 0, [_a], vo
|
|
|
43
45
|
},
|
|
44
46
|
});
|
|
45
47
|
const zerodevPaymaster = clients.createZeroDevPaymasterClient({
|
|
46
|
-
chain
|
|
47
|
-
entryPoint: entryPointAddress,
|
|
48
|
+
chain,
|
|
48
49
|
transport: viem.http(resolvedPaymasterRpc),
|
|
49
50
|
});
|
|
50
51
|
const kernelClient = clients.createKernelAccountClient({
|
|
51
52
|
account,
|
|
52
53
|
bundlerTransport: viem.http(resolvedBundlerRpc),
|
|
53
54
|
chain,
|
|
54
|
-
|
|
55
|
-
|
|
55
|
+
client: publicClient,
|
|
56
|
+
paymaster: paymaster !== 'NONE'
|
|
56
57
|
? {
|
|
57
|
-
|
|
58
|
+
getPaymasterData: (userOperation) => {
|
|
58
59
|
const _userOperation = userOperation;
|
|
59
60
|
if (isERC20(paymaster)) {
|
|
60
61
|
return zerodevPaymaster.sponsorUserOperation({
|
|
61
|
-
entryPoint: entryPointAddress,
|
|
62
62
|
gasToken: paymaster,
|
|
63
63
|
userOperation: _userOperation,
|
|
64
64
|
});
|
|
65
65
|
}
|
|
66
66
|
return zerodevPaymaster.sponsorUserOperation({
|
|
67
|
-
entryPoint: entryPointAddress,
|
|
68
67
|
userOperation: _userOperation,
|
|
69
68
|
});
|
|
70
|
-
}
|
|
69
|
+
},
|
|
71
70
|
}
|
|
72
71
|
: undefined,
|
|
72
|
+
userOperation: {
|
|
73
|
+
estimateFeesPerGas: (_b) => _tslib.__awaiter(void 0, [_b], void 0, function* ({ bundlerClient }) { return actions.getUserOperationGasPrice(bundlerClient); }),
|
|
74
|
+
},
|
|
73
75
|
});
|
|
74
76
|
return kernelClient;
|
|
75
77
|
});
|
|
@@ -1,24 +1,23 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { SmartAccount, EntryPointVersion } from 'viem/account-abstraction';
|
|
2
2
|
import { KernelAccountClient } from '@zerodev/sdk/clients';
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
6
|
-
import { GetKernelVersion } from '@zerodev/sdk/types';
|
|
3
|
+
import { type Chain as ViemChain } from 'viem/chains';
|
|
4
|
+
import { Address, WalletClient, Account, type Client, type RpcSchema, type Transport } from 'viem';
|
|
5
|
+
import { EntryPointType, GetKernelVersion } from '@zerodev/sdk/types';
|
|
7
6
|
export type BundlerProvider = 'STACKUP' | 'PIMLICO' | 'ALCHEMY' | 'GELATO';
|
|
8
7
|
export type ERC20Paymaster = Address;
|
|
9
8
|
export type PaymasterType = 'NONE' | 'SPONSOR' | ERC20Paymaster;
|
|
10
9
|
export declare const getZeroDevBundlerRPC: (projectId: string, provider?: BundlerProvider) => string;
|
|
11
10
|
export declare const getZeroDevPaymasterRPC: (projectId: string, provider?: BundlerProvider) => string;
|
|
12
|
-
export declare const createEcdsaKernelAccountClient: <entryPoint extends
|
|
13
|
-
bundlerRpc?: string;
|
|
11
|
+
export declare const createEcdsaKernelAccountClient: <entryPoint extends EntryPointVersion, TChain extends ViemChain | undefined = ViemChain | undefined>({ bundlerRpc, chain, paymasterRpc, projectId, signer, provider, index, paymaster, entryPoint, kernelVersion, ecdsaValidator, }: {
|
|
12
|
+
bundlerRpc?: string | undefined;
|
|
14
13
|
chain: TChain;
|
|
15
14
|
projectId: string;
|
|
16
|
-
signer:
|
|
15
|
+
signer: WalletClient<Transport, ViemChain, Account>;
|
|
17
16
|
paymaster: PaymasterType;
|
|
18
|
-
paymasterRpc?: string;
|
|
19
|
-
|
|
20
|
-
provider?: BundlerProvider;
|
|
21
|
-
index?: bigint;
|
|
17
|
+
paymasterRpc?: string | undefined;
|
|
18
|
+
entryPoint: EntryPointType<entryPoint>;
|
|
19
|
+
provider?: BundlerProvider | undefined;
|
|
20
|
+
index?: bigint | undefined;
|
|
22
21
|
kernelVersion: GetKernelVersion<entryPoint>;
|
|
23
22
|
ecdsaValidator: any;
|
|
24
|
-
}) => Promise<KernelAccountClient<
|
|
23
|
+
}) => Promise<KernelAccountClient<Transport, ViemChain, SmartAccount, Client, RpcSchema>>;
|
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
import { __awaiter } from '../../_virtual/_tslib.js';
|
|
3
3
|
import { createKernelAccount } from '@zerodev/sdk/accounts';
|
|
4
4
|
import { createZeroDevPaymasterClient, createKernelAccountClient } from '@zerodev/sdk/clients';
|
|
5
|
+
import { getUserOperationGasPrice } from '@zerodev/sdk/actions';
|
|
5
6
|
import { createPublicClient, http, isAddress } from 'viem';
|
|
6
7
|
|
|
7
8
|
const getZeroDevBundlerRPC = (projectId, provider) => {
|
|
@@ -19,19 +20,20 @@ const getZeroDevPaymasterRPC = (projectId, provider) => {
|
|
|
19
20
|
return rpc;
|
|
20
21
|
};
|
|
21
22
|
const isERC20 = (value) => isAddress(value);
|
|
22
|
-
const createEcdsaKernelAccountClient = (_a) => __awaiter(void 0, [_a], void 0, function* ({ bundlerRpc, chain, paymasterRpc, projectId, signer, provider, index, paymaster = 'SPONSOR',
|
|
23
|
+
const createEcdsaKernelAccountClient = (_a) => __awaiter(void 0, [_a], void 0, function* ({ bundlerRpc, chain, paymasterRpc, projectId, signer, provider, index, paymaster = 'SPONSOR', entryPoint, kernelVersion, ecdsaValidator, }) {
|
|
23
24
|
const resolvedBundlerRpc = bundlerRpc !== null && bundlerRpc !== void 0 ? bundlerRpc : getZeroDevBundlerRPC(projectId, provider);
|
|
24
25
|
const resolvedPaymasterRpc = paymasterRpc !== null && paymasterRpc !== void 0 ? paymasterRpc : getZeroDevPaymasterRPC(projectId, provider);
|
|
25
26
|
const publicClient = createPublicClient({
|
|
27
|
+
chain,
|
|
26
28
|
transport: http(resolvedBundlerRpc),
|
|
27
29
|
});
|
|
28
30
|
const validator = yield ecdsaValidator(publicClient, {
|
|
29
|
-
entryPoint
|
|
31
|
+
entryPoint,
|
|
30
32
|
kernelVersion,
|
|
31
33
|
signer,
|
|
32
34
|
});
|
|
33
35
|
const account = yield createKernelAccount(publicClient, {
|
|
34
|
-
entryPoint
|
|
36
|
+
entryPoint,
|
|
35
37
|
index,
|
|
36
38
|
kernelVersion,
|
|
37
39
|
plugins: {
|
|
@@ -39,33 +41,33 @@ const createEcdsaKernelAccountClient = (_a) => __awaiter(void 0, [_a], void 0, f
|
|
|
39
41
|
},
|
|
40
42
|
});
|
|
41
43
|
const zerodevPaymaster = createZeroDevPaymasterClient({
|
|
42
|
-
chain
|
|
43
|
-
entryPoint: entryPointAddress,
|
|
44
|
+
chain,
|
|
44
45
|
transport: http(resolvedPaymasterRpc),
|
|
45
46
|
});
|
|
46
47
|
const kernelClient = createKernelAccountClient({
|
|
47
48
|
account,
|
|
48
49
|
bundlerTransport: http(resolvedBundlerRpc),
|
|
49
50
|
chain,
|
|
50
|
-
|
|
51
|
-
|
|
51
|
+
client: publicClient,
|
|
52
|
+
paymaster: paymaster !== 'NONE'
|
|
52
53
|
? {
|
|
53
|
-
|
|
54
|
+
getPaymasterData: (userOperation) => {
|
|
54
55
|
const _userOperation = userOperation;
|
|
55
56
|
if (isERC20(paymaster)) {
|
|
56
57
|
return zerodevPaymaster.sponsorUserOperation({
|
|
57
|
-
entryPoint: entryPointAddress,
|
|
58
58
|
gasToken: paymaster,
|
|
59
59
|
userOperation: _userOperation,
|
|
60
60
|
});
|
|
61
61
|
}
|
|
62
62
|
return zerodevPaymaster.sponsorUserOperation({
|
|
63
|
-
entryPoint: entryPointAddress,
|
|
64
63
|
userOperation: _userOperation,
|
|
65
64
|
});
|
|
66
|
-
}
|
|
65
|
+
},
|
|
67
66
|
}
|
|
68
67
|
: undefined,
|
|
68
|
+
userOperation: {
|
|
69
|
+
estimateFeesPerGas: (_b) => __awaiter(void 0, [_b], void 0, function* ({ bundlerClient }) { return getUserOperationGasPrice(bundlerClient); }),
|
|
70
|
+
},
|
|
69
71
|
});
|
|
70
72
|
return kernelClient;
|
|
71
73
|
});
|
|
@@ -3,21 +3,21 @@
|
|
|
3
3
|
|
|
4
4
|
Object.defineProperty(exports, '__esModule', { value: true });
|
|
5
5
|
|
|
6
|
-
var
|
|
6
|
+
var constants = require('@zerodev/sdk/constants');
|
|
7
7
|
var sdkApiCore = require('@dynamic-labs/sdk-api-core');
|
|
8
8
|
var logger = require('./logger.cjs');
|
|
9
9
|
|
|
10
10
|
const getEntryPoint = (entryPoint) => {
|
|
11
11
|
if (entryPoint === undefined ||
|
|
12
12
|
entryPoint === sdkApiCore.ProviderEntryPointVersionEnum.V7) {
|
|
13
|
-
return
|
|
13
|
+
return constants.getEntryPoint('0.7');
|
|
14
14
|
}
|
|
15
15
|
else if (entryPoint === sdkApiCore.ProviderEntryPointVersionEnum.V6) {
|
|
16
|
-
return
|
|
16
|
+
return constants.getEntryPoint('0.6');
|
|
17
17
|
}
|
|
18
18
|
else {
|
|
19
19
|
logger.logger.error('Invalid entry point version', entryPoint);
|
|
20
|
-
return
|
|
20
|
+
return constants.getEntryPoint('0.7');
|
|
21
21
|
}
|
|
22
22
|
};
|
|
23
23
|
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export declare const getEntryPoint: (entryPoint: string | undefined) => "
|
|
1
|
+
export declare const getEntryPoint: (entryPoint: string | undefined) => import("@zerodev/sdk/types").EntryPointType<"0.7"> | import("@zerodev/sdk/types").EntryPointType<"0.6">;
|
|
@@ -1,19 +1,19 @@
|
|
|
1
1
|
'use client'
|
|
2
|
-
import {
|
|
2
|
+
import { getEntryPoint as getEntryPoint$1 } from '@zerodev/sdk/constants';
|
|
3
3
|
import { ProviderEntryPointVersionEnum } from '@dynamic-labs/sdk-api-core';
|
|
4
4
|
import { logger } from './logger.js';
|
|
5
5
|
|
|
6
6
|
const getEntryPoint = (entryPoint) => {
|
|
7
7
|
if (entryPoint === undefined ||
|
|
8
8
|
entryPoint === ProviderEntryPointVersionEnum.V7) {
|
|
9
|
-
return
|
|
9
|
+
return getEntryPoint$1('0.7');
|
|
10
10
|
}
|
|
11
11
|
else if (entryPoint === ProviderEntryPointVersionEnum.V6) {
|
|
12
|
-
return
|
|
12
|
+
return getEntryPoint$1('0.6');
|
|
13
13
|
}
|
|
14
14
|
else {
|
|
15
15
|
logger.error('Invalid entry point version', entryPoint);
|
|
16
|
-
return
|
|
16
|
+
return getEntryPoint$1('0.7');
|
|
17
17
|
}
|
|
18
18
|
};
|
|
19
19
|
|
|
@@ -3,7 +3,6 @@
|
|
|
3
3
|
|
|
4
4
|
Object.defineProperty(exports, '__esModule', { value: true });
|
|
5
5
|
|
|
6
|
-
var permissionless = require('permissionless');
|
|
7
6
|
var constants = require('@zerodev/sdk/constants');
|
|
8
7
|
var sdkApiCore = require('@dynamic-labs/sdk-api-core');
|
|
9
8
|
var logger = require('./logger.cjs');
|
|
@@ -11,14 +10,14 @@ var logger = require('./logger.cjs');
|
|
|
11
10
|
const getKernelVersion = (kernelVersion, entryPointAddress) => {
|
|
12
11
|
if (kernelVersion === sdkApiCore.ProviderKernelVersionEnum.V31 ||
|
|
13
12
|
(kernelVersion === undefined &&
|
|
14
|
-
entryPointAddress ===
|
|
13
|
+
entryPointAddress.address === constants.getEntryPoint('0.7').address)) {
|
|
15
14
|
return constants.KERNEL_V3_1;
|
|
16
15
|
}
|
|
17
16
|
else if (kernelVersion === sdkApiCore.ProviderKernelVersionEnum.V30) {
|
|
18
17
|
return constants.KERNEL_V3_0;
|
|
19
18
|
}
|
|
20
19
|
else if (kernelVersion === sdkApiCore.ProviderKernelVersionEnum.V24 ||
|
|
21
|
-
entryPointAddress ===
|
|
20
|
+
entryPointAddress.address === constants.getEntryPoint('0.6').address // v0.6 only supports v2.4
|
|
22
21
|
) {
|
|
23
22
|
return constants.KERNEL_V2_4;
|
|
24
23
|
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
import { KERNEL_VERSION_TYPE } from '@zerodev/sdk/types';
|
|
2
|
+
import { getEntryPoint } from '@zerodev/sdk/constants';
|
|
2
3
|
import { ProviderKernelVersionEnum } from '@dynamic-labs/sdk-api-core';
|
|
3
|
-
import { getEntryPoint } from './getEntryPoint';
|
|
4
4
|
export declare const getKernelVersion: (kernelVersion: ProviderKernelVersionEnum | undefined, entryPointAddress: ReturnType<typeof getEntryPoint>) => KERNEL_VERSION_TYPE;
|
|
@@ -1,20 +1,19 @@
|
|
|
1
1
|
'use client'
|
|
2
|
-
import {
|
|
3
|
-
import { KERNEL_V3_1, KERNEL_V3_0, KERNEL_V2_4 } from '@zerodev/sdk/constants';
|
|
2
|
+
import { getEntryPoint, KERNEL_V3_1, KERNEL_V3_0, KERNEL_V2_4 } from '@zerodev/sdk/constants';
|
|
4
3
|
import { ProviderKernelVersionEnum } from '@dynamic-labs/sdk-api-core';
|
|
5
4
|
import { logger } from './logger.js';
|
|
6
5
|
|
|
7
6
|
const getKernelVersion = (kernelVersion, entryPointAddress) => {
|
|
8
7
|
if (kernelVersion === ProviderKernelVersionEnum.V31 ||
|
|
9
8
|
(kernelVersion === undefined &&
|
|
10
|
-
entryPointAddress ===
|
|
9
|
+
entryPointAddress.address === getEntryPoint('0.7').address)) {
|
|
11
10
|
return KERNEL_V3_1;
|
|
12
11
|
}
|
|
13
12
|
else if (kernelVersion === ProviderKernelVersionEnum.V30) {
|
|
14
13
|
return KERNEL_V3_0;
|
|
15
14
|
}
|
|
16
15
|
else if (kernelVersion === ProviderKernelVersionEnum.V24 ||
|
|
17
|
-
entryPointAddress ===
|
|
16
|
+
entryPointAddress.address === getEntryPoint('0.6').address // v0.6 only supports v2.4
|
|
18
17
|
) {
|
|
19
18
|
return KERNEL_V2_4;
|
|
20
19
|
}
|