From 38f2c08200e3e491583e65b0ab1dc11e1711844d Mon Sep 17 00:00:00 2001 From: Cameron Gilbert Date: Wed, 4 Oct 2023 14:54:55 -0400 Subject: [PATCH] fix(fix): multi-schema --- packages/indexer-nibi/src/query/oracle.ts | 48 +++--- packages/indexer-nibi/src/query/perp.ts | 28 +++- packages/indexer-nibi/src/query/stats.ts | 168 +++++++++++---------- packages/nibijs/docs/classes/StableSwap.md | 2 +- 4 files changed, 139 insertions(+), 107 deletions(-) diff --git a/packages/indexer-nibi/src/query/oracle.ts b/packages/indexer-nibi/src/query/oracle.ts index 3e32ca70..3ad30248 100644 --- a/packages/indexer-nibi/src/query/oracle.ts +++ b/packages/indexer-nibi/src/query/oracle.ts @@ -28,42 +28,46 @@ export const oracleQueryString = ( ) => { const oracleQuery: string[] = [] - if (fields) { - if (fields?.oraclePrices) { - oracleQuery.push( - gqlQuery( - "oraclePrices", - args?.oraclePrices ?? {}, - convertObjectToPropertiesString(fields.oraclePrices), - true - ) + if (fields?.oraclePrices) { + oracleQuery.push( + gqlQuery( + "oraclePrices", + args.oraclePrices ?? {}, + convertObjectToPropertiesString(fields.oraclePrices), + true ) - } + ) + } - if (fields?.oracles) { - oracleQuery.push( - gqlQuery( - "oracles", - args?.oracles ?? {}, - convertObjectToPropertiesString(fields.oracles), - true - ) + if (fields?.oracles) { + oracleQuery.push( + gqlQuery( + "oracles", + args.oracles ?? {}, + convertObjectToPropertiesString(fields.oracles), + true ) - } - } else { + ) + } + + // Default Objects + + if (args.oraclePrices && !fields?.oraclePrices) { oracleQuery.push( gqlQuery( "oraclePrices", - args?.oraclePrices ?? {}, + args.oraclePrices ?? {}, convertObjectToPropertiesString(defaultOraclePrice), true ) ) + } + if (args.oracles && !fields?.oracles) { oracleQuery.push( gqlQuery( "oracles", - args?.oracles ?? {}, + args.oracles ?? {}, convertObjectToPropertiesString(defaultOracleEntry), true ) diff --git a/packages/indexer-nibi/src/query/perp.ts b/packages/indexer-nibi/src/query/perp.ts index 76a975f6..4732da28 100644 --- a/packages/indexer-nibi/src/query/perp.ts +++ b/packages/indexer-nibi/src/query/perp.ts @@ -110,56 +110,70 @@ export const perpQueryString = (args: QueryPerpArgs, fields?: PerpFields) => { ) ) } - } else { + } + + // Default Objects + + if (args.leaderboard && !fields?.leaderboard) { perpQuery.push( gqlQuery( "leaderboard", - args?.leaderboard ?? {}, + args.leaderboard ?? {}, convertObjectToPropertiesString(defaultPerpLeaderboard), true ) ) + } + if (args.market && !fields?.market) { perpQuery.push( gqlQuery( "market", - args?.market ?? {}, + args.market ?? {}, convertObjectToPropertiesString(defaultPerpMarket), true ) ) + } + if (args.markets && !fields?.markets) { perpQuery.push( gqlQuery( "markets", - args?.markets ?? {}, + args.markets ?? {}, convertObjectToPropertiesString(defaultPerpMarket), true ) ) + } + if (args.position && !fields?.position) { perpQuery.push( gqlQuery( "position", - args?.position ?? {}, + args.position ?? {}, convertObjectToPropertiesString(defaultPerpPosition), true ) ) + } + if (args.positionChanges && !fields?.positionChanges) { perpQuery.push( gqlQuery( "positionChanges", - args?.positionChanges ?? {}, + args.positionChanges ?? {}, convertObjectToPropertiesString(defaultPerpPositionChanges), true ) ) + } + if (args.position && !fields?.positionChanges) { perpQuery.push( gqlQuery( "positions", - args?.positions ?? {}, + args.positions ?? {}, convertObjectToPropertiesString(defaultPerpPosition), true ) diff --git a/packages/indexer-nibi/src/query/stats.ts b/packages/indexer-nibi/src/query/stats.ts index 7f40ee73..1f01ba3b 100644 --- a/packages/indexer-nibi/src/query/stats.ts +++ b/packages/indexer-nibi/src/query/stats.ts @@ -56,138 +56,152 @@ export const statsQueryString = ( ) => { const statsQuery: string[] = [] - if (fields) { - if (fields?.fees) { - statsQuery.push( - gqlQuery( - "fees", - args?.fees ?? {}, - convertObjectToPropertiesString(fields.fees), - true - ) + if (fields?.fees) { + statsQuery.push( + gqlQuery( + "fees", + args?.fees ?? {}, + convertObjectToPropertiesString(fields.fees), + true ) - } - - if (fields?.perpOpenInterest) { - statsQuery.push( - gqlQuery( - "perpOpenInterest", - args?.perpOpenInterest ?? {}, - convertObjectToPropertiesString(fields.perpOpenInterest), - true - ) + ) + } + + if (fields?.perpOpenInterest) { + statsQuery.push( + gqlQuery( + "perpOpenInterest", + args?.perpOpenInterest ?? {}, + convertObjectToPropertiesString(fields.perpOpenInterest), + true ) - } - - if (fields?.perpPnl) { - statsQuery.push( - gqlQuery( - "perpPnl", - args?.perpPnl ?? {}, - convertObjectToPropertiesString(fields.perpPnl), - true - ) + ) + } + + if (fields?.perpPnl) { + statsQuery.push( + gqlQuery( + "perpPnl", + args?.perpPnl ?? {}, + convertObjectToPropertiesString(fields.perpPnl), + true ) - } - - if (fields?.totals) { - statsQuery.push( - gqlQuery( - "totals", - args?.totals ?? {}, - convertObjectToPropertiesString(fields.totals), - true - ) + ) + } + + if (fields?.totals) { + statsQuery.push( + gqlQuery( + "totals", + args?.totals ?? {}, + convertObjectToPropertiesString(fields.totals), + true ) - } - - if (fields?.tvl) { - statsQuery.push( - gqlQuery( - "tvl", - args?.tvl ?? {}, - convertObjectToPropertiesString(fields.tvl), - true - ) + ) + } + + if (fields?.tvl) { + statsQuery.push( + gqlQuery( + "tvl", + args?.tvl ?? {}, + convertObjectToPropertiesString(fields.tvl), + true ) - } - - if (fields?.users) { - statsQuery.push( - gqlQuery( - "users", - args?.users ?? {}, - convertObjectToPropertiesString(fields.users), - true - ) + ) + } + + if (fields?.users) { + statsQuery.push( + gqlQuery( + "users", + args?.users ?? {}, + convertObjectToPropertiesString(fields.users), + true ) - } - - if (fields?.volume) { - statsQuery.push( - gqlQuery( - "volume", - args?.volume ?? {}, - convertObjectToPropertiesString(fields.volume), - true - ) + ) + } + + if (fields?.volume) { + statsQuery.push( + gqlQuery( + "volume", + args?.volume ?? {}, + convertObjectToPropertiesString(fields.volume), + true ) - } - } else { + ) + } + + // Default Objects + + if (args.fees && !fields?.fees) { statsQuery.push( gqlQuery( "fees", - args?.fees ?? {}, + args.fees ?? {}, convertObjectToPropertiesString(defaultStatsFees), true ) ) + } + if (args.perpOpenInterest && !fields?.perpOpenInterest) { statsQuery.push( gqlQuery( "perpOpenInterest", - args?.perpOpenInterest ?? {}, + args.perpOpenInterest ?? {}, convertObjectToPropertiesString(defaultPerpOpenInterest), true ) ) + } + if (args.perpPnl && !fields?.perpPnl) { statsQuery.push( gqlQuery( "perpPnl", - args?.perpPnl ?? {}, + args.perpPnl ?? {}, convertObjectToPropertiesString(defaultPerpPnl), true ) ) + } + if (args.totals && !fields?.totals) { statsQuery.push( gqlQuery( "totals", - args?.totals ?? {}, + args.totals ?? {}, convertObjectToPropertiesString(defaultTotals), true ) ) + } + if (args.tvl && !fields?.tvl) { statsQuery.push( gqlQuery( "tvl", - args?.tvl ?? {}, + args.tvl ?? {}, convertObjectToPropertiesString(defaultTvl), true ) ) + } + if (args.users && !fields?.users) { statsQuery.push( gqlQuery( "users", - args?.users ?? {}, + args.users ?? {}, convertObjectToPropertiesString(defaultUsers), true ) ) + } + if (args.volume && !fields?.volume) { statsQuery.push( gqlQuery( "volume", diff --git a/packages/nibijs/docs/classes/StableSwap.md b/packages/nibijs/docs/classes/StableSwap.md index 24824354..fecd50e5 100644 --- a/packages/nibijs/docs/classes/StableSwap.md +++ b/packages/nibijs/docs/classes/StableSwap.md @@ -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)