Skip to main content

ICooler

Git Source

Functions

owner

This address owns the collateral in escrow.

function owner() external view returns (address);

collateral

This token is borrowed against.

function collateral() external view returns (IERC20);

debt

This token is lent.

function debt() external view returns (IERC20);

factory

This contract created the Cooler

function factory() external view returns (ICoolerFactory);

requestLoan

Request a loan with given parameters. Collateral is taken at time of request.

function requestLoan(uint256 amount_, uint256 interest_, uint256 loanToCollateral_, uint256 duration_)
external
returns (uint256 requestId);

Parameters

NameTypeDescription
amount_uint256of debt tokens to borrow.
interest_uint256to pay (annualized % of 'amount_'). Expressed in DECIMALS_INTEREST.
loanToCollateral_uint256debt tokens per collateral token pledged. Expressed in 10**collateral().decimals().
duration_uint256of loan tenure in seconds.

Returns

NameTypeDescription
requestIduint256of the created request. Equivalent to the index of request in requests[].

rescindRequest

Cancel a loan request and get the collateral back.

function rescindRequest(uint256 requestId_) external;

Parameters

NameTypeDescription
requestId_uint256index of request in requests[].

repayLoan

Repay a loan to get the collateral back.

Despite a malicious lender could reenter with the callback, the usage of msg.sender prevents any economical benefit to the attacker, since they would be repaying the loan themselves.

function repayLoan(uint256 loanId_, uint256 repayment_) external returns (uint256 collateral);

Parameters

NameTypeDescription
loanId_uint256index of loan in loans[].
repayment_uint256debt tokens to be repaid.

Returns

NameTypeDescription
collateraluint256given back to the borrower.

clearRequest

Fill a requested loan as a lender.

function clearRequest(uint256 reqID_, address recipient_, bool isCallback_) external returns (uint256 loanId);

Parameters

NameTypeDescription
reqID_uint256index of request in requests[].
recipient_addressaddress to repay the loan to.
isCallback_booltrue if the lender implements the CoolerCallback abstract. False otherwise.

Returns

NameTypeDescription
loanIduint256of the granted loan. Equivalent to the index of loan in loans[].

extendLoanTerms

Allow lender to extend a loan for the borrower. Doesn't require borrower permission because it doesn't have a negative impact for them.

Since this function solely impacts the expiration day, the lender should ensure that extension interest payments are done beforehand.

function extendLoanTerms(uint256 loanId_, uint8 times_) external;

Parameters

NameTypeDescription
loanId_uint256index of loan in loans[].
times_uint8that the fixed-term loan duration is extended.

claimDefaulted

Claim collateral upon loan default.

function claimDefaulted(uint256 loanID_)
external
returns (uint256 principal, uint256 interestDue, uint256 collateral, uint256 elapsed);

Parameters

NameTypeDescription
loanID_uint256index of loan in loans[].

Returns

NameTypeDescription
principaluint256defaulted debt by the borrower.
interestDueuint256collateral kept by the lender.
collateraluint256elapsed time since expiry.
elapseduint256elapsed time since expiry.

collateralFor

Compute collateral needed for a desired loan amount at given loan to collateral ratio.

function collateralFor(uint256 principal_, uint256 loanToCollateral_) external view returns (uint256 collateral);

Parameters

NameTypeDescription
principal_uint256amount of debt tokens.
loanToCollateral_uint256ratio for loan. Expressed in 10**collateral().decimals().

Returns

NameTypeDescription
collateraluint256amount of collateral tokens required for the loan.

interestFor

Compute interest cost on amount for duration at given annualized rate.

function interestFor(uint256 principal_, uint256 rate_, uint256 duration_) external view returns (uint256 interest);

Parameters

NameTypeDescription
principal_uint256amount of debt tokens.
rate_uint256of interest (annualized).
duration_uint256of the loan in seconds.

Returns

NameTypeDescription
interestuint256in debt token terms.

hasExpired

Check if given loan has expired.

function hasExpired(uint256 loanID_) external view returns (bool);

Parameters

NameTypeDescription
loanID_uint256index of loan in loans[].

Returns

NameTypeDescription
<none>boolExpiration status.

isActive

Check if a given request is active.

function isActive(uint256 reqID_) external view returns (bool);

Parameters

NameTypeDescription
reqID_uint256index of request in requests[].

Returns

NameTypeDescription
<none>boolActive status.

getRequest

Getter for Request data as a struct.

function getRequest(uint256 reqID_) external view returns (Request memory);

Parameters

NameTypeDescription
reqID_uint256index of request in requests[].

Returns

NameTypeDescription
<none>RequestRequest struct.

getLoan

Getter for Loan data as a struct.

function getLoan(uint256 loanID_) external view returns (Loan memory);

Parameters

NameTypeDescription
loanID_uint256index of loan in loans[].

Returns

NameTypeDescription
<none>LoanLoan struct.

Errors

OnlyApproved

error OnlyApproved();

Deactivated

error Deactivated();

Default

error Default();

NotExpired

error NotExpired();

NotCoolerCallback

error NotCoolerCallback();

Structs

Request

A loan begins with a borrow request.

struct Request {
uint256 amount; // Amount to be borrowed.
uint256 interest; // Annualized percentage to be paid as interest.
uint256 loanToCollateral; // Requested loan-to-collateral ratio.
uint256 duration; // Time to repay the loan before it defaults.
bool active; // Any lender can clear an active loan request.
address requester; // The address that created the request.
}

Loan

A request is converted to a loan when a lender clears it.

struct Loan {
Request request; // Loan terms specified in the request.
uint256 principal; // Amount of principal debt owed to the lender.
uint256 interestDue; // Interest owed to the lender.
uint256 collateral; // Amount of collateral pledged.
uint256 expiry; // Time when the loan defaults.
address lender; // Lender's address.
address recipient; // Recipient of repayments.
bool callback; // If this is true, the lender must inherit CoolerCallback.
}