Skip to content

Commit dd81dfb

Browse files
committed
feat: migration to hh v3
1 parent fbfabbc commit dd81dfb

3 files changed

Lines changed: 48 additions & 69 deletions

File tree

Lines changed: 43 additions & 63 deletions
Original file line numberDiff line numberDiff line change
@@ -1,77 +1,57 @@
1-
import { HardhatRuntimeEnvironment } from "hardhat/types";
2-
import { DeployFunction } from "hardhat-deploy/types";
3-
import { Contract } from "ethers";
4-
import { ethers } from "hardhat";
1+
import { artifacts, deployScript } from "../rocketh/deploy.js";
2+
import { parseEther } from "viem";
53
import * as fs from "fs";
4+
65
/**
7-
* Deploys a contract named "YourContract" using the deployer account and
8-
* constructor arguments set to the deployer address
6+
* Deploys a contract named "PredictionMarket" using the deployer account.
7+
*
8+
* On localhost, the deployer account is the one that comes with Hardhat, which is already funded.
9+
*
10+
* When deploying to live networks (e.g `yarn deploy --network sepolia`), the deployer account
11+
* should have sufficient balance to pay for the gas fees for contract creation.
912
*
10-
* @param hre HardhatRuntimeEnvironment object.
13+
* You can generate a random account with `yarn generate` or `yarn account:import` to import your
14+
* existing PK which will fill DEPLOYER_PRIVATE_KEY_ENCRYPTED in the .env file (used in hardhat.config.ts).
15+
* Run `yarn account` to check the deployer balance on every network.
1116
*/
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` or `yarn account:import` to import your
20-
existing PK which will fill DEPLOYER_PRIVATE_KEY_ENCRYPTED 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-
const question = "Will the green car win the race?";
27-
const initialLiquidity = ethers.parseEther("1");
28-
const initialTokenValue = ethers.parseEther("0.01");
29-
const initialProbability = 50;
30-
const percentageLocked = 10;
31-
const liquidityProvider = deployer;
32-
const oracle = deployer;
33-
34-
await deploy("PredictionMarket", {
35-
from: deployer,
36-
// Contract constructor arguments
37-
args: [liquidityProvider, oracle, question, initialTokenValue, initialProbability, percentageLocked],
38-
log: true,
39-
value: initialLiquidity.toString(),
40-
// autoMine: can be passed to the deploy function to make the deployment process faster on local networks by
41-
// automatically mining the contract deployment transaction. There is no effect on live networks.
42-
autoMine: true,
43-
});
44-
45-
// Get the deployed contract to interact with it after deploying.
46-
const predictionMarket = await hre.ethers.getContract<Contract>("PredictionMarket", deployer);
47-
console.log("PredictionMarket deployed to:", await predictionMarket.getAddress());
48-
49-
// Get the deployed contract's address and ABI for the YES and NO tokens and copy them to the deployments directory
50-
if (predictionMarket.i_yesToken && predictionMarket.i_noToken) {
17+
export default deployScript(
18+
async env => {
19+
const { deployer } = env.namedAccounts;
20+
21+
const question = "Will the green car win the race?";
22+
const initialLiquidity = parseEther("1");
23+
const initialTokenValue = parseEther("0.01");
24+
const initialProbability = 50;
25+
const percentageLocked = 10;
26+
const liquidityProvider = deployer;
27+
const oracle = deployer;
28+
29+
const predictionMarket = await env.deploy("PredictionMarket", {
30+
account: deployer,
31+
artifact: artifacts.PredictionMarket,
32+
args: [liquidityProvider, oracle, question, initialTokenValue, initialProbability, percentageLocked],
33+
value: initialLiquidity,
34+
});
35+
36+
console.log("PredictionMarket deployed to:", predictionMarket.address);
37+
38+
// Get the deployed contract's address and ABI for the YES and NO tokens and copy them to the deployments directory
5139
try {
52-
const { abi } = JSON.parse(
53-
fs.readFileSync("./artifacts/contracts/PredictionMarketToken.sol/PredictionMarketToken.json").toString(),
54-
);
55-
56-
const i_yesToken = await predictionMarket.i_yesToken();
57-
const i_noToken = await predictionMarket.i_noToken();
40+
const i_yesToken = (await env.read(predictionMarket, { functionName: "i_yesToken" })) as `0x${string}`;
41+
const i_noToken = (await env.read(predictionMarket, { functionName: "i_noToken" })) as `0x${string}`;
42+
const abi = artifacts.PredictionMarketToken.abi;
5843
const yesToken = { address: i_yesToken, abi };
5944
const noToken = { address: i_noToken, abi };
6045

61-
const chainDir = `./deployments/${hre.network.name}`;
46+
const chainDir = `./deployments/${env.name}`;
6247
fs.writeFileSync(`${chainDir}/PredictionMarketTokenYes.json`, JSON.stringify(yesToken, null, 2));
6348
fs.writeFileSync(`${chainDir}/PredictionMarketTokenNo.json`, JSON.stringify(noToken, null, 2));
6449
console.log("Token JSON files written successfully");
6550
} catch (error) {
6651
console.error("Error handling token files:", error);
6752
}
68-
} else {
69-
console.log("No Yes, No token contracts deployed yet");
70-
}
71-
};
72-
73-
export default deployYourContract;
74-
75-
// Tags are useful if you have multiple deploy files and only want to run one of them.
76-
// e.g. yarn deploy --tags YourContract
77-
deployYourContract.tags = ["PredictionMarket"];
53+
},
54+
// Tags are useful if you have multiple deploy files and only want to run one of them.
55+
// e.g. yarn deploy --tags PredictionMarket
56+
{ tags: ["PredictionMarket"] },
57+
);

extension/packages/hardhat/test/PredictionMarket.ts

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
import { expect } from "chai";
2-
import { ethers } from "hardhat";
3-
import { PredictionMarket } from "../typechain-types";
2+
import { network } from "hardhat";
3+
import type { PredictionMarket } from "../types/ethers-contracts/index.js";
44

55
describe("📈📉🏎️ Prediction Markets Challenge", function () {
66
// We define a fixture to reuse the same setup in every test.
77

8+
let ethers: Awaited<ReturnType<typeof network.create>>["ethers"];
89
let predictionMarket: PredictionMarket;
910
let owner: any;
1011
let oracle: any;
@@ -16,6 +17,7 @@ describe("📈📉🏎️ Prediction Markets Challenge", function () {
1617
contractArtifact = "contracts/PredictionMarket.sol:PredictionMarket";
1718
}
1819
before(async () => {
20+
({ ethers } = await network.create());
1921
[owner, oracle] = await ethers.getSigners();
2022
const predictionMarketFactory = await ethers.getContractFactory(contractArtifact);
2123
predictionMarket = (await predictionMarketFactory.deploy(
@@ -26,7 +28,7 @@ describe("📈📉🏎️ Prediction Markets Challenge", function () {
2628
50,
2729
20,
2830
{ value: ethers.parseEther("10") },
29-
)) as PredictionMarket;
31+
)) as unknown as PredictionMarket;
3032
await predictionMarket.waitForDeployment();
3133
});
3234

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)