diff --git a/contracts/ICO/SimpleICO.sol b/contracts/ICO/SimpleICO.sol index 7312684..9df2ac7 100644 --- a/contracts/ICO/SimpleICO.sol +++ b/contracts/ICO/SimpleICO.sol @@ -85,6 +85,10 @@ contract SimpleICO is DaoClient, Ownable { buyTokens(msg.sender); } + /** + * @notice This function should be called only when ICO open and not paused + * @param _beneficiary account which gets tokens + */ function buyTokens(address _beneficiary) onlyWhileOpen whenNotPaused public payable { require (msg.value >= minPurchase && msg.value <= maxPurchase); require (msg.value + weiRaised <= hardCap); @@ -107,25 +111,49 @@ contract SimpleICO is DaoClient, Ownable { ); } + /** + * @notice This function should be called only when ICO open and not paused + * @param _weiAmount amount of wei sended to the contract + * @return calculated amount of tokens + * @dev this function calculates tokens by formula wei amount * rate + */ function _getTokenAmount(uint256 _weiAmount) internal view returns (uint256) { return _weiAmount.mul(rate); } + /** + * @notice This function should be called only when ICO open and only by owner + * @dev stops ICO + */ function emergencyStop() onlyOwner onlyWhileOpen public { stopped = true; } + /** + * @notice This function should be called only when ICO open and only by owner + * @dev pause ICO + */ function pauseICO() onlyOwner whenNotPaused public { paused = true; } + /** + * @notice This function should be called only by owner + * @dev unpause ICO + */ function unpauseICO() onlyOwner public { require(paused); paused = false; } + /** + * @notice This function should be called only by owner + * @param _addresses array with addresses + * @param _tokenAmounts array with token amounts related to addresses in _addresses array + * @dev this function distributes tokens before ICO + */ function distributeBeforeICO(address[] _addresses, uint256[] _tokenAmounts) onlyOwner public { require(block.timestamp < startDate); require(_addresses.length > 0); @@ -136,6 +164,12 @@ contract SimpleICO is DaoClient, Ownable { } } + /** + * @notice This function should be called only by owner and only when ICO finished with success + * @param _addresses array with addresses + * @param _tokenAmounts array with token amounts related to addresses in _addresses array + * @dev this function distributes tokens after ICO + */ function distributeAfterICO(address[] _addresses, uint256[] _tokenAmounts) onlyAfterSuccess onlyOwner public { require (_addresses.length > 0); require (_addresses.length == _tokenAmounts.length); @@ -145,18 +179,36 @@ contract SimpleICO is DaoClient, Ownable { } } + /** + * @notice This function should be called only by owner and only while ICO is open + * @param _member address + * @dev this function adds _member to the whitelist + */ function addToWhitelist(address _member) onlyOwner onlyWhileOpen public { isWhitelisted[_member] = true; } + /** + * @param _member address + * @return true if _member in whitelist + */ function isMemberInWhitelist(address _member) public returns(bool) { return isWhitelisted[_member]; } + /** + * @notice This function should be called only by owner and only after ICO finished with success + * @param _wallet address + * @dev forward funds from ICO contract to wallet + */ function forwardFunds(address _wallet) onlyAfterSuccess onlyOwner public { _wallet.transfer(address(this).balance); } + /** + * @notice This function should be called only after ICO fail + * @dev returns money for all investors + */ function refund() onlyAfterFail public { uint256 payment = deposits[msg.sender]; assert(address(this).balance >= payment); diff --git a/contracts/tasks/TaskTable.sol b/contracts/tasks/TaskTable.sol index e474f07..ffa9daa 100644 --- a/contracts/tasks/TaskTable.sol +++ b/contracts/tasks/TaskTable.sol @@ -93,6 +93,17 @@ contract TaskTable { dao = _dao; } + /** + * @param _caption caption of the task + * @param _desc task description + * @param _isPostpaid true if task postpaid + * @param _isDonation true if task have donation + * @param _neededWei needed wei which should be payeed for employee + * @param _deadlineTime deadline time of the task + * @param _timeToCancell time to cancell task before starting + * @return task index + * @dev creates new task + */ function addNewTask( string _caption, string _desc, @@ -127,7 +138,22 @@ contract TaskTable { return (elementsCount - 1); } - function addNewBounty (string _caption, string _desc, uint _neededWei, uint64 _deadlineTime, uint64 _timeToCancell) external returns(uint) { + /** + * @param _caption caption of the bounty + * @param _desc bounty description + * @param _neededWei needed wei which should be payeed for employee + * @param _deadlineTime deadline time of the bounty + * @param _timeToCancell time to cancell bounty before starting + * @return bounty index + * @dev creates new bounty + */ + function addNewBounty ( + string _caption, + string _desc, + uint _neededWei, + uint64 _deadlineTime, + uint64 _timeToCancell) external returns(uint) + { tasks[elementsCount] = Task( _caption, _desc, @@ -152,6 +178,12 @@ contract TaskTable { return (elementsCount - 1); } + /** + * @notice This function should be called only by account with START_TASK permissions + * @param _id id of the task + * @param _employee employee of this task + * @dev starts task + */ function startTask(uint _id, address _employee) public isCanDo(START_TASK) { require(getCurrentState(_id) == State.Init || getCurrentState(_id) == State.PrePaid); @@ -166,6 +198,11 @@ contract TaskTable { } // callable by anyone + /** + * @notice This function should be called only by account with START_BOUNTY permissions + * @param _id id of the bounty + * @dev starts bounty + */ function startBounty(uint _id) public isCanDo(START_BOUNTY) { require(getCurrentState(_id) == State.PrePaid); tasks[_id].startTime = block.timestamp; @@ -175,29 +212,57 @@ contract TaskTable { } // who will complete this task + /** + * @notice This function should be called only by money source + * @param _id id of the task + * @param _employee account who will complete this task + * @dev this function set employee account for this task + */ function setEmployee(uint _id, address _employee) onlyByMoneySource(_id) public { emit TaskTableSetEmployee(_employee); tasks[_id].employee = _employee; } // where to send money + /** + * @notice This function should be called only by money source + * @param _id id of the task + * @param _output account who will get all funds of this task + * @dev this function set account which will get all funds after this task will be completed + */ function setOutput(uint _id, address _output) onlyByMoneySource(_id) public { emit TaskTableSetOutput(_output); tasks[_id].output = _output; } + /** + * @param _id id of the task + * @return balance of task with id _id + */ function getBalance(uint _id) public view returns(uint) { return tasks[_id].funds; } + /** + * @param _id id of the task + * @return caption of task with id _id + */ function getCaption(uint _id) public view returns(string) { return tasks[_id].caption; } + /** + * @param _id id of the task + * @return description of task with id _id + */ function getDescription(uint _id) public view returns(string) { return tasks[_id].desc; } + /** + * @param _id id of the task + * @return state of task with id _id + */ function getCurrentState(uint _id) public view returns(State) { // for Prepaid task -> client should call processFunds method to put money into this task // when state is Init @@ -214,6 +279,10 @@ contract TaskTable { return tasks[_id].state; } + /** + * @param _id id of the task + * @return true if state of the task is init, needed wei != 0, task not post paid + */ function isTaskPrepaid(uint _id) internal view returns(bool) { if((State.Init==tasks[_id].state) && (tasks[_id].neededWei!=0) && (!tasks[_id].isPostpaid)) { if(tasks[_id].neededWei == tasks[_id].funds && tasks[_id].funds <= address(this).balance) { @@ -223,6 +292,10 @@ contract TaskTable { return false; } + /** + * @param _id id of the task + * @return true if state of the task is coplete, needed wei != 0, task post paid + */ function isTaskPostpaidAndCompleted(uint _id) internal view returns(bool) { if((State.Complete==tasks[_id].state) && (tasks[_id].neededWei!=0) && (tasks[_id].isPostpaid)) { if(tasks[_id].neededWei <= tasks[_id].funds && tasks[_id].funds <= address(this).balance) { @@ -232,6 +305,11 @@ contract TaskTable { return false; } + /** + * @notice This function should be called only by money source + * @param _id id of the task + * @dev cancel task before start + */ function cancel(uint _id) onlyByMoneySource(_id) isCanCancel(_id) public { require(getCurrentState(_id) == State.Init || getCurrentState(_id) == State.PrePaid); if(getCurrentState(_id) == State.PrePaid) { @@ -242,6 +320,11 @@ contract TaskTable { emit TaskTableStateChanged(tasks[_id].state); } + /** + * @notice This function should be called only by money source + * @param _id id of the task + * @dev return money to payeer(oney source) if deadline for task already missed + */ function returnMoney(uint _id) isDeadlineMissed(_id) onlyByMoneySource(_id) public { require(getCurrentState(_id) == State.InProgress); if(address(this).balance >= tasks[_id].funds) { @@ -252,6 +335,11 @@ contract TaskTable { emit TaskTableStateChanged(tasks[_id].state); } + /** + * @notice This function should be called only by money source + * @param _id id of the task + * @dev this function change state of the task to complete + */ function notifyThatCompleted(uint _id) public onlyEmployeeOrMoneySource(_id) { require(getCurrentState(_id) == State.InProgress); @@ -264,6 +352,11 @@ contract TaskTable { } } + /** + * @notice This function should be called only by money source + * @param _id id of the task + * @dev this function change state of the task to complete and sets needed wei + */ function evaluateAndSetNeededWei(uint _id, uint _neededWei) public onlyByMoneySource(_id) { require(getCurrentState(_id) == State.CompleteButNeedsEvaluation); require(0==tasks[_id].neededWei); @@ -275,6 +368,11 @@ contract TaskTable { // for Prepaid tasks only! // for Postpaid: call processFunds and transfer money instead! + /** + * @notice This function should be called only by money source (payeer) + * @param _id id of the task + * @dev this function confirm completion and changes state of the task to CanGetFunds + */ function confirmCompletion(uint _id) public onlyByMoneySource(_id) { require(getCurrentState(_id) == State.Complete); require(!tasks[_id].isPostpaid); @@ -286,6 +384,10 @@ contract TaskTable { // IDestination overrides: // pull model + /** + * @param _id id of the task + * @dev forward funds to the output account + */ function flush(uint _id) public { require(getCurrentState(_id) == State.CanGetFunds); require(0x0!=tasks[_id].output); @@ -295,6 +397,10 @@ contract TaskTable { emit TaskTableStateChanged(tasks[_id].state); } + /** + * @param _id id of the task + * @dev should call this function when want to send funds to the task + */ function processFunds(uint _id) public payable { emit TaskTableProcessFunds(msg.sender, msg.value, _id); if(isCanSetNeededWei(_id)) { @@ -305,6 +411,10 @@ contract TaskTable { tasks[_id].funds += msg.value; } + /** + * @param _id id of the task + * @return true if task is post paid, needed wei > 0 nad state in complete + */ function isCanSetNeededWei(uint _id) internal view returns(bool) { if(tasks[_id].isPostpaid && (0 == tasks[_id].neededWei) && (State.Complete==tasks[_id].state)) { return true; diff --git a/contracts/tasks/WeiBounty.sol b/contracts/tasks/WeiBounty.sol index 94279c4..f766dd9 100644 --- a/contracts/tasks/WeiBounty.sol +++ b/contracts/tasks/WeiBounty.sol @@ -19,6 +19,10 @@ contract WeiBounty is WeiGenericTask { // callable by anyone // anyone should call this function when for starting the task + /** + * @notice This function should be called only by account with START_BOUNTY permissions + * @dev starts bounty + */ function startTask() public isCanDo(START_BOUNTY) { require(getCurrentState() == State.PrePaid); startTime = block.timestamp; diff --git a/contracts/tasks/WeiGenericTask.sol b/contracts/tasks/WeiGenericTask.sol index db88e10..29eb10a 100644 --- a/contracts/tasks/WeiGenericTask.sol +++ b/contracts/tasks/WeiGenericTask.sol @@ -132,23 +132,38 @@ contract WeiGenericTask is WeiAbsoluteExpense { timeToCancell = _timeToCancell * 1 hours; } - // set account(employee) who will complete this task + // who will complete this task + /** + * @notice This function should be called only by owner + * @param _employee account who will complete this task + * @dev this function set employee account for this task + */ function setEmployee(address _employee) public onlyOwner { emit WeiGenericTaskSetEmployee(_employee); employee = _employee; } - // set account(output) who will get all funds + // where to send money + /** + * @notice This function should be called only by owner + * @param _output account who will get all funds of this task + * @dev this function set account which will get all funds after this task will be completed + */ function setOutput(address _output) public onlyOwner { emit WeiGenericTaskSetOutput(_output); output = _output; } + /** + * @return balance of this task + */ function getBalance() public view returns(uint) { return address(this).balance; } - // get current state of Task + /** + * @return current state of the task + */ function getCurrentState() public view returns(State) { // for Prepaid task -> client should call processFunds method to put money into this task // when state is Init @@ -169,7 +184,10 @@ contract WeiGenericTask is WeiAbsoluteExpense { return state; } - // cancell task before it's start + /** + * @notice This function should be called only by owner and creation time + time to cancell should be > now + * @dev this function cancell task and change state of the task to cancelled + */ function cancell() public isCanCancell onlyOwner { require(getCurrentState() == State.Init || getCurrentState() == State.PrePaid); if(getCurrentState() == State.PrePaid) { @@ -180,7 +198,10 @@ contract WeiGenericTask is WeiAbsoluteExpense { emit WeiGenericTaskStateChanged(state); } - // return funds for payeer if employee missed the deadline + /** + * @notice This function should be called only by owner and creation time + deadlineMissed should be <= now + * @dev this function return money to payeer because of deadline missed + */ function returnMoney() public isDeadlineMissed onlyOwner { require(getCurrentState() == State.InProgress); if(address(this).balance > 0) { @@ -191,7 +212,10 @@ contract WeiGenericTask is WeiAbsoluteExpense { emit WeiGenericTaskStateChanged(state); } - // employee or owner should call this function when job will be done + /** + * @notice This function should be called only by owner or employee + * @dev this function change state of the task to complete + */ function notifyThatCompleted() public onlyEmployeeOrOwner { require(getCurrentState() == State.InProgress); @@ -205,7 +229,10 @@ contract WeiGenericTask is WeiAbsoluteExpense { } } - // evaluation of the task by owner + /** + * @notice This function should be called only by owner + * @dev this function change state of the task to complete and sets needed wei + */ function evaluateAndSetNeededWei(uint _neededWei) public onlyOwner { require(getCurrentState() == State.CompleteButNeedsEvaluation); require(0 == neededWei); @@ -217,7 +244,10 @@ contract WeiGenericTask is WeiAbsoluteExpense { // for Prepaid tasks only! // for Postpaid: call processFunds and transfer money instead! - // account who payed for the task should call this function when job will be done + /** + * @notice This function should be called only by money source (payeer) + * @dev this function confirm completion and changes state of the task to CanGetFunds + */ function confirmCompletion() public onlyByMoneySource { require(getCurrentState() == State.Complete); require(!isPostpaid); @@ -229,7 +259,9 @@ contract WeiGenericTask is WeiAbsoluteExpense { // IDestination overrides: // pull model - // transfer money to output when job is completed success + /** + * @dev forward funds to the output account + */ function flush() public { require(getCurrentState() == State.CanGetFunds); require(0x0 != output); @@ -245,7 +277,10 @@ contract WeiGenericTask is WeiAbsoluteExpense { } } - // pay for task + /** + * @param _currentFlow index of the money flow + * @dev should call this function when want to send funds to the task + */ function processFunds(uint _currentFlow) public payable { emit WeiGenericTaskProcessFunds(msg.sender, msg.value, _currentFlow); if(isPostpaid && (0 == neededWei) && (State.Complete == state)) { diff --git a/contracts/tasks/WeiTask.sol b/contracts/tasks/WeiTask.sol index 63dfe01..2723f1e 100644 --- a/contracts/tasks/WeiTask.sol +++ b/contracts/tasks/WeiTask.sol @@ -17,7 +17,12 @@ contract WeiTask is WeiGenericTask { } // callable by any Employee of the current DaoBase or Owner - // employee should call this function when for starting the task + // employee should call this function when for starting the task + /** + * @notice This function should be called only by account with START_TASK permissions + * @param _employee employee of this task + * @dev starts task + */ function startTask(address _employee) public isCanDo(START_TASK) { require(getCurrentState() == State.Init || getCurrentState() == State.PrePaid); diff --git a/contracts/tokens/StdDaoToken.sol b/contracts/tokens/StdDaoToken.sol index 3c5b7dc..1daf388 100644 --- a/contracts/tokens/StdDaoToken.sol +++ b/contracts/tokens/StdDaoToken.sol @@ -60,7 +60,11 @@ contract StdDaoToken is DetailedERC20, PausableToken, CopyOnWriteToken, ITokenVo // ITokenVotingSupport implementation // TODO: VULNERABILITY! no onlyOwner! - // should be called when voting started for conservation balances during this voting + /** + * @notice This function should be called only when token not paused + * @return index of the new voting + * @dev should be called when voting started for conservation balances during this voting + */ function startNewVoting() public whenNotPaused returns(uint) { uint idOut = super.startNewEvent(); emit VotingStarted(msg.sender, idOut); @@ -69,16 +73,31 @@ contract StdDaoToken is DetailedERC20, PausableToken, CopyOnWriteToken, ITokenVo // TODO: VULNERABILITY! no onlyOwner! // update balances from conservation after voting finish + /** + * @notice This function should be called only when token not paused + * @param _votingID id of voting + * @dev update balances from conservation after voting finish + */ function finishVoting(uint _votingID) whenNotPaused public { super.finishEvent(_votingID); emit VotingFinished(msg.sender, _votingID); } + /** + * @param _votingID id of voting + * @param _owner account + * @return balance of voting for account _owner + */ function getBalanceAtVoting(uint _votingID, address _owner) public view returns (uint256) { return super.getBalanceAtEventStart(_votingID, _owner); } - // transfer tokens from msg.sender to _to address + /** + * @notice This function should be called only when token not paused + * @param _to address + * @param _value amount of tokens which will be transfered + * @return true + */ function transfer(address _to, uint256 _value) public whenNotPaused returns (bool) { if(!isHolder[_to]) { holders.push(_to); @@ -88,6 +107,13 @@ contract StdDaoToken is DetailedERC20, PausableToken, CopyOnWriteToken, ITokenVo } // transfer tokens from _from to _to address + /** + * @notice This function should be called only when token not paused + * @param _from address + * @param _to address + * @param _value amount of tokens which will be transfered + * @return true + */ function transferFrom(address _from, address _to, uint256 _value) public whenNotPaused returns (bool) { if(!isHolder[_to]) { holders.push(_to);