Skip to content

StoreRegistry Contract Documentation

Overview

The StoreRegistry contract manages the registration, approval, and operation of stores in the TRASH Protocol. Store owners and managers can manage their stores, add or remove hosts, and apply for approval from governance. This contract ensures secure interactions between stores and other parts of the protocol through role-based access control using permissions.

Inherited Contracts

  • Storage: Provides the data structures and mappings for store management.
  • Owners: Manages the ownership of stores.
  • Operations: Provides functions for interacting with stores, such as adding, removing, or approving them.
  • Managers: Allows for the management of stores by store owners or designated managers.
  • Hosts: Manages the hosts for stores.
  • Applications: Handles the store approval process.
  • Creation: Manages the creation of new stores.
  • Permissions: Manages role-based access control.
  • NoETH: Prevents the contract from accepting Ether.

Functions

initialize(address _registryAddress)

  • Description: Initializes the contract by setting the registry address, which manages permissions and interactions with other protocol components.
  • Parameters:
  • _registryAddress: The address of the registry store contract.
  • Reverts:
  • CantSetZeroAddress: If the registry address provided is the zero address.

addStore(address storeManager, address[] calldata hosts)

  • Description: Adds a new store to the registry. Only store owners can add new stores.
  • Parameters:
  • storeManager: The address of the store manager.
  • hosts: An array of host addresses for the store.
  • Modifiers:
  • onlyStoreOwners: Ensures only store owners can call this function.
  • Emits:
  • StoreAdded: Emitted when a new store is added.

approveStore(uint256 storeId)

  • Description: Approves the store with the given ID. Only governance can approve stores.
  • Parameters:
  • storeId: The ID of the store to be approved.
  • Modifiers:
  • onlyGovernance: Ensures only governance can call this function.
  • Emits:
  • StoreApproved: Emitted when a store is approved.

setRegistryAddress(address _registryAddress)

  • Description: Updates the registry address. Only governance can update this address.
  • Parameters:
  • _registryAddress: The new address of the registry store.
  • Modifiers:
  • onlyGovernance: Ensures only governance can call this function.
  • Emits:
  • StoreRegistryAddressChanged: Emitted when the registry address is updated.

Supporting Abstract Contracts

Storage

  • Description: Defines the data structure for storing stores and their relationships.

Data Structure

  • Store:
  • storeOwner: The address of the store owner.
  • storeManager: The address of the store manager.
  • hosts: An array of addresses for store hosts.
  • approved: Whether the store is approved by governance.
  • id: The unique ID of the store.

Owners

  • Description: Manages store ownership.

Functions - Owners

  • isOwnerOfStore(uint256 storeId, address owner):

  • Checks if the specified owner is the owner of the store.

  • setStoreOwner(uint256 storeId, address owner):

  • Sets a new owner for the specified store. Only the current store owner can set a new owner.

Operations

  • Description: Provides functions for interacting with stores, such as retrieving store information and deleting stores.

Functions - Operations

  • getStore(uint256 storeId):

  • Retrieves the details of a store.

  • getStoresByStoreOwner(address storeOwner):

  • Retrieves all stores owned by the specified store owner.

  • deleteStore(uint256 storeId):

  • Deletes a store and removes it from the owner's store count. Only the store manager or owner can delete a store.
  • Emits:
  • StoreDeleted: Emitted when a store is deleted.

Managers

  • Description: Manages store managers.

Functions - Managers

  • isStoreManager(uint256 storeId, address manager):

  • Checks if the specified manager is the manager of the store.

  • setStoreManager(uint256 storeId, address manager):

  • Sets a new manager for the specified store. Only the store owner or manager can set a new manager.
  • Emits:
  • StoreManagerSet: Emitted when a new store manager is set.

Hosts

  • Description: Manages store hosts.

Functions - Hosts

  • isStoreHost(uint256 storeId, address host):

  • Checks if the specified host is a host of the store.

  • getHostsStores(address host):

  • Retrieves all stores where the specified address is a host.

  • addStoreHost(uint256 storeId, address host):

  • Adds a new host to the store.
  • Emits:

  • StoreHostAdded: Emitted when a new host is added to the store.

  • removeStoreHost(uint256 storeId, address host):

  • Removes a host from the store.
  • Emits:

  • StoreHostRemoved: Emitted when a host is removed from the store.

  • replaceStoreHosts(uint256 storeId, address[] memory hosts):

  • Replaces the current hosts of a store with the provided list of hosts.
  • Emits:

  • StoreHostsReplaced: Emitted when the hosts of a store are replaced.

  • clearAllHosts(uint256 storeId):

  • Clears all hosts from the store.

Applications

  • Description: Handles the approval process for stores.

Functions - Applications

  • isStoreApproved(uint256 storeId):

  • Checks if the specified store has been approved by governance.

  • getStoreApplications():

  • Retrieves all stores that have not yet been approved.

  • _approveStore(uint256 storeId):

  • Approves the store with the given ID.
  • Emits:
  • StoreApproved: Emitted when a store is approved.

Creation

  • Description: Manages the creation of new stores.

Functions - Creation

  • _addStore(address storeManager, address[] calldata hosts):
  • Adds a new store to the registry. This is an internal function used by the addStore public function.
  • Emits:

  • StoreAdded: Emitted when a new store is added.

  • _createStore(address storeOwner, address storeManager, address[] calldata hosts, bool storeApproved):

  • Internal function for creating a new store with the provided details.

Errors

  • CantSetZeroAddress: Thrown when a zero address is provided where a valid address is required.
  • MismatchedRecipientsAndPercentages: Thrown when the recipients and percentages provided do not match.
  • SplitPercentagesExceed100: Thrown when the sum of the percentages exceeds 100.
  • StoreAlreadyExists: Thrown when trying to create a store that already exists.
  • StoreDoesNotExist: Thrown when trying to access a store that does not exist.
  • StoreAlreadyApproved: Thrown when trying to approve a store that has already been approved.
  • HostNotFound: Thrown when trying to remove a host that is not found in the store.
  • NotStoreManager: Thrown when an action is attempted by a non-store manager.
  • NotOwnerOfStore: Thrown when an action is attempted by a non-owner of the store.
  • NotStoreOwner: Thrown when an action requires store ownership, but the caller is not the owner.

Events

StoreEvents

Events - StoreEvents

  • StoreAdded(uint256 storeId): Emitted when a store is added.
  • StoreDeleted(uint256 storeId): Emitted when a store is deleted.
  • StoreApproved(uint256 storeId): Emitted when a store is approved.
  • StoreDoesNotExist(uint256 storeId): Emitted when a store does not exist.
  • StoreHostAdded(uint256 storeId, address host): Emitted when a new host is added to a store.
  • StoreHostRemoved(uint256 storeId, address host): Emitted when a host is removed from a store.
  • StoreOwnerSet(uint256 storeId, address owner): Emitted when a new store owner is set.
  • StoreManagerSet(uint256 storeId, address manager): Emitted when a new store manager is set.
  • StoreTrashAwardChanged(uint256 storeId, uint64 trashOnSale): Emitted when the store's trash award is changed.
  • StoreHostsReplaced(uint256 storeId, address[] hosts): Emitted when the hosts of a store are replaced.
  • StoreRegistryAddressChanged(address newAddress): Emitted when the registry address is updated.

Conclusion

The StoreRegistry contract provides a comprehensive system for managing stores in the TRASH Protocol. It allows store owners and managers to manage their stores, while governance