A Solana-based DeFi system that implements a tax-and-reward mechanism for SPL token trades. The system automatically taxes token swaps, converts collected tokens to SOL via DEX integration, and redistributes rewards to token holders proportionally. It is a side project I work on at leisure time and still under development.
- ** Automated Tax Collection**: Configurable tax rates (0-100%) on token swaps
- ** SOL Reward Distribution**: Collected tokens are swapped to SOL and distributed to holders
- ** Multi-DEX Integration**: Primary Jupiter support with Serum fallback
- ** Real-time Reward Accounting**: Cumulative reward per token algorithm (scaled by 1e18)
- ** Security First**: Comprehensive overflow protection and pause mechanisms
- ** Production Ready**: Full CI/CD, monitoring, and operational runbooks
┌─────────────────┐ ┌─────────────────┐ ┌─────────────────┐
│ Web dApp │ │ Batch Service │ │ Solana Program │
│ (Next.js) │◄──►│ (Node.js) │◄──►│ (Anchor) │
│ │ │ │ │ │
│ • User Interface│ │ • Automation │ │ • Tax Logic │
│ • Wallet Connect│ │ • Monitoring │ │ • Reward Dist. │
│ • Transaction │ │ • Batch Ops │ │ • DEX Integration│
└─────────────────┘ └─────────────────┘ └─────────────────┘
│
▼
┌─────────────────┐
│ DEX Protocols │
│ │
│ • Jupiter (1°) │
│ • Serum (2°) │
└─────────────────┘
solana-tax-reward/
├── programs/tax_reward/ # Anchor Solana program
│ ├── src/
│ │ ├── lib.rs # Main program logic
│ │ ├── state.rs # Account structures
│ │ ├── instructions.rs # Context definitions
│ │ ├── swap.rs # DEX integration
│ │ └── error.rs # Custom errors
│ ├── tests/ # Program tests
│ ├── Cargo.toml # Dependencies
│ └── Anchor.toml # Anchor config
│
├── clients/
│ ├── dapp/ # Next.js 15 + React 19 frontend
│ │ ├── src/app/ # App Router structure
│ │ ├── src/lib/ # Utilities & hooks
│ │ ├── cypress/ # E2E tests
│ │ └── package.json # Dependencies
│ └── batch-service/ # Node.js automation service
│ ├── src/index.js # Express server
│ ├── tests/ # Service tests
│ └── package.json # Dependencies
│
├── scripts/
│ ├── deploy/deploy.sh # Deployment automation
│ ├── maintenance/monitoring.sh # Health checks
│ └── benchmark/compute_bench.sh # Performance testing
│
├── tests/ # Integration test suites
│ ├── anchor_tests.rs # Anchor program tests
│ ├── e2e_tests.rs # End-to-end scenarios
│ ├── property_tests.rs # Property-based testing
│ └── integration_tests.rs # Cross-component tests
│
├── docs/
│ ├── ARCHITECTURE.md # System design
│ ├── OPERATIONAL_RUNBOOK.md # Deployment guide
│ ├── SECURITY.md # Security practices
│ ├── TESTING_FRAMEWORK.md # Testing strategy
│ └── monitoring/ # Prometheus config
│
├── .github/workflows/ # CI/CD pipelines
│ ├── ci.yml # Continuous integration
│ └── deploy.yml # Deployment workflow
│
└── Configuration files
├── Anchor.toml # Workspace config
├── Cargo.toml # Rust workspace
├── CHANGELOG.md # Version history
└── CONTRIBUTING.md # Contribution guide
- Rust 1.70+ with
cargo - Solana CLI 1.14.17+
- Anchor Framework 0.27.0+
- Node.js 18+ with
npm - Git for version control
git clone https://github.com/your-username/solana-tax-reward.git
cd solana-tax-reward
# Verify Rust installation
rustc --version
solana --version
anchor --versioncd programs/tax_reward
# Install dependencies and build
cargo check # Verify compilation
anchor build # Build the program
anchor test --skip-deploy # Run unit tests# Start local validator
solana-test-validator
# Deploy program
anchor deploy --provider.cluster localnet
# Run integration tests
anchor testcd clients/dapp
npm install # Install dependencies
npm run dev # Start development server
# Visit http://localhost:3000cd clients/batch-service
npm install # Install dependencies
npm start # Start the service
# Service runs on http://localhost:3001# Unit tests
cargo test --manifest-path programs/tax_reward/Cargo.toml
# Property-based tests
cargo test --manifest-path programs/tax_reward/Cargo.toml -- --ignored
# Anchor integration tests
anchor test --skip-deploy# dApp tests
cd clients/dapp
npm test # Unit tests
npm run e2e:test # Cypress E2E tests
# Batch service tests
cd clients/batch-service
npm test # Jest tests
npm run e2e:test # Integration tests# Run everything (mimics CI pipeline)
cargo fmt --manifest-path programs/tax_reward/Cargo.toml -- --check
cargo clippy --manifest-path programs/tax_reward/Cargo.toml --all -- -D warnings
anchor test --skip-deploy
cargo test --manifest-path programs/tax_reward/Cargo.toml -- --ignoredanchor build # Build program
anchor deploy # Deploy to configured cluster
anchor test # Run all tests
anchor clean # Clean build artifactscargo fmt # Format Rust code
cargo clippy # Lint Rust code
npm run lint # Lint TypeScript/JavaScript
npm run format # Format client code# Deploy to devnet
./scripts/deploy/deploy.sh devnet ~/.config/solana/id.json
# Deploy to mainnet (requires multisig)
./scripts/deploy/deploy.sh mainnet ~/.config/solana/mainnet-key.json- Health Checks:
./scripts/maintenance/monitoring.sh - Metrics: Prometheus metrics at
/api/metrics - Performance:
./scripts/benchmark/compute_bench.sh - Logs: Centralized logging via Winston/Pino
See OPERATIONAL_RUNBOOK.md for detailed procedures.
- Math Safety: All arithmetic operations use checked math
- Access Control: PDA-based authority validation
- Emergency Stop: Program pause functionality
- Audit Trail: Comprehensive event logging
See SECURITY.md for security practices and reporting.
We welcome contributions! Please see CONTRIBUTING.md for:
- Development setup
- Code style guidelines
- Testing requirements
- Pull request process
- Architecture Guide - System design and components
- Operational Runbook - Deployment and maintenance
- Testing Framework - Testing strategy and tools
- API Documentation - Program instructions and client APIs
- Core Program: Functional and tested
- DEX Integration: Jupiter + Serum support
- Web dApp: Next.js 15 with full functionality
- Batch Service: Automated operations
- CI/CD: GitHub Actions pipeline
- Monitoring: Prometheus + Grafana ready
- Mainnet Deployment: In preparation