@dydxfoundation/governance
Version:
dYdX governance smart contracts
40 lines (39 loc) • 1.36 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.setHre = exports.getHre = exports.getNetworkName = exports.hardhatTask = void 0;
require("@nomiclabs/hardhat-ethers/internal/type-extensions");
const config_1 = require("hardhat/config");
// Within src/, we use this method to access `hre` in order to avoid importing 'hardhat', since we
// cannot import 'hardhat' from file (such as tasks) that are imported from the hardhat config.
let hre = null;
let hreWasSet = false;
const hardhatTask = function hardhatTask(name, descriptionOrAction, action) {
if (action) {
return (0, config_1.task)(name, descriptionOrAction, (taskArgs, env, runSuper) => {
setHre(env);
return action(taskArgs, env, runSuper);
});
}
return (0, config_1.task)(name, (taskArgs, env, runSuper) => {
setHre(env);
return descriptionOrAction(taskArgs, env, runSuper);
});
};
exports.hardhatTask = hardhatTask;
function getNetworkName() {
return getHre().network.name;
}
exports.getNetworkName = getNetworkName;
function getHre() {
/* eslint-disable-next-line global-require */
return hre || require('hardhat');
}
exports.getHre = getHre;
function setHre(newHre) {
if (hreWasSet) {
return;
}
hre = newHre;
hreWasSet = true;
}
exports.setHre = setHre;