Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

feat(ibc): transfers and channels #248

Merged
merged 2 commits into from
Nov 15, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 36 additions & 2 deletions packages/indexer-nibi/src/defaultObjects.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@ import {
GovProposal,
GovVote,
Governance,
Ibc,
IbcChannel,
IbcChannelsResponse,
IbcTransfer,
MarkPriceCandle,
OracleEntry,
OraclePrice,
Expand Down Expand Up @@ -179,6 +183,7 @@ export const defaultMarkPriceCandles: MarkPriceCandle = {
pair: "",
period: 0,
periodStartTs: "",
indexPriceTwapClose: 0,
}

export const defaultPerpPositionChanges: PerpPositionChange = {
Expand Down Expand Up @@ -347,13 +352,42 @@ export const defaultUnbondings: Unbonding = {

export const defaultOraclePrice: OraclePrice = {
block: defaultBlock,
eventSeqNo: 0,
pair: "",
price: 0,
txSeqNo: 0,
}

export const defaultOracleEntry: OracleEntry = {
numVotes: 0,
validator: defaultValidator,
}

export const defaultIbcChannel: IbcChannel = {
chain_id: "",
chain_logo: "",
chain_name: "",
channel_id: "",
counterparty_channel_id: "",
revision_height: 0,
}

export const defaultIbcTransfer: IbcTransfer = {
amount: 0,
memo: "",
block: defaultBlock,
denom: "",
sender: "",
receiver: "",
}

export const defaultIbc: Ibc = {
ibcChannels: {
channels: [defaultIbcChannel],
revision_height: 0,
},
ibcTransfers: [defaultIbcTransfer],
}

export const defaultIbcChannelsResponse: IbcChannelsResponse = {
channels: [defaultIbcChannel],
revision_height: 0,
}
67 changes: 63 additions & 4 deletions packages/indexer-nibi/src/gql/generated.ts
Original file line number Diff line number Diff line change
Expand Up @@ -203,6 +203,57 @@ export type GovernanceGovVotesArgs = {
where?: InputMaybe<GovVotesFilter>
}

export type Ibc = {
readonly __typename?: "IBC"
readonly ibcChannels: IbcChannelsResponse
readonly ibcTransfers: ReadonlyArray<IbcTransfer>
}

export type IbcIbcTransfersArgs = {
limit?: InputMaybe<Scalars["Int"]["input"]>
offset?: InputMaybe<Scalars["Int"]["input"]>
order_by?: InputMaybe<IbcTranferOrder>
order_desc?: InputMaybe<Scalars["Boolean"]["input"]>
where?: InputMaybe<IbcTranferFilter>
}

export type IbcChannel = {
readonly __typename?: "IBCChannel"
readonly chain_id: Scalars["String"]["output"]
readonly chain_logo: Scalars["String"]["output"]
readonly chain_name: Scalars["String"]["output"]
readonly channel_id: Scalars["String"]["output"]
readonly counterparty_channel_id: Scalars["String"]["output"]
readonly revision_height: Scalars["Int"]["output"]
}

export type IbcChannelsResponse = {
readonly __typename?: "IBCChannelsResponse"
readonly channels: ReadonlyArray<IbcChannel>
readonly revision_height: Scalars["Int"]["output"]
}

export type IbcTranferFilter = {
readonly receiver?: InputMaybe<Scalars["String"]["input"]>
readonly sender?: InputMaybe<Scalars["String"]["input"]>
}

export enum IbcTranferOrder {
Block = "block",
Receiver = "receiver",
Sender = "sender",
}

export type IbcTransfer = {
readonly __typename?: "IBCTransfer"
readonly amount: Scalars["Float"]["output"]
readonly block: Block
readonly denom: Scalars["String"]["output"]
readonly memo: Scalars["String"]["output"]
readonly receiver: Scalars["String"]["output"]
readonly sender: Scalars["String"]["output"]
}

export type IntFilter = {
readonly eq?: InputMaybe<Scalars["Int"]["input"]>
readonly gt?: InputMaybe<Scalars["Int"]["input"]>
Expand All @@ -215,6 +266,7 @@ export type MarkPriceCandle = {
readonly __typename?: "MarkPriceCandle"
readonly close: Scalars["Float"]["output"]
readonly high: Scalars["Float"]["output"]
readonly indexPriceTwapClose: Scalars["Float"]["output"]
readonly low: Scalars["Float"]["output"]
readonly open: Scalars["Float"]["output"]
readonly pair: Scalars["String"]["output"]
Expand Down Expand Up @@ -273,15 +325,16 @@ export type OracleEntry = {
export type OraclePrice = {
readonly __typename?: "OraclePrice"
readonly block: Block
readonly eventSeqNo: Scalars["Int"]["output"]
/** @deprecated Not applicable for oracle prices */
readonly eventSeqNo?: Scalars["Int"]["output"]
readonly pair: Scalars["String"]["output"]
readonly price: Scalars["Float"]["output"]
readonly txSeqNo: Scalars["Int"]["output"]
/** @deprecated Not applicable for oracle prices */
readonly txSeqNo?: Scalars["Int"]["output"]
}

export type OraclePricesFilter = {
readonly block?: InputMaybe<IntFilter>
readonly blockTs?: InputMaybe<TimeFilter>
readonly pair?: InputMaybe<StringFilter>
}

Expand Down Expand Up @@ -503,6 +556,7 @@ export type Query = {
readonly delegations: ReadonlyArray<Delegation>
readonly distributionCommissions: ReadonlyArray<DistributionCommission>
readonly governance: Governance
readonly ibc: Ibc
readonly markPriceCandles: ReadonlyArray<MarkPriceCandle>
readonly oracle: Oracle
readonly perp: Perp
Expand Down Expand Up @@ -1041,6 +1095,11 @@ export type StringFilter = {
readonly like?: InputMaybe<Scalars["String"]["input"]>
}

export type SubMarkPriceCandlesFilter = {
readonly pairEq: Scalars["String"]["input"]
readonly periodEq: Scalars["Int"]["input"]
}

export type SubOraclePricesFilter = {
readonly pair: Scalars["String"]["input"]
}
Expand All @@ -1064,7 +1123,7 @@ export type Subscription = {

export type SubscriptionMarkPriceCandlesArgs = {
limit?: InputMaybe<Scalars["Int"]["input"]>
where?: InputMaybe<MarkPriceCandlesFilter>
where: SubMarkPriceCandlesFilter
}

export type SubscriptionOraclePricesArgs = {
Expand Down
59 changes: 55 additions & 4 deletions packages/indexer-nibi/src/gql/schema.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,51 @@ type Governance {
): [GovVote!]!
}

type IBC {
ibcChannels: IBCChannelsResponse!
ibcTransfers(
limit: Int
offset: Int
order_by: IBCTranferOrder
order_desc: Boolean
where: IBCTranferFilter
): [IBCTransfer!]!
}

type IBCChannel {
chain_id: String!
chain_logo: String!
chain_name: String!
channel_id: String!
counterparty_channel_id: String!
revision_height: Int!
}

type IBCChannelsResponse {
channels: [IBCChannel!]!
revision_height: Int!
}

input IBCTranferFilter {
receiver: String
sender: String
}

enum IBCTranferOrder {
block
receiver
sender
}

type IBCTransfer {
amount: Float!
block: Block!
denom: String!
memo: String!
receiver: String!
sender: String!
}

input IntFilter {
eq: Int
gt: Int
Expand All @@ -176,6 +221,7 @@ input IntFilter {
type MarkPriceCandle {
close: Float!
high: Float!
indexPriceTwapClose: Float!
low: Float!
open: Float!
pair: String!
Expand Down Expand Up @@ -227,15 +273,14 @@ type OracleEntry {

type OraclePrice {
block: Block!
eventSeqNo: Int!
eventSeqNo: Int @deprecated(reason: "Not applicable for oracle prices")
pair: String!
price: Float!
txSeqNo: Int!
txSeqNo: Int @deprecated(reason: "Not applicable for oracle prices")
}

input OraclePricesFilter {
block: IntFilter
blockTs: TimeFilter
pair: StringFilter
}

Expand Down Expand Up @@ -450,6 +495,7 @@ type Query {
where: DistributionCommissionFilter
): [DistributionCommission!]!
governance: Governance!
ibc: IBC!
markPriceCandles(
limit: Int
order_by: MarkPriceCandlesOrder
Expand Down Expand Up @@ -897,6 +943,11 @@ input StringFilter {
like: String
}

input SubMarkPriceCandlesFilter {
pairEq: String!
periodEq: Int!
}

input SubOraclePricesFilter {
pair: String!
}
Expand All @@ -913,7 +964,7 @@ input SubPerpPositionFilter {
type Subscription {
markPriceCandles(
limit: Int
where: MarkPriceCandlesFilter
where: SubMarkPriceCandlesFilter!
): [MarkPriceCandle!]!
oraclePrices(where: SubOraclePricesFilter): [OraclePrice!]!
perpMarket(where: SubPerpMarketFilter!): PerpMarket!
Expand Down
53 changes: 49 additions & 4 deletions packages/indexer-nibi/src/heart-monitor.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,11 @@ import { HeartMonitor } from "./heart-monitor"
import { cleanResponse, gqlEndptFromTmRpc } from "./gql"
import {
GovernanceFields,
IbcFields,
OracleFields,
PerpFields,
QueryGovernanceArgs,
QueryIbcArgs,
QueryOracleArgs,
QueryPerpArgs,
QueryStatsArgs,
Expand All @@ -19,6 +21,9 @@ import {
defaultGovDeposit,
defaultGovProposal,
defaultGovVote,
defaultIbcChannel,
defaultIbcChannelsResponse,
defaultIbcTransfer,
defaultMarkPriceCandles,
defaultOracleEntry,
defaultOraclePrice,
Expand Down Expand Up @@ -211,6 +216,45 @@ test("distributionCommissions", async () => {
await testDistributionCommissions({}, defaultDistributionCommission)
})

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], ["ibcChannels", "ibcTransfers"])
}
}

test("ibc", async () => {
await testIbc({
ibcChannels: {},
ibcTransfers: {
limit: 1,
},
})
await testIbc(
{
ibcChannels: {},
ibcTransfers: {
limit: 1,
},
},
{
ibcChannels: defaultIbcChannelsResponse,
ibcTransfers: defaultIbcTransfer,
}
)
await testIbc(
{},
{
ibcChannels: defaultIbcChannelsResponse,
ibcTransfers: defaultIbcTransfer,
}
)
})

const testGovernance = async (
args: QueryGovernanceArgs,
fields?: GovernanceFields
Expand Down Expand Up @@ -293,6 +337,10 @@ test("markPriceCandles", async () => {
test("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,
})

Expand Down Expand Up @@ -406,10 +454,7 @@ const testOraclePricesSubscription = async (
if ((event?.value.data.oraclePrices.length ?? 0) > 0) {
const [oraclePrices] = event?.value.data.oraclePrices ?? []

checkFields(
[oraclePrices],
["block", "eventSeqNo", "pair", "price", "txSeqNo"]
)
checkFields([oraclePrices], ["block", "pair", "price"])
}
}

Expand Down
Loading