diff --git a/src/features/account/AssetBalances/liquidityPositions/hooks.ts b/src/features/account/AssetBalances/liquidityPositions/hooks.ts index ab47e3d2d1..afcde5359b 100644 --- a/src/features/account/AssetBalances/liquidityPositions/hooks.ts +++ b/src/features/account/AssetBalances/liquidityPositions/hooks.ts @@ -85,8 +85,6 @@ export function useLegacyLiquidityPositionsBalances({ account, chainId }: Positi const pair = pairs.find((pair: any) => pair.id === position.pair.id) const pair1w = pairs1w?.find((pair: any) => pair.id === position.pair.id) ?? pair - // console.log(pair.volumeUSD - pair1w.volumeUSD, pairs1w, pair.reserveUSD) - return { id: position.id, assets: [pair.token0, pair.token1].map( @@ -95,8 +93,8 @@ export function useLegacyLiquidityPositionsBalances({ account, chainId }: Positi type: PoolType.ConstantProduct, swapFeePercent: 0.3, twapEnabled: true, - value: (position.liquidityTokenBalance / pair.totalSupply) * pair.reserveUSD, - apy: getApy({ volume: pair.volumeUSD - pair1w.volumeUSD, liquidity: pair.reserveUSD, days: 7 }), + value: (position.balance / pair.liquidity) * pair.liquidityUSD, + apy: getApy({ volume: pair.volumeUSD - pair1w.volumeUSD, liquidity: pair.liquidityUSD, days: 7 }), legacy: true, } }) diff --git a/src/features/analytics/bentobox/getAnalyticsBentobox.ts b/src/features/analytics/bentobox/getAnalyticsBentobox.ts index e26c95da8d..7146477c88 100644 --- a/src/features/analytics/bentobox/getAnalyticsBentobox.ts +++ b/src/features/analytics/bentobox/getAnalyticsBentobox.ts @@ -30,13 +30,14 @@ export default async function getAnalyticsBentobox({ chainId }: getAnalyticsBent }) // Creating map to easily reference TokenId -> Token - const tokenIdToPrice: Map }> = - new Map(tokens?.map((token: any) => [token.id, token])) + const tokenIdToPrice: Map = new Map( + tokens?.map((token: any) => [token.id, token]) + ) const bentoBoxTvl: number = bentoBoxTokens .map(({ id, rebase }: any) => { const token = tokenIdToPrice.get(id) - return (token?.derivedETH ?? 0) * nativePrice * rebase.elastic + return (token?.price.derivedNative ?? 0) * nativePrice * rebase.elastic }) .filter(Boolean) .reduce((previousValue: any, currentValue: any) => previousValue + currentValue, 0) @@ -45,8 +46,8 @@ export default async function getAnalyticsBentobox({ chainId }: getAnalyticsBent .map(({ id, rebase, decimals, symbol, name }: any) => { const token = tokenIdToPrice.get(id) const supply = rebase.elastic - const tokenDerivedETH = token?.derivedETH - const price = (tokenDerivedETH ?? 0) * nativePrice + const tokenDerivedNative = token?.price.derivedNative + const price = (tokenDerivedNative ?? 0) * nativePrice const tvl = price * supply const strategy = strategies?.find((strategy) => strategy.token === id) diff --git a/src/features/analytics/hooks/useFarmRewardHistories.ts b/src/features/analytics/hooks/useFarmRewardHistories.ts index 9ab9eb7ca7..9c0f9a4b45 100644 --- a/src/features/analytics/hooks/useFarmRewardHistories.ts +++ b/src/features/analytics/hooks/useFarmRewardHistories.ts @@ -28,7 +28,7 @@ export default function useFarmRewardHistories({ masterChefV1TotalAllocPoint, masterChefV1SushiPerBlock, sushiPrice, - ethPrice, + nativePrice, maticPrice, gnoPrice, onePrice, @@ -73,7 +73,7 @@ export default function useFarmRewardHistories({ masterChefV1SushiPerBlock, masterChefV1TotalAllocPoint, sushiPrice, - ethPrice, + nativePrice, maticPrice, gnoPrice, onePrice, @@ -90,16 +90,17 @@ export default function useFarmRewardHistories({ : poolHistory.balance / 10 ** kashiPair.token0.decimals const tvl = swapPair - ? (balance / Number(swapPair.totalSupply)) * Number(swapPair.reserveUSD) - : balance * kashiPair.token0.derivedETH * ethPrice + ? (balance / Number(swapPair.liquidity)) * Number(swapPair.liquidityUSD) + : balance * kashiPair.token0.price.derivedNative * nativePrice const tvlHistory = swapPair - ? (balanceHistory / Number(swapPair.totalSupply)) * Number(swapPair.reserveUSD) - : balanceHistory * kashiPair.token0.derivedETH * ethPrice + ? (balanceHistory / Number(swapPair.liquidity)) * Number(swapPair.liquidityUSD) + : balanceHistory * kashiPair.token0.price.derivedNative * nativePrice const feeApyPerYear = swapPair && swapPair1d - ? aprToApy((((pair?.volumeUSD - swapPair1d?.volumeUSD) * 0.0025 * 365) / pair?.reserveUSD) * 100, 3650) / 100 + ? aprToApy((((pair?.volumeUSD - swapPair1d?.volumeUSD) * 0.0025 * 365) / pair?.liquidityUSD) * 100, 3650) / + 100 : 0 const feeApyPerMonth = feeApyPerYear / 12 @@ -163,7 +164,6 @@ export default function useFarmRewardHistories({ blocksPerDay, celoPrice, chainId, - ethPrice, fantomPrice, fusePrice, glimmerPrice, @@ -173,6 +173,7 @@ export default function useFarmRewardHistories({ masterChefV1TotalAllocPoint, maticPrice, movrPrice, + nativePrice, onePrice, positions, sushiPrice, diff --git a/src/features/analytics/hooks/useFarmRewardsWithUsers.ts b/src/features/analytics/hooks/useFarmRewardsWithUsers.ts index 42249308b6..7d52c1fce6 100644 --- a/src/features/analytics/hooks/useFarmRewardsWithUsers.ts +++ b/src/features/analytics/hooks/useFarmRewardsWithUsers.ts @@ -10,7 +10,6 @@ import { useAllTokens } from 'app/hooks/Tokens' import { useAverageBlockTime, useCeloPrice, - useEthPrice, useFantomPrice, useFarmsWithUsers, useFusePrice, @@ -21,6 +20,7 @@ import { useMasterChefV1TotalAllocPoint, useMaticPrice, useMovrPrice, + useNativePrice, useOneDayBlock, useOnePrice, useSushiPairs, @@ -38,7 +38,7 @@ export function getRewards({ masterChefV1SushiPerBlock, masterChefV1TotalAllocPoint, sushiPrice, - ethPrice, + nativePrice, maticPrice, gnoPrice, onePrice, @@ -57,7 +57,7 @@ export function getRewards({ masterChefV1SushiPerBlock: any masterChefV1TotalAllocPoint: any sushiPrice: any - ethPrice: any + nativePrice: any maticPrice: any gnoPrice: any onePrice: any @@ -102,7 +102,7 @@ export function getRewards({ pool.rewarder.rewardToken = '0xba8a621b4a54e61c442f5ec623687e2a942225ef' pool.rewardToken.id = '0xba8a621b4a54e61c442f5ec623687e2a942225ef' pool.rewardToken.symbol = 'vestedQUARTZ' - pool.rewardToken.derivedETH = pair.token1.derivedETH + pool.rewardToken.price.derivedNative = pair.token1.price.derivedNative pool.rewardToken.decimals = 18 } @@ -123,7 +123,7 @@ export function getRewards({ ? (0 / decimals) * averageBlockTime * blocksPerDay : (pool.rewarder.rewardPerSecond / decimals) * averageBlockTime * blocksPerDay - const rewardPrice = pool.rewardToken.derivedETH * ethPrice + const rewardPrice = pool.rewardToken.price.derivedNative * nativePrice const address = getAddress(pool.rewardToken.id) @@ -230,7 +230,7 @@ export function getRewards({ : ((pool.allocPoint / pool.rewarder.totalAllocPoint) * pool.rewarder.rewardPerSecond) / 1e18 const rewardPerBlock = rewardPerSecond * averageBlockTime const rewardPerDay = rewardPerBlock * blocksPerDay - const rewardPrice = pool.rewardToken.derivedETH * ethPrice + const rewardPrice = pool.rewardToken.price.derivedNative * nativePrice const address = getAddress(pool.rewardToken.id) @@ -292,7 +292,7 @@ export function useRewardCalculationData(chainId: number, farmAddresses: any) { const { data: masterChefV1SushiPerBlock } = useMasterChefV1SushiPerBlock() const { data: sushiPrice } = useSushiPrice() - const { data: ethPrice } = useEthPrice() + const { data: nativePrice } = useNativePrice({ chainId }) const { data: maticPrice } = useMaticPrice() const { data: gnoPrice } = useGnoPrice() const { data: onePrice } = useOnePrice() @@ -314,7 +314,7 @@ export function useRewardCalculationData(chainId: number, farmAddresses: any) { masterChefV1TotalAllocPoint, masterChefV1SushiPerBlock, sushiPrice, - ethPrice, + nativePrice, maticPrice, gnoPrice, onePrice, @@ -346,7 +346,7 @@ export default function useFarmRewardsWithUsers({ masterChefV1TotalAllocPoint, masterChefV1SushiPerBlock, sushiPrice, - ethPrice, + nativePrice, maticPrice, gnoPrice, onePrice, @@ -389,7 +389,7 @@ export default function useFarmRewardsWithUsers({ masterChefV1SushiPerBlock, masterChefV1TotalAllocPoint, sushiPrice, - ethPrice, + nativePrice, maticPrice, gnoPrice, onePrice, @@ -403,12 +403,13 @@ export default function useFarmRewardsWithUsers({ const balance = swapPair ? Number(pool.balance / 1e18) : pool.balance / 10 ** kashiPair.token0.decimals const tvl = swapPair - ? (balance / Number(swapPair.totalSupply)) * Number(swapPair.reserveUSD) - : balance * kashiPair.token0.derivedETH * ethPrice + ? (balance / Number(swapPair.totalSupply)) * Number(swapPair.liquidityUSD) + : balance * kashiPair.token0.price.derivedNative * nativePrice const feeApyPerYear = swapPair && swapPair1d - ? aprToApy((((pair?.volumeUSD - swapPair1d?.volumeUSD) * 0.0025 * 365) / pair?.reserveUSD) * 100, 3650) / 100 + ? aprToApy((((pair?.volumeUSD - swapPair1d?.volumeUSD) * 0.0025 * 365) / pair?.liquidityUSD) * 100, 3650) / + 100 : 0 const feeApyPerMonth = feeApyPerYear / 12 @@ -440,8 +441,8 @@ export default function useFarmRewardsWithUsers({ share: (amount * 100) / balance, amount, amountUSD: swapPair - ? (amount / Number(swapPair.totalSupply)) * Number(swapPair.reserveUSD) - : amount * kashiPair.token0.derivedETH * ethPrice, + ? (amount / Number(swapPair.liquidity)) * Number(swapPair.liquidityUSD) + : amount * kashiPair.token0.price.derivedNative * nativePrice, } }) @@ -478,7 +479,6 @@ export default function useFarmRewardsWithUsers({ blocksPerDay, celoPrice, chainId, - ethPrice, fantomPrice, fusePrice, glimmerPrice, @@ -488,6 +488,7 @@ export default function useFarmRewardsWithUsers({ masterChefV1TotalAllocPoint, maticPrice, movrPrice, + nativePrice, onePrice, positions, sushiPrice, diff --git a/src/features/analytics/hooks/useTokensAnalytics.ts b/src/features/analytics/hooks/useTokensAnalytics.ts index 31ca5cd605..25df150e6d 100644 --- a/src/features/analytics/hooks/useTokensAnalytics.ts +++ b/src/features/analytics/hooks/useTokensAnalytics.ts @@ -61,18 +61,15 @@ export default function useTokensAnalytics({ chainId = ChainId.ETHEREUM }) { name: token.name, decimals: token.decimals, }, - liquidity: token.liquidity * token.derivedETH * nativePrice, + liquidity: token.liquidityUSD, volume1d: token.volumeUSD - token1d.volumeUSD, volume1w: token.volumeUSD - token1w.volumeUSD, - price: token.derivedETH * nativePrice, + price: token.price.derivedNative * nativePrice, strategy, - change1d: ((token.derivedETH * nativePrice) / (token1d.derivedETH * nativePrice1d)) * 100 - 100, - change1w: ((token.derivedETH * nativePrice) / (token1w.derivedETH * nativePrice1w)) * 100 - 100, - graph: token.dayData - .slice(0) - .reverse() - // @ts-ignore TYPE NEEDS FIXING - .map((day, i) => ({ x: i, y: Number(day.priceUSD) })), + change1d: + ((token.price.derivedNative * nativePrice) / (token1d.price.derivedNative * nativePrice1d)) * 100 - 100, + change1w: + ((token.price.derivedNative * nativePrice) / (token1w.price.derivedNative * nativePrice1w)) * 100 - 100, } }), [ diff --git a/src/features/analytics/pools/getAnalyticsPair.ts b/src/features/analytics/pools/getAnalyticsPair.ts index d8b2a4acd8..40ad5251b0 100644 --- a/src/features/analytics/pools/getAnalyticsPair.ts +++ b/src/features/analytics/pools/getAnalyticsPair.ts @@ -1,5 +1,5 @@ import { ChainId } from '@sushiswap/core-sdk' -import { getBlockDaysAgo, getNativePrice, getPairDayData, getPairs } from 'app/services/graph' +import { getBlockDaysAgo, getNativePrice, getPairDaySnapshots, getPairs } from 'app/services/graph' export type AnalyticsPair = Awaited> @@ -10,12 +10,12 @@ export default async function getAnalyticsPair(chainId: ChainId, id: string) { getPairs(chainId, { where: { id: id.toLowerCase() } }), getPairs(chainId, { where: { id: id.toLowerCase() }, block: block1d }), getPairs(chainId, { where: { id: id.toLowerCase() }, block: block2d }), - getPairDayData(chainId, { where: { pair: id.toLowerCase() } }), + getPairDaySnapshots(chainId, { where: { pair: id.toLowerCase() } }), getNativePrice(chainId), ]) - const liquidityUSD = pair.reserveUSD - const liquidityUSD1dChange = (pair.reserveUSD / pair1d.reserveUSD) * 100 - 100 + const liquidityUSD = pair.liquidityUSD + const liquidityUSD1dChange = (pair.liquidityUSD / pair1d.liquidityUSD) * 100 - 100 const volumeUSD1d = pair.volumeUSD - pair1d.volumeUSD const volumeUSD2d = pair1d.volumeUSD - pair2d.volumeUSD @@ -29,14 +29,14 @@ export default async function getAnalyticsPair(chainId: ChainId, id: string) { const avgTrade2d = volumeUSD2d / tx2d const avgTrade1dChange = (avgTrade1d / avgTrade2d) * 100 - 100 - const utilisation1d = (volumeUSD1d / pair.reserveUSD) * 100 - const utilisation2d = (volumeUSD2d / pair1d.reserveUSD) * 100 + const utilisation1d = (volumeUSD1d / pair.liquidityUSD) * 100 + const utilisation2d = (volumeUSD2d / pair1d.liquidityUSD) * 100 const utilisation1dChange = (utilisation1d / utilisation2d) * 100 - 100 const chartData = { liquidity: pairDayData .sort((a: any, b: any) => a.date - b.date) - .map((day: any) => ({ x: Number(day.date), y: Number(day.reserveUSD) })), + .map((day: any) => ({ x: Number(day.date), y: Number(day.liquidityUSD) })), volume: pairDayData .sort((a: any, b: any) => a.date - b.date) .map((day: any) => ({ x: Number(day.date), y: Number(day.volumeUSD) })), @@ -46,14 +46,14 @@ export default async function getAnalyticsPair(chainId: ChainId, id: string) { token0: { ...pair.token0, price: pair.token1Price, - reserve: pair.reserve0, - derivedUSD: pair.token0.derivedETH * nativePrice, + reserve: pair.reserve0 / 10 ** pair.token0.decimals, + derivedUSD: pair.token0.price.derivedNative * nativePrice, }, token1: { ...pair.token1, price: pair.token0Price, - reserve: pair.reserve1, - derivedUSD: pair.token1.derivedETH * nativePrice, + reserve: pair.reserve1 / 10 ** pair.token1.decimals, + derivedUSD: pair.token1.price.derivedNative * nativePrice, }, liquidityUSD, liquidityUSD1dChange, diff --git a/src/features/analytics/pools/getAnalyticsPairs.ts b/src/features/analytics/pools/getAnalyticsPairs.ts index 3f15f7664b..e6d3bd17bf 100644 --- a/src/features/analytics/pools/getAnalyticsPairs.ts +++ b/src/features/analytics/pools/getAnalyticsPairs.ts @@ -42,14 +42,14 @@ export default async function getAnalyticsPairs({ chainId, first }: getAnalytics const fees1d = volume1d * 0.003 const fees1w = volume1w * 0.003 - const liquidity = pair.reserveUSD - const liquidity1d = pair1d.reserveUSD + const liquidity = pair.liquidityUSD + const liquidity1d = pair1d.liquidityUSD - const liquidity1dChange = pair.reserveUSD - pair1d.reserveUSD - const liquidity1dChangePercent = (pair.reserveUSD / pair1d.reserveUSD) * 100 - 100 ?? 0 + const liquidity1dChange = pair.liquidityUSD - pair1d.liquidityUSD + const liquidity1dChangePercent = (pair.liquidityUSD / pair1d.liquidityUSD) * 100 - 100 ?? 0 - const utilisation1d = ((pair.volumeUSD - pair1d.volumeUSD) / pair?.reserveUSD) * 100 ?? 0 - const utilisation2d = ((pair1d.volumeUSD - pair2d.volumeUSD) / pair1d?.reserveUSD) * 100 ?? 0 + const utilisation1d = ((pair.volumeUSD - pair1d.volumeUSD) / pair?.liquidityUSD) * 100 ?? 0 + const utilisation2d = ((pair1d.volumeUSD - pair2d.volumeUSD) / pair1d?.liquidityUSD) * 100 ?? 0 const utilisation1dChange = (utilisation1d / utilisation2d) * 100 - 100 ?? 0 const tx1d = pair.txCount - pair1d.txCount diff --git a/src/features/analytics/tokens/getAnalyticsTokens.ts b/src/features/analytics/tokens/getAnalyticsTokens.ts index eab73c01cd..c01968db52 100644 --- a/src/features/analytics/tokens/getAnalyticsTokens.ts +++ b/src/features/analytics/tokens/getAnalyticsTokens.ts @@ -36,18 +36,15 @@ export default async function getAnalyticsTokens({ chainId, first }: getAnalytic name: token.name, decimals: token.decimals, }, - liquidity: token.liquidity * token.derivedETH * nativePrice, + liquidity: token.liquidityUSD, volume1d: token.volumeUSD - token1d.volumeUSD, volume1w: token.volumeUSD - token1w.volumeUSD, - price: token.derivedETH * nativePrice, + price: token.price.derivedNative * nativePrice, strategy, - change1d: ((token.derivedETH * nativePrice) / (token1d.derivedETH * nativePrice1d)) * 100 - 100, - change1w: ((token.derivedETH * nativePrice) / (token1w.derivedETH * nativePrice1w)) * 100 - 100, - graph: token.dayData - .slice(0) - .reverse() - // @ts-ignore TYPE NEEDS FIXING - .map((day, i) => ({ x: i, y: Number(day.priceUSD) })), + change1d: + ((token.price.derivedNative * nativePrice) / (token1d.price.derivedNative * nativePrice1d)) * 100 - 100, + change1w: + ((token.price.derivedNative * nativePrice) / (token1w.price.derivedNative * nativePrice1w)) * 100 - 100, } }) ) diff --git a/src/features/analytics/xsushi/getAnalyticsXsushi.ts b/src/features/analytics/xsushi/getAnalyticsXsushi.ts index fdd031c272..d004b2e77b 100644 --- a/src/features/analytics/xsushi/getAnalyticsXsushi.ts +++ b/src/features/analytics/xsushi/getAnalyticsXsushi.ts @@ -13,7 +13,7 @@ export default async function getAnalyticsXsushi() { getBlockDaysAgo(ChainId.ETHEREUM, 365), ]) - const [ethPrice, [xSushi], bar, bar1m, bar3m, bar6m, bar1y, barHistory] = await Promise.all([ + const [nativePrice, [xSushi], bar, bar1m, bar3m, bar6m, bar1y, barHistory] = await Promise.all([ getNativePrice(ChainId.ETHEREUM), getTokens(ChainId.ETHEREUM, { first: 1, where: { id: XSUSHI.address.toLowerCase() } }), getBar(), @@ -33,8 +33,8 @@ export default async function getAnalyticsXsushi() { const apy1y = (bar.ratio / bar1y.ratio - 1) * 100 const [xSushiPrice, xSushiMarketcap] = [ - xSushi?.derivedETH * ethPrice, - xSushi?.derivedETH * ethPrice * bar?.totalSupply, + xSushi?.price.derivedNative * nativePrice, + xSushi?.price.derivedNative * nativePrice * bar?.totalSupply, ] const chart = barHistory.map((barDay: any, i: number) => { diff --git a/src/features/onsen/InvestmentDetails.tsx b/src/features/onsen/InvestmentDetails.tsx index 6b34815c88..ecb8fea1bb 100644 --- a/src/features/onsen/InvestmentDetails.tsx +++ b/src/features/onsen/InvestmentDetails.tsx @@ -85,7 +85,7 @@ const InvestmentDetails = ({ farm }) => { const kashiFiatValue = kashiAssetAmount && kashiAssetPrice ? kashiAssetPrice.quote(kashiAssetAmount) : undefined - const slpFiatValue = Number(stakedAmount?.toExact() ?? 0) * (farm.pair.reserveUSD / farm.pair.totalSupply) + const slpFiatValue = Number(stakedAmount?.toExact() ?? 0) * (farm.pair.liquidityUSD / farm.pair.liquidity) const scplpFiatValue = Number(stakedAmount?.toExact() ?? 0) * (farm.pair.liquidityUSD / (farm.pair.liquidity / 1e18)) const secondaryRewardOnly = chainId && [ChainId.FUSE].includes(chainId) diff --git a/src/hooks/useFarmRewards.ts b/src/hooks/useFarmRewards.ts index bec1e5c005..b491a6c724 100644 --- a/src/hooks/useFarmRewards.ts +++ b/src/hooks/useFarmRewards.ts @@ -9,7 +9,6 @@ import { aprToApy } from 'app/functions/convert' import { useAverageBlockTime, useCeloPrice, - useEthPrice, useFantomPrice, useFarms, useFusePrice, @@ -85,7 +84,6 @@ export default function useFarmRewards({ chainId = ChainId.ETHEREUM }) { const { data: masterChefV1SushiPerBlock } = useMasterChefV1SushiPerBlock() const { data: sushiPrice } = useSushiPrice() - const { data: ethPrice } = useEthPrice() const { data: nativePrice } = useNativePrice({ chainId }) const { data: maticPrice } = useMaticPrice() const { data: gnoPrice } = useGnoPrice() @@ -158,7 +156,7 @@ export default function useFarmRewards({ chainId = ChainId.ETHEREUM }) { pool.rewarder.rewardToken = '0xba8a621b4a54e61c442f5ec623687e2a942225ef' pool.rewardToken.id = '0xba8a621b4a54e61c442f5ec623687e2a942225ef' pool.rewardToken.symbol = 'vestedQUARTZ' - pool.rewardToken.derivedETH = pair.token1.derivedETH + pool.rewardToken.price = { derivedNative: pair.token1.price.derivedNative } pool.rewardToken.decimals = 18 } @@ -179,7 +177,9 @@ export default function useFarmRewards({ chainId = ChainId.ETHEREUM }) { ? (0 / decimals) * averageBlockTime * blocksPerDay : (pool.rewarder.rewardPerSecond / decimals) * averageBlockTime * blocksPerDay - const rewardPrice = pool.rewardToken.derivedETH * ethPrice + console.log(pool.rewardToken) + + const rewardPrice = pool.rewardToken.price.derivedNative * nativePrice const address = getAddress(pool.rewardToken.id) @@ -306,7 +306,8 @@ export default function useFarmRewards({ chainId = ChainId.ETHEREUM }) { : ((pool.allocPoint / pool.rewarder.totalAllocPoint) * pool.rewarder.rewardPerSecond) / 1e18 const rewardPerBlock = rewardPerSecond * averageBlockTime const rewardPerDay = rewardPerBlock * blocksPerDay - const rewardPrice = pool.rewardToken.derivedETH * nativePrice + + const rewardPrice = pool.rewardToken.price.derivedNative * nativePrice const address = getAddress(pool.rewardToken.id) @@ -335,14 +336,15 @@ export default function useFarmRewards({ chainId = ChainId.ETHEREUM }) { const balance = kashiPair ? pool.balance / 10 ** kashiPair.token0.decimals : Number(pool.balance / 1e18) const tvl = kashiPair - ? balance * kashiPair.token0.derivedETH * ethPrice + ? balance * kashiPair.token0.price.derivedNative * nativePrice : swapPair - ? (balance / Number(swapPair.totalSupply)) * Number(swapPair.reserveUSD) + ? (balance / Number(swapPair.liquidity / 1e18)) * Number(swapPair.liquidityUSD) : (balance / (Number(tridentPair?.liquidity) / 1e18)) * Number(tridentPair?.liquidityUSD) const feeApyPerYear = swapPair && swapPair1d - ? aprToApy((((pair?.volumeUSD - swapPair1d?.volumeUSD) * 0.0025 * 365) / pair?.reserveUSD) * 100, 3650) / 100 + ? aprToApy((((pair?.volumeUSD - swapPair1d?.volumeUSD) * 0.0025 * 365) / pair?.liquidityUSD) * 100, 3650) / + 100 : 0 const feeApyPerMonth = feeApyPerYear / 12 @@ -417,7 +419,6 @@ export default function useFarmRewards({ chainId = ChainId.ETHEREUM }) { blocksPerDay, celoPrice, chainId, - ethPrice, fantomPrice, fusePrice, glimmerPrice, @@ -426,6 +427,7 @@ export default function useFarmRewards({ chainId = ChainId.ETHEREUM }) { masterChefV1SushiPerBlock, masterChefV1TotalAllocPoint, maticPrice, + metisPrice, movrPrice, nativePrice, onePrice, diff --git a/src/hooks/useUSDCSubgraph.ts b/src/hooks/useUSDCSubgraph.ts index 6dfb9bf33c..9a419742e3 100644 --- a/src/hooks/useUSDCSubgraph.ts +++ b/src/hooks/useUSDCSubgraph.ts @@ -51,12 +51,12 @@ export function useUSDCPricesSubgraph( if (tokenLegacy && tokenTrident) { if (tokenLegacy.liquidity > tokenTrident.kpi.liquidity) { - price = ethPrice * tokenLegacy.derivedETH + price = ethPrice * tokenLegacy.price.derivedNative } else { price = tokenTrident.price.derivedUSD } } else if (ethPrice && tokenLegacy) { - price = ethPrice * tokenLegacy.derivedETH + price = ethPrice * tokenLegacy.price.derivedNative } else if (tokenTrident) { price = tokenTrident.price.derivedUSD } diff --git a/src/pages/analytics/farms/[id].tsx b/src/pages/analytics/farms/[id].tsx index f7b978ef51..efe3856225 100644 --- a/src/pages/analytics/farms/[id].tsx +++ b/src/pages/analytics/farms/[id].tsx @@ -142,7 +142,7 @@ export default function Pool() {
Value
- {formatNumber(farm?.pair.reserveUSD / farm?.pair.totalSupply, true)} + {formatNumber(farm?.pair.liquidityUSD / farm?.pair.liquidity, true)}
diff --git a/src/pages/analytics/tokens/[id].tsx b/src/pages/analytics/tokens/[id].tsx index 134541b579..a0d0d34b2f 100644 --- a/src/pages/analytics/tokens/[id].tsx +++ b/src/pages/analytics/tokens/[id].tsx @@ -13,7 +13,7 @@ import { TridentBody, TridentHeader } from 'app/layouts/Trident' import { useNativePrice, useOneDayBlock, - useTokenDayData, + useTokenDaySnapshots, useTokenPairs, useTokens, useTwoDayBlock, @@ -67,14 +67,14 @@ export default function TokenPage() { // Token Pairs const tokenPairs = useTokenPairs({ chainId, variables: { id } }) - + console.log(tokenPairs) // For the Info Cards - const price = token?.derivedETH * nativePrice - const priceChange = ((token?.derivedETH * nativePrice) / (token1d?.derivedETH * nativePrice1d)) * 100 - 100 + const price = token?.price.derivedNative * nativePrice + const priceChange = + ((token?.price.derivedNative * nativePrice) / (token1d?.price.derivedNative * nativePrice1d)) * 100 - 100 - const liquidityUSD = token?.liquidity * token?.derivedETH * nativePrice - const liquidityUSDChange = - ((token?.liquidity * price) / (token1d?.liquidity * token1d?.derivedETH * nativePrice1d)) * 100 - 100 + const liquidityUSD = token?.liquidityUSD + const liquidityUSDChange = (token?.liquidityUSD / token1d?.liquidityUSD) * 100 - 100 const volumeUSD1d = token?.volumeUSD - token1d?.volumeUSD const volumeUSD2d = token1d?.volumeUSD - token2d?.volumeUSD @@ -85,33 +85,33 @@ export default function TokenPage() { const priceUSD1dChange = (priceUSD1d / priceUSD2d) * 100 - 100 // The Chart - const tokenDayData = useTokenDayData({ + const tokenDaySnapshots = useTokenDaySnapshots({ chainId, - variables: { where: { token: id.toLowerCase() } }, + variables: { where: { token: id?.toLowerCase() } }, shouldFetch: !!id && !!chainId, }) const chartData = useMemo( () => ({ - liquidityChart: tokenDayData + liquidityChart: tokenDaySnapshots /* @ts-ignore TYPE NEEDS FIXING */ ?.sort((a, b) => a.date - b.date) /* @ts-ignore TYPE NEEDS FIXING */ .map((day) => ({ x: new Date(day.date * 1000), y: Number(day.liquidityUSD) })), - volumeChart: tokenDayData + volumeChart: tokenDaySnapshots /* @ts-ignore TYPE NEEDS FIXING */ ?.sort((a, b) => a.date - b.date) /* @ts-ignore TYPE NEEDS FIXING */ .map((day) => ({ x: new Date(day.date * 1000), y: Number(day.volumeUSD) })), - priceChart: tokenDayData + priceChart: tokenDaySnapshots /* @ts-ignore TYPE NEEDS FIXING */ ?.sort((a, b) => a.date - b.date) /* @ts-ignore TYPE NEEDS FIXING */ .map((day) => ({ x: new Date(day.date * 1000), y: Number(day.priceUSD) })), }), - [tokenDayData] + [tokenDaySnapshots] ) const currency = token diff --git a/src/pages/bar/index.tsx b/src/pages/bar/index.tsx index 076a08dc45..761e9e9016 100644 --- a/src/pages/bar/index.tsx +++ b/src/pages/bar/index.tsx @@ -185,8 +185,6 @@ export default function Stake() { shouldFetch: !!block1y, }) - const [xSushiPrice] = [xSushi?.derivedETH * ethPrice, xSushi?.derivedETH * ethPrice * bar?.totalSupply] - const apy1m = (bar?.ratio / bar1m?.ratio - 1) * 12 * 100 return ( diff --git a/src/services/graph/fetchers/exchange.ts b/src/services/graph/fetchers/exchange.ts index 4518b9a5be..2b102c087e 100644 --- a/src/services/graph/fetchers/exchange.ts +++ b/src/services/graph/fetchers/exchange.ts @@ -1,13 +1,13 @@ import { ChainId } from '@sushiswap/core-sdk' import { GRAPH_HOST } from 'app/services/graph/constants' import { - dayDatasQuery, - ethPriceQuery, + factoryDaySnapshotsQuery, factoryQuery, liquidityPositionsQuery, - pairDayDatasQuery, + nativePriceQuery, + pairDaySnapshotsQuery, pairsQuery, - tokenDayDatasQuery, + tokenDaySnapshotsQuery, tokenPairsQuery, tokenPriceQuery, tokenQuery, @@ -35,10 +35,25 @@ export const EXCHANGE = { [ChainId.MOONBEAM]: 'sushiswap/exchange-moonbeam', } +export const EXCHANGE_NEW = { + [ChainId.ETHEREUM]: 'sushi-graph/sushiswap-ethereum', + [ChainId.AVALANCHE]: 'sushiswap/sushiswap-avalanche', + [ChainId.ARBITRUM]: 'sushiswap/sushiswap-arbitrum', + [ChainId.BSC]: 'sushiswap/sushiswap-bsc', + [ChainId.CELO]: 'sushiswap/sushiswap-celo', + [ChainId.FANTOM]: 'sushiswap/sushiswap-fantom', + [ChainId.FUSE]: 'sushiswap/sushiswap-fuse', + [ChainId.XDAI]: 'sushiswap/sushiswap-gnosis', + [ChainId.MOONBEAM]: 'sushiswap/sushiswap-moonbeam', + [ChainId.MOONRIVER]: 'sushiswap/sushiswap-moonriver', + [ChainId.HARMONY]: 'sushi-graph/sushiswap-harmony', + [ChainId.MATIC]: 'sushiswap/exchange-polygon', +} + // @ts-ignore TYPE NEEDS FIXING export const exchange = async (chainId = ChainId.ETHEREUM, query, variables = {}) => // @ts-ignore TYPE NEEDS FIXING - pager(`${GRAPH_HOST[chainId]}/subgraphs/name/${EXCHANGE[chainId]}`, query, variables) + pager(`${GRAPH_HOST[chainId]}/subgraphs/name/${EXCHANGE_NEW[chainId]}`, query, variables) export const getPairs = async (chainId = ChainId.ETHEREUM, variables: any = undefined, query = pairsQuery) => { const { pairs } = await exchange(chainId, query, variables) @@ -46,10 +61,10 @@ export const getPairs = async (chainId = ChainId.ETHEREUM, variables: any = unde } // @ts-ignore TYPE NEEDS FIXING -export const getPairDayData = async (chainId = ChainId.ETHEREUM, variables) => { +export const getPairDaySnapshots = async (chainId = ChainId.ETHEREUM, variables) => { // console.log('getTokens') - const { pairDayDatas } = await exchange(chainId, pairDayDatasQuery, variables) - return pairDayDatas + const { pairDaySnapshots } = await exchange(chainId, pairDaySnapshotsQuery, variables) + return pairDaySnapshots } // @ts-ignore TYPE NEEDS FIXING @@ -74,10 +89,10 @@ export const getToken = async (chainId = ChainId.ETHEREUM, query = tokenQuery, v } // @ts-ignore TYPE NEEDS FIXING -export const getTokenDayData = async (chainId = ChainId.ETHEREUM, variables) => { +export const getTokenDaySnapshots = async (chainId = ChainId.ETHEREUM, variables) => { // console.log('getTokens') - const { tokenDayDatas } = await exchange(chainId, tokenDayDatasQuery, variables) - return tokenDayDatas + const { tokenDaySnapshots } = await exchange(chainId, tokenDaySnapshotsQuery, variables) + return tokenDaySnapshots } // @ts-ignore TYPE NEEDS FIXING @@ -85,7 +100,7 @@ export const getTokenPrices = async (chainId = ChainId.ETHEREUM, variables) => { // console.log('getTokenPrice') const { tokens } = await exchange(chainId, tokensQuery, variables) // @ts-ignore TYPE NEEDS FIXING - return tokens.map((token) => token?.derivedETH) + return tokens.map((token) => token?.price.derivedNative) } // @ts-ignore TYPE NEEDS FIXING @@ -94,13 +109,13 @@ export const getTokenPrice = async (chainId = ChainId.ETHEREUM, query, variables const nativePrice = await getNativePrice(chainId) const { token } = await exchange(chainId, query, variables) - return token?.derivedETH * nativePrice + return token?.price.derivedNative * nativePrice } export const getNativePrice = async (chainId = ChainId.ETHEREUM, variables: any = undefined) => { // console.log('getEthPrice') const data = await getBundle(chainId, undefined, variables) - return data?.bundles[0]?.ethPrice + return data?.bundles[0]?.nativePrice } export const getEthPrice = async (variables = undefined) => { @@ -252,7 +267,7 @@ export const getFusePrice = async () => { export const getBundle = async ( chainId = ChainId.ETHEREUM, - query = ethPriceQuery, + query = nativePriceQuery, variables = { id: 1, } @@ -267,7 +282,7 @@ export const getLiquidityPositions = async (chainId = ChainId.ETHEREUM, variable } export const getDayData = async (chainId = ChainId.ETHEREUM, variables = undefined) => { - const { dayDatas } = await exchange(chainId, dayDatasQuery, variables) + const { factoryDaySnapshots: dayDatas } = await exchange(chainId, factoryDaySnapshotsQuery, variables) return dayDatas } @@ -282,6 +297,9 @@ export const getTransactions = async (chainId = ChainId.ETHEREUM, variables = un } export const getTokenPairs = async (chainId = ChainId.ETHEREUM, variables = undefined) => { + console.log('gettokenpairs') const { pairs0, pairs1 } = await exchange(chainId, tokenPairsQuery, variables) + console.log(pairs0, pairs1) + return pairs0 || pairs1 ? [...(pairs0 ? pairs0 : []), ...(pairs1 ? pairs1 : [])] : undefined } diff --git a/src/services/graph/hooks/exchange.ts b/src/services/graph/hooks/exchange.ts index a810ea730f..2a35793e31 100644 --- a/src/services/graph/hooks/exchange.ts +++ b/src/services/graph/hooks/exchange.ts @@ -24,20 +24,20 @@ import { getNativePrice, getOhmPrice, getOnePrice, - getPairDayData, + getPairDaySnapshots, getPairs, getPicklePrice, getRulerPrice, getSpellPrice, getSushiPrice, - getTokenDayData, + getTokenDaySnapshots, getTokenPairs, getTokens, getTruPrice, getYggPrice, } from '../fetchers' import { GraphProps } from '../interfaces' -import { ethPriceQuery } from '../queries' +import { nativePriceQuery } from '../queries' export function useFactory({ chainId = ChainId.ETHEREUM, @@ -207,7 +207,7 @@ export function useMagicPrice(swrConfig: SWRConfiguration = undefined) { // @ts-ignore TYPE NEEDS FIXING export function useBundle(variables = undefined, swrConfig: SWRConfiguration = undefined) { const { chainId } = useActiveWeb3React() - return useSWR(chainId ? [chainId, ethPriceQuery, stringify(variables)] : null, () => getBundle(), swrConfig) + return useSWR(chainId ? [chainId, nativePriceQuery, stringify(variables)] : null, () => getBundle(), swrConfig) } export function useLiquidityPositions({ @@ -252,28 +252,28 @@ export function useTokens({ return data } -export function usePairDayData({ +export function usePairDaySnapshots({ chainId = ChainId.ETHEREUM, variables, shouldFetch = true, swrConfig = undefined, }: GraphProps) { const { data } = useSWR( - shouldFetch && !!chainId ? ['pairDayData', chainId, stringify(variables)] : null, - (_, chainId) => getPairDayData(chainId, variables), + shouldFetch && !!chainId ? ['pairDaySnapshot', chainId, stringify(variables)] : null, + (_, chainId) => getPairDaySnapshots(chainId, variables), swrConfig ) return data } -export function useTokenDayData( +export function useTokenDaySnapshots( { chainId, variables, shouldFetch = true }: GraphProps, // @ts-ignore TYPE NEEDS FIXING swrConfig: SWRConfiguration = undefined ) { const { data } = useSWR( - shouldFetch && !!chainId ? ['tokenDayData', chainId, stringify(variables)] : null, - (_, chainId) => getTokenDayData(chainId, variables), + shouldFetch && !!chainId ? ['tokenDaySnapshots', chainId, stringify(variables)] : null, + (_, chainId) => getTokenDaySnapshots(chainId, variables), swrConfig ) return data diff --git a/src/services/graph/hooks/transactions/legacy.ts b/src/services/graph/hooks/transactions/legacy.ts index 52b4e6dd5f..645829749a 100644 --- a/src/services/graph/hooks/transactions/legacy.ts +++ b/src/services/graph/hooks/transactions/legacy.ts @@ -7,19 +7,15 @@ import { useMemo } from 'react' import useSWR from 'swr' export interface LegacyTransactions { - amount0In: string - amount0Out: string - amount1In: string - amount1Out: string + amountIn: string + amountOut: string amountUSD: string id: string - pair: { - token0: { - symbol: string - } - token1: { - symbol: string - } + tokenIn: { + symbol: string + } + tokenOut: { + symbol: string } sender: string timestamp: string @@ -29,18 +25,11 @@ export interface LegacyTransactions { export const legacyTransactionDataFormatter = (rawData: LegacyTransactions[]): Transactions[] => { return rawData.map((tx) => { - const props = - tx.amount0In === '0' - ? { - type: `Swap ${tx.pair.token1.symbol} for ${tx.pair.token0.symbol}`, - incomingAmt: `${formatNumber(tx.amount1In)} ${tx.pair.token1.symbol}`, - outgoingAmt: `${formatNumber(tx.amount0Out)} ${tx.pair.token0.symbol}`, - } - : { - type: `Swap ${tx.pair.token0.symbol} for ${tx.pair.token1.symbol}`, - incomingAmt: `${formatNumber(tx.amount0In)} ${tx.pair.token0.symbol}`, - outgoingAmt: `${formatNumber(tx.amount1Out)} ${tx.pair.token1.symbol}`, - } + const props = { + type: `Swap ${tx.tokenIn.symbol} for ${tx.tokenOut.symbol}`, + incomingAmt: `${formatNumber(tx.amountIn)} ${tx.tokenIn.symbol}`, + outgoingAmt: `${formatNumber(tx.amountOut)} ${tx.tokenOut.symbol}`, + } return { value: formatNumber(tx.amountUSD, true), address: tx.to, diff --git a/src/services/graph/queries/exchange.ts b/src/services/graph/queries/exchange.ts index e95e625454..c820e91c1f 100644 --- a/src/services/graph/queries/exchange.ts +++ b/src/services/graph/queries/exchange.ts @@ -41,12 +41,12 @@ export const uniswapUserQuery = gql` export const bundleFields = gql` fragment bundleFields on Bundle { id - ethPrice + nativePrice } ` -export const ethPriceQuery = gql` - query ethPriceQuery($id: Int! = 1, $block: Block_height) { +export const nativePriceQuery = gql` + query nativePriceQuery($id: Int! = 1, $block: Block_height) { bundles(id: $id, block: $block) { ...bundleFields } @@ -58,43 +58,45 @@ export const tokenPriceQuery = gql` query tokenPriceQuery($id: String!) { token(id: $id) { id - derivedETH + price { + derivedNative + } } } ` -export const dayDataFieldsQuery = gql` - fragment dayDataFields on DayData { +export const factoryDaySnapshotsFieldsQuery = gql` + fragment factoryDaySnapshotsFields on FactoryDaySnapshot { id date - volumeETH + volumeNative volumeUSD - untrackedVolume - liquidityETH + untrackedVolumeUSD + liquidityNative liquidityUSD - txCount + transactionCount } ` // Dashboard... -export const dayDatasQuery = gql` - query dayDatasQuery($first: Int! = 1000, $date: Int! = 0, $where: DayData_filter) { - dayDatas(first: $first, orderBy: date, orderDirection: desc, where: $where) { - ...dayDataFields +export const factoryDaySnapshotsQuery = gql` + query factoryDaySnapshots($first: Int! = 1000, $date: Int! = 0, $where: FactoryDaySnapshot_filter) { + factoryDaySnapshots(first: $first, orderBy: date, orderDirection: desc, where: $where) { + ...factoryDaySnapshotsFields } } - ${dayDataFieldsQuery} + ${factoryDaySnapshotsFieldsQuery} ` // Pairs... export const pairFieldsQuery = gql` fragment pairFields on Pair { id - reserveUSD - reserveETH + liquidityUSD + liquidityNative volumeUSD untrackedVolumeUSD - trackedReserveETH + trackedLiquidityNative token0 { ...PairToken } @@ -105,17 +107,18 @@ export const pairFieldsQuery = gql` reserve1 token0Price token1Price - totalSupply + liquidity # totalSupply txCount - timestamp } fragment PairToken on Token { id name symbol decimals - totalSupply - derivedETH + liquidity + price { + derivedNative + } } ` @@ -144,24 +147,18 @@ export const pairCountQuery = gql` } ` -export const pairDayDatasQuery = gql` - query pairDayDatasQuery($first: Int = 1000, $skip: Int, $block: Block_height, $where: PairDayData_filter) { - pairDayDatas(first: $first, skip: $skip, orderBy: date, orderDirection: desc, where: $where, block: $block) { +export const pairDaySnapshotsQuery = gql` + query pairDaySnapshotsQuery($first: Int = 1000, $skip: Int, $block: Block_height, $where: PairDaySnapshot_filter) { + pairDaySnapshots(first: $first, skip: $skip, orderBy: date, orderDirection: desc, where: $where, block: $block) { date pair { id } - token0 { - derivedETH - } - token1 { - derivedETH - } - reserveUSD + liquidityUSD volumeToken0 volumeToken1 volumeUSD - txCount + transactionCount } } ` @@ -170,7 +167,7 @@ export const liquidityPositionsQuery = gql` query liquidityPositionSubsetQuery($first: Int! = 1000, $skip: Int, $where: LiquidityPosition_filter) { liquidityPositions(first: $first, skip: $skip, where: $where) { id - liquidityTokenBalance + balance user { id } @@ -187,7 +184,7 @@ export const pairsQuery = gql` $first: Int = 1000 $where: Pair_filter $block: Block_height - $orderBy: Pair_orderBy = "trackedReserveETH" + $orderBy: Pair_orderBy = "trackedLiquidityNative" $orderDirection: OrderDirection = "desc" ) { pairs( @@ -209,13 +206,13 @@ export const pairsTimeTravelQuery = gql` pairs( first: $first block: $block - orderBy: trackedReserveETH + orderBy: trackedLiquidityNative orderDirection: desc where: { id_in: $pairAddresses } ) { id - reserveUSD - trackedReserveETH + liquidityUSD + trackedLiquidityNative volumeUSD untrackedVolumeUSD txCount @@ -230,13 +227,15 @@ export const tokenFieldsQuery = gql` symbol name decimals - totalSupply volume volumeUSD untrackedVolumeUSD txCount liquidity - derivedETH + liquidityUSD + price { + derivedNative + } } ` @@ -257,9 +256,9 @@ export const tokenIdsQuery = gql` } ` -export const tokenDayDatasQuery = gql` - query tokenDayDatasQuery($first: Int! = 1000, $skip: Int, $block: Block_height, $where: TokenDayData_filter) { - tokenDayDatas(first: $first, skip: $skip, orderBy: date, orderDirection: desc, where: $where, block: $block) { +export const tokenDaySnapshotsQuery = gql` + query tokenDaySnapshotsQuery($first: Int! = 1000, $skip: Int, $block: Block_height, $where: TokenDaySnapshot_filter) { + tokenDaySnapshots(first: $first, skip: $skip, orderBy: date, orderDirection: desc, where: $where, block: $block) { id date token { @@ -268,7 +267,7 @@ export const tokenDayDatasQuery = gql` volumeUSD liquidityUSD priceUSD - txCount + transactionCount } } ` @@ -278,7 +277,7 @@ export const tokenPairsQuery = gql` pairs0: pairs( first: 1000 skip: $skip - orderBy: reserveUSD + orderBy: liquidityUSD orderDirection: desc where: { token0: $id } block: $block @@ -288,7 +287,7 @@ export const tokenPairsQuery = gql` pairs1: pairs( first: 1000 skip: $skip - orderBy: reserveUSD + orderBy: liquidityUSD orderDirection: desc where: { token1: $id } block: $block @@ -303,11 +302,6 @@ export const tokensQuery = gql` query tokensQuery($first: Int! = 1000, $skip: Int, $block: Block_height, $where: Token_filter) { tokens(first: $first, skip: $skip, orderBy: volumeUSD, orderDirection: desc, block: $block, where: $where) { ...tokenFields - dayData(first: 7, orderBy: date, orderDirection: desc) { - id - priceUSD - date - } } } ${tokenFieldsQuery} @@ -345,20 +339,15 @@ export const transactionsQuery = gql` transaction { id } - pair { - id - token0 { - symbol - } - token1 { - symbol - } + tokenIn { + symbol + } + tokenOut { + symbol } sender - amount0In - amount0Out - amount1In - amount1Out + amountIn + amountOut amountUSD to }