Skip to content

Commit

Permalink
(hub): simplify Rings register and self-register function
Browse files Browse the repository at this point in the history
  • Loading branch information
benjaminbollen committed Oct 31, 2024
1 parent 69aa494 commit 5419485
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 29 deletions.
2 changes: 1 addition & 1 deletion script/deployments/gnosisChainDeploy.sh
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ deploy_and_store_details() {
--private-key ${PRIVATE_KEY} \
--optimizer-runs 200 \
--chain-id 100 \
--priority-gas-price 1200000000 \
--priority-gas-price 2200000000 \
--nonce ${nonce_to_use} \
${source_path} \
${@:5}"
Expand Down
4 changes: 2 additions & 2 deletions script/deployments/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "deploy-circles",
"version": "rc-1.0.0-beta",
"name": "deploy-rings",
"version": "rings-1.0.1-beta",
"type": "module",
"dependencies": {
"dotenv": "^16.4.5",
Expand Down
34 changes: 14 additions & 20 deletions src/hub/Hub.sol
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ import "../names/INameRegistry.sol";
import "./TypeDefinitions.sol";

/**
* @title Hub v2 contract for Circles
* @notice The Hub contract is the main contract for the Circles protocol.
* @title Hub v2 contract for Rings (test version of Circles)
* @notice The Hub contract is the main contract for the Rings(Circles) protocol.
* It adopts the ERC1155 standard for multi-token contracts and governs
* the personal and group Circles of people, organizations and groups.
* Circle balances are demurraged in the Hub contract.
Expand All @@ -30,7 +30,7 @@ contract Hub is Circles, TypeDefinitions, IHubErrors {
uint256 private constant WELCOME_BONUS = 200 * EXA;

/**
* @dev The cost of an invitation for a new avatar, paid in personal Circles burnt, set to 0.1 RINGS.
* @dev The cost of an invitation for a new avatar, paid in personal Rings burnt, set to 0.1 RINGS.
*/
uint256 private constant INVITATION_COST = 1 * EXA / 10;

Expand Down Expand Up @@ -235,17 +235,13 @@ contract Hub is Circles, TypeDefinitions, IHubErrors {
*/
function registerHuman(address _inviter, bytes32 _metadataDigest) external {
if (_inviter == address(0)) {
// to self-register yourself if you are a stopped v1 user,
// leave the inviter address as zero.

// only available for v1 users with stopped v1 mint, for initial bootstrap period
(address v1CirclesStatus, uint256 v1LastTouched) = _registerHuman(msg.sender, _inviter);
// check if v1 Circles exists and has been stopped
// and if it has been stopped, did it stop before the end of the invitation period?
if (v1CirclesStatus != CIRCLES_STOPPED_V1 || v1LastTouched >= invitationOnlyTime) {
// revert CirclesHubRegisterAvatarV1MustBeStoppedBeforeEndOfInvitationPeriod(msg.sender, 0);
revert CirclesErrorOneAddressArg(msg.sender, 0x60);
}
// anyone can self-register in RINGS (test deployment)
// Simply leave the inviter address as zero

_registerHuman(msg.sender, _inviter);

// always mint the welcome bonus to the newly registered human
_mintAndUpdateTotalSupply(msg.sender, toTokenId(msg.sender), WELCOME_BONUS, "", true);
} else {
// if someone has invited you by trusting your address ahead of this call,
// they must themselves be a registered human, and they must pay the invitation cost (after invitation period).
Expand All @@ -262,13 +258,11 @@ contract Hub is Circles, TypeDefinitions, IHubErrors {
// if they have not stopped their v1 contract)
_registerHuman(msg.sender, _inviter);

if (block.timestamp > invitationOnlyTime) {
// after the invitation period, the inviter must burn the invitation cost
_burnAndUpdateTotalSupply(_inviter, toTokenId(_inviter), INVITATION_COST);
// after the invitation period, the inviter must burn the invitation cost
_burnAndUpdateTotalSupply(_inviter, toTokenId(_inviter), INVITATION_COST);

// mint the welcome bonus to the newly registered human
_mintAndUpdateTotalSupply(msg.sender, toTokenId(msg.sender), WELCOME_BONUS, "", true);
}
// mint the welcome bonus to the newly registered human
_mintAndUpdateTotalSupply(msg.sender, toTokenId(msg.sender), WELCOME_BONUS, "", true);
}

// store the metadata digest for the avatar metadata
Expand Down
12 changes: 6 additions & 6 deletions test/names/NameRegistry.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -35,15 +35,15 @@ contract NamesTest is Test, HumanRegistration {
function testShortName() public {
// without a short name registered, first get the long name
string memory longName = mockNameRegistry.getShortOrLongName(addresses[0]);
assertEq(longName, "Circles-3fNX29VBXc9WSxAT2dG3RYSfj6uX");
assertEq(longName, "Rings-3fNX29VBXc9WSxAT2dG3RYSfj6uX");

// now register a short name
vm.prank(addresses[0]);
mockNameRegistry.registerShortNameNoChecks();

// and get the short name
string memory shortName = mockNameRegistry.getShortOrLongName(addresses[0]);
assertEq(shortName, "Circles-Q6sQpEYS9Dg1");
assertEq(shortName, "Rings-Q6sQpEYS9Dg1");

// can't register a second time
vm.expectRevert();
Expand All @@ -55,7 +55,7 @@ contract NamesTest is Test, HumanRegistration {
vm.prank(addresses[0]);
mockNameRegistry.registerShortNameWithNonceNoChecks(839892892);
string memory shortName = mockNameRegistry.getShortOrLongName(addresses[0]);
assertEq(shortName, "Circles-uNJGyf6sN6vY");
assertEq(shortName, "Rings-uNJGyf6sN6vY");
}

function testShortNameWithPadding() public {
Expand All @@ -65,7 +65,7 @@ contract NamesTest is Test, HumanRegistration {
// but as a short name it shold be padded to 12 characters
mockNameRegistry.storeShortName(addresses[0], 42);
string memory shortName = mockNameRegistry.getShortOrLongName(addresses[0]);
assertEq(shortName, "Circles-11111111111j");
assertEq(shortName, "Rings-11111111111j");
}

function testBase58Conversion() public {
Expand All @@ -82,8 +82,8 @@ contract NamesTest is Test, HumanRegistration {
}

function testCustomName() public {
mockNameRegistry.registerCustomNameNoChecks(addresses[0], "Circles");
assertEq(mockNameRegistry.customNames(addresses[0]), "Circles");
mockNameRegistry.registerCustomNameNoChecks(addresses[0], "Rings");
assertEq(mockNameRegistry.customNames(addresses[0]), "Rings");
}

function testInvalidCustomNames() public {
Expand Down

0 comments on commit 5419485

Please sign in to comment.