Skip to content

Coordinator Contract Documentation

Overview

The Coordinator contract handles core functionality of the TRASH Protocol, including the minting of tokens and handling the trashing process for stores. The contract integrates several components like TrashProcess, MintProcess, and Permissions, while also leveraging OpenZeppelin's ReentrancyGuard to protect against reentrancy attacks.

Inherited Contracts

  • ReentrancyGuardUpgradeable: Provides reentrancy protection for key functions.
  • RegistryStore: Centralized storage for managing permissions and registry addresses.
  • StoreOwnership: Manages store ownership and roles like managers or hosts.
  • TrashTokenMinter: Provides minting capabilities for $TRASH tokens.
  • StoreAuthorization: Manages the authorization for stores to handle minters and trashers.
  • MintProcess: Facilitates minting NFTs with associated stories.
  • TrashProcess: Handles the trashing of NFTs and rewarding stores with tokens.
  • Permissions: Governs roles like minters, trashers, and governance.

Functions

initialize(address _registryAddress)

  • Description: Initializes the contract by setting the registry address and enabling reentrancy protection.
  • Parameters:
  • _registryAddress: The address of the registry store contract that manages permissions and access control.
  • Reverts:
  • CantSetZeroAddress: If the registry address provided is the zero address.

trash(uint256 storeId, uint256 trashReward, uint256 priceInUSDC, uint256 tokenId)

  • Description: Trashes an NFT associated with a store, rewarding the caller with $TRASH tokens.
  • Parameters:
  • storeId: The ID of the store where the trashing takes place.
  • trashReward: The amount of $TRASH tokens to reward.
  • priceInUSDC: The price of the item in USDC.
  • tokenId: The ID of the NFT to be trashed.
  • Modifiers:
  • onlyTrasher: Ensures only authorized trashers can call this function.
  • nonReentrant: Protects against reentrancy attacks.
  • Reverts:
  • StoreNotApproved: If the store is not approved for trashing.
  • TokenNotApprovedForTransfer: If the NFT token is not approved for transfer.
  • InvalidRewardAmountForStore: If the reward amount does not match the store’s allocation.

mint(string calldata story)

  • Description: Mints a new NFT with an associated story for the caller.
  • Parameters:
  • story: A string representing the story to be inscribed on the minted NFT.
  • Modifiers:
  • onlyMinter: Ensures only authorized minters can call this function.
  • nonReentrant: Protects against reentrancy attacks.

onboard(uint256 storeId, address user)

  • Description: Authorizes a new user to interact with the specified store.
  • Parameters:
  • storeId: The ID of the store to which the user will be authorized.
  • user: The address of the user to be onboarded.
  • Modifiers:
  • onlyStoreOwnerHostOrManager: Ensures that only the store owner, host, or manager can call this function.
  • nonReentrant: Protects against reentrancy attacks.

offboard(uint256 storeId, address user)

  • Description: Revokes the authorization of a user from interacting with the specified store.
  • Parameters:
  • storeId: The ID of the store from which the user will be offboarded.
  • user: The address of the user to be offboarded.
  • Modifiers:
  • onlyStoreOwnerHostOrManager: Ensures that only the store owner, host, or manager can call this function.
  • nonReentrant: Protects against reentrancy attacks.

Supporting Abstract Contracts

MintProcess

  • Description: Handles the minting of NFTs with stories. This is triggered by the mint function in the Coordinator contract.

TrashProcess

  • Description: Handles the process of trashing NFTs and distributing rewards to the store. This is triggered by the trash function in the Coordinator contract.

  • _trash() performs the following steps:

    1. Verifies that the store is approved for trashing.
    2. Ensures the NFT is approved for transfer.
    3. Validates the reward amount against the store’s allocation.
    4. Mints $TRASH tokens as a reward for the trasher.
    5. Transfers the NFT to the store's inventory.

TrashTokenMinter

  • Description: Mints $TRASH tokens and is used within the TrashProcess to distribute rewards when an NFT is trashed.

StoreOwnership

  • Description: Verifies ownership, management, or hosting rights for store-related actions, such as onboarding and offboarding users.

StoreAuthorization

  • Description: Manages the roles and permissions for store operations, such as minters and trashers. It includes functions for authorizing and revoking user roles within a store.

  • onlyTrasher: Restricts function access to users who have the Trasher role.

  • onlyMinter: Restricts function access to users who have the Minter role.

Errors

  • CantSetZeroAddress: Thrown when a zero address is passed where a valid address is expected.
  • StoreNotApproved: Thrown when the store is not approved for the requested action.
  • NotTrasher: Thrown when a non-authorized user attempts to trash an NFT.
  • NotMinter: Thrown when a non-authorized user attempts to mint a token.
  • InvalidRewardAmountForStore: Thrown when the reward amount does not match the store’s allocation.
  • NotOwnerOfStore: Thrown when an unauthorized user attempts to perform store management actions.
  • TokenNotApprovedForTransfer: Thrown when an NFT is not approved for transfer.

Conclusion

The Coordinator contract is a core part of the TRASH Protocol, managing key processes like NFT minting and trashing while ensuring role-based access control using the Permissions system. With ReentrancyGuard in place, it is protected against reentrancy attacks during sensitive operations like minting and trashing.