diff --git a/.changeset/clean-cameras-destroy.md b/.changeset/clean-cameras-destroy.md new file mode 100644 index 000000000..fdce8454f --- /dev/null +++ b/.changeset/clean-cameras-destroy.md @@ -0,0 +1,6 @@ +--- +'@typechain/ethers-v5': patch +'@typechain/ethers-v6': patch +--- + +Fix clashes with built-in contract properties diff --git a/contracts/v0.8.9/NameClashes.sol b/contracts/v0.8.9/NameClashes.sol new file mode 100644 index 000000000..fe6f0fc53 --- /dev/null +++ b/contracts/v0.8.9/NameClashes.sol @@ -0,0 +1,20 @@ +pragma solidity ^0.8.7; + +contract NameClashes { + address public target; + address public runner; + address public filters; + address public connect; + address public attach; + address public getAddress; + address public getDeployedCode; + address public getFunction; + address public on; + address public off; + address public once; + address public listeners; + address public signer; + address public provider; + address public deployed; + address public then; +} diff --git a/packages/target-ethers-v5-test/types/factories/v0.8.9/NameClashes__factory.ts b/packages/target-ethers-v5-test/types/factories/v0.8.9/NameClashes__factory.ts new file mode 100644 index 000000000..2ce1ee94b --- /dev/null +++ b/packages/target-ethers-v5-test/types/factories/v0.8.9/NameClashes__factory.ts @@ -0,0 +1,234 @@ +/* Autogenerated file. Do not edit manually. */ +/* tslint:disable */ +/* eslint-disable */ + +import { Contract, Signer, utils } from "ethers"; +import type { Provider } from "@ethersproject/providers"; +import type { + NameClashes, + NameClashesInterface, +} from "../../v0.8.9/NameClashes"; + +const _abi = [ + { + inputs: [], + name: "attach", + outputs: [ + { + internalType: "address", + name: "", + type: "address", + }, + ], + stateMutability: "view", + type: "function", + }, + { + inputs: [], + name: "connect", + outputs: [ + { + internalType: "address", + name: "", + type: "address", + }, + ], + stateMutability: "view", + type: "function", + }, + { + inputs: [], + name: "deployed", + outputs: [ + { + internalType: "address", + name: "", + type: "address", + }, + ], + stateMutability: "view", + type: "function", + }, + { + inputs: [], + name: "filters", + outputs: [ + { + internalType: "address", + name: "", + type: "address", + }, + ], + stateMutability: "view", + type: "function", + }, + { + inputs: [], + name: "getAddress", + outputs: [ + { + internalType: "address", + name: "", + type: "address", + }, + ], + stateMutability: "view", + type: "function", + }, + { + inputs: [], + name: "getDeployedCode", + outputs: [ + { + internalType: "address", + name: "", + type: "address", + }, + ], + stateMutability: "view", + type: "function", + }, + { + inputs: [], + name: "getFunction", + outputs: [ + { + internalType: "address", + name: "", + type: "address", + }, + ], + stateMutability: "view", + type: "function", + }, + { + inputs: [], + name: "listeners", + outputs: [ + { + internalType: "address", + name: "", + type: "address", + }, + ], + stateMutability: "view", + type: "function", + }, + { + inputs: [], + name: "off", + outputs: [ + { + internalType: "address", + name: "", + type: "address", + }, + ], + stateMutability: "view", + type: "function", + }, + { + inputs: [], + name: "on", + outputs: [ + { + internalType: "address", + name: "", + type: "address", + }, + ], + stateMutability: "view", + type: "function", + }, + { + inputs: [], + name: "once", + outputs: [ + { + internalType: "address", + name: "", + type: "address", + }, + ], + stateMutability: "view", + type: "function", + }, + { + inputs: [], + name: "provider", + outputs: [ + { + internalType: "address", + name: "", + type: "address", + }, + ], + stateMutability: "view", + type: "function", + }, + { + inputs: [], + name: "runner", + outputs: [ + { + internalType: "address", + name: "", + type: "address", + }, + ], + stateMutability: "view", + type: "function", + }, + { + inputs: [], + name: "signer", + outputs: [ + { + internalType: "address", + name: "", + type: "address", + }, + ], + stateMutability: "view", + type: "function", + }, + { + inputs: [], + name: "target", + outputs: [ + { + internalType: "address", + name: "", + type: "address", + }, + ], + stateMutability: "view", + type: "function", + }, + { + inputs: [], + name: "then", + outputs: [ + { + internalType: "address", + name: "", + type: "address", + }, + ], + stateMutability: "view", + type: "function", + }, +] as const; + +export class NameClashes__factory { + static readonly abi = _abi; + static createInterface(): NameClashesInterface { + return new utils.Interface(_abi) as NameClashesInterface; + } + static connect( + address: string, + signerOrProvider: Signer | Provider + ): NameClashes { + return new Contract(address, _abi, signerOrProvider) as NameClashes; + } +} diff --git a/packages/target-ethers-v5-test/types/factories/v0.8.9/index.ts b/packages/target-ethers-v5-test/types/factories/v0.8.9/index.ts index 964695c88..af7f489dd 100644 --- a/packages/target-ethers-v5-test/types/factories/v0.8.9/index.ts +++ b/packages/target-ethers-v5-test/types/factories/v0.8.9/index.ts @@ -6,4 +6,5 @@ export * as rarity from "./Rarity"; export * as nested from "./nested"; export { ISimpleToken__factory } from "./ISimpleToken__factory"; export { Issue552_Reproduction__factory } from "./Issue552_Reproduction__factory"; +export { NameClashes__factory } from "./NameClashes__factory"; export { SimpleToken__factory } from "./SimpleToken__factory"; diff --git a/packages/target-ethers-v5-test/types/index.ts b/packages/target-ethers-v5-test/types/index.ts index 86c671afb..0f56e2d84 100644 --- a/packages/target-ethers-v5-test/types/index.ts +++ b/packages/target-ethers-v5-test/types/index.ts @@ -38,6 +38,8 @@ export type { KingOfTheHill } from "./v0.8.9/KingOfTheHill/KingOfTheHill"; export { KingOfTheHill__factory } from "./factories/v0.8.9/KingOfTheHill/KingOfTheHill__factory"; export type { Withdrawable } from "./v0.8.9/KingOfTheHill/Withdrawable"; export { Withdrawable__factory } from "./factories/v0.8.9/KingOfTheHill/Withdrawable__factory"; +export type { NameClashes } from "./v0.8.9/NameClashes"; +export { NameClashes__factory } from "./factories/v0.8.9/NameClashes__factory"; export type { NestedLibrary } from "./v0.8.9/nested/a/NestedLibrary"; export { NestedLibrary__factory } from "./factories/v0.8.9/nested/a/NestedLibrary__factory"; export type { ERC721 } from "./v0.8.9/Rarity/ERC721"; diff --git a/packages/target-ethers-v5-test/types/v0.8.9/NameClashes.ts b/packages/target-ethers-v5-test/types/v0.8.9/NameClashes.ts new file mode 100644 index 000000000..2302094de --- /dev/null +++ b/packages/target-ethers-v5-test/types/v0.8.9/NameClashes.ts @@ -0,0 +1,301 @@ +/* Autogenerated file. Do not edit manually. */ +/* tslint:disable */ +/* eslint-disable */ +import type { + BaseContract, + BigNumber, + BytesLike, + CallOverrides, + PopulatedTransaction, + Signer, + utils, +} from "ethers"; +import type { FunctionFragment, Result } from "@ethersproject/abi"; +import type { Listener, Provider } from "@ethersproject/providers"; +import type { + TypedEventFilter, + TypedEvent, + TypedListener, + OnEvent, +} from "../common"; + +export interface NameClashesInterface extends utils.Interface { + functions: { + "attach()": FunctionFragment; + "connect()": FunctionFragment; + "deployed()": FunctionFragment; + "filters()": FunctionFragment; + "getAddress()": FunctionFragment; + "getDeployedCode()": FunctionFragment; + "getFunction()": FunctionFragment; + "listeners()": FunctionFragment; + "off()": FunctionFragment; + "on()": FunctionFragment; + "once()": FunctionFragment; + "provider()": FunctionFragment; + "runner()": FunctionFragment; + "signer()": FunctionFragment; + "target()": FunctionFragment; + "then()": FunctionFragment; + }; + + getFunction( + nameOrSignatureOrTopic: + | "attach" + | "connect" + | "deployed" + | "filters" + | "getAddress" + | "getDeployedCode" + | "getFunction" + | "listeners" + | "off" + | "on" + | "once" + | "provider" + | "runner" + | "signer" + | "target" + | "then" + ): FunctionFragment; + + encodeFunctionData(functionFragment: "attach", values?: undefined): string; + encodeFunctionData(functionFragment: "connect", values?: undefined): string; + encodeFunctionData(functionFragment: "deployed", values?: undefined): string; + encodeFunctionData(functionFragment: "filters", values?: undefined): string; + encodeFunctionData( + functionFragment: "getAddress", + values?: undefined + ): string; + encodeFunctionData( + functionFragment: "getDeployedCode", + values?: undefined + ): string; + encodeFunctionData( + functionFragment: "getFunction", + values?: undefined + ): string; + encodeFunctionData(functionFragment: "listeners", values?: undefined): string; + encodeFunctionData(functionFragment: "off", values?: undefined): string; + encodeFunctionData(functionFragment: "on", values?: undefined): string; + encodeFunctionData(functionFragment: "once", values?: undefined): string; + encodeFunctionData(functionFragment: "provider", values?: undefined): string; + encodeFunctionData(functionFragment: "runner", values?: undefined): string; + encodeFunctionData(functionFragment: "signer", values?: undefined): string; + encodeFunctionData(functionFragment: "target", values?: undefined): string; + encodeFunctionData(functionFragment: "then", values?: undefined): string; + + decodeFunctionResult(functionFragment: "attach", data: BytesLike): Result; + decodeFunctionResult(functionFragment: "connect", data: BytesLike): Result; + decodeFunctionResult(functionFragment: "deployed", data: BytesLike): Result; + decodeFunctionResult(functionFragment: "filters", data: BytesLike): Result; + decodeFunctionResult(functionFragment: "getAddress", data: BytesLike): Result; + decodeFunctionResult( + functionFragment: "getDeployedCode", + data: BytesLike + ): Result; + decodeFunctionResult( + functionFragment: "getFunction", + data: BytesLike + ): Result; + decodeFunctionResult(functionFragment: "listeners", data: BytesLike): Result; + decodeFunctionResult(functionFragment: "off", data: BytesLike): Result; + decodeFunctionResult(functionFragment: "on", data: BytesLike): Result; + decodeFunctionResult(functionFragment: "once", data: BytesLike): Result; + decodeFunctionResult(functionFragment: "provider", data: BytesLike): Result; + decodeFunctionResult(functionFragment: "runner", data: BytesLike): Result; + decodeFunctionResult(functionFragment: "signer", data: BytesLike): Result; + decodeFunctionResult(functionFragment: "target", data: BytesLike): Result; + decodeFunctionResult(functionFragment: "then", data: BytesLike): Result; + + events: {}; +} + +export interface NameClashes extends BaseContract { + connect(signerOrProvider: Signer | Provider | string): this; + attach(addressOrName: string): this; + deployed(): Promise; + + interface: NameClashesInterface; + + queryFilter( + event: TypedEventFilter, + fromBlockOrBlockhash?: string | number | undefined, + toBlock?: string | number | undefined + ): Promise>; + + listeners( + eventFilter?: TypedEventFilter + ): Array>; + listeners(eventName?: string): Array; + removeAllListeners( + eventFilter: TypedEventFilter + ): this; + removeAllListeners(eventName?: string): this; + off: OnEvent; + on: OnEvent; + once: OnEvent; + removeListener: OnEvent; + + functions: { + attach(overrides?: CallOverrides): Promise<[string]>; + + connect(overrides?: CallOverrides): Promise<[string]>; + + deployed(overrides?: CallOverrides): Promise<[string]>; + + filters(overrides?: CallOverrides): Promise<[string]>; + + getAddress(overrides?: CallOverrides): Promise<[string]>; + + getDeployedCode(overrides?: CallOverrides): Promise<[string]>; + + getFunction(overrides?: CallOverrides): Promise<[string]>; + + listeners(overrides?: CallOverrides): Promise<[string]>; + + off(overrides?: CallOverrides): Promise<[string]>; + + on(overrides?: CallOverrides): Promise<[string]>; + + once(overrides?: CallOverrides): Promise<[string]>; + + provider(overrides?: CallOverrides): Promise<[string]>; + + runner(overrides?: CallOverrides): Promise<[string]>; + + signer(overrides?: CallOverrides): Promise<[string]>; + + target(overrides?: CallOverrides): Promise<[string]>; + + then(overrides?: CallOverrides): Promise<[string]>; + }; + + attach(overrides?: CallOverrides): Promise; + + filters(overrides?: CallOverrides): Promise; + + getAddress(overrides?: CallOverrides): Promise; + + getDeployedCode(overrides?: CallOverrides): Promise; + + getFunction(overrides?: CallOverrides): Promise; + + listeners(overrides?: CallOverrides): Promise; + + off(overrides?: CallOverrides): Promise; + + on(overrides?: CallOverrides): Promise; + + once(overrides?: CallOverrides): Promise; + + runner(overrides?: CallOverrides): Promise; + + target(overrides?: CallOverrides): Promise; + + then(overrides?: CallOverrides): Promise; + + callStatic: { + attach(overrides?: CallOverrides): Promise; + + connect(overrides?: CallOverrides): Promise; + + deployed(overrides?: CallOverrides): Promise; + + filters(overrides?: CallOverrides): Promise; + + getAddress(overrides?: CallOverrides): Promise; + + getDeployedCode(overrides?: CallOverrides): Promise; + + getFunction(overrides?: CallOverrides): Promise; + + listeners(overrides?: CallOverrides): Promise; + + off(overrides?: CallOverrides): Promise; + + on(overrides?: CallOverrides): Promise; + + once(overrides?: CallOverrides): Promise; + + provider(overrides?: CallOverrides): Promise; + + runner(overrides?: CallOverrides): Promise; + + signer(overrides?: CallOverrides): Promise; + + target(overrides?: CallOverrides): Promise; + + then(overrides?: CallOverrides): Promise; + }; + + filters: {}; + + estimateGas: { + attach(overrides?: CallOverrides): Promise; + + connect(overrides?: CallOverrides): Promise; + + deployed(overrides?: CallOverrides): Promise; + + filters(overrides?: CallOverrides): Promise; + + getAddress(overrides?: CallOverrides): Promise; + + getDeployedCode(overrides?: CallOverrides): Promise; + + getFunction(overrides?: CallOverrides): Promise; + + listeners(overrides?: CallOverrides): Promise; + + off(overrides?: CallOverrides): Promise; + + on(overrides?: CallOverrides): Promise; + + once(overrides?: CallOverrides): Promise; + + provider(overrides?: CallOverrides): Promise; + + runner(overrides?: CallOverrides): Promise; + + signer(overrides?: CallOverrides): Promise; + + target(overrides?: CallOverrides): Promise; + + then(overrides?: CallOverrides): Promise; + }; + + populateTransaction: { + attach(overrides?: CallOverrides): Promise; + + connect(overrides?: CallOverrides): Promise; + + deployed(overrides?: CallOverrides): Promise; + + filters(overrides?: CallOverrides): Promise; + + getAddress(overrides?: CallOverrides): Promise; + + getDeployedCode(overrides?: CallOverrides): Promise; + + getFunction(overrides?: CallOverrides): Promise; + + listeners(overrides?: CallOverrides): Promise; + + off(overrides?: CallOverrides): Promise; + + on(overrides?: CallOverrides): Promise; + + once(overrides?: CallOverrides): Promise; + + provider(overrides?: CallOverrides): Promise; + + runner(overrides?: CallOverrides): Promise; + + signer(overrides?: CallOverrides): Promise; + + target(overrides?: CallOverrides): Promise; + + then(overrides?: CallOverrides): Promise; + }; +} diff --git a/packages/target-ethers-v5-test/types/v0.8.9/index.ts b/packages/target-ethers-v5-test/types/v0.8.9/index.ts index 25c6eeca5..613fbc4b1 100644 --- a/packages/target-ethers-v5-test/types/v0.8.9/index.ts +++ b/packages/target-ethers-v5-test/types/v0.8.9/index.ts @@ -9,4 +9,5 @@ import type * as nested from "./nested"; export type { nested }; export type { ISimpleToken } from "./ISimpleToken"; export type { Issue552_Reproduction } from "./Issue552_Reproduction"; +export type { NameClashes } from "./NameClashes"; export type { SimpleToken } from "./SimpleToken"; diff --git a/packages/target-ethers-v5/src/codegen/reserved-keywords.ts b/packages/target-ethers-v5/src/codegen/reserved-keywords.ts index 478698758..047b3aa63 100644 --- a/packages/target-ethers-v5/src/codegen/reserved-keywords.ts +++ b/packages/target-ethers-v5/src/codegen/reserved-keywords.ts @@ -1 +1,7 @@ -export const reservedKeywords = new Set(['signer', 'provider', 'deployTransaction', 'deployed', 'fallback', 'connect']) +import { BaseContract, constants } from 'ethers' + +export const reservedKeywords = new Set([ + 'then', + ...Object.getOwnPropertyNames(BaseContract.prototype), // for methods + ...Object.keys(new BaseContract(constants.AddressZero, [])), // for readOnly properties +]) diff --git a/packages/target-ethers-v6-test/test/NameClashes.test.ts b/packages/target-ethers-v6-test/test/NameClashes.test.ts new file mode 100644 index 000000000..cab361740 --- /dev/null +++ b/packages/target-ethers-v6-test/test/NameClashes.test.ts @@ -0,0 +1,18 @@ +import type { BaseContract } from 'ethers' +import type { AssertTrue, Has } from 'test-utils' + +import type { NameClashes } from '../types/v0.8.9/NameClashes' + +type _testTarget = AssertTrue> +type _testRunner = AssertTrue> +type _testFilters = AssertTrue> +type _testGetAddress = AssertTrue> +type _testGetDeployedCode = AssertTrue> +type _testGetFunction = AssertTrue> +type _testOn = AssertTrue> +type _testOff = AssertTrue> +type _testOnce = AssertTrue> +type _testListeners = AssertTrue> + +// "then" won't be passed through by ethers as it's listed in `passProperties` (see: https://github.com/ethers-io/ethers.js/blob/6ee1a5f8bb38ec31fa84c00aae7f091e1d3d6837/src.ts/contract/contract.ts#L779) +type _testThen = AssertTrue<'then' extends keyof NameClashes ? false : true> diff --git a/packages/target-ethers-v6-test/types/factories/v0.8.9/NameClashes__factory.ts b/packages/target-ethers-v6-test/types/factories/v0.8.9/NameClashes__factory.ts new file mode 100644 index 000000000..09f0b33bf --- /dev/null +++ b/packages/target-ethers-v6-test/types/factories/v0.8.9/NameClashes__factory.ts @@ -0,0 +1,230 @@ +/* Autogenerated file. Do not edit manually. */ +/* tslint:disable */ +/* eslint-disable */ + +import { Contract, Interface, type ContractRunner } from "ethers"; +import type { + NameClashes, + NameClashesInterface, +} from "../../v0.8.9/NameClashes"; + +const _abi = [ + { + inputs: [], + name: "attach", + outputs: [ + { + internalType: "address", + name: "", + type: "address", + }, + ], + stateMutability: "view", + type: "function", + }, + { + inputs: [], + name: "connect", + outputs: [ + { + internalType: "address", + name: "", + type: "address", + }, + ], + stateMutability: "view", + type: "function", + }, + { + inputs: [], + name: "deployed", + outputs: [ + { + internalType: "address", + name: "", + type: "address", + }, + ], + stateMutability: "view", + type: "function", + }, + { + inputs: [], + name: "filters", + outputs: [ + { + internalType: "address", + name: "", + type: "address", + }, + ], + stateMutability: "view", + type: "function", + }, + { + inputs: [], + name: "getAddress", + outputs: [ + { + internalType: "address", + name: "", + type: "address", + }, + ], + stateMutability: "view", + type: "function", + }, + { + inputs: [], + name: "getDeployedCode", + outputs: [ + { + internalType: "address", + name: "", + type: "address", + }, + ], + stateMutability: "view", + type: "function", + }, + { + inputs: [], + name: "getFunction", + outputs: [ + { + internalType: "address", + name: "", + type: "address", + }, + ], + stateMutability: "view", + type: "function", + }, + { + inputs: [], + name: "listeners", + outputs: [ + { + internalType: "address", + name: "", + type: "address", + }, + ], + stateMutability: "view", + type: "function", + }, + { + inputs: [], + name: "off", + outputs: [ + { + internalType: "address", + name: "", + type: "address", + }, + ], + stateMutability: "view", + type: "function", + }, + { + inputs: [], + name: "on", + outputs: [ + { + internalType: "address", + name: "", + type: "address", + }, + ], + stateMutability: "view", + type: "function", + }, + { + inputs: [], + name: "once", + outputs: [ + { + internalType: "address", + name: "", + type: "address", + }, + ], + stateMutability: "view", + type: "function", + }, + { + inputs: [], + name: "provider", + outputs: [ + { + internalType: "address", + name: "", + type: "address", + }, + ], + stateMutability: "view", + type: "function", + }, + { + inputs: [], + name: "runner", + outputs: [ + { + internalType: "address", + name: "", + type: "address", + }, + ], + stateMutability: "view", + type: "function", + }, + { + inputs: [], + name: "signer", + outputs: [ + { + internalType: "address", + name: "", + type: "address", + }, + ], + stateMutability: "view", + type: "function", + }, + { + inputs: [], + name: "target", + outputs: [ + { + internalType: "address", + name: "", + type: "address", + }, + ], + stateMutability: "view", + type: "function", + }, + { + inputs: [], + name: "then", + outputs: [ + { + internalType: "address", + name: "", + type: "address", + }, + ], + stateMutability: "view", + type: "function", + }, +] as const; + +export class NameClashes__factory { + static readonly abi = _abi; + static createInterface(): NameClashesInterface { + return new Interface(_abi) as NameClashesInterface; + } + static connect(address: string, runner?: ContractRunner | null): NameClashes { + return new Contract(address, _abi, runner) as unknown as NameClashes; + } +} diff --git a/packages/target-ethers-v6-test/types/factories/v0.8.9/index.ts b/packages/target-ethers-v6-test/types/factories/v0.8.9/index.ts index 964695c88..af7f489dd 100644 --- a/packages/target-ethers-v6-test/types/factories/v0.8.9/index.ts +++ b/packages/target-ethers-v6-test/types/factories/v0.8.9/index.ts @@ -6,4 +6,5 @@ export * as rarity from "./Rarity"; export * as nested from "./nested"; export { ISimpleToken__factory } from "./ISimpleToken__factory"; export { Issue552_Reproduction__factory } from "./Issue552_Reproduction__factory"; +export { NameClashes__factory } from "./NameClashes__factory"; export { SimpleToken__factory } from "./SimpleToken__factory"; diff --git a/packages/target-ethers-v6-test/types/index.ts b/packages/target-ethers-v6-test/types/index.ts index 86c671afb..0f56e2d84 100644 --- a/packages/target-ethers-v6-test/types/index.ts +++ b/packages/target-ethers-v6-test/types/index.ts @@ -38,6 +38,8 @@ export type { KingOfTheHill } from "./v0.8.9/KingOfTheHill/KingOfTheHill"; export { KingOfTheHill__factory } from "./factories/v0.8.9/KingOfTheHill/KingOfTheHill__factory"; export type { Withdrawable } from "./v0.8.9/KingOfTheHill/Withdrawable"; export { Withdrawable__factory } from "./factories/v0.8.9/KingOfTheHill/Withdrawable__factory"; +export type { NameClashes } from "./v0.8.9/NameClashes"; +export { NameClashes__factory } from "./factories/v0.8.9/NameClashes__factory"; export type { NestedLibrary } from "./v0.8.9/nested/a/NestedLibrary"; export { NestedLibrary__factory } from "./factories/v0.8.9/nested/a/NestedLibrary__factory"; export type { ERC721 } from "./v0.8.9/Rarity/ERC721"; diff --git a/packages/target-ethers-v6-test/types/v0.8.9/NameClashes.ts b/packages/target-ethers-v6-test/types/v0.8.9/NameClashes.ts new file mode 100644 index 000000000..0e319e0cd --- /dev/null +++ b/packages/target-ethers-v6-test/types/v0.8.9/NameClashes.ts @@ -0,0 +1,212 @@ +/* Autogenerated file. Do not edit manually. */ +/* tslint:disable */ +/* eslint-disable */ +import type { + BaseContract, + BytesLike, + FunctionFragment, + Result, + Interface, + ContractRunner, + ContractMethod, + Listener, +} from "ethers"; +import type { + TypedContractEvent, + TypedDeferredTopicFilter, + TypedEventLog, + TypedListener, + TypedContractMethod, +} from "../common"; + +export interface NameClashesInterface extends Interface { + getFunction( + nameOrSignature: + | "attach" + | "connect" + | "deployed" + | "filters" + | "getAddress" + | "getDeployedCode" + | "getFunction" + | "listeners" + | "off" + | "on" + | "once" + | "provider" + | "runner" + | "signer" + | "target" + | "then" + ): FunctionFragment; + + encodeFunctionData(functionFragment: "attach", values?: undefined): string; + encodeFunctionData(functionFragment: "connect", values?: undefined): string; + encodeFunctionData(functionFragment: "deployed", values?: undefined): string; + encodeFunctionData(functionFragment: "filters", values?: undefined): string; + encodeFunctionData( + functionFragment: "getAddress", + values?: undefined + ): string; + encodeFunctionData( + functionFragment: "getDeployedCode", + values?: undefined + ): string; + encodeFunctionData( + functionFragment: "getFunction", + values?: undefined + ): string; + encodeFunctionData(functionFragment: "listeners", values?: undefined): string; + encodeFunctionData(functionFragment: "off", values?: undefined): string; + encodeFunctionData(functionFragment: "on", values?: undefined): string; + encodeFunctionData(functionFragment: "once", values?: undefined): string; + encodeFunctionData(functionFragment: "provider", values?: undefined): string; + encodeFunctionData(functionFragment: "runner", values?: undefined): string; + encodeFunctionData(functionFragment: "signer", values?: undefined): string; + encodeFunctionData(functionFragment: "target", values?: undefined): string; + encodeFunctionData(functionFragment: "then", values?: undefined): string; + + decodeFunctionResult(functionFragment: "attach", data: BytesLike): Result; + decodeFunctionResult(functionFragment: "connect", data: BytesLike): Result; + decodeFunctionResult(functionFragment: "deployed", data: BytesLike): Result; + decodeFunctionResult(functionFragment: "filters", data: BytesLike): Result; + decodeFunctionResult(functionFragment: "getAddress", data: BytesLike): Result; + decodeFunctionResult( + functionFragment: "getDeployedCode", + data: BytesLike + ): Result; + decodeFunctionResult( + functionFragment: "getFunction", + data: BytesLike + ): Result; + decodeFunctionResult(functionFragment: "listeners", data: BytesLike): Result; + decodeFunctionResult(functionFragment: "off", data: BytesLike): Result; + decodeFunctionResult(functionFragment: "on", data: BytesLike): Result; + decodeFunctionResult(functionFragment: "once", data: BytesLike): Result; + decodeFunctionResult(functionFragment: "provider", data: BytesLike): Result; + decodeFunctionResult(functionFragment: "runner", data: BytesLike): Result; + decodeFunctionResult(functionFragment: "signer", data: BytesLike): Result; + decodeFunctionResult(functionFragment: "target", data: BytesLike): Result; + decodeFunctionResult(functionFragment: "then", data: BytesLike): Result; +} + +export interface NameClashes extends BaseContract { + connect(runner?: ContractRunner | null): NameClashes; + waitForDeployment(): Promise; + + interface: NameClashesInterface; + + queryFilter( + event: TCEvent, + fromBlockOrBlockhash?: string | number | undefined, + toBlock?: string | number | undefined + ): Promise>>; + queryFilter( + filter: TypedDeferredTopicFilter, + fromBlockOrBlockhash?: string | number | undefined, + toBlock?: string | number | undefined + ): Promise>>; + + on( + event: TCEvent, + listener: TypedListener + ): Promise; + on( + filter: TypedDeferredTopicFilter, + listener: TypedListener + ): Promise; + + once( + event: TCEvent, + listener: TypedListener + ): Promise; + once( + filter: TypedDeferredTopicFilter, + listener: TypedListener + ): Promise; + + listeners( + event: TCEvent + ): Promise>>; + listeners(eventName?: string): Promise>; + removeAllListeners( + event?: TCEvent + ): Promise; + + attach: TypedContractMethod<[], [string], "view">; + + filters: TypedContractMethod<[], [string], "view">; + + getAddress: TypedContractMethod<[], [string], "view">; + + getDeployedCode: TypedContractMethod<[], [string], "view">; + + getFunction: TypedContractMethod<[], [string], "view">; + + listeners: TypedContractMethod<[], [string], "view">; + + off: TypedContractMethod<[], [string], "view">; + + on: TypedContractMethod<[], [string], "view">; + + once: TypedContractMethod<[], [string], "view">; + + runner: TypedContractMethod<[], [string], "view">; + + target: TypedContractMethod<[], [string], "view">; + + then: TypedContractMethod<[], [string], "view">; + + getFunction( + key: string | FunctionFragment + ): T; + + getFunction( + nameOrSignature: "attach" + ): TypedContractMethod<[], [string], "view">; + getFunction( + nameOrSignature: "connect" + ): TypedContractMethod<[], [string], "view">; + getFunction( + nameOrSignature: "deployed" + ): TypedContractMethod<[], [string], "view">; + getFunction( + nameOrSignature: "filters" + ): TypedContractMethod<[], [string], "view">; + getFunction( + nameOrSignature: "getAddress" + ): TypedContractMethod<[], [string], "view">; + getFunction( + nameOrSignature: "getDeployedCode" + ): TypedContractMethod<[], [string], "view">; + getFunction( + nameOrSignature: "getFunction" + ): TypedContractMethod<[], [string], "view">; + getFunction( + nameOrSignature: "listeners" + ): TypedContractMethod<[], [string], "view">; + getFunction( + nameOrSignature: "off" + ): TypedContractMethod<[], [string], "view">; + getFunction(nameOrSignature: "on"): TypedContractMethod<[], [string], "view">; + getFunction( + nameOrSignature: "once" + ): TypedContractMethod<[], [string], "view">; + getFunction( + nameOrSignature: "provider" + ): TypedContractMethod<[], [string], "view">; + getFunction( + nameOrSignature: "runner" + ): TypedContractMethod<[], [string], "view">; + getFunction( + nameOrSignature: "signer" + ): TypedContractMethod<[], [string], "view">; + getFunction( + nameOrSignature: "target" + ): TypedContractMethod<[], [string], "view">; + getFunction( + nameOrSignature: "then" + ): TypedContractMethod<[], [string], "view">; + + filters: {}; +} diff --git a/packages/target-ethers-v6-test/types/v0.8.9/index.ts b/packages/target-ethers-v6-test/types/v0.8.9/index.ts index 25c6eeca5..613fbc4b1 100644 --- a/packages/target-ethers-v6-test/types/v0.8.9/index.ts +++ b/packages/target-ethers-v6-test/types/v0.8.9/index.ts @@ -9,4 +9,5 @@ import type * as nested from "./nested"; export type { nested }; export type { ISimpleToken } from "./ISimpleToken"; export type { Issue552_Reproduction } from "./Issue552_Reproduction"; +export type { NameClashes } from "./NameClashes"; export type { SimpleToken } from "./SimpleToken"; diff --git a/packages/target-ethers-v6/src/codegen/index.ts b/packages/target-ethers-v6/src/codegen/index.ts index fa0ff9d16..697dd21e2 100644 --- a/packages/target-ethers-v6/src/codegen/index.ts +++ b/packages/target-ethers-v6/src/codegen/index.ts @@ -30,7 +30,7 @@ import { generateGetFunctionForInterface, generateParamNames, } from './functions' -import { reservedKeywords } from './reserved-keywords' +import { baseContractProperties, ethersPassProperties } from './reserved-keywords' import { generateStructTypes } from './structs' import { generateInputTypes } from './types' @@ -73,8 +73,9 @@ export function codegenContractTypings(contract: Contract, codegenConfig: Codege ${EVENT_METHOD_OVERRIDES} + ${values(contract.functions) - .filter((f) => !reservedKeywords.has(f[0].name)) + .filter((f) => !ethersPassProperties.has(f[0].name) && !baseContractProperties.has(f[0].name)) .map(codegenFunctions.bind(null, { codegenConfig })) .join('\n')} diff --git a/packages/target-ethers-v6/src/codegen/reserved-keywords.ts b/packages/target-ethers-v6/src/codegen/reserved-keywords.ts index 1cc0f1eed..f0567bd21 100644 --- a/packages/target-ethers-v6/src/codegen/reserved-keywords.ts +++ b/packages/target-ethers-v6/src/codegen/reserved-keywords.ts @@ -1,4 +1,10 @@ -export const reservedKeywords = new Set(['signer', 'provider', 'deployTransaction', 'deployed', 'fallback', 'connect']) +import { BaseContract } from 'ethers' + +export const ethersPassProperties = new Set(['then']) +export const baseContractProperties = new Set([ + ...Object.getOwnPropertyNames(BaseContract.prototype), // for methods + ...Object.keys(new BaseContract('0x', [])), // for readOnly properties +]) export const reservedKeywordsLabels = new Set([ 'class', diff --git a/packages/target-web3-v1-test/types/v0.8.9/NameClashes.ts b/packages/target-web3-v1-test/types/v0.8.9/NameClashes.ts new file mode 100644 index 000000000..f8e469bd6 --- /dev/null +++ b/packages/target-web3-v1-test/types/v0.8.9/NameClashes.ts @@ -0,0 +1,67 @@ +/* Autogenerated file. Do not edit manually. */ +/* tslint:disable */ +/* eslint-disable */ + +import type BN from "bn.js"; +import type { ContractOptions } from "web3-eth-contract"; +import type { EventLog } from "web3-core"; +import type { EventEmitter } from "events"; +import type { + Callback, + PayableTransactionObject, + NonPayableTransactionObject, + BlockType, + ContractEventLog, + BaseContract, +} from "../types"; + +export interface EventOptions { + filter?: object; + fromBlock?: BlockType; + topics?: string[]; +} + +export interface NameClashes extends BaseContract { + constructor( + jsonInterface: any[], + address?: string, + options?: ContractOptions + ): NameClashes; + clone(): NameClashes; + methods: { + attach(): NonPayableTransactionObject; + + connect(): NonPayableTransactionObject; + + deployed(): NonPayableTransactionObject; + + filters(): NonPayableTransactionObject; + + getAddress(): NonPayableTransactionObject; + + getDeployedCode(): NonPayableTransactionObject; + + getFunction(): NonPayableTransactionObject; + + listeners(): NonPayableTransactionObject; + + off(): NonPayableTransactionObject; + + on(): NonPayableTransactionObject; + + once(): NonPayableTransactionObject; + + provider(): NonPayableTransactionObject; + + runner(): NonPayableTransactionObject; + + signer(): NonPayableTransactionObject; + + target(): NonPayableTransactionObject; + + then(): NonPayableTransactionObject; + }; + events: { + allEvents(options?: EventOptions, cb?: Callback): EventEmitter; + }; +} diff --git a/packages/target-web3-v1-test/types/v0.8.9/index.ts b/packages/target-web3-v1-test/types/v0.8.9/index.ts index 25c6eeca5..613fbc4b1 100644 --- a/packages/target-web3-v1-test/types/v0.8.9/index.ts +++ b/packages/target-web3-v1-test/types/v0.8.9/index.ts @@ -9,4 +9,5 @@ import type * as nested from "./nested"; export type { nested }; export type { ISimpleToken } from "./ISimpleToken"; export type { Issue552_Reproduction } from "./Issue552_Reproduction"; +export type { NameClashes } from "./NameClashes"; export type { SimpleToken } from "./SimpleToken";