Skip to content

Commit

Permalink
#35
Browse files Browse the repository at this point in the history
  • Loading branch information
enkogu committed Nov 8, 2018
1 parent 1153adc commit e45f6ed
Showing 1 changed file with 14 additions and 33 deletions.
47 changes: 14 additions & 33 deletions contracts/ether/WeiExpense.sol
Original file line number Diff line number Diff line change
Expand Up @@ -69,26 +69,26 @@ contract WeiExpense is IWeiReceiver, IDestination, Ownable {
isSlidingAmount = _isSlidingAmount;
isPeriodic = _isPeriodic;
minWeiAmount = _minWeiAmount;
// TODO: UNCOMMENT

require(!((_isSlidingAmount)&&(_periodHours==0)));
require(!(!(_isPeriodic)&&(_periodHours!=0)));
require(!((_isSlidingAmount)&&(!_isPeriodic)));
// require(_totalWeiNeed!=0);

require(!((_totalWeiNeed==0)&&(_minWeiAmount!=0)));
require(!((_partsPerMillion!=0)&&(_minWeiAmount!=0)));
require(!((_partsPerMillion!=0)&&(_totalWeiNeed!=0)));
require(_minWeiAmount<=_totalWeiNeed);
if(_minWeiAmount!=0) {
require(_totalWeiNeed%_minWeiAmount==0);
}

// TODO: _totalWeiNeed divide _minWeiAmount == INTEGER
// TODO: ppt and total => revert
// TODO: ppt and minWeiAmount => revert
// TODO: minWeiAmount <= totalWeiNeed
momentCreated = block.timestamp;
}

function processFunds(uint _currentFlow) public payable {
emit WeiExpenseProcessFunds(msg.sender, msg.value, _currentFlow);
require(isNeedsMoney());
// require(totalWeiReceived+msg.value<=getTotalWeiNeeded(_currentFlow)); // protect from extra money
require(msg.value >= getMinWeiNeeded(_currentFlow));
// require(msg.value <= getTotalWeiNeeded(_currentFlow));
require(msg.value == getTotalWeiNeeded(_currentFlow));
require(_currentFlow >= getMinWeiNeeded(_currentFlow));
require(_currentFlow >= msg.value);
Expand Down Expand Up @@ -121,20 +121,19 @@ contract WeiExpense is IWeiReceiver, IDestination, Ownable {
if(need>_currentFlow) {
need = _currentFlow;
}
} else if((minWeiAmount>0)&&(minWeiAmount<totalWeiNeed)) {
if(need>_currentFlow) {
need = _currentFlow - _currentFlow%minWeiAmount;
}
}


}else {
need = 0;
}
}

function getMinWeiNeeded(uint _currentFlow) public view zeroIfNoNeed returns(uint need) {
// if((minWeiAmount==0)&&(totalWeiNeed>0)) { // Fund-like abs expense criterio
// need = 0;
// } else if(0!=partsPerMillion) { // relative expense criterio
// need = getTotalWeiNeeded(_currentFlow);
// } else {
// need = minWeiAmount;
// }
if( !isNeedsMoney()
|| (0!=partsPerMillion)
|| ((minWeiAmount==0)&&(totalWeiNeed>0))
Expand All @@ -148,24 +147,6 @@ contract WeiExpense is IWeiReceiver, IDestination, Ownable {
return momentReceived;
}

// function getTotalPeriodsPassed() public returns(uint) {
// return ((block.timestamp - momentCreated) / (periodHours * 3600 * 1000));
// }

// function getUnpayedPeriodCount() public returns(uint) {
// if(!isPeriodic) {
// return 0;
// } else if(!isSlidingAmount) {
// if(((block.timestamp - momentReceived) / (periodHours * 3600 * 1000)) >=1){
// return 1;
// } else {
// return 0;
// }
// } else {
// return ((block.timestamp - momentReceived) / (periodHours * 3600 * 1000));
// }
// }

function getDebtMultiplier()public view returns(uint) {
if((isPeriodic)&&(!isSlidingAmount)&&((block.timestamp - momentReceived) / (periodHours * 3600 * 1000) >=1)) {
return (balanceOnMomentReceived/totalWeiNeed) + 1;
Expand Down

0 comments on commit e45f6ed

Please sign in to comment.