Skip to content

Commit

Permalink
refactor(StorageRegistry): rename StorageRent to StorageRegistry (#299)
Browse files Browse the repository at this point in the history
  • Loading branch information
varunsrin authored Jul 31, 2023
1 parent 91fc275 commit ddbf16c
Show file tree
Hide file tree
Showing 16 changed files with 441 additions and 439 deletions.
12 changes: 6 additions & 6 deletions .gas-snapshot
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
BundleRegistryGasUsageTest:testGasRegisterWithSig() (gas: 826403)
BundleRegistryGasUsageTest:testGasRegisterWithSig() (gas: 826601)
BundleRegistryGasUsageTest:testGasTrustedBatchRegister() (gas: 6744222)
BundleRegistryGasUsageTest:testGasTrustedRegister() (gas: 852391)
IdRegistryGasUsageTest:testGasRegister() (gas: 734576)
IdRegistryGasUsageTest:testGasRegisterForAndRecover() (gas: 1702036)
IdRegistryGasUsageTest:testGasRegisterFromTrustedCaller() (gas: 808056)
StorageRentGasUsageTest:testGasBatchCredit() (gas: 168903)
StorageRentGasUsageTest:testGasBatchRent() (gas: 267026)
StorageRentGasUsageTest:testGasContinuousCredit() (gas: 142400)
StorageRentGasUsageTest:testGasCredit() (gas: 78390)
StorageRentGasUsageTest:testGasRent() (gas: 159486)
StorageRegistryGasUsageTest:testGasBatchCredit() (gas: 168903)
StorageRegistryGasUsageTest:testGasBatchRent() (gas: 267026)
StorageRegistryGasUsageTest:testGasContinuousCredit() (gas: 142400)
StorageRegistryGasUsageTest:testGasCredit() (gas: 78390)
StorageRegistryGasUsageTest:testGasRent() (gas: 159486)
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
This repository contains all the contracts deployed by the [Farcaster protocol](https://github.com/farcasterxyz/protocol). The contracts are:

1. **[Id Registry](./src/IdRegistry.sol)** - issues farcaster identities (fids) to new users.
2. **[Storage](./src/StorageRent.sol)** - allocates storage to fids and collects rent.
2. **[Storage Registry](./src/StorageRegistry.sol)** - allocates storage to fids and collects rent.
3. **[Key Registry](./src/KeyRegistry.sol)** - allows users with an fid to register key pairs for signing messages.
4. **[Bundler](./src/Bundler.sol)** - allows calling registry and storage in a single transaction.
5. **[Fname Resolver](./src/FnameResolver.sol)** - validates Farcaster ENS names which were issued off-chain.
Expand Down
12 changes: 6 additions & 6 deletions docs/docs.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,15 @@ graph TD
end
subgraph Identity
BN(Bundler) --> IR(Id Registry) & SR(Storage) & KR(Key Registry)
BN(Bundler) --> IR(Id Registry) & SR(Storage Registry) & KR(Key Registry)
KR --> IR
end
```

## Table of Contents

1. [Id Registry](#1-id-registry)
2. [Storage](#2-storage)
2. [Storage Registry](#2-storage)
3. [Key Registry](#3-key-registry)
4. [Bundler](#4-bundler)
5. [Fname Resolver](#5-fname-resolver)
Expand Down Expand Up @@ -80,9 +80,9 @@ The IdRegistry contract may need to be upgraded in case a bug is discovered or t
5. A new Bundler contract is deployed, pointing to the correct contracts.
6. The new IdRegistry is moved to the registrable state where anyone can register an fid.

# 2. Storage
# 2. Storage Registry

The Storage contract lets anyone rent units of storage space on Farcaster Hubs for a given fid. Payment must be made in Ethereum to acquire storage for a year. Acquiring storage emits an event that is read off-chain by the Farcaster Hubs, which allocate space to the user. The contract will deprecate itself one year after deployment, and we expect to launch a new contract with updated logic.
The StorageRegistry contract lets anyone rent units of storage space on Farcaster Hubs for a given fid. Payment must be made in Ethereum to acquire storage for a year. Acquiring storage emits an event that is read off-chain by the Farcaster Hubs, which allocate space to the user. The contract will deprecate itself one year after deployment, and we expect to launch a new contract with updated logic.

### Pricing

Expand All @@ -105,7 +105,7 @@ A price refresh occurs when a transaction is made after the cache period has pas

### Migration

The Storage contract does not contain any special states for migration. Once deployed, the operator can use the credit functions to award storage
The StorageRegistry contract does not contain any special states for migration. Once deployed, the operator can use the credit functions to award storage
units to fids if necessary.

### Administration
Expand All @@ -118,7 +118,7 @@ An `admin` address can modify many parameters including the total supply of stor

### Upgradeability

The Storage contract may need to be upgraded in case a bug is discovered or the logic needs to be changed. In such cases:
The StorageRegistry contract may need to be upgraded in case a bug is discovered or the logic needs to be changed. In such cases:

1. A new storage contract is deployed and is paused so that storage cannot be rented.
2. Hubs are upgraded so that they respect storage events from both contracts.
Expand Down
18 changes: 10 additions & 8 deletions script/Deploy.s.sol
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
pragma solidity 0.8.21;

import {IdRegistry} from "../src/IdRegistry.sol";
import {StorageRent} from "../src/StorageRent.sol";
import {StorageRegistry} from "../src/StorageRegistry.sol";
import {KeyRegistry} from "../src/KeyRegistry.sol";
import {Bundler} from "../src/Bundler.sol";
import {ImmutableCreate2Deployer} from "./lib/ImmutableCreate2Deployer.sol";
Expand Down Expand Up @@ -36,7 +36,7 @@ contract Deploy is ImmutableCreate2Deployer {
}

struct Contracts {
StorageRent storageRent;
StorageRegistry storageRegistry;
IdRegistry idRegistry;
KeyRegistry keyRegistry;
Bundler bundler;
Expand All @@ -47,10 +47,10 @@ contract Deploy is ImmutableCreate2Deployer {
}

function runDeploy(DeploymentParams memory params) public returns (Contracts memory) {
address storageRent = register(
"StorageRent",
address storageRegistry = register(
"StorageRegistry",
STORAGE_RENT_CREATE2_SALT,
type(StorageRent).creationCode,
type(StorageRegistry).creationCode,
abi.encode(
params.priceFeed,
params.uptimeFeed,
Expand Down Expand Up @@ -82,13 +82,15 @@ contract Deploy is ImmutableCreate2Deployer {
"Bundler",
BUNDLER_CREATE2_SALT,
type(Bundler).creationCode,
abi.encode(idRegistry, storageRent, keyRegistry, params.bundlerTrustedCaller, params.initialBundlerOwner)
abi.encode(
idRegistry, storageRegistry, keyRegistry, params.bundlerTrustedCaller, params.initialBundlerOwner
)
);

deploy();

return Contracts({
storageRent: StorageRent(storageRent),
storageRegistry: StorageRegistry(storageRegistry),
idRegistry: IdRegistry(idRegistry),
keyRegistry: KeyRegistry(keyRegistry),
bundler: Bundler(payable(bundler))
Expand All @@ -101,7 +103,7 @@ contract Deploy is ImmutableCreate2Deployer {
vm.startBroadcast();
contracts.idRegistry.setTrustedCaller(bundler);
contracts.keyRegistry.setTrustedCaller(bundler);
contracts.storageRent.grantRole(keccak256("OPERATOR_ROLE"), bundler);
contracts.storageRegistry.grantRole(keccak256("OPERATOR_ROLE"), bundler);
vm.stopBroadcast();
}

Expand Down
6 changes: 3 additions & 3 deletions script/LocalDeploy.s.sol
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import "forge-std/console.sol";
import {AggregatorV3Interface} from "chainlink/v0.8/interfaces/AggregatorV3Interface.sol";

import {IdRegistry} from "../src/IdRegistry.sol";
import {StorageRent} from "../src/StorageRent.sol";
import {StorageRegistry} from "../src/StorageRegistry.sol";
import {KeyRegistry} from "../src/KeyRegistry.sol";
import {MockPriceFeed, MockUptimeFeed, MockChainlinkFeed} from "../test/Utils.sol";

Expand Down Expand Up @@ -43,7 +43,7 @@ contract LocalDeploy is Script {
KEY_REGISTRY_MIGRATION_GRACE_PERIOD,
initialKeyRegistryOwner
);
StorageRent storageRent = new StorageRent{ salt: STORAGE_RENT_CREATE2_SALT }(
StorageRegistry storageRegistry = new StorageRegistry{ salt: STORAGE_RENT_CREATE2_SALT }(
priceFeed,
uptimeFeed,
INITIAL_RENTAL_PERIOD,
Expand All @@ -58,7 +58,7 @@ contract LocalDeploy is Script {
vm.stopBroadcast();
console.log("ID Registry: %s", address(idRegistry));
console.log("Key Registry: %s", address(keyRegistry));
console.log("Storage Rent: %s", address(storageRent));
console.log("Storage Rent: %s", address(storageRegistry));
}

/* @dev Make an Anvil RPC call to deploy the same CREATE2 deployer Foundry uses on mainnet. */
Expand Down
8 changes: 4 additions & 4 deletions script/StorageRent.s.sol → script/StorageRegistry.s.sol
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
// SPDX-License-Identifier: UNLICENSED
pragma solidity 0.8.21;

import {StorageRent} from "../src/StorageRent.sol";
import {StorageRegistry} from "../src/StorageRegistry.sol";
import {ImmutableCreate2Deployer} from "./lib/ImmutableCreate2Deployer.sol";

contract StorageRentScript is ImmutableCreate2Deployer {
contract StorageRegistryScript is ImmutableCreate2Deployer {
uint256 internal constant INITIAL_RENTAL_PERIOD = 365 days;
uint256 internal constant INITIAL_USD_UNIT_PRICE = 5e8; // $5 USD
uint256 internal constant INITIAL_MAX_UNITS = 2_000_000;
Expand All @@ -21,8 +21,8 @@ contract StorageRentScript is ImmutableCreate2Deployer {
address treasurer = vm.envAddress("STORAGE_RENT_TREASURER_ADDRESS");

register(
"StorageRent",
type(StorageRent).creationCode,
"StorageRegistry",
type(StorageRegistry).creationCode,
abi.encode(
priceFeed,
uptimeFeed,
Expand Down
20 changes: 10 additions & 10 deletions src/Bundler.sol
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
pragma solidity 0.8.21;

import {IdRegistry} from "./IdRegistry.sol";
import {StorageRent} from "./StorageRent.sol";
import {StorageRegistry} from "./StorageRegistry.sol";
import {KeyRegistry} from "./KeyRegistry.sol";
import {TrustedCaller} from "./lib/TrustedCaller.sol";
import {TransferHelper} from "./lib/TransferHelper.sol";
Expand Down Expand Up @@ -58,12 +58,12 @@ contract Bundler is TrustedCaller {
IdRegistry public immutable idRegistry;

/**
* @dev Address of the StorageRent contract
* @dev Address of the StorageRegistry contract
*/
StorageRent public immutable storageRent;
StorageRegistry public immutable storageRegistry;

/**
* @dev Address of the StorageRent contract
* @dev Address of the StorageRegistry contract
*/
KeyRegistry public immutable keyRegistry;

Expand All @@ -76,19 +76,19 @@ contract Bundler is TrustedCaller {
* allowed to register during the bootstrap phase.
*
* @param _idRegistry Address of the IdRegistry contract
* @param _storageRent Address of the StorageRent contract
* @param _storageRegistry Address of the StorageRegistry contract
* @param _trustedCaller Address that can call trustedRegister and trustedBatchRegister
* @param _owner Address that can set the trusted caller
*/
constructor(
address _idRegistry,
address _storageRent,
address _storageRegistry,
address _keyRegistry,
address _trustedCaller,
address _owner
) TrustedCaller(_owner) {
idRegistry = IdRegistry(_idRegistry);
storageRent = StorageRent(_storageRent);
storageRegistry = StorageRegistry(_storageRegistry);
keyRegistry = KeyRegistry(_keyRegistry);
_setTrustedCaller(_trustedCaller);
}
Expand All @@ -114,7 +114,7 @@ contract Bundler is TrustedCaller {
keyRegistry.addFor(registration.to, signer.scheme, signer.key, signer.metadata, signer.deadline, signer.sig);
}

uint256 overpayment = storageRent.rent{value: msg.value}(fid, storageUnits);
uint256 overpayment = storageRegistry.rent{value: msg.value}(fid, storageUnits);

if (overpayment > 0) {
msg.sender.sendNative(overpayment);
Expand All @@ -140,7 +140,7 @@ contract Bundler is TrustedCaller {
// Will revert unless IdRegistry is in the Seedable phase
uint256 fid = idRegistry.trustedRegister(to, recovery);
keyRegistry.trustedAdd(to, scheme, key, metadata);
storageRent.credit(fid, storageUnits);
storageRegistry.credit(fid, storageUnits);
}

/**
Expand All @@ -155,7 +155,7 @@ contract Bundler is TrustedCaller {
for (uint256 i = 0; i < users.length; i++) {
uint256 fid = idRegistry.trustedRegister(users[i].to, users[i].recovery);
keyRegistry.trustedAdd(users[i].to, users[i].scheme, users[i].key, users[i].metadata);
storageRent.credit(fid, users[i].units);
storageRegistry.credit(fid, users[i].units);
}
}

Expand Down
4 changes: 2 additions & 2 deletions src/StorageRent.sol → src/StorageRegistry.sol
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,11 @@ import {FixedPointMathLib} from "solmate/src/utils/FixedPointMathLib.sol";
import {TransferHelper} from "./lib/TransferHelper.sol";

/**
* @title StorageRent
* @title StorageRegistry
*
* @notice See ../docs/docs.md for an overview.
*/
contract StorageRent is AccessControlEnumerable {
contract StorageRegistry is AccessControlEnumerable {
using FixedPointMathLib for uint256;
using TransferHelper for address;

Expand Down
10 changes: 5 additions & 5 deletions test/Bundler/Bundler.gas.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ contract BundleRegistryGasUsageTest is BundlerTestSuite {
for (uint256 i = 1; i < 10; i++) {
address account = vm.addr(i);
bytes memory sig = _signRegister(i, account, address(0), type(uint40).max);
uint256 price = storageRent.price(1);
uint256 price = storageRegistry.price(1);

Bundler.SignerParams[] memory signers = new Bundler.SignerParams[](0);

Expand All @@ -36,9 +36,9 @@ contract BundleRegistryGasUsageTest is BundlerTestSuite {
keyRegistry.setTrustedCaller(address(bundler));
vm.stopPrank();

bytes32 operatorRoleId = storageRent.operatorRoleId();
bytes32 operatorRoleId = storageRegistry.operatorRoleId();
vm.prank(roleAdmin);
storageRent.grantRole(operatorRoleId, address(bundler));
storageRegistry.grantRole(operatorRoleId, address(bundler));

for (uint256 i = 0; i < 10; i++) {
address account = address(uint160(i));
Expand All @@ -53,9 +53,9 @@ contract BundleRegistryGasUsageTest is BundlerTestSuite {
keyRegistry.setTrustedCaller(address(bundler));
vm.stopPrank();

bytes32 operatorRoleId = storageRent.operatorRoleId();
bytes32 operatorRoleId = storageRegistry.operatorRoleId();
vm.prank(roleAdmin);
storageRent.grantRole(operatorRoleId, address(bundler));
storageRegistry.grantRole(operatorRoleId, address(bundler));

for (uint256 i = 0; i < 10; i++) {
Bundler.UserData[] memory batchArray = new Bundler.UserData[](10);
Expand Down
Loading

0 comments on commit ddbf16c

Please sign in to comment.