Skip to content

Commit

Permalink
Update manager to support multiple implementation contracts
Browse files Browse the repository at this point in the history
  • Loading branch information
neokry committed Jul 18, 2023
1 parent 1789d0d commit a7f3cc5
Show file tree
Hide file tree
Showing 22 changed files with 348 additions and 427 deletions.
6 changes: 3 additions & 3 deletions script/DeployContracts.s.sol
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ contract DeployContracts is Script {
vm.startBroadcast(deployerAddress);

// Deploy root manager implementation + proxy
address managerImpl0 = address(new Manager(address(0), address(0), address(0), address(0), address(0)));
address managerImpl0 = address(new Manager());

Manager manager = Manager(address(new ERC1967Proxy(managerImpl0, abi.encodeWithSignature("initialize(address)", owner))));

Expand All @@ -57,7 +57,7 @@ contract DeployContracts is Script {
// Deploy governor implementation
address governorImpl = address(new Governor(address(manager)));

address managerImpl = address(new Manager(tokenImpl, metadataRendererImpl, auctionImpl, treasuryImpl, governorImpl));
address managerImpl = address(new Manager());

// vm.prank(owner);
// manager.upgradeTo(managerImpl);
Expand Down Expand Up @@ -104,7 +104,7 @@ contract DeployContracts is Script {
function addressToString(address _addr) private pure returns (string memory) {
bytes memory s = new bytes(40);
for (uint256 i = 0; i < 20; i++) {
bytes1 b = bytes1(uint8(uint256(uint160(_addr)) / (2**(8 * (19 - i)))));
bytes1 b = bytes1(uint8(uint256(uint160(_addr)) / (2 ** (8 * (19 - i)))));
bytes1 hi = bytes1(uint8(b) / 16);
bytes1 lo = bytes1(uint8(b) - 16 * uint8(hi));
s[2 * i] = char(hi);
Expand Down
4 changes: 2 additions & 2 deletions script/DeployMetadataUpgrade.s.sol
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ contract DeployMetadataUpgrade is Script {
// Deploy metadata renderer implementation
address metadataRendererImpl = address(new MetadataRenderer(managerProxy));

address managerImpl = address(new Manager(tokenImpl, metadataRendererImpl, auctionImpl, treasuryImpl, governorImpl));
address managerImpl = address(new Manager());

console2.log("MR");
console2.log(metadataRendererImpl);
Expand All @@ -77,7 +77,7 @@ contract DeployMetadataUpgrade is Script {
function addressToString(address _addr) private pure returns (string memory) {
bytes memory s = new bytes(40);
for (uint256 i = 0; i < 20; i++) {
bytes1 b = bytes1(uint8(uint256(uint160(_addr)) / (2**(8 * (19 - i)))));
bytes1 b = bytes1(uint8(uint256(uint160(_addr)) / (2 ** (8 * (19 - i)))));
bytes1 hi = bytes1(uint8(b) / 16);
bytes1 lo = bytes1(uint8(b) - 16 * uint8(hi));
s[2 * i] = char(hi);
Expand Down
4 changes: 2 additions & 2 deletions script/DeployTokenUpgrade.s.sol
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ contract DeployTokenUpgrade is Script {
// Deploy token upgrade implementation
address tokenUpgradeImpl = address(new Token(managerProxy));

address managerImpl = address(new Manager(tokenUpgradeImpl, metadataImpl, auctionImpl, treasuryImpl, governorImpl));
address managerImpl = address(new Manager());

console2.log("TU");
console2.log(tokenUpgradeImpl);
Expand All @@ -88,7 +88,7 @@ contract DeployTokenUpgrade is Script {
function addressToString(address _addr) private pure returns (string memory) {
bytes memory s = new bytes(40);
for (uint256 i = 0; i < 20; i++) {
bytes1 b = bytes1(uint8(uint256(uint160(_addr)) / (2**(8 * (19 - i)))));
bytes1 b = bytes1(uint8(uint256(uint160(_addr)) / (2 ** (8 * (19 - i)))));
bytes1 hi = bytes1(uint8(b) / 16);
bytes1 lo = bytes1(uint8(b) - 16 * uint8(hi));
s[2 * i] = char(hi);
Expand Down
6 changes: 2 additions & 4 deletions script/DeployVersion1_1.s.sol
Original file line number Diff line number Diff line change
Expand Up @@ -60,9 +60,7 @@ contract DeployVersion1_1 is Script {
// Deploy metadata upgrade implementation
address metadataUpgradeImpl = address(new MetadataRenderer(managerProxy));

address managerImpl = address(
new Manager(tokenUpgradeImpl, metadataUpgradeImpl, auctionUpgradeImpl, treasuryUpgradeImpl, governorUpgradeImpl)
);
address managerImpl = address(new Manager());

vm.stopBroadcast();

Expand All @@ -79,7 +77,7 @@ contract DeployVersion1_1 is Script {
function addressToString(address _addr) private pure returns (string memory) {
bytes memory s = new bytes(40);
for (uint256 i = 0; i < 20; i++) {
bytes1 b = bytes1(uint8(uint256(uint160(_addr)) / (2**(8 * (19 - i)))));
bytes1 b = bytes1(uint8(uint256(uint160(_addr)) / (2 ** (8 * (19 - i)))));
bytes1 hi = bytes1(uint8(b) / 16);
bytes1 lo = bytes1(uint8(b) - 16 * uint8(hi));
s[2 * i] = char(hi);
Expand Down
19 changes: 7 additions & 12 deletions src/auction/Auction.sol
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import { VersionedContract } from "../VersionedContract.sol";
/// @title Auction
/// @author Rohan Kulkarni
/// @notice A DAO's auction house
/// @custom:repo github.com/ourzora/nouns-protocol
/// @custom:repo github.com/ourzora/nouns-protocol
/// Modified from:
/// - NounsAuctionHouse.sol commit 2cbe6c7 - licensed under the BSD-3-Clause license.
/// - Zora V3 ReserveAuctionCoreEth module commit 795aeca - licensed under the GPL-3.0 license.
Expand Down Expand Up @@ -58,15 +58,8 @@ contract Auction is IAuction, VersionedContract, UUPS, Ownable, ReentrancyGuard,
/// @param _token The ERC-721 token address
/// @param _founder The founder responsible for starting the first auction
/// @param _treasury The treasury address where ETH will be sent
/// @param _duration The duration of each auction
/// @param _reservePrice The reserve price of each auction
function initialize(
address _token,
address _founder,
address _treasury,
uint256 _duration,
uint256 _reservePrice
) external initializer {
/// @param _data The encoded auction settings
function initialize(address _token, address _founder, address _treasury, bytes calldata _data) external initializer {
// Ensure the caller is the contract manager
if (msg.sender != address(manager)) revert ONLY_MANAGER();

Expand All @@ -82,9 +75,11 @@ contract Auction is IAuction, VersionedContract, UUPS, Ownable, ReentrancyGuard,
// Store DAO's ERC-721 token
token = Token(_token);

AuctionParams memory params = abi.decode(_data, (AuctionParams));

// Store the auction house settings
settings.duration = SafeCast.toUint40(_duration);
settings.reservePrice = _reservePrice;
settings.duration = SafeCast.toUint40(params.duration);
settings.reservePrice = params.reservePrice;
settings.treasury = _treasury;
settings.timeBuffer = INITIAL_TIME_BUFFER;
settings.minBidIncrement = INITIAL_MIN_BID_INCREMENT_PERCENT;
Expand Down
20 changes: 11 additions & 9 deletions src/auction/IAuction.sol
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,15 @@ interface IAuction is IUUPS, IOwnable, IPausable {
/// @dev Thrown if the auction creation failed
error AUCTION_CREATE_FAILED_TO_LAUNCH();

/// ///
/// STRUCTS ///
/// ///

struct AuctionParams {
uint256 duration;
uint256 reservePrice;
}

/// ///
/// FUNCTIONS ///
/// ///
Expand All @@ -97,15 +106,8 @@ interface IAuction is IUUPS, IOwnable, IPausable {
/// @param token The ERC-721 token address
/// @param founder The founder responsible for starting the first auction
/// @param treasury The treasury address where ETH will be sent
/// @param duration The duration of each auction
/// @param reservePrice The reserve price of each auction
function initialize(
address token,
address founder,
address treasury,
uint256 duration,
uint256 reservePrice
) external;
/// @param data The encoded auction initialization data
function initialize(address token, address founder, address treasury, bytes calldata data) external;

/// @notice Creates a bid for the current token
/// @param tokenId The ERC-721 token id
Expand Down
62 changes: 18 additions & 44 deletions src/governance/governor/Governor.sol
Original file line number Diff line number Diff line change
Expand Up @@ -75,45 +75,36 @@ contract Governor is IGovernor, VersionedContract, UUPS, Ownable, EIP712, Propos
/// @notice Initializes a DAO's governor
/// @param _treasury The DAO's treasury address
/// @param _token The DAO's governance token address
/// @param _vetoer The address eligible to veto proposals
/// @param _votingDelay The voting delay
/// @param _votingPeriod The voting period
/// @param _proposalThresholdBps The proposal threshold basis points
/// @param _quorumThresholdBps The quorum threshold basis points
function initialize(
address _treasury,
address _token,
address _vetoer,
uint256 _votingDelay,
uint256 _votingPeriod,
uint256 _proposalThresholdBps,
uint256 _quorumThresholdBps
) external initializer {
/// @param _data The encoded governor parameters
function initialize(address _treasury, address _token, bytes calldata _data) external initializer {
// Ensure the caller is the contract manager
if (msg.sender != address(manager)) revert ONLY_MANAGER();

// Ensure non-zero addresses are provided
if (_treasury == address(0)) revert ADDRESS_ZERO();
if (_token == address(0)) revert ADDRESS_ZERO();

GovParams memory params = abi.decode(_data, (GovParams));

// If a vetoer is specified, store its address
if (_vetoer != address(0)) settings.vetoer = _vetoer;
if (params.vetoer != address(0)) settings.vetoer = params.vetoer;

// Ensure the specified governance settings are valid
if (_proposalThresholdBps < MIN_PROPOSAL_THRESHOLD_BPS || _proposalThresholdBps > MAX_PROPOSAL_THRESHOLD_BPS)
if (params.proposalThresholdBps < MIN_PROPOSAL_THRESHOLD_BPS || params.proposalThresholdBps > MAX_PROPOSAL_THRESHOLD_BPS)
revert INVALID_PROPOSAL_THRESHOLD_BPS();
if (_quorumThresholdBps < MIN_QUORUM_THRESHOLD_BPS || _quorumThresholdBps > MAX_QUORUM_THRESHOLD_BPS) revert INVALID_QUORUM_THRESHOLD_BPS();
if (_proposalThresholdBps >= _quorumThresholdBps) revert INVALID_PROPOSAL_THRESHOLD_BPS();
if (_votingDelay < MIN_VOTING_DELAY || _votingDelay > MAX_VOTING_DELAY) revert INVALID_VOTING_DELAY();
if (_votingPeriod < MIN_VOTING_PERIOD || _votingPeriod > MAX_VOTING_PERIOD) revert INVALID_VOTING_PERIOD();
if (params.quorumThresholdBps < MIN_QUORUM_THRESHOLD_BPS || params.quorumThresholdBps > MAX_QUORUM_THRESHOLD_BPS)
revert INVALID_QUORUM_THRESHOLD_BPS();
if (params.proposalThresholdBps >= params.quorumThresholdBps) revert INVALID_PROPOSAL_THRESHOLD_BPS();
if (params.votingDelay < MIN_VOTING_DELAY || params.votingDelay > MAX_VOTING_DELAY) revert INVALID_VOTING_DELAY();
if (params.votingPeriod < MIN_VOTING_PERIOD || params.votingPeriod > MAX_VOTING_PERIOD) revert INVALID_VOTING_PERIOD();

// Store the governor settings
settings.treasury = Treasury(payable(_treasury));
settings.token = Token(_token);
settings.votingDelay = SafeCast.toUint48(_votingDelay);
settings.votingPeriod = SafeCast.toUint48(_votingPeriod);
settings.proposalThresholdBps = SafeCast.toUint16(_proposalThresholdBps);
settings.quorumThresholdBps = SafeCast.toUint16(_quorumThresholdBps);
settings.votingDelay = SafeCast.toUint48(params.votingDelay);
settings.votingPeriod = SafeCast.toUint48(params.votingPeriod);
settings.proposalThresholdBps = SafeCast.toUint16(params.proposalThresholdBps);
settings.quorumThresholdBps = SafeCast.toUint16(params.quorumThresholdBps);

// Initialize EIP-712 support
__EIP712_init(string.concat(settings.token.symbol(), " GOV"), "1");
Expand Down Expand Up @@ -209,11 +200,7 @@ contract Governor is IGovernor, VersionedContract, UUPS, Ownable, EIP712, Propos
/// @param _proposalId The proposal id
/// @param _support The support value (0 = Against, 1 = For, 2 = Abstain)
/// @param _reason The vote reason
function castVoteWithReason(
bytes32 _proposalId,
uint256 _support,
string memory _reason
) external returns (uint256) {
function castVoteWithReason(bytes32 _proposalId, uint256 _support, string memory _reason) external returns (uint256) {
return _castVote(_proposalId, msg.sender, _support, _reason);
}

Expand Down Expand Up @@ -265,12 +252,7 @@ contract Governor is IGovernor, VersionedContract, UUPS, Ownable, EIP712, Propos
/// @param _proposalId The proposal id
/// @param _voter The voter address
/// @param _support The vote choice
function _castVote(
bytes32 _proposalId,
address _voter,
uint256 _support,
string memory _reason
) internal returns (uint256) {
function _castVote(bytes32 _proposalId, address _voter, uint256 _support, string memory _reason) internal returns (uint256) {
// Ensure voting is active
if (state(_proposalId) != ProposalState.Active) revert VOTING_NOT_STARTED();

Expand Down Expand Up @@ -518,15 +500,7 @@ contract Governor is IGovernor, VersionedContract, UUPS, Ownable, EIP712, Propos

/// @notice The vote counts for a proposal
/// @param _proposalId The proposal id
function proposalVotes(bytes32 _proposalId)
external
view
returns (
uint256,
uint256,
uint256
)
{
function proposalVotes(bytes32 _proposalId) external view returns (uint256, uint256, uint256) {
Proposal memory proposal = proposals[_proposalId];

return (proposal.againstVotes, proposal.forVotes, proposal.abstainVotes);
Expand Down
49 changes: 22 additions & 27 deletions src/governance/governor/IGovernor.sol
Original file line number Diff line number Diff line change
Expand Up @@ -113,27 +113,33 @@ interface IGovernor is IUUPS, IOwnable, IEIP712, GovernorTypesV1 {
/// @dev Reverts if the caller was not the contract manager
error ONLY_MANAGER();

/// ///
/// STRUCTS ///
/// ///

/// @notice The governance parameters
/// @param votingDelay The time delay to vote on a created proposal
/// @param votingPeriod The time period to vote on a proposal
/// @param proposalThresholdBps The basis points of the token supply required to create a proposal
/// @param quorumThresholdBps The basis points of the token supply required to reach quorum
/// @param vetoer The address authorized to veto proposals (address(0) if none desired)
struct GovParams {
uint256 votingDelay;
uint256 votingPeriod;
uint256 proposalThresholdBps;
uint256 quorumThresholdBps;
address vetoer;
}

/// ///
/// FUNCTIONS ///
/// ///

/// @notice Initializes a DAO's governor
/// @param treasury The DAO's treasury address
/// @param token The DAO's governance token address
/// @param vetoer The address eligible to veto proposals
/// @param votingDelay The voting delay
/// @param votingPeriod The voting period
/// @param proposalThresholdBps The proposal threshold basis points
/// @param quorumThresholdBps The quorum threshold basis points
function initialize(
address treasury,
address token,
address vetoer,
uint256 votingDelay,
uint256 votingPeriod,
uint256 proposalThresholdBps,
uint256 quorumThresholdBps
) external;
/// @param data The encoded governance parameters
function initialize(address treasury, address token, bytes calldata data) external;

/// @notice Creates a proposal
/// @param targets The target addresses to call
Expand All @@ -156,11 +162,7 @@ interface IGovernor is IUUPS, IOwnable, IEIP712, GovernorTypesV1 {
/// @param proposalId The proposal id
/// @param support The support value (0 = Against, 1 = For, 2 = Abstain)
/// @param reason The vote reason
function castVoteWithReason(
bytes32 proposalId,
uint256 support,
string memory reason
) external returns (uint256);
function castVoteWithReason(bytes32 proposalId, uint256 support, string memory reason) external returns (uint256);

/// @notice Casts a signed vote
/// @param voter The voter address
Expand Down Expand Up @@ -235,14 +237,7 @@ interface IGovernor is IUUPS, IOwnable, IEIP712, GovernorTypesV1 {

/// @notice The vote counts for a proposal
/// @param proposalId The proposal id
function proposalVotes(bytes32 proposalId)
external
view
returns (
uint256 againstVotes,
uint256 forVotes,
uint256 abstainVotes
);
function proposalVotes(bytes32 proposalId) external view returns (uint256 againstVotes, uint256 forVotes, uint256 abstainVotes);

/// @notice The timestamp valid to execute a proposal
/// @param proposalId The proposal id
Expand Down
12 changes: 10 additions & 2 deletions src/governance/treasury/ITreasury.sol
Original file line number Diff line number Diff line change
Expand Up @@ -54,14 +54,22 @@ interface ITreasury is IUUPS, IOwnable {
/// @dev Reverts if the caller was not the contract manager
error ONLY_MANAGER();

/// ///
/// STRUCTS ///
/// ///

struct TreasuryParams {
uint256 timelockDelay;
}

/// ///
/// FUNCTIONS ///
/// ///

/// @notice Initializes a DAO's treasury
/// @param governor The governor address
/// @param timelockDelay The time delay to execute a queued transaction
function initialize(address governor, uint256 timelockDelay) external;
/// @param data The encoded treasury initialization data
function initialize(address governor, bytes calldata data) external;

/// @notice The timestamp that a proposal is valid to execute
/// @param proposalId The proposal id
Expand Down
Loading

0 comments on commit a7f3cc5

Please sign in to comment.