Support @custom:override-namespace-id annotation to override namespace ID#189
Open
ernestognw wants to merge 4 commits intomasterfrom
Open
Support @custom:override-namespace-id annotation to override namespace ID#189ernestognw wants to merge 4 commits intomasterfrom
@custom:override-namespace-id annotation to override namespace ID#189ernestognw wants to merge 4 commits intomasterfrom
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
@custom:override-namespace-id <Name>NatSpec annotation on contracts to override the namespace ID used in the ERC-7201 storage struct generation.Motivation
When refactoring contracts (e.g. extracting a base contract from an existing one), the storage variables may move to a new contract with a different name. Without an override, the transpiled upgradeable version would produce a different ERC-7201 namespace (e.g.
openzeppelin.storage.ERC20Vaultinstead of the existingopenzeppelin.storage.ERC4626), breaking storage compatibility for deployed proxies.This annotation allows the source contract to declare the intended namespace identity, preserving backward-compatible storage layouts across such refactors.
Changes
src/utils/natspec.ts: AddextractTranspileNamespace()to extract the@custom:oz-transpile-namespaceannotation from a contract's NatSpec documentation.src/transformations/add-namespace-struct.ts: Use the override (if present) instead ofcontract.namewhen deriving the namespace struct name andopenzeppelin.storage.*ID.src/transformations/transform-constructor.ts: Use the override (if present) when emitting the namespace storage getter in the generated initializer.contracts/namespaces-override.sol: Test fixture with contracts annotated with@custom:oz-transpile-namespace.src/transform-namespaces.test.ts: Snapshot test for the namespace override behavior.