From 686f2c3205a8aa14f8b8eddbd7b1e7dfe3326652 Mon Sep 17 00:00:00 2001 From: enkogu Date: Mon, 1 Oct 2018 22:53:37 +0700 Subject: [PATCH] #341: ppm --- contracts/moneyflow/IReceiver.sol | 2 +- contracts/moneyflow/MoneflowTable.sol | 22 +++++++-------- contracts/moneyflow/Moneyflow.sol | 2 +- contracts/moneyflow/ether/WeiExpense.sol | 28 +++++++++---------- contracts/moneyflow/ether/WeiFund.sol | 2 +- .../moneyflow/ether/WeiRelativeExpense.sol | 4 +-- .../ether/WeiRelativeExpenseWithPeriod.sol | 4 +-- .../moneyflow/ether/WeiTopDownSplitter.sol | 12 ++++---- .../moneyflow/ether/WeiUnsortedSplitter.sol | 18 ++++++------ package-lock.json | 2 +- 10 files changed, 48 insertions(+), 48 deletions(-) diff --git a/contracts/moneyflow/IReceiver.sol b/contracts/moneyflow/IReceiver.sol index 1746690..9fae9be 100644 --- a/contracts/moneyflow/IReceiver.sol +++ b/contracts/moneyflow/IReceiver.sol @@ -10,7 +10,7 @@ contract IReceiver { // in 1/100th percents of input. Examples: // 12 is 0.12% of input; // 100 is 1% of input - function getPercentsMul100() public view returns(uint); + function getPpm() public view returns(uint); // If this output needs more funds -> will return true // If this output does not need more funds -> will return false diff --git a/contracts/moneyflow/MoneflowTable.sol b/contracts/moneyflow/MoneflowTable.sol index f5af7af..a62fb10 100644 --- a/contracts/moneyflow/MoneflowTable.sol +++ b/contracts/moneyflow/MoneflowTable.sol @@ -26,7 +26,7 @@ contract MoneyflowTable is Ownable {//is IWeiReceiver, struct Expense { uint neededAmount; - uint neededPercentsMul100; + uint neededPpm; uint periodHours; @@ -47,9 +47,9 @@ contract MoneyflowTable is Ownable {//is IWeiReceiver, // -------------------- INTERNAL IWEIRECEIVER FUNCTIONS -------------------- for elements - function _getPercentsMul100(uint _eId) internal view returns(uint) { + function _getPpm(uint _eId) internal view returns(uint) { if(ElementTypes.RelativeExpense == elementsType[_eId]) { - return expenses[_eId].neededPercentsMul100; + return expenses[_eId].neededPpm; }else { return 0; } @@ -139,20 +139,20 @@ contract MoneyflowTable is Ownable {//is IWeiReceiver, function _getMinWeiNeededUnsortedSplitter(uint _eId) internal view returns(uint) { uint absSum = 0; - uint percentsMul100ReverseSum = 10000; + uint ppmReverseSum = 1000000; for(uint i=0; i0; --j) { if(ElementTypes.RelativeExpense == elementsType[splitters[_eId].outputs[j-1]]) { - out = 10000 * out / expenses[splitters[_eId].outputs[j-1]].neededPercentsMul100; + out = 1000000 * out / expenses[splitters[_eId].outputs[j-1]].neededPpm; }else { out += _getMinWeiNeeded(splitters[_eId].outputs[j-1]); } @@ -221,7 +221,7 @@ contract MoneyflowTable is Ownable {//is IWeiReceiver, } if(ElementTypes.RelativeExpense==elementsType[_eId]) { - return (_getDebtMultiplier(_eId)*(expenses[_eId].neededPercentsMul100 * _currentFlow)) / 10000; + return (_getDebtMultiplier(_eId)*(expenses[_eId].neededPpm * _currentFlow)) / 1000000; }else { return _getMinWeiNeeded(_eId); } @@ -265,9 +265,9 @@ contract MoneyflowTable is Ownable {//is IWeiReceiver, elementsCount += 1; } - function addRelativeExpense(uint _neededPercentsMul100, bool _isPeriodic, bool _isAccumulateDebt, uint _periodHours, IWeiReceiver _output)external onlyOwner { + function addRelativeExpense(uint _neededPpm, bool _isPeriodic, bool _isAccumulateDebt, uint _periodHours, IWeiReceiver _output)external onlyOwner { expenses[elementsCount] = Expense( - 0, _neededPercentsMul100, + 0, _neededPpm, _periodHours, _isPeriodic, _isAccumulateDebt, _output, 0, false, true, 0 ); diff --git a/contracts/moneyflow/Moneyflow.sol b/contracts/moneyflow/Moneyflow.sol index 83cfa94..c055ee9 100644 --- a/contracts/moneyflow/Moneyflow.sol +++ b/contracts/moneyflow/Moneyflow.sol @@ -40,7 +40,7 @@ contract MoneyFlow is IMoneyflow, DaoClient, Ownable { DaoClient(_daoBase) { // do not set output! - donationEndpoint = new WeiRelativeExpenseWithPeriod(10000, 0, false); + donationEndpoint = new WeiRelativeExpenseWithPeriod(1000000, 0, false); donationF2WR = new FallbackToWeiReceiver(donationEndpoint); } diff --git a/contracts/moneyflow/ether/WeiExpense.sol b/contracts/moneyflow/ether/WeiExpense.sol index c096ad9..47d5bb1 100644 --- a/contracts/moneyflow/ether/WeiExpense.sol +++ b/contracts/moneyflow/ether/WeiExpense.sol @@ -16,7 +16,7 @@ contract WeiExpense is IWeiReceiver, IDestination, Ownable { bool isMoneyReceived = false; bool isAccumulateDebt = false; bool isPeriodic = false; - uint percentsMul100 = 0; + uint ppm = 0; uint periodHours = 0; uint momentReceived = 0; uint neededWei = 0; @@ -24,19 +24,19 @@ contract WeiExpense is IWeiReceiver, IDestination, Ownable { event WeiExpenseFlush(address _owner, uint _balance); event WeiExpenseSetNeededWei(uint _neededWei); - event WeiExpenseSetPercents(uint _percentsMul100); + event WeiExpenseSetPercents(uint _ppm); event WeiExpenseProcessFunds(address _sender, uint _value, uint _currentFlow); /** * @dev Constructor - * @param _neededWei - absolute value. how much Ether this expense should receive (in Wei). Can be zero (use _percentsMul100 in this case) - * @param _percentsMul100 - if need to get % out of the input flow -> specify this parameter (1% is 100 units) + * @param _neededWei - absolute value. how much Ether this expense should receive (in Wei). Can be zero (use _ppm in this case) + * @param _ppm - if need to get % out of the input flow -> specify this parameter (1% is 10000 units) * @param _periodHours - if not isPeriodic and periodHours>0 ->no sense. if isPeriodic and periodHours==0 -> needs money everytime. if isPeriodic and periodHours>0 -> needs money every period. * @param _isAccumulateDebt - if you don't pay in the current period -> will accumulate the needed amount (only for _neededWei!) * @param _isPeriodic - if isPeriodic and periodHours>0 -> needs money every period. if isPeriodic and periodHours==0 -> needs money everytime. */ - constructor(uint _neededWei, uint _percentsMul100, uint _periodHours, bool _isAccumulateDebt, bool _isPeriodic) public { - percentsMul100 = _percentsMul100; + constructor(uint _neededWei, uint _ppm, uint _periodHours, bool _isAccumulateDebt, bool _isPeriodic) public { + ppm = _ppm; periodHours = _periodHours; neededWei = _neededWei; isAccumulateDebt = _isAccumulateDebt; @@ -71,15 +71,15 @@ contract WeiExpense is IWeiReceiver, IDestination, Ownable { return 0; } - if(0!=percentsMul100) { - return (getDebtMultiplier()*(percentsMul100 * _inputWei)) / 10000; + if(0!=ppm) { + return (getDebtMultiplier()*(ppm * _inputWei)) / 1000000; }else { return getMinWeiNeeded(); } } function getMinWeiNeeded()public view returns(uint) { - if(!isNeedsMoney() || (0!=percentsMul100)) { + if(!isNeedsMoney() || (0!=ppm)) { return 0; } return getDebtMultiplier()*neededWei; @@ -112,8 +112,8 @@ contract WeiExpense is IWeiReceiver, IDestination, Ownable { _; } - function getPercentsMul100()public view returns(uint) { - return percentsMul100; + function getPpm()public view returns(uint) { + return ppm; } function flush()public onlyOwner { @@ -131,9 +131,9 @@ contract WeiExpense is IWeiReceiver, IDestination, Ownable { neededWei = _neededWei; } - function setPercents(uint _percentsMul100) public onlyOwner { - emit WeiExpenseSetPercents(_percentsMul100); - percentsMul100 = _percentsMul100; + function setPercents(uint _ppm) public onlyOwner { + emit WeiExpenseSetPercents(_ppm); + ppm = _ppm; } function()public { diff --git a/contracts/moneyflow/ether/WeiFund.sol b/contracts/moneyflow/ether/WeiFund.sol index 0f9b9ff..9681bcb 100644 --- a/contracts/moneyflow/ether/WeiFund.sol +++ b/contracts/moneyflow/ether/WeiFund.sol @@ -89,7 +89,7 @@ contract WeiFund is IWeiReceiver, IDestination, Ownable {// return 0; } - function getPercentsMul100() view public returns(uint) { + function getPpm() view public returns(uint) { return 0; } diff --git a/contracts/moneyflow/ether/WeiRelativeExpense.sol b/contracts/moneyflow/ether/WeiRelativeExpense.sol index bfd30e0..9f5be07 100644 --- a/contracts/moneyflow/ether/WeiRelativeExpense.sol +++ b/contracts/moneyflow/ether/WeiRelativeExpense.sol @@ -4,7 +4,7 @@ import "./WeiExpense.sol"; contract WeiRelativeExpense is WeiExpense { - constructor(uint _percentsMul100)public - WeiExpense(0, _percentsMul100, 0, false, false) + constructor(uint _ppm)public + WeiExpense(0, _ppm, 0, false, false) {} } \ No newline at end of file diff --git a/contracts/moneyflow/ether/WeiRelativeExpenseWithPeriod.sol b/contracts/moneyflow/ether/WeiRelativeExpenseWithPeriod.sol index e6a8235..d335a52 100644 --- a/contracts/moneyflow/ether/WeiRelativeExpenseWithPeriod.sol +++ b/contracts/moneyflow/ether/WeiRelativeExpenseWithPeriod.sol @@ -4,7 +4,7 @@ import "./WeiExpense.sol"; contract WeiRelativeExpenseWithPeriod is WeiExpense { - constructor(uint _percentsMul100, uint _periodHours, bool _isAccumulateDebt) public - WeiExpense(0, _percentsMul100, _periodHours, _isAccumulateDebt, true) + constructor(uint _ppm, uint _periodHours, bool _isAccumulateDebt) public + WeiExpense(0, _ppm, _periodHours, _isAccumulateDebt, true) {} } diff --git a/contracts/moneyflow/ether/WeiTopDownSplitter.sol b/contracts/moneyflow/ether/WeiTopDownSplitter.sol index c65e133..08ddbfc 100644 --- a/contracts/moneyflow/ether/WeiTopDownSplitter.sol +++ b/contracts/moneyflow/ether/WeiTopDownSplitter.sol @@ -22,8 +22,8 @@ contract WeiTopDownSplitter is SplitterBase, IWeiReceiver { uint out = 0; for(uint j=childrenCount; j>0; --j) { IWeiReceiver c = IWeiReceiver(children[j-1]); - if(c.getPercentsMul100()>0) { - out = 10000 * out / c.getPercentsMul100(); + if(c.getPpm()>0) { + out = 1000000 * out / c.getPpm(); }else { out += c.getMinWeiNeeded(); } @@ -53,16 +53,16 @@ contract WeiTopDownSplitter is SplitterBase, IWeiReceiver { return total; } - function getPercentsMul100()public view returns(uint) { + function getPpm()public view returns(uint) { uint total = 0; for(uint i=0; i10000) { - return 10000; + if(total>1000000) { + return 1000000; } return total; } diff --git a/contracts/moneyflow/ether/WeiUnsortedSplitter.sol b/contracts/moneyflow/ether/WeiUnsortedSplitter.sol index a50abf1..2db5671 100644 --- a/contracts/moneyflow/ether/WeiUnsortedSplitter.sol +++ b/contracts/moneyflow/ether/WeiUnsortedSplitter.sol @@ -21,20 +21,20 @@ contract WeiUnsortedSplitter is SplitterBase, IWeiReceiver { } uint absSum = 0; - uint percentsMul100ReverseSum = 10000; + uint ppmReverseSum = 1000000; for(uint i=0; i10000) { - return 10000; + if(total>1000000) { + return 1000000; } return total; } diff --git a/package-lock.json b/package-lock.json index 81b26e0..3b439ed 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,6 +1,6 @@ { "name": "@thetta/core", - "version": "1.4.0", + "version": "1.4.1", "lockfileVersion": 1, "requires": true, "dependencies": {