@dynamic-labs/ethereum 3.0.0-alpha.4 → 3.0.0-alpha.6
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 +41 -0
- package/package.json +9 -9
- package/src/EthWalletConnector.cjs +50 -7
- package/src/EthWalletConnector.d.ts +25 -19
- package/src/EthWalletConnector.js +51 -8
- package/src/coinbase/coinbase.cjs +1 -1
- package/src/coinbase/coinbase.d.ts +2 -7124
- package/src/coinbase/coinbase.js +1 -1
- package/src/ethProviderHelper.cjs +2 -3
- package/src/ethProviderHelper.d.ts +6 -2
- package/src/ethProviderHelper.js +2 -3
- package/src/index.cjs +3 -0
- package/src/index.js +3 -0
- package/src/injected/FallbackEvmConnector.cjs +22 -0
- package/src/injected/FallbackEvmConnector.d.ts +9 -0
- package/src/injected/FallbackEvmConnector.js +18 -0
- package/src/injected/InjectedWalletBase.d.ts +2 -2
- package/src/injected/index.d.ts +1 -0
- package/src/walletConnect/walletConnect.d.ts +2 -7124
- package/src/eip6963Provider.cjs +0 -40
- package/src/eip6963Provider.d.ts +0 -25
- package/src/eip6963Provider.js +0 -35
package/CHANGELOG.md
CHANGED
|
@@ -1,4 +1,45 @@
|
|
|
1
1
|
|
|
2
|
+
## [3.0.0-alpha.6](https://github.com/dynamic-labs/DynamicAuth/compare/v3.0.0-alpha.5...v3.0.0-alpha.6) (2024-06-18)
|
|
3
|
+
|
|
4
|
+
|
|
5
|
+
### Features
|
|
6
|
+
|
|
7
|
+
* implement useExternalAuth hook to signin using external jwt auth ([#6039](https://github.com/dynamic-labs/DynamicAuth/issues/6039)) ([ba90908](https://github.com/dynamic-labs/DynamicAuth/commit/ba90908509ec21f708a4a0782a7f94861fc3b484))
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
### Bug Fixes
|
|
11
|
+
|
|
12
|
+
* allow sign-in with different ME BTC wallet after initial connection ([a527b46](https://github.com/dynamic-labs/DynamicAuth/commit/a527b464f321b4fc27730f57c3812e996b5ed878))
|
|
13
|
+
* close sign modal when signing in with a wallet when embedded wallet is enabled ([#6013](https://github.com/dynamic-labs/DynamicAuth/issues/6013)) ([0f4f3c8](https://github.com/dynamic-labs/DynamicAuth/commit/0f4f3c83db162f7a1794a3549b60bbad6b03e2c0))
|
|
14
|
+
* custom network without a valid icon should still display its name in network picker ([#6018](https://github.com/dynamic-labs/DynamicAuth/issues/6018)) ([0b10df6](https://github.com/dynamic-labs/DynamicAuth/commit/0b10df68950bfc9b8492443158a6bb030dc1122c))
|
|
15
|
+
* e2e: remove page pause ([#6045](https://github.com/dynamic-labs/DynamicAuth/issues/6045)) ([55bba00](https://github.com/dynamic-labs/DynamicAuth/commit/55bba0034255055d6ae266b1296542f47ed48e2b))
|
|
16
|
+
* more fixes for connect starknet button ([#6046](https://github.com/dynamic-labs/DynamicAuth/issues/6046)) ([0fb570a](https://github.com/dynamic-labs/DynamicAuth/commit/0fb570a44e65f8dd6d4d2bf5edb2ee54985ec9d4))
|
|
17
|
+
* set verified credentials on embedded wallet creation ([#6044](https://github.com/dynamic-labs/DynamicAuth/issues/6044)) ([b52a96d](https://github.com/dynamic-labs/DynamicAuth/commit/b52a96d321e7efdb30dce9cdb3f6f176c24ceb81))
|
|
18
|
+
|
|
19
|
+
## [3.0.0-alpha.5](https://github.com/dynamic-labs/DynamicAuth/compare/v3.0.0-alpha.4...v3.0.0-alpha.5) (2024-06-14)
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
### ⚠ BREAKING CHANGES
|
|
23
|
+
|
|
24
|
+
* remove viem dependency from non-evm packages (#5508)
|
|
25
|
+
* move rpc providers into their own packages (#5981)
|
|
26
|
+
|
|
27
|
+
### Features
|
|
28
|
+
|
|
29
|
+
* add in-app browser navigation support for sats-connect ([#5988](https://github.com/dynamic-labs/DynamicAuth/issues/5988)) ([be27d2d](https://github.com/dynamic-labs/DynamicAuth/commit/be27d2d4030bbe2157e879497d8e6a00b4a3e404))
|
|
30
|
+
* move rpc providers into their own packages ([#5981](https://github.com/dynamic-labs/DynamicAuth/issues/5981)) ([d7a62d6](https://github.com/dynamic-labs/DynamicAuth/commit/d7a62d60e79dfa6d6651b0fa103e90b6f8a9ccf3))
|
|
31
|
+
|
|
32
|
+
|
|
33
|
+
### Bug Fixes
|
|
34
|
+
|
|
35
|
+
* embedded solana wallets can send SPL tokens and estimate gas ([#5982](https://github.com/dynamic-labs/DynamicAuth/issues/5982)) ([36623eb](https://github.com/dynamic-labs/DynamicAuth/commit/36623eb99d1d1dfebfd8b6f3194eeff31e7de2bf))
|
|
36
|
+
* improve logic related to turnkey and emailVerifcation ([#5946](https://github.com/dynamic-labs/DynamicAuth/issues/5946)) ([dd0b2dc](https://github.com/dynamic-labs/DynamicAuth/commit/dd0b2dc6d93a8bbbcb6eef88732e62b747005bb3))
|
|
37
|
+
* show linked wallets with unavailable providers in user wallets list ([#5992](https://github.com/dynamic-labs/DynamicAuth/issues/5992)) ([996079c](https://github.com/dynamic-labs/DynamicAuth/commit/996079ced360651c7b1eb5273548e0548f6f9f3a))
|
|
38
|
+
* switch network modal not closing after switching to a supported network ([#5979](https://github.com/dynamic-labs/DynamicAuth/issues/5979)) ([f239952](https://github.com/dynamic-labs/DynamicAuth/commit/f2399523dd82bb28046992cac4582688b688bdc0))
|
|
39
|
+
|
|
40
|
+
|
|
41
|
+
* remove viem dependency from non-evm packages ([#5508](https://github.com/dynamic-labs/DynamicAuth/issues/5508)) ([0299dc3](https://github.com/dynamic-labs/DynamicAuth/commit/0299dc3cbb611182d763e9a89d1270c2e2f32df5))
|
|
42
|
+
|
|
2
43
|
## [3.0.0-alpha.4](https://github.com/dynamic-labs/DynamicAuth/compare/v3.0.0-alpha.3...v3.0.0-alpha.4) (2024-06-12)
|
|
3
44
|
|
|
4
45
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@dynamic-labs/ethereum",
|
|
3
|
-
"version": "3.0.0-alpha.
|
|
3
|
+
"version": "3.0.0-alpha.6",
|
|
4
4
|
"repository": {
|
|
5
5
|
"type": "git",
|
|
6
6
|
"url": "git+https://github.com/dynamic-labs/dynamic-auth.git",
|
|
@@ -26,18 +26,18 @@
|
|
|
26
26
|
"./package.json": "./package.json"
|
|
27
27
|
},
|
|
28
28
|
"dependencies": {
|
|
29
|
-
"@dynamic-labs/sdk-api-core": "0.0.
|
|
29
|
+
"@dynamic-labs/sdk-api-core": "0.0.470",
|
|
30
30
|
"@coinbase/wallet-sdk": "4.0.3",
|
|
31
31
|
"@walletconnect/ethereum-provider": "2.11.2",
|
|
32
32
|
"eventemitter3": "5.0.1",
|
|
33
33
|
"buffer": "6.0.3",
|
|
34
|
-
"@dynamic-labs/rpc-provider-ethereum": "3.0.0-alpha.
|
|
35
|
-
"@dynamic-labs/turnkey": "3.0.0-alpha.
|
|
36
|
-
"@dynamic-labs/types": "3.0.0-alpha.
|
|
37
|
-
"@dynamic-labs/utils": "3.0.0-alpha.
|
|
38
|
-
"@dynamic-labs/viem-utils": "3.0.0-alpha.
|
|
39
|
-
"@dynamic-labs/wallet-book": "3.0.0-alpha.
|
|
40
|
-
"@dynamic-labs/wallet-connector-core": "3.0.0-alpha.
|
|
34
|
+
"@dynamic-labs/rpc-provider-ethereum": "3.0.0-alpha.6",
|
|
35
|
+
"@dynamic-labs/turnkey": "3.0.0-alpha.6",
|
|
36
|
+
"@dynamic-labs/types": "3.0.0-alpha.6",
|
|
37
|
+
"@dynamic-labs/utils": "3.0.0-alpha.6",
|
|
38
|
+
"@dynamic-labs/viem-utils": "3.0.0-alpha.6",
|
|
39
|
+
"@dynamic-labs/wallet-book": "3.0.0-alpha.6",
|
|
40
|
+
"@dynamic-labs/wallet-connector-core": "3.0.0-alpha.6",
|
|
41
41
|
"stream": "0.0.2"
|
|
42
42
|
},
|
|
43
43
|
"peerDependencies": {
|
|
@@ -6,15 +6,16 @@ Object.defineProperty(exports, '__esModule', { value: true });
|
|
|
6
6
|
var _tslib = require('../_virtual/_tslib.cjs');
|
|
7
7
|
var viem = require('viem');
|
|
8
8
|
var accounts = require('viem/accounts');
|
|
9
|
-
var walletConnectorCore = require('@dynamic-labs/wallet-connector-core');
|
|
10
9
|
var utils = require('@dynamic-labs/utils');
|
|
10
|
+
var viemUtils = require('@dynamic-labs/viem-utils');
|
|
11
|
+
var walletConnectorCore = require('@dynamic-labs/wallet-connector-core');
|
|
11
12
|
var findEvmNetwork = require('./utils/findEvmNetwork.cjs');
|
|
12
13
|
var getNameservice = require('./utils/getNameservice.cjs');
|
|
13
14
|
|
|
14
15
|
class EthWalletConnector extends walletConnectorCore.WalletConnectorBase {
|
|
15
16
|
getPublicClient() {
|
|
16
17
|
return _tslib.__awaiter(this, void 0, void 0, function* () {
|
|
17
|
-
var _a, _b
|
|
18
|
+
var _a, _b;
|
|
18
19
|
const networkId = (_a = (yield this.getNetwork())) !== null && _a !== void 0 ? _a : 1;
|
|
19
20
|
if (this.evmNetworks.length === 0) {
|
|
20
21
|
return undefined;
|
|
@@ -25,7 +26,10 @@ class EthWalletConnector extends walletConnectorCore.WalletConnectorBase {
|
|
|
25
26
|
solana: [],
|
|
26
27
|
starknet: undefined,
|
|
27
28
|
};
|
|
28
|
-
|
|
29
|
+
if (!this.chainRpcProviders)
|
|
30
|
+
return undefined;
|
|
31
|
+
const providers = this.chainRpcProviders.getProviders(configurations);
|
|
32
|
+
return (_b = this.chainRpcProviders.getEvmProviderByChainId(providers, networkId)) === null || _b === void 0 ? void 0 : _b.provider;
|
|
29
33
|
});
|
|
30
34
|
}
|
|
31
35
|
constructor(props) {
|
|
@@ -48,7 +52,7 @@ class EthWalletConnector extends walletConnectorCore.WalletConnectorBase {
|
|
|
48
52
|
if (!this.supportsNetworkSwitching || !provider) {
|
|
49
53
|
return Promise.resolve(undefined);
|
|
50
54
|
}
|
|
51
|
-
|
|
55
|
+
const chainId = yield utils.retryableFn(provider.getChainId, {
|
|
52
56
|
fallbackValue: utils.FALLBACK_UNDEFINED,
|
|
53
57
|
/**
|
|
54
58
|
* The timeout is set to 1 second because the getChainId method
|
|
@@ -58,6 +62,8 @@ class EthWalletConnector extends walletConnectorCore.WalletConnectorBase {
|
|
|
58
62
|
*/
|
|
59
63
|
timeoutMs: 1000,
|
|
60
64
|
});
|
|
65
|
+
this.setActiveChain(viemUtils.chainsMap[chainId]);
|
|
66
|
+
return chainId;
|
|
61
67
|
});
|
|
62
68
|
}
|
|
63
69
|
getNameService() {
|
|
@@ -72,6 +78,23 @@ class EthWalletConnector extends walletConnectorCore.WalletConnectorBase {
|
|
|
72
78
|
return getNameservice.getNameservice({ address, rpcProvider });
|
|
73
79
|
});
|
|
74
80
|
}
|
|
81
|
+
isTestnet() {
|
|
82
|
+
return _tslib.__awaiter(this, void 0, void 0, function* () {
|
|
83
|
+
var _a, _b, _c;
|
|
84
|
+
return (_c = (_b = (_a = (yield this.getPublicClient())) === null || _a === void 0 ? void 0 : _a.chain) === null || _b === void 0 ? void 0 : _b.testnet) !== null && _c !== void 0 ? _c : false;
|
|
85
|
+
});
|
|
86
|
+
}
|
|
87
|
+
parseAddress(address) {
|
|
88
|
+
try {
|
|
89
|
+
// Ensures the address follows the EIP55 format.
|
|
90
|
+
// see: https://eips.ethereum.org/EIPS/eip-55
|
|
91
|
+
return viem.getAddress(address);
|
|
92
|
+
}
|
|
93
|
+
catch (err) {
|
|
94
|
+
walletConnectorCore.logger.debug(`Failed to parse EVM address into EIP55 format: error getting checksum, returning default ${address}`, err);
|
|
95
|
+
}
|
|
96
|
+
return address;
|
|
97
|
+
}
|
|
75
98
|
getSigner() {
|
|
76
99
|
return _tslib.__awaiter(this, void 0, void 0, function* () {
|
|
77
100
|
return this.getWalletClient();
|
|
@@ -123,7 +146,7 @@ class EthWalletConnector extends walletConnectorCore.WalletConnectorBase {
|
|
|
123
146
|
return [];
|
|
124
147
|
const addresses = yield utils.retryableFn(provider.getAddresses, {
|
|
125
148
|
fallbackValue: [],
|
|
126
|
-
timeoutMs:
|
|
149
|
+
timeoutMs: 500,
|
|
127
150
|
});
|
|
128
151
|
if (addresses.length) {
|
|
129
152
|
this.setActiveAccount(addresses[0]);
|
|
@@ -143,11 +166,15 @@ class EthWalletConnector extends walletConnectorCore.WalletConnectorBase {
|
|
|
143
166
|
if (!this.supportsNetworkSwitching()) {
|
|
144
167
|
throw new utils.DynamicError('Network switching is not supported');
|
|
145
168
|
}
|
|
146
|
-
|
|
169
|
+
const viemChain = viemUtils.getOrMapViemChain(network);
|
|
170
|
+
yield provider.switchChain(viemChain);
|
|
147
171
|
if (this.key === 'magiceden') {
|
|
148
172
|
const newChainId = yield provider.getChainId();
|
|
149
173
|
this.emit('chainChange', { chain: newChainId.toString() });
|
|
150
174
|
}
|
|
175
|
+
else {
|
|
176
|
+
this.setActiveChain(viemChain);
|
|
177
|
+
}
|
|
151
178
|
}
|
|
152
179
|
catch (error) {
|
|
153
180
|
// we need to check for unrecognized chain error first because it also contains 'rejected' in message
|
|
@@ -173,7 +200,7 @@ class EthWalletConnector extends walletConnectorCore.WalletConnectorBase {
|
|
|
173
200
|
return _tslib.__awaiter(this, arguments, void 0, function* ({ network, provider, }) {
|
|
174
201
|
var _b;
|
|
175
202
|
try {
|
|
176
|
-
return yield provider.addChain({ chain:
|
|
203
|
+
return yield provider.addChain({ chain: viemUtils.getOrMapViemChain(network) });
|
|
177
204
|
}
|
|
178
205
|
catch (error) {
|
|
179
206
|
if (((_b = error.message) === null || _b === void 0 ? void 0 : _b.includes('rejected')) ||
|
|
@@ -192,6 +219,22 @@ class EthWalletConnector extends walletConnectorCore.WalletConnectorBase {
|
|
|
192
219
|
getActiveAccount() {
|
|
193
220
|
return this.activeAccount;
|
|
194
221
|
}
|
|
222
|
+
setActiveChain(chain) {
|
|
223
|
+
this.activeChain = chain;
|
|
224
|
+
}
|
|
225
|
+
getActiveChain() {
|
|
226
|
+
return this.activeChain;
|
|
227
|
+
}
|
|
228
|
+
createUiTransaction(from) {
|
|
229
|
+
return _tslib.__awaiter(this, void 0, void 0, function* () {
|
|
230
|
+
const walletClient = yield this.getWalletClient();
|
|
231
|
+
const publicClient = yield this.getPublicClient();
|
|
232
|
+
if (!publicClient || !walletClient) {
|
|
233
|
+
throw new utils.DynamicError('No public client available');
|
|
234
|
+
}
|
|
235
|
+
return viemUtils.createViemUiTransaction({ from, publicClient, walletClient });
|
|
236
|
+
});
|
|
237
|
+
}
|
|
195
238
|
}
|
|
196
239
|
|
|
197
240
|
exports.EthWalletConnector = EthWalletConnector;
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { NameServiceData, WalletConnectorBase } from '@dynamic-labs/wallet-connector-core';
|
|
3
|
-
import { EvmNetwork, GenericNetwork } from '@dynamic-labs/types';
|
|
1
|
+
import { Account, Hex, PublicClient, Transport, Chain as ViemChain, WalletClient } from 'viem';
|
|
4
2
|
import { IChainRpcProviders } from '@dynamic-labs/rpc-provider-ethereum';
|
|
3
|
+
import { EvmNetwork, GenericNetwork, IUITransaction } from '@dynamic-labs/types';
|
|
5
4
|
import { WalletBookSchema } from '@dynamic-labs/wallet-book';
|
|
5
|
+
import { ISendBalanceWalletConnector, NameServiceData, WalletConnectorBase } from '@dynamic-labs/wallet-connector-core';
|
|
6
6
|
export type SwitchNetworkOps = {
|
|
7
7
|
networkChainId?: number;
|
|
8
8
|
networkName?: string;
|
|
@@ -15,16 +15,19 @@ export type EthWalletConnectorOpts = {
|
|
|
15
15
|
evmNetworks: GenericNetwork[];
|
|
16
16
|
walletBook: WalletBookSchema;
|
|
17
17
|
};
|
|
18
|
-
export declare abstract class EthWalletConnector extends WalletConnectorBase {
|
|
18
|
+
export declare abstract class EthWalletConnector extends WalletConnectorBase implements ISendBalanceWalletConnector {
|
|
19
19
|
evmNetworks: EvmNetwork[];
|
|
20
20
|
private activeAccount;
|
|
21
|
-
|
|
22
|
-
|
|
21
|
+
private activeChain;
|
|
22
|
+
abstract getWalletClient(chainId?: string): WalletClient<Transport, ViemChain, Account> | undefined;
|
|
23
|
+
getPublicClient(): Promise<void | PublicClient<Transport, ViemChain> | undefined>;
|
|
23
24
|
constructor(props: EthWalletConnectorOpts);
|
|
24
25
|
getNetwork(): Promise<number | undefined>;
|
|
25
26
|
getNameService(): Promise<NameServiceData | undefined>;
|
|
27
|
+
isTestnet(): Promise<boolean>;
|
|
28
|
+
parseAddress(address: string): string;
|
|
26
29
|
getSigner(): Promise<{
|
|
27
|
-
account: Account
|
|
30
|
+
account: Account;
|
|
28
31
|
batch?: {
|
|
29
32
|
multicall?: boolean | {
|
|
30
33
|
batchSize?: number | undefined;
|
|
@@ -35,7 +38,7 @@ export declare abstract class EthWalletConnector extends WalletConnectorBase {
|
|
|
35
38
|
ccipRead?: false | {
|
|
36
39
|
request?: ((parameters: import("viem").CcipRequestParameters) => Promise<`0x${string}`>) | undefined;
|
|
37
40
|
} | undefined;
|
|
38
|
-
chain:
|
|
41
|
+
chain: ViemChain;
|
|
39
42
|
key: string;
|
|
40
43
|
name: string;
|
|
41
44
|
pollingInterval: number;
|
|
@@ -44,15 +47,15 @@ export declare abstract class EthWalletConnector extends WalletConnectorBase {
|
|
|
44
47
|
type: string;
|
|
45
48
|
uid: string;
|
|
46
49
|
addChain: (args: import("viem").AddChainParameters) => Promise<void>;
|
|
47
|
-
deployContract: <const abi extends import("viem").Abi | readonly unknown[], chainOverride extends
|
|
50
|
+
deployContract: <const abi extends import("viem").Abi | readonly unknown[], chainOverride extends ViemChain | undefined>(args: import("viem").DeployContractParameters<abi, ViemChain, Account, chainOverride>) => Promise<`0x${string}`>;
|
|
48
51
|
getAddresses: () => Promise<import("viem").GetAddressesReturnType>;
|
|
49
52
|
getChainId: () => Promise<number>;
|
|
50
53
|
getPermissions: () => Promise<import("viem").GetPermissionsReturnType>;
|
|
51
|
-
prepareTransactionRequest: <const TRequest extends import("viem").PrepareTransactionRequestRequest<
|
|
54
|
+
prepareTransactionRequest: <const TRequest extends import("viem").PrepareTransactionRequestRequest<ViemChain, TChainOverride>, TChainOverride extends ViemChain | undefined = undefined, TAccountOverride extends `0x${string}` | Account | undefined = undefined>(args: import("viem").PrepareTransactionRequestParameters<ViemChain, Account, TChainOverride, TAccountOverride, TRequest>) => Promise<import("viem").UnionRequiredBy<Extract<import("viem").UnionOmit<import("viem").ExtractChainFormatterParameters<import("viem").DeriveChain<ViemChain, TChainOverride>, "transactionRequest", import("viem").TransactionRequest>, "from"> & (import("viem").DeriveChain<ViemChain, TChainOverride> extends infer T_12 ? T_12 extends import("viem").DeriveChain<ViemChain, TChainOverride> ? T_12 extends ViemChain ? {
|
|
52
55
|
chain: T_12;
|
|
53
56
|
} : {
|
|
54
57
|
chain?: undefined;
|
|
55
|
-
} : never : never) & (import("viem").DeriveAccount<Account
|
|
58
|
+
} : never : never) & (import("viem").DeriveAccount<Account, TAccountOverride> extends infer T_13 ? T_13 extends import("viem").DeriveAccount<Account, TAccountOverride> ? T_13 extends Account ? {
|
|
56
59
|
account: T_13;
|
|
57
60
|
from: `0x${string}`;
|
|
58
61
|
} : {
|
|
@@ -1436,11 +1439,11 @@ export declare abstract class EthWalletConnector extends WalletConnectorBase {
|
|
|
1436
1439
|
sidecars: false | readonly import("viem").BlobSidecar<`0x${string}`>[] | undefined;
|
|
1437
1440
|
}, import("viem").TransactionSerializableEIP4844>)) | import("viem").Opaque<import("viem").TransactionSerializableEIP4844, TRequest> | import("viem").Opaque<import("viem").TransactionRequestEIP4844, TRequest> ? "eip4844" : never) | (TRequest["type"] extends string ? TRequest["type"] : never)>) ? T_21 extends "eip4844" ? import("viem").TransactionRequestEIP4844 : never : never : never)>> & {
|
|
1438
1441
|
chainId?: number | undefined;
|
|
1439
|
-
}, (TRequest["parameters"] extends readonly import("viem").PrepareTransactionRequestParameterType[] ? TRequest["parameters"][number] : "chainId" | "type" | "gas" | "nonce" | "blobVersionedHashes" | "fees") extends infer T_22 ? T_22 extends (TRequest["parameters"] extends readonly import("viem").PrepareTransactionRequestParameterType[] ? TRequest["parameters"][number] : "chainId" | "type" | "gas" | "nonce" | "blobVersionedHashes" | "fees") ? T_22 extends "fees" ? "gasPrice" | "maxFeePerGas" | "maxPriorityFeePerGas" : T_22 : never : never> & (unknown extends TRequest["kzg"] ? {} : Pick<TRequest, "kzg">) extends infer T ? { [K in keyof T]: (import("viem").UnionRequiredBy<Extract<import("viem").UnionOmit<import("viem").ExtractChainFormatterParameters<import("viem").DeriveChain<
|
|
1442
|
+
}, (TRequest["parameters"] extends readonly import("viem").PrepareTransactionRequestParameterType[] ? TRequest["parameters"][number] : "chainId" | "type" | "gas" | "nonce" | "blobVersionedHashes" | "fees") extends infer T_22 ? T_22 extends (TRequest["parameters"] extends readonly import("viem").PrepareTransactionRequestParameterType[] ? TRequest["parameters"][number] : "chainId" | "type" | "gas" | "nonce" | "blobVersionedHashes" | "fees") ? T_22 extends "fees" ? "gasPrice" | "maxFeePerGas" | "maxPriorityFeePerGas" : T_22 : never : never> & (unknown extends TRequest["kzg"] ? {} : Pick<TRequest, "kzg">) extends infer T ? { [K in keyof T]: (import("viem").UnionRequiredBy<Extract<import("viem").UnionOmit<import("viem").ExtractChainFormatterParameters<import("viem").DeriveChain<ViemChain, TChainOverride>, "transactionRequest", import("viem").TransactionRequest>, "from"> & (import("viem").DeriveChain<ViemChain, TChainOverride> extends infer T_1 ? T_1 extends import("viem").DeriveChain<ViemChain, TChainOverride> ? T_1 extends ViemChain ? {
|
|
1440
1443
|
chain: T_1;
|
|
1441
1444
|
} : {
|
|
1442
1445
|
chain?: undefined;
|
|
1443
|
-
} : never : never) & (import("viem").DeriveAccount<Account
|
|
1446
|
+
} : never : never) & (import("viem").DeriveAccount<Account, TAccountOverride> extends infer T_2 ? T_2 extends import("viem").DeriveAccount<Account, TAccountOverride> ? T_2 extends Account ? {
|
|
1444
1447
|
account: T_2;
|
|
1445
1448
|
from: `0x${string}`;
|
|
1446
1449
|
} : {
|
|
@@ -2831,9 +2834,9 @@ export declare abstract class EthWalletConnector extends WalletConnectorBase {
|
|
|
2831
2834
|
eth_accounts: Record<string, any>;
|
|
2832
2835
|
}) => Promise<import("viem").RequestPermissionsReturnType>;
|
|
2833
2836
|
sendRawTransaction: (args: import("viem").SendRawTransactionParameters) => Promise<`0x${string}`>;
|
|
2834
|
-
sendTransaction: <const TRequest_1 extends import("viem").SendTransactionRequest<
|
|
2835
|
-
signMessage: (args: import("viem").SignMessageParameters<Account
|
|
2836
|
-
signTransaction: <TChainOverride_2 extends
|
|
2837
|
+
sendTransaction: <const TRequest_1 extends import("viem").SendTransactionRequest<ViemChain, TChainOverride_1>, TChainOverride_1 extends ViemChain | undefined = undefined>(args: import("viem").SendTransactionParameters<ViemChain, Account, TChainOverride_1, TRequest_1>) => Promise<`0x${string}`>;
|
|
2838
|
+
signMessage: (args: import("viem").SignMessageParameters<Account>) => Promise<`0x${string}`>;
|
|
2839
|
+
signTransaction: <TChainOverride_2 extends ViemChain | undefined>(args: import("viem").SignTransactionParameters<ViemChain, Account, TChainOverride_2>) => Promise<`0x02${string}` | `0x01${string}` | `0x03${string}` | import("viem").TransactionSerializedLegacy>;
|
|
2837
2840
|
signTypedData: <const TTypedData extends {
|
|
2838
2841
|
[x: string]: readonly import("viem").TypedDataParameter[];
|
|
2839
2842
|
[x: `string[${string}]`]: undefined;
|
|
@@ -3041,10 +3044,10 @@ export declare abstract class EthWalletConnector extends WalletConnectorBase {
|
|
|
3041
3044
|
uint256?: undefined;
|
|
3042
3045
|
} | {
|
|
3043
3046
|
[key: string]: unknown;
|
|
3044
|
-
}, TPrimaryType extends string>(args: import("viem").SignTypedDataParameters<TTypedData, TPrimaryType, Account
|
|
3047
|
+
}, TPrimaryType extends string>(args: import("viem").SignTypedDataParameters<TTypedData, TPrimaryType, Account>) => Promise<`0x${string}`>;
|
|
3045
3048
|
switchChain: (args: import("viem").SwitchChainParameters) => Promise<void>;
|
|
3046
3049
|
watchAsset: (args: import("viem").WatchAssetParams) => Promise<boolean>;
|
|
3047
|
-
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, "nonpayable" | "payable", functionName>, TChainOverride_3 extends
|
|
3050
|
+
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, "nonpayable" | "payable", functionName>, TChainOverride_3 extends ViemChain | undefined = undefined>(args: import("viem").WriteContractParameters<abi_1, functionName, args, ViemChain, Account, TChainOverride_3>) => Promise<`0x${string}`>;
|
|
3048
3051
|
extend: <const client extends {
|
|
3049
3052
|
[x: string]: unknown;
|
|
3050
3053
|
account?: undefined;
|
|
@@ -3059,7 +3062,7 @@ export declare abstract class EthWalletConnector extends WalletConnectorBase {
|
|
|
3059
3062
|
transport?: undefined;
|
|
3060
3063
|
type?: undefined;
|
|
3061
3064
|
uid?: undefined;
|
|
3062
|
-
} & import("viem").ExactPartial<Pick<import("viem").PublicActions<
|
|
3065
|
+
} & import("viem").ExactPartial<Pick<import("viem").PublicActions<Transport, ViemChain, Account>, "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>, "sendTransaction" | "writeContract">>>(fn: (client: import("viem").Client<Transport, ViemChain, Account, import("viem").WalletRpcSchema, import("viem").WalletActions<ViemChain, Account>>) => client) => import("viem").Client<Transport, ViemChain, Account, import("viem").WalletRpcSchema, { [K_1 in keyof client]: client[K_1]; } & import("viem").WalletActions<ViemChain, Account>>;
|
|
3063
3066
|
} | undefined>;
|
|
3064
3067
|
getBalance(): Promise<string | undefined>;
|
|
3065
3068
|
supportsNetworkSwitching(): boolean;
|
|
@@ -3076,5 +3079,8 @@ export declare abstract class EthWalletConnector extends WalletConnectorBase {
|
|
|
3076
3079
|
protected evmNetworkRpcMap: () => EvmRpcMap;
|
|
3077
3080
|
setActiveAccount(account: Hex | undefined): void;
|
|
3078
3081
|
getActiveAccount(): Account | undefined;
|
|
3082
|
+
setActiveChain(chain: ViemChain | undefined): void;
|
|
3083
|
+
getActiveChain(): ViemChain | undefined;
|
|
3084
|
+
createUiTransaction(from: string): Promise<IUITransaction>;
|
|
3079
3085
|
}
|
|
3080
3086
|
export {};
|
|
@@ -1,16 +1,17 @@
|
|
|
1
1
|
'use client'
|
|
2
2
|
import { __awaiter } from '../_virtual/_tslib.js';
|
|
3
|
-
import { formatEther } from 'viem';
|
|
3
|
+
import { getAddress, formatEther } from 'viem';
|
|
4
4
|
import { toAccount } from 'viem/accounts';
|
|
5
|
-
import {
|
|
6
|
-
import {
|
|
5
|
+
import { parseEvmNetworks, retryableFn, FALLBACK_UNDEFINED, DynamicError } from '@dynamic-labs/utils';
|
|
6
|
+
import { chainsMap, getOrMapViemChain, createViemUiTransaction } from '@dynamic-labs/viem-utils';
|
|
7
|
+
import { WalletConnectorBase, logger } from '@dynamic-labs/wallet-connector-core';
|
|
7
8
|
import { findEvmNetwork } from './utils/findEvmNetwork.js';
|
|
8
9
|
import { getNameservice } from './utils/getNameservice.js';
|
|
9
10
|
|
|
10
11
|
class EthWalletConnector extends WalletConnectorBase {
|
|
11
12
|
getPublicClient() {
|
|
12
13
|
return __awaiter(this, void 0, void 0, function* () {
|
|
13
|
-
var _a, _b
|
|
14
|
+
var _a, _b;
|
|
14
15
|
const networkId = (_a = (yield this.getNetwork())) !== null && _a !== void 0 ? _a : 1;
|
|
15
16
|
if (this.evmNetworks.length === 0) {
|
|
16
17
|
return undefined;
|
|
@@ -21,7 +22,10 @@ class EthWalletConnector extends WalletConnectorBase {
|
|
|
21
22
|
solana: [],
|
|
22
23
|
starknet: undefined,
|
|
23
24
|
};
|
|
24
|
-
|
|
25
|
+
if (!this.chainRpcProviders)
|
|
26
|
+
return undefined;
|
|
27
|
+
const providers = this.chainRpcProviders.getProviders(configurations);
|
|
28
|
+
return (_b = this.chainRpcProviders.getEvmProviderByChainId(providers, networkId)) === null || _b === void 0 ? void 0 : _b.provider;
|
|
25
29
|
});
|
|
26
30
|
}
|
|
27
31
|
constructor(props) {
|
|
@@ -44,7 +48,7 @@ class EthWalletConnector extends WalletConnectorBase {
|
|
|
44
48
|
if (!this.supportsNetworkSwitching || !provider) {
|
|
45
49
|
return Promise.resolve(undefined);
|
|
46
50
|
}
|
|
47
|
-
|
|
51
|
+
const chainId = yield retryableFn(provider.getChainId, {
|
|
48
52
|
fallbackValue: FALLBACK_UNDEFINED,
|
|
49
53
|
/**
|
|
50
54
|
* The timeout is set to 1 second because the getChainId method
|
|
@@ -54,6 +58,8 @@ class EthWalletConnector extends WalletConnectorBase {
|
|
|
54
58
|
*/
|
|
55
59
|
timeoutMs: 1000,
|
|
56
60
|
});
|
|
61
|
+
this.setActiveChain(chainsMap[chainId]);
|
|
62
|
+
return chainId;
|
|
57
63
|
});
|
|
58
64
|
}
|
|
59
65
|
getNameService() {
|
|
@@ -68,6 +74,23 @@ class EthWalletConnector extends WalletConnectorBase {
|
|
|
68
74
|
return getNameservice({ address, rpcProvider });
|
|
69
75
|
});
|
|
70
76
|
}
|
|
77
|
+
isTestnet() {
|
|
78
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
79
|
+
var _a, _b, _c;
|
|
80
|
+
return (_c = (_b = (_a = (yield this.getPublicClient())) === null || _a === void 0 ? void 0 : _a.chain) === null || _b === void 0 ? void 0 : _b.testnet) !== null && _c !== void 0 ? _c : false;
|
|
81
|
+
});
|
|
82
|
+
}
|
|
83
|
+
parseAddress(address) {
|
|
84
|
+
try {
|
|
85
|
+
// Ensures the address follows the EIP55 format.
|
|
86
|
+
// see: https://eips.ethereum.org/EIPS/eip-55
|
|
87
|
+
return getAddress(address);
|
|
88
|
+
}
|
|
89
|
+
catch (err) {
|
|
90
|
+
logger.debug(`Failed to parse EVM address into EIP55 format: error getting checksum, returning default ${address}`, err);
|
|
91
|
+
}
|
|
92
|
+
return address;
|
|
93
|
+
}
|
|
71
94
|
getSigner() {
|
|
72
95
|
return __awaiter(this, void 0, void 0, function* () {
|
|
73
96
|
return this.getWalletClient();
|
|
@@ -119,7 +142,7 @@ class EthWalletConnector extends WalletConnectorBase {
|
|
|
119
142
|
return [];
|
|
120
143
|
const addresses = yield retryableFn(provider.getAddresses, {
|
|
121
144
|
fallbackValue: [],
|
|
122
|
-
timeoutMs:
|
|
145
|
+
timeoutMs: 500,
|
|
123
146
|
});
|
|
124
147
|
if (addresses.length) {
|
|
125
148
|
this.setActiveAccount(addresses[0]);
|
|
@@ -139,11 +162,15 @@ class EthWalletConnector extends WalletConnectorBase {
|
|
|
139
162
|
if (!this.supportsNetworkSwitching()) {
|
|
140
163
|
throw new DynamicError('Network switching is not supported');
|
|
141
164
|
}
|
|
142
|
-
|
|
165
|
+
const viemChain = getOrMapViemChain(network);
|
|
166
|
+
yield provider.switchChain(viemChain);
|
|
143
167
|
if (this.key === 'magiceden') {
|
|
144
168
|
const newChainId = yield provider.getChainId();
|
|
145
169
|
this.emit('chainChange', { chain: newChainId.toString() });
|
|
146
170
|
}
|
|
171
|
+
else {
|
|
172
|
+
this.setActiveChain(viemChain);
|
|
173
|
+
}
|
|
147
174
|
}
|
|
148
175
|
catch (error) {
|
|
149
176
|
// we need to check for unrecognized chain error first because it also contains 'rejected' in message
|
|
@@ -188,6 +215,22 @@ class EthWalletConnector extends WalletConnectorBase {
|
|
|
188
215
|
getActiveAccount() {
|
|
189
216
|
return this.activeAccount;
|
|
190
217
|
}
|
|
218
|
+
setActiveChain(chain) {
|
|
219
|
+
this.activeChain = chain;
|
|
220
|
+
}
|
|
221
|
+
getActiveChain() {
|
|
222
|
+
return this.activeChain;
|
|
223
|
+
}
|
|
224
|
+
createUiTransaction(from) {
|
|
225
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
226
|
+
const walletClient = yield this.getWalletClient();
|
|
227
|
+
const publicClient = yield this.getPublicClient();
|
|
228
|
+
if (!publicClient || !walletClient) {
|
|
229
|
+
throw new DynamicError('No public client available');
|
|
230
|
+
}
|
|
231
|
+
return createViemUiTransaction({ from, publicClient, walletClient });
|
|
232
|
+
});
|
|
233
|
+
}
|
|
191
234
|
}
|
|
192
235
|
|
|
193
236
|
export { EthWalletConnector };
|
|
@@ -5,8 +5,8 @@ Object.defineProperty(exports, '__esModule', { value: true });
|
|
|
5
5
|
|
|
6
6
|
var _tslib = require('../../_virtual/_tslib.cjs');
|
|
7
7
|
var viem = require('viem');
|
|
8
|
-
var walletConnectorCore = require('@dynamic-labs/wallet-connector-core');
|
|
9
8
|
var viemUtils = require('@dynamic-labs/viem-utils');
|
|
9
|
+
var walletConnectorCore = require('@dynamic-labs/wallet-connector-core');
|
|
10
10
|
var EthWalletConnector = require('../EthWalletConnector.cjs');
|
|
11
11
|
var helpers = require('./helpers.cjs');
|
|
12
12
|
|