Vault Operations Guide

1. System Overview

This backend system is composed of two main components:

  • Data Service Backend: This component is responsible for providing data to the frontend, including Vault information, APY (Annual Percentage Yield) data, user portfolio data, and generating PTB for deposit and withdrawal operations. It ensures that the frontend is decoupled from business logic, allowing the frontend to request data without directly interacting with complex backend operations.

  • Chain Operations Task System: This component focuses on task scheduling, data calculations, API monitoring, Vault monitoring, and chain-level operations such as portfolio rebalancing, deposit/withdrawal executions, and yield optimization. It ensures the smooth execution of real-time chain operations.

Both systems work collaboratively to maintain high-speed data access, operational accuracy, and efficient task management.


2. System Architecture

2.1 Data Service Backend

  • Vault Data: Provides real-time information about Vaults, enabling frontend to display users' holdings and asset statuses.

  • APY Data: Calculates and provides the latest APY for each Vault, offering users insights into yield trends.

  • User Portfolio Data: Displays user positions across Vaults, showing asset shares in each Vault.

  • PTB Generation: Whenever a user initiates a deposit or withdrawal, PTB is generated, encapsulating the request to the frontend. This design decouples frontend operations from business logic.

2.2 Chain Operations Task System

  • Task Scheduling and Management: The task system includes various periodic tasks that handle chain operations, data calculations, portfolio monitoring, and yield generation. It ensures that tasks are executed efficiently and within the necessary time frames.

  • Task Classification:

    • Operational Tasks: Handle deposit and withdrawal actions, reward claims, and funds management.

    • Health Monitoring Tasks: Monitor Vault health, including actions like portfolio rebalancing to maintain healthy lending ratios.

    • Calculation Tasks: Handle APY calculations, user yield updates, and daily financial reconciliations.


3. Task Scheduling

The task scheduling system is central to the operation of the backend, ensuring that tasks run at the correct intervals. Below is a summary of key tasks categorized by function:

3.1 Deposit and Withdrawal Event Monitoring

  • Deposit Events:

    • DepositRequestedWatcher: Listens for new deposit requests on the blockchain and records the events in the local database.

    • DepositCancelledWatcher: Tracks deposit cancellations and updates the status of corresponding records in the local database.

    • DepositExecutedWatcher: Monitors completed deposits and updates the records with execution details (e.g., shares, execution time).

  • Withdrawal Events:

    • WithdrawRequestedWatcher: Monitors withdrawal requests on the blockchain and synchronizes them with the local database.

    • WithdrawCancelledWatcher: Tracks cancellation of withdrawal requests and updates the status in the local database.

    • WithdrawExecutedWatcher: Listens for completed withdrawals and updates the local database with relevant details.

These tasks ensure that deposit and withdrawal events are consistently and accurately synchronized with the local database, providing real-time data for downstream processes.

3.2 Operational Tasks (Chain-level Operations)

These tasks directly interact with chain-level operations, such as deposits, withdrawals, reward claims, and portfolio management.

  • Rebalancing:

    • Rebalancer: For lending strategies, this task monitors the health factor of Vaults. When the health factor falls below or rises above predefined thresholds, the system triggers rebalancing to ensure optimal lending ratios. For DEX strategies, it monitors liquidity within specified price ranges and adjusts the positions to keep liquidity within the desired boundaries, ensuring efficient trading and minimizing slippage.

  • Reward Claims:

    • ClaimResupply: This task is responsible for claiming rewards from various sources (e.g., yield farming or staking rewards) and reinvesting them every hour. The goal is to continuously compound the rewards to maximize overall yield.

  • MonitorFunds:

    • MonitorFunds: This task tracks the movement of large deposits into the Vault. When significant funds are detected, it ensures that these funds are immediately allocated to the appropriate strategies to maximize returns.

  • Daily Financial Reconciliation:

    • DailyFundClearing: This task performs a daily reconciliation of Vault funds, processing any withdrawal requests from users and adjusting the Vault's strategy as needed. It ensures that any requested withdrawals are handled before rebalancing the remaining funds in the Vault.

These tasks ensure seamless operation by handling real-time adjustments, reward management, and daily financial operations, all crucial for maintaining Vault health and optimizing yield.

3.3 Health Monitoring Tasks (Vault and Portfolio Health)

These tasks monitor Vaults and ensure that health factors are maintained within acceptable ranges:

  • Vault Monitoring:

    • VaultMonitorTask: Monitors Vault statuses and health metrics to ensure their smooth operation.

  • Funds Monitoring:

    • MonitorGas: Ensures that sufficient gas is available for transactions to proceed smoothly.

3.3 Calculation Tasks (Data Computation and Updates)

These tasks handle various computations and updates related to user yields, APY, and financial settlements:

  • APY Calculation:

    • ApyCal: Calculates and updates the APY for Vaults daily.

  • User Yield Calculation:

    • UserHourlyYieldWriter: Calculates and updates user yield every hour.

    • UserDailyYieldWriter: Updates user yields.

    • UserTotalYieldWriter: Updates the total user yield data.


4. Vault Types and Strategies

The system supports multiple Vault strategies, each tailored for specific DeFi scenarios, such as lending and DEX.

These Vaults focus on lending strategies involving Bitcoin-based assets.

  • xBTC Vault: A lending strategy Vault using xBTC to facilitate lending and borrowing of Bitcoin-based assets.

  • wBTC Vault: A Vault based on wBTC for lending purposes.

  • Rebalancing: The Rebalancer task monitors price movements and adjusts positions when necessary, ensuring optimal lending ratios and maintaining a healthy portfolio.

4.2 DEX Vaults (e.g., MMT Stable Vault)

These Vaults are designed for stablecoin and other asset strategies.

  • MMT Stable Vault: A Vault designed for stablecoin trading.

  • Rebalancing & Liquidity Management: Through tasks like Rebalancer and MonitorFunds, the system ensures liquidity is allocated efficiently, preventing funds from sitting idle.


5. Data Access and Security

5.1 Data Access Architecture

The system combines chain data and backend database data to ensure accurate and fast data retrieval:

  • Chain Data: Real-time chain data is fetched using RPC calls, especially for deposit/withdrawal actions, reward distribution, and other important events.

  • Backend Data: Backend databases store user data, Vault states, APY records, and other essential information for consistency and persistence.

5.2 Security Measures

To ensure the safety and privacy of sensitive information, the following security practices are implemented:

  1. Mnemonic Encryption: AWS KMS is used to securely encrypt mnemonic phrases, ensuring that sensitive data is protected.

  2. Code-level Protection: An ESLint check is used to prevent any attempt to log mnemonic phrases or sensitive data, ensuring that sensitive information is never exposed during development or deployment.

  3. Real-time Monitoring and Alerts: Critical tasks and metrics, such as gas availability, transaction failures, and APY data accuracy, are continuously monitored. Alerts are triggered in case of anomalies to enable quick response and mitigation.


6. Risk Management and Mitigation Strategies

The system has implemented several measures to manage and mitigate risks:

  • Decoupled Task Design: Tasks are designed to be independent, so failures in one task (e.g., deposit or withdrawal processing) do not impact other tasks.

  • Real-time Monitoring and Alerts: Critical tasks and metrics, such as gas availability, transaction success rates, and APY data, are monitored in real time. Alerts are triggered when abnormal behaviors are detected.

  • Chain Data Synchronization: The backend uses real-time chain data to ensure operations are based on the most up-to-date information, preventing any discrepancies between backend state and chain state. This guarantees that chain operations, such as deposits, withdrawals, and rebalancing, are always accurate.

  • Health Factor Monitoring: For lending-related Vaults, the system continuously checks and adjusts the health factor using tasks like Rebalancer, ensuring that the lending ratios remain within safe limits.

By maintaining real-time monitoring, leveraging chain-level data for operational accuracy, and employing automated recovery strategies, the system effectively mitigates risks and ensures seamless user experience and system reliability.

Last updated