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

Allow funds to be sent directly to domains #1291

Draft
wants to merge 4 commits into
base: develop
Choose a base branch
from
Draft
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
Original file line number Diff line number Diff line change
Expand Up @@ -1132,6 +1132,17 @@
}
}
}
},
{
"contract": "contracts/colonyNetwork/ColonyNetwork.sol:ColonyNetwork",
"label": "domainReceiverResolverAddress",
"offset": 0,
"slot": "50",
"type": {
"encoding": "inplace",
"label": "address",
"numberOfBytes": "20"
}
}
]
}
Original file line number Diff line number Diff line change
Expand Up @@ -1132,6 +1132,17 @@
}
}
}
},
{
"contract": "contracts/colonyNetwork/ColonyNetworkAuction.sol:ColonyNetworkAuction",
"label": "domainReceiverResolverAddress",
"offset": 0,
"slot": "50",
"type": {
"encoding": "inplace",
"label": "address",
"numberOfBytes": "20"
}
}
]
}
Original file line number Diff line number Diff line change
Expand Up @@ -1132,6 +1132,17 @@
}
}
}
},
{
"contract": "contracts/colonyNetwork/ColonyNetworkDeployer.sol:ColonyNetworkDeployer",
"label": "domainReceiverResolverAddress",
"offset": 0,
"slot": "50",
"type": {
"encoding": "inplace",
"label": "address",
"numberOfBytes": "20"
}
}
]
}
Original file line number Diff line number Diff line change
Expand Up @@ -1132,6 +1132,17 @@
}
}
}
},
{
"contract": "contracts/colonyNetwork/ColonyNetworkENS.sol:ColonyNetworkENS",
"label": "domainReceiverResolverAddress",
"offset": 0,
"slot": "50",
"type": {
"encoding": "inplace",
"label": "address",
"numberOfBytes": "20"
}
}
]
}
Original file line number Diff line number Diff line change
Expand Up @@ -1132,6 +1132,17 @@
}
}
}
},
{
"contract": "contracts/colonyNetwork/ColonyNetworkExtensions.sol:ColonyNetworkExtensions",
"label": "domainReceiverResolverAddress",
"offset": 0,
"slot": "50",
"type": {
"encoding": "inplace",
"label": "address",
"numberOfBytes": "20"
}
}
]
}
Original file line number Diff line number Diff line change
Expand Up @@ -1132,6 +1132,17 @@
}
}
}
},
{
"contract": "contracts/colonyNetwork/ColonyNetworkMining.sol:ColonyNetworkMining",
"label": "domainReceiverResolverAddress",
"offset": 0,
"slot": "50",
"type": {
"encoding": "inplace",
"label": "address",
"numberOfBytes": "20"
}
}
]
}
Original file line number Diff line number Diff line change
Expand Up @@ -1132,6 +1132,17 @@
}
}
}
},
{
"contract": "contracts/colonyNetwork/ColonyNetworkSkills.sol:ColonyNetworkSkills",
"label": "domainReceiverResolverAddress",
"offset": 0,
"slot": "50",
"type": {
"encoding": "inplace",
"label": "address",
"numberOfBytes": "20"
}
}
]
}
Original file line number Diff line number Diff line change
Expand Up @@ -1132,6 +1132,17 @@
}
}
}
},
{
"contract": "contracts/colonyNetwork/ColonyNetworkStorage.sol:ColonyNetworkStorage",
"label": "domainReceiverResolverAddress",
"offset": 0,
"slot": "50",
"type": {
"encoding": "inplace",
"label": "address",
"numberOfBytes": "20"
}
}
]
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
{
"storage": [
{
"contract": "contracts/common/DomainTokenReceiver.sol:DomainTokenReceiver",
"label": "authority",
"offset": 0,
"slot": "0",
"type": {
"encoding": "inplace",
"label": "contract DSAuthority",
"numberOfBytes": "20"
}
},
{
"contract": "contracts/common/DomainTokenReceiver.sol:DomainTokenReceiver",
"label": "owner",
"offset": 0,
"slot": "1",
"type": {
"encoding": "inplace",
"label": "address",
"numberOfBytes": "20"
}
},
{
"contract": "contracts/common/DomainTokenReceiver.sol:DomainTokenReceiver",
"label": "resolver",
"offset": 0,
"slot": "2",
"type": {
"encoding": "inplace",
"label": "address",
"numberOfBytes": "20"
}
},
{
"contract": "contracts/common/DomainTokenReceiver.sol:DomainTokenReceiver",
"label": "colony",
"offset": 0,
"slot": "3",
"type": {
"encoding": "inplace",
"label": "address",
"numberOfBytes": "20"
}
}
]
}
8 changes: 8 additions & 0 deletions contracts/colony/ColonyDataTypes.sol
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,14 @@ interface ColonyDataTypes {
/// @param payoutRemainder The remaining funds moved to the top-level domain pot
event ColonyFundsClaimed(address agent, address token, uint256 fee, uint256 payoutRemainder);

/// @notice Event logged when funds sent directly to a domain are claimed
/// @param agent The address that is responsible for triggering this event
/// @param token The token address
/// @param domainId The domain id
/// @param fee The fee deducted for rewards
/// @param payoutRemainder The remaining funds moved to the domain pot
event DomainFundsClaimed(address agent, address token, uint256 domainId, uint256 fee, uint256 payoutRemainder);

/// @notice Event logged when a new reward payout cycle has started
/// @param agent The address that is responsible for triggering this event
/// @param rewardPayoutId The reward payout cycle id
Expand Down
33 changes: 33 additions & 0 deletions contracts/colony/ColonyFunding.sol
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import { ITokenLocking } from "./../tokenLocking/ITokenLocking.sol";
import { ColonyStorage } from "./ColonyStorage.sol";
import { ERC20Extended } from "./../common/ERC20Extended.sol";
import { IColonyNetwork } from "./../colonyNetwork/IColonyNetwork.sol";
import { DomainTokenReceiver } from "./../common/DomainTokenReceiver.sol";

contract ColonyFunding is
ColonyStorage // ignore-swc-123
Expand Down Expand Up @@ -106,6 +107,38 @@ contract ColonyFunding is
emit ColonyFundsClaimed(msgSender(), _token, feeToPay, remainder);
}

function claimDomainFunds(address _token, uint256 _domainId) public stoppable {
require(domainExists(_domainId), "colony-funding-domain-does-not-exist");
address domainTokenReceiverAddress = IColonyNetwork(colonyNetworkAddress)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thinking more about whether this deployment should go on the network or the colony, while putting it on the colony seems preferable to avoid the external call, if we're going to check the resolver each time then the external call will be inevitable, and if so probably best to keep all the deployment logic in one place.

.idempotentDeployDomainTokenReceiver(_domainId);
uint256 fundingPotId = domains[_domainId].fundingPotId;
// It's deployed, so check current balance of pot

uint256 claimAmount;

if (_token == address(0x0)) {
kronosapiens marked this conversation as resolved.
Show resolved Hide resolved
claimAmount = address(domainTokenReceiverAddress).balance;
} else {
claimAmount = ERC20Extended(_token).balanceOf(address(domainTokenReceiverAddress));
}

uint256 feeToPay = claimAmount / getRewardInverse(); // ignore-swc-110 . This variable is set when the colony is
// initialised to MAX_UINT, and cannot be set to zero via setRewardInverse, so this is a false positive. It *can* be set
// 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
// able to do with recovery mode.
uint256 remainder = claimAmount - feeToPay;
nonRewardPotsTotal[_token] += remainder;

fundingPots[0].balance[_token] += feeToPay;
fundingPots[fundingPotId].balance[_token] += remainder;

// Claim funds

DomainTokenReceiver(domainTokenReceiverAddress).transferToColony(_token);

emit DomainFundsClaimed(msgSender(), _token, _domainId, feeToPay, remainder);
}

function getNonRewardPotsTotal(address _token) public view returns (uint256) {
return nonRewardPotsTotal[_token];
}
Expand Down
6 changes: 6 additions & 0 deletions contracts/colony/IColony.sol
Original file line number Diff line number Diff line change
Expand Up @@ -841,6 +841,12 @@ interface IColony is ColonyDataTypes, IRecovery, IBasicMetaTransaction, IMultica
/// @param _token Address of the token, `0x0` value indicates Ether
function claimColonyFunds(address _token) external;

/// @notice Move any funds received by the colony for a specific domain to that domain's pot
/// Currently no fees are taken
/// @param _token Address of the token, `0x0` value indicates Ether
/// @param _domainId Id of the domain
function claimDomainFunds(address _token, uint256 _domainId) external;

/// @notice Get the total amount of tokens `_token` minus amount reserved to be paid to the reputation and token holders as rewards.
/// @param _token Address of the token, `0x0` value indicates Ether
/// @return amount Total amount of tokens in funding pots other than the rewards pot (id 0)
Expand Down
Loading