Skip to content

Commit 564335d

Browse files
committed
feat: querier active stake delegation
1 parent 0f20f21 commit 564335d

File tree

2 files changed

+48
-1
lines changed

2 files changed

+48
-1
lines changed

packages/sdk-ts/src/client/chain/grpc/ChainGrpcExchangeApi.ts

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -329,4 +329,36 @@ export class ChainGrpcExchangeApi extends BaseGrpcConsumer {
329329
})
330330
}
331331
}
332+
333+
async fetchActiveStakeGrant(account: string) {
334+
const request =
335+
InjectiveExchangeV1Beta1Query.QueryActiveStakeGrantRequest.create()
336+
337+
request.grantee = account
338+
339+
try {
340+
const response =
341+
await this.retry<InjectiveExchangeV1Beta1Query.QueryActiveStakeGrantResponse>(
342+
() => this.client.ActiveStakeGrant(request, this.metadata),
343+
)
344+
345+
return ChainGrpcExchangeTransformer.activeStakeGrantResponseToActiveStakeGrant(
346+
response,
347+
)
348+
} catch (e: any) {
349+
if (e instanceof InjectiveExchangeV1Beta1Query.GrpcWebError) {
350+
throw new GrpcUnaryRequestException(new Error(e.toString()), {
351+
code: e.code,
352+
context: 'ActiveStakeGrant',
353+
contextModule: this.module,
354+
})
355+
}
356+
357+
throw new GrpcUnaryRequestException(e as Error, {
358+
code: UnspecifiedErrorCode,
359+
context: 'ActiveStakeGrant',
360+
contextModule: ChainModule.Exchange,
361+
})
362+
}
363+
}
332364
}

packages/sdk-ts/src/client/chain/transformers/ChainGrpcExchangeTransformer.ts

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
1-
import { InjectiveExchangeV1Beta1Query } from '@injectivelabs/core-proto-ts'
1+
import {
2+
InjectiveExchangeV1Beta1Query,
3+
InjectiveExchangeV1Beta1Exchange,
4+
} from '@injectivelabs/core-proto-ts'
25
import { AtomicMarketOrderAccessLevel } from '@injectivelabs/core-proto-ts/cjs/injective/exchange/v1beta1/exchange.js'
36
import {
47
IsOptedOutOfRewards,
@@ -261,4 +264,16 @@ export class ChainGrpcExchangeTransformer {
261264
isOptedOut: response.isOptedOut,
262265
}
263266
}
267+
268+
static activeStakeGrantResponseToActiveStakeGrant(
269+
response: InjectiveExchangeV1Beta1Query.QueryActiveStakeGrantResponse,
270+
): {
271+
grant: InjectiveExchangeV1Beta1Exchange.ActiveGrant
272+
effectiveGrant: InjectiveExchangeV1Beta1Exchange.EffectiveGrant
273+
} {
274+
return {
275+
grant: response.grant!,
276+
effectiveGrant: response.effectiveGrant!,
277+
}
278+
}
264279
}

0 commit comments

Comments
 (0)