From e6515c43b7dc2ba99313c2795f85ddf5c3790a37 Mon Sep 17 00:00:00 2001 From: gabaldon Date: Thu, 10 Mar 2022 10:47:15 +0100 Subject: [PATCH 01/19] fix(ui): fix routing --- packages/api/src/dataFeedsRouter.json | 37 ++++++++++++++++++++ packages/api/src/repository/ResultRequest.ts | 18 +++++----- packages/api/src/types.ts | 1 + packages/api/src/web3Middleware/provider.ts | 1 + packages/ui/assets/svg/glmr.svg | 9 +++++ packages/ui/assets/svg/moonbeam.svg | 9 +++++ 6 files changed, 66 insertions(+), 9 deletions(-) create mode 100644 packages/ui/assets/svg/glmr.svg create mode 100644 packages/ui/assets/svg/moonbeam.svg diff --git a/packages/api/src/dataFeedsRouter.json b/packages/api/src/dataFeedsRouter.json index fe608c23..9702e7d0 100644 --- a/packages/api/src/dataFeedsRouter.json +++ b/packages/api/src/dataFeedsRouter.json @@ -498,6 +498,43 @@ } } }, + "moonbeam": { + "networks": { + "moonbeam.moonbase": { + "address": "0x56834Ff8D4b27db647Da97CA3bd8540f7fA0e89D", + "blockExplorer": "https://moonbase.moonscan.io/address/{address}#readContract", + "color": "#ff6600", + "name": "Moonbase Alpha", + "pollingPeriod": 10000, + "feeds": { + "Price-BTC/USD-6": { + "label": "$", + "deviationPercentage": 1.0, + "maxSecsBetweenUpdates": 86400, + "minSecsBetweenUpdates": 900 + }, + "Price-ETH/USD-6": { + "label": "$", + "deviationPercentage": 1.0, + "maxSecsBetweenUpdates": 86400, + "minSecsBetweenUpdates": 300 + }, + "Price-GLMR/USDT-6": { + "label": "₮", + "deviationPercentage": 1.0, + "maxSecsBetweenUpdates": 86400, + "minSecsBetweenUpdates": 900 + }, + "Price-USDT/USD-6": { + "label": "$", + "deviationPercentage": 0.1, + "maxSecsBetweenUpdates": 86400, + "minSecsBetweenUpdates": 900 + } + } + } + } + }, "polygon": { "networks": { "polygon.goerli": { diff --git a/packages/api/src/repository/ResultRequest.ts b/packages/api/src/repository/ResultRequest.ts index f282c8c6..40f6a177 100644 --- a/packages/api/src/repository/ResultRequest.ts +++ b/packages/api/src/repository/ResultRequest.ts @@ -13,15 +13,15 @@ export class ResultRequestRepository { constructor (db: Db, _dataFeeds: Array) { this.collection = db.collection('result_request') - this.collection.createIndex( - { feedFullName: 1, timestamp: -1 }, - { - collation: { - locale: 'en_US', - numericOrdering: true - } - } - ) + // this.collection.createIndex( + // { feedFullName: 1, timestamp: -1 }, + // { + // collation: { + // locale: 'en_US', + // numericOrdering: true + // } + // } + // ) } async getFeedRequests ( diff --git a/packages/api/src/types.ts b/packages/api/src/types.ts index 3a70a201..122b671a 100644 --- a/packages/api/src/types.ts +++ b/packages/api/src/types.ts @@ -50,6 +50,7 @@ export enum Network { HarmonyTestnet = 'harmony-testnet', MetisMainnet = 'metis-mainnet', MetisRinkeby = 'metis-rinkeby', + MoonbeamMoonbase = 'moonbeam-moonbase', PolygonMainnet = 'polygon-mainnet', PolygonGoerli = 'polygon-goerli', KCCMainnet = 'KCC-mainnet', diff --git a/packages/api/src/web3Middleware/provider.ts b/packages/api/src/web3Middleware/provider.ts index 43684eec..48d527ab 100644 --- a/packages/api/src/web3Middleware/provider.ts +++ b/packages/api/src/web3Middleware/provider.ts @@ -16,6 +16,7 @@ export function getProvider (network: Network) { [Network.HarmonyTestnet]: process.env.HARMONY_TESTNET_PROVIDER, [Network.KCCTestnet]: process.env.KCC_TESTNET_PROVIDER, [Network.KCCMainnet]: process.env.KCC_MAINNET_PROVIDER, + [Network.MoonbeamMoonbase]: process.env.MOONBASE_ALPHA_PROVIDER, [Network.PolygonMainnet]: process.env.POLYGON_MAINNET_PROVIDER, [Network.PolygonGoerli]: process.env.POLYGON_GOERLI_PROVIDER, [Network.AvalancheFuji]: process.env.AVALANCHE_FUJI_PROVIDER diff --git a/packages/ui/assets/svg/glmr.svg b/packages/ui/assets/svg/glmr.svg new file mode 100644 index 00000000..7dde2569 --- /dev/null +++ b/packages/ui/assets/svg/glmr.svg @@ -0,0 +1,9 @@ + + + + + + + + + diff --git a/packages/ui/assets/svg/moonbeam.svg b/packages/ui/assets/svg/moonbeam.svg new file mode 100644 index 00000000..7dde2569 --- /dev/null +++ b/packages/ui/assets/svg/moonbeam.svg @@ -0,0 +1,9 @@ + + + + + + + + + From 34c36ea8c389fbdd0927d2212c4f99b62b3768a2 Mon Sep 17 00:00:00 2001 From: gabaldon Date: Thu, 10 Mar 2022 15:49:40 +0100 Subject: [PATCH 02/19] fix(ui): add chain to config file --- packages/api/src/types.ts | 26 +++++++++++++++- packages/api/src/utils/index.ts | 30 +++++++++++++------ packages/api/src/web3Middleware/provider.ts | 2 +- packages/ui/apollo/queries/feed.gql | 1 + .../assets/svg/{moonbeam.svg => moonbase.svg} | 0 packages/ui/components/Main.vue | 1 + 6 files changed, 49 insertions(+), 11 deletions(-) rename packages/ui/assets/svg/{moonbeam.svg => moonbase.svg} (100%) diff --git a/packages/api/src/types.ts b/packages/api/src/types.ts index 122b671a..76e7af64 100644 --- a/packages/api/src/types.ts +++ b/packages/api/src/types.ts @@ -35,6 +35,18 @@ export type Context = { export type ConfigByFullName = { [key: string]: FeedInfo } +export enum Chain { + Ethereum = 'ethereum', + Avalanche = 'avalanche', + Boba = 'boba', + Conflux = 'conflux', + Celo = 'celo', + Harmony = 'harmony', + Metis = 'metis', + Moonbeam = 'moonbeam', + Polygon = 'polygon', + KCC = 'KCC' +} export enum Network { EthereumMainnet = 'ethereum-mainnet', @@ -50,7 +62,7 @@ export enum Network { HarmonyTestnet = 'harmony-testnet', MetisMainnet = 'metis-mainnet', MetisRinkeby = 'metis-rinkeby', - MoonbeamMoonbase = 'moonbeam-moonbase', + MoonbaseAlpha = 'moonbase-alpha', PolygonMainnet = 'polygon-mainnet', PolygonGoerli = 'polygon-goerli', KCCMainnet = 'KCC-mainnet', @@ -65,6 +77,7 @@ export type FeedInfoGeneric = { address: string routerAddress: string network: Network + chain: string name: string pollingPeriod: number label: string @@ -131,6 +144,7 @@ export type FeedParsedParams = { maxSecsBetweenUpdates: number minSecsBetweenUpdates: number key: string + chain: string } export type FeedConfig = { @@ -142,6 +156,16 @@ export type FeedConfig = { feeds: FeedInfoRouterConfigMap } +export type ExtendedFeedConfig = { + address: string + blockExplorer: string + color: string + name: string + chain: string + pollingPeriod: number + feeds: FeedInfoRouterConfigMap +} + export type NetworkConfigMap = Record export type RouterDataFeedsConfig = { diff --git a/packages/api/src/utils/index.ts b/packages/api/src/utils/index.ts index 7cb5c550..f6d23477 100644 --- a/packages/api/src/utils/index.ts +++ b/packages/api/src/utils/index.ts @@ -1,4 +1,5 @@ import { + ExtendedFeedConfig, FeedConfig, FeedInfosWithoutAbis, FeedParamsConfig, @@ -13,6 +14,9 @@ export function parseNetworkName (value) { .split(' ') .join('-') } +export function parseChainName (value) { + return value.toLowerCase().split('.')[0] +} // parse data feed name to fit schema export function parseDataName (value) { return value.split('-')[1].toLowerCase() @@ -44,18 +48,22 @@ export function normalizeConfig ( ) // Network Config list deleting key label const configs: Array = networksConfigMap - .reduce( - (acc: Array>, networkConfigMap) => [ - ...acc, - Object.values(networkConfigMap) - ], - [] - ) + .reduce((acc: Array>, networkConfigMap) => { + const config = Object.values(networkConfigMap).map((feed, index) => { + const result = { + ...feed, + chain: Object.keys(networkConfigMap)[index] + } + return result + }) + const result = [...acc, config] + return result + }, []) .flat() - // Parse Feed adding common config + console.log('------', configs) const feeds: FeedInfosWithoutAbis = configs.reduce( - (acc: FeedInfosWithoutAbis, config: FeedConfig) => { + (acc: FeedInfosWithoutAbis, config: ExtendedFeedConfig) => { const feedsArrayConfig: Array = Object.values( config.feeds ) @@ -66,10 +74,13 @@ export function normalizeConfig ( ({ ...feed, key: Object.keys(config.feeds)[index] + // chain: Object.keys(config.chainsNames)[index] } as FeedParsedParams) ) feedsArray.forEach(feed => { + console.log('feed-----', feed) + const chain = parseChainName(config.chain) const network = parseNetworkName(config.name) const name = parseDataName(feed.key) const decimals = parseDataDecimals(feed.key) @@ -81,6 +92,7 @@ export function normalizeConfig ( contractId: '0x0000000000000000000000000000000000000000', routerAddress: config.address, network, + chain, name, label: feed.label, pollingPeriod: config.pollingPeriod, diff --git a/packages/api/src/web3Middleware/provider.ts b/packages/api/src/web3Middleware/provider.ts index 48d527ab..ae0a2591 100644 --- a/packages/api/src/web3Middleware/provider.ts +++ b/packages/api/src/web3Middleware/provider.ts @@ -16,7 +16,7 @@ export function getProvider (network: Network) { [Network.HarmonyTestnet]: process.env.HARMONY_TESTNET_PROVIDER, [Network.KCCTestnet]: process.env.KCC_TESTNET_PROVIDER, [Network.KCCMainnet]: process.env.KCC_MAINNET_PROVIDER, - [Network.MoonbeamMoonbase]: process.env.MOONBASE_ALPHA_PROVIDER, + [Network.MoonbaseAlpha]: process.env.MOONBASE_ALPHA_PROVIDER, [Network.PolygonMainnet]: process.env.POLYGON_MAINNET_PROVIDER, [Network.PolygonGoerli]: process.env.POLYGON_GOERLI_PROVIDER, [Network.AvalancheFuji]: process.env.AVALANCHE_FUJI_PROVIDER diff --git a/packages/ui/apollo/queries/feed.gql b/packages/ui/apollo/queries/feed.gql index d47a1f8f..bd8c4f36 100644 --- a/packages/ui/apollo/queries/feed.gql +++ b/packages/ui/apollo/queries/feed.gql @@ -8,6 +8,7 @@ query feed($feedFullName: String!, $timestamp: Int!) { network label deviation + chain proxyAddress heartbeat finality diff --git a/packages/ui/assets/svg/moonbeam.svg b/packages/ui/assets/svg/moonbase.svg similarity index 100% rename from packages/ui/assets/svg/moonbeam.svg rename to packages/ui/assets/svg/moonbase.svg diff --git a/packages/ui/components/Main.vue b/packages/ui/components/Main.vue index b5e2d679..24be81e8 100644 --- a/packages/ui/components/Main.vue +++ b/packages/ui/components/Main.vue @@ -59,6 +59,7 @@ export default { }, options() { if (this.networks) { + console.log('all networks', this.networks) return generateSelectOptions(this.networks) } else { return null From 7c926f9dd16ee9a080d65e9412825bbfd8311da9 Mon Sep 17 00:00:00 2001 From: gabaldon Date: Thu, 10 Mar 2022 15:52:59 +0100 Subject: [PATCH 03/19] fix(ui): delete unnecessary sortByNetwork --- packages/ui/tests/utils/sortByNetwork.spec.js | 21 ------------------- packages/ui/utils/sortByNetwork.js | 16 -------------- 2 files changed, 37 deletions(-) delete mode 100644 packages/ui/tests/utils/sortByNetwork.spec.js delete mode 100644 packages/ui/utils/sortByNetwork.js diff --git a/packages/ui/tests/utils/sortByNetwork.spec.js b/packages/ui/tests/utils/sortByNetwork.spec.js deleted file mode 100644 index cbf96c28..00000000 --- a/packages/ui/tests/utils/sortByNetwork.spec.js +++ /dev/null @@ -1,21 +0,0 @@ -import { sortByNetwork } from '../../utils/sortByNetwork' - -describe('sortByNetwork.js', () => { - it('orders ethereum-mainnet first, ethereum remainning networks in second place, and the rest alphabetically', () => { - const feeds = [ - { network: 'boba-rinkeby' }, - { network: 'conflux-testnet' }, - { network: 'ethereum-rinkeby' }, - { network: 'ethereum-mainnet' }, - { network: 'ethereum-goerli' }, - ] - const options = sortByNetwork(feeds) - expect(options).toStrictEqual([ - { network: 'ethereum-mainnet' }, - { network: 'ethereum-rinkeby' }, - { network: 'ethereum-goerli' }, - { network: 'boba-rinkeby' }, - { network: 'conflux-testnet' }, - ]) - }) -}) diff --git a/packages/ui/utils/sortByNetwork.js b/packages/ui/utils/sortByNetwork.js deleted file mode 100644 index 16f57b65..00000000 --- a/packages/ui/utils/sortByNetwork.js +++ /dev/null @@ -1,16 +0,0 @@ -export function sortByNetwork(feeds) { - return feeds.sort((firstFeed, secondFeed) => { - if ( - firstFeed.network.includes('ethereum-mainnet') && - !secondFeed.network.includes('ethereum-mainnet') - ) { - return -1 - } else if ( - firstFeed.network.includes('ethereum') && - !secondFeed.network.includes('ethereum') - ) { - return -1 - } - return 0 - }) -} From c0a71b73e95604411de51bde0cf147e79212b6c5 Mon Sep 17 00:00:00 2001 From: gabaldon Date: Thu, 10 Mar 2022 16:09:33 +0100 Subject: [PATCH 04/19] fix(ui): rename network -> chain --- .../ui/components/DataFeedDescription.vue | 4 + packages/ui/components/DataFeedDetails.vue | 3 + packages/ui/components/DataFeeds.vue | 2 + packages/ui/components/Main.vue | 7 +- packages/ui/components/NavBar.vue | 5 +- packages/ui/components/SideBar.vue | 86 +++++++++++++++++++ packages/ui/store/index.js | 2 +- packages/ui/utils/generateSelectOptions.js | 2 +- 8 files changed, 104 insertions(+), 7 deletions(-) create mode 100644 packages/ui/components/SideBar.vue diff --git a/packages/ui/components/DataFeedDescription.vue b/packages/ui/components/DataFeedDescription.vue index 118c2e63..0abd2f7a 100644 --- a/packages/ui/components/DataFeedDescription.vue +++ b/packages/ui/components/DataFeedDescription.vue @@ -44,6 +44,10 @@ export default { type: String, required: true, }, + chain: { + type: String, + required: true, + }, network: { type: String, required: true, diff --git a/packages/ui/components/DataFeedDetails.vue b/packages/ui/components/DataFeedDetails.vue index c55aaf61..0e5dac95 100644 --- a/packages/ui/components/DataFeedDetails.vue +++ b/packages/ui/components/DataFeedDetails.vue @@ -15,6 +15,7 @@ @@ -78,6 +79,7 @@ export default { alt: feed.name, }, network: feed.network, + chain: feed.chain, color: feed.color, blockExplorer: feed.blockExplorer, } diff --git a/packages/ui/components/Main.vue b/packages/ui/components/Main.vue index 24be81e8..a65f1470 100644 --- a/packages/ui/components/Main.vue +++ b/packages/ui/components/Main.vue @@ -7,13 +7,13 @@
-

{{ $t('main.network_subtitle') }} - {{ selected[0].network }} + {{ selected[0].chain }} {{ selectedNetworks }}.

@@ -59,7 +59,6 @@ export default { }, options() { if (this.networks) { - console.log('all networks', this.networks) return generateSelectOptions(this.networks) } else { return null diff --git a/packages/ui/components/NavBar.vue b/packages/ui/components/NavBar.vue index 1bc846a0..844d6d49 100644 --- a/packages/ui/components/NavBar.vue +++ b/packages/ui/components/NavBar.vue @@ -77,7 +77,7 @@ export default { } }, selectedOption() { - return (this.selected[0] ? this.selected[0].network : '').toLowerCase() + return (this.selected[0] ? this.selected[0].chain : '').toLowerCase() }, }, watch: { @@ -89,6 +89,9 @@ export default { }, }, methods: { + optionFromSelected(options) { + return (options[0] ? options[0].chain : '').toLowerCase() + }, capitalizeFirstLetter, closeMenu() { this.isMenuVisible = false diff --git a/packages/ui/components/SideBar.vue b/packages/ui/components/SideBar.vue new file mode 100644 index 00000000..1080a66a --- /dev/null +++ b/packages/ui/components/SideBar.vue @@ -0,0 +1,86 @@ + + + + + diff --git a/packages/ui/store/index.js b/packages/ui/store/index.js index d189c113..f42f368c 100644 --- a/packages/ui/store/index.js +++ b/packages/ui/store/index.js @@ -3,7 +3,7 @@ export const state = () => ({ { label: 'ethereum-mainnet', key: 'Ethereum Mainnet', - network: 'Ethereum', + chain: 'Ethereum', }, ], }) diff --git a/packages/ui/utils/generateSelectOptions.js b/packages/ui/utils/generateSelectOptions.js index 4fe73d9a..a5ede8ec 100644 --- a/packages/ui/utils/generateSelectOptions.js +++ b/packages/ui/utils/generateSelectOptions.js @@ -7,7 +7,7 @@ export function generateSelectOptions(list) { const networkDetails = { label: chain.label, key: chain.label.split('-').map(capitalizeFirstLetter).join(' '), - network: capitalizeFirstLetter(network), + chain: capitalizeFirstLetter(network), } // Initialize network entry if not exists if (!chainByNetwork[network]) { From 9ba71a386e7d8210abc28b2eaabb9d37a2cb4378 Mon Sep 17 00:00:00 2001 From: gabaldon Date: Thu, 10 Mar 2022 17:11:47 +0100 Subject: [PATCH 05/19] feat(api): get networks from config file --- packages/api/src/index.ts | 13 +++++-- packages/api/src/resolvers.ts | 21 ++++++----- packages/api/src/server.ts | 11 +++--- packages/api/src/typeDefs.ts | 13 +++---- packages/api/src/types.ts | 5 ++- packages/api/src/utils/index.ts | 35 +++++++++++++++++-- packages/ui/apollo/queries/networks.gql | 4 ++- .../assets/svg/{moonbase.svg => moonbeam.svg} | 0 packages/ui/components/Main.vue | 6 ++-- packages/ui/utils/generateSelectOptions.js | 17 +++------ 10 files changed, 83 insertions(+), 42 deletions(-) rename packages/ui/assets/svg/{moonbase.svg => moonbeam.svg} (100%) diff --git a/packages/api/src/index.ts b/packages/api/src/index.ts index abc0a86d..d25baf1a 100644 --- a/packages/api/src/index.ts +++ b/packages/api/src/index.ts @@ -14,13 +14,14 @@ import { RouterDataFeedsConfig } from './types' import { Web3Middleware } from './web3Middleware/index' -import { normalizeConfig } from './utils/index' +import { normalizeConfig, normalizeNetworkConfig } from './utils/index' import dataFeedsRouterConfig from './dataFeedsRouter.json' async function main () { const mongoManager = new MongoManager() const db = await mongoManager.start() const dataFeeds = readDataFeeds() + const networksConfig = readNetworks() const repositories: Repositories = { feedRepository: new FeedRepository(dataFeeds), @@ -33,7 +34,7 @@ async function main () { ) web3Middleware.listen() - const server = await createServer(repositories, dataFeeds) + const server = await createServer(repositories, dataFeeds, networksConfig) server .listen({ host: '0.0.0.0', port: process.env.SERVER_PORT }) @@ -42,6 +43,14 @@ async function main () { }) } +export function readNetworks (): any { + const dataFeeds: Array> = normalizeNetworkConfig(dataFeedsRouterConfig as RouterDataFeedsConfig) + return dataFeeds +} + export function readDataFeeds (): Array { const dataFeeds: Array { return await feedRepository.getFeedsByNetwork(args.network) }, - networks: async (_parent, _args) => { - return Object.keys(Network).map(key => ({ - label: Network[key] - })) + networks: async (_parent, _args, { config }) => { + console.log('--new networks config in RESOLVERS--', config.networksConfig) + return config.networksConfig }, requests: async (_parent, args, { resultRequestRepository }: Context) => { @@ -37,24 +36,24 @@ const resolvers = { return (await loaders.lastResult.load(parent.feedFullName))?.timestamp }, color: async (parent, _args, { config }: Context) => { - return config[parent.feedFullName]?.color || '' + return config.feedsConfig[parent.feedFullName]?.color || '' }, blockExplorer: async (parent, _args, { config }: Context) => { - return config[parent.feedFullName]?.blockExplorer || '' + return config.feedsConfig[parent.feedFullName]?.blockExplorer || '' }, proxyAddress: async (parent, _args, { config }: Context) => { - return config[parent.feedFullName]?.routerAddress || '' + return config.feedsConfig[parent.feedFullName]?.routerAddress || '' }, deviation: async (parent, _args, { config }: Context) => { - return config[parent.feedFullName]?.deviation || '' + return config.feedsConfig[parent.feedFullName]?.deviation || '' }, heartbeat: async (parent, _args, { config }: Context) => { // Heartbeat plus aproximate time in milliseconds that takes to resolve the witnet dr - return config[parent.feedFullName]?.heartbeat || '' + return config.feedsConfig[parent.feedFullName]?.heartbeat || '' }, finality: async (parent, _args, { config }: Context) => { // Heartbeat plus aproximate time in milliseconds that takes to resolve the witnet dr - return config[parent.feedFullName]?.finality || '' + return config.feedsConfig[parent.feedFullName]?.finality || '' } } } diff --git a/packages/api/src/server.ts b/packages/api/src/server.ts index 7a412010..ea369f46 100644 --- a/packages/api/src/server.ts +++ b/packages/api/src/server.ts @@ -7,13 +7,14 @@ import { Loaders } from './loaders' export async function createServer ( repositories: Repositories, - config: Array + dataFeedsConfig: Array, + networksConfig: any ): Promise { return new ApolloServer({ typeDefs: [DIRECTIVES, typeDefs], resolvers, context: () => { - const configByFullName: ConfigByFullName = config.reduce( + const configByFullName: ConfigByFullName = dataFeedsConfig.reduce( (acc, feedInfo) => ({ ...acc, [`${feedInfo.feedFullName}`]: feedInfo @@ -22,10 +23,12 @@ export async function createServer ( ) const loaders = new Loaders(repositories) - return { ...repositories, - config: configByFullName, + config: { + feedsConfig: configByFullName, + networksConfig: networksConfig + }, loaders: loaders.getLoaders() } } diff --git a/packages/api/src/typeDefs.ts b/packages/api/src/typeDefs.ts index 4c67717e..f201301b 100644 --- a/packages/api/src/typeDefs.ts +++ b/packages/api/src/typeDefs.ts @@ -29,6 +29,12 @@ const typeDefs = gql` total: Int! } + type NetworksConfig @entity { + chain: String + label: String + key: String + } + type ResultRequest @entity { id: String! @id drTxHash: String! @column @@ -39,11 +45,6 @@ const typeDefs = gql` timestamp: String! @column } - type Network @entity { - id: String! @id - label: String - } - # type DataRequest @entity(embedded: true) { # retrieval: String! @column # aggregation: String! @column @@ -54,7 +55,7 @@ const typeDefs = gql` feed(feedFullName: String!): Feed feeds(network: String): FeedsPage! requests(feedFullName: String!, page: Int!, size: Int!): [ResultRequest]! - networks: [Network]! + networks: [NetworksConfig]! } ` diff --git a/packages/api/src/types.ts b/packages/api/src/types.ts index 76e7af64..ea574f45 100644 --- a/packages/api/src/types.ts +++ b/packages/api/src/types.ts @@ -15,7 +15,10 @@ export type WithoutId = Omit export type Context = { feedRepository: FeedRepository resultRequestRepository: ResultRequestRepository - config: ConfigByFullName + config: { + feedsConfig: ConfigByFullName + networksConfig: any + } loaders: { lastResult: DataLoader requests: DataLoader< diff --git a/packages/api/src/utils/index.ts b/packages/api/src/utils/index.ts index f6d23477..ee1b6ef1 100644 --- a/packages/api/src/utils/index.ts +++ b/packages/api/src/utils/index.ts @@ -29,6 +29,39 @@ export function createFeedFullName (network, name, decimals) { return `${network}_${name.split('/').join('-')}_${decimals}` } +// normalize config to fit network schema +export function normalizeNetworkConfig (config: RouterDataFeedsConfig): any { + const chains: any = Object.keys(config.chains) + // const networks: any = Object.values( + // config.chains + // ).map(chain => Object.keys(chain.networks)) + + const networks: any = Object.values(config.chains).map(chain => + Object.values(chain.networks).map(value => value.name) + ) + + console.log( + Object.values(config.chains).map(chain => + Object.values(chain.networks).map(value => value.name) + ) + ) + + const networkConfig = networks.reduce((networks, network, index) => { + network.map(network => { + networks.push({ + label: network + .split(' ') + .join('-') + .toLowerCase(), + key: network, + chain: chains[index] + }) + }) + return networks + }, []) + return networkConfig +} + // normalize config to fit schema export function normalizeConfig ( @@ -61,7 +94,6 @@ export function normalizeConfig ( }, []) .flat() // Parse Feed adding common config - console.log('------', configs) const feeds: FeedInfosWithoutAbis = configs.reduce( (acc: FeedInfosWithoutAbis, config: ExtendedFeedConfig) => { const feedsArrayConfig: Array = Object.values( @@ -79,7 +111,6 @@ export function normalizeConfig ( ) feedsArray.forEach(feed => { - console.log('feed-----', feed) const chain = parseChainName(config.chain) const network = parseNetworkName(config.name) const name = parseDataName(feed.key) diff --git a/packages/ui/apollo/queries/networks.gql b/packages/ui/apollo/queries/networks.gql index 859a9b83..98c8fe75 100644 --- a/packages/ui/apollo/queries/networks.gql +++ b/packages/ui/apollo/queries/networks.gql @@ -1,5 +1,7 @@ query networks { networks { - label + label, + key, + chain, } } \ No newline at end of file diff --git a/packages/ui/assets/svg/moonbase.svg b/packages/ui/assets/svg/moonbeam.svg similarity index 100% rename from packages/ui/assets/svg/moonbase.svg rename to packages/ui/assets/svg/moonbeam.svg diff --git a/packages/ui/components/Main.vue b/packages/ui/components/Main.vue index a65f1470..d9cd6924 100644 --- a/packages/ui/components/Main.vue +++ b/packages/ui/components/Main.vue @@ -8,12 +8,11 @@

{{ $t('main.network_subtitle') }} - {{ selected[0].chain }} {{ selectedNetworks }}.

@@ -66,7 +65,7 @@ export default { }, selectedNetworks() { const result = this.selected.map((option) => { - return capitalizeFirstLetter(option.label.split('-')[1]) + return option.key }) return result.join(', ').replace(/, ([^,]*)$/, ' and $1') }, @@ -80,6 +79,7 @@ export default { }) }, methods: { + capitalizeFirstLetter, updateOptions(index) { this.$store.commit('deleteEmptyNetwork', { index }) }, diff --git a/packages/ui/utils/generateSelectOptions.js b/packages/ui/utils/generateSelectOptions.js index a5ede8ec..f03e5e32 100644 --- a/packages/ui/utils/generateSelectOptions.js +++ b/packages/ui/utils/generateSelectOptions.js @@ -1,19 +1,12 @@ -import { capitalizeFirstLetter } from '../utils/capitalizeFirstLetter' - export function generateSelectOptions(list) { if (!list) return {} - return list.reduce((chainByNetwork, chain) => { - const network = chain.label.split('-')[0] - const networkDetails = { - label: chain.label, - key: chain.label.split('-').map(capitalizeFirstLetter).join(' '), - chain: capitalizeFirstLetter(network), - } + return list.reduce((chainByNetwork, network) => { + const chain = network.chain // Initialize network entry if not exists - if (!chainByNetwork[network]) { - chainByNetwork[network] = [] + if (!chainByNetwork[chain]) { + chainByNetwork[chain] = [] } - chainByNetwork[network].push(networkDetails) + chainByNetwork[chain].push(network) return chainByNetwork }, {}) } From 208883ae85173dc39180163e0de05153429c0d47 Mon Sep 17 00:00:00 2001 From: gabaldon Date: Fri, 11 Mar 2022 10:12:24 +0100 Subject: [PATCH 06/19] fix(api): fix tests --- packages/api/src/index.ts | 6 +- packages/api/src/server.ts | 10 ++-- packages/api/src/utils/index.ts | 3 - packages/api/test/feeds.spec.ts | 10 +++- packages/api/test/validateFeedsConfig.spec.ts | 55 +++++++++++++++++++ .../tests/utils/generateSelectOptions.spec.js | 24 ++++---- 6 files changed, 85 insertions(+), 23 deletions(-) diff --git a/packages/api/src/index.ts b/packages/api/src/index.ts index d25baf1a..37c372b9 100644 --- a/packages/api/src/index.ts +++ b/packages/api/src/index.ts @@ -27,6 +27,10 @@ async function main () { feedRepository: new FeedRepository(dataFeeds), resultRequestRepository: new ResultRequestRepository(db, dataFeeds) } + const config = { + dataFeedsConfig: dataFeeds, + networksConfig: networksConfig + } const web3Middleware = new Web3Middleware( { repositories, Web3: Web3 }, @@ -34,7 +38,7 @@ async function main () { ) web3Middleware.listen() - const server = await createServer(repositories, dataFeeds, networksConfig) + const server = await createServer(repositories, config) server .listen({ host: '0.0.0.0', port: process.env.SERVER_PORT }) diff --git a/packages/api/src/server.ts b/packages/api/src/server.ts index ea369f46..4549947d 100644 --- a/packages/api/src/server.ts +++ b/packages/api/src/server.ts @@ -7,14 +7,16 @@ import { Loaders } from './loaders' export async function createServer ( repositories: Repositories, - dataFeedsConfig: Array, - networksConfig: any + config: { + dataFeedsConfig: Array, + networksConfig: any + } ): Promise { return new ApolloServer({ typeDefs: [DIRECTIVES, typeDefs], resolvers, context: () => { - const configByFullName: ConfigByFullName = dataFeedsConfig.reduce( + const configByFullName: ConfigByFullName = config.dataFeedsConfig.reduce( (acc, feedInfo) => ({ ...acc, [`${feedInfo.feedFullName}`]: feedInfo @@ -27,7 +29,7 @@ export async function createServer ( ...repositories, config: { feedsConfig: configByFullName, - networksConfig: networksConfig + networksConfig: config.networksConfig }, loaders: loaders.getLoaders() } diff --git a/packages/api/src/utils/index.ts b/packages/api/src/utils/index.ts index ee1b6ef1..45dde84e 100644 --- a/packages/api/src/utils/index.ts +++ b/packages/api/src/utils/index.ts @@ -32,9 +32,6 @@ export function createFeedFullName (network, name, decimals) { // normalize config to fit network schema export function normalizeNetworkConfig (config: RouterDataFeedsConfig): any { const chains: any = Object.keys(config.chains) - // const networks: any = Object.values( - // config.chains - // ).map(chain => Object.keys(chain.networks)) const networks: any = Object.values(config.chains).map(chain => Object.values(chain.networks).map(value => value.name) diff --git a/packages/api/test/feeds.spec.ts b/packages/api/test/feeds.spec.ts index 140730bf..22393107 100644 --- a/packages/api/test/feeds.spec.ts +++ b/packages/api/test/feeds.spec.ts @@ -6,9 +6,10 @@ import { CHART_RANGE } from './constants' import { MongoManager } from './../src/database' import { FeedRepository } from '../src/repository/Feed' import { ResultRequestRepository } from '../src/repository/ResultRequest' -import { readDataFeeds } from '../src/index' +import { readDataFeeds, readNetworks } from '../src/index' const dataFeeds = readDataFeeds() +const networksconfig = readNetworks() const state: { mongoManager: MongoManager @@ -29,9 +30,12 @@ describe.skip('feeds', function () { const server = await createServer( { feedRepository: new FeedRepository(dataFeeds), - resultRequestRepository: new ResultRequestRepository(db, dataFeeds) + resultRequestRepository: new ResultRequestRepository(db, dataFeeds), }, - dataFeeds + { + dataFeedsConfig: dataFeeds, + networksConfig: networksconfig + } ) await new Promise(resolve => { server.listen(info => { diff --git a/packages/api/test/validateFeedsConfig.spec.ts b/packages/api/test/validateFeedsConfig.spec.ts index ce558e37..40fbda09 100644 --- a/packages/api/test/validateFeedsConfig.spec.ts +++ b/packages/api/test/validateFeedsConfig.spec.ts @@ -20,6 +20,7 @@ describe('validateDataFeedsConfig', () => { contractId: '0x0000000000000000000000000000000000000000', deviation: '1', feedFullName: 'avalanche-fuji_avax-usd_6', + chain: 'avalanche', finality: '900000', heartbeat: '3600000', id: 'Price-AVAX/USD-6', @@ -36,6 +37,7 @@ describe('validateDataFeedsConfig', () => { contractId: '0x0000000000000000000000000000000000000000', deviation: '1', feedFullName: 'avalanche-fuji_btc-usd_6', + chain: 'avalanche', finality: '900000', heartbeat: '3600000', id: 'Price-BTC/USD-6', @@ -52,6 +54,7 @@ describe('validateDataFeedsConfig', () => { contractId: '0x0000000000000000000000000000000000000000', deviation: '1', feedFullName: 'avalanche-fuji_eth-usd_6', + chain: 'avalanche', finality: '900000', heartbeat: '3600000', id: 'Price-ETH/USD-6', @@ -69,6 +72,7 @@ describe('validateDataFeedsConfig', () => { color: '#1cd83d', deviation: '1', feedFullName: 'boba-rinkeby_boba-usdt_6', + chain: 'boba', finality: '900000', heartbeat: '86400000', id: 'Price-BOBA/USDT-6', @@ -86,6 +90,7 @@ describe('validateDataFeedsConfig', () => { color: '#1cd83d', deviation: '1', feedFullName: 'boba-rinkeby_btc-usd_6', + chain: 'boba', finality: '900000', heartbeat: '86400000', id: 'Price-BTC/USD-6', @@ -103,6 +108,7 @@ describe('validateDataFeedsConfig', () => { color: '#1cd83d', deviation: '1', feedFullName: 'boba-rinkeby_eth-usd_6', + chain: 'boba', finality: '900000', heartbeat: '86400000', id: 'Price-ETH/USD-6', @@ -120,6 +126,7 @@ describe('validateDataFeedsConfig', () => { contractId: '0x0000000000000000000000000000000000000000', deviation: '0.1', feedFullName: 'boba-rinkeby_frax-usdt_6', + chain: 'boba', finality: '900000', heartbeat: '86400000', id: 'Price-FRAX/USDT-6', @@ -137,6 +144,7 @@ describe('validateDataFeedsConfig', () => { color: '#1cd83d', deviation: '1', feedFullName: 'boba-rinkeby_fxs-usdt_6', + chain: 'boba', finality: '900000', heartbeat: '86400000', id: 'Price-FXS/USDT-6', @@ -154,6 +162,7 @@ describe('validateDataFeedsConfig', () => { color: '#1cd83d', deviation: '1', feedFullName: 'boba-rinkeby_omg-btc_9', + chain: 'boba', finality: '900000', heartbeat: '86400000', id: 'Price-OMG/BTC-9', @@ -171,6 +180,7 @@ describe('validateDataFeedsConfig', () => { color: '#1cd83d', deviation: '1', feedFullName: 'boba-rinkeby_omg-eth_9', + chain: 'boba', finality: '900000', heartbeat: '86400000', id: 'Price-OMG/ETH-9', @@ -188,6 +198,7 @@ describe('validateDataFeedsConfig', () => { color: '#1cd83d', deviation: '1', feedFullName: 'boba-rinkeby_omg-usdt_6', + chain: 'boba', finality: '900000', heartbeat: '86400000', id: 'Price-OMG/USDT-6', @@ -205,6 +216,7 @@ describe('validateDataFeedsConfig', () => { contractId: '0x0000000000000000000000000000000000000000', deviation: '0.1', feedFullName: 'boba-rinkeby_usdc-usd_6', + chain: 'boba', finality: '900000', heartbeat: '86400000', id: 'Price-USDC/USD-6', @@ -222,6 +234,7 @@ describe('validateDataFeedsConfig', () => { contractId: '0x0000000000000000000000000000000000000000', deviation: '0.1', feedFullName: 'boba-rinkeby_usdt-usd_6', + chain: 'boba', finality: '900000', heartbeat: '86400000', id: 'Price-USDT/USD-6', @@ -238,6 +251,7 @@ describe('validateDataFeedsConfig', () => { contractId: '0x0000000000000000000000000000000000000000', deviation: '1', feedFullName: 'boba-mainnet_boba-usdt_6', + chain: 'boba', finality: '900000', heartbeat: '86400000', id: 'Price-BOBA/USDT-6', @@ -254,6 +268,7 @@ describe('validateDataFeedsConfig', () => { contractId: '0x0000000000000000000000000000000000000000', deviation: '1', feedFullName: 'boba-mainnet_btc-usd_6', + chain: 'boba', finality: '900000', heartbeat: '86400000', id: 'Price-BTC/USD-6', @@ -270,6 +285,7 @@ describe('validateDataFeedsConfig', () => { contractId: '0x0000000000000000000000000000000000000000', deviation: '1', feedFullName: 'boba-mainnet_eth-usd_6', + chain: 'boba', finality: '900000', heartbeat: '86400000', id: 'Price-ETH/USD-6', @@ -286,6 +302,7 @@ describe('validateDataFeedsConfig', () => { contractId: '0x0000000000000000000000000000000000000000', deviation: '0.25', feedFullName: 'boba-mainnet_frax-usdt_6', + chain: 'boba', finality: '900000', heartbeat: '86400000', id: 'Price-FRAX/USDT-6', @@ -302,6 +319,7 @@ describe('validateDataFeedsConfig', () => { contractId: '0x0000000000000000000000000000000000000000', deviation: '0.25', feedFullName: 'boba-mainnet_usdc-usd_6', + chain: 'boba', finality: '900000', heartbeat: '86400000', id: 'Price-USDC/USD-6', @@ -318,6 +336,7 @@ describe('validateDataFeedsConfig', () => { contractId: '0x0000000000000000000000000000000000000000', deviation: '0.25', feedFullName: 'boba-mainnet_usdt-usd_6', + chain: 'boba', finality: '900000', heartbeat: '86400000', id: 'Price-USDT/USD-6', @@ -335,6 +354,7 @@ describe('validateDataFeedsConfig', () => { color: '#1cd8d2', deviation: '1', feedFullName: 'celo-alfajores_btc-usd_6', + chain: 'celo', finality: '900000', heartbeat: '3600000', id: 'Price-BTC/USD-6', @@ -352,6 +372,7 @@ describe('validateDataFeedsConfig', () => { color: '#1cd8d2', deviation: '1', feedFullName: 'celo-alfajores_celo-eur_6', + chain: 'celo', finality: '900000', heartbeat: '3600000', id: 'Price-CELO/EUR-6', @@ -369,6 +390,7 @@ describe('validateDataFeedsConfig', () => { color: '#1cd8d2', deviation: '1', feedFullName: 'celo-alfajores_celo-usd_6', + chain: 'celo', finality: '900000', heartbeat: '3600000', id: 'Price-CELO/USD-6', @@ -386,6 +408,7 @@ describe('validateDataFeedsConfig', () => { color: '#1cd8d2', deviation: '1', feedFullName: 'celo-alfajores_eth-usd_6', + chain: 'celo', finality: '900000', heartbeat: '3600000', id: 'Price-ETH/USD-6', @@ -402,6 +425,7 @@ describe('validateDataFeedsConfig', () => { color: '#ff8100', deviation: '1', feedFullName: 'celo-mainnet_celo-eur_6', + chain: 'celo', finality: '900000', heartbeat: '86400000', id: 'Price-CELO/EUR-6', @@ -418,6 +442,7 @@ describe('validateDataFeedsConfig', () => { color: '#ff8100', deviation: '1', feedFullName: 'celo-mainnet_celo-usd_6', + chain: 'celo', finality: '900000', heartbeat: '86400000', id: 'Price-CELO/USD-6', @@ -434,6 +459,7 @@ describe('validateDataFeedsConfig', () => { color: '#ff8100', deviation: '3.5', feedFullName: 'celo-mainnet_btc-usd_6', + chain: 'celo', finality: '900000', heartbeat: '86400000', id: 'Price-BTC/USD-6', @@ -450,6 +476,7 @@ describe('validateDataFeedsConfig', () => { color: '#ff8100', deviation: '3.5', feedFullName: 'celo-mainnet_eth-usd_6', + chain: 'celo', finality: '900000', heartbeat: '86400000', id: 'Price-ETH/USD-6', @@ -466,6 +493,7 @@ describe('validateDataFeedsConfig', () => { color: '#6600ff', deviation: '1', feedFullName: 'conflux-testnet_cfx-usdt_6', + chain: 'conflux', finality: '900000', heartbeat: '3600000', id: 'Price-CFX/USDT-6', @@ -482,6 +510,7 @@ describe('validateDataFeedsConfig', () => { color: '#6600ff', deviation: '1', feedFullName: 'conflux-testnet_btc-usd_6', + chain: 'conflux', finality: '900000', heartbeat: '3600000', id: 'Price-BTC/USD-6', @@ -498,6 +527,7 @@ describe('validateDataFeedsConfig', () => { color: '#6600ff', deviation: '1', feedFullName: 'conflux-testnet_eth-usd_6', + chain: 'conflux', finality: '900000', heartbeat: '3600000', id: 'Price-ETH/USD-6', @@ -514,6 +544,7 @@ describe('validateDataFeedsConfig', () => { color: '#ff0000', deviation: '1', feedFullName: 'conflux-tethys_cfx-usdt_6', + chain: 'conflux', finality: '900000', heartbeat: '3600000', id: 'Price-CFX/USDT-6', @@ -530,6 +561,7 @@ describe('validateDataFeedsConfig', () => { color: '#ff0000', deviation: '3.5', feedFullName: 'conflux-tethys_btc-usd_6', + chain: 'conflux', finality: '900000', heartbeat: '86400000', id: 'Price-BTC/USD-6', @@ -546,6 +578,7 @@ describe('validateDataFeedsConfig', () => { color: '#ff0000', deviation: '3.5', feedFullName: 'conflux-tethys_eth-usd_6', + chain: 'conflux', finality: '900000', heartbeat: '86400000', id: 'Price-ETH/USD-6', @@ -562,6 +595,7 @@ describe('validateDataFeedsConfig', () => { color: '#ff5599', deviation: '1', feedFullName: 'ethereum-goerli_btc-usd_6', + chain: 'ethereum', finality: '900000', heartbeat: '28800000', id: 'Price-BTC/USD-6', @@ -578,6 +612,7 @@ describe('validateDataFeedsConfig', () => { color: '#ff5599', deviation: '1', feedFullName: 'ethereum-goerli_eth-usd_6', + chain: 'ethereum', finality: '900000', heartbeat: '28800000', id: 'Price-ETH/USD-6', @@ -594,6 +629,7 @@ describe('validateDataFeedsConfig', () => { color: '#ff5599', deviation: '1', feedFullName: 'ethereum-rinkeby_btc-usd_6', + chain: 'ethereum', finality: '900000', heartbeat: '86400000', id: 'Price-BTC/USD-6', @@ -610,6 +646,7 @@ describe('validateDataFeedsConfig', () => { color: '#ff5599', deviation: '1', feedFullName: 'ethereum-rinkeby_eth-usd_6', + chain: 'ethereum', finality: '900000', heartbeat: '86400000', id: 'Price-ETH/USD-6', @@ -626,6 +663,7 @@ describe('validateDataFeedsConfig', () => { color: '#ff5599', deviation: '3.5', feedFullName: 'ethereum-mainnet_btc-usd_6', + chain: 'ethereum', finality: '900000', heartbeat: '86400000', id: 'Price-BTC/USD-6', @@ -642,6 +680,7 @@ describe('validateDataFeedsConfig', () => { color: '#ff5599', deviation: '3.5', feedFullName: 'ethereum-mainnet_eth-usd_6', + chain: 'ethereum', finality: '900000', heartbeat: '86400000', id: 'Price-ETH/USD-6', @@ -658,6 +697,7 @@ describe('validateDataFeedsConfig', () => { color: '#f6006f', deviation: '1', feedFullName: 'harmony-testnet_btc-usd_6', + chain: 'harmony', finality: '900000', heartbeat: '3600000', id: 'Price-BTC/USD-6', @@ -674,6 +714,7 @@ describe('validateDataFeedsConfig', () => { color: '#f6006f', deviation: '1', feedFullName: 'harmony-testnet_eth-usd_6', + chain: 'harmony', finality: '900000', heartbeat: '3600000', id: 'Price-ETH/USD-6', @@ -690,6 +731,7 @@ describe('validateDataFeedsConfig', () => { color: '#ff0066', deviation: '0.5', feedFullName: 'kcc-testnet_kcs-usdt_6', + chain: 'kcc', finality: '900000', heartbeat: '600000', id: 'Price-KCS/USDT-6', @@ -706,6 +748,7 @@ describe('validateDataFeedsConfig', () => { color: '#ff0066', deviation: '0.5', feedFullName: 'kcc-testnet_btc-usd_6', + chain: 'kcc', finality: '900000', heartbeat: '600000', id: 'Price-BTC/USD-6', @@ -722,6 +765,7 @@ describe('validateDataFeedsConfig', () => { color: '#ff0066', deviation: '0.5', feedFullName: 'kcc-testnet_eth-usd_6', + chain: 'kcc', finality: '900000', heartbeat: '600000', id: 'Price-ETH/USD-6', @@ -738,6 +782,7 @@ describe('validateDataFeedsConfig', () => { color: '#ff0066', deviation: '0.5', feedFullName: 'kcc-mainnet_kcs-usdt_6', + chain: 'kcc', finality: '900000', heartbeat: '600000', id: 'Price-KCS/USDT-6', @@ -754,6 +799,7 @@ describe('validateDataFeedsConfig', () => { color: '#ff0066', deviation: '0.5', feedFullName: 'kcc-mainnet_btc-usd_6', + chain: 'kcc', finality: '900000', heartbeat: '600000', id: 'Price-BTC/USD-6', @@ -770,6 +816,7 @@ describe('validateDataFeedsConfig', () => { color: '#ff0066', deviation: '0.5', feedFullName: 'kcc-mainnet_eth-usd_6', + chain: 'kcc', finality: '900000', heartbeat: '600000', id: 'Price-ETH/USD-6', @@ -786,6 +833,7 @@ describe('validateDataFeedsConfig', () => { color: '#ff6600', deviation: '1', feedFullName: 'metis-rinkeby_metis-usdt_6', + chain: 'metis', finality: '900000', heartbeat: '86400000', id: 'Price-METIS/USDT-6', @@ -802,6 +850,7 @@ describe('validateDataFeedsConfig', () => { color: '#ff6600', deviation: '1', feedFullName: 'metis-rinkeby_btc-usd_6', + chain: 'metis', finality: '900000', heartbeat: '86400000', id: 'Price-BTC/USD-6', @@ -818,6 +867,7 @@ describe('validateDataFeedsConfig', () => { color: '#ff6600', deviation: '1', feedFullName: 'metis-rinkeby_eth-usd_6', + chain: 'metis', finality: '900000', heartbeat: '86400000', id: 'Price-ETH/USD-6', @@ -834,6 +884,7 @@ describe('validateDataFeedsConfig', () => { color: '#ff6600', deviation: '2', feedFullName: 'metis-mainnet_metis-usdt_6', + chain: 'metis', finality: '900000', heartbeat: '86400000', id: 'Price-METIS/USDT-6', @@ -850,6 +901,7 @@ describe('validateDataFeedsConfig', () => { color: '#66ff00', deviation: '3.5', feedFullName: 'polygon-goerli_btc-usd_6', + chain: 'polygon', finality: '900000', heartbeat: '86400000', id: 'Price-BTC/USD-6', @@ -866,6 +918,7 @@ describe('validateDataFeedsConfig', () => { color: '#66ff00', deviation: '3.5', feedFullName: 'polygon-goerli_eth-usd_6', + chain: 'polygon', finality: '900000', heartbeat: '86400000', id: 'Price-ETH/USD-6', @@ -882,6 +935,7 @@ describe('validateDataFeedsConfig', () => { contractId: '0x0000000000000000000000000000000000000000', deviation: '1', feedFullName: 'polygon-mainnet_btc-usd_6', + chain: 'polygon', finality: '900000', heartbeat: '86400000', id: 'Price-BTC/USD-6', @@ -898,6 +952,7 @@ describe('validateDataFeedsConfig', () => { contractId: '0x0000000000000000000000000000000000000000', deviation: '1', feedFullName: 'polygon-mainnet_eth-usd_6', + chain: 'polygon', finality: '900000', heartbeat: '86400000', id: 'Price-ETH/USD-6', diff --git a/packages/ui/tests/utils/generateSelectOptions.spec.js b/packages/ui/tests/utils/generateSelectOptions.spec.js index 37f79d2b..fa6d2880 100644 --- a/packages/ui/tests/utils/generateSelectOptions.spec.js +++ b/packages/ui/tests/utils/generateSelectOptions.spec.js @@ -3,33 +3,33 @@ import { generateSelectOptions } from '../../utils/generateSelectOptions' describe('generateSelectOptions.js', () => { it('should generate a list of options from a list of feeds', () => { const networks = [ - { label: 'ethereum-rinkeby' }, - { label: 'ethereum-goerli' }, - { label: 'conflux-testnet' }, - { label: 'boba-rinkeby' }, + { label: 'ethereum-rinkeby', key: 'Ethereum Rinkeby', chain: 'Ethereum' }, + { label: 'ethereum-goerli', key: 'Ethereum Goerly', chain: 'Ethereum' }, + { label: 'conflux-testnet', key: 'Conflux Testnet', chain: 'Conflux' }, + { label: 'boba-rinkeby', key: 'Boba Rinkeby', chain: 'Boba' }, ] const options = generateSelectOptions(networks) expect(options).toStrictEqual({ - boba: [{ key: 'Boba Rinkeby', label: 'boba-rinkeby', network: 'Boba' }], - conflux: [ + Boba: [{ key: 'Boba Rinkeby', label: 'boba-rinkeby', chain: 'Boba' }], + Conflux: [ { key: 'Conflux Testnet', label: 'conflux-testnet', - network: 'Conflux', + chain: 'Conflux', }, ], - ethereum: [ + Ethereum: [ { - key: 'Ethereum Rinkeby', label: 'ethereum-rinkeby', - network: 'Ethereum', + key: 'Ethereum Rinkeby', + chain: 'Ethereum', }, { - key: 'Ethereum Goerli', label: 'ethereum-goerli', - network: 'Ethereum', + key: 'Ethereum Goerly', + chain: 'Ethereum', }, ], }) From f32661a99f85d96c75d24dc9e4105125e8ce2702 Mon Sep 17 00:00:00 2001 From: gabaldon Date: Fri, 11 Mar 2022 10:29:50 +0100 Subject: [PATCH 07/19] feat(ui): add immo/mcusd to celo --- packages/api/src/dataFeedsRouter.json | 12 ++++++++++++ packages/api/src/server.ts | 2 +- packages/api/test/feeds.spec.ts | 2 +- packages/ui/assets/svg/immo.svg | 5 +++++ 4 files changed, 19 insertions(+), 2 deletions(-) create mode 100644 packages/ui/assets/svg/immo.svg diff --git a/packages/api/src/dataFeedsRouter.json b/packages/api/src/dataFeedsRouter.json index 9702e7d0..bfa2a4af 100644 --- a/packages/api/src/dataFeedsRouter.json +++ b/packages/api/src/dataFeedsRouter.json @@ -206,6 +206,12 @@ "deviationPercentage": 1.0, "maxSecsBetweenUpdates": 3600, "minSecsBetweenUpdates": 300 + }, + "Price-IMMO/MCUSD-6": { + "label": "$", + "deviationPercentage": 1.0, + "maxSecsBetweenUpdates": 3600, + "minSecsBetweenUpdates": 300 } } }, @@ -239,6 +245,12 @@ "deviationPercentage": 3.5, "maxSecsBetweenUpdates": 86400, "minSecsBetweenUpdates": 3600 + }, + "Price-IMMO/MCUSD-6": { + "label": "$", + "deviationPercentage": 1.0, + "maxSecsBetweenUpdates": 86400, + "minSecsBetweenUpdates": 3600 } } } diff --git a/packages/api/src/server.ts b/packages/api/src/server.ts index 4549947d..db365cb0 100644 --- a/packages/api/src/server.ts +++ b/packages/api/src/server.ts @@ -8,7 +8,7 @@ import { Loaders } from './loaders' export async function createServer ( repositories: Repositories, config: { - dataFeedsConfig: Array, + dataFeedsConfig: Array networksConfig: any } ): Promise { diff --git a/packages/api/test/feeds.spec.ts b/packages/api/test/feeds.spec.ts index 22393107..2b8d4fc2 100644 --- a/packages/api/test/feeds.spec.ts +++ b/packages/api/test/feeds.spec.ts @@ -30,7 +30,7 @@ describe.skip('feeds', function () { const server = await createServer( { feedRepository: new FeedRepository(dataFeeds), - resultRequestRepository: new ResultRequestRepository(db, dataFeeds), + resultRequestRepository: new ResultRequestRepository(db, dataFeeds) }, { dataFeedsConfig: dataFeeds, diff --git a/packages/ui/assets/svg/immo.svg b/packages/ui/assets/svg/immo.svg new file mode 100644 index 00000000..5e6c2b82 --- /dev/null +++ b/packages/ui/assets/svg/immo.svg @@ -0,0 +1,5 @@ + + + + + From bd87878dd755d3fe60228c34e662b8202e15cb9f Mon Sep 17 00:00:00 2001 From: gabaldon Date: Fri, 11 Mar 2022 11:01:36 +0100 Subject: [PATCH 08/19] fix(api): add missing types --- packages/api/src/index.ts | 11 ++++------- packages/api/src/resolvers.ts | 3 +-- packages/api/src/server.ts | 9 +++++++-- packages/api/src/types.ts | 9 ++++++++- packages/api/src/utils/index.ts | 20 ++++++++++++-------- packages/ui/components/Main.vue | 1 + 6 files changed, 33 insertions(+), 20 deletions(-) diff --git a/packages/api/src/index.ts b/packages/api/src/index.ts index 37c372b9..8805f38a 100644 --- a/packages/api/src/index.ts +++ b/packages/api/src/index.ts @@ -11,7 +11,8 @@ import { FeedInfo, FeedInfoConfig, Repositories, - RouterDataFeedsConfig + RouterDataFeedsConfig, + NetworksConfig } from './types' import { Web3Middleware } from './web3Middleware/index' import { normalizeConfig, normalizeNetworkConfig } from './utils/index' @@ -47,12 +48,8 @@ async function main () { }) } -export function readNetworks (): any { - const dataFeeds: Array> = normalizeNetworkConfig(dataFeedsRouterConfig as RouterDataFeedsConfig) - return dataFeeds +export function readNetworks (): Array { + return normalizeNetworkConfig(dataFeedsRouterConfig as RouterDataFeedsConfig) } export function readDataFeeds (): Array { diff --git a/packages/api/src/resolvers.ts b/packages/api/src/resolvers.ts index 68a71983..2ecbe18f 100644 --- a/packages/api/src/resolvers.ts +++ b/packages/api/src/resolvers.ts @@ -5,8 +5,7 @@ const resolvers = { return await feedRepository.getFeedsByNetwork(args.network) }, - networks: async (_parent, _args, { config }) => { - console.log('--new networks config in RESOLVERS--', config.networksConfig) + networks: (_parent, _args, { config }): Context => { return config.networksConfig }, diff --git a/packages/api/src/server.ts b/packages/api/src/server.ts index db365cb0..bcb11c41 100644 --- a/packages/api/src/server.ts +++ b/packages/api/src/server.ts @@ -2,14 +2,19 @@ import { ApolloServer } from 'apollo-server' import typeDefs from './typeDefs' import { DIRECTIVES } from '@graphql-codegen/typescript-mongodb' import resolvers from './resolvers' -import { ConfigByFullName, FeedInfo, Repositories } from './types' import { Loaders } from './loaders' +import { + ConfigByFullName, + FeedInfo, + Repositories, + NetworksConfig +} from './types' export async function createServer ( repositories: Repositories, config: { dataFeedsConfig: Array - networksConfig: any + networksConfig: Array } ): Promise { return new ApolloServer({ diff --git a/packages/api/src/types.ts b/packages/api/src/types.ts index ea574f45..dcf2377d 100644 --- a/packages/api/src/types.ts +++ b/packages/api/src/types.ts @@ -17,7 +17,7 @@ export type Context = { resultRequestRepository: ResultRequestRepository config: { feedsConfig: ConfigByFullName - networksConfig: any + networksConfig: NetworksConfig } loaders: { lastResult: DataLoader @@ -91,6 +91,13 @@ export type FeedInfoGeneric = { heartbeat: string finality: string } + +export type NetworksConfig = { + chain: String + label: String + key: String +} + export type FeedInfo = FeedInfoGeneric> export type FeedInfoConfig = FeedInfoGeneric diff --git a/packages/api/src/utils/index.ts b/packages/api/src/utils/index.ts index 45dde84e..67d6a324 100644 --- a/packages/api/src/utils/index.ts +++ b/packages/api/src/utils/index.ts @@ -5,7 +5,8 @@ import { FeedParamsConfig, FeedParsedParams, NetworkConfigMap, - RouterDataFeedsConfig + RouterDataFeedsConfig, + NetworksConfig } from '../types' // parse network name to fit schema export function parseNetworkName (value) { @@ -30,18 +31,21 @@ export function createFeedFullName (network, name, decimals) { } // normalize config to fit network schema -export function normalizeNetworkConfig (config: RouterDataFeedsConfig): any { - const chains: any = Object.keys(config.chains) + +export function normalizeNetworkConfig ( + config: RouterDataFeedsConfig +): Array { + // get list of chains + + const chains: Array = Object.keys(config.chains) + + // get list of networks const networks: any = Object.values(config.chains).map(chain => Object.values(chain.networks).map(value => value.name) ) - console.log( - Object.values(config.chains).map(chain => - Object.values(chain.networks).map(value => value.name) - ) - ) + // add chain to each of the networks const networkConfig = networks.reduce((networks, network, index) => { network.map(network => { diff --git a/packages/ui/components/Main.vue b/packages/ui/components/Main.vue index d9cd6924..ac8bc4e3 100644 --- a/packages/ui/components/Main.vue +++ b/packages/ui/components/Main.vue @@ -58,6 +58,7 @@ export default { }, options() { if (this.networks) { + console.log(this.networks) return generateSelectOptions(this.networks) } else { return null From 354190dbd0b3b931de9da4807a019fb5685f328f Mon Sep 17 00:00:00 2001 From: gabaldon Date: Fri, 11 Mar 2022 12:04:15 +0100 Subject: [PATCH 09/19] fix(api): change key and label values --- packages/api/src/types.ts | 14 +------------ packages/api/src/utils/index.ts | 21 +++++++++++-------- packages/api/src/web3Middleware/provider.ts | 2 +- packages/ui/components/DataFeeds.vue | 2 +- packages/ui/components/Main.vue | 7 +++---- .../ui/components/breadcrumbs/BreadCrumbs.vue | 2 +- packages/ui/store/index.js | 4 ++-- 7 files changed, 21 insertions(+), 31 deletions(-) diff --git a/packages/api/src/types.ts b/packages/api/src/types.ts index dcf2377d..b5b62d6d 100644 --- a/packages/api/src/types.ts +++ b/packages/api/src/types.ts @@ -38,18 +38,6 @@ export type Context = { export type ConfigByFullName = { [key: string]: FeedInfo } -export enum Chain { - Ethereum = 'ethereum', - Avalanche = 'avalanche', - Boba = 'boba', - Conflux = 'conflux', - Celo = 'celo', - Harmony = 'harmony', - Metis = 'metis', - Moonbeam = 'moonbeam', - Polygon = 'polygon', - KCC = 'KCC' -} export enum Network { EthereumMainnet = 'ethereum-mainnet', @@ -65,7 +53,7 @@ export enum Network { HarmonyTestnet = 'harmony-testnet', MetisMainnet = 'metis-mainnet', MetisRinkeby = 'metis-rinkeby', - MoonbaseAlpha = 'moonbase-alpha', + MoonbeamMoonbase = 'moonbeam-moonbase', PolygonMainnet = 'polygon-mainnet', PolygonGoerli = 'polygon-goerli', KCCMainnet = 'KCC-mainnet', diff --git a/packages/api/src/utils/index.ts b/packages/api/src/utils/index.ts index 67d6a324..95431fc8 100644 --- a/packages/api/src/utils/index.ts +++ b/packages/api/src/utils/index.ts @@ -12,7 +12,7 @@ import { export function parseNetworkName (value) { return value .toLowerCase() - .split(' ') + .split('.') .join('-') } export function parseChainName (value) { @@ -40,9 +40,16 @@ export function normalizeNetworkConfig ( const chains: Array = Object.keys(config.chains) // get list of networks - const networks: any = Object.values(config.chains).map(chain => - Object.values(chain.networks).map(value => value.name) + Object.values(chain.networks).map((value, index) => { + return { + key: Object.keys(chain.networks) + [index].split('.') + .join('-') + .toLowerCase(), + label: value.name + } + }) ) // add chain to each of the networks @@ -50,11 +57,7 @@ export function normalizeNetworkConfig ( const networkConfig = networks.reduce((networks, network, index) => { network.map(network => { networks.push({ - label: network - .split(' ') - .join('-') - .toLowerCase(), - key: network, + ...network, chain: chains[index] }) }) @@ -113,7 +116,7 @@ export function normalizeConfig ( feedsArray.forEach(feed => { const chain = parseChainName(config.chain) - const network = parseNetworkName(config.name) + const network = parseNetworkName(config.chain) const name = parseDataName(feed.key) const decimals = parseDataDecimals(feed.key) diff --git a/packages/api/src/web3Middleware/provider.ts b/packages/api/src/web3Middleware/provider.ts index ae0a2591..48d527ab 100644 --- a/packages/api/src/web3Middleware/provider.ts +++ b/packages/api/src/web3Middleware/provider.ts @@ -16,7 +16,7 @@ export function getProvider (network: Network) { [Network.HarmonyTestnet]: process.env.HARMONY_TESTNET_PROVIDER, [Network.KCCTestnet]: process.env.KCC_TESTNET_PROVIDER, [Network.KCCMainnet]: process.env.KCC_MAINNET_PROVIDER, - [Network.MoonbaseAlpha]: process.env.MOONBASE_ALPHA_PROVIDER, + [Network.MoonbeamMoonbase]: process.env.MOONBASE_ALPHA_PROVIDER, [Network.PolygonMainnet]: process.env.POLYGON_MAINNET_PROVIDER, [Network.PolygonGoerli]: process.env.POLYGON_GOERLI_PROVIDER, [Network.AvalancheFuji]: process.env.AVALANCHE_FUJI_PROVIDER diff --git a/packages/ui/components/DataFeeds.vue b/packages/ui/components/DataFeeds.vue index facbc352..14f1f4eb 100644 --- a/packages/ui/components/DataFeeds.vue +++ b/packages/ui/components/DataFeeds.vue @@ -29,7 +29,7 @@ export default { query: feeds, variables() { return { - network: this.network.label.toLowerCase(), + network: this.network.key.toLowerCase(), } }, pollInterval: 60000, diff --git a/packages/ui/components/Main.vue b/packages/ui/components/Main.vue index ac8bc4e3..7a54992f 100644 --- a/packages/ui/components/Main.vue +++ b/packages/ui/components/Main.vue @@ -19,10 +19,10 @@
-
{{ option.key }}
+
{{ option.label }}
{ - return option.key + return option.label }) return result.join(', ').replace(/, ([^,]*)$/, ' and $1') }, diff --git a/packages/ui/components/breadcrumbs/BreadCrumbs.vue b/packages/ui/components/breadcrumbs/BreadCrumbs.vue index d15c7201..71742b62 100644 --- a/packages/ui/components/breadcrumbs/BreadCrumbs.vue +++ b/packages/ui/components/breadcrumbs/BreadCrumbs.vue @@ -2,7 +2,7 @@