Inventory Contract Documentation
Overview
The Inventory contract manages the storage, addition, and removal of NFTs into and from the inventory. It interacts with other components of the TRASH Protocol, including the Permissions system and the RegistryStore, to manage inventory items securely. Additionally, it adheres to the ERC721Receiver standard to allow NFTs to be transferred to this contract.
Inherited Contracts
- IERC721Receiver: Ensures the contract can receive ERC721 tokens.
- InventoryStorage: Manages the internal inventory state and contains utility functions for interacting with NFTs.
- Permissions: Ensures role-based access control, particularly for Ecosystem Operators.
Functions
initialize(address _registryAddress)
- Description: Initializes the contract by setting the registry address. This address is used to interact with other core components of the protocol.
- Parameters:
_registryAddress: The address of the registry store to manage permissions and interactions with other contracts.- Reverts:
CantSetZeroAddress: If the registry address provided is the zero address.
addToInventory(uint256 tokenId, address seller, uint256 priceInUSDC, uint256 storeId)
- Description: Adds a specified NFT to the inventory. Only addresses with the Ecosystem Operator role can add to the inventory.
- Parameters:
tokenId: The ID of the NFT being added to the inventory.seller: The address of the seller adding the NFT to the inventory.priceInUSDC: The price of the NFT in USDC.storeId: The ID of the store related to the inventory item.- Modifiers:
onlyEcosystemOperator: Ensures only authorized Ecosystem Operators can call this function.- Emits:
ItemAddedToInventory: Emitted when an item is added to the inventory.
removeFromInventory(uint256 tokenId, address buyer)
- Description: Removes a specified NFT from the inventory and transfers it to the buyer. Only addresses with the Ecosystem Operator role can remove items from the inventory.
- Parameters:
tokenId: The ID of the NFT to be removed from the inventory.buyer: The address of the buyer who will receive the NFT.- Modifiers:
onlyEcosystemOperator: Ensures only authorized Ecosystem Operators can call this function.- Emits:
ItemRemovedFromInventory: Emitted when an item is removed from the inventory.
getInventoryItem(address tokenAddress, uint256 tokenId)
- Description: Retrieves the details of a specific inventory item.
- Parameters:
tokenAddress: The address of the NFT contract.tokenId: The ID of the NFT.- Returns:
InventoryItem: The details of the inventory item, including the seller, store ID, and price.
getInventory(address tokenAddress, uint256 tokenId)
- Description: Retrieves the seller, price, and store ID of a specific inventory item.
- Parameters:
tokenAddress: The address of the NFT contract.tokenId: The ID of the NFT.- Returns:
seller: The address of the seller.priceInUSDC: The price of the NFT in USDC.storeId: The store ID related to the inventory item.
onERC721Received()
- Description: This function is required by the IERC721Receiver interface to allow the contract to receive NFTs.
- Returns:
bytes4: The selector foronERC721Received.
Supporting Abstract Contracts
InventoryStorage
-
Description: Manages the internal storage for inventory items, including mappings that associate NFTs with their prices and sellers.
-
InventoryItem: A struct that represents an inventory item, containing the following fields:
seller: The address of the seller.storeId: The ID of the store related to the item.tokenId: The ID of the token.priceInUSDC: The price of the item in USDC.
Internal Functions
-
_getNFTAddress(): -
Retrieves the address of the NFT contract using the registry.
-
_addToInventory(uint256 tokenId, address seller, uint256 priceInUSDC, uint256 storeId): -
Adds an NFT to the inventory.
-
_removeFromInventory(uint256 tokenId, address buyer): -
Removes an NFT from the inventory and transfers it to the buyer.
-
_getInventoryItem(address tokenAddress, uint256 tokenId): - Returns an inventory item for the specified token address and token ID.
Modifiers
marketplaceIsOwner(uint256 tokenId)
- Description: Ensures that the marketplace contract owns the specified NFT before proceeding.
- Reverts:
InventoryNotOwnerOfToken: If the marketplace is not the owner of the specified token.
Errors
- CantSetZeroAddress: Thrown when a zero address is passed where a valid address is expected.
- NotValidMinter: Thrown when a non-authorized minter attempts to mint tokens.
- InventoryNotOwnerOfToken: Thrown when the inventory contract is not the owner of the specified NFT.
Events
ItemAddedToInventory(uint256 tokenId, address tokenAddress, address seller, uint256 priceInUSDC, uint256 storeId)
- Description: Emitted when an NFT is added to the inventory.
- Parameters:
tokenId: The ID of the added NFT.tokenAddress: The address of the NFT contract.seller: The address of the seller who added the item.priceInUSDC: The price of the NFT in USDC.storeId: The ID of the store related to the item.
ItemRemovedFromInventory(uint256 tokenId, address tokenAddress, address buyer)
- Description: Emitted when an NFT is removed from the inventory and transferred to the buyer.
- Parameters:
tokenId: The ID of the removed NFT.tokenAddress: The address of the NFT contract.buyer: The address of the buyer who received the item.
Conclusion
The Inventory contract is responsible for managing the NFTs in the TRASH Protocol's marketplace. It allows Ecosystem Operators to add or remove items from the inventory while maintaining the details of each item. The contract ensures that role-based access control is enforced through the Permissions system and integrates with other components via the RegistryStore to manage NFTs securely.