Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update ethers.deployContract with DeployContractOptions #853

Merged
merged 4 commits into from
Jul 17, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions .changeset/cuddly-ghosts-drum.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
'@typechain/hardhat': patch
'@typechain/ethers-v6': patch
---

Support for the newest hardhat-ethers version
2 changes: 1 addition & 1 deletion examples/hardhat/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
"typecheck": "pnpm compile && pnpm test && pnpm tsc --noEmit"
},
"devDependencies": {
"@nomicfoundation/hardhat-ethers": "^3.0.0",
"@nomicfoundation/hardhat-ethers": "^3.0.4",
"@nomicfoundation/hardhat-chai-matchers": "^2.0.0",
"@typechain/ethers-v6": "workspace:^0.4.0",
"@typechain/hardhat": "workspace:^8.0.0",
Expand Down
7 changes: 5 additions & 2 deletions examples/hardhat/test/counter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import chai from 'chai'
import chaiAsPromised from 'chai-as-promised'
import { solidity } from 'ethereum-waffle'
import { ethers } from 'hardhat'
import { DeployContractOptions } from '@nomicfoundation/hardhat-ethers/types'

import type { Counter } from '../typechain-types'

Expand All @@ -17,13 +18,15 @@ describe('Counter', () => {
const signers = await ethers.getSigners()

// 2
counter = await ethers.deployContract('Counter')

const gasPrice = 1637083528
const options: DeployContractOptions = { gasPrice }
counter = await ethers.deployContract('Counter', options)
const initialCount = await counter.getCount()

// 3
expect(initialCount).to.eq(0)
expect(await counter.getAddress()).to.properAddress
expect(counter.deploymentTransaction()?.gasPrice).to.eq(gasPrice)
})

// 4
Expand Down
21 changes: 11 additions & 10 deletions packages/hardhat-test/typechain-types/hardhat.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

import { ethers } from "ethers";
import {
DeployContractOptions,
FactoryOptions,
HardhatEthersHelpers as HardhatEthersHelpersBase,
} from "@nomicfoundation/hardhat-ethers/types";
Expand Down Expand Up @@ -52,40 +53,40 @@ declare module "hardhat/types/runtime" {

deployContract(
name: "Counter",
signerOrOptions?: ethers.Signer | FactoryOptions
signerOrOptions?: ethers.Signer | DeployContractOptions
): Promise<Contracts.Counter>;
deployContract(
name: "Demo",
signerOrOptions?: ethers.Signer | FactoryOptions
signerOrOptions?: ethers.Signer | DeployContractOptions
): Promise<Contracts.Demo>;
deployContract(
name: "Hello",
signerOrOptions?: ethers.Signer | FactoryOptions
signerOrOptions?: ethers.Signer | DeployContractOptions
): Promise<Contracts.Hello>;
deployContract(
name: "StructsInConstructor",
signerOrOptions?: ethers.Signer | FactoryOptions
signerOrOptions?: ethers.Signer | DeployContractOptions
): Promise<Contracts.StructsInConstructor>;

deployContract(
name: "Counter",
args: any[],
signerOrOptions?: ethers.Signer | FactoryOptions
signerOrOptions?: ethers.Signer | DeployContractOptions
): Promise<Contracts.Counter>;
deployContract(
name: "Demo",
args: any[],
signerOrOptions?: ethers.Signer | FactoryOptions
signerOrOptions?: ethers.Signer | DeployContractOptions
): Promise<Contracts.Demo>;
deployContract(
name: "Hello",
args: any[],
signerOrOptions?: ethers.Signer | FactoryOptions
signerOrOptions?: ethers.Signer | DeployContractOptions
): Promise<Contracts.Hello>;
deployContract(
name: "StructsInConstructor",
args: any[],
signerOrOptions?: ethers.Signer | FactoryOptions
signerOrOptions?: ethers.Signer | DeployContractOptions
): Promise<Contracts.StructsInConstructor>;

// default types
Expand All @@ -105,12 +106,12 @@ declare module "hardhat/types/runtime" {
): Promise<ethers.Contract>;
deployContract(
name: string,
signerOrOptions?: ethers.Signer | FactoryOptions
signerOrOptions?: ethers.Signer | DeployContractOptions
): Promise<ethers.Contract>;
deployContract(
name: string,
args: any[],
signerOrOptions?: ethers.Signer | FactoryOptions
signerOrOptions?: ethers.Signer | DeployContractOptions
): Promise<ethers.Contract>;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

import { ethers } from "ethers";
import {
DeployContractOptions,
FactoryOptions,
HardhatEthersHelpers as HardhatEthersHelpersBase,
} from "@nomicfoundation/hardhat-ethers/types";
Expand Down Expand Up @@ -61,49 +62,49 @@ declare module "hardhat/types/runtime" {

deployContract(
name: "EdgeCases",
signerOrOptions?: ethers.Signer | FactoryOptions
signerOrOptions?: ethers.Signer | DeployContractOptions
): Promise<Contracts.EdgeCases>;
deployContract(
name: "SafeMath",
signerOrOptions?: ethers.Signer | FactoryOptions
signerOrOptions?: ethers.Signer | DeployContractOptions
): Promise<Contracts.SafeMath>;
deployContract(
name: "TestContract",
signerOrOptions?: ethers.Signer | FactoryOptions
signerOrOptions?: ethers.Signer | DeployContractOptions
): Promise<Contracts.TestContract>;
deployContract(
name: "TestContract1",
signerOrOptions?: ethers.Signer | FactoryOptions
signerOrOptions?: ethers.Signer | DeployContractOptions
): Promise<Contracts.TestContract1>;
deployContract(
name: "ERC20",
signerOrOptions?: ethers.Signer | FactoryOptions
signerOrOptions?: ethers.Signer | DeployContractOptions
): Promise<Contracts.ERC20>;

deployContract(
name: "EdgeCases",
args: any[],
signerOrOptions?: ethers.Signer | FactoryOptions
signerOrOptions?: ethers.Signer | DeployContractOptions
): Promise<Contracts.EdgeCases>;
deployContract(
name: "SafeMath",
args: any[],
signerOrOptions?: ethers.Signer | FactoryOptions
signerOrOptions?: ethers.Signer | DeployContractOptions
): Promise<Contracts.SafeMath>;
deployContract(
name: "TestContract",
args: any[],
signerOrOptions?: ethers.Signer | FactoryOptions
signerOrOptions?: ethers.Signer | DeployContractOptions
): Promise<Contracts.TestContract>;
deployContract(
name: "TestContract1",
args: any[],
signerOrOptions?: ethers.Signer | FactoryOptions
signerOrOptions?: ethers.Signer | DeployContractOptions
): Promise<Contracts.TestContract1>;
deployContract(
name: "ERC20",
args: any[],
signerOrOptions?: ethers.Signer | FactoryOptions
signerOrOptions?: ethers.Signer | DeployContractOptions
): Promise<Contracts.ERC20>;

// default types
Expand All @@ -123,12 +124,12 @@ declare module "hardhat/types/runtime" {
): Promise<ethers.Contract>;
deployContract(
name: string,
signerOrOptions?: ethers.Signer | FactoryOptions
signerOrOptions?: ethers.Signer | DeployContractOptions
): Promise<ethers.Contract>;
deployContract(
name: string,
args: any[],
signerOrOptions?: ethers.Signer | FactoryOptions
signerOrOptions?: ethers.Signer | DeployContractOptions
): Promise<ethers.Contract>;
}
}
11 changes: 6 additions & 5 deletions packages/target-ethers-v6/src/codegen/hardhat.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ export function generateHardhatHelper(contracts: string[]): string {
return `

import { ethers } from 'ethers'
import { FactoryOptions, HardhatEthersHelpers as HardhatEthersHelpersBase} from "@nomicfoundation/hardhat-ethers/types";
import { DeployContractOptions, FactoryOptions, HardhatEthersHelpers as HardhatEthersHelpersBase} from "@nomicfoundation/hardhat-ethers/types";

import * as Contracts from "."

Expand All @@ -29,14 +29,15 @@ declare module "hardhat/types/runtime" {

${contracts
.map(
(n) => `deployContract(name: '${n}', signerOrOptions?: ethers.Signer | FactoryOptions): Promise<Contracts.${n}>`,
(n) =>
`deployContract(name: '${n}', signerOrOptions?: ethers.Signer | DeployContractOptions): Promise<Contracts.${n}>`,
)
.join('\n')}

${contracts
.map(
(n) =>
`deployContract(name: '${n}', args: any[], signerOrOptions?: ethers.Signer | FactoryOptions): Promise<Contracts.${n}>`,
`deployContract(name: '${n}', args: any[], signerOrOptions?: ethers.Signer | DeployContractOptions): Promise<Contracts.${n}>`,
)
.join('\n')}

Expand All @@ -57,12 +58,12 @@ declare module "hardhat/types/runtime" {
): Promise<ethers.Contract>;
deployContract(
name: string,
signerOrOptions?: ethers.Signer | FactoryOptions
signerOrOptions?: ethers.Signer | DeployContractOptions
): Promise<ethers.Contract>;
deployContract(
name: string,
args: any[],
signerOrOptions?: ethers.Signer | FactoryOptions
signerOrOptions?: ethers.Signer | DeployContractOptions
): Promise<ethers.Contract>;
}
}
Expand Down
27 changes: 20 additions & 7 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading