Documentation

AssemblyScript API Reference

Available types in the Wasm sandbox environment:

• Transaction — full Solana transaction with signature, slot, blockTime, instructions
• Instruction — programId, accounts, data (Uint8Array)
• decode<T>(data) — Borsh deserialization into typed struct
• base58Encode(bytes) / base58Decode(str) — Base58 utilities
• console.log(msg) — Output appears in worker logs

Example:
  const swap = decode<SwapEvent>(ix.data);
  console.log("Amount: " + swap.inAmount.toString());

Architecture: Batching & Backpressure

SolIndexer uses a Rust-powered worker pipeline:

1. gRPC Stream — connects to Solana RPC for real-time blocks
2. Batch Decoder — groups transactions into configurable batches (default: 50)
3. Wasm Runtime — executes your AssemblyScript transform per transaction
4. PostgreSQL Writer — bulk INSERTs with configurable batch size

Backpressure system:
• If DB inserts fall behind, the worker reduces batch intake rate
• Metrics exposed: queue depth, insertion latency, transform latency
• OOM protection: Wasm memory capped at 64MB per transform call
• Worker auto-restarts with exponential backoff on crash

Troubleshooting

Common issues and solutions:

BYODB Connection Errors:
• "Connection refused" — check your PostgreSQL host/port is externally accessible
• "SSRF blocked" — localhost, 127.0.0.1, and private IPs are blocked for security
• "SSL required" — add ?sslmode=require to your connection string

Out of Memory (OOM):
• Wasm memory limit is 64MB — avoid large array allocations in transforms
• Use streaming decode for large instruction data
• Check for memory leaks in loops

Transform Errors:
• "decode failed" — ensure your struct matches the on-chain Borsh schema
• "null returned" — transform returned null, transaction skipped (this is OK)
• Check worker logs for console.log output from your AssemblyScript