Hey @mudgen,
Though originally created for proxy contracts, diamond storage can be used to organize storage and data access within any smart contract.
Indeed, you are right, it can be used in any contract. I went through the EIP again, and it reads very well!
On another note, from my experience implementing ERC2535 Diamonds with many facets and their own diamond storage, I faced some challenges in deciding on the proper string format and versioning for the facet storage. It can easily become hard to manage and error-prone, increasing the risk of collision.
While the ERC8042 defines that it should use ASCII-enforced, human-readable, meaningful strings, it doesnât provide a concrete naming scheme.
Maybe this is a good opportunity to have a concrete naming scheme, inspired by existing software engineering practices, for example:
- Reverse-DNS provides global uniqueness:
org.example
- Protocol gives the name of the specific project or protocol:
exchange
- Module is the logical sub-component or contract name for the storage:
orderbook
- Major version as a suffix inspired by SemVer:
v2
Examples:
org.example.exchange.orderbook.v2
com.acme.nft.registry.v2
io.foo.access.roles.v1
etc.
To prevent storage slot churn, you would only bump the major version when you need a completely new storage slot, reorder fields, change field type/size, etc. Otherwise, simply add fields at the end of the struct, as usual.
If you still want to keep minor/patch versioning, you can do it through NatSpec.
Dots read well and mirror what EIPs already use. This could help avoid collisions in large contract systems that use diamond storage heavily, as it introduces a guide on the naming scheme.
What do you think?