Skip to content

Frhnmj2004/lambda_contracts

Repository files navigation

Lamda Network - Hybrid-Chain Smart Contracts

This repository contains the smart contracts for the Lamda Network's hybrid-chain blockchain foundation. The system uses two distinct contracts deployed on different BNB Chain networks to handle specific responsibilities.

🏗️ Architecture Overview

Hybrid-Chain Strategy

The Lamda Network implements a hybrid-chain approach with two main contracts:

  1. NodeReputation.sol (opBNB Testnet)

    • Provider directory and reputation management
    • Optimized for frequent, low-cost updates
    • Handles provider registration, heartbeats, and job completion tracking
  2. JobManager.sol (BNB Smart Chain Testnet)

    • Escrow agent for job payments
    • Designed for security over cost
    • Manages job creation, confirmation, and payment distribution

📋 Prerequisites

  • Node.js (v16 or higher)
  • npm or yarn
  • A wallet with testnet BNB for deployment
  • API keys for contract verification (optional)

🚀 Quick Start

1. Install Dependencies

npm install

2. Environment Setup

Copy the example environment file and configure your settings:

cp env.example .env

Edit .env and add your configuration:

# Deployer wallet private key (without 0x prefix)
DEPLOYER_PRIVATE_KEY=your_private_key_here

# API Keys for contract verification (optional)
BSCSCAN_API_KEY=your_bscscan_api_key_here
OPBNBSCAN_API_KEY=your_opbnbscan_api_key_here

# Optional: Enable gas reporting
REPORT_GAS=true

3. Compile Contracts

npm run compile

4. Deploy Contracts

Deploy NodeReputation to opBNB Testnet

npm run deploy:reputation

Deploy JobManager to BNB Smart Chain Testnet

npm run deploy:manager

📄 Contract Documentation

NodeReputation Contract

Network: opBNB Testnet (Chain ID: 5611)
Purpose: Provider directory and reputation management

Key Functions

  • registerNode(string gpuModel, uint256 vram) - Register a new provider
  • sendHeartbeat() - Send periodic heartbeat to signal online status
  • incrementJobs(address provider) - Increment provider's job count (admin only)
  • getProviderInfo(address provider) - Get provider information
  • isProviderActive(address provider) - Check if provider is active

Events

  • NodeRegistered(address indexed provider, string gpuModel, uint256 vram)
  • NodeHeartbeat(address indexed provider, uint256 timestamp)
  • JobCountIncremented(address indexed provider, uint256 newCount)

JobManager Contract

Network: BNB Smart Chain Testnet (Chain ID: 97)
Purpose: Job escrow and payment management

Key Functions

  • createJob(bytes32 jobId, address providerAddress) - Create job and lock payment
  • confirmResult(bytes32 jobId) - Confirm job completion (renter only)
  • claimReward(bytes32 jobId) - Claim payment (provider only)
  • getJobInfo(bytes32 jobId) - Get detailed job information
  • getJobStatistics() - Get contract statistics

Events

  • JobCreated(bytes32 indexed jobId, address indexed renter, address indexed provider, uint256 payment)
  • JobConfirmed(bytes32 indexed jobId, uint256 confirmedAt)
  • PaymentClaimed(bytes32 indexed jobId, address indexed provider, uint256 amount)

🔧 Development

Testing

npm test

Gas Reporting

REPORT_GAS=true npm test

Contract Verification

After deployment, contracts are automatically verified on their respective block explorers:

🔒 Security Features

NodeReputation Contract

  • OpenZeppelin Ownable for admin controls
  • Input validation for registration parameters
  • Timestamp-based activity tracking

JobManager Contract

  • OpenZeppelin ReentrancyGuard for payment functions
  • Comprehensive access control
  • Double-spending prevention
  • Secure payment handling with low-level calls

🌐 Network Configuration

opBNB Testnet

BNB Smart Chain Testnet

📊 Integration with Backend Services

The contracts emit events that your off-chain backend services should monitor:

  1. Provider Registration: Monitor NodeRegistered events for new providers
  2. Provider Activity: Monitor NodeHeartbeat events for provider status
  3. Job Creation: Monitor JobCreated events for new job requests
  4. Job Completion: Monitor JobConfirmed events for completed jobs
  5. Payment Processing: Monitor PaymentClaimed events for payment confirmations

🚨 Important Notes

  1. Private Key Security: Never commit your .env file to version control
  2. Testnet Usage: These contracts are configured for testnet deployment
  3. Gas Optimization: The contracts are optimized for their respective networks
  4. Event Monitoring: Ensure your backend services properly handle all emitted events

📞 Support

For questions or issues related to the smart contracts, please refer to the Lamda Network documentation or contact the development team.

📄 License

This project is licensed under the MIT License - see the LICENSE file for details.

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published