Skip to content

Commit d698cfc

Browse files
committed
Respect reward pots for domain-level claims; add event
1 parent 21ae75b commit d698cfc

File tree

3 files changed

+34
-7
lines changed

3 files changed

+34
-7
lines changed

contracts/colony/ColonyDataTypes.sol

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,14 @@ interface ColonyDataTypes {
6363
/// @param payoutRemainder The remaining funds moved to the top-level domain pot
6464
event ColonyFundsClaimed(address agent, address token, uint256 fee, uint256 payoutRemainder);
6565

66+
/// @notice Event logged when funds sent directly to a domain are claimed
67+
/// @param agent The address that is responsible for triggering this event
68+
/// @param token The token address
69+
/// @param domainId The domain id
70+
/// @param fee The fee deducted for rewards
71+
/// @param payoutRemainder The remaining funds moved to the domain pot
72+
event DomainFundsClaimed(address agent, address token, uint256 domainId, uint256 fee, uint256 payoutRemainder);
73+
6674
/// @notice Event logged when a new reward payout cycle has started
6775
/// @param agent The address that is responsible for triggering this event
6876
/// @param rewardPayoutId The reward payout cycle id

contracts/colony/ColonyFunding.sol

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,15 @@ contract ColonyFunding is
126126
thisBalanceBefore = ERC20Extended(_token).balanceOf(address(this));
127127
}
128128

129-
fundingPots[fundingPotId].balance[_token] += claimAmount;
129+
uint256 feeToPay = claimAmount / getRewardInverse(); // ignore-swc-110 . This variable is set when the colony is
130+
// initialised to MAX_UINT, and cannot be set to zero via setRewardInverse, so this is a false positive. It *can* be set
131+
// to 0 via recovery mode, but a) That's not why MythX is balking here and b) There's only so much we can stop people being
132+
// able to do with recovery mode.
133+
uint256 remainder = claimAmount - feeToPay;
134+
nonRewardPotsTotal[_token] += remainder;
135+
136+
fundingPots[0].balance[_token] += feeToPay;
137+
fundingPots[fundingPotId].balance[_token] += remainder;
130138

131139
// Claim funds
132140

@@ -136,7 +144,7 @@ contract ColonyFunding is
136144

137145
uint256 balanceAfter = getFundingPotBalance(fundingPotId, _token);
138146

139-
assert(balanceAfter - balanceBefore == claimAmount);
147+
assert(balanceAfter - balanceBefore == remainder);
140148

141149
uint256 thisBalanceAfter;
142150
if (_token == address(0x0)) {
@@ -146,6 +154,8 @@ contract ColonyFunding is
146154
}
147155

148156
assert(thisBalanceAfter - thisBalanceBefore == claimAmount);
157+
158+
emit DomainFundsClaimed(msgSender(), _token, _domainId, feeToPay, remainder);
149159
}
150160

151161
function getNonRewardPotsTotal(address _token) public view returns (uint256) {

test/contracts-network/colony-funding.js

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ const {
1717
} = require("../../helpers/constants");
1818

1919
const { fundColonyWithTokens, setupRandomColony, makeExpenditure, setupFundedExpenditure } = require("../../helpers/test-data-generator");
20-
const { getTokenArgs, checkErrorRevert, web3GetBalance, removeSubdomainLimit } = require("../../helpers/test-helper");
20+
const { getTokenArgs, checkErrorRevert, web3GetBalance, removeSubdomainLimit, expectEvent } = require("../../helpers/test-helper");
2121
const { setupDomainTokenReceiverResolver } = require("../../helpers/upgradable-contracts");
2222

2323
const { expect } = chai;
@@ -563,14 +563,19 @@ contract("Colony Funding", (accounts) => {
563563

564564
const domain = await colony.getDomain(2);
565565
const domainPotBalanceBefore = await colony.getFundingPotBalance(domain.fundingPotId, ethers.constants.AddressZero);
566+
const nonRewardPotsTotalBefore = await colony.getNonRewardPotsTotal(ethers.constants.AddressZero);
566567

567568
// Claim the funds
568-
await colony.claimDomainFunds(ethers.constants.AddressZero, 2);
569+
570+
const tx = await colony.claimDomainFunds(ethers.constants.AddressZero, 2);
571+
await expectEvent(tx, "DomainFundsClaimed", [MANAGER, ethers.constants.AddressZero, 2, 1, 99]);
569572

570573
const domainPotBalanceAfter = await colony.getFundingPotBalance(domain.fundingPotId, ethers.constants.AddressZero);
574+
const nonRewardPotsTotalAfter = await colony.getNonRewardPotsTotal(ethers.constants.AddressZero);
571575

572576
// Check the balance of the domain
573-
expect(domainPotBalanceAfter.sub(domainPotBalanceBefore)).to.eq.BN(100);
577+
expect(domainPotBalanceAfter.sub(domainPotBalanceBefore)).to.eq.BN(99);
578+
expect(nonRewardPotsTotalAfter.sub(nonRewardPotsTotalBefore)).to.eq.BN(99);
574579
});
575580

576581
it("should allow a token to be directly sent to a domain", async () => {
@@ -583,14 +588,18 @@ contract("Colony Funding", (accounts) => {
583588

584589
const domain = await colony.getDomain(2);
585590
const domainPotBalanceBefore = await colony.getFundingPotBalance(domain.fundingPotId, otherToken.address);
591+
const nonRewardPotsTotalBefore = await colony.getNonRewardPotsTotal(otherToken.address);
586592

587593
// Claim the funds
588-
await colony.claimDomainFunds(otherToken.address, 2);
594+
const tx = await colony.claimDomainFunds(otherToken.address, 2);
595+
await expectEvent(tx, "DomainFundsClaimed", [MANAGER, otherToken.address, 2, 1, 99]);
589596

590597
const domainPotBalanceAfter = await colony.getFundingPotBalance(domain.fundingPotId, otherToken.address);
598+
const nonRewardPotsTotalAfter = await colony.getNonRewardPotsTotal(otherToken.address);
591599

592600
// Check the balance of the domain
593-
expect(domainPotBalanceAfter.sub(domainPotBalanceBefore)).to.eq.BN(100);
601+
expect(domainPotBalanceAfter.sub(domainPotBalanceBefore)).to.eq.BN(99);
602+
expect(nonRewardPotsTotalAfter.sub(nonRewardPotsTotalBefore)).to.eq.BN(99);
594603
});
595604

596605
it("should not be able to claim funds for a domain that does not exist", async () => {

0 commit comments

Comments
 (0)