@clawdvault/sdk 0.1.1 → 0.1.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -1,5 +1,8 @@
1
1
  # @clawdvault/sdk
2
2
 
3
+ [![npm version](https://img.shields.io/npm/v/@clawdvault/sdk.svg)](https://www.npmjs.com/package/@clawdvault/sdk)
4
+ [![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)
5
+
3
6
  TypeScript SDK for [ClawdVault](https://clawdvault.com) - a pump.fun-style token launchpad on Solana.
4
7
 
5
8
  ## Features
@@ -36,6 +39,12 @@ const quote = await client.getQuote({
36
39
  type: 'buy',
37
40
  amount: 0.1
38
41
  });
42
+
43
+ // Get SOL/USD price
44
+ const { price } = await client.getSolPrice();
45
+
46
+ // Get top holders
47
+ const { holders } = await client.getHolders('TOKEN_MINT_ADDRESS');
39
48
  ```
40
49
 
41
50
  ### Write Operations (Wallet Required)
@@ -43,9 +52,12 @@ const quote = await client.getQuote({
43
52
  ```typescript
44
53
  import { createClient, KeypairSigner } from '@clawdvault/sdk';
45
54
 
46
- // Load wallet from file or private key
55
+ // Load wallet from file
47
56
  const signer = KeypairSigner.fromFile('/path/to/wallet.json');
48
- // or: const signer = new KeypairSigner(process.env.SOLANA_PRIVATE_KEY);
57
+ // Or from environment variable
58
+ const signer = KeypairSigner.fromEnv('SOLANA_PRIVATE_KEY');
59
+ // Or from base58 string
60
+ const signer = new KeypairSigner('base58_private_key');
49
61
 
50
62
  const client = createClient({ signer });
51
63
 
@@ -55,26 +67,161 @@ const result = await client.createToken({
55
67
  symbol: 'MYTOK',
56
68
  description: 'A cool token',
57
69
  image: 'https://example.com/image.png',
58
- initialBuy: 0.1 // Optional initial buy in SOL
70
+ initialBuy: 0.1, // Optional initial buy in SOL
71
+ twitter: 'https://twitter.com/mytoken',
72
+ website: 'https://mytoken.io'
59
73
  });
60
74
 
75
+ console.log('Token created:', result.mint);
76
+
61
77
  // Buy tokens with 0.1 SOL
62
78
  const buyResult = await client.buy('TOKEN_MINT_ADDRESS', 0.1);
79
+ console.log('Bought tokens, tx:', buyResult.signature);
63
80
 
64
81
  // Sell tokens
65
82
  const sellResult = await client.sell('TOKEN_MINT_ADDRESS', 1000000); // 1M tokens
66
83
 
67
84
  // Sell percentage of holdings
68
85
  const sellPercentResult = await client.sellPercent('TOKEN_MINT_ADDRESS', 50);
86
+
87
+ // Check your balance
88
+ const { balance } = await client.getMyBalance('TOKEN_MINT_ADDRESS');
89
+ ```
90
+
91
+ ### Smart Trading (Auto-Routes for Graduated Tokens)
92
+
93
+ ```typescript
94
+ // smartBuy automatically uses Jupiter for graduated tokens
95
+ const result = await client.smartBuy('TOKEN_MINT_ADDRESS', 0.5);
96
+
97
+ // Check if token uses Jupiter
98
+ const { graduated } = await client.getJupiterStatus('TOKEN_MINT_ADDRESS');
99
+ if (graduated) {
100
+ console.log('Token graduated - using Jupiter DEX');
101
+ }
102
+ ```
103
+
104
+ ## Real-Time Streaming
105
+
106
+ Subscribe to live data feeds using Server-Sent Events (SSE):
107
+
108
+ ```typescript
109
+ import { createStreaming } from '@clawdvault/sdk';
110
+
111
+ const streaming = createStreaming('https://clawdvault.com/api');
112
+
113
+ // Quick subscription helpers
114
+ const { unsubscribe, connection } = streaming.onTrades('TOKEN_MINT', (trade) => {
115
+ console.log(`${trade.type.toUpperCase()}: ${trade.sol_amount} SOL`);
116
+ });
117
+
118
+ // Later: cleanup
119
+ unsubscribe();
120
+ connection.disconnect();
121
+ ```
122
+
123
+ ### Streaming Trades
124
+
125
+ ```typescript
126
+ const conn = streaming.streamTrades('TOKEN_MINT');
127
+
128
+ conn.onConnect(() => console.log('Connected!'));
129
+ conn.onDisconnect(() => console.log('Disconnected'));
130
+ conn.onError((err) => console.error(err));
131
+
132
+ conn.on('trade', (trade) => {
133
+ console.log('New trade:', trade.type, trade.sol_amount, 'SOL');
134
+ });
135
+
136
+ conn.connect();
137
+
138
+ // Cleanup
139
+ conn.disconnect();
140
+ ```
141
+
142
+ ### Streaming Token Price Updates
143
+
144
+ ```typescript
145
+ const conn = streaming.streamToken('TOKEN_MINT');
146
+
147
+ conn.on('connected', (data) => {
148
+ console.log(`${data.name} (${data.symbol})`);
149
+ console.log(`Price: ${data.price_sol} SOL`);
150
+ console.log(`Market Cap: ${data.market_cap_sol} SOL`);
151
+ });
152
+
153
+ conn.on('update', (update) => {
154
+ console.log(`New price: ${update.price_sol} SOL`);
155
+ });
156
+
157
+ conn.on('trade', (trade) => {
158
+ console.log(`Price changed from ${trade.type}: ${trade.price_sol}`);
159
+ });
160
+
161
+ conn.connect();
162
+ ```
163
+
164
+ ### Streaming Chat Messages
165
+
166
+ ```typescript
167
+ const conn = streaming.streamChat('TOKEN_MINT');
168
+
169
+ conn.on('message', (msg) => {
170
+ const sender = msg.username || msg.wallet.slice(0, 8);
171
+ console.log(`${sender}: ${msg.message}`);
172
+ });
173
+
174
+ conn.on('reaction_added', (reaction) => {
175
+ console.log(`${reaction.emoji} added to message`);
176
+ });
177
+
178
+ conn.connect();
179
+ ```
180
+
181
+ ### Streaming Options
182
+
183
+ ```typescript
184
+ const streaming = createStreaming('https://clawdvault.com/api', {
185
+ autoReconnect: true, // Auto-reconnect on disconnect (default: true)
186
+ reconnectDelay: 3000, // Initial delay before reconnect (default: 3000ms)
187
+ maxReconnectAttempts: 10, // Max attempts before giving up (default: 10)
188
+ });
189
+ ```
190
+
191
+ ### Disconnect All Streams
192
+
193
+ ```typescript
194
+ // Disconnect everything
195
+ streaming.disconnectAll();
196
+
197
+ // Or disconnect specific stream
198
+ streaming.disconnect('trades', 'TOKEN_MINT');
69
199
  ```
70
200
 
71
201
  ## Configuration
72
202
 
73
203
  ```typescript
74
204
  const client = createClient({
75
- baseUrl: 'https://clawdvault.com/api', // Optional: custom API endpoint
76
- signer: mySigner, // Optional: add later with setSigner()
205
+ // Optional: custom API endpoint
206
+ baseUrl: 'https://clawdvault.com/api',
207
+
208
+ // Optional: wallet signer (can also use setSigner() later)
209
+ signer: mySigner,
210
+
211
+ // Optional: session token for authenticated endpoints
212
+ sessionToken: 'your-session-token',
213
+
214
+ // Optional: global error handler
215
+ onError: (error) => {
216
+ console.error('API Error:', error.message);
217
+ }
77
218
  });
219
+
220
+ // Add signer later
221
+ client.setSigner(newSigner);
222
+
223
+ // Get connected wallet address
224
+ const address = client.getWalletAddress(); // returns string | null
78
225
  ```
79
226
 
80
227
  ## Browser Usage with Phantom Wallet
@@ -82,6 +229,7 @@ const client = createClient({
82
229
  ```typescript
83
230
  import { createClient, PhantomSigner } from '@clawdvault/sdk';
84
231
 
232
+ // Connect to Phantom (will prompt user)
85
233
  const phantomSigner = await PhantomSigner.fromWindow();
86
234
  const client = createClient({ signer: phantomSigner });
87
235
 
@@ -91,7 +239,234 @@ const result = await client.buy('TOKEN_MINT_ADDRESS', 0.1);
91
239
 
92
240
  ## API Reference
93
241
 
94
- See the [ClawdVault API Documentation](https://clawdvault.com/docs) for full endpoint details.
242
+ ### Token Operations
243
+
244
+ ```typescript
245
+ // List tokens with filters
246
+ const { tokens } = await client.listTokens({
247
+ sort: 'market_cap', // 'created_at' | 'market_cap' | 'volume' | 'price'
248
+ limit: 20,
249
+ page: 1,
250
+ graduated: false // filter by graduation status
251
+ });
252
+
253
+ // Get single token
254
+ const { token, trades } = await client.getToken('MINT_ADDRESS');
255
+
256
+ // Get Metaplex metadata
257
+ const metadata = await client.getMetadata('MINT_ADDRESS');
258
+
259
+ // Create new token
260
+ const result = await client.createToken({
261
+ name: 'Token Name',
262
+ symbol: 'SYMBOL',
263
+ description: 'Description',
264
+ image: 'https://...', // or upload first with uploadImage()
265
+ initialBuy: 0.1, // optional
266
+ twitter: 'https://twitter.com/...',
267
+ telegram: 'https://t.me/...',
268
+ website: 'https://...'
269
+ });
270
+ ```
271
+
272
+ ### Trading Operations
273
+
274
+ ```typescript
275
+ // Get quote (no wallet required)
276
+ const quote = await client.getQuote({
277
+ mint: 'MINT_ADDRESS',
278
+ type: 'buy', // or 'sell'
279
+ amount: 0.1
280
+ });
281
+ console.log('Expected tokens:', quote.expectedAmount);
282
+ console.log('Price impact:', quote.priceImpact);
283
+
284
+ // Buy on bonding curve
285
+ const buyResult = await client.buy('MINT', 0.1, 0.01); // 1% slippage
286
+
287
+ // Sell on bonding curve
288
+ const sellResult = await client.sell('MINT', 1000000, 0.01);
289
+
290
+ // Sell percentage
291
+ const result = await client.sellPercent('MINT', 50, 0.01); // sell 50%
292
+
293
+ // Smart trading (auto-routes to Jupiter for graduated tokens)
294
+ const smartBuy = await client.smartBuy('MINT', 0.5, 0.01);
295
+ const smartSell = await client.smartSell('MINT', 1000000, 0.01);
296
+
297
+ // Jupiter-specific (for graduated tokens)
298
+ const jupBuy = await client.buyJupiter('MINT', 0.5, 50); // 50 bps = 0.5%
299
+ const jupSell = await client.sellJupiter('MINT', 1000000, 50);
300
+ ```
301
+
302
+ ### Price & Market Data
303
+
304
+ ```typescript
305
+ // Trade history
306
+ const { trades } = await client.getTrades({
307
+ mint: 'MINT_ADDRESS',
308
+ limit: 50
309
+ });
310
+
311
+ // OHLCV candles
312
+ const { candles } = await client.getCandles({
313
+ mint: 'MINT_ADDRESS',
314
+ interval: '1m', // '1m' | '5m' | '15m' | '1h' | '4h' | '1d'
315
+ limit: 100
316
+ });
317
+
318
+ // On-chain stats
319
+ const stats = await client.getStats('MINT_ADDRESS');
320
+
321
+ // Top holders
322
+ const { holders } = await client.getHolders('MINT_ADDRESS');
323
+
324
+ // Token balance
325
+ const { balance } = await client.getBalance('WALLET_ADDRESS', 'MINT_ADDRESS');
326
+ const { balance: myBalance } = await client.getMyBalance('MINT_ADDRESS');
327
+
328
+ // SOL/USD price
329
+ const { price } = await client.getSolPrice();
330
+
331
+ // Graduation status
332
+ const status = await client.getGraduationStatus('MINT_ADDRESS');
333
+ const jupStatus = await client.getJupiterStatus('MINT_ADDRESS');
334
+ ```
335
+
336
+ ### Chat & Social
337
+
338
+ ```typescript
339
+ // Get chat messages
340
+ const { messages } = await client.getChat({
341
+ mint: 'MINT_ADDRESS',
342
+ limit: 50
343
+ });
344
+
345
+ // Send message (requires auth)
346
+ await client.sendChat({
347
+ mint: 'MINT_ADDRESS',
348
+ content: 'Hello world!'
349
+ });
350
+
351
+ // Reactions
352
+ await client.addReaction('MESSAGE_ID', '🚀');
353
+ await client.removeReaction('MESSAGE_ID', '🚀');
354
+ ```
355
+
356
+ ### User & Auth
357
+
358
+ ```typescript
359
+ // Get profile
360
+ const profile = await client.getProfile('WALLET_ADDRESS');
361
+
362
+ // Update profile
363
+ await client.updateProfile({
364
+ username: 'newname',
365
+ bio: 'New bio'
366
+ });
367
+
368
+ // Session management
369
+ const { token } = await client.createSession();
370
+ client.setSessionToken(token);
371
+ const { valid } = await client.validateSession();
372
+ ```
373
+
374
+ ### File Upload
375
+
376
+ ```typescript
377
+ // Upload from file path (Node.js)
378
+ const { url } = await client.uploadImageFromPath('./logo.png');
379
+
380
+ // Upload from Buffer/File
381
+ const { url } = await client.uploadImage(buffer, 'logo.png');
382
+
383
+ // Use in token creation
384
+ await client.createToken({
385
+ name: 'My Token',
386
+ symbol: 'MTK',
387
+ image: url // use uploaded URL
388
+ });
389
+ ```
390
+
391
+ ## Error Handling
392
+
393
+ ```typescript
394
+ import { createClient, KeypairSigner } from '@clawdvault/sdk';
395
+
396
+ const client = createClient({
397
+ signer: KeypairSigner.fromEnv(),
398
+ onError: (error) => {
399
+ // Global error handler
400
+ console.error('API Error:', error.message);
401
+ }
402
+ });
403
+
404
+ // Try/catch for specific handling
405
+ try {
406
+ const result = await client.buy('MINT_ADDRESS', 0.1);
407
+ } catch (error) {
408
+ // error.status - HTTP status code (404, 400, 500, etc.)
409
+ // error.response - parsed response body
410
+ // error.message - error message
411
+
412
+ if (error.status === 404) {
413
+ console.log('Token not found');
414
+ } else if (error.status === 400) {
415
+ console.log('Bad request:', error.response?.error);
416
+ } else if (error.message.includes('Signer required')) {
417
+ console.log('Wallet not connected');
418
+ } else if (error.message.includes('No tokens to sell')) {
419
+ console.log('Zero balance');
420
+ } else {
421
+ console.log('Unexpected error:', error.message);
422
+ }
423
+ }
424
+ ```
425
+
426
+ ## TypeScript Types
427
+
428
+ All types are exported for use in your application:
429
+
430
+ ```typescript
431
+ import type {
432
+ Token,
433
+ Trade,
434
+ QuoteResponse,
435
+ TokenListParams,
436
+ ExecuteTradeResponse,
437
+ // ... many more
438
+ } from '@clawdvault/sdk';
439
+ ```
440
+
441
+ ## Constants
442
+
443
+ ```typescript
444
+ import { PROGRAM_ID, DEFAULT_BASE_URL } from '@clawdvault/sdk';
445
+
446
+ console.log(PROGRAM_ID); // 'GUyF2TVe32Cid4iGVt2F6wPYDhLSVmTUZBj2974outYM'
447
+ console.log(DEFAULT_BASE_URL); // 'https://clawdvault.com/api'
448
+ ```
449
+
450
+ ## Troubleshooting
451
+
452
+ ### "Signer required" error
453
+ Write operations (buy, sell, createToken) need a wallet signer:
454
+ ```typescript
455
+ const signer = KeypairSigner.fromFile('~/.config/solana/id.json');
456
+ const client = createClient({ signer });
457
+ ```
458
+
459
+ ### "Phantom wallet not found"
460
+ - Install the Phantom browser extension
461
+ - Page must be served over HTTPS (or localhost)
462
+
463
+ ### Transaction failures
464
+ - Increase slippage: `client.buy(mint, sol, 0.05)` (5%)
465
+ - Check SOL balance for fees
466
+ - Token price may have moved
467
+
468
+ ### "No tokens to sell"
469
+ Call `getMyBalance()` to verify you have tokens before selling.
95
470
 
96
471
  ## License
97
472
 
package/dist/index.d.mts CHANGED
@@ -600,6 +600,161 @@ declare class ClawdVaultClient {
600
600
  */
601
601
  declare function createClient(config?: ClawdVaultConfig): ClawdVaultClient;
602
602
 
603
+ /**
604
+ * ClawdVault Streaming Client
605
+ * Real-time data feeds via Server-Sent Events
606
+ */
607
+ interface StreamTrade {
608
+ id: string;
609
+ type: 'buy' | 'sell';
610
+ sol_amount: number;
611
+ token_amount: number;
612
+ price_sol: number;
613
+ trader: string;
614
+ signature?: string;
615
+ created_at: string;
616
+ }
617
+ interface StreamTokenUpdate {
618
+ price_sol: number;
619
+ market_cap_sol: number;
620
+ virtual_sol_reserves: number;
621
+ virtual_token_reserves: number;
622
+ real_sol_reserves: number;
623
+ graduated: boolean;
624
+ timestamp: number;
625
+ }
626
+ interface StreamTokenConnected extends StreamTokenUpdate {
627
+ mint: string;
628
+ name: string;
629
+ symbol: string;
630
+ }
631
+ interface StreamChatMessage {
632
+ id: string;
633
+ wallet: string;
634
+ username?: string;
635
+ message: string;
636
+ reply_to?: string;
637
+ created_at: string;
638
+ }
639
+ interface StreamReaction {
640
+ message_id: string;
641
+ emoji: string;
642
+ wallet: string;
643
+ }
644
+ interface StreamingOptions {
645
+ /** Auto-reconnect on connection loss (default: true) */
646
+ autoReconnect?: boolean;
647
+ /** Reconnect delay in ms (default: 3000) */
648
+ reconnectDelay?: number;
649
+ /** Max reconnect attempts (default: 10) */
650
+ maxReconnectAttempts?: number;
651
+ }
652
+ type EventCallback<T> = (data: T) => void;
653
+ type ErrorCallback = (error: Error) => void;
654
+ type ConnectionCallback = () => void;
655
+ declare class StreamConnection {
656
+ private eventSource;
657
+ private url;
658
+ private options;
659
+ private reconnectAttempts;
660
+ private reconnectTimeout;
661
+ private listeners;
662
+ private onConnectCallbacks;
663
+ private onDisconnectCallbacks;
664
+ private onErrorCallbacks;
665
+ private isConnected;
666
+ private isManuallyDisconnected;
667
+ constructor(url: string, options?: StreamingOptions);
668
+ /**
669
+ * Connect to the stream
670
+ */
671
+ connect(): void;
672
+ private handleEvent;
673
+ private scheduleReconnect;
674
+ /**
675
+ * Disconnect from the stream
676
+ */
677
+ disconnect(): void;
678
+ /**
679
+ * Subscribe to an event type
680
+ */
681
+ on<T>(eventType: string, callback: EventCallback<T>): () => void;
682
+ /**
683
+ * One-time event listener
684
+ */
685
+ once<T>(eventType: string, callback: EventCallback<T>): void;
686
+ /**
687
+ * Register connection callback
688
+ */
689
+ onConnect(callback: ConnectionCallback): () => void;
690
+ /**
691
+ * Register disconnection callback
692
+ */
693
+ onDisconnect(callback: ConnectionCallback): () => void;
694
+ /**
695
+ * Register error callback
696
+ */
697
+ onError(callback: ErrorCallback): () => void;
698
+ /**
699
+ * Check if connected
700
+ */
701
+ get connected(): boolean;
702
+ }
703
+ /**
704
+ * Streaming client for ClawdVault
705
+ */
706
+ declare class ClawdVaultStreaming {
707
+ private baseUrl;
708
+ private connections;
709
+ private options;
710
+ constructor(baseUrl?: string, options?: StreamingOptions);
711
+ /**
712
+ * Stream trades for a token
713
+ */
714
+ streamTrades(mint: string): StreamConnection;
715
+ /**
716
+ * Stream token updates (price, market cap)
717
+ */
718
+ streamToken(mint: string): StreamConnection;
719
+ /**
720
+ * Stream chat messages
721
+ */
722
+ streamChat(mint: string): StreamConnection;
723
+ /**
724
+ * Convenience: Subscribe to trades with callback
725
+ */
726
+ onTrades(mint: string, callback: EventCallback<StreamTrade>): {
727
+ unsubscribe: () => void;
728
+ connection: StreamConnection;
729
+ };
730
+ /**
731
+ * Convenience: Subscribe to token price updates
732
+ */
733
+ onPrice(mint: string, callback: EventCallback<StreamTokenUpdate>): {
734
+ unsubscribe: () => void;
735
+ connection: StreamConnection;
736
+ };
737
+ /**
738
+ * Convenience: Subscribe to chat messages
739
+ */
740
+ onChat(mint: string, callback: EventCallback<StreamChatMessage>): {
741
+ unsubscribe: () => void;
742
+ connection: StreamConnection;
743
+ };
744
+ /**
745
+ * Disconnect all streams
746
+ */
747
+ disconnectAll(): void;
748
+ /**
749
+ * Disconnect a specific stream
750
+ */
751
+ disconnect(type: 'trades' | 'token' | 'chat', mint: string): void;
752
+ }
753
+ /**
754
+ * Create streaming client
755
+ */
756
+ declare function createStreaming(baseUrl?: string, options?: StreamingOptions): ClawdVaultStreaming;
757
+
603
758
  /**
604
759
  * ClawdVault SDK
605
760
  * TypeScript client for ClawdVault token launchpad on Solana
@@ -610,4 +765,4 @@ declare function createClient(config?: ClawdVaultConfig): ClawdVaultClient;
610
765
  declare const PROGRAM_ID = "GUyF2TVe32Cid4iGVt2F6wPYDhLSVmTUZBj2974outYM";
611
766
  declare const DEFAULT_BASE_URL = "https://clawdvault.com/api";
612
767
 
613
- export { type BalanceResponse, type CandleData, type CandlesParams, type CandlesResponse, type ChatMessage, type ChatMessagesResponse, type ChatParams, ClawdVaultClient, type ClawdVaultConfig, DEFAULT_BASE_URL, type ExecuteCreateRequest, type ExecuteCreateResponse, type ExecuteTradeRequest, type ExecuteTradeResponse, type GraduationStatusResponse, type HolderInfo, type HoldersResponse, type JupiterExecuteRequest, type JupiterQuoteResponse, type JupiterStatusResponse, type JupiterSwapRequest, KeypairSigner, type NetworkStatusResponse, PROGRAM_ID, PhantomSigner, type PhantomWallet, type PrepareCreateRequest, type PrepareCreateResponse, type PrepareTradeRequest, type PrepareTradeResponse, type QuoteParams, type QuoteResponse, type SendChatRequest, type SessionResponse, type SessionValidateResponse, type SolPriceResponse, type StatsResponse, type Token, type TokenDetailResponse, type TokenListParams, type TokenListResponse, type Trade, type TradeHistoryResponse, type TradesParams, type UpdateProfileRequest, type UploadResponse, type UserProfile, type WalletSigner, createAuthSignature, createClient, signAndSerialize, verifySignature };
768
+ export { type BalanceResponse, type CandleData, type CandlesParams, type CandlesResponse, type ChatMessage, type ChatMessagesResponse, type ChatParams, ClawdVaultClient, type ClawdVaultConfig, ClawdVaultStreaming, DEFAULT_BASE_URL, type ExecuteCreateRequest, type ExecuteCreateResponse, type ExecuteTradeRequest, type ExecuteTradeResponse, type GraduationStatusResponse, type HolderInfo, type HoldersResponse, type JupiterExecuteRequest, type JupiterQuoteResponse, type JupiterStatusResponse, type JupiterSwapRequest, KeypairSigner, type NetworkStatusResponse, PROGRAM_ID, PhantomSigner, type PhantomWallet, type PrepareCreateRequest, type PrepareCreateResponse, type PrepareTradeRequest, type PrepareTradeResponse, type QuoteParams, type QuoteResponse, type SendChatRequest, type SessionResponse, type SessionValidateResponse, type SolPriceResponse, type StatsResponse, type StreamChatMessage, StreamConnection, type StreamReaction, type StreamTokenConnected, type StreamTokenUpdate, type StreamTrade, type StreamingOptions, type Token, type TokenDetailResponse, type TokenListParams, type TokenListResponse, type Trade, type TradeHistoryResponse, type TradesParams, type UpdateProfileRequest, type UploadResponse, type UserProfile, type WalletSigner, createAuthSignature, createClient, createStreaming, signAndSerialize, verifySignature };
package/dist/index.d.ts CHANGED
@@ -600,6 +600,161 @@ declare class ClawdVaultClient {
600
600
  */
601
601
  declare function createClient(config?: ClawdVaultConfig): ClawdVaultClient;
602
602
 
603
+ /**
604
+ * ClawdVault Streaming Client
605
+ * Real-time data feeds via Server-Sent Events
606
+ */
607
+ interface StreamTrade {
608
+ id: string;
609
+ type: 'buy' | 'sell';
610
+ sol_amount: number;
611
+ token_amount: number;
612
+ price_sol: number;
613
+ trader: string;
614
+ signature?: string;
615
+ created_at: string;
616
+ }
617
+ interface StreamTokenUpdate {
618
+ price_sol: number;
619
+ market_cap_sol: number;
620
+ virtual_sol_reserves: number;
621
+ virtual_token_reserves: number;
622
+ real_sol_reserves: number;
623
+ graduated: boolean;
624
+ timestamp: number;
625
+ }
626
+ interface StreamTokenConnected extends StreamTokenUpdate {
627
+ mint: string;
628
+ name: string;
629
+ symbol: string;
630
+ }
631
+ interface StreamChatMessage {
632
+ id: string;
633
+ wallet: string;
634
+ username?: string;
635
+ message: string;
636
+ reply_to?: string;
637
+ created_at: string;
638
+ }
639
+ interface StreamReaction {
640
+ message_id: string;
641
+ emoji: string;
642
+ wallet: string;
643
+ }
644
+ interface StreamingOptions {
645
+ /** Auto-reconnect on connection loss (default: true) */
646
+ autoReconnect?: boolean;
647
+ /** Reconnect delay in ms (default: 3000) */
648
+ reconnectDelay?: number;
649
+ /** Max reconnect attempts (default: 10) */
650
+ maxReconnectAttempts?: number;
651
+ }
652
+ type EventCallback<T> = (data: T) => void;
653
+ type ErrorCallback = (error: Error) => void;
654
+ type ConnectionCallback = () => void;
655
+ declare class StreamConnection {
656
+ private eventSource;
657
+ private url;
658
+ private options;
659
+ private reconnectAttempts;
660
+ private reconnectTimeout;
661
+ private listeners;
662
+ private onConnectCallbacks;
663
+ private onDisconnectCallbacks;
664
+ private onErrorCallbacks;
665
+ private isConnected;
666
+ private isManuallyDisconnected;
667
+ constructor(url: string, options?: StreamingOptions);
668
+ /**
669
+ * Connect to the stream
670
+ */
671
+ connect(): void;
672
+ private handleEvent;
673
+ private scheduleReconnect;
674
+ /**
675
+ * Disconnect from the stream
676
+ */
677
+ disconnect(): void;
678
+ /**
679
+ * Subscribe to an event type
680
+ */
681
+ on<T>(eventType: string, callback: EventCallback<T>): () => void;
682
+ /**
683
+ * One-time event listener
684
+ */
685
+ once<T>(eventType: string, callback: EventCallback<T>): void;
686
+ /**
687
+ * Register connection callback
688
+ */
689
+ onConnect(callback: ConnectionCallback): () => void;
690
+ /**
691
+ * Register disconnection callback
692
+ */
693
+ onDisconnect(callback: ConnectionCallback): () => void;
694
+ /**
695
+ * Register error callback
696
+ */
697
+ onError(callback: ErrorCallback): () => void;
698
+ /**
699
+ * Check if connected
700
+ */
701
+ get connected(): boolean;
702
+ }
703
+ /**
704
+ * Streaming client for ClawdVault
705
+ */
706
+ declare class ClawdVaultStreaming {
707
+ private baseUrl;
708
+ private connections;
709
+ private options;
710
+ constructor(baseUrl?: string, options?: StreamingOptions);
711
+ /**
712
+ * Stream trades for a token
713
+ */
714
+ streamTrades(mint: string): StreamConnection;
715
+ /**
716
+ * Stream token updates (price, market cap)
717
+ */
718
+ streamToken(mint: string): StreamConnection;
719
+ /**
720
+ * Stream chat messages
721
+ */
722
+ streamChat(mint: string): StreamConnection;
723
+ /**
724
+ * Convenience: Subscribe to trades with callback
725
+ */
726
+ onTrades(mint: string, callback: EventCallback<StreamTrade>): {
727
+ unsubscribe: () => void;
728
+ connection: StreamConnection;
729
+ };
730
+ /**
731
+ * Convenience: Subscribe to token price updates
732
+ */
733
+ onPrice(mint: string, callback: EventCallback<StreamTokenUpdate>): {
734
+ unsubscribe: () => void;
735
+ connection: StreamConnection;
736
+ };
737
+ /**
738
+ * Convenience: Subscribe to chat messages
739
+ */
740
+ onChat(mint: string, callback: EventCallback<StreamChatMessage>): {
741
+ unsubscribe: () => void;
742
+ connection: StreamConnection;
743
+ };
744
+ /**
745
+ * Disconnect all streams
746
+ */
747
+ disconnectAll(): void;
748
+ /**
749
+ * Disconnect a specific stream
750
+ */
751
+ disconnect(type: 'trades' | 'token' | 'chat', mint: string): void;
752
+ }
753
+ /**
754
+ * Create streaming client
755
+ */
756
+ declare function createStreaming(baseUrl?: string, options?: StreamingOptions): ClawdVaultStreaming;
757
+
603
758
  /**
604
759
  * ClawdVault SDK
605
760
  * TypeScript client for ClawdVault token launchpad on Solana
@@ -610,4 +765,4 @@ declare function createClient(config?: ClawdVaultConfig): ClawdVaultClient;
610
765
  declare const PROGRAM_ID = "GUyF2TVe32Cid4iGVt2F6wPYDhLSVmTUZBj2974outYM";
611
766
  declare const DEFAULT_BASE_URL = "https://clawdvault.com/api";
612
767
 
613
- export { type BalanceResponse, type CandleData, type CandlesParams, type CandlesResponse, type ChatMessage, type ChatMessagesResponse, type ChatParams, ClawdVaultClient, type ClawdVaultConfig, DEFAULT_BASE_URL, type ExecuteCreateRequest, type ExecuteCreateResponse, type ExecuteTradeRequest, type ExecuteTradeResponse, type GraduationStatusResponse, type HolderInfo, type HoldersResponse, type JupiterExecuteRequest, type JupiterQuoteResponse, type JupiterStatusResponse, type JupiterSwapRequest, KeypairSigner, type NetworkStatusResponse, PROGRAM_ID, PhantomSigner, type PhantomWallet, type PrepareCreateRequest, type PrepareCreateResponse, type PrepareTradeRequest, type PrepareTradeResponse, type QuoteParams, type QuoteResponse, type SendChatRequest, type SessionResponse, type SessionValidateResponse, type SolPriceResponse, type StatsResponse, type Token, type TokenDetailResponse, type TokenListParams, type TokenListResponse, type Trade, type TradeHistoryResponse, type TradesParams, type UpdateProfileRequest, type UploadResponse, type UserProfile, type WalletSigner, createAuthSignature, createClient, signAndSerialize, verifySignature };
768
+ export { type BalanceResponse, type CandleData, type CandlesParams, type CandlesResponse, type ChatMessage, type ChatMessagesResponse, type ChatParams, ClawdVaultClient, type ClawdVaultConfig, ClawdVaultStreaming, DEFAULT_BASE_URL, type ExecuteCreateRequest, type ExecuteCreateResponse, type ExecuteTradeRequest, type ExecuteTradeResponse, type GraduationStatusResponse, type HolderInfo, type HoldersResponse, type JupiterExecuteRequest, type JupiterQuoteResponse, type JupiterStatusResponse, type JupiterSwapRequest, KeypairSigner, type NetworkStatusResponse, PROGRAM_ID, PhantomSigner, type PhantomWallet, type PrepareCreateRequest, type PrepareCreateResponse, type PrepareTradeRequest, type PrepareTradeResponse, type QuoteParams, type QuoteResponse, type SendChatRequest, type SessionResponse, type SessionValidateResponse, type SolPriceResponse, type StatsResponse, type StreamChatMessage, StreamConnection, type StreamReaction, type StreamTokenConnected, type StreamTokenUpdate, type StreamTrade, type StreamingOptions, type Token, type TokenDetailResponse, type TokenListParams, type TokenListResponse, type Trade, type TradeHistoryResponse, type TradesParams, type UpdateProfileRequest, type UploadResponse, type UserProfile, type WalletSigner, createAuthSignature, createClient, createStreaming, signAndSerialize, verifySignature };
package/dist/index.js CHANGED
@@ -31,14 +31,17 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
31
31
  var index_exports = {};
32
32
  __export(index_exports, {
33
33
  ClawdVaultClient: () => ClawdVaultClient,
34
+ ClawdVaultStreaming: () => ClawdVaultStreaming,
34
35
  DEFAULT_BASE_URL: () => DEFAULT_BASE_URL,
35
36
  Keypair: () => import_web32.Keypair,
36
37
  KeypairSigner: () => KeypairSigner,
37
38
  PROGRAM_ID: () => PROGRAM_ID,
38
39
  PhantomSigner: () => PhantomSigner,
39
40
  PublicKey: () => import_web32.PublicKey,
41
+ StreamConnection: () => StreamConnection,
40
42
  createAuthSignature: () => createAuthSignature,
41
43
  createClient: () => createClient,
44
+ createStreaming: () => createStreaming,
42
45
  signAndSerialize: () => signAndSerialize,
43
46
  verifySignature: () => verifySignature
44
47
  });
@@ -611,6 +614,268 @@ function createClient(config) {
611
614
  return new ClawdVaultClient(config);
612
615
  }
613
616
 
617
+ // src/streaming.ts
618
+ var getEventSource = () => {
619
+ if (typeof EventSource !== "undefined") {
620
+ return EventSource;
621
+ }
622
+ return require("eventsource");
623
+ };
624
+ var StreamConnection = class {
625
+ constructor(url, options = {}) {
626
+ this.eventSource = null;
627
+ this.reconnectAttempts = 0;
628
+ this.reconnectTimeout = null;
629
+ this.listeners = /* @__PURE__ */ new Map();
630
+ this.onConnectCallbacks = /* @__PURE__ */ new Set();
631
+ this.onDisconnectCallbacks = /* @__PURE__ */ new Set();
632
+ this.onErrorCallbacks = /* @__PURE__ */ new Set();
633
+ this.isConnected = false;
634
+ this.isManuallyDisconnected = false;
635
+ this.url = url;
636
+ this.options = {
637
+ autoReconnect: options.autoReconnect ?? true,
638
+ reconnectDelay: options.reconnectDelay ?? 3e3,
639
+ maxReconnectAttempts: options.maxReconnectAttempts ?? 10
640
+ };
641
+ }
642
+ /**
643
+ * Connect to the stream
644
+ */
645
+ connect() {
646
+ if (this.eventSource) {
647
+ return;
648
+ }
649
+ this.isManuallyDisconnected = false;
650
+ const EventSourceImpl = getEventSource();
651
+ this.eventSource = new EventSourceImpl(this.url);
652
+ this.eventSource.onopen = () => {
653
+ this.isConnected = true;
654
+ this.reconnectAttempts = 0;
655
+ this.onConnectCallbacks.forEach((cb) => cb());
656
+ };
657
+ this.eventSource.onerror = (event) => {
658
+ const wasConnected = this.isConnected;
659
+ this.isConnected = false;
660
+ if (wasConnected) {
661
+ this.onDisconnectCallbacks.forEach((cb) => cb());
662
+ }
663
+ this.onErrorCallbacks.forEach((cb) => cb(new Error("Stream connection error")));
664
+ if (this.options.autoReconnect && !this.isManuallyDisconnected) {
665
+ this.scheduleReconnect();
666
+ }
667
+ };
668
+ this.eventSource.onmessage = (event) => {
669
+ this.handleEvent("message", event.data);
670
+ };
671
+ for (const eventType of this.listeners.keys()) {
672
+ this.eventSource.addEventListener(eventType, (event) => {
673
+ this.handleEvent(eventType, event.data);
674
+ });
675
+ }
676
+ }
677
+ handleEvent(eventType, data) {
678
+ const callbacks = this.listeners.get(eventType);
679
+ if (!callbacks) return;
680
+ try {
681
+ const parsed = JSON.parse(data);
682
+ callbacks.forEach((cb) => cb(parsed));
683
+ } catch {
684
+ }
685
+ }
686
+ scheduleReconnect() {
687
+ if (this.reconnectTimeout) {
688
+ clearTimeout(this.reconnectTimeout);
689
+ }
690
+ if (this.reconnectAttempts >= this.options.maxReconnectAttempts) {
691
+ this.onErrorCallbacks.forEach(
692
+ (cb) => cb(new Error(`Max reconnect attempts (${this.options.maxReconnectAttempts}) reached`))
693
+ );
694
+ return;
695
+ }
696
+ this.reconnectAttempts++;
697
+ const delay = this.options.reconnectDelay * Math.pow(1.5, this.reconnectAttempts - 1);
698
+ this.reconnectTimeout = setTimeout(() => {
699
+ this.eventSource?.close();
700
+ this.eventSource = null;
701
+ this.connect();
702
+ }, delay);
703
+ }
704
+ /**
705
+ * Disconnect from the stream
706
+ */
707
+ disconnect() {
708
+ this.isManuallyDisconnected = true;
709
+ if (this.reconnectTimeout) {
710
+ clearTimeout(this.reconnectTimeout);
711
+ this.reconnectTimeout = null;
712
+ }
713
+ if (this.eventSource) {
714
+ this.eventSource.close();
715
+ this.eventSource = null;
716
+ }
717
+ if (this.isConnected) {
718
+ this.isConnected = false;
719
+ this.onDisconnectCallbacks.forEach((cb) => cb());
720
+ }
721
+ }
722
+ /**
723
+ * Subscribe to an event type
724
+ */
725
+ on(eventType, callback) {
726
+ if (!this.listeners.has(eventType)) {
727
+ this.listeners.set(eventType, /* @__PURE__ */ new Set());
728
+ if (this.eventSource) {
729
+ this.eventSource.addEventListener(eventType, (event) => {
730
+ this.handleEvent(eventType, event.data);
731
+ });
732
+ }
733
+ }
734
+ this.listeners.get(eventType).add(callback);
735
+ return () => {
736
+ const callbacks = this.listeners.get(eventType);
737
+ if (callbacks) {
738
+ callbacks.delete(callback);
739
+ }
740
+ };
741
+ }
742
+ /**
743
+ * One-time event listener
744
+ */
745
+ once(eventType, callback) {
746
+ const unsubscribe = this.on(eventType, (data) => {
747
+ unsubscribe();
748
+ callback(data);
749
+ });
750
+ }
751
+ /**
752
+ * Register connection callback
753
+ */
754
+ onConnect(callback) {
755
+ this.onConnectCallbacks.add(callback);
756
+ return () => this.onConnectCallbacks.delete(callback);
757
+ }
758
+ /**
759
+ * Register disconnection callback
760
+ */
761
+ onDisconnect(callback) {
762
+ this.onDisconnectCallbacks.add(callback);
763
+ return () => this.onDisconnectCallbacks.delete(callback);
764
+ }
765
+ /**
766
+ * Register error callback
767
+ */
768
+ onError(callback) {
769
+ this.onErrorCallbacks.add(callback);
770
+ return () => this.onErrorCallbacks.delete(callback);
771
+ }
772
+ /**
773
+ * Check if connected
774
+ */
775
+ get connected() {
776
+ return this.isConnected;
777
+ }
778
+ };
779
+ var ClawdVaultStreaming = class {
780
+ constructor(baseUrl = "https://clawdvault.com/api", options = {}) {
781
+ this.connections = /* @__PURE__ */ new Map();
782
+ this.baseUrl = baseUrl.replace(/\/$/, "");
783
+ this.options = options;
784
+ }
785
+ /**
786
+ * Stream trades for a token
787
+ */
788
+ streamTrades(mint) {
789
+ const key = `trades:${mint}`;
790
+ if (!this.connections.has(key)) {
791
+ const conn = new StreamConnection(
792
+ `${this.baseUrl}/stream/trades?mint=${mint}`,
793
+ this.options
794
+ );
795
+ this.connections.set(key, conn);
796
+ }
797
+ return this.connections.get(key);
798
+ }
799
+ /**
800
+ * Stream token updates (price, market cap)
801
+ */
802
+ streamToken(mint) {
803
+ const key = `token:${mint}`;
804
+ if (!this.connections.has(key)) {
805
+ const conn = new StreamConnection(
806
+ `${this.baseUrl}/stream/token?mint=${mint}`,
807
+ this.options
808
+ );
809
+ this.connections.set(key, conn);
810
+ }
811
+ return this.connections.get(key);
812
+ }
813
+ /**
814
+ * Stream chat messages
815
+ */
816
+ streamChat(mint) {
817
+ const key = `chat:${mint}`;
818
+ if (!this.connections.has(key)) {
819
+ const conn = new StreamConnection(
820
+ `${this.baseUrl}/stream/chat?mint=${mint}`,
821
+ this.options
822
+ );
823
+ this.connections.set(key, conn);
824
+ }
825
+ return this.connections.get(key);
826
+ }
827
+ /**
828
+ * Convenience: Subscribe to trades with callback
829
+ */
830
+ onTrades(mint, callback) {
831
+ const conn = this.streamTrades(mint);
832
+ const unsubscribe = conn.on("trade", callback);
833
+ conn.connect();
834
+ return { unsubscribe, connection: conn };
835
+ }
836
+ /**
837
+ * Convenience: Subscribe to token price updates
838
+ */
839
+ onPrice(mint, callback) {
840
+ const conn = this.streamToken(mint);
841
+ const unsubscribe = conn.on("update", callback);
842
+ conn.connect();
843
+ return { unsubscribe, connection: conn };
844
+ }
845
+ /**
846
+ * Convenience: Subscribe to chat messages
847
+ */
848
+ onChat(mint, callback) {
849
+ const conn = this.streamChat(mint);
850
+ const unsubscribe = conn.on("message", callback);
851
+ conn.connect();
852
+ return { unsubscribe, connection: conn };
853
+ }
854
+ /**
855
+ * Disconnect all streams
856
+ */
857
+ disconnectAll() {
858
+ for (const conn of this.connections.values()) {
859
+ conn.disconnect();
860
+ }
861
+ this.connections.clear();
862
+ }
863
+ /**
864
+ * Disconnect a specific stream
865
+ */
866
+ disconnect(type, mint) {
867
+ const key = `${type}:${mint}`;
868
+ const conn = this.connections.get(key);
869
+ if (conn) {
870
+ conn.disconnect();
871
+ this.connections.delete(key);
872
+ }
873
+ }
874
+ };
875
+ function createStreaming(baseUrl, options) {
876
+ return new ClawdVaultStreaming(baseUrl, options);
877
+ }
878
+
614
879
  // src/index.ts
615
880
  var import_web32 = require("@solana/web3.js");
616
881
  var PROGRAM_ID = "GUyF2TVe32Cid4iGVt2F6wPYDhLSVmTUZBj2974outYM";
@@ -618,14 +883,17 @@ var DEFAULT_BASE_URL = "https://clawdvault.com/api";
618
883
  // Annotate the CommonJS export names for ESM import in node:
619
884
  0 && (module.exports = {
620
885
  ClawdVaultClient,
886
+ ClawdVaultStreaming,
621
887
  DEFAULT_BASE_URL,
622
888
  Keypair,
623
889
  KeypairSigner,
624
890
  PROGRAM_ID,
625
891
  PhantomSigner,
626
892
  PublicKey,
893
+ StreamConnection,
627
894
  createAuthSignature,
628
895
  createClient,
896
+ createStreaming,
629
897
  signAndSerialize,
630
898
  verifySignature
631
899
  });
package/dist/index.mjs CHANGED
@@ -577,20 +577,285 @@ function createClient(config) {
577
577
  return new ClawdVaultClient(config);
578
578
  }
579
579
 
580
+ // src/streaming.ts
581
+ var getEventSource = () => {
582
+ if (typeof EventSource !== "undefined") {
583
+ return EventSource;
584
+ }
585
+ return __require("eventsource");
586
+ };
587
+ var StreamConnection = class {
588
+ constructor(url, options = {}) {
589
+ this.eventSource = null;
590
+ this.reconnectAttempts = 0;
591
+ this.reconnectTimeout = null;
592
+ this.listeners = /* @__PURE__ */ new Map();
593
+ this.onConnectCallbacks = /* @__PURE__ */ new Set();
594
+ this.onDisconnectCallbacks = /* @__PURE__ */ new Set();
595
+ this.onErrorCallbacks = /* @__PURE__ */ new Set();
596
+ this.isConnected = false;
597
+ this.isManuallyDisconnected = false;
598
+ this.url = url;
599
+ this.options = {
600
+ autoReconnect: options.autoReconnect ?? true,
601
+ reconnectDelay: options.reconnectDelay ?? 3e3,
602
+ maxReconnectAttempts: options.maxReconnectAttempts ?? 10
603
+ };
604
+ }
605
+ /**
606
+ * Connect to the stream
607
+ */
608
+ connect() {
609
+ if (this.eventSource) {
610
+ return;
611
+ }
612
+ this.isManuallyDisconnected = false;
613
+ const EventSourceImpl = getEventSource();
614
+ this.eventSource = new EventSourceImpl(this.url);
615
+ this.eventSource.onopen = () => {
616
+ this.isConnected = true;
617
+ this.reconnectAttempts = 0;
618
+ this.onConnectCallbacks.forEach((cb) => cb());
619
+ };
620
+ this.eventSource.onerror = (event) => {
621
+ const wasConnected = this.isConnected;
622
+ this.isConnected = false;
623
+ if (wasConnected) {
624
+ this.onDisconnectCallbacks.forEach((cb) => cb());
625
+ }
626
+ this.onErrorCallbacks.forEach((cb) => cb(new Error("Stream connection error")));
627
+ if (this.options.autoReconnect && !this.isManuallyDisconnected) {
628
+ this.scheduleReconnect();
629
+ }
630
+ };
631
+ this.eventSource.onmessage = (event) => {
632
+ this.handleEvent("message", event.data);
633
+ };
634
+ for (const eventType of this.listeners.keys()) {
635
+ this.eventSource.addEventListener(eventType, (event) => {
636
+ this.handleEvent(eventType, event.data);
637
+ });
638
+ }
639
+ }
640
+ handleEvent(eventType, data) {
641
+ const callbacks = this.listeners.get(eventType);
642
+ if (!callbacks) return;
643
+ try {
644
+ const parsed = JSON.parse(data);
645
+ callbacks.forEach((cb) => cb(parsed));
646
+ } catch {
647
+ }
648
+ }
649
+ scheduleReconnect() {
650
+ if (this.reconnectTimeout) {
651
+ clearTimeout(this.reconnectTimeout);
652
+ }
653
+ if (this.reconnectAttempts >= this.options.maxReconnectAttempts) {
654
+ this.onErrorCallbacks.forEach(
655
+ (cb) => cb(new Error(`Max reconnect attempts (${this.options.maxReconnectAttempts}) reached`))
656
+ );
657
+ return;
658
+ }
659
+ this.reconnectAttempts++;
660
+ const delay = this.options.reconnectDelay * Math.pow(1.5, this.reconnectAttempts - 1);
661
+ this.reconnectTimeout = setTimeout(() => {
662
+ this.eventSource?.close();
663
+ this.eventSource = null;
664
+ this.connect();
665
+ }, delay);
666
+ }
667
+ /**
668
+ * Disconnect from the stream
669
+ */
670
+ disconnect() {
671
+ this.isManuallyDisconnected = true;
672
+ if (this.reconnectTimeout) {
673
+ clearTimeout(this.reconnectTimeout);
674
+ this.reconnectTimeout = null;
675
+ }
676
+ if (this.eventSource) {
677
+ this.eventSource.close();
678
+ this.eventSource = null;
679
+ }
680
+ if (this.isConnected) {
681
+ this.isConnected = false;
682
+ this.onDisconnectCallbacks.forEach((cb) => cb());
683
+ }
684
+ }
685
+ /**
686
+ * Subscribe to an event type
687
+ */
688
+ on(eventType, callback) {
689
+ if (!this.listeners.has(eventType)) {
690
+ this.listeners.set(eventType, /* @__PURE__ */ new Set());
691
+ if (this.eventSource) {
692
+ this.eventSource.addEventListener(eventType, (event) => {
693
+ this.handleEvent(eventType, event.data);
694
+ });
695
+ }
696
+ }
697
+ this.listeners.get(eventType).add(callback);
698
+ return () => {
699
+ const callbacks = this.listeners.get(eventType);
700
+ if (callbacks) {
701
+ callbacks.delete(callback);
702
+ }
703
+ };
704
+ }
705
+ /**
706
+ * One-time event listener
707
+ */
708
+ once(eventType, callback) {
709
+ const unsubscribe = this.on(eventType, (data) => {
710
+ unsubscribe();
711
+ callback(data);
712
+ });
713
+ }
714
+ /**
715
+ * Register connection callback
716
+ */
717
+ onConnect(callback) {
718
+ this.onConnectCallbacks.add(callback);
719
+ return () => this.onConnectCallbacks.delete(callback);
720
+ }
721
+ /**
722
+ * Register disconnection callback
723
+ */
724
+ onDisconnect(callback) {
725
+ this.onDisconnectCallbacks.add(callback);
726
+ return () => this.onDisconnectCallbacks.delete(callback);
727
+ }
728
+ /**
729
+ * Register error callback
730
+ */
731
+ onError(callback) {
732
+ this.onErrorCallbacks.add(callback);
733
+ return () => this.onErrorCallbacks.delete(callback);
734
+ }
735
+ /**
736
+ * Check if connected
737
+ */
738
+ get connected() {
739
+ return this.isConnected;
740
+ }
741
+ };
742
+ var ClawdVaultStreaming = class {
743
+ constructor(baseUrl = "https://clawdvault.com/api", options = {}) {
744
+ this.connections = /* @__PURE__ */ new Map();
745
+ this.baseUrl = baseUrl.replace(/\/$/, "");
746
+ this.options = options;
747
+ }
748
+ /**
749
+ * Stream trades for a token
750
+ */
751
+ streamTrades(mint) {
752
+ const key = `trades:${mint}`;
753
+ if (!this.connections.has(key)) {
754
+ const conn = new StreamConnection(
755
+ `${this.baseUrl}/stream/trades?mint=${mint}`,
756
+ this.options
757
+ );
758
+ this.connections.set(key, conn);
759
+ }
760
+ return this.connections.get(key);
761
+ }
762
+ /**
763
+ * Stream token updates (price, market cap)
764
+ */
765
+ streamToken(mint) {
766
+ const key = `token:${mint}`;
767
+ if (!this.connections.has(key)) {
768
+ const conn = new StreamConnection(
769
+ `${this.baseUrl}/stream/token?mint=${mint}`,
770
+ this.options
771
+ );
772
+ this.connections.set(key, conn);
773
+ }
774
+ return this.connections.get(key);
775
+ }
776
+ /**
777
+ * Stream chat messages
778
+ */
779
+ streamChat(mint) {
780
+ const key = `chat:${mint}`;
781
+ if (!this.connections.has(key)) {
782
+ const conn = new StreamConnection(
783
+ `${this.baseUrl}/stream/chat?mint=${mint}`,
784
+ this.options
785
+ );
786
+ this.connections.set(key, conn);
787
+ }
788
+ return this.connections.get(key);
789
+ }
790
+ /**
791
+ * Convenience: Subscribe to trades with callback
792
+ */
793
+ onTrades(mint, callback) {
794
+ const conn = this.streamTrades(mint);
795
+ const unsubscribe = conn.on("trade", callback);
796
+ conn.connect();
797
+ return { unsubscribe, connection: conn };
798
+ }
799
+ /**
800
+ * Convenience: Subscribe to token price updates
801
+ */
802
+ onPrice(mint, callback) {
803
+ const conn = this.streamToken(mint);
804
+ const unsubscribe = conn.on("update", callback);
805
+ conn.connect();
806
+ return { unsubscribe, connection: conn };
807
+ }
808
+ /**
809
+ * Convenience: Subscribe to chat messages
810
+ */
811
+ onChat(mint, callback) {
812
+ const conn = this.streamChat(mint);
813
+ const unsubscribe = conn.on("message", callback);
814
+ conn.connect();
815
+ return { unsubscribe, connection: conn };
816
+ }
817
+ /**
818
+ * Disconnect all streams
819
+ */
820
+ disconnectAll() {
821
+ for (const conn of this.connections.values()) {
822
+ conn.disconnect();
823
+ }
824
+ this.connections.clear();
825
+ }
826
+ /**
827
+ * Disconnect a specific stream
828
+ */
829
+ disconnect(type, mint) {
830
+ const key = `${type}:${mint}`;
831
+ const conn = this.connections.get(key);
832
+ if (conn) {
833
+ conn.disconnect();
834
+ this.connections.delete(key);
835
+ }
836
+ }
837
+ };
838
+ function createStreaming(baseUrl, options) {
839
+ return new ClawdVaultStreaming(baseUrl, options);
840
+ }
841
+
580
842
  // src/index.ts
581
843
  import { PublicKey as PublicKey2, Keypair as Keypair2 } from "@solana/web3.js";
582
844
  var PROGRAM_ID = "GUyF2TVe32Cid4iGVt2F6wPYDhLSVmTUZBj2974outYM";
583
845
  var DEFAULT_BASE_URL = "https://clawdvault.com/api";
584
846
  export {
585
847
  ClawdVaultClient,
848
+ ClawdVaultStreaming,
586
849
  DEFAULT_BASE_URL,
587
850
  Keypair2 as Keypair,
588
851
  KeypairSigner,
589
852
  PROGRAM_ID,
590
853
  PhantomSigner,
591
854
  PublicKey2 as PublicKey,
855
+ StreamConnection,
592
856
  createAuthSignature,
593
857
  createClient,
858
+ createStreaming,
594
859
  signAndSerialize,
595
860
  verifySignature
596
861
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@clawdvault/sdk",
3
- "version": "0.1.1",
3
+ "version": "0.1.3",
4
4
  "description": "TypeScript SDK for ClawdVault - Solana token launchpad",
5
5
  "main": "dist/index.js",
6
6
  "module": "dist/index.mjs",
@@ -25,7 +25,8 @@
25
25
  "@solana/web3.js": "^1.91.0",
26
26
  "@solana/spl-token": "^0.4.0",
27
27
  "bs58": "^5.0.0",
28
- "tweetnacl": "^1.0.3"
28
+ "tweetnacl": "^1.0.3",
29
+ "eventsource": "^2.0.2"
29
30
  },
30
31
  "devDependencies": {
31
32
  "tsup": "^8.0.1",