Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix setExpenditurePayouts logic #1154

Merged
merged 1 commit into from
Aug 14, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 5 additions & 4 deletions contracts/colony/ColonyFunding.sol
Original file line number Diff line number Diff line change
Expand Up @@ -409,21 +409,22 @@ contract ColonyFunding is ColonyStorage { // ignore-swc-123
FundingPot storage fundingPot = fundingPots[expenditures[_id].fundingPotId];
assert(fundingPot.associatedType == FundingPotAssociatedType.Expenditure);

uint256 currentTotal = fundingPot.payouts[_token];
uint256 previousTotal = fundingPot.payouts[_token];
uint256 runningTotal = fundingPot.payouts[_token];

for (uint256 i; i < _slots.length; i++) {
require(_amounts[i] <= MAX_PAYOUT, "colony-payout-too-large");

uint256 currentPayout = expenditureSlotPayouts[_id][_slots[i]][_token];

expenditureSlotPayouts[_id][_slots[i]][_token] = _amounts[i];
fundingPot.payouts[_token] = (currentTotal - currentPayout) + _amounts[i];

runningTotal = (runningTotal - currentPayout) + _amounts[i];

emit ExpenditurePayoutSet(msgSender(), _id, _slots[i], _token, _amounts[i]);
}
fundingPot.payouts[_token] = runningTotal;

updatePayoutsWeCannotMakeAfterBudgetChange(expenditures[_id].fundingPotId, _token, currentTotal);
updatePayoutsWeCannotMakeAfterBudgetChange(expenditures[_id].fundingPotId, _token, previousTotal);
}

function setTaskPayout(uint256 _id, TaskRole _role, address _token, uint256 _amount) private
Expand Down
45 changes: 45 additions & 0 deletions test/contracts-network/colony-expenditure.js
Original file line number Diff line number Diff line change
Expand Up @@ -367,6 +367,11 @@ contract("Colony Expenditure", (accounts) => {
expect(payout).to.eq.BN(10);
payout = await colony.getExpenditureSlotPayout(expenditureId, SLOT2, token.address);
expect(payout).to.eq.BN(20);

const expenditure = await colony.getExpenditure(expenditureId);
const fundingPotId = await expenditure.fundingPotId;
const fundingPotPayout = await colony.getFundingPotPayout(fundingPotId, token.address);
expect(fundingPotPayout).to.eq.BN(30);
});

it("should not allow owners to update many slot payouts with mismatched arguments", async () => {
Expand Down Expand Up @@ -939,6 +944,46 @@ contract("Colony Expenditure", (accounts) => {
expect(potPayout).to.be.zero;
});

it("should be able to pay out all recipients if setExpenditurePayouts is used to set recipients", async () => {
await colony.setExpenditureRecipient(expenditureId, SLOT0, RECIPIENT, { from: ADMIN });
await colony.setExpenditureRecipient(expenditureId, SLOT1, RECIPIENT, { from: ADMIN });

await colony.setExpenditurePayouts(expenditureId, [SLOT0, SLOT1], token.address, [10, 20], { from: ADMIN });

let expenditure = await colony.getExpenditure(expenditureId);

await colony.moveFundsBetweenPots(
1,
UINT256_MAX,
1,
UINT256_MAX,
UINT256_MAX,
domain1.fundingPotId,
expenditure.fundingPotId,
30,
token.address
);
await colony.finalizeExpenditure(expenditureId, { from: ADMIN });

expenditure = await colony.getExpenditure(expenditureId);

const balanceBefore = await colony.getFundingPotBalance(expenditure.fundingPotId, token.address);
await colony.claimExpenditurePayout(expenditureId, SLOT0, token.address);
const balanceAfter = await colony.getFundingPotBalance(expenditure.fundingPotId, token.address);
expect(balanceBefore.sub(balanceAfter)).to.eq.BN(10);

let potBalance = await colony.getFundingPotBalance(expenditure.fundingPotId, token.address);
let potPayout = await colony.getFundingPotPayout(expenditure.fundingPotId, token.address);
expect(potBalance).to.eq.BN(20);
expect(potPayout).to.eq.BN(20);

await colony.claimExpenditurePayout(expenditureId, SLOT1, token.address);
potBalance = await colony.getFundingPotBalance(expenditure.fundingPotId, token.address);
potPayout = await colony.getFundingPotPayout(expenditure.fundingPotId, token.address);
expect(potBalance).to.be.zero;
expect(potPayout).to.be.zero;
});

it("if skill is set, should emit two reputation updates", async () => {
await colony.setExpenditureRecipient(expenditureId, SLOT0, RECIPIENT, { from: ADMIN });
await colony.setExpenditurePayout(expenditureId, SLOT0, token.address, WAD, { from: ADMIN });
Expand Down