fix: apys and aprs (#514)
* fix: fixed aprs * fix: apy and apr * fix: fixed build
This commit is contained in:
parent
f20ae553d9
commit
fac07787c5
@ -36,6 +36,7 @@ export default async function getVaults(): Promise<Vault[]> {
|
||||
),
|
||||
},
|
||||
apy: apr ? convertAprToApy(apr.apr, 365) : null,
|
||||
apr: apr ? apr.apr / 100 : null,
|
||||
ltv: {
|
||||
max: Number(vaultConfig.max_loan_to_value),
|
||||
liq: Number(vaultConfig.liquidation_threshold),
|
||||
|
@ -52,7 +52,7 @@ export default function useAccountBalanceData(props: Props) {
|
||||
})
|
||||
|
||||
const vaults = accountVaults.map((vault) => {
|
||||
const apy = (vault.apy ?? 0) * 100
|
||||
const apy = vault.apy ?? 0
|
||||
const prevVault = updatedAccount
|
||||
? account?.vaults.find((position) => position.name === vault.name)
|
||||
: vault
|
||||
|
@ -76,6 +76,7 @@ function Fallback() {
|
||||
const mockVaults: Vault[] = vaults.map((vault) => ({
|
||||
...vault,
|
||||
apy: null,
|
||||
apr: null,
|
||||
ltv: {
|
||||
max: 0,
|
||||
liq: 0,
|
||||
|
@ -56,11 +56,13 @@ export function addValueToVaults(
|
||||
|
||||
if (!vaultMetaData) return
|
||||
const apy = availableVaults.find((vault) => vault.address === vaultValue.address)?.apy ?? null
|
||||
const apr = availableVaults.find((vault) => vault.address === vaultValue.address)?.apr ?? null
|
||||
|
||||
vaults.push({
|
||||
...vaultMetaData,
|
||||
...MOCK_DEPOSITED_VAULT_POSITION,
|
||||
apy,
|
||||
apr,
|
||||
values: {
|
||||
primary: halfValue,
|
||||
secondary: halfValue,
|
||||
|
1
src/types/interfaces/vaults.d.ts
vendored
1
src/types/interfaces/vaults.d.ts
vendored
@ -34,6 +34,7 @@ interface VaultConfig extends VaultMetaData, VaultInfo {}
|
||||
|
||||
interface Vault extends VaultConfig {
|
||||
apy: number | null
|
||||
apr: number | null
|
||||
}
|
||||
|
||||
interface VaultValuesAndAmounts {
|
||||
|
@ -9,7 +9,8 @@ import {
|
||||
import { byDenom } from 'utils/array'
|
||||
import { getAssetByDenom } from 'utils/assets'
|
||||
import { BN } from 'utils/helpers'
|
||||
import { convertApyToApr } from 'utils/parsers'
|
||||
|
||||
import { convertApyToApr } from './parsers'
|
||||
|
||||
export const calculateAccountBalanceValue = (
|
||||
account: Account | AccountChange,
|
||||
@ -66,7 +67,11 @@ export const calculateAccountApr = (
|
||||
lendingAssetsData: LendingMarketTableData[],
|
||||
prices: BNCoin[],
|
||||
): BigNumber => {
|
||||
const totalValue = calculateAccountBalanceValue(account, prices)
|
||||
const depositValue = calculateAccountValue('deposits', account, prices)
|
||||
const lendsValue = calculateAccountValue('lends', account, prices)
|
||||
const vaultsValue = calculateAccountValue('vaults', account, prices)
|
||||
const totalValue = depositValue.plus(lendsValue).plus(vaultsValue)
|
||||
|
||||
if (totalValue.isZero()) return BN_ZERO
|
||||
const { vaults, lends, debts } = account
|
||||
|
||||
@ -88,7 +93,7 @@ export const calculateAccountApr = (
|
||||
|
||||
vaults?.forEach((vault) => {
|
||||
const lockedValue = vault.values.primary.plus(vault.values.secondary)
|
||||
const positionInterest = lockedValue.multipliedBy(convertApyToApr(vault?.apy ?? 0, 365))
|
||||
const positionInterest = lockedValue.multipliedBy(vault?.apr ?? 0)
|
||||
totalVaultsInterestValue = totalVaultsInterestValue.plus(positionInterest)
|
||||
})
|
||||
|
||||
@ -97,16 +102,17 @@ export const calculateAccountApr = (
|
||||
if (!asset) return BN_ZERO
|
||||
const price = prices.find(byDenom(debt.denom))?.amount ?? 0
|
||||
const amount = BN(debt.amount).shiftedBy(-asset.decimals)
|
||||
const apr =
|
||||
const apy =
|
||||
borrowAssetsData.find((borrowAsset) => borrowAsset.asset.denom === debt.denom)?.borrowRate ??
|
||||
0
|
||||
const positionInterest = amount.multipliedBy(price).multipliedBy(apr)
|
||||
const positionInterest = amount.multipliedBy(price).multipliedBy(convertApyToApr(apy, 365))
|
||||
totalDebtInterestValue = totalDebtInterestValue.plus(positionInterest)
|
||||
})
|
||||
|
||||
const totalInterstValue = totalLendsInterestValue
|
||||
.plus(totalVaultsInterestValue)
|
||||
.minus(totalDebtInterestValue)
|
||||
|
||||
return totalInterstValue.dividedBy(totalValue).times(100)
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user