Velvet-Capital / Velvet-v4

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

Modular Flash Loan and Borrow Integration #41

Open Havoc19 opened 1 month ago

Havoc19 commented 1 month ago

The current architecture of the BorrowManager contract integrates flash loan protocols like Algebra, but it tightly couples the flash loan initiation and callback logic within the same contract. This design limits flexibility when integrating additional flash loan protocols or operating across different chains, as each protocol has its own specific callback function requirements.

Problem:

Tight Coupling: The BorrowManager directly handles both the initiation and callback logic for flash loans, making it difficult to integrate new protocols without modifying the core contract.

Protocol-Specific Callbacks: Each flash loan protocol requires a specific callback function, which complicates the integration of multiple protocols.

Limited Modularity: The current design does not easily support adding, removing, or updating flash loan protocols without altering the core contract logic.

Havoc19 commented 1 month ago

For the solution, I tried to shift the flashLoan part in handler, but still it didn't resolve the issue becasue

  1. If handler is calling the flashLoan then fallback function(which protocol pool contract call) , should have pullFromVault which is not safe

  2. If borrowManager contract delegate calls the flashLoan handler, then borrowManager contract should have fallback function(this is our current approach), in this we need to change it for each protocol