Skip to content

refactor: consolidate abi generation#658

Merged
spsjvc merged 15 commits intomainfrom
refactor-consolidate-abi-generation
Mar 11, 2026
Merged

refactor: consolidate abi generation#658
spsjvc merged 15 commits intomainfrom
refactor-consolidate-abi-generation

Conversation

@spsjvc
Copy link
Member

@spsjvc spsjvc commented Mar 10, 2026

Summary

Refactors the ABI generation logic out of wagmi.config.ts into a dedicated wagmi.generate.ts file with a custom wagmi plugin, replacing the patched @wagmi/cli etherscan plugin.

Motivation

Previously, wagmi.config.ts contained all ABI fetching, proxy resolution, and contract validation logic inline, and relied on a patch to @wagmi/cli to work around etherscan rate limiting and proxy resolution. This made the file large and hard to follow, as different contract types (factories, precompiles, core contracts) were handled through a mix of conditionals in a single code path.

What changed

  • Removed the @wagmi/cli patch (patches/@wagmi+cli+1.5.2.patch) -- ABI fetching is now handled directly rather than through the patched etherscan plugin.
  • Extracted wagmi.generate.ts -- a custom wagmi plugin with a generate() function that auto-detects the contract type and delegates to the appropriate handler:
    • generateAbiForFactoryContract -- For RollupCreator and TokenBridgeCreator. These are proxies deployed on every parent chain. Resolves each chain's implementation address, fetches the implementation ABI, and asserts all ABIs match across chains.
    • generateAbiForPrecompileContract -- For ArbOwner, ArbGasInfo, etc. These have a fixed address on every Arbitrum chain and are not proxies. Simply fetches the ABI from the reference chain.
    • generateAbiForCoreContract -- For Rollup and SequencerInbox. These are proxies from example deployments. Resolves primary (and optionally secondary) implementation addresses and merges their ABIs. The Rollup contract's dual-proxy pattern (RollupAdminLogic + RollupUserLogic) is handled here.
  • fetchAbi is now a pure block explorer fetch -- proxy-to-implementation resolution is handled explicitly by each code path rather than being buried inside fetchAbi.
  • Simplified wagmi.config.ts -- now only defines the contract list and loops through it, delegating all generation logic to the plugin.
  • Cleaned up generated contract files -- removed blockscout link comments and added as const to address exports.

) {
const chainId = referenceChain.id;

await assertContractAbisMatch({ name, address });
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What about returning the abi from assertContractAbisMatch if they match and remove every else in this function ?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree there's a bit of duplicated work here (fetching ABI for the same contract multiple times), but I wanted to keep assertContractAbisMatch to do just that and nothing else. I'm not too worried about optimizing for number of calls since this is run extremely rarely.

const primaryImplementation = await getImplementation({ client, address });
const primaryAbi: Abi = await fetchAbi(chainId, primaryImplementation);

const secondaryImplementation = await getImplementation({
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If the rollup contract is the only one having a secondary implementation, might be worth to handle it with a special condition and save all the unnecessary calls for other contracts.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Addressed in 6e7b166. I added a check for name !== 'Rollup' in case we ever add other core contracts.

@spsjvc spsjvc requested a review from alxdca March 11, 2026 10:43
@spsjvc spsjvc merged commit f48ee41 into main Mar 11, 2026
10 checks passed
@spsjvc spsjvc deleted the refactor-consolidate-abi-generation branch March 11, 2026 11:37
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.

2 participants