Skip to content

Commit

Permalink
preparations for the menu (#8)
Browse files Browse the repository at this point in the history
* preparations for the menu

* dashboard and menu integration

* add options

* update menu script

* add baseURI for menu options

* add menu option to deploy only simple providers

* menu item option - add only collateral and refund provider

* refactor

* menu progression

* add LightMigrator to menu

* refactor

* add builders to menu

* add deploy all option

* add delayVaultProvider and migrator

* add ability to multiply selection
  • Loading branch information
YouStillAlive authored Dec 22, 2023
1 parent 4e375ac commit a04f5e2
Show file tree
Hide file tree
Showing 16 changed files with 1,598 additions and 857 deletions.
2,117 changes: 1,270 additions & 847 deletions package-lock.json

Large diffs are not rendered by default.

18 changes: 12 additions & 6 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
"main": "index.js",
"scripts": {
"test": "npx hardhat test",
"menu": "npx hardhat compile && .\\scripts\\separate-scripts.bat",
"testnet": "npx hardhat compile && npx ts-node ./scripts/testnet.ts"
},
"license": "ISC",
Expand All @@ -15,31 +16,36 @@
"@nomicfoundation/hardhat-toolbox": "^2.0.0",
"@nomiclabs/hardhat-ethers": "^2.2.1",
"@nomiclabs/hardhat-etherscan": "^3.1.2",
"@openzeppelin/contracts": "^4.8.3",
"@poolzfinance/poolz-helper-v2": "^2.2.1",
"@trivago/prettier-plugin-sort-imports": "^4.0.0",
"@truffle/dashboard-hardhat-plugin": "0.2.7",
"@typechain/ethers-v5": "^10.1.1",
"@typechain/hardhat": "^6.1.4",
"@types/chai": "^4.3.4",
"@types/fs-extra": "^9.0.13",
"@types/inquirer": "^9.0.7",
"@types/mocha": "^10.0.0",
"@types/node": "^18.11.9",
"@types/node": "^18.19.3",
"@typescript-eslint/eslint-plugin": "^5.44.0",
"@truffle/dashboard-hardhat-plugin": "0.2.7",
"@typescript-eslint/parser": "^5.44.0",
"chai": "^4.3.7",
"dotenv": "^16.3.1",
"ethers": "^5.7.2",
"fs-extra": "^10.1.0",
"hardhat": "^2.15.0",
"hardhat-gas-reporter": "^1.0.9",
"inquirer": "^7.3.3",
"lodash": "^4.17.21",
"mocha": "^10.1.0",
"rimraf": "^4.1.2",
"solidity-coverage": "^0.8.2",
"ts-generator": "^0.1.1",
"ts-node": "^10.9.1",
"typechain": "^8.1.1",
"typescript": "^4.9.3",
"dotenv": "^16.3.1",
"@openzeppelin/contracts": "^4.8.3",
"@poolzfinance/poolz-helper-v2": "^2.2.1"
"typescript": "^4.9.3"
},
"dependencies": {
"tsconfig-paths": "^4.2.0"
}
}
3 changes: 2 additions & 1 deletion scripts/deploy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,8 @@ async function deployAllContracts(baseURI: string = "") {
await deploy("SimpleRefundBuilder", lockDealNFT.address, refundProvider.address, collateralProvider.address)
}

const baseURI = ""
const baseURI = process.env.BASEURI || ""

deployAllContracts(baseURI).catch((error) => {
console.error(error)
process.exitCode = 1
Expand Down
2 changes: 2 additions & 0 deletions scripts/separate-scripts.bat
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
start cmd /k truffle dashboard
start cmd /k ts-node .\\scripts\\terminal.ts
71 changes: 71 additions & 0 deletions scripts/terminal.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
import { getMenu } from "./utility/deployment/input"
import {
deployVaultAndLockDealNFT,
deploySimpleProviders,
deployRefundProvider,
deployRefundAndCollateral,
deployBuilders,
deployAllContracts,
deployLightMigrator,
deployDelayProviderAndMigrator,
} from "./utility/deployment/execute"

const scriptPaths = [
"VaultAndLockDealNFT.ts",
"SimpleProviders.ts",
"RefundProvider.ts",
"RefundAndCollateral.ts",
"Builders.ts",
"LightMigrator.ts",
"DelayVaultProvider.ts",
]

const menuItems = [
{ name: "Deploy All contracts" },
...scriptPaths.map((script) => ({ name: `Deploy ${script.replace(".ts", "")}` })),
]

async function displayMenu() {
let keepMenuOpen = true

while (keepMenuOpen) {
try {
const answer = await getMenu(menuItems)

switch (answer) {
case "Deploy All contracts":
await deployAllContracts()
break
case menuItems[1].name:
await deployVaultAndLockDealNFT()
break
case menuItems[2].name:
await deploySimpleProviders()
break
case menuItems[3].name:
await deployRefundProvider()
break
case menuItems[4].name:
await deployRefundAndCollateral()
break
case menuItems[5].name:
await deployBuilders()
break
case menuItems[6].name:
await deployLightMigrator()
break
case menuItems[7].name:
await deployDelayProviderAndMigrator()
break
default:
// Exit the loop if an invalid option is selected
keepMenuOpen = false
break
}
} catch (error) {
console.error(`Error executing command: ${error}`)
}
}
}

displayMenu()
2 changes: 1 addition & 1 deletion scripts/utility/builders.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { Wallet } from "ethers"
import { gasLimit, gasPrice, amount } from "./constants"
import { SimpleBuilder, SimpleRefundBuilder, ERC20Token, VaultManager } from "../../typechain-types"
import { getSignature } from "./creation"
import { BuilderState } from "../../typechain-types/contracts/LockDealNFT/contracts/Builders/SimpleBuilder/SimpleBuilder"
import { BuilderState } from "../../typechain-types"
import { finishTime } from "./constants"

const sendData: BuilderState.BuilderStruct = {
Expand Down
16 changes: 16 additions & 0 deletions scripts/utility/deployment/Builders.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import { deploy } from "../deployment"

export async function deployBuilders(
lockDealNFT: string,
refundProvider: string,
collateralProvider: string
) {
await deploy("SimpleBuilder", lockDealNFT)
await deploy("SimpleRefundBuilder", lockDealNFT, refundProvider, collateralProvider)
}

const lockDealNFT = process.env.LOCK_DEAL_NFT_ADDRESS || ""
const refundProvider = process.env.REFUND_PROVIDER_ADDRESS || ""
const collateralProvider = process.env.COLLATERAL_PROVIDER_ADDRESS || ""

deployBuilders(lockDealNFT, refundProvider, collateralProvider)
15 changes: 15 additions & 0 deletions scripts/utility/deployment/DelayVaultProvider.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import { deploy, delayVaultSettings } from "../deployment"
import { DelayVaultMigrator } from "../../../typechain-types"
import { POOLX } from "../constants"

async function deployDelayProviderAndMigrator(lockDealNFT: string, v1DelayVault: string, lockProvider: string){
const migrator: DelayVaultMigrator = await deploy("DelayVaultMigrator", lockDealNFT, v1DelayVault)
await deploy("DelayVaultProvider", POOLX, migrator.address, delayVaultSettings(lockProvider))
}

// Retrieve environment variable
const lockDealNFT = process.env.LOCK_DEAL_NFT_ADDRESS || ""
const v1DelayVault = process.env.V1_DELAY_VAULT || ""
const lockProvider = process.env.LOCK_PROVIDER || ""

deployDelayProviderAndMigrator(lockDealNFT, v1DelayVault, lockProvider)
12 changes: 12 additions & 0 deletions scripts/utility/deployment/LightMigrator.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import { deploy } from "../deployment"

export async function deployLightMigrator(lockDealNFT: string, oldDelay: string, newDelay: string) {
await deploy("LightMigrator", lockDealNFT, oldDelay, newDelay)
}

// Retrieve environment variables
const lockDealNFT = process.env.LOCK_DEAL_NFT_ADDRESS || ""
const oldDelay = process.env.OLD_DELAY || ""
const newDelay = process.env.NEW_DELAY || ""

deployLightMigrator(lockDealNFT, oldDelay, newDelay)
14 changes: 14 additions & 0 deletions scripts/utility/deployment/RefundAndCollateral.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import { CollateralProvider } from "../../../typechain-types"
import { deploy } from "../deployment"
import { deployRefundProvider } from "./RefundProvider"

export async function deployRefundWithCollateral(lockDealNFT: string, provider: string) {
const collateralProvider: CollateralProvider = await deploy("CollateralProvider", lockDealNFT, provider)
await deployRefundProvider(lockDealNFT, collateralProvider.address)
}

// Retrieve environment variables
const lockDealNFT = process.env.LOCK_DEAL_NFT_ADDRESS || ""
const provider = process.env.PROVIDER_ADDRESS || ""

deployRefundWithCollateral(lockDealNFT, provider)
11 changes: 11 additions & 0 deletions scripts/utility/deployment/RefundProvider.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import { deploy } from "../deployment"

export async function deployRefundProvider(lockDealNFT: string, collateralProvider: string) {
await deploy("RefundProvider", lockDealNFT, collateralProvider)
}

// Retrieve environment variables
const lockDealNFT = process.env.LOCK_DEAL_NFT_ADDRESS || ""
const provider = process.env.COLLATERAL || ""

deployRefundProvider(lockDealNFT, provider)
14 changes: 14 additions & 0 deletions scripts/utility/deployment/SimpleProviders.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import { DealProvider, LockDealProvider } from "../../../typechain-types";
import { deploy } from "../deployment"

export async function deploySimpleProviders(lockDealNFT: string) {
const dealProvider: DealProvider = await deploy("DealProvider", lockDealNFT);
const lockProvider: LockDealProvider = await deploy("LockDealProvider", lockDealNFT, dealProvider.address);
await deploy("TimedDealProvider", lockDealNFT, lockProvider.address);

console.log("SimpleProviders deployed successfully!");
}

const lockDealNFTAddress = process.env.LOCK_DEAL_NFT_ADDRESS || "";

deploySimpleProviders(lockDealNFTAddress);
12 changes: 12 additions & 0 deletions scripts/utility/deployment/VaultAndLockDealNFT.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import { deploy } from "../deployment"
import { VaultManager } from "../../../typechain-types"

async function deployNFTandVaultManager(baseURI: string = "") {
const vaultManager: VaultManager = await deploy("VaultManager")
await deploy("LockDealNFT", vaultManager.address, baseURI)
}

// Retrieve environment variable
const baseURI = process.env.BASEURI || ""

deployNFTandVaultManager(baseURI)
71 changes: 71 additions & 0 deletions scripts/utility/deployment/execute.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
// scriptDeployer.js
import { exec } from "child_process";
import util from "util";
import {
getBaseURI,
getLockDealNFTAddress,
getCollateralProviderAddress,
getDealProviderAddress,
getLockProviderAddress,
getOldDelay,
getNewDelay,
getRefundProviderAddress,
} from "./input";

const execAsync = util.promisify(exec);

async function executeScript(scriptName: string, scriptPath: string) {
const network = "truffleDashboard";
const command = `npx hardhat run ${scriptPath} --network ${network}`;

await execAsync(command);
console.log(`Command executed successfully: Deploy ${scriptName}`);
}

export async function deployVaultAndLockDealNFT() {
process.env.BASEURI = await getBaseURI();
await executeScript("VaultAndLockDealNFT", "scripts/utility/deployment/VaultAndLockDealNFT.ts");
}

export async function deploySimpleProviders() {
process.env.LOCK_DEAL_NFT_ADDRESS = await getLockDealNFTAddress();
await executeScript("SimpleProviders", "scripts/utility/deployment/SimpleProviders.ts");
}

export async function deployRefundProvider() {
process.env.LOCK_DEAL_NFT_ADDRESS = await getLockDealNFTAddress();
process.env.COLLATERAL = await getCollateralProviderAddress();
await executeScript("RefundProvider", "scripts/utility/deployment/RefundProvider.ts");
}

export async function deployRefundAndCollateral() {
process.env.LOCK_DEAL_NFT_ADDRESS = await getLockDealNFTAddress();
process.env.PROVIDER_ADDRESS = await getDealProviderAddress();
await executeScript("RefundAndCollateral", "scripts/utility/deployment/RefundAndCollateral.ts");
}

export async function deployLightMigrator() {
process.env.LOCK_DEAL_NFT_ADDRESS = await getLockDealNFTAddress();
process.env.OLD_DELAY = await getOldDelay();
process.env.NEW_DELAY = await getNewDelay();
await executeScript("LightMigrator", "scripts/utility/deployment/LightMigrator.ts");
}

export async function deployBuilders() {
process.env.LOCK_DEAL_NFT_ADDRESS = await getLockDealNFTAddress();
process.env.REFUND_PROVIDER_ADDRESS = await getRefundProviderAddress();
process.env.COLLATERAL_PROVIDER_ADDRESS = await getCollateralProviderAddress();
await executeScript("Builders", "scripts/utility/deployment/Builders.ts");
}

export async function deployDelayProviderAndMigrator() {
process.env.LOCK_DEAL_NFT_ADDRESS = await getLockDealNFTAddress();
process.env.V1_DELAY_VAULT = await getOldDelay();
process.env.LOCK_PROVIDER = await getLockProviderAddress();
await executeScript("DelayProviderAndMigrator", "scripts/utility/deployment/DelayVaultProvider.ts");
}

export async function deployAllContracts() {
process.env.BASEURI = await getBaseURI();
await executeScript("AllContracts", "scripts/deploy.ts");
}
69 changes: 69 additions & 0 deletions scripts/utility/deployment/input.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
// inquirerPrompts.js
const inquirer = require("inquirer")

async function promptUser(
message: string,
name: string,
type = "input",
choices: { name: string }[] = [],
defaultValue = ""
) {
const answer = await inquirer.prompt([
{
type,
name,
message,
choices,
default: defaultValue,
},
])
return answer[name]
}

async function getBaseURI() {
return await promptUser("Enter the baseURI for NFT deployment:", "baseURI")
}

async function getLockDealNFTAddress() {
return await promptUser("Enter the LockDealNFT address for deployment:", "lockDealNFTAddress")
}

async function getDealProviderAddress() {
return await promptUser("Enter the Deal Provider address for deployment:", "providerAddress")
}

async function getLockProviderAddress() {
return await promptUser("Enter the Lock Provider address for deployment:", "providerAddress")
}

async function getCollateralProviderAddress() {
return await promptUser("Enter the Collateral Provider address for deployment:", "collateralProviderAddress")
}

async function getMenu(menuItems: { name: string }[]) {
return await promptUser("Choose a menu item:\n", "menuItem", "list", menuItems)
}

async function getOldDelay() {
return await promptUser("Enter the old delay address for deployment:", "oldDelay")
}

async function getNewDelay() {
return await promptUser("Enter the new delay address for deployment:", "newDelay")
}

async function getRefundProviderAddress() {
return await promptUser("Enter the Refund Provider address for deployment:", "refundProviderAddress")
}

export {
getBaseURI,
getLockDealNFTAddress,
getDealProviderAddress,
getLockProviderAddress,
getCollateralProviderAddress,
getMenu,
getOldDelay,
getNewDelay,
getRefundProviderAddress,
}
Loading

0 comments on commit a04f5e2

Please sign in to comment.