Skip to content

Migation to ethers 6#379

Open
elshan-eth wants to merge 1 commit intomasterfrom
migration-to-ethers-6
Open

Migation to ethers 6#379
elshan-eth wants to merge 1 commit intomasterfrom
migration-to-ethers-6

Conversation

@elshan-eth
Copy link
Collaborator

Description

This PR migrates the project to ethers 6. To avoid creating too many changes, the idea is to create a layer similar to ethers 5 for the old tests.

I didn't have time to test that the commands work, so I would appreciate it if someone could check them.

Type of change

  • Bug fix
  • New feature
  • Breaking change
  • Dependency changes
  • Code refactor / cleanup
  • Documentation or wording changes
  • Other

Checklist:

  • The diff is legible and has no extraneous changes
  • Complex code has been commented, including external interfaces
  • Tests are included for all code paths
  • The base branch is either master, or there's a description of how to merge

Issue Resolution

Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR migrates the repo’s Hardhat + Ethers integration to Ethers v6 / Hardhat v3, primarily by introducing a compatibility layer (@src/hardhatCompat) and updating tasks/tests/helpers to work with bigint-based numeric handling.

Changes:

  • Add a Hardhat/Ethers v6 compatibility bridge (hardhatConnection, hardhatCompat) and update fork-test infrastructure to use it.
  • Migrate numeric utilities and many tests from Ethers v5 BigNumber patterns to bigint (@helpers/numbers) and updated chai assertions/helpers.
  • Update numerous v2/v3 task fork tests and task inputs/imports to work under the new runtime and module system changes.

Reviewed changes

Copilot reviewed 147 out of 151 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
v3/tasks/20260203-v3-stable-pool-oracle-v2/test/task.fork.ts Switch Hardhat/Ethers imports to compat layer; update event extraction.
v3/tasks/20260202-v3-weighted-pool-oracle-v2/test/task.fork.ts Switch Hardhat import to compat; update event extraction.
v3/tasks/20260126-v3-gyro-eclp-v2/test/task.fork.ts Update signer type import; bigint/chai comparison adjustments.
v3/tasks/20260123-v3-gyro-2clp-v2/test/task.fork.ts Update signer type import; bigint/chai comparison adjustments.
v3/tasks/20260117-v3-stable-surge-pool-factory-v3/test/task.fork.ts Switch Hardhat import to compat.
v3/tasks/20260116-v3-stable-pool-v3/test/task.fork.ts Switch Hardhat import; update signer type import.
v3/tasks/20260115-v3-weighted-pool-v2/test/task.fork.ts Switch Hardhat import to compat.
v3/tasks/20251219-v3-liquidity-bootstrapping-pool-v3/test/task.fork.ts Update signer type; struct field rename for v6 struct encoding; bigint usage.
v3/tasks/20251219-v3-liquidity-bootstrapping-pool-v3/index.ts Switch ethers import to compat.
v3/tasks/20251219-v3-balancer-fee-burner-v2/test/task.fork.ts Switch to compat + bigint comparisons; add missing struct fields for v6.
v3/tasks/20251205-v3-fixed-price-lbp/test/task.fork.ts Switch Hardhat import; update signer type import.
v3/tasks/20251205-v3-fixed-price-lbp/index.ts Switch ethers import to compat.
v3/tasks/20251010-v3-unbalanced-add-via-swap-router/test/task.fork.ts Switch to compat; network helpers wrapper; bigint comparisons.
v3/tasks/20251010-v3-prepaid-composite-liquidity-router-v3/test/task.fork.ts Switch to compat; update signer type import.
v3/tasks/20251010-v3-composite-liquidity-router-v3/test/task.fork.ts Switch to compat; update signer type import.
v3/tasks/20250925-v3-timelock-authorizer/test/task.fork.ts Switch Hardhat import; update signer type import.
v3/tasks/20250925-v3-timelock-authorizer/input/sepolia.ts Type-only imports for input types.
v3/tasks/20250925-v3-timelock-authorizer/input.ts Replace dynamic requires with explicit network input import.
v3/tasks/20250919-v3-protocol-fee-helper-v2/test/task.fork.ts Switch Hardhat import; update signer type import.
v3/tasks/20250919-v3-pool-swap-fee-helper-v2/test/task.fork.ts Update setup to create a pool via factory; add expectEvent usage.
v3/tasks/20250919-v3-pool-pause-helper-v2/test/task.fork.ts Switch Hardhat import; update signer type import.
v3/tasks/20250828-v3-hyperevm-rate-provider/test/task.fork.ts Switch Hardhat import to compat.
v3/tasks/20250813-v3-constant-price-feed/test/task.fork.ts Switch Hardhat import to compat.
v3/tasks/20250806-v3-token-pair-registry/test/task.fork.ts Switch Hardhat import; update signer type import; await missing tx.
v3/tasks/20250702-v3-reclamm-pool-v2/test/task.fork.ts Switch Hardhat import to compat.
v3/tasks/20250530-v3-erc4626-cow-swap-fee-burner-v2/test/task.fork.ts Switch to compat; adjust order comparisons for bigint/string fields.
v3/tasks/20250530-v3-cow-swap-fee-burner-v2/test/task.fork.ts Switch to compat; adjust order comparisons for bigint/string fields.
v3/tasks/20250507-v3-aggregator-batch-router/test/task.fork.ts Replace ethers BigNumber import with repo bigint helper types.
v3/tasks/20250503-v3-protocol-fee-sweeper-v2/test/task.fork.ts Switch Hardhat import; update signer type import.
v3/tasks/20250502-v3-fee-percentages-provider/test/task.fork.ts Switch Hardhat import; update signer type import.
v3/tasks/20250418-v3-wrapped-bpt/test/task.fork.ts Switch Hardhat import to compat.
v3/tasks/20250407-v3-vault-explorer-v2/test/task.fork.ts Network helpers wrapper; snapshot typing update; signer type update.
v3/tasks/20250403-v3-stable-surge-hook-v2/test/task.fork.ts Switch Hardhat import to compat.
v3/tasks/20250321-v3-vault-factory-v2/test/task.fork.ts Switch Hardhat import; update signer type import.
v3/tasks/20250321-v3-vault-factory-v2/index.ts Switch ethers import to compat.
v3/tasks/20250307-v3-router-v2/test/task.fork.ts Switch to compat; network helpers wrapper.
v3/tasks/20250218-v3-aggregator-router/test/task.fork.ts Replace ethers BigNumber import with repo bigint helper types.
v3/tasks/20250214-v3-protocol-fee-controller-v2/test/task.fork.ts Switch Hardhat import; update signer type import.
v3/tasks/20250212-v3-mev-capture-hook/test/task.fork.ts Switch Hardhat import to compat.
v3/tasks/20250212-v3-mev-capture-hook/input.ts Change input types from ethers BigNumber to bigint.
v3/tasks/20250123-v3-composite-liquidity-router-v2/test/task.fork.ts Switch to compat; update signer type import.
v3/tasks/20250117-v3-contract-registry/test/task.fork.ts Switch to compat; update signer type import.
v3/tasks/20241213-v3-hook-examples/test/task.fork.ts Switch Hardhat import to compat.
v3/tasks/20241205-v3-buffer-router/test/task.fork.ts Switch to compat; update signer type import.
v3/tasks/20241205-v3-batch-router/test/task.fork.ts Switch to compat; update signer type import.
v3/tasks/20241204-v3-vault/test/task.fork.ts Switch to compat; update signer type import.
v3/tasks/20241204-v3-vault/index.ts Switch ethers import to compat.
v2/tasks/20250925-timelock-authorizer/test/task.fork.ts Update signer type import.
v2/tasks/20250925-timelock-authorizer/input.ts Replace dynamic requires with explicit network input import.
v2/tasks/20250919-pool-swap-fee-helper/test/task.fork.ts Update ethers imports (randomBytes) and signer type.
v2/tasks/20250613-veboost-v2.1/test/test.fork.ts Switch BigNumber import to repo helper; signer type update; type casts.
v2/tasks/20240522-fraxtal-root-gauge-factory/test/task.fork.ts Switch ethers import to compat; lodash.range; voting power calc updates.
v2/tasks/20231031-batch-relayer-v6/test/yearnWrapping.fork.ts Replace math-on-number with bigint math; signer type update.
v2/tasks/20231031-batch-relayer-v6/test/tetuWrapping.fork.ts Switch ethers import to compat; replace math-on-number with bigint math.
v2/tasks/20231031-batch-relayer-v6/test/test.fork.ts Switch ethers import to compat; Interface import changes.
v2/tasks/20231031-batch-relayer-v6/test/siloWrapping.fork.ts Adjust wrapping math to bigint-safe computations.
v2/tasks/20231031-batch-relayer-v6/test/queryVaultActions.fork.ts Update randomBytes import and signer type.
v2/tasks/20231031-batch-relayer-v6/test/legacyStable.fork.ts Update signer type import.
v2/tasks/20231031-batch-relayer-v6/test/gearboxWrapping.fork.ts Update signer type import and BigNumber import source.
v2/tasks/20231031-batch-relayer-v6/test/gaugeCheckpoints.fork.ts Switch ethers import to compat; Interface import changes.
v2/tasks/20231031-batch-relayer-v6/test/eulerWrapping.fork.ts Update signer type import and BigNumber import source.
v2/tasks/20231031-batch-relayer-v6/test/erc4626Wrapping.fork.ts Update signer type import and BigNumber import source.
v2/tasks/20231031-batch-relayer-v6/test/compoundV2Wrapping.fork.ts Update signer type import and BigNumber import source.
v2/tasks/20231031-batch-relayer-v6/test/composableStableV2.fork.ts Adjust getPoolTokens token list handling for v6 return types.
v2/tasks/20231031-batch-relayer-v6/test/composableStableV1.fork.ts Adjust getPoolTokens token list handling for v6 return types.
v2/tasks/20230915-stakeless-gauge-checkpointer-v2/test/task.fork.ts Switch ethers import to compat; Interface import changes; bigint comparisons.
v2/tasks/20230915-stakeless-gauge-checkpointer-v2/test/task-base.fork.ts Add gasLimit; switch ethers import to compat; Interface import changes.
v2/tasks/20230911-base-root-gauge-factory/test/task.fork.ts Switch ethers import to compat; lodash.range; v6 utils replacements.
v2/tasks/20230811-avalanche-root-gauge-factory-v2/test/task.fork.ts Switch ethers import to compat; v6 padding/randomBytes; bigint comparisons.
v2/tasks/20230712-child-chain-gauge-checkpointer/test/test.fork.ts Switch ethers import to compat; Interface import changes.
v2/tasks/20230613-balancer-pool-data-queries/test/task-failing-scaling-factors.fork.ts Extend default config to include loadLinearTargets.
v2/tasks/20230526-zkevm-root-gauge-factory/test/task.fork.ts Switch ethers import to compat; lodash.range; bigint comparisons.
v2/tasks/20230526-gauge-working-balance-helper/test/L2GaugeHelper.fork.ts Update signer type import; bigint comparisons.
v2/tasks/20230526-gauge-working-balance-helper/test/L1VeBALDecay.fork.ts BigNumber import source change; signer type update.
v2/tasks/20230526-gauge-working-balance-helper/test/L1GaugeHelper.fork.ts Update signer type import.
v2/tasks/20230525-l2-veboost-v2/test/test.fork.ts BigNumber import source change.
v2/tasks/20230524-mainnet-lz-omni-voting-escrow/test/task.fork.ts Switch ethers import to compat; AbiCoder usage updated for v6.
v2/tasks/20230524-lz-omni-voting-escrow-child/test/task.fork.ts Switch ethers import to compat; AbiCoder usage updated for v6.
v2/tasks/20230519-gauge-adder-v4/test/task.fork.ts Update event decoding to v6 interface decodeEventLog.
v2/tasks/20230504-vebal-remapper/test/task.fork.ts Switch ethers import to compat; signer type update.
v2/tasks/20230414-authorizer-wrapper/test/task.fork.ts Switch ethers import to compat; Interface import changes.
v2/tasks/20230404-l2-layer0-bridge-forwarder/test/task.fork.ts Switch ethers import to compat; signer type update.
v2/tasks/20230320-weighted-pool-v4/test/task.fork.ts Switch to v6 parseEther; internal balance flag rename; token list handling.
v2/tasks/20230320-weighted-pool-v4/index.ts Switch ethers import to compat; add hre import.
v2/tasks/20230316-l2-ve-delegation-proxy/test/test.fork.ts Switch ethers import to compat; signer type update.
v2/tasks/20230316-l2-balancer-pseudo-minter/test/test.fork.ts Switch ethers import to compat; signer type update.
v2/tasks/20230316-child-chain-gauge-factory-v2/test/test.fork.ts Switch ethers import to compat; update receipt type import.
v2/tasks/20230223-protocol-id-registry/test/task.fork.ts Switch ethers import to compat; signer type update.
v2/tasks/20230222-merkle-orchard-v2/test/test.fork.ts Switch ethers import to compat; v6 solidityPackedKeccak256 usage.
v2/tasks/20230222-merkle-orchard-v2/test/merkleTree.ts Switch ethers import to compat; v6 bytes/keccak helpers.
v2/tasks/20230217-gnosis-root-gauge-factory/test/task.fork.ts Switch ethers import to compat; lodash.range; Interface import changes.
v2/tasks/20230215-single-recipient-gauge-factory-v2/test/task.fork.ts Network helpers wrapper; signer type update; lodash.range.
v2/tasks/20221123-pool-recovery-helper/test/test.fork.ts Network helpers wrapper; signer type update.
v2/tasks/20220823-polygon-root-gauge-factory-v2/test/task.fork.ts Switch ethers import to compat; replace VEBAL whale approach; add pool join/lock setup.
v2/tasks/20220823-optimism-root-gauge-factory-v2/test/task.fork.ts Switch ethers import to compat; replace VEBAL whale approach; add pool join/lock setup.
v2/tasks/20220823-arbitrum-root-gauge-factory-v2/test/task.fork.ts Switch ethers import to compat; replace VEBAL whale approach; add pool join/lock setup.
v2/tasks/20220822-mainnet-gauge-factory-v2/test/task.fork.ts lodash.range; signer type update; bigint comparisons.
v2/tasks/20220725-protocol-fee-percentages-provider/test/task.fork.ts Update signer type import.
v2/tasks/20220725-protocol-fee-percentages-provider/input.ts BigNumber import source change to repo helper.
v2/tasks/20220714-fee-distributor-v2/test/test.fork.ts Switch ethers import to compat; TypedDataEncoder import updated.
v2/tasks/20220707-distribution-scheduler/test/test.fork.ts Update signer type import.
v2/tasks/20220530-preseeded-voting-escrow-delegation/test/test.fork.ts Add timeouts; adjust range iteration; bigint expiry handling.
v2/tasks/20220513-double-entrypoint-fix-relayer/test/task.fork.ts Update signer type import.
v2/scripts/20230130-ta-transition-migrator/input/mainnet.ts Change lodash import style for ESM compatibility.
v2/scripts/20220418-veBAL-gauge-fix-coordinator/test/task.fork.ts Replace lodash range import with lodash.range.
v2/scripts/20220415-veBAL-L2-gauge-setup-coordinator/test/task.fork.ts Switch ethers import to compat.
tsconfig.json Update target; exclude deprecated; formatting; keep baseUrl.
src/verifier.ts Refine etherscan verify response typing.
src/types.ts Update types for v6 signer + bigint Param; adjust artifact/libraries typing.
src/type-compat.d.ts Add broad type compat shims for Hardhat 3 / Ethers 6.
src/test.ts Update fork network detection to use env + rpc-url mapping helper.
src/task.ts ESM-friendly loading; path resolution changes; v6 receipt/contract compat adjustments.
src/signers.ts Switch to compat ethers + networkHelpers wrapper; bigint balance type.
src/network.ts Switch BigNumber on-chain delay types to bigint; update path roots to cwd.
src/helpers/time.ts Switch time helpers to wrapper; return bigint timestamps; receiptTimestamp safety.
src/helpers/sharedBeforeEach.ts Use snapshot wrapper + typed SnapshotRestorer import.
src/helpers/setupTests.ts Add chai revert assertions + bigint-aware comparisons/equality overrides.
src/helpers/relativeError.ts Rework comparisons for bigint/bn utilities.
src/helpers/numbers.ts Migrate BigNumber utilities to bigint; add BigInt prototype helpers.
src/helpers/networkHelpers.ts Add wrapper around Hardhat network helpers via hardhatConnection.
src/helpers/models/types/types.ts Align types for v6 signer + bigint BigNumberish.
src/helpers/models/pools/weighted/normalizedWeights.ts Rewrite normalization to bigint math.
src/helpers/models/pools/weighted/math.ts Remove ethers BigNumber import; alias to bigint.
src/helpers/models/pools/stable/math.ts Remove ethers BigNumber import; alias to bigint.
src/helpers/models/misc/actions.ts Switch Interface import path for ethers v6.
src/helpers/models/authorizer/types.ts Update signer type import for hardhat-ethers v4.
src/helpers/models/authorizer/TimelockAuthorizerDeployer.ts Switch ethers import to compat.
src/helpers/models/authorizer/TimelockAuthorizer.ts Update imports/types for ethers v6; cast connect result.
src/helpers/merkleTree.ts Replace ethers utils.arrayify with ethers getBytes.
src/helpers/expectTransfer.ts Update receipt handling for missing to; v6 Interface import.
src/helpers/expectEvent.ts Update receipt parsing to support v6 logs; normalize args.
src/helpers/expectCustomError.ts Switch ethers import to compat; use v6 ethers.id.
src/helpers/contracts/ReadOnlyReentrancyAttackerLP.sol Update Solidity imports; add IAsset/IERC20; minor formatting.
src/helpers/contracts/ReadOnlyReentrancyAttackerEP.sol Remove unused import; formatting.
src/helpers/contracts/ReadOnlyReentrancyAttackerAaveLP.sol Remove unused import; formatting.
src/helpers/contracts/IWETH.sol Add IWETH interface for v6-era dependencies/tests.
src/helpers/constants.ts Use ethers Wallet directly; align BigNumber type to bigint helper.
src/hardhatConnection.ts Add Hardhat 3 connection manager + ethers compat bridge + fork snapshotting.
src/hardhatCompat.ts Export compat hre + proxied ethers with fallback.
src/forkingNetwork.ts Add RPC URL discovery (env + local config + optional public fallbacks).
src/forkTests.ts Update fork test setup to use new connection manager + timeout env.
src/contracts.ts Replace hardhat internal artifacts usage; add v6 contract compatibility patching.
src/buildinfo.ts Update BuildInfo import path for hardhat v3 types.
src/artifact.ts Update hardhat type imports for v3.
src/actionId.ts Replace lodash padEnd import; update action-ids directory to cwd.
src/@src/hardhatCompat.ts Re-export compat module under @src/* style path.
package.json Switch to ESM (type: module); upgrade hardhat/ethers deps; update test globs.
index.ts Cast artifact ABI to satisfy ethers v6 typings.
hardhat.config.ts Migrate to hardhat v3 plugin model; gate legacy tasks; adjust test task wiring.
.gitignore Ignore hardhat .hardhat dirs and typechain output.
Comments suppressed due to low confidence (3)

hardhat.config.ts:71

  • verify-contract still accepts key/v1 flags, but the task constructs Task(...).verify(...) without providing any verifier instance/API key wiring. This likely makes verification non-functional while the command appears to support it. Either reintroduce the verifier integration or remove/disable this task until verification is supported again.
  task('verify-contract', `Verify a task's deployment on a block explorer`)
  .addParam('id', 'Deployment task ID')
  .addParam('name', 'Contract name')
  .addParam('address', 'Contract address')
  .addParam('args', 'ABI-encoded constructor arguments')
  .addOptionalParam('key', 'Etherscan API key to verify contracts')
  .addFlag('v1', 'Use Etherscan V1 API to verify the contract')
  .setAction(
    async (
      args: { id: string; name: string; address: string; key: string; args: string; verbose?: boolean; v1?: boolean },
      hre: HardhatRuntimeEnvironment
    ) => {
      Logger.setDefaults(false, args.verbose || false);

      // Contracts can only be verified in Live mode
      await new Task(args.id, TaskMode.LIVE, hre.network.name).verify(args.name, args.address, args.args);
    }

src/helpers/numbers.ts:123

  • parseScientific converts the input via Number(num) before reconstructing the decimal string. For values above Number.MAX_SAFE_INTEGER, this can silently lose precision and produce an incorrect bigint in bn(...) (e.g. large scientific-notation values). Consider parsing the scientific notation string manually without going through JS Number, or reject unsafe numeric inputs and require callers to pass strings/bigints.
    hardhat.config.ts:52
  • The deploy task still defines key and v1 parameters (and includes them in the action args type), but they are no longer used to construct a Verifier. As a result, running hardhat deploy --key ... will silently skip verification behavior that the flags imply. Either wire these params back into Task verification setup, or remove the flags to avoid misleading CLI behavior.
  task('deploy', 'Run deployment task')
  .addParam('id', 'Deployment task ID')
  .addFlag('force', 'Ignore previous deployments')
  .addOptionalParam('key', 'Etherscan API key to verify contracts')
  .addFlag('v1', 'Use Etherscan V1 API to verify the contract')
  .setAction(
    async (
      args: { id: string; force?: boolean; key?: string; verbose?: boolean; v1?: boolean },
      hre: HardhatRuntimeEnvironment
    ) => {
      Logger.setDefaults(false, args.verbose || false);

      await new Task(args.id, TaskMode.LIVE, hre.network.name).run(args);
    }

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.


describeForkTest.skip = function (name: string, forkNetwork: Network, blockNumber: number, callback: () => void): void {
describe.skip(name, () => {
describe(name, () => {
Copy link

Copilot AI Mar 2, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

describeForkTest.skip currently calls describe(...) instead of describe.skip(...), so tests marked as skipped will still run. This will unexpectedly execute long-running fork tests in CI/local runs. Change this implementation back to describe.skip (or otherwise ensure skipped suites are not executed).

Suggested change
describe(name, () => {
describe.skip(name, () => {

Copilot uses AI. Check for mistakes.
Comment on lines 197 to +206
if (value === null) {
expect(args[key]).to.equal(null, `expected event argument '${key}' to be null but got ${args[key]}`);
} else if (BigNumber.isBigNumber(args[key]) || BigNumber.isBigNumber(value)) {
const actual = BigNumber.isBigNumber(args[key]) ? args[key].toString() : args[key];
expect(actualValue).to.equal(null, `expected event argument '${key}' to be null but got ${actualValue}`);
} else if (BigNumber.isBigNumber(actualValue) || BigNumber.isBigNumber(value)) {
const actual = BigNumber.isBigNumber(actualValue) ? actualValue.toString() : actualValue;
const expected = BigNumber.isBigNumber(value) ? value.toString() : value;

expect(args[key]).to.equal(value, `expected event argument '${key}' to have value ${expected} but got ${actual}`);
expect(actualValue).to.equal(
value,
`expected event argument '${key}' to have value ${expected} but got ${actual}`
);
Copy link

Copilot AI Mar 2, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In contains, when the actual event arg is a bigint (ethers v6) and the expected value is a number/string, the code enters the BigNumber branch but still compares actualValue (bigint) directly to value (number/string). This will fail even for equal numeric values (e.g. 0n vs 0). Convert both sides to a common representation (e.g. bn(...) or toString()) before asserting equality.

Copilot uses AI. Check for mistakes.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants