LoanDesk
LoanDesk
Provides loan lifecycle.
config
LoanDesk configuration parameters
loanTemplate
Default loan parameter values
nextApplicationId
Loan application id generator counter
loanApplications
Loan applications by applicationId
loanOffers
Loan offers by applicationId
recentApplicationIdOf
Recent application id by address
nextLoanId
Loan id generator counter
loans
Loans by loan ID
loanDetails
LoanDetails by loan ID
lentFunds
Accessor
Total funds lent at this time, accounts only for loan principals
weightedAvgAPR
Weighted average loan APR on the borrowed funds
applicationInStatus
A modifier to limit access only to when the application exists and has the specified status
loanInStatus
A modifier to limit access only to when the loan exists and has the specified status
updatedState
Modifier to update pool accounting state before function execution
constructor
initialize
Initializer a new LoanDesk.
Addresses must not be 0.
Name | Type | Description |
---|---|---|
_pool | address | Lending pool address |
_liquidityToken | address | ERC20 token contract address to be used as pool liquidity currency. |
_accessControl | address | Access control contract |
_stakerAddress | address | Staker address |
_lenderGovernanceRole | bytes32 | Role held by the timelock control that executed passed lender votes |
setMinLoanAmount
Set a minimum loan amount.
minAmount must be greater than or equal to safeMinAmount. Caller must be the staker.
Name | Type | Description |
---|---|---|
minAmount | uint256 | Minimum loan amount to be enforced on new loan requests and offers |
setMinLoanDuration
Set the minimum loan duration
Duration must be in seconds and inclusively between SAFE_MIN_DURATION and maxDuration. Caller must be the staker.
Name | Type | Description |
---|---|---|
duration | uint256 | Minimum loan duration to be enforced on new loan requests and offers |
setMaxLoanDuration
Set the maximum loan duration.
Duration must be in seconds and inclusively between minDuration and SAFE_MAX_DURATION. Caller must be the staker.
Name | Type | Description |
---|---|---|
duration | uint256 | Maximum loan duration to be enforced on new loan requests and offers |
setTemplateLoanGracePeriod
Set the template loan payment grace period.
Grace period must be in seconds and inclusively between MIN_LOAN_GRACE_PERIOD and MAX_LOAN_GRACE_PERIOD. Caller must be the staker.
Name | Type | Description |
---|---|---|
gracePeriod | uint256 | Loan payment grace period for new loan offers |
setTemplateLoanAPR
Set a template loan APR
APR must be inclusively between SAFE_MIN_APR and 100%. Caller must be the staker.
Name | Type | Description |
---|---|---|
apr | uint32 | Loan APR to be enforced on the new loan offers. |
requestLoan
Request a new loan.
_Requested amount must be greater or equal to minLoanAmount(). Loan duration must be between minDuration() and maxDuration(). Multiple pending applications from the same address are not allowed. _profileId and profileDigest are optional - provide nill values when not applicable.
Name | Type | Description |
---|---|---|
_amount | uint256 | Liquidity token amount to be borrowed |
_duration | uint256 | Loan duration in seconds |
_profileId | string | Borrower metadata profile id obtained from the borrower service |
_profileDigest | string | Borrower metadata digest obtained from the borrower service |
denyLoan
Deny a loan.
Loan must be in APPLIED status. Caller must be the staker.
draftOffer
Draft a loan offer for an application.
Loan application must be in APPLIED status. Caller must be the staker. Loan amount must not exceed available liquidity.
Name | Type | Description |
---|---|---|
appId | uint256 | Loan application id |
_amount | uint256 | Loan amount in liquidity tokens |
_duration | uint256 | Loan term in seconds |
_gracePeriod | uint256 | Loan payment grace period in seconds |
_installmentAmount | uint256 | Minimum payment amount on each instalment in liquidity tokens |
_installments | uint16 | The number of payment installments |
_apr | uint32 | Annual percentage rate of this loan |
updateDraftOffer
Update an existing draft loan offer.
Loan application must be in OFFER_DRAFTED status. Caller must be the staker. Loan amount must not exceed available liquidity.
Name | Type | Description |
---|---|---|
appId | uint256 | Loan application id |
_amount | uint256 | Loan amount in liquidity tokens |
_duration | uint256 | Loan term in seconds |
_gracePeriod | uint256 | Loan payment grace period in seconds |
_installmentAmount | uint256 | Minimum payment amount on each instalment in liquidity tokens |
_installments | uint16 | The number of payment installments |
_apr | uint32 | Annual percentage rate of this loan |
lockDraftOffer
Lock a draft loan offer.
Locking an offer makes it cancellable by a lender vote. Loan application must be in OFFER_DRAFTED status. Caller must be the staker.
Name | Type | Description |
---|---|---|
appId | uint256 | Loan application id |
offerLoan
Make a loan offer.
Loan application must be in OFFER_DRAFT_LOCKED status. Caller must be the staker. Voting lock period must have expired.
Name | Type | Description |
---|---|---|
appId | uint256 | Loan application id |
cancelLoan
Cancel a loan.
Loan application must be in one of OFFER_MADE, OFFER_DRAFT_LOCKED, OFFER_MADE statuses. Caller must be the staker or the lender governance within the voting window.
borrow
Accept a loan offer and withdraw funds
Caller must be the borrower of the loan in question. The loan must be in OFFER_MADE status.
Name | Type | Description |
---|---|---|
appId | uint256 | ID of the loan application to accept the offer of |
repay
Make a payment towards a loan.
Caller must be the borrower. Loan must be in OUTSTANDING status. Only the necessary sum is charged if amount exceeds amount due. Amount charged will not exceed the amount parameter.
Name | Type | Description |
---|---|---|
loanId | uint256 | ID of the loan to make a payment towards. |
amount | uint256 | Payment amount |
repayOnBehalf
Make a payment towards a loan on behalf of a borrower.
Loan must be in OUTSTANDING status. Only the necessary sum is charged if amount exceeds amount due. Amount charged will not exceed the amount parameter.
Name | Type | Description |
---|---|---|
loanId | uint256 | ID of the loan to make a payment towards. |
amount | uint256 | Payment amount |
borrower | address | address of the borrower to make a payment on behalf of. |
defaultLoan
Default a loan.
Loan must be in OUTSTANDING status. Caller must be the staker. canDefault(loanId) must be true.
Name | Type | Description |
---|---|---|
loanId | uint256 | ID of the loan to default |
repayBase
Make a payment towards a loan.
Loan must be in OUTSTANDING status. Only the necessary sum is charged if amount exceeds amount due. Amount charged will not exceed the amount parameter.
Name | Type | Description |
---|---|---|
loanId | uint256 | ID of the loan to make a payment towards |
amount | uint256 | Payment amount in tokens |
updateAvgApr
Internal method to update the weighted average loan apr based on the amount reduced by and an apr.
Name | Type | Description |
---|---|---|
amountReducedBy | uint256 | amount by which the funds committed into strategy were reduced, due to repayment or loss |
apr | uint32 | annual percentage rate of the strategy |
applicationsCount
Count of all loan requests in this pool.
Name | Type | Description |
---|---|---|
[0] | uint256 | LoanApplication count. |
loansCount
Count of all loans in this pool.
Name | Type | Description |
---|---|---|
[0] | uint256 | Loan count. |
loanBalanceDue
Loan balance due including interest if paid in full at this time.
Loan must be in OUTSTANDING status.
Name | Type | Description |
---|---|---|
loanId | uint256 | ID of the loan to check the balance of |
Name | Type | Description |
---|---|---|
[0] | uint256 | Total amount due with interest on this loan |
hasOpenApplication
canDefault
View indicating whether or not a given loan qualifies to be defaulted
Name | Type | Description |
---|---|---|
loanId | uint256 | ID of the loan to check |
Name | Type | Description |
---|---|---|
[0] | bool | True if the given loan can be defaulted, false otherwise |
validateLoanParams
Validates loan offer parameters
Throws a require-type exception on invalid loan parameter
Name | Type | Description |
---|---|---|
_amount | uint256 | Loan amount in liquidity tokens |
_duration | uint256 | Loan term in seconds |
_gracePeriod | uint256 | Loan payment grace period in seconds |
_installmentAmount | uint256 | Minimum payment amount on each instalment in liquidity tokens |
_installments | uint16 | The number of payment installments |
_apr | uint32 | Annual percentage rate of this loan |
loanBalanceDueWithInterest
Loan balances due if paid in full at this time.
Name | Type | Description |
---|---|---|
loanId | uint256 | ID of the loan to check the balance of |
Name | Type | Description |
---|---|---|
[0] | uint256 | Principal outstanding, interest outstanding, and the number of interest acquired days |
[1] | uint256 | |
[2] | uint256 |
payableLoanBalance
Loan balances payable given a max payment amount.
Name | Type | Description |
---|---|---|
loanId | uint256 | ID of the loan to check the balance of |
maxPaymentAmount | uint256 | Maximum liquidity token amount user has agreed to pay towards the loan |
Name | Type | Description |
---|---|---|
[0] | uint256 | Total transfer amount, interest payable, and the number of payable interest days, and the current loan balance |
[1] | uint256 | |
[2] | uint256 |
countInterestDays
Get the number of days in a time period to witch an interest can be applied.
Returns the floor of the unix day count, but not less than 1.
Name | Type | Description |
---|---|---|
borrowedTime | uint256 | Block timestamp of the loan borrowed time. |
interestPaidTillTime | uint256 | Block timestamp up to which the interest is paid for. |
Name | Type | Description |
---|---|---|
[0] | uint256 | Floor count of unix day in a time period to witch an interest can be applied. |
canClose
Indicates whether or not the contract can be closed in it's current state.
Overrides a hook in SaplingStakerContext.
Name | Type | Description |
---|---|---|
[0] | bool | True if the contract is closed, false otherwise. |
canOpen
Indicates whether or not the contract can be opened in it's current state.
Overrides a hook in SaplingStakerContext.
Name | Type | Description |
---|---|---|
[0] | bool | True if the conditions to open are met, false otherwise. |
percentDecimals
External accessor for library level percent decimals.
Last updated