@nomicfoundation/hardhat-viem 2.0.6 → 3.0.0-next.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (95) hide show
  1. package/CHANGELOG.md +7 -0
  2. package/LICENSE +4 -16
  3. package/README.md +35 -247
  4. package/dist/src/index.d.ts +5 -0
  5. package/dist/src/index.d.ts.map +1 -0
  6. package/dist/src/index.js +10 -0
  7. package/dist/src/index.js.map +1 -0
  8. package/dist/src/internal/accounts.d.ts +4 -0
  9. package/dist/src/internal/accounts.d.ts.map +1 -0
  10. package/dist/src/internal/accounts.js +15 -0
  11. package/dist/src/internal/accounts.js.map +1 -0
  12. package/dist/src/internal/chains.d.ts +11 -0
  13. package/dist/src/internal/chains.d.ts.map +1 -0
  14. package/dist/src/internal/chains.js +116 -0
  15. package/dist/src/internal/chains.js.map +1 -0
  16. package/dist/src/internal/clients.d.ts +10 -0
  17. package/dist/src/internal/clients.d.ts.map +1 -0
  18. package/dist/src/internal/clients.js +91 -0
  19. package/dist/src/internal/clients.js.map +1 -0
  20. package/dist/src/internal/contracts.d.ts +11 -0
  21. package/dist/src/internal/contracts.d.ts.map +1 -0
  22. package/dist/src/internal/contracts.js +141 -0
  23. package/dist/src/internal/contracts.js.map +1 -0
  24. package/dist/src/internal/hook-handlers/network.d.ts +4 -0
  25. package/dist/src/internal/hook-handlers/network.d.ts.map +1 -0
  26. package/dist/src/internal/hook-handlers/network.js +12 -0
  27. package/dist/src/internal/hook-handlers/network.js.map +1 -0
  28. package/dist/src/internal/initialization.d.ts +6 -0
  29. package/dist/src/internal/initialization.d.ts.map +1 -0
  30. package/dist/src/internal/initialization.js +14 -0
  31. package/dist/src/internal/initialization.js.map +1 -0
  32. package/dist/src/type-extensions.d.ts +8 -0
  33. package/dist/src/type-extensions.d.ts.map +1 -0
  34. package/dist/src/type-extensions.js +2 -0
  35. package/dist/src/type-extensions.js.map +1 -0
  36. package/dist/src/types.d.ts +166 -0
  37. package/dist/src/types.d.ts.map +1 -0
  38. package/dist/src/types.js +2 -0
  39. package/dist/src/types.js.map +1 -0
  40. package/package.json +46 -51
  41. package/src/index.ts +10 -39
  42. package/src/internal/accounts.ts +20 -7
  43. package/src/internal/chains.ts +122 -62
  44. package/src/internal/clients.ts +135 -141
  45. package/src/internal/contracts.ts +126 -150
  46. package/src/internal/hook-handlers/network.ts +27 -0
  47. package/src/internal/initialization.ts +67 -0
  48. package/src/type-extensions.ts +10 -0
  49. package/src/types.ts +237 -72
  50. package/.eslintrc.js +0 -24
  51. package/index.d.ts +0 -3
  52. package/index.d.ts.map +0 -1
  53. package/index.js +0 -20
  54. package/index.js.map +0 -1
  55. package/internal/accounts.d.ts +0 -5
  56. package/internal/accounts.d.ts.map +0 -1
  57. package/internal/accounts.js +0 -9
  58. package/internal/accounts.js.map +0 -1
  59. package/internal/bytecode.d.ts +0 -13
  60. package/internal/bytecode.d.ts.map +0 -1
  61. package/internal/bytecode.js +0 -94
  62. package/internal/bytecode.js.map +0 -1
  63. package/internal/chains.d.ts +0 -7
  64. package/internal/chains.d.ts.map +0 -1
  65. package/internal/chains.js +0 -80
  66. package/internal/chains.js.map +0 -1
  67. package/internal/clients.d.ts +0 -45
  68. package/internal/clients.d.ts.map +0 -1
  69. package/internal/clients.js +0 -136
  70. package/internal/clients.js.map +0 -1
  71. package/internal/contracts.d.ts +0 -11
  72. package/internal/contracts.d.ts.map +0 -1
  73. package/internal/contracts.js +0 -164
  74. package/internal/contracts.js.map +0 -1
  75. package/internal/errors.d.ts +0 -36
  76. package/internal/errors.d.ts.map +0 -1
  77. package/internal/errors.js +0 -102
  78. package/internal/errors.js.map +0 -1
  79. package/internal/tasks.d.ts +0 -2
  80. package/internal/tasks.d.ts.map +0 -1
  81. package/internal/tasks.js +0 -240
  82. package/internal/tasks.js.map +0 -1
  83. package/internal/type-extensions.d.ts +0 -19
  84. package/internal/type-extensions.d.ts.map +0 -1
  85. package/internal/type-extensions.js +0 -5
  86. package/internal/type-extensions.js.map +0 -1
  87. package/src/internal/bytecode.ts +0 -138
  88. package/src/internal/errors.ts +0 -125
  89. package/src/internal/tasks.ts +0 -341
  90. package/src/internal/type-extensions.ts +0 -27
  91. package/src/tsconfig.json +0 -15
  92. package/types.d.ts +0 -52
  93. package/types.d.ts.map +0 -1
  94. package/types.js +0 -3
  95. package/types.js.map +0 -1
@@ -0,0 +1,11 @@
1
+ import type { ContractReturnType, DeployContractConfig, GetContractAtConfig, GetTransactionReturnType, SendDeploymentTransactionConfig } from "../types.js";
2
+ import type { ArtifactManager } from "hardhat/types/artifacts";
3
+ import type { EthereumProvider } from "hardhat/types/providers";
4
+ import type { Address as ViemAddress } from "viem";
5
+ export declare function deployContract<ContractName extends string>(provider: EthereumProvider, artifactManager: ArtifactManager, contractName: ContractName, constructorArgs?: unknown[], deployContractConfig?: DeployContractConfig): Promise<ContractReturnType<ContractName>>;
6
+ export declare function sendDeploymentTransaction<ContractName extends string>(provider: EthereumProvider, artifactManager: ArtifactManager, contractName: ContractName, constructorArgs?: unknown[], sendDeploymentTransactionConfig?: SendDeploymentTransactionConfig): Promise<{
7
+ contract: ContractReturnType<ContractName>;
8
+ deploymentTransaction: GetTransactionReturnType;
9
+ }>;
10
+ export declare function getContractAt<ContractName extends string>(provider: EthereumProvider, artifactManager: ArtifactManager, contractName: ContractName, address: ViemAddress, getContractAtConfig?: GetContractAtConfig): Promise<ContractReturnType<ContractName>>;
11
+ //# sourceMappingURL=contracts.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"contracts.d.ts","sourceRoot":"","sources":["../../../src/internal/contracts.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,kBAAkB,EAClB,oBAAoB,EACpB,mBAAmB,EACnB,wBAAwB,EAGxB,+BAA+B,EAEhC,MAAM,aAAa,CAAC;AAErB,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,yBAAyB,CAAC;AAC/D,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,yBAAyB,CAAC;AAChE,OAAO,KAAK,EAAkB,OAAO,IAAI,WAAW,EAAE,MAAM,MAAM,CAAC;AAUnE,wBAAsB,cAAc,CAAC,YAAY,SAAS,MAAM,EAC9D,QAAQ,EAAE,gBAAgB,EAC1B,eAAe,EAAE,eAAe,EAChC,YAAY,EAAE,YAAY,EAC1B,eAAe,GAAE,OAAO,EAAO,EAC/B,oBAAoB,GAAE,oBAAyB,GAC9C,OAAO,CAAC,kBAAkB,CAAC,YAAY,CAAC,CAAC,CAwE3C;AAED,wBAAsB,yBAAyB,CAAC,YAAY,SAAS,MAAM,EACzE,QAAQ,EAAE,gBAAgB,EAC1B,eAAe,EAAE,eAAe,EAChC,YAAY,EAAE,YAAY,EAC1B,eAAe,GAAE,OAAO,EAAO,EAC/B,+BAA+B,GAAE,+BAAoC,GACpE,OAAO,CAAC;IACT,QAAQ,EAAE,kBAAkB,CAAC,YAAY,CAAC,CAAC;IAC3C,qBAAqB,EAAE,wBAAwB,CAAC;CACjD,CAAC,CAoDD;AAED,wBAAsB,aAAa,CAAC,YAAY,SAAS,MAAM,EAC7D,QAAQ,EAAE,gBAAgB,EAC1B,eAAe,EAAE,eAAe,EAChC,YAAY,EAAE,YAAY,EAC1B,OAAO,EAAE,WAAW,EACpB,mBAAmB,GAAE,mBAAwB,GAC5C,OAAO,CAAC,kBAAkB,CAAC,YAAY,CAAC,CAAC,CAe3C"}
@@ -0,0 +1,141 @@
1
+ import { HardhatError } from "@nomicfoundation/hardhat-errors";
2
+ import { toBigInt } from "@nomicfoundation/hardhat-utils/bigint";
3
+ import { resolveLinkedBytecode } from "@nomicfoundation/hardhat-utils/bytecode";
4
+ import { ensureError } from "@nomicfoundation/hardhat-utils/error";
5
+ import { getContractAddress, getContract } from "viem";
6
+ import { getDefaultWalletClient, getPublicClient } from "./clients.js";
7
+ export async function deployContract(provider, artifactManager, contractName, constructorArgs = [], deployContractConfig = {}) {
8
+ const { client, confirmations = 1, libraries = {}, ...deployContractParameters } = deployContractConfig;
9
+ if (confirmations < 0) {
10
+ throw new HardhatError(HardhatError.ERRORS.VIEM.INVALID_CONFIRMATIONS, {
11
+ error: "Confirmations must be greather than 0.",
12
+ });
13
+ }
14
+ if (confirmations === 0) {
15
+ throw new HardhatError(HardhatError.ERRORS.VIEM.INVALID_CONFIRMATIONS, {
16
+ error: "deployContract does not support 0 confirmations. Use sendDeploymentTransaction if you want to handle the deployment transaction yourself.",
17
+ });
18
+ }
19
+ const [publicClient, walletClient, { abi, bytecode }] = await Promise.all([
20
+ client?.public ?? getPublicClient(provider, "l1"),
21
+ client?.wallet ?? getDefaultWalletClient(provider, "l1"),
22
+ getContractAbiAndBytecode(artifactManager, contractName, libraries),
23
+ ]);
24
+ let deploymentTxHash;
25
+ // If gasPrice is defined, then maxFeePerGas and maxPriorityFeePerGas
26
+ // must be undefined because it's a legaxy tx.
27
+ if (deployContractParameters.gasPrice !== undefined) {
28
+ deploymentTxHash = await walletClient.deployContract({
29
+ abi,
30
+ bytecode,
31
+ args: constructorArgs,
32
+ ...deployContractParameters,
33
+ maxFeePerGas: undefined,
34
+ maxPriorityFeePerGas: undefined,
35
+ });
36
+ }
37
+ else {
38
+ deploymentTxHash = await walletClient.deployContract({
39
+ abi,
40
+ bytecode,
41
+ args: constructorArgs,
42
+ ...deployContractParameters,
43
+ gasPrice: undefined,
44
+ });
45
+ }
46
+ const { contractAddress } = await publicClient.waitForTransactionReceipt({
47
+ hash: deploymentTxHash,
48
+ confirmations,
49
+ });
50
+ if (contractAddress === null || contractAddress === undefined) {
51
+ const transaction = await publicClient.getTransaction({
52
+ hash: deploymentTxHash,
53
+ });
54
+ throw new HardhatError(HardhatError.ERRORS.VIEM.DEPLOY_CONTRACT_ERROR, {
55
+ txHash: deploymentTxHash,
56
+ blockNumber: transaction.blockNumber,
57
+ });
58
+ }
59
+ const contract = createContractInstance(contractName, publicClient, walletClient, abi, contractAddress);
60
+ return contract;
61
+ }
62
+ export async function sendDeploymentTransaction(provider, artifactManager, contractName, constructorArgs = [], sendDeploymentTransactionConfig = {}) {
63
+ const { client, libraries = {}, ...deployContractParameters } = sendDeploymentTransactionConfig;
64
+ const [publicClient, walletClient, { abi, bytecode }] = await Promise.all([
65
+ client?.public ?? getPublicClient(provider, "l1"),
66
+ client?.wallet ?? getDefaultWalletClient(provider, "l1"),
67
+ getContractAbiAndBytecode(artifactManager, contractName, libraries),
68
+ ]);
69
+ let deploymentTxHash;
70
+ // If gasPrice is defined, then maxFeePerGas and maxPriorityFeePerGas
71
+ // must be undefined because it's a legaxy tx.
72
+ if (deployContractParameters.gasPrice !== undefined) {
73
+ deploymentTxHash = await walletClient.deployContract({
74
+ abi,
75
+ bytecode,
76
+ args: constructorArgs,
77
+ ...deployContractParameters,
78
+ maxFeePerGas: undefined,
79
+ maxPriorityFeePerGas: undefined,
80
+ });
81
+ }
82
+ else {
83
+ deploymentTxHash = await walletClient.deployContract({
84
+ abi,
85
+ bytecode,
86
+ args: constructorArgs,
87
+ ...deployContractParameters,
88
+ gasPrice: undefined,
89
+ });
90
+ }
91
+ const deploymentTx = await publicClient.getTransaction({
92
+ hash: deploymentTxHash,
93
+ });
94
+ const contractAddress = getContractAddress({
95
+ from: walletClient.account.address,
96
+ nonce: toBigInt(deploymentTx.nonce),
97
+ });
98
+ const contract = createContractInstance(contractName, publicClient, walletClient, abi, contractAddress);
99
+ return { contract, deploymentTransaction: deploymentTx };
100
+ }
101
+ export async function getContractAt(provider, artifactManager, contractName, address, getContractAtConfig = {}) {
102
+ const [publicClient, walletClient, artifact] = await Promise.all([
103
+ getContractAtConfig.client?.public ?? getPublicClient(provider, "l1"),
104
+ getContractAtConfig.client?.wallet ??
105
+ getDefaultWalletClient(provider, "l1"),
106
+ artifactManager.readArtifact(contractName),
107
+ ]);
108
+ return createContractInstance(contractName, publicClient, walletClient, artifact.abi, address);
109
+ }
110
+ function createContractInstance(_contractName, publicClient, walletClient, abi, address) {
111
+ const contract = getContract({
112
+ address,
113
+ client: {
114
+ public: publicClient,
115
+ wallet: walletClient,
116
+ },
117
+ abi,
118
+ });
119
+ /* eslint-disable-next-line @typescript-eslint/consistent-type-assertions
120
+ -- Cast it as TS can't infer the type of the contract */
121
+ return contract;
122
+ }
123
+ async function getContractAbiAndBytecode(artifacts, contractName, libraries) {
124
+ const artifact = await artifacts.readArtifact(contractName);
125
+ let bytecode;
126
+ try {
127
+ bytecode = resolveLinkedBytecode(artifact, libraries);
128
+ }
129
+ catch (error) {
130
+ ensureError(error);
131
+ throw new HardhatError(HardhatError.ERRORS.VIEM.LINKING_CONTRACT_ERROR, {
132
+ contractName,
133
+ error: error.message,
134
+ }, error);
135
+ }
136
+ return {
137
+ abi: artifact.abi,
138
+ bytecode,
139
+ };
140
+ }
141
+ //# sourceMappingURL=contracts.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"contracts.js","sourceRoot":"","sources":["../../../src/internal/contracts.ts"],"names":[],"mappings":"AAeA,OAAO,EAAE,YAAY,EAAE,MAAM,iCAAiC,CAAC;AAC/D,OAAO,EAAE,QAAQ,EAAE,MAAM,uCAAuC,CAAC;AACjE,OAAO,EAAE,qBAAqB,EAAE,MAAM,yCAAyC,CAAC;AAChF,OAAO,EAAE,WAAW,EAAE,MAAM,sCAAsC,CAAC;AACnE,OAAO,EAAE,kBAAkB,EAAE,WAAW,EAAE,MAAM,MAAM,CAAC;AAEvD,OAAO,EAAE,sBAAsB,EAAE,eAAe,EAAE,MAAM,cAAc,CAAC;AAEvE,MAAM,CAAC,KAAK,UAAU,cAAc,CAClC,QAA0B,EAC1B,eAAgC,EAChC,YAA0B,EAC1B,kBAA6B,EAAE,EAC/B,uBAA6C,EAAE;IAE/C,MAAM,EACJ,MAAM,EACN,aAAa,GAAG,CAAC,EACjB,SAAS,GAAG,EAAE,EACd,GAAG,wBAAwB,EAC5B,GAAG,oBAAoB,CAAC;IAEzB,IAAI,aAAa,GAAG,CAAC,EAAE,CAAC;QACtB,MAAM,IAAI,YAAY,CAAC,YAAY,CAAC,MAAM,CA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R,CAAC;AACJ,CAAC;AAED,SAAS,sBAAsB,CAC7B,aAA2B,EAC3B,YAA0B,EAC1B,YAA0B,EAC1B,GAAY,EACZ,OAAoB;IAEpB,MAAM,QAAQ,GAAG,WAAW,CAAC;QAC3B,OAAO;QACP,MAAM,EAAE;YACN,MAAM,EAAE,YAAY;YACpB,MAAM,EAAE,YAAY;SACrB;QACD,GAAG;KACJ,CAAC,CAAC;IAEH;4DACwD;IACxD,OAAO,QAA4C,CAAC;AACtD,CAAC;AAED,KAAK,UAAU,yBAAyB,CACtC,SAA0B,EAC1B,YAAoB,EACpB,SAAoB;IAEpB,MAAM,QAAQ,GAAG,MAAM,SAAS,CAAC,YAAY,CAAC,YAAY,CAAC,CAAC;IAC5D,IAAI,QAAQ,CAAC;IACb,IAAI,CAAC;QACH,QAAQ,GAAG,qBAAqB,CAAC,QAAQ,EAAE,SAAS,CAAC,CAAC;IACxD,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACf,WAAW,CAAC,KAAK,CAAC,CAAC;QAEnB,MAAM,IAAI,YAAY,CACpB,YAAY,CAAC,MAAM,CAAC,IAAI,CAAC,sBAAsB,EAC/C;YACE,YAAY;YACZ,KAAK,EAAE,KAAK,CAAC,OAAO;SACrB,EACD,KAAK,CACN,CAAC;IACJ,CAAC;IAED,OAAO;QACL,GAAG,EAAE,QAAQ,CAAC,GAAG;QACjB,QAAQ;KACT,CAAC;AACJ,CAAC"}
@@ -0,0 +1,4 @@
1
+ import type { NetworkHooks } from "hardhat/types/hooks";
2
+ declare const _default: () => Promise<Partial<NetworkHooks>>;
3
+ export default _default;
4
+ //# sourceMappingURL=network.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"network.d.ts","sourceRoot":"","sources":["../../../../src/internal/hook-handlers/network.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAe,YAAY,EAAE,MAAM,qBAAqB,CAAC;8BAK5C,OAAO,CAAC,OAAO,CAAC,YAAY,CAAC,CAAC;AAAvD,wBAqBE"}
@@ -0,0 +1,12 @@
1
+ import { initializeViem } from "../initialization.js";
2
+ export default async () => {
3
+ const handlers = {
4
+ async newConnection(context, next) {
5
+ const connection = await next(context);
6
+ connection.viem = initializeViem(connection.chainType, connection.provider, context.artifacts);
7
+ return connection;
8
+ },
9
+ };
10
+ return handlers;
11
+ };
12
+ //# sourceMappingURL=network.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"network.js","sourceRoot":"","sources":["../../../../src/internal/hook-handlers/network.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,cAAc,EAAE,MAAM,sBAAsB,CAAC;AAEtD,eAAe,KAAK,IAAoC,EAAE;IACxD,MAAM,QAAQ,GAA0B;QACtC,KAAK,CAAC,aAAa,CACjB,OAAoB,EACpB,IAE2C;YAE3C,MAAM,UAAU,GAAkC,MAAM,IAAI,CAAC,OAAO,CAAC,CAAC;YAEtE,UAAU,CAAC,IAAI,GAAG,cAAc,CAC9B,UAAU,CAAC,SAAS,EACpB,UAAU,CAAC,QAAQ,EACnB,OAAO,CAAC,SAAS,CAClB,CAAC;YAEF,OAAO,UAAU,CAAC;QACpB,CAAC;KACF,CAAC;IAEF,OAAO,QAAQ,CAAC;AAClB,CAAC,CAAC"}
@@ -0,0 +1,6 @@
1
+ import type { HardhatViemHelpers } from "../types.js";
2
+ import type { ArtifactManager } from "hardhat/types/artifacts";
3
+ import type { ChainType } from "hardhat/types/network";
4
+ import type { EthereumProvider } from "hardhat/types/providers";
5
+ export declare function initializeViem<ChainTypeT extends ChainType | string>(chainType: ChainTypeT, provider: EthereumProvider, artifactManager: ArtifactManager): HardhatViemHelpers<ChainTypeT>;
6
+ //# sourceMappingURL=initialization.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"initialization.d.ts","sourceRoot":"","sources":["../../../src/internal/initialization.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,aAAa,CAAC;AACtD,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,yBAAyB,CAAC;AAC/D,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,uBAAuB,CAAC;AACvD,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,yBAAyB,CAAC;AAchE,wBAAgB,cAAc,CAAC,UAAU,SAAS,SAAS,GAAG,MAAM,EAClE,SAAS,EAAE,UAAU,EACrB,QAAQ,EAAE,gBAAgB,EAC1B,eAAe,EAAE,eAAe,GAC/B,kBAAkB,CAAC,UAAU,CAAC,CA6ChC"}
@@ -0,0 +1,14 @@
1
+ import { getPublicClient, getWalletClients, getWalletClient, getTestClient, } from "./clients.js";
2
+ import { deployContract, getContractAt, sendDeploymentTransaction, } from "./contracts.js";
3
+ export function initializeViem(chainType, provider, artifactManager) {
4
+ return {
5
+ getPublicClient: (publicClientConfig) => getPublicClient(provider, chainType, publicClientConfig),
6
+ getWalletClients: (walletClientConfig) => getWalletClients(provider, chainType, walletClientConfig),
7
+ getWalletClient: (address, walletClientConfig) => getWalletClient(provider, chainType, address, walletClientConfig),
8
+ getTestClient: (testClientConfig) => getTestClient(provider, chainType, testClientConfig),
9
+ deployContract: (contractName, constructorArgs, deployContractConfig) => deployContract(provider, artifactManager, contractName, constructorArgs, deployContractConfig),
10
+ sendDeploymentTransaction: (contractName, constructorArgs, sendDeploymentTransactionConfig) => sendDeploymentTransaction(provider, artifactManager, contractName, constructorArgs, sendDeploymentTransactionConfig),
11
+ getContractAt: (contractName, address, getContractAtConfig) => getContractAt(provider, artifactManager, contractName, address, getContractAtConfig),
12
+ };
13
+ }
14
+ //# sourceMappingURL=initialization.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"initialization.js","sourceRoot":"","sources":["../../../src/internal/initialization.ts"],"names":[],"mappings":"AAKA,OAAO,EACL,eAAe,EACf,gBAAgB,EAChB,eAAe,EACf,aAAa,GACd,MAAM,cAAc,CAAC;AACtB,OAAO,EACL,cAAc,EACd,aAAa,EACb,yBAAyB,GAC1B,MAAM,gBAAgB,CAAC;AAExB,MAAM,UAAU,cAAc,CAC5B,SAAqB,EACrB,QAA0B,EAC1B,eAAgC;IAEhC,OAAO;QACL,eAAe,EAAE,CAAC,kBAAkB,EAAE,EAAE,CACtC,eAAe,CAAC,QAAQ,EAAE,SAAS,EAAE,kBAAkB,CAAC;QAE1D,gBAAgB,EAAE,CAAC,kBAAkB,EAAE,EAAE,CACvC,gBAAgB,CAAC,QAAQ,EAAE,SAAS,EAAE,kBAAkB,CAAC;QAE3D,eAAe,EAAE,CAAC,OAAO,EAAE,kBAAkB,EAAE,EAAE,CAC/C,eAAe,CAAC,QAAQ,EAAE,SAAS,EAAE,OAAO,EAAE,kBAAkB,CAAC;QAEnE,aAAa,EAAE,CAAC,gBAAgB,EAAE,EAAE,CAClC,aAAa,CAAC,QAAQ,EAAE,SAAS,EAAE,gBAAgB,CAAC;QAEtD,cAAc,EAAE,CAAC,YAAY,EAAE,eAAe,EAAE,oBAAoB,EAAE,EAAE,CACtE,cAAc,CACZ,QAAQ,EACR,eAAe,EACf,YAAY,EACZ,eAAe,EACf,oBAAoB,CACrB;QAEH,yBAAyB,EAAE,CACzB,YAAY,EACZ,eAAe,EACf,+BAA+B,EAC/B,EAAE,CACF,yBAAyB,CACvB,QAAQ,EACR,eAAe,EACf,YAAY,EACZ,eAAe,EACf,+BAA+B,CAChC;QAEH,aAAa,EAAE,CAAC,YAAY,EAAE,OAAO,EAAE,mBAAmB,EAAE,EAAE,CAC5D,aAAa,CACX,QAAQ,EACR,eAAe,EACf,YAAY,EACZ,OAAO,EACP,mBAAmB,CACpB;KACJ,CAAC;AACJ,CAAC"}
@@ -0,0 +1,8 @@
1
+ import type { HardhatViemHelpers } from "./types.js";
2
+ import "hardhat/types/network";
3
+ declare module "hardhat/types/network" {
4
+ interface NetworkConnection<ChainTypeT extends ChainType | string = DefaultChainType> {
5
+ viem: HardhatViemHelpers<ChainTypeT>;
6
+ }
7
+ }
8
+ //# sourceMappingURL=type-extensions.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"type-extensions.d.ts","sourceRoot":"","sources":["../../src/type-extensions.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,YAAY,CAAC;AAErD,OAAO,uBAAuB,CAAC;AAC/B,OAAO,QAAQ,uBAAuB,CAAC;IACrC,UAAU,iBAAiB,CACzB,UAAU,SAAS,SAAS,GAAG,MAAM,GAAG,gBAAgB;QAExD,IAAI,EAAE,kBAAkB,CAAC,UAAU,CAAC,CAAC;KACtC;CACF"}
@@ -0,0 +1,2 @@
1
+ import "hardhat/types/network";
2
+ //# sourceMappingURL=type-extensions.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"type-extensions.js","sourceRoot":"","sources":["../../src/type-extensions.ts"],"names":[],"mappings":"AAEA,OAAO,uBAAuB,CAAC"}
@@ -0,0 +1,166 @@
1
+ import type { ArtifactMap } from "hardhat/types/artifacts";
2
+ import type { ChainType, DefaultChainType } from "hardhat/types/network";
3
+ import type { Abi as ViemAbi, Account as ViemAccount, Address as ViemAddress, Chain as ViemChain, Client as ViemClient, ContractConstructorArgs as ViemContractConstructorArgs, createTestClient as ViemCreateTestClient, GetContractReturnType as ViemGetContractReturnType, GetTransactionReturnType as ViemGetTransactionReturnType, PublicClient as ViemPublicClient, PublicClientConfig as ViemPublicClientConfig, RpcSchema as ViemRpcSchema, TestClient as ViemTestClient, TestClientConfig as ViemTestClientConfig, Transport as ViemTransport, WalletClient as ViemWalletClient, WalletClientConfig as ViemWalletClientConfig, PublicActions as ViemPublicActions, WalletActions as ViemWalletActions } from "viem";
4
+ import type { PublicActionsL2 as ViemOpStackPublicActionsL2, WalletActionsL2 as ViemOpStackWalletActionsL2 } from "viem/op-stack";
5
+ export interface HardhatViemHelpers<ChainTypeT extends ChainType | string = DefaultChainType> {
6
+ /**
7
+ * Creates a public client configured with the provided settings.
8
+ *
9
+ * @param publicClientConfig A viem's PublicClientConfig object with the
10
+ * desired configuration.
11
+ * @returns The configured public client. If the connection's chainType is
12
+ * "optimism", the client will be extended with L2 actions.
13
+ */
14
+ getPublicClient: (publicClientConfig?: Partial<ViemPublicClientConfig>) => Promise<GetPublicClientReturnType<ChainTypeT>>;
15
+ /**
16
+ * Creates a wallet client configured with the provided settings for each
17
+ * account in the provider.
18
+ *
19
+ * @param walletClientConfig A viem's WalletClientConfig object with the
20
+ * desired configuration.
21
+ * @returns An array with the configured wallet clients. If the connection's
22
+ * chainType is "optimism", the clients will be extended with L2 actions.
23
+ */
24
+ getWalletClients: (walletClientConfig?: Partial<ViemWalletClientConfig>) => Promise<Array<GetWalletClientReturnType<ChainTypeT>>>;
25
+ /**
26
+ * Creates a wallet client configured with the provided settings for the
27
+ * specified address.
28
+ *
29
+ * @param address The address of the account to create the wallet client for.
30
+ * @param walletClientConfig A viem's WalletClientConfig object with the
31
+ * desired configuration.
32
+ * @returns The configured wallet client for the specified address. If the
33
+ * connection's chainType is "optimism", the client will be extended with L2
34
+ * actions.
35
+ */
36
+ getWalletClient: (address: ViemAddress, walletClientConfig?: Partial<ViemWalletClientConfig>) => Promise<GetWalletClientReturnType<ChainTypeT>>;
37
+ /**
38
+ * Creates a test client configured with the provided settings.
39
+ *
40
+ * @param testClientConfig A viem's TestClientConfig object with the desired
41
+ * configuration.
42
+ * @returns The configured test client.
43
+ */
44
+ getTestClient: (testClientConfig?: Partial<ViemTestClientConfig>) => Promise<TestClient>;
45
+ /**
46
+ * Deploys a contract with the provided name and constructor arguments and
47
+ * returns the viem's contract instance.
48
+ *
49
+ * @param contractName The name of the contract to deploy. This is required
50
+ * to return the correct contract type.
51
+ * @param constructorArgs The arguments to pass to the contract's constructor.
52
+ * @param deployContractConfig A configuration object. See
53
+ * {@link DeployContractConfig} for more details.
54
+ * @returns The deployed contract instance.
55
+ */
56
+ deployContract: <ContractName extends string>(contractName: ContractName, constructorArgs?: ConstructorArgs<ContractName>, deployContractConfig?: DeployContractConfig) => Promise<ContractReturnType<ContractName>>;
57
+ /**
58
+ * Sends a deployment transaction for the specified contract and returns the
59
+ * contract instance along with the deployment transaction.
60
+ * The function does not wait for the transaction to be mined.
61
+ *
62
+ * @param contractName The name of the contract to deploy. This is required
63
+ * to return the correct contract type.
64
+ * @param constructorArgs The arguments to pass to the contract's constructor.
65
+ * @param sendDeploymentTransactionConfig A configuration object. See
66
+ * {@link SendDeploymentTransactionConfig} for more details.
67
+ * @returns An object containing the deployed contract instance and the
68
+ * deployment transaction.
69
+ */
70
+ sendDeploymentTransaction: <ContractName extends string>(contractName: ContractName, constructorArgs?: ConstructorArgs<ContractName>, sendDeploymentTransactionConfig?: SendDeploymentTransactionConfig) => Promise<{
71
+ contract: ContractReturnType<ContractName>;
72
+ deploymentTransaction: GetTransactionReturnType;
73
+ }>;
74
+ /**
75
+ * Returns a contract instance for the specified contract at the provided
76
+ * address.
77
+ *
78
+ * @param contractName The name of the contract to get an instance of. This
79
+ * is required to return the correct contract type.
80
+ * @param address The address of the contract.
81
+ * @param getContractAtConfig A configuration object. See
82
+ * {@link GetContractAtConfig} for more details.
83
+ * @returns The contract instance.
84
+ */
85
+ getContractAt: <ContractName extends string>(contractName: ContractName, address: ViemAddress, getContractAtConfig?: GetContractAtConfig) => Promise<ContractReturnType<ContractName>>;
86
+ }
87
+ export type GetPublicClientReturnType<ChainTypeT extends ChainType | string> = ChainTypeT extends "optimism" ? OpPublicClient : PublicClient;
88
+ export type GetWalletClientReturnType<ChainTypeT extends ChainType | string> = ChainTypeT extends "optimism" ? OpWalletClient : WalletClient;
89
+ export type PublicClient = ViemPublicClient<ViemTransport, ViemChain>;
90
+ export type OpPublicClient = ViemClient<ViemTransport, ViemChain, undefined, ViemRpcSchema, ViemPublicActions<ViemTransport, ViemChain, ViemAccount> & ViemOpStackPublicActionsL2<ViemChain, ViemAccount>>;
91
+ export type WalletClient = ViemWalletClient<ViemTransport, ViemChain, ViemAccount>;
92
+ export type OpWalletClient = ViemClient<ViemTransport, ViemChain, ViemAccount, ViemRpcSchema, ViemWalletActions<ViemChain, ViemAccount> & ViemOpStackWalletActionsL2<ViemChain, ViemAccount>>;
93
+ export type TestClient = ViemTestClient<TestClientMode, ViemTransport, ViemChain>;
94
+ export type TestClientMode = Parameters<typeof ViemCreateTestClient>[0]["mode"];
95
+ /**
96
+ * Configuration options for sending a transaction.
97
+ *
98
+ * - `client`: A KeyedClient object with the public and wallet clients to use.
99
+ * If some of them are not provided, the default clients will be used. The
100
+ * default wallet client is the first one returned by `getWalletClients`.
101
+ * - `gas`: The gas limit for the deployment transaction.
102
+ * - `gasPrice`: The gas price for the deployment transaction.
103
+ * - `maxFeePerGas`: The maximum fee per gas for the deployment transaction.
104
+ * - `maxPriorityFeePerGas`: The maximum priority fee per gas for the deployment
105
+ * transaction.
106
+ * - `value`: The value to send with the deployment transaction.
107
+ */
108
+ export interface SendTransactionConfig {
109
+ client?: KeyedClient;
110
+ gas?: bigint;
111
+ gasPrice?: bigint;
112
+ maxFeePerGas?: bigint;
113
+ maxPriorityFeePerGas?: bigint;
114
+ value?: bigint;
115
+ }
116
+ export type KeyedClient = {
117
+ public?: PublicClient;
118
+ wallet: WalletClient;
119
+ } | {
120
+ public: PublicClient;
121
+ wallet?: WalletClient;
122
+ };
123
+ export interface Libraries {
124
+ [libraryName: string]: ViemAddress;
125
+ }
126
+ /**
127
+ * Configuration options for deploying a contract.
128
+ *
129
+ * - `confirmations`: The number of confirmations to wait for the deployment
130
+ * transaction. Default is 1.
131
+ *
132
+ * - `libraries`: An object with the contract's library names as keys and their
133
+ * addresses as values. This is required if the contract uses libraries,
134
+ * to enable linking.
135
+ *
136
+ * This interface extends {@link SendTransactionConfig}, which includes
137
+ * additional properties such as `client`, `gas`, `gasPrice`, `maxFeePerGas`,
138
+ * `maxPriorityFeePerGas` and `value`.
139
+ */
140
+ export interface DeployContractConfig extends SendTransactionConfig {
141
+ confirmations?: number;
142
+ libraries?: Libraries;
143
+ }
144
+ export interface SendDeploymentTransactionConfig extends SendTransactionConfig {
145
+ libraries?: Libraries;
146
+ }
147
+ /**
148
+ * Configuration options for getting a contract instance.
149
+ *
150
+ * - `client`: A KeyedClient object with the public and wallet clients to use.
151
+ * If some of them are not provided, the default clients will be used. The
152
+ * default wallet client is the first one returned by `getWalletClients`. It is
153
+ * mandatory to provide a wallet client if there are no accounts in the
154
+ * provider.
155
+ */
156
+ export interface GetContractAtConfig {
157
+ client?: KeyedClient;
158
+ }
159
+ export type GetContractReturnType<TAbi extends ViemAbi | readonly unknown[] = ViemAbi> = ViemGetContractReturnType<TAbi, Required<KeyedClient>, ViemAddress>;
160
+ export type GetTransactionReturnType = ViemGetTransactionReturnType<ViemChain, "latest">;
161
+ export type ContractAbis = {
162
+ [ContractName in keyof ArtifactMap]: ArtifactMap[ContractName] extends never ? never : ArtifactMap[ContractName]["abi"];
163
+ };
164
+ export type ConstructorArgs<ContractName> = ContractName extends keyof ContractAbis ? ViemContractConstructorArgs<ContractAbis[ContractName]> : unknown[];
165
+ export type ContractReturnType<ContractName> = ContractName extends keyof ContractAbis ? GetContractReturnType<ContractAbis[ContractName]> : GetContractReturnType;
166
+ //# sourceMappingURL=types.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,yBAAyB,CAAC;AAC3D,OAAO,KAAK,EAAE,SAAS,EAAE,gBAAgB,EAAE,MAAM,uBAAuB,CAAC;AACzE,OAAO,KAAK,EACV,GAAG,IAAI,OAAO,EACd,OAAO,IAAI,WAAW,EACtB,OAAO,IAAI,WAAW,EACtB,KAAK,IAAI,SAAS,EAClB,MAAM,IAAI,UAAU,EACpB,uBAAuB,IAAI,2BAA2B,EACtD,gBAAgB,IAAI,oBAAoB,EACxC,qBAAqB,IAAI,yBAAyB,EAClD,wBAAwB,IAAI,4BAA4B,EACxD,YAAY,IAAI,gBAAgB,EAChC,kBAAkB,IAAI,sBAAsB,EAC5C,SAAS,IAAI,aA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AE,WAAW,CAAC,CAAC;AAExE,MAAM,MAAM,wBAAwB,GAAG,4BAA4B,CACjE,SAAS,EACT,QAAQ,CACT,CAAC;AAEF,MAAM,MAAM,YAAY,GAAG;KACxB,YAAY,IAAI,MAAM,WAAW,GAAG,WAAW,CAAC,YAAY,CAAC,SAAS,KAAK,GACxE,KAAK,GACL,WAAW,CAAC,YAAY,CAAC,CAAC,KAAK,CAAC;CACrC,CAAC;AAEF,MAAM,MAAM,eAAe,CAAC,YAAY,IACtC,YAAY,SAAS,MAAM,YAAY,GACnC,2BAA2B,CAAC,YAAY,CAAC,YAAY,CAAC,CAAC,GACvD,OAAO,EAAE,CAAC;AAEhB,MAAM,MAAM,kBAAkB,CAAC,YAAY,IACzC,YAAY,SAAS,MAAM,YAAY,GACnC,qBAAqB,CAAC,YAAY,CAAC,YAAY,CAAC,CAAC,GACjD,qBAAqB,CAAC"}
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=types.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.js","sourceRoot":"","sources":["../../src/types.ts"],"names":[],"mappings":""}
package/package.json CHANGED
@@ -1,13 +1,21 @@
1
1
  {
2
2
  "name": "@nomicfoundation/hardhat-viem",
3
- "version": "2.0.6",
3
+ "version": "3.0.0-next.1",
4
4
  "description": "Hardhat plugin for viem",
5
- "homepage": "https://github.com/nomicfoundation/hardhat/tree/main/packages/hardhat-viem",
6
- "repository": "github:nomicfoundation/hardhat",
5
+ "homepage": "https://github.com/nomicfoundation/hardhat/tree/v-next/v-next/hardhat-viem",
6
+ "repository": {
7
+ "type": "git",
8
+ "url": "https://github.com/NomicFoundation/hardhat",
9
+ "directory": "v-next/hardhat-viem"
10
+ },
7
11
  "author": "Nomic Foundation",
8
12
  "license": "MIT",
9
- "main": "index.js",
10
- "types": "index.d.ts",
13
+ "type": "module",
14
+ "types": "dist/src/index.d.ts",
15
+ "exports": {
16
+ ".": "./dist/src/index.js",
17
+ "./types": "./dist/src/types.js"
18
+ },
11
19
  "keywords": [
12
20
  "ethereum",
13
21
  "smart-contracts",
@@ -16,63 +24,50 @@
16
24
  "viem"
17
25
  ],
18
26
  "files": [
27
+ "dist/src/",
19
28
  "src/",
20
- "internal/",
21
- "*.d.ts",
22
- "*.d.ts.map",
23
- "*.js",
24
- "*.js.map",
29
+ "CHANGELOG.md",
25
30
  "LICENSE",
26
31
  "README.md"
27
32
  ],
28
33
  "devDependencies": {
29
- "@types/chai": "^4.2.0",
30
- "@types/chai-as-promised": "^7.1.3",
31
- "@types/lodash": "^4.14.123",
32
- "@types/lodash.memoize": "^4.1.7",
33
- "@types/mocha": ">=9.1.0",
34
- "@types/node": "^18.0.0",
35
- "@types/sinon": "^9.0.8",
36
- "@typescript-eslint/eslint-plugin": "5.61.0",
37
- "@typescript-eslint/parser": "5.61.0",
38
- "chai": "^4.2.0",
39
- "chai-as-promised": "^7.1.1",
40
- "eslint": "^8.44.0",
41
- "eslint-config-prettier": "8.3.0",
42
- "eslint-plugin-import": "2.27.5",
43
- "eslint-plugin-mocha": "10.4.1",
44
- "eslint-plugin-prettier": "3.4.0",
45
- "hardhat": "^2.17.0",
46
- "jest-diff": "^29.7.0",
47
- "mocha": "^10.0.0",
48
- "nyc": "^15.1.0",
49
- "prettier": "2.4.1",
50
- "rimraf": "^3.0.2",
51
- "sinon": "^9.0.0",
52
- "ts-node": "^10.8.0",
53
- "typescript": "~5.0.0",
54
- "viem": "^2.7.6",
55
- "@nomicfoundation/eslint-plugin-hardhat-internal-rules": "^1.0.2",
56
- "@nomicfoundation/eslint-plugin-slow-imports": "^1.0.0"
57
- },
58
- "peerDependencies": {
59
- "hardhat": "^2.17.0",
60
- "viem": "^2.7.6"
34
+ "@eslint-community/eslint-plugin-eslint-comments": "^4.3.0",
35
+ "@nomicfoundation/hardhat-node-test-reporter": "^3.0.0-next.1",
36
+ "@types/node": "^20.14.9",
37
+ "@typescript-eslint/eslint-plugin": "^7.7.1",
38
+ "@typescript-eslint/parser": "^7.7.1",
39
+ "eslint": "8.57.0",
40
+ "eslint-config-prettier": "9.1.0",
41
+ "eslint-import-resolver-typescript": "^3.6.1",
42
+ "eslint-plugin-import": "2.29.1",
43
+ "eslint-plugin-no-only-tests": "3.1.0",
44
+ "expect-type": "^0.19.0",
45
+ "prettier": "3.2.5",
46
+ "rimraf": "^5.0.5",
47
+ "tsx": "^4.19.3",
48
+ "typescript": "~5.5.0",
49
+ "typescript-eslint": "7.7.1",
50
+ "viem": "^2.21.42",
51
+ "@nomicfoundation/hardhat-test-utils": "^3.0.0-next.1"
61
52
  },
62
53
  "dependencies": {
63
- "abitype": "^0.9.8",
64
- "lodash.memoize": "^4.1.2"
54
+ "@nomicfoundation/hardhat-errors": "^3.0.0-next.1",
55
+ "@nomicfoundation/hardhat-utils": "^3.0.0-next.1"
56
+ },
57
+ "peerDependencies": {
58
+ "hardhat": "^3.0.0-next.1",
59
+ "viem": "^2.21.42"
65
60
  },
66
61
  "scripts": {
67
62
  "lint": "pnpm prettier --check && pnpm eslint",
68
63
  "lint:fix": "pnpm prettier --write && pnpm eslint --fix",
69
- "eslint": "eslint 'src/**/*.ts' 'test/**/*.ts'",
70
- "prettier": "prettier \"**/*.{js,md,json}\"",
71
- "pretest": "cd ../.. && pnpm build",
72
- "test": "mocha --recursive \"test/**/*.ts\" -c --exit",
73
- "snapshots:update": "ts-node test/update-snapshots.ts",
74
- "coverage": "nyc pnpm test -- --reporter min",
64
+ "eslint": "eslint \"src/**/*.ts\" \"test/**/*.ts\"",
65
+ "prettier": "prettier \"**/*.{ts,js,md,json}\"",
66
+ "test": "node --import tsx/esm --test --test-reporter=@nomicfoundation/hardhat-node-test-reporter \"test/*.ts\" \"test/!(fixture-projects|helpers)/**/*.ts\"",
67
+ "test:only": "node --import tsx/esm --test --test-only --test-reporter=@nomicfoundation/hardhat-node-test-reporter \"test/*.ts\" \"test/!(fixture-projects|helpers)/**/*.ts\"",
68
+ "pretest": "pnpm build",
69
+ "pretest:only": "pnpm build",
75
70
  "build": "tsc --build .",
76
- "clean": "rimraf internal *.{d.ts,js}{,.map} build-test tsconfig.tsbuildinfo"
71
+ "clean": "rimraf dist"
77
72
  }
78
73
  }
package/src/index.ts CHANGED
@@ -1,42 +1,13 @@
1
- import { extendEnvironment } from "hardhat/config";
1
+ import type { HardhatPlugin } from "hardhat/types/plugins";
2
2
 
3
- import {
4
- getPublicClient,
5
- getWalletClients,
6
- getWalletClient,
7
- getTestClient,
8
- } from "./internal/clients";
9
- import {
10
- deployContract,
11
- sendDeploymentTransaction,
12
- getContractAt,
13
- } from "./internal/contracts";
14
- import "./internal/type-extensions";
15
- import "./internal/tasks";
3
+ import "./type-extensions.js";
16
4
 
17
- extendEnvironment((hre) => {
18
- const { provider } = hre.network;
5
+ const hardhatPlugin: HardhatPlugin = {
6
+ id: "hardhat-viem",
7
+ hookHandlers: {
8
+ network: import.meta.resolve("./internal/hook-handlers/network.js"),
9
+ },
10
+ npmPackage: "@nomicfoundation/hardhat-viem",
11
+ };
19
12
 
20
- hre.viem = {
21
- getPublicClient: (publicClientConfig) =>
22
- getPublicClient(provider, publicClientConfig),
23
-
24
- getWalletClients: (walletClientConfig) =>
25
- getWalletClients(provider, walletClientConfig),
26
-
27
- getWalletClient: (address, walletClientConfig) =>
28
- getWalletClient(provider, address, walletClientConfig),
29
-
30
- getTestClient: (testClientConfig) =>
31
- getTestClient(provider, testClientConfig),
32
-
33
- deployContract: (contractName, constructorArgs, config) =>
34
- deployContract(hre, contractName, constructorArgs, config),
35
-
36
- sendDeploymentTransaction: (contractName, constructorArgs, config) =>
37
- sendDeploymentTransaction(hre, contractName, constructorArgs, config),
38
-
39
- getContractAt: (contractName, address, config) =>
40
- getContractAt(hre, contractName, address, config),
41
- };
42
- });
13
+ export default hardhatPlugin;