Velvet-Capital / Velvet-v4

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

Borrow fixes #54

Closed Havoc19 closed 7 hours ago

Havoc19 commented 1 day ago

1. Borrowed Token Length Tracking


#### Mechanism
1. Before borrowing, we capture the initial length of borrowed tokens:
   ```solidity
   uint256 borrowedLengthBefore = (
     assetHandler.getBorrowedTokens(_vault, _controller)
   ).length;
  1. After borrowing, we capture the new length:

    uint256 borrowedLengthAfter = (
     assetHandler.getBorrowedTokens(_vault, _controller)
    ).length;
  2. We increment tokensBorrowed only if a new token type was borrowed:

    if (borrowedLengthAfter > borrowedLengthBefore) {
     tokensBorrowed++;
    }

Why This Approach?

Example Scenario

Safeguards

2. Flash Loan Safety Mechanism

#### Mechanism
1. Flag Initialization:
   ```solidity
   bool _isFlashLoanActive;
  1. Before Flash Loan Initiation:

    // Set flash loan flag to true to allow callback execution
    _isFlashLoanActive = true;
    • Enables callback processing
    • Signals the start of a flash loan operation
  2. Callback Verification:

    function algebraFlashCallback(...) external override {
       // Prevent unauthorized callbacks
       if(!_isFlashLoanActive) revert ErrorLibrary.FlashLoanIsInactive();
    
       // Proceed with callback logic
       // ...
    }

Security Considerations

Potential Attack Vectors Mitigated