Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

V2 protocol rewards #117

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 12 additions & 1 deletion script/DeployContracts.s.sol
Original file line number Diff line number Diff line change
Expand Up @@ -13,16 +13,25 @@ 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 { ERC1967Proxy } from "../src/lib/proxy/ERC1967Proxy.sol";
import { ProtocolRewards } from "../src/rewards/ProtocolRewards.sol";

contract DeployContracts is Script {
using Strings for uint256;

string configFile;

function _getKey(string memory key) internal returns (address result) {
(result) = abi.decode(vm.parseJson(configFile, key), (address));
}

function run() public {
uint256 chainID = vm.envUint("CHAIN_ID");
uint256 key = vm.envUint("PRIVATE_KEY");
address weth = vm.envAddress("WETH_ADDRESS");
address owner = vm.envAddress("MANAGER_OWNER");

configFile = vm.readFile(string.concat("./addresses/", Strings.toString(chainID), ".json"));

address deployerAddress = vm.addr(key);

console2.log("~~~~~~~~~~ CHAIN ID ~~~~~~~~~~~");
Expand All @@ -42,14 +51,16 @@ contract DeployContracts is Script {

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

ProtocolRewards rewards = new ProtocolRewards(address(manager), _getKey("BuilderDAO"));

// 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), weth));
address auctionImpl = address(new Auction(address(manager), address(rewards), weth));

// Deploy treasury implementation
address treasuryImpl = address(new Treasury(address(manager)));
Expand Down
6 changes: 5 additions & 1 deletion script/DeployVersion1_1.s.sol
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ 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 { ERC1967Proxy } from "../src/lib/proxy/ERC1967Proxy.sol";
import { ProtocolRewards } from "../src/rewards/ProtocolRewards.sol";

contract DeployVersion1_1 is Script {
using Strings for uint256;
Expand All @@ -34,6 +35,7 @@ contract DeployVersion1_1 is Script {

address managerProxy = _getKey("Manager");
address weth = _getKey("WETH");
address builderRewardsRecipent = _getKey("BuilderDAO");

console2.log("~~~~~~~~~~ DEPLOYER ADDRESS ~~~~~~~~~~~");
console2.logAddress(deployerAddress);
Expand All @@ -49,8 +51,10 @@ contract DeployVersion1_1 is Script {
// Get root manager implementation + proxy
Manager manager = Manager(managerProxy);

ProtocolRewards rewards = new ProtocolRewards(address(manager), builderRewardsRecipent);

// Deploy auction upgrade implementation
address auctionUpgradeImpl = address(new Auction(managerProxy, weth));
address auctionUpgradeImpl = address(new Auction(managerProxy, address(rewards), weth));
// Deploy governor upgrade implementation
address governorUpgradeImpl = address(new Governor(managerProxy));
// Deploy treasury upgrade implementation
Expand Down
55 changes: 50 additions & 5 deletions src/auction/Auction.sol
Original file line number Diff line number Diff line change
Expand Up @@ -8,21 +8,23 @@ import { Pausable } from "../lib/utils/Pausable.sol";
import { SafeCast } from "../lib/utils/SafeCast.sol";

import { AuctionStorageV1 } from "./storage/AuctionStorageV1.sol";
import { AuctionStorageV2 } from "./storage/AuctionStorageV2.sol";
import { Token } from "../token/Token.sol";
import { IManager } from "../manager/IManager.sol";
import { IAuction } from "./IAuction.sol";
import { IWETH } from "../lib/interfaces/IWETH.sol";
import { IProtocolRewards } from "../rewards/interfaces/IProtocolRewards.sol";

import { VersionedContract } from "../VersionedContract.sol";

/// @title Auction
/// @author Rohan Kulkarni
/// @author Rohan Kulkarni & Neokry
/// @notice A DAO's auction house
/// @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.
contract Auction is IAuction, VersionedContract, UUPS, Ownable, ReentrancyGuard, Pausable, AuctionStorageV1 {
contract Auction is IAuction, VersionedContract, UUPS, Ownable, ReentrancyGuard, Pausable, AuctionStorageV1, AuctionStorageV2 {
/// ///
/// IMMUTABLES ///
/// ///
Expand All @@ -39,15 +41,23 @@ contract Auction is IAuction, VersionedContract, UUPS, Ownable, ReentrancyGuard,
/// @notice The contract upgrade manager
IManager private immutable manager;

/// @notice The rewards manager
IProtocolRewards private immutable rewards;

/// ///
/// CONSTRUCTOR ///
/// ///

/// @param _manager The contract upgrade manager address
/// @param _weth The address of WETH
constructor(address _manager, address _weth) payable initializer {
constructor(
address _manager,
address _rewards,
address _weth
) payable initializer {
manager = IManager(_manager);
WETH = _weth;
rewards = IProtocolRewards(_rewards);
}

/// ///
Expand Down Expand Up @@ -88,15 +98,33 @@ contract Auction is IAuction, VersionedContract, UUPS, Ownable, ReentrancyGuard,
settings.treasury = _treasury;
settings.timeBuffer = INITIAL_TIME_BUFFER;
settings.minBidIncrement = INITIAL_MIN_BID_INCREMENT_PERCENT;

// Store the founder rewards recipient
founderRewardsRecipent = _founder;
founderRewardBPS = params.founderRewardBPS;
}

/// ///
/// CREATE BID ///
/// ///

/// @notice Creates a bid for the current token
/// @param _tokenId The ERC-721 token id
function createBidWithReferral(uint256 _tokenId, address _referral) external payable nonReentrant {
currentBidReferral = _referral;
_createBid(_tokenId);
}

/// @notice Creates a bid for the current token
/// @param _tokenId The ERC-721 token id
function createBid(uint256 _tokenId) external payable nonReentrant {
currentBidReferral = address(0);
_createBid(_tokenId);
}

/// @notice Creates a bid for the current token
/// @param _tokenId The ERC-721 token id
function _createBid(uint256 _tokenId) private {
// Ensure the bid is for the current token
if (auction.tokenId != _tokenId) {
revert INVALID_TOKEN_ID();
Expand Down Expand Up @@ -203,8 +231,25 @@ contract Auction is IAuction, VersionedContract, UUPS, Ownable, ReentrancyGuard,
// Cache the amount of the highest bid
uint256 highestBid = _auction.highestBid;

// If the highest bid included ETH: Transfer it to the DAO treasury
if (highestBid != 0) _handleOutgoingTransfer(settings.treasury, highestBid);
// If the highest bid included ETH: Pay rewards and transfer remaining amount to the DAO treasury
if (highestBid != 0) {
// Calculate rewards
IProtocolRewards.RewardSplits memory split = rewards.computeTotalRewards(highestBid, founderRewardBPS);

if (split.totalRewards != 0) {
// Deposit rewards
rewards.depositRewards{ value: split.totalRewards }(
founderRewardsRecipent,
split.founderReward,
currentBidReferral,
split.refferalReward,
split.builderReward
);
}

// Deposit remaining amount to treasury
_handleOutgoingTransfer(settings.treasury, highestBid - split.totalRewards);
}

// Transfer the token to the highest bidder
token.transferFrom(address(this), _auction.highestBidder, _auction.tokenId);
Expand Down
1 change: 1 addition & 0 deletions src/auction/IAuction.sol
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@ interface IAuction is IUUPS, IOwnable, IPausable {
struct AuctionParams {
uint256 duration;
uint256 reservePrice;
uint256 founderRewardBPS;
}

/// ///
Expand Down
13 changes: 13 additions & 0 deletions src/auction/storage/AuctionStorageV2.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
// SPDX-License-Identifier: MIT
pragma solidity 0.8.16;

contract AuctionStorageV2 {
/// @notice The referral for the current auction bid
address public currentBidReferral;

/// @notice The DAO founder collecting protocol rewards
address public founderRewardsRecipent;

/// @notice The rewards to be paid to the DAO founder in BPS
uint256 public founderRewardBPS;
}
Loading
Loading