Skip to content

Commit

Permalink
Revert "πŸ› Migrate Uniswap GraphQL from Apollo to new GraphQL client (#…
Browse files Browse the repository at this point in the history
…4143)"

This reverts commit 1d896b3.
  • Loading branch information
skylarbarrera authored and Ibrahim Taveras committed Jun 20, 2023
1 parent 3007da7 commit 975fd86
Show file tree
Hide file tree
Showing 6 changed files with 152 additions and 146 deletions.
103 changes: 103 additions & 0 deletions src/apollo/queries.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,16 @@ export const COMPOUND_ACCOUNT_AND_MARKET_QUERY = gql`
}
`;

export const UNISWAP_ADDITIONAL_POOL_DATA = gql`
query pairs($address: String!) {
pairs(where: { id: $address }) {
volumeUSD
reserveUSD
trackedReserveETH
}
}
`;

export const GET_BLOCKS_QUERY = (timestamps: any) => {
let queryString = 'query blocks {';
queryString += timestamps.map((timestamp: any) => {
Expand All @@ -63,6 +73,99 @@ export const GET_BLOCKS_QUERY = (timestamps: any) => {
`;
};

export const USER_POSITIONS = gql`
query liquidityPositions($user: Bytes!) {
liquidityPositions(where: { user: $user, liquidityTokenBalance_gt: 0 }) {
pair {
id
reserve0
reserve1
reserveUSD
token0 {
decimals
id
name
symbol
derivedETH
}
token1 {
decimals
id
name
symbol
derivedETH
}
totalSupply
}
liquidityTokenBalance
}
}
`;

export const USER_MINTS_BURNS_PER_PAIR = gql`
query events($user: Bytes!, $pair: Bytes!) {
mints(where: { to: $user, pair: $pair }) {
amountUSD
amount0
amount1
timestamp
pair {
token0 {
id
}
token1 {
id
}
}
}
burns(where: { sender: $user, pair: $pair }) {
amountUSD
amount0
amount1
timestamp
pair {
token0 {
id
}
token1 {
id
}
}
}
}
`;

export const USER_HISTORY = gql`
query snapshots($user: Bytes!, $skip: Int!) {
liquidityPositionSnapshots(
first: 1000
skip: $skip
where: { user: $user }
) {
timestamp
reserveUSD
liquidityTokenBalance
liquidityTokenTotalSupply
reserve0
reserve1
token0PriceUSD
token1PriceUSD
pair {
id
reserve0
reserve1
reserveUSD
token0 {
id
}
token1 {
id
}
}
}
}
`;

export const CONTRACT_FUNCTION = gql`
query contractFunction($chainID: Int!, $hex: String!) {
contractFunction(chainID: $chainID, hex: $hex) {
Expand Down
7 changes: 0 additions & 7 deletions src/graphql/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,4 @@ exports.config = {
document: './queries/metadata.graphql',
schema: { method: 'GET', url: 'https://metadata.p.rainbow.me/v1/graph' },
},
uniswap: {
document: './queries/uniswap.graphql',
schema: {
method: 'POST',
url: 'https://api.thegraph.com/subgraphs/name/ianlapham/uniswapv2',
},
},
};
4 changes: 0 additions & 4 deletions src/graphql/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,8 @@ import { config } from './config';
import { getFetchRequester } from './utils/getFetchRequester';
import { getSdk as getEnsSdk } from './__generated__/ens';
import { getSdk as getMetadataSdk } from './__generated__/metadata';
import { getSdk as getUniswapSdk } from './__generated__/uniswap';

export const ensClient = getEnsSdk(getFetchRequester(config.ens.schema));
export const metadataClient = getMetadataSdk(
getFetchRequester(config.metadata.schema)
);
export const uniswapClient = getUniswapSdk(
getFetchRequester(config.uniswap.schema)
);
108 changes: 0 additions & 108 deletions src/graphql/queries/uniswap.graphql

This file was deleted.

16 changes: 11 additions & 5 deletions src/hooks/usePoolDetails.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,16 @@ import { getUnixTime, startOfMinute, sub } from 'date-fns';
import { useCallback, useEffect, useMemo } from 'react';
import { useDispatch, useSelector } from 'react-redux';
import { uniswapClientDeprecated } from '../apollo/client';
import { UNISWAP_PAIR_DATA_QUERY_VOLUME } from '../apollo/queries';
import {
UNISWAP_ADDITIONAL_POOL_DATA,
UNISWAP_PAIR_DATA_QUERY_VOLUME,
} from '../apollo/queries';
import useAccountSettings from './useAccountSettings';
import useNativeCurrencyToUSD from './useNativeCurrencyToUSD';
import { bigNumberFormat } from '@/helpers/bigNumberFormat';
import { AppDispatch, AppState } from '@/redux/store';
import { setPoolsDetails } from '@/redux/uniswapLiquidity';
import { ethereumUtils, getBlocksFromTimestamps } from '@/utils';
import { uniswapClient } from '@/graphql';

function cutIfOver10000(value: number) {
return value > 10000 ? Math.round(value) : value;
Expand All @@ -23,11 +25,16 @@ function getOneDayVolume(
}

async function fetchPoolDetails(address: string, dispatch: AppDispatch) {
const result = await uniswapClient.getAdditionalPoolData({ address });
const result = await uniswapClientDeprecated.query({
query: UNISWAP_ADDITIONAL_POOL_DATA,
variables: {
address,
},
});

// uniswap v2 graph for the volume

const pair = result?.pairs?.[0];
const pair = result?.data?.pairs?.[0];

if (pair) {
const partialData = {
Expand All @@ -37,7 +44,6 @@ async function fetchPoolDetails(address: string, dispatch: AppDispatch) {
const t1 = getUnixTime(startOfMinute(sub(Date.now(), { days: 1 })));
const [{ number: b1 }] = await getBlocksFromTimestamps([t1]);

// TODO(jxom): migrate this to React Query's `fetchQuery` w/ cacheTime=Infinite.
const oneDayResult = await uniswapClientDeprecated.query({
fetchPolicy: 'cache-first',
query: UNISWAP_PAIR_DATA_QUERY_VOLUME(address, b1),
Expand Down
Loading

0 comments on commit 975fd86

Please sign in to comment.