Skip to content

Instantly share code, notes, and snippets.

@himawari2021
Created February 13, 2022 08:41
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save himawari2021/69bb8be6aca52a376b71131b8620fb80 to your computer and use it in GitHub Desktop.
Save himawari2021/69bb8be6aca52a376b71131b8620fb80 to your computer and use it in GitHub Desktop.
Inflation Token example
// SPDX-License-Identifier: GPL-3.0
pragma solidity >=0.7.0 <0.9.0;
import "https://github.com/OpenZeppelin/openzeppelin-contracts/blob/master/contracts/token/ERC20/ERC20.sol";
//the token amount is twice whenever minted. if the mint_count is over 256, token amount is reseted.
contract MyToken4 is ERC20 {
uint public mint_count = 0;
constructor() ERC20("Super Inflation Token", "SIT") {
_mint(msg.sender, 1);
}
//free mint for everyone!
function requestToken(uint amount) public {
amount = amount * (10 ** decimals());
_mint(msg.sender, _removeRate(amount));
mint_count = mint_count + 1;
}
//change amount by mint_count
function _applyRate(uint amount) internal view returns(uint) {
return amount * (2 ** (mint_count%256));
}
function _removeRate(uint amount) internal view returns(uint) {
return amount / (2 ** (mint_count%256));
}
function balanceOf(address account) public view virtual override returns (uint256) {
return _applyRate(super.balanceOf(account));
}
function totalSupply() public view virtual override returns (uint256) {
return _applyRate(super.totalSupply());
}
function _transfer(
address from,
address to,
uint256 amount
) internal virtual override {
super._transfer(from, to, _removeRate(amount));
}
//no _applyRate for approve
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment