UNPKG

@vechain/vebetterdao-contracts

Version:

Open-source repository that houses the smart contracts powering the decentralized VeBetterDAO on the VeChain Thor blockchain.

50 lines (49 loc) 2.33 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.checkContractsDeployment = checkContractsDeployment; const hardhat_1 = require("hardhat"); const config_1 = require("@repo/config"); const contracts_1 = require("@repo/config/contracts"); const deployAll_1 = require("./deploy/deployAll"); const devStack_1 = require("./helpers/devStack"); const config = (0, config_1.getConfig)(); const env = config.environment; if (!env) throw new Error("NEXT_PUBLIC_APP_ENV env variable must be set"); const isTestnetEnv = process.env.NEXT_PUBLIC_APP_ENV === contracts_1.AppEnv.TESTNET; async function main() { console.log(`Checking contracts deployment on ${hardhat_1.network.name} (${config.network.urls[0]})...`); await checkContractsDeployment(); process.exit(0); } // Source of truth for the "is deployed?" question is the address in // packages/config/<env>.ts. If the on-chain bytecode at that address is empty, // redeploy and rewrite the config. The shared dev-stack registration is only // touched when SKIP_DEV_STACK_REGISTER is unset (i.e. from `dev:up`/`dev:deploy`), // so a redeploy triggered by `dev:local` updates only local.ts and leaves // the shared indexer/explorer registration alone. async function checkContractsDeployment() { const code = config.b3trContractAddress === "" ? "0x" : await hardhat_1.ethers.provider.getCode(config.b3trContractAddress); if (code !== "0x") { console.log(`B3tr contract already deployed`); return; } console.log(`B3tr contract not deployed at address ${config.b3trContractAddress} deploying...`); if (env === contracts_1.AppEnv.LOCAL) { const newAddresses = await (0, deployAll_1.deployAll)((0, config_1.getContractsConfig)(env)); const finalConfig = await (0, devStack_1.overrideLocalConfigWithNewContracts)(newAddresses); await (0, devStack_1.registerWithDevStack)(finalConfig); return; } if (isTestnetEnv) { const newAddresses = await (0, deployAll_1.deployAll)((0, config_1.getContractsConfig)(env)); await (0, devStack_1.overrideLocalConfigWithNewContracts)(newAddresses); } else { console.log(`Skipping deployment on ${hardhat_1.network.name}`); } } main().catch(error => { console.error(error); process.exit(1); });