An open-source extension of near-lake-framework-rs for sharded archival nodes with an AI query optimizer.
This repository is the working proof-of-concept submitted alongside the ShardLake Toolkit grant proposal to the NEAR Foundation.
From the NEAR Ecosystem 2025 Year in Review:
"Sharded archival nodes represent one of the most significant infrastructure improvements in 2025. By allowing archival operators to store and serve data for individual shards rather than the entire chain, NEAR dramatically reduces the hardware requirements for running archival infrastructure β making it feasible for a much broader set of participants to contribute to the network's data availability layer."
ShardLake Toolkit builds on this foundation by providing a developer-friendly Rust library that:
- Filters NEAR Lake streams by shard β only the shards you need ever touch your memory or disk.
- Pre-indexes data for AI-agent queries β bloom-filter + inverted-index engine that delivers 4β11Γ faster pattern matching than a vanilla full-scan.
- Ships a ready-to-use CLI for quick experimentation and benchmarking.
| Feature | Description |
|---|---|
| π§© Shard-filtered streaming | Stream only selected shards from NEAR Lake, cutting resource usage proportionally |
| π€ AI Query Optimizer | Pre-indexed search for method names (ft_transfer, nft_mint), event logs, and AI-agent intent patterns |
| β±οΈ Temporal queries | Restrict any query to a block-height window |
| π Regex support | ft_transfer|nft_mint β combine patterns in a single pass |
| π Built-in benchmarks | Every CLI run shows optimizer vs. vanilla speedup |
| π³ Docker image | One command to build and run |
git clone https://github.com/Fosurero/ShardLake-Toolkit.git
cd ShardLake-Toolkit
cargo build --releasecargo install --git https://github.com/Fosurero/ShardLake-Toolkit.git# Run the default demo: shards 0,3 β’ 1 000 blocks β’ query "intent"
cargo run -- run --network testnet --start-block 100000000 --shards 0,3 --query "intent" βββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
β π· ShardLake Toolkit v0.1.0 β
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
Network: testnet
Start Block: 100,000,000
Shards: [0, 3]
Query: "intent"
Mode: Demo (1,000 simulated blocks per shard)
β³ Generating demo data β¦ done (14.2ms)
β³ Building optimizer index β¦ done (11.8ms, 12,847 entries)
π Results
βββββββββββ¬βββββββββββββββββ¬βββββββββββ¬βββββββββββββββ
β Shard β Blocks β Matches β Query Time β
βββββββββββΌβββββββββββββββββΌβββββββββββΌβββββββββββββββ€
β 0 β 1,000 β 168 β 0.4ms β
β 3 β 1,000 β 152 β 0.4ms β
βββββββββββΌβββββββββββββββββΌβββββββββββΌβββββββββββββββ€
β Total β 2,000 β 320 β 0.8ms β
βββββββββββ΄βββββββββββββββββ΄βββββββββββ΄βββββββββββββββ
β‘ ShardLake Optimizer: 0.82ms (filtered 2 of 4 shards)
π Vanilla full scan: 3.91ms (all 4 shards, no index)
π Speedup: 4.8Γ faster
π Match breakdown:
intent 192 hits
event 88 hits
method 40 hits
π Sample matches (first 5):
Block 100,000,042 β Shard 0 β [intent] intent:swap NEAR->USDT amount=50
Block 100,000,107 β Shard 3 β [intent] intent:bridge ETH->NEAR
Block 100,000,218 β Shard 0 β [intent] intent:delegate stake=100
Block 100,000,319 β Shard 3 β [event] EVENT_JSON:{"standard":"nep141"...
Block 100,000,455 β Shard 0 β [intent] intent:query price_feed NEAR/USD
β
Complete. 320 events matched query "intent" across 2 shards in 42.1ms.
Indexed 2,000 blocks, 7,412 receipts, 10 unique methods.
# Token transfers only
cargo run -- run --query "ft_transfer" --num-blocks 5000
# Regex: transfers OR mints, all shards
cargo run -- run --query "ft_transfer|nft_mint" --shards 0,1,2,3
# Run the library examples
cargo run --example sharded_archival_streamer
cargo run --example ai_query_demoShardLake-Toolkit/
βββ Cargo.toml # Dependencies & build config
βββ src/
β βββ lib.rs # Core types & module re-exports
β βββ streamer.rs # Shard-filtered NEAR Lake streamer
β βββ optimizer.rs # AI query optimizer (index + bloom)
β βββ main.rs # CLI binary (clap)
βββ examples/
β βββ sharded_archival_streamer.rs # Streamer example
β βββ ai_query_demo.rs # Optimizer example
βββ benches/
β βββ optimizer_bench.rs # Criterion benchmarks
βββ docs/
β βββ usage.md # Detailed usage guide
βββ benchmarks/
β βββ results.md # Performance results
βββ .github/workflows/
β βββ ci.yml # GitHub Actions CI
βββ Dockerfile # Multi-stage Docker build
βββ milestones.md # M1 / M2 / M3 roadmap
βββ LICENSE # MIT
βββ README.md # β You are here
βββββββββββββββββββββββββββββββββββββββ
β NEAR Lake S3 Bucket β
β (testnet / mainnet block data) β
ββββββββββββββββ¬βββββββββββββββββββββββ
β
ββββββββββββββββΌβββββββββββββββββββββββ
β near-lake-framework-rs β
β (StreamerMessage per block) β
ββββββββββββββββ¬βββββββββββββββββββββββ
β
ββββββββββββββββββββββΌβββββββββββββββββββββββββ
β ShardLake Toolkit β
β β
β βββββββββββββββββββ ββββββββββββββββββββ β
β β ShardedStreamer β β QueryOptimizer β β
β β β β β β
β β β’ shard filter β β β’ inverted index β β
β β β’ config build β β β’ bloom filter β β
β β β’ demo gen β β β’ regex engine β β
β β β’ type convert β β β’ temporal query β β
β ββββββββββ¬βββββββββ ββββββββββ¬ββββββββββ β
β β β β
β ββββββββββ¬ββββββββββββ β
β β β
β βββββββββΌβββββββββ β
β β CLI / API β β
β β (shardlake) β β
β ββββββββββββββββββ β
βββββββββββββββββββββββββββββββββββββββββββββββ
cargo test # All tests
cargo test -- --nocapture # With stdout
cargo test optimizer # Only optimizer testscargo bench # Criterion benchmarksSee benchmarks/results.md for detailed numbers.
docker build -t shardlake-toolkit .
docker run --rm shardlake-toolkit
docker run --rm shardlake-toolkit run --query "ft_transfer" --num-blocks 2000| Milestone | Target | Status |
|---|---|---|
| M1 Core PoC | Feb 2026 | β Complete |
| M2 Live NEAR Lake integration | Mar 2026 | π² Planned |
| M3 Production & AI-agent SDK | AprβMay 2026 | π² Planned |
See milestones.md for full details.
This PoC accompanies the ShardLake Toolkit grant proposal submitted to the NEAR Foundation Infrastructure Committee.
π Proposal link: ShardLake Toolkit β NEAR Grant Proposal
Contributions are welcome! Please open an issue first to discuss what you'd like to change.
- Fork the repository
- Create a feature branch (
git checkout -b feature/amazing-thing) - Commit your changes (
git commit -m 'Add amazing thing') - Push to the branch (
git push origin feature/amazing-thing) - Open a Pull Request
MIT Β© 2026 ShardLake Contributors