@injectivelabs/wallet-core 1.19.26 → 1.19.28

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.
@@ -244,6 +244,7 @@ var MsgBroadcaster = class {
244
244
  _defineProperty(this, "gasBufferCoefficient", 1.2);
245
245
  _defineProperty(this, "retriesOnError", defaultRetriesConfig());
246
246
  _defineProperty(this, "httpHeaders", void 0);
247
+ _defineProperty(this, "txInclusion", void 0);
247
248
  const networkInfo = (0, __injectivelabs_networks.getNetworkInfo)(options.network);
248
249
  this.options = options;
249
250
  this.simulateTx = options.simulateTx !== void 0 ? options.simulateTx : true;
@@ -255,11 +256,13 @@ var MsgBroadcaster = class {
255
256
  this.endpoints = options.endpoints || (0, __injectivelabs_networks.getNetworkEndpoints)(options.network);
256
257
  this.walletStrategy = options.walletStrategy;
257
258
  this.httpHeaders = options.httpHeaders;
259
+ this.txInclusion = options.txInclusion;
258
260
  }
259
261
  setOptions(options) {
260
262
  this.simulateTx = options.simulateTx || this.simulateTx;
261
263
  this.txTimeout = options.txTimeout || this.txTimeout;
262
264
  this.txTimeoutOnFeeDelegation = options.txTimeoutOnFeeDelegation || this.txTimeoutOnFeeDelegation;
265
+ this.txInclusion = options.txInclusion || this.txInclusion;
263
266
  }
264
267
  async getEvmChainId() {
265
268
  const { walletStrategy } = this;
@@ -373,7 +376,7 @@ var MsgBroadcaster = class {
373
376
  * @param privateKey Taker (autosign) private key — hex, with or without `0x`
374
377
  * @returns transaction response with txHash
375
378
  */
376
- async broadcastWithFeePayerSig({ tx, privateKey, feePayerSig, accountNumber, txTimeoutInBlocks: txTimeoutInBlocksParam }) {
379
+ async broadcastWithFeePayerSig({ tx, privateKey, feePayerSig, accountNumber, txInclusion, txTimeoutInBlocks: txTimeoutInBlocksParam }) {
377
380
  const { chainId, endpoints, walletStrategy } = this;
378
381
  const txTimeoutInBlocks = this.resolveTimeoutInBlocks(txTimeoutInBlocksParam);
379
382
  const pk = __injectivelabs_sdk_ts_core_accounts.PrivateKey.fromHex(privateKey);
@@ -393,8 +396,10 @@ var MsgBroadcaster = class {
393
396
  walletStrategy.emit(__injectivelabs_wallet_base.WalletStrategyEmitterEventType.TransactionPreparationEnd);
394
397
  txRaw.signatures = [takerSig, feePayerSig.startsWith("0x") ? (0, __injectivelabs_sdk_ts_utils.hexToUint8Array)(feePayerSig.slice(2)) : (0, __injectivelabs_sdk_ts_utils.base64ToUint8Array)(feePayerSig)];
395
398
  walletStrategy.emit(__injectivelabs_wallet_base.WalletStrategyEmitterEventType.TransactionBroadcastStart);
399
+ const txInclusionOptions = this.resolveTxInclusionOptions({ txInclusion });
396
400
  const txResponse = await new __injectivelabs_sdk_ts_core_tx.TxGrpcApi(endpoints.grpc).broadcast(txRaw, {
397
401
  txTimeout: txTimeoutInBlocks,
402
+ ...txInclusionOptions,
398
403
  onBroadcast: () => {
399
404
  walletStrategy.emit(__injectivelabs_wallet_base.WalletStrategyEmitterEventType.TransactionBroadcastSynced);
400
405
  }
@@ -413,9 +418,6 @@ var MsgBroadcaster = class {
413
418
  throw new __injectivelabs_exceptions.TransactionException(new Error(error));
414
419
  }
415
420
  }
416
- resolveTimeoutInBlocks(override) {
417
- return typeof override === "number" && Number.isInteger(override) && override > 0 ? override : this.txTimeout;
418
- }
419
421
  /**
420
422
  * Prepare/sign/broadcast transaction using
421
423
  * Ethereum native wallets on the client side.
@@ -497,14 +499,30 @@ var MsgBroadcaster = class {
497
499
  const txRawEip712 = (0, __injectivelabs_sdk_ts_core_tx.createTxRawEIP712)(txRaw, (0, __injectivelabs_sdk_ts_core_tx.createWeb3Extension)({ evmChainId }));
498
500
  /** Append Signatures */
499
501
  txRawEip712.signatures = [(0, __injectivelabs_sdk_ts_utils.hexToBuff)(signature)];
500
- const response = await walletStrategy.sendTransaction(txRawEip712, {
501
- chainId,
502
- endpoints,
503
- txTimeout: txTimeoutInBlocks,
504
- address: tx.injectiveAddress
502
+ const inclusionWaiter = await this.prepareTxInclusionWaiter({
503
+ tx,
504
+ txRawOrSignResponse: txRawEip712,
505
+ timeout: txTimeoutTimeInMilliSeconds
505
506
  });
507
+ let response;
508
+ try {
509
+ response = await walletStrategy.sendTransaction(txRawEip712, {
510
+ chainId,
511
+ endpoints,
512
+ txTimeout: txTimeoutInBlocks,
513
+ address: tx.injectiveAddress
514
+ });
515
+ } catch (e) {
516
+ inclusionWaiter.close();
517
+ throw e;
518
+ }
506
519
  walletStrategy.emit(__injectivelabs_wallet_base.WalletStrategyEmitterEventType.TransactionBroadcastSynced);
507
- const confirmedTx = await new __injectivelabs_sdk_ts_core_tx.TxGrpcApi(endpoints.grpc).fetchTxPoll(response.txHash, txTimeoutTimeInMilliSeconds);
520
+ const confirmedTx = await this.waitForPreparedTxInclusion({
521
+ tx,
522
+ inclusionWaiter,
523
+ responseTxHash: response.txHash,
524
+ timeout: txTimeoutTimeInMilliSeconds
525
+ });
508
526
  walletStrategy.emit(__injectivelabs_wallet_base.WalletStrategyEmitterEventType.TransactionBroadcastEnd);
509
527
  return confirmedTx;
510
528
  }
@@ -591,14 +609,30 @@ var MsgBroadcaster = class {
591
609
  const txRawEip712 = (0, __injectivelabs_sdk_ts_core_tx.createTxRawEIP712)(txRaw, (0, __injectivelabs_sdk_ts_core_tx.createWeb3Extension)({ evmChainId }));
592
610
  /** Append Signatures */
593
611
  txRawEip712.signatures = [(0, __injectivelabs_sdk_ts_utils.hexToBuff)(signature)];
594
- const response = await walletStrategy.sendTransaction(txRawEip712, {
595
- chainId,
596
- endpoints,
597
- txTimeout: txTimeoutInBlocks,
598
- address: tx.injectiveAddress
612
+ const inclusionWaiter = await this.prepareTxInclusionWaiter({
613
+ tx,
614
+ timeout: txTimeoutTimeInMilliSeconds,
615
+ txRawOrSignResponse: txRawEip712
599
616
  });
617
+ let response;
618
+ try {
619
+ response = await walletStrategy.sendTransaction(txRawEip712, {
620
+ chainId,
621
+ endpoints,
622
+ txTimeout: txTimeoutInBlocks,
623
+ address: tx.injectiveAddress
624
+ });
625
+ } catch (e) {
626
+ inclusionWaiter.close();
627
+ throw e;
628
+ }
600
629
  walletStrategy.emit(__injectivelabs_wallet_base.WalletStrategyEmitterEventType.TransactionBroadcastSynced);
601
- const confirmedTx = await new __injectivelabs_sdk_ts_core_tx.TxGrpcApi(endpoints.grpc).fetchTxPoll(response.txHash, txTimeoutTimeInMilliSeconds);
630
+ const confirmedTx = await this.waitForPreparedTxInclusion({
631
+ tx,
632
+ inclusionWaiter,
633
+ responseTxHash: response.txHash,
634
+ timeout: txTimeoutTimeInMilliSeconds
635
+ });
602
636
  walletStrategy.emit(__injectivelabs_wallet_base.WalletStrategyEmitterEventType.TransactionBroadcastEnd);
603
637
  return confirmedTx;
604
638
  }
@@ -644,7 +678,11 @@ var MsgBroadcaster = class {
644
678
  walletStrategy.emit(__injectivelabs_wallet_base.WalletStrategyEmitterEventType.TransactionBroadcastStart);
645
679
  const response = await broadcast();
646
680
  walletStrategy.emit(__injectivelabs_wallet_base.WalletStrategyEmitterEventType.TransactionBroadcastSynced);
647
- const confirmedTx = await new __injectivelabs_sdk_ts_core_tx.TxGrpcApi(endpoints.grpc).fetchTxPoll(response.txHash, txTimeoutTimeInMilliSeconds);
681
+ const confirmedTx = await this.waitForTxInclusion({
682
+ tx,
683
+ txHash: response.txHash,
684
+ timeout: txTimeoutTimeInMilliSeconds
685
+ });
648
686
  walletStrategy.emit(__injectivelabs_wallet_base.WalletStrategyEmitterEventType.TransactionBroadcastEnd);
649
687
  return confirmedTx;
650
688
  } catch (e) {
@@ -726,14 +764,30 @@ var MsgBroadcaster = class {
726
764
  address: tx.injectiveAddress
727
765
  })).signature.signature)];
728
766
  walletStrategy.emit(__injectivelabs_wallet_base.WalletStrategyEmitterEventType.TransactionBroadcastStart);
729
- const response$1 = await walletStrategy.sendTransaction(txRaw, {
730
- chainId,
731
- endpoints,
732
- address: tx.injectiveAddress,
733
- txTimeout: txTimeoutInBlocks
767
+ const inclusionWaiter$1 = await this.prepareTxInclusionWaiter({
768
+ tx,
769
+ txRawOrSignResponse: txRaw,
770
+ timeout: txTimeoutTimeInMilliSeconds
734
771
  });
772
+ let response$1;
773
+ try {
774
+ response$1 = await walletStrategy.sendTransaction(txRaw, {
775
+ chainId,
776
+ endpoints,
777
+ address: tx.injectiveAddress,
778
+ txTimeout: txTimeoutInBlocks
779
+ });
780
+ } catch (e) {
781
+ inclusionWaiter$1.close();
782
+ throw e;
783
+ }
735
784
  walletStrategy.emit(__injectivelabs_wallet_base.WalletStrategyEmitterEventType.TransactionBroadcastSynced);
736
- const confirmedTx$1 = await new __injectivelabs_sdk_ts_core_tx.TxGrpcApi(endpoints.grpc).fetchTxPoll(response$1.txHash, txTimeoutTimeInMilliSeconds);
785
+ const confirmedTx$1 = await this.waitForPreparedTxInclusion({
786
+ tx,
787
+ inclusionWaiter: inclusionWaiter$1,
788
+ timeout: txTimeoutTimeInMilliSeconds,
789
+ responseTxHash: response$1.txHash
790
+ });
737
791
  walletStrategy.emit(__injectivelabs_wallet_base.WalletStrategyEmitterEventType.TransactionBroadcastEnd);
738
792
  return confirmedTx$1;
739
793
  }
@@ -744,14 +798,30 @@ var MsgBroadcaster = class {
744
798
  accountNumber: baseAccount.accountNumber
745
799
  });
746
800
  walletStrategy.emit(__injectivelabs_wallet_base.WalletStrategyEmitterEventType.TransactionBroadcastStart);
747
- const response = await walletStrategy.sendTransaction(directSignResponse, {
748
- chainId,
749
- endpoints,
750
- txTimeout: txTimeoutInBlocks,
751
- address: tx.injectiveAddress
801
+ const inclusionWaiter = await this.prepareTxInclusionWaiter({
802
+ tx,
803
+ timeout: txTimeoutTimeInMilliSeconds,
804
+ txRawOrSignResponse: directSignResponse
752
805
  });
806
+ let response;
807
+ try {
808
+ response = await walletStrategy.sendTransaction(directSignResponse, {
809
+ chainId,
810
+ endpoints,
811
+ txTimeout: txTimeoutInBlocks,
812
+ address: tx.injectiveAddress
813
+ });
814
+ } catch (e) {
815
+ inclusionWaiter.close();
816
+ throw e;
817
+ }
753
818
  walletStrategy.emit(__injectivelabs_wallet_base.WalletStrategyEmitterEventType.TransactionBroadcastSynced);
754
- const confirmedTx = await new __injectivelabs_sdk_ts_core_tx.TxGrpcApi(endpoints.grpc).fetchTxPoll(response.txHash, txTimeoutTimeInMilliSeconds);
819
+ const confirmedTx = await this.waitForPreparedTxInclusion({
820
+ tx,
821
+ inclusionWaiter,
822
+ responseTxHash: response.txHash,
823
+ timeout: txTimeoutTimeInMilliSeconds
824
+ });
755
825
  walletStrategy.emit(__injectivelabs_wallet_base.WalletStrategyEmitterEventType.TransactionBroadcastEnd);
756
826
  return confirmedTx;
757
827
  }
@@ -812,14 +882,14 @@ var MsgBroadcaster = class {
812
882
  */
813
883
  const { txRaw } = (0, __injectivelabs_sdk_ts_core_tx.createTransaction)({
814
884
  pubKey,
885
+ chainId,
815
886
  message: msgs,
816
- memo: aminoSignResponse.signed.memo,
817
887
  signMode: __injectivelabs_sdk_ts_core_tx.SIGN_EIP712,
888
+ memo: aminoSignResponse.signed.memo,
818
889
  fee: aminoSignResponse.signed.fee,
819
890
  sequence: parseInt(aminoSignResponse.signed.sequence, 10),
820
- timeoutHeight: parseInt(aminoSignResponse.signed.timeout_height, 10),
821
891
  accountNumber: parseInt(aminoSignResponse.signed.account_number, 10),
822
- chainId
892
+ timeoutHeight: parseInt(aminoSignResponse.signed.timeout_height, 10)
823
893
  });
824
894
  const txRawEip712 = (0, __injectivelabs_sdk_ts_core_tx.createTxRawEIP712)(txRaw, (0, __injectivelabs_sdk_ts_core_tx.createWeb3Extension)({ evmChainId }));
825
895
  if (simulateTx) await this.simulateTxRaw(txRawEip712);
@@ -827,6 +897,7 @@ var MsgBroadcaster = class {
827
897
  /** Broadcast the transaction */
828
898
  const response = await new __injectivelabs_sdk_ts_core_tx.TxGrpcApi(endpoints.grpc).broadcast(txRawEip712, {
829
899
  txTimeout: txTimeoutInBlocks,
900
+ ...this.resolveTxInclusionOptions(tx),
830
901
  onBroadcast: () => {
831
902
  walletStrategy.emit(__injectivelabs_wallet_base.WalletStrategyEmitterEventType.TransactionBroadcastSynced);
832
903
  }
@@ -929,9 +1000,10 @@ var MsgBroadcaster = class {
929
1000
  accountNumber: baseAccount.accountNumber
930
1001
  });
931
1002
  walletStrategy.emit(__injectivelabs_wallet_base.WalletStrategyEmitterEventType.TransactionPreparationEnd);
1003
+ const signedTxRaw = (0, __injectivelabs_sdk_ts_core_tx.createTxRawFromSigResponse)(directSignResponse);
932
1004
  const broadcast = async () => await transactionApi.broadcastCosmosTxRequest({
1005
+ txRaw: signedTxRaw,
933
1006
  address: tx.injectiveAddress,
934
- txRaw: (0, __injectivelabs_sdk_ts_core_tx.createTxRawFromSigResponse)(directSignResponse),
935
1007
  signature: directSignResponse.signature.signature,
936
1008
  pubKey: directSignResponse.signature.pub_key || {
937
1009
  value: pubKey,
@@ -940,10 +1012,26 @@ var MsgBroadcaster = class {
940
1012
  });
941
1013
  try {
942
1014
  walletStrategy.emit(__injectivelabs_wallet_base.WalletStrategyEmitterEventType.TransactionBroadcastStart);
943
- const response = await broadcast();
1015
+ const inclusionWaiter = await this.prepareTxInclusionWaiter({
1016
+ tx,
1017
+ txRawOrSignResponse: signedTxRaw,
1018
+ timeout: txTimeoutTimeInMilliSeconds
1019
+ });
1020
+ let response;
1021
+ try {
1022
+ response = await broadcast();
1023
+ } catch (e) {
1024
+ inclusionWaiter.close();
1025
+ throw e;
1026
+ }
944
1027
  walletStrategy.emit(__injectivelabs_wallet_base.WalletStrategyEmitterEventType.TransactionBroadcastSynced);
945
1028
  if (canDisableCosmosGasCheck && cosmosWallet.enableGasCheck) cosmosWallet.enableGasCheck(chainId);
946
- const confirmedTx = await new __injectivelabs_sdk_ts_core_tx.TxGrpcApi(endpoints.grpc).fetchTxPoll(response.txHash, txTimeoutTimeInMilliSeconds);
1029
+ const confirmedTx = await this.waitForPreparedTxInclusion({
1030
+ tx,
1031
+ inclusionWaiter,
1032
+ responseTxHash: response.txHash,
1033
+ timeout: txTimeoutTimeInMilliSeconds
1034
+ });
947
1035
  walletStrategy.emit(__injectivelabs_wallet_base.WalletStrategyEmitterEventType.TransactionBroadcastEnd);
948
1036
  return confirmedTx;
949
1037
  } catch (e) {
@@ -1076,6 +1164,52 @@ var MsgBroadcaster = class {
1076
1164
  latestHeight: latestBlock.header.height.toString()
1077
1165
  };
1078
1166
  }
1167
+ resolveTimeoutInBlocks(override) {
1168
+ return typeof override === "number" && Number.isInteger(override) && override > 0 ? override : this.txTimeout;
1169
+ }
1170
+ resolveTxInclusionOptions(tx) {
1171
+ var _txInclusion$eventInc;
1172
+ const txInclusion = (tx === null || tx === void 0 ? void 0 : tx.txInclusion) || this.txInclusion;
1173
+ if (!txInclusion) return;
1174
+ return {
1175
+ ...txInclusion,
1176
+ eventInclusion: {
1177
+ ...txInclusion.eventInclusion,
1178
+ rpcEndpoint: ((_txInclusion$eventInc = txInclusion.eventInclusion) === null || _txInclusion$eventInc === void 0 ? void 0 : _txInclusion$eventInc.rpcEndpoint) || this.endpoints.rpc
1179
+ }
1180
+ };
1181
+ }
1182
+ createTxGrpcApi() {
1183
+ const client = new __injectivelabs_sdk_ts_core_tx.TxGrpcApi(this.endpoints.grpc);
1184
+ if (this.httpHeaders) client.setMetadata(this.httpHeaders);
1185
+ return client;
1186
+ }
1187
+ async waitForTxInclusion({ tx, txHash, timeout }) {
1188
+ return this.createTxGrpcApi().waitForTxInclusion({
1189
+ txHash,
1190
+ timeout,
1191
+ options: this.resolveTxInclusionOptions(tx)
1192
+ });
1193
+ }
1194
+ async prepareTxInclusionWaiter({ tx, timeout, txRawOrSignResponse }) {
1195
+ const txRaw = (0, __injectivelabs_sdk_ts_core_tx.createTxRawFromSigResponse)(txRawOrSignResponse);
1196
+ const txHash = __injectivelabs_sdk_ts_core_tx.TxClient.hash(txRaw);
1197
+ return this.createTxGrpcApi().prepareTxInclusionWait({
1198
+ txHash,
1199
+ timeout,
1200
+ options: this.resolveTxInclusionOptions(tx)
1201
+ });
1202
+ }
1203
+ async waitForPreparedTxInclusion({ tx, timeout, responseTxHash, inclusionWaiter }) {
1204
+ if (!inclusionWaiter) return this.waitForTxInclusion({
1205
+ tx,
1206
+ timeout,
1207
+ txHash: responseTxHash
1208
+ });
1209
+ const confirmedTx = await inclusionWaiter.wait(responseTxHash);
1210
+ if (!confirmedTx) throw new __injectivelabs_exceptions.TransactionException(/* @__PURE__ */ new Error(`The transaction with ${responseTxHash} is not found`));
1211
+ return confirmedTx;
1212
+ }
1079
1213
  };
1080
1214
 
1081
1215
  //#endregion
@@ -2,7 +2,7 @@ import { ConcreteStrategiesArg, ConcreteWalletStrategy, CosmosWalletAbstraction,
2
2
  import { StdSignDoc } from "@keplr-wallet/types";
3
3
  import { OfflineSigner } from "@cosmjs/proto-signing";
4
4
  import { AccountAddress, ChainId, EvmChainId } from "@injectivelabs/ts-types";
5
- import { TxResponse } from "@injectivelabs/sdk-ts/core/tx";
5
+ import { TxClientInclusionOptions, TxResponse } from "@injectivelabs/sdk-ts/core/tx";
6
6
  import { AminoSignResponse, DirectSignResponse, TxRaw } from "@injectivelabs/sdk-ts/types";
7
7
  import { Msgs } from "@injectivelabs/sdk-ts/core/modules";
8
8
  import { Network, NetworkEndpoints } from "@injectivelabs/networks";
@@ -81,6 +81,7 @@ interface MsgBroadcasterTxOptions {
81
81
  injectiveAddress?: string;
82
82
  accountDetails?: AuthBaseAccount;
83
83
  txTimeoutInBlocks?: number;
84
+ txInclusion?: TxClientInclusionOptions;
84
85
  gas?: {
85
86
  gasPrice?: string;
86
87
  gas?: number; /** gas limit */
@@ -101,6 +102,7 @@ interface MsgBroadcasterOptions {
101
102
  simulateTx?: boolean;
102
103
  txTimeoutOnFeeDelegation?: boolean;
103
104
  txTimeout?: number;
105
+ txInclusion?: TxClientInclusionOptions;
104
106
  walletStrategy: BaseWalletStrategy;
105
107
  gasBufferCoefficient?: number;
106
108
  httpHeaders?: Record<string, string>;
@@ -132,6 +134,7 @@ declare class MsgBroadcaster {
132
134
  };
133
135
  };
134
136
  httpHeaders?: Record<string, string>;
137
+ txInclusion?: TxClientInclusionOptions;
135
138
  constructor(options: MsgBroadcasterOptions);
136
139
  setOptions(options: Partial<MsgBroadcasterOptions>): void;
137
140
  getEvmChainId(): Promise<EvmChainId | undefined>;
@@ -182,15 +185,16 @@ declare class MsgBroadcaster {
182
185
  privateKey,
183
186
  feePayerSig,
184
187
  accountNumber,
188
+ txInclusion,
185
189
  txTimeoutInBlocks: txTimeoutInBlocksParam
186
190
  }: {
187
191
  privateKey: string;
188
192
  feePayerSig: string;
189
193
  accountNumber: number;
190
194
  tx: Uint8Array | string;
195
+ txInclusion?: TxClientInclusionOptions;
191
196
  txTimeoutInBlocks?: number;
192
197
  }): Promise<TxResponse>;
193
- private resolveTimeoutInBlocks;
194
198
  /**
195
199
  * Prepare/sign/broadcast transaction using
196
200
  * Ethereum native wallets on the client side.
@@ -268,6 +272,12 @@ declare class MsgBroadcaster {
268
272
  private simulateTxWithSigners;
269
273
  private retryOnException;
270
274
  private fetchAccountAndBlockDetails;
275
+ private resolveTimeoutInBlocks;
276
+ private resolveTxInclusionOptions;
277
+ private createTxGrpcApi;
278
+ private waitForTxInclusion;
279
+ private prepareTxInclusionWaiter;
280
+ private waitForPreparedTxInclusion;
271
281
  }
272
282
  //#endregion
273
283
  //#region src/broadcaster/Web3Broadcaster.d.ts
@@ -2,7 +2,7 @@ import { ConcreteStrategiesArg, ConcreteWalletStrategy, CosmosWalletAbstraction,
2
2
  import { AccountAddress, ChainId, EvmChainId } from "@injectivelabs/ts-types";
3
3
  import { Network, NetworkEndpoints } from "@injectivelabs/networks";
4
4
  import { AuthBaseAccount } from "@injectivelabs/sdk-ts/client/chain";
5
- import { TxResponse } from "@injectivelabs/sdk-ts/core/tx";
5
+ import { TxClientInclusionOptions, TxResponse } from "@injectivelabs/sdk-ts/core/tx";
6
6
  import { StdSignDoc } from "@keplr-wallet/types";
7
7
  import { OfflineSigner } from "@cosmjs/proto-signing";
8
8
  import { AminoSignResponse, DirectSignResponse, TxRaw } from "@injectivelabs/sdk-ts/types";
@@ -81,6 +81,7 @@ interface MsgBroadcasterTxOptions {
81
81
  injectiveAddress?: string;
82
82
  accountDetails?: AuthBaseAccount;
83
83
  txTimeoutInBlocks?: number;
84
+ txInclusion?: TxClientInclusionOptions;
84
85
  gas?: {
85
86
  gasPrice?: string;
86
87
  gas?: number; /** gas limit */
@@ -101,6 +102,7 @@ interface MsgBroadcasterOptions {
101
102
  simulateTx?: boolean;
102
103
  txTimeoutOnFeeDelegation?: boolean;
103
104
  txTimeout?: number;
105
+ txInclusion?: TxClientInclusionOptions;
104
106
  walletStrategy: BaseWalletStrategy;
105
107
  gasBufferCoefficient?: number;
106
108
  httpHeaders?: Record<string, string>;
@@ -132,6 +134,7 @@ declare class MsgBroadcaster {
132
134
  };
133
135
  };
134
136
  httpHeaders?: Record<string, string>;
137
+ txInclusion?: TxClientInclusionOptions;
135
138
  constructor(options: MsgBroadcasterOptions);
136
139
  setOptions(options: Partial<MsgBroadcasterOptions>): void;
137
140
  getEvmChainId(): Promise<EvmChainId | undefined>;
@@ -182,15 +185,16 @@ declare class MsgBroadcaster {
182
185
  privateKey,
183
186
  feePayerSig,
184
187
  accountNumber,
188
+ txInclusion,
185
189
  txTimeoutInBlocks: txTimeoutInBlocksParam
186
190
  }: {
187
191
  privateKey: string;
188
192
  feePayerSig: string;
189
193
  accountNumber: number;
190
194
  tx: Uint8Array | string;
195
+ txInclusion?: TxClientInclusionOptions;
191
196
  txTimeoutInBlocks?: number;
192
197
  }): Promise<TxResponse>;
193
- private resolveTimeoutInBlocks;
194
198
  /**
195
199
  * Prepare/sign/broadcast transaction using
196
200
  * Ethereum native wallets on the client side.
@@ -268,6 +272,12 @@ declare class MsgBroadcaster {
268
272
  private simulateTxWithSigners;
269
273
  private retryOnException;
270
274
  private fetchAccountAndBlockDetails;
275
+ private resolveTimeoutInBlocks;
276
+ private resolveTxInclusionOptions;
277
+ private createTxGrpcApi;
278
+ private waitForTxInclusion;
279
+ private prepareTxInclusionWaiter;
280
+ private waitForPreparedTxInclusion;
271
281
  }
272
282
  //#endregion
273
283
  //#region src/broadcaster/Web3Broadcaster.d.ts
package/dist/esm/index.js CHANGED
@@ -8,7 +8,7 @@ import { IndexerGrpcWeb3GwApi } from "@injectivelabs/sdk-ts/client/indexer";
8
8
  import { getNetworkEndpoints, getNetworkInfo, isMainnet, isTestnet } from "@injectivelabs/networks";
9
9
  import { ChainGrpcAuthApi, ChainGrpcTendermintApi, ChainGrpcTxFeesApi } from "@injectivelabs/sdk-ts/client/chain";
10
10
  import { DEFAULT_BLOCK_TIMEOUT_HEIGHT, DEFAULT_BLOCK_TIME_IN_SECONDS, DEFAULT_GAS_PRICE, getStdFee, sleep, toBigNumber } from "@injectivelabs/utils";
11
- import { CosmosTxV1Beta1TxPb, SIGN_DIRECT, SIGN_EIP712, SIGN_EIP712_V2, TxGrpcApi, createTransaction, createTransactionWithSigners, createTxRawEIP712, createTxRawFromSigResponse, createWeb3Extension, getAminoStdSignDoc, getEip712TypedData, getEip712TypedDataV2 } from "@injectivelabs/sdk-ts/core/tx";
11
+ import { CosmosTxV1Beta1TxPb, SIGN_DIRECT, SIGN_EIP712, SIGN_EIP712_V2, TxClient, TxGrpcApi, createTransaction, createTransactionWithSigners, createTxRawEIP712, createTxRawFromSigResponse, createWeb3Extension, getAminoStdSignDoc, getEip712TypedData, getEip712TypedDataV2 } from "@injectivelabs/sdk-ts/core/tx";
12
12
 
13
13
  //#region src/utils/tx.ts
14
14
  const checkIfTxRunOutOfGas = (e) => {
@@ -244,6 +244,7 @@ var MsgBroadcaster = class {
244
244
  _defineProperty(this, "gasBufferCoefficient", 1.2);
245
245
  _defineProperty(this, "retriesOnError", defaultRetriesConfig());
246
246
  _defineProperty(this, "httpHeaders", void 0);
247
+ _defineProperty(this, "txInclusion", void 0);
247
248
  const networkInfo = getNetworkInfo(options.network);
248
249
  this.options = options;
249
250
  this.simulateTx = options.simulateTx !== void 0 ? options.simulateTx : true;
@@ -255,11 +256,13 @@ var MsgBroadcaster = class {
255
256
  this.endpoints = options.endpoints || getNetworkEndpoints(options.network);
256
257
  this.walletStrategy = options.walletStrategy;
257
258
  this.httpHeaders = options.httpHeaders;
259
+ this.txInclusion = options.txInclusion;
258
260
  }
259
261
  setOptions(options) {
260
262
  this.simulateTx = options.simulateTx || this.simulateTx;
261
263
  this.txTimeout = options.txTimeout || this.txTimeout;
262
264
  this.txTimeoutOnFeeDelegation = options.txTimeoutOnFeeDelegation || this.txTimeoutOnFeeDelegation;
265
+ this.txInclusion = options.txInclusion || this.txInclusion;
263
266
  }
264
267
  async getEvmChainId() {
265
268
  const { walletStrategy } = this;
@@ -373,7 +376,7 @@ var MsgBroadcaster = class {
373
376
  * @param privateKey Taker (autosign) private key — hex, with or without `0x`
374
377
  * @returns transaction response with txHash
375
378
  */
376
- async broadcastWithFeePayerSig({ tx, privateKey, feePayerSig, accountNumber, txTimeoutInBlocks: txTimeoutInBlocksParam }) {
379
+ async broadcastWithFeePayerSig({ tx, privateKey, feePayerSig, accountNumber, txInclusion, txTimeoutInBlocks: txTimeoutInBlocksParam }) {
377
380
  const { chainId, endpoints, walletStrategy } = this;
378
381
  const txTimeoutInBlocks = this.resolveTimeoutInBlocks(txTimeoutInBlocksParam);
379
382
  const pk = PrivateKey.fromHex(privateKey);
@@ -393,8 +396,10 @@ var MsgBroadcaster = class {
393
396
  walletStrategy.emit(WalletStrategyEmitterEventType.TransactionPreparationEnd);
394
397
  txRaw.signatures = [takerSig, feePayerSig.startsWith("0x") ? hexToUint8Array(feePayerSig.slice(2)) : base64ToUint8Array(feePayerSig)];
395
398
  walletStrategy.emit(WalletStrategyEmitterEventType.TransactionBroadcastStart);
399
+ const txInclusionOptions = this.resolveTxInclusionOptions({ txInclusion });
396
400
  const txResponse = await new TxGrpcApi(endpoints.grpc).broadcast(txRaw, {
397
401
  txTimeout: txTimeoutInBlocks,
402
+ ...txInclusionOptions,
398
403
  onBroadcast: () => {
399
404
  walletStrategy.emit(WalletStrategyEmitterEventType.TransactionBroadcastSynced);
400
405
  }
@@ -413,9 +418,6 @@ var MsgBroadcaster = class {
413
418
  throw new TransactionException(new Error(error));
414
419
  }
415
420
  }
416
- resolveTimeoutInBlocks(override) {
417
- return typeof override === "number" && Number.isInteger(override) && override > 0 ? override : this.txTimeout;
418
- }
419
421
  /**
420
422
  * Prepare/sign/broadcast transaction using
421
423
  * Ethereum native wallets on the client side.
@@ -497,14 +499,30 @@ var MsgBroadcaster = class {
497
499
  const txRawEip712 = createTxRawEIP712(txRaw, createWeb3Extension({ evmChainId }));
498
500
  /** Append Signatures */
499
501
  txRawEip712.signatures = [hexToBuff(signature)];
500
- const response = await walletStrategy.sendTransaction(txRawEip712, {
501
- chainId,
502
- endpoints,
503
- txTimeout: txTimeoutInBlocks,
504
- address: tx.injectiveAddress
502
+ const inclusionWaiter = await this.prepareTxInclusionWaiter({
503
+ tx,
504
+ txRawOrSignResponse: txRawEip712,
505
+ timeout: txTimeoutTimeInMilliSeconds
505
506
  });
507
+ let response;
508
+ try {
509
+ response = await walletStrategy.sendTransaction(txRawEip712, {
510
+ chainId,
511
+ endpoints,
512
+ txTimeout: txTimeoutInBlocks,
513
+ address: tx.injectiveAddress
514
+ });
515
+ } catch (e) {
516
+ inclusionWaiter.close();
517
+ throw e;
518
+ }
506
519
  walletStrategy.emit(WalletStrategyEmitterEventType.TransactionBroadcastSynced);
507
- const confirmedTx = await new TxGrpcApi(endpoints.grpc).fetchTxPoll(response.txHash, txTimeoutTimeInMilliSeconds);
520
+ const confirmedTx = await this.waitForPreparedTxInclusion({
521
+ tx,
522
+ inclusionWaiter,
523
+ responseTxHash: response.txHash,
524
+ timeout: txTimeoutTimeInMilliSeconds
525
+ });
508
526
  walletStrategy.emit(WalletStrategyEmitterEventType.TransactionBroadcastEnd);
509
527
  return confirmedTx;
510
528
  }
@@ -591,14 +609,30 @@ var MsgBroadcaster = class {
591
609
  const txRawEip712 = createTxRawEIP712(txRaw, createWeb3Extension({ evmChainId }));
592
610
  /** Append Signatures */
593
611
  txRawEip712.signatures = [hexToBuff(signature)];
594
- const response = await walletStrategy.sendTransaction(txRawEip712, {
595
- chainId,
596
- endpoints,
597
- txTimeout: txTimeoutInBlocks,
598
- address: tx.injectiveAddress
612
+ const inclusionWaiter = await this.prepareTxInclusionWaiter({
613
+ tx,
614
+ timeout: txTimeoutTimeInMilliSeconds,
615
+ txRawOrSignResponse: txRawEip712
599
616
  });
617
+ let response;
618
+ try {
619
+ response = await walletStrategy.sendTransaction(txRawEip712, {
620
+ chainId,
621
+ endpoints,
622
+ txTimeout: txTimeoutInBlocks,
623
+ address: tx.injectiveAddress
624
+ });
625
+ } catch (e) {
626
+ inclusionWaiter.close();
627
+ throw e;
628
+ }
600
629
  walletStrategy.emit(WalletStrategyEmitterEventType.TransactionBroadcastSynced);
601
- const confirmedTx = await new TxGrpcApi(endpoints.grpc).fetchTxPoll(response.txHash, txTimeoutTimeInMilliSeconds);
630
+ const confirmedTx = await this.waitForPreparedTxInclusion({
631
+ tx,
632
+ inclusionWaiter,
633
+ responseTxHash: response.txHash,
634
+ timeout: txTimeoutTimeInMilliSeconds
635
+ });
602
636
  walletStrategy.emit(WalletStrategyEmitterEventType.TransactionBroadcastEnd);
603
637
  return confirmedTx;
604
638
  }
@@ -644,7 +678,11 @@ var MsgBroadcaster = class {
644
678
  walletStrategy.emit(WalletStrategyEmitterEventType.TransactionBroadcastStart);
645
679
  const response = await broadcast();
646
680
  walletStrategy.emit(WalletStrategyEmitterEventType.TransactionBroadcastSynced);
647
- const confirmedTx = await new TxGrpcApi(endpoints.grpc).fetchTxPoll(response.txHash, txTimeoutTimeInMilliSeconds);
681
+ const confirmedTx = await this.waitForTxInclusion({
682
+ tx,
683
+ txHash: response.txHash,
684
+ timeout: txTimeoutTimeInMilliSeconds
685
+ });
648
686
  walletStrategy.emit(WalletStrategyEmitterEventType.TransactionBroadcastEnd);
649
687
  return confirmedTx;
650
688
  } catch (e) {
@@ -726,14 +764,30 @@ var MsgBroadcaster = class {
726
764
  address: tx.injectiveAddress
727
765
  })).signature.signature)];
728
766
  walletStrategy.emit(WalletStrategyEmitterEventType.TransactionBroadcastStart);
729
- const response$1 = await walletStrategy.sendTransaction(txRaw, {
730
- chainId,
731
- endpoints,
732
- address: tx.injectiveAddress,
733
- txTimeout: txTimeoutInBlocks
767
+ const inclusionWaiter$1 = await this.prepareTxInclusionWaiter({
768
+ tx,
769
+ txRawOrSignResponse: txRaw,
770
+ timeout: txTimeoutTimeInMilliSeconds
734
771
  });
772
+ let response$1;
773
+ try {
774
+ response$1 = await walletStrategy.sendTransaction(txRaw, {
775
+ chainId,
776
+ endpoints,
777
+ address: tx.injectiveAddress,
778
+ txTimeout: txTimeoutInBlocks
779
+ });
780
+ } catch (e) {
781
+ inclusionWaiter$1.close();
782
+ throw e;
783
+ }
735
784
  walletStrategy.emit(WalletStrategyEmitterEventType.TransactionBroadcastSynced);
736
- const confirmedTx$1 = await new TxGrpcApi(endpoints.grpc).fetchTxPoll(response$1.txHash, txTimeoutTimeInMilliSeconds);
785
+ const confirmedTx$1 = await this.waitForPreparedTxInclusion({
786
+ tx,
787
+ inclusionWaiter: inclusionWaiter$1,
788
+ timeout: txTimeoutTimeInMilliSeconds,
789
+ responseTxHash: response$1.txHash
790
+ });
737
791
  walletStrategy.emit(WalletStrategyEmitterEventType.TransactionBroadcastEnd);
738
792
  return confirmedTx$1;
739
793
  }
@@ -744,14 +798,30 @@ var MsgBroadcaster = class {
744
798
  accountNumber: baseAccount.accountNumber
745
799
  });
746
800
  walletStrategy.emit(WalletStrategyEmitterEventType.TransactionBroadcastStart);
747
- const response = await walletStrategy.sendTransaction(directSignResponse, {
748
- chainId,
749
- endpoints,
750
- txTimeout: txTimeoutInBlocks,
751
- address: tx.injectiveAddress
801
+ const inclusionWaiter = await this.prepareTxInclusionWaiter({
802
+ tx,
803
+ timeout: txTimeoutTimeInMilliSeconds,
804
+ txRawOrSignResponse: directSignResponse
752
805
  });
806
+ let response;
807
+ try {
808
+ response = await walletStrategy.sendTransaction(directSignResponse, {
809
+ chainId,
810
+ endpoints,
811
+ txTimeout: txTimeoutInBlocks,
812
+ address: tx.injectiveAddress
813
+ });
814
+ } catch (e) {
815
+ inclusionWaiter.close();
816
+ throw e;
817
+ }
753
818
  walletStrategy.emit(WalletStrategyEmitterEventType.TransactionBroadcastSynced);
754
- const confirmedTx = await new TxGrpcApi(endpoints.grpc).fetchTxPoll(response.txHash, txTimeoutTimeInMilliSeconds);
819
+ const confirmedTx = await this.waitForPreparedTxInclusion({
820
+ tx,
821
+ inclusionWaiter,
822
+ responseTxHash: response.txHash,
823
+ timeout: txTimeoutTimeInMilliSeconds
824
+ });
755
825
  walletStrategy.emit(WalletStrategyEmitterEventType.TransactionBroadcastEnd);
756
826
  return confirmedTx;
757
827
  }
@@ -812,14 +882,14 @@ var MsgBroadcaster = class {
812
882
  */
813
883
  const { txRaw } = createTransaction({
814
884
  pubKey,
885
+ chainId,
815
886
  message: msgs,
816
- memo: aminoSignResponse.signed.memo,
817
887
  signMode: SIGN_EIP712,
888
+ memo: aminoSignResponse.signed.memo,
818
889
  fee: aminoSignResponse.signed.fee,
819
890
  sequence: parseInt(aminoSignResponse.signed.sequence, 10),
820
- timeoutHeight: parseInt(aminoSignResponse.signed.timeout_height, 10),
821
891
  accountNumber: parseInt(aminoSignResponse.signed.account_number, 10),
822
- chainId
892
+ timeoutHeight: parseInt(aminoSignResponse.signed.timeout_height, 10)
823
893
  });
824
894
  const txRawEip712 = createTxRawEIP712(txRaw, createWeb3Extension({ evmChainId }));
825
895
  if (simulateTx) await this.simulateTxRaw(txRawEip712);
@@ -827,6 +897,7 @@ var MsgBroadcaster = class {
827
897
  /** Broadcast the transaction */
828
898
  const response = await new TxGrpcApi(endpoints.grpc).broadcast(txRawEip712, {
829
899
  txTimeout: txTimeoutInBlocks,
900
+ ...this.resolveTxInclusionOptions(tx),
830
901
  onBroadcast: () => {
831
902
  walletStrategy.emit(WalletStrategyEmitterEventType.TransactionBroadcastSynced);
832
903
  }
@@ -929,9 +1000,10 @@ var MsgBroadcaster = class {
929
1000
  accountNumber: baseAccount.accountNumber
930
1001
  });
931
1002
  walletStrategy.emit(WalletStrategyEmitterEventType.TransactionPreparationEnd);
1003
+ const signedTxRaw = createTxRawFromSigResponse(directSignResponse);
932
1004
  const broadcast = async () => await transactionApi.broadcastCosmosTxRequest({
1005
+ txRaw: signedTxRaw,
933
1006
  address: tx.injectiveAddress,
934
- txRaw: createTxRawFromSigResponse(directSignResponse),
935
1007
  signature: directSignResponse.signature.signature,
936
1008
  pubKey: directSignResponse.signature.pub_key || {
937
1009
  value: pubKey,
@@ -940,10 +1012,26 @@ var MsgBroadcaster = class {
940
1012
  });
941
1013
  try {
942
1014
  walletStrategy.emit(WalletStrategyEmitterEventType.TransactionBroadcastStart);
943
- const response = await broadcast();
1015
+ const inclusionWaiter = await this.prepareTxInclusionWaiter({
1016
+ tx,
1017
+ txRawOrSignResponse: signedTxRaw,
1018
+ timeout: txTimeoutTimeInMilliSeconds
1019
+ });
1020
+ let response;
1021
+ try {
1022
+ response = await broadcast();
1023
+ } catch (e) {
1024
+ inclusionWaiter.close();
1025
+ throw e;
1026
+ }
944
1027
  walletStrategy.emit(WalletStrategyEmitterEventType.TransactionBroadcastSynced);
945
1028
  if (canDisableCosmosGasCheck && cosmosWallet.enableGasCheck) cosmosWallet.enableGasCheck(chainId);
946
- const confirmedTx = await new TxGrpcApi(endpoints.grpc).fetchTxPoll(response.txHash, txTimeoutTimeInMilliSeconds);
1029
+ const confirmedTx = await this.waitForPreparedTxInclusion({
1030
+ tx,
1031
+ inclusionWaiter,
1032
+ responseTxHash: response.txHash,
1033
+ timeout: txTimeoutTimeInMilliSeconds
1034
+ });
947
1035
  walletStrategy.emit(WalletStrategyEmitterEventType.TransactionBroadcastEnd);
948
1036
  return confirmedTx;
949
1037
  } catch (e) {
@@ -1076,6 +1164,52 @@ var MsgBroadcaster = class {
1076
1164
  latestHeight: latestBlock.header.height.toString()
1077
1165
  };
1078
1166
  }
1167
+ resolveTimeoutInBlocks(override) {
1168
+ return typeof override === "number" && Number.isInteger(override) && override > 0 ? override : this.txTimeout;
1169
+ }
1170
+ resolveTxInclusionOptions(tx) {
1171
+ var _txInclusion$eventInc;
1172
+ const txInclusion = (tx === null || tx === void 0 ? void 0 : tx.txInclusion) || this.txInclusion;
1173
+ if (!txInclusion) return;
1174
+ return {
1175
+ ...txInclusion,
1176
+ eventInclusion: {
1177
+ ...txInclusion.eventInclusion,
1178
+ rpcEndpoint: ((_txInclusion$eventInc = txInclusion.eventInclusion) === null || _txInclusion$eventInc === void 0 ? void 0 : _txInclusion$eventInc.rpcEndpoint) || this.endpoints.rpc
1179
+ }
1180
+ };
1181
+ }
1182
+ createTxGrpcApi() {
1183
+ const client = new TxGrpcApi(this.endpoints.grpc);
1184
+ if (this.httpHeaders) client.setMetadata(this.httpHeaders);
1185
+ return client;
1186
+ }
1187
+ async waitForTxInclusion({ tx, txHash, timeout }) {
1188
+ return this.createTxGrpcApi().waitForTxInclusion({
1189
+ txHash,
1190
+ timeout,
1191
+ options: this.resolveTxInclusionOptions(tx)
1192
+ });
1193
+ }
1194
+ async prepareTxInclusionWaiter({ tx, timeout, txRawOrSignResponse }) {
1195
+ const txRaw = createTxRawFromSigResponse(txRawOrSignResponse);
1196
+ const txHash = TxClient.hash(txRaw);
1197
+ return this.createTxGrpcApi().prepareTxInclusionWait({
1198
+ txHash,
1199
+ timeout,
1200
+ options: this.resolveTxInclusionOptions(tx)
1201
+ });
1202
+ }
1203
+ async waitForPreparedTxInclusion({ tx, timeout, responseTxHash, inclusionWaiter }) {
1204
+ if (!inclusionWaiter) return this.waitForTxInclusion({
1205
+ tx,
1206
+ timeout,
1207
+ txHash: responseTxHash
1208
+ });
1209
+ const confirmedTx = await inclusionWaiter.wait(responseTxHash);
1210
+ if (!confirmedTx) throw new TransactionException(/* @__PURE__ */ new Error(`The transaction with ${responseTxHash} is not found`));
1211
+ return confirmedTx;
1212
+ }
1079
1213
  };
1080
1214
 
1081
1215
  //#endregion
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@injectivelabs/wallet-core",
3
- "version": "1.19.26",
3
+ "version": "1.19.28",
4
4
  "description": "Core wallet strategy",
5
5
  "license": "Apache-2.0",
6
6
  "author": {
@@ -44,12 +44,12 @@
44
44
  "dependencies": {
45
45
  "@keplr-wallet/types": "^0.12.296",
46
46
  "eventemitter3": "^5.0.1",
47
- "@injectivelabs/exceptions": "1.19.26",
48
- "@injectivelabs/sdk-ts": "1.19.26",
49
- "@injectivelabs/ts-types": "1.19.26",
50
- "@injectivelabs/utils": "1.19.26",
51
- "@injectivelabs/networks": "1.19.26",
52
- "@injectivelabs/wallet-base": "1.19.26"
47
+ "@injectivelabs/ts-types": "1.19.28",
48
+ "@injectivelabs/sdk-ts": "1.19.28",
49
+ "@injectivelabs/networks": "1.19.28",
50
+ "@injectivelabs/wallet-base": "1.19.28",
51
+ "@injectivelabs/exceptions": "1.19.28",
52
+ "@injectivelabs/utils": "1.19.28"
53
53
  },
54
54
  "publishConfig": {
55
55
  "access": "public"