Merge pull request #14 from mars-protocol/hofix/farm-apr

fix: fixed the farm borrowing apr
This commit is contained in:
Linkie Link 2023-02-27 17:04:08 +01:00 committed by GitHub
commit 193bb0f2d6
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 33 additions and 32 deletions

View File

@ -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

View File

@ -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 = {

View File

@ -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%;
}
}

View File

@ -154,28 +154,32 @@ export const vaultsSlice = (set: NamedSet<Store>, get: GetState<Store>): 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<Store>, get: GetState<Store>): 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'