From 3c5ed0bac65accfa1ac72771c201ae5c8d37a9a1 Mon Sep 17 00:00:00 2001 From: Jawad <38837406+JDawg287@users.noreply.github.com> Date: Tue, 19 Mar 2024 12:04:51 -0400 Subject: [PATCH] Revert "feat: add multi-target Typechain typings build option" (#130) --- README.md | 32 -------------- hardhat.config.ts | 7 ---- scripts/const-addr-deployer.ts | 2 +- scripts/deploy-subnet-registrator.ts | 2 +- scripts/deploy-topos-core.ts | 8 ++-- scripts/deploy-topos-msg-protocol-dynamic.ts | 12 +++--- scripts/deploy-topos-msg-protocol.ts | 3 +- scripts/register-subnet.ts | 6 +-- scripts/test/send-token.ts | 9 ++-- scripts/upgrade-topos-core.ts | 6 +-- tasks/compile.ts | 42 ------------------- .../BurnableMintableCappedERC20.test.ts | 6 +-- test/topos-core/Bytes32Sets.test.ts | 6 +-- test/topos-core/SubnetRegistrator.test.ts | 6 +-- test/topos-core/ToposCore.test.ts | 11 ++--- test/topos-core/ToposMessaging.test.ts | 2 +- tsconfig.json | 2 +- 17 files changed, 31 insertions(+), 131 deletions(-) delete mode 100644 tasks/compile.ts diff --git a/README.md b/README.md index 32c5673..d802e0c 100644 --- a/README.md +++ b/README.md @@ -52,38 +52,6 @@ To build: $ npm run build ``` -## Build contracts with different Typechain target - -To build different Typechain target: - -``` -npx hardhat compile --typechain-target target -``` - -Where `target` can be `ethers-v6`, `web3-v1`, etc. - -*Note: you need to install the appropriate package for the target you want to build for. For example, to build for `web3-v1`, you need to install `@typechain/web3-v1` package.* - -Default target is `ethers-v6` and it is output to `typechain-types/ethers-v6` directory. - -You can specify the target in several ways: -- By setting the `TYPECHAIN_TARGET` environment variable -```bash -export TYPECHAIN_TARGET=web3-v1 -``` -- By setting the `--typechain-target` command line option -```bash -npx hardhat compile --typechain-target web3-v1 -``` -- By setting the `typechain` field in `hardhat.config.ts` -```typescript -module.exports = { - typechain: { - target: 'web3-v1' - } -} -``` - ## Tests To run the tests: diff --git a/hardhat.config.ts b/hardhat.config.ts index 2685104..bcedbd0 100644 --- a/hardhat.config.ts +++ b/hardhat.config.ts @@ -1,8 +1,6 @@ import { HardhatUserConfig } from 'hardhat/config' import '@nomicfoundation/hardhat-toolbox' -import './tasks/compile' - const config: HardhatUserConfig = { solidity: { version: '0.8.9', @@ -13,11 +11,6 @@ const config: HardhatUserConfig = { }, }, }, - typechain: { - // default 'ethers-v6' - outDir: 'typechain-types/ethers-v6', - target: 'ethers-v6', - }, } export default config diff --git a/scripts/const-addr-deployer.ts b/scripts/const-addr-deployer.ts index 1c457da..c28b98c 100644 --- a/scripts/const-addr-deployer.ts +++ b/scripts/const-addr-deployer.ts @@ -8,7 +8,7 @@ import { Wallet, } from 'ethers' -import { ConstAddressDeployer__factory } from '../typechain-types/ethers-v6' +import { ConstAddressDeployer__factory } from '../typechain-types/factories/contracts/topos-core/ConstAddressDeployer__factory' export type Arg = string | number diff --git a/scripts/deploy-subnet-registrator.ts b/scripts/deploy-subnet-registrator.ts index 4864d6f..ef95a51 100644 --- a/scripts/deploy-subnet-registrator.ts +++ b/scripts/deploy-subnet-registrator.ts @@ -1,7 +1,7 @@ import { computeAddress, isHexString, JsonRpcProvider, Wallet } from 'ethers' import subnetRegistratorJSON from '../artifacts/contracts/topos-core/SubnetRegistrator.sol/SubnetRegistrator.json' -import { SubnetRegistrator__factory } from '../typechain-types/ethers-v6' +import { SubnetRegistrator__factory } from '../typechain-types/factories/contracts/topos-core/SubnetRegistrator__factory' import { Arg, deployContractConstant } from './const-addr-deployer' const main = async function (..._args: Arg[]) { diff --git a/scripts/deploy-topos-core.ts b/scripts/deploy-topos-core.ts index ef92ec6..58b0a31 100644 --- a/scripts/deploy-topos-core.ts +++ b/scripts/deploy-topos-core.ts @@ -1,10 +1,8 @@ import { isHexString, JsonRpcProvider, Wallet } from 'ethers' -import { - ToposCore, - ToposCore__factory, - ToposCoreProxy__factory, -} from '../typechain-types/ethers-v6' +import { ToposCore__factory } from '../typechain-types/factories/contracts/topos-core/ToposCore__factory' +import { ToposCoreProxy__factory } from '../typechain-types/factories/contracts/topos-core/ToposCoreProxy__factory' +import { ToposCore } from '../typechain-types/contracts/topos-core/ToposCore' const main = async function (...args: string[]) { const [_providerEndpoint, _sequencerPrivateKey, _gasLimit] = args diff --git a/scripts/deploy-topos-msg-protocol-dynamic.ts b/scripts/deploy-topos-msg-protocol-dynamic.ts index afcbb62..72391f3 100644 --- a/scripts/deploy-topos-msg-protocol-dynamic.ts +++ b/scripts/deploy-topos-msg-protocol-dynamic.ts @@ -1,12 +1,10 @@ import { isHexString, JsonRpcProvider, Wallet } from 'ethers' -import { - ERC20Messaging__factory, - TokenDeployer__factory, - ToposCore__factory, - ToposCoreProxy__factory, - ToposCore, -} from '../typechain-types/ethers-v6' +import { TokenDeployer__factory } from '../typechain-types/factories/contracts/topos-core/TokenDeployer__factory' +import { ToposCore__factory } from '../typechain-types/factories/contracts/topos-core/ToposCore__factory' +import { ToposCoreProxy__factory } from '../typechain-types/factories/contracts/topos-core/ToposCoreProxy__factory' +import { ERC20Messaging__factory } from '../typechain-types/factories/contracts/examples/ERC20Messaging__factory' +import { ToposCore } from '../typechain-types/contracts/topos-core/ToposCore' const main = async function (...args: string[]) { const [providerEndpoint, _sequencerPrivateKey] = args diff --git a/scripts/deploy-topos-msg-protocol.ts b/scripts/deploy-topos-msg-protocol.ts index b241cad..d1002d6 100644 --- a/scripts/deploy-topos-msg-protocol.ts +++ b/scripts/deploy-topos-msg-protocol.ts @@ -10,7 +10,8 @@ import { deployContractConstant, predictContractConstant, } from './const-addr-deployer' -import { ToposCore__factory, ToposCore } from '../typechain-types/ethers-v6' +import { ToposCore__factory } from '../typechain-types/factories/contracts/topos-core/ToposCore__factory' +import { ToposCore } from '../typechain-types/contracts/topos-core/ToposCore' const main = async function (...args: string[]) { const [providerEndpoint, _sequencerPrivateKey] = args diff --git a/scripts/register-subnet.ts b/scripts/register-subnet.ts index 0889d0d..cdd223f 100644 --- a/scripts/register-subnet.ts +++ b/scripts/register-subnet.ts @@ -1,9 +1,7 @@ import { isHexString, JsonRpcProvider, Wallet } from 'ethers' -import { - SubnetRegistrator, - SubnetRegistrator__factory, -} from '../typechain-types/ethers-v6' +import { SubnetRegistrator__factory } from '../typechain-types/factories/contracts/topos-core/SubnetRegistrator__factory' +import { SubnetRegistrator } from '../typechain-types/contracts/topos-core/SubnetRegistrator' const main = async function (...args: string[]) { const [ diff --git a/scripts/test/send-token.ts b/scripts/test/send-token.ts index b86cff0..d1ef103 100644 --- a/scripts/test/send-token.ts +++ b/scripts/test/send-token.ts @@ -1,10 +1,7 @@ import { isHexString, JsonRpcProvider, Wallet } from 'ethers' - -import { - BurnableMintableCappedERC20__factory, - ERC20Messaging, - ERC20Messaging__factory, -} from '../../typechain-types/ethers-v6' +import { ERC20Messaging__factory } from '../../typechain-types/factories/contracts/examples/ERC20Messaging__factory' +import { BurnableMintableCappedERC20__factory } from '../../typechain-types/factories/contracts/topos-core/BurnableMintableCappedERC20__factory' +import { ERC20Messaging } from '../../typechain-types/contracts/examples/ERC20Messaging' import * as cc from '../../test/topos-core/shared/constants/certificates' import * as tc from '../../test/topos-core/shared/constants/tokens' import * as testUtils from '../../test/topos-core/shared/utils/common' diff --git a/scripts/upgrade-topos-core.ts b/scripts/upgrade-topos-core.ts index 3d64401..700f93a 100644 --- a/scripts/upgrade-topos-core.ts +++ b/scripts/upgrade-topos-core.ts @@ -8,10 +8,8 @@ import { Wallet, } from 'ethers' -import { - ToposCore__factory, - CodeHash__factory, -} from '../typechain-types/ethers-v6' +import { ToposCore__factory } from '../typechain-types/factories/contracts/topos-core/ToposCore__factory' +import { CodeHash__factory } from '../typechain-types/factories/contracts/topos-core/CodeHash__factory' import toposCoreJSON from '../artifacts/contracts/topos-core/ToposCore.sol/ToposCore.json' diff --git a/tasks/compile.ts b/tasks/compile.ts deleted file mode 100644 index 1a820c1..0000000 --- a/tasks/compile.ts +++ /dev/null @@ -1,42 +0,0 @@ -import { task } from 'hardhat/config' - -enum SupportedTypechainTargets { - 'ethers-v5' = 'ethers-v5', - 'ethers-v6' = 'ethers-v6', - 'truffle-v4' = 'truffle-v4', - 'truffle-v5' = 'truffle-v5', - 'web3-v1' = 'web3-v1', -} - -/** - * This task overrides the original compile task to allow for setting the Typechain target - * via several methods: - * 1. Command line argument: `npx hardhat compile --typechain ethers-v5` - * 2. Environment variable: `TYPECHAIN_TARGET=ethers-v5 npx hardhat compile` - * 3. Hardhat config: `const config: HardhatUserConfig = { typechain: { target: 'ethers-v5' } }` - * @param args.typechainTarget (optional) The Typechain target to build for - */ -task( - 'compile', - 'Compiles the entire project, building all artifacts and custom Typechain typings' -) - .addOptionalParam('typechainTarget', 'The Typechain target to build for') - .setAction(async (args, hre, runSuper) => { - const typechainTarget = - args.typechainTarget || - process.env.TYPECHAIN_TARGET || - hre.config.typechain.target // default 'ethers-v6' - - // Validate the Typechain target - if (!Object.values(SupportedTypechainTargets).includes(typechainTarget)) { - throw new Error(`Unsupported typechain target: ${typechainTarget}`) - } - // Override the Typechain target - hre.config.typechain.target = typechainTarget - hre.config.typechain.outDir = `typechain-types/${typechainTarget}` - - // Call the original compile task - if (runSuper.isDefined) { - await runSuper(args) - } - }) diff --git a/test/topos-core/BurnableMintableCappedERC20.test.ts b/test/topos-core/BurnableMintableCappedERC20.test.ts index bff011e..66047a1 100644 --- a/test/topos-core/BurnableMintableCappedERC20.test.ts +++ b/test/topos-core/BurnableMintableCappedERC20.test.ts @@ -2,10 +2,8 @@ import { EventLog } from 'ethers' import { expect } from 'chai' import { ethers } from 'hardhat' -import { - BurnableMintableCappedERC20__factory, - TokenDeployer__factory, -} from '../../typechain-types/ethers-v6' +import { BurnableMintableCappedERC20__factory } from '../../typechain-types/factories/contracts/topos-core/BurnableMintableCappedERC20__factory' +import { TokenDeployer__factory } from '../../typechain-types/factories/contracts/topos-core/TokenDeployer__factory' import * as tc from './shared/constants/tokens' describe('BurnableMintableCappedERC20', () => { diff --git a/test/topos-core/Bytes32Sets.test.ts b/test/topos-core/Bytes32Sets.test.ts index 20a08b3..3f4eb18 100644 --- a/test/topos-core/Bytes32Sets.test.ts +++ b/test/topos-core/Bytes32Sets.test.ts @@ -1,10 +1,8 @@ import { ethers } from 'hardhat' import { expect } from 'chai' -import { - Bytes32SetsTest, - Bytes32SetsTest__factory, -} from '../../typechain-types/ethers-v6' +import { Bytes32SetsTest__factory } from '../../typechain-types/factories/contracts/topos-core/Bytes32Sets.sol/Bytes32SetsTest__factory' +import { Bytes32SetsTest } from '../../typechain-types/contracts/topos-core/Bytes32Sets.sol/Bytes32SetsTest' describe('Bytes32Sets', () => { let bytes32SetsTest: Bytes32SetsTest diff --git a/test/topos-core/SubnetRegistrator.test.ts b/test/topos-core/SubnetRegistrator.test.ts index f46fdb2..7061eff 100644 --- a/test/topos-core/SubnetRegistrator.test.ts +++ b/test/topos-core/SubnetRegistrator.test.ts @@ -2,10 +2,8 @@ import { Signer } from 'ethers' import { ethers } from 'hardhat' import { expect } from 'chai' -import { - SubnetRegistrator__factory, - SubnetRegistrator, -} from '../../typechain-types/ethers-v6' +import { SubnetRegistrator__factory } from '../../typechain-types/factories/contracts/topos-core/SubnetRegistrator__factory' +import { SubnetRegistrator } from '../../typechain-types' describe('SubnetRegistrator', () => { const chainId = 1 diff --git a/test/topos-core/ToposCore.test.ts b/test/topos-core/ToposCore.test.ts index ddd534d..6f84417 100644 --- a/test/topos-core/ToposCore.test.ts +++ b/test/topos-core/ToposCore.test.ts @@ -2,13 +2,10 @@ import { loadFixture } from '@nomicfoundation/hardhat-network-helpers' import { ethers } from 'hardhat' import { expect } from 'chai' -import { - CodeHash__factory, - ToposCore__factory, - ToposCoreProxy, - ToposCoreProxy__factory, -} from '../../typechain-types/ethers-v6' - +import { ToposCore__factory } from '../../typechain-types/factories/contracts/topos-core/ToposCore__factory' +import { ToposCoreProxy__factory } from '../../typechain-types/factories/contracts/topos-core/ToposCoreProxy__factory' +import { CodeHash__factory } from '../../typechain-types/factories/contracts/topos-core/CodeHash__factory' +import { ToposCoreProxy } from '../../typechain-types/contracts/topos-core/ToposCoreProxy' import * as cc from './shared/constants/certificates' import * as testUtils from './shared/utils/common' diff --git a/test/topos-core/ToposMessaging.test.ts b/test/topos-core/ToposMessaging.test.ts index 5cb7a56..a12442c 100644 --- a/test/topos-core/ToposMessaging.test.ts +++ b/test/topos-core/ToposMessaging.test.ts @@ -15,7 +15,7 @@ import { ToposCoreProxy__factory, ERC20Messaging__factory, ERC20Messaging, -} from '../../typechain-types/ethers-v6' +} from '../../typechain-types' import * as cc from './shared/constants/certificates' import * as testUtils from './shared/utils/common' import { getReceiptMptProof } from './shared/utils/mpt_proof' diff --git a/tsconfig.json b/tsconfig.json index 7ccde2c..63cc994 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -9,6 +9,6 @@ "skipLibCheck": true, "resolveJsonModule": true }, - "include": ["./scripts", "./test", "./typechain-types", "./tasks"], + "include": ["./scripts", "./test", "./typechain-types"], "files": ["./hardhat.config.ts"] }