Skip to content

Commit 015abb2

Browse files
authored
Support promise inputs in ethers-v5 target (#700)
* feat: wrap primitive input types in PromiseOrValue * chore: regenerate types * test: add tests for inputs wrapped in promise * fix: common import in factories * refactor: use PromiseOrValue for the from override * chore: regenerate types * chore: add changeset
1 parent fd4cd05 commit 015abb2

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

60 files changed

+2178
-1365
lines changed

.changeset/wild-fans-brake.md

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@typechain/ethers-v5': minor
3+
---
4+
5+
Added support for inputs wrapped in promise for ethers-v5 target.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
// SPDX-License-Identifier: MIT
2+
pragma solidity ^0.8.7;
3+
4+
contract Hello {
5+
constructor(uint) {}
6+
}

packages/hardhat-test/typechain-types/Counter.ts

+9-8
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ import type {
2323
TypedEvent,
2424
TypedListener,
2525
OnEvent,
26+
PromiseOrValue,
2627
} from "./common";
2728

2829
export interface CounterInterface extends utils.Interface {
@@ -86,22 +87,22 @@ export interface Counter extends BaseContract {
8687

8788
functions: {
8889
countDown(
89-
overrides?: Overrides & { from?: string | Promise<string> }
90+
overrides?: Overrides & { from?: PromiseOrValue<string> }
9091
): Promise<ContractTransaction>;
9192

9293
countUp(
93-
overrides?: Overrides & { from?: string | Promise<string> }
94+
overrides?: Overrides & { from?: PromiseOrValue<string> }
9495
): Promise<ContractTransaction>;
9596

9697
getCount(overrides?: CallOverrides): Promise<[BigNumber]>;
9798
};
9899

99100
countDown(
100-
overrides?: Overrides & { from?: string | Promise<string> }
101+
overrides?: Overrides & { from?: PromiseOrValue<string> }
101102
): Promise<ContractTransaction>;
102103

103104
countUp(
104-
overrides?: Overrides & { from?: string | Promise<string> }
105+
overrides?: Overrides & { from?: PromiseOrValue<string> }
105106
): Promise<ContractTransaction>;
106107

107108
getCount(overrides?: CallOverrides): Promise<BigNumber>;
@@ -121,23 +122,23 @@ export interface Counter extends BaseContract {
121122

122123
estimateGas: {
123124
countDown(
124-
overrides?: Overrides & { from?: string | Promise<string> }
125+
overrides?: Overrides & { from?: PromiseOrValue<string> }
125126
): Promise<BigNumber>;
126127

127128
countUp(
128-
overrides?: Overrides & { from?: string | Promise<string> }
129+
overrides?: Overrides & { from?: PromiseOrValue<string> }
129130
): Promise<BigNumber>;
130131

131132
getCount(overrides?: CallOverrides): Promise<BigNumber>;
132133
};
133134

134135
populateTransaction: {
135136
countDown(
136-
overrides?: Overrides & { from?: string | Promise<string> }
137+
overrides?: Overrides & { from?: PromiseOrValue<string> }
137138
): Promise<PopulatedTransaction>;
138139

139140
countUp(
140-
overrides?: Overrides & { from?: string | Promise<string> }
141+
overrides?: Overrides & { from?: PromiseOrValue<string> }
141142
): Promise<PopulatedTransaction>;
142143

143144
getCount(overrides?: CallOverrides): Promise<PopulatedTransaction>;

packages/hardhat-test/typechain-types/Demo.ts

+9-2
Original file line numberDiff line numberDiff line change
@@ -15,17 +15,24 @@ import type {
1515
TypedEvent,
1616
TypedListener,
1717
OnEvent,
18+
PromiseOrValue,
1819
} from "./common";
1920

2021
export declare namespace Demo {
21-
export type Struct1Struct = { a: BigNumberish; b: BigNumberish };
22+
export type Struct1Struct = {
23+
a: PromiseOrValue<BigNumberish>;
24+
b: PromiseOrValue<BigNumberish>;
25+
};
2226

2327
export type Struct1StructOutput = [BigNumber, BigNumber] & {
2428
a: BigNumber;
2529
b: BigNumber;
2630
};
2731

28-
export type Struct2Struct = { a: BigNumberish; b: BigNumberish };
32+
export type Struct2Struct = {
33+
a: PromiseOrValue<BigNumberish>;
34+
b: PromiseOrValue<BigNumberish>;
35+
};
2936

3037
export type Struct2StructOutput = [BigNumber, BigNumber] & {
3138
a: BigNumber;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
/* Autogenerated file. Do not edit manually. */
2+
/* tslint:disable */
3+
/* eslint-disable */
4+
import type { BaseContract, Signer, utils } from "ethers";
5+
6+
import type { Listener, Provider } from "@ethersproject/providers";
7+
import type {
8+
TypedEventFilter,
9+
TypedEvent,
10+
TypedListener,
11+
OnEvent,
12+
PromiseOrValue,
13+
} from "../common";
14+
15+
export interface HelloInterface extends utils.Interface {
16+
functions: {};
17+
18+
events: {};
19+
}
20+
21+
export interface Hello extends BaseContract {
22+
connect(signerOrProvider: Signer | Provider | string): this;
23+
attach(addressOrName: string): this;
24+
deployed(): Promise<this>;
25+
26+
interface: HelloInterface;
27+
28+
queryFilter<TEvent extends TypedEvent>(
29+
event: TypedEventFilter<TEvent>,
30+
fromBlockOrBlockhash?: string | number | undefined,
31+
toBlock?: string | number | undefined
32+
): Promise<Array<TEvent>>;
33+
34+
listeners<TEvent extends TypedEvent>(
35+
eventFilter?: TypedEventFilter<TEvent>
36+
): Array<TypedListener<TEvent>>;
37+
listeners(eventName?: string): Array<Listener>;
38+
removeAllListeners<TEvent extends TypedEvent>(
39+
eventFilter: TypedEventFilter<TEvent>
40+
): this;
41+
removeAllListeners(eventName?: string): this;
42+
off: OnEvent<this>;
43+
on: OnEvent<this>;
44+
once: OnEvent<this>;
45+
removeListener: OnEvent<this>;
46+
47+
functions: {};
48+
49+
callStatic: {};
50+
51+
filters: {};
52+
53+
estimateGas: {};
54+
55+
populateTransaction: {};
56+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
/* Autogenerated file. Do not edit manually. */
2+
/* tslint:disable */
3+
/* eslint-disable */
4+
export type { Hello } from "./Hello";

packages/hardhat-test/typechain-types/StructsInConstructor.ts

+5-1
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,13 @@ import type {
1515
TypedEvent,
1616
TypedListener,
1717
OnEvent,
18+
PromiseOrValue,
1819
} from "./common";
1920

20-
export type Vector2Struct = { x: BigNumberish; y: BigNumberish };
21+
export type Vector2Struct = {
22+
x: PromiseOrValue<BigNumberish>;
23+
y: PromiseOrValue<BigNumberish>;
24+
};
2125

2226
export type Vector2StructOutput = [BigNumber, BigNumber] & {
2327
x: BigNumber;

packages/hardhat-test/typechain-types/common.ts

+2
Original file line numberDiff line numberDiff line change
@@ -42,3 +42,5 @@ export type GetContractTypeFromFactory<F> = F extends MinEthersFactory<
4242
export type GetARGsTypeFromFactory<F> = F extends MinEthersFactory<any, any>
4343
? Parameters<F["deploy"]>
4444
: never;
45+
46+
export type PromiseOrValue<T> = T | Promise<T>;

packages/hardhat-test/typechain-types/factories/Counter__factory.ts

+3-2
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
/* eslint-disable */
44
import { Signer, utils, Contract, ContractFactory, Overrides } from "ethers";
55
import type { Provider, TransactionRequest } from "@ethersproject/providers";
6+
import type { PromiseOrValue } from "../common";
67
import type { Counter, CounterInterface } from "../Counter";
78

89
const _abi = [
@@ -81,12 +82,12 @@ export class Counter__factory extends ContractFactory {
8182
}
8283

8384
override deploy(
84-
overrides?: Overrides & { from?: string | Promise<string> }
85+
overrides?: Overrides & { from?: PromiseOrValue<string> }
8586
): Promise<Counter> {
8687
return super.deploy(overrides || {}) as Promise<Counter>;
8788
}
8889
override getDeployTransaction(
89-
overrides?: Overrides & { from?: string | Promise<string> }
90+
overrides?: Overrides & { from?: PromiseOrValue<string> }
9091
): TransactionRequest {
9192
return super.getDeployTransaction(overrides || {});
9293
}

packages/hardhat-test/typechain-types/factories/Demo__factory.ts

+3-2
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
/* eslint-disable */
44
import { Signer, utils, Contract, ContractFactory, Overrides } from "ethers";
55
import type { Provider, TransactionRequest } from "@ethersproject/providers";
6+
import type { PromiseOrValue } from "../common";
67
import type { Demo, DemoInterface } from "../Demo";
78

89
const _abi = [
@@ -71,14 +72,14 @@ export class Demo__factory extends ContractFactory {
7172
override deploy(
7273
input1: Demo.Struct1Struct,
7374
input2: Demo.Struct2Struct[],
74-
overrides?: Overrides & { from?: string | Promise<string> }
75+
overrides?: Overrides & { from?: PromiseOrValue<string> }
7576
): Promise<Demo> {
7677
return super.deploy(input1, input2, overrides || {}) as Promise<Demo>;
7778
}
7879
override getDeployTransaction(
7980
input1: Demo.Struct1Struct,
8081
input2: Demo.Struct2Struct[],
81-
overrides?: Overrides & { from?: string | Promise<string> }
82+
overrides?: Overrides & { from?: PromiseOrValue<string> }
8283
): TransactionRequest {
8384
return super.getDeployTransaction(input1, input2, overrides || {});
8485
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
/* Autogenerated file. Do not edit manually. */
2+
/* tslint:disable */
3+
/* eslint-disable */
4+
import {
5+
Signer,
6+
utils,
7+
Contract,
8+
ContractFactory,
9+
BigNumberish,
10+
Overrides,
11+
} from "ethers";
12+
import type { Provider, TransactionRequest } from "@ethersproject/providers";
13+
import type { PromiseOrValue } from "../../common";
14+
import type { Hello, HelloInterface } from "../../Directory/Hello";
15+
16+
const _abi = [
17+
{
18+
inputs: [
19+
{
20+
internalType: "uint256",
21+
name: "",
22+
type: "uint256",
23+
},
24+
],
25+
stateMutability: "nonpayable",
26+
type: "constructor",
27+
},
28+
];
29+
30+
const _bytecode =
31+
"0x6080604052348015600f57600080fd5b5060405160dc38038060dc8339818101604052810190602d91906045565b506090565b600081519050603f81607c565b92915050565b60006020828403121560585760576077565b5b60006064848285016032565b91505092915050565b6000819050919050565b600080fd5b608381606d565b8114608d57600080fd5b50565b603f80609d6000396000f3fe6080604052600080fdfea2646970667358221220133f91b0425ce510af8b75336b57852d3a7de1c90943e9b26ca086eabb5334d264736f6c63430008070033";
32+
33+
type HelloConstructorParams =
34+
| [signer?: Signer]
35+
| ConstructorParameters<typeof ContractFactory>;
36+
37+
const isSuperArgs = (
38+
xs: HelloConstructorParams
39+
): xs is ConstructorParameters<typeof ContractFactory> => xs.length > 1;
40+
41+
export class Hello__factory extends ContractFactory {
42+
constructor(...args: HelloConstructorParams) {
43+
if (isSuperArgs(args)) {
44+
super(...args);
45+
} else {
46+
super(_abi, _bytecode, args[0]);
47+
}
48+
}
49+
50+
override deploy(
51+
arg0: PromiseOrValue<BigNumberish>,
52+
overrides?: Overrides & { from?: PromiseOrValue<string> }
53+
): Promise<Hello> {
54+
return super.deploy(arg0, overrides || {}) as Promise<Hello>;
55+
}
56+
override getDeployTransaction(
57+
arg0: PromiseOrValue<BigNumberish>,
58+
overrides?: Overrides & { from?: PromiseOrValue<string> }
59+
): TransactionRequest {
60+
return super.getDeployTransaction(arg0, overrides || {});
61+
}
62+
override attach(address: string): Hello {
63+
return super.attach(address) as Hello;
64+
}
65+
override connect(signer: Signer): Hello__factory {
66+
return super.connect(signer) as Hello__factory;
67+
}
68+
69+
static readonly bytecode = _bytecode;
70+
static readonly abi = _abi;
71+
static createInterface(): HelloInterface {
72+
return new utils.Interface(_abi) as HelloInterface;
73+
}
74+
static connect(address: string, signerOrProvider: Signer | Provider): Hello {
75+
return new Contract(address, _abi, signerOrProvider) as Hello;
76+
}
77+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
/* Autogenerated file. Do not edit manually. */
2+
/* tslint:disable */
3+
/* eslint-disable */
4+
export { Hello__factory } from "./Hello__factory";

packages/hardhat-test/typechain-types/factories/StructsInConstructor__factory.ts

+3-2
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
/* eslint-disable */
44
import { Signer, utils, Contract, ContractFactory, Overrides } from "ethers";
55
import type { Provider, TransactionRequest } from "@ethersproject/providers";
6+
import type { PromiseOrValue } from "../common";
67
import type {
78
StructsInConstructor,
89
StructsInConstructorInterface,
@@ -57,7 +58,7 @@ export class StructsInConstructor__factory extends ContractFactory {
5758

5859
override deploy(
5960
segment: [Vector2Struct, Vector2Struct],
60-
overrides?: Overrides & { from?: string | Promise<string> }
61+
overrides?: Overrides & { from?: PromiseOrValue<string> }
6162
): Promise<StructsInConstructor> {
6263
return super.deploy(
6364
segment,
@@ -66,7 +67,7 @@ export class StructsInConstructor__factory extends ContractFactory {
6667
}
6768
override getDeployTransaction(
6869
segment: [Vector2Struct, Vector2Struct],
69-
overrides?: Overrides & { from?: string | Promise<string> }
70+
overrides?: Overrides & { from?: PromiseOrValue<string> }
7071
): TransactionRequest {
7172
return super.getDeployTransaction(segment, overrides || {});
7273
}
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
/* Autogenerated file. Do not edit manually. */
22
/* tslint:disable */
33
/* eslint-disable */
4+
export * as directory from "./Directory";
45
export { Counter__factory } from "./Counter__factory";
56
export { Demo__factory } from "./Demo__factory";
67
export { StructsInConstructor__factory } from "./StructsInConstructor__factory";

packages/hardhat-test/typechain-types/hardhat.d.ts

+9
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,10 @@ declare module "hardhat/types/runtime" {
2020
name: "Demo",
2121
signerOrOptions?: ethers.Signer | FactoryOptions
2222
): Promise<Contracts.Demo__factory>;
23+
getContractFactory(
24+
name: "Hello",
25+
signerOrOptions?: ethers.Signer | FactoryOptions
26+
): Promise<Contracts.Hello__factory>;
2327
getContractFactory(
2428
name: "StructsInConstructor",
2529
signerOrOptions?: ethers.Signer | FactoryOptions
@@ -35,6 +39,11 @@ declare module "hardhat/types/runtime" {
3539
address: string,
3640
signer?: ethers.Signer
3741
): Promise<Contracts.Demo>;
42+
getContractAt(
43+
name: "Hello",
44+
address: string,
45+
signer?: ethers.Signer
46+
): Promise<Contracts.Hello>;
3847
getContractAt(
3948
name: "StructsInConstructor",
4049
address: string,
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,14 @@
11
/* Autogenerated file. Do not edit manually. */
22
/* tslint:disable */
33
/* eslint-disable */
4+
import type * as directory from "./Directory";
5+
export type { directory };
46
export type { Counter } from "./Counter";
57
export type { Demo } from "./Demo";
68
export type { StructsInConstructor } from "./StructsInConstructor";
79
export * as factories from "./factories";
810
export { Counter__factory } from "./factories/Counter__factory";
911
export { Demo__factory } from "./factories/Demo__factory";
12+
export type { Hello } from "./Directory/Hello";
13+
export { Hello__factory } from "./factories/Directory/Hello__factory";
1014
export { StructsInConstructor__factory } from "./factories/StructsInConstructor__factory";

packages/hardhat/test/fixture-projects/hardhat-project/typechain-types/artifacts/contracts/EdgeCases.ts

+1
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import type {
99
TypedEvent,
1010
TypedListener,
1111
OnEvent,
12+
PromiseOrValue,
1213
} from "../../common";
1314

1415
export interface EdgeCasesInterface extends utils.Interface {

0 commit comments

Comments
 (0)