uint public listingCounter
: A counter to keep track of the number of listings.
struct Listing
: A struct representing an ERC721 listing with fields for the listingId, order creator, ERC721 token address, token ID, price, signature, deadline and isSold.
mapping(uint => Listing) public listings
: A mapping that associates listing IDs with their respectiveListing
structs.
address _tokenAddress
: The address of the ERC721 token.uint _tokenID
: The token ID of the ERC721 token.uint _price
: The price of the listing in ether.bytes memory _signature
: The seller's signature of the order data.uint _deadline
: The deadline for the listing.
-
Owner Check:
- Check that
msg.sender
is the owner of the token usingownerOf(_tokenID)
.
- Check that
-
Approval Check:
- Check that
msg.sender
has approved the contract to spend the ERC721 token usingisApprovedForAll(msg.sender, address(this))
.
- Check that
-
Token Address Validation:
- Check that
_tokenAddress
is not the zero address (address(0)
). - Check if
_tokenAddress
has code (is a smart contract).
- Check that
-
Price Check:
- Check that
_price
is greater than 0.
- Check that
-
Deadline Check:
- Check that
_deadline
is greater thanblock.timestamp
.
- Check that
- Create a new
Listing
struct with the provided information. - Increment
listingCounter
to generate a new listing ID. - Store the
Listing
in thelistings
mapping using the new listing ID.
uint _listingId
: The ID of the listing to be executed.
-
Listing ID Check:
- Check that
_listingId
is less thanlistingCounter
.
- Check that
-
Payment Check:
- Check that
msg.value
is equal to the price of the listing.
- Check that
-
Deadline Check:
- Check that
block.timestamp
is less than or equal to the listing's deadline.
- Check that
-
Signature Verification:
- Verify that the
_signature
is signed by the listing's owner.
- Verify that the
- Retrieve the
Listing
information from storage based on_listingId
. - Transfer ether from the buyer to the seller.
- Transfer the ERC721 token from the seller to the buyer.
- Mark the listing as completed (optional, but useful for preventing double purchases).