Skip to content

Commit

Permalink
Correct tvl on pools list (#316)
Browse files Browse the repository at this point in the history
Co-authored-by: jmzwar <[email protected]>
  • Loading branch information
jmzwar and jmzwar authored Jun 20, 2024
1 parent 52284db commit 5217282
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,9 @@ export const useOfflinePrices = (collaterals?: Collaterals[]) => {
throw 'useOfflinePrices is missing required data';
}

const stables = ['sUSDC', 'USDC'];
const filteredCollaterals = collaterals.filter((item) => !stables.includes(item.symbol));

const returnData: { symbol: string; price: BigNumberish }[] = [
{
symbol: 'sUSDC',
Expand All @@ -135,16 +138,12 @@ export const useOfflinePrices = (collaterals?: Collaterals[]) => {
},
];

const filteredCollaterals = collaterals.filter(
(collateral) => !collateral.symbol.includes('sUSDC')
);

if (!filteredCollaterals.length) {
return returnData;
}

const pythIds = await getPythFeedIdsFromCollateralList(
collaterals.map((collateral) => collateral.symbol)
filteredCollaterals.map((collateral) => collateral.symbol)
);

const prices = await priceService.getLatestPriceFeeds(
Expand All @@ -155,7 +154,7 @@ export const useOfflinePrices = (collaterals?: Collaterals[]) => {
const price = item.getPriceUnchecked();

returnData.push({
symbol: collaterals[index].symbol,
symbol: filteredCollaterals[index].symbol,
price: parseUnits(price.price, 18 + price.expo),
});
});
Expand Down
20 changes: 17 additions & 3 deletions liquidity/ui/src/components/Pools/PoolCards/PoolCard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import { isBaseAndromeda } from '@snx-v3/isBaseAndromeda';
import { CollateralIcon } from '@snx-v3/icons';
import { useMemo } from 'react';
import { wei } from '@synthetixio/wei';
import { BigNumberish } from 'ethers';

export interface PoolCardProps {
pool: {
Expand All @@ -23,22 +24,35 @@ export interface PoolCardProps {
symbol: string;
total_amount_deposited: string;
}[];
collateralPrices?: {
symbol: string;
price: BigNumberish;
}[];
apr: {
combinedApr: number;
cumulativePnl: number;
};
}

export const PoolCard = ({ pool, network, collaterals, apr, collateralTypes }: PoolCardProps) => {
export const PoolCard = ({
pool,
network,
collaterals,
apr,
collateralTypes,
collateralPrices,
}: PoolCardProps) => {
const navigate = useNavigate();
const [queryParams] = useSearchParams();

const { network: currentNetwork, setNetwork } = useNetwork();
const { connect } = useWallet();

const vaultTVL = collateralTypes.reduce((acc, type) => {
const price = wei(collateralPrices?.find((price) => price.symbol === type.symbol)?.price || 0);
const amount = wei(type.total_amount_deposited, type.decimals, true);
return acc.add(amount);
const value = price.mul(amount);
return acc.add(value);
}, ZEROWEI);

const sanitizedCollateralTypes = collateralTypes.map((collateralType) => {
Expand Down Expand Up @@ -129,7 +143,7 @@ export const PoolCard = ({ pool, network, collaterals, apr, collateralTypes }: P
alignItems="center"
lineHeight="36px"
>
{(vaultTVL?.toNumber() && `$${compactInteger(vaultTVL.toNumber(), 1)}`) || '-'}
{(vaultTVL?.toNumber() && `$${compactInteger(vaultTVL.toNumber(), 2)}`) || '-'}
</Text>
</Flex>
<Flex alignItems="center" gap={2}>
Expand Down
21 changes: 20 additions & 1 deletion liquidity/ui/src/components/Pools/PoolsList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,35 @@ import { ChainFilter, CollateralFilter, PoolCard } from './';
import { TorosPoolCard } from './PoolCards/TorosPoolCard';
import { usePoolsList } from '@snx-v3/usePoolsList';
import { PoolCardsLoading } from './PoolCards/PoolCardsLoading';
import { useOfflinePrices } from '@snx-v3/useCollateralPriceUpdates';

export const PoolsList = () => {
const [state, dispatch] = useReducer(poolsReducer, { collateral: [], chain: [] });
const { data, isLoading } = usePoolsList();
const { data, isLoading: isPoolsListLoading } = usePoolsList();

const collaterals = data?.synthetixPools
.map((pool) =>
pool.poolInfo
.map((info) => ({
symbol: info.collateral_type.symbol,
oracleId: info.collateral_type.oracle_node_id,
id: info.collateral_type.id,
}))
.flat()
)
.flat();

const { data: collateralPrices, isLoading: isLoadingCollateralPrices } =
useOfflinePrices(collaterals);

const { collateral, chain } = state;

const showToros =
(chain.length === 0 || chain.includes(8453)) &&
(collateral.length === 0 || collateral.includes('USDC'));

const isLoading = isPoolsListLoading || isLoadingCollateralPrices;

return (
<Flex mt={6} flexDirection="column">
<Heading fontWeight={700} fontSize={24}>
Expand All @@ -40,6 +58,7 @@ export const PoolsList = () => {
<PoolCard
key={network.hexId}
collateralTypes={collateralTypes}
collateralPrices={collateralPrices}
apr={apr}
network={network}
pool={pool}
Expand Down

0 comments on commit 5217282

Please sign in to comment.