Skip to content

Commit

Permalink
Merge branch 'v2-generic-manager' into v2-claim-system
Browse files Browse the repository at this point in the history
  • Loading branch information
neokry committed Aug 7, 2023
2 parents 3749ef8 + ff754ea commit 588a9de
Show file tree
Hide file tree
Showing 14 changed files with 183 additions and 37 deletions.
2 changes: 1 addition & 1 deletion script/DeployContracts.s.sol
Original file line number Diff line number Diff line change
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
2 changes: 1 addition & 1 deletion script/DeployMetadataUpgrade.s.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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
2 changes: 1 addition & 1 deletion script/DeployTokenUpgrade.s.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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
2 changes: 1 addition & 1 deletion script/DeployVersion1_1.s.sol
Original file line number Diff line number Diff line change
Expand Up @@ -77,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
7 changes: 6 additions & 1 deletion src/auction/Auction.sol
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,12 @@ contract Auction is IAuction, VersionedContract, UUPS, Ownable, ReentrancyGuard,
/// @param _founder The founder responsible for starting the first auction
/// @param _treasury The treasury address where ETH will be sent
/// @param _data The encoded auction settings
function initialize(address _token, address _founder, address _treasury, bytes calldata _data) external initializer {
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 Down
7 changes: 6 additions & 1 deletion src/auction/IAuction.sol
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,12 @@ interface IAuction is IUUPS, IOwnable, IPausable {
/// @param founder The founder responsible for starting the first auction
/// @param treasury The treasury address where ETH will be sent
/// @param data The encoded auction initialization data
function initialize(address token, address founder, address treasury, bytes calldata data) external;
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
47 changes: 38 additions & 9 deletions src/governance/governor/Governor.sol
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,11 @@ contract Governor is IGovernor, VersionedContract, UUPS, Ownable, EIP712, Propos
/// @param _treasury The DAO's treasury address
/// @param _token The DAO's governance token address
/// @param _data The encoded governor parameters
function initialize(address _treasury, address _token, bytes calldata _data) external initializer {
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();

Expand All @@ -90,13 +94,21 @@ contract Governor is IGovernor, VersionedContract, UUPS, Ownable, EIP712, Propos
if (params.vetoer != address(0)) settings.vetoer = params.vetoer;

// Ensure the specified governance settings are valid
if (params.proposalThresholdBps < MIN_PROPOSAL_THRESHOLD_BPS || params.proposalThresholdBps > MAX_PROPOSAL_THRESHOLD_BPS)
if (params.proposalThresholdBps < MIN_PROPOSAL_THRESHOLD_BPS || params.proposalThresholdBps > MAX_PROPOSAL_THRESHOLD_BPS) {
revert INVALID_PROPOSAL_THRESHOLD_BPS();
if (params.quorumThresholdBps < MIN_QUORUM_THRESHOLD_BPS || params.quorumThresholdBps > MAX_QUORUM_THRESHOLD_BPS)
}
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();
}
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));
Expand Down Expand Up @@ -200,7 +212,11 @@ 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 @@ -252,7 +268,12 @@ 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 @@ -500,7 +521,15 @@ 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
21 changes: 18 additions & 3 deletions src/governance/governor/IGovernor.sol
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,11 @@ interface IGovernor is IUUPS, IOwnable, IEIP712, GovernorTypesV1 {
/// @param treasury The DAO's treasury address
/// @param token The DAO's governance token address
/// @param data The encoded governance parameters
function initialize(address treasury, address token, bytes calldata data) external;
function initialize(
address treasury,
address token,
bytes calldata data
) external;

/// @notice Creates a proposal
/// @param targets The target addresses to call
Expand All @@ -162,7 +166,11 @@ 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 @@ -237,7 +245,14 @@ 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
23 changes: 20 additions & 3 deletions src/governance/treasury/Treasury.sol
Original file line number Diff line number Diff line change
Expand Up @@ -230,17 +230,34 @@ contract Treasury is ITreasury, VersionedContract, UUPS, Ownable, ProposalHasher
/// ///

/// @dev Accepts all ERC-721 transfers
function onERC721Received(address, address, uint256, bytes memory) public pure returns (bytes4) {
function onERC721Received(
address,
address,
uint256,
bytes memory
) public pure returns (bytes4) {
return ERC721TokenReceiver.onERC721Received.selector;
}

/// @dev Accepts all ERC-1155 single id transfers
function onERC1155Received(address, address, uint256, uint256, bytes memory) public pure returns (bytes4) {
function onERC1155Received(
address,
address,
uint256,
uint256,
bytes memory
) public pure returns (bytes4) {
return ERC1155TokenReceiver.onERC1155Received.selector;
}

/// @dev Accept all ERC-1155 batch id transfers
function onERC1155BatchReceived(address, address, uint256[] memory, uint256[] memory, bytes memory) public pure returns (bytes4) {
function onERC1155BatchReceived(
address,
address,
uint256[] memory,
uint256[] memory,
bytes memory
) public pure returns (bytes4) {
return ERC1155TokenReceiver.onERC1155BatchReceived.selector;
}

Expand Down
21 changes: 18 additions & 3 deletions src/manager/IManager.sol
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ interface IManager is IUUPS, IOwnable {
/// @notice Emitted when an implementation is unregistered by the Builder DAO
/// @param implType The type of implementation
/// @param implAddress The implementation address
event ImplemenetationRemoved(uint8 implType, address implAddress);
event ImplementationRemoved(uint8 implType, address implAddress);

/// @notice Emitted when an upgrade is registered by the Builder DAO
/// @param baseImpl The base implementation address
Expand Down Expand Up @@ -99,11 +99,26 @@ interface IManager is IUUPS, IOwnable {
FounderParams[] calldata founderParams,
address[] calldata implAddresses,
bytes[] calldata implData
) external returns (address token, address metadataRenderer, address auction, address treasury, address governor);
)
external
returns (
address token,
address metadataRenderer,
address auction,
address treasury,
address governor
);

/// @notice A DAO's remaining contract addresses from its token address
/// @param token The ERC-721 token address
function getAddresses(address token) external returns (address metadataRenderer, address auction, address treasury, address governor);
function getAddresses(address token)
external
returns (
address metadataRenderer,
address auction,
address treasury,
address governor
);

/// @notice If an implementation is registered by the Builder DAO as an optional upgrade
/// @param baseImpl The base implementation address
Expand Down
26 changes: 22 additions & 4 deletions src/manager/Manager.sol
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ contract Manager is IManager, VersionedContract, UUPS, Ownable, ManagerStorageV1
uint8 public constant IMPLEMENTATION_TYPE_COUNT = 5;

// Public constants for implementation types.
// Allows for adding new types later easily compared to a enum.
// Allows for more clarity when adding new types compared to a enum.
uint8 public constant IMPLEMENTATION_TYPE_TOKEN = 0;
uint8 public constant IMPLEMENTATION_TYPE_METADATA = 1;
uint8 public constant IMPLEMENTATION_TYPE_AUCTION = 2;
Expand Down Expand Up @@ -63,7 +63,16 @@ contract Manager is IManager, VersionedContract, UUPS, Ownable, ManagerStorageV1
FounderParams[] calldata _founderParams,
address[] calldata _implAddresses,
bytes[] calldata _implData
) external returns (address token, address metadata, address auction, address treasury, address governor) {
)
external
returns (
address token,
address metadata,
address auction,
address treasury,
address governor
)
{
// Used to store the address of the first (or only) founder
// This founder is responsible for adding token artwork and launching the first auction -- they're also free to transfer this responsiblity
address founder;
Expand Down Expand Up @@ -123,7 +132,16 @@ contract Manager is IManager, VersionedContract, UUPS, Ownable, ManagerStorageV1
/// @return auction Auction deployed address
/// @return treasury Treasury deployed address
/// @return governor Governor deployed address
function getAddresses(address _token) public view returns (address metadata, address auction, address treasury, address governor) {
function getAddresses(address _token)
public
view
returns (
address metadata,
address auction,
address treasury,
address governor
)
{
DAOAddresses storage addresses = daoAddressesByToken[_token];

metadata = addresses.metadata;
Expand Down Expand Up @@ -160,7 +178,7 @@ contract Manager is IManager, VersionedContract, UUPS, Ownable, ManagerStorageV1
if (_isInvalidImplementationType(_implType)) revert INVALID_IMPLEMENTATION_TYPE();
delete isImplementation[_implType][_implAddress];

emit ImplemenetationRemoved(_implType, _implAddress);
emit ImplementationRemoved(_implType, _implAddress);
}

/// ///
Expand Down
18 changes: 15 additions & 3 deletions src/token/metadata/MetadataRenderer.sol
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,11 @@ contract MetadataRenderer is
/// @param _names The names of the properties to add
/// @param _items The items to add to each property
/// @param _ipfsGroup The IPFS base URI and extension
function addProperties(string[] calldata _names, ItemParam[] calldata _items, IPFSGroup calldata _ipfsGroup) external onlyOwner {
function addProperties(
string[] calldata _names,
ItemParam[] calldata _items,
IPFSGroup calldata _ipfsGroup
) external onlyOwner {
_addProperties(_names, _items, _ipfsGroup);
}

Expand All @@ -133,13 +137,21 @@ contract MetadataRenderer is
/// @param _names The names of the properties to add
/// @param _items The items to add to each property
/// @param _ipfsGroup The IPFS base URI and extension
function deleteAndRecreateProperties(string[] calldata _names, ItemParam[] calldata _items, IPFSGroup calldata _ipfsGroup) external onlyOwner {
function deleteAndRecreateProperties(
string[] calldata _names,
ItemParam[] calldata _items,
IPFSGroup calldata _ipfsGroup
) external onlyOwner {
delete ipfsData;
delete properties;
_addProperties(_names, _items, _ipfsGroup);
}

function _addProperties(string[] calldata _names, ItemParam[] calldata _items, IPFSGroup calldata _ipfsGroup) internal {
function _addProperties(
string[] calldata _names,
ItemParam[] calldata _items,
IPFSGroup calldata _ipfsGroup
) internal {
// Cache the existing amount of IPFS data stored
uint256 dataLength = ipfsData.length;

Expand Down
Loading

0 comments on commit 588a9de

Please sign in to comment.