Skip to content

Commit e3f35a1

Browse files
authored
feat(BundleRegistry): add trustedBatchRegister for faster migrations (#149)
* feat(BundleRegistry): add trustedBatchRegister for faster migrations * test(BundleRegistry): remove unnecessary warps * fix: add comment to explain deploy script behavior
1 parent c51595e commit e3f35a1

File tree

4 files changed

+262
-84
lines changed

4 files changed

+262
-84
lines changed

script/BundleRegistry.s.sol

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,8 @@ contract BundleRegistryScript is Script {
1515
address constant GOERLI_FORWARDER = address(0x7A95fA73250dc53556d264522150A940d4C50238);
1616
bytes32 constant ADMIN_ROLE = keccak256("ADMIN_ROLE");
1717

18-
// TODO: Always update this to the address of the private key used to deploy the contracts
19-
address constant DEPLOYER = address(0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266);
18+
// TODO: Always update this to the address of the private key used to deploy the contracts on the network
19+
address constant DEPLOYER = address(0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266); // anvil deployer
2020

2121
// TODO: Update the vault and pool addresses every time
2222
address constant VAULT = DEPLOYER;

src/BundleRegistry.sol

Lines changed: 53 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,33 @@ import {NameRegistry} from "./NameRegistry.sol";
1414
* reducing complexity for the caller.
1515
*/
1616
contract BundleRegistry is Ownable {
17+
/*//////////////////////////////////////////////////////////////
18+
ERRORS
19+
//////////////////////////////////////////////////////////////*/
20+
21+
/// @dev Revert when the caller does not have the authority to perform the action
1722
error Unauthorized();
23+
24+
/// @dev Revert when excess funds could not be sent back to the caller
1825
error CallFailed();
1926

27+
/*//////////////////////////////////////////////////////////////
28+
EVENTS
29+
//////////////////////////////////////////////////////////////*/
30+
2031
/// @dev Emit when the trustedCaller is changed by the owner after the contract is deployed
2132
event ChangeTrustedCaller(address indexed trustedCaller, address indexed owner);
2233

34+
/*//////////////////////////////////////////////////////////////
35+
STORAGE
36+
//////////////////////////////////////////////////////////////*/
37+
38+
/// @notice The data required to trustedBatchRegister a single user
39+
struct BatchUser {
40+
address to;
41+
bytes16 username;
42+
}
43+
2344
/// @dev The only address that can call trustedRegister and partialTrustedRegister
2445
address internal trustedCaller;
2546

@@ -29,6 +50,13 @@ contract BundleRegistry is Ownable {
2950
/// @dev The address of the NameRegistry UUPS Proxy contract
3051
NameRegistry internal immutable nameRegistry;
3152

53+
/*//////////////////////////////////////////////////////////////
54+
CONSTANTS
55+
//////////////////////////////////////////////////////////////*/
56+
57+
/// @dev The default homeUrl value for the IdRegistry call, to be used until Hubs are launched
58+
string internal constant DEFAULT_URL = "https://www.farcaster.xyz/";
59+
3260
/**
3361
* @notice Configure the addresses of the Registry contracts and the trusted caller which is
3462
* allowed to register during the invitation phase.
@@ -72,10 +100,11 @@ contract BundleRegistry is Ownable {
72100
}
73101

74102
/**
75-
* @notice Register an fid and an fname during the Goerli phase, where registration can only be
76-
* performed by the Farcaster Invite Server (trustedCaller)
103+
* @notice Register an fid and an fname during the first Mainnet phase, where registration of
104+
* the fid is available to all, but registration of the fname can only be performed by
105+
* the Farcaster Invite Server (trustedCaller)
77106
*/
78-
function trustedRegister(
107+
function partialTrustedRegister(
79108
address to,
80109
address recovery,
81110
string calldata url,
@@ -86,16 +115,15 @@ contract BundleRegistry is Ownable {
86115
if (msg.sender != trustedCaller) revert Unauthorized();
87116

88117
// Audit: is it possible to end up in a state where one passes but the other fails?
89-
idRegistry.trustedRegister(to, recovery, url);
118+
idRegistry.register(to, recovery, url);
90119
nameRegistry.trustedRegister(username, to, recovery, inviter, idRegistry.idOf(to));
91120
}
92121

93122
/**
94-
* @notice Register an fid and an fname during the first Mainnet phase, where registration of
95-
* the fid is available to all, but registration of the fname can only be performed by
96-
* the Farcaster Invite Server (trustedCaller)
123+
* @notice Register an fid and an fname during the Goerli phase, where registration can only be
124+
* performed by the Farcaster Invite Server (trustedCaller)
97125
*/
98-
function partialTrustedRegister(
126+
function trustedRegister(
99127
address to,
100128
address recovery,
101129
string calldata url,
@@ -106,10 +134,26 @@ contract BundleRegistry is Ownable {
106134
if (msg.sender != trustedCaller) revert Unauthorized();
107135

108136
// Audit: is it possible to end up in a state where one passes but the other fails?
109-
idRegistry.register(to, recovery, url);
137+
idRegistry.trustedRegister(to, recovery, url);
110138
nameRegistry.trustedRegister(username, to, recovery, inviter, idRegistry.idOf(to));
111139
}
112140

141+
/**
142+
* @notice Register multiple fids and fname during a migration to a new network, where
143+
* registration can only be performed by the Farcaster Invite Server (trustedCaller).
144+
* Recovery address, inviter, invitee and homeUrl are initialized to default values
145+
* during this migration.
146+
*/
147+
function trustedBatchRegister(BatchUser[] calldata users) external {
148+
// Do not allow anyone except the Farcaster Invite Server (trustedCaller) to call this
149+
if (msg.sender != trustedCaller) revert Unauthorized();
150+
151+
for (uint256 i = 0; i < users.length; i++) {
152+
idRegistry.trustedRegister(users[i].to, address(0), DEFAULT_URL);
153+
nameRegistry.trustedRegister(users[i].username, users[i].to, address(0), 0, 0);
154+
}
155+
}
156+
113157
/**
114158
* @notice Change the trusted caller that can call trustedRegister and partialTrustedRegister
115159
*/

src/NameRegistry.sol

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ contract NameRegistry is
5555

5656
/// @dev Revert if the caller does not have TREASURER_ROLE
5757
error NotTreasurer();
58+
5859
/// @dev Revert when excess funds could not be sent back to the caller
5960
error CallFailed();
6061

0 commit comments

Comments
 (0)