[Feature] Flash Loan Implementation with 0.05% Fee Model #182
Open
Menjay7 wants to merge 1 commit into
Open
Conversation
Contributor
|
@Menjay7 please work on the Rust CI/build |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Introduce flash loan functionality to the protocol, allowing users to borrow assets without collateral provided the loan and associated fee are repaid within the same transaction. The implementation includes a fixed 0.05% flash loan fee, repayment verification, and safeguards against incomplete or malicious loan execution.
Changes
Add flash loan execution flow to the lending contract
Implement a fixed 0.05% fee model for all flash loans
Add borrower callback interface for custom flash loan strategies
Verify full repayment of principal and fee before transaction completion
Revert the entire transaction if repayment requirements are not met
Add fee accounting and treasury allocation logic
Prevent unsupported assets from being flash-loaned
Emit events for flash loan issuance and repayment
Add custom errors:
FlashLoanUnavailable
FlashLoanAmountExceedsLiquidity
FlashLoanRepaymentInsufficient
FlashLoanCallbackFailed
UnsupportedFlashLoanAsset
Contract Flow
User requests a flash loan.
Contract validates available liquidity.
Loaned assets are transferred to the receiver contract.
Receiver executes custom logic via callback.
Contract verifies repayment of:
Principal amount
0.05% flash loan fee
Fee is distributed according to protocol treasury configuration.
Transaction completes; otherwise, the entire operation reverts.
Testing
Add unit tests for flash loan creation and repayment
Verify correct 0.05% fee calculation across varying loan sizes
Test insufficient repayment scenarios
Test liquidity limit enforcement
Test unsupported asset requests
Test callback execution failures
Add integration tests for:
Arbitrage workflows
Debt refinancing workflows
Multi-operation flash loan transactions
Fee accrual and treasury accounting
Security Considerations
Atomic repayment enforcement
Reentrancy protection during loan execution
Liquidity validation before asset transfer
Callback failure rollback protection
Comprehensive repayment verification before transaction finalization
Motivation
Flash loans enable advanced DeFi use cases such as arbitrage, collateral swaps, refinancing, liquidations, and portfolio rebalancing without requiring upfront capital. The 0.05% fee model provides protocol revenue while maintaining competitive borrowing costs.
Checklist
Added flash loan execution functionality
Implemented 0.05% fee calculation and collection
Added borrower callback interface
Added repayment verification and transaction rollback logic
Added events and custom errors
Added unit and integration tests
Performed security review for flash loan execution flow
Updated documentation and developer guides..closed #172