diff --git a/packages/sdk-ts/package.json b/packages/sdk-ts/package.json index e09268ea9..c0bcb5a75 100644 --- a/packages/sdk-ts/package.json +++ b/packages/sdk-ts/package.json @@ -44,7 +44,7 @@ "@injectivelabs/grpc-web": "^0.0.1", "@injectivelabs/grpc-web-node-http-transport": "^0.0.2", "@injectivelabs/grpc-web-react-native-transport": "^0.0.2", - "@injectivelabs/indexer-proto-ts": "1.11.49", + "@injectivelabs/indexer-proto-ts": "1.11.53", "@injectivelabs/mito-proto-ts": "1.0.65", "@injectivelabs/networks": "^1.14.14", "@injectivelabs/test-utils": "^1.14.14", diff --git a/packages/sdk-ts/src/client/indexer/grpc/IndexerGrpcArchiverApi.spec.ts b/packages/sdk-ts/src/client/indexer/grpc/IndexerGrpcArchiverApi.spec.ts index 0d2353de4..c1cdfa94f 100644 --- a/packages/sdk-ts/src/client/indexer/grpc/IndexerGrpcArchiverApi.spec.ts +++ b/packages/sdk-ts/src/client/indexer/grpc/IndexerGrpcArchiverApi.spec.ts @@ -1,12 +1,13 @@ import { getNetworkEndpoints, Network } from '@injectivelabs/networks' +import { INJ_DENOM } from '@injectivelabs/utils' import { mockFactory } from '@injectivelabs/test-utils' import { IndexerGrpcArchiverTransformer } from '../transformers' import { IndexerGrpcArchiverApi } from './IndexerGrpcArchiverApi' const account = mockFactory.injectiveAddress const resolution = '1D' -const startDate = 1622505600 -const endDate = 1625097600 +const startDate = '1622505600' +const endDate = '1625097600' const limit = 10 const endpoints = getNetworkEndpoints(Network.MainnetSentry) const indexerGrpcArchiverApi = new IndexerGrpcArchiverApi(endpoints.indexer) @@ -173,4 +174,26 @@ describe('IndexerGrpcArchiverApi', () => { ) } }) + + test('fetchDenomHolders', async () => { + try { + const response = await indexerGrpcArchiverApi.fetchDenomHolders({ + denom: INJ_DENOM, + limit, + }) + + expect(response).toBeDefined() + expect(response).toEqual( + expect.objectContaining< + ReturnType< + typeof IndexerGrpcArchiverTransformer.grpcDenomHoldersResponseToDenomHolders + > + >(response), + ) + } catch (e) { + console.error( + 'IndexerGrpcArchiverApi.fetchDenomHolders => ' + (e as any).message, + ) + } + }) }) diff --git a/packages/sdk-ts/src/client/indexer/grpc/IndexerGrpcArchiverApi.ts b/packages/sdk-ts/src/client/indexer/grpc/IndexerGrpcArchiverApi.ts index db16c1c33..a3d8aa156 100644 --- a/packages/sdk-ts/src/client/indexer/grpc/IndexerGrpcArchiverApi.ts +++ b/packages/sdk-ts/src/client/indexer/grpc/IndexerGrpcArchiverApi.ts @@ -305,4 +305,51 @@ export class IndexerGrpcArchiverApi extends BaseGrpcConsumer { }) } } + + async fetchDenomHolders({ + denom, + token, + limit, + }: { + denom: string + token?: string + limit?: number + }) { + const request = InjectiveArchiverRpc.DenomHoldersRequest.create() + + request.denom = denom + + if (token) { + request.token = token + } + + if (limit) { + request.limit = limit + } + + try { + const response = + await this.retry(() => + this.client.DenomHolders(request), + ) + + return IndexerGrpcArchiverTransformer.grpcDenomHoldersResponseToDenomHolders( + response, + ) + } catch (e: unknown) { + if (e instanceof InjectiveArchiverRpc.GrpcWebError) { + throw new GrpcUnaryRequestException(new Error(e.toString()), { + code: e.code, + context: 'DenomHolders', + contextModule: this.module, + }) + } + + throw new GrpcUnaryRequestException(e as Error, { + code: UnspecifiedErrorCode, + context: 'DenomHolders', + contextModule: this.module, + }) + } + } } diff --git a/packages/sdk-ts/src/client/indexer/grpc/IndexerGrpcExplorerApi.spec.ts b/packages/sdk-ts/src/client/indexer/grpc/IndexerGrpcExplorerApi.spec.ts index 91e14d10e..803da57fb 100644 --- a/packages/sdk-ts/src/client/indexer/grpc/IndexerGrpcExplorerApi.spec.ts +++ b/packages/sdk-ts/src/client/indexer/grpc/IndexerGrpcExplorerApi.spec.ts @@ -222,4 +222,23 @@ describe('IndexerGrpcExplorerApi', () => { ) } }) + + test('fetchExplorerStats', async () => { + try { + const response = await indexerGrpcExplorerApi.fetchExplorerStats() + + expect(response).toBeDefined() + expect(response).toEqual( + expect.objectContaining< + ReturnType< + typeof IndexerGrpcExplorerTransformer.getExplorerStatsResponseToExplorerStats + > + >(response), + ) + } catch (e) { + console.error( + 'IndexerGrpcExplorerApi.fetchExplorerStats => ' + (e as any).message, + ) + } + }) }) diff --git a/packages/sdk-ts/src/client/indexer/grpc/IndexerGrpcExplorerApi.ts b/packages/sdk-ts/src/client/indexer/grpc/IndexerGrpcExplorerApi.ts index 4dd9be3bb..3cd189bf0 100644 --- a/packages/sdk-ts/src/client/indexer/grpc/IndexerGrpcExplorerApi.ts +++ b/packages/sdk-ts/src/client/indexer/grpc/IndexerGrpcExplorerApi.ts @@ -540,4 +540,32 @@ export class IndexerGrpcExplorerApi extends BaseGrpcConsumer { }) } } + + async fetchExplorerStats() { + const request = InjectiveExplorerRpc.GetStatsRequest.create() + + try { + const response = await this.retry( + () => this.client.GetStats(request), + ) + + return IndexerGrpcExplorerTransformer.getExplorerStatsResponseToExplorerStats( + response, + ) + } catch (e: unknown) { + if (e instanceof InjectiveExplorerRpc.GrpcWebError) { + throw new GrpcUnaryRequestException(new Error(e.toString()), { + code: e.code, + context: 'GetExplorerStats', + contextModule: this.module, + }) + } + + throw new GrpcUnaryRequestException(e as Error, { + code: UnspecifiedErrorCode, + context: 'GetExplorerStats', + contextModule: this.module, + }) + } + } } diff --git a/packages/sdk-ts/src/client/indexer/grpc/IndexerGrpcPortfolioApi.ts b/packages/sdk-ts/src/client/indexer/grpc/IndexerGrpcPortfolioApi.ts index 26f4a71c1..7b532fb90 100644 --- a/packages/sdk-ts/src/client/indexer/grpc/IndexerGrpcPortfolioApi.ts +++ b/packages/sdk-ts/src/client/indexer/grpc/IndexerGrpcPortfolioApi.ts @@ -104,51 +104,4 @@ export class IndexerGrpcAccountPortfolioApi extends BaseGrpcConsumer { }) } } - - async fetchAccountPortfolioTokenHolders({ - denom, - cursor, - limit, - }: { - denom: string - cursor?: string - limit?: number - }) { - const request = InjectivePortfolioRpc.TokenHoldersRequest.create() - - request.denom = denom - - if (cursor) { - request.cursor = cursor - } - - if (limit) { - request.limit = limit - } - - try { - const response = - await this.retry(() => - this.client.TokenHolders(request), - ) - - return IndexerGrpcAccountPortfolioTransformer.tokenHoldersResponseToTokenHolders( - response, - ) - } catch (e: unknown) { - if (e instanceof InjectivePortfolioRpc.GrpcWebError) { - throw new GrpcUnaryRequestException(new Error(e.toString()), { - code: e.code, - context: 'TokenHolders', - contextModule: this.module, - }) - } - - throw new GrpcUnaryRequestException(e as Error, { - code: UnspecifiedErrorCode, - context: 'TokenHolders', - contextModule: this.module, - }) - } - } } diff --git a/packages/sdk-ts/src/client/indexer/transformers/IndexerAccountPortfolioTransformer.ts b/packages/sdk-ts/src/client/indexer/transformers/IndexerAccountPortfolioTransformer.ts index 4f269b2e6..1844c6026 100644 --- a/packages/sdk-ts/src/client/indexer/transformers/IndexerAccountPortfolioTransformer.ts +++ b/packages/sdk-ts/src/client/indexer/transformers/IndexerAccountPortfolioTransformer.ts @@ -1,7 +1,6 @@ import { Coin } from '@injectivelabs/ts-types' import { GrpcCoin } from '../../../types' import { - TokenHolders, PositionsWithUPNL, AccountPortfolioV2, SubaccountDepositV2, @@ -118,16 +117,4 @@ export class IndexerGrpcAccountPortfolioTransformer { : undefined, } } - - static tokenHoldersResponseToTokenHolders( - response: InjectivePortfolioRpc.TokenHoldersResponse, - ): TokenHolders { - return { - holders: response.holders.map((holder) => ({ - accountAddress: holder.accountAddress, - balance: holder.balance, - })), - nextCursors: response.nextCursors, - } - } } diff --git a/packages/sdk-ts/src/client/indexer/transformers/IndexerGrpcArchiverTransformer.ts b/packages/sdk-ts/src/client/indexer/transformers/IndexerGrpcArchiverTransformer.ts index c06390233..04cdaf0b3 100644 --- a/packages/sdk-ts/src/client/indexer/transformers/IndexerGrpcArchiverTransformer.ts +++ b/packages/sdk-ts/src/client/indexer/transformers/IndexerGrpcArchiverTransformer.ts @@ -1,10 +1,11 @@ import { + DenomHolders, HistoricalRPNL, - HistoricalBalance, - HistoricalVolumes, LeaderboardRow, PnlLeaderboard, VolLeaderboard, + HistoricalBalance, + HistoricalVolumes, } from '../types/archiver' import { InjectiveArchiverRpc } from '@injectivelabs/indexer-proto-ts' @@ -133,4 +134,16 @@ export class IndexerGrpcArchiverTransformer { ), } } + + static grpcDenomHoldersResponseToDenomHolders( + response: InjectiveArchiverRpc.DenomHoldersResponse, + ): DenomHolders { + return { + holders: response.holders.map((holder) => ({ + accountAddress: holder.accountAddress, + balance: holder.balance, + })), + next: response.next, + } + } } diff --git a/packages/sdk-ts/src/client/indexer/transformers/IndexerGrpcExplorerTransformer.ts b/packages/sdk-ts/src/client/indexer/transformers/IndexerGrpcExplorerTransformer.ts index a2cd1b184..4b20f399b 100644 --- a/packages/sdk-ts/src/client/indexer/transformers/IndexerGrpcExplorerTransformer.ts +++ b/packages/sdk-ts/src/client/indexer/transformers/IndexerGrpcExplorerTransformer.ts @@ -1,25 +1,26 @@ import { - BankMsgSendTransaction, Block, - BlockWithTxs, GasFee, - GrpcBankMsgSendMessage, GrpcGasFee, - GrpcIndexerValidatorDescription, - GrpcValidatorSlashingEvent, - GrpcValidatorUptime, Transaction, - ExplorerValidator, - ExplorerValidatorDescription, - ValidatorSlashingEvent, - ValidatorUptime, + BlockWithTxs, IBCTransferTx, + ExplorerStats, PeggyDepositTx, + ValidatorUptime, + ExplorerValidator, PeggyWithdrawalTx, GrpcIBCTransferTx, GrpcPeggyDepositTx, + GrpcValidatorUptime, GrpcPeggyWithdrawalTx, + BankMsgSendTransaction, + GrpcBankMsgSendMessage, + ValidatorSlashingEvent, IndexerStreamTransaction, + GrpcValidatorSlashingEvent, + ExplorerValidatorDescription, + GrpcIndexerValidatorDescription, } from '../types/explorer' import { grpcPagingToPaging } from '../../../utils' import { InjectiveExplorerRpc } from '@injectivelabs/indexer-proto-ts' @@ -395,4 +396,20 @@ export class IndexerGrpcExplorerTransformer { updatedAt: grpcPeggyWithdrawalTx.updatedAt, } } + + static getExplorerStatsResponseToExplorerStats( + response: InjectiveExplorerRpc.GetStatsResponse, + ): ExplorerStats { + return { + assets: response.assets, + txsTotal: response.txsTotal, + addresses: response.addresses, + injSupply: response.injSupply, + txsInPast24Hours: response.txs24H, + txsInPast30Days: response.txs30D, + blockCountInPast24Hours: response.blockCount24H, + txsPerSecondInPast24Hours: response.txsPs24H, + txsPerSecondInPast100Blocks: response.txsPs100B, + } + } } diff --git a/packages/sdk-ts/src/client/indexer/types/account-portfolio.ts b/packages/sdk-ts/src/client/indexer/types/account-portfolio.ts index 2c2199532..dc80eccaf 100644 --- a/packages/sdk-ts/src/client/indexer/types/account-portfolio.ts +++ b/packages/sdk-ts/src/client/indexer/types/account-portfolio.ts @@ -31,20 +31,9 @@ export interface AccountPortfolioBalances { subaccountsList: PortfolioSubaccountBalanceV2[] } -export interface Holder { - accountAddress: string - balance: string -} - -export interface TokenHolders { - holders: Holder[] - nextCursors: string[] -} - export type GrpcPositionV2 = InjectivePortfolioRpc.DerivativePosition export type GrpcAccountPortfolioV2 = InjectivePortfolioRpc.Portfolio export type GrpcSubaccountDepositV2 = InjectivePortfolioRpc.SubaccountDeposit export type GrpcPositionsWithUPNL = InjectivePortfolioRpc.PositionsWithUPNL export type GrpcPortfolioSubaccountBalanceV2 = InjectivePortfolioRpc.SubaccountBalanceV2 -export type GrpcTokenHolders = InjectivePortfolioRpc.TokenHoldersResponse diff --git a/packages/sdk-ts/src/client/indexer/types/archiver.ts b/packages/sdk-ts/src/client/indexer/types/archiver.ts index b6f4245a9..e29eb49d4 100644 --- a/packages/sdk-ts/src/client/indexer/types/archiver.ts +++ b/packages/sdk-ts/src/client/indexer/types/archiver.ts @@ -34,6 +34,16 @@ export interface VolLeaderboard { leaders: LeaderboardRow[] } +export interface Holder { + accountAddress: string + balance: string +} + +export interface DenomHolders { + holders: Holder[] + next: string[] +} + export type GrpcHistoricalRPNL = InjectiveArchiverRpc.HistoricalRPNL export type GrpcHistoricalBalance = InjectiveArchiverRpc.HistoricalBalance export type GrpcHistoricalVolumes = InjectiveArchiverRpc.HistoricalVolumes @@ -44,3 +54,4 @@ export type GrpcVolLeaderboard = | InjectiveArchiverRpc.VolLeaderboardResponse | InjectiveArchiverRpc.VolLeaderboardFixedResolutionResponse export type GrpcLeaderboardRow = InjectiveArchiverRpc.LeaderboardRow +export type GrpcDenomHolders = InjectiveArchiverRpc.DenomHoldersResponse diff --git a/packages/sdk-ts/src/client/indexer/types/explorer.ts b/packages/sdk-ts/src/client/indexer/types/explorer.ts index 450a68dcc..1c13f604d 100644 --- a/packages/sdk-ts/src/client/indexer/types/explorer.ts +++ b/packages/sdk-ts/src/client/indexer/types/explorer.ts @@ -379,6 +379,18 @@ export interface CosmWasmChecksum { hash: string } +export interface ExplorerStats { + assets: string + txsTotal: string + addresses: string + injSupply: string + txsInPast30Days: string + txsInPast24Hours: string + blockCountInPast24Hours: string + txsPerSecondInPast24Hours: string + txsPerSecondInPast100Blocks: string +} + export type GrpcIBCTransferTx = InjectiveExplorerRpc.IBCTransferTx export type GrpcPeggyDepositTx = InjectiveExplorerRpc.PeggyDepositTx export type GrpcPeggyWithdrawalTx = InjectiveExplorerRpc.PeggyWithdrawalTx @@ -387,3 +399,4 @@ export type GrpcValidatorUptime = InjectiveExplorerRpc.ValidatorUptime export type GrpcIndexerValidatorDescription = InjectiveExplorerRpc.ValidatorDescription export type GrpcValidatorSlashingEvent = InjectiveExplorerRpc.SlashingEvent +export type GrpcExplorerStats = InjectiveExplorerRpc.GetStatsResponse diff --git a/yarn.lock b/yarn.lock index 7c3bd3a7d..ddaa4b4fb 100644 --- a/yarn.lock +++ b/yarn.lock @@ -2211,10 +2211,10 @@ dependencies: browser-headers "^0.4.1" -"@injectivelabs/indexer-proto-ts@1.11.49": - version "1.11.49" - resolved "https://registry.yarnpkg.com/@injectivelabs/indexer-proto-ts/-/indexer-proto-ts-1.11.49.tgz#cefe5bdc2ffe75754c14a43cb586469eef3f391b" - integrity sha512-CLSYpkYJ12QWgzqA3a1AHO9HoMdz1zMOunf3cee1OtA4EdZGp+0KsenS46gCulzqBB6N6l3si6GbwHzlT2nFZQ== +"@injectivelabs/indexer-proto-ts@1.11.53": + version "1.11.53" + resolved "https://registry.yarnpkg.com/@injectivelabs/indexer-proto-ts/-/indexer-proto-ts-1.11.53.tgz#9dba45c5af0c719505090b47cc4cdcd17da0cb8c" + integrity sha512-hc67sPi5Pr0iZO2SLgsk43f+n7f1ZGkx82ux4kXtE61lTuHPRWfweel1zHQfo+bmnD8wO3MKD2TZWTeoWbsyhQ== dependencies: "@injectivelabs/grpc-web" "^0.0.1" google-protobuf "^3.14.0"