ERC20CappedLib
Title: ERC20CappedLib
Authors: David Dada <daveproxy80@gmail.com> (https://github.com/dadadave80), Modified from OpenZeppelin (https://github.com/OpenZeppelin/openzeppelin-contracts/blob/master/contracts/token/ERC20/extensions/ERC20Capped.sol)
Library implementing a capped total supply for ERC-20 tokens.
Ports OpenZeppelin v5.6.1 ERC20Capped. Differences from OpenZeppelin:
- OpenZeppelin checks the cap in
_update, so every mint is capped. Here the cap holds only where a mint path calls _checkCap. The ERC20Capped facet exports onlycap(), and its internal_mintis not reachable through a diamond, so a composing mint facet must call _checkCap itself. A mint throughERC20Lib._mintfrom another facet (ERC7802, ERC20Crosschain, ERC20Wrapper, ERC4626, VaultCore, GovernedVault,ERC20VotesLib._mint, and ERC20FlashMint for the length of a loan) is not capped. Closing this needs a hook in ERC20Lib, which decision D25 on #234 rules out for 0.5.0. - _checkCap runs before the mint with the projected supply; OpenZeppelin checks the supply after it.
Both revert
IERC20Capped.ERC20ExceededCapwith the same arguments. - Registers IERC20Capped for ERC-165 in its init; OpenZeppelin's extension has no ERC-165. See docs/guides/selector-compatibility.md#token-extension-hook-model.
Functions
erc20CappedStorage
function erc20CappedStorage() internal pure returns (ERC20CappedStorage storage $);Returns
| Name | Type | Description |
|---|---|---|
| $ | ERC20CappedStorage |
__ERC20Capped_init
Initializes the ERC-20Capped module with a supply cap.
Must be called inside a pre/postInitializer block. Reverts with ERC20InvalidCap if cap is 0.
function __ERC20Capped_init(uint256 cap_) internal;Parameters
| Name | Type | Description |
|---|---|---|
| cap_ | uint256 |
registerInterface
Registers support for the IERC20Capped interface via ERC-165.
function registerInterface() internal;cap
Returns the cap on the token's total supply.
function cap() internal view returns (uint256);Returns
| Name | Type | Description |
|---|---|---|
| <none> | uint256 |
_checkCap
Reverts if newSupply would exceed the cap.
Call this before minting to enforce the cap constraint.
function _checkCap(uint256 newSupply) internal view;Parameters
| Name | Type | Description |
|---|---|---|
| newSupply | uint256 |