Add participants and supply to redistribution

This commit is contained in:
nolash 2021-02-02 17:53:35 +01:00
parent 64a6bdcabe
commit 4c6ee96acc
Signed by: lash
GPG Key ID: 21D2E7BB88C2A746
2 changed files with 34 additions and 13 deletions

View File

@ -154,8 +154,6 @@ class Test(unittest.TestCase):
r = self.w3.eth.getTransactionReceipt(tx_hash); r = self.w3.eth.getTransactionReceipt(tx_hash);
self.assertEqual(r.status, 1); 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]}); 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); r = self.w3.eth.getTransactionReceipt(tx_hash);
self.assertEqual(r.status, 1); self.assertEqual(r.status, 1);
@ -166,5 +164,3 @@ class Test(unittest.TestCase):
if __name__ == '__main__': if __name__ == '__main__':
unittest.main() unittest.main()

View File

@ -15,7 +15,7 @@ contract RedistributedDemurrageToken {
uint256 public taxLevel; // PPM uint256 public taxLevel; // PPM
uint256 public demurrageModifier; // 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 => bytes32) account;
mapping (address => bool) minter; mapping (address => bool) minter;
@ -33,7 +33,7 @@ contract RedistributedDemurrageToken {
symbol = _symbol; symbol = _symbol;
decimals = 6; decimals = 6;
demurrageModifier = 1000000; demurrageModifier = 1000000;
bytes32 initialRedistribution = toRedistribution(0, 1, 0); bytes32 initialRedistribution = toRedistribution(0, 0, 1);
redistributions.push(initialRedistribution); redistributions.push(initialRedistribution);
} }
@ -71,16 +71,19 @@ contract RedistributedDemurrageToken {
function mintTo(address _beneficiary, uint256 _amount) external returns (bool) { function mintTo(address _beneficiary, uint256 _amount) external returns (bool) {
require(minter[msg.sender]); require(minter[msg.sender]);
totalSupply += _amount;
increaseBalance(_beneficiary, _amount); increaseBalance(_beneficiary, _amount);
emit Mint(msg.sender, _beneficiary, _amount); emit Mint(msg.sender, _beneficiary, _amount);
saveRedistributionSupply();
return true; return true;
} }
function toRedistribution(uint256 _participants, uint256 _value, uint256 _period) private pure returns(bytes32) { function toRedistribution(uint256 _participants, uint256 _value, uint256 _period) private pure returns(bytes32) {
bytes32 redistribution; bytes32 redistribution;
redistribution |= bytes32((_participants & 0xffffffffff) << 215);
redistribution |= bytes32((_value & 0xffffffffffffffffffffffff) << 55); redistribution |= bytes32((_participants & 0xffffffffff) << 216);
redistribution |= bytes32((_period & 0xffffffffffffff) << 55); redistribution |= bytes32((_value & 0xffffffffffffffffffffffff) << 56);
redistribution |= bytes32(_period & 0xffffffffffffff);
return redistribution; return redistribution;
} }
@ -92,6 +95,28 @@ contract RedistributedDemurrageToken {
return redistributions.length; 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) { function actualPeriod() public view returns (uint256) {
return (block.number - periodStart) / periodDuration; return (block.number - periodStart) / periodDuration;
} }
@ -115,7 +140,6 @@ contract RedistributedDemurrageToken {
return demurrageModifier; return demurrageModifier;
} }
demurrageModifier -= (demurrageModifier * taxLevel) / 1000000; demurrageModifier -= (demurrageModifier * taxLevel) / 1000000;
// this should increment for one single period at at time
currentPeriod = toRedistributionPeriod(pendingRedistribution); currentPeriod = toRedistributionPeriod(pendingRedistribution);
nextRedistribution = toRedistribution(0, currentPeriod + 1, 0); nextRedistribution = toRedistribution(0, currentPeriod + 1, 0);
redistributions.push(nextRedistribution); redistributions.push(nextRedistribution);
@ -126,9 +150,10 @@ contract RedistributedDemurrageToken {
return (uint256(account[_account]) & 0xffffffffffffffffffffffff0000000000000000000000000000000000000000) >> 160; 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] &= 0x000000000000000000000000ffffffffffffffffffffffffffffffffffffffff;
account[_account] |= bytes32(_period << 160); account[_account] |= bytes32(_period << 160);
incrementRedistributionParticipants();
} }
function transfer(address _to, uint256 _value) public returns (bool) { function transfer(address _to, uint256 _value) public returns (bool) {
@ -153,7 +178,7 @@ contract RedistributedDemurrageToken {
} }
period = actualPeriod(); period = actualPeriod();
if (accountPeriod(_from) != period) { if (accountPeriod(_from) != period) {
saveAccountPeriod(_from, period); registerAccountPeriod(_from, period);
} }
return true; return true;
} }