From cbb36d752d177c6c467175d94463772d56f3e5f6 Mon Sep 17 00:00:00 2001 From: Calico Nino <54007257+CalicoNino@users.noreply.github.com> Date: Wed, 23 Oct 2024 14:42:51 -0400 Subject: [PATCH] refactor: updating to latest graphql schema since featureflags don't include spot & perp (#385) --- README.md | 68 +--------- src/gql/heart-monitor/heart-monitor.test.ts | 10 +- src/gql/utils/consts.test.ts | 5 +- src/gql/utils/defaultObjects.ts | 133 +------------------- 4 files changed, 5 insertions(+), 211 deletions(-) diff --git a/README.md b/README.md index 5a514080..4fdd8a09 100644 --- a/README.md +++ b/README.md @@ -46,10 +46,9 @@ The `nibijs` source code can be found in the `src` directory. - [Example: Creating a wallet](#example-creating-a-wallet) - [Example: Querying](#example-querying) - [Example: Sending funds](#example-sending-funds) - - [Example: Transaction with arbitrary messages](#example-transaction-with-arbitrary-messages) - [Codebase structure](#codebase-structure) - [Development Quick Start](#development-quick-start) -- [🔓 License](#%F0%9F%94%93-license) +- [🔓 License](#-license) To learn more about Nibiru, see [nibiru.fi/docs](https://nibiru.fi/docs) @@ -100,14 +99,6 @@ console.log("balances: %o", balances) const blockHeight = 200000 const block = await querier.getBlock(blockHeight) console.log("block: %o", block) - -// Query PERP markets -const perpMarkets = await querier.nibiruExtensions.perp.markets() -console.log("perpMarkets: %o", perpMarkets) - -// Query SPOT pools -const spotPools = await querier.nibiruExtensions.spot.pools() -console.log("spotPools: %o", spotPools) ``` ### Example: Sending funds @@ -151,63 +142,6 @@ balances = await querier.getAllBalances(exampleAddress) console.log("balances: %o", balances) ``` -### Example: Transaction with arbitrary messages - -```js -import { - NibiruTxClient, - newSignerFromMnemonic, - Msg, - Testnet, - NibiruQuerier, -} from "@nibiruchain/nibijs" -import { coin } from "@cosmjs/proto-signing" - -const mnemonic = "Your mnemonic here" -export const CHAIN = Testnet(2) -const signer = await newSignerFromMnemonic(mnemonic) -const querier = await NibiruQuerier.connect(CHAIN.endptTm) -const txClient = await NibiruTxClient.connectWithSigner(CHAIN.endptTm, signer) -const [{ address: fromAddr }] = await signer.getAccounts() -const pair = "ubtc:unusd" - -// Construct tx msgs -const msgs = [ - Msg.perp.openPosition({ - sender: fromAddr, - pair: pair, - quoteAssetAmount: 10, - leverage: 1, - goLong: true, - baseAssetAmountLimit: 0, - }), - Msg.perp.addMargin({ - sender: fromAddr, - pair: pair, - margin: coin("20", "unusd"), - }), - Msg.perp.removeMargin({ - sender: fromAddr, - pair: pair, - margin: coin("5", "unusd"), - }), - // final margin value of 10 (open) + 20 (add) - 5 (remove) = 25 -] - -// Broadcast tx -const txResp = await txClient.signAndBroadcast(fromAddr, msgs, "auto") -console.log(txResp) - -// Check your open PERP positions -const delay = (ms) => new Promise((res) => setTimeout(res, ms)) -await delay(5000) - -const perpPositions = await querier.nibiruExtensions.perp.positions({ - trader: fromAddr, -}) -console.log("perpPositions: %o", perpPositions) -``` - ## Codebase structure | Directories of `@nibiruchain/nibijs` | Purpose/Utility | diff --git a/src/gql/heart-monitor/heart-monitor.test.ts b/src/gql/heart-monitor/heart-monitor.test.ts index b2c87c4e..30a5c1d8 100644 --- a/src/gql/heart-monitor/heart-monitor.test.ts +++ b/src/gql/heart-monitor/heart-monitor.test.ts @@ -139,10 +139,7 @@ const testFeatureFlags = async (fields: GQLFeatureFlags) => { if (resp.featureFlags) { const { featureFlags } = resp - checkFields( - [featureFlags], - ["gov", "oracle", "perp", "spot", "staking", "wasm"] - ) + checkFields([featureFlags], ["gov", "oracle", "staking", "wasm"]) } } @@ -398,10 +395,7 @@ test("queryBatchHandler", async () => { if (resp.featureFlags) { const { featureFlags } = resp - checkFields( - [featureFlags], - ["gov", "oracle", "perp", "spot", "staking", "wasm"] - ) + checkFields([featureFlags], ["gov", "oracle", "staking", "wasm"]) } }) diff --git a/src/gql/utils/consts.test.ts b/src/gql/utils/consts.test.ts index b62dfa85..a6ad8f81 100644 --- a/src/gql/utils/consts.test.ts +++ b/src/gql/utils/consts.test.ts @@ -37,10 +37,7 @@ describe("queryBatchHandler tests", () => { if (resp.featureFlags) { const { featureFlags } = resp - checkFields( - [featureFlags], - ["gov", "oracle", "perp", "spot", "staking", "wasm"] - ) + checkFields([featureFlags], ["gov", "oracle", "staking", "wasm"]) } }) diff --git a/src/gql/utils/defaultObjects.ts b/src/gql/utils/defaultObjects.ts index 09ec535d..e419516a 100644 --- a/src/gql/utils/defaultObjects.ts +++ b/src/gql/utils/defaultObjects.ts @@ -14,18 +14,10 @@ import { GQLInflationDistribution, GQLInflationInfo, GQLInflationRewards, - GQLMarkPriceCandle, GQLOracleEntry, GQLOraclePrice, - GQLPerpLeaderboard, - GQLPerpMarket, - GQLPerpPosition, - GQLPerpPositionChange, GQLProxies, GQLRedelegation, - GQLSpotLpPosition, - GQLSpotPool, - GQLSpotPoolSwap, GQLStakingActionType, GQLStakingHistoryItem, GQLToken, @@ -82,68 +74,6 @@ export const defaultActor: GQLUser = { export const defaultUser = defaultActor -export const defaultPerpMarket: GQLPerpMarket = { - base_reserve: 0, - ecosystem_fund_fee_ratio: 0, - max_funding_rate: 0, - enabled: true, - exchange_fee_ratio: 0, - funding_rate_epoch_id: "", - index_price_twap: 0, - is_deleted: false, - latest_cumulative_premium_fraction: 0, - liquidation_fee_ratio: 0, - maintenance_margin_ratio: 0, - mark_price: 0, - mark_price_twap: 0, - max_leverage: 0, - pair: "", - partial_liquidation_ratio: 0, - prepaid_bad_debt: defaultToken, - price_multiplier: 0, - quote_reserve: 0, - sqrt_depth: 0, - total_long: 0, - total_short: 0, - twap_lookback_window: "", -} - -export const defaultPerpPosition: GQLPerpPosition = { - bad_debt: 0, - last_updated_block: defaultBlock, - latest_cumulative_premium_fraction: 0, - margin: 0, - margin_ratio: 0, - open_notional: 0, - pair: "", - liquidation_price: 0, - position_notional: 0, - size: 0, - trader_address: "", - unrealized_funding_payment: 0, - unrealized_pnl: 0, -} - -export const defaultPool: GQLSpotPool = { - amplification: 0, - created_block: defaultBlock, - exit_fee: 0, - swap_fee: 0, - pool_id: 0, - tokens: [defaultToken], - pool_type: "", - total_shares: defaultToken, - total_weight: 0, - weights: [defaultToken], -} - -export const defaultSpotPool = { - block: defaultBlock, - pool: defaultPool, - pool_shares: defaultToken, - user: defaultUser, -} - export const defaultGovProposal: GQLGovProposal = { depositEndTime: "", finalTallyResultAbstain: 0, @@ -176,50 +106,6 @@ export const defaultGovVote: GQLGovVote = { sender: defaultUser, } -export const defaultMarkPriceCandles: GQLMarkPriceCandle = { - close: 0, - high: 0, - low: 0, - open: 0, - volume: 0, - volumeNotional: 0, - pair: "", - period: 0, - periodInterval: "", - periodStartTs: "", - indexPriceTwapClose: 0, -} - -export const defaultPerpPositionChanges: GQLPerpPositionChange = { - badDebt: defaultToken, - block: defaultBlock, - changeReason: "", - eventSeqNo: 0, - exchangedNotional: 0, - exchangedSize: 0, - fundingPayment: 0, - latestCumulativePremiumFraction: 0, - margin: 0, - marginToUser: 0, - openNotional: 0, - pair: "", - positionNotional: 0, - realizedPnl: 0, - size: 0, - traderAddress: "", - transactionFee: defaultToken, - txSeqNo: 0, -} - -export const defaultPerpLeaderboard: GQLPerpLeaderboard = { - avg_pct_pnl_rank: 0, - avg_pct_pnl: 0, - input_margin: 0, - raw_pnl: 0, - raw_pnl_with_unrealized: 0, - trader_address: "", -} - export const defaultGovernance: GQLGovernance = { govDeposits: [defaultGovDeposit], govProposals: [defaultGovProposal], @@ -227,7 +113,7 @@ export const defaultGovernance: GQLGovernance = { } export const defaultDistributionCommission: GQLDistributionCommission = { - commission: [defaultToken], + commission: defaultToken, validator: defaultValidator, } @@ -246,21 +132,6 @@ export const defaultRedelegations: GQLRedelegation = { creation_block: defaultBlock, } -export const defaultSpotLpPosition: GQLSpotLpPosition = { - created_block: defaultBlock, - pool: defaultPool, - pool_shares: defaultToken, - user: defaultUser, -} - -export const defaultSpotPoolSwap: GQLSpotPoolSwap = { - block: defaultBlock, - pool: defaultPool, - token_in: defaultToken, - token_out: defaultToken, - user: defaultUser, -} - export const defaultUnbondings: GQLUnbonding = { amount: 0, completion_time: "", @@ -342,8 +213,6 @@ export const defaultInflationInfo: GQLInflationInfo = { export const defaultFeatureFlags: GQLFeatureFlags = { gov: true, oracle: true, - perp: false, - spot: false, staking: true, wasm: true, }