Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/dev' into feat/shperex
Browse files Browse the repository at this point in the history
  • Loading branch information
dovgopoly committed Oct 16, 2023
2 parents 8ab403f + 02e0dde commit 8ab9506
Show file tree
Hide file tree
Showing 5 changed files with 70 additions and 45 deletions.
38 changes: 19 additions & 19 deletions contracts/libs/gov/gov-pool/GovPoolCreate.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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 {
Expand Down
8 changes: 6 additions & 2 deletions contracts/libs/gov/gov-pool/GovPoolMicropool.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
7 changes: 4 additions & 3 deletions contracts/libs/gov/gov-pool/GovPoolRewards.sol
Original file line number Diff line number Diff line change
Expand Up @@ -281,9 +281,10 @@ library GovPoolRewards {
treasuryPercentage
);

delegatorsRewards =
votingRewards.micropool -
votingRewards.micropool.percentage(micropoolPercentage);
delegatorsRewards = votingRewards.micropool.percentage(
PERCENTAGE_100 - micropoolPercentage
);

votingRewards.micropool -= delegatorsRewards;
}
}
21 changes: 10 additions & 11 deletions deploy/92_GovPoolsSetup.migration.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
41 changes: 31 additions & 10 deletions test/gov/GovPool.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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])],
Expand Down Expand Up @@ -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 });

Expand Down Expand Up @@ -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;
Expand Down

0 comments on commit 8ab9506

Please sign in to comment.