-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathNounsMarketWrapper.sol
138 lines (122 loc) · 4.43 KB
/
NounsMarketWrapper.sol
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
// SPDX-License-Identifier: Beta Software
pragma solidity ^0.8;
// ============ External Imports ============
import {INounsAuctionHouse} from "../vendor/markets/INounsAuctionHouse.sol";
// ============ Internal Imports ============
import {IMarketWrapper} from "./IMarketWrapper.sol";
/**
* @title NounsMarketWrapper
* @author Anna Carroll + Nounders
* @notice MarketWrapper contract implementing IMarketWrapper interface
* according to the logic of Nouns' Auction Houses
*/
contract NounsMarketWrapper is IMarketWrapper {
// ============ Public Immutables ============
INounsAuctionHouse public immutable market;
// ======== Constructor =========
constructor(address _nounsAuctionHouse) {
market = INounsAuctionHouse(_nounsAuctionHouse);
}
// ======== External Functions =========
/**
* @notice Determine whether there is an existing, active auction
* for this token. In the Nouns auction house, the current auction
* id is the token id, which increments sequentially, forever. The
* auction is considered active while the current block timestamp
* is less than the auction's end time.
* @return TRUE if the auction exists
*/
function auctionExists(uint256 auctionId) public view returns (bool) {
(uint256 currentAuctionId, , , uint256 endTime, , ) = market.auction();
return auctionId == currentAuctionId && block.timestamp < endTime;
}
/**
* @notice Determine whether the given auctionId and tokenId is active.
* We ignore nftContract since it is static for all nouns auctions.
* @return TRUE if the auctionId and tokenId matches the active auction
*/
function auctionIdMatchesToken(
uint256 auctionId,
address, /* nftContract */
uint256 tokenId
) public view override returns (bool) {
return auctionId == tokenId && auctionExists(auctionId);
}
/**
* @notice Calculate the minimum next bid for the active auction
* @return minimum bid amount
*/
function getMinimumBid(uint256 auctionId)
external
view
override
returns (uint256)
{
require(
auctionExists(auctionId),
"NounsMarketWrapper::getMinimumBid: Auction not active"
);
(, uint256 amount, , , address payable bidder, ) = market.auction();
if (bidder == address(0)) {
// if there are NO bids, the minimum bid is the reserve price
return market.reservePrice();
}
// if there ARE bids, the minimum bid is the current bid plus the increment buffer
uint8 minBidIncrementPercentage = market.minBidIncrementPercentage();
return amount + ((amount * minBidIncrementPercentage) / 100);
}
/**
* @notice Query the current highest bidder for this auction
* @return highest bidder
*/
function getCurrentHighestBidder(uint256 auctionId)
external
view
override
returns (address)
{
require(
auctionExists(auctionId),
"NounsMarketWrapper::getCurrentHighestBidder: Auction not active"
);
(, , , , address payable bidder, ) = market.auction();
return bidder;
}
/**
* @notice Submit bid to Market contract
*/
function bid(uint256 auctionId, uint256 bidAmount) external override {
// line 104 of Nouns Auction House, createBid() function
(bool success, bytes memory returnData) = address(market).call{
value: bidAmount
}(abi.encodeWithSignature("createBid(uint256)", auctionId));
require(success, string(returnData));
}
/**
* @notice Determine whether the auction has been finalized
* @return TRUE if the auction has been finalized
*/
function isFinalized(uint256 auctionId)
external
view
override
returns (bool)
{
(uint256 currentAuctionId, , , , , bool settled) = market.auction();
bool settledNormally = auctionId != currentAuctionId;
bool settledWhenPaused = auctionId == currentAuctionId && settled;
return settledNormally || settledWhenPaused;
}
/**
* @notice Finalize the results of the auction
*/
function finalize(
uint256 /* auctionId */
) external override {
if (market.paused()) {
market.settleAuction();
} else {
market.settleCurrentAndCreateNewAuction();
}
}
}