Skip to content

ERC20Capped : do not make _cap private #4459

@SvenMeyer

Description

@SvenMeyer

I would like to create a token which has 2% inflation per year, based on ERC20Capped
I would still use the _cap which is initialzed in ERC20Capped but would then override cap()
Surprisingly, i can not access _cap to do the math.

// SPDX-License-Identifier: MIT
pragma solidity ^0.8.9;

// import "@openzeppelin/contracts/token/ERC20/ERC20.sol";
import "@openzeppelin/contracts/token/ERC20/extensions/ERC20Capped.sol";
import "@openzeppelin/contracts/security/Pausable.sol";
import "@openzeppelin/contracts/access/AccessControl.sol";



contract COIN is ERC20Capped, AccessControl {
    bytes32 public constant MINTER_ROLE   = keccak256("MINTER_ROLE");

    uint256 public constant SECONDS_PER_YEAR = 36525 days / 100;
    uint256 public constant INFLATION = 2000; // 2.000 %
    uint256 public immutable DEPLOYMENT_TIME;

    constructor() ERC20("inflationary COIN", "COIN") ERC20Capped(100000000) {
        _grantRole(DEFAULT_ADMIN_ROLE, msg.sender);
        _grantRole(MINTER_ROLE, msg.sender);
        DEPLOYMENT_TIME = block.timestamp;
    }

    /**
     * @dev Returns the cap on the token's total supply
     * @dev ERROR : _cap not accessible here ! - TODO
     */
    function cap() public view override returns (uint256) {
        return _cap + _cap * (block.timestamp - DEPLOYMENT_TIME) * INFLATION / SECONDS_PER_YEAR / 100 / 1000;
    }

    function mint(address to, uint256 amount) public onlyRole(MINTER_ROLE) {
        _mint(to, amount);
    }
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions