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

Donations #41

Open
wants to merge 3 commits into
base: develop
Choose a base branch
from
Open

Donations #41

wants to merge 3 commits into from

Conversation

irfanbozkurt
Copy link
Owner

Implements a contract as a controller of donation mechanism.

  • Deployed with a list of contributor addresses and each address has a weight
  • Incoming donations are immediately split and sent to contributors respecting their weights
  • Addition of a new contributor requires approval of everybody.
    • If a contributor doesn't want a new contributor, they can simply ignore the proposal
    • If a contributor is okay with a new contributor, but doesn't like their proposed weight; they can create a new proposal with a new weight value

I didn't include a "remove contributor" functionality.

Copy link
Collaborator

@escottalexander escottalexander left a comment

Choose a reason for hiding this comment

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

Left some questions and suggestions. We can discuss if you think I missed your logic. Nice work. This is great stuff.

size := extcodesize(addr)
}
return size > 0;
}
Copy link
Collaborator

Choose a reason for hiding this comment

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

I think we should have some methods for removing a contributor. What happens if a contributor wallet address gets hacked. It would be nice if other members could propose to remove the hacked address and then add a new one.

}

if (!proposals[newContributor].exists) {
if (_isContract(newContributor)) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Curious to hear your reasoning on why we shouldn't allow a contract address. I don't see a reentrancy risk by allowing contracts and it would be nice if contributors could use Safe addresses instead of EOAs. It is generally frowned upon to check if an address has code in the smart contract layer because there are ways around it. For instance, lets pretend that reentrancy was possible/beneficial in this contract. If I wanted to I could pre-define the address for an exploiting contract but only deploy the contract after you added the address as a contributor. Lots of holes. But curious if you have other concerns I am not thinking about.


modifier onlyContributors() {
bool contains;
for (uint8 i = 0; i < contributors.length; i++) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Wonder if it would make more sense to create a mapping that stores the contributors mapping(address => bool) alongside the existing array of contributors and that would save us having to loop through this each time a call is made. Pretty sure it would be more gas efficient but I have not tested it.

revert PaymentFailed(contributors[i], amount);
}
}
emit Donation(msg.sender, msg.value);
Copy link
Collaborator

Choose a reason for hiding this comment

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

Does it make sense to fire this higher, like after line 122 so that even small donations are acknowledged. Otherwise this will only fire if the value is greater than the weights. Open to thoughts.

if (totalWeiToSend < totalWeight) {
// Not enough balance, not worth splitting
return;
}
Copy link
Collaborator

Choose a reason for hiding this comment

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

Just wanted to say that the above five lines are so simply genius. Nice work. There will be minuscule amounts left in the contract but it is not a problem because the contract is guaranteed to send what it can without encountering division issues. I will be duplicating this kind of simple yet effective solution in the future.

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

Successfully merging this pull request may close these issues.

3 participants