A distributed reward system service designed to calculate and distribute rewards among operators' hotspots (WUBI/WUPI) based on device scores and multipliers. This server integrates with external APIs for score calculation and uses Solana blockchain for reward distribution.
- Overview
- Features
- Architecture
- Prerequisites
- Installation
- Configuration
- Usage
- Project Structure
- API Integration
- Docker Deployment
- Kubernetes Deployment
- Development
- Contributing
- License
Reward Server is a TypeScript-based microservice that:
- Calculates rewards based on device scores and multipliers
- Distributes rewards via Solana blockchain (mainnet/devnet)
- Processes scores from external APIs:
- NAS API for WUPI devices
- WiFi API for WUBI devices
- Manages reward pools and epochs
- Handles asynchronous processing via RabbitMQ message queues
- Automates reward cycles using cron jobs
- π Koa.js web framework for HTTP server
- π PostgreSQL database for data persistence
- π° RabbitMQ integration for asynchronous message processing
- βοΈ Solana blockchain integration for reward distribution
- π Automated cron jobs for reward processing
- π― Rate limiting for API requests
- π Network score calculation for reward distribution
- π Error handling and recovery mechanisms
- π³ Docker support for containerized deployment
- βΈοΈ Kubernetes manifests for orchestration
The server follows a modular architecture:
βββββββββββββββββββ
β HTTP Server β (Koa.js)
ββββββββββ¬βββββββββ
β
ββββββ΄βββββ
β β
βββββΌββββ ββββΌβββββ
βRabbitMQβ βPostgreSQLβ
βββββ¬ββββ βββββ¬βββββ
β β
βββββΌββββββββββΌββββ
β Reward Engine β
β - Score Calc β
β - Pool Mgmt β
β - Epoch Proc β
βββββ¬ββββββββββββββ
β
βββββΌβββββ
β Solana β
βBlockchainβ
ββββββββββ
- Rewards Per Epoch: Processes and distributes rewards for each epoch
- Pool Per Epoch: Manages reward pools and network score calculations
- RabbitMQ Consumers: Handles asynchronous message processing from WUBI/WUPI APIs
- Solana Services: Manages blockchain transactions for reward distribution
- Event Hub: Centralized event management system
- Cron Jobs: Automated reward processing and status updates
Before you begin, ensure you have the following installed:
- Node.js (v18 or higher)
- npm or yarn
- PostgreSQL (v12 or higher)
- RabbitMQ (v3.8 or higher)
- TypeScript (v5.4 or higher)
git clone <repository-url>
cd reward-servernpm install
# or
yarn installCopy the example environment file and configure it:
cp env.example.env .envEdit .env with your configuration (see Configuration section).
Ensure PostgreSQL is running and create the database:
createdb your_database_namenpm run buildKey environment variables to configure:
DATABASE_HOST=localhost
DATABASE_PORT=5432
DATABASE_NAME=your_database_name
DATABASE_USERNAME=your_username
DATABASE_PASSWORD=your_password
DATABASE_SSL=falseRABBIT_USER=your_rabbitmq_user
RABBIT_PASS=your_rabbitmq_password
RABBIT_HOST=your_rabbitmq_host:5672
RABBIT_RATE_LIMIT_PER_SECOND=40WUBI_API_QUEUE=wifi_api_queue
WUBI_API_QUEUE_RESPONSE=reward_server_local
WUPI_API_QUEUE=wupi_score_queue_local
WUPI_API_QUEUE_RESPONSE=reward_server_local_wupiSOLANA_ENV=devnet # or 'mainnet'
SOLANA_API_KEY=your_solana_api_key
SOLANA_API_URL=https://api.devnet.solana.com
SOLANA_PRIVATE_KEY=your_solana_private_keyNAS_API=http://nas-api
NAS_API_KEY=your_nas_api_keyPORT=1339
NODE_ENV=development
REWARDS_MODE=production # or 'test'
ENABLE_ERROR_SIMULATION=false
REWARDS_PERIOD=mainnet # or 'devnet'The server includes rate limiting for RabbitMQ consumers to prevent RPC errors. Configure it using:
RABBIT_RATE_LIMIT_PER_SECOND=40See README-RATE-LIMITER.md for detailed information.
Run the server in development mode with hot reload:
npm run devThe server will start on http://localhost:1339 (or your configured PORT).
- Build the project:
npm run build- Start the server:
npm startBuild and run with Docker:
# Build the image
docker build -t reward-server .
# Run the container
docker run -p 1339:80 --env-file .env reward-serverDeploy to Kubernetes using the provided manifests:
kubectl apply -f kubernetes/reward-server/
βββ src/
β βββ bootstrap/ # Service initialization
β βββ config/ # Configuration files
β βββ constants/ # Application constants
β βββ controllers/ # HTTP route controllers
β βββ crons/ # Cron job definitions
β βββ helpers/ # Utility helpers
β βββ interfaces/ # TypeScript interfaces
β βββ middlewares/ # Koa middlewares
β βββ services/ # Business logic services
β β βββ depin-stake-rewards/
β β βββ nfnodes/
β β βββ pool-per-epoch/
β β βββ rabbitmq-wrapper/
β β βββ rewards-per-epoch/
β β βββ solana/
β β βββ ...
β βββ utils/ # Utility functions
β βββ server.ts # Main server entry point
βββ dist/ # Compiled JavaScript output
βββ kubernetes/ # Kubernetes manifests
βββ Dockerfile # Docker configuration
βββ package.json # Dependencies and scripts
βββ tsconfig.json # TypeScript configuration
βββ env.example.env # Environment variables template
The server communicates with the WiFi API (WUBI) via RabbitMQ:
- Request Queue:
WUBI_API_QUEUE - Response Queue:
WUBI_API_QUEUE_RESPONSE
The API calculates scores for WUBI devices.
The server communicates with the NAS API (WUPI) via RabbitMQ:
- Request Queue:
WUPI_API_QUEUE - Response Queue:
WUPI_API_QUEUE_RESPONSE
The API calculates scores for WUPI devices.
- Server sends requests to WUBI/WUPI APIs via RabbitMQ
- APIs calculate device scores
- APIs send responses back via RabbitMQ
- Server processes responses and calculates rewards
- Rewards are distributed via Solana blockchain
docker build -t reward-server:latest .docker run -d \
--name reward-server \
-p 1339:80 \
--env-file .env \
reward-server:latestThe project includes Kubernetes manifests in the kubernetes/ directory. Deploy using:
kubectl apply -f kubernetes/prod/Ensure you have:
- ConfigMaps for configuration
- Secrets for sensitive data
- Persistent volumes for database (if needed)
npm run dev- Start development server with hot reloadnpm run build- Build TypeScript to JavaScriptnpm start- Start production server
The project uses TypeScript with strict type checking. Ensure your code follows the existing patterns and interfaces.
- Create interfaces in
src/interfaces/ - Implement services in
src/services/ - Add routes in
src/controllers/(if needed) - Update bootstrap if new services need initialization
This project is now open source and welcomes contributions from the community. Since WAYRU no longer exists and cannot provide support, contributions are essential for maintaining and improving this project.
- Fork the repository
- Create a feature branch (
git checkout -b feature/amazing-feature) - Commit your changes (
git commit -m 'Add some amazing feature') - Push to the branch (
git push origin feature/amazing-feature) - Open a Pull Request
Please report bugs and request features through GitHub Issues. Note that there is no official support from WAYRU, but the community can help.
This project is open source and available under the ISC License.
- Rate Limiter Documentation - Detailed information about rate limiting configuration
With gratitude and love, we say goodbye.
WAYRU is closing its doors, but we are leaving these repositories open and free for the community.
May they continue to inspire builders, dreamers, and innovators.
With love, WAYRU
Note: This project is open source. Wayru, Inc and The Wayru Foundation are no longer operating entities, and will not provide any kind of support. The community is welcome to use, modify, and improve this codebase.