From c289fcc49e9d407314cee938e7094d1f41b5c807 Mon Sep 17 00:00:00 2001 From: Linkie Link Date: Mon, 27 Feb 2023 16:53:09 +0100 Subject: [PATCH] fix: fixed the farm borrowing apr --- .../useAvailableVaultsColumns.tsx | 4 ++- .../BreakdownTable/BreakdownTable.tsx | 3 +- .../fields/VaultLogo/VaultLogo.module.scss | 22 +++++------- src/store/slices/vaults.ts | 36 ++++++++++--------- 4 files changed, 33 insertions(+), 32 deletions(-) diff --git a/src/components/fields/AvailableVaultsTable/useAvailableVaultsColumns.tsx b/src/components/fields/AvailableVaultsTable/useAvailableVaultsColumns.tsx index 6fe127e..4939beb 100644 --- a/src/components/fields/AvailableVaultsTable/useAvailableVaultsColumns.tsx +++ b/src/components/fields/AvailableVaultsTable/useAvailableVaultsColumns.tsx @@ -91,7 +91,9 @@ export const useAvailableVaultsColumns = () => { const borrowAsset = redBankAssets.find( (asset) => asset.denom === row.original.denoms.secondary, ) - const maxBorrowRate = Number(borrowAsset?.borrowRate ?? 0) * row.original.ltv.max + const maxBorrowRate = + Number(borrowAsset?.borrowRate ?? 0) * (ltvToLeverage(row.original.ltv.max) - 1) + const minAPY = new BigNumber(row.original.apy).toNumber() const maxAPY = new BigNumber(minAPY).times(maxLeverage).toNumber() - maxBorrowRate diff --git a/src/components/fields/Breakdown/BreakdownTable/BreakdownTable.tsx b/src/components/fields/Breakdown/BreakdownTable/BreakdownTable.tsx index 3e30067..fd7013e 100644 --- a/src/components/fields/Breakdown/BreakdownTable/BreakdownTable.tsx +++ b/src/components/fields/Breakdown/BreakdownTable/BreakdownTable.tsx @@ -209,7 +209,8 @@ export const BreakdownTable = (props: Props) => { const currentLeverage = props.newPosition.currentLeverage const trueBorrowRate = - (Number(secondaryRedBankAsset?.borrowRate ?? 0) / 2) * (Number(currentLeverage) - 1) + Number(secondaryRedBankAsset?.borrowRate ?? 0) * (Number(currentLeverage) - 1) + const apy = (props.vault.apy || 0) * currentLeverage - trueBorrowRate const apyData = { diff --git a/src/components/fields/VaultLogo/VaultLogo.module.scss b/src/components/fields/VaultLogo/VaultLogo.module.scss index 75bcc8f..5977dd5 100644 --- a/src/components/fields/VaultLogo/VaultLogo.module.scss +++ b/src/components/fields/VaultLogo/VaultLogo.module.scss @@ -1,24 +1,18 @@ @import 'src/styles/master'; +.primary, +.secondary { + position: absolute; + top: 50%; + transform: translateY(-50%); +} .primary { - position: absolute; + margin-top: space(-1); left: 20%; z-index: 1; } .secondary { - position: absolute; + margin-top: space(1); right: 20%; - top: 20%; -} - -@media only screen and (min-width: $bpMediumLow) { - .primary { - top: 20%; - } - - .secondary { - top: unset; - bottom: 20%; - } } diff --git a/src/store/slices/vaults.ts b/src/store/slices/vaults.ts index 8b90468..d51e841 100644 --- a/src/store/slices/vaults.ts +++ b/src/store/slices/vaults.ts @@ -154,28 +154,32 @@ export const vaultsSlice = (set: NamedSet, get: GetState): VaultsS const networkConfig = get().networkConfig if (!networkConfig) return null - const response = await fetch(networkConfig!.apolloAprUrl) + try { + const response = await fetch(networkConfig!.apolloAprUrl) - if (response.ok) { - const data: AprResponse[] = await response.json() + if (response.ok) { + const data: AprResponse[] = await response.json() - const newAprs = data.map((aprData) => { - const aprTotal = aprData.apr.reduce((prev, curr) => Number(curr.value) + prev, 0) - const feeTotal = aprData.fees.reduce((prev, curr) => Number(curr.value) + prev, 0) + const newAprs = data.map((aprData) => { + const aprTotal = aprData.apr.reduce((prev, curr) => Number(curr.value) + prev, 0) + const feeTotal = aprData.fees.reduce((prev, curr) => Number(curr.value) + prev, 0) - const finalApr = aprTotal + feeTotal + const finalApr = aprTotal + feeTotal - return { contractAddress: aprData.contract_address, apr: finalApr } - }) + return { contractAddress: aprData.contract_address, apr: finalApr } + }) - set({ - aprs: newAprs, - }) + set({ + aprs: newAprs, + }) - get().addAprToVaults(newAprs) + get().addAprToVaults(newAprs) + } + + return null + } catch { + return null } - - return null }, getCaps: async (options?: Options) => { const caps = get().caps @@ -360,7 +364,7 @@ export const vaultsSlice = (set: NamedSet, get: GetState): VaultsS const borrowRate = redBankAssets.find((asset) => asset.denom === curr.denoms.secondary)?.borrowRate || 0 - const trueBorrowRate = (borrowRate / 2) * (leverage - 1) + const trueBorrowRate = (leverage - 1) * borrowRate const getPositionStatus = (unlockTime?: number) => { if (!unlockTime) return 'active'