diff --git a/src/api/vaults/getDepositedVaults.ts b/src/api/vaults/getDepositedVaults.ts index 0076ae7b..516fe75b 100644 --- a/src/api/vaults/getDepositedVaults.ts +++ b/src/api/vaults/getDepositedVaults.ts @@ -76,10 +76,7 @@ async function getLpTokensForVaultPosition( const vaultQueryClient = await getVaultQueryClient(vault.address) const creditManagerQueryClient = await getCreditManagerQueryClient() const amounts = flatVaultPositionAmount(vaultPosition.amount) - const totalAmount = BN(amounts.locked) - .plus(BN(amounts.unlocked)) - .plus(BN(amounts.unlocking)) - .toString() + const totalAmount = amounts.locked.plus(amounts.unlocked).plus(amounts.unlocking).toString() const lpAmount = await vaultQueryClient.previewRedeem({ amount: totalAmount, @@ -115,15 +112,14 @@ async function getVaultValuesAndAmounts( const pricesQueries = Promise.all([ getPrice(vault.denoms.primary), getPrice(vault.denoms.secondary), + getPrice(vault.denoms.lp), ]) const lpTokensQuery = getLpTokensForVaultPosition(vault, vaultPosition) const amounts = flatVaultPositionAmount(vaultPosition.amount) - const [[primaryLpToken, secondaryLpToken], [primaryPrice, secondaryPrice]] = await Promise.all([ - lpTokensQuery, - pricesQueries, - ]) + const [[primaryLpToken, secondaryLpToken], [primaryPrice, secondaryPrice, lpPrice]] = + await Promise.all([lpTokensQuery, pricesQueries]) return { amounts: { @@ -138,6 +134,12 @@ async function getVaultValuesAndAmounts( secondary: getCoinValue(new BNCoin(secondaryLpToken), [ BNCoin.fromDenomAndBigNumber(secondaryLpToken.denom, secondaryPrice), ]), + unlocking: getCoinValue(BNCoin.fromDenomAndBigNumber(vault.denoms.lp, amounts.unlocking), [ + BNCoin.fromDenomAndBigNumber(vault.denoms.lp, lpPrice), + ]), + unlocked: getCoinValue(BNCoin.fromDenomAndBigNumber(vault.denoms.lp, amounts.unlocked), [ + BNCoin.fromDenomAndBigNumber(vault.denoms.lp, lpPrice), + ]), }, } } catch (ex) { diff --git a/src/components/Account/AccountBalancesTable/functions.ts b/src/components/Account/AccountBalancesTable/functions.ts index c0d7d569..f5b875bb 100644 --- a/src/components/Account/AccountBalancesTable/functions.ts +++ b/src/components/Account/AccountBalancesTable/functions.ts @@ -32,10 +32,18 @@ export function getVaultAccountBalanceRow( ): AccountBalanceRow { const { name } = vault const previous = prev || vault - const totalValue = vault.values.primary.plus(vault.values.secondary) - const prevTotalValue = previous.values.primary.plus(previous.values.secondary) + const totalLockedValue = vault.values.primary.plus(vault.values.secondary) + const totalValue = totalLockedValue.plus(vault.values.unlocked).plus(vault.values.unlocking) + const prevTotalValue = previous.values.primary + .plus(previous.values.secondary) + .plus(previous.values.unlocked) + .plus(previous.values.unlocking) const amountChange = !prev ? totalValue : totalValue.minus(prevTotalValue) + if (totalLockedValue.isLessThan(totalValue)) { + apy = totalLockedValue.dividedBy(totalValue).times(apy).toNumber() + } + return { type: 'vault', symbol: name, diff --git a/src/components/Earn/Farm/VaultTable.tsx b/src/components/Earn/Farm/VaultTable.tsx index ba59fa33..ecd81e10 100644 --- a/src/components/Earn/Farm/VaultTable.tsx +++ b/src/components/Earn/Farm/VaultTable.tsx @@ -105,7 +105,10 @@ export const VaultTable = (props: Props) => { header: 'Pos. Value', cell: ({ row }: { row: Row }) => { const vault = row.original as DepositedVault - const positionValue = vault.values.primary.plus(vault.values.secondary) + const positionValue = vault.values.primary + .plus(vault.values.secondary) + .plus(vault.values.unlocking) + .plus(vault.values.unlocked) const coin = BNCoin.fromDenomAndBigNumber(ORACLE_DENOM, positionValue) return }, diff --git a/src/components/Modals/Vault/VaultModalContentHeader.tsx b/src/components/Modals/Vault/VaultModalContentHeader.tsx index 483ba031..d15edc9f 100644 --- a/src/components/Modals/Vault/VaultModalContentHeader.tsx +++ b/src/components/Modals/Vault/VaultModalContentHeader.tsx @@ -17,6 +17,8 @@ export default function VaultModalContentHeader({ vault }: Props) { if ('values' in vault) { const value = vault.values.primary .plus(vault.values.secondary) + .plus(vault.values.unlocked) + .plus(vault.values.unlocking) .shiftedBy(-PRICE_ORACLE_DECIMALS) // To eliminate super small leftover amounts diff --git a/src/constants/vaults.ts b/src/constants/vaults.ts index 79599023..e5954082 100644 --- a/src/constants/vaults.ts +++ b/src/constants/vaults.ts @@ -134,6 +134,8 @@ export const MOCK_DEPOSITED_VAULT_POSITION = { values: { primary: BN_ZERO, secondary: BN_ZERO, + unlocked: BN_ZERO, + unlocking: BN_ZERO, }, amounts: { primary: BN_ZERO, diff --git a/src/hooks/useAccount.tsx b/src/hooks/useAccount.tsx index 8b79d6c2..d0570a0d 100644 --- a/src/hooks/useAccount.tsx +++ b/src/hooks/useAccount.tsx @@ -4,7 +4,7 @@ import getAccount from 'api/accounts/getAccount' export default function useAccounts(accountId?: string) { return useSWR(`account${accountId}`, () => getAccount(accountId || ''), { - refreshInterval: 30_000, + suspense: true, revalidateOnFocus: false, }) } diff --git a/src/hooks/useHealthComputer.tsx b/src/hooks/useHealthComputer.tsx index 304d5bc1..63aaa447 100644 --- a/src/hooks/useHealthComputer.tsx +++ b/src/hooks/useHealthComputer.tsx @@ -57,6 +57,8 @@ export default function useHealthComputer(account?: Account) { denom: curr.denoms.vault, value: curr.values.primary .plus(curr.values.secondary) + .plus(curr.values.unlocking) + .plus(curr.values.unlocked) .shiftedBy(VALUE_SCALE_FACTOR + 6) // Need to scale additional 6 to correct for uusd values .integerValue() .toString(), diff --git a/src/hooks/useUpdatedAccount/functions.ts b/src/hooks/useUpdatedAccount/functions.ts index fb701e5a..a099733e 100644 --- a/src/hooks/useUpdatedAccount/functions.ts +++ b/src/hooks/useUpdatedAccount/functions.ts @@ -43,7 +43,6 @@ export function addValueToVaults( availableVaults: Vault[], ): DepositedVault[] { const currentVaultAddresses = vaults.map((vault) => vault.address) - vaultValues.forEach((vaultValue) => { if (vaultValue.value.isZero()) return const halfValue = vaultValue.value.div(2) @@ -65,6 +64,8 @@ export function addValueToVaults( values: { primary: halfValue, secondary: halfValue, + unlocked: BN_ZERO, + unlocking: BN_ZERO, }, }) } diff --git a/src/hooks/useUpdatedAccount/index.ts b/src/hooks/useUpdatedAccount/index.ts index 56b311bb..0b5a22ef 100644 --- a/src/hooks/useUpdatedAccount/index.ts +++ b/src/hooks/useUpdatedAccount/index.ts @@ -199,6 +199,7 @@ export function useUpdatedAccount(account?: Account) { addedLends, removedLends, availableVaults, + prices, ]) return { diff --git a/src/pages/_layout.tsx b/src/pages/_layout.tsx index 4e9a5ade..dc12c625 100644 --- a/src/pages/_layout.tsx +++ b/src/pages/_layout.tsx @@ -58,7 +58,7 @@ export default function Layout({ children }: { children: React.ReactNode }) { 'min-h-screen gap-6 px-4 py-6 w-full relative', 'flex', isFullWidth && account && (accountDetailsExpanded ? 'pr-110.5' : 'pr-24'), - !reduceMotion && 'transition-all duration-300', + !reduceMotion && isFullWidth && 'transition-all duration-300', 'justify-center', focusComponent && 'items-center', isMobile && 'items-start', diff --git a/src/types/interfaces/vaults.d.ts b/src/types/interfaces/vaults.d.ts index 34717c94..86876c18 100644 --- a/src/types/interfaces/vaults.d.ts +++ b/src/types/interfaces/vaults.d.ts @@ -47,6 +47,8 @@ interface VaultValuesAndAmounts { values: { primary: BigNumber secondary: BigNumber + unlocked: BigNumber + unlocking: BigNumber } } diff --git a/src/utils/accounts.ts b/src/utils/accounts.ts index 2955757c..ae30f268 100644 --- a/src/utils/accounts.ts +++ b/src/utils/accounts.ts @@ -40,11 +40,13 @@ export const calculateAccountValue = ( if (type === 'vaults') { return ( - account.vaults?.reduce( - (acc, vaultPosition) => - acc.plus(vaultPosition.values.primary).plus(vaultPosition.values.secondary), - BN_ZERO, - ) || BN_ZERO + account.vaults?.reduce((acc, vaultPosition) => { + return acc + .plus(vaultPosition.values.primary) + .plus(vaultPosition.values.secondary) + .plus(vaultPosition.values.unlocking) + .plus(vaultPosition.values.unlocked) + }, BN_ZERO) || BN_ZERO ) } @@ -85,8 +87,8 @@ export const calculateAccountApr = ( }) vaults?.forEach((vault) => { - const vaultValue = vault.values.primary.plus(vault.values.secondary) - const positionInterest = vaultValue.multipliedBy(convertApyToApr(vault?.apy ?? 0, 365)) + const lockedValue = vault.values.primary.plus(vault.values.secondary) + const positionInterest = lockedValue.multipliedBy(convertApyToApr(vault?.apy ?? 0, 365)) totalVaultsInterestValue = totalVaultsInterestValue.plus(positionInterest) }) @@ -108,13 +110,6 @@ export const calculateAccountApr = ( return totalInterstValue.dividedBy(totalValue).times(100) } -export const calculateAccountBorrowRate = ( - account: Account | AccountChange, - prices: BNCoin[], -): BigNumber => { - return BN_ZERO -} - export function calculateAccountLeverage(account: Account, prices: BNCoin[]) { const [deposits, lends, debts, vaults] = getAccountPositionValues(account, prices) const netValue = deposits.plus(lends).plus(vaults).minus(debts) @@ -186,15 +181,17 @@ export function cloneAccount(account: Account): Account { vaults: account.vaults.map((vault) => ({ ...vault, amounts: { - locked: BN(vault.amounts.locked), - unlocking: BN(vault.amounts.unlocking), - unlocked: BN(vault.amounts.unlocked), - primary: BN(vault.amounts.primary), - secondary: BN(vault.amounts.secondary), + locked: vault.amounts.locked, + unlocking: vault.amounts.unlocking, + unlocked: vault.amounts.unlocked, + primary: vault.amounts.primary, + secondary: vault.amounts.secondary, }, values: { - primary: BN(vault.values.primary), - secondary: BN(vault.values.secondary), + primary: vault.values.primary, + secondary: vault.values.secondary, + unlocking: vault.values.unlocking, + unlocked: vault.values.unlocked, }, })), }