Skip to content

Commit

Permalink
fix(fix): hm (#236)
Browse files Browse the repository at this point in the history
* fix(fix): hm

* fix(fix): fix

* fix(test): fix
  • Loading branch information
cgilbe27 authored Oct 3, 2023
1 parent 981e77b commit 424e644
Show file tree
Hide file tree
Showing 11 changed files with 11,487 additions and 73,494 deletions.
61,703 changes: 0 additions & 61,703 deletions package-lock.json

This file was deleted.

6 changes: 4 additions & 2 deletions packages/indexer-nibi/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,15 @@
"@graphql-codegen/typescript": "^4.0.1",
"@types/jest": "^29.1.2",
"@types/node-fetch": "^2.6.2",
"cross-fetch": "4.0.0",
"graphql": "^16.7.1",
"graphql-ws": "^5.14.0",
"jest": "^28.1.3",
"ts-jest": "^28.0.0-next.3",
"ws": "^8.14.1"
},
"dependencies": {
"cross-fetch": "4.0.0",
"graphql-ws": "^5.14.0"
},
"publishConfig": {
"registry": "https://registry.npmjs.org/",
"tag": "latest",
Expand Down
9 changes: 6 additions & 3 deletions packages/indexer-nibi/src/heart-monitor.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,12 @@ import {

const nibiruUrl = "itn-3"

const heartMonitor = new HeartMonitor({
endptTm: `https://hm-graphql.${nibiruUrl}.nibiru.fi`,
})
const heartMonitor = new HeartMonitor(
{
endptTm: `https://hm-graphql.${nibiruUrl}.nibiru.fi`,
},
`ws://hm-graphql.${nibiruUrl}.nibiru.fi`
)

describe("Heart Monitor constructor", () => {
interface TestCase {
Expand Down
34 changes: 25 additions & 9 deletions packages/indexer-nibi/src/heart-monitor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@ import {
perpPositionsSubscription,
oraclePricesSubscription,
GqlOutOraclePrices,
GqlOutPerpPositions,
} from "./subscription"
import { queryBatchHandler } from "./batchHandlers/queryBatchHandler"

Expand Down Expand Up @@ -125,7 +126,9 @@ export interface IHeartMonitor {
readonly markPriceCandlesSubscription: (
args: SubscriptionMarkPriceCandlesArgs,
fields?: Partial<MarkPriceCandle>
) => Promise<AsyncIterableIterator<ExecutionResult<GqlOutMarkPriceCandles>>>
) => Promise<
AsyncIterableIterator<ExecutionResult<GqlOutMarkPriceCandles>> | undefined
>

readonly oracle: (
args: QueryOracleArgs,
Expand All @@ -135,7 +138,9 @@ export interface IHeartMonitor {
readonly oraclePricesSubscription: (
args: SubscriptionOraclePricesArgs,
fields?: Partial<OraclePrice>
) => Promise<AsyncIterableIterator<ExecutionResult<GqlOutOraclePrices>>>
) => Promise<
AsyncIterableIterator<ExecutionResult<GqlOutOraclePrices>> | undefined
>

readonly perp: (
args: QueryPerpArgs,
Expand All @@ -145,7 +150,16 @@ export interface IHeartMonitor {
readonly perpMarketSubscription: (
args: SubscriptionPerpMarketArgs,
fields?: Partial<PerpMarket>
) => Promise<AsyncIterableIterator<ExecutionResult<GqlOutPerpMarket>>>
) => Promise<
AsyncIterableIterator<ExecutionResult<GqlOutPerpMarket>> | undefined
>

readonly perpPositionsSubscription: (
args: SubscriptionPerpPositionsArgs,
fields?: Partial<PerpPosition>
) => Promise<
AsyncIterableIterator<ExecutionResult<GqlOutPerpPositions>> | undefined
>

readonly queryBatchHandler: (queryQueryString: string[]) => Promise<any>

Expand Down Expand Up @@ -211,9 +225,9 @@ export interface IHeartMonitor {
export class HeartMonitor implements IHeartMonitor {
gqlEndpt: string
defaultGqlEndpt = "https://hm-graphql.devnet-2.nibiru.fi/query"
subscriptionClient: Client
subscriptionClient: Client | undefined

constructor(gqlEndpt?: string | { endptTm: string }) {
constructor(gqlEndpt?: string | { endptTm: string }, webSocketUrl?: string) {
const chain = gqlEndpt as { endptTm: string }
if (!gqlEndpt) {
this.gqlEndpt = this.defaultGqlEndpt
Expand All @@ -226,10 +240,12 @@ export class HeartMonitor implements IHeartMonitor {
this.gqlEndpt = this.defaultGqlEndpt
}

this.subscriptionClient = createClient({
url: this.defaultGqlEndpt,
webSocketImpl: WebSocket,
})
if (webSocketUrl) {
this.subscriptionClient = createClient({
url: webSocketUrl,
...(WebSocket ? { webSocketImpl: WebSocket } : {}),
})
}
}

communityPool = async (
Expand Down
13 changes: 7 additions & 6 deletions packages/indexer-nibi/src/node-test.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
import { HeartMonitor } from "./heart-monitor"
;(async () => {
const hm = new HeartMonitor()
const b = await hm.markPriceCandlesSubscription({})
const test = await hm.markPriceCandlesSubscription({})
if (test) {
for await (const event of test) {
console.log(event)

for await (const event of b) {
console.log(event)

// complete a running subscription by breaking the iterator loop
// break
// complete a running subscription by breaking the iterator loop
// break
}
}
})()
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,11 @@ export const markPriceCandlesSubscriptionQueryString = (

export const markPriceCandlesSubscription = async (
args: SubscriptionMarkPriceCandlesArgs,
client: Client,
client: Client | undefined,
fields?: Partial<MarkPriceCandle>
): Promise<AsyncIterableIterator<ExecutionResult<GqlOutMarkPriceCandles>>> =>
client.iterate({
): Promise<
AsyncIterableIterator<ExecutionResult<GqlOutMarkPriceCandles>> | undefined
> =>
client?.iterate({
query: markPriceCandlesSubscriptionQueryString(args, fields),
})
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,11 @@ export const oraclePricesSubscriptionQueryString = (

export const oraclePricesSubscription = async (
args: SubscriptionOraclePricesArgs,
client: Client,
client: Client | undefined,
fields?: Partial<OraclePrice>
): Promise<AsyncIterableIterator<ExecutionResult<GqlOutOraclePrices>>> =>
client.iterate({
): Promise<
AsyncIterableIterator<ExecutionResult<GqlOutOraclePrices>> | undefined
> =>
client?.iterate({
query: oraclePricesSubscriptionQueryString(args, fields),
})
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,11 @@ export const perpMarketSubscriptionQueryString = (

export const perpMarketSubscription = async (
args: SubscriptionPerpMarketArgs,
client: Client,
client: Client | undefined,
fields?: Partial<PerpMarket>
): Promise<AsyncIterableIterator<ExecutionResult<GqlOutPerpMarket>>> =>
client.iterate({
): Promise<
AsyncIterableIterator<ExecutionResult<GqlOutPerpMarket>> | undefined
> =>
client?.iterate({
query: perpMarketSubscriptionQueryString(args, fields),
})
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,12 @@ export const perpPositionsSubscriptionQueryString = (

export const perpPositionsSubscription = async (
args: SubscriptionPerpPositionsArgs,
client: Client,
client: Client | undefined,
fields?: Partial<PerpPosition>
): Promise<AsyncIterableIterator<ExecutionResult<GqlOutPerpPositions>>> =>
client.iterate({
): Promise<
AsyncIterableIterator<ExecutionResult<GqlOutPerpPositions>> | undefined
> =>
client?.iterate({
query: `subscription {
${perpPositionsSubscriptionQueryString(args, fields)}
}`,
Expand Down
2 changes: 1 addition & 1 deletion packages/nibijs/docs/classes/StableSwap.md
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@ y()
Calculate x[j] if one makes x[i] = x

Done by solving quadratic equation iteratively.
x*1**2 + x1 * (sum' - (A*n**n - 1) * D / (A _ n**n)) = D ** (n+1)/(n \*\* (2 _ n) \_ prod' \* A)
x*1\*\*2 + x1 * (sum' - (A*n\*\*n - 1) * D / (A _ n**n)) = D ** (n+1)/(n \*\* (2 _ n) \_ prod' \* A)
x_1\*\*2 + b\*x_1 = c

x_1 = (x_1\**2 + c) / (2*x_1 + b)
Expand Down
Loading

0 comments on commit 424e644

Please sign in to comment.