2020-10-07 17:45:46 +00:00
|
|
|
// Buidler
|
2020-11-16 16:55:04 +00:00
|
|
|
const { task, types } = require("hardhat/config");
|
2020-10-19 16:17:27 +00:00
|
|
|
require("@nomiclabs/hardhat-ethers");
|
|
|
|
require("@nomiclabs/hardhat-waffle");
|
2020-11-04 12:21:01 +00:00
|
|
|
require("hardhat-deploy");
|
2020-11-04 17:09:34 +00:00
|
|
|
require("hardhat-deploy-ethers");
|
2020-11-10 18:23:22 +00:00
|
|
|
require("hardhat-gas-reporter");
|
2020-10-07 17:45:46 +00:00
|
|
|
|
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");
|
|
|
|
|
2020-11-16 16:55:04 +00:00
|
|
|
const mainnetDeployments = require("./hardhat/config/mainnet-deployments");
|
|
|
|
|
2020-08-17 10:17:04 +00:00
|
|
|
// Process Env Variables
|
|
|
|
require("dotenv").config();
|
2020-10-19 16:17:27 +00:00
|
|
|
// 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 = "0xe1F076849B781b1395Fd332dC1758Dbc129be6EC"; // Gelato-Luis
|
|
|
|
const DEPLOYER_PK_MAINNET = process.env.DEPLOYER_PK_MAINNET;
|
|
|
|
|
2020-08-17 10:17:04 +00:00
|
|
|
// ================================= CONFIG =========================================
|
|
|
|
module.exports = {
|
2020-10-19 16:17:27 +00:00
|
|
|
defaultNetwork: "hardhat",
|
2020-11-10 18:23:22 +00:00
|
|
|
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,
|
|
|
|
},
|
2020-11-04 17:09:34 +00:00
|
|
|
user: {
|
|
|
|
default: 0,
|
|
|
|
},
|
2020-11-04 12:21:01 +00:00
|
|
|
gelatoProvider: {
|
|
|
|
default: 1,
|
|
|
|
mainnet: DEPLOYER,
|
|
|
|
},
|
|
|
|
gelatoExecutor: {
|
|
|
|
default: 2,
|
|
|
|
},
|
|
|
|
},
|
2020-08-17 10:17:04 +00:00
|
|
|
networks: {
|
2020-10-19 16:17:27 +00:00
|
|
|
hardhat: {
|
2020-08-17 10:17:04 +00:00
|
|
|
// Standard config
|
2020-10-19 16:17:27 +00:00
|
|
|
// timeout: 150000,
|
|
|
|
forking: {
|
|
|
|
url: `https://eth-mainnet.alchemyapi.io/v2/${ALCHEMY_ID}`,
|
2020-11-03 18:57:25 +00:00
|
|
|
blockNumber: 11189230,
|
2020-10-19 16:17:27 +00:00
|
|
|
},
|
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}`,
|
2020-11-16 16:55:04 +00:00
|
|
|
gasPrice: parseInt(utils.parseUnits("90", "gwei")),
|
|
|
|
timeout: 150000,
|
|
|
|
// Custom
|
|
|
|
...mainnetDeployments,
|
2020-11-04 12:21:01 +00:00
|
|
|
},
|
2020-08-17 10:17:04 +00:00
|
|
|
},
|
2020-10-19 16:17:27 +00:00
|
|
|
solidity: {
|
2020-11-11 16:06:07 +00:00
|
|
|
compilers: [
|
|
|
|
{
|
|
|
|
version: "0.6.10",
|
|
|
|
settings: {
|
2020-11-16 16:55:04 +00:00
|
|
|
optimizer: { enabled: process.env.DEBUG ? false : true },
|
2020-11-11 16:06:07 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
version: "0.7.4",
|
|
|
|
settings: {
|
2020-11-16 16:55:04 +00:00
|
|
|
optimizer: { enabled: process.env.DEBUG ? false : true },
|
2020-11-11 16:06:07 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
],
|
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")
|
2020-10-19 16:17:27 +00:00
|
|
|
.setAction(async (taskArgs, hre) => {
|
2020-08-17 10:17:04 +00:00
|
|
|
try {
|
2020-10-19 16:17:27 +00:00
|
|
|
const gelatoCore = await hre.ethers.getContractAt(
|
2020-08-17 10:17:04 +00:00
|
|
|
GelatoCoreLib.GelatoCore.abi,
|
|
|
|
taskArgs.gelatocoreaddress
|
|
|
|
? taskArgs.gelatocoreaddress
|
2020-10-19 16:17:27 +00:00
|
|
|
: 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
|
2020-10-19 16:17:27 +00:00
|
|
|
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
|
|
|
});
|