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

20240207 invite as org #87

Merged
merged 4 commits into from
Feb 7, 2024
Merged
Show file tree
Hide file tree
Changes from 3 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
42 changes: 42 additions & 0 deletions src/multitoken-graph/Hub.sol → src/hub/Hub.sol
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,13 @@ contract Hub is Circles {
*/
uint256 public constant WELCOME_BONUS = 3 * 24 * 10 ** 18;

/**
* @dev The minimum donation amount for registering a human as an organization,
* paid in xDai, set to 0.1 xDai. The donation benefiary is arbitrary, and purely
* reputational for the organization inviting people to Circles.
*/
uint256 public constant MINIMUM_DONATION = 10 ** 17;

/**
* @dev The address used as the first element of the linked list of avatars.
*/
Expand Down Expand Up @@ -262,6 +269,41 @@ contract Hub is Circles {
emit InviteHuman(msg.sender, _human);
}

/**
* Invite human as organization allows to register a human avatar as an organization.
* @param _human address of the human to invite
* @param _donationReceiver address of where to send the donation to with 2300 gas (using transfer)
*/
function inviteHumanAsOrganization(address _human, address payable _donationReceiver) external payable {
require(msg.value > MINIMUM_DONATION, "Donation must be at least 0.1 xDai.");
require(isOrganization(msg.sender), "Only organizations can invite.");

Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
require(msg.sender != _donationReceiver, "Can't donate to yourself");

Copy link
Contributor

Choose a reason for hiding this comment

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

Makes it at least a little bit more expensive to perpetually invite people with the same funds.

Copy link
Member Author

Choose a reason for hiding this comment

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

well, I agree, but you can always send to yourself over one-hop, so I don't know if we should block it. we already know that the donation is a reputation requirement for it to have meaning

Copy link
Member Author

Choose a reason for hiding this comment

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

I added the requirement with comment

// insert avatar into linked list; reverts if it already exists
_insertAvatar(_human);

// set the last mint time to the current timestamp for invited human
// and register the v1 Circles contract status
address v1CirclesStatus = _avatarV1CirclesStatus(_human);
Copy link
Contributor

Choose a reason for hiding this comment

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

Let's refactor the common parts of inviteHuman and inviteHumanAsOrganization into an _inviteHuman function

Copy link
Member Author

Choose a reason for hiding this comment

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

yes, I wanted to, but then thought I was overthinking it. Ill quickly do

Copy link
Member Author

Choose a reason for hiding this comment

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

turned out it was well worth the refactoring!

MintTime storage mintTime = mintTimes[_human];
mintTime.mintV1Status = v1CirclesStatus;
mintTime.lastMintTime = uint96(block.timestamp);

// invited receives the welcome bonus in their personal Circles
_mint(_human, _toTokenId(_human), WELCOME_BONUS, "");

// set trust for a year, but organization can edit this later
_trust(msg.sender, _human, uint96(block.timestamp + 365 days));

// set the trust for the invited to self to indefinite future; not editable later
_trust(_human, _human, INDEFINITELY);

// send the donation to the donation receiver but with minimal gas
// to avoid reentrancy attacks
_donationReceiver.transfer(msg.value);

emit InviteHuman(msg.sender, _human);
}

/**
* @notice Register group allows to register a group avatar.
* @param _mint mint address will be called before minting group circles
Expand Down
File renamed without changes.
2 changes: 1 addition & 1 deletion src/names/NameRegistry.sol
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// SPDX-License-Identifier: AGPL-3.0-only
pragma solidity >=0.8.13;

import "../multitoken-graph/IHub.sol";
import "../hub/IHub.sol";

contract NameRegistry {
// Constants
Expand Down
Loading