UNPKG

@vechain/vebetterdao-contracts

Version:

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

55 lines (54 loc) 2.25 kB
"use strict"; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); exports.getMigrationConfig = getMigrationConfig; exports.getX2EarnAppsContract = getX2EarnAppsContract; exports.getDataPath = getDataPath; exports.loadMigrationData = loadMigrationData; exports.validateMigrationData = validateMigrationData; exports.saveMigrationData = saveMigrationData; const config_1 = require("@repo/config"); const hardhat_1 = require("hardhat"); const path_1 = __importDefault(require("path")); const fs_1 = __importDefault(require("fs")); const DATA_DIR = path_1.default.join(__dirname, "data"); const DATA_FILE = path_1.default.join(DATA_DIR, "endorsements.json"); function getMigrationConfig() { const env = process.env.NEXT_PUBLIC_APP_ENV; if (!env) throw new Error("Missing NEXT_PUBLIC_APP_ENV"); return (0, config_1.getConfig)(env); } async function getX2EarnAppsContract() { const config = getMigrationConfig(); return hardhat_1.ethers.getContractAt("X2EarnApps", config.x2EarnAppsContractAddress); } function getDataPath() { return DATA_FILE; } function loadMigrationData() { if (!fs_1.default.existsSync(DATA_FILE)) { throw new Error(`Migration data not found at ${DATA_FILE}. Run 1_fetch.ts first.`); } const raw = fs_1.default.readFileSync(DATA_FILE, "utf-8"); return JSON.parse(raw); } function validateMigrationData(data) { const config = getMigrationConfig(); if (data.network !== config.network.name) { console.error(`Network mismatch: JSON="${data.network}", running on="${config.network.name}"`); process.exit(1); } if (data.x2EarnAppsAddress.toLowerCase() !== config.x2EarnAppsContractAddress.toLowerCase()) { console.error(`Contract address mismatch: JSON="${data.x2EarnAppsAddress}", config="${config.x2EarnAppsContractAddress}"`); process.exit(1); } } function saveMigrationData(data) { if (!fs_1.default.existsSync(DATA_DIR)) { fs_1.default.mkdirSync(DATA_DIR, { recursive: true }); } fs_1.default.writeFileSync(DATA_FILE, JSON.stringify(data, null, 2), "utf-8"); }