Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: initial zora network support #2

Open
wants to merge 1 commit into
base: v2
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
},
Expand Down
26 changes: 13 additions & 13 deletions src/apollo/client.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,39 +4,39 @@ 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,
})

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(),
})
13 changes: 3 additions & 10 deletions src/apollo/queries.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/components/TokenLogo/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
<StyledEthereumLogo size={size} {...rest}>
<img
Expand Down
2 changes: 1 addition & 1 deletion src/components/TxnList/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -304,7 +304,7 @@ function TxnList({ transactions, symbol0Override, symbol1Override, color }) {
)}
{!below1080 && (
<DataText area="account">
<Link color={color} external href={'https://etherscan.io/address/' + item.account}>
<Link color={color} external href={'https://explorer.zora.energy/address/' + item.account}>
{item.account && item.account.slice(0, 6) + '...' + item.account.slice(38, 42)}
</Link>
</DataText>
Expand Down
4 changes: 2 additions & 2 deletions src/components/Warning/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
12 changes: 8 additions & 4 deletions src/contexts/Application.js
Original file line number Diff line number Diff line change
@@ -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'
Expand Down Expand Up @@ -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) => {
Expand Down
116 changes: 58 additions & 58 deletions src/contexts/V1Data.js
Original file line number Diff line number Diff line change
@@ -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)
// }
// }
4 changes: 2 additions & 2 deletions src/pages/AccountPage.js
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ function AccountPage({ account }) {
<RowBetween>
<TYPE.body>
<BasicLink to="/accounts">{'Accounts '}</BasicLink>→{' '}
<Link lineHeight={'145.23%'} href={'https://etherscan.io/address/' + account} target="_blank">
<Link lineHeight={'145.23%'} href={'https://explorer.zora.energy/address/' + account} target="_blank">
{' '}
{account?.slice(0, 42)}{' '}
</Link>
Expand All @@ -177,7 +177,7 @@ function AccountPage({ account }) {
<RowBetween>
<span>
<TYPE.header fontSize={24}>{account?.slice(0, 6) + '...' + account?.slice(38, 42)}</TYPE.header>
<Link lineHeight={'145.23%'} href={'https://etherscan.io/address/' + account} target="_blank">
<Link lineHeight={'145.23%'} href={'https://explorer.zora.energy/address/' + account} target="_blank">
<TYPE.main fontSize={14}>View on Etherscan</TYPE.main>
</Link>
</span>
Expand Down
4 changes: 2 additions & 2 deletions src/pages/PairPage.js
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,7 @@ function PairPage({ pairAddress, history }) {
<TYPE.light style={{ textAlign: 'center' }}>
{BLOCKED_WARNINGS[pairAddress] ?? `This pair is not supported.`}
</TYPE.light>
<Link external={true} href={'https://etherscan.io/address/' + pairAddress}>{`More about ${shortenAddress(
<Link external={true} href={'https://explorer.zora.energy/address/' + pairAddress}>{`More about ${shortenAddress(
pairAddress
)}`}</Link>
</AutoColumn>
Expand Down Expand Up @@ -500,7 +500,7 @@ function PairPage({ pairAddress, history }) {
</AutoRow>
</Column>
<ButtonLight color={backgroundColor}>
<Link color={backgroundColor} external href={'https://etherscan.io/address/' + pairAddress}>
<Link color={backgroundColor} external href={'https://explorer.zora.energy/address/' + pairAddress}>
View on Etherscan ↗
</Link>
</ButtonLight>
Expand Down
6 changes: 3 additions & 3 deletions src/pages/TokenPage.js
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@ function TokenPage({ address, history }) {
<TYPE.light style={{ textAlign: 'center' }}>
{BLOCKED_WARNINGS[address] ?? `This token is not supported.`}
</TYPE.light>
<Link external={true} href={'https://etherscan.io/address/' + address}>{`More about ${shortenAddress(
<Link external={true} href={'https://explorer.zora.energy/address/' + address}>{`More about ${shortenAddress(
address
)}`}</Link>
</AutoColumn>
Expand Down Expand Up @@ -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}
>
<Text style={{ marginLeft: '.15rem' }} fontSize={'14px'} fontWeight={400}>
({address.slice(0, 8) + '...' + address.slice(36, 42)})
Expand Down Expand Up @@ -420,7 +420,7 @@ function TokenPage({ address, history }) {
</AutoRow>
</Column>
<ButtonLight color={backgroundColor}>
<Link color={backgroundColor} external href={'https://etherscan.io/address/' + address}>
<Link color={backgroundColor} external href={'https://explorer.zora.energy/address/' + address}>
View on Etherscan ↗
</Link>
</ButtonLight>
Expand Down
2 changes: 1 addition & 1 deletion src/utils/data.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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',
},
Expand Down
18 changes: 9 additions & 9 deletions src/utils/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
}`
)
}
Expand All @@ -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}`
}
}

Expand Down Expand Up @@ -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) => {
Expand Down
4 changes: 2 additions & 2 deletions src/utils/returns.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
}
Expand Down