Last active
May 17, 2023 13:15
-
-
Save k06a/1c06785f5283fb9a73c3ff1907efef3b to your computer and use it in GitHub Desktop.
ShardedToken
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
contract ShardedToken { | |
using SafeMath for uint256; | |
address owner = msg.sender; | |
uint256 private _totalSupply; | |
mapping(address => ShardedToken.Extension) private extensions; | |
function register() public { | |
extensions[msg.sender] = new Token.Extension(); | |
} | |
function mint(address to, uint256 amount) public { | |
require(msg.sender == owner, "Access denied"); | |
_totalSupply = _totalSupply.add(amount); | |
ShardedToken.Extension(to).receive(address(0), amount); | |
} | |
library Extension { | |
uint256 private _balance; | |
mapping(address => uint256) private _allowance; | |
function balance() public view returns(uint256) { | |
return _balance; | |
} | |
function transfer(address to, uint256 amount) public { | |
_balance = _balance.sub(amount, "Not enough balance"); | |
ShardedToken.Extension(to).receive(this, amount); | |
} | |
function receive(address from, uint256 amount) protected { | |
_balance = _balance.add(amount); | |
} | |
// | |
function allowance(address to) public view returns(uint256) { | |
return _allowance[to]; | |
} | |
function approve(address to, uint256 amount) public { | |
require(_allowance[to] == 0 || amount == 0); | |
_allowance[to] = amount; | |
} | |
function transferFrom(address to, uint256 amount) public { | |
_allowance[msg.sender] = _allowance[msg.sender].sub(amount); | |
transfer(to, amount); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This raw concept ended up to this MVP: https://github.com/k06a/ShardedToken