From 1723d2b41187009dbda1efe997109cb74b6ac953 Mon Sep 17 00:00:00 2001 From: Cameron Gilbert Date: Thu, 30 Nov 2023 13:25:07 -0500 Subject: [PATCH] fix(fix): unhide spot/perp protojs (#250) * fix(fix): protojs * fix(revert): prior change * fix(resolve rabbit comments): comments * fix(more review): review * fix(fix): fix --- packages/nibijs/docs/classes/StableSwap.md | 4 +- packages/nibijs/src/chain/chain.ts | 2 +- packages/nibijs/src/msg/index.ts | 18 +- packages/nibijs/src/msg/perp.ts | 350 +- packages/nibijs/src/msg/spot.ts | 236 +- packages/nibijs/src/query/epochs.ts | 8 +- packages/nibijs/src/query/index.ts | 4 +- packages/nibijs/src/query/perp.ts | 135 +- packages/nibijs/src/query/query.ts | 12 +- packages/nibijs/src/query/spot.ts | 506 +-- packages/nibijs/src/test/query.test.ts | 32 +- .../src/test/query.tests/epochs.test.ts | 4 +- .../src/test/query.tests/perp.test-hidden.ts | 127 - .../nibijs/src/test/query.tests/perp.test.ts | 127 + .../src/test/query.tests/spot.test-hidden.ts | 402 --- .../nibijs/src/test/query.tests/spot.test.ts | 402 +++ packages/nibijs/src/tx/signingClient.test.ts | 398 ++- packages/nibijs/src/tx/signingClient.ts | 14 +- .../protojs/src/cosmos/bank/v1beta1/bank.ts | 811 ----- packages/protojs/src/cosmos/msg/v1/msg.ts | 3 - .../protojs/src/nibiru/devgas/v1/devgas.ts | 161 - .../protojs/src/nibiru/devgas/v1/event.ts | 440 --- .../protojs/src/nibiru/devgas/v1/genesis.ts | 269 -- .../protojs/src/nibiru/devgas/v1/query.ts | 749 ----- packages/protojs/src/nibiru/devgas/v1/tx.ts | 795 ----- .../protojs/src/nibiru/epochs/v1/query.ts | 66 +- packages/protojs/src/nibiru/oracle/v1/tx.ts | 478 --- packages/protojs/src/nibiru/perp/v2/event.ts | 1187 +++++++ .../protojs/src/nibiru/perp/v2/genesis.ts | 186 ++ packages/protojs/src/nibiru/perp/v2/query.ts | 972 ++++++ packages/protojs/src/nibiru/perp/v2/state.ts | 922 ++++++ packages/protojs/src/nibiru/perp/v2/tx.ts | 2072 ++++++++++++ packages/protojs/src/nibiru/spot/v1/event.ts | 746 +++++ .../protojs/src/nibiru/spot/v1/genesis.ts | 141 + packages/protojs/src/nibiru/spot/v1/params.ts | 169 + packages/protojs/src/nibiru/spot/v1/pool.ts | 470 +++ packages/protojs/src/nibiru/spot/v1/query.ts | 2945 +++++++++++++++++ packages/protojs/src/nibiru/spot/v1/tx.ts | 946 ++++++ .../src/nibiru/stablecoin/v1/events.ts | 664 ++++ .../src/nibiru/stablecoin/v1/genesis.ts | 145 + .../src/nibiru/stablecoin/v1/params.ts | 303 ++ .../protojs/src/nibiru/stablecoin/v1/query.ts | 959 ++++++ .../protojs/src/nibiru/stablecoin/v1/tx.ts | 897 +++++ .../src/nibiru/tokenfactory/v1/event.ts | 539 --- .../src/nibiru/tokenfactory/v1/query.ts | 552 --- .../src/nibiru/tokenfactory/v1/state.ts | 526 --- .../protojs/src/nibiru/tokenfactory/v1/tx.ts | 1118 ------- 47 files changed, 15141 insertions(+), 7871 deletions(-) delete mode 100644 packages/nibijs/src/test/query.tests/perp.test-hidden.ts create mode 100644 packages/nibijs/src/test/query.tests/perp.test.ts delete mode 100644 packages/nibijs/src/test/query.tests/spot.test-hidden.ts create mode 100644 packages/nibijs/src/test/query.tests/spot.test.ts delete mode 100644 packages/protojs/src/cosmos/bank/v1beta1/bank.ts delete mode 100644 packages/protojs/src/cosmos/msg/v1/msg.ts delete mode 100644 packages/protojs/src/nibiru/devgas/v1/devgas.ts delete mode 100644 packages/protojs/src/nibiru/devgas/v1/event.ts delete mode 100644 packages/protojs/src/nibiru/devgas/v1/genesis.ts delete mode 100644 packages/protojs/src/nibiru/devgas/v1/query.ts delete mode 100644 packages/protojs/src/nibiru/devgas/v1/tx.ts create mode 100644 packages/protojs/src/nibiru/perp/v2/event.ts create mode 100644 packages/protojs/src/nibiru/perp/v2/genesis.ts create mode 100644 packages/protojs/src/nibiru/perp/v2/query.ts create mode 100644 packages/protojs/src/nibiru/perp/v2/state.ts create mode 100644 packages/protojs/src/nibiru/perp/v2/tx.ts create mode 100644 packages/protojs/src/nibiru/spot/v1/event.ts create mode 100644 packages/protojs/src/nibiru/spot/v1/genesis.ts create mode 100644 packages/protojs/src/nibiru/spot/v1/params.ts create mode 100644 packages/protojs/src/nibiru/spot/v1/pool.ts create mode 100644 packages/protojs/src/nibiru/spot/v1/query.ts create mode 100644 packages/protojs/src/nibiru/spot/v1/tx.ts create mode 100644 packages/protojs/src/nibiru/stablecoin/v1/events.ts create mode 100644 packages/protojs/src/nibiru/stablecoin/v1/genesis.ts create mode 100644 packages/protojs/src/nibiru/stablecoin/v1/params.ts create mode 100644 packages/protojs/src/nibiru/stablecoin/v1/query.ts create mode 100644 packages/protojs/src/nibiru/stablecoin/v1/tx.ts delete mode 100644 packages/protojs/src/nibiru/tokenfactory/v1/event.ts delete mode 100644 packages/protojs/src/nibiru/tokenfactory/v1/query.ts delete mode 100644 packages/protojs/src/nibiru/tokenfactory/v1/state.ts delete mode 100644 packages/protojs/src/nibiru/tokenfactory/v1/tx.ts diff --git a/packages/nibijs/docs/classes/StableSwap.md b/packages/nibijs/docs/classes/StableSwap.md index c6d36438..b037d60f 100644 --- a/packages/nibijs/docs/classes/StableSwap.md +++ b/packages/nibijs/docs/classes/StableSwap.md @@ -178,8 +178,8 @@ y() Calculate x[j] if one makes x[i] = x Done by solving quadratic equation iteratively. -x_1**2 + x1 * (sum' - (A*n**n - 1) _ D / (A _ n**n)) = D ** (n+1)/(n ** (2 _ n) _ prod' \* A) -x_1**2 + b\*x_1 = c +x*1\*\*2 + x1 * (sum' - (A*n\*\*n - 1) * D / (A _ n**n)) = D ** (n+1)/(n \*\* (2 _ n) _ prod' _ A) +x_1\*\*2 + b\*x_1 = c x_1 = (x_1\**2 + c) / (2*x_1 + b) diff --git a/packages/nibijs/src/chain/chain.ts b/packages/nibijs/src/chain/chain.ts index 9a35d740..e93ab9ad 100644 --- a/packages/nibijs/src/chain/chain.ts +++ b/packages/nibijs/src/chain/chain.ts @@ -75,7 +75,7 @@ export class CustomChain implements Chain { private initChainId = () => { const { prefix, shortName, number } = this.chainIdParts - return [prefix, shortName, number].filter(Boolean).join("-") + return [prefix, shortName, number].join("-") } } diff --git a/packages/nibijs/src/msg/index.ts b/packages/nibijs/src/msg/index.ts index 482f5919..5aa889f3 100644 --- a/packages/nibijs/src/msg/index.ts +++ b/packages/nibijs/src/msg/index.ts @@ -1,14 +1,14 @@ -// import { PerpMsgFactory } from "./perp" -// import { SpotMsgFactory } from "./spot" +import { PerpMsgFactory } from "./perp" +import { SpotMsgFactory } from "./spot" -// export class MsgFactory { -// spot = SpotMsgFactory +export class MsgFactory { + spot = SpotMsgFactory -// perp = PerpMsgFactory -// } + perp = PerpMsgFactory +} -// export const Msg = new MsgFactory() +export const Msg = new MsgFactory() export * from "./encode-types" -// export * from "./perp" -// export * from "./spot" +export * from "./perp" +export * from "./spot" diff --git a/packages/nibijs/src/msg/perp.ts b/packages/nibijs/src/msg/perp.ts index 0efa7369..1f64545a 100644 --- a/packages/nibijs/src/msg/perp.ts +++ b/packages/nibijs/src/msg/perp.ts @@ -1,175 +1,175 @@ -// import { EncodeObject, GeneratedType } from "@cosmjs/proto-signing" -// import { -// MsgAddMargin, -// MsgClosePosition, -// MsgDonateToEcosystemFund, -// MsgMultiLiquidate, -// MsgMarketOrder, -// MsgRemoveMargin, -// MsgPartialClose, -// protobufPackage, -// } from "@nibiruchain/protojs/dist/nibiru/perp/v2/tx" -// import { Direction } from "@nibiruchain/protojs/dist/nibiru/perp/v2/state" -// import { toSdkDec, toSdkInt } from "../chain" -// import { TxMessage } from "./encode-types" - -// export const PERP_MSG_TYPE_URLS = { -// MsgAddMargin: `/${protobufPackage}.MsgAddMargin`, -// MsgRemoveMargin: `/${protobufPackage}.MsgRemoveMargin`, -// MsgMultiLiquidate: `/${protobufPackage}.MsgMultiLiquidate`, -// MsgMarketOrder: `/${protobufPackage}.MsgMarketOrder`, -// MsgClosePosition: `/${protobufPackage}.MsgClosePosition`, -// MsgDonateToEcosystemFund: `/${protobufPackage}.MsgDonateToEcosystemFund`, -// MsgPartialClose: `/${protobufPackage}.MsgPartialClose`, -// } - -// export const perpTypes: ReadonlyArray<[string, GeneratedType]> = [ -// [PERP_MSG_TYPE_URLS.MsgAddMargin, MsgAddMargin], -// [PERP_MSG_TYPE_URLS.MsgRemoveMargin, MsgRemoveMargin], -// [PERP_MSG_TYPE_URLS.MsgMultiLiquidate, MsgMultiLiquidate], -// [PERP_MSG_TYPE_URLS.MsgMarketOrder, MsgMarketOrder], -// [PERP_MSG_TYPE_URLS.MsgClosePosition, MsgClosePosition], -// [PERP_MSG_TYPE_URLS.MsgDonateToEcosystemFund, MsgDonateToEcosystemFund], -// [PERP_MSG_TYPE_URLS.MsgPartialClose, MsgPartialClose], -// ] - -// export interface MsgAddMarginEncodeObject extends EncodeObject { -// readonly typeUrl: string -// readonly value: Partial -// } - -// export const isMsgAddMarginEncodeObject = (encodeObject: EncodeObject) => -// (encodeObject as MsgAddMarginEncodeObject).typeUrl === -// PERP_MSG_TYPE_URLS.MsgAddMargin - -// export interface MsgRemoveMarginEncodeObject extends EncodeObject { -// readonly typeUrl: string -// readonly value: Partial -// } - -// export const isMsgRemoveMarginEncodeObject = (encodeObject: EncodeObject) => -// (encodeObject as MsgRemoveMarginEncodeObject).typeUrl === -// PERP_MSG_TYPE_URLS.MsgRemoveMargin - -// export interface MsgMultiLiquidateEncodeObject extends EncodeObject { -// readonly typeUrl: string -// readonly value: Partial -// } - -// export const isMsgMultiLiquidateEncodeObject = (encodeObject: EncodeObject) => -// (encodeObject as MsgMultiLiquidateEncodeObject).typeUrl === -// PERP_MSG_TYPE_URLS.MsgMultiLiquidate - -// export interface MsgOpenPositionEncodeObject extends EncodeObject { -// readonly typeUrl: string -// readonly value: Partial -// } - -// export const isMsgOpenPositionEncodeObject = (encodeObject: EncodeObject) => -// (encodeObject as MsgOpenPositionEncodeObject).typeUrl === -// PERP_MSG_TYPE_URLS.MsgMarketOrder - -// export interface MsgClosePositionEncodeObject extends EncodeObject { -// readonly typeUrl: string -// readonly value: Partial -// } - -// export const isMsgClosePositionEncodeObject = (encodeObject: EncodeObject) => -// (encodeObject as MsgClosePositionEncodeObject).typeUrl === -// PERP_MSG_TYPE_URLS.MsgClosePosition - -// export interface MsgDonateToEcosystemFundEncodeObject extends EncodeObject { -// readonly typeUrl: string -// readonly value: Partial -// } - -// export const isMsgDonateToEcosystemFundEncodeObject = ( -// encodeObject: EncodeObject -// ) => -// (encodeObject as MsgDonateToEcosystemFundEncodeObject).typeUrl === -// PERP_MSG_TYPE_URLS.MsgDonateToEcosystemFund - -// export interface MsgPartialCloseEncodeObject extends EncodeObject { -// readonly typeUrl: string -// readonly value: Partial -// } - -// export const isMsgPartialCloseEncodeObject = (encodeObject: EncodeObject) => -// (encodeObject as MsgPartialCloseEncodeObject).typeUrl === -// PERP_MSG_TYPE_URLS.MsgPartialClose - -// // ---------------------------------------------------------------------------- - -// export class PerpMsgFactory { -// static removeMargin(msg: MsgRemoveMargin): TxMessage { -// return { -// typeUrl: PERP_MSG_TYPE_URLS.MsgRemoveMargin, -// value: MsgRemoveMargin.fromPartial(msg), -// } -// } - -// /** -// * Returns a 'TxMessage' for adding margin to a position -// * -// * @static -// * @param {MsgAddMargin} msg - Message to add margin -// * @returns {TxMessage} - formatted version of MsgAddMargin -// */ -// static addMargin(msg: MsgAddMargin): TxMessage { -// return { -// typeUrl: PERP_MSG_TYPE_URLS.MsgAddMargin, -// value: MsgAddMargin.fromPartial(msg), -// } -// } - -// static liquidate(msg: MsgMultiLiquidate): TxMessage { -// return { -// typeUrl: PERP_MSG_TYPE_URLS.MsgMultiLiquidate, -// value: MsgMultiLiquidate.fromPartial(msg), -// } -// } - -// static openPosition(msg: { -// sender: string -// pair: string -// goLong: boolean -// quoteAssetAmount: number -// baseAssetAmountLimit?: number -// leverage: number -// }): TxMessage { -// const { quoteAssetAmount, baseAssetAmountLimit, leverage } = msg -// const pbMsg: MsgMarketOrder = { -// sender: msg.sender, -// pair: msg.pair, -// quoteAssetAmount: toSdkInt(quoteAssetAmount), -// baseAssetAmountLimit: toSdkInt(baseAssetAmountLimit ?? 0), -// leverage: toSdkDec(leverage.toString()), -// side: msg.goLong ? Direction.LONG : Direction.SHORT, -// } -// return { -// typeUrl: PERP_MSG_TYPE_URLS.MsgMarketOrder, -// value: MsgMarketOrder.fromPartial(pbMsg), -// } -// } - -// static closePosition(msg: MsgClosePosition): TxMessage { -// return { -// typeUrl: PERP_MSG_TYPE_URLS.MsgClosePosition, -// value: MsgClosePosition.fromPartial(msg), -// } -// } - -// static partialClosePosition(msg: MsgPartialClose): TxMessage { -// return { -// typeUrl: PERP_MSG_TYPE_URLS.MsgPartialClose, -// value: MsgPartialClose.fromPartial(msg), -// } -// } - -// static donateToPerpEF(msg: MsgDonateToEcosystemFund): TxMessage { -// return { -// typeUrl: PERP_MSG_TYPE_URLS.MsgDonateToEcosystemFund, -// value: MsgDonateToEcosystemFund.fromPartial(msg), -// } -// } -// } +import { EncodeObject, GeneratedType } from "@cosmjs/proto-signing" +import { + MsgAddMargin, + MsgClosePosition, + MsgDonateToEcosystemFund, + MsgMultiLiquidate, + MsgMarketOrder, + MsgRemoveMargin, + MsgPartialClose, + protobufPackage, +} from "@nibiruchain/protojs/dist/nibiru/perp/v2/tx" +import { Direction } from "@nibiruchain/protojs/dist/nibiru/perp/v2/state" +import { toSdkDec, toSdkInt } from "../chain" +import { TxMessage } from "./encode-types" + +export const PERP_MSG_TYPE_URLS = { + MsgAddMargin: `/${protobufPackage}.MsgAddMargin`, + MsgRemoveMargin: `/${protobufPackage}.MsgRemoveMargin`, + MsgMultiLiquidate: `/${protobufPackage}.MsgMultiLiquidate`, + MsgMarketOrder: `/${protobufPackage}.MsgMarketOrder`, + MsgClosePosition: `/${protobufPackage}.MsgClosePosition`, + MsgDonateToEcosystemFund: `/${protobufPackage}.MsgDonateToEcosystemFund`, + MsgPartialClose: `/${protobufPackage}.MsgPartialClose`, +} + +export const perpTypes: ReadonlyArray<[string, GeneratedType]> = [ + [PERP_MSG_TYPE_URLS.MsgAddMargin, MsgAddMargin], + [PERP_MSG_TYPE_URLS.MsgRemoveMargin, MsgRemoveMargin], + [PERP_MSG_TYPE_URLS.MsgMultiLiquidate, MsgMultiLiquidate], + [PERP_MSG_TYPE_URLS.MsgMarketOrder, MsgMarketOrder], + [PERP_MSG_TYPE_URLS.MsgClosePosition, MsgClosePosition], + [PERP_MSG_TYPE_URLS.MsgDonateToEcosystemFund, MsgDonateToEcosystemFund], + [PERP_MSG_TYPE_URLS.MsgPartialClose, MsgPartialClose], +] + +export interface MsgAddMarginEncodeObject extends EncodeObject { + readonly typeUrl: string + readonly value: Partial +} + +export const isMsgAddMarginEncodeObject = (encodeObject: EncodeObject) => + (encodeObject as MsgAddMarginEncodeObject).typeUrl === + PERP_MSG_TYPE_URLS.MsgAddMargin + +export interface MsgRemoveMarginEncodeObject extends EncodeObject { + readonly typeUrl: string + readonly value: Partial +} + +export const isMsgRemoveMarginEncodeObject = (encodeObject: EncodeObject) => + (encodeObject as MsgRemoveMarginEncodeObject).typeUrl === + PERP_MSG_TYPE_URLS.MsgRemoveMargin + +export interface MsgMultiLiquidateEncodeObject extends EncodeObject { + readonly typeUrl: string + readonly value: Partial +} + +export const isMsgMultiLiquidateEncodeObject = (encodeObject: EncodeObject) => + (encodeObject as MsgMultiLiquidateEncodeObject).typeUrl === + PERP_MSG_TYPE_URLS.MsgMultiLiquidate + +export interface MsgOpenPositionEncodeObject extends EncodeObject { + readonly typeUrl: string + readonly value: Partial +} + +export const isMsgOpenPositionEncodeObject = (encodeObject: EncodeObject) => + (encodeObject as MsgOpenPositionEncodeObject).typeUrl === + PERP_MSG_TYPE_URLS.MsgMarketOrder + +export interface MsgClosePositionEncodeObject extends EncodeObject { + readonly typeUrl: string + readonly value: Partial +} + +export const isMsgClosePositionEncodeObject = (encodeObject: EncodeObject) => + (encodeObject as MsgClosePositionEncodeObject).typeUrl === + PERP_MSG_TYPE_URLS.MsgClosePosition + +export interface MsgDonateToEcosystemFundEncodeObject extends EncodeObject { + readonly typeUrl: string + readonly value: Partial +} + +export const isMsgDonateToEcosystemFundEncodeObject = ( + encodeObject: EncodeObject +) => + (encodeObject as MsgDonateToEcosystemFundEncodeObject).typeUrl === + PERP_MSG_TYPE_URLS.MsgDonateToEcosystemFund + +export interface MsgPartialCloseEncodeObject extends EncodeObject { + readonly typeUrl: string + readonly value: Partial +} + +export const isMsgPartialCloseEncodeObject = (encodeObject: EncodeObject) => + (encodeObject as MsgPartialCloseEncodeObject).typeUrl === + PERP_MSG_TYPE_URLS.MsgPartialClose + +// ---------------------------------------------------------------------------- + +export class PerpMsgFactory { + static removeMargin(msg: MsgRemoveMargin): TxMessage { + return { + typeUrl: PERP_MSG_TYPE_URLS.MsgRemoveMargin, + value: MsgRemoveMargin.fromPartial(msg), + } + } + + /** + * Returns a 'TxMessage' for adding margin to a position + * + * @static + * @param {MsgAddMargin} msg - Message to add margin + * @returns {TxMessage} - formatted version of MsgAddMargin + */ + static addMargin(msg: MsgAddMargin): TxMessage { + return { + typeUrl: PERP_MSG_TYPE_URLS.MsgAddMargin, + value: MsgAddMargin.fromPartial(msg), + } + } + + static liquidate(msg: MsgMultiLiquidate): TxMessage { + return { + typeUrl: PERP_MSG_TYPE_URLS.MsgMultiLiquidate, + value: MsgMultiLiquidate.fromPartial(msg), + } + } + + static openPosition(msg: { + sender: string + pair: string + goLong: boolean + quoteAssetAmount: number + baseAssetAmountLimit?: number + leverage: number + }): TxMessage { + const { quoteAssetAmount, baseAssetAmountLimit, leverage } = msg + const pbMsg: MsgMarketOrder = { + sender: msg.sender, + pair: msg.pair, + quoteAssetAmount: toSdkInt(quoteAssetAmount), + baseAssetAmountLimit: toSdkInt(baseAssetAmountLimit ?? 0), + leverage: toSdkDec(leverage.toString()), + side: msg.goLong ? Direction.LONG : Direction.SHORT, + } + return { + typeUrl: PERP_MSG_TYPE_URLS.MsgMarketOrder, + value: MsgMarketOrder.fromPartial(pbMsg), + } + } + + static closePosition(msg: MsgClosePosition): TxMessage { + return { + typeUrl: PERP_MSG_TYPE_URLS.MsgClosePosition, + value: MsgClosePosition.fromPartial(msg), + } + } + + static partialClosePosition(msg: MsgPartialClose): TxMessage { + return { + typeUrl: PERP_MSG_TYPE_URLS.MsgPartialClose, + value: MsgPartialClose.fromPartial(msg), + } + } + + static donateToPerpEF(msg: MsgDonateToEcosystemFund): TxMessage { + return { + typeUrl: PERP_MSG_TYPE_URLS.MsgDonateToEcosystemFund, + value: MsgDonateToEcosystemFund.fromPartial(msg), + } + } +} diff --git a/packages/nibijs/src/msg/spot.ts b/packages/nibijs/src/msg/spot.ts index 7f7fd5a4..ece20a78 100644 --- a/packages/nibijs/src/msg/spot.ts +++ b/packages/nibijs/src/msg/spot.ts @@ -1,118 +1,118 @@ -// import { EncodeObject, GeneratedType } from "@cosmjs/proto-signing" -// import { -// MsgCreatePool, -// MsgExitPool, -// MsgJoinPool, -// MsgSwapAssets, -// protobufPackage, -// } from "@nibiruchain/protojs/dist/nibiru/spot/v1/tx" -// import { TxMessage } from "./encode-types" -// import { toSdkDec } from "../chain" - -// export const SPOT_MSG_TYPE_URLS = { -// MsgCreatePool: `/${protobufPackage}.MsgCreatePool`, -// MsgJoinPool: `/${protobufPackage}.MsgJoinPool`, -// MsgExitPool: `/${protobufPackage}.MsgExitPool`, -// MsgSwapAssets: `/${protobufPackage}.MsgSwapAssets`, -// } - -// export const spotTypes: ReadonlyArray<[string, GeneratedType]> = [ -// [SPOT_MSG_TYPE_URLS.MsgCreatePool, MsgCreatePool], -// [SPOT_MSG_TYPE_URLS.MsgJoinPool, MsgJoinPool], -// [SPOT_MSG_TYPE_URLS.MsgExitPool, MsgExitPool], -// [SPOT_MSG_TYPE_URLS.MsgSwapAssets, MsgSwapAssets], -// ] - -// export interface MsgCreatePoolEncodeObject extends EncodeObject { -// readonly typeUrl: string -// readonly value: Partial -// } - -// export const isMsgCreatePoolEncodeObject = (encodeObject: EncodeObject) => -// encodeObject.typeUrl === SPOT_MSG_TYPE_URLS.MsgCreatePool - -// export interface MsgJoinPoolEncodeObject extends EncodeObject { -// readonly typeUrl: string -// readonly value: Partial -// } - -// export const isMsgJoinPoolEncodeObject = (encodeObject: EncodeObject) => -// encodeObject.typeUrl === SPOT_MSG_TYPE_URLS.MsgJoinPool - -// export interface MsgExitPoolEncodeObject extends EncodeObject { -// readonly typeUrl: string -// readonly value: Partial -// } - -// export const isMsgExitPoolEncodeObject = (encodeObject: EncodeObject) => -// encodeObject.typeUrl === SPOT_MSG_TYPE_URLS.MsgExitPool - -// export interface MsgSwapAssetsEncodeObject extends EncodeObject { -// readonly typeUrl: string -// readonly value: Partial -// } - -// export const isMsgSwapAssetsEncodeObject = (encodeObject: EncodeObject) => -// encodeObject.typeUrl === SPOT_MSG_TYPE_URLS.MsgSwapAssets - -// // ---------------------------------------------------------------------------- - -// export class SpotMsgFactory { -// static createPool(msg: MsgCreatePool): TxMessage { -// if (msg.poolParams) { -// const { swapFee, exitFee } = msg.poolParams -// msg.poolParams.swapFee = toSdkDec(swapFee) -// msg.poolParams.exitFee = toSdkDec(exitFee) -// } - -// return { -// typeUrl: `/${protobufPackage}.MsgCreatePool`, -// value: MsgCreatePool.fromPartial(msg), -// } -// } - -// static joinPool({ -// poolId, -// sender, -// tokensIn, -// useAllCoins, -// }: MsgJoinPool): TxMessage { -// return { -// typeUrl: `/${protobufPackage}.MsgJoinPool`, -// value: MsgJoinPool.fromPartial({ -// poolId: Number(poolId), -// sender, -// tokensIn, -// useAllCoins, -// }), -// } -// } - -// static exitPool({ poolId, sender, poolShares }: MsgExitPool): TxMessage { -// return { -// typeUrl: `/${protobufPackage}.MsgExitPool`, -// value: MsgExitPool.fromPartial({ -// poolId: Number(poolId), -// sender, -// poolShares, -// }), -// } -// } - -// static swapAssets({ -// poolId, -// sender, -// tokenOutDenom, -// tokenIn, -// }: MsgSwapAssets): TxMessage { -// return { -// typeUrl: `/${protobufPackage}.MsgSwapAssets`, -// value: MsgSwapAssets.fromPartial({ -// poolId: Number(poolId), -// sender, -// tokenIn, -// tokenOutDenom, -// }), -// } -// } -// } +import { EncodeObject, GeneratedType } from "@cosmjs/proto-signing" +import { + MsgCreatePool, + MsgExitPool, + MsgJoinPool, + MsgSwapAssets, + protobufPackage, +} from "@nibiruchain/protojs/dist/nibiru/spot/v1/tx" +import { TxMessage } from "./encode-types" +import { toSdkDec } from "../chain" + +export const SPOT_MSG_TYPE_URLS = { + MsgCreatePool: `/${protobufPackage}.MsgCreatePool`, + MsgJoinPool: `/${protobufPackage}.MsgJoinPool`, + MsgExitPool: `/${protobufPackage}.MsgExitPool`, + MsgSwapAssets: `/${protobufPackage}.MsgSwapAssets`, +} + +export const spotTypes: ReadonlyArray<[string, GeneratedType]> = [ + [SPOT_MSG_TYPE_URLS.MsgCreatePool, MsgCreatePool], + [SPOT_MSG_TYPE_URLS.MsgJoinPool, MsgJoinPool], + [SPOT_MSG_TYPE_URLS.MsgExitPool, MsgExitPool], + [SPOT_MSG_TYPE_URLS.MsgSwapAssets, MsgSwapAssets], +] + +export interface MsgCreatePoolEncodeObject extends EncodeObject { + readonly typeUrl: string + readonly value: Partial +} + +export const isMsgCreatePoolEncodeObject = (encodeObject: EncodeObject) => + encodeObject.typeUrl === SPOT_MSG_TYPE_URLS.MsgCreatePool + +export interface MsgJoinPoolEncodeObject extends EncodeObject { + readonly typeUrl: string + readonly value: Partial +} + +export const isMsgJoinPoolEncodeObject = (encodeObject: EncodeObject) => + encodeObject.typeUrl === SPOT_MSG_TYPE_URLS.MsgJoinPool + +export interface MsgExitPoolEncodeObject extends EncodeObject { + readonly typeUrl: string + readonly value: Partial +} + +export const isMsgExitPoolEncodeObject = (encodeObject: EncodeObject) => + encodeObject.typeUrl === SPOT_MSG_TYPE_URLS.MsgExitPool + +export interface MsgSwapAssetsEncodeObject extends EncodeObject { + readonly typeUrl: string + readonly value: Partial +} + +export const isMsgSwapAssetsEncodeObject = (encodeObject: EncodeObject) => + encodeObject.typeUrl === SPOT_MSG_TYPE_URLS.MsgSwapAssets + +// ---------------------------------------------------------------------------- + +export class SpotMsgFactory { + static createPool(msg: MsgCreatePool): TxMessage { + if (msg.poolParams) { + const { swapFee, exitFee } = msg.poolParams + msg.poolParams.swapFee = toSdkDec(swapFee) + msg.poolParams.exitFee = toSdkDec(exitFee) + } + + return { + typeUrl: `/${protobufPackage}.MsgCreatePool`, + value: MsgCreatePool.fromPartial(msg), + } + } + + static joinPool({ + poolId, + sender, + tokensIn, + useAllCoins, + }: MsgJoinPool): TxMessage { + return { + typeUrl: `/${protobufPackage}.MsgJoinPool`, + value: MsgJoinPool.fromPartial({ + poolId: Number(poolId), + sender, + tokensIn, + useAllCoins, + }), + } + } + + static exitPool({ poolId, sender, poolShares }: MsgExitPool): TxMessage { + return { + typeUrl: `/${protobufPackage}.MsgExitPool`, + value: MsgExitPool.fromPartial({ + poolId: Number(poolId), + sender, + poolShares, + }), + } + } + + static swapAssets({ + poolId, + sender, + tokenOutDenom, + tokenIn, + }: MsgSwapAssets): TxMessage { + return { + typeUrl: `/${protobufPackage}.MsgSwapAssets`, + value: MsgSwapAssets.fromPartial({ + poolId: Number(poolId), + sender, + tokenIn, + tokenOutDenom, + }), + } + } +} diff --git a/packages/nibijs/src/query/epochs.ts b/packages/nibijs/src/query/epochs.ts index 26bc1dca..7b4e0298 100644 --- a/packages/nibijs/src/query/epochs.ts +++ b/packages/nibijs/src/query/epochs.ts @@ -3,8 +3,8 @@ import { QueryClientImpl, QueryCurrentEpochRequest, QueryCurrentEpochResponse, - QueryEpochInfosRequest, - QueryEpochInfosResponse, + QueryEpochsInfoRequest, + QueryEpochsInfoResponse, } from "@nibiruchain/protojs/dist/nibiru/epochs/v1/query" export interface EpochsExtension { @@ -12,7 +12,7 @@ export interface EpochsExtension { currentEpoch: (args: { identifier: string }) => Promise - epochsInfo: () => Promise + epochsInfo: () => Promise }> } @@ -28,7 +28,7 @@ export const setupEpochsExtension = (base: QueryClient): EpochsExtension => { return resp }, epochsInfo: async () => { - const req = QueryEpochInfosRequest.fromPartial({}) + const req = QueryEpochsInfoRequest.fromPartial({}) const resp = await queryService.EpochInfos(req) return resp }, diff --git a/packages/nibijs/src/query/index.ts b/packages/nibijs/src/query/index.ts index f949ffdd..c96e17de 100644 --- a/packages/nibijs/src/query/index.ts +++ b/packages/nibijs/src/query/index.ts @@ -1,7 +1,7 @@ export * from "./epochs" export * from "./inflation" export * from "./oracle" -// export * from "./perp" +export * from "./perp" export * from "./query" -// export * from "./spot" +export * from "./spot" export * from "./sudo" diff --git a/packages/nibijs/src/query/perp.ts b/packages/nibijs/src/query/perp.ts index b3bc6655..0c64b98d 100644 --- a/packages/nibijs/src/query/perp.ts +++ b/packages/nibijs/src/query/perp.ts @@ -1,74 +1,73 @@ -// import { createProtobufRpcClient, QueryClient } from "@cosmjs/stargate" -// import { -// QueryClientImpl, -// QueryMarketsRequest, -// QueryMarketsResponse, -// QueryModuleAccountsRequest, -// QueryModuleAccountsResponse, -// QueryPositionRequest, -// QueryPositionResponse, -// QueryPositionsRequest, -// QueryPositionsResponse, -// } from "@nibiruchain/protojs/dist/nibiru/perp/v2/query" -// import { fromSdkDec } from "../chain" +import { createProtobufRpcClient, QueryClient } from "@cosmjs/stargate" +import { + QueryClientImpl, + QueryMarketsRequest, + QueryMarketsResponse, + QueryModuleAccountsRequest, + QueryModuleAccountsResponse, + QueryPositionRequest, + QueryPositionResponse, + QueryPositionsRequest, + QueryPositionsResponse, +} from "@nibiruchain/protojs/dist/nibiru/perp/v2/query" +import { fromSdkDec } from "../chain" -// function transformPosition(resp: QueryPositionResponse): QueryPositionResponse { -// const { positionNotional: pn, unrealizedPnl: upnl, marginRatio: mr } = resp -// resp.positionNotional = fromSdkDec(pn).toString() -// resp.unrealizedPnl = fromSdkDec(upnl).toString() -// resp.marginRatio = fromSdkDec(mr).toString() -// return resp -// } +function transformPosition(resp: QueryPositionResponse): QueryPositionResponse { + const { positionNotional: pn, unrealizedPnl: upnl, marginRatio: mr } = resp + resp.positionNotional = fromSdkDec(pn).toString() + resp.unrealizedPnl = fromSdkDec(upnl).toString() + resp.marginRatio = fromSdkDec(mr).toString() + return resp +} -// export interface PerpExtension { -// perp: Readonly<{ -// moduleAccounts: () => Promise -// position: (args: { -// pair: string -// trader: string -// }) => Promise -// positions: (args: { trader: string }) => Promise -// markets: () => Promise -// }> -// } +export interface PerpExtension { + perp: Readonly<{ + moduleAccounts: () => Promise + position: (args: { + pair: string + trader: string + }) => Promise + positions: (args: { trader: string }) => Promise + markets: () => Promise + }> +} -// export function setupPerpExtension(base: QueryClient): PerpExtension { -// const rpcClient = createProtobufRpcClient(base) -// const queryService = new QueryClientImpl(rpcClient) +const transformPositions = ( + resp: QueryPositionsResponse +): QueryPositionsResponse => { + const { positions } = resp + resp.positions = positions.map((position: QueryPositionResponse) => + transformPosition(position) + ) + return resp +} -// return { -// perp: { -// moduleAccounts: async (): Promise => { -// const req = QueryModuleAccountsRequest.fromPartial({}) -// const resp = await queryService.ModuleAccounts(req) -// return resp -// }, -// position: async (args: { pair: string; trader: string }) => { -// const req = QueryPositionRequest.fromPartial(args) -// const resp = await queryService.QueryPosition(req) -// return transformPosition(resp) -// }, -// positions: async (args: { trader: string }) => { -// const req = QueryPositionsRequest.fromPartial(args) -// const resp = await queryService.QueryPositions(req) +export function setupPerpExtension(base: QueryClient): PerpExtension { + const rpcClient = createProtobufRpcClient(base) + const queryService = new QueryClientImpl(rpcClient) -// function transformPositions( -// resp: QueryPositionsResponse -// ): QueryPositionsResponse { -// const { positions } = resp -// resp.positions = positions.map((position: QueryPositionResponse) => -// transformPosition(position) -// ) -// return resp -// } + return { + perp: { + moduleAccounts: async (): Promise => { + const req = QueryModuleAccountsRequest.fromPartial({}) + const resp = await queryService.ModuleAccounts(req) + return resp + }, + position: async (args: { pair: string; trader: string }) => { + const req = QueryPositionRequest.fromPartial(args) + const resp = await queryService.QueryPosition(req) + return transformPosition(resp) + }, + positions: async (args: { trader: string }) => { + const req = QueryPositionsRequest.fromPartial(args) + const resp = await queryService.QueryPositions(req) -// return transformPositions(resp) -// }, -// markets: async () => { -// const req = QueryMarketsRequest.fromPartial({}) -// const resp = queryService.QueryMarkets(req) -// return resp -// }, -// }, -// } -// } + return transformPositions(resp) + }, + markets: async () => { + const req = QueryMarketsRequest.fromPartial({}) + return queryService.QueryMarkets(req) + }, + }, + } +} diff --git a/packages/nibijs/src/query/query.ts b/packages/nibijs/src/query/query.ts index 0d74b09f..60ee425e 100644 --- a/packages/nibijs/src/query/query.ts +++ b/packages/nibijs/src/query/query.ts @@ -21,14 +21,14 @@ import { } from "@cosmjs/cosmwasm-stargate" import { EpochsExtension, setupEpochsExtension } from "./epochs" import { OracleExtension, setupOracleExtension } from "./oracle" -// import { PerpExtension, setupPerpExtension } from "./perp" -// import { setupSpotExtension, SpotExtension } from "./spot" +import { PerpExtension, setupPerpExtension } from "./perp" +import { setupSpotExtension, SpotExtension } from "./spot" import { setupSudoExtension, SudoExtension } from "./sudo" import { InflationExtension, setupInflationExtension } from "./inflation" export type NibiruExtensions = QueryClient & - // SpotExtension & - // PerpExtension & + SpotExtension & + PerpExtension & SudoExtension & InflationExtension & OracleExtension & @@ -64,10 +64,10 @@ export class NibiruQueryClient extends StargateClient { tmClient, setupEpochsExtension, setupOracleExtension, - // setupPerpExtension, + setupPerpExtension, setupSudoExtension, setupInflationExtension, - // setupSpotExtension, + setupSpotExtension, setupDistributionExtension, setupGovExtension, setupStakingExtension, diff --git a/packages/nibijs/src/query/spot.ts b/packages/nibijs/src/query/spot.ts index 95ad2923..39b8a968 100644 --- a/packages/nibijs/src/query/spot.ts +++ b/packages/nibijs/src/query/spot.ts @@ -1,259 +1,259 @@ -// import { createProtobufRpcClient, QueryClient } from "@cosmjs/stargate" -// import { Coin } from "@cosmjs/proto-signing" -// import { Pool, PoolParams } from "@nibiruchain/protojs/dist/nibiru/spot/v1/pool" -// import { -// QueryClientImpl as SpotQueryClientImpl, -// QueryExitExactAmountInRequest, -// QueryExitExactAmountInResponse, -// QueryExitExactAmountOutRequest, -// QueryExitExactAmountOutResponse, -// QueryJoinExactAmountInRequest, -// QueryJoinExactAmountInResponse, -// QueryJoinExactAmountOutRequest, -// QueryJoinExactAmountOutResponse, -// QueryNumPoolsRequest, -// QueryNumPoolsResponse, -// QueryParamsRequest, -// QueryParamsResponse, -// QueryPoolNumberRequest, -// QueryPoolNumberResponse, -// QueryPoolParamsRequest, -// QueryPoolParamsResponse, -// QueryPoolRequest, -// QueryPoolResponse, -// QueryPoolsRequest, -// QueryPoolsResponse, -// QuerySpotPriceRequest, -// QuerySpotPriceResponse, -// QuerySwapExactAmountInRequest, -// QuerySwapExactAmountInResponse, -// QuerySwapExactAmountOutRequest, -// QuerySwapExactAmountOutResponse, -// QueryTotalLiquidityRequest, -// QueryTotalLiquidityResponse, -// QueryTotalPoolLiquidityRequest, -// QueryTotalPoolLiquidityResponse, -// QueryTotalSharesRequest, -// QueryTotalSharesResponse, -// } from "@nibiruchain/protojs/dist/nibiru/spot/v1/query" -// import { fromSdkDec } from "../chain" +import { createProtobufRpcClient, QueryClient } from "@cosmjs/stargate" +import { Coin } from "@cosmjs/proto-signing" +import { Pool, PoolParams } from "@nibiruchain/protojs/dist/nibiru/spot/v1/pool" +import { + QueryClientImpl as SpotQueryClientImpl, + QueryExitExactAmountInRequest, + QueryExitExactAmountInResponse, + QueryExitExactAmountOutRequest, + QueryExitExactAmountOutResponse, + QueryJoinExactAmountInRequest, + QueryJoinExactAmountInResponse, + QueryJoinExactAmountOutRequest, + QueryJoinExactAmountOutResponse, + QueryNumPoolsRequest, + QueryNumPoolsResponse, + QueryParamsRequest, + QueryParamsResponse, + QueryPoolNumberRequest, + QueryPoolNumberResponse, + QueryPoolParamsRequest, + QueryPoolParamsResponse, + QueryPoolRequest, + QueryPoolResponse, + QueryPoolsRequest, + QueryPoolsResponse, + QuerySpotPriceRequest, + QuerySpotPriceResponse, + QuerySwapExactAmountInRequest, + QuerySwapExactAmountInResponse, + QuerySwapExactAmountOutRequest, + QuerySwapExactAmountOutResponse, + QueryTotalLiquidityRequest, + QueryTotalLiquidityResponse, + QueryTotalPoolLiquidityRequest, + QueryTotalPoolLiquidityResponse, + QueryTotalSharesRequest, + QueryTotalSharesResponse, +} from "@nibiruchain/protojs/dist/nibiru/spot/v1/query" +import { fromSdkDec } from "../chain" -// export const transformPoolParams = (pp?: PoolParams) => { -// if (pp) { -// pp.swapFee = fromSdkDec(pp.swapFee).toString() -// pp.exitFee = fromSdkDec(pp.exitFee).toString() -// } -// return pp -// } +export const transformPoolParams = (pp?: PoolParams) => { + if (pp) { + pp.swapFee = fromSdkDec(pp.swapFee).toString() + pp.exitFee = fromSdkDec(pp.exitFee).toString() + } + return pp +} -// export const transformPool = (p?: Pool) => { -// if (!p) { -// return p -// } -// p.poolParams = transformPoolParams(p.poolParams) -// return p -// } +export const transformPool = (p?: Pool) => { + if (!p) { + return p + } + p.poolParams = transformPoolParams(p.poolParams) + return p +} -// export interface SpotExtension { -// spot: Readonly<{ -// params: () => Promise -// poolNumber: () => Promise -// pool: (poolId: number) => Promise -// pools: (pagination?: PageRequest) => Promise -// poolParams: (poolId: number) => Promise -// numPools: () => Promise -// totalLiquidity: () => Promise -// totalPoolLiquidity: ( -// poolId: number -// ) => Promise -// totalShares: (poolId: number) => Promise -// spotPrice: ( -// poolId: number, -// tokenInDenom: string, -// tokenOutDenom: string -// ) => Promise -// estimateSwapExactAmountIn: ( -// poolId: number, -// tokenOutDenom: string, -// tokenIn?: Coin -// ) => Promise -// estimateSwapExactAmountOut: ( -// poolId: number, -// tokenInDenom: string, -// tokenOut?: Coin -// ) => Promise -// estimateJoinExactAmountIn: ( -// poolId: number, -// tokensIn: Coin[] -// ) => Promise -// estimateJoinExactAmountOut: ( -// poolId: number -// ) => Promise -// estimateExitExactAmountIn: ( -// poolId: number, -// poolSharesIn: number -// ) => Promise -// estimateExitExactAmountOut: ( -// poolId: number -// ) => Promise -// }> -// } +export interface SpotExtension { + spot: Readonly<{ + params: () => Promise + poolNumber: () => Promise + pool: (poolId: number) => Promise + pools: (pagination?: PageRequest) => Promise + poolParams: (poolId: number) => Promise + numPools: () => Promise + totalLiquidity: () => Promise + totalPoolLiquidity: ( + poolId: number + ) => Promise + totalShares: (poolId: number) => Promise + spotPrice: ( + poolId: number, + tokenInDenom: string, + tokenOutDenom: string + ) => Promise + estimateSwapExactAmountIn: ( + poolId: number, + tokenOutDenom: string, + tokenIn?: Coin + ) => Promise + estimateSwapExactAmountOut: ( + poolId: number, + tokenInDenom: string, + tokenOut?: Coin + ) => Promise + estimateJoinExactAmountIn: ( + poolId: number, + tokensIn: Coin[] + ) => Promise + estimateJoinExactAmountOut: ( + poolId: number + ) => Promise + estimateExitExactAmountIn: ( + poolId: number, + poolSharesIn: number + ) => Promise + estimateExitExactAmountOut: ( + poolId: number + ) => Promise + }> +} -// export const setupSpotExtension = (base: QueryClient): SpotExtension => { -// const rpcClient = createProtobufRpcClient(base) -// const queryService = new SpotQueryClientImpl(rpcClient) +export const setupSpotExtension = (base: QueryClient): SpotExtension => { + const rpcClient = createProtobufRpcClient(base) + const queryService = new SpotQueryClientImpl(rpcClient) -// return { -// spot: { -// params: () => { -// const req = QueryParamsRequest.fromPartial({}) -// return queryService.Params(req) -// }, -// poolNumber: () => { -// const req = QueryPoolNumberRequest.fromPartial({}) -// return queryService.PoolNumber(req) -// }, -// pool: async (poolId: number) => { -// const req = QueryPoolRequest.fromPartial({ poolId }) -// const resp = await queryService.Pool(req) -// resp.pool = transformPool(resp.pool) -// return resp -// }, -// pools: async (pagination?: PageRequest) => { -// const req = QueryPoolsRequest.fromPartial({ pagination }) -// const resp = await queryService.Pools(req) -// resp.pools = resp.pools.map((p) => transformPool(p)!) -// return resp -// }, -// poolParams: async (poolId: number) => { -// const req = QueryPoolParamsRequest.fromPartial({ poolId }) -// const resp = await queryService.PoolParams(req) -// resp.poolParams = transformPoolParams(resp.poolParams) -// return resp -// }, -// numPools: () => { -// const req = QueryNumPoolsRequest.fromPartial({}) -// return queryService.NumPools(req) -// }, -// totalLiquidity: () => { -// const req = QueryTotalLiquidityRequest.fromPartial({}) -// return queryService.TotalLiquidity(req) -// }, -// totalPoolLiquidity: (poolId: number) => { -// const req = QueryTotalPoolLiquidityRequest.fromPartial({ -// poolId, -// }) -// return queryService.TotalPoolLiquidity(req) -// }, -// totalShares: (poolId: number) => { -// const req = QueryTotalSharesRequest.fromPartial({ poolId }) -// return queryService.TotalShares(req) -// }, -// spotPrice: ( -// poolId: number, -// tokenInDenom: string, -// tokenOutDenom: string -// ) => { -// const req = QuerySpotPriceRequest.fromPartial({ -// poolId, -// tokenInDenom, -// tokenOutDenom, -// }) -// return queryService.SpotPrice(req) -// }, -// estimateSwapExactAmountIn: ( -// poolId: number, -// tokenOutDenom: string, -// tokenIn?: Coin -// ) => { -// const req = QuerySwapExactAmountInRequest.fromPartial({ -// poolId, -// tokenOutDenom, -// tokenIn, -// }) -// return queryService.EstimateSwapExactAmountIn(req) -// }, -// estimateSwapExactAmountOut: ( -// poolId: number, -// tokenInDenom: string, -// tokenOut?: Coin -// ) => { -// const req = QuerySwapExactAmountOutRequest.fromPartial({ -// poolId, -// tokenInDenom, -// tokenOut, -// }) -// return queryService.EstimateSwapExactAmountOut(req) -// }, -// estimateJoinExactAmountIn: (poolId: number, tokensIn: Coin[]) => { -// const req = QueryJoinExactAmountInRequest.fromPartial({ -// poolId, -// tokensIn, -// }) -// return queryService.EstimateJoinExactAmountIn(req) -// }, -// estimateJoinExactAmountOut: (poolId: number) => { -// const req = QueryJoinExactAmountOutRequest.fromPartial({ -// poolId, -// }) -// return queryService.EstimateJoinExactAmountOut(req) -// }, -// estimateExitExactAmountIn: (poolId: number, poolSharesIn: number) => { -// const req = QueryExitExactAmountInRequest.fromPartial({ -// poolId, -// poolSharesIn: poolSharesIn.toString(), -// }) -// return queryService.EstimateExitExactAmountIn(req) -// }, -// estimateExitExactAmountOut: (poolId: number) => { -// const req = QueryExitExactAmountOutRequest.fromPartial({ -// poolId, -// }) -// return queryService.EstimateExitExactAmountOut(req) -// }, -// }, -// } -// } + return { + spot: { + params: () => { + const req = QueryParamsRequest.fromPartial({}) + return queryService.Params(req) + }, + poolNumber: () => { + const req = QueryPoolNumberRequest.fromPartial({}) + return queryService.PoolNumber(req) + }, + pool: async (poolId: number) => { + const req = QueryPoolRequest.fromPartial({ poolId }) + const resp = await queryService.Pool(req) + resp.pool = transformPool(resp.pool) + return resp + }, + pools: async (pagination?: PageRequest) => { + const req = QueryPoolsRequest.fromPartial({ pagination }) + const resp = await queryService.Pools(req) + resp.pools = resp.pools.map((p) => transformPool(p)!) + return resp + }, + poolParams: async (poolId: number) => { + const req = QueryPoolParamsRequest.fromPartial({ poolId }) + const resp = await queryService.PoolParams(req) + resp.poolParams = transformPoolParams(resp.poolParams) + return resp + }, + numPools: () => { + const req = QueryNumPoolsRequest.fromPartial({}) + return queryService.NumPools(req) + }, + totalLiquidity: () => { + const req = QueryTotalLiquidityRequest.fromPartial({}) + return queryService.TotalLiquidity(req) + }, + totalPoolLiquidity: (poolId: number) => { + const req = QueryTotalPoolLiquidityRequest.fromPartial({ + poolId, + }) + return queryService.TotalPoolLiquidity(req) + }, + totalShares: (poolId: number) => { + const req = QueryTotalSharesRequest.fromPartial({ poolId }) + return queryService.TotalShares(req) + }, + spotPrice: ( + poolId: number, + tokenInDenom: string, + tokenOutDenom: string + ) => { + const req = QuerySpotPriceRequest.fromPartial({ + poolId, + tokenInDenom, + tokenOutDenom, + }) + return queryService.SpotPrice(req) + }, + estimateSwapExactAmountIn: ( + poolId: number, + tokenOutDenom: string, + tokenIn?: Coin + ) => { + const req = QuerySwapExactAmountInRequest.fromPartial({ + poolId, + tokenOutDenom, + tokenIn, + }) + return queryService.EstimateSwapExactAmountIn(req) + }, + estimateSwapExactAmountOut: ( + poolId: number, + tokenInDenom: string, + tokenOut?: Coin + ) => { + const req = QuerySwapExactAmountOutRequest.fromPartial({ + poolId, + tokenInDenom, + tokenOut, + }) + return queryService.EstimateSwapExactAmountOut(req) + }, + estimateJoinExactAmountIn: (poolId: number, tokensIn: Coin[]) => { + const req = QueryJoinExactAmountInRequest.fromPartial({ + poolId, + tokensIn, + }) + return queryService.EstimateJoinExactAmountIn(req) + }, + estimateJoinExactAmountOut: (poolId: number) => { + const req = QueryJoinExactAmountOutRequest.fromPartial({ + poolId, + }) + return queryService.EstimateJoinExactAmountOut(req) + }, + estimateExitExactAmountIn: (poolId: number, poolSharesIn: number) => { + const req = QueryExitExactAmountInRequest.fromPartial({ + poolId, + poolSharesIn: poolSharesIn.toString(), + }) + return queryService.EstimateExitExactAmountIn(req) + }, + estimateExitExactAmountOut: (poolId: number) => { + const req = QueryExitExactAmountOutRequest.fromPartial({ + poolId, + }) + return queryService.EstimateExitExactAmountOut(req) + }, + }, + } +} -// /** -// * An offset pagination request. -// * -// * Pagination is the process of dividing a document into discrete pages. -// * Pagination in the context of API requests resembles this process. -// * -// * @export -// * @interface PageRequest -// * @typedef {PageRequest} -// */ -// export interface PageRequest { -// /** -// * key is a value returned in PageResponse.next_key to begin -// * querying the next page most efficiently. Only one of offset or key -// * should be set. -// */ -// key: Uint8Array -// /** -// * offset is a numeric offset that can be used when key is unavailable. -// * It is less efficient than using key. Only one of offset or key should -// * be set. -// */ -// offset: number -// /** -// * limit is the total number of results to be returned in the result page. -// * If left empty it will default to a value to be set by each app. -// */ -// limit: number -// /** -// * count_total is set to true to indicate that the result set should include -// * a count of the total number of items available for pagination in UIs. -// * count_total is only respected when offset is used. It is ignored when key -// * is set. -// */ -// countTotal: boolean -// /** -// * reverse is set to true if results are to be returned in the descending order. -// * -// * Since: cosmos-sdk 0.43 -// */ -// reverse: boolean -// } +/** + * An offset pagination request. + * + * Pagination is the process of dividing a document into discrete pages. + * Pagination in the context of API requests resembles this process. + * + * @export + * @interface PageRequest + * @typedef {PageRequest} + */ +export interface PageRequest { + /** + * key is a value returned in PageResponse.next_key to begin + * querying the next page most efficiently. Only one of offset or key + * should be set. + */ + key: Uint8Array + /** + * offset is a numeric offset that can be used when key is unavailable. + * It is less efficient than using key. Only one of offset or key should + * be set. + */ + offset: number + /** + * limit is the total number of results to be returned in the result page. + * If left empty it will default to a value to be set by each app. + */ + limit: number + /** + * count_total is set to true to indicate that the result set should include + * a count of the total number of items available for pagination in UIs. + * count_total is only respected when offset is used. It is ignored when key + * is set. + */ + countTotal: boolean + /** + * reverse is set to true if results are to be returned in the descending order. + * + * Since: cosmos-sdk 0.43 + */ + reverse: boolean +} diff --git a/packages/nibijs/src/test/query.test.ts b/packages/nibijs/src/test/query.test.ts index 7a526acc..f75aae38 100644 --- a/packages/nibijs/src/test/query.test.ts +++ b/packages/nibijs/src/test/query.test.ts @@ -49,22 +49,22 @@ describe("x/bank queries", () => { }) }) -// describe("x/spot queries", () => { -// test("query spot params", async () => { -// const queryClient = await NibiruQueryClient.connect(TEST_CHAIN.endptTm) -// const { params } = await queryClient.nibiruExtensions.spot.params() -// const fields: string[] = [ -// "poolCreationFee", -// "startingPoolNumber", -// "whitelistedAsset", -// ] -// for (const field of fields) { -// expect(params).toHaveProperty(field) -// } -// expect(params?.whitelistedAsset.length).toBeGreaterThan(0) -// expect(params?.whitelistedAsset[0]).not.toBe("") -// }) -// }) +describe("x/spot queries", () => { + test("query spot params", async () => { + const queryClient = await NibiruQueryClient.connect(TEST_CHAIN.endptTm) + const { params } = await queryClient.nibiruExtensions.spot.params() + const fields: string[] = [ + "poolCreationFee", + "startingPoolNumber", + "whitelistedAsset", + ] + for (const field of fields) { + expect(params).toHaveProperty(field) + } + expect(params?.whitelistedAsset.length).toBeGreaterThan(0) + expect(params?.whitelistedAsset[0]).not.toBe("") + }) +}) describe("x/oracle queries", () => { test("query active oracles", async () => { diff --git a/packages/nibijs/src/test/query.tests/epochs.test.ts b/packages/nibijs/src/test/query.tests/epochs.test.ts index 6977c71e..525ef963 100644 --- a/packages/nibijs/src/test/query.tests/epochs.test.ts +++ b/packages/nibijs/src/test/query.tests/epochs.test.ts @@ -42,8 +42,8 @@ describe("setupEpochsExtension", () => { describe("epochs.epochsInfo", () => { test("should call QueryEpochsInfoRequest and return the response", async () => { const queryEpochsInfoRequest = jest - .spyOn(query.QueryEpochInfosRequest, "fromPartial") - .mockReturnValue({} as query.QueryEpochInfosRequest) + .spyOn(query.QueryEpochsInfoRequest, "fromPartial") + .mockReturnValue({} as query.QueryEpochsInfoRequest) const extension = setupEpochsExtension(mockBaseQueryClient) const result = await extension.epochs.epochsInfo() diff --git a/packages/nibijs/src/test/query.tests/perp.test-hidden.ts b/packages/nibijs/src/test/query.tests/perp.test-hidden.ts deleted file mode 100644 index d712e00e..00000000 --- a/packages/nibijs/src/test/query.tests/perp.test-hidden.ts +++ /dev/null @@ -1,127 +0,0 @@ -// import { QueryClient } from "@cosmjs/stargate" -// import * as query from "@nibiruchain/protojs/dist/nibiru/perp/v2/query" -// import { setupPerpExtension } from "../../query" - -// describe("setupPerpExtension", () => { -// const mockBaseQueryClient = {} as QueryClient - -// test("should setup perp extension correctly", () => { -// const extension = setupPerpExtension(mockBaseQueryClient) - -// expect(extension.perp).toBeDefined() -// expect(extension.perp.moduleAccounts).toBeInstanceOf(Function) -// expect(extension.perp.position).toBeInstanceOf(Function) -// expect(extension.perp.positions).toBeInstanceOf(Function) -// expect(extension.perp.markets).toBeInstanceOf(Function) -// }) - -// jest.spyOn(query, "QueryClientImpl").mockReturnValue({ -// QueryPosition: jest.fn().mockResolvedValue({ -// positionNotional: "100", -// unrealizedPnl: "50", -// marginRatio: "5", -// }), -// QueryPositions: jest.fn().mockResolvedValue({ -// positions: [ -// { -// positionNotional: "100", -// unrealizedPnl: "50", -// marginRatio: "5", -// }, -// { -// positionNotional: "200", -// unrealizedPnl: "100", -// marginRatio: "75", -// }, -// ], -// }), -// ModuleAccounts: jest.fn().mockResolvedValue({ -// moduleAccounts: ["Test Account 1", "Test Account 2"], -// }), -// QueryMarkets: jest.fn().mockResolvedValue({}), -// } as unknown as query.QueryClientImpl) - -// describe("perp.moduleAccounts", () => { -// test("should call QueryModuleAccountsRequest and return the response", async () => { -// const queryModuleAccountsRequest = jest -// .spyOn(query.QueryModuleAccountsRequest, "fromPartial") -// .mockReturnValue({} as query.QueryModuleAccountsRequest) - -// const extension = setupPerpExtension(mockBaseQueryClient) -// const result = await extension.perp.moduleAccounts() - -// expect(queryModuleAccountsRequest).toHaveBeenCalledWith({}) -// expect(result).toEqual({ -// moduleAccounts: ["Test Account 1", "Test Account 2"], -// }) -// }) -// }) - -// describe("perp.position", () => { -// test("should call QueryPositionRequest, transform the response, and return it", async () => { -// const queryPositionRequest = jest -// .spyOn(query.QueryPositionRequest, "fromPartial") -// .mockReturnValue({} as query.QueryPositionRequest) - -// const extension = setupPerpExtension(mockBaseQueryClient) -// const result = await extension.perp.position({ -// pair: "Test Pair", -// trader: "Test Trader", -// }) - -// expect(queryPositionRequest).toHaveBeenCalledWith({ -// pair: "Test Pair", -// trader: "Test Trader", -// }) -// expect(result).toEqual({ -// positionNotional: "1e-16", -// unrealizedPnl: "5e-17", -// marginRatio: "5e-18", -// }) -// }) -// }) - -// describe("perp.positions", () => { -// test("should call QueryPositionsRequest, transform the response, and return it", async () => { -// const queryPositionsRequest = jest -// .spyOn(query.QueryPositionsRequest, "fromPartial") -// .mockReturnValue({} as query.QueryPositionsRequest) - -// const extension = setupPerpExtension(mockBaseQueryClient) -// const result = await extension.perp.positions({ trader: "Test Trader" }) - -// expect(queryPositionsRequest).toHaveBeenCalledWith({ -// trader: "Test Trader", -// }) - -// expect(result).toEqual({ -// positions: [ -// { -// positionNotional: "1e-16", -// unrealizedPnl: "5e-17", -// marginRatio: "5e-18", -// }, -// { -// positionNotional: "2e-16", -// unrealizedPnl: "1e-16", -// marginRatio: "7.5e-17", -// }, -// ], -// }) -// }) -// }) - -// describe("perp.markets", () => { -// test("should call QueryMarketsRequest and return the response", async () => { -// const queryMarketsRequest = jest -// .spyOn(query.QueryMarketsRequest, "fromPartial") -// .mockReturnValue({} as query.QueryMarketsRequest) - -// const extension = setupPerpExtension(mockBaseQueryClient) -// const result = await extension.perp.markets() - -// expect(queryMarketsRequest).toHaveBeenCalledWith({}) -// expect(result).toEqual({}) -// }) -// }) -// }) diff --git a/packages/nibijs/src/test/query.tests/perp.test.ts b/packages/nibijs/src/test/query.tests/perp.test.ts new file mode 100644 index 00000000..fec78d78 --- /dev/null +++ b/packages/nibijs/src/test/query.tests/perp.test.ts @@ -0,0 +1,127 @@ +import { QueryClient } from "@cosmjs/stargate" +import * as query from "@nibiruchain/protojs/dist/nibiru/perp/v2/query" +import { setupPerpExtension } from "../../query" + +describe("setupPerpExtension", () => { + const mockBaseQueryClient = {} as QueryClient + + test("should setup perp extension correctly", () => { + const extension = setupPerpExtension(mockBaseQueryClient) + + expect(extension.perp).toBeDefined() + expect(extension.perp.moduleAccounts).toBeInstanceOf(Function) + expect(extension.perp.position).toBeInstanceOf(Function) + expect(extension.perp.positions).toBeInstanceOf(Function) + expect(extension.perp.markets).toBeInstanceOf(Function) + }) + + jest.spyOn(query, "QueryClientImpl").mockReturnValue({ + QueryPosition: jest.fn().mockResolvedValue({ + positionNotional: "100", + unrealizedPnl: "50", + marginRatio: "5", + }), + QueryPositions: jest.fn().mockResolvedValue({ + positions: [ + { + positionNotional: "100", + unrealizedPnl: "50", + marginRatio: "5", + }, + { + positionNotional: "200", + unrealizedPnl: "100", + marginRatio: "75", + }, + ], + }), + ModuleAccounts: jest.fn().mockResolvedValue({ + moduleAccounts: ["Test Account 1", "Test Account 2"], + }), + QueryMarkets: jest.fn().mockResolvedValue({}), + } as unknown as query.QueryClientImpl) + + describe("perp.moduleAccounts", () => { + test("should call QueryModuleAccountsRequest and return the response", async () => { + const queryModuleAccountsRequest = jest + .spyOn(query.QueryModuleAccountsRequest, "fromPartial") + .mockReturnValue({} as query.QueryModuleAccountsRequest) + + const extension = setupPerpExtension(mockBaseQueryClient) + const result = await extension.perp.moduleAccounts() + + expect(queryModuleAccountsRequest).toHaveBeenCalledWith({}) + expect(result).toEqual({ + moduleAccounts: ["Test Account 1", "Test Account 2"], + }) + }) + }) + + describe("perp.position", () => { + test("should call QueryPositionRequest, transform the response, and return it", async () => { + const queryPositionRequest = jest + .spyOn(query.QueryPositionRequest, "fromPartial") + .mockReturnValue({} as query.QueryPositionRequest) + + const extension = setupPerpExtension(mockBaseQueryClient) + const result = await extension.perp.position({ + pair: "Test Pair", + trader: "Test Trader", + }) + + expect(queryPositionRequest).toHaveBeenCalledWith({ + pair: "Test Pair", + trader: "Test Trader", + }) + expect(result).toEqual({ + marginRatio: "5e-18", + positionNotional: "1e-16", + unrealizedPnl: "5e-17", + }) + }) + }) + + describe("perp.positions", () => { + test("should call QueryPositionsRequest, transform the response, and return it", async () => { + const queryPositionsRequest = jest + .spyOn(query.QueryPositionsRequest, "fromPartial") + .mockReturnValue({} as query.QueryPositionsRequest) + + const extension = setupPerpExtension(mockBaseQueryClient) + const result = await extension.perp.positions({ trader: "Test Trader" }) + + expect(queryPositionsRequest).toHaveBeenCalledWith({ + trader: "Test Trader", + }) + + expect(result).toEqual({ + positions: [ + { + positionNotional: "1e-16", + unrealizedPnl: "5e-17", + marginRatio: "5e-18", + }, + { + positionNotional: "2e-16", + unrealizedPnl: "1e-16", + marginRatio: "7.5e-17", + }, + ], + }) + }) + }) + + describe("perp.markets", () => { + test("should call QueryMarketsRequest and return the response", async () => { + const queryMarketsRequest = jest + .spyOn(query.QueryMarketsRequest, "fromPartial") + .mockReturnValue({} as query.QueryMarketsRequest) + + const extension = setupPerpExtension(mockBaseQueryClient) + const result = await extension.perp.markets() + + expect(queryMarketsRequest).toHaveBeenCalledWith({}) + expect(result).toEqual({}) + }) + }) +}) diff --git a/packages/nibijs/src/test/query.tests/spot.test-hidden.ts b/packages/nibijs/src/test/query.tests/spot.test-hidden.ts deleted file mode 100644 index 436a5f42..00000000 --- a/packages/nibijs/src/test/query.tests/spot.test-hidden.ts +++ /dev/null @@ -1,402 +0,0 @@ -// import { QueryClient } from "@cosmjs/stargate" -// import * as query from "@nibiruchain/protojs/dist/nibiru/spot/v1/query" -// import { setupSpotExtension, transformPool } from "../../query" - -// describe("setupSpotExtension", () => { -// const mockBaseQueryClient = {} as QueryClient - -// jest.spyOn(query, "QueryClientImpl").mockReturnValue({ -// EstimateExitExactAmountIn: jest.fn().mockResolvedValue({ -// tokensOut: [], -// fees: [], -// }), -// EstimateExitExactAmountOut: jest.fn().mockResolvedValue({ -// estimateExitExactAmountOut: {}, -// }), -// EstimateJoinExactAmountIn: jest.fn().mockResolvedValue({ -// poolSharesOut: "", -// remCoins: [], -// }), -// EstimateJoinExactAmountOut: jest.fn().mockResolvedValue({ -// estimateJoinExactAmountOut: {}, -// }), -// EstimateSwapExactAmountIn: jest.fn().mockResolvedValue({ -// tokenOut: {}, -// fee: {}, -// }), -// EstimateSwapExactAmountOut: jest.fn().mockResolvedValue({ -// tokenIn: {}, -// }), -// NumPools: jest.fn().mockResolvedValue({ -// numPools: 0, -// }), -// Params: jest.fn().mockResolvedValue({ -// params: { -// startingPoolNumber: 0, -// poolCreationFee: [], -// whitelistedAsset: [], -// }, -// }), -// Pool: jest.fn().mockResolvedValue({ -// pool: { -// id: 0, -// address: "", -// poolParams: {}, -// poolAssets: [], -// totalWeight: "", -// totalShares: {}, -// }, -// }), -// PoolNumber: jest.fn().mockResolvedValue({ -// poolId: 0, -// }), -// PoolParams: jest.fn().mockResolvedValue({ -// poolParams: { -// swapFee: "", -// exitFee: "", -// A: "", -// poolType: {}, -// }, -// }), -// Pools: jest.fn().mockResolvedValue({ -// pools: [ -// { -// id: 0, -// address: "", -// poolParams: {}, -// poolAssets: [], -// totalWeight: "", -// totalShares: {}, -// }, -// ], -// pagination: {}, -// }), -// SpotPrice: jest.fn().mockResolvedValue({ -// spotPrice: "", -// }), -// TotalLiquidity: jest.fn().mockResolvedValue({ -// liquidity: [], -// }), -// TotalPoolLiquidity: jest.fn().mockResolvedValue({ -// liquidity: [], -// }), -// TotalShares: jest.fn().mockResolvedValue({ -// totalShares: {}, -// }), -// } as unknown as query.QueryClientImpl) - -// test("transformPool undefined", () => { -// const result = transformPool() -// expect(result).toBeUndefined() -// }) - -// test("should setup spot extension correctly", () => { -// const extension = setupSpotExtension(mockBaseQueryClient) - -// expect(extension.spot).toBeDefined() -// expect(extension.spot.estimateExitExactAmountIn).toBeInstanceOf(Function) -// expect(extension.spot.estimateExitExactAmountOut).toBeInstanceOf(Function) -// expect(extension.spot.estimateJoinExactAmountIn).toBeInstanceOf(Function) -// expect(extension.spot.estimateJoinExactAmountOut).toBeInstanceOf(Function) -// expect(extension.spot.estimateSwapExactAmountIn).toBeInstanceOf(Function) -// expect(extension.spot.estimateSwapExactAmountOut).toBeInstanceOf(Function) -// expect(extension.spot.numPools).toBeInstanceOf(Function) -// expect(extension.spot.params).toBeInstanceOf(Function) -// expect(extension.spot.pool).toBeInstanceOf(Function) -// expect(extension.spot.poolNumber).toBeInstanceOf(Function) -// expect(extension.spot.poolParams).toBeInstanceOf(Function) -// expect(extension.spot.pools).toBeInstanceOf(Function) -// expect(extension.spot.spotPrice).toBeInstanceOf(Function) -// expect(extension.spot.totalLiquidity).toBeInstanceOf(Function) -// expect(extension.spot.totalPoolLiquidity).toBeInstanceOf(Function) -// expect(extension.spot.totalShares).toBeInstanceOf(Function) -// }) - -// test("estimateExitExactAmountIn should call and return the response", async () => { -// const queryRequest = jest -// .spyOn(query.QueryExitExactAmountInRequest, "fromPartial") -// .mockReturnValue({} as query.QueryExitExactAmountInRequest) - -// const extension = setupSpotExtension(mockBaseQueryClient) -// const result = await extension.spot.estimateExitExactAmountIn(0, 1) - -// expect(queryRequest).toHaveBeenCalledWith({ -// poolId: 0, -// poolSharesIn: "1", -// }) -// expect(result).toEqual({ -// tokensOut: [], -// fees: [], -// }) -// }) - -// test("estimateExitExactAmountOut should call and return the response", async () => { -// const queryRequest = jest -// .spyOn(query.QueryExitExactAmountOutRequest, "fromPartial") -// .mockReturnValue({} as query.QueryExitExactAmountOutRequest) - -// const extension = setupSpotExtension(mockBaseQueryClient) -// const result = await extension.spot.estimateExitExactAmountOut(0) - -// expect(queryRequest).toHaveBeenCalledWith({ -// poolId: 0, -// }) -// expect(result).toEqual({ -// estimateExitExactAmountOut: {}, -// }) -// }) - -// test("estimateJoinExactAmountIn should call and return the response", async () => { -// const queryRequest = jest -// .spyOn(query.QueryJoinExactAmountInRequest, "fromPartial") -// .mockReturnValue({} as query.QueryJoinExactAmountInRequest) - -// const extension = setupSpotExtension(mockBaseQueryClient) -// const result = await extension.spot.estimateJoinExactAmountIn(0, []) - -// expect(queryRequest).toHaveBeenCalledWith({ -// poolId: 0, -// tokensIn: [], -// }) -// expect(result).toEqual({ -// poolSharesOut: "", -// remCoins: [], -// }) -// }) - -// test("estimateJoinExactAmountOut should call and return the response", async () => { -// const queryRequest = jest -// .spyOn(query.QueryJoinExactAmountOutRequest, "fromPartial") -// .mockReturnValue({} as query.QueryJoinExactAmountOutRequest) - -// const extension = setupSpotExtension(mockBaseQueryClient) -// const result = await extension.spot.estimateJoinExactAmountOut(0) - -// expect(queryRequest).toHaveBeenCalledWith({ -// poolId: 0, -// }) -// expect(result).toEqual({ -// estimateJoinExactAmountOut: {}, -// }) -// }) - -// test("estimateSwapExactAmountIn should call and return the response", async () => { -// const queryRequest = jest -// .spyOn(query.QuerySwapExactAmountInRequest, "fromPartial") -// .mockReturnValue({} as query.QuerySwapExactAmountInRequest) - -// const extension = setupSpotExtension(mockBaseQueryClient) -// const result = await extension.spot.estimateSwapExactAmountIn(0, "") - -// expect(queryRequest).toHaveBeenCalledWith({ -// poolId: 0, -// tokenIn: undefined, -// tokenOutDenom: "", -// }) -// expect(result).toEqual({ -// tokenOut: {}, -// fee: {}, -// }) -// }) - -// test("estimateSwapExactAmountOut should call and return the response", async () => { -// const queryRequest = jest -// .spyOn(query.QuerySwapExactAmountOutRequest, "fromPartial") -// .mockReturnValue({} as query.QuerySwapExactAmountOutRequest) - -// const extension = setupSpotExtension(mockBaseQueryClient) -// const result = await extension.spot.estimateSwapExactAmountOut(0, "") - -// expect(queryRequest).toHaveBeenCalledWith({ -// poolId: 0, -// tokenInDenom: "", -// }) -// expect(result).toEqual({ -// tokenIn: {}, -// }) -// }) - -// test("numPools should call and return the response", async () => { -// const queryParamsRequest = jest -// .spyOn(query.QueryNumPoolsRequest, "fromPartial") -// .mockReturnValue({} as query.QueryNumPoolsRequest) - -// const extension = setupSpotExtension(mockBaseQueryClient) -// const result = await extension.spot.numPools() - -// expect(queryParamsRequest).toHaveBeenCalledWith({}) -// expect(result).toEqual({ -// numPools: 0, -// }) -// }) - -// test("params should call and return the response", async () => { -// const queryParamsRequest = jest -// .spyOn(query.QueryParamsRequest, "fromPartial") -// .mockReturnValue({} as query.QueryParamsRequest) - -// const extension = setupSpotExtension(mockBaseQueryClient) -// const result = await extension.spot.params() - -// expect(queryParamsRequest).toHaveBeenCalledWith({}) -// expect(result).toEqual({ -// params: { -// startingPoolNumber: 0, -// poolCreationFee: [], -// whitelistedAsset: [], -// }, -// }) -// }) - -// test("pool should call and return the response", async () => { -// const queryParamsRequest = jest -// .spyOn(query.QueryPoolRequest, "fromPartial") -// .mockReturnValue({} as query.QueryPoolRequest) - -// const extension = setupSpotExtension(mockBaseQueryClient) -// const result = await extension.spot.pool(0) - -// expect(queryParamsRequest).toHaveBeenCalledWith({ poolId: 0 }) -// expect(result).toEqual({ -// pool: { -// id: 0, -// address: "", -// poolParams: { -// exitFee: "0", -// swapFee: "0", -// }, -// poolAssets: [], -// totalWeight: "", -// totalShares: {}, -// }, -// }) -// }) - -// test("poolNumber should call and return the response", async () => { -// const queryParamsRequest = jest -// .spyOn(query.QueryPoolNumberRequest, "fromPartial") -// .mockReturnValue({} as query.QueryPoolNumberRequest) - -// const extension = setupSpotExtension(mockBaseQueryClient) -// const result = await extension.spot.poolNumber() - -// expect(queryParamsRequest).toHaveBeenCalledWith({}) -// expect(result).toEqual({ -// poolId: 0, -// }) -// }) - -// test("poolParams should call and return the response", async () => { -// const queryParamsRequest = jest -// .spyOn(query.QueryPoolParamsRequest, "fromPartial") -// .mockReturnValue({} as query.QueryPoolParamsRequest) - -// const extension = setupSpotExtension(mockBaseQueryClient) -// const result = await extension.spot.poolParams(0) - -// expect(queryParamsRequest).toHaveBeenCalledWith({ poolId: 0 }) -// expect(result).toEqual({ -// poolParams: { -// swapFee: "0", -// exitFee: "0", -// A: "", -// poolType: {}, -// }, -// }) -// }) - -// test("pools should call and return the response", async () => { -// const queryParamsRequest = jest -// .spyOn(query.QueryPoolsRequest, "fromPartial") -// .mockReturnValue({} as query.QueryPoolsRequest) - -// const extension = setupSpotExtension(mockBaseQueryClient) -// const result = await extension.spot.pools() - -// expect(queryParamsRequest).toHaveBeenCalledWith({ pagination: undefined }) -// expect(result).toEqual({ -// pools: [ -// { -// id: 0, -// address: "", -// poolParams: { -// exitFee: "0", -// swapFee: "0", -// }, -// poolAssets: [], -// totalWeight: "", -// totalShares: {}, -// }, -// ], -// pagination: {}, -// }) -// }) - -// test("spotPrice should call and return the response", async () => { -// const queryParamsRequest = jest -// .spyOn(query.QuerySpotPriceRequest, "fromPartial") -// .mockReturnValue({} as query.QuerySpotPriceRequest) - -// const extension = setupSpotExtension(mockBaseQueryClient) -// const result = await extension.spot.spotPrice(0, "", "") - -// expect(queryParamsRequest).toHaveBeenCalledWith({ -// poolId: 0, -// tokenInDenom: "", -// tokenOutDenom: "", -// }) -// expect(result).toEqual({ -// spotPrice: "", -// }) -// }) - -// test("totalLiquidity should call and return the response", async () => { -// const queryParamsRequest = jest -// .spyOn(query.QuerySpotPriceRequest, "fromPartial") -// .mockReturnValue({} as query.QuerySpotPriceRequest) - -// const extension = setupSpotExtension(mockBaseQueryClient) -// const result = await extension.spot.totalLiquidity() - -// expect(queryParamsRequest).toHaveBeenCalledWith({ -// poolId: 0, -// tokenInDenom: "", -// tokenOutDenom: "", -// }) -// expect(result).toEqual({ -// liquidity: [], -// }) -// }) - -// test("totalPoolLiquidity should call and return the response", async () => { -// const queryParamsRequest = jest -// .spyOn(query.QueryTotalPoolLiquidityRequest, "fromPartial") -// .mockReturnValue({} as query.QueryTotalPoolLiquidityRequest) - -// const extension = setupSpotExtension(mockBaseQueryClient) -// const result = await extension.spot.totalPoolLiquidity(0) - -// expect(queryParamsRequest).toHaveBeenCalledWith({ -// poolId: 0, -// }) -// expect(result).toEqual({ -// liquidity: [], -// }) -// }) - -// test("totalShares should call and return the response", async () => { -// const queryParamsRequest = jest -// .spyOn(query.QueryTotalSharesRequest, "fromPartial") -// .mockReturnValue({} as query.QueryTotalSharesRequest) - -// const extension = setupSpotExtension(mockBaseQueryClient) -// const result = await extension.spot.totalShares(0) - -// expect(queryParamsRequest).toHaveBeenCalledWith({ -// poolId: 0, -// }) -// expect(result).toEqual({ -// totalShares: {}, -// }) -// }) -// }) diff --git a/packages/nibijs/src/test/query.tests/spot.test.ts b/packages/nibijs/src/test/query.tests/spot.test.ts new file mode 100644 index 00000000..8dce13cb --- /dev/null +++ b/packages/nibijs/src/test/query.tests/spot.test.ts @@ -0,0 +1,402 @@ +import { QueryClient } from "@cosmjs/stargate" +import * as query from "@nibiruchain/protojs/dist/nibiru/spot/v1/query" +import { setupSpotExtension, transformPool } from "../../query" + +describe("setupSpotExtension", () => { + const mockBaseQueryClient = {} as QueryClient + + jest.spyOn(query, "QueryClientImpl").mockReturnValue({ + EstimateExitExactAmountIn: jest.fn().mockResolvedValue({ + tokensOut: [], + fees: [], + }), + EstimateExitExactAmountOut: jest.fn().mockResolvedValue({ + estimateExitExactAmountOut: {}, + }), + EstimateJoinExactAmountIn: jest.fn().mockResolvedValue({ + poolSharesOut: "", + remCoins: [], + }), + EstimateJoinExactAmountOut: jest.fn().mockResolvedValue({ + estimateJoinExactAmountOut: {}, + }), + EstimateSwapExactAmountIn: jest.fn().mockResolvedValue({ + tokenOut: {}, + fee: {}, + }), + EstimateSwapExactAmountOut: jest.fn().mockResolvedValue({ + tokenIn: {}, + }), + NumPools: jest.fn().mockResolvedValue({ + numPools: 0, + }), + Params: jest.fn().mockResolvedValue({ + params: { + startingPoolNumber: 0, + poolCreationFee: [], + whitelistedAsset: [], + }, + }), + Pool: jest.fn().mockResolvedValue({ + pool: { + id: 0, + address: "", + poolParams: {}, + poolAssets: [], + totalWeight: "", + totalShares: {}, + }, + }), + PoolNumber: jest.fn().mockResolvedValue({ + poolId: 0, + }), + PoolParams: jest.fn().mockResolvedValue({ + poolParams: { + swapFee: "", + exitFee: "", + A: "", + poolType: {}, + }, + }), + Pools: jest.fn().mockResolvedValue({ + pools: [ + { + id: 0, + address: "", + poolParams: {}, + poolAssets: [], + totalWeight: "", + totalShares: {}, + }, + ], + pagination: {}, + }), + SpotPrice: jest.fn().mockResolvedValue({ + spotPrice: "", + }), + TotalLiquidity: jest.fn().mockResolvedValue({ + liquidity: [], + }), + TotalPoolLiquidity: jest.fn().mockResolvedValue({ + liquidity: [], + }), + TotalShares: jest.fn().mockResolvedValue({ + totalShares: {}, + }), + } as unknown as query.QueryClientImpl) + + test("transformPool undefined", () => { + const result = transformPool() + expect(result).toBeUndefined() + }) + + test("should setup spot extension correctly", () => { + const extension = setupSpotExtension(mockBaseQueryClient) + + expect(extension.spot).toBeDefined() + expect(extension.spot.estimateExitExactAmountIn).toBeInstanceOf(Function) + expect(extension.spot.estimateExitExactAmountOut).toBeInstanceOf(Function) + expect(extension.spot.estimateJoinExactAmountIn).toBeInstanceOf(Function) + expect(extension.spot.estimateJoinExactAmountOut).toBeInstanceOf(Function) + expect(extension.spot.estimateSwapExactAmountIn).toBeInstanceOf(Function) + expect(extension.spot.estimateSwapExactAmountOut).toBeInstanceOf(Function) + expect(extension.spot.numPools).toBeInstanceOf(Function) + expect(extension.spot.params).toBeInstanceOf(Function) + expect(extension.spot.pool).toBeInstanceOf(Function) + expect(extension.spot.poolNumber).toBeInstanceOf(Function) + expect(extension.spot.poolParams).toBeInstanceOf(Function) + expect(extension.spot.pools).toBeInstanceOf(Function) + expect(extension.spot.spotPrice).toBeInstanceOf(Function) + expect(extension.spot.totalLiquidity).toBeInstanceOf(Function) + expect(extension.spot.totalPoolLiquidity).toBeInstanceOf(Function) + expect(extension.spot.totalShares).toBeInstanceOf(Function) + }) + + test("estimateExitExactAmountIn should call and return the response", async () => { + const queryRequest = jest + .spyOn(query.QueryExitExactAmountInRequest, "fromPartial") + .mockReturnValue({} as query.QueryExitExactAmountInRequest) + + const extension = setupSpotExtension(mockBaseQueryClient) + const result = await extension.spot.estimateExitExactAmountIn(0, 1) + + expect(queryRequest).toHaveBeenCalledWith({ + poolId: 0, + poolSharesIn: "1", + }) + expect(result).toEqual({ + tokensOut: [], + fees: [], + }) + }) + + test("estimateExitExactAmountOut should call and return the response", async () => { + const queryRequest = jest + .spyOn(query.QueryExitExactAmountOutRequest, "fromPartial") + .mockReturnValue({} as query.QueryExitExactAmountOutRequest) + + const extension = setupSpotExtension(mockBaseQueryClient) + const result = await extension.spot.estimateExitExactAmountOut(0) + + expect(queryRequest).toHaveBeenCalledWith({ + poolId: 0, + }) + expect(result).toEqual({ + estimateExitExactAmountOut: {}, + }) + }) + + test("estimateJoinExactAmountIn should call and return the response", async () => { + const queryRequest = jest + .spyOn(query.QueryJoinExactAmountInRequest, "fromPartial") + .mockReturnValue({} as query.QueryJoinExactAmountInRequest) + + const extension = setupSpotExtension(mockBaseQueryClient) + const result = await extension.spot.estimateJoinExactAmountIn(0, []) + + expect(queryRequest).toHaveBeenCalledWith({ + poolId: 0, + tokensIn: [], + }) + expect(result).toEqual({ + poolSharesOut: "", + remCoins: [], + }) + }) + + test("estimateJoinExactAmountOut should call and return the response", async () => { + const queryRequest = jest + .spyOn(query.QueryJoinExactAmountOutRequest, "fromPartial") + .mockReturnValue({} as query.QueryJoinExactAmountOutRequest) + + const extension = setupSpotExtension(mockBaseQueryClient) + const result = await extension.spot.estimateJoinExactAmountOut(0) + + expect(queryRequest).toHaveBeenCalledWith({ + poolId: 0, + }) + expect(result).toEqual({ + estimateJoinExactAmountOut: {}, + }) + }) + + test("estimateSwapExactAmountIn should call and return the response", async () => { + const queryRequest = jest + .spyOn(query.QuerySwapExactAmountInRequest, "fromPartial") + .mockReturnValue({} as query.QuerySwapExactAmountInRequest) + + const extension = setupSpotExtension(mockBaseQueryClient) + const result = await extension.spot.estimateSwapExactAmountIn(0, "") + + expect(queryRequest).toHaveBeenCalledWith({ + poolId: 0, + tokenIn: undefined, + tokenOutDenom: "", + }) + expect(result).toEqual({ + tokenOut: {}, + fee: {}, + }) + }) + + test("estimateSwapExactAmountOut should call and return the response", async () => { + const queryRequest = jest + .spyOn(query.QuerySwapExactAmountOutRequest, "fromPartial") + .mockReturnValue({} as query.QuerySwapExactAmountOutRequest) + + const extension = setupSpotExtension(mockBaseQueryClient) + const result = await extension.spot.estimateSwapExactAmountOut(0, "") + + expect(queryRequest).toHaveBeenCalledWith({ + poolId: 0, + tokenInDenom: "", + }) + expect(result).toEqual({ + tokenIn: {}, + }) + }) + + test("numPools should call and return the response", async () => { + const queryParamsRequest = jest + .spyOn(query.QueryNumPoolsRequest, "fromPartial") + .mockReturnValue({} as query.QueryNumPoolsRequest) + + const extension = setupSpotExtension(mockBaseQueryClient) + const result = await extension.spot.numPools() + + expect(queryParamsRequest).toHaveBeenCalledWith({}) + expect(result).toEqual({ + numPools: 0, + }) + }) + + test("params should call and return the response", async () => { + const queryParamsRequest = jest + .spyOn(query.QueryParamsRequest, "fromPartial") + .mockReturnValue({} as query.QueryParamsRequest) + + const extension = setupSpotExtension(mockBaseQueryClient) + const result = await extension.spot.params() + + expect(queryParamsRequest).toHaveBeenCalledWith({}) + expect(result).toEqual({ + params: { + startingPoolNumber: 0, + poolCreationFee: [], + whitelistedAsset: [], + }, + }) + }) + + test("pool should call and return the response", async () => { + const queryParamsRequest = jest + .spyOn(query.QueryPoolRequest, "fromPartial") + .mockReturnValue({} as query.QueryPoolRequest) + + const extension = setupSpotExtension(mockBaseQueryClient) + const result = await extension.spot.pool(0) + + expect(queryParamsRequest).toHaveBeenCalledWith({ poolId: 0 }) + expect(result).toEqual({ + pool: { + id: 0, + address: "", + poolParams: { + exitFee: "0", + swapFee: "0", + }, + poolAssets: [], + totalWeight: "", + totalShares: {}, + }, + }) + }) + + test("poolNumber should call and return the response", async () => { + const queryParamsRequest = jest + .spyOn(query.QueryPoolNumberRequest, "fromPartial") + .mockReturnValue({} as query.QueryPoolNumberRequest) + + const extension = setupSpotExtension(mockBaseQueryClient) + const result = await extension.spot.poolNumber() + + expect(queryParamsRequest).toHaveBeenCalledWith({}) + expect(result).toEqual({ + poolId: 0, + }) + }) + + test("poolParams should call and return the response", async () => { + const queryParamsRequest = jest + .spyOn(query.QueryPoolParamsRequest, "fromPartial") + .mockReturnValue({} as query.QueryPoolParamsRequest) + + const extension = setupSpotExtension(mockBaseQueryClient) + const result = await extension.spot.poolParams(0) + + expect(queryParamsRequest).toHaveBeenCalledWith({ poolId: 0 }) + expect(result).toEqual({ + poolParams: { + swapFee: "0", + exitFee: "0", + A: "", + poolType: {}, + }, + }) + }) + + test("pools should call and return the response", async () => { + const queryParamsRequest = jest + .spyOn(query.QueryPoolsRequest, "fromPartial") + .mockReturnValue({} as query.QueryPoolsRequest) + + const extension = setupSpotExtension(mockBaseQueryClient) + const result = await extension.spot.pools() + + expect(queryParamsRequest).toHaveBeenCalledWith({ pagination: undefined }) + expect(result).toEqual({ + pools: [ + { + id: 0, + address: "", + poolParams: { + exitFee: "0", + swapFee: "0", + }, + poolAssets: [], + totalWeight: "", + totalShares: {}, + }, + ], + pagination: {}, + }) + }) + + test("spotPrice should call and return the response", async () => { + const queryParamsRequest = jest + .spyOn(query.QuerySpotPriceRequest, "fromPartial") + .mockReturnValue({} as query.QuerySpotPriceRequest) + + const extension = setupSpotExtension(mockBaseQueryClient) + const result = await extension.spot.spotPrice(0, "", "") + + expect(queryParamsRequest).toHaveBeenCalledWith({ + poolId: 0, + tokenInDenom: "", + tokenOutDenom: "", + }) + expect(result).toEqual({ + spotPrice: "", + }) + }) + + test("totalLiquidity should call and return the response", async () => { + const queryParamsRequest = jest + .spyOn(query.QuerySpotPriceRequest, "fromPartial") + .mockReturnValue({} as query.QuerySpotPriceRequest) + + const extension = setupSpotExtension(mockBaseQueryClient) + const result = await extension.spot.totalLiquidity() + + expect(queryParamsRequest).toHaveBeenCalledWith({ + poolId: 0, + tokenInDenom: "", + tokenOutDenom: "", + }) + expect(result).toEqual({ + liquidity: [], + }) + }) + + test("totalPoolLiquidity should call and return the response", async () => { + const queryParamsRequest = jest + .spyOn(query.QueryTotalPoolLiquidityRequest, "fromPartial") + .mockReturnValue({} as query.QueryTotalPoolLiquidityRequest) + + const extension = setupSpotExtension(mockBaseQueryClient) + const result = await extension.spot.totalPoolLiquidity(0) + + expect(queryParamsRequest).toHaveBeenCalledWith({ + poolId: 0, + }) + expect(result).toEqual({ + liquidity: [], + }) + }) + + test("totalShares should call and return the response", async () => { + const queryParamsRequest = jest + .spyOn(query.QueryTotalSharesRequest, "fromPartial") + .mockReturnValue({} as query.QueryTotalSharesRequest) + + const extension = setupSpotExtension(mockBaseQueryClient) + const result = await extension.spot.totalShares(0) + + expect(queryParamsRequest).toHaveBeenCalledWith({ + poolId: 0, + }) + expect(result).toEqual({ + totalShares: {}, + }) + }) +}) diff --git a/packages/nibijs/src/tx/signingClient.test.ts b/packages/nibijs/src/tx/signingClient.test.ts index 7744a90c..d4d44a7b 100644 --- a/packages/nibijs/src/tx/signingClient.test.ts +++ b/packages/nibijs/src/tx/signingClient.test.ts @@ -1,36 +1,24 @@ +import { AccountData, coin, coins, parseCoins } from "@cosmjs/proto-signing" +import { assertIsDeliverTxSuccess, DeliverTxResponse } from "@cosmjs/stargate" import { - AccountData, - // coin, - // coins, - // DirectSecp256k1HdWallet, - parseCoins, -} from "@cosmjs/proto-signing" + MsgAddMargin, + MsgClosePosition, + MsgMarketOrder, + MsgRemoveMargin, +} from "@nibiruchain/protojs/dist/nibiru/perp/v2/tx" +import { Direction } from "@nibiruchain/protojs/dist/nibiru/perp/v2/state" +import { TxLog } from "../chain" +import { Msg, TxMessage } from "../msg" +import { PERP_MSG_TYPE_URLS } from "../msg/perp" +import { NibiruQueryClient } from "../query/query" import { - assertIsDeliverTxSuccess, - // DeliverTxResponse -} from "@cosmjs/stargate" -// import { -// MsgAddMargin, -// MsgClosePosition, -// MsgMarketOrder, -// MsgRemoveMargin, -// } from "@nibiruchain/protojs/dist/nibiru/perp/v2/tx" -// import { Direction } from "@nibiruchain/protojs/dist/nibiru/perp/v2/state" -// import { TxLog } from "../chain" -// import { -// Msg, -// TxMessage, -// } from "../msg" -// import { PERP_MSG_TYPE_URLS } from "../msg/perp" -// import { NibiruQueryClient } from "../query/query" -import { - // assertHasEventType, - // assertHasMsgType, - // assertExpectedError, + assertHasEventType, + assertHasMsgType, + assertExpectedError, TEST_CHAIN, - // TEST_ADDRESS, + TEST_ADDRESS, TEST_MNEMONIC, - // ERR, + ERR, } from "../test/helpers" import { newRandomWallet, newSignerFromMnemonic } from "./signer" import { NibiruSigningClient } from "./signingClient" @@ -67,179 +55,179 @@ describe("nibid tx bank send", () => { }) }) -// describe("nibid tx perp", () => { -// const pair = "ubtc:unusd" - -// test("open-position, add-margin, remove-margin", async () => { -// const signer = await newSignerFromMnemonic(TEST_MNEMONIC) -// const signingClient = await NibiruSigningClient.connectWithSigner( -// TEST_CHAIN.endptTm, -// signer -// ) -// const [{ address: sender }] = await signer.getAccounts() - -// const fee = { -// amount: coins(10_000, "unibi"), -// gas: "400000", -// } - -// const msgs: TxMessage[] = [ -// { -// typeUrl: PERP_MSG_TYPE_URLS.MsgMarketOrder, -// value: MsgMarketOrder.fromPartial({ -// pair, -// baseAssetAmountLimit: "0", -// leverage: "10", -// quoteAssetAmount: "1000", -// sender, -// side: Direction.LONG, -// }), -// }, -// { -// typeUrl: PERP_MSG_TYPE_URLS.MsgAddMargin, -// value: MsgAddMargin.fromPartial({ -// margin: coin(20, "unusd"), -// pair, -// sender, -// }), -// }, -// { -// typeUrl: PERP_MSG_TYPE_URLS.MsgRemoveMargin, -// value: MsgRemoveMargin.fromPartial({ -// margin: coin(5, "unusd"), -// pair, -// sender, -// }), -// }, -// Msg.perp.openPosition({ -// sender, -// pair, -// goLong: false, -// quoteAssetAmount: 200, -// leverage: 4, -// }), -// ] - -// const assertHappyPath = (result: DeliverTxResponse) => { -// const txLogs: TxLog[] = JSON.parse(result.rawLog!) -// expect(txLogs).toHaveLength(4) - -// // perp tx open-position events -// let idx = 0 -// assertHasMsgType(PERP_MSG_TYPE_URLS.MsgMarketOrder, txLogs[idx].events) -// assertHasEventType( -// "nibiru.perp.v1.PositionChangedEvent", -// txLogs[idx].events -// ) -// assertHasEventType("transfer", txLogs[idx].events) - -// // perp tx add-margin events -// idx = 1 -// assertHasMsgType(PERP_MSG_TYPE_URLS.MsgAddMargin, txLogs[idx].events) -// assertHasEventType( -// "nibiru.perp.v1.PositionChangedEvent", -// txLogs[idx].events -// ) -// assertHasEventType("transfer", txLogs[idx].events) - -// // perp tx remove-margin events -// idx = 2 -// assertHasMsgType(PERP_MSG_TYPE_URLS.MsgRemoveMargin, txLogs[idx].events) -// assertHasEventType( -// "nibiru.perp.v1.PositionChangedEvent", -// txLogs[idx].events -// ) -// assertHasEventType("transfer", txLogs[idx].events) - -// // perp tx open-position events -// idx = 3 -// assertHasMsgType(PERP_MSG_TYPE_URLS.MsgAddMargin, txLogs[idx].events) -// assertHasEventType( -// "nibiru.perp.v1.PositionChangedEvent", -// txLogs[idx].events -// ) -// assertHasEventType("transfer", txLogs[idx].events) -// } - -// try { -// const result = await signingClient.signAndBroadcast(sender, msgs, fee) -// console.log(result) -// assertIsDeliverTxSuccess(result) -// assertHappyPath(result) -// } catch (error) { -// const okErrors: string[] = [ERR.collections, ERR.noPrices, ERR.sequence] - -// let err = error as any -// if (err.rawLog) { -// err = err.rawLog -// } -// assertExpectedError(err, okErrors) -// } -// }, 40_000 /* default timeout is not sufficient. */) - -// test("nibid query perp positions", async () => { -// const queryClient = await NibiruQueryClient.connect(TEST_CHAIN.endptTm) -// const resp = await queryClient.nibiruExtensions.perp.positions({ -// trader: TEST_ADDRESS, -// }) -// resp.positions.forEach((position) => { -// const fields = [ -// position.position, -// position.unrealizedPnl, -// position.positionNotional, -// ] -// fields.forEach((val) => expect(val).toBeDefined()) -// }) -// }) - -// test("nibid tx perp close-position", async () => { -// const signer = await newSignerFromMnemonic(TEST_MNEMONIC) -// const signingClient = await NibiruSigningClient.connectWithSigner( -// TEST_CHAIN.endptTm, -// signer -// ) -// const [{ address: sender }] = await signer.getAccounts() - -// const fee = { -// amount: coins(12_500, "unibi"), -// gas: "500000", -// } - -// const msgs: TxMessage[] = [ -// { -// typeUrl: PERP_MSG_TYPE_URLS.MsgClosePosition, -// value: MsgClosePosition.fromPartial({ -// pair, -// sender, -// }), -// }, -// ] - -// const assertHappyPath = (result: DeliverTxResponse) => { -// const txLogs: TxLog[] = JSON.parse(result.rawLog!) -// expect(txLogs).toHaveLength(1) - -// // perp tx close-position events -// assertHasMsgType("MsgClosePosition", txLogs[0].events) -// assertHasEventType( -// "nibiru.perp.v1.PositionChangedEvent", -// txLogs[0].events -// ) -// assertHasEventType("transfer", txLogs[0].events) -// } - -// try { -// const result = await signingClient.signAndBroadcast(sender, msgs, fee) -// assertIsDeliverTxSuccess(result) -// assertHappyPath(result) -// } catch (error) { -// const okErrors: string[] = [ERR.collections, ERR.sequence] - -// let err = error as any -// if (err.rawLog) { -// err = err.rawLog -// } -// assertExpectedError(err, okErrors) -// } -// }) -// }) +describe("nibid tx perp", () => { + const pair = "ubtc:unusd" + + test("open-position, add-margin, remove-margin", async () => { + const signer = await newSignerFromMnemonic(TEST_MNEMONIC) + const signingClient = await NibiruSigningClient.connectWithSigner( + TEST_CHAIN.endptTm, + signer + ) + const [{ address: sender }] = await signer.getAccounts() + + const fee = { + amount: coins(10_000, "unibi"), + gas: "400000", + } + + const msgs: TxMessage[] = [ + { + typeUrl: PERP_MSG_TYPE_URLS.MsgMarketOrder, + value: MsgMarketOrder.fromPartial({ + pair, + baseAssetAmountLimit: "0", + leverage: "10", + quoteAssetAmount: "1000", + sender, + side: Direction.LONG, + }), + }, + { + typeUrl: PERP_MSG_TYPE_URLS.MsgAddMargin, + value: MsgAddMargin.fromPartial({ + margin: coin(20, "unusd"), + pair, + sender, + }), + }, + { + typeUrl: PERP_MSG_TYPE_URLS.MsgRemoveMargin, + value: MsgRemoveMargin.fromPartial({ + margin: coin(5, "unusd"), + pair, + sender, + }), + }, + Msg.perp.openPosition({ + sender, + pair, + goLong: false, + quoteAssetAmount: 200, + leverage: 4, + }), + ] + + const assertHappyPath = (result: DeliverTxResponse) => { + const txLogs: TxLog[] = JSON.parse(result.rawLog!) + expect(txLogs).toHaveLength(4) + + // perp tx open-position events + let idx = 0 + assertHasMsgType(PERP_MSG_TYPE_URLS.MsgMarketOrder, txLogs[idx].events) + assertHasEventType( + "nibiru.perp.v1.PositionChangedEvent", + txLogs[idx].events + ) + assertHasEventType("transfer", txLogs[idx].events) + + // perp tx add-margin events + idx = 1 + assertHasMsgType(PERP_MSG_TYPE_URLS.MsgAddMargin, txLogs[idx].events) + assertHasEventType( + "nibiru.perp.v1.PositionChangedEvent", + txLogs[idx].events + ) + assertHasEventType("transfer", txLogs[idx].events) + + // perp tx remove-margin events + idx = 2 + assertHasMsgType(PERP_MSG_TYPE_URLS.MsgRemoveMargin, txLogs[idx].events) + assertHasEventType( + "nibiru.perp.v1.PositionChangedEvent", + txLogs[idx].events + ) + assertHasEventType("transfer", txLogs[idx].events) + + // perp tx open-position events + idx = 3 + assertHasMsgType(PERP_MSG_TYPE_URLS.MsgAddMargin, txLogs[idx].events) + assertHasEventType( + "nibiru.perp.v1.PositionChangedEvent", + txLogs[idx].events + ) + assertHasEventType("transfer", txLogs[idx].events) + } + + try { + const result = await signingClient.signAndBroadcast(sender, msgs, fee) + + assertIsDeliverTxSuccess(result) + assertHappyPath(result) + } catch (error) { + const okErrors: string[] = [ERR.collections, ERR.noPrices, ERR.sequence] + + let err = error as any + if (err.rawLog) { + err = err.rawLog + } + assertExpectedError(err, okErrors) + } + }, 40_000 /* default timeout is not sufficient. */) + + test("nibid query perp positions", async () => { + const queryClient = await NibiruQueryClient.connect(TEST_CHAIN.endptTm) + const resp = await queryClient.nibiruExtensions.perp.positions({ + trader: TEST_ADDRESS, + }) + resp.positions.forEach((position) => { + const fields = [ + position.position, + position.unrealizedPnl, + position.positionNotional, + ] + fields.forEach((val) => expect(val).toBeDefined()) + }) + }) + + test("nibid tx perp close-position", async () => { + const signer = await newSignerFromMnemonic(TEST_MNEMONIC) + const signingClient = await NibiruSigningClient.connectWithSigner( + TEST_CHAIN.endptTm, + signer + ) + const [{ address: sender }] = await signer.getAccounts() + + const fee = { + amount: coins(12_500, "unibi"), + gas: "500000", + } + + const msgs: TxMessage[] = [ + { + typeUrl: PERP_MSG_TYPE_URLS.MsgClosePosition, + value: MsgClosePosition.fromPartial({ + pair, + sender, + }), + }, + ] + + const assertHappyPath = (result: DeliverTxResponse) => { + const txLogs: TxLog[] = JSON.parse(result.rawLog!) + expect(txLogs).toHaveLength(1) + + // perp tx close-position events + assertHasMsgType(PERP_MSG_TYPE_URLS.MsgClosePosition, txLogs[0].events) + assertHasEventType( + "nibiru.perp.v1.PositionChangedEvent", + txLogs[0].events + ) + assertHasEventType("transfer", txLogs[0].events) + } + + try { + const result = await signingClient.signAndBroadcast(sender, msgs, fee) + assertIsDeliverTxSuccess(result) + assertHappyPath(result) + } catch (error) { + const okErrors: string[] = [ERR.collections, ERR.sequence] + + let err = error as any + if (err.rawLog) { + err = err.rawLog + } + assertExpectedError(err, okErrors) + } + }) +}) diff --git a/packages/nibijs/src/tx/signingClient.ts b/packages/nibijs/src/tx/signingClient.ts index 901ffd4c..ae51c081 100644 --- a/packages/nibijs/src/tx/signingClient.ts +++ b/packages/nibijs/src/tx/signingClient.ts @@ -17,21 +17,21 @@ import { SigningCosmWasmClientOptions, setupWasmExtension, } from "@cosmjs/cosmwasm-stargate" -// import { perpTypes, spotTypes } from "../msg" +import { perpTypes, spotTypes } from "../msg" import { setupInflationExtension, setupSudoExtension, - // setupSpotExtension, + setupSpotExtension, NibiruExtensions, - // setupPerpExtension, + setupPerpExtension, setupOracleExtension, setupEpochsExtension, } from "../query" export const nibiruRegistryTypes: ReadonlyArray<[string, GeneratedType]> = [ ...defaultRegistryTypes, - // ...perpTypes, - // ...spotTypes, + ...perpTypes, + ...spotTypes, ] export class NibiruSigningClient extends SigningStargateClient { @@ -50,8 +50,8 @@ export class NibiruSigningClient extends SigningStargateClient { tmClient, setupEpochsExtension, setupOracleExtension, - // setupPerpExtension, - // setupSpotExtension, + setupPerpExtension, + setupSpotExtension, setupSudoExtension, setupInflationExtension, setupDistributionExtension, diff --git a/packages/protojs/src/cosmos/bank/v1beta1/bank.ts b/packages/protojs/src/cosmos/bank/v1beta1/bank.ts deleted file mode 100644 index b6989298..00000000 --- a/packages/protojs/src/cosmos/bank/v1beta1/bank.ts +++ /dev/null @@ -1,811 +0,0 @@ -/* eslint-disable */ -import Long from "long" -import _m0 from "protobufjs/minimal" -import { Coin } from "../../base/v1beta1/coin" - -export const protobufPackage = "cosmos.bank.v1beta1" - -/** Params defines the parameters for the bank module. */ -export interface Params { - /** - * Deprecated: Use of SendEnabled in params is deprecated. - * For genesis, use the newly added send_enabled field in the genesis object. - * Storage, lookup, and manipulation of this information is now in the keeper. - * - * As of cosmos-sdk 0.47, this only exists for backwards compatibility of genesis files. - * - * @deprecated - */ - sendEnabled: SendEnabled[] - defaultSendEnabled: boolean -} - -/** - * SendEnabled maps coin denom to a send_enabled status (whether a denom is - * sendable). - */ -export interface SendEnabled { - denom: string - enabled: boolean -} - -/** Input models transaction input. */ -export interface Input { - address: string - coins: Coin[] -} - -/** Output models transaction outputs. */ -export interface Output { - address: string - coins: Coin[] -} - -/** - * Supply represents a struct that passively keeps track of the total supply - * amounts in the network. - * This message is deprecated now that supply is indexed by denom. - * - * @deprecated - */ -export interface Supply { - total: Coin[] -} - -/** - * DenomUnit represents a struct that describes a given - * denomination unit of the basic token. - */ -export interface DenomUnit { - /** denom represents the string name of the given denom unit (e.g uatom). */ - denom: string - /** - * exponent represents power of 10 exponent that one must - * raise the base_denom to in order to equal the given DenomUnit's denom - * 1 denom = 10^exponent base_denom - * (e.g. with a base_denom of uatom, one can create a DenomUnit of 'atom' with - * exponent = 6, thus: 1 atom = 10^6 uatom). - */ - exponent: number - /** aliases is a list of string aliases for the given denom */ - aliases: string[] -} - -/** - * Metadata represents a struct that describes - * a basic token. - */ -export interface Metadata { - description: string - /** denom_units represents the list of DenomUnit's for a given coin */ - denomUnits: DenomUnit[] - /** base represents the base denom (should be the DenomUnit with exponent = 0). */ - base: string - /** - * display indicates the suggested denom that should be - * displayed in clients. - */ - display: string - /** - * name defines the name of the token (eg: Cosmos Atom) - * - * Since: cosmos-sdk 0.43 - */ - name: string - /** - * symbol is the token symbol usually shown on exchanges (eg: ATOM). This can - * be the same as the display. - * - * Since: cosmos-sdk 0.43 - */ - symbol: string - /** - * URI to a document (on or off-chain) that contains additional information. Optional. - * - * Since: cosmos-sdk 0.46 - */ - uri: string - /** - * URIHash is a sha256 hash of a document pointed by URI. It's used to verify that - * the document didn't change. Optional. - * - * Since: cosmos-sdk 0.46 - */ - uriHash: string -} - -function createBaseParams(): Params { - return { sendEnabled: [], defaultSendEnabled: false } -} - -export const Params = { - encode( - message: Params, - writer: _m0.Writer = _m0.Writer.create() - ): _m0.Writer { - for (const v of message.sendEnabled) { - SendEnabled.encode(v!, writer.uint32(10).fork()).ldelim() - } - if (message.defaultSendEnabled === true) { - writer.uint32(16).bool(message.defaultSendEnabled) - } - return writer - }, - - decode(input: _m0.Reader | Uint8Array, length?: number): Params { - const reader = - input instanceof _m0.Reader ? input : _m0.Reader.create(input) - let end = length === undefined ? reader.len : reader.pos + length - const message = createBaseParams() - while (reader.pos < end) { - const tag = reader.uint32() - switch (tag >>> 3) { - case 1: - if (tag !== 10) { - break - } - - message.sendEnabled.push(SendEnabled.decode(reader, reader.uint32())) - continue - case 2: - if (tag !== 16) { - break - } - - message.defaultSendEnabled = reader.bool() - continue - } - if ((tag & 7) === 4 || tag === 0) { - break - } - reader.skipType(tag & 7) - } - return message - }, - - fromJSON(object: any): Params { - return { - sendEnabled: Array.isArray(object?.sendEnabled) - ? object.sendEnabled.map((e: any) => SendEnabled.fromJSON(e)) - : [], - defaultSendEnabled: isSet(object.defaultSendEnabled) - ? Boolean(object.defaultSendEnabled) - : false, - } - }, - - toJSON(message: Params): unknown { - const obj: any = {} - if (message.sendEnabled) { - obj.sendEnabled = message.sendEnabled.map((e) => - e ? SendEnabled.toJSON(e) : undefined - ) - } else { - obj.sendEnabled = [] - } - message.defaultSendEnabled !== undefined && - (obj.defaultSendEnabled = message.defaultSendEnabled) - return obj - }, - - create, I>>(base?: I): Params { - return Params.fromPartial(base ?? {}) - }, - - fromPartial, I>>(object: I): Params { - const message = createBaseParams() - message.sendEnabled = - object.sendEnabled?.map((e) => SendEnabled.fromPartial(e)) || [] - message.defaultSendEnabled = object.defaultSendEnabled ?? false - return message - }, -} - -function createBaseSendEnabled(): SendEnabled { - return { denom: "", enabled: false } -} - -export const SendEnabled = { - encode( - message: SendEnabled, - writer: _m0.Writer = _m0.Writer.create() - ): _m0.Writer { - if (message.denom !== "") { - writer.uint32(10).string(message.denom) - } - if (message.enabled === true) { - writer.uint32(16).bool(message.enabled) - } - return writer - }, - - decode(input: _m0.Reader | Uint8Array, length?: number): SendEnabled { - const reader = - input instanceof _m0.Reader ? input : _m0.Reader.create(input) - let end = length === undefined ? reader.len : reader.pos + length - const message = createBaseSendEnabled() - while (reader.pos < end) { - const tag = reader.uint32() - switch (tag >>> 3) { - case 1: - if (tag !== 10) { - break - } - - message.denom = reader.string() - continue - case 2: - if (tag !== 16) { - break - } - - message.enabled = reader.bool() - continue - } - if ((tag & 7) === 4 || tag === 0) { - break - } - reader.skipType(tag & 7) - } - return message - }, - - fromJSON(object: any): SendEnabled { - return { - denom: isSet(object.denom) ? String(object.denom) : "", - enabled: isSet(object.enabled) ? Boolean(object.enabled) : false, - } - }, - - toJSON(message: SendEnabled): unknown { - const obj: any = {} - message.denom !== undefined && (obj.denom = message.denom) - message.enabled !== undefined && (obj.enabled = message.enabled) - return obj - }, - - create, I>>(base?: I): SendEnabled { - return SendEnabled.fromPartial(base ?? {}) - }, - - fromPartial, I>>( - object: I - ): SendEnabled { - const message = createBaseSendEnabled() - message.denom = object.denom ?? "" - message.enabled = object.enabled ?? false - return message - }, -} - -function createBaseInput(): Input { - return { address: "", coins: [] } -} - -export const Input = { - encode(message: Input, writer: _m0.Writer = _m0.Writer.create()): _m0.Writer { - if (message.address !== "") { - writer.uint32(10).string(message.address) - } - for (const v of message.coins) { - Coin.encode(v!, writer.uint32(18).fork()).ldelim() - } - return writer - }, - - decode(input: _m0.Reader | Uint8Array, length?: number): Input { - const reader = - input instanceof _m0.Reader ? input : _m0.Reader.create(input) - let end = length === undefined ? reader.len : reader.pos + length - const message = createBaseInput() - while (reader.pos < end) { - const tag = reader.uint32() - switch (tag >>> 3) { - case 1: - if (tag !== 10) { - break - } - - message.address = reader.string() - continue - case 2: - if (tag !== 18) { - break - } - - message.coins.push(Coin.decode(reader, reader.uint32())) - continue - } - if ((tag & 7) === 4 || tag === 0) { - break - } - reader.skipType(tag & 7) - } - return message - }, - - fromJSON(object: any): Input { - return { - address: isSet(object.address) ? String(object.address) : "", - coins: Array.isArray(object?.coins) - ? object.coins.map((e: any) => Coin.fromJSON(e)) - : [], - } - }, - - toJSON(message: Input): unknown { - const obj: any = {} - message.address !== undefined && (obj.address = message.address) - if (message.coins) { - obj.coins = message.coins.map((e) => (e ? Coin.toJSON(e) : undefined)) - } else { - obj.coins = [] - } - return obj - }, - - create, I>>(base?: I): Input { - return Input.fromPartial(base ?? {}) - }, - - fromPartial, I>>(object: I): Input { - const message = createBaseInput() - message.address = object.address ?? "" - message.coins = object.coins?.map((e) => Coin.fromPartial(e)) || [] - return message - }, -} - -function createBaseOutput(): Output { - return { address: "", coins: [] } -} - -export const Output = { - encode( - message: Output, - writer: _m0.Writer = _m0.Writer.create() - ): _m0.Writer { - if (message.address !== "") { - writer.uint32(10).string(message.address) - } - for (const v of message.coins) { - Coin.encode(v!, writer.uint32(18).fork()).ldelim() - } - return writer - }, - - decode(input: _m0.Reader | Uint8Array, length?: number): Output { - const reader = - input instanceof _m0.Reader ? input : _m0.Reader.create(input) - let end = length === undefined ? reader.len : reader.pos + length - const message = createBaseOutput() - while (reader.pos < end) { - const tag = reader.uint32() - switch (tag >>> 3) { - case 1: - if (tag !== 10) { - break - } - - message.address = reader.string() - continue - case 2: - if (tag !== 18) { - break - } - - message.coins.push(Coin.decode(reader, reader.uint32())) - continue - } - if ((tag & 7) === 4 || tag === 0) { - break - } - reader.skipType(tag & 7) - } - return message - }, - - fromJSON(object: any): Output { - return { - address: isSet(object.address) ? String(object.address) : "", - coins: Array.isArray(object?.coins) - ? object.coins.map((e: any) => Coin.fromJSON(e)) - : [], - } - }, - - toJSON(message: Output): unknown { - const obj: any = {} - message.address !== undefined && (obj.address = message.address) - if (message.coins) { - obj.coins = message.coins.map((e) => (e ? Coin.toJSON(e) : undefined)) - } else { - obj.coins = [] - } - return obj - }, - - create, I>>(base?: I): Output { - return Output.fromPartial(base ?? {}) - }, - - fromPartial, I>>(object: I): Output { - const message = createBaseOutput() - message.address = object.address ?? "" - message.coins = object.coins?.map((e) => Coin.fromPartial(e)) || [] - return message - }, -} - -function createBaseSupply(): Supply { - return { total: [] } -} - -export const Supply = { - encode( - message: Supply, - writer: _m0.Writer = _m0.Writer.create() - ): _m0.Writer { - for (const v of message.total) { - Coin.encode(v!, writer.uint32(10).fork()).ldelim() - } - return writer - }, - - decode(input: _m0.Reader | Uint8Array, length?: number): Supply { - const reader = - input instanceof _m0.Reader ? input : _m0.Reader.create(input) - let end = length === undefined ? reader.len : reader.pos + length - const message = createBaseSupply() - while (reader.pos < end) { - const tag = reader.uint32() - switch (tag >>> 3) { - case 1: - if (tag !== 10) { - break - } - - message.total.push(Coin.decode(reader, reader.uint32())) - continue - } - if ((tag & 7) === 4 || tag === 0) { - break - } - reader.skipType(tag & 7) - } - return message - }, - - fromJSON(object: any): Supply { - return { - total: Array.isArray(object?.total) - ? object.total.map((e: any) => Coin.fromJSON(e)) - : [], - } - }, - - toJSON(message: Supply): unknown { - const obj: any = {} - if (message.total) { - obj.total = message.total.map((e) => (e ? Coin.toJSON(e) : undefined)) - } else { - obj.total = [] - } - return obj - }, - - create, I>>(base?: I): Supply { - return Supply.fromPartial(base ?? {}) - }, - - fromPartial, I>>(object: I): Supply { - const message = createBaseSupply() - message.total = object.total?.map((e) => Coin.fromPartial(e)) || [] - return message - }, -} - -function createBaseDenomUnit(): DenomUnit { - return { denom: "", exponent: 0, aliases: [] } -} - -export const DenomUnit = { - encode( - message: DenomUnit, - writer: _m0.Writer = _m0.Writer.create() - ): _m0.Writer { - if (message.denom !== "") { - writer.uint32(10).string(message.denom) - } - if (message.exponent !== 0) { - writer.uint32(16).uint32(message.exponent) - } - for (const v of message.aliases) { - writer.uint32(26).string(v!) - } - return writer - }, - - decode(input: _m0.Reader | Uint8Array, length?: number): DenomUnit { - const reader = - input instanceof _m0.Reader ? input : _m0.Reader.create(input) - let end = length === undefined ? reader.len : reader.pos + length - const message = createBaseDenomUnit() - while (reader.pos < end) { - const tag = reader.uint32() - switch (tag >>> 3) { - case 1: - if (tag !== 10) { - break - } - - message.denom = reader.string() - continue - case 2: - if (tag !== 16) { - break - } - - message.exponent = reader.uint32() - continue - case 3: - if (tag !== 26) { - break - } - - message.aliases.push(reader.string()) - continue - } - if ((tag & 7) === 4 || tag === 0) { - break - } - reader.skipType(tag & 7) - } - return message - }, - - fromJSON(object: any): DenomUnit { - return { - denom: isSet(object.denom) ? String(object.denom) : "", - exponent: isSet(object.exponent) ? Number(object.exponent) : 0, - aliases: Array.isArray(object?.aliases) - ? object.aliases.map((e: any) => String(e)) - : [], - } - }, - - toJSON(message: DenomUnit): unknown { - const obj: any = {} - message.denom !== undefined && (obj.denom = message.denom) - message.exponent !== undefined && - (obj.exponent = Math.round(message.exponent)) - if (message.aliases) { - obj.aliases = message.aliases.map((e) => e) - } else { - obj.aliases = [] - } - return obj - }, - - create, I>>(base?: I): DenomUnit { - return DenomUnit.fromPartial(base ?? {}) - }, - - fromPartial, I>>( - object: I - ): DenomUnit { - const message = createBaseDenomUnit() - message.denom = object.denom ?? "" - message.exponent = object.exponent ?? 0 - message.aliases = object.aliases?.map((e) => e) || [] - return message - }, -} - -function createBaseMetadata(): Metadata { - return { - description: "", - denomUnits: [], - base: "", - display: "", - name: "", - symbol: "", - uri: "", - uriHash: "", - } -} - -export const Metadata = { - encode( - message: Metadata, - writer: _m0.Writer = _m0.Writer.create() - ): _m0.Writer { - if (message.description !== "") { - writer.uint32(10).string(message.description) - } - for (const v of message.denomUnits) { - DenomUnit.encode(v!, writer.uint32(18).fork()).ldelim() - } - if (message.base !== "") { - writer.uint32(26).string(message.base) - } - if (message.display !== "") { - writer.uint32(34).string(message.display) - } - if (message.name !== "") { - writer.uint32(42).string(message.name) - } - if (message.symbol !== "") { - writer.uint32(50).string(message.symbol) - } - if (message.uri !== "") { - writer.uint32(58).string(message.uri) - } - if (message.uriHash !== "") { - writer.uint32(66).string(message.uriHash) - } - return writer - }, - - decode(input: _m0.Reader | Uint8Array, length?: number): Metadata { - const reader = - input instanceof _m0.Reader ? input : _m0.Reader.create(input) - let end = length === undefined ? reader.len : reader.pos + length - const message = createBaseMetadata() - while (reader.pos < end) { - const tag = reader.uint32() - switch (tag >>> 3) { - case 1: - if (tag !== 10) { - break - } - - message.description = reader.string() - continue - case 2: - if (tag !== 18) { - break - } - - message.denomUnits.push(DenomUnit.decode(reader, reader.uint32())) - continue - case 3: - if (tag !== 26) { - break - } - - message.base = reader.string() - continue - case 4: - if (tag !== 34) { - break - } - - message.display = reader.string() - continue - case 5: - if (tag !== 42) { - break - } - - message.name = reader.string() - continue - case 6: - if (tag !== 50) { - break - } - - message.symbol = reader.string() - continue - case 7: - if (tag !== 58) { - break - } - - message.uri = reader.string() - continue - case 8: - if (tag !== 66) { - break - } - - message.uriHash = reader.string() - continue - } - if ((tag & 7) === 4 || tag === 0) { - break - } - reader.skipType(tag & 7) - } - return message - }, - - fromJSON(object: any): Metadata { - return { - description: isSet(object.description) ? String(object.description) : "", - denomUnits: Array.isArray(object?.denomUnits) - ? object.denomUnits.map((e: any) => DenomUnit.fromJSON(e)) - : [], - base: isSet(object.base) ? String(object.base) : "", - display: isSet(object.display) ? String(object.display) : "", - name: isSet(object.name) ? String(object.name) : "", - symbol: isSet(object.symbol) ? String(object.symbol) : "", - uri: isSet(object.uri) ? String(object.uri) : "", - uriHash: isSet(object.uriHash) ? String(object.uriHash) : "", - } - }, - - toJSON(message: Metadata): unknown { - const obj: any = {} - message.description !== undefined && (obj.description = message.description) - if (message.denomUnits) { - obj.denomUnits = message.denomUnits.map((e) => - e ? DenomUnit.toJSON(e) : undefined - ) - } else { - obj.denomUnits = [] - } - message.base !== undefined && (obj.base = message.base) - message.display !== undefined && (obj.display = message.display) - message.name !== undefined && (obj.name = message.name) - message.symbol !== undefined && (obj.symbol = message.symbol) - message.uri !== undefined && (obj.uri = message.uri) - message.uriHash !== undefined && (obj.uriHash = message.uriHash) - return obj - }, - - create, I>>(base?: I): Metadata { - return Metadata.fromPartial(base ?? {}) - }, - - fromPartial, I>>(object: I): Metadata { - const message = createBaseMetadata() - message.description = object.description ?? "" - message.denomUnits = - object.denomUnits?.map((e) => DenomUnit.fromPartial(e)) || [] - message.base = object.base ?? "" - message.display = object.display ?? "" - message.name = object.name ?? "" - message.symbol = object.symbol ?? "" - message.uri = object.uri ?? "" - message.uriHash = object.uriHash ?? "" - return message - }, -} - -type Builtin = - | Date - | Function - | Uint8Array - | string - | number - | boolean - | undefined - -export type DeepPartial = T extends Builtin - ? T - : T extends Long - ? string | number | Long - : T extends Array - ? Array> - : T extends ReadonlyArray - ? ReadonlyArray> - : T extends {} - ? { [K in keyof T]?: DeepPartial } - : Partial - -type KeysOfUnion = T extends T ? keyof T : never -export type Exact = P extends Builtin - ? P - : P & { [K in keyof P]: Exact } & { - [K in Exclude>]: never - } - -if (_m0.util.Long !== Long) { - _m0.util.Long = Long as any - _m0.configure() -} - -function isSet(value: any): boolean { - return value !== null && value !== undefined -} diff --git a/packages/protojs/src/cosmos/msg/v1/msg.ts b/packages/protojs/src/cosmos/msg/v1/msg.ts deleted file mode 100644 index 8bcdfbb6..00000000 --- a/packages/protojs/src/cosmos/msg/v1/msg.ts +++ /dev/null @@ -1,3 +0,0 @@ -/* eslint-disable */ - -export const protobufPackage = "cosmos.msg.v1" diff --git a/packages/protojs/src/nibiru/devgas/v1/devgas.ts b/packages/protojs/src/nibiru/devgas/v1/devgas.ts deleted file mode 100644 index a64cc7ba..00000000 --- a/packages/protojs/src/nibiru/devgas/v1/devgas.ts +++ /dev/null @@ -1,161 +0,0 @@ -/* eslint-disable */ -import Long from "long" -import _m0 from "protobufjs/minimal" - -export const protobufPackage = "nibiru.devgas.v1" - -/** - * FeeShare defines an instance that organizes fee distribution conditions for - * the owner of a given smart contract - */ -export interface FeeShare { - /** - * contract_address is the bech32 address of a registered contract in string - * form - */ - contractAddress: string - /** - * deployer_address is the bech32 address of message sender. It must be the - * same as the contracts admin address. - */ - deployerAddress: string - /** - * withdrawer_address is the bech32 address of account receiving the - * transaction fees. - */ - withdrawerAddress: string -} - -function createBaseFeeShare(): FeeShare { - return { contractAddress: "", deployerAddress: "", withdrawerAddress: "" } -} - -export const FeeShare = { - encode( - message: FeeShare, - writer: _m0.Writer = _m0.Writer.create() - ): _m0.Writer { - if (message.contractAddress !== "") { - writer.uint32(10).string(message.contractAddress) - } - if (message.deployerAddress !== "") { - writer.uint32(18).string(message.deployerAddress) - } - if (message.withdrawerAddress !== "") { - writer.uint32(26).string(message.withdrawerAddress) - } - return writer - }, - - decode(input: _m0.Reader | Uint8Array, length?: number): FeeShare { - const reader = - input instanceof _m0.Reader ? input : _m0.Reader.create(input) - let end = length === undefined ? reader.len : reader.pos + length - const message = createBaseFeeShare() - while (reader.pos < end) { - const tag = reader.uint32() - switch (tag >>> 3) { - case 1: - if (tag !== 10) { - break - } - - message.contractAddress = reader.string() - continue - case 2: - if (tag !== 18) { - break - } - - message.deployerAddress = reader.string() - continue - case 3: - if (tag !== 26) { - break - } - - message.withdrawerAddress = reader.string() - continue - } - if ((tag & 7) === 4 || tag === 0) { - break - } - reader.skipType(tag & 7) - } - return message - }, - - fromJSON(object: any): FeeShare { - return { - contractAddress: isSet(object.contractAddress) - ? String(object.contractAddress) - : "", - deployerAddress: isSet(object.deployerAddress) - ? String(object.deployerAddress) - : "", - withdrawerAddress: isSet(object.withdrawerAddress) - ? String(object.withdrawerAddress) - : "", - } - }, - - toJSON(message: FeeShare): unknown { - const obj: any = {} - message.contractAddress !== undefined && - (obj.contractAddress = message.contractAddress) - message.deployerAddress !== undefined && - (obj.deployerAddress = message.deployerAddress) - message.withdrawerAddress !== undefined && - (obj.withdrawerAddress = message.withdrawerAddress) - return obj - }, - - create, I>>(base?: I): FeeShare { - return FeeShare.fromPartial(base ?? {}) - }, - - fromPartial, I>>(object: I): FeeShare { - const message = createBaseFeeShare() - message.contractAddress = object.contractAddress ?? "" - message.deployerAddress = object.deployerAddress ?? "" - message.withdrawerAddress = object.withdrawerAddress ?? "" - return message - }, -} - -type Builtin = - | Date - | Function - | Uint8Array - | string - | number - | boolean - | undefined - -export type DeepPartial = T extends Builtin - ? T - : T extends Long - ? string | number | Long - : T extends Array - ? Array> - : T extends ReadonlyArray - ? ReadonlyArray> - : T extends {} - ? { [K in keyof T]?: DeepPartial } - : Partial - -type KeysOfUnion = T extends T ? keyof T : never -export type Exact = P extends Builtin - ? P - : P & { [K in keyof P]: Exact } & { - [K in Exclude>]: never - } - -if (_m0.util.Long !== Long) { - _m0.util.Long = Long as any - _m0.configure() -} - -function isSet(value: any): boolean { - return value !== null && value !== undefined -} diff --git a/packages/protojs/src/nibiru/devgas/v1/event.ts b/packages/protojs/src/nibiru/devgas/v1/event.ts deleted file mode 100644 index a4e7ca8e..00000000 --- a/packages/protojs/src/nibiru/devgas/v1/event.ts +++ /dev/null @@ -1,440 +0,0 @@ -/* eslint-disable */ -import Long from "long" -import _m0 from "protobufjs/minimal" - -export const protobufPackage = "nibiru.devgas.v1" - -/** - * ABCI event emitted when a deployer registers a contract to receive fee - * sharing payouts, specifying the deployer, contract, and withdrawer addresses. - */ -export interface EventRegisterDevGas { - /** - * deployer is the addess of the account that registered the smart contract to - * receive dev gas royalties. - */ - deployer: string - /** - * Address of the smart contract. This identifies the specific contract - * that will receive fee sharing payouts. - */ - contract: string - /** - * The address that will receive the fee sharing payouts for the registered - * contract. This could be the deployer address or a separate withdrawer - * address specified. - */ - withdrawer: string -} - -/** - * ABCI event emitted when a deployer cancels fee sharing for a contract, - * specifying the deployer and contract addresses. - */ -export interface EventCancelDevGas { - /** - * deployer is the addess of the account that registered the smart contract to - * receive dev gas royalties. - */ - deployer: string - /** - * Address of the smart contract. This identifies the specific contract - * that will receive fee sharing payouts. - */ - contract: string -} - -/** - * ABCI event emitted when a deployer updates the fee sharing registration for a - * contract, specifying updated deployer, contract, and/or withdrawer addresses. - */ -export interface EventUpdateDevGas { - /** - * deployer is the addess of the account that registered the smart contract to - * receive dev gas royalties. - */ - deployer: string - /** - * Address of the smart contract. This identifies the specific contract - * that will receive fee sharing payouts. - */ - contract: string - /** - * The address that will receive the fee sharing payouts for the registered - * contract. This could be the deployer address or a separate withdrawer - * address specified. - */ - withdrawer: string -} - -/** - * ABCI event emitted when fee sharing payouts are made, containing details on - * the payouts in JSON format. - */ -export interface EventPayoutDevGas { - payouts: string -} - -function createBaseEventRegisterDevGas(): EventRegisterDevGas { - return { deployer: "", contract: "", withdrawer: "" } -} - -export const EventRegisterDevGas = { - encode( - message: EventRegisterDevGas, - writer: _m0.Writer = _m0.Writer.create() - ): _m0.Writer { - if (message.deployer !== "") { - writer.uint32(10).string(message.deployer) - } - if (message.contract !== "") { - writer.uint32(18).string(message.contract) - } - if (message.withdrawer !== "") { - writer.uint32(26).string(message.withdrawer) - } - return writer - }, - - decode(input: _m0.Reader | Uint8Array, length?: number): EventRegisterDevGas { - const reader = - input instanceof _m0.Reader ? input : _m0.Reader.create(input) - let end = length === undefined ? reader.len : reader.pos + length - const message = createBaseEventRegisterDevGas() - while (reader.pos < end) { - const tag = reader.uint32() - switch (tag >>> 3) { - case 1: - if (tag !== 10) { - break - } - - message.deployer = reader.string() - continue - case 2: - if (tag !== 18) { - break - } - - message.contract = reader.string() - continue - case 3: - if (tag !== 26) { - break - } - - message.withdrawer = reader.string() - continue - } - if ((tag & 7) === 4 || tag === 0) { - break - } - reader.skipType(tag & 7) - } - return message - }, - - fromJSON(object: any): EventRegisterDevGas { - return { - deployer: isSet(object.deployer) ? String(object.deployer) : "", - contract: isSet(object.contract) ? String(object.contract) : "", - withdrawer: isSet(object.withdrawer) ? String(object.withdrawer) : "", - } - }, - - toJSON(message: EventRegisterDevGas): unknown { - const obj: any = {} - message.deployer !== undefined && (obj.deployer = message.deployer) - message.contract !== undefined && (obj.contract = message.contract) - message.withdrawer !== undefined && (obj.withdrawer = message.withdrawer) - return obj - }, - - create, I>>( - base?: I - ): EventRegisterDevGas { - return EventRegisterDevGas.fromPartial(base ?? {}) - }, - - fromPartial, I>>( - object: I - ): EventRegisterDevGas { - const message = createBaseEventRegisterDevGas() - message.deployer = object.deployer ?? "" - message.contract = object.contract ?? "" - message.withdrawer = object.withdrawer ?? "" - return message - }, -} - -function createBaseEventCancelDevGas(): EventCancelDevGas { - return { deployer: "", contract: "" } -} - -export const EventCancelDevGas = { - encode( - message: EventCancelDevGas, - writer: _m0.Writer = _m0.Writer.create() - ): _m0.Writer { - if (message.deployer !== "") { - writer.uint32(10).string(message.deployer) - } - if (message.contract !== "") { - writer.uint32(18).string(message.contract) - } - return writer - }, - - decode(input: _m0.Reader | Uint8Array, length?: number): EventCancelDevGas { - const reader = - input instanceof _m0.Reader ? input : _m0.Reader.create(input) - let end = length === undefined ? reader.len : reader.pos + length - const message = createBaseEventCancelDevGas() - while (reader.pos < end) { - const tag = reader.uint32() - switch (tag >>> 3) { - case 1: - if (tag !== 10) { - break - } - - message.deployer = reader.string() - continue - case 2: - if (tag !== 18) { - break - } - - message.contract = reader.string() - continue - } - if ((tag & 7) === 4 || tag === 0) { - break - } - reader.skipType(tag & 7) - } - return message - }, - - fromJSON(object: any): EventCancelDevGas { - return { - deployer: isSet(object.deployer) ? String(object.deployer) : "", - contract: isSet(object.contract) ? String(object.contract) : "", - } - }, - - toJSON(message: EventCancelDevGas): unknown { - const obj: any = {} - message.deployer !== undefined && (obj.deployer = message.deployer) - message.contract !== undefined && (obj.contract = message.contract) - return obj - }, - - create, I>>( - base?: I - ): EventCancelDevGas { - return EventCancelDevGas.fromPartial(base ?? {}) - }, - - fromPartial, I>>( - object: I - ): EventCancelDevGas { - const message = createBaseEventCancelDevGas() - message.deployer = object.deployer ?? "" - message.contract = object.contract ?? "" - return message - }, -} - -function createBaseEventUpdateDevGas(): EventUpdateDevGas { - return { deployer: "", contract: "", withdrawer: "" } -} - -export const EventUpdateDevGas = { - encode( - message: EventUpdateDevGas, - writer: _m0.Writer = _m0.Writer.create() - ): _m0.Writer { - if (message.deployer !== "") { - writer.uint32(10).string(message.deployer) - } - if (message.contract !== "") { - writer.uint32(18).string(message.contract) - } - if (message.withdrawer !== "") { - writer.uint32(26).string(message.withdrawer) - } - return writer - }, - - decode(input: _m0.Reader | Uint8Array, length?: number): EventUpdateDevGas { - const reader = - input instanceof _m0.Reader ? input : _m0.Reader.create(input) - let end = length === undefined ? reader.len : reader.pos + length - const message = createBaseEventUpdateDevGas() - while (reader.pos < end) { - const tag = reader.uint32() - switch (tag >>> 3) { - case 1: - if (tag !== 10) { - break - } - - message.deployer = reader.string() - continue - case 2: - if (tag !== 18) { - break - } - - message.contract = reader.string() - continue - case 3: - if (tag !== 26) { - break - } - - message.withdrawer = reader.string() - continue - } - if ((tag & 7) === 4 || tag === 0) { - break - } - reader.skipType(tag & 7) - } - return message - }, - - fromJSON(object: any): EventUpdateDevGas { - return { - deployer: isSet(object.deployer) ? String(object.deployer) : "", - contract: isSet(object.contract) ? String(object.contract) : "", - withdrawer: isSet(object.withdrawer) ? String(object.withdrawer) : "", - } - }, - - toJSON(message: EventUpdateDevGas): unknown { - const obj: any = {} - message.deployer !== undefined && (obj.deployer = message.deployer) - message.contract !== undefined && (obj.contract = message.contract) - message.withdrawer !== undefined && (obj.withdrawer = message.withdrawer) - return obj - }, - - create, I>>( - base?: I - ): EventUpdateDevGas { - return EventUpdateDevGas.fromPartial(base ?? {}) - }, - - fromPartial, I>>( - object: I - ): EventUpdateDevGas { - const message = createBaseEventUpdateDevGas() - message.deployer = object.deployer ?? "" - message.contract = object.contract ?? "" - message.withdrawer = object.withdrawer ?? "" - return message - }, -} - -function createBaseEventPayoutDevGas(): EventPayoutDevGas { - return { payouts: "" } -} - -export const EventPayoutDevGas = { - encode( - message: EventPayoutDevGas, - writer: _m0.Writer = _m0.Writer.create() - ): _m0.Writer { - if (message.payouts !== "") { - writer.uint32(10).string(message.payouts) - } - return writer - }, - - decode(input: _m0.Reader | Uint8Array, length?: number): EventPayoutDevGas { - const reader = - input instanceof _m0.Reader ? input : _m0.Reader.create(input) - let end = length === undefined ? reader.len : reader.pos + length - const message = createBaseEventPayoutDevGas() - while (reader.pos < end) { - const tag = reader.uint32() - switch (tag >>> 3) { - case 1: - if (tag !== 10) { - break - } - - message.payouts = reader.string() - continue - } - if ((tag & 7) === 4 || tag === 0) { - break - } - reader.skipType(tag & 7) - } - return message - }, - - fromJSON(object: any): EventPayoutDevGas { - return { payouts: isSet(object.payouts) ? String(object.payouts) : "" } - }, - - toJSON(message: EventPayoutDevGas): unknown { - const obj: any = {} - message.payouts !== undefined && (obj.payouts = message.payouts) - return obj - }, - - create, I>>( - base?: I - ): EventPayoutDevGas { - return EventPayoutDevGas.fromPartial(base ?? {}) - }, - - fromPartial, I>>( - object: I - ): EventPayoutDevGas { - const message = createBaseEventPayoutDevGas() - message.payouts = object.payouts ?? "" - return message - }, -} - -type Builtin = - | Date - | Function - | Uint8Array - | string - | number - | boolean - | undefined - -export type DeepPartial = T extends Builtin - ? T - : T extends Long - ? string | number | Long - : T extends Array - ? Array> - : T extends ReadonlyArray - ? ReadonlyArray> - : T extends {} - ? { [K in keyof T]?: DeepPartial } - : Partial - -type KeysOfUnion = T extends T ? keyof T : never -export type Exact = P extends Builtin - ? P - : P & { [K in keyof P]: Exact } & { - [K in Exclude>]: never - } - -if (_m0.util.Long !== Long) { - _m0.util.Long = Long as any - _m0.configure() -} - -function isSet(value: any): boolean { - return value !== null && value !== undefined -} diff --git a/packages/protojs/src/nibiru/devgas/v1/genesis.ts b/packages/protojs/src/nibiru/devgas/v1/genesis.ts deleted file mode 100644 index e6ba3b66..00000000 --- a/packages/protojs/src/nibiru/devgas/v1/genesis.ts +++ /dev/null @@ -1,269 +0,0 @@ -/* eslint-disable */ -import Long from "long" -import _m0 from "protobufjs/minimal" -import { FeeShare } from "./devgas" - -export const protobufPackage = "nibiru.devgas.v1" - -/** GenesisState defines the module's genesis state. */ -export interface GenesisState { - /** params are the feeshare module parameters */ - params?: ModuleParams - /** FeeShare is a slice of active registered contracts for fee distribution */ - feeShare: FeeShare[] -} - -/** ModuleParams defines the params for the devgas module */ -export interface ModuleParams { - /** enable_feeshare defines a parameter to enable the feeshare module */ - enableFeeShare: boolean - /** - * developer_shares defines the proportion of the transaction fees to be - * distributed to the registered contract owner - */ - developerShares: string - /** - * allowed_denoms defines the list of denoms that are allowed to be paid to - * the contract withdraw addresses. If said denom is not in the list, the fees - * will ONLY be sent to the community pool. - * If this list is empty, all denoms are allowed. - */ - allowedDenoms: string[] -} - -function createBaseGenesisState(): GenesisState { - return { params: undefined, feeShare: [] } -} - -export const GenesisState = { - encode( - message: GenesisState, - writer: _m0.Writer = _m0.Writer.create() - ): _m0.Writer { - if (message.params !== undefined) { - ModuleParams.encode(message.params, writer.uint32(10).fork()).ldelim() - } - for (const v of message.feeShare) { - FeeShare.encode(v!, writer.uint32(18).fork()).ldelim() - } - return writer - }, - - decode(input: _m0.Reader | Uint8Array, length?: number): GenesisState { - const reader = - input instanceof _m0.Reader ? input : _m0.Reader.create(input) - let end = length === undefined ? reader.len : reader.pos + length - const message = createBaseGenesisState() - while (reader.pos < end) { - const tag = reader.uint32() - switch (tag >>> 3) { - case 1: - if (tag !== 10) { - break - } - - message.params = ModuleParams.decode(reader, reader.uint32()) - continue - case 2: - if (tag !== 18) { - break - } - - message.feeShare.push(FeeShare.decode(reader, reader.uint32())) - continue - } - if ((tag & 7) === 4 || tag === 0) { - break - } - reader.skipType(tag & 7) - } - return message - }, - - fromJSON(object: any): GenesisState { - return { - params: isSet(object.params) - ? ModuleParams.fromJSON(object.params) - : undefined, - feeShare: Array.isArray(object?.feeShare) - ? object.feeShare.map((e: any) => FeeShare.fromJSON(e)) - : [], - } - }, - - toJSON(message: GenesisState): unknown { - const obj: any = {} - message.params !== undefined && - (obj.params = message.params - ? ModuleParams.toJSON(message.params) - : undefined) - if (message.feeShare) { - obj.feeShare = message.feeShare.map((e) => - e ? FeeShare.toJSON(e) : undefined - ) - } else { - obj.feeShare = [] - } - return obj - }, - - create, I>>( - base?: I - ): GenesisState { - return GenesisState.fromPartial(base ?? {}) - }, - - fromPartial, I>>( - object: I - ): GenesisState { - const message = createBaseGenesisState() - message.params = - object.params !== undefined && object.params !== null - ? ModuleParams.fromPartial(object.params) - : undefined - message.feeShare = - object.feeShare?.map((e) => FeeShare.fromPartial(e)) || [] - return message - }, -} - -function createBaseModuleParams(): ModuleParams { - return { enableFeeShare: false, developerShares: "", allowedDenoms: [] } -} - -export const ModuleParams = { - encode( - message: ModuleParams, - writer: _m0.Writer = _m0.Writer.create() - ): _m0.Writer { - if (message.enableFeeShare === true) { - writer.uint32(8).bool(message.enableFeeShare) - } - if (message.developerShares !== "") { - writer.uint32(18).string(message.developerShares) - } - for (const v of message.allowedDenoms) { - writer.uint32(26).string(v!) - } - return writer - }, - - decode(input: _m0.Reader | Uint8Array, length?: number): ModuleParams { - const reader = - input instanceof _m0.Reader ? input : _m0.Reader.create(input) - let end = length === undefined ? reader.len : reader.pos + length - const message = createBaseModuleParams() - while (reader.pos < end) { - const tag = reader.uint32() - switch (tag >>> 3) { - case 1: - if (tag !== 8) { - break - } - - message.enableFeeShare = reader.bool() - continue - case 2: - if (tag !== 18) { - break - } - - message.developerShares = reader.string() - continue - case 3: - if (tag !== 26) { - break - } - - message.allowedDenoms.push(reader.string()) - continue - } - if ((tag & 7) === 4 || tag === 0) { - break - } - reader.skipType(tag & 7) - } - return message - }, - - fromJSON(object: any): ModuleParams { - return { - enableFeeShare: isSet(object.enableFeeShare) - ? Boolean(object.enableFeeShare) - : false, - developerShares: isSet(object.developerShares) - ? String(object.developerShares) - : "", - allowedDenoms: Array.isArray(object?.allowedDenoms) - ? object.allowedDenoms.map((e: any) => String(e)) - : [], - } - }, - - toJSON(message: ModuleParams): unknown { - const obj: any = {} - message.enableFeeShare !== undefined && - (obj.enableFeeShare = message.enableFeeShare) - message.developerShares !== undefined && - (obj.developerShares = message.developerShares) - if (message.allowedDenoms) { - obj.allowedDenoms = message.allowedDenoms.map((e) => e) - } else { - obj.allowedDenoms = [] - } - return obj - }, - - create, I>>( - base?: I - ): ModuleParams { - return ModuleParams.fromPartial(base ?? {}) - }, - - fromPartial, I>>( - object: I - ): ModuleParams { - const message = createBaseModuleParams() - message.enableFeeShare = object.enableFeeShare ?? false - message.developerShares = object.developerShares ?? "" - message.allowedDenoms = object.allowedDenoms?.map((e) => e) || [] - return message - }, -} - -type Builtin = - | Date - | Function - | Uint8Array - | string - | number - | boolean - | undefined - -export type DeepPartial = T extends Builtin - ? T - : T extends Long - ? string | number | Long - : T extends Array - ? Array> - : T extends ReadonlyArray - ? ReadonlyArray> - : T extends {} - ? { [K in keyof T]?: DeepPartial } - : Partial - -type KeysOfUnion = T extends T ? keyof T : never -export type Exact = P extends Builtin - ? P - : P & { [K in keyof P]: Exact } & { - [K in Exclude>]: never - } - -if (_m0.util.Long !== Long) { - _m0.util.Long = Long as any - _m0.configure() -} - -function isSet(value: any): boolean { - return value !== null && value !== undefined -} diff --git a/packages/protojs/src/nibiru/devgas/v1/query.ts b/packages/protojs/src/nibiru/devgas/v1/query.ts deleted file mode 100644 index bd698e20..00000000 --- a/packages/protojs/src/nibiru/devgas/v1/query.ts +++ /dev/null @@ -1,749 +0,0 @@ -/* eslint-disable */ -import Long from "long" -import _m0 from "protobufjs/minimal" -import { FeeShare } from "./devgas" -import { ModuleParams } from "./genesis" - -export const protobufPackage = "nibiru.devgas.v1" - -/** QueryFeeSharesRequest is the request type for the Query/FeeShares RPC method. */ -export interface QueryFeeSharesRequest { - /** - * TODO feat(devgas): re-implement the paginated version - * TODO feat(colletions): add automatic pagination generation - */ - deployer: string -} - -/** - * QueryFeeSharesResponse is the response type for the Query/FeeShares RPC - * method. - */ -export interface QueryFeeSharesResponse { - /** FeeShare is the slice of all stored Reveneue for the deployer */ - feeshare: FeeShare[] -} - -/** QueryFeeShareRequest is the request type for the Query/FeeShare RPC method. */ -export interface QueryFeeShareRequest { - /** contract_address of a registered contract in bech32 format */ - contractAddress: string -} - -/** QueryFeeShareResponse is the response type for the Query/FeeShare RPC method. */ -export interface QueryFeeShareResponse { - /** FeeShare is a stored Reveneue for the queried contract */ - feeshare?: FeeShare -} - -/** 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 is the returned FeeShare parameter */ - params?: ModuleParams -} - -/** - * QueryFeeSharesByWithdrawerRequest is the request type for the - * Query/FeeSharesByWithdrawer RPC method. - */ -export interface QueryFeeSharesByWithdrawerRequest { - /** withdrawer_address in bech32 format */ - withdrawerAddress: string -} - -/** - * QueryFeeSharesByWithdrawerResponse is the response type for the - * Query/FeeSharesByWithdrawer RPC method. - */ -export interface QueryFeeSharesByWithdrawerResponse { - feeshare: FeeShare[] -} - -function createBaseQueryFeeSharesRequest(): QueryFeeSharesRequest { - return { deployer: "" } -} - -export const QueryFeeSharesRequest = { - encode( - message: QueryFeeSharesRequest, - writer: _m0.Writer = _m0.Writer.create() - ): _m0.Writer { - if (message.deployer !== "") { - writer.uint32(10).string(message.deployer) - } - return writer - }, - - decode( - input: _m0.Reader | Uint8Array, - length?: number - ): QueryFeeSharesRequest { - const reader = - input instanceof _m0.Reader ? input : _m0.Reader.create(input) - let end = length === undefined ? reader.len : reader.pos + length - const message = createBaseQueryFeeSharesRequest() - while (reader.pos < end) { - const tag = reader.uint32() - switch (tag >>> 3) { - case 1: - if (tag !== 10) { - break - } - - message.deployer = reader.string() - continue - } - if ((tag & 7) === 4 || tag === 0) { - break - } - reader.skipType(tag & 7) - } - return message - }, - - fromJSON(object: any): QueryFeeSharesRequest { - return { deployer: isSet(object.deployer) ? String(object.deployer) : "" } - }, - - toJSON(message: QueryFeeSharesRequest): unknown { - const obj: any = {} - message.deployer !== undefined && (obj.deployer = message.deployer) - return obj - }, - - create, I>>( - base?: I - ): QueryFeeSharesRequest { - return QueryFeeSharesRequest.fromPartial(base ?? {}) - }, - - fromPartial, I>>( - object: I - ): QueryFeeSharesRequest { - const message = createBaseQueryFeeSharesRequest() - message.deployer = object.deployer ?? "" - return message - }, -} - -function createBaseQueryFeeSharesResponse(): QueryFeeSharesResponse { - return { feeshare: [] } -} - -export const QueryFeeSharesResponse = { - encode( - message: QueryFeeSharesResponse, - writer: _m0.Writer = _m0.Writer.create() - ): _m0.Writer { - for (const v of message.feeshare) { - FeeShare.encode(v!, writer.uint32(10).fork()).ldelim() - } - return writer - }, - - decode( - input: _m0.Reader | Uint8Array, - length?: number - ): QueryFeeSharesResponse { - const reader = - input instanceof _m0.Reader ? input : _m0.Reader.create(input) - let end = length === undefined ? reader.len : reader.pos + length - const message = createBaseQueryFeeSharesResponse() - while (reader.pos < end) { - const tag = reader.uint32() - switch (tag >>> 3) { - case 1: - if (tag !== 10) { - break - } - - message.feeshare.push(FeeShare.decode(reader, reader.uint32())) - continue - } - if ((tag & 7) === 4 || tag === 0) { - break - } - reader.skipType(tag & 7) - } - return message - }, - - fromJSON(object: any): QueryFeeSharesResponse { - return { - feeshare: Array.isArray(object?.feeshare) - ? object.feeshare.map((e: any) => FeeShare.fromJSON(e)) - : [], - } - }, - - toJSON(message: QueryFeeSharesResponse): unknown { - const obj: any = {} - if (message.feeshare) { - obj.feeshare = message.feeshare.map((e) => - e ? FeeShare.toJSON(e) : undefined - ) - } else { - obj.feeshare = [] - } - return obj - }, - - create, I>>( - base?: I - ): QueryFeeSharesResponse { - return QueryFeeSharesResponse.fromPartial(base ?? {}) - }, - - fromPartial, I>>( - object: I - ): QueryFeeSharesResponse { - const message = createBaseQueryFeeSharesResponse() - message.feeshare = - object.feeshare?.map((e) => FeeShare.fromPartial(e)) || [] - return message - }, -} - -function createBaseQueryFeeShareRequest(): QueryFeeShareRequest { - return { contractAddress: "" } -} - -export const QueryFeeShareRequest = { - encode( - message: QueryFeeShareRequest, - writer: _m0.Writer = _m0.Writer.create() - ): _m0.Writer { - if (message.contractAddress !== "") { - writer.uint32(10).string(message.contractAddress) - } - return writer - }, - - decode( - input: _m0.Reader | Uint8Array, - length?: number - ): QueryFeeShareRequest { - const reader = - input instanceof _m0.Reader ? input : _m0.Reader.create(input) - let end = length === undefined ? reader.len : reader.pos + length - const message = createBaseQueryFeeShareRequest() - while (reader.pos < end) { - const tag = reader.uint32() - switch (tag >>> 3) { - case 1: - if (tag !== 10) { - break - } - - message.contractAddress = reader.string() - continue - } - if ((tag & 7) === 4 || tag === 0) { - break - } - reader.skipType(tag & 7) - } - return message - }, - - fromJSON(object: any): QueryFeeShareRequest { - return { - contractAddress: isSet(object.contractAddress) - ? String(object.contractAddress) - : "", - } - }, - - toJSON(message: QueryFeeShareRequest): unknown { - const obj: any = {} - message.contractAddress !== undefined && - (obj.contractAddress = message.contractAddress) - return obj - }, - - create, I>>( - base?: I - ): QueryFeeShareRequest { - return QueryFeeShareRequest.fromPartial(base ?? {}) - }, - - fromPartial, I>>( - object: I - ): QueryFeeShareRequest { - const message = createBaseQueryFeeShareRequest() - message.contractAddress = object.contractAddress ?? "" - return message - }, -} - -function createBaseQueryFeeShareResponse(): QueryFeeShareResponse { - return { feeshare: undefined } -} - -export const QueryFeeShareResponse = { - encode( - message: QueryFeeShareResponse, - writer: _m0.Writer = _m0.Writer.create() - ): _m0.Writer { - if (message.feeshare !== undefined) { - FeeShare.encode(message.feeshare, writer.uint32(10).fork()).ldelim() - } - return writer - }, - - decode( - input: _m0.Reader | Uint8Array, - length?: number - ): QueryFeeShareResponse { - const reader = - input instanceof _m0.Reader ? input : _m0.Reader.create(input) - let end = length === undefined ? reader.len : reader.pos + length - const message = createBaseQueryFeeShareResponse() - while (reader.pos < end) { - const tag = reader.uint32() - switch (tag >>> 3) { - case 1: - if (tag !== 10) { - break - } - - message.feeshare = FeeShare.decode(reader, reader.uint32()) - continue - } - if ((tag & 7) === 4 || tag === 0) { - break - } - reader.skipType(tag & 7) - } - return message - }, - - fromJSON(object: any): QueryFeeShareResponse { - return { - feeshare: isSet(object.feeshare) - ? FeeShare.fromJSON(object.feeshare) - : undefined, - } - }, - - toJSON(message: QueryFeeShareResponse): unknown { - const obj: any = {} - message.feeshare !== undefined && - (obj.feeshare = message.feeshare - ? FeeShare.toJSON(message.feeshare) - : undefined) - return obj - }, - - create, I>>( - base?: I - ): QueryFeeShareResponse { - return QueryFeeShareResponse.fromPartial(base ?? {}) - }, - - fromPartial, I>>( - object: I - ): QueryFeeShareResponse { - const message = createBaseQueryFeeShareResponse() - message.feeshare = - object.feeshare !== undefined && object.feeshare !== null - ? FeeShare.fromPartial(object.feeshare) - : undefined - return message - }, -} - -function createBaseQueryParamsRequest(): QueryParamsRequest { - return {} -} - -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 : _m0.Reader.create(input) - let end = length === undefined ? reader.len : reader.pos + length - const message = createBaseQueryParamsRequest() - while (reader.pos < end) { - const tag = reader.uint32() - switch (tag >>> 3) { - } - if ((tag & 7) === 4 || tag === 0) { - break - } - reader.skipType(tag & 7) - } - return message - }, - - fromJSON(_: any): QueryParamsRequest { - return {} - }, - - toJSON(_: QueryParamsRequest): unknown { - const obj: any = {} - return obj - }, - - create, I>>( - base?: I - ): QueryParamsRequest { - return QueryParamsRequest.fromPartial(base ?? {}) - }, - - fromPartial, I>>( - _: I - ): QueryParamsRequest { - const message = createBaseQueryParamsRequest() - return message - }, -} - -function createBaseQueryParamsResponse(): QueryParamsResponse { - return { params: undefined } -} - -export const QueryParamsResponse = { - encode( - message: QueryParamsResponse, - writer: _m0.Writer = _m0.Writer.create() - ): _m0.Writer { - if (message.params !== undefined) { - ModuleParams.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 : _m0.Reader.create(input) - let end = length === undefined ? reader.len : reader.pos + length - const message = createBaseQueryParamsResponse() - while (reader.pos < end) { - const tag = reader.uint32() - switch (tag >>> 3) { - case 1: - if (tag !== 10) { - break - } - - message.params = ModuleParams.decode(reader, reader.uint32()) - continue - } - if ((tag & 7) === 4 || tag === 0) { - break - } - reader.skipType(tag & 7) - } - return message - }, - - fromJSON(object: any): QueryParamsResponse { - return { - params: isSet(object.params) - ? ModuleParams.fromJSON(object.params) - : undefined, - } - }, - - toJSON(message: QueryParamsResponse): unknown { - const obj: any = {} - message.params !== undefined && - (obj.params = message.params - ? ModuleParams.toJSON(message.params) - : undefined) - return obj - }, - - create, I>>( - base?: I - ): QueryParamsResponse { - return QueryParamsResponse.fromPartial(base ?? {}) - }, - - fromPartial, I>>( - object: I - ): QueryParamsResponse { - const message = createBaseQueryParamsResponse() - message.params = - object.params !== undefined && object.params !== null - ? ModuleParams.fromPartial(object.params) - : undefined - return message - }, -} - -function createBaseQueryFeeSharesByWithdrawerRequest(): QueryFeeSharesByWithdrawerRequest { - return { withdrawerAddress: "" } -} - -export const QueryFeeSharesByWithdrawerRequest = { - encode( - message: QueryFeeSharesByWithdrawerRequest, - writer: _m0.Writer = _m0.Writer.create() - ): _m0.Writer { - if (message.withdrawerAddress !== "") { - writer.uint32(10).string(message.withdrawerAddress) - } - return writer - }, - - decode( - input: _m0.Reader | Uint8Array, - length?: number - ): QueryFeeSharesByWithdrawerRequest { - const reader = - input instanceof _m0.Reader ? input : _m0.Reader.create(input) - let end = length === undefined ? reader.len : reader.pos + length - const message = createBaseQueryFeeSharesByWithdrawerRequest() - while (reader.pos < end) { - const tag = reader.uint32() - switch (tag >>> 3) { - case 1: - if (tag !== 10) { - break - } - - message.withdrawerAddress = reader.string() - continue - } - if ((tag & 7) === 4 || tag === 0) { - break - } - reader.skipType(tag & 7) - } - return message - }, - - fromJSON(object: any): QueryFeeSharesByWithdrawerRequest { - return { - withdrawerAddress: isSet(object.withdrawerAddress) - ? String(object.withdrawerAddress) - : "", - } - }, - - toJSON(message: QueryFeeSharesByWithdrawerRequest): unknown { - const obj: any = {} - message.withdrawerAddress !== undefined && - (obj.withdrawerAddress = message.withdrawerAddress) - return obj - }, - - create, I>>( - base?: I - ): QueryFeeSharesByWithdrawerRequest { - return QueryFeeSharesByWithdrawerRequest.fromPartial(base ?? {}) - }, - - fromPartial< - I extends Exact, I> - >(object: I): QueryFeeSharesByWithdrawerRequest { - const message = createBaseQueryFeeSharesByWithdrawerRequest() - message.withdrawerAddress = object.withdrawerAddress ?? "" - return message - }, -} - -function createBaseQueryFeeSharesByWithdrawerResponse(): QueryFeeSharesByWithdrawerResponse { - return { feeshare: [] } -} - -export const QueryFeeSharesByWithdrawerResponse = { - encode( - message: QueryFeeSharesByWithdrawerResponse, - writer: _m0.Writer = _m0.Writer.create() - ): _m0.Writer { - for (const v of message.feeshare) { - FeeShare.encode(v!, writer.uint32(10).fork()).ldelim() - } - return writer - }, - - decode( - input: _m0.Reader | Uint8Array, - length?: number - ): QueryFeeSharesByWithdrawerResponse { - const reader = - input instanceof _m0.Reader ? input : _m0.Reader.create(input) - let end = length === undefined ? reader.len : reader.pos + length - const message = createBaseQueryFeeSharesByWithdrawerResponse() - while (reader.pos < end) { - const tag = reader.uint32() - switch (tag >>> 3) { - case 1: - if (tag !== 10) { - break - } - - message.feeshare.push(FeeShare.decode(reader, reader.uint32())) - continue - } - if ((tag & 7) === 4 || tag === 0) { - break - } - reader.skipType(tag & 7) - } - return message - }, - - fromJSON(object: any): QueryFeeSharesByWithdrawerResponse { - return { - feeshare: Array.isArray(object?.feeshare) - ? object.feeshare.map((e: any) => FeeShare.fromJSON(e)) - : [], - } - }, - - toJSON(message: QueryFeeSharesByWithdrawerResponse): unknown { - const obj: any = {} - if (message.feeshare) { - obj.feeshare = message.feeshare.map((e) => - e ? FeeShare.toJSON(e) : undefined - ) - } else { - obj.feeshare = [] - } - return obj - }, - - create, I>>( - base?: I - ): QueryFeeSharesByWithdrawerResponse { - return QueryFeeSharesByWithdrawerResponse.fromPartial(base ?? {}) - }, - - fromPartial< - I extends Exact, I> - >(object: I): QueryFeeSharesByWithdrawerResponse { - const message = createBaseQueryFeeSharesByWithdrawerResponse() - message.feeshare = - object.feeshare?.map((e) => FeeShare.fromPartial(e)) || [] - return message - }, -} - -/** Query defines the gRPC querier service. */ -export interface Query { - /** - * FeeShares retrieves all FeeShares that a deployer has - * registered - */ - FeeShares(request: QueryFeeSharesRequest): Promise - /** FeeShare retrieves a registered FeeShare for a given contract address */ - FeeShare(request: QueryFeeShareRequest): Promise - /** Params retrieves the module params */ - Params(request: QueryParamsRequest): Promise - /** - * FeeSharesByWithdrawer retrieves all FeeShares with a given withdrawer - * address - */ - FeeSharesByWithdrawer( - request: QueryFeeSharesByWithdrawerRequest - ): Promise -} - -export const QueryServiceName = "nibiru.devgas.v1.Query" -export class QueryClientImpl implements Query { - private readonly rpc: Rpc - private readonly service: string - constructor(rpc: Rpc, opts?: { service?: string }) { - this.service = opts?.service || QueryServiceName - this.rpc = rpc - this.FeeShares = this.FeeShares.bind(this) - this.FeeShare = this.FeeShare.bind(this) - this.Params = this.Params.bind(this) - this.FeeSharesByWithdrawer = this.FeeSharesByWithdrawer.bind(this) - } - FeeShares(request: QueryFeeSharesRequest): Promise { - const data = QueryFeeSharesRequest.encode(request).finish() - const promise = this.rpc.request(this.service, "FeeShares", data) - return promise.then((data) => - QueryFeeSharesResponse.decode(_m0.Reader.create(data)) - ) - } - - FeeShare(request: QueryFeeShareRequest): Promise { - const data = QueryFeeShareRequest.encode(request).finish() - const promise = this.rpc.request(this.service, "FeeShare", data) - return promise.then((data) => - QueryFeeShareResponse.decode(_m0.Reader.create(data)) - ) - } - - Params(request: QueryParamsRequest): Promise { - const data = QueryParamsRequest.encode(request).finish() - const promise = this.rpc.request(this.service, "Params", data) - return promise.then((data) => - QueryParamsResponse.decode(_m0.Reader.create(data)) - ) - } - - FeeSharesByWithdrawer( - request: QueryFeeSharesByWithdrawerRequest - ): Promise { - const data = QueryFeeSharesByWithdrawerRequest.encode(request).finish() - const promise = this.rpc.request( - this.service, - "FeeSharesByWithdrawer", - data - ) - return promise.then((data) => - QueryFeeSharesByWithdrawerResponse.decode(_m0.Reader.create(data)) - ) - } -} - -interface Rpc { - request( - service: string, - method: string, - data: Uint8Array - ): Promise -} - -type Builtin = - | Date - | Function - | Uint8Array - | string - | number - | boolean - | undefined - -export type DeepPartial = T extends Builtin - ? T - : T extends Long - ? string | number | Long - : T extends Array - ? Array> - : T extends ReadonlyArray - ? ReadonlyArray> - : T extends {} - ? { [K in keyof T]?: DeepPartial } - : Partial - -type KeysOfUnion = T extends T ? keyof T : never -export type Exact = P extends Builtin - ? P - : P & { [K in keyof P]: Exact } & { - [K in Exclude>]: never - } - -if (_m0.util.Long !== Long) { - _m0.util.Long = Long as any - _m0.configure() -} - -function isSet(value: any): boolean { - return value !== null && value !== undefined -} diff --git a/packages/protojs/src/nibiru/devgas/v1/tx.ts b/packages/protojs/src/nibiru/devgas/v1/tx.ts deleted file mode 100644 index b174c4aa..00000000 --- a/packages/protojs/src/nibiru/devgas/v1/tx.ts +++ /dev/null @@ -1,795 +0,0 @@ -/* eslint-disable */ -import Long from "long" -import _m0 from "protobufjs/minimal" -import { ModuleParams } from "./genesis" - -export const protobufPackage = "nibiru.devgas.v1" - -/** MsgRegisterFeeShare defines a message that registers a FeeShare */ -export interface MsgRegisterFeeShare { - /** contract_address in bech32 format */ - contractAddress: string - /** - * deployer_address is the bech32 address of message sender. It must be the - * same the contract's admin address - */ - deployerAddress: string - /** - * withdrawer_address is the bech32 address of account receiving the - * transaction fees - */ - withdrawerAddress: string -} - -/** MsgRegisterFeeShareResponse defines the MsgRegisterFeeShare response type */ -export interface MsgRegisterFeeShareResponse {} - -/** - * MsgUpdateFeeShare defines a message that updates the withdrawer address for a - * registered FeeShare - */ -export interface MsgUpdateFeeShare { - /** contract_address in bech32 format */ - contractAddress: string - /** - * deployer_address is the bech32 address of message sender. It must be the - * same the contract's admin address - */ - deployerAddress: string - /** - * withdrawer_address is the bech32 address of account receiving the - * transaction fees - */ - withdrawerAddress: string -} - -/** MsgUpdateFeeShareResponse defines the MsgUpdateFeeShare response type */ -export interface MsgUpdateFeeShareResponse {} - -/** MsgCancelFeeShare defines a message that cancels a registered FeeShare */ -export interface MsgCancelFeeShare { - /** contract_address in bech32 format */ - contractAddress: string - /** - * deployer_address is the bech32 address of message sender. It must be the - * same the contract's admin address - */ - deployerAddress: string -} - -/** MsgCancelFeeShareResponse defines the MsgCancelFeeShare response type */ -export interface MsgCancelFeeShareResponse {} - -/** - * MsgUpdateParams is the Msg/UpdateParams request type. - * - * Since: cosmos-sdk 0.47 - */ -export interface MsgUpdateParams { - /** - * authority is the address that controls the module (defaults to x/gov unless - * overwritten). - */ - authority: string - /** - * params defines the x/feeshare parameters to update. - * - * NOTE: All parameters must be supplied. - */ - params?: ModuleParams -} - -/** - * MsgUpdateParamsResponse defines the response structure for executing a - * MsgUpdateParams message. - * - * Since: cosmos-sdk 0.47 - */ -export interface MsgUpdateParamsResponse {} - -function createBaseMsgRegisterFeeShare(): MsgRegisterFeeShare { - return { contractAddress: "", deployerAddress: "", withdrawerAddress: "" } -} - -export const MsgRegisterFeeShare = { - encode( - message: MsgRegisterFeeShare, - writer: _m0.Writer = _m0.Writer.create() - ): _m0.Writer { - if (message.contractAddress !== "") { - writer.uint32(10).string(message.contractAddress) - } - if (message.deployerAddress !== "") { - writer.uint32(18).string(message.deployerAddress) - } - if (message.withdrawerAddress !== "") { - writer.uint32(26).string(message.withdrawerAddress) - } - return writer - }, - - decode(input: _m0.Reader | Uint8Array, length?: number): MsgRegisterFeeShare { - const reader = - input instanceof _m0.Reader ? input : _m0.Reader.create(input) - let end = length === undefined ? reader.len : reader.pos + length - const message = createBaseMsgRegisterFeeShare() - while (reader.pos < end) { - const tag = reader.uint32() - switch (tag >>> 3) { - case 1: - if (tag !== 10) { - break - } - - message.contractAddress = reader.string() - continue - case 2: - if (tag !== 18) { - break - } - - message.deployerAddress = reader.string() - continue - case 3: - if (tag !== 26) { - break - } - - message.withdrawerAddress = reader.string() - continue - } - if ((tag & 7) === 4 || tag === 0) { - break - } - reader.skipType(tag & 7) - } - return message - }, - - fromJSON(object: any): MsgRegisterFeeShare { - return { - contractAddress: isSet(object.contractAddress) - ? String(object.contractAddress) - : "", - deployerAddress: isSet(object.deployerAddress) - ? String(object.deployerAddress) - : "", - withdrawerAddress: isSet(object.withdrawerAddress) - ? String(object.withdrawerAddress) - : "", - } - }, - - toJSON(message: MsgRegisterFeeShare): unknown { - const obj: any = {} - message.contractAddress !== undefined && - (obj.contractAddress = message.contractAddress) - message.deployerAddress !== undefined && - (obj.deployerAddress = message.deployerAddress) - message.withdrawerAddress !== undefined && - (obj.withdrawerAddress = message.withdrawerAddress) - return obj - }, - - create, I>>( - base?: I - ): MsgRegisterFeeShare { - return MsgRegisterFeeShare.fromPartial(base ?? {}) - }, - - fromPartial, I>>( - object: I - ): MsgRegisterFeeShare { - const message = createBaseMsgRegisterFeeShare() - message.contractAddress = object.contractAddress ?? "" - message.deployerAddress = object.deployerAddress ?? "" - message.withdrawerAddress = object.withdrawerAddress ?? "" - return message - }, -} - -function createBaseMsgRegisterFeeShareResponse(): MsgRegisterFeeShareResponse { - return {} -} - -export const MsgRegisterFeeShareResponse = { - encode( - _: MsgRegisterFeeShareResponse, - writer: _m0.Writer = _m0.Writer.create() - ): _m0.Writer { - return writer - }, - - decode( - input: _m0.Reader | Uint8Array, - length?: number - ): MsgRegisterFeeShareResponse { - const reader = - input instanceof _m0.Reader ? input : _m0.Reader.create(input) - let end = length === undefined ? reader.len : reader.pos + length - const message = createBaseMsgRegisterFeeShareResponse() - while (reader.pos < end) { - const tag = reader.uint32() - switch (tag >>> 3) { - } - if ((tag & 7) === 4 || tag === 0) { - break - } - reader.skipType(tag & 7) - } - return message - }, - - fromJSON(_: any): MsgRegisterFeeShareResponse { - return {} - }, - - toJSON(_: MsgRegisterFeeShareResponse): unknown { - const obj: any = {} - return obj - }, - - create, I>>( - base?: I - ): MsgRegisterFeeShareResponse { - return MsgRegisterFeeShareResponse.fromPartial(base ?? {}) - }, - - fromPartial, I>>( - _: I - ): MsgRegisterFeeShareResponse { - const message = createBaseMsgRegisterFeeShareResponse() - return message - }, -} - -function createBaseMsgUpdateFeeShare(): MsgUpdateFeeShare { - return { contractAddress: "", deployerAddress: "", withdrawerAddress: "" } -} - -export const MsgUpdateFeeShare = { - encode( - message: MsgUpdateFeeShare, - writer: _m0.Writer = _m0.Writer.create() - ): _m0.Writer { - if (message.contractAddress !== "") { - writer.uint32(10).string(message.contractAddress) - } - if (message.deployerAddress !== "") { - writer.uint32(18).string(message.deployerAddress) - } - if (message.withdrawerAddress !== "") { - writer.uint32(26).string(message.withdrawerAddress) - } - return writer - }, - - decode(input: _m0.Reader | Uint8Array, length?: number): MsgUpdateFeeShare { - const reader = - input instanceof _m0.Reader ? input : _m0.Reader.create(input) - let end = length === undefined ? reader.len : reader.pos + length - const message = createBaseMsgUpdateFeeShare() - while (reader.pos < end) { - const tag = reader.uint32() - switch (tag >>> 3) { - case 1: - if (tag !== 10) { - break - } - - message.contractAddress = reader.string() - continue - case 2: - if (tag !== 18) { - break - } - - message.deployerAddress = reader.string() - continue - case 3: - if (tag !== 26) { - break - } - - message.withdrawerAddress = reader.string() - continue - } - if ((tag & 7) === 4 || tag === 0) { - break - } - reader.skipType(tag & 7) - } - return message - }, - - fromJSON(object: any): MsgUpdateFeeShare { - return { - contractAddress: isSet(object.contractAddress) - ? String(object.contractAddress) - : "", - deployerAddress: isSet(object.deployerAddress) - ? String(object.deployerAddress) - : "", - withdrawerAddress: isSet(object.withdrawerAddress) - ? String(object.withdrawerAddress) - : "", - } - }, - - toJSON(message: MsgUpdateFeeShare): unknown { - const obj: any = {} - message.contractAddress !== undefined && - (obj.contractAddress = message.contractAddress) - message.deployerAddress !== undefined && - (obj.deployerAddress = message.deployerAddress) - message.withdrawerAddress !== undefined && - (obj.withdrawerAddress = message.withdrawerAddress) - return obj - }, - - create, I>>( - base?: I - ): MsgUpdateFeeShare { - return MsgUpdateFeeShare.fromPartial(base ?? {}) - }, - - fromPartial, I>>( - object: I - ): MsgUpdateFeeShare { - const message = createBaseMsgUpdateFeeShare() - message.contractAddress = object.contractAddress ?? "" - message.deployerAddress = object.deployerAddress ?? "" - message.withdrawerAddress = object.withdrawerAddress ?? "" - return message - }, -} - -function createBaseMsgUpdateFeeShareResponse(): MsgUpdateFeeShareResponse { - return {} -} - -export const MsgUpdateFeeShareResponse = { - encode( - _: MsgUpdateFeeShareResponse, - writer: _m0.Writer = _m0.Writer.create() - ): _m0.Writer { - return writer - }, - - decode( - input: _m0.Reader | Uint8Array, - length?: number - ): MsgUpdateFeeShareResponse { - const reader = - input instanceof _m0.Reader ? input : _m0.Reader.create(input) - let end = length === undefined ? reader.len : reader.pos + length - const message = createBaseMsgUpdateFeeShareResponse() - while (reader.pos < end) { - const tag = reader.uint32() - switch (tag >>> 3) { - } - if ((tag & 7) === 4 || tag === 0) { - break - } - reader.skipType(tag & 7) - } - return message - }, - - fromJSON(_: any): MsgUpdateFeeShareResponse { - return {} - }, - - toJSON(_: MsgUpdateFeeShareResponse): unknown { - const obj: any = {} - return obj - }, - - create, I>>( - base?: I - ): MsgUpdateFeeShareResponse { - return MsgUpdateFeeShareResponse.fromPartial(base ?? {}) - }, - - fromPartial, I>>( - _: I - ): MsgUpdateFeeShareResponse { - const message = createBaseMsgUpdateFeeShareResponse() - return message - }, -} - -function createBaseMsgCancelFeeShare(): MsgCancelFeeShare { - return { contractAddress: "", deployerAddress: "" } -} - -export const MsgCancelFeeShare = { - encode( - message: MsgCancelFeeShare, - writer: _m0.Writer = _m0.Writer.create() - ): _m0.Writer { - if (message.contractAddress !== "") { - writer.uint32(10).string(message.contractAddress) - } - if (message.deployerAddress !== "") { - writer.uint32(18).string(message.deployerAddress) - } - return writer - }, - - decode(input: _m0.Reader | Uint8Array, length?: number): MsgCancelFeeShare { - const reader = - input instanceof _m0.Reader ? input : _m0.Reader.create(input) - let end = length === undefined ? reader.len : reader.pos + length - const message = createBaseMsgCancelFeeShare() - while (reader.pos < end) { - const tag = reader.uint32() - switch (tag >>> 3) { - case 1: - if (tag !== 10) { - break - } - - message.contractAddress = reader.string() - continue - case 2: - if (tag !== 18) { - break - } - - message.deployerAddress = reader.string() - continue - } - if ((tag & 7) === 4 || tag === 0) { - break - } - reader.skipType(tag & 7) - } - return message - }, - - fromJSON(object: any): MsgCancelFeeShare { - return { - contractAddress: isSet(object.contractAddress) - ? String(object.contractAddress) - : "", - deployerAddress: isSet(object.deployerAddress) - ? String(object.deployerAddress) - : "", - } - }, - - toJSON(message: MsgCancelFeeShare): unknown { - const obj: any = {} - message.contractAddress !== undefined && - (obj.contractAddress = message.contractAddress) - message.deployerAddress !== undefined && - (obj.deployerAddress = message.deployerAddress) - return obj - }, - - create, I>>( - base?: I - ): MsgCancelFeeShare { - return MsgCancelFeeShare.fromPartial(base ?? {}) - }, - - fromPartial, I>>( - object: I - ): MsgCancelFeeShare { - const message = createBaseMsgCancelFeeShare() - message.contractAddress = object.contractAddress ?? "" - message.deployerAddress = object.deployerAddress ?? "" - return message - }, -} - -function createBaseMsgCancelFeeShareResponse(): MsgCancelFeeShareResponse { - return {} -} - -export const MsgCancelFeeShareResponse = { - encode( - _: MsgCancelFeeShareResponse, - writer: _m0.Writer = _m0.Writer.create() - ): _m0.Writer { - return writer - }, - - decode( - input: _m0.Reader | Uint8Array, - length?: number - ): MsgCancelFeeShareResponse { - const reader = - input instanceof _m0.Reader ? input : _m0.Reader.create(input) - let end = length === undefined ? reader.len : reader.pos + length - const message = createBaseMsgCancelFeeShareResponse() - while (reader.pos < end) { - const tag = reader.uint32() - switch (tag >>> 3) { - } - if ((tag & 7) === 4 || tag === 0) { - break - } - reader.skipType(tag & 7) - } - return message - }, - - fromJSON(_: any): MsgCancelFeeShareResponse { - return {} - }, - - toJSON(_: MsgCancelFeeShareResponse): unknown { - const obj: any = {} - return obj - }, - - create, I>>( - base?: I - ): MsgCancelFeeShareResponse { - return MsgCancelFeeShareResponse.fromPartial(base ?? {}) - }, - - fromPartial, I>>( - _: I - ): MsgCancelFeeShareResponse { - const message = createBaseMsgCancelFeeShareResponse() - return message - }, -} - -function createBaseMsgUpdateParams(): MsgUpdateParams { - return { authority: "", params: undefined } -} - -export const MsgUpdateParams = { - encode( - message: MsgUpdateParams, - writer: _m0.Writer = _m0.Writer.create() - ): _m0.Writer { - if (message.authority !== "") { - writer.uint32(10).string(message.authority) - } - if (message.params !== undefined) { - ModuleParams.encode(message.params, writer.uint32(18).fork()).ldelim() - } - return writer - }, - - decode(input: _m0.Reader | Uint8Array, length?: number): MsgUpdateParams { - const reader = - input instanceof _m0.Reader ? input : _m0.Reader.create(input) - let end = length === undefined ? reader.len : reader.pos + length - const message = createBaseMsgUpdateParams() - while (reader.pos < end) { - const tag = reader.uint32() - switch (tag >>> 3) { - case 1: - if (tag !== 10) { - break - } - - message.authority = reader.string() - continue - case 2: - if (tag !== 18) { - break - } - - message.params = ModuleParams.decode(reader, reader.uint32()) - continue - } - if ((tag & 7) === 4 || tag === 0) { - break - } - reader.skipType(tag & 7) - } - return message - }, - - fromJSON(object: any): MsgUpdateParams { - return { - authority: isSet(object.authority) ? String(object.authority) : "", - params: isSet(object.params) - ? ModuleParams.fromJSON(object.params) - : undefined, - } - }, - - toJSON(message: MsgUpdateParams): unknown { - const obj: any = {} - message.authority !== undefined && (obj.authority = message.authority) - message.params !== undefined && - (obj.params = message.params - ? ModuleParams.toJSON(message.params) - : undefined) - return obj - }, - - create, I>>( - base?: I - ): MsgUpdateParams { - return MsgUpdateParams.fromPartial(base ?? {}) - }, - - fromPartial, I>>( - object: I - ): MsgUpdateParams { - const message = createBaseMsgUpdateParams() - message.authority = object.authority ?? "" - message.params = - object.params !== undefined && object.params !== null - ? ModuleParams.fromPartial(object.params) - : undefined - return message - }, -} - -function createBaseMsgUpdateParamsResponse(): MsgUpdateParamsResponse { - return {} -} - -export const MsgUpdateParamsResponse = { - encode( - _: MsgUpdateParamsResponse, - writer: _m0.Writer = _m0.Writer.create() - ): _m0.Writer { - return writer - }, - - decode( - input: _m0.Reader | Uint8Array, - length?: number - ): MsgUpdateParamsResponse { - const reader = - input instanceof _m0.Reader ? input : _m0.Reader.create(input) - let end = length === undefined ? reader.len : reader.pos + length - const message = createBaseMsgUpdateParamsResponse() - while (reader.pos < end) { - const tag = reader.uint32() - switch (tag >>> 3) { - } - if ((tag & 7) === 4 || tag === 0) { - break - } - reader.skipType(tag & 7) - } - return message - }, - - fromJSON(_: any): MsgUpdateParamsResponse { - return {} - }, - - toJSON(_: MsgUpdateParamsResponse): unknown { - const obj: any = {} - return obj - }, - - create, I>>( - base?: I - ): MsgUpdateParamsResponse { - return MsgUpdateParamsResponse.fromPartial(base ?? {}) - }, - - fromPartial, I>>( - _: I - ): MsgUpdateParamsResponse { - const message = createBaseMsgUpdateParamsResponse() - return message - }, -} - -/** Msg defines the fees Msg service. */ -export interface Msg { - /** RegisterFeeShare registers a new contract for receiving transaction fees */ - RegisterFeeShare( - request: MsgRegisterFeeShare - ): Promise - /** UpdateFeeShare updates the withdrawer address of a FeeShare */ - UpdateFeeShare(request: MsgUpdateFeeShare): Promise - /** - * CancelFeeShare cancels a contract's fee registration and further receival - * of transaction fees - */ - CancelFeeShare(request: MsgCancelFeeShare): Promise - /** Update the params of the module through gov v1 type. */ - UpdateParams(request: MsgUpdateParams): Promise -} - -export const MsgServiceName = "nibiru.devgas.v1.Msg" -export class MsgClientImpl implements Msg { - private readonly rpc: Rpc - private readonly service: string - constructor(rpc: Rpc, opts?: { service?: string }) { - this.service = opts?.service || MsgServiceName - this.rpc = rpc - this.RegisterFeeShare = this.RegisterFeeShare.bind(this) - this.UpdateFeeShare = this.UpdateFeeShare.bind(this) - this.CancelFeeShare = this.CancelFeeShare.bind(this) - this.UpdateParams = this.UpdateParams.bind(this) - } - RegisterFeeShare( - request: MsgRegisterFeeShare - ): Promise { - const data = MsgRegisterFeeShare.encode(request).finish() - const promise = this.rpc.request(this.service, "RegisterFeeShare", data) - return promise.then((data) => - MsgRegisterFeeShareResponse.decode(_m0.Reader.create(data)) - ) - } - - UpdateFeeShare( - request: MsgUpdateFeeShare - ): Promise { - const data = MsgUpdateFeeShare.encode(request).finish() - const promise = this.rpc.request(this.service, "UpdateFeeShare", data) - return promise.then((data) => - MsgUpdateFeeShareResponse.decode(_m0.Reader.create(data)) - ) - } - - CancelFeeShare( - request: MsgCancelFeeShare - ): Promise { - const data = MsgCancelFeeShare.encode(request).finish() - const promise = this.rpc.request(this.service, "CancelFeeShare", data) - return promise.then((data) => - MsgCancelFeeShareResponse.decode(_m0.Reader.create(data)) - ) - } - - UpdateParams(request: MsgUpdateParams): Promise { - const data = MsgUpdateParams.encode(request).finish() - const promise = this.rpc.request(this.service, "UpdateParams", data) - return promise.then((data) => - MsgUpdateParamsResponse.decode(_m0.Reader.create(data)) - ) - } -} - -interface Rpc { - request( - service: string, - method: string, - data: Uint8Array - ): Promise -} - -type Builtin = - | Date - | Function - | Uint8Array - | string - | number - | boolean - | undefined - -export type DeepPartial = T extends Builtin - ? T - : T extends Long - ? string | number | Long - : T extends Array - ? Array> - : T extends ReadonlyArray - ? ReadonlyArray> - : T extends {} - ? { [K in keyof T]?: DeepPartial } - : Partial - -type KeysOfUnion = T extends T ? keyof T : never -export type Exact = P extends Builtin - ? P - : P & { [K in keyof P]: Exact } & { - [K in Exclude>]: never - } - -if (_m0.util.Long !== Long) { - _m0.util.Long = Long as any - _m0.configure() -} - -function isSet(value: any): boolean { - return value !== null && value !== undefined -} diff --git a/packages/protojs/src/nibiru/epochs/v1/query.ts b/packages/protojs/src/nibiru/epochs/v1/query.ts index ed1bff50..b8076e56 100644 --- a/packages/protojs/src/nibiru/epochs/v1/query.ts +++ b/packages/protojs/src/nibiru/epochs/v1/query.ts @@ -5,9 +5,9 @@ import { EpochInfo } from "./state" export const protobufPackage = "nibiru.epochs.v1" -export interface QueryEpochInfosRequest {} +export interface QueryEpochsInfoRequest {} -export interface QueryEpochInfosResponse { +export interface QueryEpochsInfoResponse { epochs: EpochInfo[] } @@ -19,13 +19,13 @@ export interface QueryCurrentEpochResponse { currentEpoch: Long } -function createBaseQueryEpochInfosRequest(): QueryEpochInfosRequest { +function createBaseQueryEpochsInfoRequest(): QueryEpochsInfoRequest { return {} } -export const QueryEpochInfosRequest = { +export const QueryEpochsInfoRequest = { encode( - _: QueryEpochInfosRequest, + _: QueryEpochsInfoRequest, writer: _m0.Writer = _m0.Writer.create() ): _m0.Writer { return writer @@ -34,11 +34,11 @@ export const QueryEpochInfosRequest = { decode( input: _m0.Reader | Uint8Array, length?: number - ): QueryEpochInfosRequest { + ): QueryEpochsInfoRequest { const reader = input instanceof _m0.Reader ? input : _m0.Reader.create(input) let end = length === undefined ? reader.len : reader.pos + length - const message = createBaseQueryEpochInfosRequest() + const message = createBaseQueryEpochsInfoRequest() while (reader.pos < end) { const tag = reader.uint32() switch (tag >>> 3) { @@ -51,36 +51,36 @@ export const QueryEpochInfosRequest = { return message }, - fromJSON(_: any): QueryEpochInfosRequest { + fromJSON(_: any): QueryEpochsInfoRequest { return {} }, - toJSON(_: QueryEpochInfosRequest): unknown { + toJSON(_: QueryEpochsInfoRequest): unknown { const obj: any = {} return obj }, - create, I>>( + create, I>>( base?: I - ): QueryEpochInfosRequest { - return QueryEpochInfosRequest.fromPartial(base ?? {}) + ): QueryEpochsInfoRequest { + return QueryEpochsInfoRequest.fromPartial(base ?? {}) }, - fromPartial, I>>( + fromPartial, I>>( _: I - ): QueryEpochInfosRequest { - const message = createBaseQueryEpochInfosRequest() + ): QueryEpochsInfoRequest { + const message = createBaseQueryEpochsInfoRequest() return message }, } -function createBaseQueryEpochInfosResponse(): QueryEpochInfosResponse { +function createBaseQueryEpochsInfoResponse(): QueryEpochsInfoResponse { return { epochs: [] } } -export const QueryEpochInfosResponse = { +export const QueryEpochsInfoResponse = { encode( - message: QueryEpochInfosResponse, + message: QueryEpochsInfoResponse, writer: _m0.Writer = _m0.Writer.create() ): _m0.Writer { for (const v of message.epochs) { @@ -92,11 +92,11 @@ export const QueryEpochInfosResponse = { decode( input: _m0.Reader | Uint8Array, length?: number - ): QueryEpochInfosResponse { + ): QueryEpochsInfoResponse { const reader = input instanceof _m0.Reader ? input : _m0.Reader.create(input) let end = length === undefined ? reader.len : reader.pos + length - const message = createBaseQueryEpochInfosResponse() + const message = createBaseQueryEpochsInfoResponse() while (reader.pos < end) { const tag = reader.uint32() switch (tag >>> 3) { @@ -116,7 +116,7 @@ export const QueryEpochInfosResponse = { return message }, - fromJSON(object: any): QueryEpochInfosResponse { + fromJSON(object: any): QueryEpochsInfoResponse { return { epochs: Array.isArray(object?.epochs) ? object.epochs.map((e: any) => EpochInfo.fromJSON(e)) @@ -124,7 +124,7 @@ export const QueryEpochInfosResponse = { } }, - toJSON(message: QueryEpochInfosResponse): unknown { + toJSON(message: QueryEpochsInfoResponse): unknown { const obj: any = {} if (message.epochs) { obj.epochs = message.epochs.map((e) => @@ -136,16 +136,16 @@ export const QueryEpochInfosResponse = { return obj }, - create, I>>( + create, I>>( base?: I - ): QueryEpochInfosResponse { - return QueryEpochInfosResponse.fromPartial(base ?? {}) + ): QueryEpochsInfoResponse { + return QueryEpochsInfoResponse.fromPartial(base ?? {}) }, - fromPartial, I>>( + fromPartial, I>>( object: I - ): QueryEpochInfosResponse { - const message = createBaseQueryEpochInfosResponse() + ): QueryEpochsInfoResponse { + const message = createBaseQueryEpochsInfoResponse() message.epochs = object.epochs?.map((e) => EpochInfo.fromPartial(e)) || [] return message }, @@ -298,7 +298,7 @@ export const QueryCurrentEpochResponse = { /** Query defines the gRPC querier service. */ export interface Query { /** EpochInfos provide running epochInfos */ - EpochInfos(request: QueryEpochInfosRequest): Promise + EpochInfos(request: QueryEpochsInfoRequest): Promise /** CurrentEpoch provide current epoch of specified identifier */ CurrentEpoch( request: QueryCurrentEpochRequest @@ -316,12 +316,12 @@ export class QueryClientImpl implements Query { this.CurrentEpoch = this.CurrentEpoch.bind(this) } EpochInfos( - request: QueryEpochInfosRequest - ): Promise { - const data = QueryEpochInfosRequest.encode(request).finish() + request: QueryEpochsInfoRequest + ): Promise { + const data = QueryEpochsInfoRequest.encode(request).finish() const promise = this.rpc.request(this.service, "EpochInfos", data) return promise.then((data) => - QueryEpochInfosResponse.decode(_m0.Reader.create(data)) + QueryEpochsInfoResponse.decode(_m0.Reader.create(data)) ) } diff --git a/packages/protojs/src/nibiru/oracle/v1/tx.ts b/packages/protojs/src/nibiru/oracle/v1/tx.ts index 1fbd24f0..3171f768 100644 --- a/packages/protojs/src/nibiru/oracle/v1/tx.ts +++ b/packages/protojs/src/nibiru/oracle/v1/tx.ts @@ -1,7 +1,6 @@ /* eslint-disable */ import Long from "long" import _m0 from "protobufjs/minimal" -import { Duration } from "../../../google/protobuf/duration" export const protobufPackage = "nibiru.oracle.v1" @@ -65,63 +64,6 @@ export interface MsgDelegateFeedConsent { */ export interface MsgDelegateFeedConsentResponse {} -export interface MsgEditOracleParams { - sender: string - params?: OracleParamsMsg -} - -export interface MsgEditOracleParamsResponse {} - -export interface OracleParamsMsg { - /** VotePeriod defines the number of blocks during which voting takes place. */ - votePeriod: Long - /** - * VoteThreshold specifies the minimum proportion of votes that must be - * received for a ballot to pass. - */ - voteThreshold: string - /** - * RewardBand defines a maxium divergence that a price vote can have from the - * weighted median in the ballot. If a vote lies within the valid range - * defined by: - * Ī¼ := weightedMedian, - * validRange := Ī¼ Ā± (Ī¼ * rewardBand / 2), - * then rewards are added to the validator performance. - * Note that if the reward band is smaller than 1 standard - * deviation, the band is taken to be 1 standard deviation.a price - */ - rewardBand: string - /** - * The set of whitelisted markets, or asset pairs, for the module. - * Ex. '["unibi:uusd","ubtc:uusd"]' - */ - whitelist: string[] - /** - * SlashFraction returns the proportion of an oracle's stake that gets - * slashed in the event of slashing. `SlashFraction` specifies the exact - * penalty for failing a voting period. - */ - slashFraction: string - /** - * SlashWindow returns the number of voting periods that specify a - * "slash window". After each slash window, all oracles that have missed more - * than the penalty threshold are slashed. Missing the penalty threshold is - * synonymous with submitting fewer valid votes than `MinValidPerWindow`. - */ - slashWindow: Long - minValidPerWindow: string - /** Amount of time to look back for TWAP calculations */ - twapLookbackWindow?: Duration - /** - * The minimum number of voters (i.e. oracle validators) per pair for it to be - * considered a passing ballot. Recommended at least 4. - */ - minVoters: Long - /** The validator fee ratio that is given to validators every epoch. */ - validatorFeeRatio: string - expirationBlocks: Long -} - function createBaseMsgAggregateExchangeRatePrevote(): MsgAggregateExchangeRatePrevote { return { hash: "", feeder: "", validator: "" } } @@ -575,412 +517,6 @@ export const MsgDelegateFeedConsentResponse = { }, } -function createBaseMsgEditOracleParams(): MsgEditOracleParams { - return { sender: "", params: undefined } -} - -export const MsgEditOracleParams = { - encode( - message: MsgEditOracleParams, - writer: _m0.Writer = _m0.Writer.create() - ): _m0.Writer { - if (message.sender !== "") { - writer.uint32(10).string(message.sender) - } - if (message.params !== undefined) { - OracleParamsMsg.encode(message.params, writer.uint32(18).fork()).ldelim() - } - return writer - }, - - decode(input: _m0.Reader | Uint8Array, length?: number): MsgEditOracleParams { - const reader = - input instanceof _m0.Reader ? input : _m0.Reader.create(input) - let end = length === undefined ? reader.len : reader.pos + length - const message = createBaseMsgEditOracleParams() - while (reader.pos < end) { - const tag = reader.uint32() - switch (tag >>> 3) { - case 1: - if (tag !== 10) { - break - } - - message.sender = reader.string() - continue - case 2: - if (tag !== 18) { - break - } - - message.params = OracleParamsMsg.decode(reader, reader.uint32()) - continue - } - if ((tag & 7) === 4 || tag === 0) { - break - } - reader.skipType(tag & 7) - } - return message - }, - - fromJSON(object: any): MsgEditOracleParams { - return { - sender: isSet(object.sender) ? String(object.sender) : "", - params: isSet(object.params) - ? OracleParamsMsg.fromJSON(object.params) - : undefined, - } - }, - - toJSON(message: MsgEditOracleParams): unknown { - const obj: any = {} - message.sender !== undefined && (obj.sender = message.sender) - message.params !== undefined && - (obj.params = message.params - ? OracleParamsMsg.toJSON(message.params) - : undefined) - return obj - }, - - create, I>>( - base?: I - ): MsgEditOracleParams { - return MsgEditOracleParams.fromPartial(base ?? {}) - }, - - fromPartial, I>>( - object: I - ): MsgEditOracleParams { - const message = createBaseMsgEditOracleParams() - message.sender = object.sender ?? "" - message.params = - object.params !== undefined && object.params !== null - ? OracleParamsMsg.fromPartial(object.params) - : undefined - return message - }, -} - -function createBaseMsgEditOracleParamsResponse(): MsgEditOracleParamsResponse { - return {} -} - -export const MsgEditOracleParamsResponse = { - encode( - _: MsgEditOracleParamsResponse, - writer: _m0.Writer = _m0.Writer.create() - ): _m0.Writer { - return writer - }, - - decode( - input: _m0.Reader | Uint8Array, - length?: number - ): MsgEditOracleParamsResponse { - const reader = - input instanceof _m0.Reader ? input : _m0.Reader.create(input) - let end = length === undefined ? reader.len : reader.pos + length - const message = createBaseMsgEditOracleParamsResponse() - while (reader.pos < end) { - const tag = reader.uint32() - switch (tag >>> 3) { - } - if ((tag & 7) === 4 || tag === 0) { - break - } - reader.skipType(tag & 7) - } - return message - }, - - fromJSON(_: any): MsgEditOracleParamsResponse { - return {} - }, - - toJSON(_: MsgEditOracleParamsResponse): unknown { - const obj: any = {} - return obj - }, - - create, I>>( - base?: I - ): MsgEditOracleParamsResponse { - return MsgEditOracleParamsResponse.fromPartial(base ?? {}) - }, - - fromPartial, I>>( - _: I - ): MsgEditOracleParamsResponse { - const message = createBaseMsgEditOracleParamsResponse() - return message - }, -} - -function createBaseOracleParamsMsg(): OracleParamsMsg { - return { - votePeriod: Long.UZERO, - voteThreshold: "", - rewardBand: "", - whitelist: [], - slashFraction: "", - slashWindow: Long.UZERO, - minValidPerWindow: "", - twapLookbackWindow: undefined, - minVoters: Long.UZERO, - validatorFeeRatio: "", - expirationBlocks: Long.UZERO, - } -} - -export const OracleParamsMsg = { - encode( - message: OracleParamsMsg, - writer: _m0.Writer = _m0.Writer.create() - ): _m0.Writer { - if (!message.votePeriod.isZero()) { - writer.uint32(8).uint64(message.votePeriod) - } - if (message.voteThreshold !== "") { - writer.uint32(18).string(message.voteThreshold) - } - if (message.rewardBand !== "") { - writer.uint32(26).string(message.rewardBand) - } - for (const v of message.whitelist) { - writer.uint32(34).string(v!) - } - if (message.slashFraction !== "") { - writer.uint32(42).string(message.slashFraction) - } - if (!message.slashWindow.isZero()) { - writer.uint32(48).uint64(message.slashWindow) - } - if (message.minValidPerWindow !== "") { - writer.uint32(58).string(message.minValidPerWindow) - } - if (message.twapLookbackWindow !== undefined) { - Duration.encode( - message.twapLookbackWindow, - writer.uint32(66).fork() - ).ldelim() - } - if (!message.minVoters.isZero()) { - writer.uint32(72).uint64(message.minVoters) - } - if (message.validatorFeeRatio !== "") { - writer.uint32(82).string(message.validatorFeeRatio) - } - if (!message.expirationBlocks.isZero()) { - writer.uint32(88).uint64(message.expirationBlocks) - } - return writer - }, - - decode(input: _m0.Reader | Uint8Array, length?: number): OracleParamsMsg { - const reader = - input instanceof _m0.Reader ? input : _m0.Reader.create(input) - let end = length === undefined ? reader.len : reader.pos + length - const message = createBaseOracleParamsMsg() - while (reader.pos < end) { - const tag = reader.uint32() - switch (tag >>> 3) { - case 1: - if (tag !== 8) { - break - } - - message.votePeriod = reader.uint64() as Long - continue - case 2: - if (tag !== 18) { - break - } - - message.voteThreshold = reader.string() - continue - case 3: - if (tag !== 26) { - break - } - - message.rewardBand = reader.string() - continue - case 4: - if (tag !== 34) { - break - } - - message.whitelist.push(reader.string()) - continue - case 5: - if (tag !== 42) { - break - } - - message.slashFraction = reader.string() - continue - case 6: - if (tag !== 48) { - break - } - - message.slashWindow = reader.uint64() as Long - continue - case 7: - if (tag !== 58) { - break - } - - message.minValidPerWindow = reader.string() - continue - case 8: - if (tag !== 66) { - break - } - - message.twapLookbackWindow = Duration.decode(reader, reader.uint32()) - continue - case 9: - if (tag !== 72) { - break - } - - message.minVoters = reader.uint64() as Long - continue - case 10: - if (tag !== 82) { - break - } - - message.validatorFeeRatio = reader.string() - continue - case 11: - if (tag !== 88) { - break - } - - message.expirationBlocks = reader.uint64() as Long - continue - } - if ((tag & 7) === 4 || tag === 0) { - break - } - reader.skipType(tag & 7) - } - return message - }, - - fromJSON(object: any): OracleParamsMsg { - return { - votePeriod: isSet(object.votePeriod) - ? Long.fromValue(object.votePeriod) - : Long.UZERO, - voteThreshold: isSet(object.voteThreshold) - ? String(object.voteThreshold) - : "", - rewardBand: isSet(object.rewardBand) ? String(object.rewardBand) : "", - whitelist: Array.isArray(object?.whitelist) - ? object.whitelist.map((e: any) => String(e)) - : [], - slashFraction: isSet(object.slashFraction) - ? String(object.slashFraction) - : "", - slashWindow: isSet(object.slashWindow) - ? Long.fromValue(object.slashWindow) - : Long.UZERO, - minValidPerWindow: isSet(object.minValidPerWindow) - ? String(object.minValidPerWindow) - : "", - twapLookbackWindow: isSet(object.twapLookbackWindow) - ? Duration.fromJSON(object.twapLookbackWindow) - : undefined, - minVoters: isSet(object.minVoters) - ? Long.fromValue(object.minVoters) - : Long.UZERO, - validatorFeeRatio: isSet(object.validatorFeeRatio) - ? String(object.validatorFeeRatio) - : "", - expirationBlocks: isSet(object.expirationBlocks) - ? Long.fromValue(object.expirationBlocks) - : Long.UZERO, - } - }, - - toJSON(message: OracleParamsMsg): unknown { - const obj: any = {} - message.votePeriod !== undefined && - (obj.votePeriod = (message.votePeriod || Long.UZERO).toString()) - message.voteThreshold !== undefined && - (obj.voteThreshold = message.voteThreshold) - message.rewardBand !== undefined && (obj.rewardBand = message.rewardBand) - if (message.whitelist) { - obj.whitelist = message.whitelist.map((e) => e) - } else { - obj.whitelist = [] - } - message.slashFraction !== undefined && - (obj.slashFraction = message.slashFraction) - message.slashWindow !== undefined && - (obj.slashWindow = (message.slashWindow || Long.UZERO).toString()) - message.minValidPerWindow !== undefined && - (obj.minValidPerWindow = message.minValidPerWindow) - message.twapLookbackWindow !== undefined && - (obj.twapLookbackWindow = message.twapLookbackWindow - ? Duration.toJSON(message.twapLookbackWindow) - : undefined) - message.minVoters !== undefined && - (obj.minVoters = (message.minVoters || Long.UZERO).toString()) - message.validatorFeeRatio !== undefined && - (obj.validatorFeeRatio = message.validatorFeeRatio) - message.expirationBlocks !== undefined && - (obj.expirationBlocks = ( - message.expirationBlocks || Long.UZERO - ).toString()) - return obj - }, - - create, I>>( - base?: I - ): OracleParamsMsg { - return OracleParamsMsg.fromPartial(base ?? {}) - }, - - fromPartial, I>>( - object: I - ): OracleParamsMsg { - const message = createBaseOracleParamsMsg() - message.votePeriod = - object.votePeriod !== undefined && object.votePeriod !== null - ? Long.fromValue(object.votePeriod) - : Long.UZERO - message.voteThreshold = object.voteThreshold ?? "" - message.rewardBand = object.rewardBand ?? "" - message.whitelist = object.whitelist?.map((e) => e) || [] - message.slashFraction = object.slashFraction ?? "" - message.slashWindow = - object.slashWindow !== undefined && object.slashWindow !== null - ? Long.fromValue(object.slashWindow) - : Long.UZERO - message.minValidPerWindow = object.minValidPerWindow ?? "" - message.twapLookbackWindow = - object.twapLookbackWindow !== undefined && - object.twapLookbackWindow !== null - ? Duration.fromPartial(object.twapLookbackWindow) - : undefined - message.minVoters = - object.minVoters !== undefined && object.minVoters !== null - ? Long.fromValue(object.minVoters) - : Long.UZERO - message.validatorFeeRatio = object.validatorFeeRatio ?? "" - message.expirationBlocks = - object.expirationBlocks !== undefined && object.expirationBlocks !== null - ? Long.fromValue(object.expirationBlocks) - : Long.UZERO - return message - }, -} - /** Msg defines the oracle Msg service. */ export interface Msg { /** @@ -1005,9 +541,6 @@ export interface Msg { DelegateFeedConsent( request: MsgDelegateFeedConsent ): Promise - EditOracleParams( - request: MsgEditOracleParams - ): Promise } export const MsgServiceName = "nibiru.oracle.v1.Msg" @@ -1021,7 +554,6 @@ export class MsgClientImpl implements Msg { this.AggregateExchangeRatePrevote.bind(this) this.AggregateExchangeRateVote = this.AggregateExchangeRateVote.bind(this) this.DelegateFeedConsent = this.DelegateFeedConsent.bind(this) - this.EditOracleParams = this.EditOracleParams.bind(this) } AggregateExchangeRatePrevote( request: MsgAggregateExchangeRatePrevote @@ -1060,16 +592,6 @@ export class MsgClientImpl implements Msg { MsgDelegateFeedConsentResponse.decode(_m0.Reader.create(data)) ) } - - EditOracleParams( - request: MsgEditOracleParams - ): Promise { - const data = MsgEditOracleParams.encode(request).finish() - const promise = this.rpc.request(this.service, "EditOracleParams", data) - return promise.then((data) => - MsgEditOracleParamsResponse.decode(_m0.Reader.create(data)) - ) - } } interface Rpc { diff --git a/packages/protojs/src/nibiru/perp/v2/event.ts b/packages/protojs/src/nibiru/perp/v2/event.ts new file mode 100644 index 00000000..b8011caa --- /dev/null +++ b/packages/protojs/src/nibiru/perp/v2/event.ts @@ -0,0 +1,1187 @@ +/* eslint-disable */ +import Long from "long" +import _m0 from "protobufjs/minimal" +import { Coin } from "../../../cosmos/base/v1beta1/coin" +import { AMM, Market, Position } from "./state" + +export const protobufPackage = "nibiru.perp.v2" + +/** Emitted when a position changes. */ +export interface PositionChangedEvent { + finalPosition?: Position + /** + * Position notional (in quote units) after the change. In general, + * 'notional = baseAmount * priceQuotePerBase', where size is the baseAmount. + */ + positionNotional: string + /** Transaction fee paid. A "taker" fee. */ + transactionFee?: Coin + /** realize profits and losses after the change */ + realizedPnl: string + /** + * Amount of bad debt cleared by the PerpEF during the change. + * Bad debt is negative net margin past the liquidation point of a position. + */ + badDebt?: Coin + /** + * A funding payment made or received by the trader on the current position. + * 'fundingPayment' is positive if 'owner' is the sender and negative if 'owner' + * is the receiver of the payment. Its magnitude is abs(size * fundingRate). + * Funding payments act to converge the mark price and index price + * (average price on major exchanges). + */ + fundingPayment: string + /** The block number at which this position was changed. */ + blockHeight: Long + /** + * margin_to_user is the amount of collateral received by the trader during + * the position change. A positve value indicates that the trader received + * funds, while a negative value indicates that the trader spent funds. + */ + marginToUser: string + /** + * change_reason describes the reason for why the position resulted in a + * change. Change type can take the following values: + * + * - CHANGE_REASON_UNSPECIFIED: Unspecified change reason. + * - CHANGE_REASON_ADD_MARGIN: Margin was added to the position. + * - CHANGE_REASON_REMOVE_MARGIN: Margin was removed from the position. + * - CHANGE_REASON_OPEN_POSITION: A new position was opened. + * - CHANGE_REASON_CLOSE_POSITION: An existing position was closed. + */ + changeReason: string + /** + * exchanged_size represent the change in size for an existing position + * after the change. A positive value indicates that the position size + * increased, while a negative value indicates that the position size + * decreased. + */ + exchangedSize: string + /** + * exchanged_notional represent the change in notional for an existing + * position after the change. A positive value indicates that the position + * notional increased, while a negative value indicates that the position + * notional decreased. + */ + exchangedNotional: string +} + +/** + * Emitted when a position is liquidated. Wraps a PositionChanged event since a + * liquidation causes position changes. + */ +export interface PositionLiquidatedEvent { + positionChangedEvent?: PositionChangedEvent + /** Address of the account that executed the tx. */ + liquidatorAddress: string + /** Commission (in margin units) received by 'liquidator'. */ + feeToLiquidator?: Coin + /** Commission (in margin units) given to the ecosystem fund. */ + feeToEcosystemFund?: Coin +} + +/** Emitted when a position is settled. */ +export interface PositionSettledEvent { + /** Identifier for the virtual pool of the position. */ + pair: string + /** Owner of the position. */ + traderAddress: string + /** Settled coin as dictated by the settlement price of the perp.amm. */ + settledCoins: Coin[] +} + +/** Emitted when the funding rate changes for a market. */ +export interface FundingRateChangedEvent { + /** The pair for which the funding rate was calculated. */ + pair: string + /** The mark price of the pair. */ + markPriceTwap: string + /** The oracle index price of the pair. */ + indexPriceTwap: string + /** The latest premium fraction just calculated. */ + premiumFraction: string + /** + * The market's latest cumulative premium fraction. + * The funding payment a position will pay is the difference between this + * value and the latest cumulative premium fraction on the position, + * multiplied by the position size. + */ + cumulativePremiumFraction: string +} + +/** Emitted when liquidation fails. */ +export interface LiquidationFailedEvent { + /** The pair for which we are trying to liquidate. */ + pair: string + /** owner of the position. */ + trader: string + /** Address of the account that executed the tx. */ + liquidator: string + /** Reason for the liquidation failure. */ + reason: LiquidationFailedEvent_LiquidationFailedReason +} + +export enum LiquidationFailedEvent_LiquidationFailedReason { + UNSPECIFIED = 0, + /** POSITION_HEALTHY - the position is healthy and does not need to be liquidated. */ + POSITION_HEALTHY = 1, + /** NONEXISTENT_PAIR - the pair does not exist. */ + NONEXISTENT_PAIR = 2, + /** NONEXISTENT_POSITION - the position does not exist. */ + NONEXISTENT_POSITION = 3, + UNRECOGNIZED = -1, +} + +export function liquidationFailedEvent_LiquidationFailedReasonFromJSON( + object: any +): LiquidationFailedEvent_LiquidationFailedReason { + switch (object) { + case 0: + case "UNSPECIFIED": + return LiquidationFailedEvent_LiquidationFailedReason.UNSPECIFIED + case 1: + case "POSITION_HEALTHY": + return LiquidationFailedEvent_LiquidationFailedReason.POSITION_HEALTHY + case 2: + case "NONEXISTENT_PAIR": + return LiquidationFailedEvent_LiquidationFailedReason.NONEXISTENT_PAIR + case 3: + case "NONEXISTENT_POSITION": + return LiquidationFailedEvent_LiquidationFailedReason.NONEXISTENT_POSITION + case -1: + case "UNRECOGNIZED": + default: + return LiquidationFailedEvent_LiquidationFailedReason.UNRECOGNIZED + } +} + +export function liquidationFailedEvent_LiquidationFailedReasonToJSON( + object: LiquidationFailedEvent_LiquidationFailedReason +): string { + switch (object) { + case LiquidationFailedEvent_LiquidationFailedReason.UNSPECIFIED: + return "UNSPECIFIED" + case LiquidationFailedEvent_LiquidationFailedReason.POSITION_HEALTHY: + return "POSITION_HEALTHY" + case LiquidationFailedEvent_LiquidationFailedReason.NONEXISTENT_PAIR: + return "NONEXISTENT_PAIR" + case LiquidationFailedEvent_LiquidationFailedReason.NONEXISTENT_POSITION: + return "NONEXISTENT_POSITION" + case LiquidationFailedEvent_LiquidationFailedReason.UNRECOGNIZED: + default: + return "UNRECOGNIZED" + } +} + +/** + * This event is emitted when the amm is updated, which can be triggered by + * the following events: + * + * - swap + * - edit price multiplier + * - edit depth + */ +export interface AmmUpdatedEvent { + /** the final state of the AMM */ + finalAmm?: AMM + /** The mark price of the pair. */ + markPriceTwap: string + /** The oracle index price of the pair. */ + indexPriceTwap: string +} + +/** + * This event is emitted at the end of every block for persisting market changes + * off-chain + * + * Market changes are triggered by the following actions: + * + * - disabling market + * - changing market fees + * - bad debt is prepaid by the ecosystem fund + */ +export interface MarketUpdatedEvent { + /** the final state of the market */ + finalMarket?: Market +} + +function createBasePositionChangedEvent(): PositionChangedEvent { + return { + finalPosition: undefined, + positionNotional: "", + transactionFee: undefined, + realizedPnl: "", + badDebt: undefined, + fundingPayment: "", + blockHeight: Long.ZERO, + marginToUser: "", + changeReason: "", + exchangedSize: "", + exchangedNotional: "", + } +} + +export const PositionChangedEvent = { + encode( + message: PositionChangedEvent, + writer: _m0.Writer = _m0.Writer.create() + ): _m0.Writer { + if (message.finalPosition !== undefined) { + Position.encode(message.finalPosition, writer.uint32(10).fork()).ldelim() + } + if (message.positionNotional !== "") { + writer.uint32(18).string(message.positionNotional) + } + if (message.transactionFee !== undefined) { + Coin.encode(message.transactionFee, writer.uint32(26).fork()).ldelim() + } + if (message.realizedPnl !== "") { + writer.uint32(34).string(message.realizedPnl) + } + if (message.badDebt !== undefined) { + Coin.encode(message.badDebt, writer.uint32(42).fork()).ldelim() + } + if (message.fundingPayment !== "") { + writer.uint32(50).string(message.fundingPayment) + } + if (!message.blockHeight.isZero()) { + writer.uint32(56).int64(message.blockHeight) + } + if (message.marginToUser !== "") { + writer.uint32(66).string(message.marginToUser) + } + if (message.changeReason !== "") { + writer.uint32(74).string(message.changeReason) + } + if (message.exchangedSize !== "") { + writer.uint32(82).string(message.exchangedSize) + } + if (message.exchangedNotional !== "") { + writer.uint32(90).string(message.exchangedNotional) + } + return writer + }, + + decode( + input: _m0.Reader | Uint8Array, + length?: number + ): PositionChangedEvent { + const reader = + input instanceof _m0.Reader ? input : _m0.Reader.create(input) + let end = length === undefined ? reader.len : reader.pos + length + const message = createBasePositionChangedEvent() + while (reader.pos < end) { + const tag = reader.uint32() + switch (tag >>> 3) { + case 1: + if (tag !== 10) { + break + } + + message.finalPosition = Position.decode(reader, reader.uint32()) + continue + case 2: + if (tag !== 18) { + break + } + + message.positionNotional = reader.string() + continue + case 3: + if (tag !== 26) { + break + } + + message.transactionFee = Coin.decode(reader, reader.uint32()) + continue + case 4: + if (tag !== 34) { + break + } + + message.realizedPnl = reader.string() + continue + case 5: + if (tag !== 42) { + break + } + + message.badDebt = Coin.decode(reader, reader.uint32()) + continue + case 6: + if (tag !== 50) { + break + } + + message.fundingPayment = reader.string() + continue + case 7: + if (tag !== 56) { + break + } + + message.blockHeight = reader.int64() as Long + continue + case 8: + if (tag !== 66) { + break + } + + message.marginToUser = reader.string() + continue + case 9: + if (tag !== 74) { + break + } + + message.changeReason = reader.string() + continue + case 10: + if (tag !== 82) { + break + } + + message.exchangedSize = reader.string() + continue + case 11: + if (tag !== 90) { + break + } + + message.exchangedNotional = reader.string() + continue + } + if ((tag & 7) === 4 || tag === 0) { + break + } + reader.skipType(tag & 7) + } + return message + }, + + fromJSON(object: any): PositionChangedEvent { + return { + finalPosition: isSet(object.finalPosition) + ? Position.fromJSON(object.finalPosition) + : undefined, + positionNotional: isSet(object.positionNotional) + ? String(object.positionNotional) + : "", + transactionFee: isSet(object.transactionFee) + ? Coin.fromJSON(object.transactionFee) + : undefined, + realizedPnl: isSet(object.realizedPnl) ? String(object.realizedPnl) : "", + badDebt: isSet(object.badDebt) + ? Coin.fromJSON(object.badDebt) + : undefined, + fundingPayment: isSet(object.fundingPayment) + ? String(object.fundingPayment) + : "", + blockHeight: isSet(object.blockHeight) + ? Long.fromValue(object.blockHeight) + : Long.ZERO, + marginToUser: isSet(object.marginToUser) + ? String(object.marginToUser) + : "", + changeReason: isSet(object.changeReason) + ? String(object.changeReason) + : "", + exchangedSize: isSet(object.exchangedSize) + ? String(object.exchangedSize) + : "", + exchangedNotional: isSet(object.exchangedNotional) + ? String(object.exchangedNotional) + : "", + } + }, + + toJSON(message: PositionChangedEvent): unknown { + const obj: any = {} + message.finalPosition !== undefined && + (obj.finalPosition = message.finalPosition + ? Position.toJSON(message.finalPosition) + : undefined) + message.positionNotional !== undefined && + (obj.positionNotional = message.positionNotional) + message.transactionFee !== undefined && + (obj.transactionFee = message.transactionFee + ? Coin.toJSON(message.transactionFee) + : undefined) + message.realizedPnl !== undefined && (obj.realizedPnl = message.realizedPnl) + message.badDebt !== undefined && + (obj.badDebt = message.badDebt ? Coin.toJSON(message.badDebt) : undefined) + message.fundingPayment !== undefined && + (obj.fundingPayment = message.fundingPayment) + message.blockHeight !== undefined && + (obj.blockHeight = (message.blockHeight || Long.ZERO).toString()) + message.marginToUser !== undefined && + (obj.marginToUser = message.marginToUser) + message.changeReason !== undefined && + (obj.changeReason = message.changeReason) + message.exchangedSize !== undefined && + (obj.exchangedSize = message.exchangedSize) + message.exchangedNotional !== undefined && + (obj.exchangedNotional = message.exchangedNotional) + return obj + }, + + create, I>>( + base?: I + ): PositionChangedEvent { + return PositionChangedEvent.fromPartial(base ?? {}) + }, + + fromPartial, I>>( + object: I + ): PositionChangedEvent { + const message = createBasePositionChangedEvent() + message.finalPosition = + object.finalPosition !== undefined && object.finalPosition !== null + ? Position.fromPartial(object.finalPosition) + : undefined + message.positionNotional = object.positionNotional ?? "" + message.transactionFee = + object.transactionFee !== undefined && object.transactionFee !== null + ? Coin.fromPartial(object.transactionFee) + : undefined + message.realizedPnl = object.realizedPnl ?? "" + message.badDebt = + object.badDebt !== undefined && object.badDebt !== null + ? Coin.fromPartial(object.badDebt) + : undefined + message.fundingPayment = object.fundingPayment ?? "" + message.blockHeight = + object.blockHeight !== undefined && object.blockHeight !== null + ? Long.fromValue(object.blockHeight) + : Long.ZERO + message.marginToUser = object.marginToUser ?? "" + message.changeReason = object.changeReason ?? "" + message.exchangedSize = object.exchangedSize ?? "" + message.exchangedNotional = object.exchangedNotional ?? "" + return message + }, +} + +function createBasePositionLiquidatedEvent(): PositionLiquidatedEvent { + return { + positionChangedEvent: undefined, + liquidatorAddress: "", + feeToLiquidator: undefined, + feeToEcosystemFund: undefined, + } +} + +export const PositionLiquidatedEvent = { + encode( + message: PositionLiquidatedEvent, + writer: _m0.Writer = _m0.Writer.create() + ): _m0.Writer { + if (message.positionChangedEvent !== undefined) { + PositionChangedEvent.encode( + message.positionChangedEvent, + writer.uint32(10).fork() + ).ldelim() + } + if (message.liquidatorAddress !== "") { + writer.uint32(18).string(message.liquidatorAddress) + } + if (message.feeToLiquidator !== undefined) { + Coin.encode(message.feeToLiquidator, writer.uint32(26).fork()).ldelim() + } + if (message.feeToEcosystemFund !== undefined) { + Coin.encode(message.feeToEcosystemFund, writer.uint32(34).fork()).ldelim() + } + return writer + }, + + decode( + input: _m0.Reader | Uint8Array, + length?: number + ): PositionLiquidatedEvent { + const reader = + input instanceof _m0.Reader ? input : _m0.Reader.create(input) + let end = length === undefined ? reader.len : reader.pos + length + const message = createBasePositionLiquidatedEvent() + while (reader.pos < end) { + const tag = reader.uint32() + switch (tag >>> 3) { + case 1: + if (tag !== 10) { + break + } + + message.positionChangedEvent = PositionChangedEvent.decode( + reader, + reader.uint32() + ) + continue + case 2: + if (tag !== 18) { + break + } + + message.liquidatorAddress = reader.string() + continue + case 3: + if (tag !== 26) { + break + } + + message.feeToLiquidator = Coin.decode(reader, reader.uint32()) + continue + case 4: + if (tag !== 34) { + break + } + + message.feeToEcosystemFund = Coin.decode(reader, reader.uint32()) + continue + } + if ((tag & 7) === 4 || tag === 0) { + break + } + reader.skipType(tag & 7) + } + return message + }, + + fromJSON(object: any): PositionLiquidatedEvent { + return { + positionChangedEvent: isSet(object.positionChangedEvent) + ? PositionChangedEvent.fromJSON(object.positionChangedEvent) + : undefined, + liquidatorAddress: isSet(object.liquidatorAddress) + ? String(object.liquidatorAddress) + : "", + feeToLiquidator: isSet(object.feeToLiquidator) + ? Coin.fromJSON(object.feeToLiquidator) + : undefined, + feeToEcosystemFund: isSet(object.feeToEcosystemFund) + ? Coin.fromJSON(object.feeToEcosystemFund) + : undefined, + } + }, + + toJSON(message: PositionLiquidatedEvent): unknown { + const obj: any = {} + message.positionChangedEvent !== undefined && + (obj.positionChangedEvent = message.positionChangedEvent + ? PositionChangedEvent.toJSON(message.positionChangedEvent) + : undefined) + message.liquidatorAddress !== undefined && + (obj.liquidatorAddress = message.liquidatorAddress) + message.feeToLiquidator !== undefined && + (obj.feeToLiquidator = message.feeToLiquidator + ? Coin.toJSON(message.feeToLiquidator) + : undefined) + message.feeToEcosystemFund !== undefined && + (obj.feeToEcosystemFund = message.feeToEcosystemFund + ? Coin.toJSON(message.feeToEcosystemFund) + : undefined) + return obj + }, + + create, I>>( + base?: I + ): PositionLiquidatedEvent { + return PositionLiquidatedEvent.fromPartial(base ?? {}) + }, + + fromPartial, I>>( + object: I + ): PositionLiquidatedEvent { + const message = createBasePositionLiquidatedEvent() + message.positionChangedEvent = + object.positionChangedEvent !== undefined && + object.positionChangedEvent !== null + ? PositionChangedEvent.fromPartial(object.positionChangedEvent) + : undefined + message.liquidatorAddress = object.liquidatorAddress ?? "" + message.feeToLiquidator = + object.feeToLiquidator !== undefined && object.feeToLiquidator !== null + ? Coin.fromPartial(object.feeToLiquidator) + : undefined + message.feeToEcosystemFund = + object.feeToEcosystemFund !== undefined && + object.feeToEcosystemFund !== null + ? Coin.fromPartial(object.feeToEcosystemFund) + : undefined + return message + }, +} + +function createBasePositionSettledEvent(): PositionSettledEvent { + return { pair: "", traderAddress: "", settledCoins: [] } +} + +export const PositionSettledEvent = { + encode( + message: PositionSettledEvent, + writer: _m0.Writer = _m0.Writer.create() + ): _m0.Writer { + if (message.pair !== "") { + writer.uint32(10).string(message.pair) + } + if (message.traderAddress !== "") { + writer.uint32(18).string(message.traderAddress) + } + for (const v of message.settledCoins) { + Coin.encode(v!, writer.uint32(26).fork()).ldelim() + } + return writer + }, + + decode( + input: _m0.Reader | Uint8Array, + length?: number + ): PositionSettledEvent { + const reader = + input instanceof _m0.Reader ? input : _m0.Reader.create(input) + let end = length === undefined ? reader.len : reader.pos + length + const message = createBasePositionSettledEvent() + while (reader.pos < end) { + const tag = reader.uint32() + switch (tag >>> 3) { + case 1: + if (tag !== 10) { + break + } + + message.pair = reader.string() + continue + case 2: + if (tag !== 18) { + break + } + + message.traderAddress = reader.string() + continue + case 3: + if (tag !== 26) { + break + } + + message.settledCoins.push(Coin.decode(reader, reader.uint32())) + continue + } + if ((tag & 7) === 4 || tag === 0) { + break + } + reader.skipType(tag & 7) + } + return message + }, + + fromJSON(object: any): PositionSettledEvent { + return { + pair: isSet(object.pair) ? String(object.pair) : "", + traderAddress: isSet(object.traderAddress) + ? String(object.traderAddress) + : "", + settledCoins: Array.isArray(object?.settledCoins) + ? object.settledCoins.map((e: any) => Coin.fromJSON(e)) + : [], + } + }, + + toJSON(message: PositionSettledEvent): unknown { + const obj: any = {} + message.pair !== undefined && (obj.pair = message.pair) + message.traderAddress !== undefined && + (obj.traderAddress = message.traderAddress) + if (message.settledCoins) { + obj.settledCoins = message.settledCoins.map((e) => + e ? Coin.toJSON(e) : undefined + ) + } else { + obj.settledCoins = [] + } + return obj + }, + + create, I>>( + base?: I + ): PositionSettledEvent { + return PositionSettledEvent.fromPartial(base ?? {}) + }, + + fromPartial, I>>( + object: I + ): PositionSettledEvent { + const message = createBasePositionSettledEvent() + message.pair = object.pair ?? "" + message.traderAddress = object.traderAddress ?? "" + message.settledCoins = + object.settledCoins?.map((e) => Coin.fromPartial(e)) || [] + return message + }, +} + +function createBaseFundingRateChangedEvent(): FundingRateChangedEvent { + return { + pair: "", + markPriceTwap: "", + indexPriceTwap: "", + premiumFraction: "", + cumulativePremiumFraction: "", + } +} + +export const FundingRateChangedEvent = { + encode( + message: FundingRateChangedEvent, + writer: _m0.Writer = _m0.Writer.create() + ): _m0.Writer { + if (message.pair !== "") { + writer.uint32(10).string(message.pair) + } + if (message.markPriceTwap !== "") { + writer.uint32(18).string(message.markPriceTwap) + } + if (message.indexPriceTwap !== "") { + writer.uint32(26).string(message.indexPriceTwap) + } + if (message.premiumFraction !== "") { + writer.uint32(42).string(message.premiumFraction) + } + if (message.cumulativePremiumFraction !== "") { + writer.uint32(50).string(message.cumulativePremiumFraction) + } + return writer + }, + + decode( + input: _m0.Reader | Uint8Array, + length?: number + ): FundingRateChangedEvent { + const reader = + input instanceof _m0.Reader ? input : _m0.Reader.create(input) + let end = length === undefined ? reader.len : reader.pos + length + const message = createBaseFundingRateChangedEvent() + while (reader.pos < end) { + const tag = reader.uint32() + switch (tag >>> 3) { + case 1: + if (tag !== 10) { + break + } + + message.pair = reader.string() + continue + case 2: + if (tag !== 18) { + break + } + + message.markPriceTwap = reader.string() + continue + case 3: + if (tag !== 26) { + break + } + + message.indexPriceTwap = reader.string() + continue + case 5: + if (tag !== 42) { + break + } + + message.premiumFraction = reader.string() + continue + case 6: + if (tag !== 50) { + break + } + + message.cumulativePremiumFraction = reader.string() + continue + } + if ((tag & 7) === 4 || tag === 0) { + break + } + reader.skipType(tag & 7) + } + return message + }, + + fromJSON(object: any): FundingRateChangedEvent { + return { + pair: isSet(object.pair) ? String(object.pair) : "", + markPriceTwap: isSet(object.markPriceTwap) + ? String(object.markPriceTwap) + : "", + indexPriceTwap: isSet(object.indexPriceTwap) + ? String(object.indexPriceTwap) + : "", + premiumFraction: isSet(object.premiumFraction) + ? String(object.premiumFraction) + : "", + cumulativePremiumFraction: isSet(object.cumulativePremiumFraction) + ? String(object.cumulativePremiumFraction) + : "", + } + }, + + toJSON(message: FundingRateChangedEvent): unknown { + const obj: any = {} + message.pair !== undefined && (obj.pair = message.pair) + message.markPriceTwap !== undefined && + (obj.markPriceTwap = message.markPriceTwap) + message.indexPriceTwap !== undefined && + (obj.indexPriceTwap = message.indexPriceTwap) + message.premiumFraction !== undefined && + (obj.premiumFraction = message.premiumFraction) + message.cumulativePremiumFraction !== undefined && + (obj.cumulativePremiumFraction = message.cumulativePremiumFraction) + return obj + }, + + create, I>>( + base?: I + ): FundingRateChangedEvent { + return FundingRateChangedEvent.fromPartial(base ?? {}) + }, + + fromPartial, I>>( + object: I + ): FundingRateChangedEvent { + const message = createBaseFundingRateChangedEvent() + message.pair = object.pair ?? "" + message.markPriceTwap = object.markPriceTwap ?? "" + message.indexPriceTwap = object.indexPriceTwap ?? "" + message.premiumFraction = object.premiumFraction ?? "" + message.cumulativePremiumFraction = object.cumulativePremiumFraction ?? "" + return message + }, +} + +function createBaseLiquidationFailedEvent(): LiquidationFailedEvent { + return { pair: "", trader: "", liquidator: "", reason: 0 } +} + +export const LiquidationFailedEvent = { + encode( + message: LiquidationFailedEvent, + writer: _m0.Writer = _m0.Writer.create() + ): _m0.Writer { + if (message.pair !== "") { + writer.uint32(10).string(message.pair) + } + if (message.trader !== "") { + writer.uint32(18).string(message.trader) + } + if (message.liquidator !== "") { + writer.uint32(26).string(message.liquidator) + } + if (message.reason !== 0) { + writer.uint32(32).int32(message.reason) + } + return writer + }, + + decode( + input: _m0.Reader | Uint8Array, + length?: number + ): LiquidationFailedEvent { + const reader = + input instanceof _m0.Reader ? input : _m0.Reader.create(input) + let end = length === undefined ? reader.len : reader.pos + length + const message = createBaseLiquidationFailedEvent() + while (reader.pos < end) { + const tag = reader.uint32() + switch (tag >>> 3) { + case 1: + if (tag !== 10) { + break + } + + message.pair = reader.string() + continue + case 2: + if (tag !== 18) { + break + } + + message.trader = reader.string() + continue + case 3: + if (tag !== 26) { + break + } + + message.liquidator = reader.string() + continue + case 4: + if (tag !== 32) { + break + } + + message.reason = reader.int32() as any + continue + } + if ((tag & 7) === 4 || tag === 0) { + break + } + reader.skipType(tag & 7) + } + return message + }, + + fromJSON(object: any): LiquidationFailedEvent { + return { + pair: isSet(object.pair) ? String(object.pair) : "", + trader: isSet(object.trader) ? String(object.trader) : "", + liquidator: isSet(object.liquidator) ? String(object.liquidator) : "", + reason: isSet(object.reason) + ? liquidationFailedEvent_LiquidationFailedReasonFromJSON(object.reason) + : 0, + } + }, + + toJSON(message: LiquidationFailedEvent): unknown { + const obj: any = {} + message.pair !== undefined && (obj.pair = message.pair) + message.trader !== undefined && (obj.trader = message.trader) + message.liquidator !== undefined && (obj.liquidator = message.liquidator) + message.reason !== undefined && + (obj.reason = liquidationFailedEvent_LiquidationFailedReasonToJSON( + message.reason + )) + return obj + }, + + create, I>>( + base?: I + ): LiquidationFailedEvent { + return LiquidationFailedEvent.fromPartial(base ?? {}) + }, + + fromPartial, I>>( + object: I + ): LiquidationFailedEvent { + const message = createBaseLiquidationFailedEvent() + message.pair = object.pair ?? "" + message.trader = object.trader ?? "" + message.liquidator = object.liquidator ?? "" + message.reason = object.reason ?? 0 + return message + }, +} + +function createBaseAmmUpdatedEvent(): AmmUpdatedEvent { + return { finalAmm: undefined, markPriceTwap: "", indexPriceTwap: "" } +} + +export const AmmUpdatedEvent = { + encode( + message: AmmUpdatedEvent, + writer: _m0.Writer = _m0.Writer.create() + ): _m0.Writer { + if (message.finalAmm !== undefined) { + AMM.encode(message.finalAmm, writer.uint32(10).fork()).ldelim() + } + if (message.markPriceTwap !== "") { + writer.uint32(18).string(message.markPriceTwap) + } + if (message.indexPriceTwap !== "") { + writer.uint32(26).string(message.indexPriceTwap) + } + return writer + }, + + decode(input: _m0.Reader | Uint8Array, length?: number): AmmUpdatedEvent { + const reader = + input instanceof _m0.Reader ? input : _m0.Reader.create(input) + let end = length === undefined ? reader.len : reader.pos + length + const message = createBaseAmmUpdatedEvent() + while (reader.pos < end) { + const tag = reader.uint32() + switch (tag >>> 3) { + case 1: + if (tag !== 10) { + break + } + + message.finalAmm = AMM.decode(reader, reader.uint32()) + continue + case 2: + if (tag !== 18) { + break + } + + message.markPriceTwap = reader.string() + continue + case 3: + if (tag !== 26) { + break + } + + message.indexPriceTwap = reader.string() + continue + } + if ((tag & 7) === 4 || tag === 0) { + break + } + reader.skipType(tag & 7) + } + return message + }, + + fromJSON(object: any): AmmUpdatedEvent { + return { + finalAmm: isSet(object.finalAmm) + ? AMM.fromJSON(object.finalAmm) + : undefined, + markPriceTwap: isSet(object.markPriceTwap) + ? String(object.markPriceTwap) + : "", + indexPriceTwap: isSet(object.indexPriceTwap) + ? String(object.indexPriceTwap) + : "", + } + }, + + toJSON(message: AmmUpdatedEvent): unknown { + const obj: any = {} + message.finalAmm !== undefined && + (obj.finalAmm = message.finalAmm + ? AMM.toJSON(message.finalAmm) + : undefined) + message.markPriceTwap !== undefined && + (obj.markPriceTwap = message.markPriceTwap) + message.indexPriceTwap !== undefined && + (obj.indexPriceTwap = message.indexPriceTwap) + return obj + }, + + create, I>>( + base?: I + ): AmmUpdatedEvent { + return AmmUpdatedEvent.fromPartial(base ?? {}) + }, + + fromPartial, I>>( + object: I + ): AmmUpdatedEvent { + const message = createBaseAmmUpdatedEvent() + message.finalAmm = + object.finalAmm !== undefined && object.finalAmm !== null + ? AMM.fromPartial(object.finalAmm) + : undefined + message.markPriceTwap = object.markPriceTwap ?? "" + message.indexPriceTwap = object.indexPriceTwap ?? "" + return message + }, +} + +function createBaseMarketUpdatedEvent(): MarketUpdatedEvent { + return { finalMarket: undefined } +} + +export const MarketUpdatedEvent = { + encode( + message: MarketUpdatedEvent, + writer: _m0.Writer = _m0.Writer.create() + ): _m0.Writer { + if (message.finalMarket !== undefined) { + Market.encode(message.finalMarket, writer.uint32(10).fork()).ldelim() + } + return writer + }, + + decode(input: _m0.Reader | Uint8Array, length?: number): MarketUpdatedEvent { + const reader = + input instanceof _m0.Reader ? input : _m0.Reader.create(input) + let end = length === undefined ? reader.len : reader.pos + length + const message = createBaseMarketUpdatedEvent() + while (reader.pos < end) { + const tag = reader.uint32() + switch (tag >>> 3) { + case 1: + if (tag !== 10) { + break + } + + message.finalMarket = Market.decode(reader, reader.uint32()) + continue + } + if ((tag & 7) === 4 || tag === 0) { + break + } + reader.skipType(tag & 7) + } + return message + }, + + fromJSON(object: any): MarketUpdatedEvent { + return { + finalMarket: isSet(object.finalMarket) + ? Market.fromJSON(object.finalMarket) + : undefined, + } + }, + + toJSON(message: MarketUpdatedEvent): unknown { + const obj: any = {} + message.finalMarket !== undefined && + (obj.finalMarket = message.finalMarket + ? Market.toJSON(message.finalMarket) + : undefined) + return obj + }, + + create, I>>( + base?: I + ): MarketUpdatedEvent { + return MarketUpdatedEvent.fromPartial(base ?? {}) + }, + + fromPartial, I>>( + object: I + ): MarketUpdatedEvent { + const message = createBaseMarketUpdatedEvent() + message.finalMarket = + object.finalMarket !== undefined && object.finalMarket !== null + ? Market.fromPartial(object.finalMarket) + : undefined + return message + }, +} + +type Builtin = + | Date + | Function + | Uint8Array + | string + | number + | boolean + | undefined + +export type DeepPartial = T extends Builtin + ? T + : T extends Long + ? string | number | Long + : T extends Array + ? Array> + : T extends ReadonlyArray + ? ReadonlyArray> + : T extends {} + ? { [K in keyof T]?: DeepPartial } + : Partial + +type KeysOfUnion = T extends T ? keyof T : never +export type Exact = P extends Builtin + ? P + : P & { [K in keyof P]: Exact } & { + [K in Exclude>]: never + } + +if (_m0.util.Long !== Long) { + _m0.util.Long = Long as any + _m0.configure() +} + +function isSet(value: any): boolean { + return value !== null && value !== undefined +} diff --git a/packages/protojs/src/nibiru/perp/v2/genesis.ts b/packages/protojs/src/nibiru/perp/v2/genesis.ts new file mode 100644 index 00000000..968de6d9 --- /dev/null +++ b/packages/protojs/src/nibiru/perp/v2/genesis.ts @@ -0,0 +1,186 @@ +/* eslint-disable */ +import Long from "long" +import _m0 from "protobufjs/minimal" +import { AMM, Market, Position, ReserveSnapshot } from "./state" + +export const protobufPackage = "nibiru.perp.v2" + +/** GenesisState defines the perp module's genesis state. */ +export interface GenesisState { + markets: Market[] + amms: AMM[] + positions: Position[] + reserveSnapshots: ReserveSnapshot[] +} + +function createBaseGenesisState(): GenesisState { + return { markets: [], amms: [], positions: [], reserveSnapshots: [] } +} + +export const GenesisState = { + encode( + message: GenesisState, + writer: _m0.Writer = _m0.Writer.create() + ): _m0.Writer { + for (const v of message.markets) { + Market.encode(v!, writer.uint32(18).fork()).ldelim() + } + for (const v of message.amms) { + AMM.encode(v!, writer.uint32(26).fork()).ldelim() + } + for (const v of message.positions) { + Position.encode(v!, writer.uint32(34).fork()).ldelim() + } + for (const v of message.reserveSnapshots) { + ReserveSnapshot.encode(v!, writer.uint32(42).fork()).ldelim() + } + return writer + }, + + decode(input: _m0.Reader | Uint8Array, length?: number): GenesisState { + const reader = + input instanceof _m0.Reader ? input : _m0.Reader.create(input) + let end = length === undefined ? reader.len : reader.pos + length + const message = createBaseGenesisState() + while (reader.pos < end) { + const tag = reader.uint32() + switch (tag >>> 3) { + case 2: + if (tag !== 18) { + break + } + + message.markets.push(Market.decode(reader, reader.uint32())) + continue + case 3: + if (tag !== 26) { + break + } + + message.amms.push(AMM.decode(reader, reader.uint32())) + continue + case 4: + if (tag !== 34) { + break + } + + message.positions.push(Position.decode(reader, reader.uint32())) + continue + case 5: + if (tag !== 42) { + break + } + + message.reserveSnapshots.push( + ReserveSnapshot.decode(reader, reader.uint32()) + ) + continue + } + if ((tag & 7) === 4 || tag === 0) { + break + } + reader.skipType(tag & 7) + } + return message + }, + + fromJSON(object: any): GenesisState { + return { + markets: Array.isArray(object?.markets) + ? object.markets.map((e: any) => Market.fromJSON(e)) + : [], + amms: Array.isArray(object?.amms) + ? object.amms.map((e: any) => AMM.fromJSON(e)) + : [], + positions: Array.isArray(object?.positions) + ? object.positions.map((e: any) => Position.fromJSON(e)) + : [], + reserveSnapshots: Array.isArray(object?.reserveSnapshots) + ? object.reserveSnapshots.map((e: any) => ReserveSnapshot.fromJSON(e)) + : [], + } + }, + + toJSON(message: GenesisState): unknown { + const obj: any = {} + if (message.markets) { + obj.markets = message.markets.map((e) => + e ? Market.toJSON(e) : undefined + ) + } else { + obj.markets = [] + } + if (message.amms) { + obj.amms = message.amms.map((e) => (e ? AMM.toJSON(e) : undefined)) + } else { + obj.amms = [] + } + if (message.positions) { + obj.positions = message.positions.map((e) => + e ? Position.toJSON(e) : undefined + ) + } else { + obj.positions = [] + } + if (message.reserveSnapshots) { + obj.reserveSnapshots = message.reserveSnapshots.map((e) => + e ? ReserveSnapshot.toJSON(e) : undefined + ) + } else { + obj.reserveSnapshots = [] + } + return obj + }, + + create, I>>( + base?: I + ): GenesisState { + return GenesisState.fromPartial(base ?? {}) + }, + + fromPartial, I>>( + object: I + ): GenesisState { + const message = createBaseGenesisState() + message.markets = object.markets?.map((e) => Market.fromPartial(e)) || [] + message.amms = object.amms?.map((e) => AMM.fromPartial(e)) || [] + message.positions = + object.positions?.map((e) => Position.fromPartial(e)) || [] + message.reserveSnapshots = + object.reserveSnapshots?.map((e) => ReserveSnapshot.fromPartial(e)) || [] + return message + }, +} + +type Builtin = + | Date + | Function + | Uint8Array + | string + | number + | boolean + | undefined + +export type DeepPartial = T extends Builtin + ? T + : T extends Long + ? string | number | Long + : T extends Array + ? Array> + : T extends ReadonlyArray + ? ReadonlyArray> + : T extends {} + ? { [K in keyof T]?: DeepPartial } + : Partial + +type KeysOfUnion = T extends T ? keyof T : never +export type Exact = P extends Builtin + ? P + : P & { [K in keyof P]: Exact } & { + [K in Exclude>]: never + } + +if (_m0.util.Long !== Long) { + _m0.util.Long = Long as any + _m0.configure() +} diff --git a/packages/protojs/src/nibiru/perp/v2/query.ts b/packages/protojs/src/nibiru/perp/v2/query.ts new file mode 100644 index 00000000..54b085e6 --- /dev/null +++ b/packages/protojs/src/nibiru/perp/v2/query.ts @@ -0,0 +1,972 @@ +/* eslint-disable */ +import Long from "long" +import _m0 from "protobufjs/minimal" +import { Coin } from "../../../cosmos/base/v1beta1/coin" +import { AMM, Market, Position } from "./state" + +export const protobufPackage = "nibiru.perp.v2" + +export interface QueryPositionsRequest { + trader: string +} + +export interface QueryPositionsResponse { + positions: QueryPositionResponse[] +} + +/** + * QueryPositionRequest is the request type for the position of the x/perp + * module account. + */ +export interface QueryPositionRequest { + pair: string + trader: string +} + +export interface QueryPositionResponse { + /** The position as it exists in the blockchain state */ + position?: Position + /** + * The position's current notional value, if it were to be entirely closed (in + * margin units). + */ + positionNotional: string + /** The position's unrealized PnL. */ + unrealizedPnl: string + /** margin ratio of the position based on the spot price */ + marginRatio: string +} + +export interface QueryModuleAccountsRequest {} + +export interface QueryModuleAccountsResponse { + accounts: AccountWithBalance[] +} + +export interface AccountWithBalance { + name: string + address: string + balance: Coin[] +} + +export interface AmmMarket { + market?: Market + amm?: AMM +} + +export interface QueryMarketsRequest {} + +export interface QueryMarketsResponse { + ammMarkets: AmmMarket[] +} + +function createBaseQueryPositionsRequest(): QueryPositionsRequest { + return { trader: "" } +} + +export const QueryPositionsRequest = { + encode( + message: QueryPositionsRequest, + writer: _m0.Writer = _m0.Writer.create() + ): _m0.Writer { + if (message.trader !== "") { + writer.uint32(10).string(message.trader) + } + return writer + }, + + decode( + input: _m0.Reader | Uint8Array, + length?: number + ): QueryPositionsRequest { + const reader = + input instanceof _m0.Reader ? input : _m0.Reader.create(input) + let end = length === undefined ? reader.len : reader.pos + length + const message = createBaseQueryPositionsRequest() + while (reader.pos < end) { + const tag = reader.uint32() + switch (tag >>> 3) { + case 1: + if (tag !== 10) { + break + } + + message.trader = reader.string() + continue + } + if ((tag & 7) === 4 || tag === 0) { + break + } + reader.skipType(tag & 7) + } + return message + }, + + fromJSON(object: any): QueryPositionsRequest { + return { trader: isSet(object.trader) ? String(object.trader) : "" } + }, + + toJSON(message: QueryPositionsRequest): unknown { + const obj: any = {} + message.trader !== undefined && (obj.trader = message.trader) + return obj + }, + + create, I>>( + base?: I + ): QueryPositionsRequest { + return QueryPositionsRequest.fromPartial(base ?? {}) + }, + + fromPartial, I>>( + object: I + ): QueryPositionsRequest { + const message = createBaseQueryPositionsRequest() + message.trader = object.trader ?? "" + return message + }, +} + +function createBaseQueryPositionsResponse(): QueryPositionsResponse { + return { positions: [] } +} + +export const QueryPositionsResponse = { + encode( + message: QueryPositionsResponse, + writer: _m0.Writer = _m0.Writer.create() + ): _m0.Writer { + for (const v of message.positions) { + QueryPositionResponse.encode(v!, writer.uint32(10).fork()).ldelim() + } + return writer + }, + + decode( + input: _m0.Reader | Uint8Array, + length?: number + ): QueryPositionsResponse { + const reader = + input instanceof _m0.Reader ? input : _m0.Reader.create(input) + let end = length === undefined ? reader.len : reader.pos + length + const message = createBaseQueryPositionsResponse() + while (reader.pos < end) { + const tag = reader.uint32() + switch (tag >>> 3) { + case 1: + if (tag !== 10) { + break + } + + message.positions.push( + QueryPositionResponse.decode(reader, reader.uint32()) + ) + continue + } + if ((tag & 7) === 4 || tag === 0) { + break + } + reader.skipType(tag & 7) + } + return message + }, + + fromJSON(object: any): QueryPositionsResponse { + return { + positions: Array.isArray(object?.positions) + ? object.positions.map((e: any) => QueryPositionResponse.fromJSON(e)) + : [], + } + }, + + toJSON(message: QueryPositionsResponse): unknown { + const obj: any = {} + if (message.positions) { + obj.positions = message.positions.map((e) => + e ? QueryPositionResponse.toJSON(e) : undefined + ) + } else { + obj.positions = [] + } + return obj + }, + + create, I>>( + base?: I + ): QueryPositionsResponse { + return QueryPositionsResponse.fromPartial(base ?? {}) + }, + + fromPartial, I>>( + object: I + ): QueryPositionsResponse { + const message = createBaseQueryPositionsResponse() + message.positions = + object.positions?.map((e) => QueryPositionResponse.fromPartial(e)) || [] + return message + }, +} + +function createBaseQueryPositionRequest(): QueryPositionRequest { + return { pair: "", trader: "" } +} + +export const QueryPositionRequest = { + encode( + message: QueryPositionRequest, + writer: _m0.Writer = _m0.Writer.create() + ): _m0.Writer { + if (message.pair !== "") { + writer.uint32(10).string(message.pair) + } + if (message.trader !== "") { + writer.uint32(18).string(message.trader) + } + return writer + }, + + decode( + input: _m0.Reader | Uint8Array, + length?: number + ): QueryPositionRequest { + const reader = + input instanceof _m0.Reader ? input : _m0.Reader.create(input) + let end = length === undefined ? reader.len : reader.pos + length + const message = createBaseQueryPositionRequest() + while (reader.pos < end) { + const tag = reader.uint32() + switch (tag >>> 3) { + case 1: + if (tag !== 10) { + break + } + + message.pair = reader.string() + continue + case 2: + if (tag !== 18) { + break + } + + message.trader = reader.string() + continue + } + if ((tag & 7) === 4 || tag === 0) { + break + } + reader.skipType(tag & 7) + } + return message + }, + + fromJSON(object: any): QueryPositionRequest { + return { + pair: isSet(object.pair) ? String(object.pair) : "", + trader: isSet(object.trader) ? String(object.trader) : "", + } + }, + + toJSON(message: QueryPositionRequest): unknown { + const obj: any = {} + message.pair !== undefined && (obj.pair = message.pair) + message.trader !== undefined && (obj.trader = message.trader) + return obj + }, + + create, I>>( + base?: I + ): QueryPositionRequest { + return QueryPositionRequest.fromPartial(base ?? {}) + }, + + fromPartial, I>>( + object: I + ): QueryPositionRequest { + const message = createBaseQueryPositionRequest() + message.pair = object.pair ?? "" + message.trader = object.trader ?? "" + return message + }, +} + +function createBaseQueryPositionResponse(): QueryPositionResponse { + return { + position: undefined, + positionNotional: "", + unrealizedPnl: "", + marginRatio: "", + } +} + +export const QueryPositionResponse = { + encode( + message: QueryPositionResponse, + writer: _m0.Writer = _m0.Writer.create() + ): _m0.Writer { + if (message.position !== undefined) { + Position.encode(message.position, writer.uint32(10).fork()).ldelim() + } + if (message.positionNotional !== "") { + writer.uint32(18).string(message.positionNotional) + } + if (message.unrealizedPnl !== "") { + writer.uint32(26).string(message.unrealizedPnl) + } + if (message.marginRatio !== "") { + writer.uint32(34).string(message.marginRatio) + } + return writer + }, + + decode( + input: _m0.Reader | Uint8Array, + length?: number + ): QueryPositionResponse { + const reader = + input instanceof _m0.Reader ? input : _m0.Reader.create(input) + let end = length === undefined ? reader.len : reader.pos + length + const message = createBaseQueryPositionResponse() + while (reader.pos < end) { + const tag = reader.uint32() + switch (tag >>> 3) { + case 1: + if (tag !== 10) { + break + } + + message.position = Position.decode(reader, reader.uint32()) + continue + case 2: + if (tag !== 18) { + break + } + + message.positionNotional = reader.string() + continue + case 3: + if (tag !== 26) { + break + } + + message.unrealizedPnl = reader.string() + continue + case 4: + if (tag !== 34) { + break + } + + message.marginRatio = reader.string() + continue + } + if ((tag & 7) === 4 || tag === 0) { + break + } + reader.skipType(tag & 7) + } + return message + }, + + fromJSON(object: any): QueryPositionResponse { + return { + position: isSet(object.position) + ? Position.fromJSON(object.position) + : undefined, + positionNotional: isSet(object.positionNotional) + ? String(object.positionNotional) + : "", + unrealizedPnl: isSet(object.unrealizedPnl) + ? String(object.unrealizedPnl) + : "", + marginRatio: isSet(object.marginRatio) ? String(object.marginRatio) : "", + } + }, + + toJSON(message: QueryPositionResponse): unknown { + const obj: any = {} + message.position !== undefined && + (obj.position = message.position + ? Position.toJSON(message.position) + : undefined) + message.positionNotional !== undefined && + (obj.positionNotional = message.positionNotional) + message.unrealizedPnl !== undefined && + (obj.unrealizedPnl = message.unrealizedPnl) + message.marginRatio !== undefined && (obj.marginRatio = message.marginRatio) + return obj + }, + + create, I>>( + base?: I + ): QueryPositionResponse { + return QueryPositionResponse.fromPartial(base ?? {}) + }, + + fromPartial, I>>( + object: I + ): QueryPositionResponse { + const message = createBaseQueryPositionResponse() + message.position = + object.position !== undefined && object.position !== null + ? Position.fromPartial(object.position) + : undefined + message.positionNotional = object.positionNotional ?? "" + message.unrealizedPnl = object.unrealizedPnl ?? "" + message.marginRatio = object.marginRatio ?? "" + return message + }, +} + +function createBaseQueryModuleAccountsRequest(): QueryModuleAccountsRequest { + return {} +} + +export const QueryModuleAccountsRequest = { + encode( + _: QueryModuleAccountsRequest, + writer: _m0.Writer = _m0.Writer.create() + ): _m0.Writer { + return writer + }, + + decode( + input: _m0.Reader | Uint8Array, + length?: number + ): QueryModuleAccountsRequest { + const reader = + input instanceof _m0.Reader ? input : _m0.Reader.create(input) + let end = length === undefined ? reader.len : reader.pos + length + const message = createBaseQueryModuleAccountsRequest() + while (reader.pos < end) { + const tag = reader.uint32() + switch (tag >>> 3) { + } + if ((tag & 7) === 4 || tag === 0) { + break + } + reader.skipType(tag & 7) + } + return message + }, + + fromJSON(_: any): QueryModuleAccountsRequest { + return {} + }, + + toJSON(_: QueryModuleAccountsRequest): unknown { + const obj: any = {} + return obj + }, + + create, I>>( + base?: I + ): QueryModuleAccountsRequest { + return QueryModuleAccountsRequest.fromPartial(base ?? {}) + }, + + fromPartial, I>>( + _: I + ): QueryModuleAccountsRequest { + const message = createBaseQueryModuleAccountsRequest() + return message + }, +} + +function createBaseQueryModuleAccountsResponse(): QueryModuleAccountsResponse { + return { accounts: [] } +} + +export const QueryModuleAccountsResponse = { + encode( + message: QueryModuleAccountsResponse, + writer: _m0.Writer = _m0.Writer.create() + ): _m0.Writer { + for (const v of message.accounts) { + AccountWithBalance.encode(v!, writer.uint32(10).fork()).ldelim() + } + return writer + }, + + decode( + input: _m0.Reader | Uint8Array, + length?: number + ): QueryModuleAccountsResponse { + const reader = + input instanceof _m0.Reader ? input : _m0.Reader.create(input) + let end = length === undefined ? reader.len : reader.pos + length + const message = createBaseQueryModuleAccountsResponse() + while (reader.pos < end) { + const tag = reader.uint32() + switch (tag >>> 3) { + case 1: + if (tag !== 10) { + break + } + + message.accounts.push( + AccountWithBalance.decode(reader, reader.uint32()) + ) + continue + } + if ((tag & 7) === 4 || tag === 0) { + break + } + reader.skipType(tag & 7) + } + return message + }, + + fromJSON(object: any): QueryModuleAccountsResponse { + return { + accounts: Array.isArray(object?.accounts) + ? object.accounts.map((e: any) => AccountWithBalance.fromJSON(e)) + : [], + } + }, + + toJSON(message: QueryModuleAccountsResponse): unknown { + const obj: any = {} + if (message.accounts) { + obj.accounts = message.accounts.map((e) => + e ? AccountWithBalance.toJSON(e) : undefined + ) + } else { + obj.accounts = [] + } + return obj + }, + + create, I>>( + base?: I + ): QueryModuleAccountsResponse { + return QueryModuleAccountsResponse.fromPartial(base ?? {}) + }, + + fromPartial, I>>( + object: I + ): QueryModuleAccountsResponse { + const message = createBaseQueryModuleAccountsResponse() + message.accounts = + object.accounts?.map((e) => AccountWithBalance.fromPartial(e)) || [] + return message + }, +} + +function createBaseAccountWithBalance(): AccountWithBalance { + return { name: "", address: "", balance: [] } +} + +export const AccountWithBalance = { + encode( + message: AccountWithBalance, + writer: _m0.Writer = _m0.Writer.create() + ): _m0.Writer { + if (message.name !== "") { + writer.uint32(10).string(message.name) + } + if (message.address !== "") { + writer.uint32(18).string(message.address) + } + for (const v of message.balance) { + Coin.encode(v!, writer.uint32(26).fork()).ldelim() + } + return writer + }, + + decode(input: _m0.Reader | Uint8Array, length?: number): AccountWithBalance { + const reader = + input instanceof _m0.Reader ? input : _m0.Reader.create(input) + let end = length === undefined ? reader.len : reader.pos + length + const message = createBaseAccountWithBalance() + while (reader.pos < end) { + const tag = reader.uint32() + switch (tag >>> 3) { + case 1: + if (tag !== 10) { + break + } + + message.name = reader.string() + continue + case 2: + if (tag !== 18) { + break + } + + message.address = reader.string() + continue + case 3: + if (tag !== 26) { + break + } + + message.balance.push(Coin.decode(reader, reader.uint32())) + continue + } + if ((tag & 7) === 4 || tag === 0) { + break + } + reader.skipType(tag & 7) + } + return message + }, + + fromJSON(object: any): AccountWithBalance { + return { + name: isSet(object.name) ? String(object.name) : "", + address: isSet(object.address) ? String(object.address) : "", + balance: Array.isArray(object?.balance) + ? object.balance.map((e: any) => Coin.fromJSON(e)) + : [], + } + }, + + toJSON(message: AccountWithBalance): unknown { + const obj: any = {} + message.name !== undefined && (obj.name = message.name) + message.address !== undefined && (obj.address = message.address) + if (message.balance) { + obj.balance = message.balance.map((e) => (e ? Coin.toJSON(e) : undefined)) + } else { + obj.balance = [] + } + return obj + }, + + create, I>>( + base?: I + ): AccountWithBalance { + return AccountWithBalance.fromPartial(base ?? {}) + }, + + fromPartial, I>>( + object: I + ): AccountWithBalance { + const message = createBaseAccountWithBalance() + message.name = object.name ?? "" + message.address = object.address ?? "" + message.balance = object.balance?.map((e) => Coin.fromPartial(e)) || [] + return message + }, +} + +function createBaseAmmMarket(): AmmMarket { + return { market: undefined, amm: undefined } +} + +export const AmmMarket = { + encode( + message: AmmMarket, + writer: _m0.Writer = _m0.Writer.create() + ): _m0.Writer { + if (message.market !== undefined) { + Market.encode(message.market, writer.uint32(10).fork()).ldelim() + } + if (message.amm !== undefined) { + AMM.encode(message.amm, writer.uint32(18).fork()).ldelim() + } + return writer + }, + + decode(input: _m0.Reader | Uint8Array, length?: number): AmmMarket { + const reader = + input instanceof _m0.Reader ? input : _m0.Reader.create(input) + let end = length === undefined ? reader.len : reader.pos + length + const message = createBaseAmmMarket() + while (reader.pos < end) { + const tag = reader.uint32() + switch (tag >>> 3) { + case 1: + if (tag !== 10) { + break + } + + message.market = Market.decode(reader, reader.uint32()) + continue + case 2: + if (tag !== 18) { + break + } + + message.amm = AMM.decode(reader, reader.uint32()) + continue + } + if ((tag & 7) === 4 || tag === 0) { + break + } + reader.skipType(tag & 7) + } + return message + }, + + fromJSON(object: any): AmmMarket { + return { + market: isSet(object.market) ? Market.fromJSON(object.market) : undefined, + amm: isSet(object.amm) ? AMM.fromJSON(object.amm) : undefined, + } + }, + + toJSON(message: AmmMarket): unknown { + const obj: any = {} + message.market !== undefined && + (obj.market = message.market ? Market.toJSON(message.market) : undefined) + message.amm !== undefined && + (obj.amm = message.amm ? AMM.toJSON(message.amm) : undefined) + return obj + }, + + create, I>>(base?: I): AmmMarket { + return AmmMarket.fromPartial(base ?? {}) + }, + + fromPartial, I>>( + object: I + ): AmmMarket { + const message = createBaseAmmMarket() + message.market = + object.market !== undefined && object.market !== null + ? Market.fromPartial(object.market) + : undefined + message.amm = + object.amm !== undefined && object.amm !== null + ? AMM.fromPartial(object.amm) + : undefined + return message + }, +} + +function createBaseQueryMarketsRequest(): QueryMarketsRequest { + return {} +} + +export const QueryMarketsRequest = { + encode( + _: QueryMarketsRequest, + writer: _m0.Writer = _m0.Writer.create() + ): _m0.Writer { + return writer + }, + + decode(input: _m0.Reader | Uint8Array, length?: number): QueryMarketsRequest { + const reader = + input instanceof _m0.Reader ? input : _m0.Reader.create(input) + let end = length === undefined ? reader.len : reader.pos + length + const message = createBaseQueryMarketsRequest() + while (reader.pos < end) { + const tag = reader.uint32() + switch (tag >>> 3) { + } + if ((tag & 7) === 4 || tag === 0) { + break + } + reader.skipType(tag & 7) + } + return message + }, + + fromJSON(_: any): QueryMarketsRequest { + return {} + }, + + toJSON(_: QueryMarketsRequest): unknown { + const obj: any = {} + return obj + }, + + create, I>>( + base?: I + ): QueryMarketsRequest { + return QueryMarketsRequest.fromPartial(base ?? {}) + }, + + fromPartial, I>>( + _: I + ): QueryMarketsRequest { + const message = createBaseQueryMarketsRequest() + return message + }, +} + +function createBaseQueryMarketsResponse(): QueryMarketsResponse { + return { ammMarkets: [] } +} + +export const QueryMarketsResponse = { + encode( + message: QueryMarketsResponse, + writer: _m0.Writer = _m0.Writer.create() + ): _m0.Writer { + for (const v of message.ammMarkets) { + AmmMarket.encode(v!, writer.uint32(10).fork()).ldelim() + } + return writer + }, + + decode( + input: _m0.Reader | Uint8Array, + length?: number + ): QueryMarketsResponse { + const reader = + input instanceof _m0.Reader ? input : _m0.Reader.create(input) + let end = length === undefined ? reader.len : reader.pos + length + const message = createBaseQueryMarketsResponse() + while (reader.pos < end) { + const tag = reader.uint32() + switch (tag >>> 3) { + case 1: + if (tag !== 10) { + break + } + + message.ammMarkets.push(AmmMarket.decode(reader, reader.uint32())) + continue + } + if ((tag & 7) === 4 || tag === 0) { + break + } + reader.skipType(tag & 7) + } + return message + }, + + fromJSON(object: any): QueryMarketsResponse { + return { + ammMarkets: Array.isArray(object?.ammMarkets) + ? object.ammMarkets.map((e: any) => AmmMarket.fromJSON(e)) + : [], + } + }, + + toJSON(message: QueryMarketsResponse): unknown { + const obj: any = {} + if (message.ammMarkets) { + obj.ammMarkets = message.ammMarkets.map((e) => + e ? AmmMarket.toJSON(e) : undefined + ) + } else { + obj.ammMarkets = [] + } + return obj + }, + + create, I>>( + base?: I + ): QueryMarketsResponse { + return QueryMarketsResponse.fromPartial(base ?? {}) + }, + + fromPartial, I>>( + object: I + ): QueryMarketsResponse { + const message = createBaseQueryMarketsResponse() + message.ammMarkets = + object.ammMarkets?.map((e) => AmmMarket.fromPartial(e)) || [] + return message + }, +} + +/** Query defines the gRPC querier service. */ +export interface Query { + QueryPosition(request: QueryPositionRequest): Promise + QueryPositions( + request: QueryPositionsRequest + ): Promise + /** Queries the reserve assets in a given pool, identified by a token pair. */ + ModuleAccounts( + request: QueryModuleAccountsRequest + ): Promise + QueryMarkets(request: QueryMarketsRequest): Promise +} + +export const QueryServiceName = "nibiru.perp.v2.Query" +export class QueryClientImpl implements Query { + private readonly rpc: Rpc + private readonly service: string + constructor(rpc: Rpc, opts?: { service?: string }) { + this.service = opts?.service || QueryServiceName + this.rpc = rpc + this.QueryPosition = this.QueryPosition.bind(this) + this.QueryPositions = this.QueryPositions.bind(this) + this.ModuleAccounts = this.ModuleAccounts.bind(this) + this.QueryMarkets = this.QueryMarkets.bind(this) + } + QueryPosition(request: QueryPositionRequest): Promise { + const data = QueryPositionRequest.encode(request).finish() + const promise = this.rpc.request(this.service, "QueryPosition", data) + return promise.then((data) => + QueryPositionResponse.decode(_m0.Reader.create(data)) + ) + } + + QueryPositions( + request: QueryPositionsRequest + ): Promise { + const data = QueryPositionsRequest.encode(request).finish() + const promise = this.rpc.request(this.service, "QueryPositions", data) + return promise.then((data) => + QueryPositionsResponse.decode(_m0.Reader.create(data)) + ) + } + + ModuleAccounts( + request: QueryModuleAccountsRequest + ): Promise { + const data = QueryModuleAccountsRequest.encode(request).finish() + const promise = this.rpc.request(this.service, "ModuleAccounts", data) + return promise.then((data) => + QueryModuleAccountsResponse.decode(_m0.Reader.create(data)) + ) + } + + QueryMarkets(request: QueryMarketsRequest): Promise { + const data = QueryMarketsRequest.encode(request).finish() + const promise = this.rpc.request(this.service, "QueryMarkets", data) + return promise.then((data) => + QueryMarketsResponse.decode(_m0.Reader.create(data)) + ) + } +} + +interface Rpc { + request( + service: string, + method: string, + data: Uint8Array + ): Promise +} + +type Builtin = + | Date + | Function + | Uint8Array + | string + | number + | boolean + | undefined + +export type DeepPartial = T extends Builtin + ? T + : T extends Long + ? string | number | Long + : T extends Array + ? Array> + : T extends ReadonlyArray + ? ReadonlyArray> + : T extends {} + ? { [K in keyof T]?: DeepPartial } + : Partial + +type KeysOfUnion = T extends T ? keyof T : never +export type Exact = P extends Builtin + ? P + : P & { [K in keyof P]: Exact } & { + [K in Exclude>]: never + } + +if (_m0.util.Long !== Long) { + _m0.util.Long = Long as any + _m0.configure() +} + +function isSet(value: any): boolean { + return value !== null && value !== undefined +} diff --git a/packages/protojs/src/nibiru/perp/v2/state.ts b/packages/protojs/src/nibiru/perp/v2/state.ts new file mode 100644 index 00000000..8f217acd --- /dev/null +++ b/packages/protojs/src/nibiru/perp/v2/state.ts @@ -0,0 +1,922 @@ +/* eslint-disable */ +import Long from "long" +import _m0 from "protobufjs/minimal" +import { Coin } from "../../../cosmos/base/v1beta1/coin" +import { Duration } from "../../../google/protobuf/duration" + +export const protobufPackage = "nibiru.perp.v2" + +/** + * The direction that the user is trading in + * LONG means the user is going long the base asset (e.g. buy BTC) + * SHORT means the user is shorting the base asset (e.g. sell BTC) + */ +export enum Direction { + DIRECTION_UNSPECIFIED = 0, + LONG = 1, + SHORT = 2, + UNRECOGNIZED = -1, +} + +export function directionFromJSON(object: any): Direction { + switch (object) { + case 0: + case "DIRECTION_UNSPECIFIED": + return Direction.DIRECTION_UNSPECIFIED + case 1: + case "LONG": + return Direction.LONG + case 2: + case "SHORT": + return Direction.SHORT + case -1: + case "UNRECOGNIZED": + default: + return Direction.UNRECOGNIZED + } +} + +export function directionToJSON(object: Direction): string { + switch (object) { + case Direction.DIRECTION_UNSPECIFIED: + return "DIRECTION_UNSPECIFIED" + case Direction.LONG: + return "LONG" + case Direction.SHORT: + return "SHORT" + case Direction.UNRECOGNIZED: + default: + return "UNRECOGNIZED" + } +} + +/** Enumerates different options of calculating twap. */ +export enum TwapCalcOption { + TWAP_CALC_OPTION_UNSPECIFIED = 0, + /** SPOT - Spot price from quote asset reserve / base asset reserve */ + SPOT = 1, + /** QUOTE_ASSET_SWAP - Swapping with quote assets, output denominated in base assets */ + QUOTE_ASSET_SWAP = 2, + /** BASE_ASSET_SWAP - Swapping with base assets, output denominated in quote assets */ + BASE_ASSET_SWAP = 3, + UNRECOGNIZED = -1, +} + +export function twapCalcOptionFromJSON(object: any): TwapCalcOption { + switch (object) { + case 0: + case "TWAP_CALC_OPTION_UNSPECIFIED": + return TwapCalcOption.TWAP_CALC_OPTION_UNSPECIFIED + case 1: + case "SPOT": + return TwapCalcOption.SPOT + case 2: + case "QUOTE_ASSET_SWAP": + return TwapCalcOption.QUOTE_ASSET_SWAP + case 3: + case "BASE_ASSET_SWAP": + return TwapCalcOption.BASE_ASSET_SWAP + case -1: + case "UNRECOGNIZED": + default: + return TwapCalcOption.UNRECOGNIZED + } +} + +export function twapCalcOptionToJSON(object: TwapCalcOption): string { + switch (object) { + case TwapCalcOption.TWAP_CALC_OPTION_UNSPECIFIED: + return "TWAP_CALC_OPTION_UNSPECIFIED" + case TwapCalcOption.SPOT: + return "SPOT" + case TwapCalcOption.QUOTE_ASSET_SWAP: + return "QUOTE_ASSET_SWAP" + case TwapCalcOption.BASE_ASSET_SWAP: + return "BASE_ASSET_SWAP" + case TwapCalcOption.UNRECOGNIZED: + default: + return "UNRECOGNIZED" + } +} + +export interface Market { + /** + * the trading pair represented by this market + * always BASE:QUOTE, e.g. BTC:NUSD or ETH:NUSD + */ + pair: string + /** whether or not the market is enabled */ + enabled: boolean + /** the minimum margin ratio which a user must maintain on this market */ + maintenanceMarginRatio: string + /** the maximum leverage a user is able to be taken on this market */ + maxLeverage: string + /** + * Latest cumulative premium fraction for a given pair. + * Calculated once per funding rate interval. + * A premium fraction is the difference between mark and index, divided by the + * number of payments per day. (mark - index) / # payments in a day + */ + latestCumulativePremiumFraction: string + /** the percentage of the notional given to the exchange when trading */ + exchangeFeeRatio: string + /** + * the percentage of the notional transferred to the ecosystem fund when + * trading + */ + ecosystemFundFeeRatio: string + /** + * the percentage of liquidated position that will be + * given to out as a reward. Half of the liquidation fee is given to the + * liquidator, and the other half is given to the ecosystem fund. + */ + liquidationFeeRatio: string + /** + * the portion of the position size we try to liquidate if the available + * margin is higher than liquidation fee + */ + partialLiquidationRatio: string + /** specifies the interval on which the funding rate is updated */ + fundingRateEpochId: string + /** amount of time to look back for TWAP calculations */ + twapLookbackWindow?: Duration + /** the amount of collateral already credited from the ecosystem fund */ + prepaidBadDebt?: Coin + /** + * the maximum funding rate payment per epoch, this represents the maximum + * amount of funding that can be paid out per epoch as a percentage of the + * position size + */ + maxFundingRate: string +} + +export interface AMM { + /** identifies the market this AMM belongs to */ + pair: string + /** the amount of base reserves this AMM has */ + baseReserve: string + /** the amount of quote reserves this AMM has */ + quoteReserve: string + /** sqrt(k) */ + sqrtDepth: string + /** the price multiplier of the dynamic AMM */ + priceMultiplier: string + /** Total long refers to the sum of long open notional in base. */ + totalLong: string + /** Total short refers to the sum of short open notional in base. */ + totalShort: string +} + +export interface Position { + /** address identifies the address owner of this position */ + traderAddress: string + /** pair identifies the pair associated with this position */ + pair: string + /** the position size */ + size: string + /** amount of margin remaining in the position */ + margin: string + /** value of position in quote assets when opened */ + openNotional: string + /** + * The most recent cumulative premium fraction this position has. + * Used to calculate the next funding payment. + */ + latestCumulativePremiumFraction: string + /** last block number this position was updated */ + lastUpdatedBlockNumber: Long +} + +/** a snapshot of the perp.amm's reserves at a given point in time */ +export interface ReserveSnapshot { + amm?: AMM + /** milliseconds since unix epoch */ + timestampMs: Long +} + +function createBaseMarket(): Market { + return { + pair: "", + enabled: false, + maintenanceMarginRatio: "", + maxLeverage: "", + latestCumulativePremiumFraction: "", + exchangeFeeRatio: "", + ecosystemFundFeeRatio: "", + liquidationFeeRatio: "", + partialLiquidationRatio: "", + fundingRateEpochId: "", + twapLookbackWindow: undefined, + prepaidBadDebt: undefined, + maxFundingRate: "", + } +} + +export const Market = { + encode( + message: Market, + writer: _m0.Writer = _m0.Writer.create() + ): _m0.Writer { + if (message.pair !== "") { + writer.uint32(10).string(message.pair) + } + if (message.enabled === true) { + writer.uint32(16).bool(message.enabled) + } + if (message.maintenanceMarginRatio !== "") { + writer.uint32(26).string(message.maintenanceMarginRatio) + } + if (message.maxLeverage !== "") { + writer.uint32(34).string(message.maxLeverage) + } + if (message.latestCumulativePremiumFraction !== "") { + writer.uint32(42).string(message.latestCumulativePremiumFraction) + } + if (message.exchangeFeeRatio !== "") { + writer.uint32(50).string(message.exchangeFeeRatio) + } + if (message.ecosystemFundFeeRatio !== "") { + writer.uint32(58).string(message.ecosystemFundFeeRatio) + } + if (message.liquidationFeeRatio !== "") { + writer.uint32(66).string(message.liquidationFeeRatio) + } + if (message.partialLiquidationRatio !== "") { + writer.uint32(74).string(message.partialLiquidationRatio) + } + if (message.fundingRateEpochId !== "") { + writer.uint32(82).string(message.fundingRateEpochId) + } + if (message.twapLookbackWindow !== undefined) { + Duration.encode( + message.twapLookbackWindow, + writer.uint32(90).fork() + ).ldelim() + } + if (message.prepaidBadDebt !== undefined) { + Coin.encode(message.prepaidBadDebt, writer.uint32(98).fork()).ldelim() + } + if (message.maxFundingRate !== "") { + writer.uint32(106).string(message.maxFundingRate) + } + return writer + }, + + decode(input: _m0.Reader | Uint8Array, length?: number): Market { + const reader = + input instanceof _m0.Reader ? input : _m0.Reader.create(input) + let end = length === undefined ? reader.len : reader.pos + length + const message = createBaseMarket() + while (reader.pos < end) { + const tag = reader.uint32() + switch (tag >>> 3) { + case 1: + if (tag !== 10) { + break + } + + message.pair = reader.string() + continue + case 2: + if (tag !== 16) { + break + } + + message.enabled = reader.bool() + continue + case 3: + if (tag !== 26) { + break + } + + message.maintenanceMarginRatio = reader.string() + continue + case 4: + if (tag !== 34) { + break + } + + message.maxLeverage = reader.string() + continue + case 5: + if (tag !== 42) { + break + } + + message.latestCumulativePremiumFraction = reader.string() + continue + case 6: + if (tag !== 50) { + break + } + + message.exchangeFeeRatio = reader.string() + continue + case 7: + if (tag !== 58) { + break + } + + message.ecosystemFundFeeRatio = reader.string() + continue + case 8: + if (tag !== 66) { + break + } + + message.liquidationFeeRatio = reader.string() + continue + case 9: + if (tag !== 74) { + break + } + + message.partialLiquidationRatio = reader.string() + continue + case 10: + if (tag !== 82) { + break + } + + message.fundingRateEpochId = reader.string() + continue + case 11: + if (tag !== 90) { + break + } + + message.twapLookbackWindow = Duration.decode(reader, reader.uint32()) + continue + case 12: + if (tag !== 98) { + break + } + + message.prepaidBadDebt = Coin.decode(reader, reader.uint32()) + continue + case 13: + if (tag !== 106) { + break + } + + message.maxFundingRate = reader.string() + continue + } + if ((tag & 7) === 4 || tag === 0) { + break + } + reader.skipType(tag & 7) + } + return message + }, + + fromJSON(object: any): Market { + return { + pair: isSet(object.pair) ? String(object.pair) : "", + enabled: isSet(object.enabled) ? Boolean(object.enabled) : false, + maintenanceMarginRatio: isSet(object.maintenanceMarginRatio) + ? String(object.maintenanceMarginRatio) + : "", + maxLeverage: isSet(object.maxLeverage) ? String(object.maxLeverage) : "", + latestCumulativePremiumFraction: isSet( + object.latestCumulativePremiumFraction + ) + ? String(object.latestCumulativePremiumFraction) + : "", + exchangeFeeRatio: isSet(object.exchangeFeeRatio) + ? String(object.exchangeFeeRatio) + : "", + ecosystemFundFeeRatio: isSet(object.ecosystemFundFeeRatio) + ? String(object.ecosystemFundFeeRatio) + : "", + liquidationFeeRatio: isSet(object.liquidationFeeRatio) + ? String(object.liquidationFeeRatio) + : "", + partialLiquidationRatio: isSet(object.partialLiquidationRatio) + ? String(object.partialLiquidationRatio) + : "", + fundingRateEpochId: isSet(object.fundingRateEpochId) + ? String(object.fundingRateEpochId) + : "", + twapLookbackWindow: isSet(object.twapLookbackWindow) + ? Duration.fromJSON(object.twapLookbackWindow) + : undefined, + prepaidBadDebt: isSet(object.prepaidBadDebt) + ? Coin.fromJSON(object.prepaidBadDebt) + : undefined, + maxFundingRate: isSet(object.maxFundingRate) + ? String(object.maxFundingRate) + : "", + } + }, + + toJSON(message: Market): unknown { + const obj: any = {} + message.pair !== undefined && (obj.pair = message.pair) + message.enabled !== undefined && (obj.enabled = message.enabled) + message.maintenanceMarginRatio !== undefined && + (obj.maintenanceMarginRatio = message.maintenanceMarginRatio) + message.maxLeverage !== undefined && (obj.maxLeverage = message.maxLeverage) + message.latestCumulativePremiumFraction !== undefined && + (obj.latestCumulativePremiumFraction = + message.latestCumulativePremiumFraction) + message.exchangeFeeRatio !== undefined && + (obj.exchangeFeeRatio = message.exchangeFeeRatio) + message.ecosystemFundFeeRatio !== undefined && + (obj.ecosystemFundFeeRatio = message.ecosystemFundFeeRatio) + message.liquidationFeeRatio !== undefined && + (obj.liquidationFeeRatio = message.liquidationFeeRatio) + message.partialLiquidationRatio !== undefined && + (obj.partialLiquidationRatio = message.partialLiquidationRatio) + message.fundingRateEpochId !== undefined && + (obj.fundingRateEpochId = message.fundingRateEpochId) + message.twapLookbackWindow !== undefined && + (obj.twapLookbackWindow = message.twapLookbackWindow + ? Duration.toJSON(message.twapLookbackWindow) + : undefined) + message.prepaidBadDebt !== undefined && + (obj.prepaidBadDebt = message.prepaidBadDebt + ? Coin.toJSON(message.prepaidBadDebt) + : undefined) + message.maxFundingRate !== undefined && + (obj.maxFundingRate = message.maxFundingRate) + return obj + }, + + create, I>>(base?: I): Market { + return Market.fromPartial(base ?? {}) + }, + + fromPartial, I>>(object: I): Market { + const message = createBaseMarket() + message.pair = object.pair ?? "" + message.enabled = object.enabled ?? false + message.maintenanceMarginRatio = object.maintenanceMarginRatio ?? "" + message.maxLeverage = object.maxLeverage ?? "" + message.latestCumulativePremiumFraction = + object.latestCumulativePremiumFraction ?? "" + message.exchangeFeeRatio = object.exchangeFeeRatio ?? "" + message.ecosystemFundFeeRatio = object.ecosystemFundFeeRatio ?? "" + message.liquidationFeeRatio = object.liquidationFeeRatio ?? "" + message.partialLiquidationRatio = object.partialLiquidationRatio ?? "" + message.fundingRateEpochId = object.fundingRateEpochId ?? "" + message.twapLookbackWindow = + object.twapLookbackWindow !== undefined && + object.twapLookbackWindow !== null + ? Duration.fromPartial(object.twapLookbackWindow) + : undefined + message.prepaidBadDebt = + object.prepaidBadDebt !== undefined && object.prepaidBadDebt !== null + ? Coin.fromPartial(object.prepaidBadDebt) + : undefined + message.maxFundingRate = object.maxFundingRate ?? "" + return message + }, +} + +function createBaseAMM(): AMM { + return { + pair: "", + baseReserve: "", + quoteReserve: "", + sqrtDepth: "", + priceMultiplier: "", + totalLong: "", + totalShort: "", + } +} + +export const AMM = { + encode(message: AMM, writer: _m0.Writer = _m0.Writer.create()): _m0.Writer { + if (message.pair !== "") { + writer.uint32(10).string(message.pair) + } + if (message.baseReserve !== "") { + writer.uint32(18).string(message.baseReserve) + } + if (message.quoteReserve !== "") { + writer.uint32(26).string(message.quoteReserve) + } + if (message.sqrtDepth !== "") { + writer.uint32(34).string(message.sqrtDepth) + } + if (message.priceMultiplier !== "") { + writer.uint32(42).string(message.priceMultiplier) + } + if (message.totalLong !== "") { + writer.uint32(50).string(message.totalLong) + } + if (message.totalShort !== "") { + writer.uint32(58).string(message.totalShort) + } + return writer + }, + + decode(input: _m0.Reader | Uint8Array, length?: number): AMM { + const reader = + input instanceof _m0.Reader ? input : _m0.Reader.create(input) + let end = length === undefined ? reader.len : reader.pos + length + const message = createBaseAMM() + while (reader.pos < end) { + const tag = reader.uint32() + switch (tag >>> 3) { + case 1: + if (tag !== 10) { + break + } + + message.pair = reader.string() + continue + case 2: + if (tag !== 18) { + break + } + + message.baseReserve = reader.string() + continue + case 3: + if (tag !== 26) { + break + } + + message.quoteReserve = reader.string() + continue + case 4: + if (tag !== 34) { + break + } + + message.sqrtDepth = reader.string() + continue + case 5: + if (tag !== 42) { + break + } + + message.priceMultiplier = reader.string() + continue + case 6: + if (tag !== 50) { + break + } + + message.totalLong = reader.string() + continue + case 7: + if (tag !== 58) { + break + } + + message.totalShort = reader.string() + continue + } + if ((tag & 7) === 4 || tag === 0) { + break + } + reader.skipType(tag & 7) + } + return message + }, + + fromJSON(object: any): AMM { + return { + pair: isSet(object.pair) ? String(object.pair) : "", + baseReserve: isSet(object.baseReserve) ? String(object.baseReserve) : "", + quoteReserve: isSet(object.quoteReserve) + ? String(object.quoteReserve) + : "", + sqrtDepth: isSet(object.sqrtDepth) ? String(object.sqrtDepth) : "", + priceMultiplier: isSet(object.priceMultiplier) + ? String(object.priceMultiplier) + : "", + totalLong: isSet(object.totalLong) ? String(object.totalLong) : "", + totalShort: isSet(object.totalShort) ? String(object.totalShort) : "", + } + }, + + toJSON(message: AMM): unknown { + const obj: any = {} + message.pair !== undefined && (obj.pair = message.pair) + message.baseReserve !== undefined && (obj.baseReserve = message.baseReserve) + message.quoteReserve !== undefined && + (obj.quoteReserve = message.quoteReserve) + message.sqrtDepth !== undefined && (obj.sqrtDepth = message.sqrtDepth) + message.priceMultiplier !== undefined && + (obj.priceMultiplier = message.priceMultiplier) + message.totalLong !== undefined && (obj.totalLong = message.totalLong) + message.totalShort !== undefined && (obj.totalShort = message.totalShort) + return obj + }, + + create, I>>(base?: I): AMM { + return AMM.fromPartial(base ?? {}) + }, + + fromPartial, I>>(object: I): AMM { + const message = createBaseAMM() + message.pair = object.pair ?? "" + message.baseReserve = object.baseReserve ?? "" + message.quoteReserve = object.quoteReserve ?? "" + message.sqrtDepth = object.sqrtDepth ?? "" + message.priceMultiplier = object.priceMultiplier ?? "" + message.totalLong = object.totalLong ?? "" + message.totalShort = object.totalShort ?? "" + return message + }, +} + +function createBasePosition(): Position { + return { + traderAddress: "", + pair: "", + size: "", + margin: "", + openNotional: "", + latestCumulativePremiumFraction: "", + lastUpdatedBlockNumber: Long.ZERO, + } +} + +export const Position = { + encode( + message: Position, + writer: _m0.Writer = _m0.Writer.create() + ): _m0.Writer { + if (message.traderAddress !== "") { + writer.uint32(10).string(message.traderAddress) + } + if (message.pair !== "") { + writer.uint32(18).string(message.pair) + } + if (message.size !== "") { + writer.uint32(26).string(message.size) + } + if (message.margin !== "") { + writer.uint32(34).string(message.margin) + } + if (message.openNotional !== "") { + writer.uint32(42).string(message.openNotional) + } + if (message.latestCumulativePremiumFraction !== "") { + writer.uint32(50).string(message.latestCumulativePremiumFraction) + } + if (!message.lastUpdatedBlockNumber.isZero()) { + writer.uint32(56).int64(message.lastUpdatedBlockNumber) + } + return writer + }, + + decode(input: _m0.Reader | Uint8Array, length?: number): Position { + const reader = + input instanceof _m0.Reader ? input : _m0.Reader.create(input) + let end = length === undefined ? reader.len : reader.pos + length + const message = createBasePosition() + while (reader.pos < end) { + const tag = reader.uint32() + switch (tag >>> 3) { + case 1: + if (tag !== 10) { + break + } + + message.traderAddress = reader.string() + continue + case 2: + if (tag !== 18) { + break + } + + message.pair = reader.string() + continue + case 3: + if (tag !== 26) { + break + } + + message.size = reader.string() + continue + case 4: + if (tag !== 34) { + break + } + + message.margin = reader.string() + continue + case 5: + if (tag !== 42) { + break + } + + message.openNotional = reader.string() + continue + case 6: + if (tag !== 50) { + break + } + + message.latestCumulativePremiumFraction = reader.string() + continue + case 7: + if (tag !== 56) { + break + } + + message.lastUpdatedBlockNumber = reader.int64() as Long + continue + } + if ((tag & 7) === 4 || tag === 0) { + break + } + reader.skipType(tag & 7) + } + return message + }, + + fromJSON(object: any): Position { + return { + traderAddress: isSet(object.traderAddress) + ? String(object.traderAddress) + : "", + pair: isSet(object.pair) ? String(object.pair) : "", + size: isSet(object.size) ? String(object.size) : "", + margin: isSet(object.margin) ? String(object.margin) : "", + openNotional: isSet(object.openNotional) + ? String(object.openNotional) + : "", + latestCumulativePremiumFraction: isSet( + object.latestCumulativePremiumFraction + ) + ? String(object.latestCumulativePremiumFraction) + : "", + lastUpdatedBlockNumber: isSet(object.lastUpdatedBlockNumber) + ? Long.fromValue(object.lastUpdatedBlockNumber) + : Long.ZERO, + } + }, + + toJSON(message: Position): unknown { + const obj: any = {} + message.traderAddress !== undefined && + (obj.traderAddress = message.traderAddress) + message.pair !== undefined && (obj.pair = message.pair) + message.size !== undefined && (obj.size = message.size) + message.margin !== undefined && (obj.margin = message.margin) + message.openNotional !== undefined && + (obj.openNotional = message.openNotional) + message.latestCumulativePremiumFraction !== undefined && + (obj.latestCumulativePremiumFraction = + message.latestCumulativePremiumFraction) + message.lastUpdatedBlockNumber !== undefined && + (obj.lastUpdatedBlockNumber = ( + message.lastUpdatedBlockNumber || Long.ZERO + ).toString()) + return obj + }, + + create, I>>(base?: I): Position { + return Position.fromPartial(base ?? {}) + }, + + fromPartial, I>>(object: I): Position { + const message = createBasePosition() + message.traderAddress = object.traderAddress ?? "" + message.pair = object.pair ?? "" + message.size = object.size ?? "" + message.margin = object.margin ?? "" + message.openNotional = object.openNotional ?? "" + message.latestCumulativePremiumFraction = + object.latestCumulativePremiumFraction ?? "" + message.lastUpdatedBlockNumber = + object.lastUpdatedBlockNumber !== undefined && + object.lastUpdatedBlockNumber !== null + ? Long.fromValue(object.lastUpdatedBlockNumber) + : Long.ZERO + return message + }, +} + +function createBaseReserveSnapshot(): ReserveSnapshot { + return { amm: undefined, timestampMs: Long.ZERO } +} + +export const ReserveSnapshot = { + encode( + message: ReserveSnapshot, + writer: _m0.Writer = _m0.Writer.create() + ): _m0.Writer { + if (message.amm !== undefined) { + AMM.encode(message.amm, writer.uint32(10).fork()).ldelim() + } + if (!message.timestampMs.isZero()) { + writer.uint32(16).int64(message.timestampMs) + } + return writer + }, + + decode(input: _m0.Reader | Uint8Array, length?: number): ReserveSnapshot { + const reader = + input instanceof _m0.Reader ? input : _m0.Reader.create(input) + let end = length === undefined ? reader.len : reader.pos + length + const message = createBaseReserveSnapshot() + while (reader.pos < end) { + const tag = reader.uint32() + switch (tag >>> 3) { + case 1: + if (tag !== 10) { + break + } + + message.amm = AMM.decode(reader, reader.uint32()) + continue + case 2: + if (tag !== 16) { + break + } + + message.timestampMs = reader.int64() as Long + continue + } + if ((tag & 7) === 4 || tag === 0) { + break + } + reader.skipType(tag & 7) + } + return message + }, + + fromJSON(object: any): ReserveSnapshot { + return { + amm: isSet(object.amm) ? AMM.fromJSON(object.amm) : undefined, + timestampMs: isSet(object.timestampMs) + ? Long.fromValue(object.timestampMs) + : Long.ZERO, + } + }, + + toJSON(message: ReserveSnapshot): unknown { + const obj: any = {} + message.amm !== undefined && + (obj.amm = message.amm ? AMM.toJSON(message.amm) : undefined) + message.timestampMs !== undefined && + (obj.timestampMs = (message.timestampMs || Long.ZERO).toString()) + return obj + }, + + create, I>>( + base?: I + ): ReserveSnapshot { + return ReserveSnapshot.fromPartial(base ?? {}) + }, + + fromPartial, I>>( + object: I + ): ReserveSnapshot { + const message = createBaseReserveSnapshot() + message.amm = + object.amm !== undefined && object.amm !== null + ? AMM.fromPartial(object.amm) + : undefined + message.timestampMs = + object.timestampMs !== undefined && object.timestampMs !== null + ? Long.fromValue(object.timestampMs) + : Long.ZERO + return message + }, +} + +type Builtin = + | Date + | Function + | Uint8Array + | string + | number + | boolean + | undefined + +export type DeepPartial = T extends Builtin + ? T + : T extends Long + ? string | number | Long + : T extends Array + ? Array> + : T extends ReadonlyArray + ? ReadonlyArray> + : T extends {} + ? { [K in keyof T]?: DeepPartial } + : Partial + +type KeysOfUnion = T extends T ? keyof T : never +export type Exact = P extends Builtin + ? P + : P & { [K in keyof P]: Exact } & { + [K in Exclude>]: never + } + +if (_m0.util.Long !== Long) { + _m0.util.Long = Long as any + _m0.configure() +} + +function isSet(value: any): boolean { + return value !== null && value !== undefined +} diff --git a/packages/protojs/src/nibiru/perp/v2/tx.ts b/packages/protojs/src/nibiru/perp/v2/tx.ts new file mode 100644 index 00000000..b50979eb --- /dev/null +++ b/packages/protojs/src/nibiru/perp/v2/tx.ts @@ -0,0 +1,2072 @@ +/* eslint-disable */ +import Long from "long" +import _m0 from "protobufjs/minimal" +import { Coin } from "../../../cosmos/base/v1beta1/coin" +import { + Direction, + directionFromJSON, + directionToJSON, + Position, +} from "./state" + +export const protobufPackage = "nibiru.perp.v2" + +/** MsgRemoveMargin: Msg to remove margin. */ +export interface MsgRemoveMargin { + sender: string + pair: string + margin?: Coin +} + +export interface MsgRemoveMarginResponse { + /** tokens transferred back to the trader */ + marginOut?: Coin + /** the funding payment applied on this position interaction */ + fundingPayment: string + /** The resulting position */ + position?: Position +} + +/** MsgAddMargin: Msg to remove margin. */ +export interface MsgAddMargin { + sender: string + pair: string + margin?: Coin +} + +export interface MsgAddMarginResponse { + fundingPayment: string + position?: Position +} + +export interface MsgMultiLiquidate { + sender: string + liquidations: MsgMultiLiquidate_Liquidation[] +} + +export interface MsgMultiLiquidate_Liquidation { + pair: string + trader: string +} + +export interface MsgMultiLiquidateResponse { + liquidations: MsgMultiLiquidateResponse_LiquidationResponse[] +} + +export interface MsgMultiLiquidateResponse_LiquidationResponse { + success: boolean + error: string + /** nullable since no fee is taken on failed liquidation */ + liquidatorFee?: Coin + /** perp ecosystem fund */ + perpEfFee?: Coin + trader: string + pair: string +} + +export interface MsgMarketOrder { + sender: string + pair: string + side: Direction + quoteAssetAmount: string + leverage: string + baseAssetAmountLimit: string +} + +export interface MsgMarketOrderResponse { + position?: Position + /** The amount of quote assets exchanged. */ + exchangedNotionalValue: string + /** The amount of base assets exchanged. */ + exchangedPositionSize: string + /** + * The funding payment applied on this position change, measured in quote + * units. + */ + fundingPayment: string + /** + * The amount of PnL realized on this position changed, measured in quote + * units. + */ + realizedPnl: string + /** + * The unrealized PnL in the position after the position change, measured in + * quote units. + */ + unrealizedPnlAfter: string + /** + * The amount of margin the trader has to give to the vault. + * A negative value means the vault pays the trader. + */ + marginToVault: string + /** + * The position's notional value after the position change, measured in quote + * units. + */ + positionNotional: string +} + +export interface MsgClosePosition { + sender: string + pair: string +} + +export interface MsgClosePositionResponse { + /** The amount of quote assets exchanged. */ + exchangedNotionalValue: string + /** The amount of base assets exchanged. */ + exchangedPositionSize: string + /** + * The funding payment applied on this position change, measured in quote + * units. + */ + fundingPayment: string + /** + * The amount of PnL realized on this position changed, measured in quote + * units. + */ + realizedPnl: string + /** + * The amount of margin the trader receives after closing the position, from + * the vault. Should never be negative. + */ + marginToTrader: string +} + +export interface MsgPartialClose { + sender: string + pair: string + size: string +} + +export interface MsgPartialCloseResponse { + /** The amount of quote assets exchanged. */ + exchangedNotionalValue: string + /** The amount of base assets exchanged. */ + exchangedPositionSize: string + /** + * The funding payment applied on this position change, measured in quote + * units. + */ + fundingPayment: string + /** + * The amount of PnL realized on this position changed, measured in quote + * units. + */ + realizedPnl: string + /** + * The amount of margin the trader receives after closing the position, from + * the vault. Should never be negative. + */ + marginToTrader: string +} + +export interface MsgDonateToEcosystemFund { + sender: string + /** donation to the EF */ + donation?: Coin +} + +export interface MsgDonateToEcosystemFundResponse {} + +function createBaseMsgRemoveMargin(): MsgRemoveMargin { + return { sender: "", pair: "", margin: undefined } +} + +export const MsgRemoveMargin = { + encode( + message: MsgRemoveMargin, + writer: _m0.Writer = _m0.Writer.create() + ): _m0.Writer { + if (message.sender !== "") { + writer.uint32(10).string(message.sender) + } + if (message.pair !== "") { + writer.uint32(18).string(message.pair) + } + if (message.margin !== undefined) { + Coin.encode(message.margin, writer.uint32(26).fork()).ldelim() + } + return writer + }, + + decode(input: _m0.Reader | Uint8Array, length?: number): MsgRemoveMargin { + const reader = + input instanceof _m0.Reader ? input : _m0.Reader.create(input) + let end = length === undefined ? reader.len : reader.pos + length + const message = createBaseMsgRemoveMargin() + while (reader.pos < end) { + const tag = reader.uint32() + switch (tag >>> 3) { + case 1: + if (tag !== 10) { + break + } + + message.sender = reader.string() + continue + case 2: + if (tag !== 18) { + break + } + + message.pair = reader.string() + continue + case 3: + if (tag !== 26) { + break + } + + message.margin = Coin.decode(reader, reader.uint32()) + continue + } + if ((tag & 7) === 4 || tag === 0) { + break + } + reader.skipType(tag & 7) + } + return message + }, + + fromJSON(object: any): MsgRemoveMargin { + return { + sender: isSet(object.sender) ? String(object.sender) : "", + pair: isSet(object.pair) ? String(object.pair) : "", + margin: isSet(object.margin) ? Coin.fromJSON(object.margin) : undefined, + } + }, + + toJSON(message: MsgRemoveMargin): unknown { + const obj: any = {} + message.sender !== undefined && (obj.sender = message.sender) + message.pair !== undefined && (obj.pair = message.pair) + message.margin !== undefined && + (obj.margin = message.margin ? Coin.toJSON(message.margin) : undefined) + return obj + }, + + create, I>>( + base?: I + ): MsgRemoveMargin { + return MsgRemoveMargin.fromPartial(base ?? {}) + }, + + fromPartial, I>>( + object: I + ): MsgRemoveMargin { + const message = createBaseMsgRemoveMargin() + message.sender = object.sender ?? "" + message.pair = object.pair ?? "" + message.margin = + object.margin !== undefined && object.margin !== null + ? Coin.fromPartial(object.margin) + : undefined + return message + }, +} + +function createBaseMsgRemoveMarginResponse(): MsgRemoveMarginResponse { + return { marginOut: undefined, fundingPayment: "", position: undefined } +} + +export const MsgRemoveMarginResponse = { + encode( + message: MsgRemoveMarginResponse, + writer: _m0.Writer = _m0.Writer.create() + ): _m0.Writer { + if (message.marginOut !== undefined) { + Coin.encode(message.marginOut, writer.uint32(10).fork()).ldelim() + } + if (message.fundingPayment !== "") { + writer.uint32(18).string(message.fundingPayment) + } + if (message.position !== undefined) { + Position.encode(message.position, writer.uint32(26).fork()).ldelim() + } + return writer + }, + + decode( + input: _m0.Reader | Uint8Array, + length?: number + ): MsgRemoveMarginResponse { + const reader = + input instanceof _m0.Reader ? input : _m0.Reader.create(input) + let end = length === undefined ? reader.len : reader.pos + length + const message = createBaseMsgRemoveMarginResponse() + while (reader.pos < end) { + const tag = reader.uint32() + switch (tag >>> 3) { + case 1: + if (tag !== 10) { + break + } + + message.marginOut = Coin.decode(reader, reader.uint32()) + continue + case 2: + if (tag !== 18) { + break + } + + message.fundingPayment = reader.string() + continue + case 3: + if (tag !== 26) { + break + } + + message.position = Position.decode(reader, reader.uint32()) + continue + } + if ((tag & 7) === 4 || tag === 0) { + break + } + reader.skipType(tag & 7) + } + return message + }, + + fromJSON(object: any): MsgRemoveMarginResponse { + return { + marginOut: isSet(object.marginOut) + ? Coin.fromJSON(object.marginOut) + : undefined, + fundingPayment: isSet(object.fundingPayment) + ? String(object.fundingPayment) + : "", + position: isSet(object.position) + ? Position.fromJSON(object.position) + : undefined, + } + }, + + toJSON(message: MsgRemoveMarginResponse): unknown { + const obj: any = {} + message.marginOut !== undefined && + (obj.marginOut = message.marginOut + ? Coin.toJSON(message.marginOut) + : undefined) + message.fundingPayment !== undefined && + (obj.fundingPayment = message.fundingPayment) + message.position !== undefined && + (obj.position = message.position + ? Position.toJSON(message.position) + : undefined) + return obj + }, + + create, I>>( + base?: I + ): MsgRemoveMarginResponse { + return MsgRemoveMarginResponse.fromPartial(base ?? {}) + }, + + fromPartial, I>>( + object: I + ): MsgRemoveMarginResponse { + const message = createBaseMsgRemoveMarginResponse() + message.marginOut = + object.marginOut !== undefined && object.marginOut !== null + ? Coin.fromPartial(object.marginOut) + : undefined + message.fundingPayment = object.fundingPayment ?? "" + message.position = + object.position !== undefined && object.position !== null + ? Position.fromPartial(object.position) + : undefined + return message + }, +} + +function createBaseMsgAddMargin(): MsgAddMargin { + return { sender: "", pair: "", margin: undefined } +} + +export const MsgAddMargin = { + encode( + message: MsgAddMargin, + writer: _m0.Writer = _m0.Writer.create() + ): _m0.Writer { + if (message.sender !== "") { + writer.uint32(10).string(message.sender) + } + if (message.pair !== "") { + writer.uint32(18).string(message.pair) + } + if (message.margin !== undefined) { + Coin.encode(message.margin, writer.uint32(26).fork()).ldelim() + } + return writer + }, + + decode(input: _m0.Reader | Uint8Array, length?: number): MsgAddMargin { + const reader = + input instanceof _m0.Reader ? input : _m0.Reader.create(input) + let end = length === undefined ? reader.len : reader.pos + length + const message = createBaseMsgAddMargin() + while (reader.pos < end) { + const tag = reader.uint32() + switch (tag >>> 3) { + case 1: + if (tag !== 10) { + break + } + + message.sender = reader.string() + continue + case 2: + if (tag !== 18) { + break + } + + message.pair = reader.string() + continue + case 3: + if (tag !== 26) { + break + } + + message.margin = Coin.decode(reader, reader.uint32()) + continue + } + if ((tag & 7) === 4 || tag === 0) { + break + } + reader.skipType(tag & 7) + } + return message + }, + + fromJSON(object: any): MsgAddMargin { + return { + sender: isSet(object.sender) ? String(object.sender) : "", + pair: isSet(object.pair) ? String(object.pair) : "", + margin: isSet(object.margin) ? Coin.fromJSON(object.margin) : undefined, + } + }, + + toJSON(message: MsgAddMargin): unknown { + const obj: any = {} + message.sender !== undefined && (obj.sender = message.sender) + message.pair !== undefined && (obj.pair = message.pair) + message.margin !== undefined && + (obj.margin = message.margin ? Coin.toJSON(message.margin) : undefined) + return obj + }, + + create, I>>( + base?: I + ): MsgAddMargin { + return MsgAddMargin.fromPartial(base ?? {}) + }, + + fromPartial, I>>( + object: I + ): MsgAddMargin { + const message = createBaseMsgAddMargin() + message.sender = object.sender ?? "" + message.pair = object.pair ?? "" + message.margin = + object.margin !== undefined && object.margin !== null + ? Coin.fromPartial(object.margin) + : undefined + return message + }, +} + +function createBaseMsgAddMarginResponse(): MsgAddMarginResponse { + return { fundingPayment: "", position: undefined } +} + +export const MsgAddMarginResponse = { + encode( + message: MsgAddMarginResponse, + writer: _m0.Writer = _m0.Writer.create() + ): _m0.Writer { + if (message.fundingPayment !== "") { + writer.uint32(10).string(message.fundingPayment) + } + if (message.position !== undefined) { + Position.encode(message.position, writer.uint32(18).fork()).ldelim() + } + return writer + }, + + decode( + input: _m0.Reader | Uint8Array, + length?: number + ): MsgAddMarginResponse { + const reader = + input instanceof _m0.Reader ? input : _m0.Reader.create(input) + let end = length === undefined ? reader.len : reader.pos + length + const message = createBaseMsgAddMarginResponse() + while (reader.pos < end) { + const tag = reader.uint32() + switch (tag >>> 3) { + case 1: + if (tag !== 10) { + break + } + + message.fundingPayment = reader.string() + continue + case 2: + if (tag !== 18) { + break + } + + message.position = Position.decode(reader, reader.uint32()) + continue + } + if ((tag & 7) === 4 || tag === 0) { + break + } + reader.skipType(tag & 7) + } + return message + }, + + fromJSON(object: any): MsgAddMarginResponse { + return { + fundingPayment: isSet(object.fundingPayment) + ? String(object.fundingPayment) + : "", + position: isSet(object.position) + ? Position.fromJSON(object.position) + : undefined, + } + }, + + toJSON(message: MsgAddMarginResponse): unknown { + const obj: any = {} + message.fundingPayment !== undefined && + (obj.fundingPayment = message.fundingPayment) + message.position !== undefined && + (obj.position = message.position + ? Position.toJSON(message.position) + : undefined) + return obj + }, + + create, I>>( + base?: I + ): MsgAddMarginResponse { + return MsgAddMarginResponse.fromPartial(base ?? {}) + }, + + fromPartial, I>>( + object: I + ): MsgAddMarginResponse { + const message = createBaseMsgAddMarginResponse() + message.fundingPayment = object.fundingPayment ?? "" + message.position = + object.position !== undefined && object.position !== null + ? Position.fromPartial(object.position) + : undefined + return message + }, +} + +function createBaseMsgMultiLiquidate(): MsgMultiLiquidate { + return { sender: "", liquidations: [] } +} + +export const MsgMultiLiquidate = { + encode( + message: MsgMultiLiquidate, + writer: _m0.Writer = _m0.Writer.create() + ): _m0.Writer { + if (message.sender !== "") { + writer.uint32(10).string(message.sender) + } + for (const v of message.liquidations) { + MsgMultiLiquidate_Liquidation.encode( + v!, + writer.uint32(18).fork() + ).ldelim() + } + return writer + }, + + decode(input: _m0.Reader | Uint8Array, length?: number): MsgMultiLiquidate { + const reader = + input instanceof _m0.Reader ? input : _m0.Reader.create(input) + let end = length === undefined ? reader.len : reader.pos + length + const message = createBaseMsgMultiLiquidate() + while (reader.pos < end) { + const tag = reader.uint32() + switch (tag >>> 3) { + case 1: + if (tag !== 10) { + break + } + + message.sender = reader.string() + continue + case 2: + if (tag !== 18) { + break + } + + message.liquidations.push( + MsgMultiLiquidate_Liquidation.decode(reader, reader.uint32()) + ) + continue + } + if ((tag & 7) === 4 || tag === 0) { + break + } + reader.skipType(tag & 7) + } + return message + }, + + fromJSON(object: any): MsgMultiLiquidate { + return { + sender: isSet(object.sender) ? String(object.sender) : "", + liquidations: Array.isArray(object?.liquidations) + ? object.liquidations.map((e: any) => + MsgMultiLiquidate_Liquidation.fromJSON(e) + ) + : [], + } + }, + + toJSON(message: MsgMultiLiquidate): unknown { + const obj: any = {} + message.sender !== undefined && (obj.sender = message.sender) + if (message.liquidations) { + obj.liquidations = message.liquidations.map((e) => + e ? MsgMultiLiquidate_Liquidation.toJSON(e) : undefined + ) + } else { + obj.liquidations = [] + } + return obj + }, + + create, I>>( + base?: I + ): MsgMultiLiquidate { + return MsgMultiLiquidate.fromPartial(base ?? {}) + }, + + fromPartial, I>>( + object: I + ): MsgMultiLiquidate { + const message = createBaseMsgMultiLiquidate() + message.sender = object.sender ?? "" + message.liquidations = + object.liquidations?.map((e) => + MsgMultiLiquidate_Liquidation.fromPartial(e) + ) || [] + return message + }, +} + +function createBaseMsgMultiLiquidate_Liquidation(): MsgMultiLiquidate_Liquidation { + return { pair: "", trader: "" } +} + +export const MsgMultiLiquidate_Liquidation = { + encode( + message: MsgMultiLiquidate_Liquidation, + writer: _m0.Writer = _m0.Writer.create() + ): _m0.Writer { + if (message.pair !== "") { + writer.uint32(10).string(message.pair) + } + if (message.trader !== "") { + writer.uint32(18).string(message.trader) + } + return writer + }, + + decode( + input: _m0.Reader | Uint8Array, + length?: number + ): MsgMultiLiquidate_Liquidation { + const reader = + input instanceof _m0.Reader ? input : _m0.Reader.create(input) + let end = length === undefined ? reader.len : reader.pos + length + const message = createBaseMsgMultiLiquidate_Liquidation() + while (reader.pos < end) { + const tag = reader.uint32() + switch (tag >>> 3) { + case 1: + if (tag !== 10) { + break + } + + message.pair = reader.string() + continue + case 2: + if (tag !== 18) { + break + } + + message.trader = reader.string() + continue + } + if ((tag & 7) === 4 || tag === 0) { + break + } + reader.skipType(tag & 7) + } + return message + }, + + fromJSON(object: any): MsgMultiLiquidate_Liquidation { + return { + pair: isSet(object.pair) ? String(object.pair) : "", + trader: isSet(object.trader) ? String(object.trader) : "", + } + }, + + toJSON(message: MsgMultiLiquidate_Liquidation): unknown { + const obj: any = {} + message.pair !== undefined && (obj.pair = message.pair) + message.trader !== undefined && (obj.trader = message.trader) + return obj + }, + + create, I>>( + base?: I + ): MsgMultiLiquidate_Liquidation { + return MsgMultiLiquidate_Liquidation.fromPartial(base ?? {}) + }, + + fromPartial, I>>( + object: I + ): MsgMultiLiquidate_Liquidation { + const message = createBaseMsgMultiLiquidate_Liquidation() + message.pair = object.pair ?? "" + message.trader = object.trader ?? "" + return message + }, +} + +function createBaseMsgMultiLiquidateResponse(): MsgMultiLiquidateResponse { + return { liquidations: [] } +} + +export const MsgMultiLiquidateResponse = { + encode( + message: MsgMultiLiquidateResponse, + writer: _m0.Writer = _m0.Writer.create() + ): _m0.Writer { + for (const v of message.liquidations) { + MsgMultiLiquidateResponse_LiquidationResponse.encode( + v!, + writer.uint32(10).fork() + ).ldelim() + } + return writer + }, + + decode( + input: _m0.Reader | Uint8Array, + length?: number + ): MsgMultiLiquidateResponse { + const reader = + input instanceof _m0.Reader ? input : _m0.Reader.create(input) + let end = length === undefined ? reader.len : reader.pos + length + const message = createBaseMsgMultiLiquidateResponse() + while (reader.pos < end) { + const tag = reader.uint32() + switch (tag >>> 3) { + case 1: + if (tag !== 10) { + break + } + + message.liquidations.push( + MsgMultiLiquidateResponse_LiquidationResponse.decode( + reader, + reader.uint32() + ) + ) + continue + } + if ((tag & 7) === 4 || tag === 0) { + break + } + reader.skipType(tag & 7) + } + return message + }, + + fromJSON(object: any): MsgMultiLiquidateResponse { + return { + liquidations: Array.isArray(object?.liquidations) + ? object.liquidations.map((e: any) => + MsgMultiLiquidateResponse_LiquidationResponse.fromJSON(e) + ) + : [], + } + }, + + toJSON(message: MsgMultiLiquidateResponse): unknown { + const obj: any = {} + if (message.liquidations) { + obj.liquidations = message.liquidations.map((e) => + e ? MsgMultiLiquidateResponse_LiquidationResponse.toJSON(e) : undefined + ) + } else { + obj.liquidations = [] + } + return obj + }, + + create, I>>( + base?: I + ): MsgMultiLiquidateResponse { + return MsgMultiLiquidateResponse.fromPartial(base ?? {}) + }, + + fromPartial, I>>( + object: I + ): MsgMultiLiquidateResponse { + const message = createBaseMsgMultiLiquidateResponse() + message.liquidations = + object.liquidations?.map((e) => + MsgMultiLiquidateResponse_LiquidationResponse.fromPartial(e) + ) || [] + return message + }, +} + +function createBaseMsgMultiLiquidateResponse_LiquidationResponse(): MsgMultiLiquidateResponse_LiquidationResponse { + return { + success: false, + error: "", + liquidatorFee: undefined, + perpEfFee: undefined, + trader: "", + pair: "", + } +} + +export const MsgMultiLiquidateResponse_LiquidationResponse = { + encode( + message: MsgMultiLiquidateResponse_LiquidationResponse, + writer: _m0.Writer = _m0.Writer.create() + ): _m0.Writer { + if (message.success === true) { + writer.uint32(8).bool(message.success) + } + if (message.error !== "") { + writer.uint32(18).string(message.error) + } + if (message.liquidatorFee !== undefined) { + Coin.encode(message.liquidatorFee, writer.uint32(26).fork()).ldelim() + } + if (message.perpEfFee !== undefined) { + Coin.encode(message.perpEfFee, writer.uint32(34).fork()).ldelim() + } + if (message.trader !== "") { + writer.uint32(42).string(message.trader) + } + if (message.pair !== "") { + writer.uint32(50).string(message.pair) + } + return writer + }, + + decode( + input: _m0.Reader | Uint8Array, + length?: number + ): MsgMultiLiquidateResponse_LiquidationResponse { + const reader = + input instanceof _m0.Reader ? input : _m0.Reader.create(input) + let end = length === undefined ? reader.len : reader.pos + length + const message = createBaseMsgMultiLiquidateResponse_LiquidationResponse() + while (reader.pos < end) { + const tag = reader.uint32() + switch (tag >>> 3) { + case 1: + if (tag !== 8) { + break + } + + message.success = reader.bool() + continue + case 2: + if (tag !== 18) { + break + } + + message.error = reader.string() + continue + case 3: + if (tag !== 26) { + break + } + + message.liquidatorFee = Coin.decode(reader, reader.uint32()) + continue + case 4: + if (tag !== 34) { + break + } + + message.perpEfFee = Coin.decode(reader, reader.uint32()) + continue + case 5: + if (tag !== 42) { + break + } + + message.trader = reader.string() + continue + case 6: + if (tag !== 50) { + break + } + + message.pair = reader.string() + continue + } + if ((tag & 7) === 4 || tag === 0) { + break + } + reader.skipType(tag & 7) + } + return message + }, + + fromJSON(object: any): MsgMultiLiquidateResponse_LiquidationResponse { + return { + success: isSet(object.success) ? Boolean(object.success) : false, + error: isSet(object.error) ? String(object.error) : "", + liquidatorFee: isSet(object.liquidatorFee) + ? Coin.fromJSON(object.liquidatorFee) + : undefined, + perpEfFee: isSet(object.perpEfFee) + ? Coin.fromJSON(object.perpEfFee) + : undefined, + trader: isSet(object.trader) ? String(object.trader) : "", + pair: isSet(object.pair) ? String(object.pair) : "", + } + }, + + toJSON(message: MsgMultiLiquidateResponse_LiquidationResponse): unknown { + const obj: any = {} + message.success !== undefined && (obj.success = message.success) + message.error !== undefined && (obj.error = message.error) + message.liquidatorFee !== undefined && + (obj.liquidatorFee = message.liquidatorFee + ? Coin.toJSON(message.liquidatorFee) + : undefined) + message.perpEfFee !== undefined && + (obj.perpEfFee = message.perpEfFee + ? Coin.toJSON(message.perpEfFee) + : undefined) + message.trader !== undefined && (obj.trader = message.trader) + message.pair !== undefined && (obj.pair = message.pair) + return obj + }, + + create< + I extends Exact< + DeepPartial, + I + > + >(base?: I): MsgMultiLiquidateResponse_LiquidationResponse { + return MsgMultiLiquidateResponse_LiquidationResponse.fromPartial(base ?? {}) + }, + + fromPartial< + I extends Exact< + DeepPartial, + I + > + >(object: I): MsgMultiLiquidateResponse_LiquidationResponse { + const message = createBaseMsgMultiLiquidateResponse_LiquidationResponse() + message.success = object.success ?? false + message.error = object.error ?? "" + message.liquidatorFee = + object.liquidatorFee !== undefined && object.liquidatorFee !== null + ? Coin.fromPartial(object.liquidatorFee) + : undefined + message.perpEfFee = + object.perpEfFee !== undefined && object.perpEfFee !== null + ? Coin.fromPartial(object.perpEfFee) + : undefined + message.trader = object.trader ?? "" + message.pair = object.pair ?? "" + return message + }, +} + +function createBaseMsgMarketOrder(): MsgMarketOrder { + return { + sender: "", + pair: "", + side: 0, + quoteAssetAmount: "", + leverage: "", + baseAssetAmountLimit: "", + } +} + +export const MsgMarketOrder = { + encode( + message: MsgMarketOrder, + writer: _m0.Writer = _m0.Writer.create() + ): _m0.Writer { + if (message.sender !== "") { + writer.uint32(10).string(message.sender) + } + if (message.pair !== "") { + writer.uint32(18).string(message.pair) + } + if (message.side !== 0) { + writer.uint32(24).int32(message.side) + } + if (message.quoteAssetAmount !== "") { + writer.uint32(34).string(message.quoteAssetAmount) + } + if (message.leverage !== "") { + writer.uint32(42).string(message.leverage) + } + if (message.baseAssetAmountLimit !== "") { + writer.uint32(50).string(message.baseAssetAmountLimit) + } + return writer + }, + + decode(input: _m0.Reader | Uint8Array, length?: number): MsgMarketOrder { + const reader = + input instanceof _m0.Reader ? input : _m0.Reader.create(input) + let end = length === undefined ? reader.len : reader.pos + length + const message = createBaseMsgMarketOrder() + while (reader.pos < end) { + const tag = reader.uint32() + switch (tag >>> 3) { + case 1: + if (tag !== 10) { + break + } + + message.sender = reader.string() + continue + case 2: + if (tag !== 18) { + break + } + + message.pair = reader.string() + continue + case 3: + if (tag !== 24) { + break + } + + message.side = reader.int32() as any + continue + case 4: + if (tag !== 34) { + break + } + + message.quoteAssetAmount = reader.string() + continue + case 5: + if (tag !== 42) { + break + } + + message.leverage = reader.string() + continue + case 6: + if (tag !== 50) { + break + } + + message.baseAssetAmountLimit = reader.string() + continue + } + if ((tag & 7) === 4 || tag === 0) { + break + } + reader.skipType(tag & 7) + } + return message + }, + + fromJSON(object: any): MsgMarketOrder { + return { + sender: isSet(object.sender) ? String(object.sender) : "", + pair: isSet(object.pair) ? String(object.pair) : "", + side: isSet(object.side) ? directionFromJSON(object.side) : 0, + quoteAssetAmount: isSet(object.quoteAssetAmount) + ? String(object.quoteAssetAmount) + : "", + leverage: isSet(object.leverage) ? String(object.leverage) : "", + baseAssetAmountLimit: isSet(object.baseAssetAmountLimit) + ? String(object.baseAssetAmountLimit) + : "", + } + }, + + toJSON(message: MsgMarketOrder): unknown { + const obj: any = {} + message.sender !== undefined && (obj.sender = message.sender) + message.pair !== undefined && (obj.pair = message.pair) + message.side !== undefined && (obj.side = directionToJSON(message.side)) + message.quoteAssetAmount !== undefined && + (obj.quoteAssetAmount = message.quoteAssetAmount) + message.leverage !== undefined && (obj.leverage = message.leverage) + message.baseAssetAmountLimit !== undefined && + (obj.baseAssetAmountLimit = message.baseAssetAmountLimit) + return obj + }, + + create, I>>( + base?: I + ): MsgMarketOrder { + return MsgMarketOrder.fromPartial(base ?? {}) + }, + + fromPartial, I>>( + object: I + ): MsgMarketOrder { + const message = createBaseMsgMarketOrder() + message.sender = object.sender ?? "" + message.pair = object.pair ?? "" + message.side = object.side ?? 0 + message.quoteAssetAmount = object.quoteAssetAmount ?? "" + message.leverage = object.leverage ?? "" + message.baseAssetAmountLimit = object.baseAssetAmountLimit ?? "" + return message + }, +} + +function createBaseMsgMarketOrderResponse(): MsgMarketOrderResponse { + return { + position: undefined, + exchangedNotionalValue: "", + exchangedPositionSize: "", + fundingPayment: "", + realizedPnl: "", + unrealizedPnlAfter: "", + marginToVault: "", + positionNotional: "", + } +} + +export const MsgMarketOrderResponse = { + encode( + message: MsgMarketOrderResponse, + writer: _m0.Writer = _m0.Writer.create() + ): _m0.Writer { + if (message.position !== undefined) { + Position.encode(message.position, writer.uint32(10).fork()).ldelim() + } + if (message.exchangedNotionalValue !== "") { + writer.uint32(18).string(message.exchangedNotionalValue) + } + if (message.exchangedPositionSize !== "") { + writer.uint32(26).string(message.exchangedPositionSize) + } + if (message.fundingPayment !== "") { + writer.uint32(34).string(message.fundingPayment) + } + if (message.realizedPnl !== "") { + writer.uint32(42).string(message.realizedPnl) + } + if (message.unrealizedPnlAfter !== "") { + writer.uint32(50).string(message.unrealizedPnlAfter) + } + if (message.marginToVault !== "") { + writer.uint32(58).string(message.marginToVault) + } + if (message.positionNotional !== "") { + writer.uint32(66).string(message.positionNotional) + } + return writer + }, + + decode( + input: _m0.Reader | Uint8Array, + length?: number + ): MsgMarketOrderResponse { + const reader = + input instanceof _m0.Reader ? input : _m0.Reader.create(input) + let end = length === undefined ? reader.len : reader.pos + length + const message = createBaseMsgMarketOrderResponse() + while (reader.pos < end) { + const tag = reader.uint32() + switch (tag >>> 3) { + case 1: + if (tag !== 10) { + break + } + + message.position = Position.decode(reader, reader.uint32()) + continue + case 2: + if (tag !== 18) { + break + } + + message.exchangedNotionalValue = reader.string() + continue + case 3: + if (tag !== 26) { + break + } + + message.exchangedPositionSize = reader.string() + continue + case 4: + if (tag !== 34) { + break + } + + message.fundingPayment = reader.string() + continue + case 5: + if (tag !== 42) { + break + } + + message.realizedPnl = reader.string() + continue + case 6: + if (tag !== 50) { + break + } + + message.unrealizedPnlAfter = reader.string() + continue + case 7: + if (tag !== 58) { + break + } + + message.marginToVault = reader.string() + continue + case 8: + if (tag !== 66) { + break + } + + message.positionNotional = reader.string() + continue + } + if ((tag & 7) === 4 || tag === 0) { + break + } + reader.skipType(tag & 7) + } + return message + }, + + fromJSON(object: any): MsgMarketOrderResponse { + return { + position: isSet(object.position) + ? Position.fromJSON(object.position) + : undefined, + exchangedNotionalValue: isSet(object.exchangedNotionalValue) + ? String(object.exchangedNotionalValue) + : "", + exchangedPositionSize: isSet(object.exchangedPositionSize) + ? String(object.exchangedPositionSize) + : "", + fundingPayment: isSet(object.fundingPayment) + ? String(object.fundingPayment) + : "", + realizedPnl: isSet(object.realizedPnl) ? String(object.realizedPnl) : "", + unrealizedPnlAfter: isSet(object.unrealizedPnlAfter) + ? String(object.unrealizedPnlAfter) + : "", + marginToVault: isSet(object.marginToVault) + ? String(object.marginToVault) + : "", + positionNotional: isSet(object.positionNotional) + ? String(object.positionNotional) + : "", + } + }, + + toJSON(message: MsgMarketOrderResponse): unknown { + const obj: any = {} + message.position !== undefined && + (obj.position = message.position + ? Position.toJSON(message.position) + : undefined) + message.exchangedNotionalValue !== undefined && + (obj.exchangedNotionalValue = message.exchangedNotionalValue) + message.exchangedPositionSize !== undefined && + (obj.exchangedPositionSize = message.exchangedPositionSize) + message.fundingPayment !== undefined && + (obj.fundingPayment = message.fundingPayment) + message.realizedPnl !== undefined && (obj.realizedPnl = message.realizedPnl) + message.unrealizedPnlAfter !== undefined && + (obj.unrealizedPnlAfter = message.unrealizedPnlAfter) + message.marginToVault !== undefined && + (obj.marginToVault = message.marginToVault) + message.positionNotional !== undefined && + (obj.positionNotional = message.positionNotional) + return obj + }, + + create, I>>( + base?: I + ): MsgMarketOrderResponse { + return MsgMarketOrderResponse.fromPartial(base ?? {}) + }, + + fromPartial, I>>( + object: I + ): MsgMarketOrderResponse { + const message = createBaseMsgMarketOrderResponse() + message.position = + object.position !== undefined && object.position !== null + ? Position.fromPartial(object.position) + : undefined + message.exchangedNotionalValue = object.exchangedNotionalValue ?? "" + message.exchangedPositionSize = object.exchangedPositionSize ?? "" + message.fundingPayment = object.fundingPayment ?? "" + message.realizedPnl = object.realizedPnl ?? "" + message.unrealizedPnlAfter = object.unrealizedPnlAfter ?? "" + message.marginToVault = object.marginToVault ?? "" + message.positionNotional = object.positionNotional ?? "" + return message + }, +} + +function createBaseMsgClosePosition(): MsgClosePosition { + return { sender: "", pair: "" } +} + +export const MsgClosePosition = { + encode( + message: MsgClosePosition, + writer: _m0.Writer = _m0.Writer.create() + ): _m0.Writer { + if (message.sender !== "") { + writer.uint32(10).string(message.sender) + } + if (message.pair !== "") { + writer.uint32(18).string(message.pair) + } + return writer + }, + + decode(input: _m0.Reader | Uint8Array, length?: number): MsgClosePosition { + const reader = + input instanceof _m0.Reader ? input : _m0.Reader.create(input) + let end = length === undefined ? reader.len : reader.pos + length + const message = createBaseMsgClosePosition() + while (reader.pos < end) { + const tag = reader.uint32() + switch (tag >>> 3) { + case 1: + if (tag !== 10) { + break + } + + message.sender = reader.string() + continue + case 2: + if (tag !== 18) { + break + } + + message.pair = reader.string() + continue + } + if ((tag & 7) === 4 || tag === 0) { + break + } + reader.skipType(tag & 7) + } + return message + }, + + fromJSON(object: any): MsgClosePosition { + return { + sender: isSet(object.sender) ? String(object.sender) : "", + pair: isSet(object.pair) ? String(object.pair) : "", + } + }, + + toJSON(message: MsgClosePosition): unknown { + const obj: any = {} + message.sender !== undefined && (obj.sender = message.sender) + message.pair !== undefined && (obj.pair = message.pair) + return obj + }, + + create, I>>( + base?: I + ): MsgClosePosition { + return MsgClosePosition.fromPartial(base ?? {}) + }, + + fromPartial, I>>( + object: I + ): MsgClosePosition { + const message = createBaseMsgClosePosition() + message.sender = object.sender ?? "" + message.pair = object.pair ?? "" + return message + }, +} + +function createBaseMsgClosePositionResponse(): MsgClosePositionResponse { + return { + exchangedNotionalValue: "", + exchangedPositionSize: "", + fundingPayment: "", + realizedPnl: "", + marginToTrader: "", + } +} + +export const MsgClosePositionResponse = { + encode( + message: MsgClosePositionResponse, + writer: _m0.Writer = _m0.Writer.create() + ): _m0.Writer { + if (message.exchangedNotionalValue !== "") { + writer.uint32(10).string(message.exchangedNotionalValue) + } + if (message.exchangedPositionSize !== "") { + writer.uint32(18).string(message.exchangedPositionSize) + } + if (message.fundingPayment !== "") { + writer.uint32(26).string(message.fundingPayment) + } + if (message.realizedPnl !== "") { + writer.uint32(34).string(message.realizedPnl) + } + if (message.marginToTrader !== "") { + writer.uint32(42).string(message.marginToTrader) + } + return writer + }, + + decode( + input: _m0.Reader | Uint8Array, + length?: number + ): MsgClosePositionResponse { + const reader = + input instanceof _m0.Reader ? input : _m0.Reader.create(input) + let end = length === undefined ? reader.len : reader.pos + length + const message = createBaseMsgClosePositionResponse() + while (reader.pos < end) { + const tag = reader.uint32() + switch (tag >>> 3) { + case 1: + if (tag !== 10) { + break + } + + message.exchangedNotionalValue = reader.string() + continue + case 2: + if (tag !== 18) { + break + } + + message.exchangedPositionSize = reader.string() + continue + case 3: + if (tag !== 26) { + break + } + + message.fundingPayment = reader.string() + continue + case 4: + if (tag !== 34) { + break + } + + message.realizedPnl = reader.string() + continue + case 5: + if (tag !== 42) { + break + } + + message.marginToTrader = reader.string() + continue + } + if ((tag & 7) === 4 || tag === 0) { + break + } + reader.skipType(tag & 7) + } + return message + }, + + fromJSON(object: any): MsgClosePositionResponse { + return { + exchangedNotionalValue: isSet(object.exchangedNotionalValue) + ? String(object.exchangedNotionalValue) + : "", + exchangedPositionSize: isSet(object.exchangedPositionSize) + ? String(object.exchangedPositionSize) + : "", + fundingPayment: isSet(object.fundingPayment) + ? String(object.fundingPayment) + : "", + realizedPnl: isSet(object.realizedPnl) ? String(object.realizedPnl) : "", + marginToTrader: isSet(object.marginToTrader) + ? String(object.marginToTrader) + : "", + } + }, + + toJSON(message: MsgClosePositionResponse): unknown { + const obj: any = {} + message.exchangedNotionalValue !== undefined && + (obj.exchangedNotionalValue = message.exchangedNotionalValue) + message.exchangedPositionSize !== undefined && + (obj.exchangedPositionSize = message.exchangedPositionSize) + message.fundingPayment !== undefined && + (obj.fundingPayment = message.fundingPayment) + message.realizedPnl !== undefined && (obj.realizedPnl = message.realizedPnl) + message.marginToTrader !== undefined && + (obj.marginToTrader = message.marginToTrader) + return obj + }, + + create, I>>( + base?: I + ): MsgClosePositionResponse { + return MsgClosePositionResponse.fromPartial(base ?? {}) + }, + + fromPartial, I>>( + object: I + ): MsgClosePositionResponse { + const message = createBaseMsgClosePositionResponse() + message.exchangedNotionalValue = object.exchangedNotionalValue ?? "" + message.exchangedPositionSize = object.exchangedPositionSize ?? "" + message.fundingPayment = object.fundingPayment ?? "" + message.realizedPnl = object.realizedPnl ?? "" + message.marginToTrader = object.marginToTrader ?? "" + return message + }, +} + +function createBaseMsgPartialClose(): MsgPartialClose { + return { sender: "", pair: "", size: "" } +} + +export const MsgPartialClose = { + encode( + message: MsgPartialClose, + writer: _m0.Writer = _m0.Writer.create() + ): _m0.Writer { + if (message.sender !== "") { + writer.uint32(10).string(message.sender) + } + if (message.pair !== "") { + writer.uint32(18).string(message.pair) + } + if (message.size !== "") { + writer.uint32(26).string(message.size) + } + return writer + }, + + decode(input: _m0.Reader | Uint8Array, length?: number): MsgPartialClose { + const reader = + input instanceof _m0.Reader ? input : _m0.Reader.create(input) + let end = length === undefined ? reader.len : reader.pos + length + const message = createBaseMsgPartialClose() + while (reader.pos < end) { + const tag = reader.uint32() + switch (tag >>> 3) { + case 1: + if (tag !== 10) { + break + } + + message.sender = reader.string() + continue + case 2: + if (tag !== 18) { + break + } + + message.pair = reader.string() + continue + case 3: + if (tag !== 26) { + break + } + + message.size = reader.string() + continue + } + if ((tag & 7) === 4 || tag === 0) { + break + } + reader.skipType(tag & 7) + } + return message + }, + + fromJSON(object: any): MsgPartialClose { + return { + sender: isSet(object.sender) ? String(object.sender) : "", + pair: isSet(object.pair) ? String(object.pair) : "", + size: isSet(object.size) ? String(object.size) : "", + } + }, + + toJSON(message: MsgPartialClose): unknown { + const obj: any = {} + message.sender !== undefined && (obj.sender = message.sender) + message.pair !== undefined && (obj.pair = message.pair) + message.size !== undefined && (obj.size = message.size) + return obj + }, + + create, I>>( + base?: I + ): MsgPartialClose { + return MsgPartialClose.fromPartial(base ?? {}) + }, + + fromPartial, I>>( + object: I + ): MsgPartialClose { + const message = createBaseMsgPartialClose() + message.sender = object.sender ?? "" + message.pair = object.pair ?? "" + message.size = object.size ?? "" + return message + }, +} + +function createBaseMsgPartialCloseResponse(): MsgPartialCloseResponse { + return { + exchangedNotionalValue: "", + exchangedPositionSize: "", + fundingPayment: "", + realizedPnl: "", + marginToTrader: "", + } +} + +export const MsgPartialCloseResponse = { + encode( + message: MsgPartialCloseResponse, + writer: _m0.Writer = _m0.Writer.create() + ): _m0.Writer { + if (message.exchangedNotionalValue !== "") { + writer.uint32(10).string(message.exchangedNotionalValue) + } + if (message.exchangedPositionSize !== "") { + writer.uint32(18).string(message.exchangedPositionSize) + } + if (message.fundingPayment !== "") { + writer.uint32(26).string(message.fundingPayment) + } + if (message.realizedPnl !== "") { + writer.uint32(34).string(message.realizedPnl) + } + if (message.marginToTrader !== "") { + writer.uint32(42).string(message.marginToTrader) + } + return writer + }, + + decode( + input: _m0.Reader | Uint8Array, + length?: number + ): MsgPartialCloseResponse { + const reader = + input instanceof _m0.Reader ? input : _m0.Reader.create(input) + let end = length === undefined ? reader.len : reader.pos + length + const message = createBaseMsgPartialCloseResponse() + while (reader.pos < end) { + const tag = reader.uint32() + switch (tag >>> 3) { + case 1: + if (tag !== 10) { + break + } + + message.exchangedNotionalValue = reader.string() + continue + case 2: + if (tag !== 18) { + break + } + + message.exchangedPositionSize = reader.string() + continue + case 3: + if (tag !== 26) { + break + } + + message.fundingPayment = reader.string() + continue + case 4: + if (tag !== 34) { + break + } + + message.realizedPnl = reader.string() + continue + case 5: + if (tag !== 42) { + break + } + + message.marginToTrader = reader.string() + continue + } + if ((tag & 7) === 4 || tag === 0) { + break + } + reader.skipType(tag & 7) + } + return message + }, + + fromJSON(object: any): MsgPartialCloseResponse { + return { + exchangedNotionalValue: isSet(object.exchangedNotionalValue) + ? String(object.exchangedNotionalValue) + : "", + exchangedPositionSize: isSet(object.exchangedPositionSize) + ? String(object.exchangedPositionSize) + : "", + fundingPayment: isSet(object.fundingPayment) + ? String(object.fundingPayment) + : "", + realizedPnl: isSet(object.realizedPnl) ? String(object.realizedPnl) : "", + marginToTrader: isSet(object.marginToTrader) + ? String(object.marginToTrader) + : "", + } + }, + + toJSON(message: MsgPartialCloseResponse): unknown { + const obj: any = {} + message.exchangedNotionalValue !== undefined && + (obj.exchangedNotionalValue = message.exchangedNotionalValue) + message.exchangedPositionSize !== undefined && + (obj.exchangedPositionSize = message.exchangedPositionSize) + message.fundingPayment !== undefined && + (obj.fundingPayment = message.fundingPayment) + message.realizedPnl !== undefined && (obj.realizedPnl = message.realizedPnl) + message.marginToTrader !== undefined && + (obj.marginToTrader = message.marginToTrader) + return obj + }, + + create, I>>( + base?: I + ): MsgPartialCloseResponse { + return MsgPartialCloseResponse.fromPartial(base ?? {}) + }, + + fromPartial, I>>( + object: I + ): MsgPartialCloseResponse { + const message = createBaseMsgPartialCloseResponse() + message.exchangedNotionalValue = object.exchangedNotionalValue ?? "" + message.exchangedPositionSize = object.exchangedPositionSize ?? "" + message.fundingPayment = object.fundingPayment ?? "" + message.realizedPnl = object.realizedPnl ?? "" + message.marginToTrader = object.marginToTrader ?? "" + return message + }, +} + +function createBaseMsgDonateToEcosystemFund(): MsgDonateToEcosystemFund { + return { sender: "", donation: undefined } +} + +export const MsgDonateToEcosystemFund = { + encode( + message: MsgDonateToEcosystemFund, + writer: _m0.Writer = _m0.Writer.create() + ): _m0.Writer { + if (message.sender !== "") { + writer.uint32(10).string(message.sender) + } + if (message.donation !== undefined) { + Coin.encode(message.donation, writer.uint32(18).fork()).ldelim() + } + return writer + }, + + decode( + input: _m0.Reader | Uint8Array, + length?: number + ): MsgDonateToEcosystemFund { + const reader = + input instanceof _m0.Reader ? input : _m0.Reader.create(input) + let end = length === undefined ? reader.len : reader.pos + length + const message = createBaseMsgDonateToEcosystemFund() + while (reader.pos < end) { + const tag = reader.uint32() + switch (tag >>> 3) { + case 1: + if (tag !== 10) { + break + } + + message.sender = reader.string() + continue + case 2: + if (tag !== 18) { + break + } + + message.donation = Coin.decode(reader, reader.uint32()) + continue + } + if ((tag & 7) === 4 || tag === 0) { + break + } + reader.skipType(tag & 7) + } + return message + }, + + fromJSON(object: any): MsgDonateToEcosystemFund { + return { + sender: isSet(object.sender) ? String(object.sender) : "", + donation: isSet(object.donation) + ? Coin.fromJSON(object.donation) + : undefined, + } + }, + + toJSON(message: MsgDonateToEcosystemFund): unknown { + const obj: any = {} + message.sender !== undefined && (obj.sender = message.sender) + message.donation !== undefined && + (obj.donation = message.donation + ? Coin.toJSON(message.donation) + : undefined) + return obj + }, + + create, I>>( + base?: I + ): MsgDonateToEcosystemFund { + return MsgDonateToEcosystemFund.fromPartial(base ?? {}) + }, + + fromPartial, I>>( + object: I + ): MsgDonateToEcosystemFund { + const message = createBaseMsgDonateToEcosystemFund() + message.sender = object.sender ?? "" + message.donation = + object.donation !== undefined && object.donation !== null + ? Coin.fromPartial(object.donation) + : undefined + return message + }, +} + +function createBaseMsgDonateToEcosystemFundResponse(): MsgDonateToEcosystemFundResponse { + return {} +} + +export const MsgDonateToEcosystemFundResponse = { + encode( + _: MsgDonateToEcosystemFundResponse, + writer: _m0.Writer = _m0.Writer.create() + ): _m0.Writer { + return writer + }, + + decode( + input: _m0.Reader | Uint8Array, + length?: number + ): MsgDonateToEcosystemFundResponse { + const reader = + input instanceof _m0.Reader ? input : _m0.Reader.create(input) + let end = length === undefined ? reader.len : reader.pos + length + const message = createBaseMsgDonateToEcosystemFundResponse() + while (reader.pos < end) { + const tag = reader.uint32() + switch (tag >>> 3) { + } + if ((tag & 7) === 4 || tag === 0) { + break + } + reader.skipType(tag & 7) + } + return message + }, + + fromJSON(_: any): MsgDonateToEcosystemFundResponse { + return {} + }, + + toJSON(_: MsgDonateToEcosystemFundResponse): unknown { + const obj: any = {} + return obj + }, + + create, I>>( + base?: I + ): MsgDonateToEcosystemFundResponse { + return MsgDonateToEcosystemFundResponse.fromPartial(base ?? {}) + }, + + fromPartial< + I extends Exact, I> + >(_: I): MsgDonateToEcosystemFundResponse { + const message = createBaseMsgDonateToEcosystemFundResponse() + return message + }, +} + +/** Msg defines the x/perp Msg service. */ +export interface Msg { + RemoveMargin(request: MsgRemoveMargin): Promise + AddMargin(request: MsgAddMargin): Promise + MultiLiquidate(request: MsgMultiLiquidate): Promise + MarketOrder(request: MsgMarketOrder): Promise + ClosePosition(request: MsgClosePosition): Promise + PartialClose(request: MsgPartialClose): Promise + DonateToEcosystemFund( + request: MsgDonateToEcosystemFund + ): Promise +} + +export const MsgServiceName = "nibiru.perp.v2.Msg" +export class MsgClientImpl implements Msg { + private readonly rpc: Rpc + private readonly service: string + constructor(rpc: Rpc, opts?: { service?: string }) { + this.service = opts?.service || MsgServiceName + this.rpc = rpc + this.RemoveMargin = this.RemoveMargin.bind(this) + this.AddMargin = this.AddMargin.bind(this) + this.MultiLiquidate = this.MultiLiquidate.bind(this) + this.MarketOrder = this.MarketOrder.bind(this) + this.ClosePosition = this.ClosePosition.bind(this) + this.PartialClose = this.PartialClose.bind(this) + this.DonateToEcosystemFund = this.DonateToEcosystemFund.bind(this) + } + RemoveMargin(request: MsgRemoveMargin): Promise { + const data = MsgRemoveMargin.encode(request).finish() + const promise = this.rpc.request(this.service, "RemoveMargin", data) + return promise.then((data) => + MsgRemoveMarginResponse.decode(_m0.Reader.create(data)) + ) + } + + AddMargin(request: MsgAddMargin): Promise { + const data = MsgAddMargin.encode(request).finish() + const promise = this.rpc.request(this.service, "AddMargin", data) + return promise.then((data) => + MsgAddMarginResponse.decode(_m0.Reader.create(data)) + ) + } + + MultiLiquidate( + request: MsgMultiLiquidate + ): Promise { + const data = MsgMultiLiquidate.encode(request).finish() + const promise = this.rpc.request(this.service, "MultiLiquidate", data) + return promise.then((data) => + MsgMultiLiquidateResponse.decode(_m0.Reader.create(data)) + ) + } + + MarketOrder(request: MsgMarketOrder): Promise { + const data = MsgMarketOrder.encode(request).finish() + const promise = this.rpc.request(this.service, "MarketOrder", data) + return promise.then((data) => + MsgMarketOrderResponse.decode(_m0.Reader.create(data)) + ) + } + + ClosePosition(request: MsgClosePosition): Promise { + const data = MsgClosePosition.encode(request).finish() + const promise = this.rpc.request(this.service, "ClosePosition", data) + return promise.then((data) => + MsgClosePositionResponse.decode(_m0.Reader.create(data)) + ) + } + + PartialClose(request: MsgPartialClose): Promise { + const data = MsgPartialClose.encode(request).finish() + const promise = this.rpc.request(this.service, "PartialClose", data) + return promise.then((data) => + MsgPartialCloseResponse.decode(_m0.Reader.create(data)) + ) + } + + DonateToEcosystemFund( + request: MsgDonateToEcosystemFund + ): Promise { + const data = MsgDonateToEcosystemFund.encode(request).finish() + const promise = this.rpc.request( + this.service, + "DonateToEcosystemFund", + data + ) + return promise.then((data) => + MsgDonateToEcosystemFundResponse.decode(_m0.Reader.create(data)) + ) + } +} + +interface Rpc { + request( + service: string, + method: string, + data: Uint8Array + ): Promise +} + +type Builtin = + | Date + | Function + | Uint8Array + | string + | number + | boolean + | undefined + +export type DeepPartial = T extends Builtin + ? T + : T extends Long + ? string | number | Long + : T extends Array + ? Array> + : T extends ReadonlyArray + ? ReadonlyArray> + : T extends {} + ? { [K in keyof T]?: DeepPartial } + : Partial + +type KeysOfUnion = T extends T ? keyof T : never +export type Exact = P extends Builtin + ? P + : P & { [K in keyof P]: Exact } & { + [K in Exclude>]: never + } + +if (_m0.util.Long !== Long) { + _m0.util.Long = Long as any + _m0.configure() +} + +function isSet(value: any): boolean { + return value !== null && value !== undefined +} diff --git a/packages/protojs/src/nibiru/spot/v1/event.ts b/packages/protojs/src/nibiru/spot/v1/event.ts new file mode 100644 index 00000000..4cbdbf9b --- /dev/null +++ b/packages/protojs/src/nibiru/spot/v1/event.ts @@ -0,0 +1,746 @@ +/* eslint-disable */ +import Long from "long" +import _m0 from "protobufjs/minimal" +import { Coin } from "../../../cosmos/base/v1beta1/coin" +import { Pool } from "./pool" + +export const protobufPackage = "nibiru.spot.v1" + +export interface EventPoolCreated { + /** the address of the user who created the pool */ + creator: string + /** the create pool fee */ + fees: Coin[] + /** the final state of the pool */ + finalPool?: Pool + /** the amount of pool shares that the user received */ + finalUserPoolShares?: Coin +} + +export interface EventPoolJoined { + /** the address of the user who joined the pool */ + address: string + /** the amount of tokens that the user deposited */ + tokensIn: Coin[] + /** the amount of pool shares that the user received */ + poolSharesOut?: Coin + /** the amount of tokens remaining for the user */ + remCoins: Coin[] + /** the final state of the pool */ + finalPool?: Pool + /** the final amount of user pool shares */ + finalUserPoolShares?: Coin +} + +export interface EventPoolExited { + /** the address of the user who exited the pool */ + address: string + /** the amount of pool shares that the user exited with */ + poolSharesIn?: Coin + /** the amount of tokens returned to the user */ + tokensOut: Coin[] + /** the amount of fees collected by the pool */ + fees: Coin[] + /** the final state of the pool */ + finalPool?: Pool + /** the final amount of user pool shares */ + finalUserPoolShares?: Coin +} + +export interface EventAssetsSwapped { + /** the address of the user who swapped tokens */ + address: string + /** the amount of tokens that the user deposited */ + tokenIn?: Coin + /** the amount of tokens that the user received */ + tokenOut?: Coin + /** the amount of fees collected by the pool */ + fee?: Coin + /** the final state of the pool */ + finalPool?: Pool +} + +function createBaseEventPoolCreated(): EventPoolCreated { + return { + creator: "", + fees: [], + finalPool: undefined, + finalUserPoolShares: undefined, + } +} + +export const EventPoolCreated = { + encode( + message: EventPoolCreated, + writer: _m0.Writer = _m0.Writer.create() + ): _m0.Writer { + if (message.creator !== "") { + writer.uint32(10).string(message.creator) + } + for (const v of message.fees) { + Coin.encode(v!, writer.uint32(18).fork()).ldelim() + } + if (message.finalPool !== undefined) { + Pool.encode(message.finalPool, writer.uint32(34).fork()).ldelim() + } + if (message.finalUserPoolShares !== undefined) { + Coin.encode( + message.finalUserPoolShares, + writer.uint32(42).fork() + ).ldelim() + } + return writer + }, + + decode(input: _m0.Reader | Uint8Array, length?: number): EventPoolCreated { + const reader = + input instanceof _m0.Reader ? input : _m0.Reader.create(input) + let end = length === undefined ? reader.len : reader.pos + length + const message = createBaseEventPoolCreated() + while (reader.pos < end) { + const tag = reader.uint32() + switch (tag >>> 3) { + case 1: + if (tag !== 10) { + break + } + + message.creator = reader.string() + continue + case 2: + if (tag !== 18) { + break + } + + message.fees.push(Coin.decode(reader, reader.uint32())) + continue + case 4: + if (tag !== 34) { + break + } + + message.finalPool = Pool.decode(reader, reader.uint32()) + continue + case 5: + if (tag !== 42) { + break + } + + message.finalUserPoolShares = Coin.decode(reader, reader.uint32()) + continue + } + if ((tag & 7) === 4 || tag === 0) { + break + } + reader.skipType(tag & 7) + } + return message + }, + + fromJSON(object: any): EventPoolCreated { + return { + creator: isSet(object.creator) ? String(object.creator) : "", + fees: Array.isArray(object?.fees) + ? object.fees.map((e: any) => Coin.fromJSON(e)) + : [], + finalPool: isSet(object.finalPool) + ? Pool.fromJSON(object.finalPool) + : undefined, + finalUserPoolShares: isSet(object.finalUserPoolShares) + ? Coin.fromJSON(object.finalUserPoolShares) + : undefined, + } + }, + + toJSON(message: EventPoolCreated): unknown { + const obj: any = {} + message.creator !== undefined && (obj.creator = message.creator) + if (message.fees) { + obj.fees = message.fees.map((e) => (e ? Coin.toJSON(e) : undefined)) + } else { + obj.fees = [] + } + message.finalPool !== undefined && + (obj.finalPool = message.finalPool + ? Pool.toJSON(message.finalPool) + : undefined) + message.finalUserPoolShares !== undefined && + (obj.finalUserPoolShares = message.finalUserPoolShares + ? Coin.toJSON(message.finalUserPoolShares) + : undefined) + return obj + }, + + create, I>>( + base?: I + ): EventPoolCreated { + return EventPoolCreated.fromPartial(base ?? {}) + }, + + fromPartial, I>>( + object: I + ): EventPoolCreated { + const message = createBaseEventPoolCreated() + message.creator = object.creator ?? "" + message.fees = object.fees?.map((e) => Coin.fromPartial(e)) || [] + message.finalPool = + object.finalPool !== undefined && object.finalPool !== null + ? Pool.fromPartial(object.finalPool) + : undefined + message.finalUserPoolShares = + object.finalUserPoolShares !== undefined && + object.finalUserPoolShares !== null + ? Coin.fromPartial(object.finalUserPoolShares) + : undefined + return message + }, +} + +function createBaseEventPoolJoined(): EventPoolJoined { + return { + address: "", + tokensIn: [], + poolSharesOut: undefined, + remCoins: [], + finalPool: undefined, + finalUserPoolShares: undefined, + } +} + +export const EventPoolJoined = { + encode( + message: EventPoolJoined, + writer: _m0.Writer = _m0.Writer.create() + ): _m0.Writer { + if (message.address !== "") { + writer.uint32(10).string(message.address) + } + for (const v of message.tokensIn) { + Coin.encode(v!, writer.uint32(18).fork()).ldelim() + } + if (message.poolSharesOut !== undefined) { + Coin.encode(message.poolSharesOut, writer.uint32(26).fork()).ldelim() + } + for (const v of message.remCoins) { + Coin.encode(v!, writer.uint32(34).fork()).ldelim() + } + if (message.finalPool !== undefined) { + Pool.encode(message.finalPool, writer.uint32(42).fork()).ldelim() + } + if (message.finalUserPoolShares !== undefined) { + Coin.encode( + message.finalUserPoolShares, + writer.uint32(50).fork() + ).ldelim() + } + return writer + }, + + decode(input: _m0.Reader | Uint8Array, length?: number): EventPoolJoined { + const reader = + input instanceof _m0.Reader ? input : _m0.Reader.create(input) + let end = length === undefined ? reader.len : reader.pos + length + const message = createBaseEventPoolJoined() + while (reader.pos < end) { + const tag = reader.uint32() + switch (tag >>> 3) { + case 1: + if (tag !== 10) { + break + } + + message.address = reader.string() + continue + case 2: + if (tag !== 18) { + break + } + + message.tokensIn.push(Coin.decode(reader, reader.uint32())) + continue + case 3: + if (tag !== 26) { + break + } + + message.poolSharesOut = Coin.decode(reader, reader.uint32()) + continue + case 4: + if (tag !== 34) { + break + } + + message.remCoins.push(Coin.decode(reader, reader.uint32())) + continue + case 5: + if (tag !== 42) { + break + } + + message.finalPool = Pool.decode(reader, reader.uint32()) + continue + case 6: + if (tag !== 50) { + break + } + + message.finalUserPoolShares = Coin.decode(reader, reader.uint32()) + continue + } + if ((tag & 7) === 4 || tag === 0) { + break + } + reader.skipType(tag & 7) + } + return message + }, + + fromJSON(object: any): EventPoolJoined { + return { + address: isSet(object.address) ? String(object.address) : "", + tokensIn: Array.isArray(object?.tokensIn) + ? object.tokensIn.map((e: any) => Coin.fromJSON(e)) + : [], + poolSharesOut: isSet(object.poolSharesOut) + ? Coin.fromJSON(object.poolSharesOut) + : undefined, + remCoins: Array.isArray(object?.remCoins) + ? object.remCoins.map((e: any) => Coin.fromJSON(e)) + : [], + finalPool: isSet(object.finalPool) + ? Pool.fromJSON(object.finalPool) + : undefined, + finalUserPoolShares: isSet(object.finalUserPoolShares) + ? Coin.fromJSON(object.finalUserPoolShares) + : undefined, + } + }, + + toJSON(message: EventPoolJoined): unknown { + const obj: any = {} + message.address !== undefined && (obj.address = message.address) + if (message.tokensIn) { + obj.tokensIn = message.tokensIn.map((e) => + e ? Coin.toJSON(e) : undefined + ) + } else { + obj.tokensIn = [] + } + message.poolSharesOut !== undefined && + (obj.poolSharesOut = message.poolSharesOut + ? Coin.toJSON(message.poolSharesOut) + : undefined) + if (message.remCoins) { + obj.remCoins = message.remCoins.map((e) => + e ? Coin.toJSON(e) : undefined + ) + } else { + obj.remCoins = [] + } + message.finalPool !== undefined && + (obj.finalPool = message.finalPool + ? Pool.toJSON(message.finalPool) + : undefined) + message.finalUserPoolShares !== undefined && + (obj.finalUserPoolShares = message.finalUserPoolShares + ? Coin.toJSON(message.finalUserPoolShares) + : undefined) + return obj + }, + + create, I>>( + base?: I + ): EventPoolJoined { + return EventPoolJoined.fromPartial(base ?? {}) + }, + + fromPartial, I>>( + object: I + ): EventPoolJoined { + const message = createBaseEventPoolJoined() + message.address = object.address ?? "" + message.tokensIn = object.tokensIn?.map((e) => Coin.fromPartial(e)) || [] + message.poolSharesOut = + object.poolSharesOut !== undefined && object.poolSharesOut !== null + ? Coin.fromPartial(object.poolSharesOut) + : undefined + message.remCoins = object.remCoins?.map((e) => Coin.fromPartial(e)) || [] + message.finalPool = + object.finalPool !== undefined && object.finalPool !== null + ? Pool.fromPartial(object.finalPool) + : undefined + message.finalUserPoolShares = + object.finalUserPoolShares !== undefined && + object.finalUserPoolShares !== null + ? Coin.fromPartial(object.finalUserPoolShares) + : undefined + return message + }, +} + +function createBaseEventPoolExited(): EventPoolExited { + return { + address: "", + poolSharesIn: undefined, + tokensOut: [], + fees: [], + finalPool: undefined, + finalUserPoolShares: undefined, + } +} + +export const EventPoolExited = { + encode( + message: EventPoolExited, + writer: _m0.Writer = _m0.Writer.create() + ): _m0.Writer { + if (message.address !== "") { + writer.uint32(10).string(message.address) + } + if (message.poolSharesIn !== undefined) { + Coin.encode(message.poolSharesIn, writer.uint32(18).fork()).ldelim() + } + for (const v of message.tokensOut) { + Coin.encode(v!, writer.uint32(26).fork()).ldelim() + } + for (const v of message.fees) { + Coin.encode(v!, writer.uint32(34).fork()).ldelim() + } + if (message.finalPool !== undefined) { + Pool.encode(message.finalPool, writer.uint32(42).fork()).ldelim() + } + if (message.finalUserPoolShares !== undefined) { + Coin.encode( + message.finalUserPoolShares, + writer.uint32(50).fork() + ).ldelim() + } + return writer + }, + + decode(input: _m0.Reader | Uint8Array, length?: number): EventPoolExited { + const reader = + input instanceof _m0.Reader ? input : _m0.Reader.create(input) + let end = length === undefined ? reader.len : reader.pos + length + const message = createBaseEventPoolExited() + while (reader.pos < end) { + const tag = reader.uint32() + switch (tag >>> 3) { + case 1: + if (tag !== 10) { + break + } + + message.address = reader.string() + continue + case 2: + if (tag !== 18) { + break + } + + message.poolSharesIn = Coin.decode(reader, reader.uint32()) + continue + case 3: + if (tag !== 26) { + break + } + + message.tokensOut.push(Coin.decode(reader, reader.uint32())) + continue + case 4: + if (tag !== 34) { + break + } + + message.fees.push(Coin.decode(reader, reader.uint32())) + continue + case 5: + if (tag !== 42) { + break + } + + message.finalPool = Pool.decode(reader, reader.uint32()) + continue + case 6: + if (tag !== 50) { + break + } + + message.finalUserPoolShares = Coin.decode(reader, reader.uint32()) + continue + } + if ((tag & 7) === 4 || tag === 0) { + break + } + reader.skipType(tag & 7) + } + return message + }, + + fromJSON(object: any): EventPoolExited { + return { + address: isSet(object.address) ? String(object.address) : "", + poolSharesIn: isSet(object.poolSharesIn) + ? Coin.fromJSON(object.poolSharesIn) + : undefined, + tokensOut: Array.isArray(object?.tokensOut) + ? object.tokensOut.map((e: any) => Coin.fromJSON(e)) + : [], + fees: Array.isArray(object?.fees) + ? object.fees.map((e: any) => Coin.fromJSON(e)) + : [], + finalPool: isSet(object.finalPool) + ? Pool.fromJSON(object.finalPool) + : undefined, + finalUserPoolShares: isSet(object.finalUserPoolShares) + ? Coin.fromJSON(object.finalUserPoolShares) + : undefined, + } + }, + + toJSON(message: EventPoolExited): unknown { + const obj: any = {} + message.address !== undefined && (obj.address = message.address) + message.poolSharesIn !== undefined && + (obj.poolSharesIn = message.poolSharesIn + ? Coin.toJSON(message.poolSharesIn) + : undefined) + if (message.tokensOut) { + obj.tokensOut = message.tokensOut.map((e) => + e ? Coin.toJSON(e) : undefined + ) + } else { + obj.tokensOut = [] + } + if (message.fees) { + obj.fees = message.fees.map((e) => (e ? Coin.toJSON(e) : undefined)) + } else { + obj.fees = [] + } + message.finalPool !== undefined && + (obj.finalPool = message.finalPool + ? Pool.toJSON(message.finalPool) + : undefined) + message.finalUserPoolShares !== undefined && + (obj.finalUserPoolShares = message.finalUserPoolShares + ? Coin.toJSON(message.finalUserPoolShares) + : undefined) + return obj + }, + + create, I>>( + base?: I + ): EventPoolExited { + return EventPoolExited.fromPartial(base ?? {}) + }, + + fromPartial, I>>( + object: I + ): EventPoolExited { + const message = createBaseEventPoolExited() + message.address = object.address ?? "" + message.poolSharesIn = + object.poolSharesIn !== undefined && object.poolSharesIn !== null + ? Coin.fromPartial(object.poolSharesIn) + : undefined + message.tokensOut = object.tokensOut?.map((e) => Coin.fromPartial(e)) || [] + message.fees = object.fees?.map((e) => Coin.fromPartial(e)) || [] + message.finalPool = + object.finalPool !== undefined && object.finalPool !== null + ? Pool.fromPartial(object.finalPool) + : undefined + message.finalUserPoolShares = + object.finalUserPoolShares !== undefined && + object.finalUserPoolShares !== null + ? Coin.fromPartial(object.finalUserPoolShares) + : undefined + return message + }, +} + +function createBaseEventAssetsSwapped(): EventAssetsSwapped { + return { + address: "", + tokenIn: undefined, + tokenOut: undefined, + fee: undefined, + finalPool: undefined, + } +} + +export const EventAssetsSwapped = { + encode( + message: EventAssetsSwapped, + writer: _m0.Writer = _m0.Writer.create() + ): _m0.Writer { + if (message.address !== "") { + writer.uint32(10).string(message.address) + } + if (message.tokenIn !== undefined) { + Coin.encode(message.tokenIn, writer.uint32(18).fork()).ldelim() + } + if (message.tokenOut !== undefined) { + Coin.encode(message.tokenOut, writer.uint32(26).fork()).ldelim() + } + if (message.fee !== undefined) { + Coin.encode(message.fee, writer.uint32(34).fork()).ldelim() + } + if (message.finalPool !== undefined) { + Pool.encode(message.finalPool, writer.uint32(42).fork()).ldelim() + } + return writer + }, + + decode(input: _m0.Reader | Uint8Array, length?: number): EventAssetsSwapped { + const reader = + input instanceof _m0.Reader ? input : _m0.Reader.create(input) + let end = length === undefined ? reader.len : reader.pos + length + const message = createBaseEventAssetsSwapped() + while (reader.pos < end) { + const tag = reader.uint32() + switch (tag >>> 3) { + case 1: + if (tag !== 10) { + break + } + + message.address = reader.string() + continue + case 2: + if (tag !== 18) { + break + } + + message.tokenIn = Coin.decode(reader, reader.uint32()) + continue + case 3: + if (tag !== 26) { + break + } + + message.tokenOut = Coin.decode(reader, reader.uint32()) + continue + case 4: + if (tag !== 34) { + break + } + + message.fee = Coin.decode(reader, reader.uint32()) + continue + case 5: + if (tag !== 42) { + break + } + + message.finalPool = Pool.decode(reader, reader.uint32()) + continue + } + if ((tag & 7) === 4 || tag === 0) { + break + } + reader.skipType(tag & 7) + } + return message + }, + + fromJSON(object: any): EventAssetsSwapped { + return { + address: isSet(object.address) ? String(object.address) : "", + tokenIn: isSet(object.tokenIn) + ? Coin.fromJSON(object.tokenIn) + : undefined, + tokenOut: isSet(object.tokenOut) + ? Coin.fromJSON(object.tokenOut) + : undefined, + fee: isSet(object.fee) ? Coin.fromJSON(object.fee) : undefined, + finalPool: isSet(object.finalPool) + ? Pool.fromJSON(object.finalPool) + : undefined, + } + }, + + toJSON(message: EventAssetsSwapped): unknown { + const obj: any = {} + message.address !== undefined && (obj.address = message.address) + message.tokenIn !== undefined && + (obj.tokenIn = message.tokenIn ? Coin.toJSON(message.tokenIn) : undefined) + message.tokenOut !== undefined && + (obj.tokenOut = message.tokenOut + ? Coin.toJSON(message.tokenOut) + : undefined) + message.fee !== undefined && + (obj.fee = message.fee ? Coin.toJSON(message.fee) : undefined) + message.finalPool !== undefined && + (obj.finalPool = message.finalPool + ? Pool.toJSON(message.finalPool) + : undefined) + return obj + }, + + create, I>>( + base?: I + ): EventAssetsSwapped { + return EventAssetsSwapped.fromPartial(base ?? {}) + }, + + fromPartial, I>>( + object: I + ): EventAssetsSwapped { + const message = createBaseEventAssetsSwapped() + message.address = object.address ?? "" + message.tokenIn = + object.tokenIn !== undefined && object.tokenIn !== null + ? Coin.fromPartial(object.tokenIn) + : undefined + message.tokenOut = + object.tokenOut !== undefined && object.tokenOut !== null + ? Coin.fromPartial(object.tokenOut) + : undefined + message.fee = + object.fee !== undefined && object.fee !== null + ? Coin.fromPartial(object.fee) + : undefined + message.finalPool = + object.finalPool !== undefined && object.finalPool !== null + ? Pool.fromPartial(object.finalPool) + : undefined + return message + }, +} + +type Builtin = + | Date + | Function + | Uint8Array + | string + | number + | boolean + | undefined + +export type DeepPartial = T extends Builtin + ? T + : T extends Long + ? string | number | Long + : T extends Array + ? Array> + : T extends ReadonlyArray + ? ReadonlyArray> + : T extends {} + ? { [K in keyof T]?: DeepPartial } + : Partial + +type KeysOfUnion = T extends T ? keyof T : never +export type Exact = P extends Builtin + ? P + : P & { [K in keyof P]: Exact } & { + [K in Exclude>]: never + } + +if (_m0.util.Long !== Long) { + _m0.util.Long = Long as any + _m0.configure() +} + +function isSet(value: any): boolean { + return value !== null && value !== undefined +} diff --git a/packages/protojs/src/nibiru/spot/v1/genesis.ts b/packages/protojs/src/nibiru/spot/v1/genesis.ts new file mode 100644 index 00000000..babe9c46 --- /dev/null +++ b/packages/protojs/src/nibiru/spot/v1/genesis.ts @@ -0,0 +1,141 @@ +/* eslint-disable */ +import Long from "long" +import _m0 from "protobufjs/minimal" +import { Params } from "./params" +import { Pool } from "./pool" + +export const protobufPackage = "nibiru.spot.v1" + +/** GenesisState defines the spot module's genesis state. */ +export interface GenesisState { + /** params defines all the parameters of the module. */ + params?: Params + /** pools defines all the pools of the module. */ + pools: Pool[] +} + +function createBaseGenesisState(): GenesisState { + return { params: undefined, pools: [] } +} + +export const GenesisState = { + encode( + message: GenesisState, + writer: _m0.Writer = _m0.Writer.create() + ): _m0.Writer { + if (message.params !== undefined) { + Params.encode(message.params, writer.uint32(10).fork()).ldelim() + } + for (const v of message.pools) { + Pool.encode(v!, writer.uint32(18).fork()).ldelim() + } + return writer + }, + + decode(input: _m0.Reader | Uint8Array, length?: number): GenesisState { + const reader = + input instanceof _m0.Reader ? input : _m0.Reader.create(input) + let end = length === undefined ? reader.len : reader.pos + length + const message = createBaseGenesisState() + while (reader.pos < end) { + const tag = reader.uint32() + switch (tag >>> 3) { + case 1: + if (tag !== 10) { + break + } + + message.params = Params.decode(reader, reader.uint32()) + continue + case 2: + if (tag !== 18) { + break + } + + message.pools.push(Pool.decode(reader, reader.uint32())) + continue + } + if ((tag & 7) === 4 || tag === 0) { + break + } + reader.skipType(tag & 7) + } + return message + }, + + fromJSON(object: any): GenesisState { + return { + params: isSet(object.params) ? Params.fromJSON(object.params) : undefined, + pools: Array.isArray(object?.pools) + ? object.pools.map((e: any) => Pool.fromJSON(e)) + : [], + } + }, + + toJSON(message: GenesisState): unknown { + const obj: any = {} + message.params !== undefined && + (obj.params = message.params ? Params.toJSON(message.params) : undefined) + if (message.pools) { + obj.pools = message.pools.map((e) => (e ? Pool.toJSON(e) : undefined)) + } else { + obj.pools = [] + } + return obj + }, + + create, I>>( + base?: I + ): GenesisState { + return GenesisState.fromPartial(base ?? {}) + }, + + fromPartial, I>>( + object: I + ): GenesisState { + const message = createBaseGenesisState() + message.params = + object.params !== undefined && object.params !== null + ? Params.fromPartial(object.params) + : undefined + message.pools = object.pools?.map((e) => Pool.fromPartial(e)) || [] + return message + }, +} + +type Builtin = + | Date + | Function + | Uint8Array + | string + | number + | boolean + | undefined + +export type DeepPartial = T extends Builtin + ? T + : T extends Long + ? string | number | Long + : T extends Array + ? Array> + : T extends ReadonlyArray + ? ReadonlyArray> + : T extends {} + ? { [K in keyof T]?: DeepPartial } + : Partial + +type KeysOfUnion = T extends T ? keyof T : never +export type Exact = P extends Builtin + ? P + : P & { [K in keyof P]: Exact } & { + [K in Exclude>]: never + } + +if (_m0.util.Long !== Long) { + _m0.util.Long = Long as any + _m0.configure() +} + +function isSet(value: any): boolean { + return value !== null && value !== undefined +} diff --git a/packages/protojs/src/nibiru/spot/v1/params.ts b/packages/protojs/src/nibiru/spot/v1/params.ts new file mode 100644 index 00000000..ddd93c71 --- /dev/null +++ b/packages/protojs/src/nibiru/spot/v1/params.ts @@ -0,0 +1,169 @@ +/* eslint-disable */ +import Long from "long" +import _m0 from "protobufjs/minimal" +import { Coin } from "../../../cosmos/base/v1beta1/coin" + +export const protobufPackage = "nibiru.spot.v1" + +/** Params defines the parameters for the module. */ +export interface Params { + /** The start pool number, i.e. the first pool number that isn't taken yet. */ + startingPoolNumber: Long + /** The cost of creating a pool, taken from the pool creator's account. */ + poolCreationFee: Coin[] + /** The assets that can be used to create liquidity pools */ + whitelistedAsset: string[] +} + +function createBaseParams(): Params { + return { + startingPoolNumber: Long.UZERO, + poolCreationFee: [], + whitelistedAsset: [], + } +} + +export const Params = { + encode( + message: Params, + writer: _m0.Writer = _m0.Writer.create() + ): _m0.Writer { + if (!message.startingPoolNumber.isZero()) { + writer.uint32(8).uint64(message.startingPoolNumber) + } + for (const v of message.poolCreationFee) { + Coin.encode(v!, writer.uint32(18).fork()).ldelim() + } + for (const v of message.whitelistedAsset) { + writer.uint32(26).string(v!) + } + return writer + }, + + decode(input: _m0.Reader | Uint8Array, length?: number): Params { + const reader = + input instanceof _m0.Reader ? input : _m0.Reader.create(input) + let end = length === undefined ? reader.len : reader.pos + length + const message = createBaseParams() + while (reader.pos < end) { + const tag = reader.uint32() + switch (tag >>> 3) { + case 1: + if (tag !== 8) { + break + } + + message.startingPoolNumber = reader.uint64() as Long + continue + case 2: + if (tag !== 18) { + break + } + + message.poolCreationFee.push(Coin.decode(reader, reader.uint32())) + continue + case 3: + if (tag !== 26) { + break + } + + message.whitelistedAsset.push(reader.string()) + continue + } + if ((tag & 7) === 4 || tag === 0) { + break + } + reader.skipType(tag & 7) + } + return message + }, + + fromJSON(object: any): Params { + return { + startingPoolNumber: isSet(object.startingPoolNumber) + ? Long.fromValue(object.startingPoolNumber) + : Long.UZERO, + poolCreationFee: Array.isArray(object?.poolCreationFee) + ? object.poolCreationFee.map((e: any) => Coin.fromJSON(e)) + : [], + whitelistedAsset: Array.isArray(object?.whitelistedAsset) + ? object.whitelistedAsset.map((e: any) => String(e)) + : [], + } + }, + + toJSON(message: Params): unknown { + const obj: any = {} + message.startingPoolNumber !== undefined && + (obj.startingPoolNumber = ( + message.startingPoolNumber || Long.UZERO + ).toString()) + if (message.poolCreationFee) { + obj.poolCreationFee = message.poolCreationFee.map((e) => + e ? Coin.toJSON(e) : undefined + ) + } else { + obj.poolCreationFee = [] + } + if (message.whitelistedAsset) { + obj.whitelistedAsset = message.whitelistedAsset.map((e) => e) + } else { + obj.whitelistedAsset = [] + } + return obj + }, + + create, I>>(base?: I): Params { + return Params.fromPartial(base ?? {}) + }, + + fromPartial, I>>(object: I): Params { + const message = createBaseParams() + message.startingPoolNumber = + object.startingPoolNumber !== undefined && + object.startingPoolNumber !== null + ? Long.fromValue(object.startingPoolNumber) + : Long.UZERO + message.poolCreationFee = + object.poolCreationFee?.map((e) => Coin.fromPartial(e)) || [] + message.whitelistedAsset = object.whitelistedAsset?.map((e) => e) || [] + return message + }, +} + +type Builtin = + | Date + | Function + | Uint8Array + | string + | number + | boolean + | undefined + +export type DeepPartial = T extends Builtin + ? T + : T extends Long + ? string | number | Long + : T extends Array + ? Array> + : T extends ReadonlyArray + ? ReadonlyArray> + : T extends {} + ? { [K in keyof T]?: DeepPartial } + : Partial + +type KeysOfUnion = T extends T ? keyof T : never +export type Exact = P extends Builtin + ? P + : P & { [K in keyof P]: Exact } & { + [K in Exclude>]: never + } + +if (_m0.util.Long !== Long) { + _m0.util.Long = Long as any + _m0.configure() +} + +function isSet(value: any): boolean { + return value !== null && value !== undefined +} diff --git a/packages/protojs/src/nibiru/spot/v1/pool.ts b/packages/protojs/src/nibiru/spot/v1/pool.ts new file mode 100644 index 00000000..33ec39b3 --- /dev/null +++ b/packages/protojs/src/nibiru/spot/v1/pool.ts @@ -0,0 +1,470 @@ +/* eslint-disable */ +import Long from "long" +import _m0 from "protobufjs/minimal" +import { Coin } from "../../../cosmos/base/v1beta1/coin" + +export const protobufPackage = "nibiru.spot.v1" + +/** + * - `balancer`: Balancer are pools defined by the equation xy=k, extended by + * the weighs introduced by Balancer. + * - `stableswap`: Stableswap pools are defined by a combination of + * constant-product and constant-sum pool + */ +export enum PoolType { + BALANCER = 0, + STABLESWAP = 1, + UNRECOGNIZED = -1, +} + +export function poolTypeFromJSON(object: any): PoolType { + switch (object) { + case 0: + case "BALANCER": + return PoolType.BALANCER + case 1: + case "STABLESWAP": + return PoolType.STABLESWAP + case -1: + case "UNRECOGNIZED": + default: + return PoolType.UNRECOGNIZED + } +} + +export function poolTypeToJSON(object: PoolType): string { + switch (object) { + case PoolType.BALANCER: + return "BALANCER" + case PoolType.STABLESWAP: + return "STABLESWAP" + case PoolType.UNRECOGNIZED: + default: + return "UNRECOGNIZED" + } +} + +/** Configuration parameters for the pool. */ +export interface PoolParams { + swapFee: string + exitFee: string + /** + * Amplification Parameter (A): Larger value of A make the curve better + * resemble a straight line in the center (when pool is near balance). Highly + * volatile assets should use a lower value, while assets that are closer + * together may be best with a higher value. This is only used if the + * pool_type is set to 1 (stableswap) + */ + A: string + poolType: PoolType +} + +/** Which assets the pool contains. */ +export interface PoolAsset { + /** + * Coins we are talking about, + * the denomination must be unique amongst all PoolAssets for this pool. + */ + token?: Coin + /** Weight that is not normalized. This weight must be less than 2^50 */ + weight: string +} + +export interface Pool { + /** The pool id. */ + id: Long + /** The pool account address. */ + address: string + /** Fees and other pool-specific parameters. */ + poolParams?: PoolParams + /** + * These are assumed to be sorted by denomiation. + * They contain the pool asset and the information about the weight + */ + poolAssets: PoolAsset[] + /** sum of all non-normalized pool weights */ + totalWeight: string + /** sum of all LP tokens sent out */ + totalShares?: Coin +} + +function createBasePoolParams(): PoolParams { + return { swapFee: "", exitFee: "", A: "", poolType: 0 } +} + +export const PoolParams = { + encode( + message: PoolParams, + writer: _m0.Writer = _m0.Writer.create() + ): _m0.Writer { + if (message.swapFee !== "") { + writer.uint32(10).string(message.swapFee) + } + if (message.exitFee !== "") { + writer.uint32(18).string(message.exitFee) + } + if (message.A !== "") { + writer.uint32(26).string(message.A) + } + if (message.poolType !== 0) { + writer.uint32(32).int32(message.poolType) + } + return writer + }, + + decode(input: _m0.Reader | Uint8Array, length?: number): PoolParams { + const reader = + input instanceof _m0.Reader ? input : _m0.Reader.create(input) + let end = length === undefined ? reader.len : reader.pos + length + const message = createBasePoolParams() + while (reader.pos < end) { + const tag = reader.uint32() + switch (tag >>> 3) { + case 1: + if (tag !== 10) { + break + } + + message.swapFee = reader.string() + continue + case 2: + if (tag !== 18) { + break + } + + message.exitFee = reader.string() + continue + case 3: + if (tag !== 26) { + break + } + + message.A = reader.string() + continue + case 4: + if (tag !== 32) { + break + } + + message.poolType = reader.int32() as any + continue + } + if ((tag & 7) === 4 || tag === 0) { + break + } + reader.skipType(tag & 7) + } + return message + }, + + fromJSON(object: any): PoolParams { + return { + swapFee: isSet(object.swapFee) ? String(object.swapFee) : "", + exitFee: isSet(object.exitFee) ? String(object.exitFee) : "", + A: isSet(object.A) ? String(object.A) : "", + poolType: isSet(object.poolType) ? poolTypeFromJSON(object.poolType) : 0, + } + }, + + toJSON(message: PoolParams): unknown { + const obj: any = {} + message.swapFee !== undefined && (obj.swapFee = message.swapFee) + message.exitFee !== undefined && (obj.exitFee = message.exitFee) + message.A !== undefined && (obj.A = message.A) + message.poolType !== undefined && + (obj.poolType = poolTypeToJSON(message.poolType)) + return obj + }, + + create, I>>(base?: I): PoolParams { + return PoolParams.fromPartial(base ?? {}) + }, + + fromPartial, I>>( + object: I + ): PoolParams { + const message = createBasePoolParams() + message.swapFee = object.swapFee ?? "" + message.exitFee = object.exitFee ?? "" + message.A = object.A ?? "" + message.poolType = object.poolType ?? 0 + return message + }, +} + +function createBasePoolAsset(): PoolAsset { + return { token: undefined, weight: "" } +} + +export const PoolAsset = { + encode( + message: PoolAsset, + writer: _m0.Writer = _m0.Writer.create() + ): _m0.Writer { + if (message.token !== undefined) { + Coin.encode(message.token, writer.uint32(10).fork()).ldelim() + } + if (message.weight !== "") { + writer.uint32(18).string(message.weight) + } + return writer + }, + + decode(input: _m0.Reader | Uint8Array, length?: number): PoolAsset { + const reader = + input instanceof _m0.Reader ? input : _m0.Reader.create(input) + let end = length === undefined ? reader.len : reader.pos + length + const message = createBasePoolAsset() + while (reader.pos < end) { + const tag = reader.uint32() + switch (tag >>> 3) { + case 1: + if (tag !== 10) { + break + } + + message.token = Coin.decode(reader, reader.uint32()) + continue + case 2: + if (tag !== 18) { + break + } + + message.weight = reader.string() + continue + } + if ((tag & 7) === 4 || tag === 0) { + break + } + reader.skipType(tag & 7) + } + return message + }, + + fromJSON(object: any): PoolAsset { + return { + token: isSet(object.token) ? Coin.fromJSON(object.token) : undefined, + weight: isSet(object.weight) ? String(object.weight) : "", + } + }, + + toJSON(message: PoolAsset): unknown { + const obj: any = {} + message.token !== undefined && + (obj.token = message.token ? Coin.toJSON(message.token) : undefined) + message.weight !== undefined && (obj.weight = message.weight) + return obj + }, + + create, I>>(base?: I): PoolAsset { + return PoolAsset.fromPartial(base ?? {}) + }, + + fromPartial, I>>( + object: I + ): PoolAsset { + const message = createBasePoolAsset() + message.token = + object.token !== undefined && object.token !== null + ? Coin.fromPartial(object.token) + : undefined + message.weight = object.weight ?? "" + return message + }, +} + +function createBasePool(): Pool { + return { + id: Long.UZERO, + address: "", + poolParams: undefined, + poolAssets: [], + totalWeight: "", + totalShares: undefined, + } +} + +export const Pool = { + encode(message: Pool, writer: _m0.Writer = _m0.Writer.create()): _m0.Writer { + if (!message.id.isZero()) { + writer.uint32(8).uint64(message.id) + } + if (message.address !== "") { + writer.uint32(18).string(message.address) + } + if (message.poolParams !== undefined) { + PoolParams.encode(message.poolParams, writer.uint32(26).fork()).ldelim() + } + for (const v of message.poolAssets) { + PoolAsset.encode(v!, writer.uint32(34).fork()).ldelim() + } + if (message.totalWeight !== "") { + writer.uint32(42).string(message.totalWeight) + } + if (message.totalShares !== undefined) { + Coin.encode(message.totalShares, writer.uint32(50).fork()).ldelim() + } + return writer + }, + + decode(input: _m0.Reader | Uint8Array, length?: number): Pool { + const reader = + input instanceof _m0.Reader ? input : _m0.Reader.create(input) + let end = length === undefined ? reader.len : reader.pos + length + const message = createBasePool() + while (reader.pos < end) { + const tag = reader.uint32() + switch (tag >>> 3) { + case 1: + if (tag !== 8) { + break + } + + message.id = reader.uint64() as Long + continue + case 2: + if (tag !== 18) { + break + } + + message.address = reader.string() + continue + case 3: + if (tag !== 26) { + break + } + + message.poolParams = PoolParams.decode(reader, reader.uint32()) + continue + case 4: + if (tag !== 34) { + break + } + + message.poolAssets.push(PoolAsset.decode(reader, reader.uint32())) + continue + case 5: + if (tag !== 42) { + break + } + + message.totalWeight = reader.string() + continue + case 6: + if (tag !== 50) { + break + } + + message.totalShares = Coin.decode(reader, reader.uint32()) + continue + } + if ((tag & 7) === 4 || tag === 0) { + break + } + reader.skipType(tag & 7) + } + return message + }, + + fromJSON(object: any): Pool { + return { + id: isSet(object.id) ? Long.fromValue(object.id) : Long.UZERO, + address: isSet(object.address) ? String(object.address) : "", + poolParams: isSet(object.poolParams) + ? PoolParams.fromJSON(object.poolParams) + : undefined, + poolAssets: Array.isArray(object?.poolAssets) + ? object.poolAssets.map((e: any) => PoolAsset.fromJSON(e)) + : [], + totalWeight: isSet(object.totalWeight) ? String(object.totalWeight) : "", + totalShares: isSet(object.totalShares) + ? Coin.fromJSON(object.totalShares) + : undefined, + } + }, + + toJSON(message: Pool): unknown { + const obj: any = {} + message.id !== undefined && (obj.id = (message.id || Long.UZERO).toString()) + message.address !== undefined && (obj.address = message.address) + message.poolParams !== undefined && + (obj.poolParams = message.poolParams + ? PoolParams.toJSON(message.poolParams) + : undefined) + if (message.poolAssets) { + obj.poolAssets = message.poolAssets.map((e) => + e ? PoolAsset.toJSON(e) : undefined + ) + } else { + obj.poolAssets = [] + } + message.totalWeight !== undefined && (obj.totalWeight = message.totalWeight) + message.totalShares !== undefined && + (obj.totalShares = message.totalShares + ? Coin.toJSON(message.totalShares) + : undefined) + return obj + }, + + create, I>>(base?: I): Pool { + return Pool.fromPartial(base ?? {}) + }, + + fromPartial, I>>(object: I): Pool { + const message = createBasePool() + message.id = + object.id !== undefined && object.id !== null + ? Long.fromValue(object.id) + : Long.UZERO + message.address = object.address ?? "" + message.poolParams = + object.poolParams !== undefined && object.poolParams !== null + ? PoolParams.fromPartial(object.poolParams) + : undefined + message.poolAssets = + object.poolAssets?.map((e) => PoolAsset.fromPartial(e)) || [] + message.totalWeight = object.totalWeight ?? "" + message.totalShares = + object.totalShares !== undefined && object.totalShares !== null + ? Coin.fromPartial(object.totalShares) + : undefined + return message + }, +} + +type Builtin = + | Date + | Function + | Uint8Array + | string + | number + | boolean + | undefined + +export type DeepPartial = T extends Builtin + ? T + : T extends Long + ? string | number | Long + : T extends Array + ? Array> + : T extends ReadonlyArray + ? ReadonlyArray> + : T extends {} + ? { [K in keyof T]?: DeepPartial } + : Partial + +type KeysOfUnion = T extends T ? keyof T : never +export type Exact = P extends Builtin + ? P + : P & { [K in keyof P]: Exact } & { + [K in Exclude>]: never + } + +if (_m0.util.Long !== Long) { + _m0.util.Long = Long as any + _m0.configure() +} + +function isSet(value: any): boolean { + return value !== null && value !== undefined +} diff --git a/packages/protojs/src/nibiru/spot/v1/query.ts b/packages/protojs/src/nibiru/spot/v1/query.ts new file mode 100644 index 00000000..bb60e0b8 --- /dev/null +++ b/packages/protojs/src/nibiru/spot/v1/query.ts @@ -0,0 +1,2945 @@ +/* eslint-disable */ +import Long from "long" +import _m0 from "protobufjs/minimal" +import { + PageRequest, + PageResponse, +} from "../../../cosmos/base/query/v1beta1/pagination" +import { Coin } from "../../../cosmos/base/v1beta1/coin" +import { Params } from "./params" +import { Pool, PoolParams } from "./pool" + +export const protobufPackage = "nibiru.spot.v1" + +/** QueryParamsRequest is request type for the Query/Params RPC method. */ +export interface QueryParamsRequest {} + +/** QueryParamsResponse is response type for the Query/Params RPC method. */ +export interface QueryParamsResponse { + /** params holds all the parameters of this module. */ + params?: Params +} + +export interface QueryPoolNumberRequest {} + +export interface QueryPoolNumberResponse { + poolId: Long +} + +export interface QueryPoolRequest { + poolId: Long +} + +export interface QueryPoolResponse { + pool?: Pool +} + +export interface QueryPoolsRequest { + /** pagination defines an optional pagination for the request. */ + pagination?: PageRequest +} + +export interface QueryPoolsResponse { + pools: Pool[] + /** pagination defines the pagination in the response. */ + pagination?: PageResponse +} + +export interface QueryPoolParamsRequest { + poolId: Long +} + +export interface QueryPoolParamsResponse { + poolParams?: PoolParams +} + +export interface QueryNumPoolsRequest {} + +export interface QueryNumPoolsResponse { + numPools: Long +} + +/** + * -------------------------------------------- + * Query total liquidity the protocol + */ +export interface QueryTotalLiquidityRequest {} + +export interface QueryTotalLiquidityResponse { + liquidity: Coin[] +} + +/** + * -------------------------------------------- + * Query total liquidity for a pool + */ +export interface QueryTotalPoolLiquidityRequest { + poolId: Long +} + +export interface QueryTotalPoolLiquidityResponse { + liquidity: Coin[] +} + +export interface QueryTotalSharesRequest { + poolId: Long +} + +export interface QueryTotalSharesResponse { + /** sum of all LP tokens sent out */ + totalShares?: Coin +} + +/** + * Returns the amount of tokenInDenom to produce 1 tokenOutDenom + * For example, if the price of NIBI = 9.123 NUSD, then setting + * tokenInDenom=NUSD and tokenOutDenom=NIBI would give "9.123". + */ +export interface QuerySpotPriceRequest { + poolId: Long + /** the denomination of the token you are giving into the pool */ + tokenInDenom: string + /** the denomination of the token you are taking out of the pool */ + tokenOutDenom: string +} + +export interface QuerySpotPriceResponse { + spotPrice: string +} + +/** + * Given an exact amount of tokens in and a target tokenOutDenom, calculates + * the expected amount of tokens out received from a swap. + */ +export interface QuerySwapExactAmountInRequest { + poolId: Long + tokenIn?: Coin + tokenOutDenom: string +} + +export interface QuerySwapExactAmountInResponse { + tokenOut?: Coin + fee?: Coin +} + +/** + * Given an exact amount of tokens out and a target tokenInDenom, calculates + * the expected amount of tokens in required to do the swap. + */ +export interface QuerySwapExactAmountOutRequest { + poolId: Long + tokenOut?: Coin + tokenInDenom: string +} + +export interface QuerySwapExactAmountOutResponse { + tokenIn?: Coin +} + +export interface QueryJoinExactAmountInRequest { + poolId: Long + tokensIn: Coin[] +} + +export interface QueryJoinExactAmountInResponse { + /** amount of pool shares returned to user after join */ + poolSharesOut: string + /** coins remaining after pool join */ + remCoins: Coin[] +} + +export interface QueryJoinExactAmountOutRequest { + poolId: Long +} + +export interface QueryJoinExactAmountOutResponse {} + +export interface QueryExitExactAmountInRequest { + poolId: Long + /** amount of pool shares to return to pool */ + poolSharesIn: string +} + +export interface QueryExitExactAmountInResponse { + /** coins obtained after exiting */ + tokensOut: Coin[] + fees: Coin[] +} + +export interface QueryExitExactAmountOutRequest { + poolId: Long +} + +export interface QueryExitExactAmountOutResponse {} + +function createBaseQueryParamsRequest(): QueryParamsRequest { + return {} +} + +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 : _m0.Reader.create(input) + let end = length === undefined ? reader.len : reader.pos + length + const message = createBaseQueryParamsRequest() + while (reader.pos < end) { + const tag = reader.uint32() + switch (tag >>> 3) { + } + if ((tag & 7) === 4 || tag === 0) { + break + } + reader.skipType(tag & 7) + } + return message + }, + + fromJSON(_: any): QueryParamsRequest { + return {} + }, + + toJSON(_: QueryParamsRequest): unknown { + const obj: any = {} + return obj + }, + + create, I>>( + base?: I + ): QueryParamsRequest { + return QueryParamsRequest.fromPartial(base ?? {}) + }, + + fromPartial, I>>( + _: I + ): QueryParamsRequest { + const message = createBaseQueryParamsRequest() + return message + }, +} + +function createBaseQueryParamsResponse(): QueryParamsResponse { + return { params: undefined } +} + +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 : _m0.Reader.create(input) + let end = length === undefined ? reader.len : reader.pos + length + const message = createBaseQueryParamsResponse() + while (reader.pos < end) { + const tag = reader.uint32() + switch (tag >>> 3) { + case 1: + if (tag !== 10) { + break + } + + message.params = Params.decode(reader, reader.uint32()) + continue + } + if ((tag & 7) === 4 || tag === 0) { + break + } + reader.skipType(tag & 7) + } + return message + }, + + fromJSON(object: any): QueryParamsResponse { + return { + params: isSet(object.params) ? Params.fromJSON(object.params) : undefined, + } + }, + + toJSON(message: QueryParamsResponse): unknown { + const obj: any = {} + message.params !== undefined && + (obj.params = message.params ? Params.toJSON(message.params) : undefined) + return obj + }, + + create, I>>( + base?: I + ): QueryParamsResponse { + return QueryParamsResponse.fromPartial(base ?? {}) + }, + + fromPartial, I>>( + object: I + ): QueryParamsResponse { + const message = createBaseQueryParamsResponse() + message.params = + object.params !== undefined && object.params !== null + ? Params.fromPartial(object.params) + : undefined + return message + }, +} + +function createBaseQueryPoolNumberRequest(): QueryPoolNumberRequest { + return {} +} + +export const QueryPoolNumberRequest = { + encode( + _: QueryPoolNumberRequest, + writer: _m0.Writer = _m0.Writer.create() + ): _m0.Writer { + return writer + }, + + decode( + input: _m0.Reader | Uint8Array, + length?: number + ): QueryPoolNumberRequest { + const reader = + input instanceof _m0.Reader ? input : _m0.Reader.create(input) + let end = length === undefined ? reader.len : reader.pos + length + const message = createBaseQueryPoolNumberRequest() + while (reader.pos < end) { + const tag = reader.uint32() + switch (tag >>> 3) { + } + if ((tag & 7) === 4 || tag === 0) { + break + } + reader.skipType(tag & 7) + } + return message + }, + + fromJSON(_: any): QueryPoolNumberRequest { + return {} + }, + + toJSON(_: QueryPoolNumberRequest): unknown { + const obj: any = {} + return obj + }, + + create, I>>( + base?: I + ): QueryPoolNumberRequest { + return QueryPoolNumberRequest.fromPartial(base ?? {}) + }, + + fromPartial, I>>( + _: I + ): QueryPoolNumberRequest { + const message = createBaseQueryPoolNumberRequest() + return message + }, +} + +function createBaseQueryPoolNumberResponse(): QueryPoolNumberResponse { + return { poolId: Long.UZERO } +} + +export const QueryPoolNumberResponse = { + encode( + message: QueryPoolNumberResponse, + writer: _m0.Writer = _m0.Writer.create() + ): _m0.Writer { + if (!message.poolId.isZero()) { + writer.uint32(8).uint64(message.poolId) + } + return writer + }, + + decode( + input: _m0.Reader | Uint8Array, + length?: number + ): QueryPoolNumberResponse { + const reader = + input instanceof _m0.Reader ? input : _m0.Reader.create(input) + let end = length === undefined ? reader.len : reader.pos + length + const message = createBaseQueryPoolNumberResponse() + while (reader.pos < end) { + const tag = reader.uint32() + switch (tag >>> 3) { + case 1: + if (tag !== 8) { + break + } + + message.poolId = reader.uint64() as Long + continue + } + if ((tag & 7) === 4 || tag === 0) { + break + } + reader.skipType(tag & 7) + } + return message + }, + + fromJSON(object: any): QueryPoolNumberResponse { + return { + poolId: isSet(object.poolId) ? Long.fromValue(object.poolId) : Long.UZERO, + } + }, + + toJSON(message: QueryPoolNumberResponse): unknown { + const obj: any = {} + message.poolId !== undefined && + (obj.poolId = (message.poolId || Long.UZERO).toString()) + return obj + }, + + create, I>>( + base?: I + ): QueryPoolNumberResponse { + return QueryPoolNumberResponse.fromPartial(base ?? {}) + }, + + fromPartial, I>>( + object: I + ): QueryPoolNumberResponse { + const message = createBaseQueryPoolNumberResponse() + message.poolId = + object.poolId !== undefined && object.poolId !== null + ? Long.fromValue(object.poolId) + : Long.UZERO + return message + }, +} + +function createBaseQueryPoolRequest(): QueryPoolRequest { + return { poolId: Long.UZERO } +} + +export const QueryPoolRequest = { + encode( + message: QueryPoolRequest, + writer: _m0.Writer = _m0.Writer.create() + ): _m0.Writer { + if (!message.poolId.isZero()) { + writer.uint32(8).uint64(message.poolId) + } + return writer + }, + + decode(input: _m0.Reader | Uint8Array, length?: number): QueryPoolRequest { + const reader = + input instanceof _m0.Reader ? input : _m0.Reader.create(input) + let end = length === undefined ? reader.len : reader.pos + length + const message = createBaseQueryPoolRequest() + while (reader.pos < end) { + const tag = reader.uint32() + switch (tag >>> 3) { + case 1: + if (tag !== 8) { + break + } + + message.poolId = reader.uint64() as Long + continue + } + if ((tag & 7) === 4 || tag === 0) { + break + } + reader.skipType(tag & 7) + } + return message + }, + + fromJSON(object: any): QueryPoolRequest { + return { + poolId: isSet(object.poolId) ? Long.fromValue(object.poolId) : Long.UZERO, + } + }, + + toJSON(message: QueryPoolRequest): unknown { + const obj: any = {} + message.poolId !== undefined && + (obj.poolId = (message.poolId || Long.UZERO).toString()) + return obj + }, + + create, I>>( + base?: I + ): QueryPoolRequest { + return QueryPoolRequest.fromPartial(base ?? {}) + }, + + fromPartial, I>>( + object: I + ): QueryPoolRequest { + const message = createBaseQueryPoolRequest() + message.poolId = + object.poolId !== undefined && object.poolId !== null + ? Long.fromValue(object.poolId) + : Long.UZERO + return message + }, +} + +function createBaseQueryPoolResponse(): QueryPoolResponse { + return { pool: undefined } +} + +export const QueryPoolResponse = { + encode( + message: QueryPoolResponse, + writer: _m0.Writer = _m0.Writer.create() + ): _m0.Writer { + if (message.pool !== undefined) { + Pool.encode(message.pool, writer.uint32(10).fork()).ldelim() + } + return writer + }, + + decode(input: _m0.Reader | Uint8Array, length?: number): QueryPoolResponse { + const reader = + input instanceof _m0.Reader ? input : _m0.Reader.create(input) + let end = length === undefined ? reader.len : reader.pos + length + const message = createBaseQueryPoolResponse() + while (reader.pos < end) { + const tag = reader.uint32() + switch (tag >>> 3) { + case 1: + if (tag !== 10) { + break + } + + message.pool = Pool.decode(reader, reader.uint32()) + continue + } + if ((tag & 7) === 4 || tag === 0) { + break + } + reader.skipType(tag & 7) + } + return message + }, + + fromJSON(object: any): QueryPoolResponse { + return { pool: isSet(object.pool) ? Pool.fromJSON(object.pool) : undefined } + }, + + toJSON(message: QueryPoolResponse): unknown { + const obj: any = {} + message.pool !== undefined && + (obj.pool = message.pool ? Pool.toJSON(message.pool) : undefined) + return obj + }, + + create, I>>( + base?: I + ): QueryPoolResponse { + return QueryPoolResponse.fromPartial(base ?? {}) + }, + + fromPartial, I>>( + object: I + ): QueryPoolResponse { + const message = createBaseQueryPoolResponse() + message.pool = + object.pool !== undefined && object.pool !== null + ? Pool.fromPartial(object.pool) + : undefined + return message + }, +} + +function createBaseQueryPoolsRequest(): QueryPoolsRequest { + return { pagination: undefined } +} + +export const QueryPoolsRequest = { + encode( + message: QueryPoolsRequest, + writer: _m0.Writer = _m0.Writer.create() + ): _m0.Writer { + if (message.pagination !== undefined) { + PageRequest.encode(message.pagination, writer.uint32(10).fork()).ldelim() + } + return writer + }, + + decode(input: _m0.Reader | Uint8Array, length?: number): QueryPoolsRequest { + const reader = + input instanceof _m0.Reader ? input : _m0.Reader.create(input) + let end = length === undefined ? reader.len : reader.pos + length + const message = createBaseQueryPoolsRequest() + while (reader.pos < end) { + const tag = reader.uint32() + switch (tag >>> 3) { + case 1: + if (tag !== 10) { + break + } + + message.pagination = PageRequest.decode(reader, reader.uint32()) + continue + } + if ((tag & 7) === 4 || tag === 0) { + break + } + reader.skipType(tag & 7) + } + return message + }, + + fromJSON(object: any): QueryPoolsRequest { + return { + pagination: isSet(object.pagination) + ? PageRequest.fromJSON(object.pagination) + : undefined, + } + }, + + toJSON(message: QueryPoolsRequest): unknown { + const obj: any = {} + message.pagination !== undefined && + (obj.pagination = message.pagination + ? PageRequest.toJSON(message.pagination) + : undefined) + return obj + }, + + create, I>>( + base?: I + ): QueryPoolsRequest { + return QueryPoolsRequest.fromPartial(base ?? {}) + }, + + fromPartial, I>>( + object: I + ): QueryPoolsRequest { + const message = createBaseQueryPoolsRequest() + message.pagination = + object.pagination !== undefined && object.pagination !== null + ? PageRequest.fromPartial(object.pagination) + : undefined + return message + }, +} + +function createBaseQueryPoolsResponse(): QueryPoolsResponse { + return { pools: [], pagination: undefined } +} + +export const QueryPoolsResponse = { + encode( + message: QueryPoolsResponse, + writer: _m0.Writer = _m0.Writer.create() + ): _m0.Writer { + for (const v of message.pools) { + Pool.encode(v!, writer.uint32(10).fork()).ldelim() + } + if (message.pagination !== undefined) { + PageResponse.encode(message.pagination, writer.uint32(18).fork()).ldelim() + } + return writer + }, + + decode(input: _m0.Reader | Uint8Array, length?: number): QueryPoolsResponse { + const reader = + input instanceof _m0.Reader ? input : _m0.Reader.create(input) + let end = length === undefined ? reader.len : reader.pos + length + const message = createBaseQueryPoolsResponse() + while (reader.pos < end) { + const tag = reader.uint32() + switch (tag >>> 3) { + case 1: + if (tag !== 10) { + break + } + + message.pools.push(Pool.decode(reader, reader.uint32())) + continue + case 2: + if (tag !== 18) { + break + } + + message.pagination = PageResponse.decode(reader, reader.uint32()) + continue + } + if ((tag & 7) === 4 || tag === 0) { + break + } + reader.skipType(tag & 7) + } + return message + }, + + fromJSON(object: any): QueryPoolsResponse { + return { + pools: Array.isArray(object?.pools) + ? object.pools.map((e: any) => Pool.fromJSON(e)) + : [], + pagination: isSet(object.pagination) + ? PageResponse.fromJSON(object.pagination) + : undefined, + } + }, + + toJSON(message: QueryPoolsResponse): unknown { + const obj: any = {} + if (message.pools) { + obj.pools = message.pools.map((e) => (e ? Pool.toJSON(e) : undefined)) + } else { + obj.pools = [] + } + message.pagination !== undefined && + (obj.pagination = message.pagination + ? PageResponse.toJSON(message.pagination) + : undefined) + return obj + }, + + create, I>>( + base?: I + ): QueryPoolsResponse { + return QueryPoolsResponse.fromPartial(base ?? {}) + }, + + fromPartial, I>>( + object: I + ): QueryPoolsResponse { + const message = createBaseQueryPoolsResponse() + message.pools = object.pools?.map((e) => Pool.fromPartial(e)) || [] + message.pagination = + object.pagination !== undefined && object.pagination !== null + ? PageResponse.fromPartial(object.pagination) + : undefined + return message + }, +} + +function createBaseQueryPoolParamsRequest(): QueryPoolParamsRequest { + return { poolId: Long.UZERO } +} + +export const QueryPoolParamsRequest = { + encode( + message: QueryPoolParamsRequest, + writer: _m0.Writer = _m0.Writer.create() + ): _m0.Writer { + if (!message.poolId.isZero()) { + writer.uint32(8).uint64(message.poolId) + } + return writer + }, + + decode( + input: _m0.Reader | Uint8Array, + length?: number + ): QueryPoolParamsRequest { + const reader = + input instanceof _m0.Reader ? input : _m0.Reader.create(input) + let end = length === undefined ? reader.len : reader.pos + length + const message = createBaseQueryPoolParamsRequest() + while (reader.pos < end) { + const tag = reader.uint32() + switch (tag >>> 3) { + case 1: + if (tag !== 8) { + break + } + + message.poolId = reader.uint64() as Long + continue + } + if ((tag & 7) === 4 || tag === 0) { + break + } + reader.skipType(tag & 7) + } + return message + }, + + fromJSON(object: any): QueryPoolParamsRequest { + return { + poolId: isSet(object.poolId) ? Long.fromValue(object.poolId) : Long.UZERO, + } + }, + + toJSON(message: QueryPoolParamsRequest): unknown { + const obj: any = {} + message.poolId !== undefined && + (obj.poolId = (message.poolId || Long.UZERO).toString()) + return obj + }, + + create, I>>( + base?: I + ): QueryPoolParamsRequest { + return QueryPoolParamsRequest.fromPartial(base ?? {}) + }, + + fromPartial, I>>( + object: I + ): QueryPoolParamsRequest { + const message = createBaseQueryPoolParamsRequest() + message.poolId = + object.poolId !== undefined && object.poolId !== null + ? Long.fromValue(object.poolId) + : Long.UZERO + return message + }, +} + +function createBaseQueryPoolParamsResponse(): QueryPoolParamsResponse { + return { poolParams: undefined } +} + +export const QueryPoolParamsResponse = { + encode( + message: QueryPoolParamsResponse, + writer: _m0.Writer = _m0.Writer.create() + ): _m0.Writer { + if (message.poolParams !== undefined) { + PoolParams.encode(message.poolParams, writer.uint32(10).fork()).ldelim() + } + return writer + }, + + decode( + input: _m0.Reader | Uint8Array, + length?: number + ): QueryPoolParamsResponse { + const reader = + input instanceof _m0.Reader ? input : _m0.Reader.create(input) + let end = length === undefined ? reader.len : reader.pos + length + const message = createBaseQueryPoolParamsResponse() + while (reader.pos < end) { + const tag = reader.uint32() + switch (tag >>> 3) { + case 1: + if (tag !== 10) { + break + } + + message.poolParams = PoolParams.decode(reader, reader.uint32()) + continue + } + if ((tag & 7) === 4 || tag === 0) { + break + } + reader.skipType(tag & 7) + } + return message + }, + + fromJSON(object: any): QueryPoolParamsResponse { + return { + poolParams: isSet(object.poolParams) + ? PoolParams.fromJSON(object.poolParams) + : undefined, + } + }, + + toJSON(message: QueryPoolParamsResponse): unknown { + const obj: any = {} + message.poolParams !== undefined && + (obj.poolParams = message.poolParams + ? PoolParams.toJSON(message.poolParams) + : undefined) + return obj + }, + + create, I>>( + base?: I + ): QueryPoolParamsResponse { + return QueryPoolParamsResponse.fromPartial(base ?? {}) + }, + + fromPartial, I>>( + object: I + ): QueryPoolParamsResponse { + const message = createBaseQueryPoolParamsResponse() + message.poolParams = + object.poolParams !== undefined && object.poolParams !== null + ? PoolParams.fromPartial(object.poolParams) + : undefined + return message + }, +} + +function createBaseQueryNumPoolsRequest(): QueryNumPoolsRequest { + return {} +} + +export const QueryNumPoolsRequest = { + encode( + _: QueryNumPoolsRequest, + writer: _m0.Writer = _m0.Writer.create() + ): _m0.Writer { + return writer + }, + + decode( + input: _m0.Reader | Uint8Array, + length?: number + ): QueryNumPoolsRequest { + const reader = + input instanceof _m0.Reader ? input : _m0.Reader.create(input) + let end = length === undefined ? reader.len : reader.pos + length + const message = createBaseQueryNumPoolsRequest() + while (reader.pos < end) { + const tag = reader.uint32() + switch (tag >>> 3) { + } + if ((tag & 7) === 4 || tag === 0) { + break + } + reader.skipType(tag & 7) + } + return message + }, + + fromJSON(_: any): QueryNumPoolsRequest { + return {} + }, + + toJSON(_: QueryNumPoolsRequest): unknown { + const obj: any = {} + return obj + }, + + create, I>>( + base?: I + ): QueryNumPoolsRequest { + return QueryNumPoolsRequest.fromPartial(base ?? {}) + }, + + fromPartial, I>>( + _: I + ): QueryNumPoolsRequest { + const message = createBaseQueryNumPoolsRequest() + return message + }, +} + +function createBaseQueryNumPoolsResponse(): QueryNumPoolsResponse { + return { numPools: Long.UZERO } +} + +export const QueryNumPoolsResponse = { + encode( + message: QueryNumPoolsResponse, + writer: _m0.Writer = _m0.Writer.create() + ): _m0.Writer { + if (!message.numPools.isZero()) { + writer.uint32(8).uint64(message.numPools) + } + return writer + }, + + decode( + input: _m0.Reader | Uint8Array, + length?: number + ): QueryNumPoolsResponse { + const reader = + input instanceof _m0.Reader ? input : _m0.Reader.create(input) + let end = length === undefined ? reader.len : reader.pos + length + const message = createBaseQueryNumPoolsResponse() + while (reader.pos < end) { + const tag = reader.uint32() + switch (tag >>> 3) { + case 1: + if (tag !== 8) { + break + } + + message.numPools = reader.uint64() as Long + continue + } + if ((tag & 7) === 4 || tag === 0) { + break + } + reader.skipType(tag & 7) + } + return message + }, + + fromJSON(object: any): QueryNumPoolsResponse { + return { + numPools: isSet(object.numPools) + ? Long.fromValue(object.numPools) + : Long.UZERO, + } + }, + + toJSON(message: QueryNumPoolsResponse): unknown { + const obj: any = {} + message.numPools !== undefined && + (obj.numPools = (message.numPools || Long.UZERO).toString()) + return obj + }, + + create, I>>( + base?: I + ): QueryNumPoolsResponse { + return QueryNumPoolsResponse.fromPartial(base ?? {}) + }, + + fromPartial, I>>( + object: I + ): QueryNumPoolsResponse { + const message = createBaseQueryNumPoolsResponse() + message.numPools = + object.numPools !== undefined && object.numPools !== null + ? Long.fromValue(object.numPools) + : Long.UZERO + return message + }, +} + +function createBaseQueryTotalLiquidityRequest(): QueryTotalLiquidityRequest { + return {} +} + +export const QueryTotalLiquidityRequest = { + encode( + _: QueryTotalLiquidityRequest, + writer: _m0.Writer = _m0.Writer.create() + ): _m0.Writer { + return writer + }, + + decode( + input: _m0.Reader | Uint8Array, + length?: number + ): QueryTotalLiquidityRequest { + const reader = + input instanceof _m0.Reader ? input : _m0.Reader.create(input) + let end = length === undefined ? reader.len : reader.pos + length + const message = createBaseQueryTotalLiquidityRequest() + while (reader.pos < end) { + const tag = reader.uint32() + switch (tag >>> 3) { + } + if ((tag & 7) === 4 || tag === 0) { + break + } + reader.skipType(tag & 7) + } + return message + }, + + fromJSON(_: any): QueryTotalLiquidityRequest { + return {} + }, + + toJSON(_: QueryTotalLiquidityRequest): unknown { + const obj: any = {} + return obj + }, + + create, I>>( + base?: I + ): QueryTotalLiquidityRequest { + return QueryTotalLiquidityRequest.fromPartial(base ?? {}) + }, + + fromPartial, I>>( + _: I + ): QueryTotalLiquidityRequest { + const message = createBaseQueryTotalLiquidityRequest() + return message + }, +} + +function createBaseQueryTotalLiquidityResponse(): QueryTotalLiquidityResponse { + return { liquidity: [] } +} + +export const QueryTotalLiquidityResponse = { + encode( + message: QueryTotalLiquidityResponse, + writer: _m0.Writer = _m0.Writer.create() + ): _m0.Writer { + for (const v of message.liquidity) { + Coin.encode(v!, writer.uint32(10).fork()).ldelim() + } + return writer + }, + + decode( + input: _m0.Reader | Uint8Array, + length?: number + ): QueryTotalLiquidityResponse { + const reader = + input instanceof _m0.Reader ? input : _m0.Reader.create(input) + let end = length === undefined ? reader.len : reader.pos + length + const message = createBaseQueryTotalLiquidityResponse() + while (reader.pos < end) { + const tag = reader.uint32() + switch (tag >>> 3) { + case 1: + if (tag !== 10) { + break + } + + message.liquidity.push(Coin.decode(reader, reader.uint32())) + continue + } + if ((tag & 7) === 4 || tag === 0) { + break + } + reader.skipType(tag & 7) + } + return message + }, + + fromJSON(object: any): QueryTotalLiquidityResponse { + return { + liquidity: Array.isArray(object?.liquidity) + ? object.liquidity.map((e: any) => Coin.fromJSON(e)) + : [], + } + }, + + toJSON(message: QueryTotalLiquidityResponse): unknown { + const obj: any = {} + if (message.liquidity) { + obj.liquidity = message.liquidity.map((e) => + e ? Coin.toJSON(e) : undefined + ) + } else { + obj.liquidity = [] + } + return obj + }, + + create, I>>( + base?: I + ): QueryTotalLiquidityResponse { + return QueryTotalLiquidityResponse.fromPartial(base ?? {}) + }, + + fromPartial, I>>( + object: I + ): QueryTotalLiquidityResponse { + const message = createBaseQueryTotalLiquidityResponse() + message.liquidity = object.liquidity?.map((e) => Coin.fromPartial(e)) || [] + return message + }, +} + +function createBaseQueryTotalPoolLiquidityRequest(): QueryTotalPoolLiquidityRequest { + return { poolId: Long.UZERO } +} + +export const QueryTotalPoolLiquidityRequest = { + encode( + message: QueryTotalPoolLiquidityRequest, + writer: _m0.Writer = _m0.Writer.create() + ): _m0.Writer { + if (!message.poolId.isZero()) { + writer.uint32(8).uint64(message.poolId) + } + return writer + }, + + decode( + input: _m0.Reader | Uint8Array, + length?: number + ): QueryTotalPoolLiquidityRequest { + const reader = + input instanceof _m0.Reader ? input : _m0.Reader.create(input) + let end = length === undefined ? reader.len : reader.pos + length + const message = createBaseQueryTotalPoolLiquidityRequest() + while (reader.pos < end) { + const tag = reader.uint32() + switch (tag >>> 3) { + case 1: + if (tag !== 8) { + break + } + + message.poolId = reader.uint64() as Long + continue + } + if ((tag & 7) === 4 || tag === 0) { + break + } + reader.skipType(tag & 7) + } + return message + }, + + fromJSON(object: any): QueryTotalPoolLiquidityRequest { + return { + poolId: isSet(object.poolId) ? Long.fromValue(object.poolId) : Long.UZERO, + } + }, + + toJSON(message: QueryTotalPoolLiquidityRequest): unknown { + const obj: any = {} + message.poolId !== undefined && + (obj.poolId = (message.poolId || Long.UZERO).toString()) + return obj + }, + + create, I>>( + base?: I + ): QueryTotalPoolLiquidityRequest { + return QueryTotalPoolLiquidityRequest.fromPartial(base ?? {}) + }, + + fromPartial, I>>( + object: I + ): QueryTotalPoolLiquidityRequest { + const message = createBaseQueryTotalPoolLiquidityRequest() + message.poolId = + object.poolId !== undefined && object.poolId !== null + ? Long.fromValue(object.poolId) + : Long.UZERO + return message + }, +} + +function createBaseQueryTotalPoolLiquidityResponse(): QueryTotalPoolLiquidityResponse { + return { liquidity: [] } +} + +export const QueryTotalPoolLiquidityResponse = { + encode( + message: QueryTotalPoolLiquidityResponse, + writer: _m0.Writer = _m0.Writer.create() + ): _m0.Writer { + for (const v of message.liquidity) { + Coin.encode(v!, writer.uint32(10).fork()).ldelim() + } + return writer + }, + + decode( + input: _m0.Reader | Uint8Array, + length?: number + ): QueryTotalPoolLiquidityResponse { + const reader = + input instanceof _m0.Reader ? input : _m0.Reader.create(input) + let end = length === undefined ? reader.len : reader.pos + length + const message = createBaseQueryTotalPoolLiquidityResponse() + while (reader.pos < end) { + const tag = reader.uint32() + switch (tag >>> 3) { + case 1: + if (tag !== 10) { + break + } + + message.liquidity.push(Coin.decode(reader, reader.uint32())) + continue + } + if ((tag & 7) === 4 || tag === 0) { + break + } + reader.skipType(tag & 7) + } + return message + }, + + fromJSON(object: any): QueryTotalPoolLiquidityResponse { + return { + liquidity: Array.isArray(object?.liquidity) + ? object.liquidity.map((e: any) => Coin.fromJSON(e)) + : [], + } + }, + + toJSON(message: QueryTotalPoolLiquidityResponse): unknown { + const obj: any = {} + if (message.liquidity) { + obj.liquidity = message.liquidity.map((e) => + e ? Coin.toJSON(e) : undefined + ) + } else { + obj.liquidity = [] + } + return obj + }, + + create, I>>( + base?: I + ): QueryTotalPoolLiquidityResponse { + return QueryTotalPoolLiquidityResponse.fromPartial(base ?? {}) + }, + + fromPartial, I>>( + object: I + ): QueryTotalPoolLiquidityResponse { + const message = createBaseQueryTotalPoolLiquidityResponse() + message.liquidity = object.liquidity?.map((e) => Coin.fromPartial(e)) || [] + return message + }, +} + +function createBaseQueryTotalSharesRequest(): QueryTotalSharesRequest { + return { poolId: Long.UZERO } +} + +export const QueryTotalSharesRequest = { + encode( + message: QueryTotalSharesRequest, + writer: _m0.Writer = _m0.Writer.create() + ): _m0.Writer { + if (!message.poolId.isZero()) { + writer.uint32(8).uint64(message.poolId) + } + return writer + }, + + decode( + input: _m0.Reader | Uint8Array, + length?: number + ): QueryTotalSharesRequest { + const reader = + input instanceof _m0.Reader ? input : _m0.Reader.create(input) + let end = length === undefined ? reader.len : reader.pos + length + const message = createBaseQueryTotalSharesRequest() + while (reader.pos < end) { + const tag = reader.uint32() + switch (tag >>> 3) { + case 1: + if (tag !== 8) { + break + } + + message.poolId = reader.uint64() as Long + continue + } + if ((tag & 7) === 4 || tag === 0) { + break + } + reader.skipType(tag & 7) + } + return message + }, + + fromJSON(object: any): QueryTotalSharesRequest { + return { + poolId: isSet(object.poolId) ? Long.fromValue(object.poolId) : Long.UZERO, + } + }, + + toJSON(message: QueryTotalSharesRequest): unknown { + const obj: any = {} + message.poolId !== undefined && + (obj.poolId = (message.poolId || Long.UZERO).toString()) + return obj + }, + + create, I>>( + base?: I + ): QueryTotalSharesRequest { + return QueryTotalSharesRequest.fromPartial(base ?? {}) + }, + + fromPartial, I>>( + object: I + ): QueryTotalSharesRequest { + const message = createBaseQueryTotalSharesRequest() + message.poolId = + object.poolId !== undefined && object.poolId !== null + ? Long.fromValue(object.poolId) + : Long.UZERO + return message + }, +} + +function createBaseQueryTotalSharesResponse(): QueryTotalSharesResponse { + return { totalShares: undefined } +} + +export const QueryTotalSharesResponse = { + encode( + message: QueryTotalSharesResponse, + writer: _m0.Writer = _m0.Writer.create() + ): _m0.Writer { + if (message.totalShares !== undefined) { + Coin.encode(message.totalShares, writer.uint32(10).fork()).ldelim() + } + return writer + }, + + decode( + input: _m0.Reader | Uint8Array, + length?: number + ): QueryTotalSharesResponse { + const reader = + input instanceof _m0.Reader ? input : _m0.Reader.create(input) + let end = length === undefined ? reader.len : reader.pos + length + const message = createBaseQueryTotalSharesResponse() + while (reader.pos < end) { + const tag = reader.uint32() + switch (tag >>> 3) { + case 1: + if (tag !== 10) { + break + } + + message.totalShares = Coin.decode(reader, reader.uint32()) + continue + } + if ((tag & 7) === 4 || tag === 0) { + break + } + reader.skipType(tag & 7) + } + return message + }, + + fromJSON(object: any): QueryTotalSharesResponse { + return { + totalShares: isSet(object.totalShares) + ? Coin.fromJSON(object.totalShares) + : undefined, + } + }, + + toJSON(message: QueryTotalSharesResponse): unknown { + const obj: any = {} + message.totalShares !== undefined && + (obj.totalShares = message.totalShares + ? Coin.toJSON(message.totalShares) + : undefined) + return obj + }, + + create, I>>( + base?: I + ): QueryTotalSharesResponse { + return QueryTotalSharesResponse.fromPartial(base ?? {}) + }, + + fromPartial, I>>( + object: I + ): QueryTotalSharesResponse { + const message = createBaseQueryTotalSharesResponse() + message.totalShares = + object.totalShares !== undefined && object.totalShares !== null + ? Coin.fromPartial(object.totalShares) + : undefined + return message + }, +} + +function createBaseQuerySpotPriceRequest(): QuerySpotPriceRequest { + return { poolId: Long.UZERO, tokenInDenom: "", tokenOutDenom: "" } +} + +export const QuerySpotPriceRequest = { + encode( + message: QuerySpotPriceRequest, + writer: _m0.Writer = _m0.Writer.create() + ): _m0.Writer { + if (!message.poolId.isZero()) { + writer.uint32(8).uint64(message.poolId) + } + if (message.tokenInDenom !== "") { + writer.uint32(18).string(message.tokenInDenom) + } + if (message.tokenOutDenom !== "") { + writer.uint32(26).string(message.tokenOutDenom) + } + return writer + }, + + decode( + input: _m0.Reader | Uint8Array, + length?: number + ): QuerySpotPriceRequest { + const reader = + input instanceof _m0.Reader ? input : _m0.Reader.create(input) + let end = length === undefined ? reader.len : reader.pos + length + const message = createBaseQuerySpotPriceRequest() + while (reader.pos < end) { + const tag = reader.uint32() + switch (tag >>> 3) { + case 1: + if (tag !== 8) { + break + } + + message.poolId = reader.uint64() as Long + continue + case 2: + if (tag !== 18) { + break + } + + message.tokenInDenom = reader.string() + continue + case 3: + if (tag !== 26) { + break + } + + message.tokenOutDenom = reader.string() + continue + } + if ((tag & 7) === 4 || tag === 0) { + break + } + reader.skipType(tag & 7) + } + return message + }, + + fromJSON(object: any): QuerySpotPriceRequest { + return { + poolId: isSet(object.poolId) ? Long.fromValue(object.poolId) : Long.UZERO, + tokenInDenom: isSet(object.tokenInDenom) + ? String(object.tokenInDenom) + : "", + tokenOutDenom: isSet(object.tokenOutDenom) + ? String(object.tokenOutDenom) + : "", + } + }, + + toJSON(message: QuerySpotPriceRequest): unknown { + const obj: any = {} + message.poolId !== undefined && + (obj.poolId = (message.poolId || Long.UZERO).toString()) + message.tokenInDenom !== undefined && + (obj.tokenInDenom = message.tokenInDenom) + message.tokenOutDenom !== undefined && + (obj.tokenOutDenom = message.tokenOutDenom) + return obj + }, + + create, I>>( + base?: I + ): QuerySpotPriceRequest { + return QuerySpotPriceRequest.fromPartial(base ?? {}) + }, + + fromPartial, I>>( + object: I + ): QuerySpotPriceRequest { + const message = createBaseQuerySpotPriceRequest() + message.poolId = + object.poolId !== undefined && object.poolId !== null + ? Long.fromValue(object.poolId) + : Long.UZERO + message.tokenInDenom = object.tokenInDenom ?? "" + message.tokenOutDenom = object.tokenOutDenom ?? "" + return message + }, +} + +function createBaseQuerySpotPriceResponse(): QuerySpotPriceResponse { + return { spotPrice: "" } +} + +export const QuerySpotPriceResponse = { + encode( + message: QuerySpotPriceResponse, + writer: _m0.Writer = _m0.Writer.create() + ): _m0.Writer { + if (message.spotPrice !== "") { + writer.uint32(10).string(message.spotPrice) + } + return writer + }, + + decode( + input: _m0.Reader | Uint8Array, + length?: number + ): QuerySpotPriceResponse { + const reader = + input instanceof _m0.Reader ? input : _m0.Reader.create(input) + let end = length === undefined ? reader.len : reader.pos + length + const message = createBaseQuerySpotPriceResponse() + while (reader.pos < end) { + const tag = reader.uint32() + switch (tag >>> 3) { + case 1: + if (tag !== 10) { + break + } + + message.spotPrice = reader.string() + continue + } + if ((tag & 7) === 4 || tag === 0) { + break + } + reader.skipType(tag & 7) + } + return message + }, + + fromJSON(object: any): QuerySpotPriceResponse { + return { + spotPrice: isSet(object.spotPrice) ? String(object.spotPrice) : "", + } + }, + + toJSON(message: QuerySpotPriceResponse): unknown { + const obj: any = {} + message.spotPrice !== undefined && (obj.spotPrice = message.spotPrice) + return obj + }, + + create, I>>( + base?: I + ): QuerySpotPriceResponse { + return QuerySpotPriceResponse.fromPartial(base ?? {}) + }, + + fromPartial, I>>( + object: I + ): QuerySpotPriceResponse { + const message = createBaseQuerySpotPriceResponse() + message.spotPrice = object.spotPrice ?? "" + return message + }, +} + +function createBaseQuerySwapExactAmountInRequest(): QuerySwapExactAmountInRequest { + return { poolId: Long.UZERO, tokenIn: undefined, tokenOutDenom: "" } +} + +export const QuerySwapExactAmountInRequest = { + encode( + message: QuerySwapExactAmountInRequest, + writer: _m0.Writer = _m0.Writer.create() + ): _m0.Writer { + if (!message.poolId.isZero()) { + writer.uint32(8).uint64(message.poolId) + } + if (message.tokenIn !== undefined) { + Coin.encode(message.tokenIn, writer.uint32(18).fork()).ldelim() + } + if (message.tokenOutDenom !== "") { + writer.uint32(26).string(message.tokenOutDenom) + } + return writer + }, + + decode( + input: _m0.Reader | Uint8Array, + length?: number + ): QuerySwapExactAmountInRequest { + const reader = + input instanceof _m0.Reader ? input : _m0.Reader.create(input) + let end = length === undefined ? reader.len : reader.pos + length + const message = createBaseQuerySwapExactAmountInRequest() + while (reader.pos < end) { + const tag = reader.uint32() + switch (tag >>> 3) { + case 1: + if (tag !== 8) { + break + } + + message.poolId = reader.uint64() as Long + continue + case 2: + if (tag !== 18) { + break + } + + message.tokenIn = Coin.decode(reader, reader.uint32()) + continue + case 3: + if (tag !== 26) { + break + } + + message.tokenOutDenom = reader.string() + continue + } + if ((tag & 7) === 4 || tag === 0) { + break + } + reader.skipType(tag & 7) + } + return message + }, + + fromJSON(object: any): QuerySwapExactAmountInRequest { + return { + poolId: isSet(object.poolId) ? Long.fromValue(object.poolId) : Long.UZERO, + tokenIn: isSet(object.tokenIn) + ? Coin.fromJSON(object.tokenIn) + : undefined, + tokenOutDenom: isSet(object.tokenOutDenom) + ? String(object.tokenOutDenom) + : "", + } + }, + + toJSON(message: QuerySwapExactAmountInRequest): unknown { + const obj: any = {} + message.poolId !== undefined && + (obj.poolId = (message.poolId || Long.UZERO).toString()) + message.tokenIn !== undefined && + (obj.tokenIn = message.tokenIn ? Coin.toJSON(message.tokenIn) : undefined) + message.tokenOutDenom !== undefined && + (obj.tokenOutDenom = message.tokenOutDenom) + return obj + }, + + create, I>>( + base?: I + ): QuerySwapExactAmountInRequest { + return QuerySwapExactAmountInRequest.fromPartial(base ?? {}) + }, + + fromPartial, I>>( + object: I + ): QuerySwapExactAmountInRequest { + const message = createBaseQuerySwapExactAmountInRequest() + message.poolId = + object.poolId !== undefined && object.poolId !== null + ? Long.fromValue(object.poolId) + : Long.UZERO + message.tokenIn = + object.tokenIn !== undefined && object.tokenIn !== null + ? Coin.fromPartial(object.tokenIn) + : undefined + message.tokenOutDenom = object.tokenOutDenom ?? "" + return message + }, +} + +function createBaseQuerySwapExactAmountInResponse(): QuerySwapExactAmountInResponse { + return { tokenOut: undefined, fee: undefined } +} + +export const QuerySwapExactAmountInResponse = { + encode( + message: QuerySwapExactAmountInResponse, + writer: _m0.Writer = _m0.Writer.create() + ): _m0.Writer { + if (message.tokenOut !== undefined) { + Coin.encode(message.tokenOut, writer.uint32(18).fork()).ldelim() + } + if (message.fee !== undefined) { + Coin.encode(message.fee, writer.uint32(26).fork()).ldelim() + } + return writer + }, + + decode( + input: _m0.Reader | Uint8Array, + length?: number + ): QuerySwapExactAmountInResponse { + const reader = + input instanceof _m0.Reader ? input : _m0.Reader.create(input) + let end = length === undefined ? reader.len : reader.pos + length + const message = createBaseQuerySwapExactAmountInResponse() + while (reader.pos < end) { + const tag = reader.uint32() + switch (tag >>> 3) { + case 2: + if (tag !== 18) { + break + } + + message.tokenOut = Coin.decode(reader, reader.uint32()) + continue + case 3: + if (tag !== 26) { + break + } + + message.fee = Coin.decode(reader, reader.uint32()) + continue + } + if ((tag & 7) === 4 || tag === 0) { + break + } + reader.skipType(tag & 7) + } + return message + }, + + fromJSON(object: any): QuerySwapExactAmountInResponse { + return { + tokenOut: isSet(object.tokenOut) + ? Coin.fromJSON(object.tokenOut) + : undefined, + fee: isSet(object.fee) ? Coin.fromJSON(object.fee) : undefined, + } + }, + + toJSON(message: QuerySwapExactAmountInResponse): unknown { + const obj: any = {} + message.tokenOut !== undefined && + (obj.tokenOut = message.tokenOut + ? Coin.toJSON(message.tokenOut) + : undefined) + message.fee !== undefined && + (obj.fee = message.fee ? Coin.toJSON(message.fee) : undefined) + return obj + }, + + create, I>>( + base?: I + ): QuerySwapExactAmountInResponse { + return QuerySwapExactAmountInResponse.fromPartial(base ?? {}) + }, + + fromPartial, I>>( + object: I + ): QuerySwapExactAmountInResponse { + const message = createBaseQuerySwapExactAmountInResponse() + message.tokenOut = + object.tokenOut !== undefined && object.tokenOut !== null + ? Coin.fromPartial(object.tokenOut) + : undefined + message.fee = + object.fee !== undefined && object.fee !== null + ? Coin.fromPartial(object.fee) + : undefined + return message + }, +} + +function createBaseQuerySwapExactAmountOutRequest(): QuerySwapExactAmountOutRequest { + return { poolId: Long.UZERO, tokenOut: undefined, tokenInDenom: "" } +} + +export const QuerySwapExactAmountOutRequest = { + encode( + message: QuerySwapExactAmountOutRequest, + writer: _m0.Writer = _m0.Writer.create() + ): _m0.Writer { + if (!message.poolId.isZero()) { + writer.uint32(8).uint64(message.poolId) + } + if (message.tokenOut !== undefined) { + Coin.encode(message.tokenOut, writer.uint32(18).fork()).ldelim() + } + if (message.tokenInDenom !== "") { + writer.uint32(26).string(message.tokenInDenom) + } + return writer + }, + + decode( + input: _m0.Reader | Uint8Array, + length?: number + ): QuerySwapExactAmountOutRequest { + const reader = + input instanceof _m0.Reader ? input : _m0.Reader.create(input) + let end = length === undefined ? reader.len : reader.pos + length + const message = createBaseQuerySwapExactAmountOutRequest() + while (reader.pos < end) { + const tag = reader.uint32() + switch (tag >>> 3) { + case 1: + if (tag !== 8) { + break + } + + message.poolId = reader.uint64() as Long + continue + case 2: + if (tag !== 18) { + break + } + + message.tokenOut = Coin.decode(reader, reader.uint32()) + continue + case 3: + if (tag !== 26) { + break + } + + message.tokenInDenom = reader.string() + continue + } + if ((tag & 7) === 4 || tag === 0) { + break + } + reader.skipType(tag & 7) + } + return message + }, + + fromJSON(object: any): QuerySwapExactAmountOutRequest { + return { + poolId: isSet(object.poolId) ? Long.fromValue(object.poolId) : Long.UZERO, + tokenOut: isSet(object.tokenOut) + ? Coin.fromJSON(object.tokenOut) + : undefined, + tokenInDenom: isSet(object.tokenInDenom) + ? String(object.tokenInDenom) + : "", + } + }, + + toJSON(message: QuerySwapExactAmountOutRequest): unknown { + const obj: any = {} + message.poolId !== undefined && + (obj.poolId = (message.poolId || Long.UZERO).toString()) + message.tokenOut !== undefined && + (obj.tokenOut = message.tokenOut + ? Coin.toJSON(message.tokenOut) + : undefined) + message.tokenInDenom !== undefined && + (obj.tokenInDenom = message.tokenInDenom) + return obj + }, + + create, I>>( + base?: I + ): QuerySwapExactAmountOutRequest { + return QuerySwapExactAmountOutRequest.fromPartial(base ?? {}) + }, + + fromPartial, I>>( + object: I + ): QuerySwapExactAmountOutRequest { + const message = createBaseQuerySwapExactAmountOutRequest() + message.poolId = + object.poolId !== undefined && object.poolId !== null + ? Long.fromValue(object.poolId) + : Long.UZERO + message.tokenOut = + object.tokenOut !== undefined && object.tokenOut !== null + ? Coin.fromPartial(object.tokenOut) + : undefined + message.tokenInDenom = object.tokenInDenom ?? "" + return message + }, +} + +function createBaseQuerySwapExactAmountOutResponse(): QuerySwapExactAmountOutResponse { + return { tokenIn: undefined } +} + +export const QuerySwapExactAmountOutResponse = { + encode( + message: QuerySwapExactAmountOutResponse, + writer: _m0.Writer = _m0.Writer.create() + ): _m0.Writer { + if (message.tokenIn !== undefined) { + Coin.encode(message.tokenIn, writer.uint32(18).fork()).ldelim() + } + return writer + }, + + decode( + input: _m0.Reader | Uint8Array, + length?: number + ): QuerySwapExactAmountOutResponse { + const reader = + input instanceof _m0.Reader ? input : _m0.Reader.create(input) + let end = length === undefined ? reader.len : reader.pos + length + const message = createBaseQuerySwapExactAmountOutResponse() + while (reader.pos < end) { + const tag = reader.uint32() + switch (tag >>> 3) { + case 2: + if (tag !== 18) { + break + } + + message.tokenIn = Coin.decode(reader, reader.uint32()) + continue + } + if ((tag & 7) === 4 || tag === 0) { + break + } + reader.skipType(tag & 7) + } + return message + }, + + fromJSON(object: any): QuerySwapExactAmountOutResponse { + return { + tokenIn: isSet(object.tokenIn) + ? Coin.fromJSON(object.tokenIn) + : undefined, + } + }, + + toJSON(message: QuerySwapExactAmountOutResponse): unknown { + const obj: any = {} + message.tokenIn !== undefined && + (obj.tokenIn = message.tokenIn ? Coin.toJSON(message.tokenIn) : undefined) + return obj + }, + + create, I>>( + base?: I + ): QuerySwapExactAmountOutResponse { + return QuerySwapExactAmountOutResponse.fromPartial(base ?? {}) + }, + + fromPartial, I>>( + object: I + ): QuerySwapExactAmountOutResponse { + const message = createBaseQuerySwapExactAmountOutResponse() + message.tokenIn = + object.tokenIn !== undefined && object.tokenIn !== null + ? Coin.fromPartial(object.tokenIn) + : undefined + return message + }, +} + +function createBaseQueryJoinExactAmountInRequest(): QueryJoinExactAmountInRequest { + return { poolId: Long.UZERO, tokensIn: [] } +} + +export const QueryJoinExactAmountInRequest = { + encode( + message: QueryJoinExactAmountInRequest, + writer: _m0.Writer = _m0.Writer.create() + ): _m0.Writer { + if (!message.poolId.isZero()) { + writer.uint32(8).uint64(message.poolId) + } + for (const v of message.tokensIn) { + Coin.encode(v!, writer.uint32(18).fork()).ldelim() + } + return writer + }, + + decode( + input: _m0.Reader | Uint8Array, + length?: number + ): QueryJoinExactAmountInRequest { + const reader = + input instanceof _m0.Reader ? input : _m0.Reader.create(input) + let end = length === undefined ? reader.len : reader.pos + length + const message = createBaseQueryJoinExactAmountInRequest() + while (reader.pos < end) { + const tag = reader.uint32() + switch (tag >>> 3) { + case 1: + if (tag !== 8) { + break + } + + message.poolId = reader.uint64() as Long + continue + case 2: + if (tag !== 18) { + break + } + + message.tokensIn.push(Coin.decode(reader, reader.uint32())) + continue + } + if ((tag & 7) === 4 || tag === 0) { + break + } + reader.skipType(tag & 7) + } + return message + }, + + fromJSON(object: any): QueryJoinExactAmountInRequest { + return { + poolId: isSet(object.poolId) ? Long.fromValue(object.poolId) : Long.UZERO, + tokensIn: Array.isArray(object?.tokensIn) + ? object.tokensIn.map((e: any) => Coin.fromJSON(e)) + : [], + } + }, + + toJSON(message: QueryJoinExactAmountInRequest): unknown { + const obj: any = {} + message.poolId !== undefined && + (obj.poolId = (message.poolId || Long.UZERO).toString()) + if (message.tokensIn) { + obj.tokensIn = message.tokensIn.map((e) => + e ? Coin.toJSON(e) : undefined + ) + } else { + obj.tokensIn = [] + } + return obj + }, + + create, I>>( + base?: I + ): QueryJoinExactAmountInRequest { + return QueryJoinExactAmountInRequest.fromPartial(base ?? {}) + }, + + fromPartial, I>>( + object: I + ): QueryJoinExactAmountInRequest { + const message = createBaseQueryJoinExactAmountInRequest() + message.poolId = + object.poolId !== undefined && object.poolId !== null + ? Long.fromValue(object.poolId) + : Long.UZERO + message.tokensIn = object.tokensIn?.map((e) => Coin.fromPartial(e)) || [] + return message + }, +} + +function createBaseQueryJoinExactAmountInResponse(): QueryJoinExactAmountInResponse { + return { poolSharesOut: "", remCoins: [] } +} + +export const QueryJoinExactAmountInResponse = { + encode( + message: QueryJoinExactAmountInResponse, + writer: _m0.Writer = _m0.Writer.create() + ): _m0.Writer { + if (message.poolSharesOut !== "") { + writer.uint32(10).string(message.poolSharesOut) + } + for (const v of message.remCoins) { + Coin.encode(v!, writer.uint32(18).fork()).ldelim() + } + return writer + }, + + decode( + input: _m0.Reader | Uint8Array, + length?: number + ): QueryJoinExactAmountInResponse { + const reader = + input instanceof _m0.Reader ? input : _m0.Reader.create(input) + let end = length === undefined ? reader.len : reader.pos + length + const message = createBaseQueryJoinExactAmountInResponse() + while (reader.pos < end) { + const tag = reader.uint32() + switch (tag >>> 3) { + case 1: + if (tag !== 10) { + break + } + + message.poolSharesOut = reader.string() + continue + case 2: + if (tag !== 18) { + break + } + + message.remCoins.push(Coin.decode(reader, reader.uint32())) + continue + } + if ((tag & 7) === 4 || tag === 0) { + break + } + reader.skipType(tag & 7) + } + return message + }, + + fromJSON(object: any): QueryJoinExactAmountInResponse { + return { + poolSharesOut: isSet(object.poolSharesOut) + ? String(object.poolSharesOut) + : "", + remCoins: Array.isArray(object?.remCoins) + ? object.remCoins.map((e: any) => Coin.fromJSON(e)) + : [], + } + }, + + toJSON(message: QueryJoinExactAmountInResponse): unknown { + const obj: any = {} + message.poolSharesOut !== undefined && + (obj.poolSharesOut = message.poolSharesOut) + if (message.remCoins) { + obj.remCoins = message.remCoins.map((e) => + e ? Coin.toJSON(e) : undefined + ) + } else { + obj.remCoins = [] + } + return obj + }, + + create, I>>( + base?: I + ): QueryJoinExactAmountInResponse { + return QueryJoinExactAmountInResponse.fromPartial(base ?? {}) + }, + + fromPartial, I>>( + object: I + ): QueryJoinExactAmountInResponse { + const message = createBaseQueryJoinExactAmountInResponse() + message.poolSharesOut = object.poolSharesOut ?? "" + message.remCoins = object.remCoins?.map((e) => Coin.fromPartial(e)) || [] + return message + }, +} + +function createBaseQueryJoinExactAmountOutRequest(): QueryJoinExactAmountOutRequest { + return { poolId: Long.UZERO } +} + +export const QueryJoinExactAmountOutRequest = { + encode( + message: QueryJoinExactAmountOutRequest, + writer: _m0.Writer = _m0.Writer.create() + ): _m0.Writer { + if (!message.poolId.isZero()) { + writer.uint32(8).uint64(message.poolId) + } + return writer + }, + + decode( + input: _m0.Reader | Uint8Array, + length?: number + ): QueryJoinExactAmountOutRequest { + const reader = + input instanceof _m0.Reader ? input : _m0.Reader.create(input) + let end = length === undefined ? reader.len : reader.pos + length + const message = createBaseQueryJoinExactAmountOutRequest() + while (reader.pos < end) { + const tag = reader.uint32() + switch (tag >>> 3) { + case 1: + if (tag !== 8) { + break + } + + message.poolId = reader.uint64() as Long + continue + } + if ((tag & 7) === 4 || tag === 0) { + break + } + reader.skipType(tag & 7) + } + return message + }, + + fromJSON(object: any): QueryJoinExactAmountOutRequest { + return { + poolId: isSet(object.poolId) ? Long.fromValue(object.poolId) : Long.UZERO, + } + }, + + toJSON(message: QueryJoinExactAmountOutRequest): unknown { + const obj: any = {} + message.poolId !== undefined && + (obj.poolId = (message.poolId || Long.UZERO).toString()) + return obj + }, + + create, I>>( + base?: I + ): QueryJoinExactAmountOutRequest { + return QueryJoinExactAmountOutRequest.fromPartial(base ?? {}) + }, + + fromPartial, I>>( + object: I + ): QueryJoinExactAmountOutRequest { + const message = createBaseQueryJoinExactAmountOutRequest() + message.poolId = + object.poolId !== undefined && object.poolId !== null + ? Long.fromValue(object.poolId) + : Long.UZERO + return message + }, +} + +function createBaseQueryJoinExactAmountOutResponse(): QueryJoinExactAmountOutResponse { + return {} +} + +export const QueryJoinExactAmountOutResponse = { + encode( + _: QueryJoinExactAmountOutResponse, + writer: _m0.Writer = _m0.Writer.create() + ): _m0.Writer { + return writer + }, + + decode( + input: _m0.Reader | Uint8Array, + length?: number + ): QueryJoinExactAmountOutResponse { + const reader = + input instanceof _m0.Reader ? input : _m0.Reader.create(input) + let end = length === undefined ? reader.len : reader.pos + length + const message = createBaseQueryJoinExactAmountOutResponse() + while (reader.pos < end) { + const tag = reader.uint32() + switch (tag >>> 3) { + } + if ((tag & 7) === 4 || tag === 0) { + break + } + reader.skipType(tag & 7) + } + return message + }, + + fromJSON(_: any): QueryJoinExactAmountOutResponse { + return {} + }, + + toJSON(_: QueryJoinExactAmountOutResponse): unknown { + const obj: any = {} + return obj + }, + + create, I>>( + base?: I + ): QueryJoinExactAmountOutResponse { + return QueryJoinExactAmountOutResponse.fromPartial(base ?? {}) + }, + + fromPartial, I>>( + _: I + ): QueryJoinExactAmountOutResponse { + const message = createBaseQueryJoinExactAmountOutResponse() + return message + }, +} + +function createBaseQueryExitExactAmountInRequest(): QueryExitExactAmountInRequest { + return { poolId: Long.UZERO, poolSharesIn: "" } +} + +export const QueryExitExactAmountInRequest = { + encode( + message: QueryExitExactAmountInRequest, + writer: _m0.Writer = _m0.Writer.create() + ): _m0.Writer { + if (!message.poolId.isZero()) { + writer.uint32(8).uint64(message.poolId) + } + if (message.poolSharesIn !== "") { + writer.uint32(18).string(message.poolSharesIn) + } + return writer + }, + + decode( + input: _m0.Reader | Uint8Array, + length?: number + ): QueryExitExactAmountInRequest { + const reader = + input instanceof _m0.Reader ? input : _m0.Reader.create(input) + let end = length === undefined ? reader.len : reader.pos + length + const message = createBaseQueryExitExactAmountInRequest() + while (reader.pos < end) { + const tag = reader.uint32() + switch (tag >>> 3) { + case 1: + if (tag !== 8) { + break + } + + message.poolId = reader.uint64() as Long + continue + case 2: + if (tag !== 18) { + break + } + + message.poolSharesIn = reader.string() + continue + } + if ((tag & 7) === 4 || tag === 0) { + break + } + reader.skipType(tag & 7) + } + return message + }, + + fromJSON(object: any): QueryExitExactAmountInRequest { + return { + poolId: isSet(object.poolId) ? Long.fromValue(object.poolId) : Long.UZERO, + poolSharesIn: isSet(object.poolSharesIn) + ? String(object.poolSharesIn) + : "", + } + }, + + toJSON(message: QueryExitExactAmountInRequest): unknown { + const obj: any = {} + message.poolId !== undefined && + (obj.poolId = (message.poolId || Long.UZERO).toString()) + message.poolSharesIn !== undefined && + (obj.poolSharesIn = message.poolSharesIn) + return obj + }, + + create, I>>( + base?: I + ): QueryExitExactAmountInRequest { + return QueryExitExactAmountInRequest.fromPartial(base ?? {}) + }, + + fromPartial, I>>( + object: I + ): QueryExitExactAmountInRequest { + const message = createBaseQueryExitExactAmountInRequest() + message.poolId = + object.poolId !== undefined && object.poolId !== null + ? Long.fromValue(object.poolId) + : Long.UZERO + message.poolSharesIn = object.poolSharesIn ?? "" + return message + }, +} + +function createBaseQueryExitExactAmountInResponse(): QueryExitExactAmountInResponse { + return { tokensOut: [], fees: [] } +} + +export const QueryExitExactAmountInResponse = { + encode( + message: QueryExitExactAmountInResponse, + writer: _m0.Writer = _m0.Writer.create() + ): _m0.Writer { + for (const v of message.tokensOut) { + Coin.encode(v!, writer.uint32(10).fork()).ldelim() + } + for (const v of message.fees) { + Coin.encode(v!, writer.uint32(18).fork()).ldelim() + } + return writer + }, + + decode( + input: _m0.Reader | Uint8Array, + length?: number + ): QueryExitExactAmountInResponse { + const reader = + input instanceof _m0.Reader ? input : _m0.Reader.create(input) + let end = length === undefined ? reader.len : reader.pos + length + const message = createBaseQueryExitExactAmountInResponse() + while (reader.pos < end) { + const tag = reader.uint32() + switch (tag >>> 3) { + case 1: + if (tag !== 10) { + break + } + + message.tokensOut.push(Coin.decode(reader, reader.uint32())) + continue + case 2: + if (tag !== 18) { + break + } + + message.fees.push(Coin.decode(reader, reader.uint32())) + continue + } + if ((tag & 7) === 4 || tag === 0) { + break + } + reader.skipType(tag & 7) + } + return message + }, + + fromJSON(object: any): QueryExitExactAmountInResponse { + return { + tokensOut: Array.isArray(object?.tokensOut) + ? object.tokensOut.map((e: any) => Coin.fromJSON(e)) + : [], + fees: Array.isArray(object?.fees) + ? object.fees.map((e: any) => Coin.fromJSON(e)) + : [], + } + }, + + toJSON(message: QueryExitExactAmountInResponse): unknown { + const obj: any = {} + if (message.tokensOut) { + obj.tokensOut = message.tokensOut.map((e) => + e ? Coin.toJSON(e) : undefined + ) + } else { + obj.tokensOut = [] + } + if (message.fees) { + obj.fees = message.fees.map((e) => (e ? Coin.toJSON(e) : undefined)) + } else { + obj.fees = [] + } + return obj + }, + + create, I>>( + base?: I + ): QueryExitExactAmountInResponse { + return QueryExitExactAmountInResponse.fromPartial(base ?? {}) + }, + + fromPartial, I>>( + object: I + ): QueryExitExactAmountInResponse { + const message = createBaseQueryExitExactAmountInResponse() + message.tokensOut = object.tokensOut?.map((e) => Coin.fromPartial(e)) || [] + message.fees = object.fees?.map((e) => Coin.fromPartial(e)) || [] + return message + }, +} + +function createBaseQueryExitExactAmountOutRequest(): QueryExitExactAmountOutRequest { + return { poolId: Long.UZERO } +} + +export const QueryExitExactAmountOutRequest = { + encode( + message: QueryExitExactAmountOutRequest, + writer: _m0.Writer = _m0.Writer.create() + ): _m0.Writer { + if (!message.poolId.isZero()) { + writer.uint32(8).uint64(message.poolId) + } + return writer + }, + + decode( + input: _m0.Reader | Uint8Array, + length?: number + ): QueryExitExactAmountOutRequest { + const reader = + input instanceof _m0.Reader ? input : _m0.Reader.create(input) + let end = length === undefined ? reader.len : reader.pos + length + const message = createBaseQueryExitExactAmountOutRequest() + while (reader.pos < end) { + const tag = reader.uint32() + switch (tag >>> 3) { + case 1: + if (tag !== 8) { + break + } + + message.poolId = reader.uint64() as Long + continue + } + if ((tag & 7) === 4 || tag === 0) { + break + } + reader.skipType(tag & 7) + } + return message + }, + + fromJSON(object: any): QueryExitExactAmountOutRequest { + return { + poolId: isSet(object.poolId) ? Long.fromValue(object.poolId) : Long.UZERO, + } + }, + + toJSON(message: QueryExitExactAmountOutRequest): unknown { + const obj: any = {} + message.poolId !== undefined && + (obj.poolId = (message.poolId || Long.UZERO).toString()) + return obj + }, + + create, I>>( + base?: I + ): QueryExitExactAmountOutRequest { + return QueryExitExactAmountOutRequest.fromPartial(base ?? {}) + }, + + fromPartial, I>>( + object: I + ): QueryExitExactAmountOutRequest { + const message = createBaseQueryExitExactAmountOutRequest() + message.poolId = + object.poolId !== undefined && object.poolId !== null + ? Long.fromValue(object.poolId) + : Long.UZERO + return message + }, +} + +function createBaseQueryExitExactAmountOutResponse(): QueryExitExactAmountOutResponse { + return {} +} + +export const QueryExitExactAmountOutResponse = { + encode( + _: QueryExitExactAmountOutResponse, + writer: _m0.Writer = _m0.Writer.create() + ): _m0.Writer { + return writer + }, + + decode( + input: _m0.Reader | Uint8Array, + length?: number + ): QueryExitExactAmountOutResponse { + const reader = + input instanceof _m0.Reader ? input : _m0.Reader.create(input) + let end = length === undefined ? reader.len : reader.pos + length + const message = createBaseQueryExitExactAmountOutResponse() + while (reader.pos < end) { + const tag = reader.uint32() + switch (tag >>> 3) { + } + if ((tag & 7) === 4 || tag === 0) { + break + } + reader.skipType(tag & 7) + } + return message + }, + + fromJSON(_: any): QueryExitExactAmountOutResponse { + return {} + }, + + toJSON(_: QueryExitExactAmountOutResponse): unknown { + const obj: any = {} + return obj + }, + + create, I>>( + base?: I + ): QueryExitExactAmountOutResponse { + return QueryExitExactAmountOutResponse.fromPartial(base ?? {}) + }, + + fromPartial, I>>( + _: I + ): QueryExitExactAmountOutResponse { + const message = createBaseQueryExitExactAmountOutResponse() + return message + }, +} + +/** Query defines the gRPC querier service. */ +export interface Query { + /** Parameters of the spot module. */ + Params(request: QueryParamsRequest): Promise + /** Next available pool id number. */ + PoolNumber(request: QueryPoolNumberRequest): Promise + /** Fetch a pool by id. */ + Pool(request: QueryPoolRequest): Promise + /** Returns all pools. */ + Pools(request: QueryPoolsRequest): Promise + /** Parameters of a single pool. */ + PoolParams(request: QueryPoolParamsRequest): Promise + /** Number of pools. */ + NumPools(request: QueryNumPoolsRequest): Promise + /** Total liquidity across all pools. */ + TotalLiquidity( + request: QueryTotalLiquidityRequest + ): Promise + /** Total liquidity in a single pool. */ + TotalPoolLiquidity( + request: QueryTotalPoolLiquidityRequest + ): Promise + /** Total shares in a single pool. */ + TotalShares( + request: QueryTotalSharesRequest + ): Promise + /** Instantaneous price of an asset in a pool. */ + SpotPrice(request: QuerySpotPriceRequest): Promise + /** + * Estimates the amount of assets returned given an exact amount of tokens to + * swap. + */ + EstimateSwapExactAmountIn( + request: QuerySwapExactAmountInRequest + ): Promise + /** + * Estimates the amount of tokens required to return the exact amount of + * assets requested. + */ + EstimateSwapExactAmountOut( + request: QuerySwapExactAmountOutRequest + ): Promise + /** + * Estimates the amount of pool shares returned given an amount of tokens to + * join. + */ + EstimateJoinExactAmountIn( + request: QueryJoinExactAmountInRequest + ): Promise + /** + * Estimates the amount of tokens required to obtain an exact amount of pool + * shares. + */ + EstimateJoinExactAmountOut( + request: QueryJoinExactAmountOutRequest + ): Promise + /** + * Estimates the amount of tokens returned to the user given an exact amount + * of pool shares. + */ + EstimateExitExactAmountIn( + request: QueryExitExactAmountInRequest + ): Promise + /** + * Estimates the amount of pool shares required to extract an exact amount of + * tokens from the pool. + */ + EstimateExitExactAmountOut( + request: QueryExitExactAmountOutRequest + ): Promise +} + +export const QueryServiceName = "nibiru.spot.v1.Query" +export class QueryClientImpl implements Query { + private readonly rpc: Rpc + private readonly service: string + constructor(rpc: Rpc, opts?: { service?: string }) { + this.service = opts?.service || QueryServiceName + this.rpc = rpc + this.Params = this.Params.bind(this) + this.PoolNumber = this.PoolNumber.bind(this) + this.Pool = this.Pool.bind(this) + this.Pools = this.Pools.bind(this) + this.PoolParams = this.PoolParams.bind(this) + this.NumPools = this.NumPools.bind(this) + this.TotalLiquidity = this.TotalLiquidity.bind(this) + this.TotalPoolLiquidity = this.TotalPoolLiquidity.bind(this) + this.TotalShares = this.TotalShares.bind(this) + this.SpotPrice = this.SpotPrice.bind(this) + this.EstimateSwapExactAmountIn = this.EstimateSwapExactAmountIn.bind(this) + this.EstimateSwapExactAmountOut = this.EstimateSwapExactAmountOut.bind(this) + this.EstimateJoinExactAmountIn = this.EstimateJoinExactAmountIn.bind(this) + this.EstimateJoinExactAmountOut = this.EstimateJoinExactAmountOut.bind(this) + this.EstimateExitExactAmountIn = this.EstimateExitExactAmountIn.bind(this) + this.EstimateExitExactAmountOut = this.EstimateExitExactAmountOut.bind(this) + } + Params(request: QueryParamsRequest): Promise { + const data = QueryParamsRequest.encode(request).finish() + const promise = this.rpc.request(this.service, "Params", data) + return promise.then((data) => + QueryParamsResponse.decode(_m0.Reader.create(data)) + ) + } + + PoolNumber( + request: QueryPoolNumberRequest + ): Promise { + const data = QueryPoolNumberRequest.encode(request).finish() + const promise = this.rpc.request(this.service, "PoolNumber", data) + return promise.then((data) => + QueryPoolNumberResponse.decode(_m0.Reader.create(data)) + ) + } + + Pool(request: QueryPoolRequest): Promise { + const data = QueryPoolRequest.encode(request).finish() + const promise = this.rpc.request(this.service, "Pool", data) + return promise.then((data) => + QueryPoolResponse.decode(_m0.Reader.create(data)) + ) + } + + Pools(request: QueryPoolsRequest): Promise { + const data = QueryPoolsRequest.encode(request).finish() + const promise = this.rpc.request(this.service, "Pools", data) + return promise.then((data) => + QueryPoolsResponse.decode(_m0.Reader.create(data)) + ) + } + + PoolParams( + request: QueryPoolParamsRequest + ): Promise { + const data = QueryPoolParamsRequest.encode(request).finish() + const promise = this.rpc.request(this.service, "PoolParams", data) + return promise.then((data) => + QueryPoolParamsResponse.decode(_m0.Reader.create(data)) + ) + } + + NumPools(request: QueryNumPoolsRequest): Promise { + const data = QueryNumPoolsRequest.encode(request).finish() + const promise = this.rpc.request(this.service, "NumPools", data) + return promise.then((data) => + QueryNumPoolsResponse.decode(_m0.Reader.create(data)) + ) + } + + TotalLiquidity( + request: QueryTotalLiquidityRequest + ): Promise { + const data = QueryTotalLiquidityRequest.encode(request).finish() + const promise = this.rpc.request(this.service, "TotalLiquidity", data) + return promise.then((data) => + QueryTotalLiquidityResponse.decode(_m0.Reader.create(data)) + ) + } + + TotalPoolLiquidity( + request: QueryTotalPoolLiquidityRequest + ): Promise { + const data = QueryTotalPoolLiquidityRequest.encode(request).finish() + const promise = this.rpc.request(this.service, "TotalPoolLiquidity", data) + return promise.then((data) => + QueryTotalPoolLiquidityResponse.decode(_m0.Reader.create(data)) + ) + } + + TotalShares( + request: QueryTotalSharesRequest + ): Promise { + const data = QueryTotalSharesRequest.encode(request).finish() + const promise = this.rpc.request(this.service, "TotalShares", data) + return promise.then((data) => + QueryTotalSharesResponse.decode(_m0.Reader.create(data)) + ) + } + + SpotPrice(request: QuerySpotPriceRequest): Promise { + const data = QuerySpotPriceRequest.encode(request).finish() + const promise = this.rpc.request(this.service, "SpotPrice", data) + return promise.then((data) => + QuerySpotPriceResponse.decode(_m0.Reader.create(data)) + ) + } + + EstimateSwapExactAmountIn( + request: QuerySwapExactAmountInRequest + ): Promise { + const data = QuerySwapExactAmountInRequest.encode(request).finish() + const promise = this.rpc.request( + this.service, + "EstimateSwapExactAmountIn", + data + ) + return promise.then((data) => + QuerySwapExactAmountInResponse.decode(_m0.Reader.create(data)) + ) + } + + EstimateSwapExactAmountOut( + request: QuerySwapExactAmountOutRequest + ): Promise { + const data = QuerySwapExactAmountOutRequest.encode(request).finish() + const promise = this.rpc.request( + this.service, + "EstimateSwapExactAmountOut", + data + ) + return promise.then((data) => + QuerySwapExactAmountOutResponse.decode(_m0.Reader.create(data)) + ) + } + + EstimateJoinExactAmountIn( + request: QueryJoinExactAmountInRequest + ): Promise { + const data = QueryJoinExactAmountInRequest.encode(request).finish() + const promise = this.rpc.request( + this.service, + "EstimateJoinExactAmountIn", + data + ) + return promise.then((data) => + QueryJoinExactAmountInResponse.decode(_m0.Reader.create(data)) + ) + } + + EstimateJoinExactAmountOut( + request: QueryJoinExactAmountOutRequest + ): Promise { + const data = QueryJoinExactAmountOutRequest.encode(request).finish() + const promise = this.rpc.request( + this.service, + "EstimateJoinExactAmountOut", + data + ) + return promise.then((data) => + QueryJoinExactAmountOutResponse.decode(_m0.Reader.create(data)) + ) + } + + EstimateExitExactAmountIn( + request: QueryExitExactAmountInRequest + ): Promise { + const data = QueryExitExactAmountInRequest.encode(request).finish() + const promise = this.rpc.request( + this.service, + "EstimateExitExactAmountIn", + data + ) + return promise.then((data) => + QueryExitExactAmountInResponse.decode(_m0.Reader.create(data)) + ) + } + + EstimateExitExactAmountOut( + request: QueryExitExactAmountOutRequest + ): Promise { + const data = QueryExitExactAmountOutRequest.encode(request).finish() + const promise = this.rpc.request( + this.service, + "EstimateExitExactAmountOut", + data + ) + return promise.then((data) => + QueryExitExactAmountOutResponse.decode(_m0.Reader.create(data)) + ) + } +} + +interface Rpc { + request( + service: string, + method: string, + data: Uint8Array + ): Promise +} + +type Builtin = + | Date + | Function + | Uint8Array + | string + | number + | boolean + | undefined + +export type DeepPartial = T extends Builtin + ? T + : T extends Long + ? string | number | Long + : T extends Array + ? Array> + : T extends ReadonlyArray + ? ReadonlyArray> + : T extends {} + ? { [K in keyof T]?: DeepPartial } + : Partial + +type KeysOfUnion = T extends T ? keyof T : never +export type Exact = P extends Builtin + ? P + : P & { [K in keyof P]: Exact } & { + [K in Exclude>]: never + } + +if (_m0.util.Long !== Long) { + _m0.util.Long = Long as any + _m0.configure() +} + +function isSet(value: any): boolean { + return value !== null && value !== undefined +} diff --git a/packages/protojs/src/nibiru/spot/v1/tx.ts b/packages/protojs/src/nibiru/spot/v1/tx.ts new file mode 100644 index 00000000..3bdcd690 --- /dev/null +++ b/packages/protojs/src/nibiru/spot/v1/tx.ts @@ -0,0 +1,946 @@ +/* eslint-disable */ +import Long from "long" +import _m0 from "protobufjs/minimal" +import { Coin } from "../../../cosmos/base/v1beta1/coin" +import { Pool, PoolAsset, PoolParams } from "./pool" + +export const protobufPackage = "nibiru.spot.v1" + +export interface MsgCreatePool { + creator: string + poolParams?: PoolParams + poolAssets: PoolAsset[] +} + +export interface MsgCreatePoolResponse { + poolId: Long +} + +/** Message to join a pool (identified by poolId) with a set of tokens to deposit. */ +export interface MsgJoinPool { + sender: string + poolId: Long + tokensIn: Coin[] + useAllCoins: boolean +} + +/** Response when a user joins a pool. */ +export interface MsgJoinPoolResponse { + /** the final state of the pool after a join */ + pool?: Pool + /** sum of LP tokens minted from the join */ + numPoolSharesOut?: Coin + /** remaining tokens from attempting to join the pool */ + remainingCoins: Coin[] +} + +export interface MsgExitPool { + sender: string + poolId: Long + poolShares?: Coin +} + +export interface MsgExitPoolResponse { + tokensOut: Coin[] +} + +export interface MsgSwapAssets { + sender: string + poolId: Long + tokenIn?: Coin + tokenOutDenom: string +} + +export interface MsgSwapAssetsResponse { + tokenOut?: Coin +} + +function createBaseMsgCreatePool(): MsgCreatePool { + return { creator: "", poolParams: undefined, poolAssets: [] } +} + +export const MsgCreatePool = { + encode( + message: MsgCreatePool, + writer: _m0.Writer = _m0.Writer.create() + ): _m0.Writer { + if (message.creator !== "") { + writer.uint32(10).string(message.creator) + } + if (message.poolParams !== undefined) { + PoolParams.encode(message.poolParams, writer.uint32(18).fork()).ldelim() + } + for (const v of message.poolAssets) { + PoolAsset.encode(v!, writer.uint32(26).fork()).ldelim() + } + return writer + }, + + decode(input: _m0.Reader | Uint8Array, length?: number): MsgCreatePool { + const reader = + input instanceof _m0.Reader ? input : _m0.Reader.create(input) + let end = length === undefined ? reader.len : reader.pos + length + const message = createBaseMsgCreatePool() + while (reader.pos < end) { + const tag = reader.uint32() + switch (tag >>> 3) { + case 1: + if (tag !== 10) { + break + } + + message.creator = reader.string() + continue + case 2: + if (tag !== 18) { + break + } + + message.poolParams = PoolParams.decode(reader, reader.uint32()) + continue + case 3: + if (tag !== 26) { + break + } + + message.poolAssets.push(PoolAsset.decode(reader, reader.uint32())) + continue + } + if ((tag & 7) === 4 || tag === 0) { + break + } + reader.skipType(tag & 7) + } + return message + }, + + fromJSON(object: any): MsgCreatePool { + return { + creator: isSet(object.creator) ? String(object.creator) : "", + poolParams: isSet(object.poolParams) + ? PoolParams.fromJSON(object.poolParams) + : undefined, + poolAssets: Array.isArray(object?.poolAssets) + ? object.poolAssets.map((e: any) => PoolAsset.fromJSON(e)) + : [], + } + }, + + toJSON(message: MsgCreatePool): unknown { + const obj: any = {} + message.creator !== undefined && (obj.creator = message.creator) + message.poolParams !== undefined && + (obj.poolParams = message.poolParams + ? PoolParams.toJSON(message.poolParams) + : undefined) + if (message.poolAssets) { + obj.poolAssets = message.poolAssets.map((e) => + e ? PoolAsset.toJSON(e) : undefined + ) + } else { + obj.poolAssets = [] + } + return obj + }, + + create, I>>( + base?: I + ): MsgCreatePool { + return MsgCreatePool.fromPartial(base ?? {}) + }, + + fromPartial, I>>( + object: I + ): MsgCreatePool { + const message = createBaseMsgCreatePool() + message.creator = object.creator ?? "" + message.poolParams = + object.poolParams !== undefined && object.poolParams !== null + ? PoolParams.fromPartial(object.poolParams) + : undefined + message.poolAssets = + object.poolAssets?.map((e) => PoolAsset.fromPartial(e)) || [] + return message + }, +} + +function createBaseMsgCreatePoolResponse(): MsgCreatePoolResponse { + return { poolId: Long.UZERO } +} + +export const MsgCreatePoolResponse = { + encode( + message: MsgCreatePoolResponse, + writer: _m0.Writer = _m0.Writer.create() + ): _m0.Writer { + if (!message.poolId.isZero()) { + writer.uint32(8).uint64(message.poolId) + } + return writer + }, + + decode( + input: _m0.Reader | Uint8Array, + length?: number + ): MsgCreatePoolResponse { + const reader = + input instanceof _m0.Reader ? input : _m0.Reader.create(input) + let end = length === undefined ? reader.len : reader.pos + length + const message = createBaseMsgCreatePoolResponse() + while (reader.pos < end) { + const tag = reader.uint32() + switch (tag >>> 3) { + case 1: + if (tag !== 8) { + break + } + + message.poolId = reader.uint64() as Long + continue + } + if ((tag & 7) === 4 || tag === 0) { + break + } + reader.skipType(tag & 7) + } + return message + }, + + fromJSON(object: any): MsgCreatePoolResponse { + return { + poolId: isSet(object.poolId) ? Long.fromValue(object.poolId) : Long.UZERO, + } + }, + + toJSON(message: MsgCreatePoolResponse): unknown { + const obj: any = {} + message.poolId !== undefined && + (obj.poolId = (message.poolId || Long.UZERO).toString()) + return obj + }, + + create, I>>( + base?: I + ): MsgCreatePoolResponse { + return MsgCreatePoolResponse.fromPartial(base ?? {}) + }, + + fromPartial, I>>( + object: I + ): MsgCreatePoolResponse { + const message = createBaseMsgCreatePoolResponse() + message.poolId = + object.poolId !== undefined && object.poolId !== null + ? Long.fromValue(object.poolId) + : Long.UZERO + return message + }, +} + +function createBaseMsgJoinPool(): MsgJoinPool { + return { sender: "", poolId: Long.UZERO, tokensIn: [], useAllCoins: false } +} + +export const MsgJoinPool = { + encode( + message: MsgJoinPool, + writer: _m0.Writer = _m0.Writer.create() + ): _m0.Writer { + if (message.sender !== "") { + writer.uint32(10).string(message.sender) + } + if (!message.poolId.isZero()) { + writer.uint32(16).uint64(message.poolId) + } + for (const v of message.tokensIn) { + Coin.encode(v!, writer.uint32(26).fork()).ldelim() + } + if (message.useAllCoins === true) { + writer.uint32(32).bool(message.useAllCoins) + } + return writer + }, + + decode(input: _m0.Reader | Uint8Array, length?: number): MsgJoinPool { + const reader = + input instanceof _m0.Reader ? input : _m0.Reader.create(input) + let end = length === undefined ? reader.len : reader.pos + length + const message = createBaseMsgJoinPool() + while (reader.pos < end) { + const tag = reader.uint32() + switch (tag >>> 3) { + case 1: + if (tag !== 10) { + break + } + + message.sender = reader.string() + continue + case 2: + if (tag !== 16) { + break + } + + message.poolId = reader.uint64() as Long + continue + case 3: + if (tag !== 26) { + break + } + + message.tokensIn.push(Coin.decode(reader, reader.uint32())) + continue + case 4: + if (tag !== 32) { + break + } + + message.useAllCoins = reader.bool() + continue + } + if ((tag & 7) === 4 || tag === 0) { + break + } + reader.skipType(tag & 7) + } + return message + }, + + fromJSON(object: any): MsgJoinPool { + return { + sender: isSet(object.sender) ? String(object.sender) : "", + poolId: isSet(object.poolId) ? Long.fromValue(object.poolId) : Long.UZERO, + tokensIn: Array.isArray(object?.tokensIn) + ? object.tokensIn.map((e: any) => Coin.fromJSON(e)) + : [], + useAllCoins: isSet(object.useAllCoins) + ? Boolean(object.useAllCoins) + : false, + } + }, + + toJSON(message: MsgJoinPool): unknown { + const obj: any = {} + message.sender !== undefined && (obj.sender = message.sender) + message.poolId !== undefined && + (obj.poolId = (message.poolId || Long.UZERO).toString()) + if (message.tokensIn) { + obj.tokensIn = message.tokensIn.map((e) => + e ? Coin.toJSON(e) : undefined + ) + } else { + obj.tokensIn = [] + } + message.useAllCoins !== undefined && (obj.useAllCoins = message.useAllCoins) + return obj + }, + + create, I>>(base?: I): MsgJoinPool { + return MsgJoinPool.fromPartial(base ?? {}) + }, + + fromPartial, I>>( + object: I + ): MsgJoinPool { + const message = createBaseMsgJoinPool() + message.sender = object.sender ?? "" + message.poolId = + object.poolId !== undefined && object.poolId !== null + ? Long.fromValue(object.poolId) + : Long.UZERO + message.tokensIn = object.tokensIn?.map((e) => Coin.fromPartial(e)) || [] + message.useAllCoins = object.useAllCoins ?? false + return message + }, +} + +function createBaseMsgJoinPoolResponse(): MsgJoinPoolResponse { + return { pool: undefined, numPoolSharesOut: undefined, remainingCoins: [] } +} + +export const MsgJoinPoolResponse = { + encode( + message: MsgJoinPoolResponse, + writer: _m0.Writer = _m0.Writer.create() + ): _m0.Writer { + if (message.pool !== undefined) { + Pool.encode(message.pool, writer.uint32(10).fork()).ldelim() + } + if (message.numPoolSharesOut !== undefined) { + Coin.encode(message.numPoolSharesOut, writer.uint32(18).fork()).ldelim() + } + for (const v of message.remainingCoins) { + Coin.encode(v!, writer.uint32(26).fork()).ldelim() + } + return writer + }, + + decode(input: _m0.Reader | Uint8Array, length?: number): MsgJoinPoolResponse { + const reader = + input instanceof _m0.Reader ? input : _m0.Reader.create(input) + let end = length === undefined ? reader.len : reader.pos + length + const message = createBaseMsgJoinPoolResponse() + while (reader.pos < end) { + const tag = reader.uint32() + switch (tag >>> 3) { + case 1: + if (tag !== 10) { + break + } + + message.pool = Pool.decode(reader, reader.uint32()) + continue + case 2: + if (tag !== 18) { + break + } + + message.numPoolSharesOut = Coin.decode(reader, reader.uint32()) + continue + case 3: + if (tag !== 26) { + break + } + + message.remainingCoins.push(Coin.decode(reader, reader.uint32())) + continue + } + if ((tag & 7) === 4 || tag === 0) { + break + } + reader.skipType(tag & 7) + } + return message + }, + + fromJSON(object: any): MsgJoinPoolResponse { + return { + pool: isSet(object.pool) ? Pool.fromJSON(object.pool) : undefined, + numPoolSharesOut: isSet(object.numPoolSharesOut) + ? Coin.fromJSON(object.numPoolSharesOut) + : undefined, + remainingCoins: Array.isArray(object?.remainingCoins) + ? object.remainingCoins.map((e: any) => Coin.fromJSON(e)) + : [], + } + }, + + toJSON(message: MsgJoinPoolResponse): unknown { + const obj: any = {} + message.pool !== undefined && + (obj.pool = message.pool ? Pool.toJSON(message.pool) : undefined) + message.numPoolSharesOut !== undefined && + (obj.numPoolSharesOut = message.numPoolSharesOut + ? Coin.toJSON(message.numPoolSharesOut) + : undefined) + if (message.remainingCoins) { + obj.remainingCoins = message.remainingCoins.map((e) => + e ? Coin.toJSON(e) : undefined + ) + } else { + obj.remainingCoins = [] + } + return obj + }, + + create, I>>( + base?: I + ): MsgJoinPoolResponse { + return MsgJoinPoolResponse.fromPartial(base ?? {}) + }, + + fromPartial, I>>( + object: I + ): MsgJoinPoolResponse { + const message = createBaseMsgJoinPoolResponse() + message.pool = + object.pool !== undefined && object.pool !== null + ? Pool.fromPartial(object.pool) + : undefined + message.numPoolSharesOut = + object.numPoolSharesOut !== undefined && object.numPoolSharesOut !== null + ? Coin.fromPartial(object.numPoolSharesOut) + : undefined + message.remainingCoins = + object.remainingCoins?.map((e) => Coin.fromPartial(e)) || [] + return message + }, +} + +function createBaseMsgExitPool(): MsgExitPool { + return { sender: "", poolId: Long.UZERO, poolShares: undefined } +} + +export const MsgExitPool = { + encode( + message: MsgExitPool, + writer: _m0.Writer = _m0.Writer.create() + ): _m0.Writer { + if (message.sender !== "") { + writer.uint32(10).string(message.sender) + } + if (!message.poolId.isZero()) { + writer.uint32(16).uint64(message.poolId) + } + if (message.poolShares !== undefined) { + Coin.encode(message.poolShares, writer.uint32(26).fork()).ldelim() + } + return writer + }, + + decode(input: _m0.Reader | Uint8Array, length?: number): MsgExitPool { + const reader = + input instanceof _m0.Reader ? input : _m0.Reader.create(input) + let end = length === undefined ? reader.len : reader.pos + length + const message = createBaseMsgExitPool() + while (reader.pos < end) { + const tag = reader.uint32() + switch (tag >>> 3) { + case 1: + if (tag !== 10) { + break + } + + message.sender = reader.string() + continue + case 2: + if (tag !== 16) { + break + } + + message.poolId = reader.uint64() as Long + continue + case 3: + if (tag !== 26) { + break + } + + message.poolShares = Coin.decode(reader, reader.uint32()) + continue + } + if ((tag & 7) === 4 || tag === 0) { + break + } + reader.skipType(tag & 7) + } + return message + }, + + fromJSON(object: any): MsgExitPool { + return { + sender: isSet(object.sender) ? String(object.sender) : "", + poolId: isSet(object.poolId) ? Long.fromValue(object.poolId) : Long.UZERO, + poolShares: isSet(object.poolShares) + ? Coin.fromJSON(object.poolShares) + : undefined, + } + }, + + toJSON(message: MsgExitPool): unknown { + const obj: any = {} + message.sender !== undefined && (obj.sender = message.sender) + message.poolId !== undefined && + (obj.poolId = (message.poolId || Long.UZERO).toString()) + message.poolShares !== undefined && + (obj.poolShares = message.poolShares + ? Coin.toJSON(message.poolShares) + : undefined) + return obj + }, + + create, I>>(base?: I): MsgExitPool { + return MsgExitPool.fromPartial(base ?? {}) + }, + + fromPartial, I>>( + object: I + ): MsgExitPool { + const message = createBaseMsgExitPool() + message.sender = object.sender ?? "" + message.poolId = + object.poolId !== undefined && object.poolId !== null + ? Long.fromValue(object.poolId) + : Long.UZERO + message.poolShares = + object.poolShares !== undefined && object.poolShares !== null + ? Coin.fromPartial(object.poolShares) + : undefined + return message + }, +} + +function createBaseMsgExitPoolResponse(): MsgExitPoolResponse { + return { tokensOut: [] } +} + +export const MsgExitPoolResponse = { + encode( + message: MsgExitPoolResponse, + writer: _m0.Writer = _m0.Writer.create() + ): _m0.Writer { + for (const v of message.tokensOut) { + Coin.encode(v!, writer.uint32(26).fork()).ldelim() + } + return writer + }, + + decode(input: _m0.Reader | Uint8Array, length?: number): MsgExitPoolResponse { + const reader = + input instanceof _m0.Reader ? input : _m0.Reader.create(input) + let end = length === undefined ? reader.len : reader.pos + length + const message = createBaseMsgExitPoolResponse() + while (reader.pos < end) { + const tag = reader.uint32() + switch (tag >>> 3) { + case 3: + if (tag !== 26) { + break + } + + message.tokensOut.push(Coin.decode(reader, reader.uint32())) + continue + } + if ((tag & 7) === 4 || tag === 0) { + break + } + reader.skipType(tag & 7) + } + return message + }, + + fromJSON(object: any): MsgExitPoolResponse { + return { + tokensOut: Array.isArray(object?.tokensOut) + ? object.tokensOut.map((e: any) => Coin.fromJSON(e)) + : [], + } + }, + + toJSON(message: MsgExitPoolResponse): unknown { + const obj: any = {} + if (message.tokensOut) { + obj.tokensOut = message.tokensOut.map((e) => + e ? Coin.toJSON(e) : undefined + ) + } else { + obj.tokensOut = [] + } + return obj + }, + + create, I>>( + base?: I + ): MsgExitPoolResponse { + return MsgExitPoolResponse.fromPartial(base ?? {}) + }, + + fromPartial, I>>( + object: I + ): MsgExitPoolResponse { + const message = createBaseMsgExitPoolResponse() + message.tokensOut = object.tokensOut?.map((e) => Coin.fromPartial(e)) || [] + return message + }, +} + +function createBaseMsgSwapAssets(): MsgSwapAssets { + return { + sender: "", + poolId: Long.UZERO, + tokenIn: undefined, + tokenOutDenom: "", + } +} + +export const MsgSwapAssets = { + encode( + message: MsgSwapAssets, + writer: _m0.Writer = _m0.Writer.create() + ): _m0.Writer { + if (message.sender !== "") { + writer.uint32(10).string(message.sender) + } + if (!message.poolId.isZero()) { + writer.uint32(16).uint64(message.poolId) + } + if (message.tokenIn !== undefined) { + Coin.encode(message.tokenIn, writer.uint32(26).fork()).ldelim() + } + if (message.tokenOutDenom !== "") { + writer.uint32(34).string(message.tokenOutDenom) + } + return writer + }, + + decode(input: _m0.Reader | Uint8Array, length?: number): MsgSwapAssets { + const reader = + input instanceof _m0.Reader ? input : _m0.Reader.create(input) + let end = length === undefined ? reader.len : reader.pos + length + const message = createBaseMsgSwapAssets() + while (reader.pos < end) { + const tag = reader.uint32() + switch (tag >>> 3) { + case 1: + if (tag !== 10) { + break + } + + message.sender = reader.string() + continue + case 2: + if (tag !== 16) { + break + } + + message.poolId = reader.uint64() as Long + continue + case 3: + if (tag !== 26) { + break + } + + message.tokenIn = Coin.decode(reader, reader.uint32()) + continue + case 4: + if (tag !== 34) { + break + } + + message.tokenOutDenom = reader.string() + continue + } + if ((tag & 7) === 4 || tag === 0) { + break + } + reader.skipType(tag & 7) + } + return message + }, + + fromJSON(object: any): MsgSwapAssets { + return { + sender: isSet(object.sender) ? String(object.sender) : "", + poolId: isSet(object.poolId) ? Long.fromValue(object.poolId) : Long.UZERO, + tokenIn: isSet(object.tokenIn) + ? Coin.fromJSON(object.tokenIn) + : undefined, + tokenOutDenom: isSet(object.tokenOutDenom) + ? String(object.tokenOutDenom) + : "", + } + }, + + toJSON(message: MsgSwapAssets): unknown { + const obj: any = {} + message.sender !== undefined && (obj.sender = message.sender) + message.poolId !== undefined && + (obj.poolId = (message.poolId || Long.UZERO).toString()) + message.tokenIn !== undefined && + (obj.tokenIn = message.tokenIn ? Coin.toJSON(message.tokenIn) : undefined) + message.tokenOutDenom !== undefined && + (obj.tokenOutDenom = message.tokenOutDenom) + return obj + }, + + create, I>>( + base?: I + ): MsgSwapAssets { + return MsgSwapAssets.fromPartial(base ?? {}) + }, + + fromPartial, I>>( + object: I + ): MsgSwapAssets { + const message = createBaseMsgSwapAssets() + message.sender = object.sender ?? "" + message.poolId = + object.poolId !== undefined && object.poolId !== null + ? Long.fromValue(object.poolId) + : Long.UZERO + message.tokenIn = + object.tokenIn !== undefined && object.tokenIn !== null + ? Coin.fromPartial(object.tokenIn) + : undefined + message.tokenOutDenom = object.tokenOutDenom ?? "" + return message + }, +} + +function createBaseMsgSwapAssetsResponse(): MsgSwapAssetsResponse { + return { tokenOut: undefined } +} + +export const MsgSwapAssetsResponse = { + encode( + message: MsgSwapAssetsResponse, + writer: _m0.Writer = _m0.Writer.create() + ): _m0.Writer { + if (message.tokenOut !== undefined) { + Coin.encode(message.tokenOut, writer.uint32(26).fork()).ldelim() + } + return writer + }, + + decode( + input: _m0.Reader | Uint8Array, + length?: number + ): MsgSwapAssetsResponse { + const reader = + input instanceof _m0.Reader ? input : _m0.Reader.create(input) + let end = length === undefined ? reader.len : reader.pos + length + const message = createBaseMsgSwapAssetsResponse() + while (reader.pos < end) { + const tag = reader.uint32() + switch (tag >>> 3) { + case 3: + if (tag !== 26) { + break + } + + message.tokenOut = Coin.decode(reader, reader.uint32()) + continue + } + if ((tag & 7) === 4 || tag === 0) { + break + } + reader.skipType(tag & 7) + } + return message + }, + + fromJSON(object: any): MsgSwapAssetsResponse { + return { + tokenOut: isSet(object.tokenOut) + ? Coin.fromJSON(object.tokenOut) + : undefined, + } + }, + + toJSON(message: MsgSwapAssetsResponse): unknown { + const obj: any = {} + message.tokenOut !== undefined && + (obj.tokenOut = message.tokenOut + ? Coin.toJSON(message.tokenOut) + : undefined) + return obj + }, + + create, I>>( + base?: I + ): MsgSwapAssetsResponse { + return MsgSwapAssetsResponse.fromPartial(base ?? {}) + }, + + fromPartial, I>>( + object: I + ): MsgSwapAssetsResponse { + const message = createBaseMsgSwapAssetsResponse() + message.tokenOut = + object.tokenOut !== undefined && object.tokenOut !== null + ? Coin.fromPartial(object.tokenOut) + : undefined + return message + }, +} + +/** Msg defines the Msg service. */ +export interface Msg { + /** Used to create a pool. */ + CreatePool(request: MsgCreatePool): Promise + /** Join a pool as a liquidity provider. */ + JoinPool(request: MsgJoinPool): Promise + /** Exit a pool position by returning LP shares */ + ExitPool(request: MsgExitPool): Promise + /** Swap assets in a pool */ + SwapAssets(request: MsgSwapAssets): Promise +} + +export const MsgServiceName = "nibiru.spot.v1.Msg" +export class MsgClientImpl implements Msg { + private readonly rpc: Rpc + private readonly service: string + constructor(rpc: Rpc, opts?: { service?: string }) { + this.service = opts?.service || MsgServiceName + this.rpc = rpc + this.CreatePool = this.CreatePool.bind(this) + this.JoinPool = this.JoinPool.bind(this) + this.ExitPool = this.ExitPool.bind(this) + this.SwapAssets = this.SwapAssets.bind(this) + } + CreatePool(request: MsgCreatePool): Promise { + const data = MsgCreatePool.encode(request).finish() + const promise = this.rpc.request(this.service, "CreatePool", data) + return promise.then((data) => + MsgCreatePoolResponse.decode(_m0.Reader.create(data)) + ) + } + + JoinPool(request: MsgJoinPool): Promise { + const data = MsgJoinPool.encode(request).finish() + const promise = this.rpc.request(this.service, "JoinPool", data) + return promise.then((data) => + MsgJoinPoolResponse.decode(_m0.Reader.create(data)) + ) + } + + ExitPool(request: MsgExitPool): Promise { + const data = MsgExitPool.encode(request).finish() + const promise = this.rpc.request(this.service, "ExitPool", data) + return promise.then((data) => + MsgExitPoolResponse.decode(_m0.Reader.create(data)) + ) + } + + SwapAssets(request: MsgSwapAssets): Promise { + const data = MsgSwapAssets.encode(request).finish() + const promise = this.rpc.request(this.service, "SwapAssets", data) + return promise.then((data) => + MsgSwapAssetsResponse.decode(_m0.Reader.create(data)) + ) + } +} + +interface Rpc { + request( + service: string, + method: string, + data: Uint8Array + ): Promise +} + +type Builtin = + | Date + | Function + | Uint8Array + | string + | number + | boolean + | undefined + +export type DeepPartial = T extends Builtin + ? T + : T extends Long + ? string | number | Long + : T extends Array + ? Array> + : T extends ReadonlyArray + ? ReadonlyArray> + : T extends {} + ? { [K in keyof T]?: DeepPartial } + : Partial + +type KeysOfUnion = T extends T ? keyof T : never +export type Exact = P extends Builtin + ? P + : P & { [K in keyof P]: Exact } & { + [K in Exclude>]: never + } + +if (_m0.util.Long !== Long) { + _m0.util.Long = Long as any + _m0.configure() +} + +function isSet(value: any): boolean { + return value !== null && value !== undefined +} diff --git a/packages/protojs/src/nibiru/stablecoin/v1/events.ts b/packages/protojs/src/nibiru/stablecoin/v1/events.ts new file mode 100644 index 00000000..36e8715f --- /dev/null +++ b/packages/protojs/src/nibiru/stablecoin/v1/events.ts @@ -0,0 +1,664 @@ +/* eslint-disable */ +import Long from "long" +import _m0 from "protobufjs/minimal" +import { Coin } from "../../../cosmos/base/v1beta1/coin" + +export const protobufPackage = "nibiru.stablecoin.v1" + +export interface EventTransfer { + coin?: Coin + from: string + to: string +} + +export interface EventMintStable { + amount: string +} + +export interface EventBurnStable { + amount: string +} + +export interface EventMintNIBI { + amount: string +} + +export interface EventBurnNIBI { + amount: string +} + +export interface EventRecollateralize { + caller: string + inCoin?: Coin + outCoin?: Coin + collRatio: string +} + +export interface EventBuyback { + caller: string + inCoin?: Coin + outCoin?: Coin + collRatio: string +} + +function createBaseEventTransfer(): EventTransfer { + return { coin: undefined, from: "", to: "" } +} + +export const EventTransfer = { + encode( + message: EventTransfer, + writer: _m0.Writer = _m0.Writer.create() + ): _m0.Writer { + if (message.coin !== undefined) { + Coin.encode(message.coin, writer.uint32(10).fork()).ldelim() + } + if (message.from !== "") { + writer.uint32(18).string(message.from) + } + if (message.to !== "") { + writer.uint32(26).string(message.to) + } + return writer + }, + + decode(input: _m0.Reader | Uint8Array, length?: number): EventTransfer { + const reader = + input instanceof _m0.Reader ? input : _m0.Reader.create(input) + let end = length === undefined ? reader.len : reader.pos + length + const message = createBaseEventTransfer() + while (reader.pos < end) { + const tag = reader.uint32() + switch (tag >>> 3) { + case 1: + if (tag !== 10) { + break + } + + message.coin = Coin.decode(reader, reader.uint32()) + continue + case 2: + if (tag !== 18) { + break + } + + message.from = reader.string() + continue + case 3: + if (tag !== 26) { + break + } + + message.to = reader.string() + continue + } + if ((tag & 7) === 4 || tag === 0) { + break + } + reader.skipType(tag & 7) + } + return message + }, + + fromJSON(object: any): EventTransfer { + return { + coin: isSet(object.coin) ? Coin.fromJSON(object.coin) : undefined, + from: isSet(object.from) ? String(object.from) : "", + to: isSet(object.to) ? String(object.to) : "", + } + }, + + toJSON(message: EventTransfer): unknown { + const obj: any = {} + message.coin !== undefined && + (obj.coin = message.coin ? Coin.toJSON(message.coin) : undefined) + message.from !== undefined && (obj.from = message.from) + message.to !== undefined && (obj.to = message.to) + return obj + }, + + create, I>>( + base?: I + ): EventTransfer { + return EventTransfer.fromPartial(base ?? {}) + }, + + fromPartial, I>>( + object: I + ): EventTransfer { + const message = createBaseEventTransfer() + message.coin = + object.coin !== undefined && object.coin !== null + ? Coin.fromPartial(object.coin) + : undefined + message.from = object.from ?? "" + message.to = object.to ?? "" + return message + }, +} + +function createBaseEventMintStable(): EventMintStable { + return { amount: "" } +} + +export const EventMintStable = { + encode( + message: EventMintStable, + writer: _m0.Writer = _m0.Writer.create() + ): _m0.Writer { + if (message.amount !== "") { + writer.uint32(10).string(message.amount) + } + return writer + }, + + decode(input: _m0.Reader | Uint8Array, length?: number): EventMintStable { + const reader = + input instanceof _m0.Reader ? input : _m0.Reader.create(input) + let end = length === undefined ? reader.len : reader.pos + length + const message = createBaseEventMintStable() + while (reader.pos < end) { + const tag = reader.uint32() + switch (tag >>> 3) { + case 1: + if (tag !== 10) { + break + } + + message.amount = reader.string() + continue + } + if ((tag & 7) === 4 || tag === 0) { + break + } + reader.skipType(tag & 7) + } + return message + }, + + fromJSON(object: any): EventMintStable { + return { amount: isSet(object.amount) ? String(object.amount) : "" } + }, + + toJSON(message: EventMintStable): unknown { + const obj: any = {} + message.amount !== undefined && (obj.amount = message.amount) + return obj + }, + + create, I>>( + base?: I + ): EventMintStable { + return EventMintStable.fromPartial(base ?? {}) + }, + + fromPartial, I>>( + object: I + ): EventMintStable { + const message = createBaseEventMintStable() + message.amount = object.amount ?? "" + return message + }, +} + +function createBaseEventBurnStable(): EventBurnStable { + return { amount: "" } +} + +export const EventBurnStable = { + encode( + message: EventBurnStable, + writer: _m0.Writer = _m0.Writer.create() + ): _m0.Writer { + if (message.amount !== "") { + writer.uint32(10).string(message.amount) + } + return writer + }, + + decode(input: _m0.Reader | Uint8Array, length?: number): EventBurnStable { + const reader = + input instanceof _m0.Reader ? input : _m0.Reader.create(input) + let end = length === undefined ? reader.len : reader.pos + length + const message = createBaseEventBurnStable() + while (reader.pos < end) { + const tag = reader.uint32() + switch (tag >>> 3) { + case 1: + if (tag !== 10) { + break + } + + message.amount = reader.string() + continue + } + if ((tag & 7) === 4 || tag === 0) { + break + } + reader.skipType(tag & 7) + } + return message + }, + + fromJSON(object: any): EventBurnStable { + return { amount: isSet(object.amount) ? String(object.amount) : "" } + }, + + toJSON(message: EventBurnStable): unknown { + const obj: any = {} + message.amount !== undefined && (obj.amount = message.amount) + return obj + }, + + create, I>>( + base?: I + ): EventBurnStable { + return EventBurnStable.fromPartial(base ?? {}) + }, + + fromPartial, I>>( + object: I + ): EventBurnStable { + const message = createBaseEventBurnStable() + message.amount = object.amount ?? "" + return message + }, +} + +function createBaseEventMintNIBI(): EventMintNIBI { + return { amount: "" } +} + +export const EventMintNIBI = { + encode( + message: EventMintNIBI, + writer: _m0.Writer = _m0.Writer.create() + ): _m0.Writer { + if (message.amount !== "") { + writer.uint32(10).string(message.amount) + } + return writer + }, + + decode(input: _m0.Reader | Uint8Array, length?: number): EventMintNIBI { + const reader = + input instanceof _m0.Reader ? input : _m0.Reader.create(input) + let end = length === undefined ? reader.len : reader.pos + length + const message = createBaseEventMintNIBI() + while (reader.pos < end) { + const tag = reader.uint32() + switch (tag >>> 3) { + case 1: + if (tag !== 10) { + break + } + + message.amount = reader.string() + continue + } + if ((tag & 7) === 4 || tag === 0) { + break + } + reader.skipType(tag & 7) + } + return message + }, + + fromJSON(object: any): EventMintNIBI { + return { amount: isSet(object.amount) ? String(object.amount) : "" } + }, + + toJSON(message: EventMintNIBI): unknown { + const obj: any = {} + message.amount !== undefined && (obj.amount = message.amount) + return obj + }, + + create, I>>( + base?: I + ): EventMintNIBI { + return EventMintNIBI.fromPartial(base ?? {}) + }, + + fromPartial, I>>( + object: I + ): EventMintNIBI { + const message = createBaseEventMintNIBI() + message.amount = object.amount ?? "" + return message + }, +} + +function createBaseEventBurnNIBI(): EventBurnNIBI { + return { amount: "" } +} + +export const EventBurnNIBI = { + encode( + message: EventBurnNIBI, + writer: _m0.Writer = _m0.Writer.create() + ): _m0.Writer { + if (message.amount !== "") { + writer.uint32(10).string(message.amount) + } + return writer + }, + + decode(input: _m0.Reader | Uint8Array, length?: number): EventBurnNIBI { + const reader = + input instanceof _m0.Reader ? input : _m0.Reader.create(input) + let end = length === undefined ? reader.len : reader.pos + length + const message = createBaseEventBurnNIBI() + while (reader.pos < end) { + const tag = reader.uint32() + switch (tag >>> 3) { + case 1: + if (tag !== 10) { + break + } + + message.amount = reader.string() + continue + } + if ((tag & 7) === 4 || tag === 0) { + break + } + reader.skipType(tag & 7) + } + return message + }, + + fromJSON(object: any): EventBurnNIBI { + return { amount: isSet(object.amount) ? String(object.amount) : "" } + }, + + toJSON(message: EventBurnNIBI): unknown { + const obj: any = {} + message.amount !== undefined && (obj.amount = message.amount) + return obj + }, + + create, I>>( + base?: I + ): EventBurnNIBI { + return EventBurnNIBI.fromPartial(base ?? {}) + }, + + fromPartial, I>>( + object: I + ): EventBurnNIBI { + const message = createBaseEventBurnNIBI() + message.amount = object.amount ?? "" + return message + }, +} + +function createBaseEventRecollateralize(): EventRecollateralize { + return { caller: "", inCoin: undefined, outCoin: undefined, collRatio: "" } +} + +export const EventRecollateralize = { + encode( + message: EventRecollateralize, + writer: _m0.Writer = _m0.Writer.create() + ): _m0.Writer { + if (message.caller !== "") { + writer.uint32(10).string(message.caller) + } + if (message.inCoin !== undefined) { + Coin.encode(message.inCoin, writer.uint32(18).fork()).ldelim() + } + if (message.outCoin !== undefined) { + Coin.encode(message.outCoin, writer.uint32(26).fork()).ldelim() + } + if (message.collRatio !== "") { + writer.uint32(34).string(message.collRatio) + } + return writer + }, + + decode( + input: _m0.Reader | Uint8Array, + length?: number + ): EventRecollateralize { + const reader = + input instanceof _m0.Reader ? input : _m0.Reader.create(input) + let end = length === undefined ? reader.len : reader.pos + length + const message = createBaseEventRecollateralize() + while (reader.pos < end) { + const tag = reader.uint32() + switch (tag >>> 3) { + case 1: + if (tag !== 10) { + break + } + + message.caller = reader.string() + continue + case 2: + if (tag !== 18) { + break + } + + message.inCoin = Coin.decode(reader, reader.uint32()) + continue + case 3: + if (tag !== 26) { + break + } + + message.outCoin = Coin.decode(reader, reader.uint32()) + continue + case 4: + if (tag !== 34) { + break + } + + message.collRatio = reader.string() + continue + } + if ((tag & 7) === 4 || tag === 0) { + break + } + reader.skipType(tag & 7) + } + return message + }, + + fromJSON(object: any): EventRecollateralize { + return { + caller: isSet(object.caller) ? String(object.caller) : "", + inCoin: isSet(object.inCoin) ? Coin.fromJSON(object.inCoin) : undefined, + outCoin: isSet(object.outCoin) + ? Coin.fromJSON(object.outCoin) + : undefined, + collRatio: isSet(object.collRatio) ? String(object.collRatio) : "", + } + }, + + toJSON(message: EventRecollateralize): unknown { + const obj: any = {} + message.caller !== undefined && (obj.caller = message.caller) + message.inCoin !== undefined && + (obj.inCoin = message.inCoin ? Coin.toJSON(message.inCoin) : undefined) + message.outCoin !== undefined && + (obj.outCoin = message.outCoin ? Coin.toJSON(message.outCoin) : undefined) + message.collRatio !== undefined && (obj.collRatio = message.collRatio) + return obj + }, + + create, I>>( + base?: I + ): EventRecollateralize { + return EventRecollateralize.fromPartial(base ?? {}) + }, + + fromPartial, I>>( + object: I + ): EventRecollateralize { + const message = createBaseEventRecollateralize() + message.caller = object.caller ?? "" + message.inCoin = + object.inCoin !== undefined && object.inCoin !== null + ? Coin.fromPartial(object.inCoin) + : undefined + message.outCoin = + object.outCoin !== undefined && object.outCoin !== null + ? Coin.fromPartial(object.outCoin) + : undefined + message.collRatio = object.collRatio ?? "" + return message + }, +} + +function createBaseEventBuyback(): EventBuyback { + return { caller: "", inCoin: undefined, outCoin: undefined, collRatio: "" } +} + +export const EventBuyback = { + encode( + message: EventBuyback, + writer: _m0.Writer = _m0.Writer.create() + ): _m0.Writer { + if (message.caller !== "") { + writer.uint32(10).string(message.caller) + } + if (message.inCoin !== undefined) { + Coin.encode(message.inCoin, writer.uint32(18).fork()).ldelim() + } + if (message.outCoin !== undefined) { + Coin.encode(message.outCoin, writer.uint32(26).fork()).ldelim() + } + if (message.collRatio !== "") { + writer.uint32(34).string(message.collRatio) + } + return writer + }, + + decode(input: _m0.Reader | Uint8Array, length?: number): EventBuyback { + const reader = + input instanceof _m0.Reader ? input : _m0.Reader.create(input) + let end = length === undefined ? reader.len : reader.pos + length + const message = createBaseEventBuyback() + while (reader.pos < end) { + const tag = reader.uint32() + switch (tag >>> 3) { + case 1: + if (tag !== 10) { + break + } + + message.caller = reader.string() + continue + case 2: + if (tag !== 18) { + break + } + + message.inCoin = Coin.decode(reader, reader.uint32()) + continue + case 3: + if (tag !== 26) { + break + } + + message.outCoin = Coin.decode(reader, reader.uint32()) + continue + case 4: + if (tag !== 34) { + break + } + + message.collRatio = reader.string() + continue + } + if ((tag & 7) === 4 || tag === 0) { + break + } + reader.skipType(tag & 7) + } + return message + }, + + fromJSON(object: any): EventBuyback { + return { + caller: isSet(object.caller) ? String(object.caller) : "", + inCoin: isSet(object.inCoin) ? Coin.fromJSON(object.inCoin) : undefined, + outCoin: isSet(object.outCoin) + ? Coin.fromJSON(object.outCoin) + : undefined, + collRatio: isSet(object.collRatio) ? String(object.collRatio) : "", + } + }, + + toJSON(message: EventBuyback): unknown { + const obj: any = {} + message.caller !== undefined && (obj.caller = message.caller) + message.inCoin !== undefined && + (obj.inCoin = message.inCoin ? Coin.toJSON(message.inCoin) : undefined) + message.outCoin !== undefined && + (obj.outCoin = message.outCoin ? Coin.toJSON(message.outCoin) : undefined) + message.collRatio !== undefined && (obj.collRatio = message.collRatio) + return obj + }, + + create, I>>( + base?: I + ): EventBuyback { + return EventBuyback.fromPartial(base ?? {}) + }, + + fromPartial, I>>( + object: I + ): EventBuyback { + const message = createBaseEventBuyback() + message.caller = object.caller ?? "" + message.inCoin = + object.inCoin !== undefined && object.inCoin !== null + ? Coin.fromPartial(object.inCoin) + : undefined + message.outCoin = + object.outCoin !== undefined && object.outCoin !== null + ? Coin.fromPartial(object.outCoin) + : undefined + message.collRatio = object.collRatio ?? "" + return message + }, +} + +type Builtin = + | Date + | Function + | Uint8Array + | string + | number + | boolean + | undefined + +export type DeepPartial = T extends Builtin + ? T + : T extends Long + ? string | number | Long + : T extends Array + ? Array> + : T extends ReadonlyArray + ? ReadonlyArray> + : T extends {} + ? { [K in keyof T]?: DeepPartial } + : Partial + +type KeysOfUnion = T extends T ? keyof T : never +export type Exact = P extends Builtin + ? P + : P & { [K in keyof P]: Exact } & { + [K in Exclude>]: never + } + +if (_m0.util.Long !== Long) { + _m0.util.Long = Long as any + _m0.configure() +} + +function isSet(value: any): boolean { + return value !== null && value !== undefined +} diff --git a/packages/protojs/src/nibiru/stablecoin/v1/genesis.ts b/packages/protojs/src/nibiru/stablecoin/v1/genesis.ts new file mode 100644 index 00000000..d5fe7038 --- /dev/null +++ b/packages/protojs/src/nibiru/stablecoin/v1/genesis.ts @@ -0,0 +1,145 @@ +/* eslint-disable */ +import Long from "long" +import _m0 from "protobufjs/minimal" +import { Coin } from "../../../cosmos/base/v1beta1/coin" +import { Params } from "./params" + +export const protobufPackage = "nibiru.stablecoin.v1" + +/** GenesisState defines the stablecoin module's genesis state. */ +export interface GenesisState { + params?: Params + moduleAccountBalance?: Coin +} + +function createBaseGenesisState(): GenesisState { + return { params: undefined, moduleAccountBalance: undefined } +} + +export const GenesisState = { + encode( + message: GenesisState, + writer: _m0.Writer = _m0.Writer.create() + ): _m0.Writer { + if (message.params !== undefined) { + Params.encode(message.params, writer.uint32(10).fork()).ldelim() + } + if (message.moduleAccountBalance !== undefined) { + Coin.encode( + message.moduleAccountBalance, + writer.uint32(18).fork() + ).ldelim() + } + return writer + }, + + decode(input: _m0.Reader | Uint8Array, length?: number): GenesisState { + const reader = + input instanceof _m0.Reader ? input : _m0.Reader.create(input) + let end = length === undefined ? reader.len : reader.pos + length + const message = createBaseGenesisState() + while (reader.pos < end) { + const tag = reader.uint32() + switch (tag >>> 3) { + case 1: + if (tag !== 10) { + break + } + + message.params = Params.decode(reader, reader.uint32()) + continue + case 2: + if (tag !== 18) { + break + } + + message.moduleAccountBalance = Coin.decode(reader, reader.uint32()) + continue + } + if ((tag & 7) === 4 || tag === 0) { + break + } + reader.skipType(tag & 7) + } + return message + }, + + fromJSON(object: any): GenesisState { + return { + params: isSet(object.params) ? Params.fromJSON(object.params) : undefined, + moduleAccountBalance: isSet(object.moduleAccountBalance) + ? Coin.fromJSON(object.moduleAccountBalance) + : undefined, + } + }, + + toJSON(message: GenesisState): unknown { + const obj: any = {} + message.params !== undefined && + (obj.params = message.params ? Params.toJSON(message.params) : undefined) + message.moduleAccountBalance !== undefined && + (obj.moduleAccountBalance = message.moduleAccountBalance + ? Coin.toJSON(message.moduleAccountBalance) + : undefined) + return obj + }, + + create, I>>( + base?: I + ): GenesisState { + return GenesisState.fromPartial(base ?? {}) + }, + + fromPartial, I>>( + object: I + ): GenesisState { + const message = createBaseGenesisState() + message.params = + object.params !== undefined && object.params !== null + ? Params.fromPartial(object.params) + : undefined + message.moduleAccountBalance = + object.moduleAccountBalance !== undefined && + object.moduleAccountBalance !== null + ? Coin.fromPartial(object.moduleAccountBalance) + : undefined + return message + }, +} + +type Builtin = + | Date + | Function + | Uint8Array + | string + | number + | boolean + | undefined + +export type DeepPartial = T extends Builtin + ? T + : T extends Long + ? string | number | Long + : T extends Array + ? Array> + : T extends ReadonlyArray + ? ReadonlyArray> + : T extends {} + ? { [K in keyof T]?: DeepPartial } + : Partial + +type KeysOfUnion = T extends T ? keyof T : never +export type Exact = P extends Builtin + ? P + : P & { [K in keyof P]: Exact } & { + [K in Exclude>]: never + } + +if (_m0.util.Long !== Long) { + _m0.util.Long = Long as any + _m0.configure() +} + +function isSet(value: any): boolean { + return value !== null && value !== undefined +} diff --git a/packages/protojs/src/nibiru/stablecoin/v1/params.ts b/packages/protojs/src/nibiru/stablecoin/v1/params.ts new file mode 100644 index 00000000..15b3e478 --- /dev/null +++ b/packages/protojs/src/nibiru/stablecoin/v1/params.ts @@ -0,0 +1,303 @@ +/* eslint-disable */ +import Long from "long" +import _m0 from "protobufjs/minimal" + +export const protobufPackage = "nibiru.stablecoin.v1" + +/** Params defines the parameters for the module. */ +export interface Params { + /** collRatio is the ratio needed as collateral to exchange for stables */ + collRatio: Long + /** feeRatio is the ratio taken as fees when minting or burning stables */ + feeRatio: Long + /** efFeeRatio is the ratio taken from the fees that goes to Ecosystem Fund */ + efFeeRatio: Long + /** + * BonusRateRecoll is the percentage of extra stablecoin value given to the + * caller of 'Recollateralize' in units of governance tokens. + */ + bonusRateRecoll: Long + /** + * distr_epoch_identifier defines the frequnecy of update for the collateral + * ratio + */ + distrEpochIdentifier: string + /** + * adjustmentStep is the size of the step taken when updating the collateral + * ratio + */ + adjustmentStep: Long + /** + * priceLowerBound is the lower bound for the stable coin to trigger a + * collateral ratio update + */ + priceLowerBound: Long + /** + * priceUpperBound is the upper bound for the stable coin to trigger a + * collateral ratio update + */ + priceUpperBound: Long + /** isCollateralRatioValid checks if the collateral ratio is correctly updated */ + isCollateralRatioValid: boolean +} + +function createBaseParams(): Params { + return { + collRatio: Long.ZERO, + feeRatio: Long.ZERO, + efFeeRatio: Long.ZERO, + bonusRateRecoll: Long.ZERO, + distrEpochIdentifier: "", + adjustmentStep: Long.ZERO, + priceLowerBound: Long.ZERO, + priceUpperBound: Long.ZERO, + isCollateralRatioValid: false, + } +} + +export const Params = { + encode( + message: Params, + writer: _m0.Writer = _m0.Writer.create() + ): _m0.Writer { + if (!message.collRatio.isZero()) { + writer.uint32(8).int64(message.collRatio) + } + if (!message.feeRatio.isZero()) { + writer.uint32(16).int64(message.feeRatio) + } + if (!message.efFeeRatio.isZero()) { + writer.uint32(24).int64(message.efFeeRatio) + } + if (!message.bonusRateRecoll.isZero()) { + writer.uint32(32).int64(message.bonusRateRecoll) + } + if (message.distrEpochIdentifier !== "") { + writer.uint32(42).string(message.distrEpochIdentifier) + } + if (!message.adjustmentStep.isZero()) { + writer.uint32(48).int64(message.adjustmentStep) + } + if (!message.priceLowerBound.isZero()) { + writer.uint32(56).int64(message.priceLowerBound) + } + if (!message.priceUpperBound.isZero()) { + writer.uint32(64).int64(message.priceUpperBound) + } + if (message.isCollateralRatioValid === true) { + writer.uint32(72).bool(message.isCollateralRatioValid) + } + return writer + }, + + decode(input: _m0.Reader | Uint8Array, length?: number): Params { + const reader = + input instanceof _m0.Reader ? input : _m0.Reader.create(input) + let end = length === undefined ? reader.len : reader.pos + length + const message = createBaseParams() + while (reader.pos < end) { + const tag = reader.uint32() + switch (tag >>> 3) { + case 1: + if (tag !== 8) { + break + } + + message.collRatio = reader.int64() as Long + continue + case 2: + if (tag !== 16) { + break + } + + message.feeRatio = reader.int64() as Long + continue + case 3: + if (tag !== 24) { + break + } + + message.efFeeRatio = reader.int64() as Long + continue + case 4: + if (tag !== 32) { + break + } + + message.bonusRateRecoll = reader.int64() as Long + continue + case 5: + if (tag !== 42) { + break + } + + message.distrEpochIdentifier = reader.string() + continue + case 6: + if (tag !== 48) { + break + } + + message.adjustmentStep = reader.int64() as Long + continue + case 7: + if (tag !== 56) { + break + } + + message.priceLowerBound = reader.int64() as Long + continue + case 8: + if (tag !== 64) { + break + } + + message.priceUpperBound = reader.int64() as Long + continue + case 9: + if (tag !== 72) { + break + } + + message.isCollateralRatioValid = reader.bool() + continue + } + if ((tag & 7) === 4 || tag === 0) { + break + } + reader.skipType(tag & 7) + } + return message + }, + + fromJSON(object: any): Params { + return { + collRatio: isSet(object.collRatio) + ? Long.fromValue(object.collRatio) + : Long.ZERO, + feeRatio: isSet(object.feeRatio) + ? Long.fromValue(object.feeRatio) + : Long.ZERO, + efFeeRatio: isSet(object.efFeeRatio) + ? Long.fromValue(object.efFeeRatio) + : Long.ZERO, + bonusRateRecoll: isSet(object.bonusRateRecoll) + ? Long.fromValue(object.bonusRateRecoll) + : Long.ZERO, + distrEpochIdentifier: isSet(object.distrEpochIdentifier) + ? String(object.distrEpochIdentifier) + : "", + adjustmentStep: isSet(object.adjustmentStep) + ? Long.fromValue(object.adjustmentStep) + : Long.ZERO, + priceLowerBound: isSet(object.priceLowerBound) + ? Long.fromValue(object.priceLowerBound) + : Long.ZERO, + priceUpperBound: isSet(object.priceUpperBound) + ? Long.fromValue(object.priceUpperBound) + : Long.ZERO, + isCollateralRatioValid: isSet(object.isCollateralRatioValid) + ? Boolean(object.isCollateralRatioValid) + : false, + } + }, + + toJSON(message: Params): unknown { + const obj: any = {} + message.collRatio !== undefined && + (obj.collRatio = (message.collRatio || Long.ZERO).toString()) + message.feeRatio !== undefined && + (obj.feeRatio = (message.feeRatio || Long.ZERO).toString()) + message.efFeeRatio !== undefined && + (obj.efFeeRatio = (message.efFeeRatio || Long.ZERO).toString()) + message.bonusRateRecoll !== undefined && + (obj.bonusRateRecoll = (message.bonusRateRecoll || Long.ZERO).toString()) + message.distrEpochIdentifier !== undefined && + (obj.distrEpochIdentifier = message.distrEpochIdentifier) + message.adjustmentStep !== undefined && + (obj.adjustmentStep = (message.adjustmentStep || Long.ZERO).toString()) + message.priceLowerBound !== undefined && + (obj.priceLowerBound = (message.priceLowerBound || Long.ZERO).toString()) + message.priceUpperBound !== undefined && + (obj.priceUpperBound = (message.priceUpperBound || Long.ZERO).toString()) + message.isCollateralRatioValid !== undefined && + (obj.isCollateralRatioValid = message.isCollateralRatioValid) + return obj + }, + + create, I>>(base?: I): Params { + return Params.fromPartial(base ?? {}) + }, + + fromPartial, I>>(object: I): Params { + const message = createBaseParams() + message.collRatio = + object.collRatio !== undefined && object.collRatio !== null + ? Long.fromValue(object.collRatio) + : Long.ZERO + message.feeRatio = + object.feeRatio !== undefined && object.feeRatio !== null + ? Long.fromValue(object.feeRatio) + : Long.ZERO + message.efFeeRatio = + object.efFeeRatio !== undefined && object.efFeeRatio !== null + ? Long.fromValue(object.efFeeRatio) + : Long.ZERO + message.bonusRateRecoll = + object.bonusRateRecoll !== undefined && object.bonusRateRecoll !== null + ? Long.fromValue(object.bonusRateRecoll) + : Long.ZERO + message.distrEpochIdentifier = object.distrEpochIdentifier ?? "" + message.adjustmentStep = + object.adjustmentStep !== undefined && object.adjustmentStep !== null + ? Long.fromValue(object.adjustmentStep) + : Long.ZERO + message.priceLowerBound = + object.priceLowerBound !== undefined && object.priceLowerBound !== null + ? Long.fromValue(object.priceLowerBound) + : Long.ZERO + message.priceUpperBound = + object.priceUpperBound !== undefined && object.priceUpperBound !== null + ? Long.fromValue(object.priceUpperBound) + : Long.ZERO + message.isCollateralRatioValid = object.isCollateralRatioValid ?? false + return message + }, +} + +type Builtin = + | Date + | Function + | Uint8Array + | string + | number + | boolean + | undefined + +export type DeepPartial = T extends Builtin + ? T + : T extends Long + ? string | number | Long + : T extends Array + ? Array> + : T extends ReadonlyArray + ? ReadonlyArray> + : T extends {} + ? { [K in keyof T]?: DeepPartial } + : Partial + +type KeysOfUnion = T extends T ? keyof T : never +export type Exact = P extends Builtin + ? P + : P & { [K in keyof P]: Exact } & { + [K in Exclude>]: never + } + +if (_m0.util.Long !== Long) { + _m0.util.Long = Long as any + _m0.configure() +} + +function isSet(value: any): boolean { + return value !== null && value !== undefined +} diff --git a/packages/protojs/src/nibiru/stablecoin/v1/query.ts b/packages/protojs/src/nibiru/stablecoin/v1/query.ts new file mode 100644 index 00000000..b3f2de30 --- /dev/null +++ b/packages/protojs/src/nibiru/stablecoin/v1/query.ts @@ -0,0 +1,959 @@ +/* eslint-disable */ +import Long from "long" +import _m0 from "protobufjs/minimal" +import { Coin } from "../../../cosmos/base/v1beta1/coin" +import { Params } from "./params" + +export const protobufPackage = "nibiru.stablecoin.v1" + +/** QueryParamsRequest is request type for the Query/Params RPC method. */ +export interface QueryParamsRequest {} + +/** QueryParamsResponse is response type for the Query/Params RPC method. */ +export interface QueryParamsResponse { + /** params holds all the parameters of this module. */ + params?: Params +} + +/** + * QueryModuleAccountBalances is the request type for the balance of the + * x/stablecoin module account. + */ +export interface QueryModuleAccountBalances {} + +export interface QueryModuleAccountBalancesResponse { + /** + * ModuleAccountBalances is the balance of all coins in the x/stablecoin + * module. + */ + moduleAccountBalances: Coin[] +} + +/** + * QueryCirculatingSupplies is the request type for the circulating supply of + * both NIBI and NUSD. + */ +export interface QueryCirculatingSupplies {} + +export interface QueryCirculatingSuppliesResponse { + nibi?: Coin + nusd?: Coin +} + +/** + * QueryGovToMintStable is the request type for the Query/GovToMintStable RPC + * method + */ +export interface QueryGovToMintStable { + collateral?: Coin +} + +/** QueryGovToMintStableResponse is the response type for 'QueryGovToMintStable' */ +export interface QueryGovToMintStableResponse { + gov?: Coin +} + +export interface LiquidityRatioInfo { + liquidityRatio: string + upperBand: string + lowerBand: string +} + +export interface QueryLiquidityRatioInfoRequest {} + +export interface QueryLiquidityRatioInfoResponse { + info?: LiquidityRatioInfo +} + +function createBaseQueryParamsRequest(): QueryParamsRequest { + return {} +} + +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 : _m0.Reader.create(input) + let end = length === undefined ? reader.len : reader.pos + length + const message = createBaseQueryParamsRequest() + while (reader.pos < end) { + const tag = reader.uint32() + switch (tag >>> 3) { + } + if ((tag & 7) === 4 || tag === 0) { + break + } + reader.skipType(tag & 7) + } + return message + }, + + fromJSON(_: any): QueryParamsRequest { + return {} + }, + + toJSON(_: QueryParamsRequest): unknown { + const obj: any = {} + return obj + }, + + create, I>>( + base?: I + ): QueryParamsRequest { + return QueryParamsRequest.fromPartial(base ?? {}) + }, + + fromPartial, I>>( + _: I + ): QueryParamsRequest { + const message = createBaseQueryParamsRequest() + return message + }, +} + +function createBaseQueryParamsResponse(): QueryParamsResponse { + return { params: undefined } +} + +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 : _m0.Reader.create(input) + let end = length === undefined ? reader.len : reader.pos + length + const message = createBaseQueryParamsResponse() + while (reader.pos < end) { + const tag = reader.uint32() + switch (tag >>> 3) { + case 1: + if (tag !== 10) { + break + } + + message.params = Params.decode(reader, reader.uint32()) + continue + } + if ((tag & 7) === 4 || tag === 0) { + break + } + reader.skipType(tag & 7) + } + return message + }, + + fromJSON(object: any): QueryParamsResponse { + return { + params: isSet(object.params) ? Params.fromJSON(object.params) : undefined, + } + }, + + toJSON(message: QueryParamsResponse): unknown { + const obj: any = {} + message.params !== undefined && + (obj.params = message.params ? Params.toJSON(message.params) : undefined) + return obj + }, + + create, I>>( + base?: I + ): QueryParamsResponse { + return QueryParamsResponse.fromPartial(base ?? {}) + }, + + fromPartial, I>>( + object: I + ): QueryParamsResponse { + const message = createBaseQueryParamsResponse() + message.params = + object.params !== undefined && object.params !== null + ? Params.fromPartial(object.params) + : undefined + return message + }, +} + +function createBaseQueryModuleAccountBalances(): QueryModuleAccountBalances { + return {} +} + +export const QueryModuleAccountBalances = { + encode( + _: QueryModuleAccountBalances, + writer: _m0.Writer = _m0.Writer.create() + ): _m0.Writer { + return writer + }, + + decode( + input: _m0.Reader | Uint8Array, + length?: number + ): QueryModuleAccountBalances { + const reader = + input instanceof _m0.Reader ? input : _m0.Reader.create(input) + let end = length === undefined ? reader.len : reader.pos + length + const message = createBaseQueryModuleAccountBalances() + while (reader.pos < end) { + const tag = reader.uint32() + switch (tag >>> 3) { + } + if ((tag & 7) === 4 || tag === 0) { + break + } + reader.skipType(tag & 7) + } + return message + }, + + fromJSON(_: any): QueryModuleAccountBalances { + return {} + }, + + toJSON(_: QueryModuleAccountBalances): unknown { + const obj: any = {} + return obj + }, + + create, I>>( + base?: I + ): QueryModuleAccountBalances { + return QueryModuleAccountBalances.fromPartial(base ?? {}) + }, + + fromPartial, I>>( + _: I + ): QueryModuleAccountBalances { + const message = createBaseQueryModuleAccountBalances() + return message + }, +} + +function createBaseQueryModuleAccountBalancesResponse(): QueryModuleAccountBalancesResponse { + return { moduleAccountBalances: [] } +} + +export const QueryModuleAccountBalancesResponse = { + encode( + message: QueryModuleAccountBalancesResponse, + writer: _m0.Writer = _m0.Writer.create() + ): _m0.Writer { + for (const v of message.moduleAccountBalances) { + Coin.encode(v!, writer.uint32(10).fork()).ldelim() + } + return writer + }, + + decode( + input: _m0.Reader | Uint8Array, + length?: number + ): QueryModuleAccountBalancesResponse { + const reader = + input instanceof _m0.Reader ? input : _m0.Reader.create(input) + let end = length === undefined ? reader.len : reader.pos + length + const message = createBaseQueryModuleAccountBalancesResponse() + while (reader.pos < end) { + const tag = reader.uint32() + switch (tag >>> 3) { + case 1: + if (tag !== 10) { + break + } + + message.moduleAccountBalances.push( + Coin.decode(reader, reader.uint32()) + ) + continue + } + if ((tag & 7) === 4 || tag === 0) { + break + } + reader.skipType(tag & 7) + } + return message + }, + + fromJSON(object: any): QueryModuleAccountBalancesResponse { + return { + moduleAccountBalances: Array.isArray(object?.moduleAccountBalances) + ? object.moduleAccountBalances.map((e: any) => Coin.fromJSON(e)) + : [], + } + }, + + toJSON(message: QueryModuleAccountBalancesResponse): unknown { + const obj: any = {} + if (message.moduleAccountBalances) { + obj.moduleAccountBalances = message.moduleAccountBalances.map((e) => + e ? Coin.toJSON(e) : undefined + ) + } else { + obj.moduleAccountBalances = [] + } + return obj + }, + + create, I>>( + base?: I + ): QueryModuleAccountBalancesResponse { + return QueryModuleAccountBalancesResponse.fromPartial(base ?? {}) + }, + + fromPartial< + I extends Exact, I> + >(object: I): QueryModuleAccountBalancesResponse { + const message = createBaseQueryModuleAccountBalancesResponse() + message.moduleAccountBalances = + object.moduleAccountBalances?.map((e) => Coin.fromPartial(e)) || [] + return message + }, +} + +function createBaseQueryCirculatingSupplies(): QueryCirculatingSupplies { + return {} +} + +export const QueryCirculatingSupplies = { + encode( + _: QueryCirculatingSupplies, + writer: _m0.Writer = _m0.Writer.create() + ): _m0.Writer { + return writer + }, + + decode( + input: _m0.Reader | Uint8Array, + length?: number + ): QueryCirculatingSupplies { + const reader = + input instanceof _m0.Reader ? input : _m0.Reader.create(input) + let end = length === undefined ? reader.len : reader.pos + length + const message = createBaseQueryCirculatingSupplies() + while (reader.pos < end) { + const tag = reader.uint32() + switch (tag >>> 3) { + } + if ((tag & 7) === 4 || tag === 0) { + break + } + reader.skipType(tag & 7) + } + return message + }, + + fromJSON(_: any): QueryCirculatingSupplies { + return {} + }, + + toJSON(_: QueryCirculatingSupplies): unknown { + const obj: any = {} + return obj + }, + + create, I>>( + base?: I + ): QueryCirculatingSupplies { + return QueryCirculatingSupplies.fromPartial(base ?? {}) + }, + + fromPartial, I>>( + _: I + ): QueryCirculatingSupplies { + const message = createBaseQueryCirculatingSupplies() + return message + }, +} + +function createBaseQueryCirculatingSuppliesResponse(): QueryCirculatingSuppliesResponse { + return { nibi: undefined, nusd: undefined } +} + +export const QueryCirculatingSuppliesResponse = { + encode( + message: QueryCirculatingSuppliesResponse, + writer: _m0.Writer = _m0.Writer.create() + ): _m0.Writer { + if (message.nibi !== undefined) { + Coin.encode(message.nibi, writer.uint32(10).fork()).ldelim() + } + if (message.nusd !== undefined) { + Coin.encode(message.nusd, writer.uint32(18).fork()).ldelim() + } + return writer + }, + + decode( + input: _m0.Reader | Uint8Array, + length?: number + ): QueryCirculatingSuppliesResponse { + const reader = + input instanceof _m0.Reader ? input : _m0.Reader.create(input) + let end = length === undefined ? reader.len : reader.pos + length + const message = createBaseQueryCirculatingSuppliesResponse() + while (reader.pos < end) { + const tag = reader.uint32() + switch (tag >>> 3) { + case 1: + if (tag !== 10) { + break + } + + message.nibi = Coin.decode(reader, reader.uint32()) + continue + case 2: + if (tag !== 18) { + break + } + + message.nusd = Coin.decode(reader, reader.uint32()) + continue + } + if ((tag & 7) === 4 || tag === 0) { + break + } + reader.skipType(tag & 7) + } + return message + }, + + fromJSON(object: any): QueryCirculatingSuppliesResponse { + return { + nibi: isSet(object.nibi) ? Coin.fromJSON(object.nibi) : undefined, + nusd: isSet(object.nusd) ? Coin.fromJSON(object.nusd) : undefined, + } + }, + + toJSON(message: QueryCirculatingSuppliesResponse): unknown { + const obj: any = {} + message.nibi !== undefined && + (obj.nibi = message.nibi ? Coin.toJSON(message.nibi) : undefined) + message.nusd !== undefined && + (obj.nusd = message.nusd ? Coin.toJSON(message.nusd) : undefined) + return obj + }, + + create, I>>( + base?: I + ): QueryCirculatingSuppliesResponse { + return QueryCirculatingSuppliesResponse.fromPartial(base ?? {}) + }, + + fromPartial< + I extends Exact, I> + >(object: I): QueryCirculatingSuppliesResponse { + const message = createBaseQueryCirculatingSuppliesResponse() + message.nibi = + object.nibi !== undefined && object.nibi !== null + ? Coin.fromPartial(object.nibi) + : undefined + message.nusd = + object.nusd !== undefined && object.nusd !== null + ? Coin.fromPartial(object.nusd) + : undefined + return message + }, +} + +function createBaseQueryGovToMintStable(): QueryGovToMintStable { + return { collateral: undefined } +} + +export const QueryGovToMintStable = { + encode( + message: QueryGovToMintStable, + writer: _m0.Writer = _m0.Writer.create() + ): _m0.Writer { + if (message.collateral !== undefined) { + Coin.encode(message.collateral, writer.uint32(10).fork()).ldelim() + } + return writer + }, + + decode( + input: _m0.Reader | Uint8Array, + length?: number + ): QueryGovToMintStable { + const reader = + input instanceof _m0.Reader ? input : _m0.Reader.create(input) + let end = length === undefined ? reader.len : reader.pos + length + const message = createBaseQueryGovToMintStable() + while (reader.pos < end) { + const tag = reader.uint32() + switch (tag >>> 3) { + case 1: + if (tag !== 10) { + break + } + + message.collateral = Coin.decode(reader, reader.uint32()) + continue + } + if ((tag & 7) === 4 || tag === 0) { + break + } + reader.skipType(tag & 7) + } + return message + }, + + fromJSON(object: any): QueryGovToMintStable { + return { + collateral: isSet(object.collateral) + ? Coin.fromJSON(object.collateral) + : undefined, + } + }, + + toJSON(message: QueryGovToMintStable): unknown { + const obj: any = {} + message.collateral !== undefined && + (obj.collateral = message.collateral + ? Coin.toJSON(message.collateral) + : undefined) + return obj + }, + + create, I>>( + base?: I + ): QueryGovToMintStable { + return QueryGovToMintStable.fromPartial(base ?? {}) + }, + + fromPartial, I>>( + object: I + ): QueryGovToMintStable { + const message = createBaseQueryGovToMintStable() + message.collateral = + object.collateral !== undefined && object.collateral !== null + ? Coin.fromPartial(object.collateral) + : undefined + return message + }, +} + +function createBaseQueryGovToMintStableResponse(): QueryGovToMintStableResponse { + return { gov: undefined } +} + +export const QueryGovToMintStableResponse = { + encode( + message: QueryGovToMintStableResponse, + writer: _m0.Writer = _m0.Writer.create() + ): _m0.Writer { + if (message.gov !== undefined) { + Coin.encode(message.gov, writer.uint32(10).fork()).ldelim() + } + return writer + }, + + decode( + input: _m0.Reader | Uint8Array, + length?: number + ): QueryGovToMintStableResponse { + const reader = + input instanceof _m0.Reader ? input : _m0.Reader.create(input) + let end = length === undefined ? reader.len : reader.pos + length + const message = createBaseQueryGovToMintStableResponse() + while (reader.pos < end) { + const tag = reader.uint32() + switch (tag >>> 3) { + case 1: + if (tag !== 10) { + break + } + + message.gov = Coin.decode(reader, reader.uint32()) + continue + } + if ((tag & 7) === 4 || tag === 0) { + break + } + reader.skipType(tag & 7) + } + return message + }, + + fromJSON(object: any): QueryGovToMintStableResponse { + return { gov: isSet(object.gov) ? Coin.fromJSON(object.gov) : undefined } + }, + + toJSON(message: QueryGovToMintStableResponse): unknown { + const obj: any = {} + message.gov !== undefined && + (obj.gov = message.gov ? Coin.toJSON(message.gov) : undefined) + return obj + }, + + create, I>>( + base?: I + ): QueryGovToMintStableResponse { + return QueryGovToMintStableResponse.fromPartial(base ?? {}) + }, + + fromPartial, I>>( + object: I + ): QueryGovToMintStableResponse { + const message = createBaseQueryGovToMintStableResponse() + message.gov = + object.gov !== undefined && object.gov !== null + ? Coin.fromPartial(object.gov) + : undefined + return message + }, +} + +function createBaseLiquidityRatioInfo(): LiquidityRatioInfo { + return { liquidityRatio: "", upperBand: "", lowerBand: "" } +} + +export const LiquidityRatioInfo = { + encode( + message: LiquidityRatioInfo, + writer: _m0.Writer = _m0.Writer.create() + ): _m0.Writer { + if (message.liquidityRatio !== "") { + writer.uint32(10).string(message.liquidityRatio) + } + if (message.upperBand !== "") { + writer.uint32(18).string(message.upperBand) + } + if (message.lowerBand !== "") { + writer.uint32(26).string(message.lowerBand) + } + return writer + }, + + decode(input: _m0.Reader | Uint8Array, length?: number): LiquidityRatioInfo { + const reader = + input instanceof _m0.Reader ? input : _m0.Reader.create(input) + let end = length === undefined ? reader.len : reader.pos + length + const message = createBaseLiquidityRatioInfo() + while (reader.pos < end) { + const tag = reader.uint32() + switch (tag >>> 3) { + case 1: + if (tag !== 10) { + break + } + + message.liquidityRatio = reader.string() + continue + case 2: + if (tag !== 18) { + break + } + + message.upperBand = reader.string() + continue + case 3: + if (tag !== 26) { + break + } + + message.lowerBand = reader.string() + continue + } + if ((tag & 7) === 4 || tag === 0) { + break + } + reader.skipType(tag & 7) + } + return message + }, + + fromJSON(object: any): LiquidityRatioInfo { + return { + liquidityRatio: isSet(object.liquidityRatio) + ? String(object.liquidityRatio) + : "", + upperBand: isSet(object.upperBand) ? String(object.upperBand) : "", + lowerBand: isSet(object.lowerBand) ? String(object.lowerBand) : "", + } + }, + + toJSON(message: LiquidityRatioInfo): unknown { + const obj: any = {} + message.liquidityRatio !== undefined && + (obj.liquidityRatio = message.liquidityRatio) + message.upperBand !== undefined && (obj.upperBand = message.upperBand) + message.lowerBand !== undefined && (obj.lowerBand = message.lowerBand) + return obj + }, + + create, I>>( + base?: I + ): LiquidityRatioInfo { + return LiquidityRatioInfo.fromPartial(base ?? {}) + }, + + fromPartial, I>>( + object: I + ): LiquidityRatioInfo { + const message = createBaseLiquidityRatioInfo() + message.liquidityRatio = object.liquidityRatio ?? "" + message.upperBand = object.upperBand ?? "" + message.lowerBand = object.lowerBand ?? "" + return message + }, +} + +function createBaseQueryLiquidityRatioInfoRequest(): QueryLiquidityRatioInfoRequest { + return {} +} + +export const QueryLiquidityRatioInfoRequest = { + encode( + _: QueryLiquidityRatioInfoRequest, + writer: _m0.Writer = _m0.Writer.create() + ): _m0.Writer { + return writer + }, + + decode( + input: _m0.Reader | Uint8Array, + length?: number + ): QueryLiquidityRatioInfoRequest { + const reader = + input instanceof _m0.Reader ? input : _m0.Reader.create(input) + let end = length === undefined ? reader.len : reader.pos + length + const message = createBaseQueryLiquidityRatioInfoRequest() + while (reader.pos < end) { + const tag = reader.uint32() + switch (tag >>> 3) { + } + if ((tag & 7) === 4 || tag === 0) { + break + } + reader.skipType(tag & 7) + } + return message + }, + + fromJSON(_: any): QueryLiquidityRatioInfoRequest { + return {} + }, + + toJSON(_: QueryLiquidityRatioInfoRequest): unknown { + const obj: any = {} + return obj + }, + + create, I>>( + base?: I + ): QueryLiquidityRatioInfoRequest { + return QueryLiquidityRatioInfoRequest.fromPartial(base ?? {}) + }, + + fromPartial, I>>( + _: I + ): QueryLiquidityRatioInfoRequest { + const message = createBaseQueryLiquidityRatioInfoRequest() + return message + }, +} + +function createBaseQueryLiquidityRatioInfoResponse(): QueryLiquidityRatioInfoResponse { + return { info: undefined } +} + +export const QueryLiquidityRatioInfoResponse = { + encode( + message: QueryLiquidityRatioInfoResponse, + writer: _m0.Writer = _m0.Writer.create() + ): _m0.Writer { + if (message.info !== undefined) { + LiquidityRatioInfo.encode(message.info, writer.uint32(10).fork()).ldelim() + } + return writer + }, + + decode( + input: _m0.Reader | Uint8Array, + length?: number + ): QueryLiquidityRatioInfoResponse { + const reader = + input instanceof _m0.Reader ? input : _m0.Reader.create(input) + let end = length === undefined ? reader.len : reader.pos + length + const message = createBaseQueryLiquidityRatioInfoResponse() + while (reader.pos < end) { + const tag = reader.uint32() + switch (tag >>> 3) { + case 1: + if (tag !== 10) { + break + } + + message.info = LiquidityRatioInfo.decode(reader, reader.uint32()) + continue + } + if ((tag & 7) === 4 || tag === 0) { + break + } + reader.skipType(tag & 7) + } + return message + }, + + fromJSON(object: any): QueryLiquidityRatioInfoResponse { + return { + info: isSet(object.info) + ? LiquidityRatioInfo.fromJSON(object.info) + : undefined, + } + }, + + toJSON(message: QueryLiquidityRatioInfoResponse): unknown { + const obj: any = {} + message.info !== undefined && + (obj.info = message.info + ? LiquidityRatioInfo.toJSON(message.info) + : undefined) + return obj + }, + + create, I>>( + base?: I + ): QueryLiquidityRatioInfoResponse { + return QueryLiquidityRatioInfoResponse.fromPartial(base ?? {}) + }, + + fromPartial, I>>( + object: I + ): QueryLiquidityRatioInfoResponse { + const message = createBaseQueryLiquidityRatioInfoResponse() + message.info = + object.info !== undefined && object.info !== null + ? LiquidityRatioInfo.fromPartial(object.info) + : undefined + return message + }, +} + +/** Query defines the gRPC querier service. */ +export interface Query { + /** Parameters queries the parameters of the x/stablecoin module. */ + Params(request: QueryParamsRequest): Promise + /** ModuleAccountBalances queries the account balance of x/stablecoin. */ + ModuleAccountBalances( + request: QueryModuleAccountBalances + ): Promise + CirculatingSupplies( + request: QueryCirculatingSupplies + ): Promise + LiquidityRatioInfo( + request: QueryLiquidityRatioInfoRequest + ): Promise +} + +export const QueryServiceName = "nibiru.stablecoin.v1.Query" +export class QueryClientImpl implements Query { + private readonly rpc: Rpc + private readonly service: string + constructor(rpc: Rpc, opts?: { service?: string }) { + this.service = opts?.service || QueryServiceName + this.rpc = rpc + this.Params = this.Params.bind(this) + this.ModuleAccountBalances = this.ModuleAccountBalances.bind(this) + this.CirculatingSupplies = this.CirculatingSupplies.bind(this) + this.LiquidityRatioInfo = this.LiquidityRatioInfo.bind(this) + } + Params(request: QueryParamsRequest): Promise { + const data = QueryParamsRequest.encode(request).finish() + const promise = this.rpc.request(this.service, "Params", data) + return promise.then((data) => + QueryParamsResponse.decode(_m0.Reader.create(data)) + ) + } + + ModuleAccountBalances( + request: QueryModuleAccountBalances + ): Promise { + const data = QueryModuleAccountBalances.encode(request).finish() + const promise = this.rpc.request( + this.service, + "ModuleAccountBalances", + data + ) + return promise.then((data) => + QueryModuleAccountBalancesResponse.decode(_m0.Reader.create(data)) + ) + } + + CirculatingSupplies( + request: QueryCirculatingSupplies + ): Promise { + const data = QueryCirculatingSupplies.encode(request).finish() + const promise = this.rpc.request(this.service, "CirculatingSupplies", data) + return promise.then((data) => + QueryCirculatingSuppliesResponse.decode(_m0.Reader.create(data)) + ) + } + + LiquidityRatioInfo( + request: QueryLiquidityRatioInfoRequest + ): Promise { + const data = QueryLiquidityRatioInfoRequest.encode(request).finish() + const promise = this.rpc.request(this.service, "LiquidityRatioInfo", data) + return promise.then((data) => + QueryLiquidityRatioInfoResponse.decode(_m0.Reader.create(data)) + ) + } +} + +interface Rpc { + request( + service: string, + method: string, + data: Uint8Array + ): Promise +} + +type Builtin = + | Date + | Function + | Uint8Array + | string + | number + | boolean + | undefined + +export type DeepPartial = T extends Builtin + ? T + : T extends Long + ? string | number | Long + : T extends Array + ? Array> + : T extends ReadonlyArray + ? ReadonlyArray> + : T extends {} + ? { [K in keyof T]?: DeepPartial } + : Partial + +type KeysOfUnion = T extends T ? keyof T : never +export type Exact = P extends Builtin + ? P + : P & { [K in keyof P]: Exact } & { + [K in Exclude>]: never + } + +if (_m0.util.Long !== Long) { + _m0.util.Long = Long as any + _m0.configure() +} + +function isSet(value: any): boolean { + return value !== null && value !== undefined +} diff --git a/packages/protojs/src/nibiru/stablecoin/v1/tx.ts b/packages/protojs/src/nibiru/stablecoin/v1/tx.ts new file mode 100644 index 00000000..25aeea01 --- /dev/null +++ b/packages/protojs/src/nibiru/stablecoin/v1/tx.ts @@ -0,0 +1,897 @@ +/* eslint-disable */ +import Long from "long" +import _m0 from "protobufjs/minimal" +import { Coin } from "../../../cosmos/base/v1beta1/coin" + +export const protobufPackage = "nibiru.stablecoin.v1" + +/** + * MsgMintStable: Msg to mint NUSD. A user deposits NIBI and collateral and gets + * NUSD in return. The amount of NUSD received depends on the current price set + * by the oracle library and the current collateral ratio for the protocol. + */ +export interface MsgMintStable { + creator: string + stable?: Coin +} + +/** + * MsgMintStableResponse specifies the amount of NUSD token the user will + * receive after their mint transaction + */ +export interface MsgMintStableResponse { + stable?: Coin + usedCoins: Coin[] + feesPayed: Coin[] +} + +/** + * MsgBurnStable allows users to burn NUSD in exchange for NIBI and collateral. + * The amount of NIBI and Collateral received depends on the current price set by + * the x/oracle library and the current collateral ratio. + */ +export interface MsgBurnStable { + creator: string + stable?: Coin +} + +/** + * MsgBurnStableResponse specifies the amount of collateral and governance + * token the user will receive after their burn transaction. + */ +export interface MsgBurnStableResponse { + collateral?: Coin + gov?: Coin + feesPayed: Coin[] +} + +/** MsgRecollateralize */ +export interface MsgRecollateralize { + creator: string + coll?: Coin +} + +/** MsgRecollateralizeResponse is the output of a successful 'Recollateralize' */ +export interface MsgRecollateralizeResponse { + /** + * Gov (sdk.Coin): Tokens rewarded to the caller in exchange for her + * collateral. + */ + gov?: Coin +} + +/** MsgBuyback */ +export interface MsgBuyback { + creator: string + /** + * Gov (sdk.Coin): Tokens the caller wants to sell to the protocol in exchange + * for collateral. + */ + gov?: Coin +} + +/** MsgBuybackResponse is the output of a successful 'Buyback' */ +export interface MsgBuybackResponse { + /** Coll (sdk.Coin): Tokens sold to the caller in exchange for her collateral. */ + coll?: Coin +} + +function createBaseMsgMintStable(): MsgMintStable { + return { creator: "", stable: undefined } +} + +export const MsgMintStable = { + encode( + message: MsgMintStable, + writer: _m0.Writer = _m0.Writer.create() + ): _m0.Writer { + if (message.creator !== "") { + writer.uint32(10).string(message.creator) + } + if (message.stable !== undefined) { + Coin.encode(message.stable, writer.uint32(18).fork()).ldelim() + } + return writer + }, + + decode(input: _m0.Reader | Uint8Array, length?: number): MsgMintStable { + const reader = + input instanceof _m0.Reader ? input : _m0.Reader.create(input) + let end = length === undefined ? reader.len : reader.pos + length + const message = createBaseMsgMintStable() + while (reader.pos < end) { + const tag = reader.uint32() + switch (tag >>> 3) { + case 1: + if (tag !== 10) { + break + } + + message.creator = reader.string() + continue + case 2: + if (tag !== 18) { + break + } + + message.stable = Coin.decode(reader, reader.uint32()) + continue + } + if ((tag & 7) === 4 || tag === 0) { + break + } + reader.skipType(tag & 7) + } + return message + }, + + fromJSON(object: any): MsgMintStable { + return { + creator: isSet(object.creator) ? String(object.creator) : "", + stable: isSet(object.stable) ? Coin.fromJSON(object.stable) : undefined, + } + }, + + toJSON(message: MsgMintStable): unknown { + const obj: any = {} + message.creator !== undefined && (obj.creator = message.creator) + message.stable !== undefined && + (obj.stable = message.stable ? Coin.toJSON(message.stable) : undefined) + return obj + }, + + create, I>>( + base?: I + ): MsgMintStable { + return MsgMintStable.fromPartial(base ?? {}) + }, + + fromPartial, I>>( + object: I + ): MsgMintStable { + const message = createBaseMsgMintStable() + message.creator = object.creator ?? "" + message.stable = + object.stable !== undefined && object.stable !== null + ? Coin.fromPartial(object.stable) + : undefined + return message + }, +} + +function createBaseMsgMintStableResponse(): MsgMintStableResponse { + return { stable: undefined, usedCoins: [], feesPayed: [] } +} + +export const MsgMintStableResponse = { + encode( + message: MsgMintStableResponse, + writer: _m0.Writer = _m0.Writer.create() + ): _m0.Writer { + if (message.stable !== undefined) { + Coin.encode(message.stable, writer.uint32(10).fork()).ldelim() + } + for (const v of message.usedCoins) { + Coin.encode(v!, writer.uint32(18).fork()).ldelim() + } + for (const v of message.feesPayed) { + Coin.encode(v!, writer.uint32(26).fork()).ldelim() + } + return writer + }, + + decode( + input: _m0.Reader | Uint8Array, + length?: number + ): MsgMintStableResponse { + const reader = + input instanceof _m0.Reader ? input : _m0.Reader.create(input) + let end = length === undefined ? reader.len : reader.pos + length + const message = createBaseMsgMintStableResponse() + while (reader.pos < end) { + const tag = reader.uint32() + switch (tag >>> 3) { + case 1: + if (tag !== 10) { + break + } + + message.stable = Coin.decode(reader, reader.uint32()) + continue + case 2: + if (tag !== 18) { + break + } + + message.usedCoins.push(Coin.decode(reader, reader.uint32())) + continue + case 3: + if (tag !== 26) { + break + } + + message.feesPayed.push(Coin.decode(reader, reader.uint32())) + continue + } + if ((tag & 7) === 4 || tag === 0) { + break + } + reader.skipType(tag & 7) + } + return message + }, + + fromJSON(object: any): MsgMintStableResponse { + return { + stable: isSet(object.stable) ? Coin.fromJSON(object.stable) : undefined, + usedCoins: Array.isArray(object?.usedCoins) + ? object.usedCoins.map((e: any) => Coin.fromJSON(e)) + : [], + feesPayed: Array.isArray(object?.feesPayed) + ? object.feesPayed.map((e: any) => Coin.fromJSON(e)) + : [], + } + }, + + toJSON(message: MsgMintStableResponse): unknown { + const obj: any = {} + message.stable !== undefined && + (obj.stable = message.stable ? Coin.toJSON(message.stable) : undefined) + if (message.usedCoins) { + obj.usedCoins = message.usedCoins.map((e) => + e ? Coin.toJSON(e) : undefined + ) + } else { + obj.usedCoins = [] + } + if (message.feesPayed) { + obj.feesPayed = message.feesPayed.map((e) => + e ? Coin.toJSON(e) : undefined + ) + } else { + obj.feesPayed = [] + } + return obj + }, + + create, I>>( + base?: I + ): MsgMintStableResponse { + return MsgMintStableResponse.fromPartial(base ?? {}) + }, + + fromPartial, I>>( + object: I + ): MsgMintStableResponse { + const message = createBaseMsgMintStableResponse() + message.stable = + object.stable !== undefined && object.stable !== null + ? Coin.fromPartial(object.stable) + : undefined + message.usedCoins = object.usedCoins?.map((e) => Coin.fromPartial(e)) || [] + message.feesPayed = object.feesPayed?.map((e) => Coin.fromPartial(e)) || [] + return message + }, +} + +function createBaseMsgBurnStable(): MsgBurnStable { + return { creator: "", stable: undefined } +} + +export const MsgBurnStable = { + encode( + message: MsgBurnStable, + writer: _m0.Writer = _m0.Writer.create() + ): _m0.Writer { + if (message.creator !== "") { + writer.uint32(10).string(message.creator) + } + if (message.stable !== undefined) { + Coin.encode(message.stable, writer.uint32(18).fork()).ldelim() + } + return writer + }, + + decode(input: _m0.Reader | Uint8Array, length?: number): MsgBurnStable { + const reader = + input instanceof _m0.Reader ? input : _m0.Reader.create(input) + let end = length === undefined ? reader.len : reader.pos + length + const message = createBaseMsgBurnStable() + while (reader.pos < end) { + const tag = reader.uint32() + switch (tag >>> 3) { + case 1: + if (tag !== 10) { + break + } + + message.creator = reader.string() + continue + case 2: + if (tag !== 18) { + break + } + + message.stable = Coin.decode(reader, reader.uint32()) + continue + } + if ((tag & 7) === 4 || tag === 0) { + break + } + reader.skipType(tag & 7) + } + return message + }, + + fromJSON(object: any): MsgBurnStable { + return { + creator: isSet(object.creator) ? String(object.creator) : "", + stable: isSet(object.stable) ? Coin.fromJSON(object.stable) : undefined, + } + }, + + toJSON(message: MsgBurnStable): unknown { + const obj: any = {} + message.creator !== undefined && (obj.creator = message.creator) + message.stable !== undefined && + (obj.stable = message.stable ? Coin.toJSON(message.stable) : undefined) + return obj + }, + + create, I>>( + base?: I + ): MsgBurnStable { + return MsgBurnStable.fromPartial(base ?? {}) + }, + + fromPartial, I>>( + object: I + ): MsgBurnStable { + const message = createBaseMsgBurnStable() + message.creator = object.creator ?? "" + message.stable = + object.stable !== undefined && object.stable !== null + ? Coin.fromPartial(object.stable) + : undefined + return message + }, +} + +function createBaseMsgBurnStableResponse(): MsgBurnStableResponse { + return { collateral: undefined, gov: undefined, feesPayed: [] } +} + +export const MsgBurnStableResponse = { + encode( + message: MsgBurnStableResponse, + writer: _m0.Writer = _m0.Writer.create() + ): _m0.Writer { + if (message.collateral !== undefined) { + Coin.encode(message.collateral, writer.uint32(10).fork()).ldelim() + } + if (message.gov !== undefined) { + Coin.encode(message.gov, writer.uint32(18).fork()).ldelim() + } + for (const v of message.feesPayed) { + Coin.encode(v!, writer.uint32(26).fork()).ldelim() + } + return writer + }, + + decode( + input: _m0.Reader | Uint8Array, + length?: number + ): MsgBurnStableResponse { + const reader = + input instanceof _m0.Reader ? input : _m0.Reader.create(input) + let end = length === undefined ? reader.len : reader.pos + length + const message = createBaseMsgBurnStableResponse() + while (reader.pos < end) { + const tag = reader.uint32() + switch (tag >>> 3) { + case 1: + if (tag !== 10) { + break + } + + message.collateral = Coin.decode(reader, reader.uint32()) + continue + case 2: + if (tag !== 18) { + break + } + + message.gov = Coin.decode(reader, reader.uint32()) + continue + case 3: + if (tag !== 26) { + break + } + + message.feesPayed.push(Coin.decode(reader, reader.uint32())) + continue + } + if ((tag & 7) === 4 || tag === 0) { + break + } + reader.skipType(tag & 7) + } + return message + }, + + fromJSON(object: any): MsgBurnStableResponse { + return { + collateral: isSet(object.collateral) + ? Coin.fromJSON(object.collateral) + : undefined, + gov: isSet(object.gov) ? Coin.fromJSON(object.gov) : undefined, + feesPayed: Array.isArray(object?.feesPayed) + ? object.feesPayed.map((e: any) => Coin.fromJSON(e)) + : [], + } + }, + + toJSON(message: MsgBurnStableResponse): unknown { + const obj: any = {} + message.collateral !== undefined && + (obj.collateral = message.collateral + ? Coin.toJSON(message.collateral) + : undefined) + message.gov !== undefined && + (obj.gov = message.gov ? Coin.toJSON(message.gov) : undefined) + if (message.feesPayed) { + obj.feesPayed = message.feesPayed.map((e) => + e ? Coin.toJSON(e) : undefined + ) + } else { + obj.feesPayed = [] + } + return obj + }, + + create, I>>( + base?: I + ): MsgBurnStableResponse { + return MsgBurnStableResponse.fromPartial(base ?? {}) + }, + + fromPartial, I>>( + object: I + ): MsgBurnStableResponse { + const message = createBaseMsgBurnStableResponse() + message.collateral = + object.collateral !== undefined && object.collateral !== null + ? Coin.fromPartial(object.collateral) + : undefined + message.gov = + object.gov !== undefined && object.gov !== null + ? Coin.fromPartial(object.gov) + : undefined + message.feesPayed = object.feesPayed?.map((e) => Coin.fromPartial(e)) || [] + return message + }, +} + +function createBaseMsgRecollateralize(): MsgRecollateralize { + return { creator: "", coll: undefined } +} + +export const MsgRecollateralize = { + encode( + message: MsgRecollateralize, + writer: _m0.Writer = _m0.Writer.create() + ): _m0.Writer { + if (message.creator !== "") { + writer.uint32(10).string(message.creator) + } + if (message.coll !== undefined) { + Coin.encode(message.coll, writer.uint32(18).fork()).ldelim() + } + return writer + }, + + decode(input: _m0.Reader | Uint8Array, length?: number): MsgRecollateralize { + const reader = + input instanceof _m0.Reader ? input : _m0.Reader.create(input) + let end = length === undefined ? reader.len : reader.pos + length + const message = createBaseMsgRecollateralize() + while (reader.pos < end) { + const tag = reader.uint32() + switch (tag >>> 3) { + case 1: + if (tag !== 10) { + break + } + + message.creator = reader.string() + continue + case 2: + if (tag !== 18) { + break + } + + message.coll = Coin.decode(reader, reader.uint32()) + continue + } + if ((tag & 7) === 4 || tag === 0) { + break + } + reader.skipType(tag & 7) + } + return message + }, + + fromJSON(object: any): MsgRecollateralize { + return { + creator: isSet(object.creator) ? String(object.creator) : "", + coll: isSet(object.coll) ? Coin.fromJSON(object.coll) : undefined, + } + }, + + toJSON(message: MsgRecollateralize): unknown { + const obj: any = {} + message.creator !== undefined && (obj.creator = message.creator) + message.coll !== undefined && + (obj.coll = message.coll ? Coin.toJSON(message.coll) : undefined) + return obj + }, + + create, I>>( + base?: I + ): MsgRecollateralize { + return MsgRecollateralize.fromPartial(base ?? {}) + }, + + fromPartial, I>>( + object: I + ): MsgRecollateralize { + const message = createBaseMsgRecollateralize() + message.creator = object.creator ?? "" + message.coll = + object.coll !== undefined && object.coll !== null + ? Coin.fromPartial(object.coll) + : undefined + return message + }, +} + +function createBaseMsgRecollateralizeResponse(): MsgRecollateralizeResponse { + return { gov: undefined } +} + +export const MsgRecollateralizeResponse = { + encode( + message: MsgRecollateralizeResponse, + writer: _m0.Writer = _m0.Writer.create() + ): _m0.Writer { + if (message.gov !== undefined) { + Coin.encode(message.gov, writer.uint32(10).fork()).ldelim() + } + return writer + }, + + decode( + input: _m0.Reader | Uint8Array, + length?: number + ): MsgRecollateralizeResponse { + const reader = + input instanceof _m0.Reader ? input : _m0.Reader.create(input) + let end = length === undefined ? reader.len : reader.pos + length + const message = createBaseMsgRecollateralizeResponse() + while (reader.pos < end) { + const tag = reader.uint32() + switch (tag >>> 3) { + case 1: + if (tag !== 10) { + break + } + + message.gov = Coin.decode(reader, reader.uint32()) + continue + } + if ((tag & 7) === 4 || tag === 0) { + break + } + reader.skipType(tag & 7) + } + return message + }, + + fromJSON(object: any): MsgRecollateralizeResponse { + return { gov: isSet(object.gov) ? Coin.fromJSON(object.gov) : undefined } + }, + + toJSON(message: MsgRecollateralizeResponse): unknown { + const obj: any = {} + message.gov !== undefined && + (obj.gov = message.gov ? Coin.toJSON(message.gov) : undefined) + return obj + }, + + create, I>>( + base?: I + ): MsgRecollateralizeResponse { + return MsgRecollateralizeResponse.fromPartial(base ?? {}) + }, + + fromPartial, I>>( + object: I + ): MsgRecollateralizeResponse { + const message = createBaseMsgRecollateralizeResponse() + message.gov = + object.gov !== undefined && object.gov !== null + ? Coin.fromPartial(object.gov) + : undefined + return message + }, +} + +function createBaseMsgBuyback(): MsgBuyback { + return { creator: "", gov: undefined } +} + +export const MsgBuyback = { + encode( + message: MsgBuyback, + writer: _m0.Writer = _m0.Writer.create() + ): _m0.Writer { + if (message.creator !== "") { + writer.uint32(10).string(message.creator) + } + if (message.gov !== undefined) { + Coin.encode(message.gov, writer.uint32(18).fork()).ldelim() + } + return writer + }, + + decode(input: _m0.Reader | Uint8Array, length?: number): MsgBuyback { + const reader = + input instanceof _m0.Reader ? input : _m0.Reader.create(input) + let end = length === undefined ? reader.len : reader.pos + length + const message = createBaseMsgBuyback() + while (reader.pos < end) { + const tag = reader.uint32() + switch (tag >>> 3) { + case 1: + if (tag !== 10) { + break + } + + message.creator = reader.string() + continue + case 2: + if (tag !== 18) { + break + } + + message.gov = Coin.decode(reader, reader.uint32()) + continue + } + if ((tag & 7) === 4 || tag === 0) { + break + } + reader.skipType(tag & 7) + } + return message + }, + + fromJSON(object: any): MsgBuyback { + return { + creator: isSet(object.creator) ? String(object.creator) : "", + gov: isSet(object.gov) ? Coin.fromJSON(object.gov) : undefined, + } + }, + + toJSON(message: MsgBuyback): unknown { + const obj: any = {} + message.creator !== undefined && (obj.creator = message.creator) + message.gov !== undefined && + (obj.gov = message.gov ? Coin.toJSON(message.gov) : undefined) + return obj + }, + + create, I>>(base?: I): MsgBuyback { + return MsgBuyback.fromPartial(base ?? {}) + }, + + fromPartial, I>>( + object: I + ): MsgBuyback { + const message = createBaseMsgBuyback() + message.creator = object.creator ?? "" + message.gov = + object.gov !== undefined && object.gov !== null + ? Coin.fromPartial(object.gov) + : undefined + return message + }, +} + +function createBaseMsgBuybackResponse(): MsgBuybackResponse { + return { coll: undefined } +} + +export const MsgBuybackResponse = { + encode( + message: MsgBuybackResponse, + writer: _m0.Writer = _m0.Writer.create() + ): _m0.Writer { + if (message.coll !== undefined) { + Coin.encode(message.coll, writer.uint32(10).fork()).ldelim() + } + return writer + }, + + decode(input: _m0.Reader | Uint8Array, length?: number): MsgBuybackResponse { + const reader = + input instanceof _m0.Reader ? input : _m0.Reader.create(input) + let end = length === undefined ? reader.len : reader.pos + length + const message = createBaseMsgBuybackResponse() + while (reader.pos < end) { + const tag = reader.uint32() + switch (tag >>> 3) { + case 1: + if (tag !== 10) { + break + } + + message.coll = Coin.decode(reader, reader.uint32()) + continue + } + if ((tag & 7) === 4 || tag === 0) { + break + } + reader.skipType(tag & 7) + } + return message + }, + + fromJSON(object: any): MsgBuybackResponse { + return { coll: isSet(object.coll) ? Coin.fromJSON(object.coll) : undefined } + }, + + toJSON(message: MsgBuybackResponse): unknown { + const obj: any = {} + message.coll !== undefined && + (obj.coll = message.coll ? Coin.toJSON(message.coll) : undefined) + return obj + }, + + create, I>>( + base?: I + ): MsgBuybackResponse { + return MsgBuybackResponse.fromPartial(base ?? {}) + }, + + fromPartial, I>>( + object: I + ): MsgBuybackResponse { + const message = createBaseMsgBuybackResponse() + message.coll = + object.coll !== undefined && object.coll !== null + ? Coin.fromPartial(object.coll) + : undefined + return message + }, +} + +/** Msg defines the x/stablecoin Msg service. */ +export interface Msg { + /** + * MintStable defines a method for trading a mixture of GOV and COLL to mint + * an equivalent value of stablecoins. + */ + MintStable(request: MsgMintStable): Promise + /** + * BurnStable defines a method for redeeming/burning stablecoins to receive an + * equivalent value as a mixture of governance and collateral tokens. + */ + BurnStable(request: MsgBurnStable): Promise + /** + * Recollateralize defines a method for manually adding collateral to the + * protocol in exchange for an equivalent stablecoin value in governance tokens + * plus a small bonus. + */ + Recollateralize( + request: MsgRecollateralize + ): Promise + /** + * Buyback defines a method for manually adding NIBI to the protocol + * in exchange for an equivalent stablecoin value in collateral, effectively + * executing a share buyback for Nibiru Chain. The NIBI purchased by the protocol + * is then burned, distributing value to all NIBI hodlers. + */ + Buyback(request: MsgBuyback): Promise +} + +export const MsgServiceName = "nibiru.stablecoin.v1.Msg" +export class MsgClientImpl implements Msg { + private readonly rpc: Rpc + private readonly service: string + constructor(rpc: Rpc, opts?: { service?: string }) { + this.service = opts?.service || MsgServiceName + this.rpc = rpc + this.MintStable = this.MintStable.bind(this) + this.BurnStable = this.BurnStable.bind(this) + this.Recollateralize = this.Recollateralize.bind(this) + this.Buyback = this.Buyback.bind(this) + } + MintStable(request: MsgMintStable): Promise { + const data = MsgMintStable.encode(request).finish() + const promise = this.rpc.request(this.service, "MintStable", data) + return promise.then((data) => + MsgMintStableResponse.decode(_m0.Reader.create(data)) + ) + } + + BurnStable(request: MsgBurnStable): Promise { + const data = MsgBurnStable.encode(request).finish() + const promise = this.rpc.request(this.service, "BurnStable", data) + return promise.then((data) => + MsgBurnStableResponse.decode(_m0.Reader.create(data)) + ) + } + + Recollateralize( + request: MsgRecollateralize + ): Promise { + const data = MsgRecollateralize.encode(request).finish() + const promise = this.rpc.request(this.service, "Recollateralize", data) + return promise.then((data) => + MsgRecollateralizeResponse.decode(_m0.Reader.create(data)) + ) + } + + Buyback(request: MsgBuyback): Promise { + const data = MsgBuyback.encode(request).finish() + const promise = this.rpc.request(this.service, "Buyback", data) + return promise.then((data) => + MsgBuybackResponse.decode(_m0.Reader.create(data)) + ) + } +} + +interface Rpc { + request( + service: string, + method: string, + data: Uint8Array + ): Promise +} + +type Builtin = + | Date + | Function + | Uint8Array + | string + | number + | boolean + | undefined + +export type DeepPartial = T extends Builtin + ? T + : T extends Long + ? string | number | Long + : T extends Array + ? Array> + : T extends ReadonlyArray + ? ReadonlyArray> + : T extends {} + ? { [K in keyof T]?: DeepPartial } + : Partial + +type KeysOfUnion = T extends T ? keyof T : never +export type Exact = P extends Builtin + ? P + : P & { [K in keyof P]: Exact } & { + [K in Exclude>]: never + } + +if (_m0.util.Long !== Long) { + _m0.util.Long = Long as any + _m0.configure() +} + +function isSet(value: any): boolean { + return value !== null && value !== undefined +} diff --git a/packages/protojs/src/nibiru/tokenfactory/v1/event.ts b/packages/protojs/src/nibiru/tokenfactory/v1/event.ts deleted file mode 100644 index 6379d103..00000000 --- a/packages/protojs/src/nibiru/tokenfactory/v1/event.ts +++ /dev/null @@ -1,539 +0,0 @@ -/* eslint-disable */ -import Long from "long" -import _m0 from "protobufjs/minimal" -import { Metadata } from "../../../cosmos/bank/v1beta1/bank" -import { Coin } from "../../../cosmos/base/v1beta1/coin" - -export const protobufPackage = "nibiru.tokenfactory.v1" - -export interface EventCreateDenom { - denom: string - creator: string -} - -export interface EventChangeAdmin { - denom: string - newAdmin: string - oldAdmin: string -} - -export interface EventMint { - coin?: Coin - toAddr: string - caller: string -} - -export interface EventBurn { - coin?: Coin - fromAddr: string - caller: string -} - -export interface EventSetDenomMetadata { - denom: string - /** - * Metadata: Official x/bank metadata for the denom. All token factory denoms - * are standard, native assets. The "metadata.base" is the denom. - */ - metadata?: Metadata - caller: string -} - -function createBaseEventCreateDenom(): EventCreateDenom { - return { denom: "", creator: "" } -} - -export const EventCreateDenom = { - encode( - message: EventCreateDenom, - writer: _m0.Writer = _m0.Writer.create() - ): _m0.Writer { - if (message.denom !== "") { - writer.uint32(10).string(message.denom) - } - if (message.creator !== "") { - writer.uint32(18).string(message.creator) - } - return writer - }, - - decode(input: _m0.Reader | Uint8Array, length?: number): EventCreateDenom { - const reader = - input instanceof _m0.Reader ? input : _m0.Reader.create(input) - let end = length === undefined ? reader.len : reader.pos + length - const message = createBaseEventCreateDenom() - while (reader.pos < end) { - const tag = reader.uint32() - switch (tag >>> 3) { - case 1: - if (tag !== 10) { - break - } - - message.denom = reader.string() - continue - case 2: - if (tag !== 18) { - break - } - - message.creator = reader.string() - continue - } - if ((tag & 7) === 4 || tag === 0) { - break - } - reader.skipType(tag & 7) - } - return message - }, - - fromJSON(object: any): EventCreateDenom { - return { - denom: isSet(object.denom) ? String(object.denom) : "", - creator: isSet(object.creator) ? String(object.creator) : "", - } - }, - - toJSON(message: EventCreateDenom): unknown { - const obj: any = {} - message.denom !== undefined && (obj.denom = message.denom) - message.creator !== undefined && (obj.creator = message.creator) - return obj - }, - - create, I>>( - base?: I - ): EventCreateDenom { - return EventCreateDenom.fromPartial(base ?? {}) - }, - - fromPartial, I>>( - object: I - ): EventCreateDenom { - const message = createBaseEventCreateDenom() - message.denom = object.denom ?? "" - message.creator = object.creator ?? "" - return message - }, -} - -function createBaseEventChangeAdmin(): EventChangeAdmin { - return { denom: "", newAdmin: "", oldAdmin: "" } -} - -export const EventChangeAdmin = { - encode( - message: EventChangeAdmin, - writer: _m0.Writer = _m0.Writer.create() - ): _m0.Writer { - if (message.denom !== "") { - writer.uint32(10).string(message.denom) - } - if (message.newAdmin !== "") { - writer.uint32(18).string(message.newAdmin) - } - if (message.oldAdmin !== "") { - writer.uint32(26).string(message.oldAdmin) - } - return writer - }, - - decode(input: _m0.Reader | Uint8Array, length?: number): EventChangeAdmin { - const reader = - input instanceof _m0.Reader ? input : _m0.Reader.create(input) - let end = length === undefined ? reader.len : reader.pos + length - const message = createBaseEventChangeAdmin() - while (reader.pos < end) { - const tag = reader.uint32() - switch (tag >>> 3) { - case 1: - if (tag !== 10) { - break - } - - message.denom = reader.string() - continue - case 2: - if (tag !== 18) { - break - } - - message.newAdmin = reader.string() - continue - case 3: - if (tag !== 26) { - break - } - - message.oldAdmin = reader.string() - continue - } - if ((tag & 7) === 4 || tag === 0) { - break - } - reader.skipType(tag & 7) - } - return message - }, - - fromJSON(object: any): EventChangeAdmin { - return { - denom: isSet(object.denom) ? String(object.denom) : "", - newAdmin: isSet(object.newAdmin) ? String(object.newAdmin) : "", - oldAdmin: isSet(object.oldAdmin) ? String(object.oldAdmin) : "", - } - }, - - toJSON(message: EventChangeAdmin): unknown { - const obj: any = {} - message.denom !== undefined && (obj.denom = message.denom) - message.newAdmin !== undefined && (obj.newAdmin = message.newAdmin) - message.oldAdmin !== undefined && (obj.oldAdmin = message.oldAdmin) - return obj - }, - - create, I>>( - base?: I - ): EventChangeAdmin { - return EventChangeAdmin.fromPartial(base ?? {}) - }, - - fromPartial, I>>( - object: I - ): EventChangeAdmin { - const message = createBaseEventChangeAdmin() - message.denom = object.denom ?? "" - message.newAdmin = object.newAdmin ?? "" - message.oldAdmin = object.oldAdmin ?? "" - return message - }, -} - -function createBaseEventMint(): EventMint { - return { coin: undefined, toAddr: "", caller: "" } -} - -export const EventMint = { - encode( - message: EventMint, - writer: _m0.Writer = _m0.Writer.create() - ): _m0.Writer { - if (message.coin !== undefined) { - Coin.encode(message.coin, writer.uint32(10).fork()).ldelim() - } - if (message.toAddr !== "") { - writer.uint32(18).string(message.toAddr) - } - if (message.caller !== "") { - writer.uint32(26).string(message.caller) - } - return writer - }, - - decode(input: _m0.Reader | Uint8Array, length?: number): EventMint { - const reader = - input instanceof _m0.Reader ? input : _m0.Reader.create(input) - let end = length === undefined ? reader.len : reader.pos + length - const message = createBaseEventMint() - while (reader.pos < end) { - const tag = reader.uint32() - switch (tag >>> 3) { - case 1: - if (tag !== 10) { - break - } - - message.coin = Coin.decode(reader, reader.uint32()) - continue - case 2: - if (tag !== 18) { - break - } - - message.toAddr = reader.string() - continue - case 3: - if (tag !== 26) { - break - } - - message.caller = reader.string() - continue - } - if ((tag & 7) === 4 || tag === 0) { - break - } - reader.skipType(tag & 7) - } - return message - }, - - fromJSON(object: any): EventMint { - return { - coin: isSet(object.coin) ? Coin.fromJSON(object.coin) : undefined, - toAddr: isSet(object.toAddr) ? String(object.toAddr) : "", - caller: isSet(object.caller) ? String(object.caller) : "", - } - }, - - toJSON(message: EventMint): unknown { - const obj: any = {} - message.coin !== undefined && - (obj.coin = message.coin ? Coin.toJSON(message.coin) : undefined) - message.toAddr !== undefined && (obj.toAddr = message.toAddr) - message.caller !== undefined && (obj.caller = message.caller) - return obj - }, - - create, I>>(base?: I): EventMint { - return EventMint.fromPartial(base ?? {}) - }, - - fromPartial, I>>( - object: I - ): EventMint { - const message = createBaseEventMint() - message.coin = - object.coin !== undefined && object.coin !== null - ? Coin.fromPartial(object.coin) - : undefined - message.toAddr = object.toAddr ?? "" - message.caller = object.caller ?? "" - return message - }, -} - -function createBaseEventBurn(): EventBurn { - return { coin: undefined, fromAddr: "", caller: "" } -} - -export const EventBurn = { - encode( - message: EventBurn, - writer: _m0.Writer = _m0.Writer.create() - ): _m0.Writer { - if (message.coin !== undefined) { - Coin.encode(message.coin, writer.uint32(10).fork()).ldelim() - } - if (message.fromAddr !== "") { - writer.uint32(18).string(message.fromAddr) - } - if (message.caller !== "") { - writer.uint32(26).string(message.caller) - } - return writer - }, - - decode(input: _m0.Reader | Uint8Array, length?: number): EventBurn { - const reader = - input instanceof _m0.Reader ? input : _m0.Reader.create(input) - let end = length === undefined ? reader.len : reader.pos + length - const message = createBaseEventBurn() - while (reader.pos < end) { - const tag = reader.uint32() - switch (tag >>> 3) { - case 1: - if (tag !== 10) { - break - } - - message.coin = Coin.decode(reader, reader.uint32()) - continue - case 2: - if (tag !== 18) { - break - } - - message.fromAddr = reader.string() - continue - case 3: - if (tag !== 26) { - break - } - - message.caller = reader.string() - continue - } - if ((tag & 7) === 4 || tag === 0) { - break - } - reader.skipType(tag & 7) - } - return message - }, - - fromJSON(object: any): EventBurn { - return { - coin: isSet(object.coin) ? Coin.fromJSON(object.coin) : undefined, - fromAddr: isSet(object.fromAddr) ? String(object.fromAddr) : "", - caller: isSet(object.caller) ? String(object.caller) : "", - } - }, - - toJSON(message: EventBurn): unknown { - const obj: any = {} - message.coin !== undefined && - (obj.coin = message.coin ? Coin.toJSON(message.coin) : undefined) - message.fromAddr !== undefined && (obj.fromAddr = message.fromAddr) - message.caller !== undefined && (obj.caller = message.caller) - return obj - }, - - create, I>>(base?: I): EventBurn { - return EventBurn.fromPartial(base ?? {}) - }, - - fromPartial, I>>( - object: I - ): EventBurn { - const message = createBaseEventBurn() - message.coin = - object.coin !== undefined && object.coin !== null - ? Coin.fromPartial(object.coin) - : undefined - message.fromAddr = object.fromAddr ?? "" - message.caller = object.caller ?? "" - return message - }, -} - -function createBaseEventSetDenomMetadata(): EventSetDenomMetadata { - return { denom: "", metadata: undefined, caller: "" } -} - -export const EventSetDenomMetadata = { - encode( - message: EventSetDenomMetadata, - writer: _m0.Writer = _m0.Writer.create() - ): _m0.Writer { - if (message.denom !== "") { - writer.uint32(10).string(message.denom) - } - if (message.metadata !== undefined) { - Metadata.encode(message.metadata, writer.uint32(18).fork()).ldelim() - } - if (message.caller !== "") { - writer.uint32(26).string(message.caller) - } - return writer - }, - - decode( - input: _m0.Reader | Uint8Array, - length?: number - ): EventSetDenomMetadata { - const reader = - input instanceof _m0.Reader ? input : _m0.Reader.create(input) - let end = length === undefined ? reader.len : reader.pos + length - const message = createBaseEventSetDenomMetadata() - while (reader.pos < end) { - const tag = reader.uint32() - switch (tag >>> 3) { - case 1: - if (tag !== 10) { - break - } - - message.denom = reader.string() - continue - case 2: - if (tag !== 18) { - break - } - - message.metadata = Metadata.decode(reader, reader.uint32()) - continue - case 3: - if (tag !== 26) { - break - } - - message.caller = reader.string() - continue - } - if ((tag & 7) === 4 || tag === 0) { - break - } - reader.skipType(tag & 7) - } - return message - }, - - fromJSON(object: any): EventSetDenomMetadata { - return { - denom: isSet(object.denom) ? String(object.denom) : "", - metadata: isSet(object.metadata) - ? Metadata.fromJSON(object.metadata) - : undefined, - caller: isSet(object.caller) ? String(object.caller) : "", - } - }, - - toJSON(message: EventSetDenomMetadata): unknown { - const obj: any = {} - message.denom !== undefined && (obj.denom = message.denom) - message.metadata !== undefined && - (obj.metadata = message.metadata - ? Metadata.toJSON(message.metadata) - : undefined) - message.caller !== undefined && (obj.caller = message.caller) - return obj - }, - - create, I>>( - base?: I - ): EventSetDenomMetadata { - return EventSetDenomMetadata.fromPartial(base ?? {}) - }, - - fromPartial, I>>( - object: I - ): EventSetDenomMetadata { - const message = createBaseEventSetDenomMetadata() - message.denom = object.denom ?? "" - message.metadata = - object.metadata !== undefined && object.metadata !== null - ? Metadata.fromPartial(object.metadata) - : undefined - message.caller = object.caller ?? "" - return message - }, -} - -type Builtin = - | Date - | Function - | Uint8Array - | string - | number - | boolean - | undefined - -export type DeepPartial = T extends Builtin - ? T - : T extends Long - ? string | number | Long - : T extends Array - ? Array> - : T extends ReadonlyArray - ? ReadonlyArray> - : T extends {} - ? { [K in keyof T]?: DeepPartial } - : Partial - -type KeysOfUnion = T extends T ? keyof T : never -export type Exact = P extends Builtin - ? P - : P & { [K in keyof P]: Exact } & { - [K in Exclude>]: never - } - -if (_m0.util.Long !== Long) { - _m0.util.Long = Long as any - _m0.configure() -} - -function isSet(value: any): boolean { - return value !== null && value !== undefined -} diff --git a/packages/protojs/src/nibiru/tokenfactory/v1/query.ts b/packages/protojs/src/nibiru/tokenfactory/v1/query.ts deleted file mode 100644 index 31db84da..00000000 --- a/packages/protojs/src/nibiru/tokenfactory/v1/query.ts +++ /dev/null @@ -1,552 +0,0 @@ -/* eslint-disable */ -import Long from "long" -import _m0 from "protobufjs/minimal" -import { Metadata } from "../../../cosmos/bank/v1beta1/bank" -import { ModuleParams } from "./state" - -export const protobufPackage = "nibiru.tokenfactory.v1" - -/** 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 { - /** Module parameters stored in state */ - params?: ModuleParams -} - -/** QueryDenomsRequest: gRPC query for all denoms registered for a creator */ -export interface QueryDenomsRequest { - creator: string -} - -/** QueryDenomsResponse: All registered denoms for a creator */ -export interface QueryDenomsResponse { - denoms: string[] -} - -/** QueryDenomInfoRequest: gRPC query for the denom admin and x/bank metadata */ -export interface QueryDenomInfoRequest { - denom: string -} - -/** QueryDenomInfoResponse: All registered denoms for a creator */ -export interface QueryDenomInfoResponse { - /** Admin of the token factory denom */ - admin: string - /** - * Metadata: Official x/bank metadata for the denom. All token factory denoms - * are standard, native assets. - */ - metadata?: Metadata -} - -function createBaseQueryParamsRequest(): QueryParamsRequest { - return {} -} - -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 : _m0.Reader.create(input) - let end = length === undefined ? reader.len : reader.pos + length - const message = createBaseQueryParamsRequest() - while (reader.pos < end) { - const tag = reader.uint32() - switch (tag >>> 3) { - } - if ((tag & 7) === 4 || tag === 0) { - break - } - reader.skipType(tag & 7) - } - return message - }, - - fromJSON(_: any): QueryParamsRequest { - return {} - }, - - toJSON(_: QueryParamsRequest): unknown { - const obj: any = {} - return obj - }, - - create, I>>( - base?: I - ): QueryParamsRequest { - return QueryParamsRequest.fromPartial(base ?? {}) - }, - - fromPartial, I>>( - _: I - ): QueryParamsRequest { - const message = createBaseQueryParamsRequest() - return message - }, -} - -function createBaseQueryParamsResponse(): QueryParamsResponse { - return { params: undefined } -} - -export const QueryParamsResponse = { - encode( - message: QueryParamsResponse, - writer: _m0.Writer = _m0.Writer.create() - ): _m0.Writer { - if (message.params !== undefined) { - ModuleParams.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 : _m0.Reader.create(input) - let end = length === undefined ? reader.len : reader.pos + length - const message = createBaseQueryParamsResponse() - while (reader.pos < end) { - const tag = reader.uint32() - switch (tag >>> 3) { - case 1: - if (tag !== 10) { - break - } - - message.params = ModuleParams.decode(reader, reader.uint32()) - continue - } - if ((tag & 7) === 4 || tag === 0) { - break - } - reader.skipType(tag & 7) - } - return message - }, - - fromJSON(object: any): QueryParamsResponse { - return { - params: isSet(object.params) - ? ModuleParams.fromJSON(object.params) - : undefined, - } - }, - - toJSON(message: QueryParamsResponse): unknown { - const obj: any = {} - message.params !== undefined && - (obj.params = message.params - ? ModuleParams.toJSON(message.params) - : undefined) - return obj - }, - - create, I>>( - base?: I - ): QueryParamsResponse { - return QueryParamsResponse.fromPartial(base ?? {}) - }, - - fromPartial, I>>( - object: I - ): QueryParamsResponse { - const message = createBaseQueryParamsResponse() - message.params = - object.params !== undefined && object.params !== null - ? ModuleParams.fromPartial(object.params) - : undefined - return message - }, -} - -function createBaseQueryDenomsRequest(): QueryDenomsRequest { - return { creator: "" } -} - -export const QueryDenomsRequest = { - encode( - message: QueryDenomsRequest, - writer: _m0.Writer = _m0.Writer.create() - ): _m0.Writer { - if (message.creator !== "") { - writer.uint32(10).string(message.creator) - } - return writer - }, - - decode(input: _m0.Reader | Uint8Array, length?: number): QueryDenomsRequest { - const reader = - input instanceof _m0.Reader ? input : _m0.Reader.create(input) - let end = length === undefined ? reader.len : reader.pos + length - const message = createBaseQueryDenomsRequest() - while (reader.pos < end) { - const tag = reader.uint32() - switch (tag >>> 3) { - case 1: - if (tag !== 10) { - break - } - - message.creator = reader.string() - continue - } - if ((tag & 7) === 4 || tag === 0) { - break - } - reader.skipType(tag & 7) - } - return message - }, - - fromJSON(object: any): QueryDenomsRequest { - return { creator: isSet(object.creator) ? String(object.creator) : "" } - }, - - toJSON(message: QueryDenomsRequest): unknown { - const obj: any = {} - message.creator !== undefined && (obj.creator = message.creator) - return obj - }, - - create, I>>( - base?: I - ): QueryDenomsRequest { - return QueryDenomsRequest.fromPartial(base ?? {}) - }, - - fromPartial, I>>( - object: I - ): QueryDenomsRequest { - const message = createBaseQueryDenomsRequest() - message.creator = object.creator ?? "" - return message - }, -} - -function createBaseQueryDenomsResponse(): QueryDenomsResponse { - return { denoms: [] } -} - -export const QueryDenomsResponse = { - encode( - message: QueryDenomsResponse, - writer: _m0.Writer = _m0.Writer.create() - ): _m0.Writer { - for (const v of message.denoms) { - writer.uint32(10).string(v!) - } - return writer - }, - - decode(input: _m0.Reader | Uint8Array, length?: number): QueryDenomsResponse { - const reader = - input instanceof _m0.Reader ? input : _m0.Reader.create(input) - let end = length === undefined ? reader.len : reader.pos + length - const message = createBaseQueryDenomsResponse() - while (reader.pos < end) { - const tag = reader.uint32() - switch (tag >>> 3) { - case 1: - if (tag !== 10) { - break - } - - message.denoms.push(reader.string()) - continue - } - if ((tag & 7) === 4 || tag === 0) { - break - } - reader.skipType(tag & 7) - } - return message - }, - - fromJSON(object: any): QueryDenomsResponse { - return { - denoms: Array.isArray(object?.denoms) - ? object.denoms.map((e: any) => String(e)) - : [], - } - }, - - toJSON(message: QueryDenomsResponse): unknown { - const obj: any = {} - if (message.denoms) { - obj.denoms = message.denoms.map((e) => e) - } else { - obj.denoms = [] - } - return obj - }, - - create, I>>( - base?: I - ): QueryDenomsResponse { - return QueryDenomsResponse.fromPartial(base ?? {}) - }, - - fromPartial, I>>( - object: I - ): QueryDenomsResponse { - const message = createBaseQueryDenomsResponse() - message.denoms = object.denoms?.map((e) => e) || [] - return message - }, -} - -function createBaseQueryDenomInfoRequest(): QueryDenomInfoRequest { - return { denom: "" } -} - -export const QueryDenomInfoRequest = { - encode( - message: QueryDenomInfoRequest, - writer: _m0.Writer = _m0.Writer.create() - ): _m0.Writer { - if (message.denom !== "") { - writer.uint32(10).string(message.denom) - } - return writer - }, - - decode( - input: _m0.Reader | Uint8Array, - length?: number - ): QueryDenomInfoRequest { - const reader = - input instanceof _m0.Reader ? input : _m0.Reader.create(input) - let end = length === undefined ? reader.len : reader.pos + length - const message = createBaseQueryDenomInfoRequest() - while (reader.pos < end) { - const tag = reader.uint32() - switch (tag >>> 3) { - case 1: - if (tag !== 10) { - break - } - - message.denom = reader.string() - continue - } - if ((tag & 7) === 4 || tag === 0) { - break - } - reader.skipType(tag & 7) - } - return message - }, - - fromJSON(object: any): QueryDenomInfoRequest { - return { denom: isSet(object.denom) ? String(object.denom) : "" } - }, - - toJSON(message: QueryDenomInfoRequest): unknown { - const obj: any = {} - message.denom !== undefined && (obj.denom = message.denom) - return obj - }, - - create, I>>( - base?: I - ): QueryDenomInfoRequest { - return QueryDenomInfoRequest.fromPartial(base ?? {}) - }, - - fromPartial, I>>( - object: I - ): QueryDenomInfoRequest { - const message = createBaseQueryDenomInfoRequest() - message.denom = object.denom ?? "" - return message - }, -} - -function createBaseQueryDenomInfoResponse(): QueryDenomInfoResponse { - return { admin: "", metadata: undefined } -} - -export const QueryDenomInfoResponse = { - encode( - message: QueryDenomInfoResponse, - writer: _m0.Writer = _m0.Writer.create() - ): _m0.Writer { - if (message.admin !== "") { - writer.uint32(10).string(message.admin) - } - if (message.metadata !== undefined) { - Metadata.encode(message.metadata, writer.uint32(18).fork()).ldelim() - } - return writer - }, - - decode( - input: _m0.Reader | Uint8Array, - length?: number - ): QueryDenomInfoResponse { - const reader = - input instanceof _m0.Reader ? input : _m0.Reader.create(input) - let end = length === undefined ? reader.len : reader.pos + length - const message = createBaseQueryDenomInfoResponse() - while (reader.pos < end) { - const tag = reader.uint32() - switch (tag >>> 3) { - case 1: - if (tag !== 10) { - break - } - - message.admin = reader.string() - continue - case 2: - if (tag !== 18) { - break - } - - message.metadata = Metadata.decode(reader, reader.uint32()) - continue - } - if ((tag & 7) === 4 || tag === 0) { - break - } - reader.skipType(tag & 7) - } - return message - }, - - fromJSON(object: any): QueryDenomInfoResponse { - return { - admin: isSet(object.admin) ? String(object.admin) : "", - metadata: isSet(object.metadata) - ? Metadata.fromJSON(object.metadata) - : undefined, - } - }, - - toJSON(message: QueryDenomInfoResponse): unknown { - const obj: any = {} - message.admin !== undefined && (obj.admin = message.admin) - message.metadata !== undefined && - (obj.metadata = message.metadata - ? Metadata.toJSON(message.metadata) - : undefined) - return obj - }, - - create, I>>( - base?: I - ): QueryDenomInfoResponse { - return QueryDenomInfoResponse.fromPartial(base ?? {}) - }, - - fromPartial, I>>( - object: I - ): QueryDenomInfoResponse { - const message = createBaseQueryDenomInfoResponse() - message.admin = object.admin ?? "" - message.metadata = - object.metadata !== undefined && object.metadata !== null - ? Metadata.fromPartial(object.metadata) - : undefined - return message - }, -} - -/** Query defines the gRPC querier service. */ -export interface Query { - /** Params retrieves the module params */ - Params(request: QueryParamsRequest): Promise - /** Denoms retrieves all registered denoms for a given creator */ - Denoms(request: QueryDenomsRequest): Promise - /** DenomInfo retrieves the denom metadata and admin info */ - DenomInfo(request: QueryDenomInfoRequest): Promise -} - -export const QueryServiceName = "nibiru.tokenfactory.v1.Query" -export class QueryClientImpl implements Query { - private readonly rpc: Rpc - private readonly service: string - constructor(rpc: Rpc, opts?: { service?: string }) { - this.service = opts?.service || QueryServiceName - this.rpc = rpc - this.Params = this.Params.bind(this) - this.Denoms = this.Denoms.bind(this) - this.DenomInfo = this.DenomInfo.bind(this) - } - Params(request: QueryParamsRequest): Promise { - const data = QueryParamsRequest.encode(request).finish() - const promise = this.rpc.request(this.service, "Params", data) - return promise.then((data) => - QueryParamsResponse.decode(_m0.Reader.create(data)) - ) - } - - Denoms(request: QueryDenomsRequest): Promise { - const data = QueryDenomsRequest.encode(request).finish() - const promise = this.rpc.request(this.service, "Denoms", data) - return promise.then((data) => - QueryDenomsResponse.decode(_m0.Reader.create(data)) - ) - } - - DenomInfo(request: QueryDenomInfoRequest): Promise { - const data = QueryDenomInfoRequest.encode(request).finish() - const promise = this.rpc.request(this.service, "DenomInfo", data) - return promise.then((data) => - QueryDenomInfoResponse.decode(_m0.Reader.create(data)) - ) - } -} - -interface Rpc { - request( - service: string, - method: string, - data: Uint8Array - ): Promise -} - -type Builtin = - | Date - | Function - | Uint8Array - | string - | number - | boolean - | undefined - -export type DeepPartial = T extends Builtin - ? T - : T extends Long - ? string | number | Long - : T extends Array - ? Array> - : T extends ReadonlyArray - ? ReadonlyArray> - : T extends {} - ? { [K in keyof T]?: DeepPartial } - : Partial - -type KeysOfUnion = T extends T ? keyof T : never -export type Exact = P extends Builtin - ? P - : P & { [K in keyof P]: Exact } & { - [K in Exclude>]: never - } - -if (_m0.util.Long !== Long) { - _m0.util.Long = Long as any - _m0.configure() -} - -function isSet(value: any): boolean { - return value !== null && value !== undefined -} diff --git a/packages/protojs/src/nibiru/tokenfactory/v1/state.ts b/packages/protojs/src/nibiru/tokenfactory/v1/state.ts deleted file mode 100644 index 5337b1e7..00000000 --- a/packages/protojs/src/nibiru/tokenfactory/v1/state.ts +++ /dev/null @@ -1,526 +0,0 @@ -/* eslint-disable */ -import Long from "long" -import _m0 from "protobufjs/minimal" - -export const protobufPackage = "nibiru.tokenfactory.v1" - -/** - * DenomAuthorityMetadata specifies metadata foraddresses that have specific - * capabilities over a token factory denom. Right now there is only one Admin - * permission, but is planned to be extended to the future. - */ -export interface DenomAuthorityMetadata { - /** - * Admin: Bech32 address of the admin for the tokefactory denom. Can be empty - * for no admin. - */ - admin: string -} - -/** - * ModuleParams defines the parameters for the tokenfactory module. - * - * ### On Denom Creation Costs - * - * We'd like for fees to be paid by the user/signer of a ransaction, but in many - * casess, token creation is abstracted away behind a smart contract. Setting a - * nonzero `denom_creation_fee` would force each contract to handle collecting - * and paying a fees for denom (factory/{contract-addr}/{subdenom}) creation on - * behalf of the end user. - * - * For IBC token transfers, it's unclear who should pay the feeā€”the contract, - * the relayer, or the original sender? - * > "Charging fees will mess up composability, the same way Terra transfer tax - * caused all kinds of headaches for contract devs." - @ethanfrey - * - * ### Recommended Solution - * - * Have the end user (signer) pay fees directly in the form of higher gas costs. - * This way, contracts won't need to handle collecting or paying fees. And for - * IBC, the gas costs are already paid by the original sender and can be - * estimated by the relayer. It's easier to tune gas costs to make spam - * prohibitively expensive since there are per-transaction and per-block gas - * limits. - * - * See https://github.com/CosmWasm/token-factory/issues/11 for the initial - * discussion of the issue with @ethanfrey and @valardragon. - */ -export interface ModuleParams { - /** - * Adds gas consumption to the execution of `MsgCreateDenom` as a method of - * spam prevention. Defaults to 10 NIBI. - */ - denomCreationGasConsume: Long -} - -/** - * TFDenom is a token factory (TF) denom. The canonical representation is - * "tf/{creator}/{subdenom}", its unique denomination in the x/bank module. - */ -export interface TFDenom { - /** Creator: Bech32 address of the creator of the denom. */ - creator: string - /** - * Subdenom: Unique suffix of a token factory denom. A subdenom is specific - * to a given creator. It is the name given during a token factory "Mint". - */ - subdenom: string -} - -/** GenesisState for the Token Factory module. */ -export interface GenesisState { - params?: ModuleParams - factoryDenoms: GenesisDenom[] -} - -/** GenesisDenom defines a tokenfactory denoms in the genesis state. */ -export interface GenesisDenom { - denom: string - authorityMetadata?: DenomAuthorityMetadata -} - -function createBaseDenomAuthorityMetadata(): DenomAuthorityMetadata { - return { admin: "" } -} - -export const DenomAuthorityMetadata = { - encode( - message: DenomAuthorityMetadata, - writer: _m0.Writer = _m0.Writer.create() - ): _m0.Writer { - if (message.admin !== "") { - writer.uint32(10).string(message.admin) - } - return writer - }, - - decode( - input: _m0.Reader | Uint8Array, - length?: number - ): DenomAuthorityMetadata { - const reader = - input instanceof _m0.Reader ? input : _m0.Reader.create(input) - let end = length === undefined ? reader.len : reader.pos + length - const message = createBaseDenomAuthorityMetadata() - while (reader.pos < end) { - const tag = reader.uint32() - switch (tag >>> 3) { - case 1: - if (tag !== 10) { - break - } - - message.admin = reader.string() - continue - } - if ((tag & 7) === 4 || tag === 0) { - break - } - reader.skipType(tag & 7) - } - return message - }, - - fromJSON(object: any): DenomAuthorityMetadata { - return { admin: isSet(object.admin) ? String(object.admin) : "" } - }, - - toJSON(message: DenomAuthorityMetadata): unknown { - const obj: any = {} - message.admin !== undefined && (obj.admin = message.admin) - return obj - }, - - create, I>>( - base?: I - ): DenomAuthorityMetadata { - return DenomAuthorityMetadata.fromPartial(base ?? {}) - }, - - fromPartial, I>>( - object: I - ): DenomAuthorityMetadata { - const message = createBaseDenomAuthorityMetadata() - message.admin = object.admin ?? "" - return message - }, -} - -function createBaseModuleParams(): ModuleParams { - return { denomCreationGasConsume: Long.UZERO } -} - -export const ModuleParams = { - encode( - message: ModuleParams, - writer: _m0.Writer = _m0.Writer.create() - ): _m0.Writer { - if (!message.denomCreationGasConsume.isZero()) { - writer.uint32(8).uint64(message.denomCreationGasConsume) - } - return writer - }, - - decode(input: _m0.Reader | Uint8Array, length?: number): ModuleParams { - const reader = - input instanceof _m0.Reader ? input : _m0.Reader.create(input) - let end = length === undefined ? reader.len : reader.pos + length - const message = createBaseModuleParams() - while (reader.pos < end) { - const tag = reader.uint32() - switch (tag >>> 3) { - case 1: - if (tag !== 8) { - break - } - - message.denomCreationGasConsume = reader.uint64() as Long - continue - } - if ((tag & 7) === 4 || tag === 0) { - break - } - reader.skipType(tag & 7) - } - return message - }, - - fromJSON(object: any): ModuleParams { - return { - denomCreationGasConsume: isSet(object.denomCreationGasConsume) - ? Long.fromValue(object.denomCreationGasConsume) - : Long.UZERO, - } - }, - - toJSON(message: ModuleParams): unknown { - const obj: any = {} - message.denomCreationGasConsume !== undefined && - (obj.denomCreationGasConsume = ( - message.denomCreationGasConsume || Long.UZERO - ).toString()) - return obj - }, - - create, I>>( - base?: I - ): ModuleParams { - return ModuleParams.fromPartial(base ?? {}) - }, - - fromPartial, I>>( - object: I - ): ModuleParams { - const message = createBaseModuleParams() - message.denomCreationGasConsume = - object.denomCreationGasConsume !== undefined && - object.denomCreationGasConsume !== null - ? Long.fromValue(object.denomCreationGasConsume) - : Long.UZERO - return message - }, -} - -function createBaseTFDenom(): TFDenom { - return { creator: "", subdenom: "" } -} - -export const TFDenom = { - encode( - message: TFDenom, - writer: _m0.Writer = _m0.Writer.create() - ): _m0.Writer { - if (message.creator !== "") { - writer.uint32(10).string(message.creator) - } - if (message.subdenom !== "") { - writer.uint32(18).string(message.subdenom) - } - return writer - }, - - decode(input: _m0.Reader | Uint8Array, length?: number): TFDenom { - const reader = - input instanceof _m0.Reader ? input : _m0.Reader.create(input) - let end = length === undefined ? reader.len : reader.pos + length - const message = createBaseTFDenom() - while (reader.pos < end) { - const tag = reader.uint32() - switch (tag >>> 3) { - case 1: - if (tag !== 10) { - break - } - - message.creator = reader.string() - continue - case 2: - if (tag !== 18) { - break - } - - message.subdenom = reader.string() - continue - } - if ((tag & 7) === 4 || tag === 0) { - break - } - reader.skipType(tag & 7) - } - return message - }, - - fromJSON(object: any): TFDenom { - return { - creator: isSet(object.creator) ? String(object.creator) : "", - subdenom: isSet(object.subdenom) ? String(object.subdenom) : "", - } - }, - - toJSON(message: TFDenom): unknown { - const obj: any = {} - message.creator !== undefined && (obj.creator = message.creator) - message.subdenom !== undefined && (obj.subdenom = message.subdenom) - return obj - }, - - create, I>>(base?: I): TFDenom { - return TFDenom.fromPartial(base ?? {}) - }, - - fromPartial, I>>(object: I): TFDenom { - const message = createBaseTFDenom() - message.creator = object.creator ?? "" - message.subdenom = object.subdenom ?? "" - return message - }, -} - -function createBaseGenesisState(): GenesisState { - return { params: undefined, factoryDenoms: [] } -} - -export const GenesisState = { - encode( - message: GenesisState, - writer: _m0.Writer = _m0.Writer.create() - ): _m0.Writer { - if (message.params !== undefined) { - ModuleParams.encode(message.params, writer.uint32(10).fork()).ldelim() - } - for (const v of message.factoryDenoms) { - GenesisDenom.encode(v!, writer.uint32(18).fork()).ldelim() - } - return writer - }, - - decode(input: _m0.Reader | Uint8Array, length?: number): GenesisState { - const reader = - input instanceof _m0.Reader ? input : _m0.Reader.create(input) - let end = length === undefined ? reader.len : reader.pos + length - const message = createBaseGenesisState() - while (reader.pos < end) { - const tag = reader.uint32() - switch (tag >>> 3) { - case 1: - if (tag !== 10) { - break - } - - message.params = ModuleParams.decode(reader, reader.uint32()) - continue - case 2: - if (tag !== 18) { - break - } - - message.factoryDenoms.push( - GenesisDenom.decode(reader, reader.uint32()) - ) - continue - } - if ((tag & 7) === 4 || tag === 0) { - break - } - reader.skipType(tag & 7) - } - return message - }, - - fromJSON(object: any): GenesisState { - return { - params: isSet(object.params) - ? ModuleParams.fromJSON(object.params) - : undefined, - factoryDenoms: Array.isArray(object?.factoryDenoms) - ? object.factoryDenoms.map((e: any) => GenesisDenom.fromJSON(e)) - : [], - } - }, - - toJSON(message: GenesisState): unknown { - const obj: any = {} - message.params !== undefined && - (obj.params = message.params - ? ModuleParams.toJSON(message.params) - : undefined) - if (message.factoryDenoms) { - obj.factoryDenoms = message.factoryDenoms.map((e) => - e ? GenesisDenom.toJSON(e) : undefined - ) - } else { - obj.factoryDenoms = [] - } - return obj - }, - - create, I>>( - base?: I - ): GenesisState { - return GenesisState.fromPartial(base ?? {}) - }, - - fromPartial, I>>( - object: I - ): GenesisState { - const message = createBaseGenesisState() - message.params = - object.params !== undefined && object.params !== null - ? ModuleParams.fromPartial(object.params) - : undefined - message.factoryDenoms = - object.factoryDenoms?.map((e) => GenesisDenom.fromPartial(e)) || [] - return message - }, -} - -function createBaseGenesisDenom(): GenesisDenom { - return { denom: "", authorityMetadata: undefined } -} - -export const GenesisDenom = { - encode( - message: GenesisDenom, - writer: _m0.Writer = _m0.Writer.create() - ): _m0.Writer { - if (message.denom !== "") { - writer.uint32(10).string(message.denom) - } - if (message.authorityMetadata !== undefined) { - DenomAuthorityMetadata.encode( - message.authorityMetadata, - writer.uint32(18).fork() - ).ldelim() - } - return writer - }, - - decode(input: _m0.Reader | Uint8Array, length?: number): GenesisDenom { - const reader = - input instanceof _m0.Reader ? input : _m0.Reader.create(input) - let end = length === undefined ? reader.len : reader.pos + length - const message = createBaseGenesisDenom() - while (reader.pos < end) { - const tag = reader.uint32() - switch (tag >>> 3) { - case 1: - if (tag !== 10) { - break - } - - message.denom = reader.string() - continue - case 2: - if (tag !== 18) { - break - } - - message.authorityMetadata = DenomAuthorityMetadata.decode( - reader, - reader.uint32() - ) - continue - } - if ((tag & 7) === 4 || tag === 0) { - break - } - reader.skipType(tag & 7) - } - return message - }, - - fromJSON(object: any): GenesisDenom { - return { - denom: isSet(object.denom) ? String(object.denom) : "", - authorityMetadata: isSet(object.authorityMetadata) - ? DenomAuthorityMetadata.fromJSON(object.authorityMetadata) - : undefined, - } - }, - - toJSON(message: GenesisDenom): unknown { - const obj: any = {} - message.denom !== undefined && (obj.denom = message.denom) - message.authorityMetadata !== undefined && - (obj.authorityMetadata = message.authorityMetadata - ? DenomAuthorityMetadata.toJSON(message.authorityMetadata) - : undefined) - return obj - }, - - create, I>>( - base?: I - ): GenesisDenom { - return GenesisDenom.fromPartial(base ?? {}) - }, - - fromPartial, I>>( - object: I - ): GenesisDenom { - const message = createBaseGenesisDenom() - message.denom = object.denom ?? "" - message.authorityMetadata = - object.authorityMetadata !== undefined && - object.authorityMetadata !== null - ? DenomAuthorityMetadata.fromPartial(object.authorityMetadata) - : undefined - return message - }, -} - -type Builtin = - | Date - | Function - | Uint8Array - | string - | number - | boolean - | undefined - -export type DeepPartial = T extends Builtin - ? T - : T extends Long - ? string | number | Long - : T extends Array - ? Array> - : T extends ReadonlyArray - ? ReadonlyArray> - : T extends {} - ? { [K in keyof T]?: DeepPartial } - : Partial - -type KeysOfUnion = T extends T ? keyof T : never -export type Exact = P extends Builtin - ? P - : P & { [K in keyof P]: Exact } & { - [K in Exclude>]: never - } - -if (_m0.util.Long !== Long) { - _m0.util.Long = Long as any - _m0.configure() -} - -function isSet(value: any): boolean { - return value !== null && value !== undefined -} diff --git a/packages/protojs/src/nibiru/tokenfactory/v1/tx.ts b/packages/protojs/src/nibiru/tokenfactory/v1/tx.ts deleted file mode 100644 index c025f71d..00000000 --- a/packages/protojs/src/nibiru/tokenfactory/v1/tx.ts +++ /dev/null @@ -1,1118 +0,0 @@ -/* eslint-disable */ -import Long from "long" -import _m0 from "protobufjs/minimal" -import { Metadata } from "../../../cosmos/bank/v1beta1/bank" -import { Coin } from "../../../cosmos/base/v1beta1/coin" -import { ModuleParams } from "./state" - -export const protobufPackage = "nibiru.tokenfactory.v1" - -/** - * MsgCreateDenom: sdk.Msg that registers an a token factory denom. - * A denom has the form "tf/[creatorAddr]/[subdenom]". - * - Denoms become unique x/bank tokens, so the creator-subdenom pair that - * defines a denom cannot be reused. - * - The resulting denom's admin is originally set to be the creator, but the - * admin can be changed later. - */ -export interface MsgCreateDenom { - sender: string - /** subdenom can be up to 44 "alphanumeric" characters long. */ - subdenom: string -} - -/** MsgCreateDenomResponse is the return value of MsgCreateDenom */ -export interface MsgCreateDenomResponse { - /** NewTokenDenom: identifier for the newly created token factory denom. */ - newTokenDenom: string -} - -/** - * MsgChangeAdmin is the sdk.Msg type for allowing an admin account to change - * admin of a denom to a new account - */ -export interface MsgChangeAdmin { - sender: string - denom: string - newAdmin: string -} - -/** MsgChangeAdminResponse is the gRPC response for the MsgChangeAdmin TxMsg. */ -export interface MsgChangeAdminResponse {} - -/** MsgUpdateModuleParams: sdk.Msg for updating the x/tokenfactory module params */ -export interface MsgUpdateModuleParams { - /** Authority: Address of the governance module account. */ - authority: string - params?: ModuleParams -} - -/** - * MsgUpdateModuleParamsResponse is the gRPC response for the - * MsgUpdateModuleParams TxMsg. - */ -export interface MsgUpdateModuleParamsResponse {} - -/** MsgMint: sdk.Msg (TxMsg) where an denom admin mints more of the token. */ -export interface MsgMint { - sender: string - /** coin: The denom identifier and amount to mint. */ - coin?: Coin - /** - * mint_to_addr: An address to which tokens will be minted. If blank, - * tokens are minted to the "sender". - */ - mintTo: string -} - -export interface MsgMintResponse { - mintTo: string -} - -/** - * MsgBurn: sdk.Msg (TxMsg) where a denom admin burns some of the token. - * The reason that the sender isn't automatically the "burn_from" address - * is to support smart contracts (primary use case). In this situation, the - * contract is the message signer and sender, while "burn_from" is based on the - * contract logic. - */ -export interface MsgBurn { - sender: string - /** coin: The denom identifier and amount to burn. */ - coin?: Coin - /** burn_from: The address from which tokens will be burned. */ - burnFrom: string -} - -export interface MsgBurnResponse {} - -/** - * MsgSetDenomMetadata: sdk.Msg (TxMsg) enabling the denom admin to change its - * bank metadata. - */ -export interface MsgSetDenomMetadata { - sender: string - /** - * Metadata: Official x/bank metadata for the denom. All token factory denoms - * are standard, native assets. The "metadata.base" is the denom. - */ - metadata?: Metadata -} - -export interface MsgSetDenomMetadataResponse {} - -function createBaseMsgCreateDenom(): MsgCreateDenom { - return { sender: "", subdenom: "" } -} - -export const MsgCreateDenom = { - encode( - message: MsgCreateDenom, - writer: _m0.Writer = _m0.Writer.create() - ): _m0.Writer { - if (message.sender !== "") { - writer.uint32(10).string(message.sender) - } - if (message.subdenom !== "") { - writer.uint32(18).string(message.subdenom) - } - return writer - }, - - decode(input: _m0.Reader | Uint8Array, length?: number): MsgCreateDenom { - const reader = - input instanceof _m0.Reader ? input : _m0.Reader.create(input) - let end = length === undefined ? reader.len : reader.pos + length - const message = createBaseMsgCreateDenom() - while (reader.pos < end) { - const tag = reader.uint32() - switch (tag >>> 3) { - case 1: - if (tag !== 10) { - break - } - - message.sender = reader.string() - continue - case 2: - if (tag !== 18) { - break - } - - message.subdenom = reader.string() - continue - } - if ((tag & 7) === 4 || tag === 0) { - break - } - reader.skipType(tag & 7) - } - return message - }, - - fromJSON(object: any): MsgCreateDenom { - return { - sender: isSet(object.sender) ? String(object.sender) : "", - subdenom: isSet(object.subdenom) ? String(object.subdenom) : "", - } - }, - - toJSON(message: MsgCreateDenom): unknown { - const obj: any = {} - message.sender !== undefined && (obj.sender = message.sender) - message.subdenom !== undefined && (obj.subdenom = message.subdenom) - return obj - }, - - create, I>>( - base?: I - ): MsgCreateDenom { - return MsgCreateDenom.fromPartial(base ?? {}) - }, - - fromPartial, I>>( - object: I - ): MsgCreateDenom { - const message = createBaseMsgCreateDenom() - message.sender = object.sender ?? "" - message.subdenom = object.subdenom ?? "" - return message - }, -} - -function createBaseMsgCreateDenomResponse(): MsgCreateDenomResponse { - return { newTokenDenom: "" } -} - -export const MsgCreateDenomResponse = { - encode( - message: MsgCreateDenomResponse, - writer: _m0.Writer = _m0.Writer.create() - ): _m0.Writer { - if (message.newTokenDenom !== "") { - writer.uint32(10).string(message.newTokenDenom) - } - return writer - }, - - decode( - input: _m0.Reader | Uint8Array, - length?: number - ): MsgCreateDenomResponse { - const reader = - input instanceof _m0.Reader ? input : _m0.Reader.create(input) - let end = length === undefined ? reader.len : reader.pos + length - const message = createBaseMsgCreateDenomResponse() - while (reader.pos < end) { - const tag = reader.uint32() - switch (tag >>> 3) { - case 1: - if (tag !== 10) { - break - } - - message.newTokenDenom = reader.string() - continue - } - if ((tag & 7) === 4 || tag === 0) { - break - } - reader.skipType(tag & 7) - } - return message - }, - - fromJSON(object: any): MsgCreateDenomResponse { - return { - newTokenDenom: isSet(object.newTokenDenom) - ? String(object.newTokenDenom) - : "", - } - }, - - toJSON(message: MsgCreateDenomResponse): unknown { - const obj: any = {} - message.newTokenDenom !== undefined && - (obj.newTokenDenom = message.newTokenDenom) - return obj - }, - - create, I>>( - base?: I - ): MsgCreateDenomResponse { - return MsgCreateDenomResponse.fromPartial(base ?? {}) - }, - - fromPartial, I>>( - object: I - ): MsgCreateDenomResponse { - const message = createBaseMsgCreateDenomResponse() - message.newTokenDenom = object.newTokenDenom ?? "" - return message - }, -} - -function createBaseMsgChangeAdmin(): MsgChangeAdmin { - return { sender: "", denom: "", newAdmin: "" } -} - -export const MsgChangeAdmin = { - encode( - message: MsgChangeAdmin, - writer: _m0.Writer = _m0.Writer.create() - ): _m0.Writer { - if (message.sender !== "") { - writer.uint32(10).string(message.sender) - } - if (message.denom !== "") { - writer.uint32(18).string(message.denom) - } - if (message.newAdmin !== "") { - writer.uint32(26).string(message.newAdmin) - } - return writer - }, - - decode(input: _m0.Reader | Uint8Array, length?: number): MsgChangeAdmin { - const reader = - input instanceof _m0.Reader ? input : _m0.Reader.create(input) - let end = length === undefined ? reader.len : reader.pos + length - const message = createBaseMsgChangeAdmin() - while (reader.pos < end) { - const tag = reader.uint32() - switch (tag >>> 3) { - case 1: - if (tag !== 10) { - break - } - - message.sender = reader.string() - continue - case 2: - if (tag !== 18) { - break - } - - message.denom = reader.string() - continue - case 3: - if (tag !== 26) { - break - } - - message.newAdmin = reader.string() - continue - } - if ((tag & 7) === 4 || tag === 0) { - break - } - reader.skipType(tag & 7) - } - return message - }, - - fromJSON(object: any): MsgChangeAdmin { - return { - sender: isSet(object.sender) ? String(object.sender) : "", - denom: isSet(object.denom) ? String(object.denom) : "", - newAdmin: isSet(object.newAdmin) ? String(object.newAdmin) : "", - } - }, - - toJSON(message: MsgChangeAdmin): unknown { - const obj: any = {} - message.sender !== undefined && (obj.sender = message.sender) - message.denom !== undefined && (obj.denom = message.denom) - message.newAdmin !== undefined && (obj.newAdmin = message.newAdmin) - return obj - }, - - create, I>>( - base?: I - ): MsgChangeAdmin { - return MsgChangeAdmin.fromPartial(base ?? {}) - }, - - fromPartial, I>>( - object: I - ): MsgChangeAdmin { - const message = createBaseMsgChangeAdmin() - message.sender = object.sender ?? "" - message.denom = object.denom ?? "" - message.newAdmin = object.newAdmin ?? "" - return message - }, -} - -function createBaseMsgChangeAdminResponse(): MsgChangeAdminResponse { - return {} -} - -export const MsgChangeAdminResponse = { - encode( - _: MsgChangeAdminResponse, - writer: _m0.Writer = _m0.Writer.create() - ): _m0.Writer { - return writer - }, - - decode( - input: _m0.Reader | Uint8Array, - length?: number - ): MsgChangeAdminResponse { - const reader = - input instanceof _m0.Reader ? input : _m0.Reader.create(input) - let end = length === undefined ? reader.len : reader.pos + length - const message = createBaseMsgChangeAdminResponse() - while (reader.pos < end) { - const tag = reader.uint32() - switch (tag >>> 3) { - } - if ((tag & 7) === 4 || tag === 0) { - break - } - reader.skipType(tag & 7) - } - return message - }, - - fromJSON(_: any): MsgChangeAdminResponse { - return {} - }, - - toJSON(_: MsgChangeAdminResponse): unknown { - const obj: any = {} - return obj - }, - - create, I>>( - base?: I - ): MsgChangeAdminResponse { - return MsgChangeAdminResponse.fromPartial(base ?? {}) - }, - - fromPartial, I>>( - _: I - ): MsgChangeAdminResponse { - const message = createBaseMsgChangeAdminResponse() - return message - }, -} - -function createBaseMsgUpdateModuleParams(): MsgUpdateModuleParams { - return { authority: "", params: undefined } -} - -export const MsgUpdateModuleParams = { - encode( - message: MsgUpdateModuleParams, - writer: _m0.Writer = _m0.Writer.create() - ): _m0.Writer { - if (message.authority !== "") { - writer.uint32(10).string(message.authority) - } - if (message.params !== undefined) { - ModuleParams.encode(message.params, writer.uint32(18).fork()).ldelim() - } - return writer - }, - - decode( - input: _m0.Reader | Uint8Array, - length?: number - ): MsgUpdateModuleParams { - const reader = - input instanceof _m0.Reader ? input : _m0.Reader.create(input) - let end = length === undefined ? reader.len : reader.pos + length - const message = createBaseMsgUpdateModuleParams() - while (reader.pos < end) { - const tag = reader.uint32() - switch (tag >>> 3) { - case 1: - if (tag !== 10) { - break - } - - message.authority = reader.string() - continue - case 2: - if (tag !== 18) { - break - } - - message.params = ModuleParams.decode(reader, reader.uint32()) - continue - } - if ((tag & 7) === 4 || tag === 0) { - break - } - reader.skipType(tag & 7) - } - return message - }, - - fromJSON(object: any): MsgUpdateModuleParams { - return { - authority: isSet(object.authority) ? String(object.authority) : "", - params: isSet(object.params) - ? ModuleParams.fromJSON(object.params) - : undefined, - } - }, - - toJSON(message: MsgUpdateModuleParams): unknown { - const obj: any = {} - message.authority !== undefined && (obj.authority = message.authority) - message.params !== undefined && - (obj.params = message.params - ? ModuleParams.toJSON(message.params) - : undefined) - return obj - }, - - create, I>>( - base?: I - ): MsgUpdateModuleParams { - return MsgUpdateModuleParams.fromPartial(base ?? {}) - }, - - fromPartial, I>>( - object: I - ): MsgUpdateModuleParams { - const message = createBaseMsgUpdateModuleParams() - message.authority = object.authority ?? "" - message.params = - object.params !== undefined && object.params !== null - ? ModuleParams.fromPartial(object.params) - : undefined - return message - }, -} - -function createBaseMsgUpdateModuleParamsResponse(): MsgUpdateModuleParamsResponse { - return {} -} - -export const MsgUpdateModuleParamsResponse = { - encode( - _: MsgUpdateModuleParamsResponse, - writer: _m0.Writer = _m0.Writer.create() - ): _m0.Writer { - return writer - }, - - decode( - input: _m0.Reader | Uint8Array, - length?: number - ): MsgUpdateModuleParamsResponse { - const reader = - input instanceof _m0.Reader ? input : _m0.Reader.create(input) - let end = length === undefined ? reader.len : reader.pos + length - const message = createBaseMsgUpdateModuleParamsResponse() - while (reader.pos < end) { - const tag = reader.uint32() - switch (tag >>> 3) { - } - if ((tag & 7) === 4 || tag === 0) { - break - } - reader.skipType(tag & 7) - } - return message - }, - - fromJSON(_: any): MsgUpdateModuleParamsResponse { - return {} - }, - - toJSON(_: MsgUpdateModuleParamsResponse): unknown { - const obj: any = {} - return obj - }, - - create, I>>( - base?: I - ): MsgUpdateModuleParamsResponse { - return MsgUpdateModuleParamsResponse.fromPartial(base ?? {}) - }, - - fromPartial, I>>( - _: I - ): MsgUpdateModuleParamsResponse { - const message = createBaseMsgUpdateModuleParamsResponse() - return message - }, -} - -function createBaseMsgMint(): MsgMint { - return { sender: "", coin: undefined, mintTo: "" } -} - -export const MsgMint = { - encode( - message: MsgMint, - writer: _m0.Writer = _m0.Writer.create() - ): _m0.Writer { - if (message.sender !== "") { - writer.uint32(10).string(message.sender) - } - if (message.coin !== undefined) { - Coin.encode(message.coin, writer.uint32(18).fork()).ldelim() - } - if (message.mintTo !== "") { - writer.uint32(26).string(message.mintTo) - } - return writer - }, - - decode(input: _m0.Reader | Uint8Array, length?: number): MsgMint { - const reader = - input instanceof _m0.Reader ? input : _m0.Reader.create(input) - let end = length === undefined ? reader.len : reader.pos + length - const message = createBaseMsgMint() - while (reader.pos < end) { - const tag = reader.uint32() - switch (tag >>> 3) { - case 1: - if (tag !== 10) { - break - } - - message.sender = reader.string() - continue - case 2: - if (tag !== 18) { - break - } - - message.coin = Coin.decode(reader, reader.uint32()) - continue - case 3: - if (tag !== 26) { - break - } - - message.mintTo = reader.string() - continue - } - if ((tag & 7) === 4 || tag === 0) { - break - } - reader.skipType(tag & 7) - } - return message - }, - - fromJSON(object: any): MsgMint { - return { - sender: isSet(object.sender) ? String(object.sender) : "", - coin: isSet(object.coin) ? Coin.fromJSON(object.coin) : undefined, - mintTo: isSet(object.mintTo) ? String(object.mintTo) : "", - } - }, - - toJSON(message: MsgMint): unknown { - const obj: any = {} - message.sender !== undefined && (obj.sender = message.sender) - message.coin !== undefined && - (obj.coin = message.coin ? Coin.toJSON(message.coin) : undefined) - message.mintTo !== undefined && (obj.mintTo = message.mintTo) - return obj - }, - - create, I>>(base?: I): MsgMint { - return MsgMint.fromPartial(base ?? {}) - }, - - fromPartial, I>>(object: I): MsgMint { - const message = createBaseMsgMint() - message.sender = object.sender ?? "" - message.coin = - object.coin !== undefined && object.coin !== null - ? Coin.fromPartial(object.coin) - : undefined - message.mintTo = object.mintTo ?? "" - return message - }, -} - -function createBaseMsgMintResponse(): MsgMintResponse { - return { mintTo: "" } -} - -export const MsgMintResponse = { - encode( - message: MsgMintResponse, - writer: _m0.Writer = _m0.Writer.create() - ): _m0.Writer { - if (message.mintTo !== "") { - writer.uint32(10).string(message.mintTo) - } - return writer - }, - - decode(input: _m0.Reader | Uint8Array, length?: number): MsgMintResponse { - const reader = - input instanceof _m0.Reader ? input : _m0.Reader.create(input) - let end = length === undefined ? reader.len : reader.pos + length - const message = createBaseMsgMintResponse() - while (reader.pos < end) { - const tag = reader.uint32() - switch (tag >>> 3) { - case 1: - if (tag !== 10) { - break - } - - message.mintTo = reader.string() - continue - } - if ((tag & 7) === 4 || tag === 0) { - break - } - reader.skipType(tag & 7) - } - return message - }, - - fromJSON(object: any): MsgMintResponse { - return { mintTo: isSet(object.mintTo) ? String(object.mintTo) : "" } - }, - - toJSON(message: MsgMintResponse): unknown { - const obj: any = {} - message.mintTo !== undefined && (obj.mintTo = message.mintTo) - return obj - }, - - create, I>>( - base?: I - ): MsgMintResponse { - return MsgMintResponse.fromPartial(base ?? {}) - }, - - fromPartial, I>>( - object: I - ): MsgMintResponse { - const message = createBaseMsgMintResponse() - message.mintTo = object.mintTo ?? "" - return message - }, -} - -function createBaseMsgBurn(): MsgBurn { - return { sender: "", coin: undefined, burnFrom: "" } -} - -export const MsgBurn = { - encode( - message: MsgBurn, - writer: _m0.Writer = _m0.Writer.create() - ): _m0.Writer { - if (message.sender !== "") { - writer.uint32(10).string(message.sender) - } - if (message.coin !== undefined) { - Coin.encode(message.coin, writer.uint32(18).fork()).ldelim() - } - if (message.burnFrom !== "") { - writer.uint32(26).string(message.burnFrom) - } - return writer - }, - - decode(input: _m0.Reader | Uint8Array, length?: number): MsgBurn { - const reader = - input instanceof _m0.Reader ? input : _m0.Reader.create(input) - let end = length === undefined ? reader.len : reader.pos + length - const message = createBaseMsgBurn() - while (reader.pos < end) { - const tag = reader.uint32() - switch (tag >>> 3) { - case 1: - if (tag !== 10) { - break - } - - message.sender = reader.string() - continue - case 2: - if (tag !== 18) { - break - } - - message.coin = Coin.decode(reader, reader.uint32()) - continue - case 3: - if (tag !== 26) { - break - } - - message.burnFrom = reader.string() - continue - } - if ((tag & 7) === 4 || tag === 0) { - break - } - reader.skipType(tag & 7) - } - return message - }, - - fromJSON(object: any): MsgBurn { - return { - sender: isSet(object.sender) ? String(object.sender) : "", - coin: isSet(object.coin) ? Coin.fromJSON(object.coin) : undefined, - burnFrom: isSet(object.burnFrom) ? String(object.burnFrom) : "", - } - }, - - toJSON(message: MsgBurn): unknown { - const obj: any = {} - message.sender !== undefined && (obj.sender = message.sender) - message.coin !== undefined && - (obj.coin = message.coin ? Coin.toJSON(message.coin) : undefined) - message.burnFrom !== undefined && (obj.burnFrom = message.burnFrom) - return obj - }, - - create, I>>(base?: I): MsgBurn { - return MsgBurn.fromPartial(base ?? {}) - }, - - fromPartial, I>>(object: I): MsgBurn { - const message = createBaseMsgBurn() - message.sender = object.sender ?? "" - message.coin = - object.coin !== undefined && object.coin !== null - ? Coin.fromPartial(object.coin) - : undefined - message.burnFrom = object.burnFrom ?? "" - return message - }, -} - -function createBaseMsgBurnResponse(): MsgBurnResponse { - return {} -} - -export const MsgBurnResponse = { - encode( - _: MsgBurnResponse, - writer: _m0.Writer = _m0.Writer.create() - ): _m0.Writer { - return writer - }, - - decode(input: _m0.Reader | Uint8Array, length?: number): MsgBurnResponse { - const reader = - input instanceof _m0.Reader ? input : _m0.Reader.create(input) - let end = length === undefined ? reader.len : reader.pos + length - const message = createBaseMsgBurnResponse() - while (reader.pos < end) { - const tag = reader.uint32() - switch (tag >>> 3) { - } - if ((tag & 7) === 4 || tag === 0) { - break - } - reader.skipType(tag & 7) - } - return message - }, - - fromJSON(_: any): MsgBurnResponse { - return {} - }, - - toJSON(_: MsgBurnResponse): unknown { - const obj: any = {} - return obj - }, - - create, I>>( - base?: I - ): MsgBurnResponse { - return MsgBurnResponse.fromPartial(base ?? {}) - }, - - fromPartial, I>>( - _: I - ): MsgBurnResponse { - const message = createBaseMsgBurnResponse() - return message - }, -} - -function createBaseMsgSetDenomMetadata(): MsgSetDenomMetadata { - return { sender: "", metadata: undefined } -} - -export const MsgSetDenomMetadata = { - encode( - message: MsgSetDenomMetadata, - writer: _m0.Writer = _m0.Writer.create() - ): _m0.Writer { - if (message.sender !== "") { - writer.uint32(10).string(message.sender) - } - if (message.metadata !== undefined) { - Metadata.encode(message.metadata, writer.uint32(18).fork()).ldelim() - } - return writer - }, - - decode(input: _m0.Reader | Uint8Array, length?: number): MsgSetDenomMetadata { - const reader = - input instanceof _m0.Reader ? input : _m0.Reader.create(input) - let end = length === undefined ? reader.len : reader.pos + length - const message = createBaseMsgSetDenomMetadata() - while (reader.pos < end) { - const tag = reader.uint32() - switch (tag >>> 3) { - case 1: - if (tag !== 10) { - break - } - - message.sender = reader.string() - continue - case 2: - if (tag !== 18) { - break - } - - message.metadata = Metadata.decode(reader, reader.uint32()) - continue - } - if ((tag & 7) === 4 || tag === 0) { - break - } - reader.skipType(tag & 7) - } - return message - }, - - fromJSON(object: any): MsgSetDenomMetadata { - return { - sender: isSet(object.sender) ? String(object.sender) : "", - metadata: isSet(object.metadata) - ? Metadata.fromJSON(object.metadata) - : undefined, - } - }, - - toJSON(message: MsgSetDenomMetadata): unknown { - const obj: any = {} - message.sender !== undefined && (obj.sender = message.sender) - message.metadata !== undefined && - (obj.metadata = message.metadata - ? Metadata.toJSON(message.metadata) - : undefined) - return obj - }, - - create, I>>( - base?: I - ): MsgSetDenomMetadata { - return MsgSetDenomMetadata.fromPartial(base ?? {}) - }, - - fromPartial, I>>( - object: I - ): MsgSetDenomMetadata { - const message = createBaseMsgSetDenomMetadata() - message.sender = object.sender ?? "" - message.metadata = - object.metadata !== undefined && object.metadata !== null - ? Metadata.fromPartial(object.metadata) - : undefined - return message - }, -} - -function createBaseMsgSetDenomMetadataResponse(): MsgSetDenomMetadataResponse { - return {} -} - -export const MsgSetDenomMetadataResponse = { - encode( - _: MsgSetDenomMetadataResponse, - writer: _m0.Writer = _m0.Writer.create() - ): _m0.Writer { - return writer - }, - - decode( - input: _m0.Reader | Uint8Array, - length?: number - ): MsgSetDenomMetadataResponse { - const reader = - input instanceof _m0.Reader ? input : _m0.Reader.create(input) - let end = length === undefined ? reader.len : reader.pos + length - const message = createBaseMsgSetDenomMetadataResponse() - while (reader.pos < end) { - const tag = reader.uint32() - switch (tag >>> 3) { - } - if ((tag & 7) === 4 || tag === 0) { - break - } - reader.skipType(tag & 7) - } - return message - }, - - fromJSON(_: any): MsgSetDenomMetadataResponse { - return {} - }, - - toJSON(_: MsgSetDenomMetadataResponse): unknown { - const obj: any = {} - return obj - }, - - create, I>>( - base?: I - ): MsgSetDenomMetadataResponse { - return MsgSetDenomMetadataResponse.fromPartial(base ?? {}) - }, - - fromPartial, I>>( - _: I - ): MsgSetDenomMetadataResponse { - const message = createBaseMsgSetDenomMetadataResponse() - return message - }, -} - -/** Msg defines the gRPC Msg service for transactions. */ -export interface Msg { - /** CreateDenom: registers a token factory denom. */ - CreateDenom(request: MsgCreateDenom): Promise - ChangeAdmin(request: MsgChangeAdmin): Promise - /** - * UpdateModuleParams: A governance operation for updating the x/tokenfactory - * module parameters. - */ - UpdateModuleParams( - request: MsgUpdateModuleParams - ): Promise - Mint(request: MsgMint): Promise - Burn(request: MsgBurn): Promise - SetDenomMetadata( - request: MsgSetDenomMetadata - ): Promise -} - -export const MsgServiceName = "nibiru.tokenfactory.v1.Msg" -export class MsgClientImpl implements Msg { - private readonly rpc: Rpc - private readonly service: string - constructor(rpc: Rpc, opts?: { service?: string }) { - this.service = opts?.service || MsgServiceName - this.rpc = rpc - this.CreateDenom = this.CreateDenom.bind(this) - this.ChangeAdmin = this.ChangeAdmin.bind(this) - this.UpdateModuleParams = this.UpdateModuleParams.bind(this) - this.Mint = this.Mint.bind(this) - this.Burn = this.Burn.bind(this) - this.SetDenomMetadata = this.SetDenomMetadata.bind(this) - } - CreateDenom(request: MsgCreateDenom): Promise { - const data = MsgCreateDenom.encode(request).finish() - const promise = this.rpc.request(this.service, "CreateDenom", data) - return promise.then((data) => - MsgCreateDenomResponse.decode(_m0.Reader.create(data)) - ) - } - - ChangeAdmin(request: MsgChangeAdmin): Promise { - const data = MsgChangeAdmin.encode(request).finish() - const promise = this.rpc.request(this.service, "ChangeAdmin", data) - return promise.then((data) => - MsgChangeAdminResponse.decode(_m0.Reader.create(data)) - ) - } - - UpdateModuleParams( - request: MsgUpdateModuleParams - ): Promise { - const data = MsgUpdateModuleParams.encode(request).finish() - const promise = this.rpc.request(this.service, "UpdateModuleParams", data) - return promise.then((data) => - MsgUpdateModuleParamsResponse.decode(_m0.Reader.create(data)) - ) - } - - Mint(request: MsgMint): Promise { - const data = MsgMint.encode(request).finish() - const promise = this.rpc.request(this.service, "Mint", data) - return promise.then((data) => - MsgMintResponse.decode(_m0.Reader.create(data)) - ) - } - - Burn(request: MsgBurn): Promise { - const data = MsgBurn.encode(request).finish() - const promise = this.rpc.request(this.service, "Burn", data) - return promise.then((data) => - MsgBurnResponse.decode(_m0.Reader.create(data)) - ) - } - - SetDenomMetadata( - request: MsgSetDenomMetadata - ): Promise { - const data = MsgSetDenomMetadata.encode(request).finish() - const promise = this.rpc.request(this.service, "SetDenomMetadata", data) - return promise.then((data) => - MsgSetDenomMetadataResponse.decode(_m0.Reader.create(data)) - ) - } -} - -interface Rpc { - request( - service: string, - method: string, - data: Uint8Array - ): Promise -} - -type Builtin = - | Date - | Function - | Uint8Array - | string - | number - | boolean - | undefined - -export type DeepPartial = T extends Builtin - ? T - : T extends Long - ? string | number | Long - : T extends Array - ? Array> - : T extends ReadonlyArray - ? ReadonlyArray> - : T extends {} - ? { [K in keyof T]?: DeepPartial } - : Partial - -type KeysOfUnion = T extends T ? keyof T : never -export type Exact = P extends Builtin - ? P - : P & { [K in keyof P]: Exact } & { - [K in Exclude>]: never - } - -if (_m0.util.Long !== Long) { - _m0.util.Long = Long as any - _m0.configure() -} - -function isSet(value: any): boolean { - return value !== null && value !== undefined -}