Lending and Borrowing Operations
In this section, we undertake a comprehensive description of lending and borrowing processes. We will elaborate on the stages that are involved in these operations. Ranging from the fundamental lending pool contributions to the multifaceted borrowing phases, collateral management, and the intricate mechanisms underpinning liquidation and effective protection of the Weft solvency.
Interest Rate and Interest Accrual
Weft dynamically calculates interest rates based on pool usage using a defined interest strategy. As a reminder, an interest strategy is a function that takes pool state as input and gives interest rate as output. Users benefit from real-time interest rate updates on each user operation with a 1-minute debounce time, ensuring an immediate reflection of market dynamics in their lending or borrowing decisions.
Lending
Operations on the lending side are straightforward, involving contributing to the lending pool and receiving deposit units in return. The redemption process mirrors the contribution, with users initiating a redemption action by providing deposit units they wish to redeem and obtaining the corresponding assets in return.
Borrowing
On the borrowing side, Weft operates primarily through three phases: Validation Phase: The Lending Market validates the presented Wefty. Once validated, an extended version is generated by copying ledger data from the lending pools corresponding to the assets within the Wefty positions. This extended Wefty incorporates all the essential methods required for interactions with lending pools.
- User Order Execution Phase: The Lending Market maps the user’s method call to the relevant extended Wefty methods. Depending on the user’s method, multiple internal method calls may be triggered.
- Health Check and Wefty Update Phase: After the execution phase, the Lending Market component evaluates the health of the resultant Wefty. This assessment mainly involves verifying whether all existing loans maintain adequate over-collateralization.
- Loan state update
Loan state update
With the concepts of deposit and loan units, we can easily accrue interest to the pool by increasing the total borrowed amount by the appropriate amount based on the interest rate. This is the critical feature that allows us to use non-fungible resources to store deposit and loan data efficiently.
Again, Units are fixed and stay relevant until the next operation from their owners, so they can be stored on the ledger and updated only on each operation initiated by the user. At the same time, we can keep the pool state up to date by performing accrued interest updates on any operation from any user or from another component that supports the lending pool operations. To accommodate multiple interest rate options, the lending pool state data structure is set up as a sub-pool categorized by interest options with its loan units and total loans borrowed.
Borrowing power delegation
A delegated Wefty represents a specialized form of Wefty allowing users to delegate their borrowing power to others. A user with a Wefty can mint a linked delegated Wefty and send it to another user. The recipient can then utilize the delegated Wefty to borrow from Weft without the need for collateral provided by himself. Instead, the required collaterals will be counted from the delegator Wefty.
To make this feature possible in a scalable way, loan positions from delegated Wefties are consolidated during each operation into specific loan positions and stored within the delegator’s Wefty under the label “delegated_loan.” During each operation, the extended Wefty will access collateral positions, loan positions, and delegated loan positions from the delegator. A health check is performed on this combination, and if it fails, the transaction is rejected.
Delegated Wefties can be minted with delegation limits. The primary limit is a borrowing power cap, which specifies the maximum value of assets a delegated Wefty can borrow in the base currency of the lending market. Another limit is the maximum loan-to-value ratio, capping the contribution of the delegated Wefty to a fixed amount relative to the delegator’s total loan-to-value ratio. These limits empower users to manage their exposure and liability in the event of default or liquidation of their delegates.
User positions operations
Beyond lending and borrowing, Weft extends swap functionality to its users. This feature enables users to modify the asset serving as collateral or adjust the borrowed asset without repaying the debt. Another offered capability is the option to directly repay a loan using the corresponding collateral, known as self-liquidation. As these operations are closely tied to loans and collateral, they adhere to the same steps outlined in the borrowing operations section.
Although this functionality could have been realized using the Radix transaction manifest and flash loans offered by lending pools, we’ve chosen to incorporate it as a native feature for convenience due to its expected widespread use.
Liquidations
On Weft, loans can be liquidated if the loan-to-value ratio surpasses a predefined liquidation threshold. That means the market component will sell loan collateral on the open market to repay the loan if the Wefty is in an unhealthy loan state.
Loan-to-Value (LTV) Ratio & Threshold: The LTV ratio represents the size of the loan relative to the value of the collateral. If this ratio exceeds a predefined threshold, the Wefty becomes unhealthy and a liquidation can be triggered. This threshold ensures a buffer between the loan amount and the collateral's value to protect the interests of lenders. As loans can be backed by multiple assets, the LTV of a Wefty is given by an average of the LTV of each loan position against available collaterals, weighted by each loan position size.
External Liquidation: External entities (liquidators) monitor the LTV ratios of Wefties. If they identify a Wefty in an unhealthy state, (i.e., the LTV surpasses the threshold), they can choose a position present in the Wefty and repay the debt on behalf of the borrower. In return, they can choose any of the borrower's collateral and redeem it for the underlying asset. As an incentive, they receive a bonus on top of the redeemed collateral. This bonus ensures that there's an active community willing to step in and safeguard the platform.
Internal Liquidation: The platform identifies Wefties that are unhealthy or at high risk. Then sells the borrower's collateral on the open market to recoup the loan amount. The proceeds from the sale are used to repay the debt and continue on each loan position until enough funds have been generated to bring the Wefty back to a healthy LTV ratio.
Role of External Components
For its operations, Weft needs integration with two critical external key components: a Price oracle and a DEX aggregator. Price Oracle: Real-time and accurate asset prices are crucial to determine the LTV ratio. A price oracle provides this data, ensuring that the platform has up-to-date values to base its decisions on. Decentralized Exchange (DEX) Aggregator: When assets are liquidated, especially during internal liquidation, they need to be sold quickly and efficiently. A DEX aggregator allows the platform to find the best prices across multiple exchanges, ensuring maximum returns from the sale.