From 192edd0ce82d534fec152b9ff7181142cee55224 Mon Sep 17 00:00:00 2001 From: Luis Schaab Date: Thu, 15 Feb 2024 16:36:45 -0300 Subject: [PATCH 1/3] Upgrade hardhat-viem to support viem@2 --- .changeset/proud-peas-sort.md | 5 +++ packages/hardhat-viem/package.json | 4 +- .../hardhat-viem/src/internal/contracts.ts | 6 ++- packages/hardhat-viem/src/types.ts | 6 ++- packages/hardhat-viem/test/integration.ts | 8 ++-- pnpm-lock.yaml | 45 +++++++++++++++++-- 6 files changed, 60 insertions(+), 14 deletions(-) create mode 100644 .changeset/proud-peas-sort.md diff --git a/.changeset/proud-peas-sort.md b/.changeset/proud-peas-sort.md new file mode 100644 index 0000000000..32ef9372c9 --- /dev/null +++ b/.changeset/proud-peas-sort.md @@ -0,0 +1,5 @@ +--- +"@nomicfoundation/hardhat-viem": major +--- + +Upgraded hardhat-viem to support viem@2 diff --git a/packages/hardhat-viem/package.json b/packages/hardhat-viem/package.json index c548701f85..fffa9b08f5 100644 --- a/packages/hardhat-viem/package.json +++ b/packages/hardhat-viem/package.json @@ -66,12 +66,12 @@ "sinon": "^9.0.0", "ts-node": "^10.8.0", "typescript": "~5.0.0", - "viem": "^1.15.1" + "viem": "^2.7.6" }, "peerDependencies": { "hardhat": "^2.17.0", "typescript": "~5.0.0", - "viem": "^1.15.1" + "viem": "^2.7.6" }, "dependencies": { "abitype": "^0.9.8", diff --git a/packages/hardhat-viem/src/internal/contracts.ts b/packages/hardhat-viem/src/internal/contracts.ts index a5c8b1359f..8d253162e7 100644 --- a/packages/hardhat-viem/src/internal/contracts.ts +++ b/packages/hardhat-viem/src/internal/contracts.ts @@ -225,8 +225,10 @@ async function innerGetContractAt( const viem = await import("viem"); const contract = viem.getContract({ address, - publicClient, - walletClient, + client: { + public: publicClient, + wallet: walletClient, + }, abi: contractAbi, }); diff --git a/packages/hardhat-viem/src/types.ts b/packages/hardhat-viem/src/types.ts index 39071d2e6c..42890070d8 100644 --- a/packages/hardhat-viem/src/types.ts +++ b/packages/hardhat-viem/src/types.ts @@ -42,8 +42,10 @@ export type GetContractReturnType< TAbi extends viemT.Abi | readonly unknown[] = viemT.Abi > = viemT.GetContractReturnType< TAbi, - PublicClient, - WalletClient, + { + public: PublicClient; + wallet: WalletClient; + }, viemT.Address >; diff --git a/packages/hardhat-viem/test/integration.ts b/packages/hardhat-viem/test/integration.ts index f8ff1454c5..d62ac2d030 100644 --- a/packages/hardhat-viem/test/integration.ts +++ b/packages/hardhat-viem/test/integration.ts @@ -64,10 +64,10 @@ describe("Integration tests", function () { const fromAddress = fromWalletClient.account.address; const toAddress = toWalletClient.account.address; - const fromBalanceBefore: bigint = await publicClient.getBalance({ + const fromBalanceBefore = await publicClient.getBalance({ address: fromAddress, }); - const toBalanceBefore: bigint = await publicClient.getBalance({ + const toBalanceBefore = await publicClient.getBalance({ address: toAddress, }); @@ -79,10 +79,10 @@ describe("Integration tests", function () { const receipt = await publicClient.waitForTransactionReceipt({ hash }); const transactionFee = receipt.gasUsed * receipt.effectiveGasPrice; - const fromBalanceAfter: bigint = await publicClient.getBalance({ + const fromBalanceAfter = await publicClient.getBalance({ address: fromAddress, }); - const toBalanceAfter: bigint = await publicClient.getBalance({ + const toBalanceAfter = await publicClient.getBalance({ address: toAddress, }); diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 39b9e7d278..f51d9065fc 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -1570,8 +1570,8 @@ importers: specifier: ~5.0.0 version: 5.0.4 viem: - specifier: ^1.15.1 - version: 1.21.4(typescript@5.0.4) + specifier: ^2.7.6 + version: 2.7.9(typescript@5.0.4) packages/hardhat-vyper: dependencies: @@ -3271,7 +3271,7 @@ packages: resolution: {integrity: sha512-N1ZhksgwD3OBlwTv3R6KFEcPojl/W4ElJOeCZdi+vuI5QmTFwLq3OFf2zd2ROpKvxFdgZ6hUpb0dx9bVNEwYCA==} dependencies: '@noble/curves': 1.2.0 - '@noble/hashes': 1.3.2 + '@noble/hashes': 1.3.3 '@scure/base': 1.1.5 dev: true @@ -3291,7 +3291,7 @@ packages: /@scure/bip39@1.2.1: resolution: {integrity: sha512-Z3/Fsz1yr904dduJD0NpiyRHhRYHdcnyh73FZWiV+/qhWi83wNJ3NWolYqCEN+ZWsUz2TWwajJggcRE9r1zUYg==} dependencies: - '@noble/hashes': 1.3.2 + '@noble/hashes': 1.3.3 '@scure/base': 1.1.5 dev: true @@ -4048,6 +4048,20 @@ packages: typescript: 5.0.4 dev: true + /abitype@1.0.0(typescript@5.0.4): + resolution: {integrity: sha512-NMeMah//6bJ56H5XRj8QCV4AwuW6hB6zqz2LnhhLdcWVQOsXki6/Pn3APeqxCma62nXIcmZWdu1DlHWS74umVQ==} + peerDependencies: + typescript: '>=5.0.4' + zod: ^3 >=3.22.0 + peerDependenciesMeta: + typescript: + optional: true + zod: + optional: true + dependencies: + typescript: 5.0.4 + dev: true + /abortcontroller-polyfill@1.7.5: resolution: {integrity: sha512-JMJ5soJWP18htbbxJjG7bG6yuI6pRhgJ0scHHTfkUjf6wjP912xZWvM+A4sJK3gqd9E8fcPbDnOefbA9Th/FIQ==} @@ -10581,6 +10595,29 @@ packages: - zod dev: true + /viem@2.7.9(typescript@5.0.4): + resolution: {integrity: sha512-iDfc8TwaZFp1K95zlsxYh6Cs0OWCt35Tqs8uYgXKSxtz7w075mZ0H5SJ8zSyJGoEaticVDhtdmRRX6TtcW9EeQ==} + peerDependencies: + typescript: '>=5.0.4' + peerDependenciesMeta: + typescript: + optional: true + dependencies: + '@adraffy/ens-normalize': 1.10.0 + '@noble/curves': 1.2.0 + '@noble/hashes': 1.3.2 + '@scure/bip32': 1.3.2 + '@scure/bip39': 1.2.1 + abitype: 1.0.0(typescript@5.0.4) + isows: 1.0.3(ws@8.13.0) + typescript: 5.0.4 + ws: 8.13.0 + transitivePeerDependencies: + - bufferutil + - utf-8-validate + - zod + dev: true + /wcwidth@1.0.1: resolution: {integrity: sha512-XHPEwS0q6TaxcvG85+8EYkbiCux2XtWG2mkc47Ng2A77BQu9+DqIOJldST4HgPkuea7dvKSj5VgX3P1d4rW8Tg==} dependencies: From 1b6f0846db13a03c6ec2d93c739aa8f6edc3881a Mon Sep 17 00:00:00 2001 From: Luis Schaab Date: Thu, 15 Feb 2024 17:14:22 -0300 Subject: [PATCH 2/3] Upgrade the viem toolbox and project creation to viem@2 --- .../hardhat-core/src/internal/cli/project-creation.ts | 6 +++--- packages/hardhat-toolbox-viem/package.json | 8 ++++---- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/packages/hardhat-core/src/internal/cli/project-creation.ts b/packages/hardhat-core/src/internal/cli/project-creation.ts index 15bc1030b0..4608f6e002 100644 --- a/packages/hardhat-core/src/internal/cli/project-creation.ts +++ b/packages/hardhat-core/src/internal/cli/project-creation.ts @@ -46,7 +46,7 @@ const ETHERS_PROJECT_DEPENDENCIES: Dependencies = { }; const VIEM_PROJECT_DEPENDENCIES: Dependencies = { - "@nomicfoundation/hardhat-toolbox-viem": "^2.0.0", + "@nomicfoundation/hardhat-toolbox-viem": "^3.0.0", }; const PEER_DEPENDENCIES: Dependencies = { @@ -68,8 +68,8 @@ const ETHERS_PEER_DEPENDENCIES: Dependencies = { }; const VIEM_PEER_DEPENDENCIES: Dependencies = { - "@nomicfoundation/hardhat-viem": "^1.0.0", - viem: "^1.15.1", + "@nomicfoundation/hardhat-viem": "^2.0.0", + viem: "^2.7.6", }; const TYPESCRIPT_DEPENDENCIES: Dependencies = {}; diff --git a/packages/hardhat-toolbox-viem/package.json b/packages/hardhat-toolbox-viem/package.json index 4d72c81122..8daed06c27 100644 --- a/packages/hardhat-toolbox-viem/package.json +++ b/packages/hardhat-toolbox-viem/package.json @@ -47,7 +47,7 @@ "@nomicfoundation/eslint-plugin-slow-imports": "workspace:^", "@nomicfoundation/hardhat-network-helpers": "workspace:^1.0.0", "@nomicfoundation/hardhat-verify": "workspace:^2.0.0", - "@nomicfoundation/hardhat-viem": "workspace:^1.0.0", + "@nomicfoundation/hardhat-viem": "workspace:^2.0.0", "@types/chai": "^4.2.0", "@types/chai-as-promised": "^7.1.6", "@types/mocha": ">=9.1.0", @@ -68,12 +68,12 @@ "solidity-coverage": "^0.8.1", "ts-node": "^10.8.0", "typescript": "~5.0.4", - "viem": "^1.15.1" + "viem": "^2.7.6" }, "peerDependencies": { "@nomicfoundation/hardhat-network-helpers": "^1.0.0", "@nomicfoundation/hardhat-verify": "^2.0.0", - "@nomicfoundation/hardhat-viem": "^1.0.0", + "@nomicfoundation/hardhat-viem": "^2.0.0", "@types/chai": "^4.2.0", "@types/chai-as-promised": "^7.1.6", "@types/mocha": ">=9.1.0", @@ -84,7 +84,7 @@ "solidity-coverage": "^0.8.1", "ts-node": ">=8.0.0", "typescript": "~5.0.4", - "viem": "^1.15.1" + "viem": "^2.7.6" }, "bugs": { "url": "https://github.com/nomicfoundation/hardhat/issues" From a1de1d20663b73645a466e14e1836acef8d9012e Mon Sep 17 00:00:00 2001 From: Luis Schaab Date: Thu, 15 Feb 2024 17:22:06 -0300 Subject: [PATCH 3/3] Changeset --- .changeset/silver-waves-cough.md | 6 ++++++ 1 file changed, 6 insertions(+) create mode 100644 .changeset/silver-waves-cough.md diff --git a/.changeset/silver-waves-cough.md b/.changeset/silver-waves-cough.md new file mode 100644 index 0000000000..636032268e --- /dev/null +++ b/.changeset/silver-waves-cough.md @@ -0,0 +1,6 @@ +--- +"@nomicfoundation/hardhat-toolbox-viem": major +"hardhat": patch +--- + +Upgraded hardhat-toolbox-viem and project creation to support viem@2