From aa33e69fbf13c14a8833552a52989feeb19b1d24 Mon Sep 17 00:00:00 2001 From: Fabrice Bascoulergue Date: Thu, 9 Sep 2021 18:25:33 +0200 Subject: [PATCH] Add mint capabilities to client --- scripts/define-proto.sh | 2 + src/client/LumClient.ts | 5 +- src/codec/cosmos/mint/v1beta1/mint.ts | 257 ++++++++++++++++ src/codec/cosmos/mint/v1beta1/query.ts | 404 +++++++++++++++++++++++++ src/extensions/index.ts | 1 + src/extensions/mint.ts | 41 +++ tests/client.test.ts | 19 ++ 7 files changed, 727 insertions(+), 2 deletions(-) create mode 100644 src/codec/cosmos/mint/v1beta1/mint.ts create mode 100644 src/codec/cosmos/mint/v1beta1/query.ts create mode 100644 src/extensions/mint.ts diff --git a/scripts/define-proto.sh b/scripts/define-proto.sh index 90f70c1..680105d 100644 --- a/scripts/define-proto.sh +++ b/scripts/define-proto.sh @@ -39,6 +39,8 @@ protoc \ "$COSMOS_PROTO_DIR/cosmos/gov/v1beta1/query.proto" \ "$COSMOS_PROTO_DIR/cosmos/gov/v1beta1/gov.proto" \ "$COSMOS_PROTO_DIR/cosmos/gov/v1beta1/tx.proto" \ + "$COSMOS_PROTO_DIR/cosmos/mint/v1beta1/query.proto" \ + "$COSMOS_PROTO_DIR/cosmos/mint/v1beta1/mint.proto" \ "$COSMOS_PROTO_DIR/cosmos/tx/signing/v1beta1/signing.proto" \ "$COSMOS_PROTO_DIR/cosmos/tx/v1beta1/tx.proto" \ "$COSMOS_PROTO_DIR/cosmos/vesting/v1beta1/vesting.proto" \ diff --git a/src/client/LumClient.ts b/src/client/LumClient.ts index 8ecb478..65be5b6 100644 --- a/src/client/LumClient.ts +++ b/src/client/LumClient.ts @@ -17,11 +17,11 @@ import { import { BaseAccount } from '../codec/cosmos/auth/v1beta1/auth'; import { LumWallet, LumUtils, LumTypes, LumRegistry } from '..'; -import { BeamExtension, setupBeamExtension as BeamSetupBeamExtension } from '../extensions'; +import { BeamExtension, setupBeamExtension as BeamSetupBeamExtension, MintExtension, setupMintExtension as MintSetupExtension } from '../extensions'; export class LumClient { readonly tmClient: Tendermint34Client; - readonly queryClient: StargateQueryClient & AuthExtension & BankExtension & DistributionExtension & StakingExtension & GovExtension & BeamExtension; + readonly queryClient: StargateQueryClient & AuthExtension & BankExtension & DistributionExtension & StakingExtension & GovExtension & MintExtension & BeamExtension; private chainId?: string; /** @@ -38,6 +38,7 @@ export class LumClient { StargateDistributionExtension, StargateStakingExtension, StargateGovExtension, + MintSetupExtension, BeamSetupBeamExtension, ); diff --git a/src/codec/cosmos/mint/v1beta1/mint.ts b/src/codec/cosmos/mint/v1beta1/mint.ts new file mode 100644 index 0000000..fd582db --- /dev/null +++ b/src/codec/cosmos/mint/v1beta1/mint.ts @@ -0,0 +1,257 @@ +/* eslint-disable */ +import Long from 'long'; +import _m0 from 'protobufjs/minimal'; + +export const protobufPackage = 'cosmos.mint.v1beta1'; + +/** Minter represents the minting state. */ +export interface Minter { + /** current annual inflation rate */ + inflation: string; + /** current annual expected provisions */ + annualProvisions: string; +} + +/** Params holds parameters for the mint module. */ +export interface Params { + /** type of coin to mint */ + mintDenom: string; + /** maximum annual change in inflation rate */ + inflationRateChange: string; + /** maximum inflation rate */ + inflationMax: string; + /** minimum inflation rate */ + inflationMin: string; + /** goal of percent bonded atoms */ + goalBonded: string; + /** expected blocks per year */ + blocksPerYear: Long; +} + +const baseMinter: object = { inflation: '', annualProvisions: '' }; + +export const Minter = { + encode(message: Minter, writer: _m0.Writer = _m0.Writer.create()): _m0.Writer { + if (message.inflation !== '') { + writer.uint32(10).string(message.inflation); + } + if (message.annualProvisions !== '') { + writer.uint32(18).string(message.annualProvisions); + } + return writer; + }, + + decode(input: _m0.Reader | Uint8Array, length?: number): Minter { + const reader = input instanceof _m0.Reader ? input : new _m0.Reader(input); + let end = length === undefined ? reader.len : reader.pos + length; + const message = { ...baseMinter } as Minter; + while (reader.pos < end) { + const tag = reader.uint32(); + switch (tag >>> 3) { + case 1: + message.inflation = reader.string(); + break; + case 2: + message.annualProvisions = reader.string(); + break; + default: + reader.skipType(tag & 7); + break; + } + } + return message; + }, + + fromJSON(object: any): Minter { + const message = { ...baseMinter } as Minter; + if (object.inflation !== undefined && object.inflation !== null) { + message.inflation = String(object.inflation); + } else { + message.inflation = ''; + } + if (object.annualProvisions !== undefined && object.annualProvisions !== null) { + message.annualProvisions = String(object.annualProvisions); + } else { + message.annualProvisions = ''; + } + return message; + }, + + toJSON(message: Minter): unknown { + const obj: any = {}; + message.inflation !== undefined && (obj.inflation = message.inflation); + message.annualProvisions !== undefined && (obj.annualProvisions = message.annualProvisions); + return obj; + }, + + fromPartial(object: DeepPartial): Minter { + const message = { ...baseMinter } as Minter; + if (object.inflation !== undefined && object.inflation !== null) { + message.inflation = object.inflation; + } else { + message.inflation = ''; + } + if (object.annualProvisions !== undefined && object.annualProvisions !== null) { + message.annualProvisions = object.annualProvisions; + } else { + message.annualProvisions = ''; + } + return message; + }, +}; + +const baseParams: object = { mintDenom: '', inflationRateChange: '', inflationMax: '', inflationMin: '', goalBonded: '', blocksPerYear: Long.UZERO }; + +export const Params = { + encode(message: Params, writer: _m0.Writer = _m0.Writer.create()): _m0.Writer { + if (message.mintDenom !== '') { + writer.uint32(10).string(message.mintDenom); + } + if (message.inflationRateChange !== '') { + writer.uint32(18).string(message.inflationRateChange); + } + if (message.inflationMax !== '') { + writer.uint32(26).string(message.inflationMax); + } + if (message.inflationMin !== '') { + writer.uint32(34).string(message.inflationMin); + } + if (message.goalBonded !== '') { + writer.uint32(42).string(message.goalBonded); + } + if (!message.blocksPerYear.isZero()) { + writer.uint32(48).uint64(message.blocksPerYear); + } + return writer; + }, + + decode(input: _m0.Reader | Uint8Array, length?: number): Params { + const reader = input instanceof _m0.Reader ? input : new _m0.Reader(input); + let end = length === undefined ? reader.len : reader.pos + length; + const message = { ...baseParams } as Params; + while (reader.pos < end) { + const tag = reader.uint32(); + switch (tag >>> 3) { + case 1: + message.mintDenom = reader.string(); + break; + case 2: + message.inflationRateChange = reader.string(); + break; + case 3: + message.inflationMax = reader.string(); + break; + case 4: + message.inflationMin = reader.string(); + break; + case 5: + message.goalBonded = reader.string(); + break; + case 6: + message.blocksPerYear = reader.uint64() as Long; + break; + default: + reader.skipType(tag & 7); + break; + } + } + return message; + }, + + fromJSON(object: any): Params { + const message = { ...baseParams } as Params; + if (object.mintDenom !== undefined && object.mintDenom !== null) { + message.mintDenom = String(object.mintDenom); + } else { + message.mintDenom = ''; + } + if (object.inflationRateChange !== undefined && object.inflationRateChange !== null) { + message.inflationRateChange = String(object.inflationRateChange); + } else { + message.inflationRateChange = ''; + } + if (object.inflationMax !== undefined && object.inflationMax !== null) { + message.inflationMax = String(object.inflationMax); + } else { + message.inflationMax = ''; + } + if (object.inflationMin !== undefined && object.inflationMin !== null) { + message.inflationMin = String(object.inflationMin); + } else { + message.inflationMin = ''; + } + if (object.goalBonded !== undefined && object.goalBonded !== null) { + message.goalBonded = String(object.goalBonded); + } else { + message.goalBonded = ''; + } + if (object.blocksPerYear !== undefined && object.blocksPerYear !== null) { + message.blocksPerYear = Long.fromString(object.blocksPerYear); + } else { + message.blocksPerYear = Long.UZERO; + } + return message; + }, + + toJSON(message: Params): unknown { + const obj: any = {}; + message.mintDenom !== undefined && (obj.mintDenom = message.mintDenom); + message.inflationRateChange !== undefined && (obj.inflationRateChange = message.inflationRateChange); + message.inflationMax !== undefined && (obj.inflationMax = message.inflationMax); + message.inflationMin !== undefined && (obj.inflationMin = message.inflationMin); + message.goalBonded !== undefined && (obj.goalBonded = message.goalBonded); + message.blocksPerYear !== undefined && (obj.blocksPerYear = (message.blocksPerYear || Long.UZERO).toString()); + return obj; + }, + + fromPartial(object: DeepPartial): Params { + const message = { ...baseParams } as Params; + if (object.mintDenom !== undefined && object.mintDenom !== null) { + message.mintDenom = object.mintDenom; + } else { + message.mintDenom = ''; + } + if (object.inflationRateChange !== undefined && object.inflationRateChange !== null) { + message.inflationRateChange = object.inflationRateChange; + } else { + message.inflationRateChange = ''; + } + if (object.inflationMax !== undefined && object.inflationMax !== null) { + message.inflationMax = object.inflationMax; + } else { + message.inflationMax = ''; + } + if (object.inflationMin !== undefined && object.inflationMin !== null) { + message.inflationMin = object.inflationMin; + } else { + message.inflationMin = ''; + } + if (object.goalBonded !== undefined && object.goalBonded !== null) { + message.goalBonded = object.goalBonded; + } else { + message.goalBonded = ''; + } + if (object.blocksPerYear !== undefined && object.blocksPerYear !== null) { + message.blocksPerYear = object.blocksPerYear as Long; + } else { + message.blocksPerYear = Long.UZERO; + } + return message; + }, +}; + +type Builtin = Date | Function | Uint8Array | string | number | boolean | undefined | Long; +export type DeepPartial = T extends Builtin + ? T + : T extends Array + ? Array> + : T extends ReadonlyArray + ? ReadonlyArray> + : T extends {} + ? { [K in keyof T]?: DeepPartial } + : Partial; + +if (_m0.util.Long !== Long) { + _m0.util.Long = Long as any; + _m0.configure(); +} diff --git a/src/codec/cosmos/mint/v1beta1/query.ts b/src/codec/cosmos/mint/v1beta1/query.ts new file mode 100644 index 0000000..d3bad9c --- /dev/null +++ b/src/codec/cosmos/mint/v1beta1/query.ts @@ -0,0 +1,404 @@ +/* eslint-disable */ +import Long from 'long'; +import _m0 from 'protobufjs/minimal'; +import { Params } from '../../../cosmos/mint/v1beta1/mint'; + +export const protobufPackage = 'cosmos.mint.v1beta1'; + +/** QueryParamsRequest is the request type for the Query/Params RPC method. */ +export interface QueryParamsRequest {} + +/** QueryParamsResponse is the response type for the Query/Params RPC method. */ +export interface QueryParamsResponse { + /** params defines the parameters of the module. */ + params?: Params; +} + +/** QueryInflationRequest is the request type for the Query/Inflation RPC method. */ +export interface QueryInflationRequest {} + +/** + * QueryInflationResponse is the response type for the Query/Inflation RPC + * method. + */ +export interface QueryInflationResponse { + /** inflation is the current minting inflation value. */ + inflation: Uint8Array; +} + +/** + * QueryAnnualProvisionsRequest is the request type for the + * Query/AnnualProvisions RPC method. + */ +export interface QueryAnnualProvisionsRequest {} + +/** + * QueryAnnualProvisionsResponse is the response type for the + * Query/AnnualProvisions RPC method. + */ +export interface QueryAnnualProvisionsResponse { + /** annual_provisions is the current minting annual provisions value. */ + annualProvisions: Uint8Array; +} + +const baseQueryParamsRequest: object = {}; + +export const QueryParamsRequest = { + encode(_: QueryParamsRequest, writer: _m0.Writer = _m0.Writer.create()): _m0.Writer { + return writer; + }, + + decode(input: _m0.Reader | Uint8Array, length?: number): QueryParamsRequest { + const reader = input instanceof _m0.Reader ? input : new _m0.Reader(input); + let end = length === undefined ? reader.len : reader.pos + length; + const message = { ...baseQueryParamsRequest } as QueryParamsRequest; + while (reader.pos < end) { + const tag = reader.uint32(); + switch (tag >>> 3) { + default: + reader.skipType(tag & 7); + break; + } + } + return message; + }, + + fromJSON(_: any): QueryParamsRequest { + const message = { ...baseQueryParamsRequest } as QueryParamsRequest; + return message; + }, + + toJSON(_: QueryParamsRequest): unknown { + const obj: any = {}; + return obj; + }, + + fromPartial(_: DeepPartial): QueryParamsRequest { + const message = { ...baseQueryParamsRequest } as QueryParamsRequest; + return message; + }, +}; + +const baseQueryParamsResponse: object = {}; + +export const QueryParamsResponse = { + encode(message: QueryParamsResponse, writer: _m0.Writer = _m0.Writer.create()): _m0.Writer { + if (message.params !== undefined) { + Params.encode(message.params, writer.uint32(10).fork()).ldelim(); + } + return writer; + }, + + decode(input: _m0.Reader | Uint8Array, length?: number): QueryParamsResponse { + const reader = input instanceof _m0.Reader ? input : new _m0.Reader(input); + let end = length === undefined ? reader.len : reader.pos + length; + const message = { ...baseQueryParamsResponse } as QueryParamsResponse; + while (reader.pos < end) { + const tag = reader.uint32(); + switch (tag >>> 3) { + case 1: + message.params = Params.decode(reader, reader.uint32()); + break; + default: + reader.skipType(tag & 7); + break; + } + } + return message; + }, + + fromJSON(object: any): QueryParamsResponse { + const message = { ...baseQueryParamsResponse } as QueryParamsResponse; + if (object.params !== undefined && object.params !== null) { + message.params = Params.fromJSON(object.params); + } else { + message.params = undefined; + } + return message; + }, + + toJSON(message: QueryParamsResponse): unknown { + const obj: any = {}; + message.params !== undefined && (obj.params = message.params ? Params.toJSON(message.params) : undefined); + return obj; + }, + + fromPartial(object: DeepPartial): QueryParamsResponse { + const message = { ...baseQueryParamsResponse } as QueryParamsResponse; + if (object.params !== undefined && object.params !== null) { + message.params = Params.fromPartial(object.params); + } else { + message.params = undefined; + } + return message; + }, +}; + +const baseQueryInflationRequest: object = {}; + +export const QueryInflationRequest = { + encode(_: QueryInflationRequest, writer: _m0.Writer = _m0.Writer.create()): _m0.Writer { + return writer; + }, + + decode(input: _m0.Reader | Uint8Array, length?: number): QueryInflationRequest { + const reader = input instanceof _m0.Reader ? input : new _m0.Reader(input); + let end = length === undefined ? reader.len : reader.pos + length; + const message = { ...baseQueryInflationRequest } as QueryInflationRequest; + while (reader.pos < end) { + const tag = reader.uint32(); + switch (tag >>> 3) { + default: + reader.skipType(tag & 7); + break; + } + } + return message; + }, + + fromJSON(_: any): QueryInflationRequest { + const message = { ...baseQueryInflationRequest } as QueryInflationRequest; + return message; + }, + + toJSON(_: QueryInflationRequest): unknown { + const obj: any = {}; + return obj; + }, + + fromPartial(_: DeepPartial): QueryInflationRequest { + const message = { ...baseQueryInflationRequest } as QueryInflationRequest; + return message; + }, +}; + +const baseQueryInflationResponse: object = {}; + +export const QueryInflationResponse = { + encode(message: QueryInflationResponse, writer: _m0.Writer = _m0.Writer.create()): _m0.Writer { + if (message.inflation.length !== 0) { + writer.uint32(10).bytes(message.inflation); + } + return writer; + }, + + decode(input: _m0.Reader | Uint8Array, length?: number): QueryInflationResponse { + const reader = input instanceof _m0.Reader ? input : new _m0.Reader(input); + let end = length === undefined ? reader.len : reader.pos + length; + const message = { ...baseQueryInflationResponse } as QueryInflationResponse; + message.inflation = new Uint8Array(); + while (reader.pos < end) { + const tag = reader.uint32(); + switch (tag >>> 3) { + case 1: + message.inflation = reader.bytes(); + break; + default: + reader.skipType(tag & 7); + break; + } + } + return message; + }, + + fromJSON(object: any): QueryInflationResponse { + const message = { ...baseQueryInflationResponse } as QueryInflationResponse; + message.inflation = new Uint8Array(); + if (object.inflation !== undefined && object.inflation !== null) { + message.inflation = bytesFromBase64(object.inflation); + } + return message; + }, + + toJSON(message: QueryInflationResponse): unknown { + const obj: any = {}; + message.inflation !== undefined && (obj.inflation = base64FromBytes(message.inflation !== undefined ? message.inflation : new Uint8Array())); + return obj; + }, + + fromPartial(object: DeepPartial): QueryInflationResponse { + const message = { ...baseQueryInflationResponse } as QueryInflationResponse; + if (object.inflation !== undefined && object.inflation !== null) { + message.inflation = object.inflation; + } else { + message.inflation = new Uint8Array(); + } + return message; + }, +}; + +const baseQueryAnnualProvisionsRequest: object = {}; + +export const QueryAnnualProvisionsRequest = { + encode(_: QueryAnnualProvisionsRequest, writer: _m0.Writer = _m0.Writer.create()): _m0.Writer { + return writer; + }, + + decode(input: _m0.Reader | Uint8Array, length?: number): QueryAnnualProvisionsRequest { + const reader = input instanceof _m0.Reader ? input : new _m0.Reader(input); + let end = length === undefined ? reader.len : reader.pos + length; + const message = { ...baseQueryAnnualProvisionsRequest } as QueryAnnualProvisionsRequest; + while (reader.pos < end) { + const tag = reader.uint32(); + switch (tag >>> 3) { + default: + reader.skipType(tag & 7); + break; + } + } + return message; + }, + + fromJSON(_: any): QueryAnnualProvisionsRequest { + const message = { ...baseQueryAnnualProvisionsRequest } as QueryAnnualProvisionsRequest; + return message; + }, + + toJSON(_: QueryAnnualProvisionsRequest): unknown { + const obj: any = {}; + return obj; + }, + + fromPartial(_: DeepPartial): QueryAnnualProvisionsRequest { + const message = { ...baseQueryAnnualProvisionsRequest } as QueryAnnualProvisionsRequest; + return message; + }, +}; + +const baseQueryAnnualProvisionsResponse: object = {}; + +export const QueryAnnualProvisionsResponse = { + encode(message: QueryAnnualProvisionsResponse, writer: _m0.Writer = _m0.Writer.create()): _m0.Writer { + if (message.annualProvisions.length !== 0) { + writer.uint32(10).bytes(message.annualProvisions); + } + return writer; + }, + + decode(input: _m0.Reader | Uint8Array, length?: number): QueryAnnualProvisionsResponse { + const reader = input instanceof _m0.Reader ? input : new _m0.Reader(input); + let end = length === undefined ? reader.len : reader.pos + length; + const message = { ...baseQueryAnnualProvisionsResponse } as QueryAnnualProvisionsResponse; + message.annualProvisions = new Uint8Array(); + while (reader.pos < end) { + const tag = reader.uint32(); + switch (tag >>> 3) { + case 1: + message.annualProvisions = reader.bytes(); + break; + default: + reader.skipType(tag & 7); + break; + } + } + return message; + }, + + fromJSON(object: any): QueryAnnualProvisionsResponse { + const message = { ...baseQueryAnnualProvisionsResponse } as QueryAnnualProvisionsResponse; + message.annualProvisions = new Uint8Array(); + if (object.annualProvisions !== undefined && object.annualProvisions !== null) { + message.annualProvisions = bytesFromBase64(object.annualProvisions); + } + return message; + }, + + toJSON(message: QueryAnnualProvisionsResponse): unknown { + const obj: any = {}; + message.annualProvisions !== undefined && (obj.annualProvisions = base64FromBytes(message.annualProvisions !== undefined ? message.annualProvisions : new Uint8Array())); + return obj; + }, + + fromPartial(object: DeepPartial): QueryAnnualProvisionsResponse { + const message = { ...baseQueryAnnualProvisionsResponse } as QueryAnnualProvisionsResponse; + if (object.annualProvisions !== undefined && object.annualProvisions !== null) { + message.annualProvisions = object.annualProvisions; + } else { + message.annualProvisions = new Uint8Array(); + } + return message; + }, +}; + +/** Query provides defines the gRPC querier service. */ +export interface Query { + /** Params returns the total set of minting parameters. */ + Params(request: QueryParamsRequest): Promise; + /** Inflation returns the current minting inflation value. */ + Inflation(request: QueryInflationRequest): Promise; + /** AnnualProvisions current minting annual provisions value. */ + AnnualProvisions(request: QueryAnnualProvisionsRequest): Promise; +} + +export class QueryClientImpl implements Query { + private readonly rpc: Rpc; + constructor(rpc: Rpc) { + this.rpc = rpc; + } + Params(request: QueryParamsRequest): Promise { + const data = QueryParamsRequest.encode(request).finish(); + const promise = this.rpc.request('cosmos.mint.v1beta1.Query', 'Params', data); + return promise.then((data) => QueryParamsResponse.decode(new _m0.Reader(data))); + } + + Inflation(request: QueryInflationRequest): Promise { + const data = QueryInflationRequest.encode(request).finish(); + const promise = this.rpc.request('cosmos.mint.v1beta1.Query', 'Inflation', data); + return promise.then((data) => QueryInflationResponse.decode(new _m0.Reader(data))); + } + + AnnualProvisions(request: QueryAnnualProvisionsRequest): Promise { + const data = QueryAnnualProvisionsRequest.encode(request).finish(); + const promise = this.rpc.request('cosmos.mint.v1beta1.Query', 'AnnualProvisions', data); + return promise.then((data) => QueryAnnualProvisionsResponse.decode(new _m0.Reader(data))); + } +} + +interface Rpc { + request(service: string, method: string, data: Uint8Array): Promise; +} + +declare var self: any | undefined; +declare var window: any | undefined; +var globalThis: any = (() => { + if (typeof globalThis !== 'undefined') return globalThis; + if (typeof self !== 'undefined') return self; + if (typeof window !== 'undefined') return window; + if (typeof global !== 'undefined') return global; + throw 'Unable to locate global object'; +})(); + +const atob: (b64: string) => string = globalThis.atob || ((b64) => globalThis.Buffer.from(b64, 'base64').toString('binary')); +function bytesFromBase64(b64: string): Uint8Array { + const bin = atob(b64); + const arr = new Uint8Array(bin.length); + for (let i = 0; i < bin.length; ++i) { + arr[i] = bin.charCodeAt(i); + } + return arr; +} + +const btoa: (bin: string) => string = globalThis.btoa || ((bin) => globalThis.Buffer.from(bin, 'binary').toString('base64')); +function base64FromBytes(arr: Uint8Array): string { + const bin: string[] = []; + for (let i = 0; i < arr.byteLength; ++i) { + bin.push(String.fromCharCode(arr[i])); + } + return btoa(bin.join('')); +} + +type Builtin = Date | Function | Uint8Array | string | number | boolean | undefined | Long; +export type DeepPartial = T extends Builtin + ? T + : T extends Array + ? Array> + : T extends ReadonlyArray + ? ReadonlyArray> + : T extends {} + ? { [K in keyof T]?: DeepPartial } + : Partial; + +if (_m0.util.Long !== Long) { + _m0.util.Long = Long as any; + _m0.configure(); +} diff --git a/src/extensions/index.ts b/src/extensions/index.ts index 8f87cbd..c0f3448 100644 --- a/src/extensions/index.ts +++ b/src/extensions/index.ts @@ -1 +1,2 @@ +export * from './mint'; export * from './beam'; diff --git a/src/extensions/mint.ts b/src/extensions/mint.ts new file mode 100644 index 0000000..cee630a --- /dev/null +++ b/src/extensions/mint.ts @@ -0,0 +1,41 @@ +import { createProtobufRpcClient, QueryClient } from '@cosmjs/stargate'; +import { assert } from '@cosmjs/utils'; + +import { LumUtils } from '..'; +import { Params } from '../codec/cosmos/mint/v1beta1/mint'; +import { QueryClientImpl } from '../codec/cosmos/mint/v1beta1/query'; + +export interface MintExtension { + readonly mint: { + readonly params: () => Promise; + readonly annualProvisions: () => Promise; + readonly inflation: () => Promise; + }; +} + +export const setupMintExtension = (base: QueryClient): MintExtension => { + const rpc = createProtobufRpcClient(base); + const queryService = new QueryClientImpl(rpc); + + return { + mint: { + params: async () => { + const { params } = await queryService.Params({}); + assert(params); + return params; + }, + + annualProvisions: async () => { + const { annualProvisions } = await queryService.AnnualProvisions({}); + assert(annualProvisions); + return LumUtils.fromAscii(annualProvisions); + }, + + inflation: async () => { + const { inflation } = await queryService.Inflation({}); + assert(inflation); + return LumUtils.fromAscii(inflation); + }, + }, + }; +}; diff --git a/tests/client.test.ts b/tests/client.test.ts index bd754e6..0834094 100644 --- a/tests/client.test.ts +++ b/tests/client.test.ts @@ -382,6 +382,25 @@ describe('LumClient', () => { expect(delegValidators.validators.length).toBeGreaterThan(0); }); + it('Should expose the mint module', async () => { + const supply = await clt.getAllSupplies(); + + const params = await clt.queryClient.mint.params(); + expect(params).toBeTruthy(); + expect(params.inflationMin).toBeTruthy(); + expect(params.inflationMax).toBeTruthy(); + expect(params.inflationRateChange).toBeTruthy(); + expect(params.mintDenom).toBeTruthy(); + expect(params.blocksPerYear).toBeTruthy(); + expect(params.goalBonded).toBeTruthy(); + + const inflation = await clt.queryClient.mint.inflation(); + expect(parseInt(inflation)).toBeGreaterThan(0); + + const annualProvisions = await clt.queryClient.mint.annualProvisions(); + expect(parseInt(annualProvisions)).toBeGreaterThan(0); + }); + it('Should allow multiple signers per transaction', async () => { const acc1 = await clt.getAccount(w1.getAddress()); const acc2 = await clt.getAccount(w2.getAddress());