@injectivelabs/wallet-core 1.20.51 → 1.20.53

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.
@@ -42,6 +42,7 @@ var MsgBroadcaster = class {
42
42
  require_defineProperty._defineProperty(this, "txTimeout", __injectivelabs_utils.DEFAULT_BLOCK_TIMEOUT_HEIGHT);
43
43
  require_defineProperty._defineProperty(this, "simulateTx", true);
44
44
  require_defineProperty._defineProperty(this, "useDynamicBaseFee", false);
45
+ require_defineProperty._defineProperty(this, "useFixedGas", false);
45
46
  require_defineProperty._defineProperty(this, "txTimeoutOnFeeDelegation", false);
46
47
  require_defineProperty._defineProperty(this, "evmChainId", void 0);
47
48
  require_defineProperty._defineProperty(this, "gasBufferCoefficient", 1.2);
@@ -52,6 +53,7 @@ var MsgBroadcaster = class {
52
53
  this.options = options;
53
54
  this.simulateTx = options.simulateTx !== void 0 ? options.simulateTx : true;
54
55
  this.useDynamicBaseFee = options.useDynamicBaseFee !== void 0 ? options.useDynamicBaseFee : false;
56
+ this.useFixedGas = options.useFixedGas !== void 0 ? options.useFixedGas : false;
55
57
  this.txTimeout = options.txTimeout || __injectivelabs_utils.DEFAULT_BLOCK_TIMEOUT_HEIGHT;
56
58
  this.txTimeoutOnFeeDelegation = options.txTimeoutOnFeeDelegation !== void 0 ? options.txTimeoutOnFeeDelegation : true;
57
59
  this.gasBufferCoefficient = options.gasBufferCoefficient || 1.2;
@@ -65,10 +67,19 @@ var MsgBroadcaster = class {
65
67
  setOptions(options) {
66
68
  this.simulateTx = options.simulateTx !== void 0 ? options.simulateTx : this.simulateTx;
67
69
  this.useDynamicBaseFee = options.useDynamicBaseFee !== void 0 ? options.useDynamicBaseFee : this.useDynamicBaseFee;
70
+ this.useFixedGas = options.useFixedGas !== void 0 ? options.useFixedGas : this.useFixedGas;
68
71
  this.txTimeout = options.txTimeout !== void 0 ? options.txTimeout : this.txTimeout;
69
72
  this.txTimeoutOnFeeDelegation = options.txTimeoutOnFeeDelegation !== void 0 ? options.txTimeoutOnFeeDelegation : this.txTimeoutOnFeeDelegation;
70
73
  this.txInclusion = options.txInclusion !== void 0 ? options.txInclusion : this.txInclusion;
71
74
  }
75
+ resolveGasOptions(msgs, gas) {
76
+ return (0, __injectivelabs_sdk_ts_utils.getGasOptionsBasedOnMessage)({
77
+ msgs,
78
+ gas,
79
+ simulateTx: this.simulateTx,
80
+ useFixedGas: this.useFixedGas
81
+ });
82
+ }
72
83
  async getEvmChainId() {
73
84
  const { walletStrategy } = this;
74
85
  if (!(0, __injectivelabs_wallet_base.isEvmBrowserWallet)(walletStrategy.wallet)) return this.evmChainId;
@@ -251,7 +262,7 @@ var MsgBroadcaster = class {
251
262
  });
252
263
  const txTimeoutTimeInSeconds = txTimeoutInBlocks * __injectivelabs_utils.DEFAULT_BLOCK_TIME_IN_SECONDS;
253
264
  const txTimeoutTimeInMilliSeconds = txTimeoutTimeInSeconds * 1e3;
254
- const gas = (((_tx$gas = tx.gas) === null || _tx$gas === void 0 ? void 0 : _tx$gas.gas) || (0, __injectivelabs_sdk_ts_utils.getGasPriceBasedOnMessage)(msgs)).toString();
265
+ const { gas, estimateGas } = this.resolveGasOptions(msgs, (_tx$gas = tx.gas) === null || _tx$gas === void 0 ? void 0 : _tx$gas.gas);
255
266
  let stdFee = (0, __injectivelabs_utils.getStdFee)({
256
267
  ...tx.gas,
257
268
  gas
@@ -275,7 +286,7 @@ var MsgBroadcaster = class {
275
286
  sequence: baseAccount.sequence
276
287
  },
277
288
  fee: stdFee
278
- });
289
+ }, estimateGas);
279
290
  stdFee = simulatedStdFee;
280
291
  }
281
292
  /** EIP712 for signing on Ethereum wallets */
@@ -371,7 +382,7 @@ var MsgBroadcaster = class {
371
382
  });
372
383
  const txTimeoutTimeInSeconds = txTimeoutInBlocks * __injectivelabs_utils.DEFAULT_BLOCK_TIME_IN_SECONDS;
373
384
  const txTimeoutTimeInMilliSeconds = txTimeoutTimeInSeconds * 1e3;
374
- const gas = (((_tx$gas2 = tx.gas) === null || _tx$gas2 === void 0 ? void 0 : _tx$gas2.gas) || (0, __injectivelabs_sdk_ts_utils.getGasPriceBasedOnMessage)(msgs)).toString();
385
+ const { gas, estimateGas } = this.resolveGasOptions(msgs, (_tx$gas2 = tx.gas) === null || _tx$gas2 === void 0 ? void 0 : _tx$gas2.gas);
375
386
  let stdFee = (0, __injectivelabs_utils.getStdFee)({
376
387
  ...tx.gas,
377
388
  gas
@@ -395,7 +406,7 @@ var MsgBroadcaster = class {
395
406
  accountNumber: baseAccount.accountNumber
396
407
  },
397
408
  fee: stdFee
398
- });
409
+ }, estimateGas);
399
410
  stdFee = simulatedStdFee;
400
411
  }
401
412
  walletStrategy.emit(__injectivelabs_wallet_base.WalletStrategyEmitterEventType.TransactionPreparationStart);
@@ -473,7 +484,8 @@ var MsgBroadcaster = class {
473
484
  * @returns transaction hash
474
485
  */
475
486
  async broadcastEip712WithFeeDelegation(tx) {
476
- const { endpoints, simulateTx, httpHeaders, walletStrategy, txTimeoutOnFeeDelegation } = this;
487
+ var _tx$gas3;
488
+ const { endpoints, httpHeaders, walletStrategy, txTimeoutOnFeeDelegation } = this;
477
489
  const txTimeoutInBlocks = this.resolveTimeoutInBlocks(tx.txTimeoutInBlocks);
478
490
  const msgs = Array.isArray(tx.msgs) ? tx.msgs : [tx.msgs];
479
491
  const web3Msgs = msgs.map((msg) => msg.toWeb3());
@@ -497,14 +509,15 @@ var MsgBroadcaster = class {
497
509
  });
498
510
  }
499
511
  walletStrategy.emit(__injectivelabs_wallet_base.WalletStrategyEmitterEventType.TransactionPreparationStart);
512
+ const { gasLimit, estimateGas } = this.resolveGasOptions(msgs, this.useFixedGas ? (_tx$gas3 = tx.gas) === null || _tx$gas3 === void 0 ? void 0 : _tx$gas3.gas : void 0);
500
513
  const prepareTxResponse = await transactionApi.prepareTxRequest({
501
514
  timeoutHeight: timeoutHeight === null || timeoutHeight === void 0 ? void 0 : timeoutHeight.toNumber(),
502
515
  memo: tx.memo,
503
516
  message: web3Msgs,
504
517
  address: tx.ethereumAddress,
505
518
  chainId: evmChainId,
506
- gasLimit: (0, __injectivelabs_sdk_ts_utils.getGasPriceBasedOnMessage)(msgs),
507
- estimateGas: simulateTx
519
+ gasLimit,
520
+ estimateGas
508
521
  });
509
522
  walletStrategy.emit(__injectivelabs_wallet_base.WalletStrategyEmitterEventType.TransactionPreparationEnd);
510
523
  const signature = await walletStrategy.signEip712TypedData(prepareTxResponse.data, tx.ethereumAddress, { txTimeout: txTimeoutTimeInSeconds });
@@ -553,7 +566,7 @@ var MsgBroadcaster = class {
553
566
  * @returns transaction hash
554
567
  */
555
568
  async broadcastDirectSign(tx) {
556
- var _tx$gas3;
569
+ var _tx$gas4;
557
570
  const { chainId, endpoints, walletStrategy } = this;
558
571
  const txTimeoutInBlocks = this.resolveTimeoutInBlocks(tx.txTimeoutInBlocks);
559
572
  const msgs = Array.isArray(tx.msgs) ? tx.msgs : [tx.msgs];
@@ -577,7 +590,7 @@ var MsgBroadcaster = class {
577
590
  });
578
591
  const txTimeoutTimeInMilliSeconds = txTimeoutInBlocks * __injectivelabs_utils.DEFAULT_BLOCK_TIME_IN_SECONDS * 1e3;
579
592
  const signMode = (0, __injectivelabs_wallet_base.isCosmosAminoOnlyWallet)(walletStrategy.wallet) ? __injectivelabs_sdk_ts_core_tx.SIGN_EIP712 : __injectivelabs_sdk_ts_core_tx.SIGN_DIRECT;
580
- const gas = (((_tx$gas3 = tx.gas) === null || _tx$gas3 === void 0 ? void 0 : _tx$gas3.gas) || (0, __injectivelabs_sdk_ts_utils.getGasPriceBasedOnMessage)(msgs)).toString();
593
+ const { gas, estimateGas } = this.resolveGasOptions(msgs, (_tx$gas4 = tx.gas) === null || _tx$gas4 === void 0 ? void 0 : _tx$gas4.gas);
581
594
  walletStrategy.emit(__injectivelabs_wallet_base.WalletStrategyEmitterEventType.TransactionPreparationStart);
582
595
  /** Prepare the Transaction * */
583
596
  const { txRaw } = await this.getTxWithSignersAndStdFee({
@@ -595,17 +608,17 @@ var MsgBroadcaster = class {
595
608
  ...tx.gas,
596
609
  gas
597
610
  })
598
- });
611
+ }, estimateGas);
599
612
  walletStrategy.emit(__injectivelabs_wallet_base.WalletStrategyEmitterEventType.TransactionPreparationEnd);
600
613
  /** Ledger using Cosmos app only allows signing amino docs */
601
614
  if ((0, __injectivelabs_wallet_base.isCosmosAminoOnlyWallet)(walletStrategy.wallet)) {
602
- var _tx$gas4;
615
+ var _tx$gas5;
603
616
  const aminoSignDoc = (0, __injectivelabs_sdk_ts_core_tx.getAminoStdSignDoc)({
604
617
  ...tx,
605
618
  ...baseAccount,
606
619
  msgs,
607
620
  chainId,
608
- gas: gas || ((_tx$gas4 = tx.gas) === null || _tx$gas4 === void 0 || (_tx$gas4 = _tx$gas4.gas) === null || _tx$gas4 === void 0 ? void 0 : _tx$gas4.toString()),
621
+ gas: gas || ((_tx$gas5 = tx.gas) === null || _tx$gas5 === void 0 || (_tx$gas5 = _tx$gas5.gas) === null || _tx$gas5 === void 0 ? void 0 : _tx$gas5.toString()),
609
622
  timeoutHeight: timeoutHeight.toFixed()
610
623
  });
611
624
  txRaw.signatures = [(0, __injectivelabs_sdk_ts_utils.base64ToUint8Array)((await walletStrategy.signAminoCosmosTransaction({
@@ -687,8 +700,8 @@ var MsgBroadcaster = class {
687
700
  * @param tx the transaction that needs to be broadcasted
688
701
  */
689
702
  async experimentalBroadcastWalletThroughLedger(tx) {
690
- var _tx$gas5, _tx$gas6;
691
- const { chainId, endpoints, evmChainId, simulateTx, walletStrategy } = this;
703
+ var _tx$gas6, _tx$gas7;
704
+ const { chainId, endpoints, evmChainId, walletStrategy } = this;
692
705
  const txTimeoutInBlocks = this.resolveTimeoutInBlocks(tx.txTimeoutInBlocks);
693
706
  const msgs = Array.isArray(tx.msgs) ? tx.msgs : [tx.msgs];
694
707
  /**
@@ -711,7 +724,7 @@ var MsgBroadcaster = class {
711
724
  latestHeight,
712
725
  txTimeoutInBlocks
713
726
  });
714
- const gas = (((_tx$gas5 = tx.gas) === null || _tx$gas5 === void 0 ? void 0 : _tx$gas5.gas) || (0, __injectivelabs_sdk_ts_utils.getGasPriceBasedOnMessage)(msgs)).toString();
727
+ const { gas, estimateGas } = this.resolveGasOptions(msgs, (_tx$gas6 = tx.gas) === null || _tx$gas6 === void 0 ? void 0 : _tx$gas6.gas);
715
728
  /** EIP712 for signing on Ethereum wallets */
716
729
  const eip712TypedData = (0, __injectivelabs_sdk_ts_core_tx.getEip712TypedData)({
717
730
  msgs,
@@ -735,7 +748,7 @@ var MsgBroadcaster = class {
735
748
  ...baseAccount,
736
749
  msgs,
737
750
  chainId,
738
- gas: gas || ((_tx$gas6 = tx.gas) === null || _tx$gas6 === void 0 || (_tx$gas6 = _tx$gas6.gas) === null || _tx$gas6 === void 0 ? void 0 : _tx$gas6.toString()),
751
+ gas: gas || ((_tx$gas7 = tx.gas) === null || _tx$gas7 === void 0 || (_tx$gas7 = _tx$gas7.gas) === null || _tx$gas7 === void 0 ? void 0 : _tx$gas7.toString()),
739
752
  timeoutHeight: timeoutHeight.toFixed()
740
753
  })
741
754
  });
@@ -756,7 +769,7 @@ var MsgBroadcaster = class {
756
769
  timeoutHeight: parseInt(aminoSignResponse.signed.timeout_height, 10)
757
770
  });
758
771
  const txRawEip712 = (0, __injectivelabs_sdk_ts_core_tx.createTxRawEIP712)(txRaw, (0, __injectivelabs_sdk_ts_core_tx.createWeb3Extension)({ evmChainId }));
759
- if (simulateTx) await this.simulateTxRaw(txRawEip712);
772
+ if (estimateGas) await this.simulateTxRaw(txRawEip712);
760
773
  txRawEip712.signatures = [(0, __injectivelabs_sdk_ts_utils.base64ToUint8Array)(aminoSignResponse.signature.signature)];
761
774
  /** Broadcast the transaction */
762
775
  const response = await new __injectivelabs_sdk_ts_core_tx.TxGrpcApi(endpoints.grpc).broadcast(txRawEip712, {
@@ -782,8 +795,8 @@ var MsgBroadcaster = class {
782
795
  * @returns transaction hashR
783
796
  */
784
797
  async broadcastDirectSignWithFeeDelegation(tx) {
785
- var _tx$gas7;
786
- const { options, chainId, endpoints, simulateTx, httpHeaders, walletStrategy, txTimeoutOnFeeDelegation } = this;
798
+ var _tx$gas9;
799
+ const { options, chainId, endpoints, httpHeaders, walletStrategy, txTimeoutOnFeeDelegation } = this;
787
800
  const txTimeoutInBlocks = this.resolveTimeoutInBlocks(tx.txTimeoutInBlocks);
788
801
  const msgs = Array.isArray(tx.msgs) ? tx.msgs : [tx.msgs];
789
802
  /**
@@ -814,11 +827,14 @@ var MsgBroadcaster = class {
814
827
  } catch (e) {
815
828
  const error = e;
816
829
  if ((0, __injectivelabs_exceptions.isThrownException)(error) && error.message.toLowerCase().includes(`account ${tx.injectiveAddress} not found`)) {
830
+ var _tx$gas8, _fixedGasOptions$esti;
831
+ const fixedGasOptions = this.useFixedGas ? this.resolveGasOptions(msgs, (_tx$gas8 = tx.gas) === null || _tx$gas8 === void 0 ? void 0 : _tx$gas8.gas) : void 0;
817
832
  await transactionApi.prepareCosmosTxRequest({
818
833
  address: tx.injectiveAddress,
819
834
  message: msgs.map((msg) => msg.toWeb3Gw()),
820
835
  memo: tx.memo,
821
- estimateGas: simulateTx
836
+ ...fixedGasOptions && { gasLimit: fixedGasOptions.gasLimit },
837
+ estimateGas: (_fixedGasOptions$esti = fixedGasOptions === null || fixedGasOptions === void 0 ? void 0 : fixedGasOptions.estimateGas) !== null && _fixedGasOptions$esti !== void 0 ? _fixedGasOptions$esti : this.simulateTx
822
838
  });
823
839
  const { baseAccount: baseAccount$1, latestHeight: latestHeight$1 } = await this.fetchAccountAndBlockDetails({
824
840
  latestHeight: tx.latestHeight,
@@ -848,7 +864,7 @@ var MsgBroadcaster = class {
848
864
  txTimeoutInBlocks: txTimeoutOnFeeDelegation ? txTimeoutInBlocks : __injectivelabs_utils.DEFAULT_BLOCK_TIMEOUT_HEIGHT
849
865
  });
850
866
  const txTimeoutTimeInMilliSeconds = txTimeoutInBlocks * __injectivelabs_utils.DEFAULT_BLOCK_TIME_IN_SECONDS * 1e3;
851
- const gas = (((_tx$gas7 = tx.gas) === null || _tx$gas7 === void 0 ? void 0 : _tx$gas7.gas) || (0, __injectivelabs_sdk_ts_utils.getGasPriceBasedOnMessage)(msgs)).toString();
867
+ const { gas, estimateGas } = this.resolveGasOptions(msgs, (_tx$gas9 = tx.gas) === null || _tx$gas9 === void 0 ? void 0 : _tx$gas9.gas);
852
868
  /** Prepare the Transaction * */
853
869
  const { txRaw } = await this.getTxWithSignersAndStdFee({
854
870
  chainId,
@@ -869,7 +885,7 @@ var MsgBroadcaster = class {
869
885
  gas,
870
886
  payer: feePayer
871
887
  })
872
- });
888
+ }, estimateGas);
873
889
  if (cosmosWallet === null || cosmosWallet === void 0 ? void 0 : cosmosWallet.disableGasCheck) cosmosWallet.disableGasCheck(chainId);
874
890
  walletStrategy.emit(__injectivelabs_wallet_base.WalletStrategyEmitterEventType.TransactionPreparationStart);
875
891
  const directSignResponse = await walletStrategy.signCosmosTransaction({
@@ -964,13 +980,18 @@ var MsgBroadcaster = class {
964
980
  * gas limit based on the simulation and add a small multiplier
965
981
  * to be safe (factor of 1.2 as default)
966
982
  */
967
- async getTxWithSignersAndStdFee(args) {
983
+ async getTxWithSignersAndStdFee(args, estimateGas = this.simulateTx) {
968
984
  var _result$gasInfo;
969
- const { simulateTx } = this;
970
- if (!simulateTx) return {
971
- ...(0, __injectivelabs_sdk_ts_core_tx.createTransactionWithSigners)(args),
972
- stdFee: await this.getStdFeeWithDynamicBaseFee(args.fee)
973
- };
985
+ if (!estimateGas) {
986
+ const stdFee = await this.getStdFeeWithDynamicBaseFee(args.fee);
987
+ return {
988
+ ...(0, __injectivelabs_sdk_ts_core_tx.createTransactionWithSigners)({
989
+ ...args,
990
+ fee: this.useFixedGas ? stdFee : args.fee
991
+ }),
992
+ stdFee
993
+ };
994
+ }
974
995
  const result = await this.simulateTxWithSigners(args);
975
996
  if (!((_result$gasInfo = result.gasInfo) === null || _result$gasInfo === void 0 ? void 0 : _result$gasInfo.gasUsed)) return {
976
997
  ...(0, __injectivelabs_sdk_ts_core_tx.createTransactionWithSigners)(args),
@@ -1,4 +1,4 @@
1
- const require_broadcaster = require('./broadcaster-DTwN2Hve.cjs');
1
+ const require_broadcaster = require('./broadcaster-B2w12U0i.cjs');
2
2
  require('./defineProperty-CImP5zIM.cjs');
3
3
 
4
4
  exports.MsgBroadcaster = require_broadcaster.MsgBroadcaster;
@@ -1,3 +1,3 @@
1
1
  import "./BaseWalletStrategy-CD9sBzZB.cjs";
2
- import { a as MsgBroadcasterTxOptionsWithAddresses, i as MsgBroadcasterTxOptions, n as MsgBroadcaster, r as MsgBroadcasterOptions, t as Web3Broadcaster } from "./index-DIurlb8S.cjs";
2
+ import { a as MsgBroadcasterTxOptionsWithAddresses, i as MsgBroadcasterTxOptions, n as MsgBroadcaster, r as MsgBroadcasterOptions, t as Web3Broadcaster } from "./index-CHR5Ye7m.cjs";
3
3
  export { MsgBroadcaster, MsgBroadcasterOptions, MsgBroadcasterTxOptions, MsgBroadcasterTxOptionsWithAddresses, Web3Broadcaster };
@@ -38,6 +38,7 @@ interface MsgBroadcasterOptions {
38
38
  txInclusion?: TxClientInclusionOptions;
39
39
  walletStrategy: BaseWalletStrategy;
40
40
  useDynamicBaseFee?: boolean;
41
+ useFixedGas?: boolean;
41
42
  txTimeoutOnFeeDelegation?: boolean;
42
43
  gasBufferCoefficient?: number;
43
44
  httpHeaders?: Record<string, string>;
@@ -59,6 +60,7 @@ declare class MsgBroadcaster {
59
60
  txTimeout: number;
60
61
  simulateTx: boolean;
61
62
  useDynamicBaseFee: boolean;
63
+ useFixedGas: boolean;
62
64
  txTimeoutOnFeeDelegation: boolean;
63
65
  evmChainId?: EvmChainId;
64
66
  gasBufferCoefficient: number;
@@ -73,6 +75,7 @@ declare class MsgBroadcaster {
73
75
  txInclusion?: TxClientInclusionOptions;
74
76
  constructor(options: MsgBroadcasterOptions);
75
77
  setOptions(options: Partial<MsgBroadcasterOptions>): void;
78
+ private resolveGasOptions;
76
79
  getEvmChainId(): Promise<EvmChainId | undefined>;
77
80
  /**
78
81
  * Broadcasting the transaction using the client
@@ -1,4 +1,4 @@
1
- const require_broadcaster = require('./broadcaster-DTwN2Hve.cjs');
1
+ const require_broadcaster = require('./broadcaster-B2w12U0i.cjs');
2
2
  require('./defineProperty-CImP5zIM.cjs');
3
3
  const require_strategy = require('./strategy-BxKznCI0.cjs');
4
4
 
@@ -1,5 +1,5 @@
1
1
  import { t as BaseWalletStrategy } from "./BaseWalletStrategy-CD9sBzZB.cjs";
2
- import { a as MsgBroadcasterTxOptionsWithAddresses, i as MsgBroadcasterTxOptions, n as MsgBroadcaster, r as MsgBroadcasterOptions, t as Web3Broadcaster } from "./index-DIurlb8S.cjs";
2
+ import { a as MsgBroadcasterTxOptionsWithAddresses, i as MsgBroadcasterTxOptions, n as MsgBroadcaster, r as MsgBroadcasterOptions, t as Web3Broadcaster } from "./index-CHR5Ye7m.cjs";
3
3
  import "./index-DLoAMD9J.cjs";
4
4
 
5
5
  //#region src/utils/tx.d.ts
@@ -2,7 +2,7 @@ import { t as _defineProperty } from "./defineProperty-D4YE9KXX.js";
2
2
  import { ChainCosmosErrorCode, GeneralException, TransactionChainErrorModule, TransactionException, UnspecifiedErrorCode, WalletException, Web3Exception, isThrownException } from "@injectivelabs/exceptions";
3
3
  import { EvmChainId } from "@injectivelabs/ts-types";
4
4
  import { PrivateKey, PublicKey } from "@injectivelabs/sdk-ts/core/accounts";
5
- import { base64ToUint8Array, getGasPriceBasedOnMessage, hexToBase64, hexToBuff, hexToUint8Array, ofacList, recoverTypedSignaturePubKey, safeBigIntStringify, uint8ArrayToBase64 } from "@injectivelabs/sdk-ts/utils";
5
+ import { base64ToUint8Array, getGasOptionsBasedOnMessage, hexToBase64, hexToBuff, hexToUint8Array, ofacList, recoverTypedSignaturePubKey, safeBigIntStringify, uint8ArrayToBase64 } from "@injectivelabs/sdk-ts/utils";
6
6
  import { IndexerGrpcWeb3GwApi } from "@injectivelabs/sdk-ts/client/indexer";
7
7
  import { getNetworkEndpoints, getNetworkInfo, isMainnet, isTestnet } from "@injectivelabs/networks";
8
8
  import { ChainGrpcAuthApi, ChainGrpcTendermintApi, ChainGrpcTxFeesApi } from "@injectivelabs/sdk-ts/client/chain";
@@ -42,6 +42,7 @@ var MsgBroadcaster = class {
42
42
  _defineProperty(this, "txTimeout", DEFAULT_BLOCK_TIMEOUT_HEIGHT);
43
43
  _defineProperty(this, "simulateTx", true);
44
44
  _defineProperty(this, "useDynamicBaseFee", false);
45
+ _defineProperty(this, "useFixedGas", false);
45
46
  _defineProperty(this, "txTimeoutOnFeeDelegation", false);
46
47
  _defineProperty(this, "evmChainId", void 0);
47
48
  _defineProperty(this, "gasBufferCoefficient", 1.2);
@@ -52,6 +53,7 @@ var MsgBroadcaster = class {
52
53
  this.options = options;
53
54
  this.simulateTx = options.simulateTx !== void 0 ? options.simulateTx : true;
54
55
  this.useDynamicBaseFee = options.useDynamicBaseFee !== void 0 ? options.useDynamicBaseFee : false;
56
+ this.useFixedGas = options.useFixedGas !== void 0 ? options.useFixedGas : false;
55
57
  this.txTimeout = options.txTimeout || DEFAULT_BLOCK_TIMEOUT_HEIGHT;
56
58
  this.txTimeoutOnFeeDelegation = options.txTimeoutOnFeeDelegation !== void 0 ? options.txTimeoutOnFeeDelegation : true;
57
59
  this.gasBufferCoefficient = options.gasBufferCoefficient || 1.2;
@@ -65,10 +67,19 @@ var MsgBroadcaster = class {
65
67
  setOptions(options) {
66
68
  this.simulateTx = options.simulateTx !== void 0 ? options.simulateTx : this.simulateTx;
67
69
  this.useDynamicBaseFee = options.useDynamicBaseFee !== void 0 ? options.useDynamicBaseFee : this.useDynamicBaseFee;
70
+ this.useFixedGas = options.useFixedGas !== void 0 ? options.useFixedGas : this.useFixedGas;
68
71
  this.txTimeout = options.txTimeout !== void 0 ? options.txTimeout : this.txTimeout;
69
72
  this.txTimeoutOnFeeDelegation = options.txTimeoutOnFeeDelegation !== void 0 ? options.txTimeoutOnFeeDelegation : this.txTimeoutOnFeeDelegation;
70
73
  this.txInclusion = options.txInclusion !== void 0 ? options.txInclusion : this.txInclusion;
71
74
  }
75
+ resolveGasOptions(msgs, gas) {
76
+ return getGasOptionsBasedOnMessage({
77
+ msgs,
78
+ gas,
79
+ simulateTx: this.simulateTx,
80
+ useFixedGas: this.useFixedGas
81
+ });
82
+ }
72
83
  async getEvmChainId() {
73
84
  const { walletStrategy } = this;
74
85
  if (!isEvmBrowserWallet(walletStrategy.wallet)) return this.evmChainId;
@@ -251,7 +262,7 @@ var MsgBroadcaster = class {
251
262
  });
252
263
  const txTimeoutTimeInSeconds = txTimeoutInBlocks * DEFAULT_BLOCK_TIME_IN_SECONDS;
253
264
  const txTimeoutTimeInMilliSeconds = txTimeoutTimeInSeconds * 1e3;
254
- const gas = (((_tx$gas = tx.gas) === null || _tx$gas === void 0 ? void 0 : _tx$gas.gas) || getGasPriceBasedOnMessage(msgs)).toString();
265
+ const { gas, estimateGas } = this.resolveGasOptions(msgs, (_tx$gas = tx.gas) === null || _tx$gas === void 0 ? void 0 : _tx$gas.gas);
255
266
  let stdFee = getStdFee({
256
267
  ...tx.gas,
257
268
  gas
@@ -275,7 +286,7 @@ var MsgBroadcaster = class {
275
286
  sequence: baseAccount.sequence
276
287
  },
277
288
  fee: stdFee
278
- });
289
+ }, estimateGas);
279
290
  stdFee = simulatedStdFee;
280
291
  }
281
292
  /** EIP712 for signing on Ethereum wallets */
@@ -371,7 +382,7 @@ var MsgBroadcaster = class {
371
382
  });
372
383
  const txTimeoutTimeInSeconds = txTimeoutInBlocks * DEFAULT_BLOCK_TIME_IN_SECONDS;
373
384
  const txTimeoutTimeInMilliSeconds = txTimeoutTimeInSeconds * 1e3;
374
- const gas = (((_tx$gas2 = tx.gas) === null || _tx$gas2 === void 0 ? void 0 : _tx$gas2.gas) || getGasPriceBasedOnMessage(msgs)).toString();
385
+ const { gas, estimateGas } = this.resolveGasOptions(msgs, (_tx$gas2 = tx.gas) === null || _tx$gas2 === void 0 ? void 0 : _tx$gas2.gas);
375
386
  let stdFee = getStdFee({
376
387
  ...tx.gas,
377
388
  gas
@@ -395,7 +406,7 @@ var MsgBroadcaster = class {
395
406
  accountNumber: baseAccount.accountNumber
396
407
  },
397
408
  fee: stdFee
398
- });
409
+ }, estimateGas);
399
410
  stdFee = simulatedStdFee;
400
411
  }
401
412
  walletStrategy.emit(WalletStrategyEmitterEventType.TransactionPreparationStart);
@@ -473,7 +484,8 @@ var MsgBroadcaster = class {
473
484
  * @returns transaction hash
474
485
  */
475
486
  async broadcastEip712WithFeeDelegation(tx) {
476
- const { endpoints, simulateTx, httpHeaders, walletStrategy, txTimeoutOnFeeDelegation } = this;
487
+ var _tx$gas3;
488
+ const { endpoints, httpHeaders, walletStrategy, txTimeoutOnFeeDelegation } = this;
477
489
  const txTimeoutInBlocks = this.resolveTimeoutInBlocks(tx.txTimeoutInBlocks);
478
490
  const msgs = Array.isArray(tx.msgs) ? tx.msgs : [tx.msgs];
479
491
  const web3Msgs = msgs.map((msg) => msg.toWeb3());
@@ -497,14 +509,15 @@ var MsgBroadcaster = class {
497
509
  });
498
510
  }
499
511
  walletStrategy.emit(WalletStrategyEmitterEventType.TransactionPreparationStart);
512
+ const { gasLimit, estimateGas } = this.resolveGasOptions(msgs, this.useFixedGas ? (_tx$gas3 = tx.gas) === null || _tx$gas3 === void 0 ? void 0 : _tx$gas3.gas : void 0);
500
513
  const prepareTxResponse = await transactionApi.prepareTxRequest({
501
514
  timeoutHeight: timeoutHeight === null || timeoutHeight === void 0 ? void 0 : timeoutHeight.toNumber(),
502
515
  memo: tx.memo,
503
516
  message: web3Msgs,
504
517
  address: tx.ethereumAddress,
505
518
  chainId: evmChainId,
506
- gasLimit: getGasPriceBasedOnMessage(msgs),
507
- estimateGas: simulateTx
519
+ gasLimit,
520
+ estimateGas
508
521
  });
509
522
  walletStrategy.emit(WalletStrategyEmitterEventType.TransactionPreparationEnd);
510
523
  const signature = await walletStrategy.signEip712TypedData(prepareTxResponse.data, tx.ethereumAddress, { txTimeout: txTimeoutTimeInSeconds });
@@ -553,7 +566,7 @@ var MsgBroadcaster = class {
553
566
  * @returns transaction hash
554
567
  */
555
568
  async broadcastDirectSign(tx) {
556
- var _tx$gas3;
569
+ var _tx$gas4;
557
570
  const { chainId, endpoints, walletStrategy } = this;
558
571
  const txTimeoutInBlocks = this.resolveTimeoutInBlocks(tx.txTimeoutInBlocks);
559
572
  const msgs = Array.isArray(tx.msgs) ? tx.msgs : [tx.msgs];
@@ -577,7 +590,7 @@ var MsgBroadcaster = class {
577
590
  });
578
591
  const txTimeoutTimeInMilliSeconds = txTimeoutInBlocks * DEFAULT_BLOCK_TIME_IN_SECONDS * 1e3;
579
592
  const signMode = isCosmosAminoOnlyWallet(walletStrategy.wallet) ? SIGN_EIP712 : SIGN_DIRECT;
580
- const gas = (((_tx$gas3 = tx.gas) === null || _tx$gas3 === void 0 ? void 0 : _tx$gas3.gas) || getGasPriceBasedOnMessage(msgs)).toString();
593
+ const { gas, estimateGas } = this.resolveGasOptions(msgs, (_tx$gas4 = tx.gas) === null || _tx$gas4 === void 0 ? void 0 : _tx$gas4.gas);
581
594
  walletStrategy.emit(WalletStrategyEmitterEventType.TransactionPreparationStart);
582
595
  /** Prepare the Transaction * */
583
596
  const { txRaw } = await this.getTxWithSignersAndStdFee({
@@ -595,17 +608,17 @@ var MsgBroadcaster = class {
595
608
  ...tx.gas,
596
609
  gas
597
610
  })
598
- });
611
+ }, estimateGas);
599
612
  walletStrategy.emit(WalletStrategyEmitterEventType.TransactionPreparationEnd);
600
613
  /** Ledger using Cosmos app only allows signing amino docs */
601
614
  if (isCosmosAminoOnlyWallet(walletStrategy.wallet)) {
602
- var _tx$gas4;
615
+ var _tx$gas5;
603
616
  const aminoSignDoc = getAminoStdSignDoc({
604
617
  ...tx,
605
618
  ...baseAccount,
606
619
  msgs,
607
620
  chainId,
608
- gas: gas || ((_tx$gas4 = tx.gas) === null || _tx$gas4 === void 0 || (_tx$gas4 = _tx$gas4.gas) === null || _tx$gas4 === void 0 ? void 0 : _tx$gas4.toString()),
621
+ gas: gas || ((_tx$gas5 = tx.gas) === null || _tx$gas5 === void 0 || (_tx$gas5 = _tx$gas5.gas) === null || _tx$gas5 === void 0 ? void 0 : _tx$gas5.toString()),
609
622
  timeoutHeight: timeoutHeight.toFixed()
610
623
  });
611
624
  txRaw.signatures = [base64ToUint8Array((await walletStrategy.signAminoCosmosTransaction({
@@ -687,8 +700,8 @@ var MsgBroadcaster = class {
687
700
  * @param tx the transaction that needs to be broadcasted
688
701
  */
689
702
  async experimentalBroadcastWalletThroughLedger(tx) {
690
- var _tx$gas5, _tx$gas6;
691
- const { chainId, endpoints, evmChainId, simulateTx, walletStrategy } = this;
703
+ var _tx$gas6, _tx$gas7;
704
+ const { chainId, endpoints, evmChainId, walletStrategy } = this;
692
705
  const txTimeoutInBlocks = this.resolveTimeoutInBlocks(tx.txTimeoutInBlocks);
693
706
  const msgs = Array.isArray(tx.msgs) ? tx.msgs : [tx.msgs];
694
707
  /**
@@ -711,7 +724,7 @@ var MsgBroadcaster = class {
711
724
  latestHeight,
712
725
  txTimeoutInBlocks
713
726
  });
714
- const gas = (((_tx$gas5 = tx.gas) === null || _tx$gas5 === void 0 ? void 0 : _tx$gas5.gas) || getGasPriceBasedOnMessage(msgs)).toString();
727
+ const { gas, estimateGas } = this.resolveGasOptions(msgs, (_tx$gas6 = tx.gas) === null || _tx$gas6 === void 0 ? void 0 : _tx$gas6.gas);
715
728
  /** EIP712 for signing on Ethereum wallets */
716
729
  const eip712TypedData = getEip712TypedData({
717
730
  msgs,
@@ -735,7 +748,7 @@ var MsgBroadcaster = class {
735
748
  ...baseAccount,
736
749
  msgs,
737
750
  chainId,
738
- gas: gas || ((_tx$gas6 = tx.gas) === null || _tx$gas6 === void 0 || (_tx$gas6 = _tx$gas6.gas) === null || _tx$gas6 === void 0 ? void 0 : _tx$gas6.toString()),
751
+ gas: gas || ((_tx$gas7 = tx.gas) === null || _tx$gas7 === void 0 || (_tx$gas7 = _tx$gas7.gas) === null || _tx$gas7 === void 0 ? void 0 : _tx$gas7.toString()),
739
752
  timeoutHeight: timeoutHeight.toFixed()
740
753
  })
741
754
  });
@@ -756,7 +769,7 @@ var MsgBroadcaster = class {
756
769
  timeoutHeight: parseInt(aminoSignResponse.signed.timeout_height, 10)
757
770
  });
758
771
  const txRawEip712 = createTxRawEIP712(txRaw, createWeb3Extension({ evmChainId }));
759
- if (simulateTx) await this.simulateTxRaw(txRawEip712);
772
+ if (estimateGas) await this.simulateTxRaw(txRawEip712);
760
773
  txRawEip712.signatures = [base64ToUint8Array(aminoSignResponse.signature.signature)];
761
774
  /** Broadcast the transaction */
762
775
  const response = await new TxGrpcApi(endpoints.grpc).broadcast(txRawEip712, {
@@ -782,8 +795,8 @@ var MsgBroadcaster = class {
782
795
  * @returns transaction hashR
783
796
  */
784
797
  async broadcastDirectSignWithFeeDelegation(tx) {
785
- var _tx$gas7;
786
- const { options, chainId, endpoints, simulateTx, httpHeaders, walletStrategy, txTimeoutOnFeeDelegation } = this;
798
+ var _tx$gas9;
799
+ const { options, chainId, endpoints, httpHeaders, walletStrategy, txTimeoutOnFeeDelegation } = this;
787
800
  const txTimeoutInBlocks = this.resolveTimeoutInBlocks(tx.txTimeoutInBlocks);
788
801
  const msgs = Array.isArray(tx.msgs) ? tx.msgs : [tx.msgs];
789
802
  /**
@@ -814,11 +827,14 @@ var MsgBroadcaster = class {
814
827
  } catch (e) {
815
828
  const error = e;
816
829
  if (isThrownException(error) && error.message.toLowerCase().includes(`account ${tx.injectiveAddress} not found`)) {
830
+ var _tx$gas8, _fixedGasOptions$esti;
831
+ const fixedGasOptions = this.useFixedGas ? this.resolveGasOptions(msgs, (_tx$gas8 = tx.gas) === null || _tx$gas8 === void 0 ? void 0 : _tx$gas8.gas) : void 0;
817
832
  await transactionApi.prepareCosmosTxRequest({
818
833
  address: tx.injectiveAddress,
819
834
  message: msgs.map((msg) => msg.toWeb3Gw()),
820
835
  memo: tx.memo,
821
- estimateGas: simulateTx
836
+ ...fixedGasOptions && { gasLimit: fixedGasOptions.gasLimit },
837
+ estimateGas: (_fixedGasOptions$esti = fixedGasOptions === null || fixedGasOptions === void 0 ? void 0 : fixedGasOptions.estimateGas) !== null && _fixedGasOptions$esti !== void 0 ? _fixedGasOptions$esti : this.simulateTx
822
838
  });
823
839
  const { baseAccount: baseAccount$1, latestHeight: latestHeight$1 } = await this.fetchAccountAndBlockDetails({
824
840
  latestHeight: tx.latestHeight,
@@ -848,7 +864,7 @@ var MsgBroadcaster = class {
848
864
  txTimeoutInBlocks: txTimeoutOnFeeDelegation ? txTimeoutInBlocks : DEFAULT_BLOCK_TIMEOUT_HEIGHT
849
865
  });
850
866
  const txTimeoutTimeInMilliSeconds = txTimeoutInBlocks * DEFAULT_BLOCK_TIME_IN_SECONDS * 1e3;
851
- const gas = (((_tx$gas7 = tx.gas) === null || _tx$gas7 === void 0 ? void 0 : _tx$gas7.gas) || getGasPriceBasedOnMessage(msgs)).toString();
867
+ const { gas, estimateGas } = this.resolveGasOptions(msgs, (_tx$gas9 = tx.gas) === null || _tx$gas9 === void 0 ? void 0 : _tx$gas9.gas);
852
868
  /** Prepare the Transaction * */
853
869
  const { txRaw } = await this.getTxWithSignersAndStdFee({
854
870
  chainId,
@@ -869,7 +885,7 @@ var MsgBroadcaster = class {
869
885
  gas,
870
886
  payer: feePayer
871
887
  })
872
- });
888
+ }, estimateGas);
873
889
  if (cosmosWallet === null || cosmosWallet === void 0 ? void 0 : cosmosWallet.disableGasCheck) cosmosWallet.disableGasCheck(chainId);
874
890
  walletStrategy.emit(WalletStrategyEmitterEventType.TransactionPreparationStart);
875
891
  const directSignResponse = await walletStrategy.signCosmosTransaction({
@@ -964,13 +980,18 @@ var MsgBroadcaster = class {
964
980
  * gas limit based on the simulation and add a small multiplier
965
981
  * to be safe (factor of 1.2 as default)
966
982
  */
967
- async getTxWithSignersAndStdFee(args) {
983
+ async getTxWithSignersAndStdFee(args, estimateGas = this.simulateTx) {
968
984
  var _result$gasInfo;
969
- const { simulateTx } = this;
970
- if (!simulateTx) return {
971
- ...createTransactionWithSigners(args),
972
- stdFee: await this.getStdFeeWithDynamicBaseFee(args.fee)
973
- };
985
+ if (!estimateGas) {
986
+ const stdFee = await this.getStdFeeWithDynamicBaseFee(args.fee);
987
+ return {
988
+ ...createTransactionWithSigners({
989
+ ...args,
990
+ fee: this.useFixedGas ? stdFee : args.fee
991
+ }),
992
+ stdFee
993
+ };
994
+ }
974
995
  const result = await this.simulateTxWithSigners(args);
975
996
  if (!((_result$gasInfo = result.gasInfo) === null || _result$gasInfo === void 0 ? void 0 : _result$gasInfo.gasUsed)) return {
976
997
  ...createTransactionWithSigners(args),
@@ -1,3 +1,3 @@
1
1
  import "./BaseWalletStrategy-2HVN2oeB.js";
2
- import { a as MsgBroadcasterTxOptionsWithAddresses, i as MsgBroadcasterTxOptions, n as MsgBroadcaster, r as MsgBroadcasterOptions, t as Web3Broadcaster } from "./index-mLvMuoGv.js";
2
+ import { a as MsgBroadcasterTxOptionsWithAddresses, i as MsgBroadcasterTxOptions, n as MsgBroadcaster, r as MsgBroadcasterOptions, t as Web3Broadcaster } from "./index-70XLhK_X.js";
3
3
  export { MsgBroadcaster, MsgBroadcasterOptions, MsgBroadcasterTxOptions, MsgBroadcasterTxOptionsWithAddresses, Web3Broadcaster };
@@ -1,4 +1,4 @@
1
- import { n as MsgBroadcaster, t as Web3Broadcaster } from "./broadcaster-DzLAEG3E.js";
1
+ import { n as MsgBroadcaster, t as Web3Broadcaster } from "./broadcaster-iB5heVHH.js";
2
2
  import "./defineProperty-D4YE9KXX.js";
3
3
 
4
4
  export { MsgBroadcaster, Web3Broadcaster };
@@ -38,6 +38,7 @@ interface MsgBroadcasterOptions {
38
38
  txInclusion?: TxClientInclusionOptions;
39
39
  walletStrategy: BaseWalletStrategy;
40
40
  useDynamicBaseFee?: boolean;
41
+ useFixedGas?: boolean;
41
42
  txTimeoutOnFeeDelegation?: boolean;
42
43
  gasBufferCoefficient?: number;
43
44
  httpHeaders?: Record<string, string>;
@@ -59,6 +60,7 @@ declare class MsgBroadcaster {
59
60
  txTimeout: number;
60
61
  simulateTx: boolean;
61
62
  useDynamicBaseFee: boolean;
63
+ useFixedGas: boolean;
62
64
  txTimeoutOnFeeDelegation: boolean;
63
65
  evmChainId?: EvmChainId;
64
66
  gasBufferCoefficient: number;
@@ -73,6 +75,7 @@ declare class MsgBroadcaster {
73
75
  txInclusion?: TxClientInclusionOptions;
74
76
  constructor(options: MsgBroadcasterOptions);
75
77
  setOptions(options: Partial<MsgBroadcasterOptions>): void;
78
+ private resolveGasOptions;
76
79
  getEvmChainId(): Promise<EvmChainId | undefined>;
77
80
  /**
78
81
  * Broadcasting the transaction using the client
@@ -1,5 +1,5 @@
1
1
  import { t as BaseWalletStrategy } from "./BaseWalletStrategy-2HVN2oeB.js";
2
- import { a as MsgBroadcasterTxOptionsWithAddresses, i as MsgBroadcasterTxOptions, n as MsgBroadcaster, r as MsgBroadcasterOptions, t as Web3Broadcaster } from "./index-mLvMuoGv.js";
2
+ import { a as MsgBroadcasterTxOptionsWithAddresses, i as MsgBroadcasterTxOptions, n as MsgBroadcaster, r as MsgBroadcasterOptions, t as Web3Broadcaster } from "./index-70XLhK_X.js";
3
3
  import "./index-DRYular4.js";
4
4
 
5
5
  //#region src/utils/tx.d.ts
package/dist/esm/index.js CHANGED
@@ -1,4 +1,4 @@
1
- import { n as MsgBroadcaster, r as checkIfTxRunOutOfGas, t as Web3Broadcaster } from "./broadcaster-DzLAEG3E.js";
1
+ import { n as MsgBroadcaster, r as checkIfTxRunOutOfGas, t as Web3Broadcaster } from "./broadcaster-iB5heVHH.js";
2
2
  import "./defineProperty-D4YE9KXX.js";
3
3
  import { t as BaseWalletStrategy } from "./strategy-Co4vD1wN.js";
4
4
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@injectivelabs/wallet-core",
3
- "version": "1.20.51",
3
+ "version": "1.20.53",
4
4
  "description": "Core wallet strategy",
5
5
  "license": "Apache-2.0",
6
6
  "author": {
@@ -84,12 +84,12 @@
84
84
  "dependencies": {
85
85
  "@keplr-wallet/types": "^0.12.296",
86
86
  "eventemitter3": "^5.0.1",
87
- "@injectivelabs/networks": "1.20.51",
88
- "@injectivelabs/exceptions": "1.20.51",
89
- "@injectivelabs/utils": "1.20.51",
90
- "@injectivelabs/sdk-ts": "1.20.51",
91
- "@injectivelabs/ts-types": "1.20.51",
92
- "@injectivelabs/wallet-base": "1.20.51"
87
+ "@injectivelabs/exceptions": "1.20.53",
88
+ "@injectivelabs/networks": "1.20.53",
89
+ "@injectivelabs/sdk-ts": "1.20.53",
90
+ "@injectivelabs/utils": "1.20.53",
91
+ "@injectivelabs/wallet-base": "1.20.53",
92
+ "@injectivelabs/ts-types": "1.20.53"
93
93
  },
94
94
  "publishConfig": {
95
95
  "access": "public"