@validators-dao/solana-stream-sdk 0.9.0 → 0.10.0

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.
Files changed (2) hide show
  1. package/README.md +40 -90
  2. package/package.json +3 -3
package/README.md CHANGED
@@ -210,94 +210,56 @@ Here's how to use the SDK to subscribe to Solana Shreds and decode entries:
210
210
 
211
211
  ```typescript
212
212
  import {
213
- ShredstreamProxyClient,
214
- credentials,
215
- ShredsCommitmentLevel,
216
- ShredsSubscribeEntriesRequestFns,
217
- decodeSolanaEntries,
218
- bs58,
213
+ ShredsClient,
214
+ ShredsClientCommitmentLevel,
215
+ // decodeSolanaEntries,
219
216
  } from '@validators-dao/solana-stream-sdk'
220
217
  import 'dotenv/config'
218
+ // import { logDecodedEntries } from '@/utils/logDecodedEntries'
221
219
 
222
- const endpoint = process.env.SHREDS_ENDPOINT!.replace(/^https?:\/\//, '')
220
+ import { receivedSlots, startLatencyCheck } from '@/utils/checkLatency'
223
221
 
224
- const client = new ShredstreamProxyClient(endpoint, credentials.createSsl())
222
+ const endpoint = process.env.SHREDS_ENDPOINT!
225
223
 
226
- const request = ShredsSubscribeEntriesRequestFns.create({
227
- accounts: {
228
- pumpfun: {
229
- account: [],
230
- owner: [],
231
- filters: [],
232
- },
233
- },
224
+ const client = new ShredsClient(endpoint)
225
+
226
+ // The filter is experimental
227
+ const request = {
228
+ accounts: {},
234
229
  transactions: {},
235
230
  slots: {},
236
- commitment: ShredsCommitmentLevel.PROCESSED,
237
- })
231
+ commitment: ShredsClientCommitmentLevel.Processed,
232
+ }
238
233
 
239
- const connect = async () => {
234
+ const connect = () => {
240
235
  console.log('Connecting to:', endpoint)
241
236
 
242
- const stream = client.subscribeEntries(request)
243
-
244
- stream.on('data', (data) => {
245
- console.log(`\n🟢 Received slot: ${data.slot}`)
246
-
247
- const decodedEntries = decodeSolanaEntries(data.entries)
248
-
249
- if (!Array.isArray(decodedEntries)) {
250
- console.warn('āš ļø decodedEntries is not an array:', decodedEntries)
251
- return
252
- }
253
-
254
- decodedEntries.forEach((entry, entryIdx) => {
255
- console.log(`\nāœ… Entry #${entryIdx + 1}`)
256
- console.log(
257
- ` - Hash: ${entry.hash ? bs58.encode(Buffer.from(entry.hash)) : 'N/A'}`,
258
- )
259
- console.log(` - Num Hashes: ${entry.num_hashes ?? 'N/A'}`)
260
-
261
- entry.transactions.forEach((tx, txIdx) => {
262
- console.log(`\nšŸ“„ Transaction #${txIdx + 1}`)
263
- const signaturesBase58 = tx.signatures
264
- .slice(1)
265
- .map((sig) => bs58.encode(Buffer.from(sig)))
266
- console.log(` - Signatures:`, signaturesBase58)
267
-
268
- const message = tx.message[0]
269
- if (message) {
270
- message.accountKeys.forEach((key, idx) => {
271
- console.log(` [${idx}] ${bs58.encode(Buffer.from(key))}`)
272
- })
273
-
274
- message.instructions.forEach((inst, instIdx) => {
275
- console.log(` [${instIdx}]`)
276
- console.log(` - Program ID Index: ${inst.programIdIndex}`)
277
- console.log(` - Accounts: ${inst.accounts.join(', ')}`)
278
- console.log(` - Data: ${bs58.encode(Buffer.from(inst.data))}`)
279
- })
280
-
281
- console.log(
282
- ` šŸ“Œ Recent Blockhash: ${bs58.encode(Buffer.from(message.recentBlockhash))}`,
283
- )
237
+ client.subscribeEntries(
238
+ JSON.stringify(request),
239
+ (_error: any, buffer: any) => {
240
+ const receivedAt = new Date()
241
+ if (buffer) {
242
+ const {
243
+ slot,
244
+ // entries
245
+ } = JSON.parse(buffer)
246
+
247
+ // You can decode entries as needed
248
+ // const decodedEntries = decodeSolanaEntries(new Uint8Array(entries))
249
+ // logDecodedEntries(decodedEntries)
250
+
251
+ if (!receivedSlots.has(slot)) {
252
+ receivedSlots.set(slot, [{ receivedAt }])
253
+ } else {
254
+ receivedSlots.get(slot)!.push({ receivedAt })
284
255
  }
285
- })
286
- })
287
- })
288
-
289
- stream.on('error', (err) => {
290
- console.error('🚨 Stream error:', err)
291
- setTimeout(connect, 5000)
292
- })
293
-
294
- stream.on('end', () => {
295
- console.log('šŸ”š Stream ended, reconnecting...')
296
- setTimeout(connect, 5000)
297
- })
256
+ }
257
+ },
258
+ )
298
259
  }
299
260
 
300
261
  connect()
262
+ startLatencyCheck()
301
263
  ```
302
264
 
303
265
  Ensure the environment variable `SHREDS_ENDPOINT` is set correctly.
@@ -325,33 +287,21 @@ Ensure the environment variable `SHREDS_ENDPOINT` is set correctly.
325
287
  - `SubscribeRequestAccountsDataSlice`: Data slice configuration for account subscriptions.
326
288
  - `bs58`: Base58 encoding/decoding utilities for Solana addresses and data.
327
289
 
328
- ### Shredstream Client Types
329
-
330
- - `ShredstreamProxyClient`: Client for streaming Solana shreds through proxy endpoints.
331
- - `ShredstreamClient`: Direct client for streaming Solana shreds.
332
- - `ShredsCommitmentLevel`: Commitment levels specifically for Shredstream data.
333
- - `ShredsSubscribeEntriesRequestFns`: Functions to construct entry subscription requests.
334
- - `ShredsEntryFns`: Utilities and functions for handling shred entries.
335
-
336
- ### Shredstream Exported Type Definitions
290
+ ### Shredstream Client
337
291
 
338
- - `ShredsSubscribeEntriesRequest`: Request type definition for subscribing to entries.
339
- - `ShredsSubscribeRequestFilterAccounts`: Account filter type for shred subscriptions.
340
- - `ShredsSubscribeRequestFilterTransactions`: Transaction filter type for shred subscriptions.
341
- - `ShredsSubscribeRequestFilterSlots`: Slot filter type for shred subscriptions.
342
- - `ShredsEntry`: Entry type definition representing Solana shred entries.
292
+ - `ShredsClient`: Client for streaming Solana shreds through shreds endpoints.
293
+ - `ShredsClientCommitmentLevel`: Solana commitment levels (e.g., processed, confirmed, finalized).
343
294
 
344
295
  ### Utility Exports
345
296
 
346
297
  - `decodeSolanaEntries`: Function to decode raw Solana shred entry data into structured, human-readable formats.
347
- - `credentials`, `Metadata`: gRPC credentials and metadata utilities.
348
298
 
349
299
  ## Dependencies
350
300
 
351
301
  - `@triton-one/yellowstone-grpc`: For gRPC streaming capabilities
352
302
  - `bs58`: For base58 encoding/decoding
353
- - `@grpc/grpc-js`
354
303
  - `@validators-dao/solana-entry-decoder`: Utility for decoding Solana shred entries.
304
+ - `@validators-dao/solana-shreds-client`: Solana Shreds Client for Scale. (NAPI-RS)
355
305
 
356
306
  ## āš ļø Experimental Filtering Feature Notice
357
307
 
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@validators-dao/solana-stream-sdk",
3
3
  "description": "Solana Stream SDK by Validators DAO",
4
- "version": "0.9.0",
4
+ "version": "0.10.0",
5
5
  "license": "Apache-2.0",
6
6
  "main": "dist/index.js",
7
7
  "types": "dist/index.d.ts",
@@ -26,8 +26,8 @@
26
26
  "dependencies": {
27
27
  "@triton-one/yellowstone-grpc": "4.0.2",
28
28
  "bs58": "6.0.0",
29
- "@validators-dao/solana-entry-decoder": "2.2.0",
30
- "@validators-dao/solana-shreds-client": "1.0.1"
29
+ "@validators-dao/solana-shreds-client": "1.0.1",
30
+ "@validators-dao/solana-entry-decoder": "2.2.0"
31
31
  },
32
32
  "devDependencies": {
33
33
  "@types/node": "22.15.27",