wagmi icon indicating copy to clipboard operation
wagmi copied to clipboard

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

Open silasdavis opened this issue 7 months ago • 5 comments

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

silasdavis avatar Jun 02 '25 12:06 silasdavis

⚠️ No Changeset found

Latest commit: a5c31d07dcf0de34d8d14da031d73468666068ee

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

changeset-bot[bot] avatar Jun 02 '25 12:06 changeset-bot[bot]

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

vercel[bot] avatar Jun 02 '25 12:06 vercel[bot]

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 avatar Jun 02 '25 12:06 silasdavis

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 avatar Jun 03 '25 12:06 silasdavis

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.

silasdavis avatar Jun 03 '25 16:06 silasdavis