Search…
Repayments

Purpose

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.

Roles

Borrower

Assignment
  • Through pool creation
Permissions
  • can call the repayment functions

Functionality

Repaying interest

msg.sender can repay the interests accrued by calling the function below.

Function

1
function repay(address _poolID, uint256 _amount)
2
external payable nonReentrant isPoolInitialized(_poolID) {
Copied!

Approvals

  • None

Restrictions

  • None

Arguments

  • _poolID: the pool for which interests are being repaid
  • _amount: the amount that msg.sender wishes to repay

Repaying principal

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

1
function repayPrincipal(address payable _poolID)
2
external payable nonReentrant isPoolInitialized(_poolID) {
Copied!

Approvals

  • None

Restrictions

  • All interest repayments must be complete

Arguments

  • _poolID: the pool whose principal is being repaid

Flow

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.

Helpers

Below are the helper function which help query the state of the repayment.

RepaymentConstants

This function is used to query parameters which are constant while repayment of a specific pool
1
function repaymentConstants(address poolID) view returns (
2
uint256 numberOfTotalRepayments,
3
uint256 gracePenaltyRate,
4
uint256 gracePeriodFraction,
5
uint256 loanDuration,
6
uint256 repaymentInterval,
7
uint256 borrowRate,
8
uint256 loanStartTime,
9
address repayAsset,
10
address savingsAccount
11
)
Copied!
  • 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 repaid
    • gracePenalityRate: Factor with which interest is multiplied in case of late repayment in grace period
    • gracePeriodFraction : Duration of Grace Period as a factor of repaymentInterval multiplied by
      103010^{30}
      . e.g. If repayment interval is 10 days and if grace period should be 5 days then, the param would be
      121030=51029\frac12 * 10^{30} = 5 * 10^{29}
    • loanDuration : Total duration of the loan in seconds
    • repaymentInterval : The duration of interval to repay instalments in seconds
    • borrowRate : Interest rate per annum for the pool multiplied by
      103010^{30}
    • loanStartTime : Timestamp at which loan started
    • repayAsset : Address of the borrow token for the pool
    • savingsAccount : Address of the savings account for the pool

RepaymentVars

This function is used to query the variables that track repayments for a specific pool
1
function repaymentVars(address poolID) view returns (
2
uint256 totalRepaidAmount,
3
uint256 repaymentPeriodCovered,
4
uint256 repaidAmount,
5
bool isLoanExtensionActive,
6
uint256 loanDurationCovered,
7
uint256 nextDuePeriod,
8
uint256 nInstalmentsFullyPaid,
9
uint256 loanExtensionPeriod
10
)
Copied!
  • 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 now
    • repaymentPeriodCovered : Duration of the repayment period repaid for
    • repaidAmount : Amount of borrow tokens repaid for the pool till now
    • isLoanExtensionActive : Flag to know if the pool has an extension active
    • loanDurationCovered : Duration of the loan for which interest is paid for multiplied by
      103010^{30}
    • nextDuePeriod : Period when the next repayment is due
    • nInstalmentsFullyPaid : Instalments for the pool which are completed paid
    • loanExtensionPeriod : Instalment period for which extension is granted

getInterestPerSecond

This function is used to query the interest to be paid to the pool per second
1
function getInterestPerSecond(address poolID) view returns (uint256)
Copied!
  • 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
    103010^{30}

getInstalmentsCompleted

This function is used to query the instalments for which interest is paid till now
1
function getInstalmentsCompleted(address poolID) view returns (uint256)
Copied!
  • 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
    103010^{30}
    . Scaling to
    103010^{30}
    is to ensure that accuracy is not lost

getInterestDueTillInstalmentDeadline

This function calculates the interest that is left to be repaid in that repayment interval
1
function getInterestDueTillInstalmentDeadline(address poolID) view returns (uint256)
Copied!
  • 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
    103010^{30}

getNextInstalmentDeadline

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.
1
function getNextInstalmentDeadline(address poolID) view returns (uint256)
Copied!
  • 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

getCurrentInstalmentInterval

This function calculates the interval for which repayment has to be done next
1
function getCurrentInstalmentInterval(address poolID) view returns (uint256)
Copied!
  • 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
    103010^{30}

getCurrentLoanInterval

This function calculates the instalment interval currently running
1
function getCurrentLoanInterval(address poolID) view returns (uint256)
Copied!
  • 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
    103010^{30}

isGracePenaltyApplicable

This function return a flag to specify if grace penalty is applicable for the pool. Reverts if borrower defaulted
1
function isGracePenaltyApplicable(address poolID) returns (bool)
Copied!
  • 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

didBorrowerDefault

This function returns a flag to specify if borrower defaulted due to not making repayments regularly
1
function didBorrowerDefault(address poolID) returns (bool)
Copied!
  • 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

getInterestLeft

This function calculates the total interest left to be repaid for the pool
1
function getInterestLeft(address poolID) returns (uint256)
Copied!
  • 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
    103010^{30}

getInterestOverdue

This function calculates the interest overdue when repayment deadline is missed without extension
1
function getInterestOverdue(address poolID) returns (uint256)
Copied!
  • 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
    103010^{30}

getTotalRepaidAmount

This function calculated the total amount repaid for the pool
1
function getTotalRepaidAmount(address poolID) returns (uint256)
Copied!
  • 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