diff --git a/.github/actions/cache-evm-artifacts/action.yml b/.github/actions/cache-evm-artifacts/action.yml index 9fa0527af..67ff4b764 100644 --- a/.github/actions/cache-evm-artifacts/action.yml +++ b/.github/actions/cache-evm-artifacts/action.yml @@ -23,7 +23,7 @@ runs: # The job that generates the artifacts is responsible for archiving them to the cache tarball. This avoids any # conflicts with other caching actions that might have cleaned some of cached contents. path: evm-artifacts.tar - key: evm-artifacts-${{ runner.os }}-node-${{ steps.resolved-node.outputs.version }}-${{ hashFiles('yarn.lock', 'hardhat.config.ts', 'contracts/**/*.sol') }} + key: evm-artifacts-${{ runner.os }}-node-${{ steps.resolved-node.outputs.version }}-${{ hashFiles('yarn.lock', 'hardhat.config.ts', 'foundry.toml', 'contracts/**/*.sol') }} - name: Unpack restored EVM artifacts if: steps.evm-artifacts-cache.outputs.cache-hit == 'true' shell: bash diff --git a/.github/actions/generate-evm-artifacts/action.yml b/.github/actions/generate-evm-artifacts/action.yml index 0ae401266..9b2edbff6 100644 --- a/.github/actions/generate-evm-artifacts/action.yml +++ b/.github/actions/generate-evm-artifacts/action.yml @@ -16,9 +16,23 @@ runs: - name: Install packages shell: bash run: yarn install --frozen-lockfile - - name: Build EVM + - name: Build Hardhat shell: bash run: yarn build-evm + - name: Install Foundry + uses: foundry-rs/foundry-toolchain@v1 + - name: Install forge dependencies + shell: bash + run: forge install + - name: Build Foundry + shell: bash + run: forge build --skip test script + - name: Generate Typechain artifacts + shell: bash + run: npx ts-node scripts/typechainArtifacts.ts + - name: Generate Typechain + shell: bash + run: npx typechain --target ethers-v5 "typechain-artifacts/**/*.json" --out-dir typechain - name: Archive EVM artifacts (for caching) shell: bash env: diff --git a/.gitignore b/.gitignore index 147e874f2..2746c1796 100644 --- a/.gitignore +++ b/.gitignore @@ -31,6 +31,9 @@ out zkout cache-foundry +# Typechain +typechain-artifacts + # Upgradeability files .openzeppelin diff --git a/hardhat.config.ts b/hardhat.config.ts index 12e7d866d..40ffc98fa 100644 --- a/hardhat.config.ts +++ b/hardhat.config.ts @@ -1,12 +1,14 @@ const { subtask } = require("hardhat/config"); const { TASK_COMPILE_SOLIDITY_GET_SOURCE_PATHS } = require("hardhat/builtin-tasks/task-names"); +const isTest = process.env.IS_TEST === "true" || process.env.CI === "true"; + subtask(TASK_COMPILE_SOLIDITY_GET_SOURCE_PATHS).setAction(async (_: any, __: any, runSuper: any) => { const paths = await runSuper(); // Filter out files that cause problems when using "paris" hardfork (currently used to compile everything when IS_TEST=true) // Reference: https://github.com/NomicFoundation/hardhat/issues/2306#issuecomment-1039452928 - if (process.env.IS_TEST === "true") { + if (isTest) { return paths.filter((p: any) => { return ( !p.includes("contracts/periphery/mintburn") && @@ -28,7 +30,6 @@ import { getNodeUrl } from "./utils"; import "@nomicfoundation/hardhat-verify"; // Must be above hardhat-upgrades import "@nomiclabs/hardhat-waffle"; -import "@typechain/hardhat"; import "@matterlabs/hardhat-zksync-solc"; import "@matterlabs/hardhat-zksync-verify"; import "@matterlabs/hardhat-zksync-upgradable"; @@ -70,8 +71,6 @@ const tasks = [ // eslint-disable-next-line node/no-missing-require tasks.forEach((task) => require(`./tasks/${task}`)); -const isTest = process.env.IS_TEST === "true"; - // To compile with zksolc, `hardhat` must be the default network and its `zksync` property must be true. // So we allow the caller to set this environment variable to toggle compiling zk contracts or not. // TODO: Figure out way to only compile specific contracts intended to be deployed on ZkSync (e.g. ZkSync_SpokePool) if @@ -82,6 +81,7 @@ const solcVersion = "0.8.30"; // Hardhat 2.14.0 doesn't support prague yet, so we use paris instead (need to upgrade to v3 to use prague) const evmVersion = isTest ? "paris" : "prague"; +const revertStrings = isTest ? "debug" : "strip"; // Compilation settings are overridden for large contracts to allow them to compile without going over the bytecode // limit. @@ -91,7 +91,7 @@ const LARGE_CONTRACT_COMPILER_SETTINGS = { optimizer: { enabled: true, runs: 800 }, viaIR: true, evmVersion, - debug: { revertStrings: isTest ? "debug" : "strip" }, + debug: { revertStrings }, }, }; const DEFAULT_CONTRACT_COMPILER_SETTINGS = { @@ -101,7 +101,7 @@ const DEFAULT_CONTRACT_COMPILER_SETTINGS = { viaIR: true, evmVersion, // Only strip revert strings if not testing or in ci. - debug: { revertStrings: isTest ? "debug" : "strip" }, + debug: { revertStrings }, }, }; // This is only used by Blast_SpokePool for now, as it's the largest bytecode-wise @@ -111,7 +111,7 @@ const LARGEST_CONTRACT_COMPILER_SETTINGS = { optimizer: { enabled: true, runs: 50 }, viaIR: true, evmVersion, - debug: { revertStrings: isTest ? "debug" : "strip" }, + debug: { revertStrings }, }, }; @@ -396,10 +396,6 @@ const config: HardhatUserConfig = { ], }, namedAccounts: { deployer: 0 }, - typechain: { - outDir: "./typechain", - target: "ethers-v5", - }, paths: { tests: "./test/evm/hardhat", }, diff --git a/package.json b/package.json index 94dbd4279..07f10e931 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@across-protocol/contracts", - "version": "4.1.17-beta.4", + "version": "4.1.19-alpha.3", "author": "UMA Team", "license": "AGPL-3.0-only", "repository": { @@ -95,7 +95,6 @@ "@openzeppelin/hardhat-upgrades": "^1.22.0", "@pinata/sdk": "^2.1.0", "@typechain/ethers-v5": "^11.0.0", - "@typechain/hardhat": "^8.0.0", "@types/bn.js": "^5.1.0", "@types/chai": "^4.3.5", "@types/mocha": "^9.0.0", diff --git a/script/mintburn/cctp/113DeploySponsoredCCTPSrcPeriphery.sol b/script/mintburn/cctp/113DeploySponsoredCCTPSrcPeriphery.s.sol similarity index 100% rename from script/mintburn/cctp/113DeploySponsoredCCTPSrcPeriphery.sol rename to script/mintburn/cctp/113DeploySponsoredCCTPSrcPeriphery.s.sol diff --git a/script/mintburn/cctp/114DeploySponsoredCCTPDstPeriphery.sol b/script/mintburn/cctp/114DeploySponsoredCCTPDstPeriphery.s.sol similarity index 100% rename from script/mintburn/cctp/114DeploySponsoredCCTPDstPeriphery.sol rename to script/mintburn/cctp/114DeploySponsoredCCTPDstPeriphery.s.sol diff --git a/scripts/typechainArtifacts.ts b/scripts/typechainArtifacts.ts new file mode 100644 index 000000000..73e1c9b70 --- /dev/null +++ b/scripts/typechainArtifacts.ts @@ -0,0 +1,46 @@ +import fs from "fs"; +import path from "path"; +import fg from "fast-glob"; + +const OUT_DIR = "out"; +const STAGE_DIR = "typechain-artifacts"; + +function main() { + if (fs.existsSync(STAGE_DIR)) { + fs.rmdirSync(STAGE_DIR, { recursive: true }); + } + fs.mkdirSync(STAGE_DIR, { recursive: true }); + + const files = fg.sync([`${OUT_DIR}/**/*.json`, `!${OUT_DIR}/build-info/**`], { + dot: false, + onlyFiles: true, + }); + + const seen = new Map(); // contractName -> first file path kept + const dups: Array<{ name: string; kept: string; dropped: string }> = []; + + for (const file of files) { + const name = file.split("/").pop()?.split(".")[0]; + if (!name) continue; + + const already = seen.get(name); + if (already) { + dups.push({ name, kept: already, dropped: file }); + continue; + } + + seen.set(name, file); + + // One artifact per name => stable TypeChain inputs + const dest = path.join(STAGE_DIR, `${name}.json`); + fs.copyFileSync(file, dest); + } + + if (dups.length > 0) { + console.warn(`\nTypeChain dedupe: dropped ${dups.length} duplicate contract names:\n`); + } + + console.log(`Staged ${seen.size} unique artifacts into ${STAGE_DIR}/`); +} + +main(); diff --git a/test/evm/hardhat/chain-adapters/Arbitrum_Adapter.ts b/test/evm/hardhat/chain-adapters/Arbitrum_Adapter.ts index 57c31b866..51c110e28 100644 --- a/test/evm/hardhat/chain-adapters/Arbitrum_Adapter.ts +++ b/test/evm/hardhat/chain-adapters/Arbitrum_Adapter.ts @@ -27,8 +27,8 @@ import { MessagingReceiptStructOutput, OFTReceiptStructOutput, SendParamStruct, -} from "../../../../typechain/contracts/interfaces/IOFT.sol/IOFT"; -import { IOFT__factory } from "../../../../typechain/factories/contracts/interfaces/IOFT.sol/IOFT__factory"; +} from "../../../../typechain/IOFT"; +import { IOFT__factory } from "../../../../typechain/factories/IOFT__factory"; import { hubPoolFixture, enableTokensForLP } from "../fixtures/HubPool.Fixture"; import { constructSingleChainTree } from "../MerkleLib.utils"; import { CIRCLE_DOMAIN_IDs } from "../../../../deploy/consts"; diff --git a/test/evm/hardhat/chain-adapters/Polygon_Adapter.ts b/test/evm/hardhat/chain-adapters/Polygon_Adapter.ts index f8f3850a6..05500d63f 100644 --- a/test/evm/hardhat/chain-adapters/Polygon_Adapter.ts +++ b/test/evm/hardhat/chain-adapters/Polygon_Adapter.ts @@ -32,8 +32,8 @@ import { MessagingReceiptStructOutput, OFTReceiptStructOutput, SendParamStruct, -} from "../../../../typechain/contracts/interfaces/IOFT.sol/IOFT"; -import { IOFT__factory } from "../../../../typechain/factories/contracts/interfaces/IOFT.sol/IOFT__factory"; +} from "../../../../typechain/IOFT"; +import { IOFT__factory } from "../../../../typechain/factories/IOFT__factory"; import { CIRCLE_DOMAIN_IDs } from "../../../../deploy/consts"; import { AdapterStore, AdapterStore__factory } from "../../../../typechain"; import { CHAIN_IDs } from "@across-protocol/constants"; diff --git a/test/evm/hardhat/chain-specific-spokepools/Arbitrum_SpokePool.ts b/test/evm/hardhat/chain-specific-spokepools/Arbitrum_SpokePool.ts index 690d3a206..aa720e344 100644 --- a/test/evm/hardhat/chain-specific-spokepools/Arbitrum_SpokePool.ts +++ b/test/evm/hardhat/chain-specific-spokepools/Arbitrum_SpokePool.ts @@ -26,8 +26,8 @@ import { MessagingReceiptStructOutput, OFTReceiptStructOutput, SendParamStruct, -} from "../../../../typechain/contracts/interfaces/IOFT.sol/IOFT"; -import { IOFT__factory } from "../../../../typechain/factories/contracts/interfaces/IOFT.sol/IOFT__factory"; +} from "../../../../typechain/IOFT"; +import { IOFT__factory } from "../../../../typechain/factories/IOFT__factory"; import { CHAIN_IDs } from "@across-protocol/constants"; let hubPool: Contract, arbitrumSpokePool: Contract, dai: Contract, weth: Contract, l2UsdtContract: Contract; diff --git a/test/evm/hardhat/chain-specific-spokepools/Polygon_SpokePool.ts b/test/evm/hardhat/chain-specific-spokepools/Polygon_SpokePool.ts index b3989e5c3..01b37e101 100644 --- a/test/evm/hardhat/chain-specific-spokepools/Polygon_SpokePool.ts +++ b/test/evm/hardhat/chain-specific-spokepools/Polygon_SpokePool.ts @@ -25,13 +25,13 @@ import { } from "../../../../utils/utils"; import { getOftEid } from "../../../../utils/utils"; import { CHAIN_IDs } from "@across-protocol/constants"; -import { IOFT__factory } from "../../../../typechain/factories/contracts/interfaces/IOFT.sol/IOFT__factory"; +import { IOFT__factory } from "../../../../typechain/factories/IOFT__factory"; import { MessagingFeeStructOutput, MessagingReceiptStructOutput, OFTReceiptStructOutput, SendParamStruct, -} from "../../../../typechain/contracts/interfaces/IOFT.sol/IOFT"; +} from "../../../../typechain/IOFT"; import { hre } from "../../../../utils/utils.hre"; import { hubPoolFixture } from "../fixtures/HubPool.Fixture"; import { buildRelayerRefundLeaves, buildRelayerRefundTree, constructSingleRelayerRefundTree } from "../MerkleLib.utils"; diff --git a/yarn.lock b/yarn.lock index 5b1feb8a7..c8334063a 100644 --- a/yarn.lock +++ b/yarn.lock @@ -3993,13 +3993,6 @@ dependencies: ethers "^5.0.2" -"@typechain/hardhat@^8.0.0": - version "8.0.0" - resolved "https://registry.yarnpkg.com/@typechain/hardhat/-/hardhat-8.0.0.tgz#60568b7a2d0260cc741fb0830a8caee8eb06ac64" - integrity sha512-XUVbqlMx8tJTOmzZCD/r196CidtNWAnTBZRcYxjLTKgcJMvc/kHQpWBnVMMB5QHxVKpYpCiz8g07FYCpG8rrjA== - dependencies: - fs-extra "^9.1.0" - "@types/async-eventemitter@^0.2.1": version "0.2.1" resolved "https://registry.yarnpkg.com/@types/async-eventemitter/-/async-eventemitter-0.2.1.tgz#f8e6280e87e8c60b2b938624b0a3530fb3e24712" @@ -9710,7 +9703,7 @@ fs-extra@^8.1.0: jsonfile "^4.0.0" universalify "^0.1.0" -fs-extra@^9.0.0, fs-extra@^9.1.0: +fs-extra@^9.0.0: version "9.1.0" resolved "https://registry.yarnpkg.com/fs-extra/-/fs-extra-9.1.0.tgz#5954460c764a8da2094ba3554bf839e6b9a7c86d" integrity sha512-hcg3ZmepS30/7BSFqRvoo3DOMQu7IjqxO5nCDt+zM9XWjb33Wg7ziNT+Qvqbuc3+gWpzO02JubVyk2G4Zvo1OQ==