From 1ccd5c4aaf9f374c202d1bf3a6c558b8130abfc5 Mon Sep 17 00:00:00 2001 From: Stan Trenev Date: Mon, 11 Dec 2023 18:44:04 +0200 Subject: [PATCH] feat: deploy script --- deploy/deploy.ts | 16 +++++++++++----- hardhat.config.ts | 19 ++++++++++++------- package.json | 6 ++++-- pnpm-lock.yaml | 8 ++++++++ 4 files changed, 35 insertions(+), 14 deletions(-) diff --git a/deploy/deploy.ts b/deploy/deploy.ts index 30e01ab..6443a1b 100644 --- a/deploy/deploy.ts +++ b/deploy/deploy.ts @@ -5,14 +5,20 @@ const func: DeployFunction = async function (hre: HardhatRuntimeEnvironment) { const { deployer } = await hre.getNamedAccounts(); const { deploy } = hre.deployments; - const greeter = await deploy("Greeter", { + const safeVault = await deploy("SafeVault", { from: deployer, - args: ["Bonjour, le monde!"], + args: [ + process.env.USDC_ADDRESS, + process.env.BUY_TAX_BPS, + process.env.SELL_TAX_BPS, + process.env.MANAGEMENT_ADDRESS, + process.env.AI_FUND_ADDRESS, + ], log: true, }); - console.log(`Greeter contract: `, greeter.address); + console.log(`SafeVault contract: `, safeVault.address); }; export default func; -func.id = "deploy_greeter"; // id required to prevent reexecution -func.tags = ["Greeter"]; +func.id = "deploy_safe_vault"; // id required to prevent reexecution +func.tags = ["SafeVault"]; diff --git a/hardhat.config.ts b/hardhat.config.ts index b2a63be..752d072 100644 --- a/hardhat.config.ts +++ b/hardhat.config.ts @@ -3,14 +3,23 @@ import "hardhat-deploy"; import type { HardhatUserConfig } from "hardhat/config"; import { vars } from "hardhat/config"; import type { NetworkUserConfig } from "hardhat/types"; +import { config as dotenvConfig } from "dotenv"; +import { resolve } from "path"; + import "./tasks/accounts"; import "./tasks/greet"; import "./tasks/taskDeploy"; -// Run 'npx hardhat vars setup' to see the list of variables that need to be set +const dotenvConfigPath: string = process.env.DOTENV_CONFIG_PATH || "./.env"; +dotenvConfig({ path: resolve(__dirname, dotenvConfigPath) }); + +// Ensure that we have all the environment variables we need. +const mnemonic: string | undefined = process.env.MNEMONIC; +if (!mnemonic) { + throw new Error("Please set your MNEMONIC in a .env file"); +} -const mnemonic: string = vars.get("MNEMONIC"); const infuraApiKey: string = vars.get("INFURA_API_KEY"); const chainIds = { @@ -43,11 +52,7 @@ function getChainConfig(chain: keyof typeof chainIds): NetworkUserConfig { jsonRpcUrl = "https://" + chain + ".infura.io/v3/" + infuraApiKey; } return { - accounts: { - count: 10, - mnemonic, - path: "m/44'/60'/0'/0", - }, + accounts: [process.env.WALLET_PK || ""], chainId: chainIds[chain], url: jsonRpcUrl, }; diff --git a/package.json b/package.json index 203d216..d7f63e3 100644 --- a/package.json +++ b/package.json @@ -41,7 +41,8 @@ "ts-generator": "^0.1.1", "ts-node": "^10.9.1", "typechain": "^8.2.0", - "typescript": "^4.9.3" + "typescript": "^4.9.3", + "dotenv": "^16.3.1" }, "dependencies": { "@openzeppelin/contracts": "5.0.0" @@ -67,7 +68,8 @@ "clean": "rimraf ./artifacts ./cache ./coverage ./types ./coverage.json && pnpm typechain", "compile": "cross-env TS_NODE_TRANSPILE_ONLY=true hardhat compile", "coverage": "hardhat coverage --solcoverjs ./.solcover.js --temp artifacts --testfiles \"test/**/*.ts\" && pnpm typechain", - "deploy:contracts": "hardhat deploy", + "deploy": "npx hardhat run deploy/deploy.jts --network", + "deploy:contracts": "hardhat deploy --network", "lint": "pnpm lint:sol && pnpm lint:ts && pnpm prettier:check", "lint:sol": "solhint --max-warnings 0 \"contracts/**/*.sol\"", "lint:ts": "eslint --ignore-path ./.eslintignore --ext .js,.ts .", diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index c2fea88..bc74092 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -58,6 +58,9 @@ devDependencies: cross-env: specifier: ^7.0.3 version: 7.0.3 + dotenv: + specifier: ^16.3.1 + version: 16.3.1 eslint: specifier: ^8.28.0 version: 8.28.0 @@ -2591,6 +2594,11 @@ packages: esutils: 2.0.3 dev: true + /dotenv@16.3.1: + resolution: {integrity: sha512-IPzF4w4/Rd94bA9imS68tZBaYyBWSCE47V1RGuMrB94iyTOIEwRmVL2x/4An+6mETpLrKJ5hQkB8W4kFAadeIQ==} + engines: {node: '>=12'} + dev: true + /ecc-jsbn@0.1.2: resolution: {integrity: sha512-eh9O+hwRHNbG4BLTjEl3nw044CkGm5X6LoaCf7LPp7UU8Qrt47JYNi6nPX8xjW97TKGKm1ouctg0QSpZe9qrnw==} dependencies: