From 564335d12df0e8b5ba7d8b4cf1fe403cdf5d850c Mon Sep 17 00:00:00 2001 From: Bojan Angjelkoski Date: Sun, 15 Dec 2024 21:25:00 +0100 Subject: [PATCH] feat: querier active stake delegation --- .../client/chain/grpc/ChainGrpcExchangeApi.ts | 32 +++++++++++++++++++ .../ChainGrpcExchangeTransformer.ts | 17 +++++++++- 2 files changed, 48 insertions(+), 1 deletion(-) diff --git a/packages/sdk-ts/src/client/chain/grpc/ChainGrpcExchangeApi.ts b/packages/sdk-ts/src/client/chain/grpc/ChainGrpcExchangeApi.ts index 2010ca317..feb326e12 100644 --- a/packages/sdk-ts/src/client/chain/grpc/ChainGrpcExchangeApi.ts +++ b/packages/sdk-ts/src/client/chain/grpc/ChainGrpcExchangeApi.ts @@ -329,4 +329,36 @@ export class ChainGrpcExchangeApi extends BaseGrpcConsumer { }) } } + + async fetchActiveStakeGrant(account: string) { + const request = + InjectiveExchangeV1Beta1Query.QueryActiveStakeGrantRequest.create() + + request.grantee = account + + try { + const response = + await this.retry( + () => this.client.ActiveStakeGrant(request, this.metadata), + ) + + return ChainGrpcExchangeTransformer.activeStakeGrantResponseToActiveStakeGrant( + response, + ) + } catch (e: any) { + if (e instanceof InjectiveExchangeV1Beta1Query.GrpcWebError) { + throw new GrpcUnaryRequestException(new Error(e.toString()), { + code: e.code, + context: 'ActiveStakeGrant', + contextModule: this.module, + }) + } + + throw new GrpcUnaryRequestException(e as Error, { + code: UnspecifiedErrorCode, + context: 'ActiveStakeGrant', + contextModule: ChainModule.Exchange, + }) + } + } } diff --git a/packages/sdk-ts/src/client/chain/transformers/ChainGrpcExchangeTransformer.ts b/packages/sdk-ts/src/client/chain/transformers/ChainGrpcExchangeTransformer.ts index 547709c89..679918812 100644 --- a/packages/sdk-ts/src/client/chain/transformers/ChainGrpcExchangeTransformer.ts +++ b/packages/sdk-ts/src/client/chain/transformers/ChainGrpcExchangeTransformer.ts @@ -1,4 +1,7 @@ -import { InjectiveExchangeV1Beta1Query } from '@injectivelabs/core-proto-ts' +import { + InjectiveExchangeV1Beta1Query, + InjectiveExchangeV1Beta1Exchange, +} from '@injectivelabs/core-proto-ts' import { AtomicMarketOrderAccessLevel } from '@injectivelabs/core-proto-ts/cjs/injective/exchange/v1beta1/exchange.js' import { IsOptedOutOfRewards, @@ -261,4 +264,16 @@ export class ChainGrpcExchangeTransformer { isOptedOut: response.isOptedOut, } } + + static activeStakeGrantResponseToActiveStakeGrant( + response: InjectiveExchangeV1Beta1Query.QueryActiveStakeGrantResponse, + ): { + grant: InjectiveExchangeV1Beta1Exchange.ActiveGrant + effectiveGrant: InjectiveExchangeV1Beta1Exchange.EffectiveGrant + } { + return { + grant: response.grant!, + effectiveGrant: response.effectiveGrant!, + } + } }