import fs from "fs-extra" ; import { TASK_COMPILE_SOLIDITY_GET_ARTIFACT_FROM_COMPILATION_OUTPUT , } from "hardhat/builtin-tasks/task-names" ; import { TASK_TYPECHAIN_GENERATE_TYPES } from "@typechain/hardhat/dist/constants" ; import { subtask } from "hardhat/config" ; import { addGasToAbiMethods , removeGasFromAbiMethods } from "../utils/tasks" ; subtask ( TASK_COMPILE_SOLIDITY_GET_ARTIFACT_FROM_COMPILATION_OUTPUT ) . setAction ( async ( _ , { network } , runSuper ) => { const artifact = await runSuper ( ) ; if ( ! process . env . SKIP_ABI_GAS_MODS ) { artifact . abi = addGasToAbiMethods ( network . config , artifact . abi ) ; } return artifact ; } ) ; subtask ( TASK_TYPECHAIN_GENERATE_TYPES ) . setAction ( async ( _ , env , runSuper ) => { const artifacts = [ ] ; for ( const project of ( env . config as any ) . externalGasMods ) { const files = fs . readdirSync ( project ) ; for ( const file of files ) { const artifactPath = `${ process . cwd ( ) }/${ project }/${ file }` ; const artifact = require ( artifactPath ) ; artifact . abi = addGasToAbiMethods ( env . network . config , artifact . abi ) ; fs . outputFileSync ( artifactPath , JSON . stringify ( artifact , undefined , "  " ) ) ; artifacts . push ( { artifact , artifactPath } ) ; } } await runSuper ( ) ; for ( const item of artifacts ) { item . artifact . abi = removeGasFromAbiMethods ( item . artifact . abi ) ; fs . outputFileSync ( item . artifactPath , JSON . stringify ( item . artifact , undefined , "  " ) ) ; } } ) ; export { } ;