dsa-connectors/scripts/deployment/deployConnector.ts

38 lines
1.2 KiB
TypeScript
Raw Normal View History

2021-12-26 07:47:07 +00:00
import hre, { ethers } from "hardhat";
import { execScript } from "../tests/command";
export const deployConnector = async (connectorName?: string) => {
connectorName = String(process.env.connectorName) ?? connectorName;
2021-11-29 17:21:11 +00:00
const Connector = await ethers.getContractFactory(connectorName);
const connector = await Connector.deploy();
await connector.deployed();
console.log(`${connectorName} Deployed: ${connector.address}`);
2021-12-26 07:47:07 +00:00
2022-01-11 08:19:13 +00:00
const chain = String(hre.network.name);
if (chain !== "hardhat") {
const allPaths = await hre.artifacts.getArtifactPaths();
let connectorPath;
for (const path of allPaths)
if (path.split("/").includes(connectorName + ".json"))
connectorPath = path.slice(path.indexOf("contracts"), path.indexOf(connectorName) - 1) + `:${connectorName}`;
2022-01-11 08:19:13 +00:00
try {
await execScript({
cmd: "npx",
args: ["hardhat", "verify", "--network", `${chain}`, `${connector.address}`, "--contract", `${connectorPath}`],
2022-01-11 08:19:13 +00:00
env: {
networkType: chain
}
2022-01-11 08:19:13 +00:00
});
} catch (error) {
console.log(`Failed to verify: ${connectorName}@${connector.address}`);
console.log(error);
console.log();
}
2021-12-26 07:47:07 +00:00
}
2022-01-11 08:19:13 +00:00
2021-11-29 17:21:11 +00:00
return connector.address;
};