Skip to content

Commit 2760d9c

Browse files
committed
feat: migration to hh v3
1 parent d7d1d47 commit 2760d9c

3 files changed

Lines changed: 50 additions & 75 deletions

File tree

Lines changed: 39 additions & 67 deletions
Original file line numberDiff line numberDiff line change
@@ -1,71 +1,43 @@
1-
import { HardhatRuntimeEnvironment } from "hardhat/types";
2-
import { DeployFunction } from "hardhat-deploy/types";
3-
import { DEX } from "../typechain-types/contracts/DEX";
4-
import { Balloons } from "../typechain-types/contracts/Balloons";
1+
import { artifacts, deployScript } from "../rocketh/deploy.js";
52

63
/**
7-
* Deploys a contract named "YourContract" using the deployer account and
8-
* constructor arguments set to the deployer address
4+
* Deploys "Balloons" and "DEX".
95
*
10-
* @param hre HardhatRuntimeEnvironment object.
6+
* On localhost, the deployer account is the one that comes with Hardhat, which is already funded.
7+
*
8+
* When deploying to live networks (e.g `yarn deploy --network sepolia`), the deployer account
9+
* should have sufficient balance to pay for the gas fees for contract creation.
10+
*
11+
* You can generate a random account with `yarn generate` which will fill DEPLOYER_PRIVATE_KEY_ENCRYPTED
12+
* in the .env file (used in hardhat.config.ts).
13+
* Run `yarn account` to check the deployer balance on every network.
1114
*/
12-
const deployYourContract: DeployFunction = async function (hre: HardhatRuntimeEnvironment) {
13-
/*
14-
On localhost, the deployer account is the one that comes with Hardhat, which is already funded.
15-
16-
When deploying to live networks (e.g `yarn deploy --network sepolia`), the deployer account
17-
should have sufficient balance to pay for the gas fees for contract creation.
18-
19-
You can generate a random account with `yarn generate` which will fill DEPLOYER_PRIVATE_KEY
20-
with a random private key in the .env file (then used on hardhat.config.ts)
21-
You can run the `yarn account` command to check your balance in every network.
22-
*/
23-
const { deployer } = await hre.getNamedAccounts();
24-
const { deploy } = hre.deployments;
25-
26-
await deploy("Balloons", {
27-
from: deployer,
28-
// Contract constructor arguments
29-
//args: [deployer],
30-
log: true,
31-
// autoMine: can be passed to the deploy function to make the deployment process faster on local networks by
32-
// automatically mining the contract deployment transaction. There is no effect on live networks.
33-
autoMine: true,
34-
});
35-
// Get the deployed contract
36-
// const yourContract = await hre.ethers.getContract("YourContract", deployer);
37-
const balloons: Balloons = await hre.ethers.getContract("Balloons", deployer);
38-
const balloonsAddress = await balloons.getAddress();
39-
40-
await deploy("DEX", {
41-
from: deployer,
42-
// Contract constructor arguments
43-
args: [balloonsAddress],
44-
log: true,
45-
// autoMine: can be passed to the deploy function to make the deployment process faster on local networks by
46-
// automatically mining the contract deployment transaction. There is no effect on live networks.
47-
autoMine: true,
48-
});
49-
50-
const dex = (await hre.ethers.getContract("DEX", deployer)) as DEX;
51-
52-
// // CHECKPOINT 2: Paste in your front-end address here to get 10 balloons on deploy:
53-
// await balloons.transfer("YOUR_FRONTEND_ADDRESS", "" + 10 * 10 ** 18);
54-
55-
// // CHECKPOINT 3: Uncomment to init DEX on deploy:
56-
// const dexAddress = await dex.getAddress();
57-
// console.log("Approving DEX (" + dexAddress + ") to take Balloons from main account...");
58-
// // If you are going to the testnet make sure your deployer account has enough ETH
59-
// await balloons.approve(dexAddress, hre.ethers.parseEther("100"));
60-
// console.log("INIT exchange...");
61-
// await dex.init(hre.ethers.parseEther("5"), {
62-
// value: hre.ethers.parseEther("5"),
63-
// gasLimit: 200000,
64-
// });
65-
};
66-
67-
export default deployYourContract;
68-
69-
// Tags are useful if you have multiple deploy files and only want to run one of them.
70-
// e.g. yarn deploy --tags YourContract
71-
deployYourContract.tags = ["Balloons", "DEX"];
15+
export default deployScript(
16+
async ({ deploy, namedAccounts }) => {
17+
const { deployer } = namedAccounts;
18+
19+
const balloons = await deploy("Balloons", {
20+
account: deployer,
21+
artifact: artifacts.Balloons,
22+
args: [],
23+
});
24+
25+
await deploy("DEX", {
26+
account: deployer,
27+
artifact: artifacts.DEX,
28+
args: [balloons.address],
29+
});
30+
31+
// // CHECKPOINT 2: Paste in your front-end address here to get 10 balloons on deploy:
32+
// await execute(balloons, { functionName: "transfer", args: ["YOUR_FRONTEND_ADDRESS", parseEther("10")], account: deployer });
33+
34+
// // CHECKPOINT 3: Uncomment to init DEX on deploy:
35+
// console.log("Approving DEX (" + dex.address + ") to take Balloons from main account...");
36+
// await execute(balloons, { functionName: "approve", args: [dex.address, parseEther("100")], account: deployer });
37+
// console.log("INIT exchange...");
38+
// await execute(dex, { functionName: "init", args: [parseEther("5")], value: parseEther("5"), account: deployer });
39+
},
40+
// Tags are useful if you have multiple deploy files and only want to run one of them.
41+
// e.g. yarn deploy --tags DEX
42+
{ tags: ["Balloons", "DEX"] },
43+
);

extension/packages/hardhat/test/DEX.ts

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,18 @@
88
// yarn test --grep "Checkpoint5"
99
//
1010

11-
import { ethers } from "hardhat";
11+
import { network } from "hardhat";
1212
import { expect } from "chai";
13-
import { anyValue } from "@nomicfoundation/hardhat-chai-matchers/withArgs";
14-
import { Balloons, DEX } from "../typechain-types";
13+
import { anyValue } from "@nomicfoundation/hardhat-ethers-chai-matchers/withArgs";
14+
import type { Balloons, DEX } from "../types/ethers-contracts/index.js";
1515

1616
describe("🚩 Challenge: ⚖️ 🪙 DEX", function () {
17+
let ethers: Awaited<ReturnType<typeof network.create>>["ethers"];
18+
19+
before(async function () {
20+
({ ethers } = await network.create());
21+
});
22+
1723
const contractAddress = process.env.CONTRACT_ADDRESS;
1824
const getDexArtifact = () => {
1925
if (contractAddress) return `contracts/download-${contractAddress}.sol:DEX`;
@@ -24,11 +30,11 @@ describe("🚩 Challenge: ⚖️ 🪙 DEX", function () {
2430
const [deployer, user2, user3] = await ethers.getSigners();
2531

2632
const BalloonsFactory = await ethers.getContractFactory("Balloons");
27-
const balloons = (await BalloonsFactory.deploy()) as Balloons;
33+
const balloons = (await BalloonsFactory.deploy()) as unknown as Balloons;
2834
await balloons.waitForDeployment();
2935

3036
const DexFactory = await ethers.getContractFactory(getDexArtifact());
31-
const dex = (await DexFactory.deploy(await balloons.getAddress())) as DEX;
37+
const dex = (await DexFactory.deploy(await balloons.getAddress())) as unknown as DEX;
3238
await dex.waitForDeployment();
3339

3440
return {

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)