Repayments
The Repayments.sol contract contains logic required to process repayments by the borrower. The loan duration of the borrower is divided into multiple instalment intervals, with the borrower having to repay the interest accrued in a particular interval before its end. A borrower can repay the interests early, ie, if the borrower wishes, they can repay the interests for intervals 2-4 of a loan with 5 intervals within interval 2 itself. However, early repayments do not entail any discounts.
The borrower is also required to repay the principal (alongside the interest) within the last interval.
If the borrower fails to repay the amount that's due within an interval before the deadline, they enter a grace period. During the grace period it's still possible for the borrower to repay albeit with a penalty.
A single-use extension can also be granted to the borrower for a given loan. Since extensions can only be given once, borrowers should be careful if they wish to do so.
Assignment
- Through pool creation
Permissions
- can call the repayment functions
msg.sender
can repay the interests accrued by calling the function below.function repay(address _poolID, uint256 _amount)
external payable nonReentrant isPoolInitialized(_poolID) {
- None
- None
_poolID
: the pool for which interests are being repaid_amount
: the amount thatmsg.sender
wishes to repay
msg.sender
can repay the principal by calling the function below. The function also calls the closeLoan()
function in Pool.sol
to close the loan. Note that the principal need to be repaid within the last instalment interval. function repayPrincipal(address payable _poolID)
external payable nonReentrant isPoolInitialized(_poolID) {
- None
- All interest repayments must be complete
_poolID
: the pool whose principal is being repaid
The following describes the typical flow with repayments:
- Borrower should repay interest to the pool every interval for the number of repayments specified in the pool.
- Borrower can request for extension which if approved, the interest for the current period can be paid along with the next interest repayment.
- If repayments are not made correctly, the pool can be liquidated.
- There is a grace period after the end of period before which interest along with the grace Period penalty has to be repaid to avoid being liquidated.
Below are the helper function which help query the state of the repayment.
This function is used to query parameters which are constant while repayment of a specific pool
function repaymentConstants(address poolID) view returns (
uint256 numberOfTotalRepayments,
uint256 gracePenaltyRate,
uint256 gracePeriodFraction,
uint256 loanDuration,
uint256 repaymentInterval,
uint256 borrowRate,
uint256 loanStartTime,
address repayAsset,
address savingsAccount
)
poolID
: Unique ID for the pool the repayment is made. Currently address of the pool contract is the unique id of that pool.RETURNS
:numberOfTotalRepayments
: Number of instalments in which loan interest should be repaidgracePenalityRate
: Factor with which interest is multiplied in case of late repayment in grace periodgracePeriodFraction
: Duration of Grace Period as a factor of repaymentInterval multiplied by. e.g. If repayment interval is 10 days and if grace period should be 5 days then, the param would beloanDuration
: Total duration of the loan in secondsrepaymentInterval
: The duration of interval to repay instalments in secondsborrowRate
: Interest rate per annum for the pool multiplied byloanStartTime
: Timestamp at which loan startedrepayAsset
: Address of the borrow token for the poolsavingsAccount
: Address of the savings account for the pool
This function is used to query the variables that track repayments for a specific pool
function repaymentVars(address poolID) view returns (
uint256 totalRepaidAmount,
uint256 repaymentPeriodCovered,
uint256 repaidAmount,
bool isLoanExtensionActive,
uint256 loanDurationCovered,
uint256 nextDuePeriod,
uint256 nInstalmentsFullyPaid,
uint256 loanExtensionPeriod
)
poolID
: Unique ID for the pool the repayment is made. Currently address of the pool contract is the unique id of that pool.RETURNS
:totalRepaidAmount
: Total amount of borrow tokens repaid till nowrepaymentPeriodCovered
: Duration of the repayment period repaid forrepaidAmount
: Amount of borrow tokens repaid for the pool till nowisLoanExtensionActive
: Flag to know if the pool has an extension activeloanDurationCovered
: Duration of the loan for which interest is paid for multiplied bynextDuePeriod
: Period when the next repayment is duenInstalmentsFullyPaid
: Instalments for the pool which are completed paidloanExtensionPeriod
: Instalment period for which extension is granted
This function is used to query the interest to be paid to the pool per second
function getInterestPerSecond(address poolID) view returns (uint256)
poolID
: Unique ID for the pool the repayment is made. Currently address of the pool contract is the unique id of that pool.RETURNS
: Interest per second to be paid to the pool multiplied by
This function is used to query the instalments for which interest is paid till now
function getInstalmentsCompleted(address poolID) view returns (uint256)
poolID
: Unique ID for the pool the repayment is made. Currently address of the pool contract is the unique id of that pool.RETURNS
: Number of instalments completed multiplied by. Scaling tois to ensure that accuracy is not lost
This function calculates the interest that is left to be repaid in that repayment interval
function getInterestDueTillInstalmentDeadline(address poolID) view returns (uint256)
poolID
: Unique ID for the pool the repayment is made. Currently address of the pool contract is the unique id of that pool.RETURNS
: Interest due for the current period multiplied by
This function calculates the timestamp till the next instalment has to be repaid. This will be end of current period in general, but if extension passes then it will be the end of next instalment period.
function getNextInstalmentDeadline(address poolID) view returns (uint256)
poolID
: Unique ID for the pool the repayment is made. Currently address of the pool contract is the unique id of that pool.RETURNS
: Timestamp of the next deadline for repayment to the pool
This function calculates the interval for which repayment has to be done next
function getCurrentInstalmentInterval(address poolID) view returns (uint256)
poolID
: Unique ID for the pool the repayment is made. Currently address of the pool contract is the unique id of that pool.RETURNS
: Interval for which repayment has to be done next multiplied by
This function calculates the instalment interval currently running
function getCurrentLoanInterval(address poolID) view returns (uint256)
poolID
: Unique ID for the pool the repayment is made. Currently address of the pool contract is the unique id of that pool.RETURNS
: Current Interval of the pool multiplied by
This function return a flag to specify if grace penalty is applicable for the pool. Reverts if borrower defaulted
function isGracePenaltyApplicable(address poolID) returns (bool)
poolID
: Unique ID for the pool the repayment is made. Currently address of the pool contract is the unique id of that pool.RETURNS
: Flag that specifies if grace penalty is applicable for the pool as instalment deadline has passed
This function returns a flag to specify if borrower defaulted due to not making repayments regularly
function didBorrowerDefault(address poolID) returns (bool)
poolID
: Unique ID for the pool the repayment is made. Currently address of the pool contract is the unique id of that pool.RETURNS
: Flag that specifies if borrower defaulted on the loan due to non payment of interest instalments within specified period
This function calculates the total interest left to be repaid for the pool
function getInterestLeft(address poolID) returns (uint256)
poolID
: Unique ID for the pool the repayment is made. Currently address of the pool contract is the unique id of that pool.RETURNS
: Interest left to be repaid in the pool multiplied by
This function calculates the interest overdue when repayment deadline is missed without extension
function getInterestOverdue(address poolID) returns (uint256)
poolID
: Unique ID for the pool the repayment is made. Currently address of the pool contract is the unique id of that pool.RETURNS
: Interest overdue when repayment deadline is missed without extension multiplied by
This function calculated the total amount repaid for the pool
function getTotalRepaidAmount(address poolID) returns (uint256)
poolID
: Unique ID for the pool the repayment is made. Currently address of the pool contract is the unique id of that pool.RETURNS
: Total amount repaid to the pool till now
Last modified 1yr ago