Skip to main content

CoolerFactory

Git Source

Title: Cooler Loans Factory.

The Cooler Factory creates new Cooler escrow contracts.

This contract uses Clones (https://github.com/wighawag/clones-with-immutable-args) to save gas on deployment.

Constants​

coolerImplementation​

Cooler reference implementation (deployed on creation to clone from).

Cooler public immutable coolerImplementation;

State Variables​

created​

Mapping to validate deployed coolers.

mapping(address => bool) public created;

coolerFor​

Mapping to prevent duplicate coolers.

mapping(address => mapping(ERC20 => mapping(ERC20 => address))) private coolerFor;

coolersFor​

Mapping to query Coolers for Collateral-Debt pair.

mapping(ERC20 => mapping(ERC20 => address[])) public coolersFor;

Functions​

constructor​

constructor();

generateCooler​

creates a new Escrow contract for collateral and debt tokens.

function generateCooler(ERC20 collateral_, ERC20 debt_) external returns (address cooler);

Parameters

NameTypeDescription
collateral_ERC20the token given as collateral.
debt_ERC20the token to be lent. Interest is denominated in debt tokens.

Returns

NameTypeDescription
cooleraddressaddress of the contract.

onlyFromFactory​

Ensure that the called is a Cooler.

modifier onlyFromFactory();

logRequestLoan​

Emit a global event when a new loan request is created.

function logRequestLoan(uint256 reqID_) external onlyFromFactory;

Parameters

NameTypeDescription
reqID_uint256

logRescindRequest​

Emit a global event when a loan request is rescinded.

function logRescindRequest(uint256 reqID_) external onlyFromFactory;

Parameters

NameTypeDescription
reqID_uint256

logClearRequest​

Emit a global event when a loan request is fulfilled.

function logClearRequest(uint256 reqID_, uint256 loanID_) external onlyFromFactory;

Parameters

NameTypeDescription
reqID_uint256
loanID_uint256

logRepayLoan​

Emit a global event when a loan is repaid.

function logRepayLoan(uint256 loanID_, uint256 repayment_) external onlyFromFactory;

Parameters

NameTypeDescription
loanID_uint256
repayment_uint256

logExtendLoan​

Emit a global event when a loan is extended.

function logExtendLoan(uint256 loanID_, uint8 times_) external onlyFromFactory;

Parameters

NameTypeDescription
loanID_uint256
times_uint8

logDefaultLoan​

Emit a global event when the collateral of defaulted loan is claimed.

function logDefaultLoan(uint256 loanID_, uint256 collateral_) external onlyFromFactory;

Parameters

NameTypeDescription
loanID_uint256
collateral_uint256

getCoolerFor​

Getter function to get an existing cooler for a given user <> collateral <> debt combination.

function getCoolerFor(
address user_,
address collateral_,
address debt_
) public view returns (address);

Parameters

NameTypeDescription
user_address
collateral_address
debt_address

Returns

NameTypeDescription
<none>address

Events​

RequestLoan​

A global event when a new loan request is created.

event RequestLoan(address indexed cooler, address collateral, address debt, uint256 reqID);

Parameters

NameTypeDescription
cooleraddress
collateraladdress
debtaddress
reqIDuint256

RescindRequest​

A global event when a loan request is rescinded.

event RescindRequest(address indexed cooler, uint256 reqID);

Parameters

NameTypeDescription
cooleraddress
reqIDuint256

ClearRequest​

A global event when a loan request is fulfilled.

event ClearRequest(address indexed cooler, uint256 reqID, uint256 loanID);

Parameters

NameTypeDescription
cooleraddress
reqIDuint256
loanIDuint256

RepayLoan​

A global event when a loan is repaid.

event RepayLoan(address indexed cooler, uint256 loanID, uint256 amount);

Parameters

NameTypeDescription
cooleraddress
loanIDuint256
amountuint256

ExtendLoan​

A global event when a loan is extended.

event ExtendLoan(address indexed cooler, uint256 loanID, uint8 times);

Parameters

NameTypeDescription
cooleraddress
loanIDuint256
timesuint8

DefaultLoan​

A global event when the collateral of defaulted loan is claimed.

event DefaultLoan(address indexed cooler, uint256 loanID, uint256 amount);

Parameters

NameTypeDescription
cooleraddress
loanIDuint256
amountuint256

Errors​

NotFromFactory​

error NotFromFactory();

DecimalsNot18​

error DecimalsNot18();