diff --git a/scripts/constant/cmdAssets.js b/scripts/constant/cmdAssets.js deleted file mode 100644 index 81b640e1..00000000 --- a/scripts/constant/cmdAssets.js +++ /dev/null @@ -1,12 +0,0 @@ -module.exports = { - connectors: { - uniswapV3: "ConnectV2UniswapV3", - "1inch": "ConnectV2OneInch", - "1proto": "ConnectV2OneProto", - aaveV1: "ConnectV2AaveV1", - aaveV2: "ConnectV2AaveV2", - authority: "ConnectV2Auth", - basic: "ConnectV2Basic", - comp: "ConnectV2COMP", - } - }; \ No newline at end of file diff --git a/scripts/deployConnectorsFromCmd.js b/scripts/deployConnectorsFromCmd.js index 290dee4d..f2584fa5 100644 --- a/scripts/deployConnectorsFromCmd.js +++ b/scripts/deployConnectorsFromCmd.js @@ -1,8 +1,7 @@ +const fs = require("fs"); const hre = require("hardhat"); const { ethers } = hre; -const { connectors, networks } = require("./constant/cmdAssets"); - let args = process.argv; args = args.splice(2, args.length); let params = {}; @@ -14,9 +13,6 @@ for (let i = 0; i < args.length; i += 2) { } let key = args[i].slice(2, args[i].length); params[key] = args[i + 1]; - if (key === "connector") { - params[key] = connectors[args[i + 1]]; - } } if (!params.hasOwnProperty('connector')) { @@ -24,38 +20,63 @@ if (!params.hasOwnProperty('connector')) { process.exit(-1); } -if(params['connector'] === undefined || params['connector'] === null) { - console.error("Unsupported connector name"); - const keys = Object.keys(connectors); - console.log("Currently supported connector names are: ", keys.join(",")); - console.log("If you want to add, please edit scripts/constant/cmdAssets.js"); - process.exit(1); -} - if (!params.hasOwnProperty('network')) { console.error("Should include network params") process.exit(-1); } -if (!params.hasOwnProperty('gas')) { +if (!params.hasOwnProperty('gasPrice')) { console.error("Should include gas params") process.exit(-1); } let privateKey = process.env.PRIVATE_KEY; let provider = new ethers.providers.JsonRpcProvider(hre.config.networks[params['network']].url); -// let wallet = new ethers.Wallet("0xac0974bec39a17e36ba4a6b4d238ff944bacb478cbed5efcae784d7bf4f2ff80", provider); let wallet = new ethers.Wallet(privateKey, provider); -const connectorName = params['connector']; - hre.network.name = params['networkName']; hre.network.config = hre.config.networks[params['networkName']]; hre.network.provider = provider; +let contracts = []; + +const parseFile = async (filePath) => { + const data = fs.readFileSync(filePath, "utf-8"); + let parsedData = data.split("contract "); + parsedData = parsedData[parsedData.length - 1].split(" "); + parsedData = parsedData[0]; + return parsedData; +} + +const parseDir = async (root, basePath, addPath) => { + 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['gas'], "gwei") }); + const connector = await Connector.connect(wallet).deploy({ gasPrice: ethers.utils.parseUnits(params['gasPrice'], "gwei") }); await connector.deployed(); console.log(`${connectorName} Deployed: ${connector.address}`);