Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add msg client #364

Merged
merged 6 commits into from
Jun 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/test-ts-sdk.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ jobs:
- name: Run Nibiru network in the background
run: |
cd nibiru
make chaosnet
make chaosnet-heartmonitor
cd ..

- name: yarn test
Expand Down
2 changes: 1 addition & 1 deletion jest.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ const config: Config = {
"!**/src/gql/utils/generated.ts",
"!**/src/sdk/utils/testutil.ts",
],
testPathIgnorePatterns: ["/node_modules/", "/dist/"],
testPathIgnorePatterns: ["/node_modules/", "/dist/", "/nibiru/"],
coverageReporters: ["json-summary", "text", "html", "lcov"],
globals: {
window: {
Expand Down
10 changes: 1 addition & 9 deletions src/gql/heart-monitor/heart-monitor.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -93,14 +93,6 @@ import {
GQLQueryGqlUserArgs,
} from ".."

const checkNoFields = <T>(objects: T[], fields: string[]) => {
objects.forEach((obj: T) => {
fields.forEach((field: string) => {
expect(obj).not.toHaveProperty(field)
})
})
}

const nibiruUrl = "testnet-1"

const heartMonitor = new HeartMonitor(
Expand Down Expand Up @@ -854,7 +846,7 @@ const testStaking = async (
}
}

test("staking", async () => {
test.skip("staking", async () => {
await testStaking(
{
delegations: {
Expand Down
107 changes: 34 additions & 73 deletions src/sdk/msg/devgas.ts
Original file line number Diff line number Diff line change
@@ -1,88 +1,49 @@
import { EncodeObject, GeneratedType } from "@cosmjs/proto-signing"
import { createProtobufRpcClient, QueryClient } from "@cosmjs/stargate"
import {
MsgCancelFeeShare,
MsgCancelFeeShareResponse,
MsgClientImpl,
MsgRegisterFeeShare,
MsgRegisterFeeShareResponse,
MsgUpdateFeeShare,
MsgUpdateFeeShareResponse,
MsgUpdateParams,
MsgUpdateParamsResponse,
} from "../../protojs/nibiru/devgas/v1/tx"
import { TxMessage } from ".."

const protobufPackage = "nibiru.devgas.v1"

export const DEVGAS_MSG_TYPE_URLS = {
MsgCancelFeeShare: `/${protobufPackage}.MsgCancelFeeShare`,
MsgRegisterFeeShare: `/${protobufPackage}.MsgRegisterFeeShare`,
MsgUpdateFeeShare: `/${protobufPackage}.MsgUpdateFeeShare`,
MsgUpdateParams: `/${protobufPackage}.MsgUpdateParams`,
export interface DevgasMsgExtension {
readonly devgasMsg: Readonly<{
registerFeeShare: (
body: MsgRegisterFeeShare
) => Promise<MsgRegisterFeeShareResponse>
updateFeeShare: (
body: MsgUpdateFeeShare
) => Promise<MsgUpdateFeeShareResponse>
cancelFeeShare: (
body: MsgCancelFeeShare
) => Promise<MsgCancelFeeShareResponse>
updateParams: (body: MsgUpdateParams) => Promise<MsgUpdateParamsResponse>
}>
}

export const devgasTypes: ReadonlyArray<[string, GeneratedType]> = [
[DEVGAS_MSG_TYPE_URLS.MsgCancelFeeShare, MsgCancelFeeShare],
[DEVGAS_MSG_TYPE_URLS.MsgRegisterFeeShare, MsgRegisterFeeShare],
[DEVGAS_MSG_TYPE_URLS.MsgUpdateFeeShare, MsgUpdateFeeShare],
[DEVGAS_MSG_TYPE_URLS.MsgUpdateParams, MsgUpdateParams],
]

export interface MsgCancelFeeShareEncodeObject extends EncodeObject {
readonly typeUrl: string
readonly value: Partial<MsgCancelFeeShare>
}
export const setupDevgasMsgExtension = (
base: QueryClient
): DevgasMsgExtension => {
const queryService = new MsgClientImpl(createProtobufRpcClient(base))

export const isMsgCancelFeeShareEncodeObject = (encodeObject: EncodeObject) =>
encodeObject.typeUrl === DEVGAS_MSG_TYPE_URLS.MsgCancelFeeShare

export interface MsgRegisterFeeShareEncodeObject extends EncodeObject {
readonly typeUrl: string
readonly value: Partial<MsgRegisterFeeShare>
}
return {
devgasMsg: {
registerFeeShare: async (body: MsgRegisterFeeShare) =>
queryService.RegisterFeeShare(MsgRegisterFeeShare.fromPartial(body)),

export const isMsgRegisterFeeShareEncodeObject = (encodeObject: EncodeObject) =>
encodeObject.typeUrl === DEVGAS_MSG_TYPE_URLS.MsgRegisterFeeShare
updateFeeShare: async (body: MsgUpdateFeeShare) =>
queryService.UpdateFeeShare(MsgUpdateFeeShare.fromPartial(body)),

export interface MsgUpdateFeeShareEncodeObject extends EncodeObject {
readonly typeUrl: string
readonly value: Partial<MsgUpdateFeeShare>
}

export const isMsgUpdateFeeShareEncodeObject = (encodeObject: EncodeObject) =>
encodeObject.typeUrl === DEVGAS_MSG_TYPE_URLS.MsgUpdateFeeShare

export interface MsgUpdateParamsEncodeObject extends EncodeObject {
readonly typeUrl: string
readonly value: Partial<MsgUpdateParams>
}

export const isMsgUpdateParamsEncodeObject = (encodeObject: EncodeObject) =>
encodeObject.typeUrl === DEVGAS_MSG_TYPE_URLS.MsgUpdateParams

// ----------------------------------------------------------------------------

export class DevgasMsgFactory {
static cancelFeeShare(msg: MsgCancelFeeShare): TxMessage {
return {
typeUrl: `/${protobufPackage}.MsgCancelFeeShare`,
value: MsgCancelFeeShare.fromPartial(msg),
}
}

static registerFeeShare(msg: MsgRegisterFeeShare): TxMessage {
return {
typeUrl: `/${protobufPackage}.MsgRegisterFeeShare`,
value: MsgRegisterFeeShare.fromPartial(msg),
}
}

static MsgUpdateFeeShare(msg: MsgUpdateFeeShare): TxMessage {
return {
typeUrl: `/${protobufPackage}.MsgUpdateFeeShare`,
value: MsgUpdateFeeShare.fromPartial(msg),
}
}
cancelFeeShare: async (body: MsgCancelFeeShare) =>
queryService.CancelFeeShare(MsgCancelFeeShare.fromPartial(body)),

static updateParams(msg: MsgUpdateParams): TxMessage {
return {
typeUrl: `/${protobufPackage}.MsgUpdateParams`,
value: MsgUpdateParams.fromPartial(msg),
}
updateParams: async (body: MsgUpdateParams) =>
queryService.UpdateParams(MsgUpdateParams.fromPartial(body)),
},
}
}
29 changes: 0 additions & 29 deletions src/sdk/msg/encode-types.ts

This file was deleted.

1 change: 0 additions & 1 deletion src/sdk/msg/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
*/

export * from "./devgas"
export * from "./encode-types"
export * from "./inflation"
export * from "./oracle"
export * from "./sudo"
Expand Down
72 changes: 28 additions & 44 deletions src/sdk/msg/inflation.ts
Original file line number Diff line number Diff line change
@@ -1,53 +1,37 @@
import { EncodeObject, GeneratedType } from "@cosmjs/proto-signing"
import { createProtobufRpcClient, QueryClient } from "@cosmjs/stargate"
import {
MsgClientImpl,
MsgEditInflationParams,
MsgEditInflationParamsResponse,
MsgToggleInflation,
MsgToggleInflationResponse,
} from "../../protojs/nibiru/inflation/v1/tx"
import { TxMessage } from ".."

const protobufPackage = "nibiru.inflation.v1"

export const INFLATION_MSG_TYPE_URLS = {
MsgEditInflationParams: `/${protobufPackage}.MsgEditInflationParams`,
MsgToggleInflation: `/${protobufPackage}.MsgToggleInflation`,
}

export const inflationTypes: ReadonlyArray<[string, GeneratedType]> = [
[INFLATION_MSG_TYPE_URLS.MsgEditInflationParams, MsgEditInflationParams],
[INFLATION_MSG_TYPE_URLS.MsgToggleInflation, MsgToggleInflation],
]

export interface MsgEditInflationParamsEncodeObject extends EncodeObject {
readonly typeUrl: string
readonly value: Partial<MsgEditInflationParams>
export interface InflationMsgExtension {
readonly inflationMsg: Readonly<{
toggleInflation: (
body: MsgToggleInflation
) => Promise<MsgToggleInflationResponse>
editInflationParams: (
body: MsgEditInflationParams
) => Promise<MsgEditInflationParamsResponse>
}>
}

export const isMsgEditInflationParamsEncodeObject = (
encodeObject: EncodeObject
) => encodeObject.typeUrl === INFLATION_MSG_TYPE_URLS.MsgEditInflationParams

export interface MsgToggleInflationEncodeObject extends EncodeObject {
readonly typeUrl: string
readonly value: Partial<MsgToggleInflation>
}

export const isMsgToggleInflationEncodeObject = (encodeObject: EncodeObject) =>
encodeObject.typeUrl === INFLATION_MSG_TYPE_URLS.MsgToggleInflation

// ----------------------------------------------------------------------------

export class InflationMsgFactory {
static editInflationParams(msg: MsgEditInflationParams): TxMessage {
return {
typeUrl: `/${protobufPackage}.MsgEditInflationParams`,
value: MsgEditInflationParams.fromPartial(msg),
}
}

static toggleInflation(msg: MsgToggleInflation): TxMessage {
return {
typeUrl: `/${protobufPackage}.MsgToggleInflation`,
value: MsgToggleInflation.fromPartial(msg),
}
export const setupInflationMsgExtension = (
base: QueryClient
): InflationMsgExtension => {
const queryService = new MsgClientImpl(createProtobufRpcClient(base))

return {
inflationMsg: {
toggleInflation: async (body: MsgToggleInflation) =>
queryService.ToggleInflation(MsgToggleInflation.fromPartial(body)),

editInflationParams: async (body: MsgEditInflationParams) =>
queryService.EditInflationParams(
MsgEditInflationParams.fromPartial(body)
),
},
}
cgilbe27 marked this conversation as resolved.
Show resolved Hide resolved
}
Loading
Loading