PoolFactory.sol
PoolFactory
The PoolFactory deploys Pool with the help of OpenZeppelin Clones. Each pool is a representation of an immutable pool implementation.
router
Address of Router contract.
pid
The number of created pools.
maxNumberOfCollateralAssets
Maximum unique collateral assets per pool.
Can be set by the owner in setMaxNumberOfCollateralAssets
.
originationFee
Origination fee in WAD (1e18 = 100%)
Denominated in WAD. A value of 0.01e18 means the origination fee is 1%. Supplied to pool clones by copying this variable, not by the deployer. Can be set by the owner in setOriginationFee
.
pidToPoolAddress
Maps pool id to its address.
MAX_ORIGINATION_FEE
Maximum configurable origination fee.
Set to 10%.
poolImplementation
Address of the pool implementation contract.
_This implementation is cloned when a new pool is deployed in createPool
.
Set in the constructor. See Pool
._
constructor
createPool
Deploys a new pool. Parameters must pass certain sanity checks.
Uses OpenZeppelin Clones to clone the pool implementation. Throws if the supplied parameters are invalid. See Pool
for detailed descriptions of the parameters.
Parameters
Name | Type | Description |
---|---|---|
_lentAsset | address | The ERC20 token that lenders deposit and the borrower borrows. |
_collateralAssets | address[] | The ERC20 tokens that can be used as collateral by the borrower. |
_coupon | uint96 | The yield for the duration of the term in WAD. |
_ltv | uint96 | The loan-to-value ratio in WAD that must be achieved when borrowing. |
_activeAt | uint32 | The timestamp after which deposits close and borrowers can borrow the deposits. |
_maturesAt | uint32 | The timestamp after which lenders can withdraw their deposits with yield. |
_minSupply | uint256 | The minimum supplied lent asset to activate the pool. |
_maxSupply | uint256 | The deposit cap of the pool. |
_whitelistedLender | address | The whitelisted lender for the pool. 0 address if the pool is public. |
Return Values
Name | Type | Description |
---|---|---|
pool | address | The address of the deployed pool. |
setMaxNumberOfCollateralAssets
Sets the maximum number of collateral assets allowed in a pool. Must be greater than 0.
Can be called only by the owner.
Parameters
Name | Type | Description |
---|---|---|
_maxNumberOfCollateralAssets | uint256 | The new maximum number of collateral assets. |
setOriginationFee
Sets the origination fee. Cannot be greater than the maximum.
Can be called only by the owner.
Parameters
Name | Type | Description |
---|---|---|
_originationFee | uint96 | The new origination fee in WAD. |
getAllPools
Retrieves all pools.
Used for off-chain data retrieval. May run out of gas if pid
is too large. Use getAllPoolsSlice
in that case.
Return Values
Name | Type | Description |
---|---|---|
[0] | address[] | an array of pool addresses. |
getAllPoolsSlice
Retrieves a slice of pools.
Used for off-chain data retrieval.
Parameters
Name | Type | Description |
---|---|---|
_from | uint256 | The starting pool id (inclusive). |
_to | uint256 | The ending pool id (exclusive). |
Return Values
Name | Type | Description |
---|---|---|
[0] | address[] | an array of pool addresses. |
_assetsAreValid
Verifies that pool assets are valid. They must be unique, nonzero and have 18 or less decimals.
The decimal check also checks (loosely) that the assets conform to the ERC20 standard. May throw if the address does not have a decimals function.
Parameters
Name | Type | Description |
---|---|---|
_collateralAssets | address[] | An array of ERC20 token addresses to be used as collateral. |
_lentAsset | address | The address of the ERC20 token which is lent. |
Return Values
Name | Type | Description |
---|---|---|
[0] | bool | true if the assets are valid or false if the checks fail. |
_executeTransferFromWithBalanceChecks
Private function that transfers specific amount of _asset
and performs checks before and after the execution of the transfer.
Parameters
Name | Type | Description |
---|---|---|
_asset | contract IERC20 | The address of the token transfer. |
_from | address | The address of the sender. |
_to | address | The address of the recipient. |
_amt | uint256 | The amount to be transferred. |
Return Values
Name | Type | Description |
---|---|---|
[0] | uint256 | uint256 The value extracted from the difference between pre and post transfer. |
Last updated