@dynamic-labs/ethereum-aa 1.0.0-alpha.1 → 1.0.0-alpha.10

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,132 @@
1
1
 
2
+ ## [1.0.0-alpha.10](https://github.com/dynamic-labs/DynamicAuth/compare/v1.0.0-alpha.9...v1.0.0-alpha.10) (2023-12-08)
3
+
4
+
5
+ ### Bug Fixes
6
+
7
+ * allow transaction error to read from viem error ([#4101](https://github.com/dynamic-labs/DynamicAuth/issues/4101)) ([0f46cbe](https://github.com/dynamic-labs/DynamicAuth/commit/0f46cbea1eb260c2efdeee9b62f669fb3cf4ab93))
8
+ * trigger claim flow for unclaimed embedded smart contract wallet signer ([#4108](https://github.com/dynamic-labs/DynamicAuth/issues/4108)) ([37c9013](https://github.com/dynamic-labs/DynamicAuth/commit/37c9013109f2d6a37bde041da9072c5f5fa2df67))
9
+ * WalletConnect v2 connector with non active chains ([#4085](https://github.com/dynamic-labs/DynamicAuth/issues/4085)) ([f69cbe9](https://github.com/dynamic-labs/DynamicAuth/commit/f69cbe96012563f71e89939c96f2a46926e7b394))
10
+
11
+ ## [1.0.0-alpha.9](https://github.com/dynamic-labs/DynamicAuth/compare/v1.0.0-alpha.8...v1.0.0-alpha.9) (2023-12-07)
12
+
13
+
14
+ ### ⚠ BREAKING CHANGES
15
+
16
+ * how to migrate
17
+ Whenever you would use the property wallets from the object returned by useDynamicContext, you must now rename it to walletConnectorOptions.
18
+
19
+ ### Features
20
+
21
+ * add support for eip6963 ([#4064](https://github.com/dynamic-labs/DynamicAuth/issues/4064)) ([3f8cf0e](https://github.com/dynamic-labs/DynamicAuth/commit/3f8cf0e4250945f3a331f701d491a308fab5f7b8))
22
+ * allow AA wallets to access owner features ([#4079](https://github.com/dynamic-labs/DynamicAuth/issues/4079)) ([9efc2be](https://github.com/dynamic-labs/DynamicAuth/commit/9efc2bee87ec9193c3682863d72024b3586de724))
23
+ * introduce UserWalletsContext ([#4083](https://github.com/dynamic-labs/DynamicAuth/issues/4083)) ([b9ca7f6](https://github.com/dynamic-labs/DynamicAuth/commit/b9ca7f6b0aff4b3992325b70cc9a903ece445c7f))
24
+
25
+
26
+ ### Bug Fixes
27
+
28
+ * ensure zero dev provider will receive a signer ([#4084](https://github.com/dynamic-labs/DynamicAuth/issues/4084)) ([f02a540](https://github.com/dynamic-labs/DynamicAuth/commit/f02a54036d39bfc5fb0c262f292acf914e4bd653))
29
+ * render recovery section only when turnkey provider is enabled ([#4093](https://github.com/dynamic-labs/DynamicAuth/issues/4093)) ([5f29bd2](https://github.com/dynamic-labs/DynamicAuth/commit/5f29bd23ccca2e307822377be28396edc7ab1fda))
30
+ * reset selected social provider on logout ([#4078](https://github.com/dynamic-labs/DynamicAuth/issues/4078)) ([85dc611](https://github.com/dynamic-labs/DynamicAuth/commit/85dc611d9c0e733bdb9d316b008bdaa35bcc2a91))
31
+
32
+
33
+ * rename wallets > walletConnectorOptions ([#4086](https://github.com/dynamic-labs/DynamicAuth/issues/4086)) ([10a7795](https://github.com/dynamic-labs/DynamicAuth/commit/10a779567e751469a667095726da52d78facbd57))
34
+
35
+ ## [1.0.0-alpha.8](https://github.com/dynamic-labs/DynamicAuth/compare/v1.0.0-alpha.7...v1.0.0-alpha.8) (2023-12-05)
36
+
37
+
38
+ ### ⚠ BREAKING CHANGES
39
+
40
+ * rename EthereumSmartWalletConnectors to ZeroDevSmartWalletConnectors (#4067)
41
+
42
+
43
+ ### Features
44
+
45
+ * add support for pregenerated wallets + securing them ([#3968](https://github.com/dynamic-labs/DynamicAuth/issues/3968)) ([8212b76](https://github.com/dynamic-labs/DynamicAuth/commit/8212b760ba199bd989e0ba2ad3caf97590db4861))
46
+
47
+ ## [1.0.0-alpha.7](https://github.com/dynamic-labs/DynamicAuth/compare/v1.0.0-alpha.6...v1.0.0-alpha.7) (2023-12-05)
48
+
49
+
50
+ ### Features
51
+
52
+ * add support for Turnkey HD wallets and backwards compatiblity for private key wallets ([#4011](https://github.com/dynamic-labs/DynamicAuth/issues/4011)) ([75c5258](https://github.com/dynamic-labs/DynamicAuth/commit/75c5258da494d5d4dfa8b96655303dd9645f2269))
53
+
54
+
55
+ ### Bug Fixes
56
+
57
+ * add close button to wallets list ([#4036](https://github.com/dynamic-labs/DynamicAuth/issues/4036)) ([a2b988b](https://github.com/dynamic-labs/DynamicAuth/commit/a2b988bdfc662af6f85d37a79ed6666c483aa447))
58
+ * add support for embedded wallets in connect-only ([#4041](https://github.com/dynamic-labs/DynamicAuth/issues/4041)) ([ceea635](https://github.com/dynamic-labs/DynamicAuth/commit/ceea635b69e2a0c2636b47fbd30639d69dba7a1c))
59
+ * embedded wallet invalid stored chain breaking network picker ([#4050](https://github.com/dynamic-labs/DynamicAuth/issues/4050)) ([2e2384b](https://github.com/dynamic-labs/DynamicAuth/commit/2e2384ba37407d9164cce47e23f5d5f469f7e062))
60
+ * handle insufficient funds from AA provider ([#4027](https://github.com/dynamic-labs/DynamicAuth/issues/4027)) ([6b9cc88](https://github.com/dynamic-labs/DynamicAuth/commit/6b9cc886f4f2590094bd50aba195c07a5532dfa4))
61
+ * prevent double logout caused by wagmi sync ([#4048](https://github.com/dynamic-labs/DynamicAuth/issues/4048)) ([c66c81c](https://github.com/dynamic-labs/DynamicAuth/commit/c66c81c80839aa9ce1cfae76f4afce12e34f3513))
62
+ * properly detect network switch for secondary wallets ([#4038](https://github.com/dynamic-labs/DynamicAuth/issues/4038)) ([f87174d](https://github.com/dynamic-labs/DynamicAuth/commit/f87174de0892dd057401eaf3c0bc68d974add0fc))
63
+ * **use-wallets-connected-state:** update state on wallet id change ([#4045](https://github.com/dynamic-labs/DynamicAuth/issues/4045)) ([ca3a835](https://github.com/dynamic-labs/DynamicAuth/commit/ca3a8359eae386bffa758ed646ac14af8360a7f8))
64
+ * user should be able to see the full passkey name on management view ([#4043](https://github.com/dynamic-labs/DynamicAuth/issues/4043)) ([7bc1b70](https://github.com/dynamic-labs/DynamicAuth/commit/7bc1b7043cbc9f0e21df78a57efc3e6938a99db2))
65
+ * users should be able to easily find passkey recovery ([#4058](https://github.com/dynamic-labs/DynamicAuth/issues/4058)) ([0202ae9](https://github.com/dynamic-labs/DynamicAuth/commit/0202ae98c96544dec5ac357dc77000996e32ad33))
66
+
67
+ ## [1.0.0-alpha.6](https://github.com/dynamic-labs/DynamicAuth/compare/v1.0.0-alpha.5...v1.0.0-alpha.6) (2023-11-29)
68
+
69
+
70
+ ### Bug Fixes
71
+
72
+ * transaction layout show alert ([#4024](https://github.com/dynamic-labs/DynamicAuth/issues/4024)) ([52057f5](https://github.com/dynamic-labs/DynamicAuth/commit/52057f54ebc32464b2486a2328cb6310caf85208)), closes [#4020](https://github.com/dynamic-labs/DynamicAuth/issues/4020)
73
+
74
+ ## [1.0.0-alpha.5](https://github.com/dynamic-labs/DynamicAuth/compare/v1.0.0-alpha.4...v1.0.0-alpha.5) (2023-11-29)
75
+
76
+
77
+ ### Features
78
+
79
+ * gracefully handle uknown wallet ([#3997](https://github.com/dynamic-labs/DynamicAuth/issues/3997)) ([ce7ff6a](https://github.com/dynamic-labs/DynamicAuth/commit/ce7ff6a50a8e8947050734b61587c8cadd041dbe))
80
+
81
+
82
+ ### Bug Fixes
83
+
84
+ * remove total on sponsored transactions ([#4019](https://github.com/dynamic-labs/DynamicAuth/issues/4019)) ([d976678](https://github.com/dynamic-labs/DynamicAuth/commit/d9766787b29665fbcd7983c5d61c31a4d97c8257))
85
+ * send balance align information ([#4020](https://github.com/dynamic-labs/DynamicAuth/issues/4020)) ([508dccf](https://github.com/dynamic-labs/DynamicAuth/commit/508dccfa2c6aeaed30616b6a41b30002cccb3b40))
86
+
87
+ ## [1.0.0-alpha.4](https://github.com/dynamic-labs/DynamicAuth/compare/v1.0.0-alpha.3...v1.0.0-alpha.4) (2023-11-28)
88
+
89
+
90
+ ### Bug Fixes
91
+
92
+ * update zerodev provider initialization ([#4015](https://github.com/dynamic-labs/DynamicAuth/issues/4015)) ([8faca00](https://github.com/dynamic-labs/DynamicAuth/commit/8faca00d414677adc5fecde451ca01da53fe9641))
93
+
94
+ ## [1.0.0-alpha.3](https://github.com/dynamic-labs/DynamicAuth/compare/v1.0.0-alpha.2...v1.0.0-alpha.3) (2023-11-28)
95
+
96
+
97
+ ### Bug Fixes
98
+
99
+ * fix solflare mobile wallet deep linking ([#3998](https://github.com/dynamic-labs/DynamicAuth/issues/3998)) ([10069ae](https://github.com/dynamic-labs/DynamicAuth/commit/10069ae9ed5d8e1978131f57c3e90680e85d2efb))
100
+ * passkey error message when reaching limit of accounts ([#4010](https://github.com/dynamic-labs/DynamicAuth/issues/4010)) ([dabce3b](https://github.com/dynamic-labs/DynamicAuth/commit/dabce3b6ada4bac75903b43d5cb125cfd5619d18))
101
+
102
+ ## [1.0.0-alpha.2](https://github.com/dynamic-labs/DynamicAuth/compare/v1.0.0-alpha.1...v1.0.0-alpha.2) (2023-11-28)
103
+
104
+
105
+ ### ⚠ BREAKING CHANGES
106
+
107
+ * rename walletsByChain to bridgeChains (#3954)
108
+
109
+ ### Features
110
+
111
+ * passkey management and recovery ([#3911](https://github.com/dynamic-labs/DynamicAuth/issues/3911)) ([b692b3a](https://github.com/dynamic-labs/DynamicAuth/commit/b692b3a8697d0ffb441faae97e609b144965695d))
112
+
113
+
114
+ ### Bug Fixes
115
+
116
+ * ensure all chain rpc providers are always assigned correctly ([#3981](https://github.com/dynamic-labs/DynamicAuth/issues/3981)) ([cd2e25c](https://github.com/dynamic-labs/DynamicAuth/commit/cd2e25c4eb39791866c1ea283d61fff388cce5df))
117
+ * initialize selected chain with first evm network if no value in ls ([#3999](https://github.com/dynamic-labs/DynamicAuth/issues/3999)) ([bc9e43b](https://github.com/dynamic-labs/DynamicAuth/commit/bc9e43be9d33c75bb1236756589f63f17b230ab1))
118
+ * nextjs issues to show transaction modals ([#3964](https://github.com/dynamic-labs/DynamicAuth/issues/3964)) ([9326ac4](https://github.com/dynamic-labs/DynamicAuth/commit/9326ac49394e067ce38b17faff08b4fabf91bb3f))
119
+ * onEmbeddedWalletCreated not being called ([#3975](https://github.com/dynamic-labs/DynamicAuth/issues/3975)) ([035cebe](https://github.com/dynamic-labs/DynamicAuth/commit/035cebe02891048e62c66a7277ed7f43c27e559d))
120
+ * return linked wallets even when there's no primary wallet ([#3965](https://github.com/dynamic-labs/DynamicAuth/issues/3965)) ([27705de](https://github.com/dynamic-labs/DynamicAuth/commit/27705de4ac7e1584efd1245bb9c6a818b1c20742))
121
+ * transaction modal not throwing viem compatible exception ([#3971](https://github.com/dynamic-labs/DynamicAuth/issues/3971)) ([bedab0c](https://github.com/dynamic-labs/DynamicAuth/commit/bedab0c4448bcca5c3e696ceb276867ce55bbd85))
122
+ * **zero-dev:** ensure the sign typed data is parsed for zero dev to handle ([#3974](https://github.com/dynamic-labs/DynamicAuth/issues/3974)) ([f517738](https://github.com/dynamic-labs/DynamicAuth/commit/f517738e1abc138f882525c128cd1ee5e88b9050))
123
+ * zerodev sign message with ethers ([#3972](https://github.com/dynamic-labs/DynamicAuth/issues/3972)) ([5de3873](https://github.com/dynamic-labs/DynamicAuth/commit/5de3873daa9cbfeef6dd9123b7a319d8e6b412d5))
124
+ * **zerodev:** ensure ECDSAProvider supports sendUserOperation ([#4003](https://github.com/dynamic-labs/DynamicAuth/issues/4003)) ([c8f5886](https://github.com/dynamic-labs/DynamicAuth/commit/c8f58868fcf6912fd11a92940369faf37e3fcdde))
125
+ * **zerodev:** ensure transaction is sponsored before submission ([#3932](https://github.com/dynamic-labs/DynamicAuth/issues/3932)) ([74becb7](https://github.com/dynamic-labs/DynamicAuth/commit/74becb7ec2fd55f8b905a9c9f0bbba44a9d22513))
126
+
127
+
128
+ * rename walletsByChain to bridgeChains ([#3954](https://github.com/dynamic-labs/DynamicAuth/issues/3954)) ([a91e8fe](https://github.com/dynamic-labs/DynamicAuth/commit/a91e8fe605694ccd8a00b71aa194c0c5191f156c))
129
+
2
130
  ## [1.0.0-alpha.1](https://github.com/dynamic-labs/DynamicAuth/compare/v1.0.0-alpha.0...v1.0.0-alpha.1) (2023-11-22)
3
131
 
4
132
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dynamic-labs/ethereum-aa",
3
- "version": "1.0.0-alpha.1",
3
+ "version": "1.0.0-alpha.10",
4
4
  "repository": {
5
5
  "type": "git",
6
6
  "url": "https://github.com/dynamic-labs/DynamicAuth.git",
@@ -27,12 +27,13 @@
27
27
  },
28
28
  "dependencies": {
29
29
  "@zerodev/sdk": "^4.1.5",
30
- "@dynamic-labs/sdk-api": "0.0.307",
31
- "@dynamic-labs/types": "1.0.0-alpha.1",
32
- "@dynamic-labs/utils": "1.0.0-alpha.1",
33
- "@dynamic-labs/viem-utils": "1.0.0-alpha.1",
34
- "@dynamic-labs/wallet-book": "1.0.0-alpha.1",
35
- "@dynamic-labs/wallet-connector-core": "1.0.0-alpha.1"
30
+ "@dynamic-labs/sdk-api": "0.0.315",
31
+ "@dynamic-labs/logger": "1.0.0-alpha.10",
32
+ "@dynamic-labs/types": "1.0.0-alpha.10",
33
+ "@dynamic-labs/utils": "1.0.0-alpha.10",
34
+ "@dynamic-labs/viem-utils": "1.0.0-alpha.10",
35
+ "@dynamic-labs/wallet-book": "1.0.0-alpha.10",
36
+ "@dynamic-labs/wallet-connector-core": "1.0.0-alpha.10"
36
37
  },
37
38
  "peerDependencies": {
38
39
  "viem": "^1.1.0"
@@ -8,13 +8,19 @@ var viem = require('viem');
8
8
  var walletConnectorCore = require('@dynamic-labs/wallet-connector-core');
9
9
  var viemUtils = require('@dynamic-labs/viem-utils');
10
10
  var utils = require('@dynamic-labs/utils');
11
+ var logger = require('./utils/logger.cjs');
11
12
 
12
13
  class ZeroDevConnector extends walletConnectorCore.WalletConnectorBase {
14
+ get key() {
15
+ return 'zerodev';
16
+ }
13
17
  constructor(opts) {
14
18
  var _a;
15
19
  super(opts);
16
20
  this.connectedChain = 'EVM';
17
21
  this.supportedChains = ['ETH', 'EVM'];
22
+ this.isGasSponsorshipDisabled = false;
23
+ this.isEmbeddedWallet = true;
18
24
  this.name = 'ZeroDev';
19
25
  const zeroDevProjectId = (_a = opts.apiProviders.zerodev) === null || _a === void 0 ? void 0 : _a.clientId;
20
26
  if (!zeroDevProjectId) {
@@ -24,34 +30,143 @@ class ZeroDevConnector extends walletConnectorCore.WalletConnectorBase {
24
30
  this._walletUiUtils = opts.walletUiUtils;
25
31
  this.evmNetworks = utils.parseEvmNetworks(opts.evmNetworks);
26
32
  }
33
+ getEOAConnector() {
34
+ return this.eoaConnector;
35
+ }
36
+ getAccountAbstractionProvider() {
37
+ return this.zeroDevProvider;
38
+ }
27
39
  setEoaConnector(connector) {
28
40
  return _tslib.__awaiter(this, void 0, void 0, function* () {
41
+ this.zeroDevProviderDeferredPromise = new utils.DeferredPromise();
29
42
  this.eoaConnector = connector;
30
43
  const signer = yield this.eoaConnector.getSigner();
31
- this.zeroDevProvider = new sdk.ECDSAProvider({
44
+ if (!signer) {
45
+ return;
46
+ }
47
+ const zeroDevProvider = yield sdk.ECDSAProvider.init({
48
+ bundlerProvider: 'STACKUP',
32
49
  owner: sdk.convertWalletClientToAccountSigner(signer),
33
50
  projectId: this.projectId,
34
51
  });
52
+ utils.wrapMethodWithCallback(zeroDevProvider, 'sendUserOperation', (original, ...args) => {
53
+ this._walletUiUtils.disabledConfirmationOnce();
54
+ return original(...args);
55
+ });
56
+ this.zeroDevProvider = zeroDevProvider;
57
+ yield this.checkIsProjectChainEnabled();
58
+ this.zeroDevProviderDeferredPromise.resolve();
59
+ });
60
+ }
61
+ checkIsProjectChainEnabled() {
62
+ var _a, _b;
63
+ return _tslib.__awaiter(this, void 0, void 0, function* () {
64
+ const client = yield this.getPublicClient();
65
+ const chainName = (_a = client === null || client === void 0 ? void 0 : client.chain) === null || _a === void 0 ? void 0 : _a.name;
66
+ const chainId = (_b = client === null || client === void 0 ? void 0 : client.chain) === null || _b === void 0 ? void 0 : _b.id;
67
+ const isProjectChainEnabled = this.evmNetworks.some((network) => network.chainId === chainId);
68
+ if (!isProjectChainEnabled) {
69
+ logger.logger.error(`Please make sure to enable ${chainName} (${chainId}) in the Dynamic dashboard (https://app.dynamic.xyz/dashboard/configurations#evm).`);
70
+ }
71
+ });
72
+ }
73
+ getProviderWithSponsorshipValidation() {
74
+ return _tslib.__awaiter(this, void 0, void 0, function* () {
75
+ if (this.providerWithSponsorship) {
76
+ return this.providerWithSponsorship;
77
+ }
78
+ const { eoaConnector } = this;
79
+ if (!eoaConnector)
80
+ throw new utils.DynamicError('No EOA connector');
81
+ const signer = yield eoaConnector.getSigner();
82
+ this.providerWithSponsorship = yield sdk.ECDSAProvider.init({
83
+ bundlerProvider: 'STACKUP',
84
+ opts: {
85
+ paymasterConfig: {
86
+ onlySendSponsoredTransaction: true,
87
+ policy: 'VERIFYING_PAYMASTER',
88
+ },
89
+ },
90
+ owner: sdk.convertWalletClientToAccountSigner(signer),
91
+ projectId: this.projectId,
92
+ });
93
+ utils.wrapMethodWithCallback(this.providerWithSponsorship, 'sendUserOperation', (original, ...args) => {
94
+ this._walletUiUtils.disabledConfirmationOnce();
95
+ return original(...args);
96
+ });
97
+ return this.providerWithSponsorship;
35
98
  });
36
99
  }
37
100
  fetchPublicAddress() {
38
- var _a;
101
+ var _a, _b;
39
102
  return _tslib.__awaiter(this, void 0, void 0, function* () {
40
- return (_a = this.zeroDevProvider) === null || _a === void 0 ? void 0 : _a.getAddress();
103
+ yield ((_a = this.zeroDevProviderDeferredPromise) === null || _a === void 0 ? void 0 : _a.promise);
104
+ return (_b = this.zeroDevProvider) === null || _b === void 0 ? void 0 : _b.getAddress();
41
105
  });
42
106
  }
43
107
  getConnectedAccounts() {
108
+ var _a;
44
109
  return _tslib.__awaiter(this, void 0, void 0, function* () {
110
+ yield ((_a = this.zeroDevProviderDeferredPromise) === null || _a === void 0 ? void 0 : _a.promise);
45
111
  return this.zeroDevProvider
46
112
  ? [yield this.zeroDevProvider.getAddress()]
47
113
  : [];
48
114
  });
49
115
  }
50
116
  getNetwork() {
51
- var _a;
117
+ var _a, _b;
52
118
  return _tslib.__awaiter(this, void 0, void 0, function* () {
53
- return (_a = this.zeroDevProvider) === null || _a === void 0 ? void 0 : _a.rpcClient.chain.id;
119
+ yield ((_a = this.zeroDevProviderDeferredPromise) === null || _a === void 0 ? void 0 : _a.promise);
120
+ return (_b = this.zeroDevProvider) === null || _b === void 0 ? void 0 : _b.rpcClient.chain.id;
121
+ });
122
+ }
123
+ getTransport(provider) {
124
+ const transport = viemUtils.confirmationTransport({
125
+ connector: this,
126
+ onPersonalSign: ({ message }) => _tslib.__awaiter(this, void 0, void 0, function* () {
127
+ this._walletUiUtils.disabledConfirmationOnce();
128
+ return provider.signMessage(message);
129
+ }),
130
+ onSendTransaction: ({ transaction }) => _tslib.__awaiter(this, void 0, void 0, function* () {
131
+ try {
132
+ this._walletUiUtils.disabledConfirmationOnce();
133
+ const effectiveProvider = this.isGasSponsorshipDisabled
134
+ ? provider
135
+ : yield this.getProviderWithSponsorshipValidation();
136
+ const response = yield effectiveProvider.sendTransaction(viemUtils.unFormatTransaction(transaction));
137
+ return response;
138
+ }
139
+ catch (err) {
140
+ logger.logger.debug(err);
141
+ if (utils.TransactionGasCannotBeSponsoredError.isErrorMessage(err)) {
142
+ throw new utils.TransactionGasCannotBeSponsoredError();
143
+ }
144
+ if (utils.InsufficientFundsError.isErrorMessage(err)) {
145
+ throw new utils.InsufficientFundsError();
146
+ }
147
+ throw err;
148
+ }
149
+ }),
150
+ onSignTypedData: ({ message }) => _tslib.__awaiter(this, void 0, void 0, function* () {
151
+ this._walletUiUtils.disabledConfirmationOnce();
152
+ const signTypedData = JSON.parse(message);
153
+ return provider.signTypedData(signTypedData);
154
+ }),
155
+ provider: provider.rpcClient,
156
+ transport: viem.custom(provider),
157
+ walletUiUtils: this._walletUiUtils,
54
158
  });
159
+ return transport;
160
+ }
161
+ getWalletClient() {
162
+ const provider = this.zeroDevProvider;
163
+ if (!provider)
164
+ throw new utils.DynamicError('No provider');
165
+ const transport = this.getTransport(provider);
166
+ const walletClient = viem.createWalletClient({
167
+ transport,
168
+ });
169
+ return walletClient;
55
170
  }
56
171
  getPublicClient() {
57
172
  return _tslib.__awaiter(this, void 0, void 0, function* () {
@@ -66,25 +181,7 @@ class ZeroDevConnector extends walletConnectorCore.WalletConnectorBase {
66
181
  const provider = this.zeroDevProvider;
67
182
  if (!provider)
68
183
  throw new utils.DynamicError('No provider');
69
- const transport = viemUtils.confirmationTransport({
70
- connector: this,
71
- onPersonalSign: ({ message }) => _tslib.__awaiter(this, void 0, void 0, function* () {
72
- this._walletUiUtils.disabledConfirmationOnce();
73
- return provider.signMessage(message);
74
- }),
75
- onSendTransaction: ({ transaction }) => _tslib.__awaiter(this, void 0, void 0, function* () {
76
- this._walletUiUtils.disabledConfirmationOnce();
77
- const response = yield provider.sendTransaction(viemUtils.unFormatTransaction(transaction));
78
- return response;
79
- }),
80
- onSignTypedData: ({ args }) => _tslib.__awaiter(this, void 0, void 0, function* () {
81
- this._walletUiUtils.disabledConfirmationOnce();
82
- return provider.signTypedData(args);
83
- }),
84
- provider: provider.rpcClient,
85
- transport: viem.custom(provider),
86
- walletUiUtils: this._walletUiUtils,
87
- });
184
+ const transport = this.getTransport(provider);
88
185
  const address = yield provider.getAddress();
89
186
  const walletClient = viem.createWalletClient({
90
187
  account: address,
@@ -93,22 +190,31 @@ class ZeroDevConnector extends walletConnectorCore.WalletConnectorBase {
93
190
  return walletClient;
94
191
  });
95
192
  }
96
- isGasSponsored(transaction) {
193
+ canSponsorTransactionGas(transaction) {
97
194
  var _a;
98
195
  return _tslib.__awaiter(this, void 0, void 0, function* () {
99
- const userOperation = {
100
- data: transaction.data ? transaction.data : '0x',
101
- target: transaction.to,
102
- value: viem.isHex(transaction.value)
103
- ? viem.fromHex(transaction.value, 'bigint')
104
- : transaction.value,
105
- };
106
- const result = yield ((_a = this.zeroDevProvider) === null || _a === void 0 ? void 0 : _a.buildUserOperation(userOperation));
107
- if (!result)
196
+ try {
197
+ const userOperation = {
198
+ data: transaction.data ? transaction.data : '0x',
199
+ target: transaction.to,
200
+ value: viem.isHex(transaction.value)
201
+ ? viem.fromHex(transaction.value, 'bigint')
202
+ : transaction.value,
203
+ };
204
+ const result = yield ((_a = this.zeroDevProvider) === null || _a === void 0 ? void 0 : _a.buildUserOperation(userOperation));
205
+ if (!result)
206
+ return false;
207
+ return result.paymasterAndData !== '0x';
208
+ }
209
+ catch (err) {
210
+ logger.logger.debug(err);
108
211
  return false;
109
- return result.paymasterAndData !== '0x';
212
+ }
110
213
  });
111
214
  }
215
+ disableGasSponsorshipOnce() {
216
+ this.isGasSponsorshipDisabled = true;
217
+ }
112
218
  getBalance() {
113
219
  var _a;
114
220
  return _tslib.__awaiter(this, void 0, void 0, function* () {
@@ -1,7 +1,7 @@
1
1
  import { ECDSAProvider } from '@zerodev/sdk';
2
2
  import { PublicClient, RpcTransactionRequest, WalletClient } from 'viem';
3
3
  import { Provider, ProviderEnum } from '@dynamic-labs/sdk-api';
4
- import { Chain, WalletConnector, WalletConnectorBase } from '@dynamic-labs/wallet-connector-core';
4
+ import { Chain, IAccountAbstractionWalletConnector, WalletConnector, WalletConnectorBase } from '@dynamic-labs/wallet-connector-core';
5
5
  import { WalletBookSchema } from '@dynamic-labs/wallet-book';
6
6
  import { EvmNetwork, GenericNetwork, WalletUiUtils } from '@dynamic-labs/types';
7
7
  type ZeroDevConnectorProps = {
@@ -12,23 +12,40 @@ type ZeroDevConnectorProps = {
12
12
  walletBook: WalletBookSchema;
13
13
  walletUiUtils: WalletUiUtils<WalletConnector>;
14
14
  };
15
- export declare class ZeroDevConnector extends WalletConnectorBase {
15
+ export declare class ZeroDevConnector extends WalletConnectorBase implements IAccountAbstractionWalletConnector {
16
16
  projectId: string;
17
17
  zeroDevProvider: ECDSAProvider | undefined;
18
18
  eoaConnector: WalletConnector | undefined;
19
+ private providerWithSponsorship;
19
20
  connectedChain: Chain;
20
21
  supportedChains: Chain[];
21
22
  evmNetworks: EvmNetwork[];
23
+ private isGasSponsorshipDisabled;
24
+ isEmbeddedWallet: boolean;
25
+ /**
26
+ * Deferred promise that resolves when the ZeroDev provider is set.
27
+ * This is used to make sure that the provider is set before any other method is called.
28
+ * This is needed because the provider is set asynchronously.
29
+ */
30
+ private zeroDevProviderDeferredPromise;
22
31
  name: string;
32
+ get key(): string;
23
33
  private _walletUiUtils;
24
34
  constructor(opts: ZeroDevConnectorProps);
35
+ getEOAConnector(): WalletConnector | undefined;
36
+ getAccountAbstractionProvider(): ECDSAProvider | undefined;
25
37
  setEoaConnector(connector: WalletConnector): Promise<void>;
38
+ private checkIsProjectChainEnabled;
39
+ private getProviderWithSponsorshipValidation;
26
40
  fetchPublicAddress(): Promise<string | undefined>;
27
41
  getConnectedAccounts(): Promise<string[]>;
28
42
  getNetwork(): Promise<number | undefined>;
43
+ private getTransport;
44
+ getWalletClient(): WalletClient | undefined;
29
45
  getPublicClient(): Promise<void | PublicClient | undefined>;
30
46
  getSigner(): Promise<WalletClient | undefined>;
31
- isGasSponsored(transaction: RpcTransactionRequest): Promise<boolean>;
47
+ canSponsorTransactionGas(transaction: RpcTransactionRequest): Promise<boolean>;
48
+ disableGasSponsorshipOnce(): void;
32
49
  getBalance(): Promise<string | undefined>;
33
50
  signMessage(messageToSign: string): Promise<string | undefined>;
34
51
  }
@@ -3,14 +3,20 @@ import { ECDSAProvider, convertWalletClientToAccountSigner } from '@zerodev/sdk'
3
3
  import { custom, createWalletClient, isHex, fromHex, formatEther } from 'viem';
4
4
  import { WalletConnectorBase } from '@dynamic-labs/wallet-connector-core';
5
5
  import { confirmationTransport, unFormatTransaction } from '@dynamic-labs/viem-utils';
6
- import { parseEvmNetworks, DynamicError } from '@dynamic-labs/utils';
6
+ import { parseEvmNetworks, DynamicError, DeferredPromise, wrapMethodWithCallback, TransactionGasCannotBeSponsoredError, InsufficientFundsError } from '@dynamic-labs/utils';
7
+ import { logger } from './utils/logger.js';
7
8
 
8
9
  class ZeroDevConnector extends WalletConnectorBase {
10
+ get key() {
11
+ return 'zerodev';
12
+ }
9
13
  constructor(opts) {
10
14
  var _a;
11
15
  super(opts);
12
16
  this.connectedChain = 'EVM';
13
17
  this.supportedChains = ['ETH', 'EVM'];
18
+ this.isGasSponsorshipDisabled = false;
19
+ this.isEmbeddedWallet = true;
14
20
  this.name = 'ZeroDev';
15
21
  const zeroDevProjectId = (_a = opts.apiProviders.zerodev) === null || _a === void 0 ? void 0 : _a.clientId;
16
22
  if (!zeroDevProjectId) {
@@ -20,34 +26,143 @@ class ZeroDevConnector extends WalletConnectorBase {
20
26
  this._walletUiUtils = opts.walletUiUtils;
21
27
  this.evmNetworks = parseEvmNetworks(opts.evmNetworks);
22
28
  }
29
+ getEOAConnector() {
30
+ return this.eoaConnector;
31
+ }
32
+ getAccountAbstractionProvider() {
33
+ return this.zeroDevProvider;
34
+ }
23
35
  setEoaConnector(connector) {
24
36
  return __awaiter(this, void 0, void 0, function* () {
37
+ this.zeroDevProviderDeferredPromise = new DeferredPromise();
25
38
  this.eoaConnector = connector;
26
39
  const signer = yield this.eoaConnector.getSigner();
27
- this.zeroDevProvider = new ECDSAProvider({
40
+ if (!signer) {
41
+ return;
42
+ }
43
+ const zeroDevProvider = yield ECDSAProvider.init({
44
+ bundlerProvider: 'STACKUP',
28
45
  owner: convertWalletClientToAccountSigner(signer),
29
46
  projectId: this.projectId,
30
47
  });
48
+ wrapMethodWithCallback(zeroDevProvider, 'sendUserOperation', (original, ...args) => {
49
+ this._walletUiUtils.disabledConfirmationOnce();
50
+ return original(...args);
51
+ });
52
+ this.zeroDevProvider = zeroDevProvider;
53
+ yield this.checkIsProjectChainEnabled();
54
+ this.zeroDevProviderDeferredPromise.resolve();
55
+ });
56
+ }
57
+ checkIsProjectChainEnabled() {
58
+ var _a, _b;
59
+ return __awaiter(this, void 0, void 0, function* () {
60
+ const client = yield this.getPublicClient();
61
+ const chainName = (_a = client === null || client === void 0 ? void 0 : client.chain) === null || _a === void 0 ? void 0 : _a.name;
62
+ const chainId = (_b = client === null || client === void 0 ? void 0 : client.chain) === null || _b === void 0 ? void 0 : _b.id;
63
+ const isProjectChainEnabled = this.evmNetworks.some((network) => network.chainId === chainId);
64
+ if (!isProjectChainEnabled) {
65
+ logger.error(`Please make sure to enable ${chainName} (${chainId}) in the Dynamic dashboard (https://app.dynamic.xyz/dashboard/configurations#evm).`);
66
+ }
67
+ });
68
+ }
69
+ getProviderWithSponsorshipValidation() {
70
+ return __awaiter(this, void 0, void 0, function* () {
71
+ if (this.providerWithSponsorship) {
72
+ return this.providerWithSponsorship;
73
+ }
74
+ const { eoaConnector } = this;
75
+ if (!eoaConnector)
76
+ throw new DynamicError('No EOA connector');
77
+ const signer = yield eoaConnector.getSigner();
78
+ this.providerWithSponsorship = yield ECDSAProvider.init({
79
+ bundlerProvider: 'STACKUP',
80
+ opts: {
81
+ paymasterConfig: {
82
+ onlySendSponsoredTransaction: true,
83
+ policy: 'VERIFYING_PAYMASTER',
84
+ },
85
+ },
86
+ owner: convertWalletClientToAccountSigner(signer),
87
+ projectId: this.projectId,
88
+ });
89
+ wrapMethodWithCallback(this.providerWithSponsorship, 'sendUserOperation', (original, ...args) => {
90
+ this._walletUiUtils.disabledConfirmationOnce();
91
+ return original(...args);
92
+ });
93
+ return this.providerWithSponsorship;
31
94
  });
32
95
  }
33
96
  fetchPublicAddress() {
34
- var _a;
97
+ var _a, _b;
35
98
  return __awaiter(this, void 0, void 0, function* () {
36
- return (_a = this.zeroDevProvider) === null || _a === void 0 ? void 0 : _a.getAddress();
99
+ yield ((_a = this.zeroDevProviderDeferredPromise) === null || _a === void 0 ? void 0 : _a.promise);
100
+ return (_b = this.zeroDevProvider) === null || _b === void 0 ? void 0 : _b.getAddress();
37
101
  });
38
102
  }
39
103
  getConnectedAccounts() {
104
+ var _a;
40
105
  return __awaiter(this, void 0, void 0, function* () {
106
+ yield ((_a = this.zeroDevProviderDeferredPromise) === null || _a === void 0 ? void 0 : _a.promise);
41
107
  return this.zeroDevProvider
42
108
  ? [yield this.zeroDevProvider.getAddress()]
43
109
  : [];
44
110
  });
45
111
  }
46
112
  getNetwork() {
47
- var _a;
113
+ var _a, _b;
48
114
  return __awaiter(this, void 0, void 0, function* () {
49
- return (_a = this.zeroDevProvider) === null || _a === void 0 ? void 0 : _a.rpcClient.chain.id;
115
+ yield ((_a = this.zeroDevProviderDeferredPromise) === null || _a === void 0 ? void 0 : _a.promise);
116
+ return (_b = this.zeroDevProvider) === null || _b === void 0 ? void 0 : _b.rpcClient.chain.id;
117
+ });
118
+ }
119
+ getTransport(provider) {
120
+ const transport = confirmationTransport({
121
+ connector: this,
122
+ onPersonalSign: ({ message }) => __awaiter(this, void 0, void 0, function* () {
123
+ this._walletUiUtils.disabledConfirmationOnce();
124
+ return provider.signMessage(message);
125
+ }),
126
+ onSendTransaction: ({ transaction }) => __awaiter(this, void 0, void 0, function* () {
127
+ try {
128
+ this._walletUiUtils.disabledConfirmationOnce();
129
+ const effectiveProvider = this.isGasSponsorshipDisabled
130
+ ? provider
131
+ : yield this.getProviderWithSponsorshipValidation();
132
+ const response = yield effectiveProvider.sendTransaction(unFormatTransaction(transaction));
133
+ return response;
134
+ }
135
+ catch (err) {
136
+ logger.debug(err);
137
+ if (TransactionGasCannotBeSponsoredError.isErrorMessage(err)) {
138
+ throw new TransactionGasCannotBeSponsoredError();
139
+ }
140
+ if (InsufficientFundsError.isErrorMessage(err)) {
141
+ throw new InsufficientFundsError();
142
+ }
143
+ throw err;
144
+ }
145
+ }),
146
+ onSignTypedData: ({ message }) => __awaiter(this, void 0, void 0, function* () {
147
+ this._walletUiUtils.disabledConfirmationOnce();
148
+ const signTypedData = JSON.parse(message);
149
+ return provider.signTypedData(signTypedData);
150
+ }),
151
+ provider: provider.rpcClient,
152
+ transport: custom(provider),
153
+ walletUiUtils: this._walletUiUtils,
50
154
  });
155
+ return transport;
156
+ }
157
+ getWalletClient() {
158
+ const provider = this.zeroDevProvider;
159
+ if (!provider)
160
+ throw new DynamicError('No provider');
161
+ const transport = this.getTransport(provider);
162
+ const walletClient = createWalletClient({
163
+ transport,
164
+ });
165
+ return walletClient;
51
166
  }
52
167
  getPublicClient() {
53
168
  return __awaiter(this, void 0, void 0, function* () {
@@ -62,25 +177,7 @@ class ZeroDevConnector extends WalletConnectorBase {
62
177
  const provider = this.zeroDevProvider;
63
178
  if (!provider)
64
179
  throw new DynamicError('No provider');
65
- const transport = confirmationTransport({
66
- connector: this,
67
- onPersonalSign: ({ message }) => __awaiter(this, void 0, void 0, function* () {
68
- this._walletUiUtils.disabledConfirmationOnce();
69
- return provider.signMessage(message);
70
- }),
71
- onSendTransaction: ({ transaction }) => __awaiter(this, void 0, void 0, function* () {
72
- this._walletUiUtils.disabledConfirmationOnce();
73
- const response = yield provider.sendTransaction(unFormatTransaction(transaction));
74
- return response;
75
- }),
76
- onSignTypedData: ({ args }) => __awaiter(this, void 0, void 0, function* () {
77
- this._walletUiUtils.disabledConfirmationOnce();
78
- return provider.signTypedData(args);
79
- }),
80
- provider: provider.rpcClient,
81
- transport: custom(provider),
82
- walletUiUtils: this._walletUiUtils,
83
- });
180
+ const transport = this.getTransport(provider);
84
181
  const address = yield provider.getAddress();
85
182
  const walletClient = createWalletClient({
86
183
  account: address,
@@ -89,22 +186,31 @@ class ZeroDevConnector extends WalletConnectorBase {
89
186
  return walletClient;
90
187
  });
91
188
  }
92
- isGasSponsored(transaction) {
189
+ canSponsorTransactionGas(transaction) {
93
190
  var _a;
94
191
  return __awaiter(this, void 0, void 0, function* () {
95
- const userOperation = {
96
- data: transaction.data ? transaction.data : '0x',
97
- target: transaction.to,
98
- value: isHex(transaction.value)
99
- ? fromHex(transaction.value, 'bigint')
100
- : transaction.value,
101
- };
102
- const result = yield ((_a = this.zeroDevProvider) === null || _a === void 0 ? void 0 : _a.buildUserOperation(userOperation));
103
- if (!result)
192
+ try {
193
+ const userOperation = {
194
+ data: transaction.data ? transaction.data : '0x',
195
+ target: transaction.to,
196
+ value: isHex(transaction.value)
197
+ ? fromHex(transaction.value, 'bigint')
198
+ : transaction.value,
199
+ };
200
+ const result = yield ((_a = this.zeroDevProvider) === null || _a === void 0 ? void 0 : _a.buildUserOperation(userOperation));
201
+ if (!result)
202
+ return false;
203
+ return result.paymasterAndData !== '0x';
204
+ }
205
+ catch (err) {
206
+ logger.debug(err);
104
207
  return false;
105
- return result.paymasterAndData !== '0x';
208
+ }
106
209
  });
107
210
  }
211
+ disableGasSponsorshipOnce() {
212
+ this.isGasSponsorshipDisabled = true;
213
+ }
108
214
  getBalance() {
109
215
  var _a;
110
216
  return __awaiter(this, void 0, void 0, function* () {
package/src/index.cjs CHANGED
@@ -4,15 +4,16 @@ Object.defineProperty(exports, '__esModule', { value: true });
4
4
 
5
5
  var ZeroDevConnector = require('./ZeroDevConnector.cjs');
6
6
  var ethereumAa = require('./ethereum-aa.cjs');
7
+ var isZeroDevConnector = require('./utils/isZeroDevConnector.cjs');
7
8
 
8
- const EthereumSmartWalletConnectors = (props) => {
9
+ const ZeroDevSmartWalletConnectors = (props) => {
9
10
  var _a;
10
- const connectors = [];
11
11
  if ((_a = props.apiProviders) === null || _a === void 0 ? void 0 : _a.zerodev) {
12
- connectors.push(ZeroDevConnector.ZeroDevConnector);
12
+ return [ZeroDevConnector.ZeroDevConnector];
13
13
  }
14
- return connectors;
14
+ return [];
15
15
  };
16
16
 
17
17
  exports.EthereumAaConnector = ethereumAa.EthereumAaConnector;
18
- exports.EthereumSmartWalletConnectors = EthereumSmartWalletConnectors;
18
+ exports.isZeroDevConnector = isZeroDevConnector.isZeroDevConnector;
19
+ exports.ZeroDevSmartWalletConnectors = ZeroDevSmartWalletConnectors;
package/src/index.d.ts CHANGED
@@ -1,3 +1,4 @@
1
1
  import { WalletConnectorConstructor } from '@dynamic-labs/wallet-connector-core';
2
2
  export * from './ethereum-aa';
3
- export declare const EthereumSmartWalletConnectors: (props: any) => WalletConnectorConstructor[];
3
+ export { isZeroDevConnector } from './utils/isZeroDevConnector';
4
+ export declare const ZeroDevSmartWalletConnectors: (props: any) => WalletConnectorConstructor[];
package/src/index.js CHANGED
@@ -1,13 +1,13 @@
1
1
  import { ZeroDevConnector } from './ZeroDevConnector.js';
2
2
  export { EthereumAaConnector } from './ethereum-aa.js';
3
+ export { isZeroDevConnector } from './utils/isZeroDevConnector.js';
3
4
 
4
- const EthereumSmartWalletConnectors = (props) => {
5
+ const ZeroDevSmartWalletConnectors = (props) => {
5
6
  var _a;
6
- const connectors = [];
7
7
  if ((_a = props.apiProviders) === null || _a === void 0 ? void 0 : _a.zerodev) {
8
- connectors.push(ZeroDevConnector);
8
+ return [ZeroDevConnector];
9
9
  }
10
- return connectors;
10
+ return [];
11
11
  };
12
12
 
13
- export { EthereumSmartWalletConnectors };
13
+ export { ZeroDevSmartWalletConnectors };
@@ -0,0 +1,7 @@
1
+ 'use strict';
2
+
3
+ Object.defineProperty(exports, '__esModule', { value: true });
4
+
5
+ const isZeroDevConnector = (connector) => (connector === null || connector === void 0 ? void 0 : connector.key) === 'zerodev';
6
+
7
+ exports.isZeroDevConnector = isZeroDevConnector;
@@ -0,0 +1,3 @@
1
+ import { WalletConnector } from '@dynamic-labs/wallet-connector-core';
2
+ import { ZeroDevConnector } from '../ZeroDevConnector';
3
+ export declare const isZeroDevConnector: (connector: ZeroDevConnector | WalletConnector) => connector is ZeroDevConnector;
@@ -0,0 +1,3 @@
1
+ const isZeroDevConnector = (connector) => (connector === null || connector === void 0 ? void 0 : connector.key) === 'zerodev';
2
+
3
+ export { isZeroDevConnector };
@@ -0,0 +1,9 @@
1
+ 'use strict';
2
+
3
+ Object.defineProperty(exports, '__esModule', { value: true });
4
+
5
+ var logger$1 = require('@dynamic-labs/logger');
6
+
7
+ const logger = new logger$1.Logger('Ethereum AA', logger$1.LogLevel.INFO);
8
+
9
+ exports.logger = logger;
@@ -0,0 +1,2 @@
1
+ import { Logger } from '@dynamic-labs/logger';
2
+ export declare const logger: Logger;
@@ -0,0 +1,5 @@
1
+ import { Logger, LogLevel } from '@dynamic-labs/logger';
2
+
3
+ const logger = new Logger('Ethereum AA', LogLevel.INFO);
4
+
5
+ export { logger };