Last active
November 4, 2021 01:44
-
-
Save leolion3/ead3f9159b4da424e1e365e9b9b47d50 to your computer and use it in GitHub Desktop.
Salvation ERC20 Sourcecode
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// SPDX-License-Identifier: MIT | |
pragma solidity ^0.8.9; | |
import 'https://github.com/OpenZeppelin/openzeppelin-contracts/blob/master/contracts/token/ERC20/ERC20.sol'; | |
import 'https://github.com/OpenZeppelin/openzeppelin-contracts/blob/master/contracts/token/ERC20/extensions/ERC20Burnable.sol'; | |
contract Salvation is ERC20, ERC20Burnable { | |
constructor() ERC20('Salvation', 'SLN') { | |
_mint(msg.sender, cap() * 10 ** 2); | |
} | |
/** SLN is capped at 400Bn SLN */ | |
uint256 private immutable _cap = 40 * 10 ** 10; | |
/** SLN only uses 2 decimals after the comma */ | |
function decimals() public view virtual override returns (uint8) { | |
return 2; | |
} | |
/** | |
* Get current coin burn amount | |
*/ | |
function burnAmount() public view virtual returns (uint256) { | |
uint256 currentSupply = ERC20.totalSupply(); | |
// Based on current supply, burn rate is either lower or higher | |
if (currentSupply < 1000) { | |
return 1; | |
} | |
else if (currentSupply < 40 * 10 ** 4) { | |
return 1000; | |
} | |
else if (currentSupply < 40 * 10 ** 6) { | |
return 10000; | |
} | |
else { | |
return 100000; | |
} | |
} | |
/** | |
* @dev Returns the cap on the token's total supply. | |
*/ | |
function cap() public view virtual returns (uint256) { | |
return _cap; | |
} | |
/** | |
* Override to take into account burnt coin during transfers | |
*/ | |
function transfer(address recipient, uint256 amount) public virtual override returns (bool) { | |
uint256 currentBurnAmount = burnAmount(); | |
if (amount <= currentBurnAmount) { | |
return false; | |
} | |
amount -= currentBurnAmount; | |
burn(currentBurnAmount); | |
_transfer(_msgSender(), recipient, amount); | |
return true; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment