diff --git a/src/gql/heart-monitor/heart-monitor.test.ts b/src/gql/heart-monitor/heart-monitor.test.ts index 3e97812a..c1b1a5a6 100644 --- a/src/gql/heart-monitor/heart-monitor.test.ts +++ b/src/gql/heart-monitor/heart-monitor.test.ts @@ -12,14 +12,11 @@ import { QueryStatsArgs, GQLStatsFields, communityPoolQueryString, - delegationsQueryString, QueryWasmArgs, GqlWasmFields, GqlOutCommunityPool, - GqlOutDelegations, checkFields, cleanResponse, - defaultDelegations, defaultDistributionCommission, defaultGovDeposit, defaultGovProposal, @@ -36,7 +33,6 @@ import { defaultPerpPosition, defaultPerpPositionChanges, defaultPool, - defaultRedelegations, defaultSpotLpPosition, defaultSpotPool, defaultSpotPoolSwap, @@ -44,11 +40,9 @@ import { defaultToken, defaultTotals, defaultTvl, - defaultUnbondings, defaultUser, defaultUserContract, defaultUsers, - defaultValidator, defaultVolume, GQLDelegation, GQLDistributionCommission, @@ -58,20 +52,15 @@ import { GQLPerpMarket, GQLPerpPosition, GQLQueryGqlCommunityPoolArgs, - GQLQueryGqlDelegationsArgs, GQLQueryGqlDistributionCommissionsArgs, GQLQueryGqlMarkPriceCandlesArgs, - GQLQueryGqlRedelegationsArgs, GQLQueryGqlSpotLpPositionsArgs, GQLQueryGqlSpotPoolCreatedArgs, GQLQueryGqlSpotPoolExitedArgs, GQLQueryGqlSpotPoolJoinedArgs, GQLQueryGqlSpotPoolSwapArgs, GQLQueryGqlSpotPoolsArgs, - GQLQueryGqlUnbondingsArgs, GQLQueryGqlUsersArgs, - GQLQueryGqlValidatorsArgs, - GQLRedelegation, GQLSpotLpPosition, GQLSpotPool, GQLSpotPoolCreated, @@ -83,9 +72,7 @@ import { GQLSubscriptionGqlPerpMarketArgs, GQLSubscriptionGqlPerpPositionsArgs, GQLToken, - GQLUnbonding, GQLUser, - GQLValidator, InflationFields, QueryInflationArgs, defaultInflationInfo, @@ -95,6 +82,12 @@ import { defaultProxy, GQLProxies, defaultInflationReward, + QueryStakingArgs, + GQLStakingFields, + GQLValidatorOrder, + GQLStakingQueryString, + GQLStakingActionType, + checkNoFields, } from ".." const nibiruUrl = "testnet-1" @@ -151,25 +144,6 @@ test("communityPool", async () => { await testCommunityPool({}, defaultToken) }) -const testDelegations = async ( - args: GQLQueryGqlDelegationsArgs, - fields?: GQLDelegation -) => { - const resp = await heartMonitor.delegations(args, fields) - expect(resp).toHaveProperty("delegations") - - if ((resp.delegations?.length ?? 0) > 0) { - const [delegation] = resp.delegations ?? [] - - checkFields([delegation], ["amount", "delegator", "validator"]) - } -} - -test("delegations", async () => { - await testDelegations({ limit: 1 }) - await testDelegations({}, defaultDelegations) -}) - const testDistributionCommissions = async ( args: GQLQueryGqlDistributionCommissionsArgs, fields?: GQLDistributionCommission @@ -760,19 +734,25 @@ test("queryBatchHandler", async () => { // TODO: Make a partial type that includes all of these const resp = await heartMonitor.GQLQueryGqlBatchHandler<{ communityPool: GqlOutCommunityPool[] - delegations: GqlOutDelegations[] + staking: { + delegations: GQLDelegation[] + } }>([ communityPoolQueryString({}, true), - delegationsQueryString( + GQLStakingQueryString( + { delegations: { limit: 1 } }, { - limit: 1, - }, - true + delegations: { + delegator: { address: "" }, + validator: { operator_address: "" }, + amount: 0, + }, + } ), ]) expect(resp).toHaveProperty("communityPool") - expect(resp).toHaveProperty("delegations") + expect(resp.staking).toHaveProperty("delegations") if ((resp.communityPool?.length ?? 0) > 0) { const [communityPool] = resp.communityPool ?? [] @@ -780,44 +760,13 @@ test("queryBatchHandler", async () => { checkFields([communityPool], ["amount", "denom"]) } - if ((resp.delegations?.length ?? 0) > 0) { - const [delegation] = resp.delegations ?? [] + if ((resp.staking.delegations?.length ?? 0) > 0) { + const [delegation] = resp.staking.delegations ?? [] checkFields([delegation], ["amount", "delegator", "validator"]) } }) -const testRedelegations = async ( - args: GQLQueryGqlRedelegationsArgs, - fields?: GQLRedelegation -) => { - const resp = await heartMonitor.redelegations(args, fields) - expect(resp).toHaveProperty("redelegations") - - if ((resp.redelegations?.length ?? 0) > 0) { - const [redelegations] = resp.redelegations ?? [] - - checkFields( - [redelegations], - [ - "delegator", - "source_validator", - "destination_validator", - "amount", - "creation_block", - "completion_time", - ] - ) - } -} - -test("redelegations", async () => { - await testRedelegations({ - limit: 1, - }) - await testRedelegations({}, defaultRedelegations) -}) - const testSpotLpPositions = async ( args: GQLQueryGqlSpotLpPositionsArgs, fields?: GQLSpotLpPosition @@ -1097,28 +1046,6 @@ test("wasm", async () => { ) }) -const testUnbondings = async ( - args: GQLQueryGqlUnbondingsArgs, - fields?: GQLUnbonding -) => { - const resp = await heartMonitor.unbondings(args, fields) - expect(resp).toHaveProperty("unbondings") - - if ((resp.unbondings?.length ?? 0) > 0) { - const [unbonding] = resp.unbondings ?? [] - - checkFields( - [unbonding], - ["delegator", "validator", "amount", "creation_block", "completion_time"] - ) - } -} - -test("unbondings", async () => { - await testUnbondings({ limit: 1 }) - await testUnbondings({}, defaultUnbondings) -}) - const testUsers = async (args: GQLQueryGqlUsersArgs, fields?: GQLUser) => { const resp = await heartMonitor.users(args, fields) @@ -1136,39 +1063,101 @@ test("users", async () => { await testUsers({}, defaultUser) }) -const testValidators = async ( - args: GQLQueryGqlValidatorsArgs, - fields?: GQLValidator +const testStaking = async ( + args: QueryStakingArgs, + fields: GQLStakingFields ) => { - const resp = await heartMonitor.validators(args, fields) - expect(resp).toHaveProperty("validators") + const resp = await heartMonitor.staking(args, fields) + expect(resp).toHaveProperty("staking") - if ((resp.validators?.length ?? 0) > 0) { - const [validator] = resp.validators ?? [] + if (resp.staking) { + const { staking } = resp checkFields( - [validator], - [ - "commission_rates", - "commission_update_time", - "delegator_shares", - "description", - "jailed", - "min_self_delegation", - "operator_address", - "status", - "tokens", - "unbonding_block", - "unbonding_time", - ] + [staking], + ["delegations", "history", "redelegations", "unbondings", "validators"] ) } } -test("validators", async () => { - await testValidators({ - limit: 1, - }) - await testValidators({}, defaultValidator) + +test("staking", async () => { + await testStaking( + { + delegations: { + limit: 10, + order_desc: true, + }, + history: { + limit: 10, + order_desc: true, + where: { + delegator: { + like: "nibi", + }, + }, + }, + redelegations: { + limit: 10, + }, + unbondings: { + limit: 10, + }, + validators: { + limit: 10, + order_by: GQLValidatorOrder.GQLTokens, + order_desc: true, + }, + }, + { + delegations: { amount: 0 }, + redelegations: { amount: 0 }, + unbondings: { amount: 0 }, + validators: { operator_address: "" }, + history: { action: GQLStakingActionType.GQLUnbond, amount: 0 }, + } + ) +}) + +test("staking - empty args", async () => { + testStaking( + { + delegations: {}, + history: {}, + redelegations: {}, + unbondings: {}, + validators: {}, + }, + { + delegations: { amount: 0 }, + redelegations: { amount: 0 }, + unbondings: { amount: 0 }, + validators: { operator_address: "" }, + history: { action: GQLStakingActionType.GQLUnbond, amount: 0 }, + } + ) +}) + +test("staking - partial fields", async () => { + const args = { + redelegations: {}, + validators: {}, + history: {}, + } + + const fields = { + redelegations: { amount: 0 }, + validators: { operator_address: "" }, + history: { action: GQLStakingActionType.GQLUnbond, amount: 0 }, + } + const resp = await heartMonitor.staking(args, fields) + expect(resp).toHaveProperty("staking") + + if (resp.staking) { + const { staking } = resp + + checkFields([staking], ["history", "redelegations", "validators"]) + checkNoFields([staking], ["delegations", "unbondings"]) + } }) describe("gql cleanResponse", () => { diff --git a/src/gql/heart-monitor/heart-monitor.ts b/src/gql/heart-monitor/heart-monitor.ts index aba98792..d3c010d8 100644 --- a/src/gql/heart-monitor/heart-monitor.ts +++ b/src/gql/heart-monitor/heart-monitor.ts @@ -1,27 +1,21 @@ import { WebSocket } from "ws" import { Client, ExecutionResult, createClient } from "graphql-ws" import { - GQLDelegation, GQLDistributionCommission, GQLMarkPriceCandle, GQLOraclePrice, GQLPerpMarket, GQLPerpPosition, GQLQueryGqlCommunityPoolArgs, - GQLQueryGqlDelegationsArgs, GQLQueryGqlDistributionCommissionsArgs, GQLQueryGqlMarkPriceCandlesArgs, - GQLQueryGqlRedelegationsArgs, GQLQueryGqlSpotLpPositionsArgs, GQLQueryGqlSpotPoolCreatedArgs, GQLQueryGqlSpotPoolExitedArgs, GQLQueryGqlSpotPoolJoinedArgs, GQLQueryGqlSpotPoolSwapArgs, GQLQueryGqlSpotPoolsArgs, - GQLQueryGqlUnbondingsArgs, GQLQueryGqlUsersArgs, - GQLQueryGqlValidatorsArgs, - GQLRedelegation, GQLSpotLpPosition, GQLSpotPool, GQLSpotPoolCreated, @@ -33,36 +27,26 @@ import { GQLSubscriptionGqlPerpMarketArgs, GQLSubscriptionGqlPerpPositionsArgs, GQLToken, - GQLUnbonding, GQLUser, - GQLValidator, queryBatchHandler, GqlOutCommunityPool, - GqlOutDelegations, GqlOutDistributionCommissions, - GqlOutRedelegations, GqlOutSpotLpPositions, GqlOutSpotPoolCreated, GqlOutSpotPoolExited, GqlOutSpotPoolJoined, GqlOutSpotPoolSwap, GqlOutSpotPools, - GqlOutUnbondings, GqlOutUsers, - GqlOutValidators, communityPool, - delegations, distributionCommissions, - redelegations, spotLpPositions, spotPoolCreated, spotPoolExited, spotPoolJoined, spotPoolSwap, spotPools, - unbondings, users, - validators, GqlOutPerp, GQLPerpFields, perp, @@ -108,6 +92,12 @@ import { GqlOutProxies, proxies, } from ".." +import { + GQLStakingFields, + GqlOutStaking, + QueryStakingArgs, + staking, +} from "../query/staking" /** IHeartMonitor is an interface for a Heart Monitor GraphQL API. * Each of its methods corresponds to a GQLQueryGql function. */ @@ -119,11 +109,6 @@ export interface IHeartMonitor { fields?: DeepPartial ) => Promise - readonly delegations: ( - args: GQLQueryGqlDelegationsArgs, - fields?: DeepPartial - ) => Promise - readonly distributionCommissions: ( args: GQLQueryGqlDistributionCommissionsArgs, fields?: DeepPartial @@ -197,11 +182,6 @@ export interface IHeartMonitor { queryQueryStrings: string[] ) => Promise - readonly redelegations: ( - args: GQLQueryGqlRedelegationsArgs, - fields?: DeepPartial - ) => Promise - readonly spotLpPositions: ( args: GQLQueryGqlSpotLpPositionsArgs, fields?: DeepPartial @@ -237,25 +217,20 @@ export interface IHeartMonitor { fields?: DeepPartial ) => Promise - readonly unbondings: ( - args: GQLQueryGqlUnbondingsArgs, - fields?: DeepPartial - ) => Promise - readonly users: ( args: GQLQueryGqlUsersArgs, fields?: DeepPartial ) => Promise - readonly validators: ( - args: GQLQueryGqlValidatorsArgs, - fields?: DeepPartial - ) => Promise - readonly wasm: ( args: QueryWasmArgs, fields?: DeepPartial ) => Promise + + readonly staking: ( + args: QueryStakingArgs, + fields?: DeepPartial + ) => Promise } /** HeartMonitor is an API for "Heart Monitor" that indexes the Nibiru blockchain @@ -292,11 +267,6 @@ export class HeartMonitor implements IHeartMonitor { fields?: DeepPartial ) => communityPool(args, this.gqlEndpt, fields) - delegations = async ( - args: GQLQueryGqlDelegationsArgs, - fields?: DeepPartial - ) => delegations(args, this.gqlEndpt, fields) - distributionCommissions = async ( args: GQLQueryGqlDistributionCommissionsArgs, fields?: DeepPartial @@ -355,11 +325,6 @@ export class HeartMonitor implements IHeartMonitor { GQLQueryGqlBatchHandler = async (queryQueryStrings: string[]) => queryBatchHandler(queryQueryStrings, this.gqlEndpt) - redelegations = async ( - args: GQLQueryGqlRedelegationsArgs, - fields?: DeepPartial - ) => redelegations(args, this.gqlEndpt, fields) - spotLpPositions = async ( args: GQLQueryGqlSpotLpPositionsArgs, fields?: DeepPartial @@ -390,22 +355,17 @@ export class HeartMonitor implements IHeartMonitor { fields?: DeepPartial ) => spotPoolSwap(args, this.gqlEndpt, fields) + staking = async ( + args: QueryStakingArgs, + fields?: DeepPartial + ) => staking(args, this.gqlEndpt, fields) + stats = async (args: QueryStatsArgs, fields?: DeepPartial) => stats(args, this.gqlEndpt, fields) - unbondings = async ( - args: GQLQueryGqlUnbondingsArgs, - fields?: DeepPartial - ) => unbondings(args, this.gqlEndpt, fields) - users = async (args: GQLQueryGqlUsersArgs, fields?: DeepPartial) => users(args, this.gqlEndpt, fields) - validators = async ( - args: GQLQueryGqlValidatorsArgs, - fields?: DeepPartial - ) => validators(args, this.gqlEndpt, fields) - wasm = async (args: QueryWasmArgs, fields?: DeepPartial) => wasm(args, this.gqlEndpt, fields) } diff --git a/src/gql/query/delegations.ts b/src/gql/query/delegations.ts deleted file mode 100644 index b4b743cf..00000000 --- a/src/gql/query/delegations.ts +++ /dev/null @@ -1,41 +0,0 @@ -import { - defaultDelegations, - convertObjectToPropertiesString, - doGqlQuery, - gqlQuery, - GQLQuery, - GQLQueryGqlDelegationsArgs, - GQLDelegationOrder, - GQLDelegation, - DeepPartial, -} from ".." - -export interface GqlOutDelegations { - delegations?: GQLQuery["delegations"] -} - -export const delegationsQueryString = ( - args: GQLQueryGqlDelegationsArgs, - 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 = GQLDelegationOrder.GQLDelegatorAddress - - return gqlQuery( - "delegations", - args, - fields - ? convertObjectToPropertiesString(fields) - : convertObjectToPropertiesString(defaultDelegations), - excludeParentObject - ) -} - -export const delegations = async ( - args: GQLQueryGqlDelegationsArgs, - endpt: string, - fields?: DeepPartial -): Promise => - doGqlQuery(delegationsQueryString(args, false, fields), endpt) diff --git a/src/gql/query/index.ts b/src/gql/query/index.ts index 7af64e95..240dbc6b 100644 --- a/src/gql/query/index.ts +++ b/src/gql/query/index.ts @@ -3,7 +3,6 @@ */ export * from "./communityPool" -export * from "./delegations" export * from "./distributionCommissions" export * from "./featureFlags" export * from "./governance" @@ -13,15 +12,13 @@ export * from "./markPriceCandles" export * from "./oracle" export * from "./perp" export * from "./proxies" -export * from "./redelegations" 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 "./unbondings" export * from "./users" -export * from "./validators" export * from "./wasm" diff --git a/src/gql/query/redelegations.ts b/src/gql/query/redelegations.ts deleted file mode 100644 index 7bdb0ce4..00000000 --- a/src/gql/query/redelegations.ts +++ /dev/null @@ -1,41 +0,0 @@ -import { - defaultRedelegations, - convertObjectToPropertiesString, - doGqlQuery, - gqlQuery, - GQLQuery, - GQLQueryGqlRedelegationsArgs, - GQLRedelegation, - GQLRedelegationOrder, - DeepPartial, -} from ".." - -export interface GqlOutRedelegations { - redelegations?: GQLQuery["redelegations"] -} - -export const redelegationsQueryString = ( - args: GQLQueryGqlRedelegationsArgs, - excludeParentObject: boolean, - fields?: DeepPartial -) => { - if (!args.limit) args.limit = 100 - if (args.order_desc === undefined) args.order_desc = true - if (!args.order_by) args.order_by = GQLRedelegationOrder.GQLCreationHeight - - return gqlQuery( - "redelegations", - args, - fields - ? convertObjectToPropertiesString(fields) - : convertObjectToPropertiesString(defaultRedelegations), - excludeParentObject - ) -} - -export const redelegations = async ( - args: GQLQueryGqlRedelegationsArgs, - endpt: string, - fields?: DeepPartial -): Promise => - doGqlQuery(redelegationsQueryString(args, false, fields), endpt) diff --git a/src/gql/query/staking.ts b/src/gql/query/staking.ts new file mode 100644 index 00000000..829dacf5 --- /dev/null +++ b/src/gql/query/staking.ts @@ -0,0 +1,117 @@ +import { + DeepPartial, + GQLDelegation, + GQLQuery, + GQLQueryGqlRedelegationsArgs, + GQLQueryGqlUnbondingsArgs, + GQLRedelegation, + GQLStakingGqlDelegationsArgs, + GQLStakingGqlHistoryArgs, + GQLStakingGqlValidatorsArgs, + GQLStakingHistoryItem, + GQLUnbonding, + GQLValidator, + convertObjectToPropertiesString, + doGqlQuery, + gqlQuery, +} from "../utils" + +export type QueryStakingArgs = { + delegations?: GQLStakingGqlDelegationsArgs + history?: GQLStakingGqlHistoryArgs + redelegations?: GQLQueryGqlRedelegationsArgs + unbondings?: GQLQueryGqlUnbondingsArgs + validators?: GQLStakingGqlValidatorsArgs +} + +export interface GqlOutStaking { + staking?: GQLQuery["staking"] +} + +export type GQLStakingFields = DeepPartial<{ + delegations?: DeepPartial + history?: DeepPartial + redelegations?: DeepPartial + unbondings?: DeepPartial + validators?: DeepPartial +}> + +export const GQLStakingQueryString = ( + args: QueryStakingArgs, + fields?: GQLStakingFields +) => { + const GQLStakingQuery: string[] = [] + + if (fields?.delegations) { + GQLStakingQuery.push( + gqlQuery( + "delegations", + args.delegations ?? {}, + convertObjectToPropertiesString(fields.delegations), + true + ) + ) + } + + if (fields?.history) { + GQLStakingQuery.push( + gqlQuery( + "history", + args.history ?? {}, + convertObjectToPropertiesString(fields.history), + true + ) + ) + } + + if (fields?.redelegations) { + GQLStakingQuery.push( + gqlQuery( + "redelegations", + args.redelegations ?? {}, + convertObjectToPropertiesString(fields.redelegations), + true + ) + ) + } + + if (fields?.unbondings) { + GQLStakingQuery.push( + gqlQuery( + "unbondings", + args.unbondings ?? {}, + convertObjectToPropertiesString(fields.unbondings), + true + ) + ) + } + + if (fields?.validators) { + GQLStakingQuery.push( + gqlQuery( + "validators", + args.validators ?? {}, + convertObjectToPropertiesString(fields.validators), + true + ) + ) + } + + return ` + staking { + ${GQLStakingQuery.join("\n")} + } + ` +} + +export const staking = async ( + args: QueryStakingArgs, + endpt: string, + fields?: GQLStakingFields +): Promise => + doGqlQuery( + `{ + ${GQLStakingQueryString(args, fields)} + }`, + endpt + ) diff --git a/src/gql/query/unbondings.ts b/src/gql/query/unbondings.ts deleted file mode 100644 index 987b1b3f..00000000 --- a/src/gql/query/unbondings.ts +++ /dev/null @@ -1,41 +0,0 @@ -import { - defaultUnbondings, - convertObjectToPropertiesString, - doGqlQuery, - gqlQuery, - GQLQuery, - GQLQueryGqlUnbondingsArgs, - GQLUnbonding, - GQLUnbondingOrder, - DeepPartial, -} from ".." - -export interface GqlOutUnbondings { - unbondings?: GQLQuery["unbondings"] -} - -export const unbondingsQueryString = ( - args: GQLQueryGqlUnbondingsArgs, - excludeParentObject: boolean, - fields?: DeepPartial -) => { - if (!args.limit) args.limit = 100 - if (args.order_desc === undefined) args.order_desc = true - if (!args.order_by) args.order_by = GQLUnbondingOrder.GQLCreationHeight - - return gqlQuery( - "unbondings", - args, - fields - ? convertObjectToPropertiesString(fields) - : convertObjectToPropertiesString(defaultUnbondings), - excludeParentObject - ) -} - -export const unbondings = async ( - args: GQLQueryGqlUnbondingsArgs, - endpt: string, - fields?: DeepPartial -): Promise => - doGqlQuery(unbondingsQueryString(args, false, fields), endpt) diff --git a/src/gql/query/validators.ts b/src/gql/query/validators.ts deleted file mode 100644 index a08ffa8a..00000000 --- a/src/gql/query/validators.ts +++ /dev/null @@ -1,41 +0,0 @@ -import { - defaultValidator, - convertObjectToPropertiesString, - doGqlQuery, - gqlQuery, - GQLQuery, - GQLQueryGqlValidatorsArgs, - GQLValidator, - GQLValidatorOrder, - DeepPartial, -} from ".." - -export interface GqlOutValidators { - validators?: GQLQuery["validators"] -} - -export const validatorsQueryString = ( - args: GQLQueryGqlValidatorsArgs, - excludeParentObject: boolean, - fields?: DeepPartial -) => { - if (!args.limit) args.limit = 100 - if (args.order_desc === undefined) args.order_desc = true - if (!args.order_by) args.order_by = GQLValidatorOrder.GQLOperatorAddress - - return gqlQuery( - "validators", - args, - fields - ? convertObjectToPropertiesString(fields) - : convertObjectToPropertiesString(defaultValidator), - excludeParentObject - ) -} - -export const validators = async ( - args: GQLQueryGqlValidatorsArgs, - endpt: string, - fields?: DeepPartial -): Promise => - doGqlQuery(validatorsQueryString(args, false, fields), endpt) diff --git a/src/gql/utils/consts.test.ts b/src/gql/utils/consts.test.ts index 9d185a32..aa7ff331 100644 --- a/src/gql/utils/consts.test.ts +++ b/src/gql/utils/consts.test.ts @@ -3,42 +3,45 @@ import { queryBatchHandler, GqlOutCommunityPool, communityPoolQueryString, - GqlOutDelegations, - delegationsQueryString, arg, + GQLDelegation, + GQLStakingQueryString, } from ".." describe("queryBatchHandler tests", () => { test("queryBatchHandler", async () => { const resp = await queryBatchHandler<{ communityPool: GqlOutCommunityPool[] - delegations: GqlOutDelegations[] + staking: { + delegations: GQLDelegation[] + } }>( [ communityPoolQueryString({}, true), - delegationsQueryString( + GQLStakingQueryString( + { delegations: { limit: 1 } }, { - limit: 1, - }, - true + delegations: { + delegator: { address: "" }, + amount: 0, + }, + } ), ], "https://hm-graphql.testnet-1.nibiru.fi/query" ) expect(resp).toHaveProperty("communityPool") - expect(resp).toHaveProperty("delegations") + expect(resp.staking).toHaveProperty("delegations") if (resp.communityPool?.length) { const [communityPool] = resp.communityPool const communityPoolFields = ["amount", "denom"] checkFields([communityPool], communityPoolFields) } - - if (resp.delegations?.length) { - const [delegation] = resp.delegations - const delegationFields = ["amount", "delegator", "validator"] - checkFields([delegation], delegationFields) + if (resp.staking.delegations?.length) { + const [delegation] = resp.staking.delegations + checkFields([delegation], ["amount", "delegator"]) } }) diff --git a/src/gql/utils/consts.ts b/src/gql/utils/consts.ts index 80bd2746..4e89dc8f 100644 --- a/src/gql/utils/consts.ts +++ b/src/gql/utils/consts.ts @@ -58,6 +58,14 @@ export const checkFields = (objects: T[], fields: string[]) => { }) } +export const checkNoFields = (objects: T[], fields: string[]) => { + objects.forEach((obj: T) => { + fields.forEach((field: string) => { + expect(obj).not.toHaveProperty(field) + }) + }) +} + export const queryBatchHandler = async ( queryQueryStrings: string[], endpt: string diff --git a/src/gql/utils/defaultObjects.ts b/src/gql/utils/defaultObjects.ts index 623d5b3b..acd4aa40 100644 --- a/src/gql/utils/defaultObjects.ts +++ b/src/gql/utils/defaultObjects.ts @@ -1,6 +1,5 @@ import { GQLBlock, - GQLDelegation, GQLDistributionCommission, GQLFeatureFlags, GQLGovDeposit, @@ -22,7 +21,6 @@ import { GQLPerpPosition, GQLPerpPositionChange, GQLProxies, - GQLRedelegation, GQLSpotLpPosition, GQLSpotPool, GQLSpotPoolSwap, @@ -34,7 +32,6 @@ import { GQLStatsUsers, GQLStatsVolume, GQLToken, - GQLUnbonding, GQLUser, GQLUserContract, GQLValidator, @@ -234,21 +231,6 @@ export const defaultDistributionCommission: GQLDistributionCommission = { validator: defaultValidator, } -export const defaultDelegations: GQLDelegation = { - amount: 0, - delegator: defaultUser, - validator: defaultValidator, -} - -export const defaultRedelegations: GQLRedelegation = { - amount: 0, - delegator: defaultUser, - source_validator: defaultValidator, - destination_validator: defaultValidator, - completion_time: "", - creation_block: defaultBlock, -} - export const defaultSpotLpPosition: GQLSpotLpPosition = { created_block: defaultBlock, pool: defaultPool, @@ -359,14 +341,6 @@ export const defaultVolume: GQLStatsVolume = { periodStartTs: "", } -export const defaultUnbondings: GQLUnbonding = { - amount: 0, - completion_time: "", - creation_block: defaultBlock, - delegator: defaultUser, - validator: defaultValidator, -} - export const defaultOraclePrice: GQLOraclePrice = { block: defaultBlock, pair: "",