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 router

Address of Router contract.

pid

uint256 pid

The number of created pools.

maxNumberOfCollateralAssets

uint256 maxNumberOfCollateralAssets

Maximum unique collateral assets per pool.

Can be set by the owner in setMaxNumberOfCollateralAssets.

originationFee

uint96 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

mapping(uint256 => address) pidToPoolAddress

Maps pool id to its address.

MAX_ORIGINATION_FEE

uint96 MAX_ORIGINATION_FEE

Maximum configurable origination fee.

Set to 10%.

poolImplementation

address 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

constructor(address _router) public

createPool

function createPool(address _lentAsset, address[] _collateralAssets, uint96 _coupon, uint96 _ltv, uint32 _activeAt, uint32 _maturesAt, uint256 _minSupply, uint256 _maxSupply, address _whitelistedLender) external returns (address pool)

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

NameTypeDescription

_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

NameTypeDescription

pool

address

The address of the deployed pool.

setMaxNumberOfCollateralAssets

function setMaxNumberOfCollateralAssets(uint256 _maxNumberOfCollateralAssets) external

Sets the maximum number of collateral assets allowed in a pool. Must be greater than 0.

Can be called only by the owner.

Parameters

NameTypeDescription

_maxNumberOfCollateralAssets

uint256

The new maximum number of collateral assets.

setOriginationFee

function setOriginationFee(uint96 _originationFee) external

Sets the origination fee. Cannot be greater than the maximum.

Can be called only by the owner.

Parameters

NameTypeDescription

_originationFee

uint96

The new origination fee in WAD.

getAllPools

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

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

NameTypeDescription

[0]

address[]

an array of pool addresses.

getAllPoolsSlice

function getAllPoolsSlice(uint256 _from, uint256 _to) external view returns (address[])

Retrieves a slice of pools.

Used for off-chain data retrieval.

Parameters

NameTypeDescription

_from

uint256

The starting pool id (inclusive).

_to

uint256

The ending pool id (exclusive).

Return Values

NameTypeDescription

[0]

address[]

an array of pool addresses.

_assetsAreValid

function _assetsAreValid(address[] _collateralAssets, address _lentAsset) private view returns (bool)

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

NameTypeDescription

_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

NameTypeDescription

[0]

bool

true if the assets are valid or false if the checks fail.

_executeTransferFromWithBalanceChecks

function _executeTransferFromWithBalanceChecks(contract IERC20 _asset, address _from, address _to, uint256 _amt) private returns (uint256)

Private function that transfers specific amount of _asset and performs checks before and after the execution of the transfer.

Parameters

NameTypeDescription

_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

NameTypeDescription

[0]

uint256

uint256 The value extracted from the difference between pre and post transfer.

Last updated