From 5866ec515e1fe3d5ad64732972c826ac22a6ad9b Mon Sep 17 00:00:00 2001 From: Jakub Nowakowski Date: Thu, 28 Dec 2023 21:47:43 +0100 Subject: [PATCH 1/8] Import ethers from hardhat When using ethers we should import it from hardhat. --- core/test/Acre.test.ts | 1 + core/test/helpers/contract.ts | 3 +-- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/core/test/Acre.test.ts b/core/test/Acre.test.ts index 4a5960e3e..b4f176830 100644 --- a/core/test/Acre.test.ts +++ b/core/test/Acre.test.ts @@ -3,6 +3,7 @@ import { loadFixture, } from "@nomicfoundation/hardhat-toolbox/network-helpers" import { expect } from "chai" +import { ethers } from "hardhat" import { ContractTransactionResponse, ZeroAddress } from "ethers" import type { HardhatEthersSigner } from "@nomicfoundation/hardhat-ethers/signers" diff --git a/core/test/helpers/contract.ts b/core/test/helpers/contract.ts index 88a83812a..6ba7b36ae 100644 --- a/core/test/helpers/contract.ts +++ b/core/test/helpers/contract.ts @@ -1,5 +1,4 @@ -import { ethers } from "ethers" -import { deployments } from "hardhat" +import { deployments, ethers } from "hardhat" import type { BaseContract } from "ethers" import { getUnnamedSigner } from "./signer" From 58576bd62a8ca07304f460582a96104448712a6f Mon Sep 17 00:00:00 2001 From: Jakub Nowakowski Date: Thu, 28 Dec 2023 21:48:44 +0100 Subject: [PATCH 2/8] Update @thesis-co/eslint-config to the latest version This version enables `@typescript-eslint/recommended-type-checked` rules. The commit hash refers to the merge commit of https://github.com/thesis/eslint-config/pull/12. --- core/package.json | 2 +- pnpm-lock.yaml | 44 ++++++++++++++++++++++++++++++++++++++------ sdk/package.json | 2 +- website/package.json | 2 +- 4 files changed, 41 insertions(+), 9 deletions(-) diff --git a/core/package.json b/core/package.json index ff7aa5197..ca5b4e175 100644 --- a/core/package.json +++ b/core/package.json @@ -35,7 +35,7 @@ "@nomicfoundation/hardhat-verify": "^2.0.1", "@nomiclabs/hardhat-etherscan": "^3.1.7", "@openzeppelin/hardhat-upgrades": "^2.4.1", - "@thesis-co/eslint-config": "^0.6.1", + "@thesis-co/eslint-config": "github:thesis/eslint-config#7b9bc8c", "@typechain/ethers-v6": "^0.5.1", "@typechain/hardhat": "^9.1.0", "@types/chai": "^4.3.11", diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 5c71a8afa..ccfe3ea52 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -46,8 +46,8 @@ importers: specifier: ^2.4.1 version: 2.4.1(@nomicfoundation/hardhat-ethers@3.0.5)(@nomicfoundation/hardhat-verify@2.0.1)(ethers@6.8.1)(hardhat@2.19.1) '@thesis-co/eslint-config': - specifier: ^0.6.1 - version: 0.6.1(eslint@8.54.0)(prettier@3.1.0)(typescript@5.3.2) + specifier: github:thesis/eslint-config#7b9bc8c + version: github.com/thesis/eslint-config/7b9bc8c(eslint@8.54.0)(prettier@3.1.0)(typescript@5.3.2) '@typechain/ethers-v6': specifier: ^0.5.1 version: 0.5.1(ethers@6.8.1)(typechain@8.3.2)(typescript@5.3.2) @@ -173,8 +173,8 @@ importers: sdk: devDependencies: '@thesis-co/eslint-config': - specifier: ^0.6.1 - version: 0.6.1(eslint@8.54.0)(prettier@3.1.0)(typescript@5.3.2) + specifier: github:thesis/eslint-config#7b9bc8c + version: github.com/thesis/eslint-config/7b9bc8c(eslint@8.54.0)(prettier@3.1.0)(typescript@5.3.2) '@types/chai': specifier: ^4.3.11 version: 4.3.11 @@ -225,8 +225,8 @@ importers: version: 6.1.0(react@18.2.0) devDependencies: '@thesis-co/eslint-config': - specifier: ^0.6.1 - version: 0.6.1(eslint@8.54.0)(prettier@3.1.0)(typescript@5.3.2) + specifier: github:thesis/eslint-config#7b9bc8c + version: github.com/thesis/eslint-config/7b9bc8c(eslint@8.54.0)(prettier@3.1.0)(typescript@5.3.2) '@types/node': specifier: ^20.9.4 version: 20.9.4 @@ -15476,6 +15476,38 @@ packages: resolution: {integrity: sha512-iC+8Io04lddc+mVqQ9AZ7OQ2MrUKGN+oIQyq1vemgt46jwCwLfhq7/pwnBnNXXXZb8VTVLKwp9EDkx+ryxIWmg==} dev: false + github.com/thesis/eslint-config/7b9bc8c(eslint@8.54.0)(prettier@3.1.0)(typescript@5.3.2): + resolution: {tarball: https://codeload.github.com/thesis/eslint-config/tar.gz/7b9bc8c} + id: github.com/thesis/eslint-config/7b9bc8c + name: '@thesis-co/eslint-config' + version: 0.8.0-pre + engines: {node: '>=14.0.0'} + peerDependencies: + eslint: '>=6.8.0' + dependencies: + '@thesis-co/prettier-config': github.com/thesis/prettier-config/daeaac564056a7885e4366ce12bfde6fd823fc90(prettier@3.1.0) + '@typescript-eslint/eslint-plugin': 6.12.0(@typescript-eslint/parser@6.12.0)(eslint@8.54.0)(typescript@5.3.2) + '@typescript-eslint/parser': 6.12.0(eslint@8.54.0)(typescript@5.3.2) + eslint: 8.54.0 + eslint-config-airbnb: 19.0.4(eslint-plugin-import@2.29.0)(eslint-plugin-jsx-a11y@6.8.0)(eslint-plugin-react-hooks@4.6.0)(eslint-plugin-react@7.33.2)(eslint@8.54.0) + eslint-config-airbnb-base: 15.0.0(eslint-plugin-import@2.29.0)(eslint@8.54.0) + eslint-config-airbnb-typescript: 17.1.0(@typescript-eslint/eslint-plugin@6.12.0)(@typescript-eslint/parser@6.12.0)(eslint-plugin-import@2.29.0)(eslint@8.54.0) + eslint-config-prettier: 9.0.0(eslint@8.54.0) + eslint-plugin-import: 2.29.0(@typescript-eslint/parser@6.12.0)(eslint@8.54.0) + eslint-plugin-jsx-a11y: 6.8.0(eslint@8.54.0) + eslint-plugin-no-only-tests: 3.1.0 + eslint-plugin-prettier: 5.0.1(eslint-config-prettier@9.0.0)(eslint@8.54.0)(prettier@3.1.0) + eslint-plugin-react: 7.33.2(eslint@8.54.0) + eslint-plugin-react-hooks: 4.6.0(eslint@8.54.0) + transitivePeerDependencies: + - '@types/eslint' + - eslint-import-resolver-typescript + - eslint-import-resolver-webpack + - prettier + - supports-color + - typescript + dev: true + github.com/thesis/prettier-config/daeaac564056a7885e4366ce12bfde6fd823fc90(prettier@3.1.0): resolution: {tarball: https://codeload.github.com/thesis/prettier-config/tar.gz/daeaac564056a7885e4366ce12bfde6fd823fc90} id: github.com/thesis/prettier-config/daeaac564056a7885e4366ce12bfde6fd823fc90 diff --git a/sdk/package.json b/sdk/package.json index 49d9e8580..2c95625aa 100644 --- a/sdk/package.json +++ b/sdk/package.json @@ -14,7 +14,7 @@ "test": "mocha --exit --recursive 'test/**/*.test.ts'" }, "devDependencies": { - "@thesis-co/eslint-config": "^0.6.1", + "@thesis-co/eslint-config": "github:thesis/eslint-config#7b9bc8c", "@types/chai": "^4.3.11", "@types/mocha": "^10.0.6", "@types/node": "^20.9.4", diff --git a/website/package.json b/website/package.json index 23f6fdb53..3d0dcc6fd 100644 --- a/website/package.json +++ b/website/package.json @@ -28,7 +28,7 @@ "react-helmet": "^6.1.0" }, "devDependencies": { - "@thesis-co/eslint-config": "^0.6.1", + "@thesis-co/eslint-config": "github:thesis/eslint-config#7b9bc8c", "@types/node": "^20.9.4", "@types/react": "^18.2.38", "@types/react-dom": "^18.2.17", From 57272f0f3c52082ec8aa4b609e9aabf8166e7f1b Mon Sep 17 00:00:00 2001 From: Jakub Nowakowski Date: Thu, 28 Dec 2023 22:07:37 +0100 Subject: [PATCH 3/8] Fix problems reported by eslint The problems were reported after the latest upgrade of eslint-config. --- core/deploy/00_resolve_tbtc.ts | 1 + core/deploy/21_transfer_ownership_acre.ts | 2 ++ core/deploy/22_transfer_ownership_acre_router.ts | 1 + core/test/Acre.test.ts | 16 ++++++++-------- 4 files changed, 12 insertions(+), 8 deletions(-) diff --git a/core/deploy/00_resolve_tbtc.ts b/core/deploy/00_resolve_tbtc.ts index dc1bfeff5..bf9f27d46 100644 --- a/core/deploy/00_resolve_tbtc.ts +++ b/core/deploy/00_resolve_tbtc.ts @@ -4,6 +4,7 @@ import { isNonZeroAddress } from "../helpers/address" const func: DeployFunction = async (hre: HardhatRuntimeEnvironment) => { const { getNamedAccounts, deployments } = hre + // eslint-disable-next-line @typescript-eslint/unbound-method const { log } = deployments const { deployer } = await getNamedAccounts() diff --git a/core/deploy/21_transfer_ownership_acre.ts b/core/deploy/21_transfer_ownership_acre.ts index c62708641..709a219b0 100644 --- a/core/deploy/21_transfer_ownership_acre.ts +++ b/core/deploy/21_transfer_ownership_acre.ts @@ -4,6 +4,7 @@ import type { DeployFunction } from "hardhat-deploy/types" const func: DeployFunction = async (hre: HardhatRuntimeEnvironment) => { const { getNamedAccounts, deployments } = hre const { deployer, governance } = await getNamedAccounts() + // eslint-disable-next-line @typescript-eslint/unbound-method const { log } = deployments log(`transferring ownership of Acre contract to ${governance}`) @@ -20,4 +21,5 @@ export default func func.tags = ["TransferOwnershipAcre"] // TODO: Enable once Acre extends Ownable +// eslint-disable-next-line @typescript-eslint/require-await func.skip = async () => true diff --git a/core/deploy/22_transfer_ownership_acre_router.ts b/core/deploy/22_transfer_ownership_acre_router.ts index 686d378c4..2c7322898 100644 --- a/core/deploy/22_transfer_ownership_acre_router.ts +++ b/core/deploy/22_transfer_ownership_acre_router.ts @@ -4,6 +4,7 @@ import type { DeployFunction } from "hardhat-deploy/types" const func: DeployFunction = async (hre: HardhatRuntimeEnvironment) => { const { getNamedAccounts, deployments } = hre const { deployer, governance } = await getNamedAccounts() + // eslint-disable-next-line @typescript-eslint/unbound-method const { log } = deployments log(`transferring ownership of Dispatcher contract to ${governance}`) diff --git a/core/test/Acre.test.ts b/core/test/Acre.test.ts index b4f176830..a292dffa4 100644 --- a/core/test/Acre.test.ts +++ b/core/test/Acre.test.ts @@ -21,8 +21,8 @@ async function fixture() { const [staker1, staker2] = await getUnnamedSigner() const amountToMint = to1e18(100000) - tbtc.mint(staker1, amountToMint) - tbtc.mint(staker2, amountToMint) + await tbtc.mint(staker1, amountToMint) + await tbtc.mint(staker2, amountToMint) return { acre, tbtc, staker1, staker2 } } @@ -38,7 +38,7 @@ describe("Acre", () => { }) describe("stake", () => { - const referral = ethers.encodeBytes32String("referral") + const referral: string = ethers.encodeBytes32String("referral") let snapshot: SnapshotRestorer context("when staking as first staker", () => { @@ -75,8 +75,8 @@ describe("Acre", () => { .stake(amountToStake, receiver.address, referral) }) - it("should emit Deposit event", () => { - expect(tx).to.emit(acre, "Deposit").withArgs( + it("should emit Deposit event", async () => { + await expect(tx).to.emit(acre, "Deposit").withArgs( // Caller. tbtcHolder.address, // Receiver. @@ -88,8 +88,8 @@ describe("Acre", () => { ) }) - it("should emit StakeReferral event", () => { - expect(tx) + it("should emit StakeReferral event", async () => { + await expect(tx) .to.emit(acre, "StakeReferral") .withArgs(referral, amountToStake) }) @@ -368,7 +368,7 @@ describe("Acre", () => { sharesBefore = await acre.balanceOf(staker1.address) availableToRedeemBefore = await acre.previewRedeem(sharesBefore) - tbtc.mint(staker1.address, newAmountToStake) + await tbtc.mint(staker1.address, newAmountToStake) await tbtc .connect(staker1) From f04bca6732d47935ee15aa68060d1192276e68ce Mon Sep 17 00:00:00 2001 From: Jakub Nowakowski Date: Thu, 28 Dec 2023 22:13:32 +0100 Subject: [PATCH 4/8] Run format after build in CI workflow Since the eslint rules we enabled for typescript with the latest eslint-config upgrade check typings, we need to ensure that `typechain/` directory is generated before we run eslint. For this reason we first run build and later format. --- .github/workflows/core.yaml | 33 ++++++++++++++++++++------------- 1 file changed, 20 insertions(+), 13 deletions(-) diff --git a/.github/workflows/core.yaml b/.github/workflows/core.yaml index a0501e05b..6b431ba4e 100644 --- a/.github/workflows/core.yaml +++ b/.github/workflows/core.yaml @@ -13,7 +13,7 @@ defaults: working-directory: ./core jobs: - core-format: + core-build: runs-on: ubuntu-latest steps: - uses: actions/checkout@v4 @@ -30,10 +30,20 @@ jobs: - name: Install Dependencies run: pnpm install --prefer-offline --frozen-lockfile - - name: Format - run: pnpm run format + - name: Build + run: pnpm run build - core-build: + - name: Upload Build Artifacts + uses: actions/upload-artifact@v3 + with: + name: core-build + path: | + core/build/ + core/typechain/ + if-no-files-found: error + + core-format: + needs: [core-build] runs-on: ubuntu-latest steps: - uses: actions/checkout@v4 @@ -50,17 +60,14 @@ jobs: - name: Install Dependencies run: pnpm install --prefer-offline --frozen-lockfile - - name: Build - run: pnpm run build - - - name: Upload Build Artifacts - uses: actions/upload-artifact@v3 + - name: Download Build Artifacts + uses: actions/download-artifact@v3 with: name: core-build - path: | - core/build/ - core/typechain/ - if-no-files-found: error + path: core/ + + - name: Format + run: pnpm run format core-slither: needs: [core-build] From e74ac482449e2302f3578b2e00af7c60b508ae3c Mon Sep 17 00:00:00 2001 From: Jakub Nowakowski Date: Wed, 3 Jan 2024 12:57:40 +0100 Subject: [PATCH 5/8] Disable unbound-method for all deploy scripts Instead of adding inline comments for unbound-method rule we define it in the eslint config, as the `const { log } = deployments` is and will be broadly used in the scripts. --- core/.eslintrc | 10 +++++++++- core/deploy/00_resolve_tbtc.ts | 1 - core/deploy/21_transfer_ownership_acre.ts | 1 - core/deploy/22_transfer_ownership_acre_router.ts | 1 - 4 files changed, 9 insertions(+), 4 deletions(-) diff --git a/core/.eslintrc b/core/.eslintrc index 39419600b..67ae8e215 100644 --- a/core/.eslintrc +++ b/core/.eslintrc @@ -13,5 +13,13 @@ ] } ] - } + }, + "overrides": [ + { + "files": ["deploy/*.ts"], + "rules": { + "@typescript-eslint/unbound-method": "off" + } + } + ] } diff --git a/core/deploy/00_resolve_tbtc.ts b/core/deploy/00_resolve_tbtc.ts index bf9f27d46..dc1bfeff5 100644 --- a/core/deploy/00_resolve_tbtc.ts +++ b/core/deploy/00_resolve_tbtc.ts @@ -4,7 +4,6 @@ import { isNonZeroAddress } from "../helpers/address" const func: DeployFunction = async (hre: HardhatRuntimeEnvironment) => { const { getNamedAccounts, deployments } = hre - // eslint-disable-next-line @typescript-eslint/unbound-method const { log } = deployments const { deployer } = await getNamedAccounts() diff --git a/core/deploy/21_transfer_ownership_acre.ts b/core/deploy/21_transfer_ownership_acre.ts index df6794a7f..09a875a1d 100644 --- a/core/deploy/21_transfer_ownership_acre.ts +++ b/core/deploy/21_transfer_ownership_acre.ts @@ -4,7 +4,6 @@ import type { DeployFunction } from "hardhat-deploy/types" const func: DeployFunction = async (hre: HardhatRuntimeEnvironment) => { const { getNamedAccounts, deployments } = hre const { deployer, governance } = await getNamedAccounts() - // eslint-disable-next-line @typescript-eslint/unbound-method const { log } = deployments log(`transferring ownership of Acre contract to ${governance}`) diff --git a/core/deploy/22_transfer_ownership_acre_router.ts b/core/deploy/22_transfer_ownership_acre_router.ts index 2c7322898..686d378c4 100644 --- a/core/deploy/22_transfer_ownership_acre_router.ts +++ b/core/deploy/22_transfer_ownership_acre_router.ts @@ -4,7 +4,6 @@ import type { DeployFunction } from "hardhat-deploy/types" const func: DeployFunction = async (hre: HardhatRuntimeEnvironment) => { const { getNamedAccounts, deployments } = hre const { deployer, governance } = await getNamedAccounts() - // eslint-disable-next-line @typescript-eslint/unbound-method const { log } = deployments log(`transferring ownership of Dispatcher contract to ${governance}`) From cba01f4600195fe46dbdefc04543e6b51801cef1 Mon Sep 17 00:00:00 2001 From: Jakub Nowakowski Date: Thu, 4 Jan 2024 09:35:16 +0100 Subject: [PATCH 6/8] Disable no-unused-expressions for test files We want to use `to.be.true` instead of `to.be.equal(true)`, so we need to disable the rule. --- core/.eslintrc | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/core/.eslintrc b/core/.eslintrc index 67ae8e215..8090228c6 100644 --- a/core/.eslintrc +++ b/core/.eslintrc @@ -20,6 +20,12 @@ "rules": { "@typescript-eslint/unbound-method": "off" } + }, + { + "files": ["*.test.ts"], + "rules": { + "@typescript-eslint/no-unused-expressions": "off" + } } ] } From 3a585e4db8fa7d07bf34a6d292c94ab96b26ed43 Mon Sep 17 00:00:00 2001 From: Jakub Nowakowski Date: Thu, 4 Jan 2024 09:39:52 +0100 Subject: [PATCH 7/8] Fix require-await error in deployment script 26:70 error Async arrow function has no 'await' expression @typescript-eslint/require-await --- core/deploy/00_resolve_testing_erc4626.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/core/deploy/00_resolve_testing_erc4626.ts b/core/deploy/00_resolve_testing_erc4626.ts index b8e483897..d1e82b665 100644 --- a/core/deploy/00_resolve_testing_erc4626.ts +++ b/core/deploy/00_resolve_testing_erc4626.ts @@ -24,4 +24,4 @@ func.tags = ["TestERC4626"] func.dependencies = ["TBTC"] func.skip = async (hre: HardhatRuntimeEnvironment): Promise => - hre.network.name === "mainnet" + Promise.resolve(hre.network.name === "mainnet") From 76a8938ac48dfcea5060667312d0fbcae5280950 Mon Sep 17 00:00:00 2001 From: Jakub Nowakowski Date: Thu, 4 Jan 2024 09:53:40 +0100 Subject: [PATCH 8/8] Explicitly import ethers to satisfy eslint This fixes: Error: 861:11 error Unsafe assignment of an `any` value @typescript-eslint/no-unsafe-assignment Error: 861:33 error Unsafe call of an `any` typed value @typescript-eslint/no-unsafe-call Error: 861:33 error Unsafe call of an `any` typed value @typescript-eslint/no-unsafe-call Error: 861:40 error Unsafe member access .Wallet on an `any` value @typescript-eslint/no-unsafe-member-access Error: 861:62 error Unsafe member access .getAddress on an `any` value @typescript-eslint/no-unsafe-member-access --- core/test/Acre.test.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/core/test/Acre.test.ts b/core/test/Acre.test.ts index 272f9a656..2a872dc02 100644 --- a/core/test/Acre.test.ts +++ b/core/test/Acre.test.ts @@ -9,6 +9,7 @@ import { ZeroAddress, encodeBytes32String, } from "ethers" +import { ethers } from "hardhat" import type { HardhatEthersSigner } from "@nomicfoundation/hardhat-ethers/signers" import type { SnapshotRestorer } from "@nomicfoundation/hardhat-toolbox/network-helpers"