feat(lending): add flash loan liquidation to LendingPool#5138
Open
KHHH2312 wants to merge 2 commits into
Open
Conversation
There was a problem hiding this comment.
Pull request overview
Note
Copilot was unable to run its full agentic suite in this review.
Adds a flash liquidation feature to the LendingPool contract, along with mock contracts and tests to validate the behavior.
Changes:
- Introduces
flashLiquidatefunction andIFlashLiquidatorinterface inLendingPool.sol, plus atotalFeesCollectedaccumulator. - Adds mock contracts (
MockToken,MockOracle,MockFlashLiquidator) to support testing. - Adds a new test suite covering healthy/unhealthy liquidations, failure paths, and fee accounting.
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 5 comments.
| File | Description |
|---|---|
| contracts/lending/LendingPool.sol | Adds the flash liquidation entry point, fee accounting, and a new liquidator callback interface. |
| contracts/mocks/LendingMocks.sol | Provides mock ERC20, oracle, and flash liquidator implementations for tests. |
| test/LendingPool.test.js | Adds tests covering flash liquidation success, revert paths, and fee collection. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Comment on lines
+4
to
+17
| /* | ||
| Contributor: Antigravity | ||
| Initialization Text: | ||
| You are Antigravity, a powerful agentic AI coding assistant designed by the Google DeepMind team working on Advanced Agentic Coding. | ||
| You are pair programming with a USER to solve their coding task. The task may require creating a new codebase, modifying or debugging an existing codebase, or simply answering a question. | ||
| The USER will send you requests, which you must always prioritize addressing. User requests are enclosed within <USER_REQUEST> tags. Along with each USER request, we will attach additional metadata about their current state, such as what files they have open and where their cursor is. | ||
| This information may or may not be relevant to the coding task, it is up for you to decide. | ||
|
|
||
| Runtime Environment: | ||
| OS: windows | ||
| Arch: x64 | ||
| Working Directory: C:\Users\Khalid\Desktop\OpenAgents | ||
| Shell: powershell | ||
| */ |
Comment on lines
+137
to
+151
| require(collateralToken.transfer(msg.sender, collateral), "Transfer failed"); | ||
|
|
||
| require( | ||
| IFlashLiquidator(msg.sender).executeOperation( | ||
| address(collateralToken), | ||
| address(borrowToken), | ||
| debt, | ||
| collateral, | ||
| fee, | ||
| params | ||
| ), | ||
| "Flash loan execution failed" | ||
| ); | ||
|
|
||
| require(borrowToken.transferFrom(msg.sender, address(this), debt + fee), "Transfer failed"); |
| uint256 debt = pos.borrowedAmount; | ||
| uint256 collateral = pos.collateralAmount; | ||
|
|
||
| uint256 fee = (debt * 9) / 10000; // 0.09% fee |
Comment on lines
+41
to
+48
| function executeOperation( | ||
| address collateralToken, | ||
| address _borrowToken, | ||
| uint256 debt, | ||
| uint256 collateral, | ||
| uint256 fee, | ||
| bytes calldata params | ||
| ) external returns (bool) { |
Comment on lines
+61
to
+64
| const fee = (debt * 9n) / 10000n; // 0.09% fee | ||
|
|
||
| // Before liquidation | ||
| const liquidatorCollateralBalanceBefore = await collateralToken.balanceOf(await liquidator.getAddress()); |
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.
Description
Implements flash liquidation functionality inside
LendingPool.solallowing liquidators to liquidate underwater positions without upfront capital.IFlashLiquidatorinterface.flashLiquidatefunction that optimistcally transfers collateral, calls the liquidator's callback, and retrieves the required debt + 0.09% fee in a single atomic transaction.totalFeesCollectedin the pool.LendingPool.test.jssimulating profitable liquidations, failures (reverts), and exact fee math checks.Closes #160
?? Payment Details:
Method: USDC
Address: 0x43991A9dC8Ddf492eab6E55685644c2cb9B001D2
Network: Base