Skip to content

Commit

Permalink
🐛 installments: fix max pools argument
Browse files Browse the repository at this point in the history
  • Loading branch information
cruzdanilo committed May 20, 2024
1 parent f829411 commit f722000
Showing 1 changed file with 13 additions and 15 deletions.
28 changes: 13 additions & 15 deletions hooks/useInstallmentsData.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { useCallback, useMemo } from 'react';
import { parseUnits } from 'viem';
import split from '@exactly/lib/esm/installments/split';
import splitInstallments from '@exactly/lib/esm/installments/split';
import fixedUtilization from '@exactly/lib/esm/interest-rate-model/fixedUtilization';
import globalUtilization from '@exactly/lib/esm/interest-rate-model/globalUtilization';
import useAccountData from 'hooks/useAccountData';
Expand Down Expand Up @@ -40,27 +40,25 @@ export default function useInstallmentsData({
floatingBackupBorrowed,
fixedPools,
} = marketAccount;
const fixedPoolsUtilizations = fixedPools
.filter(({ maturity }) => maturity >= firstMaturity && maturity < firstMaturity + installments_ * INTERVAL)
.map(({ supplied, borrowed }) => fixedUtilization(supplied, borrowed, totalFloatingDepositAssets));
const timestamp = Math.round(Date.now() / 1000);
const parameters = [
const {
amounts: installmentsPrincipal,
installments: installmentsRepayAmount,
effectiveRate,
} = splitInstallments(
amount,
totalFloatingDepositAssets,
Number(firstMaturity),
Number(installments_),
fixedPoolsUtilizations,
fixedPools.length,
fixedPools
.filter(({ maturity }) => maturity >= firstMaturity && maturity < firstMaturity + installments_ * INTERVAL)
.map(({ supplied, borrowed }) => fixedUtilization(supplied, borrowed, totalFloatingDepositAssets)),
floatingUtilization,
globalUtilization(totalFloatingDepositAssets, totalFloatingBorrowAssets, floatingBackupBorrowed),
irmParameters,
timestamp,
] as const;
const {
amounts: installmentsPrincipal,
installments: installmentsRepayAmount,
effectiveRate,
} = split(amount, ...parameters, {
rateTolerance: 10n ** 15n,
});
{ rateTolerance: 10n ** 15n },
);
const totalPrincipal = installmentsPrincipal.reduce((acc, val) => acc + val, 0n);
const maxRepay = installmentsRepayAmount.reduce((acc, val) => acc + val, 0n);
const averageRepay = maxRepay / installments_;
Expand Down

0 comments on commit f722000

Please sign in to comment.