Velvet-Capital / Velvet-v4

V4 (thena+venus) on top of v3
Other
0 stars 0 forks source link

Venus integration #10

Closed Havoc19 closed 2 months ago

Havoc19 commented 2 months ago

Rebalancing Contract -

repay Function:

borrow Function:

Key Players:

BorrowManager Contract -

The BorrowManager contract is responsible for managing the borrowing and repayment processes within a DeFi protocol. Here’s a simple breakdown:

  1. Repayment Handling:

    • The repayDeposit function handles the repayment of borrowed tokens when a user withdraws from the portfolio. It calculates the amount owed based on the user's share of the total supply and uses flash loans to repay the debt.
    • The repayVault function is specifically designed to repay the entire debt of the vault. It initiates a flash loan from a specified pool, uses the borrowed amount to repay the debt, and handles token swaps as needed.
  2. Flash Loan Callback:

    • The algebraFlashCallback function is a special callback that gets triggered after receiving a flash loan. It handles the actual repayment of the debt, performs necessary token swaps, and ensures that the flash loan is repaid with the required fees.
  3. Flash Loan and Debt Management:

    • The contract uses Algebra pools for flash loans, which are short-term loans that must be repaid within the same transaction. It encodes all necessary data for the flash loan process, including which tokens to borrow and repay, how much to borrow, and any associated swaps.

Key Functions:

Key Components:

Portfolio Contract -

_borrowManager.repayDeposit(
  _portfolioTokenAmount,
  totalSupplyPortfolio,
  repayData
);

Here, it first repays the borrowed tokens based on user's share, and then rest of the process of withdrawal goes on