diff --git a/.github/workflows/release.yaml b/.github/workflows/release.yaml index deed7cf3..0b611473 100644 --- a/.github/workflows/release.yaml +++ b/.github/workflows/release.yaml @@ -10,6 +10,8 @@ jobs: release: name: Release runs-on: ubuntu-latest + env: + BUF_TOKEN: ${{ secrets.BUF_TOKEN }} permissions: contents: write issues: write diff --git a/.github/workflows/test-ts-sdk.yaml b/.github/workflows/test-ts-sdk.yaml index 6d58f3b5..1515355d 100644 --- a/.github/workflows/test-ts-sdk.yaml +++ b/.github/workflows/test-ts-sdk.yaml @@ -12,6 +12,7 @@ jobs: env: VALIDATOR_MNEMONIC: ${{ secrets.VALIDATOR_MNEMONIC }} VALIDATOR_ADDRESS: ${{ secrets.VALIDATOR_ADDRESS }} + BUF_TOKEN: ${{ secrets.BUF_TOKEN }} LCD_ENDPOINT: "http://127.0.0.1:1317" GRPC_ENDPOINT: "127.0.0.1:9090" TENDERMINT_RPC_ENDPOINT: "http://127.0.0.1:26657" diff --git a/QUERIES.md b/QUERIES.md index 2ec5eea6..e81f3cd1 100644 --- a/QUERIES.md +++ b/QUERIES.md @@ -135,99 +135,6 @@ liquidations( limit: Int): [Liquidations] ``` -## markPriceCandles - -TODO docs - -```graphql -markPriceCandles( - where: MarkPriceCandlesFilter - order: MarkPriceCandlesOrder - orderDesc: Boolean - limit: Int): [MarkPriceCandles] -``` - -#### In English - -- The above code block means that there is a query function called `markPriceCandles` with four arguments, `where`, `order`, `orderDesc`, and `limit`, that returns `[MarkPriceCandles]`. -- The `[MarkPriceCandles]` type means that "list of `MarkPriceCandles` objects". - -#### `MarkPriceCandles` - -```graphql -type MarkPriceCandles { - pair: String - open: Int - close: Int - low: Int - high: Int - period: Float - periodStartTs: DateTime -} -``` - -ANKI `Boolean` in GraphQL means `true` or `false`. - -The `where` parameter has options for filtering based on conditions for each field. The filter condition must match the type of the corresponding field. Examples include: - -```graphql -where: { pairEq: "ubtc:unusd" } -where: { lowGt: 100 } -where: { periodStartTsLt: "2023-02-22" } -``` - -Every field, e.g. `pair`, `open`, `close`, `period`, has filter options. In the case of `MarkPriceCandles`, every field has methods for: - -- `=` : `Eq` : equals -- `>` : `Gt` : greater than -- `<` : `Lt` : less than -- `>=` : `Gte` : greater than or equal -- `<=` : `Lte` : less than or equal - -Except, `pair`, which only has the `pairEq` method. - -### `order: MarkPriceCandlesOrder` - -```graphql -markPriceCandles( - where: MarkPriceCandlesFilter - order: MarkPriceCandlesOrder - orderDesc: Boolean - limit: Int): [MarkPriceCandles] -``` - -```graphql -type MarkPriceCandlesOrder { - pair - open - close - low - high - period - period_start_ts -} -``` - -This means we can use one of these values with the `order` argument in the query like follows: - -```graphql -order: pair -order: close -order: period_start_ts -``` - -## markPrices - -TODO docs - -```graphql -markPrices( - where: MarkPricesFilter - order: MarkPricesOrder - orderDesc: Boolean - limit: Int): [MarkPrices] -``` - ## oraclePrices TODO docs diff --git a/nibiru b/nibiru index 422c6765..3c73f036 160000 --- a/nibiru +++ b/nibiru @@ -1 +1 @@ -Subproject commit 422c67652d7c26e410ba99aa448c4dfd7dd7f71c +Subproject commit 3c73f036e78bf56d1e32c4120c1aaa3c201cc933 diff --git a/src/gql/heart-monitor/heart-monitor.test.ts b/src/gql/heart-monitor/heart-monitor.test.ts index 4910d11f..bb835bfd 100644 --- a/src/gql/heart-monitor/heart-monitor.test.ts +++ b/src/gql/heart-monitor/heart-monitor.test.ts @@ -4,11 +4,9 @@ import { GovernanceFields, IbcFields, OracleFields, - GQLPerpFields, QueryGovernanceArgs, QueryIbcArgs, QueryOracleArgs, - QueryPerpArgs, QueryStatsArgs, GQLStatsFields, communityPoolQueryString, @@ -24,20 +22,11 @@ import { defaultGovVote, defaultIbcChannelsResponse, defaultIbcTransfer, - defaultMarkPriceCandles, defaultOracleEntry, defaultOraclePrice, - defaultPerpLeaderboard, - defaultPerpMarket, defaultPerpOpenInterest, defaultPerpPnl, - defaultPerpPosition, - defaultPerpPositionChanges, - defaultPool, defaultRedelegations, - defaultSpotLpPosition, - defaultSpotPool, - defaultSpotPoolSwap, defaultStatsFees, defaultToken, defaultTotals, @@ -49,30 +38,11 @@ import { defaultValidator, defaultVolume, GQLDistributionCommission, - GQLMarkPriceCandle, GQLOraclePrice, - GQLPerpMarket, - GQLPerpPosition, GQLQueryGqlCommunityPoolArgs, GQLQueryGqlDistributionCommissionsArgs, - GQLQueryGqlMarkPriceCandlesArgs, - GQLQueryGqlSpotLpPositionsArgs, - GQLQueryGqlSpotPoolCreatedArgs, - GQLQueryGqlSpotPoolExitedArgs, - GQLQueryGqlSpotPoolJoinedArgs, - GQLQueryGqlSpotPoolSwapArgs, - GQLQueryGqlSpotPoolsArgs, GQLQueryGqlUsersArgs, - GQLSpotLpPosition, - GQLSpotPool, - GQLSpotPoolCreated, - GQLSpotPoolExited, - GQLSpotPoolJoined, - GQLSpotPoolSwap, - GQLSubscriptionGqlMarkPriceCandlesArgs, GQLSubscriptionGqlOraclePricesArgs, - GQLSubscriptionGqlPerpMarketArgs, - GQLSubscriptionGqlPerpPositionsArgs, GQLToken, GQLUser, InflationFields, @@ -92,6 +62,7 @@ import { GQLValidatorOrder, GQLQueryGqlUserArgs, } from ".." +import { Client } from "graphql-ws" const nibiruUrl = "testnet-1" @@ -142,6 +113,12 @@ const testCommunityPool = async ( } } +test("closeWebSocket - no dispose", async () => { + const hm = new HeartMonitor(`https://hm-graphql.${nibiruUrl}.nibiru.fi/query`) + await hm.closeWebSocket() + expect(hm.subscriptionClient).toEqual(undefined) +}) + test("communityPool", async () => { await testCommunityPool({}, defaultToken) }) @@ -228,38 +205,60 @@ test.skip("governance", async () => { const testIbc = async (args: QueryIbcArgs, fields: IbcFields) => { const resp = await heartMonitor.ibc(args, fields) - expect(resp).toHaveProperty("ibc") - - if (resp.ibc) { - const { ibc } = resp - - checkFields( - [ibc], - [...(args.ibcChannels ? ["ibcChannels"] : []), "ibcTransfers"] - ) + if (fields.ibcChannels || fields.ibcTransfers) { + expect(resp).toHaveProperty("ibc") + + if (resp.ibc) { + const { ibc } = resp + + checkFields( + [ibc], + [ + ...(args.ibcChannels ? ["ibcChannels"] : []), + ...(args.ibcTransfers ? ["ibcTransfers"] : []), + ] + ) + } + } else { + expect((resp as unknown as { data: null }).data).toBe(null) } } test("ibc", async () => { + await testIbc( + {}, + { + ibcChannels: defaultIbcChannelsResponse, + ibcTransfers: defaultIbcTransfer, + } + ) await testIbc( { - ibcChannels: undefined, ibcTransfers: { limit: 1, }, }, { - ibcChannels: defaultIbcChannelsResponse, ibcTransfers: defaultIbcTransfer, } ) await testIbc( - {}, + { + ibcChannels: undefined, + }, { ibcChannels: defaultIbcChannelsResponse, - ibcTransfers: defaultIbcTransfer, } ) + await testIbc( + { + ibcChannels: undefined, + ibcTransfers: { + limit: 1, + }, + }, + {} + ) }) const testInflation = async ( @@ -288,6 +287,15 @@ test("inflation", async () => { rewards: defaultInflationReward, } ) + + await testInflation( + { inflations: { limit: 1 }, distributions: { limit: 1 } }, + { + inflations: defaultInflationInfo, + distributions: defaultInflationDistribution, + rewards: defaultInflationReward, + } + ) }) const testOracle = async (args: QueryOracleArgs, fields: OracleFields) => { @@ -301,76 +309,6 @@ const testOracle = async (args: QueryOracleArgs, fields: OracleFields) => { } } -const testMarkPriceCandles = async ( - args: GQLQueryGqlMarkPriceCandlesArgs, - fields: GQLMarkPriceCandle -) => { - const resp = await heartMonitor.markPriceCandles(args, fields) - expect(resp).toHaveProperty("markPriceCandles") - - if ((resp.markPriceCandles?.length ?? 0) > 0) { - const [markPriceCandle] = resp.markPriceCandles ?? [] - - checkFields( - [markPriceCandle], - ["close", "high", "low", "open", "pair", "period", "periodStartTs"] - ) - } -} - -test.skip("markPriceCandles", async () => { - await testMarkPriceCandles({}, defaultMarkPriceCandles) -}) - -test.skip("markPriceCandlesSubscription undefined client", async () => { - const hm = new HeartMonitor(`https://hm-graphql.${nibiruUrl}.nibiru.fi/query`) - const resp = await hm.markPriceCandlesSubscription( - { - where: { - pairEq: "ubtc:unusd", - periodEq: 100000000, - }, - limit: 1, - }, - defaultMarkPriceCandles - ) - - expect(resp).toBeUndefined() -}) - -const testMarkPriceCandlesSubscription = async ( - args: GQLSubscriptionGqlMarkPriceCandlesArgs, - fields: GQLMarkPriceCandle -) => { - const resp = await heartMonitor.markPriceCandlesSubscription(args, fields) - - const event = await resp?.next() - - expect(event?.value.data).toHaveProperty("markPriceCandles") - - if ((event?.value.data.markPriceCandles.length ?? 0) > 0) { - const [markPriceCandle] = event?.value.data.markPriceCandles ?? [] - - checkFields( - [markPriceCandle], - ["close", "high", "low", "open", "pair", "period", "periodStartTs"] - ) - } -} - -test.skip("markPriceCandlesSubscription", async () => { - await testMarkPriceCandlesSubscription( - { - limit: 1, - where: { - pairEq: "ubtc:unusd", - periodEq: 100000000, - }, - }, - defaultMarkPriceCandles - ) -}) - test("oracle", async () => { await testOracle( { @@ -433,208 +371,6 @@ test.skip("oraclePricesSubscription", async () => { ) }) -const testPerp = async (args: QueryPerpArgs, fields: GQLPerpFields) => { - const resp = await heartMonitor.perp(args, fields) - expect(resp).toHaveProperty("perp") - - if (resp.GQLPerp) { - const { GQLPerp } = resp - - checkFields( - [GQLPerp], - [ - "leaderboard", - "market", - "markets", - "position", - "positionChanges", - "positions", - ] - ) - } -} - -test.skip("perp", async () => { - await testPerp( - { - leaderboard: { - limit: 1, - }, - market: { - where: { - pair: "ubtc:unusd", - }, - }, - markets: { - limit: 1, - }, - position: { - where: { - pair: "ubtc:unusd", - trader_address: "nibi1judn9xtel563nmq0ghpvmkqvyd5wnkm30mvkk3", - }, - }, - positions: { - limit: 1, - }, - positionChanges: { - limit: 1, - where: { - traderAddressEq: "nibi1judn9xtel563nmq0ghpvmkqvyd5wnkm30mvkk3", - }, - }, - }, - { - leaderboard: defaultPerpLeaderboard, - market: defaultPerpMarket, - markets: defaultPerpMarket, - position: defaultPerpPosition, - positions: defaultPerpPosition, - positionChanges: defaultPerpPositionChanges, - } - ) - - // Note: This is because market and position do not exist - const resp = await heartMonitor.perp( - {}, - { - leaderboard: defaultPerpLeaderboard, - markets: defaultPerpMarket, - positions: defaultPerpPosition, - } - ) - expect(resp).toHaveProperty("perp") - - if (resp.GQLPerp) { - const { GQLPerp } = resp - - checkFields([GQLPerp], ["leaderboard", "markets", "positions"]) - } -}) - -test("perpMarketSubscription undefined client", async () => { - const hm = new HeartMonitor(`https://hm-graphql.${nibiruUrl}.nibiru.fi/query`) - const resp = await hm.perpMarketSubscription( - { - where: { pair: "ubtc:unusd" }, - }, - defaultPerpMarket - ) - - expect(resp).toBeUndefined() -}) - -const testPerpMarketSubscription = async ( - args: GQLSubscriptionGqlPerpMarketArgs, - fields: GQLPerpMarket -) => { - const resp = await heartMonitor.perpMarketSubscription(args, fields) - - const event = await resp?.next() - - expect(event?.value.data).toHaveProperty("perpMarket") - if (event?.value.data.perpMarket) { - const { perpMarket } = event.value.data - - checkFields( - [perpMarket], - [ - "pair", - "enabled", - "maintenance_margin_ratio", - "max_leverage", - "latest_cumulative_premium_fraction", - "exchange_fee_ratio", - "ecosystem_fund_fee_ratio", - "max_funding_rate", - "liquidation_fee_ratio", - "partial_liquidation_ratio", - "funding_rate_epoch_id", - "twap_lookback_window", - "prepaid_bad_debt", - "base_reserve", - "quote_reserve", - "sqrt_depth", - "price_multiplier", - "total_long", - "total_short", - "mark_price", - "mark_price_twap", - "index_price_twap", - "is_deleted", - ] - ) - } -} - -test.skip("perpMarketSubscription", async () => { - await testPerpMarketSubscription( - { - where: { pair: "ubtc:unusd" }, - }, - defaultPerpMarket - ) -}) - -test("perpPositionsSubscription undefined client", async () => { - const hm = new HeartMonitor(`https://hm-graphql.${nibiruUrl}.nibiru.fi/query`) - const resp = await hm.perpPositionsSubscription( - { - where: { - pair: "ubtc:unusd", - trader_address: "nibi14garegtvsx3zcku4esd30xd2pze7ck44ysxeg3", - }, - }, - defaultPerpPosition - ) - - expect(resp).toBeUndefined() -}) - -const testPerpPositionsSubscription = async ( - args: GQLSubscriptionGqlPerpPositionsArgs, - fields: GQLPerpPosition -) => { - const resp = await heartMonitor.perpPositionsSubscription(args, fields) - - const event = await resp?.next() - - expect(event?.value.data).toHaveProperty("perpPositions") - if ((event?.value.data.perpPositions.length ?? 0) > 0) { - const [perpPositions] = event?.value.data.perpPositions ?? [] - - checkFields( - [perpPositions], - [ - "pair", - "trader_address", - "size", - "margin", - "open_notional", - "position_notional", - "latest_cumulative_premium_fraction", - "unrealized_pnl", - "unrealized_funding_payment", - "margin_ratio", - "bad_debt", - "last_updated_block", - ] - ) - } -} - -test.skip("perpPositionsSubscription", async () => { - await testPerpPositionsSubscription( - { - where: { - pair: "ubtc:unusd", - trader_address: "nibi14garegtvsx3zcku4esd30xd2pze7ck44ysxeg3", - }, - }, - defaultPerpPosition - ) -}) - const testProxies = async (fields: GQLProxies) => { const resp = await heartMonitor.proxies(fields) expect(resp).toHaveProperty("proxies") @@ -679,134 +415,6 @@ test("queryBatchHandler", async () => { } }) -const testSpotLpPositions = async ( - args: GQLQueryGqlSpotLpPositionsArgs, - fields: GQLSpotLpPosition -) => { - const resp = await heartMonitor.spotLpPositions(args, fields) - expect(resp).toHaveProperty("spotLpPositions") - - if ((resp.spotLpPositions?.length ?? 0) > 0) { - const [spotLpPositions] = resp.spotLpPositions ?? [] - - checkFields( - [spotLpPositions], - ["pool", "user", "pool_shares", "created_block"] - ) - } -} - -test("spotLpPositions", async () => { - await testSpotLpPositions({}, defaultSpotLpPosition) -}) - -const testSpotPoolCreated = async ( - args: GQLQueryGqlSpotPoolCreatedArgs, - fields: GQLSpotPoolCreated -) => { - const resp = await heartMonitor.spotPoolCreated(args, fields) - expect(resp).toHaveProperty("spotPoolCreated") - - if ((resp.spotPoolCreated?.length ?? 0) > 0) { - const [spotPoolCreated] = resp.spotPoolCreated ?? [] - - checkFields([spotPoolCreated], ["user", "block", "pool", "pool_shares"]) - } -} - -test("spotPoolCreated", async () => { - await testSpotPoolCreated({}, defaultSpotPool) -}) - -const testSpotPoolExited = async ( - args: GQLQueryGqlSpotPoolExitedArgs, - fields: GQLSpotPoolExited -) => { - const resp = await heartMonitor.spotPoolExited(args, fields) - expect(resp).toHaveProperty("spotPoolExited") - - if ((resp.spotPoolExited?.length ?? 0) > 0) { - const [spotPoolExited] = resp.spotPoolExited ?? [] - - checkFields([spotPoolExited], ["user", "block", "pool", "pool_shares"]) - } -} - -test("spotPoolExited", async () => { - await testSpotPoolExited({}, defaultSpotPool) -}) - -const testSpotPoolJoined = async ( - args: GQLQueryGqlSpotPoolJoinedArgs, - fields: GQLSpotPoolJoined -) => { - const resp = await heartMonitor.spotPoolJoined(args, fields) - expect(resp).toHaveProperty("spotPoolJoined") - - if ((resp.spotPoolJoined?.length ?? 0) > 0) { - const [spotPoolJoined] = resp.spotPoolJoined ?? [] - - checkFields([spotPoolJoined], ["user", "block", "pool", "pool_shares"]) - } -} - -test("spotPoolJoined", async () => { - await testSpotPoolJoined({}, defaultSpotPool) -}) - -const testSpotPools = async ( - args: GQLQueryGqlSpotPoolsArgs, - fields: GQLSpotPool -) => { - const resp = await heartMonitor.spotPools(args, fields) - expect(resp).toHaveProperty("spotPools") - - if ((resp.spotPools?.length ?? 0) > 0) { - const [spotPools] = resp.spotPools ?? [] - - checkFields( - [spotPools], - [ - "pool_id", - "pool_type", - "swap_fee", - "exit_fee", - "amplification", - "tokens", - "weights", - "total_weight", - "total_shares", - "created_block", - ] - ) - } -} - -test("spotPools", async () => { - await testSpotPools({}, defaultPool) -}) - -const testSpotPoolSwap = async ( - args: GQLQueryGqlSpotPoolSwapArgs, - fields: GQLSpotPoolSwap -) => { - const resp = await heartMonitor.spotPoolSwap(args, fields) - expect(resp).toHaveProperty("spotPoolSwap") - - if ((resp.spotPoolSwap?.length ?? 0) > 0) { - const [spotPoolSwap] = resp.spotPoolSwap ?? [] - - checkFields( - [spotPoolSwap], - ["user", "block", "token_in", "token_out", "pool"] - ) - } -} - -test("spotPoolSwap", async () => { - await testSpotPoolSwap({}, defaultSpotPoolSwap) -}) - const testStats = async (args: QueryStatsArgs, fields: GQLStatsFields) => { const resp = await heartMonitor.stats(args, fields) expect(resp).toHaveProperty("stats") @@ -846,7 +454,7 @@ const testStaking = async ( } } -test.skip("staking", async () => { +test("staking", async () => { await testStaking( { delegations: { @@ -883,13 +491,7 @@ test.skip("staking", async () => { } ) await testStaking( - { - delegations: {}, - history: {}, - redelegations: {}, - unbondings: {}, - validators: {}, - }, + {}, { delegations: defaultDelegations, redelegations: defaultRedelegations, diff --git a/src/gql/heart-monitor/heart-monitor.ts b/src/gql/heart-monitor/heart-monitor.ts index 7a7d3030..1ff4f11e 100644 --- a/src/gql/heart-monitor/heart-monitor.ts +++ b/src/gql/heart-monitor/heart-monitor.ts @@ -2,54 +2,20 @@ import { WebSocket } from "ws" import { Client, ExecutionResult, createClient } from "graphql-ws" import { GQLDistributionCommission, - GQLMarkPriceCandle, GQLOraclePrice, - GQLPerpMarket, - GQLPerpPosition, GQLQueryGqlCommunityPoolArgs, GQLQueryGqlDistributionCommissionsArgs, - GQLQueryGqlMarkPriceCandlesArgs, - GQLQueryGqlSpotLpPositionsArgs, - GQLQueryGqlSpotPoolCreatedArgs, - GQLQueryGqlSpotPoolExitedArgs, - GQLQueryGqlSpotPoolJoinedArgs, - GQLQueryGqlSpotPoolSwapArgs, - GQLQueryGqlSpotPoolsArgs, GQLQueryGqlUsersArgs, - GQLSpotLpPosition, - GQLSpotPool, - GQLSpotPoolCreated, - GQLSpotPoolExited, - GQLSpotPoolJoined, - GQLSpotPoolSwap, - GQLSubscriptionGqlMarkPriceCandlesArgs, GQLSubscriptionGqlOraclePricesArgs, - GQLSubscriptionGqlPerpMarketArgs, - GQLSubscriptionGqlPerpPositionsArgs, GQLToken, GQLUser, queryBatchHandler, GqlOutCommunityPool, GqlOutDistributionCommissions, - GqlOutSpotLpPositions, - GqlOutSpotPoolCreated, - GqlOutSpotPoolExited, - GqlOutSpotPoolJoined, - GqlOutSpotPoolSwap, - GqlOutSpotPools, GqlOutUsers, communityPool, distributionCommissions, - spotLpPositions, - spotPoolCreated, - spotPoolExited, - spotPoolJoined, - spotPoolSwap, - spotPools, users, - GqlOutPerp, - GQLPerpFields, - perp, GqlOutStats, QueryStatsArgs, GQLStatsFields, @@ -57,8 +23,6 @@ import { GqlOutGovernance, QueryGovernanceArgs, governance, - GqlOutMarkPriceCandles, - markPriceCandles, QueryOracleArgs, OracleFields, GqlOutOracle, @@ -68,14 +32,8 @@ import { IbcFields, GqlOutIbc, ibc, - QueryPerpArgs, - markPriceCandlesSubscription, - GqlOutPerpMarket, - perpMarketSubscription, - perpPositionsSubscription, oraclePricesSubscription, GqlOutOraclePrices, - GqlOutPerpPositions, GqlOutWasm, GqlWasmFields, QueryWasmArgs, @@ -103,6 +61,9 @@ import { /** IHeartMonitor is an interface for a Heart Monitor GraphQL API. * Each of its methods corresponds to a GQLQueryGql function. */ export interface IHeartMonitor { + gqlEndpt: string + defaultGqlEndpt: string + subscriptionClient: Client | undefined closeWebSocket: () => Promise readonly communityPool: ( @@ -134,18 +95,6 @@ export interface IHeartMonitor { fields: DeepPartial ) => Promise - readonly markPriceCandles: ( - args: GQLQueryGqlMarkPriceCandlesArgs, - fields: DeepPartial - ) => Promise - - readonly markPriceCandlesSubscription: ( - args: GQLSubscriptionGqlMarkPriceCandlesArgs, - fields: DeepPartial - ) => Promise< - AsyncIterableIterator> | undefined - > - readonly oracle: ( args: QueryOracleArgs, fields: DeepPartial @@ -158,64 +107,15 @@ export interface IHeartMonitor { AsyncIterableIterator> | undefined > - readonly perp: ( - args: QueryPerpArgs, - fields: DeepPartial - ) => Promise - - readonly perpMarketSubscription: ( - args: GQLSubscriptionGqlPerpMarketArgs, - fields: DeepPartial - ) => Promise< - AsyncIterableIterator> | undefined - > - - readonly perpPositionsSubscription: ( - args: GQLSubscriptionGqlPerpPositionsArgs, - fields: DeepPartial - ) => Promise< - AsyncIterableIterator> | undefined - > - readonly proxies: (fields: DeepPartial) => Promise readonly GQLQueryGqlBatchHandler: ( queryQueryStrings: string[] ) => Promise - readonly spotLpPositions: ( - args: GQLQueryGqlSpotLpPositionsArgs, - fields: DeepPartial - ) => Promise - - readonly spotPoolCreated: ( - args: GQLQueryGqlSpotPoolCreatedArgs, - fields: DeepPartial - ) => Promise - - readonly spotPoolExited: ( - args: GQLQueryGqlSpotPoolExitedArgs, - fields: DeepPartial - ) => Promise - - readonly spotPoolJoined: ( - args: GQLQueryGqlSpotPoolJoinedArgs, - fields: DeepPartial - ) => Promise - - readonly spotPools: ( - args: GQLQueryGqlSpotPoolsArgs, - fields: DeepPartial - ) => Promise - - readonly spotPoolSwap: ( - args: GQLQueryGqlSpotPoolSwapArgs, - fields: DeepPartial - ) => Promise - readonly staking: ( args: QueryStakingArgs, - fields?: DeepPartial + fields: DeepPartial ) => Promise readonly stats: ( @@ -294,16 +194,6 @@ export class HeartMonitor implements IHeartMonitor { fields: DeepPartial ) => inflation(args, this.gqlEndpt, fields) - markPriceCandles = async ( - args: GQLQueryGqlMarkPriceCandlesArgs, - fields: DeepPartial - ) => markPriceCandles(args, this.gqlEndpt, fields) - - markPriceCandlesSubscription = async ( - args: GQLSubscriptionGqlMarkPriceCandlesArgs, - fields: DeepPartial - ) => markPriceCandlesSubscription(args, fields, this.subscriptionClient) - oracle = async (args: QueryOracleArgs, fields: DeepPartial) => oracle(args, this.gqlEndpt, fields) @@ -312,58 +202,15 @@ export class HeartMonitor implements IHeartMonitor { fields: DeepPartial ) => oraclePricesSubscription(args, fields, this.subscriptionClient) - perp = async (args: QueryPerpArgs, fields: DeepPartial) => - perp(args, this.gqlEndpt, fields) - - perpMarketSubscription = async ( - args: GQLSubscriptionGqlPerpMarketArgs, - fields: DeepPartial - ) => perpMarketSubscription(args, fields, this.subscriptionClient) - - perpPositionsSubscription = async ( - args: GQLSubscriptionGqlPerpPositionsArgs, - fields: DeepPartial - ) => perpPositionsSubscription(args, fields, this.subscriptionClient) - proxies = async (fields: DeepPartial) => proxies(this.gqlEndpt, fields) GQLQueryGqlBatchHandler = async (queryQueryStrings: string[]) => queryBatchHandler(queryQueryStrings, this.gqlEndpt) - spotLpPositions = async ( - args: GQLQueryGqlSpotLpPositionsArgs, - fields: DeepPartial - ) => spotLpPositions(args, this.gqlEndpt, fields) - - spotPoolCreated = async ( - args: GQLQueryGqlSpotPoolCreatedArgs, - fields: DeepPartial - ) => spotPoolCreated(args, this.gqlEndpt, fields) - - spotPoolExited = async ( - args: GQLQueryGqlSpotPoolExitedArgs, - fields: DeepPartial - ) => spotPoolExited(args, this.gqlEndpt, fields) - - spotPoolJoined = async ( - args: GQLQueryGqlSpotPoolJoinedArgs, - fields: DeepPartial - ) => spotPoolJoined(args, this.gqlEndpt, fields) - - spotPools = async ( - args: GQLQueryGqlSpotPoolsArgs, - fields: DeepPartial - ) => spotPools(args, this.gqlEndpt, fields) - - spotPoolSwap = async ( - args: GQLQueryGqlSpotPoolSwapArgs, - fields: DeepPartial - ) => spotPoolSwap(args, this.gqlEndpt, fields) - staking = async ( args: QueryStakingArgs, - fields?: DeepPartial + fields: DeepPartial ) => staking(args, this.gqlEndpt, fields) stats = async (args: QueryStatsArgs, fields: DeepPartial) => diff --git a/src/gql/query/governance.ts b/src/gql/query/governance.ts index 7f352430..2173377e 100644 --- a/src/gql/query/governance.ts +++ b/src/gql/query/governance.ts @@ -34,7 +34,7 @@ export const governanceQueryString = ( ) => { const governanceQuery: string[] = [] - if (fields?.govDeposits) { + if (fields.govDeposits) { governanceQuery.push( gqlQuery( "govDeposits", @@ -45,7 +45,7 @@ export const governanceQueryString = ( ) } - if (fields?.govProposals) { + if (fields.govProposals) { governanceQuery.push( gqlQuery( "govProposals", @@ -56,7 +56,7 @@ export const governanceQueryString = ( ) } - if (fields?.govVotes) { + if (fields.govVotes) { governanceQuery.push( gqlQuery( "govVotes", diff --git a/src/gql/query/ibc.ts b/src/gql/query/ibc.ts index d47d394b..aaebfaa7 100644 --- a/src/gql/query/ibc.ts +++ b/src/gql/query/ibc.ts @@ -26,7 +26,7 @@ export type IbcFields = DeepPartial<{ export const ibcQueryString = (args: QueryIbcArgs, fields: IbcFields) => { const ibcQuery: string[] = [] - if (fields?.ibcTransfers) { + if (fields.ibcTransfers) { ibcQuery.push( gqlQuery( "ibcTransfers", @@ -37,13 +37,13 @@ export const ibcQueryString = (args: QueryIbcArgs, fields: IbcFields) => { ) } - if (fields?.ibcChannels) { + if (fields.ibcChannels) { ibcQuery.push( gqlQuery( "ibcChannels", // No args {}, - convertObjectToPropertiesString(fields?.ibcChannels), + convertObjectToPropertiesString(fields.ibcChannels), true ) ) diff --git a/src/gql/query/index.ts b/src/gql/query/index.ts index 0724566e..d82f41ca 100644 --- a/src/gql/query/index.ts +++ b/src/gql/query/index.ts @@ -8,16 +8,8 @@ export * from "./featureFlags" export * from "./governance" export * from "./ibc" export * from "./inflation" -export * from "./markPriceCandles" export * from "./oracle" -export * from "./perp" export * from "./proxies" -export * from "./spotLpPositions" -export * from "./spotPoolCreated" -export * from "./spotPoolExited" -export * from "./spotPoolJoined" -export * from "./spotPools" -export * from "./spotPoolSwap" export * from "./staking" export * from "./stats" export * from "./user" diff --git a/src/gql/query/inflation.ts b/src/gql/query/inflation.ts index 548c413c..dcb34d4d 100644 --- a/src/gql/query/inflation.ts +++ b/src/gql/query/inflation.ts @@ -32,7 +32,7 @@ export const inflationQueryString = ( ) => { const inflationQuery: string[] = [] - if (fields?.distributions) { + if (fields.distributions) { inflationQuery.push( gqlQuery( "distributions", @@ -43,7 +43,7 @@ export const inflationQueryString = ( ) } - if (fields?.inflations) { + if (fields.inflations) { inflationQuery.push( gqlQuery( "inflations", @@ -54,7 +54,7 @@ export const inflationQueryString = ( ) } - if (fields?.rewards) { + if (fields.rewards) { inflationQuery.push( gqlQuery( "rewards", diff --git a/src/gql/query/markPriceCandles.ts b/src/gql/query/markPriceCandles.ts deleted file mode 100644 index 683f0132..00000000 --- a/src/gql/query/markPriceCandles.ts +++ /dev/null @@ -1,32 +0,0 @@ -import { - convertObjectToPropertiesString, - doGqlQuery, - gqlQuery, - GQLQueryGqlMarkPriceCandlesArgs, - GQLQuery, - GQLMarkPriceCandle, - DeepPartial, -} from ".." - -export interface GqlOutMarkPriceCandles { - markPriceCandles?: GQLQuery["markPriceCandles"] -} - -export const markPriceCandlesQueryString = ( - args: GQLQueryGqlMarkPriceCandlesArgs, - excludeParentObject: boolean, - fields: DeepPartial -) => - gqlQuery( - "markPriceCandles", - args, - convertObjectToPropertiesString(fields), - excludeParentObject - ) - -export const markPriceCandles = async ( - args: GQLQueryGqlMarkPriceCandlesArgs, - endpt: string, - fields: DeepPartial -): Promise => - doGqlQuery(markPriceCandlesQueryString(args, false, fields), endpt) diff --git a/src/gql/query/oracle.ts b/src/gql/query/oracle.ts index eba33542..f45f8c6f 100644 --- a/src/gql/query/oracle.ts +++ b/src/gql/query/oracle.ts @@ -30,7 +30,7 @@ export const oracleQueryString = ( ) => { const oracleQuery: string[] = [] - if (fields?.oraclePrices) { + if (fields.oraclePrices) { oracleQuery.push( gqlQuery( "oraclePrices", @@ -41,7 +41,7 @@ export const oracleQueryString = ( ) } - if (fields?.oracles) { + if (fields.oracles) { oracleQuery.push( gqlQuery( "oracles", diff --git a/src/gql/query/perp.ts b/src/gql/query/perp.ts deleted file mode 100644 index 9332c9fb..00000000 --- a/src/gql/query/perp.ts +++ /dev/null @@ -1,133 +0,0 @@ -import { - convertObjectToPropertiesString, - doGqlQuery, - gqlQuery, - GQLQuery, - GQLPerpLeaderboard, - GQLPerpMarket, - GQLPerpPosition, - GQLPerpPositionChange, - GQLPerpGqlLeaderboardArgs, - GQLPerpGqlMarketArgs, - GQLPerpGqlMarketsArgs, - GQLPerpGqlPositionArgs, - GQLPerpGqlPositionsArgs, - GQLPerpGqlPositionChangesArgs, - DeepPartial, -} from ".." - -export type QueryPerpArgs = { - leaderboard?: GQLPerpGqlLeaderboardArgs - market?: GQLPerpGqlMarketArgs - markets?: GQLPerpGqlMarketsArgs - position?: GQLPerpGqlPositionArgs - positionChanges?: GQLPerpGqlPositionChangesArgs - positions?: GQLPerpGqlPositionsArgs -} - -export interface GqlOutPerp { - GQLPerp?: GQLQuery["perp"] -} - -export type GQLPerpFields = DeepPartial<{ - leaderboard?: DeepPartial - market?: DeepPartial - markets?: DeepPartial - position?: DeepPartial - positionChanges?: DeepPartial - positions?: DeepPartial -}> - -export const GQLPerpQueryString = ( - args: QueryPerpArgs, - fields: GQLPerpFields -) => { - const GQLPerpQuery: string[] = [] - - if (fields?.leaderboard) { - GQLPerpQuery.push( - gqlQuery( - "leaderboard", - args.leaderboard ?? {}, - convertObjectToPropertiesString(fields.leaderboard), - true - ) - ) - } - - // Note: args.market must be defined - if (args.market && fields?.market) { - GQLPerpQuery.push( - gqlQuery( - "market", - args.market, - convertObjectToPropertiesString(fields.market), - true - ) - ) - } - - if (fields?.markets) { - GQLPerpQuery.push( - gqlQuery( - "markets", - args.markets ?? {}, - convertObjectToPropertiesString(fields.markets), - true - ) - ) - } - - // Note: args.position must be defined - if (args.position && fields?.position) { - GQLPerpQuery.push( - gqlQuery( - "position", - args.position, - convertObjectToPropertiesString(fields.position), - true - ) - ) - } - - // Note: args.positionChanges must be defined - if (args.positionChanges && fields?.positionChanges) { - GQLPerpQuery.push( - gqlQuery( - "positionChanges", - args.positionChanges, - convertObjectToPropertiesString(fields.positionChanges), - true - ) - ) - } - - if (fields?.positions) { - GQLPerpQuery.push( - gqlQuery( - "positions", - args.positions ?? {}, - convertObjectToPropertiesString(fields.positions), - true - ) - ) - } - - return ` - perp { - ${GQLPerpQuery.join("\n")} - } - ` -} - -export const perp = async ( - args: QueryPerpArgs, - endpt: string, - fields: GQLPerpFields -): Promise => - doGqlQuery( - `{ - ${GQLPerpQueryString(args, fields)} - }`, - endpt - ) diff --git a/src/gql/query/spotLpPositions.ts b/src/gql/query/spotLpPositions.ts deleted file mode 100644 index cb22cfc6..00000000 --- a/src/gql/query/spotLpPositions.ts +++ /dev/null @@ -1,38 +0,0 @@ -import { - convertObjectToPropertiesString, - doGqlQuery, - gqlQuery, - GQLQuery, - GQLQueryGqlSpotLpPositionsArgs, - GQLSpotLpPosition, - GQLSpotLpPositionOrder, - DeepPartial, -} from ".." - -export interface GqlOutSpotLpPositions { - spotLpPositions?: GQLQuery["spotLpPositions"] -} - -export const spotLpPositionsQueryString = ( - args: GQLQueryGqlSpotLpPositionsArgs, - excludeParentObject: boolean, - fields: DeepPartial -) => { - if (!args.limit) args.limit = 100 - if (!args.order_desc) args.order_desc = true - if (!args.order_by) args.order_by = GQLSpotLpPositionOrder.GQLPoolId - - return gqlQuery( - "spotLpPositions", - args, - convertObjectToPropertiesString(fields), - excludeParentObject - ) -} - -export const spotLpPositions = async ( - args: GQLQueryGqlSpotLpPositionsArgs, - endpt: string, - fields: DeepPartial -): Promise => - doGqlQuery(spotLpPositionsQueryString(args, false, fields), endpt) diff --git a/src/gql/query/spotPoolCreated.ts b/src/gql/query/spotPoolCreated.ts deleted file mode 100644 index 76e4f8d6..00000000 --- a/src/gql/query/spotPoolCreated.ts +++ /dev/null @@ -1,38 +0,0 @@ -import { - convertObjectToPropertiesString, - doGqlQuery, - gqlQuery, - GQLQuery, - GQLQueryGqlSpotPoolCreatedArgs, - GQLSpotPoolCreated, - GQLSpotPoolCreatedOrder, - DeepPartial, -} from ".." - -export interface GqlOutSpotPoolCreated { - spotPoolCreated?: GQLQuery["spotPoolCreated"] -} - -export const spotPoolCreatedQueryString = ( - args: GQLQueryGqlSpotPoolCreatedArgs, - excludeParentObject: boolean, - fields: DeepPartial -) => { - if (!args.limit) args.limit = 100 - if (!args.order_desc) args.order_desc = true - if (!args.order_by) args.order_by = GQLSpotPoolCreatedOrder.GQLPoolId - - return gqlQuery( - "spotPoolCreated", - args, - convertObjectToPropertiesString(fields), - excludeParentObject - ) -} - -export const spotPoolCreated = async ( - args: GQLQueryGqlSpotPoolCreatedArgs, - endpt: string, - fields: DeepPartial -): Promise => - doGqlQuery(spotPoolCreatedQueryString(args, false, fields), endpt) diff --git a/src/gql/query/spotPoolExited.ts b/src/gql/query/spotPoolExited.ts deleted file mode 100644 index 35b683e0..00000000 --- a/src/gql/query/spotPoolExited.ts +++ /dev/null @@ -1,38 +0,0 @@ -import { - convertObjectToPropertiesString, - doGqlQuery, - gqlQuery, - GQLQuery, - GQLQueryGqlSpotPoolExitedArgs, - GQLSpotPoolExited, - GQLSpotPoolExitedOrder, - DeepPartial, -} from ".." - -export interface GqlOutSpotPoolExited { - spotPoolExited?: GQLQuery["spotPoolExited"] -} - -export const spotPoolExitedQueryString = ( - args: GQLQueryGqlSpotPoolExitedArgs, - excludeParentObject: boolean, - fields: DeepPartial -) => { - if (!args.limit) args.limit = 100 - if (!args.order_desc) args.order_desc = true - if (!args.order_by) args.order_by = GQLSpotPoolExitedOrder.GQLPoolId - - return gqlQuery( - "spotPoolExited", - args, - convertObjectToPropertiesString(fields), - excludeParentObject - ) -} - -export const spotPoolExited = async ( - args: GQLQueryGqlSpotPoolExitedArgs, - endpt: string, - fields: DeepPartial -): Promise => - doGqlQuery(spotPoolExitedQueryString(args, false, fields), endpt) diff --git a/src/gql/query/spotPoolJoined.ts b/src/gql/query/spotPoolJoined.ts deleted file mode 100644 index 746e987f..00000000 --- a/src/gql/query/spotPoolJoined.ts +++ /dev/null @@ -1,38 +0,0 @@ -import { - convertObjectToPropertiesString, - doGqlQuery, - gqlQuery, - GQLQuery, - GQLQueryGqlSpotPoolJoinedArgs, - GQLSpotPoolJoined, - GQLSpotPoolJoinedOrder, - DeepPartial, -} from ".." - -export interface GqlOutSpotPoolJoined { - spotPoolJoined?: GQLQuery["spotPoolJoined"] -} - -export const spotPoolJoinedQueryString = ( - args: GQLQueryGqlSpotPoolJoinedArgs, - excludeParentObject: boolean, - fields: DeepPartial -) => { - if (!args.limit) args.limit = 100 - if (!args.order_desc) args.order_desc = true - if (!args.order_by) args.order_by = GQLSpotPoolJoinedOrder.GQLPoolId - - return gqlQuery( - "spotPoolJoined", - args, - convertObjectToPropertiesString(fields), - excludeParentObject - ) -} - -export const spotPoolJoined = async ( - args: GQLQueryGqlSpotPoolJoinedArgs, - endpt: string, - fields: DeepPartial -): Promise => - doGqlQuery(spotPoolJoinedQueryString(args, false, fields), endpt) diff --git a/src/gql/query/spotPoolSwap.ts b/src/gql/query/spotPoolSwap.ts deleted file mode 100644 index 7506e699..00000000 --- a/src/gql/query/spotPoolSwap.ts +++ /dev/null @@ -1,38 +0,0 @@ -import { - convertObjectToPropertiesString, - doGqlQuery, - gqlQuery, - GQLQuery, - GQLQueryGqlSpotPoolSwapArgs, - GQLSpotPoolSwap, - GQLSpotPoolSwapOrder, - DeepPartial, -} from ".." - -export interface GqlOutSpotPoolSwap { - spotPoolSwap?: GQLQuery["spotPoolSwap"] -} - -export const spotPoolSwapQueryString = ( - args: GQLQueryGqlSpotPoolSwapArgs, - excludeParentObject: boolean, - fields: DeepPartial -) => { - if (!args.limit) args.limit = 100 - if (!args.order_desc) args.order_desc = true - if (!args.order_by) args.order_by = GQLSpotPoolSwapOrder.GQLBlock - - return gqlQuery( - "spotPoolSwap", - args, - convertObjectToPropertiesString(fields), - excludeParentObject - ) -} - -export const spotPoolSwap = async ( - args: GQLQueryGqlSpotPoolSwapArgs, - endpt: string, - fields: DeepPartial -): Promise => - doGqlQuery(spotPoolSwapQueryString(args, false, fields), endpt) diff --git a/src/gql/query/spotPools.ts b/src/gql/query/spotPools.ts deleted file mode 100644 index b86aaa93..00000000 --- a/src/gql/query/spotPools.ts +++ /dev/null @@ -1,38 +0,0 @@ -import { - convertObjectToPropertiesString, - doGqlQuery, - gqlQuery, - GQLQueryGqlSpotPoolsArgs, - GQLQuery, - GQLSpotPool, - GQLSpotPoolOrder, - DeepPartial, -} from ".." - -export interface GqlOutSpotPools { - spotPools?: GQLQuery["spotPools"] -} - -export const spotPoolsQueryString = ( - args: GQLQueryGqlSpotPoolsArgs, - excludeParentObject: boolean, - fields: DeepPartial -) => { - if (!args.limit) args.limit = 100 - if (!args.order_desc) args.order_desc = true - if (!args.order_by) args.order_by = GQLSpotPoolOrder.GQLPoolId - - return gqlQuery( - "spotPools", - args, - convertObjectToPropertiesString(fields), - excludeParentObject - ) -} - -export const spotPools = async ( - args: GQLQueryGqlSpotPoolsArgs, - endpt: string, - fields: DeepPartial -): Promise => - doGqlQuery(spotPoolsQueryString(args, false, fields), endpt) diff --git a/src/gql/query/staking.ts b/src/gql/query/staking.ts index 829dacf5..08eb798e 100644 --- a/src/gql/query/staking.ts +++ b/src/gql/query/staking.ts @@ -38,11 +38,11 @@ export type GQLStakingFields = DeepPartial<{ export const GQLStakingQueryString = ( args: QueryStakingArgs, - fields?: GQLStakingFields + fields: GQLStakingFields ) => { const GQLStakingQuery: string[] = [] - if (fields?.delegations) { + if (fields.delegations) { GQLStakingQuery.push( gqlQuery( "delegations", @@ -53,7 +53,7 @@ export const GQLStakingQueryString = ( ) } - if (fields?.history) { + if (fields.history) { GQLStakingQuery.push( gqlQuery( "history", @@ -64,7 +64,7 @@ export const GQLStakingQueryString = ( ) } - if (fields?.redelegations) { + if (fields.redelegations) { GQLStakingQuery.push( gqlQuery( "redelegations", @@ -75,7 +75,7 @@ export const GQLStakingQueryString = ( ) } - if (fields?.unbondings) { + if (fields.unbondings) { GQLStakingQuery.push( gqlQuery( "unbondings", @@ -86,7 +86,7 @@ export const GQLStakingQueryString = ( ) } - if (fields?.validators) { + if (fields.validators) { GQLStakingQuery.push( gqlQuery( "validators", @@ -107,7 +107,7 @@ export const GQLStakingQueryString = ( export const staking = async ( args: QueryStakingArgs, endpt: string, - fields?: GQLStakingFields + fields: GQLStakingFields ): Promise => doGqlQuery( `{ diff --git a/src/gql/query/stats.ts b/src/gql/query/stats.ts index 9fac996d..c388e8a9 100644 --- a/src/gql/query/stats.ts +++ b/src/gql/query/stats.ts @@ -50,7 +50,7 @@ export const GQLStatsQueryString = ( ) => { const GQLStatsQuery: string[] = [] - if (fields?.fees) { + if (fields.fees) { GQLStatsQuery.push( gqlQuery( "fees", @@ -61,7 +61,7 @@ export const GQLStatsQueryString = ( ) } - if (fields?.perpOpenInterest) { + if (fields.perpOpenInterest) { GQLStatsQuery.push( gqlQuery( "perpOpenInterest", @@ -72,7 +72,7 @@ export const GQLStatsQueryString = ( ) } - if (fields?.perpPnl) { + if (fields.perpPnl) { GQLStatsQuery.push( gqlQuery( "perpPnl", @@ -83,7 +83,7 @@ export const GQLStatsQueryString = ( ) } - if (fields?.totals) { + if (fields.totals) { GQLStatsQuery.push( gqlQuery( "totals", @@ -94,7 +94,7 @@ export const GQLStatsQueryString = ( ) } - if (fields?.tvl) { + if (fields.tvl) { GQLStatsQuery.push( gqlQuery( "tvl", @@ -105,7 +105,7 @@ export const GQLStatsQueryString = ( ) } - if (fields?.users) { + if (fields.users) { GQLStatsQuery.push( gqlQuery( "users", @@ -116,7 +116,7 @@ export const GQLStatsQueryString = ( ) } - if (fields?.volume) { + if (fields.volume) { GQLStatsQuery.push( gqlQuery( "volume", diff --git a/src/gql/query/wasm.ts b/src/gql/query/wasm.ts index de4ddbad..65f96c80 100644 --- a/src/gql/query/wasm.ts +++ b/src/gql/query/wasm.ts @@ -23,7 +23,7 @@ export type GqlWasmFields = DeepPartial<{ export const wasmQueryString = (args: QueryWasmArgs, fields: GqlWasmFields) => { const wasmQuery: string[] = [] - if (fields?.userContracts) { + if (fields.userContracts) { wasmQuery.push( gqlQuery( "userContracts", diff --git a/src/gql/subscription/index.ts b/src/gql/subscription/index.ts index d1f790da..4df5da11 100644 --- a/src/gql/subscription/index.ts +++ b/src/gql/subscription/index.ts @@ -2,7 +2,4 @@ * @file Automatically generated by barrelsby. */ -export * from "./markPriceCandlesSubscription" export * from "./oraclePricesSubscription" -export * from "./perpMarketSubscription" -export * from "./perpPositionsSubscription" diff --git a/src/gql/subscription/markPriceCandlesSubscription.ts b/src/gql/subscription/markPriceCandlesSubscription.ts deleted file mode 100644 index 3599f533..00000000 --- a/src/gql/subscription/markPriceCandlesSubscription.ts +++ /dev/null @@ -1,33 +0,0 @@ -import { Client, ExecutionResult } from "graphql-ws" -import { - GQLMarkPriceCandle, - GQLSubscriptionGqlMarkPriceCandlesArgs, - gqlQuery, - convertObjectToPropertiesString, - GqlOutMarkPriceCandles, - DeepPartial, -} from ".." - -export const markPriceCandlesSubscriptionQueryString = ( - args: GQLSubscriptionGqlMarkPriceCandlesArgs, - fields: DeepPartial -) => - `subscription { - ${gqlQuery( - "markPriceCandles", - args, - convertObjectToPropertiesString(fields), - true - )} - }` - -export const markPriceCandlesSubscription = async ( - args: GQLSubscriptionGqlMarkPriceCandlesArgs, - fields: DeepPartial, - client?: Client -): Promise< - AsyncIterableIterator> | undefined -> => - client?.iterate({ - query: markPriceCandlesSubscriptionQueryString(args, fields), - }) diff --git a/src/gql/subscription/perpMarketSubscription.ts b/src/gql/subscription/perpMarketSubscription.ts deleted file mode 100644 index d98c76a7..00000000 --- a/src/gql/subscription/perpMarketSubscription.ts +++ /dev/null @@ -1,37 +0,0 @@ -import { Client, ExecutionResult } from "graphql-ws" -import { - GQLSubscriptionGqlPerpMarketArgs, - GQLPerpMarket, - GQLSubscription, - gqlQuery, - convertObjectToPropertiesString, - DeepPartial, -} from ".." - -export interface GqlOutPerpMarket { - perpMarket?: GQLSubscription["perpMarket"] -} - -export const perpMarketSubscriptionQueryString = ( - args: GQLSubscriptionGqlPerpMarketArgs, - fields: DeepPartial -) => - `subscription { - ${gqlQuery( - "perpMarket", - args, - convertObjectToPropertiesString(fields), - true - )} - }` - -export const perpMarketSubscription = async ( - args: GQLSubscriptionGqlPerpMarketArgs, - fields: DeepPartial, - client?: Client -): Promise< - AsyncIterableIterator> | undefined -> => - client?.iterate({ - query: perpMarketSubscriptionQueryString(args, fields), - }) diff --git a/src/gql/subscription/perpPositionsSubscription.ts b/src/gql/subscription/perpPositionsSubscription.ts deleted file mode 100644 index 3f1dd086..00000000 --- a/src/gql/subscription/perpPositionsSubscription.ts +++ /dev/null @@ -1,32 +0,0 @@ -import { Client, ExecutionResult } from "graphql-ws" -import { - GQLSubscriptionGqlPerpPositionsArgs, - GQLPerpPosition, - GQLSubscription, - gqlQuery, - convertObjectToPropertiesString, - DeepPartial, -} from ".." - -export interface GqlOutPerpPositions { - perpPositions?: GQLSubscription["perpPositions"] -} - -export const perpPositionsSubscriptionQueryString = ( - args: GQLSubscriptionGqlPerpPositionsArgs, - fields: DeepPartial -) => - gqlQuery("perpPositions", args, convertObjectToPropertiesString(fields), true) - -export const perpPositionsSubscription = async ( - args: GQLSubscriptionGqlPerpPositionsArgs, - fields: DeepPartial, - client?: Client -): Promise< - AsyncIterableIterator> | undefined -> => - client?.iterate({ - query: `subscription { - ${perpPositionsSubscriptionQueryString(args, fields)} - }`, - }) diff --git a/src/gql/utils/consts.test.ts b/src/gql/utils/consts.test.ts index 30dadde3..b62dfa85 100644 --- a/src/gql/utils/consts.test.ts +++ b/src/gql/utils/consts.test.ts @@ -8,6 +8,8 @@ import { GqlOutFeatureFlags, defaultFeatureFlags, featureFlagsQueryString, + objToGql, + IterableDictionary, } from ".." describe("queryBatchHandler tests", () => { @@ -46,4 +48,16 @@ describe("queryBatchHandler tests", () => { const result = arg("mock", "mock", false) expect(result).toEqual(`mock: "mock"`) }) + + test("arg", async () => { + const result = arg("mock", { mock: "mock" }, false) + expect(result).toEqual(`mock: { + mock:"mock" + }`) + }) + + test("objToGql - wrong object type", async () => { + const result = objToGql(12 as unknown as IterableDictionary) + expect(result).toEqual(12) + }) }) diff --git a/src/sdk/balancer/index.ts b/src/sdk/balancer/index.ts deleted file mode 100644 index 4a54a546..00000000 --- a/src/sdk/balancer/index.ts +++ /dev/null @@ -1,5 +0,0 @@ -/** - * @file Automatically generated by barrelsby. - */ - -export * from "./balancer" diff --git a/src/sdk/index.ts b/src/sdk/index.ts index 76541633..6a0a2063 100644 --- a/src/sdk/index.ts +++ b/src/sdk/index.ts @@ -2,9 +2,7 @@ * @file Automatically generated by barrelsby. */ -export * from "./balancer/index" export * from "./msg/index" export * from "./query/index" -export * from "./stableswap/index" export * from "./tx/index" export * from "./utils/index" diff --git a/src/sdk/msg/devgas.test.ts b/src/sdk/msg/devgas.test.ts new file mode 100644 index 00000000..e6e77990 --- /dev/null +++ b/src/sdk/msg/devgas.test.ts @@ -0,0 +1,118 @@ +import { QueryClient } from "@cosmjs/stargate" +import * as query from "../../protojs/nibiru/devgas/v1/tx" +import { setupDevgasMsgExtension } from "." + +describe("setupDevgasMsgExtension", () => { + const mockBaseQueryClient = {} as QueryClient + + jest.spyOn(query, "MsgClientImpl").mockReturnValue({ + RegisterFeeShare: jest.fn().mockResolvedValue({ test: "Test" }), + UpdateFeeShare: jest.fn().mockResolvedValue({ + test: "Test", + }), + CancelFeeShare: jest.fn().mockResolvedValue({ + test: "Test", + }), + UpdateParams: jest.fn().mockResolvedValue({ + test: "Test", + }), + } as unknown as query.MsgClientImpl) + + test("should setup extension correctly", () => { + const extension = setupDevgasMsgExtension(mockBaseQueryClient) + + expect(extension).toBeDefined() + expect(extension.registerFeeShare).toBeInstanceOf(Function) + expect(extension.updateFeeShare).toBeInstanceOf(Function) + expect(extension.cancelFeeShare).toBeInstanceOf(Function) + expect(extension.updateParams).toBeInstanceOf(Function) + }) + + describe("registerFeeShare", () => { + test("should call MsgRegisterFeeShare and return the response", async () => { + const msgRegisterFeeShare = jest + .spyOn(query.MsgRegisterFeeShare, "fromPartial") + .mockReturnValue({} as query.MsgRegisterFeeShare) + + const extension = setupDevgasMsgExtension(mockBaseQueryClient) + const result = await extension.registerFeeShare({ + contractAddress: "", + deployerAddress: "", + withdrawerAddress: "", + }) + expect(msgRegisterFeeShare).toHaveBeenCalledWith({ + contractAddress: "", + deployerAddress: "", + withdrawerAddress: "", + }) + expect(result).toEqual({ test: "Test" }) + }) + }) + + describe("updateFeeShare", () => { + test("should call MsgRegisterFeeShare and return the response", async () => { + const msgUpdateFeeShare = jest + .spyOn(query.MsgUpdateFeeShare, "fromPartial") + .mockReturnValue({} as query.MsgUpdateFeeShare) + + const extension = setupDevgasMsgExtension(mockBaseQueryClient) + const result = await extension.updateFeeShare({ + contractAddress: "", + deployerAddress: "", + withdrawerAddress: "", + }) + expect(msgUpdateFeeShare).toHaveBeenCalledWith({ + contractAddress: "", + deployerAddress: "", + withdrawerAddress: "", + }) + expect(result).toEqual({ test: "Test" }) + }) + }) + + describe("cancelFeeShare", () => { + test("should call MsgRegisterFeeShare and return the response", async () => { + const msgCancelFeeShare = jest + .spyOn(query.MsgCancelFeeShare, "fromPartial") + .mockReturnValue({} as query.MsgCancelFeeShare) + + const extension = setupDevgasMsgExtension(mockBaseQueryClient) + const result = await extension.cancelFeeShare({ + contractAddress: "", + deployerAddress: "", + }) + expect(msgCancelFeeShare).toHaveBeenCalledWith({ + contractAddress: "", + deployerAddress: "", + }) + expect(result).toEqual({ test: "Test" }) + }) + }) + + describe("updateParams", () => { + test("should call MsgRegisterFeeShare and return the response", async () => { + const msgUpdateParams = jest + .spyOn(query.MsgUpdateParams, "fromPartial") + .mockReturnValue({} as query.MsgUpdateParams) + + const extension = setupDevgasMsgExtension(mockBaseQueryClient) + const result = await extension.updateParams({ + authority: "", + params: { + enableFeeShare: true, + developerShares: "", + allowedDenoms: [""], + }, + }) + expect(msgUpdateParams).toHaveBeenCalledWith({ + authority: "", + params: { + enableFeeShare: true, + developerShares: "", + allowedDenoms: [""], + }, + }) + expect(result).toEqual({ test: "Test" }) + }) + }) +}) diff --git a/src/sdk/msg/devgas.ts b/src/sdk/msg/devgas.ts index ba7501c1..ec5ffa24 100644 --- a/src/sdk/msg/devgas.ts +++ b/src/sdk/msg/devgas.ts @@ -12,18 +12,16 @@ import { } from "../../protojs/nibiru/devgas/v1/tx" export interface DevgasMsgExtension { - readonly devgasMsg: Readonly<{ - registerFeeShare: ( - body: MsgRegisterFeeShare - ) => Promise - updateFeeShare: ( - body: MsgUpdateFeeShare - ) => Promise - cancelFeeShare: ( - body: MsgCancelFeeShare - ) => Promise - updateParams: (body: MsgUpdateParams) => Promise - }> + registerFeeShare: ( + body: MsgRegisterFeeShare + ) => Promise + updateFeeShare: ( + body: MsgUpdateFeeShare + ) => Promise + cancelFeeShare: ( + body: MsgCancelFeeShare + ) => Promise + updateParams: (body: MsgUpdateParams) => Promise } export const setupDevgasMsgExtension = ( @@ -32,18 +30,16 @@ export const setupDevgasMsgExtension = ( const queryService = new MsgClientImpl(createProtobufRpcClient(base)) return { - devgasMsg: { - registerFeeShare: async (body: MsgRegisterFeeShare) => - queryService.RegisterFeeShare(MsgRegisterFeeShare.fromPartial(body)), + registerFeeShare: async (body: MsgRegisterFeeShare) => + queryService.RegisterFeeShare(MsgRegisterFeeShare.fromPartial(body)), - updateFeeShare: async (body: MsgUpdateFeeShare) => - queryService.UpdateFeeShare(MsgUpdateFeeShare.fromPartial(body)), + updateFeeShare: async (body: MsgUpdateFeeShare) => + queryService.UpdateFeeShare(MsgUpdateFeeShare.fromPartial(body)), - cancelFeeShare: async (body: MsgCancelFeeShare) => - queryService.CancelFeeShare(MsgCancelFeeShare.fromPartial(body)), + cancelFeeShare: async (body: MsgCancelFeeShare) => + queryService.CancelFeeShare(MsgCancelFeeShare.fromPartial(body)), - updateParams: async (body: MsgUpdateParams) => - queryService.UpdateParams(MsgUpdateParams.fromPartial(body)), - }, + updateParams: async (body: MsgUpdateParams) => + queryService.UpdateParams(MsgUpdateParams.fromPartial(body)), } } diff --git a/src/sdk/msg/eth.test.ts b/src/sdk/msg/eth.test.ts new file mode 100644 index 00000000..50271945 --- /dev/null +++ b/src/sdk/msg/eth.test.ts @@ -0,0 +1,83 @@ +import { QueryClient } from "@cosmjs/stargate" +import * as query from "../../protojs/eth/evm/v1/tx" +import { setupEthMsgExtension } from "." +import Long from "long" + +describe("setupEthMsgExtension", () => { + const mockBaseQueryClient = {} as QueryClient + + jest.spyOn(query, "MsgClientImpl").mockReturnValue({ + EthereumTx: jest.fn().mockResolvedValue({ test: "Test" }), + UpdateParams: jest.fn().mockResolvedValue({ + test: "Test", + }), + } as unknown as query.MsgClientImpl) + + test("should setup extension correctly", () => { + const extension = setupEthMsgExtension(mockBaseQueryClient) + + expect(extension).toBeDefined() + expect(extension.ethereumTx).toBeInstanceOf(Function) + expect(extension.updateParams).toBeInstanceOf(Function) + }) + + describe("ethereumTx", () => { + test("should call MsgEthereumTx and return the response", async () => { + const msgEthereumTx = jest + .spyOn(query.MsgEthereumTx, "fromPartial") + .mockReturnValue({} as query.MsgEthereumTx) + + const extension = setupEthMsgExtension(mockBaseQueryClient) + const result = await extension.ethereumTx({ + data: { typeUrl: "", value: new Uint8Array() }, + size: 0, + hash: "", + from: "", + }) + expect(msgEthereumTx).toHaveBeenCalledWith({ + data: { typeUrl: "", value: new Uint8Array() }, + size: 0, + hash: "", + from: "", + }) + expect(result).toEqual({ test: "Test" }) + }) + }) + + describe("updateParams", () => { + test("should call MsgRegisterFeeShare and return the response", async () => { + const msgUpdateParams = jest + .spyOn(query.MsgUpdateParams, "fromPartial") + .mockReturnValue({} as query.MsgUpdateParams) + + const extension = setupEthMsgExtension(mockBaseQueryClient) + const result = await extension.updateParams({ + authority: "", + params: { + evmDenom: "", + createFuntokenFee: "", + enableCreate: true, + enableCall: true, + extraEips: [new Long(0)], + allowUnprotectedTxs: true, + activePrecompiles: [""], + evmChannels: [""], + }, + }) + expect(msgUpdateParams).toHaveBeenCalledWith({ + authority: "", + params: { + evmDenom: "", + createFuntokenFee: "", + enableCreate: true, + enableCall: true, + extraEips: [new Long(0)], + allowUnprotectedTxs: true, + activePrecompiles: [""], + evmChannels: [""], + }, + }) + expect(result).toEqual({ test: "Test" }) + }) + }) +}) diff --git a/src/sdk/msg/eth.ts b/src/sdk/msg/eth.ts new file mode 100644 index 00000000..dce30c0c --- /dev/null +++ b/src/sdk/msg/eth.ts @@ -0,0 +1,24 @@ +import { createProtobufRpcClient, QueryClient } from "@cosmjs/stargate" +import { + MsgClientImpl, + MsgEthereumTx, + MsgEthereumTxResponse, + MsgUpdateParams, + MsgUpdateParamsResponse, +} from "../../protojs/eth/evm/v1/tx" + +export interface EthMsgExtension { + ethereumTx: (body: MsgEthereumTx) => Promise + updateParams: (body: MsgUpdateParams) => Promise +} + +export const setupEthMsgExtension = (base: QueryClient): EthMsgExtension => { + const queryService = new MsgClientImpl(createProtobufRpcClient(base)) + + return { + ethereumTx: async (body: MsgEthereumTx) => + queryService.EthereumTx(MsgEthereumTx.fromPartial(body)), + updateParams: async (body: MsgUpdateParams) => + queryService.UpdateParams(MsgUpdateParams.fromPartial(body)), + } +} diff --git a/src/sdk/msg/index.ts b/src/sdk/msg/index.ts index 602f697f..4669bae8 100644 --- a/src/sdk/msg/index.ts +++ b/src/sdk/msg/index.ts @@ -3,6 +3,7 @@ */ export * from "./devgas" +export * from "./eth" export * from "./inflation" export * from "./oracle" export * from "./sudo" diff --git a/src/sdk/msg/inflation.test.ts b/src/sdk/msg/inflation.test.ts new file mode 100644 index 00000000..992c20dc --- /dev/null +++ b/src/sdk/msg/inflation.test.ts @@ -0,0 +1,78 @@ +import { QueryClient } from "@cosmjs/stargate" +import * as query from "../../protojs/nibiru/inflation/v1/tx" +import { setupInflationMsgExtension } from "." + +describe("setupEthMsgExtension", () => { + const mockBaseQueryClient = {} as QueryClient + + jest.spyOn(query, "MsgClientImpl").mockReturnValue({ + ToggleInflation: jest.fn().mockResolvedValue({ test: "Test" }), + EditInflationParams: jest.fn().mockResolvedValue({ + test: "Test", + }), + } as unknown as query.MsgClientImpl) + + test("should setup extension correctly", () => { + const extension = setupInflationMsgExtension(mockBaseQueryClient) + + expect(extension).toBeDefined() + expect(extension.toggleInflation).toBeInstanceOf(Function) + expect(extension.editInflationParams).toBeInstanceOf(Function) + }) + + describe("toggleInflation", () => { + test("should call MsgToggleInflation and return the response", async () => { + const msgToggleInflation = jest + .spyOn(query.MsgToggleInflation, "fromPartial") + .mockReturnValue({} as query.MsgToggleInflation) + + const extension = setupInflationMsgExtension(mockBaseQueryClient) + const result = await extension.toggleInflation({ + sender: "", + enable: true, + }) + expect(msgToggleInflation).toHaveBeenCalledWith({ + sender: "", + enable: true, + }) + expect(result).toEqual({ test: "Test" }) + }) + }) + + describe("editInflationParams", () => { + test("should call MsgEditInflationParams and return the response", async () => { + const msgEditInflationParams = jest + .spyOn(query.MsgEditInflationParams, "fromPartial") + .mockReturnValue({} as query.MsgEditInflationParams) + + const extension = setupInflationMsgExtension(mockBaseQueryClient) + const result = await extension.editInflationParams({ + sender: "", + inflationEnabled: true, + polynomialFactors: [""], + inflationDistribution: { + stakingRewards: "", + communityPool: "", + strategicReserves: "", + }, + epochsPerPeriod: "", + periodsPerYear: "", + maxPeriod: "", + }) + expect(msgEditInflationParams).toHaveBeenCalledWith({ + sender: "", + inflationEnabled: true, + polynomialFactors: [""], + inflationDistribution: { + stakingRewards: "", + communityPool: "", + strategicReserves: "", + }, + epochsPerPeriod: "", + periodsPerYear: "", + maxPeriod: "", + }) + expect(result).toEqual({ test: "Test" }) + }) + }) +}) diff --git a/src/sdk/msg/inflation.ts b/src/sdk/msg/inflation.ts index 6abfa0fe..49e3cb82 100644 --- a/src/sdk/msg/inflation.ts +++ b/src/sdk/msg/inflation.ts @@ -8,14 +8,12 @@ import { } from "../../protojs/nibiru/inflation/v1/tx" export interface InflationMsgExtension { - readonly inflationMsg: Readonly<{ - toggleInflation: ( - body: MsgToggleInflation - ) => Promise - editInflationParams: ( - body: MsgEditInflationParams - ) => Promise - }> + toggleInflation: ( + body: MsgToggleInflation + ) => Promise + editInflationParams: ( + body: MsgEditInflationParams + ) => Promise } export const setupInflationMsgExtension = ( @@ -24,14 +22,12 @@ export const setupInflationMsgExtension = ( const queryService = new MsgClientImpl(createProtobufRpcClient(base)) return { - inflationMsg: { - toggleInflation: async (body: MsgToggleInflation) => - queryService.ToggleInflation(MsgToggleInflation.fromPartial(body)), + toggleInflation: async (body: MsgToggleInflation) => + queryService.ToggleInflation(MsgToggleInflation.fromPartial(body)), - editInflationParams: async (body: MsgEditInflationParams) => - queryService.EditInflationParams( - MsgEditInflationParams.fromPartial(body) - ), - }, + editInflationParams: async (body: MsgEditInflationParams) => + queryService.EditInflationParams( + MsgEditInflationParams.fromPartial(body) + ), } } diff --git a/src/sdk/msg/oracle.test.ts b/src/sdk/msg/oracle.test.ts new file mode 100644 index 00000000..dfc71daa --- /dev/null +++ b/src/sdk/msg/oracle.test.ts @@ -0,0 +1,130 @@ +import { QueryClient } from "@cosmjs/stargate" +import * as query from "../../protojs/nibiru/oracle/v1/tx" +import { setupOracleMsgExtension } from "." + +describe("setupEthMsgExtension", () => { + const mockBaseQueryClient = {} as QueryClient + + jest.spyOn(query, "MsgClientImpl").mockReturnValue({ + AggregateExchangeRatePrevote: jest.fn().mockResolvedValue({ test: "Test" }), + AggregateExchangeRateVote: jest.fn().mockResolvedValue({ + test: "Test", + }), + DelegateFeedConsent: jest.fn().mockResolvedValue({ + test: "Test", + }), + EditOracleParams: jest.fn().mockResolvedValue({ + test: "Test", + }), + } as unknown as query.MsgClientImpl) + + test("should setup extension correctly", () => { + const extension = setupOracleMsgExtension(mockBaseQueryClient) + + expect(extension).toBeDefined() + expect(extension.aggregateExchangeRatePrevote).toBeInstanceOf(Function) + expect(extension.aggregateExchangeRateVote).toBeInstanceOf(Function) + expect(extension.delegateFeedConsent).toBeInstanceOf(Function) + expect(extension.editOracleParams).toBeInstanceOf(Function) + }) + + describe("aggregateExchangeRatePrevote", () => { + test("should call MsgAggregateExchangeRatePrevote and return the response", async () => { + const msgAggregateExchangeRatePrevote = jest + .spyOn(query.MsgAggregateExchangeRatePrevote, "fromPartial") + .mockReturnValue({} as query.MsgAggregateExchangeRatePrevote) + + const extension = setupOracleMsgExtension(mockBaseQueryClient) + const result = await extension.aggregateExchangeRatePrevote({ + hash: "", + feeder: "", + validator: "", + }) + expect(msgAggregateExchangeRatePrevote).toHaveBeenCalledWith({ + hash: "", + feeder: "", + validator: "", + }) + expect(result).toEqual({ test: "Test" }) + }) + }) + + describe("aggregateExchangeRateVote", () => { + test("should call MsgAggregateExchangeRateVote and return the response", async () => { + const msgAggregateExchangeRateVote = jest + .spyOn(query.MsgAggregateExchangeRateVote, "fromPartial") + .mockReturnValue({} as query.MsgAggregateExchangeRateVote) + + const extension = setupOracleMsgExtension(mockBaseQueryClient) + const result = await extension.aggregateExchangeRateVote({ + salt: "", + exchangeRates: "", + feeder: "", + validator: "", + }) + expect(msgAggregateExchangeRateVote).toHaveBeenCalledWith({ + salt: "", + exchangeRates: "", + feeder: "", + validator: "", + }) + expect(result).toEqual({ test: "Test" }) + }) + }) + + describe("delegateFeedConsent", () => { + test("should call MsgDelegateFeedConsent and return the response", async () => { + const msgDelegateFeedConsent = jest + .spyOn(query.MsgDelegateFeedConsent, "fromPartial") + .mockReturnValue({} as query.MsgDelegateFeedConsent) + + const extension = setupOracleMsgExtension(mockBaseQueryClient) + const result = await extension.delegateFeedConsent({ + operator: "", + delegate: "", + }) + expect(msgDelegateFeedConsent).toHaveBeenCalledWith({ + operator: "", + delegate: "", + }) + expect(result).toEqual({ test: "Test" }) + }) + }) + + describe("editOracleParams", () => { + test("should call MsgEditOracleParams and return the response", async () => { + const msgEditOracleParams = jest + .spyOn(query.MsgEditOracleParams, "fromPartial") + .mockReturnValue({} as query.MsgEditOracleParams) + + const extension = setupOracleMsgExtension(mockBaseQueryClient) + const result = await extension.editOracleParams({ + sender: "", + votePeriod: "", + voteThreshold: "", + rewardBand: "", + whitelist: [""], + slashFraction: "", + slashWindow: "", + minValidPerWindow: "", + twapLookbackWindow: "", + minVoters: "", + validatorFeeRatio: "", + }) + expect(msgEditOracleParams).toHaveBeenCalledWith({ + sender: "", + votePeriod: "", + voteThreshold: "", + rewardBand: "", + whitelist: [""], + slashFraction: "", + slashWindow: "", + minValidPerWindow: "", + twapLookbackWindow: "", + minVoters: "", + validatorFeeRatio: "", + }) + expect(result).toEqual({ test: "Test" }) + }) + }) +}) diff --git a/src/sdk/msg/oracle.ts b/src/sdk/msg/oracle.ts index 288cb72b..ba7a921a 100644 --- a/src/sdk/msg/oracle.ts +++ b/src/sdk/msg/oracle.ts @@ -12,20 +12,18 @@ import { } from "../../protojs/nibiru/oracle/v1/tx" export interface OracleMsgExtension { - readonly oracleMsg: Readonly<{ - aggregateExchangeRatePrevote: ( - body: MsgAggregateExchangeRatePrevote - ) => Promise - aggregateExchangeRateVote: ( - body: MsgAggregateExchangeRateVote - ) => Promise - delegateFeedConsent: ( - body: MsgDelegateFeedConsent - ) => Promise - editOracleParams: ( - body: MsgEditOracleParams - ) => Promise - }> + aggregateExchangeRatePrevote: ( + body: MsgAggregateExchangeRatePrevote + ) => Promise + aggregateExchangeRateVote: ( + body: MsgAggregateExchangeRateVote + ) => Promise + delegateFeedConsent: ( + body: MsgDelegateFeedConsent + ) => Promise + editOracleParams: ( + body: MsgEditOracleParams + ) => Promise } export const setupOracleMsgExtension = ( @@ -34,26 +32,24 @@ export const setupOracleMsgExtension = ( const queryService = new MsgClientImpl(createProtobufRpcClient(base)) return { - oracleMsg: { - aggregateExchangeRatePrevote: async ( - body: MsgAggregateExchangeRatePrevote - ) => - queryService.AggregateExchangeRatePrevote( - MsgAggregateExchangeRatePrevote.fromPartial(body) - ), + aggregateExchangeRatePrevote: async ( + body: MsgAggregateExchangeRatePrevote + ) => + queryService.AggregateExchangeRatePrevote( + MsgAggregateExchangeRatePrevote.fromPartial(body) + ), - aggregateExchangeRateVote: async (body: MsgAggregateExchangeRateVote) => - queryService.AggregateExchangeRateVote( - MsgAggregateExchangeRateVote.fromPartial(body) - ), + aggregateExchangeRateVote: async (body: MsgAggregateExchangeRateVote) => + queryService.AggregateExchangeRateVote( + MsgAggregateExchangeRateVote.fromPartial(body) + ), - delegateFeedConsent: async (body: MsgDelegateFeedConsent) => - queryService.DelegateFeedConsent( - MsgDelegateFeedConsent.fromPartial(body) - ), + delegateFeedConsent: async (body: MsgDelegateFeedConsent) => + queryService.DelegateFeedConsent( + MsgDelegateFeedConsent.fromPartial(body) + ), - editOracleParams: async (body: MsgEditOracleParams) => - queryService.EditOracleParams(MsgEditOracleParams.fromPartial(body)), - }, + editOracleParams: async (body: MsgEditOracleParams) => + queryService.EditOracleParams(MsgEditOracleParams.fromPartial(body)), } } diff --git a/src/sdk/msg/sudo.test.ts b/src/sdk/msg/sudo.test.ts new file mode 100644 index 00000000..ac3a2760 --- /dev/null +++ b/src/sdk/msg/sudo.test.ts @@ -0,0 +1,62 @@ +import { QueryClient } from "@cosmjs/stargate" +import * as query from "../../protojs/nibiru/sudo/v1/tx" +import { setupSudoMsgExtension } from "." + +describe("setupEthMsgExtension", () => { + const mockBaseQueryClient = {} as QueryClient + + jest.spyOn(query, "MsgClientImpl").mockReturnValue({ + EditSudoers: jest.fn().mockResolvedValue({ test: "Test" }), + ChangeRoot: jest.fn().mockResolvedValue({ + test: "Test", + }), + } as unknown as query.MsgClientImpl) + + test("should setup extension correctly", () => { + const extension = setupSudoMsgExtension(mockBaseQueryClient) + + expect(extension).toBeDefined() + expect(extension.editSudoers).toBeInstanceOf(Function) + expect(extension.changeRoot).toBeInstanceOf(Function) + }) + + describe("editSudoers", () => { + test("should call MsgEditSudoers and return the response", async () => { + const msgEditSudoers = jest + .spyOn(query.MsgEditSudoers, "fromPartial") + .mockReturnValue({} as query.MsgEditSudoers) + + const extension = setupSudoMsgExtension(mockBaseQueryClient) + const result = await extension.editSudoers({ + sender: "", + action: "", + contracts: [""], + }) + expect(msgEditSudoers).toHaveBeenCalledWith({ + sender: "", + action: "", + contracts: [""], + }) + expect(result).toEqual({ test: "Test" }) + }) + }) + + describe("changeRoot", () => { + test("should call MsgChangeRoot and return the response", async () => { + const msgChangeRoot = jest + .spyOn(query.MsgChangeRoot, "fromPartial") + .mockReturnValue({} as query.MsgChangeRoot) + + const extension = setupSudoMsgExtension(mockBaseQueryClient) + const result = await extension.changeRoot({ + sender: "", + newRoot: "", + }) + expect(msgChangeRoot).toHaveBeenCalledWith({ + sender: "", + newRoot: "", + }) + expect(result).toEqual({ test: "Test" }) + }) + }) +}) diff --git a/src/sdk/msg/sudo.ts b/src/sdk/msg/sudo.ts index ecd5bb9e..6762f0b3 100644 --- a/src/sdk/msg/sudo.ts +++ b/src/sdk/msg/sudo.ts @@ -8,22 +8,18 @@ import { } from "../../protojs/nibiru/sudo/v1/tx" export interface SudoMsgExtension { - readonly sudoMsg: Readonly<{ - editSudoers: (body: MsgEditSudoers) => Promise - changeRoot: (body: MsgChangeRoot) => Promise - }> + editSudoers: (body: MsgEditSudoers) => Promise + changeRoot: (body: MsgChangeRoot) => Promise } export const setupSudoMsgExtension = (base: QueryClient): SudoMsgExtension => { const queryService = new MsgClientImpl(createProtobufRpcClient(base)) return { - sudoMsg: { - editSudoers: async (body: MsgEditSudoers) => - queryService.EditSudoers(MsgEditSudoers.fromPartial(body)), + editSudoers: async (body: MsgEditSudoers) => + queryService.EditSudoers(MsgEditSudoers.fromPartial(body)), - changeRoot: async (body: MsgChangeRoot) => - queryService.ChangeRoot(MsgChangeRoot.fromPartial(body)), - }, + changeRoot: async (body: MsgChangeRoot) => + queryService.ChangeRoot(MsgChangeRoot.fromPartial(body)), } } diff --git a/src/sdk/msg/tokenfactory.test.ts b/src/sdk/msg/tokenfactory.test.ts new file mode 100644 index 00000000..4b6758d4 --- /dev/null +++ b/src/sdk/msg/tokenfactory.test.ts @@ -0,0 +1,204 @@ +import { QueryClient } from "@cosmjs/stargate" +import * as query from "../../protojs/nibiru/tokenfactory/v1/tx" +import { setupTokenFactoryMsgExtension } from "." +import Long from "long" + +describe("setupEthMsgExtension", () => { + const mockBaseQueryClient = {} as QueryClient + + jest.spyOn(query, "MsgClientImpl").mockReturnValue({ + CreateDenom: jest.fn().mockResolvedValue({ test: "Test" }), + ChangeAdmin: jest.fn().mockResolvedValue({ + test: "Test", + }), + UpdateModuleParams: jest.fn().mockResolvedValue({ + test: "Test", + }), + Mint: jest.fn().mockResolvedValue({ + test: "Test", + }), + Burn: jest.fn().mockResolvedValue({ + test: "Test", + }), + SetDenomMetadata: jest.fn().mockResolvedValue({ + test: "Test", + }), + BurnNative: jest.fn().mockResolvedValue({ + test: "Test", + }), + } as unknown as query.MsgClientImpl) + + test("should setup extension correctly", () => { + const extension = setupTokenFactoryMsgExtension(mockBaseQueryClient) + + expect(extension).toBeDefined() + expect(extension.createDenom).toBeInstanceOf(Function) + expect(extension.changeAdmin).toBeInstanceOf(Function) + expect(extension.updateModuleParams).toBeInstanceOf(Function) + expect(extension.mint).toBeInstanceOf(Function) + expect(extension.burn).toBeInstanceOf(Function) + expect(extension.setDenomMetadata).toBeInstanceOf(Function) + expect(extension.burnNative).toBeInstanceOf(Function) + }) + + describe("createDenom", () => { + test("should call MsgCreateDenom and return the response", async () => { + const msgCreateDenom = jest + .spyOn(query.MsgCreateDenom, "fromPartial") + .mockReturnValue({} as query.MsgCreateDenom) + + const extension = setupTokenFactoryMsgExtension(mockBaseQueryClient) + const result = await extension.createDenom({ + sender: "", + subdenom: "", + }) + expect(msgCreateDenom).toHaveBeenCalledWith({ + sender: "", + subdenom: "", + }) + expect(result).toEqual({ test: "Test" }) + }) + }) + + describe("changeAdmin", () => { + test("should call MsgChangeAdmin and return the response", async () => { + const msgChangeAdmin = jest + .spyOn(query.MsgChangeAdmin, "fromPartial") + .mockReturnValue({} as query.MsgChangeAdmin) + + const extension = setupTokenFactoryMsgExtension(mockBaseQueryClient) + const result = await extension.changeAdmin({ + sender: "", + denom: "", + newAdmin: "", + }) + expect(msgChangeAdmin).toHaveBeenCalledWith({ + sender: "", + denom: "", + newAdmin: "", + }) + expect(result).toEqual({ test: "Test" }) + }) + }) + + describe("updateModuleParams", () => { + test("should call MsgUpdateModuleParams and return the response", async () => { + const msgUpdateModuleParams = jest + .spyOn(query.MsgUpdateModuleParams, "fromPartial") + .mockReturnValue({} as query.MsgUpdateModuleParams) + + const extension = setupTokenFactoryMsgExtension(mockBaseQueryClient) + const result = await extension.updateModuleParams({ + authority: "", + params: { + denomCreationGasConsume: new Long(0), + }, + }) + expect(msgUpdateModuleParams).toHaveBeenCalledWith({ + authority: "", + params: { + denomCreationGasConsume: new Long(0), + }, + }) + expect(result).toEqual({ test: "Test" }) + }) + }) + + describe("mint", () => { + test("should call MsgMint and return the response", async () => { + const msgMint = jest + .spyOn(query.MsgMint, "fromPartial") + .mockReturnValue({} as query.MsgMint) + + const extension = setupTokenFactoryMsgExtension(mockBaseQueryClient) + const result = await extension.mint({ + sender: "", + coin: { denom: "", amount: "" }, + mintTo: "", + }) + expect(msgMint).toHaveBeenCalledWith({ + sender: "", + coin: { denom: "", amount: "" }, + mintTo: "", + }) + expect(result).toEqual({ test: "Test" }) + }) + }) + + describe("burn", () => { + test("should call MsgBurn and return the response", async () => { + const msgBurn = jest + .spyOn(query.MsgBurn, "fromPartial") + .mockReturnValue({} as query.MsgBurn) + + const extension = setupTokenFactoryMsgExtension(mockBaseQueryClient) + const result = await extension.burn({ + sender: "", + coin: { denom: "", amount: "" }, + burnFrom: "", + }) + expect(msgBurn).toHaveBeenCalledWith({ + sender: "", + coin: { denom: "", amount: "" }, + burnFrom: "", + }) + expect(result).toEqual({ test: "Test" }) + }) + }) + + describe("setDenomMetadata", () => { + test("should call MsgSetDenomMetadata and return the response", async () => { + const msgSetDenomMetadata = jest + .spyOn(query.MsgSetDenomMetadata, "fromPartial") + .mockReturnValue({} as query.MsgSetDenomMetadata) + + const extension = setupTokenFactoryMsgExtension(mockBaseQueryClient) + const result = await extension.setDenomMetadata({ + sender: "", + metadata: { + description: "", + denomUnits: [{ denom: "", exponent: 0, aliases: [""] }], + base: "", + display: "", + name: "", + symbol: "", + uri: "", + uriHash: "", + }, + }) + expect(msgSetDenomMetadata).toHaveBeenCalledWith({ + sender: "", + metadata: { + description: "", + denomUnits: [{ denom: "", exponent: 0, aliases: [""] }], + base: "", + display: "", + name: "", + symbol: "", + uri: "", + uriHash: "", + }, + }) + expect(result).toEqual({ test: "Test" }) + }) + }) + + describe("burnNative", () => { + test("should call MsgBurnNative and return the response", async () => { + const msgBurnNative = jest + .spyOn(query.MsgBurnNative, "fromPartial") + .mockReturnValue({} as query.MsgBurnNative) + + const extension = setupTokenFactoryMsgExtension(mockBaseQueryClient) + const result = await extension.burnNative({ + sender: "", + coin: { denom: "", amount: "" }, + }) + expect(msgBurnNative).toHaveBeenCalledWith({ + sender: "", + coin: { denom: "", amount: "" }, + }) + expect(result).toEqual({ test: "Test" }) + }) + }) +}) diff --git a/src/sdk/msg/tokenfactory.ts b/src/sdk/msg/tokenfactory.ts index 5e036a45..2b6c1d85 100644 --- a/src/sdk/msg/tokenfactory.ts +++ b/src/sdk/msg/tokenfactory.ts @@ -18,19 +18,17 @@ import { } from "../../protojs/nibiru/tokenfactory/v1/tx" export interface TokenFactoryMsgExtension { - readonly tokenFactoryMsg: Readonly<{ - createDenom: (body: MsgCreateDenom) => Promise - changeAdmin: (body: MsgChangeAdmin) => Promise - updateModuleParams: ( - body: MsgUpdateModuleParams - ) => Promise - mint: (body: MsgMint) => Promise - burn: (body: MsgBurn) => Promise - setDenomMetadata: ( - body: MsgSetDenomMetadata - ) => Promise - burnNative: (body: MsgBurnNative) => Promise - }> + createDenom: (body: MsgCreateDenom) => Promise + changeAdmin: (body: MsgChangeAdmin) => Promise + updateModuleParams: ( + body: MsgUpdateModuleParams + ) => Promise + mint: (body: MsgMint) => Promise + burn: (body: MsgBurn) => Promise + setDenomMetadata: ( + body: MsgSetDenomMetadata + ) => Promise + burnNative: (body: MsgBurnNative) => Promise } export const setupTokenFactoryMsgExtension = ( @@ -39,29 +37,23 @@ export const setupTokenFactoryMsgExtension = ( const queryService = new MsgClientImpl(createProtobufRpcClient(base)) return { - tokenFactoryMsg: { - createDenom: async (body: MsgCreateDenom) => - queryService.CreateDenom(MsgCreateDenom.fromPartial(body)), + createDenom: async (body: MsgCreateDenom) => + queryService.CreateDenom(MsgCreateDenom.fromPartial(body)), - changeAdmin: async (body: MsgChangeAdmin) => - queryService.ChangeAdmin(MsgChangeAdmin.fromPartial(body)), + changeAdmin: async (body: MsgChangeAdmin) => + queryService.ChangeAdmin(MsgChangeAdmin.fromPartial(body)), - updateModuleParams: async (body: MsgUpdateModuleParams) => - queryService.UpdateModuleParams( - MsgUpdateModuleParams.fromPartial(body) - ), + updateModuleParams: async (body: MsgUpdateModuleParams) => + queryService.UpdateModuleParams(MsgUpdateModuleParams.fromPartial(body)), - mint: async (body: MsgMint) => - queryService.Mint(MsgMint.fromPartial(body)), + mint: async (body: MsgMint) => queryService.Mint(MsgMint.fromPartial(body)), - burn: async (body: MsgBurn) => - queryService.Burn(MsgBurn.fromPartial(body)), + burn: async (body: MsgBurn) => queryService.Burn(MsgBurn.fromPartial(body)), - setDenomMetadata: async (body: MsgSetDenomMetadata) => - queryService.SetDenomMetadata(MsgSetDenomMetadata.fromPartial(body)), + setDenomMetadata: async (body: MsgSetDenomMetadata) => + queryService.SetDenomMetadata(MsgSetDenomMetadata.fromPartial(body)), - burnNative: async (body: MsgBurnNative) => - queryService.BurnNative(MsgBurnNative.fromPartial(body)), - }, + burnNative: async (body: MsgBurnNative) => + queryService.BurnNative(MsgBurnNative.fromPartial(body)), } } diff --git a/src/sdk/query/devgas.test.ts b/src/sdk/query/devgas.test.ts new file mode 100644 index 00000000..ea8ed9ad --- /dev/null +++ b/src/sdk/query/devgas.test.ts @@ -0,0 +1,88 @@ +import { QueryClient } from "@cosmjs/stargate" +import * as query from "../../protojs/nibiru/devgas/v1/query" +import { setupDevgasExtension } from "." + +describe("setupDevgasExtension", () => { + const mockBaseQueryClient = {} as QueryClient + + jest.spyOn(query, "QueryClientImpl").mockReturnValue({ + FeeShare: jest.fn().mockResolvedValue({ feeShare: "Test" }), + FeeSharesByWithdrawer: jest + .fn() + .mockResolvedValue({ feeSharesByWithdrawer: "Test" }), + FeeShares: jest.fn().mockResolvedValue({ feeShares: "Test" }), + Params: jest.fn().mockResolvedValue({ params: "Test" }), + } as unknown as query.QueryClientImpl) + + test("should setup extension correctly", () => { + const extension = setupDevgasExtension(mockBaseQueryClient) + + expect(extension).toBeDefined() + expect(extension.feeShare).toBeInstanceOf(Function) + expect(extension.feeSharesByWithdrawer).toBeInstanceOf(Function) + expect(extension.feeShares).toBeInstanceOf(Function) + expect(extension.params).toBeInstanceOf(Function) + }) + + describe("devgas.feeShare", () => { + test("should call QueryFeeShareRequest and return the response", async () => { + const queryFeeShareRequest = jest + .spyOn(query.QueryFeeShareRequest, "fromPartial") + .mockReturnValue({} as query.QueryFeeShareRequest) + + const extension = setupDevgasExtension(mockBaseQueryClient) + const result = await extension.feeShare({ contractAddress: "" }) + expect(queryFeeShareRequest).toHaveBeenCalledWith({ + contractAddress: "", + }) + expect(result).toEqual({ feeShare: "Test" }) + }) + }) + + describe("devgas.feeSharesByWithdrawer", () => { + test("should call QueryFeeSharesByWithdrawerRequest and return the response", async () => { + const queryFeeSharesByWithdrawerRequest = jest + .spyOn(query.QueryFeeSharesByWithdrawerRequest, "fromPartial") + .mockReturnValue({} as query.QueryFeeSharesByWithdrawerRequest) + + const extension = setupDevgasExtension(mockBaseQueryClient) + const result = await extension.feeSharesByWithdrawer({ + withdrawerAddress: "", + }) + expect(queryFeeSharesByWithdrawerRequest).toHaveBeenCalledWith({ + withdrawerAddress: "", + }) + expect(result).toEqual({ feeSharesByWithdrawer: "Test" }) + }) + }) + + describe("devgas.feeShares", () => { + test("should call QueryFeeSharesRequest and return the response", async () => { + const queryFeeSharesRequest = jest + .spyOn(query.QueryFeeSharesRequest, "fromPartial") + .mockReturnValue({} as query.QueryFeeSharesRequest) + + const extension = setupDevgasExtension(mockBaseQueryClient) + const result = await extension.feeShares({ + deployer: "", + }) + expect(queryFeeSharesRequest).toHaveBeenCalledWith({ + deployer: "", + }) + expect(result).toEqual({ feeShares: "Test" }) + }) + }) + + describe("devgas.params", () => { + test("should call QueryParamsRequest and return the response", async () => { + const queryParamsRequest = jest + .spyOn(query.QueryParamsRequest, "fromPartial") + .mockReturnValue({} as query.QueryParamsRequest) + + const extension = setupDevgasExtension(mockBaseQueryClient) + const result = await extension.params({}) + expect(queryParamsRequest).toHaveBeenCalledWith({}) + expect(result).toEqual({ params: "Test" }) + }) + }) +}) diff --git a/src/sdk/query/devgas.ts b/src/sdk/query/devgas.ts index a4abda04..0d92d30f 100644 --- a/src/sdk/query/devgas.ts +++ b/src/sdk/query/devgas.ts @@ -12,34 +12,30 @@ import { } from "../../protojs/nibiru/devgas/v1/query" export interface DevgasExtension { - readonly devgas: Readonly<{ - feeShare: (args: QueryFeeShareRequest) => Promise - feeSharesByWithdrawer: ( - args: QueryFeeSharesByWithdrawerRequest - ) => Promise - feeShares: (args: QueryFeeSharesRequest) => Promise - params: (args: QueryParamsRequest) => Promise - }> + feeShare: (args: QueryFeeShareRequest) => Promise + feeSharesByWithdrawer: ( + args: QueryFeeSharesByWithdrawerRequest + ) => Promise + feeShares: (args: QueryFeeSharesRequest) => Promise + params: (args: QueryParamsRequest) => Promise } export const setupDevgasExtension = (base: QueryClient): DevgasExtension => { const queryService = new QueryClientImpl(createProtobufRpcClient(base)) return { - devgas: { - feeShare: async (args: QueryFeeShareRequest) => - queryService.FeeShare(QueryFeeShareRequest.fromPartial(args)), + feeShare: async (args: QueryFeeShareRequest) => + queryService.FeeShare(QueryFeeShareRequest.fromPartial(args)), - feeSharesByWithdrawer: async (args: QueryFeeSharesByWithdrawerRequest) => - queryService.FeeSharesByWithdrawer( - QueryFeeSharesByWithdrawerRequest.fromPartial(args) - ), + feeSharesByWithdrawer: async (args: QueryFeeSharesByWithdrawerRequest) => + queryService.FeeSharesByWithdrawer( + QueryFeeSharesByWithdrawerRequest.fromPartial(args) + ), - feeShares: async (args: QueryFeeSharesRequest) => - queryService.FeeShares(QueryFeeSharesRequest.fromPartial(args)), + feeShares: async (args: QueryFeeSharesRequest) => + queryService.FeeShares(QueryFeeSharesRequest.fromPartial(args)), - params: async (args: QueryParamsRequest) => - queryService.Params(QueryParamsRequest.fromPartial(args)), - }, + params: async (args: QueryParamsRequest) => + queryService.Params(QueryParamsRequest.fromPartial(args)), } } diff --git a/src/sdk/query/epochs.test.ts b/src/sdk/query/epochs.test.ts index eeca7af2..25023724 100644 --- a/src/sdk/query/epochs.test.ts +++ b/src/sdk/query/epochs.test.ts @@ -14,12 +14,12 @@ describe("setupEpochsExtension", () => { }), } as unknown as query.QueryClientImpl) - test("should setup epochs extension correctly", () => { + test("should setup extension correctly", () => { const extension = setupEpochsExtension(mockBaseQueryClient) - expect(extension.epochs).toBeDefined() - expect(extension.epochs.currentEpoch).toBeInstanceOf(Function) - expect(extension.epochs.epochsInfos).toBeInstanceOf(Function) + expect(extension).toBeDefined() + expect(extension.currentEpoch).toBeInstanceOf(Function) + expect(extension.epochsInfos).toBeInstanceOf(Function) }) describe("epochs.currentEpoch", () => { @@ -29,7 +29,7 @@ describe("setupEpochsExtension", () => { .mockReturnValue({} as query.QueryCurrentEpochRequest) const extension = setupEpochsExtension(mockBaseQueryClient) - const result = await extension.epochs.currentEpoch({ + const result = await extension.currentEpoch({ identifier: "Test Identifier", }) expect(queryCurrentEpochRequest).toHaveBeenCalledWith({ @@ -46,7 +46,7 @@ describe("setupEpochsExtension", () => { .mockReturnValue({} as query.QueryEpochInfosRequest) const extension = setupEpochsExtension(mockBaseQueryClient) - const result = await extension.epochs.epochsInfos() + const result = await extension.epochsInfos() expect(queryEpochInfosRequest).toHaveBeenCalledWith({}) expect(result).toEqual({ diff --git a/src/sdk/query/epochs.ts b/src/sdk/query/epochs.ts index 873f938e..6bdf17ee 100644 --- a/src/sdk/query/epochs.ts +++ b/src/sdk/query/epochs.ts @@ -8,24 +8,20 @@ import { } from "../../protojs/nibiru/epochs/v1/query" export interface EpochsExtension { - readonly epochs: Readonly<{ - currentEpoch: ( - body: QueryCurrentEpochRequest - ) => Promise - epochsInfos: () => Promise - }> + currentEpoch: ( + body: QueryCurrentEpochRequest + ) => Promise + epochsInfos: () => Promise } export const setupEpochsExtension = (base: QueryClient): EpochsExtension => { const queryService = new QueryClientImpl(createProtobufRpcClient(base)) return { - epochs: { - currentEpoch: async (body: QueryCurrentEpochRequest) => - queryService.CurrentEpoch(QueryCurrentEpochRequest.fromPartial(body)), + currentEpoch: async (body: QueryCurrentEpochRequest) => + queryService.CurrentEpoch(QueryCurrentEpochRequest.fromPartial(body)), - epochsInfos: async () => - queryService.EpochInfos(QueryEpochInfosRequest.fromPartial({})), - }, + epochsInfos: async () => + queryService.EpochInfos(QueryEpochInfosRequest.fromPartial({})), } } diff --git a/src/sdk/query/eth.test.ts b/src/sdk/query/eth.test.ts new file mode 100644 index 00000000..f24c79dc --- /dev/null +++ b/src/sdk/query/eth.test.ts @@ -0,0 +1,349 @@ +import { QueryClient } from "@cosmjs/stargate" +import * as query from "../../protojs/eth/evm/v1/query" +import { setupEthExtension } from "." +import Long from "long" +import { MsgEthereumTx } from "src/protojs/eth/evm/v1/tx" + +describe("setupEpochsExtension", () => { + const mockBaseQueryClient = {} as QueryClient + + jest.spyOn(query, "QueryClientImpl").mockReturnValue({ + EthAccount: jest.fn().mockResolvedValue({ ethAccount: "Test" }), + NibiruAccount: jest.fn().mockResolvedValue({ + nibiruAccount: "Test", + }), + ValidatorAccount: jest.fn().mockResolvedValue({ + validatorAccount: "Test", + }), + Balance: jest.fn().mockResolvedValue({ + balance: "Test", + }), + Storage: jest.fn().mockResolvedValue({ + storage: "Test", + }), + Code: jest.fn().mockResolvedValue({ + code: "Test", + }), + Params: jest.fn().mockResolvedValue({ + params: "Test", + }), + EthCall: jest.fn().mockResolvedValue({ + ethCall: "Test", + }), + EstimateGas: jest.fn().mockResolvedValue({ + estimateGas: "Test", + }), + TraceTx: jest.fn().mockResolvedValue({ + traceTx: "Test", + }), + TraceBlock: jest.fn().mockResolvedValue({ + traceBlock: "Test", + }), + BaseFee: jest.fn().mockResolvedValue({ + baseFee: "Test", + }), + } as unknown as query.QueryClientImpl) + + test("should setup extension correctly", () => { + const extension = setupEthExtension(mockBaseQueryClient) + + expect(extension).toBeDefined() + expect(extension.ethAccount).toBeInstanceOf(Function) + expect(extension.nibiruAccount).toBeInstanceOf(Function) + expect(extension.validatorAccount).toBeInstanceOf(Function) + expect(extension.balance).toBeInstanceOf(Function) + expect(extension.storage).toBeInstanceOf(Function) + expect(extension.code).toBeInstanceOf(Function) + expect(extension.params).toBeInstanceOf(Function) + expect(extension.ethCall).toBeInstanceOf(Function) + expect(extension.estimateGas).toBeInstanceOf(Function) + expect(extension.traceTx).toBeInstanceOf(Function) + expect(extension.traceBlock).toBeInstanceOf(Function) + expect(extension.baseFee).toBeInstanceOf(Function) + }) + + describe("ethAccount", () => { + test("should call QueryEthAccountRequest and return the response", async () => { + const queryEthAccountRequest = jest + .spyOn(query.QueryEthAccountRequest, "fromPartial") + .mockReturnValue({} as query.QueryEthAccountRequest) + + const extension = setupEthExtension(mockBaseQueryClient) + const result = await extension.ethAccount({ + address: "", + }) + expect(queryEthAccountRequest).toHaveBeenCalledWith({ + address: "", + }) + expect(result).toEqual({ ethAccount: "Test" }) + }) + }) + + describe("nibiruAccount", () => { + test("should call QueryNibiruAccountRequest and return the response", async () => { + const queryNibiruAccountRequest = jest + .spyOn(query.QueryNibiruAccountRequest, "fromPartial") + .mockReturnValue({} as query.QueryNibiruAccountRequest) + + const extension = setupEthExtension(mockBaseQueryClient) + const result = await extension.nibiruAccount({ + address: "", + }) + expect(queryNibiruAccountRequest).toHaveBeenCalledWith({ + address: "", + }) + expect(result).toEqual({ nibiruAccount: "Test" }) + }) + }) + + describe("validatorAccount", () => { + test("should call queryValidatorAccountRequest and return the response", async () => { + const queryValidatorAccountRequest = jest + .spyOn(query.QueryValidatorAccountRequest, "fromPartial") + .mockReturnValue({} as query.QueryValidatorAccountRequest) + + const extension = setupEthExtension(mockBaseQueryClient) + const result = await extension.validatorAccount({ + consAddress: "", + }) + expect(queryValidatorAccountRequest).toHaveBeenCalledWith({ + consAddress: "", + }) + expect(result).toEqual({ validatorAccount: "Test" }) + }) + }) + + describe("balance", () => { + test("should call QueryBalanceRequest and return the response", async () => { + const queryBalanceRequest = jest + .spyOn(query.QueryBalanceRequest, "fromPartial") + .mockReturnValue({} as query.QueryBalanceRequest) + + const extension = setupEthExtension(mockBaseQueryClient) + const result = await extension.balance({ + address: "", + }) + expect(queryBalanceRequest).toHaveBeenCalledWith({ + address: "", + }) + expect(result).toEqual({ balance: "Test" }) + }) + }) + + describe("storage", () => { + test("should call QueryStorageRequest and return the response", async () => { + const queryStorageRequest = jest + .spyOn(query.QueryStorageRequest, "fromPartial") + .mockReturnValue({} as query.QueryStorageRequest) + + const extension = setupEthExtension(mockBaseQueryClient) + const result = await extension.storage({ + address: "", + key: "", + }) + expect(queryStorageRequest).toHaveBeenCalledWith({ + address: "", + key: "", + }) + expect(result).toEqual({ storage: "Test" }) + }) + }) + + describe("code", () => { + test("should call QueryCodeRequest and return the response", async () => { + const queryCodeRequest = jest + .spyOn(query.QueryCodeRequest, "fromPartial") + .mockReturnValue({} as query.QueryCodeRequest) + + const extension = setupEthExtension(mockBaseQueryClient) + const result = await extension.code({ + address: "", + }) + expect(queryCodeRequest).toHaveBeenCalledWith({ + address: "", + }) + expect(result).toEqual({ code: "Test" }) + }) + }) + + describe("params", () => { + test("should call QueryParamsRequest and return the response", async () => { + const queryParamsRequest = jest + .spyOn(query.QueryParamsRequest, "fromPartial") + .mockReturnValue({} as query.QueryParamsRequest) + + const extension = setupEthExtension(mockBaseQueryClient) + const result = await extension.params({}) + expect(queryParamsRequest).toHaveBeenCalledWith({}) + expect(result).toEqual({ params: "Test" }) + }) + }) + + describe("ethCall", () => { + test("should call EthCallRequest and return the response", async () => { + const ethCallRequest = jest + .spyOn(query.EthCallRequest, "fromPartial") + .mockReturnValue({} as query.EthCallRequest) + + const extension = setupEthExtension(mockBaseQueryClient) + const result = await extension.ethCall({ + args: new Uint8Array(), + gasCap: new Long(0), + proposerAddress: new Uint8Array(), + chainId: new Long(0), + }) + expect(ethCallRequest).toHaveBeenCalledWith({ + args: new Uint8Array(), + gasCap: new Long(0), + proposerAddress: new Uint8Array(), + chainId: new Long(0), + }) + expect(result).toEqual({ ethCall: "Test" }) + }) + }) + + describe("estimateGas", () => { + test("should call EthCallRequest and return the response", async () => { + const ethCallRequest = jest + .spyOn(query.EthCallRequest, "fromPartial") + .mockReturnValue({} as query.EthCallRequest) + + const extension = setupEthExtension(mockBaseQueryClient) + const result = await extension.estimateGas({ + args: new Uint8Array(), + gasCap: new Long(0), + proposerAddress: new Uint8Array(), + chainId: new Long(0), + }) + expect(ethCallRequest).toHaveBeenCalledWith({ + args: new Uint8Array(), + gasCap: new Long(0), + proposerAddress: new Uint8Array(), + chainId: new Long(0), + }) + expect(result).toEqual({ estimateGas: "Test" }) + }) + }) + + describe("traceTx", () => { + test("should call QueryTraceTxRequest and return the response", async () => { + const queryTraceTxRequest = jest + .spyOn(query.QueryTraceTxRequest, "fromPartial") + .mockReturnValue({} as query.QueryTraceTxRequest) + + const extension = setupEthExtension(mockBaseQueryClient) + const result = await extension.traceTx({ + msg: MsgEthereumTx.fromPartial({}), + traceConfig: { + tracer: "", + timeout: "", + reexec: new Long(0), + disableStack: true, + disableStorage: true, + debug: true, + limit: 0, + enableMemory: true, + enableReturnData: true, + tracerJsonConfig: "", + }, + predecessors: [MsgEthereumTx.fromPartial({})], + blockNumber: new Long(0), + blockHash: "", + blockTime: new Date(1), + proposerAddress: new Uint8Array(), + chainId: new Long(0), + blockMaxGas: new Long(0), + }) + + expect(queryTraceTxRequest).toHaveBeenCalledWith({ + msg: MsgEthereumTx.fromPartial({}), + traceConfig: { + tracer: "", + timeout: "", + reexec: new Long(0), + disableStack: true, + disableStorage: true, + debug: true, + limit: 0, + enableMemory: true, + enableReturnData: true, + tracerJsonConfig: "", + }, + predecessors: [MsgEthereumTx.fromPartial({})], + blockNumber: new Long(0), + blockHash: "", + blockTime: new Date(1), + proposerAddress: new Uint8Array(), + chainId: new Long(0), + blockMaxGas: new Long(0), + }) + expect(result).toEqual({ traceTx: "Test" }) + }) + }) + + describe("traceBlock", () => { + test("should call QueryTraceBlockRequest and return the response", async () => { + const queryTraceBlockRequest = jest + .spyOn(query.QueryTraceBlockRequest, "fromPartial") + .mockReturnValue({} as query.QueryTraceBlockRequest) + + const extension = setupEthExtension(mockBaseQueryClient) + const result = await extension.traceBlock({ + txs: [MsgEthereumTx.fromPartial({})], + traceConfig: { + tracer: "", + timeout: "", + reexec: new Long(0), + disableStack: true, + disableStorage: true, + debug: true, + limit: 0, + enableMemory: true, + enableReturnData: true, + tracerJsonConfig: "", + }, + blockNumber: new Long(0), + blockHash: "", + blockTime: new Date(1), + proposerAddress: new Uint8Array(), + chainId: new Long(0), + blockMaxGas: new Long(0), + }) + expect(queryTraceBlockRequest).toHaveBeenCalledWith({ + txs: [MsgEthereumTx.fromPartial({})], + traceConfig: { + tracer: "", + timeout: "", + reexec: new Long(0), + disableStack: true, + disableStorage: true, + debug: true, + limit: 0, + enableMemory: true, + enableReturnData: true, + tracerJsonConfig: "", + }, + blockNumber: new Long(0), + blockHash: "", + blockTime: new Date(1), + proposerAddress: new Uint8Array(), + chainId: new Long(0), + blockMaxGas: new Long(0), + }) + expect(result).toEqual({ traceBlock: "Test" }) + }) + }) + + describe("baseFee", () => { + test("should call QueryBaseFeeRequest and return the response", async () => { + const queryBaseFeeRequest = jest + .spyOn(query.QueryBaseFeeRequest, "fromPartial") + .mockReturnValue({} as query.QueryBaseFeeRequest) + + const extension = setupEthExtension(mockBaseQueryClient) + const result = await extension.baseFee({}) + expect(queryBaseFeeRequest).toHaveBeenCalledWith({}) + expect(result).toEqual({ baseFee: "Test" }) + }) + }) +}) diff --git a/src/sdk/query/eth.ts b/src/sdk/query/eth.ts new file mode 100644 index 00000000..41eeb641 --- /dev/null +++ b/src/sdk/query/eth.ts @@ -0,0 +1,90 @@ +import { createProtobufRpcClient, QueryClient } from "@cosmjs/stargate" +import { + EstimateGasResponse, + EthCallRequest, + QueryBalanceRequest, + QueryBalanceResponse, + QueryBaseFeeRequest, + QueryBaseFeeResponse, + QueryClientImpl, + QueryCodeRequest, + QueryCodeResponse, + QueryEthAccountRequest, + QueryEthAccountResponse, + QueryNibiruAccountRequest, + QueryNibiruAccountResponse, + QueryParamsRequest, + QueryParamsResponse, + QueryStorageRequest, + QueryStorageResponse, + QueryTraceBlockRequest, + QueryTraceBlockResponse, + QueryTraceTxRequest, + QueryTraceTxResponse, + QueryValidatorAccountRequest, + QueryValidatorAccountResponse, +} from "../../protojs/eth/evm/v1/query" +import { MsgEthereumTxResponse } from "../../protojs/eth/evm/v1/tx" + +export interface EthExtension { + ethAccount: (args: QueryEthAccountRequest) => Promise + nibiruAccount: ( + args: QueryNibiruAccountRequest + ) => Promise + validatorAccount: ( + args: QueryValidatorAccountRequest + ) => Promise + balance: (args: QueryBalanceRequest) => Promise + storage: (args: QueryStorageRequest) => Promise + code: (args: QueryCodeRequest) => Promise + params: (args: QueryParamsRequest) => Promise + ethCall: (args: EthCallRequest) => Promise + estimateGas: (args: EthCallRequest) => Promise + traceTx: (args: QueryTraceTxRequest) => Promise + traceBlock: (args: QueryTraceBlockRequest) => Promise + baseFee: (args: QueryBaseFeeRequest) => Promise +} + +export const setupEthExtension = (base: QueryClient): EthExtension => { + const queryService = new QueryClientImpl(createProtobufRpcClient(base)) + + return { + ethAccount: async (args: QueryEthAccountRequest) => + queryService.EthAccount(QueryEthAccountRequest.fromPartial(args)), + + nibiruAccount: async (args: QueryNibiruAccountRequest) => + queryService.NibiruAccount(QueryNibiruAccountRequest.fromPartial(args)), + + validatorAccount: async (args: QueryValidatorAccountRequest) => + queryService.ValidatorAccount( + QueryValidatorAccountRequest.fromPartial(args) + ), + + balance: async (args: QueryBalanceRequest) => + queryService.Balance(QueryBalanceRequest.fromPartial(args)), + + storage: async (args: QueryStorageRequest) => + queryService.Storage(QueryStorageRequest.fromPartial(args)), + + code: async (args: QueryCodeRequest) => + queryService.Code(QueryCodeRequest.fromPartial(args)), + + params: async (args: QueryParamsRequest) => + queryService.Params(QueryParamsRequest.fromPartial(args)), + + ethCall: async (args: EthCallRequest) => + queryService.EthCall(EthCallRequest.fromPartial(args)), + + estimateGas: async (args: EthCallRequest) => + queryService.EstimateGas(EthCallRequest.fromPartial(args)), + + traceTx: async (args: QueryTraceTxRequest) => + queryService.TraceTx(QueryTraceTxRequest.fromPartial(args)), + + traceBlock: async (args: QueryTraceBlockRequest) => + queryService.TraceBlock(QueryTraceBlockRequest.fromPartial(args)), + + baseFee: async (args: QueryBaseFeeRequest) => + queryService.BaseFee(QueryBaseFeeRequest.fromPartial(args)), + } +} diff --git a/src/sdk/query/index.ts b/src/sdk/query/index.ts index 705bcb8c..027ffb7d 100644 --- a/src/sdk/query/index.ts +++ b/src/sdk/query/index.ts @@ -4,6 +4,7 @@ export * from "./devgas" export * from "./epochs" +export * from "./eth" export * from "./inflation" export * from "./oracle" export * from "./query" diff --git a/src/sdk/query/inflation.test.ts b/src/sdk/query/inflation.test.ts index 514b489a..8706d44d 100644 --- a/src/sdk/query/inflation.test.ts +++ b/src/sdk/query/inflation.test.ts @@ -24,16 +24,16 @@ describe("setupInflationExtension", () => { }), } as unknown as query.QueryClientImpl) - test("should setup inflation extension correctly", () => { + test("should setup extension correctly", () => { const extension = setupInflationExtension(mockBaseQueryClient) - expect(extension.inflation).toBeDefined() - expect(extension.inflation.period).toBeInstanceOf(Function) - expect(extension.inflation.epochMintProvision).toBeInstanceOf(Function) - expect(extension.inflation.skippedEpochs).toBeInstanceOf(Function) - expect(extension.inflation.circulatingSupply).toBeInstanceOf(Function) - expect(extension.inflation.inflationRate).toBeInstanceOf(Function) - expect(extension.inflation.params).toBeInstanceOf(Function) + expect(extension).toBeDefined() + expect(extension.period).toBeInstanceOf(Function) + expect(extension.epochMintProvision).toBeInstanceOf(Function) + expect(extension.skippedEpochs).toBeInstanceOf(Function) + expect(extension.circulatingSupply).toBeInstanceOf(Function) + expect(extension.inflationRate).toBeInstanceOf(Function) + expect(extension.params).toBeInstanceOf(Function) }) describe("inflation.period", () => { @@ -43,7 +43,7 @@ describe("setupInflationExtension", () => { .mockReturnValue({} as query.QueryPeriodRequest) const extension = setupInflationExtension(mockBaseQueryClient) - const result = await extension.inflation.period() + const result = await extension.period() expect(queryPeriodRequest).toHaveBeenCalledWith({}) expect(result).toEqual({ period: "Test Period" }) @@ -57,7 +57,7 @@ describe("setupInflationExtension", () => { .mockReturnValue({} as query.QueryEpochMintProvisionRequest) const extension = setupInflationExtension(mockBaseQueryClient) - const result = await extension.inflation.epochMintProvision() + const result = await extension.epochMintProvision() expect(queryEpochMintProvisionRequest).toHaveBeenCalledWith({}) expect(result).toEqual({ @@ -73,7 +73,7 @@ describe("setupInflationExtension", () => { .mockReturnValue({} as query.QuerySkippedEpochsRequest) const extension = setupInflationExtension(mockBaseQueryClient) - const result = await extension.inflation.skippedEpochs() + const result = await extension.skippedEpochs() expect(querySkippedEpochsRequest).toHaveBeenCalledWith({}) expect(result).toEqual({ skippedEpochs: "Test Skipped Epochs" }) @@ -87,7 +87,7 @@ describe("setupInflationExtension", () => { .mockReturnValue({} as query.QueryCirculatingSupplyRequest) const extension = setupInflationExtension(mockBaseQueryClient) - const result = await extension.inflation.circulatingSupply() + const result = await extension.circulatingSupply() expect(queryCirculatingSupplyRequest).toHaveBeenCalledWith({}) expect(result).toEqual({ circulatingSupply: "Test Circulating Supply" }) @@ -101,7 +101,7 @@ describe("setupInflationExtension", () => { .mockReturnValue({} as query.QueryInflationRateRequest) const extension = setupInflationExtension(mockBaseQueryClient) - const result = await extension.inflation.inflationRate() + const result = await extension.inflationRate() expect(queryInflationRateRequest).toHaveBeenCalledWith({}) expect(result).toEqual({ inflationRate: "Test Inflation Rate" }) @@ -115,7 +115,7 @@ describe("setupInflationExtension", () => { .mockReturnValue({} as query.QueryParamsRequest) const extension = setupInflationExtension(mockBaseQueryClient) - const result = await extension.inflation.params() + const result = await extension.params() expect(queryParamsRequest).toHaveBeenCalledWith({}) expect(result).toEqual({ params: "Test Params" }) diff --git a/src/sdk/query/inflation.ts b/src/sdk/query/inflation.ts index 7563d778..e3beb681 100644 --- a/src/sdk/query/inflation.ts +++ b/src/sdk/query/inflation.ts @@ -16,14 +16,12 @@ import { } from "../../protojs/nibiru/inflation/v1/query" export interface InflationExtension { - readonly inflation: Readonly<{ - period: () => Promise - epochMintProvision: () => Promise - skippedEpochs: () => Promise - circulatingSupply: () => Promise - inflationRate: () => Promise - params: () => Promise - }> + period: () => Promise + epochMintProvision: () => Promise + skippedEpochs: () => Promise + circulatingSupply: () => Promise + inflationRate: () => Promise + params: () => Promise } export const setupInflationExtension = ( @@ -32,28 +30,24 @@ export const setupInflationExtension = ( const queryService = new QueryClientImpl(createProtobufRpcClient(base)) return { - inflation: { - circulatingSupply: async () => - queryService.CirculatingSupply( - QueryCirculatingSupplyRequest.fromPartial({}) - ), + circulatingSupply: async () => + queryService.CirculatingSupply( + QueryCirculatingSupplyRequest.fromPartial({}) + ), - epochMintProvision: async () => - queryService.EpochMintProvision( - QueryEpochMintProvisionRequest.fromPartial({}) - ), + epochMintProvision: async () => + queryService.EpochMintProvision( + QueryEpochMintProvisionRequest.fromPartial({}) + ), - inflationRate: async () => - queryService.InflationRate(QueryInflationRateRequest.fromPartial({})), + inflationRate: async () => + queryService.InflationRate(QueryInflationRateRequest.fromPartial({})), - params: async () => - queryService.Params(QueryParamsRequest.fromPartial({})), + params: async () => queryService.Params(QueryParamsRequest.fromPartial({})), - period: async () => - queryService.Period(QueryPeriodRequest.fromPartial({})), + period: async () => queryService.Period(QueryPeriodRequest.fromPartial({})), - skippedEpochs: async () => - queryService.SkippedEpochs(QuerySkippedEpochsRequest.fromPartial({})), - }, + skippedEpochs: async () => + queryService.SkippedEpochs(QuerySkippedEpochsRequest.fromPartial({})), } } diff --git a/src/sdk/query/oracle.test.ts b/src/sdk/query/oracle.test.ts index b59c11b2..064ac892 100644 --- a/src/sdk/query/oracle.test.ts +++ b/src/sdk/query/oracle.test.ts @@ -1,7 +1,7 @@ import Long from "long" import { QueryClient } from "@cosmjs/stargate" import * as query from "../../protojs/nibiru/oracle/v1/query" -import { fromSdkDec, setupOracleExtension, toSdkDec } from ".." +import { fromSdkDec, newExchangeRatesMap, setupOracleExtension } from ".." describe("setupOracleExtension", () => { const mockBaseQueryClient = {} as QueryClient @@ -57,18 +57,19 @@ describe("setupOracleExtension", () => { test("should setup oracle extension correctly", () => { const extension = setupOracleExtension(mockBaseQueryClient) - expect(extension.oracle).toBeDefined() - expect(extension.oracle.actives).toBeInstanceOf(Function) - expect(extension.oracle.aggregatePrevote).toBeInstanceOf(Function) - expect(extension.oracle.aggregatePrevotes).toBeInstanceOf(Function) - expect(extension.oracle.aggregateVote).toBeInstanceOf(Function) - expect(extension.oracle.aggregateVotes).toBeInstanceOf(Function) - expect(extension.oracle.exchangeRate).toBeInstanceOf(Function) - expect(extension.oracle.exchangeRates).toBeInstanceOf(Function) - expect(extension.oracle.feederDelegation).toBeInstanceOf(Function) - expect(extension.oracle.missCounter).toBeInstanceOf(Function) - expect(extension.oracle.params).toBeInstanceOf(Function) - expect(extension.oracle.voteTargets).toBeInstanceOf(Function) + expect(extension).toBeDefined() + expect(extension.actives).toBeInstanceOf(Function) + expect(extension.aggregatePrevote).toBeInstanceOf(Function) + expect(extension.aggregatePrevotes).toBeInstanceOf(Function) + expect(extension.aggregateVote).toBeInstanceOf(Function) + expect(extension.aggregateVotes).toBeInstanceOf(Function) + expect(extension.exchangeRate).toBeInstanceOf(Function) + expect(extension.exchangeRates).toBeInstanceOf(Function) + expect(extension.feederDelegation).toBeInstanceOf(Function) + expect(extension.missCounter).toBeInstanceOf(Function) + expect(extension.params).toBeInstanceOf(Function) + expect(extension.voteTargets).toBeInstanceOf(Function) + expect(extension.exchangeRateTwap).toBeInstanceOf(Function) }) jest.spyOn(query, "QueryClientImpl").mockReturnValue({ @@ -80,6 +81,7 @@ describe("setupOracleExtension", () => { AggregateVote: jest.fn().mockResolvedValue(mockAggregateVoteResponse), AggregateVotes: jest.fn().mockResolvedValue(mockAggregateVotesResponse), ExchangeRate: jest.fn().mockResolvedValue(mockExchangeRateResponse), + ExchangeRateTwap: jest.fn().mockResolvedValue(mockExchangeRateResponse), ExchangeRates: jest.fn().mockResolvedValue(mockExchangeRatesResponse), FeederDelegation: jest.fn().mockResolvedValue(mockFeederDelegationResponse), MissCounter: jest.fn().mockResolvedValue(mockMissCounterResponse), @@ -94,7 +96,7 @@ describe("setupOracleExtension", () => { .mockReturnValue({} as query.QueryActivesRequest) const extension = setupOracleExtension(mockBaseQueryClient) - const result = await extension.oracle.actives() + const result = await extension.actives() expect(queryActiveRequest).toHaveBeenCalledWith({}) expect(result).toEqual(mockActivesResponse) @@ -108,7 +110,7 @@ describe("setupOracleExtension", () => { .mockReturnValue({} as query.QueryAggregatePrevoteRequest) const extension = setupOracleExtension(mockBaseQueryClient) - const result = await extension.oracle.aggregatePrevote({ + const result = await extension.aggregatePrevote({ validatorAddr: "1234567", }) @@ -126,7 +128,7 @@ describe("setupOracleExtension", () => { .mockReturnValue({} as query.QueryAggregatePrevotesRequest) const extension = setupOracleExtension(mockBaseQueryClient) - const result = await extension.oracle.aggregatePrevotes() + const result = await extension.aggregatePrevotes() expect(queryAggregatePrevotesRequest).toHaveBeenCalledWith({}) expect(result).toEqual(mockAggregatePrevotesResponse) @@ -140,7 +142,7 @@ describe("setupOracleExtension", () => { .mockReturnValue({} as query.QueryAggregateVoteRequest) const extension = setupOracleExtension(mockBaseQueryClient) - const result = await extension.oracle.aggregateVote({ + const result = await extension.aggregateVote({ validatorAddr: "1234567", }) @@ -158,7 +160,7 @@ describe("setupOracleExtension", () => { .mockReturnValue({} as query.QueryAggregateVotesRequest) const extension = setupOracleExtension(mockBaseQueryClient) - const result = await extension.oracle.aggregateVotes() + const result = await extension.aggregateVotes() expect(queryAggregateVotesRequest).toHaveBeenCalledWith({}) expect(result).toEqual(mockAggregateVotesResponse) @@ -172,7 +174,7 @@ describe("setupOracleExtension", () => { .mockReturnValue({} as query.QueryExchangeRateRequest) const extension = setupOracleExtension(mockBaseQueryClient) - const result = await extension.oracle.exchangeRate({ pair: "PAIR" }) + const result = await extension.exchangeRate({ pair: "PAIR" }) expect(queryExchangeRateRequest).toHaveBeenCalledWith({ pair: "PAIR" }) expect(fromSdkDec(result.exchangeRate)).toEqual(mockExchangeRate) @@ -186,7 +188,7 @@ describe("setupOracleExtension", () => { .mockReturnValue({} as query.QueryExchangeRatesRequest) const extension = setupOracleExtension(mockBaseQueryClient) - const result = await extension.oracle.exchangeRates() + const result = await extension.exchangeRates() expect(queryExchangeRatesRequest).toHaveBeenCalledWith({}) expect(result.exchangeRates[0]).toEqual({ @@ -203,7 +205,7 @@ describe("setupOracleExtension", () => { .mockReturnValue({} as query.QueryFeederDelegationRequest) const extension = setupOracleExtension(mockBaseQueryClient) - const result = await extension.oracle.feederDelegation({ + const result = await extension.feederDelegation({ validatorAddr: "oracle", }) @@ -221,7 +223,7 @@ describe("setupOracleExtension", () => { .mockReturnValue({} as query.QueryMissCounterRequest) const extension = setupOracleExtension(mockBaseQueryClient) - const result = await extension.oracle.missCounter({ + const result = await extension.missCounter({ validatorAddr: "oracle", }) @@ -239,7 +241,7 @@ describe("setupOracleExtension", () => { .mockReturnValue({} as query.QueryParamsRequest) const extension = setupOracleExtension(mockBaseQueryClient) - const result = await extension.oracle.params() + const result = await extension.params() expect(queryParamsRequest).toHaveBeenCalledWith({}) expect(result).toEqual(mockParamsResponse) @@ -253,10 +255,31 @@ describe("setupOracleExtension", () => { .mockReturnValue({} as query.QueryVoteTargetsRequest) const extension = setupOracleExtension(mockBaseQueryClient) - const result = await extension.oracle.voteTargets() + const result = await extension.voteTargets() expect(queryVoteTargetsRequest).toHaveBeenCalledWith({}) expect(result).toEqual(mockVoteTargetsResponse) }) }) + + describe("oracle.exchangeRateTwap", () => { + test("should call QueryExchangeRateRequest and return the response", async () => { + const queryExchangeRateRequest = jest + .spyOn(query.QueryExchangeRateRequest, "fromPartial") + .mockReturnValue({} as query.QueryExchangeRateRequest) + + const extension = setupOracleExtension(mockBaseQueryClient) + const result = await extension.exchangeRateTwap({ pair: "PAIR" }) + + expect(queryExchangeRateRequest).toHaveBeenCalledWith({ pair: "PAIR" }) + expect(result).toEqual(mockExchangeRateResponse) + }) + }) + + describe("newExchangeRatesMap ", () => { + test("should call method and return a response", async () => { + const test = newExchangeRatesMap(mockExchangeRatesResponse) + expect(test).toEqual({ USD: 1.32e-16 }) + }) + }) }) diff --git a/src/sdk/query/oracle.ts b/src/sdk/query/oracle.ts index c86cadaa..9f1b2d2e 100644 --- a/src/sdk/query/oracle.ts +++ b/src/sdk/query/oracle.ts @@ -30,57 +30,55 @@ import { import { fromSdkDec } from ".." export interface OracleExtension { - oracle: Readonly<{ - /** actives: Query the list of active/whitelisted pairs for the oracle module. */ - actives: () => Promise - /** aggregatePrevote: TODO Query outstanding oracle aggregate prevotes. */ - aggregatePrevote: ( - body: QueryAggregatePrevoteRequest - ) => Promise - /** aggregatePrevotes: TODO Query all aggregate prevotes. */ - aggregatePrevotes: () => Promise - - /** aggregateVote: TODO Query outstanding oracle aggregate vote. */ - aggregateVote: ( - body: QueryAggregateVoteRequest - ) => Promise - - /** aggregateVotes: TODO Query all aggregate votes. */ - aggregateVotes: () => Promise - - /** exchangeRate: Returns the current exchange rate that validators voted - * for on the given 'pair'. */ - exchangeRate: ( - body: QueryExchangeRateRequest - ) => Promise - - /** exchangeRate: Returns the current exchange rate that validators voted - * for on the given 'pair'. */ - exchangeRateTwap: ( - body: QueryExchangeRateRequest - ) => Promise - - /** TODO Query all exchange rates. */ - exchangeRates: () => Promise - - /** feederDelegation: Query for the feeder account to which the validator has - * delegated the authority to vote on exchange rotes prices. */ - feederDelegation: ( - body: QueryFeederDelegationRequest - ) => Promise - - /** TODO Query the miss count of a validator */ - missCounter: ( - body: QueryMissCounterRequest - ) => Promise - - /** params: Returns the module parameters for the x/oracle module. */ - params: () => Promise - - /** voteTargets: Returns current vote targets, the list of pairs that - * everyone should vote on in the during the vote period. */ - voteTargets: () => Promise - }> + /** actives: Query the list of active/whitelisted pairs for the oracle module. */ + actives: () => Promise + /** aggregatePrevote: TODO Query outstanding oracle aggregate prevotes. */ + aggregatePrevote: ( + body: QueryAggregatePrevoteRequest + ) => Promise + /** aggregatePrevotes: TODO Query all aggregate prevotes. */ + aggregatePrevotes: () => Promise + + /** aggregateVote: TODO Query outstanding oracle aggregate vote. */ + aggregateVote: ( + body: QueryAggregateVoteRequest + ) => Promise + + /** aggregateVotes: TODO Query all aggregate votes. */ + aggregateVotes: () => Promise + + /** exchangeRate: Returns the current exchange rate that validators voted + * for on the given 'pair'. */ + exchangeRate: ( + body: QueryExchangeRateRequest + ) => Promise + + /** exchangeRate: Returns the current exchange rate that validators voted + * for on the given 'pair'. */ + exchangeRateTwap: ( + body: QueryExchangeRateRequest + ) => Promise + + /** TODO Query all exchange rates. */ + exchangeRates: () => Promise + + /** feederDelegation: Query for the feeder account to which the validator has + * delegated the authority to vote on exchange rotes prices. */ + feederDelegation: ( + body: QueryFeederDelegationRequest + ) => Promise + + /** TODO Query the miss count of a validator */ + missCounter: ( + body: QueryMissCounterRequest + ) => Promise + + /** params: Returns the module parameters for the x/oracle module. */ + params: () => Promise + + /** voteTargets: Returns current vote targets, the list of pairs that + * everyone should vote on in the during the vote period. */ + voteTargets: () => Promise } export interface ExchangeRatesMap { @@ -102,50 +100,45 @@ export const setupOracleExtension = (base: QueryClient): OracleExtension => { ) return { - oracle: { - actives: async () => - queryService.Actives(QueryActivesRequest.fromPartial({})), + actives: async () => + queryService.Actives(QueryActivesRequest.fromPartial({})), - aggregatePrevote: async (body: QueryAggregatePrevoteRequest) => - queryService.AggregatePrevote( - QueryAggregatePrevoteRequest.fromPartial(body) - ), + aggregatePrevote: async (body: QueryAggregatePrevoteRequest) => + queryService.AggregatePrevote( + QueryAggregatePrevoteRequest.fromPartial(body) + ), - aggregatePrevotes: async () => - queryService.AggregatePrevotes( - QueryAggregatePrevotesRequest.fromPartial({}) - ), + aggregatePrevotes: async () => + queryService.AggregatePrevotes( + QueryAggregatePrevotesRequest.fromPartial({}) + ), - aggregateVote: async (body: QueryAggregateVoteRequest) => - queryService.AggregateVote(QueryAggregateVoteRequest.fromPartial(body)), + aggregateVote: async (body: QueryAggregateVoteRequest) => + queryService.AggregateVote(QueryAggregateVoteRequest.fromPartial(body)), - aggregateVotes: async () => - queryService.AggregateVotes(QueryAggregateVotesRequest.fromPartial({})), + aggregateVotes: async () => + queryService.AggregateVotes(QueryAggregateVotesRequest.fromPartial({})), - exchangeRate: async (body: QueryExchangeRateRequest) => - queryService.ExchangeRate(QueryExchangeRateRequest.fromPartial(body)), + exchangeRate: async (body: QueryExchangeRateRequest) => + queryService.ExchangeRate(QueryExchangeRateRequest.fromPartial(body)), - exchangeRateTwap: async (body: QueryExchangeRateRequest) => - queryService.ExchangeRateTwap( - QueryExchangeRateRequest.fromPartial(body) - ), + exchangeRateTwap: async (body: QueryExchangeRateRequest) => + queryService.ExchangeRateTwap(QueryExchangeRateRequest.fromPartial(body)), - exchangeRates: async () => - queryService.ExchangeRates(QueryExchangeRatesRequest.fromPartial({})), + exchangeRates: async () => + queryService.ExchangeRates(QueryExchangeRatesRequest.fromPartial({})), - feederDelegation: async (body: QueryFeederDelegationRequest) => - queryService.FeederDelegation( - QueryFeederDelegationRequest.fromPartial(body) - ), + feederDelegation: async (body: QueryFeederDelegationRequest) => + queryService.FeederDelegation( + QueryFeederDelegationRequest.fromPartial(body) + ), - missCounter: async (body: QueryMissCounterRequest) => - queryService.MissCounter(QueryMissCounterRequest.fromPartial(body)), + missCounter: async (body: QueryMissCounterRequest) => + queryService.MissCounter(QueryMissCounterRequest.fromPartial(body)), - params: async () => - queryService.Params(QueryParamsRequest.fromPartial({})), + params: async () => queryService.Params(QueryParamsRequest.fromPartial({})), - voteTargets: async () => - queryService.VoteTargets(QueryVoteTargetsRequest.fromPartial({})), - }, + voteTargets: async () => + queryService.VoteTargets(QueryVoteTargetsRequest.fromPartial({})), } } diff --git a/src/sdk/query/query.test.ts b/src/sdk/query/query.test.ts index 65cce42c..1154b82e 100644 --- a/src/sdk/query/query.test.ts +++ b/src/sdk/query/query.test.ts @@ -1,5 +1,5 @@ import fs from "fs" -import { Block, coins } from "@cosmjs/stargate" +import { Block, coins, QueryClient } from "@cosmjs/stargate" import Long from "long" import { fetch } from "cross-fetch" import { @@ -12,6 +12,20 @@ import { assertExpectedError, newSignerFromMnemonic, NibiruTxClient, + setupNibiruExtension, + setupDevgasExtension, + setupDevgasMsgExtension, + setupEpochsExtension, + setupEthExtension, + setupEthMsgExtension, + setupInflationExtension, + setupInflationMsgExtension, + setupOracleExtension, + setupOracleMsgExtension, + setupSudoExtension, + setupSudoMsgExtension, + setupTokenFactoryExtension, + setupTokenFactoryMsgExtension, } from ".." interface BlockResp { @@ -52,7 +66,7 @@ describe("x/bank queries", () => { describe("x/oracle queries", () => { test("query active oracles", async () => { const querier = await NibiruQuerier.connect(Localnet.endptTm) - const { actives } = await querier.nibiruExtensions.oracle.actives() + const { actives } = await querier.nibiruExtensions.query.oracle.actives() if (actives.length > 0) { const pair = actives[0] expect(pair).toContain(":") @@ -62,14 +76,15 @@ describe("x/oracle queries", () => { test("query oracle params", async () => { const querier = await NibiruQuerier.connect(Localnet.endptTm) const { params: moduleParams } = - await querier.nibiruExtensions.oracle.params() + await querier.nibiruExtensions.query.oracle.params() expect(moduleParams).toBeDefined() expect(moduleParams?.whitelist.length).toBeGreaterThan(0) }) test("query exchange rates", async () => { const querier = await NibiruQuerier.connect(Localnet.endptTm) - const exhangeRateMap = await querier.nibiruExtensions.oracle.exchangeRates() + const exhangeRateMap = + await querier.nibiruExtensions.query.oracle.exchangeRates() if (Object.keys(exhangeRateMap).length > 0) { for (const pair in exhangeRateMap.exchangeRates) { expect(pair).toBeDefined() @@ -87,13 +102,13 @@ describe("x/epochs queries", () => { "query epochs info and current epoch", async () => { const querier = await NibiruQuerier.connect(Localnet.endptTm) - const infoResp = await querier.nibiruExtensions.epochs.epochsInfos() + const infoResp = await querier.nibiruExtensions.query.epochs.epochsInfos() expect(infoResp).toHaveProperty("epochs") expect(infoResp.epochs.length).toBeGreaterThan(0) const epochId = infoResp.epochs[0].identifier const currentEpochResp = - await querier.nibiruExtensions.epochs.currentEpoch({ + await querier.nibiruExtensions.query.epochs.currentEpoch({ identifier: epochId, }) expect(Long.isLong(currentEpochResp.currentEpoch)).toBeTruthy() @@ -357,4 +372,12 @@ describe("NibiruQuerier", () => { expect(result.isErr()).toEqual(true) }) + + test("setupNibiruExtension ", async () => { + const mockBaseQueryClient = {} as QueryClient + const extension = setupNibiruExtension(mockBaseQueryClient) + + expect(extension.msg).toBeTruthy() + expect(extension.query).toBeTruthy() + }) }) diff --git a/src/sdk/query/query.ts b/src/sdk/query/query.ts index 1b8aff5c..6c083a51 100644 --- a/src/sdk/query/query.ts +++ b/src/sdk/query/query.ts @@ -12,6 +12,7 @@ import { StargateClientOptions, StakingExtension, setupStakingExtension, + QueryClient, } from "@cosmjs/stargate" import { Tendermint37Client } from "@cosmjs/tendermint-rpc" import { @@ -44,30 +45,64 @@ import { setupOracleMsgExtension, setupSudoMsgExtension, setupTokenFactoryMsgExtension, -} from ".." -import { + EthExtension, + EthMsgExtension, + setupEthExtension, + setupEthMsgExtension, TokenFactoryExtension, setupTokenFactoryExtension, -} from "./tokenfactory" +} from ".." + +export interface NibiruExtension { + readonly msg: Readonly<{ + ethMsg: EthMsgExtension + tokenFactoryMsg: TokenFactoryMsgExtension + sudoMsg: SudoMsgExtension + inflationMsg: InflationMsgExtension + oracleMsg: OracleMsgExtension + devgasMsg: DevgasMsgExtension + }> + readonly query: Readonly<{ + devgas: DevgasExtension + epochs: EpochsExtension + eth: EthExtension + inflation: InflationExtension + oracle: OracleExtension + sudo: SudoExtension + tokenFactory: TokenFactoryExtension + }> +} + +export const setupNibiruExtension = (base: QueryClient): NibiruExtension => { + return { + msg: { + ethMsg: setupEthMsgExtension(base), + tokenFactoryMsg: setupTokenFactoryMsgExtension(base), + sudoMsg: setupSudoMsgExtension(base), + inflationMsg: setupInflationMsgExtension(base), + oracleMsg: setupOracleMsgExtension(base), + devgasMsg: setupDevgasMsgExtension(base), + }, + query: { + devgas: setupDevgasExtension(base), + epochs: setupEpochsExtension(base), + eth: setupEthExtension(base), + inflation: setupInflationExtension(base), + oracle: setupOracleExtension(base), + sudo: setupSudoExtension(base), + tokenFactory: setupTokenFactoryExtension(base), + }, + } +} export type NibiruExtensions = StargateQueryClient & - SudoExtension & - InflationExtension & - OracleExtension & - EpochsExtension & - DevgasExtension & DistributionExtension & GovExtension & StakingExtension & IbcExtension & WasmExtension & AuthExtension & - TokenFactoryExtension & - DevgasMsgExtension & - OracleMsgExtension & - InflationMsgExtension & - SudoMsgExtension & - TokenFactoryMsgExtension + NibiruExtension /** Querier for a Nibiru network. * @example @@ -100,23 +135,13 @@ export class NibiruQuerier extends StargateClient { this.tm = tmClient this.nibiruExtensions = StargateQueryClient.withExtensions( tmClient, - setupDevgasExtension, - setupEpochsExtension, - setupOracleExtension, - setupSudoExtension, - setupInflationExtension, setupDistributionExtension, setupGovExtension, setupStakingExtension, setupIbcExtension, setupWasmExtension, setupAuthExtension, - setupTokenFactoryExtension, - setupDevgasMsgExtension, - setupInflationMsgExtension, - setupOracleMsgExtension, - setupSudoMsgExtension, - setupTokenFactoryMsgExtension + setupNibiruExtension ) } diff --git a/src/sdk/query/sudo.test.ts b/src/sdk/query/sudo.test.ts index 5031d6b0..42194254 100644 --- a/src/sdk/query/sudo.test.ts +++ b/src/sdk/query/sudo.test.ts @@ -14,8 +14,8 @@ describe("setupSudoExtension", () => { test("should setup sudo extension correctly", () => { const extension = setupSudoExtension(mockBaseQueryClient) - expect(extension.sudo).toBeDefined() - expect(extension.sudo.querySudoers).toBeInstanceOf(Function) + expect(extension).toBeDefined() + expect(extension.querySudoers).toBeInstanceOf(Function) }) describe("sudo.querySudoers", () => { @@ -25,7 +25,7 @@ describe("setupSudoExtension", () => { .mockReturnValue({} as query.QuerySudoersRequest) const extension = setupSudoExtension(mockBaseQueryClient) - const result = await extension.sudo.querySudoers() + const result = await extension.querySudoers() expect(querySudoersRequest).toHaveBeenCalledWith({}) expect(result).toEqual({ sudoers: ["Test Sudoer 1", "Test Sudoer 2"] }) diff --git a/src/sdk/query/sudo.ts b/src/sdk/query/sudo.ts index 6af62b1f..0effa841 100644 --- a/src/sdk/query/sudo.ts +++ b/src/sdk/query/sudo.ts @@ -6,18 +6,14 @@ import { } from "../../protojs/nibiru/sudo/v1/query" export interface SudoExtension { - readonly sudo: Readonly<{ - querySudoers: () => Promise - }> + querySudoers: () => Promise } export const setupSudoExtension = (base: QueryClient): SudoExtension => { const queryService = new QueryClientImpl(createProtobufRpcClient(base)) return { - sudo: { - querySudoers: async () => - queryService.QuerySudoers(QuerySudoersRequest.fromPartial({})), - }, + querySudoers: async () => + queryService.QuerySudoers(QuerySudoersRequest.fromPartial({})), } } diff --git a/src/sdk/query/tokenfactory.test.ts b/src/sdk/query/tokenfactory.test.ts new file mode 100644 index 00000000..68300655 --- /dev/null +++ b/src/sdk/query/tokenfactory.test.ts @@ -0,0 +1,60 @@ +import { QueryClient } from "@cosmjs/stargate" +import * as query from "../../protojs/nibiru/tokenfactory/v1/query" +import { setupTokenFactoryExtension } from "." + +describe("setupTokenFactoryExtension", () => { + const mockBaseQueryClient = {} as QueryClient + + jest.spyOn(query, "QueryClientImpl").mockReturnValue({ + DenomInfo: jest.fn().mockResolvedValue({ denomInfo: ["Test 1", "Test 2"] }), + Denoms: jest.fn().mockResolvedValue({ denoms: ["Test 1", "Test 2"] }), + Params: jest.fn().mockResolvedValue({ params: ["Test 1", "Test 2"] }), + } as unknown as query.QueryClientImpl) + + test("should setup extension correctly", () => { + const extension = setupTokenFactoryExtension(mockBaseQueryClient) + + expect(extension).toBeDefined() + expect(extension.denomInfo).toBeInstanceOf(Function) + expect(extension.denoms).toBeInstanceOf(Function) + expect(extension.params).toBeInstanceOf(Function) + }) + + describe("tokenFactory.denomInfo", () => { + test("should call QueryDenomInfoRequest and return the response", async () => { + const queryDenomInfoRequest = jest + .spyOn(query.QueryDenomInfoRequest, "fromPartial") + .mockReturnValue({} as query.QueryDenomInfoRequest) + + const extension = setupTokenFactoryExtension(mockBaseQueryClient) + const result = await extension.denomInfo({ denom: "PAIR" }) + + expect(queryDenomInfoRequest).toHaveBeenCalledWith({ denom: "PAIR" }) + expect(result).toEqual({ denomInfo: ["Test 1", "Test 2"] }) + }) + }) + + test("should call QueryDenomsRequest and return the response", async () => { + const queryDenomsRequest = jest + .spyOn(query.QueryDenomsRequest, "fromPartial") + .mockReturnValue({} as query.QueryDenomsRequest) + + const extension = setupTokenFactoryExtension(mockBaseQueryClient) + const result = await extension.denoms({ creator: "" }) + + expect(queryDenomsRequest).toHaveBeenCalledWith({ creator: "" }) + expect(result).toEqual({ denoms: ["Test 1", "Test 2"] }) + }) + + test("should call QueryParamsRequest and return the response", async () => { + const queryParamsRequest = jest + .spyOn(query.QueryParamsRequest, "fromPartial") + .mockReturnValue({} as query.QueryParamsRequest) + + const extension = setupTokenFactoryExtension(mockBaseQueryClient) + const result = await extension.params({}) + + expect(queryParamsRequest).toHaveBeenCalledWith({}) + expect(result).toEqual({ params: ["Test 1", "Test 2"] }) + }) +}) diff --git a/src/sdk/query/tokenfactory.ts b/src/sdk/query/tokenfactory.ts index be2f833f..fd96e97a 100644 --- a/src/sdk/query/tokenfactory.ts +++ b/src/sdk/query/tokenfactory.ts @@ -10,11 +10,9 @@ import { } from "../../protojs/nibiru/tokenfactory/v1/query" export interface TokenFactoryExtension { - readonly tokenFactory: Readonly<{ - denomInfo: (body: QueryDenomInfoRequest) => Promise - denoms: (body: QueryDenomsRequest) => Promise - params: (body: QueryParamsRequest) => Promise - }> + denomInfo: (body: QueryDenomInfoRequest) => Promise + denoms: (body: QueryDenomsRequest) => Promise + params: (body: QueryParamsRequest) => Promise } export const setupTokenFactoryExtension = ( @@ -23,15 +21,13 @@ export const setupTokenFactoryExtension = ( const queryService = new QueryClientImpl(createProtobufRpcClient(base)) return { - tokenFactory: { - denomInfo: async (body: QueryDenomInfoRequest) => - queryService.DenomInfo(QueryDenomInfoRequest.fromPartial(body)), + denomInfo: async (body: QueryDenomInfoRequest) => + queryService.DenomInfo(QueryDenomInfoRequest.fromPartial(body)), - denoms: async (body: QueryDenomsRequest) => - queryService.Denoms(QueryDenomsRequest.fromPartial(body)), + denoms: async (body: QueryDenomsRequest) => + queryService.Denoms(QueryDenomsRequest.fromPartial(body)), - params: async () => - queryService.Params(QueryParamsRequest.fromPartial({})), - }, + params: async (body: QueryParamsRequest) => + queryService.Params(QueryParamsRequest.fromPartial(body)), } } diff --git a/src/sdk/stableswap/index.ts b/src/sdk/stableswap/index.ts deleted file mode 100644 index a0645cc4..00000000 --- a/src/sdk/stableswap/index.ts +++ /dev/null @@ -1,5 +0,0 @@ -/** - * @file Automatically generated by barrelsby. - */ - -export * from "./stableswap" diff --git a/src/sdk/tx/txClient.ts b/src/sdk/tx/txClient.ts index 200e9c88..38b718b0 100644 --- a/src/sdk/tx/txClient.ts +++ b/src/sdk/tx/txClient.ts @@ -17,20 +17,7 @@ import { SigningCosmWasmClientOptions, setupWasmExtension, } from "@cosmjs/cosmwasm-stargate" -import { - setupInflationExtension, - setupSudoExtension, - NibiruExtensions, - setupOracleExtension, - setupEpochsExtension, - setupDevgasExtension, - setupTokenFactoryExtension, - setupDevgasMsgExtension, - setupInflationMsgExtension, - setupOracleMsgExtension, - setupSudoMsgExtension, - setupTokenFactoryMsgExtension, -} from ".." +import { NibiruExtensions, setupNibiruExtension } from ".." export const nibiruRegistryTypes: ReadonlyArray<[string, GeneratedType]> = [ ...defaultRegistryTypes, @@ -50,23 +37,13 @@ export class NibiruTxClient extends SigningStargateClient { this.wasmClient = wasm this.nibiruExtensions = QueryClient.withExtensions( tmClient, - setupDevgasExtension, - setupEpochsExtension, - setupOracleExtension, - setupSudoExtension, - setupInflationExtension, setupDistributionExtension, setupGovExtension, setupStakingExtension, setupIbcExtension, setupWasmExtension, setupAuthExtension, - setupTokenFactoryExtension, - setupDevgasMsgExtension, - setupInflationMsgExtension, - setupOracleMsgExtension, - setupSudoMsgExtension, - setupTokenFactoryMsgExtension + setupNibiruExtension ) } diff --git a/src/sdk/balancer/balancer.test.ts b/src/sdk/utils/balancer.test.ts similarity index 98% rename from src/sdk/balancer/balancer.test.ts rename to src/sdk/utils/balancer.test.ts index 839a09e1..0113356c 100644 --- a/src/sdk/balancer/balancer.test.ts +++ b/src/sdk/utils/balancer.test.ts @@ -1,5 +1,5 @@ import { BigNumber } from "bignumber.js" -import { BalancerPool, Swap } from "." +import { BalancerPool, Swap } from "./balancer" describe("balancer tests", () => { test("add x", () => { diff --git a/src/sdk/balancer/balancer.ts b/src/sdk/utils/balancer.ts similarity index 100% rename from src/sdk/balancer/balancer.ts rename to src/sdk/utils/balancer.ts diff --git a/src/sdk/utils/index.ts b/src/sdk/utils/index.ts index 0cfd2561..529c4b7e 100644 --- a/src/sdk/utils/index.ts +++ b/src/sdk/utils/index.ts @@ -2,11 +2,13 @@ * @file Automatically generated by barrelsby. */ +export * from "./balancer" export * from "./chain" export * from "./faucet" export * from "./hash" export * from "./math" export * from "./parse" export * from "./result" +export * from "./stableswap" export * from "./testutil" export * from "./types" diff --git a/src/sdk/utils/math.test.ts b/src/sdk/utils/math.test.ts index 4e1f1757..f7f3711b 100644 --- a/src/sdk/utils/math.test.ts +++ b/src/sdk/utils/math.test.ts @@ -74,6 +74,31 @@ describe("computeStakingEmissionPerPeriod", () => { }, expected: NaN, }, + { + name: "NaN", + in: { + myStake: 0, + totalStaked: 0, + params: { + inflationEnabled: true, + polynomialFactors: [ + "-0.000147085524000000", + "0.074291982762000000", + "-18.867415611180000000", + "3128.641926954698000000", + "-334834.740631598223000000", + "17827464.906540066004000000", + ], + inflationDistribution: undefined, + epochsPerPeriod: new Long(30), + periodsPerYear: new Long(12), + maxPeriod: new Long(96), + hasInflationStarted: true, + }, + epochMintProvision: QueryEpochMintProvisionResponse.fromPartial({}), + }, + expected: NaN, + }, ] test.each(tests)("%o", (tt) => { diff --git a/src/sdk/stableswap/mocks/stabletests.csv b/src/sdk/utils/mocks/stabletests.csv similarity index 100% rename from src/sdk/stableswap/mocks/stabletests.csv rename to src/sdk/utils/mocks/stabletests.csv diff --git a/src/sdk/stableswap/stableswap.test.ts b/src/sdk/utils/stableswap.test.ts similarity index 97% rename from src/sdk/stableswap/stableswap.test.ts rename to src/sdk/utils/stableswap.test.ts index 8c49113c..d3375d54 100644 --- a/src/sdk/stableswap/stableswap.test.ts +++ b/src/sdk/utils/stableswap.test.ts @@ -1,7 +1,7 @@ import fs from "fs" import path from "path" import { BigNumber } from "bignumber.js" -import { StableSwap } from "." +import { StableSwap } from "./stableswap" describe("stableswap tests", () => { test("stabletests", () => { diff --git a/src/sdk/stableswap/stableswap.ts b/src/sdk/utils/stableswap.ts similarity index 100% rename from src/sdk/stableswap/stableswap.ts rename to src/sdk/utils/stableswap.ts