mirror of
https://github.com/Instadapp/dsa-connectors.git
synced 2024-07-29 22:37:00 +00:00
updated deployConnectorFromCmd script + minor fixes
This commit is contained in:
parent
413f448cbd
commit
fd9c72eafb
|
@ -11,7 +11,8 @@
|
|||
"deploy": "node scripts/deployConnectorsFromCmd.js",
|
||||
"test:runner": "hardhat run scripts/tests/run-tests.ts",
|
||||
"typechain": "hardhat typechain",
|
||||
"compile": "hardhat compile"
|
||||
"compile": "hardhat compile",
|
||||
"deploy:runner": "hardhat run scripts/deployment/deployConnectorsFromCmd.ts"
|
||||
},
|
||||
"repository": {
|
||||
"type": "git",
|
||||
|
|
31
scripts/deployment/connectors.ts
Normal file
31
scripts/deployment/connectors.ts
Normal file
|
@ -0,0 +1,31 @@
|
|||
export const connectMapping: Record<string, any> = {
|
||||
"1INCH-A": "ConnectV2OneInch",
|
||||
"1INCH-B": "ConnectV2OneProto",
|
||||
"AAVE-V1-A": "ConnectV2AaveV1",
|
||||
"AAVE-V2-A": "ConnectV2AaveV2",
|
||||
"AUTHORITY-A": "ConnectV2Auth",
|
||||
"BASIC-A": "ConnectV2Basic",
|
||||
"COMP-A": "ConnectV2COMP",
|
||||
"COMPOUND-A": "ConnectV2Compound",
|
||||
"DYDX-A": "ConnectV2Dydx",
|
||||
"FEE-A": "ConnectV2Fee",
|
||||
"GELATO-A": "ConnectV2Gelato",
|
||||
"MAKERDAO-A": "ConnectV2Maker",
|
||||
"UNISWAP-A": "ConnectV2UniswapV2",
|
||||
};
|
||||
|
||||
export const connectors = [
|
||||
"1INCH-A",
|
||||
"1INCH-B",
|
||||
"AAVE-V1-A",
|
||||
"AAVE-V2-A",
|
||||
"AUTHORITY-A",
|
||||
"BASIC-A",
|
||||
"COMP-A",
|
||||
"COMPOUND-A",
|
||||
"DYDX-A",
|
||||
"FEE-A",
|
||||
"GELATO-A",
|
||||
"MAKERDAO-A",
|
||||
"UNISWAP-A",
|
||||
];
|
|
@ -1,29 +1,17 @@
|
|||
import { ethers } from "hardhat";
|
||||
import { deployConnector } from "./deployConnector";
|
||||
import { connectMapping } from "./connectors";
|
||||
|
||||
async function main() {
|
||||
const accounts = await ethers.getSigners();
|
||||
if (process.env.connectorName) {
|
||||
await deployConnector();
|
||||
} else {
|
||||
const addressMapping: Record<string, string> = {};
|
||||
|
||||
const connectMapping: Record<string, string> = {
|
||||
"1INCH-A": "ConnectV2OneInch",
|
||||
"1INCH-B": "ConnectV2OneProto",
|
||||
"AAVE-V1-A": "ConnectV2AaveV1",
|
||||
"AAVE-V2-A": "ConnectV2AaveV2",
|
||||
"AUTHORITY-A": "ConnectV2Auth",
|
||||
"BASIC-A": "ConnectV2Basic",
|
||||
"COMP-A": "ConnectV2COMP",
|
||||
"COMPOUND-A": "ConnectV2Compound",
|
||||
"DYDX-A": "ConnectV2Dydx",
|
||||
"FEE-A": "ConnectV2Fee",
|
||||
"GELATO-A": "ConnectV2Gelato",
|
||||
"MAKERDAO-A": "ConnectV2Maker",
|
||||
"UNISWAP-A": "ConnectV2UniswapV2",
|
||||
};
|
||||
|
||||
const addressMapping: Record<string, string> = {};
|
||||
|
||||
for (const key in connectMapping) {
|
||||
addressMapping[key] = await deployConnector(connectMapping[key]);
|
||||
for (const key in connectMapping) {
|
||||
addressMapping[key] = await deployConnector(connectMapping[key]);
|
||||
}
|
||||
console.log(addressMapping);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
import { ethers } from "hardhat";
|
||||
|
||||
export const deployConnector = async (connectorName: string) => {
|
||||
export const deployConnector = async (connectorName?: string) => {
|
||||
connectorName = String(process.env.connectorName) ?? connectorName;
|
||||
const Connector = await ethers.getContractFactory(connectorName);
|
||||
const connector = await Connector.deploy();
|
||||
await connector.deployed();
|
||||
|
|
|
@ -1,106 +1,142 @@
|
|||
import fs from "fs";
|
||||
import hre from "hardhat"
|
||||
const { ethers, network, config } = hre;
|
||||
import { execScript } from "../tests/command";
|
||||
import inquirer from "inquirer";
|
||||
import { connectors, connectMapping } from "./connectors";
|
||||
import { join } from "path";
|
||||
|
||||
let args = process.argv;
|
||||
args = args.splice(2, args.length);
|
||||
let params: Record<string, string> = {};
|
||||
async function deployRunner() {
|
||||
const { chain } = await inquirer.prompt([
|
||||
{
|
||||
name: "chain",
|
||||
message: "What chain do you want to deploy on?",
|
||||
type: "list",
|
||||
choices: ["mainnet", "polygon", "avalanche", "arbitrum"],
|
||||
},
|
||||
]);
|
||||
|
||||
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];
|
||||
}
|
||||
let { connector } = await inquirer.prompt([
|
||||
{
|
||||
name: "connector",
|
||||
message: "Which connector do you want to deploy?",
|
||||
type: "list",
|
||||
choices: connectors,
|
||||
},
|
||||
]);
|
||||
|
||||
if (!params.hasOwnProperty("connector")) {
|
||||
console.error("Should include connector params");
|
||||
process.exit(-1);
|
||||
}
|
||||
connector = connectMapping[connector];
|
||||
|
||||
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 execScript({
|
||||
cmd: "npx",
|
||||
args: ["hardhat", "run", "scripts/deployment/deploy.ts"],
|
||||
env: {
|
||||
connectorName: connector,
|
||||
networkType: chain,
|
||||
},
|
||||
});
|
||||
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);
|
||||
}
|
||||
// let args = process.argv;
|
||||
// args = args.splice(2, args.length);
|
||||
// let params: Record<string, string> = {};
|
||||
|
||||
return connector.address;
|
||||
};
|
||||
// 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];
|
||||
// }
|
||||
|
||||
main()
|
||||
// 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()
|
||||
.then(() => {
|
||||
console.log("Done successfully");
|
||||
process.exit(0);
|
||||
|
|
Loading…
Reference in New Issue
Block a user