Skip to content

Commit

Permalink
minor refactor and some natspec
Browse files Browse the repository at this point in the history
  • Loading branch information
eladmallel committed Sep 29, 2023
1 parent f834827 commit f1a18fd
Showing 1 changed file with 17 additions and 10 deletions.
27 changes: 17 additions & 10 deletions packages/nouns-contracts/contracts/governance/ExcessETH.sol
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
// SPDX-License-Identifier: GPL-3.0

/// @title A helpder contract for calculating Nouns excess ETH

/**
*
* ░░░░░░░░░░░░░░░░░░░░░░░░░░░░░ *
Expand Down Expand Up @@ -36,6 +34,11 @@ interface INounsAuctionHouseV2 is INounsAuctionHouse {
function prices(uint256 auctionCount) external view returns (Settlement[] memory settlements);
}

/**
* @title ExcessETH Helper
* @notice A helpder contract for calculating Nouns excess ETH, used by NounsDAOExecutorV3 to burn excess ETH.
* @dev Owner is assumed to be the NounsDAOExecutorV3 contract, i.e. the Nouns treasury.
*/
contract ExcessETH is IExcessETH, Ownable {
/**
* ░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
Expand All @@ -44,8 +47,8 @@ contract ExcessETH is IExcessETH, Ownable {
*/

error NotEnoughAuctionHistory();

error RocketETHConversionRateTooLow();

/**
* ░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
* EVENTS
Expand Down Expand Up @@ -102,14 +105,23 @@ contract ExcessETH is IExcessETH, Ownable {
function excessETH() public view returns (uint256) {
if (block.timestamp < waitingPeriodEnd) return 0;

uint256 expectedTreasuryValue = meanAuctionPrice() * dao.adjustedTotalSupply();
uint256 expectedTreasuryValue = expectedTreasuryValueInETH();
uint256 treasuryValue = treasuryValueInETH();

if (expectedTreasuryValue >= treasuryValue) return 0;

return min(treasuryValue - expectedTreasuryValue, owner().balance);
}

function expectedTreasuryValueInETH() public view returns (uint256) {
return meanAuctionPrice() * dao.adjustedTotalSupply();
}

function treasuryValueInETH() public view returns (uint256) {
address owner_ = owner();
return owner_.balance + stETH.balanceOf(owner_) + wETH.balanceOf(owner_) + rETHBalanceInETH();
}

function meanAuctionPrice() public view returns (uint256) {
uint16 numberOfPastAuctionsForMeanPrice_ = numberOfPastAuctionsForMeanPrice;
INounsAuctionHouseV2.Settlement[] memory settlements = auction.prices(numberOfPastAuctionsForMeanPrice_);
Expand All @@ -124,11 +136,6 @@ contract ExcessETH is IExcessETH, Ownable {
return sum / numberOfPastAuctionsForMeanPrice_;
}

function treasuryValueInETH() public view returns (uint256) {
address owner_ = owner();
return owner_.balance + stETH.balanceOf(owner_) + wETH.balanceOf(owner_) + rETHBalanceInETH();
}

function rETHBalanceInETH() public view returns (uint256) {
return RocketETH(address(rETH)).getEthValue(rETH.balanceOf(owner()));
}
Expand All @@ -139,7 +146,7 @@ contract ExcessETH is IExcessETH, Ownable {
* ░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
*/

function setNumberOfPastAuctionsForMeanPrice(uint16 newNumberOfPastAuctionsForMeanPrice) public onlyOwner {
function setNumberOfPastAuctionsForMeanPrice(uint16 newNumberOfPastAuctionsForMeanPrice) external onlyOwner {
emit NumberOfPastAuctionsForMeanPriceSet(numberOfPastAuctionsForMeanPrice, newNumberOfPastAuctionsForMeanPrice);

numberOfPastAuctionsForMeanPrice = newNumberOfPastAuctionsForMeanPrice;
Expand Down

0 comments on commit f1a18fd

Please sign in to comment.