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 of the borrower.
whitelistedLender
Address of the whitelisted lender.
Zero address if the pool is open to everyone.
lentAsset
The ERC20 token that lenders deposit and the borrower borrows.
collateralAssets
The ERC20 tokens that can be used as collateral.
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
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
The timestamp at which the Pool matures. Lenders can withdraw their deposits after maturity.
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
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
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
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
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
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
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
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
Stores a lender's notional (total deposited amount), used to calculate rewards.
collateralReserves
Collateral amounts supplied by the borrower.
router
Address of the Router contract.
onlyRouter
Verify that the caller is the router.
Throws an error otherwise.
constructor
initialize
Initialize the pool variables.
Called by the Router when the clone is created.
Parameters
deposit
Performs accounting when an asset is deposited. Called when the lender deposits.
Can be called only by the Router.
Parameters
supplyCollateral
Performs accounting when the borrower supplies collateral.
Can be called only by the Router.
Parameters
borrow
Performs accounting and transfers on borrow. Called when the borrower borrows.
Can be called only by the Router.
Parameters
repay
Performs accounting and transfers back collateral on repay. Called when the borrower repays their loan.
Can be called only by the Router.
Parameters
redeem
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
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
Performs accounting when the borrower withdraws redundant rewards.
Can be called only by the Router.
Parameters
_transfer
Transfers an ERC20 token from the pool.
Uses the OpenZeppelin's SafeERC20 library.
Parameters
getCollateralAssets
Retrieves the array of collateral assets.
Used for off-chain data retrieval.
Return Values
Last updated