Skip to content

Commit

Permalink
fix - totalDonation decrease order (#776)
Browse files Browse the repository at this point in the history
* fix - totalDonation decrease order

* more updates

* require acceptance at ragequit

* tests coverage

* remove member accepted

* use infra 21

* solc 0.6.12
  • Loading branch information
orenyodfat authored Jul 30, 2020
1 parent 5b7720f commit 4ea1138
Show file tree
Hide file tree
Showing 70 changed files with 689 additions and 506 deletions.
2 changes: 1 addition & 1 deletion .solhint.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,6 @@
"two-lines-top-level-separator": "off",
"mark-callable-contracts": "off",
"reason-string": "off",
"compiler-version": ["error","^0.6.10"]
"compiler-version": ["error","^0.6.12"]
}
}
2 changes: 1 addition & 1 deletion buidler.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ module.exports = {
}
},
solc: {
version: "0.6.10", // Fetch exact version from solc-bin (default: truffle's version)
version: "0.6.12", // Fetch exact version from solc-bin (default: truffle's version)
optimizer: {
enabled: true,
runs: 200
Expand Down
2 changes: 1 addition & 1 deletion contracts/controller/Avatar.sol
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
pragma solidity ^0.6.10;
pragma solidity ^0.6.12;
// SPDX-License-Identifier: GPL-3.0

import "@daostack/infra-experimental/contracts/Reputation.sol";
Expand Down
2 changes: 1 addition & 1 deletion contracts/controller/Controller.sol
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
pragma solidity ^0.6.10;
pragma solidity ^0.6.12;
// SPDX-License-Identifier: GPL-3.0

import "./Avatar.sol";
Expand Down
2 changes: 1 addition & 1 deletion contracts/controller/DAOToken.sol
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
pragma solidity ^0.6.10;
pragma solidity ^0.6.12;
// SPDX-License-Identifier: GPL-3.0

import "@openzeppelin/contracts-ethereum-package/contracts/token/ERC20/ERC20Burnable.sol";
Expand Down
2 changes: 1 addition & 1 deletion contracts/controller/Vault.sol
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
pragma solidity ^0.6.10;
pragma solidity ^0.6.12;
// SPDX-License-Identifier: GPL-3.0

import "@openzeppelin/contracts-ethereum-package/contracts/access/Ownable.sol";
Expand Down
2 changes: 1 addition & 1 deletion contracts/globalConstraints/GlobalConstraintInterface.sol
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
pragma solidity ^0.6.10;
pragma solidity ^0.6.12;
// SPDX-License-Identifier: GPL-3.0

// solhint-disable-next-line indent
Expand Down
2 changes: 1 addition & 1 deletion contracts/globalConstraints/TokenCapGC.sol
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
pragma solidity ^0.6.10;
pragma solidity ^0.6.12;
// SPDX-License-Identifier: GPL-3.0

import "@openzeppelin/contracts-ethereum-package/contracts/token/ERC20/IERC20.sol";
Expand Down
2 changes: 1 addition & 1 deletion contracts/libs/Bytes32ToStr.sol
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
pragma solidity ^0.6.10;
pragma solidity ^0.6.12;
// SPDX-License-Identifier: GPL-3.0

library Bytes32ToStr {
Expand Down
2 changes: 1 addition & 1 deletion contracts/libs/BytesLib.sol
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
* The library lets you concatenate, slice and type cast bytes arrays both in memory and storage.
*/

pragma solidity ^0.6.10;
pragma solidity ^0.6.12;
// SPDX-License-Identifier: GPL-3.0


Expand Down
2 changes: 1 addition & 1 deletion contracts/libs/StringUtil.sol
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
pragma solidity ^0.6.10;
pragma solidity ^0.6.12;
// SPDX-License-Identifier: GPL-3.0


Expand Down
2 changes: 1 addition & 1 deletion contracts/misc/CommonToken.sol
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
pragma solidity ^0.6.10;
pragma solidity ^0.6.12;
// SPDX-License-Identifier: GPL-3.0

import "@openzeppelin/contracts-ethereum-package/contracts/token/ERC20/ERC20.sol";
Expand Down
2 changes: 1 addition & 1 deletion contracts/misc/NFTManager.sol
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
pragma solidity ^0.6.10;
pragma solidity ^0.6.12;
// SPDX-License-Identifier: GPL-3.0

import "@openzeppelin/contracts-ethereum-package/contracts/token/ERC721/IERC721.sol";
Expand Down
2 changes: 1 addition & 1 deletion contracts/misc/NectarRepAllocation.sol
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
pragma solidity ^0.6.10;
pragma solidity ^0.6.12;
// SPDX-License-Identifier: GPL-3.0

import "@openzeppelin/contracts-ethereum-package/contracts/math/SafeMath.sol";
Expand Down
2 changes: 1 addition & 1 deletion contracts/misc/PolkaCurve.sol
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
pragma solidity ^0.6.10;
pragma solidity ^0.6.12;
// SPDX-License-Identifier: GPL-3.0

import "../schemes/CurveInterface.sol";
Expand Down
2 changes: 1 addition & 1 deletion contracts/registry/App.sol
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
pragma solidity ^0.6.10;
pragma solidity ^0.6.12;
// SPDX-License-Identifier: GPL-3.0

import "./ImplementationProvider.sol";
Expand Down
2 changes: 1 addition & 1 deletion contracts/registry/ImplementationDirectory.sol
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
pragma solidity ^0.6.10;
pragma solidity ^0.6.12;
// SPDX-License-Identifier: GPL-3.0

import "./ImplementationProvider.sol";
Expand Down
2 changes: 1 addition & 1 deletion contracts/registry/ImplementationProvider.sol
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
pragma solidity ^0.6.10;
pragma solidity ^0.6.12;
// SPDX-License-Identifier: GPL-3.0


Expand Down
2 changes: 1 addition & 1 deletion contracts/registry/Package.sol
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
pragma solidity ^0.6.10;
pragma solidity ^0.6.12;
// SPDX-License-Identifier: GPL-3.0

import "@daostack/upgrades/contracts/ownership/Ownable.sol";
Expand Down
2 changes: 1 addition & 1 deletion contracts/schemes/Agreement.sol
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
pragma solidity ^0.6.10;
pragma solidity ^0.6.12;
// SPDX-License-Identifier: GPL-3.0

/**
Expand Down
2 changes: 1 addition & 1 deletion contracts/schemes/ArcScheme.sol
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
pragma solidity ^0.6.10;
pragma solidity ^0.6.12;
// SPDX-License-Identifier: GPL-3.0

import "../controller/Avatar.sol";
Expand Down
2 changes: 1 addition & 1 deletion contracts/schemes/Auction4Reputation.sol
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
pragma solidity ^0.6.10;
pragma solidity ^0.6.12;
// SPDX-License-Identifier: GPL-3.0

import "@openzeppelin/contracts-ethereum-package/contracts/math/SafeMath.sol";
Expand Down
2 changes: 1 addition & 1 deletion contracts/schemes/CommonInterface.sol
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
pragma solidity ^0.6.10;
pragma solidity ^0.6.12;
// SPDX-License-Identifier: GPL-3.0


Expand Down
2 changes: 1 addition & 1 deletion contracts/schemes/Competition.sol
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
pragma solidity ^0.6.10;
pragma solidity ^0.6.12;
// SPDX-License-Identifier: GPL-3.0

import "./ContributionRewardExt.sol";
Expand Down
2 changes: 1 addition & 1 deletion contracts/schemes/ContinuousLocking4Reputation.sol
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
pragma solidity ^0.6.10;
pragma solidity ^0.6.12;
// SPDX-License-Identifier: GPL-3.0

import "@openzeppelin/contracts-ethereum-package/contracts/math/SafeMath.sol";
Expand Down
2 changes: 1 addition & 1 deletion contracts/schemes/ContributionReward.sol
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
pragma solidity ^0.6.10;
pragma solidity ^0.6.12;
// SPDX-License-Identifier: GPL-3.0

import "../votingMachines/VotingMachineCallbacks.sol";
Expand Down
2 changes: 1 addition & 1 deletion contracts/schemes/ContributionRewardExt.sol
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
pragma solidity ^0.6.10;
pragma solidity ^0.6.12;
// SPDX-License-Identifier: GPL-3.0

import "../votingMachines/VotingMachineCallbacks.sol";
Expand Down
2 changes: 1 addition & 1 deletion contracts/schemes/ControllerUpgradeScheme.sol
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
pragma solidity ^0.6.10;
pragma solidity ^0.6.12;
// SPDX-License-Identifier: GPL-3.0

import "@daostack/infra-experimental/contracts/votingMachines/IntVoteInterface.sol";
Expand Down
2 changes: 1 addition & 1 deletion contracts/schemes/CurveInterface.sol
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
pragma solidity ^0.6.10;
pragma solidity ^0.6.12;
// SPDX-License-Identifier: GPL-3.0

interface CurveInterface {
Expand Down
2 changes: 1 addition & 1 deletion contracts/schemes/Dictator.sol
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
pragma solidity ^0.6.10;
pragma solidity ^0.6.12;
// SPDX-License-Identifier: GPL-3.0

import "../controller/Avatar.sol";
Expand Down
2 changes: 1 addition & 1 deletion contracts/schemes/ExternalLocking4Reputation.sol
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
pragma solidity ^0.6.10;
pragma solidity ^0.6.12;
// SPDX-License-Identifier: GPL-3.0

import "./Locking4Reputation.sol";
Expand Down
2 changes: 1 addition & 1 deletion contracts/schemes/FixedReputationAllocation.sol
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
pragma solidity ^0.6.10;
pragma solidity ^0.6.12;
// SPDX-License-Identifier: GPL-3.0

import "../controller/Controller.sol";
Expand Down
2 changes: 1 addition & 1 deletion contracts/schemes/FundingRequest.sol
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
pragma solidity ^0.6.10;
pragma solidity ^0.6.12;
// SPDX-License-Identifier: GPL-3.0

import "../votingMachines/VotingMachineCallbacks.sol";
Expand Down
2 changes: 1 addition & 1 deletion contracts/schemes/GenericScheme.sol
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
pragma solidity ^0.6.10;
pragma solidity ^0.6.12;
// SPDX-License-Identifier: GPL-3.0

import "@daostack/infra-experimental/contracts/votingMachines/IntVoteInterface.sol";
Expand Down
2 changes: 1 addition & 1 deletion contracts/schemes/GlobalConstraintRegistrar.sol
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
pragma solidity ^0.6.10;
pragma solidity ^0.6.12;
// SPDX-License-Identifier: GPL-3.0

import "@daostack/infra-experimental/contracts/votingMachines/IntVoteInterface.sol";
Expand Down
25 changes: 15 additions & 10 deletions contracts/schemes/JoinAndQuit.sol
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
pragma solidity ^0.6.10;
pragma solidity ^0.6.12;
// SPDX-License-Identifier: GPL-3.0

import "../votingMachines/VotingMachineCallbacks.sol";
Expand Down Expand Up @@ -53,9 +53,10 @@ contract JoinAndQuit is
event ProposalExecuted(address indexed _avatar, bytes32 indexed _proposalId, int256 _decision);

struct Proposal {
bool accepted;
address proposedMember;
uint256 funding;
bool executed;
bool accepted;
}

struct MemberFund {
Expand Down Expand Up @@ -124,22 +125,25 @@ contract JoinAndQuit is
onlyVotingMachine(_proposalId)
override
returns(bool) {
require(proposals[_proposalId].accepted == false);
require(proposals[_proposalId].proposedMember != address(0));
Proposal memory proposal = proposals[_proposalId];
require(proposal.proposedMember != address(0), "not a valid proposal");
require(proposal.executed == false, "proposal already been executed");
proposals[_proposalId].executed = true;

bool success;
// Check if vote was successful:
if ((_decision == 1) && (avatar.nativeReputation().balanceOf(proposal.proposedMember) == 0)) {
proposals[_proposalId].accepted = true;
fundings[proposal.proposedMember].funding = proposal.funding;
totalDonation = totalDonation.add(proposal.funding);
if (fundingToken == IERC20(0)) {
// solhint-disable-next-line
(success, ) = address(avatar).call{value:proposal.funding}("");
require(success, "sendEther to avatar failed");
} else {
fundingToken.safeTransfer(address(avatar), proposal.funding);
}
fundings[proposal.proposedMember].funding = proposal.funding;
totalDonation = totalDonation.add(proposal.funding);
//this should be called/check after the transfer to the avatar.
setFundingGoalReachedFlag();
} else {
if (fundingToken == IERC20(0)) {
Expand Down Expand Up @@ -182,9 +186,10 @@ contract JoinAndQuit is
bytes32 proposalId = votingMachine.propose(2, voteParamsHash, proposer, address(avatar));

Proposal memory proposal = Proposal({
accepted: false,
executed: false,
proposedMember: proposer,
funding : _feeAmount
funding : _feeAmount,
accepted: false
});
proposals[proposalId] = proposal;

Expand All @@ -210,9 +215,9 @@ contract JoinAndQuit is
Proposal storage proposal = proposals[_proposalId];
require(proposal.proposedMember != address(0), "no member to redeem");
require(!fundings[proposal.proposedMember].rageQuit, "member already rageQuit");
require(proposal.accepted == true, " proposal not accepted");
//set proposal proposedMember to zero to prevent reentrancy attack.
proposal.proposedMember = address(0);
require(proposal.accepted == true, " proposal not accepted");
if (memberReputation == 0) {
reputation = _proposal.funding;
} else {
Expand Down Expand Up @@ -258,12 +263,12 @@ contract JoinAndQuit is
} else {
refundAmount = userDonation.mul(fundingToken.balanceOf(address(avatar))).div(totalDonation);
}
totalDonation = totalDonation.sub(userDonation);
sendToBeneficiary(refundAmount, msg.sender);
uint256 msgSenderReputation = avatar.nativeReputation().balanceOf(msg.sender);
require(
Controller(
avatar.owner()).burnReputation(msgSenderReputation, msg.sender));
totalDonation = totalDonation.sub(userDonation);
emit RageQuit(address(avatar), msg.sender, refundAmount);
}

Expand Down
2 changes: 1 addition & 1 deletion contracts/schemes/Locking4Reputation.sol
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
pragma solidity ^0.6.10;
pragma solidity ^0.6.12;
// SPDX-License-Identifier: GPL-3.0

import "../controller/Controller.sol";
Expand Down
2 changes: 1 addition & 1 deletion contracts/schemes/LockingEth4Reputation.sol
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
pragma solidity ^0.6.10;
pragma solidity ^0.6.12;
// SPDX-License-Identifier: GPL-3.0

import "./Locking4Reputation.sol";
Expand Down
2 changes: 1 addition & 1 deletion contracts/schemes/LockingToken4Reputation.sol
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
pragma solidity ^0.6.10;
pragma solidity ^0.6.12;
// SPDX-License-Identifier: GPL-3.0

import "./Locking4Reputation.sol";
Expand Down
2 changes: 1 addition & 1 deletion contracts/schemes/PriceOracleInterface.sol
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
pragma solidity ^0.6.10;
pragma solidity ^0.6.12;
// SPDX-License-Identifier: GPL-3.0

interface PriceOracleInterface {
Expand Down
2 changes: 1 addition & 1 deletion contracts/schemes/ReputationAdmin.sol
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
pragma solidity 0.6.10;
pragma solidity 0.6.12;
// SPDX-License-Identifier: GPL-3.0

import "@openzeppelin/contracts-ethereum-package/contracts/access/Ownable.sol";
Expand Down
2 changes: 1 addition & 1 deletion contracts/schemes/ReputationFromToken.sol
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
pragma solidity ^0.6.10;
pragma solidity ^0.6.12;
// SPDX-License-Identifier: GPL-3.0

import "../controller/Controller.sol";
Expand Down
2 changes: 1 addition & 1 deletion contracts/schemes/SchemeFactory.sol
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
pragma solidity ^0.6.10;
pragma solidity ^0.6.12;
// SPDX-License-Identifier: GPL-3.0

import "@daostack/infra-experimental/contracts/votingMachines/IntVoteInterface.sol";
Expand Down
2 changes: 1 addition & 1 deletion contracts/schemes/SchemeRegistrar.sol
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
pragma solidity ^0.6.10;
pragma solidity ^0.6.12;
// SPDX-License-Identifier: GPL-3.0

import "@daostack/infra-experimental/contracts/votingMachines/VotingMachineCallbacksInterface.sol";
Expand Down
2 changes: 1 addition & 1 deletion contracts/schemes/SignalScheme.sol
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
pragma solidity ^0.6.10;
pragma solidity ^0.6.12;
// SPDX-License-Identifier: GPL-3.0

import "@daostack/infra-experimental/contracts/votingMachines/IntVoteInterface.sol";
Expand Down
2 changes: 1 addition & 1 deletion contracts/schemes/TokenTrade.sol
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
pragma solidity ^0.6.10;
pragma solidity ^0.6.12;
// SPDX-License-Identifier: GPL-3.0

import "../votingMachines/VotingMachineCallbacks.sol";
Expand Down
2 changes: 1 addition & 1 deletion contracts/schemes/UpgradeScheme.sol
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
pragma solidity ^0.6.10;
pragma solidity ^0.6.12;
// SPDX-License-Identifier: GPL-3.0

import "@daostack/infra-experimental/contracts/votingMachines/IntVoteInterface.sol";
Expand Down
2 changes: 1 addition & 1 deletion contracts/schemes/VoteInOrganizationScheme.sol
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
pragma solidity ^0.6.10;
pragma solidity ^0.6.12;
// SPDX-License-Identifier: GPL-3.0

import "../votingMachines/VotingMachineCallbacks.sol";
Expand Down
2 changes: 1 addition & 1 deletion contracts/test/ARCDebug.sol
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
pragma solidity ^0.6.10;
pragma solidity ^0.6.12;
// SPDX-License-Identifier: GPL-3.0

import "@daostack/infra-experimental/contracts/votingMachines/GenesisProtocol.sol";
Expand Down
2 changes: 1 addition & 1 deletion contracts/test/ARCGenesisProtocolCallbacksMock.sol
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
pragma solidity ^0.6.10;
pragma solidity ^0.6.12;
// SPDX-License-Identifier: GPL-3.0

import "../votingMachines/VotingMachineCallbacks.sol";
Expand Down
2 changes: 1 addition & 1 deletion contracts/test/ActionMock.sol
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
pragma solidity ^0.6.10;
pragma solidity ^0.6.12;
// SPDX-License-Identifier: GPL-3.0

import "../controller/Avatar.sol";
Expand Down
2 changes: 1 addition & 1 deletion contracts/test/AgreementMock.sol
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
pragma solidity ^0.6.10;
pragma solidity ^0.6.12;
// SPDX-License-Identifier: GPL-3.0

import "../schemes/Agreement.sol";
Expand Down
Loading

0 comments on commit 4ea1138

Please sign in to comment.