From dfae2249659a5dc80a33c6111056bcaf6011da47 Mon Sep 17 00:00:00 2001 From: Keno Budde Date: Thu, 29 Oct 2020 00:58:33 +0100 Subject: [PATCH 1/2] removed unused data query and corrected health query --- .vscode/settings.json | 3 -- src/apollo/client.js | 20 ++++------- src/apollo/queries.js | 79 ++++++++++++++---------------------------- src/contexts/V1Data.js | 58 ------------------------------- 4 files changed, 32 insertions(+), 128 deletions(-) delete mode 100644 .vscode/settings.json delete mode 100644 src/contexts/V1Data.js diff --git a/.vscode/settings.json b/.vscode/settings.json deleted file mode 100644 index 23fd35f..0000000 --- a/.vscode/settings.json +++ /dev/null @@ -1,3 +0,0 @@ -{ - "editor.formatOnSave": true -} \ No newline at end of file diff --git a/src/apollo/client.js b/src/apollo/client.js index 9395018..e5f8334 100644 --- a/src/apollo/client.js +++ b/src/apollo/client.js @@ -4,31 +4,23 @@ import { HttpLink } from 'apollo-link-http' export const client = new ApolloClient({ link: new HttpLink({ - uri: 'https://api.thegraph.com/subgraphs/name/zippoxer/sushiswap-subgraph-fork' + uri: 'https://api.thegraph.com/subgraphs/name/zippoxer/sushiswap-subgraph-fork', }), cache: new InMemoryCache(), - shouldBatch: true + shouldBatch: true, }) export const healthClient = new ApolloClient({ link: new HttpLink({ - uri: 'https://api.thegraph.com/index-node/graphql' + uri: 'https://api.thegraph.com/index-node/graphql', }), cache: new InMemoryCache(), - shouldBatch: true -}) - -export const v1Client = new ApolloClient({ - link: new HttpLink({ - uri: 'https://api.thegraph.com/subgraphs/name/ianlapham/uniswap' - }), - cache: new InMemoryCache(), - shouldBatch: true + shouldBatch: true, }) export const blockClient = new ApolloClient({ link: new HttpLink({ - uri: 'https://api.thegraph.com/subgraphs/name/blocklytics/ethereum-blocks' + uri: 'https://api.thegraph.com/subgraphs/name/blocklytics/ethereum-blocks', }), - cache: new InMemoryCache() + cache: new InMemoryCache(), }) diff --git a/src/apollo/queries.js b/src/apollo/queries.js index f1658a6..32ee4db 100644 --- a/src/apollo/queries.js +++ b/src/apollo/queries.js @@ -3,7 +3,7 @@ import { FACTORY_ADDRESS, BUNDLE_ID } from '../constants' export const SUBGRAPH_HEALTH = gql` query health { - indexingStatusForCurrentVersion(subgraphName: "ianlapham/uniswapv2") { + indexingStatusForCurrentVersion(subgraphName: "zippoxer/sushiswap-subgraph-fork") { synced health chains { @@ -18,34 +18,6 @@ export const SUBGRAPH_HEALTH = gql` } ` -export const V1_DATA_QUERY = gql` - query uniswap($date: Int!, $date2: Int!) { - current: uniswap(id: "1") { - totalVolumeUSD - totalLiquidityUSD - txCount - } - oneDay: uniswapHistoricalDatas(where: { timestamp_lt: $date }, first: 1, orderBy: timestamp, orderDirection: desc) { - totalVolumeUSD - totalLiquidityUSD - txCount - } - twoDay: uniswapHistoricalDatas( - where: { timestamp_lt: $date2 } - first: 1 - orderBy: timestamp - orderDirection: desc - ) { - totalVolumeUSD - totalLiquidityUSD - txCount - } - exchanges(first: 200, orderBy: ethBalance, orderDirection: desc) { - ethBalance - } - } -` - export const GET_BLOCK = gql` query blocks($timestampFrom: Int!, $timestampTo: Int!) { blocks( @@ -61,11 +33,12 @@ export const GET_BLOCK = gql` } ` -export const GET_BLOCKS = timestamps => { +export const GET_BLOCKS = (timestamps) => { let queryString = 'query blocks {' - queryString += timestamps.map(timestamp => { - return `t${timestamp}:blocks(first: 1, orderBy: timestamp, orderDirection: desc, where: { timestamp_gt: ${timestamp}, timestamp_lt: ${timestamp + - 600} }) { + queryString += timestamps.map((timestamp) => { + return `t${timestamp}:blocks(first: 1, orderBy: timestamp, orderDirection: desc, where: { timestamp_gt: ${timestamp}, timestamp_lt: ${ + timestamp + 600 + } }) { number }` }) @@ -76,8 +49,8 @@ export const GET_BLOCKS = timestamps => { export const POSITIONS_BY_BLOCK = (account, blocks) => { let queryString = 'query blocks {' queryString += blocks.map( - block => ` - t${block.timestamp}:liquidityPositions(where: {user: "${account}"}, block: { number: ${block.number} }) { + (block) => ` + t${block.timestamp}:liquidityPositions(where: {user: "${account}"}, block: { number: ${block.number} }) { liquidityTokenBalance pair { id @@ -94,16 +67,16 @@ export const POSITIONS_BY_BLOCK = (account, blocks) => { export const PRICES_BY_BLOCK = (tokenAddress, blocks) => { let queryString = 'query blocks {' queryString += blocks.map( - block => ` - t${block.timestamp}:token(id:"${tokenAddress}", block: { number: ${block.number} }) { + (block) => ` + t${block.timestamp}:token(id:"${tokenAddress}", block: { number: ${block.number} }) { derivedETH } ` ) queryString += ',' queryString += blocks.map( - block => ` - b${block.timestamp}: bundle(id:"1", block: { number: ${block.number} }) { + (block) => ` + b${block.timestamp}: bundle(id:"1", block: { number: ${block.number} }) { ethPrice } ` @@ -130,8 +103,8 @@ export const TOP_LPS_PER_PAIRS = gql` export const HOURLY_PAIR_RATES = (pairAddress, blocks) => { let queryString = 'query blocks {' queryString += blocks.map( - block => ` - t${block.timestamp}: pair(id:"${pairAddress}", block: { number: ${block.number} }) { + (block) => ` + t${block.timestamp}: pair(id:"${pairAddress}", block: { number: ${block.number} }) { token0Price token1Price } @@ -145,12 +118,12 @@ export const HOURLY_PAIR_RATES = (pairAddress, blocks) => { export const SHARE_VALUE = (pairAddress, blocks) => { let queryString = 'query blocks {' queryString += blocks.map( - block => ` - t${block.timestamp}:pair(id:"${pairAddress}", block: { number: ${block.number} }) { + (block) => ` + t${block.timestamp}:pair(id:"${pairAddress}", block: { number: ${block.number} }) { reserve0 reserve1 reserveUSD - totalSupply + totalSupply token0{ derivedETH } @@ -162,8 +135,8 @@ export const SHARE_VALUE = (pairAddress, blocks) => { ) queryString += ',' queryString += blocks.map( - block => ` - b${block.timestamp}: bundle(id:"1", block: { number: ${block.number} }) { + (block) => ` + b${block.timestamp}: bundle(id:"1", block: { number: ${block.number} }) { ethPrice } ` @@ -173,7 +146,7 @@ export const SHARE_VALUE = (pairAddress, blocks) => { return gql(queryString) } -export const ETH_PRICE = block => { +export const ETH_PRICE = (block) => { const queryString = block ? ` query bundles { @@ -397,7 +370,7 @@ export const PAIR_DAY_DATA = gql` export const PAIR_DAY_DATA_BULK = (pairs, startTimestamp) => { let pairsString = `[` - pairs.map(pair => { + pairs.map((pair) => { return (pairsString += `"${pair}"`) }) pairsString += ']' @@ -413,7 +386,7 @@ export const PAIR_DAY_DATA_BULK = (pairs, startTimestamp) => { totalSupply reserveUSD } - } + } ` return gql(queryString) } @@ -432,10 +405,10 @@ export const GLOBAL_CHART = gql` } ` -export const GLOBAL_DATA = block => { +export const GLOBAL_DATA = (block) => { const queryString = ` query uniswapFactories { uniswapFactories( - ${block ? `block: { number: ${block}}` : ``} + ${block ? `block: { number: ${block}}` : ``} where: { id: "${FACTORY_ADDRESS}" }) { id totalVolumeUSD @@ -679,7 +652,7 @@ export const PAIRS_BULK = gql` export const PAIRS_HISTORICAL_BULK = (block, pairs) => { let pairsString = `[` - pairs.map(pair => { + pairs.map((pair) => { return (pairsString += `"${pair}"`) }) pairsString += ']' @@ -747,7 +720,7 @@ export const TOKENS_CURRENT = gql` } ` -export const TOKENS_DYNAMIC = block => { +export const TOKENS_DYNAMIC = (block) => { const queryString = ` ${TokenFields} query tokens { diff --git a/src/contexts/V1Data.js b/src/contexts/V1Data.js deleted file mode 100644 index 1fd95d3..0000000 --- a/src/contexts/V1Data.js +++ /dev/null @@ -1,58 +0,0 @@ -import { v1Client } from '../apollo/client' -import dayjs from 'dayjs' -import utc from 'dayjs/plugin/utc' -import { getPercentChange, get2DayPercentChange } from '../utils' -import { V1_DATA_QUERY } from '../apollo/queries' -import weekOfYear from 'dayjs/plugin/weekOfYear' - -dayjs.extend(utc) -dayjs.extend(weekOfYear) - -export async function getV1Data() { - dayjs.extend(utc) - - const utcCurrentTime = dayjs() - const utcOneDayBack = utcCurrentTime.subtract(1, 'day').unix() - const utcTwoDaysBack = utcCurrentTime.subtract(2, 'day').unix() - - try { - // get the current data - let result = await v1Client.query({ - query: V1_DATA_QUERY, - variables: { - date: utcOneDayBack, - date2: utcTwoDaysBack - }, - fetchPolicy: 'cache-first' - }) - - let data = result.data.current - let oneDayData = result.data.oneDay[0] - let twoDayData = result.data.twoDay[0] - - let [volumeChangeUSD, volumePercentChangeUSD] = get2DayPercentChange( - data.totalVolumeUSD, - oneDayData.totalVolumeUSD, - twoDayData.totalVolumeUSD - ) - - let [txCountChange, txCountPercentChange] = get2DayPercentChange( - data.txCount, - oneDayData.txCount, - twoDayData.txCount - ) - - // regular percent changes - let liquidityPercentChangeUSD = getPercentChange(data.liquidityUsd, oneDayData.liquidityUsd) - - data.liquidityPercentChangeUSD = liquidityPercentChangeUSD - data.volumePercentChangeUSD = volumePercentChangeUSD - data.txCount = txCountChange - data.txCountPercentChange = txCountPercentChange - data.dailyVolumeUSD = volumeChangeUSD - - return data - } catch (err) { - console.log('error: ', err) - } -} From 129f8278f02a891575f5b8d7526ab179959b1a50 Mon Sep 17 00:00:00 2001 From: Keno Budde Date: Thu, 29 Oct 2020 01:15:19 +0100 Subject: [PATCH 2/2] fix formatting --- src/apollo/client.js | 12 ++++++------ src/apollo/queries.js | 31 +++++++++++++++---------------- 2 files changed, 21 insertions(+), 22 deletions(-) diff --git a/src/apollo/client.js b/src/apollo/client.js index e5f8334..5ed96f7 100644 --- a/src/apollo/client.js +++ b/src/apollo/client.js @@ -4,23 +4,23 @@ import { HttpLink } from 'apollo-link-http' export const client = new ApolloClient({ link: new HttpLink({ - uri: 'https://api.thegraph.com/subgraphs/name/zippoxer/sushiswap-subgraph-fork', + uri: 'https://api.thegraph.com/subgraphs/name/zippoxer/sushiswap-subgraph-fork' }), cache: new InMemoryCache(), - shouldBatch: true, + shouldBatch: true }) export const healthClient = new ApolloClient({ link: new HttpLink({ - uri: 'https://api.thegraph.com/index-node/graphql', + uri: 'https://api.thegraph.com/index-node/graphql' }), cache: new InMemoryCache(), - shouldBatch: true, + shouldBatch: true }) export const blockClient = new ApolloClient({ link: new HttpLink({ - uri: 'https://api.thegraph.com/subgraphs/name/blocklytics/ethereum-blocks', + uri: 'https://api.thegraph.com/subgraphs/name/blocklytics/ethereum-blocks' }), - cache: new InMemoryCache(), + cache: new InMemoryCache() }) diff --git a/src/apollo/queries.js b/src/apollo/queries.js index 32ee4db..12c7d89 100644 --- a/src/apollo/queries.js +++ b/src/apollo/queries.js @@ -33,12 +33,11 @@ export const GET_BLOCK = gql` } ` -export const GET_BLOCKS = (timestamps) => { +export const GET_BLOCKS = timestamps => { let queryString = 'query blocks {' - queryString += timestamps.map((timestamp) => { - return `t${timestamp}:blocks(first: 1, orderBy: timestamp, orderDirection: desc, where: { timestamp_gt: ${timestamp}, timestamp_lt: ${ - timestamp + 600 - } }) { + queryString += timestamps.map(timestamp => { + return `t${timestamp}:blocks(first: 1, orderBy: timestamp, orderDirection: desc, where: { timestamp_gt: ${timestamp}, timestamp_lt: ${timestamp + + 600} }) { number }` }) @@ -49,7 +48,7 @@ export const GET_BLOCKS = (timestamps) => { export const POSITIONS_BY_BLOCK = (account, blocks) => { let queryString = 'query blocks {' queryString += blocks.map( - (block) => ` + block => ` t${block.timestamp}:liquidityPositions(where: {user: "${account}"}, block: { number: ${block.number} }) { liquidityTokenBalance pair { @@ -67,7 +66,7 @@ export const POSITIONS_BY_BLOCK = (account, blocks) => { export const PRICES_BY_BLOCK = (tokenAddress, blocks) => { let queryString = 'query blocks {' queryString += blocks.map( - (block) => ` + block => ` t${block.timestamp}:token(id:"${tokenAddress}", block: { number: ${block.number} }) { derivedETH } @@ -75,7 +74,7 @@ export const PRICES_BY_BLOCK = (tokenAddress, blocks) => { ) queryString += ',' queryString += blocks.map( - (block) => ` + block => ` b${block.timestamp}: bundle(id:"1", block: { number: ${block.number} }) { ethPrice } @@ -103,7 +102,7 @@ export const TOP_LPS_PER_PAIRS = gql` export const HOURLY_PAIR_RATES = (pairAddress, blocks) => { let queryString = 'query blocks {' queryString += blocks.map( - (block) => ` + block => ` t${block.timestamp}: pair(id:"${pairAddress}", block: { number: ${block.number} }) { token0Price token1Price @@ -118,7 +117,7 @@ export const HOURLY_PAIR_RATES = (pairAddress, blocks) => { export const SHARE_VALUE = (pairAddress, blocks) => { let queryString = 'query blocks {' queryString += blocks.map( - (block) => ` + block => ` t${block.timestamp}:pair(id:"${pairAddress}", block: { number: ${block.number} }) { reserve0 reserve1 @@ -135,7 +134,7 @@ export const SHARE_VALUE = (pairAddress, blocks) => { ) queryString += ',' queryString += blocks.map( - (block) => ` + block => ` b${block.timestamp}: bundle(id:"1", block: { number: ${block.number} }) { ethPrice } @@ -146,7 +145,7 @@ export const SHARE_VALUE = (pairAddress, blocks) => { return gql(queryString) } -export const ETH_PRICE = (block) => { +export const ETH_PRICE = block => { const queryString = block ? ` query bundles { @@ -370,7 +369,7 @@ export const PAIR_DAY_DATA = gql` export const PAIR_DAY_DATA_BULK = (pairs, startTimestamp) => { let pairsString = `[` - pairs.map((pair) => { + pairs.map(pair => { return (pairsString += `"${pair}"`) }) pairsString += ']' @@ -405,7 +404,7 @@ export const GLOBAL_CHART = gql` } ` -export const GLOBAL_DATA = (block) => { +export const GLOBAL_DATA = block => { const queryString = ` query uniswapFactories { uniswapFactories( ${block ? `block: { number: ${block}}` : ``} @@ -652,7 +651,7 @@ export const PAIRS_BULK = gql` export const PAIRS_HISTORICAL_BULK = (block, pairs) => { let pairsString = `[` - pairs.map((pair) => { + pairs.map(pair => { return (pairsString += `"${pair}"`) }) pairsString += ']' @@ -720,7 +719,7 @@ export const TOKENS_CURRENT = gql` } ` -export const TOKENS_DYNAMIC = (block) => { +export const TOKENS_DYNAMIC = block => { const queryString = ` ${TokenFields} query tokens {