hardhat/config#extendEnvironment TypeScript Examples

The following examples show how to use hardhat/config#extendEnvironment. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: hardhat.config.ts    From eth with GNU General Public License v3.0 6 votes vote down vote up
extendEnvironment((env: HardhatRuntimeEnvironment) => {
  env.DEPLOYER_MNEMONIC = DEPLOYER_MNEMONIC;
  // cant easily lookup deployer.address here so well have to be ok with undefined and check it later
  env.ADMIN_PUBLIC_ADDRESS = ADMIN_PUBLIC_ADDRESS;

  env.packageDirs = packageDirs;

  env.contracts = lazyObject(() => {
    const contracts = require('@darkforest_eth/contracts');
    return settings.parse(decodeContracts, contracts);
  });

  env.initializers = lazyObject(() => {
    const { initializers = {} } = settings.load(env.network.name);
    return settings.parse(decodeInitializers, initializers);
  });

  env.adminPlanets = lazyObject(() => {
    const { planets = [] } = settings.load(env.network.name);
    return settings.parse(decodeAdminPlanets, planets);
  });
});
Example #2
Source File: index.ts    From plugins with MIT License 6 votes vote down vote up
extendEnvironment((hre) => {

  if (hre.network.config.ovm ) { // || process.env.TARGET // we could make it activate by env variable too but I would make it a less generic one than TARGET, more like OPTIMISM_TARGET
    hre.network.ovm = hre.network.config.ovm;

    let artifactsPath = hre.config.paths.artifacts
    if (!artifactsPath.endsWith('-ovm')) {
      artifactsPath = artifactsPath + '-ovm'
    }

    let cachePath = hre.config.paths.cache
    if (!cachePath.endsWith('-ovm')) {
      cachePath = cachePath + '-ovm'
    }

    // Forcibly update the artifacts object.
    hre.config.paths.artifacts = artifactsPath;
    hre.config.paths.cache = cachePath;
    (hre as any).artifacts = new Artifacts(artifactsPath);
  }
})
Example #3
Source File: index.ts    From hardhat-kms-signer with MIT License 6 votes vote down vote up
extendEnvironment((hre) => {
  if (hre.network.config.kmsKeyId) {
    const httpNetConfig = hre.network.config as HttpNetworkUserConfig;
    const eip1193Provider = new HttpProvider(
      httpNetConfig.url!,
      hre.network.name,
      httpNetConfig.httpHeaders,
      httpNetConfig.timeout
    );
    let wrappedProvider: EIP1193Provider;
    wrappedProvider = new KMSSigner(
      eip1193Provider,
      hre.network.config.kmsKeyId
    );
    wrappedProvider = new AutomaticGasProvider(
      wrappedProvider,
      hre.network.config.gasMultiplier
    );
    wrappedProvider = new AutomaticGasPriceProvider(wrappedProvider);
    hre.network.provider = new BackwardsCompatibilityProviderAdapter(
      wrappedProvider
    );
  }
});
Example #4
Source File: index.ts    From openzeppelin-upgrades with MIT License 5 votes vote down vote up
extendEnvironment(hre => {
  hre.defender = lazyObject((): HardhatDefenderUpgrades => {
    const { makeProposeUpgrade } = require('./propose-upgrade');
    return {
      proposeUpgrade: makeProposeUpgrade(hre),
    };
  });
});
Example #5
Source File: index.ts    From openzeppelin-upgrades with MIT License 5 votes vote down vote up
extendEnvironment(hre => {
  hre.upgrades = lazyObject((): HardhatUpgrades => {
    const {
      silenceWarnings,
      getAdminAddress,
      getImplementationAddress,
      getBeaconAddress,
    } = require('@openzeppelin/upgrades-core');
    const { makeDeployProxy } = require('./deploy-proxy');
    const { makeUpgradeProxy } = require('./upgrade-proxy');
    const { makePrepareUpgrade } = require('./prepare-upgrade');
    const { makeDeployBeacon } = require('./deploy-beacon');
    const { makeDeployBeaconProxy } = require('./deploy-beacon-proxy');
    const { makeUpgradeBeacon } = require('./upgrade-beacon');
    const { makeForceImport } = require('./force-import');
    const { makeChangeProxyAdmin, makeTransferProxyAdminOwnership, makeGetInstanceFunction } = require('./admin');

    return {
      silenceWarnings,
      deployProxy: makeDeployProxy(hre),
      upgradeProxy: makeUpgradeProxy(hre),
      prepareUpgrade: makePrepareUpgrade(hre),
      deployBeacon: makeDeployBeacon(hre),
      deployBeaconProxy: makeDeployBeaconProxy(hre),
      upgradeBeacon: makeUpgradeBeacon(hre),
      forceImport: makeForceImport(hre),
      admin: {
        getInstance: makeGetInstanceFunction(hre),
        changeProxyAdmin: makeChangeProxyAdmin(hre),
        transferProxyAdminOwnership: makeTransferProxyAdminOwnership(hre),
      },
      erc1967: {
        getAdminAddress: proxyAddress => getAdminAddress(hre.network.provider, proxyAddress),
        getImplementationAddress: proxyAddress => getImplementationAddress(hre.network.provider, proxyAddress),
        getBeaconAddress: proxyAddress => getBeaconAddress(hre.network.provider, proxyAddress),
      },
      beacon: {
        getImplementationAddress: beaconAddress =>
          getImplementationAddressFromBeacon(hre.network.provider, beaconAddress),
      },
    };
  });
});
Example #6
Source File: index.ts    From hardhat-tenderly with GNU General Public License v3.0 5 votes vote down vote up
extendEnvironment(env => {
  env.tenderly = lazyObject(() => new Tenderly(env));
  populateNetworks(env);
});
Example #7
Source File: hardhat.config.ts    From hoprnet with GNU General Public License v3.0 5 votes vote down vote up
extendEnvironment((hre: HardhatRuntimeEnvironment) => {
  hre.environment = HOPR_ENVIRONMENT_ID
})
Example #8
Source File: index.ts    From hardhat-etherscan-abi with MIT License 5 votes vote down vote up
extendEnvironment((hre) => {
  const prevEthers = hre.ethers;
  hre.ethers = lazyObject(() => {
    // @ts-ignore
    prevEthers.getVerifiedContractAt = getVerifiedContractAt.bind(null, hre);
    return prevEthers;
  });
});
Example #9
Source File: index.ts    From hardhat-circom with GNU General Public License v3.0 5 votes vote down vote up
// non-object or non-thenable

extendEnvironment((hre) => {
  hre.circom = circom1Compiler;
  hre.snarkjs = snarkjs;
});
Example #10
Source File: index.ts    From hardhat-deploy with MIT License 5 votes vote down vote up
extendEnvironment((env) => {
  networkFromConfig(env, env.network, true);
  if (deploymentsManager === undefined || env.deployments === undefined) {
    deploymentsManager = new DeploymentsManager(
      env,
      lazyObject(() => env.network) // IMPORTANT, else other plugin cannot set env.network before end, like solidity-coverage does here in the coverage task :  https://github.com/sc-forks/solidity-coverage/blob/3c0f3a5c7db26e82974873bbf61cf462072a7c6d/plugins/resources/nomiclabs.utils.js#L93-L98
    );
    env.deployments = deploymentsManager.deploymentsExtension;
    env.getNamedAccounts =
      deploymentsManager.getNamedAccounts.bind(deploymentsManager);
    env.getUnnamedAccounts =
      deploymentsManager.getUnnamedAccounts.bind(deploymentsManager);
    env.getChainId = () => {
      return deploymentsManager.getChainId();
    };

    for (const networkName of Object.keys(env.config.networks)) {
      const config = env.config.networks[networkName];
      if (!('url' in config) || networkName === 'hardhat') {
        continue;
      }
      store.networks[networkName] = createNetworkFromConfig(
        env,
        networkName,
        config
      );
    }

    env.companionNetworks = {};
    for (const name of Object.keys(env.network.companionNetworks)) {
      const networkName = env.network.companionNetworks[name];
      // TODO Fork case ?
      if (networkName === env.network.name) {
        deploymentsManager.addCompanionManager(name, deploymentsManager);
        const extraNetwork = {
          deployments: deploymentsManager.deploymentsExtension,
          getNamedAccounts: () => deploymentsManager.getNamedAccounts(),
          getUnnamedAccounts: () => deploymentsManager.getUnnamedAccounts(),
          getChainId: () => deploymentsManager.getChainId(),
          provider: lazyObject(() => env.network.provider),
        };
        env.companionNetworks[name] = extraNetwork;
        continue;
      }
      const config = env.config.networks[networkName];
      if (!('url' in config) || networkName === 'hardhat') {
        throw new Error(
          `in memory network like hardhat are not supported as companion network`
        );
      }

      const network = store.networks[networkName];
      if (!network) {
        throw new Error(`no network named ${networkName}`);
      }
      network.provider = createProvider(
        networkName,
        config,
        env.config.paths,
        env.artifacts
      );
      const networkDeploymentsManager = new DeploymentsManager(env, network);
      deploymentsManager.addCompanionManager(name, networkDeploymentsManager);
      const extraNetwork = {
        deployments: networkDeploymentsManager.deploymentsExtension,
        getNamedAccounts: () => networkDeploymentsManager.getNamedAccounts(),
        getUnnamedAccounts: () =>
          networkDeploymentsManager.getUnnamedAccounts(),
        getChainId: () => networkDeploymentsManager.getChainId(),
        provider: network.provider,
      };
      env.companionNetworks[name] = extraNetwork;
    }
  }
  log('ready');
});