Liquidation
Overview
The LiquidationService is a critical component of the Positions Finance architecture, designed to manage the liquidation of NFT collateral when certain utilization thresholds are exceeded. In the context of decentralized finance (DeFi), NFTs can serve as collateral for loans, and their value can fluctuate based on market conditions.
The LiquidationService ensures that the system can respond to these fluctuations by monitoring the utilization of NFTs and executing liquidations when necessary.
This service interacts closely with the NFTService to fetch relevant NFT data and with the database to retrieve historical event data. By maintaining an accurate and up-to-date view of asset values and utilization, the LiquidationService plays a vital role in protecting the integrity of the collateralization process.
Purpose: The Liquidation package is responsible for managing the liquidation of assets when certain utilization thresholds are exceeded.
Key Responsibilities:
Monitoring Utilization: It continuously monitors the utilization of NFTs as collateral. If the utilization exceeds a predefined threshold, the service triggers a liquidation process.
Calculating Asset Values: The service calculates the total asset value of NFTs by aggregating the values of all deposits and withdrawals associated with them.
Executing Liquidations: When conditions for liquidation are met, it interacts with smart contracts to liquidate the assets, ensuring that the process adheres to the defined rules and protocols.
Interactions:
NFTService: This service interacts with the NFTService to fetch details about NFTs, such as their total supply and specific asset values.
Database: It queries the database for vault and relayer events to determine the current state of assets and their utilization.
Key Methods
initialize:
This method is responsible for setting up the
LiquidationService
by fetching vault and Relayer events from the database. It stores these events in memory for efficient processing during liquidation checks. This initialization step is crucial for ensuring that the service has access to the latest data regarding asset values and utilization.
performLiquidation:
The core method of the
LiquidationService
,performLiquidation
, iterates through all NFTs managed by the system. For each NFT, it calculates the total asset value and checks the current utilization against a predefined threshold. If the utilization exceeds this threshold, the service triggers the liquidation process, ensuring that the assets are liquidated in a timely manner to minimize losses.
getTotalAssetValue:
This method calculates the total asset value for a given NFT by summing the values of all deposit events associated with that NFT. It queries the database for relevant deposit records and aggregates their values, providing a clear picture of the NFT's current worth.
getFulfilledRequests:
The
getFulfilledRequests
method retrieves all fulfilled requests for a specific NFT. This information is essential for calculating utilization, as it provides insight into how much of the NFT's value is currently being utilized as collateral for loans or other financial instruments.
getUtilization:
This method fetches the utilization value from the smart contract for a specific NFT and request ID. It interacts with the blockchain to obtain real-time data on how much of the NFT's value is currently being used, allowing the LiquidationService to make informed decisions about potential liquidations.
liquidateAssets:
This method serves as a placeholder for the actual liquidation logic. When implemented, it will handle the process of liquidating assets, which may involve interacting with smart contracts to execute sales or transfers of the NFT collateral. The specifics of this process will depend on the protocols and mechanisms established for asset liquidation within the Positions Finance ecosystem.
Liquidation Logic
The liquidation process follows a systematic approach to ensure that assets are managed effectively:
Fetch Total Asset Value: For each NFT, the service retrieves the total asset value, which reflects the current worth of the collateral.
Retrieve Fulfilled Requests: The service gathers all fulfilled requests associated with the NFT, which are necessary for understanding how much of the asset's value is currently utilized.
Calculate Utilization: For each fulfilled request, the service calculates the utilization, which indicates the proportion of the NFT's value that is being used as collateral.
Check Against Threshold: If the total utilization exceeds the predefined threshold, the service initiates the liquidation process. This threshold is a critical parameter that helps manage risk and protect the interests of both the platform and its users.
Liquidate Assets: If the conditions for liquidation are met, the service executes the liquidation process, ensuring that the assets are sold or transferred in a manner that minimizes losses and adheres to the established protocols.
Conclusion
The LiquidationService is a vital component of the Positions Finance ecosystem, ensuring that NFT collateral is managed effectively and that liquidations occur in a timely manner when necessary. By monitoring asset values and utilization, the service helps maintain the integrity of the collateralization process, protecting both users and the platform from potential losses due to market fluctuations. Its systematic approach to liquidation ensures that the system remains responsive and resilient in the dynamic landscape of decentralized finance.
Last updated