diff --git a/liquidity/lib/useCollateralPriceUpdates/package.json b/liquidity/lib/useCollateralPriceUpdates/package.json index a8b4151a1..08a269049 100644 --- a/liquidity/lib/useCollateralPriceUpdates/package.json +++ b/liquidity/lib/useCollateralPriceUpdates/package.json @@ -7,6 +7,7 @@ "@pythnetwork/pyth-evm-js": "^1.42.0", "@snx-v3/constants": "workspace:*", "@snx-v3/contracts": "workspace:*", + "@snx-v3/format": "workspace:*", "@snx-v3/isBaseAndromeda": "workspace:*", "@snx-v3/useBlockchain": "workspace:*", "@snx-v3/usePoolsList": "workspace:*", diff --git a/liquidity/lib/useCollateralPriceUpdates/useCollateralPriceUpdates.ts b/liquidity/lib/useCollateralPriceUpdates/useCollateralPriceUpdates.ts index 566a85202..a64ab8cdc 100644 --- a/liquidity/lib/useCollateralPriceUpdates/useCollateralPriceUpdates.ts +++ b/liquidity/lib/useCollateralPriceUpdates/useCollateralPriceUpdates.ts @@ -1,5 +1,5 @@ import { useQuery } from '@tanstack/react-query'; -import { ethers } from 'ethers'; +import { BigNumberish, ethers } from 'ethers'; import { Network, useDefaultProvider, useNetwork, useWallet } from '@snx-v3/useBlockchain'; import { EvmPriceServiceConnection } from '@pythnetwork/pyth-evm-js'; import { offchainMainnetEndpoint } from '@snx-v3/constants'; @@ -7,8 +7,9 @@ import { ERC7412_ABI } from '@snx-v3/withERC7412'; import { isBaseAndromeda } from '@snx-v3/isBaseAndromeda'; import { importMulticall3, importExtras } from '@snx-v3/contracts'; import { networksOffline } from '@snx-v3/usePoolsList'; -import { wei, Wei } from '@synthetixio/wei'; +import { wei } from '@synthetixio/wei'; import { importPythERC7412Wrapper } from '@snx-v3/contracts'; +import { parseUnits } from '@snx-v3/format'; const priceService = new EvmPriceServiceConnection(offchainMainnetEndpoint); @@ -123,10 +124,14 @@ export const useOfflinePrices = (collaterals?: Collaterals[]) => { throw 'useOfflinePrices is missing required data'; } - const returnData: { symbol: string; price: Wei }[] = [ + const returnData: { symbol: string; price: BigNumberish }[] = [ { symbol: 'sUSDC', - price: wei(1), + price: wei(1).toBN(), + }, + { + symbol: 'USDC', + price: wei(1).toBN(), }, ]; @@ -149,9 +154,9 @@ export const useOfflinePrices = (collaterals?: Collaterals[]) => { prices?.forEach((item, index) => { const price = item.getPriceUnchecked(); - returnData.unshift({ - symbol: filteredCollaterals[index].symbol, - price: wei(price.price, price.expo), + returnData.push({ + symbol: collaterals[index].symbol, + price: parseUnits(price.price, 18 + price.expo), }); }); diff --git a/liquidity/lib/useCoreProxy/useCoreProxy.ts b/liquidity/lib/useCoreProxy/useCoreProxy.ts index 8ee141214..3e11e8c7b 100644 --- a/liquidity/lib/useCoreProxy/useCoreProxy.ts +++ b/liquidity/lib/useCoreProxy/useCoreProxy.ts @@ -9,7 +9,7 @@ import { } from '@snx-v3/useBlockchain'; import { importCoreProxy } from '@snx-v3/contracts'; -export function useCoreProxy(customNetwork?: Network) { +export function useCoreProxy(customNetwork?: Network | null) { const providerForChain = useProviderForChain(customNetwork); const { network } = useNetwork(); const provider = useProvider(); diff --git a/liquidity/lib/useLiquidityPositions/useLiquidityPositions.ts b/liquidity/lib/useLiquidityPositions/useLiquidityPositions.ts index bfc65ee93..bfc16de4e 100644 --- a/liquidity/lib/useLiquidityPositions/useLiquidityPositions.ts +++ b/liquidity/lib/useLiquidityPositions/useLiquidityPositions.ts @@ -161,9 +161,7 @@ export const useLiquidityPositions = ({ accountId }: { accountId?: string }) => 'useLiquidityPositions' ); }, - enabled: Boolean( - collateralPriceUpdates && CoreProxy && collateralTypes?.length && accountId && pools?.length - ), + enabled: Boolean(CoreProxy && collateralTypes?.length && accountId && pools?.length), }); return { diff --git a/liquidity/lib/usePools/usePools.ts b/liquidity/lib/usePools/usePools.ts index b532a5275..820c4d827 100644 --- a/liquidity/lib/usePools/usePools.ts +++ b/liquidity/lib/usePools/usePools.ts @@ -21,15 +21,16 @@ export type PoolsType = z.infer; export function usePools(customNetwork?: Network) { const { network } = useNetwork(); - const { data: CoreProxy } = useCoreProxy(customNetwork); - const targetNetwork = customNetwork || network; + const { data: CoreProxy } = useCoreProxy(targetNetwork); return useQuery({ enabled: Boolean(targetNetwork), - queryKey: [`${targetNetwork?.id}-${targetNetwork?.preset}`, 'Pools'], + queryKey: [`${targetNetwork?.id}-${targetNetwork?.preset}`, CoreProxy?.address, 'Pools'], queryFn: async () => { - if (!CoreProxy) throw 'usePools is missing required data'; + if (!CoreProxy) { + throw 'usePools is missing required data'; + } const [prefferedPoolId, approvedPoolIds] = await Promise.all([ CoreProxy.callStatic.getPreferredPool(), diff --git a/liquidity/ui/src/components/Pools/CollateralSection.tsx b/liquidity/ui/src/components/Pools/CollateralSection.tsx index 1cc7d65ea..ed76ba64e 100644 --- a/liquidity/ui/src/components/Pools/CollateralSection.tsx +++ b/liquidity/ui/src/components/Pools/CollateralSection.tsx @@ -1,7 +1,7 @@ import { Box, Divider, Flex, Skeleton, Text } from '@chakra-ui/react'; import { useVaultsData, VaultsDataType } from '@snx-v3/useVaultsData'; import React, { FC } from 'react'; -import Wei, { wei } from '@synthetixio/wei'; +import { wei } from '@synthetixio/wei'; import { formatNumber, formatNumberToUsd, formatPercent } from '@snx-v3/formatters'; import { useParams } from '@snx-v3/useParams'; import { BorderBox } from '@snx-v3/BorderBox'; @@ -11,6 +11,8 @@ import { Tooltip } from '@snx-v3/Tooltip'; import { NETWORKS } from '@snx-v3/useBlockchain'; import { useOfflinePrices } from '@snx-v3/useCollateralPriceUpdates'; import { usePool } from '@snx-v3/usePoolsList'; +import { formatEther } from 'ethers/lib/utils'; +import { BigNumberish } from 'ethers'; export const calculateVaultTotals = (vaultsData: VaultsDataType) => { const zeroValues = { collateral: { value: wei(0), amount: wei(0) }, debt: wei(0) }; @@ -27,7 +29,7 @@ export const calculateVaultTotals = (vaultsData: VaultsDataType) => { export const CollateralSectionUi: FC<{ vaultsData: VaultsDataType; - collateralPrices?: { symbol: string; price: Wei }[]; + collateralPrices?: { symbol: string; price: BigNumberish }[]; apr?: number; isAprLoading?: boolean; }> = ({ vaultsData, collateralPrices, apr, isAprLoading }) => { @@ -108,7 +110,7 @@ export const CollateralSectionUi: FC<{ )} - + {!vaultsData || !collateralPrices ? ( @@ -116,19 +118,18 @@ export const CollateralSectionUi: FC<{ ) : ( <> - {vaultsData.map((vaultCollateral) => { const price = collateralPrices?.find( (item) => item.symbol === vaultCollateral.collateralType.symbol )?.price; + return ( + - {price ? formatNumberToUsd(price.toNumber()) : '-'} + {price ? formatNumberToUsd(formatEther(price.toString())) : '-'} - + - + { - try { - if (!currentNetwork) { - connect(); - return; - } - - if (currentNetwork.id !== network.id) { - if (!(await setNetwork(network.id))) { - return; - } - } - - navigate(`/pools/${network.id}/${pool.id}`); - } catch (error) {} - }} + onClick={() => navigate(`/pools/${network.id}/${pool.id}`)} > diff --git a/liquidity/ui/src/pages/Pool.tsx b/liquidity/ui/src/pages/Pool.tsx index 2f76cb665..028225416 100644 --- a/liquidity/ui/src/pages/Pool.tsx +++ b/liquidity/ui/src/pages/Pool.tsx @@ -14,7 +14,10 @@ export const Pool = () => { const { poolInfo } = pool || {}; - const registeredDistributors = poolInfo?.map((info) => info.pool.registered_distributors).flat(); + const registeredDistributors = poolInfo + ?.map((info) => info.pool.registered_distributors) + .flat() + ?.filter((item, pos, self) => self.findIndex((d) => d.id === item.id) === pos); const collateralTypes = poolInfo?.map((info) => info.collateral_type); const network = NETWORKS.find((n) => n.id === Number(networkId)); @@ -42,7 +45,7 @@ export const Pool = () => { - + diff --git a/yarn.lock b/yarn.lock index 0bcb1bc4e..d05277cbb 100644 --- a/yarn.lock +++ b/yarn.lock @@ -6221,6 +6221,7 @@ __metadata: "@pythnetwork/pyth-evm-js": "npm:^1.42.0" "@snx-v3/constants": "workspace:*" "@snx-v3/contracts": "workspace:*" + "@snx-v3/format": "workspace:*" "@snx-v3/isBaseAndromeda": "workspace:*" "@snx-v3/useBlockchain": "workspace:*" "@snx-v3/usePoolsList": "workspace:*"