Skip to content

Commit

Permalink
Allow deployment with custom metadata renderer
Browse files Browse the repository at this point in the history
  • Loading branch information
neokry committed Oct 26, 2023
1 parent b0506e7 commit 7bf36d5
Show file tree
Hide file tree
Showing 6 changed files with 47 additions and 9 deletions.
6 changes: 5 additions & 1 deletion script/DeployNewDAO.s.sol
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,11 @@ contract SetupDaoScript is Script {
"https://renderer.com/render"
);

IManager.TokenParams memory tokenParams = IManager.TokenParams({ initStrings: initStrings, reservedUntilTokenId: 10 });
IManager.TokenParams memory tokenParams = IManager.TokenParams({
initStrings: initStrings,
metadataRenderer: address(0),
reservedUntilTokenId: 10
});

IManager.AuctionParams memory auctionParams = IManager.AuctionParams({
duration: 24 hours,
Expand Down
1 change: 0 additions & 1 deletion script/DeployV2New.s.sol
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ contract DeployContracts is Script {

address deployerAddress = vm.addr(key);
address managerAddress = _getKey("Manager");
address builderDAO = _getKey("BuilderDAO");
address crossDomainMessenger = _getKey("CrossDomainMessenger");

console2.log("~~~~~~~~~~ CHAIN ID ~~~~~~~~~~~");
Expand Down
2 changes: 2 additions & 0 deletions src/manager/IManager.sol
Original file line number Diff line number Diff line change
Expand Up @@ -71,9 +71,11 @@ interface IManager is IUUPS, IOwnable {

/// @notice The ERC-721 token parameters
/// @param initStrings The encoded token name, symbol, collection description, collection image uri, renderer base uri
/// @param metadataRenderer The metadata renderer implementation to use
/// @param reservedUntilTokenId The tokenId that a DAO's auctions will start at
struct TokenParams {
bytes initStrings;
address metadataRenderer;
uint256 reservedUntilTokenId;
}

Expand Down
5 changes: 4 additions & 1 deletion src/manager/Manager.sol
Original file line number Diff line number Diff line change
Expand Up @@ -113,8 +113,11 @@ contract Manager is IManager, VersionedContract, UUPS, Ownable, ManagerStorageV1
// Use the token address to precompute the DAO's remaining addresses
bytes32 salt = bytes32(uint256(uint160(token)) << 96);

// Check if the deployer is using an alternate metadata renderer. If not default to the standard one
address metadataImplToUse = _tokenParams.metadataRenderer != address(0) ? _tokenParams.metadataRenderer : metadataImpl;

// Deploy the remaining DAO contracts
metadata = address(new ERC1967Proxy{ salt: salt }(metadataImpl, ""));
metadata = address(new ERC1967Proxy{ salt: salt }(metadataImplToUse, ""));
auction = address(new ERC1967Proxy{ salt: salt }(auctionImpl, ""));
treasury = address(new ERC1967Proxy{ salt: salt }(treasuryImpl, ""));
governor = address(new ERC1967Proxy{ salt: salt }(governorImpl, ""));
Expand Down
12 changes: 11 additions & 1 deletion test/Manager.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -6,20 +6,23 @@ import { NounsBuilderTest } from "./utils/NounsBuilderTest.sol";
import { IManager, Manager } from "../src/manager/Manager.sol";

import { MockImpl } from "./utils/mocks/MockImpl.sol";
import { MetadataRenderer } from "../src/token/metadata/MetadataRenderer.sol";

contract ManagerTest is NounsBuilderTest {
MockImpl internal mockImpl;
address internal altMetadataImpl;

function setUp() public virtual override {
super.setUp();

mockImpl = new MockImpl();
altMetadataImpl = address(new MetadataRenderer(address(manager)));
}

function setupAltMock() internal virtual {
setMockFounderParams();

setMockTokenParams();
setMockTokenParamsWithRenderer(altMetadataImpl);

setMockAuctionParams();

Expand Down Expand Up @@ -139,6 +142,13 @@ contract ManagerTest is NounsBuilderTest {
manager.removeUpgrade(address(token), address(mockImpl));
}

function test_DeployWithAltRenderer() public {
setupAltMock();
deploy(foundersArr, tokenParams, auctionParams, govParams);

assertEq(metadataRenderer.owner(), address(founder));
}

function test_SetNewRenderer() public {
deployMock();

Expand Down
30 changes: 25 additions & 5 deletions test/utils/NounsBuilderTest.sol
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,8 @@ contract NounsBuilderTest is Test {
"ipfs://Qmew7TdyGnj6YRUjQR68sUJN3239MYXRD8uxowxF6rGK8j",
"https://nouns.build",
"http://localhost:5000/render",
0
0,
address(0)
);
}

Expand All @@ -140,7 +141,21 @@ contract NounsBuilderTest is Test {
"ipfs://Qmew7TdyGnj6YRUjQR68sUJN3239MYXRD8uxowxF6rGK8j",
"https://nouns.build",
"http://localhost:5000/render",
_reservedUntilTokenId
_reservedUntilTokenId,
address(0)
);
}

function setMockTokenParamsWithRenderer(address _metadataRenderer) internal virtual {
setTokenParams(
"Mock Token",
"MOCK",
"This is a mock token",
"ipfs://Qmew7TdyGnj6YRUjQR68sUJN3239MYXRD8uxowxF6rGK8j",
"https://nouns.build",
"http://localhost:5000/render",
0,
_metadataRenderer
);
}

Expand All @@ -151,11 +166,16 @@ contract NounsBuilderTest is Test {
string memory _contractImage,
string memory _contractURI,
string memory _rendererBase,
uint256 _reservedUntilTokenId
uint256 _reservedUntilTokenId,
address _metadataRenderer
) internal virtual {
bytes memory initStrings = abi.encode(_name, _symbol, _description, _contractImage, _contractURI, _rendererBase);

tokenParams = IManager.TokenParams({ initStrings: initStrings, reservedUntilTokenId: _reservedUntilTokenId });
tokenParams = IManager.TokenParams({
initStrings: initStrings,
metadataRenderer: _metadataRenderer,
reservedUntilTokenId: _reservedUntilTokenId
});
}

function setMockAuctionParams() internal virtual {
Expand Down Expand Up @@ -264,7 +284,7 @@ contract NounsBuilderTest is Test {
) internal {
setMockFounderParams();

setTokenParams(_name, _symbol, _description, _contractImage, _projectURI, _rendererBase, 0);
setTokenParams(_name, _symbol, _description, _contractImage, _projectURI, _rendererBase, 0, address(0));

setMockAuctionParams();

Expand Down

0 comments on commit 7bf36d5

Please sign in to comment.