-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAuction.sol
More file actions
112 lines (106 loc) · 3.18 KB
/
Auction.sol
File metadata and controls
112 lines (106 loc) · 3.18 KB
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
// SPDX-License-Identifier: GPL-3.0
pragma solidity >=0.8.9;
import "@openzeppelin/contracts/token/ERC721/IERC721.sol";
import "Sender.sol";
//I really dont want to test this lmao im too tired
contract Auction{
address payable owner;
uint256 currentprice;
string description;
int256 start;
int256 auctionEnd;
bool forced;
IERC721 public nft;
uint public nftId;
struct Bid {
address payable addr;
uint256 price;
}
Bid[] bidHistory;
event bidUpdated(uint256 price, uint auctionEnd,Sender[] history);
constructor(int256 timeindays,uint256 startingprice, string memory _desc) descCheck(_desc) {
description = _desc;
owner = payable (msg.sender);
start = int(block.timestamp);
auctionEnd = start + timeindays;
currentprice = startingprice;
forced = false;
}
function setNft(address _nftaddress, uint _nftId) public{
nft = IERC721(_nftaddress);
nftId = _nftId;
}
modifier descCheck(string memory desc)
{
require(100>countWords(),"words too high");
_;
}
function countWords() public pure returns(uint256){
uint256 count = 0;
// for(uint256 a=0;a<bytes(words).length;a++){
// if ( words[0] == " "){
// count +=1;
// }
// }
return count;
}
function aucEnding() view public returns (bool){
return (auctionEnd <= int(block.number));
}
function timeLeft() view public returns(int256){
return(auctionEnd- int256(block.number));
}
function forceEndAuction() public{
auctionEnd = int256(block.number);
forced= true;
}
event latest(uint256 price);
function updateBiddingPrice(uint256 bid) public higherBid(bid) {
require(!aucEnding(),"auction is already over");
require(msg.sender.balance > bid,"u broke");
auctionEnd += 6 seconds;
currentprice = bid;
bidHistory.push(Bid(payable(msg.sender),bid));
}
//prompt highest bidder to send money to the person if it wasnt force ended
//if transaction isn't required then it cancels transfer
function endAuction(Sender sendy) payable public toOwner(sendy){
require(aucEnding(),"auction hasn't ended");
if(!forced && msg.sender==bidHistory[bidHistory.length-1].addr){
nft.safeTransferFrom(address(this), msg.sender, nftId);
sendy.execute();
}
else{
sendy.cancel;
}
}
modifier sameasHighest(uint256 bid){
require(bid == bidHistory[bidHistory.length-1].price);
_;
}
function latestB() public view returns (uint256 price)
{
return currentprice;
}
function ownerBoi() public view returns(address){
return owner;
}
modifier toOwner(Sender s)
{
require(s.receiver() == owner);
_;
}
function latestBid() public returns(string memory){
emit latest(currentprice);
return "";
}
modifier zeroBid(uint256 bid)
{
require(bid!=0);
_;
}
modifier higherBid(uint256 bid){
require(bid>=currentprice, "bid too low");
_;
}
}