69 lines
2.0 KiB
TypeScript
69 lines
2.0 KiB
TypeScript
|
|
import { read, write } from "fs-jetpack";
|
|
|
|
export const updateArray = ({ name, type, json, address, network }: { name: string, type: string, json: string, address: string, network: string }) => {
|
|
let env = process.env.NODE_ENV || "dev";
|
|
const filename = `./out/${network}_${env}.json`;
|
|
let cfgs = read(filename, "json");
|
|
cfgs = cfgs || [];
|
|
if (cfgs.find((item: any) => item.name === name)) {
|
|
cfgs.splice(
|
|
cfgs.findIndex((item: any) => item.name === name),
|
|
1,
|
|
);
|
|
}
|
|
cfgs.push({
|
|
name,
|
|
type,
|
|
json,
|
|
address,
|
|
});
|
|
write(filename, cfgs);
|
|
return cfgs;
|
|
};
|
|
|
|
export const loadData = function ({ network }: { network: string }) {
|
|
let env = process.env.NODE_ENV || "dev";
|
|
const filename = `./out/${network}_${env}.json`;
|
|
return read(filename, "json");
|
|
};
|
|
|
|
export const verifyContract = async function ({ hre, name, address, args }:
|
|
{ hre: any, name: string, address: string, args: any[] }) {
|
|
try {
|
|
await hre.run("verify:verify", {
|
|
address,
|
|
constructorArguments: args,
|
|
});
|
|
} catch (e) {
|
|
console.log(`==verify ${name} failed`, e);
|
|
}
|
|
}
|
|
|
|
export const deplayOne = async function ({ hre, name, type, contractName, args, verify }:
|
|
{ hre: any, name: string, type: string, contractName: string, args: any[], verify: boolean }) {
|
|
const provider = hre.ethers.provider;
|
|
const from = await (await provider.getSigner()).getAddress();
|
|
const contract = await hre.deployments.deploy(contractName, {
|
|
from,
|
|
args,
|
|
log: true,
|
|
});
|
|
console.log(`==${name} addr=`, contract.address);
|
|
updateArray({
|
|
name,
|
|
type,
|
|
json: `assets/contracts/${contractName}.json`,
|
|
address: contract.address,
|
|
network: hre.network.name,
|
|
});
|
|
if (!verify) {
|
|
return contract;
|
|
}
|
|
// Wait for 5 blocks
|
|
let currentBlock = await hre.ethers.provider.getBlockNumber();
|
|
while (currentBlock + 5 > (await hre.ethers.provider.getBlockNumber())) {}
|
|
await verifyContract({ hre, name, address: contract.address, args });
|
|
return contract;
|
|
}
|