Skip to content

Commit

Permalink
feat: querier active stake delegation
Browse files Browse the repository at this point in the history
  • Loading branch information
bangjelkoski committed Dec 15, 2024
1 parent 0f20f21 commit 564335d
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 1 deletion.
32 changes: 32 additions & 0 deletions packages/sdk-ts/src/client/chain/grpc/ChainGrpcExchangeApi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<InjectiveExchangeV1Beta1Query.QueryActiveStakeGrantResponse>(
() => 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,
})
}
}
}
Original file line number Diff line number Diff line change
@@ -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,
Expand Down Expand Up @@ -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!,
}
}
}

0 comments on commit 564335d

Please sign in to comment.