From 73741ff3fe4c49a7279998e1d2a76907bbecfe65 Mon Sep 17 00:00:00 2001 From: Artem Chystiakov Date: Sat, 14 Oct 2023 20:40:15 +0300 Subject: [PATCH 1/4] fix precision --- contracts/libs/gov/gov-pool/GovPoolRewards.sol | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/contracts/libs/gov/gov-pool/GovPoolRewards.sol b/contracts/libs/gov/gov-pool/GovPoolRewards.sol index 52f8b1a6..eebc1304 100644 --- a/contracts/libs/gov/gov-pool/GovPoolRewards.sol +++ b/contracts/libs/gov/gov-pool/GovPoolRewards.sol @@ -281,9 +281,10 @@ library GovPoolRewards { treasuryPercentage ); - delegatorsRewards = - votingRewards.micropool - - votingRewards.micropool.percentage(micropoolPercentage); + delegatorsRewards = votingRewards.micropool.percentage( + PERCENTAGE_100 - micropoolPercentage + ); + votingRewards.micropool -= delegatorsRewards; } } From 8401d1957008db45a253b7dbcf7ccaae9fca17bb Mon Sep 17 00:00:00 2001 From: Artem Chystiakov Date: Sat, 14 Oct 2023 20:45:50 +0300 Subject: [PATCH 2/4] simplified deploy on failure --- deploy/92_GovPoolsSetup.migration.js | 21 ++++++++++----------- 1 file changed, 10 insertions(+), 11 deletions(-) diff --git a/deploy/92_GovPoolsSetup.migration.js b/deploy/92_GovPoolsSetup.migration.js index 4cd7cbb7..5b1aee2a 100644 --- a/deploy/92_GovPoolsSetup.migration.js +++ b/deploy/92_GovPoolsSetup.migration.js @@ -88,26 +88,25 @@ async function linkGovValidators(deployer) { await deployer.link(GovValidatorsExecuteLib, GovValidators); } -async function link(deployer) { - await linkGovUserKeeper(deployer); - await linkGovPool(deployer); - await linkTokenSaleProposal(deployer); - await linkGovValidators(deployer); -} - module.exports = async (deployer, logger) => { const contractsRegistry = await ContractsRegistry.at((await Proxy.deployed()).address); const poolRegistry = await PoolRegistry.at(await contractsRegistry.getPoolRegistryContract()); - await link(deployer); - + await linkGovPool(deployer); const govPool = await deployer.deploy(GovPool); - const govSettings = await deployer.deploy(GovSettings); + + await linkGovValidators(deployer); const govValidators = await deployer.deploy(GovValidators); + + await linkGovUserKeeper(deployer); const govUserKeeper = await deployer.deploy(GovUserKeeper); - const distributionProposal = await deployer.deploy(DistributionProposal); + + await linkTokenSaleProposal(deployer); const tokenSaleProposal = await deployer.deploy(TokenSaleProposal); + + const distributionProposal = await deployer.deploy(DistributionProposal); + const govSettings = await deployer.deploy(GovSettings); const expertNft = await deployer.deploy(ERC721Expert); const nftMultiplier = await deployer.deploy(ERC721Multiplier); const linearPower = await deployer.deploy(LinearPower); From 9a5808c6c40008e14d989463dd6652acf35772f3 Mon Sep 17 00:00:00 2001 From: Artem Chystiakov Date: Sun, 15 Oct 2023 12:28:05 +0300 Subject: [PATCH 3/4] view -> pure --- contracts/libs/gov/gov-pool/GovPoolCreate.sol | 38 +++++++++---------- 1 file changed, 19 insertions(+), 19 deletions(-) diff --git a/contracts/libs/gov/gov-pool/GovPoolCreate.sol b/contracts/libs/gov/gov-pool/GovPoolCreate.sol index 7497f490..3c3b9fd4 100644 --- a/contracts/libs/gov/gov-pool/GovPoolCreate.sol +++ b/contracts/libs/gov/gov-pool/GovPoolCreate.sol @@ -423,25 +423,6 @@ library GovPoolCreate { } } - function _validateDeposit( - IGovPool.ProposalAction calldata actionFor, - IGovPool.ProposalAction calldata actionAgainst, - address metaGovPool - ) internal view { - (uint256 amountFor, uint256[] memory nftIdsFor) = _decodeDepositFunction(actionFor); - (uint256 amountAgainst, uint256[] memory nftIdsAgainst) = _decodeDepositFunction( - actionAgainst - ); - - require(actionFor.executor == metaGovPool, "Gov: invalid executor"); - require(amountFor == amountAgainst, "Gov: invalid amount"); - require(nftIdsFor.length == nftIdsAgainst.length, "Gov: invalid nfts length"); - - for (uint256 i = 0; i < nftIdsFor.length; i++) { - require(nftIdsFor[i] == nftIdsAgainst[i], "Gov: invalid nft deposit"); - } - } - function _validateApprove( IGovPool.ProposalAction calldata actionFor, IGovPool.ProposalAction calldata actionAgainst, @@ -486,6 +467,25 @@ library GovPoolCreate { require(approvedFor == approvedAgainst, "Gov: invalid approve"); } + function _validateDeposit( + IGovPool.ProposalAction calldata actionFor, + IGovPool.ProposalAction calldata actionAgainst, + address metaGovPool + ) internal pure { + (uint256 amountFor, uint256[] memory nftIdsFor) = _decodeDepositFunction(actionFor); + (uint256 amountAgainst, uint256[] memory nftIdsAgainst) = _decodeDepositFunction( + actionAgainst + ); + + require(actionFor.executor == metaGovPool, "Gov: invalid executor"); + require(amountFor == amountAgainst, "Gov: invalid amount"); + require(nftIdsFor.length == nftIdsAgainst.length, "Gov: invalid nfts length"); + + for (uint256 i = 0; i < nftIdsFor.length; i++) { + require(nftIdsFor[i] == nftIdsAgainst[i], "Gov: invalid nft deposit"); + } + } + function _handleDataForValidatorBalanceProposal( IGovPool.ProposalAction[] calldata actions ) internal pure { From 02e0dde26343c98c7bb7211d7d42989daa6b742e Mon Sep 17 00:00:00 2001 From: Artem Chystiakov Date: Mon, 16 Oct 2023 16:27:43 +0300 Subject: [PATCH 4/4] fix micropool rewards --- .../libs/gov/gov-pool/GovPoolMicropool.sol | 8 +++- test/gov/GovPool.test.js | 41 ++++++++++++++----- 2 files changed, 37 insertions(+), 12 deletions(-) diff --git a/contracts/libs/gov/gov-pool/GovPoolMicropool.sol b/contracts/libs/gov/gov-pool/GovPoolMicropool.sol index a94fc474..ce23ed53 100644 --- a/contracts/libs/gov/gov-pool/GovPoolMicropool.sol +++ b/contracts/libs/gov/gov-pool/GovPoolMicropool.sol @@ -142,14 +142,18 @@ library GovPoolMicropool { return 0; } + uint256[] storage timestamps = delegatorInfo.delegationTimes; + uint256 quorumReachedTime = core.executeAfter - core.settings.executionDelay; - uint256 index = delegatorInfo.delegationTimes.lowerBound(quorumReachedTime); + uint256 index = timestamps.lowerBound(quorumReachedTime); if (index == 0) { return 0; } - --index; + if (index == timestamps.length || timestamps[index] != quorumReachedTime) { + --index; + } uint256 delegationAmount = delegatorInfo.tokenAmounts[index] + IGovUserKeeper(userKeeper).getNftsPowerInTokensBySnapshot( diff --git a/test/gov/GovPool.test.js b/test/gov/GovPool.test.js index 1c660034..4ec57b32 100644 --- a/test/gov/GovPool.test.js +++ b/test/gov/GovPool.test.js @@ -556,10 +556,14 @@ describe("GovPool", () => { describe("Fullfat GovPool", () => { let POOL_PARAMETERS; - async function changeInternalSettings(validatorsVote) { + async function changeInternalSettings(validatorsVote, minVotingPower) { let GOV_POOL_SETTINGS = JSON.parse(JSON.stringify(POOL_PARAMETERS.settingsParams.proposalSettings[1])); GOV_POOL_SETTINGS.validatorsVote = validatorsVote; + if (minVotingPower != null) { + GOV_POOL_SETTINGS.minVotesForVoting = minVotingPower; + } + await executeValidatorProposal( [ [settings.address, 0, getBytesAddSettings([GOV_POOL_SETTINGS])], @@ -3990,15 +3994,9 @@ describe("GovPool", () => { "0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF", // balance ]); - await govPool.createProposal( - "example.com", - - [[settings.address, 0, getBytesAddSettings([NEW_SETTINGS])]], - [], - { - from: coreProperties.address, - } - ); + await govPool.createProposal("example.com", [[settings.address, 0, getBytesAddSettings([NEW_SETTINGS])]], [], { + from: coreProperties.address, + }); await govPool.vote(2, true, wei("100000000000000000000"), [], { from: coreProperties.address }); @@ -4283,6 +4281,29 @@ describe("GovPool", () => { ); }); + it("should claim latest rewards", async () => { + await changeInternalSettings(false, 1); + + await govPool.createProposal("example.com", [[govPool.address, 0, getBytesEditUrl("NEW_URL")]], []); + await govPool.vote(3, true, 1, [], { from: SECOND }); + + assert.equal((await govPool.getProposalState(3)).toNumber(), ProposalState.Voting); + + await govPool.delegate(SECOND, 1, [], { from: delegator2 }); + + assert.equal((await govPool.getProposalState(3)).toNumber(), ProposalState.Voting); + + await govPool.delegate(SECOND, wei("300000"), [], { from: delegator2 }); + + assert.equal((await govPool.getProposalState(3)).toNumber(), ProposalState.Locked); + + await govPool.execute(3); + + let delegatorRewardsView = await govPool.getDelegatorRewards([3], delegator2, SECOND); + + assert.equal(delegatorRewardsView.expectedRewards, wei("240000")); + }); + it("should claim rewards properly if multicall delegation and delegator claim first", async () => { let DEFAULT_SETTINGS = POOL_PARAMETERS.settingsParams.proposalSettings[0]; DEFAULT_SETTINGS.validatorsVote = false;