Skip to content

Commit

Permalink
Improve implementation of deployContract overrides
Browse files Browse the repository at this point in the history
  • Loading branch information
fvictorio committed Jun 7, 2023
1 parent 9e2554e commit 1409b0a
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 29 deletions.
35 changes: 6 additions & 29 deletions packages/hardhat-ethers/src/internal/helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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>]: 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);
Expand Down
13 changes: 13 additions & 0 deletions packages/hardhat-ethers/test/type-tests.ts
Original file line number Diff line number Diff line change
@@ -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<FactoryOptions> = {
signer: null as any,
libraries: null as any,
};

0 comments on commit 1409b0a

Please sign in to comment.