From 1bcf810845dcfec62737bf453007d3f6e9ed72ef Mon Sep 17 00:00:00 2001 From: Bob van der Helm <34470358+bobthebuidlr@users.noreply.github.com> Date: Thu, 4 Jan 2024 13:42:41 +0100 Subject: [PATCH] Perp queries (#712) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * update assets config and chains * make clients dynamic * feat: formatted ChainSelect * fix infinite rerender on trade page * feat: added NTRN icon * fix: fixed ChainInfoID * fix: fixed autoLendEnabled for NTRN * fix: fixed the navigation and dependencies * fix: fixed the pricefeed id * fix: fixed the header menu * fix: fixed the trading charts * fix: fixed the healthbars * fix: fixed naming of pion-1 * feast: updated xdefi image * env: updated contracts * make localStorage chain agnostic * fix: made the selected chain persistant * fix: fixed the wallet providers * fix: updated auto connect * fix: fixed auto connecting * fix: added ChainSelect to focusMode * store raw strings in localstorage * 🔥 remnove tests * update caching keys + disconnect wallet on change chain * update contract types and add perps asset select overlay * fix build + add perps positions to accounts * fix healthcomputer errors * fix healthcomputer errors --------- Co-authored-by: Linkie Link --- src/hooks/useHealthComputer.tsx | 7 ++----- .../MarsRoverHealthComputer.types.ts | 2 +- src/types/interfaces/perps.d.ts | 6 ++++++ src/utils/accounts.ts | 8 +++----- 4 files changed, 12 insertions(+), 11 deletions(-) diff --git a/src/hooks/useHealthComputer.tsx b/src/hooks/useHealthComputer.tsx index 1eb7810b..a34aa3b0 100644 --- a/src/hooks/useHealthComputer.tsx +++ b/src/hooks/useHealthComputer.tsx @@ -9,10 +9,7 @@ import useLocalStorage from 'hooks/localStorage/useLocalStorage' import useAssetParams from 'hooks/params/useAssetParams' import usePrices from 'hooks/usePrices' import useVaultConfigs from 'hooks/useVaultConfigs' -import { - Positions, - VaultPositionValue, -} from 'types/generated/mars-credit-manager/MarsCreditManager.types' +import { VaultPositionValue } from 'types/generated/mars-credit-manager/MarsCreditManager.types' import { VaultConfigBaseForString } from 'types/generated/mars-params/MarsParams.types' import { AssetParamsBaseForAddr, @@ -45,7 +42,7 @@ export default function useHealthComputer(account?: Account) { const [slippage] = useLocalStorage(LocalStorageKeys.SLIPPAGE, DEFAULT_SETTINGS.slippage) const [healthFactor, setHealthFactor] = useState(0) - const positions: Positions | null = useMemo(() => { + const positions: PositionsWithoutPerps | null = useMemo(() => { if (!account) return null return convertAccountToPositions(account) }, [account]) diff --git a/src/types/generated/mars-rover-health-computer/MarsRoverHealthComputer.types.ts b/src/types/generated/mars-rover-health-computer/MarsRoverHealthComputer.types.ts index 26d6f8df..69139e1f 100644 --- a/src/types/generated/mars-rover-health-computer/MarsRoverHealthComputer.types.ts +++ b/src/types/generated/mars-rover-health-computer/MarsRoverHealthComputer.types.ts @@ -41,7 +41,7 @@ export type UnlockingPositions = VaultUnlockingPosition[] export interface HealthComputer { denoms_data: DenomsData kind: AccountKind - positions: Positions + positions: PositionsWithoutPerps vaults_data: VaultsData } export interface DenomsData { diff --git a/src/types/interfaces/perps.d.ts b/src/types/interfaces/perps.d.ts index 6eb541e0..96e35d73 100644 --- a/src/types/interfaces/perps.d.ts +++ b/src/types/interfaces/perps.d.ts @@ -1 +1,7 @@ type OrderDirection = 'long' | 'short' | 'buy' | 'sell' + +// TODO: 📈Remove this type when healthcomputer is implemented +type PositionsWithoutPerps = Omit< + import('types/generated/mars-credit-manager/MarsCreditManager.types').Positions, + 'perps' +> diff --git a/src/utils/accounts.ts b/src/utils/accounts.ts index 39e05b89..7ffc56a3 100644 --- a/src/utils/accounts.ts +++ b/src/utils/accounts.ts @@ -3,10 +3,7 @@ import BigNumber from 'bignumber.js' import { BN_ZERO } from 'constants/math' import { ORACLE_DENOM } from 'constants/oracle' import { BNCoin } from 'types/classes/BNCoin' -import { - Positions, - VaultPosition, -} from 'types/generated/mars-credit-manager/MarsCreditManager.types' +import { VaultPosition } from 'types/generated/mars-credit-manager/MarsCreditManager.types' import { byDenom } from 'utils/array' import { BN } from 'utils/helpers' import { convertApyToApr } from 'utils/parsers' @@ -171,7 +168,8 @@ export function accumulateAmounts(denom: string, coins: BNCoin[]): BigNumber { return coins.reduce((acc, coin) => acc.plus(getAmount(denom, [coin.toCoin()])), BN_ZERO) } -export function convertAccountToPositions(account: Account): Positions { +// TODO: 📈 Add correct type mapping +export function convertAccountToPositions(account: Account): PositionsWithoutPerps { return { account_id: account.id, debts: account.debts.map((debt) => ({