Skip to content

Commit f04d0d6

Browse files
authored
Fix reputation redeem after ragequit (#730)
* fix rageQuit function * bump version * bool rageQuit to MemberFund
1 parent 6d8986f commit f04d0d6

File tree

4 files changed

+24
-17
lines changed

4 files changed

+24
-17
lines changed

contracts/schemes/JoinAndQuit.sol

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -53,8 +53,13 @@ contract JoinAndQuit is
5353
uint256 funding;
5454
}
5555

56+
struct MemberFund {
57+
bool rageQuit;
58+
uint256 funding;
59+
}
60+
5661
mapping(bytes32=>Proposal) public proposals;
57-
mapping(address=>uint256) public fundings;
62+
mapping(address=>MemberFund) public fundings;
5863

5964
IntVoteInterface public votingMachine;
6065
bytes32 public voteParams;
@@ -125,7 +130,7 @@ contract JoinAndQuit is
125130
} else {
126131
address(fundingToken).safeTransfer(address(avatar), proposal.funding);
127132
}
128-
fundings[proposal.proposedMember] = proposal.funding;
133+
fundings[proposal.proposedMember].funding = proposal.funding;
129134
totalDonation = totalDonation.add(proposal.funding);
130135
setFundingGoalReachedFlag();
131136
} else {
@@ -196,6 +201,7 @@ contract JoinAndQuit is
196201
Proposal memory _proposal = proposals[_proposalId];
197202
Proposal storage proposal = proposals[_proposalId];
198203
require(proposal.proposedMember != address(0), "no member to redeem");
204+
require(!fundings[proposal.proposedMember].rageQuit, "member already rageQuit");
199205
//set proposal proposedMember to zero to prevent reentrancy attack.
200206
proposal.proposedMember = address(0);
201207
require(proposal.accepted == true, " proposal not accepted");
@@ -218,9 +224,10 @@ contract JoinAndQuit is
218224
* @return refund the refund amount
219225
*/
220226
function rageQuit() public returns(uint256 refund) {
221-
require(fundings[msg.sender] > 0, "no fund to RageQuit");
222-
uint256 userDonation = fundings[msg.sender];
223-
fundings[msg.sender] = 0;
227+
require(fundings[msg.sender].funding > 0, "no fund to RageQuit");
228+
uint256 userDonation = fundings[msg.sender].funding;
229+
fundings[msg.sender].funding = 0;
230+
fundings[msg.sender].rageQuit = true;
224231
if (fundingToken == IERC20(0)) {
225232
refund = userDonation.mul(address(avatar.vault()).balance).div(totalDonation);
226233
require(

package-lock.json

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@daostack/arc-experimental",
3-
"version": "0.1.1-rc.10",
3+
"version": "0.1.1-rc.11",
44
"description": "A platform for building DAOs",
55
"files": [
66
"contracts/",

test/joinandquit.js

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -244,7 +244,7 @@ contract('JoinAndQuit', accounts => {
244244
assert.equal(proposal.accepted,true);
245245
assert.equal(await testSetup.standardTokenMock.balanceOf(testSetup.org.avatar.address),testSetup.minFeeToJoin);
246246
assert.equal(await testSetup.standardTokenMock.balanceOf(testSetup.joinAndQuit.address),0);
247-
assert.equal(await testSetup.joinAndQuit.fundings(accounts[3]),testSetup.minFeeToJoin);
247+
assert.equal((await testSetup.joinAndQuit.fundings(accounts[3])).funding,testSetup.minFeeToJoin);
248248
});
249249

250250
it("execute proposeJoinAndQuit yes with eth", async function() {
@@ -261,7 +261,7 @@ contract('JoinAndQuit', accounts => {
261261
assert.equal(proposal.accepted,true);
262262
assert.equal(await avatarBalance(testSetup),testSetup.minFeeToJoin);
263263
assert.equal(await web3.eth.getBalance(testSetup.joinAndQuit.address),0);
264-
assert.equal(await testSetup.joinAndQuit.fundings(accounts[3]),testSetup.minFeeToJoin);
264+
assert.equal((await testSetup.joinAndQuit.fundings(accounts[3])).funding,testSetup.minFeeToJoin);
265265
});
266266

267267
it("execute proposeJoinAndQuit no", async function() {
@@ -279,7 +279,7 @@ contract('JoinAndQuit', accounts => {
279279
assert.equal(proposal.accepted,false);
280280
assert.equal(await testSetup.standardTokenMock.balanceOf(testSetup.org.avatar.address),0);
281281
assert.equal(await testSetup.standardTokenMock.balanceOf(testSetup.joinAndQuit.address),0);
282-
assert.equal(await testSetup.joinAndQuit.fundings(accounts[3]),0);
282+
assert.equal((await testSetup.joinAndQuit.fundings(accounts[3])).funding,0);
283283
assert.equal(await testSetup.standardTokenMock.balanceOf(accounts[3]),10000);
284284
});
285285

@@ -299,7 +299,7 @@ contract('JoinAndQuit', accounts => {
299299
assert.equal(proposal.accepted,false);
300300
assert.equal(await avatarBalance(testSetup),0);
301301
assert.equal(await web3.eth.getBalance(testSetup.joinAndQuit.address),0);
302-
assert.equal(await testSetup.joinAndQuit.fundings(accounts[3]),0);
302+
assert.equal((await testSetup.joinAndQuit.fundings(accounts[3])).funding,0);
303303
var BN = web3.utils.BN;
304304
var a = new BN(balanceBefore);
305305
var b = new BN(testSetup.minFeeToJoin);
@@ -361,11 +361,11 @@ contract('JoinAndQuit', accounts => {
361361
var proposalId = await helpers.getValueFromLogs(tx, '_proposalId',1);
362362
await testSetup.joinAndQuitParams.votingMachine.absoluteVote.vote(proposalId,1,0,helpers.NULL_ADDRESS,{from:accounts[2]});
363363
assert.equal(await testSetup.standardTokenMock.balanceOf(testSetup.org.avatar.address),testSetup.minFeeToJoin);
364-
assert.equal(await testSetup.joinAndQuit.fundings(accounts[3]),testSetup.minFeeToJoin);
364+
assert.equal((await testSetup.joinAndQuit.fundings(accounts[3])).funding,testSetup.minFeeToJoin);
365365
await testSetup.joinAndQuit.rageQuit({from:accounts[3]});
366366
assert.equal(await testSetup.standardTokenMock.balanceOf(testSetup.joinAndQuit.address),0);
367367
assert.equal(await testSetup.standardTokenMock.balanceOf(testSetup.org.avatar.address),0);
368-
assert.equal(await testSetup.joinAndQuit.fundings(accounts[3]),0);
368+
assert.equal((await testSetup.joinAndQuit.fundings(accounts[3])).funding,0);
369369
try {
370370
await testSetup.joinAndQuit.rageQuit({from:accounts[3]});
371371
assert(false, 'cannot rage quite twice without refunding');
@@ -384,7 +384,7 @@ contract('JoinAndQuit', accounts => {
384384
await addMember(accounts,testSetup,500,accounts[4]);
385385

386386
assert.equal(await testSetup.standardTokenMock.balanceOf(testSetup.org.avatar.address),900);
387-
assert.equal(await testSetup.joinAndQuit.fundings(accounts[0]),300);
387+
assert.equal((await testSetup.joinAndQuit.fundings(accounts[0])).funding,300);
388388
assert.equal(await testSetup.joinAndQuit.totalDonation(),900);
389389
tx = await testSetup.joinAndQuit.rageQuit({from:accounts[0]});
390390
assert.equal(tx.logs[0].event, "RageQuit");
@@ -406,11 +406,11 @@ contract('JoinAndQuit', accounts => {
406406
var proposalId = await helpers.getValueFromLogs(tx, '_proposalId',1);
407407
await testSetup.joinAndQuitParams.votingMachine.absoluteVote.vote(proposalId,1,0,helpers.NULL_ADDRESS,{from:accounts[2]});
408408
assert.equal(await avatarBalance(testSetup),testSetup.minFeeToJoin);
409-
assert.equal(await testSetup.joinAndQuit.fundings(accounts[3]),testSetup.minFeeToJoin);
409+
assert.equal((await testSetup.joinAndQuit.fundings(accounts[3])).funding,testSetup.minFeeToJoin);
410410
await testSetup.joinAndQuit.rageQuit({from:accounts[3]});
411411
assert.equal(await web3.eth.getBalance(testSetup.joinAndQuit.address),0);
412412
assert.equal(await avatarBalance(testSetup),0);
413-
assert.equal(await testSetup.joinAndQuit.fundings(accounts[3]),0);
413+
assert.equal((await testSetup.joinAndQuit.fundings(accounts[3])).funding,0);
414414

415415
try {
416416
await testSetup.joinAndQuit.rageQuit({from:accounts[3]});
@@ -424,7 +424,7 @@ contract('JoinAndQuit', accounts => {
424424
await addMember(accounts,testSetup,500,accounts[4]);
425425

426426
assert.equal(await avatarBalance(testSetup),900);
427-
assert.equal(await testSetup.joinAndQuit.fundings(accounts[0]),300);
427+
assert.equal((await testSetup.joinAndQuit.fundings(accounts[0])).funding,300);
428428
assert.equal(await testSetup.joinAndQuit.totalDonation(),900);
429429
tx = await testSetup.joinAndQuit.rageQuit({from:accounts[0]});
430430
assert.equal(tx.logs[0].event, "RageQuit");

0 commit comments

Comments
 (0)