Skip to content

feat: Soften duplicate contract name in the case contracts have identical ABIs #4695

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

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

silasdavis
Copy link

Foundry seems to duplicate some imported sub-files within a contract, for example:

<foundry root>/src/parts/primitives/Foo.sol

Is defined only once, and imported from <foundry root>/src/Bar.sol

But ends up appearing twice in artifacts directory:

<foundry root>/out/Foo.sol/Foo.json
<foundry root>/out/primitives/Foo.sol/Foo.json

In this case getArtifactPaths() in the Foundry plugin pick up the same contracts twice since they end up existing in multiple subdirectories of out/. I don't think there is a reliable to heuristic to de-duplicate them at this level.

It seems like duck-typing contracts by the ABI should be fine and may help other plugin sources. it could always be disabled by default and enabled via an option at the cost of yet more config

…ical ABIs

Foundry seems to duplicate some imported sub-files within a contract,
for example:

`<foundry root>/src/parts/primitives/Foo.sol`

Is defined only once, and imported from `<foundry root>/src/Bar.sol`

But ends up appearing twice in artifacts directory:

```
<foundry root>/out/Foo.sol/Foo.json
<foundry root>/out/primitives/Foo.sol/Foo.json
```

In this case `getArtifactPaths()` in the Foundry plugin pick up the same
contracts twice since they end up existing in multiple subdirectories of `out/`. I
don't think there is a reliable to heuristic to de-duplicate them at
this level.

It seems like duck-typing contracts by the ABI should be fine and may
help other plugin sources. it could always be disabled by default and enabled via an option at the cost of yet more config

Signed-off-by: Silas Davis <[email protected]>
Copy link

changeset-bot bot commented Jun 2, 2025

⚠️ No Changeset found

Latest commit: a5c31d0

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

Copy link

vercel bot commented Jun 2, 2025

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
wagmi ✅ Ready (Inspect) Visit Preview 💬 Add feedback Jun 2, 2025 0:08am

@silasdavis
Copy link
Author

I just want to put this out for a sense check before going to town on the rest of contribution requirements, let me know what you think.

@silasdavis
Copy link
Author

A bit more on why these duplicates might be seen from foundry,

These snippets are are target from two duplicated foundry artifacts.

the first appears under out/:

      "compilationTarget": {
        "src/Foo.sol": "Foo"
      },

the second under out/src/:

      "compilationTarget": {
        "../project/src/Foo.sol": "Foo"
      },

Where we are compiling in the Foundry project project, but we do have some other Foundry projects that import from each other, so it seems to be that the way Foundry processes the Solidity compiler output causes these duplicates, which probably isn't really a bug, so would be nice if wagmi supports this.

@silasdavis
Copy link
Author

silasdavis commented Jun 3, 2025

I've implemented a similar fix in the foundry.ts plugin source itself which I am using as a local vendored patch, let me know if you'd prefer that version.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant