...by Daniel Szego
"Simplicity is the ultimate sophistication."
Leonardo da Vinci

Tuesday, January 9, 2018

Minimal ERC20 token with adjustable monetary policy

As we have seen in the previous blog (Ethereum token with adjustable monetary policy), there might be a good idea to design a token with adjustable monetary supply, in a way that there is actually at least two token balances an M0 basic monetary supply and an M1 that is a dynamic multiplication of the basic monetary supply. The following code demonstrates a minimal implementation of such a token. For the first run as a simple sketch, without having some necessary elements for a live system, like Transfer event, safe match functions or token information fields 

contract SimpleMonetaryToken {

 mapping(address => uint256) m0Balances;
 uint256 public monetaryMultiplicator = 110;

 uint initialSupply = 10000;

 function SimpleMonetaryToken(){
  m0Balances[msg.sender] = initialSupply;

 function transfer(address _to, uint256 _m1Value) public returns
      (bool) {
  uint256 _m0Value = (_m1Value * 100) / monetaryMultiplicator;
  require(_to != address(0));
  require(_m0Value <= m0Balances[msg.sender]);

  m0Balances[msg.sender] = m0Balances[msg.sender] - _m0Value;
  m0Balances[_to] = m0Balances[_to] + _m0Value;
  return true;

 function balanceOf(address _owner) public view returns (uint256
  balance) {
   return (m0Balances[_owner] * monetaryMultiplicator) / 100;

Certainly, the structure should be further tested regarding the possible hackings or attacks. As an example division represents actually a rounding, so it might produces some inconsistencies or possible hackings. On the other hand, due to multiplications with 100, the overflow can be a critical issue.