Skip to content

Commit

Permalink
test(hardhat): add erc4626 deposit
Browse files Browse the repository at this point in the history
  • Loading branch information
Rubilmax committed Oct 30, 2023
1 parent 4412f6f commit e116b0b
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 4 deletions.
52 changes: 49 additions & 3 deletions test/hardhat/EthereumBundler.spec.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { AbiCoder, MaxUint256, Signature, keccak256, toBigInt, TypedDataDomain, TypedDataField } from "ethers";
import hre from "hardhat";
import { BundlerAction } from "pkg";
import { ERC20Mock, EthereumBundler, MorphoMock, OracleMock, SpeedJumpIrmMock } from "types";
import { ERC20Mock, ERC4626Mock, EthereumBundler, MorphoMock, OracleMock, SpeedJumpIrmMock } from "types";
import { MarketParamsStruct } from "types/lib/morpho-blue/src/Morpho";

import { SignerWithAddress } from "@nomicfoundation/hardhat-ethers/signers";
Expand Down Expand Up @@ -134,6 +134,9 @@ describe("EthereumBundler", () => {

let morphoAuthorizationConfig: TypedDataConfig;

let erc4626: ERC4626Mock;
let erc4626Address: string;

let bundler: EthereumBundler;
let bundlerAddress: string;

Expand Down Expand Up @@ -180,8 +183,15 @@ describe("EthereumBundler", () => {
types: morphoAuthorizationTypes,
};

const loanAddress = await loan.getAddress();
const ERC4626MockFactory = await hre.ethers.getContractFactory("ERC4626Mock", admin);

const collateralAddress = await collateral.getAddress();

erc4626 = await ERC4626MockFactory.deploy(collateralAddress, "MetaMorpho", "MM");

erc4626Address = await erc4626.getAddress();

const loanAddress = await loan.getAddress();
const oracleAddress = await oracle.getAddress();
const irmAddress = await irm.getAddress();

Expand Down Expand Up @@ -220,7 +230,7 @@ describe("EthereumBundler", () => {
hre.tracer.nameTags[bundlerAddress] = "EthereumBundler";
});

it("should simulate gas cost [supplyCollateral+borrow]", async () => {
it("should simulate gas cost [morpho-supplyCollateral+borrow]", async () => {
for (let i = 0; i < suppliers.length; ++i) {
logProgress("supplyCollateral+borrow", i, suppliers.length);

Expand Down Expand Up @@ -279,4 +289,40 @@ describe("EthereumBundler", () => {
]);
}
});

it("should simulate gas cost [erc4626-deposit]", async () => {
for (let i = 0; i < suppliers.length; ++i) {
logProgress("erc4626-deposit", i, suppliers.length);

const supplier = suppliers[i];

const assets = BigInt.WAD * toBigInt(1 + Math.floor(random() * 100));

const permit2TransferFrom = {
permitted: {
token: await collateral.getAddress(),
amount: assets,
},
spender: bundlerAddress,
nonce: 0n,
deadline: MAX_UINT48,
};

await collateral.connect(supplier).approve(permit2Address, MaxUint256);

await randomForwardTimestamp();

await bundler
.connect(supplier)
.multicall([
BundlerAction.permit2TransferFrom(
permit2TransferFrom,
Signature.from(
await supplier.signTypedData(permit2Config.domain, permit2Config.types, permit2TransferFrom),
),
),
BundlerAction.erc4626Deposit(erc4626Address, assets, 0, supplier.address),
]);
}
});
});
2 changes: 1 addition & 1 deletion tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"compilerOptions": {
"target": "es6",
"target": "es2020",
"module": "nodenext",
"moduleResolution": "nodenext",
"outDir": "dist",
Expand Down

0 comments on commit e116b0b

Please sign in to comment.