hardhat/types#RunSuperFunction TypeScript Examples
The following examples show how to use
hardhat/types#RunSuperFunction.
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: test.ts From balancer-v2-monorepo with GNU General Public License v3.0 | 6 votes |
async function runForkTests(args: any, hre: HardhatRuntimeEnvironment, run: RunSuperFunction<any>): Promise<void> {
console.log('Running fork tests...');
if (args.fork === 'hardhat') throw Error('Cannot fork local networks');
args.testFiles = args.testFiles.filter((file: string) => file.endsWith('.fork.ts'));
const forkingNetworkName = Object.keys(hre.config.networks).find((networkName) => networkName === args.fork);
if (!forkingNetworkName) throw Error(`Could not find a config for network ${args.fork} to be forked`);
const forkingNetworkConfig = hre.config.networks[forkingNetworkName] as HttpNetworkConfig;
if (!forkingNetworkConfig.url) throw Error(`Could not find a RPC url in network config for ${forkingNetworkName}`);
await hre.network.provider.request({
method: 'hardhat_reset',
params: [{ forking: { jsonRpcUrl: forkingNetworkConfig.url, blockNumber: args.blockNumber } }],
});
const config = hre.network.config as HardhatNetworkConfig;
config.forking = { enabled: true, blockNumber: args.blockNumber, url: forkingNetworkConfig.url };
await run(args);
}
Example #2
Source File: overrideQueryFunctions.ts From balancer-v2-monorepo with GNU General Public License v3.0 | 6 votes |
override: ActionType<any> = async (
args: any,
env: HardhatRuntimeEnvironment,
run: RunSuperFunction<any>
): Promise<any> => {
const result = await run();
DIRECTORIES.forEach(traverseDirectory);
return result;
}
Example #3
Source File: compile.ts From eth with GNU General Public License v3.0 | 6 votes |
async function copyAbi(
args: HardhatArguments,
hre: HardhatRuntimeEnvironment,
runSuper: RunSuperFunction<TaskArguments>
) {
const out = await runSuper(args);
const { abi } = await hre.artifacts.readArtifact(hre.config.diamondAbi.name);
const abisDir = path.join(hre.packageDirs['@darkforest_eth/contracts'], 'abis');
// workaround for: https://github.com/graphprotocol/graph-cli/issues/588
// just remove calls we cant process, note makes them unusable from within
// graph but largely dont need these
const filteredDiamondAbi = abi.filter(abiFilter);
await fs.writeFile(
path.join(abisDir, 'DarkForest_stripped.json'),
prettier.format(JSON.stringify(filteredDiamondAbi), {
semi: false,
parser: 'json',
})
);
return out;
}
Example #4
Source File: verify-proxy.ts From openzeppelin-upgrades with MIT License | 5 votes |
/**
* Overrides hardhat-etherscan's verify function to fully verify a proxy.
*
* Verifies the contract at an address. If the address is an ERC-1967 compatible proxy, verifies the proxy and associated proxy contracts,
* as well as the implementation. Otherwise, calls hardhat-etherscan's verify function directly.
*
* @param args Args to the hardhat-etherscan verify function
* @param hre
* @param runSuper The parent function which is expected to be hardhat-etherscan's verify function
* @returns
*/
export async function verify(args: any, hre: HardhatRuntimeEnvironment, runSuper: RunSuperFunction<any>) {
if (!runSuper.isDefined) {
throw new UpgradesError(
'The hardhat-etherscan plugin must be imported before the hardhat-upgrades plugin.',
() =>
'Import the plugins in the following order in hardhat.config.js:\n' +
' require("@nomiclabs/hardhat-etherscan");\n' +
' require("@openzeppelin/hardhat-upgrades");\n' +
'Or if you are using TypeScript, import the plugins in the following order in hardhat.config.ts:\n' +
' import "@nomiclabs/hardhat-etherscan";\n' +
' import "@openzeppelin/hardhat-upgrades";\n',
);
}
const provider = hre.network.provider;
const proxyAddress = args.address;
const errors: string[] = [];
if (await isTransparentOrUUPSProxy(provider, proxyAddress)) {
await fullVerifyTransparentOrUUPS(hre, proxyAddress, hardhatVerify, errors);
} else if (await isBeaconProxy(provider, proxyAddress)) {
await fullVerifyBeaconProxy(hre, proxyAddress, hardhatVerify, errors);
} else {
// Doesn't look like a proxy, so just verify directly
return hardhatVerify(proxyAddress);
}
if (errors.length > 0) {
throw new UpgradesError(getVerificationErrorSummary(errors));
}
console.info('\nProxy fully verified.');
async function hardhatVerify(address: string) {
return await runSuper({ ...args, address });
}
}
Example #5
Source File: test.ts From balancer-v2-monorepo with GNU General Public License v3.0 | 5 votes |
/* eslint-disable @typescript-eslint/no-explicit-any */
/* eslint-disable @typescript-eslint/explicit-module-boundary-types */
export default async function (args: any, hre: HardhatRuntimeEnvironment, run: RunSuperFunction<any>): Promise<void> {
await runForkTests(args, hre, run);
}
Example #6
Source File: faucet.ts From hoprnet with GNU General Public License v3.0 | 5 votes |
/**
* Faucets HOPR and ETH tokens to a local account with HOPR
*/
async function main(
opts: FaucetCLIOPts,
{ network, ethers, deployments, environment }: HardhatRuntimeEnvironment,
_runSuper: RunSuperFunction<any>
): Promise<void> {
if (environment == undefined) {
console.error(`HOPR_ENVIRONMENT_ID is not set. Run with "HOPR_ENVIRONMENT_ID=<environment> ..."`)
process.exit(1)
}
if (!network.tags.development) {
console.error('Faucet is only valid in a development network')
process.exit(1)
}
let hoprTokenAddress: string
try {
const contract = await deployments.get('HoprToken')
hoprTokenAddress = contract.address
} catch (error) {
console.error('HoprToken contract has not been deployed. Deploy the contract and run again.')
process.exit(1)
}
const identities: string[] = []
if (opts.useLocalIdentities) {
identities.push(...(await getIdentities(opts.identityDirectory, opts.password, opts.identityPrefix)))
}
if (opts.address) {
if (opts.address.match(/0x[0-9a-fA-F]{40}|[0-9a-fA-F]{40}/)) {
identities.push(opts.address)
} else if (hasB58String(opts.address)) {
try {
identities.push(PublicKey.fromPeerIdString(opts.address).toAddress().toHex())
} catch (err) {
console.log(`error while parsing ${opts.address}`)
}
} else {
console.log(`Address ${opts.address} has unknown format.`)
}
}
if (identities.length == 0) {
console.error(`Could not get any usable addresses.`)
process.exit(1)
}
const hoprToken = (await ethers.getContractFactory('HoprToken')).attach(hoprTokenAddress)
// we use a custom ethers provider here instead of the ethers object from the
// hre which is managed by hardhat-ethers, because that one seems to
// run its own in-memory hardhat instance, which is undesirable
const provider = new ethers.providers.JsonRpcProvider()
const signer = provider.getSigner()
const txs: Promise<void>[] = []
for (const identity of identities) {
let newTxs = await createTransaction(
hoprToken,
identity,
utils.parseEther('10.0'),
utils.parseEther('20000.0'),
network.name
)
for (const tx of newTxs) {
let txSend = send(signer, tx)
txs.push(txSend)
}
}
await Promise.all(txs)
}
Example #7
Source File: getAccounts.ts From hoprnet with GNU General Public License v3.0 | 5 votes |
/**
* Display unlocked accounts alongside with how much
* ETH / HOPR they have.
*/
async function main(
_params,
{ network, ethers, deployments }: HardhatRuntimeEnvironment,
_runSuper: RunSuperFunction<any>
) {
const contract = await deployments.get('HoprToken')
const hoprToken = (await ethers.getContractFactory('HoprToken')).attach(contract.address)
console.log('Running task "accounts" with config:', {
network: network.name
})
const accounts = await ethers.getSigners()
const nativeBalances = await Promise.all(
accounts.map(async (account) => {
const amount = await account.getBalance()
return ethers.utils.formatEther(amount)
})
)
const hoprBalances = await Promise.all(
accounts.map(async (account) => {
const amount = await hoprToken.balanceOf(account.address)
return ethers.utils.formatEther(amount)
})
)
console.table(
accounts.map((account, i) => {
return {
account,
native: nativeBalances[i],
hopr: hoprBalances[i]
}
})
)
}
Example #8
Source File: register.ts From hoprnet with GNU General Public License v3.0 | 5 votes |
/**
* Used by our E2E tests to interact with 'HoprNetworkRegistry' and 'HoprDummyProxyForNetworkRegistry'.
*/
async function main(
opts: RegisterOpts,
{ network, ethers, deployments, environment }: HardhatRuntimeEnvironment,
_runSuper: RunSuperFunction<any>
): Promise<void> {
if (environment == undefined) {
console.error(`HOPR_ENVIRONMENT_ID is not set. Run with "HOPR_ENVIRONMENT_ID=<environment> ..."`)
process.exit(1)
}
if (network.name !== 'hardhat') {
console.error('Register only works in a hardhat network.')
process.exit(1)
}
let hoprDummyProxyAddress: string
let hoprNetworkRegistryAddress: string
try {
hoprDummyProxyAddress = (await deployments.get('HoprNetworkRegistryProxy')).address
hoprNetworkRegistryAddress = (await deployments.get('HoprNetworkRegistry')).address
} catch {
console.error(
'HoprNetworkRegistry or HoprDummyProxyForNetworkRegistry contract has not been deployed. Deploy the contract and run again.'
)
process.exit(1)
}
// we use a custom ethers provider here instead of the ethers object from the
// hre which is managed by hardhat-ethers, because that one seems to
// run its own in-memory hardhat instance, which is undesirable
const provider = new ethers.providers.JsonRpcProvider()
const signer = provider.getSigner()
const hoprDummyProxy = (await ethers.getContractFactory('HoprDummyProxyForNetworkRegistry'))
.connect(signer)
.attach(hoprDummyProxyAddress) as HoprDummyProxyForNetworkRegistry
const hoprNetworkRegistry = (await ethers.getContractFactory('HoprNetworkRegistry'))
.connect(signer)
.attach(hoprNetworkRegistryAddress) as HoprNetworkRegistry
const isEnabled = await hoprNetworkRegistry.enabled()
try {
if (opts.task === 'add') {
const nativeAddresses = opts.nativeAddresses.split(',')
const peerIds = opts.peerIds.split(',')
// ensure lists match in length
if (nativeAddresses.length !== peerIds.length) {
console.error('Given native and multiaddress lists do not match in length.')
process.exit(1)
}
// ensure all native addresses are valid
if (nativeAddresses.some((a) => !utils.isAddress(a))) {
console.error(`Given address list '${nativeAddresses.join(',')}' contains an invalid address.`)
process.exit(1)
}
await (await hoprDummyProxy.ownerBatchAddAccounts(nativeAddresses)).wait()
await (await hoprNetworkRegistry.ownerRegister(nativeAddresses, peerIds)).wait()
} else if (opts.task === 'enable' && !isEnabled) {
await (await hoprNetworkRegistry.enableRegistry()).wait()
} else if (opts.task === 'disable' && isEnabled) {
await (await hoprNetworkRegistry.disableRegistry()).wait()
} else {
throw Error(`Task "${opts.task}" not available.`)
}
} catch (error) {
console.error('Failed to add account with error:', error)
process.exit(1)
}
}