@dynamic-labs/ethereum-aa 4.16.0 → 4.18.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 +27 -0
- package/package.cjs +1 -1
- package/package.js +1 -1
- package/package.json +12 -12
- package/src/ZeroDevConnector.cjs +84 -87
- package/src/ZeroDevConnector.d.ts +20 -8
- package/src/ZeroDevConnector.js +86 -89
- package/src/utils/createEcdsaKernelAccountClient.cjs +13 -13
- package/src/utils/createEcdsaKernelAccountClient.d.ts +3 -5
- package/src/utils/createEcdsaKernelAccountClient.js +14 -14
- package/src/utils/hasSmartAccount.cjs +20 -0
- package/src/utils/hasSmartAccount.d.ts +2 -0
- package/src/utils/hasSmartAccount.js +16 -0
- package/src/utils/index.d.ts +1 -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,31 @@
|
|
|
1
1
|
|
|
2
|
+
## [4.18.0](https://github.com/dynamic-labs/dynamic-auth/compare/v4.17.0...v4.18.0) (2025-05-07)
|
|
3
|
+
|
|
4
|
+
|
|
5
|
+
### Features
|
|
6
|
+
|
|
7
|
+
* 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)
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
### Bug Fixes
|
|
11
|
+
|
|
12
|
+
* 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))
|
|
13
|
+
|
|
14
|
+
## [4.17.0](https://github.com/dynamic-labs/dynamic-auth/compare/v4.16.0...v4.17.0) (2025-05-06)
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
### Features
|
|
18
|
+
|
|
19
|
+
* add chain id option to create kernel client in react-native ([#8650](https://github.com/dynamic-labs/dynamic-auth/issues/8650)) ([1450bea](https://github.com/dynamic-labs/dynamic-auth/commit/1450bea6f979a82ed4880700aff14fa1ead9dc60))
|
|
20
|
+
* add sendCalls method to EthereumWallet ([#8634](https://github.com/dynamic-labs/dynamic-auth/issues/8634)) ([7c9aef9](https://github.com/dynamic-labs/dynamic-auth/commit/7c9aef95382b4823a40279bebfb084de32c25610))
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
### Bug Fixes
|
|
24
|
+
|
|
25
|
+
* 7702 do not override existing old aa ([#8630](https://github.com/dynamic-labs/dynamic-auth/issues/8630)) ([a731d9e](https://github.com/dynamic-labs/dynamic-auth/commit/a731d9e77ecd9e1dec3a7704a63989b5f2741a57))
|
|
26
|
+
* improve error message when email login fails ([#8649](https://github.com/dynamic-labs/dynamic-auth/issues/8649)) ([e1c03ac](https://github.com/dynamic-labs/dynamic-auth/commit/e1c03ac6dc83386c63d63db59d31355bc4fe2959))
|
|
27
|
+
* improve react-native stability on android ([#8652](https://github.com/dynamic-labs/dynamic-auth/issues/8652)) ([1617546](https://github.com/dynamic-labs/dynamic-auth/commit/1617546e6053c2ab32f7d385336c47df185d077f))
|
|
28
|
+
|
|
2
29
|
## [4.16.0](https://github.com/dynamic-labs/dynamic-auth/compare/v4.15.0...v4.16.0) (2025-05-03)
|
|
3
30
|
|
|
4
31
|
|
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.0",
|
|
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",
|
|
@@ -19,17 +19,17 @@
|
|
|
19
19
|
"homepage": "https://www.dynamic.xyz/",
|
|
20
20
|
"dependencies": {
|
|
21
21
|
"@dynamic-labs/sdk-api-core": "0.0.660",
|
|
22
|
-
"@zerodev/ecdsa-validator": "5.4.
|
|
23
|
-
"@zerodev/multi-chain-ecdsa-validator": "5.4.
|
|
24
|
-
"@zerodev/sdk": "5.4.
|
|
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.
|
|
22
|
+
"@zerodev/ecdsa-validator": "5.4.8",
|
|
23
|
+
"@zerodev/multi-chain-ecdsa-validator": "5.4.5",
|
|
24
|
+
"@zerodev/sdk": "5.4.34",
|
|
25
|
+
"@dynamic-labs/assert-package-version": "4.18.0",
|
|
26
|
+
"@dynamic-labs/ethereum-aa-core": "4.18.0",
|
|
27
|
+
"@dynamic-labs/ethereum-core": "4.18.0",
|
|
28
|
+
"@dynamic-labs/logger": "4.18.0",
|
|
29
|
+
"@dynamic-labs/types": "4.18.0",
|
|
30
|
+
"@dynamic-labs/utils": "4.18.0",
|
|
31
|
+
"@dynamic-labs/wallet-book": "4.18.0",
|
|
32
|
+
"@dynamic-labs/wallet-connector-core": "4.18.0"
|
|
33
33
|
},
|
|
34
34
|
"peerDependencies": {
|
|
35
35
|
"viem": "^2.21.60"
|
package/src/ZeroDevConnector.cjs
CHANGED
|
@@ -8,6 +8,7 @@ var viem = require('viem');
|
|
|
8
8
|
var accounts = require('viem/accounts');
|
|
9
9
|
var constants$1 = require('@zerodev/sdk/constants');
|
|
10
10
|
var ethereumCore = require('@dynamic-labs/ethereum-core');
|
|
11
|
+
var sdkApiCore = require('@dynamic-labs/sdk-api-core');
|
|
11
12
|
var walletConnectorCore = require('@dynamic-labs/wallet-connector-core');
|
|
12
13
|
var utils = require('@dynamic-labs/utils');
|
|
13
14
|
var ethereumAaCore = require('@dynamic-labs/ethereum-aa-core');
|
|
@@ -17,7 +18,7 @@ var createEcdsaKernelAccountClient = require('./utils/createEcdsaKernelAccountCl
|
|
|
17
18
|
var getEcdsaValidator = require('./utils/getEcdsaValidator.cjs');
|
|
18
19
|
var getEntryPoint = require('./utils/getEntryPoint.cjs');
|
|
19
20
|
var getKernelVersion = require('./utils/getKernelVersion.cjs');
|
|
20
|
-
var
|
|
21
|
+
var hasSmartAccount = require('./utils/hasSmartAccount.cjs');
|
|
21
22
|
|
|
22
23
|
class ZeroDevConnector extends ethereumAaCore.AccountAbstractionBaseConnector {
|
|
23
24
|
constructor(opts) {
|
|
@@ -32,6 +33,12 @@ class ZeroDevConnector extends ethereumAaCore.AccountAbstractionBaseConnector {
|
|
|
32
33
|
this.supportedChains = ['ETH', 'EVM'];
|
|
33
34
|
this.isEmbeddedWallet = true;
|
|
34
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 = {};
|
|
35
42
|
this.name = 'ZeroDev';
|
|
36
43
|
this.overrideKey = 'zerodev';
|
|
37
44
|
this.walletFallback = {
|
|
@@ -41,9 +48,15 @@ class ZeroDevConnector extends ethereumAaCore.AccountAbstractionBaseConnector {
|
|
|
41
48
|
},
|
|
42
49
|
name: 'ZeroDev',
|
|
43
50
|
};
|
|
51
|
+
this.hasExistingSmartAccount = false;
|
|
52
|
+
/**
|
|
53
|
+
* Flag for EIP-7702 mode, enabled when EIP-7702 is enabled and no smart account exists
|
|
54
|
+
*/
|
|
55
|
+
this.shouldUseEIP7702Mode = false;
|
|
44
56
|
this._walletUiUtils = opts.walletUiUtils;
|
|
45
57
|
this.providersConfig = (_a = opts.providersConfig) !== null && _a !== void 0 ? _a : {};
|
|
46
|
-
this.
|
|
58
|
+
this.is7702EnabledOnDashboard =
|
|
59
|
+
(_c = (_b = opts.apiProviders.zerodev) === null || _b === void 0 ? void 0 : _b.enableEIP7702) !== null && _c !== void 0 ? _c : false;
|
|
47
60
|
this.entryPoint = getEntryPoint.getEntryPoint((_d = opts.apiProviders.zerodev) === null || _d === void 0 ? void 0 : _d.entryPointVersion);
|
|
48
61
|
this.kernelVersion = getKernelVersion.getKernelVersion((_e = opts.apiProviders.zerodev) === null || _e === void 0 ? void 0 : _e.kernelVersion, this.entryPoint);
|
|
49
62
|
this.enableKernelV3Migration =
|
|
@@ -120,17 +133,22 @@ class ZeroDevConnector extends ethereumAaCore.AccountAbstractionBaseConnector {
|
|
|
120
133
|
});
|
|
121
134
|
}
|
|
122
135
|
initialize(_a) {
|
|
123
|
-
return _tslib.__awaiter(this, arguments, void 0, function* ({ smartWalletAddress, eoaAddress, eoaConnector, properties, shouldSetEoaConnector, }) {
|
|
136
|
+
return _tslib.__awaiter(this, arguments, void 0, function* ({ smartWalletAddress, eoaAddress, eoaConnector, properties, shouldSetEoaConnector, verifiedCredentials, }) {
|
|
124
137
|
yield this.registerEoa(Object.assign({ eoaAddress,
|
|
125
138
|
eoaConnector,
|
|
126
139
|
shouldSetEoaConnector,
|
|
127
|
-
smartWalletAddress
|
|
140
|
+
smartWalletAddress,
|
|
141
|
+
verifiedCredentials }, properties));
|
|
128
142
|
});
|
|
129
143
|
}
|
|
130
144
|
registerEoa(_a) {
|
|
131
145
|
return _tslib.__awaiter(this, void 0, void 0, function* () {
|
|
132
|
-
var { smartWalletAddress, eoaAddress, eoaConnector, shouldSetEoaConnector = false } = _a, properties = _tslib.__rest(_a, ["smartWalletAddress", "eoaAddress", "eoaConnector", "shouldSetEoaConnector"]);
|
|
133
|
-
if (
|
|
146
|
+
var { smartWalletAddress, eoaAddress, eoaConnector, verifiedCredentials, shouldSetEoaConnector = false } = _a, properties = _tslib.__rest(_a, ["smartWalletAddress", "eoaAddress", "eoaConnector", "verifiedCredentials", "shouldSetEoaConnector"]);
|
|
147
|
+
if (!eoaConnector) {
|
|
148
|
+
throw new utils.DynamicError('No EOA connector');
|
|
149
|
+
}
|
|
150
|
+
this.determineSmartAccountStatus(eoaConnector, verifiedCredentials);
|
|
151
|
+
if (this.shouldUseEIP7702Mode) {
|
|
134
152
|
// In EIP-7702, addresses must match
|
|
135
153
|
if (smartWalletAddress !== eoaAddress) {
|
|
136
154
|
throw new Error('In EIP-7702 mode, smart wallet and EOA addresses must be the same');
|
|
@@ -158,48 +176,13 @@ class ZeroDevConnector extends ethereumAaCore.AccountAbstractionBaseConnector {
|
|
|
158
176
|
}
|
|
159
177
|
});
|
|
160
178
|
}
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
}
|
|
169
|
-
const ZERODEV_AUTHORIZATION = 'zerodev_authorization';
|
|
170
|
-
try {
|
|
171
|
-
const storedAuthorization = utils.StorageService.getItem(ZERODEV_AUTHORIZATION);
|
|
172
|
-
if (storedAuthorization) {
|
|
173
|
-
return storedAuthorization;
|
|
174
|
-
}
|
|
175
|
-
const kernelVersion = constants$1.KERNEL_V3_3_BETA;
|
|
176
|
-
const authorization = yield this.eoaConnector.experimental_signAuthorization({
|
|
177
|
-
contractAddress: (_a = ZeroDevConnector.kernelDelegationAddress) !== null && _a !== void 0 ? _a : constants$1.KernelVersionToAddressesMap[kernelVersion]
|
|
178
|
-
.accountImplementationAddress,
|
|
179
|
-
});
|
|
180
|
-
if (authorization) {
|
|
181
|
-
const serializedAuth = Object.entries(authorization).reduce((acc, [key, value]) => {
|
|
182
|
-
acc[key] = typeof value === 'bigint' ? value.toString() : value;
|
|
183
|
-
return acc;
|
|
184
|
-
}, {});
|
|
185
|
-
utils.StorageService.setItem(ZERODEV_AUTHORIZATION, serializedAuth);
|
|
186
|
-
}
|
|
187
|
-
return {
|
|
188
|
-
address: authorization.contractAddress,
|
|
189
|
-
chainId: authorization.chainId,
|
|
190
|
-
nonce: authorization.nonce,
|
|
191
|
-
r: authorization.r,
|
|
192
|
-
s: authorization.s,
|
|
193
|
-
v: authorization.v,
|
|
194
|
-
yParity: authorization.yParity,
|
|
195
|
-
};
|
|
196
|
-
}
|
|
197
|
-
catch (error) {
|
|
198
|
-
logger.logger.error('Failed to get/set authorization:', error);
|
|
199
|
-
utils.StorageService.removeItem(ZERODEV_AUTHORIZATION);
|
|
200
|
-
return undefined;
|
|
201
|
-
}
|
|
202
|
-
});
|
|
179
|
+
determineSmartAccountStatus(eoaConnector, verifiedCredentials) {
|
|
180
|
+
if (walletConnectorCore.getWalletProvider(eoaConnector) !== sdkApiCore.WalletProviderEnum.EmbeddedWallet) {
|
|
181
|
+
return;
|
|
182
|
+
}
|
|
183
|
+
this.hasExistingSmartAccount = hasSmartAccount.hasSmartAccount(verifiedCredentials);
|
|
184
|
+
this.shouldUseEIP7702Mode =
|
|
185
|
+
this.is7702EnabledOnDashboard && !this.hasExistingSmartAccount;
|
|
203
186
|
}
|
|
204
187
|
setEoaConnector(_a) {
|
|
205
188
|
return _tslib.__awaiter(this, arguments, void 0, function* ({ eoaAddress, connector, properties, }) {
|
|
@@ -230,10 +213,6 @@ class ZeroDevConnector extends ethereumAaCore.AccountAbstractionBaseConnector {
|
|
|
230
213
|
yield this.eoaConnector.getConnectedAccounts();
|
|
231
214
|
}
|
|
232
215
|
const signer = yield this.eoaConnector.getSigner();
|
|
233
|
-
signer.account = accounts.toAccount(eoaAddress);
|
|
234
|
-
if (this.enableEIP7702Mode) {
|
|
235
|
-
this.authorization = yield this.getOrCreateAuthorization();
|
|
236
|
-
}
|
|
237
216
|
yield this.generateProviderMap(signer);
|
|
238
217
|
this.kernelClientDeferredPromise.resolve();
|
|
239
218
|
});
|
|
@@ -271,7 +250,6 @@ class ZeroDevConnector extends ethereumAaCore.AccountAbstractionBaseConnector {
|
|
|
271
250
|
signer,
|
|
272
251
|
}),
|
|
273
252
|
this.createKernelClient({
|
|
274
|
-
authorization: this.authorization,
|
|
275
253
|
chainId: chain,
|
|
276
254
|
paymaster: 'SPONSOR',
|
|
277
255
|
projectId: clientId,
|
|
@@ -295,7 +273,7 @@ class ZeroDevConnector extends ethereumAaCore.AccountAbstractionBaseConnector {
|
|
|
295
273
|
});
|
|
296
274
|
}
|
|
297
275
|
createKernelClient(_a) {
|
|
298
|
-
return _tslib.__awaiter(this, arguments, void 0, function* ({ chainId, projectId, signer, paymaster,
|
|
276
|
+
return _tslib.__awaiter(this, arguments, void 0, function* ({ chainId, projectId, signer, paymaster, }) {
|
|
299
277
|
var _b;
|
|
300
278
|
if (chainId && this.providerMap[chainId]) {
|
|
301
279
|
return paymaster === 'SPONSOR'
|
|
@@ -309,38 +287,24 @@ class ZeroDevConnector extends ethereumAaCore.AccountAbstractionBaseConnector {
|
|
|
309
287
|
const network = this.evmNetworks.find((network) => network.chainId === utils.parseChainId(chainId));
|
|
310
288
|
const publicClientRpc = (_b = network === null || network === void 0 ? void 0 : network.privateCustomerRpcUrls) === null || _b === void 0 ? void 0 : _b[0];
|
|
311
289
|
let kernelClient;
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
});
|
|
290
|
+
const params = {
|
|
291
|
+
bundlerRpc: ZeroDevConnector.bundlerRpc,
|
|
292
|
+
chain,
|
|
293
|
+
enableKernelV3Migration: this.enableKernelV3Migration,
|
|
294
|
+
entryPoint: this.entryPoint,
|
|
295
|
+
kernelVersion: this.kernelVersion,
|
|
296
|
+
paymaster,
|
|
297
|
+
paymasterRpc: ZeroDevConnector.paymasterRpc,
|
|
298
|
+
projectId,
|
|
299
|
+
provider: ZeroDevConnector.bundlerProvider,
|
|
300
|
+
publicClientRpc,
|
|
301
|
+
signer,
|
|
302
|
+
};
|
|
303
|
+
if (this.shouldUseEIP7702Mode) {
|
|
304
|
+
kernelClient = yield createEcdsaKernelAccountClient.createEcdsaKernelAccountClientWith7702(Object.assign(Object.assign({}, params), { kernelVersion: constants$1.KERNEL_V3_3 }));
|
|
328
305
|
}
|
|
329
306
|
else {
|
|
330
|
-
kernelClient = yield createEcdsaKernelAccountClient.createEcdsaKernelAccountClient({
|
|
331
|
-
bundlerRpc: ZeroDevConnector.bundlerRpc,
|
|
332
|
-
chain,
|
|
333
|
-
ecdsaValidator: getEcdsaValidator.getEcdsaValidator(this.ecdsaProviderType),
|
|
334
|
-
enableKernelV3Migration: this.enableKernelV3Migration,
|
|
335
|
-
entryPoint: this.entryPoint,
|
|
336
|
-
kernelVersion: this.kernelVersion,
|
|
337
|
-
paymaster,
|
|
338
|
-
paymasterRpc: ZeroDevConnector.paymasterRpc,
|
|
339
|
-
projectId,
|
|
340
|
-
provider: ZeroDevConnector.bundlerProvider,
|
|
341
|
-
publicClientRpc,
|
|
342
|
-
signer,
|
|
343
|
-
});
|
|
307
|
+
kernelClient = yield createEcdsaKernelAccountClient.createEcdsaKernelAccountClient(Object.assign(Object.assign({}, params), { ecdsaValidator: getEcdsaValidator.getEcdsaValidator(this.ecdsaProviderType) }));
|
|
344
308
|
}
|
|
345
309
|
utils.wrapMethodWithCallback(kernelClient, 'sendUserOperation', (original, ...args) => {
|
|
346
310
|
this._walletUiUtils.disabledConfirmationOnce();
|
|
@@ -352,7 +316,7 @@ class ZeroDevConnector extends ethereumAaCore.AccountAbstractionBaseConnector {
|
|
|
352
316
|
getAddress() {
|
|
353
317
|
return _tslib.__awaiter(this, void 0, void 0, function* () {
|
|
354
318
|
var _a, _b, _c;
|
|
355
|
-
if (this.
|
|
319
|
+
if (this.shouldUseEIP7702Mode) {
|
|
356
320
|
return this.eoaAddress;
|
|
357
321
|
}
|
|
358
322
|
yield ((_a = this.kernelClientDeferredPromise) === null || _a === void 0 ? void 0 : _a.promise);
|
|
@@ -393,7 +357,14 @@ class ZeroDevConnector extends ethereumAaCore.AccountAbstractionBaseConnector {
|
|
|
393
357
|
if (!effectiveProvider) {
|
|
394
358
|
throw new utils.DynamicError('No provider');
|
|
395
359
|
}
|
|
396
|
-
const
|
|
360
|
+
const unformattedTransaction = ethereumCore.unFormatTransaction(transaction);
|
|
361
|
+
const key = `${unformattedTransaction.from}-${unformattedTransaction.to}-${unformattedTransaction.data}`;
|
|
362
|
+
const cachedTransaction = this.userOperationCache[key];
|
|
363
|
+
if (cachedTransaction) {
|
|
364
|
+
const signedTransaction = yield effectiveProvider.signUserOperation(cachedTransaction.userOperation);
|
|
365
|
+
return effectiveProvider.sendUserOperation(signedTransaction);
|
|
366
|
+
}
|
|
367
|
+
const response = yield effectiveProvider.sendTransaction(unformattedTransaction);
|
|
397
368
|
return response;
|
|
398
369
|
}
|
|
399
370
|
catch (err) {
|
|
@@ -506,6 +477,10 @@ class ZeroDevConnector extends ethereumAaCore.AccountAbstractionBaseConnector {
|
|
|
506
477
|
getCurrentUserOperation(transaction) {
|
|
507
478
|
return _tslib.__awaiter(this, void 0, void 0, function* () {
|
|
508
479
|
var _a, _b;
|
|
480
|
+
const key = `${transaction.from}-${transaction.to}-${transaction.data}`;
|
|
481
|
+
if (this.userOperationCache[key]) {
|
|
482
|
+
return this.userOperationCache[key];
|
|
483
|
+
}
|
|
509
484
|
try {
|
|
510
485
|
const { kernelClientWithSponsorship } = this;
|
|
511
486
|
if (!kernelClientWithSponsorship) {
|
|
@@ -532,6 +507,11 @@ class ZeroDevConnector extends ethereumAaCore.AccountAbstractionBaseConnector {
|
|
|
532
507
|
callData,
|
|
533
508
|
}));
|
|
534
509
|
}
|
|
510
|
+
// Cache the result
|
|
511
|
+
this.userOperationCache[key] = {
|
|
512
|
+
sponsored: (sponsorResult === null || sponsorResult === void 0 ? void 0 : sponsorResult.paymasterAndData) !== '0x',
|
|
513
|
+
userOperation: sponsorResult !== null && sponsorResult !== void 0 ? sponsorResult : unsponsoredResult,
|
|
514
|
+
};
|
|
535
515
|
if ((sponsorResult === null || sponsorResult === void 0 ? void 0 : sponsorResult.paymasterAndData) === '0x')
|
|
536
516
|
return { sponsored: false, userOperation: sponsorResult };
|
|
537
517
|
return sponsorResult
|
|
@@ -573,7 +553,7 @@ class ZeroDevConnector extends ethereumAaCore.AccountAbstractionBaseConnector {
|
|
|
573
553
|
}
|
|
574
554
|
validateActiveWallet(expectedAddress) {
|
|
575
555
|
return _tslib.__awaiter(this, void 0, void 0, function* () {
|
|
576
|
-
if (this.
|
|
556
|
+
if (this.shouldUseEIP7702Mode) {
|
|
577
557
|
const currentAddress = yield this.getAddress();
|
|
578
558
|
if (currentAddress !== expectedAddress) {
|
|
579
559
|
throw new utils.DynamicError('Invalid active wallet');
|
|
@@ -594,6 +574,23 @@ class ZeroDevConnector extends ethereumAaCore.AccountAbstractionBaseConnector {
|
|
|
594
574
|
});
|
|
595
575
|
});
|
|
596
576
|
}
|
|
577
|
+
isAtomicSupported(chainId) {
|
|
578
|
+
return _tslib.__awaiter(this, void 0, void 0, function* () {
|
|
579
|
+
logger.logger.debug('[ZeroDevConnector] isAtomicSupported - is supported', {
|
|
580
|
+
chainId,
|
|
581
|
+
});
|
|
582
|
+
return true;
|
|
583
|
+
});
|
|
584
|
+
}
|
|
585
|
+
isPaymasterServiceSupported(chainId) {
|
|
586
|
+
return _tslib.__awaiter(this, void 0, void 0, function* () {
|
|
587
|
+
logger.logger.debug('[ZeroDevConnector] isPaymasterServiceSupported - not supported', {
|
|
588
|
+
chainId,
|
|
589
|
+
});
|
|
590
|
+
// TODO: update this to return true once we add support for paymaster url
|
|
591
|
+
return false;
|
|
592
|
+
});
|
|
593
|
+
}
|
|
597
594
|
}
|
|
598
595
|
|
|
599
596
|
exports.ZeroDevConnector = ZeroDevConnector;
|
|
@@ -1,11 +1,10 @@
|
|
|
1
1
|
import { KernelAccountClient } from '@zerodev/sdk/clients';
|
|
2
2
|
import { SmartAccount, EntryPointVersion } from 'viem/account-abstraction';
|
|
3
3
|
import { Account, Client, PublicClient, RpcSchema, Transport, WalletClient } from 'viem';
|
|
4
|
-
import { SignAuthorizationReturnType } from 'viem/accounts';
|
|
5
4
|
import { type Chain as ViemChain } from 'viem/chains';
|
|
6
5
|
import { EntryPointType, KERNEL_VERSION_TYPE } from '@zerodev/sdk/types';
|
|
7
6
|
import { EthereumWallet, RegisterEvmProvidersConfig } from '@dynamic-labs/ethereum-core';
|
|
8
|
-
import { EcdsaValidatorOptions, Provider, ProviderEntryPointVersionEnum, ProviderEnum, ProviderKernelVersionEnum, ProviderMultichainAccountAbstractionProviders, SmartWalletProperties } from '@dynamic-labs/sdk-api-core';
|
|
7
|
+
import { EcdsaValidatorOptions, Provider, ProviderEntryPointVersionEnum, ProviderEnum, ProviderKernelVersionEnum, ProviderMultichainAccountAbstractionProviders, SmartWalletProperties, JwtVerifiedCredential } from '@dynamic-labs/sdk-api-core';
|
|
9
8
|
import { Chain, InternalWalletConnector, IZeroDevConnector } from '@dynamic-labs/wallet-connector-core';
|
|
10
9
|
import { WalletBookSchema } from '@dynamic-labs/wallet-book';
|
|
11
10
|
import { GenericNetwork, TransactionReceipt, WalletUiUtils } from '@dynamic-labs/types';
|
|
@@ -20,7 +19,6 @@ type ZeroDevConnectorProps = AccountAbstractionConnectorProps & {
|
|
|
20
19
|
walletUiUtils: WalletUiUtils<InternalWalletConnector>;
|
|
21
20
|
bundlerProvider: BundlerProvider | undefined;
|
|
22
21
|
enableEIP7702?: boolean;
|
|
23
|
-
authorization?: SignAuthorizationReturnType;
|
|
24
22
|
providersConfig?: RegisterEvmProvidersConfig;
|
|
25
23
|
};
|
|
26
24
|
type KernelClient = KernelAccountClient<Transport, ViemChain, SmartAccount, Client, RpcSchema>;
|
|
@@ -51,6 +49,12 @@ export declare class ZeroDevConnector extends AccountAbstractionBaseConnector im
|
|
|
51
49
|
* This is needed because the provider is set asynchronously.
|
|
52
50
|
*/
|
|
53
51
|
private kernelClientDeferredPromise;
|
|
52
|
+
/**
|
|
53
|
+
* Cache for prepared user operations indexed by transaction details.
|
|
54
|
+
* The key is a concatenation of from-to-data to uniquely identify transactions.
|
|
55
|
+
* Used to avoid re-preparing the same user operation multiple times.
|
|
56
|
+
*/
|
|
57
|
+
private userOperationCache;
|
|
54
58
|
name: string;
|
|
55
59
|
overrideKey: string;
|
|
56
60
|
walletFallback: {
|
|
@@ -60,8 +64,12 @@ export declare class ZeroDevConnector extends AccountAbstractionBaseConnector im
|
|
|
60
64
|
};
|
|
61
65
|
name: string;
|
|
62
66
|
};
|
|
63
|
-
|
|
64
|
-
private
|
|
67
|
+
is7702EnabledOnDashboard: boolean;
|
|
68
|
+
private hasExistingSmartAccount;
|
|
69
|
+
/**
|
|
70
|
+
* Flag for EIP-7702 mode, enabled when EIP-7702 is enabled and no smart account exists
|
|
71
|
+
*/
|
|
72
|
+
private shouldUseEIP7702Mode;
|
|
65
73
|
constructor(opts: ZeroDevConnectorProps);
|
|
66
74
|
confirmTransactionStatus(): Promise<TransactionReceipt>;
|
|
67
75
|
get currentNetworkProvider(): {
|
|
@@ -79,23 +87,25 @@ export declare class ZeroDevConnector extends AccountAbstractionBaseConnector im
|
|
|
79
87
|
withSponsorship?: boolean;
|
|
80
88
|
}): T;
|
|
81
89
|
endSession(): Promise<void>;
|
|
82
|
-
initialize({ smartWalletAddress, eoaAddress, eoaConnector, properties, shouldSetEoaConnector, }: {
|
|
90
|
+
initialize({ smartWalletAddress, eoaAddress, eoaConnector, properties, shouldSetEoaConnector, verifiedCredentials, }: {
|
|
83
91
|
smartWalletAddress: string;
|
|
84
92
|
eoaAddress: string;
|
|
85
93
|
eoaConnector: InternalWalletConnector;
|
|
86
94
|
shouldSetEoaConnector: boolean;
|
|
87
95
|
properties?: SmartWalletProperties;
|
|
96
|
+
verifiedCredentials: JwtVerifiedCredential[];
|
|
88
97
|
}): Promise<void>;
|
|
89
|
-
registerEoa({ smartWalletAddress, eoaAddress, eoaConnector, shouldSetEoaConnector, ...properties }: {
|
|
98
|
+
registerEoa({ smartWalletAddress, eoaAddress, eoaConnector, verifiedCredentials, shouldSetEoaConnector, ...properties }: {
|
|
90
99
|
smartWalletAddress: string;
|
|
91
100
|
eoaAddress: string;
|
|
92
101
|
eoaConnector: InternalWalletConnector;
|
|
102
|
+
verifiedCredentials: JwtVerifiedCredential[];
|
|
93
103
|
shouldSetEoaConnector: boolean;
|
|
94
104
|
ecdsaProviderType?: EcdsaValidatorOptions;
|
|
95
105
|
kernelVersion?: ProviderKernelVersionEnum;
|
|
96
106
|
entryPointVersion?: ProviderEntryPointVersionEnum;
|
|
97
107
|
}): Promise<void>;
|
|
98
|
-
private
|
|
108
|
+
private determineSmartAccountStatus;
|
|
99
109
|
private setEoaConnector;
|
|
100
110
|
private warnIfProjectChainNotEnabled;
|
|
101
111
|
/**
|
|
@@ -159,5 +169,7 @@ export declare class ZeroDevConnector extends AccountAbstractionBaseConnector im
|
|
|
159
169
|
getBalance(address: string): Promise<string | undefined>;
|
|
160
170
|
signMessage(messageToSign: string): Promise<string | undefined>;
|
|
161
171
|
validateActiveWallet(expectedAddress: string): Promise<void>;
|
|
172
|
+
isAtomicSupported(chainId?: number): Promise<boolean>;
|
|
173
|
+
isPaymasterServiceSupported(chainId?: number): Promise<boolean>;
|
|
162
174
|
}
|
|
163
175
|
export {};
|
package/src/ZeroDevConnector.js
CHANGED
|
@@ -2,9 +2,10 @@
|
|
|
2
2
|
import { __awaiter, __rest } from '../_virtual/_tslib.js';
|
|
3
3
|
import { publicActions, custom, createWalletClient, toHex, formatEther } from 'viem';
|
|
4
4
|
import { toAccount } from 'viem/accounts';
|
|
5
|
-
import {
|
|
5
|
+
import { KERNEL_V3_3, getEntryPoint as getEntryPoint$1 } from '@zerodev/sdk/constants';
|
|
6
6
|
import { EthereumWallet, isEthWalletConnector, chainsMap, confirmationTransport, unFormatTransaction } from '@dynamic-labs/ethereum-core';
|
|
7
|
-
import {
|
|
7
|
+
import { WalletProviderEnum } from '@dynamic-labs/sdk-api-core';
|
|
8
|
+
import { eventListenerHandlers, getWalletProvider } from '@dynamic-labs/wallet-connector-core';
|
|
8
9
|
import { parseEvmNetworks, StorageService, DynamicError, DeferredPromise, parseChainId, wrapMethodWithCallback, TransactionGasCannotBeSponsoredError, InsufficientFundsError } from '@dynamic-labs/utils';
|
|
9
10
|
import { AccountAbstractionBaseConnector } from '@dynamic-labs/ethereum-aa-core';
|
|
10
11
|
import { ZERO_DEV_LAST_USED_CHAIN_ID_KEY } from './constants.js';
|
|
@@ -13,7 +14,7 @@ import { createEcdsaKernelAccountClientWith7702, createEcdsaKernelAccountClient
|
|
|
13
14
|
import { getEcdsaValidator } from './utils/getEcdsaValidator.js';
|
|
14
15
|
import { getEntryPoint } from './utils/getEntryPoint.js';
|
|
15
16
|
import { getKernelVersion } from './utils/getKernelVersion.js';
|
|
16
|
-
import {
|
|
17
|
+
import { hasSmartAccount } from './utils/hasSmartAccount.js';
|
|
17
18
|
|
|
18
19
|
class ZeroDevConnector extends AccountAbstractionBaseConnector {
|
|
19
20
|
constructor(opts) {
|
|
@@ -28,6 +29,12 @@ class ZeroDevConnector extends AccountAbstractionBaseConnector {
|
|
|
28
29
|
this.supportedChains = ['ETH', 'EVM'];
|
|
29
30
|
this.isEmbeddedWallet = true;
|
|
30
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 = {};
|
|
31
38
|
this.name = 'ZeroDev';
|
|
32
39
|
this.overrideKey = 'zerodev';
|
|
33
40
|
this.walletFallback = {
|
|
@@ -37,9 +44,15 @@ class ZeroDevConnector extends AccountAbstractionBaseConnector {
|
|
|
37
44
|
},
|
|
38
45
|
name: 'ZeroDev',
|
|
39
46
|
};
|
|
47
|
+
this.hasExistingSmartAccount = false;
|
|
48
|
+
/**
|
|
49
|
+
* Flag for EIP-7702 mode, enabled when EIP-7702 is enabled and no smart account exists
|
|
50
|
+
*/
|
|
51
|
+
this.shouldUseEIP7702Mode = false;
|
|
40
52
|
this._walletUiUtils = opts.walletUiUtils;
|
|
41
53
|
this.providersConfig = (_a = opts.providersConfig) !== null && _a !== void 0 ? _a : {};
|
|
42
|
-
this.
|
|
54
|
+
this.is7702EnabledOnDashboard =
|
|
55
|
+
(_c = (_b = opts.apiProviders.zerodev) === null || _b === void 0 ? void 0 : _b.enableEIP7702) !== null && _c !== void 0 ? _c : false;
|
|
43
56
|
this.entryPoint = getEntryPoint((_d = opts.apiProviders.zerodev) === null || _d === void 0 ? void 0 : _d.entryPointVersion);
|
|
44
57
|
this.kernelVersion = getKernelVersion((_e = opts.apiProviders.zerodev) === null || _e === void 0 ? void 0 : _e.kernelVersion, this.entryPoint);
|
|
45
58
|
this.enableKernelV3Migration =
|
|
@@ -116,17 +129,22 @@ class ZeroDevConnector extends AccountAbstractionBaseConnector {
|
|
|
116
129
|
});
|
|
117
130
|
}
|
|
118
131
|
initialize(_a) {
|
|
119
|
-
return __awaiter(this, arguments, void 0, function* ({ smartWalletAddress, eoaAddress, eoaConnector, properties, shouldSetEoaConnector, }) {
|
|
132
|
+
return __awaiter(this, arguments, void 0, function* ({ smartWalletAddress, eoaAddress, eoaConnector, properties, shouldSetEoaConnector, verifiedCredentials, }) {
|
|
120
133
|
yield this.registerEoa(Object.assign({ eoaAddress,
|
|
121
134
|
eoaConnector,
|
|
122
135
|
shouldSetEoaConnector,
|
|
123
|
-
smartWalletAddress
|
|
136
|
+
smartWalletAddress,
|
|
137
|
+
verifiedCredentials }, properties));
|
|
124
138
|
});
|
|
125
139
|
}
|
|
126
140
|
registerEoa(_a) {
|
|
127
141
|
return __awaiter(this, void 0, void 0, function* () {
|
|
128
|
-
var { smartWalletAddress, eoaAddress, eoaConnector, shouldSetEoaConnector = false } = _a, properties = __rest(_a, ["smartWalletAddress", "eoaAddress", "eoaConnector", "shouldSetEoaConnector"]);
|
|
129
|
-
if (
|
|
142
|
+
var { smartWalletAddress, eoaAddress, eoaConnector, verifiedCredentials, shouldSetEoaConnector = false } = _a, properties = __rest(_a, ["smartWalletAddress", "eoaAddress", "eoaConnector", "verifiedCredentials", "shouldSetEoaConnector"]);
|
|
143
|
+
if (!eoaConnector) {
|
|
144
|
+
throw new DynamicError('No EOA connector');
|
|
145
|
+
}
|
|
146
|
+
this.determineSmartAccountStatus(eoaConnector, verifiedCredentials);
|
|
147
|
+
if (this.shouldUseEIP7702Mode) {
|
|
130
148
|
// In EIP-7702, addresses must match
|
|
131
149
|
if (smartWalletAddress !== eoaAddress) {
|
|
132
150
|
throw new Error('In EIP-7702 mode, smart wallet and EOA addresses must be the same');
|
|
@@ -154,48 +172,13 @@ class ZeroDevConnector extends AccountAbstractionBaseConnector {
|
|
|
154
172
|
}
|
|
155
173
|
});
|
|
156
174
|
}
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
}
|
|
165
|
-
const ZERODEV_AUTHORIZATION = 'zerodev_authorization';
|
|
166
|
-
try {
|
|
167
|
-
const storedAuthorization = StorageService.getItem(ZERODEV_AUTHORIZATION);
|
|
168
|
-
if (storedAuthorization) {
|
|
169
|
-
return storedAuthorization;
|
|
170
|
-
}
|
|
171
|
-
const kernelVersion = KERNEL_V3_3_BETA;
|
|
172
|
-
const authorization = yield this.eoaConnector.experimental_signAuthorization({
|
|
173
|
-
contractAddress: (_a = ZeroDevConnector.kernelDelegationAddress) !== null && _a !== void 0 ? _a : KernelVersionToAddressesMap[kernelVersion]
|
|
174
|
-
.accountImplementationAddress,
|
|
175
|
-
});
|
|
176
|
-
if (authorization) {
|
|
177
|
-
const serializedAuth = Object.entries(authorization).reduce((acc, [key, value]) => {
|
|
178
|
-
acc[key] = typeof value === 'bigint' ? value.toString() : value;
|
|
179
|
-
return acc;
|
|
180
|
-
}, {});
|
|
181
|
-
StorageService.setItem(ZERODEV_AUTHORIZATION, serializedAuth);
|
|
182
|
-
}
|
|
183
|
-
return {
|
|
184
|
-
address: authorization.contractAddress,
|
|
185
|
-
chainId: authorization.chainId,
|
|
186
|
-
nonce: authorization.nonce,
|
|
187
|
-
r: authorization.r,
|
|
188
|
-
s: authorization.s,
|
|
189
|
-
v: authorization.v,
|
|
190
|
-
yParity: authorization.yParity,
|
|
191
|
-
};
|
|
192
|
-
}
|
|
193
|
-
catch (error) {
|
|
194
|
-
logger.error('Failed to get/set authorization:', error);
|
|
195
|
-
StorageService.removeItem(ZERODEV_AUTHORIZATION);
|
|
196
|
-
return undefined;
|
|
197
|
-
}
|
|
198
|
-
});
|
|
175
|
+
determineSmartAccountStatus(eoaConnector, verifiedCredentials) {
|
|
176
|
+
if (getWalletProvider(eoaConnector) !== WalletProviderEnum.EmbeddedWallet) {
|
|
177
|
+
return;
|
|
178
|
+
}
|
|
179
|
+
this.hasExistingSmartAccount = hasSmartAccount(verifiedCredentials);
|
|
180
|
+
this.shouldUseEIP7702Mode =
|
|
181
|
+
this.is7702EnabledOnDashboard && !this.hasExistingSmartAccount;
|
|
199
182
|
}
|
|
200
183
|
setEoaConnector(_a) {
|
|
201
184
|
return __awaiter(this, arguments, void 0, function* ({ eoaAddress, connector, properties, }) {
|
|
@@ -226,10 +209,6 @@ class ZeroDevConnector extends AccountAbstractionBaseConnector {
|
|
|
226
209
|
yield this.eoaConnector.getConnectedAccounts();
|
|
227
210
|
}
|
|
228
211
|
const signer = yield this.eoaConnector.getSigner();
|
|
229
|
-
signer.account = toAccount(eoaAddress);
|
|
230
|
-
if (this.enableEIP7702Mode) {
|
|
231
|
-
this.authorization = yield this.getOrCreateAuthorization();
|
|
232
|
-
}
|
|
233
212
|
yield this.generateProviderMap(signer);
|
|
234
213
|
this.kernelClientDeferredPromise.resolve();
|
|
235
214
|
});
|
|
@@ -267,7 +246,6 @@ class ZeroDevConnector extends AccountAbstractionBaseConnector {
|
|
|
267
246
|
signer,
|
|
268
247
|
}),
|
|
269
248
|
this.createKernelClient({
|
|
270
|
-
authorization: this.authorization,
|
|
271
249
|
chainId: chain,
|
|
272
250
|
paymaster: 'SPONSOR',
|
|
273
251
|
projectId: clientId,
|
|
@@ -291,7 +269,7 @@ class ZeroDevConnector extends AccountAbstractionBaseConnector {
|
|
|
291
269
|
});
|
|
292
270
|
}
|
|
293
271
|
createKernelClient(_a) {
|
|
294
|
-
return __awaiter(this, arguments, void 0, function* ({ chainId, projectId, signer, paymaster,
|
|
272
|
+
return __awaiter(this, arguments, void 0, function* ({ chainId, projectId, signer, paymaster, }) {
|
|
295
273
|
var _b;
|
|
296
274
|
if (chainId && this.providerMap[chainId]) {
|
|
297
275
|
return paymaster === 'SPONSOR'
|
|
@@ -305,38 +283,24 @@ class ZeroDevConnector extends AccountAbstractionBaseConnector {
|
|
|
305
283
|
const network = this.evmNetworks.find((network) => network.chainId === parseChainId(chainId));
|
|
306
284
|
const publicClientRpc = (_b = network === null || network === void 0 ? void 0 : network.privateCustomerRpcUrls) === null || _b === void 0 ? void 0 : _b[0];
|
|
307
285
|
let kernelClient;
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
});
|
|
286
|
+
const params = {
|
|
287
|
+
bundlerRpc: ZeroDevConnector.bundlerRpc,
|
|
288
|
+
chain,
|
|
289
|
+
enableKernelV3Migration: this.enableKernelV3Migration,
|
|
290
|
+
entryPoint: this.entryPoint,
|
|
291
|
+
kernelVersion: this.kernelVersion,
|
|
292
|
+
paymaster,
|
|
293
|
+
paymasterRpc: ZeroDevConnector.paymasterRpc,
|
|
294
|
+
projectId,
|
|
295
|
+
provider: ZeroDevConnector.bundlerProvider,
|
|
296
|
+
publicClientRpc,
|
|
297
|
+
signer,
|
|
298
|
+
};
|
|
299
|
+
if (this.shouldUseEIP7702Mode) {
|
|
300
|
+
kernelClient = yield createEcdsaKernelAccountClientWith7702(Object.assign(Object.assign({}, params), { kernelVersion: KERNEL_V3_3 }));
|
|
324
301
|
}
|
|
325
302
|
else {
|
|
326
|
-
kernelClient = yield createEcdsaKernelAccountClient({
|
|
327
|
-
bundlerRpc: ZeroDevConnector.bundlerRpc,
|
|
328
|
-
chain,
|
|
329
|
-
ecdsaValidator: getEcdsaValidator(this.ecdsaProviderType),
|
|
330
|
-
enableKernelV3Migration: this.enableKernelV3Migration,
|
|
331
|
-
entryPoint: this.entryPoint,
|
|
332
|
-
kernelVersion: this.kernelVersion,
|
|
333
|
-
paymaster,
|
|
334
|
-
paymasterRpc: ZeroDevConnector.paymasterRpc,
|
|
335
|
-
projectId,
|
|
336
|
-
provider: ZeroDevConnector.bundlerProvider,
|
|
337
|
-
publicClientRpc,
|
|
338
|
-
signer,
|
|
339
|
-
});
|
|
303
|
+
kernelClient = yield createEcdsaKernelAccountClient(Object.assign(Object.assign({}, params), { ecdsaValidator: getEcdsaValidator(this.ecdsaProviderType) }));
|
|
340
304
|
}
|
|
341
305
|
wrapMethodWithCallback(kernelClient, 'sendUserOperation', (original, ...args) => {
|
|
342
306
|
this._walletUiUtils.disabledConfirmationOnce();
|
|
@@ -348,7 +312,7 @@ class ZeroDevConnector extends AccountAbstractionBaseConnector {
|
|
|
348
312
|
getAddress() {
|
|
349
313
|
return __awaiter(this, void 0, void 0, function* () {
|
|
350
314
|
var _a, _b, _c;
|
|
351
|
-
if (this.
|
|
315
|
+
if (this.shouldUseEIP7702Mode) {
|
|
352
316
|
return this.eoaAddress;
|
|
353
317
|
}
|
|
354
318
|
yield ((_a = this.kernelClientDeferredPromise) === null || _a === void 0 ? void 0 : _a.promise);
|
|
@@ -389,7 +353,14 @@ class ZeroDevConnector extends AccountAbstractionBaseConnector {
|
|
|
389
353
|
if (!effectiveProvider) {
|
|
390
354
|
throw new DynamicError('No provider');
|
|
391
355
|
}
|
|
392
|
-
const
|
|
356
|
+
const unformattedTransaction = unFormatTransaction(transaction);
|
|
357
|
+
const key = `${unformattedTransaction.from}-${unformattedTransaction.to}-${unformattedTransaction.data}`;
|
|
358
|
+
const cachedTransaction = this.userOperationCache[key];
|
|
359
|
+
if (cachedTransaction) {
|
|
360
|
+
const signedTransaction = yield effectiveProvider.signUserOperation(cachedTransaction.userOperation);
|
|
361
|
+
return effectiveProvider.sendUserOperation(signedTransaction);
|
|
362
|
+
}
|
|
363
|
+
const response = yield effectiveProvider.sendTransaction(unformattedTransaction);
|
|
393
364
|
return response;
|
|
394
365
|
}
|
|
395
366
|
catch (err) {
|
|
@@ -502,6 +473,10 @@ class ZeroDevConnector extends AccountAbstractionBaseConnector {
|
|
|
502
473
|
getCurrentUserOperation(transaction) {
|
|
503
474
|
return __awaiter(this, void 0, void 0, function* () {
|
|
504
475
|
var _a, _b;
|
|
476
|
+
const key = `${transaction.from}-${transaction.to}-${transaction.data}`;
|
|
477
|
+
if (this.userOperationCache[key]) {
|
|
478
|
+
return this.userOperationCache[key];
|
|
479
|
+
}
|
|
505
480
|
try {
|
|
506
481
|
const { kernelClientWithSponsorship } = this;
|
|
507
482
|
if (!kernelClientWithSponsorship) {
|
|
@@ -528,6 +503,11 @@ class ZeroDevConnector extends AccountAbstractionBaseConnector {
|
|
|
528
503
|
callData,
|
|
529
504
|
}));
|
|
530
505
|
}
|
|
506
|
+
// Cache the result
|
|
507
|
+
this.userOperationCache[key] = {
|
|
508
|
+
sponsored: (sponsorResult === null || sponsorResult === void 0 ? void 0 : sponsorResult.paymasterAndData) !== '0x',
|
|
509
|
+
userOperation: sponsorResult !== null && sponsorResult !== void 0 ? sponsorResult : unsponsoredResult,
|
|
510
|
+
};
|
|
531
511
|
if ((sponsorResult === null || sponsorResult === void 0 ? void 0 : sponsorResult.paymasterAndData) === '0x')
|
|
532
512
|
return { sponsored: false, userOperation: sponsorResult };
|
|
533
513
|
return sponsorResult
|
|
@@ -569,7 +549,7 @@ class ZeroDevConnector extends AccountAbstractionBaseConnector {
|
|
|
569
549
|
}
|
|
570
550
|
validateActiveWallet(expectedAddress) {
|
|
571
551
|
return __awaiter(this, void 0, void 0, function* () {
|
|
572
|
-
if (this.
|
|
552
|
+
if (this.shouldUseEIP7702Mode) {
|
|
573
553
|
const currentAddress = yield this.getAddress();
|
|
574
554
|
if (currentAddress !== expectedAddress) {
|
|
575
555
|
throw new DynamicError('Invalid active wallet');
|
|
@@ -590,6 +570,23 @@ class ZeroDevConnector extends AccountAbstractionBaseConnector {
|
|
|
590
570
|
});
|
|
591
571
|
});
|
|
592
572
|
}
|
|
573
|
+
isAtomicSupported(chainId) {
|
|
574
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
575
|
+
logger.debug('[ZeroDevConnector] isAtomicSupported - is supported', {
|
|
576
|
+
chainId,
|
|
577
|
+
});
|
|
578
|
+
return true;
|
|
579
|
+
});
|
|
580
|
+
}
|
|
581
|
+
isPaymasterServiceSupported(chainId) {
|
|
582
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
583
|
+
logger.debug('[ZeroDevConnector] isPaymasterServiceSupported - not supported', {
|
|
584
|
+
chainId,
|
|
585
|
+
});
|
|
586
|
+
// TODO: update this to return true once we add support for paymaster url
|
|
587
|
+
return false;
|
|
588
|
+
});
|
|
589
|
+
}
|
|
593
590
|
}
|
|
594
591
|
|
|
595
592
|
export { ZeroDevConnector };
|
|
@@ -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,7 +3,6 @@ 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 { SignAuthorizationReturnType } from 'viem/experimental';
|
|
7
6
|
export type BundlerProvider = 'STACKUP' | 'PIMLICO' | 'ALCHEMY' | 'GELATO';
|
|
8
7
|
export type ERC20Paymaster = Address;
|
|
9
8
|
export type PaymasterType = 'NONE' | 'SPONSOR' | ERC20Paymaster;
|
|
@@ -19,12 +18,11 @@ type CommonClientParams<TChain extends Chain | undefined = Chain | undefined> =
|
|
|
19
18
|
entryPoint: EntryPointType<EntryPointVersion>;
|
|
20
19
|
provider?: BundlerProvider;
|
|
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 };
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
'use client'
|
|
2
|
+
'use strict';
|
|
3
|
+
|
|
4
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
|
5
|
+
|
|
6
|
+
const hasSmartAccount = (verifiedCredentials) => {
|
|
7
|
+
const embeddedWallet = verifiedCredentials.find((vc) => vc.walletProvider === 'embeddedWallet' &&
|
|
8
|
+
(vc.walletName === 'dynamicwaas' ||
|
|
9
|
+
vc.walletName === 'turnkey' ||
|
|
10
|
+
vc.walletName === 'turnkeyhd'));
|
|
11
|
+
if (!embeddedWallet)
|
|
12
|
+
return false;
|
|
13
|
+
const hasSmartContractWallet = verifiedCredentials.find((vc) => vc.walletProvider === 'smartContractWallet' &&
|
|
14
|
+
vc.signerRefId === embeddedWallet.id);
|
|
15
|
+
if (!hasSmartContractWallet)
|
|
16
|
+
return false;
|
|
17
|
+
return !hasSmartContractWallet.id.includes('zerodev');
|
|
18
|
+
};
|
|
19
|
+
|
|
20
|
+
exports.hasSmartAccount = hasSmartAccount;
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
'use client'
|
|
2
|
+
const hasSmartAccount = (verifiedCredentials) => {
|
|
3
|
+
const embeddedWallet = verifiedCredentials.find((vc) => vc.walletProvider === 'embeddedWallet' &&
|
|
4
|
+
(vc.walletName === 'dynamicwaas' ||
|
|
5
|
+
vc.walletName === 'turnkey' ||
|
|
6
|
+
vc.walletName === 'turnkeyhd'));
|
|
7
|
+
if (!embeddedWallet)
|
|
8
|
+
return false;
|
|
9
|
+
const hasSmartContractWallet = verifiedCredentials.find((vc) => vc.walletProvider === 'smartContractWallet' &&
|
|
10
|
+
vc.signerRefId === embeddedWallet.id);
|
|
11
|
+
if (!hasSmartContractWallet)
|
|
12
|
+
return false;
|
|
13
|
+
return !hasSmartContractWallet.id.includes('zerodev');
|
|
14
|
+
};
|
|
15
|
+
|
|
16
|
+
export { hasSmartAccount };
|
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 {};
|