@injectivelabs/wallet-core 1.16.7 → 1.16.8

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/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
- yarn add @injectivelabs/wallet-core
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, EthereumChainId } from '@injectivelabs/ts-types';
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
- ethereumChainId?: EthereumChainId;
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
- getEvmChainId(): Promise<EthereumChainId | undefined>;
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
- ethereumChainId;
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.ethereumChainId =
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;
@@ -68,19 +67,19 @@ class MsgBroadcaster {
68
67
  async getEvmChainId() {
69
68
  const { walletStrategy } = this;
70
69
  if (!(0, wallet_base_1.isEvmBrowserWallet)(walletStrategy.wallet)) {
71
- return this.ethereumChainId;
70
+ return this.evmChainId;
72
71
  }
73
- const mainnetEvmIds = [ts_types_1.EthereumChainId.Mainnet, ts_types_1.EthereumChainId.MainnetEvm];
74
- const testnetEvmIds = [ts_types_1.EthereumChainId.Sepolia, ts_types_1.EthereumChainId.TestnetEvm];
75
- const devnetEvmIds = [ts_types_1.EthereumChainId.Sepolia, ts_types_1.EthereumChainId.DevnetEvm];
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();
78
77
  if (!chainId) {
79
- return this.ethereumChainId;
78
+ return this.evmChainId;
80
79
  }
81
80
  const evmChainId = parseInt(chainId, 16);
82
81
  if (isNaN(evmChainId)) {
83
- return this.ethereumChainId;
82
+ return this.evmChainId;
84
83
  }
85
84
  if (((0, networks_1.isMainnet)(this.options.network) &&
86
85
  !mainnetEvmIds.includes(evmChainId)) ||
@@ -205,9 +204,9 @@ class MsgBroadcaster {
205
204
  async broadcastEip712(tx) {
206
205
  const { chainId, txTimeout, endpoints, walletStrategy } = this;
207
206
  const msgs = Array.isArray(tx.msgs) ? tx.msgs : [tx.msgs];
208
- const ethereumChainId = await this.getEvmChainId();
209
- if (!ethereumChainId) {
210
- throw new exceptions_1.GeneralException(new Error('Please provide ethereumChainId'));
207
+ const evmChainId = await this.getEvmChainId();
208
+ if (!evmChainId) {
209
+ throw new exceptions_1.GeneralException(new Error('Please provide evmChainId'));
211
210
  }
212
211
  /** Account Details * */
213
212
  const { baseAccount, latestHeight } = await this.fetchAccountAndBlockDetails(tx.injectiveAddress);
@@ -249,7 +248,7 @@ class MsgBroadcaster {
249
248
  timeoutHeight: timeoutHeight.toFixed(),
250
249
  chainId,
251
250
  },
252
- ethereumChainId,
251
+ evmChainId,
253
252
  });
254
253
  /** Signing on Ethereum */
255
254
  const signature = await walletStrategy.signEip712TypedData(JSON.stringify(eip712TypedData), tx.ethereumAddress);
@@ -271,7 +270,7 @@ class MsgBroadcaster {
271
270
  chainId,
272
271
  });
273
272
  const web3Extension = (0, sdk_ts_1.createWeb3Extension)({
274
- ethereumChainId,
273
+ evmChainId,
275
274
  });
276
275
  const txRawEip712 = (0, sdk_ts_1.createTxRawEIP712)(txRaw, web3Extension);
277
276
  /** Append Signatures */
@@ -297,9 +296,9 @@ class MsgBroadcaster {
297
296
  async broadcastEip712V2(tx) {
298
297
  const { chainId, endpoints, txTimeout, walletStrategy } = this;
299
298
  const msgs = Array.isArray(tx.msgs) ? tx.msgs : [tx.msgs];
300
- const ethereumChainId = await this.getEvmChainId();
301
- if (!ethereumChainId) {
302
- throw new exceptions_1.GeneralException(new Error('Please provide ethereumChainId'));
299
+ const evmChainId = await this.getEvmChainId();
300
+ if (!evmChainId) {
301
+ throw new exceptions_1.GeneralException(new Error('Please provide evmChainId'));
303
302
  }
304
303
  /** Account Details * */
305
304
  const { baseAccount, latestHeight } = await this.fetchAccountAndBlockDetails(tx.injectiveAddress);
@@ -342,7 +341,7 @@ class MsgBroadcaster {
342
341
  timeoutHeight: timeoutHeight.toFixed(),
343
342
  chainId,
344
343
  },
345
- ethereumChainId,
344
+ evmChainId,
346
345
  });
347
346
  walletStrategy.emit(types_js_1.WalletStrategyEmitterEventType.TransactionPreparationEnd);
348
347
  /** Signing on Ethereum */
@@ -365,7 +364,7 @@ class MsgBroadcaster {
365
364
  chainId,
366
365
  });
367
366
  const web3Extension = (0, sdk_ts_1.createWeb3Extension)({
368
- ethereumChainId,
367
+ evmChainId,
369
368
  });
370
369
  const txRawEip712 = (0, sdk_ts_1.createTxRawEIP712)(txRaw, web3Extension);
371
370
  /** Append Signatures */
@@ -390,9 +389,9 @@ class MsgBroadcaster {
390
389
  const { txTimeout, endpoints, simulateTx, httpHeaders, walletStrategy, txTimeoutOnFeeDelegation, } = this;
391
390
  const msgs = Array.isArray(tx.msgs) ? tx.msgs : [tx.msgs];
392
391
  const web3Msgs = msgs.map((msg) => msg.toWeb3());
393
- const ethereumChainId = await this.getEvmChainId();
394
- if (!ethereumChainId) {
395
- throw new exceptions_1.GeneralException(new Error('Please provide ethereumChainId'));
392
+ const evmChainId = await this.getEvmChainId();
393
+ if (!evmChainId) {
394
+ throw new exceptions_1.GeneralException(new Error('Please provide evmChainId'));
396
395
  }
397
396
  const transactionApi = new sdk_ts_1.IndexerGrpcWeb3GwApi(endpoints.web3gw || endpoints.indexer);
398
397
  if (httpHeaders) {
@@ -412,7 +411,7 @@ class MsgBroadcaster {
412
411
  memo: tx.memo,
413
412
  message: web3Msgs,
414
413
  address: tx.ethereumAddress,
415
- chainId: ethereumChainId,
414
+ chainId: evmChainId,
416
415
  gasLimit: (0, sdk_ts_1.getGasPriceBasedOnMessage)(msgs),
417
416
  estimateGas: simulateTx,
418
417
  });
@@ -422,7 +421,7 @@ class MsgBroadcaster {
422
421
  signature,
423
422
  message: web3Msgs,
424
423
  txResponse: prepareTxResponse,
425
- chainId: ethereumChainId,
424
+ chainId: evmChainId,
426
425
  });
427
426
  try {
428
427
  walletStrategy.emit(types_js_1.WalletStrategyEmitterEventType.TransactionBroadcastStart);
@@ -549,7 +548,7 @@ class MsgBroadcaster {
549
548
  * @param tx the transaction that needs to be broadcasted
550
549
  */
551
550
  async experimentalBroadcastWalletThroughLedger(tx) {
552
- const { chainId, txTimeout, endpoints, simulateTx, walletStrategy, ethereumChainId, } = this;
551
+ const { chainId, txTimeout, endpoints, evmChainId, simulateTx, walletStrategy, } = this;
553
552
  const msgs = Array.isArray(tx.msgs) ? tx.msgs : [tx.msgs];
554
553
  /**
555
554
  * We can only use this method
@@ -562,8 +561,8 @@ class MsgBroadcaster {
562
561
  throw new exceptions_1.GeneralException(new Error(`This method can only be used when Ledger is connected through ${walletStrategy.getWallet()}`));
563
562
  }
564
563
  }
565
- if (!ethereumChainId) {
566
- throw new exceptions_1.GeneralException(new Error('Please provide ethereumChainId'));
564
+ if (!evmChainId) {
565
+ throw new exceptions_1.GeneralException(new Error('Please provide evmChainId'));
567
566
  }
568
567
  const cosmosWallet = walletStrategy.getCosmosWallet(chainId);
569
568
  const { baseAccount, latestHeight } = await this.fetchAccountAndBlockDetails(tx.injectiveAddress);
@@ -581,7 +580,7 @@ class MsgBroadcaster {
581
580
  sequence: baseAccount.sequence.toString(),
582
581
  accountNumber: baseAccount.accountNumber.toString(),
583
582
  },
584
- ethereumChainId,
583
+ evmChainId,
585
584
  });
586
585
  const aminoSignResponse = await cosmosWallet.signEIP712CosmosTx({
587
586
  eip712: eip712TypedData,
@@ -612,7 +611,7 @@ class MsgBroadcaster {
612
611
  });
613
612
  /** Preparing the transaction for client broadcasting */
614
613
  const web3Extension = (0, sdk_ts_1.createWeb3Extension)({
615
- ethereumChainId,
614
+ evmChainId,
616
615
  });
617
616
  const txRawEip712 = (0, sdk_ts_1.createTxRawEIP712)(txRaw, web3Extension);
618
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
- ethereumChainId?: EthereumChainId;
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 ethereumChainId;
23
- constructor({ walletStrategy, ethereumChainId, }: {
22
+ private evmChainId;
23
+ constructor({ walletStrategy, evmChainId, }: {
24
24
  walletStrategy: BaseWalletStrategy;
25
- ethereumChainId: EthereumChainId;
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
- ethereumChainId;
12
- constructor({ walletStrategy, ethereumChainId, }) {
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 { walletStrategy, ethereumChainId } = this;
17
+ const { evmChainId, walletStrategy } = this;
18
18
  try {
19
- const chainId = args.ethereumChainId || ethereumChainId;
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, EthereumChainId } from '@injectivelabs/ts-types';
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
- ethereumChainId?: EthereumChainId;
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, ethereumChainId?: EthereumChainId): Promise<void>;
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
- throw new exceptions_1.GeneralException(new Error('No strategies provided to BaseWalletStrategy'));
13
+ return wallet_base_1.Wallet.Metamask;
14
14
  }
15
- if (keys.includes(wallet_base_1.Wallet.Metamask) && args.ethereumOptions) {
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.ethereumOptions) {
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, ethereumChainId) {
79
- return this.getStrategy().getEvmTransactionReceipt(txHash, ethereumChainId);
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, EthereumChainId } from '@injectivelabs/ts-types';
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
- ethereumChainId?: EthereumChainId;
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
- getEvmChainId(): Promise<EthereumChainId | undefined>;
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 { EthereumChainId } from '@injectivelabs/ts-types';
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
- ethereumChainId;
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.ethereumChainId =
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;
@@ -65,19 +64,19 @@ export class MsgBroadcaster {
65
64
  async getEvmChainId() {
66
65
  const { walletStrategy } = this;
67
66
  if (!isEvmBrowserWallet(walletStrategy.wallet)) {
68
- return this.ethereumChainId;
67
+ return this.evmChainId;
69
68
  }
70
- const mainnetEvmIds = [EthereumChainId.Mainnet, EthereumChainId.MainnetEvm];
71
- const testnetEvmIds = [EthereumChainId.Sepolia, EthereumChainId.TestnetEvm];
72
- const devnetEvmIds = [EthereumChainId.Sepolia, EthereumChainId.DevnetEvm];
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();
75
74
  if (!chainId) {
76
- return this.ethereumChainId;
75
+ return this.evmChainId;
77
76
  }
78
77
  const evmChainId = parseInt(chainId, 16);
79
78
  if (isNaN(evmChainId)) {
80
- return this.ethereumChainId;
79
+ return this.evmChainId;
81
80
  }
82
81
  if ((isMainnet(this.options.network) &&
83
82
  !mainnetEvmIds.includes(evmChainId)) ||
@@ -202,9 +201,9 @@ export class MsgBroadcaster {
202
201
  async broadcastEip712(tx) {
203
202
  const { chainId, txTimeout, endpoints, walletStrategy } = this;
204
203
  const msgs = Array.isArray(tx.msgs) ? tx.msgs : [tx.msgs];
205
- const ethereumChainId = await this.getEvmChainId();
206
- if (!ethereumChainId) {
207
- throw new GeneralException(new Error('Please provide ethereumChainId'));
204
+ const evmChainId = await this.getEvmChainId();
205
+ if (!evmChainId) {
206
+ throw new GeneralException(new Error('Please provide evmChainId'));
208
207
  }
209
208
  /** Account Details * */
210
209
  const { baseAccount, latestHeight } = await this.fetchAccountAndBlockDetails(tx.injectiveAddress);
@@ -246,7 +245,7 @@ export class MsgBroadcaster {
246
245
  timeoutHeight: timeoutHeight.toFixed(),
247
246
  chainId,
248
247
  },
249
- ethereumChainId,
248
+ evmChainId,
250
249
  });
251
250
  /** Signing on Ethereum */
252
251
  const signature = await walletStrategy.signEip712TypedData(JSON.stringify(eip712TypedData), tx.ethereumAddress);
@@ -268,7 +267,7 @@ export class MsgBroadcaster {
268
267
  chainId,
269
268
  });
270
269
  const web3Extension = createWeb3Extension({
271
- ethereumChainId,
270
+ evmChainId,
272
271
  });
273
272
  const txRawEip712 = createTxRawEIP712(txRaw, web3Extension);
274
273
  /** Append Signatures */
@@ -294,9 +293,9 @@ export class MsgBroadcaster {
294
293
  async broadcastEip712V2(tx) {
295
294
  const { chainId, endpoints, txTimeout, walletStrategy } = this;
296
295
  const msgs = Array.isArray(tx.msgs) ? tx.msgs : [tx.msgs];
297
- const ethereumChainId = await this.getEvmChainId();
298
- if (!ethereumChainId) {
299
- throw new GeneralException(new Error('Please provide ethereumChainId'));
296
+ const evmChainId = await this.getEvmChainId();
297
+ if (!evmChainId) {
298
+ throw new GeneralException(new Error('Please provide evmChainId'));
300
299
  }
301
300
  /** Account Details * */
302
301
  const { baseAccount, latestHeight } = await this.fetchAccountAndBlockDetails(tx.injectiveAddress);
@@ -339,7 +338,7 @@ export class MsgBroadcaster {
339
338
  timeoutHeight: timeoutHeight.toFixed(),
340
339
  chainId,
341
340
  },
342
- ethereumChainId,
341
+ evmChainId,
343
342
  });
344
343
  walletStrategy.emit(WalletStrategyEmitterEventType.TransactionPreparationEnd);
345
344
  /** Signing on Ethereum */
@@ -362,7 +361,7 @@ export class MsgBroadcaster {
362
361
  chainId,
363
362
  });
364
363
  const web3Extension = createWeb3Extension({
365
- ethereumChainId,
364
+ evmChainId,
366
365
  });
367
366
  const txRawEip712 = createTxRawEIP712(txRaw, web3Extension);
368
367
  /** Append Signatures */
@@ -387,9 +386,9 @@ export class MsgBroadcaster {
387
386
  const { txTimeout, endpoints, simulateTx, httpHeaders, walletStrategy, txTimeoutOnFeeDelegation, } = this;
388
387
  const msgs = Array.isArray(tx.msgs) ? tx.msgs : [tx.msgs];
389
388
  const web3Msgs = msgs.map((msg) => msg.toWeb3());
390
- const ethereumChainId = await this.getEvmChainId();
391
- if (!ethereumChainId) {
392
- throw new GeneralException(new Error('Please provide ethereumChainId'));
389
+ const evmChainId = await this.getEvmChainId();
390
+ if (!evmChainId) {
391
+ throw new GeneralException(new Error('Please provide evmChainId'));
393
392
  }
394
393
  const transactionApi = new IndexerGrpcWeb3GwApi(endpoints.web3gw || endpoints.indexer);
395
394
  if (httpHeaders) {
@@ -409,7 +408,7 @@ export class MsgBroadcaster {
409
408
  memo: tx.memo,
410
409
  message: web3Msgs,
411
410
  address: tx.ethereumAddress,
412
- chainId: ethereumChainId,
411
+ chainId: evmChainId,
413
412
  gasLimit: getGasPriceBasedOnMessage(msgs),
414
413
  estimateGas: simulateTx,
415
414
  });
@@ -419,7 +418,7 @@ export class MsgBroadcaster {
419
418
  signature,
420
419
  message: web3Msgs,
421
420
  txResponse: prepareTxResponse,
422
- chainId: ethereumChainId,
421
+ chainId: evmChainId,
423
422
  });
424
423
  try {
425
424
  walletStrategy.emit(WalletStrategyEmitterEventType.TransactionBroadcastStart);
@@ -546,7 +545,7 @@ export class MsgBroadcaster {
546
545
  * @param tx the transaction that needs to be broadcasted
547
546
  */
548
547
  async experimentalBroadcastWalletThroughLedger(tx) {
549
- const { chainId, txTimeout, endpoints, simulateTx, walletStrategy, ethereumChainId, } = this;
548
+ const { chainId, txTimeout, endpoints, evmChainId, simulateTx, walletStrategy, } = this;
550
549
  const msgs = Array.isArray(tx.msgs) ? tx.msgs : [tx.msgs];
551
550
  /**
552
551
  * We can only use this method
@@ -559,8 +558,8 @@ export class MsgBroadcaster {
559
558
  throw new GeneralException(new Error(`This method can only be used when Ledger is connected through ${walletStrategy.getWallet()}`));
560
559
  }
561
560
  }
562
- if (!ethereumChainId) {
563
- throw new GeneralException(new Error('Please provide ethereumChainId'));
561
+ if (!evmChainId) {
562
+ throw new GeneralException(new Error('Please provide evmChainId'));
564
563
  }
565
564
  const cosmosWallet = walletStrategy.getCosmosWallet(chainId);
566
565
  const { baseAccount, latestHeight } = await this.fetchAccountAndBlockDetails(tx.injectiveAddress);
@@ -578,7 +577,7 @@ export class MsgBroadcaster {
578
577
  sequence: baseAccount.sequence.toString(),
579
578
  accountNumber: baseAccount.accountNumber.toString(),
580
579
  },
581
- ethereumChainId,
580
+ evmChainId,
582
581
  });
583
582
  const aminoSignResponse = await cosmosWallet.signEIP712CosmosTx({
584
583
  eip712: eip712TypedData,
@@ -609,7 +608,7 @@ export class MsgBroadcaster {
609
608
  });
610
609
  /** Preparing the transaction for client broadcasting */
611
610
  const web3Extension = createWeb3Extension({
612
- ethereumChainId,
611
+ evmChainId,
613
612
  });
614
613
  const txRawEip712 = createTxRawEIP712(txRaw, web3Extension);
615
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
- ethereumChainId?: EthereumChainId;
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 ethereumChainId;
23
- constructor({ walletStrategy, ethereumChainId, }: {
22
+ private evmChainId;
23
+ constructor({ walletStrategy, evmChainId, }: {
24
24
  walletStrategy: BaseWalletStrategy;
25
- ethereumChainId: EthereumChainId;
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
- ethereumChainId;
9
- constructor({ walletStrategy, ethereumChainId, }) {
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 { walletStrategy, ethereumChainId } = this;
14
+ const { evmChainId, walletStrategy } = this;
15
15
  try {
16
- const chainId = args.ethereumChainId || ethereumChainId;
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, EthereumChainId } from '@injectivelabs/ts-types';
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
- ethereumChainId?: EthereumChainId;
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, ethereumChainId?: EthereumChainId): Promise<void>;
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
- throw new GeneralException(new Error('No strategies provided to BaseWalletStrategy'));
11
+ return Wallet.Metamask;
12
12
  }
13
- if (keys.includes(Wallet.Metamask) && args.ethereumOptions) {
13
+ if (keys.includes(Wallet.Metamask) && args.evmOptions) {
14
14
  return Wallet.Metamask;
15
15
  }
16
- if (keys.includes(Wallet.Keplr) && !args.ethereumOptions) {
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, ethereumChainId) {
77
- return this.getStrategy().getEvmTransactionReceipt(txHash, ethereumChainId);
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.7",
4
+ "version": "1.16.8",
5
5
  "sideEffects": false,
6
6
  "type": "module",
7
7
  "author": {
@@ -41,10 +41,10 @@
41
41
  }
42
42
  },
43
43
  "scripts": {
44
- "build": "yarn build:cjs && yarn build:esm && yarn build:post",
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 && yarn build:post",
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": "^1.16.7",
60
- "@injectivelabs/networks": "^1.16.7",
61
- "@injectivelabs/sdk-ts": "^1.16.7",
62
- "@injectivelabs/ts-types": "^1.16.7",
63
- "@injectivelabs/utils": "^1.16.7",
64
- "@injectivelabs/wallet-base": "^1.16.7",
59
+ "@injectivelabs/exceptions": "1.16.6",
60
+ "@injectivelabs/networks": "1.16.8",
61
+ "@injectivelabs/sdk-ts": "1.16.8",
62
+ "@injectivelabs/ts-types": "1.16.8",
63
+ "@injectivelabs/utils": "1.16.8",
64
+ "@injectivelabs/wallet-base": "1.16.8",
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": "78f656ef404ef511dfe6e4cc9defcae0a7cbec76"
71
+ "gitHead": "8bdbbfff8a07053ec2cd91a7103bfe99975672b4"
72
72
  }