A comprehensive blockchain-based solution for managing access to worldwide server-based simulations, laboratory equipment, and other 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 access, reservations, and payments to lab resources and services. 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)
βββ DistributionFacet (Tokenomics distribution and subsidies)
βββ IntentRegistryFacet (EIP-712 intent registration and consumption)
βββ ProviderFacet (Provider & institutional treasury management)
βββ LabFacet (Lab/NFT management)
βββ StakingFacet (Staking, slashing, and unstaking)
βββ Reservation Facets (Booking & payments for labs)
βββ 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 reservationCONFIRMED- Admin confirms reservationIN_USE- Reservation is activeCOMPLETED- Reservation finished, ready for collectionCOLLECTED- 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, providers, and institutions
- Provider registry: Track provider information (name, email, country)
- Institutional treasury: Manage token balances for institutional users
- 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.
Handles initial tokenomics distribution and controlled subsidies:
- One-time mint of treasury, subsidies, and ecosystem funds
- Admin-controlled top-ups with caps
- Timelock and vesting for large distributions
- Emergency pause for distribution controls
Manages EIP-712 based intent system for gasless operations:
- Intent registration with admin approval
- Secure execution of signed intents
- Nonce-based replay protection
- Support for reservation and provider actions
Manages lab providers, roles, and institutional treasuries:
- Add/remove providers and institutions
- Institutional treasury management for SAML users
- Role-based access control (admin, provider, institution)
- Automatic token grants for new providers
Implements ERC-721 for laboratory NFTs with additional features:
- Add/update/delete labs
- Set token URIs and metadata
- Paginated lab queries
- Provider-only transfer restrictions
- Staking requirements for listing labs
Sub-facets:
- LabAdminFacet: Admin operations for lab management (minting, burning)
- LabIntentFacet: Lab operations via intent system
- LabQueryFacet: Read-only queries for lab data
- LabReputationFacet: Reputation-based lab features
Implements provider staking mechanism for quality assurance:
- Token staking requirements for providers
- Slashing for misconduct with timelock recovery
- Unstaking with lock periods
- Reputation-based mechanisms
Handles the complete reservation lifecycle for labs:
- Reservation requests and admin confirmations
- Calendar conflict detection using interval trees
- Multi-state workflow (PENDING β CONFIRMED β IN_USE β COMPLETED β COLLECTED)
- Automatic refunds and batch fund collection
- Support for institutional and wallet reservations
Sub-facets:
- WalletReservationReleaseFacet: Releases expired reservations paid from user wallets
- WalletReservationCoreFacet: Core reservation request flow for wallet users
- WalletReservationConfirmationFacet: Confirms wallet reservation requests
- ReservationDenialFacet: Denies reservation requests (wallet + institutional)
- WalletReservationCancellationFacet: Cancellation logic for wallet reservations
- WalletPayoutFacet: Provider payout collection for wallet reservations
- InstitutionalReservationFacet: Releases expired institutional reservations
- InstitutionalReservationRequestFacet: Entry point for institutional reservation requests
- InstitutionalReservationRequestValidationFacet: Validates institutional reservation requests
- InstitutionalReservationRequestCreationFacet: Creates institutional reservation records
- InstitutionalReservationConfirmationFacet: Confirms institutional reservation requests
- InstitutionalReservationCancellationFacet: Cancellation logic for institutional reservations
- InstitutionalReservationQueryFacet: Read-only queries for institutional reservations
- InstitutionalTreasuryFacet: Institutional treasury balances and transfers
- InstitutionalOrgRegistryFacet: Institutional organization registry
- InstitutionFacet: Institution role and organization management
- ReservationIntentFacet: Intent-based institutional reservation actions
- ReservationCheckInFacet: Check-in functionality for completed reservations
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.
Manages institutional organizations and SAML-based user associations.
Handles EIP-712 intent validation and execution logic.
Implements provider reputation system with check-in rewards and penalties.
Manages revenue sharing and distribution calculations.
Provides tracking and analytics for reservations and usage.
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
struct ProviderBase {
string name;
string email;
string country;
string authURI;
}
struct Provider {
address account;
ProviderBase base;
}struct LabBase {
string uri;
uint96 price;
string accessURI;
string accessKey;
uint32 createdAt;
}
struct Lab {
uint labId;
LabBase base;
}struct Reservation {
uint256 labId;
address renter;
uint96 price;
address labProvider;
uint8 status; // 0=PENDING, 1=CONFIRMED, 2=IN_USE, 3=COMPLETED, 4=COLLECTED, 5=CANCELLED
uint32 start;
uint32 end;
string puc; // schacPersonalUniqueCode for institutional
uint64 requestPeriodStart;
uint64 requestPeriodDuration;
address payerInstitution;
address collectorInstitution;
uint96 providerShare;
uint96 projectTreasuryShare;
uint96 subsidiesShare;
uint96 governanceShare;
}struct PendingSlash {
uint256 amount;
uint256 executeAfter;
string reason;
}struct IntentMeta {
bytes32 requestId;
address signer;
address executor;
uint8 action;
bytes32 payloadHash;
uint256 nonce;
uint64 requestedAt;
uint64 expiresAt;
IntentState state;
}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)
- Luis de la Torre - ldelatorre@dia.uned.es
- Juan Luis Ramos VillalΓ³n - juanluis@melilla.uned.es
- 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