Skip to content

Commit

Permalink
Metadata Functions (#989)
Browse files Browse the repository at this point in the history
* Added a `name` and `version` function to each of the Hyperdrive instances

* Add `name` and `version` functions to the `HyperdriveFactory`

* Added a `name` and `version` function to the deployer coordinators

* Added a `name` and `version` function to the registry

* Fixed the rust tests

* Fixed the rust tests

* Addressed review feedback from @jrhea and @mcclurejt

* Used the constant for the `HyperdriveRegistry`

* Fixed remaining nit
  • Loading branch information
jalextowle authored Apr 18, 2024
1 parent 78a1b59 commit abd8f92
Show file tree
Hide file tree
Showing 36 changed files with 323 additions and 70 deletions.
11 changes: 11 additions & 0 deletions contracts/src/deployers/HyperdriveDeployerCoordinator.sol
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { IHyperdrive } from "../interfaces/IHyperdrive.sol";
import { IHyperdriveCoreDeployer } from "../interfaces/IHyperdriveCoreDeployer.sol";
import { IHyperdriveDeployerCoordinator } from "../interfaces/IHyperdriveDeployerCoordinator.sol";
import { IHyperdriveTargetDeployer } from "../interfaces/IHyperdriveTargetDeployer.sol";
import { VERSION } from "../libraries/Constants.sol";
import { ONE } from "../libraries/FixedPointMath.sol";

/// @author DELV
Expand Down Expand Up @@ -103,6 +104,16 @@ abstract contract HyperdriveDeployerCoordinator is
_;
}

/// @notice Returns the deployer coordinator's name.
/// @notice The deployer coordinator's name.
function name() external pure virtual returns (string memory);

/// @notice Returns the deployer coordinator's version.
/// @notice The deployer coordinator's version.
function version() external pure returns (string memory) {
return VERSION;
}

/// @notice Deploys a Hyperdrive instance with the given parameters.
/// @dev This can only be deployed by the associated factory.
/// @param _deploymentId The ID of the deployment.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,10 @@ import { HyperdriveDeployerCoordinator } from "../HyperdriveDeployerCoordinator.
contract ERC4626HyperdriveDeployerCoordinator is HyperdriveDeployerCoordinator {
using SafeERC20 for ERC20;

/// @notice The deployer coordinator's name.
string public constant override name =
"ERC4626HyperdriveDeployerCoordinator";

/// @notice Instantiates the deployer coordinator.
/// @param _factory The factory that this deployer will be registered with.
/// @param _coreDeployer The core deployer.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@ contract EzETHHyperdriveDeployerCoordinator is HyperdriveDeployerCoordinator {
using SafeERC20 for ERC20;
using FixedPointMath for uint256;

/// @notice The deployer coordinator's name.
string public constant override name = "EzETHHyperdriveDeployerCoordinator";

/// @notice The Renzo contract.
IRestakeManager public immutable restakeManager;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@ contract LsETHHyperdriveDeployerCoordinator is HyperdriveDeployerCoordinator {
using SafeERC20 for ERC20;
using FixedPointMath for uint256;

/// @notice The deployer coordinator's name.
string public constant override name = "LsETHHyperdriveDeployerCoordinator";

/// @dev The LsETH contract.
IRiverV1 internal immutable river;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@ contract RETHHyperdriveDeployerCoordinator is HyperdriveDeployerCoordinator {
using SafeERC20 for ERC20;
using FixedPointMath for uint256;

/// @notice The deployer coordinator's name.
string public constant override name = "RETHHyperdriveDeployerCoordinator";

/// @dev The Rocket Token RETH contract.
IRocketTokenRETH internal immutable rocketTokenReth;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@ import { HyperdriveDeployerCoordinator } from "../HyperdriveDeployerCoordinator.
contract StETHHyperdriveDeployerCoordinator is HyperdriveDeployerCoordinator {
using FixedPointMath for uint256;

/// @notice The deployer coordinator's name.
string public constant override name = "StETHHyperdriveDeployerCoordinator";

/// @notice The Lido contract.
ILido public immutable lido;

Expand Down
11 changes: 11 additions & 0 deletions contracts/src/external/HyperdriveTarget0.sol
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import { HyperdriveMultiToken } from "../internal/HyperdriveMultiToken.sol";
import { HyperdriveShort } from "../internal/HyperdriveShort.sol";
import { HyperdriveStorage } from "../internal/HyperdriveStorage.sol";
import { AssetId } from "../libraries/AssetId.sol";
import { VERSION } from "../libraries/Constants.sol";
import { FixedPointMath } from "../libraries/FixedPointMath.sol";
import { LPMath } from "../libraries/LPMath.sol";

Expand Down Expand Up @@ -229,6 +230,16 @@ abstract contract HyperdriveTarget0 is

/// Getters ///

/// @notice Gets the instance's name.
/// @return The instance's name.
function name() external pure virtual returns (string memory);

/// @notice Gets the instance's version.
/// @return The instance's version.
function version() external pure returns (string memory) {
_revert(abi.encode(VERSION));
}

/// @notice Gets the pauser status of an address.
/// @param _account The account to check.
/// @return The pauser status.
Expand Down
13 changes: 12 additions & 1 deletion contracts/src/factory/HyperdriveFactory.sol
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { IHyperdrive } from "../interfaces/IHyperdrive.sol";
import { IHyperdriveFactory } from "../interfaces/IHyperdriveFactory.sol";
import { IHyperdriveDeployerCoordinator } from "../interfaces/IHyperdriveDeployerCoordinator.sol";
import { FixedPointMath, ONE } from "../libraries/FixedPointMath.sol";
import { VERSION } from "../libraries/Constants.sol";
import { HyperdriveMath } from "../libraries/HyperdriveMath.sol";

/// @author DELV
Expand All @@ -17,6 +18,12 @@ import { HyperdriveMath } from "../libraries/HyperdriveMath.sol";
contract HyperdriveFactory is IHyperdriveFactory {
using FixedPointMath for uint256;

/// @notice The factory's name.
string public name;

/// @notice The factory's version.
string public constant version = VERSION;

/// @dev Signifies an unlocked receive function, used by isReceiveLocked
uint256 private constant RECEIVE_UNLOCKED = 1;

Expand Down Expand Up @@ -165,7 +172,11 @@ contract HyperdriveFactory is IHyperdriveFactory {

/// @notice Initializes the factory.
/// @param _factoryConfig Configuration of the Hyperdrive Factory.
constructor(FactoryConfig memory _factoryConfig) {
/// @param _name The factory's name.
constructor(FactoryConfig memory _factoryConfig, string memory _name) {
// Set the factory's name.
name = _name;

// Ensure that the minimum checkpoint duration is greater than or equal
// to the checkpoint duration resolution and is a multiple of the
// checkpoint duration resolution.
Expand Down
15 changes: 14 additions & 1 deletion contracts/src/factory/HyperdriveRegistry.sol
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,30 @@ pragma solidity 0.8.20;

import { IHyperdriveGovernedRegistry } from "../interfaces/IHyperdriveGovernedRegistry.sol";
import { IHyperdriveRegistry } from "../interfaces/IHyperdriveRegistry.sol";
import { VERSION } from "../libraries/Constants.sol";

contract HyperdriveRegistry is
IHyperdriveRegistry,
IHyperdriveGovernedRegistry
{
/// @notice The registry's name.
string public name;

/// @notice The registry's version.
string public constant version = VERSION;

/// @notice The registry's governance address.
address public governance;

/// @notice A mapping from hyperdrive instances to info associated with
/// those instances.
mapping(address hyperdrive => uint256 data) internal _hyperdriveInfo;

constructor() {
/// @notice Instantiates the hyperdrive registry.
/// @param _name The registry's name.
constructor(string memory _name) {
governance = msg.sender;
name = _name;
}

modifier onlyGovernance() {
Expand Down
9 changes: 9 additions & 0 deletions contracts/src/instances/erc4626/ERC4626Target0.sol
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,18 @@ import { ERC4626Base } from "./ERC4626Base.sol";
/// only, and is not intended to, and does not, have any
/// particular legal or regulatory significance.
contract ERC4626Target0 is HyperdriveTarget0, ERC4626Base {
/// @dev The instance's name.
string internal constant NAME = "ERC4626Hyperdrive";

/// @notice Initializes the target0 contract.
/// @param _config The configuration of the Hyperdrive pool.
constructor(
IHyperdrive.PoolConfig memory _config
) HyperdriveTarget0(_config) {}

/// @notice Returns the instance's name.
/// @return The instance's name.
function name() external pure override returns (string memory) {
_revert(abi.encode(NAME));
}
}
9 changes: 9 additions & 0 deletions contracts/src/instances/ezeth/EzETHTarget0.sol
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@ import { EzETHBase } from "./EzETHBase.sol";
contract EzETHTarget0 is HyperdriveTarget0, EzETHBase {
using SafeERC20 for ERC20;

/// @dev The instance's name.
string internal constant NAME = "EzETHHyperdrive";

/// @notice Initializes the target0 contract.
/// @param _config The configuration of the Hyperdrive pool.
/// @param _restakeManager The Renzo contract.
Expand All @@ -29,6 +32,12 @@ contract EzETHTarget0 is HyperdriveTarget0, EzETHBase {

/// Extras ///

/// @notice Returns the instance's name.
/// @return The instance's name.
function name() external pure override returns (string memory) {
_revert(abi.encode(NAME));
}

/// @notice Returns the Renzo contract.
/// @return The Renzo contract.
function renzo() external view returns (IRestakeManager) {
Expand Down
9 changes: 9 additions & 0 deletions contracts/src/instances/lseth/LsETHTarget0.sol
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@ import { LsETHBase } from "./LsETHBase.sol";
/// only, and is not intended to, and does not, have any
/// particular legal or regulatory significance.
contract LsETHTarget0 is HyperdriveTarget0, LsETHBase {
/// @dev The instance's name.
string internal constant NAME = "LsETHHyperdrive";

/// @notice Initializes the target0 contract.
/// @param _config The configuration of the Hyperdrive pool.
constructor(
Expand All @@ -22,6 +25,12 @@ contract LsETHTarget0 is HyperdriveTarget0, LsETHBase {

/// Getters ///

/// @notice Returns the instance's name.
/// @return The instance's name.
function name() external pure override returns (string memory) {
_revert(abi.encode(NAME));
}

/// @notice Returns the MultiToken's decimals.
/// @return The MultiToken's decimals.
function decimals() external pure override returns (uint8) {
Expand Down
9 changes: 9 additions & 0 deletions contracts/src/instances/reth/RETHTarget0.sol
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@ import { RETHBase } from "./RETHBase.sol";
/// only, and is not intended to, and does not, have any
/// particular legal or regulatory significance.
contract RETHTarget0 is HyperdriveTarget0, RETHBase {
/// @dev The instance's name.
string internal constant NAME = "RETHHyperdrive";

/// @notice Initializes the target0 contract.
/// @param _config The configuration of the Hyperdrive pool.
constructor(
Expand All @@ -22,6 +25,12 @@ contract RETHTarget0 is HyperdriveTarget0, RETHBase {

/// Getters ///

/// @notice Returns the instance's name.
/// @return The instance's name.
function name() external pure override returns (string memory) {
_revert(abi.encode(NAME));
}

/// @notice Returns the MultiToken's decimals.
/// @return The MultiToken's decimals.
function decimals() external pure override returns (uint8) {
Expand Down
9 changes: 9 additions & 0 deletions contracts/src/instances/steth/StETHTarget0.sol
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@ import { StETHBase } from "./StETHBase.sol";
/// only, and is not intended to, and does not, have any
/// particular legal or regulatory significance.
contract StETHTarget0 is HyperdriveTarget0, StETHBase {
/// @dev The instance's name.
string internal constant NAME = "StETHHyperdrive";

/// @notice Initializes the target0 contract.
/// @param _config The configuration of the Hyperdrive pool.
constructor(
Expand All @@ -22,6 +25,12 @@ contract StETHTarget0 is HyperdriveTarget0, StETHBase {

/// Getters ///

/// @notice Returns the instance's name.
/// @return The instance's name.
function name() external pure override returns (string memory) {
_revert(abi.encode(NAME));
}

/// @notice Returns the MultiToken's decimals.
/// @return The MultiToken's decimals.
function decimals() external pure override returns (uint8) {
Expand Down
8 changes: 8 additions & 0 deletions contracts/src/interfaces/IHyperdriveDeployerCoordinator.sol
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,14 @@ interface IHyperdriveDeployerCoordinator {

/// Functions ///

/// @notice Returns the deployer coordinator's name.
/// @return The deployer coordinator's name.
function name() external pure returns (string memory);

/// @notice Returns the deployer coordinator's version.
/// @return The deployer coordinator's version.
function version() external pure returns (string memory);

/// @notice Deploys a Hyperdrive instance with the given parameters.
/// @param _deploymentId The ID of the deployment.
/// @param _deployConfig The deploy configuration of the Hyperdrive pool.
Expand Down
4 changes: 3 additions & 1 deletion contracts/src/interfaces/IHyperdriveGovernedRegistry.sol
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
// SPDX-License-Identifier: Apache-2.0
pragma solidity 0.8.20;

interface IHyperdriveGovernedRegistry {
import { IHyperdriveRegistry } from "./IHyperdriveRegistry.sol";

interface IHyperdriveGovernedRegistry is IHyperdriveRegistry {
/// @notice Emitted when governance is transferred.
event GovernanceUpdated(address indexed governance);

Expand Down
8 changes: 8 additions & 0 deletions contracts/src/interfaces/IHyperdriveRead.sol
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,14 @@ import { IHyperdrive } from "./IHyperdrive.sol";
import { IMultiTokenRead } from "./IMultiTokenRead.sol";

interface IHyperdriveRead is IMultiTokenRead {
/// @notice Gets the instance's name.
/// @return The instance's name.
function name() external pure returns (string memory);

/// @notice Gets the instance's version.
/// @return The instance's version.
function version() external pure returns (string memory);

/// @notice Gets the Hyperdrive pool's base token.
/// @return The base token.
function baseToken() external view returns (address);
Expand Down
3 changes: 3 additions & 0 deletions contracts/src/libraries/Constants.sol
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,6 @@ pragma solidity 0.8.20;

/// @dev The placeholder address for ETH.
address constant ETH = 0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE;

/// @dev The version of the contracts.
string constant VERSION = "v1.0.2";
2 changes: 2 additions & 0 deletions contracts/test/MockHyperdrive.sol
Original file line number Diff line number Diff line change
Expand Up @@ -447,6 +447,8 @@ contract MockHyperdrive is Hyperdrive, MockHyperdriveBase {
}

contract MockHyperdriveTarget0 is HyperdriveTarget0, MockHyperdriveBase {
string public constant override name = "MockHyperdrive";

constructor(
IHyperdrive.PoolConfig memory _config
) HyperdriveTarget0(_config) {}
Expand Down
5 changes: 5 additions & 0 deletions contracts/test/MockHyperdriveDeployer.sol
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,14 @@ import { IERC20 } from "contracts/src/interfaces/IERC20.sol";
import { IHyperdrive } from "contracts/src/interfaces/IHyperdrive.sol";
import { IHyperdriveDeployerCoordinator } from "contracts/src/interfaces/IHyperdriveDeployerCoordinator.sol";
import { IHyperdriveTargetDeployer } from "contracts/src/interfaces/IHyperdriveTargetDeployer.sol";
import { VERSION } from "contracts/src/libraries/Constants.sol";
import { MockHyperdrive } from "./MockHyperdrive.sol";

contract MockHyperdriveDeployer is IHyperdriveDeployerCoordinator {
string public constant name = "MockHyperdriveDeployer";

string public constant version = VERSION;

mapping(address => mapping(bytes32 => address)) internal _deployments;

function deploy(
Expand Down
Loading

0 comments on commit abd8f92

Please sign in to comment.