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

Conversation

area
Copy link
Member

@area area commented Sep 13, 2024

This is work that I've done while working on #1285 as a prerequisite for the required functionality of domains to be able to manage and exchange tokens cross-chain. For that functionality to work, I believe this functionality (or something equivalent) is required; where such an exchange is happening cross-chain, and we can't directly interrogate balances before and after the exchange on the other chain, we need a more generic way to send tokens to a domain directly in order to do the bookkeeping correctly.

Because we can't send extra data with an ERC20 token transfer that's executed by other parties, I believe the only way to do this is have a system where each domain has a unique address that can have tokens swept from it in to the corresponding domain.

Fortunately, we can (re-)use CreateX for this. By using a contract deployment salt that's a function of the colony address and domain id, we can deploy a helper contract (DomainTokenReceiver) to a fixed address for each domain (even across chains) with simple functionality to allow the sweep to occur.

I've tried to make this as transparent as possible - the deployment, upgrading, and management of the receiving contract is intended to not require any explicit interaction from the user. The experience should be that the users send tokens to a domain-specific address (which they can get from getDomainTokenReceiverAddress on ColonyNetwork) and then claim them (via claimDomainFunds on Colony) without having to check whether the contract is already deployed and/or up-to-date.

Tagging this as ready-for-review because I want feedback, but leaving as draft because I don't want it merged yet. I think the biggest question I have hanging over this implementation is what the split between the Colony and ColonyNetwork should be for the implementation but open to feedback from any and all directions.

@area
Copy link
Member Author

area commented Sep 13, 2024

An open question here is what should happen in terms of the colony reward pot. I think I am of the opinion that whatever it is set to should be respected.

@arrenv
Copy link
Member

arrenv commented Sep 13, 2024

So, funds sent to the main colony address or specific domain addresses will also automatically be divided up and split amongst the respective teams set by the rewards pot? Regardless if the funds are only sent to a specific team?

@area
Copy link
Member Author

area commented Sep 13, 2024

split amongst the respective teams set by the rewards pot

This isn't really describing what the reward pot does. It is a single pot, and the only configuration available related to it is the fraction of incoming funds that gets put in to it, and those funds will eventually be divided among all people who have both reputation and native tokens.

It's possible this is functionality that should be removed, but until that decision is made, anything other than respecting that configuration means that it can be totally bypassed (as instead of sending funds to a colony directly, you can send funds directly to the top-level domain).

@arrenv
Copy link
Member

arrenv commented Sep 13, 2024

This isn't really describing what the reward pot does. It is a single pot, and the only configuration available related to it is the fraction of incoming funds that gets put in to it, and those funds will eventually be divided among all people who have both reputation and native tokens.

It's possible this is functionality that should be removed, but until that decision is made, anything other than respecting that configuration means that it can be totally bypassed (as instead of sending funds to a colony directly, you can send funds directly to the top-level domain).

Haha, yeah, just crisscrossed myself with the talk of teams.

I agree with you on both. Perhaps in needs to be rethought a little or removed, but until that time, if it is configured, it seems to make sense that it can't be bypassed.

It just does not seem intuitive that it would be the case when a colony is transferring funds to itself, but, I understand that this is how this functionality would essentially work.

@area area force-pushed the feat/fund-domains-directly branch 4 times, most recently from d698cfc to d5c36c3 Compare September 24, 2024 14:38
Copy link
Member

@kronosapiens kronosapiens left a comment

Choose a reason for hiding this comment

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

Looks good overall, will probably have some more comments on my next go-round but here are my first reactions.

contracts/colonyNetwork/ColonyNetworkDeployer.sol Outdated Show resolved Hide resolved
return domainReceiverResolverAddress;
}

function checkDomainTokenReceiverDeployed(
Copy link
Member

Choose a reason for hiding this comment

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

Can we choose a different naming convention for this type of idempotent deployment? I feel the same about deployCreateXIfNeeded. I'd be happy rolling this up into getDomainTokenReceiverAddress with a dev note that it deploys the contract idempotently if needed. idempotentDeployDomainTokenReceiver goes in that direction but is just as wordy so I don't know if that's a huge win. Open to your thoughts on this.

Copy link
Member Author

@area area Sep 26, 2024

Choose a reason for hiding this comment

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

I'd be happy rolling this up into getDomainTokenReceiverAddress with a dev note that it deploys the contract idempotently if needed.

I'm quite against this, as it makes it significantly less intuitive to use from the frontend side (as it's no longer a view function).

In terms of naming... I agree that it's much of a muchness. I will say I'm completely unfussed about deployCreateXIfNeeded though, as it's a non-contract function only used in tests.

EDIT: I'm on board for making things consistent, at least.

Copy link
Member

Choose a reason for hiding this comment

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

Ok, how about idempotentDeployCONTRACTNAME for these types of things? So idempotentDeployCreateX and idempotentDeployDomainTokenReceiver?

contracts/colony/ColonyFunding.sol Show resolved Hide resolved
@area area force-pushed the feat/fund-domains-directly branch 2 times, most recently from f8120c9 to c978a65 Compare September 26, 2024 12:35
@@ -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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants