Skip to content

Commit 199bfec

Browse files
rin-stdamianmarti
andauthored
feat: prediction-markets migration to hh v3 (#460)
* feat: migration to hh v3 * fix: linting for raceeffects * Fix contract type on hardhat tests * feat: patch rocket/deploy * chore: bump create-eth 2.0.18 -> 2.0.20 * Revert "feat: patch rocket/deploy" This reverts commit adbbcc9. * Reapply "feat: patch rocket/deploy" This reverts commit 9b98638. --------- Co-authored-by: Damian <damianmarti@gmail.com>
1 parent 8987d21 commit 199bfec

7 files changed

Lines changed: 131 additions & 114 deletions

File tree

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ Before you begin, you need to install the following tools:
8080
Then download the challenge to your computer and install dependencies by running:
8181

8282
```sh
83-
npx create-eth@2.0.18 -e challenge-prediction-markets challenge-prediction-markets
83+
npx create-eth@2.0.20 -e challenge-prediction-markets challenge-prediction-markets
8484
cd challenge-prediction-markets
8585
```
8686

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
diff --git a/dist/index.js b/dist/index.js
2+
index 451d69f2199a28fbbc7084dae3371a736efb6b95..abaa582f7b2c2eed62dce66b2ac5861bd870c595 100644
3+
--- a/dist/index.js
4+
+++ b/dist/index.js
5+
@@ -259,7 +259,7 @@ export function deploy(env) {
6+
maxFeePerGas,
7+
maxPriorityFeePerGas,
8+
// gasPrice: viemArgs.gasPrice && `0x${viemArgs.gasPrice.toString(16)}` as `0x${string}`,
9+
- // value: `0x${viemArgs.value?.toString(16)}` as `0x${string}`,
10+
+ ...(viemArgs.value !== undefined && { value: `0x${viemArgs.value.toString(16)}` }),
11+
// nonce: viemArgs.nonce && (`0x${viemArgs.nonce.toString(16)}` as `0x${string}`),
12+
};
13+
let expectedAddress = undefined;
14+
diff --git a/src/index.ts b/src/index.ts
15+
index f86a31e2b13fb8208c14668e4994683af591d8bb..538145b931ba06cf9a45f85388fa89d73efa7e9c 100644
16+
--- a/src/index.ts
17+
+++ b/src/index.ts
18+
@@ -393,7 +393,7 @@ export function deploy(env: Environment): <TAbi extends Abi>(
19+
maxFeePerGas,
20+
maxPriorityFeePerGas,
21+
// gasPrice: viemArgs.gasPrice && `0x${viemArgs.gasPrice.toString(16)}` as `0x${string}`,
22+
- // value: `0x${viemArgs.value?.toString(16)}` as `0x${string}`,
23+
+ ...(viemArgs.value !== undefined && { value: `0x${viemArgs.value.toString(16)}` as `0x${string}` }),
24+
// nonce: viemArgs.nonce && (`0x${viemArgs.nonce.toString(16)}` as `0x${string}`),
25+
};
26+
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+
);
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{
2+
"devDependencies": {
3+
"@rocketh/deploy": "patch:@rocketh/deploy@npm%3A0.19.7#~/.yarn/patches/@rocketh-deploy-npm-0.19.7-80ebb5f207.patch"
4+
}
5+
}

0 commit comments

Comments
 (0)