Skip to content

Commit

Permalink
VotingMachine interface update (#32)
Browse files Browse the repository at this point in the history
* absoluteVote : remove ownerVote

uint-> uint256
remove voteWithSpecificAmount

* bump version to alpha 12

* use truffle 5.0

* remove getVoter

* MAX_BOOSTED_PROPOSAL = 4096

* solc 0.5.2

openzeppelin 2.1 (rc)

* make travis happy

* change travis from `org` to `com`

* Remove redundant comment

* bump version

* fix travis link
  • Loading branch information
orenyodfat authored and leviadam committed Dec 25, 2018
1 parent d76e330 commit 877af6c
Show file tree
Hide file tree
Showing 28 changed files with 974 additions and 7,022 deletions.
2 changes: 2 additions & 0 deletions .soliumignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
node_modules
docs
contracts/votingMachines/GenesisProtocol.sol
contracts/test/GenesisProtocolCallbacksMock.sol
2 changes: 1 addition & 1 deletion .soliumrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
4
],
"arg-overflow": [
"warning",
"error",
5
],
"error-reason": [
Expand Down
8 changes: 1 addition & 7 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,9 @@ dist: trusty
language: node_js

node_js:
- "10.13.0"
- "10.14.2"

before_install:
- sudo apt-get update -qq
- sudo apt-get install software-properties-common -y -qq
- sudo add-apt-repository -y ppa:ethereum/ethereum
- sudo add-apt-repository -y ppa:ethereum/ethereum-dev
- sudo apt-get update -qq
- sudo apt-get install geth -y -qq

install:
- npm i
Expand Down
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,5 @@
[![Build Status](https://travis-ci.com/daostack/infra.svg?branch=master)](https://travis-ci.com/daostack/infra)
[![NPM Package](https://img.shields.io/npm/v/@daostack/infra.svg?style=flat-square)](https://www.npmjs.org/package/@daostack/infra)

# Infra
Base layer components for Governance such as Voting Machines and Reputation system.
6 changes: 3 additions & 3 deletions contracts/Migrations.sol
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
pragma solidity ^0.4.25;
pragma solidity ^0.5.2;


contract Migrations {
address public owner;
uint public lastCompletedMigration;
uint256 public lastCompletedMigration;

modifier restricted() {
if (msg.sender == owner) {
Expand All @@ -15,7 +15,7 @@ contract Migrations {
owner = msg.sender;
}

function setCompleted(uint completed) public restricted {
function setCompleted(uint256 completed) public restricted {
lastCompletedMigration = completed;
}

Expand Down
56 changes: 24 additions & 32 deletions contracts/Reputation.sol
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
pragma solidity ^0.4.25;
pragma solidity ^0.5.2;

import "openzeppelin-solidity/contracts/ownership/Ownable.sol";

Expand Down Expand Up @@ -32,9 +32,6 @@ contract Reputation is Ownable {
uint128 value;
}

// `creationBlock` is the block number that the Clone Token was created
uint public creationBlock;

// `balances` is the map that tracks the balance of each address, in this
// contract when the balance changes the block number that the change
// occurred is also included in the map
Expand All @@ -43,16 +40,15 @@ contract Reputation is Ownable {
// Tracks the history of the `totalSupply` of the reputation
Checkpoint[] totalSupplyHistory;

/// @notice Constructor to create a MiniMeToken
/// @notice Constructor to create a Reputation
constructor(
) public
{
creationBlock = block.number;
}

/// @dev This function makes it easy to get the total number of reputation
/// @return The total number of reputation
function totalSupply() public view returns (uint) {
function totalSupply() public view returns (uint256) {
return totalSupplyAt(block.number);
}

Expand All @@ -71,8 +67,8 @@ contract Reputation is Ownable {
/// @param _owner The address from which the balance will be retrieved
/// @param _blockNumber The block number when the balance is queried
/// @return The balance at `_blockNumber`
function balanceOfAt(address _owner, uint _blockNumber)
public view returns (uint)
function balanceOfAt(address _owner, uint256 _blockNumber)
public view returns (uint256)
{
if ((balances[_owner].length == 0) || (balances[_owner][0].fromBlock > _blockNumber)) {
return 0;
Expand All @@ -85,7 +81,7 @@ contract Reputation is Ownable {
/// @notice Total amount of reputation at a specific `_blockNumber`.
/// @param _blockNumber The block number when the totalSupply is queried
/// @return The total amount of reputation at `_blockNumber`
function totalSupplyAt(uint _blockNumber) public view returns(uint) {
function totalSupplyAt(uint256 _blockNumber) public view returns(uint256) {
if ((totalSupplyHistory.length == 0) || (totalSupplyHistory[0].fromBlock > _blockNumber)) {
return 0;
// This will return the expected totalSupply during normal situations
Expand All @@ -95,38 +91,34 @@ contract Reputation is Ownable {
}

/// @notice Generates `_amount` reputation that are assigned to `_owner`
/// @param _owner The address that will be assigned the new reputation
/// @param _user The address that will be assigned the new reputation
/// @param _amount The quantity of reputation generated
/// @return True if the reputation are generated correctly
function mint(address _owner, uint _amount) public onlyOwner returns (bool) {
uint curTotalSupply = totalSupply();
function mint(address _user, uint256 _amount) public onlyOwner returns (bool) {
uint256 curTotalSupply = totalSupply();
require(curTotalSupply + _amount >= curTotalSupply); // Check for overflow
uint previousBalanceTo = balanceOf(_owner);
uint256 previousBalanceTo = balanceOf(_user);
require(previousBalanceTo + _amount >= previousBalanceTo); // Check for overflow
updateValueAtNow(totalSupplyHistory, curTotalSupply + _amount);
updateValueAtNow(balances[_owner], previousBalanceTo + _amount);
emit Mint(_owner, _amount);
updateValueAtNow(balances[_user], previousBalanceTo + _amount);
emit Mint(_user, _amount);
return true;
}

/// @notice Burns `_amount` reputation from `_owner`
/// @param _owner The address that will lose the reputation
/// @param _user The address that will lose the reputation
/// @param _amount The quantity of reputation to burn
/// @return True if the reputation are burned correctly
function burn(address _owner, uint _amount) public onlyOwner returns (bool) {
uint curTotalSupply = totalSupply();
uint amountBurned = _amount;
if (curTotalSupply < amountBurned) {
amountBurned = curTotalSupply;
}
uint previousBalanceFrom = balanceOf(_owner);
function burn(address _user, uint256 _amount) public onlyOwner returns (bool) {
uint256 curTotalSupply = totalSupply();
uint256 amountBurned = _amount;
uint256 previousBalanceFrom = balanceOf(_user);
if (previousBalanceFrom < amountBurned) {
amountBurned = previousBalanceFrom;
}
//require(previousBalanceFrom >= _amount);
updateValueAtNow(totalSupplyHistory, curTotalSupply - amountBurned);
updateValueAtNow(balances[_owner], previousBalanceFrom - amountBurned);
emit Burn(_owner, amountBurned);
updateValueAtNow(balances[_user], previousBalanceFrom - amountBurned);
emit Burn(_user, amountBurned);
return true;
}

Expand All @@ -138,7 +130,7 @@ contract Reputation is Ownable {
/// @param checkpoints The history of values being queried
/// @param _block The block number to retrieve the value at
/// @return The number of reputation being queried
function getValueAt(Checkpoint[] storage checkpoints, uint _block) internal view returns (uint) {
function getValueAt(Checkpoint[] storage checkpoints, uint256 _block) internal view returns (uint256) {
if (checkpoints.length == 0) {
return 0;
}
Expand All @@ -152,10 +144,10 @@ contract Reputation is Ownable {
}

// Binary search of the value in the array
uint min = 0;
uint max = checkpoints.length-1;
uint256 min = 0;
uint256 max = checkpoints.length-1;
while (max > min) {
uint mid = (max + min + 1) / 2;
uint256 mid = (max + min + 1) / 2;
if (checkpoints[mid].fromBlock<=_block) {
min = mid;
} else {
Expand All @@ -169,7 +161,7 @@ contract Reputation is Ownable {
/// `totalSupplyHistory`
/// @param checkpoints The history of data being updated
/// @param _value The new number of reputation
function updateValueAtNow(Checkpoint[] storage checkpoints, uint _value) internal {
function updateValueAtNow(Checkpoint[] storage checkpoints, uint256 _value) internal {
require(uint128(_value) == _value); //check value is in the 128 bits bounderies
if ((checkpoints.length == 0) || (checkpoints[checkpoints.length - 1].fromBlock < block.number)) {
Checkpoint storage newCheckPoint = checkpoints[checkpoints.length++];
Expand Down
4 changes: 2 additions & 2 deletions contracts/libs/RealMath.sol
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
pragma solidity ^0.4.25;
pragma solidity ^0.5.2;

/**
* RealMath: fixed-point math library, based on fractional and integer parts.
Expand Down Expand Up @@ -289,7 +289,7 @@ library RealMath {
}

// Find the high bit
int216 highBit = findbit(hibit(uint256(realArg)));
int216 highBit = findbit(hibit(uint256 (realArg)));

// We'll shift so the high bit is the lowest non-fractional bit.
shift = highBit - int216(REAL_FBITS);
Expand Down
30 changes: 11 additions & 19 deletions contracts/test/AbsoluteVoteExecuteMock.sol
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
pragma solidity ^0.4.25;
pragma solidity ^0.5.2;

import "../votingMachines/ProposalExecuteInterface.sol";
import "../votingMachines/VotingMachineCallbacksInterface.sol";
Expand All @@ -15,7 +15,7 @@ contract AbsoluteVoteExecuteMock is Debug,VotingMachineCallbacksInterface,Propos
mapping (bytes32=>uint) proposalsBlockNumbers;


event NewProposal(bytes32 indexed _proposalId, address indexed _organization, uint _numOfChoices, address _proposer, bytes32 _paramsHash);
event NewProposal(bytes32 indexed _proposalId, address indexed _organization, uint256 _numOfChoices, address _proposer, bytes32 _paramsHash);

/**
* @dev Constructor
Expand All @@ -31,40 +31,40 @@ contract AbsoluteVoteExecuteMock is Debug,VotingMachineCallbacksInterface,Propos
return reputation.totalSupplyAt(proposalsBlockNumbers[_proposalId]);
}

function mintReputation(uint _amount,address _beneficiary,bytes32)
function mintReputation(uint256 _amount,address _beneficiary,bytes32)
external
onlyOwner
returns(bool)
{
return reputation.mint(_beneficiary,_amount);
}

function burnReputation(uint _amount,address _beneficiary,bytes32)
function burnReputation(uint256 _amount,address _beneficiary,bytes32)
external
onlyOwner
returns(bool)
{
return reputation.burn(_beneficiary,_amount);
}

function reputationOf(address _owner,bytes32 _proposalId) external view returns(uint) {
function reputationOf(address _owner,bytes32 _proposalId) external view returns(uint256) {
return reputation.balanceOfAt(_owner,proposalsBlockNumbers[_proposalId]);
}

function stakingTokenTransfer(StandardToken _stakingToken,address _beneficiary,uint _amount,bytes32)
function stakingTokenTransfer(ERC20 _stakingToken,address _beneficiary,uint256 _amount,bytes32)
external
onlyOwner
returns(bool)
{
return _stakingToken.transfer(_beneficiary,_amount);
}

function balanceOfStakingToken(StandardToken _stakingToken,bytes32)
function balanceOfStakingToken(ERC20 _stakingToken,bytes32)
external
view
returns(uint)
returns(uint256)
{
return _stakingToken.balanceOf(this);
return _stakingToken.balanceOf(address(this));
}

function executeProposal(bytes32 _proposalId,int _decision) external returns(bool) {
Expand All @@ -73,15 +73,7 @@ contract AbsoluteVoteExecuteMock is Debug,VotingMachineCallbacksInterface,Propos
return true;
}

function ownerVote(bytes32 _proposalId,uint _vote, address _voter) external returns(bool) {
return absoluteVote.ownerVote(_proposalId,_vote,_voter);
}

function cancelProposal(bytes32 _proposalId) external returns(bool) {
return absoluteVote.cancelProposal(_proposalId);
}

function propose(uint _numOfChoices, bytes32 _paramsHash, address ,address _proposer,address _organization)
function propose(uint256 _numOfChoices, bytes32 _paramsHash, address ,address _proposer,address _organization)
external
returns
(bytes32)
Expand All @@ -93,7 +85,7 @@ contract AbsoluteVoteExecuteMock is Debug,VotingMachineCallbacksInterface,Propos
}

//this function is used only for testing purpose on this mock contract
function burnReputationTest(uint _amount,address _beneficiary,bytes32)
function burnReputationTest(uint256 _amount,address _beneficiary,bytes32)
external
returns(bool)
{
Expand Down
4 changes: 2 additions & 2 deletions contracts/test/Debug.sol
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
pragma solidity ^0.4.25;
pragma solidity ^0.5.2;
/*
A contract you can inherit from that has some useful Events to print statements.
*/
Expand All @@ -8,7 +8,7 @@ contract Debug {
event LogAddress(address _msg);
event LogInt(int _msg);
event LogString(string _msg);
event LogUint(uint _msg);
event LogUint(uint256 _msg);
event LogBytes(bytes _msg);
event LogBytes32(bytes32 _msg);
event LogBool(bool _msg);
Expand Down
5 changes: 2 additions & 3 deletions contracts/test/ERC827TokenMock.sol
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
pragma solidity ^0.4.25;
pragma solidity ^0.5.2;

import "../token/ERC827/ERC827Token.sol";// mock class using ERC827 Token


contract ERC827TokenMock is ERC827Token {

constructor(address initialAccount, uint256 initialBalance) public {
balances[initialAccount] = initialBalance;
totalSupply_ = initialBalance;
_mint(initialAccount,initialBalance);
}

}
Loading

0 comments on commit 877af6c

Please sign in to comment.