ERC1155 Data Manager
Data Managers are independent smart contracts that implement business logic for data management, serving as the primary entry point for user interactions and ensuring the underlying storage aligns with the required use-case logic.
There are various implementations of Data Managers, as they can integrate any logic, offering limitless possibilities. Having covered the core concepts, let's explore specific minimal implementations.
Data Managers can interact with each other. In this example, two Data Managers are deployed, with ERC1155 and ERC20 being essential for communication.
ERC1155 With ERC20Fractions DataManager
Contract Explanation
The MinimalisticERC1155WithERC20FractionsDataManager
smart contract implements the ERC1155 interface, treating each token in the collection as an ERC20.
The contract inherits several ERC1155 functionalities and includes IFractionTransferEventEmitter
to emit events across multiple Data Managers. Changes in one Data Manager will update the other, and events are emitted across both Data Managers.
State Variables
Generic Data Manager
Variable Name | Description | Type | Visibility |
---|---|---|---|
_datapoint | DataPoint for fungible fractions | DataPoint | internal |
fungibleFractionsDO | Fungible Fractions Data Object contract | IDataObject | public |
dataIndex | Data Index implementation | IDataIndex | public |
ERC1155 Specific
Variable Name | Description | Type | Visibility |
---|---|---|---|
_name | Name of the ERC1155 token | string | private |
_symbol | Symbol of the ERC1155 token | string | private |
_defaultURI | Default URI for token types | string | private |
_operatorApprovals | Approvals state for operators per address | mapping(address => mapping(address => bool)) | private |
ERC20 Fractions Specific
This part is not mandatory, but we incorporate this information to help retrieve and managing the fractions more easily.
Variable Name | Description | Type | Visibility |
---|---|---|---|
erc20FractionsDMFactory | Factory for ERC20FractionDataManager | MinimalisticERC20FractionDataManagerFactory | public |
fractionManagersById | ERC20FractionDataManager by token ID | mapping(uint256 => address) | public |
fractionManagersByAddress | Token ID by ERC20FractionDataManager address | mapping(address => uint256) | public |
Following an Standard Interface and forwarding methods
In this section, we’ll demonstrate how to perform a write operation to a DataPoint using the ERC1155 Standard Interface, using the mint()
operation as an example.
For external users allowed to mint, the public method follows the standard but requires proper internal management.
We perform validation checks on the token ID and ensure the receiver is not a zero address. Before calling this method, we verify if the ERC20Fractions Data Manager has been deployed. Then, we proceed with the logic using the appropriate storage references.
The _updateWithAcceptanceCheck()
method performs user updates and checks if the destination implements IERC1155Receiver.onERC1155Received
as required by the IERC1155 standard. After update()
, we call _doSafeBatchTransferAcceptanceCheck(operator, from, to, ids, values, data)
.
Following the internal calls, you'll see how it notifies the ERC20 Data Manager and forwards the write operation to the Data Index.
We check that variables like fungibleFractionsDO
and _datapoint
are set in the constructor, then pass the operation selector encoded with the operation values.
This flow applies to any write()
operation, such as burning or transferring. For read()
operations, we can directly call the DataObject, as demonstrated in the following method: