An open API service indexing awesome lists of open source software.

https://github.com/0xintuition/intuition-rs

Rust implementation of Intuition's off-chain back-end systems.
https://github.com/0xintuition/intuition-rs

Last synced: 8 months ago
JSON representation

Rust implementation of Intuition's off-chain back-end systems.

Awesome Lists containing this project

README

          

# Intuition Rust

[![Ask DeepWiki](https://deepwiki.com/badge.svg)](https://deepwiki.com/0xIntuition/intuition-rs)

A comprehensive Rust workspace for blockchain data indexing and processing, featuring a modular architecture with multiple specialized services.

## ๐Ÿ—๏ธ Architecture

This workspace contains the following core services:

### Core Services
- **`apps/cli`** - Terminal UI client for interacting with the Intuition system
- **`apps/consumer`** - Event processing pipeline using Redis Streams (RAW, DECODED, and RESOLVER consumers)
- **`apps/models`** - Domain models and data structures for the Intuition system

### Infrastructure Services
- **`infrastructure/hasura`** - GraphQL API with database migrations and configuration
- **`apps/image-guard`** - Image processing and validation service
- **`apps/rpc-proxy`** - RPC call proxy with caching for `eth_call` methods

### Supporting Services
- **`apps/histocrawler`** - Historical data crawler
- **`apps/shared-utils`** - Common utilities and shared code
- **`infrastructure/migration-scripts`** - Database migration utilities

## ๐Ÿš€ Quick Start

### Prerequisites

1. **Install Rust toolchain**
```bash
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh
```

2. **Install required tools**
```bash
# Install cargo-make for build automation
cargo install --force cargo-make

# Install Hasura CLI
curl -L https://github.com/hasura/graphql-engine/raw/stable/cli/get.sh | bash
```

3. **Install Node.js dependencies** (for integration tests)
```bash
cd integration-tests
pnpm install
```

### Environment Setup

1. **Copy environment template**
```bash
cp .env.sample .env
```

2. **Configure required environment variables**

| Variable | Description | Source |
|----------|-------------|---------|
| `OPENAI_API_KEY` | OpenAI API key for AI features | [OpenAI Platform](https://platform.openai.com/api-keys) |
| `PINATA_GATEWAY_TOKEN` | Pinata gateway token for IPFS | [Pinata Dashboard](https://app.pinata.cloud/developers/gateway-settings) |
| `PINATA_API_JWT` | Pinata API JWT for IPFS uploads | [Pinata Dashboard](https://app.pinata.cloud/developers/api-keys) |
| `RPC_URL_MAINNET` | Ethereum mainnet RPC endpoint | [Alchemy Dashboard](https://dashboard.alchemy.com/) |
| `RPC_URL_BASE` | Base network RPC endpoint | [Alchemy Dashboard](https://dashboard.alchemy.com/apps) |
| `RPC_URL_LINEA` | Linea network RPC endpoint | [Alchemy Dashboard](https://dashboard.alchemy.com/apps) |

## ๐Ÿƒโ€โ™‚๏ธ Running the System

**Note**: All scripts are located in the `scripts/` directory and should be run from the project root.

### Option 1: Using Published Docker Images (Recommended)

```bash

# Start with local Ethereum node
cargo make start-local
```

### Option 2: Building from Source

```bash
# Build all Docker images from source
cargo make build-docker-images

# Start the system
cargo make start-local
```

### Option 3: Running with Integration Tests

```bash
# Start with tests enabled
cargo make start-local test
```

## ๐Ÿงช Testing

### Run All Tests
```bash
cargo nextest run
```

### Run Integration Tests
```bash
cd integration-tests
export VITE_INTUITION_CONTRACT_ADDRESS=0x....
pnpm test src/follow.test.ts
```

### Run Specific Test Suites
```bash
# Test account operations
pnpm test src/create-person.test.ts

# Test vault operations
pnpm test src/vaults.test.ts

# Test AI agents
pnpm test src/ai-agents.test.ts
```

## ๐Ÿ› ๏ธ Development

### CLI Tool
```bash
# Run the CLI to verify latest data
./scripts/cli.sh
```

### Code Quality
```bash
# Format code
cargo make fmt

# Run linter
cargo make clippy

# Run all checks
cargo make check
```

### Database Operations
```bash
# Start services and run migrations
cargo make start-docker-and-migrate

# Manual migration (if needed)
cp .env.sample .env
source .env
```

## ๐Ÿ”ง Local Development Setup

### Using Local Ethereum Node

Add to your `.env` file:
```bash
INTUITION_CONTRACT_ADDRESS=0x04056c43d0498b22f7a0c60d4c3584fb5fa881cc
START_BLOCK=0
```

Create local test data:
```bash
cd integration-tests
npm install
npm run create-predicates
```

### Manual Service Management

```bash
# Start all services
docker-compose -f docker/docker-compose-apps.yml up -d

# Stop all services
./scripts/stop.sh

# View logs
docker-compose -f docker/docker-compose-apps.yml logs -f
```

### Logging and Monitoring

**JSON Logging:**
All consumer services output structured JSON logs with the following fields:
- `timestamp`: ISO 8601 timestamp
- `level`: Log level (INFO, WARN, ERROR, DEBUG)
- `fields.message`: Log message content
- `target`: Module path
- `filename`: Source file name
- `line_number`: Line number in source file
- `threadId`: Thread identifier

**Viewing Logs:**
```bash
# View container logs directly
docker logs decoded_consumer | grep '"level":"INFO"'
docker logs resolver_consumer | grep '"level":"ERROR"'
docker logs ipfs_upload_consumer | grep '"level":"WARN"'
```

## ๐Ÿ“ Project Structure

```
intuition-rs/
โ”œโ”€โ”€ apps/ # Custom Rust applications
โ”‚ โ”œโ”€โ”€ cli/ # Terminal UI client
โ”‚ โ”œโ”€โ”€ consumer/ # Event processing pipeline (Redis Streams)
โ”‚ โ”œโ”€โ”€ histocrawler/ # Historical data crawler
โ”‚ โ”œโ”€โ”€ image-guard/ # Image processing service
โ”‚ โ”œโ”€โ”€ models/ # Domain models & data structures
โ”‚ โ”œโ”€โ”€ rpc-proxy/ # RPC proxy with caching
โ”‚ โ””โ”€โ”€ shared-utils/ # Common utilities
โ”œโ”€โ”€ infrastructure/ # Infrastructure components
โ”‚ โ”œโ”€โ”€ hasura/ # GraphQL API & migrations
โ”‚ โ”œโ”€โ”€ blockscout/ # Blockchain explorer
โ”‚ โ”œโ”€โ”€ drizzle/ # Database schema management
โ”‚ โ”œโ”€โ”€ geth/ # Local Ethereum node config
โ”‚ โ”œโ”€โ”€ indexer-and-cache-migrations/ # Database migrations
โ”‚ โ”œโ”€โ”€ migration-scripts/ # Migration utilities
โ”‚ โ””โ”€โ”€ prometheus/ # Monitoring configuration
โ”œโ”€โ”€ docker/ # Docker configuration
โ”‚ โ”œโ”€โ”€ docker-compose-apps.yml # Application services
โ”‚ โ”œโ”€โ”€ docker-compose-shared.yml # Shared infrastructure
โ”‚ โ””โ”€โ”€ Dockerfile # Multi-stage build
โ”œโ”€โ”€ scripts/ # Shell scripts
โ”‚ โ”œโ”€โ”€ start.sh # System startup
โ”‚ โ”œโ”€โ”€ stop.sh # System shutdown
โ”‚ โ”œโ”€โ”€ cli.sh # CLI runner
โ”‚ โ”œโ”€โ”€ init-dbs.sh # Database initialization
โ”œโ”€โ”€ integration-tests/ # End-to-end tests
โ””โ”€โ”€ README.md # This file
```

## ๐Ÿ”„ Event Processing Pipeline

The system processes blockchain events through multiple stages:

1. **RAW** - Raw event ingestion from blockchain
2. **DECODED** - Event decoding and parsing
3. **RESOLVER** - Data resolution and enrichment

### Supported Contract Versions
- EthMultiVault v1.0
- EthMultiVault v1.5
- Multivault v2.0

## ๐Ÿšจ Known Issues

- **Base Events Indexing**: To index Base events, uncomment `substreams-sink` and comment `envio-indexer` in `docker-compose.yml`. The optimal process is under investigation.

## ๐Ÿ“Š Monitoring and Observability

### Logging

The system includes comprehensive logging capabilities:

**Features:**
- **Structured JSON Logging**: All services output machine-readable logs
- **Container Logs**: Direct access to service logs via Docker
- **Log Filtering**: Easy filtering by log level and service

**Benefits:**
- **Debugging**: Quickly find and analyze issues across services
- **Performance Monitoring**: Track service performance and bottlenecks
- **Audit Trail**: Complete visibility into system operations

**Getting Started:**
1. Start the system: `cargo make start-local`
2. View logs: `docker logs `
3. Filter logs: `docker logs | grep '"level":"INFO"'`

## ๐Ÿ“š Additional Resources

- [Hasura Documentation](https://hasura.io/docs/)
- [Alchemy Dashboard](https://dashboard.alchemy.com/)
- [Pinata Documentation](https://docs.pinata.cloud/)

## ๐Ÿ“„ License

See [LICENSE](LICENSE) file for details.

---

**Note**: This project is under active development. Code and APIs are subject to change.