|
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"; |
4 | 3 |
|
5 | 4 | /** |
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. |
8 | 6 | * |
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. |
10 | 15 | */ |
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; |
24 | 19 |
|
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 | + }); |
35 | 25 |
|
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 | + }); |
49 | 31 |
|
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 | + }); |
57 | 37 |
|
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 | + }); |
75 | 44 |
|
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 | + }); |
80 | 73 |
|
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 | +); |
0 commit comments