@@ -8,13 +8,21 @@ import {AbstractBlocklockReceiver} from "@blocklock-solidity/src/AbstractBlocklo
8
8
// Import ReentrancyGuard which is an Openzeppelin solidity library that helps prevent reentrant calls to a function.
9
9
import {ReentrancyGuard} from "@openzeppelin/contracts/utils/ReentrancyGuard.sol " ;
10
10
11
+ /// @title Sealed Bid Auction interface
12
+ /// @author Randamu developers
13
+ /// @notice An interface for a sealed bid auction smart contract
14
+ /// allowing encrypted bids which are decrypted at a future block number.
11
15
interface ISealedBidAuction {
12
16
function placeSealedBid (TypesLib.Ciphertext calldata sealedBid ) external payable returns (uint256 );
13
17
function withdrawRefund () external ;
14
18
function fulfillHighestBid () external payable ;
15
19
function finalizeAuction () external ;
16
20
}
17
21
22
+ /// @title Sealed Bid Auction contract
23
+ /// @author Randamu developers
24
+ /// @notice A bid smart contract which allows sealed bids to be made in an auction.
25
+ /// The bids are automatically decrypted at a future block number (block number that closes the bidding window).
18
26
contract SealedBidAuction is ISealedBidAuction , AbstractBlocklockReceiver , ReentrancyGuard {
19
27
struct Bid {
20
28
uint256 bidID; // Unique identifier for the bid
@@ -77,11 +85,12 @@ contract SealedBidAuction is ISealedBidAuction, AbstractBlocklockReceiver, Reent
77
85
seller = msg .sender ;
78
86
}
79
87
80
- // BID PHASES
81
- /**
82
- * Phase 1. Bidding Phase
83
- */
84
- // Submit a sealed bid
88
+ /// BID PHASES
89
+
90
+ /// @dev Phase 1. Bidding Phase
91
+ /// @notice Submit a sealed bid to participate in the auction.
92
+ /// @param sealedBid The encrypted bid amount to submit to the auction.
93
+ /// @return bidID The unique identifier for the submitted bid.
85
94
function placeSealedBid (TypesLib.Ciphertext calldata sealedBid )
86
95
external
87
96
payable
@@ -111,10 +120,10 @@ contract SealedBidAuction is ISealedBidAuction, AbstractBlocklockReceiver, Reent
111
120
return bidID;
112
121
}
113
122
114
- /**
115
- * Phase 2. Reveal Phase
116
- */
117
- // Unseal sealed bid
123
+ /// @dev Phase 2. Reveal Phase
124
+ /// @notice Unseals the sealed bid after the bidding phase has ended.
125
+ /// @param requestID The unique identifier for the bid to unseal.
126
+ /// @param decryptionKey The key used to decrypt the sealed bid.
118
127
function receiveBlocklock (uint256 requestID , bytes calldata decryptionKey )
119
128
external
120
129
override
@@ -140,6 +149,9 @@ contract SealedBidAuction is ISealedBidAuction, AbstractBlocklockReceiver, Reent
140
149
emit BidUnsealed (bid.bidID, bid.bidder, bid.unsealedBid);
141
150
}
142
151
152
+ /// @dev Updates the highest bid during the reveal phase.
153
+ /// @param bidID The unique identifier of the bid being evaluated.
154
+ /// @param unsealedBid The decrypted bid amount.
143
155
function updateHighestBid (uint256 bidID , uint256 unsealedBid ) internal {
144
156
Bid storage bid = bidsById[bidID];
145
157
@@ -155,10 +167,8 @@ contract SealedBidAuction is ISealedBidAuction, AbstractBlocklockReceiver, Reent
155
167
emit BidUnsealed (bidID, bid.bidder, unsealedBid);
156
168
}
157
169
158
- /**
159
- * Phase 3. Auction Finalization
160
- */
161
- // Withdraw refundable reserve amounts paid during bidding
170
+ /// @dev Phase 3. Auction Finalization
171
+ /// @notice Allows bidders (except the highest bidder) to withdraw refundable reserve amounts.
162
172
function withdrawRefund () external onlyAfter (biddingEndBlock) onlyAfterBidsUnsealed nonReentrant {
163
173
require (msg .sender != highestBidder, "Highest bidder cannot withdraw refund. " );
164
174
Bid memory bid = bids[msg .sender ];
@@ -169,7 +179,8 @@ contract SealedBidAuction is ISealedBidAuction, AbstractBlocklockReceiver, Reent
169
179
emit ReservePriceClaimed (bid.bidID, msg .sender , amount);
170
180
}
171
181
172
- // Fulfil highest bid
182
+ /// @dev Fulfill the highest bid after the bidding ends and bids are unsealed.
183
+ /// @notice Only the highest bidder can fulfill the bid and pay the difference.
173
184
function fulfillHighestBid () external payable onlyAfter (biddingEndBlock) onlyAfterBidsUnsealed {
174
185
require (highestBid > 0 , "Highest bid is zero. " );
175
186
require (msg .sender == highestBidder, "Only the highest bidder can fulfil. " );
@@ -183,16 +194,23 @@ contract SealedBidAuction is ISealedBidAuction, AbstractBlocklockReceiver, Reent
183
194
emit HighestBidFulfilled (msg .sender , msg .value + RESERVE_PRICE);
184
195
}
185
196
186
- // Finalize auction
197
+ /// @dev Finalizes the auction and declares the winner.
198
+ /// @notice Marks the auction as ended and emits an event with the winning bid and bidder.
187
199
function finalizeAuction () external onlyAfterBidsUnsealed {
188
200
require (! auctionEnded, "Auction already finalised. " );
189
201
auctionEnded = true ;
190
202
emit AuctionEnded (highestBidder, highestBid);
191
203
}
192
204
193
- /**
194
- * Getters
195
- */
205
+ /// GETTERS
206
+
207
+ /// @dev Retrieves bid details using the bid ID.
208
+ /// @param bidID The unique identifier for the bid.
209
+ /// @return sealedBid The encrypted sealed bid.
210
+ /// @return decryptionKey The decryption key used for revealing the bid.
211
+ /// @return unsealedBid The decrypted bid amount.
212
+ /// @return bidder The address of the bidder.
213
+ /// @return revealed Whether the bid has been revealed.
196
214
function getBidWithBidID (uint256 bidID )
197
215
external
198
216
view
@@ -211,6 +229,13 @@ contract SealedBidAuction is ISealedBidAuction, AbstractBlocklockReceiver, Reent
211
229
revealed = bidsById[bidID].revealed;
212
230
}
213
231
232
+ /// @dev Retrieves bid details using the bidder's address.
233
+ /// @param bidder The address of the bidder.
234
+ /// @return sealedBid The encrypted sealed bid.
235
+ /// @return decryptionKey The decryption key used for revealing the bid.
236
+ /// @return unsealedBid The decrypted bid amount.
237
+ /// @return _bidder The address of the bidder.
238
+ /// @return revealed Whether the bid has been revealed.
214
239
function getBidWithBidder (address bidder )
215
240
external
216
241
view
@@ -229,6 +254,9 @@ contract SealedBidAuction is ISealedBidAuction, AbstractBlocklockReceiver, Reent
229
254
revealed = bidsById[bidderToBidID[bidder]].revealed;
230
255
}
231
256
257
+ /// @dev Retrieves the current highest bid and bidder's address.
258
+ /// @return highestBidAmount The amount of the highest bid.
259
+ /// @return highestBidderAddress The address of the highest bidder.
232
260
function getHighestBid () external view returns (uint256 highestBidAmount , address highestBidderAddress ) {
233
261
highestBidAmount = highestBid;
234
262
highestBidderAddress = highestBidder;
0 commit comments