flashLoan gas test

This commit is contained in:
tim
2025-10-07 15:57:04 -04:00
parent 457385e692
commit 12957aaa51
3 changed files with 8 additions and 17 deletions

View File

@@ -34,10 +34,6 @@ contract FlashBorrower is IERC3156FlashBorrower {
payer = _payer;
}
function flash(address token, uint256 amount) external {
PartyPool(pool).flashLoan(IERC3156FlashBorrower(address(this)), token, amount, "");
}
function onFlashLoan(
address /*initiator*/,
address token,
@@ -416,7 +412,7 @@ contract GasTest is Test {
// Execute flash loan 10 times to measure gas
for (uint256 i = 0; i < 10; i++) {
borrower.flash(token, amount);
pool2.flashLoan(borrower, token, amount, "");
}
}
}

View File

@@ -37,10 +37,6 @@ contract FlashBorrower is IERC3156FlashBorrower {
payer = _payer;
}
function flash(address token, uint256 amount) external {
PartyPool(pool).flashLoan(IERC3156FlashBorrower(address(this)), token, amount, "");
}
function onFlashLoan(
address /*initiator*/,
address token,
@@ -850,7 +846,7 @@ contract PartyPoolTest is Test {
uint256 poolToken0Before = token0.balanceOf(address(pool));
// Execute flash loan
borrower.flash(address(token0), amount);
pool.flashLoan(borrower, address(token0), amount, "");
// Net change for alice should equal the flash fee (principal is returned during repayment)
uint256 fee = (amount * pool.flashFeePpm() + 1_000_000 - 1) / 1_000_000; // ceil fee calculation
@@ -882,7 +878,7 @@ contract PartyPoolTest is Test {
// Execute flash loan - should revert due to insufficient allowance when pool tries to pull repayment
vm.expectRevert();
borrower.flash(address(token0), amount);
pool.flashLoan(borrower, address(token0), amount, "");
}
/// @notice Test flash loan with partial repayment (should revert)
@@ -897,7 +893,7 @@ contract PartyPoolTest is Test {
// Execute flash loan - should revert due to insufficient allowance when pool tries to pull full repayment
vm.expectRevert();
borrower.flash(address(token0), amount);
pool.flashLoan(borrower, address(token0), amount, "");
}
/// @notice Test flash loan with principal repayment but no fee (should revert)
@@ -913,10 +909,10 @@ contract PartyPoolTest is Test {
// Execute flash loan - should revert due to insufficient allowance if fee > 0
if (pool.flashFeePpm() > 0) {
vm.expectRevert();
borrower.flash(address(token0), amount);
pool.flashLoan(borrower, address(token0), amount, "");
} else {
// If fee is zero, this should succeed
borrower.flash(address(token0), amount);
pool.flashLoan(borrower, address(token0), amount, "");
}
}
@@ -935,7 +931,7 @@ contract PartyPoolTest is Test {
uint256 poolToken0Before = token0.balanceOf(address(pool));
// Execute flash loan
borrower.flash(address(token0), amount);
pool.flashLoan(borrower, address(token0), amount, "");
// Check balances: net change for alice should equal the fee
uint256 fee = (amount * pool.flashFeePpm() + 1_000_000 - 1) / 1_000_000; // ceil fee calculation