@injectivelabs/wallet-core 1.16.2-alpha.1 → 1.16.2
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 +2 -2
- package/dist/cjs/broadcaster/MsgBroadcaster.js +23 -22
- 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 +6 -8
- package/dist/esm/broadcaster/MsgBroadcaster.d.ts +2 -2
- package/dist/esm/broadcaster/MsgBroadcaster.js +23 -22
- 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 +6 -8
- 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
|
+
yarn 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({
|
|
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({
|
|
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, EthereumChainId } 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
|
+
ethereumChainId?: EthereumChainId;
|
|
22
22
|
gasBufferCoefficient: number;
|
|
23
23
|
retriesOnError: {
|
|
24
24
|
"sdk-20": {
|
|
@@ -36,7 +36,7 @@ class MsgBroadcaster {
|
|
|
36
36
|
txTimeout = utils_1.DEFAULT_BLOCK_TIMEOUT_HEIGHT;
|
|
37
37
|
simulateTx = true;
|
|
38
38
|
txTimeoutOnFeeDelegation = false;
|
|
39
|
-
|
|
39
|
+
ethereumChainId;
|
|
40
40
|
gasBufferCoefficient = 1.2;
|
|
41
41
|
retriesOnError = defaultRetriesConfig();
|
|
42
42
|
httpHeaders;
|
|
@@ -52,7 +52,8 @@ class MsgBroadcaster {
|
|
|
52
52
|
: true;
|
|
53
53
|
this.gasBufferCoefficient = options.gasBufferCoefficient || 1.2;
|
|
54
54
|
this.chainId = options.chainId || networkInfo.chainId;
|
|
55
|
-
this.
|
|
55
|
+
this.ethereumChainId =
|
|
56
|
+
options.ethereumChainId || networkInfo.ethereumChainId;
|
|
56
57
|
this.endpoints = options.endpoints || (0, networks_1.getNetworkEndpoints)(options.network);
|
|
57
58
|
this.walletStrategy = options.walletStrategy;
|
|
58
59
|
this.httpHeaders = options.httpHeaders;
|
|
@@ -169,10 +170,10 @@ class MsgBroadcaster {
|
|
|
169
170
|
* @returns transaction hash
|
|
170
171
|
*/
|
|
171
172
|
async broadcastEip712(tx) {
|
|
172
|
-
const { chainId, txTimeout, endpoints,
|
|
173
|
+
const { chainId, txTimeout, endpoints, ethereumChainId, walletStrategy } = this;
|
|
173
174
|
const msgs = Array.isArray(tx.msgs) ? tx.msgs : [tx.msgs];
|
|
174
|
-
if (!
|
|
175
|
-
throw new exceptions_1.GeneralException(new Error('Please provide
|
|
175
|
+
if (!ethereumChainId) {
|
|
176
|
+
throw new exceptions_1.GeneralException(new Error('Please provide ethereumChainId'));
|
|
176
177
|
}
|
|
177
178
|
/** Account Details * */
|
|
178
179
|
const { baseAccount, latestHeight } = await this.fetchAccountAndBlockDetails(tx.injectiveAddress);
|
|
@@ -214,7 +215,7 @@ class MsgBroadcaster {
|
|
|
214
215
|
timeoutHeight: timeoutHeight.toFixed(),
|
|
215
216
|
chainId,
|
|
216
217
|
},
|
|
217
|
-
|
|
218
|
+
ethereumChainId,
|
|
218
219
|
});
|
|
219
220
|
/** Signing on Ethereum */
|
|
220
221
|
const signature = await walletStrategy.signEip712TypedData(JSON.stringify(eip712TypedData), tx.ethereumAddress);
|
|
@@ -236,7 +237,7 @@ class MsgBroadcaster {
|
|
|
236
237
|
chainId,
|
|
237
238
|
});
|
|
238
239
|
const web3Extension = (0, sdk_ts_1.createWeb3Extension)({
|
|
239
|
-
|
|
240
|
+
ethereumChainId,
|
|
240
241
|
});
|
|
241
242
|
const txRawEip712 = (0, sdk_ts_1.createTxRawEIP712)(txRaw, web3Extension);
|
|
242
243
|
/** Append Signatures */
|
|
@@ -260,10 +261,10 @@ class MsgBroadcaster {
|
|
|
260
261
|
* @returns transaction hash
|
|
261
262
|
*/
|
|
262
263
|
async broadcastEip712V2(tx) {
|
|
263
|
-
const { chainId, endpoints, txTimeout, walletStrategy,
|
|
264
|
+
const { chainId, endpoints, txTimeout, walletStrategy, ethereumChainId } = this;
|
|
264
265
|
const msgs = Array.isArray(tx.msgs) ? tx.msgs : [tx.msgs];
|
|
265
|
-
if (!
|
|
266
|
-
throw new exceptions_1.GeneralException(new Error('Please provide
|
|
266
|
+
if (!ethereumChainId) {
|
|
267
|
+
throw new exceptions_1.GeneralException(new Error('Please provide ethereumChainId'));
|
|
267
268
|
}
|
|
268
269
|
/** Account Details * */
|
|
269
270
|
const { baseAccount, latestHeight } = await this.fetchAccountAndBlockDetails(tx.injectiveAddress);
|
|
@@ -306,7 +307,7 @@ class MsgBroadcaster {
|
|
|
306
307
|
timeoutHeight: timeoutHeight.toFixed(),
|
|
307
308
|
chainId,
|
|
308
309
|
},
|
|
309
|
-
|
|
310
|
+
ethereumChainId,
|
|
310
311
|
});
|
|
311
312
|
walletStrategy.emit(types_js_1.WalletStrategyEmitterEventType.TransactionPreparationEnd);
|
|
312
313
|
/** Signing on Ethereum */
|
|
@@ -329,7 +330,7 @@ class MsgBroadcaster {
|
|
|
329
330
|
chainId,
|
|
330
331
|
});
|
|
331
332
|
const web3Extension = (0, sdk_ts_1.createWeb3Extension)({
|
|
332
|
-
|
|
333
|
+
ethereumChainId,
|
|
333
334
|
});
|
|
334
335
|
const txRawEip712 = (0, sdk_ts_1.createTxRawEIP712)(txRaw, web3Extension);
|
|
335
336
|
/** Append Signatures */
|
|
@@ -351,11 +352,11 @@ class MsgBroadcaster {
|
|
|
351
352
|
* @returns transaction hash
|
|
352
353
|
*/
|
|
353
354
|
async broadcastEip712WithFeeDelegation(tx) {
|
|
354
|
-
const { txTimeout, endpoints,
|
|
355
|
+
const { txTimeout, endpoints, simulateTx, httpHeaders, walletStrategy, ethereumChainId, txTimeoutOnFeeDelegation, } = this;
|
|
355
356
|
const msgs = Array.isArray(tx.msgs) ? tx.msgs : [tx.msgs];
|
|
356
357
|
const web3Msgs = msgs.map((msg) => msg.toWeb3());
|
|
357
|
-
if (!
|
|
358
|
-
throw new exceptions_1.GeneralException(new Error('Please provide
|
|
358
|
+
if (!ethereumChainId) {
|
|
359
|
+
throw new exceptions_1.GeneralException(new Error('Please provide ethereumChainId'));
|
|
359
360
|
}
|
|
360
361
|
const transactionApi = new sdk_ts_1.IndexerGrpcWeb3GwApi(endpoints.web3gw || endpoints.indexer);
|
|
361
362
|
if (httpHeaders) {
|
|
@@ -375,7 +376,7 @@ class MsgBroadcaster {
|
|
|
375
376
|
memo: tx.memo,
|
|
376
377
|
message: web3Msgs,
|
|
377
378
|
address: tx.ethereumAddress,
|
|
378
|
-
chainId:
|
|
379
|
+
chainId: ethereumChainId,
|
|
379
380
|
gasLimit: (0, sdk_ts_1.getGasPriceBasedOnMessage)(msgs),
|
|
380
381
|
estimateGas: simulateTx,
|
|
381
382
|
});
|
|
@@ -385,7 +386,7 @@ class MsgBroadcaster {
|
|
|
385
386
|
signature,
|
|
386
387
|
message: web3Msgs,
|
|
387
388
|
txResponse: prepareTxResponse,
|
|
388
|
-
chainId:
|
|
389
|
+
chainId: ethereumChainId,
|
|
389
390
|
});
|
|
390
391
|
try {
|
|
391
392
|
walletStrategy.emit(types_js_1.WalletStrategyEmitterEventType.TransactionBroadcastStart);
|
|
@@ -512,7 +513,7 @@ class MsgBroadcaster {
|
|
|
512
513
|
* @param tx the transaction that needs to be broadcasted
|
|
513
514
|
*/
|
|
514
515
|
async experimentalBroadcastWalletThroughLedger(tx) {
|
|
515
|
-
const { chainId, txTimeout, endpoints,
|
|
516
|
+
const { chainId, txTimeout, endpoints, simulateTx, walletStrategy, ethereumChainId, } = this;
|
|
516
517
|
const msgs = Array.isArray(tx.msgs) ? tx.msgs : [tx.msgs];
|
|
517
518
|
/**
|
|
518
519
|
* We can only use this method
|
|
@@ -525,8 +526,8 @@ class MsgBroadcaster {
|
|
|
525
526
|
throw new exceptions_1.GeneralException(new Error(`This method can only be used when Ledger is connected through ${walletStrategy.getWallet()}`));
|
|
526
527
|
}
|
|
527
528
|
}
|
|
528
|
-
if (!
|
|
529
|
-
throw new exceptions_1.GeneralException(new Error('Please provide
|
|
529
|
+
if (!ethereumChainId) {
|
|
530
|
+
throw new exceptions_1.GeneralException(new Error('Please provide ethereumChainId'));
|
|
530
531
|
}
|
|
531
532
|
const cosmosWallet = walletStrategy.getCosmosWallet(chainId);
|
|
532
533
|
const { baseAccount, latestHeight } = await this.fetchAccountAndBlockDetails(tx.injectiveAddress);
|
|
@@ -544,7 +545,7 @@ class MsgBroadcaster {
|
|
|
544
545
|
sequence: baseAccount.sequence.toString(),
|
|
545
546
|
accountNumber: baseAccount.accountNumber.toString(),
|
|
546
547
|
},
|
|
547
|
-
|
|
548
|
+
ethereumChainId,
|
|
548
549
|
});
|
|
549
550
|
const aminoSignResponse = await cosmosWallet.signEIP712CosmosTx({
|
|
550
551
|
eip712: eip712TypedData,
|
|
@@ -575,7 +576,7 @@ class MsgBroadcaster {
|
|
|
575
576
|
});
|
|
576
577
|
/** Preparing the transaction for client broadcasting */
|
|
577
578
|
const web3Extension = (0, sdk_ts_1.createWeb3Extension)({
|
|
578
|
-
|
|
579
|
+
ethereumChainId,
|
|
579
580
|
});
|
|
580
581
|
const txRawEip712 = (0, sdk_ts_1.createTxRawEIP712)(txRaw, web3Extension);
|
|
581
582
|
if (simulateTx) {
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
+
import { EthereumChainId } from '@injectivelabs/ts-types';
|
|
1
2
|
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
|
+
ethereumChainId?: EthereumChainId;
|
|
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 ethereumChainId;
|
|
23
|
+
constructor({ walletStrategy, ethereumChainId, }: {
|
|
24
24
|
walletStrategy: BaseWalletStrategy;
|
|
25
|
-
|
|
25
|
+
ethereumChainId: EthereumChainId;
|
|
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,
|
|
13
|
-
this.evmChainId = evmChainId;
|
|
11
|
+
ethereumChainId;
|
|
12
|
+
constructor({ walletStrategy, ethereumChainId, }) {
|
|
14
13
|
this.walletStrategy = walletStrategy;
|
|
14
|
+
this.ethereumChainId = ethereumChainId;
|
|
15
15
|
}
|
|
16
16
|
async sendTransaction(args) {
|
|
17
|
-
const {
|
|
17
|
+
const { walletStrategy, ethereumChainId } = this;
|
|
18
18
|
try {
|
|
19
|
-
const chainId = args.
|
|
19
|
+
const chainId = args.ethereumChainId || ethereumChainId;
|
|
20
20
|
const txHash = await walletStrategy.sendEvmTransaction(args.tx, {
|
|
21
|
-
evmChainId: chainId,
|
|
22
21
|
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, EthereumChainId } 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
|
+
ethereumChainId?: EthereumChainId;
|
|
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';
|
|
2
3
|
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, ethereumChainId?: EthereumChainId): 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;
|
|
33
32
|
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 wallet_base_1 = require("@injectivelabs/wallet-base");
|
|
5
4
|
const exceptions_1 = require("@injectivelabs/exceptions");
|
|
5
|
+
const wallet_base_1 = require("@injectivelabs/wallet-base");
|
|
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
|
+
throw new exceptions_1.GeneralException(new Error('No strategies provided to BaseWalletStrategy'));
|
|
14
14
|
}
|
|
15
|
-
if (keys.includes(wallet_base_1.Wallet.Metamask) && args.
|
|
15
|
+
if (keys.includes(wallet_base_1.Wallet.Metamask) && args.ethereumOptions) {
|
|
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.ethereumOptions) {
|
|
19
19
|
return wallet_base_1.Wallet.Keplr;
|
|
20
20
|
}
|
|
21
21
|
return keys[0];
|
|
@@ -45,10 +45,8 @@ class BaseWalletStrategy {
|
|
|
45
45
|
}
|
|
46
46
|
setWallet(wallet) {
|
|
47
47
|
this.wallet = wallet;
|
|
48
|
-
this.getStrategy();
|
|
49
48
|
}
|
|
50
49
|
setMetadata(metadata) {
|
|
51
|
-
console.log('Setting metadata', metadata);
|
|
52
50
|
this.metadata = metadata;
|
|
53
51
|
this.getStrategy().setMetadata?.(metadata);
|
|
54
52
|
}
|
|
@@ -77,8 +75,8 @@ class BaseWalletStrategy {
|
|
|
77
75
|
getEthereumChainId() {
|
|
78
76
|
return this.getStrategy().getEthereumChainId();
|
|
79
77
|
}
|
|
80
|
-
async getEvmTransactionReceipt(txHash,
|
|
81
|
-
return this.getStrategy().getEvmTransactionReceipt(txHash,
|
|
78
|
+
async getEvmTransactionReceipt(txHash, ethereumChainId) {
|
|
79
|
+
return this.getStrategy().getEvmTransactionReceipt(txHash, ethereumChainId);
|
|
82
80
|
}
|
|
83
81
|
async getSessionOrConfirm(address) {
|
|
84
82
|
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, EthereumChainId } 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
|
+
ethereumChainId?: EthereumChainId;
|
|
22
22
|
gasBufferCoefficient: number;
|
|
23
23
|
retriesOnError: {
|
|
24
24
|
"sdk-20": {
|
|
@@ -33,7 +33,7 @@ export class MsgBroadcaster {
|
|
|
33
33
|
txTimeout = DEFAULT_BLOCK_TIMEOUT_HEIGHT;
|
|
34
34
|
simulateTx = true;
|
|
35
35
|
txTimeoutOnFeeDelegation = false;
|
|
36
|
-
|
|
36
|
+
ethereumChainId;
|
|
37
37
|
gasBufferCoefficient = 1.2;
|
|
38
38
|
retriesOnError = defaultRetriesConfig();
|
|
39
39
|
httpHeaders;
|
|
@@ -49,7 +49,8 @@ export class MsgBroadcaster {
|
|
|
49
49
|
: true;
|
|
50
50
|
this.gasBufferCoefficient = options.gasBufferCoefficient || 1.2;
|
|
51
51
|
this.chainId = options.chainId || networkInfo.chainId;
|
|
52
|
-
this.
|
|
52
|
+
this.ethereumChainId =
|
|
53
|
+
options.ethereumChainId || networkInfo.ethereumChainId;
|
|
53
54
|
this.endpoints = options.endpoints || getNetworkEndpoints(options.network);
|
|
54
55
|
this.walletStrategy = options.walletStrategy;
|
|
55
56
|
this.httpHeaders = options.httpHeaders;
|
|
@@ -166,10 +167,10 @@ export class MsgBroadcaster {
|
|
|
166
167
|
* @returns transaction hash
|
|
167
168
|
*/
|
|
168
169
|
async broadcastEip712(tx) {
|
|
169
|
-
const { chainId, txTimeout, endpoints,
|
|
170
|
+
const { chainId, txTimeout, endpoints, ethereumChainId, walletStrategy } = this;
|
|
170
171
|
const msgs = Array.isArray(tx.msgs) ? tx.msgs : [tx.msgs];
|
|
171
|
-
if (!
|
|
172
|
-
throw new GeneralException(new Error('Please provide
|
|
172
|
+
if (!ethereumChainId) {
|
|
173
|
+
throw new GeneralException(new Error('Please provide ethereumChainId'));
|
|
173
174
|
}
|
|
174
175
|
/** Account Details * */
|
|
175
176
|
const { baseAccount, latestHeight } = await this.fetchAccountAndBlockDetails(tx.injectiveAddress);
|
|
@@ -211,7 +212,7 @@ export class MsgBroadcaster {
|
|
|
211
212
|
timeoutHeight: timeoutHeight.toFixed(),
|
|
212
213
|
chainId,
|
|
213
214
|
},
|
|
214
|
-
|
|
215
|
+
ethereumChainId,
|
|
215
216
|
});
|
|
216
217
|
/** Signing on Ethereum */
|
|
217
218
|
const signature = await walletStrategy.signEip712TypedData(JSON.stringify(eip712TypedData), tx.ethereumAddress);
|
|
@@ -233,7 +234,7 @@ export class MsgBroadcaster {
|
|
|
233
234
|
chainId,
|
|
234
235
|
});
|
|
235
236
|
const web3Extension = createWeb3Extension({
|
|
236
|
-
|
|
237
|
+
ethereumChainId,
|
|
237
238
|
});
|
|
238
239
|
const txRawEip712 = createTxRawEIP712(txRaw, web3Extension);
|
|
239
240
|
/** Append Signatures */
|
|
@@ -257,10 +258,10 @@ export class MsgBroadcaster {
|
|
|
257
258
|
* @returns transaction hash
|
|
258
259
|
*/
|
|
259
260
|
async broadcastEip712V2(tx) {
|
|
260
|
-
const { chainId, endpoints, txTimeout, walletStrategy,
|
|
261
|
+
const { chainId, endpoints, txTimeout, walletStrategy, ethereumChainId } = this;
|
|
261
262
|
const msgs = Array.isArray(tx.msgs) ? tx.msgs : [tx.msgs];
|
|
262
|
-
if (!
|
|
263
|
-
throw new GeneralException(new Error('Please provide
|
|
263
|
+
if (!ethereumChainId) {
|
|
264
|
+
throw new GeneralException(new Error('Please provide ethereumChainId'));
|
|
264
265
|
}
|
|
265
266
|
/** Account Details * */
|
|
266
267
|
const { baseAccount, latestHeight } = await this.fetchAccountAndBlockDetails(tx.injectiveAddress);
|
|
@@ -303,7 +304,7 @@ export class MsgBroadcaster {
|
|
|
303
304
|
timeoutHeight: timeoutHeight.toFixed(),
|
|
304
305
|
chainId,
|
|
305
306
|
},
|
|
306
|
-
|
|
307
|
+
ethereumChainId,
|
|
307
308
|
});
|
|
308
309
|
walletStrategy.emit(WalletStrategyEmitterEventType.TransactionPreparationEnd);
|
|
309
310
|
/** Signing on Ethereum */
|
|
@@ -326,7 +327,7 @@ export class MsgBroadcaster {
|
|
|
326
327
|
chainId,
|
|
327
328
|
});
|
|
328
329
|
const web3Extension = createWeb3Extension({
|
|
329
|
-
|
|
330
|
+
ethereumChainId,
|
|
330
331
|
});
|
|
331
332
|
const txRawEip712 = createTxRawEIP712(txRaw, web3Extension);
|
|
332
333
|
/** Append Signatures */
|
|
@@ -348,11 +349,11 @@ export class MsgBroadcaster {
|
|
|
348
349
|
* @returns transaction hash
|
|
349
350
|
*/
|
|
350
351
|
async broadcastEip712WithFeeDelegation(tx) {
|
|
351
|
-
const { txTimeout, endpoints,
|
|
352
|
+
const { txTimeout, endpoints, simulateTx, httpHeaders, walletStrategy, ethereumChainId, txTimeoutOnFeeDelegation, } = this;
|
|
352
353
|
const msgs = Array.isArray(tx.msgs) ? tx.msgs : [tx.msgs];
|
|
353
354
|
const web3Msgs = msgs.map((msg) => msg.toWeb3());
|
|
354
|
-
if (!
|
|
355
|
-
throw new GeneralException(new Error('Please provide
|
|
355
|
+
if (!ethereumChainId) {
|
|
356
|
+
throw new GeneralException(new Error('Please provide ethereumChainId'));
|
|
356
357
|
}
|
|
357
358
|
const transactionApi = new IndexerGrpcWeb3GwApi(endpoints.web3gw || endpoints.indexer);
|
|
358
359
|
if (httpHeaders) {
|
|
@@ -372,7 +373,7 @@ export class MsgBroadcaster {
|
|
|
372
373
|
memo: tx.memo,
|
|
373
374
|
message: web3Msgs,
|
|
374
375
|
address: tx.ethereumAddress,
|
|
375
|
-
chainId:
|
|
376
|
+
chainId: ethereumChainId,
|
|
376
377
|
gasLimit: getGasPriceBasedOnMessage(msgs),
|
|
377
378
|
estimateGas: simulateTx,
|
|
378
379
|
});
|
|
@@ -382,7 +383,7 @@ export class MsgBroadcaster {
|
|
|
382
383
|
signature,
|
|
383
384
|
message: web3Msgs,
|
|
384
385
|
txResponse: prepareTxResponse,
|
|
385
|
-
chainId:
|
|
386
|
+
chainId: ethereumChainId,
|
|
386
387
|
});
|
|
387
388
|
try {
|
|
388
389
|
walletStrategy.emit(WalletStrategyEmitterEventType.TransactionBroadcastStart);
|
|
@@ -509,7 +510,7 @@ export class MsgBroadcaster {
|
|
|
509
510
|
* @param tx the transaction that needs to be broadcasted
|
|
510
511
|
*/
|
|
511
512
|
async experimentalBroadcastWalletThroughLedger(tx) {
|
|
512
|
-
const { chainId, txTimeout, endpoints,
|
|
513
|
+
const { chainId, txTimeout, endpoints, simulateTx, walletStrategy, ethereumChainId, } = this;
|
|
513
514
|
const msgs = Array.isArray(tx.msgs) ? tx.msgs : [tx.msgs];
|
|
514
515
|
/**
|
|
515
516
|
* We can only use this method
|
|
@@ -522,8 +523,8 @@ export class MsgBroadcaster {
|
|
|
522
523
|
throw new GeneralException(new Error(`This method can only be used when Ledger is connected through ${walletStrategy.getWallet()}`));
|
|
523
524
|
}
|
|
524
525
|
}
|
|
525
|
-
if (!
|
|
526
|
-
throw new GeneralException(new Error('Please provide
|
|
526
|
+
if (!ethereumChainId) {
|
|
527
|
+
throw new GeneralException(new Error('Please provide ethereumChainId'));
|
|
527
528
|
}
|
|
528
529
|
const cosmosWallet = walletStrategy.getCosmosWallet(chainId);
|
|
529
530
|
const { baseAccount, latestHeight } = await this.fetchAccountAndBlockDetails(tx.injectiveAddress);
|
|
@@ -541,7 +542,7 @@ export class MsgBroadcaster {
|
|
|
541
542
|
sequence: baseAccount.sequence.toString(),
|
|
542
543
|
accountNumber: baseAccount.accountNumber.toString(),
|
|
543
544
|
},
|
|
544
|
-
|
|
545
|
+
ethereumChainId,
|
|
545
546
|
});
|
|
546
547
|
const aminoSignResponse = await cosmosWallet.signEIP712CosmosTx({
|
|
547
548
|
eip712: eip712TypedData,
|
|
@@ -572,7 +573,7 @@ export class MsgBroadcaster {
|
|
|
572
573
|
});
|
|
573
574
|
/** Preparing the transaction for client broadcasting */
|
|
574
575
|
const web3Extension = createWeb3Extension({
|
|
575
|
-
|
|
576
|
+
ethereumChainId,
|
|
576
577
|
});
|
|
577
578
|
const txRawEip712 = createTxRawEIP712(txRaw, web3Extension);
|
|
578
579
|
if (simulateTx) {
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
+
import { EthereumChainId } from '@injectivelabs/ts-types';
|
|
1
2
|
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
|
+
ethereumChainId?: EthereumChainId;
|
|
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 ethereumChainId;
|
|
23
|
+
constructor({ walletStrategy, ethereumChainId, }: {
|
|
24
24
|
walletStrategy: BaseWalletStrategy;
|
|
25
|
-
|
|
25
|
+
ethereumChainId: EthereumChainId;
|
|
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,
|
|
10
|
-
this.evmChainId = evmChainId;
|
|
8
|
+
ethereumChainId;
|
|
9
|
+
constructor({ walletStrategy, ethereumChainId, }) {
|
|
11
10
|
this.walletStrategy = walletStrategy;
|
|
11
|
+
this.ethereumChainId = ethereumChainId;
|
|
12
12
|
}
|
|
13
13
|
async sendTransaction(args) {
|
|
14
|
-
const {
|
|
14
|
+
const { walletStrategy, ethereumChainId } = this;
|
|
15
15
|
try {
|
|
16
|
-
const chainId = args.
|
|
16
|
+
const chainId = args.ethereumChainId || ethereumChainId;
|
|
17
17
|
const txHash = await walletStrategy.sendEvmTransaction(args.tx, {
|
|
18
|
-
evmChainId: chainId,
|
|
19
18
|
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, EthereumChainId } 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
|
+
ethereumChainId?: EthereumChainId;
|
|
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';
|
|
2
3
|
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, ethereumChainId?: EthereumChainId): 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;
|
|
33
32
|
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 { Wallet, isEvmWallet, isCosmosWallet, } from '@injectivelabs/wallet-base';
|
|
3
2
|
import { GeneralException, WalletException } from '@injectivelabs/exceptions';
|
|
3
|
+
import { Wallet, isEvmWallet, isCosmosWallet, } from '@injectivelabs/wallet-base';
|
|
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
|
+
throw new GeneralException(new Error('No strategies provided to BaseWalletStrategy'));
|
|
12
12
|
}
|
|
13
|
-
if (keys.includes(Wallet.Metamask) && args.
|
|
13
|
+
if (keys.includes(Wallet.Metamask) && args.ethereumOptions) {
|
|
14
14
|
return Wallet.Metamask;
|
|
15
15
|
}
|
|
16
|
-
if (keys.includes(Wallet.Keplr) && !args.
|
|
16
|
+
if (keys.includes(Wallet.Keplr) && !args.ethereumOptions) {
|
|
17
17
|
return Wallet.Keplr;
|
|
18
18
|
}
|
|
19
19
|
return keys[0];
|
|
@@ -43,10 +43,8 @@ export default class BaseWalletStrategy {
|
|
|
43
43
|
}
|
|
44
44
|
setWallet(wallet) {
|
|
45
45
|
this.wallet = wallet;
|
|
46
|
-
this.getStrategy();
|
|
47
46
|
}
|
|
48
47
|
setMetadata(metadata) {
|
|
49
|
-
console.log('Setting metadata', metadata);
|
|
50
48
|
this.metadata = metadata;
|
|
51
49
|
this.getStrategy().setMetadata?.(metadata);
|
|
52
50
|
}
|
|
@@ -75,8 +73,8 @@ export default class BaseWalletStrategy {
|
|
|
75
73
|
getEthereumChainId() {
|
|
76
74
|
return this.getStrategy().getEthereumChainId();
|
|
77
75
|
}
|
|
78
|
-
async getEvmTransactionReceipt(txHash,
|
|
79
|
-
return this.getStrategy().getEvmTransactionReceipt(txHash,
|
|
76
|
+
async getEvmTransactionReceipt(txHash, ethereumChainId) {
|
|
77
|
+
return this.getStrategy().getEvmTransactionReceipt(txHash, ethereumChainId);
|
|
80
78
|
}
|
|
81
79
|
async getSessionOrConfirm(address) {
|
|
82
80
|
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.2
|
|
4
|
+
"version": "1.16.2",
|
|
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": "yarn build:cjs && yarn build:esm && yarn 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 && yarn 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": "1.16.2
|
|
60
|
-
"@injectivelabs/networks": "1.16.2
|
|
61
|
-
"@injectivelabs/sdk-ts": "1.16.2
|
|
62
|
-
"@injectivelabs/ts-types": "1.16.2
|
|
63
|
-
"@injectivelabs/utils": "1.16.2
|
|
64
|
-
"@injectivelabs/wallet-base": "1.16.2
|
|
59
|
+
"@injectivelabs/exceptions": "^1.16.2",
|
|
60
|
+
"@injectivelabs/networks": "^1.16.2",
|
|
61
|
+
"@injectivelabs/sdk-ts": "^1.16.2",
|
|
62
|
+
"@injectivelabs/ts-types": "^1.16.2",
|
|
63
|
+
"@injectivelabs/utils": "^1.16.2",
|
|
64
|
+
"@injectivelabs/wallet-base": "^1.16.2",
|
|
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": "56e3f6c8f399c2d881a65858e8e0b1b39828a917"
|
|
72
72
|
}
|