erc20-demurrage-token

ERC20 token with redistributed continual demurrage
Log | Files | Refs | README

commit 4c6ee96acca7acf4bf058224b56153979291a83f
parent 64a6bdcabe0137979871bcd8743b084aecb0f230
Author: nolash <dev@holbrook.no>
Date:   Tue,  2 Feb 2021 17:53:35 +0100

Add participants and supply to redistribution

Diffstat:
Mpython/tests/test_basic.py | 4----
Msolidity/RedistributedDemurrageToken.sol | 43++++++++++++++++++++++++++++++++++---------
2 files changed, 34 insertions(+), 13 deletions(-)

diff --git a/python/tests/test_basic.py b/python/tests/test_basic.py @@ -154,8 +154,6 @@ class Test(unittest.TestCase): r = self.w3.eth.getTransactionReceipt(tx_hash); self.assertEqual(r.status, 1); - self.eth_tester.mine_blocks(PERIOD*10) - tx_hash = self.contract.functions.transfer(self.w3.eth.accounts[2], 500).transact({'from': self.w3.eth.accounts[1]}); r = self.w3.eth.getTransactionReceipt(tx_hash); self.assertEqual(r.status, 1); @@ -166,5 +164,3 @@ class Test(unittest.TestCase): if __name__ == '__main__': unittest.main() - - diff --git a/solidity/RedistributedDemurrageToken.sol b/solidity/RedistributedDemurrageToken.sol @@ -15,7 +15,7 @@ contract RedistributedDemurrageToken { uint256 public taxLevel; // PPM uint256 public demurrageModifier; // PPM - bytes32[] redistributions; // uint40(participants) uint160(value) uint56(period) + bytes32[] public redistributions; // uint40(participants) uint160(value) uint56(period) mapping (address => bytes32) account; mapping (address => bool) minter; @@ -33,7 +33,7 @@ contract RedistributedDemurrageToken { symbol = _symbol; decimals = 6; demurrageModifier = 1000000; - bytes32 initialRedistribution = toRedistribution(0, 1, 0); + bytes32 initialRedistribution = toRedistribution(0, 0, 1); redistributions.push(initialRedistribution); } @@ -71,16 +71,19 @@ contract RedistributedDemurrageToken { function mintTo(address _beneficiary, uint256 _amount) external returns (bool) { require(minter[msg.sender]); + totalSupply += _amount; increaseBalance(_beneficiary, _amount); emit Mint(msg.sender, _beneficiary, _amount); + saveRedistributionSupply(); return true; } function toRedistribution(uint256 _participants, uint256 _value, uint256 _period) private pure returns(bytes32) { bytes32 redistribution; - redistribution |= bytes32((_participants & 0xffffffffff) << 215); - redistribution |= bytes32((_value & 0xffffffffffffffffffffffff) << 55); - redistribution |= bytes32((_period & 0xffffffffffffff) << 55); + + redistribution |= bytes32((_participants & 0xffffffffff) << 216); + redistribution |= bytes32((_value & 0xffffffffffffffffffffffff) << 56); + redistribution |= bytes32(_period & 0xffffffffffffff); return redistribution; } @@ -92,6 +95,28 @@ contract RedistributedDemurrageToken { return redistributions.length; } + function incrementRedistributionParticipants() private returns (bool) { + uint256 currentRedistribution; + uint256 participants; + + currentRedistribution = uint256(redistributions[redistributions.length-1]); + participants = ((currentRedistribution & 0xffffffffff000000000000000000000000000000000000000000000000000000) >> 216) + 1; + currentRedistribution &= 0x0000000000ffffffffffffffffffffffffffffffffffffffffffffffffffffff; + currentRedistribution |= participants << 216; + + redistributions[redistributions.length-1] = bytes32(currentRedistribution); + } + + function saveRedistributionSupply() private returns (bool) { + uint256 currentRedistribution; + + currentRedistribution = uint256(redistributions[redistributions.length-1]); + currentRedistribution &= 0xffffffffff0000000000000000000000000000000000000000ffffffffffffff; + currentRedistribution |= totalSupply << 56; //& 0x0000000000ffffffffffffffffffffffffffffffffffffffff00000000000000;; + + redistributions[redistributions.length-1] = bytes32(currentRedistribution); + } + function actualPeriod() public view returns (uint256) { return (block.number - periodStart) / periodDuration; } @@ -115,7 +140,6 @@ contract RedistributedDemurrageToken { return demurrageModifier; } demurrageModifier -= (demurrageModifier * taxLevel) / 1000000; - // this should increment for one single period at at time currentPeriod = toRedistributionPeriod(pendingRedistribution); nextRedistribution = toRedistribution(0, currentPeriod + 1, 0); redistributions.push(nextRedistribution); @@ -126,9 +150,10 @@ contract RedistributedDemurrageToken { return (uint256(account[_account]) & 0xffffffffffffffffffffffff0000000000000000000000000000000000000000) >> 160; } - function saveAccountPeriod(address _account, uint256 _period) private returns (bool) { + function registerAccountPeriod(address _account, uint256 _period) private returns (bool) { account[_account] &= 0x000000000000000000000000ffffffffffffffffffffffffffffffffffffffff; - account[_account] |= bytes32(_period << 160); + account[_account] |= bytes32(_period << 160); + incrementRedistributionParticipants(); } function transfer(address _to, uint256 _value) public returns (bool) { @@ -153,7 +178,7 @@ contract RedistributedDemurrageToken { } period = actualPeriod(); if (accountPeriod(_from) != period) { - saveAccountPeriod(_from, period); + registerAccountPeriod(_from, period); } return true; }