Pool.sol

Pool

Pools are OpenZeppelin Clones of an immutable pool implementation. The pool contract resembles an OTC term sheet with a single borrower and one or more lenders. The borrower takes a loan from the lenders on a specific predefined loan-to-value ratio against collateral.

borrower

address borrower

Address of the borrower.

whitelistedLender

address whitelistedLender

Address of the whitelisted lender.

Zero address if the pool is open to everyone.

lentAsset

address lentAsset

The ERC20 token that lenders deposit and the borrower borrows.

collateralAssets

address[] collateralAssets

The ERC20 tokens that can be used as collateral.

startsAt

uint32 startsAt

The timestamp at which the pool was deployed. Lenders can deposit lentAsset until the pool becomes active.

Set to block.timestamp during pool initialization.

activeAt

uint32 activeAt

The timestamp after which deposits close and borrowers can borrow the deposits. If the minimum is not reached, borrowers cannot borrow and lenders can withdraw their deposits without accruing yield.

maturesAt

uint32 maturesAt

The timestamp at which the Pool matures. Lenders can withdraw their deposits after maturity.

coupon

uint96 coupon

The yield for the pool during the term. The term is the duration at which the pool is active. Borrower must pay this

Denominated in WAD. A value of 1e17 means the coupon is 10%. The APR can be calculated by multiplying this value by the number of seconds in a year and dividing it by maturesAt-activeAt.

ltv

uint96 ltv

The loan-to-value ratio of the pool. When borrowing the borrower must supply collateral such that the value of the loan = ltv * value of the collateral.

Denonimated in WAD. A value of 2e18 means the LTV is 200%. The collateralization ratio is the inverse of the LTV. If the LTV is 200% then the CR is 50%.

originationFee

uint96 originationFee

The origination fee charged to the protocol treasury. When borrowing, the origination fee is deducted from the borrowed amount and transferred to the protocol treasury.

Denominated in WAD. A value of 3e15 means the origination fee is 0.3%. The Treasury address is kept in the Router contract.

leftoversWithdrawn

bool leftoversWithdrawn

A boolean that stores whether the borrower has withdrawn the redundant coupon for the pool. Borrowers are required to supply the coupon for the maximum capacity of the pool at pool creation. If the maximum capacity is not reached and the pool is active or mature, the coupon for the unfilled capacity can be withdrawn by the borrower.

minSupply

uint256 minSupply

The minimum amount of lentAsset that lenders must deposit to activate borrowing functionality.

If at least minSupply of lentAsset is deposited, borrowers can borrow all or a part of deposits. Borrowers must repay their loan before maturity or the pool will default.

maxSupply

uint256 maxSupply

The maximum amount of lentAsset that lenders can deposit. Borrowers must pay the coupon upfront based on this amount, so in practice this cannot be unbounded. This measure also keeps away pool spam.

supply

uint256 supply

The pool supply reached. This is used for a checkpoint to calculate the amount of extra coupon to withdraw.

When lenders deposit, the amount is added to supply. However when lenders redeem, the amount is NOT subtracted from supply. Therefore this variable can be interpreted as the supply reached. This is done so that the borrower can withdraw the extra coupon at any time.

borrowed

uint256 borrowed

The amount of lentAsset borrowed by the borrower. Borrowers must pay the coupon upfront based on this amount, so in practice this cannot be unbounded. This is also a measure to keep away pool spam.

notionals

mapping(address => uint256) notionals

Stores a lender's notional (total deposited amount), used to calculate rewards.

collateralReserves

mapping(address => uint256) collateralReserves

Collateral amounts supplied by the borrower.

router

address router

Address of the Router contract.

onlyRouter

modifier onlyRouter()

Verify that the caller is the router.

Throws an error otherwise.

constructor

constructor(address _router) public

initialize

function initialize(address _borrower, address _lentAsset, address[] _collateralAssets, uint96 _coupon, uint96 _ltv, uint96 _originationFee, uint32 _activeAt, uint32 _maturesAt, uint256 _minSupply, uint256 _maxSupply, address _whitelistedLender) external

Initialize the pool variables.

Called by the Router when the clone is created.

Parameters

deposit

function deposit(address _src, uint256 _amt) external

Performs accounting when an asset is deposited. Called when the lender deposits.

Can be called only by the Router.

Parameters

supplyCollateral

function supplyCollateral(address _asset, uint256 _amt) external

Performs accounting when the borrower supplies collateral.

Can be called only by the Router.

Parameters

borrow

function borrow(address _lentAsset, uint256 _amt) external

Performs accounting and transfers on borrow. Called when the borrower borrows.

Can be called only by the Router.

Parameters

repay

function repay(uint256 _amt) external

Performs accounting and transfers back collateral on repay. Called when the borrower repays their loan.

Can be called only by the Router.

Parameters

redeem

function redeem(address _src) external

Performs accounting and returns deposit to the lender. Called when the lender redeems their deposit. Partial redeems are not allowed.

Can be called only by the Router.

Parameters

_default

function _default(address _src) external

Performs accounting and returns some lent asset and collateral to the lender. Called when the lender redeems their deposit and the borrower has not repaid all debt before maturity.

Can be called only by the Router.

Parameters

withdrawLeftovers

function withdrawLeftovers(uint256 _amt) external

Performs accounting when the borrower withdraws redundant rewards.

Can be called only by the Router.

Parameters

_transfer

function _transfer(address _asset, address _dst, uint256 _amt) private

Transfers an ERC20 token from the pool.

Uses the OpenZeppelin's SafeERC20 library.

Parameters

getCollateralAssets

function getCollateralAssets() external view returns (address[])

Retrieves the array of collateral assets.

Used for off-chain data retrieval.

Return Values

Last updated