Sure, I can provide a basic example of an auction contract written in Vyper. Please modify it according to your needs.
# Auction Contract
# Auction params
# Beneficiary receives money from the highest bidder
beneficiary: public(address)
auctionStart: public(timestamp)
auctionEnd: public(timestamp)
# Current state of the auction.
highestBidder: public(address)
highestBid: public(wei_value)
# Set to true at the end, disallows any change
ended: public(bool)
# Events that will be fired on changes.
AuctionEnded: event({highestBidder: address, highestBid: wei_value})
@public
@payable
def bid():
# Check if auction endtime has not been passed
assert block.timestamp < self.auctionEnd
# Check if bid is high enough
assert msg.value > self.highestBid
# Return the money to the previous highest bidder
send(self.highestBidder, self.highestBid)
# Save the new highest bidder
self.highestBidder = msg.sender
self.highestBid = msg.value
@public
def endAuction():
# Check if auction endtime has not been passed
assert block.timestamp >= self.auctionEnd
# Check if this function has already been called
assert not self.ended
# Set the flag to end the auction
self.ended = True
# Announce the winner
log.AuctionEnded(self.highestBidder, self.highestBid)
# Send the money to the beneficiary
send(self.beneficiary, self.highestBid)
@public
def __init__(_beneficiary: address, _biddingTime: uint256):
self.beneficiary = _beneficiary
self.auctionStart = block.timestamp
self.auctionEnd = self.auctionStart + _biddingTime
In this contract, the highest bidder is stored and when a new highest bid comes in, the previous highest bidder gets their money back. The auction can be ended using the endAuction function which transfers the highest bid to the beneficiary.
Please note that this is a simple example and a real-world contract would need more features like safety checks, error handling etc. Also, it's important to remember that contract testing is critical before deploying it to the mainnet.