diff --git a/scripts/terminal.ts b/scripts/terminal.ts index cd53ccc..8f1ff4f 100644 --- a/scripts/terminal.ts +++ b/scripts/terminal.ts @@ -31,7 +31,7 @@ const menuItems = [ ] // Map menu item names to deployment functions for cleaner handling -const deploymentActions: { [key: string]: () => Promise } = { +const deploymentActions: { [key: string]: () => Promise } = { "Deploy All contracts": deployAllContracts, "Deploy withoutRefund": deployWithoutRefund, "Deploy VaultAndLockDealNFT": deployVaultAndLockDealNFT, @@ -52,20 +52,22 @@ async function displayMenu() { const answer = await getMenu(menuItems) if (deploymentActions[answer]) { - await deploymentActions[answer]() - + // Capture the deployment addresses + const deploymentData = await deploymentActions[answer]() + //console.log("data", deploymentData) // Ask if the user wants to create an issue with deployment data const openIssue = await askYesNoQuestion("Do you want to open an issue with deployment data?") if (openIssue) { - await openAndSubmitGitHubIssue("test", "This is a test issue created by the deployment script") + // Prepare the issue body with the deployment data + const issueBody = `This issue is created by the deployment script. The following contracts were deployed successfully:\n\n${deploymentData.map((address: string) => `- ${address}`).join("\n")}` + await openAndSubmitGitHubIssue("test issue", issueBody) console.log("Issue created successfully.") } else { console.log("Issue creation skipped.") } } else { console.log("Exiting the menu. Thank you!") - keepMenuOpen = false } } catch (error) { console.error(`Error executing command: ${error}`) diff --git a/scripts/utility/deployment/deploy.ts b/scripts/utility/deployment/deploy.ts index 28b549a..b0e73b7 100644 --- a/scripts/utility/deployment/deploy.ts +++ b/scripts/utility/deployment/deploy.ts @@ -7,24 +7,35 @@ import { RefundProvider, VaultManager, SimpleBuilder, - SimpleRefundBuilder + SimpleRefundBuilder, } from "../../../typechain-types" import { deploy } from "../deployment" -async function deployAllContracts(baseURI: string = "") { +async function deployAllContracts(baseURI: string = ""): Promise { + const addresses: string[] = [] + const vaultManager: VaultManager = await deploy("VaultManager") + addresses.push("VaultManager address: " + vaultManager.address) // Deploy LockDealNFT contract const lockDealNFT: LockDealNFT = await deploy("LockDealNFT", vaultManager.address, baseURI) + addresses.push("lockDealNFT address: " + lockDealNFT.address) // Deploy DealProvider contract const dealProvider: DealProvider = await deploy("DealProvider", lockDealNFT.address) + addresses.push("dealProvider address: " + dealProvider.address) // Deploy LockDealProvider contract const lockProvider: LockDealProvider = await deploy("LockDealProvider", lockDealNFT.address, dealProvider.address) + addresses.push("LockDealProvider address:" + lockProvider.address) // Deploy TimedDealProvider contract - const timedDealProvider: TimedDealProvider = await deploy("TimedDealProvider", lockDealNFT.address, lockProvider.address) + const timedDealProvider: TimedDealProvider = await deploy( + "TimedDealProvider", + lockDealNFT.address, + lockProvider.address + ) + addresses.push("TimedDealProvider address: " + timedDealProvider.address) // Deploy CollateralProvider contract const collateralProvider: CollateralProvider = await deploy( @@ -32,6 +43,7 @@ async function deployAllContracts(baseURI: string = "") { lockDealNFT.address, dealProvider.address ) + addresses.push("CollateralProvider address: " + collateralProvider.address) // Deploy RefundProvider contract const refundProvider: RefundProvider = await deploy( @@ -39,22 +51,25 @@ async function deployAllContracts(baseURI: string = "") { lockDealNFT.address, collateralProvider.address ) + addresses.push("RefundProvider address: " + refundProvider.address) - // Deploy Buiders + // Deploy Builders const simpleBuilder: SimpleBuilder = await deploy("SimpleBuilder", lockDealNFT.address) - const simpleRefundBuilder: SimpleRefundBuilder = await deploy("SimpleRefundBuilder", lockDealNFT.address, refundProvider.address, collateralProvider.address) - + addresses.push("SimpleBuilder address: " + simpleBuilder.address) + + const simpleRefundBuilder: SimpleRefundBuilder = await deploy( + "SimpleRefundBuilder", + lockDealNFT.address, + refundProvider.address, + collateralProvider.address + ) + addresses.push("SimpleRefundBuilder address: " + simpleRefundBuilder.address) + let tx = await vaultManager.setTrustee(lockDealNFT.address) await tx.wait() - await setApprovedContracts(lockDealNFT, [ - dealProvider.address, - lockProvider.address, - timedDealProvider.address, - collateralProvider.address, - refundProvider.address, - simpleBuilder.address, - simpleRefundBuilder.address, - ]) + await setApprovedContracts(lockDealNFT, addresses) + + return addresses // Return the array of deployed addresses } const baseURI = process.env.BASEURI || "" diff --git a/scripts/utility/deployment/execute.ts b/scripts/utility/deployment/execute.ts index 6d74cbd..8a877c5 100644 --- a/scripts/utility/deployment/execute.ts +++ b/scripts/utility/deployment/execute.ts @@ -14,63 +14,72 @@ import util from "util" const execAsync = util.promisify(exec) -async function executeScript(scriptName: string, scriptPath: string) { +async function executeScript(scriptName: string, scriptPath: string): Promise { const network = "truffleDashboard" const command = `npx hardhat run ${scriptPath} --network ${network}` - await execAsync(command) - console.log(`Command executed successfully: Deploy ${scriptName}`) + try { + const { stdout } = await execAsync(command) + console.log(`Command executed successfully: Deploy ${scriptName}`) + return stdout + } catch (error) { + console.error(`Error executing script ${scriptName}:`, error) + return "" + } } -export async function deployVaultAndLockDealNFT() { +export async function deployVaultAndLockDealNFT() : Promise { process.env.BASEURI = await getBaseURI() - await executeScript("VaultAndLockDealNFT", "scripts/utility/deployment/VaultAndLockDealNFT.ts") + return await executeScript("VaultAndLockDealNFT", "scripts/utility/deployment/VaultAndLockDealNFT.ts") } -export async function deploySimpleProviders() { +export async function deploySimpleProviders() : Promise { process.env.LOCK_DEAL_NFT_ADDRESS = await getLockDealNFTAddress() - await executeScript("SimpleProviders", "scripts/utility/deployment/SimpleProviders.ts") + return await executeScript("SimpleProviders", "scripts/utility/deployment/SimpleProviders.ts") } -export async function deployRefundProvider() { +export async function deployRefundProvider() : Promise{ process.env.LOCK_DEAL_NFT_ADDRESS = await getLockDealNFTAddress() process.env.COLLATERAL = await getCollateralProviderAddress() - await executeScript("RefundProvider", "scripts/utility/deployment/RefundProvider.ts") + return await executeScript("RefundProvider", "scripts/utility/deployment/RefundProvider.ts") } -export async function deployRefundAndCollateral() { +export async function deployRefundAndCollateral() : Promise{ process.env.LOCK_DEAL_NFT_ADDRESS = await getLockDealNFTAddress() process.env.PROVIDER_ADDRESS = await getDealProviderAddress() - await executeScript("RefundAndCollateral", "scripts/utility/deployment/RefundAndCollateral.ts") + return await executeScript("RefundAndCollateral", "scripts/utility/deployment/RefundAndCollateral.ts") } -export async function deployLightMigrator() { +export async function deployLightMigrator() : Promise{ 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") + return await executeScript("LightMigrator", "scripts/utility/deployment/LightMigrator.ts") } -export async function deployBuilders() { +export async function deployBuilders() : Promise{ 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") + return await executeScript("Builders", "scripts/utility/deployment/Builders.ts") } -export async function deployDelayProviderAndMigrator() { +export async function deployDelayProviderAndMigrator() : Promise { 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") + return await executeScript( + "DelayProviderAndMigrator", + "scripts/utility/deployment/DelayVaultProvider.ts" + ) } -export async function deployAllContracts() { +export async function deployAllContracts() : Promise{ process.env.BASEURI = await getBaseURI() - await executeScript("AllContracts", "scripts/utility/deployment/deploy.ts") + return await executeScript("AllContracts", "scripts/utility/deployment/deploy.ts") } -export async function deployWithoutRefund() { +export async function deployWithoutRefund() : Promise{ process.env.BASEURI = await getBaseURI() - await executeScript("deploy core contracts without Refund", "scripts/withoutRefund.ts") + return await executeScript("deploy core contracts without Refund", "scripts/withoutRefund.ts") }