Skip to content

Commit

Permalink
Merge pull request #186 from Gearbox-protocol/tests-pool-fix
Browse files Browse the repository at this point in the history
fix: handle >90% utilization in tests
  • Loading branch information
Van0k authored Mar 8, 2024
2 parents d4986bd + 278c6fc commit 0ebe7f5
Showing 1 changed file with 14 additions and 3 deletions.
17 changes: 14 additions & 3 deletions contracts/test/helpers/IntegrationTestHelper.sol
Original file line number Diff line number Diff line change
Expand Up @@ -337,19 +337,30 @@ contract IntegrationTestHelper is TestHelper, BalanceHelper, ConfigManager {
uint256 remainingBorrowable = pool.creditManagerBorrowable(address(creditManager));

if (remainingBorrowable < minDebt) {
tokenTestSuite.mint(underlying, INITIAL_LP, 5 * minDebt);
uint256 depositAmount = 5 * minDebt;
{
uint256 utilization =
WAD * (pool.expectedLiquidity() - pool.availableLiquidity()) / pool.expectedLiquidity();
if (utilization > 85 * WAD / 100) {
depositAmount =
pool.expectedLiquidity() * utilization / (75 * WAD / 100) - pool.expectedLiquidity();
}
}

tokenTestSuite.mint(underlying, INITIAL_LP, depositAmount);
tokenTestSuite.approve(underlying, INITIAL_LP, address(pool));

vm.prank(INITIAL_LP);
pool.deposit(5 * minDebt, INITIAL_LP);
pool.deposit(depositAmount, INITIAL_LP);

address configurator = IACL(addressProvider.getAddressOrRevert(AP_ACL, NO_VERSION_CONTROL)).owner();
uint256 currentLimit = pool.creditManagerDebtLimit(address(creditManager));
vm.prank(configurator);
pool.setCreditManagerDebtLimit(address(creditManager), currentLimit + 5 * minDebt);
pool.setCreditManagerDebtLimit(address(creditManager), currentLimit + depositAmount);
}

creditAccountAmount = Math.min(creditAccountAmount, Math.max(remainingBorrowable / 2, minDebt));
creditAccountAmount = Math.min(creditAccountAmount, minDebt * 5);
} else {
creditAccountAmount = configAccountAmount;
}
Expand Down

0 comments on commit 0ebe7f5

Please sign in to comment.