@dynamic-labs/ethereum-aa 1.0.0-alpha.1 → 1.0.0-alpha.4
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 +43 -0
- package/package.json +8 -7
- package/src/ZeroDevConnector.cjs +126 -35
- package/src/ZeroDevConnector.d.ts +19 -3
- package/src/ZeroDevConnector.js +127 -36
- package/src/index.cjs +2 -0
- package/src/index.d.ts +1 -0
- package/src/index.js +1 -0
- package/src/utils/isGasNotSponsoredError.cjs +10 -0
- package/src/utils/isGasNotSponsoredError.d.ts +1 -0
- package/src/utils/isGasNotSponsoredError.js +6 -0
- package/src/utils/isZeroDevConnector.cjs +7 -0
- package/src/utils/isZeroDevConnector.d.ts +3 -0
- package/src/utils/isZeroDevConnector.js +3 -0
- package/src/utils/logger.cjs +9 -0
- package/src/utils/logger.d.ts +2 -0
- package/src/utils/logger.js +5 -0
package/CHANGELOG.md
CHANGED
|
@@ -1,4 +1,47 @@
|
|
|
1
1
|
|
|
2
|
+
## [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)
|
|
3
|
+
|
|
4
|
+
|
|
5
|
+
### Bug Fixes
|
|
6
|
+
|
|
7
|
+
* update zerodev provider initialization ([#4015](https://github.com/dynamic-labs/DynamicAuth/issues/4015)) ([8faca00](https://github.com/dynamic-labs/DynamicAuth/commit/8faca00d414677adc5fecde451ca01da53fe9641))
|
|
8
|
+
|
|
9
|
+
## [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)
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
### Bug Fixes
|
|
13
|
+
|
|
14
|
+
* fix solflare mobile wallet deep linking ([#3998](https://github.com/dynamic-labs/DynamicAuth/issues/3998)) ([10069ae](https://github.com/dynamic-labs/DynamicAuth/commit/10069ae9ed5d8e1978131f57c3e90680e85d2efb))
|
|
15
|
+
* 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))
|
|
16
|
+
|
|
17
|
+
## [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)
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
### ⚠ BREAKING CHANGES
|
|
21
|
+
|
|
22
|
+
* rename walletsByChain to bridgeChains (#3954)
|
|
23
|
+
|
|
24
|
+
### Features
|
|
25
|
+
|
|
26
|
+
* passkey management and recovery ([#3911](https://github.com/dynamic-labs/DynamicAuth/issues/3911)) ([b692b3a](https://github.com/dynamic-labs/DynamicAuth/commit/b692b3a8697d0ffb441faae97e609b144965695d))
|
|
27
|
+
|
|
28
|
+
|
|
29
|
+
### Bug Fixes
|
|
30
|
+
|
|
31
|
+
* 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))
|
|
32
|
+
* 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))
|
|
33
|
+
* nextjs issues to show transaction modals ([#3964](https://github.com/dynamic-labs/DynamicAuth/issues/3964)) ([9326ac4](https://github.com/dynamic-labs/DynamicAuth/commit/9326ac49394e067ce38b17faff08b4fabf91bb3f))
|
|
34
|
+
* onEmbeddedWalletCreated not being called ([#3975](https://github.com/dynamic-labs/DynamicAuth/issues/3975)) ([035cebe](https://github.com/dynamic-labs/DynamicAuth/commit/035cebe02891048e62c66a7277ed7f43c27e559d))
|
|
35
|
+
* 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))
|
|
36
|
+
* 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))
|
|
37
|
+
* **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))
|
|
38
|
+
* zerodev sign message with ethers ([#3972](https://github.com/dynamic-labs/DynamicAuth/issues/3972)) ([5de3873](https://github.com/dynamic-labs/DynamicAuth/commit/5de3873daa9cbfeef6dd9123b7a319d8e6b412d5))
|
|
39
|
+
* **zerodev:** ensure ECDSAProvider supports sendUserOperation ([#4003](https://github.com/dynamic-labs/DynamicAuth/issues/4003)) ([c8f5886](https://github.com/dynamic-labs/DynamicAuth/commit/c8f58868fcf6912fd11a92940369faf37e3fcdde))
|
|
40
|
+
* **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))
|
|
41
|
+
|
|
42
|
+
|
|
43
|
+
* rename walletsByChain to bridgeChains ([#3954](https://github.com/dynamic-labs/DynamicAuth/issues/3954)) ([a91e8fe](https://github.com/dynamic-labs/DynamicAuth/commit/a91e8fe605694ccd8a00b71aa194c0c5191f156c))
|
|
44
|
+
|
|
2
45
|
## [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
46
|
|
|
4
47
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@dynamic-labs/ethereum-aa",
|
|
3
|
-
"version": "1.0.0-alpha.
|
|
3
|
+
"version": "1.0.0-alpha.4",
|
|
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.
|
|
31
|
-
"@dynamic-labs/
|
|
32
|
-
"@dynamic-labs/
|
|
33
|
-
"@dynamic-labs/
|
|
34
|
-
"@dynamic-labs/
|
|
35
|
-
"@dynamic-labs/wallet-
|
|
30
|
+
"@dynamic-labs/sdk-api": "0.0.311",
|
|
31
|
+
"@dynamic-labs/logger": "1.0.0-alpha.4",
|
|
32
|
+
"@dynamic-labs/types": "1.0.0-alpha.4",
|
|
33
|
+
"@dynamic-labs/utils": "1.0.0-alpha.4",
|
|
34
|
+
"@dynamic-labs/viem-utils": "1.0.0-alpha.4",
|
|
35
|
+
"@dynamic-labs/wallet-book": "1.0.0-alpha.4",
|
|
36
|
+
"@dynamic-labs/wallet-connector-core": "1.0.0-alpha.4"
|
|
36
37
|
},
|
|
37
38
|
"peerDependencies": {
|
|
38
39
|
"viem": "^1.1.0"
|
package/src/ZeroDevConnector.cjs
CHANGED
|
@@ -8,13 +8,20 @@ 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');
|
|
12
|
+
var isGasNotSponsoredError = require('./utils/isGasNotSponsoredError.cjs');
|
|
11
13
|
|
|
12
14
|
class ZeroDevConnector extends walletConnectorCore.WalletConnectorBase {
|
|
15
|
+
get key() {
|
|
16
|
+
return 'zerodev';
|
|
17
|
+
}
|
|
13
18
|
constructor(opts) {
|
|
14
19
|
var _a;
|
|
15
20
|
super(opts);
|
|
16
21
|
this.connectedChain = 'EVM';
|
|
17
22
|
this.supportedChains = ['ETH', 'EVM'];
|
|
23
|
+
this.isGasSponsorshipDisabled = false;
|
|
24
|
+
this.isEmbeddedWallet = true;
|
|
18
25
|
this.name = 'ZeroDev';
|
|
19
26
|
const zeroDevProjectId = (_a = opts.apiProviders.zerodev) === null || _a === void 0 ? void 0 : _a.clientId;
|
|
20
27
|
if (!zeroDevProjectId) {
|
|
@@ -24,34 +31,127 @@ class ZeroDevConnector extends walletConnectorCore.WalletConnectorBase {
|
|
|
24
31
|
this._walletUiUtils = opts.walletUiUtils;
|
|
25
32
|
this.evmNetworks = utils.parseEvmNetworks(opts.evmNetworks);
|
|
26
33
|
}
|
|
34
|
+
getEOAConnector() {
|
|
35
|
+
return this.eoaConnector;
|
|
36
|
+
}
|
|
37
|
+
getAccountAbstractionProvider() {
|
|
38
|
+
return this.zeroDevProvider;
|
|
39
|
+
}
|
|
27
40
|
setEoaConnector(connector) {
|
|
28
41
|
return _tslib.__awaiter(this, void 0, void 0, function* () {
|
|
42
|
+
this.zeroDevProviderDeferredPromise = new utils.DeferredPromise();
|
|
29
43
|
this.eoaConnector = connector;
|
|
30
44
|
const signer = yield this.eoaConnector.getSigner();
|
|
31
|
-
|
|
45
|
+
const zeroDevProvider = yield sdk.ECDSAProvider.init({
|
|
46
|
+
opts: {
|
|
47
|
+
paymasterConfig: {
|
|
48
|
+
onlySendSponsoredTransaction: true,
|
|
49
|
+
policy: 'VERIFYING_PAYMASTER',
|
|
50
|
+
},
|
|
51
|
+
},
|
|
52
|
+
owner: sdk.convertWalletClientToAccountSigner(signer),
|
|
53
|
+
projectId: this.projectId,
|
|
54
|
+
});
|
|
55
|
+
utils.wrapMethodWithCallback(zeroDevProvider, 'sendUserOperation', (original, ...args) => {
|
|
56
|
+
this._walletUiUtils.disabledConfirmationOnce();
|
|
57
|
+
return original(...args);
|
|
58
|
+
});
|
|
59
|
+
this.zeroDevProvider = zeroDevProvider;
|
|
60
|
+
yield this.checkIsProjectChainEnabled();
|
|
61
|
+
this.zeroDevProviderDeferredPromise.resolve();
|
|
62
|
+
});
|
|
63
|
+
}
|
|
64
|
+
checkIsProjectChainEnabled() {
|
|
65
|
+
var _a, _b;
|
|
66
|
+
return _tslib.__awaiter(this, void 0, void 0, function* () {
|
|
67
|
+
const client = yield this.getPublicClient();
|
|
68
|
+
const chainName = (_a = client === null || client === void 0 ? void 0 : client.chain) === null || _a === void 0 ? void 0 : _a.name;
|
|
69
|
+
const chainId = (_b = client === null || client === void 0 ? void 0 : client.chain) === null || _b === void 0 ? void 0 : _b.id;
|
|
70
|
+
const isProjectChainEnabled = this.evmNetworks.some((network) => network.chainId === chainId);
|
|
71
|
+
if (!isProjectChainEnabled) {
|
|
72
|
+
logger.logger.error(`Please make sure to enable ${chainName} (${chainId}) in the Dynamic dashboard (https://app.dynamic.xyz/dashboard/configurations#evm).`);
|
|
73
|
+
}
|
|
74
|
+
});
|
|
75
|
+
}
|
|
76
|
+
getProviderWithoutSponsorship() {
|
|
77
|
+
return _tslib.__awaiter(this, void 0, void 0, function* () {
|
|
78
|
+
const { eoaConnector } = this;
|
|
79
|
+
if (!eoaConnector)
|
|
80
|
+
throw new utils.DynamicError('No EOA connector');
|
|
81
|
+
const signer = yield eoaConnector.getSigner();
|
|
82
|
+
return sdk.ECDSAProvider.init({
|
|
32
83
|
owner: sdk.convertWalletClientToAccountSigner(signer),
|
|
33
84
|
projectId: this.projectId,
|
|
34
85
|
});
|
|
35
86
|
});
|
|
36
87
|
}
|
|
37
88
|
fetchPublicAddress() {
|
|
38
|
-
var _a;
|
|
89
|
+
var _a, _b;
|
|
39
90
|
return _tslib.__awaiter(this, void 0, void 0, function* () {
|
|
40
|
-
|
|
91
|
+
yield ((_a = this.zeroDevProviderDeferredPromise) === null || _a === void 0 ? void 0 : _a.promise);
|
|
92
|
+
return (_b = this.zeroDevProvider) === null || _b === void 0 ? void 0 : _b.getAddress();
|
|
41
93
|
});
|
|
42
94
|
}
|
|
43
95
|
getConnectedAccounts() {
|
|
96
|
+
var _a;
|
|
44
97
|
return _tslib.__awaiter(this, void 0, void 0, function* () {
|
|
98
|
+
yield ((_a = this.zeroDevProviderDeferredPromise) === null || _a === void 0 ? void 0 : _a.promise);
|
|
45
99
|
return this.zeroDevProvider
|
|
46
100
|
? [yield this.zeroDevProvider.getAddress()]
|
|
47
101
|
: [];
|
|
48
102
|
});
|
|
49
103
|
}
|
|
50
104
|
getNetwork() {
|
|
51
|
-
var _a;
|
|
105
|
+
var _a, _b;
|
|
52
106
|
return _tslib.__awaiter(this, void 0, void 0, function* () {
|
|
53
|
-
|
|
107
|
+
yield ((_a = this.zeroDevProviderDeferredPromise) === null || _a === void 0 ? void 0 : _a.promise);
|
|
108
|
+
return (_b = this.zeroDevProvider) === null || _b === void 0 ? void 0 : _b.rpcClient.chain.id;
|
|
109
|
+
});
|
|
110
|
+
}
|
|
111
|
+
getTransport(provider) {
|
|
112
|
+
const transport = viemUtils.confirmationTransport({
|
|
113
|
+
connector: this,
|
|
114
|
+
onPersonalSign: ({ message }) => _tslib.__awaiter(this, void 0, void 0, function* () {
|
|
115
|
+
this._walletUiUtils.disabledConfirmationOnce();
|
|
116
|
+
return provider.signMessage(message);
|
|
117
|
+
}),
|
|
118
|
+
onSendTransaction: ({ transaction }) => _tslib.__awaiter(this, void 0, void 0, function* () {
|
|
119
|
+
try {
|
|
120
|
+
this._walletUiUtils.disabledConfirmationOnce();
|
|
121
|
+
const effectiveProvider = this.isGasSponsorshipDisabled
|
|
122
|
+
? yield this.getProviderWithoutSponsorship()
|
|
123
|
+
: provider;
|
|
124
|
+
const response = yield effectiveProvider.sendTransaction(viemUtils.unFormatTransaction(transaction));
|
|
125
|
+
return response;
|
|
126
|
+
}
|
|
127
|
+
catch (err) {
|
|
128
|
+
logger.logger.error(err);
|
|
129
|
+
if (isGasNotSponsoredError.isGasNotSponsoredError(err)) {
|
|
130
|
+
throw new utils.TransactionGasCannotBeSponsoredError();
|
|
131
|
+
}
|
|
132
|
+
throw err;
|
|
133
|
+
}
|
|
134
|
+
}),
|
|
135
|
+
onSignTypedData: ({ message }) => _tslib.__awaiter(this, void 0, void 0, function* () {
|
|
136
|
+
this._walletUiUtils.disabledConfirmationOnce();
|
|
137
|
+
const signTypedData = JSON.parse(message);
|
|
138
|
+
return provider.signTypedData(signTypedData);
|
|
139
|
+
}),
|
|
140
|
+
provider: provider.rpcClient,
|
|
141
|
+
transport: viem.custom(provider),
|
|
142
|
+
walletUiUtils: this._walletUiUtils,
|
|
143
|
+
});
|
|
144
|
+
return transport;
|
|
145
|
+
}
|
|
146
|
+
getWalletClient() {
|
|
147
|
+
const provider = this.zeroDevProvider;
|
|
148
|
+
if (!provider)
|
|
149
|
+
throw new utils.DynamicError('No provider');
|
|
150
|
+
const transport = this.getTransport(provider);
|
|
151
|
+
const walletClient = viem.createWalletClient({
|
|
152
|
+
transport,
|
|
54
153
|
});
|
|
154
|
+
return walletClient;
|
|
55
155
|
}
|
|
56
156
|
getPublicClient() {
|
|
57
157
|
return _tslib.__awaiter(this, void 0, void 0, function* () {
|
|
@@ -66,25 +166,7 @@ class ZeroDevConnector extends walletConnectorCore.WalletConnectorBase {
|
|
|
66
166
|
const provider = this.zeroDevProvider;
|
|
67
167
|
if (!provider)
|
|
68
168
|
throw new utils.DynamicError('No provider');
|
|
69
|
-
const transport =
|
|
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
|
-
});
|
|
169
|
+
const transport = this.getTransport(provider);
|
|
88
170
|
const address = yield provider.getAddress();
|
|
89
171
|
const walletClient = viem.createWalletClient({
|
|
90
172
|
account: address,
|
|
@@ -93,22 +175,31 @@ class ZeroDevConnector extends walletConnectorCore.WalletConnectorBase {
|
|
|
93
175
|
return walletClient;
|
|
94
176
|
});
|
|
95
177
|
}
|
|
96
|
-
|
|
178
|
+
canSponsorTransactionGas(transaction) {
|
|
97
179
|
var _a;
|
|
98
180
|
return _tslib.__awaiter(this, void 0, void 0, function* () {
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
181
|
+
try {
|
|
182
|
+
const userOperation = {
|
|
183
|
+
data: transaction.data ? transaction.data : '0x',
|
|
184
|
+
target: transaction.to,
|
|
185
|
+
value: viem.isHex(transaction.value)
|
|
186
|
+
? viem.fromHex(transaction.value, 'bigint')
|
|
187
|
+
: transaction.value,
|
|
188
|
+
};
|
|
189
|
+
const result = yield ((_a = this.zeroDevProvider) === null || _a === void 0 ? void 0 : _a.buildUserOperation(userOperation));
|
|
190
|
+
if (!result)
|
|
191
|
+
return false;
|
|
192
|
+
return result.paymasterAndData !== '0x';
|
|
193
|
+
}
|
|
194
|
+
catch (err) {
|
|
195
|
+
logger.logger.error(err);
|
|
108
196
|
return false;
|
|
109
|
-
|
|
197
|
+
}
|
|
110
198
|
});
|
|
111
199
|
}
|
|
200
|
+
disableGasSponsorshipOnce() {
|
|
201
|
+
this.isGasSponsorshipDisabled = true;
|
|
202
|
+
}
|
|
112
203
|
getBalance() {
|
|
113
204
|
var _a;
|
|
114
205
|
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,39 @@ 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
19
|
connectedChain: Chain;
|
|
20
20
|
supportedChains: Chain[];
|
|
21
21
|
evmNetworks: EvmNetwork[];
|
|
22
|
+
private isGasSponsorshipDisabled;
|
|
23
|
+
isEmbeddedWallet: boolean;
|
|
24
|
+
/**
|
|
25
|
+
* Deferred promise that resolves when the ZeroDev provider is set.
|
|
26
|
+
* This is used to make sure that the provider is set before any other method is called.
|
|
27
|
+
* This is needed because the provider is set asynchronously.
|
|
28
|
+
*/
|
|
29
|
+
private zeroDevProviderDeferredPromise;
|
|
22
30
|
name: string;
|
|
31
|
+
get key(): string;
|
|
23
32
|
private _walletUiUtils;
|
|
24
33
|
constructor(opts: ZeroDevConnectorProps);
|
|
34
|
+
getEOAConnector(): WalletConnector | undefined;
|
|
35
|
+
getAccountAbstractionProvider(): ECDSAProvider | undefined;
|
|
25
36
|
setEoaConnector(connector: WalletConnector): Promise<void>;
|
|
37
|
+
private checkIsProjectChainEnabled;
|
|
38
|
+
private getProviderWithoutSponsorship;
|
|
26
39
|
fetchPublicAddress(): Promise<string | undefined>;
|
|
27
40
|
getConnectedAccounts(): Promise<string[]>;
|
|
28
41
|
getNetwork(): Promise<number | undefined>;
|
|
42
|
+
private getTransport;
|
|
43
|
+
getWalletClient(): WalletClient | undefined;
|
|
29
44
|
getPublicClient(): Promise<void | PublicClient | undefined>;
|
|
30
45
|
getSigner(): Promise<WalletClient | undefined>;
|
|
31
|
-
|
|
46
|
+
canSponsorTransactionGas(transaction: RpcTransactionRequest): Promise<boolean>;
|
|
47
|
+
disableGasSponsorshipOnce(): void;
|
|
32
48
|
getBalance(): Promise<string | undefined>;
|
|
33
49
|
signMessage(messageToSign: string): Promise<string | undefined>;
|
|
34
50
|
}
|
package/src/ZeroDevConnector.js
CHANGED
|
@@ -3,14 +3,21 @@ 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 } from '@dynamic-labs/utils';
|
|
7
|
+
import { logger } from './utils/logger.js';
|
|
8
|
+
import { isGasNotSponsoredError } from './utils/isGasNotSponsoredError.js';
|
|
7
9
|
|
|
8
10
|
class ZeroDevConnector extends WalletConnectorBase {
|
|
11
|
+
get key() {
|
|
12
|
+
return 'zerodev';
|
|
13
|
+
}
|
|
9
14
|
constructor(opts) {
|
|
10
15
|
var _a;
|
|
11
16
|
super(opts);
|
|
12
17
|
this.connectedChain = 'EVM';
|
|
13
18
|
this.supportedChains = ['ETH', 'EVM'];
|
|
19
|
+
this.isGasSponsorshipDisabled = false;
|
|
20
|
+
this.isEmbeddedWallet = true;
|
|
14
21
|
this.name = 'ZeroDev';
|
|
15
22
|
const zeroDevProjectId = (_a = opts.apiProviders.zerodev) === null || _a === void 0 ? void 0 : _a.clientId;
|
|
16
23
|
if (!zeroDevProjectId) {
|
|
@@ -20,34 +27,127 @@ class ZeroDevConnector extends WalletConnectorBase {
|
|
|
20
27
|
this._walletUiUtils = opts.walletUiUtils;
|
|
21
28
|
this.evmNetworks = parseEvmNetworks(opts.evmNetworks);
|
|
22
29
|
}
|
|
30
|
+
getEOAConnector() {
|
|
31
|
+
return this.eoaConnector;
|
|
32
|
+
}
|
|
33
|
+
getAccountAbstractionProvider() {
|
|
34
|
+
return this.zeroDevProvider;
|
|
35
|
+
}
|
|
23
36
|
setEoaConnector(connector) {
|
|
24
37
|
return __awaiter(this, void 0, void 0, function* () {
|
|
38
|
+
this.zeroDevProviderDeferredPromise = new DeferredPromise();
|
|
25
39
|
this.eoaConnector = connector;
|
|
26
40
|
const signer = yield this.eoaConnector.getSigner();
|
|
27
|
-
|
|
41
|
+
const zeroDevProvider = yield ECDSAProvider.init({
|
|
42
|
+
opts: {
|
|
43
|
+
paymasterConfig: {
|
|
44
|
+
onlySendSponsoredTransaction: true,
|
|
45
|
+
policy: 'VERIFYING_PAYMASTER',
|
|
46
|
+
},
|
|
47
|
+
},
|
|
48
|
+
owner: convertWalletClientToAccountSigner(signer),
|
|
49
|
+
projectId: this.projectId,
|
|
50
|
+
});
|
|
51
|
+
wrapMethodWithCallback(zeroDevProvider, 'sendUserOperation', (original, ...args) => {
|
|
52
|
+
this._walletUiUtils.disabledConfirmationOnce();
|
|
53
|
+
return original(...args);
|
|
54
|
+
});
|
|
55
|
+
this.zeroDevProvider = zeroDevProvider;
|
|
56
|
+
yield this.checkIsProjectChainEnabled();
|
|
57
|
+
this.zeroDevProviderDeferredPromise.resolve();
|
|
58
|
+
});
|
|
59
|
+
}
|
|
60
|
+
checkIsProjectChainEnabled() {
|
|
61
|
+
var _a, _b;
|
|
62
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
63
|
+
const client = yield this.getPublicClient();
|
|
64
|
+
const chainName = (_a = client === null || client === void 0 ? void 0 : client.chain) === null || _a === void 0 ? void 0 : _a.name;
|
|
65
|
+
const chainId = (_b = client === null || client === void 0 ? void 0 : client.chain) === null || _b === void 0 ? void 0 : _b.id;
|
|
66
|
+
const isProjectChainEnabled = this.evmNetworks.some((network) => network.chainId === chainId);
|
|
67
|
+
if (!isProjectChainEnabled) {
|
|
68
|
+
logger.error(`Please make sure to enable ${chainName} (${chainId}) in the Dynamic dashboard (https://app.dynamic.xyz/dashboard/configurations#evm).`);
|
|
69
|
+
}
|
|
70
|
+
});
|
|
71
|
+
}
|
|
72
|
+
getProviderWithoutSponsorship() {
|
|
73
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
74
|
+
const { eoaConnector } = this;
|
|
75
|
+
if (!eoaConnector)
|
|
76
|
+
throw new DynamicError('No EOA connector');
|
|
77
|
+
const signer = yield eoaConnector.getSigner();
|
|
78
|
+
return ECDSAProvider.init({
|
|
28
79
|
owner: convertWalletClientToAccountSigner(signer),
|
|
29
80
|
projectId: this.projectId,
|
|
30
81
|
});
|
|
31
82
|
});
|
|
32
83
|
}
|
|
33
84
|
fetchPublicAddress() {
|
|
34
|
-
var _a;
|
|
85
|
+
var _a, _b;
|
|
35
86
|
return __awaiter(this, void 0, void 0, function* () {
|
|
36
|
-
|
|
87
|
+
yield ((_a = this.zeroDevProviderDeferredPromise) === null || _a === void 0 ? void 0 : _a.promise);
|
|
88
|
+
return (_b = this.zeroDevProvider) === null || _b === void 0 ? void 0 : _b.getAddress();
|
|
37
89
|
});
|
|
38
90
|
}
|
|
39
91
|
getConnectedAccounts() {
|
|
92
|
+
var _a;
|
|
40
93
|
return __awaiter(this, void 0, void 0, function* () {
|
|
94
|
+
yield ((_a = this.zeroDevProviderDeferredPromise) === null || _a === void 0 ? void 0 : _a.promise);
|
|
41
95
|
return this.zeroDevProvider
|
|
42
96
|
? [yield this.zeroDevProvider.getAddress()]
|
|
43
97
|
: [];
|
|
44
98
|
});
|
|
45
99
|
}
|
|
46
100
|
getNetwork() {
|
|
47
|
-
var _a;
|
|
101
|
+
var _a, _b;
|
|
48
102
|
return __awaiter(this, void 0, void 0, function* () {
|
|
49
|
-
|
|
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.rpcClient.chain.id;
|
|
105
|
+
});
|
|
106
|
+
}
|
|
107
|
+
getTransport(provider) {
|
|
108
|
+
const transport = confirmationTransport({
|
|
109
|
+
connector: this,
|
|
110
|
+
onPersonalSign: ({ message }) => __awaiter(this, void 0, void 0, function* () {
|
|
111
|
+
this._walletUiUtils.disabledConfirmationOnce();
|
|
112
|
+
return provider.signMessage(message);
|
|
113
|
+
}),
|
|
114
|
+
onSendTransaction: ({ transaction }) => __awaiter(this, void 0, void 0, function* () {
|
|
115
|
+
try {
|
|
116
|
+
this._walletUiUtils.disabledConfirmationOnce();
|
|
117
|
+
const effectiveProvider = this.isGasSponsorshipDisabled
|
|
118
|
+
? yield this.getProviderWithoutSponsorship()
|
|
119
|
+
: provider;
|
|
120
|
+
const response = yield effectiveProvider.sendTransaction(unFormatTransaction(transaction));
|
|
121
|
+
return response;
|
|
122
|
+
}
|
|
123
|
+
catch (err) {
|
|
124
|
+
logger.error(err);
|
|
125
|
+
if (isGasNotSponsoredError(err)) {
|
|
126
|
+
throw new TransactionGasCannotBeSponsoredError();
|
|
127
|
+
}
|
|
128
|
+
throw err;
|
|
129
|
+
}
|
|
130
|
+
}),
|
|
131
|
+
onSignTypedData: ({ message }) => __awaiter(this, void 0, void 0, function* () {
|
|
132
|
+
this._walletUiUtils.disabledConfirmationOnce();
|
|
133
|
+
const signTypedData = JSON.parse(message);
|
|
134
|
+
return provider.signTypedData(signTypedData);
|
|
135
|
+
}),
|
|
136
|
+
provider: provider.rpcClient,
|
|
137
|
+
transport: custom(provider),
|
|
138
|
+
walletUiUtils: this._walletUiUtils,
|
|
139
|
+
});
|
|
140
|
+
return transport;
|
|
141
|
+
}
|
|
142
|
+
getWalletClient() {
|
|
143
|
+
const provider = this.zeroDevProvider;
|
|
144
|
+
if (!provider)
|
|
145
|
+
throw new DynamicError('No provider');
|
|
146
|
+
const transport = this.getTransport(provider);
|
|
147
|
+
const walletClient = createWalletClient({
|
|
148
|
+
transport,
|
|
50
149
|
});
|
|
150
|
+
return walletClient;
|
|
51
151
|
}
|
|
52
152
|
getPublicClient() {
|
|
53
153
|
return __awaiter(this, void 0, void 0, function* () {
|
|
@@ -62,25 +162,7 @@ class ZeroDevConnector extends WalletConnectorBase {
|
|
|
62
162
|
const provider = this.zeroDevProvider;
|
|
63
163
|
if (!provider)
|
|
64
164
|
throw new DynamicError('No provider');
|
|
65
|
-
const transport =
|
|
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
|
-
});
|
|
165
|
+
const transport = this.getTransport(provider);
|
|
84
166
|
const address = yield provider.getAddress();
|
|
85
167
|
const walletClient = createWalletClient({
|
|
86
168
|
account: address,
|
|
@@ -89,22 +171,31 @@ class ZeroDevConnector extends WalletConnectorBase {
|
|
|
89
171
|
return walletClient;
|
|
90
172
|
});
|
|
91
173
|
}
|
|
92
|
-
|
|
174
|
+
canSponsorTransactionGas(transaction) {
|
|
93
175
|
var _a;
|
|
94
176
|
return __awaiter(this, void 0, void 0, function* () {
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
177
|
+
try {
|
|
178
|
+
const userOperation = {
|
|
179
|
+
data: transaction.data ? transaction.data : '0x',
|
|
180
|
+
target: transaction.to,
|
|
181
|
+
value: isHex(transaction.value)
|
|
182
|
+
? fromHex(transaction.value, 'bigint')
|
|
183
|
+
: transaction.value,
|
|
184
|
+
};
|
|
185
|
+
const result = yield ((_a = this.zeroDevProvider) === null || _a === void 0 ? void 0 : _a.buildUserOperation(userOperation));
|
|
186
|
+
if (!result)
|
|
187
|
+
return false;
|
|
188
|
+
return result.paymasterAndData !== '0x';
|
|
189
|
+
}
|
|
190
|
+
catch (err) {
|
|
191
|
+
logger.error(err);
|
|
104
192
|
return false;
|
|
105
|
-
|
|
193
|
+
}
|
|
106
194
|
});
|
|
107
195
|
}
|
|
196
|
+
disableGasSponsorshipOnce() {
|
|
197
|
+
this.isGasSponsorshipDisabled = true;
|
|
198
|
+
}
|
|
108
199
|
getBalance() {
|
|
109
200
|
var _a;
|
|
110
201
|
return __awaiter(this, void 0, void 0, function* () {
|
package/src/index.cjs
CHANGED
|
@@ -4,6 +4,7 @@ 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
9
|
const EthereumSmartWalletConnectors = (props) => {
|
|
9
10
|
var _a;
|
|
@@ -15,4 +16,5 @@ const EthereumSmartWalletConnectors = (props) => {
|
|
|
15
16
|
};
|
|
16
17
|
|
|
17
18
|
exports.EthereumAaConnector = ethereumAa.EthereumAaConnector;
|
|
19
|
+
exports.isZeroDevConnector = isZeroDevConnector.isZeroDevConnector;
|
|
18
20
|
exports.EthereumSmartWalletConnectors = EthereumSmartWalletConnectors;
|
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 { isZeroDevConnector } from './utils/isZeroDevConnector';
|
|
3
4
|
export declare const EthereumSmartWalletConnectors: (props: any) => WalletConnectorConstructor[];
|
package/src/index.js
CHANGED
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
|
+
|
|
5
|
+
const isGasNotSponsoredError = (err) => {
|
|
6
|
+
var _a;
|
|
7
|
+
return (_a = err === null || err === void 0 ? void 0 : err.message) === null || _a === void 0 ? void 0 : _a.includes('userOp did not match any gas sponsoring policies');
|
|
8
|
+
};
|
|
9
|
+
|
|
10
|
+
exports.isGasNotSponsoredError = isGasNotSponsoredError;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const isGasNotSponsoredError: (err: unknown) => boolean | undefined;
|