80 lines
2.4 KiB
JavaScript
80 lines
2.4 KiB
JavaScript
const hre = require("hardhat");
|
|
const fs = require("fs");
|
|
const path = require("path");
|
|
|
|
function requiredEnv(name) {
|
|
const value = process.env[name];
|
|
if (!value || !value.trim()) {
|
|
throw new Error(`Missing required env: ${name}`);
|
|
}
|
|
return value.trim();
|
|
}
|
|
|
|
function requireAddress(name, value, { allowZero = false } = {}) {
|
|
if (!hre.ethers.utils.isAddress(value)) {
|
|
throw new Error(`Invalid address for ${name}: ${value}`);
|
|
}
|
|
if (!allowZero && value === hre.ethers.constants.AddressZero) {
|
|
throw new Error(`${name} cannot be zero address`);
|
|
}
|
|
return value;
|
|
}
|
|
|
|
function parseUint(name, value) {
|
|
try {
|
|
const parsed = hre.ethers.BigNumber.from(value);
|
|
if (parsed.lt(0)) {
|
|
throw new Error("must be >= 0");
|
|
}
|
|
return parsed;
|
|
} catch (err) {
|
|
throw new Error(`Invalid uint for ${name}: ${value} (${err.message})`);
|
|
}
|
|
}
|
|
|
|
async function main() {
|
|
const treasury = requireAddress("TREASURY_WALLET", requiredEnv("TREASURY_WALLET"));
|
|
const mintCurrency = requireAddress(
|
|
"MINT_CURRENCY_ADDRESS",
|
|
(process.env.MINT_CURRENCY_ADDRESS || hre.ethers.constants.AddressZero).trim(),
|
|
{ allowZero: true },
|
|
);
|
|
const mintAmountAtomic = parseUint("MINT_AMOUNT_ATOMIC", requiredEnv("MINT_AMOUNT_ATOMIC"));
|
|
|
|
const [deployer] = await hre.ethers.getSigners();
|
|
console.log("deployer:", deployer.address);
|
|
console.log("network:", hre.network.name);
|
|
console.log("treasury:", treasury);
|
|
console.log("mint_currency:", mintCurrency);
|
|
console.log("mint_amount_atomic:", mintAmountAtomic);
|
|
|
|
const factory = await hre.ethers.getContractFactory("EdutHumanMembership");
|
|
const contract = await factory.deploy(treasury, mintCurrency, mintAmountAtomic);
|
|
await contract.deployed();
|
|
|
|
console.log("membership_contract:", contract.address);
|
|
|
|
const output = {
|
|
network: hre.network.name,
|
|
chainId: hre.network.config.chainId || null,
|
|
deployer: deployer.address,
|
|
treasury,
|
|
mintCurrency,
|
|
mintAmountAtomic: mintAmountAtomic.toString(),
|
|
membershipContract: contract.address,
|
|
txHash: contract.deployTransaction.hash,
|
|
};
|
|
const outputPath = (process.env.DEPLOY_OUTPUT_PATH || "").trim();
|
|
if (outputPath) {
|
|
const absolute = path.resolve(outputPath);
|
|
fs.mkdirSync(path.dirname(absolute), { recursive: true });
|
|
fs.writeFileSync(absolute, JSON.stringify(output, null, 2));
|
|
console.log("deployment_output:", absolute);
|
|
}
|
|
}
|
|
|
|
main().catch((err) => {
|
|
console.error(err);
|
|
process.exitCode = 1;
|
|
});
|