@dynamic-labs/ethereum-aa 4.0.0-alpha.2 → 4.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 +185 -0
- package/package.cjs +8 -0
- package/package.js +4 -0
- package/package.json +10 -17
- package/src/ZeroDevConnector.cjs +160 -106
- package/src/ZeroDevConnector.d.ts +105 -87
- package/src/ZeroDevConnector.js +163 -109
- package/src/constants.cjs +8 -0
- package/src/constants.d.ts +1 -0
- package/src/constants.js +4 -0
- package/src/index.cjs +13 -0
- package/src/index.d.ts +5 -0
- package/src/index.js +8 -0
- package/src/utils/createEcsdaKernelAccountClient.d.ts +1 -1
- package/src/utils/{fetchChain.cjs → fetchZeroDevChain.cjs} +2 -2
- package/src/utils/{fetchChain.d.ts → fetchZeroDevChain.d.ts} +1 -1
- package/src/utils/{fetchChain.js → fetchZeroDevChain.js} +2 -2
- package/src/utils/getEcdsaValidator.cjs +21 -0
- package/src/utils/getEcdsaValidator.d.ts +3 -0
- package/src/utils/getEcdsaValidator.js +17 -0
- package/src/utils/getEntryPoint.cjs +24 -0
- package/src/utils/getEntryPoint.d.ts +1 -0
- package/src/utils/getEntryPoint.js +20 -0
- package/src/utils/getKernelVersion.cjs +31 -0
- package/src/utils/getKernelVersion.d.ts +4 -0
- package/src/utils/getKernelVersion.js +27 -0
- package/src/utils/index.d.ts +4 -1
|
@@ -1,14 +1,12 @@
|
|
|
1
1
|
import { KernelAccountClient } from '@zerodev/sdk/clients';
|
|
2
2
|
import { KernelSmartAccount } from '@zerodev/sdk/accounts';
|
|
3
|
-
import { toMultiChainECDSAValidator } from '@zerodev/multi-chain-validator';
|
|
4
3
|
import { Account, PublicClient, Transport, WalletClient } from 'viem';
|
|
5
4
|
import { type Chain as ViemChain } from 'viem/chains';
|
|
6
5
|
import { EntryPoint } from 'permissionless/types';
|
|
7
6
|
import { KERNEL_VERSION_TYPE } from '@zerodev/sdk/types';
|
|
8
|
-
import { signerToEcdsaValidator } from '@zerodev/ecdsa-validator';
|
|
9
|
-
import { Provider, ProviderEnum } from '@dynamic-labs/sdk-api-core';
|
|
10
|
-
import { Chain, IAccountAbstractionWalletConnector, ISendBalanceWalletConnector, InternalWalletConnector, WalletConnectorBase } from '@dynamic-labs/wallet-connector-core';
|
|
11
7
|
import { EthereumWallet } from '@dynamic-labs/ethereum-core';
|
|
8
|
+
import { Provider, ProviderEnum, ProviderMultichainAccountAbstractionProviders } from '@dynamic-labs/sdk-api-core';
|
|
9
|
+
import { Chain, IAccountAbstractionWalletConnector, ISendBalanceWalletConnector, InternalWalletConnector, WalletConnectorBase } from '@dynamic-labs/wallet-connector-core';
|
|
12
10
|
import { WalletBookSchema } from '@dynamic-labs/wallet-book';
|
|
13
11
|
import { EvmNetwork, GenericNetwork, IUITransaction, WalletUiUtils } from '@dynamic-labs/types';
|
|
14
12
|
import { BundlerProvider } from './utils';
|
|
@@ -22,11 +20,13 @@ type ZeroDevConnectorProps = {
|
|
|
22
20
|
bundlerProvider: BundlerProvider | undefined;
|
|
23
21
|
};
|
|
24
22
|
type IZeroDevConnector = IAccountAbstractionWalletConnector & ISendBalanceWalletConnector;
|
|
23
|
+
type KernelClient = KernelAccountClient<EntryPoint, Transport, ViemChain, KernelSmartAccount<EntryPoint>>;
|
|
25
24
|
export declare class ZeroDevConnector extends WalletConnectorBase<typeof EthereumWallet> implements IZeroDevConnector {
|
|
26
|
-
|
|
27
|
-
kernelClient: KernelAccountClient<EntryPoint, Transport, ViemChain, KernelSmartAccount<EntryPoint>> | undefined;
|
|
25
|
+
clientId: string;
|
|
28
26
|
eoaConnector: InternalWalletConnector | undefined;
|
|
29
|
-
|
|
27
|
+
eoaAddress: string | undefined;
|
|
28
|
+
private providerMap;
|
|
29
|
+
private eoaConnectorMap;
|
|
30
30
|
ChainWallet: typeof EthereumWallet;
|
|
31
31
|
connectedChain: Chain;
|
|
32
32
|
supportedChains: Chain[];
|
|
@@ -36,6 +36,8 @@ export declare class ZeroDevConnector extends WalletConnectorBase<typeof Ethereu
|
|
|
36
36
|
entryPoint: EntryPoint;
|
|
37
37
|
kernelVersion: KERNEL_VERSION_TYPE;
|
|
38
38
|
ecdsaProviderType: string | undefined;
|
|
39
|
+
defaultChainId: string | undefined;
|
|
40
|
+
providersFromApi: ProviderMultichainAccountAbstractionProviders[];
|
|
39
41
|
static bundlerProvider: BundlerProvider | undefined;
|
|
40
42
|
static bundlerRpc: string | undefined;
|
|
41
43
|
static paymasterRpc: string | undefined;
|
|
@@ -56,9 +58,17 @@ export declare class ZeroDevConnector extends WalletConnectorBase<typeof Ethereu
|
|
|
56
58
|
};
|
|
57
59
|
private _walletUiUtils;
|
|
58
60
|
constructor(opts: ZeroDevConnectorProps);
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
61
|
+
get currentNetworkProvider(): {
|
|
62
|
+
kernelClient: KernelClient;
|
|
63
|
+
kernelClientWithSponsorship: KernelClient;
|
|
64
|
+
} | undefined;
|
|
65
|
+
get lastUsedChainId(): string;
|
|
66
|
+
get kernelClient(): KernelClient | undefined;
|
|
67
|
+
get kernelClientWithSponsorship(): KernelClient | undefined;
|
|
68
|
+
supportsNetworkSwitching(): boolean;
|
|
69
|
+
switchNetwork({ networkChainId, }: {
|
|
70
|
+
networkChainId?: number | string;
|
|
71
|
+
}): Promise<void>;
|
|
62
72
|
/**
|
|
63
73
|
* @deprecated You should get the EOA connector by passing the SCW to getEOAConnector,
|
|
64
74
|
* from the useSmartWallet hook
|
|
@@ -66,10 +76,18 @@ export declare class ZeroDevConnector extends WalletConnectorBase<typeof Ethereu
|
|
|
66
76
|
getEOAConnector(): InternalWalletConnector | undefined;
|
|
67
77
|
getAccountAbstractionProvider({ withSponsorship, }?: {
|
|
68
78
|
withSponsorship?: boolean;
|
|
69
|
-
}):
|
|
79
|
+
}): KernelClient | undefined;
|
|
70
80
|
endSession(): Promise<void>;
|
|
71
|
-
|
|
72
|
-
|
|
81
|
+
registerEoa({ smartWalletAddress, eoaAddress, eoaConnector, shouldSetEoaConnector, }: {
|
|
82
|
+
smartWalletAddress: string;
|
|
83
|
+
eoaAddress: string;
|
|
84
|
+
eoaConnector: InternalWalletConnector;
|
|
85
|
+
shouldSetEoaConnector: boolean;
|
|
86
|
+
}): Promise<void>;
|
|
87
|
+
private setEoaConnector;
|
|
88
|
+
private warnIfProjectChainNotEnabled;
|
|
89
|
+
private generateProviderMap;
|
|
90
|
+
private getKernelClientWithoutSponsorshipValidation;
|
|
73
91
|
private getKernelClientWithSponsorshipValidation;
|
|
74
92
|
getAddress(): Promise<string | undefined>;
|
|
75
93
|
getConnectedAccounts(): Promise<string[]>;
|
|
@@ -2895,44 +2913,44 @@ export declare class ZeroDevConnector extends WalletConnectorBase<typeof Ethereu
|
|
|
2895
2913
|
[x: `address[${string}]`]: undefined;
|
|
2896
2914
|
[x: `bool[${string}]`]: undefined;
|
|
2897
2915
|
[x: `bytes[${string}]`]: undefined;
|
|
2898
|
-
[x: `bytes9[${string}]`]: undefined;
|
|
2899
2916
|
[x: `bytes1[${string}]`]: undefined;
|
|
2900
|
-
[x: `bytes32[${string}]`]: undefined;
|
|
2901
|
-
[x: `bytes31[${string}]`]: undefined;
|
|
2902
|
-
[x: `bytes30[${string}]`]: undefined;
|
|
2903
|
-
[x: `bytes29[${string}]`]: undefined;
|
|
2904
|
-
[x: `bytes28[${string}]`]: undefined;
|
|
2905
|
-
[x: `bytes27[${string}]`]: undefined;
|
|
2906
|
-
[x: `bytes26[${string}]`]: undefined;
|
|
2907
|
-
[x: `bytes25[${string}]`]: undefined;
|
|
2908
|
-
[x: `bytes24[${string}]`]: undefined;
|
|
2909
|
-
[x: `bytes23[${string}]`]: undefined;
|
|
2910
|
-
[x: `bytes22[${string}]`]: undefined;
|
|
2911
|
-
[x: `bytes21[${string}]`]: undefined;
|
|
2912
|
-
[x: `bytes20[${string}]`]: undefined;
|
|
2913
|
-
[x: `bytes19[${string}]`]: undefined;
|
|
2914
2917
|
[x: `bytes2[${string}]`]: undefined;
|
|
2915
|
-
[x: `bytes18[${string}]`]: undefined;
|
|
2916
|
-
[x: `bytes17[${string}]`]: undefined;
|
|
2917
|
-
[x: `bytes16[${string}]`]: undefined;
|
|
2918
|
-
[x: `bytes15[${string}]`]: undefined;
|
|
2919
|
-
[x: `bytes14[${string}]`]: undefined;
|
|
2920
|
-
[x: `bytes13[${string}]`]: undefined;
|
|
2921
|
-
[x: `bytes12[${string}]`]: undefined;
|
|
2922
|
-
[x: `bytes11[${string}]`]: undefined;
|
|
2923
|
-
[x: `bytes10[${string}]`]: undefined;
|
|
2924
|
-
[x: `bytes8[${string}]`]: undefined;
|
|
2925
|
-
[x: `bytes7[${string}]`]: undefined;
|
|
2926
|
-
[x: `bytes6[${string}]`]: undefined;
|
|
2927
|
-
[x: `bytes5[${string}]`]: undefined;
|
|
2928
|
-
[x: `bytes4[${string}]`]: undefined;
|
|
2929
2918
|
[x: `bytes3[${string}]`]: undefined;
|
|
2919
|
+
[x: `bytes4[${string}]`]: undefined;
|
|
2920
|
+
[x: `bytes5[${string}]`]: undefined;
|
|
2921
|
+
[x: `bytes6[${string}]`]: undefined;
|
|
2922
|
+
[x: `bytes7[${string}]`]: undefined;
|
|
2923
|
+
[x: `bytes8[${string}]`]: undefined;
|
|
2924
|
+
[x: `bytes9[${string}]`]: undefined;
|
|
2925
|
+
[x: `bytes10[${string}]`]: undefined;
|
|
2926
|
+
[x: `bytes11[${string}]`]: undefined;
|
|
2927
|
+
[x: `bytes12[${string}]`]: undefined;
|
|
2928
|
+
[x: `bytes13[${string}]`]: undefined;
|
|
2929
|
+
[x: `bytes14[${string}]`]: undefined;
|
|
2930
|
+
[x: `bytes15[${string}]`]: undefined;
|
|
2931
|
+
[x: `bytes16[${string}]`]: undefined;
|
|
2932
|
+
[x: `bytes17[${string}]`]: undefined;
|
|
2933
|
+
[x: `bytes18[${string}]`]: undefined;
|
|
2934
|
+
[x: `bytes19[${string}]`]: undefined;
|
|
2935
|
+
[x: `bytes20[${string}]`]: undefined;
|
|
2936
|
+
[x: `bytes21[${string}]`]: undefined;
|
|
2937
|
+
[x: `bytes22[${string}]`]: undefined;
|
|
2938
|
+
[x: `bytes23[${string}]`]: undefined;
|
|
2939
|
+
[x: `bytes24[${string}]`]: undefined;
|
|
2940
|
+
[x: `bytes25[${string}]`]: undefined;
|
|
2941
|
+
[x: `bytes26[${string}]`]: undefined;
|
|
2942
|
+
[x: `bytes27[${string}]`]: undefined;
|
|
2943
|
+
[x: `bytes28[${string}]`]: undefined;
|
|
2944
|
+
[x: `bytes29[${string}]`]: undefined;
|
|
2945
|
+
[x: `bytes30[${string}]`]: undefined;
|
|
2946
|
+
[x: `bytes31[${string}]`]: undefined;
|
|
2947
|
+
[x: `bytes32[${string}]`]: undefined;
|
|
2930
2948
|
[x: `int[${string}]`]: undefined;
|
|
2931
|
-
[x: `int40[${string}]`]: undefined;
|
|
2932
|
-
[x: `int32[${string}]`]: undefined;
|
|
2933
|
-
[x: `int24[${string}]`]: undefined;
|
|
2934
|
-
[x: `int16[${string}]`]: undefined;
|
|
2935
2949
|
[x: `int8[${string}]`]: undefined;
|
|
2950
|
+
[x: `int16[${string}]`]: undefined;
|
|
2951
|
+
[x: `int24[${string}]`]: undefined;
|
|
2952
|
+
[x: `int32[${string}]`]: undefined;
|
|
2953
|
+
[x: `int40[${string}]`]: undefined;
|
|
2936
2954
|
[x: `int48[${string}]`]: undefined;
|
|
2937
2955
|
[x: `int56[${string}]`]: undefined;
|
|
2938
2956
|
[x: `int64[${string}]`]: undefined;
|
|
@@ -2961,11 +2979,11 @@ export declare class ZeroDevConnector extends WalletConnectorBase<typeof Ethereu
|
|
|
2961
2979
|
[x: `int248[${string}]`]: undefined;
|
|
2962
2980
|
[x: `int256[${string}]`]: undefined;
|
|
2963
2981
|
[x: `uint[${string}]`]: undefined;
|
|
2964
|
-
[x: `uint40[${string}]`]: undefined;
|
|
2965
|
-
[x: `uint32[${string}]`]: undefined;
|
|
2966
|
-
[x: `uint24[${string}]`]: undefined;
|
|
2967
|
-
[x: `uint16[${string}]`]: undefined;
|
|
2968
2982
|
[x: `uint8[${string}]`]: undefined;
|
|
2983
|
+
[x: `uint16[${string}]`]: undefined;
|
|
2984
|
+
[x: `uint24[${string}]`]: undefined;
|
|
2985
|
+
[x: `uint32[${string}]`]: undefined;
|
|
2986
|
+
[x: `uint40[${string}]`]: undefined;
|
|
2969
2987
|
[x: `uint48[${string}]`]: undefined;
|
|
2970
2988
|
[x: `uint56[${string}]`]: undefined;
|
|
2971
2989
|
[x: `uint64[${string}]`]: undefined;
|
|
@@ -2997,43 +3015,43 @@ export declare class ZeroDevConnector extends WalletConnectorBase<typeof Ethereu
|
|
|
2997
3015
|
address?: undefined;
|
|
2998
3016
|
bool?: undefined;
|
|
2999
3017
|
bytes?: undefined;
|
|
3000
|
-
bytes9?: undefined;
|
|
3001
3018
|
bytes1?: undefined;
|
|
3002
|
-
bytes32?: undefined;
|
|
3003
|
-
bytes31?: undefined;
|
|
3004
|
-
bytes30?: undefined;
|
|
3005
|
-
bytes29?: undefined;
|
|
3006
|
-
bytes28?: undefined;
|
|
3007
|
-
bytes27?: undefined;
|
|
3008
|
-
bytes26?: undefined;
|
|
3009
|
-
bytes25?: undefined;
|
|
3010
|
-
bytes24?: undefined;
|
|
3011
|
-
bytes23?: undefined;
|
|
3012
|
-
bytes22?: undefined;
|
|
3013
|
-
bytes21?: undefined;
|
|
3014
|
-
bytes20?: undefined;
|
|
3015
|
-
bytes19?: undefined;
|
|
3016
3019
|
bytes2?: undefined;
|
|
3017
|
-
bytes18?: undefined;
|
|
3018
|
-
bytes17?: undefined;
|
|
3019
|
-
bytes16?: undefined;
|
|
3020
|
-
bytes15?: undefined;
|
|
3021
|
-
bytes14?: undefined;
|
|
3022
|
-
bytes13?: undefined;
|
|
3023
|
-
bytes12?: undefined;
|
|
3024
|
-
bytes11?: undefined;
|
|
3025
|
-
bytes10?: undefined;
|
|
3026
|
-
bytes8?: undefined;
|
|
3027
|
-
bytes7?: undefined;
|
|
3028
|
-
bytes6?: undefined;
|
|
3029
|
-
bytes5?: undefined;
|
|
3030
|
-
bytes4?: undefined;
|
|
3031
3020
|
bytes3?: undefined;
|
|
3032
|
-
|
|
3033
|
-
|
|
3034
|
-
|
|
3035
|
-
|
|
3021
|
+
bytes4?: undefined;
|
|
3022
|
+
bytes5?: undefined;
|
|
3023
|
+
bytes6?: undefined;
|
|
3024
|
+
bytes7?: undefined;
|
|
3025
|
+
bytes8?: undefined;
|
|
3026
|
+
bytes9?: undefined;
|
|
3027
|
+
bytes10?: undefined;
|
|
3028
|
+
bytes11?: undefined;
|
|
3029
|
+
bytes12?: undefined;
|
|
3030
|
+
bytes13?: undefined;
|
|
3031
|
+
bytes14?: undefined;
|
|
3032
|
+
bytes15?: undefined;
|
|
3033
|
+
bytes16?: undefined;
|
|
3034
|
+
bytes17?: undefined;
|
|
3035
|
+
bytes18?: undefined;
|
|
3036
|
+
bytes19?: undefined;
|
|
3037
|
+
bytes20?: undefined;
|
|
3038
|
+
bytes21?: undefined;
|
|
3039
|
+
bytes22?: undefined;
|
|
3040
|
+
bytes23?: undefined;
|
|
3041
|
+
bytes24?: undefined;
|
|
3042
|
+
bytes25?: undefined;
|
|
3043
|
+
bytes26?: undefined;
|
|
3044
|
+
bytes27?: undefined;
|
|
3045
|
+
bytes28?: undefined;
|
|
3046
|
+
bytes29?: undefined;
|
|
3047
|
+
bytes30?: undefined;
|
|
3048
|
+
bytes31?: undefined;
|
|
3049
|
+
bytes32?: undefined;
|
|
3036
3050
|
int8?: undefined;
|
|
3051
|
+
int16?: undefined;
|
|
3052
|
+
int24?: undefined;
|
|
3053
|
+
int32?: undefined;
|
|
3054
|
+
int40?: undefined;
|
|
3037
3055
|
int48?: undefined;
|
|
3038
3056
|
int56?: undefined;
|
|
3039
3057
|
int64?: undefined;
|
|
@@ -3061,11 +3079,11 @@ export declare class ZeroDevConnector extends WalletConnectorBase<typeof Ethereu
|
|
|
3061
3079
|
int240?: undefined;
|
|
3062
3080
|
int248?: undefined;
|
|
3063
3081
|
int256?: undefined;
|
|
3064
|
-
uint40?: undefined;
|
|
3065
|
-
uint32?: undefined;
|
|
3066
|
-
uint24?: undefined;
|
|
3067
|
-
uint16?: undefined;
|
|
3068
3082
|
uint8?: undefined;
|
|
3083
|
+
uint16?: undefined;
|
|
3084
|
+
uint24?: undefined;
|
|
3085
|
+
uint32?: undefined;
|
|
3086
|
+
uint40?: undefined;
|
|
3069
3087
|
uint48?: undefined;
|
|
3070
3088
|
uint56?: undefined;
|
|
3071
3089
|
uint64?: undefined;
|
package/src/ZeroDevConnector.js
CHANGED
|
@@ -1,27 +1,32 @@
|
|
|
1
1
|
'use client'
|
|
2
2
|
import { __awaiter } from '../_virtual/_tslib.js';
|
|
3
|
-
import { toMultiChainECDSAValidator } from '@zerodev/multi-chain-validator';
|
|
4
3
|
import { publicActions, custom, createWalletClient, isHex, fromHex, formatEther } from 'viem';
|
|
5
|
-
import {
|
|
6
|
-
import {
|
|
7
|
-
import {
|
|
8
|
-
import {
|
|
9
|
-
import {
|
|
10
|
-
import {
|
|
11
|
-
import { parseEvmNetworks, DynamicError, DeferredPromise, wrapMethodWithCallback, TransactionGasCannotBeSponsoredError, InsufficientFundsError } from '@dynamic-labs/utils';
|
|
12
|
-
import { cachedChainIdKey, fetchChain } from './utils/fetchChain.js';
|
|
4
|
+
import { toAccount } from 'viem/accounts';
|
|
5
|
+
import { walletClientToSmartAccountSigner } from 'permissionless/utils';
|
|
6
|
+
import { EthereumWallet, isEthWalletConnector, chainsMap, confirmationTransport, unFormatTransaction, createViemUiTransaction } from '@dynamic-labs/ethereum-core';
|
|
7
|
+
import { WalletConnectorBase, eventListenerHandlers } from '@dynamic-labs/wallet-connector-core';
|
|
8
|
+
import { parseEvmNetworks, StorageService, DeferredPromise, parseChainId, DynamicError, wrapMethodWithCallback, TransactionGasCannotBeSponsoredError, InsufficientFundsError } from '@dynamic-labs/utils';
|
|
9
|
+
import { ZERO_DEV_LAST_USED_CHAIN_ID_KEY } from './constants.js';
|
|
13
10
|
import { logger } from './utils/logger.js';
|
|
14
11
|
import { createEcdsaKernelAccountClient } from './utils/createEcsdaKernelAccountClient.js';
|
|
12
|
+
import { getEcdsaValidator } from './utils/getEcdsaValidator.js';
|
|
13
|
+
import { getEntryPoint } from './utils/getEntryPoint.js';
|
|
14
|
+
import { getKernelVersion } from './utils/getKernelVersion.js';
|
|
15
15
|
|
|
16
16
|
class ZeroDevConnector extends WalletConnectorBase {
|
|
17
17
|
constructor(opts) {
|
|
18
18
|
var _a, _b, _c, _d;
|
|
19
19
|
super(opts);
|
|
20
|
+
// provider map maintains the kernel clients per chain
|
|
21
|
+
this.providerMap = {};
|
|
22
|
+
// eoa connector map maintains the eoa address and connector for each smart wallet address
|
|
23
|
+
this.eoaConnectorMap = {};
|
|
20
24
|
this.ChainWallet = EthereumWallet;
|
|
21
25
|
this.connectedChain = 'EVM';
|
|
22
26
|
this.supportedChains = ['ETH', 'EVM'];
|
|
23
27
|
this.isGasSponsorshipDisabled = false;
|
|
24
28
|
this.isEmbeddedWallet = true;
|
|
29
|
+
this.providersFromApi = [];
|
|
25
30
|
this.name = 'ZeroDev';
|
|
26
31
|
this.overrideKey = 'zerodev';
|
|
27
32
|
this.walletFallback = {
|
|
@@ -31,59 +36,64 @@ class ZeroDevConnector extends WalletConnectorBase {
|
|
|
31
36
|
},
|
|
32
37
|
name: 'ZeroDev',
|
|
33
38
|
};
|
|
34
|
-
const zeroDevProjectId = (_a = opts.apiProviders.zerodev) === null || _a === void 0 ? void 0 : _a.clientId;
|
|
35
|
-
if (!zeroDevProjectId) {
|
|
36
|
-
throw new Error('Missing ZeroDev project ID provided. Add your ZeroDev project id to your project configuration via the Dynamic Labs dashboard.');
|
|
37
|
-
}
|
|
38
|
-
this.projectId = zeroDevProjectId;
|
|
39
39
|
this._walletUiUtils = opts.walletUiUtils;
|
|
40
40
|
this.evmNetworks = parseEvmNetworks(opts.evmNetworks);
|
|
41
|
-
this.entryPoint =
|
|
42
|
-
this.kernelVersion =
|
|
41
|
+
this.entryPoint = getEntryPoint((_a = opts.apiProviders.zerodev) === null || _a === void 0 ? void 0 : _a.entryPointVersion);
|
|
42
|
+
this.kernelVersion = getKernelVersion((_b = opts.apiProviders.zerodev) === null || _b === void 0 ? void 0 : _b.kernelVersion, this.entryPoint);
|
|
43
|
+
// this is the list of providers from the api that are used for multi-chain account abstraction
|
|
44
|
+
this.providersFromApi =
|
|
45
|
+
((_c = opts.apiProviders.zerodev) === null || _c === void 0 ? void 0 : _c.multichainAccountAbstractionProviders) || [];
|
|
46
|
+
const [defaultProvider] = this.providersFromApi;
|
|
47
|
+
this.clientId = defaultProvider === null || defaultProvider === void 0 ? void 0 : defaultProvider.clientId;
|
|
48
|
+
if (!this.clientId) {
|
|
49
|
+
throw new Error('Missing ZeroDev project ID provided. Add your ZeroDev project id to your project configuration via the Dynamic Labs dashboard.');
|
|
50
|
+
}
|
|
51
|
+
this.defaultChainId = defaultProvider === null || defaultProvider === void 0 ? void 0 : defaultProvider.chain;
|
|
43
52
|
this.ecdsaProviderType = (_d = opts.apiProviders.zerodev) === null || _d === void 0 ? void 0 : _d.ecdsaProviderType;
|
|
44
53
|
}
|
|
45
|
-
|
|
46
|
-
if
|
|
47
|
-
|
|
48
|
-
return
|
|
54
|
+
get currentNetworkProvider() {
|
|
55
|
+
// check if the last used chain id is in the provider map
|
|
56
|
+
if (this.providerMap[this.lastUsedChainId]) {
|
|
57
|
+
return this.providerMap[this.lastUsedChainId];
|
|
49
58
|
}
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
else {
|
|
54
|
-
logger.error('Invalid entry point version', entryPoint);
|
|
55
|
-
return ENTRYPOINT_ADDRESS_V07;
|
|
59
|
+
// if not, check if the default chain id is in the provider map
|
|
60
|
+
if (this.defaultChainId) {
|
|
61
|
+
return this.providerMap[this.defaultChainId];
|
|
56
62
|
}
|
|
63
|
+
// if no chain id is found, return undefined
|
|
64
|
+
return undefined;
|
|
57
65
|
}
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
}
|
|
64
|
-
else if (kernelVersion === ProviderKernelVersionEnum.V30) {
|
|
65
|
-
return KERNEL_V3_0;
|
|
66
|
-
}
|
|
67
|
-
else if (kernelVersion === ProviderKernelVersionEnum.V24 ||
|
|
68
|
-
this.entryPoint === ENTRYPOINT_ADDRESS_V06 // v0.6 only supports v2.4
|
|
69
|
-
) {
|
|
70
|
-
return KERNEL_V2_4;
|
|
71
|
-
}
|
|
72
|
-
else {
|
|
73
|
-
logger.error('Invalid kernel version', kernelVersion);
|
|
74
|
-
return KERNEL_V3_1;
|
|
75
|
-
}
|
|
66
|
+
get lastUsedChainId() {
|
|
67
|
+
var _a;
|
|
68
|
+
const storedChainId = StorageService.getItem(ZERO_DEV_LAST_USED_CHAIN_ID_KEY);
|
|
69
|
+
// returning string of unknown if no chain id is found to result in undefined provider lookup
|
|
70
|
+
return (_a = storedChainId !== null && storedChainId !== void 0 ? storedChainId : this.defaultChainId) !== null && _a !== void 0 ? _a : 'unknown';
|
|
76
71
|
}
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
72
|
+
get kernelClient() {
|
|
73
|
+
var _a;
|
|
74
|
+
return (_a = this.currentNetworkProvider) === null || _a === void 0 ? void 0 : _a.kernelClient;
|
|
75
|
+
}
|
|
76
|
+
get kernelClientWithSponsorship() {
|
|
77
|
+
var _a;
|
|
78
|
+
return (_a = this.currentNetworkProvider) === null || _a === void 0 ? void 0 : _a.kernelClientWithSponsorship;
|
|
79
|
+
}
|
|
80
|
+
supportsNetworkSwitching() {
|
|
81
|
+
return (Object.keys(this.providerMap).length > 1 && this.evmNetworks.length > 1);
|
|
82
|
+
}
|
|
83
|
+
switchNetwork(_a) {
|
|
84
|
+
return __awaiter(this, arguments, void 0, function* ({ networkChainId, }) {
|
|
85
|
+
if (!this.supportsNetworkSwitching())
|
|
86
|
+
return;
|
|
87
|
+
if (!networkChainId)
|
|
88
|
+
return;
|
|
89
|
+
const chainId = networkChainId.toString();
|
|
90
|
+
if (!this.providerMap[chainId]) {
|
|
91
|
+
throw new Error(`No provider found for chainId: ${chainId}`);
|
|
92
|
+
}
|
|
93
|
+
StorageService.setItem(ZERO_DEV_LAST_USED_CHAIN_ID_KEY, chainId);
|
|
94
|
+
const { handleChainChange } = eventListenerHandlers(this);
|
|
95
|
+
handleChainChange(chainId);
|
|
96
|
+
});
|
|
87
97
|
}
|
|
88
98
|
/**
|
|
89
99
|
* @deprecated You should get the EOA connector by passing the SCW to getEOAConnector,
|
|
@@ -100,10 +110,22 @@ class ZeroDevConnector extends WalletConnectorBase {
|
|
|
100
110
|
}
|
|
101
111
|
endSession() {
|
|
102
112
|
return __awaiter(this, void 0, void 0, function* () {
|
|
103
|
-
|
|
113
|
+
StorageService.removeItem(ZERO_DEV_LAST_USED_CHAIN_ID_KEY);
|
|
104
114
|
});
|
|
105
115
|
}
|
|
106
|
-
|
|
116
|
+
registerEoa(_a) {
|
|
117
|
+
return __awaiter(this, arguments, void 0, function* ({ smartWalletAddress, eoaAddress, eoaConnector, shouldSetEoaConnector = false, }) {
|
|
118
|
+
this.eoaConnectorMap[smartWalletAddress] = {
|
|
119
|
+
eoaAddress,
|
|
120
|
+
eoaConnector,
|
|
121
|
+
};
|
|
122
|
+
// if this is the primary wallet, set the eoa connector and kernel clients
|
|
123
|
+
if (shouldSetEoaConnector && this.eoaAddress !== eoaAddress) {
|
|
124
|
+
yield this.setEoaConnector(eoaAddress, eoaConnector);
|
|
125
|
+
}
|
|
126
|
+
});
|
|
127
|
+
}
|
|
128
|
+
setEoaConnector(eoaAddress, connector) {
|
|
107
129
|
return __awaiter(this, void 0, void 0, function* () {
|
|
108
130
|
if (!connector) {
|
|
109
131
|
logger.error('No EOA connector provided');
|
|
@@ -111,24 +133,76 @@ class ZeroDevConnector extends WalletConnectorBase {
|
|
|
111
133
|
}
|
|
112
134
|
this.kernelClientDeferredPromise = new DeferredPromise();
|
|
113
135
|
this.eoaConnector = connector;
|
|
136
|
+
this.eoaAddress = eoaAddress;
|
|
114
137
|
if (isEthWalletConnector(this.eoaConnector) &&
|
|
115
138
|
!this.eoaConnector.getActiveAccount()) {
|
|
116
139
|
yield this.eoaConnector.getConnectedAccounts();
|
|
117
140
|
}
|
|
118
141
|
const signer = yield this.eoaConnector.getSigner();
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
142
|
+
signer.account = toAccount(eoaAddress);
|
|
143
|
+
yield this.generateProviderMap(signer);
|
|
144
|
+
this.evmNetworks = this.evmNetworks.filter((network) => Boolean(this.providerMap[network.chainId]));
|
|
145
|
+
this.kernelClientDeferredPromise.resolve();
|
|
146
|
+
});
|
|
147
|
+
}
|
|
148
|
+
warnIfProjectChainNotEnabled(chainId) {
|
|
149
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
150
|
+
var _a;
|
|
151
|
+
let chainIdToCheck = chainId;
|
|
152
|
+
if (!chainIdToCheck) {
|
|
153
|
+
const client = yield this.getPublicClient();
|
|
154
|
+
chainIdToCheck = (_a = client === null || client === void 0 ? void 0 : client.chain) === null || _a === void 0 ? void 0 : _a.id;
|
|
155
|
+
}
|
|
156
|
+
const isProjectChainEnabled = this.evmNetworks.some((network) => network.chainId === chainIdToCheck);
|
|
157
|
+
if (!isProjectChainEnabled) {
|
|
158
|
+
logger.error(`Please make sure to enable (${chainIdToCheck}) in the Dynamic dashboard (https://app.dynamic.xyz/dashboard/configurations#evm).`);
|
|
159
|
+
}
|
|
160
|
+
});
|
|
161
|
+
}
|
|
162
|
+
generateProviderMap(signer) {
|
|
163
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
164
|
+
// reset the chains provider map when eoa connector changes
|
|
165
|
+
this.providerMap = {};
|
|
166
|
+
for (const provider of this.providersFromApi) {
|
|
167
|
+
if (!this.providerMap[provider.chain]) {
|
|
168
|
+
const [kernelClient, kernelClientWithSponsorship] = yield Promise.all([
|
|
169
|
+
this.getKernelClientWithoutSponsorshipValidation({
|
|
170
|
+
chainId: provider.chain,
|
|
171
|
+
projectId: provider.clientId,
|
|
172
|
+
signer,
|
|
173
|
+
}),
|
|
174
|
+
this.getKernelClientWithSponsorshipValidation({
|
|
175
|
+
chainId: provider.chain,
|
|
176
|
+
projectId: provider.clientId,
|
|
177
|
+
signer,
|
|
178
|
+
}),
|
|
179
|
+
]);
|
|
180
|
+
this.providerMap[provider.chain] = {
|
|
181
|
+
kernelClient,
|
|
182
|
+
kernelClientWithSponsorship,
|
|
183
|
+
};
|
|
184
|
+
}
|
|
185
|
+
yield this.warnIfProjectChainNotEnabled(parseChainId(provider.chain));
|
|
122
186
|
}
|
|
187
|
+
});
|
|
188
|
+
}
|
|
189
|
+
getKernelClientWithoutSponsorshipValidation(_a) {
|
|
190
|
+
return __awaiter(this, arguments, void 0, function* ({ projectId, signer, chainId, }) {
|
|
191
|
+
if (chainId && this.providerMap[chainId]) {
|
|
192
|
+
return this.providerMap[chainId].kernelClient;
|
|
193
|
+
}
|
|
194
|
+
const { eoaConnector } = this;
|
|
195
|
+
if (!eoaConnector)
|
|
196
|
+
throw new DynamicError('No EOA connector');
|
|
123
197
|
const kernelClient = yield createEcdsaKernelAccountClient({
|
|
124
198
|
bundlerRpc: ZeroDevConnector.bundlerRpc,
|
|
125
|
-
chain:
|
|
126
|
-
ecdsaValidator:
|
|
199
|
+
chain: chainsMap[chainId],
|
|
200
|
+
ecdsaValidator: getEcdsaValidator(this.ecdsaProviderType),
|
|
127
201
|
entryPointAddress: this.entryPoint,
|
|
128
202
|
kernelVersion: this.kernelVersion,
|
|
129
203
|
paymaster: 'NONE',
|
|
130
204
|
paymasterRpc: ZeroDevConnector.paymasterRpc,
|
|
131
|
-
projectId
|
|
205
|
+
projectId,
|
|
132
206
|
provider: ZeroDevConnector.bundlerProvider,
|
|
133
207
|
signer: walletClientToSmartAccountSigner(signer),
|
|
134
208
|
});
|
|
@@ -136,51 +210,34 @@ class ZeroDevConnector extends WalletConnectorBase {
|
|
|
136
210
|
this._walletUiUtils.disabledConfirmationOnce();
|
|
137
211
|
return original(...args);
|
|
138
212
|
});
|
|
139
|
-
|
|
140
|
-
// set the provider with sponsorship enabled
|
|
141
|
-
yield this.getKernelClientWithSponsorshipValidation();
|
|
142
|
-
yield this.checkIsProjectChainEnabled();
|
|
143
|
-
this.kernelClientDeferredPromise.resolve();
|
|
213
|
+
return kernelClient;
|
|
144
214
|
});
|
|
145
215
|
}
|
|
146
|
-
|
|
147
|
-
return __awaiter(this,
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
const chainName = (_a = client === null || client === void 0 ? void 0 : client.chain) === null || _a === void 0 ? void 0 : _a.name;
|
|
151
|
-
const chainId = (_b = client === null || client === void 0 ? void 0 : client.chain) === null || _b === void 0 ? void 0 : _b.id;
|
|
152
|
-
const isProjectChainEnabled = this.evmNetworks.some((network) => network.chainId === chainId);
|
|
153
|
-
if (!isProjectChainEnabled) {
|
|
154
|
-
logger.error(`Please make sure to enable ${chainName} (${chainId}) in the Dynamic dashboard (https://app.dynamic.xyz/dashboard/configurations#evm).`);
|
|
155
|
-
}
|
|
156
|
-
});
|
|
157
|
-
}
|
|
158
|
-
getKernelClientWithSponsorshipValidation() {
|
|
159
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
160
|
-
if (this.kernelClientWithSponsorship) {
|
|
161
|
-
return this.kernelClientWithSponsorship;
|
|
216
|
+
getKernelClientWithSponsorshipValidation(_a) {
|
|
217
|
+
return __awaiter(this, arguments, void 0, function* ({ projectId, signer, chainId, }) {
|
|
218
|
+
if (chainId && this.providerMap[chainId]) {
|
|
219
|
+
return this.providerMap[chainId].kernelClientWithSponsorship;
|
|
162
220
|
}
|
|
163
221
|
const { eoaConnector } = this;
|
|
164
222
|
if (!eoaConnector)
|
|
165
223
|
throw new DynamicError('No EOA connector');
|
|
166
|
-
const
|
|
167
|
-
this.kernelClientWithSponsorship = yield createEcdsaKernelAccountClient({
|
|
224
|
+
const kernelClientWithSponsorship = yield createEcdsaKernelAccountClient({
|
|
168
225
|
bundlerRpc: ZeroDevConnector.bundlerRpc,
|
|
169
|
-
chain:
|
|
170
|
-
ecdsaValidator:
|
|
226
|
+
chain: chainsMap[chainId],
|
|
227
|
+
ecdsaValidator: getEcdsaValidator(this.ecdsaProviderType),
|
|
171
228
|
entryPointAddress: this.entryPoint,
|
|
172
229
|
kernelVersion: this.kernelVersion,
|
|
173
230
|
paymaster: 'SPONSOR',
|
|
174
231
|
paymasterRpc: ZeroDevConnector.paymasterRpc,
|
|
175
|
-
projectId
|
|
232
|
+
projectId,
|
|
176
233
|
provider: ZeroDevConnector.bundlerProvider,
|
|
177
234
|
signer: walletClientToSmartAccountSigner(signer),
|
|
178
235
|
});
|
|
179
|
-
wrapMethodWithCallback(
|
|
236
|
+
wrapMethodWithCallback(kernelClientWithSponsorship, 'sendUserOperation', (original, ...args) => {
|
|
180
237
|
this._walletUiUtils.disabledConfirmationOnce();
|
|
181
238
|
return original(...args);
|
|
182
239
|
});
|
|
183
|
-
return
|
|
240
|
+
return kernelClientWithSponsorship;
|
|
184
241
|
});
|
|
185
242
|
}
|
|
186
243
|
getAddress() {
|
|
@@ -221,7 +278,10 @@ class ZeroDevConnector extends WalletConnectorBase {
|
|
|
221
278
|
this._walletUiUtils.disabledConfirmationOnce();
|
|
222
279
|
const effectiveProvider = this.isGasSponsorshipDisabled
|
|
223
280
|
? provider
|
|
224
|
-
:
|
|
281
|
+
: this.kernelClientWithSponsorship;
|
|
282
|
+
if (!effectiveProvider) {
|
|
283
|
+
throw new DynamicError('No provider');
|
|
284
|
+
}
|
|
225
285
|
const response = yield effectiveProvider.sendTransaction(unFormatTransaction(transaction));
|
|
226
286
|
return response;
|
|
227
287
|
}
|
|
@@ -259,7 +319,7 @@ class ZeroDevConnector extends WalletConnectorBase {
|
|
|
259
319
|
var _a;
|
|
260
320
|
const provider = this.kernelClient;
|
|
261
321
|
if (!provider)
|
|
262
|
-
|
|
322
|
+
return undefined;
|
|
263
323
|
const transport = this.getTransport(provider);
|
|
264
324
|
const address = (_a = provider.account) === null || _a === void 0 ? void 0 : _a.address;
|
|
265
325
|
const walletClient = createWalletClient({
|
|
@@ -274,7 +334,7 @@ class ZeroDevConnector extends WalletConnectorBase {
|
|
|
274
334
|
var _a;
|
|
275
335
|
const provider = (_a = this.kernelClient) === null || _a === void 0 ? void 0 : _a.extend(publicActions);
|
|
276
336
|
if (!provider)
|
|
277
|
-
|
|
337
|
+
return undefined;
|
|
278
338
|
return provider;
|
|
279
339
|
});
|
|
280
340
|
}
|
|
@@ -286,7 +346,10 @@ class ZeroDevConnector extends WalletConnectorBase {
|
|
|
286
346
|
canSponsorTransactionGas(transaction) {
|
|
287
347
|
return __awaiter(this, void 0, void 0, function* () {
|
|
288
348
|
try {
|
|
289
|
-
const kernelClientWithSponsorship =
|
|
349
|
+
const { kernelClientWithSponsorship } = this;
|
|
350
|
+
if (!kernelClientWithSponsorship) {
|
|
351
|
+
throw new DynamicError('No kernel client with sponsorship found');
|
|
352
|
+
}
|
|
290
353
|
const userOperation = {
|
|
291
354
|
callData: yield kernelClientWithSponsorship.account.encodeCallData({
|
|
292
355
|
data: transaction.data ? transaction.data : '0x',
|
|
@@ -347,23 +410,14 @@ class ZeroDevConnector extends WalletConnectorBase {
|
|
|
347
410
|
});
|
|
348
411
|
}
|
|
349
412
|
validateActiveWallet(expectedAddress) {
|
|
350
|
-
const _super = Object.create(null, {
|
|
351
|
-
validateActiveWallet: { get: () => super.validateActiveWallet }
|
|
352
|
-
});
|
|
353
413
|
return __awaiter(this, void 0, void 0, function* () {
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
const verifiedCredentials = eoaConnector === null || eoaConnector === void 0 ? void 0 : eoaConnector.verifiedCredentials;
|
|
358
|
-
const expectedEoaAddress = (_a = verifiedCredentials === null || verifiedCredentials === void 0 ? void 0 : verifiedCredentials.find((vc) => vc.smartWalletRefAddress === expectedAddress)) === null || _a === void 0 ? void 0 : _a.address;
|
|
359
|
-
if (!expectedEoaAddress) {
|
|
360
|
-
throw new DynamicError('No EOA connector');
|
|
361
|
-
}
|
|
362
|
-
yield (eoaConnector === null || eoaConnector === void 0 ? void 0 : eoaConnector.validateActiveWallet(expectedEoaAddress));
|
|
363
|
-
}
|
|
364
|
-
else {
|
|
365
|
-
yield _super.validateActiveWallet.call(this, expectedAddress);
|
|
414
|
+
const eoa = this.eoaConnectorMap[expectedAddress];
|
|
415
|
+
if (!eoa) {
|
|
416
|
+
throw new DynamicError('No EOA connector');
|
|
366
417
|
}
|
|
418
|
+
const { eoaAddress, eoaConnector } = eoa;
|
|
419
|
+
yield eoaConnector.validateActiveWallet(eoaAddress);
|
|
420
|
+
yield this.setEoaConnector(eoaAddress, eoaConnector);
|
|
367
421
|
});
|
|
368
422
|
}
|
|
369
423
|
}
|