From b56d379f3381a71f8da3ee134e2b617ce27af6e0 Mon Sep 17 00:00:00 2001 From: Rohan Kulkarni Date: Fri, 8 Mar 2024 02:34:12 -0500 Subject: [PATCH] feat: initial zora network support --- package.json | 4 +- src/apollo/client.js | 26 +++---- src/apollo/queries.js | 13 +--- src/components/TokenLogo/index.js | 2 +- src/components/TxnList/index.js | 2 +- src/components/Warning/index.js | 4 +- src/contexts/Application.js | 12 ++-- src/contexts/V1Data.js | 116 +++++++++++++++--------------- src/pages/AccountPage.js | 4 +- src/pages/PairPage.js | 4 +- src/pages/TokenPage.js | 6 +- src/utils/data.ts | 2 +- src/utils/index.js | 18 ++--- src/utils/returns.ts | 4 +- 14 files changed, 107 insertions(+), 110 deletions(-) diff --git a/package.json b/package.json index ae4179eaa..ee21da996 100644 --- a/package.json +++ b/package.json @@ -71,8 +71,8 @@ "wcag-contrast": "^3.0.0" }, "scripts": { - "start": "react-scripts start", - "build": "react-scripts build", + "start": "react-scripts --openssl-legacy-provider start", + "build": "react-scripts --openssl-legacy-provider build", "test": "react-scripts test", "eject": "react-scripts eject" }, diff --git a/src/apollo/client.js b/src/apollo/client.js index c11e1ec89..8dc16017b 100644 --- a/src/apollo/client.js +++ b/src/apollo/client.js @@ -4,7 +4,7 @@ import { HttpLink } from 'apollo-link-http' export const client = new ApolloClient({ link: new HttpLink({ - uri: 'https://api.thegraph.com/subgraphs/name/ianlapham/uniswap-v2-dev', + uri: 'https://api.goldsky.com/api/public/project_clhk16b61ay9t49vm6ntn4mkz/subgraphs/uniswap-v2-zora-network/stable/gn', }), cache: new InMemoryCache(), shouldBatch: true, @@ -12,31 +12,31 @@ export const client = new ApolloClient({ export const healthClient = new ApolloClient({ link: new HttpLink({ - uri: 'https://api.thegraph.com/index-node/graphql', + uri: 'https://api.goldsky.com/api/public/project_clhk16b61ay9t49vm6ntn4mkz/subgraphs/uniswap-v2-zora-network/stable/gn', }), cache: new InMemoryCache(), shouldBatch: true, }) -export const v1Client = new ApolloClient({ +export const blockClient = new ApolloClient({ link: new HttpLink({ - uri: 'https://api.thegraph.com/subgraphs/name/ianlapham/uniswap', + uri: 'https://api.goldsky.com/api/public/project_clhk16b61ay9t49vm6ntn4mkz/subgraphs/uniswap-v2-zora-network/stable/gn', }), 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, +// }) + export const stakingClient = new ApolloClient({ link: new HttpLink({ - uri: 'https://api.thegraph.com/subgraphs/name/way2rach/talisman', + uri: '', }), cache: new InMemoryCache(), shouldBatch: true, }) - -export const blockClient = new ApolloClient({ - link: new HttpLink({ - uri: 'https://api.thegraph.com/subgraphs/name/blocklytics/ethereum-blocks', - }), - cache: new InMemoryCache(), -}) diff --git a/src/apollo/queries.js b/src/apollo/queries.js index 95a6a2022..922fccb9b 100644 --- a/src/apollo/queries.js +++ b/src/apollo/queries.js @@ -3,16 +3,9 @@ import { FACTORY_ADDRESS, BUNDLE_ID } from '../constants' export const SUBGRAPH_HEALTH = gql` query health { - indexingStatusForCurrentVersion(subgraphName: "uniswap/uniswap-v2-dev") { - synced - health - chains { - chainHeadBlock { - number - } - latestBlock { - number - } + _meta { + block { + number } } } diff --git a/src/components/TokenLogo/index.js b/src/components/TokenLogo/index.js index fcd5ec7f2..3e8ee0bf8 100644 --- a/src/components/TokenLogo/index.js +++ b/src/components/TokenLogo/index.js @@ -56,7 +56,7 @@ export default function TokenLogo({ address, header = false, size = '24px', ...r address = '0xc011a72400e58ecd99ee497cf89e3775d4bd732f' } - if (address?.toLowerCase() === '0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2') { + if (address?.toLowerCase() === '0x4200000000000000000000000000000000000006') { return ( - + {item.account && item.account.slice(0, 6) + '...' + item.account.slice(38, 42)} diff --git a/src/components/Warning/index.js b/src/components/Warning/index.js index 273c00ada..c2990e24f 100644 --- a/src/components/Warning/index.js +++ b/src/components/Warning/index.js @@ -72,7 +72,7 @@ export default function Warning({ type, show, setShow, address }) { fontWeight={500} lineHeight={'145.23%'} color={'#2172E5'} - href={'https://etherscan.io/address/' + address} + href={'https://explorer.zora.energy/address/' + address} target="_blank" > View {type === 'token' ? 'token' : 'pair'} contract on Etherscan @@ -92,7 +92,7 @@ export default function Warning({ type, show, setShow, address }) { fontWeight={500} lineHeight={'145.23%'} color={'#2172E5'} - href={'https://etherscan.io/address/' + address} + href={'https://explorer.zora.energy/address/' + address} target="_blank" > View {type === 'token' ? 'token' : 'pair'} contract on Etherscan diff --git a/src/contexts/Application.js b/src/contexts/Application.js index ab435c553..75990acb5 100644 --- a/src/contexts/Application.js +++ b/src/contexts/Application.js @@ -1,5 +1,6 @@ import React, { createContext, useContext, useReducer, useMemo, useCallback, useState, useEffect } from 'react' import { timeframeOptions, SUPPORTED_LIST_URLS__NO_ENS } from '../constants' +import { JsonRpcProvider } from 'ethers/providers' import dayjs from 'dayjs' import utc from 'dayjs/plugin/utc' import getTokenList from '../utils/tokenLists' @@ -174,16 +175,19 @@ export function useLatestBlocks() { useEffect(() => { async function fetch() { + const provider = new JsonRpcProvider('https://rpc.zora.energy') + const currentBlockNumber = await provider.getBlockNumber() + healthClient .query({ query: SUBGRAPH_HEALTH, }) .then((res) => { - const syncedBlock = res.data.indexingStatusForCurrentVersion.chains[0].latestBlock.number - const headBlock = res.data.indexingStatusForCurrentVersion.chains[0].chainHeadBlock.number - if (syncedBlock && headBlock) { + const syncedBlock = res.data._meta.block.number + + if (syncedBlock && currentBlockNumber) { updateLatestBlock(syncedBlock) - updateHeadBlock(headBlock) + updateHeadBlock(currentBlockNumber) } }) .catch((e) => { diff --git a/src/contexts/V1Data.js b/src/contexts/V1Data.js index ebfe6397a..2d95618ff 100644 --- a/src/contexts/V1Data.js +++ b/src/contexts/V1Data.js @@ -1,58 +1,58 @@ -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) - } -} +// 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) +// } +// } diff --git a/src/pages/AccountPage.js b/src/pages/AccountPage.js index acaa06d07..92039c3c6 100644 --- a/src/pages/AccountPage.js +++ b/src/pages/AccountPage.js @@ -166,7 +166,7 @@ function AccountPage({ account }) { {'Accounts '}→{' '} - + {' '} {account?.slice(0, 42)}{' '} @@ -177,7 +177,7 @@ function AccountPage({ account }) { {account?.slice(0, 6) + '...' + account?.slice(38, 42)} - + View on Etherscan diff --git a/src/pages/PairPage.js b/src/pages/PairPage.js index 50c4f2294..a25007fe0 100644 --- a/src/pages/PairPage.js +++ b/src/pages/PairPage.js @@ -203,7 +203,7 @@ function PairPage({ pairAddress, history }) { {BLOCKED_WARNINGS[pairAddress] ?? `This pair is not supported.`} - {`More about ${shortenAddress( + {`More about ${shortenAddress( pairAddress )}`} @@ -500,7 +500,7 @@ function PairPage({ pairAddress, history }) { - + View on Etherscan ↗ diff --git a/src/pages/TokenPage.js b/src/pages/TokenPage.js index 0989916a9..a8a2d2115 100644 --- a/src/pages/TokenPage.js +++ b/src/pages/TokenPage.js @@ -179,7 +179,7 @@ function TokenPage({ address, history }) { {BLOCKED_WARNINGS[address] ?? `This token is not supported.`} - {`More about ${shortenAddress( + {`More about ${shortenAddress( address )}`} @@ -207,7 +207,7 @@ function TokenPage({ address, history }) { style={{ width: 'fit-content' }} color={backgroundColor} external - href={'https://etherscan.io/address/' + address} + href={'https://explorer.zora.energy/address/' + address} > ({address.slice(0, 8) + '...' + address.slice(36, 42)}) @@ -420,7 +420,7 @@ function TokenPage({ address, history }) { - + View on Etherscan ↗ diff --git a/src/utils/data.ts b/src/utils/data.ts index 54b27b194..dc6ecc554 100644 --- a/src/utils/data.ts +++ b/src/utils/data.ts @@ -15,7 +15,7 @@ interface BasicData { // names since entitiy was created in subgraph // keys are lowercase token addresses <-------- const TOKEN_OVERRIDES: { [address: string]: { name: string; symbol: string } } = { - '0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2': { + '0x4200000000000000000000000000000000000006': { name: 'Ether (Wrapped)', symbol: 'ETH', }, diff --git a/src/utils/index.js b/src/utils/index.js index 683125343..fda62a431 100644 --- a/src/utils/index.js +++ b/src/utils/index.js @@ -42,14 +42,14 @@ export function getPoolLink(token0Address, token1Address = null, remove = false) return ( `https://app.uniswap.org/#/` + (remove ? `remove` : `add`) + - `/v2/${token0Address === '0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2' ? 'ETH' : token0Address}/${'ETH'}` + `/v2/${token0Address === '0x4200000000000000000000000000000000000006' ? 'ETH' : token0Address}/${'ETH'}` ) } else { return ( `https://app.uniswap.org/#/` + (remove ? `remove` : `add`) + - `/v2/${token0Address === '0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2' ? 'ETH' : token0Address}/${ - token1Address === '0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2' ? 'ETH' : token1Address + `/v2/${token0Address === '0x4200000000000000000000000000000000000006' ? 'ETH' : token0Address}/${ + token1Address === '0x4200000000000000000000000000000000000006' ? 'ETH' : token1Address }` ) } @@ -60,8 +60,8 @@ export function getSwapLink(token0Address, token1Address = null) { return `https://app.uniswap.org/#/swap?inputCurrency=${token0Address}` } else { return `https://app.uniswap.org/#/swap?inputCurrency=${ - token0Address === '0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2' ? 'ETH' : token0Address - }&outputCurrency=${token1Address === '0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2' ? 'ETH' : token1Address}` + token0Address === '0x4200000000000000000000000000000000000006' ? 'ETH' : token0Address + }&outputCurrency=${token1Address === '0x4200000000000000000000000000000000000006' ? 'ETH' : token1Address}` } } @@ -303,10 +303,10 @@ export const setThemeColor = (theme) => document.documentElement.style.setProper export const Big = (number) => new BigNumber(number) export const urls = { - showTransaction: (tx) => `https://etherscan.io/tx/${tx}/`, - showAddress: (address) => `https://www.etherscan.io/address/${address}/`, - showToken: (address) => `https://www.etherscan.io/token/${address}/`, - showBlock: (block) => `https://etherscan.io/block/${block}/`, + showTransaction: (tx) => `https://explorer.zora.energy/tx/${tx}/`, + showAddress: (address) => `https://www.explorer.zora.energy/address/${address}/`, + showToken: (address) => `https://www.explorer.zora.energy/token/${address}/`, + showBlock: (block) => `https://explorer.zora.energy/block/${block}/`, } export const formatTime = (unix) => { diff --git a/src/utils/returns.ts b/src/utils/returns.ts index cc4381737..670ba7f7f 100644 --- a/src/utils/returns.ts +++ b/src/utils/returns.ts @@ -39,10 +39,10 @@ function formatPricesForEarlyTimestamps(position): Position { position.token1PriceUSD = 1 } // WETH price - if (position.pair?.token0.id === '0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2') { + if (position.pair?.token0.id === '0x4200000000000000000000000000000000000006') { position.token0PriceUSD = 203 } - if (position.pair?.token1.id === '0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2') { + if (position.pair?.token1.id === '0x4200000000000000000000000000000000000006') { position.token1PriceUSD = 203 } }