I've just started learning about Chainlink Upkeepers, I'm very new to this and not able to plan my approach how to begin with automating the concludeAuction() function below. The smart contract manages the data of auctions with auctionItemId and this is also used as an argument. A single auctionItemId can be allocated only ones to a single auction item. Also, auctionItemId are keys to a private mapping.
I want to automate the conclusion of auction when the condition:
require(block.timestamp > idToAuctionItem[auctionItemId].startTime + idToAuctionItem[auctionItemId].auctionDuration) becomes true i.e. when auction timer expires.
I'm not able to understand how to start approaching the solution in terms of checkData is concerned as the auctionItemId need to be looked after, maybe or maybe not. Below is the whole function code written by me, any help is much appreciated.
function concludeAuction(address nftContract, uint256 auctionItemId) public payable nonReentrant {
require(msg.sender == idToAuctionItem[auctionItemId].seller, "You're not the auction creator");
require(block.timestamp > idToAuctionItem[auctionItemId].startTime + idToAuctionItem[auctionItemId].auctionDuration, "Bidding period not yet over");
require(idToAuctionItem[auctionItemId].sold == false, "Auction already concluded or canceled");
uint settlementPrice = idToHighestBid[auctionItemId].bidAmount;
uint tokenId = idToAuctionItem[auctionItemId].tokenId;
NFT nft = NFT(nftContract);
address soulCreator = nft.getSoulCreator(tokenId);
uint royalty = nft.getRoyalty(tokenId);
// 2.5% commission cut & royalty
uint _commissionValue = settlementPrice / 40 ;
uint _royalty = (settlementPrice * royalty) / 100 ;
uint _sellerValue = settlementPrice - _commissionValue - _royalty ;
payable(idToAuctionItem[auctionItemId].seller).transfer(_sellerValue);
owner.transfer(_commissionValue); // put commission account address in place of 'owner' in case different account needed for platform tax
IERC721(nftContract).transferFrom(address(this), idToHighestBid[auctionItemId].bidder, tokenId);
idToAuctionItem[auctionItemId].owner = payable(idToHighestBid[auctionItemId].bidder);
idToAuctionItem[auctionItemId].sold = true;
_auctionItemsSold.increment();
payable(soulCreator).transfer(_royalty);
}