Metadata-Version: 2.4
Name: aicoin
Version: 0.3.1
Summary: AICoin - Decentralized AI computing network where nodes mine AIC tokens by contributing GPU/CPU compute power to run AI inference
Author-email: AICoin Team <aicoin@proton.me>
License: MIT
Project-URL: Homepage, https://github.com/ctz168/aicoin
Project-URL: Repository, https://github.com/ctz168/aicoin
Project-URL: Documentation, https://github.com/ctz168/aicoin#readme
Project-URL: Bug Tracker, https://github.com/ctz168/aicoin/issues
Project-URL: PyPI, https://pypi.org/project/aicoin/
Keywords: aicoin,blockchain,cryptocurrency,mining,ai,decentralized,compute,inference,erc20,web3,gpu-mining,distributed-computing,governance,dao
Classifier: Development Status :: 3 - Alpha
Classifier: Intended Audience :: Developers
Classifier: License :: OSI Approved :: MIT License
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3.10
Classifier: Programming Language :: Python :: 3.11
Classifier: Programming Language :: Python :: 3.12
Classifier: Topic :: Software Development :: Libraries :: Python Modules
Classifier: Topic :: System :: Distributed Computing
Classifier: Topic :: Scientific/Engineering :: Artificial Intelligence
Classifier: Framework :: AsyncIO
Classifier: Typing :: Typed
Requires-Python: >=3.10
Description-Content-Type: text/markdown
License-File: LICENSE
Requires-Dist: aiohttp>=3.9.0
Requires-Dist: ecdsa>=0.18.0
Requires-Dist: pycryptodome>=3.19.0
Requires-Dist: psutil>=5.9.0
Requires-Dist: pydantic>=2.5.0
Requires-Dist: python-dotenv>=1.0.0
Provides-Extra: inference
Requires-Dist: torch>=2.0.0; extra == "inference"
Requires-Dist: transformers>=4.36.0; extra == "inference"
Requires-Dist: accelerate>=0.25.0; extra == "inference"
Requires-Dist: sentencepiece>=0.1.99; extra == "inference"
Requires-Dist: safetensors>=0.4.0; extra == "inference"
Provides-Extra: web3
Requires-Dist: web3>=6.15.0; extra == "web3"
Provides-Extra: perf
Requires-Dist: uvloop>=0.19.0; extra == "perf"
Requires-Dist: numpy>=1.24.0; extra == "perf"
Provides-Extra: rust
Requires-Dist: maturin>=1.3.0; extra == "rust"
Provides-Extra: gpu
Requires-Dist: nvidia-ml-py3>=7.352.0; extra == "gpu"
Provides-Extra: all
Requires-Dist: aicoin[gpu,inference,perf,web3]; extra == "all"
Provides-Extra: dev
Requires-Dist: pytest>=7.0; extra == "dev"
Requires-Dist: pytest-asyncio>=0.21; extra == "dev"
Requires-Dist: black>=23.0; extra == "dev"
Requires-Dist: ruff>=0.1; extra == "dev"
Requires-Dist: mypy>=1.0; extra == "dev"
Dynamic: license-file

# AICoin - Decentralized AI Computing Network

<p align="center">
  <strong>Train the future, mine the intelligence.</strong>
</p>

AICoin is a decentralized AI computing network where nodes earn AIC tokens by contributing GPU/CPU compute power to run AI inference tasks. Built with Python and Solidity, it combines blockchain mining economics with distributed AI model serving.

## Key Features

- **Proof-of-Compute Mining**: Nodes mine AIC by running AI model inference (not hash puzzles). Rewards scale with actual compute contribution — GPU hours, token throughput, and task completion rate.
- **Bitcoin-Style Tokenomics**: Fixed 21,000,000 AIC max supply. Initial block reward is 50 AIC, halving every 210,000 blocks (~1 year). 50% pre-allocated to genesis wallet, 50% released through mining.
- **Built-in Crypto Wallet**: BIP39 mnemonic generation, HD key derivation (BIP44 `m/44'/60'/0'/0/0`), secp256k1 ECDSA signing, and encrypted local storage. Compatible with Ethereum addresses.
- **On-Chain Governance**: Token-weighted voting (1 AIC = 1 vote). Proposals for model selection, parameter changes, emergency actions, and protocol upgrades. 51% approval threshold with 10% quorum.
- **Dual-Mode Blockchain**: Simulation mode (in-memory, for development) and Web3 mode (connect to EVM-compatible chains for production). All simulation logic strictly mirrors Solidity contracts.
- **Distributed Inference**: Pipeline-parallel model serving across nodes. Supports Qwen2.5, Llama-3, and other transformer models with automatic sharding and load balancing.
- **API Gateway**: RESTful API for AI inference with tiered pricing (Basic / Standard / Premium). Revenue shared 80/20 between compute nodes and treasury.
- **CPU & GPU Support**: CPU-only nodes can also mine with a fair power coefficient. No GPU required to participate.

## Architecture

```
┌──────────────────────────────────────────────────────────┐
│                      AICoin Node                         │
├──────────┬──────────┬───────────┬──────────┬─────────────┤
│  Wallet  │ Mining   │ Blockchain│Governance│ API Gateway │
│ (BIP39)  │ Engine   │ Manager   │ Manager  │ (REST)      │
├──────────┴──────────┴───────────┴──────────┴─────────────┤
│              Distributed Inference Engine                 │
│         (Pipeline Parallelism + Model Sharding)           │
├──────────────────────────────────────────────────────────┤
│              P2P Network (TCP + Gossip)                   │
│              Raft Consensus + Routing                     │
└──────────────────────────────────────────────────────────┘
```

## Token Economics

| Parameter | Value |
|-----------|-------|
| Token Symbol | AIC |
| Max Supply | 21,000,000 AIC |
| Decimals | 18 (ERC20 compatible) |
| Genesis Allocation | 10,500,000 AIC (50%) |
| Mining Reserve | 10,500,000 AIC (50%) |
| Initial Block Reward | 50 AIC |
| Halving Interval | 210,000 blocks (~1 year) |
| Mining Reward Split | 80% node / 20% treasury |

### Supply Schedule

```
Year 1:  50 AIC/block  → ~10,500,000 AIC mined
Year 2:  25 AIC/block  → ~5,250,000 AIC mined
Year 3:  12.5 AIC/block → ~2,625,000 AIC mined
...continues halving until max supply reached
```

## Quick Start

### Installation

```bash
# Basic installation
pip install aicoin

# With Web3 support (for production chains)
pip install aicoin[web3]

# With AI inference support (requires GPU)
pip install aicoin[inference]

# Everything
pip install aicoin[all]
```

### Create a Wallet

```python
from core.wallet import AICoinWallet

wallet = AICoinWallet("my_wallet.dat")
result = wallet.create_new("my_secure_password_123")

print(f"Mnemonic: {result['mnemonic']}")
print(f"Address:  {result['address']}")
# ⚠️ Write down your mnemonic! It can recover your wallet.
```

### Start a Node

```python
from core.node import AICoinNode
from core.config import AICoinConfig

config = AICoinConfig.from_file("config.json")
node = AICoinNode(config)
node.start()

# Run AI inference
result = node.run_inference("Explain quantum computing", max_tokens=256)
print(result["response"])

# Stop
node.stop()
```

### Blockchain Operations (Simulation Mode)

```python
from core.blockchain import BlockchainManager

# Initialize with genesis wallet pre-allocation
bm = BlockchainManager({"mode": "simulation"})

# Check genesis wallet
info = bm.get_genesis_wallet_info()
print(f"Genesis balance: {info['balance_aic']:,.0f} AIC")

# Transfer from genesis wallet
bm.genesis_transfer("0xRecipient...", 1000 * 10**18)

# Mining reward
bm.mint_mining_reward("0xMiner1", 50 * 10**18)

# Burn tokens
bm.burn_tokens("0xMiner1", 10 * 10**18)

# Governance
proposal_id = bm.create_proposal(
    proposer="0xMiner1",
    proposal_type="ParameterChange",
    title="Reduce API pricing",
    description="Lower the API access cost to attract more users"
)
bm.vote("0xMiner1", proposal_id, support=True)
```

### Web3 Mode (Production)

```python
bm = BlockchainManager({
    "mode": "web3",
    "rpc_url": "https://mainnet.infura.io/v3/YOUR_KEY",
    "token_address": "0x...",
    "mining_address": "0x...",
    "governance_address": "0x...",
    "chain_id": 1,
    "genesis_private_key": "0x...",  # For genesis transfers
})
```

## Smart Contracts

The `contracts/` directory contains Solidity source code for deployment on EVM-compatible chains:

| Contract | Description |
|----------|-------------|
| `AICoinToken.sol` | ERC20 token with mining minting, burning, voting weight, and role-based access control |
| `Mining.sol` | Compute proof submission, reward calculation, halving logic |
| `Governance.sol` | Proposal creation, token-weighted voting, execution |
| `APIAccess.sol` | Tiered API access with AIC payment and daily quotas |
| `AICoinDAO.sol` | DAO integration with proposal execution callbacks |

Deploy with Hardhat:

```bash
cd deploy/hardhat
npm install
npx hardhat run scripts/deploy.js --network mainnet
```

## Compute Scoring

Mining rewards are proportional to each node's compute score (0–10,000), calculated from four dimensions:

| Dimension | Weight | Metric |
|-----------|--------|--------|
| Compute Utilization | 30% | GPU VRAM usage or CPU inference time |
| Throughput | 30% | Tokens/second (model-adjusted) |
| Uptime | 20% | Node online duration (log-scaled, 30-day cap) |
| Completion Rate | 20% | Successful inference tasks / total tasks in 24h |

CPU nodes receive a fair power coefficient (default 0.3x) so they earn meaningful rewards even without GPU.

## Governance

Token holders govern the network through proposals and voting:

- **1 AIC = 1 Vote** — voting power equals token balance
- **Quorum**: 10% of total supply must participate
- **Approval**: 51%+ of cast votes required to pass
- **Standard voting period**: 7 days
- **Emergency voting period**: 24 hours
- **Proposal types**: Model selection, model addition/removal, parameter changes, emergency actions, protocol upgrades
- **Minimum stake**: 1,000 AIC required to create a proposal

## Project Structure

```
aicoin/
├── core/
│   ├── blockchain.py      # Blockchain manager (simulation + Web3)
│   ├── wallet.py          # BIP39/HD wallet with ECDSA signing
│   ├── mining_engine.py   # Compute meter + mining engine + reward distributor
│   ├── governance.py      # Governance manager + model registry + proposal executor
│   ├── node.py            # Full node (P2P + mining + API + governance)
│   ├── api_gateway.py     # REST API gateway
│   ├── config.py          # Configuration management
│   ├── router.py          # Intelligent request routing
│   ├── consensus.py       # Finality consensus mechanism
│   ├── async_blockchain.py # Async I/O path (asyncio + uvloop)
│   ├── dag_scheduler.py   # DAG-based parallel transaction scheduler
│   ├── worker_pool.py     # Multi-process worker pool (GIL bypass)
│   ├── hybrid_inference.py # Hybrid CPU/GPU inference engine
│   ├── rust_engine/       # Rust execution engine (PyO3 FFI)
│   └── distributed/       # Distributed inference modules
│       ├── distributed_node.py
│       ├── inference_coordinator.py
│       ├── model_manager.py
│       ├── raft_election.py
│       ├── network_manager.py
│       ├── sharded_model.py
│       ├── load_balancer.py
│       └── resource_monitor.py
├── contracts/             # Solidity smart contracts
├── deploy/                # Deployment tools (Hardhat + Python)
└── tests/                 # Test suite
```

## Requirements

- Python >= 3.10
- `ecdsa` >= 0.18.0 (secp256k1 signing)
- `aiohttp` >= 3.9.0 (API gateway)
- `pydantic` >= 2.5.0 (data validation)
- `psutil` >= 5.9.0 (system monitoring)

### Optional

- `torch` + `transformers` (AI model inference)
- `web3` (production blockchain connection)
- `uvloop` + `numpy` (performance optimization)

## License

MIT License

## Links

- **PyPI**: https://pypi.org/project/aicoin/
- **GitHub**: https://github.com/ctz168/aicoin
