|
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"; |
5 | 3 | import * as fs from "fs"; |
| 4 | + |
6 | 5 | /** |
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. |
9 | 12 | * |
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. |
11 | 16 | */ |
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 |
51 | 39 | 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; |
58 | 43 | const yesToken = { address: i_yesToken, abi }; |
59 | 44 | const noToken = { address: i_noToken, abi }; |
60 | 45 |
|
61 | | - const chainDir = `./deployments/${hre.network.name}`; |
| 46 | + const chainDir = `./deployments/${env.name}`; |
62 | 47 | fs.writeFileSync(`${chainDir}/PredictionMarketTokenYes.json`, JSON.stringify(yesToken, null, 2)); |
63 | 48 | fs.writeFileSync(`${chainDir}/PredictionMarketTokenNo.json`, JSON.stringify(noToken, null, 2)); |
64 | 49 | console.log("Token JSON files written successfully"); |
65 | 50 | } catch (error) { |
66 | 51 | console.error("Error handling token files:", error); |
67 | 52 | } |
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 | +); |
0 commit comments