Skip to content

Commit 92fc368

Browse files
committed
Remove withdrawAll
1 parent d8dfd58 commit 92fc368

File tree

2 files changed

+6
-55
lines changed

2 files changed

+6
-55
lines changed

contracts/LiquidityPool.sol

Lines changed: 1 addition & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,7 @@ contract LiquidityPool is AccessControlUpgradeable, EIP712Upgradeable {
160160
// get USDC from AAVE
161161
IPool pool = IPool(AAVE_POOL_PROVIDER.getPool());
162162
uint256 withdrawn = pool.withdraw(address(COLLATERAL), amount, to);
163-
assert(withdrawn == amount);
163+
// assert(withdrawn == amount);
164164
// health factor after withdraw
165165
UserAccountData memory userAccountData;
166166
(
@@ -172,25 +172,6 @@ contract LiquidityPool is AccessControlUpgradeable, EIP712Upgradeable {
172172
userAccountData.healthFactor
173173
) = pool.getUserAccountData(address(this));
174174
if (userAccountData.healthFactor < _getStorage()._minHealthFactor) revert HealthFactorTooLow();
175-
emit WithdrawnFromAave(amount);
176-
}
177-
178-
function withdrawAll(address to) public onlyRole(DEFAULT_ADMIN_ROLE) {
179-
// get USDC from AAVE
180-
IPool pool = IPool(AAVE_POOL_PROVIDER.getPool());
181-
// Check that there is no debt
182-
UserAccountData memory userAccountData;
183-
(
184-
userAccountData.totalCollateralBase,
185-
userAccountData.totalDebtBase,
186-
userAccountData.availableBorrowsBase,
187-
userAccountData.currentLiquidationThreshold,
188-
userAccountData.ltv,
189-
userAccountData.healthFactor
190-
) = pool.getUserAccountData(address(this));
191-
if (userAccountData.totalDebtBase != 0) revert TokenHasDebt();
192-
193-
uint256 withdrawn = pool.withdraw(address(COLLATERAL), type(uint256).max, to);
194175
emit WithdrawnFromAave(withdrawn);
195176
}
196177

test/LiquidityPool.ts

Lines changed: 5 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import hre from "hardhat";
66
import {
77
getCreateAddress, getContractAt, deploy, signBorrow
88
} from "./helpers";
9-
import {encodeBytes32String} from "ethers";
9+
import {encodeBytes32String, MaxUint256} from "ethers";
1010
import {
1111
MockTarget, LiquidityPool, TransparentUpgradeableProxy, ProxyAdmin
1212
} from "../typechain-types";
@@ -412,7 +412,10 @@ describe("LiquidityPool", function () {
412412
expect(await usdc.balanceOf(user.address)).to.be.eq(amount);
413413
expect(await aToken.balanceOf(liquidityPool.target)).to.be.greaterThan(0);
414414

415-
expect(await liquidityPool.connect(admin).withdrawAll(user.address))
415+
// Using type(uint256).max as amount to withdraw all available amount
416+
expect(await liquidityPool.connect(admin).withdraw(
417+
user.address, MaxUint256
418+
))
416419
.to.emit(liquidityPool, "WidthrawnFromAave");
417420
expect(await usdc.balanceOf(user.address)).to.be.greaterThan(amount);
418421
expect(await aToken.balanceOf(liquidityPool.target)).to.eq(0);
@@ -681,39 +684,6 @@ describe("LiquidityPool", function () {
681684
.to.be.revertedWithCustomError(liquidityPool, "AccessControlUnauthorizedAccount");
682685
});
683686

684-
it("Should NOT withdraw all collateral if there is some debt", async function () {
685-
const {
686-
liquidityPool, usdc, usdcOwner, USDC_DEC, user, admin, uni, mpc_signer, UNI_DEC, user2
687-
} = await loadFixture(deployAll);
688-
const amount = 1000n * USDC_DEC; // $1000
689-
await usdc.connect(usdcOwner).transfer(liquidityPool.target, amount);
690-
expect(await liquidityPool.deposit())
691-
.to.emit(liquidityPool, "SuppliedToAave").withArgs(amount);
692-
693-
const amountToBorrow = 3n * UNI_DEC;
694-
695-
const signature = await signBorrow(
696-
mpc_signer,
697-
liquidityPool.target as string,
698-
uni.target as string,
699-
amountToBorrow.toString(),
700-
user2.address,
701-
"0x",
702-
31337
703-
);
704-
705-
expect(await liquidityPool.connect(user).borrow(
706-
uni.target,
707-
amountToBorrow,
708-
user2,
709-
"0x",
710-
signature))
711-
.to.emit(liquidityPool, "Borrowed");
712-
713-
await expect(liquidityPool.connect(admin).withdrawAll(user.address))
714-
.to.be.revertedWithCustomError(liquidityPool, "TokenHasDebt");
715-
});
716-
717687
it("Should NOT withdraw profit for collateral", async function () {
718688
const {liquidityPool, usdc, admin, user} = await loadFixture(deployAll);
719689
const amount = 1000n;

0 commit comments

Comments
 (0)