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

Lines changed: 5 additions & 0 deletions
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.
Lines changed: 6 additions & 0 deletions
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

Lines changed: 9 additions & 8 deletions
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

Lines changed: 9 additions & 2 deletions
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;
Lines changed: 56 additions & 0 deletions
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+
}
Lines changed: 4 additions & 0 deletions
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

Lines changed: 5 additions & 1 deletion
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

Lines changed: 2 additions & 0 deletions
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

Lines changed: 3 additions & 2 deletions
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

Lines changed: 3 additions & 2 deletions
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
}

0 commit comments

Comments
 (0)