Router.sol
Router
The router is the entry point for interacting with the LombardFi system. All of the transfers from user to pool are executed by the router. Much of the verification logic is done in the router to compress the size of the Pool contract.
poolFactory
contract IPoolFactory poolFactory
Address of the PoolFactory.
oracleManager
contract IOracleManager oracleManager
Address of the OracleManager.
treasury
address treasury
Address of the protocol treasury.
Receives the origination fee at pool creation.
nonZero
modifier nonZero(uint256 amt)
Verify that an integer is greater than 0.
Throws an error if the uint256 is equal to 0
Parameters
amt
uint256
The integer to check.
nonZeroAddress
modifier nonZeroAddress(address _address)
Verify that an address is not the zero address.
Throws an error if the address is the zero address.
Parameters
_address
address
The address to check.
setFactory
function setFactory(contract IPoolFactory _poolFactory) external
Set the PoolFactory implementation address.
Callable only by the owner.
Throws an error if the supplied address is the zero address.
Parameters
_poolFactory
contract IPoolFactory
The new implementation.
setOracleManager
function setOracleManager(contract IOracleManager _oracleManager) external
Set the OracleManager implementation address.
Callable only by the owner.
Throws an error if the address is the zero address.
Parameters
_oracleManager
contract IOracleManager
The new implementation.
setTreasury
function setTreasury(address _treasury) external
Set the treasury address. Callable only by the owner.
Throws an error if the address is the zero address.
Parameters
_treasury
address
The new recipient.
pause
function pause() external
Pause the contract. Callable only by the owner.
unpause
function unpause() external
Unpause the contract. Callable only by the owner.
The contract must be paused to unpause it.
deposit
function deposit(uint256 _pid, uint256 _amt) external
Deposit into a pool.
The contract must not be paused. _amt
must be nonzero.
A pool with the _pid
must exist.
Caller must not be the pool's borrower.
Caller must be the whitelisted lender if the pool has one.
Caller must have approved this contract to spend _amt
of the pool's lent asset.
The pool must not be active or mature.
The pool must have sufficient open capacity for _amt
.
Parameters
_pid
uint256
The id of the pool to deposit in.
_amt
uint256
The amount of the pool's lent asset to deposit.
borrow
function borrow(uint256 _pid, address[] _collateralAssets, uint256[] _amts) external
Borrow the available amount of lent asset from a pool. Transfers the pool's lent asset from pool to borrower. Transfers collateral from borrower to pool.
The contract must not be paused.
A pool with the _pid
must exist.
Caller must be the pool's borrower.
Lengths of _collateralAssets
and amts
must match.
_collateralAssets
must be the pool's collateral assets or a subset.
The pool must be active.
The pool's minimum deposit must have been reached.
The loan amount and value of the supplied collateral must satisfy the loan-to-value ratio.
Parameters
_pid
uint256
The id of the pool to borrow from.
_collateralAssets
address[]
The assets to deposit as collateral
_amts
uint256[]
The amounts corresponding to the collaterals
repay
function repay(uint256 _pid, uint256 _amt) external
Repay a part of the loan. Transfers the pool's lent asset from borrower to pool. Transfers collateral from pool to borrower.
A pool with the _pid
must exist. _amt
must be nonzero.
The contract must not be paused.
Pool must be active if the router is under normal operation.
Caller must be the pool's borrower.
The pool must be active.
Parameters
_pid
uint256
The id of the pool to repay in.
_amt
uint256
The amount of the pool's lent asset to repay.
redeem
function redeem(uint256 _pid) external
Redeem notional and yield from a mature pool or redeem notional from an unsuccessful pool. Transfers the pool's lent asset from pool to caller. Transfers collateral from caller to pool.
The contract must not be paused.
A pool with the _pid
must exist.
Caller must not be the pool's borrower.
The pool must be mature or active with less deposits than the minimum.
Caller must have made a deposit.
Caller can redeem only once per pool.
Parameters
_pid
uint256
The id of the pool to redeem from.
withdrawLeftovers
function withdrawLeftovers(uint256 _pid) external
Withdraw redundant yield from a pool. Transfers a part of the upfront for the unrealised size back to the borrower.
The contract must not be paused.
A pool with the _pid
must exist.
Caller must be the pool's borrower.
Borrower can withdraw only once.
The pool must be active.
Parameters
_pid
uint256
The id of the pool to withdraw leftovers from.
getBorrowingPower
function getBorrowingPower(address[] _collateralAssets, uint256[] _amts) public view returns (uint256 _borrowingPower)
Utility function that returns the value of collateral. Prices are fetched from the OracleManager.
Also used for off-chain data retrieval.
Parameters
_collateralAssets
address[]
Array of collateral assets.
_amts
uint256[]
The amounts corresponding to the collateral assets.
Return Values
_borrowingPower
uint256
The total value of the collateral.
_assetsAreValidPoolCollateral
function _assetsAreValidPoolCollateral(contract IPool _pool, address[] _assets) private view returns (bool)
Utility function that checks whether an array of addresses match pool collateral. They must be a subset.
Parameters
_pool
contract IPool
The pool to check the assets against.
_assets
address[]
The array of ERC20 token addresses to check against the pool.
Return Values
[0]
bool
Whether the given assets are valid subset of pool collateral.
_verifyCallerIsNotBorrower
function _verifyCallerIsNotBorrower(contract IPool _pool) private view
Private function that verifies that the caller is not the pool's borrower.
Parameters
_pool
contract IPool
The pool contract.
_getPool
function _getPool(uint256 _pid) private view returns (contract IPool _pool)
Private function that gets a pool address from a pool id.
Throws an error if a pool with the _pid
does not exist.
Parameters
_pid
uint256
The id of the pool to get the address of.
Return Values
_pool
contract IPool
The pool contract.
Last updated