diff --git a/packages/hardhat-ethers/src/internal/helpers.ts b/packages/hardhat-ethers/src/internal/helpers.ts index 4cfcde5917..bd3bc89ff2 100644 --- a/packages/hardhat-ethers/src/internal/helpers.ts +++ b/packages/hardhat-ethers/src/internal/helpers.ts @@ -371,37 +371,14 @@ export async function deployContract( let overrides: EthersT.Overrides = {}; if (signerOrOptions !== undefined && !("getAddress" in signerOrOptions)) { - // the DeployContractOptions type combines the properties of FactoryOptions - // and of EthersT.Overrides, but we only want to use the latter. - // - // This seems to be the type-safest way to extract only those. - const overridesExplicitProperties: { - [K in keyof Required]: EthersT.Overrides[K]; - } = { - type: signerOrOptions.type, + const overridesAndFactoryOptions = { ...signerOrOptions }; - from: signerOrOptions.from, + // we delete the factory options properties in case ethers + // rejects unknown properties + delete overridesAndFactoryOptions.signer; + delete overridesAndFactoryOptions.libraries; - nonce: signerOrOptions.nonce, - - gasLimit: signerOrOptions.gasLimit, - gasPrice: signerOrOptions.gasPrice, - - maxPriorityFeePerGas: signerOrOptions.maxPriorityFeePerGas, - maxFeePerGas: signerOrOptions.maxFeePerGas, - - value: signerOrOptions.value, - chainId: signerOrOptions.chainId, - - accessList: signerOrOptions.accessList, - - customData: signerOrOptions.customData, - - blockTag: signerOrOptions.blockTag, - enableCcipRead: signerOrOptions.enableCcipRead, - }; - - overrides = overridesExplicitProperties; + overrides = overridesAndFactoryOptions; } const factory = await getContractFactory(hre, name, signerOrOptions); diff --git a/packages/hardhat-ethers/test/type-tests.ts b/packages/hardhat-ethers/test/type-tests.ts new file mode 100644 index 0000000000..0fe9ce754d --- /dev/null +++ b/packages/hardhat-ethers/test/type-tests.ts @@ -0,0 +1,13 @@ +import { FactoryOptions } from "../src/types"; + +// FactoryOptions shouldn't have mandatory properties +const _factoryOptions: FactoryOptions = {}; + +// FactoryOptions only has these two properties. +// If new ones are added, then the deployContract +// implementation should be updated to also delete +// those new extra properties +const _factoryOptionsRequired: Required = { + signer: null as any, + libraries: null as any, +};