@dynamic-labs/ethereum-aa 3.1.4 → 3.3.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 CHANGED
@@ -1,4 +1,28 @@
1
1
 
2
+ ## [3.3.0](https://github.com/dynamic-labs/DynamicAuth/compare/v3.2.0...v3.3.0) (2024-10-08)
3
+
4
+
5
+ ### Features
6
+
7
+ * Account Abstraction Multi-Chain ([#7088](https://github.com/dynamic-labs/DynamicAuth/issues/7088)) ([c5de504](https://github.com/dynamic-labs/DynamicAuth/commit/c5de50414299473b8ec18094693377d8c064e4fa))
8
+
9
+
10
+ ### Bug Fixes
11
+
12
+ * solana embedded sponsored transactions ([#7066](https://github.com/dynamic-labs/DynamicAuth/issues/7066)) ([086b4ec](https://github.com/dynamic-labs/DynamicAuth/commit/086b4ecbbad56a4684f655fb977a1d5d7d3bca3a))
13
+
14
+ ## [3.2.0](https://github.com/dynamic-labs/DynamicAuth/compare/v3.1.4...v3.2.0) (2024-10-02)
15
+
16
+
17
+ ### Features
18
+
19
+ * view global connectivity connections and allow disconnection ([#7037](https://github.com/dynamic-labs/DynamicAuth/issues/7037)) ([6d7c2ba](https://github.com/dynamic-labs/DynamicAuth/commit/6d7c2baf2d1480e30e1394547635f0f1e7c47509))
20
+
21
+
22
+ ### Bug Fixes
23
+
24
+ * ensure the correct auth mode is used on social redirect ([#7047](https://github.com/dynamic-labs/DynamicAuth/issues/7047)) ([#7055](https://github.com/dynamic-labs/DynamicAuth/issues/7055)) ([b83ee70](https://github.com/dynamic-labs/DynamicAuth/commit/b83ee702fede980dad9641ad08453fc20ba1b6bb))
25
+
2
26
  ### [3.1.4](https://github.com/dynamic-labs/DynamicAuth/compare/v3.1.3...v3.1.4) (2024-09-30)
3
27
 
4
28
 
@@ -890,7 +914,7 @@
890
914
 
891
915
  - React Native - You can now build mobile-first onboarding experiences with the same Dynamic magic but for React Native, get started [here](https://docs.dynamic.xyz/react-native/introduction)
892
916
 
893
- - Cookie Authentication - Dynamic can now be configured to set a secure, HttpOnly cookie that can be used for authenticating with Dynamic’s backend. This will contain a minified version of our JWT token.
917
+ - Cookie Authentication - Dynamic can now be configured to set a secure, HttpOnly cookie that can be used for authenticating with Dynamic’s backend. This will contain a minified version of our JWT token.
894
918
 
895
919
 
896
920
  ## Improvements
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dynamic-labs/ethereum-aa",
3
- "version": "3.1.4",
3
+ "version": "3.3.0",
4
4
  "repository": {
5
5
  "type": "git",
6
6
  "url": "git+https://github.com/dynamic-labs/dynamic-auth.git",
@@ -31,12 +31,12 @@
31
31
  "@zerodev/multi-chain-validator": "5.3.3",
32
32
  "@zerodev/sdk": "5.3.4",
33
33
  "permissionless": "^0.1.20",
34
- "@dynamic-labs/ethereum-core": "3.1.4",
35
- "@dynamic-labs/logger": "3.1.4",
36
- "@dynamic-labs/types": "3.1.4",
37
- "@dynamic-labs/utils": "3.1.4",
38
- "@dynamic-labs/wallet-book": "3.1.4",
39
- "@dynamic-labs/wallet-connector-core": "3.1.4"
34
+ "@dynamic-labs/ethereum-core": "3.3.0",
35
+ "@dynamic-labs/logger": "3.3.0",
36
+ "@dynamic-labs/types": "3.3.0",
37
+ "@dynamic-labs/utils": "3.3.0",
38
+ "@dynamic-labs/wallet-book": "3.3.0",
39
+ "@dynamic-labs/wallet-connector-core": "3.3.0"
40
40
  },
41
41
  "peerDependencies": {
42
42
  "viem": "^2.7.6"
@@ -4,28 +4,29 @@
4
4
  Object.defineProperty(exports, '__esModule', { value: true });
5
5
 
6
6
  var _tslib = require('../_virtual/_tslib.cjs');
7
- var multiChainValidator = require('@zerodev/multi-chain-validator');
8
7
  var viem = require('viem');
9
8
  var utils$1 = require('permissionless/utils');
10
- var constants = require('@zerodev/sdk/constants');
11
- var ecdsaValidator = require('@zerodev/ecdsa-validator');
12
- var sdkApiCore = require('@dynamic-labs/sdk-api-core');
13
- var walletConnectorCore = require('@dynamic-labs/wallet-connector-core');
14
9
  var ethereumCore = require('@dynamic-labs/ethereum-core');
10
+ var walletConnectorCore = require('@dynamic-labs/wallet-connector-core');
15
11
  var utils = require('@dynamic-labs/utils');
16
- var fetchChain = require('./utils/fetchChain.cjs');
12
+ var constants = require('./constants.cjs');
17
13
  var logger = require('./utils/logger.cjs');
18
14
  var createEcsdaKernelAccountClient = require('./utils/createEcsdaKernelAccountClient.cjs');
15
+ var getEntryPoint = require('./utils/getEntryPoint.cjs');
16
+ var getEcdsaValidator = require('./utils/getEcdsaValidator.cjs');
17
+ var getKernelVersion = require('./utils/getKernelVersion.cjs');
19
18
 
20
19
  class ZeroDevConnector extends walletConnectorCore.WalletConnectorBase {
21
20
  constructor(opts) {
22
21
  var _a, _b, _c, _d;
23
22
  super(opts);
23
+ this.providerMap = {};
24
24
  this.ChainWallet = ethereumCore.EthereumWallet;
25
25
  this.connectedChain = 'EVM';
26
26
  this.supportedChains = ['ETH', 'EVM'];
27
27
  this.isGasSponsorshipDisabled = false;
28
28
  this.isEmbeddedWallet = true;
29
+ this.providersFromApi = [];
29
30
  this.name = 'ZeroDev';
30
31
  this.overrideKey = 'zerodev';
31
32
  this.walletFallback = {
@@ -35,59 +36,64 @@ class ZeroDevConnector extends walletConnectorCore.WalletConnectorBase {
35
36
  },
36
37
  name: 'ZeroDev',
37
38
  };
38
- const zeroDevProjectId = (_a = opts.apiProviders.zerodev) === null || _a === void 0 ? void 0 : _a.clientId;
39
- if (!zeroDevProjectId) {
40
- throw new Error('Missing ZeroDev project ID provided. Add your ZeroDev project id to your project configuration via the Dynamic Labs dashboard.');
41
- }
42
- this.projectId = zeroDevProjectId;
43
39
  this._walletUiUtils = opts.walletUiUtils;
44
40
  this.evmNetworks = utils.parseEvmNetworks(opts.evmNetworks);
45
- this.entryPoint = this.getEntryPoint((_b = opts.apiProviders.zerodev) === null || _b === void 0 ? void 0 : _b.entryPointVersion);
46
- this.kernelVersion = this.getKernelVersion((_c = opts.apiProviders.zerodev) === null || _c === void 0 ? void 0 : _c.kernelVersion);
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;
47
52
  this.ecdsaProviderType = (_d = opts.apiProviders.zerodev) === null || _d === void 0 ? void 0 : _d.ecdsaProviderType;
48
53
  }
49
- getEntryPoint(entryPoint) {
50
- if (entryPoint === undefined ||
51
- entryPoint === sdkApiCore.ProviderEntryPointVersionEnum.V7) {
52
- return utils$1.ENTRYPOINT_ADDRESS_V07;
53
- }
54
- else if (entryPoint === sdkApiCore.ProviderEntryPointVersionEnum.V6) {
55
- return utils$1.ENTRYPOINT_ADDRESS_V06;
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];
56
58
  }
57
- else {
58
- logger.logger.error('Invalid entry point version', entryPoint);
59
- return utils$1.ENTRYPOINT_ADDRESS_V07;
59
+ // if not, check if the default chain id is in the provider map
60
+ if (this.defaultChainId) {
61
+ return this.providerMap[this.defaultChainId];
60
62
  }
63
+ // if no chain id is found, return undefined
64
+ return undefined;
61
65
  }
62
- getKernelVersion(kernelVersion) {
63
- if (kernelVersion === sdkApiCore.ProviderKernelVersionEnum.V31 ||
64
- (kernelVersion === undefined &&
65
- this.entryPoint === utils$1.ENTRYPOINT_ADDRESS_V07)) {
66
- return constants.KERNEL_V3_1;
67
- }
68
- else if (kernelVersion === sdkApiCore.ProviderKernelVersionEnum.V30) {
69
- return constants.KERNEL_V3_0;
70
- }
71
- else if (kernelVersion === sdkApiCore.ProviderKernelVersionEnum.V24 ||
72
- this.entryPoint === utils$1.ENTRYPOINT_ADDRESS_V06 // v0.6 only supports v2.4
73
- ) {
74
- return constants.KERNEL_V2_4;
75
- }
76
- else {
77
- logger.logger.error('Invalid kernel version', kernelVersion);
78
- return constants.KERNEL_V3_1;
79
- }
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';
80
71
  }
81
- getEcdsaValidator(ecdsaProviderType) {
82
- if (ecdsaProviderType === 'zerodev_signer_to_ecdsa') {
83
- return ecdsaValidator.signerToEcdsaValidator;
84
- }
85
- else if (ecdsaProviderType === 'zerodev_multi_chain') {
86
- return multiChainValidator.toMultiChainECDSAValidator;
87
- }
88
- else {
89
- return ecdsaValidator.signerToEcdsaValidator;
90
- }
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
+ });
91
97
  }
92
98
  /**
93
99
  * @deprecated You should get the EOA connector by passing the SCW to getEOAConnector,
@@ -104,7 +110,7 @@ class ZeroDevConnector extends walletConnectorCore.WalletConnectorBase {
104
110
  }
105
111
  endSession() {
106
112
  return _tslib.__awaiter(this, void 0, void 0, function* () {
107
- localStorage.removeItem(fetchChain.cachedChainIdKey);
113
+ utils.StorageService.removeItem(constants.ZERO_DEV_LAST_USED_CHAIN_ID_KEY);
108
114
  });
109
115
  }
110
116
  setEoaConnector(connector) {
@@ -124,15 +130,63 @@ class ZeroDevConnector extends walletConnectorCore.WalletConnectorBase {
124
130
  logger.logger.error('No signer account found');
125
131
  return;
126
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');
127
181
  const kernelClient = yield createEcsdaKernelAccountClient.createEcdsaKernelAccountClient({
128
182
  bundlerRpc: ZeroDevConnector.bundlerRpc,
129
- chain: yield fetchChain.fetchChain(this.projectId),
130
- ecdsaValidator: this.getEcdsaValidator(this.ecdsaProviderType),
183
+ chain: ethereumCore.chainsMap[chainId],
184
+ ecdsaValidator: getEcdsaValidator.getEcdsaValidator(this.ecdsaProviderType),
131
185
  entryPointAddress: this.entryPoint,
132
186
  kernelVersion: this.kernelVersion,
133
187
  paymaster: 'NONE',
134
188
  paymasterRpc: ZeroDevConnector.paymasterRpc,
135
- projectId: this.projectId,
189
+ projectId,
136
190
  provider: ZeroDevConnector.bundlerProvider,
137
191
  signer: utils$1.walletClientToSmartAccountSigner(signer),
138
192
  });
@@ -140,51 +194,34 @@ class ZeroDevConnector extends walletConnectorCore.WalletConnectorBase {
140
194
  this._walletUiUtils.disabledConfirmationOnce();
141
195
  return original(...args);
142
196
  });
143
- this.kernelClient = kernelClient;
144
- // set the provider with sponsorship enabled
145
- yield this.getKernelClientWithSponsorshipValidation();
146
- yield this.checkIsProjectChainEnabled();
147
- this.kernelClientDeferredPromise.resolve();
197
+ return kernelClient;
148
198
  });
149
199
  }
150
- checkIsProjectChainEnabled() {
151
- return _tslib.__awaiter(this, void 0, void 0, function* () {
152
- var _a, _b;
153
- const client = yield this.getPublicClient();
154
- const chainName = (_a = client === null || client === void 0 ? void 0 : client.chain) === null || _a === void 0 ? void 0 : _a.name;
155
- const chainId = (_b = client === null || client === void 0 ? void 0 : client.chain) === null || _b === void 0 ? void 0 : _b.id;
156
- const isProjectChainEnabled = this.evmNetworks.some((network) => network.chainId === chainId);
157
- if (!isProjectChainEnabled) {
158
- logger.logger.error(`Please make sure to enable ${chainName} (${chainId}) in the Dynamic dashboard (https://app.dynamic.xyz/dashboard/configurations#evm).`);
159
- }
160
- });
161
- }
162
- getKernelClientWithSponsorshipValidation() {
163
- return _tslib.__awaiter(this, void 0, void 0, function* () {
164
- if (this.kernelClientWithSponsorship) {
165
- 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;
166
204
  }
167
205
  const { eoaConnector } = this;
168
206
  if (!eoaConnector)
169
207
  throw new utils.DynamicError('No EOA connector');
170
- const signer = yield eoaConnector.getSigner();
171
- this.kernelClientWithSponsorship = yield createEcsdaKernelAccountClient.createEcdsaKernelAccountClient({
208
+ const kernelClientWithSponsorship = yield createEcsdaKernelAccountClient.createEcdsaKernelAccountClient({
172
209
  bundlerRpc: ZeroDevConnector.bundlerRpc,
173
- chain: yield fetchChain.fetchChain(this.projectId),
174
- ecdsaValidator: this.getEcdsaValidator(this.ecdsaProviderType),
210
+ chain: ethereumCore.chainsMap[chainId],
211
+ ecdsaValidator: getEcdsaValidator.getEcdsaValidator(this.ecdsaProviderType),
175
212
  entryPointAddress: this.entryPoint,
176
213
  kernelVersion: this.kernelVersion,
177
214
  paymaster: 'SPONSOR',
178
215
  paymasterRpc: ZeroDevConnector.paymasterRpc,
179
- projectId: this.projectId,
216
+ projectId,
180
217
  provider: ZeroDevConnector.bundlerProvider,
181
218
  signer: utils$1.walletClientToSmartAccountSigner(signer),
182
219
  });
183
- utils.wrapMethodWithCallback(this.kernelClientWithSponsorship, 'sendUserOperation', (original, ...args) => {
220
+ utils.wrapMethodWithCallback(kernelClientWithSponsorship, 'sendUserOperation', (original, ...args) => {
184
221
  this._walletUiUtils.disabledConfirmationOnce();
185
222
  return original(...args);
186
223
  });
187
- return this.kernelClientWithSponsorship;
224
+ return kernelClientWithSponsorship;
188
225
  });
189
226
  }
190
227
  getAddress() {
@@ -225,7 +262,10 @@ class ZeroDevConnector extends walletConnectorCore.WalletConnectorBase {
225
262
  this._walletUiUtils.disabledConfirmationOnce();
226
263
  const effectiveProvider = this.isGasSponsorshipDisabled
227
264
  ? provider
228
- : yield this.getKernelClientWithSponsorshipValidation();
265
+ : this.kernelClientWithSponsorship;
266
+ if (!effectiveProvider) {
267
+ throw new utils.DynamicError('No provider');
268
+ }
229
269
  const response = yield effectiveProvider.sendTransaction(ethereumCore.unFormatTransaction(transaction));
230
270
  return response;
231
271
  }
@@ -263,7 +303,7 @@ class ZeroDevConnector extends walletConnectorCore.WalletConnectorBase {
263
303
  var _a;
264
304
  const provider = this.kernelClient;
265
305
  if (!provider)
266
- throw new utils.DynamicError('No provider');
306
+ return undefined;
267
307
  const transport = this.getTransport(provider);
268
308
  const address = (_a = provider.account) === null || _a === void 0 ? void 0 : _a.address;
269
309
  const walletClient = viem.createWalletClient({
@@ -278,7 +318,7 @@ class ZeroDevConnector extends walletConnectorCore.WalletConnectorBase {
278
318
  var _a;
279
319
  const provider = (_a = this.kernelClient) === null || _a === void 0 ? void 0 : _a.extend(viem.publicActions);
280
320
  if (!provider)
281
- throw new utils.DynamicError('No provider');
321
+ return undefined;
282
322
  return provider;
283
323
  });
284
324
  }
@@ -290,7 +330,10 @@ class ZeroDevConnector extends walletConnectorCore.WalletConnectorBase {
290
330
  canSponsorTransactionGas(transaction) {
291
331
  return _tslib.__awaiter(this, void 0, void 0, function* () {
292
332
  try {
293
- const kernelClientWithSponsorship = yield this.getKernelClientWithSponsorshipValidation();
333
+ const { kernelClientWithSponsorship } = this;
334
+ if (!kernelClientWithSponsorship) {
335
+ throw new utils.DynamicError('No kernel client with sponsorship found');
336
+ }
294
337
  const userOperation = {
295
338
  callData: yield kernelClientWithSponsorship.account.encodeCallData({
296
339
  data: transaction.data ? transaction.data : '0x',
@@ -1,14 +1,12 @@
1
1
  import { KernelAccountClient } from '@zerodev/sdk/clients';
2
2
  import { KernelSmartAccount } from '@zerodev/sdk/accounts';
3
- import { toMultiChainECDSAValidator } from '@zerodev/multi-chain-validator';
4
3
  import { Account, PublicClient, Transport, WalletClient } from 'viem';
5
4
  import { type Chain as ViemChain } from 'viem/chains';
6
5
  import { EntryPoint } from 'permissionless/types';
7
6
  import { KERNEL_VERSION_TYPE } from '@zerodev/sdk/types';
8
- import { signerToEcdsaValidator } from '@zerodev/ecdsa-validator';
9
- import { Provider, ProviderEnum } from '@dynamic-labs/sdk-api-core';
10
- import { Chain, IAccountAbstractionWalletConnector, ISendBalanceWalletConnector, InternalWalletConnector, WalletConnectorBase } from '@dynamic-labs/wallet-connector-core';
11
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';
12
10
  import { WalletBookSchema } from '@dynamic-labs/wallet-book';
13
11
  import { EvmNetwork, GenericNetwork, IUITransaction, WalletUiUtils } from '@dynamic-labs/types';
14
12
  import { BundlerProvider } from './utils';
@@ -22,11 +20,11 @@ type ZeroDevConnectorProps = {
22
20
  bundlerProvider: BundlerProvider | undefined;
23
21
  };
24
22
  type IZeroDevConnector = IAccountAbstractionWalletConnector & ISendBalanceWalletConnector;
23
+ type KernelClient = KernelAccountClient<EntryPoint, Transport, ViemChain, KernelSmartAccount<EntryPoint>>;
25
24
  export declare class ZeroDevConnector extends WalletConnectorBase<typeof EthereumWallet> implements IZeroDevConnector {
26
- projectId: string;
27
- kernelClient: KernelAccountClient<EntryPoint, Transport, ViemChain, KernelSmartAccount<EntryPoint>> | undefined;
25
+ clientId: string;
28
26
  eoaConnector: InternalWalletConnector | undefined;
29
- kernelClientWithSponsorship: KernelAccountClient<EntryPoint, Transport, ViemChain, KernelSmartAccount<EntryPoint>> | undefined;
27
+ private providerMap;
30
28
  ChainWallet: typeof EthereumWallet;
31
29
  connectedChain: Chain;
32
30
  supportedChains: Chain[];
@@ -36,6 +34,8 @@ export declare class ZeroDevConnector extends WalletConnectorBase<typeof Ethereu
36
34
  entryPoint: EntryPoint;
37
35
  kernelVersion: KERNEL_VERSION_TYPE;
38
36
  ecdsaProviderType: string | undefined;
37
+ defaultChainId: string | undefined;
38
+ providersFromApi: ProviderMultichainAccountAbstractionProviders[];
39
39
  static bundlerProvider: BundlerProvider | undefined;
40
40
  static bundlerRpc: string | undefined;
41
41
  static paymasterRpc: string | undefined;
@@ -56,9 +56,17 @@ export declare class ZeroDevConnector extends WalletConnectorBase<typeof Ethereu
56
56
  };
57
57
  private _walletUiUtils;
58
58
  constructor(opts: ZeroDevConnectorProps);
59
- getEntryPoint(entryPoint: string | undefined): "0x5FF137D4b0FDCD49DcA30c7CF57E578a026d2789" | "0x0000000071727De22E5E9d8BAf0edAc6f37da032";
60
- getKernelVersion(kernelVersion: string | undefined): KERNEL_VERSION_TYPE;
61
- getEcdsaValidator(ecdsaProviderType: string | undefined): typeof signerToEcdsaValidator | typeof toMultiChainECDSAValidator;
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>;
62
70
  /**
63
71
  * @deprecated You should get the EOA connector by passing the SCW to getEOAConnector,
64
72
  * from the useSmartWallet hook
@@ -66,10 +74,12 @@ export declare class ZeroDevConnector extends WalletConnectorBase<typeof Ethereu
66
74
  getEOAConnector(): InternalWalletConnector | undefined;
67
75
  getAccountAbstractionProvider({ withSponsorship, }?: {
68
76
  withSponsorship?: boolean;
69
- }): KernelAccountClient<EntryPoint> | undefined;
77
+ }): KernelClient | undefined;
70
78
  endSession(): Promise<void>;
71
79
  setEoaConnector(connector: InternalWalletConnector): Promise<void>;
72
- private checkIsProjectChainEnabled;
80
+ private warnIfProjectChainNotEnabled;
81
+ private generateProviderMap;
82
+ private getKernelClientWithoutSponsorshipValidation;
73
83
  private getKernelClientWithSponsorshipValidation;
74
84
  getAddress(): Promise<string | undefined>;
75
85
  getConnectedAccounts(): Promise<string[]>;
@@ -2895,44 +2905,44 @@ export declare class ZeroDevConnector extends WalletConnectorBase<typeof Ethereu
2895
2905
  [x: `address[${string}]`]: undefined;
2896
2906
  [x: `bool[${string}]`]: undefined;
2897
2907
  [x: `bytes[${string}]`]: undefined;
2898
- [x: `bytes9[${string}]`]: undefined;
2899
2908
  [x: `bytes1[${string}]`]: undefined;
2900
- [x: `bytes32[${string}]`]: undefined;
2901
- [x: `bytes31[${string}]`]: undefined;
2902
- [x: `bytes30[${string}]`]: undefined;
2903
- [x: `bytes29[${string}]`]: undefined;
2904
- [x: `bytes28[${string}]`]: undefined;
2905
- [x: `bytes27[${string}]`]: undefined;
2906
- [x: `bytes26[${string}]`]: undefined;
2907
- [x: `bytes25[${string}]`]: undefined;
2908
- [x: `bytes24[${string}]`]: undefined;
2909
- [x: `bytes23[${string}]`]: undefined;
2910
- [x: `bytes22[${string}]`]: undefined;
2911
- [x: `bytes21[${string}]`]: undefined;
2912
- [x: `bytes20[${string}]`]: undefined;
2913
- [x: `bytes19[${string}]`]: undefined;
2914
2909
  [x: `bytes2[${string}]`]: undefined;
2915
- [x: `bytes18[${string}]`]: undefined;
2916
- [x: `bytes17[${string}]`]: undefined;
2917
- [x: `bytes16[${string}]`]: undefined;
2918
- [x: `bytes15[${string}]`]: undefined;
2919
- [x: `bytes14[${string}]`]: undefined;
2920
- [x: `bytes13[${string}]`]: undefined;
2921
- [x: `bytes12[${string}]`]: undefined;
2922
- [x: `bytes11[${string}]`]: undefined;
2923
- [x: `bytes10[${string}]`]: undefined;
2924
- [x: `bytes8[${string}]`]: undefined;
2925
- [x: `bytes7[${string}]`]: undefined;
2926
- [x: `bytes6[${string}]`]: undefined;
2927
- [x: `bytes5[${string}]`]: undefined;
2928
- [x: `bytes4[${string}]`]: undefined;
2929
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;
2930
2940
  [x: `int[${string}]`]: undefined;
2931
- [x: `int40[${string}]`]: undefined;
2932
- [x: `int32[${string}]`]: undefined;
2933
- [x: `int24[${string}]`]: undefined;
2934
- [x: `int16[${string}]`]: undefined;
2935
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;
2936
2946
  [x: `int48[${string}]`]: undefined;
2937
2947
  [x: `int56[${string}]`]: undefined;
2938
2948
  [x: `int64[${string}]`]: undefined;
@@ -2961,11 +2971,11 @@ export declare class ZeroDevConnector extends WalletConnectorBase<typeof Ethereu
2961
2971
  [x: `int248[${string}]`]: undefined;
2962
2972
  [x: `int256[${string}]`]: undefined;
2963
2973
  [x: `uint[${string}]`]: undefined;
2964
- [x: `uint40[${string}]`]: undefined;
2965
- [x: `uint32[${string}]`]: undefined;
2966
- [x: `uint24[${string}]`]: undefined;
2967
- [x: `uint16[${string}]`]: undefined;
2968
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;
2969
2979
  [x: `uint48[${string}]`]: undefined;
2970
2980
  [x: `uint56[${string}]`]: undefined;
2971
2981
  [x: `uint64[${string}]`]: undefined;
@@ -2997,43 +3007,43 @@ export declare class ZeroDevConnector extends WalletConnectorBase<typeof Ethereu
2997
3007
  address?: undefined;
2998
3008
  bool?: undefined;
2999
3009
  bytes?: undefined;
3000
- bytes9?: undefined;
3001
3010
  bytes1?: undefined;
3002
- bytes32?: undefined;
3003
- bytes31?: undefined;
3004
- bytes30?: undefined;
3005
- bytes29?: undefined;
3006
- bytes28?: undefined;
3007
- bytes27?: undefined;
3008
- bytes26?: undefined;
3009
- bytes25?: undefined;
3010
- bytes24?: undefined;
3011
- bytes23?: undefined;
3012
- bytes22?: undefined;
3013
- bytes21?: undefined;
3014
- bytes20?: undefined;
3015
- bytes19?: undefined;
3016
3011
  bytes2?: undefined;
3017
- bytes18?: undefined;
3018
- bytes17?: undefined;
3019
- bytes16?: undefined;
3020
- bytes15?: undefined;
3021
- bytes14?: undefined;
3022
- bytes13?: undefined;
3023
- bytes12?: undefined;
3024
- bytes11?: undefined;
3025
- bytes10?: undefined;
3026
- bytes8?: undefined;
3027
- bytes7?: undefined;
3028
- bytes6?: undefined;
3029
- bytes5?: undefined;
3030
- bytes4?: undefined;
3031
3012
  bytes3?: undefined;
3032
- int40?: undefined;
3033
- int32?: undefined;
3034
- int24?: undefined;
3035
- 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;
3036
3042
  int8?: undefined;
3043
+ int16?: undefined;
3044
+ int24?: undefined;
3045
+ int32?: undefined;
3046
+ int40?: undefined;
3037
3047
  int48?: undefined;
3038
3048
  int56?: undefined;
3039
3049
  int64?: undefined;
@@ -3061,11 +3071,11 @@ export declare class ZeroDevConnector extends WalletConnectorBase<typeof Ethereu
3061
3071
  int240?: undefined;
3062
3072
  int248?: undefined;
3063
3073
  int256?: undefined;
3064
- uint40?: undefined;
3065
- uint32?: undefined;
3066
- uint24?: undefined;
3067
- uint16?: undefined;
3068
3074
  uint8?: undefined;
3075
+ uint16?: undefined;
3076
+ uint24?: undefined;
3077
+ uint32?: undefined;
3078
+ uint40?: undefined;
3069
3079
  uint48?: undefined;
3070
3080
  uint56?: undefined;
3071
3081
  uint64?: undefined;
@@ -1,27 +1,28 @@
1
1
  'use client'
2
2
  import { __awaiter } from '../_virtual/_tslib.js';
3
- import { toMultiChainECDSAValidator } from '@zerodev/multi-chain-validator';
4
3
  import { publicActions, custom, createWalletClient, isHex, fromHex, formatEther } from 'viem';
5
- import { ENTRYPOINT_ADDRESS_V07, ENTRYPOINT_ADDRESS_V06, walletClientToSmartAccountSigner } from 'permissionless/utils';
6
- import { KERNEL_V3_1, KERNEL_V3_0, KERNEL_V2_4 } from '@zerodev/sdk/constants';
7
- import { signerToEcdsaValidator } from '@zerodev/ecdsa-validator';
8
- import { ProviderEntryPointVersionEnum, ProviderKernelVersionEnum } from '@dynamic-labs/sdk-api-core';
9
- import { WalletConnectorBase, isTurnkeyWalletConnector } from '@dynamic-labs/wallet-connector-core';
4
+ import { walletClientToSmartAccountSigner } from 'permissionless/utils';
10
5
  import { EthereumWallet, confirmationTransport, chainsMap, isEthWalletConnector, unFormatTransaction, createViemUiTransaction } from '@dynamic-labs/ethereum-core';
11
- import { parseEvmNetworks, DynamicError, DeferredPromise, wrapMethodWithCallback, TransactionGasCannotBeSponsoredError, InsufficientFundsError } from '@dynamic-labs/utils';
12
- import { cachedChainIdKey, fetchChain } from './utils/fetchChain.js';
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';
13
9
  import { logger } from './utils/logger.js';
14
10
  import { createEcdsaKernelAccountClient } from './utils/createEcsdaKernelAccountClient.js';
11
+ import { getEntryPoint } from './utils/getEntryPoint.js';
12
+ import { getEcdsaValidator } from './utils/getEcdsaValidator.js';
13
+ import { getKernelVersion } from './utils/getKernelVersion.js';
15
14
 
16
15
  class ZeroDevConnector extends WalletConnectorBase {
17
16
  constructor(opts) {
18
17
  var _a, _b, _c, _d;
19
18
  super(opts);
19
+ this.providerMap = {};
20
20
  this.ChainWallet = EthereumWallet;
21
21
  this.connectedChain = 'EVM';
22
22
  this.supportedChains = ['ETH', 'EVM'];
23
23
  this.isGasSponsorshipDisabled = false;
24
24
  this.isEmbeddedWallet = true;
25
+ this.providersFromApi = [];
25
26
  this.name = 'ZeroDev';
26
27
  this.overrideKey = 'zerodev';
27
28
  this.walletFallback = {
@@ -31,59 +32,64 @@ class ZeroDevConnector extends WalletConnectorBase {
31
32
  },
32
33
  name: 'ZeroDev',
33
34
  };
34
- const zeroDevProjectId = (_a = opts.apiProviders.zerodev) === null || _a === void 0 ? void 0 : _a.clientId;
35
- if (!zeroDevProjectId) {
36
- throw new Error('Missing ZeroDev project ID provided. Add your ZeroDev project id to your project configuration via the Dynamic Labs dashboard.');
37
- }
38
- this.projectId = zeroDevProjectId;
39
35
  this._walletUiUtils = opts.walletUiUtils;
40
36
  this.evmNetworks = parseEvmNetworks(opts.evmNetworks);
41
- this.entryPoint = this.getEntryPoint((_b = opts.apiProviders.zerodev) === null || _b === void 0 ? void 0 : _b.entryPointVersion);
42
- this.kernelVersion = this.getKernelVersion((_c = opts.apiProviders.zerodev) === null || _c === void 0 ? void 0 : _c.kernelVersion);
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;
43
48
  this.ecdsaProviderType = (_d = opts.apiProviders.zerodev) === null || _d === void 0 ? void 0 : _d.ecdsaProviderType;
44
49
  }
45
- getEntryPoint(entryPoint) {
46
- if (entryPoint === undefined ||
47
- entryPoint === ProviderEntryPointVersionEnum.V7) {
48
- return ENTRYPOINT_ADDRESS_V07;
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];
49
54
  }
50
- else if (entryPoint === ProviderEntryPointVersionEnum.V6) {
51
- return ENTRYPOINT_ADDRESS_V06;
52
- }
53
- else {
54
- logger.error('Invalid entry point version', entryPoint);
55
- return ENTRYPOINT_ADDRESS_V07;
55
+ // if not, check if the default chain id is in the provider map
56
+ if (this.defaultChainId) {
57
+ return this.providerMap[this.defaultChainId];
56
58
  }
59
+ // if no chain id is found, return undefined
60
+ return undefined;
57
61
  }
58
- getKernelVersion(kernelVersion) {
59
- if (kernelVersion === ProviderKernelVersionEnum.V31 ||
60
- (kernelVersion === undefined &&
61
- this.entryPoint === ENTRYPOINT_ADDRESS_V07)) {
62
- return KERNEL_V3_1;
63
- }
64
- else if (kernelVersion === ProviderKernelVersionEnum.V30) {
65
- return KERNEL_V3_0;
66
- }
67
- else if (kernelVersion === ProviderKernelVersionEnum.V24 ||
68
- this.entryPoint === ENTRYPOINT_ADDRESS_V06 // v0.6 only supports v2.4
69
- ) {
70
- return KERNEL_V2_4;
71
- }
72
- else {
73
- logger.error('Invalid kernel version', kernelVersion);
74
- return KERNEL_V3_1;
75
- }
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';
76
67
  }
77
- getEcdsaValidator(ecdsaProviderType) {
78
- if (ecdsaProviderType === 'zerodev_signer_to_ecdsa') {
79
- return signerToEcdsaValidator;
80
- }
81
- else if (ecdsaProviderType === 'zerodev_multi_chain') {
82
- return toMultiChainECDSAValidator;
83
- }
84
- else {
85
- return signerToEcdsaValidator;
86
- }
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
+ });
87
93
  }
88
94
  /**
89
95
  * @deprecated You should get the EOA connector by passing the SCW to getEOAConnector,
@@ -100,7 +106,7 @@ class ZeroDevConnector extends WalletConnectorBase {
100
106
  }
101
107
  endSession() {
102
108
  return __awaiter(this, void 0, void 0, function* () {
103
- localStorage.removeItem(cachedChainIdKey);
109
+ StorageService.removeItem(ZERO_DEV_LAST_USED_CHAIN_ID_KEY);
104
110
  });
105
111
  }
106
112
  setEoaConnector(connector) {
@@ -120,15 +126,63 @@ class ZeroDevConnector extends WalletConnectorBase {
120
126
  logger.error('No signer account found');
121
127
  return;
122
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');
123
177
  const kernelClient = yield createEcdsaKernelAccountClient({
124
178
  bundlerRpc: ZeroDevConnector.bundlerRpc,
125
- chain: yield fetchChain(this.projectId),
126
- ecdsaValidator: this.getEcdsaValidator(this.ecdsaProviderType),
179
+ chain: chainsMap[chainId],
180
+ ecdsaValidator: getEcdsaValidator(this.ecdsaProviderType),
127
181
  entryPointAddress: this.entryPoint,
128
182
  kernelVersion: this.kernelVersion,
129
183
  paymaster: 'NONE',
130
184
  paymasterRpc: ZeroDevConnector.paymasterRpc,
131
- projectId: this.projectId,
185
+ projectId,
132
186
  provider: ZeroDevConnector.bundlerProvider,
133
187
  signer: walletClientToSmartAccountSigner(signer),
134
188
  });
@@ -136,51 +190,34 @@ class ZeroDevConnector extends WalletConnectorBase {
136
190
  this._walletUiUtils.disabledConfirmationOnce();
137
191
  return original(...args);
138
192
  });
139
- this.kernelClient = kernelClient;
140
- // set the provider with sponsorship enabled
141
- yield this.getKernelClientWithSponsorshipValidation();
142
- yield this.checkIsProjectChainEnabled();
143
- this.kernelClientDeferredPromise.resolve();
144
- });
145
- }
146
- checkIsProjectChainEnabled() {
147
- return __awaiter(this, void 0, void 0, function* () {
148
- var _a, _b;
149
- const client = yield this.getPublicClient();
150
- const chainName = (_a = client === null || client === void 0 ? void 0 : client.chain) === null || _a === void 0 ? void 0 : _a.name;
151
- const chainId = (_b = client === null || client === void 0 ? void 0 : client.chain) === null || _b === void 0 ? void 0 : _b.id;
152
- const isProjectChainEnabled = this.evmNetworks.some((network) => network.chainId === chainId);
153
- if (!isProjectChainEnabled) {
154
- logger.error(`Please make sure to enable ${chainName} (${chainId}) in the Dynamic dashboard (https://app.dynamic.xyz/dashboard/configurations#evm).`);
155
- }
193
+ return kernelClient;
156
194
  });
157
195
  }
158
- getKernelClientWithSponsorshipValidation() {
159
- return __awaiter(this, void 0, void 0, function* () {
160
- if (this.kernelClientWithSponsorship) {
161
- 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;
162
200
  }
163
201
  const { eoaConnector } = this;
164
202
  if (!eoaConnector)
165
203
  throw new DynamicError('No EOA connector');
166
- const signer = yield eoaConnector.getSigner();
167
- this.kernelClientWithSponsorship = yield createEcdsaKernelAccountClient({
204
+ const kernelClientWithSponsorship = yield createEcdsaKernelAccountClient({
168
205
  bundlerRpc: ZeroDevConnector.bundlerRpc,
169
- chain: yield fetchChain(this.projectId),
170
- ecdsaValidator: this.getEcdsaValidator(this.ecdsaProviderType),
206
+ chain: chainsMap[chainId],
207
+ ecdsaValidator: getEcdsaValidator(this.ecdsaProviderType),
171
208
  entryPointAddress: this.entryPoint,
172
209
  kernelVersion: this.kernelVersion,
173
210
  paymaster: 'SPONSOR',
174
211
  paymasterRpc: ZeroDevConnector.paymasterRpc,
175
- projectId: this.projectId,
212
+ projectId,
176
213
  provider: ZeroDevConnector.bundlerProvider,
177
214
  signer: walletClientToSmartAccountSigner(signer),
178
215
  });
179
- wrapMethodWithCallback(this.kernelClientWithSponsorship, 'sendUserOperation', (original, ...args) => {
216
+ wrapMethodWithCallback(kernelClientWithSponsorship, 'sendUserOperation', (original, ...args) => {
180
217
  this._walletUiUtils.disabledConfirmationOnce();
181
218
  return original(...args);
182
219
  });
183
- return this.kernelClientWithSponsorship;
220
+ return kernelClientWithSponsorship;
184
221
  });
185
222
  }
186
223
  getAddress() {
@@ -221,7 +258,10 @@ class ZeroDevConnector extends WalletConnectorBase {
221
258
  this._walletUiUtils.disabledConfirmationOnce();
222
259
  const effectiveProvider = this.isGasSponsorshipDisabled
223
260
  ? provider
224
- : yield this.getKernelClientWithSponsorshipValidation();
261
+ : this.kernelClientWithSponsorship;
262
+ if (!effectiveProvider) {
263
+ throw new DynamicError('No provider');
264
+ }
225
265
  const response = yield effectiveProvider.sendTransaction(unFormatTransaction(transaction));
226
266
  return response;
227
267
  }
@@ -259,7 +299,7 @@ class ZeroDevConnector extends WalletConnectorBase {
259
299
  var _a;
260
300
  const provider = this.kernelClient;
261
301
  if (!provider)
262
- throw new DynamicError('No provider');
302
+ return undefined;
263
303
  const transport = this.getTransport(provider);
264
304
  const address = (_a = provider.account) === null || _a === void 0 ? void 0 : _a.address;
265
305
  const walletClient = createWalletClient({
@@ -274,7 +314,7 @@ class ZeroDevConnector extends WalletConnectorBase {
274
314
  var _a;
275
315
  const provider = (_a = this.kernelClient) === null || _a === void 0 ? void 0 : _a.extend(publicActions);
276
316
  if (!provider)
277
- throw new DynamicError('No provider');
317
+ return undefined;
278
318
  return provider;
279
319
  });
280
320
  }
@@ -286,7 +326,10 @@ class ZeroDevConnector extends WalletConnectorBase {
286
326
  canSponsorTransactionGas(transaction) {
287
327
  return __awaiter(this, void 0, void 0, function* () {
288
328
  try {
289
- const kernelClientWithSponsorship = yield this.getKernelClientWithSponsorshipValidation();
329
+ const { kernelClientWithSponsorship } = this;
330
+ if (!kernelClientWithSponsorship) {
331
+ throw new DynamicError('No kernel client with sponsorship found');
332
+ }
290
333
  const userOperation = {
291
334
  callData: yield kernelClientWithSponsorship.account.encodeCallData({
292
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>>>;
@@ -1,3 +1,3 @@
1
1
  import { type Chain } from 'viem/chains';
2
2
  export declare const cachedChainIdKey = "dynamic_zd_chain_id";
3
- export declare const fetchChain: (projectId: string) => Promise<Chain>;
3
+ export declare const fetchZeroDevChain: (projectId: string) => Promise<Chain>;
@@ -0,0 +1,21 @@
1
+ 'use client'
2
+ 'use strict';
3
+
4
+ Object.defineProperty(exports, '__esModule', { value: true });
5
+
6
+ var ecdsaValidator = require('@zerodev/ecdsa-validator');
7
+ var multiChainValidator = require('@zerodev/multi-chain-validator');
8
+
9
+ const getEcdsaValidator = (ecdsaProviderType) => {
10
+ if (ecdsaProviderType === 'zerodev_signer_to_ecdsa') {
11
+ return ecdsaValidator.signerToEcdsaValidator;
12
+ }
13
+ else if (ecdsaProviderType === 'zerodev_multi_chain') {
14
+ return multiChainValidator.toMultiChainECDSAValidator;
15
+ }
16
+ else {
17
+ return ecdsaValidator.signerToEcdsaValidator;
18
+ }
19
+ };
20
+
21
+ exports.getEcdsaValidator = getEcdsaValidator;
@@ -0,0 +1,3 @@
1
+ import { signerToEcdsaValidator } from '@zerodev/ecdsa-validator';
2
+ import { toMultiChainECDSAValidator } from '@zerodev/multi-chain-validator';
3
+ export declare const getEcdsaValidator: (ecdsaProviderType: string | undefined) => typeof signerToEcdsaValidator | typeof toMultiChainECDSAValidator;
@@ -0,0 +1,17 @@
1
+ 'use client'
2
+ import { signerToEcdsaValidator } from '@zerodev/ecdsa-validator';
3
+ import { toMultiChainECDSAValidator } from '@zerodev/multi-chain-validator';
4
+
5
+ const getEcdsaValidator = (ecdsaProviderType) => {
6
+ if (ecdsaProviderType === 'zerodev_signer_to_ecdsa') {
7
+ return signerToEcdsaValidator;
8
+ }
9
+ else if (ecdsaProviderType === 'zerodev_multi_chain') {
10
+ return toMultiChainECDSAValidator;
11
+ }
12
+ else {
13
+ return signerToEcdsaValidator;
14
+ }
15
+ };
16
+
17
+ export { getEcdsaValidator };
@@ -0,0 +1,24 @@
1
+ 'use client'
2
+ 'use strict';
3
+
4
+ Object.defineProperty(exports, '__esModule', { value: true });
5
+
6
+ var permissionless = require('permissionless');
7
+ var sdkApiCore = require('@dynamic-labs/sdk-api-core');
8
+ var logger = require('./logger.cjs');
9
+
10
+ const getEntryPoint = (entryPoint) => {
11
+ if (entryPoint === undefined ||
12
+ entryPoint === sdkApiCore.ProviderEntryPointVersionEnum.V7) {
13
+ return permissionless.ENTRYPOINT_ADDRESS_V07;
14
+ }
15
+ else if (entryPoint === sdkApiCore.ProviderEntryPointVersionEnum.V6) {
16
+ return permissionless.ENTRYPOINT_ADDRESS_V06;
17
+ }
18
+ else {
19
+ logger.logger.error('Invalid entry point version', entryPoint);
20
+ return permissionless.ENTRYPOINT_ADDRESS_V07;
21
+ }
22
+ };
23
+
24
+ exports.getEntryPoint = getEntryPoint;
@@ -0,0 +1 @@
1
+ export declare const getEntryPoint: (entryPoint: string | undefined) => "0x0000000071727De22E5E9d8BAf0edAc6f37da032" | "0x5FF137D4b0FDCD49DcA30c7CF57E578a026d2789";
@@ -0,0 +1,20 @@
1
+ 'use client'
2
+ import { ENTRYPOINT_ADDRESS_V07, ENTRYPOINT_ADDRESS_V06 } from 'permissionless';
3
+ import { ProviderEntryPointVersionEnum } from '@dynamic-labs/sdk-api-core';
4
+ import { logger } from './logger.js';
5
+
6
+ const getEntryPoint = (entryPoint) => {
7
+ if (entryPoint === undefined ||
8
+ entryPoint === ProviderEntryPointVersionEnum.V7) {
9
+ return ENTRYPOINT_ADDRESS_V07;
10
+ }
11
+ else if (entryPoint === ProviderEntryPointVersionEnum.V6) {
12
+ return ENTRYPOINT_ADDRESS_V06;
13
+ }
14
+ else {
15
+ logger.error('Invalid entry point version', entryPoint);
16
+ return ENTRYPOINT_ADDRESS_V07;
17
+ }
18
+ };
19
+
20
+ export { getEntryPoint };
@@ -0,0 +1,31 @@
1
+ 'use client'
2
+ 'use strict';
3
+
4
+ Object.defineProperty(exports, '__esModule', { value: true });
5
+
6
+ var permissionless = require('permissionless');
7
+ var constants = require('@zerodev/sdk/constants');
8
+ var sdkApiCore = require('@dynamic-labs/sdk-api-core');
9
+ var logger = require('./logger.cjs');
10
+
11
+ const getKernelVersion = (kernelVersion, entryPointAddress) => {
12
+ if (kernelVersion === sdkApiCore.ProviderKernelVersionEnum.V31 ||
13
+ (kernelVersion === undefined &&
14
+ entryPointAddress === permissionless.ENTRYPOINT_ADDRESS_V07)) {
15
+ return constants.KERNEL_V3_1;
16
+ }
17
+ else if (kernelVersion === sdkApiCore.ProviderKernelVersionEnum.V30) {
18
+ return constants.KERNEL_V3_0;
19
+ }
20
+ else if (kernelVersion === sdkApiCore.ProviderKernelVersionEnum.V24 ||
21
+ entryPointAddress === permissionless.ENTRYPOINT_ADDRESS_V06 // v0.6 only supports v2.4
22
+ ) {
23
+ return constants.KERNEL_V2_4;
24
+ }
25
+ else {
26
+ logger.logger.error('Invalid kernel version', kernelVersion);
27
+ return constants.KERNEL_V3_1;
28
+ }
29
+ };
30
+
31
+ exports.getKernelVersion = getKernelVersion;
@@ -0,0 +1,4 @@
1
+ import { KERNEL_VERSION_TYPE } from '@zerodev/sdk/types';
2
+ import { ProviderKernelVersionEnum } from '@dynamic-labs/sdk-api-core';
3
+ import { getEntryPoint } from './getEntryPoint';
4
+ export declare const getKernelVersion: (kernelVersion: ProviderKernelVersionEnum | undefined, entryPointAddress: ReturnType<typeof getEntryPoint>) => KERNEL_VERSION_TYPE;
@@ -0,0 +1,27 @@
1
+ 'use client'
2
+ import { ENTRYPOINT_ADDRESS_V07, ENTRYPOINT_ADDRESS_V06 } from 'permissionless';
3
+ import { KERNEL_V3_1, KERNEL_V3_0, KERNEL_V2_4 } from '@zerodev/sdk/constants';
4
+ import { ProviderKernelVersionEnum } from '@dynamic-labs/sdk-api-core';
5
+ import { logger } from './logger.js';
6
+
7
+ const getKernelVersion = (kernelVersion, entryPointAddress) => {
8
+ if (kernelVersion === ProviderKernelVersionEnum.V31 ||
9
+ (kernelVersion === undefined &&
10
+ entryPointAddress === ENTRYPOINT_ADDRESS_V07)) {
11
+ return KERNEL_V3_1;
12
+ }
13
+ else if (kernelVersion === ProviderKernelVersionEnum.V30) {
14
+ return KERNEL_V3_0;
15
+ }
16
+ else if (kernelVersion === ProviderKernelVersionEnum.V24 ||
17
+ entryPointAddress === ENTRYPOINT_ADDRESS_V06 // v0.6 only supports v2.4
18
+ ) {
19
+ return KERNEL_V2_4;
20
+ }
21
+ else {
22
+ logger.error('Invalid kernel version', kernelVersion);
23
+ return KERNEL_V3_1;
24
+ }
25
+ };
26
+
27
+ export { getKernelVersion };
@@ -1,4 +1,7 @@
1
- export * from './fetchChain';
1
+ export * from './fetchZeroDevChain';
2
2
  export * from './logger';
3
3
  export * from './isZeroDevConnector';
4
4
  export * from './createEcsdaKernelAccountClient';
5
+ export * from './getEntryPoint';
6
+ export * from './getEcdsaValidator';
7
+ export * from './getKernelVersion';
@@ -1,29 +0,0 @@
1
- 'use client'
2
- 'use strict';
3
-
4
- Object.defineProperty(exports, '__esModule', { value: true });
5
-
6
- var _tslib = require('../../_virtual/_tslib.cjs');
7
- var ethereumCore = require('@dynamic-labs/ethereum-core');
8
- var logger = require('./logger.cjs');
9
-
10
- const cachedChainIdKey = 'dynamic_zd_chain_id';
11
- const fetchChain = (projectId) => _tslib.__awaiter(void 0, void 0, void 0, function* () {
12
- try {
13
- const cachedChainId = localStorage.getItem(cachedChainIdKey);
14
- if (cachedChainId) {
15
- return ethereumCore.chainsMap[cachedChainId];
16
- }
17
- const response = yield (yield fetch(`https://prod-api.zerodev.app/projects/${projectId}`)).json();
18
- localStorage.setItem(cachedChainIdKey, response.chainId);
19
- return ethereumCore.chainsMap[response.chainId];
20
- }
21
- catch (err) {
22
- logger.logger.error('Failed to fetch ZeroDev project settings from ZeroDev API ' +
23
- 'This is needed to fetch the chain id so that we know which chain the smart contract is on');
24
- throw err;
25
- }
26
- });
27
-
28
- exports.cachedChainIdKey = cachedChainIdKey;
29
- exports.fetchChain = fetchChain;
@@ -1,24 +0,0 @@
1
- 'use client'
2
- import { __awaiter } from '../../_virtual/_tslib.js';
3
- import { chainsMap } from '@dynamic-labs/ethereum-core';
4
- import { logger } from './logger.js';
5
-
6
- const cachedChainIdKey = 'dynamic_zd_chain_id';
7
- const fetchChain = (projectId) => __awaiter(void 0, void 0, void 0, function* () {
8
- try {
9
- const cachedChainId = localStorage.getItem(cachedChainIdKey);
10
- if (cachedChainId) {
11
- return chainsMap[cachedChainId];
12
- }
13
- const response = yield (yield fetch(`https://prod-api.zerodev.app/projects/${projectId}`)).json();
14
- localStorage.setItem(cachedChainIdKey, response.chainId);
15
- return chainsMap[response.chainId];
16
- }
17
- catch (err) {
18
- logger.error('Failed to fetch ZeroDev project settings from ZeroDev API ' +
19
- 'This is needed to fetch the chain id so that we know which chain the smart contract is on');
20
- throw err;
21
- }
22
- });
23
-
24
- export { cachedChainIdKey, fetchChain };