A comprehensive blockchain-based solution for managing access to worldwide laboratory equipment (Cyber-Physical Systems) through a decentralized platform. Built on Ethereum using the Diamond proxy pattern for maximum upgradeability and modularity.
DecentraLabs provides a blockchain infrastructure for managing remote laboratory access, reservations, and payments. The system enables:
- Lab Providers to register and manage their laboratory equipment as NFTs
- Users to discover, reserve, and access laboratory equipment worldwide
- Administrators to oversee the platform and manage roles
- Transparent payments using the native $LAB ERC20 token
This project implements a modular smart contract architecture using the EIP-2535 Diamond Standard, allowing for efficient upgrades and unlimited contract functionality.
Diamond Proxy (Main Contract)
βββ DiamondCutFacet (Upgrade management)
βββ DiamondLoupeFacet (Introspection)
βββ OwnershipFacet (Ownership management)
βββ LabFacet (Lab/NFT management)
βββ ProviderFacet (Provider & role management)
βββ ReservationFacet (Booking & payments)
βββ LabERC20 (External: $LAB token)
- Unlimited contract size: Break through the 24KB Ethereum contract size limit
- Upgradeable architecture: Add, replace, or remove functionality without redeploying
- Gas efficient: Share storage across all facets
- Modular design: Organize code into logical facets
- NFT-based labs: Each laboratory is represented as an ERC-721 token
- Comprehensive metadata: URI, pricing, authentication endpoints, and access keys
- Provider control: Lab owners can add, update, and delete their laboratories
- Paginated queries: Efficient retrieval of lab listings
- Transfer restrictions: Only lab providers can own lab NFTs
- Time-based booking: Reserve labs for specific time periods
- Interval tree calendar: Efficient O(log n) calendar conflict detection
- Multi-state workflow:
PENDING- User requests reservationBOOKED- Admin confirms reservationCOLLECTED- Provider claims payment after useCANCELLED- Cancelled by user or provider
- Automatic refunds: Failed or cancelled reservations are automatically refunded
- Batch processing: Providers can claim multiple completed reservations in batches
- ERC-20 compliant: Standard token interface
- Supply cap: Maximum supply of 1,000,000 tokens (1M tokens with 6 decimals)
- Burnable: Token holders can burn their tokens
- Pausable: Emergency pause functionality for security incidents
- Role-based minting: Only authorized contracts can mint new tokens
- Initial distribution: New providers receive initial token allocation
- Role-based access control: Distinct roles for admins and providers
- Provider registry: Track provider information (name, email, country)
- Automatic token grants: New providers receive initial $LAB tokens
- Provider updates: Providers can update their information
- Red-Black Tree: Self-balancing binary search tree for O(log n) operations
- Rival interval management: Prevents overlapping reservations
- Efficient lookups: Fast availability checking and booking confirmation
- Space efficient: Optimized storage using interval compression
- Access control: OpenZeppelin's AccessControlUpgradeable
- Input validation: Comprehensive parameter checking
- Reentrancy protection: Safe token transfer patterns
- Emergency controls: Pausable token for critical situations
- Immutable ownership: Diamond ownership can be transferred but not renounced
The main entry point implementing the EIP-2535 Diamond proxy pattern. Delegates all function calls to the appropriate facet using delegatecall.
Manages the upgrade mechanism allowing addition, replacement, and removal of facet functions.
Provides introspection into the Diamond's structure, allowing queries about available functions and their corresponding facets.
Manages the Diamond contract ownership following EIP-173.
Implements ERC-721 for laboratory NFTs with additional features:
- Add/update/delete labs
- Set token URIs
- Paginated lab queries
- Provider-only transfer restrictions
Manages lab providers and role assignments:
- Add/remove providers
- Update provider information
- Role-based access control integration
- Automatic token distribution
Handles the complete reservation lifecycle:
- Reservation requests
- Admin confirmations/denials
- Booking cancellations
- Fund collection for providers
- Balance tracking
The native platform token with:
- 6 decimal precision
- 1,000,000 token supply cap
- Minter role (granted to Diamond)
- Pauser role (for emergencies)
- Burnable tokens
Core Diamond Standard implementation managing facet storage and function selectors.
Diamond Storage pattern implementation providing shared storage across all facets.
Enhanced access control with role enumeration capabilities.
Red-Black tree implementation for efficient calendar management and conflict detection.
This solution is built upon the following Ethereum standards and implementations:
-
EIP-2535 Diamonds - Diamond-1-Hardhat Implementation by Nick Mudge
https://github.com/mudgen/diamond-1-hardhat -
ERC-809 - Rental NFT implementation concept by Greg Taschuk
https://github.com/gtaschuk/erc809 -
EIP-721 - NFT standard with OpenZeppelin upgradeable contracts
https://github.com/OpenZeppelin/openzeppelin-contracts-upgradeable -
EIP-2612 - Token permits (via OpenZeppelin ERC20)
-
EIP-173 - Contract ownership standard
- Register as a provider through the admin
- Receive initial $LAB token allocation
- Add laboratory equipment as NFTs
- Set pricing and access credentials
- Manage reservations and collect payments
- Update lab information as needed
- Browse available laboratories
- Check availability using the calendar system
- Request reservations with $LAB tokens
- Wait for admin confirmation
- Access laboratories during booked time
- Cancel if needed (with automatic refunds)
- Manage provider registrations
- Confirm or deny reservation requests
- Monitor platform activity
- Handle disputes
- Emergency pause if needed
struct Lab {
uint labId; // Unique identifier
string uri; // Metadata URI
uint96 price; // Price per reservation
string auth; // Authentication service URI
string accessURI; // Lab access endpoint
string accessKey; // Public routing key
}struct Reservation {
uint256 labId; // Lab identifier
address renter; // User address
uint96 price; // Reservation price
uint32 start; // Start timestamp
uint32 end; // End timestamp
uint status; // Reservation status
}struct Provider {
address account; // Provider address
string name; // Provider name
string email; // Contact email
string country; // Location
}- All contracts use OpenZeppelin's audited implementations
- Role-based access control prevents unauthorized actions
- Token transfers use safe transfer patterns
- Calendar system prevents double-booking
- Emergency pause capability for critical situations
- Comprehensive input validation throughout
- Supply cap prevents infinite token inflation
This project is licensed under the GNU General Public License v3.0 - see the LICENSE.txt file for details.
Portions of the code are also licensed under:
- MIT License (Diamond implementation)
- GPL-2.0-or-later (Custom facets)
- Juan Luis Ramos VillalΓ³n - [email protected]
- Luis de la Torre - [email protected]
- Nick Mudgen for the Diamond Standard implementation
- OpenZeppelin team for secure, audited contract libraries
- Greg Taschuk for the Rental NFT concept
- BokkyPooBah for the Red-Black Tree library foundation