@dynamic-labs/ethereum-aa 2.0.0-alpha.2 → 2.0.0-alpha.21
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 +236 -0
- package/package.json +12 -10
- package/src/ZeroDevConnector.cjs +93 -68
- package/src/ZeroDevConnector.d.ts +279 -15
- package/src/ZeroDevConnector.js +95 -70
- package/src/index.cjs +7 -0
- package/src/index.d.ts +4 -0
- package/src/index.js +7 -1
- package/src/utils/fetchChain.cjs +28 -0
- package/src/utils/fetchChain.d.ts +3 -0
- package/src/utils/fetchChain.js +23 -0
- package/src/utils/index.d.ts +3 -0
|
@@ -1,9 +1,11 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
1
|
+
import { KernelAccountClient } from '@zerodev/sdk';
|
|
2
|
+
import { type Provider as BundlerProvider } from '@zerodev/presets';
|
|
3
|
+
import { Account, PublicClient, Transport, WalletClient } from 'viem';
|
|
4
|
+
import { type Chain as ViemChain } from 'viem/chains';
|
|
3
5
|
import { Provider, ProviderEnum } from '@dynamic-labs/sdk-api';
|
|
4
|
-
import { Chain, IAccountAbstractionWalletConnector, WalletConnector, WalletConnectorBase } from '@dynamic-labs/wallet-connector-core';
|
|
6
|
+
import { Chain, IAccountAbstractionWalletConnector, ISendBalanceWalletConnector, WalletConnector, WalletConnectorBase } from '@dynamic-labs/wallet-connector-core';
|
|
5
7
|
import { WalletBookSchema } from '@dynamic-labs/wallet-book';
|
|
6
|
-
import { EvmNetwork, GenericNetwork, WalletUiUtils } from '@dynamic-labs/types';
|
|
8
|
+
import { EvmNetwork, GenericNetwork, IUITransaction, WalletUiUtils } from '@dynamic-labs/types';
|
|
7
9
|
type ZeroDevConnectorProps = {
|
|
8
10
|
apiProviders: {
|
|
9
11
|
[key in ProviderEnum]?: Provider;
|
|
@@ -11,42 +13,304 @@ type ZeroDevConnectorProps = {
|
|
|
11
13
|
evmNetworks: GenericNetwork[];
|
|
12
14
|
walletBook: WalletBookSchema;
|
|
13
15
|
walletUiUtils: WalletUiUtils<WalletConnector>;
|
|
16
|
+
bundlerProvider: BundlerProvider | undefined;
|
|
14
17
|
};
|
|
15
|
-
|
|
18
|
+
type IZeroDevConnector = IAccountAbstractionWalletConnector & ISendBalanceWalletConnector;
|
|
19
|
+
export declare class ZeroDevConnector extends WalletConnectorBase implements IZeroDevConnector {
|
|
16
20
|
projectId: string;
|
|
17
|
-
|
|
21
|
+
kernelClient: KernelAccountClient | undefined;
|
|
18
22
|
eoaConnector: WalletConnector | undefined;
|
|
19
|
-
private
|
|
23
|
+
private kernelClientWithSponsorship;
|
|
20
24
|
connectedChain: Chain;
|
|
21
25
|
supportedChains: Chain[];
|
|
22
26
|
evmNetworks: EvmNetwork[];
|
|
23
27
|
private isGasSponsorshipDisabled;
|
|
24
28
|
isEmbeddedWallet: boolean;
|
|
29
|
+
static bundlerProvider: BundlerProvider | undefined;
|
|
25
30
|
/**
|
|
26
31
|
* Deferred promise that resolves when the ZeroDev provider is set.
|
|
27
32
|
* This is used to make sure that the provider is set before any other method is called.
|
|
28
33
|
* This is needed because the provider is set asynchronously.
|
|
29
34
|
*/
|
|
30
|
-
private
|
|
35
|
+
private kernelClientDeferredPromise;
|
|
31
36
|
name: string;
|
|
32
|
-
|
|
37
|
+
overrideKey: string;
|
|
33
38
|
private _walletUiUtils;
|
|
34
39
|
constructor(opts: ZeroDevConnectorProps);
|
|
35
40
|
getEOAConnector(): WalletConnector | undefined;
|
|
36
|
-
getAccountAbstractionProvider():
|
|
41
|
+
getAccountAbstractionProvider(): KernelAccountClient | undefined;
|
|
42
|
+
endSession(): Promise<void>;
|
|
37
43
|
setEoaConnector(connector: WalletConnector): Promise<void>;
|
|
38
44
|
private checkIsProjectChainEnabled;
|
|
39
|
-
private
|
|
40
|
-
|
|
45
|
+
private getKernelClientWithSponsorshipValidation;
|
|
46
|
+
getAddress(): Promise<string | undefined>;
|
|
41
47
|
getConnectedAccounts(): Promise<string[]>;
|
|
42
48
|
getNetwork(): Promise<number | undefined>;
|
|
43
49
|
private getTransport;
|
|
44
|
-
getWalletClient(): WalletClient | undefined;
|
|
50
|
+
getWalletClient(chainId?: string): WalletClient<Transport, ViemChain> | undefined;
|
|
45
51
|
getPublicClient(): Promise<void | PublicClient | undefined>;
|
|
46
|
-
getSigner(): Promise<
|
|
47
|
-
|
|
52
|
+
getSigner(): Promise<{
|
|
53
|
+
account: Account | undefined;
|
|
54
|
+
batch?: {
|
|
55
|
+
multicall?: boolean | {
|
|
56
|
+
batchSize?: number | undefined;
|
|
57
|
+
wait?: number | undefined;
|
|
58
|
+
} | undefined;
|
|
59
|
+
} | undefined;
|
|
60
|
+
cacheTime: number;
|
|
61
|
+
chain: ViemChain;
|
|
62
|
+
key: string;
|
|
63
|
+
name: string;
|
|
64
|
+
pollingInterval: number;
|
|
65
|
+
request: import("viem").EIP1193RequestFn<import("viem").WalletRpcSchema>;
|
|
66
|
+
transport: import("viem").TransportConfig<string, import("viem").EIP1193RequestFn> & Record<string, any>;
|
|
67
|
+
type: string;
|
|
68
|
+
uid: string;
|
|
69
|
+
addChain: (args: import("viem").AddChainParameters) => Promise<void>;
|
|
70
|
+
deployContract: <const abi extends import("viem").Abi | readonly unknown[], chainOverride extends ViemChain | undefined>(args: import("viem").DeployContractParameters<abi, ViemChain, Account | undefined, chainOverride>) => Promise<`0x${string}`>;
|
|
71
|
+
getAddresses: () => Promise<import("viem").GetAddressesReturnType>;
|
|
72
|
+
getChainId: () => Promise<number>;
|
|
73
|
+
getPermissions: () => Promise<import("viem").GetPermissionsReturnType>;
|
|
74
|
+
prepareTransactionRequest: <TParameterType extends import("viem").PrepareTransactionRequestParameterType, TChainOverride extends ViemChain | undefined = undefined, TAccountOverride extends `0x${string}` | Account | undefined = undefined>(args: import("viem").PrepareTransactionRequestParameters<ViemChain, Account | undefined, TChainOverride, TAccountOverride, TParameterType>) => Promise<import("viem").PrepareTransactionRequestReturnType<ViemChain, Account | undefined, TChainOverride, TAccountOverride, TParameterType>>;
|
|
75
|
+
requestAddresses: () => Promise<import("viem").RequestAddressesReturnType>;
|
|
76
|
+
requestPermissions: (args: {
|
|
77
|
+
[x: string]: Record<string, any>;
|
|
78
|
+
eth_accounts: Record<string, any>;
|
|
79
|
+
}) => Promise<import("viem").RequestPermissionsReturnType>;
|
|
80
|
+
sendRawTransaction: (args: import("viem").SendRawTransactionParameters) => Promise<`0x${string}`>;
|
|
81
|
+
sendTransaction: <TChainOverride_1 extends ViemChain | undefined = undefined>(args: import("viem").SendTransactionParameters<ViemChain, Account | undefined, TChainOverride_1>) => Promise<`0x${string}`>;
|
|
82
|
+
signMessage: (args: import("viem").SignMessageParameters<Account | undefined>) => Promise<`0x${string}`>;
|
|
83
|
+
signTransaction: <TChainOverride_2 extends ViemChain | undefined>(args: import("viem").SignTransactionParameters<ViemChain, Account | undefined, TChainOverride_2>) => Promise<`0x${string}`>;
|
|
84
|
+
signTypedData: <const TTypedData extends {
|
|
85
|
+
[x: string]: readonly import("viem").TypedDataParameter[];
|
|
86
|
+
[x: `string[${string}]`]: undefined;
|
|
87
|
+
[x: `function[${string}]`]: undefined;
|
|
88
|
+
[x: `address[${string}]`]: undefined;
|
|
89
|
+
[x: `bool[${string}]`]: undefined;
|
|
90
|
+
[x: `bytes[${string}]`]: undefined;
|
|
91
|
+
[x: `bytes9[${string}]`]: undefined;
|
|
92
|
+
[x: `bytes1[${string}]`]: undefined;
|
|
93
|
+
[x: `bytes32[${string}]`]: undefined;
|
|
94
|
+
[x: `bytes31[${string}]`]: undefined;
|
|
95
|
+
[x: `bytes30[${string}]`]: undefined;
|
|
96
|
+
[x: `bytes29[${string}]`]: undefined;
|
|
97
|
+
[x: `bytes28[${string}]`]: undefined;
|
|
98
|
+
[x: `bytes27[${string}]`]: undefined;
|
|
99
|
+
[x: `bytes26[${string}]`]: undefined;
|
|
100
|
+
[x: `bytes25[${string}]`]: undefined;
|
|
101
|
+
[x: `bytes24[${string}]`]: undefined;
|
|
102
|
+
[x: `bytes23[${string}]`]: undefined;
|
|
103
|
+
[x: `bytes22[${string}]`]: undefined;
|
|
104
|
+
[x: `bytes21[${string}]`]: undefined;
|
|
105
|
+
[x: `bytes20[${string}]`]: undefined;
|
|
106
|
+
[x: `bytes19[${string}]`]: undefined;
|
|
107
|
+
[x: `bytes2[${string}]`]: undefined;
|
|
108
|
+
[x: `bytes18[${string}]`]: undefined;
|
|
109
|
+
[x: `bytes17[${string}]`]: undefined;
|
|
110
|
+
[x: `bytes16[${string}]`]: undefined;
|
|
111
|
+
[x: `bytes15[${string}]`]: undefined;
|
|
112
|
+
[x: `bytes14[${string}]`]: undefined;
|
|
113
|
+
[x: `bytes13[${string}]`]: undefined;
|
|
114
|
+
[x: `bytes12[${string}]`]: undefined;
|
|
115
|
+
[x: `bytes11[${string}]`]: undefined;
|
|
116
|
+
[x: `bytes10[${string}]`]: undefined;
|
|
117
|
+
[x: `bytes8[${string}]`]: undefined;
|
|
118
|
+
[x: `bytes7[${string}]`]: undefined;
|
|
119
|
+
[x: `bytes6[${string}]`]: undefined;
|
|
120
|
+
[x: `bytes5[${string}]`]: undefined;
|
|
121
|
+
[x: `bytes4[${string}]`]: undefined;
|
|
122
|
+
[x: `bytes3[${string}]`]: undefined;
|
|
123
|
+
[x: `int[${string}]`]: undefined;
|
|
124
|
+
[x: `int40[${string}]`]: undefined;
|
|
125
|
+
[x: `int32[${string}]`]: undefined;
|
|
126
|
+
[x: `int24[${string}]`]: undefined;
|
|
127
|
+
[x: `int16[${string}]`]: undefined;
|
|
128
|
+
[x: `int8[${string}]`]: undefined;
|
|
129
|
+
[x: `int48[${string}]`]: undefined;
|
|
130
|
+
[x: `int56[${string}]`]: undefined;
|
|
131
|
+
[x: `int64[${string}]`]: undefined;
|
|
132
|
+
[x: `int72[${string}]`]: undefined;
|
|
133
|
+
[x: `int80[${string}]`]: undefined;
|
|
134
|
+
[x: `int88[${string}]`]: undefined;
|
|
135
|
+
[x: `int96[${string}]`]: undefined;
|
|
136
|
+
[x: `int104[${string}]`]: undefined;
|
|
137
|
+
[x: `int112[${string}]`]: undefined;
|
|
138
|
+
[x: `int120[${string}]`]: undefined;
|
|
139
|
+
[x: `int128[${string}]`]: undefined;
|
|
140
|
+
[x: `int136[${string}]`]: undefined;
|
|
141
|
+
[x: `int144[${string}]`]: undefined;
|
|
142
|
+
[x: `int152[${string}]`]: undefined;
|
|
143
|
+
[x: `int160[${string}]`]: undefined;
|
|
144
|
+
[x: `int168[${string}]`]: undefined;
|
|
145
|
+
[x: `int176[${string}]`]: undefined;
|
|
146
|
+
[x: `int184[${string}]`]: undefined;
|
|
147
|
+
[x: `int192[${string}]`]: undefined;
|
|
148
|
+
[x: `int200[${string}]`]: undefined;
|
|
149
|
+
[x: `int208[${string}]`]: undefined;
|
|
150
|
+
[x: `int216[${string}]`]: undefined;
|
|
151
|
+
[x: `int224[${string}]`]: undefined;
|
|
152
|
+
[x: `int232[${string}]`]: undefined;
|
|
153
|
+
[x: `int240[${string}]`]: undefined;
|
|
154
|
+
[x: `int248[${string}]`]: undefined;
|
|
155
|
+
[x: `int256[${string}]`]: undefined;
|
|
156
|
+
[x: `uint[${string}]`]: undefined;
|
|
157
|
+
[x: `uint40[${string}]`]: undefined;
|
|
158
|
+
[x: `uint32[${string}]`]: undefined;
|
|
159
|
+
[x: `uint24[${string}]`]: undefined;
|
|
160
|
+
[x: `uint16[${string}]`]: undefined;
|
|
161
|
+
[x: `uint8[${string}]`]: undefined;
|
|
162
|
+
[x: `uint48[${string}]`]: undefined;
|
|
163
|
+
[x: `uint56[${string}]`]: undefined;
|
|
164
|
+
[x: `uint64[${string}]`]: undefined;
|
|
165
|
+
[x: `uint72[${string}]`]: undefined;
|
|
166
|
+
[x: `uint80[${string}]`]: undefined;
|
|
167
|
+
[x: `uint88[${string}]`]: undefined;
|
|
168
|
+
[x: `uint96[${string}]`]: undefined;
|
|
169
|
+
[x: `uint104[${string}]`]: undefined;
|
|
170
|
+
[x: `uint112[${string}]`]: undefined;
|
|
171
|
+
[x: `uint120[${string}]`]: undefined;
|
|
172
|
+
[x: `uint128[${string}]`]: undefined;
|
|
173
|
+
[x: `uint136[${string}]`]: undefined;
|
|
174
|
+
[x: `uint144[${string}]`]: undefined;
|
|
175
|
+
[x: `uint152[${string}]`]: undefined;
|
|
176
|
+
[x: `uint160[${string}]`]: undefined;
|
|
177
|
+
[x: `uint168[${string}]`]: undefined;
|
|
178
|
+
[x: `uint176[${string}]`]: undefined;
|
|
179
|
+
[x: `uint184[${string}]`]: undefined;
|
|
180
|
+
[x: `uint192[${string}]`]: undefined;
|
|
181
|
+
[x: `uint200[${string}]`]: undefined;
|
|
182
|
+
[x: `uint208[${string}]`]: undefined;
|
|
183
|
+
[x: `uint216[${string}]`]: undefined;
|
|
184
|
+
[x: `uint224[${string}]`]: undefined;
|
|
185
|
+
[x: `uint232[${string}]`]: undefined;
|
|
186
|
+
[x: `uint240[${string}]`]: undefined;
|
|
187
|
+
[x: `uint248[${string}]`]: undefined;
|
|
188
|
+
[x: `uint256[${string}]`]: undefined;
|
|
189
|
+
string?: undefined;
|
|
190
|
+
address?: undefined;
|
|
191
|
+
bool?: undefined;
|
|
192
|
+
bytes?: undefined;
|
|
193
|
+
bytes9?: undefined;
|
|
194
|
+
bytes1?: undefined;
|
|
195
|
+
bytes32?: undefined;
|
|
196
|
+
bytes31?: undefined;
|
|
197
|
+
bytes30?: undefined;
|
|
198
|
+
bytes29?: undefined;
|
|
199
|
+
bytes28?: undefined;
|
|
200
|
+
bytes27?: undefined;
|
|
201
|
+
bytes26?: undefined;
|
|
202
|
+
bytes25?: undefined;
|
|
203
|
+
bytes24?: undefined;
|
|
204
|
+
bytes23?: undefined;
|
|
205
|
+
bytes22?: undefined;
|
|
206
|
+
bytes21?: undefined;
|
|
207
|
+
bytes20?: undefined;
|
|
208
|
+
bytes19?: undefined;
|
|
209
|
+
bytes2?: undefined;
|
|
210
|
+
bytes18?: undefined;
|
|
211
|
+
bytes17?: undefined;
|
|
212
|
+
bytes16?: undefined;
|
|
213
|
+
bytes15?: undefined;
|
|
214
|
+
bytes14?: undefined;
|
|
215
|
+
bytes13?: undefined;
|
|
216
|
+
bytes12?: undefined;
|
|
217
|
+
bytes11?: undefined;
|
|
218
|
+
bytes10?: undefined;
|
|
219
|
+
bytes8?: undefined;
|
|
220
|
+
bytes7?: undefined;
|
|
221
|
+
bytes6?: undefined;
|
|
222
|
+
bytes5?: undefined;
|
|
223
|
+
bytes4?: undefined;
|
|
224
|
+
bytes3?: undefined;
|
|
225
|
+
int40?: undefined;
|
|
226
|
+
int32?: undefined;
|
|
227
|
+
int24?: undefined;
|
|
228
|
+
int16?: undefined;
|
|
229
|
+
int8?: undefined;
|
|
230
|
+
int48?: undefined;
|
|
231
|
+
int56?: undefined;
|
|
232
|
+
int64?: undefined;
|
|
233
|
+
int72?: undefined;
|
|
234
|
+
int80?: undefined;
|
|
235
|
+
int88?: undefined;
|
|
236
|
+
int96?: undefined;
|
|
237
|
+
int104?: undefined;
|
|
238
|
+
int112?: undefined;
|
|
239
|
+
int120?: undefined;
|
|
240
|
+
int128?: undefined;
|
|
241
|
+
int136?: undefined;
|
|
242
|
+
int144?: undefined;
|
|
243
|
+
int152?: undefined;
|
|
244
|
+
int160?: undefined;
|
|
245
|
+
int168?: undefined;
|
|
246
|
+
int176?: undefined;
|
|
247
|
+
int184?: undefined;
|
|
248
|
+
int192?: undefined;
|
|
249
|
+
int200?: undefined;
|
|
250
|
+
int208?: undefined;
|
|
251
|
+
int216?: undefined;
|
|
252
|
+
int224?: undefined;
|
|
253
|
+
int232?: undefined;
|
|
254
|
+
int240?: undefined;
|
|
255
|
+
int248?: undefined;
|
|
256
|
+
int256?: undefined;
|
|
257
|
+
uint40?: undefined;
|
|
258
|
+
uint32?: undefined;
|
|
259
|
+
uint24?: undefined;
|
|
260
|
+
uint16?: undefined;
|
|
261
|
+
uint8?: undefined;
|
|
262
|
+
uint48?: undefined;
|
|
263
|
+
uint56?: undefined;
|
|
264
|
+
uint64?: undefined;
|
|
265
|
+
uint72?: undefined;
|
|
266
|
+
uint80?: undefined;
|
|
267
|
+
uint88?: undefined;
|
|
268
|
+
uint96?: undefined;
|
|
269
|
+
uint104?: undefined;
|
|
270
|
+
uint112?: undefined;
|
|
271
|
+
uint120?: undefined;
|
|
272
|
+
uint128?: undefined;
|
|
273
|
+
uint136?: undefined;
|
|
274
|
+
uint144?: undefined;
|
|
275
|
+
uint152?: undefined;
|
|
276
|
+
uint160?: undefined;
|
|
277
|
+
uint168?: undefined;
|
|
278
|
+
uint176?: undefined;
|
|
279
|
+
uint184?: undefined;
|
|
280
|
+
uint192?: undefined;
|
|
281
|
+
uint200?: undefined;
|
|
282
|
+
uint208?: undefined;
|
|
283
|
+
uint216?: undefined;
|
|
284
|
+
uint224?: undefined;
|
|
285
|
+
uint232?: undefined;
|
|
286
|
+
uint240?: undefined;
|
|
287
|
+
uint248?: undefined;
|
|
288
|
+
uint256?: undefined;
|
|
289
|
+
} | {
|
|
290
|
+
[key: string]: unknown;
|
|
291
|
+
}, TPrimaryType extends string>(args: import("viem").SignTypedDataParameters<TTypedData, TPrimaryType, Account | undefined>) => Promise<`0x${string}`>;
|
|
292
|
+
switchChain: (args: import("viem").SwitchChainParameters) => Promise<void>;
|
|
293
|
+
watchAsset: (args: import("viem").WatchAssetParams) => Promise<boolean>;
|
|
294
|
+
writeContract: <const abi_1 extends import("viem").Abi | readonly unknown[], functionName extends import("viem").ContractFunctionName<abi_1, "nonpayable" | "payable">, args extends import("viem").ContractFunctionArgs<abi_1, "pure" | "view", functionName>, TChainOverride_3 extends ViemChain | undefined = undefined>(args: import("viem").WriteContractParameters<abi_1, functionName, args, ViemChain, Account | undefined, TChainOverride_3>) => Promise<`0x${string}`>;
|
|
295
|
+
extend: <const client extends {
|
|
296
|
+
[x: string]: unknown;
|
|
297
|
+
account?: undefined;
|
|
298
|
+
batch?: undefined;
|
|
299
|
+
cacheTime?: undefined;
|
|
300
|
+
chain?: undefined;
|
|
301
|
+
key?: undefined;
|
|
302
|
+
name?: undefined;
|
|
303
|
+
pollingInterval?: undefined;
|
|
304
|
+
request?: undefined;
|
|
305
|
+
transport?: undefined;
|
|
306
|
+
type?: undefined;
|
|
307
|
+
uid?: undefined;
|
|
308
|
+
} & Partial<Pick<import("viem").PublicActions<Transport, ViemChain, Account | undefined>, "call" | "createContractEventFilter" | "createEventFilter" | "estimateContractGas" | "estimateGas" | "getBlock" | "getBlockNumber" | "getChainId" | "getContractEvents" | "getEnsText" | "getFilterChanges" | "getGasPrice" | "getLogs" | "getTransaction" | "getTransactionCount" | "getTransactionReceipt" | "prepareTransactionRequest" | "readContract" | "sendRawTransaction" | "simulateContract" | "uninstallFilter" | "watchBlockNumber" | "watchContractEvent"> & Pick<import("viem").WalletActions<ViemChain, Account | undefined>, "sendTransaction" | "writeContract">>>(fn: (client: import("viem").Client<Transport, ViemChain, Account | undefined, import("viem").WalletRpcSchema, import("viem").WalletActions<ViemChain, Account | undefined>>) => client) => import("viem").Client<Transport, ViemChain, Account | undefined, import("viem").WalletRpcSchema, { [K in keyof client]: client[K]; } & import("viem").WalletActions<ViemChain, Account | undefined>>;
|
|
309
|
+
} | undefined>;
|
|
310
|
+
canSponsorTransactionGas(transaction: IUITransaction): Promise<boolean>;
|
|
48
311
|
disableGasSponsorshipOnce(): void;
|
|
49
312
|
getBalance(): Promise<string | undefined>;
|
|
50
313
|
signMessage(messageToSign: string): Promise<string | undefined>;
|
|
314
|
+
createUiTransaction(from: string): Promise<IUITransaction>;
|
|
51
315
|
}
|
|
52
316
|
export {};
|
package/src/ZeroDevConnector.js
CHANGED
|
@@ -1,15 +1,14 @@
|
|
|
1
1
|
import { __awaiter } from '../_virtual/_tslib.js';
|
|
2
|
-
import {
|
|
3
|
-
import { custom, createWalletClient, isHex, fromHex, formatEther } from 'viem';
|
|
2
|
+
import { createEcdsaKernelAccountClient } from '@zerodev/presets';
|
|
3
|
+
import { publicActions, custom, createWalletClient, isHex, fromHex, formatEther } from 'viem';
|
|
4
|
+
import { walletClientToSmartAccountSigner } from 'permissionless';
|
|
4
5
|
import { WalletConnectorBase } from '@dynamic-labs/wallet-connector-core';
|
|
5
|
-
import { confirmationTransport, unFormatTransaction } from '@dynamic-labs/viem-utils';
|
|
6
|
+
import { confirmationTransport, chainsMap, unFormatTransaction, createViemUiTransaction } from '@dynamic-labs/viem-utils';
|
|
6
7
|
import { parseEvmNetworks, DynamicError, DeferredPromise, wrapMethodWithCallback, TransactionGasCannotBeSponsoredError, InsufficientFundsError } from '@dynamic-labs/utils';
|
|
8
|
+
import { cachedChainIdKey, fetchChain } from './utils/fetchChain.js';
|
|
7
9
|
import { logger } from './utils/logger.js';
|
|
8
10
|
|
|
9
11
|
class ZeroDevConnector extends WalletConnectorBase {
|
|
10
|
-
get key() {
|
|
11
|
-
return 'zerodev';
|
|
12
|
-
}
|
|
13
12
|
constructor(opts) {
|
|
14
13
|
var _a;
|
|
15
14
|
super(opts);
|
|
@@ -18,6 +17,7 @@ class ZeroDevConnector extends WalletConnectorBase {
|
|
|
18
17
|
this.isGasSponsorshipDisabled = false;
|
|
19
18
|
this.isEmbeddedWallet = true;
|
|
20
19
|
this.name = 'ZeroDev';
|
|
20
|
+
this.overrideKey = 'zerodev';
|
|
21
21
|
const zeroDevProjectId = (_a = opts.apiProviders.zerodev) === null || _a === void 0 ? void 0 : _a.clientId;
|
|
22
22
|
if (!zeroDevProjectId) {
|
|
23
23
|
throw new Error('Missing ZeroDev project ID provided. Add your ZeroDev project id to your project configuration via the Dynamic Labs dashboard.');
|
|
@@ -30,28 +30,35 @@ class ZeroDevConnector extends WalletConnectorBase {
|
|
|
30
30
|
return this.eoaConnector;
|
|
31
31
|
}
|
|
32
32
|
getAccountAbstractionProvider() {
|
|
33
|
-
return this.
|
|
33
|
+
return this.kernelClient;
|
|
34
|
+
}
|
|
35
|
+
endSession() {
|
|
36
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
37
|
+
localStorage.removeItem(cachedChainIdKey);
|
|
38
|
+
});
|
|
34
39
|
}
|
|
35
40
|
setEoaConnector(connector) {
|
|
36
41
|
return __awaiter(this, void 0, void 0, function* () {
|
|
37
|
-
this.
|
|
42
|
+
this.kernelClientDeferredPromise = new DeferredPromise();
|
|
38
43
|
this.eoaConnector = connector;
|
|
39
44
|
const signer = yield this.eoaConnector.getSigner();
|
|
40
|
-
if (!signer) {
|
|
45
|
+
if (!(signer === null || signer === void 0 ? void 0 : signer.account)) {
|
|
41
46
|
return;
|
|
42
47
|
}
|
|
43
|
-
const
|
|
44
|
-
|
|
45
|
-
|
|
48
|
+
const kernelClient = yield createEcdsaKernelAccountClient({
|
|
49
|
+
chain: yield fetchChain(this.projectId),
|
|
50
|
+
paymaster: 'NONE',
|
|
46
51
|
projectId: this.projectId,
|
|
52
|
+
provider: ZeroDevConnector.bundlerProvider,
|
|
53
|
+
signer: walletClientToSmartAccountSigner(signer),
|
|
47
54
|
});
|
|
48
|
-
wrapMethodWithCallback(
|
|
55
|
+
wrapMethodWithCallback(kernelClient, 'sendUserOperation', (original, ...args) => {
|
|
49
56
|
this._walletUiUtils.disabledConfirmationOnce();
|
|
50
57
|
return original(...args);
|
|
51
58
|
});
|
|
52
|
-
this.
|
|
59
|
+
this.kernelClient = kernelClient;
|
|
53
60
|
yield this.checkIsProjectChainEnabled();
|
|
54
|
-
this.
|
|
61
|
+
this.kernelClientDeferredPromise.resolve();
|
|
55
62
|
});
|
|
56
63
|
}
|
|
57
64
|
checkIsProjectChainEnabled() {
|
|
@@ -66,69 +73,67 @@ class ZeroDevConnector extends WalletConnectorBase {
|
|
|
66
73
|
}
|
|
67
74
|
});
|
|
68
75
|
}
|
|
69
|
-
|
|
76
|
+
getKernelClientWithSponsorshipValidation() {
|
|
70
77
|
return __awaiter(this, void 0, void 0, function* () {
|
|
71
|
-
if (this.
|
|
72
|
-
return this.
|
|
78
|
+
if (this.kernelClientWithSponsorship) {
|
|
79
|
+
return this.kernelClientWithSponsorship;
|
|
73
80
|
}
|
|
74
81
|
const { eoaConnector } = this;
|
|
75
82
|
if (!eoaConnector)
|
|
76
83
|
throw new DynamicError('No EOA connector');
|
|
77
84
|
const signer = yield eoaConnector.getSigner();
|
|
78
|
-
this.
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
paymasterConfig: {
|
|
82
|
-
onlySendSponsoredTransaction: true,
|
|
83
|
-
policy: 'VERIFYING_PAYMASTER',
|
|
84
|
-
},
|
|
85
|
-
},
|
|
86
|
-
owner: convertWalletClientToAccountSigner(signer),
|
|
85
|
+
this.kernelClientWithSponsorship = yield createEcdsaKernelAccountClient({
|
|
86
|
+
chain: yield fetchChain(this.projectId),
|
|
87
|
+
paymaster: 'SPONSOR',
|
|
87
88
|
projectId: this.projectId,
|
|
89
|
+
provider: ZeroDevConnector.bundlerProvider,
|
|
90
|
+
signer: walletClientToSmartAccountSigner(signer),
|
|
88
91
|
});
|
|
89
|
-
wrapMethodWithCallback(this.
|
|
92
|
+
wrapMethodWithCallback(this.kernelClientWithSponsorship, 'sendUserOperation', (original, ...args) => {
|
|
90
93
|
this._walletUiUtils.disabledConfirmationOnce();
|
|
91
94
|
return original(...args);
|
|
92
95
|
});
|
|
93
|
-
return this.
|
|
96
|
+
return this.kernelClientWithSponsorship;
|
|
94
97
|
});
|
|
95
98
|
}
|
|
96
|
-
|
|
97
|
-
var _a, _b;
|
|
99
|
+
getAddress() {
|
|
100
|
+
var _a, _b, _c;
|
|
98
101
|
return __awaiter(this, void 0, void 0, function* () {
|
|
99
|
-
yield ((_a = this.
|
|
100
|
-
return (_b = this.
|
|
102
|
+
yield ((_a = this.kernelClientDeferredPromise) === null || _a === void 0 ? void 0 : _a.promise);
|
|
103
|
+
return (_c = (_b = this.kernelClient) === null || _b === void 0 ? void 0 : _b.account) === null || _c === void 0 ? void 0 : _c.address;
|
|
101
104
|
});
|
|
102
105
|
}
|
|
103
106
|
getConnectedAccounts() {
|
|
104
|
-
var _a;
|
|
107
|
+
var _a, _b, _c;
|
|
105
108
|
return __awaiter(this, void 0, void 0, function* () {
|
|
106
|
-
yield ((_a = this.
|
|
107
|
-
return this.
|
|
108
|
-
? [yield this.
|
|
109
|
+
yield ((_a = this.kernelClientDeferredPromise) === null || _a === void 0 ? void 0 : _a.promise);
|
|
110
|
+
return ((_c = (_b = this.kernelClient) === null || _b === void 0 ? void 0 : _b.account) === null || _c === void 0 ? void 0 : _c.address)
|
|
111
|
+
? [yield this.kernelClient.account.address]
|
|
109
112
|
: [];
|
|
110
113
|
});
|
|
111
114
|
}
|
|
112
115
|
getNetwork() {
|
|
113
|
-
var _a, _b;
|
|
116
|
+
var _a, _b, _c;
|
|
114
117
|
return __awaiter(this, void 0, void 0, function* () {
|
|
115
|
-
yield ((_a = this.
|
|
116
|
-
return (_b = this.
|
|
118
|
+
yield ((_a = this.kernelClientDeferredPromise) === null || _a === void 0 ? void 0 : _a.promise);
|
|
119
|
+
return (_c = (_b = this.kernelClient) === null || _b === void 0 ? void 0 : _b.chain) === null || _c === void 0 ? void 0 : _c.id;
|
|
117
120
|
});
|
|
118
121
|
}
|
|
119
122
|
getTransport(provider) {
|
|
120
123
|
const transport = confirmationTransport({
|
|
121
|
-
connector: this,
|
|
122
124
|
onPersonalSign: ({ message }) => __awaiter(this, void 0, void 0, function* () {
|
|
123
125
|
this._walletUiUtils.disabledConfirmationOnce();
|
|
124
|
-
return provider.signMessage(
|
|
126
|
+
return provider.signMessage({
|
|
127
|
+
account: provider.account,
|
|
128
|
+
message,
|
|
129
|
+
});
|
|
125
130
|
}),
|
|
126
131
|
onSendTransaction: ({ transaction }) => __awaiter(this, void 0, void 0, function* () {
|
|
127
132
|
try {
|
|
128
133
|
this._walletUiUtils.disabledConfirmationOnce();
|
|
129
134
|
const effectiveProvider = this.isGasSponsorshipDisabled
|
|
130
135
|
? provider
|
|
131
|
-
: yield this.
|
|
136
|
+
: yield this.getKernelClientWithSponsorshipValidation();
|
|
132
137
|
const response = yield effectiveProvider.sendTransaction(unFormatTransaction(transaction));
|
|
133
138
|
return response;
|
|
134
139
|
}
|
|
@@ -146,58 +151,69 @@ class ZeroDevConnector extends WalletConnectorBase {
|
|
|
146
151
|
onSignTypedData: ({ message }) => __awaiter(this, void 0, void 0, function* () {
|
|
147
152
|
this._walletUiUtils.disabledConfirmationOnce();
|
|
148
153
|
const signTypedData = JSON.parse(message);
|
|
149
|
-
return provider.signTypedData(
|
|
154
|
+
return provider.signTypedData({
|
|
155
|
+
account: provider.account,
|
|
156
|
+
domain: signTypedData.domain,
|
|
157
|
+
message: signTypedData.message,
|
|
158
|
+
primaryType: signTypedData.primaryType,
|
|
159
|
+
types: signTypedData.types,
|
|
160
|
+
});
|
|
150
161
|
}),
|
|
151
|
-
provider: provider.
|
|
162
|
+
provider: provider.extend(publicActions),
|
|
152
163
|
transport: custom(provider),
|
|
164
|
+
walletConnector: this,
|
|
153
165
|
walletUiUtils: this._walletUiUtils,
|
|
154
166
|
});
|
|
155
167
|
return transport;
|
|
156
168
|
}
|
|
157
|
-
getWalletClient() {
|
|
158
|
-
|
|
169
|
+
getWalletClient(chainId) {
|
|
170
|
+
var _a;
|
|
171
|
+
const provider = this.kernelClient;
|
|
159
172
|
if (!provider)
|
|
160
173
|
throw new DynamicError('No provider');
|
|
161
174
|
const transport = this.getTransport(provider);
|
|
175
|
+
const address = (_a = provider.account) === null || _a === void 0 ? void 0 : _a.address;
|
|
162
176
|
const walletClient = createWalletClient({
|
|
177
|
+
account: address,
|
|
178
|
+
chain: chainId ? chainsMap[chainId] : provider.chain,
|
|
163
179
|
transport,
|
|
164
180
|
});
|
|
165
181
|
return walletClient;
|
|
166
182
|
}
|
|
167
183
|
getPublicClient() {
|
|
168
184
|
return __awaiter(this, void 0, void 0, function* () {
|
|
169
|
-
const provider = this.
|
|
185
|
+
const provider = this.kernelClient.extend(publicActions);
|
|
170
186
|
if (!provider)
|
|
171
187
|
throw new DynamicError('No provider');
|
|
172
|
-
return provider
|
|
188
|
+
return provider;
|
|
173
189
|
});
|
|
174
190
|
}
|
|
175
191
|
getSigner() {
|
|
176
192
|
return __awaiter(this, void 0, void 0, function* () {
|
|
177
|
-
|
|
178
|
-
if (!provider)
|
|
179
|
-
throw new DynamicError('No provider');
|
|
180
|
-
const transport = this.getTransport(provider);
|
|
181
|
-
const address = yield provider.getAddress();
|
|
182
|
-
const walletClient = createWalletClient({
|
|
183
|
-
account: address,
|
|
184
|
-
transport,
|
|
185
|
-
});
|
|
186
|
-
return walletClient;
|
|
193
|
+
return this.getWalletClient();
|
|
187
194
|
});
|
|
188
195
|
}
|
|
189
196
|
canSponsorTransactionGas(transaction) {
|
|
190
|
-
var _a;
|
|
191
197
|
return __awaiter(this, void 0, void 0, function* () {
|
|
192
198
|
try {
|
|
199
|
+
yield this.getKernelClientWithSponsorshipValidation();
|
|
193
200
|
const userOperation = {
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
201
|
+
callData: yield this.kernelClientWithSponsorship.account.encodeCallData({
|
|
202
|
+
data: transaction.data ? transaction.data : '0x',
|
|
203
|
+
to: transaction.to,
|
|
204
|
+
/**
|
|
205
|
+
* if value is undefined, it will be set to 0x0 so the sponsorship
|
|
206
|
+
* check does not fail
|
|
207
|
+
*/
|
|
208
|
+
value: transaction.value && isHex(transaction.value)
|
|
209
|
+
? fromHex(transaction.value, 'bigint')
|
|
210
|
+
: '0x0',
|
|
211
|
+
}),
|
|
199
212
|
};
|
|
200
|
-
const result = yield
|
|
213
|
+
const result = yield this.kernelClientWithSponsorship.prepareUserOperationRequest({
|
|
214
|
+
account: this.kernelClientWithSponsorship.account,
|
|
215
|
+
userOperation,
|
|
216
|
+
});
|
|
201
217
|
if (!result)
|
|
202
218
|
return false;
|
|
203
219
|
return result.paymasterAndData !== '0x';
|
|
@@ -212,12 +228,11 @@ class ZeroDevConnector extends WalletConnectorBase {
|
|
|
212
228
|
this.isGasSponsorshipDisabled = true;
|
|
213
229
|
}
|
|
214
230
|
getBalance() {
|
|
215
|
-
var _a;
|
|
216
231
|
return __awaiter(this, void 0, void 0, function* () {
|
|
217
|
-
const rpcClient =
|
|
232
|
+
const rpcClient = this.kernelClient.extend(publicActions);
|
|
218
233
|
if (!rpcClient)
|
|
219
234
|
throw new DynamicError('No RPC client');
|
|
220
|
-
const address = yield this.
|
|
235
|
+
const address = yield this.getAddress();
|
|
221
236
|
if (!address)
|
|
222
237
|
return;
|
|
223
238
|
return formatEther(yield rpcClient.getBalance({ address: address }));
|
|
@@ -226,7 +241,7 @@ class ZeroDevConnector extends WalletConnectorBase {
|
|
|
226
241
|
signMessage(messageToSign) {
|
|
227
242
|
return __awaiter(this, void 0, void 0, function* () {
|
|
228
243
|
const client = yield this.getSigner();
|
|
229
|
-
const account = yield this.
|
|
244
|
+
const account = yield this.getAddress();
|
|
230
245
|
if (!account || !client)
|
|
231
246
|
return;
|
|
232
247
|
return client.signMessage({
|
|
@@ -235,6 +250,16 @@ class ZeroDevConnector extends WalletConnectorBase {
|
|
|
235
250
|
});
|
|
236
251
|
});
|
|
237
252
|
}
|
|
253
|
+
createUiTransaction(from) {
|
|
254
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
255
|
+
const walletClient = this.getWalletClient();
|
|
256
|
+
const publicClient = yield this.getPublicClient();
|
|
257
|
+
if (!publicClient || !walletClient) {
|
|
258
|
+
throw new DynamicError('No public client available');
|
|
259
|
+
}
|
|
260
|
+
return createViemUiTransaction({ from, publicClient, walletClient });
|
|
261
|
+
});
|
|
262
|
+
}
|
|
238
263
|
}
|
|
239
264
|
|
|
240
265
|
export { ZeroDevConnector };
|
package/src/index.cjs
CHANGED
|
@@ -6,6 +6,12 @@ var ZeroDevConnector = require('./ZeroDevConnector.cjs');
|
|
|
6
6
|
var ethereumAa = require('./ethereum-aa.cjs');
|
|
7
7
|
var isZeroDevConnector = require('./utils/isZeroDevConnector.cjs');
|
|
8
8
|
|
|
9
|
+
const ZeroDevSmartWalletConnectorsWithConfig = ({ bundlerProvider, } = {}) => {
|
|
10
|
+
if (bundlerProvider) {
|
|
11
|
+
ZeroDevConnector.ZeroDevConnector.bundlerProvider = bundlerProvider;
|
|
12
|
+
}
|
|
13
|
+
return ZeroDevSmartWalletConnectors;
|
|
14
|
+
};
|
|
9
15
|
const ZeroDevSmartWalletConnectors = (props) => {
|
|
10
16
|
var _a;
|
|
11
17
|
if ((_a = props.apiProviders) === null || _a === void 0 ? void 0 : _a.zerodev) {
|
|
@@ -17,3 +23,4 @@ const ZeroDevSmartWalletConnectors = (props) => {
|
|
|
17
23
|
exports.EthereumAaConnector = ethereumAa.EthereumAaConnector;
|
|
18
24
|
exports.isZeroDevConnector = isZeroDevConnector.isZeroDevConnector;
|
|
19
25
|
exports.ZeroDevSmartWalletConnectors = ZeroDevSmartWalletConnectors;
|
|
26
|
+
exports.ZeroDevSmartWalletConnectorsWithConfig = ZeroDevSmartWalletConnectorsWithConfig;
|
package/src/index.d.ts
CHANGED
|
@@ -1,4 +1,8 @@
|
|
|
1
|
+
import { Provider as BundlerProvider } from '@zerodev/presets';
|
|
1
2
|
import { WalletConnectorConstructor } from '@dynamic-labs/wallet-connector-core';
|
|
2
3
|
export * from './ethereum-aa';
|
|
3
4
|
export { isZeroDevConnector } from './utils/isZeroDevConnector';
|
|
5
|
+
export declare const ZeroDevSmartWalletConnectorsWithConfig: ({ bundlerProvider, }?: {
|
|
6
|
+
bundlerProvider?: BundlerProvider | undefined;
|
|
7
|
+
}) => (props: any) => WalletConnectorConstructor[];
|
|
4
8
|
export declare const ZeroDevSmartWalletConnectors: (props: any) => WalletConnectorConstructor[];
|