|
| 1 | +# IDLHub Library |
| 2 | + |
| 3 | +This directory contains shared utilities and type definitions for IDLHub, following the aldrin-labs/openSVM model for compatibility. |
| 4 | + |
| 5 | +## Structure |
| 6 | + |
| 7 | +``` |
| 8 | +lib/ |
| 9 | +├── qdrant.js # Qdrant database utilities |
| 10 | +├── types/ # TypeScript type definitions |
| 11 | +│ ├── program.ts # Program and IDL types (openSVM compatible) |
| 12 | +│ └── index.ts # Type exports |
| 13 | +└── README.md # This file |
| 14 | +``` |
| 15 | + |
| 16 | +## Qdrant Integration |
| 17 | + |
| 18 | +### Collections |
| 19 | + |
| 20 | +IDLHub uses the same collection structure as aldrin-labs/openSVM: |
| 21 | + |
| 22 | +- **program_metadata** - Main collection storing programs with full IDL data |
| 23 | +- **token_metadata** - Token metadata (for future expansion) |
| 24 | +- **idl_cache** - Additional caching layer |
| 25 | + |
| 26 | +### ProgramMetadataEntry Model |
| 27 | + |
| 28 | +The core data model matches openSVM's `ProgramMetadataEntry`: |
| 29 | + |
| 30 | +```typescript |
| 31 | +interface ProgramMetadataEntry { |
| 32 | + id: string; // Program ID |
| 33 | + programId: string; // Same as id |
| 34 | + name: string; // Program name |
| 35 | + description?: string; // Program description |
| 36 | + githubUrl?: string; // GitHub repository URL |
| 37 | + websiteUrl?: string; // Official website |
| 38 | + docsUrl?: string; // Documentation URL |
| 39 | + category?: string; // Category (defi, nft, etc.) |
| 40 | + idl?: any; // Full IDL JSON object |
| 41 | + verified: boolean; // Verification status |
| 42 | + cached: boolean; // Cache status |
| 43 | + lastUpdated: number; // Timestamp |
| 44 | + cacheExpiry: number; // Cache expiration |
| 45 | + tags?: string[]; // Tags for search |
| 46 | +} |
| 47 | +``` |
| 48 | + |
| 49 | +### Key Features |
| 50 | + |
| 51 | +1. **IDL Storage** - IDLs are stored as part of program metadata in the `idl` field |
| 52 | +2. **Semantic Search** - Vector-based search for programs |
| 53 | +3. **Cache Management** - Automatic cache expiration and refresh |
| 54 | +4. **Batch Operations** - Efficient bulk storage and retrieval |
| 55 | +5. **openSVM Compatibility** - Uses identical data structures |
| 56 | + |
| 57 | +## Usage |
| 58 | + |
| 59 | +### Initialize Collections |
| 60 | + |
| 61 | +```javascript |
| 62 | +const qdrant = require('./lib/qdrant'); |
| 63 | + |
| 64 | +await qdrant.initializeCollections(); |
| 65 | +``` |
| 66 | + |
| 67 | +### Store Program Metadata |
| 68 | + |
| 69 | +```javascript |
| 70 | +const protocol = { |
| 71 | + id: 'jupiter', |
| 72 | + name: 'Jupiter', |
| 73 | + description: 'Jupiter Aggregator', |
| 74 | + category: 'dex-aggregator', |
| 75 | + idlPath: 'IDLs/jupiterIDL.json', |
| 76 | + status: 'available', |
| 77 | + repo: 'https://github.com/jup-ag/jupiter-core' |
| 78 | +}; |
| 79 | + |
| 80 | +// Stores program with IDL automatically loaded |
| 81 | +await qdrant.storeProgramMetadata(protocol); |
| 82 | +``` |
| 83 | + |
| 84 | +### Search Programs |
| 85 | + |
| 86 | +```javascript |
| 87 | +// Search by text query |
| 88 | +const results = await qdrant.searchPrograms('dex trading', 10); |
| 89 | +``` |
| 90 | + |
| 91 | +### Get Program by ID |
| 92 | + |
| 93 | +```javascript |
| 94 | +const program = await qdrant.getProgramMetadata('jupiter'); |
| 95 | +console.log(program.idl); // Full IDL object |
| 96 | +``` |
| 97 | + |
| 98 | +### Batch Operations |
| 99 | + |
| 100 | +```javascript |
| 101 | +// Store multiple programs |
| 102 | +await qdrant.batchStorePrograms(protocols); |
| 103 | + |
| 104 | +// Retrieve multiple programs |
| 105 | +const programs = await qdrant.batchGetProgramMetadata(['jupiter', 'orca']); |
| 106 | +``` |
| 107 | + |
| 108 | +## Type Definitions |
| 109 | + |
| 110 | +TypeScript types are available in `lib/types/`: |
| 111 | + |
| 112 | +```typescript |
| 113 | +import { ProgramMetadataEntry, IDL, IDLProtocol } from './lib/types'; |
| 114 | +``` |
| 115 | + |
| 116 | +These types ensure compatibility with aldrin-labs/openSVM when integrating with shared databases. |
| 117 | + |
| 118 | +## Environment Variables |
| 119 | + |
| 120 | +```bash |
| 121 | +QDRANT_URL=http://localhost:6333 # Qdrant server URL |
| 122 | +QDRANT_API_KEY=your_api_key # Qdrant API key |
| 123 | +QDRANT_SERVER=http://localhost:6333 # Alternative (openSVM compatible) |
| 124 | +QDRANT=your_api_key # Alternative (openSVM compatible) |
| 125 | +``` |
| 126 | + |
| 127 | +## Compatibility |
| 128 | + |
| 129 | +This implementation is designed to be compatible with aldrin-labs/openSVM: |
| 130 | +- Same collection names and structure |
| 131 | +- Identical ProgramMetadataEntry model |
| 132 | +- Compatible search patterns |
| 133 | +- Shared database can be used by both projects |
0 commit comments