From 46c082a7b2731fce9523cbf1e7b4815717aa5221 Mon Sep 17 00:00:00 2001 From: Tranquil-Flow <66773372+Tranquil-Flow@users.noreply.github.com> Date: Fri, 21 Jun 2024 18:56:11 +0200 Subject: [PATCH] replace removeBid with modified editBid --- packages/hardhat/contracts/Auction.sol | 30 +++++++++++++++----------- 1 file changed, 17 insertions(+), 13 deletions(-) diff --git a/packages/hardhat/contracts/Auction.sol b/packages/hardhat/contracts/Auction.sol index 9f7d090..ec8aee2 100644 --- a/packages/hardhat/contracts/Auction.sol +++ b/packages/hardhat/contracts/Auction.sol @@ -36,7 +36,7 @@ contract Auction is ReentrancyGuard { event AuctionStarted(uint indexed audioSlotID, string audioName, uint auctionStartTime); event BidPlaced(uint indexed audioSlotID, address indexed bidder, uint bidAmount); - event BidRemoved(uint indexed audioSlotID, address indexed bidder); + event BidEdited(uint indexed audioSlotID, address indexed bidder, uint newBidAmount); event AuctionEnded(uint indexed audioSlotID, address indexed winner, uint winningBid, string swarmLink); constructor() { @@ -70,22 +70,26 @@ contract Auction is ReentrancyGuard { emit BidPlaced(_audioSlotID, msg.sender, msg.value); } - function removeBid(uint _audioSlotID) external nonReentrant { + function editBid(uint _audioSlotID) external payable nonReentrant { AudioSlot storage slot = audioSlots[_audioSlotID]; Bid storage existingBid = bids[_audioSlotID][msg.sender]; - // Check the auction has ended - if (block.timestamp < slot.auctionStartTime + auctionLength) {revert AuctionNotEnded();} - - // Remove bid from bid list for the audio slot (set to 0) - uint returnAmount = existingBid.bidAmount; - existingBid.bidAmount = 0; - - // Transfer the bid amount back to the bidder - (bool success, ) = msg.sender.call{value: returnAmount}(""); - if (!success) {revert ETHTransferOutFailed();} + // Check the auction is ongoing + if (block.timestamp < slot.auctionStartTime) {revert AuctionNotStarted();} + if (block.timestamp > slot.auctionStartTime + auctionLength) {revert AuctionAlreadyEnded();} + + // Check bid amount is greater than zero + if (msg.value == 0) {revert BidAmountZero();} + + // Transfer the bid amount to the contract + (bool success, ) = address(this).call{value: msg.value}(""); + if (!success) {revert ETHTransferInFailed();} + + // Update the bid amount + uint newBidAmount = existingBid.bidAmount + msg.value; + existingBid.bidAmount = newBidAmount; - emit BidRemoved(_audioSlotID, msg.sender); + emit BidEdited(_audioSlotID, msg.sender, newBidAmount); } function startAuction(uint _audioSlotID, string calldata _audioName) external {