@perfect-abstractions/compose/token/ERC20/Metadata/ERC20MetadataMod.solHelper functions for writing token metadata and accessing metadata storage
setMetadata writes the name, symbol, and decimals in one call.Use helper functions from Compose using your own custom facets. See Facets & Modules for more information.
STORAGE_POSITIONbytes32keccak256("erc20.metadata"))Returns a pointer to the ERC20MetadataStorage struct.
Returns:
sERC20MetadataStorage storageWrites the token name, symbol, and decimals.
All three fields are overwritten on every call. There is no way to update one field and leave the others untouched, so pass the current values for the fields you are not changing, or write through getStorage instead.
There is no msg.sender or role check. Use only from trusted initialization code, or wrap it with your own checks in a facet.
Parameters:
_namestring"My Token"._symbolstring"MTK"._decimalsuint818 is the usual choice.setMetadata once, from your diamond constructor or a one-time setup path, before anyone reads ERC20MetadataFacet._decimals before launch. Changing it later reinterprets every balance already held, since balances are stored as raw integers.STORAGE_POSITION and ERC20MetadataStorage layout as ERC20MetadataFacet. Do not introduce a second metadata slot.Import the module under a namespace and call it from your diamond constructor:
ExampleDiamond wires the ERC-721 equivalent the same way, calling ERC721MetadataMod.setMetadata from its constructor.
ERC20MetadataStorage lives at keccak256("erc20.metadata"), which is a separate slot from the erc20 slot holding balances and allowances. Adding or removing metadata contracts never touches balances.
ERC20PermitFacet reads name from this same slot to build its EIP-712 domain. Changing the name after deployment invalidates permit signatures that have already been issued but not yet used.