Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update DutchAuction.sol #153

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 13 additions & 3 deletions contracts/Auction/DutchAuction.sol
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,10 @@ interface IERC721 {
) external;
}

error AuctionExpired();
error AuctionFinished();
error InsufficientValue(uint256 receivedAmount, uint256 requiredAmount);

contract DutchAuction {
event Buy(address winner, uint256 amount);

Expand Down Expand Up @@ -41,15 +45,21 @@ contract DutchAuction {

function buy() external payable {
// Check for the timestamp before buy
require(block.timestamp < expiresAt, "auction expired");
if(block.timestamp >= expiresAt){
revert AuctionExpired();
}

require(winner == address(0), "auction finished");
if(winner != address(0)) {
revert AuctionFinished();
}

uint256 timeElapsed = block.timestamp - startAt;
uint256 deduction = priceDeductionRate * timeElapsed;
uint256 price = startingPrice - deduction;

require(msg.value >= price, "ETH < price");
if(msg.value < price){
revert InsufficientValue(msg.value, price);
}

winner = msg.sender;
nft.transferFrom(seller, msg.sender, nftId);
Expand Down