Skip to content

Commit

Permalink
Add loan APR. Refactor net apr calculation
Browse files Browse the repository at this point in the history
  • Loading branch information
sablevsky committed Dec 12, 2024
1 parent 079d9a2 commit 9dc819c
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 13 deletions.
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { calcBorrowerTokenAPR } from 'fbonds-core/lib/fbond-protocol/helpers'

import { ColumnType } from '@banx/components/Table'
import { HeaderCell, createPercentValueJSX } from '@banx/components/TableComponents'
import { HeaderCell } from '@banx/components/TableComponents'

import { CollateralToken } from '@banx/api/tokens'

Expand Down Expand Up @@ -38,7 +38,7 @@ export const getTableColumns: GetTableColumns = ({ collateral }) => {
render: (offer) => {
const marketInterestFee = collateral?.collateral.interestFee || 0
const aprPercent = calcBorrowerTokenAPR(offer.apr.toNumber(), marketInterestFee) / 100
return <span>{createPercentValueJSX(aprPercent)}</span>
return <span>{aprPercent.toFixed(1)}%</span>
},
},

Expand Down
27 changes: 16 additions & 11 deletions src/pages/tokenLending/LeveragePage/components/Summary/Summary.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -49,23 +49,26 @@ export const Summary: FC<SummaryProps> = ({

const upfrontFee = new BN(borrowAmount).mul(new BN(marketUpfrontFee)).div(new BN(BASE_POINTS))

const statClassNames = {
value: styles.fixedStatValue,
}
const aprRate = selectedOffer
? calcBorrowerTokenAPR(selectedOffer.apr.toNumber(), marketUpfrontFee)
: 0

const netApr = selectedOffer
? calculateNetApr({
totalCollateralAmount,
userEnteredCollateralAmount,
conversionRate,
offer: selectedOffer,
collateral,
aprRate,
collateralYield,
})
: 0

const upfrontFeePercent = marketUpfrontFee / 100

const statClassNames = {
value: styles.fixedStatValue,
}

return (
<div className={styles.summary}>
{/* <StatInfo
Expand All @@ -85,6 +88,12 @@ export const Summary: FC<SummaryProps> = ({
classNamesProps={statClassNames}
flexType="row"
/>
<StatInfo
label="Offer APR"
value={`${(aprRate / 100).toFixed(1)}%`}
classNamesProps={statClassNames}
flexType="row"
/>
<StatInfo
label="NET APR"
value={`${netApr.toFixed(1)}%`}
Expand Down Expand Up @@ -118,28 +127,24 @@ export const Summary: FC<SummaryProps> = ({
}

type CalculateNetAprParams = {
offer: LeverageSimpleOffer
totalCollateralAmount: BN
userEnteredCollateralAmount: BN
conversionRate: number
collateral: CollateralToken
collateralYield: BN
aprRate: number
}
const calculateNetApr = ({
totalCollateralAmount,
userEnteredCollateralAmount,
conversionRate,
offer,
collateral,
collateralYield,
aprRate,
}: CalculateNetAprParams) => {
const totalBorrowAmount = calculateTokenLoanBorrowAmount(
totalCollateralAmount.sub(userEnteredCollateralAmount),
conversionRate,
)

const aprRate = calcBorrowerTokenAPR(offer.apr.toNumber(), collateral.collateral.interestFee)

const debtInYear = calculateCurrentInterestSolPure({
loanValue: bnToNumberSafe(totalBorrowAmount),
startTime: moment().unix(),
Expand Down

0 comments on commit 9dc819c

Please sign in to comment.