Skip to content

Commit

Permalink
#52
Browse files Browse the repository at this point in the history
  • Loading branch information
enkogu committed Dec 27, 2018
1 parent a108d47 commit 2fdee24
Show file tree
Hide file tree
Showing 38 changed files with 2,164 additions and 105 deletions.
8 changes: 4 additions & 4 deletions contracts/FallbackToWeiReceiver.sol
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
pragma solidity ^0.4.23;
pragma solidity ^0.4.24;

import "./interfaces/IReceiver.sol";
import "./interfaces/IWeiReceiver.sol";


/**
Expand All @@ -16,8 +16,8 @@ contract FallbackToWeiReceiver {
output = _output;
}

function()public payable {
IReceiver iwr = IReceiver(output);
function() public payable {
IWeiReceiver iwr = IWeiReceiver(output);
iwr.processFunds.value(msg.value)(msg.value);
}
}
49 changes: 13 additions & 36 deletions contracts/bases/ExpenseBase.sol
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
pragma solidity ^0.4.24;

pragma experimental ABIEncoderV2;
import "../libs/ExpenseLib.sol";

import "../interfaces/IDestination.sol";
Expand All @@ -14,7 +14,7 @@ import "zeppelin-solidity/contracts/ownership/Ownable.sol";
* @dev Something that needs money (task, salary, bonus, etc)
* Should be used in the Moneyflow so will automatically receive Wei.
*/
contract ExpenseBase is ExpenseLib, IReceiver, IDestination, Ownable {
contract ExpenseBase is ExpenseLib, IReceiver, Ownable {
Expense public expense;

function getReceiverType() public view returns(Type) {
Expand All @@ -25,51 +25,29 @@ contract ExpenseBase is ExpenseLib, IReceiver, IDestination, Ownable {
}
}

function processFunds(uint _currentFlow) public payable {
emit ExpenseProcessFunds(msg.sender, msg.value, _currentFlow);
expense = _processFunds(expense, _currentFlow, msg.value);
}

function getIsMoneyReceived() public view returns(bool) {
return expense.totalReceived > 0;
function getExpenseParams() public view returns(uint128 totalNeeded, uint128 minAmount, uint32 partsPerMillion, uint32 periodHours, uint32 momentReceived, uint128 balance, uint128 totalReceived, uint32 momentCreated) {
totalNeeded = expense.totalNeeded;
minAmount = expense.minAmount;
partsPerMillion = expense.partsPerMillion;
periodHours = expense.periodHours;
momentReceived = expense.momentReceived;
balance = expense.balance;
totalReceived = expense.totalReceived;
momentCreated = expense.momentCreated;
}

function getNeededWei() public view returns(uint) {
return expense.totalNeeded;
}

function getTotalNeeded(uint _currentFlow)public view returns(uint) {
function getTotalNeeded(uint _currentFlow) public view returns(uint) {
return _getTotalNeeded(expense, _currentFlow);
}

function getMinNeeded(uint _currentFlow) public view returns(uint) {
return _getMinNeeded(expense, _currentFlow);
}

function getMomentReceived()public view returns(uint) {
return expense.momentReceived;
}

function isNeeds()public view returns(bool) {
function isNeeds() public view returns(bool) {
return _isNeeds(expense);
}

function getPartsPerMillion()public view returns(uint) {
return expense.partsPerMillion;
}

function flush()public onlyOwner {
emit ExpenseFlush(owner, address(this).balance);
owner.transfer(address(this).balance);
expense.balance = 0;
}

function flushTo(address _to) public onlyOwner {
emit ExpenseFlush(_to, address(this).balance);
_to.transfer(address(this).balance);
expense.balance = 0;
}

function setNeededWei(uint _totalNeeded) public onlyOwner {
emit ExpenseSetNeeded(_totalNeeded);
expense.totalNeeded = uint128(_totalNeeded);
Expand All @@ -81,5 +59,4 @@ contract ExpenseBase is ExpenseLib, IReceiver, IDestination, Ownable {
}

function() public {}

}
6 changes: 1 addition & 5 deletions contracts/bases/SplitterBase.sol
Original file line number Diff line number Diff line change
Expand Up @@ -21,18 +21,14 @@ contract SplitterBase is SplitterLib, IReceiver, ISplitter, Ownable {
return _getMinNeeded(splitter, _currentFlow);
}

function getTotalNeeded(uint _currentFlow)public view returns(uint) {
function getTotalNeeded(uint _currentFlow) public view returns(uint) {
return _getTotalNeeded(splitter, _currentFlow);
}

function isNeeds() public view returns(bool) {
return _isNeeds(splitter);
}

function processFunds(uint _currentFlow) public payable {
_processFunds(splitter, _currentFlow, msg.value);
}

function open() public onlyOwner {
_open(splitter);
}
Expand Down
18 changes: 10 additions & 8 deletions contracts/bases/TableBase.sol
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
pragma solidity ^0.4.23;
pragma solidity ^0.4.24;

import "zeppelin-solidity/contracts/ownership/Ownable.sol";
import "../interfaces/IReceiver.sol";
Expand Down Expand Up @@ -45,15 +45,11 @@ contract TableBase is ExpenseLib, SplitterLib, Ownable {
return getPartsPerMillionAt(0);
}

function processFunds(uint _currentFlow) public payable {
return _processFundsAt(0, _currentFlow, msg.value);
}

function _processFundsAt(uint _eId, uint _currentFlow, uint _value) internal {
function _processAmountAt(uint _eId, uint _currentFlow, uint _value) internal {
if(isExpenseAt(_eId)) {
expenses[_eId] = _processFunds(expenses[_eId], _currentFlow, _value);
expenses[_eId] = _processAmount(expenses[_eId], _currentFlow, _value);
}else {
_processFunds(splitters[_eId], _currentFlow, _value);
_processAmount(splitters[_eId], _currentFlow, _value);
}
}

Expand Down Expand Up @@ -201,4 +197,10 @@ contract TableBase is ExpenseLib, SplitterLib, Ownable {
require(splitters[_eId].outputs.length > _index);
return splitters[_eId].outputs[_index];
}

function _tableProcessing(address _target, uint _eId, uint _flow, uint _need) internal {
_processAmountAt(_eId, _flow, _need);
}

function() public {}
}
10 changes: 10 additions & 0 deletions contracts/erc20/ERC20AbsoluteExpense.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
pragma solidity ^0.4.24;

import "./ERC20Expense.sol";


contract ERC20AbsoluteExpense is ERC20Expense {
constructor(address _tokenAddress, uint _minERC20Amount, uint _totalERC20Need) public
ERC20Expense(_tokenAddress, _minERC20Amount, _totalERC20Need, 0, 0, false, false)
{}
}
10 changes: 10 additions & 0 deletions contracts/erc20/ERC20AbsoluteExpenseWithPeriod.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
pragma solidity ^0.4.24;

import "./ERC20Expense.sol";


contract ERC20AbsoluteExpenseWithPeriod is ERC20Expense {
constructor(address _tokenAddress, uint _minERC20Amount, uint _totalERC20Need, uint _periodHours) public
ERC20Expense(_tokenAddress, _minERC20Amount, _totalERC20Need, 0, _periodHours, false, true)
{}
}
10 changes: 10 additions & 0 deletions contracts/erc20/ERC20AbsoluteExpenseWithPeriodSliding.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
pragma solidity ^0.4.24;

import "./ERC20Expense.sol";


contract ERC20AbsoluteExpenseWithPeriodSliding is ERC20Expense {
constructor(address _tokenAddress, uint _minERC20Amount, uint _totalERC20Need, uint _periodHours) public
ERC20Expense(_tokenAddress, _minERC20Amount, _totalERC20Need, 0, _periodHours, true, true)
{}
}
10 changes: 10 additions & 0 deletions contracts/erc20/ERC20RelativeExpense.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
pragma solidity ^0.4.24;

import "./ERC20Expense.sol";


contract ERC20RelativeExpense is ERC20Expense {
constructor(address _tokenAddress, uint _partsPerMillion) public
ERC20Expense(_tokenAddress, 0, 0, _partsPerMillion, 0, false, false)
{}
}
10 changes: 10 additions & 0 deletions contracts/erc20/ERC20RelativeExpenseWithPeriod.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
pragma solidity ^0.4.24;

import "./ERC20Expense.sol";


contract ERC20RelativeExpenseWithPeriod is ERC20Expense {
constructor(address _tokenAddress, uint _partsPerMillion, uint _periodHours) public
ERC20Expense(_tokenAddress, 0, 0, _partsPerMillion, _periodHours, false, true)
{}
}
10 changes: 10 additions & 0 deletions contracts/erc20/ERC20RelativeExpenseWithPeriodSliding.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
pragma solidity ^0.4.24;

import "./ERC20Expense.sol";


contract ERC20RelativeExpenseWithPeriodSliding is ERC20Expense {
constructor(address _tokenAddress, uint _partsPerMillion, uint _periodHours) public
ERC20Expense(_tokenAddress, 0, 0, _partsPerMillion, _periodHours, true, true)
{}
}
7 changes: 7 additions & 0 deletions contracts/erc20/ERC20Token.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
pragma solidity ^0.4.24;

import "zeppelin-solidity/contracts/token/ERC20/MintableToken.sol";

contract ERC20Token is MintableToken {

}
47 changes: 45 additions & 2 deletions contracts/erc20/Erc20Expense.sol
Original file line number Diff line number Diff line change
@@ -1,9 +1,52 @@
pragma solidity ^0.4.24;

import "../bases/ExpenseBase.sol";

import "../interfaces/IDestination.sol";
import "../interfaces/IReceiver.sol";
import "../interfaces/ITokenReceiver.sol";

import "zeppelin-solidity/contracts/math/SafeMath.sol";
import "zeppelin-solidity/contracts/ownership/Ownable.sol";
import "zeppelin-solidity/contracts/token/ERC20/ERC20.sol";


/**
* @title ERC20Expense
* @dev Something that needs money (task, salary, bonus, etc)
* Should be used in the Moneyflow so will automatically receive ERC20.
*/
contract ERC20Expense is ITokenReceiver, IDestination, ExpenseBase {
ERC20 public token;

constructor(
address _tokenAddress,
uint _totalNeeded,
uint _minAmount,
uint _partsPerMillion,
uint _periodHours,
bool _isSlidingAmount,
bool _isPeriodic) public
{
token = ERC20(_tokenAddress);
expense = _constructExpense(uint128(_totalNeeded), uint128(_minAmount), uint32(_partsPerMillion), uint32(_periodHours), _isSlidingAmount, _isPeriodic);
}

event ProcessTokensExpense(address sender, address target, uint _value);
function processTokens(uint _currentFlow, uint _value) public {
require(_value <= token.allowance(msg.sender, address(this)));
token.transferFrom(msg.sender, address(this), _value);
emit ProcessTokensExpense(msg.sender, address(this), _value);
expense = _processAmount(expense, _currentFlow, _value);
}

contract Erc20Expense {
function flush() public onlyOwner {
token.transfer(owner, expense.balance);
expense = _processFlushTo(expense, owner);
}

}
function flushTo(address _to) public onlyOwner {
token.transfer(_to, expense.balance);
expense = _processFlushTo(expense, _to);
}
}
31 changes: 29 additions & 2 deletions contracts/erc20/Erc20Splitter.sol
Original file line number Diff line number Diff line change
@@ -1,9 +1,36 @@
pragma solidity ^0.4.24;

import "zeppelin-solidity/contracts/math/SafeMath.sol";
import "../bases/SplitterBase.sol";

import "zeppelin-solidity/contracts/ownership/Ownable.sol";
import "zeppelin-solidity/contracts/token/ERC20/ERC20.sol";

import "../interfaces/ISplitter.sol";
import "../interfaces/ITokenReceiver.sol";
import "../interfaces/IReceiver.sol";


/**
* @title Splitter
* @dev Will split money from top to down (order matters!). It is possible for some children to not receive money
* if they have ended.
*/
contract ERC20Splitter is ITokenReceiver, SplitterBase {
ERC20 public token;

constructor(address _tokenAddress) public {
token = ERC20(_tokenAddress);
splitter = _constructSplitter(false);
}

contract Erc20Splitter {
function _elementProcessing(address _target, uint _currentFlow, uint _value) internal {
token.approve(_target, _value);
ITokenReceiver(_target).processTokens(_currentFlow, _value);
}

function processTokens(uint _currentFlow, uint _value) public {
require(_value <= token.allowance(msg.sender, address(this)));
token.transferFrom(msg.sender, address(this), _value);
_processAmount(splitter, _currentFlow, _value);
}
}
31 changes: 29 additions & 2 deletions contracts/erc20/Erc20Table.sol
Original file line number Diff line number Diff line change
@@ -1,9 +1,36 @@
pragma solidity ^0.4.24;

import "zeppelin-solidity/contracts/math/SafeMath.sol";
import "../bases/TableBase.sol";
import "../bases/ExpenseBase.sol";
import "../bases/SplitterBase.sol";

import "../interfaces/IReceiver.sol";
import "../interfaces/ITokenReceiver.sol";

import "zeppelin-solidity/contracts/ownership/Ownable.sol";
import "zeppelin-solidity/contracts/token/ERC20/ERC20.sol";


contract ERC20Table is ITable, IReceiver, ITokenReceiver, TableBase {
ERC20 public token;

constructor(address _tokenAddress) public {
token = ERC20(_tokenAddress);
}

function processTokens(uint _currentFlow, uint _value) public {
require(_value <= token.allowance(msg.sender, address(this)));
_processAmountAt(0, _currentFlow, _value);
token.transferFrom(msg.sender, address(this), _value);
}

contract Erc20Table {
function flushAt(uint _eId) public onlyOwner isCorrectId(_eId) {
token.transfer(owner, expenses[_eId].balance);
_processFlushToAt(_eId, owner);
}

function flushToAt(uint _eId, address _to) public onlyOwner isCorrectId(_eId) {
token.transfer(_to, expenses[_eId].balance);
_processFlushToAt(_eId, _to);
}
}
2 changes: 1 addition & 1 deletion contracts/ether/WeiAbsoluteExpenseWithPeriod.sol
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
pragma solidity ^0.4.23;
pragma solidity ^0.4.24;

import "./WeiExpense.sol";

Expand Down
2 changes: 1 addition & 1 deletion contracts/ether/WeiAbsoluteExpenseWithPeriodSliding.sol
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
pragma solidity ^0.4.23;
pragma solidity ^0.4.24;

import "./WeiExpense.sol";

Expand Down
Loading

0 comments on commit 2fdee24

Please sign in to comment.