Skip to content

Commit bba4e78

Browse files
committed
Merge branch 'feat-liq-pool' of github.com:sprintertech/sprinter-liquidity-contracts into feat-liq-pool
2 parents 7d23533 + 92fc368 commit bba4e78

File tree

2 files changed

+7
-58
lines changed

2 files changed

+7
-58
lines changed

contracts/LiquidityPool.sol

Lines changed: 2 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -175,7 +175,7 @@ contract LiquidityPool is AccessControlUpgradeable, EIP712Upgradeable {
175175
// get USDC from AAVE
176176
IPool pool = IPool(AAVE_POOL_PROVIDER.getPool());
177177
uint256 withdrawn = pool.withdraw(address(COLLATERAL), amount, to);
178-
assert(withdrawn == amount);
178+
// assert(withdrawn == amount);
179179
// health factor after withdraw
180180
UserAccountData memory userAccountData;
181181
(
@@ -187,29 +187,10 @@ contract LiquidityPool is AccessControlUpgradeable, EIP712Upgradeable {
187187
userAccountData.healthFactor
188188
) = pool.getUserAccountData(address(this));
189189
if (userAccountData.healthFactor < _getStorage().minHealthFactor) revert HealthFactorTooLow();
190-
emit WithdrawnFromAave(amount);
191-
}
192-
193-
function withdrawAll(address to) public onlyRole(DEFAULT_ADMIN_ROLE) {
194-
// get USDC from AAVE
195-
IPool pool = IPool(AAVE_POOL_PROVIDER.getPool());
196-
// Check that there is no debt
197-
UserAccountData memory userAccountData;
198-
(
199-
userAccountData.totalCollateralBase,
200-
userAccountData.totalDebtBase,
201-
userAccountData.availableBorrowsBase,
202-
userAccountData.currentLiquidationThreshold,
203-
userAccountData.ltv,
204-
userAccountData.healthFactor
205-
) = pool.getUserAccountData(address(this));
206-
if (userAccountData.totalDebtBase != 0) revert TokenHasDebt();
207-
208-
uint256 withdrawn = pool.withdraw(address(COLLATERAL), type(uint256).max, to);
209190
emit WithdrawnFromAave(withdrawn);
210191
}
211192

212-
function withdrawProfit(address token, address to, uint256 amount) public onlyRole(WITHDRAW_PROFIT_ROLE) {
193+
function withdrawProfit(address token, address to, uint256 amount) public onlyRole(WITHDRAW_PROFIT_ROLE) {
213194
// check that not collateral
214195
if (token == address(COLLATERAL)) revert CannotWithdrawProfitCollateral();
215196
// check that no debt

test/LiquidityPool.ts

Lines changed: 5 additions & 37 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";
@@ -431,7 +431,10 @@ describe("LiquidityPool", function () {
431431
expect(await usdc.balanceOf(user.address)).to.be.eq(amount);
432432
expect(await aToken.balanceOf(liquidityPool.target)).to.be.greaterThan(0);
433433

434-
expect(await liquidityPool.connect(admin).withdrawAll(user.address))
434+
// Using type(uint256).max as amount to withdraw all available amount
435+
expect(await liquidityPool.connect(admin).withdraw(
436+
user.address, MaxUint256
437+
))
435438
.to.emit(liquidityPool, "WidthrawnFromAave");
436439
expect(await usdc.balanceOf(user.address)).to.be.greaterThan(amount);
437440
expect(await aToken.balanceOf(liquidityPool.target)).to.eq(0);
@@ -785,41 +788,6 @@ describe("LiquidityPool", function () {
785788
.to.be.revertedWithCustomError(liquidityPool, "AccessControlUnauthorizedAccount");
786789
});
787790

788-
it("Should NOT withdraw all collateral if there is some debt", async function () {
789-
const {
790-
liquidityPool, usdc, usdcOwner, USDC_DEC, user, admin, uni, mpc_signer, UNI_DEC, user2
791-
} = await loadFixture(deployAll);
792-
const amount = 1000n * USDC_DEC; // $1000
793-
await usdc.connect(usdcOwner).transfer(liquidityPool.target, amount);
794-
expect(await liquidityPool.deposit())
795-
.to.emit(liquidityPool, "SuppliedToAave").withArgs(amount);
796-
797-
const amountToBorrow = 3n * UNI_DEC;
798-
799-
const signature = await signBorrow(
800-
mpc_signer,
801-
liquidityPool.target as string,
802-
uni.target as string,
803-
amountToBorrow.toString(),
804-
user2.address,
805-
"0x",
806-
31337
807-
);
808-
809-
expect(await liquidityPool.connect(user).borrow(
810-
uni.target,
811-
amountToBorrow,
812-
user2,
813-
"0x",
814-
0n,
815-
2000000000n,
816-
signature))
817-
.to.emit(liquidityPool, "Borrowed");
818-
819-
await expect(liquidityPool.connect(admin).withdrawAll(user.address))
820-
.to.be.revertedWithCustomError(liquidityPool, "TokenHasDebt");
821-
});
822-
823791
it("Should NOT withdraw profit for collateral", async function () {
824792
const {liquidityPool, usdc, admin, user} = await loadFixture(deployAll);
825793
const amount = 1000n;

0 commit comments

Comments
 (0)