Deep Dive Into UniLend OMNIS Code
The DeFi is scaling and bringing the exposure of the lending and borrowing industry to Fiats, Synthetic assets, Stocks, NFTs, Metaverse, and Real-World Assets.
UniLend is leading this with the launch of Omnis, a multi-contract DeFi protocol that builds the infrastructure to allow lending and borrowing of any ERC20 asset in a permissionless nature and expanding the horizon of DeFi.
Our dev team lead by CTO Suryansh Kumar have built the protocol over the last 1 year to help developer communities and utilise these contracts to build new opportunities on the UniLend layer.
And with this guide the UniLend team intends to highlight the most crucial aspect of our contracts and how various functions come into play.
Structural View of UniLend Protocol
Before we dive, check the following V2 contracts
Position Contract — https://github.com/UniLend/unilendv2/blob/main/contracts/position.sol
Oracle Contract — https://github.com/UniLend/unilendv2/blob/main/contracts/oracle.sol
Interest Rate Contract — https://github.com/UniLend/unilendv2/blob/main/contracts/interestrate.sol
UniLend protocol has concept of isolated pools of two different assets token0 and token1. The pool is created from the function createPool in Core Contract and requires addresses of both the assets.
Internally the function uses IUniLendV2Pool interface to create a pool from Pool Contract with default parameter values of defaultInterestRate, default_LTV, default_LB, default_RF.
Lend / Redeem
The lend function needs to be called with parameter _pool (pool address), and _amount (int) to start lending of the assets.
The token0 / token1 is selected respectively for +ve and -ve integer value of _amount.
The logic here gets or creates a Non Fungible Position for user and pool association using interface IUnilendV2Position and stores the information of each token’s address, lend balance and borrow balance for the user.
Borrow / Repay
Similar to the lend function the borrow function utilises the Pool Contract to create or update the Non Fungible Position.
The function here requires _collateral_amount (uint) and _recipient (address) in addition to _pool and _amount.
The logic ensures validation of necessary liquidity in the pool to ensure the successful transaction.
To keep the UniLend system active and stable the our protocols rely on a distributed network of liquidators independently to keep the overall protocol healthy.
These independent liquidators can use liquidate or liquidateMulti functions to help the system by repaying loans on behalf of defaulters and earn liquidation bonus.
The flashloan function allows smart contracts to access the liquidity of the pool within one transaction in an uncollateralized borrowing as long as the amount taken plus a fee is returned.
To initiate the flashloan function pass the following parameters
_receiver : The address of the contract receiving the funds. The receiver should implement the IFlashLoanReceiver interface.
_pool: the address of the principal reserve pool
_amount: the amount requested for this flashloan
UniLend V2 Relies on a Dual Asset Lending Pool model to offer risk mitigation and flexible lending options. All loans are backed by collateral and represented by Non-Fungible Tokens, which accrue the interests. Various protocol parameters such as collateralization ratio and interest rate vary for different assets.
The UniLend team invites developers to build upon OMNIS infrastructure and explore the possibilities of an open financial institution. DeFi 2.0 is around the corner and builders have a chance to impact the world.
For any enquiries on code and project proposals for grants reach out to our team at email@example.com.
For the love of code ♥️♥️♥️