Skip to content

Commit

Permalink
Rework rewards to set at deploy time
Browse files Browse the repository at this point in the history
  • Loading branch information
neokry committed Oct 30, 2023
1 parent 11028af commit fc365c0
Show file tree
Hide file tree
Showing 9 changed files with 164 additions and 78 deletions.
12 changes: 6 additions & 6 deletions script/DeployV2Core.s.sol
Original file line number Diff line number Diff line change
Expand Up @@ -31,37 +31,37 @@ contract DeployContracts is Script {

address deployerAddress = vm.addr(key);

uint16 BUILDER_REWARDS = chainID == 1 || chainID == 5 ? 0 : 250;
uint16 REFERRAL_REWARDS = chainID == 1 || chainID == 5 ? 0 : 250;

console2.log("~~~~~~~~~~ CHAIN ID ~~~~~~~~~~~");
console2.log(chainID);

console2.log("~~~~~~~~~~ DEPLOYER ~~~~~~~~~~~");
console2.log(deployerAddress);

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(address(0), address(0), address(0), address(0), address(0), address(0)));

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

address rewards = _getKey("ProtocolRewards");

// Deploy token implementation
address tokenImpl = address(new Token(address(manager)));

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

// Deploy auction house implementation
address auctionImpl = address(new Auction(address(manager), address(rewards), weth));
address auctionImpl = address(new Auction(address(manager), _getKey("ProtocolRewards"), weth, BUILDER_REWARDS, REFERRAL_REWARDS));

// Deploy treasury implementation
address treasuryImpl = address(new Treasury(address(manager)));

// 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(tokenImpl, metadataRendererImpl, auctionImpl, treasuryImpl, governorImpl, _getKey("BuilderDAO")));

manager.upgradeTo(managerImpl);

Expand Down
37 changes: 26 additions & 11 deletions src/auction/Auction.sol
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ import { AuctionStorageV1 } from "./storage/AuctionStorageV1.sol";
import { Token } from "../token/Token.sol";
import { AuctionStorageV2 } from "./storage/AuctionStorageV2.sol";
import { Manager } from "../manager/Manager.sol";
import { ManagerTypesV2 } from "../manager/types/ManagerTypesV2.sol";
import { IAuction } from "./IAuction.sol";
import { IWETH } from "../lib/interfaces/IWETH.sol";
import { IProtocolRewards } from "../lib/interfaces/IProtocolRewards.sol";
Expand All @@ -34,7 +33,7 @@ contract Auction is IAuction, VersionedContract, UUPS, Ownable, ReentrancyGuard,
uint256 private constant BPS_PER_100_PERCENT = 10_000;

/// @notice The maximum rewards percentage
uint256 private constant MAX_FOUNDER_REWARDS_BPS = 3_000;
uint256 private constant MAX_FOUNDER_REWARD_BPS = 3_000;

/// ///
/// IMMUTABLES ///
Expand All @@ -55,6 +54,12 @@ contract Auction is IAuction, VersionedContract, UUPS, Ownable, ReentrancyGuard,
/// @notice The rewards manager
IProtocolRewards private immutable rewardsManager;

/// @notice The builder reward BPS as a percent of settled auction amount
uint16 private immutable builderRewardsBPS;

/// @notice The referral reward BPS as a percent of settled auction amount
uint16 private immutable referralRewardsBPS;

/// ///
/// CONSTRUCTOR ///
/// ///
Expand All @@ -65,11 +70,15 @@ contract Auction is IAuction, VersionedContract, UUPS, Ownable, ReentrancyGuard,
constructor(
address _manager,
address _rewardsManager,
address _weth
address _weth,
uint16 _builderRewardsBPS,
uint16 _referralRewardsBPS
) payable initializer {
manager = Manager(_manager);
rewardsManager = IProtocolRewards(_rewardsManager);
WETH = _weth;
builderRewardsBPS = _builderRewardsBPS;
referralRewardsBPS = _referralRewardsBPS;
}

/// ///
Expand Down Expand Up @@ -97,7 +106,10 @@ contract Auction is IAuction, VersionedContract, UUPS, Ownable, ReentrancyGuard,
if (msg.sender != address(manager)) revert ONLY_MANAGER();

// Ensure the founder reward is not more than max
if (_founderRewardBps > MAX_FOUNDER_REWARDS_BPS) revert INVALID_REWARDS_CONFIG();
if (_founderRewardBps > MAX_FOUNDER_REWARD_BPS) revert INVALID_REWARDS_BPS();

// Ensure the recipient is set if the reward is greater than 0
if (_founderRewardBps > 0 && _founderRewardRecipient == address(0)) revert INVALID_REWARDS_RECIPIENT();

// Initialize the reentrancy guard
__ReentrancyGuard_init();
Expand Down Expand Up @@ -430,8 +442,11 @@ contract Auction is IAuction, VersionedContract, UUPS, Ownable, ReentrancyGuard,
/// @notice Updates the founder reward recipent address
/// @param reward The new founder reward settings
function setFounderReward(FounderReward calldata reward) external onlyOwner whenPaused {
// Ensure the reward is not more than max
if (reward.percentBps > MAX_FOUNDER_REWARDS_BPS) revert INVALID_REWARDS_CONFIG();
// Ensure the founder reward is not more than max
if (reward.percentBps > MAX_FOUNDER_REWARD_BPS) revert INVALID_REWARDS_BPS();

// Ensure the recipient is set if the reward is greater than 0
if (reward.percentBps > 0 && reward.recipient == address(0)) revert INVALID_REWARDS_RECIPIENT();

// Update the founder reward settings
founderReward = reward;
Expand All @@ -452,11 +467,11 @@ contract Auction is IAuction, VersionedContract, UUPS, Ownable, ReentrancyGuard,
uint256 _finalBidAmount,
uint256 _founderRewardBps
) internal view returns (RewardSplits memory split) {
// Get global reward settings from manager
(address builderRecipient, uint256 referralBps, uint256 builderBps) = manager.rewards();
// Get global builder recipient from manager
address builderRecipient = manager.builderRewardsRecipient();

// Calculate the total rewards percentage
uint256 totalBPS = _founderRewardBps + referralBps + builderBps;
uint256 totalBPS = _founderRewardBps + referralRewardsBPS + builderRewardsBPS;

// Verify percentage is not more than 100
if (totalBPS >= BPS_PER_100_PERCENT) {
Expand All @@ -475,8 +490,8 @@ contract Auction is IAuction, VersionedContract, UUPS, Ownable, ReentrancyGuard,
// Calculate reward splits
split.amounts = new uint256[](3);
split.amounts[0] = (_finalBidAmount * _founderRewardBps) / BPS_PER_100_PERCENT;
split.amounts[1] = (_finalBidAmount * referralBps) / BPS_PER_100_PERCENT;
split.amounts[2] = (_finalBidAmount * builderBps) / BPS_PER_100_PERCENT;
split.amounts[1] = (_finalBidAmount * referralRewardsBPS) / BPS_PER_100_PERCENT;
split.amounts[2] = (_finalBidAmount * builderRewardsBPS) / BPS_PER_100_PERCENT;

// Leave reasons empty
split.reasons = new bytes4[](3);
Expand Down
5 changes: 4 additions & 1 deletion src/auction/IAuction.sol
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,10 @@ interface IAuction is IUUPS, IOwnable, IPausable {
error AUCTION_CREATE_FAILED_TO_LAUNCH();

/// @dev Reverts if caller is not the token owner
error INVALID_REWARDS_CONFIG();
error INVALID_REWARDS_BPS();

/// @dev Reverts if caller is not the token owner
error INVALID_REWARDS_RECIPIENT();

/// @dev Thrown if the rewards total is greater than 100%
error INVALID_REWARD_TOTAL();
Expand Down
4 changes: 0 additions & 4 deletions src/manager/IManager.sol
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ pragma solidity 0.8.16;

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

/// @title IManager
/// @author Rohan Kulkarni
Expand Down Expand Up @@ -46,9 +45,6 @@ interface IManager is IUUPS, IOwnable {
/// @dev Reverts if caller is not the token owner
error ONLY_TOKEN_OWNER();

/// @dev Reverts if caller is not the token owner
error INVALID_REWARDS_CONFIG();

/// ///
/// STRUCTS ///
/// ///
Expand Down
29 changes: 7 additions & 22 deletions src/manager/Manager.sol
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import { Ownable } from "../lib/utils/Ownable.sol";
import { ERC1967Proxy } from "../lib/proxy/ERC1967Proxy.sol";

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";
Expand All @@ -22,14 +21,7 @@ import { IVersionedContract } from "../lib/interfaces/IVersionedContract.sol";
/// @author Neokry & Rohan Kulkarni
/// @custom:repo github.com/ourzora/nouns-protocol
/// @notice The DAO deployer and upgrade manager
contract Manager is IManager, VersionedContract, UUPS, Ownable, ManagerStorageV1, ManagerStorageV2 {
/// ///
/// CONSTANTS ///
/// ///

/// @notice The maximum combined BPS for referral and builder rewards
uint256 private constant MAX_REWARDS_BPS = 2_000;

contract Manager is IManager, VersionedContract, UUPS, Ownable, ManagerStorageV1 {
/// ///
/// IMMUTABLES ///
/// ///
Expand All @@ -49,6 +41,9 @@ contract Manager is IManager, VersionedContract, UUPS, Ownable, ManagerStorageV1
/// @notice The governor implementation address
address public immutable governorImpl;

/// @notice The address to send Builder DAO rewards to
address public immutable builderRewardsRecipient;

/// ///
/// CONSTRUCTOR ///
/// ///
Expand All @@ -58,13 +53,15 @@ contract Manager is IManager, VersionedContract, UUPS, Ownable, ManagerStorageV1
address _metadataImpl,
address _auctionImpl,
address _treasuryImpl,
address _governorImpl
address _governorImpl,
address _builderRewardsRecipient
) payable initializer {
tokenImpl = _tokenImpl;
metadataImpl = _metadataImpl;
auctionImpl = _auctionImpl;
treasuryImpl = _treasuryImpl;
governorImpl = _governorImpl;
builderRewardsRecipient = _builderRewardsRecipient;
}

/// ///
Expand Down Expand Up @@ -250,18 +247,6 @@ contract Manager is IManager, VersionedContract, UUPS, Ownable, ManagerStorageV1
emit UpgradeRemoved(_baseImpl, _upgradeImpl);
}

/// @notice Set the global reward configuration
/// @param _rewards The reward to be paid to the referrer in BPS
function setRewardConfig(RewardConfig calldata _rewards) external onlyOwner {
// Ensure the rewards are valid
if (_rewards.referralBps + _rewards.builderBps > MAX_REWARDS_BPS) {
revert INVALID_REWARDS_CONFIG();
}

// Set the rewards
rewards = _rewards;
}

/// @notice Safely get the contract version of a target contract.
/// @param target The ERC-721 token address
/// @dev Assume `target` is a contract
Expand Down
12 changes: 0 additions & 12 deletions src/manager/storage/ManagerStorageV2.sol

This file was deleted.

17 changes: 0 additions & 17 deletions src/manager/types/ManagerTypesV2.sol

This file was deleted.

Loading

0 comments on commit fc365c0

Please sign in to comment.