chore: migrate network stats and clean up liquidity lib (#1896)

* chore: migrate network stats and clean up liquidity lib

* fix: format

* fix: test imports

* fix: format

* fix: market info expiry format tests

* fix: format again

* fix: build
This commit is contained in:
botond 2022-10-28 13:48:42 +02:00 committed by GitHub
parent b273e2740d
commit b3a8176297
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
16 changed files with 140 additions and 310 deletions

View File

@ -1,7 +1,4 @@
query LiquidityProvisionMarkets {
marketsConnection {
edges {
node {
fragment MarketNode on Market {
id
liquidityProvisionsConnection {
edges {
@ -15,6 +12,13 @@ query LiquidityProvisionMarkets {
targetStake
}
}
query LiquidityProvisionMarkets {
marketsConnection {
edges {
node {
...MarketNode
}
}
}
}

View File

@ -1,77 +0,0 @@
/* tslint:disable */
/* eslint-disable */
// @generated
// This file was automatically generated and should not be edited.
// ====================================================
// GraphQL query operation: LiquidityProvisionMarkets
// ====================================================
export interface LiquidityProvisionMarkets_marketsConnection_edges_node_liquidityProvisionsConnection_edges_node {
__typename: "LiquidityProvision";
/**
* Specified as a unit-less number that represents the amount of settlement asset of the market.
*/
commitmentAmount: string;
/**
* Nominated liquidity fee factor, which is an input to the calculation of liquidity fees on the market, as per setting fees and rewarding liquidity providers.
*/
fee: string;
}
export interface LiquidityProvisionMarkets_marketsConnection_edges_node_liquidityProvisionsConnection_edges {
__typename: "LiquidityProvisionsEdge";
node: LiquidityProvisionMarkets_marketsConnection_edges_node_liquidityProvisionsConnection_edges_node;
}
export interface LiquidityProvisionMarkets_marketsConnection_edges_node_liquidityProvisionsConnection {
__typename: "LiquidityProvisionsConnection";
edges: (LiquidityProvisionMarkets_marketsConnection_edges_node_liquidityProvisionsConnection_edges | null)[] | null;
}
export interface LiquidityProvisionMarkets_marketsConnection_edges_node_data {
__typename: "MarketData";
/**
* The amount of stake targeted for this market
*/
targetStake: string | null;
}
export interface LiquidityProvisionMarkets_marketsConnection_edges_node {
__typename: "Market";
/**
* Market ID
*/
id: string;
/**
* The list of the liquidity provision commitments for this market
*/
liquidityProvisionsConnection: LiquidityProvisionMarkets_marketsConnection_edges_node_liquidityProvisionsConnection | null;
/**
* marketData for the given market
*/
data: LiquidityProvisionMarkets_marketsConnection_edges_node_data | null;
}
export interface LiquidityProvisionMarkets_marketsConnection_edges {
__typename: "MarketEdge";
/**
* The market
*/
node: LiquidityProvisionMarkets_marketsConnection_edges_node;
}
export interface LiquidityProvisionMarkets_marketsConnection {
__typename: "MarketConnection";
/**
* The markets in this connection
*/
edges: LiquidityProvisionMarkets_marketsConnection_edges[];
}
export interface LiquidityProvisionMarkets {
/**
* One or more instruments that are trading on the Vega network
*/
marketsConnection: LiquidityProvisionMarkets_marketsConnection | null;
}

View File

@ -3,17 +3,15 @@ import { Schema as Types } from '@vegaprotocol/types';
import { gql } from '@apollo/client';
import * as Apollo from '@apollo/client';
const defaultOptions = {} as const;
export type MarketNodeFragment = { __typename?: 'Market', id: string, liquidityProvisionsConnection?: { __typename?: 'LiquidityProvisionsConnection', edges?: Array<{ __typename?: 'LiquidityProvisionsEdge', node: { __typename?: 'LiquidityProvision', commitmentAmount: string, fee: string } } | null> | null } | null, data?: { __typename?: 'MarketData', targetStake?: string | null } | null };
export type LiquidityProvisionMarketsQueryVariables = Types.Exact<{ [key: string]: never; }>;
export type LiquidityProvisionMarketsQuery = { __typename?: 'Query', marketsConnection?: { __typename?: 'MarketConnection', edges: Array<{ __typename?: 'MarketEdge', node: { __typename?: 'Market', id: string, liquidityProvisionsConnection?: { __typename?: 'LiquidityProvisionsConnection', edges?: Array<{ __typename?: 'LiquidityProvisionsEdge', node: { __typename?: 'LiquidityProvision', commitmentAmount: string, fee: string } } | null> | null } | null, data?: { __typename?: 'MarketData', targetStake?: string | null } | null } }> } | null };
export const LiquidityProvisionMarketsDocument = gql`
query LiquidityProvisionMarkets {
marketsConnection {
edges {
node {
export const MarketNodeFragmentDoc = gql`
fragment MarketNode on Market {
id
liquidityProvisionsConnection {
edges {
@ -26,11 +24,19 @@ export const LiquidityProvisionMarketsDocument = gql`
data {
targetStake
}
}
}
}
}
`;
export const LiquidityProvisionMarketsDocument = gql`
query LiquidityProvisionMarkets {
marketsConnection {
edges {
node {
...MarketNode
}
}
}
}
${MarketNodeFragmentDoc}`;
/**
* __useLiquidityProvisionMarketsQuery__

View File

@ -1,4 +1,5 @@
export * from './__generated___/MarketLiquidity';
export * from './__generated__/MarketLiquidity';
export * from './__generated__/MarketsLiquidity';
export * from './liquidity-data-provider';
export * from './liquidity-table';
export * from './markets-liquidity-provider';

View File

@ -13,7 +13,7 @@ import {
LiquidityProvisionsDocument,
LiquidityProvisionsUpdateDocument,
MarketLpDocument,
} from './__generated___/MarketLiquidity';
} from './__generated__/MarketLiquidity';
import type {
MarketLpQuery,
@ -23,7 +23,7 @@ import type {
LiquidityProvisionFieldsFragment,
LiquidityProvisionsQuery,
LiquidityProvisionsUpdateSubscription,
} from './__generated___/MarketLiquidity';
} from './__generated__/MarketLiquidity';
import type { Account } from '@vegaprotocol/accounts';
export const liquidityProvisionsDataProvider = makeDataProvider<
LiquidityProvisionsQuery,

View File

@ -18,8 +18,8 @@ import {
marketListProvider,
} from '@vegaprotocol/market-list';
import type { LiquidityProvisionMarkets } from './__generated__/LiquidityProvisionMarkets';
import { LiquidityProvisionMarketsDocument } from './__generated___/MarketsLiquidity';
import type { LiquidityProvisionMarketsQuery } from './__generated__/MarketsLiquidity';
import { LiquidityProvisionMarketsDocument } from './__generated__/MarketsLiquidity';
import {
calcDayVolume,
@ -45,7 +45,7 @@ export interface Markets {
}
const getData = (
responseData: LiquidityProvisionMarkets
responseData: LiquidityProvisionMarketsQuery
): LiquidityProvisionMarket[] | null => {
return (
responseData?.marketsConnection?.edges.map((edge) => {
@ -82,7 +82,7 @@ export const addData = (
};
export const liquidityMarketsProvider = makeDataProvider<
LiquidityProvisionMarkets,
LiquidityProvisionMarketsQuery,
LiquidityProvisionMarket[],
never,
never

View File

@ -1,10 +1,9 @@
import BigNumber from 'bignumber.js';
import { addDecimalsFormatNumber } from '@vegaprotocol/react-helpers';
import type { LiquidityProvisionMarkets_marketsConnection_edges_node } from './../__generated__/LiquidityProvisionMarkets';
import type { MarketNodeFragment } from './../__generated__/MarketsLiquidity';
export type LiquidityProvisionMarket =
LiquidityProvisionMarkets_marketsConnection_edges_node;
export type LiquidityProvisionMarket = MarketNodeFragment;
export interface Provider {
commitmentAmount: string;

View File

@ -3,6 +3,19 @@ import React from 'react';
import { MarketExpires } from './market-expires';
jest.mock('@vegaprotocol/react-helpers', () => ({
t: jest.fn().mockImplementation((text) => text),
getDateTimeFormat: () =>
Intl.DateTimeFormat('en-GB', {
year: 'numeric',
month: 'numeric',
day: 'numeric',
hour: 'numeric',
minute: 'numeric',
second: 'numeric',
}),
}));
describe('MarketExpires', () => {
describe('should properly parse different tags', () => {
it('settlement:date', () => {

View File

@ -1,10 +1,9 @@
query NetworkStats {
query Stats {
nodeData {
stakedTotal
totalNodes
inactiveNodes
validatingNodes
uptime
}
statistics {
status
@ -19,5 +18,6 @@ query NetworkStats {
appVersion
chainVersion
chainId
genesisTime
}
}

View File

@ -1,95 +0,0 @@
/* tslint:disable */
/* eslint-disable */
// @generated
// This file was automatically generated and should not be edited.
// ====================================================
// GraphQL query operation: NetworkStats
// ====================================================
export interface NetworkStats_nodeData {
__typename: "NodeData";
/**
* Total staked amount across all nodes
*/
stakedTotal: string;
/**
* Total number of nodes
*/
totalNodes: number;
/**
* Number of inactive nodes
*/
inactiveNodes: number;
/**
* Number of nodes validating
*/
validatingNodes: number;
}
export interface NetworkStats_statistics {
__typename: "Statistics";
/**
* Status of the Vega application connection with the chain
*/
status: string;
/**
* Current block number
*/
blockHeight: string;
/**
* Duration of the last block, in nanoseconds
*/
blockDuration: string;
/**
* Number of items in the backlog
*/
backlogLength: string;
/**
* Number of transaction processed per block
*/
txPerBlock: string;
/**
* Number of the trades per seconds
*/
tradesPerSecond: string;
/**
* Number of orders per seconds
*/
ordersPerSecond: string;
/**
* Average number of orders added per blocks
*/
averageOrdersPerBlock: string;
/**
* RFC3339Nano current time of the chain (decided through consensus)
*/
vegaTime: string;
/**
* Version of the Vega node (semver)
*/
appVersion: string;
/**
* Version of the chain (semver)
*/
chainVersion: string;
/**
* Current chain ID
*/
chainId: string;
/**
* RFC3339Nano genesis time of the chain
*/
genesisTime: string;
}
export interface NetworkStats {
/**
* Returns information about nodes
*/
nodeData: NetworkStats_nodeData | null;
/**
* Get statistics about the Vega node
*/
statistics: NetworkStats_statistics;
}

View File

@ -0,0 +1,63 @@
import { Schema as Types } from '@vegaprotocol/types';
import { gql } from '@apollo/client';
import * as Apollo from '@apollo/client';
const defaultOptions = {} as const;
export type StatsQueryVariables = Types.Exact<{ [key: string]: never; }>;
export type StatsQuery = { __typename?: 'Query', nodeData?: { __typename?: 'NodeData', stakedTotal: string, totalNodes: number, inactiveNodes: number, validatingNodes: number } | null, statistics: { __typename?: 'Statistics', status: string, blockHeight: string, blockDuration: string, backlogLength: string, txPerBlock: string, tradesPerSecond: string, ordersPerSecond: string, averageOrdersPerBlock: string, vegaTime: string, appVersion: string, chainVersion: string, chainId: string, genesisTime: string } };
export const StatsDocument = gql`
query Stats {
nodeData {
stakedTotal
totalNodes
inactiveNodes
validatingNodes
}
statistics {
status
blockHeight
blockDuration
backlogLength
txPerBlock
tradesPerSecond
ordersPerSecond
averageOrdersPerBlock
vegaTime
appVersion
chainVersion
chainId
genesisTime
}
}
`;
/**
* __useStatsQuery__
*
* To run a query within a React component, call `useStatsQuery` and pass it any options that fit your needs.
* When your component renders, `useStatsQuery` returns an object from Apollo Client that contains loading, error, and data properties
* you can use to render your UI.
*
* @param baseOptions options that will be passed into the query, supported options are listed on: https://www.apollographql.com/docs/react/api/react-hooks/#options;
*
* @example
* const { data, loading, error } = useStatsQuery({
* variables: {
* },
* });
*/
export function useStatsQuery(baseOptions?: Apollo.QueryHookOptions<StatsQuery, StatsQueryVariables>) {
const options = {...defaultOptions, ...baseOptions}
return Apollo.useQuery<StatsQuery, StatsQueryVariables>(StatsDocument, options);
}
export function useStatsLazyQuery(baseOptions?: Apollo.LazyQueryHookOptions<StatsQuery, StatsQueryVariables>) {
const options = {...defaultOptions, ...baseOptions}
return Apollo.useLazyQuery<StatsQuery, StatsQueryVariables>(StatsDocument, options);
}
export type StatsQueryHookResult = ReturnType<typeof useStatsQuery>;
export type StatsLazyQueryHookResult = ReturnType<typeof useStatsLazyQuery>;
export type StatsQueryResult = Apollo.QueryResult<StatsQuery, StatsQueryVariables>;

View File

@ -1,63 +0,0 @@
import { Schema as Types } from '@vegaprotocol/types';
import { gql } from '@apollo/client';
import * as Apollo from '@apollo/client';
const defaultOptions = {} as const;
export type NetworkStatsQueryVariables = Types.Exact<{ [key: string]: never; }>;
export type NetworkStatsQuery = { __typename?: 'Query', nodeData?: { __typename?: 'NodeData', stakedTotal: string, totalNodes: number, inactiveNodes: number, validatingNodes: number, uptime: number } | null, statistics: { __typename?: 'Statistics', status: string, blockHeight: string, blockDuration: string, backlogLength: string, txPerBlock: string, tradesPerSecond: string, ordersPerSecond: string, averageOrdersPerBlock: string, vegaTime: string, appVersion: string, chainVersion: string, chainId: string } };
export const NetworkStatsDocument = gql`
query NetworkStats {
nodeData {
stakedTotal
totalNodes
inactiveNodes
validatingNodes
uptime
}
statistics {
status
blockHeight
blockDuration
backlogLength
txPerBlock
tradesPerSecond
ordersPerSecond
averageOrdersPerBlock
vegaTime
appVersion
chainVersion
chainId
}
}
`;
/**
* __useNetworkStatsQuery__
*
* To run a query within a React component, call `useNetworkStatsQuery` and pass it any options that fit your needs.
* When your component renders, `useNetworkStatsQuery` returns an object from Apollo Client that contains loading, error, and data properties
* you can use to render your UI.
*
* @param baseOptions options that will be passed into the query, supported options are listed on: https://www.apollographql.com/docs/react/api/react-hooks/#options;
*
* @example
* const { data, loading, error } = useNetworkStatsQuery({
* variables: {
* },
* });
*/
export function useNetworkStatsQuery(baseOptions?: Apollo.QueryHookOptions<NetworkStatsQuery, NetworkStatsQueryVariables>) {
const options = {...defaultOptions, ...baseOptions}
return Apollo.useQuery<NetworkStatsQuery, NetworkStatsQueryVariables>(NetworkStatsDocument, options);
}
export function useNetworkStatsLazyQuery(baseOptions?: Apollo.LazyQueryHookOptions<NetworkStatsQuery, NetworkStatsQueryVariables>) {
const options = {...defaultOptions, ...baseOptions}
return Apollo.useLazyQuery<NetworkStatsQuery, NetworkStatsQueryVariables>(NetworkStatsDocument, options);
}
export type NetworkStatsQueryHookResult = ReturnType<typeof useNetworkStatsQuery>;
export type NetworkStatsLazyQueryHookResult = ReturnType<typeof useNetworkStatsLazyQuery>;
export type NetworkStatsQueryResult = Apollo.QueryResult<NetworkStatsQuery, NetworkStatsQueryVariables>;

View File

@ -1,6 +1,5 @@
import { useEffect } from 'react';
import classnames from 'classnames';
import { useQuery, gql } from '@apollo/client';
import { useEnvironment } from '@vegaprotocol/environment';
import { statsFields } from '../../config/stats-fields';
import type {
@ -11,39 +10,14 @@ import { Table } from '../table';
import { TableRow } from '../table-row';
import { PromotedStats } from '../promoted-stats';
import { PromotedStatsItem } from '../promoted-stats-item';
import type { NetworkStats } from './__generated__/NetworkStats';
import { useStatsQuery } from './__generated__/Stats';
import type { StatsQuery } from './__generated__/Stats';
interface StatsManagerProps {
className?: string;
}
const STATS_QUERY = gql`
query NetworkStats {
nodeData {
stakedTotal
totalNodes
inactiveNodes
validatingNodes
}
statistics {
status
blockHeight
blockDuration
backlogLength
txPerBlock
tradesPerSecond
ordersPerSecond
averageOrdersPerBlock
vegaTime
appVersion
chainVersion
chainId
genesisTime
}
}
`;
const compileData = (data?: NetworkStats) => {
const compileData = (data?: StatsQuery) => {
const { nodeData, statistics } = data || {};
const returned = { ...nodeData, ...statistics };
@ -71,8 +45,7 @@ const compileData = (data?: NetworkStats) => {
export const StatsManager = ({ className }: StatsManagerProps) => {
const { VEGA_ENV } = useEnvironment();
const { data, error, startPolling, stopPolling } =
useQuery<NetworkStats>(STATS_QUERY);
const { data, error, startPolling, stopPolling } = useStatsQuery();
useEffect(() => {
startPolling(1000);

View File

@ -1,10 +1,14 @@
import type {
NetworkStats_nodeData,
NetworkStats_statistics,
} from '../components/stats-manager/__generated__/NetworkStats';
import type { Schema } from '@vegaprotocol/types';
import type { StatsQuery } from '../components/stats-manager/__generated__/Stats';
export type Stats = Omit<NetworkStats_nodeData, '__typename'> &
Omit<NetworkStats_statistics, '__typename'>;
type NodeDataKeys =
| 'stakedTotal'
| 'totalNodes'
| 'inactiveNodes'
| 'validatingNodes';
export type Stats = Pick<Schema.NodeData, NodeDataKeys> &
Omit<StatsQuery['statistics'], '__typename'>;
// eslint-disable-next-line
export type value = any;

View File

@ -22,6 +22,8 @@ module.exports = {
'../../libs/environment/**',
'../../libs/fills/**',
'../../libs/governance/**',
'../../libs/liquidity/**',
'../../libs/network-stats/**',
],
},
};