Gelato-automations/hardhat.config.js

226 lines
5.7 KiB
JavaScript
Raw Normal View History

// Buidler
2020-11-16 16:55:04 +00:00
const { task, types } = require("hardhat/config");
require("@nomiclabs/hardhat-ethers");
require("@nomiclabs/hardhat-waffle");
2020-11-04 12:21:01 +00:00
require("hardhat-deploy");
require("hardhat-deploy-ethers");
require("hardhat-gas-reporter");
2020-08-17 10:17:04 +00:00
// Libraries
const assert = require("assert");
2020-11-16 16:55:04 +00:00
const { utils } = require("ethers");
2020-08-17 10:17:04 +00:00
const GelatoCoreLib = require("@gelatonetwork/core");
const mainnetDeployments = require("./_hardhat/config/mainnet-deployments");
2020-11-16 16:55:04 +00:00
2020-08-17 10:17:04 +00:00
// Process Env Variables
require("dotenv").config();
// const INFURA_ID = process.env.INFURA_ID;
// assert.ok(INFURA_ID, "no Infura ID in process.env");
const ALCHEMY_ID = process.env.ALCHEMY_ID;
assert.ok(ALCHEMY_ID, "no Alchemy ID in process.env");
2020-11-04 12:21:01 +00:00
const DEPLOYER = "0x5B753BF02a42bC73B5846dfd16a8F2e082b99a6a"; // Gelato-Dev-Luis
2020-11-04 12:21:01 +00:00
const DEPLOYER_PK_MAINNET = process.env.DEPLOYER_PK_MAINNET;
2020-08-17 10:17:04 +00:00
// ================================= CONFIG =========================================
module.exports = {
defaultNetwork: "hardhat",
gasReporter: {
enabled: process.env.REPORT_GAS ? true : false,
maxMethodDiff: 25,
coinmarketcap: process.env.COINMARKETCAP_API_KEY,
},
2020-11-04 12:21:01 +00:00
// hardhat-deploy
namedAccounts: {
deployer: {
default: 0,
mainnet: DEPLOYER,
},
user: {
default: 0,
},
executor: {
2020-11-04 12:21:01 +00:00
default: 1,
},
},
2020-08-17 10:17:04 +00:00
networks: {
hardhat: {
2020-08-17 10:17:04 +00:00
// Standard config
// timeout: 150000,
forking: {
url: `https://eth-mainnet.alchemyapi.io/v2/${ALCHEMY_ID}`,
blockNumber: 11367046,
},
// Accounts
accounts: {
accountsBalance: "1000000000000000000000000",
},
2020-08-17 10:17:04 +00:00
// Custom
2020-11-16 16:55:04 +00:00
...mainnetDeployments,
2020-08-17 10:17:04 +00:00
},
2020-11-04 12:21:01 +00:00
mainnet: {
accounts: DEPLOYER_PK_MAINNET ? [DEPLOYER_PK_MAINNET] : [],
chainId: 1,
url: `https://eth-mainnet.alchemyapi.io/v2/${ALCHEMY_ID}`,
gasPrice: parseInt(utils.parseUnits("80", "gwei")),
2020-11-16 16:55:04 +00:00
timeout: 150000,
// Custom
...mainnetDeployments,
2020-11-04 12:21:01 +00:00
},
2020-08-17 10:17:04 +00:00
},
solidity: {
compilers: [
{
version: "0.6.0",
settings: {
2020-11-25 10:50:24 +00:00
optimizer: { enabled: false },
},
},
{
version: "0.6.6",
settings: {
optimizer: { enabled: process.env.DEBUG ? false : true },
},
},
{
version: "0.6.10",
settings: {
2020-11-16 16:55:04 +00:00
optimizer: { enabled: process.env.DEBUG ? false : true },
},
},
{
version: "0.7.4",
settings: {
2020-11-16 16:55:04 +00:00
optimizer: { enabled: process.env.DEBUG ? false : true },
},
},
],
2020-08-17 10:17:04 +00:00
},
};
// ================================= TASKS =========================================
task("abi-encode-withselector")
.addPositionalParam(
"abi",
"Contract ABI in array form",
undefined,
types.json
)
.addPositionalParam("functionname")
.addOptionalVariadicPositionalParam(
"inputs",
"Array of function params",
undefined,
types.json
)
.addFlag("log")
.setAction(async (taskArgs) => {
try {
if (taskArgs.log) console.log(taskArgs);
if (!taskArgs.abi)
throw new Error("abi-encode-withselector: no abi passed");
const interFace = new utils.Interface(taskArgs.abi);
let functionFragment;
try {
functionFragment = interFace.getFunction(taskArgs.functionname);
} catch (error) {
throw new Error(
`\n ❌ abi-encode-withselector: functionname "${taskArgs.functionname}" not found`
);
}
let payloadWithSelector;
if (taskArgs.inputs) {
let iterableInputs;
try {
iterableInputs = [...taskArgs.inputs];
} catch (error) {
iterableInputs = [taskArgs.inputs];
}
payloadWithSelector = interFace.encodeFunctionData(
functionFragment,
iterableInputs
);
} else {
payloadWithSelector = interFace.encodeFunctionData(
functionFragment,
[]
);
}
if (taskArgs.log)
console.log(`\nEncodedPayloadWithSelector:\n${payloadWithSelector}\n`);
return payloadWithSelector;
} catch (err) {
console.error(err);
process.exit(1);
}
});
task(
"fetchGelatoGasPrice",
`Returns the current gelato gas price used for calling canExec and exec`
)
.addOptionalParam("gelatocoreaddress")
.addFlag("log", "Logs return values to stdout")
.setAction(async (taskArgs, hre) => {
2020-08-17 10:17:04 +00:00
try {
const gelatoCore = await hre.ethers.getContractAt(
2020-08-17 10:17:04 +00:00
GelatoCoreLib.GelatoCore.abi,
taskArgs.gelatocoreaddress
? taskArgs.gelatocoreaddress
: hre.network.config.GelatoCore
2020-08-17 10:17:04 +00:00
);
const oracleAbi = ["function latestAnswer() view returns (int256)"];
const gelatoGasPriceOracleAddress = await gelatoCore.gelatoGasPriceOracle();
// Get gelatoGasPriceOracleAddress
const gelatoGasPriceOracle = await hre.ethers.getContractAt(
2020-08-17 10:17:04 +00:00
oracleAbi,
gelatoGasPriceOracleAddress
);
// lastAnswer is used by GelatoGasPriceOracle as well as the Chainlink Oracle
const gelatoGasPrice = await gelatoGasPriceOracle.latestAnswer();
if (taskArgs.log) {
console.log(
`\ngelatoGasPrice: ${utils.formatUnits(
gelatoGasPrice.toString(),
"gwei"
)} gwei\n`
);
}
return gelatoGasPrice;
} catch (error) {
console.error(error, "\n");
process.exit(1);
}
});
2020-10-26 17:33:36 +00:00
2020-10-27 08:24:15 +00:00
task(
"hardhatReset",
"Reset back to a fresh forked state during runtime"
).setAction(async (_, hre) => {
await hre.network.provider.request({
method: "hardhat_reset",
params: [
{
forking: {
jsonRpcUrl: hre.network.config.forking.url,
blockNumber: hre.network.config.forking.blockNumber,
2020-10-26 17:33:36 +00:00
},
2020-10-27 08:24:15 +00:00
},
],
2020-10-26 17:33:36 +00:00
});
2020-10-27 08:24:15 +00:00
});