From 7a372ce918521752130438e6f24b33de5161c815 Mon Sep 17 00:00:00 2001 From: Oumar Fall Date: Thu, 10 Oct 2024 11:07:11 +0200 Subject: [PATCH 1/6] fix gh workflow --- .github/workflows/test.yml | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index e708f78..d04321b 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -66,9 +66,8 @@ jobs: - name: Install dependencies run: yarn --frozen-lockfile - - name: Load cache - uses: dawidd6/action-download-artifact@v2.27.0 + uses: actions/download-artifact@9bc31d5ccc31df68ecc42ccf4149144866c47d8a # v3.0.2 with: name: hardhat-cache path: cache @@ -80,7 +79,7 @@ jobs: RPC_URL: ${{ secrets.RPC_URL }} - name: Save cache - uses: actions/upload-artifact@v2 + uses: actions/upload-artifact@0b7f8abb1508181956e8e162db84b466c27e18ce # v3.1.2 with: name: hardhat-cache path: cache From cd8f3c879f955ae02bb2c7b916944c5ce80a87be Mon Sep 17 00:00:00 2001 From: Oumar Fall Date: Thu, 10 Oct 2024 11:18:03 +0200 Subject: [PATCH 2/6] disabled obsolete tests --- hardhat.config.ts | 2 +- tests/units/blockTag.test.ts | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/hardhat.config.ts b/hardhat.config.ts index 396d19e..2d5baad 100644 --- a/hardhat.config.ts +++ b/hardhat.config.ts @@ -17,7 +17,7 @@ const config: HardhatUserConfig = { chainId: 1, forking: { url: rpcUrl, - blockNumber: 17514213, + blockNumber: 20934202, enabled: true, }, }, diff --git a/tests/units/blockTag.test.ts b/tests/units/blockTag.test.ts index c4ffb1e..f69b9f0 100644 --- a/tests/units/blockTag.test.ts +++ b/tests/units/blockTag.test.ts @@ -5,7 +5,7 @@ import * as process from "process"; import { MorphoAaveV3Adapter } from "../../src"; import { Underlying } from "../../src/mocks/markets"; -describe("Get positions at different blockTags", () => { +describe.skip("Get positions at different blockTags", () => { const userAddress = "0x8C01527C46f0adD00d4B52110b74e4A883590cA7"; // iaezi.eth // https://etherscan.io/tx/0xf67774337bcee684cc87abe3a96f68d3eb6ed2d79394f6bd38428782a4bc2837 // first deposit of 1 WETH From 22db20b30f37ee0c7c360ac666fceed63cf1a66c Mon Sep 17 00:00:00 2001 From: Oumar Fall Date: Thu, 10 Oct 2024 11:27:13 +0200 Subject: [PATCH 3/6] remove caching in workflow due to deprecated version --- .github/workflows/test.yml | 13 ------------- 1 file changed, 13 deletions(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index d04321b..f00f270 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -66,20 +66,7 @@ jobs: - name: Install dependencies run: yarn --frozen-lockfile - - name: Load cache - uses: actions/download-artifact@9bc31d5ccc31df68ecc42ccf4149144866c47d8a # v3.0.2 - with: - name: hardhat-cache - path: cache - if_no_artifact_found: ignore - - name: Run e2e test suite run: yarn test:e2e env: RPC_URL: ${{ secrets.RPC_URL }} - - - name: Save cache - uses: actions/upload-artifact@0b7f8abb1508181956e8e162db84b466c27e18ce # v3.1.2 - with: - name: hardhat-cache - path: cache From 43185356650c24be5b99ab0dfaf04984df48944a Mon Sep 17 00:00:00 2001 From: Oumar Fall Date: Thu, 10 Oct 2024 15:23:47 +0200 Subject: [PATCH 4/6] fix interface infinite load --- tests/e2e/bulker.test.ts | 209 ++++++++++++++++----------------- tests/e2e/transactions.test.ts | 52 ++++---- 2 files changed, 130 insertions(+), 131 deletions(-) diff --git a/tests/e2e/bulker.test.ts b/tests/e2e/bulker.test.ts index 7f5ee85..af56da6 100644 --- a/tests/e2e/bulker.test.ts +++ b/tests/e2e/bulker.test.ts @@ -1,5 +1,5 @@ import { expect } from "chai"; -import { utils, constants } from "ethers"; +import { utils, constants, BigNumber } from "ethers"; import hre, { ethers } from "hardhat"; import { deal } from "hardhat-deal"; @@ -45,11 +45,9 @@ describe("MorphoAaveV3 Bulker", () => { let owner: string; let weth: Weth; let steth: StEth; - let dai: ERC20; let wsteth: WstETH; const initialWethBalance = utils.parseEther("5"); - const initialDaiBalance = utils.parseEther("5000"); - const initialStEthBalance = utils.parseEther("5"); + const initialWstethBalance = utils.parseEther("5"); let bulker: BulkerTxHandler; /** Approve tokens spending for Bulker. @@ -64,7 +62,6 @@ describe("MorphoAaveV3 Bulker", () => { [morphoUser] = await ethers.getSigners(); weth = Weth__factory.connect(Underlying.weth, morphoUser); steth = StEth__factory.connect(Underlying.steth, morphoUser); - dai = ERC20__factory.connect(Underlying.dai, morphoUser); wsteth = WstETH__factory.connect(Underlying.wsteth, morphoUser); morphoAaveV3 = MorphoAaveV3__factory.connect( CONTRACT_ADDRESSES.morphoAaveV3, @@ -73,19 +70,14 @@ describe("MorphoAaveV3 Bulker", () => { owner = await morphoAaveV3.owner(); await deal(weth.address, morphoUser.address, initialWethBalance); - await deal(dai.address, morphoUser.address, initialDaiBalance); - await steth.submit(morphoUser.address, { - from: morphoUser.address, - value: initialStEthBalance, - }); + await deal(wsteth.address, morphoUser.address, initialWstethBalance); approveBulkerOrPermit2 = async (contractAddress) => { await weth.approve(contractAddress, constants.MaxUint256); - await dai.approve(contractAddress, constants.MaxUint256); await steth.approve(contractAddress, constants.MaxUint256); await wsteth.approve(contractAddress, constants.MaxUint256); await steth.approve(addresses.wsteth, constants.MaxUint256); - await dai.approve(morphoAaveV3.address, constants.MaxUint256); + await wsteth.approve(morphoAaveV3.address, constants.MaxUint256); await weth.approve(morphoAaveV3.address, constants.MaxUint256); }; @@ -98,6 +90,7 @@ describe("MorphoAaveV3 Bulker", () => { bulker = new BulkerTxHandler(morphoAdapter); await morphoAdapter.connect(morphoUser.address, morphoUser); await morphoAdapter.refreshAll(initialBlock); + await delay(null, 1000); }); beforeEach(async () => { @@ -116,15 +109,12 @@ describe("MorphoAaveV3 Bulker", () => { const { address } = morphoUser; const wethAllowance = () => weth.allowance(address, CONTRACT_ADDRESSES.bulker); - const daiAllowance = () => - dai.allowance(address, CONTRACT_ADDRESSES.bulker); const stethAllowance = () => steth.allowance(address, CONTRACT_ADDRESSES.bulker); const wstethAllowance = () => wsteth.allowance(address, CONTRACT_ADDRESSES.bulker); expect(await wethAllowance()).to.be.equal(constants.Zero); - expect(await daiAllowance()).to.be.equal(constants.Zero); expect(await stethAllowance()).to.be.equal(constants.Zero); expect(await wstethAllowance()).to.be.equal(constants.Zero); @@ -156,18 +146,6 @@ describe("MorphoAaveV3 Bulker", () => { `expected impersonated user weth allowance is ${constants.MaxUint256}, received ${bulkerWethAllowance}` ); - const userDaiBalance = await dai.balanceOf(address); - expect(userDaiBalance).to.be.equal( - initialDaiBalance, - `expect user dai balance is ${initialDaiBalance}, received ${userDaiBalance}` - ); - - const bulkerDaiAllowance = await daiAllowance(); - expect(bulkerDaiAllowance).to.equal( - constants.MaxUint256, - `expected impersonated user dai allowance is ${constants.MaxUint256}, received ${bulkerDaiAllowance}` - ); - const bulkerStEthAllowance = await stethAllowance(); expect(bulkerStEthAllowance).to.equal( constants.MaxUint256, @@ -179,12 +157,6 @@ describe("MorphoAaveV3 Bulker", () => { constants.MaxUint256, `expected impersonated user wsteth allowance is ${constants.MaxUint256}, received ${bulkerWstEthAllowance}` ); - - const stEthBalance = await steth.balanceOf(address); - expect( - approxEqual(stEthBalance, initialStEthBalance), - `approximate expected user steth balance is ${initialStEthBalance}, received ${stEthBalance}` - ).to.be.true; }); const toAllow = [CONTRACT_ADDRESSES.bulker, CONTRACT_ADDRESSES.permit2]; @@ -193,89 +165,90 @@ describe("MorphoAaveV3 Bulker", () => { contractAddress === CONTRACT_ADDRESSES.bulker ? "Bulker" : "Permit2"; describe(`Supply transaction with ${approvalType} approval`, () => { - it("Should supply DAI as collateral", async () => { + it("Should supply WSTETH as collateral", async () => { await approveBulkerOrPermit2(contractAddress); - const maxDaiCapacity = bulker.getUserMaxCapacity( - Underlying.dai, - TransactionType.supplyCollateral + const maxWstethCapacity = bulker.getUserMaxCapacity( + Underlying.wsteth, + TransactionType.supplyCollateral, + false )!; await bulker.addOperation({ type: TransactionType.supplyCollateral, - amount: maxDaiCapacity.amount, - underlyingAddress: Underlying.dai, + amount: maxWstethCapacity.amount, + underlyingAddress: Underlying.wsteth, }); for (const signature of bulker.signatures$.getValue()) await bulker.sign(signature); await bulker.executeBatch(); - expect(maxDaiCapacity.limiter).to.equal( + expect(maxWstethCapacity.limiter).to.equal( MaxCapacityLimiter.walletBalance ); - const userDaiBalance = await dai.balanceOf(morphoUser.address); - expect(userDaiBalance).to.be.equal( + const userWstethBalance = await wsteth.balanceOf(morphoUser.address); + expect(userWstethBalance).to.be.equal( constants.Zero, - `expected user dai balance is ${constants.Zero}, received ${userDaiBalance}` + `expected user wsteth balance is ${constants.Zero}, received ${userWstethBalance}` ); const ma3Balance = await morphoAaveV3.collateralBalance( - dai.address, + wsteth.address, morphoUser.address ); expect( - approxEqual(ma3Balance, maxDaiCapacity.amount), - `approximate expected ma3 dai balance is ${maxDaiCapacity.amount}, received ${ma3Balance}` + approxEqual(ma3Balance, maxWstethCapacity.amount), + `approximate expected ma3 wsteth balance is ${maxWstethCapacity.amount}, received ${ma3Balance}` ).to.be.true; - const daiBulkerBalance = await dai.balanceOf(addresses.bulker); - expect(daiBulkerBalance).to.be.equal( + const wstethBulkerBalance = await wsteth.balanceOf(addresses.bulker); + expect(wstethBulkerBalance).to.be.equal( constants.Zero, - `expected bulker dai balance is ${constants.Zero}, received ${daiBulkerBalance}` + `expected bulker wsteth balance is ${constants.Zero}, received ${wstethBulkerBalance}` ); }); - it("Should supply DAI as collateral twice", async () => { + it("Should supply WSTETH as collateral twice", async () => { await approveBulkerOrPermit2(contractAddress); - const amount = utils.parseEther("50"); + const amount = utils.parseEther("2"); const total = amount.mul(2); await bulker.addOperation({ type: TransactionType.supplyCollateral, amount, - underlyingAddress: Underlying.dai, + underlyingAddress: Underlying.wsteth, }); await bulker.addOperation({ type: TransactionType.supplyCollateral, amount, - underlyingAddress: Underlying.dai, + underlyingAddress: Underlying.wsteth, }); for (const signature of bulker.signatures$.getValue()) await bulker.sign(signature); await bulker.executeBatch(); - const userDaiBalance = await dai.balanceOf(morphoUser.address); - const expectUserDaiBalance = initialDaiBalance.sub(total); - expect(userDaiBalance).to.be.equal( - expectUserDaiBalance, - `expected user dai balance is ${expectUserDaiBalance}, received ${userDaiBalance}` + const userWstethBalance = await wsteth.balanceOf(morphoUser.address); + const expectUserWstethBalance = initialWstethBalance.sub(total); + expect(userWstethBalance).to.be.equal( + expectUserWstethBalance, + `expected user wsteth balance is ${expectUserWstethBalance}, received ${userWstethBalance}` ); const ma3Balance = await morphoAaveV3.collateralBalance( - dai.address, + wsteth.address, morphoUser.address ); expect( approxEqual(ma3Balance, total), - `approximate expected ma3 dai balance is ${total}, received ${ma3Balance}` + `approximate expected ma3 wsteth balance is ${total}, received ${ma3Balance}` ).to.be.true; - const bulkerDaiBalance = await dai.balanceOf(addresses.bulker); - expect(bulkerDaiBalance).to.be.equal( + const bulkerWstethBalance = await wsteth.balanceOf(addresses.bulker); + expect(bulkerWstethBalance).to.be.equal( constants.Zero, - `expected bulker dai balance is ${constants.Zero}, received ${bulkerDaiBalance}` + `expected bulker wsteth balance is ${constants.Zero}, received ${bulkerWstethBalance}` ); }); @@ -416,6 +389,13 @@ describe("MorphoAaveV3 Bulker", () => { }); it("Should fully wrap stETH and supply as collateral", async () => { + await steth.submit(morphoUser.address, { + from: morphoUser.address, + value: initialWstethBalance, + }); + await morphoAdapter.refreshAll("latest"); + await delay(null, 1000); + await approveBulkerOrPermit2(contractAddress); const maxWstethCapacity = bulker.getUserMaxCapacity( Underlying.wsteth, @@ -465,6 +445,13 @@ describe("MorphoAaveV3 Bulker", () => { }); it("Should partially wrap stETH and supply as collateral", async () => { + await steth.submit(morphoUser.address, { + from: morphoUser.address, + value: initialWstethBalance, + }); + await morphoAdapter.refreshAll("latest"); + await delay(null, 1000); + await approveBulkerOrPermit2(contractAddress); await wsteth.wrap(utils.parseEther("1")); await morphoAdapter.refreshAll("latest"); @@ -522,8 +509,8 @@ describe("MorphoAaveV3 Bulker", () => { it("should borrow ETH", async () => { await approveBulkerOrPermit2(CONTRACT_ADDRESSES.bulker); await morphoAaveV3.supplyCollateral( - Underlying.dai, - initialDaiBalance, + Underlying.wsteth, + initialWstethBalance, morphoUser.address ); await morphoAdapter.refreshAll("latest"); @@ -533,6 +520,7 @@ describe("MorphoAaveV3 Bulker", () => { amount: amountToBorrow, underlyingAddress: Underlying.weth, }); + for (const signature of bulker.signatures$.getValue()) await bulker.sign(signature); await bulker.executeBatch(); @@ -561,10 +549,14 @@ describe("MorphoAaveV3 Bulker", () => { }); it("should borrow and unwrap ETH", async () => { + const initialMa3Balance = await morphoAaveV3.borrowBalance( + weth.address, + morphoUser.address + ); await approveBulkerOrPermit2(CONTRACT_ADDRESSES.bulker); await morphoAaveV3.supplyCollateral( - Underlying.dai, - initialDaiBalance, + Underlying.wsteth, + initialWstethBalance, morphoUser.address ); await morphoAdapter.refreshAll("latest"); @@ -584,9 +576,12 @@ describe("MorphoAaveV3 Bulker", () => { weth.address, morphoUser.address ); - expect(ma3Balance).to.equal( + expect(ma3Balance.sub(initialMa3Balance)).to.approximately( amountToBorrow, - `expected ma3 weth balance is ${amountToBorrow}, received ${ma3Balance}` + 1, + `expected ma3 weth balance change is ${amountToBorrow}, received ${ma3Balance.sub( + initialMa3Balance + )}` ); const bulkerWethBalance = await weth.balanceOf(addresses.bulker); @@ -748,8 +743,8 @@ describe("MorphoAaveV3 Bulker", () => { await approveBulkerOrPermit2(contractAddress); await morphoAaveV3.supplyCollateral( - Underlying.dai, - initialDaiBalance, + Underlying.wsteth, + initialWstethBalance, morphoUser.address ); await morphoAaveV3.borrow( @@ -805,8 +800,8 @@ describe("MorphoAaveV3 Bulker", () => { it("should fully wrap ETH and repay WETH", async () => { await approveBulkerOrPermit2(contractAddress); await morphoAaveV3.supplyCollateral( - Underlying.dai, - initialDaiBalance, + Underlying.wsteth, + initialWstethBalance, morphoUser.address ); await morphoAaveV3.borrow( @@ -884,18 +879,19 @@ describe("MorphoAaveV3 Bulker", () => { }); describe("Supply Collateral + Borrow", () => { - it("Should supply DAI as collateral and borrow WETH", async () => { + it("Should supply WSTETH as collateral and borrow WETH", async () => { await approveBulkerOrPermit2(CONTRACT_ADDRESSES.permit2); - const maxDaiCapacity = bulker.getUserMaxCapacity( - Underlying.dai, - TransactionType.supplyCollateral + const maxWstethCapacity = bulker.getUserMaxCapacity( + Underlying.wsteth, + TransactionType.supplyCollateral, + false )!; const amountToBorrow = utils.parseEther("1"); await bulker.addOperation({ type: TransactionType.supplyCollateral, - amount: maxDaiCapacity.amount, - underlyingAddress: Underlying.dai, + amount: maxWstethCapacity.amount, + underlyingAddress: Underlying.wsteth, }); await bulker.addOperation({ type: TransactionType.borrow, @@ -907,26 +903,29 @@ describe("MorphoAaveV3 Bulker", () => { await bulker.sign(signature); await bulker.executeBatch(); - expect(maxDaiCapacity.limiter).to.equal(MaxCapacityLimiter.walletBalance); - const userDaiBalance = await dai.balanceOf(morphoUser.address); - expect(userDaiBalance).to.be.equal( + expect(maxWstethCapacity.limiter).to.equal( + MaxCapacityLimiter.walletBalance + ); + + const userWstethBalance = await wsteth.balanceOf(morphoUser.address); + expect(userWstethBalance).to.be.equal( constants.Zero, - `expected user dai balance is ${constants.Zero}, received ${userDaiBalance}` + `expected bulker wsteth balance is ${constants.Zero}, received ${userWstethBalance}` ); const ma3Balance = await morphoAaveV3.collateralBalance( - dai.address, + wsteth.address, morphoUser.address ); expect( - approxEqual(ma3Balance, maxDaiCapacity.amount), - `approximated expected ma3 dai balance is ${maxDaiCapacity.amount}, received ${ma3Balance}` + approxEqual(ma3Balance, maxWstethCapacity.amount), + `approximated expected ma3 wsteth balance is ${maxWstethCapacity.amount}, received ${ma3Balance}` ).to.be.true; - const bulkerDaiBalance = await dai.balanceOf(addresses.bulker); - expect(bulkerDaiBalance).to.be.equal( + const bulkerWstethBalance = await wsteth.balanceOf(addresses.bulker); + expect(bulkerWstethBalance).to.be.equal( constants.Zero, - `expected bulker dai balance is ${constants.Zero}, received ${bulkerDaiBalance}` + `expected bulker wsteth balance is ${constants.Zero}, received ${bulkerWstethBalance}` ); const userEthBalance = await weth.balanceOf(morphoUser.address); @@ -939,11 +938,11 @@ describe("MorphoAaveV3 Bulker", () => { }); describe("Repay + withdraw collateral", () => { - it("should repay WETH and withdraw DAI collateral", async () => { + it("should repay WETH and withdraw WSTETH collateral", async () => { await approveBulkerOrPermit2(CONTRACT_ADDRESSES.bulker); await morphoAaveV3.supplyCollateral( - Underlying.dai, - initialDaiBalance, + Underlying.wsteth, + initialWstethBalance, morphoUser.address ); await morphoAaveV3.borrow( @@ -956,10 +955,10 @@ describe("MorphoAaveV3 Bulker", () => { await morphoAdapter.refreshAll("latest"); - const userDaiBalance = await dai.balanceOf(morphoUser.address); - expect(userDaiBalance).to.equal( + const userWstethBalance = await wsteth.balanceOf(morphoUser.address); + expect(userWstethBalance).to.equal( constants.Zero, - `expected user dai balance is ${constants.Zero}, received ${userDaiBalance}` + `expected user wsteth balance is ${constants.Zero}, received ${userWstethBalance}` ); const userWethBalance = await weth.balanceOf(morphoUser.address); @@ -970,7 +969,7 @@ describe("MorphoAaveV3 Bulker", () => { ); const withdrawAmount = await morphoAaveV3.collateralBalance( - Underlying.dai, + Underlying.wsteth, morphoUser.address ); await bulker.addOperation({ @@ -981,23 +980,23 @@ describe("MorphoAaveV3 Bulker", () => { await bulker.addOperation({ type: TransactionType.withdrawCollateral, amount: constants.MaxUint256, - underlyingAddress: Underlying.dai, + underlyingAddress: Underlying.wsteth, }); for (const signature of bulker.signatures$.getValue()) await bulker.sign(signature); await bulker.executeBatch(); - const finalUserDaiBalance = await dai.balanceOf(morphoUser.address); - expect(finalUserDaiBalance).to.be.greaterThan( + const finalUserWstethBalance = await wsteth.balanceOf(morphoUser.address); + expect(finalUserWstethBalance).to.be.greaterThan( withdrawAmount, - `expected user dai balance should be greater than withdrawn amount ${withdrawAmount}, received ${finalUserDaiBalance}` + `expected user wsteth balance should be greater than withdrawn amount ${withdrawAmount}, received ${finalUserWstethBalance}` ); - const bulkerDaiBalance = await dai.balanceOf(addresses.bulker); - expect(bulkerDaiBalance).to.be.equal( + const bulkerWstethBalance = await wsteth.balanceOf(addresses.bulker); + expect(bulkerWstethBalance).to.be.equal( constants.Zero, - `expected bulker dai balance is ${constants.Zero}, received ${bulkerDaiBalance}` + `expected bulker wsteth balance is ${constants.Zero}, received ${bulkerWstethBalance}` ); const bulkerWethBalance = await weth.balanceOf(addresses.bulker); @@ -1014,12 +1013,12 @@ describe("MorphoAaveV3 Bulker", () => { ); const ma3Balance = await morphoAaveV3.collateralBalance( - dai.address, + wsteth.address, morphoUser.address ); expect(ma3Balance).to.equal( constants.Zero, - `expected ma3 dai balance is ${constants.Zero}, received ${ma3Balance}` + `expected ma3 wsteth balance is ${constants.Zero}, received ${ma3Balance}` ); }); }); diff --git a/tests/e2e/transactions.test.ts b/tests/e2e/transactions.test.ts index 2691b27..a0ccbc4 100644 --- a/tests/e2e/transactions.test.ts +++ b/tests/e2e/transactions.test.ts @@ -1,7 +1,7 @@ import { expect } from "chai"; import { utils, constants } from "ethers"; import { getAddress } from "ethers/lib/utils"; -import { ethers, network } from "hardhat"; +import { ethers } from "hardhat"; import { deal } from "hardhat-deal"; import { BaseProvider } from "@ethersproject/providers"; @@ -37,25 +37,25 @@ describe("MorphoAaveV3", () => { let morphoAaveV3: MorphoAaveV3; let owner: string; let weth: Weth; - let dai: ERC20; + let wsteth: ERC20; const initialWethBalance = utils.parseEther("5"); - const initialDaiBalance = utils.parseEther("500"); + const initialWstethBalance = utils.parseEther("500"); before(async () => { [morphoUser] = await ethers.getSigners(); weth = Weth__factory.connect(Underlying.weth, morphoUser); - dai = ERC20__factory.connect(Underlying.dai, morphoUser); + wsteth = ERC20__factory.connect(Underlying.wsteth, morphoUser); morphoAaveV3 = MorphoAaveV3__factory.connect( CONTRACT_ADDRESSES.morphoAaveV3, morphoUser ); owner = await morphoAaveV3.owner(); - // set user WETH and DAI balance, give impersonated user max allowance on tokens + // set user WETH and WSTETH balance, give impersonated user max allowance on tokens await weth.approve(CONTRACT_ADDRESSES.morphoAaveV3, constants.MaxUint256); - await dai.approve(CONTRACT_ADDRESSES.morphoAaveV3, constants.MaxUint256); + await wsteth.approve(CONTRACT_ADDRESSES.morphoAaveV3, constants.MaxUint256); await deal(weth.address, morphoUser.address, initialWethBalance); - await deal(dai.address, morphoUser.address, initialDaiBalance); + await deal(wsteth.address, morphoUser.address, initialWstethBalance); initialBlock = await time.latestBlock(); @@ -101,15 +101,15 @@ describe("MorphoAaveV3", () => { constants.MaxUint256, "impersonated user weth allowance is not maxUint256" ); - expect(await dai.balanceOf(morphoUser.address)).to.be.equal( - initialDaiBalance, - `dai balance is not ${initialDaiBalance}` + expect(await wsteth.balanceOf(morphoUser.address)).to.be.equal( + initialWstethBalance, + `wsteth balance is not ${initialWstethBalance}` ); expect( - await dai.allowance(morphoUser.address, morphoAaveV3.address) + await wsteth.allowance(morphoUser.address, morphoAaveV3.address) ).to.equal( constants.MaxUint256, - "impersonated user dai allowance is not maxUint256" + "impersonated user wsteth allowance is not maxUint256" ); }); @@ -142,7 +142,7 @@ describe("MorphoAaveV3", () => { describe("Supply collateral transaction", () => { it("should increase borrow capacity", async () => { let borrowCapacity = morphoAdapter.getUserMaxCapacity( - Underlying.dai, + Underlying.wsteth, TransactionType.borrow )!; @@ -152,7 +152,7 @@ describe("MorphoAaveV3", () => { ); let supplyCapacity = morphoAdapter.getUserMaxCapacity( - Underlying.dai, + Underlying.wsteth, TransactionType.supplyCollateral )!; expect(supplyCapacity.limiter).to.be.equal( @@ -162,7 +162,7 @@ describe("MorphoAaveV3", () => { await morphoAdapter.handleMorphoTransaction( TransactionType.supplyCollateral, - Underlying.dai, + Underlying.wsteth, supplyCapacity.amount ); @@ -179,13 +179,13 @@ describe("MorphoAaveV3", () => { // refresh supply capacity supplyCapacity = morphoAdapter.getUserMaxCapacity( - Underlying.dai, + Underlying.wsteth, TransactionType.supplyCollateral )!; expect(supplyCapacity.amount).to.be.equal( constants.Zero, - "max dai supply collateral capacity is not 0" + "max wsteth supply collateral capacity is not 0" ); }); }); @@ -193,7 +193,7 @@ describe("MorphoAaveV3", () => { describe("Withdraw collateral transaction", () => { it("should be limited by balance", async () => { const supplyCapacity = morphoAdapter.getUserMaxCapacity( - Underlying.dai, + Underlying.wsteth, TransactionType.supplyCollateral )!; expect(supplyCapacity.limiter).to.be.equal( @@ -203,12 +203,12 @@ describe("MorphoAaveV3", () => { await morphoAdapter.handleMorphoTransaction( TransactionType.supplyCollateral, - Underlying.dai, + Underlying.wsteth, supplyCapacity.amount ); const withdrawCapacity = morphoAdapter.getUserMaxCapacity( - Underlying.dai, + Underlying.wsteth, TransactionType.withdrawCollateral )!; @@ -246,8 +246,8 @@ describe("MorphoAaveV3", () => { await morphoAdapter.handleMorphoTransaction( TransactionType.supplyCollateral, - Underlying.dai, - initialDaiBalance + Underlying.wsteth, + initialWstethBalance ); // refresh borrow Capacity @@ -304,7 +304,7 @@ describe("MorphoAaveV3", () => { describe("Repay transaction", () => { it("should be limited by balance", async () => { const supplyCapacity = morphoAdapter.getUserMaxCapacity( - Underlying.dai, + Underlying.wsteth, TransactionType.supplyCollateral )!; expect(supplyCapacity.limiter).to.be.equal( @@ -314,7 +314,7 @@ describe("MorphoAaveV3", () => { await morphoAdapter.handleMorphoTransaction( TransactionType.supplyCollateral, - Underlying.dai, + Underlying.wsteth, supplyCapacity.amount ); @@ -518,8 +518,8 @@ describe("MorphoAaveV3", () => { await morphoAdapter.handleMorphoTransaction( TransactionType.supplyCollateral, - Underlying.dai, - initialDaiBalance + Underlying.wsteth, + initialWstethBalance ); // refresh borrow Capacity From 04c17a4840d429d8125c83b25cc6f39e3f21435c Mon Sep 17 00:00:00 2001 From: Oumar Fall Date: Thu, 17 Oct 2024 11:45:51 +0200 Subject: [PATCH 5/6] tests: update tests --- hardhat.config.ts | 2 +- tests/e2e/transactions.test.ts | 9 ++------- 2 files changed, 3 insertions(+), 8 deletions(-) diff --git a/hardhat.config.ts b/hardhat.config.ts index 2d5baad..7e069ae 100644 --- a/hardhat.config.ts +++ b/hardhat.config.ts @@ -17,7 +17,7 @@ const config: HardhatUserConfig = { chainId: 1, forking: { url: rpcUrl, - blockNumber: 20934202, + blockNumber: 20984127, enabled: true, }, }, diff --git a/tests/e2e/transactions.test.ts b/tests/e2e/transactions.test.ts index a0ccbc4..c34bb20 100644 --- a/tests/e2e/transactions.test.ts +++ b/tests/e2e/transactions.test.ts @@ -284,20 +284,15 @@ describe("MorphoAaveV3", () => { TransactionType.borrow )!; - // Let's now borrow all the liquidity we can + // Let's now borrow 90% of borrow capacity await morphoAdapter.handleMorphoTransaction( TransactionType.borrow, Underlying.weth, - borrowCapacity.amount + borrowCapacity.amount.mul(9).div(10) ); const finalHealthFactor = morphoAdapter.computeUserData().healthFactor; expect(finalHealthFactor).to.be.lt(intermediaryHealthFactor); - // TODO do a check at some decimals precision - // expect(finalHealthFactor).to.be.eq( - // WadRayMath.WAD, // won't be exactly 1 - // "final health factor is not 1" - // ); }); }); From 8ae1af2086ea69ad471ea15f1385394818a28cbf Mon Sep 17 00:00:00 2001 From: Oumar Fall Date: Thu, 24 Oct 2024 10:15:17 +0200 Subject: [PATCH 6/6] tests(block-tag): reenable disabled test --- tests/units/blockTag.test.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/units/blockTag.test.ts b/tests/units/blockTag.test.ts index f69b9f0..c4ffb1e 100644 --- a/tests/units/blockTag.test.ts +++ b/tests/units/blockTag.test.ts @@ -5,7 +5,7 @@ import * as process from "process"; import { MorphoAaveV3Adapter } from "../../src"; import { Underlying } from "../../src/mocks/markets"; -describe.skip("Get positions at different blockTags", () => { +describe("Get positions at different blockTags", () => { const userAddress = "0x8C01527C46f0adD00d4B52110b74e4A883590cA7"; // iaezi.eth // https://etherscan.io/tx/0xf67774337bcee684cc87abe3a96f68d3eb6ed2d79394f6bd38428782a4bc2837 // first deposit of 1 WETH