Skip to content

Commit f6f63e9

Browse files
committed
feat: migration to hh v3
1 parent 3203b31 commit f6f63e9

3 files changed

Lines changed: 99 additions & 86 deletions

File tree

Lines changed: 78 additions & 71 deletions
Original file line numberDiff line numberDiff line change
@@ -1,81 +1,88 @@
1-
import { HardhatRuntimeEnvironment } from "hardhat/types";
2-
import { DeployFunction } from "hardhat-deploy/types";
3-
import { Contract } from "ethers";
1+
import { artifacts, deployScript } from "../rocketh/deploy.js";
2+
import { parseEther } from "viem";
43

54
/**
6-
* Deploys a contract named "YourContract" using the deployer account and
7-
* constructor arguments set to the deployer address
5+
* Deploys "Corn", "CornDEX", "Lending" and "MovePrice" using the deployer account.
86
*
9-
* @param hre HardhatRuntimeEnvironment object.
7+
* On localhost, the deployer account is the one that comes with Hardhat, which is already funded.
8+
*
9+
* When deploying to live networks (e.g `yarn deploy --network sepolia`), the deployer account
10+
* should have sufficient balance to pay for the gas fees for contract creation.
11+
*
12+
* You can generate a random account with `yarn generate` or `yarn account:import` to import your
13+
* existing PK which will fill DEPLOYER_PRIVATE_KEY_ENCRYPTED in the .env file (used in hardhat.config.ts).
14+
* Run `yarn account` to check the deployer balance on every network.
1015
*/
11-
const deployContracts: DeployFunction = async function (hre: HardhatRuntimeEnvironment) {
12-
/*
13-
On localhost, the deployer account is the one that comes with Hardhat, which is already funded.
14-
15-
When deploying to live networks (e.g `yarn deploy --network sepolia`), the deployer account
16-
should have sufficient balance to pay for the gas fees for contract creation.
17-
18-
You can generate a random account with `yarn generate` or `yarn account:import` to import your
19-
existing PK which will fill DEPLOYER_PRIVATE_KEY_ENCRYPTED in the .env file (then used on hardhat.config.ts)
20-
You can run the `yarn account` command to check your balance in every network.
21-
*/
22-
const { deployer } = await hre.getNamedAccounts();
23-
const { deploy } = hre.deployments;
16+
export default deployScript(
17+
async env => {
18+
const { deployer } = env.namedAccounts;
2419

25-
await deploy("Corn", {
26-
from: deployer,
27-
// Contract constructor arguments
28-
args: [],
29-
log: true,
30-
// autoMine: can be passed to the deploy function to make the deployment process faster on local networks by
31-
// automatically mining the contract deployment transaction. There is no effect on live networks.
32-
autoMine: true,
33-
});
34-
const cornToken = await hre.ethers.getContract<Contract>("Corn", deployer);
20+
const cornToken = await env.deploy("Corn", {
21+
account: deployer,
22+
artifact: artifacts.Corn,
23+
args: [],
24+
});
3525

36-
await deploy("CornDEX", {
37-
from: deployer,
38-
args: [cornToken.target],
39-
log: true,
40-
autoMine: true,
41-
});
42-
const cornDEX = await hre.ethers.getContract<Contract>("CornDEX", deployer);
43-
const lending = await deploy("Lending", {
44-
from: deployer,
45-
args: [cornDEX.target, cornToken.target],
46-
log: true,
47-
autoMine: true,
48-
});
26+
const cornDEX = await env.deploy("CornDEX", {
27+
account: deployer,
28+
artifact: artifacts.CornDEX,
29+
args: [cornToken.address],
30+
});
4931

50-
// Set up the move price contract
51-
const movePrice = await deploy("MovePrice", {
52-
from: deployer,
53-
args: [cornDEX.target, cornToken.target],
54-
log: true,
55-
autoMine: true,
56-
});
32+
const lending = await env.deploy("Lending", {
33+
account: deployer,
34+
artifact: artifacts.Lending,
35+
args: [cornDEX.address, cornToken.address],
36+
});
5737

58-
// Only set up contract state on local network
59-
if (hre.network.name == "localhost") {
60-
const GAS_LIMIT = 500_000n;
61-
// Give ETH and CORN to the move price contract
62-
await hre.ethers.provider.send("hardhat_setBalance", [
63-
movePrice.address,
64-
`0x${hre.ethers.parseEther("10000000000000000000000").toString(16)}`,
65-
]);
66-
await cornToken.mintTo(movePrice.address, hre.ethers.parseEther("10000000000000000000000"), { gasLimit: GAS_LIMIT });
67-
// Lenders deposit CORN to the lending contract
68-
await cornToken.mintTo(lending.address, hre.ethers.parseEther("10000000000000000000000"), { gasLimit: GAS_LIMIT });
69-
// Give CORN and ETH to the deployer
70-
await cornToken.mintTo(deployer, hre.ethers.parseEther("1000000000000"), { gasLimit: GAS_LIMIT });
71-
await hre.ethers.provider.send("hardhat_setBalance", [
72-
deployer,
73-
`0x${hre.ethers.parseEther("100000000000").toString(16)}`,
74-
]);
38+
// Set up the move price contract
39+
const movePrice = await env.deploy("MovePrice", {
40+
account: deployer,
41+
artifact: artifacts.MovePrice,
42+
args: [cornDEX.address, cornToken.address],
43+
});
7544

76-
await cornToken.approve(cornDEX.target, hre.ethers.parseEther("1000000000"), { gasLimit: GAS_LIMIT });
77-
await cornDEX.init(hre.ethers.parseEther("1000000000"), { value: hre.ethers.parseEther("1000000"), gasLimit: GAS_LIMIT });
78-
}
79-
};
45+
// Only set up contract state on local network
46+
if (env.name === "default" || env.name === "localhost") {
47+
// Give ETH and CORN to the move price contract
48+
await env.network.provider.request({
49+
method: "hardhat_setBalance",
50+
params: [movePrice.address, `0x${parseEther("10000000000000000000000").toString(16)}`],
51+
});
52+
await env.execute(cornToken, {
53+
functionName: "mintTo",
54+
args: [movePrice.address, parseEther("10000000000000000000000")],
55+
account: deployer,
56+
});
57+
// Lenders deposit CORN to the lending contract
58+
await env.execute(cornToken, {
59+
functionName: "mintTo",
60+
args: [lending.address, parseEther("10000000000000000000000")],
61+
account: deployer,
62+
});
63+
// Give CORN and ETH to the deployer
64+
await env.execute(cornToken, {
65+
functionName: "mintTo",
66+
args: [deployer, parseEther("1000000000000")],
67+
account: deployer,
68+
});
69+
await env.network.provider.request({
70+
method: "hardhat_setBalance",
71+
params: [deployer, `0x${parseEther("100000000000").toString(16)}`],
72+
});
8073

81-
export default deployContracts;
74+
await env.execute(cornToken, {
75+
functionName: "approve",
76+
args: [cornDEX.address, parseEther("1000000000")],
77+
account: deployer,
78+
});
79+
await env.execute(cornDEX, {
80+
functionName: "init",
81+
args: [parseEther("1000000000")],
82+
value: parseEther("1000000"),
83+
account: deployer,
84+
});
85+
}
86+
},
87+
{ tags: ["Lending"] },
88+
);

extension/packages/hardhat/test/Lending.ts

Lines changed: 21 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2,32 +2,41 @@
22
// This script executes when you run 'yarn test'
33
//
44

5-
import { ethers } from "hardhat";
5+
import { network } from "hardhat";
66
import { expect } from "chai";
7-
import { Corn, CornDEX, Lending } from "../typechain-types";
8-
import { SignerWithAddress } from "@nomicfoundation/hardhat-ethers/signers";
7+
import type { Corn, CornDEX, Lending } from "../types/ethers-contracts/index.js";
8+
import type { HardhatEthersSigner } from "@nomicfoundation/hardhat-ethers/types";
99

1010
describe("💳🌽 Over-collateralized Lending Challenge 🤓", function () {
11+
let ethers: Awaited<ReturnType<typeof network.create>>["ethers"];
12+
let provider: Awaited<ReturnType<typeof network.create>>["provider"];
13+
1114
const contractAddress = process.env.CONTRACT_ADDRESS;
1215
let cornToken: Corn;
1316
let cornDEX: CornDEX;
1417
let lending: Lending;
15-
let owner: SignerWithAddress;
16-
let user1: SignerWithAddress;
17-
let user2: SignerWithAddress;
18+
let owner: HardhatEthersSigner;
19+
let user1: HardhatEthersSigner;
20+
let user2: HardhatEthersSigner;
21+
22+
let collateralAmount: bigint;
23+
let borrowAmount: bigint;
1824

19-
const collateralAmount = ethers.parseEther("10");
20-
const borrowAmount = ethers.parseEther("5000");
25+
before(async function () {
26+
({ ethers, provider } = await network.create());
27+
collateralAmount = ethers.parseEther("10");
28+
borrowAmount = ethers.parseEther("5000");
29+
});
2130

2231
beforeEach(async function () {
23-
await ethers.provider.send("hardhat_reset", []);
32+
await provider.request({ method: "hardhat_reset", params: [] });
2433
[owner, user1, user2] = await ethers.getSigners();
2534

2635
const Corn = await ethers.getContractFactory("Corn");
27-
cornToken = await Corn.deploy();
36+
cornToken = (await Corn.deploy()) as unknown as Corn;
2837

2938
const CornDEX = await ethers.getContractFactory("CornDEX");
30-
cornDEX = await CornDEX.deploy(await cornToken.getAddress());
39+
cornDEX = (await CornDEX.deploy(await cornToken.getAddress())) as unknown as CornDEX;
3140

3241
await cornToken.mintTo(owner.address, ethers.parseEther("1000000"));
3342
await cornToken.approve(cornDEX.target, ethers.parseEther("1000000"));
@@ -42,7 +51,7 @@ describe("💳🌽 Over-collateralized Lending Challenge 🤓", function () {
4251
}
4352

4453
const Lending = await ethers.getContractFactory(contractArtifact);
45-
lending = (await Lending.deploy(cornDEX.target, cornToken.target)) as Lending;
54+
lending = (await Lending.deploy(cornDEX.target, cornToken.target)) as unknown as Lending;
4655
await cornToken.mintTo(lending.target, ethers.parseEther("10000000000000000000000"));
4756
});
4857

extension/packages/nextjs/next.config.ts.args.mjs

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,4 @@ export const configOverrides = {
22
typescript: {
33
ignoreBuildErrors: true,
44
},
5-
eslint: {
6-
ignoreDuringBuilds: true,
7-
},
85
};

0 commit comments

Comments
 (0)