@injectivelabs/sdk-ts 1.19.19 → 1.19.21

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.
@@ -6,7 +6,7 @@ import { t as BaseGrpcConsumer } from "./BaseGrpcConsumer-WvNC6PWw.js";
6
6
  import { t as IndexerGrpcWeb3GwApi } from "./IndexerGrpcWeb3GwApi-Bc5TEiq5.js";
7
7
  import * as CosmosTxV1Beta1TxPb from "@injectivelabs/core-proto-ts-v2/generated/cosmos/tx/v1beta1/tx_pb";
8
8
  import { keccak256 } from "viem";
9
- import { DEFAULT_BLOCK_TIMEOUT_HEIGHT, DEFAULT_BLOCK_TIME_IN_SECONDS, DEFAULT_TX_BLOCK_INCLUSION_TIMEOUT_IN_MS, HttpClient, getDefaultStdFee, getStdFee, getStdFeeFromString, sleep, toBigNumber } from "@injectivelabs/utils";
9
+ import { DEFAULT_BLOCK_TIMEOUT_HEIGHT, DEFAULT_BLOCK_TIME_IN_SECONDS, DEFAULT_TX_BLOCK_INCLUSION_TIMEOUT_IN_MS, DEFAULT_TX_POLL_CALL_TIMEOUT_MS, DEFAULT_TX_POLL_INTERVAL_MS, HttpClient, getDefaultStdFee, getStdFee, getStdFeeFromString, sleep, toBigNumber } from "@injectivelabs/utils";
10
10
  import { GeneralException, GrpcUnaryRequestException, HttpRequestException, HttpRequestMethod, TransactionException, UnspecifiedErrorCode } from "@injectivelabs/exceptions";
11
11
  import { Network, getNetworkEndpoints, getNetworkInfo } from "@injectivelabs/networks";
12
12
  import { StatusCodes } from "http-status-codes";
@@ -297,48 +297,36 @@ var TxGrpcApi = class extends BaseGrpcConsumer {
297
297
  }
298
298
  }
299
299
  async fetchTxPoll(txHash, timeout = DEFAULT_TX_BLOCK_INCLUSION_TIMEOUT_IN_MS) {
300
- const STAGGER = 300;
301
- const POLL_INTERVAL = 500;
302
- const CALL_TIMEOUT = 3e3;
303
300
  const deadline = Date.now() + timeout;
304
- while (Date.now() < deadline) {
305
- const start = Date.now();
306
- const result = await Promise.race([this.fetchTxDual(txHash, STAGGER), sleep(CALL_TIMEOUT).then(() => null)]);
307
- if (result) return result;
308
- const remaining = POLL_INTERVAL - (Date.now() - start);
309
- if (remaining > 0) await sleep(remaining);
301
+ for (let start = Date.now(); start < deadline; start = Date.now()) {
302
+ try {
303
+ const tx = await this.fetchTxDual(txHash, deadline);
304
+ if (tx) return tx;
305
+ } catch (e) {
306
+ if (e instanceof TransactionException) throw e;
307
+ }
308
+ const gap = DEFAULT_TX_POLL_INTERVAL_MS - (Date.now() - start);
309
+ if (gap > 0) await sleep(gap);
310
310
  }
311
311
  throw new GrpcUnaryRequestException(/* @__PURE__ */ new Error(`Transaction was not included in a block before timeout of ${timeout}ms`), {
312
312
  context: "TxGrpcApi",
313
313
  contextModule: "fetch-tx-poll"
314
314
  });
315
315
  }
316
- fetchTxDual(txHash, stagger) {
317
- return new Promise((resolve, reject) => {
318
- let pending = 2;
319
- let timerId;
320
- const onResult = (response) => {
321
- if (response) {
322
- clearTimeout(timerId);
323
- return resolve(response);
324
- }
325
- pending -= 1;
326
- if (pending === 0) resolve(null);
327
- };
328
- const onError = (e) => {
329
- if (e instanceof TransactionException) {
330
- clearTimeout(timerId);
331
- return reject(e);
332
- }
333
- pending -= 1;
334
- if (pending === 0) resolve(null);
335
- };
336
- this.fetchTx(txHash).then(onResult, onError);
337
- timerId = setTimeout(() => {
338
- this.fetchTx(txHash).then(onResult, onError);
339
- }, stagger);
316
+ async safeFetchTx(txHash, delay) {
317
+ if (delay) await sleep(delay);
318
+ return this.fetchTx(txHash).catch((e) => {
319
+ if (e instanceof TransactionException) throw e;
320
+ return null;
340
321
  });
341
322
  }
323
+ fetchTxDual(txHash, deadline) {
324
+ const STAGGER = 300;
325
+ const timeout = Math.max(0, Math.min(DEFAULT_TX_POLL_CALL_TIMEOUT_MS, deadline - Date.now()));
326
+ const fetches = Promise.all([this.safeFetchTx(txHash), this.safeFetchTx(txHash, STAGGER)]).then(([a, b]) => a !== null && a !== void 0 ? a : b);
327
+ fetches.catch(() => {});
328
+ return Promise.race([fetches, sleep(timeout).then(() => null)]);
329
+ }
342
330
  async simulate(txRaw) {
343
331
  const txRawClone = CosmosTxV1Beta1TxPb.TxRaw.create({ ...txRaw });
344
332
  const simulateRequest = CosmosTxV1Beta1ServicePb.SimulateRequest.create();
@@ -473,17 +461,16 @@ var TxRestApi = class {
473
461
  }
474
462
  }
475
463
  async fetchTxPoll(txHash, timeout = DEFAULT_TX_BLOCK_INCLUSION_TIMEOUT_IN_MS) {
476
- const POLL_INTERVAL = 500;
477
464
  const deadline = Date.now() + timeout;
478
- while (Date.now() < deadline) {
479
- const start = Date.now();
465
+ for (let start = Date.now(); start < deadline; start = Date.now()) {
466
+ const callTimeout = Math.max(0, Math.min(DEFAULT_TX_POLL_CALL_TIMEOUT_MS, deadline - Date.now()));
480
467
  try {
481
- const txResponse = await this.fetchTx(txHash);
468
+ const txResponse = await Promise.race([this.fetchTx(txHash), sleep(callTimeout).then(() => null)]);
482
469
  if (txResponse) return txResponse;
483
470
  } catch (e) {
484
471
  if (e instanceof TransactionException) throw e;
485
472
  }
486
- const remaining = POLL_INTERVAL - (Date.now() - start);
473
+ const remaining = DEFAULT_TX_POLL_INTERVAL_MS - (Date.now() - start);
487
474
  if (remaining > 0) await sleep(remaining);
488
475
  }
489
476
  throw new HttpRequestException(/* @__PURE__ */ new Error(`Transaction was not included in a block before timeout of ${timeout}ms`), {
@@ -1,6 +1,6 @@
1
1
  import "./tx_pb-DG9OU_HE.js";
2
2
  import "./index-DJtcTm1W.js";
3
- import { $d as derivativeMarginToChainMarginToFixed, $f as privateKeyToPublicKey, $u as fetchAllWithPagination, Ad as getChecksumAddress, Af as getErrorMessage, Bd as getSpotMarketDecimals, Bf as safeBigIntStringify, Cd as toBase64, Cf as spotQuantityFromChainQuantity, Dd as uint8ArrayToString, Df as bigIntReplacer, Ed as uint8ArrayToHex, Ef as spotQuantityToChainQuantityToFixed, Fd as getSubaccountId, Ff as isNode, Gd as denomAmountFromChainDenomAmountToFixed, Gf as TypedDataUtilsSanitizeData, Hd as amountToCosmosSdkDecAmount, Hf as sortObjectByKeysWithReduce, Id as isCw20ContractAddress, If as isReactNative, Jd as denomAmountToChainDenomAmountToFixed, Jf as domainHash, Kd as denomAmountFromGrpcChainDenomAmount, Kf as TypedMessageV4, Ld as removeHexPrefix, Lf as isServerSide, Md as getEthereumAddress, Mf as hexToNumber, Nd as getInjectiveAddress, Nf as isBrowser, Od as addHexPrefix, Of as bigIntToNumber, Pd as getInjectiveAddressFromSubaccountId, Pf as isJsonString, Qd as derivativeMarginToChainMargin, Qf as privateKeyHashToPublicKeyBase64, Qu as recoverTypedSignaturePubKey, Rd as getDerivativeMarketDecimals, Rf as objectToJson, Sd as stringToUint8Array, Sf as spotPriceToChainPriceToFixed, Td as uint8ArrayToBase64, Tf as spotQuantityToChainQuantity, Tx as GrpcWebFetchTransport, Ud as cosmosSdkDecToBigNumber, Uf as SignTypedDataVersionV4, Vd as getSpotMarketTensMultiplier, Vf as sortObjectByKeys, Wd as denomAmountFromChainDenomAmount, Wf as TypedDataUtilsHashStruct, Xd as derivativeMarginFromChainMargin, Xf as messageHash, Yd as denomAmountToGrpcChainDenomAmount, Yf as hashToHex, Zd as derivativeMarginFromChainMarginToFixed, Zf as privateKeyHashToPublicKey, _d as fromBase64, _f as isNumber, ad as paginationUint8ArrayToString, af as derivativeQuantityFromChainQuantityToFixed, ap as parseCoins, bd as hexToBuff, bf as spotPriceFromChainPriceToFixed, cd as BECH32_ADDR_VAL_PREFIX, cf as formatAmountToAllowableAmount, cp as getGasPriceBasedOnMessage, dd as BECH32_PUBKEY_VAL_PREFIX, df as formatNumberToAllowableTensMultiplier, dp as protobufTimestampToDate, ed as grpcPaginationToPagination, ef as derivativePriceFromChainPrice, ep as privateKeyToPublicKeyBase64, fd as DEFAULT_DERIVATION_PATH, ff as formatPriceToAllowableDecimals, fp as protobufTimestampToUnixMs, gd as concatUint8Arrays, gf as getTensMultiplier, hd as binaryToBase64, hf as getSignificantDecimalsFromNumber, id as paginationRequestFromPagination, if as derivativeQuantityFromChainQuantity, ip as sha256, jd as getDefaultSubaccountId, jf as grpcCoinToUiCoin, kd as getAddressFromInjectiveAddress, kf as bigIntToString, ld as BECH32_PUBKEY_ACC_PREFIX, lf as formatAmountToAllowableDecimals, lp as makeTimeoutTimestamp, md as base64ToUtf8, mf as getExactDecimalsFromNumber, nd as grpcPagingToPagingV2, nf as derivativePriceToChainPrice, np as ripemd160, od as BECH32_ADDR_ACC_PREFIX, of as derivativeQuantityToChainQuantity, op as ofacList, pd as base64ToUint8Array, pf as formatPriceToAllowablePrice, pp as protobufTimestampToUnixSeconds, qd as denomAmountToChainDenomAmount, qf as decompressPubKey, rd as pageRequestToGrpcPageRequestV2, rf as derivativePriceToChainPriceToFixed, rp as sanitizeTypedData, sd as BECH32_ADDR_CONS_PREFIX, sf as derivativeQuantityToChainQuantityToFixed, sp as getGrpcWebTransport, td as grpcPagingToPaging, tf as derivativePriceFromChainPriceToFixed, tp as publicKeyToAddress, ud as BECH32_PUBKEY_CONS_PREFIX, uf as formatNumberToAllowableDecimals, up as makeTimeoutTimestampInNs, vd as fromUtf8, vf as numberToCosmosSdkDecString, wd as toUtf8, wf as spotQuantityFromChainQuantityToFixed, xd as hexToUint8Array, xf as spotPriceToChainPrice, yd as hexToBase64, yf as spotPriceFromChainPrice, zd as getDerivativeMarketTensMultiplier, zf as protoObjectToJson } from "./index-Bq6CkYRk.js";
3
+ import { $d as derivativeMarginToChainMarginToFixed, $f as privateKeyToPublicKey, $u as fetchAllWithPagination, Ad as getChecksumAddress, Af as getErrorMessage, Bd as getSpotMarketDecimals, Bf as safeBigIntStringify, Cd as toBase64, Cf as spotQuantityFromChainQuantity, Dd as uint8ArrayToString, Df as bigIntReplacer, Ed as uint8ArrayToHex, Ef as spotQuantityToChainQuantityToFixed, Fd as getSubaccountId, Ff as isNode, Gd as denomAmountFromChainDenomAmountToFixed, Gf as TypedDataUtilsSanitizeData, Hd as amountToCosmosSdkDecAmount, Hf as sortObjectByKeysWithReduce, Id as isCw20ContractAddress, If as isReactNative, Jd as denomAmountToChainDenomAmountToFixed, Jf as domainHash, Kd as denomAmountFromGrpcChainDenomAmount, Kf as TypedMessageV4, Ld as removeHexPrefix, Lf as isServerSide, Md as getEthereumAddress, Mf as hexToNumber, Nd as getInjectiveAddress, Nf as isBrowser, Od as addHexPrefix, Of as bigIntToNumber, Pd as getInjectiveAddressFromSubaccountId, Pf as isJsonString, Qd as derivativeMarginToChainMargin, Qf as privateKeyHashToPublicKeyBase64, Qu as recoverTypedSignaturePubKey, Rd as getDerivativeMarketDecimals, Rf as objectToJson, Sd as stringToUint8Array, Sf as spotPriceToChainPriceToFixed, Td as uint8ArrayToBase64, Tf as spotQuantityToChainQuantity, Tx as GrpcWebFetchTransport, Ud as cosmosSdkDecToBigNumber, Uf as SignTypedDataVersionV4, Vd as getSpotMarketTensMultiplier, Vf as sortObjectByKeys, Wd as denomAmountFromChainDenomAmount, Wf as TypedDataUtilsHashStruct, Xd as derivativeMarginFromChainMargin, Xf as messageHash, Yd as denomAmountToGrpcChainDenomAmount, Yf as hashToHex, Zd as derivativeMarginFromChainMarginToFixed, Zf as privateKeyHashToPublicKey, _d as fromBase64, _f as isNumber, ad as paginationUint8ArrayToString, af as derivativeQuantityFromChainQuantityToFixed, ap as parseCoins, bd as hexToBuff, bf as spotPriceFromChainPriceToFixed, cd as BECH32_ADDR_VAL_PREFIX, cf as formatAmountToAllowableAmount, cp as getGasPriceBasedOnMessage, dd as BECH32_PUBKEY_VAL_PREFIX, df as formatNumberToAllowableTensMultiplier, dp as protobufTimestampToDate, ed as grpcPaginationToPagination, ef as derivativePriceFromChainPrice, ep as privateKeyToPublicKeyBase64, fd as DEFAULT_DERIVATION_PATH, ff as formatPriceToAllowableDecimals, fp as protobufTimestampToUnixMs, gd as concatUint8Arrays, gf as getTensMultiplier, hd as binaryToBase64, hf as getSignificantDecimalsFromNumber, id as paginationRequestFromPagination, if as derivativeQuantityFromChainQuantity, ip as sha256, jd as getDefaultSubaccountId, jf as grpcCoinToUiCoin, kd as getAddressFromInjectiveAddress, kf as bigIntToString, ld as BECH32_PUBKEY_ACC_PREFIX, lf as formatAmountToAllowableDecimals, lp as makeTimeoutTimestamp, md as base64ToUtf8, mf as getExactDecimalsFromNumber, nd as grpcPagingToPagingV2, nf as derivativePriceToChainPrice, np as ripemd160, od as BECH32_ADDR_ACC_PREFIX, of as derivativeQuantityToChainQuantity, op as ofacList, pd as base64ToUint8Array, pf as formatPriceToAllowablePrice, pp as protobufTimestampToUnixSeconds, qd as denomAmountToChainDenomAmount, qf as decompressPubKey, rd as pageRequestToGrpcPageRequestV2, rf as derivativePriceToChainPriceToFixed, rp as sanitizeTypedData, sd as BECH32_ADDR_CONS_PREFIX, sf as derivativeQuantityToChainQuantityToFixed, sp as getGrpcWebTransport, td as grpcPagingToPaging, tf as derivativePriceFromChainPriceToFixed, tp as publicKeyToAddress, ud as BECH32_PUBKEY_CONS_PREFIX, uf as formatNumberToAllowableDecimals, up as makeTimeoutTimestampInNs, vd as fromUtf8, vf as numberToCosmosSdkDecString, wd as toUtf8, wf as spotQuantityFromChainQuantityToFixed, xd as hexToUint8Array, xf as spotPriceToChainPrice, yd as hexToBase64, yf as spotPriceFromChainPrice, zd as getDerivativeMarketTensMultiplier, zf as protoObjectToJson } from "./index-hr6Kp1tq.js";
4
4
  import "./BaseGrpcConsumer-BptQBj1l.js";
5
5
  import "./index-BSAdUyzU.js";
6
6
  import "./index-sT17wTBx.js";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@injectivelabs/sdk-ts",
3
- "version": "1.19.19",
3
+ "version": "1.19.21",
4
4
  "description": "SDK in TypeScript for building Injective applications in a browser, node, and react native environment.",
5
5
  "license": "Apache-2.0",
6
6
  "author": {
@@ -351,10 +351,10 @@
351
351
  "rxjs": "7.8.2",
352
352
  "snakecase-keys": "^5.4.1",
353
353
  "viem": "^2.41.2",
354
- "@injectivelabs/exceptions": "1.19.19",
355
- "@injectivelabs/ts-types": "1.19.19",
356
- "@injectivelabs/networks": "1.19.19",
357
- "@injectivelabs/utils": "1.19.19"
354
+ "@injectivelabs/exceptions": "1.19.21",
355
+ "@injectivelabs/networks": "1.19.21",
356
+ "@injectivelabs/ts-types": "1.19.21",
357
+ "@injectivelabs/utils": "1.19.21"
358
358
  },
359
359
  "publishConfig": {
360
360
  "access": "public"