@dynamic-labs/ethereum-aa 4.17.0 → 4.18.1
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 +25 -0
- package/package.cjs +1 -1
- package/package.js +1 -1
- package/package.json +10 -10
- package/src/ZeroDevConnector.cjs +72 -88
- package/src/ZeroDevConnector.d.ts +23 -16
- package/src/ZeroDevConnector.js +73 -89
- package/src/index.cjs +8 -4
- package/src/index.d.ts +10 -3
- package/src/index.js +8 -4
- package/src/utils/createEcdsaKernelAccountClient.cjs +13 -13
- package/src/utils/createEcdsaKernelAccountClient.d.ts +7 -9
- package/src/utils/createEcdsaKernelAccountClient.js +14 -14
- package/src/utils/index.d.ts +0 -1
- package/src/utils/isEVMAuthorizationCapable.cjs +0 -8
- package/src/utils/isEVMAuthorizationCapable.d.ts +0 -6
- package/src/utils/isEVMAuthorizationCapable.js +0 -4
package/CHANGELOG.md
CHANGED
|
@@ -1,4 +1,29 @@
|
|
|
1
1
|
|
|
2
|
+
### [4.18.1](https://github.com/dynamic-labs/dynamic-auth/compare/v4.18.0...v4.18.1) (2025-05-09)
|
|
3
|
+
|
|
4
|
+
|
|
5
|
+
### Features
|
|
6
|
+
|
|
7
|
+
* allow setting zerodev bundler provider from dashboard ([#8548](https://github.com/dynamic-labs/dynamic-auth/issues/8548)) ([d226733](https://github.com/dynamic-labs/dynamic-auth/commit/d2267334db3d9d742833437c81a382742c8d6a74))
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
### Bug Fixes
|
|
11
|
+
|
|
12
|
+
* correctly show back button on connect with qr view ([#8668](https://github.com/dynamic-labs/dynamic-auth/issues/8668)) ([3cff309](https://github.com/dynamic-labs/dynamic-auth/commit/3cff309fa35d7201d0c098b793334908716bc0db))
|
|
13
|
+
* display correct app origin when signing message with global wallet ([#8677](https://github.com/dynamic-labs/dynamic-auth/issues/8677)) ([a70eeb3](https://github.com/dynamic-labs/dynamic-auth/commit/a70eeb3ea28a5ad749cb5c14a0d3c49318099712))
|
|
14
|
+
|
|
15
|
+
## [4.18.0](https://github.com/dynamic-labs/dynamic-auth/compare/v4.17.0...v4.18.0) (2025-05-07)
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
### Features
|
|
19
|
+
|
|
20
|
+
* 7702 authorization now happens on the first transaction and could use sponsored user operation if paymaster provided (IMPORTANT: viem need to be upgraded to at least 2.28.4)
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
### Bug Fixes
|
|
24
|
+
|
|
25
|
+
* inline email submit button color when active ([#8663](https://github.com/dynamic-labs/dynamic-auth/issues/8663)) ([ea556e9](https://github.com/dynamic-labs/dynamic-auth/commit/ea556e9116e876fb2180870e74b6c8c6a13faecb))
|
|
26
|
+
|
|
2
27
|
## [4.17.0](https://github.com/dynamic-labs/dynamic-auth/compare/v4.16.0...v4.17.0) (2025-05-06)
|
|
3
28
|
|
|
4
29
|
|
package/package.cjs
CHANGED
package/package.js
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@dynamic-labs/ethereum-aa",
|
|
3
|
-
"version": "4.
|
|
3
|
+
"version": "4.18.1",
|
|
4
4
|
"description": "A React SDK for implementing wallet web3 authentication and authorization to your website.",
|
|
5
5
|
"author": "Dynamic Labs, Inc.",
|
|
6
6
|
"license": "MIT",
|
|
@@ -18,18 +18,18 @@
|
|
|
18
18
|
},
|
|
19
19
|
"homepage": "https://www.dynamic.xyz/",
|
|
20
20
|
"dependencies": {
|
|
21
|
-
"@dynamic-labs/sdk-api-core": "0.0.
|
|
21
|
+
"@dynamic-labs/sdk-api-core": "0.0.663",
|
|
22
22
|
"@zerodev/ecdsa-validator": "5.4.8",
|
|
23
23
|
"@zerodev/multi-chain-ecdsa-validator": "5.4.5",
|
|
24
24
|
"@zerodev/sdk": "5.4.34",
|
|
25
|
-
"@dynamic-labs/assert-package-version": "4.
|
|
26
|
-
"@dynamic-labs/ethereum-aa-core": "4.
|
|
27
|
-
"@dynamic-labs/ethereum-core": "4.
|
|
28
|
-
"@dynamic-labs/logger": "4.
|
|
29
|
-
"@dynamic-labs/types": "4.
|
|
30
|
-
"@dynamic-labs/utils": "4.
|
|
31
|
-
"@dynamic-labs/wallet-book": "4.
|
|
32
|
-
"@dynamic-labs/wallet-connector-core": "4.
|
|
25
|
+
"@dynamic-labs/assert-package-version": "4.18.1",
|
|
26
|
+
"@dynamic-labs/ethereum-aa-core": "4.18.1",
|
|
27
|
+
"@dynamic-labs/ethereum-core": "4.18.1",
|
|
28
|
+
"@dynamic-labs/logger": "4.18.1",
|
|
29
|
+
"@dynamic-labs/types": "4.18.1",
|
|
30
|
+
"@dynamic-labs/utils": "4.18.1",
|
|
31
|
+
"@dynamic-labs/wallet-book": "4.18.1",
|
|
32
|
+
"@dynamic-labs/wallet-connector-core": "4.18.1"
|
|
33
33
|
},
|
|
34
34
|
"peerDependencies": {
|
|
35
35
|
"viem": "^2.21.60"
|
package/src/ZeroDevConnector.cjs
CHANGED
|
@@ -4,26 +4,25 @@
|
|
|
4
4
|
Object.defineProperty(exports, '__esModule', { value: true });
|
|
5
5
|
|
|
6
6
|
var _tslib = require('../_virtual/_tslib.cjs');
|
|
7
|
+
var constants$1 = require('@zerodev/sdk/constants');
|
|
7
8
|
var viem = require('viem');
|
|
8
9
|
var accounts = require('viem/accounts');
|
|
9
|
-
var
|
|
10
|
+
var ethereumAaCore = require('@dynamic-labs/ethereum-aa-core');
|
|
10
11
|
var ethereumCore = require('@dynamic-labs/ethereum-core');
|
|
11
12
|
var sdkApiCore = require('@dynamic-labs/sdk-api-core');
|
|
12
|
-
var walletConnectorCore = require('@dynamic-labs/wallet-connector-core');
|
|
13
13
|
var utils = require('@dynamic-labs/utils');
|
|
14
|
-
var
|
|
14
|
+
var walletConnectorCore = require('@dynamic-labs/wallet-connector-core');
|
|
15
15
|
var constants = require('./constants.cjs');
|
|
16
16
|
var logger = require('./utils/logger.cjs');
|
|
17
17
|
var createEcdsaKernelAccountClient = require('./utils/createEcdsaKernelAccountClient.cjs');
|
|
18
18
|
var getEcdsaValidator = require('./utils/getEcdsaValidator.cjs');
|
|
19
19
|
var getEntryPoint = require('./utils/getEntryPoint.cjs');
|
|
20
20
|
var getKernelVersion = require('./utils/getKernelVersion.cjs');
|
|
21
|
-
var isEVMAuthorizationCapable = require('./utils/isEVMAuthorizationCapable.cjs');
|
|
22
21
|
var hasSmartAccount = require('./utils/hasSmartAccount.cjs');
|
|
23
22
|
|
|
24
23
|
class ZeroDevConnector extends ethereumAaCore.AccountAbstractionBaseConnector {
|
|
25
24
|
constructor(opts) {
|
|
26
|
-
var _a, _b, _c, _d, _e, _f, _g, _h, _j;
|
|
25
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r, _s, _t;
|
|
27
26
|
super(opts);
|
|
28
27
|
// provider map maintains the kernel clients per chain
|
|
29
28
|
this.providerMap = {};
|
|
@@ -34,6 +33,12 @@ class ZeroDevConnector extends ethereumAaCore.AccountAbstractionBaseConnector {
|
|
|
34
33
|
this.supportedChains = ['ETH', 'EVM'];
|
|
35
34
|
this.isEmbeddedWallet = true;
|
|
36
35
|
this.providersFromApi = [];
|
|
36
|
+
/**
|
|
37
|
+
* Cache for prepared user operations indexed by transaction details.
|
|
38
|
+
* The key is a concatenation of from-to-data to uniquely identify transactions.
|
|
39
|
+
* Used to avoid re-preparing the same user operation multiple times.
|
|
40
|
+
*/
|
|
41
|
+
this.userOperationCache = {};
|
|
37
42
|
this.name = 'ZeroDev';
|
|
38
43
|
this.overrideKey = 'zerodev';
|
|
39
44
|
this.walletFallback = {
|
|
@@ -53,12 +58,20 @@ class ZeroDevConnector extends ethereumAaCore.AccountAbstractionBaseConnector {
|
|
|
53
58
|
this.is7702EnabledOnDashboard =
|
|
54
59
|
(_c = (_b = opts.apiProviders.zerodev) === null || _b === void 0 ? void 0 : _b.enableEIP7702) !== null && _c !== void 0 ? _c : false;
|
|
55
60
|
this.entryPoint = getEntryPoint.getEntryPoint((_d = opts.apiProviders.zerodev) === null || _d === void 0 ? void 0 : _d.entryPointVersion);
|
|
56
|
-
this.
|
|
61
|
+
this.bundlerProvider =
|
|
62
|
+
(_g = (_f = (_e = opts.apiProviders.zerodev) === null || _e === void 0 ? void 0 : _e.zerodevBundlerProvider) !== null && _f !== void 0 ? _f : ZeroDevConnector.bundlerProviderDefault) !== null && _g !== void 0 ? _g : sdkApiCore.ZerodevBundlerProvider.Gelato;
|
|
63
|
+
this.bundlerRpc =
|
|
64
|
+
(_j = (_h = opts.apiProviders.zerodev) === null || _h === void 0 ? void 0 : _h.zerodevBundlerRpcUrl) !== null && _j !== void 0 ? _j : ZeroDevConnector.bundlerRpcDefault;
|
|
65
|
+
this.paymasterRpc =
|
|
66
|
+
(_l = (_k = opts.apiProviders.zerodev) === null || _k === void 0 ? void 0 : _k.zerodevPaymasterRpcUrl) !== null && _l !== void 0 ? _l : ZeroDevConnector.paymasterRpcDefault;
|
|
67
|
+
this.kernelDelegationAddress =
|
|
68
|
+
(_o = (_m = opts.apiProviders.zerodev) === null || _m === void 0 ? void 0 : _m.zerodevKernelDelegationAddress) !== null && _o !== void 0 ? _o : ZeroDevConnector.kernelDelegationAddressDefault;
|
|
69
|
+
this.kernelVersion = getKernelVersion.getKernelVersion((_p = opts.apiProviders.zerodev) === null || _p === void 0 ? void 0 : _p.kernelVersion, this.entryPoint);
|
|
57
70
|
this.enableKernelV3Migration =
|
|
58
|
-
(
|
|
71
|
+
(_r = (_q = opts.apiProviders.zerodev) === null || _q === void 0 ? void 0 : _q.enableKernelV3Migration) !== null && _r !== void 0 ? _r : false;
|
|
59
72
|
// this is the list of providers from the api that are used for multi-chain account abstraction
|
|
60
73
|
this.providersFromApi =
|
|
61
|
-
((
|
|
74
|
+
((_s = opts.apiProviders.zerodev) === null || _s === void 0 ? void 0 : _s.multichainAccountAbstractionProviders) || [];
|
|
62
75
|
const enabledZerodevNetworks = this.providersFromApi.map((provider) => provider.chain);
|
|
63
76
|
this.evmNetworks = utils.parseEvmNetworks(opts.evmNetworks).filter((network) => enabledZerodevNetworks.includes(network.chainId.toString()));
|
|
64
77
|
const [defaultProvider] = this.providersFromApi;
|
|
@@ -67,7 +80,7 @@ class ZeroDevConnector extends ethereumAaCore.AccountAbstractionBaseConnector {
|
|
|
67
80
|
throw new Error('Missing ZeroDev project ID provided. Add your ZeroDev project id to your project configuration via the Dynamic Labs dashboard.');
|
|
68
81
|
}
|
|
69
82
|
this.defaultChainId = defaultProvider === null || defaultProvider === void 0 ? void 0 : defaultProvider.chain;
|
|
70
|
-
this.ecdsaProviderType = (
|
|
83
|
+
this.ecdsaProviderType = (_t = opts.apiProviders.zerodev) === null || _t === void 0 ? void 0 : _t.ecdsaProviderType;
|
|
71
84
|
}
|
|
72
85
|
confirmTransactionStatus() {
|
|
73
86
|
throw new Error('confirmTransactionStatus not implemented in ZeroDevConnector');
|
|
@@ -179,49 +192,6 @@ class ZeroDevConnector extends ethereumAaCore.AccountAbstractionBaseConnector {
|
|
|
179
192
|
this.shouldUseEIP7702Mode =
|
|
180
193
|
this.is7702EnabledOnDashboard && !this.hasExistingSmartAccount;
|
|
181
194
|
}
|
|
182
|
-
getOrCreateAuthorization() {
|
|
183
|
-
return _tslib.__awaiter(this, void 0, void 0, function* () {
|
|
184
|
-
var _a;
|
|
185
|
-
if (!this.eoaConnector)
|
|
186
|
-
throw new utils.DynamicError('No EOA connector');
|
|
187
|
-
if (!isEVMAuthorizationCapable.isEVMAuthorizationCapable(this.eoaConnector)) {
|
|
188
|
-
throw new utils.DynamicError('Connector does not support EVM authorization');
|
|
189
|
-
}
|
|
190
|
-
const ZERODEV_AUTHORIZATION = 'zerodev_authorization';
|
|
191
|
-
try {
|
|
192
|
-
const storedAuthorization = utils.StorageService.getItem(ZERODEV_AUTHORIZATION);
|
|
193
|
-
if (storedAuthorization) {
|
|
194
|
-
return storedAuthorization;
|
|
195
|
-
}
|
|
196
|
-
const kernelVersion = constants$1.KERNEL_V3_3_BETA;
|
|
197
|
-
const authorization = yield this.eoaConnector.experimental_signAuthorization({
|
|
198
|
-
contractAddress: (_a = ZeroDevConnector.kernelDelegationAddress) !== null && _a !== void 0 ? _a : constants$1.KernelVersionToAddressesMap[kernelVersion]
|
|
199
|
-
.accountImplementationAddress,
|
|
200
|
-
});
|
|
201
|
-
if (authorization) {
|
|
202
|
-
const serializedAuth = Object.entries(authorization).reduce((acc, [key, value]) => {
|
|
203
|
-
acc[key] = typeof value === 'bigint' ? value.toString() : value;
|
|
204
|
-
return acc;
|
|
205
|
-
}, {});
|
|
206
|
-
utils.StorageService.setItem(ZERODEV_AUTHORIZATION, serializedAuth);
|
|
207
|
-
}
|
|
208
|
-
return {
|
|
209
|
-
address: authorization.contractAddress,
|
|
210
|
-
chainId: authorization.chainId,
|
|
211
|
-
nonce: authorization.nonce,
|
|
212
|
-
r: authorization.r,
|
|
213
|
-
s: authorization.s,
|
|
214
|
-
v: authorization.v,
|
|
215
|
-
yParity: authorization.yParity,
|
|
216
|
-
};
|
|
217
|
-
}
|
|
218
|
-
catch (error) {
|
|
219
|
-
logger.logger.error('Failed to get/set authorization:', error);
|
|
220
|
-
utils.StorageService.removeItem(ZERODEV_AUTHORIZATION);
|
|
221
|
-
return undefined;
|
|
222
|
-
}
|
|
223
|
-
});
|
|
224
|
-
}
|
|
225
195
|
setEoaConnector(_a) {
|
|
226
196
|
return _tslib.__awaiter(this, arguments, void 0, function* ({ eoaAddress, connector, properties, }) {
|
|
227
197
|
var _b, _c;
|
|
@@ -251,10 +221,6 @@ class ZeroDevConnector extends ethereumAaCore.AccountAbstractionBaseConnector {
|
|
|
251
221
|
yield this.eoaConnector.getConnectedAccounts();
|
|
252
222
|
}
|
|
253
223
|
const signer = yield this.eoaConnector.getSigner();
|
|
254
|
-
signer.account = accounts.toAccount(eoaAddress);
|
|
255
|
-
if (this.shouldUseEIP7702Mode) {
|
|
256
|
-
this.authorization = yield this.getOrCreateAuthorization();
|
|
257
|
-
}
|
|
258
224
|
yield this.generateProviderMap(signer);
|
|
259
225
|
this.kernelClientDeferredPromise.resolve();
|
|
260
226
|
});
|
|
@@ -292,7 +258,6 @@ class ZeroDevConnector extends ethereumAaCore.AccountAbstractionBaseConnector {
|
|
|
292
258
|
signer,
|
|
293
259
|
}),
|
|
294
260
|
this.createKernelClient({
|
|
295
|
-
authorization: this.authorization,
|
|
296
261
|
chainId: chain,
|
|
297
262
|
paymaster: 'SPONSOR',
|
|
298
263
|
projectId: clientId,
|
|
@@ -316,7 +281,7 @@ class ZeroDevConnector extends ethereumAaCore.AccountAbstractionBaseConnector {
|
|
|
316
281
|
});
|
|
317
282
|
}
|
|
318
283
|
createKernelClient(_a) {
|
|
319
|
-
return _tslib.__awaiter(this, arguments, void 0, function* ({ chainId, projectId, signer, paymaster,
|
|
284
|
+
return _tslib.__awaiter(this, arguments, void 0, function* ({ chainId, projectId, signer, paymaster, }) {
|
|
320
285
|
var _b;
|
|
321
286
|
if (chainId && this.providerMap[chainId]) {
|
|
322
287
|
return paymaster === 'SPONSOR'
|
|
@@ -330,38 +295,24 @@ class ZeroDevConnector extends ethereumAaCore.AccountAbstractionBaseConnector {
|
|
|
330
295
|
const network = this.evmNetworks.find((network) => network.chainId === utils.parseChainId(chainId));
|
|
331
296
|
const publicClientRpc = (_b = network === null || network === void 0 ? void 0 : network.privateCustomerRpcUrls) === null || _b === void 0 ? void 0 : _b[0];
|
|
332
297
|
let kernelClient;
|
|
298
|
+
const params = {
|
|
299
|
+
bundlerRpc: this.bundlerRpc,
|
|
300
|
+
chain,
|
|
301
|
+
enableKernelV3Migration: this.enableKernelV3Migration,
|
|
302
|
+
entryPoint: this.entryPoint,
|
|
303
|
+
kernelVersion: this.kernelVersion,
|
|
304
|
+
paymaster,
|
|
305
|
+
paymasterRpc: this.paymasterRpc,
|
|
306
|
+
projectId,
|
|
307
|
+
provider: this.bundlerProvider,
|
|
308
|
+
publicClientRpc,
|
|
309
|
+
signer,
|
|
310
|
+
};
|
|
333
311
|
if (this.shouldUseEIP7702Mode) {
|
|
334
|
-
kernelClient = yield createEcdsaKernelAccountClient.createEcdsaKernelAccountClientWith7702({
|
|
335
|
-
authorization,
|
|
336
|
-
bundlerRpc: ZeroDevConnector.bundlerRpc,
|
|
337
|
-
chain,
|
|
338
|
-
ecdsaValidator: getEcdsaValidator.getEcdsaValidator(this.ecdsaProviderType),
|
|
339
|
-
enableKernelV3Migration: this.enableKernelV3Migration,
|
|
340
|
-
entryPoint: this.entryPoint,
|
|
341
|
-
kernelVersion: constants$1.KERNEL_V3_3_BETA,
|
|
342
|
-
paymaster,
|
|
343
|
-
paymasterRpc: ZeroDevConnector.paymasterRpc,
|
|
344
|
-
projectId,
|
|
345
|
-
provider: ZeroDevConnector.bundlerProvider,
|
|
346
|
-
publicClientRpc,
|
|
347
|
-
signer,
|
|
348
|
-
});
|
|
312
|
+
kernelClient = yield createEcdsaKernelAccountClient.createEcdsaKernelAccountClientWith7702(Object.assign(Object.assign({}, params), { kernelVersion: constants$1.KERNEL_V3_3 }));
|
|
349
313
|
}
|
|
350
314
|
else {
|
|
351
|
-
kernelClient = yield createEcdsaKernelAccountClient.createEcdsaKernelAccountClient({
|
|
352
|
-
bundlerRpc: ZeroDevConnector.bundlerRpc,
|
|
353
|
-
chain,
|
|
354
|
-
ecdsaValidator: getEcdsaValidator.getEcdsaValidator(this.ecdsaProviderType),
|
|
355
|
-
enableKernelV3Migration: this.enableKernelV3Migration,
|
|
356
|
-
entryPoint: this.entryPoint,
|
|
357
|
-
kernelVersion: this.kernelVersion,
|
|
358
|
-
paymaster,
|
|
359
|
-
paymasterRpc: ZeroDevConnector.paymasterRpc,
|
|
360
|
-
projectId,
|
|
361
|
-
provider: ZeroDevConnector.bundlerProvider,
|
|
362
|
-
publicClientRpc,
|
|
363
|
-
signer,
|
|
364
|
-
});
|
|
315
|
+
kernelClient = yield createEcdsaKernelAccountClient.createEcdsaKernelAccountClient(Object.assign(Object.assign({}, params), { ecdsaValidator: getEcdsaValidator.getEcdsaValidator(this.ecdsaProviderType) }));
|
|
365
316
|
}
|
|
366
317
|
utils.wrapMethodWithCallback(kernelClient, 'sendUserOperation', (original, ...args) => {
|
|
367
318
|
this._walletUiUtils.disabledConfirmationOnce();
|
|
@@ -414,7 +365,14 @@ class ZeroDevConnector extends ethereumAaCore.AccountAbstractionBaseConnector {
|
|
|
414
365
|
if (!effectiveProvider) {
|
|
415
366
|
throw new utils.DynamicError('No provider');
|
|
416
367
|
}
|
|
417
|
-
const
|
|
368
|
+
const unformattedTransaction = ethereumCore.unFormatTransaction(transaction);
|
|
369
|
+
const key = `${unformattedTransaction.from}-${unformattedTransaction.to}-${unformattedTransaction.data}`;
|
|
370
|
+
const cachedTransaction = this.userOperationCache[key];
|
|
371
|
+
if (cachedTransaction) {
|
|
372
|
+
const signedTransaction = yield effectiveProvider.signUserOperation(cachedTransaction.userOperation);
|
|
373
|
+
return effectiveProvider.sendUserOperation(signedTransaction);
|
|
374
|
+
}
|
|
375
|
+
const response = yield effectiveProvider.sendTransaction(unformattedTransaction);
|
|
418
376
|
return response;
|
|
419
377
|
}
|
|
420
378
|
catch (err) {
|
|
@@ -527,6 +485,10 @@ class ZeroDevConnector extends ethereumAaCore.AccountAbstractionBaseConnector {
|
|
|
527
485
|
getCurrentUserOperation(transaction) {
|
|
528
486
|
return _tslib.__awaiter(this, void 0, void 0, function* () {
|
|
529
487
|
var _a, _b;
|
|
488
|
+
const key = `${transaction.from}-${transaction.to}-${transaction.data}`;
|
|
489
|
+
if (this.userOperationCache[key]) {
|
|
490
|
+
return this.userOperationCache[key];
|
|
491
|
+
}
|
|
530
492
|
try {
|
|
531
493
|
const { kernelClientWithSponsorship } = this;
|
|
532
494
|
if (!kernelClientWithSponsorship) {
|
|
@@ -553,6 +515,11 @@ class ZeroDevConnector extends ethereumAaCore.AccountAbstractionBaseConnector {
|
|
|
553
515
|
callData,
|
|
554
516
|
}));
|
|
555
517
|
}
|
|
518
|
+
// Cache the result
|
|
519
|
+
this.userOperationCache[key] = {
|
|
520
|
+
sponsored: (sponsorResult === null || sponsorResult === void 0 ? void 0 : sponsorResult.paymasterAndData) !== '0x',
|
|
521
|
+
userOperation: sponsorResult !== null && sponsorResult !== void 0 ? sponsorResult : unsponsoredResult,
|
|
522
|
+
};
|
|
556
523
|
if ((sponsorResult === null || sponsorResult === void 0 ? void 0 : sponsorResult.paymasterAndData) === '0x')
|
|
557
524
|
return { sponsored: false, userOperation: sponsorResult };
|
|
558
525
|
return sponsorResult
|
|
@@ -615,6 +582,23 @@ class ZeroDevConnector extends ethereumAaCore.AccountAbstractionBaseConnector {
|
|
|
615
582
|
});
|
|
616
583
|
});
|
|
617
584
|
}
|
|
585
|
+
isAtomicSupported(chainId) {
|
|
586
|
+
return _tslib.__awaiter(this, void 0, void 0, function* () {
|
|
587
|
+
logger.logger.debug('[ZeroDevConnector] isAtomicSupported - is supported', {
|
|
588
|
+
chainId,
|
|
589
|
+
});
|
|
590
|
+
return true;
|
|
591
|
+
});
|
|
592
|
+
}
|
|
593
|
+
isPaymasterServiceSupported(chainId) {
|
|
594
|
+
return _tslib.__awaiter(this, void 0, void 0, function* () {
|
|
595
|
+
logger.logger.debug('[ZeroDevConnector] isPaymasterServiceSupported - not supported', {
|
|
596
|
+
chainId,
|
|
597
|
+
});
|
|
598
|
+
// TODO: update this to return true once we add support for paymaster url
|
|
599
|
+
return false;
|
|
600
|
+
});
|
|
601
|
+
}
|
|
618
602
|
}
|
|
619
603
|
|
|
620
604
|
exports.ZeroDevConnector = ZeroDevConnector;
|
|
@@ -1,16 +1,14 @@
|
|
|
1
1
|
import { KernelAccountClient } from '@zerodev/sdk/clients';
|
|
2
|
-
import {
|
|
2
|
+
import { EntryPointType, KERNEL_VERSION_TYPE } from '@zerodev/sdk/types';
|
|
3
3
|
import { Account, Client, PublicClient, RpcSchema, Transport, WalletClient } from 'viem';
|
|
4
|
-
import {
|
|
4
|
+
import { EntryPointVersion, SmartAccount } from 'viem/account-abstraction';
|
|
5
5
|
import { type Chain as ViemChain } from 'viem/chains';
|
|
6
|
-
import {
|
|
6
|
+
import { AccountAbstractionBaseConnector, AccountAbstractionConnectorProps } from '@dynamic-labs/ethereum-aa-core';
|
|
7
7
|
import { EthereumWallet, RegisterEvmProvidersConfig } from '@dynamic-labs/ethereum-core';
|
|
8
|
-
import { EcdsaValidatorOptions, Provider, ProviderEntryPointVersionEnum, ProviderEnum, ProviderKernelVersionEnum, ProviderMultichainAccountAbstractionProviders, SmartWalletProperties,
|
|
9
|
-
import { Chain, InternalWalletConnector, IZeroDevConnector } from '@dynamic-labs/wallet-connector-core';
|
|
10
|
-
import { WalletBookSchema } from '@dynamic-labs/wallet-book';
|
|
8
|
+
import { EcdsaValidatorOptions, JwtVerifiedCredential, Provider, ProviderEntryPointVersionEnum, ProviderEnum, ProviderKernelVersionEnum, ProviderMultichainAccountAbstractionProviders, SmartWalletProperties, ZerodevBundlerProvider } from '@dynamic-labs/sdk-api-core';
|
|
11
9
|
import { GenericNetwork, TransactionReceipt, WalletUiUtils } from '@dynamic-labs/types';
|
|
12
|
-
import {
|
|
13
|
-
import {
|
|
10
|
+
import { WalletBookSchema } from '@dynamic-labs/wallet-book';
|
|
11
|
+
import { Chain, InternalWalletConnector, IZeroDevConnector } from '@dynamic-labs/wallet-connector-core';
|
|
14
12
|
type ZeroDevConnectorProps = AccountAbstractionConnectorProps & {
|
|
15
13
|
apiProviders: {
|
|
16
14
|
[key in ProviderEnum]?: Provider;
|
|
@@ -18,9 +16,8 @@ type ZeroDevConnectorProps = AccountAbstractionConnectorProps & {
|
|
|
18
16
|
evmNetworks: GenericNetwork[];
|
|
19
17
|
walletBook: WalletBookSchema;
|
|
20
18
|
walletUiUtils: WalletUiUtils<InternalWalletConnector>;
|
|
21
|
-
bundlerProvider:
|
|
19
|
+
bundlerProvider: ZerodevBundlerProvider | undefined;
|
|
22
20
|
enableEIP7702?: boolean;
|
|
23
|
-
authorization?: SignAuthorizationReturnType;
|
|
24
21
|
providersConfig?: RegisterEvmProvidersConfig;
|
|
25
22
|
};
|
|
26
23
|
type KernelClient = KernelAccountClient<Transport, ViemChain, SmartAccount, Client, RpcSchema>;
|
|
@@ -41,16 +38,26 @@ export declare class ZeroDevConnector extends AccountAbstractionBaseConnector im
|
|
|
41
38
|
ecdsaProviderType: string | undefined;
|
|
42
39
|
defaultChainId: string | undefined;
|
|
43
40
|
providersFromApi: ProviderMultichainAccountAbstractionProviders[];
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
41
|
+
bundlerProvider: ZerodevBundlerProvider;
|
|
42
|
+
bundlerRpc: string | undefined;
|
|
43
|
+
paymasterRpc: string | undefined;
|
|
44
|
+
kernelDelegationAddress: `0x${string}` | undefined;
|
|
45
|
+
static bundlerProviderDefault: ZerodevBundlerProvider | undefined;
|
|
46
|
+
static bundlerRpcDefault: string | undefined;
|
|
47
|
+
static paymasterRpcDefault: string | undefined;
|
|
48
|
+
static kernelDelegationAddressDefault: `0x${string}` | undefined;
|
|
48
49
|
/**
|
|
49
50
|
* Deferred promise that resolves when the ZeroDev provider is set.
|
|
50
51
|
* This is used to make sure that the provider is set before any other method is called.
|
|
51
52
|
* This is needed because the provider is set asynchronously.
|
|
52
53
|
*/
|
|
53
54
|
private kernelClientDeferredPromise;
|
|
55
|
+
/**
|
|
56
|
+
* Cache for prepared user operations indexed by transaction details.
|
|
57
|
+
* The key is a concatenation of from-to-data to uniquely identify transactions.
|
|
58
|
+
* Used to avoid re-preparing the same user operation multiple times.
|
|
59
|
+
*/
|
|
60
|
+
private userOperationCache;
|
|
54
61
|
name: string;
|
|
55
62
|
overrideKey: string;
|
|
56
63
|
walletFallback: {
|
|
@@ -61,7 +68,6 @@ export declare class ZeroDevConnector extends AccountAbstractionBaseConnector im
|
|
|
61
68
|
name: string;
|
|
62
69
|
};
|
|
63
70
|
is7702EnabledOnDashboard: boolean;
|
|
64
|
-
private authorization?;
|
|
65
71
|
private hasExistingSmartAccount;
|
|
66
72
|
/**
|
|
67
73
|
* Flag for EIP-7702 mode, enabled when EIP-7702 is enabled and no smart account exists
|
|
@@ -103,7 +109,6 @@ export declare class ZeroDevConnector extends AccountAbstractionBaseConnector im
|
|
|
103
109
|
entryPointVersion?: ProviderEntryPointVersionEnum;
|
|
104
110
|
}): Promise<void>;
|
|
105
111
|
private determineSmartAccountStatus;
|
|
106
|
-
private getOrCreateAuthorization;
|
|
107
112
|
private setEoaConnector;
|
|
108
113
|
private warnIfProjectChainNotEnabled;
|
|
109
114
|
/**
|
|
@@ -167,5 +172,7 @@ export declare class ZeroDevConnector extends AccountAbstractionBaseConnector im
|
|
|
167
172
|
getBalance(address: string): Promise<string | undefined>;
|
|
168
173
|
signMessage(messageToSign: string): Promise<string | undefined>;
|
|
169
174
|
validateActiveWallet(expectedAddress: string): Promise<void>;
|
|
175
|
+
isAtomicSupported(chainId?: number): Promise<boolean>;
|
|
176
|
+
isPaymasterServiceSupported(chainId?: number): Promise<boolean>;
|
|
170
177
|
}
|
|
171
178
|
export {};
|
package/src/ZeroDevConnector.js
CHANGED
|
@@ -1,25 +1,24 @@
|
|
|
1
1
|
'use client'
|
|
2
2
|
import { __awaiter, __rest } from '../_virtual/_tslib.js';
|
|
3
|
+
import { KERNEL_V3_3, getEntryPoint as getEntryPoint$1 } from '@zerodev/sdk/constants';
|
|
3
4
|
import { publicActions, custom, createWalletClient, toHex, formatEther } from 'viem';
|
|
4
5
|
import { toAccount } from 'viem/accounts';
|
|
5
|
-
import {
|
|
6
|
+
import { AccountAbstractionBaseConnector } from '@dynamic-labs/ethereum-aa-core';
|
|
6
7
|
import { EthereumWallet, isEthWalletConnector, chainsMap, confirmationTransport, unFormatTransaction } from '@dynamic-labs/ethereum-core';
|
|
7
|
-
import { WalletProviderEnum } from '@dynamic-labs/sdk-api-core';
|
|
8
|
-
import { eventListenerHandlers, getWalletProvider } from '@dynamic-labs/wallet-connector-core';
|
|
8
|
+
import { ZerodevBundlerProvider, WalletProviderEnum } from '@dynamic-labs/sdk-api-core';
|
|
9
9
|
import { parseEvmNetworks, StorageService, DynamicError, DeferredPromise, parseChainId, wrapMethodWithCallback, TransactionGasCannotBeSponsoredError, InsufficientFundsError } from '@dynamic-labs/utils';
|
|
10
|
-
import {
|
|
10
|
+
import { eventListenerHandlers, getWalletProvider } from '@dynamic-labs/wallet-connector-core';
|
|
11
11
|
import { ZERO_DEV_LAST_USED_CHAIN_ID_KEY } from './constants.js';
|
|
12
12
|
import { logger } from './utils/logger.js';
|
|
13
13
|
import { createEcdsaKernelAccountClientWith7702, createEcdsaKernelAccountClient } from './utils/createEcdsaKernelAccountClient.js';
|
|
14
14
|
import { getEcdsaValidator } from './utils/getEcdsaValidator.js';
|
|
15
15
|
import { getEntryPoint } from './utils/getEntryPoint.js';
|
|
16
16
|
import { getKernelVersion } from './utils/getKernelVersion.js';
|
|
17
|
-
import { isEVMAuthorizationCapable } from './utils/isEVMAuthorizationCapable.js';
|
|
18
17
|
import { hasSmartAccount } from './utils/hasSmartAccount.js';
|
|
19
18
|
|
|
20
19
|
class ZeroDevConnector extends AccountAbstractionBaseConnector {
|
|
21
20
|
constructor(opts) {
|
|
22
|
-
var _a, _b, _c, _d, _e, _f, _g, _h, _j;
|
|
21
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r, _s, _t;
|
|
23
22
|
super(opts);
|
|
24
23
|
// provider map maintains the kernel clients per chain
|
|
25
24
|
this.providerMap = {};
|
|
@@ -30,6 +29,12 @@ class ZeroDevConnector extends AccountAbstractionBaseConnector {
|
|
|
30
29
|
this.supportedChains = ['ETH', 'EVM'];
|
|
31
30
|
this.isEmbeddedWallet = true;
|
|
32
31
|
this.providersFromApi = [];
|
|
32
|
+
/**
|
|
33
|
+
* Cache for prepared user operations indexed by transaction details.
|
|
34
|
+
* The key is a concatenation of from-to-data to uniquely identify transactions.
|
|
35
|
+
* Used to avoid re-preparing the same user operation multiple times.
|
|
36
|
+
*/
|
|
37
|
+
this.userOperationCache = {};
|
|
33
38
|
this.name = 'ZeroDev';
|
|
34
39
|
this.overrideKey = 'zerodev';
|
|
35
40
|
this.walletFallback = {
|
|
@@ -49,12 +54,20 @@ class ZeroDevConnector extends AccountAbstractionBaseConnector {
|
|
|
49
54
|
this.is7702EnabledOnDashboard =
|
|
50
55
|
(_c = (_b = opts.apiProviders.zerodev) === null || _b === void 0 ? void 0 : _b.enableEIP7702) !== null && _c !== void 0 ? _c : false;
|
|
51
56
|
this.entryPoint = getEntryPoint((_d = opts.apiProviders.zerodev) === null || _d === void 0 ? void 0 : _d.entryPointVersion);
|
|
52
|
-
this.
|
|
57
|
+
this.bundlerProvider =
|
|
58
|
+
(_g = (_f = (_e = opts.apiProviders.zerodev) === null || _e === void 0 ? void 0 : _e.zerodevBundlerProvider) !== null && _f !== void 0 ? _f : ZeroDevConnector.bundlerProviderDefault) !== null && _g !== void 0 ? _g : ZerodevBundlerProvider.Gelato;
|
|
59
|
+
this.bundlerRpc =
|
|
60
|
+
(_j = (_h = opts.apiProviders.zerodev) === null || _h === void 0 ? void 0 : _h.zerodevBundlerRpcUrl) !== null && _j !== void 0 ? _j : ZeroDevConnector.bundlerRpcDefault;
|
|
61
|
+
this.paymasterRpc =
|
|
62
|
+
(_l = (_k = opts.apiProviders.zerodev) === null || _k === void 0 ? void 0 : _k.zerodevPaymasterRpcUrl) !== null && _l !== void 0 ? _l : ZeroDevConnector.paymasterRpcDefault;
|
|
63
|
+
this.kernelDelegationAddress =
|
|
64
|
+
(_o = (_m = opts.apiProviders.zerodev) === null || _m === void 0 ? void 0 : _m.zerodevKernelDelegationAddress) !== null && _o !== void 0 ? _o : ZeroDevConnector.kernelDelegationAddressDefault;
|
|
65
|
+
this.kernelVersion = getKernelVersion((_p = opts.apiProviders.zerodev) === null || _p === void 0 ? void 0 : _p.kernelVersion, this.entryPoint);
|
|
53
66
|
this.enableKernelV3Migration =
|
|
54
|
-
(
|
|
67
|
+
(_r = (_q = opts.apiProviders.zerodev) === null || _q === void 0 ? void 0 : _q.enableKernelV3Migration) !== null && _r !== void 0 ? _r : false;
|
|
55
68
|
// this is the list of providers from the api that are used for multi-chain account abstraction
|
|
56
69
|
this.providersFromApi =
|
|
57
|
-
((
|
|
70
|
+
((_s = opts.apiProviders.zerodev) === null || _s === void 0 ? void 0 : _s.multichainAccountAbstractionProviders) || [];
|
|
58
71
|
const enabledZerodevNetworks = this.providersFromApi.map((provider) => provider.chain);
|
|
59
72
|
this.evmNetworks = parseEvmNetworks(opts.evmNetworks).filter((network) => enabledZerodevNetworks.includes(network.chainId.toString()));
|
|
60
73
|
const [defaultProvider] = this.providersFromApi;
|
|
@@ -63,7 +76,7 @@ class ZeroDevConnector extends AccountAbstractionBaseConnector {
|
|
|
63
76
|
throw new Error('Missing ZeroDev project ID provided. Add your ZeroDev project id to your project configuration via the Dynamic Labs dashboard.');
|
|
64
77
|
}
|
|
65
78
|
this.defaultChainId = defaultProvider === null || defaultProvider === void 0 ? void 0 : defaultProvider.chain;
|
|
66
|
-
this.ecdsaProviderType = (
|
|
79
|
+
this.ecdsaProviderType = (_t = opts.apiProviders.zerodev) === null || _t === void 0 ? void 0 : _t.ecdsaProviderType;
|
|
67
80
|
}
|
|
68
81
|
confirmTransactionStatus() {
|
|
69
82
|
throw new Error('confirmTransactionStatus not implemented in ZeroDevConnector');
|
|
@@ -175,49 +188,6 @@ class ZeroDevConnector extends AccountAbstractionBaseConnector {
|
|
|
175
188
|
this.shouldUseEIP7702Mode =
|
|
176
189
|
this.is7702EnabledOnDashboard && !this.hasExistingSmartAccount;
|
|
177
190
|
}
|
|
178
|
-
getOrCreateAuthorization() {
|
|
179
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
180
|
-
var _a;
|
|
181
|
-
if (!this.eoaConnector)
|
|
182
|
-
throw new DynamicError('No EOA connector');
|
|
183
|
-
if (!isEVMAuthorizationCapable(this.eoaConnector)) {
|
|
184
|
-
throw new DynamicError('Connector does not support EVM authorization');
|
|
185
|
-
}
|
|
186
|
-
const ZERODEV_AUTHORIZATION = 'zerodev_authorization';
|
|
187
|
-
try {
|
|
188
|
-
const storedAuthorization = StorageService.getItem(ZERODEV_AUTHORIZATION);
|
|
189
|
-
if (storedAuthorization) {
|
|
190
|
-
return storedAuthorization;
|
|
191
|
-
}
|
|
192
|
-
const kernelVersion = KERNEL_V3_3_BETA;
|
|
193
|
-
const authorization = yield this.eoaConnector.experimental_signAuthorization({
|
|
194
|
-
contractAddress: (_a = ZeroDevConnector.kernelDelegationAddress) !== null && _a !== void 0 ? _a : KernelVersionToAddressesMap[kernelVersion]
|
|
195
|
-
.accountImplementationAddress,
|
|
196
|
-
});
|
|
197
|
-
if (authorization) {
|
|
198
|
-
const serializedAuth = Object.entries(authorization).reduce((acc, [key, value]) => {
|
|
199
|
-
acc[key] = typeof value === 'bigint' ? value.toString() : value;
|
|
200
|
-
return acc;
|
|
201
|
-
}, {});
|
|
202
|
-
StorageService.setItem(ZERODEV_AUTHORIZATION, serializedAuth);
|
|
203
|
-
}
|
|
204
|
-
return {
|
|
205
|
-
address: authorization.contractAddress,
|
|
206
|
-
chainId: authorization.chainId,
|
|
207
|
-
nonce: authorization.nonce,
|
|
208
|
-
r: authorization.r,
|
|
209
|
-
s: authorization.s,
|
|
210
|
-
v: authorization.v,
|
|
211
|
-
yParity: authorization.yParity,
|
|
212
|
-
};
|
|
213
|
-
}
|
|
214
|
-
catch (error) {
|
|
215
|
-
logger.error('Failed to get/set authorization:', error);
|
|
216
|
-
StorageService.removeItem(ZERODEV_AUTHORIZATION);
|
|
217
|
-
return undefined;
|
|
218
|
-
}
|
|
219
|
-
});
|
|
220
|
-
}
|
|
221
191
|
setEoaConnector(_a) {
|
|
222
192
|
return __awaiter(this, arguments, void 0, function* ({ eoaAddress, connector, properties, }) {
|
|
223
193
|
var _b, _c;
|
|
@@ -247,10 +217,6 @@ class ZeroDevConnector extends AccountAbstractionBaseConnector {
|
|
|
247
217
|
yield this.eoaConnector.getConnectedAccounts();
|
|
248
218
|
}
|
|
249
219
|
const signer = yield this.eoaConnector.getSigner();
|
|
250
|
-
signer.account = toAccount(eoaAddress);
|
|
251
|
-
if (this.shouldUseEIP7702Mode) {
|
|
252
|
-
this.authorization = yield this.getOrCreateAuthorization();
|
|
253
|
-
}
|
|
254
220
|
yield this.generateProviderMap(signer);
|
|
255
221
|
this.kernelClientDeferredPromise.resolve();
|
|
256
222
|
});
|
|
@@ -288,7 +254,6 @@ class ZeroDevConnector extends AccountAbstractionBaseConnector {
|
|
|
288
254
|
signer,
|
|
289
255
|
}),
|
|
290
256
|
this.createKernelClient({
|
|
291
|
-
authorization: this.authorization,
|
|
292
257
|
chainId: chain,
|
|
293
258
|
paymaster: 'SPONSOR',
|
|
294
259
|
projectId: clientId,
|
|
@@ -312,7 +277,7 @@ class ZeroDevConnector extends AccountAbstractionBaseConnector {
|
|
|
312
277
|
});
|
|
313
278
|
}
|
|
314
279
|
createKernelClient(_a) {
|
|
315
|
-
return __awaiter(this, arguments, void 0, function* ({ chainId, projectId, signer, paymaster,
|
|
280
|
+
return __awaiter(this, arguments, void 0, function* ({ chainId, projectId, signer, paymaster, }) {
|
|
316
281
|
var _b;
|
|
317
282
|
if (chainId && this.providerMap[chainId]) {
|
|
318
283
|
return paymaster === 'SPONSOR'
|
|
@@ -326,38 +291,24 @@ class ZeroDevConnector extends AccountAbstractionBaseConnector {
|
|
|
326
291
|
const network = this.evmNetworks.find((network) => network.chainId === parseChainId(chainId));
|
|
327
292
|
const publicClientRpc = (_b = network === null || network === void 0 ? void 0 : network.privateCustomerRpcUrls) === null || _b === void 0 ? void 0 : _b[0];
|
|
328
293
|
let kernelClient;
|
|
294
|
+
const params = {
|
|
295
|
+
bundlerRpc: this.bundlerRpc,
|
|
296
|
+
chain,
|
|
297
|
+
enableKernelV3Migration: this.enableKernelV3Migration,
|
|
298
|
+
entryPoint: this.entryPoint,
|
|
299
|
+
kernelVersion: this.kernelVersion,
|
|
300
|
+
paymaster,
|
|
301
|
+
paymasterRpc: this.paymasterRpc,
|
|
302
|
+
projectId,
|
|
303
|
+
provider: this.bundlerProvider,
|
|
304
|
+
publicClientRpc,
|
|
305
|
+
signer,
|
|
306
|
+
};
|
|
329
307
|
if (this.shouldUseEIP7702Mode) {
|
|
330
|
-
kernelClient = yield createEcdsaKernelAccountClientWith7702({
|
|
331
|
-
authorization,
|
|
332
|
-
bundlerRpc: ZeroDevConnector.bundlerRpc,
|
|
333
|
-
chain,
|
|
334
|
-
ecdsaValidator: getEcdsaValidator(this.ecdsaProviderType),
|
|
335
|
-
enableKernelV3Migration: this.enableKernelV3Migration,
|
|
336
|
-
entryPoint: this.entryPoint,
|
|
337
|
-
kernelVersion: KERNEL_V3_3_BETA,
|
|
338
|
-
paymaster,
|
|
339
|
-
paymasterRpc: ZeroDevConnector.paymasterRpc,
|
|
340
|
-
projectId,
|
|
341
|
-
provider: ZeroDevConnector.bundlerProvider,
|
|
342
|
-
publicClientRpc,
|
|
343
|
-
signer,
|
|
344
|
-
});
|
|
308
|
+
kernelClient = yield createEcdsaKernelAccountClientWith7702(Object.assign(Object.assign({}, params), { kernelVersion: KERNEL_V3_3 }));
|
|
345
309
|
}
|
|
346
310
|
else {
|
|
347
|
-
kernelClient = yield createEcdsaKernelAccountClient({
|
|
348
|
-
bundlerRpc: ZeroDevConnector.bundlerRpc,
|
|
349
|
-
chain,
|
|
350
|
-
ecdsaValidator: getEcdsaValidator(this.ecdsaProviderType),
|
|
351
|
-
enableKernelV3Migration: this.enableKernelV3Migration,
|
|
352
|
-
entryPoint: this.entryPoint,
|
|
353
|
-
kernelVersion: this.kernelVersion,
|
|
354
|
-
paymaster,
|
|
355
|
-
paymasterRpc: ZeroDevConnector.paymasterRpc,
|
|
356
|
-
projectId,
|
|
357
|
-
provider: ZeroDevConnector.bundlerProvider,
|
|
358
|
-
publicClientRpc,
|
|
359
|
-
signer,
|
|
360
|
-
});
|
|
311
|
+
kernelClient = yield createEcdsaKernelAccountClient(Object.assign(Object.assign({}, params), { ecdsaValidator: getEcdsaValidator(this.ecdsaProviderType) }));
|
|
361
312
|
}
|
|
362
313
|
wrapMethodWithCallback(kernelClient, 'sendUserOperation', (original, ...args) => {
|
|
363
314
|
this._walletUiUtils.disabledConfirmationOnce();
|
|
@@ -410,7 +361,14 @@ class ZeroDevConnector extends AccountAbstractionBaseConnector {
|
|
|
410
361
|
if (!effectiveProvider) {
|
|
411
362
|
throw new DynamicError('No provider');
|
|
412
363
|
}
|
|
413
|
-
const
|
|
364
|
+
const unformattedTransaction = unFormatTransaction(transaction);
|
|
365
|
+
const key = `${unformattedTransaction.from}-${unformattedTransaction.to}-${unformattedTransaction.data}`;
|
|
366
|
+
const cachedTransaction = this.userOperationCache[key];
|
|
367
|
+
if (cachedTransaction) {
|
|
368
|
+
const signedTransaction = yield effectiveProvider.signUserOperation(cachedTransaction.userOperation);
|
|
369
|
+
return effectiveProvider.sendUserOperation(signedTransaction);
|
|
370
|
+
}
|
|
371
|
+
const response = yield effectiveProvider.sendTransaction(unformattedTransaction);
|
|
414
372
|
return response;
|
|
415
373
|
}
|
|
416
374
|
catch (err) {
|
|
@@ -523,6 +481,10 @@ class ZeroDevConnector extends AccountAbstractionBaseConnector {
|
|
|
523
481
|
getCurrentUserOperation(transaction) {
|
|
524
482
|
return __awaiter(this, void 0, void 0, function* () {
|
|
525
483
|
var _a, _b;
|
|
484
|
+
const key = `${transaction.from}-${transaction.to}-${transaction.data}`;
|
|
485
|
+
if (this.userOperationCache[key]) {
|
|
486
|
+
return this.userOperationCache[key];
|
|
487
|
+
}
|
|
526
488
|
try {
|
|
527
489
|
const { kernelClientWithSponsorship } = this;
|
|
528
490
|
if (!kernelClientWithSponsorship) {
|
|
@@ -549,6 +511,11 @@ class ZeroDevConnector extends AccountAbstractionBaseConnector {
|
|
|
549
511
|
callData,
|
|
550
512
|
}));
|
|
551
513
|
}
|
|
514
|
+
// Cache the result
|
|
515
|
+
this.userOperationCache[key] = {
|
|
516
|
+
sponsored: (sponsorResult === null || sponsorResult === void 0 ? void 0 : sponsorResult.paymasterAndData) !== '0x',
|
|
517
|
+
userOperation: sponsorResult !== null && sponsorResult !== void 0 ? sponsorResult : unsponsoredResult,
|
|
518
|
+
};
|
|
552
519
|
if ((sponsorResult === null || sponsorResult === void 0 ? void 0 : sponsorResult.paymasterAndData) === '0x')
|
|
553
520
|
return { sponsored: false, userOperation: sponsorResult };
|
|
554
521
|
return sponsorResult
|
|
@@ -611,6 +578,23 @@ class ZeroDevConnector extends AccountAbstractionBaseConnector {
|
|
|
611
578
|
});
|
|
612
579
|
});
|
|
613
580
|
}
|
|
581
|
+
isAtomicSupported(chainId) {
|
|
582
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
583
|
+
logger.debug('[ZeroDevConnector] isAtomicSupported - is supported', {
|
|
584
|
+
chainId,
|
|
585
|
+
});
|
|
586
|
+
return true;
|
|
587
|
+
});
|
|
588
|
+
}
|
|
589
|
+
isPaymasterServiceSupported(chainId) {
|
|
590
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
591
|
+
logger.debug('[ZeroDevConnector] isPaymasterServiceSupported - not supported', {
|
|
592
|
+
chainId,
|
|
593
|
+
});
|
|
594
|
+
// TODO: update this to return true once we add support for paymaster url
|
|
595
|
+
return false;
|
|
596
|
+
});
|
|
597
|
+
}
|
|
614
598
|
}
|
|
615
599
|
|
|
616
600
|
export { ZeroDevConnector };
|
package/src/index.cjs
CHANGED
|
@@ -14,11 +14,15 @@ var getKernelVersion = require('./utils/getKernelVersion.cjs');
|
|
|
14
14
|
var isZeroDevConnector = require('./utils/isZeroDevConnector.cjs');
|
|
15
15
|
|
|
16
16
|
assertPackageVersion.assertPackageVersion('@dynamic-labs/ethereum-aa', _package.version);
|
|
17
|
+
/**
|
|
18
|
+
* Allows defining default values for zerodev configs.
|
|
19
|
+
* Values configured in the dashboard will take precedence over these values.
|
|
20
|
+
*/
|
|
17
21
|
const ZeroDevSmartWalletConnectorsWithConfig = ({ bundlerProvider, bundlerRpc, paymasterRpc, kernelDelegationAddress, } = {}) => {
|
|
18
|
-
ZeroDevConnector.ZeroDevConnector.
|
|
19
|
-
ZeroDevConnector.ZeroDevConnector.
|
|
20
|
-
ZeroDevConnector.ZeroDevConnector.
|
|
21
|
-
ZeroDevConnector.ZeroDevConnector.
|
|
22
|
+
ZeroDevConnector.ZeroDevConnector.bundlerProviderDefault = bundlerProvider;
|
|
23
|
+
ZeroDevConnector.ZeroDevConnector.bundlerRpcDefault = bundlerRpc;
|
|
24
|
+
ZeroDevConnector.ZeroDevConnector.paymasterRpcDefault = paymasterRpc;
|
|
25
|
+
ZeroDevConnector.ZeroDevConnector.kernelDelegationAddressDefault = kernelDelegationAddress;
|
|
22
26
|
return ZeroDevSmartWalletConnectors;
|
|
23
27
|
};
|
|
24
28
|
const ZeroDevSmartWalletConnectors = (props) => {
|
package/src/index.d.ts
CHANGED
|
@@ -1,13 +1,20 @@
|
|
|
1
|
+
import { ZerodevBundlerProvider } from '@dynamic-labs/sdk-api-core';
|
|
1
2
|
import { WalletConnectorConstructor } from '@dynamic-labs/wallet-connector-core';
|
|
2
|
-
|
|
3
|
-
export { createEcdsaKernelAccountClient, type BundlerProvider, type PaymasterType, } from './utils/createEcdsaKernelAccountClient';
|
|
3
|
+
export { createEcdsaKernelAccountClient, type PaymasterType, } from './utils/createEcdsaKernelAccountClient';
|
|
4
4
|
export { fetchZeroDevChain } from './utils/fetchZeroDevChain';
|
|
5
5
|
export { getEcdsaValidator } from './utils/getEcdsaValidator';
|
|
6
6
|
export { getEntryPoint } from './utils/getEntryPoint';
|
|
7
7
|
export { getKernelVersion } from './utils/getKernelVersion';
|
|
8
8
|
export { isZeroDevConnector } from './utils/isZeroDevConnector';
|
|
9
|
+
export type {
|
|
10
|
+
/** @deprecated Use ZerodevBundlerProvider from \@dynamic-labs/sdk-api-core instead */
|
|
11
|
+
ZerodevBundlerProvider as BundlerProvider, } from '@dynamic-labs/sdk-api-core';
|
|
12
|
+
/**
|
|
13
|
+
* Allows defining default values for zerodev configs.
|
|
14
|
+
* Values configured in the dashboard will take precedence over these values.
|
|
15
|
+
*/
|
|
9
16
|
export declare const ZeroDevSmartWalletConnectorsWithConfig: ({ bundlerProvider, bundlerRpc, paymasterRpc, kernelDelegationAddress, }?: {
|
|
10
|
-
bundlerProvider?:
|
|
17
|
+
bundlerProvider?: ZerodevBundlerProvider;
|
|
11
18
|
bundlerRpc?: string;
|
|
12
19
|
paymasterRpc?: string;
|
|
13
20
|
kernelDelegationAddress?: `0x${string}`;
|
package/src/index.js
CHANGED
|
@@ -10,11 +10,15 @@ export { getKernelVersion } from './utils/getKernelVersion.js';
|
|
|
10
10
|
export { isZeroDevConnector } from './utils/isZeroDevConnector.js';
|
|
11
11
|
|
|
12
12
|
assertPackageVersion('@dynamic-labs/ethereum-aa', version);
|
|
13
|
+
/**
|
|
14
|
+
* Allows defining default values for zerodev configs.
|
|
15
|
+
* Values configured in the dashboard will take precedence over these values.
|
|
16
|
+
*/
|
|
13
17
|
const ZeroDevSmartWalletConnectorsWithConfig = ({ bundlerProvider, bundlerRpc, paymasterRpc, kernelDelegationAddress, } = {}) => {
|
|
14
|
-
ZeroDevConnector.
|
|
15
|
-
ZeroDevConnector.
|
|
16
|
-
ZeroDevConnector.
|
|
17
|
-
ZeroDevConnector.
|
|
18
|
+
ZeroDevConnector.bundlerProviderDefault = bundlerProvider;
|
|
19
|
+
ZeroDevConnector.bundlerRpcDefault = bundlerRpc;
|
|
20
|
+
ZeroDevConnector.paymasterRpcDefault = paymasterRpc;
|
|
21
|
+
ZeroDevConnector.kernelDelegationAddressDefault = kernelDelegationAddress;
|
|
18
22
|
return ZeroDevSmartWalletConnectors;
|
|
19
23
|
};
|
|
20
24
|
const ZeroDevSmartWalletConnectors = (props) => {
|
|
@@ -97,27 +97,27 @@ const createEcdsaKernelAccountClient = (_b) => _tslib.__awaiter(void 0, [_b], vo
|
|
|
97
97
|
const clientConfig = createKernelClientConfig(selectedAccount, resolvedBundlerRpc, chain, publicClient, paymasterHandler);
|
|
98
98
|
return clients.createKernelAccountClient(clientConfig);
|
|
99
99
|
});
|
|
100
|
-
const createEcdsaKernelAccountClientWith7702 = (_c) => _tslib.__awaiter(void 0, [_c], void 0, function* ({ bundlerRpc, chain, paymasterRpc, projectId, signer, provider,
|
|
100
|
+
const createEcdsaKernelAccountClientWith7702 = (_c) => _tslib.__awaiter(void 0, [_c], void 0, function* ({ bundlerRpc, chain, paymasterRpc, projectId, signer, provider, paymaster = 'SPONSOR', entryPoint, kernelVersion, publicClientRpc, }) {
|
|
101
101
|
const resolvedBundlerRpc = bundlerRpc !== null && bundlerRpc !== void 0 ? bundlerRpc : getZeroDevBundlerRPC(projectId, provider);
|
|
102
102
|
const resolvedPaymasterRpc = paymasterRpc !== null && paymasterRpc !== void 0 ? paymasterRpc : getZeroDevPaymasterRPC(projectId, provider);
|
|
103
103
|
const { publicClient, zerodevPaymaster } = createPublicAndPaymasterClients(resolvedBundlerRpc, resolvedPaymasterRpc, chain, publicClientRpc);
|
|
104
|
-
const
|
|
104
|
+
const account = yield ecdsaValidator.create7702KernelAccount(publicClient, {
|
|
105
105
|
entryPoint,
|
|
106
106
|
kernelVersion,
|
|
107
|
-
signer,
|
|
107
|
+
signer: signer.account,
|
|
108
108
|
});
|
|
109
|
-
const
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
109
|
+
const paymasterHandler = createPaymasterHandler(paymaster, zerodevPaymaster);
|
|
110
|
+
const kernelClient = ecdsaValidator.create7702KernelAccountClient({
|
|
111
|
+
account: account, // TODO: check with zerodev team why this type is broken
|
|
112
|
+
bundlerTransport: viem.http(resolvedBundlerRpc),
|
|
113
|
+
chain,
|
|
114
|
+
client: publicClient,
|
|
115
|
+
paymaster: paymasterHandler,
|
|
116
|
+
userOperation: {
|
|
117
|
+
estimateFeesPerGas: (_d) => _tslib.__awaiter(void 0, [_d], void 0, function* ({ bundlerClient }) { return actions.getUserOperationGasPrice(bundlerClient); }),
|
|
116
118
|
},
|
|
117
119
|
});
|
|
118
|
-
|
|
119
|
-
const clientConfig = createKernelClientConfig(account, resolvedBundlerRpc, chain, publicClient, paymasterHandler);
|
|
120
|
-
return clients.createKernelAccountClient(clientConfig);
|
|
120
|
+
return kernelClient;
|
|
121
121
|
});
|
|
122
122
|
|
|
123
123
|
exports.createEcdsaKernelAccountClient = createEcdsaKernelAccountClient;
|
|
@@ -3,12 +3,11 @@ import { KernelAccountClient } from '@zerodev/sdk/clients';
|
|
|
3
3
|
import { type Chain as ViemChain } from 'viem/chains';
|
|
4
4
|
import { Address, WalletClient, Account, type Chain, type Client, type RpcSchema, type Transport } from 'viem';
|
|
5
5
|
import { EntryPointType, GetKernelVersion } from '@zerodev/sdk/types';
|
|
6
|
-
import {
|
|
7
|
-
export type BundlerProvider = 'STACKUP' | 'PIMLICO' | 'ALCHEMY' | 'GELATO';
|
|
6
|
+
import { ZerodevBundlerProvider } from '@dynamic-labs/sdk-api-core';
|
|
8
7
|
export type ERC20Paymaster = Address;
|
|
9
8
|
export type PaymasterType = 'NONE' | 'SPONSOR' | ERC20Paymaster;
|
|
10
|
-
export declare const getZeroDevBundlerRPC: (projectId: string, provider?:
|
|
11
|
-
export declare const getZeroDevPaymasterRPC: (projectId: string, provider?:
|
|
9
|
+
export declare const getZeroDevBundlerRPC: (projectId: string, provider?: ZerodevBundlerProvider) => string;
|
|
10
|
+
export declare const getZeroDevPaymasterRPC: (projectId: string, provider?: ZerodevBundlerProvider) => string;
|
|
12
11
|
type CommonClientParams<TChain extends Chain | undefined = Chain | undefined> = {
|
|
13
12
|
bundlerRpc?: string;
|
|
14
13
|
chain: TChain;
|
|
@@ -17,14 +16,13 @@ type CommonClientParams<TChain extends Chain | undefined = Chain | undefined> =
|
|
|
17
16
|
paymaster: PaymasterType;
|
|
18
17
|
paymasterRpc?: string;
|
|
19
18
|
entryPoint: EntryPointType<EntryPointVersion>;
|
|
20
|
-
provider?:
|
|
19
|
+
provider?: ZerodevBundlerProvider;
|
|
21
20
|
kernelVersion: GetKernelVersion<EntryPointVersion>;
|
|
22
|
-
ecdsaValidator: any;
|
|
23
21
|
enableKernelV3Migration: boolean;
|
|
24
22
|
publicClientRpc?: string;
|
|
25
23
|
};
|
|
26
|
-
export declare const createEcdsaKernelAccountClient: <entryPoint extends EntryPointVersion, TChain extends ViemChain | undefined = ViemChain | undefined>({ bundlerRpc, chain, paymasterRpc, projectId, signer, provider, paymaster, entryPoint, kernelVersion, ecdsaValidator, enableKernelV3Migration, publicClientRpc, }: CommonClientParams<TChain>
|
|
27
|
-
|
|
28
|
-
authorization?: SignAuthorizationReturnType;
|
|
24
|
+
export declare const createEcdsaKernelAccountClient: <entryPoint extends EntryPointVersion, TChain extends ViemChain | undefined = ViemChain | undefined>({ bundlerRpc, chain, paymasterRpc, projectId, signer, provider, paymaster, entryPoint, kernelVersion, ecdsaValidator, enableKernelV3Migration, publicClientRpc, }: CommonClientParams<TChain> & {
|
|
25
|
+
ecdsaValidator: any;
|
|
29
26
|
}) => Promise<KernelAccountClient<Transport, ViemChain, SmartAccount, Client, RpcSchema>>;
|
|
27
|
+
export declare const createEcdsaKernelAccountClientWith7702: <TChain extends ViemChain | undefined = ViemChain | undefined>({ bundlerRpc, chain, paymasterRpc, projectId, signer, provider, paymaster, entryPoint, kernelVersion, publicClientRpc, }: CommonClientParams<TChain>) => Promise<KernelAccountClient<Transport, ViemChain, SmartAccount, Client, RpcSchema>>;
|
|
30
28
|
export {};
|
|
@@ -4,7 +4,7 @@ import { createKernelAccount } from '@zerodev/sdk/accounts';
|
|
|
4
4
|
import { createKernelAccountClient, createZeroDevPaymasterClient } from '@zerodev/sdk/clients';
|
|
5
5
|
import { getUserOperationGasPrice } from '@zerodev/sdk/actions';
|
|
6
6
|
import { createPublicClient, http, isAddress } from 'viem';
|
|
7
|
-
import { createEcdsaKernelMigrationAccount } from '@zerodev/ecdsa-validator';
|
|
7
|
+
import { createEcdsaKernelMigrationAccount, create7702KernelAccount, create7702KernelAccountClient } from '@zerodev/ecdsa-validator';
|
|
8
8
|
import { KERNEL_V3_1 } from '@zerodev/sdk/constants';
|
|
9
9
|
|
|
10
10
|
const getZeroDevBundlerRPC = (projectId, provider) => {
|
|
@@ -93,27 +93,27 @@ const createEcdsaKernelAccountClient = (_b) => __awaiter(void 0, [_b], void 0, f
|
|
|
93
93
|
const clientConfig = createKernelClientConfig(selectedAccount, resolvedBundlerRpc, chain, publicClient, paymasterHandler);
|
|
94
94
|
return createKernelAccountClient(clientConfig);
|
|
95
95
|
});
|
|
96
|
-
const createEcdsaKernelAccountClientWith7702 = (_c) => __awaiter(void 0, [_c], void 0, function* ({ bundlerRpc, chain, paymasterRpc, projectId, signer, provider,
|
|
96
|
+
const createEcdsaKernelAccountClientWith7702 = (_c) => __awaiter(void 0, [_c], void 0, function* ({ bundlerRpc, chain, paymasterRpc, projectId, signer, provider, paymaster = 'SPONSOR', entryPoint, kernelVersion, publicClientRpc, }) {
|
|
97
97
|
const resolvedBundlerRpc = bundlerRpc !== null && bundlerRpc !== void 0 ? bundlerRpc : getZeroDevBundlerRPC(projectId, provider);
|
|
98
98
|
const resolvedPaymasterRpc = paymasterRpc !== null && paymasterRpc !== void 0 ? paymasterRpc : getZeroDevPaymasterRPC(projectId, provider);
|
|
99
99
|
const { publicClient, zerodevPaymaster } = createPublicAndPaymasterClients(resolvedBundlerRpc, resolvedPaymasterRpc, chain, publicClientRpc);
|
|
100
|
-
const
|
|
100
|
+
const account = yield create7702KernelAccount(publicClient, {
|
|
101
101
|
entryPoint,
|
|
102
102
|
kernelVersion,
|
|
103
|
-
signer,
|
|
103
|
+
signer: signer.account,
|
|
104
104
|
});
|
|
105
|
-
const
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
105
|
+
const paymasterHandler = createPaymasterHandler(paymaster, zerodevPaymaster);
|
|
106
|
+
const kernelClient = create7702KernelAccountClient({
|
|
107
|
+
account: account, // TODO: check with zerodev team why this type is broken
|
|
108
|
+
bundlerTransport: http(resolvedBundlerRpc),
|
|
109
|
+
chain,
|
|
110
|
+
client: publicClient,
|
|
111
|
+
paymaster: paymasterHandler,
|
|
112
|
+
userOperation: {
|
|
113
|
+
estimateFeesPerGas: (_d) => __awaiter(void 0, [_d], void 0, function* ({ bundlerClient }) { return getUserOperationGasPrice(bundlerClient); }),
|
|
112
114
|
},
|
|
113
115
|
});
|
|
114
|
-
|
|
115
|
-
const clientConfig = createKernelClientConfig(account, resolvedBundlerRpc, chain, publicClient, paymasterHandler);
|
|
116
|
-
return createKernelAccountClient(clientConfig);
|
|
116
|
+
return kernelClient;
|
|
117
117
|
});
|
|
118
118
|
|
|
119
119
|
export { createEcdsaKernelAccountClient, createEcdsaKernelAccountClientWith7702, getZeroDevBundlerRPC, getZeroDevPaymasterRPC };
|
package/src/utils/index.d.ts
CHANGED
|
@@ -1,6 +0,0 @@
|
|
|
1
|
-
import { InternalWalletConnector, EVMAuthorizationParameters, EVMAuthorizationResult } from '@dynamic-labs/wallet-connector-core';
|
|
2
|
-
type EVMAuthorizationCapableConnector = InternalWalletConnector & {
|
|
3
|
-
experimental_signAuthorization: (params: EVMAuthorizationParameters) => Promise<EVMAuthorizationResult>;
|
|
4
|
-
};
|
|
5
|
-
export declare const isEVMAuthorizationCapable: (connector: InternalWalletConnector) => connector is EVMAuthorizationCapableConnector;
|
|
6
|
-
export {};
|