Skip to content

Commit 5e32b9a

Browse files
committed
Improvements following review
1 parent 7683378 commit 5e32b9a

File tree

3 files changed

+51
-46
lines changed

3 files changed

+51
-46
lines changed

contracts/colony/ColonyFunding.sol

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -111,8 +111,6 @@ contract ColonyFunding is
111111
require(domainExists(_domainId), "colony-funding-domain-does-not-exist");
112112
address domainTokenReceiverAddress = IColonyNetwork(colonyNetworkAddress)
113113
.idempotentDeployDomainTokenReceiver(_domainId);
114-
uint256 fundingPotId = domains[_domainId].fundingPotId;
115-
// It's deployed, so check current balance of pot
116114

117115
uint256 claimAmount;
118116

@@ -131,6 +129,7 @@ contract ColonyFunding is
131129

132130
fundingPots[0].balance[_token] += feeToPay;
133131

132+
uint256 fundingPotId = domains[_domainId].fundingPotId;
134133
uint256 approvedAmount = domainReputationApproval[_domainId];
135134

136135
if (tokenEarnsReputationOnPayout(_token)) {
@@ -139,19 +138,22 @@ contract ColonyFunding is
139138

140139
fundingPots[fundingPotId].balance[_token] += transferrableAmount;
141140
domainReputationApproval[_domainId] -= transferrableAmount;
141+
142142
emit DomainFundsClaimed(msgSender(), _token, _domainId, feeToPay, transferrableAmount);
143143
if (untransferrableAmount > 0) {
144144
fundingPots[domains[1].fundingPotId].balance[_token] += untransferrableAmount;
145+
145146
emit ColonyFundsClaimed(msgSender(), _token, 0, untransferrableAmount);
146147
}
147148
} else {
148149
fundingPots[fundingPotId].balance[_token] += remainder;
150+
149151
emit DomainFundsClaimed(msgSender(), _token, _domainId, feeToPay, remainder);
150152
}
151153

152154
// Claim funds
153155
if (_token == address(0x0)) {
154-
DomainTokenReceiver(domainTokenReceiverAddress).transferNativeToColony();
156+
DomainTokenReceiver(domainTokenReceiverAddress).transferChainNativeToColony();
155157
} else {
156158
DomainTokenReceiver(domainTokenReceiverAddress).approveTokenToColony(_token);
157159
// slither-disable-next-line arbitrary-send-erc20
@@ -163,6 +165,7 @@ contract ColonyFunding is
163165
}
164166

165167
function tokenEarnsReputationOnPayout(address _token) internal view returns (bool) {
168+
// This function is in anticipation of multiple tokens being able to earn reputation on payout.
166169
return _token == token;
167170
}
168171

@@ -174,6 +177,8 @@ contract ColonyFunding is
174177
require(domainExists(_domainId), "colony-funding-domain-does-not-exist");
175178
require(_domainId > 1, "colony-funding-root-domain");
176179
if (_add) {
180+
// Rather than setting the approval to the amount, we add the amount to the approval, so that if there
181+
// are multiple calls to this function via motions etc, the approval will be the sum of all the amounts.
177182
domainReputationApproval[_domainId] += _amount;
178183
} else {
179184
domainReputationApproval[_domainId] -= _amount;

contracts/common/DomainTokenReceiver.sol

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ contract DomainTokenReceiver is DSAuth {
3939
colony = _colony;
4040
}
4141

42-
function transferNativeToColony() public onlyColony {
42+
function transferChainNativeToColony() public onlyColony {
4343
payable(colony).transfer(address(this).balance);
4444
}
4545

test/contracts-network/colony-funding.js

Lines changed: 42 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -656,7 +656,7 @@ contract("Colony Funding", (accounts) => {
656656

657657
const receiver = await DomainTokenReceiver.at(receiverAddress);
658658
await checkErrorRevert(receiver.approveTokenToColony(otherToken.address), "domain-token-receiver-unauthorized");
659-
await checkErrorRevert(receiver.transferNativeToColony(), "domain-token-receiver-unauthorized");
659+
await checkErrorRevert(receiver.transferChainNativeToColony(), "domain-token-receiver-unauthorized");
660660
});
661661

662662
it("should not allow even the colonyNetwork to call setColonyAddress once it's set on domainTokenReceiver", async () => {
@@ -700,6 +700,47 @@ contract("Colony Funding", (accounts) => {
700700
expect(rootDomainPotBalanceAfter.sub(rootDomainPotBalanceBefore)).to.eq.BN(99);
701701
});
702702

703+
it(`when receiving native (reputation-earning) token, if full approval present for domain,
704+
tokens are received by domain`, async () => {
705+
// Get address for domain 2
706+
await colony.addDomain(1, UINT256_MAX, 1);
707+
const receiverAddress = await colonyNetwork.getDomainTokenReceiverAddress(colony.address, 2);
708+
await colony.mintTokens(WAD.muln(100));
709+
await colony.claimColonyFunds(token.address);
710+
const domain1 = await colony.getDomain(1);
711+
712+
// Send an arbitrary transaction to mint tokens for receiverAddress
713+
const txData = token.contract.methods["mint(address,uint256)"](receiverAddress, 100).encodeABI();
714+
await colony.makeArbitraryTransaction(token.address, txData);
715+
716+
// Approve 250 for the domain
717+
await colony.editAllowedDomainReputationReceipt(2, 250, true);
718+
let allowedReceipt = await colony.getAllowedDomainReputationReceipt(2);
719+
expect(allowedReceipt).to.eq.BN(250);
720+
721+
// Now test what happens when we claim them
722+
723+
const domain = await colony.getDomain(2);
724+
const domainPotBalanceBefore = await colony.getFundingPotBalance(domain.fundingPotId, token.address);
725+
const nonRewardPotsTotalBefore = await colony.getNonRewardPotsTotal(token.address);
726+
const rootDomainPotBalanceBefore = await colony.getFundingPotBalance(domain1.fundingPotId, token.address);
727+
728+
// Claim the funds
729+
await colony.claimDomainFunds(token.address, 2);
730+
731+
const domainPotBalanceAfter = await colony.getFundingPotBalance(domain.fundingPotId, token.address);
732+
const nonRewardPotsTotalAfter = await colony.getNonRewardPotsTotal(token.address);
733+
const rootDomainPotBalanceAfter = await colony.getFundingPotBalance(domain1.fundingPotId, token.address);
734+
735+
// Check the balance of the domain
736+
expect(domainPotBalanceAfter.sub(domainPotBalanceBefore)).to.eq.BN(99);
737+
expect(nonRewardPotsTotalAfter.sub(nonRewardPotsTotalBefore)).to.eq.BN(99);
738+
expect(rootDomainPotBalanceAfter.sub(rootDomainPotBalanceBefore)).to.eq.BN(0);
739+
740+
allowedReceipt = await colony.getAllowedDomainReputationReceipt(2);
741+
expect(allowedReceipt).to.eq.BN(151);
742+
});
743+
703744
it(`when receiving native (reputation-earning) token, if partial approval present for domain,
704745
tokens are split between intended domain and root`, async () => {
705746
// Get address for domain 2
@@ -769,47 +810,6 @@ contract("Colony Funding", (accounts) => {
769810
await checkErrorRevert(colony.editAllowedDomainReputationReceipt(1, 70, true), "colony-funding-root-domain");
770811
});
771812

772-
it(`when receiving native (reputation-earning) token, if full approval present for domain,
773-
tokens are received by domain`, async () => {
774-
// Get address for domain 2
775-
await colony.addDomain(1, UINT256_MAX, 1);
776-
const receiverAddress = await colonyNetwork.getDomainTokenReceiverAddress(colony.address, 2);
777-
await colony.mintTokens(WAD.muln(100));
778-
await colony.claimColonyFunds(token.address);
779-
const domain1 = await colony.getDomain(1);
780-
781-
// Send an arbitrary transaction to mint tokens for receiverAddress
782-
const txData = token.contract.methods["mint(address,uint256)"](receiverAddress, 100).encodeABI();
783-
await colony.makeArbitraryTransaction(token.address, txData);
784-
785-
// Approve 250 for the domain
786-
await colony.editAllowedDomainReputationReceipt(2, 250, true);
787-
let allowedReceipt = await colony.getAllowedDomainReputationReceipt(2);
788-
expect(allowedReceipt).to.eq.BN(250);
789-
790-
// Now test what happens when we claim them
791-
792-
const domain = await colony.getDomain(2);
793-
const domainPotBalanceBefore = await colony.getFundingPotBalance(domain.fundingPotId, token.address);
794-
const nonRewardPotsTotalBefore = await colony.getNonRewardPotsTotal(token.address);
795-
const rootDomainPotBalanceBefore = await colony.getFundingPotBalance(domain1.fundingPotId, token.address);
796-
797-
// Claim the funds
798-
await colony.claimDomainFunds(token.address, 2);
799-
800-
const domainPotBalanceAfter = await colony.getFundingPotBalance(domain.fundingPotId, token.address);
801-
const nonRewardPotsTotalAfter = await colony.getNonRewardPotsTotal(token.address);
802-
const rootDomainPotBalanceAfter = await colony.getFundingPotBalance(domain1.fundingPotId, token.address);
803-
804-
// Check the balance of the domain
805-
expect(domainPotBalanceAfter.sub(domainPotBalanceBefore)).to.eq.BN(99);
806-
expect(nonRewardPotsTotalAfter.sub(nonRewardPotsTotalBefore)).to.eq.BN(99);
807-
expect(rootDomainPotBalanceAfter.sub(rootDomainPotBalanceBefore)).to.eq.BN(0);
808-
809-
allowedReceipt = await colony.getAllowedDomainReputationReceipt(2);
810-
expect(allowedReceipt).to.eq.BN(151);
811-
});
812-
813813
it("should not be able to claim funds for a domain that does not exist", async () => {
814814
await checkErrorRevert(colony.claimDomainFunds(ethers.constants.AddressZero, 2), "colony-funding-domain-does-not-exist");
815815
});

0 commit comments

Comments
 (0)