diff --git a/packages/nibijs/CHANGELOG.md b/packages/nibijs/CHANGELOG.md index b7c1169b..9afd3732 100644 --- a/packages/nibijs/CHANGELOG.md +++ b/packages/nibijs/CHANGELOG.md @@ -7,6 +7,10 @@ See [Conventional Commits](https://conventionalcommits.org) for commit guideline * . +## v0.19.4 + +* feat: Add gov query extension + ## v0.19.2 * chore: Raise minimum gas limit for transactions with low values for the simulated "gas used". diff --git a/packages/nibijs/package.json b/packages/nibijs/package.json index fdcb804b..385311fe 100644 --- a/packages/nibijs/package.json +++ b/packages/nibijs/package.json @@ -1,7 +1,7 @@ { "name": "@nibiruchain/nibijs", "description": "The TypeScript SDK for the Nibiru blockchain.", - "version": "0.19.3", + "version": "0.19.4", "license": "MIT", "main": "dist/index.js", "types": "dist/index.d.ts", @@ -41,4 +41,4 @@ "typedoc-plugin-markdown": "^3.14.0" }, "gitHead": "4da45aaaf65a44e6b4edc0b5d11ea1083229f977" -} \ No newline at end of file +} diff --git a/packages/nibijs/src/query/gov.ts b/packages/nibijs/src/query/gov.ts new file mode 100644 index 00000000..6a972e67 --- /dev/null +++ b/packages/nibijs/src/query/gov.ts @@ -0,0 +1,129 @@ +import { + createPagination, + createProtobufRpcClient, + GovParamsType, + QueryClient, +} from "@cosmjs/stargate" +import * as cosmosGovQuery from "@nibiruchain/protojs/dist/cosmos/gov/v1beta1/query" +import { ProposalStatus } from "@nibiruchain/protojs/src/cosmos/gov/v1beta1/gov" +import Long from "long" + +export interface GovExtension { + gov: Readonly<{ + params: (paramsType: GovParamsType) => Promise + proposal: (proposalId: number) => Promise + proposals: ( + status: ProposalStatus, + voter: string, + depositor: string, + pagination?: Uint8Array, + ) => Promise + vote: ( + proposalId: number, + voter: string, + ) => Promise + votes: ( + proposalId: number, + pagination?: Uint8Array, + ) => Promise + deposit: ( + proposalId: number, + depositor: string, + ) => Promise + deposits: ( + proposalId: number, + pagination?: Uint8Array, + ) => Promise + tallyResult: ( + proposalId: number, + ) => Promise + }> +} + +export function setupGovExtension(base: QueryClient): GovExtension { + const rpcClient = createProtobufRpcClient(base) + const queryService = new cosmosGovQuery.QueryClientImpl(rpcClient) + + return { + gov: { + proposal: async ( + proposalId: number, + ): Promise => { + const response = await queryService.Proposal({ + proposalId: Long.fromValue(proposalId), + }) + return response + }, + proposals: async ( + status: ProposalStatus, + voter: string, + depositor: string, + pagination?: Uint8Array, + ): Promise => { + const response = await queryService.Proposals({ + proposalStatus: status, + voter, + depositor, + pagination: createPagination(pagination), + }) + return response + }, + vote: async ( + proposalId: number, + voter: string, + ): Promise => { + const response = await queryService.Vote({ + proposalId: Long.fromValue(proposalId), + voter, + }) + return response + }, + votes: async ( + proposalId: number, + pagination?: Uint8Array, + ): Promise => { + const response = await queryService.Votes({ + proposalId: Long.fromValue(proposalId), + pagination: createPagination(pagination), + }) + return response + }, + params: async ( + paramsType: GovParamsType, + ): Promise => { + const response = await queryService.Params({ + paramsType, + }) + return response + }, + deposit: async ( + proposalId: number, + depositor: string, + ): Promise => { + const response = await queryService.Deposit({ + proposalId: Long.fromValue(proposalId), + depositor, + }) + return response + }, + deposits: async ( + proposalId: number, + pagination?: Uint8Array, + ): Promise => { + const response = await queryService.Deposits({ + proposalId: Long.fromValue(proposalId), + pagination: createPagination(pagination), + }) + return response + }, + tallyResult: async ( + proposalId: number, + ): Promise => { + const response = await queryService.TallyResult({ + proposalId: Long.fromValue(proposalId), + }) + return response + }, + }, + } +} diff --git a/packages/nibijs/src/query/query.ts b/packages/nibijs/src/query/query.ts index 5d7aa8e8..48f4d959 100644 --- a/packages/nibijs/src/query/query.ts +++ b/packages/nibijs/src/query/query.ts @@ -14,6 +14,7 @@ import { OracleExtension, setupOracleExtension } from "./oracle" import { setupStakingExtension, StakingExtension } from "./staking" import { setupVpoolExtension, VpoolExtension } from "./vpool" import { DistributionExtension, setupDistributionExtension } from "./distribution" +import { GovExtension, setupGovExtension } from "./gov" export type ExtendedQueryClient = BankExtension & QueryClient & @@ -24,7 +25,8 @@ export type ExtendedQueryClient = BankExtension & OracleExtension & EpochsExtension & StakingExtension & - DistributionExtension + DistributionExtension & + GovExtension export interface IQueryCmd { /** @@ -90,6 +92,7 @@ export class QueryCmd implements IQueryCmd { setupEpochsExtension, setupStakingExtension, setupDistributionExtension, + setupGovExtension, ) } diff --git a/packages/nibijs/src/test/query.test.ts b/packages/nibijs/src/test/query.test.ts index 06dd2622..2c55a3e2 100644 --- a/packages/nibijs/src/test/query.test.ts +++ b/packages/nibijs/src/test/query.test.ts @@ -213,3 +213,16 @@ describe("distribution module queries", () => { }) }) }) + +describe("gov module queries", () => { + test("gov params", async () => { + const { client: query } = await newQueryCmd(TEST_CHAIN) + const resp = await query.gov.params("voting") + const { votingParams } = resp + expect(votingParams).toBeDefined() + const properties: string[] = ["votingPeriod"] + properties.forEach((prop) => { + expect(votingParams).toHaveProperty(prop) + }) + }) +})