From 0426444428cfce2b57bcb01720ab1bd8e6b0aaa2 Mon Sep 17 00:00:00 2001 From: Peiman <25097709+Rickk137@users.noreply.github.com> Date: Mon, 2 Sep 2024 12:00:58 +0330 Subject: [PATCH] Fix/UI issues (#432) * feat: contracts update * fix: initial deposit UI * fix: negative c-ratio issue * fix: l1 multicall error --- contracts/importers/importMulticall3.js | 14 +++++++++---- liquidity/lib/withERC7412/withERC7412.ts | 21 ++++++++----------- .../components/CRatioBar/CRatioBar.utils.ts | 4 ++-- .../ui/src/components/Manage/DebtStats.tsx | 9 ++------ .../Positions/PositionsTable/DebtAmount.tsx | 13 ++++-------- .../Positions/PositionsTable/PositionsRow.tsx | 8 ++++++- 6 files changed, 34 insertions(+), 35 deletions(-) diff --git a/contracts/importers/importMulticall3.js b/contracts/importers/importMulticall3.js index 73148f1e9..982351d17 100644 --- a/contracts/importers/importMulticall3.js +++ b/contracts/importers/importMulticall3.js @@ -21,12 +21,18 @@ export async function importMulticall3(chainId, preset) { const deployment = `${Number(chainId).toFixed(0)}-${preset}`; switch (deployment) { case '1-main': { - const { mainnet } = await import('viem/chains'); - return { address: mainnet.contracts.multicall3.address, abi: abi }; + const [{ default: meta }, { default: abi }] = await Promise.all([ + import('@synthetixio/v3-contracts/1-main/meta.json'), + import('@synthetixio/v3-contracts/1-main/TrustedMulticallForwarder.readable.json'), + ]); + return { address: meta.contracts.TrustedMulticallForwarder, abi }; } case '11155111-main': { - const { sepolia } = await import('viem/chains'); - return { address: sepolia.contracts.multicall3.address, abi: abi }; + const [{ default: meta }, { default: abi }] = await Promise.all([ + import('@synthetixio/v3-contracts/11155111-main/meta.json'), + import('@synthetixio/v3-contracts/11155111-main/TrustedMulticallForwarder.readable.json'), + ]); + return { address: meta.contracts.TrustedMulticallForwarder, abi }; } case '10-main': { const { optimism } = await import('viem/chains'); diff --git a/liquidity/lib/withERC7412/withERC7412.ts b/liquidity/lib/withERC7412/withERC7412.ts index 67ef36bb4..e26a10f36 100644 --- a/liquidity/lib/withERC7412/withERC7412.ts +++ b/liquidity/lib/withERC7412/withERC7412.ts @@ -4,7 +4,7 @@ import { EvmPriceServiceConnection } from '@pythnetwork/pyth-evm-js'; import { z } from 'zod'; import { ZodBigNumber } from '@snx-v3/zod'; import { offchainMainnetEndpoint, offchainTestnetEndpoint } from '@snx-v3/constants'; -import { deploymentsWithERC7412, Network } from '@snx-v3/useBlockchain'; +import { Network } from '@snx-v3/useBlockchain'; import type { Modify } from '@snx-v3/tsHelpers'; import { importCoreProxy, importMulticall3, importAllErrors } from '@snx-v3/contracts'; import { withMemoryCache } from './withMemoryCache'; @@ -129,7 +129,7 @@ function makeMulticall( // This should be used for networks that doesn't have a multicall setup as a trusted forwarder // TODO remove when all networks have a trusted forwarder -const makeCoreProxyMulticall = ( +export const makeCoreProxyMulticall = ( calls: TransactionRequest[], senderAddr: string, coreProxyAddress: string, @@ -198,7 +198,7 @@ const parseError = async (error: any, provider: providers.JsonRpcProvider, netwo // simulate w/ wETH contract because it will have eth balance // This is useful when we do read/static calls but still need an balance for the price update // TODO: this probably need to be network aware, maybe look into a different solution even. -const getDefaultFromAddress = (chainName: string) => { +export const getDefaultFromAddress = (chainName: string) => { switch (chainName) { case 'cannon': return '0x4200000000000000000000000000000000000006'; // TODO, unclear what to put here @@ -247,12 +247,12 @@ export const withERC7412 = async ( // If from is set to the default address (wETH) we can assume it's a read rather than a write const isRead = from === getDefaultFromAddress(network.name); - const networkHaveERC7412 = deploymentsWithERC7412.includes(`${network.id}-${network.preset}`); - const useCoreProxy = !networkHaveERC7412 && !isRead; + // const networkHaveERC7412 = deploymentsWithERC7412.includes(`${network.id}-${network.preset}`); - const { address: multicallAddress, abi: multiCallAbi } = useCoreProxy - ? await importCoreProxy(network.id, network.preset) - : await importMulticall3(network.id, network.preset); + const { address: multicallAddress, abi: multiCallAbi } = await importMulticall3( + network.id, + network.preset + ); while (true) { try { @@ -292,10 +292,7 @@ export const withERC7412 = async ( } // If we're here it means we now added a tx to do . // Some networks doesn't have ERC7412 and a trusted forwarder setup, on write calls we still need to use the coreproxy for those - const multicallTxn = useCoreProxy - ? makeCoreProxyMulticall(multicallCalls, from, multicallAddress, multiCallAbi) - : makeMulticall(multicallCalls, from, multicallAddress, multiCallAbi); - + const multicallTxn = makeMulticall(multicallCalls, from, multicallAddress, multiCallAbi); const gasLimit = await jsonRpcProvider.estimateGas(multicallTxn); console.log( diff --git a/liquidity/ui/src/components/CRatioBar/CRatioBar.utils.ts b/liquidity/ui/src/components/CRatioBar/CRatioBar.utils.ts index 6c862b15f..21ab7d504 100644 --- a/liquidity/ui/src/components/CRatioBar/CRatioBar.utils.ts +++ b/liquidity/ui/src/components/CRatioBar/CRatioBar.utils.ts @@ -10,7 +10,7 @@ export const getHealthVariant = ({ if (!liquidationCratio || !targetCratio || !cRatio) { return 'success'; } - if (cRatio === 0) { + if (cRatio <= 0) { return 'success'; } if (cRatio < liquidationCratio) { @@ -22,7 +22,7 @@ export const getHealthVariant = ({ return 'success'; }; -export const ratioIsMaxUInt = (ratio: number) => ratio >= Number.MAX_SAFE_INTEGER; +export const ratioIsMaxUInt = (ratio: number) => ratio >= Number.MAX_SAFE_INTEGER || ratio < 0; export const getProgressSize = ({ targetCratio, diff --git a/liquidity/ui/src/components/Manage/DebtStats.tsx b/liquidity/ui/src/components/Manage/DebtStats.tsx index 3804d4e85..52fb0160a 100644 --- a/liquidity/ui/src/components/Manage/DebtStats.tsx +++ b/liquidity/ui/src/components/Manage/DebtStats.tsx @@ -10,6 +10,7 @@ import { ZEROWEI } from '../../utils/constants'; import { ChangeStat } from './ChangeStat'; import { isBaseAndromeda } from '@snx-v3/isBaseAndromeda'; import { useNetwork } from '@snx-v3/useBlockchain'; +import { DebtAmount } from '../Positions/PositionsTable/DebtAmount'; export const DebtStats: FC<{ liquidityPosition?: LiquidityPosition; @@ -62,13 +63,7 @@ export const DebtStats: FC<{ - currency(val, { - currency: 'USD', - style: 'currency', - maximumFractionDigits: 4, - }) - } + formatFn={(val: Wei) => } hasChanges={hasChanges} dataTestId="manage-stats-debt-value" /> diff --git a/liquidity/ui/src/components/Positions/PositionsTable/DebtAmount.tsx b/liquidity/ui/src/components/Positions/PositionsTable/DebtAmount.tsx index 1ce72e71c..325f415fb 100644 --- a/liquidity/ui/src/components/Positions/PositionsTable/DebtAmount.tsx +++ b/liquidity/ui/src/components/Positions/PositionsTable/DebtAmount.tsx @@ -1,23 +1,18 @@ -import { Text } from '@chakra-ui/react'; +import { Text, TextProps } from '@chakra-ui/react'; import { Amount } from '@snx-v3/Amount'; import Wei from '@synthetixio/wei'; import { FC } from 'react'; -interface Props { +interface Props extends TextProps { debt: Wei; showPNL?: boolean; } -export const DebtAmount: FC = ({ debt, showPNL }) => { +export const DebtAmount: FC = ({ debt, showPNL, ...props }) => { const amount = showPNL ? debt.mul(-1) : debt; return ( - + ); diff --git a/liquidity/ui/src/components/Positions/PositionsTable/PositionsRow.tsx b/liquidity/ui/src/components/Positions/PositionsTable/PositionsRow.tsx index cdb7507f8..403e619d8 100644 --- a/liquidity/ui/src/components/Positions/PositionsTable/PositionsRow.tsx +++ b/liquidity/ui/src/components/Positions/PositionsTable/PositionsRow.tsx @@ -150,7 +150,13 @@ export function PositionRow({ - +