Skip to content

Commit

Permalink
CentrifugeJS: Fix outstanding debt (#1303)
Browse files Browse the repository at this point in the history
  • Loading branch information
onnovisser authored Apr 12, 2023
1 parent ca97ec5 commit d88f009
Showing 1 changed file with 9 additions and 6 deletions.
15 changes: 9 additions & 6 deletions centrifuge-js/src/modules/pools.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2047,7 +2047,10 @@ export function getPoolsModule(inst: Centrifuge) {

const activeLoans: ActiveLoan[] = (activeLoanValues.toJSON() as any[]).map(
([loan]: [ActiveLoanData, number]) => {
const interestData = rates.find((rate) => rate.interestRatePerSec === loan.info.interestRate)
const loanRate = new Rate(hexToBN(loan.info.interestRate)).toDecimal().toString()
const interestData = rates.find(
(rate) => new Rate(hexToBN(rate.interestRatePerSec)).toApr().toDecimalPlaces(4).toString() === loanRate
)
const writeOffStatus = {
penaltyInterestRate: new Rate(hexToBN(loan.writeOffStatus.penalty)),
percentage: new Rate(hexToBN(loan.writeOffStatus.percentage)),
Expand All @@ -2067,7 +2070,7 @@ export function getPoolsModule(inst: Centrifuge) {
loan,
currency.decimals,
interestLastUpdated.toJSON() as number,
interestData?.accumulatedRate
interestData
),
normalizedDebt: new CurrencyBalance(hexToBN(loan.normalizedDebt), currency.decimals),
}
Expand Down Expand Up @@ -2330,11 +2333,11 @@ function getOutstandingDebt(
loan: ActiveLoanData,
currencyDecimals: number,
lastUpdated: number,
accumulatedRate?: InterestAccrual['accumulatedRate']
accrual?: InterestAccrual
) {
if (!accumulatedRate) return new CurrencyBalance(0, currencyDecimals)
const accRate = new Rate(hexToBN(accumulatedRate)).toDecimal()
const rate = new Rate(hexToBN(loan.info.interestRate)).toDecimal()
if (!accrual) return new CurrencyBalance(0, currencyDecimals)
const accRate = new Rate(hexToBN(accrual.accumulatedRate)).toDecimal()
const rate = new Rate(hexToBN(accrual.interestRatePerSec)).toDecimal()
const normalizedDebt = new CurrencyBalance(hexToBN(loan.normalizedDebt), currencyDecimals).toDecimal()
const secondsSinceUpdated = Date.now() / 1000 - lastUpdated

Expand Down

0 comments on commit d88f009

Please sign in to comment.