2021-12-26 07:14:52 +00:00
|
|
|
import { execScript } from "../tests/command";
|
|
|
|
import inquirer from "inquirer";
|
|
|
|
import { connectors, connectMapping } from "./connectors";
|
|
|
|
import { join } from "path";
|
|
|
|
|
2022-01-11 09:47:35 +00:00
|
|
|
let start: number, end: number, runchain: string;
|
2021-12-26 07:47:07 +00:00
|
|
|
|
2022-01-11 08:19:13 +00:00
|
|
|
async function connectorSelect(chain: string) {
|
|
|
|
let { connector } = await inquirer.prompt([
|
|
|
|
{
|
|
|
|
name: "connector",
|
|
|
|
message: "Which connector do you want to deploy?",
|
|
|
|
type: "list",
|
|
|
|
choices: connectors[chain],
|
|
|
|
},
|
|
|
|
]);
|
|
|
|
|
|
|
|
return connector;
|
|
|
|
}
|
|
|
|
|
2021-12-26 07:14:52 +00:00
|
|
|
async function deployRunner() {
|
2022-01-11 08:19:13 +00:00
|
|
|
let { chain } = await inquirer.prompt([
|
2021-12-26 07:14:52 +00:00
|
|
|
{
|
|
|
|
name: "chain",
|
|
|
|
message: "What chain do you want to deploy on?",
|
|
|
|
type: "list",
|
|
|
|
choices: ["mainnet", "polygon", "avalanche", "arbitrum"],
|
|
|
|
},
|
|
|
|
]);
|
|
|
|
|
2022-01-11 08:19:13 +00:00
|
|
|
let connector = await connectorSelect(chain);
|
|
|
|
|
|
|
|
let { choice } = await inquirer.prompt([
|
2021-12-26 07:14:52 +00:00
|
|
|
{
|
2022-01-11 08:19:13 +00:00
|
|
|
name: "choice",
|
|
|
|
message: "Do you wanna select again?",
|
2021-12-26 07:14:52 +00:00
|
|
|
type: "list",
|
2022-01-11 08:19:13 +00:00
|
|
|
choices: ["yes", "no"],
|
2021-12-26 07:14:52 +00:00
|
|
|
},
|
|
|
|
]);
|
|
|
|
|
2022-01-11 08:19:13 +00:00
|
|
|
if (choice === "yes") {
|
|
|
|
connector = await connectorSelect(chain);
|
|
|
|
}
|
|
|
|
connector = connectMapping[chain][connector];
|
|
|
|
|
|
|
|
let { choice1 } = await inquirer.prompt([
|
|
|
|
{
|
2022-01-11 09:47:35 +00:00
|
|
|
name: "choice1",
|
2022-01-11 08:19:13 +00:00
|
|
|
message: "Do you wanna try deploy on hardhat first?",
|
|
|
|
type: "list",
|
|
|
|
choices: ["yes", "no"],
|
|
|
|
},
|
|
|
|
]);
|
|
|
|
|
2022-01-11 09:47:35 +00:00
|
|
|
runchain = choice1 === "yes" ? "hardhat" : chain;
|
2022-01-11 08:19:13 +00:00
|
|
|
|
2022-01-11 09:47:35 +00:00
|
|
|
console.log(
|
|
|
|
`Deploying ${connector} on ${runchain}, press (ctrl + c) to stop`
|
|
|
|
);
|
2022-01-11 08:19:13 +00:00
|
|
|
|
2021-12-26 07:47:07 +00:00
|
|
|
start = Date.now();
|
2021-12-26 07:14:52 +00:00
|
|
|
await execScript({
|
|
|
|
cmd: "npx",
|
2022-01-11 08:19:13 +00:00
|
|
|
args: [
|
|
|
|
"hardhat",
|
|
|
|
"run",
|
|
|
|
"scripts/deployment/deploy.ts",
|
|
|
|
"--network",
|
2022-01-11 09:47:35 +00:00
|
|
|
`${runchain}`,
|
2022-01-11 08:19:13 +00:00
|
|
|
],
|
2021-12-26 07:14:52 +00:00
|
|
|
env: {
|
|
|
|
connectorName: connector,
|
|
|
|
networkType: chain,
|
|
|
|
},
|
|
|
|
});
|
2021-12-26 07:47:07 +00:00
|
|
|
end = Date.now();
|
2021-12-04 13:08:16 +00:00
|
|
|
}
|
|
|
|
|
2021-12-26 07:14:52 +00:00
|
|
|
// let args = process.argv;
|
|
|
|
// args = args.splice(2, args.length);
|
|
|
|
// let params: Record<string, string> = {};
|
|
|
|
|
|
|
|
// for (let i = 0; i < args.length; i += 2) {
|
|
|
|
// if (args[i][0] !== "-" || args[i][1] !== "-") {
|
|
|
|
// console.log("Please add '--' for the key");
|
|
|
|
// process.exit(-1);
|
|
|
|
// }
|
|
|
|
// let key = args[i].slice(2, args[i].length);
|
|
|
|
// params[key] = args[i + 1];
|
|
|
|
// }
|
|
|
|
|
|
|
|
// if (!params.hasOwnProperty("connector")) {
|
|
|
|
// console.error("Should include connector params");
|
|
|
|
// process.exit(-1);
|
|
|
|
// }
|
|
|
|
|
|
|
|
// if (!params.hasOwnProperty("network")) {
|
|
|
|
// console.error("Should include network params");
|
|
|
|
// process.exit(-1);
|
|
|
|
// }
|
|
|
|
|
|
|
|
// if (!params.hasOwnProperty("gasPrice")) {
|
|
|
|
// console.error("Should include gas params");
|
|
|
|
// process.exit(-1);
|
|
|
|
// }
|
|
|
|
|
|
|
|
// let privateKey = String(process.env.PRIVATE_KEY);
|
|
|
|
// let provider = new ethers.providers.JsonRpcProvider(
|
|
|
|
// config.networks[params["network"]].url
|
|
|
|
// );
|
|
|
|
// let wallet = new ethers.Wallet(privateKey, provider);
|
|
|
|
|
|
|
|
// network.name = params["networkName"];
|
|
|
|
// network.config = config.networks[params["networkName"]];
|
|
|
|
// network.provider = provider;
|
|
|
|
// let contracts: (string | string[])[] = [];
|
|
|
|
|
|
|
|
// const parseFile = async (filePath: fs.PathOrFileDescriptor) => {
|
|
|
|
// const data = fs.readFileSync(filePath, "utf-8");
|
|
|
|
// let parsedData = data.split("contract ");
|
|
|
|
// parsedData = parsedData[parsedData.length - 1].split(" ");
|
|
|
|
// return parsedData[0];
|
|
|
|
// };
|
|
|
|
|
|
|
|
// const parseDir = async (
|
|
|
|
// root: string | any[],
|
|
|
|
// basePath: string,
|
|
|
|
// addPath: string
|
|
|
|
// ) => {
|
|
|
|
// for (let i = 0; i < root.length; i++) {
|
|
|
|
// addPath = "/" + root[i];
|
|
|
|
// const dir = fs.readdirSync(basePath + addPath);
|
|
|
|
// if (dir.indexOf("main.sol") !== -1) {
|
|
|
|
// const fileData = await parseFile(basePath + addPath + "/main.sol");
|
|
|
|
// contracts.push(fileData);
|
|
|
|
// } else {
|
|
|
|
// await parseDir(dir, basePath + addPath, "");
|
|
|
|
// }
|
|
|
|
// }
|
|
|
|
// };
|
|
|
|
|
|
|
|
// const main = async () => {
|
|
|
|
// const mainnet = fs.readdirSync("./contracts/mainnet/connectors/");
|
|
|
|
// const polygon = fs.readdirSync("./contracts/polygon/connectors/");
|
|
|
|
// let basePathMainnet = "./contracts/mainnet/connectors/";
|
|
|
|
// let basePathPolygon = "./contracts/polygon/connectors/";
|
|
|
|
|
|
|
|
// const connectorName = params["connector"];
|
|
|
|
|
|
|
|
// await parseDir(mainnet, basePathMainnet, "");
|
|
|
|
// await parseDir(polygon, basePathPolygon, "");
|
|
|
|
|
|
|
|
// if (contracts.indexOf(connectorName) === -1) {
|
|
|
|
// throw new Error(
|
|
|
|
// "can not find the connector!\n" +
|
|
|
|
// "supported connector names are:\n" +
|
|
|
|
// contracts.join("\n")
|
|
|
|
// );
|
|
|
|
// }
|
|
|
|
|
|
|
|
// const Connector = await ethers.getContractFactory(connectorName);
|
|
|
|
// const connector = await Connector.connect(wallet).deploy({
|
|
|
|
// gasPrice: ethers.utils.parseUnits(params["gasPrice"], "gwei"),
|
|
|
|
// });
|
|
|
|
// await connector.deployed();
|
|
|
|
|
|
|
|
// console.log(`${connectorName} Deployed: ${connector.address}`);
|
|
|
|
// try {
|
|
|
|
// await hre.run("verify:verify", {
|
|
|
|
// address: connector.address,
|
|
|
|
// constructorArguments: [],
|
|
|
|
// });
|
|
|
|
// } catch (error) {
|
|
|
|
// console.log(`Failed to verify: ${connectorName}@${connector.address}`);
|
|
|
|
// console.log(error);
|
|
|
|
// }
|
|
|
|
|
|
|
|
// return connector.address;
|
|
|
|
// };
|
|
|
|
|
|
|
|
deployRunner()
|
2021-12-04 13:08:16 +00:00
|
|
|
.then(() => {
|
2021-12-26 07:47:07 +00:00
|
|
|
console.log(
|
|
|
|
`Done successfully, total time taken: ${(end - start) / 1000} sec`
|
|
|
|
);
|
2021-12-04 13:08:16 +00:00
|
|
|
process.exit(0);
|
|
|
|
})
|
|
|
|
.catch((err) => {
|
|
|
|
console.log("error:", err);
|
|
|
|
process.exit(1);
|
|
|
|
});
|