Skip to content

Commit

Permalink
Merge branch 'develop' into hardhat-env-variables
Browse files Browse the repository at this point in the history
  • Loading branch information
samajammin authored Apr 13, 2021
2 parents d88f32b + e57b0d5 commit b4dc5c1
Show file tree
Hide file tree
Showing 49 changed files with 1,113 additions and 5,261 deletions.
4 changes: 2 additions & 2 deletions contracts/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@

Install [zkutil](https://github.com/poma/zkutil) (see instructions in [MACI readme](https://github.com/appliedzkp/maci#get-started)).

Download [zkSNARK parameters](https://ipfs.io/ipfs/QmeBhtC46dXSEXaemgiAjzpzTxH6FykXDgnTdvHujjPaAR) for 'test' circuits to `snark-params` directory. Example:
Download [zkSNARK parameters](https://gateway.pinata.cloud/ipfs/Qmbi3nqjBwANPMk5BRyKjCJ4QSHK6WNp7v9NLLo4uwrG1f) for 'test' circuits to `snark-params` directory. Example:

```
ipfs get --output snark-params QmeBhtC46dXSEXaemgiAjzpzTxH6FykXDgnTdvHujjPaAR
ipfs get --output snark-params Qmbi3nqjBwANPMk5BRyKjCJ4QSHK6WNp7v9NLLo4uwrG1f
```

Set the path to downloaded parameter files and also the path to `zkutil` binary (if needed):
Expand Down
8 changes: 3 additions & 5 deletions contracts/contracts/FundingRound.sol
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ contract FundingRound is Ownable, MACISharedObjs, SignUpGatekeeper, InitialVoice
}

// State
uint256 public startBlock;
uint256 public voiceCreditFactor;
uint256 public contributorCount;
uint256 public matchingPoolSize;
Expand Down Expand Up @@ -75,7 +74,6 @@ contract FundingRound is Ownable, MACISharedObjs, SignUpGatekeeper, InitialVoice
userRegistry = _userRegistry;
recipientRegistry = _recipientRegistry;
coordinator = _coordinator;
startBlock = block.number;
}

/**
Expand Down Expand Up @@ -316,11 +314,11 @@ contract FundingRound is Ownable, MACISharedObjs, SignUpGatekeeper, InitialVoice
require(spentVerified, 'FundingRound: Incorrect amount of spent voice credits');
}
recipients[_voteOptionIndex] = true;
uint256 startTime = maci.signUpTimestamp();
address recipient = recipientRegistry.getRecipientAddress(
_voteOptionIndex,
startBlock,
// TODO: use block numbers in MACI
startBlock + (maci.signUpDurationSeconds() + maci.votingDurationSeconds()) / 15
startTime,
startTime + maci.signUpDurationSeconds() + maci.votingDurationSeconds()
);
if (recipient == address(0)) {
// Send funds back to the matching pool
Expand Down
20 changes: 20 additions & 0 deletions contracts/contracts/FundingRoundFactory.sol
Original file line number Diff line number Diff line change
Expand Up @@ -169,12 +169,32 @@ contract FundingRoundFactory is Ownable, MACISharedObjs {
MACI maci = maciFactory.deployMaci(
SignUpGatekeeper(newRound),
InitialVoiceCreditProxy(newRound),
coordinator,
coordinatorPubKey
);
newRound.setMaci(maci);
emit RoundStarted(address(newRound));
}

/**
* @dev Get total amount of matching funds.
*/
function getMatchingFunds(ERC20 token)
external
view
returns (uint256)
{
uint256 matchingPoolSize = token.balanceOf(address(this));
for (uint256 index = 0; index < fundingSources.length(); index++) {
address fundingSource = fundingSources.at(index);
uint256 allowance = token.allowance(fundingSource, address(this));
uint256 balance = token.balanceOf(fundingSource);
uint256 contribution = allowance < balance ? allowance : balance;
matchingPoolSize += contribution;
}
return matchingPoolSize;
}

/**
* @dev Transfer funds from matching pool to current funding round and finalize it.
* @param _totalSpent Total amount of spent voice credits.
Expand Down
4 changes: 3 additions & 1 deletion contracts/contracts/MACIFactory.sol
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,7 @@ contract MACIFactory is Ownable, MACIParameters, MACISharedObjs {
function deployMaci(
SignUpGatekeeper _signUpGatekeeper,
InitialVoiceCreditProxy _initialVoiceCreditProxy,
address _coordinator,
PubKey calldata _coordinatorPubKey
)
external
Expand All @@ -138,7 +139,8 @@ contract MACIFactory is Ownable, MACIParameters, MACISharedObjs {
signUpDuration,
votingDuration,
_initialVoiceCreditProxy,
_coordinatorPubKey
_coordinatorPubKey,
_coordinator
);
emit MaciDeployed(address(_maci));
}
Expand Down
16 changes: 8 additions & 8 deletions contracts/contracts/recipientRegistry/BaseRecipientRegistry.sol
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ abstract contract BaseRecipientRegistry is IRecipientRegistry {
recipientIndex = recipients[removedRecipient].index;
slots[recipientIndex - 1].push(_recipientId);
}
recipients[_recipientId] = Recipient(_recipient, recipientIndex, block.number, 0);
recipients[_recipientId] = Recipient(_recipient, recipientIndex, block.timestamp, 0);
return recipientIndex;
}

Expand All @@ -90,21 +90,21 @@ abstract contract BaseRecipientRegistry is IRecipientRegistry {
{
require(recipients[_recipientId].index != 0, 'RecipientRegistry: Recipient is not in the registry');
require(recipients[_recipientId].removedAt == 0, 'RecipientRegistry: Recipient already removed');
recipients[_recipientId].removedAt = block.number;
recipients[_recipientId].removedAt = block.timestamp;
removed.push(_recipientId);
}

/**
* @dev Get recipient address by index.
* @param _index Recipient index.
* @param _startBlock Starting block of the funding round.
* @param _endBlock Ending block of the funding round.
* @param _startTime The start time of the funding round.
* @param _endTime The end time of the funding round.
* @return Recipient address.
*/
function getRecipientAddress(
uint256 _index,
uint256 _startBlock,
uint256 _endBlock
uint256 _startTime,
uint256 _endTime
)
override
external
Expand All @@ -123,11 +123,11 @@ abstract contract BaseRecipientRegistry is IRecipientRegistry {
for (uint256 idx = history.length; idx > 0; idx--) {
bytes32 recipientId = history[idx - 1];
Recipient memory recipient = recipients[recipientId];
if (recipient.addedAt > _endBlock) {
if (recipient.addedAt > _endTime) {
// Recipient added after the end of the funding round, skip
continue;
}
else if (recipient.removedAt != 0 && recipient.removedAt <= _startBlock) {
else if (recipient.removedAt != 0 && recipient.removedAt <= _startTime) {
// Recipient had been already removed when the round started
// Stop search because subsequent items were removed even earlier
return prevRecipientAddress;
Expand Down
16 changes: 12 additions & 4 deletions contracts/contracts/recipientRegistry/KlerosGTCRAdapter.sol
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,16 @@ contract KlerosGTCRAdapter is BaseRecipientRegistry {
IKlerosGTCR public tcr;

// Events
event RecipientAdded(bytes32 indexed _tcrItemId, bytes _metadata, uint256 _index);
event RecipientRemoved(bytes32 indexed _tcrItemId);
event RecipientAdded(
bytes32 indexed _tcrItemId,
bytes _metadata,
uint256 _index,
uint256 _timestamp
);
event RecipientRemoved(
bytes32 indexed _tcrItemId,
uint256 _timestamp
);

/**
* @dev Deploy the registry.
Expand Down Expand Up @@ -54,7 +62,7 @@ contract KlerosGTCRAdapter is BaseRecipientRegistry {
// Recipient address is at index 1
address recipientAddress = recipientData[1].toAddress();
uint256 recipientIndex = _addRecipient(_tcrItemId, recipientAddress);
emit RecipientAdded(_tcrItemId, rlpData, recipientIndex);
emit RecipientAdded(_tcrItemId, rlpData, recipientIndex, block.timestamp);
}

/**
Expand All @@ -67,6 +75,6 @@ contract KlerosGTCRAdapter is BaseRecipientRegistry {
(,uint256 status,) = tcr.getItemInfo(_tcrItemId);
require(status == STATUS_ABSENT, 'RecipientRegistry: Item is not removed from TCR');
_removeRecipient(_tcrItemId);
emit RecipientRemoved(_tcrItemId);
emit RecipientRemoved(_tcrItemId, block.timestamp);
}
}
2 changes: 1 addition & 1 deletion contracts/contracts/recipientRegistry/KlerosGTCRMock.sol
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ contract KlerosGTCRMock is Ownable {
itemList.push(itemID);
itemIDtoIndex[itemID] = itemList.length - 1;
emit ItemSubmitted(itemID, msg.sender, 0, item.data);
emit ItemStatusChange(itemID, 0, 0, false, false);
emit ItemStatusChange(itemID, 0, 0, false, true);
}

/** @dev Submit a request to remove an item from the list. Accepts enough ETH to cover the deposit, reimburses the rest.
Expand Down
17 changes: 13 additions & 4 deletions contracts/contracts/recipientRegistry/SimpleRecipientRegistry.sol
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,17 @@ import './BaseRecipientRegistry.sol';
contract SimpleRecipientRegistry is Ownable, BaseRecipientRegistry {

// Events
event RecipientAdded(bytes32 indexed _recipientId, address _recipient, string _metadata, uint256 _index);
event RecipientRemoved(bytes32 indexed _recipientId);
event RecipientAdded(
bytes32 indexed _recipientId,
address _recipient,
string _metadata,
uint256 _index,
uint256 _timestamp
);
event RecipientRemoved(
bytes32 indexed _recipientId,
uint256 _timestamp
);

/**
* @dev Deploy the registry.
Expand All @@ -40,7 +49,7 @@ contract SimpleRecipientRegistry is Ownable, BaseRecipientRegistry {
require(bytes(_metadata).length != 0, 'RecipientRegistry: Metadata info is empty string');
bytes32 recipientId = keccak256(abi.encodePacked(_recipient, _metadata));
uint256 recipientIndex = _addRecipient(recipientId, _recipient);
emit RecipientAdded(recipientId, _recipient, _metadata, recipientIndex);
emit RecipientAdded(recipientId, _recipient, _metadata, recipientIndex, block.timestamp);
}

/**
Expand All @@ -52,6 +61,6 @@ contract SimpleRecipientRegistry is Ownable, BaseRecipientRegistry {
onlyOwner
{
_removeRecipient(_recipientId);
emit RecipientRemoved(_recipientId);
emit RecipientRemoved(_recipientId, block.timestamp);
}
}
Loading

0 comments on commit b4dc5c1

Please sign in to comment.