@injectivelabs/wallet-core 1.16.4-alpha.0 → 1.16.5-alpha.0
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/README.md +4 -4
- package/dist/cjs/broadcaster/MsgBroadcaster.d.ts +3 -3
- package/dist/cjs/broadcaster/MsgBroadcaster.js +40 -35
- package/dist/cjs/broadcaster/Web3Broadcaster.d.ts +5 -5
- package/dist/cjs/broadcaster/Web3Broadcaster.js +6 -6
- package/dist/cjs/broadcaster/types.d.ts +2 -2
- package/dist/cjs/strategy/BaseWalletStrategy.d.ts +3 -3
- package/dist/cjs/strategy/BaseWalletStrategy.js +8 -6
- package/dist/esm/broadcaster/MsgBroadcaster.d.ts +3 -3
- package/dist/esm/broadcaster/MsgBroadcaster.js +41 -36
- package/dist/esm/broadcaster/Web3Broadcaster.d.ts +5 -5
- package/dist/esm/broadcaster/Web3Broadcaster.js +6 -6
- package/dist/esm/broadcaster/types.d.ts +2 -2
- package/dist/esm/strategy/BaseWalletStrategy.d.ts +3 -3
- package/dist/esm/strategy/BaseWalletStrategy.js +8 -6
- package/package.json +10 -10
package/README.md
CHANGED
|
@@ -13,7 +13,7 @@ _Package to use Wallets on Injective via the wallet strategy._
|
|
|
13
13
|
## 📚 Installation
|
|
14
14
|
|
|
15
15
|
```bash
|
|
16
|
-
|
|
16
|
+
pnpm add @injectivelabs/wallet-core
|
|
17
17
|
```
|
|
18
18
|
|
|
19
19
|
---
|
|
@@ -30,13 +30,13 @@ import { PrivateKeyWalletStrategy } from '@injectivelabs/wallet-private-key'
|
|
|
30
30
|
const strategyArgs: WalletStrategyArguments = {} /** define the args */
|
|
31
31
|
const strategyEthArgs: ConcreteEthereumWalletStrategyArgs = {} /** if the wallet is an Ethereum wallet */
|
|
32
32
|
const strategies = {
|
|
33
|
-
[Wallet.PrivateKey]: new PrivateKeyWalletStrategy(strategyEthArgs)
|
|
33
|
+
[Wallet.PrivateKey]: new PrivateKeyWalletStrategy(strategyEthArgs),
|
|
34
34
|
}
|
|
35
35
|
|
|
36
|
-
export const walletStrategy = new BaseWalletStrategy({...strategyArgs, strategies})
|
|
36
|
+
export const walletStrategy = new BaseWalletStrategy({ ...strategyArgs, strategies })
|
|
37
37
|
|
|
38
38
|
const broadcasterArgs: MsgBroadcasterOptions = {} /** define the broadcaster args */
|
|
39
|
-
export const msgBroadcaster = new MsgBroadcaster({...broadcasterArgs, walletStrategy})
|
|
39
|
+
export const msgBroadcaster = new MsgBroadcaster({ ...broadcasterArgs, walletStrategy })
|
|
40
40
|
```
|
|
41
41
|
|
|
42
42
|
Read more and find example usages on our [WalletStrategy Docs](https://docs.ts.injective.network/wallet/wallet-wallet-strategy)
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { TxResponse } from '@injectivelabs/sdk-ts';
|
|
2
2
|
import { NetworkEndpoints } from '@injectivelabs/networks';
|
|
3
|
-
import { ChainId,
|
|
3
|
+
import { ChainId, EvmChainId } from '@injectivelabs/ts-types';
|
|
4
4
|
import { MsgBroadcasterOptions, MsgBroadcasterTxOptions } from './types.js';
|
|
5
5
|
import BaseWalletStrategy from '../strategy/BaseWalletStrategy.js';
|
|
6
6
|
/**
|
|
@@ -18,7 +18,7 @@ export declare class MsgBroadcaster {
|
|
|
18
18
|
txTimeout: number;
|
|
19
19
|
simulateTx: boolean;
|
|
20
20
|
txTimeoutOnFeeDelegation: boolean;
|
|
21
|
-
|
|
21
|
+
evmChainId?: EvmChainId;
|
|
22
22
|
gasBufferCoefficient: number;
|
|
23
23
|
retriesOnError: {
|
|
24
24
|
"sdk-20": {
|
|
@@ -30,7 +30,7 @@ export declare class MsgBroadcaster {
|
|
|
30
30
|
httpHeaders?: Record<string, string>;
|
|
31
31
|
constructor(options: MsgBroadcasterOptions);
|
|
32
32
|
setOptions(options: Partial<MsgBroadcasterOptions>): void;
|
|
33
|
-
|
|
33
|
+
getEvmChainId(): Promise<EvmChainId | undefined>;
|
|
34
34
|
/**
|
|
35
35
|
* Broadcasting the transaction using the client
|
|
36
36
|
* side approach for both cosmos and ethereum native wallets
|
|
@@ -37,7 +37,7 @@ class MsgBroadcaster {
|
|
|
37
37
|
txTimeout = utils_1.DEFAULT_BLOCK_TIMEOUT_HEIGHT;
|
|
38
38
|
simulateTx = true;
|
|
39
39
|
txTimeoutOnFeeDelegation = false;
|
|
40
|
-
|
|
40
|
+
evmChainId;
|
|
41
41
|
gasBufferCoefficient = 1.2;
|
|
42
42
|
retriesOnError = defaultRetriesConfig();
|
|
43
43
|
httpHeaders;
|
|
@@ -53,8 +53,7 @@ class MsgBroadcaster {
|
|
|
53
53
|
: true;
|
|
54
54
|
this.gasBufferCoefficient = options.gasBufferCoefficient || 1.2;
|
|
55
55
|
this.chainId = options.chainId || networkInfo.chainId;
|
|
56
|
-
this.
|
|
57
|
-
options.ethereumChainId || networkInfo.ethereumChainId;
|
|
56
|
+
this.evmChainId = options.evmChainId || networkInfo.evmChainId;
|
|
58
57
|
this.endpoints = options.endpoints || (0, networks_1.getNetworkEndpoints)(options.network);
|
|
59
58
|
this.walletStrategy = options.walletStrategy;
|
|
60
59
|
this.httpHeaders = options.httpHeaders;
|
|
@@ -65,17 +64,23 @@ class MsgBroadcaster {
|
|
|
65
64
|
this.txTimeoutOnFeeDelegation =
|
|
66
65
|
options.txTimeoutOnFeeDelegation || this.txTimeoutOnFeeDelegation;
|
|
67
66
|
}
|
|
68
|
-
async
|
|
67
|
+
async getEvmChainId() {
|
|
69
68
|
const { walletStrategy } = this;
|
|
70
69
|
if (!(0, wallet_base_1.isEvmBrowserWallet)(walletStrategy.wallet)) {
|
|
71
|
-
return;
|
|
70
|
+
return this.evmChainId;
|
|
72
71
|
}
|
|
73
|
-
const mainnetEvmIds = [ts_types_1.
|
|
74
|
-
const testnetEvmIds = [ts_types_1.
|
|
75
|
-
const devnetEvmIds = [ts_types_1.
|
|
72
|
+
const mainnetEvmIds = [ts_types_1.EvmChainId.Mainnet, ts_types_1.EvmChainId.MainnetEvm];
|
|
73
|
+
const testnetEvmIds = [ts_types_1.EvmChainId.Sepolia, ts_types_1.EvmChainId.TestnetEvm];
|
|
74
|
+
const devnetEvmIds = [ts_types_1.EvmChainId.Sepolia, ts_types_1.EvmChainId.DevnetEvm];
|
|
76
75
|
try {
|
|
77
76
|
const chainId = await walletStrategy.getEthereumChainId();
|
|
77
|
+
if (!chainId) {
|
|
78
|
+
return this.evmChainId;
|
|
79
|
+
}
|
|
78
80
|
const evmChainId = parseInt(chainId, 16);
|
|
81
|
+
if (isNaN(evmChainId)) {
|
|
82
|
+
return this.evmChainId;
|
|
83
|
+
}
|
|
79
84
|
if (((0, networks_1.isMainnet)(this.options.network) &&
|
|
80
85
|
!mainnetEvmIds.includes(evmChainId)) ||
|
|
81
86
|
((0, networks_1.isTestnet)(this.options.network) &&
|
|
@@ -85,11 +90,11 @@ class MsgBroadcaster {
|
|
|
85
90
|
!devnetEvmIds.includes(evmChainId))) {
|
|
86
91
|
throw new exceptions_1.WalletException(new Error('Your selected network is incorrect'));
|
|
87
92
|
}
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
93
|
+
return evmChainId;
|
|
94
|
+
}
|
|
95
|
+
catch (e) {
|
|
96
|
+
throw new exceptions_1.WalletException(e);
|
|
91
97
|
}
|
|
92
|
-
catch { }
|
|
93
98
|
}
|
|
94
99
|
/**
|
|
95
100
|
* Broadcasting the transaction using the client
|
|
@@ -197,12 +202,12 @@ class MsgBroadcaster {
|
|
|
197
202
|
* @returns transaction hash
|
|
198
203
|
*/
|
|
199
204
|
async broadcastEip712(tx) {
|
|
200
|
-
const { chainId, txTimeout, endpoints,
|
|
205
|
+
const { chainId, txTimeout, endpoints, walletStrategy } = this;
|
|
201
206
|
const msgs = Array.isArray(tx.msgs) ? tx.msgs : [tx.msgs];
|
|
202
|
-
|
|
203
|
-
|
|
207
|
+
const evmChainId = await this.getEvmChainId();
|
|
208
|
+
if (!evmChainId) {
|
|
209
|
+
throw new exceptions_1.GeneralException(new Error('Please provide evmChainId'));
|
|
204
210
|
}
|
|
205
|
-
await this.verifyEvmChainId();
|
|
206
211
|
/** Account Details * */
|
|
207
212
|
const { baseAccount, latestHeight } = await this.fetchAccountAndBlockDetails(tx.injectiveAddress);
|
|
208
213
|
const timeoutHeight = new utils_1.BigNumberInBase(latestHeight).plus(txTimeout);
|
|
@@ -243,7 +248,7 @@ class MsgBroadcaster {
|
|
|
243
248
|
timeoutHeight: timeoutHeight.toFixed(),
|
|
244
249
|
chainId,
|
|
245
250
|
},
|
|
246
|
-
|
|
251
|
+
evmChainId,
|
|
247
252
|
});
|
|
248
253
|
/** Signing on Ethereum */
|
|
249
254
|
const signature = await walletStrategy.signEip712TypedData(JSON.stringify(eip712TypedData), tx.ethereumAddress);
|
|
@@ -265,7 +270,7 @@ class MsgBroadcaster {
|
|
|
265
270
|
chainId,
|
|
266
271
|
});
|
|
267
272
|
const web3Extension = (0, sdk_ts_1.createWeb3Extension)({
|
|
268
|
-
|
|
273
|
+
evmChainId,
|
|
269
274
|
});
|
|
270
275
|
const txRawEip712 = (0, sdk_ts_1.createTxRawEIP712)(txRaw, web3Extension);
|
|
271
276
|
/** Append Signatures */
|
|
@@ -289,12 +294,12 @@ class MsgBroadcaster {
|
|
|
289
294
|
* @returns transaction hash
|
|
290
295
|
*/
|
|
291
296
|
async broadcastEip712V2(tx) {
|
|
292
|
-
const { chainId, endpoints, txTimeout, walletStrategy
|
|
297
|
+
const { chainId, endpoints, txTimeout, walletStrategy } = this;
|
|
293
298
|
const msgs = Array.isArray(tx.msgs) ? tx.msgs : [tx.msgs];
|
|
294
|
-
|
|
295
|
-
|
|
299
|
+
const evmChainId = await this.getEvmChainId();
|
|
300
|
+
if (!evmChainId) {
|
|
301
|
+
throw new exceptions_1.GeneralException(new Error('Please provide evmChainId'));
|
|
296
302
|
}
|
|
297
|
-
await this.verifyEvmChainId();
|
|
298
303
|
/** Account Details * */
|
|
299
304
|
const { baseAccount, latestHeight } = await this.fetchAccountAndBlockDetails(tx.injectiveAddress);
|
|
300
305
|
const timeoutHeight = new utils_1.BigNumberInBase(latestHeight).plus(txTimeout);
|
|
@@ -336,7 +341,7 @@ class MsgBroadcaster {
|
|
|
336
341
|
timeoutHeight: timeoutHeight.toFixed(),
|
|
337
342
|
chainId,
|
|
338
343
|
},
|
|
339
|
-
|
|
344
|
+
evmChainId,
|
|
340
345
|
});
|
|
341
346
|
walletStrategy.emit(types_js_1.WalletStrategyEmitterEventType.TransactionPreparationEnd);
|
|
342
347
|
/** Signing on Ethereum */
|
|
@@ -359,7 +364,7 @@ class MsgBroadcaster {
|
|
|
359
364
|
chainId,
|
|
360
365
|
});
|
|
361
366
|
const web3Extension = (0, sdk_ts_1.createWeb3Extension)({
|
|
362
|
-
|
|
367
|
+
evmChainId,
|
|
363
368
|
});
|
|
364
369
|
const txRawEip712 = (0, sdk_ts_1.createTxRawEIP712)(txRaw, web3Extension);
|
|
365
370
|
/** Append Signatures */
|
|
@@ -381,13 +386,13 @@ class MsgBroadcaster {
|
|
|
381
386
|
* @returns transaction hash
|
|
382
387
|
*/
|
|
383
388
|
async broadcastEip712WithFeeDelegation(tx) {
|
|
384
|
-
const { txTimeout, endpoints, simulateTx, httpHeaders, walletStrategy,
|
|
389
|
+
const { txTimeout, endpoints, simulateTx, httpHeaders, walletStrategy, txTimeoutOnFeeDelegation, } = this;
|
|
385
390
|
const msgs = Array.isArray(tx.msgs) ? tx.msgs : [tx.msgs];
|
|
386
391
|
const web3Msgs = msgs.map((msg) => msg.toWeb3());
|
|
387
|
-
|
|
388
|
-
|
|
392
|
+
const evmChainId = await this.getEvmChainId();
|
|
393
|
+
if (!evmChainId) {
|
|
394
|
+
throw new exceptions_1.GeneralException(new Error('Please provide evmChainId'));
|
|
389
395
|
}
|
|
390
|
-
await this.verifyEvmChainId();
|
|
391
396
|
const transactionApi = new sdk_ts_1.IndexerGrpcWeb3GwApi(endpoints.web3gw || endpoints.indexer);
|
|
392
397
|
if (httpHeaders) {
|
|
393
398
|
transactionApi.setMetadata(httpHeaders);
|
|
@@ -406,7 +411,7 @@ class MsgBroadcaster {
|
|
|
406
411
|
memo: tx.memo,
|
|
407
412
|
message: web3Msgs,
|
|
408
413
|
address: tx.ethereumAddress,
|
|
409
|
-
chainId:
|
|
414
|
+
chainId: evmChainId,
|
|
410
415
|
gasLimit: (0, sdk_ts_1.getGasPriceBasedOnMessage)(msgs),
|
|
411
416
|
estimateGas: simulateTx,
|
|
412
417
|
});
|
|
@@ -416,7 +421,7 @@ class MsgBroadcaster {
|
|
|
416
421
|
signature,
|
|
417
422
|
message: web3Msgs,
|
|
418
423
|
txResponse: prepareTxResponse,
|
|
419
|
-
chainId:
|
|
424
|
+
chainId: evmChainId,
|
|
420
425
|
});
|
|
421
426
|
try {
|
|
422
427
|
walletStrategy.emit(types_js_1.WalletStrategyEmitterEventType.TransactionBroadcastStart);
|
|
@@ -543,7 +548,7 @@ class MsgBroadcaster {
|
|
|
543
548
|
* @param tx the transaction that needs to be broadcasted
|
|
544
549
|
*/
|
|
545
550
|
async experimentalBroadcastWalletThroughLedger(tx) {
|
|
546
|
-
const { chainId, txTimeout, endpoints, simulateTx, walletStrategy,
|
|
551
|
+
const { chainId, txTimeout, endpoints, evmChainId, simulateTx, walletStrategy, } = this;
|
|
547
552
|
const msgs = Array.isArray(tx.msgs) ? tx.msgs : [tx.msgs];
|
|
548
553
|
/**
|
|
549
554
|
* We can only use this method
|
|
@@ -556,8 +561,8 @@ class MsgBroadcaster {
|
|
|
556
561
|
throw new exceptions_1.GeneralException(new Error(`This method can only be used when Ledger is connected through ${walletStrategy.getWallet()}`));
|
|
557
562
|
}
|
|
558
563
|
}
|
|
559
|
-
if (!
|
|
560
|
-
throw new exceptions_1.GeneralException(new Error('Please provide
|
|
564
|
+
if (!evmChainId) {
|
|
565
|
+
throw new exceptions_1.GeneralException(new Error('Please provide evmChainId'));
|
|
561
566
|
}
|
|
562
567
|
const cosmosWallet = walletStrategy.getCosmosWallet(chainId);
|
|
563
568
|
const { baseAccount, latestHeight } = await this.fetchAccountAndBlockDetails(tx.injectiveAddress);
|
|
@@ -575,7 +580,7 @@ class MsgBroadcaster {
|
|
|
575
580
|
sequence: baseAccount.sequence.toString(),
|
|
576
581
|
accountNumber: baseAccount.accountNumber.toString(),
|
|
577
582
|
},
|
|
578
|
-
|
|
583
|
+
evmChainId,
|
|
579
584
|
});
|
|
580
585
|
const aminoSignResponse = await cosmosWallet.signEIP712CosmosTx({
|
|
581
586
|
eip712: eip712TypedData,
|
|
@@ -606,7 +611,7 @@ class MsgBroadcaster {
|
|
|
606
611
|
});
|
|
607
612
|
/** Preparing the transaction for client broadcasting */
|
|
608
613
|
const web3Extension = (0, sdk_ts_1.createWeb3Extension)({
|
|
609
|
-
|
|
614
|
+
evmChainId,
|
|
610
615
|
});
|
|
611
616
|
const txRawEip712 = (0, sdk_ts_1.createTxRawEIP712)(txRaw, web3Extension);
|
|
612
617
|
if (simulateTx) {
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { EthereumChainId } from '@injectivelabs/ts-types';
|
|
2
1
|
import { Network } from '@injectivelabs/networks';
|
|
2
|
+
import { EvmChainId } from '@injectivelabs/ts-types';
|
|
3
3
|
import BaseWalletStrategy from '../strategy/BaseWalletStrategy.js';
|
|
4
4
|
interface SendTransactionOptions {
|
|
5
5
|
tx: {
|
|
@@ -11,7 +11,7 @@ interface SendTransactionOptions {
|
|
|
11
11
|
data: any;
|
|
12
12
|
};
|
|
13
13
|
address: string;
|
|
14
|
-
|
|
14
|
+
evmChainId?: EvmChainId;
|
|
15
15
|
}
|
|
16
16
|
/**
|
|
17
17
|
* Preparing and broadcasting
|
|
@@ -19,10 +19,10 @@ interface SendTransactionOptions {
|
|
|
19
19
|
*/
|
|
20
20
|
export declare class Web3Broadcaster {
|
|
21
21
|
private walletStrategy;
|
|
22
|
-
private
|
|
23
|
-
constructor({ walletStrategy,
|
|
22
|
+
private evmChainId;
|
|
23
|
+
constructor({ walletStrategy, evmChainId, }: {
|
|
24
24
|
walletStrategy: BaseWalletStrategy;
|
|
25
|
-
|
|
25
|
+
evmChainId: EvmChainId;
|
|
26
26
|
network: Network;
|
|
27
27
|
});
|
|
28
28
|
sendTransaction(args: SendTransactionOptions): Promise<string>;
|
|
@@ -8,18 +8,18 @@ const exceptions_1 = require("@injectivelabs/exceptions");
|
|
|
8
8
|
*/
|
|
9
9
|
class Web3Broadcaster {
|
|
10
10
|
walletStrategy;
|
|
11
|
-
|
|
12
|
-
constructor({ walletStrategy,
|
|
11
|
+
evmChainId;
|
|
12
|
+
constructor({ walletStrategy, evmChainId, }) {
|
|
13
|
+
this.evmChainId = evmChainId;
|
|
13
14
|
this.walletStrategy = walletStrategy;
|
|
14
|
-
this.ethereumChainId = ethereumChainId;
|
|
15
15
|
}
|
|
16
16
|
async sendTransaction(args) {
|
|
17
|
-
const {
|
|
17
|
+
const { evmChainId, walletStrategy } = this;
|
|
18
18
|
try {
|
|
19
|
-
const chainId = args.
|
|
19
|
+
const chainId = args.evmChainId || evmChainId;
|
|
20
20
|
const txHash = await walletStrategy.sendEvmTransaction(args.tx, {
|
|
21
|
+
evmChainId: chainId,
|
|
21
22
|
address: args.address,
|
|
22
|
-
ethereumChainId: chainId,
|
|
23
23
|
});
|
|
24
24
|
await walletStrategy.getEvmTransactionReceipt(txHash, chainId);
|
|
25
25
|
return txHash;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { EventEmitter } from 'eventemitter3';
|
|
2
2
|
import { Msgs } from '@injectivelabs/sdk-ts';
|
|
3
|
-
import { ChainId,
|
|
3
|
+
import { ChainId, EvmChainId } from '@injectivelabs/ts-types';
|
|
4
4
|
import { Network, NetworkEndpoints } from '@injectivelabs/networks';
|
|
5
5
|
import BaseWalletStrategy from '../strategy/BaseWalletStrategy.js';
|
|
6
6
|
export interface MsgBroadcasterTxOptions {
|
|
@@ -23,7 +23,7 @@ export interface MsgBroadcasterOptions {
|
|
|
23
23
|
network: Network;
|
|
24
24
|
endpoints?: NetworkEndpoints;
|
|
25
25
|
chainId?: ChainId;
|
|
26
|
-
|
|
26
|
+
evmChainId?: EvmChainId;
|
|
27
27
|
feePayerPubKey?: string;
|
|
28
28
|
simulateTx?: boolean;
|
|
29
29
|
txTimeoutOnFeeDelegation?: boolean;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { TxRaw, TxResponse, AminoSignResponse, DirectSignResponse } from '@injectivelabs/sdk-ts';
|
|
2
|
-
import { ChainId, AccountAddress, EthereumChainId } from '@injectivelabs/ts-types';
|
|
3
2
|
import { Wallet, WalletDeviceType, type WalletMetadata, ConcreteStrategiesArg, SendTransactionOptions, ConcreteWalletStrategy, onAccountChangeCallback, onChainIdChangeCallback, WalletStrategyArguments, CosmosWalletAbstraction, WalletStrategy as WalletStrategyInterface } from '@injectivelabs/wallet-base';
|
|
3
|
+
import { ChainId, EvmChainId, AccountAddress } from '@injectivelabs/ts-types';
|
|
4
4
|
import { StdSignDoc } from '@keplr-wallet/types';
|
|
5
5
|
import { WalletStrategyEmitter } from '../broadcaster/types.js';
|
|
6
6
|
export default class BaseWalletStrategy implements WalletStrategyInterface {
|
|
@@ -24,13 +24,13 @@ export default class BaseWalletStrategy implements WalletStrategyInterface {
|
|
|
24
24
|
enable(args?: unknown): Promise<boolean>;
|
|
25
25
|
enableAndGetAddresses(args?: unknown): Promise<AccountAddress[]>;
|
|
26
26
|
getEthereumChainId(): Promise<string>;
|
|
27
|
-
getEvmTransactionReceipt(txHash: string,
|
|
27
|
+
getEvmTransactionReceipt(txHash: string, evmChainId?: EvmChainId): Promise<void>;
|
|
28
28
|
getSessionOrConfirm(address?: AccountAddress): Promise<string>;
|
|
29
29
|
getWalletClient<T>(): Promise<T>;
|
|
30
30
|
sendTransaction(tx: DirectSignResponse | TxRaw, options: SendTransactionOptions): Promise<TxResponse>;
|
|
31
31
|
sendEvmTransaction(tx: any, options: {
|
|
32
|
+
evmChainId: EvmChainId;
|
|
32
33
|
address: AccountAddress;
|
|
33
|
-
ethereumChainId: EthereumChainId;
|
|
34
34
|
}): Promise<string>;
|
|
35
35
|
signEip712TypedData(eip712TypedData: string, address: AccountAddress): Promise<string>;
|
|
36
36
|
signAminoCosmosTransaction(transaction: {
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
const eventemitter3_1 = require("eventemitter3");
|
|
4
|
-
const exceptions_1 = require("@injectivelabs/exceptions");
|
|
5
4
|
const wallet_base_1 = require("@injectivelabs/wallet-base");
|
|
5
|
+
const exceptions_1 = require("@injectivelabs/exceptions");
|
|
6
6
|
const types_js_1 = require("../broadcaster/types.js");
|
|
7
7
|
const getInitialWallet = (args) => {
|
|
8
8
|
if (args.wallet) {
|
|
@@ -10,12 +10,12 @@ const getInitialWallet = (args) => {
|
|
|
10
10
|
}
|
|
11
11
|
const keys = Object.keys(args.strategies || {});
|
|
12
12
|
if (keys.length === 0) {
|
|
13
|
-
|
|
13
|
+
return wallet_base_1.Wallet.Metamask;
|
|
14
14
|
}
|
|
15
|
-
if (keys.includes(wallet_base_1.Wallet.Metamask) && args.
|
|
15
|
+
if (keys.includes(wallet_base_1.Wallet.Metamask) && args.evmOptions) {
|
|
16
16
|
return wallet_base_1.Wallet.Metamask;
|
|
17
17
|
}
|
|
18
|
-
if (keys.includes(wallet_base_1.Wallet.Keplr) && !args.
|
|
18
|
+
if (keys.includes(wallet_base_1.Wallet.Keplr) && !args.evmOptions) {
|
|
19
19
|
return wallet_base_1.Wallet.Keplr;
|
|
20
20
|
}
|
|
21
21
|
return keys[0];
|
|
@@ -45,8 +45,10 @@ class BaseWalletStrategy {
|
|
|
45
45
|
}
|
|
46
46
|
setWallet(wallet) {
|
|
47
47
|
this.wallet = wallet;
|
|
48
|
+
this.getStrategy();
|
|
48
49
|
}
|
|
49
50
|
setMetadata(metadata) {
|
|
51
|
+
console.log('Setting metadata', metadata);
|
|
50
52
|
this.metadata = metadata;
|
|
51
53
|
this.getStrategy().setMetadata?.(metadata);
|
|
52
54
|
}
|
|
@@ -75,8 +77,8 @@ class BaseWalletStrategy {
|
|
|
75
77
|
getEthereumChainId() {
|
|
76
78
|
return this.getStrategy().getEthereumChainId();
|
|
77
79
|
}
|
|
78
|
-
async getEvmTransactionReceipt(txHash,
|
|
79
|
-
return this.getStrategy().getEvmTransactionReceipt(txHash,
|
|
80
|
+
async getEvmTransactionReceipt(txHash, evmChainId) {
|
|
81
|
+
return this.getStrategy().getEvmTransactionReceipt(txHash, evmChainId);
|
|
80
82
|
}
|
|
81
83
|
async getSessionOrConfirm(address) {
|
|
82
84
|
return this.getStrategy().getSessionOrConfirm(address);
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { TxResponse } from '@injectivelabs/sdk-ts';
|
|
2
2
|
import { NetworkEndpoints } from '@injectivelabs/networks';
|
|
3
|
-
import { ChainId,
|
|
3
|
+
import { ChainId, EvmChainId } from '@injectivelabs/ts-types';
|
|
4
4
|
import { MsgBroadcasterOptions, MsgBroadcasterTxOptions } from './types.js';
|
|
5
5
|
import BaseWalletStrategy from '../strategy/BaseWalletStrategy.js';
|
|
6
6
|
/**
|
|
@@ -18,7 +18,7 @@ export declare class MsgBroadcaster {
|
|
|
18
18
|
txTimeout: number;
|
|
19
19
|
simulateTx: boolean;
|
|
20
20
|
txTimeoutOnFeeDelegation: boolean;
|
|
21
|
-
|
|
21
|
+
evmChainId?: EvmChainId;
|
|
22
22
|
gasBufferCoefficient: number;
|
|
23
23
|
retriesOnError: {
|
|
24
24
|
"sdk-20": {
|
|
@@ -30,7 +30,7 @@ export declare class MsgBroadcaster {
|
|
|
30
30
|
httpHeaders?: Record<string, string>;
|
|
31
31
|
constructor(options: MsgBroadcasterOptions);
|
|
32
32
|
setOptions(options: Partial<MsgBroadcasterOptions>): void;
|
|
33
|
-
|
|
33
|
+
getEvmChainId(): Promise<EvmChainId | undefined>;
|
|
34
34
|
/**
|
|
35
35
|
* Broadcasting the transaction using the client
|
|
36
36
|
* side approach for both cosmos and ethereum native wallets
|
|
@@ -2,7 +2,7 @@ import { TxGrpcApi, hexToBuff, PublicKey, SIGN_DIRECT, hexToBase64, ofacWallets,
|
|
|
2
2
|
import { sleep, getStdFee, BigNumberInBase, DEFAULT_GAS_PRICE, DEFAULT_BLOCK_TIMEOUT_HEIGHT, } from '@injectivelabs/utils';
|
|
3
3
|
import { WalletException, GeneralException, isThrownException, UnspecifiedErrorCode, ChainCosmosErrorCode, TransactionException, TransactionChainErrorModule, } from '@injectivelabs/exceptions';
|
|
4
4
|
import { isTestnet, isMainnet, getNetworkInfo, getNetworkEndpoints, } from '@injectivelabs/networks';
|
|
5
|
-
import {
|
|
5
|
+
import { EvmChainId } from '@injectivelabs/ts-types';
|
|
6
6
|
import { WalletStrategyEmitterEventType, } from './types.js';
|
|
7
7
|
import { checkIfTxRunOutOfGas } from '../utils/index.js';
|
|
8
8
|
import { Wallet, isCosmosWallet, WalletDeviceType, isEvmBrowserWallet, isEip712V2OnlyWallet, createEip712StdSignDoc, isCosmosAminoOnlyWallet, getEthereumSignerAddress, getInjectiveSignerAddress, } from '@injectivelabs/wallet-base';
|
|
@@ -34,7 +34,7 @@ export class MsgBroadcaster {
|
|
|
34
34
|
txTimeout = DEFAULT_BLOCK_TIMEOUT_HEIGHT;
|
|
35
35
|
simulateTx = true;
|
|
36
36
|
txTimeoutOnFeeDelegation = false;
|
|
37
|
-
|
|
37
|
+
evmChainId;
|
|
38
38
|
gasBufferCoefficient = 1.2;
|
|
39
39
|
retriesOnError = defaultRetriesConfig();
|
|
40
40
|
httpHeaders;
|
|
@@ -50,8 +50,7 @@ export class MsgBroadcaster {
|
|
|
50
50
|
: true;
|
|
51
51
|
this.gasBufferCoefficient = options.gasBufferCoefficient || 1.2;
|
|
52
52
|
this.chainId = options.chainId || networkInfo.chainId;
|
|
53
|
-
this.
|
|
54
|
-
options.ethereumChainId || networkInfo.ethereumChainId;
|
|
53
|
+
this.evmChainId = options.evmChainId || networkInfo.evmChainId;
|
|
55
54
|
this.endpoints = options.endpoints || getNetworkEndpoints(options.network);
|
|
56
55
|
this.walletStrategy = options.walletStrategy;
|
|
57
56
|
this.httpHeaders = options.httpHeaders;
|
|
@@ -62,17 +61,23 @@ export class MsgBroadcaster {
|
|
|
62
61
|
this.txTimeoutOnFeeDelegation =
|
|
63
62
|
options.txTimeoutOnFeeDelegation || this.txTimeoutOnFeeDelegation;
|
|
64
63
|
}
|
|
65
|
-
async
|
|
64
|
+
async getEvmChainId() {
|
|
66
65
|
const { walletStrategy } = this;
|
|
67
66
|
if (!isEvmBrowserWallet(walletStrategy.wallet)) {
|
|
68
|
-
return;
|
|
67
|
+
return this.evmChainId;
|
|
69
68
|
}
|
|
70
|
-
const mainnetEvmIds = [
|
|
71
|
-
const testnetEvmIds = [
|
|
72
|
-
const devnetEvmIds = [
|
|
69
|
+
const mainnetEvmIds = [EvmChainId.Mainnet, EvmChainId.MainnetEvm];
|
|
70
|
+
const testnetEvmIds = [EvmChainId.Sepolia, EvmChainId.TestnetEvm];
|
|
71
|
+
const devnetEvmIds = [EvmChainId.Sepolia, EvmChainId.DevnetEvm];
|
|
73
72
|
try {
|
|
74
73
|
const chainId = await walletStrategy.getEthereumChainId();
|
|
74
|
+
if (!chainId) {
|
|
75
|
+
return this.evmChainId;
|
|
76
|
+
}
|
|
75
77
|
const evmChainId = parseInt(chainId, 16);
|
|
78
|
+
if (isNaN(evmChainId)) {
|
|
79
|
+
return this.evmChainId;
|
|
80
|
+
}
|
|
76
81
|
if ((isMainnet(this.options.network) &&
|
|
77
82
|
!mainnetEvmIds.includes(evmChainId)) ||
|
|
78
83
|
(isTestnet(this.options.network) &&
|
|
@@ -82,11 +87,11 @@ export class MsgBroadcaster {
|
|
|
82
87
|
!devnetEvmIds.includes(evmChainId))) {
|
|
83
88
|
throw new WalletException(new Error('Your selected network is incorrect'));
|
|
84
89
|
}
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
90
|
+
return evmChainId;
|
|
91
|
+
}
|
|
92
|
+
catch (e) {
|
|
93
|
+
throw new WalletException(e);
|
|
88
94
|
}
|
|
89
|
-
catch { }
|
|
90
95
|
}
|
|
91
96
|
/**
|
|
92
97
|
* Broadcasting the transaction using the client
|
|
@@ -194,12 +199,12 @@ export class MsgBroadcaster {
|
|
|
194
199
|
* @returns transaction hash
|
|
195
200
|
*/
|
|
196
201
|
async broadcastEip712(tx) {
|
|
197
|
-
const { chainId, txTimeout, endpoints,
|
|
202
|
+
const { chainId, txTimeout, endpoints, walletStrategy } = this;
|
|
198
203
|
const msgs = Array.isArray(tx.msgs) ? tx.msgs : [tx.msgs];
|
|
199
|
-
|
|
200
|
-
|
|
204
|
+
const evmChainId = await this.getEvmChainId();
|
|
205
|
+
if (!evmChainId) {
|
|
206
|
+
throw new GeneralException(new Error('Please provide evmChainId'));
|
|
201
207
|
}
|
|
202
|
-
await this.verifyEvmChainId();
|
|
203
208
|
/** Account Details * */
|
|
204
209
|
const { baseAccount, latestHeight } = await this.fetchAccountAndBlockDetails(tx.injectiveAddress);
|
|
205
210
|
const timeoutHeight = new BigNumberInBase(latestHeight).plus(txTimeout);
|
|
@@ -240,7 +245,7 @@ export class MsgBroadcaster {
|
|
|
240
245
|
timeoutHeight: timeoutHeight.toFixed(),
|
|
241
246
|
chainId,
|
|
242
247
|
},
|
|
243
|
-
|
|
248
|
+
evmChainId,
|
|
244
249
|
});
|
|
245
250
|
/** Signing on Ethereum */
|
|
246
251
|
const signature = await walletStrategy.signEip712TypedData(JSON.stringify(eip712TypedData), tx.ethereumAddress);
|
|
@@ -262,7 +267,7 @@ export class MsgBroadcaster {
|
|
|
262
267
|
chainId,
|
|
263
268
|
});
|
|
264
269
|
const web3Extension = createWeb3Extension({
|
|
265
|
-
|
|
270
|
+
evmChainId,
|
|
266
271
|
});
|
|
267
272
|
const txRawEip712 = createTxRawEIP712(txRaw, web3Extension);
|
|
268
273
|
/** Append Signatures */
|
|
@@ -286,12 +291,12 @@ export class MsgBroadcaster {
|
|
|
286
291
|
* @returns transaction hash
|
|
287
292
|
*/
|
|
288
293
|
async broadcastEip712V2(tx) {
|
|
289
|
-
const { chainId, endpoints, txTimeout, walletStrategy
|
|
294
|
+
const { chainId, endpoints, txTimeout, walletStrategy } = this;
|
|
290
295
|
const msgs = Array.isArray(tx.msgs) ? tx.msgs : [tx.msgs];
|
|
291
|
-
|
|
292
|
-
|
|
296
|
+
const evmChainId = await this.getEvmChainId();
|
|
297
|
+
if (!evmChainId) {
|
|
298
|
+
throw new GeneralException(new Error('Please provide evmChainId'));
|
|
293
299
|
}
|
|
294
|
-
await this.verifyEvmChainId();
|
|
295
300
|
/** Account Details * */
|
|
296
301
|
const { baseAccount, latestHeight } = await this.fetchAccountAndBlockDetails(tx.injectiveAddress);
|
|
297
302
|
const timeoutHeight = new BigNumberInBase(latestHeight).plus(txTimeout);
|
|
@@ -333,7 +338,7 @@ export class MsgBroadcaster {
|
|
|
333
338
|
timeoutHeight: timeoutHeight.toFixed(),
|
|
334
339
|
chainId,
|
|
335
340
|
},
|
|
336
|
-
|
|
341
|
+
evmChainId,
|
|
337
342
|
});
|
|
338
343
|
walletStrategy.emit(WalletStrategyEmitterEventType.TransactionPreparationEnd);
|
|
339
344
|
/** Signing on Ethereum */
|
|
@@ -356,7 +361,7 @@ export class MsgBroadcaster {
|
|
|
356
361
|
chainId,
|
|
357
362
|
});
|
|
358
363
|
const web3Extension = createWeb3Extension({
|
|
359
|
-
|
|
364
|
+
evmChainId,
|
|
360
365
|
});
|
|
361
366
|
const txRawEip712 = createTxRawEIP712(txRaw, web3Extension);
|
|
362
367
|
/** Append Signatures */
|
|
@@ -378,13 +383,13 @@ export class MsgBroadcaster {
|
|
|
378
383
|
* @returns transaction hash
|
|
379
384
|
*/
|
|
380
385
|
async broadcastEip712WithFeeDelegation(tx) {
|
|
381
|
-
const { txTimeout, endpoints, simulateTx, httpHeaders, walletStrategy,
|
|
386
|
+
const { txTimeout, endpoints, simulateTx, httpHeaders, walletStrategy, txTimeoutOnFeeDelegation, } = this;
|
|
382
387
|
const msgs = Array.isArray(tx.msgs) ? tx.msgs : [tx.msgs];
|
|
383
388
|
const web3Msgs = msgs.map((msg) => msg.toWeb3());
|
|
384
|
-
|
|
385
|
-
|
|
389
|
+
const evmChainId = await this.getEvmChainId();
|
|
390
|
+
if (!evmChainId) {
|
|
391
|
+
throw new GeneralException(new Error('Please provide evmChainId'));
|
|
386
392
|
}
|
|
387
|
-
await this.verifyEvmChainId();
|
|
388
393
|
const transactionApi = new IndexerGrpcWeb3GwApi(endpoints.web3gw || endpoints.indexer);
|
|
389
394
|
if (httpHeaders) {
|
|
390
395
|
transactionApi.setMetadata(httpHeaders);
|
|
@@ -403,7 +408,7 @@ export class MsgBroadcaster {
|
|
|
403
408
|
memo: tx.memo,
|
|
404
409
|
message: web3Msgs,
|
|
405
410
|
address: tx.ethereumAddress,
|
|
406
|
-
chainId:
|
|
411
|
+
chainId: evmChainId,
|
|
407
412
|
gasLimit: getGasPriceBasedOnMessage(msgs),
|
|
408
413
|
estimateGas: simulateTx,
|
|
409
414
|
});
|
|
@@ -413,7 +418,7 @@ export class MsgBroadcaster {
|
|
|
413
418
|
signature,
|
|
414
419
|
message: web3Msgs,
|
|
415
420
|
txResponse: prepareTxResponse,
|
|
416
|
-
chainId:
|
|
421
|
+
chainId: evmChainId,
|
|
417
422
|
});
|
|
418
423
|
try {
|
|
419
424
|
walletStrategy.emit(WalletStrategyEmitterEventType.TransactionBroadcastStart);
|
|
@@ -540,7 +545,7 @@ export class MsgBroadcaster {
|
|
|
540
545
|
* @param tx the transaction that needs to be broadcasted
|
|
541
546
|
*/
|
|
542
547
|
async experimentalBroadcastWalletThroughLedger(tx) {
|
|
543
|
-
const { chainId, txTimeout, endpoints, simulateTx, walletStrategy,
|
|
548
|
+
const { chainId, txTimeout, endpoints, evmChainId, simulateTx, walletStrategy, } = this;
|
|
544
549
|
const msgs = Array.isArray(tx.msgs) ? tx.msgs : [tx.msgs];
|
|
545
550
|
/**
|
|
546
551
|
* We can only use this method
|
|
@@ -553,8 +558,8 @@ export class MsgBroadcaster {
|
|
|
553
558
|
throw new GeneralException(new Error(`This method can only be used when Ledger is connected through ${walletStrategy.getWallet()}`));
|
|
554
559
|
}
|
|
555
560
|
}
|
|
556
|
-
if (!
|
|
557
|
-
throw new GeneralException(new Error('Please provide
|
|
561
|
+
if (!evmChainId) {
|
|
562
|
+
throw new GeneralException(new Error('Please provide evmChainId'));
|
|
558
563
|
}
|
|
559
564
|
const cosmosWallet = walletStrategy.getCosmosWallet(chainId);
|
|
560
565
|
const { baseAccount, latestHeight } = await this.fetchAccountAndBlockDetails(tx.injectiveAddress);
|
|
@@ -572,7 +577,7 @@ export class MsgBroadcaster {
|
|
|
572
577
|
sequence: baseAccount.sequence.toString(),
|
|
573
578
|
accountNumber: baseAccount.accountNumber.toString(),
|
|
574
579
|
},
|
|
575
|
-
|
|
580
|
+
evmChainId,
|
|
576
581
|
});
|
|
577
582
|
const aminoSignResponse = await cosmosWallet.signEIP712CosmosTx({
|
|
578
583
|
eip712: eip712TypedData,
|
|
@@ -603,7 +608,7 @@ export class MsgBroadcaster {
|
|
|
603
608
|
});
|
|
604
609
|
/** Preparing the transaction for client broadcasting */
|
|
605
610
|
const web3Extension = createWeb3Extension({
|
|
606
|
-
|
|
611
|
+
evmChainId,
|
|
607
612
|
});
|
|
608
613
|
const txRawEip712 = createTxRawEIP712(txRaw, web3Extension);
|
|
609
614
|
if (simulateTx) {
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { EthereumChainId } from '@injectivelabs/ts-types';
|
|
2
1
|
import { Network } from '@injectivelabs/networks';
|
|
2
|
+
import { EvmChainId } from '@injectivelabs/ts-types';
|
|
3
3
|
import BaseWalletStrategy from '../strategy/BaseWalletStrategy.js';
|
|
4
4
|
interface SendTransactionOptions {
|
|
5
5
|
tx: {
|
|
@@ -11,7 +11,7 @@ interface SendTransactionOptions {
|
|
|
11
11
|
data: any;
|
|
12
12
|
};
|
|
13
13
|
address: string;
|
|
14
|
-
|
|
14
|
+
evmChainId?: EvmChainId;
|
|
15
15
|
}
|
|
16
16
|
/**
|
|
17
17
|
* Preparing and broadcasting
|
|
@@ -19,10 +19,10 @@ interface SendTransactionOptions {
|
|
|
19
19
|
*/
|
|
20
20
|
export declare class Web3Broadcaster {
|
|
21
21
|
private walletStrategy;
|
|
22
|
-
private
|
|
23
|
-
constructor({ walletStrategy,
|
|
22
|
+
private evmChainId;
|
|
23
|
+
constructor({ walletStrategy, evmChainId, }: {
|
|
24
24
|
walletStrategy: BaseWalletStrategy;
|
|
25
|
-
|
|
25
|
+
evmChainId: EvmChainId;
|
|
26
26
|
network: Network;
|
|
27
27
|
});
|
|
28
28
|
sendTransaction(args: SendTransactionOptions): Promise<string>;
|
|
@@ -5,18 +5,18 @@ import { Web3Exception } from '@injectivelabs/exceptions';
|
|
|
5
5
|
*/
|
|
6
6
|
export class Web3Broadcaster {
|
|
7
7
|
walletStrategy;
|
|
8
|
-
|
|
9
|
-
constructor({ walletStrategy,
|
|
8
|
+
evmChainId;
|
|
9
|
+
constructor({ walletStrategy, evmChainId, }) {
|
|
10
|
+
this.evmChainId = evmChainId;
|
|
10
11
|
this.walletStrategy = walletStrategy;
|
|
11
|
-
this.ethereumChainId = ethereumChainId;
|
|
12
12
|
}
|
|
13
13
|
async sendTransaction(args) {
|
|
14
|
-
const {
|
|
14
|
+
const { evmChainId, walletStrategy } = this;
|
|
15
15
|
try {
|
|
16
|
-
const chainId = args.
|
|
16
|
+
const chainId = args.evmChainId || evmChainId;
|
|
17
17
|
const txHash = await walletStrategy.sendEvmTransaction(args.tx, {
|
|
18
|
+
evmChainId: chainId,
|
|
18
19
|
address: args.address,
|
|
19
|
-
ethereumChainId: chainId,
|
|
20
20
|
});
|
|
21
21
|
await walletStrategy.getEvmTransactionReceipt(txHash, chainId);
|
|
22
22
|
return txHash;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { EventEmitter } from 'eventemitter3';
|
|
2
2
|
import { Msgs } from '@injectivelabs/sdk-ts';
|
|
3
|
-
import { ChainId,
|
|
3
|
+
import { ChainId, EvmChainId } from '@injectivelabs/ts-types';
|
|
4
4
|
import { Network, NetworkEndpoints } from '@injectivelabs/networks';
|
|
5
5
|
import BaseWalletStrategy from '../strategy/BaseWalletStrategy.js';
|
|
6
6
|
export interface MsgBroadcasterTxOptions {
|
|
@@ -23,7 +23,7 @@ export interface MsgBroadcasterOptions {
|
|
|
23
23
|
network: Network;
|
|
24
24
|
endpoints?: NetworkEndpoints;
|
|
25
25
|
chainId?: ChainId;
|
|
26
|
-
|
|
26
|
+
evmChainId?: EvmChainId;
|
|
27
27
|
feePayerPubKey?: string;
|
|
28
28
|
simulateTx?: boolean;
|
|
29
29
|
txTimeoutOnFeeDelegation?: boolean;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { TxRaw, TxResponse, AminoSignResponse, DirectSignResponse } from '@injectivelabs/sdk-ts';
|
|
2
|
-
import { ChainId, AccountAddress, EthereumChainId } from '@injectivelabs/ts-types';
|
|
3
2
|
import { Wallet, WalletDeviceType, type WalletMetadata, ConcreteStrategiesArg, SendTransactionOptions, ConcreteWalletStrategy, onAccountChangeCallback, onChainIdChangeCallback, WalletStrategyArguments, CosmosWalletAbstraction, WalletStrategy as WalletStrategyInterface } from '@injectivelabs/wallet-base';
|
|
3
|
+
import { ChainId, EvmChainId, AccountAddress } from '@injectivelabs/ts-types';
|
|
4
4
|
import { StdSignDoc } from '@keplr-wallet/types';
|
|
5
5
|
import { WalletStrategyEmitter } from '../broadcaster/types.js';
|
|
6
6
|
export default class BaseWalletStrategy implements WalletStrategyInterface {
|
|
@@ -24,13 +24,13 @@ export default class BaseWalletStrategy implements WalletStrategyInterface {
|
|
|
24
24
|
enable(args?: unknown): Promise<boolean>;
|
|
25
25
|
enableAndGetAddresses(args?: unknown): Promise<AccountAddress[]>;
|
|
26
26
|
getEthereumChainId(): Promise<string>;
|
|
27
|
-
getEvmTransactionReceipt(txHash: string,
|
|
27
|
+
getEvmTransactionReceipt(txHash: string, evmChainId?: EvmChainId): Promise<void>;
|
|
28
28
|
getSessionOrConfirm(address?: AccountAddress): Promise<string>;
|
|
29
29
|
getWalletClient<T>(): Promise<T>;
|
|
30
30
|
sendTransaction(tx: DirectSignResponse | TxRaw, options: SendTransactionOptions): Promise<TxResponse>;
|
|
31
31
|
sendEvmTransaction(tx: any, options: {
|
|
32
|
+
evmChainId: EvmChainId;
|
|
32
33
|
address: AccountAddress;
|
|
33
|
-
ethereumChainId: EthereumChainId;
|
|
34
34
|
}): Promise<string>;
|
|
35
35
|
signEip712TypedData(eip712TypedData: string, address: AccountAddress): Promise<string>;
|
|
36
36
|
signAminoCosmosTransaction(transaction: {
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { EventEmitter } from 'eventemitter3';
|
|
2
|
-
import { GeneralException, WalletException } from '@injectivelabs/exceptions';
|
|
3
2
|
import { Wallet, isEvmWallet, isCosmosWallet, } from '@injectivelabs/wallet-base';
|
|
3
|
+
import { GeneralException, WalletException } from '@injectivelabs/exceptions';
|
|
4
4
|
import { WalletStrategyEmitterEventType, } from '../broadcaster/types.js';
|
|
5
5
|
const getInitialWallet = (args) => {
|
|
6
6
|
if (args.wallet) {
|
|
@@ -8,12 +8,12 @@ const getInitialWallet = (args) => {
|
|
|
8
8
|
}
|
|
9
9
|
const keys = Object.keys(args.strategies || {});
|
|
10
10
|
if (keys.length === 0) {
|
|
11
|
-
|
|
11
|
+
return Wallet.Metamask;
|
|
12
12
|
}
|
|
13
|
-
if (keys.includes(Wallet.Metamask) && args.
|
|
13
|
+
if (keys.includes(Wallet.Metamask) && args.evmOptions) {
|
|
14
14
|
return Wallet.Metamask;
|
|
15
15
|
}
|
|
16
|
-
if (keys.includes(Wallet.Keplr) && !args.
|
|
16
|
+
if (keys.includes(Wallet.Keplr) && !args.evmOptions) {
|
|
17
17
|
return Wallet.Keplr;
|
|
18
18
|
}
|
|
19
19
|
return keys[0];
|
|
@@ -43,8 +43,10 @@ export default class BaseWalletStrategy {
|
|
|
43
43
|
}
|
|
44
44
|
setWallet(wallet) {
|
|
45
45
|
this.wallet = wallet;
|
|
46
|
+
this.getStrategy();
|
|
46
47
|
}
|
|
47
48
|
setMetadata(metadata) {
|
|
49
|
+
console.log('Setting metadata', metadata);
|
|
48
50
|
this.metadata = metadata;
|
|
49
51
|
this.getStrategy().setMetadata?.(metadata);
|
|
50
52
|
}
|
|
@@ -73,8 +75,8 @@ export default class BaseWalletStrategy {
|
|
|
73
75
|
getEthereumChainId() {
|
|
74
76
|
return this.getStrategy().getEthereumChainId();
|
|
75
77
|
}
|
|
76
|
-
async getEvmTransactionReceipt(txHash,
|
|
77
|
-
return this.getStrategy().getEvmTransactionReceipt(txHash,
|
|
78
|
+
async getEvmTransactionReceipt(txHash, evmChainId) {
|
|
79
|
+
return this.getStrategy().getEvmTransactionReceipt(txHash, evmChainId);
|
|
78
80
|
}
|
|
79
81
|
async getSessionOrConfirm(address) {
|
|
80
82
|
return this.getStrategy().getSessionOrConfirm(address);
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@injectivelabs/wallet-core",
|
|
3
3
|
"description": "Core wallet strategy",
|
|
4
|
-
"version": "1.16.
|
|
4
|
+
"version": "1.16.5-alpha.0",
|
|
5
5
|
"sideEffects": false,
|
|
6
6
|
"type": "module",
|
|
7
7
|
"author": {
|
|
@@ -41,10 +41,10 @@
|
|
|
41
41
|
}
|
|
42
42
|
},
|
|
43
43
|
"scripts": {
|
|
44
|
-
"build": "
|
|
44
|
+
"build": "pnpm build:cjs && pnpm build:esm && pnpm build:post",
|
|
45
45
|
"build:cjs": "tsc --build --force tsconfig.build.json",
|
|
46
46
|
"build:esm": "tsc --build --force tsconfig.build.esm.json",
|
|
47
|
-
"build:watch": "tsc --build -w tsconfig.build.json && tsc -w --build tsconfig.build.esm.json &&
|
|
47
|
+
"build:watch": "tsc --build -w tsconfig.build.json && tsc -w --build tsconfig.build.esm.json && pnpm build:post",
|
|
48
48
|
"build:post": "shx cp ../../../etc/stub/package.json.stub dist/cjs/package.json && shx cp ../../../etc/stub/package.esm.json.stub dist/esm/package.json",
|
|
49
49
|
"clean": "tsc --build tsconfig.build.json --clean && tsc --build tsconfig.build.esm.json --clean && shx rm -rf coverage *.log junit.xml dist && jest --clearCache && shx mkdir -p dist",
|
|
50
50
|
"test": "jest",
|
|
@@ -56,17 +56,17 @@
|
|
|
56
56
|
"start": "node dist/index.js"
|
|
57
57
|
},
|
|
58
58
|
"dependencies": {
|
|
59
|
-
"@injectivelabs/exceptions": "
|
|
60
|
-
"@injectivelabs/networks": "
|
|
61
|
-
"@injectivelabs/sdk-ts": "
|
|
62
|
-
"@injectivelabs/ts-types": "
|
|
63
|
-
"@injectivelabs/utils": "
|
|
64
|
-
"@injectivelabs/wallet-base": "
|
|
59
|
+
"@injectivelabs/exceptions": "1.16.5-alpha.0",
|
|
60
|
+
"@injectivelabs/networks": "1.16.5-alpha.0",
|
|
61
|
+
"@injectivelabs/sdk-ts": "1.16.5-alpha.0",
|
|
62
|
+
"@injectivelabs/ts-types": "1.16.5-alpha.0",
|
|
63
|
+
"@injectivelabs/utils": "1.16.5-alpha.0",
|
|
64
|
+
"@injectivelabs/wallet-base": "1.16.5-alpha.0",
|
|
65
65
|
"@keplr-wallet/types": "^0.12.159",
|
|
66
66
|
"eventemitter3": "^5.0.1"
|
|
67
67
|
},
|
|
68
68
|
"devDependencies": {
|
|
69
69
|
"shx": "^0.3.3"
|
|
70
70
|
},
|
|
71
|
-
"gitHead": "
|
|
71
|
+
"gitHead": "d3684b59ca82800bc469f0b5c2796c9491b8b2cd"
|
|
72
72
|
}
|