Skip to content

Commit

Permalink
refactor: add interfaces (#377)
Browse files Browse the repository at this point in the history
* refactor: add interfaces for client consumption

* chore: comment fixes

* chore: add public state vars to interfaces

---------

Co-authored-by: Kartik <[email protected]>
  • Loading branch information
horsefacts and Slokh authored Aug 28, 2023
1 parent 2c6db9b commit 3e8e925
Show file tree
Hide file tree
Showing 14 changed files with 925 additions and 176 deletions.
2 changes: 1 addition & 1 deletion script/DeployL2.s.sol
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import {IdRegistry} from "../src/IdRegistry.sol";
import {StorageRegistry} from "../src/StorageRegistry.sol";
import {KeyRegistry} from "../src/KeyRegistry.sol";
import {SignedKeyRequestValidator} from "../src/validators/SignedKeyRequestValidator.sol";
import {Bundler} from "../src/Bundler.sol";
import {Bundler, IBundler} from "../src/Bundler.sol";
import {RecoveryProxy} from "../src/RecoveryProxy.sol";
import {IMetadataValidator} from "../src/interfaces/IMetadataValidator.sol";
import {console, ImmutableCreate2Deployer} from "./lib/ImmutableCreate2Deployer.sol";
Expand Down
41 changes: 2 additions & 39 deletions src/Bundler.sol
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,11 @@ pragma solidity 0.8.21;
import {IdRegistry} from "./IdRegistry.sol";
import {StorageRegistry} from "./StorageRegistry.sol";
import {KeyRegistry} from "./KeyRegistry.sol";
import {IBundler} from "./interfaces/IBundler.sol";
import {TrustedCaller} from "./lib/TrustedCaller.sol";
import {TransferHelper} from "./lib/TransferHelper.sol";

contract Bundler is TrustedCaller {
contract Bundler is IBundler, TrustedCaller {
using TransferHelper for address;

/*//////////////////////////////////////////////////////////////
Expand All @@ -20,44 +21,6 @@ contract Bundler is TrustedCaller {
/// @dev Revert if the caller attempts to rent zero storage units.
error InvalidAmount();

/*//////////////////////////////////////////////////////////////
STRUCTS
//////////////////////////////////////////////////////////////*/

/// @notice Data needed to trusted register a user with the fid and storage contracts.
struct UserData {
address to;
address recovery;
SignerData[] signers;
uint256 units;
}

/// @notice Data needed to trusted register a signer with the key registry
struct SignerData {
uint32 keyType;
bytes key;
uint8 metadataType;
bytes metadata;
}

/// @notice Data needed to register an fid with signature.
struct RegistrationParams {
address to;
address recovery;
uint256 deadline;
bytes sig;
}

/// @notice Data needed to add a signer with signature.
struct SignerParams {
uint32 keyType;
bytes key;
uint8 metadataType;
bytes metadata;
uint256 deadline;
bytes sig;
}

/*//////////////////////////////////////////////////////////////
CONSTANTS
//////////////////////////////////////////////////////////////*/
Expand Down
3 changes: 2 additions & 1 deletion src/IdRegistry.sol
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import {SignatureChecker} from "openzeppelin/contracts/utils/cryptography/Signat
import {Nonces} from "openzeppelin-latest/contracts/utils/Nonces.sol";
import {Pausable} from "openzeppelin/contracts/security/Pausable.sol";

import {IIdRegistry} from "./interfaces/IIdRegistry.sol";
import {EIP712} from "./lib/EIP712.sol";
import {Signatures} from "./lib/Signatures.sol";
import {TrustedCaller} from "./lib/TrustedCaller.sol";
Expand All @@ -14,7 +15,7 @@ import {TrustedCaller} from "./lib/TrustedCaller.sol";
*
* @notice See ../docs/docs.md for an overview.
*/
contract IdRegistry is TrustedCaller, Signatures, Pausable, EIP712, Nonces {
contract IdRegistry is IIdRegistry, TrustedCaller, Signatures, Pausable, EIP712, Nonces {
/*//////////////////////////////////////////////////////////////
ERRORS
//////////////////////////////////////////////////////////////*/
Expand Down
69 changes: 4 additions & 65 deletions src/KeyRegistry.sol
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,11 @@ pragma solidity 0.8.21;
import {Nonces} from "openzeppelin-latest/contracts/utils/Nonces.sol";
import {Pausable} from "openzeppelin/contracts/security/Pausable.sol";

import {EIP712} from "./lib/EIP712.sol";
import {IdRegistry} from "./IdRegistry.sol";
import {IdRegistryLike} from "./interfaces/IdRegistryLike.sol";
import {IKeyRegistry} from "./interfaces/IKeyRegistry.sol";
import {IMetadataValidator} from "./interfaces/IMetadataValidator.sol";
import {IdRegistry} from "./IdRegistry.sol";
import {EIP712} from "./lib/EIP712.sol";
import {Signatures} from "./lib/Signatures.sol";
import {TrustedCaller} from "./lib/TrustedCaller.sol";

Expand All @@ -17,33 +18,7 @@ import {TrustedCaller} from "./lib/TrustedCaller.sol";
* @notice See ../docs/docs.md for an overview.
*/

contract KeyRegistry is TrustedCaller, Signatures, Pausable, EIP712, Nonces {
/**
* @notice State enumeration for a key in the registry. During migration, an admin can change
* the state of any fids key from NULL to ADDED or ADDED to NULL. After migration, an
* fid can change the state of a key from NULL to ADDED or ADDED to REMOVED only.
*
* - NULL: The key is not in the registry.
* - ADDED: The key has been added to the registry.
* - REMOVED: The key was added to the registry but is now removed.
*/
enum KeyState {
NULL,
ADDED,
REMOVED
}

/**
* @notice Data about a key.
*
* @param state The current state of the key.
* @param keyType Numeric ID representing the manner in which the key should be used.
*/
struct KeyData {
KeyState state;
uint32 keyType;
}

contract KeyRegistry is IKeyRegistry, TrustedCaller, Signatures, Pausable, EIP712, Nonces {
/*//////////////////////////////////////////////////////////////
ERRORS
//////////////////////////////////////////////////////////////*/
Expand Down Expand Up @@ -374,42 +349,6 @@ contract KeyRegistry is TrustedCaller, Signatures, Pausable, EIP712, Nonces {
MIGRATION
//////////////////////////////////////////////////////////////*/

/**
* @dev Struct argument for bulk add function, representing an FID
* and its associated keys.
*
* @param fid Fid associated with provided keys to add.
* @param keys Array of BulkAddKey structs, including key and metadata.
*/
struct BulkAddData {
uint256 fid;
BulkAddKey[] keys;
}

/**
* @dev Struct argument for bulk add function, representing a key
* and its associated metadata.
*
* @param key Bytes of the signer key.
* @param keys Metadata metadata of the signer key.
*/
struct BulkAddKey {
bytes key;
bytes metadata;
}

/**
* @dev Struct argument for bulk reset function, representing an FID
* and its associated keys.
*
* @param fid Fid associated with provided keys to reset.
* @param keys Array of keys to reset.
*/
struct BulkResetData {
uint256 fid;
bytes[] keys;
}

/**
* @notice Set the time of the key migration and emit an event. Hubs will watch this event and
* cut over to use the onchain registry as their source of truth after this timestamp.
Expand Down
3 changes: 2 additions & 1 deletion src/StorageRegistry.sol
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,15 @@ import {AccessControlEnumerable} from "openzeppelin/contracts/access/AccessContr
import {Pausable} from "openzeppelin/contracts/security/Pausable.sol";
import {FixedPointMathLib} from "solmate/src/utils/FixedPointMathLib.sol";

import {IStorageRegistry} from "./interfaces/IStorageRegistry.sol";
import {TransferHelper} from "./lib/TransferHelper.sol";

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

Expand Down
90 changes: 90 additions & 0 deletions src/interfaces/IBundler.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
// SPDX-License-Identifier: UNLICENSED
pragma solidity ^0.8.21;

interface IBundler {
/*//////////////////////////////////////////////////////////////
STRUCTS
//////////////////////////////////////////////////////////////*/

/// @notice Data needed to trusted register a user with the fid and storage contracts.
struct UserData {
address to;
address recovery;
SignerData[] signers;
uint256 units;
}

/// @notice Data needed to trusted register a signer with the key registry
struct SignerData {
uint32 keyType;
bytes key;
uint8 metadataType;
bytes metadata;
}

/// @notice Data needed to register an fid with signature.
struct RegistrationParams {
address to;
address recovery;
uint256 deadline;
bytes sig;
}

/// @notice Data needed to add a signer with signature.
struct SignerParams {
uint32 keyType;
bytes key;
uint8 metadataType;
bytes metadata;
uint256 deadline;
bytes sig;
}

/*//////////////////////////////////////////////////////////////
CONSTANTS
//////////////////////////////////////////////////////////////*/

/**
* @notice Contract version specified in the Farcaster protocol version scheme.
*/
function VERSION() external view returns (string memory);

/*//////////////////////////////////////////////////////////////
REGISTRATION
//////////////////////////////////////////////////////////////*/

/**
* @notice Register an fid, multiple signers, and rent storage to an address in a single transaction.
*
* @param registration Struct containing registration parameters: to, recovery, deadline, and signature.
* @param signers Array of structs containing signer parameters: keyType, key, metadataType, metadata, deadline, and signature.
* @param storageUnits Number of storage units to rent
*
*/
function register(
RegistrationParams calldata registration,
SignerParams[] calldata signers,
uint256 storageUnits
) external payable;

/*//////////////////////////////////////////////////////////////
PERMISSIONED ACTIONS
//////////////////////////////////////////////////////////////*/

/**
* @notice Register an fid, add a signer, and credit storage to an address in a single transaction. Can only
* be called by the trustedCaller during the Seedable phase.
*
* @param user UserData struct including to/recovery address, key params, and number of storage units.
*/
function trustedRegister(UserData calldata user) external;

/**
* @notice Register fids, keys, and credit storage for multiple users in a single transaction. Can
* only be called by the trustedCaller during the Seedable phase. Will be used when
* migrating across Ethereum networks to bootstrap a new contract with existing data.
*
* @param users Array of UserData structs to register
*/
function trustedBatchRegister(UserData[] calldata users) external;
}
Loading

0 comments on commit 3e8e925

Please sign in to comment.