-
Notifications
You must be signed in to change notification settings - Fork 0
/
Calyptus383.sol
72 lines (52 loc) · 2 KB
/
Calyptus383.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
// SPDX-License-Identifier:MIT
pragma solidity >= 0.8.24;
//https://x.com/CalyptusCareers/status/1796478087426961770
//Have a look at this Auction contract. Would you feel confident deploying it? 👀
contract SimpleAuction {
address public beneficiary;
uint256 public auctionEndTime;
address public highestBidder;
uint256 public highestBid;
mapping (address => uint256) pendingReturns;
bool ended;
event HighestBidIncreased(address bidder, uint256 amount);
event AuctionEnded(address winner, uint256 amount) ;
// Custom errors
error AuctionAlreadyEnded();
error BidNotHighEnough(uint256 currentHighestBid);
error AuctionNotYetEnded();
error AuctionEndAlreadyCalled();
constructor(uint256 _biddingTime, address _beneficiary) {
beneficiary = _beneficiary;
auctionEndTime = block.timestamp +_biddingTime;
}
function bid() external payable {
if (block.timestamp > auctionEndTime) revert AuctionAlreadyEnded();
if (msg.value <= highestBid) revert BidNotHighEnough(highestBid);
if (highestBidder != address(0)) {
pendingReturns[highestBidder] += highestBid;
}
highestBidder = msg.sender;
highestBid = msg.value;
emit HighestBidIncreased(msg.sender, msg.value);
}
function withdraw() external returns (bool) {
uint256 amount = pendingReturns[msg.sender];
if (amount > 0) {
pendingReturns[msg.sender] = 0;
(bool success,) = payable(msg.sender).call{value: amount}("");
if (!success) {
pendingReturns[msg. sender] = amount;
return false;
}
}
return true;
}
function auctionEnd() external {
if (block.timestamp < auctionEndTime) revert AuctionNotYetEnded();
if (ended) revert AuctionEndAlreadyCalled();
ended = true;
emit AuctionEnded(highestBidder, highestBid);
payable(beneficiary).transfer(highestBid);
}
}