@dynamic-labs/ethereum-aa 1.0.0-alpha.1 → 1.0.0-alpha.3
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 +36 -0
- package/package.json +8 -7
- package/src/ZeroDevConnector.cjs +115 -31
- package/src/ZeroDevConnector.d.ts +12 -3
- package/src/ZeroDevConnector.js +116 -32
- 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,40 @@
|
|
|
1
1
|
|
|
2
|
+
## [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)
|
|
3
|
+
|
|
4
|
+
|
|
5
|
+
### Bug Fixes
|
|
6
|
+
|
|
7
|
+
* fix solflare mobile wallet deep linking ([#3998](https://github.com/dynamic-labs/DynamicAuth/issues/3998)) ([10069ae](https://github.com/dynamic-labs/DynamicAuth/commit/10069ae9ed5d8e1978131f57c3e90680e85d2efb))
|
|
8
|
+
* 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))
|
|
9
|
+
|
|
10
|
+
## [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)
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
### ⚠ BREAKING CHANGES
|
|
14
|
+
|
|
15
|
+
* rename walletsByChain to bridgeChains (#3954)
|
|
16
|
+
|
|
17
|
+
### Features
|
|
18
|
+
|
|
19
|
+
* passkey management and recovery ([#3911](https://github.com/dynamic-labs/DynamicAuth/issues/3911)) ([b692b3a](https://github.com/dynamic-labs/DynamicAuth/commit/b692b3a8697d0ffb441faae97e609b144965695d))
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
### Bug Fixes
|
|
23
|
+
|
|
24
|
+
* 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))
|
|
25
|
+
* 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))
|
|
26
|
+
* nextjs issues to show transaction modals ([#3964](https://github.com/dynamic-labs/DynamicAuth/issues/3964)) ([9326ac4](https://github.com/dynamic-labs/DynamicAuth/commit/9326ac49394e067ce38b17faff08b4fabf91bb3f))
|
|
27
|
+
* onEmbeddedWalletCreated not being called ([#3975](https://github.com/dynamic-labs/DynamicAuth/issues/3975)) ([035cebe](https://github.com/dynamic-labs/DynamicAuth/commit/035cebe02891048e62c66a7277ed7f43c27e559d))
|
|
28
|
+
* 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))
|
|
29
|
+
* 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))
|
|
30
|
+
* **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))
|
|
31
|
+
* zerodev sign message with ethers ([#3972](https://github.com/dynamic-labs/DynamicAuth/issues/3972)) ([5de3873](https://github.com/dynamic-labs/DynamicAuth/commit/5de3873daa9cbfeef6dd9123b7a319d8e6b412d5))
|
|
32
|
+
* **zerodev:** ensure ECDSAProvider supports sendUserOperation ([#4003](https://github.com/dynamic-labs/DynamicAuth/issues/4003)) ([c8f5886](https://github.com/dynamic-labs/DynamicAuth/commit/c8f58868fcf6912fd11a92940369faf37e3fcdde))
|
|
33
|
+
* **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))
|
|
34
|
+
|
|
35
|
+
|
|
36
|
+
* rename walletsByChain to bridgeChains ([#3954](https://github.com/dynamic-labs/DynamicAuth/issues/3954)) ([a91e8fe](https://github.com/dynamic-labs/DynamicAuth/commit/a91e8fe605694ccd8a00b71aa194c0c5191f156c))
|
|
37
|
+
|
|
2
38
|
## [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
39
|
|
|
4
40
|
|
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.3",
|
|
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.3",
|
|
32
|
+
"@dynamic-labs/types": "1.0.0-alpha.3",
|
|
33
|
+
"@dynamic-labs/utils": "1.0.0-alpha.3",
|
|
34
|
+
"@dynamic-labs/viem-utils": "1.0.0-alpha.3",
|
|
35
|
+
"@dynamic-labs/wallet-book": "1.0.0-alpha.3",
|
|
36
|
+
"@dynamic-labs/wallet-connector-core": "1.0.0-alpha.3"
|
|
36
37
|
},
|
|
37
38
|
"peerDependencies": {
|
|
38
39
|
"viem": "^1.1.0"
|
package/src/ZeroDevConnector.cjs
CHANGED
|
@@ -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');
|
|
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;
|
|
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,11 +30,53 @@ 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* () {
|
|
29
41
|
this.eoaConnector = connector;
|
|
30
42
|
const signer = yield this.eoaConnector.getSigner();
|
|
31
|
-
|
|
43
|
+
const zeroDevProvider = new sdk.ECDSAProvider({
|
|
44
|
+
opts: {
|
|
45
|
+
paymasterConfig: {
|
|
46
|
+
onlySendSponsoredTransaction: true,
|
|
47
|
+
policy: 'VERIFYING_PAYMASTER',
|
|
48
|
+
},
|
|
49
|
+
},
|
|
50
|
+
owner: sdk.convertWalletClientToAccountSigner(signer),
|
|
51
|
+
projectId: this.projectId,
|
|
52
|
+
});
|
|
53
|
+
utils.wrapMethodWithCallback(zeroDevProvider, 'sendUserOperation', (original, ...args) => {
|
|
54
|
+
this._walletUiUtils.disabledConfirmationOnce();
|
|
55
|
+
return original(...args);
|
|
56
|
+
});
|
|
57
|
+
this.zeroDevProvider = zeroDevProvider;
|
|
58
|
+
yield this.checkIsProjectChainEnabled();
|
|
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
|
+
getProviderWithoutSponsorship() {
|
|
74
|
+
return _tslib.__awaiter(this, void 0, void 0, function* () {
|
|
75
|
+
const { eoaConnector } = this;
|
|
76
|
+
if (!eoaConnector)
|
|
77
|
+
throw new utils.DynamicError('No EOA connector');
|
|
78
|
+
const signer = yield eoaConnector.getSigner();
|
|
79
|
+
return new sdk.ECDSAProvider({
|
|
32
80
|
owner: sdk.convertWalletClientToAccountSigner(signer),
|
|
33
81
|
projectId: this.projectId,
|
|
34
82
|
});
|
|
@@ -53,6 +101,51 @@ class ZeroDevConnector extends walletConnectorCore.WalletConnectorBase {
|
|
|
53
101
|
return (_a = this.zeroDevProvider) === null || _a === void 0 ? void 0 : _a.rpcClient.chain.id;
|
|
54
102
|
});
|
|
55
103
|
}
|
|
104
|
+
getTransport(provider) {
|
|
105
|
+
const transport = viemUtils.confirmationTransport({
|
|
106
|
+
connector: this,
|
|
107
|
+
onPersonalSign: ({ message }) => _tslib.__awaiter(this, void 0, void 0, function* () {
|
|
108
|
+
this._walletUiUtils.disabledConfirmationOnce();
|
|
109
|
+
return provider.signMessage(message);
|
|
110
|
+
}),
|
|
111
|
+
onSendTransaction: ({ transaction }) => _tslib.__awaiter(this, void 0, void 0, function* () {
|
|
112
|
+
try {
|
|
113
|
+
this._walletUiUtils.disabledConfirmationOnce();
|
|
114
|
+
const effectiveProvider = this.isGasSponsorshipDisabled
|
|
115
|
+
? yield this.getProviderWithoutSponsorship()
|
|
116
|
+
: provider;
|
|
117
|
+
const response = yield effectiveProvider.sendTransaction(viemUtils.unFormatTransaction(transaction));
|
|
118
|
+
return response;
|
|
119
|
+
}
|
|
120
|
+
catch (err) {
|
|
121
|
+
logger.logger.error(err);
|
|
122
|
+
if (isGasNotSponsoredError.isGasNotSponsoredError(err)) {
|
|
123
|
+
throw new utils.TransactionGasCannotBeSponsoredError();
|
|
124
|
+
}
|
|
125
|
+
throw err;
|
|
126
|
+
}
|
|
127
|
+
}),
|
|
128
|
+
onSignTypedData: ({ message }) => _tslib.__awaiter(this, void 0, void 0, function* () {
|
|
129
|
+
this._walletUiUtils.disabledConfirmationOnce();
|
|
130
|
+
const signTypedData = JSON.parse(message);
|
|
131
|
+
return provider.signTypedData(signTypedData);
|
|
132
|
+
}),
|
|
133
|
+
provider: provider.rpcClient,
|
|
134
|
+
transport: viem.custom(provider),
|
|
135
|
+
walletUiUtils: this._walletUiUtils,
|
|
136
|
+
});
|
|
137
|
+
return transport;
|
|
138
|
+
}
|
|
139
|
+
getWalletClient() {
|
|
140
|
+
const provider = this.zeroDevProvider;
|
|
141
|
+
if (!provider)
|
|
142
|
+
throw new utils.DynamicError('No provider');
|
|
143
|
+
const transport = this.getTransport(provider);
|
|
144
|
+
const walletClient = viem.createWalletClient({
|
|
145
|
+
transport,
|
|
146
|
+
});
|
|
147
|
+
return walletClient;
|
|
148
|
+
}
|
|
56
149
|
getPublicClient() {
|
|
57
150
|
return _tslib.__awaiter(this, void 0, void 0, function* () {
|
|
58
151
|
const provider = this.zeroDevProvider;
|
|
@@ -66,25 +159,7 @@ class ZeroDevConnector extends walletConnectorCore.WalletConnectorBase {
|
|
|
66
159
|
const provider = this.zeroDevProvider;
|
|
67
160
|
if (!provider)
|
|
68
161
|
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
|
-
});
|
|
162
|
+
const transport = this.getTransport(provider);
|
|
88
163
|
const address = yield provider.getAddress();
|
|
89
164
|
const walletClient = viem.createWalletClient({
|
|
90
165
|
account: address,
|
|
@@ -93,22 +168,31 @@ class ZeroDevConnector extends walletConnectorCore.WalletConnectorBase {
|
|
|
93
168
|
return walletClient;
|
|
94
169
|
});
|
|
95
170
|
}
|
|
96
|
-
|
|
171
|
+
canSponsorTransactionGas(transaction) {
|
|
97
172
|
var _a;
|
|
98
173
|
return _tslib.__awaiter(this, void 0, void 0, function* () {
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
174
|
+
try {
|
|
175
|
+
const userOperation = {
|
|
176
|
+
data: transaction.data ? transaction.data : '0x',
|
|
177
|
+
target: transaction.to,
|
|
178
|
+
value: viem.isHex(transaction.value)
|
|
179
|
+
? viem.fromHex(transaction.value, 'bigint')
|
|
180
|
+
: transaction.value,
|
|
181
|
+
};
|
|
182
|
+
const result = yield ((_a = this.zeroDevProvider) === null || _a === void 0 ? void 0 : _a.buildUserOperation(userOperation));
|
|
183
|
+
if (!result)
|
|
184
|
+
return false;
|
|
185
|
+
return result.paymasterAndData !== '0x';
|
|
186
|
+
}
|
|
187
|
+
catch (err) {
|
|
188
|
+
logger.logger.error(err);
|
|
108
189
|
return false;
|
|
109
|
-
|
|
190
|
+
}
|
|
110
191
|
});
|
|
111
192
|
}
|
|
193
|
+
disableGasSponsorshipOnce() {
|
|
194
|
+
this.isGasSponsorshipDisabled = true;
|
|
195
|
+
}
|
|
112
196
|
getBalance() {
|
|
113
197
|
var _a;
|
|
114
198
|
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,32 @@ 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;
|
|
22
23
|
name: string;
|
|
24
|
+
get key(): string;
|
|
23
25
|
private _walletUiUtils;
|
|
24
26
|
constructor(opts: ZeroDevConnectorProps);
|
|
27
|
+
getEOAConnector(): WalletConnector | undefined;
|
|
28
|
+
getAccountAbstractionProvider(): ECDSAProvider | undefined;
|
|
25
29
|
setEoaConnector(connector: WalletConnector): Promise<void>;
|
|
30
|
+
private checkIsProjectChainEnabled;
|
|
31
|
+
private getProviderWithoutSponsorship;
|
|
26
32
|
fetchPublicAddress(): Promise<string | undefined>;
|
|
27
33
|
getConnectedAccounts(): Promise<string[]>;
|
|
28
34
|
getNetwork(): Promise<number | undefined>;
|
|
35
|
+
private getTransport;
|
|
36
|
+
getWalletClient(): WalletClient | undefined;
|
|
29
37
|
getPublicClient(): Promise<void | PublicClient | undefined>;
|
|
30
38
|
getSigner(): Promise<WalletClient | undefined>;
|
|
31
|
-
|
|
39
|
+
canSponsorTransactionGas(transaction: RpcTransactionRequest): Promise<boolean>;
|
|
40
|
+
disableGasSponsorshipOnce(): void;
|
|
32
41
|
getBalance(): Promise<string | undefined>;
|
|
33
42
|
signMessage(messageToSign: string): Promise<string | undefined>;
|
|
34
43
|
}
|
package/src/ZeroDevConnector.js
CHANGED
|
@@ -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, 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;
|
|
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,11 +26,53 @@ 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* () {
|
|
25
37
|
this.eoaConnector = connector;
|
|
26
38
|
const signer = yield this.eoaConnector.getSigner();
|
|
27
|
-
|
|
39
|
+
const zeroDevProvider = new ECDSAProvider({
|
|
40
|
+
opts: {
|
|
41
|
+
paymasterConfig: {
|
|
42
|
+
onlySendSponsoredTransaction: true,
|
|
43
|
+
policy: 'VERIFYING_PAYMASTER',
|
|
44
|
+
},
|
|
45
|
+
},
|
|
46
|
+
owner: convertWalletClientToAccountSigner(signer),
|
|
47
|
+
projectId: this.projectId,
|
|
48
|
+
});
|
|
49
|
+
wrapMethodWithCallback(zeroDevProvider, 'sendUserOperation', (original, ...args) => {
|
|
50
|
+
this._walletUiUtils.disabledConfirmationOnce();
|
|
51
|
+
return original(...args);
|
|
52
|
+
});
|
|
53
|
+
this.zeroDevProvider = zeroDevProvider;
|
|
54
|
+
yield this.checkIsProjectChainEnabled();
|
|
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
|
+
getProviderWithoutSponsorship() {
|
|
70
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
71
|
+
const { eoaConnector } = this;
|
|
72
|
+
if (!eoaConnector)
|
|
73
|
+
throw new DynamicError('No EOA connector');
|
|
74
|
+
const signer = yield eoaConnector.getSigner();
|
|
75
|
+
return new ECDSAProvider({
|
|
28
76
|
owner: convertWalletClientToAccountSigner(signer),
|
|
29
77
|
projectId: this.projectId,
|
|
30
78
|
});
|
|
@@ -49,6 +97,51 @@ class ZeroDevConnector extends WalletConnectorBase {
|
|
|
49
97
|
return (_a = this.zeroDevProvider) === null || _a === void 0 ? void 0 : _a.rpcClient.chain.id;
|
|
50
98
|
});
|
|
51
99
|
}
|
|
100
|
+
getTransport(provider) {
|
|
101
|
+
const transport = confirmationTransport({
|
|
102
|
+
connector: this,
|
|
103
|
+
onPersonalSign: ({ message }) => __awaiter(this, void 0, void 0, function* () {
|
|
104
|
+
this._walletUiUtils.disabledConfirmationOnce();
|
|
105
|
+
return provider.signMessage(message);
|
|
106
|
+
}),
|
|
107
|
+
onSendTransaction: ({ transaction }) => __awaiter(this, void 0, void 0, function* () {
|
|
108
|
+
try {
|
|
109
|
+
this._walletUiUtils.disabledConfirmationOnce();
|
|
110
|
+
const effectiveProvider = this.isGasSponsorshipDisabled
|
|
111
|
+
? yield this.getProviderWithoutSponsorship()
|
|
112
|
+
: provider;
|
|
113
|
+
const response = yield effectiveProvider.sendTransaction(unFormatTransaction(transaction));
|
|
114
|
+
return response;
|
|
115
|
+
}
|
|
116
|
+
catch (err) {
|
|
117
|
+
logger.error(err);
|
|
118
|
+
if (isGasNotSponsoredError(err)) {
|
|
119
|
+
throw new TransactionGasCannotBeSponsoredError();
|
|
120
|
+
}
|
|
121
|
+
throw err;
|
|
122
|
+
}
|
|
123
|
+
}),
|
|
124
|
+
onSignTypedData: ({ message }) => __awaiter(this, void 0, void 0, function* () {
|
|
125
|
+
this._walletUiUtils.disabledConfirmationOnce();
|
|
126
|
+
const signTypedData = JSON.parse(message);
|
|
127
|
+
return provider.signTypedData(signTypedData);
|
|
128
|
+
}),
|
|
129
|
+
provider: provider.rpcClient,
|
|
130
|
+
transport: custom(provider),
|
|
131
|
+
walletUiUtils: this._walletUiUtils,
|
|
132
|
+
});
|
|
133
|
+
return transport;
|
|
134
|
+
}
|
|
135
|
+
getWalletClient() {
|
|
136
|
+
const provider = this.zeroDevProvider;
|
|
137
|
+
if (!provider)
|
|
138
|
+
throw new DynamicError('No provider');
|
|
139
|
+
const transport = this.getTransport(provider);
|
|
140
|
+
const walletClient = createWalletClient({
|
|
141
|
+
transport,
|
|
142
|
+
});
|
|
143
|
+
return walletClient;
|
|
144
|
+
}
|
|
52
145
|
getPublicClient() {
|
|
53
146
|
return __awaiter(this, void 0, void 0, function* () {
|
|
54
147
|
const provider = this.zeroDevProvider;
|
|
@@ -62,25 +155,7 @@ class ZeroDevConnector extends WalletConnectorBase {
|
|
|
62
155
|
const provider = this.zeroDevProvider;
|
|
63
156
|
if (!provider)
|
|
64
157
|
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
|
-
});
|
|
158
|
+
const transport = this.getTransport(provider);
|
|
84
159
|
const address = yield provider.getAddress();
|
|
85
160
|
const walletClient = createWalletClient({
|
|
86
161
|
account: address,
|
|
@@ -89,22 +164,31 @@ class ZeroDevConnector extends WalletConnectorBase {
|
|
|
89
164
|
return walletClient;
|
|
90
165
|
});
|
|
91
166
|
}
|
|
92
|
-
|
|
167
|
+
canSponsorTransactionGas(transaction) {
|
|
93
168
|
var _a;
|
|
94
169
|
return __awaiter(this, void 0, void 0, function* () {
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
170
|
+
try {
|
|
171
|
+
const userOperation = {
|
|
172
|
+
data: transaction.data ? transaction.data : '0x',
|
|
173
|
+
target: transaction.to,
|
|
174
|
+
value: isHex(transaction.value)
|
|
175
|
+
? fromHex(transaction.value, 'bigint')
|
|
176
|
+
: transaction.value,
|
|
177
|
+
};
|
|
178
|
+
const result = yield ((_a = this.zeroDevProvider) === null || _a === void 0 ? void 0 : _a.buildUserOperation(userOperation));
|
|
179
|
+
if (!result)
|
|
180
|
+
return false;
|
|
181
|
+
return result.paymasterAndData !== '0x';
|
|
182
|
+
}
|
|
183
|
+
catch (err) {
|
|
184
|
+
logger.error(err);
|
|
104
185
|
return false;
|
|
105
|
-
|
|
186
|
+
}
|
|
106
187
|
});
|
|
107
188
|
}
|
|
189
|
+
disableGasSponsorshipOnce() {
|
|
190
|
+
this.isGasSponsorshipDisabled = true;
|
|
191
|
+
}
|
|
108
192
|
getBalance() {
|
|
109
193
|
var _a;
|
|
110
194
|
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;
|