@dynamic-labs/ethereum-aa 4.0.0-alpha.7 → 4.0.0-alpha.9

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 CHANGED
@@ -1,4 +1,31 @@
1
1
 
2
+ ## [4.0.0-alpha.9](https://github.com/dynamic-labs/dynamic-auth/compare/v4.0.0-alpha.8...v4.0.0-alpha.9) (2024-10-11)
3
+
4
+
5
+ ### Features
6
+
7
+ * add support for fordefi wallet ([#7109](https://github.com/dynamic-labs/dynamic-auth/issues/7109)) ([1adb6b1](https://github.com/dynamic-labs/dynamic-auth/commit/1adb6b15b7f8e9156207ac7addf4368d27c1e371))
8
+ * support ability to define additional oauth scopes ([#7105](https://github.com/dynamic-labs/dynamic-auth/issues/7105)) ([b303203](https://github.com/dynamic-labs/dynamic-auth/commit/b303203e8041c0cbf5f8968df0d3cde04ed1b22a))
9
+
10
+
11
+ ### Bug Fixes
12
+
13
+ * add eip6963 for exodus evm ([#7094](https://github.com/dynamic-labs/dynamic-auth/issues/7094)) ([c1ec5ef](https://github.com/dynamic-labs/dynamic-auth/commit/c1ec5ef4b6a531c563be4b690aa5f2bd4e7e6a16))
14
+
15
+ ## [4.0.0-alpha.8](https://github.com/dynamic-labs/dynamic-auth/compare/v4.0.0-alpha.7...v4.0.0-alpha.8) (2024-10-07)
16
+
17
+
18
+ ### Features
19
+
20
+ * add support for dynamic event callbacks in rn ([#6997](https://github.com/dynamic-labs/dynamic-auth/issues/6997)) ([f9ac402](https://github.com/dynamic-labs/dynamic-auth/commit/f9ac40259d9168dfe69dafd5fd44478ba0e69505))
21
+ * add support for dynamic handlers in rn ([#7032](https://github.com/dynamic-labs/dynamic-auth/issues/7032)) ([f61f926](https://github.com/dynamic-labs/dynamic-auth/commit/f61f92666b6df8483dde2c47304fd4fb02690f7d))
22
+ * Support for multi-chain AA ([#6829](https://github.com/dynamic-labs/dynamic-auth/issues/6829)) ([b4a0c0a](https://github.com/dynamic-labs/dynamic-auth/commit/b4a0c0a4de48231a3748826600407c25abf6894d))
23
+
24
+
25
+ ### Bug Fixes
26
+
27
+ * persist isHardwareWalletEnabled on wallet connector ([#7025](https://github.com/dynamic-labs/dynamic-auth/issues/7025)) ([#7034](https://github.com/dynamic-labs/dynamic-auth/issues/7034)) ([4bfc301](https://github.com/dynamic-labs/dynamic-auth/commit/4bfc301d891f10db8c0bd31e5164c489a882c5c3))
28
+
2
29
  ## [4.0.0-alpha.7](https://github.com/dynamic-labs/dynamic-auth/compare/v4.0.0-alpha.6...v4.0.0-alpha.7) (2024-10-03)
3
30
 
4
31
 
package/package.cjs CHANGED
@@ -3,6 +3,6 @@
3
3
 
4
4
  Object.defineProperty(exports, '__esModule', { value: true });
5
5
 
6
- var version = "4.0.0-alpha.7";
6
+ var version = "4.0.0-alpha.9";
7
7
 
8
8
  exports.version = version;
package/package.js CHANGED
@@ -1,4 +1,4 @@
1
1
  'use client'
2
- var version = "4.0.0-alpha.7";
2
+ var version = "4.0.0-alpha.9";
3
3
 
4
4
  export { version };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dynamic-labs/ethereum-aa",
3
- "version": "4.0.0-alpha.7",
3
+ "version": "4.0.0-alpha.9",
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.535",
21
+ "@dynamic-labs/sdk-api-core": "0.0.545",
22
22
  "@zerodev/ecdsa-validator": "5.3.1",
23
23
  "@zerodev/multi-chain-validator": "5.3.3",
24
24
  "@zerodev/sdk": "5.3.4",
25
25
  "permissionless": "^0.1.20",
26
- "@dynamic-labs/assert-package-version": "4.0.0-alpha.7",
27
- "@dynamic-labs/ethereum-core": "4.0.0-alpha.7",
28
- "@dynamic-labs/logger": "4.0.0-alpha.7",
29
- "@dynamic-labs/types": "4.0.0-alpha.7",
30
- "@dynamic-labs/utils": "4.0.0-alpha.7",
31
- "@dynamic-labs/wallet-book": "4.0.0-alpha.7",
32
- "@dynamic-labs/wallet-connector-core": "4.0.0-alpha.7"
26
+ "@dynamic-labs/assert-package-version": "4.0.0-alpha.9",
27
+ "@dynamic-labs/ethereum-core": "4.0.0-alpha.9",
28
+ "@dynamic-labs/logger": "4.0.0-alpha.9",
29
+ "@dynamic-labs/types": "4.0.0-alpha.9",
30
+ "@dynamic-labs/utils": "4.0.0-alpha.9",
31
+ "@dynamic-labs/wallet-book": "4.0.0-alpha.9",
32
+ "@dynamic-labs/wallet-connector-core": "4.0.0-alpha.9"
33
33
  },
34
34
  "peerDependencies": {
35
35
  "viem": "^2.7.6"
@@ -6,10 +6,10 @@ Object.defineProperty(exports, '__esModule', { value: true });
6
6
  var _tslib = require('../_virtual/_tslib.cjs');
7
7
  var viem = require('viem');
8
8
  var utils$1 = require('permissionless/utils');
9
- var walletConnectorCore = require('@dynamic-labs/wallet-connector-core');
10
9
  var ethereumCore = require('@dynamic-labs/ethereum-core');
10
+ var walletConnectorCore = require('@dynamic-labs/wallet-connector-core');
11
11
  var utils = require('@dynamic-labs/utils');
12
- var fetchZeroDevChain = require('./utils/fetchZeroDevChain.cjs');
12
+ var constants = require('./constants.cjs');
13
13
  var logger = require('./utils/logger.cjs');
14
14
  var createEcsdaKernelAccountClient = require('./utils/createEcsdaKernelAccountClient.cjs');
15
15
  var getEcdsaValidator = require('./utils/getEcdsaValidator.cjs');
@@ -20,11 +20,13 @@ class ZeroDevConnector extends walletConnectorCore.WalletConnectorBase {
20
20
  constructor(opts) {
21
21
  var _a, _b, _c, _d;
22
22
  super(opts);
23
+ this.providerMap = {};
23
24
  this.ChainWallet = ethereumCore.EthereumWallet;
24
25
  this.connectedChain = 'EVM';
25
26
  this.supportedChains = ['ETH', 'EVM'];
26
27
  this.isGasSponsorshipDisabled = false;
27
28
  this.isEmbeddedWallet = true;
29
+ this.providersFromApi = [];
28
30
  this.name = 'ZeroDev';
29
31
  this.overrideKey = 'zerodev';
30
32
  this.walletFallback = {
@@ -34,17 +36,65 @@ class ZeroDevConnector extends walletConnectorCore.WalletConnectorBase {
34
36
  },
35
37
  name: 'ZeroDev',
36
38
  };
37
- const zeroDevProjectId = (_a = opts.apiProviders.zerodev) === null || _a === void 0 ? void 0 : _a.clientId;
38
- if (!zeroDevProjectId) {
39
- throw new Error('Missing ZeroDev project ID provided. Add your ZeroDev project id to your project configuration via the Dynamic Labs dashboard.');
40
- }
41
- this.projectId = zeroDevProjectId;
42
39
  this._walletUiUtils = opts.walletUiUtils;
43
40
  this.evmNetworks = utils.parseEvmNetworks(opts.evmNetworks);
44
- this.entryPoint = getEntryPoint.getEntryPoint((_b = opts.apiProviders.zerodev) === null || _b === void 0 ? void 0 : _b.entryPointVersion);
45
- this.kernelVersion = getKernelVersion.getKernelVersion((_c = opts.apiProviders.zerodev) === null || _c === void 0 ? void 0 : _c.kernelVersion, this.entryPoint);
41
+ this.entryPoint = getEntryPoint.getEntryPoint((_a = opts.apiProviders.zerodev) === null || _a === void 0 ? void 0 : _a.entryPointVersion);
42
+ this.kernelVersion = getKernelVersion.getKernelVersion((_b = opts.apiProviders.zerodev) === null || _b === void 0 ? void 0 : _b.kernelVersion, this.entryPoint);
43
+ // this is the list of providers from the api that are used for multi-chain account abstraction
44
+ this.providersFromApi =
45
+ ((_c = opts.apiProviders.zerodev) === null || _c === void 0 ? void 0 : _c.multichainAccountAbstractionProviders) || [];
46
+ const [defaultProvider] = this.providersFromApi;
47
+ this.clientId = defaultProvider === null || defaultProvider === void 0 ? void 0 : defaultProvider.clientId;
48
+ if (!this.clientId) {
49
+ throw new Error('Missing ZeroDev project ID provided. Add your ZeroDev project id to your project configuration via the Dynamic Labs dashboard.');
50
+ }
51
+ this.defaultChainId = defaultProvider === null || defaultProvider === void 0 ? void 0 : defaultProvider.chain;
46
52
  this.ecdsaProviderType = (_d = opts.apiProviders.zerodev) === null || _d === void 0 ? void 0 : _d.ecdsaProviderType;
47
53
  }
54
+ get currentNetworkProvider() {
55
+ // check if the last used chain id is in the provider map
56
+ if (this.providerMap[this.lastUsedChainId]) {
57
+ return this.providerMap[this.lastUsedChainId];
58
+ }
59
+ // if not, check if the default chain id is in the provider map
60
+ if (this.defaultChainId) {
61
+ return this.providerMap[this.defaultChainId];
62
+ }
63
+ // if no chain id is found, return undefined
64
+ return undefined;
65
+ }
66
+ get lastUsedChainId() {
67
+ var _a;
68
+ const storedChainId = utils.StorageService.getItem(constants.ZERO_DEV_LAST_USED_CHAIN_ID_KEY);
69
+ // returning string of unknown if no chain id is found to result in undefined provider lookup
70
+ return (_a = storedChainId !== null && storedChainId !== void 0 ? storedChainId : this.defaultChainId) !== null && _a !== void 0 ? _a : 'unknown';
71
+ }
72
+ get kernelClient() {
73
+ var _a;
74
+ return (_a = this.currentNetworkProvider) === null || _a === void 0 ? void 0 : _a.kernelClient;
75
+ }
76
+ get kernelClientWithSponsorship() {
77
+ var _a;
78
+ return (_a = this.currentNetworkProvider) === null || _a === void 0 ? void 0 : _a.kernelClientWithSponsorship;
79
+ }
80
+ supportsNetworkSwitching() {
81
+ return (Object.keys(this.providerMap).length > 1 && this.evmNetworks.length > 1);
82
+ }
83
+ switchNetwork(_a) {
84
+ return _tslib.__awaiter(this, arguments, void 0, function* ({ networkChainId, }) {
85
+ if (!this.supportsNetworkSwitching())
86
+ return;
87
+ if (!networkChainId)
88
+ return;
89
+ const chainId = networkChainId.toString();
90
+ if (!this.providerMap[chainId]) {
91
+ throw new Error(`No provider found for chainId: ${chainId}`);
92
+ }
93
+ utils.StorageService.setItem(constants.ZERO_DEV_LAST_USED_CHAIN_ID_KEY, chainId);
94
+ const { handleChainChange } = walletConnectorCore.eventListenerHandlers(this);
95
+ handleChainChange(chainId);
96
+ });
97
+ }
48
98
  /**
49
99
  * @deprecated You should get the EOA connector by passing the SCW to getEOAConnector,
50
100
  * from the useSmartWallet hook
@@ -60,7 +110,7 @@ class ZeroDevConnector extends walletConnectorCore.WalletConnectorBase {
60
110
  }
61
111
  endSession() {
62
112
  return _tslib.__awaiter(this, void 0, void 0, function* () {
63
- localStorage.removeItem(fetchZeroDevChain.cachedChainIdKey);
113
+ utils.StorageService.removeItem(constants.ZERO_DEV_LAST_USED_CHAIN_ID_KEY);
64
114
  });
65
115
  }
66
116
  setEoaConnector(connector) {
@@ -80,15 +130,63 @@ class ZeroDevConnector extends walletConnectorCore.WalletConnectorBase {
80
130
  logger.logger.error('No signer account found');
81
131
  return;
82
132
  }
133
+ yield this.generateProviderMap(signer);
134
+ this.evmNetworks = this.evmNetworks.filter((network) => Boolean(this.providerMap[network.chainId]));
135
+ this.kernelClientDeferredPromise.resolve();
136
+ });
137
+ }
138
+ warnIfProjectChainNotEnabled(chainId) {
139
+ return _tslib.__awaiter(this, void 0, void 0, function* () {
140
+ var _a;
141
+ let chainIdToCheck = chainId;
142
+ if (!chainIdToCheck) {
143
+ const client = yield this.getPublicClient();
144
+ chainIdToCheck = (_a = client === null || client === void 0 ? void 0 : client.chain) === null || _a === void 0 ? void 0 : _a.id;
145
+ }
146
+ const isProjectChainEnabled = this.evmNetworks.some((network) => network.chainId === chainIdToCheck);
147
+ if (!isProjectChainEnabled) {
148
+ logger.logger.error(`Please make sure to enable (${chainIdToCheck}) in the Dynamic dashboard (https://app.dynamic.xyz/dashboard/configurations#evm).`);
149
+ }
150
+ });
151
+ }
152
+ generateProviderMap(signer) {
153
+ return _tslib.__awaiter(this, void 0, void 0, function* () {
154
+ for (const provider of this.providersFromApi) {
155
+ if (!this.providerMap[provider.chain]) {
156
+ this.providerMap[provider.chain] = {
157
+ kernelClient: yield this.getKernelClientWithoutSponsorshipValidation({
158
+ chainId: provider.chain,
159
+ projectId: provider.clientId,
160
+ signer,
161
+ }),
162
+ kernelClientWithSponsorship: yield this.getKernelClientWithSponsorshipValidation({
163
+ chainId: provider.chain,
164
+ projectId: provider.clientId,
165
+ signer,
166
+ }),
167
+ };
168
+ }
169
+ yield this.warnIfProjectChainNotEnabled(utils.parseChainId(provider.chain));
170
+ }
171
+ });
172
+ }
173
+ getKernelClientWithoutSponsorshipValidation(_a) {
174
+ return _tslib.__awaiter(this, arguments, void 0, function* ({ projectId, signer, chainId, }) {
175
+ if (chainId && this.providerMap[chainId]) {
176
+ return this.providerMap[chainId].kernelClient;
177
+ }
178
+ const { eoaConnector } = this;
179
+ if (!eoaConnector)
180
+ throw new utils.DynamicError('No EOA connector');
83
181
  const kernelClient = yield createEcsdaKernelAccountClient.createEcdsaKernelAccountClient({
84
182
  bundlerRpc: ZeroDevConnector.bundlerRpc,
85
- chain: yield fetchZeroDevChain.fetchZeroDevChain(this.projectId),
183
+ chain: ethereumCore.chainsMap[chainId],
86
184
  ecdsaValidator: getEcdsaValidator.getEcdsaValidator(this.ecdsaProviderType),
87
185
  entryPointAddress: this.entryPoint,
88
186
  kernelVersion: this.kernelVersion,
89
187
  paymaster: 'NONE',
90
188
  paymasterRpc: ZeroDevConnector.paymasterRpc,
91
- projectId: this.projectId,
189
+ projectId,
92
190
  provider: ZeroDevConnector.bundlerProvider,
93
191
  signer: utils$1.walletClientToSmartAccountSigner(signer),
94
192
  });
@@ -96,51 +194,34 @@ class ZeroDevConnector extends walletConnectorCore.WalletConnectorBase {
96
194
  this._walletUiUtils.disabledConfirmationOnce();
97
195
  return original(...args);
98
196
  });
99
- this.kernelClient = kernelClient;
100
- // set the provider with sponsorship enabled
101
- yield this.getKernelClientWithSponsorshipValidation();
102
- yield this.checkIsProjectChainEnabled();
103
- this.kernelClientDeferredPromise.resolve();
104
- });
105
- }
106
- checkIsProjectChainEnabled() {
107
- return _tslib.__awaiter(this, void 0, void 0, function* () {
108
- var _a, _b;
109
- const client = yield this.getPublicClient();
110
- const chainName = (_a = client === null || client === void 0 ? void 0 : client.chain) === null || _a === void 0 ? void 0 : _a.name;
111
- const chainId = (_b = client === null || client === void 0 ? void 0 : client.chain) === null || _b === void 0 ? void 0 : _b.id;
112
- const isProjectChainEnabled = this.evmNetworks.some((network) => network.chainId === chainId);
113
- if (!isProjectChainEnabled) {
114
- logger.logger.error(`Please make sure to enable ${chainName} (${chainId}) in the Dynamic dashboard (https://app.dynamic.xyz/dashboard/configurations#evm).`);
115
- }
197
+ return kernelClient;
116
198
  });
117
199
  }
118
- getKernelClientWithSponsorshipValidation() {
119
- return _tslib.__awaiter(this, void 0, void 0, function* () {
120
- if (this.kernelClientWithSponsorship) {
121
- return this.kernelClientWithSponsorship;
200
+ getKernelClientWithSponsorshipValidation(_a) {
201
+ return _tslib.__awaiter(this, arguments, void 0, function* ({ projectId, signer, chainId, }) {
202
+ if (chainId && this.providerMap[chainId]) {
203
+ return this.providerMap[chainId].kernelClientWithSponsorship;
122
204
  }
123
205
  const { eoaConnector } = this;
124
206
  if (!eoaConnector)
125
207
  throw new utils.DynamicError('No EOA connector');
126
- const signer = yield eoaConnector.getSigner();
127
- this.kernelClientWithSponsorship = yield createEcsdaKernelAccountClient.createEcdsaKernelAccountClient({
208
+ const kernelClientWithSponsorship = yield createEcsdaKernelAccountClient.createEcdsaKernelAccountClient({
128
209
  bundlerRpc: ZeroDevConnector.bundlerRpc,
129
- chain: yield fetchZeroDevChain.fetchZeroDevChain(this.projectId),
210
+ chain: ethereumCore.chainsMap[chainId],
130
211
  ecdsaValidator: getEcdsaValidator.getEcdsaValidator(this.ecdsaProviderType),
131
212
  entryPointAddress: this.entryPoint,
132
213
  kernelVersion: this.kernelVersion,
133
214
  paymaster: 'SPONSOR',
134
215
  paymasterRpc: ZeroDevConnector.paymasterRpc,
135
- projectId: this.projectId,
216
+ projectId,
136
217
  provider: ZeroDevConnector.bundlerProvider,
137
218
  signer: utils$1.walletClientToSmartAccountSigner(signer),
138
219
  });
139
- utils.wrapMethodWithCallback(this.kernelClientWithSponsorship, 'sendUserOperation', (original, ...args) => {
220
+ utils.wrapMethodWithCallback(kernelClientWithSponsorship, 'sendUserOperation', (original, ...args) => {
140
221
  this._walletUiUtils.disabledConfirmationOnce();
141
222
  return original(...args);
142
223
  });
143
- return this.kernelClientWithSponsorship;
224
+ return kernelClientWithSponsorship;
144
225
  });
145
226
  }
146
227
  getAddress() {
@@ -181,7 +262,10 @@ class ZeroDevConnector extends walletConnectorCore.WalletConnectorBase {
181
262
  this._walletUiUtils.disabledConfirmationOnce();
182
263
  const effectiveProvider = this.isGasSponsorshipDisabled
183
264
  ? provider
184
- : yield this.getKernelClientWithSponsorshipValidation();
265
+ : this.kernelClientWithSponsorship;
266
+ if (!effectiveProvider) {
267
+ throw new utils.DynamicError('No provider');
268
+ }
185
269
  const response = yield effectiveProvider.sendTransaction(ethereumCore.unFormatTransaction(transaction));
186
270
  return response;
187
271
  }
@@ -219,7 +303,7 @@ class ZeroDevConnector extends walletConnectorCore.WalletConnectorBase {
219
303
  var _a;
220
304
  const provider = this.kernelClient;
221
305
  if (!provider)
222
- throw new utils.DynamicError('No provider');
306
+ return undefined;
223
307
  const transport = this.getTransport(provider);
224
308
  const address = (_a = provider.account) === null || _a === void 0 ? void 0 : _a.address;
225
309
  const walletClient = viem.createWalletClient({
@@ -234,7 +318,7 @@ class ZeroDevConnector extends walletConnectorCore.WalletConnectorBase {
234
318
  var _a;
235
319
  const provider = (_a = this.kernelClient) === null || _a === void 0 ? void 0 : _a.extend(viem.publicActions);
236
320
  if (!provider)
237
- throw new utils.DynamicError('No provider');
321
+ return undefined;
238
322
  return provider;
239
323
  });
240
324
  }
@@ -246,7 +330,10 @@ class ZeroDevConnector extends walletConnectorCore.WalletConnectorBase {
246
330
  canSponsorTransactionGas(transaction) {
247
331
  return _tslib.__awaiter(this, void 0, void 0, function* () {
248
332
  try {
249
- const kernelClientWithSponsorship = yield this.getKernelClientWithSponsorshipValidation();
333
+ const { kernelClientWithSponsorship } = this;
334
+ if (!kernelClientWithSponsorship) {
335
+ throw new utils.DynamicError('No kernel client with sponsorship found');
336
+ }
250
337
  const userOperation = {
251
338
  callData: yield kernelClientWithSponsorship.account.encodeCallData({
252
339
  data: transaction.data ? transaction.data : '0x',
@@ -4,9 +4,9 @@ import { Account, PublicClient, Transport, WalletClient } from 'viem';
4
4
  import { type Chain as ViemChain } from 'viem/chains';
5
5
  import { EntryPoint } from 'permissionless/types';
6
6
  import { KERNEL_VERSION_TYPE } from '@zerodev/sdk/types';
7
- import { Provider, ProviderEnum } from '@dynamic-labs/sdk-api-core';
8
- import { Chain, IAccountAbstractionWalletConnector, ISendBalanceWalletConnector, InternalWalletConnector, WalletConnectorBase } from '@dynamic-labs/wallet-connector-core';
9
7
  import { EthereumWallet } from '@dynamic-labs/ethereum-core';
8
+ import { Provider, ProviderEnum, ProviderMultichainAccountAbstractionProviders } from '@dynamic-labs/sdk-api-core';
9
+ import { Chain, IAccountAbstractionWalletConnector, ISendBalanceWalletConnector, InternalWalletConnector, WalletConnectorBase } from '@dynamic-labs/wallet-connector-core';
10
10
  import { WalletBookSchema } from '@dynamic-labs/wallet-book';
11
11
  import { EvmNetwork, GenericNetwork, IUITransaction, WalletUiUtils } from '@dynamic-labs/types';
12
12
  import { BundlerProvider } from './utils';
@@ -20,11 +20,11 @@ type ZeroDevConnectorProps = {
20
20
  bundlerProvider: BundlerProvider | undefined;
21
21
  };
22
22
  type IZeroDevConnector = IAccountAbstractionWalletConnector & ISendBalanceWalletConnector;
23
+ type KernelClient = KernelAccountClient<EntryPoint, Transport, ViemChain, KernelSmartAccount<EntryPoint>>;
23
24
  export declare class ZeroDevConnector extends WalletConnectorBase<typeof EthereumWallet> implements IZeroDevConnector {
24
- projectId: string;
25
- kernelClient: KernelAccountClient<EntryPoint, Transport, ViemChain, KernelSmartAccount<EntryPoint>> | undefined;
25
+ clientId: string;
26
26
  eoaConnector: InternalWalletConnector | undefined;
27
- kernelClientWithSponsorship: KernelAccountClient<EntryPoint, Transport, ViemChain, KernelSmartAccount<EntryPoint>> | undefined;
27
+ private providerMap;
28
28
  ChainWallet: typeof EthereumWallet;
29
29
  connectedChain: Chain;
30
30
  supportedChains: Chain[];
@@ -34,6 +34,8 @@ export declare class ZeroDevConnector extends WalletConnectorBase<typeof Ethereu
34
34
  entryPoint: EntryPoint;
35
35
  kernelVersion: KERNEL_VERSION_TYPE;
36
36
  ecdsaProviderType: string | undefined;
37
+ defaultChainId: string | undefined;
38
+ providersFromApi: ProviderMultichainAccountAbstractionProviders[];
37
39
  static bundlerProvider: BundlerProvider | undefined;
38
40
  static bundlerRpc: string | undefined;
39
41
  static paymasterRpc: string | undefined;
@@ -54,6 +56,17 @@ export declare class ZeroDevConnector extends WalletConnectorBase<typeof Ethereu
54
56
  };
55
57
  private _walletUiUtils;
56
58
  constructor(opts: ZeroDevConnectorProps);
59
+ get currentNetworkProvider(): {
60
+ kernelClient: KernelClient;
61
+ kernelClientWithSponsorship: KernelClient;
62
+ } | undefined;
63
+ get lastUsedChainId(): string;
64
+ get kernelClient(): KernelClient | undefined;
65
+ get kernelClientWithSponsorship(): KernelClient | undefined;
66
+ supportsNetworkSwitching(): boolean;
67
+ switchNetwork({ networkChainId, }: {
68
+ networkChainId?: number | string;
69
+ }): Promise<void>;
57
70
  /**
58
71
  * @deprecated You should get the EOA connector by passing the SCW to getEOAConnector,
59
72
  * from the useSmartWallet hook
@@ -61,10 +74,12 @@ export declare class ZeroDevConnector extends WalletConnectorBase<typeof Ethereu
61
74
  getEOAConnector(): InternalWalletConnector | undefined;
62
75
  getAccountAbstractionProvider({ withSponsorship, }?: {
63
76
  withSponsorship?: boolean;
64
- }): KernelAccountClient<EntryPoint> | undefined;
77
+ }): KernelClient | undefined;
65
78
  endSession(): Promise<void>;
66
79
  setEoaConnector(connector: InternalWalletConnector): Promise<void>;
67
- private checkIsProjectChainEnabled;
80
+ private warnIfProjectChainNotEnabled;
81
+ private generateProviderMap;
82
+ private getKernelClientWithoutSponsorshipValidation;
68
83
  private getKernelClientWithSponsorshipValidation;
69
84
  getAddress(): Promise<string | undefined>;
70
85
  getConnectedAccounts(): Promise<string[]>;
@@ -2890,44 +2905,44 @@ export declare class ZeroDevConnector extends WalletConnectorBase<typeof Ethereu
2890
2905
  [x: `address[${string}]`]: undefined;
2891
2906
  [x: `bool[${string}]`]: undefined;
2892
2907
  [x: `bytes[${string}]`]: undefined;
2893
- [x: `bytes9[${string}]`]: undefined;
2894
2908
  [x: `bytes1[${string}]`]: undefined;
2895
- [x: `bytes32[${string}]`]: undefined;
2896
- [x: `bytes31[${string}]`]: undefined;
2897
- [x: `bytes30[${string}]`]: undefined;
2898
- [x: `bytes29[${string}]`]: undefined;
2899
- [x: `bytes28[${string}]`]: undefined;
2900
- [x: `bytes27[${string}]`]: undefined;
2901
- [x: `bytes26[${string}]`]: undefined;
2902
- [x: `bytes25[${string}]`]: undefined;
2903
- [x: `bytes24[${string}]`]: undefined;
2904
- [x: `bytes23[${string}]`]: undefined;
2905
- [x: `bytes22[${string}]`]: undefined;
2906
- [x: `bytes21[${string}]`]: undefined;
2907
- [x: `bytes20[${string}]`]: undefined;
2908
- [x: `bytes19[${string}]`]: undefined;
2909
2909
  [x: `bytes2[${string}]`]: undefined;
2910
- [x: `bytes18[${string}]`]: undefined;
2911
- [x: `bytes17[${string}]`]: undefined;
2912
- [x: `bytes16[${string}]`]: undefined;
2913
- [x: `bytes15[${string}]`]: undefined;
2914
- [x: `bytes14[${string}]`]: undefined;
2915
- [x: `bytes13[${string}]`]: undefined;
2916
- [x: `bytes12[${string}]`]: undefined;
2917
- [x: `bytes11[${string}]`]: undefined;
2918
- [x: `bytes10[${string}]`]: undefined;
2919
- [x: `bytes8[${string}]`]: undefined;
2920
- [x: `bytes7[${string}]`]: undefined;
2921
- [x: `bytes6[${string}]`]: undefined;
2922
- [x: `bytes5[${string}]`]: undefined;
2923
- [x: `bytes4[${string}]`]: undefined;
2924
2910
  [x: `bytes3[${string}]`]: undefined;
2911
+ [x: `bytes4[${string}]`]: undefined;
2912
+ [x: `bytes5[${string}]`]: undefined;
2913
+ [x: `bytes6[${string}]`]: undefined;
2914
+ [x: `bytes7[${string}]`]: undefined;
2915
+ [x: `bytes8[${string}]`]: undefined;
2916
+ [x: `bytes9[${string}]`]: undefined;
2917
+ [x: `bytes10[${string}]`]: undefined;
2918
+ [x: `bytes11[${string}]`]: undefined;
2919
+ [x: `bytes12[${string}]`]: undefined;
2920
+ [x: `bytes13[${string}]`]: undefined;
2921
+ [x: `bytes14[${string}]`]: undefined;
2922
+ [x: `bytes15[${string}]`]: undefined;
2923
+ [x: `bytes16[${string}]`]: undefined;
2924
+ [x: `bytes17[${string}]`]: undefined;
2925
+ [x: `bytes18[${string}]`]: undefined;
2926
+ [x: `bytes19[${string}]`]: undefined;
2927
+ [x: `bytes20[${string}]`]: undefined;
2928
+ [x: `bytes21[${string}]`]: undefined;
2929
+ [x: `bytes22[${string}]`]: undefined;
2930
+ [x: `bytes23[${string}]`]: undefined;
2931
+ [x: `bytes24[${string}]`]: undefined;
2932
+ [x: `bytes25[${string}]`]: undefined;
2933
+ [x: `bytes26[${string}]`]: undefined;
2934
+ [x: `bytes27[${string}]`]: undefined;
2935
+ [x: `bytes28[${string}]`]: undefined;
2936
+ [x: `bytes29[${string}]`]: undefined;
2937
+ [x: `bytes30[${string}]`]: undefined;
2938
+ [x: `bytes31[${string}]`]: undefined;
2939
+ [x: `bytes32[${string}]`]: undefined;
2925
2940
  [x: `int[${string}]`]: undefined;
2926
- [x: `int40[${string}]`]: undefined;
2927
- [x: `int32[${string}]`]: undefined;
2928
- [x: `int24[${string}]`]: undefined;
2929
- [x: `int16[${string}]`]: undefined;
2930
2941
  [x: `int8[${string}]`]: undefined;
2942
+ [x: `int16[${string}]`]: undefined;
2943
+ [x: `int24[${string}]`]: undefined;
2944
+ [x: `int32[${string}]`]: undefined;
2945
+ [x: `int40[${string}]`]: undefined;
2931
2946
  [x: `int48[${string}]`]: undefined;
2932
2947
  [x: `int56[${string}]`]: undefined;
2933
2948
  [x: `int64[${string}]`]: undefined;
@@ -2956,11 +2971,11 @@ export declare class ZeroDevConnector extends WalletConnectorBase<typeof Ethereu
2956
2971
  [x: `int248[${string}]`]: undefined;
2957
2972
  [x: `int256[${string}]`]: undefined;
2958
2973
  [x: `uint[${string}]`]: undefined;
2959
- [x: `uint40[${string}]`]: undefined;
2960
- [x: `uint32[${string}]`]: undefined;
2961
- [x: `uint24[${string}]`]: undefined;
2962
- [x: `uint16[${string}]`]: undefined;
2963
2974
  [x: `uint8[${string}]`]: undefined;
2975
+ [x: `uint16[${string}]`]: undefined;
2976
+ [x: `uint24[${string}]`]: undefined;
2977
+ [x: `uint32[${string}]`]: undefined;
2978
+ [x: `uint40[${string}]`]: undefined;
2964
2979
  [x: `uint48[${string}]`]: undefined;
2965
2980
  [x: `uint56[${string}]`]: undefined;
2966
2981
  [x: `uint64[${string}]`]: undefined;
@@ -2992,43 +3007,43 @@ export declare class ZeroDevConnector extends WalletConnectorBase<typeof Ethereu
2992
3007
  address?: undefined;
2993
3008
  bool?: undefined;
2994
3009
  bytes?: undefined;
2995
- bytes9?: undefined;
2996
3010
  bytes1?: undefined;
2997
- bytes32?: undefined;
2998
- bytes31?: undefined;
2999
- bytes30?: undefined;
3000
- bytes29?: undefined;
3001
- bytes28?: undefined;
3002
- bytes27?: undefined;
3003
- bytes26?: undefined;
3004
- bytes25?: undefined;
3005
- bytes24?: undefined;
3006
- bytes23?: undefined;
3007
- bytes22?: undefined;
3008
- bytes21?: undefined;
3009
- bytes20?: undefined;
3010
- bytes19?: undefined;
3011
3011
  bytes2?: undefined;
3012
- bytes18?: undefined;
3013
- bytes17?: undefined;
3014
- bytes16?: undefined;
3015
- bytes15?: undefined;
3016
- bytes14?: undefined;
3017
- bytes13?: undefined;
3018
- bytes12?: undefined;
3019
- bytes11?: undefined;
3020
- bytes10?: undefined;
3021
- bytes8?: undefined;
3022
- bytes7?: undefined;
3023
- bytes6?: undefined;
3024
- bytes5?: undefined;
3025
- bytes4?: undefined;
3026
3012
  bytes3?: undefined;
3027
- int40?: undefined;
3028
- int32?: undefined;
3029
- int24?: undefined;
3030
- int16?: undefined;
3013
+ bytes4?: undefined;
3014
+ bytes5?: undefined;
3015
+ bytes6?: undefined;
3016
+ bytes7?: undefined;
3017
+ bytes8?: undefined;
3018
+ bytes9?: undefined;
3019
+ bytes10?: undefined;
3020
+ bytes11?: undefined;
3021
+ bytes12?: undefined;
3022
+ bytes13?: undefined;
3023
+ bytes14?: undefined;
3024
+ bytes15?: undefined;
3025
+ bytes16?: undefined;
3026
+ bytes17?: undefined;
3027
+ bytes18?: undefined;
3028
+ bytes19?: undefined;
3029
+ bytes20?: undefined;
3030
+ bytes21?: undefined;
3031
+ bytes22?: undefined;
3032
+ bytes23?: undefined;
3033
+ bytes24?: undefined;
3034
+ bytes25?: undefined;
3035
+ bytes26?: undefined;
3036
+ bytes27?: undefined;
3037
+ bytes28?: undefined;
3038
+ bytes29?: undefined;
3039
+ bytes30?: undefined;
3040
+ bytes31?: undefined;
3041
+ bytes32?: undefined;
3031
3042
  int8?: undefined;
3043
+ int16?: undefined;
3044
+ int24?: undefined;
3045
+ int32?: undefined;
3046
+ int40?: undefined;
3032
3047
  int48?: undefined;
3033
3048
  int56?: undefined;
3034
3049
  int64?: undefined;
@@ -3056,11 +3071,11 @@ export declare class ZeroDevConnector extends WalletConnectorBase<typeof Ethereu
3056
3071
  int240?: undefined;
3057
3072
  int248?: undefined;
3058
3073
  int256?: undefined;
3059
- uint40?: undefined;
3060
- uint32?: undefined;
3061
- uint24?: undefined;
3062
- uint16?: undefined;
3063
3074
  uint8?: undefined;
3075
+ uint16?: undefined;
3076
+ uint24?: undefined;
3077
+ uint32?: undefined;
3078
+ uint40?: undefined;
3064
3079
  uint48?: undefined;
3065
3080
  uint56?: undefined;
3066
3081
  uint64?: undefined;
@@ -2,10 +2,10 @@
2
2
  import { __awaiter } from '../_virtual/_tslib.js';
3
3
  import { publicActions, custom, createWalletClient, isHex, fromHex, formatEther } from 'viem';
4
4
  import { walletClientToSmartAccountSigner } from 'permissionless/utils';
5
- import { WalletConnectorBase, isTurnkeyWalletConnector } from '@dynamic-labs/wallet-connector-core';
6
- import { EthereumWallet, isEthWalletConnector, confirmationTransport, unFormatTransaction, chainsMap, createViemUiTransaction } from '@dynamic-labs/ethereum-core';
7
- import { parseEvmNetworks, DeferredPromise, wrapMethodWithCallback, DynamicError, TransactionGasCannotBeSponsoredError, InsufficientFundsError } from '@dynamic-labs/utils';
8
- import { cachedChainIdKey, fetchZeroDevChain } from './utils/fetchZeroDevChain.js';
5
+ import { EthereumWallet, isEthWalletConnector, chainsMap, confirmationTransport, unFormatTransaction, createViemUiTransaction } from '@dynamic-labs/ethereum-core';
6
+ import { WalletConnectorBase, eventListenerHandlers, isTurnkeyWalletConnector } from '@dynamic-labs/wallet-connector-core';
7
+ import { parseEvmNetworks, StorageService, DeferredPromise, parseChainId, DynamicError, wrapMethodWithCallback, TransactionGasCannotBeSponsoredError, InsufficientFundsError } from '@dynamic-labs/utils';
8
+ import { ZERO_DEV_LAST_USED_CHAIN_ID_KEY } from './constants.js';
9
9
  import { logger } from './utils/logger.js';
10
10
  import { createEcdsaKernelAccountClient } from './utils/createEcsdaKernelAccountClient.js';
11
11
  import { getEcdsaValidator } from './utils/getEcdsaValidator.js';
@@ -16,11 +16,13 @@ class ZeroDevConnector extends WalletConnectorBase {
16
16
  constructor(opts) {
17
17
  var _a, _b, _c, _d;
18
18
  super(opts);
19
+ this.providerMap = {};
19
20
  this.ChainWallet = EthereumWallet;
20
21
  this.connectedChain = 'EVM';
21
22
  this.supportedChains = ['ETH', 'EVM'];
22
23
  this.isGasSponsorshipDisabled = false;
23
24
  this.isEmbeddedWallet = true;
25
+ this.providersFromApi = [];
24
26
  this.name = 'ZeroDev';
25
27
  this.overrideKey = 'zerodev';
26
28
  this.walletFallback = {
@@ -30,17 +32,65 @@ class ZeroDevConnector extends WalletConnectorBase {
30
32
  },
31
33
  name: 'ZeroDev',
32
34
  };
33
- const zeroDevProjectId = (_a = opts.apiProviders.zerodev) === null || _a === void 0 ? void 0 : _a.clientId;
34
- if (!zeroDevProjectId) {
35
- throw new Error('Missing ZeroDev project ID provided. Add your ZeroDev project id to your project configuration via the Dynamic Labs dashboard.');
36
- }
37
- this.projectId = zeroDevProjectId;
38
35
  this._walletUiUtils = opts.walletUiUtils;
39
36
  this.evmNetworks = parseEvmNetworks(opts.evmNetworks);
40
- this.entryPoint = getEntryPoint((_b = opts.apiProviders.zerodev) === null || _b === void 0 ? void 0 : _b.entryPointVersion);
41
- this.kernelVersion = getKernelVersion((_c = opts.apiProviders.zerodev) === null || _c === void 0 ? void 0 : _c.kernelVersion, this.entryPoint);
37
+ this.entryPoint = getEntryPoint((_a = opts.apiProviders.zerodev) === null || _a === void 0 ? void 0 : _a.entryPointVersion);
38
+ this.kernelVersion = getKernelVersion((_b = opts.apiProviders.zerodev) === null || _b === void 0 ? void 0 : _b.kernelVersion, this.entryPoint);
39
+ // this is the list of providers from the api that are used for multi-chain account abstraction
40
+ this.providersFromApi =
41
+ ((_c = opts.apiProviders.zerodev) === null || _c === void 0 ? void 0 : _c.multichainAccountAbstractionProviders) || [];
42
+ const [defaultProvider] = this.providersFromApi;
43
+ this.clientId = defaultProvider === null || defaultProvider === void 0 ? void 0 : defaultProvider.clientId;
44
+ if (!this.clientId) {
45
+ throw new Error('Missing ZeroDev project ID provided. Add your ZeroDev project id to your project configuration via the Dynamic Labs dashboard.');
46
+ }
47
+ this.defaultChainId = defaultProvider === null || defaultProvider === void 0 ? void 0 : defaultProvider.chain;
42
48
  this.ecdsaProviderType = (_d = opts.apiProviders.zerodev) === null || _d === void 0 ? void 0 : _d.ecdsaProviderType;
43
49
  }
50
+ get currentNetworkProvider() {
51
+ // check if the last used chain id is in the provider map
52
+ if (this.providerMap[this.lastUsedChainId]) {
53
+ return this.providerMap[this.lastUsedChainId];
54
+ }
55
+ // if not, check if the default chain id is in the provider map
56
+ if (this.defaultChainId) {
57
+ return this.providerMap[this.defaultChainId];
58
+ }
59
+ // if no chain id is found, return undefined
60
+ return undefined;
61
+ }
62
+ get lastUsedChainId() {
63
+ var _a;
64
+ const storedChainId = StorageService.getItem(ZERO_DEV_LAST_USED_CHAIN_ID_KEY);
65
+ // returning string of unknown if no chain id is found to result in undefined provider lookup
66
+ return (_a = storedChainId !== null && storedChainId !== void 0 ? storedChainId : this.defaultChainId) !== null && _a !== void 0 ? _a : 'unknown';
67
+ }
68
+ get kernelClient() {
69
+ var _a;
70
+ return (_a = this.currentNetworkProvider) === null || _a === void 0 ? void 0 : _a.kernelClient;
71
+ }
72
+ get kernelClientWithSponsorship() {
73
+ var _a;
74
+ return (_a = this.currentNetworkProvider) === null || _a === void 0 ? void 0 : _a.kernelClientWithSponsorship;
75
+ }
76
+ supportsNetworkSwitching() {
77
+ return (Object.keys(this.providerMap).length > 1 && this.evmNetworks.length > 1);
78
+ }
79
+ switchNetwork(_a) {
80
+ return __awaiter(this, arguments, void 0, function* ({ networkChainId, }) {
81
+ if (!this.supportsNetworkSwitching())
82
+ return;
83
+ if (!networkChainId)
84
+ return;
85
+ const chainId = networkChainId.toString();
86
+ if (!this.providerMap[chainId]) {
87
+ throw new Error(`No provider found for chainId: ${chainId}`);
88
+ }
89
+ StorageService.setItem(ZERO_DEV_LAST_USED_CHAIN_ID_KEY, chainId);
90
+ const { handleChainChange } = eventListenerHandlers(this);
91
+ handleChainChange(chainId);
92
+ });
93
+ }
44
94
  /**
45
95
  * @deprecated You should get the EOA connector by passing the SCW to getEOAConnector,
46
96
  * from the useSmartWallet hook
@@ -56,7 +106,7 @@ class ZeroDevConnector extends WalletConnectorBase {
56
106
  }
57
107
  endSession() {
58
108
  return __awaiter(this, void 0, void 0, function* () {
59
- localStorage.removeItem(cachedChainIdKey);
109
+ StorageService.removeItem(ZERO_DEV_LAST_USED_CHAIN_ID_KEY);
60
110
  });
61
111
  }
62
112
  setEoaConnector(connector) {
@@ -76,15 +126,63 @@ class ZeroDevConnector extends WalletConnectorBase {
76
126
  logger.error('No signer account found');
77
127
  return;
78
128
  }
129
+ yield this.generateProviderMap(signer);
130
+ this.evmNetworks = this.evmNetworks.filter((network) => Boolean(this.providerMap[network.chainId]));
131
+ this.kernelClientDeferredPromise.resolve();
132
+ });
133
+ }
134
+ warnIfProjectChainNotEnabled(chainId) {
135
+ return __awaiter(this, void 0, void 0, function* () {
136
+ var _a;
137
+ let chainIdToCheck = chainId;
138
+ if (!chainIdToCheck) {
139
+ const client = yield this.getPublicClient();
140
+ chainIdToCheck = (_a = client === null || client === void 0 ? void 0 : client.chain) === null || _a === void 0 ? void 0 : _a.id;
141
+ }
142
+ const isProjectChainEnabled = this.evmNetworks.some((network) => network.chainId === chainIdToCheck);
143
+ if (!isProjectChainEnabled) {
144
+ logger.error(`Please make sure to enable (${chainIdToCheck}) in the Dynamic dashboard (https://app.dynamic.xyz/dashboard/configurations#evm).`);
145
+ }
146
+ });
147
+ }
148
+ generateProviderMap(signer) {
149
+ return __awaiter(this, void 0, void 0, function* () {
150
+ for (const provider of this.providersFromApi) {
151
+ if (!this.providerMap[provider.chain]) {
152
+ this.providerMap[provider.chain] = {
153
+ kernelClient: yield this.getKernelClientWithoutSponsorshipValidation({
154
+ chainId: provider.chain,
155
+ projectId: provider.clientId,
156
+ signer,
157
+ }),
158
+ kernelClientWithSponsorship: yield this.getKernelClientWithSponsorshipValidation({
159
+ chainId: provider.chain,
160
+ projectId: provider.clientId,
161
+ signer,
162
+ }),
163
+ };
164
+ }
165
+ yield this.warnIfProjectChainNotEnabled(parseChainId(provider.chain));
166
+ }
167
+ });
168
+ }
169
+ getKernelClientWithoutSponsorshipValidation(_a) {
170
+ return __awaiter(this, arguments, void 0, function* ({ projectId, signer, chainId, }) {
171
+ if (chainId && this.providerMap[chainId]) {
172
+ return this.providerMap[chainId].kernelClient;
173
+ }
174
+ const { eoaConnector } = this;
175
+ if (!eoaConnector)
176
+ throw new DynamicError('No EOA connector');
79
177
  const kernelClient = yield createEcdsaKernelAccountClient({
80
178
  bundlerRpc: ZeroDevConnector.bundlerRpc,
81
- chain: yield fetchZeroDevChain(this.projectId),
179
+ chain: chainsMap[chainId],
82
180
  ecdsaValidator: getEcdsaValidator(this.ecdsaProviderType),
83
181
  entryPointAddress: this.entryPoint,
84
182
  kernelVersion: this.kernelVersion,
85
183
  paymaster: 'NONE',
86
184
  paymasterRpc: ZeroDevConnector.paymasterRpc,
87
- projectId: this.projectId,
185
+ projectId,
88
186
  provider: ZeroDevConnector.bundlerProvider,
89
187
  signer: walletClientToSmartAccountSigner(signer),
90
188
  });
@@ -92,51 +190,34 @@ class ZeroDevConnector extends WalletConnectorBase {
92
190
  this._walletUiUtils.disabledConfirmationOnce();
93
191
  return original(...args);
94
192
  });
95
- this.kernelClient = kernelClient;
96
- // set the provider with sponsorship enabled
97
- yield this.getKernelClientWithSponsorshipValidation();
98
- yield this.checkIsProjectChainEnabled();
99
- this.kernelClientDeferredPromise.resolve();
100
- });
101
- }
102
- checkIsProjectChainEnabled() {
103
- return __awaiter(this, void 0, void 0, function* () {
104
- var _a, _b;
105
- const client = yield this.getPublicClient();
106
- const chainName = (_a = client === null || client === void 0 ? void 0 : client.chain) === null || _a === void 0 ? void 0 : _a.name;
107
- const chainId = (_b = client === null || client === void 0 ? void 0 : client.chain) === null || _b === void 0 ? void 0 : _b.id;
108
- const isProjectChainEnabled = this.evmNetworks.some((network) => network.chainId === chainId);
109
- if (!isProjectChainEnabled) {
110
- logger.error(`Please make sure to enable ${chainName} (${chainId}) in the Dynamic dashboard (https://app.dynamic.xyz/dashboard/configurations#evm).`);
111
- }
193
+ return kernelClient;
112
194
  });
113
195
  }
114
- getKernelClientWithSponsorshipValidation() {
115
- return __awaiter(this, void 0, void 0, function* () {
116
- if (this.kernelClientWithSponsorship) {
117
- return this.kernelClientWithSponsorship;
196
+ getKernelClientWithSponsorshipValidation(_a) {
197
+ return __awaiter(this, arguments, void 0, function* ({ projectId, signer, chainId, }) {
198
+ if (chainId && this.providerMap[chainId]) {
199
+ return this.providerMap[chainId].kernelClientWithSponsorship;
118
200
  }
119
201
  const { eoaConnector } = this;
120
202
  if (!eoaConnector)
121
203
  throw new DynamicError('No EOA connector');
122
- const signer = yield eoaConnector.getSigner();
123
- this.kernelClientWithSponsorship = yield createEcdsaKernelAccountClient({
204
+ const kernelClientWithSponsorship = yield createEcdsaKernelAccountClient({
124
205
  bundlerRpc: ZeroDevConnector.bundlerRpc,
125
- chain: yield fetchZeroDevChain(this.projectId),
206
+ chain: chainsMap[chainId],
126
207
  ecdsaValidator: getEcdsaValidator(this.ecdsaProviderType),
127
208
  entryPointAddress: this.entryPoint,
128
209
  kernelVersion: this.kernelVersion,
129
210
  paymaster: 'SPONSOR',
130
211
  paymasterRpc: ZeroDevConnector.paymasterRpc,
131
- projectId: this.projectId,
212
+ projectId,
132
213
  provider: ZeroDevConnector.bundlerProvider,
133
214
  signer: walletClientToSmartAccountSigner(signer),
134
215
  });
135
- wrapMethodWithCallback(this.kernelClientWithSponsorship, 'sendUserOperation', (original, ...args) => {
216
+ wrapMethodWithCallback(kernelClientWithSponsorship, 'sendUserOperation', (original, ...args) => {
136
217
  this._walletUiUtils.disabledConfirmationOnce();
137
218
  return original(...args);
138
219
  });
139
- return this.kernelClientWithSponsorship;
220
+ return kernelClientWithSponsorship;
140
221
  });
141
222
  }
142
223
  getAddress() {
@@ -177,7 +258,10 @@ class ZeroDevConnector extends WalletConnectorBase {
177
258
  this._walletUiUtils.disabledConfirmationOnce();
178
259
  const effectiveProvider = this.isGasSponsorshipDisabled
179
260
  ? provider
180
- : yield this.getKernelClientWithSponsorshipValidation();
261
+ : this.kernelClientWithSponsorship;
262
+ if (!effectiveProvider) {
263
+ throw new DynamicError('No provider');
264
+ }
181
265
  const response = yield effectiveProvider.sendTransaction(unFormatTransaction(transaction));
182
266
  return response;
183
267
  }
@@ -215,7 +299,7 @@ class ZeroDevConnector extends WalletConnectorBase {
215
299
  var _a;
216
300
  const provider = this.kernelClient;
217
301
  if (!provider)
218
- throw new DynamicError('No provider');
302
+ return undefined;
219
303
  const transport = this.getTransport(provider);
220
304
  const address = (_a = provider.account) === null || _a === void 0 ? void 0 : _a.address;
221
305
  const walletClient = createWalletClient({
@@ -230,7 +314,7 @@ class ZeroDevConnector extends WalletConnectorBase {
230
314
  var _a;
231
315
  const provider = (_a = this.kernelClient) === null || _a === void 0 ? void 0 : _a.extend(publicActions);
232
316
  if (!provider)
233
- throw new DynamicError('No provider');
317
+ return undefined;
234
318
  return provider;
235
319
  });
236
320
  }
@@ -242,7 +326,10 @@ class ZeroDevConnector extends WalletConnectorBase {
242
326
  canSponsorTransactionGas(transaction) {
243
327
  return __awaiter(this, void 0, void 0, function* () {
244
328
  try {
245
- const kernelClientWithSponsorship = yield this.getKernelClientWithSponsorshipValidation();
329
+ const { kernelClientWithSponsorship } = this;
330
+ if (!kernelClientWithSponsorship) {
331
+ throw new DynamicError('No kernel client with sponsorship found');
332
+ }
246
333
  const userOperation = {
247
334
  callData: yield kernelClientWithSponsorship.account.encodeCallData({
248
335
  data: transaction.data ? transaction.data : '0x',
@@ -0,0 +1,8 @@
1
+ 'use client'
2
+ 'use strict';
3
+
4
+ Object.defineProperty(exports, '__esModule', { value: true });
5
+
6
+ const ZERO_DEV_LAST_USED_CHAIN_ID_KEY = 'dynamic_zerodev_last_used_chain_id';
7
+
8
+ exports.ZERO_DEV_LAST_USED_CHAIN_ID_KEY = ZERO_DEV_LAST_USED_CHAIN_ID_KEY;
@@ -0,0 +1 @@
1
+ export declare const ZERO_DEV_LAST_USED_CHAIN_ID_KEY = "dynamic_zerodev_last_used_chain_id";
@@ -0,0 +1,4 @@
1
+ 'use client'
2
+ const ZERO_DEV_LAST_USED_CHAIN_ID_KEY = 'dynamic_zerodev_last_used_chain_id';
3
+
4
+ export { ZERO_DEV_LAST_USED_CHAIN_ID_KEY };
@@ -21,4 +21,4 @@ export declare const createEcdsaKernelAccountClient: <entryPoint extends EntryPo
21
21
  index?: bigint;
22
22
  kernelVersion: GetKernelVersion<entryPoint>;
23
23
  ecdsaValidator: any;
24
- }) => Promise<KernelAccountClient<entryPoint, HttpTransport, TChain, KernelSmartAccount<entryPoint, HttpTransport, TChain>>>;
24
+ }) => Promise<KernelAccountClient<entryPoint, HttpTransport, TChain, KernelSmartAccount<entryPoint>>>;