|
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 "Vendor" using the deployer account and |
7 | | - * constructor arguments set to the deployer address |
| 5 | + * Deploys a contract named "Vendor" 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` which will fill DEPLOYER_PRIVATE_KEY_ENCRYPTED |
| 13 | + * 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 deployVendor: DeployFunction = async function (hre: HardhatRuntimeEnvironment) { |
12 | | - /* |
13 | | - On localhost, the deployer account is the one that comes with Hardhat, which is already funded. |
| 16 | +export default deployScript( |
| 17 | + async env => { |
| 18 | + const { deployer } = env.namedAccounts; |
| 19 | + const yourToken = env.get<typeof artifacts.YourToken.abi>("YourToken"); |
14 | 20 |
|
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. |
| 21 | + /** |
| 22 | + * Student TODO: |
| 23 | + * - Put the address you're using in the frontend here (leave "" to default to the deployer) |
| 24 | + */ |
| 25 | + const FRONTEND_ADDRESS = ""; |
17 | 26 |
|
18 | | - You can generate a random account with `yarn generate` which will fill DEPLOYER_PRIVATE_KEY |
19 | | - with a random private key 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; |
24 | | - const yourToken = await hre.ethers.getContract<Contract>("YourToken", deployer); |
| 27 | + /** |
| 28 | + * Mode switch: |
| 29 | + * - If true: deploy Vendor and seed it with the token balance |
| 30 | + * - If false: send tokens to your frontend address (or deployer if unset) |
| 31 | + */ |
| 32 | + const SEND_TOKENS_TO_VENDOR = false; // Don't switch until Checkpoint 2! |
25 | 33 |
|
26 | | - /** |
27 | | - * Student TODO: |
28 | | - * - Put the address you’re using in the frontend here (leave "" to default to the deployer) |
29 | | - */ |
30 | | - const FRONTEND_ADDRESS: string = ""; |
| 34 | + const recipientAddress = |
| 35 | + FRONTEND_ADDRESS && FRONTEND_ADDRESS.trim().length > 0 ? (FRONTEND_ADDRESS as `0x${string}`) : deployer; |
31 | 36 |
|
32 | | - /** |
33 | | - * Mode switch: |
34 | | - * - If true: deploy Vendor and seed it with the token balance |
35 | | - * - If false: send tokens to your frontend address (or deployer if unset) |
36 | | - */ |
37 | | - const SEND_TOKENS_TO_VENDOR = false; // Don't switch until Checkpoint 2! |
| 37 | + if (!SEND_TOKENS_TO_VENDOR) { |
| 38 | + // Send the entire initial supply to the wallet you use in the UI (useful when deployer != UI wallet). |
| 39 | + // If FRONTEND_ADDRESS is "", this defaults to the deployer (no-op transfer). |
| 40 | + if (recipientAddress !== deployer) { |
| 41 | + await env.execute(yourToken, { |
| 42 | + functionName: "transfer", |
| 43 | + args: [recipientAddress, parseEther("1000")], |
| 44 | + account: deployer, |
| 45 | + }); |
| 46 | + } |
| 47 | + return; |
| 48 | + } else { |
| 49 | + // Deploy Vendor |
| 50 | + const vendor = await env.deploy("Vendor", { |
| 51 | + account: deployer, |
| 52 | + artifact: artifacts.Vendor, |
| 53 | + args: [yourToken.address], |
| 54 | + }); |
38 | 55 |
|
39 | | - const recipientAddress = FRONTEND_ADDRESS && FRONTEND_ADDRESS.trim().length > 0 ? FRONTEND_ADDRESS : deployer; |
| 56 | + // Transfer tokens to Vendor (seed inventory) |
| 57 | + await env.execute(yourToken, { |
| 58 | + functionName: "transfer", |
| 59 | + args: [vendor.address, parseEther("1000")], |
| 60 | + account: deployer, |
| 61 | + }); |
40 | 62 |
|
41 | | - if (!SEND_TOKENS_TO_VENDOR) { |
42 | | - // Send the entire initial supply to the wallet you use in the UI (useful when deployer != UI wallet). |
43 | | - // If FRONTEND_ADDRESS is "", this defaults to the deployer (no-op transfer). |
44 | | - if (recipientAddress != deployer) { |
45 | | - await yourToken.transfer(recipientAddress, hre.ethers.parseEther("1000")); |
| 63 | + // Make the UI wallet the owner (for withdraw(), etc). Defaults to deployer if unset. |
| 64 | + await env.execute(vendor, { |
| 65 | + functionName: "transferOwnership", |
| 66 | + args: [recipientAddress], |
| 67 | + account: deployer, |
| 68 | + }); |
46 | 69 | } |
47 | | - return; |
48 | | - } else { |
49 | | - // Deploy Vendor |
50 | | - const yourTokenAddress = await yourToken.getAddress(); |
51 | | - await deploy("Vendor", { |
52 | | - from: deployer, |
53 | | - // Contract constructor arguments |
54 | | - args: [yourTokenAddress], |
55 | | - log: true, |
56 | | - // autoMine: can be passed to the deploy function to make the deployment process faster on local networks by |
57 | | - // automatically mining the contract deployment transaction. There is no effect on live networks. |
58 | | - autoMine: true, |
59 | | - }); |
60 | | - const vendor = await hre.ethers.getContract<Contract>("Vendor", deployer); |
61 | | - const vendorAddress = await vendor.getAddress(); |
62 | | - |
63 | | - // Transfer tokens to Vendor (seed inventory) |
64 | | - await yourToken.transfer(vendorAddress, hre.ethers.parseEther("1000")); |
65 | | - |
66 | | - // Make the UI wallet the owner (for withdraw(), etc). Defaults to deployer if unset. |
67 | | - await vendor.transferOwnership(recipientAddress); |
68 | | - } |
69 | | -}; |
70 | | - |
71 | | -export default deployVendor; |
72 | | - |
73 | | -// Tags are useful if you have multiple deploy files and only want to run one of them. |
74 | | -// e.g. yarn deploy --tags Vendor |
75 | | -deployVendor.tags = ["Vendor"]; |
| 70 | + }, |
| 71 | + // Tags are useful if you have multiple deploy files and only want to run one of them. |
| 72 | + // e.g. yarn deploy --tags Vendor |
| 73 | + { tags: ["Vendor"] }, |
| 74 | +); |
0 commit comments