Skip to content

Instantly share code, notes, and snippets.

@ilyar
Forked from k06a/ShardedToken.sol
Created May 17, 2023 13:15
Show Gist options
  • Save ilyar/a3b1348c197db670aa958a3ec026a01b to your computer and use it in GitHub Desktop.
Save ilyar/a3b1348c197db670aa958a3ec026a01b to your computer and use it in GitHub Desktop.
ShardedToken
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