Introduction
Hi, I'm cardene, a software engineer and technical writer focused on blockchain and AI.
I've also authored Japanese technical books on specification-driven development with LLMs and decentralized application (DApp) development.
I also build and publish a variety of tools, libraries, and open-source projects.
In this article, we'll explore the Nouns NounsAuctionHouse contract using Bunzz's new DeCipher feature.
DeCipher is a service that uses AI to automatically generate contract documentation.
For detailed instructions on how to use it, see the following article.
This article describes my personal experience using DeCipher. It may contain inaccuracies, so please let me know in the comments if you find any.
Translation note: The original AI-generated overview and usage sections contain claims that do not match the contract code reproduced below. In particular, the implementation uses
createBid,settleAuction, andsettleCurrentAndCreateNewAuction, rather than the generic auction functions described in the overview. Treat the overview as historical AI-generated commentary, not as a verified integration guide. Consult the implementation before interacting with the contract.
Here is the DeCipher link used in this article.
Here is the Etherscan link.
Overview
The NounsAuctionHouse contract is a key component of the Nouns ecosystem. It provides a mechanism for auctioning Nouns, special ERC721 tokens representing ownership of digital assets. The contract is designed to provide a fair and secure auction process for both buyers and sellers.
Purpose
The primary purpose of NounsAuctionHouse is to provide a decentralized marketplace where users can trade Nouns through auctions. It connects Noun owners wishing to sell their tokens with potential buyers.
Responsibilities
-
Auction management NounsAuctionHouse manages the overall auction process, including starting auctions, accepting bids, and determining the highest bid, to keep auctions fair and transparent.
-
Bid processing The contract manages bidding and provides a mechanism for users to bid on Nouns they are interested in. It records the highest bid and updates it when a higher bid is placed.
-
Auction settlement When an auction ends, the contract determines the highest bidder and transfers ownership of the Noun at the winning price. It also distributes the auction proceeds appropriately to the seller and other relevant parties.
-
Security and protection The contract incorporates security measures using libraries such as PausableUpgradeable and ReentrancyGuardUpgradeable to protect against unauthorized access and attacks.
-
Ownership and upgradeability NounsAuctionHouse uses libraries such as OwnableUpgradeable and Initializable to ensure that only authorized parties can make permitted changes. This makes future upgrades and improvements possible.
-
Integration with other contracts NounsAuctionHouse works with other contracts, including INounsToken, IERC20, IERC721, IWETH, INounsDescriptor, and INounsSeeder. These integrations facilitate interactions and help the Nouns ecosystem operate smoothly.
Usage
NounsAuctionHouse is a smart contract for auctioning special ERC721 tokens called Nouns. The contract provides a mechanism for users to create and participate in Nouns auctions. The highest bidder wins the auction and obtains ownership of the Noun.
Objective
The objective of NounsAuctionHouse is to provide a decentralized marketplace for trading Nouns through auctions. Users can create auctions for Nouns they own and configure the starting price and duration. Other users can participate by bidding. When the auction ends, the highest bidder obtains ownership of the Noun.
Procedure
The following steps describe how to implement a decentralized marketplace for Noun auctions.
- Deploy the NounsAuctionHouse contract.
- Initialize the contract with the required settings. Specify addresses such as the NounsToken contract address and the WETH contract address.
- Call the
createAuctionfunction to create an auction for a Noun. Specify parameters such as the Noun token ID, starting price, and auction duration. - Call the
bidfunction to participate in an auction, specifying the bid amount and auction ID. - Wait for the auction to end.
- Call the
claimfunction to send the Noun to the highest bidder. - If the auction creator wishes to cancel the auction, call
cancelAuctionto cancel it and return the Noun.
Functions
createAuction
Creates a new auction for a Noun.
Parameters
tokenId- ID of the Noun to be auctioned.
duration- Auction duration in seconds.
reservePrice- Starting price of the auction.
extensionDuration- Extension period when a bid is placed shortly before the auction ends.
auctionCurrency- Address of the ERC20 token used for bidding.
Return value
- auctionId
- ID of the newly created auction.
bid
Places a bid in an existing auction.
Parameters
auctionId- ID of the auction to bid in.
amount- Bid amount in the auction currency. Return value None.
claim`
Sends the Noun to the winning bidder after the auction.
Parameters
auctionId- Auction ID of the Noun to be sent.
Return value None.
cancelAuction
Cancels an existing auction and retrieves the Noun.
Parameters
auctionId- ID of the auction to cancel.
Return value None.
Events
AuctionCreated
Emitted when a new auction is created.
Parameters
auctionId- ID of the newly created auction.
tokenId- ID of the Noun being auctioned.
seller- Address of the seller who created the auction.
reservePrice- Starting price of the auction.
duration- Auction duration in seconds.
extensionDuration- Extension period when a bid is placed shortly before the auction ends.
auctionCurrency- Address of the ERC20 token used for bidding.
AuctionBid
Emitted when a bid is placed in an auction.
Parameters
auctionId- Auction ID.
bidder- Bidder's address.
amount- Bid amount in the auction currency.
AuctionExtended
Emitted when an auction is extended.
Parameters
auctionId- Auction ID.
extensionDuration- Extension duration in seconds.
AuctionEnded
Emitted when an auction ends.
Parameters
auctionId- Auction ID.
tokenId- ID of the Noun being auctioned.
winner- Address of the highest bidder.
amount- Winning bid amount in the auction currency.
AuctionCanceled
Emitted when an auction is canceled.
Parameters
auctionId- ID of the canceled auction.
tokenId- ID of the Noun in the canceled auction.
canceller- Address of the creator who canceled the auction.
Related EIPs and ERCs
The related standards are summarized below.
- ERC721
- The Noun being auctioned is an ERC721 token.
- ERC20
- Any ERC20 token can be used as the bidding currency.
- EIP165
- The contract implements the ERC165 interface to support interface detection.
- EIP721
- The contract implements the ERC721 interface to interact with Noun tokens.
- EIP1155
- The contract implements the ERC1155 interface to interact with Noun tokens.
- EIP2981
- The contract implements the ERC2981 interface for Noun royalty information.
Parameters
None.
Contract
NounsAuctionHouse
nouns
INounsToken public nouns;Overview An interface to the ERC721 token contract.
Details Stores an interface to the ERC721 token contract. Nouns are ERC721 tokens traded through auctions. This interface allows access to their information and operations.
weth
address public weth;Overview Address of the WETH contract.
Details Stores the contract address of the WETH (Wrapped Ether) token. WETH is a standard way to represent Ether as an ERC20 token. This address enables the use of WETH for bidding.
timeBuffer
uint256 public timeBuffer;Overview Minimum time remaining before the auction ends after a new bid is placed.
Details Represents the minimum time that should remain before an auction ends after the latest bid. This gives other bidders a chance to place new bids before the bidding process ends.
reservePrice
uint256 public reservePrice;Overview Minimum acceptable price for an auction.
Details Represents the minimum price accepted in an auction. If a bid is below this price, the auction cannot proceed with that bid.
minBidIncrementPercentage
uint8 public minBidIncrementPercentage;Overview Minimum percentage difference between the previous bid and the current bid.
Details Specifies the minimum percentage increase over the previous bid. A new bid is rejected if it does not meet this minimum increase.
duration
uint256 public duration;Overview Duration of an individual auction.
Details Represents the duration of a single auction. The auction must end within this period.
auction
INounsAuctionHouse.Auction public auction;Overview A struct containing information about the active auction.
Details This struct stores information about the active auction. The active auction is the auction currently in progress. The struct contains detailed auction information.
initialize
initialize
function initialize(
INounsToken _nouns,
address _weth,
uint256 _timeBuffer,
uint256 _reservePrice,
uint8 _minBidIncrementPercentage,
uint256 _duration
) external initializer {
__Pausable_init();
__ReentrancyGuard_init();
__Ownable_init();
_pause();
nouns = _nouns;
weth = _weth;
timeBuffer = _timeBuffer;
reservePrice = _reservePrice;
minBidIncrementPercentage = _minBidIncrementPercentage;
duration = _duration;
}Overview Initializes the auction house and its base contracts, sets configuration values, and pauses the contract. It can be called only once.
Details This function performs the contract's initialization procedure. Specifically, it initializes Pausable, ReentrancyGuard, and Ownable, then places the contract in the paused state.
Arguments
_nouns- Address of the contract representing Nouns tokens.
_weth- Address of the Wrapped Ether (WETH) contract.
_timeBuffer- Time buffer before the end of an auction.
_reservePrice- Minimum acceptable bid.
_minBidIncrementPercentage- Minimum bid increase percentage (%).
_duration- Auction duration.
settleCurrentAndCreateNewAuction
settleCurrentAndCreateNewAuction
function settleCurrentAndCreateNewAuction() external override nonReentrant whenNotPaused {
_settleAuction();
_createAuction();
}Overview Settles the current auction, creates a new Noun, and puts it up for auction.
Details The function performs the following steps.
- Call
_settleAuction()to settle the current auction. - Call
_createAuction()to create a new Noun and put it up for auction.
settleAuction
settleAuction
function settleAuction() external override whenPaused nonReentrant {
_settleAuction();
}Overview Settles the current auction.
Details This function can only be called when the contract is paused. It performs the following step.
- Call
_settleAuction()to settle the current auction.
createBid
createBid
function createBid(uint256 nounId) external payable override nonReentrant {
INounsAuctionHouse.Auction memory _auction = auction;
require(_auction.nounId == nounId, 'Noun not up for auction');
require(block.timestamp < _auction.endTime, 'Auction expired');
require(msg.value >= reservePrice, 'Must send at least reservePrice');
require(
msg.value >= _auction.amount + ((_auction.amount * minBidIncrementPercentage) / 100),
'Must send more than last bid by minBidIncrementPercentage amount'
);
address payable lastBidder = _auction.bidder;
// Refund the last bidder, if applicable
if (lastBidder != address(0)) {
_safeTransferETHWithFallback(lastBidder, _auction.amount);
}
auction.amount = msg.value;
auction.bidder = payable(msg.sender);
// Extend the auction if the bid was received within `timeBuffer` of the auction end time
bool extended = _auction.endTime - block.timestamp < timeBuffer;
if (extended) {
auction.endTime = _auction.endTime = block.timestamp + timeBuffer;
}
emit AuctionBid(_auction.nounId, msg.sender, msg.value, extended);
if (extended) {
emit AuctionExtended(_auction.nounId, _auction.endTime);
}
}Overview Places a bid on the specified Noun. Accepts payment in ETH for the specified amount.
Details The function performs the following steps.
- Retrieve the current auction information from
_auction. - Verify that the Noun being auctioned is the specified Noun.
- Verify that the auction's end time has not passed.
- Verify that the amount of ETH sent is at least the reserve price.
- Verify that the amount of ETH sent meets the minimum increase over the previous bid.
- Refund ETH to the previous bidder, if one exists.
- Update the amount and bidder for
_auction. - Extend the auction's end time if the bid is placed within
timeBufferof the end time. - Emit the appropriate events.
Arguments
nounId- ID of the Noun being bid on.
pause
pause
function pause() external override onlyOwner {
_pause();
}Overview Pauses the Nouns auction house.
Details Only the owner can call this function. Calling it changes the contract's state to paused. While paused, anyone can settle an existing auction, but no new auction can start.
unpause
unpause
function unpause() external override onlyOwner {
_unpause();
if (auction.startTime == 0 || auction.settled) {
_createAuction();
}
}Overview Unpauses the Nouns auction house and starts a new auction if necessary.
Details Only the owner can call this function. Calling it changes the contract's state to unpaused. It also checks the current auction information and starts a new auction if none has started or the existing auction has already been settled.
setTimeBuffer
setTimeBuffer
function setTimeBuffer(uint256 _timeBuffer) external override onlyOwner {
timeBuffer = _timeBuffer;
emit AuctionTimeBufferUpdated(_timeBuffer);
}Overview Sets the auction's time buffer.
Details
Only the owner can call this function.
Sets the specified time buffer in timeBuffer.
Arguments
_timeBuffer- Auction time buffer to set.
setReservePrice
setReservePrice
function setReservePrice(uint256 _reservePrice) external override onlyOwner {
reservePrice = _reservePrice;
emit AuctionReservePriceUpdated(_reservePrice);
}Overview Sets the auction's reserve price.
Details
Only the owner can call this function.
Sets the specified minimum acceptable bid in reservePrice.
Arguments
_reservePrice- Reserve price to set.
setMinBidIncrementPercentage
setMinBidIncrementPercentage
function setMinBidIncrementPercentage(uint8 _minBidIncrementPercentage) external override onlyOwner {
minBidIncrementPercentage = _minBidIncrementPercentage;
emit AuctionMinBidIncrementPercentageUpdated(_minBidIncrementPercentage);
}Overview Sets the auction's minimum bid increase percentage.
Details
Only the owner can call this function.
Sets the specified minimum bid increase percentage in minBidIncrementPercentage.
Arguments
_minBidIncrementPercentage- Minimum bid increase percentage (%) to set.
_createAuction
_createAuction
function _createAuction() internal {
try nouns.mint() returns (uint256 nounId) {
uint256 startTime = block.timestamp;
uint256 endTime = startTime + duration;
auction = Auction({
nounId: nounId,
amount: 0,
startTime: startTime,
endTime: endTime,
bidder: payable(0),
settled: false
});
emit AuctionCreated(nounId, startTime, endTime);
} catch Error(string memory) {
_pause();
}
}Overview Creates an auction.
Details The function performs the following steps.
- Call
nouns.mint()to create a new Noun and obtain its ID. - Calculate the auction's start and end times.
- Store the auction details in
auctionand emit theAuctionCreatedevent. - If
mintfails (for example, if the minter has been updated without pausing the contract), pause the contract.
_settleAuction
_settleAuction
function _settleAuction() internal {
INounsAuctionHouse.Auction memory _auction = auction;
require(_auction.startTime != 0, "Auction hasn't begun");
require(!_auction.settled, 'Auction has already been settled');
require(block.timestamp >= _auction.endTime, "Auction hasn't completed");
auction.settled = true;
if (_auction.bidder == address(0)) {
nouns.burn(_auction.nounId);
} else {
nouns.transferFrom(address(this), _auction.bidder, _auction.nounId);
}
if (_auction.amount > 0) {
_safeTransferETHWithFallback(owner(), _auction.amount);
}
emit AuctionSettled(_auction.nounId, _auction.bidder, _auction.amount);
}Overview Settles the auction, finalizes the winning bid, and sends the proceeds to the owner.
Details The function performs the following steps.
- Retrieve the current auction information from
_auction. - Verify that the auction has started.
- Verify that the auction has not already been settled.
- Verify that the auction's end time has passed.
- Mark the auction as settled.
- If there is no bidder, burn the Noun.
- If there is a bidder, transfer the Noun to the bidder.
- If the auction amount is greater than
0, send the proceeds to the owner. - Emit the appropriate events.
_safeTransferETHWithFallback
_safeTransferETHWithFallback
function _safeTransferETHWithFallback(address to, uint256 amount) internal {
if (!_safeTransferETH(to, amount)) {
IWETH(weth).deposit{ value: amount }();
IERC20(weth).transfer(to, amount);
}
}Overview Transfers ETH. If the ETH transfer fails, converts ETH into WETH and retries.
Details The function performs the following steps.
- Use
_safeTransferETHto transfer ETH to the specified address. - If the ETH transfer fails, convert it into WETH and retry.
Arguments
to- Recipient address for the ETH transfer.
amount- Amount of ETH to transfer.
_safeTransferETH
_safeTransferETH
function _safeTransferETH(address to, uint256 value) internal returns (bool) {
(bool success, ) = to.call{ value: value, gas: 30_000 }(new bytes(0));
return success;
}Overview Transfers ETH and returns the success status.
Details The function performs the following steps.
- Transfer the specified amount of ETH to the specified address.
- Return the success status of the transfer.
Arguments
to- Recipient address for the ETH transfer.
value- Amount of ETH to transfer.
Return value
Returns true if the ETH transfer succeeds, or false if it fails.
Events
AuctionCreated
AuctionCreated
event AuctionCreated(uint256 indexed nounId, uint256 startTime, uint256 endTime);Overview Emitted when a new auction is created.
Parameters
nounId- ID of the Noun put up for auction.
startTime- Auction start time.
endTime- Auction end time.
AuctionBid
AuctionBid
event AuctionBid(uint256 indexed nounId, address sender, uint256 value, bool extended);Overview Emitted when a bid is placed on a Noun.
Parameter details
nounId- ID of the Noun being bid on.
sender- Address that placed the bid.
value- Amount of ETH bid.
extended- Whether the bid was placed within the time buffer.
AuctionExtended
AuctionExtended
event AuctionExtended(uint256 indexed nounId, uint256 endTime);Overview Emitted when the auction's end time is extended within the time buffer.
Parameters
nounId- ID of the relevant Noun.
endTime- Auction end time after the extension.
AuctionSettled
AuctionSettled
event AuctionSettled(uint256 indexed nounId, address winner, uint256 amount);Overview Emitted when an auction is settled.
Parameters
nounId- ID of the settled Noun.
winner- Address that won the auction.
amount- Amount paid.
AuctionTimeBufferUpdated
AuctionTimeBufferUpdated
event AuctionTimeBufferUpdated(uint256 timeBuffer);Overview Emitted when the auction time buffer is updated.
Details
timeBuffer- Updated time buffer.
AuctionReservePriceUpdated
AuctionReservePriceUpdated
event AuctionReservePriceUpdated(uint256 reservePrice);Overview Emitted when the auction reserve price is updated.
Parameters
reservePrice- Updated reserve price.
AuctionMinBidIncrementPercentageUpdated
AuctionMinBidIncrementPercentageUpdated
event AuctionMinBidIncrementPercentageUpdated(uint256 minBidIncrementPercentage);Overview Emitted when the minimum bid increase percentage is updated.
Details
minBidIncrementPercentage- Updated minimum bid increase percentage.
Code
Interfaces
/contracts/interfaces
INounsAuctionHouse.sol
INounsAuctionHouse.sol
// SPDX-License-Identifier: GPL-3.0
/// @title Interface for Noun Auction Houses
/*********************************
* ░░░░░░░░░░░░░░░░░░░░░░░░░░░░░ *
* ░░░░░░░░░░░░░░░░░░░░░░░░░░░░░ *
* ░░░░░░█████████░░█████████░░░ *
* ░░░░░░██░░░████░░██░░░████░░░ *
* ░░██████░░░████████░░░████░░░ *
* ░░██░░██░░░████░░██░░░████░░░ *
* ░░██░░██░░░████░░██░░░████░░░ *
* ░░░░░░█████████░░█████████░░░ *
* ░░░░░░░░░░░░░░░░░░░░░░░░░░░░░ *
* ░░░░░░░░░░░░░░░░░░░░░░░░░░░░░ *
*********************************/
pragma solidity ^0.8.6;
interface INounsAuctionHouse {
struct Auction {
// ID for the Noun (ERC721 token ID)
uint256 nounId;
// The current highest bid amount
uint256 amount;
// The time that the auction started
uint256 startTime;
// The time that the auction is scheduled to end
uint256 endTime;
// The address of the current highest bid
address payable bidder;
// Whether or not the auction has been settled
bool settled;
}
event AuctionCreated(uint256 indexed nounId, uint256 startTime, uint256 endTime);
event AuctionBid(uint256 indexed nounId, address sender, uint256 value, bool extended);
event AuctionExtended(uint256 indexed nounId, uint256 endTime);
event AuctionSettled(uint256 indexed nounId, address winner, uint256 amount);
event AuctionTimeBufferUpdated(uint256 timeBuffer);
event AuctionReservePriceUpdated(uint256 reservePrice);
event AuctionMinBidIncrementPercentageUpdated(uint256 minBidIncrementPercentage);
function settleAuction() external;
function settleCurrentAndCreateNewAuction() external;
function createBid(uint256 nounId) external payable;
function pause() external;
function unpause() external;
function setTimeBuffer(uint256 timeBuffer) external;
function setReservePrice(uint256 reservePrice) external;
function setMinBidIncrementPercentage(uint8 minBidIncrementPercentage) external;
}INounsToken.sol
INounsToken.sol
// SPDX-License-Identifier: GPL-3.0
/// @title Interface for NounsToken
/*********************************
* ░░░░░░░░░░░░░░░░░░░░░░░░░░░░░ *
* ░░░░░░░░░░░░░░░░░░░░░░░░░░░░░ *
* ░░░░░░█████████░░█████████░░░ *
* ░░░░░░██░░░████░░██░░░████░░░ *
* ░░██████░░░████████░░░████░░░ *
* ░░██░░██░░░████░░██░░░████░░░ *
* ░░██░░██░░░████░░██░░░████░░░ *
* ░░░░░░█████████░░█████████░░░ *
* ░░░░░░░░░░░░░░░░░░░░░░░░░░░░░ *
* ░░░░░░░░░░░░░░░░░░░░░░░░░░░░░ *
*********************************/
pragma solidity ^0.8.6;
import { IERC721 } from '@openzeppelin/contracts/token/ERC721/IERC721.sol';
import { INounsDescriptor } from './INounsDescriptor.sol';
import { INounsSeeder } from './INounsSeeder.sol';
interface INounsToken is IERC721 {
event NounCreated(uint256 indexed tokenId, INounsSeeder.Seed seed);
event NounBurned(uint256 indexed tokenId);
event NoundersDAOUpdated(address noundersDAO);
event MinterUpdated(address minter);
event MinterLocked();
event DescriptorUpdated(INounsDescriptor descriptor);
event DescriptorLocked();
event SeederUpdated(INounsSeeder seeder);
event SeederLocked();
function mint() external returns (uint256);
function burn(uint256 tokenId) external;
function dataURI(uint256 tokenId) external returns (string memory);
function setNoundersDAO(address noundersDAO) external;
function setMinter(address minter) external;
function lockMinter() external;
function setDescriptor(INounsDescriptor descriptor) external;
function lockDescriptor() external;
function setSeeder(INounsSeeder seeder) external;
function lockSeeder() external;
}IWETH.sol
IWETH.sol
// SPDX-License-Identifier: GPL-3.0
pragma solidity ^0.8.6;
interface IWETH {
function deposit() external payable;
function withdraw(uint256 wad) external;
function transfer(address to, uint256 value) external returns (bool);
}INounsDescriptor.sol
INounsDescriptor.sol
// SPDX-License-Identifier: GPL-3.0
/// @title Interface for NounsDescriptor
/*********************************
* ░░░░░░░░░░░░░░░░░░░░░░░░░░░░░ *
* ░░░░░░░░░░░░░░░░░░░░░░░░░░░░░ *
* ░░░░░░█████████░░█████████░░░ *
* ░░░░░░██░░░████░░██░░░████░░░ *
* ░░██████░░░████████░░░████░░░ *
* ░░██░░██░░░████░░██░░░████░░░ *
* ░░██░░██░░░████░░██░░░████░░░ *
* ░░░░░░█████████░░█████████░░░ *
* ░░░░░░░░░░░░░░░░░░░░░░░░░░░░░ *
* ░░░░░░░░░░░░░░░░░░░░░░░░░░░░░ *
*********************************/
pragma solidity ^0.8.6;
import { INounsSeeder } from './INounsSeeder.sol';
interface INounsDescriptor {
event PartsLocked();
event DataURIToggled(bool enabled);
event BaseURIUpdated(string baseURI);
function arePartsLocked() external returns (bool);
function isDataURIEnabled() external returns (bool);
function baseURI() external returns (string memory);
function palettes(uint8 paletteIndex, uint256 colorIndex) external view returns (string memory);
function backgrounds(uint256 index) external view returns (string memory);
function bodies(uint256 index) external view returns (bytes memory);
function accessories(uint256 index) external view returns (bytes memory);
function heads(uint256 index) external view returns (bytes memory);
function glasses(uint256 index) external view returns (bytes memory);
function backgroundCount() external view returns (uint256);
function bodyCount() external view returns (uint256);
function accessoryCount() external view returns (uint256);
function headCount() external view returns (uint256);
function glassesCount() external view returns (uint256);
function addManyColorsToPalette(uint8 paletteIndex, string[] calldata newColors) external;
function addManyBackgrounds(string[] calldata backgrounds) external;
function addManyBodies(bytes[] calldata bodies) external;
function addManyAccessories(bytes[] calldata accessories) external;
function addManyHeads(bytes[] calldata heads) external;
function addManyGlasses(bytes[] calldata glasses) external;
function addColorToPalette(uint8 paletteIndex, string calldata color) external;
function addBackground(string calldata background) external;
function addBody(bytes calldata body) external;
function addAccessory(bytes calldata accessory) external;
function addHead(bytes calldata head) external;
function addGlasses(bytes calldata glasses) external;
function lockParts() external;
function toggleDataURIEnabled() external;
function setBaseURI(string calldata baseURI) external;
function tokenURI(uint256 tokenId, INounsSeeder.Seed memory seed) external view returns (string memory);
function dataURI(uint256 tokenId, INounsSeeder.Seed memory seed) external view returns (string memory);
function genericDataURI(
string calldata name,
string calldata description,
INounsSeeder.Seed memory seed
) external view returns (string memory);
function generateSVGImage(INounsSeeder.Seed memory seed) external view returns (string memory);
}INounsSeeder.sol
INounsSeeder.sol
// SPDX-License-Identifier: GPL-3.0
/// @title Interface for NounsSeeder
/*********************************
* ░░░░░░░░░░░░░░░░░░░░░░░░░░░░░ *
* ░░░░░░░░░░░░░░░░░░░░░░░░░░░░░ *
* ░░░░░░█████████░░█████████░░░ *
* ░░░░░░██░░░████░░██░░░████░░░ *
* ░░██████░░░████████░░░████░░░ *
* ░░██░░██░░░████░░██░░░████░░░ *
* ░░██░░██░░░████░░██░░░████░░░ *
* ░░░░░░█████████░░█████████░░░ *
* ░░░░░░░░░░░░░░░░░░░░░░░░░░░░░ *
* ░░░░░░░░░░░░░░░░░░░░░░░░░░░░░ *
*********************************/
pragma solidity ^0.8.6;
import { INounsDescriptor } from './INounsDescriptor.sol';
interface INounsSeeder {
struct Seed {
uint48 background;
uint48 body;
uint48 accessory;
uint48 head;
uint48 glasses;
}
function generateSeed(uint256 nounId, INounsDescriptor descriptor) external view returns (Seed memory);
}NounsAuctionHouse.sol
/contracts/NounsAuctionHouse.sol
NounsAuctionHouse.sol
NounsAuctionHouse.sol
// SPDX-License-Identifier: GPL-3.0
/// @title The Nouns DAO auction house
/*********************************
* ░░░░░░░░░░░░░░░░░░░░░░░░░░░░░ *
* ░░░░░░░░░░░░░░░░░░░░░░░░░░░░░ *
* ░░░░░░█████████░░█████████░░░ *
* ░░░░░░██░░░████░░██░░░████░░░ *
* ░░██████░░░████████░░░████░░░ *
* ░░██░░██░░░████░░██░░░████░░░ *
* ░░██░░██░░░████░░██░░░████░░░ *
* ░░░░░░█████████░░█████████░░░ *
* ░░░░░░░░░░░░░░░░░░░░░░░░░░░░░ *
* ░░░░░░░░░░░░░░░░░░░░░░░░░░░░░ *
*********************************/
// LICENSE
// NounsAuctionHouse.sol is a modified version of Zora's AuctionHouse.sol:
// https://github.com/ourzora/auction-house/blob/54a12ec1a6cf562e49f0a4917990474b11350a2d/contracts/AuctionHouse.sol
//
// AuctionHouse.sol source code Copyright Zora licensed under the GPL-3.0 license.
// With modifications by Nounders DAO.
pragma solidity ^0.8.6;
import { PausableUpgradeable } from '@openzeppelin/contracts-upgradeable/security/PausableUpgradeable.sol';
import { ReentrancyGuardUpgradeable } from '@openzeppelin/contracts-upgradeable/security/ReentrancyGuardUpgradeable.sol';
import { OwnableUpgradeable } from '@openzeppelin/contracts-upgradeable/access/OwnableUpgradeable.sol';
import { IERC20 } from '@openzeppelin/contracts/token/ERC20/IERC20.sol';
import { INounsAuctionHouse } from './interfaces/INounsAuctionHouse.sol';
import { INounsToken } from './interfaces/INounsToken.sol';
import { IWETH } from './interfaces/IWETH.sol';
contract NounsAuctionHouse is INounsAuctionHouse, PausableUpgradeable, ReentrancyGuardUpgradeable, OwnableUpgradeable {
// The Nouns ERC721 token contract
INounsToken public nouns;
// The address of the WETH contract
address public weth;
// The minimum amount of time left in an auction after a new bid is created
uint256 public timeBuffer;
// The minimum price accepted in an auction
uint256 public reservePrice;
// The minimum percentage difference between the last bid amount and the current bid
uint8 public minBidIncrementPercentage;
// The duration of a single auction
uint256 public duration;
// The active auction
INounsAuctionHouse.Auction public auction;
/**
* @notice Initialize the auction house and base contracts,
* populate configuration values, and pause the contract.
* @dev This function can only be called once.
*/
function initialize(
INounsToken _nouns,
address _weth,
uint256 _timeBuffer,
uint256 _reservePrice,
uint8 _minBidIncrementPercentage,
uint256 _duration
) external initializer {
__Pausable_init();
__ReentrancyGuard_init();
__Ownable_init();
_pause();
nouns = _nouns;
weth = _weth;
timeBuffer = _timeBuffer;
reservePrice = _reservePrice;
minBidIncrementPercentage = _minBidIncrementPercentage;
duration = _duration;
}
/**
* @notice Settle the current auction, mint a new Noun, and put it up for auction.
*/
function settleCurrentAndCreateNewAuction() external override nonReentrant whenNotPaused {
_settleAuction();
_createAuction();
}
/**
* @notice Settle the current auction.
* @dev This function can only be called when the contract is paused.
*/
function settleAuction() external override whenPaused nonReentrant {
_settleAuction();
}
/**
* @notice Create a bid for a Noun, with a given amount.
* @dev This contract only accepts payment in ETH.
*/
function createBid(uint256 nounId) external payable override nonReentrant {
INounsAuctionHouse.Auction memory _auction = auction;
require(_auction.nounId == nounId, 'Noun not up for auction');
require(block.timestamp < _auction.endTime, 'Auction expired');
require(msg.value >= reservePrice, 'Must send at least reservePrice');
require(
msg.value >= _auction.amount + ((_auction.amount * minBidIncrementPercentage) / 100),
'Must send more than last bid by minBidIncrementPercentage amount'
);
address payable lastBidder = _auction.bidder;
// Refund the last bidder, if applicable
if (lastBidder != address(0)) {
_safeTransferETHWithFallback(lastBidder, _auction.amount);
}
auction.amount = msg.value;
auction.bidder = payable(msg.sender);
// Extend the auction if the bid was received within `timeBuffer` of the auction end time
bool extended = _auction.endTime - block.timestamp < timeBuffer;
if (extended) {
auction.endTime = _auction.endTime = block.timestamp + timeBuffer;
}
emit AuctionBid(_auction.nounId, msg.sender, msg.value, extended);
if (extended) {
emit AuctionExtended(_auction.nounId, _auction.endTime);
}
}
/**
* @notice Pause the Nouns auction house.
* @dev This function can only be called by the owner when the
* contract is unpaused. While no new auctions can be started when paused,
* anyone can settle an ongoing auction.
*/
function pause() external override onlyOwner {
_pause();
}
/**
* @notice Unpause the Nouns auction house.
* @dev This function can only be called by the owner when the
* contract is paused. If required, this function will start a new auction.
*/
function unpause() external override onlyOwner {
_unpause();
if (auction.startTime == 0 || auction.settled) {
_createAuction();
}
}
/**
* @notice Set the auction time buffer.
* @dev Only callable by the owner.
*/
function setTimeBuffer(uint256 _timeBuffer) external override onlyOwner {
timeBuffer = _timeBuffer;
emit AuctionTimeBufferUpdated(_timeBuffer);
}
/**
* @notice Set the auction reserve price.
* @dev Only callable by the owner.
*/
function setReservePrice(uint256 _reservePrice) external override onlyOwner {
reservePrice = _reservePrice;
emit AuctionReservePriceUpdated(_reservePrice);
}
/**
* @notice Set the auction minimum bid increment percentage.
* @dev Only callable by the owner.
*/
function setMinBidIncrementPercentage(uint8 _minBidIncrementPercentage) external override onlyOwner {
minBidIncrementPercentage = _minBidIncrementPercentage;
emit AuctionMinBidIncrementPercentageUpdated(_minBidIncrementPercentage);
}
/**
* @notice Create an auction.
* @dev Store the auction details in the `auction` state variable and emit an AuctionCreated event.
* If the mint reverts, the minter was updated without pausing this contract first. To remedy this,
* catch the revert and pause this contract.
*/
function _createAuction() internal {
try nouns.mint() returns (uint256 nounId) {
uint256 startTime = block.timestamp;
uint256 endTime = startTime + duration;
auction = Auction({
nounId: nounId,
amount: 0,
startTime: startTime,
endTime: endTime,
bidder: payable(0),
settled: false
});
emit AuctionCreated(nounId, startTime, endTime);
} catch Error(string memory) {
_pause();
}
}
/**
* @notice Settle an auction, finalizing the bid and paying out to the owner.
* @dev If there are no bids, the Noun is burned.
*/
function _settleAuction() internal {
INounsAuctionHouse.Auction memory _auction = auction;
require(_auction.startTime != 0, "Auction hasn't begun");
require(!_auction.settled, 'Auction has already been settled');
require(block.timestamp >= _auction.endTime, "Auction hasn't completed");
auction.settled = true;
if (_auction.bidder == address(0)) {
nouns.burn(_auction.nounId);
} else {
nouns.transferFrom(address(this), _auction.bidder, _auction.nounId);
}
if (_auction.amount > 0) {
_safeTransferETHWithFallback(owner(), _auction.amount);
}
emit AuctionSettled(_auction.nounId, _auction.bidder, _auction.amount);
}
/**
* @notice Transfer ETH. If the ETH transfer fails, wrap the ETH and try send it as WETH.
*/
function _safeTransferETHWithFallback(address to, uint256 amount) internal {
if (!_safeTransferETH(to, amount)) {
IWETH(weth).deposit{ value: amount }();
IERC20(weth).transfer(to, amount);
}
}
/**
* @notice Transfer ETH and return the success status.
* @dev This function only forwards 30,000 gas to the callee.
*/
function _safeTransferETH(address to, uint256 value) internal returns (bool) {
(bool success, ) = to.call{ value: value, gas: 30_000 }(new bytes(0));
return success;
}
}Conclusion
In this article, we explored the NounsAuctionHouse contract in Nouns using Bunzz's new DeCipher feature. I hope you found this useful. I plan to continue exploring specific NFTs and contracts in future articles.


