Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: skmgoldin/tcr
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: v1.1.0
Choose a base ref
...
head repository: skmgoldin/tcr
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: master
Choose a head ref

Commits on Jun 15, 2018

  1. Copy the full SHA
    d202c5b View commit details

Commits on Jun 16, 2018

  1. Update README

    skmgoldin committed Jun 16, 2018
    Copy the full SHA
    eae369d View commit details

Commits on Jul 19, 2018

  1. add script to deploy proxies

    kangarang authored and skmgoldin committed Jul 19, 2018
    Copy the full SHA
    7813826 View commit details
  2. update readme

    kangarang authored and skmgoldin committed Jul 19, 2018
    Copy the full SHA
    272bedf View commit details

Commits on Jul 26, 2018

  1. Redesign exit -> delayed exit

    * Split exit() into initExit() and finalizeExit()
    * Add uint `exitTime` to Listing struct and `exitTimeDelay` to Parameterizer struct
    * Fix all test cases to work with initExit() and finalizeExit()
    * Add new test cases for initializing and finalizing an exit from the whitelist
    * Refactor exit.js to stateless design
    * Add checks for `exitTime` in exit.js
    * Fixed incorrect usage of assert syntax
    nigel-heeral authored and skmgoldin committed Jul 26, 2018
    Copy the full SHA
    e3e1df6 View commit details
  2. Implement exit deadline

    * Add `exitTimeExpiry` parameter to denote how long you have to call finalizeExit()
    * Add test case to prove user can't finalizeExit when `exitTimeExpiry` has elapsed
    * Add ability to call initExit() when previous exit was expired
    * Add test case for re-finalizing an exit
    * Use `now` alias for `block.timestamp`
    nigel-heeral authored and skmgoldin committed Jul 26, 2018
    Copy the full SHA
    02585f2 View commit details
  3. Copy the full SHA
    c33247f View commit details
  4. Copy the full SHA
    73956f0 View commit details
  5. Remove extraneous comment

    nigel-heeral authored and skmgoldin committed Jul 26, 2018
    Copy the full SHA
    076bbe6 View commit details
  6. delayed exit parameters

    * add exitTimeExpiry to Parameterizer
    * rm parameterizer migration
    * add delayed exit params to test proxy deployment
    kangarang authored and skmgoldin committed Jul 26, 2018
    Copy the full SHA
    324c6c6 View commit details
  7. Copy the full SHA
    17ba024 View commit details
  8. Change exitTimeExpiry to exitPeriodLen for clarity

    * Added more comments to initExit.js and finalizeExit.js
    * Formatted code into blocks for clarity
    nigel-heeral authored and skmgoldin committed Jul 26, 2018
    Copy the full SHA
    5fb6d3a View commit details
  9. Store user exitTimeExpiry in listing struct

    * Refactor initExit.js and finalizeExit.js to test `exitTimeExpiry`
    nigel-heeral authored and skmgoldin committed Jul 26, 2018
    Copy the full SHA
    480feed View commit details
  10. Copy the full SHA
    98701ee View commit details
  11. Make changes based on code review

    * Use snapshotted value for `exitTimeExpiry` in `initExit()`
    * Refactor test for `exitPeriodLen` parameter change
    * Use `beforeEach` to decrease statefulness of tests
    * Improve comments
    nigel-heeral authored and skmgoldin committed Jul 26, 2018
    Copy the full SHA
    63d511c View commit details

Commits on Aug 4, 2018

  1. Copy the full SHA
    b8b74a4 View commit details
  2. Fix apply() to be stateless

    * Re-apply a listing in a few stateful tests
    * Add a listing to the whitelist in a test
    kareem-ib authored and kangarang committed Aug 4, 2018
    Copy the full SHA
    650f756 View commit details
  3. Copy the full SHA
    426c3cd View commit details
  4. Copy the full SHA
    6b5a1dc View commit details
  5. Copy the full SHA
    456dd77 View commit details
  6. Copy the full SHA
    d8decda View commit details
  7. Refactor tests to support large integers: minDeposit and pMinDeposit

    * Must pass `toString()` of large number to `BN()`
    * Multiply `minDeposit` by 10 instead of adding due to JS integer rounding
    kareem-ib authored and kangarang committed Aug 4, 2018
    Copy the full SHA
    e2a0f66 View commit details

Commits on Aug 30, 2018

  1. claimRewardSaltBaeStyle

    kangarang authored and skmgoldin committed Aug 30, 2018
    Copy the full SHA
    63e939e View commit details
  2. claimRewardSaltBaeStyle

    kangarang authored and skmgoldin committed Aug 30, 2018
    Copy the full SHA
    c1e8ea2 View commit details
  3. ref: claimReward

    [dependency](Consensys/PLCRVoting#51)
    
    the salt bae ux working group has found that adding some state to polls allows users to claimReward w/o
    having to provide salt
    
    * refactor tests
    * rm incorrect salt test
    kangarang authored and skmgoldin committed Aug 30, 2018
    Copy the full SHA
    915d884 View commit details
  4. use safemath to calculate voterReward

    kangarang authored and skmgoldin committed Aug 30, 2018
    Copy the full SHA
    b256d3a View commit details
  5. bump epm versions

    kangarang authored and skmgoldin committed Aug 30, 2018
    Copy the full SHA
    4008319 View commit details
  6. lint-ignore console.log & web3

    kangarang authored and skmgoldin committed Aug 30, 2018
    Copy the full SHA
    fbeaf88 View commit details
  7. Update package-lock.json

    skmgoldin authored and kangarang committed Aug 30, 2018
    Copy the full SHA
    9f41150 View commit details
  8. Fix compiler warnings

    skmgoldin authored and kangarang committed Aug 30, 2018
    Copy the full SHA
    4853e4d View commit details

Commits on Sep 6, 2018

  1. Copy the full SHA
    b64a481 View commit details

Commits on Sep 10, 2018

  1. improve proxy log output

    kangarang committed Sep 10, 2018
    Copy the full SHA
    ac2a4b5 View commit details

Commits on Sep 17, 2018

  1. 1
    Copy the full SHA
    c3d3a10 View commit details

Commits on Nov 16, 2018

  1. update truffle version fix #87

    Fixes `npm install`  problem in 4.1.11
    godfreyhobbs authored and akuanti committed Nov 16, 2018
    2
    Copy the full SHA
    fd70714 View commit details
Showing with 2,516 additions and 2,100 deletions.
  1. +2 −0 .gitignore
  2. +9 −15 README.md
  3. +16 −15 conf/config.json
  4. +25 −24 contracts/Parameterizer.sol
  5. +53 −28 contracts/Registry.sol
  6. +2 −2 ethpm.json
  7. +1,764 −1,761 package-lock.json
  8. +4 −1 package.json
  9. +101 −0 scripts/deploy_proxies.js
  10. +3 −1 test/ParameterizerFactory/newParameterizerBYOToken.js
  11. +3 −1 test/ParameterizerFactory/newParameterizerWithToken.js
  12. +3 −1 test/RegistryFactory/newRegistryBYOToken.js
  13. +3 −1 test/RegistryFactory/newRegistryWithToken.js
  14. +1 −1 test/parameterizer/canBeSet.js
  15. +1 −1 test/parameterizer/challengeCanBeResolved.js
  16. +8 −5 test/parameterizer/challengeReparameterization.js
  17. +10 −10 test/parameterizer/claimReward.js
  18. +7 −9 test/parameterizer/claimRewards.js
  19. +1 −1 test/parameterizer/get.js
  20. +4 −4 test/parameterizer/processProposal.js
  21. +1 −1 test/parameterizer/propExists.js
  22. +9 −1 test/parameterizer/proposeReparameterization.js
  23. +2 −2 test/parameterizer/tokenClaims.js
  24. +3 −3 test/parameterizer/voterReward.js
  25. +1 −1 test/registry/Registry.js
  26. +5 −2 test/registry/appWasMade.js
  27. +4 −1 test/registry/apply.js
  28. +1 −1 test/registry/challenge.js
  29. +7 −48 test/registry/claimReward.js
  30. +7 −9 test/registry/claimRewards.js
  31. +1 −1 test/registry/deposit.js
  32. +1 −1 test/registry/determineReward.js
  33. +0 −120 test/registry/exit.js
  34. +301 −0 test/registry/finalizeExit.js
  35. +131 −0 test/registry/initExit.js
  36. +1 −1 test/registry/isWhitelisted.js
  37. +2 −2 test/registry/tokenClaims.js
  38. +5 −3 test/registry/updateStatus.js
  39. +1 −1 test/registry/updateStatuses.js
  40. +1 −1 test/registry/userStories.js
  41. +1 −1 test/registry/withdraw.js
  42. +6 −4 test/utils.js
  43. +1 −1 test/voting.js
  44. +4 −14 truffle.js
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
node_modules/*
build/*
builds/*
truffle.js
secrets.json
*.swp
installed_contracts/
conf/
coverage/
coverage.json
notes.md
24 changes: 9 additions & 15 deletions README.md
Original file line number Diff line number Diff line change
@@ -4,6 +4,12 @@

A hash-keyed [token-curated registry (TCR)](https://medium.com/@ilovebagels/token-curated-registries-1-0-61a232f8dac7). [Owner's Manual available](https://github.com/skmgoldin/tcr/blob/master/owners_manual.md).

Mainnet factory: [0x74bd1d07a158e8a9eecfbd2267766f5919e2b21c](https://etherscan.io/address/0x74bd1d07a158e8a9eecfbd2267766f5919e2b21c#code)

Rinkeby factory: [0x2bddfc0c506a00ea3a6ccea5fbbda8843377dcb1](https://rinkeby.etherscan.io/address/0x2bddfc0c506a00ea3a6ccea5fbbda8843377dcb1#code)

EPM: [tcr](https://www.ethpm.com/registry/packages/44)

## Initialize
The only environmental dependency you need is Node. Presently we can guarantee this all works with Node 8.
```
@@ -18,24 +24,12 @@ The repo has a comprehensive test suite. You can run it with `npm run test`. To
The repo is composed as a Truffle project, and is largely idiomatic to Truffle's conventions. The tests are in the `test` directory, the contracts are in the `contracts` directory and the migrations (deployment scripts) are in the `migrations` directory. Furthermore there is a `conf` directory containing json files where deployments can be parameterized.

## Deploying your own TCR
To deploy your own TCR, first open up `conf/config.json`. The `paramDefaults` object in the config JSON will specify the starting parameters your TCR is deployed with. In the `token` object, set `deployToken` to `true` if you want to deploy this TCR's token as part of the TCR deployment. You can specifiy initial recipients of the token in the `tokenHolders` array. If you have already deployed a token, set `deployToken` to `false` and provide the token's address in the `address` property. The token should be EIP20.

The `package.json` includes scripts for deploying to rinkeby and mainnet. Modify `truffle.js` and `package.json` if you need other networks. You'll need a `secrets.json` file with a funded mnemonic on the `m/44'/60'/0'/0/0` HD path in the root of the repo to deploy. Your `secrets.json` should look like this:
Since [v1.1.0](https://github.com/skmgoldin/tcr/releases/tag/v1.1.0), only the factory contracts are deployed during `truffle migrate`. To deploy a RegistryFactory to any network you can use the NPM scripts in the `package.json`. To deploy to a local Ganache instance, set an environment variable `MNEMONIC` to the mnemonic exposed by Ganache. To spawn proxy contracts using a deployed RegistryFactory, execute the snippet in [/scripts](./scripts) by running:

```json
{
"mnemonic": "my good mnemonic ..."
}
```

If you prefer to use an environment variable, your `.bashrc` or `.bash_profile` should look something like:

```bash
export MNEMONIC='my good mnemonic ...'
npm run deploy-proxies:[network]
```

You can use [https://iancoleman.io/bip39/](https://iancoleman.io/bip39/) to generate a mnemonic and derive its `m/44'/60'/0'/0/0` address.

## Packages
The repo consumes several EPM packages. `dll` and `attrstore` are libraries used in PLCRVoting's doubly-linked list abstraction. `tokens` provides an ERC20-comaptible token implementation. All packages are installed automatically when running `npm install`.
The repo consumes several EPM packages. `dll` and `attrstore` are libraries used in PLCRVoting's doubly-linked list abstraction. `tokens` provides an ERC20-comaptible token implementation. `plcr-revival` features batched executions for some transactions. All packages are installed automatically when running `npm install`.

31 changes: 16 additions & 15 deletions conf/config.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"paramDefaults": {
"minDeposit": 10,
"pMinDeposit": 100,
"minDeposit": 10000000000000000000,
"pMinDeposit": 100000000000000000000,
"applyStageLength": 600,
"pApplyStageLength": 1200,
"commitStageLength": 600,
@@ -11,25 +11,26 @@
"dispensationPct": 50,
"pDispensationPct": 50,
"voteQuorum": 50,
"pVoteQuorum": 50
"pVoteQuorum": 50,
"exitTimeDelay": 600,
"exitPeriodLen": 600
},
"name": "The TestChain Registry",
"token": {
"address": "0x337cDDa6D41A327c5ad456166CCB781a9722AFf9",
"deployToken": true,
"decimals": "18",
"supply": "1000000000000000000000000000",
"name": "TestCoin",
"decimals": "18",
"symbol": "TEST",
"supply": "1000000000000000000000000000",
"tokenHolders": [
{ "address": "0x627306090abaB3A6e1400e9345bC60c78a8BEf57",
"amount": "250000000000000000000000000" },
{ "address": "0xf17f52151EbEF6C7334FAD080c5704D77216b732",
"amount": "250000000000000000000000000" },
{ "address": "0xC5fdf4076b8F3A5357c5E395ab970B5B54098Fef",
"amount": "250000000000000000000000000" },
{ "address": "0x821aEa9a577a9b44299B9c15c88cf3087F3b5544",
"amount": "250000000000000000000000000" }
"0xd09cc3bc67e4294c4a446d8e4a2934a921410ed7",
"0x8FEa967fF3E8B14498BC17D8d43E8cdd614613c7",
"0x874Fec5f1D5045B85f46fBD2Be6264867c3D7cE5",
"0xf978cC95Eba88cC8869e580d282620e3b4382016",
"0x4fB9dEA18CDf6f737afDfc3f680Fb5500F8F893A",
"0xf17f52151EbEF6C7334FAD080c5704D77216b732",
"0xC5fdf4076b8F3A5357c5E395ab970B5B54098Fef",
"0x821aEa9a577a9b44299B9c15c88cf3087F3b5544",
"0x627306090abaB3A6e1400e9345bC60c78a8BEf57"
]
}
}
49 changes: 25 additions & 24 deletions contracts/Parameterizer.sol
Original file line number Diff line number Diff line change
@@ -113,6 +113,12 @@ contract Parameterizer {

// type of majority out of 100 necessary for proposal success in parameterizer
set("pVoteQuorum", _parameters[11]);

// minimum length of time user has to wait to exit the registry
set("exitTimeDelay", _parameters[12]);

// maximum length of time user can wait to exit the registry
set("exitPeriodLen", _parameters[13]);
}

// -----------------------
@@ -126,10 +132,10 @@ contract Parameterizer {
*/
function proposeReparameterization(string _name, uint _value) public returns (bytes32) {
uint deposit = get("pMinDeposit");
bytes32 propID = keccak256(_name, _value);
bytes32 propID = keccak256(abi.encodePacked(_name, _value));

if (keccak256(_name) == keccak256("dispensationPct") ||
keccak256(_name) == keccak256("pDispensationPct")) {
if (keccak256(abi.encodePacked(_name)) == keccak256(abi.encodePacked("dispensationPct")) ||
keccak256(abi.encodePacked(_name)) == keccak256(abi.encodePacked("pDispensationPct"))) {
require(_value <= 100);
}

@@ -186,7 +192,7 @@ contract Parameterizer {
//take tokens from challenger
require(token.transferFrom(msg.sender, this, deposit));

var (commitEndDate, revealEndDate,) = voting.pollMap(pollID);
(uint commitEndDate, uint revealEndDate,,,) = voting.pollMap(pollID);

emit _NewChallenge(_propID, pollID, commitEndDate, revealEndDate, msg.sender);
return pollID;
@@ -240,23 +246,23 @@ contract Parameterizer {
/**
@notice Claim the tokens owed for the msg.sender in the provided challenge
@param _challengeID the challenge ID to claim tokens for
@param _salt the salt used to vote in the challenge being withdrawn for
*/
function claimReward(uint _challengeID, uint _salt) public {
function claimReward(uint _challengeID) public {
Challenge storage challenge = challenges[_challengeID];
// ensure voter has not already claimed tokens and challenge results have been processed
require(challenges[_challengeID].tokenClaims[msg.sender] == false);
require(challenges[_challengeID].resolved == true);
require(challenge.tokenClaims[msg.sender] == false);
require(challenge.resolved == true);

uint voterTokens = voting.getNumPassingTokens(msg.sender, _challengeID, _salt);
uint reward = voterReward(msg.sender, _challengeID, _salt);
uint voterTokens = voting.getNumPassingTokens(msg.sender, _challengeID);
uint reward = voterReward(msg.sender, _challengeID);

// subtract voter's information to preserve the participation ratios of other voters
// compared to the remaining pool of rewards
challenges[_challengeID].winningTokens -= voterTokens;
challenges[_challengeID].rewardPool -= reward;
challenge.winningTokens -= voterTokens;
challenge.rewardPool -= reward;

// ensures a voter cannot claim tokens again
challenges[_challengeID].tokenClaims[msg.sender] = true;
challenge.tokenClaims[msg.sender] = true;

emit _RewardClaimed(_challengeID, reward, msg.sender);
require(token.transfer(msg.sender, reward));
@@ -266,15 +272,11 @@ contract Parameterizer {
@dev Called by a voter to claim their rewards for each completed vote.
Someone must call updateStatus() before this can be called.
@param _challengeIDs The PLCR pollIDs of the challenges rewards are being claimed for
@param _salts The salts of a voter's commit hashes in the given polls
*/
function claimRewards(uint[] _challengeIDs, uint[] _salts) public {
// make sure the array lengths are the same
require(_challengeIDs.length == _salts.length);

function claimRewards(uint[] _challengeIDs) public {
// loop through arrays, claiming each individual vote reward
for (uint i = 0; i < _challengeIDs.length; i++) {
claimReward(_challengeIDs[i], _salts[i]);
claimReward(_challengeIDs[i]);
}
}

@@ -286,14 +288,13 @@ contract Parameterizer {
@dev Calculates the provided voter's token reward for the given poll.
@param _voter The address of the voter whose reward balance is to be returned
@param _challengeID The ID of the challenge the voter's reward is being calculated for
@param _salt The salt of the voter's commit hash in the given poll
@return The uint indicating the voter's reward
*/
function voterReward(address _voter, uint _challengeID, uint _salt)
function voterReward(address _voter, uint _challengeID)
public view returns (uint) {
uint winningTokens = challenges[_challengeID].winningTokens;
uint rewardPool = challenges[_challengeID].rewardPool;
uint voterTokens = voting.getNumPassingTokens(_voter, _challengeID, _salt);
uint voterTokens = voting.getNumPassingTokens(_voter, _challengeID);
return (voterTokens * rewardPool) / winningTokens;
}

@@ -344,7 +345,7 @@ contract Parameterizer {
@param _name the key whose value is to be determined
*/
function get(string _name) public view returns (uint value) {
return params[keccak256(_name)];
return params[keccak256(abi.encodePacked(_name))];
}

/**
@@ -393,7 +394,7 @@ contract Parameterizer {
@param _value the value to set the param to be set
*/
function set(string _name, uint _value) private {
params[keccak256(_name)] = _value;
params[keccak256(abi.encodePacked(_name))] = _value;
}
}

81 changes: 53 additions & 28 deletions contracts/Registry.sol
Original file line number Diff line number Diff line change
@@ -18,11 +18,12 @@ contract Registry {
event _ApplicationWhitelisted(bytes32 indexed listingHash);
event _ApplicationRemoved(bytes32 indexed listingHash);
event _ListingRemoved(bytes32 indexed listingHash);
event _ListingWithdrawn(bytes32 indexed listingHash);
event _ListingWithdrawn(bytes32 indexed listingHash, address indexed owner);
event _TouchAndRemoved(bytes32 indexed listingHash);
event _ChallengeFailed(bytes32 indexed listingHash, uint indexed challengeID, uint rewardPool, uint totalTokens);
event _ChallengeSucceeded(bytes32 indexed listingHash, uint indexed challengeID, uint rewardPool, uint totalTokens);
event _RewardClaimed(uint indexed challengeID, uint reward, address indexed voter);
event _ExitInitialized(bytes32 indexed listingHash, uint exitTime, uint exitDelayEndDate, address indexed owner);

using SafeMath for uint;

@@ -32,6 +33,8 @@ contract Registry {
address owner; // Owner of Listing
uint unstakedDeposit; // Number of tokens in the listing not locked in a challenge
uint challengeID; // Corresponds to a PollID in PLCRVoting
uint exitTime; // Time the listing may leave the registry
uint exitTimeExpiry; // Expiration date of exit period
}

struct Challenge {
@@ -135,22 +138,47 @@ contract Registry {
}

/**
@dev Allows the owner of a listingHash to remove the listingHash from the whitelist
Returns all tokens to the owner of the listingHash
@param _listingHash A listingHash msg.sender is the owner of.
@dev Initialize an exit timer for a listing to leave the whitelist
@param _listingHash A listing hash msg.sender is the owner of
*/
function exit(bytes32 _listingHash) external {
function initExit(bytes32 _listingHash) external {
Listing storage listing = listings[_listingHash];

require(msg.sender == listing.owner);
require(isWhitelisted(_listingHash));
// Cannot exit during ongoing challenge
require(listing.challengeID == 0 || challenges[listing.challengeID].resolved);

// Ensure user never initializedExit or exitPeriodLen passed
require(listing.exitTime == 0 || now > listing.exitTimeExpiry);

// Set when the listing may be removed from the whitelist
listing.exitTime = now.add(parameterizer.get("exitTimeDelay"));
// Set exit period end time
listing.exitTimeExpiry = listing.exitTime.add(parameterizer.get("exitPeriodLen"));
emit _ExitInitialized(_listingHash, listing.exitTime,
listing.exitTimeExpiry, msg.sender);
}

/**
@dev Allow a listing to leave the whitelist
@param _listingHash A listing hash msg.sender is the owner of
*/
function finalizeExit(bytes32 _listingHash) external {
Listing storage listing = listings[_listingHash];

require(msg.sender == listing.owner);
require(isWhitelisted(_listingHash));
// Cannot exit during ongoing challenge
require(listing.challengeID == 0 || challenges[listing.challengeID].resolved);

// Remove listingHash & return tokens
// Make sure the exit was initialized
require(listing.exitTime > 0);
// Time to exit has to be after exit delay but before the exitPeriodLen is over
require(listing.exitTime < now && now < listing.exitTimeExpiry);

resetListing(_listingHash);
emit _ListingWithdrawn(_listingHash);
emit _ListingWithdrawn(_listingHash, msg.sender);
}

// -----------------------
@@ -205,7 +233,7 @@ contract Registry {
// Takes tokens from challenger
require(token.transferFrom(msg.sender, this, minDeposit));

var (commitEndDate, revealEndDate,) = voting.pollMap(pollID);
(uint commitEndDate, uint revealEndDate,,,) = voting.pollMap(pollID);

emit _Challenge(_listingHash, pollID, _data, commitEndDate, revealEndDate, msg.sender);
return pollID;
@@ -246,23 +274,25 @@ contract Registry {
@dev Called by a voter to claim their reward for each completed vote. Someone
must call updateStatus() before this can be called.
@param _challengeID The PLCR pollID of the challenge a reward is being claimed for
@param _salt The salt of a voter's commit hash in the given poll
*/
function claimReward(uint _challengeID, uint _salt) public {
// Ensures the voter has not already claimed tokens and challenge results have been processed
require(challenges[_challengeID].tokenClaims[msg.sender] == false);
require(challenges[_challengeID].resolved == true);
function claimReward(uint _challengeID) public {
Challenge storage challengeInstance = challenges[_challengeID];
// Ensures the voter has not already claimed tokens and challengeInstance results have
// been processed
require(challengeInstance.tokenClaims[msg.sender] == false);
require(challengeInstance.resolved == true);

uint voterTokens = voting.getNumPassingTokens(msg.sender, _challengeID, _salt);
uint reward = voterReward(msg.sender, _challengeID, _salt);
uint voterTokens = voting.getNumPassingTokens(msg.sender, _challengeID);
uint reward = voterTokens.mul(challengeInstance.rewardPool)
.div(challengeInstance.totalTokens);

// Subtracts the voter's information to preserve the participation ratios
// of other voters compared to the remaining pool of rewards
challenges[_challengeID].totalTokens -= voterTokens;
challenges[_challengeID].rewardPool -= reward;
challengeInstance.totalTokens -= voterTokens;
challengeInstance.rewardPool -= reward;

// Ensures a voter cannot claim tokens again
challenges[_challengeID].tokenClaims[msg.sender] = true;
challengeInstance.tokenClaims[msg.sender] = true;

require(token.transfer(msg.sender, reward));

@@ -273,15 +303,11 @@ contract Registry {
@dev Called by a voter to claim their rewards for each completed vote. Someone
must call updateStatus() before this can be called.
@param _challengeIDs The PLCR pollIDs of the challenges rewards are being claimed for
@param _salts The salts of a voter's commit hashes in the given polls
*/
function claimRewards(uint[] _challengeIDs, uint[] _salts) public {
// make sure the array lengths are the same
require(_challengeIDs.length == _salts.length);

function claimRewards(uint[] _challengeIDs) public {
// loop through arrays, claiming each individual vote reward
for (uint i = 0; i < _challengeIDs.length; i++) {
claimReward(_challengeIDs[i], _salts[i]);
claimReward(_challengeIDs[i]);
}
}

@@ -293,15 +319,14 @@ contract Registry {
@dev Calculates the provided voter's token reward for the given poll.
@param _voter The address of the voter whose reward balance is to be returned
@param _challengeID The pollID of the challenge a reward balance is being queried for
@param _salt The salt of the voter's commit hash in the given poll
@return The uint indicating the voter's reward
*/
function voterReward(address _voter, uint _challengeID, uint _salt)
function voterReward(address _voter, uint _challengeID)
public view returns (uint) {
uint totalTokens = challenges[_challengeID].totalTokens;
uint rewardPool = challenges[_challengeID].rewardPool;
uint voterTokens = voting.getNumPassingTokens(_voter, _challengeID, _salt);
return (voterTokens * rewardPool) / totalTokens;
uint voterTokens = voting.getNumPassingTokens(_voter, _challengeID);
return voterTokens.mul(rewardPool).div(totalTokens);
}

/**
Loading