From 28178dfa7289a22553aba0f10de9a64217a1caf0 Mon Sep 17 00:00:00 2001 From: Rorry Date: Mon, 9 Dec 2024 10:32:55 +0100 Subject: [PATCH] fix(STK-156): Update Swapr dapp codebase due to subgraph changes (#1932) * prune: remove now unneeded files * prune: remove unneeded code related to single sided campaigns --- .../GetSingleSidedStakingCampaign.query.gql | 11 --- .../GetSingleSidedStakingCampaigns.query.gql | 15 ---- src/graphql/GetStakingCampaings.query.gql | 14 --- .../SingleSidedStakingCampaignFragment.gql | 10 --- ...ngleSidedStakingCampaignRewardFragment.gql | 10 --- .../useSingleSidedCampaign.ts | 53 ------------ .../useSwaprSingleSidedStakeCampaigns.ts | 74 ---------------- src/hooks/useAllLiquidityMiningCampaigns.ts | 86 +------------------ .../Pools/LiquidityMiningCampaign/index.tsx | 11 +-- src/pages/Pools/index.tsx | 8 +- 10 files changed, 8 insertions(+), 284 deletions(-) delete mode 100644 src/graphql/GetSingleSidedStakingCampaign.query.gql delete mode 100644 src/graphql/GetSingleSidedStakingCampaigns.query.gql delete mode 100644 src/graphql/GetStakingCampaings.query.gql delete mode 100644 src/graphql/fragments/SingleSidedStakingCampaignFragment.gql delete mode 100644 src/graphql/fragments/SingleSidedStakingCampaignRewardFragment.gql delete mode 100644 src/hooks/singleSidedStakeCampaigns/useSingleSidedCampaign.ts delete mode 100644 src/hooks/singleSidedStakeCampaigns/useSwaprSingleSidedStakeCampaigns.ts diff --git a/src/graphql/GetSingleSidedStakingCampaign.query.gql b/src/graphql/GetSingleSidedStakingCampaign.query.gql deleted file mode 100644 index 513acd83e..000000000 --- a/src/graphql/GetSingleSidedStakingCampaign.query.gql +++ /dev/null @@ -1,11 +0,0 @@ -query getSingleSidedStakingCampaign($campaignId: ID!) { - singleSidedStakingCampaign(id: $campaignId) { - ...SingleSidedStakingCampaignFragment - stakeToken { - ...StakeTokenFragment - } - rewards { - ...SingleSidedStakingCampaignRewardFragment - } - } -} diff --git a/src/graphql/GetSingleSidedStakingCampaigns.query.gql b/src/graphql/GetSingleSidedStakingCampaigns.query.gql deleted file mode 100644 index 76314f534..000000000 --- a/src/graphql/GetSingleSidedStakingCampaigns.query.gql +++ /dev/null @@ -1,15 +0,0 @@ -query getSingleSidedStakingCampaigns($stakeTokenId: String, $userId: String) { - singleSidedStakingCampaigns(first: 100, orderBy: endsAt, where: { stakeToken: $stakeTokenId }) { - ...SingleSidedStakingCampaignFragment - stakeToken { - ...StakeTokenFragment - } - rewards { - ...SingleSidedStakingCampaignRewardFragment - } - singleSidedStakingPositions(where: { stakedAmount_gt: 0, user: $userId }) { - id - stakedAmount - } - } -} diff --git a/src/graphql/GetStakingCampaings.query.gql b/src/graphql/GetStakingCampaings.query.gql deleted file mode 100644 index be78e3d21..000000000 --- a/src/graphql/GetStakingCampaings.query.gql +++ /dev/null @@ -1,14 +0,0 @@ -query getStakingCampaigns($userId: String) { - singleSidedStakingCampaigns(first: 999) { - ...SingleSidedStakingCampaignFragment - stakeToken { - ...StakeTokenFragment - } - rewards { - ...SingleSidedStakingCampaignRewardFragment - } - singleSidedStakingPositions(where: { stakedAmount_gt: 0, user: $userId }) { - id - } - } -} diff --git a/src/graphql/fragments/SingleSidedStakingCampaignFragment.gql b/src/graphql/fragments/SingleSidedStakingCampaignFragment.gql deleted file mode 100644 index 53406031f..000000000 --- a/src/graphql/fragments/SingleSidedStakingCampaignFragment.gql +++ /dev/null @@ -1,10 +0,0 @@ -fragment SingleSidedStakingCampaignFragment on SingleSidedStakingCampaign { - id - owner - duration - startsAt - endsAt - locked - stakingCap - stakedAmount -} diff --git a/src/graphql/fragments/SingleSidedStakingCampaignRewardFragment.gql b/src/graphql/fragments/SingleSidedStakingCampaignRewardFragment.gql deleted file mode 100644 index c894243ad..000000000 --- a/src/graphql/fragments/SingleSidedStakingCampaignRewardFragment.gql +++ /dev/null @@ -1,10 +0,0 @@ -fragment SingleSidedStakingCampaignRewardFragment on SingleSidedStakingCampaignReward { - token { - address: id - name - symbol - decimals - derivedNativeCurrency - } - amount -} diff --git a/src/hooks/singleSidedStakeCampaigns/useSingleSidedCampaign.ts b/src/hooks/singleSidedStakeCampaigns/useSingleSidedCampaign.ts deleted file mode 100644 index 1e6961e94..000000000 --- a/src/hooks/singleSidedStakeCampaigns/useSingleSidedCampaign.ts +++ /dev/null @@ -1,53 +0,0 @@ -import { SingleSidedLiquidityMiningCampaign, Token } from '@swapr/sdk' - -import { useMemo } from 'react' - -import { useActiveWeb3React } from '..' -import { SubgraphSingleSidedStakingCampaign } from '../../apollo' -import { useGetSingleSidedStakingCampaignQuery } from '../../graphql/generated/schema' -import { toSingleSidedStakeCampaign } from '../../utils/liquidityMining' -import { useNativeCurrency } from '../useNativeCurrency' - -export function useSingleSidedCampaign(campaginAddress: string): { - loading: boolean - singleSidedStakingCampaign: SingleSidedLiquidityMiningCampaign | undefined -} { - //const hardcodedShit = '0x26358e62c2eded350e311bfde51588b8383a9315' - const { chainId } = useActiveWeb3React() - const nativeCurrency = useNativeCurrency() - const { data, loading, error } = useGetSingleSidedStakingCampaignQuery({ - variables: { - campaignId: campaginAddress.toLowerCase(), - }, - }) - return useMemo(() => { - if (loading || chainId === undefined) { - return { loading: true, singleSidedStakingCampaign: undefined } - } - if (error || !data || !data.singleSidedStakingCampaign) { - return { loading: false, singleSidedStakingCampaign: undefined } - } - const wrapped = data.singleSidedStakingCampaign - const stakeToken = new Token( - chainId, - wrapped.stakeToken.id, - parseInt(wrapped.stakeToken.decimals), - wrapped.stakeToken.symbol, - wrapped.stakeToken.name - ) - - const singleSidedStakeCampaign = toSingleSidedStakeCampaign( - chainId, - wrapped as SubgraphSingleSidedStakingCampaign, - stakeToken, - wrapped.stakeToken.totalSupply, - nativeCurrency, - wrapped.stakeToken.derivedNativeCurrency - ) - - return { - loading: false, - singleSidedStakingCampaign: singleSidedStakeCampaign, - } - }, [data, loading, error, chainId, nativeCurrency]) -} diff --git a/src/hooks/singleSidedStakeCampaigns/useSwaprSingleSidedStakeCampaigns.ts b/src/hooks/singleSidedStakeCampaigns/useSwaprSingleSidedStakeCampaigns.ts deleted file mode 100644 index ae4014608..000000000 --- a/src/hooks/singleSidedStakeCampaigns/useSwaprSingleSidedStakeCampaigns.ts +++ /dev/null @@ -1,74 +0,0 @@ -import { SingleSidedLiquidityMiningCampaign, Token } from '@swapr/sdk' - -import { useMemo } from 'react' - -import { useActiveWeb3React } from '..' -import { SubgraphSingleSidedStakingCampaign } from '../../apollo' -import { PairsFilterType } from '../../components/Pool/ListFilter' -import { useGetSingleSidedStakingCampaignsQuery } from '../../graphql/generated/schema' -import { toSingleSidedStakeCampaign } from '../../utils/liquidityMining' -import { useSWPRToken } from '../swpr/useSWPRToken' -import { useNativeCurrency } from '../useNativeCurrency' - -export function useSwaprSinglelSidedStakeCampaigns( - filterToken?: Token, - filter: PairsFilterType = PairsFilterType.ALL -): { - loading: boolean - data: SingleSidedLiquidityMiningCampaign | undefined - stakedAmount?: string -} { - const { chainId, account } = useActiveWeb3React() - const nativeCurrency = useNativeCurrency() - const subgraphAccountId = account?.toLowerCase() || '' - const filterTokenAddress = filterToken?.address?.toLowerCase() - - const SWPRToken = useSWPRToken() - const swaprAddress = SWPRToken?.address ?? undefined - const { data, loading, error } = useGetSingleSidedStakingCampaignsQuery({ - variables: { - stakeTokenId: swaprAddress?.toLowerCase(), - userId: subgraphAccountId, - }, - }) - return useMemo(() => { - if (loading || chainId === undefined) { - return { loading: true, data: undefined, stakedAmount: '0' } - } - if (error || !data || data.singleSidedStakingCampaigns.length === 0) { - return { loading: false, data: undefined, stakedAmount: '0' } - } - const wrapped = data.singleSidedStakingCampaigns[data.singleSidedStakingCampaigns.length - 1] - const stakeToken = new Token( - chainId, - wrapped.stakeToken.id, - parseInt(wrapped.stakeToken.decimals), - wrapped.stakeToken.symbol, - wrapped.stakeToken.name - ) - - const singleSidedStakeCampaign = toSingleSidedStakeCampaign( - chainId, - wrapped as SubgraphSingleSidedStakingCampaign, - stakeToken, - wrapped.stakeToken.totalSupply, - nativeCurrency, - wrapped.stakeToken.derivedNativeCurrency - ) - - if ( - (filterToken !== undefined && filterTokenAddress !== swaprAddress) || - (filter === PairsFilterType.MY && wrapped.singleSidedStakingPositions.length < 0) || - singleSidedStakeCampaign.ended - ) { - return { loading: false, data: undefined } - } - - return { - loading: false, - data: singleSidedStakeCampaign, - stakedAmount: - wrapped.singleSidedStakingPositions.length > 0 ? wrapped.singleSidedStakingPositions[0].stakedAmount : '0', - } - }, [filter, data, loading, error, filterToken, swaprAddress, chainId, nativeCurrency, filterTokenAddress]) -} diff --git a/src/hooks/useAllLiquidityMiningCampaigns.ts b/src/hooks/useAllLiquidityMiningCampaigns.ts index 6352aed63..b445262fc 100644 --- a/src/hooks/useAllLiquidityMiningCampaigns.ts +++ b/src/hooks/useAllLiquidityMiningCampaigns.ts @@ -1,10 +1,10 @@ -import { BigintIsh, Pair, Token } from '@swapr/sdk' +import { BigintIsh, Pair } from '@swapr/sdk' import { useCallback, useMemo } from 'react' -import { SubgraphLiquidityMiningCampaign, SubgraphSingleSidedStakingCampaign } from '../apollo' +import { SubgraphLiquidityMiningCampaign } from '../apollo' import { PairsFilterType } from '../components/Pool/ListFilter' -import { useGetLiquidityMiningCampaignsQuery, useGetStakingCampaignsQuery } from '../graphql/generated/schema' +import { useGetLiquidityMiningCampaignsQuery } from '../graphql/generated/schema' import { useAllTokensFromActiveListsOnCurrentChain } from '../state/lists/hooks' import { getLowerTimeLimit, @@ -13,7 +13,6 @@ import { sortActiveCampaigns, sortExpiredCampaigns, toLiquidityMiningCampaign, - toSingleSidedStakeCampaign, } from '../utils/liquidityMining' import { useSWPRToken } from './swpr/useSWPRToken' @@ -23,8 +22,6 @@ import { useNativeCurrency } from './useNativeCurrency' import { useActiveWeb3React } from './index' export function useAllLiquidityMiningCampaigns(pair?: Pair, dataFilter?: PairsFilterType) { - const token0Address = pair?.token0?.address.toLowerCase() - const token1Address = pair?.token1?.address.toLowerCase() const pairAddress = pair?.liquidityToken.address.toLowerCase() const { chainId, account } = useActiveWeb3React() @@ -39,16 +36,6 @@ export function useAllLiquidityMiningCampaigns(pair?: Pair, dataFilter?: PairsFi const memoizedLowerTimeLimit = useMemo(() => getLowerTimeLimit(), []) const tokensInCurrentChain = useAllTokensFromActiveListsOnCurrentChain() - const { - data: singleSidedCampaigns, - loading: singleSidedLoading, - error: singleSidedCampaignsError, - } = useGetStakingCampaignsQuery({ - variables: { - userId: subgraphAccountId, - }, - }) - const { data: pairCampaigns, loading: campaignLoading, @@ -69,14 +56,10 @@ export function useAllLiquidityMiningCampaigns(pair?: Pair, dataFilter?: PairsFi return useMemo(() => { if ( - singleSidedLoading || !chainId || campaignLoading || !SWPRToken || - singleSidedCampaignsError || campaignError || - !singleSidedCampaigns || - !singleSidedCampaigns?.singleSidedStakingCampaigns || !pairCampaigns || !pairCampaigns.liquidityMiningCampaigns || loadingKpiTokens @@ -132,64 +115,6 @@ export function useAllLiquidityMiningCampaigns(pair?: Pair, dataFilter?: PairsFi } } - for (let i = 0; i < singleSidedCampaigns.singleSidedStakingCampaigns.length; i++) { - const campaign = singleSidedCampaigns.singleSidedStakingCampaigns[i] - - if ( - (token0Address && - token1Address && - campaign.stakeToken.id.toLowerCase() !== token0Address && - campaign.stakeToken.id.toLowerCase() !== token1Address) || - (dataFilter === PairsFilterType.MY && campaign.singleSidedStakingPositions.length === 0) - ) - continue - const containsKpiToken = !!campaign.rewards.find( - reward => !!kpiTokens.find(kpiToken => kpiToken.address.toLowerCase() === reward?.token.address.toLowerCase()) - ) - const stakeToken = new Token( - chainId, - campaign.stakeToken.id, - parseInt(campaign.stakeToken.decimals), - campaign.stakeToken.symbol, - campaign.stakeToken.name - ) - - let singleSidedStakeCampaign - try { - singleSidedStakeCampaign = toSingleSidedStakeCampaign( - chainId, - campaign as SubgraphSingleSidedStakingCampaign, - stakeToken, - campaign.stakeToken.totalSupply, - nativeCurrency, - campaign.stakeToken.derivedNativeCurrency - ) - } catch (e) { - // TODO: Investigate why `derivedNativeCurrency` is zero - console.error('Campaign', { campaign }) - continue - } - - const hasStake = campaign.singleSidedStakingPositions.length > 0 - const isExpired = parseInt(campaign.endsAt) < timestamp || parseInt(campaign.endsAt) > memoizedLowerTimeLimit - - if (dataFilter !== PairsFilterType.SWPR || SWPRToken.equals(stakeToken)) { - if (hasStake || singleSidedStakeCampaign.currentlyActive || isUpcoming(singleSidedStakeCampaign.startsAt)) { - activeCampaigns.unshift({ - campaign: singleSidedStakeCampaign, - staked: hasStake, - containsKpiToken: containsKpiToken, - }) - } else if (isExpired) { - expiredCampaigns.unshift({ - campaign: singleSidedStakeCampaign, - staked: hasStake, - containsKpiToken: containsKpiToken, - }) - } - } - } - return { loading: false, miningCampaigns: { @@ -198,12 +123,9 @@ export function useAllLiquidityMiningCampaigns(pair?: Pair, dataFilter?: PairsFi }, } }, [ - singleSidedLoading, chainId, campaignLoading, - singleSidedCampaignsError, campaignError, - singleSidedCampaigns, pairCampaigns, loadingKpiTokens, pairAddress, @@ -215,7 +137,5 @@ export function useAllLiquidityMiningCampaigns(pair?: Pair, dataFilter?: PairsFi memoizedLowerTimeLimit, SWPRToken, isUpcoming, - token0Address, - token1Address, ]) } diff --git a/src/pages/Pools/LiquidityMiningCampaign/index.tsx b/src/pages/Pools/LiquidityMiningCampaign/index.tsx index ff8864505..3c0b799a5 100644 --- a/src/pages/Pools/LiquidityMiningCampaign/index.tsx +++ b/src/pages/Pools/LiquidityMiningCampaign/index.tsx @@ -13,7 +13,6 @@ import { RowBetween, RowFixed } from '../../../components/Row' import { UndecoratedLink } from '../../../components/UndercoratedLink' import { PairState, usePair } from '../../../data/Reserves' import { useActiveWeb3React } from '../../../hooks' -import { useSingleSidedCampaign } from '../../../hooks/singleSidedStakeCampaigns/useSingleSidedCampaign' import { useToken } from '../../../hooks/Tokens' import { useLiquidityMiningCampaign } from '../../../hooks/useLiquidityMiningCampaign' import { useRouter } from '../../../hooks/useRouter' @@ -56,10 +55,6 @@ export default function LiquidityMiningCampaign() { const token1 = useToken(currencyIdB) const isSingleSidedCampaign = location.pathname.includes('/single-sided-campaign') - const { singleSidedStakingCampaign, loading: singleSidedCampaignLoading } = useSingleSidedCampaign( - liquidityMiningCampaignId! - ) - const wrappedPair = usePair(token0 || undefined, token1 || undefined) const pairOrUndefined = useMemo(() => wrappedPair[1] || undefined, [wrappedPair]) const { campaign, containsKpiToken, loading } = useLiquidityMiningCampaign(pairOrUndefined, liquidityMiningCampaignId) @@ -77,7 +72,7 @@ export default function LiquidityMiningCampaign() { const AddLiquidityButtonComponent = lpTokenBalance && lpTokenBalance.equalTo('0') ? ResponsiveButtonPrimary : ResponsiveButtonSecondary - const showSingleSidedCampaignLoader = isSingleSidedCampaign && (token0 === null || singleSidedCampaignLoading) + const showSingleSidedCampaignLoader = isSingleSidedCampaign && !token0 === null const showCampaignLoader = !isSingleSidedCampaign && (token1 === null || token0 === null) return ( @@ -142,10 +137,10 @@ export default function LiquidityMiningCampaign() { - {((!isSingleSidedCampaign && !loading) || (!singleSidedCampaignLoading && isSingleSidedCampaign)) && ( + {((!isSingleSidedCampaign && !loading) || isSingleSidedCampaign) && ( )} diff --git a/src/pages/Pools/index.tsx b/src/pages/Pools/index.tsx index d5057f6b2..e7a4434b3 100644 --- a/src/pages/Pools/index.tsx +++ b/src/pages/Pools/index.tsx @@ -20,7 +20,6 @@ import { CurrencySearchModal } from '../../components/SearchModal/CurrencySearch import { Switch } from '../../components/Switch' import { LIQUIDITY_SORTING_TYPES } from '../../constants' import { useActiveWeb3React } from '../../hooks' -import { useSwaprSinglelSidedStakeCampaigns } from '../../hooks/singleSidedStakeCampaigns/useSwaprSingleSidedStakeCampaigns' import { useAllPairsWithLiquidityAndMaximumApyAndStakingIndicator } from '../../hooks/useAllPairsWithLiquidityAndMaximumApyAndStakingIndicator' import { useLPPairs } from '../../hooks/useLiquidityPositions' import { TYPE } from '../../theme' @@ -205,8 +204,6 @@ export default function Pools() { sortBy ) - const { loading: ssLoading, data } = useSwaprSinglelSidedStakeCampaigns(filterToken, aggregatedDataFilter) - const { loading: loadingUserLpPositions, data: userLpPairs } = useLPPairs(account || undefined) const handleCurrencySelect = useCallback((token: Currency) => { @@ -239,12 +236,11 @@ export default function Pools() { sortBy={sortBy} /> {aggregatedDataFilter === PairsFilterType.MY ? ( - + ) : ( )}