From 394c38c601e2f33b1462d36be40d2b5db37d9dd4 Mon Sep 17 00:00:00 2001 From: Sam Keen Date: Fri, 29 Jul 2022 11:01:11 +0100 Subject: [PATCH] Feat/633: Oracles MVP in block explorer (#871) * frontend-monorepo-633: Oracles in block explorer - initial oracles page and router setup * frontend-monorepo-633: Oracles in block explorer - added generated types file * Feat/633: Cleanup for MVP1 * Feat/633: Cleanup of route name --- apps/explorer-e2e/.env | 1 + apps/explorer-e2e/.env.devnet | 1 + apps/explorer-e2e/.env.stagnet1 | 1 + apps/explorer-e2e/.env.stagnet2 | 1 + apps/explorer-e2e/.env.testnet | 1 + apps/explorer/.env | 1 + apps/explorer/.env.capsule | 1 + apps/explorer/README.md | 1 + apps/explorer/src/app/config/env.ts | 1 + .../oracles/__generated__/OracleSpecs.ts | 97 +++++++++++++++++++ .../explorer/src/app/routes/oracles/index.tsx | 53 ++++++++++ apps/explorer/src/app/routes/route-names.tsx | 1 + .../explorer/src/app/routes/router-config.tsx | 13 +++ libs/types/src/__generated__/globalTypes.ts | 32 ++++++ 14 files changed, 205 insertions(+) create mode 100644 apps/explorer/src/app/routes/oracles/__generated__/OracleSpecs.ts create mode 100644 apps/explorer/src/app/routes/oracles/index.tsx diff --git a/apps/explorer-e2e/.env b/apps/explorer-e2e/.env index 5577c7a3e..cda5965c4 100644 --- a/apps/explorer-e2e/.env +++ b/apps/explorer-e2e/.env @@ -12,6 +12,7 @@ NX_EXPLORER_ASSETS=1 NX_EXPLORER_GENESIS=1 NX_EXPLORER_GOVERNANCE=1 NX_EXPLORER_MARKETS=1 +NX_EXPLORER_ORACLES=1 NX_EXPLORER_TXS_LIST=0 NX_EXPLORER_NETWORK_PARAMETERS=1 NX_EXPLORER_PARTIES=1 diff --git a/apps/explorer-e2e/.env.devnet b/apps/explorer-e2e/.env.devnet index 3065f3c3a..0956ee9f3 100644 --- a/apps/explorer-e2e/.env.devnet +++ b/apps/explorer-e2e/.env.devnet @@ -11,6 +11,7 @@ NX_EXPLORER_ASSETS=1 NX_EXPLORER_GENESIS=1 NX_EXPLORER_GOVERNANCE=1 NX_EXPLORER_MARKETS=1 +NX_EXPLORER_ORACLES=1 NX_EXPLORER_TXS_LIST=1 NX_EXPLORER_NETWORK_PARAMETERS=1 NX_EXPLORER_PARTIES=1 diff --git a/apps/explorer-e2e/.env.stagnet1 b/apps/explorer-e2e/.env.stagnet1 index 1d833d3c9..19d6fd050 100644 --- a/apps/explorer-e2e/.env.stagnet1 +++ b/apps/explorer-e2e/.env.stagnet1 @@ -11,6 +11,7 @@ NX_EXPLORER_ASSETS=1 NX_EXPLORER_GENESIS=1 NX_EXPLORER_GOVERNANCE=1 NX_EXPLORER_MARKETS=1 +NX_EXPLORER_ORACLES=1 NX_EXPLORER_TXS_LIST=1 NX_EXPLORER_NETWORK_PARAMETERS=1 NX_EXPLORER_PARTIES=1 diff --git a/apps/explorer-e2e/.env.stagnet2 b/apps/explorer-e2e/.env.stagnet2 index 4352d0666..c55daeed5 100644 --- a/apps/explorer-e2e/.env.stagnet2 +++ b/apps/explorer-e2e/.env.stagnet2 @@ -11,6 +11,7 @@ NX_EXPLORER_ASSETS=1 NX_EXPLORER_GENESIS=1 NX_EXPLORER_GOVERNANCE=1 NX_EXPLORER_MARKETS=1 +NX_EXPLORER_ORACLES=1 NX_EXPLORER_TXS_LIST=1 NX_EXPLORER_NETWORK_PARAMETERS=1 NX_EXPLORER_PARTIES=1 diff --git a/apps/explorer-e2e/.env.testnet b/apps/explorer-e2e/.env.testnet index add164e7a..3b5c6f537 100644 --- a/apps/explorer-e2e/.env.testnet +++ b/apps/explorer-e2e/.env.testnet @@ -11,6 +11,7 @@ NX_EXPLORER_ASSETS=1 NX_EXPLORER_GENESIS=1 NX_EXPLORER_GOVERNANCE=1 NX_EXPLORER_MARKETS=1 +NX_EXPLORER_ORACLES=1 NX_EXPLORER_TXS_LIST=1 NX_EXPLORER_NETWORK_PARAMETERS=1 NX_EXPLORER_PARTIES=1 diff --git a/apps/explorer/.env b/apps/explorer/.env index b6b59b054..844001e0f 100644 --- a/apps/explorer/.env +++ b/apps/explorer/.env @@ -23,4 +23,5 @@ NX_EXPLORER_NETWORK_PARAMETERS=1 NX_EXPLORER_PARTIES=1 NX_EXPLORER_VALIDATORS=1 NX_EXPLORER_MARKETS=1 +NX_EXPLORER_ORACLES=1 NX_EXPLORER_TXS_LIST=1 diff --git a/apps/explorer/.env.capsule b/apps/explorer/.env.capsule index e603825a6..302407622 100644 --- a/apps/explorer/.env.capsule +++ b/apps/explorer/.env.capsule @@ -13,6 +13,7 @@ NX_EXPLORER_ASSETS=1 NX_EXPLORER_GENESIS=1 NX_EXPLORER_GOVERNANCE=1 NX_EXPLORER_MARKETS=1 +NX_EXPLORER_ORACLES=1 NX_EXPLORER_TXS_LIST=1 NX_EXPLORER_NETWORK_PARAMETERS=1 NX_EXPLORER_PARTIES=1 diff --git a/apps/explorer/README.md b/apps/explorer/README.md index 0a8e8cc7c..f16ef2536 100644 --- a/apps/explorer/README.md +++ b/apps/explorer/README.md @@ -58,6 +58,7 @@ There are a few different configuration options offered for this app: | `NX_EXPLORER_GENESIS` | Enable the genesis page for the explorer | | `NX_EXPLORER_GOVERNANCE` | Enable the governance page for the explorer | | `NX_EXPLORER_MARKETS` | Enable the markets page for the explorer | +| `NX_EXPLORER_ORACLES` | Enable the oracles page for the explorer | | `NX_EXPLORER_TXS_LIST` | Enable the transactions list page for the explorer | | `NX_EXPLORER_NETWORK_PARAMETERS` | Enable the network parameters page for the explorer | | `NX_EXPLORER_PARTIES` | Enable the parties page for the explorer | diff --git a/apps/explorer/src/app/config/env.ts b/apps/explorer/src/app/config/env.ts index 6340d421f..c59d53168 100644 --- a/apps/explorer/src/app/config/env.ts +++ b/apps/explorer/src/app/config/env.ts @@ -24,6 +24,7 @@ export const ENV = { genesis: truthy.includes(windowOrDefault('NX_EXPLORER_GENESIS')), governance: truthy.includes(windowOrDefault('NX_EXPLORER_GOVERNANCE')), markets: truthy.includes(windowOrDefault('NX_EXPLORER_MARKETS')), + oracles: truthy.includes(windowOrDefault('NX_EXPLORER_ORACLES')), txsList: truthy.includes(windowOrDefault('NX_EXPLORER_TXS_LIST')), networkParameters: truthy.includes( windowOrDefault('NX_EXPLORER_NETWORK_PARAMETERS') diff --git a/apps/explorer/src/app/routes/oracles/__generated__/OracleSpecs.ts b/apps/explorer/src/app/routes/oracles/__generated__/OracleSpecs.ts new file mode 100644 index 000000000..676ebde9b --- /dev/null +++ b/apps/explorer/src/app/routes/oracles/__generated__/OracleSpecs.ts @@ -0,0 +1,97 @@ +/* tslint:disable */ +/* eslint-disable */ +// @generated +// This file was automatically generated and should not be edited. + +import { OracleSpecStatus, PropertyKeyType, ConditionOperator } from "@vegaprotocol/types"; + +// ==================================================== +// GraphQL query operation: OracleSpecs +// ==================================================== + +export interface OracleSpecs_oracleSpecs_filters_key { + __typename: "PropertyKey"; + /** + * name is the name of the property. + */ + name: string | null; + /** + * type is the type of the property. + */ + type: PropertyKeyType; +} + +export interface OracleSpecs_oracleSpecs_filters_conditions { + __typename: "Condition"; + /** + * value is used by the comparator. + */ + value: string | null; + /** + * comparator is the type of comparison to make on the value. + */ + operator: ConditionOperator; +} + +export interface OracleSpecs_oracleSpecs_filters { + __typename: "Filter"; + /** + * key is the oracle data property key targeted by the filter. + */ + key: OracleSpecs_oracleSpecs_filters_key; + /** + * conditions are the conditions that should be matched by the data to be + * considered of interest. + */ + conditions: OracleSpecs_oracleSpecs_filters_conditions[] | null; +} + +export interface OracleSpecs_oracleSpecs_data { + __typename: "OracleData"; + /** + * pubKeys is the list of public keys that signed the data + */ + pubKeys: string[] | null; +} + +export interface OracleSpecs_oracleSpecs { + __typename: "OracleSpec"; + /** + * status describes the status of the oracle spec + */ + status: OracleSpecStatus; + /** + * id is a hash generated from the OracleSpec data. + */ + id: string; + /** + * RFC3339Nano creation date time + */ + createdAt: string; + /** + * RFC3339Nano last updated timestamp + */ + updatedAt: string | null; + /** + * pubKeys is the list of authorized public keys that signed the data for this + * oracle. All the public keys in the oracle data should be contained in these + * public keys. + */ + pubKeys: string[] | null; + /** + * filters describes which oracle data are considered of interest or not for + * the product (or the risk model). + */ + filters: OracleSpecs_oracleSpecs_filters[] | null; + /** + * data list all the oracle data broadcast to this spec + */ + data: OracleSpecs_oracleSpecs_data[]; +} + +export interface OracleSpecs { + /** + * All registered oracle specs + */ + oracleSpecs: OracleSpecs_oracleSpecs[] | null; +} diff --git a/apps/explorer/src/app/routes/oracles/index.tsx b/apps/explorer/src/app/routes/oracles/index.tsx new file mode 100644 index 000000000..a9a78ee0f --- /dev/null +++ b/apps/explorer/src/app/routes/oracles/index.tsx @@ -0,0 +1,53 @@ +import { gql, useQuery } from '@apollo/client'; +import type { OracleSpecs as OracleSpecsQuery } from './__generated__/OracleSpecs'; + +import React from 'react'; +import { SyntaxHighlighter } from '@vegaprotocol/ui-toolkit'; +import { RouteTitle } from '../../components/route-title'; +import { t } from '@vegaprotocol/react-helpers'; +import { SubHeading } from '../../components/sub-heading'; + +const ORACLE_SPECS_QUERY = gql` + query OracleSpecs { + oracleSpecs { + status + id + createdAt + updatedAt + pubKeys + filters { + key { + name + type + } + conditions { + value + operator + } + } + data { + pubKeys + } + } + } +`; + +const Oracles = () => { + const { data } = useQuery(ORACLE_SPECS_QUERY); + + return ( +
+ {t('Oracles')} + {data?.oracleSpecs + ? data.oracleSpecs.map((o) => ( + + {o.id} + + + )) + : null} +
+ ); +}; + +export default Oracles; diff --git a/apps/explorer/src/app/routes/route-names.tsx b/apps/explorer/src/app/routes/route-names.tsx index 0cf20aa2a..3abbc1572 100644 --- a/apps/explorer/src/app/routes/route-names.tsx +++ b/apps/explorer/src/app/routes/route-names.tsx @@ -8,5 +8,6 @@ export const Routes = { GENESIS: 'genesis', GOVERNANCE: 'governance', MARKETS: 'markets', + ORACLES: 'oracles', NETWORK_PARAMETERS: 'network-parameters', }; diff --git a/apps/explorer/src/app/routes/router-config.tsx b/apps/explorer/src/app/routes/router-config.tsx index 5dd0d3ac3..b8602ff31 100644 --- a/apps/explorer/src/app/routes/router-config.tsx +++ b/apps/explorer/src/app/routes/router-config.tsx @@ -3,6 +3,7 @@ import BlockPage from './blocks'; import Governance from './governance'; import Home from './home'; import Markets from './markets'; +import Oracles from './oracles'; import Party from './parties'; import { Parties } from './parties/home'; import { Party as PartySingle } from './parties/id'; @@ -84,6 +85,17 @@ const marketsRoutes = flags.markets ] : []; +const oraclesRoutes = flags.oracles + ? [ + { + path: Routes.ORACLES, + name: 'Oracles', + text: t('Oracles'), + element: , + }, + ] + : []; + const networkParametersRoutes = flags.networkParameters ? [ { @@ -154,6 +166,7 @@ const routerConfig = [ ...genesisRoutes, ...governanceRoutes, ...marketsRoutes, + ...oraclesRoutes, ...networkParametersRoutes, ...validators, ]; diff --git a/libs/types/src/__generated__/globalTypes.ts b/libs/types/src/__generated__/globalTypes.ts index aaf291df8..edf55e031 100644 --- a/libs/types/src/__generated__/globalTypes.ts +++ b/libs/types/src/__generated__/globalTypes.ts @@ -67,6 +67,17 @@ export enum BusEventType { Withdrawal = "Withdrawal", } +/** + * Comparator describes the type of comparison. + */ +export enum ConditionOperator { + OperatorEquals = "OperatorEquals", + OperatorGreaterThan = "OperatorGreaterThan", + OperatorGreaterThanOrEqual = "OperatorGreaterThanOrEqual", + OperatorLessThan = "OperatorLessThan", + OperatorLessThanOrEqual = "OperatorLessThanOrEqual", +} + /** * The status of a deposit */ @@ -119,6 +130,14 @@ export enum NodeStatus { Validator = "Validator", } +/** + * Status describe the status of the oracle spec + */ +export enum OracleSpecStatus { + StatusActive = "StatusActive", + StatusUnused = "StatusUnused", +} + /** * Reason for the order being rejected by the core node */ @@ -202,6 +221,19 @@ export enum OrderType { Network = "Network", } +/** + * Type describes the type of properties that are supported by the oracle + * engine. + */ +export enum PropertyKeyType { + TypeBoolean = "TypeBoolean", + TypeDecimal = "TypeDecimal", + TypeEmpty = "TypeEmpty", + TypeInteger = "TypeInteger", + TypeString = "TypeString", + TypeTimestamp = "TypeTimestamp", +} + /** * Reason for the proposal being rejected by the core node */