From d8c4486722c52a669b17ffe8875855e543f573e8 Mon Sep 17 00:00:00 2001 From: thomasRalee Date: Tue, 16 May 2023 18:53:40 +0200 Subject: [PATCH] feat: implement retries on grpc and rest query calls --- jest.config.js | 2 +- .../sdk-ts/src/client/BaseGrpcConsumer.ts | 64 +++--- .../src/client/BaseGrpcDmmWebConsumer.ts | 22 -- .../sdk-ts/src/client/BaseRestConsumer.ts | 25 ++- .../client/chain/grpc/ChainGrpcAuctionApi.ts | 27 ++- .../src/client/chain/grpc/ChainGrpcAuthApi.ts | 33 ++- .../src/client/chain/grpc/ChainGrpcBankApi.ts | 36 +++- .../chain/grpc/ChainGrpcDistributionApi.ts | 39 +++- .../client/chain/grpc/ChainGrpcExchangeApi.ts | 57 +++-- .../src/client/chain/grpc/ChainGrpcGovApi.ts | 41 ++-- .../src/client/chain/grpc/ChainGrpcIbcApi.ts | 20 +- .../chain/grpc/ChainGrpcInsuranceFundApi.ts | 37 +++- .../src/client/chain/grpc/ChainGrpcMintApi.ts | 31 ++- .../client/chain/grpc/ChainGrpcOracleApi.ts | 15 +- .../client/chain/grpc/ChainGrpcPeggyApi.ts | 17 +- .../client/chain/grpc/ChainGrpcStakingApi.ts | 101 ++++++--- .../src/client/chain/grpc/ChainGrpcWasmApi.ts | 54 +++-- .../client/chain/grpc/ChainGrpcWasmXApi.ts | 20 +- .../src/client/chain/rest/ChainRestAuthApi.ts | 13 +- .../src/client/chain/rest/ChainRestBankApi.ts | 12 +- .../chain/rest/ChainRestTendermintApi.ts | 12 +- .../sdk-ts/src/client/dmm/grpc/DmmGrpcApi.ts | 65 ++++-- .../indexer/grpc/IndexerGrpcAccountApi.ts | 48 +++-- .../indexer/grpc/IndexerGrpcAuctionApi.ts | 21 +- .../indexer/grpc/IndexerGrpcDerivativesApi.ts | 94 ++++++--- .../indexer/grpc/IndexerGrpcExplorerApi.ts | 54 +++-- .../grpc/IndexerGrpcInsuranceFundApi.ts | 21 +- .../client/indexer/grpc/IndexerGrpcMetaApi.ts | 22 +- .../client/indexer/grpc/IndexerGrpcMitoApi.ts | 54 +++-- .../indexer/grpc/IndexerGrpcOracleApi.ts | 24 ++- .../indexer/grpc/IndexerGrpcPortfolioApi.ts | 17 +- .../client/indexer/grpc/IndexerGrpcSpotApi.ts | 68 ++++-- .../rest/IndexerRestDerivativesChronosApi.ts | 20 +- .../indexer/rest/IndexerRestExplorerApi.ts | 195 ++++++++++-------- .../rest/IndexerRestLeaderboardChronosApi.ts | 8 +- .../rest/IndexerRestMarketChronosApi.ts | 6 +- .../indexer/rest/IndexerRestSpotChronosApi.ts | 18 +- 37 files changed, 946 insertions(+), 467 deletions(-) delete mode 100644 packages/sdk-ts/src/client/BaseGrpcDmmWebConsumer.ts diff --git a/jest.config.js b/jest.config.js index 369026ac1..9225d7dee 100644 --- a/jest.config.js +++ b/jest.config.js @@ -26,7 +26,7 @@ const directoryPaths = Object.keys(compilerOptions.paths).reduce( // https://jestjs.io/docs/en/configuration.html module.exports = { - testTimeout: 15000, + testTimeout: 30000, // All imported modules in your tests should be mocked automatically // automock: false, diff --git a/packages/sdk-ts/src/client/BaseGrpcConsumer.ts b/packages/sdk-ts/src/client/BaseGrpcConsumer.ts index ee658221d..db8ae3513 100644 --- a/packages/sdk-ts/src/client/BaseGrpcConsumer.ts +++ b/packages/sdk-ts/src/client/BaseGrpcConsumer.ts @@ -1,51 +1,45 @@ import { grpc } from '@injectivelabs/grpc-web' -import { GrpcUnaryRequestException } from '@injectivelabs/exceptions' import { isBrowser } from '../utils/helpers' import { getGrpcTransport } from '../utils/grpc' +import { InjectiveAccountRpc } from '@injectivelabs/indexer-proto-ts' if (!isBrowser()) { grpc.setDefaultTransport(getGrpcTransport() as grpc.TransportFactory) } -/** - * @hidden - */ -export default class BaseGrpcConsumer { - protected module: string = '' - protected endpoint: string +export default class BaseGrpcConsumer extends InjectiveAccountRpc.GrpcWebImpl { + protected module: string = '' constructor(endpoint: string) { - this.endpoint = endpoint + super(endpoint, { transport: getGrpcTransport() }) + } + + public getGrpcWebImpl(endpoint: string) { + return new BaseGrpcConsumer(endpoint) } - protected request< - TRequest extends grpc.ProtobufMessage, - TResponse extends grpc.ProtobufMessage, - S extends grpc.UnaryMethodDefinition, - >(request: TRequest, service: S): Promise { - return new Promise((resolve, reject) => { - grpc.unary(service, { - request, - host: this.endpoint, - onEnd: (res) => { - const { statusMessage, status, message } = res + protected retry( + grpcCall: Function, + retries: number = 3, + delay: number = 1000, + ): Promise { + const retryGrpcCall = async (attempt = 1): Promise => { + try { + return await grpcCall() + } catch (e: any) { + if (attempt >= retries) { + throw e + } - if (status === grpc.Code.OK && message) { - return resolve(message as TResponse) - } + return new Promise((resolve) => + setTimeout( + () => resolve(retryGrpcCall(attempt + 1)), + delay * attempt, + ), + ) + } + } - return reject( - new GrpcUnaryRequestException( - new Error(statusMessage || 'The request failed.'), - { - code: status, - context: `${this.endpoint}?service=${service.methodName}`, - contextModule: this.module, - }, - ), - ) - }, - }) - }) + return retryGrpcCall() } } diff --git a/packages/sdk-ts/src/client/BaseGrpcDmmWebConsumer.ts b/packages/sdk-ts/src/client/BaseGrpcDmmWebConsumer.ts deleted file mode 100644 index cf2a9c289..000000000 --- a/packages/sdk-ts/src/client/BaseGrpcDmmWebConsumer.ts +++ /dev/null @@ -1,22 +0,0 @@ -import { grpc } from '@injectivelabs/grpc-web' -import { isBrowser } from '../utils/helpers' -import { getGrpcTransport } from '../utils/grpc' -import { InjectiveDmmRpc } from '@injectivelabs/dmm-proto-ts' - -if (!isBrowser()) { - grpc.setDefaultTransport(getGrpcTransport() as grpc.TransportFactory) -} - -/** - * @hidden - */ -export default class BaseDmmGrpcWebConsumer extends InjectiveDmmRpc.GrpcWebImpl { - protected module: string = '' - - constructor(endpoint: string) { - super(endpoint, { transport: getGrpcTransport() }) - } -} - -export const getGrpcDmmWebImpl = (endpoint: string) => - new BaseDmmGrpcWebConsumer(endpoint) diff --git a/packages/sdk-ts/src/client/BaseRestConsumer.ts b/packages/sdk-ts/src/client/BaseRestConsumer.ts index c4b9a1ac6..6ab573416 100644 --- a/packages/sdk-ts/src/client/BaseRestConsumer.ts +++ b/packages/sdk-ts/src/client/BaseRestConsumer.ts @@ -4,5 +4,28 @@ import { HttpRestClient } from '@injectivelabs/utils' * @hidden */ export default class BaseRestConsumer extends HttpRestClient { - // + protected retry( + httpCall: Function, + retries: number = 3, + delay: number = 1000, + ): Promise { + const retryHttpCall = async (attempt = 1): Promise => { + try { + return (await httpCall()) as TResponse + } catch (e: any) { + if (attempt >= retries) { + throw e + } + + return new Promise((resolve) => + setTimeout( + () => resolve(retryHttpCall(attempt + 1)), + delay * attempt, + ), + ) + } + } + + return retryHttpCall() + } } diff --git a/packages/sdk-ts/src/client/chain/grpc/ChainGrpcAuctionApi.ts b/packages/sdk-ts/src/client/chain/grpc/ChainGrpcAuctionApi.ts index 2f2d4aa1b..d974b698b 100644 --- a/packages/sdk-ts/src/client/chain/grpc/ChainGrpcAuctionApi.ts +++ b/packages/sdk-ts/src/client/chain/grpc/ChainGrpcAuctionApi.ts @@ -1,23 +1,25 @@ -import { InjectiveAuctionV1Beta1Query } from '@injectivelabs/core-proto-ts' import { GrpcUnaryRequestException, UnspecifiedErrorCode, } from '@injectivelabs/exceptions' -import { getGrpcWebImpl } from '../../BaseGrpcWebConsumer' -import { ChainGrpcAuctionTransformer } from '../transformers' +import { InjectiveAuctionV1Beta1Query } from '@injectivelabs/core-proto-ts' +import BaseGrpcConsumer from '../../BaseGrpcConsumer' import { ChainModule } from '../types' +import { ChainGrpcAuctionTransformer } from '../transformers' /** * @category Chain Grpc API */ -export class ChainGrpcAuctionApi { +export class ChainGrpcAuctionApi extends BaseGrpcConsumer { protected module: string = ChainModule.Auction protected client: InjectiveAuctionV1Beta1Query.QueryClientImpl constructor(endpoint: string) { + super(endpoint) + this.client = new InjectiveAuctionV1Beta1Query.QueryClientImpl( - getGrpcWebImpl(endpoint), + this.getGrpcWebImpl(endpoint), ) } @@ -26,7 +28,10 @@ export class ChainGrpcAuctionApi { InjectiveAuctionV1Beta1Query.QueryAuctionParamsRequest.create() try { - const response = await this.client.AuctionParams(request) + const response = + await this.retry( + () => this.client.AuctionParams(request), + ) return ChainGrpcAuctionTransformer.moduleParamsResponseToModuleParams( response, @@ -53,7 +58,10 @@ export class ChainGrpcAuctionApi { InjectiveAuctionV1Beta1Query.QueryModuleStateRequest.create() try { - const response = await this.client.AuctionModuleState(request) + const response = + await this.retry( + () => this.client.AuctionModuleState(request), + ) return ChainGrpcAuctionTransformer.auctionModuleStateResponseToAuctionModuleState( response, @@ -80,7 +88,10 @@ export class ChainGrpcAuctionApi { InjectiveAuctionV1Beta1Query.QueryCurrentAuctionBasketRequest.create() try { - const response = await this.client.CurrentAuctionBasket(request) + const response = + await this.retry( + () => this.client.CurrentAuctionBasket(request), + ) return ChainGrpcAuctionTransformer.currentBasketResponseToCurrentBasket( response, diff --git a/packages/sdk-ts/src/client/chain/grpc/ChainGrpcAuthApi.ts b/packages/sdk-ts/src/client/chain/grpc/ChainGrpcAuthApi.ts index d96590141..9f59e5898 100644 --- a/packages/sdk-ts/src/client/chain/grpc/ChainGrpcAuthApi.ts +++ b/packages/sdk-ts/src/client/chain/grpc/ChainGrpcAuthApi.ts @@ -1,25 +1,27 @@ -import { CosmosAuthV1Beta1Query } from '@injectivelabs/core-proto-ts' -import { PaginationOption } from '../../../types/pagination' -import { paginationRequestFromPagination } from '../../../utils/pagination' -import { ChainGrpcAuthTransformer } from '../transformers/ChainGrpcAuthTransformer' -import { ChainModule } from '../types' import { GrpcUnaryRequestException, UnspecifiedErrorCode, } from '@injectivelabs/exceptions' -import { getGrpcWebImpl } from '../../BaseGrpcWebConsumer' +import { CosmosAuthV1Beta1Query } from '@injectivelabs/core-proto-ts' +import BaseGrpcConsumer from '../../BaseGrpcConsumer' +import { ChainModule } from '../types' +import { PaginationOption } from '../../../types/pagination' +import { paginationRequestFromPagination } from '../../../utils/pagination' +import { ChainGrpcAuthTransformer } from '../transformers/ChainGrpcAuthTransformer' /** * @category Chain Grpc API */ -export class ChainGrpcAuthApi { +export class ChainGrpcAuthApi extends BaseGrpcConsumer { protected module: string = ChainModule.Auth protected client: CosmosAuthV1Beta1Query.QueryClientImpl constructor(endpoint: string) { + super(endpoint) + this.client = new CosmosAuthV1Beta1Query.QueryClientImpl( - getGrpcWebImpl(endpoint), + this.getGrpcWebImpl(endpoint), ) } @@ -27,7 +29,10 @@ export class ChainGrpcAuthApi { const request = CosmosAuthV1Beta1Query.QueryParamsRequest.create() try { - const response = await this.client.Params(request) + const response = + await this.retry(() => + this.client.Params(request), + ) return ChainGrpcAuthTransformer.moduleParamsResponseToModuleParams( response, @@ -55,7 +60,10 @@ export class ChainGrpcAuthApi { request.address = address try { - const response = await this.client.Account(request) + const response = + await this.retry(() => + this.client.Account(request), + ) return ChainGrpcAuthTransformer.accountResponseToAccount(response) } catch (e: unknown) { @@ -84,7 +92,10 @@ export class ChainGrpcAuthApi { } try { - const response = await this.client.Accounts(request) + const response = + await this.retry(() => + this.client.Accounts(request), + ) return ChainGrpcAuthTransformer.accountsResponseToAccounts(response) } catch (e: unknown) { diff --git a/packages/sdk-ts/src/client/chain/grpc/ChainGrpcBankApi.ts b/packages/sdk-ts/src/client/chain/grpc/ChainGrpcBankApi.ts index 5e53136ab..2b90a89d2 100644 --- a/packages/sdk-ts/src/client/chain/grpc/ChainGrpcBankApi.ts +++ b/packages/sdk-ts/src/client/chain/grpc/ChainGrpcBankApi.ts @@ -1,25 +1,27 @@ -import { getGrpcWebImpl } from '../../BaseGrpcWebConsumer' -import { PaginationOption } from '../../../types/pagination' -import { paginationRequestFromPagination } from '../../../utils/pagination' -import { ChainGrpcBankTransformer } from '../transformers' import { GrpcUnaryRequestException, UnspecifiedErrorCode, } from '@injectivelabs/exceptions' -import { ChainModule } from '../types' import { CosmosBankV1Beta1Query } from '@injectivelabs/core-proto-ts' +import BaseGrpcConsumer from '../../BaseGrpcConsumer' +import { ChainModule } from '../types' +import { ChainGrpcBankTransformer } from '../transformers' +import { PaginationOption } from '../../../types/pagination' +import { paginationRequestFromPagination } from '../../../utils/pagination' /** * @category Chain Grpc API */ -export class ChainGrpcBankApi { +export class ChainGrpcBankApi extends BaseGrpcConsumer { protected module: string = ChainModule.Bank protected client: CosmosBankV1Beta1Query.QueryClientImpl constructor(endpoint: string) { + super(endpoint) + this.client = new CosmosBankV1Beta1Query.QueryClientImpl( - getGrpcWebImpl(endpoint), + this.getGrpcWebImpl(endpoint), ) } @@ -27,7 +29,10 @@ export class ChainGrpcBankApi { const request = CosmosBankV1Beta1Query.QueryParamsRequest.create() try { - const response = await this.client.Params(request) + const response = + await this.retry(() => + this.client.Params(request), + ) return ChainGrpcBankTransformer.moduleParamsResponseToModuleParams( response, @@ -62,7 +67,10 @@ export class ChainGrpcBankApi { request.denom = denom try { - const response = await this.client.Balance(request) + const response = + await this.retry(() => + this.client.Balance(request), + ) return ChainGrpcBankTransformer.balanceResponseToBalance(response) } catch (e: unknown) { @@ -88,7 +96,10 @@ export class ChainGrpcBankApi { request.address = address try { - const response = await this.client.AllBalances(request) + const response = + await this.retry(() => + this.client.AllBalances(request), + ) return ChainGrpcBankTransformer.balancesResponseToBalances(response) } catch (e: unknown) { @@ -117,7 +128,10 @@ export class ChainGrpcBankApi { } try { - const response = await this.client.TotalSupply(request) + const response = + await this.retry(() => + this.client.TotalSupply(request), + ) return ChainGrpcBankTransformer.totalSupplyResponseToTotalSupply(response) } catch (e: unknown) { diff --git a/packages/sdk-ts/src/client/chain/grpc/ChainGrpcDistributionApi.ts b/packages/sdk-ts/src/client/chain/grpc/ChainGrpcDistributionApi.ts index c236ae76d..26a01ed18 100644 --- a/packages/sdk-ts/src/client/chain/grpc/ChainGrpcDistributionApi.ts +++ b/packages/sdk-ts/src/client/chain/grpc/ChainGrpcDistributionApi.ts @@ -1,24 +1,26 @@ -import { Coin } from '@injectivelabs/ts-types' -import { ChainGrpcDistributionTransformer } from '../transformers' -import { ValidatorRewards, ChainModule } from '../types' import { GrpcUnaryRequestException, UnspecifiedErrorCode, } from '@injectivelabs/exceptions' -import { getGrpcWebImpl } from '../../BaseGrpcWebConsumer' +import { Coin } from '@injectivelabs/ts-types' import { CosmosDistributionV1Beta1Query } from '@injectivelabs/core-proto-ts' +import BaseGrpcConsumer from '../../BaseGrpcConsumer' +import { ValidatorRewards, ChainModule } from '../types' +import { ChainGrpcDistributionTransformer } from '../transformers' /** * @category Chain Grpc API */ -export class ChainGrpcDistributionApi { +export class ChainGrpcDistributionApi extends BaseGrpcConsumer { protected module: string = ChainModule.Distribution protected client: CosmosDistributionV1Beta1Query.QueryClientImpl constructor(endpoint: string) { + super(endpoint) + this.client = new CosmosDistributionV1Beta1Query.QueryClientImpl( - getGrpcWebImpl(endpoint), + this.getGrpcWebImpl(endpoint), ) } @@ -26,7 +28,10 @@ export class ChainGrpcDistributionApi { const request = CosmosDistributionV1Beta1Query.QueryParamsRequest.create() try { - const response = await this.client.Params(request) + const response = + await this.retry( + () => this.client.Params(request), + ) return ChainGrpcDistributionTransformer.moduleParamsResponseToModuleParams( response, @@ -62,7 +67,10 @@ export class ChainGrpcDistributionApi { request.delegatorAddress = delegatorAddress try { - const response = await this.client.DelegationRewards(request) + const response = + await this.retry( + () => this.client.DelegationRewards(request), + ) return ChainGrpcDistributionTransformer.delegationRewardResponseToReward( response, @@ -98,7 +106,10 @@ export class ChainGrpcDistributionApi { request.delegatorAddress = delegatorAddress try { - const response = await this.client.DelegationRewards(request) + const response = + await this.retry( + () => this.client.DelegationRewards(request), + ) return ChainGrpcDistributionTransformer.delegationRewardResponseToReward( response, @@ -131,7 +142,10 @@ export class ChainGrpcDistributionApi { request.delegatorAddress = injectiveAddress try { - const response = await this.client.DelegationTotalRewards(request) + const response = + await this.retry( + () => this.client.DelegationTotalRewards(request), + ) return ChainGrpcDistributionTransformer.totalDelegationRewardResponseToTotalReward( response, @@ -160,7 +174,10 @@ export class ChainGrpcDistributionApi { request.delegatorAddress = injectiveAddress try { - const response = await this.client.DelegationTotalRewards(request) + const response = + await this.retry( + () => this.client.DelegationTotalRewards(request), + ) return ChainGrpcDistributionTransformer.totalDelegationRewardResponseToTotalReward( response, diff --git a/packages/sdk-ts/src/client/chain/grpc/ChainGrpcExchangeApi.ts b/packages/sdk-ts/src/client/chain/grpc/ChainGrpcExchangeApi.ts index 132426321..e1f3a71f1 100644 --- a/packages/sdk-ts/src/client/chain/grpc/ChainGrpcExchangeApi.ts +++ b/packages/sdk-ts/src/client/chain/grpc/ChainGrpcExchangeApi.ts @@ -1,25 +1,27 @@ -import { ChainGrpcExchangeTransformer } from '../transformers' -import { ChainModule } from '../types' import { GrpcUnaryRequestException, UnspecifiedErrorCode, } from '@injectivelabs/exceptions' -import { getGrpcWebImpl } from '../../BaseGrpcWebConsumer' import { InjectiveExchangeV1Beta1Query } from '@injectivelabs/core-proto-ts' +import BaseGrpcConsumer from '../../BaseGrpcConsumer' +import { ChainModule } from '../types' +import { ChainGrpcExchangeTransformer } from '../transformers' InjectiveExchangeV1Beta1Query /** * @category Chain Grpc API */ -export class ChainGrpcExchangeApi { +export class ChainGrpcExchangeApi extends BaseGrpcConsumer { protected module: string = ChainModule.Exchange protected client: InjectiveExchangeV1Beta1Query.QueryClientImpl constructor(endpoint: string) { + super(endpoint) + this.client = new InjectiveExchangeV1Beta1Query.QueryClientImpl( - getGrpcWebImpl(endpoint), + this.getGrpcWebImpl(endpoint), ) } @@ -28,7 +30,10 @@ export class ChainGrpcExchangeApi { InjectiveExchangeV1Beta1Query.QueryExchangeParamsRequest.create() try { - const response = await this.client.QueryExchangeParams(request) + const response = + await this.retry( + () => this.client.QueryExchangeParams(request), + ) return ChainGrpcExchangeTransformer.moduleParamsResponseToParams(response) } catch (e: any) { @@ -53,7 +58,10 @@ export class ChainGrpcExchangeApi { InjectiveExchangeV1Beta1Query.QueryModuleStateRequest.create() try { - const response = await this.client.ExchangeModuleState(request) + const response = + await this.retry( + () => this.client.ExchangeModuleState(request), + ) return response.state! } catch (e: any) { @@ -78,7 +86,10 @@ export class ChainGrpcExchangeApi { InjectiveExchangeV1Beta1Query.QueryFeeDiscountScheduleRequest.create() try { - const response = await this.client.FeeDiscountSchedule(request) + const response = + await this.retry( + () => this.client.FeeDiscountSchedule(request), + ) return ChainGrpcExchangeTransformer.feeDiscountScheduleResponseToFeeDiscountSchedule( response, @@ -108,7 +119,10 @@ export class ChainGrpcExchangeApi { request.account = injectiveAddress try { - const response = await this.client.FeeDiscountAccountInfo(request) + const response = + await this.retry( + () => this.client.FeeDiscountAccountInfo(request), + ) return ChainGrpcExchangeTransformer.feeDiscountAccountInfoResponseToFeeDiscountAccountInfo( response, @@ -135,7 +149,10 @@ export class ChainGrpcExchangeApi { InjectiveExchangeV1Beta1Query.QueryTradeRewardCampaignRequest.create() try { - const response = await this.client.TradeRewardCampaign(request) + const response = + await this.retry( + () => this.client.TradeRewardCampaign(request), + ) return ChainGrpcExchangeTransformer.tradingRewardsCampaignResponseToTradingRewardsCampaign( response, @@ -164,7 +181,10 @@ export class ChainGrpcExchangeApi { request.accounts = injectiveAddresses try { - const response = await this.client.TradeRewardPoints(request) + const response = + await this.retry( + () => this.client.TradeRewardPoints(request), + ) return response.accountTradeRewardPoints } catch (e: any) { @@ -198,7 +218,10 @@ export class ChainGrpcExchangeApi { } try { - const response = await this.client.PendingTradeRewardPoints(request) + const response = + await this.retry( + () => this.client.PendingTradeRewardPoints(request), + ) return response.accountTradeRewardPoints } catch (e: any) { @@ -222,7 +245,10 @@ export class ChainGrpcExchangeApi { const request = InjectiveExchangeV1Beta1Query.QueryPositionsRequest.create() try { - const response = await this.client.Positions(request) + const response = + await this.retry( + () => this.client.Positions(request), + ) return ChainGrpcExchangeTransformer.positionsResponseToPositions(response) } catch (e: any) { @@ -249,7 +275,10 @@ export class ChainGrpcExchangeApi { request.subaccountId = subaccountId try { - const response = await this.client.SubaccountTradeNonce(request) + const response = + await this.retry( + () => this.client.SubaccountTradeNonce(request), + ) return response } catch (e: any) { diff --git a/packages/sdk-ts/src/client/chain/grpc/ChainGrpcGovApi.ts b/packages/sdk-ts/src/client/chain/grpc/ChainGrpcGovApi.ts index 430af4f5d..1e3af73de 100644 --- a/packages/sdk-ts/src/client/chain/grpc/ChainGrpcGovApi.ts +++ b/packages/sdk-ts/src/client/chain/grpc/ChainGrpcGovApi.ts @@ -1,28 +1,30 @@ -import { PaginationOption } from '../../../types/pagination' -import { paginationRequestFromPagination } from '../../../utils/pagination' -import { ChainGrpcGovTransformer } from '../transformers/ChainGrpcGovTransformer' -import { ChainModule } from '../types' import { GrpcUnaryRequestException, UnspecifiedErrorCode, } from '@injectivelabs/exceptions' -import { getGrpcWebImpl } from '../../BaseGrpcWebConsumer' import { CosmosGovV1Beta1Query, CosmosGovV1Beta1Gov, } from '@injectivelabs/core-proto-ts' +import BaseGrpcConsumer from '../../BaseGrpcConsumer' +import { ChainModule } from '../types' +import { PaginationOption } from '../../../types/pagination' +import { paginationRequestFromPagination } from '../../../utils/pagination' +import { ChainGrpcGovTransformer } from '../transformers/ChainGrpcGovTransformer' /** * @category Chain Grpc API */ -export class ChainGrpcGovApi { +export class ChainGrpcGovApi extends BaseGrpcConsumer { protected module: string = ChainModule.Gov protected client: CosmosGovV1Beta1Query.QueryClientImpl constructor(endpoint: string) { + super(endpoint) + this.client = new CosmosGovV1Beta1Query.QueryClientImpl( - getGrpcWebImpl(endpoint), + this.getGrpcWebImpl(endpoint), ) } @@ -81,7 +83,10 @@ export class ChainGrpcGovApi { } try { - const response = await this.client.Proposals(request) + const response = + await this.retry(() => + this.client.Proposals(request), + ) return ChainGrpcGovTransformer.proposalsResponseToProposals(response) } catch (e: any) { @@ -107,7 +112,10 @@ export class ChainGrpcGovApi { request.proposalId = proposalId.toString() try { - const response = await this.client.Proposal(request) + const response = + await this.retry(() => + this.client.Proposal(request), + ) return ChainGrpcGovTransformer.proposalResponseToProposal(response) } catch (e: any) { @@ -145,7 +153,10 @@ export class ChainGrpcGovApi { } try { - const response = await this.client.Deposits(request) + const response = + await this.retry(() => + this.client.Deposits(request), + ) return ChainGrpcGovTransformer.depositsResponseToDeposits(response) } catch (e: any) { @@ -182,7 +193,10 @@ export class ChainGrpcGovApi { request.pagination = paginationForRequest } try { - const response = await this.client.Votes(request) + const response = + await this.retry(() => + this.client.Votes(request), + ) return ChainGrpcGovTransformer.votesResponseToVotes(response) } catch (e: any) { @@ -207,7 +221,10 @@ export class ChainGrpcGovApi { request.proposalId = proposalId.toString() try { - const response = await this.client.TallyResult(request) + const response = + await this.retry(() => + this.client.TallyResult(request), + ) return ChainGrpcGovTransformer.tallyResultResponseToTallyResult(response) } catch (e: any) { diff --git a/packages/sdk-ts/src/client/chain/grpc/ChainGrpcIbcApi.ts b/packages/sdk-ts/src/client/chain/grpc/ChainGrpcIbcApi.ts index de7488e89..b7f0af908 100644 --- a/packages/sdk-ts/src/client/chain/grpc/ChainGrpcIbcApi.ts +++ b/packages/sdk-ts/src/client/chain/grpc/ChainGrpcIbcApi.ts @@ -1,22 +1,24 @@ -import { getGrpcWebImpl } from '../../BaseGrpcWebConsumer' -import { ChainModule } from '../types' import { GrpcUnaryRequestException, UnspecifiedErrorCode, } from '@injectivelabs/exceptions' import { IbcApplicationsTransferV1Query } from '@injectivelabs/core-proto-ts' +import BaseGrpcConsumer from '../../BaseGrpcConsumer' +import { ChainModule } from '../types' /** * @category Chain Grpc API */ -export class ChainGrpcIbcApi { +export class ChainGrpcIbcApi extends BaseGrpcConsumer { protected module: string = ChainModule.Ibc protected client: IbcApplicationsTransferV1Query.QueryClientImpl constructor(endpoint: string) { + super(endpoint) + this.client = new IbcApplicationsTransferV1Query.QueryClientImpl( - getGrpcWebImpl(endpoint), + this.getGrpcWebImpl(endpoint), ) } @@ -27,7 +29,10 @@ export class ChainGrpcIbcApi { request.hash = hash try { - const response = await this.client.DenomTrace(request) + const response = + await this.retry( + () => this.client.DenomTrace(request), + ) return response.denomTrace! } catch (e: any) { @@ -52,7 +57,10 @@ export class ChainGrpcIbcApi { IbcApplicationsTransferV1Query.QueryDenomTracesRequest.create() try { - const response = await this.client.DenomTraces(request) + const response = + await this.retry( + () => this.client.DenomTraces(request), + ) return response.denomTraces } catch (e: any) { diff --git a/packages/sdk-ts/src/client/chain/grpc/ChainGrpcInsuranceFundApi.ts b/packages/sdk-ts/src/client/chain/grpc/ChainGrpcInsuranceFundApi.ts index e28b0e551..bf50b44bc 100644 --- a/packages/sdk-ts/src/client/chain/grpc/ChainGrpcInsuranceFundApi.ts +++ b/packages/sdk-ts/src/client/chain/grpc/ChainGrpcInsuranceFundApi.ts @@ -1,23 +1,25 @@ -import { getGrpcWebImpl } from '../../BaseGrpcWebConsumer' -import { ChainGrpcInsuranceFundTransformer } from '../transformers/ChainGrpcInsuranceFundTransformer' -import { ChainModule } from '../types' import { GrpcUnaryRequestException, UnspecifiedErrorCode, } from '@injectivelabs/exceptions' import { InjectiveInsuranceV1Beta1Query } from '@injectivelabs/core-proto-ts' +import BaseGrpcConsumer from '../../BaseGrpcConsumer' +import { ChainModule } from '../types' +import { ChainGrpcInsuranceFundTransformer } from '../transformers/ChainGrpcInsuranceFundTransformer' /** * @category Chain Grpc API */ -export class ChainGrpcInsuranceFundApi { +export class ChainGrpcInsuranceFundApi extends BaseGrpcConsumer { protected module: string = ChainModule.InsuranceFund protected client: InjectiveInsuranceV1Beta1Query.QueryClientImpl constructor(endpoint: string) { + super(endpoint) + this.client = new InjectiveInsuranceV1Beta1Query.QueryClientImpl( - getGrpcWebImpl(endpoint), + this.getGrpcWebImpl(endpoint), ) } @@ -26,7 +28,10 @@ export class ChainGrpcInsuranceFundApi { InjectiveInsuranceV1Beta1Query.QueryInsuranceParamsRequest.create() try { - const response = await this.client.InsuranceParams(request) + const response = + await this.retry( + () => this.client.InsuranceParams(request), + ) return ChainGrpcInsuranceFundTransformer.moduleParamsResponseToModuleParams( response, @@ -53,7 +58,10 @@ export class ChainGrpcInsuranceFundApi { InjectiveInsuranceV1Beta1Query.QueryInsuranceFundsRequest.create() try { - const response = await this.client.InsuranceFunds(request) + const response = + await this.retry( + () => this.client.InsuranceFunds(request), + ) return ChainGrpcInsuranceFundTransformer.insuranceFundsResponseToInsuranceFunds( response, @@ -82,7 +90,10 @@ export class ChainGrpcInsuranceFundApi { request.marketId = marketId try { - const response = await this.client.InsuranceFund(request) + const response = + await this.retry( + () => this.client.InsuranceFund(request), + ) return ChainGrpcInsuranceFundTransformer.insuranceFundResponseToInsuranceFund( response, @@ -118,7 +129,10 @@ export class ChainGrpcInsuranceFundApi { request.address = address try { - const response = await this.client.EstimatedRedemptions(request) + const response = + await this.retry( + () => this.client.EstimatedRedemptions(request), + ) return ChainGrpcInsuranceFundTransformer.estimatedRedemptionsResponseToEstimatedRedemptions( response, @@ -154,7 +168,10 @@ export class ChainGrpcInsuranceFundApi { request.address = address try { - const response = await this.client.PendingRedemptions(request) + const response = + await this.retry( + () => this.client.PendingRedemptions(request), + ) return ChainGrpcInsuranceFundTransformer.redemptionsResponseToRedemptions( response, diff --git a/packages/sdk-ts/src/client/chain/grpc/ChainGrpcMintApi.ts b/packages/sdk-ts/src/client/chain/grpc/ChainGrpcMintApi.ts index 54ca40a7c..6dd94cce9 100644 --- a/packages/sdk-ts/src/client/chain/grpc/ChainGrpcMintApi.ts +++ b/packages/sdk-ts/src/client/chain/grpc/ChainGrpcMintApi.ts @@ -1,25 +1,27 @@ -import { getGrpcWebImpl } from '../../BaseGrpcWebConsumer' -import { cosmosSdkDecToBigNumber, uint8ArrayToString } from '../../../utils' -import { BigNumberInBase } from '@injectivelabs/utils' -import { ChainGrpcMintTransformer } from './../transformers/ChainGrpcMintTransformer' -import { ChainModule } from '../types' import { GrpcUnaryRequestException, UnspecifiedErrorCode, } from '@injectivelabs/exceptions' import { CosmosMintV1Beta1Query } from '@injectivelabs/core-proto-ts' +import { cosmosSdkDecToBigNumber, uint8ArrayToString } from '../../../utils' +import { BigNumberInBase } from '@injectivelabs/utils' +import { ChainGrpcMintTransformer } from './../transformers/ChainGrpcMintTransformer' +import { ChainModule } from '../types' +import BaseGrpcConsumer from '../../BaseGrpcConsumer' /** * @category Chain Grpc API */ -export class ChainGrpcMintApi { +export class ChainGrpcMintApi extends BaseGrpcConsumer { protected module: string = ChainModule.Mint protected client: CosmosMintV1Beta1Query.QueryClientImpl constructor(endpoint: string) { + super(endpoint) + this.client = new CosmosMintV1Beta1Query.QueryClientImpl( - getGrpcWebImpl(endpoint), + this.getGrpcWebImpl(endpoint), ) } @@ -27,7 +29,10 @@ export class ChainGrpcMintApi { const request = CosmosMintV1Beta1Query.QueryParamsRequest.create() try { - const response = await this.client.Params(request) + const response = + await this.retry(() => + this.client.Params(request), + ) return ChainGrpcMintTransformer.moduleParamsResponseToModuleParams( response, @@ -53,7 +58,10 @@ export class ChainGrpcMintApi { const request = CosmosMintV1Beta1Query.QueryInflationRequest.create() try { - const response = await this.client.Inflation(request) + const response = + await this.retry(() => + this.client.Inflation(request), + ) return { inflation: cosmosSdkDecToBigNumber( @@ -81,7 +89,10 @@ export class ChainGrpcMintApi { const request = CosmosMintV1Beta1Query.QueryAnnualProvisionsRequest.create() try { - const response = await this.client.AnnualProvisions(request) + const response = + await this.retry( + () => this.client.AnnualProvisions(request), + ) return { annualProvisions: cosmosSdkDecToBigNumber( diff --git a/packages/sdk-ts/src/client/chain/grpc/ChainGrpcOracleApi.ts b/packages/sdk-ts/src/client/chain/grpc/ChainGrpcOracleApi.ts index a2f3e4d75..5c8631747 100644 --- a/packages/sdk-ts/src/client/chain/grpc/ChainGrpcOracleApi.ts +++ b/packages/sdk-ts/src/client/chain/grpc/ChainGrpcOracleApi.ts @@ -1,22 +1,24 @@ -import { ChainModule, OracleModuleParams } from '../types' import { GrpcUnaryRequestException, UnspecifiedErrorCode, } from '@injectivelabs/exceptions' -import { getGrpcWebImpl } from '../../BaseGrpcWebConsumer' import { InjectiveOracleV1Beta1Query } from '@injectivelabs/core-proto-ts' +import BaseGrpcConsumer from '../../BaseGrpcConsumer' +import { ChainModule, OracleModuleParams } from '../types' /** * @category Chain Grpc API */ -export class ChainGrpcOracleApi { +export class ChainGrpcOracleApi extends BaseGrpcConsumer { protected module: string = ChainModule.Oracle protected client: InjectiveOracleV1Beta1Query.QueryClientImpl constructor(endpoint: string) { + super(endpoint) + this.client = new InjectiveOracleV1Beta1Query.QueryClientImpl( - getGrpcWebImpl(endpoint), + this.getGrpcWebImpl(endpoint), ) } @@ -24,7 +26,10 @@ export class ChainGrpcOracleApi { const request = InjectiveOracleV1Beta1Query.QueryParamsRequest.create() try { - const response = await this.client.Params(request) + const response = + await this.retry(() => + this.client.Params(request), + ) return response.params as OracleModuleParams } catch (e: unknown) { diff --git a/packages/sdk-ts/src/client/chain/grpc/ChainGrpcPeggyApi.ts b/packages/sdk-ts/src/client/chain/grpc/ChainGrpcPeggyApi.ts index 52b38abc1..e4bc7904e 100644 --- a/packages/sdk-ts/src/client/chain/grpc/ChainGrpcPeggyApi.ts +++ b/packages/sdk-ts/src/client/chain/grpc/ChainGrpcPeggyApi.ts @@ -1,23 +1,25 @@ -import { ChainGrpcPeggyTransformer } from '../transformers' -import { ChainModule } from '../types' import { GrpcUnaryRequestException, UnspecifiedErrorCode, } from '@injectivelabs/exceptions' -import { getGrpcWebImpl } from '../../BaseGrpcWebConsumer' import { InjectivePeggyV1Beta1Query } from '@injectivelabs/core-proto-ts' +import BaseGrpcConsumer from '../../BaseGrpcConsumer' +import { ChainModule } from '../types' +import { ChainGrpcPeggyTransformer } from '../transformers' /** * @category Chain Grpc API */ -export class ChainGrpcPeggyApi { +export class ChainGrpcPeggyApi extends BaseGrpcConsumer { protected module: string = ChainModule.Peggy protected client: InjectivePeggyV1Beta1Query.QueryClientImpl constructor(endpoint: string) { + super(endpoint) + this.client = new InjectivePeggyV1Beta1Query.QueryClientImpl( - getGrpcWebImpl(endpoint), + this.getGrpcWebImpl(endpoint), ) } @@ -25,7 +27,10 @@ export class ChainGrpcPeggyApi { const request = InjectivePeggyV1Beta1Query.QueryParamsRequest.create() try { - const response = await this.client.Params(request) + const response = + await this.retry(() => + this.client.Params(request), + ) return ChainGrpcPeggyTransformer.moduleParamsResponseToModuleParams( response, diff --git a/packages/sdk-ts/src/client/chain/grpc/ChainGrpcStakingApi.ts b/packages/sdk-ts/src/client/chain/grpc/ChainGrpcStakingApi.ts index 1ac1f6f8c..16cc97112 100644 --- a/packages/sdk-ts/src/client/chain/grpc/ChainGrpcStakingApi.ts +++ b/packages/sdk-ts/src/client/chain/grpc/ChainGrpcStakingApi.ts @@ -1,25 +1,27 @@ -import { getGrpcWebImpl } from '../../BaseGrpcWebConsumer' -import { PaginationOption } from '../../../types/pagination' -import { paginationRequestFromPagination } from '../../../utils/pagination' -import { ChainGrpcStakingTransformer } from '../transformers' -import { ChainModule } from '../types' import { GrpcUnaryRequestException, UnspecifiedErrorCode, } from '@injectivelabs/exceptions' import { CosmosStakingV1Beta1Query } from '@injectivelabs/core-proto-ts' +import BaseGrpcConsumer from '../../BaseGrpcConsumer' +import { ChainModule } from '../types' +import { PaginationOption } from '../../../types/pagination' +import { ChainGrpcStakingTransformer } from '../transformers' +import { paginationRequestFromPagination } from '../../../utils/pagination' /** * @category Chain Grpc API */ -export class ChainGrpcStakingApi { +export class ChainGrpcStakingApi extends BaseGrpcConsumer { protected module: string = ChainModule.Staking protected client: CosmosStakingV1Beta1Query.QueryClientImpl constructor(endpoint: string) { + super(endpoint) + this.client = new CosmosStakingV1Beta1Query.QueryClientImpl( - getGrpcWebImpl(endpoint), + this.getGrpcWebImpl(endpoint), ) } @@ -27,7 +29,10 @@ export class ChainGrpcStakingApi { const request = CosmosStakingV1Beta1Query.QueryParamsRequest.create() try { - const response = await this.client.Params(request) + const response = + await this.retry(() => + this.client.Params(request), + ) return ChainGrpcStakingTransformer.moduleParamsResponseToModuleParams( response, @@ -53,7 +58,10 @@ export class ChainGrpcStakingApi { const request = CosmosStakingV1Beta1Query.QueryPoolRequest.create() try { - const response = await this.client.Pool(request) + const response = + await this.retry(() => + this.client.Pool(request), + ) return ChainGrpcStakingTransformer.poolResponseToPool(response) } catch (e: unknown) { @@ -83,7 +91,10 @@ export class ChainGrpcStakingApi { } try { - const response = await this.client.Validators(request) + const response = + await this.retry( + () => this.client.Validators(request), + ) return ChainGrpcStakingTransformer.validatorsResponseToValidators( response, @@ -111,7 +122,10 @@ export class ChainGrpcStakingApi { request.validatorAddr = address try { - const response = await this.client.Validator(request) + const response = + await this.retry(() => + this.client.Validator(request), + ) return ChainGrpcStakingTransformer.validatorResponseToValidator(response) } catch (e: unknown) { @@ -150,7 +164,10 @@ export class ChainGrpcStakingApi { } try { - const response = await this.client.ValidatorDelegations(request) + const response = + await this.retry( + () => this.client.ValidatorDelegations(request), + ) return ChainGrpcStakingTransformer.delegationsResponseToDelegations( response, @@ -191,7 +208,10 @@ export class ChainGrpcStakingApi { } try { - const response = await this.client.ValidatorDelegations(request) + const response = + await this.retry( + () => this.client.ValidatorDelegations(request), + ) return ChainGrpcStakingTransformer.delegationsResponseToDelegations( response, @@ -236,7 +256,10 @@ export class ChainGrpcStakingApi { } try { - const response = await this.client.ValidatorUnbondingDelegations(request) + const response = + await this.retry( + () => this.client.ValidatorUnbondingDelegations(request), + ) return ChainGrpcStakingTransformer.unBondingDelegationsResponseToUnBondingDelegations( response, @@ -277,7 +300,10 @@ export class ChainGrpcStakingApi { } try { - const response = await this.client.ValidatorUnbondingDelegations(request) + const response = + await this.retry( + () => this.client.ValidatorUnbondingDelegations(request), + ) return ChainGrpcStakingTransformer.unBondingDelegationsResponseToUnBondingDelegations( response, @@ -316,7 +342,10 @@ export class ChainGrpcStakingApi { request.validatorAddr = validatorAddress try { - const response = await this.client.Delegation(request) + const response = + await this.retry( + () => this.client.Delegation(request), + ) return ChainGrpcStakingTransformer.delegationResponseToDelegation( response, @@ -357,7 +386,10 @@ export class ChainGrpcStakingApi { } try { - const response = await this.client.DelegatorDelegations(request) + const response = + await this.retry( + () => this.client.DelegatorDelegations(request), + ) return ChainGrpcStakingTransformer.delegationsResponseToDelegations( response, @@ -398,7 +430,10 @@ export class ChainGrpcStakingApi { } try { - const response = await this.client.DelegatorDelegations(request) + const response = + await this.retry( + () => this.client.DelegatorDelegations(request), + ) return ChainGrpcStakingTransformer.delegationsResponseToDelegations( response, @@ -443,7 +478,10 @@ export class ChainGrpcStakingApi { } try { - const response = await this.client.ValidatorDelegations(request) + const response = + await this.retry( + () => this.client.ValidatorDelegations(request), + ) return ChainGrpcStakingTransformer.delegationsResponseToDelegations( response, @@ -484,7 +522,10 @@ export class ChainGrpcStakingApi { } try { - const response = await this.client.ValidatorDelegations(request) + const response = + await this.retry( + () => this.client.ValidatorDelegations(request), + ) return ChainGrpcStakingTransformer.delegationsResponseToDelegations( response, @@ -529,7 +570,10 @@ export class ChainGrpcStakingApi { } try { - const response = await this.client.DelegatorUnbondingDelegations(request) + const response = + await this.retry( + () => this.client.DelegatorUnbondingDelegations(request), + ) return ChainGrpcStakingTransformer.unBondingDelegationsResponseToUnBondingDelegations( response, @@ -570,7 +614,10 @@ export class ChainGrpcStakingApi { } try { - const response = await this.client.DelegatorUnbondingDelegations(request) + const response = + await this.retry( + () => this.client.DelegatorUnbondingDelegations(request), + ) return ChainGrpcStakingTransformer.unBondingDelegationsResponseToUnBondingDelegations( response, @@ -614,7 +661,10 @@ export class ChainGrpcStakingApi { } try { - const response = await this.client.Redelegations(request) + const response = + await this.retry( + () => this.client.Redelegations(request), + ) return ChainGrpcStakingTransformer.reDelegationsResponseToReDelegations( response, @@ -654,7 +704,10 @@ export class ChainGrpcStakingApi { } try { - const response = await this.client.Redelegations(request) + const response = + await this.retry( + () => this.client.Redelegations(request), + ) return ChainGrpcStakingTransformer.reDelegationsResponseToReDelegations( response, diff --git a/packages/sdk-ts/src/client/chain/grpc/ChainGrpcWasmApi.ts b/packages/sdk-ts/src/client/chain/grpc/ChainGrpcWasmApi.ts index 5e1e34bc7..646db8687 100644 --- a/packages/sdk-ts/src/client/chain/grpc/ChainGrpcWasmApi.ts +++ b/packages/sdk-ts/src/client/chain/grpc/ChainGrpcWasmApi.ts @@ -1,25 +1,27 @@ -import { ChainGrpcWasmTransformer } from '../transformers' -import { PaginationOption } from '../../../types/pagination' -import { paginationRequestFromPagination } from '../../../utils/pagination' -import { ChainModule } from '../types' import { GrpcUnaryRequestException, UnspecifiedErrorCode, } from '@injectivelabs/exceptions' -import { getGrpcWebImpl } from '../../BaseGrpcWebConsumer' import { CosmwasmWasmV1Query } from '@injectivelabs/core-proto-ts' +import BaseGrpcConsumer from '../../BaseGrpcConsumer' +import { ChainModule } from '../types' +import { ChainGrpcWasmTransformer } from '../transformers' +import { PaginationOption } from '../../../types/pagination' +import { paginationRequestFromPagination } from '../../../utils/pagination' /** * @category Chain Grpc API */ -export class ChainGrpcWasmApi { +export class ChainGrpcWasmApi extends BaseGrpcConsumer { protected module: string = ChainModule.Wasm protected client: CosmwasmWasmV1Query.QueryClientImpl constructor(endpoint: string) { + super(endpoint) + this.client = new CosmwasmWasmV1Query.QueryClientImpl( - getGrpcWebImpl(endpoint), + this.getGrpcWebImpl(endpoint), ) } @@ -41,7 +43,10 @@ export class ChainGrpcWasmApi { } try { - const response = await this.client.AllContractState(request) + const response = + await this.retry( + () => this.client.AllContractState(request), + ) return ChainGrpcWasmTransformer.allContractStateResponseToContractAccountsBalanceWithPagination( response, @@ -69,7 +74,10 @@ export class ChainGrpcWasmApi { request.address = contractAddress try { - const response = await this.client.ContractInfo(request) + const response = + await this.retry(() => + this.client.ContractInfo(request), + ) const contractInfo = response.contractInfo @@ -103,7 +111,10 @@ export class ChainGrpcWasmApi { request.address = contractAddress try { - const response = await this.client.ContractHistory(request) + const response = + await this.retry(() => + this.client.ContractHistory(request), + ) return ChainGrpcWasmTransformer.contactHistoryResponseToContractHistory( response, @@ -135,7 +146,10 @@ export class ChainGrpcWasmApi { } try { - const response = await this.client.SmartContractState(request) + const response = + await this.retry( + () => this.client.SmartContractState(request), + ) return response } catch (e: unknown) { @@ -165,7 +179,10 @@ export class ChainGrpcWasmApi { } try { - const response = await this.client.RawContractState(request) + const response = + await this.retry( + () => this.client.RawContractState(request), + ) return response } catch (e: unknown) { @@ -195,7 +212,9 @@ export class ChainGrpcWasmApi { } try { - const response = await this.client.Codes(request) + const response = await this.retry( + () => this.client.Codes(request), + ) return ChainGrpcWasmTransformer.contractCodesResponseToContractCodes( response, @@ -223,7 +242,9 @@ export class ChainGrpcWasmApi { request.codeId = codeId.toString() try { - const response = await this.client.Code(request) + const response = await this.retry( + () => this.client.Code(request), + ) return ChainGrpcWasmTransformer.contractCodeResponseToContractCode( response, @@ -260,7 +281,10 @@ export class ChainGrpcWasmApi { } try { - const response = await this.client.ContractsByCode(request) + const response = + await this.retry(() => + this.client.ContractsByCode(request), + ) return ChainGrpcWasmTransformer.contractByCodeResponseToContractByCode( response, diff --git a/packages/sdk-ts/src/client/chain/grpc/ChainGrpcWasmXApi.ts b/packages/sdk-ts/src/client/chain/grpc/ChainGrpcWasmXApi.ts index 8685d8dc0..bc08fa951 100644 --- a/packages/sdk-ts/src/client/chain/grpc/ChainGrpcWasmXApi.ts +++ b/packages/sdk-ts/src/client/chain/grpc/ChainGrpcWasmXApi.ts @@ -1,22 +1,24 @@ -import { ChainModule } from '../types' import { GrpcUnaryRequestException, UnspecifiedErrorCode, } from '@injectivelabs/exceptions' -import { getGrpcWebImpl } from '../../BaseGrpcWebConsumer' import { InjectiveWasmxV1Beta1Query } from '@injectivelabs/core-proto-ts' +import BaseGrpcConsumer from '../../BaseGrpcConsumer' +import { ChainModule } from '../types' /** * @category Chain Grpc API */ -export class ChainGrpcWasmXApi { +export class ChainGrpcWasmXApi extends BaseGrpcConsumer { protected module: string = ChainModule.WasmX protected client: InjectiveWasmxV1Beta1Query.QueryClientImpl constructor(endpoint: string) { + super(endpoint) + this.client = new InjectiveWasmxV1Beta1Query.QueryClientImpl( - getGrpcWebImpl(endpoint), + this.getGrpcWebImpl(endpoint), ) } @@ -24,7 +26,10 @@ export class ChainGrpcWasmXApi { const request = InjectiveWasmxV1Beta1Query.QueryWasmxParamsRequest.create() try { - const response = await this.client.WasmxParams(request) + const response = + await this.retry( + () => this.client.WasmxParams(request), + ) return response } catch (e: unknown) { @@ -48,7 +53,10 @@ export class ChainGrpcWasmXApi { const request = InjectiveWasmxV1Beta1Query.QueryModuleStateRequest.create() try { - const response = await this.client.WasmxModuleState(request) + const response = + await this.retry( + () => this.client.WasmxModuleState(request), + ) return response.state /* TODO */ } catch (e: unknown) { diff --git a/packages/sdk-ts/src/client/chain/rest/ChainRestAuthApi.ts b/packages/sdk-ts/src/client/chain/rest/ChainRestAuthApi.ts index 3d879df56..7c6bb0a30 100644 --- a/packages/sdk-ts/src/client/chain/rest/ChainRestAuthApi.ts +++ b/packages/sdk-ts/src/client/chain/rest/ChainRestAuthApi.ts @@ -23,9 +23,9 @@ export class ChainRestAuthApi extends BaseRestConsumer { const endpoint = `cosmos/auth/v1beta1/accounts/${address}` try { - const response = (await this.get( - endpoint, - )) as RestApiResponse + const response = await this.retry>(() => + this.get(endpoint), + ) return response.data } catch (e: unknown) { @@ -54,9 +54,10 @@ export class ChainRestAuthApi extends BaseRestConsumer { try { const isInjectiveAddress = address.startsWith('inj') || address.startsWith('evmos') - const response = (await this.get(endpoint)) as RestApiResponse< - AccountResponse | CosmosAccountRestResponse - > + + const response = await this.retry< + RestApiResponse + >(() => this.get(endpoint)) const baseAccount = isInjectiveAddress ? (response.data as AccountResponse).account.base_account diff --git a/packages/sdk-ts/src/client/chain/rest/ChainRestBankApi.ts b/packages/sdk-ts/src/client/chain/rest/ChainRestBankApi.ts index 187568f9f..9d81d78f8 100644 --- a/packages/sdk-ts/src/client/chain/rest/ChainRestBankApi.ts +++ b/packages/sdk-ts/src/client/chain/rest/ChainRestBankApi.ts @@ -22,9 +22,9 @@ export class ChainRestBankApi extends BaseRestConsumer { const endpoint = `cosmos/bank/v1beta1/balances/${address}` try { - const response = (await this.get( - endpoint, - )) as RestApiResponse + const response = await this.retry>(() => + this.get(endpoint), + ) return response.data } catch (e) { @@ -52,9 +52,9 @@ export class ChainRestBankApi extends BaseRestConsumer { const endpoint = `cosmos/bank/v1beta1/balances/${address}` try { - const response = (await this.get( - endpoint, - )) as RestApiResponse + const response = await this.retry>(() => + this.get(endpoint), + ) const balance = response.data.balances.find( (balance) => balance.denom === denom, diff --git a/packages/sdk-ts/src/client/chain/rest/ChainRestTendermintApi.ts b/packages/sdk-ts/src/client/chain/rest/ChainRestTendermintApi.ts index 44093a7ea..e79dd52f9 100644 --- a/packages/sdk-ts/src/client/chain/rest/ChainRestTendermintApi.ts +++ b/packages/sdk-ts/src/client/chain/rest/ChainRestTendermintApi.ts @@ -17,9 +17,9 @@ export class ChainRestTendermintApi extends BaseRestConsumer { const endpoint = `cosmos/base/tendermint/v1beta1/blocks/latest` try { - const response = (await this.get( - endpoint, - )) as RestApiResponse + const response = await this.retry< + RestApiResponse + >(() => this.get(endpoint)) return response.data.block } catch (e) { @@ -42,9 +42,9 @@ export class ChainRestTendermintApi extends BaseRestConsumer { const endpoint = `cosmos/base/tendermint/v1beta1/node_info` try { - const response = (await this.get( - endpoint, - )) as RestApiResponse + const response = await this.retry>( + () => this.get(endpoint), + ) return { nodeInfo: response.data.default_node_info, diff --git a/packages/sdk-ts/src/client/dmm/grpc/DmmGrpcApi.ts b/packages/sdk-ts/src/client/dmm/grpc/DmmGrpcApi.ts index 6b52de245..9872694ac 100644 --- a/packages/sdk-ts/src/client/dmm/grpc/DmmGrpcApi.ts +++ b/packages/sdk-ts/src/client/dmm/grpc/DmmGrpcApi.ts @@ -1,18 +1,21 @@ -import { InjectiveDmmRpc } from '@injectivelabs/dmm-proto-ts' -import { getGrpcDmmWebImpl } from '../../BaseGrpcDmmWebConsumer' -import { DmmGrpcTransformer } from './transformers' import { UnspecifiedErrorCode, GrpcUnaryRequestException, IndexerErrorModule, } from '@injectivelabs/exceptions' +import { InjectiveDmmRpc } from '@injectivelabs/dmm-proto-ts' +import BaseGrpcConsumer from '../../BaseGrpcConsumer' +import { DmmGrpcTransformer } from './transformers' -export class DmmGrpcApi { +export class DmmGrpcApi extends BaseGrpcConsumer { protected module: string = IndexerErrorModule.Dmm protected client: InjectiveDmmRpc.InjectiveDmmV2RPCClientImpl + constructor(endpoint: string) { + super(endpoint) + this.client = new InjectiveDmmRpc.InjectiveDmmV2RPCClientImpl( - getGrpcDmmWebImpl(endpoint), + this.getGrpcWebImpl(endpoint), ) } @@ -24,7 +27,9 @@ export class DmmGrpcApi { } try { - const response = await this.client.GetEpochs(request) + const response = await this.retry(() => + this.client.GetEpochs(request), + ) return DmmGrpcTransformer.epochsResponseToEpochs(response) } catch (e: unknown) { @@ -50,7 +55,10 @@ export class DmmGrpcApi { request.epochId = epochId.toString() try { - const response = await this.client.GetMarketRewards(request) + const response = + await this.retry(() => + this.client.GetMarketRewards(request), + ) return DmmGrpcTransformer.marketRewardsResponseToMarketRewards(response) } catch (e: unknown) { @@ -86,7 +94,10 @@ export class DmmGrpcApi { } try { - const response = await this.client.GetEligibleAddresses(request) + const response = + await this.retry(() => + this.client.GetEligibleAddresses(request), + ) return DmmGrpcTransformer.eligibleAddressesResponseToEligibleAddresses( response, @@ -124,7 +135,9 @@ export class DmmGrpcApi { } try { - const response = await this.client.GetEpochScores(request) + const response = await this.retry( + () => this.client.GetEpochScores(request), + ) return DmmGrpcTransformer.epochScoresResponseToEpochScores(response) } catch (e: unknown) { @@ -163,7 +176,10 @@ export class DmmGrpcApi { } try { - const response = await this.client.GetEpochScoresHistory(request) + const response = + await this.retry(() => + this.client.GetEpochScoresHistory(request), + ) return DmmGrpcTransformer.epochScoresHistoryResponseToEpochScoresHistory( response, @@ -204,7 +220,9 @@ export class DmmGrpcApi { } try { - const response = await this.client.GetTotalScores(request) + const response = await this.retry( + () => this.client.GetTotalScores(request), + ) return DmmGrpcTransformer.totalScoresResponseToTotalScores(response) } catch (e: unknown) { @@ -246,7 +264,10 @@ export class DmmGrpcApi { } try { - const response = await this.client.GetTotalScoresHistory(request) + const response = + await this.retry(() => + this.client.GetTotalScoresHistory(request), + ) return DmmGrpcTransformer.totalScoresHistoryResponseToTotalScoresHistory( response, @@ -290,7 +311,10 @@ export class DmmGrpcApi { } try { - const response = await this.client.GetLiquiditySnapshots(request) + const response = + await this.retry(() => + this.client.GetLiquiditySnapshots(request), + ) return DmmGrpcTransformer.liquiditySnapshotsResponseToLiquiditySnapshots( response, @@ -334,7 +358,10 @@ export class DmmGrpcApi { } try { - const response = await this.client.GetRewardsDistribution(request) + const response = + await this.retry(() => + this.client.GetRewardsDistribution(request), + ) return DmmGrpcTransformer.rewardsDistributionResponseToRewardsDistribution( response, @@ -369,7 +396,10 @@ export class DmmGrpcApi { request.accountAddress = accountAddress try { - const response = await this.client.GetAccountVolumes(request) + const response = + await this.retry(() => + this.client.GetAccountVolumes(request), + ) return DmmGrpcTransformer.accountVolumesResponseToAccountVolumes(response) } catch (e: unknown) { @@ -407,7 +437,10 @@ export class DmmGrpcApi { } try { - const response = await this.client.GetRewardsEligibility(request) + const response = + await this.retry(() => + this.client.GetRewardsEligibility(request), + ) return DmmGrpcTransformer.rewardsEligibilityResponseToRewardsEligibility( response, diff --git a/packages/sdk-ts/src/client/indexer/grpc/IndexerGrpcAccountApi.ts b/packages/sdk-ts/src/client/indexer/grpc/IndexerGrpcAccountApi.ts index 994361550..e7145c2eb 100644 --- a/packages/sdk-ts/src/client/indexer/grpc/IndexerGrpcAccountApi.ts +++ b/packages/sdk-ts/src/client/indexer/grpc/IndexerGrpcAccountApi.ts @@ -1,25 +1,27 @@ -import { PaginationOption } from '../../../types/pagination' -import { IndexerGrpcAccountTransformer } from '../transformers' -import { IndexerModule } from '../types' import { GeneralException, UnspecifiedErrorCode, GrpcUnaryRequestException, } from '@injectivelabs/exceptions' -import { getGrpcIndexerWebImpl } from '../../BaseIndexerGrpcWebConsumer' import { InjectiveAccountRpc } from '@injectivelabs/indexer-proto-ts' +import BaseGrpcConsumer from '../../BaseGrpcConsumer' +import { IndexerModule } from '../types' +import { PaginationOption } from '../../../types/pagination' +import { IndexerGrpcAccountTransformer } from '../transformers' /** * @category Indexer Grpc API */ -export class IndexerGrpcAccountApi { +export class IndexerGrpcAccountApi extends BaseGrpcConsumer { protected module: string = IndexerModule.Account protected client: InjectiveAccountRpc.InjectiveAccountsRPCClientImpl constructor(endpoint: string) { + super(endpoint) + this.client = new InjectiveAccountRpc.InjectiveAccountsRPCClientImpl( - getGrpcIndexerWebImpl(endpoint), + this.getGrpcWebImpl(endpoint), ) } @@ -44,7 +46,9 @@ export class IndexerGrpcAccountApi { } try { - const response = await this.client.Rewards(request) + const response = await this.retry( + () => this.client.Rewards(request), + ) return IndexerGrpcAccountTransformer.tradingRewardsResponseToTradingRewards( response, @@ -72,7 +76,10 @@ export class IndexerGrpcAccountApi { request.accountAddress = address try { - const response = await this.client.SubaccountsList(request) + const response = + await this.retry(() => + this.client.SubaccountsList(request), + ) return response.subaccounts } catch (e: unknown) { @@ -100,7 +107,10 @@ export class IndexerGrpcAccountApi { request.denom = denom try { - const response = await this.client.SubaccountBalanceEndpoint(request) + const response = + await this.retry( + () => this.client.SubaccountBalanceEndpoint(request), + ) return IndexerGrpcAccountTransformer.balanceResponseToBalance(response) } catch (e: unknown) { @@ -126,7 +136,10 @@ export class IndexerGrpcAccountApi { request.subaccountId = subaccountId try { - const response = await this.client.SubaccountBalancesList(request) + const response = + await this.retry( + () => this.client.SubaccountBalancesList(request), + ) return IndexerGrpcAccountTransformer.balancesResponseToBalances(response) } catch (e: unknown) { @@ -184,7 +197,10 @@ export class IndexerGrpcAccountApi { } try { - const response = await this.client.SubaccountHistory(request) + const response = + await this.retry(() => + this.client.SubaccountHistory(request), + ) return IndexerGrpcAccountTransformer.transferHistoryResponseToTransferHistory( response, @@ -228,7 +244,10 @@ export class IndexerGrpcAccountApi { } try { - const response = await this.client.SubaccountOrderSummary(request) + const response = + await this.retry( + () => this.client.SubaccountOrderSummary(request), + ) return response } catch (e: unknown) { @@ -259,7 +278,10 @@ export class IndexerGrpcAccountApi { request.derivativeOrderHashes = derivativeOrderHashes try { - const response = await this.client.OrderStates(request) + const response = + await this.retry(() => + this.client.OrderStates(request), + ) return response } catch (e: unknown) { diff --git a/packages/sdk-ts/src/client/indexer/grpc/IndexerGrpcAuctionApi.ts b/packages/sdk-ts/src/client/indexer/grpc/IndexerGrpcAuctionApi.ts index 06038ea3c..3a2ac8703 100644 --- a/packages/sdk-ts/src/client/indexer/grpc/IndexerGrpcAuctionApi.ts +++ b/packages/sdk-ts/src/client/indexer/grpc/IndexerGrpcAuctionApi.ts @@ -1,23 +1,25 @@ -import { IndexerGrpcAuctionTransformer } from '../transformers' -import { IndexerModule } from '../types' import { GrpcUnaryRequestException, UnspecifiedErrorCode, } from '@injectivelabs/exceptions' -import { getGrpcIndexerWebImpl } from '../../BaseIndexerGrpcWebConsumer' import { InjectiveAuctionRpc } from '@injectivelabs/indexer-proto-ts' +import BaseGrpcConsumer from '../../BaseGrpcConsumer' +import { IndexerModule } from '../types' +import { IndexerGrpcAuctionTransformer } from '../transformers' /** * @category Indexer Grpc API */ -export class IndexerGrpcAuctionApi { +export class IndexerGrpcAuctionApi extends BaseGrpcConsumer { protected module: string = IndexerModule.Account protected client: InjectiveAuctionRpc.InjectiveAuctionRPCClientImpl constructor(endpoint: string) { + super(endpoint) + this.client = new InjectiveAuctionRpc.InjectiveAuctionRPCClientImpl( - getGrpcIndexerWebImpl(endpoint), + this.getGrpcWebImpl(endpoint), ) } @@ -33,7 +35,10 @@ export class IndexerGrpcAuctionApi { } try { - const response = await this.client.AuctionEndpoint(request) + const response = + await this.retry(() => + this.client.AuctionEndpoint(request), + ) return IndexerGrpcAuctionTransformer.auctionResponseToAuction(response) } catch (e: unknown) { @@ -57,7 +62,9 @@ export class IndexerGrpcAuctionApi { const request = InjectiveAuctionRpc.AuctionsRequest.create() try { - const response = await this.client.Auctions(request) + const response = await this.retry( + () => this.client.Auctions(request), + ) return IndexerGrpcAuctionTransformer.auctionsResponseToAuctions(response) } catch (e: unknown) { diff --git a/packages/sdk-ts/src/client/indexer/grpc/IndexerGrpcDerivativesApi.ts b/packages/sdk-ts/src/client/indexer/grpc/IndexerGrpcDerivativesApi.ts index ba655978f..88b710015 100644 --- a/packages/sdk-ts/src/client/indexer/grpc/IndexerGrpcDerivativesApi.ts +++ b/packages/sdk-ts/src/client/indexer/grpc/IndexerGrpcDerivativesApi.ts @@ -1,32 +1,34 @@ +import { + GeneralException, + UnspecifiedErrorCode, + GrpcUnaryRequestException, +} from '@injectivelabs/exceptions' +import { OrderSide, OrderState } from '@injectivelabs/ts-types' +import { InjectiveDerivativeExchangeRpc } from '@injectivelabs/indexer-proto-ts' +import BaseGrpcConsumer from '../../BaseGrpcConsumer' import { TradeDirection, TradeExecutionSide, TradeExecutionType, } from '../../../types/exchange' +import { IndexerModule } from '../types' import { PaginationOption } from '../../../types/pagination' import { IndexerGrpcDerivativeTransformer } from '../transformers' -import { IndexerModule } from '../types' -import { OrderSide, OrderState } from '@injectivelabs/ts-types' -import { - GeneralException, - UnspecifiedErrorCode, - GrpcUnaryRequestException, -} from '@injectivelabs/exceptions' -import { getGrpcIndexerWebImpl } from '../../BaseIndexerGrpcWebConsumer' -import { InjectiveDerivativeExchangeRpc } from '@injectivelabs/indexer-proto-ts' /** * @category Indexer Grpc API */ -export class IndexerGrpcDerivativesApi { +export class IndexerGrpcDerivativesApi extends BaseGrpcConsumer { protected module: string = IndexerModule.Derivatives protected client: InjectiveDerivativeExchangeRpc.InjectiveDerivativeExchangeRPCClientImpl constructor(endpoint: string) { + super(endpoint) + this.client = new InjectiveDerivativeExchangeRpc.InjectiveDerivativeExchangeRPCClientImpl( - getGrpcIndexerWebImpl(endpoint), + this.getGrpcWebImpl(endpoint), ) } @@ -44,7 +46,10 @@ export class IndexerGrpcDerivativesApi { } try { - const response = await this.client.Markets(request) + const response = + await this.retry(() => + this.client.Markets(request), + ) return IndexerGrpcDerivativeTransformer.marketsResponseToMarkets(response) } catch (e: unknown) { @@ -70,7 +75,10 @@ export class IndexerGrpcDerivativesApi { request.marketId = marketId try { - const response = await this.client.Market(request) + const response = + await this.retry(() => + this.client.Market(request), + ) return IndexerGrpcDerivativeTransformer.marketResponseToMarket(response) } catch (e: unknown) { @@ -119,7 +127,10 @@ export class IndexerGrpcDerivativesApi { } try { - const response = await this.client.BinaryOptionsMarkets(request) + const response = + await this.retry( + () => this.client.BinaryOptionsMarkets(request), + ) return pagination ? IndexerGrpcDerivativeTransformer.binaryOptionsMarketResponseWithPaginationToBinaryOptionsMarket( @@ -152,7 +163,10 @@ export class IndexerGrpcDerivativesApi { request.marketId = marketId try { - const response = await this.client.BinaryOptionsMarket(request) + const response = + await this.retry( + () => this.client.BinaryOptionsMarket(request), + ) return IndexerGrpcDerivativeTransformer.binaryOptionsMarketResponseToBinaryOptionsMarket( response, @@ -233,7 +247,10 @@ export class IndexerGrpcDerivativesApi { } try { - const response = await this.client.Orders(request) + const response = + await this.retry(() => + this.client.Orders(request), + ) return IndexerGrpcDerivativeTransformer.ordersResponseToOrders(response) } catch (e: unknown) { @@ -325,7 +342,10 @@ export class IndexerGrpcDerivativesApi { } try { - const response = await this.client.OrdersHistory(request) + const response = + await this.retry( + () => this.client.OrdersHistory(request), + ) return IndexerGrpcDerivativeTransformer.orderHistoryResponseToOrderHistory( response, @@ -390,7 +410,10 @@ export class IndexerGrpcDerivativesApi { } try { - const response = await this.client.Positions(request) + const response = + await this.retry(() => + this.client.Positions(request), + ) return IndexerGrpcDerivativeTransformer.positionsResponseToPositions( response, @@ -496,7 +519,10 @@ export class IndexerGrpcDerivativesApi { } try { - const response = await this.client.Trades(request) + const response = + await this.retry(() => + this.client.Trades(request), + ) return IndexerGrpcDerivativeTransformer.tradesResponseToTrades(response) } catch (e: unknown) { @@ -554,7 +580,10 @@ export class IndexerGrpcDerivativesApi { } try { - const response = await this.client.FundingPayments(request) + const response = + await this.retry( + () => this.client.FundingPayments(request), + ) return IndexerGrpcDerivativeTransformer.fundingPaymentsResponseToFundingPayments( response, @@ -599,7 +628,10 @@ export class IndexerGrpcDerivativesApi { } try { - const response = await this.client.FundingRates(request) + const response = + await this.retry( + () => this.client.FundingRates(request), + ) return IndexerGrpcDerivativeTransformer.fundingRatesResponseToFundingRates( response, @@ -650,7 +682,10 @@ export class IndexerGrpcDerivativesApi { } try { - const response = await this.client.SubaccountOrdersList(request) + const response = + await this.retry( + () => this.client.SubaccountOrdersList(request), + ) return IndexerGrpcDerivativeTransformer.ordersResponseToOrders(response) } catch (e: unknown) { @@ -710,7 +745,10 @@ export class IndexerGrpcDerivativesApi { } try { - const response = await this.client.SubaccountTradesList(request) + const response = + await this.retry( + () => this.client.SubaccountTradesList(request), + ) return IndexerGrpcDerivativeTransformer.subaccountTradesListResponseToSubaccountTradesList( response, @@ -745,7 +783,10 @@ export class IndexerGrpcDerivativesApi { } try { - const response = await this.client.OrderbooksV2(request) + const response = + await this.retry( + () => this.client.OrderbooksV2(request), + ) return IndexerGrpcDerivativeTransformer.orderbooksV2ResponseToOrderbooksV2( response, @@ -773,7 +814,10 @@ export class IndexerGrpcDerivativesApi { request.marketId = marketId try { - const response = await this.client.OrderbookV2(request) + const response = + await this.retry( + () => this.client.OrderbookV2(request), + ) return IndexerGrpcDerivativeTransformer.orderbookV2ResponseToOrderbookV2( response, diff --git a/packages/sdk-ts/src/client/indexer/grpc/IndexerGrpcExplorerApi.ts b/packages/sdk-ts/src/client/indexer/grpc/IndexerGrpcExplorerApi.ts index 0871a2d41..dfe581d90 100644 --- a/packages/sdk-ts/src/client/indexer/grpc/IndexerGrpcExplorerApi.ts +++ b/packages/sdk-ts/src/client/indexer/grpc/IndexerGrpcExplorerApi.ts @@ -1,23 +1,25 @@ -import { IndexerGrpcExplorerTransformer } from '../transformers' -import { IndexerModule } from '../types' import { GrpcUnaryRequestException, UnspecifiedErrorCode, } from '@injectivelabs/exceptions' -import { getGrpcIndexerWebImpl } from '../../BaseIndexerGrpcWebConsumer' import { InjectiveExplorerRpc } from '@injectivelabs/indexer-proto-ts' +import BaseGrpcConsumer from '../../BaseGrpcConsumer' +import { IndexerModule } from '../types' +import { IndexerGrpcExplorerTransformer } from '../transformers' /** * @category Indexer Grpc API */ -export class IndexerGrpcExplorerApi { +export class IndexerGrpcExplorerApi extends BaseGrpcConsumer { protected module: string = IndexerModule.Explorer protected client: InjectiveExplorerRpc.InjectiveExplorerRPCClientImpl constructor(endpoint: string) { + super(endpoint) + this.client = new InjectiveExplorerRpc.InjectiveExplorerRPCClientImpl( - getGrpcIndexerWebImpl(endpoint), + this.getGrpcWebImpl(endpoint), ) } @@ -68,7 +70,10 @@ export class IndexerGrpcExplorerApi { } try { - const response = await this.client.GetAccountTxs(request) + const response = + await this.retry(() => + this.client.GetAccountTxs(request), + ) return IndexerGrpcExplorerTransformer.getAccountTxsResponseToAccountTxs( response, @@ -96,7 +101,10 @@ export class IndexerGrpcExplorerApi { request.address = validatorAddress try { - const response = await this.client.GetValidator(request) + const response = + await this.retry(() => + this.client.GetValidator(request), + ) return IndexerGrpcExplorerTransformer.validatorResponseToValidator( response, @@ -124,7 +132,10 @@ export class IndexerGrpcExplorerApi { request.address = validatorAddress try { - const response = await this.client.GetValidatorUptime(request) + const response = + await this.retry(() => + this.client.GetValidatorUptime(request), + ) return IndexerGrpcExplorerTransformer.getValidatorUptimeResponseToValidatorUptime( response, @@ -176,7 +187,10 @@ export class IndexerGrpcExplorerApi { } try { - const response = await this.client.GetPeggyDepositTxs(request) + const response = + await this.retry(() => + this.client.GetPeggyDepositTxs(request), + ) return IndexerGrpcExplorerTransformer.getPeggyDepositTxsResponseToPeggyDepositTxs( response, @@ -228,7 +242,10 @@ export class IndexerGrpcExplorerApi { } try { - const response = await this.client.GetPeggyWithdrawalTxs(request) + const response = + await this.retry( + () => this.client.GetPeggyWithdrawalTxs(request), + ) return IndexerGrpcExplorerTransformer.getPeggyWithdrawalTxsResponseToPeggyWithdrawalTxs( response, @@ -274,7 +291,9 @@ export class IndexerGrpcExplorerApi { } try { - const response = await this.client.GetBlocks(request) + const response = await this.retry( + () => this.client.GetBlocks(request), + ) return response } catch (e: unknown) { @@ -300,7 +319,9 @@ export class IndexerGrpcExplorerApi { request.id = id try { - const response = await this.client.GetBlock(request) + const response = await this.retry( + () => this.client.GetBlock(request), + ) return response } catch (e: unknown) { @@ -362,7 +383,9 @@ export class IndexerGrpcExplorerApi { } try { - const response = await this.client.GetTxs(request) + const response = await this.retry( + () => this.client.GetTxs(request), + ) return response } catch (e: unknown) { @@ -436,7 +459,10 @@ export class IndexerGrpcExplorerApi { } try { - const response = await this.client.GetIBCTransferTxs(request) + const response = + await this.retry(() => + this.client.GetIBCTransferTxs(request), + ) return IndexerGrpcExplorerTransformer.getIBCTransferTxsResponseToIBCTransferTxs( response, diff --git a/packages/sdk-ts/src/client/indexer/grpc/IndexerGrpcInsuranceFundApi.ts b/packages/sdk-ts/src/client/indexer/grpc/IndexerGrpcInsuranceFundApi.ts index 607c0e7a2..f3cc521b7 100644 --- a/packages/sdk-ts/src/client/indexer/grpc/IndexerGrpcInsuranceFundApi.ts +++ b/packages/sdk-ts/src/client/indexer/grpc/IndexerGrpcInsuranceFundApi.ts @@ -1,23 +1,25 @@ -import { IndexerGrpcInsuranceFundTransformer } from '../transformers' -import { IndexerModule } from '../types' import { GrpcUnaryRequestException, UnspecifiedErrorCode, } from '@injectivelabs/exceptions' -import { getGrpcIndexerWebImpl } from '../../BaseIndexerGrpcWebConsumer' import { InjectiveInsuranceRpc } from '@injectivelabs/indexer-proto-ts' +import BaseGrpcConsumer from '../../BaseGrpcConsumer' +import { IndexerGrpcInsuranceFundTransformer } from '../transformers' +import { IndexerModule } from '../types' /** * @category Indexer Grpc API */ -export class IndexerGrpcInsuranceFundApi { +export class IndexerGrpcInsuranceFundApi extends BaseGrpcConsumer { protected module: string = IndexerModule.InsuranceFund protected client: InjectiveInsuranceRpc.InjectiveInsuranceRPCClientImpl constructor(endpoint: string) { + super(endpoint) + this.client = new InjectiveInsuranceRpc.InjectiveInsuranceRPCClientImpl( - getGrpcIndexerWebImpl(endpoint), + this.getGrpcWebImpl(endpoint), ) } @@ -43,7 +45,10 @@ export class IndexerGrpcInsuranceFundApi { } try { - const response = await this.client.Redemptions(request) + const response = + await this.retry(() => + this.client.Redemptions(request), + ) return IndexerGrpcInsuranceFundTransformer.redemptionsResponseToRedemptions( response, @@ -69,7 +74,9 @@ export class IndexerGrpcInsuranceFundApi { const request = InjectiveInsuranceRpc.FundsRequest.create() try { - const response = await this.client.Funds(request) + const response = await this.retry( + () => this.client.Funds(request), + ) return IndexerGrpcInsuranceFundTransformer.insuranceFundsResponseToInsuranceFunds( response, diff --git a/packages/sdk-ts/src/client/indexer/grpc/IndexerGrpcMetaApi.ts b/packages/sdk-ts/src/client/indexer/grpc/IndexerGrpcMetaApi.ts index 808e6f1b7..9a28dd691 100644 --- a/packages/sdk-ts/src/client/indexer/grpc/IndexerGrpcMetaApi.ts +++ b/packages/sdk-ts/src/client/indexer/grpc/IndexerGrpcMetaApi.ts @@ -1,22 +1,24 @@ -import { IndexerModule } from '../types' import { GrpcUnaryRequestException, UnspecifiedErrorCode, } from '@injectivelabs/exceptions' -import { getGrpcIndexerWebImpl } from '../../BaseIndexerGrpcWebConsumer' import { InjectiveMetaRpc } from '@injectivelabs/indexer-proto-ts' +import BaseGrpcConsumer from '../../BaseGrpcConsumer' +import { IndexerModule } from '../types' /** * @category Indexer Grpc API */ -export class IndexerGrpcMetaApi { +export class IndexerGrpcMetaApi extends BaseGrpcConsumer { protected module: string = IndexerModule.Meta protected client: InjectiveMetaRpc.InjectiveMetaRPCClientImpl constructor(endpoint: string) { + super(endpoint) + this.client = new InjectiveMetaRpc.InjectiveMetaRPCClientImpl( - getGrpcIndexerWebImpl(endpoint), + this.getGrpcWebImpl(endpoint), ) } @@ -24,7 +26,9 @@ export class IndexerGrpcMetaApi { const request = InjectiveMetaRpc.PingRequest.create() try { - const response = await this.client.Ping(request) + const response = await this.retry(() => + this.client.Ping(request), + ) return response } catch (e: unknown) { @@ -48,7 +52,9 @@ export class IndexerGrpcMetaApi { const request = InjectiveMetaRpc.VersionRequest.create() try { - const response = await this.client.Version(request) + const response = await this.retry(() => + this.client.Version(request), + ) return response } catch (e: unknown) { @@ -74,7 +80,9 @@ export class IndexerGrpcMetaApi { request.timestamp = Date.now().toString() try { - const response = await this.client.Info(request) + const response = await this.retry(() => + this.client.Info(request), + ) return response } catch (e: unknown) { diff --git a/packages/sdk-ts/src/client/indexer/grpc/IndexerGrpcMitoApi.ts b/packages/sdk-ts/src/client/indexer/grpc/IndexerGrpcMitoApi.ts index f0f2f108f..6a4164280 100644 --- a/packages/sdk-ts/src/client/indexer/grpc/IndexerGrpcMitoApi.ts +++ b/packages/sdk-ts/src/client/indexer/grpc/IndexerGrpcMitoApi.ts @@ -1,23 +1,25 @@ -import { IndexerGrpcMitoTransformer } from '../transformers' -import { IndexerModule } from '../types' import { UnspecifiedErrorCode, GrpcUnaryRequestException, } from '@injectivelabs/exceptions' -import { InjectiveMetaRpc } from '@injectivelabs/indexer-proto-ts' -import { getGrpcIndexerWebImpl } from '../../BaseIndexerGrpcWebConsumer' import { MitoApi } from '@injectivelabs/mito-proto-ts' +import { InjectiveMetaRpc } from '@injectivelabs/indexer-proto-ts' +import BaseGrpcConsumer from '../../BaseGrpcConsumer' +import { IndexerModule } from '../types' +import { IndexerGrpcMitoTransformer } from '../transformers' /** * @category Indexer Grpc API */ -export class IndexerGrpcMitoApi { +export class IndexerGrpcMitoApi extends BaseGrpcConsumer { protected module: string = IndexerModule.Mito protected client: MitoApi.MitoAPIClientImpl constructor(endpoint: string) { - this.client = new MitoApi.MitoAPIClientImpl(getGrpcIndexerWebImpl(endpoint)) + super(endpoint) + + this.client = new MitoApi.MitoAPIClientImpl(this.getGrpcWebImpl(endpoint)) } async fetchVault({ @@ -38,7 +40,9 @@ export class IndexerGrpcMitoApi { } try { - const response = await this.client.GetVault(request) + const response = await this.retry(() => + this.client.GetVault(request), + ) return IndexerGrpcMitoTransformer.vaultResponseToVault(response) } catch (e: unknown) { @@ -82,7 +86,9 @@ export class IndexerGrpcMitoApi { } try { - const response = await this.client.GetVaults(request) + const response = await this.retry(() => + this.client.GetVaults(request), + ) return IndexerGrpcMitoTransformer.vaultsResponseToVaults(response) } catch (e: unknown) { @@ -124,7 +130,9 @@ export class IndexerGrpcMitoApi { } try { - const response = await this.client.LPTokenPriceChart(request) + const response = await this.retry(() => + this.client.LPTokenPriceChart(request), + ) return IndexerGrpcMitoTransformer.LPTokenPriceChartResponseToLPTokenPriceChart( response, @@ -168,7 +176,9 @@ export class IndexerGrpcMitoApi { } try { - const response = await this.client.TVLChart(request) + const response = await this.retry(() => + this.client.TVLChart(request), + ) return IndexerGrpcMitoTransformer.LPTokenPriceChartResponseToLPTokenPriceChart( response, @@ -218,7 +228,9 @@ export class IndexerGrpcMitoApi { } try { - const response = await this.client.VaultsByHolderAddress(request) + const response = await this.retry( + () => this.client.VaultsByHolderAddress(request), + ) return IndexerGrpcMitoTransformer.VaultsByHolderAddressResponseToVaultsByHolderAddress( response, @@ -262,7 +274,9 @@ export class IndexerGrpcMitoApi { } try { - const response = await this.client.LPHolders(request) + const response = await this.retry(() => + this.client.LPHolders(request), + ) return IndexerGrpcMitoTransformer.LPHoldersResponseToLPHolders(response) } catch (e: unknown) { @@ -288,7 +302,9 @@ export class IndexerGrpcMitoApi { request.holderAddress = holderAddress try { - const response = await this.client.Portfolio(request) + const response = await this.retry(() => + this.client.Portfolio(request), + ) return IndexerGrpcMitoTransformer.PortfolioResponseToPortfolio(response) } catch (e: unknown) { @@ -316,7 +332,9 @@ export class IndexerGrpcMitoApi { } try { - const response = await this.client.Leaderboard(request) + const response = await this.retry(() => + this.client.Leaderboard(request), + ) return IndexerGrpcMitoTransformer.LeaderboardResponseToLeaderboard( response, @@ -374,7 +392,9 @@ export class IndexerGrpcMitoApi { } try { - const response = await this.client.TransfersHistory(request) + const response = await this.retry(() => + this.client.TransfersHistory(request), + ) return IndexerGrpcMitoTransformer.TransferHistoryResponseToTransfer( response, @@ -420,7 +440,9 @@ export class IndexerGrpcMitoApi { } try { - const response = await this.client.LeaderboardEpochs(request) + const response = await this.retry(() => + this.client.LeaderboardEpochs(request), + ) return IndexerGrpcMitoTransformer.LeaderboardEpochsResponseToLeaderboardEpochs( response, diff --git a/packages/sdk-ts/src/client/indexer/grpc/IndexerGrpcOracleApi.ts b/packages/sdk-ts/src/client/indexer/grpc/IndexerGrpcOracleApi.ts index 1d8dbed78..edaacb793 100644 --- a/packages/sdk-ts/src/client/indexer/grpc/IndexerGrpcOracleApi.ts +++ b/packages/sdk-ts/src/client/indexer/grpc/IndexerGrpcOracleApi.ts @@ -1,23 +1,25 @@ -import { IndexerGrpcOracleTransformer } from '../transformers/IndexerGrpcOracleTransformer' -import { IndexerModule } from '../types' import { GrpcUnaryRequestException, UnspecifiedErrorCode, } from '@injectivelabs/exceptions' -import { getGrpcIndexerWebImpl } from '../../BaseIndexerGrpcWebConsumer' import { InjectiveOracleRpc } from '@injectivelabs/indexer-proto-ts' +import BaseGrpcConsumer from '../../BaseGrpcConsumer' +import { IndexerModule } from '../types' +import { IndexerGrpcOracleTransformer } from '../transformers/IndexerGrpcOracleTransformer' /** * @category Indexer Grpc API */ -export class IndexerGrpcOracleApi { +export class IndexerGrpcOracleApi extends BaseGrpcConsumer { protected module: string = IndexerModule.Oracle protected client: InjectiveOracleRpc.InjectiveOracleRPCClientImpl constructor(endpoint: string) { + super(endpoint) + this.client = new InjectiveOracleRpc.InjectiveOracleRPCClientImpl( - getGrpcIndexerWebImpl(endpoint), + this.getGrpcWebImpl(endpoint), ) } @@ -25,7 +27,9 @@ export class IndexerGrpcOracleApi { const request = InjectiveOracleRpc.OracleListRequest.create() try { - const response = await this.client.OracleList(request) + const response = await this.retry( + () => this.client.OracleList(request), + ) return IndexerGrpcOracleTransformer.oraclesResponseToOracles(response) } catch (e: unknown) { @@ -67,7 +71,9 @@ export class IndexerGrpcOracleApi { } try { - const response = await this.client.Price(request) + const response = await this.retry(() => + this.client.Price(request), + ) return response } catch (e: unknown) { @@ -109,7 +115,9 @@ export class IndexerGrpcOracleApi { } try { - const response = await this.client.Price(request) + const response = await this.retry(() => + this.client.Price(request), + ) return response } catch (e: unknown) { diff --git a/packages/sdk-ts/src/client/indexer/grpc/IndexerGrpcPortfolioApi.ts b/packages/sdk-ts/src/client/indexer/grpc/IndexerGrpcPortfolioApi.ts index 35f978bc7..07191f466 100644 --- a/packages/sdk-ts/src/client/indexer/grpc/IndexerGrpcPortfolioApi.ts +++ b/packages/sdk-ts/src/client/indexer/grpc/IndexerGrpcPortfolioApi.ts @@ -1,23 +1,25 @@ -import { IndexerGrpcAccountPortfolioTransformer } from '../transformers' -import { IndexerModule } from '../types' import { GrpcUnaryRequestException, UnspecifiedErrorCode, } from '@injectivelabs/exceptions' -import { getGrpcIndexerWebImpl } from '../../BaseIndexerGrpcWebConsumer' import { InjectivePortfolioRpc } from '@injectivelabs/indexer-proto-ts' +import BaseGrpcConsumer from '../../BaseGrpcConsumer' +import { IndexerModule } from '../types' +import { IndexerGrpcAccountPortfolioTransformer } from '../transformers' /** * @category Indexer Grpc API */ -export class IndexerGrpcAccountPortfolioApi { +export class IndexerGrpcAccountPortfolioApi extends BaseGrpcConsumer { protected module: string = IndexerModule.Portfolio protected client: InjectivePortfolioRpc.InjectivePortfolioRPCClientImpl constructor(endpoint: string) { + super(endpoint) + this.client = new InjectivePortfolioRpc.InjectivePortfolioRPCClientImpl( - getGrpcIndexerWebImpl(endpoint), + this.getGrpcWebImpl(endpoint), ) } @@ -27,7 +29,10 @@ export class IndexerGrpcAccountPortfolioApi { request.accountAddress = address try { - const response = await this.client.AccountPortfolio(request) + const response = + await this.retry(() => + this.client.AccountPortfolio(request), + ) return IndexerGrpcAccountPortfolioTransformer.accountPortfolioResponseToAccountPortfolio( response, diff --git a/packages/sdk-ts/src/client/indexer/grpc/IndexerGrpcSpotApi.ts b/packages/sdk-ts/src/client/indexer/grpc/IndexerGrpcSpotApi.ts index b7f518747..5ba649dac 100644 --- a/packages/sdk-ts/src/client/indexer/grpc/IndexerGrpcSpotApi.ts +++ b/packages/sdk-ts/src/client/indexer/grpc/IndexerGrpcSpotApi.ts @@ -1,32 +1,33 @@ +import { + GeneralException, + UnspecifiedErrorCode, + GrpcUnaryRequestException, +} from '@injectivelabs/exceptions' +import { OrderSide, OrderState } from '@injectivelabs/ts-types' +import { InjectiveSpotExchangeRpc } from '@injectivelabs/indexer-proto-ts' import { TradeExecutionSide, TradeDirection, TradeExecutionType, } from '../../../types/exchange' +import BaseGrpcConsumer from '../../BaseGrpcConsumer' +import { IndexerModule } from '../types' import { PaginationOption } from '../../../types/pagination' -import { OrderSide, OrderState } from '@injectivelabs/ts-types' import { IndexerGrpcSpotTransformer } from '../transformers' -import { IndexerModule } from '../types' -import { - GeneralException, - UnspecifiedErrorCode, - GrpcUnaryRequestException, -} from '@injectivelabs/exceptions' -import { getGrpcIndexerWebImpl } from '../../BaseIndexerGrpcWebConsumer' -import { InjectiveSpotExchangeRpc } from '@injectivelabs/indexer-proto-ts' /** * @category Indexer Grpc API */ -export class IndexerGrpcSpotApi { +export class IndexerGrpcSpotApi extends BaseGrpcConsumer { protected module: string = IndexerModule.Spot protected client: InjectiveSpotExchangeRpc.InjectiveSpotExchangeRPCClientImpl constructor(endpoint: string) { + super(endpoint) this.client = new InjectiveSpotExchangeRpc.InjectiveSpotExchangeRPCClientImpl( - getGrpcIndexerWebImpl(endpoint), + this.getGrpcWebImpl(endpoint), ) } @@ -51,7 +52,10 @@ export class IndexerGrpcSpotApi { } try { - const response = await this.client.Markets(request) + const response = + await this.retry(() => + this.client.Markets(request), + ) return IndexerGrpcSpotTransformer.marketsResponseToMarkets(response) } catch (e: unknown) { @@ -77,7 +81,10 @@ export class IndexerGrpcSpotApi { request.marketId = marketId try { - const response = await this.client.Market(request) + const response = + await this.retry(() => + this.client.Market(request), + ) return IndexerGrpcSpotTransformer.marketResponseToMarket(response) } catch (e: unknown) { @@ -151,7 +158,10 @@ export class IndexerGrpcSpotApi { } try { - const response = await this.client.Orders(request) + const response = + await this.retry(() => + this.client.Orders(request), + ) return IndexerGrpcSpotTransformer.ordersResponseToOrders(response) } catch (e: unknown) { @@ -244,7 +254,10 @@ export class IndexerGrpcSpotApi { } try { - const response = await this.client.OrdersHistory(request) + const response = + await this.retry(() => + this.client.OrdersHistory(request), + ) return IndexerGrpcSpotTransformer.orderHistoryResponseToOrderHistory( response, @@ -350,7 +363,10 @@ export class IndexerGrpcSpotApi { } try { - const response = await this.client.Trades(request) + const response = + await this.retry(() => + this.client.Trades(request), + ) return IndexerGrpcSpotTransformer.tradesResponseToTrades(response) } catch (e: unknown) { @@ -398,7 +414,10 @@ export class IndexerGrpcSpotApi { } try { - const response = await this.client.SubaccountOrdersList(request) + const response = + await this.retry( + () => this.client.SubaccountOrdersList(request), + ) return IndexerGrpcSpotTransformer.ordersResponseToOrders(response) } catch (e: unknown) { @@ -457,7 +476,10 @@ export class IndexerGrpcSpotApi { } try { - const response = await this.client.SubaccountTradesList(request) + const response = + await this.retry( + () => this.client.SubaccountTradesList(request), + ) return IndexerGrpcSpotTransformer.subaccountTradesListResponseToTradesList( response, @@ -492,7 +514,10 @@ export class IndexerGrpcSpotApi { } try { - const response = await this.client.OrderbooksV2(request) + const response = + await this.retry(() => + this.client.OrderbooksV2(request), + ) return IndexerGrpcSpotTransformer.orderbooksV2ResponseToOrderbooksV2( response, @@ -520,7 +545,10 @@ export class IndexerGrpcSpotApi { request.marketId = marketId try { - const response = await this.client.OrderbookV2(request) + const response = + await this.retry(() => + this.client.OrderbookV2(request), + ) return IndexerGrpcSpotTransformer.orderbookV2ResponseToOrderbookV2( response, diff --git a/packages/sdk-ts/src/client/indexer/rest/IndexerRestDerivativesChronosApi.ts b/packages/sdk-ts/src/client/indexer/rest/IndexerRestDerivativesChronosApi.ts index d02c3a7d0..5a6541cf9 100644 --- a/packages/sdk-ts/src/client/indexer/rest/IndexerRestDerivativesChronosApi.ts +++ b/packages/sdk-ts/src/client/indexer/rest/IndexerRestDerivativesChronosApi.ts @@ -18,10 +18,13 @@ export class IndexerRestDerivativesChronosApi extends BaseRestConsumer { const path = `market_summary` try { - const { data } = (await this.get(path, { - marketId, - resolution: '24h', - })) as ChronosDerivativeMarketSummaryResponse + const { data } = await this.retry( + () => + this.get(path, { + marketId, + resolution: '24h', + }), + ) return data } catch (e: unknown) { @@ -42,9 +45,12 @@ export class IndexerRestDerivativesChronosApi extends BaseRestConsumer { const path = `market_summary_all` try { - const { data } = (await this.get(path, { - resolution: '24h', - })) as AllDerivativeMarketSummaryResponse + const { data } = await this.retry( + () => + this.get(path, { + resolution: '24h', + }), + ) return data } catch (e: unknown) { diff --git a/packages/sdk-ts/src/client/indexer/rest/IndexerRestExplorerApi.ts b/packages/sdk-ts/src/client/indexer/rest/IndexerRestExplorerApi.ts index ff865b981..204725771 100644 --- a/packages/sdk-ts/src/client/indexer/rest/IndexerRestExplorerApi.ts +++ b/packages/sdk-ts/src/client/indexer/rest/IndexerRestExplorerApi.ts @@ -1,3 +1,4 @@ +import { MsgStatus, MsgType } from '@injectivelabs/ts-types' import BaseRestConsumer from '../../BaseRestConsumer' import { Paging, @@ -27,7 +28,6 @@ import { import { IndexerRestExplorerTransformer } from '../transformers' import { Block, ExplorerValidator } from '../types/explorer' import { IndexerModule } from '../types' -import { MsgStatus, MsgType } from '@injectivelabs/ts-types' const explorerEndpointSuffix = 'api/explorer/v1' @@ -47,9 +47,9 @@ export class IndexerRestExplorerApi extends BaseRestConsumer { const endpoint = `blocks/${blockHashHeight}` try { - const response = (await this.get( - `blocks/${blockHashHeight}`, - )) as ExplorerApiResponseWithPagination + const response = await this.retry< + ExplorerApiResponseWithPagination + >(() => this.get(`blocks/${blockHashHeight}`)) return IndexerRestExplorerTransformer.blockWithTxToBlockWithTx( response.data.data, @@ -75,10 +75,15 @@ export class IndexerRestExplorerApi extends BaseRestConsumer { try { const { before, limit } = params || { limit: 12 } - const response = (await this.get(endpoint, { - before, - limit, - })) as ExplorerApiResponseWithPagination + + const response = await this.retry< + ExplorerApiResponseWithPagination + >(() => + this.get(endpoint, { + before, + limit, + }), + ) const { paging, data } = response.data @@ -107,10 +112,15 @@ export class IndexerRestExplorerApi extends BaseRestConsumer { try { const { before, limit } = params || { limit: 12 } - const response = (await this.get(endpoint, { - before, - limit, - })) as ExplorerApiResponseWithPagination + + const response = await this.retry< + ExplorerApiResponseWithPagination + >(() => + this.get(endpoint, { + before, + limit, + }), + ) const { paging, data } = response.data @@ -163,20 +173,22 @@ export class IndexerRestExplorerApi extends BaseRestConsumer { limit: 12, } - const response = (await this.get(endpoint, { - limit, - after, - before, - from_number: fromNumber, - to_number: toNumber, - skip, - status, - type: type ? type.join(',') : undefined, - end_time: endTime, - start_time: startTime, - })) as ExplorerApiResponseWithPagination< - TransactionFromExplorerApiResponse[] - > + const response = await this.retry< + ExplorerApiResponseWithPagination + >(() => + this.get(endpoint, { + limit, + after, + before, + from_number: fromNumber, + to_number: toNumber, + skip, + status, + type: type ? type.join(',') : undefined, + end_time: endTime, + start_time: startTime, + }), + ) const { paging, data } = response.data @@ -234,20 +246,24 @@ export class IndexerRestExplorerApi extends BaseRestConsumer { } = params || { limit: 12, } - const response = (await this.get(endpoint, { - skip, - limit, - after, - before, - from_number: fromNumber, - to_number: toNumber, - status, - type: type ? type.join(',') : undefined, - end_time: endTime, - start_time: startTime, - })) as ExplorerApiResponseWithPagination< - TransactionFromExplorerApiResponse[] - > + + const response = await this.retry< + ExplorerApiResponseWithPagination + >(() => + this.get(endpoint, { + skip, + limit, + after, + before, + from_number: fromNumber, + to_number: toNumber, + status, + type: type ? type.join(',') : undefined, + end_time: endTime, + start_time: startTime, + }), + ) + const { paging, data } = response.data return { @@ -273,9 +289,9 @@ export class IndexerRestExplorerApi extends BaseRestConsumer { const endpoint = `txs/${hash}` try { - const response = (await this.get( - endpoint, - )) as ExplorerApiResponseWithPagination + const response = await this.retry< + ExplorerApiResponseWithPagination + >(() => this.get(endpoint)) return IndexerRestExplorerTransformer.transactionToTransaction( response.data.data, @@ -296,9 +312,9 @@ export class IndexerRestExplorerApi extends BaseRestConsumer { const endpoint = 'validators' try { - const response = (await this.get( - endpoint, - )) as ExplorerApiResponseWithPagination + const response = await this.retry< + ExplorerApiResponseWithPagination + >(() => this.get(endpoint)) if (!response.data || !response.data.data) { return [] @@ -326,11 +342,11 @@ export class IndexerRestExplorerApi extends BaseRestConsumer { const endpoint = `validator_uptime/${validatorConsensusAddress}` try { - const response = (await this.get( - endpoint, - )) as ExplorerApiResponseWithPagination< - ValidatorUptimeFromExplorerApiResponse[] - > + const response = await this.retry< + ExplorerApiResponseWithPagination< + ValidatorUptimeFromExplorerApiResponse[] + > + >(() => this.get(endpoint)) if (!response.data || !response.data.data) { return [] @@ -356,9 +372,9 @@ export class IndexerRestExplorerApi extends BaseRestConsumer { const endpoint = `/wasm/contracts/${contractAddress}` try { - const response = (await this.get( - endpoint, - )) as ExplorerApiResponse + const response = await this.retry< + ExplorerApiResponse + >(() => this.get(endpoint)) return IndexerRestExplorerTransformer.contractToExplorerContract( response.data, @@ -389,12 +405,17 @@ export class IndexerRestExplorerApi extends BaseRestConsumer { try { const { assetsOnly, fromNumber, limit, skip } = params || { limit: 12 } - const response = (await this.get(endpoint, { - skip, - limit, - assets_only: assetsOnly, - from_number: fromNumber, - })) as ExplorerApiResponseWithPagination + + const response = await this.retry< + ExplorerApiResponseWithPagination + >(() => + this.get(endpoint, { + skip, + limit, + assets_only: assetsOnly, + from_number: fromNumber, + }), + ) const { paging, data } = response.data @@ -433,14 +454,19 @@ export class IndexerRestExplorerApi extends BaseRestConsumer { try { const { fromNumber, limit, skip, toNumber } = params || { limit: 12 } - const response = (await this.get(endpoint, { - skip, - limit, - to_number: toNumber, - from_number: fromNumber, - })) as ExplorerApiResponseWithPagination< - ContractTransactionExplorerApiResponse[] - > + + const response = await this.retry< + ExplorerApiResponseWithPagination< + ContractTransactionExplorerApiResponse[] + > + >(() => + this.get(endpoint, { + skip, + limit, + to_number: toNumber, + from_number: fromNumber, + }), + ) const { paging, data } = response.data @@ -469,9 +495,9 @@ export class IndexerRestExplorerApi extends BaseRestConsumer { const endpoint = `/wasm/codes/${codeId}` try { - const response = (await this.get( - endpoint, - )) as ExplorerApiResponse + const response = await this.retry< + ExplorerApiResponse + >(() => this.get(endpoint)) return IndexerRestExplorerTransformer.wasmCodeToExplorerWasmCode( response.data, @@ -501,11 +527,16 @@ export class IndexerRestExplorerApi extends BaseRestConsumer { try { const { fromNumber, limit, toNumber } = params || { limit: 12 } - const response = (await this.get(endpoint, { - limit, - from_number: fromNumber, - to_number: toNumber, - })) as ExplorerApiResponseWithPagination + + const response = await this.retry< + ExplorerApiResponseWithPagination + >(() => + this.get(endpoint, { + limit, + from_number: fromNumber, + to_number: toNumber, + }), + ) const { paging, data } = response.data @@ -534,9 +565,9 @@ export class IndexerRestExplorerApi extends BaseRestConsumer { const endpoint = `/wasm/${address}/cw20-balance` try { - const response = (await this.get(endpoint)) as ExplorerApiResponse< - CW20BalanceExplorerApiResponse[] - > + const response = await this.retry< + ExplorerApiResponse + >(() => this.get(endpoint)) if (response.data.length === 0) { return [] @@ -564,9 +595,9 @@ export class IndexerRestExplorerApi extends BaseRestConsumer { const endpoint = `/wasm/${address}/cw20-balance` try { - const response = (await this.get(endpoint)) as ExplorerApiResponse< - CW20BalanceExplorerApiResponse[] - > + const response = await this.retry< + ExplorerApiResponse + >(() => this.get(endpoint)) if (response.data.length === 0) { return [] diff --git a/packages/sdk-ts/src/client/indexer/rest/IndexerRestLeaderboardChronosApi.ts b/packages/sdk-ts/src/client/indexer/rest/IndexerRestLeaderboardChronosApi.ts index c22fae120..0a00072c1 100644 --- a/packages/sdk-ts/src/client/indexer/rest/IndexerRestLeaderboardChronosApi.ts +++ b/packages/sdk-ts/src/client/indexer/rest/IndexerRestLeaderboardChronosApi.ts @@ -14,9 +14,11 @@ export class IndexerRestLeaderboardChronosApi extends BaseRestConsumer { const path = `` try { - const { data } = (await this.get(path, { - resolution, - })) as ChronosLeaderboardResponse + const { data } = await this.retry(() => + this.get(path, { + resolution, + }), + ) return data } catch (e: unknown) { diff --git a/packages/sdk-ts/src/client/indexer/rest/IndexerRestMarketChronosApi.ts b/packages/sdk-ts/src/client/indexer/rest/IndexerRestMarketChronosApi.ts index 79f306d38..7e723b640 100644 --- a/packages/sdk-ts/src/client/indexer/rest/IndexerRestMarketChronosApi.ts +++ b/packages/sdk-ts/src/client/indexer/rest/IndexerRestMarketChronosApi.ts @@ -33,9 +33,9 @@ export class IndexerRestMarketChronosApi extends BaseRestConsumer { const pathWithParams = `${path}?${stringifiedParams}` try { - const { data } = (await this.get( - pathWithParams, - )) as ChronosMarketHistoryResponse + const { data } = await this.retry(() => + this.get(pathWithParams), + ) return data } catch (e: unknown) { diff --git a/packages/sdk-ts/src/client/indexer/rest/IndexerRestSpotChronosApi.ts b/packages/sdk-ts/src/client/indexer/rest/IndexerRestSpotChronosApi.ts index ba1360fab..fd144dc00 100644 --- a/packages/sdk-ts/src/client/indexer/rest/IndexerRestSpotChronosApi.ts +++ b/packages/sdk-ts/src/client/indexer/rest/IndexerRestSpotChronosApi.ts @@ -18,10 +18,12 @@ export class IndexerRestSpotChronosApi extends BaseRestConsumer { const path = `market_summary` try { - const { data } = (await this.get(path, { - marketId, - resolution: '24h', - })) as ChronosSpotMarketSummaryResponse + const { data } = await this.retry(() => + this.get(path, { + marketId, + resolution: '24h', + }), + ) return data } catch (e: unknown) { @@ -42,9 +44,11 @@ export class IndexerRestSpotChronosApi extends BaseRestConsumer { const path = `market_summary_all` try { - const { data } = (await this.get(path, { - resolution: '24h', - })) as AllSpotMarketSummaryResponse + const { data } = await this.retry(() => + this.get(path, { + resolution: '24h', + }), + ) return data } catch (e: unknown) {