Skip to content

Commit

Permalink
Add new type of metadata renderer
Browse files Browse the repository at this point in the history
  • Loading branch information
neokry committed Jul 24, 2023
1 parent 682d317 commit 67d8f8e
Show file tree
Hide file tree
Showing 23 changed files with 577 additions and 107 deletions.
7 changes: 3 additions & 4 deletions script/DeployContracts.s.sol
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,11 @@ import { Strings } from "@openzeppelin/contracts/utils/Strings.sol";

import { IManager, Manager } from "../src/manager/Manager.sol";
import { IToken, Token } from "../src/token/Token.sol";
import { MetadataRenderer } from "../src/token/metadata/MetadataRenderer.sol";
import { IAuction, Auction } from "../src/auction/Auction.sol";
import { IGovernor, Governor } from "../src/governance/governor/Governor.sol";
import { ITreasury, Treasury } from "../src/governance/treasury/Treasury.sol";
import { MetadataRenderer } from "../src/token/metadata/MetadataRenderer.sol";
import { MetadataRendererTypesV1 } from "../src/token/metadata/types/MetadataRendererTypesV1.sol";
import { PropertyMetadata } from "../src/metadata/property/PropertyMetadata.sol";
import { PropertyMetadataTypesV1 } from "../src/metadata/property/types/PropertyMetadataTypesV1.sol";
import { ERC1967Proxy } from "../src/lib/proxy/ERC1967Proxy.sol";

contract DeployContracts is Script {
Expand Down Expand Up @@ -46,7 +45,7 @@ contract DeployContracts is Script {
address tokenImpl = address(new Token(address(manager)));

// Deploy metadata renderer implementation
address metadataRendererImpl = address(new MetadataRenderer(address(manager)));
address metadataRendererImpl = address(new PropertyMetadata(address(manager)));

// Deploy auction house implementation
address auctionImpl = address(new Auction(address(manager), weth));
Expand Down
7 changes: 3 additions & 4 deletions script/DeployMetadataUpgrade.s.sol
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,11 @@ import { Strings } from "@openzeppelin/contracts/utils/Strings.sol";

import { IManager, Manager } from "../src/manager/Manager.sol";
import { IToken, Token } from "../src/token/Token.sol";
import { MetadataRenderer } from "../src/token/metadata/MetadataRenderer.sol";
import { IAuction, Auction } from "../src/auction/Auction.sol";
import { IGovernor, Governor } from "../src/governance/governor/Governor.sol";
import { ITreasury, Treasury } from "../src/governance/treasury/Treasury.sol";
import { MetadataRenderer } from "../src/token/metadata/MetadataRenderer.sol";
import { MetadataRendererTypesV1 } from "../src/token/metadata/types/MetadataRendererTypesV1.sol";
import { PropertyMetadata } from "../src/metadata/property/PropertyMetadata.sol";
import { PropertyMetadataTypesV1 } from "../src/metadata/property/types/PropertyMetadataTypesV1.sol";
import { ERC1967Proxy } from "../src/lib/proxy/ERC1967Proxy.sol";

contract DeployMetadataUpgrade is Script {
Expand Down Expand Up @@ -52,7 +51,7 @@ contract DeployMetadataUpgrade is Script {
Manager manager = Manager(managerProxy);

// Deploy metadata renderer implementation
address metadataRendererImpl = address(new MetadataRenderer(managerProxy));
address metadataRendererImpl = address(new PropertyMetadata(managerProxy));

address managerImpl = address(new Manager());

Expand Down
5 changes: 2 additions & 3 deletions script/DeployTokenUpgrade.s.sol
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,11 @@ import { Strings } from "@openzeppelin/contracts/utils/Strings.sol";

import { IManager, Manager } from "../src/manager/Manager.sol";
import { IToken, Token } from "../src/token/Token.sol";
import { MetadataRenderer } from "../src/token/metadata/MetadataRenderer.sol";
import { IAuction, Auction } from "../src/auction/Auction.sol";
import { IGovernor, Governor } from "../src/governance/governor/Governor.sol";
import { ITreasury, Treasury } from "../src/governance/treasury/Treasury.sol";
import { MetadataRenderer } from "../src/token/metadata/MetadataRenderer.sol";
import { MetadataRendererTypesV1 } from "../src/token/metadata/types/MetadataRendererTypesV1.sol";
import { PropertyMetadata } from "../src/metadata/property/PropertyMetadata.sol";
import { PropertyMetadataTypesV1 } from "../src/metadata/property/types/PropertyMetadataTypesV1.sol";
import { ERC1967Proxy } from "../src/lib/proxy/ERC1967Proxy.sol";

contract DeployTokenUpgrade is Script {
Expand Down
7 changes: 3 additions & 4 deletions script/DeployVersion1_1.s.sol
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,11 @@ import { Strings } from "@openzeppelin/contracts/utils/Strings.sol";

import { IManager, Manager } from "../src/manager/Manager.sol";
import { IToken, Token } from "../src/token/Token.sol";
import { MetadataRenderer } from "../src/token/metadata/MetadataRenderer.sol";
import { IAuction, Auction } from "../src/auction/Auction.sol";
import { IGovernor, Governor } from "../src/governance/governor/Governor.sol";
import { ITreasury, Treasury } from "../src/governance/treasury/Treasury.sol";
import { MetadataRenderer } from "../src/token/metadata/MetadataRenderer.sol";
import { MetadataRendererTypesV1 } from "../src/token/metadata/types/MetadataRendererTypesV1.sol";
import { PropertyMetadata } from "../src/metadata/property/PropertyMetadata.sol";
import { PropertyMetadataTypesV1 } from "../src/metadata/property/types/PropertyMetadataTypesV1.sol";
import { ERC1967Proxy } from "../src/lib/proxy/ERC1967Proxy.sol";

contract DeployVersion1_1 is Script {
Expand Down Expand Up @@ -58,7 +57,7 @@ contract DeployVersion1_1 is Script {
// Deploy token upgrade implementation
address tokenUpgradeImpl = address(new Token(managerProxy));
// Deploy metadata upgrade implementation
address metadataUpgradeImpl = address(new MetadataRenderer(managerProxy));
address metadataUpgradeImpl = address(new PropertyMetadata(managerProxy));

address managerImpl = address(new Manager());

Expand Down
7 changes: 7 additions & 0 deletions src/manager/IManager.sol
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,11 @@ interface IManager is IUUPS, IOwnable {
/// @param upgradeImpl The upgrade implementation address
event UpgradeRemoved(address baseImpl, address upgradeImpl);

/// @notice Event emitted when metadata renderer is updated.
/// @param sender address of the updater
/// @param renderer new metadata renderer address
event MetadataRendererUpdated(address sender, address renderer);

/// ///
/// ERRORS ///
/// ///
Expand All @@ -56,6 +61,8 @@ interface IManager is IUUPS, IOwnable {
/// @dev Reverts if an implementation type is not valid on registration
error INVALID_IMPLEMENTATION_TYPE();

error ONLY_TOKEN_OWNER();

/// ///
/// STRUCTS ///
/// ///
Expand Down
22 changes: 21 additions & 1 deletion src/manager/Manager.sol
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,11 @@ import { ManagerStorageV1 } from "./storage/ManagerStorageV1.sol";
import { ManagerStorageV2 } from "./storage/ManagerStorageV2.sol";
import { IManager } from "./IManager.sol";
import { IToken } from "../token/IToken.sol";
import { IBaseMetadata } from "../token/metadata/interfaces/IBaseMetadata.sol";
import { IBaseMetadata } from "../metadata/interfaces/IBaseMetadata.sol";
import { IAuction } from "../auction/IAuction.sol";
import { ITreasury } from "../governance/treasury/ITreasury.sol";
import { IGovernor } from "../governance/governor/IGovernor.sol";
import { IOwnable } from "../lib/interfaces/IOwnable.sol";

import { VersionedContract } from "../VersionedContract.sol";
import { IVersionedContract } from "../lib/interfaces/IVersionedContract.sol";
Expand Down Expand Up @@ -79,6 +80,7 @@ contract Manager is IManager, VersionedContract, UUPS, Ownable, ManagerStorageV1
// Ensure all implementations are registered
unchecked {
for (uint256 i; i < implAddressesLength; ++i) {
if (i == IMPLEMENTATION_TYPE_METADATA) continue; // metadata registration is optional
if (!isImplementation[uint8(i)][_implAddresses[i]]) revert IMPLEMENTATION_NOT_REGISTERED();
}
}
Expand Down Expand Up @@ -113,6 +115,24 @@ contract Manager is IManager, VersionedContract, UUPS, Ownable, ManagerStorageV1
emit DAODeployed({ token: token, metadata: metadata, auction: auction, treasury: treasury, governor: governor });
}

/// @notice Set a new metadata renderer
/// @param _newRendererImpl new renderer address to use
/// @param _setupRenderer data to setup new renderer with
function setMetadataRenderer(address _token, address _newRendererImpl, bytes memory _setupRenderer) external {
if (msg.sender != IOwnable(_token).owner()) revert ONLY_TOKEN_OWNER();

address metadata = address(new ERC1967Proxy(_newRendererImpl, ""));
daoAddressesByToken[_token].metadata = metadata;

if (_setupRenderer.length > 0) {
IBaseMetadata(metadata).initialize(_setupRenderer, _token);
}

IToken(_token).setMetadataRenderer(IBaseMetadata(metadata));

emit MetadataRendererUpdated({ sender: msg.sender, renderer: metadata });
}

/// ///
/// DAO ADDRESSES ///
/// ///
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// SPDX-License-Identifier: MIT
pragma solidity 0.8.16;

import { IUUPS } from "../../../lib/interfaces/IUUPS.sol";
import { IUUPS } from "../../lib/interfaces/IUUPS.sol";

/// @title IBaseMetadata
/// @author Rohan Kulkarni
Expand Down
Loading

0 comments on commit 67d8f8e

Please sign in to comment.