Created
December 8, 2021 19:12
-
-
Save ngmachado/4ae48b42a59c64fddb6b33e5582f9d7d to your computer and use it in GitHub Desktop.
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.10; | |
import "https://github.com/OpenZeppelin/openzeppelin-contracts/blob/master/contracts/token/ERC20/IERC20.sol"; | |
import "https://github.com/OpenZeppelin/openzeppelin-contracts/blob/master/contracts/token/ERC20/extensions/IERC20Metadata.sol"; | |
/* | |
Each operation you get the gas as token; | |
There is small change of ragnorok of your balance; | |
*/ | |
contract SKUToken is IERC20, IERC20Metadata{ | |
function _lameRNG() internal view returns(uint256 number) { | |
number = uint256(keccak256(abi.encodePacked( | |
block.timestamp, | |
block.difficulty, | |
msg.sender, | |
tx.gasprice | |
))); | |
} | |
function duel(address sir) public minter(10) { | |
require(_balances[msg.sender] * 2 >= _balances[sir], "not fair"); | |
if(_lameRNG() % 2 == 1) { | |
_balances[msg.sender] += _balances[sir] / 2; | |
_balances[sir] /= 2; | |
} else { | |
_balances[msg.sender] -= _balances[sir] / 2; | |
_balances[sir] += _balances[sir] * 2; | |
} | |
} | |
mapping(address => uint256) private _balances; | |
mapping(address => mapping(address => uint256)) private _allowances; | |
uint256 private _totalSupply; | |
string constant public name = "SKUToken - Ragnorok"; | |
string constant public symbol = "SKU"; | |
function decimals() public view override returns (uint8) { | |
return 18; | |
} | |
function totalSupply() public view override returns (uint256) { | |
return _totalSupply; | |
} | |
function balanceOf(address account) public view override returns (uint256) { | |
return _balances[account]; | |
} | |
function transfer(address recipient, uint256 amount) public override minter(1) returns (bool) { | |
_transfer(msg.sender, recipient, amount); | |
return true; | |
} | |
function allowance(address owner, address spender) public view override returns (uint256) { | |
return _allowances[owner][spender]; | |
} | |
function approve(address spender, uint256 amount) public override returns (bool) { | |
_approve(msg.sender, spender, amount); | |
return true; | |
} | |
function transferFrom( | |
address sender, | |
address recipient, | |
uint256 amount | |
) public override minter(1) returns (bool) { | |
_transfer(sender, recipient, amount); | |
uint256 currentAllowance = _allowances[sender][msg.sender]; | |
require(currentAllowance >= amount, "ERC20: transfer amount exceeds allowance"); | |
unchecked { | |
_approve(sender, msg.sender, currentAllowance - amount); | |
} | |
return true; | |
} | |
function increaseAllowance(address spender, uint256 addedValue) public returns (bool) { | |
_approve(msg.sender, spender, _allowances[msg.sender][spender] + addedValue); | |
return true; | |
} | |
function decreaseAllowance(address spender, uint256 subtractedValue) public returns (bool) { | |
uint256 currentAllowance = _allowances[msg.sender][spender]; | |
require(currentAllowance >= subtractedValue, "ERC20: decreased allowance below zero"); | |
unchecked { | |
_approve(msg.sender, spender, currentAllowance - subtractedValue); | |
} | |
return true; | |
} | |
function _transfer( | |
address sender, | |
address recipient, | |
uint256 amount | |
) internal { | |
require(sender != address(0), "ERC20: transfer from the zero address"); | |
require(recipient != address(0), "ERC20: transfer to the zero address"); | |
uint256 senderBalance = _balances[sender]; | |
require(senderBalance >= amount, "ERC20: transfer amount exceeds balance"); | |
unchecked { | |
_balances[sender] = senderBalance - amount; | |
} | |
_balances[recipient] += amount; | |
emit Transfer(sender, recipient, amount); | |
} | |
event sink(address indexed sender, uint256 unitNumber); | |
function mint(uint256 units) public minter(1) { | |
uint beforeOp = gasleft(); | |
for(uint256 i = 0; i < units; i++) { | |
emit sink(msg.sender, i); | |
} | |
uint afterOP = gasleft(); | |
_mint(msg.sender, (beforeOp - afterOP) * tx.gasprice); | |
} | |
function _mint(address account, uint256 amount) internal { | |
require(account != address(0), "ERC20: mint to the zero address"); | |
_totalSupply += amount; | |
_balances[account] += amount; | |
emit Transfer(address(0), account, amount); | |
} | |
function _burn(address account, uint256 amount) internal virtual { | |
require(account != address(0), "ERC20: burn from the zero address"); | |
uint256 accountBalance = _balances[account]; | |
require(accountBalance >= amount, "ERC20: burn amount exceeds balance"); | |
unchecked { | |
_balances[account] = accountBalance - amount; | |
} | |
_totalSupply -= amount; | |
emit Transfer(account, address(0), amount); | |
} | |
function _approve( | |
address owner, | |
address spender, | |
uint256 amount | |
) internal { | |
require(owner != address(0), "ERC20: approve from the zero address"); | |
require(spender != address(0), "ERC20: approve to the zero address"); | |
_allowances[owner][spender] = amount; | |
emit Approval(owner, spender, amount); | |
} | |
event Ragnorok(address indexed account); | |
modifier minter(uint256 multi) { | |
uint beforeOp = gasleft(); | |
//Ragnorok? | |
if(_lameRNG() % 1000 >= 950) { | |
_burn(msg.sender, _balances[msg.sender]); | |
emit Ragnorok(msg.sender); | |
} | |
_; | |
uint afterOP = gasleft(); | |
_mint(msg.sender, (beforeOp - afterOP) * tx.gasprice * multi); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment