@perfect-abstractions/compose/token/ERC20/Mint/ERC20MintMod.solHelper function for creating new ERC-20 tokens
mint creates tokens for any account you name, with no permission check of any kind. Whatever facet calls it is responsible for deciding who may mint. Compose ships no general-purpose mint facet precisely so that this decision stays yours.
mint(_account, _value) increases both balanceOf[_account] and totalSupply.Transfer from address(0), which is the ERC-20 convention for a mint.ERC20Storage with no allowance field. See below.Use helper functions from Compose using your own custom facets. See Facets & Modules for more information.
STORAGE_POSITIONbytes32keccak256("erc20"))This module declares only the two fields it uses. The allowance mapping that other ERC-20 contracts declare is absent.
This is a layout-compatible prefix of the full struct, not a different slot. balanceOf and totalSupply occupy the same positions either way, so this module reads and writes exactly the same storage as the rest of ERC-20. It simply does not declare the field it never touches.
ERC20BurnMod and the two Bridgeable contracts use the same two-field form. Everything that reads or writes an allowance declares all three fields.
Returns a pointer to the ERC20Storage struct.
Because this module's struct has no allowance field, the returned pointer cannot reach allowances. If your facet needs to inspect one, import a module that declares the full struct, such as ERC20TransferMod or ERC20ApproveMod.
Returns:
sERC20Storage storagebalanceOf and totalSupply only.Creates _value new tokens, credits them to _account, and increases the total supply by the same amount.
No permission is checked. Gate this behind your own authorization. Minting 0 is allowed and still emits Transfer.
Parameters:
_accountaddressaddress(0)._valueuint256Reverts:
ERC20InvalidReceivererror_account is address(0).Panic (0x11)arithmetictotalSupply or the recipient's balance. Solidity's checked arithmetic reverts.Emitted on every successful mint, always with address(0) as the source. This is how ERC-20 represents newly created tokens, so indexers reading Transfer see the supply increase without a separate event.
_fromaddressaddress(0)._toaddress_account._valueuint256mint in an external function that checks permission first, for example an owner guard or a role check. Without one, any caller reaching your facet can inflate the supply.mint from your diamond constructor and never expose an external mint path at all.balanceOf and totalSupply in step. If you ever write balances directly, adjust the supply to match, or the unchecked subtractions in ERC20BurnMod can underflow later.STORAGE_POSITION and field order as the other ERC-20 contracts. Do not introduce a second balance mapping.Import the module under a namespace and call it from your facet:
ERC20Storage lives at keccak256("erc20") inside the diamond, the same slot ERC20DataFacet reads, so a mint is immediately visible through balanceOf() and totalSupply().
This module is not the only way supply grows. crosschainMint on ERC20BridgeableFacet also increases totalSupply, gated to holders of the trusted-bridge role. The two differ in one important way: this module uses checked arithmetic, so an overflowing mint reverts, while the bridge performs its additions inside an unchecked block.