dethcrypto / dethcrypto/TypeChain

Generated factory import unnecessary Provider from ethers when there is a contract named Provider

Open
#904 2 comments 0 reactions 0 assignees View on GitHub
Dominant language
TypeScript
Stars
2.8k
Forks
376
PR merge metrics
No merged PRs in 30d

Description

I have a contract named `Provider`. When I generate Typechain with `target=ethers-v6`, `Provider_factory` will unnecessarily import `Provider` from `ethers`. I checked other contracts, but there’s no `Provider` imported.

This is my contract:
```
// SPDX-License-Identifier: UNLICENSED
pragma solidity ^0.8.20;

contract Provider {
uint public someNumber;

event SomethingChanged(uint newNumber);

event Withdrawal(uint amount, uint when);

constructor() {}

function changeSomething(uint newNumber) public {
someNumber = newNumber;
emit SomethingChanged(newNumber);
}
}
```

Import part of `Provider__factory.ts`:
```
/* Autogenerated file. Do not edit manually. */
/* tslint:disable */
/* eslint-disable */
import {
Contract,
ContractFactory,
ContractTransactionResponse,
Interface,
} from "ethers";
import type {
Signer,
ContractDeployTransaction,
Provider,
ContractRunner,
} from "ethers";
import type { NonPayableOverrides } from "../common";
import type { Provider, ProviderInterface } from "../Provider";

const _abi = [
{
inputs: [],
stateMutability: "nonpayable",
type: "constructor",
},
{
anonymous: false,
inputs: [
{
indexed: false,
internalType: "uint256",
name: "newNumber",
type: "uint256",
...
```

I think this is a bug in Typechain. This incorrect import will lead to an error and an ambiguous type for the Provider when used in other scripts. 2 errors in `Provider__factory.ts`
- `Duplicate identifier 'Provider'.`
- `Property 'deploy' in type 'Provider__factory' is not assignable to the same property in base type 'ContractFactory'.
Type '(overrides?: (NonPayableOverrides & { from?: string | undefined; }) | undefined) => Promise' is not assignable to type '(...args: ContractMethodArgs) => Promise>'.
Type 'Promise' is not assignable to type 'Promise>'.
Type 'Provider & { deploymentTransaction(): ContractTransactionResponse; }' is not assignable to type 'BaseContract & { deploymentTransaction(): ContractTransactionResponse; } & Omit'.
Type 'Provider & { deploymentTransaction(): ContractTransactionResponse; }' is missing the following properties from type 'BaseContract': target, interface, runner, filters, and 11 more.`

My environment:
```
"@typechain/ethers-v6": "^0.5.1",
"ethers": "^6.13.2",
"hardhat": "^2.22.8",
```

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.