Router

The Router contract is an entry point for interacting with the LombardFi system, with much of the verification logic done in the contract to compress the size of the Pool contract.

Overview

The Router contract is an entry point for interacting with the LombardFi system. It is a pausable, ownable, and reentrancy-guarded contract that implements the IRouter interface. It uses the SafeERC20 library and imports several other contracts, including the Ownable, Pausable, and ReentrancyGuard contracts from the openzeppelin library. The Router contract has methods for setting the addresses of the PoolFactory, OracleManager, and treasury, as well as methods for pausing and unpausing the contract. It also has methods for creating pools, adding collateral to pools, and redeeming collateral from pools.

Deposit

The deposit function allows users to deposit funds into a pool. The function takes in the pool address, the amount to deposit, and the ERC20 token to deposit as parameters. The function first checks that the contract is not paused and that the pool address and token address are not the zero address. The function then uses the SafeERC20 contract to transfer the specified amount of the specified token to the pool.

Borrow

The borrow function allows users to borrow funds from a pool. The function takes in the pool address, the amount to borrow, and the ERC20 token to borrow as parameters. The function first checks that the contract is not paused and that the pool address and token address are not the zero address. The function then calls the borrow function on the specified pool contract, passing in the amount and token to borrow.

Repay

The repay function allows users to repay a loan from a pool. The function takes in the pool address, the amount to repay, and the ERC20 token to repay with as parameters. The function first checks that the contract is not paused and that the pool address and token address are not the zero address. The function then calls the repay function on the specified pool contract, passing in the amount and token to repay with.

Redeem

The redeem function allows a user to redeem their assets from a pool in the LombardFi system. It requires the caller to provide the ID of the pool they want to redeem from, the amount they want to redeem, and the amount of fees they want to pay. The function verifies that the caller is a member of the specified pool, and that the amount they want to redeem is not greater than their share of the pool's assets. If the verification is successful, the function calls the redeem function of the pool contract and transfers the redeemed assets to the caller.

Withdraw leftovers

The withdrawLeftovers function allows a user to withdraw any assets that remain in a pool after all other members have redeemed their shares. It requires the caller to provide the ID of the pool they want to withdraw from. The function verifies that the caller is the owner of the pool, and that the pool is not currently paused. If the verification is successful, the function calls the withdrawLeftovers function of the pool contract and transfers the remaining assets to the caller.

Helper functions

  • _getPool is a helper function that retrieves the pool contract instance associated with a given pool ID. This is used internally by other functions to access the functions and variables of the pool contract.

  • _verifyCallerIsNotBorrower is a helper function that checks if the caller is the borrower of a given pool. This is used to ensure that the caller is not the borrower before allowing them to execute certain functions.

  • _assetsAreValidPoolCollateral is a helper function that checks if the assets being added to a pool as collateral are valid. This is used to ensure that only valid assets are added as collateral to a pool.

  • getBorrowingPower is a helper function that calculates the borrowing power of a given pool. This is used to determine the maximum amount that can be borrowed from the pool.

Last updated