Skip to content

Commit

Permalink
get deployment data
Browse files Browse the repository at this point in the history
  • Loading branch information
YouStillAlive committed Oct 10, 2024
1 parent 232d77c commit e84e6b8
Show file tree
Hide file tree
Showing 3 changed files with 67 additions and 41 deletions.
12 changes: 7 additions & 5 deletions scripts/terminal.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ const menuItems = [
]

// Map menu item names to deployment functions for cleaner handling
const deploymentActions: { [key: string]: () => Promise<void> } = {
const deploymentActions: { [key: string]: () => Promise<any> } = {
"Deploy All contracts": deployAllContracts,
"Deploy withoutRefund": deployWithoutRefund,
"Deploy VaultAndLockDealNFT": deployVaultAndLockDealNFT,
Expand All @@ -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}`)
Expand Down
45 changes: 30 additions & 15 deletions scripts/utility/deployment/deploy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,54 +7,69 @@ import {
RefundProvider,
VaultManager,
SimpleBuilder,
SimpleRefundBuilder
SimpleRefundBuilder,
} from "../../../typechain-types"
import { deploy } from "../deployment"

async function deployAllContracts(baseURI: string = "") {
async function deployAllContracts(baseURI: string = ""): Promise<string[]> {
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(
"CollateralProvider",
lockDealNFT.address,
dealProvider.address
)
addresses.push("CollateralProvider address: " + collateralProvider.address)

// Deploy RefundProvider contract
const refundProvider: RefundProvider = await deploy(
"RefundProvider",
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 || ""
Expand Down
51 changes: 30 additions & 21 deletions scripts/utility/deployment/execute.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<string> {
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<string> {
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<string> {
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<string>{
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<string>{
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<string>{
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<string>{
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<string> {
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<string>{
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<string>{
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")
}

0 comments on commit e84e6b8

Please sign in to comment.