|
| 1 | +import { task } from 'hardhat/config' |
| 2 | +import { HardhatRuntimeEnvironment } from 'hardhat/types' |
| 3 | +import { runTenderlyUpload } from '@graphprotocol/toolshed/hardhat' |
| 4 | +import addresses from '../addresses.json' |
| 5 | +import path from 'path' |
| 6 | + |
| 7 | +task('tenderly:upload', 'Upload and verify contracts on Tenderly') |
| 8 | + .addFlag('noVerify', 'Skip contract verification') |
| 9 | + .addFlag('skipAdd', 'Skip adding contracts (only verify)') |
| 10 | + .setAction(async (taskArgs: { noVerify: boolean; skipAdd: boolean }, hre: HardhatRuntimeEnvironment) => { |
| 11 | + // Dynamically import tenderly plugin only when this task runs |
| 12 | + // This avoids triggering provider initialization for other hardhat commands |
| 13 | + // eslint-disable-next-line @typescript-eslint/no-require-imports |
| 14 | + const { Tenderly } = require('@tenderly/hardhat-integration') |
| 15 | + // eslint-disable-next-line @typescript-eslint/no-require-imports |
| 16 | + const { lazyObject } = require('hardhat/plugins') |
| 17 | + // eslint-disable-next-line @typescript-eslint/no-require-imports |
| 18 | + const { configExists, getAccessToken } = require('@tenderly/api-client/utils/config') |
| 19 | + |
| 20 | + // Manually attach tenderly to hre since extendEnvironment already ran |
| 21 | + if (!(hre as any).tenderly) { |
| 22 | + ;(hre as any).tenderly = lazyObject(() => new Tenderly(hre)) |
| 23 | + } |
| 24 | + |
| 25 | + if (!configExists()) { |
| 26 | + throw new Error( |
| 27 | + 'Tenderly config not found. Run `tenderly login` to authenticate, or create ~/.tenderly/config.yaml manually.', |
| 28 | + ) |
| 29 | + } |
| 30 | + |
| 31 | + const accessToken = getAccessToken() |
| 32 | + const packageDir = path.join(__dirname, '..') |
| 33 | + |
| 34 | + await runTenderlyUpload(hre, packageDir, addresses, accessToken, taskArgs) |
| 35 | + }) |
0 commit comments