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 borrowerAddress of the borrower.
whitelistedLender
address whitelistedLenderAddress of the whitelisted lender.
Zero address if the pool is open to everyone.
lentAsset
address lentAssetThe ERC20 token that lenders deposit and the borrower borrows.
collateralAssets
address[] collateralAssetsThe ERC20 tokens that can be used as collateral.
startsAt
uint32 startsAtThe 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 activeAtThe 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 maturesAtThe timestamp at which the Pool matures. Lenders can withdraw their deposits after maturity.
coupon
uint96 couponThe 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 ltvThe 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 originationFeeThe 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 leftoversWithdrawnA 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 minSupplyThe 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 maxSupplyThe 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 supplyThe 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 borrowedThe 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) notionalsStores a lender's notional (total deposited amount), used to calculate rewards.
collateralReserves
mapping(address => uint256) collateralReservesCollateral amounts supplied by the borrower.
router
address routerAddress of the Router contract.
onlyRouter
modifier onlyRouter()Verify that the caller is the router.
Throws an error otherwise.
constructor
constructor(address _router) publicinitialize
function initialize(address _borrower, address _lentAsset, address[] _collateralAssets, uint96 _coupon, uint96 _ltv, uint96 _originationFee, uint32 _activeAt, uint32 _maturesAt, uint256 _minSupply, uint256 _maxSupply, address _whitelistedLender) externalInitialize the pool variables.
Called by the Router when the clone is created.
Parameters
_borrower
address
The address of the borrower.
_lentAsset
address
The address of the lent asset.
_collateralAssets
address[]
The addresses of the collateral assets.
_coupon
uint96
The yield generated by lenders in WAD.
_ltv
uint96
The loan-to-value ratio for the borrower.
_originationFee
uint96
The fee charged by the protocol given by the .
_activeAt
uint32
When deposits end and borrowing is allowed.
_maturesAt
uint32
When the pool is over.
_minSupply
uint256
Minimum supply of the lent asset to enable borrowing.
_maxSupply
uint256
Maximum allowed supply of the lent asset.
_whitelistedLender
address
deposit
function deposit(address _src, uint256 _amt) externalPerforms accounting when an asset is deposited. Called when the lender deposits.
Can be called only by the Router.
Parameters
_src
address
The lender address.
_amt
uint256
The amount of _asset deposited.
supplyCollateral
function supplyCollateral(address _asset, uint256 _amt) externalPerforms accounting when the borrower supplies collateral.
Can be called only by the Router.
Parameters
_asset
address
The address of the asset deposited.
_amt
uint256
The amount of _asset deposited.
borrow
function borrow(address _lentAsset, uint256 _amt) externalPerforms accounting and transfers on borrow. Called when the borrower borrows.
Can be called only by the Router.
Parameters
_lentAsset
address
The address of lentAsset supplied for efficiency.
_amt
uint256
The amount of lentAsset to borrow.
repay
function repay(uint256 _amt) externalPerforms accounting and transfers back collateral on repay. Called when the borrower repays their loan.
Can be called only by the Router.
Parameters
_amt
uint256
The amount of lentAsset to repay.
redeem
function redeem(address _src) externalPerforms 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
_src
address
The address of the lender.
_default
function _default(address _src) externalPerforms 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
_src
address
The address of the lender.
withdrawLeftovers
function withdrawLeftovers(uint256 _amt) externalPerforms accounting when the borrower withdraws redundant rewards.
Can be called only by the Router.
Parameters
_amt
uint256
The amount of rewards to withdraw.
_transfer
function _transfer(address _asset, address _dst, uint256 _amt) privateTransfers an ERC20 token from the pool.
Uses the OpenZeppelin's SafeERC20 library.
Parameters
_asset
address
The address of the token to transfer.
_dst
address
The recipient of the transfer.
_amt
uint256
The amount to transfer.
getCollateralAssets
function getCollateralAssets() external view returns (address[])Retrieves the array of collateral assets.
Used for off-chain data retrieval.
Return Values
[0]
address[]
collateralAssets as a memory array.
Last updated