diff --git a/contracts/votingMachines/GenesisProtocolLogic.sol b/contracts/votingMachines/GenesisProtocolLogic.sol index e931589..c5a634e 100644 --- a/contracts/votingMachines/GenesisProtocolLogic.sol +++ b/contracts/votingMachines/GenesisProtocolLogic.sol @@ -538,20 +538,23 @@ contract GenesisProtocolLogic is IntVoteInterface { confidenceThreshold = threshold(proposal.paramsHash, proposal.organizationId); // solhint-disable-next-line not-rely-on-time if ((now - proposal.times[2]) >= params.preBoostedVotePeriodLimit) { - if ((_score(_proposalId) > confidenceThreshold) && - (orgBoostedProposalsCnt[proposal.organizationId] < MAX_BOOSTED_PROPOSALS)) { - //change proposal mode to Boosted mode. - proposal.state = ProposalState.Boosted; - // solhint-disable-next-line not-rely-on-time - proposal.times[1] = now; - orgBoostedProposalsCnt[proposal.organizationId]++; - //add a value to average -> average = average + ((value - average) / nbValues) - averageDownstakesOfBoosted = averagesDownstakesOfBoosted[proposal.organizationId]; - // solium-disable-next-line indentation - averagesDownstakesOfBoosted[proposal.organizationId] = - uint256(int256(averageDownstakesOfBoosted) + - ((int256(proposal.stakes[NO])-int256(averageDownstakesOfBoosted))/ - int256(orgBoostedProposalsCnt[proposal.organizationId]))); + if (_score(_proposalId) > confidenceThreshold) { + if (orgBoostedProposalsCnt[proposal.organizationId] < MAX_BOOSTED_PROPOSALS) { + //change proposal mode to Boosted mode. + proposal.state = ProposalState.Boosted; + // solhint-disable-next-line not-rely-on-time + proposal.times[1] = now; + orgBoostedProposalsCnt[proposal.organizationId]++; + //add a value to average -> average = average + ((value - average) / nbValues) + averageDownstakesOfBoosted = averagesDownstakesOfBoosted[proposal.organizationId]; + // solium-disable-next-line indentation + averagesDownstakesOfBoosted[proposal.organizationId] = + uint256(int256(averageDownstakesOfBoosted) + + ((int256(proposal.stakes[NO])-int256(averageDownstakesOfBoosted))/ + int256(orgBoostedProposalsCnt[proposal.organizationId]))); + } + } else { + proposal.state = ProposalState.Queued; } } else { //check the Confidence level is stable uint256 proposalScore = _score(_proposalId); diff --git a/package-lock.json b/package-lock.json index ddb8a16..bc76ea6 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,6 +1,6 @@ { "name": "@daostack/infra", - "version": "0.0.1-rc.12", + "version": "0.0.1-rc.13", "lockfileVersion": 1, "requires": true, "dependencies": { @@ -56,13 +56,15 @@ "version": "0.3.2", "resolved": "https://registry.npmjs.org/array-unique/-/array-unique-0.3.2.tgz", "integrity": "sha1-qJS3XUvE9s1nnvMkSp/Y9Gri1Cg=", - "dev": true + "dev": true, + "optional": true }, "braces": { "version": "2.3.2", "resolved": "https://registry.npmjs.org/braces/-/braces-2.3.2.tgz", "integrity": "sha512-aNdbnj9P8PjdXU4ybaWLK2IF3jc/EoDYbC7AazW6to3TRsfXxscC9UXOB5iDiEQrkyIbWp2SLQda4+QAa7nc3w==", "dev": true, + "optional": true, "requires": { "arr-flatten": "^1.1.0", "array-unique": "^0.3.2", @@ -81,6 +83,7 @@ "resolved": "https://registry.npmjs.org/extend-shallow/-/extend-shallow-2.0.1.tgz", "integrity": "sha1-Ua99YUrZqfYQ6huvu5idaxxWiQ8=", "dev": true, + "optional": true, "requires": { "is-extendable": "^0.1.0" } @@ -253,6 +256,7 @@ "resolved": "https://registry.npmjs.org/fill-range/-/fill-range-4.0.0.tgz", "integrity": "sha1-1USBHUKPmOsGpj3EAtJAPDKMOPc=", "dev": true, + "optional": true, "requires": { "extend-shallow": "^2.0.1", "is-number": "^3.0.0", @@ -265,6 +269,7 @@ "resolved": "https://registry.npmjs.org/extend-shallow/-/extend-shallow-2.0.1.tgz", "integrity": "sha1-Ua99YUrZqfYQ6huvu5idaxxWiQ8=", "dev": true, + "optional": true, "requires": { "is-extendable": "^0.1.0" } @@ -291,7 +296,8 @@ "ansi-regex": { "version": "2.1.1", "bundled": true, - "dev": true + "dev": true, + "optional": true }, "aproba": { "version": "1.2.0", @@ -312,12 +318,14 @@ "balanced-match": { "version": "1.0.0", "bundled": true, - "dev": true + "dev": true, + "optional": true }, "brace-expansion": { "version": "1.1.11", "bundled": true, "dev": true, + "optional": true, "requires": { "balanced-match": "^1.0.0", "concat-map": "0.0.1" @@ -332,17 +340,20 @@ "code-point-at": { "version": "1.1.0", "bundled": true, - "dev": true + "dev": true, + "optional": true }, "concat-map": { "version": "0.0.1", "bundled": true, - "dev": true + "dev": true, + "optional": true }, "console-control-strings": { "version": "1.1.0", "bundled": true, - "dev": true + "dev": true, + "optional": true }, "core-util-is": { "version": "1.0.2", @@ -459,7 +470,8 @@ "inherits": { "version": "2.0.3", "bundled": true, - "dev": true + "dev": true, + "optional": true }, "ini": { "version": "1.3.5", @@ -471,6 +483,7 @@ "version": "1.0.0", "bundled": true, "dev": true, + "optional": true, "requires": { "number-is-nan": "^1.0.0" } @@ -485,6 +498,7 @@ "version": "3.0.4", "bundled": true, "dev": true, + "optional": true, "requires": { "brace-expansion": "^1.1.7" } @@ -492,12 +506,14 @@ "minimist": { "version": "0.0.8", "bundled": true, - "dev": true + "dev": true, + "optional": true }, "minipass": { "version": "2.3.5", "bundled": true, "dev": true, + "optional": true, "requires": { "safe-buffer": "^5.1.2", "yallist": "^3.0.0" @@ -516,6 +532,7 @@ "version": "0.5.1", "bundled": true, "dev": true, + "optional": true, "requires": { "minimist": "0.0.8" } @@ -596,7 +613,8 @@ "number-is-nan": { "version": "1.0.1", "bundled": true, - "dev": true + "dev": true, + "optional": true }, "object-assign": { "version": "4.1.1", @@ -608,6 +626,7 @@ "version": "1.4.0", "bundled": true, "dev": true, + "optional": true, "requires": { "wrappy": "1" } @@ -693,7 +712,8 @@ "safe-buffer": { "version": "5.1.2", "bundled": true, - "dev": true + "dev": true, + "optional": true }, "safer-buffer": { "version": "2.1.2", @@ -729,6 +749,7 @@ "version": "1.0.2", "bundled": true, "dev": true, + "optional": true, "requires": { "code-point-at": "^1.0.0", "is-fullwidth-code-point": "^1.0.0", @@ -748,6 +769,7 @@ "version": "3.0.1", "bundled": true, "dev": true, + "optional": true, "requires": { "ansi-regex": "^2.0.0" } @@ -791,12 +813,14 @@ "wrappy": { "version": "1.0.2", "bundled": true, - "dev": true + "dev": true, + "optional": true }, "yallist": { "version": "3.0.3", "bundled": true, - "dev": true + "dev": true, + "optional": true } } }, @@ -859,7 +883,8 @@ "version": "2.1.1", "resolved": "https://registry.npmjs.org/is-extglob/-/is-extglob-2.1.1.tgz", "integrity": "sha1-qIwCU1eR8C7TfHahueqXc8gz+MI=", - "dev": true + "dev": true, + "optional": true }, "is-glob": { "version": "4.0.0", @@ -876,6 +901,7 @@ "resolved": "https://registry.npmjs.org/is-number/-/is-number-3.0.0.tgz", "integrity": "sha1-JP1iAaR4LPUFYcgQJ2r8fRLXEZU=", "dev": true, + "optional": true, "requires": { "kind-of": "^3.0.2" }, @@ -885,6 +911,7 @@ "resolved": "https://registry.npmjs.org/kind-of/-/kind-of-3.2.2.tgz", "integrity": "sha1-MeohpzS6ubuw8yRm2JOupR5KPGQ=", "dev": true, + "optional": true, "requires": { "is-buffer": "^1.1.5" } @@ -895,13 +922,15 @@ "version": "3.0.1", "resolved": "https://registry.npmjs.org/isobject/-/isobject-3.0.1.tgz", "integrity": "sha1-TkMekrEalzFjaqH5yNHMvP2reN8=", - "dev": true + "dev": true, + "optional": true }, "kind-of": { "version": "6.0.2", "resolved": "https://registry.npmjs.org/kind-of/-/kind-of-6.0.2.tgz", "integrity": "sha512-s5kLOcnH0XqDO+FvuaLX8DDjZ18CGFk7VygH40QoKPUQhW4e2rvM0rwUq0t8IQDOwYSeLK01U90OjzBTme2QqA==", - "dev": true + "dev": true, + "optional": true }, "micromatch": { "version": "3.1.10", @@ -3678,7 +3707,8 @@ "ansi-regex": { "version": "2.1.1", "bundled": true, - "dev": true + "dev": true, + "optional": true }, "aproba": { "version": "1.2.0", @@ -3699,12 +3729,14 @@ "balanced-match": { "version": "1.0.0", "bundled": true, - "dev": true + "dev": true, + "optional": true }, "brace-expansion": { "version": "1.1.11", "bundled": true, "dev": true, + "optional": true, "requires": { "balanced-match": "^1.0.0", "concat-map": "0.0.1" @@ -3719,17 +3751,20 @@ "code-point-at": { "version": "1.1.0", "bundled": true, - "dev": true + "dev": true, + "optional": true }, "concat-map": { "version": "0.0.1", "bundled": true, - "dev": true + "dev": true, + "optional": true }, "console-control-strings": { "version": "1.1.0", "bundled": true, - "dev": true + "dev": true, + "optional": true }, "core-util-is": { "version": "1.0.2", @@ -3846,7 +3881,8 @@ "inherits": { "version": "2.0.3", "bundled": true, - "dev": true + "dev": true, + "optional": true }, "ini": { "version": "1.3.5", @@ -3858,6 +3894,7 @@ "version": "1.0.0", "bundled": true, "dev": true, + "optional": true, "requires": { "number-is-nan": "^1.0.0" } @@ -3872,6 +3909,7 @@ "version": "3.0.4", "bundled": true, "dev": true, + "optional": true, "requires": { "brace-expansion": "^1.1.7" } @@ -3879,12 +3917,14 @@ "minimist": { "version": "0.0.8", "bundled": true, - "dev": true + "dev": true, + "optional": true }, "minipass": { "version": "2.2.4", "bundled": true, "dev": true, + "optional": true, "requires": { "safe-buffer": "^5.1.1", "yallist": "^3.0.0" @@ -3903,6 +3943,7 @@ "version": "0.5.1", "bundled": true, "dev": true, + "optional": true, "requires": { "minimist": "0.0.8" } @@ -3983,7 +4024,8 @@ "number-is-nan": { "version": "1.0.1", "bundled": true, - "dev": true + "dev": true, + "optional": true }, "object-assign": { "version": "4.1.1", @@ -3995,6 +4037,7 @@ "version": "1.4.0", "bundled": true, "dev": true, + "optional": true, "requires": { "wrappy": "1" } @@ -4080,7 +4123,8 @@ "safe-buffer": { "version": "5.1.1", "bundled": true, - "dev": true + "dev": true, + "optional": true }, "safer-buffer": { "version": "2.1.2", @@ -4116,6 +4160,7 @@ "version": "1.0.2", "bundled": true, "dev": true, + "optional": true, "requires": { "code-point-at": "^1.0.0", "is-fullwidth-code-point": "^1.0.0", @@ -4135,6 +4180,7 @@ "version": "3.0.1", "bundled": true, "dev": true, + "optional": true, "requires": { "ansi-regex": "^2.0.0" } @@ -4178,12 +4224,14 @@ "wrappy": { "version": "1.0.2", "bundled": true, - "dev": true + "dev": true, + "optional": true }, "yallist": { "version": "3.0.2", "bundled": true, - "dev": true + "dev": true, + "optional": true } } }, @@ -5252,9 +5300,9 @@ "dev": true }, "js-yaml": { - "version": "3.12.0", - "resolved": "https://registry.npmjs.org/js-yaml/-/js-yaml-3.12.0.tgz", - "integrity": "sha512-PIt2cnwmPfL4hKNwqeiuz4bKfnzHTBv6HyVgjahA6mPLwPDzjDWrplJBMjHUFxku/N3FlmrbyPclad+I+4mJ3A==", + "version": "3.13.1", + "resolved": "https://registry.npmjs.org/js-yaml/-/js-yaml-3.13.1.tgz", + "integrity": "sha512-YfbcO7jXDdyj0DGxYVSlSeQNHbD7XPWvrVWeVUujrQEoZzWJIRrCPoyk6kL6IAjAG2IolMK4T0hNUe0HOUs5Jw==", "dev": true, "requires": { "argparse": "^1.0.7", diff --git a/package.json b/package.json index 9025435..13177e9 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@daostack/infra", - "version": "0.0.1-rc.12", + "version": "0.0.1-rc.13", "description": "Base layer DAO's components", "files": [ "contracts/", @@ -83,6 +83,6 @@ "openzeppelin-solidity": "2.1.3" }, "peerDependencies": { - "ganache-cli": "^6.2.5" + "ganache-cli": "^6.4.1" } } diff --git a/test/genesisprotocol.js b/test/genesisprotocol.js index a3f18a4..861a564 100644 --- a/test/genesisprotocol.js +++ b/test/genesisprotocol.js @@ -1620,6 +1620,43 @@ contract('GenesisProtocol', accounts => { assert.equal(proposalInfo[proposalStateIndex],3); //state back to q }); + + it("from prepare for boost back to que after pre boosted time passed", async () => { + + var preBoostedVotePeriodLimit = 60; + var testSetup = await setup(accounts,helpers.NULL_ADDRESS,50,1000,60,preBoostedVotePeriodLimit); + var proposalId = await propose(testSetup); + + var proposalInfo = await testSetup.genesisProtocol.proposals(proposalId); + + await testSetup.genesisProtocol.vote(proposalId,YES,0,helpers.NULL_ADDRESS); + + await stake(testSetup,proposalId,YES,50,accounts[0]); + + proposalInfo = await testSetup.genesisProtocol.proposals(proposalId); + assert.equal(proposalInfo[proposalTotalStakesIndex],50+15); //totalStakes + + assert.equal(proposalInfo[proposalStateIndex],preBoostedState); //state pre boosted + assert.equal(proposalInfo[10],Math.pow(2,REAL_FBITS));//check proposal own threshold + + //boost 2 proposals + let proposalIdTemp; + for (var i=0;i<2;i++) { + proposalIdTemp = await propose(testSetup);//boost a proposal + await testSetup.genesisProtocol.vote(proposalIdTemp,YES,0,helpers.NULL_ADDRESS); + await stake(testSetup,proposalIdTemp,YES,web3.utils.toWei("1500"),accounts[0]); + await helpers.increaseTime(preBoostedVotePeriodLimit+1); + await testSetup.genesisProtocol.execute(proposalIdTemp); + } + + const organizationId = await web3.utils.soliditySha3(testSetup.genesisProtocolCallbacks.address,helpers.NULL_ADDRESS); + assert.equal(await testSetup.genesisProtocol.orgBoostedProposalsCnt(organizationId),2); + assert.equal(proposalInfo[proposalStateIndex],preBoostedState); //state back to q + await stake(testSetup,proposalId,NO,200,accounts[1]); //downstake ... + proposalInfo = await testSetup.genesisProtocol.proposals(proposalId); + assert.equal(proposalInfo[proposalStateIndex],3); //state back to q + }); + it("prepare for boost check high from the minimum threshold", async () => { var preBoostedVotePeriodLimit = 60; @@ -1663,41 +1700,42 @@ contract('GenesisProtocol', accounts => { var preBoostedVotePeriodLimit = 60; var testSetup = await setup(accounts,helpers.NULL_ADDRESS,50,60,60,preBoostedVotePeriodLimit); var proposalId = await propose(testSetup); - - var proposalInfo = await testSetup.genesisProtocol.proposals(proposalId); - - await testSetup.genesisProtocol.vote(proposalId,YES,0,helpers.NULL_ADDRESS); - await stake(testSetup,proposalId,YES,30,accounts[0]); - proposalInfo = await testSetup.genesisProtocol.proposals(proposalId); - assert.equal(proposalInfo[proposalTotalStakesIndex],30+15); //totalStakes + var proposalId2 = await propose(testSetup); + await stake(testSetup, proposalId2, YES, web3.utils.toWei("1500"),accounts[0]); + var proposalId3 = await propose(testSetup); + await stake(testSetup, proposalId3, YES, web3.utils.toWei("1500"),accounts[0]); + var proposalInfo = await testSetup.genesisProtocol.proposals(proposalId2); assert.equal(proposalInfo[proposalStateIndex],preBoostedState); //state pre boosted + await helpers.increaseTime(preBoostedVotePeriodLimit/2); //proposalId2 half pre boosted - //boost another proposal - var proposalId2 = await propose(testSetup); - await testSetup.genesisProtocol.vote(proposalId2,YES,0,helpers.NULL_ADDRESS); - await stake(testSetup,proposalId2,YES,web3.utils.toWei("1500"),accounts[0]); - proposalInfo = await testSetup.genesisProtocol.proposals(proposalId2); + //preboost proposalId + await stake(testSetup,proposalId,YES,60,accounts[0]); + proposalInfo = await testSetup.genesisProtocol.proposals(proposalId); + assert.equal(proposalInfo[proposalTotalStakesIndex],60+15); //totalStakes assert.equal(proposalInfo[proposalStateIndex],preBoostedState); //state pre boosted - await helpers.increaseTime(preBoostedVotePeriodLimit*2); + await helpers.increaseTime(preBoostedVotePeriodLimit/2 +1 ); await testSetup.genesisProtocol.execute(proposalId2); + await testSetup.genesisProtocol.execute(proposalId3); proposalInfo = await testSetup.genesisProtocol.proposals(proposalId2); assert.equal(proposalInfo[proposalStateIndex],boostedState); //state boosted //proposalId2 is now boosted const organizationId = await web3.utils.soliditySha3(testSetup.genesisProtocolCallbacks.address,helpers.NULL_ADDRESS); - assert.equal(await testSetup.genesisProtocol.orgBoostedProposalsCnt(organizationId),1); + assert.equal(await testSetup.genesisProtocol.orgBoostedProposalsCnt(organizationId),2); //try to execute proposalId await testSetup.genesisProtocol.execute(proposalId); proposalInfo = await testSetup.genesisProtocol.proposals(proposalId); assert.equal(proposalInfo[proposalStateIndex],preBoostedState); //still preBoosted - assert.equal(await threshold(testSetup),2); + assert.equal(await threshold(testSetup),4); var proposalStatus = await testSetup.genesisProtocol.proposalStatus(proposalId); - assert.equal(proposalStatus[2],30); + assert.equal(proposalStatus[2],60); assert.equal(proposalStatus[3],15); await stake(testSetup,proposalId,YES,web3.utils.toWei("3000"),accounts[0]); + await helpers.increaseTime(preBoostedVotePeriodLimit/2 +1 ); + await testSetup.genesisProtocol.execute(proposalId); proposalInfo = await testSetup.genesisProtocol.proposals(proposalId); assert.equal(proposalInfo[proposalStateIndex],boostedState); //now it is boosted