@dynamic-labs/ethereum-aa 4.0.0-alpha.6 → 4.0.0-alpha.8
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 +32 -0
- package/package.cjs +1 -1
- package/package.js +1 -1
- package/package.json +8 -8
- package/src/ZeroDevConnector.cjs +130 -87
- package/src/ZeroDevConnector.d.ts +96 -86
- package/src/ZeroDevConnector.js +133 -90
- package/src/constants.cjs +8 -0
- package/src/constants.d.ts +1 -0
- package/src/constants.js +4 -0
- package/src/index.cjs +10 -0
- package/src/index.d.ts +5 -0
- package/src/index.js +5 -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,11 @@ 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
|
+
private providerMap;
|
|
30
28
|
ChainWallet: typeof EthereumWallet;
|
|
31
29
|
connectedChain: Chain;
|
|
32
30
|
supportedChains: Chain[];
|
|
@@ -36,6 +34,8 @@ export declare class ZeroDevConnector extends WalletConnectorBase<typeof Ethereu
|
|
|
36
34
|
entryPoint: EntryPoint;
|
|
37
35
|
kernelVersion: KERNEL_VERSION_TYPE;
|
|
38
36
|
ecdsaProviderType: string | undefined;
|
|
37
|
+
defaultChainId: string | undefined;
|
|
38
|
+
providersFromApi: ProviderMultichainAccountAbstractionProviders[];
|
|
39
39
|
static bundlerProvider: BundlerProvider | undefined;
|
|
40
40
|
static bundlerRpc: string | undefined;
|
|
41
41
|
static paymasterRpc: string | undefined;
|
|
@@ -56,9 +56,17 @@ export declare class ZeroDevConnector extends WalletConnectorBase<typeof Ethereu
|
|
|
56
56
|
};
|
|
57
57
|
private _walletUiUtils;
|
|
58
58
|
constructor(opts: ZeroDevConnectorProps);
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
59
|
+
get currentNetworkProvider(): {
|
|
60
|
+
kernelClient: KernelClient;
|
|
61
|
+
kernelClientWithSponsorship: KernelClient;
|
|
62
|
+
} | undefined;
|
|
63
|
+
get lastUsedChainId(): string;
|
|
64
|
+
get kernelClient(): KernelClient | undefined;
|
|
65
|
+
get kernelClientWithSponsorship(): KernelClient | undefined;
|
|
66
|
+
supportsNetworkSwitching(): boolean;
|
|
67
|
+
switchNetwork({ networkChainId, }: {
|
|
68
|
+
networkChainId?: number | string;
|
|
69
|
+
}): Promise<void>;
|
|
62
70
|
/**
|
|
63
71
|
* @deprecated You should get the EOA connector by passing the SCW to getEOAConnector,
|
|
64
72
|
* from the useSmartWallet hook
|
|
@@ -66,10 +74,12 @@ export declare class ZeroDevConnector extends WalletConnectorBase<typeof Ethereu
|
|
|
66
74
|
getEOAConnector(): InternalWalletConnector | undefined;
|
|
67
75
|
getAccountAbstractionProvider({ withSponsorship, }?: {
|
|
68
76
|
withSponsorship?: boolean;
|
|
69
|
-
}):
|
|
77
|
+
}): KernelClient | undefined;
|
|
70
78
|
endSession(): Promise<void>;
|
|
71
79
|
setEoaConnector(connector: InternalWalletConnector): Promise<void>;
|
|
72
|
-
private
|
|
80
|
+
private warnIfProjectChainNotEnabled;
|
|
81
|
+
private generateProviderMap;
|
|
82
|
+
private getKernelClientWithoutSponsorshipValidation;
|
|
73
83
|
private getKernelClientWithSponsorshipValidation;
|
|
74
84
|
getAddress(): Promise<string | undefined>;
|
|
75
85
|
getConnectedAccounts(): Promise<string[]>;
|
|
@@ -2895,44 +2905,44 @@ export declare class ZeroDevConnector extends WalletConnectorBase<typeof Ethereu
|
|
|
2895
2905
|
[x: `address[${string}]`]: undefined;
|
|
2896
2906
|
[x: `bool[${string}]`]: undefined;
|
|
2897
2907
|
[x: `bytes[${string}]`]: undefined;
|
|
2898
|
-
[x: `bytes9[${string}]`]: undefined;
|
|
2899
2908
|
[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
2909
|
[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
2910
|
[x: `bytes3[${string}]`]: undefined;
|
|
2911
|
+
[x: `bytes4[${string}]`]: undefined;
|
|
2912
|
+
[x: `bytes5[${string}]`]: undefined;
|
|
2913
|
+
[x: `bytes6[${string}]`]: undefined;
|
|
2914
|
+
[x: `bytes7[${string}]`]: undefined;
|
|
2915
|
+
[x: `bytes8[${string}]`]: undefined;
|
|
2916
|
+
[x: `bytes9[${string}]`]: undefined;
|
|
2917
|
+
[x: `bytes10[${string}]`]: undefined;
|
|
2918
|
+
[x: `bytes11[${string}]`]: undefined;
|
|
2919
|
+
[x: `bytes12[${string}]`]: undefined;
|
|
2920
|
+
[x: `bytes13[${string}]`]: undefined;
|
|
2921
|
+
[x: `bytes14[${string}]`]: undefined;
|
|
2922
|
+
[x: `bytes15[${string}]`]: undefined;
|
|
2923
|
+
[x: `bytes16[${string}]`]: undefined;
|
|
2924
|
+
[x: `bytes17[${string}]`]: undefined;
|
|
2925
|
+
[x: `bytes18[${string}]`]: undefined;
|
|
2926
|
+
[x: `bytes19[${string}]`]: undefined;
|
|
2927
|
+
[x: `bytes20[${string}]`]: undefined;
|
|
2928
|
+
[x: `bytes21[${string}]`]: undefined;
|
|
2929
|
+
[x: `bytes22[${string}]`]: undefined;
|
|
2930
|
+
[x: `bytes23[${string}]`]: undefined;
|
|
2931
|
+
[x: `bytes24[${string}]`]: undefined;
|
|
2932
|
+
[x: `bytes25[${string}]`]: undefined;
|
|
2933
|
+
[x: `bytes26[${string}]`]: undefined;
|
|
2934
|
+
[x: `bytes27[${string}]`]: undefined;
|
|
2935
|
+
[x: `bytes28[${string}]`]: undefined;
|
|
2936
|
+
[x: `bytes29[${string}]`]: undefined;
|
|
2937
|
+
[x: `bytes30[${string}]`]: undefined;
|
|
2938
|
+
[x: `bytes31[${string}]`]: undefined;
|
|
2939
|
+
[x: `bytes32[${string}]`]: undefined;
|
|
2930
2940
|
[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
2941
|
[x: `int8[${string}]`]: undefined;
|
|
2942
|
+
[x: `int16[${string}]`]: undefined;
|
|
2943
|
+
[x: `int24[${string}]`]: undefined;
|
|
2944
|
+
[x: `int32[${string}]`]: undefined;
|
|
2945
|
+
[x: `int40[${string}]`]: undefined;
|
|
2936
2946
|
[x: `int48[${string}]`]: undefined;
|
|
2937
2947
|
[x: `int56[${string}]`]: undefined;
|
|
2938
2948
|
[x: `int64[${string}]`]: undefined;
|
|
@@ -2961,11 +2971,11 @@ export declare class ZeroDevConnector extends WalletConnectorBase<typeof Ethereu
|
|
|
2961
2971
|
[x: `int248[${string}]`]: undefined;
|
|
2962
2972
|
[x: `int256[${string}]`]: undefined;
|
|
2963
2973
|
[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
2974
|
[x: `uint8[${string}]`]: undefined;
|
|
2975
|
+
[x: `uint16[${string}]`]: undefined;
|
|
2976
|
+
[x: `uint24[${string}]`]: undefined;
|
|
2977
|
+
[x: `uint32[${string}]`]: undefined;
|
|
2978
|
+
[x: `uint40[${string}]`]: undefined;
|
|
2969
2979
|
[x: `uint48[${string}]`]: undefined;
|
|
2970
2980
|
[x: `uint56[${string}]`]: undefined;
|
|
2971
2981
|
[x: `uint64[${string}]`]: undefined;
|
|
@@ -2997,43 +3007,43 @@ export declare class ZeroDevConnector extends WalletConnectorBase<typeof Ethereu
|
|
|
2997
3007
|
address?: undefined;
|
|
2998
3008
|
bool?: undefined;
|
|
2999
3009
|
bytes?: undefined;
|
|
3000
|
-
bytes9?: undefined;
|
|
3001
3010
|
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
3011
|
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
3012
|
bytes3?: undefined;
|
|
3032
|
-
|
|
3033
|
-
|
|
3034
|
-
|
|
3035
|
-
|
|
3013
|
+
bytes4?: undefined;
|
|
3014
|
+
bytes5?: undefined;
|
|
3015
|
+
bytes6?: undefined;
|
|
3016
|
+
bytes7?: undefined;
|
|
3017
|
+
bytes8?: undefined;
|
|
3018
|
+
bytes9?: undefined;
|
|
3019
|
+
bytes10?: undefined;
|
|
3020
|
+
bytes11?: undefined;
|
|
3021
|
+
bytes12?: undefined;
|
|
3022
|
+
bytes13?: undefined;
|
|
3023
|
+
bytes14?: undefined;
|
|
3024
|
+
bytes15?: undefined;
|
|
3025
|
+
bytes16?: undefined;
|
|
3026
|
+
bytes17?: undefined;
|
|
3027
|
+
bytes18?: undefined;
|
|
3028
|
+
bytes19?: undefined;
|
|
3029
|
+
bytes20?: undefined;
|
|
3030
|
+
bytes21?: undefined;
|
|
3031
|
+
bytes22?: undefined;
|
|
3032
|
+
bytes23?: undefined;
|
|
3033
|
+
bytes24?: undefined;
|
|
3034
|
+
bytes25?: undefined;
|
|
3035
|
+
bytes26?: undefined;
|
|
3036
|
+
bytes27?: undefined;
|
|
3037
|
+
bytes28?: undefined;
|
|
3038
|
+
bytes29?: undefined;
|
|
3039
|
+
bytes30?: undefined;
|
|
3040
|
+
bytes31?: undefined;
|
|
3041
|
+
bytes32?: undefined;
|
|
3036
3042
|
int8?: undefined;
|
|
3043
|
+
int16?: undefined;
|
|
3044
|
+
int24?: undefined;
|
|
3045
|
+
int32?: undefined;
|
|
3046
|
+
int40?: undefined;
|
|
3037
3047
|
int48?: undefined;
|
|
3038
3048
|
int56?: undefined;
|
|
3039
3049
|
int64?: undefined;
|
|
@@ -3061,11 +3071,11 @@ export declare class ZeroDevConnector extends WalletConnectorBase<typeof Ethereu
|
|
|
3061
3071
|
int240?: undefined;
|
|
3062
3072
|
int248?: undefined;
|
|
3063
3073
|
int256?: undefined;
|
|
3064
|
-
uint40?: undefined;
|
|
3065
|
-
uint32?: undefined;
|
|
3066
|
-
uint24?: undefined;
|
|
3067
|
-
uint16?: undefined;
|
|
3068
3074
|
uint8?: undefined;
|
|
3075
|
+
uint16?: undefined;
|
|
3076
|
+
uint24?: undefined;
|
|
3077
|
+
uint32?: undefined;
|
|
3078
|
+
uint40?: undefined;
|
|
3069
3079
|
uint48?: undefined;
|
|
3070
3080
|
uint56?: undefined;
|
|
3071
3081
|
uint64?: undefined;
|
package/src/ZeroDevConnector.js
CHANGED
|
@@ -1,27 +1,28 @@
|
|
|
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 { EthereumWallet, confirmationTransport, chainsMap, isEthWalletConnector, unFormatTransaction, createViemUiTransaction } from '@dynamic-labs/ethereum-core';
|
|
11
|
-
import { parseEvmNetworks, DynamicError, DeferredPromise, wrapMethodWithCallback, TransactionGasCannotBeSponsoredError, InsufficientFundsError } from '@dynamic-labs/utils';
|
|
12
|
-
import { cachedChainIdKey, fetchChain } from './utils/fetchChain.js';
|
|
4
|
+
import { walletClientToSmartAccountSigner } from 'permissionless/utils';
|
|
5
|
+
import { EthereumWallet, isEthWalletConnector, chainsMap, confirmationTransport, unFormatTransaction, createViemUiTransaction } from '@dynamic-labs/ethereum-core';
|
|
6
|
+
import { WalletConnectorBase, eventListenerHandlers, isTurnkeyWalletConnector } from '@dynamic-labs/wallet-connector-core';
|
|
7
|
+
import { parseEvmNetworks, StorageService, DeferredPromise, parseChainId, DynamicError, wrapMethodWithCallback, TransactionGasCannotBeSponsoredError, InsufficientFundsError } from '@dynamic-labs/utils';
|
|
8
|
+
import { ZERO_DEV_LAST_USED_CHAIN_ID_KEY } from './constants.js';
|
|
13
9
|
import { logger } from './utils/logger.js';
|
|
14
10
|
import { createEcdsaKernelAccountClient } from './utils/createEcsdaKernelAccountClient.js';
|
|
11
|
+
import { getEcdsaValidator } from './utils/getEcdsaValidator.js';
|
|
12
|
+
import { getEntryPoint } from './utils/getEntryPoint.js';
|
|
13
|
+
import { getKernelVersion } from './utils/getKernelVersion.js';
|
|
15
14
|
|
|
16
15
|
class ZeroDevConnector extends WalletConnectorBase {
|
|
17
16
|
constructor(opts) {
|
|
18
17
|
var _a, _b, _c, _d;
|
|
19
18
|
super(opts);
|
|
19
|
+
this.providerMap = {};
|
|
20
20
|
this.ChainWallet = EthereumWallet;
|
|
21
21
|
this.connectedChain = 'EVM';
|
|
22
22
|
this.supportedChains = ['ETH', 'EVM'];
|
|
23
23
|
this.isGasSponsorshipDisabled = false;
|
|
24
24
|
this.isEmbeddedWallet = true;
|
|
25
|
+
this.providersFromApi = [];
|
|
25
26
|
this.name = 'ZeroDev';
|
|
26
27
|
this.overrideKey = 'zerodev';
|
|
27
28
|
this.walletFallback = {
|
|
@@ -31,59 +32,64 @@ class ZeroDevConnector extends WalletConnectorBase {
|
|
|
31
32
|
},
|
|
32
33
|
name: 'ZeroDev',
|
|
33
34
|
};
|
|
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
35
|
this._walletUiUtils = opts.walletUiUtils;
|
|
40
36
|
this.evmNetworks = parseEvmNetworks(opts.evmNetworks);
|
|
41
|
-
this.entryPoint =
|
|
42
|
-
this.kernelVersion =
|
|
37
|
+
this.entryPoint = getEntryPoint((_a = opts.apiProviders.zerodev) === null || _a === void 0 ? void 0 : _a.entryPointVersion);
|
|
38
|
+
this.kernelVersion = getKernelVersion((_b = opts.apiProviders.zerodev) === null || _b === void 0 ? void 0 : _b.kernelVersion, this.entryPoint);
|
|
39
|
+
// this is the list of providers from the api that are used for multi-chain account abstraction
|
|
40
|
+
this.providersFromApi =
|
|
41
|
+
((_c = opts.apiProviders.zerodev) === null || _c === void 0 ? void 0 : _c.multichainAccountAbstractionProviders) || [];
|
|
42
|
+
const [defaultProvider] = this.providersFromApi;
|
|
43
|
+
this.clientId = defaultProvider === null || defaultProvider === void 0 ? void 0 : defaultProvider.clientId;
|
|
44
|
+
if (!this.clientId) {
|
|
45
|
+
throw new Error('Missing ZeroDev project ID provided. Add your ZeroDev project id to your project configuration via the Dynamic Labs dashboard.');
|
|
46
|
+
}
|
|
47
|
+
this.defaultChainId = defaultProvider === null || defaultProvider === void 0 ? void 0 : defaultProvider.chain;
|
|
43
48
|
this.ecdsaProviderType = (_d = opts.apiProviders.zerodev) === null || _d === void 0 ? void 0 : _d.ecdsaProviderType;
|
|
44
49
|
}
|
|
45
|
-
|
|
46
|
-
if
|
|
47
|
-
|
|
48
|
-
return
|
|
50
|
+
get currentNetworkProvider() {
|
|
51
|
+
// check if the last used chain id is in the provider map
|
|
52
|
+
if (this.providerMap[this.lastUsedChainId]) {
|
|
53
|
+
return this.providerMap[this.lastUsedChainId];
|
|
49
54
|
}
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
else {
|
|
54
|
-
logger.error('Invalid entry point version', entryPoint);
|
|
55
|
-
return ENTRYPOINT_ADDRESS_V07;
|
|
55
|
+
// if not, check if the default chain id is in the provider map
|
|
56
|
+
if (this.defaultChainId) {
|
|
57
|
+
return this.providerMap[this.defaultChainId];
|
|
56
58
|
}
|
|
59
|
+
// if no chain id is found, return undefined
|
|
60
|
+
return undefined;
|
|
57
61
|
}
|
|
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
|
-
}
|
|
62
|
+
get lastUsedChainId() {
|
|
63
|
+
var _a;
|
|
64
|
+
const storedChainId = StorageService.getItem(ZERO_DEV_LAST_USED_CHAIN_ID_KEY);
|
|
65
|
+
// returning string of unknown if no chain id is found to result in undefined provider lookup
|
|
66
|
+
return (_a = storedChainId !== null && storedChainId !== void 0 ? storedChainId : this.defaultChainId) !== null && _a !== void 0 ? _a : 'unknown';
|
|
76
67
|
}
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
68
|
+
get kernelClient() {
|
|
69
|
+
var _a;
|
|
70
|
+
return (_a = this.currentNetworkProvider) === null || _a === void 0 ? void 0 : _a.kernelClient;
|
|
71
|
+
}
|
|
72
|
+
get kernelClientWithSponsorship() {
|
|
73
|
+
var _a;
|
|
74
|
+
return (_a = this.currentNetworkProvider) === null || _a === void 0 ? void 0 : _a.kernelClientWithSponsorship;
|
|
75
|
+
}
|
|
76
|
+
supportsNetworkSwitching() {
|
|
77
|
+
return (Object.keys(this.providerMap).length > 1 && this.evmNetworks.length > 1);
|
|
78
|
+
}
|
|
79
|
+
switchNetwork(_a) {
|
|
80
|
+
return __awaiter(this, arguments, void 0, function* ({ networkChainId, }) {
|
|
81
|
+
if (!this.supportsNetworkSwitching())
|
|
82
|
+
return;
|
|
83
|
+
if (!networkChainId)
|
|
84
|
+
return;
|
|
85
|
+
const chainId = networkChainId.toString();
|
|
86
|
+
if (!this.providerMap[chainId]) {
|
|
87
|
+
throw new Error(`No provider found for chainId: ${chainId}`);
|
|
88
|
+
}
|
|
89
|
+
StorageService.setItem(ZERO_DEV_LAST_USED_CHAIN_ID_KEY, chainId);
|
|
90
|
+
const { handleChainChange } = eventListenerHandlers(this);
|
|
91
|
+
handleChainChange(chainId);
|
|
92
|
+
});
|
|
87
93
|
}
|
|
88
94
|
/**
|
|
89
95
|
* @deprecated You should get the EOA connector by passing the SCW to getEOAConnector,
|
|
@@ -100,7 +106,7 @@ class ZeroDevConnector extends WalletConnectorBase {
|
|
|
100
106
|
}
|
|
101
107
|
endSession() {
|
|
102
108
|
return __awaiter(this, void 0, void 0, function* () {
|
|
103
|
-
|
|
109
|
+
StorageService.removeItem(ZERO_DEV_LAST_USED_CHAIN_ID_KEY);
|
|
104
110
|
});
|
|
105
111
|
}
|
|
106
112
|
setEoaConnector(connector) {
|
|
@@ -120,15 +126,63 @@ class ZeroDevConnector extends WalletConnectorBase {
|
|
|
120
126
|
logger.error('No signer account found');
|
|
121
127
|
return;
|
|
122
128
|
}
|
|
129
|
+
yield this.generateProviderMap(signer);
|
|
130
|
+
this.evmNetworks = this.evmNetworks.filter((network) => Boolean(this.providerMap[network.chainId]));
|
|
131
|
+
this.kernelClientDeferredPromise.resolve();
|
|
132
|
+
});
|
|
133
|
+
}
|
|
134
|
+
warnIfProjectChainNotEnabled(chainId) {
|
|
135
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
136
|
+
var _a;
|
|
137
|
+
let chainIdToCheck = chainId;
|
|
138
|
+
if (!chainIdToCheck) {
|
|
139
|
+
const client = yield this.getPublicClient();
|
|
140
|
+
chainIdToCheck = (_a = client === null || client === void 0 ? void 0 : client.chain) === null || _a === void 0 ? void 0 : _a.id;
|
|
141
|
+
}
|
|
142
|
+
const isProjectChainEnabled = this.evmNetworks.some((network) => network.chainId === chainIdToCheck);
|
|
143
|
+
if (!isProjectChainEnabled) {
|
|
144
|
+
logger.error(`Please make sure to enable (${chainIdToCheck}) in the Dynamic dashboard (https://app.dynamic.xyz/dashboard/configurations#evm).`);
|
|
145
|
+
}
|
|
146
|
+
});
|
|
147
|
+
}
|
|
148
|
+
generateProviderMap(signer) {
|
|
149
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
150
|
+
for (const provider of this.providersFromApi) {
|
|
151
|
+
if (!this.providerMap[provider.chain]) {
|
|
152
|
+
this.providerMap[provider.chain] = {
|
|
153
|
+
kernelClient: yield this.getKernelClientWithoutSponsorshipValidation({
|
|
154
|
+
chainId: provider.chain,
|
|
155
|
+
projectId: provider.clientId,
|
|
156
|
+
signer,
|
|
157
|
+
}),
|
|
158
|
+
kernelClientWithSponsorship: yield this.getKernelClientWithSponsorshipValidation({
|
|
159
|
+
chainId: provider.chain,
|
|
160
|
+
projectId: provider.clientId,
|
|
161
|
+
signer,
|
|
162
|
+
}),
|
|
163
|
+
};
|
|
164
|
+
}
|
|
165
|
+
yield this.warnIfProjectChainNotEnabled(parseChainId(provider.chain));
|
|
166
|
+
}
|
|
167
|
+
});
|
|
168
|
+
}
|
|
169
|
+
getKernelClientWithoutSponsorshipValidation(_a) {
|
|
170
|
+
return __awaiter(this, arguments, void 0, function* ({ projectId, signer, chainId, }) {
|
|
171
|
+
if (chainId && this.providerMap[chainId]) {
|
|
172
|
+
return this.providerMap[chainId].kernelClient;
|
|
173
|
+
}
|
|
174
|
+
const { eoaConnector } = this;
|
|
175
|
+
if (!eoaConnector)
|
|
176
|
+
throw new DynamicError('No EOA connector');
|
|
123
177
|
const kernelClient = yield createEcdsaKernelAccountClient({
|
|
124
178
|
bundlerRpc: ZeroDevConnector.bundlerRpc,
|
|
125
|
-
chain:
|
|
126
|
-
ecdsaValidator:
|
|
179
|
+
chain: chainsMap[chainId],
|
|
180
|
+
ecdsaValidator: getEcdsaValidator(this.ecdsaProviderType),
|
|
127
181
|
entryPointAddress: this.entryPoint,
|
|
128
182
|
kernelVersion: this.kernelVersion,
|
|
129
183
|
paymaster: 'NONE',
|
|
130
184
|
paymasterRpc: ZeroDevConnector.paymasterRpc,
|
|
131
|
-
projectId
|
|
185
|
+
projectId,
|
|
132
186
|
provider: ZeroDevConnector.bundlerProvider,
|
|
133
187
|
signer: walletClientToSmartAccountSigner(signer),
|
|
134
188
|
});
|
|
@@ -136,51 +190,34 @@ class ZeroDevConnector extends WalletConnectorBase {
|
|
|
136
190
|
this._walletUiUtils.disabledConfirmationOnce();
|
|
137
191
|
return original(...args);
|
|
138
192
|
});
|
|
139
|
-
|
|
140
|
-
// set the provider with sponsorship enabled
|
|
141
|
-
yield this.getKernelClientWithSponsorshipValidation();
|
|
142
|
-
yield this.checkIsProjectChainEnabled();
|
|
143
|
-
this.kernelClientDeferredPromise.resolve();
|
|
144
|
-
});
|
|
145
|
-
}
|
|
146
|
-
checkIsProjectChainEnabled() {
|
|
147
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
148
|
-
var _a, _b;
|
|
149
|
-
const client = yield this.getPublicClient();
|
|
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
|
-
}
|
|
193
|
+
return kernelClient;
|
|
156
194
|
});
|
|
157
195
|
}
|
|
158
|
-
getKernelClientWithSponsorshipValidation() {
|
|
159
|
-
return __awaiter(this,
|
|
160
|
-
if (this.
|
|
161
|
-
return this.kernelClientWithSponsorship;
|
|
196
|
+
getKernelClientWithSponsorshipValidation(_a) {
|
|
197
|
+
return __awaiter(this, arguments, void 0, function* ({ projectId, signer, chainId, }) {
|
|
198
|
+
if (chainId && this.providerMap[chainId]) {
|
|
199
|
+
return this.providerMap[chainId].kernelClientWithSponsorship;
|
|
162
200
|
}
|
|
163
201
|
const { eoaConnector } = this;
|
|
164
202
|
if (!eoaConnector)
|
|
165
203
|
throw new DynamicError('No EOA connector');
|
|
166
|
-
const
|
|
167
|
-
this.kernelClientWithSponsorship = yield createEcdsaKernelAccountClient({
|
|
204
|
+
const kernelClientWithSponsorship = yield createEcdsaKernelAccountClient({
|
|
168
205
|
bundlerRpc: ZeroDevConnector.bundlerRpc,
|
|
169
|
-
chain:
|
|
170
|
-
ecdsaValidator:
|
|
206
|
+
chain: chainsMap[chainId],
|
|
207
|
+
ecdsaValidator: getEcdsaValidator(this.ecdsaProviderType),
|
|
171
208
|
entryPointAddress: this.entryPoint,
|
|
172
209
|
kernelVersion: this.kernelVersion,
|
|
173
210
|
paymaster: 'SPONSOR',
|
|
174
211
|
paymasterRpc: ZeroDevConnector.paymasterRpc,
|
|
175
|
-
projectId
|
|
212
|
+
projectId,
|
|
176
213
|
provider: ZeroDevConnector.bundlerProvider,
|
|
177
214
|
signer: walletClientToSmartAccountSigner(signer),
|
|
178
215
|
});
|
|
179
|
-
wrapMethodWithCallback(
|
|
216
|
+
wrapMethodWithCallback(kernelClientWithSponsorship, 'sendUserOperation', (original, ...args) => {
|
|
180
217
|
this._walletUiUtils.disabledConfirmationOnce();
|
|
181
218
|
return original(...args);
|
|
182
219
|
});
|
|
183
|
-
return
|
|
220
|
+
return kernelClientWithSponsorship;
|
|
184
221
|
});
|
|
185
222
|
}
|
|
186
223
|
getAddress() {
|
|
@@ -221,7 +258,10 @@ class ZeroDevConnector extends WalletConnectorBase {
|
|
|
221
258
|
this._walletUiUtils.disabledConfirmationOnce();
|
|
222
259
|
const effectiveProvider = this.isGasSponsorshipDisabled
|
|
223
260
|
? provider
|
|
224
|
-
:
|
|
261
|
+
: this.kernelClientWithSponsorship;
|
|
262
|
+
if (!effectiveProvider) {
|
|
263
|
+
throw new DynamicError('No provider');
|
|
264
|
+
}
|
|
225
265
|
const response = yield effectiveProvider.sendTransaction(unFormatTransaction(transaction));
|
|
226
266
|
return response;
|
|
227
267
|
}
|
|
@@ -259,7 +299,7 @@ class ZeroDevConnector extends WalletConnectorBase {
|
|
|
259
299
|
var _a;
|
|
260
300
|
const provider = this.kernelClient;
|
|
261
301
|
if (!provider)
|
|
262
|
-
|
|
302
|
+
return undefined;
|
|
263
303
|
const transport = this.getTransport(provider);
|
|
264
304
|
const address = (_a = provider.account) === null || _a === void 0 ? void 0 : _a.address;
|
|
265
305
|
const walletClient = createWalletClient({
|
|
@@ -274,7 +314,7 @@ class ZeroDevConnector extends WalletConnectorBase {
|
|
|
274
314
|
var _a;
|
|
275
315
|
const provider = (_a = this.kernelClient) === null || _a === void 0 ? void 0 : _a.extend(publicActions);
|
|
276
316
|
if (!provider)
|
|
277
|
-
|
|
317
|
+
return undefined;
|
|
278
318
|
return provider;
|
|
279
319
|
});
|
|
280
320
|
}
|
|
@@ -286,7 +326,10 @@ class ZeroDevConnector extends WalletConnectorBase {
|
|
|
286
326
|
canSponsorTransactionGas(transaction) {
|
|
287
327
|
return __awaiter(this, void 0, void 0, function* () {
|
|
288
328
|
try {
|
|
289
|
-
const kernelClientWithSponsorship =
|
|
329
|
+
const { kernelClientWithSponsorship } = this;
|
|
330
|
+
if (!kernelClientWithSponsorship) {
|
|
331
|
+
throw new DynamicError('No kernel client with sponsorship found');
|
|
332
|
+
}
|
|
290
333
|
const userOperation = {
|
|
291
334
|
callData: yield kernelClientWithSponsorship.account.encodeCallData({
|
|
292
335
|
data: transaction.data ? transaction.data : '0x',
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const ZERO_DEV_LAST_USED_CHAIN_ID_KEY = "dynamic_zerodev_last_used_chain_id";
|
package/src/constants.js
ADDED
package/src/index.cjs
CHANGED
|
@@ -6,6 +6,11 @@ Object.defineProperty(exports, '__esModule', { value: true });
|
|
|
6
6
|
var assertPackageVersion = require('@dynamic-labs/assert-package-version');
|
|
7
7
|
var _package = require('../package.cjs');
|
|
8
8
|
var ZeroDevConnector = require('./ZeroDevConnector.cjs');
|
|
9
|
+
var createEcsdaKernelAccountClient = require('./utils/createEcsdaKernelAccountClient.cjs');
|
|
10
|
+
var fetchZeroDevChain = require('./utils/fetchZeroDevChain.cjs');
|
|
11
|
+
var getEcdsaValidator = require('./utils/getEcdsaValidator.cjs');
|
|
12
|
+
var getEntryPoint = require('./utils/getEntryPoint.cjs');
|
|
13
|
+
var getKernelVersion = require('./utils/getKernelVersion.cjs');
|
|
9
14
|
var ethereumAa = require('./ethereum-aa.cjs');
|
|
10
15
|
var isZeroDevConnector = require('./utils/isZeroDevConnector.cjs');
|
|
11
16
|
|
|
@@ -24,6 +29,11 @@ const ZeroDevSmartWalletConnectors = (props) => {
|
|
|
24
29
|
return [];
|
|
25
30
|
};
|
|
26
31
|
|
|
32
|
+
exports.createEcdsaKernelAccountClient = createEcsdaKernelAccountClient.createEcdsaKernelAccountClient;
|
|
33
|
+
exports.fetchZeroDevChain = fetchZeroDevChain.fetchZeroDevChain;
|
|
34
|
+
exports.getEcdsaValidator = getEcdsaValidator.getEcdsaValidator;
|
|
35
|
+
exports.getEntryPoint = getEntryPoint.getEntryPoint;
|
|
36
|
+
exports.getKernelVersion = getKernelVersion.getKernelVersion;
|
|
27
37
|
exports.EthereumAaConnector = ethereumAa.EthereumAaConnector;
|
|
28
38
|
exports.isZeroDevConnector = isZeroDevConnector.isZeroDevConnector;
|
|
29
39
|
exports.ZeroDevSmartWalletConnectors = ZeroDevSmartWalletConnectors;
|
package/src/index.d.ts
CHANGED
|
@@ -1,5 +1,10 @@
|
|
|
1
1
|
import { WalletConnectorConstructor } from '@dynamic-labs/wallet-connector-core';
|
|
2
2
|
import { BundlerProvider } from './utils';
|
|
3
|
+
export { createEcdsaKernelAccountClient, type BundlerProvider, type PaymasterType, } from './utils/createEcsdaKernelAccountClient';
|
|
4
|
+
export { fetchZeroDevChain } from './utils/fetchZeroDevChain';
|
|
5
|
+
export { getEcdsaValidator } from './utils/getEcdsaValidator';
|
|
6
|
+
export { getEntryPoint } from './utils/getEntryPoint';
|
|
7
|
+
export { getKernelVersion } from './utils/getKernelVersion';
|
|
3
8
|
export * from './ethereum-aa';
|
|
4
9
|
export { isZeroDevConnector } from './utils/isZeroDevConnector';
|
|
5
10
|
export declare const ZeroDevSmartWalletConnectorsWithConfig: ({ bundlerProvider, bundlerRpc, paymasterRpc, }?: {
|
package/src/index.js
CHANGED
|
@@ -2,6 +2,11 @@
|
|
|
2
2
|
import { assertPackageVersion } from '@dynamic-labs/assert-package-version';
|
|
3
3
|
import { version } from '../package.js';
|
|
4
4
|
import { ZeroDevConnector } from './ZeroDevConnector.js';
|
|
5
|
+
export { createEcdsaKernelAccountClient } from './utils/createEcsdaKernelAccountClient.js';
|
|
6
|
+
export { fetchZeroDevChain } from './utils/fetchZeroDevChain.js';
|
|
7
|
+
export { getEcdsaValidator } from './utils/getEcdsaValidator.js';
|
|
8
|
+
export { getEntryPoint } from './utils/getEntryPoint.js';
|
|
9
|
+
export { getKernelVersion } from './utils/getKernelVersion.js';
|
|
5
10
|
export { EthereumAaConnector } from './ethereum-aa.js';
|
|
6
11
|
export { isZeroDevConnector } from './utils/isZeroDevConnector.js';
|
|
7
12
|
|