@validators-dao/solana-stream-sdk 0.9.0 ā 0.11.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.
- package/README.md +40 -90
- 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
|
-
|
|
214
|
-
|
|
215
|
-
|
|
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
|
-
|
|
220
|
+
import { receivedSlots, startLatencyCheck } from '@/utils/checkLatency'
|
|
223
221
|
|
|
224
|
-
const
|
|
222
|
+
const endpoint = process.env.SHREDS_ENDPOINT!
|
|
225
223
|
|
|
226
|
-
const
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
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:
|
|
237
|
-
}
|
|
231
|
+
commitment: ShredsClientCommitmentLevel.Processed,
|
|
232
|
+
}
|
|
238
233
|
|
|
239
|
-
const connect =
|
|
234
|
+
const connect = () => {
|
|
240
235
|
console.log('Connecting to:', endpoint)
|
|
241
236
|
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
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
|
|
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
|
-
- `
|
|
339
|
-
- `
|
|
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.
|
|
4
|
+
"version": "0.11.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.
|
|
30
|
-
"@validators-dao/solana-shreds-client": "1.0
|
|
29
|
+
"@validators-dao/solana-entry-decoder": "2.3.0",
|
|
30
|
+
"@validators-dao/solana-shreds-client": "1.1.0"
|
|
31
31
|
},
|
|
32
32
|
"devDependencies": {
|
|
33
33
|
"@types/node": "22.15.27",
|