@effect-blockchain/solana 0.0.0-stage → 0.2.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 (58) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +12 -2
  3. package/dist/SolanaAddress.d.ts +21 -0
  4. package/dist/SolanaAddress.d.ts.map +1 -0
  5. package/dist/SolanaAddress.js +33 -0
  6. package/dist/SolanaAddress.js.map +1 -0
  7. package/dist/SolanaIndexer.d.ts +198 -0
  8. package/dist/SolanaIndexer.d.ts.map +1 -0
  9. package/dist/SolanaIndexer.js +344 -0
  10. package/dist/SolanaIndexer.js.map +1 -0
  11. package/dist/SolanaNetwork.d.ts +64 -0
  12. package/dist/SolanaNetwork.d.ts.map +1 -0
  13. package/dist/SolanaNetwork.js +84 -0
  14. package/dist/SolanaNetwork.js.map +1 -0
  15. package/dist/SolanaRelayer.d.ts +207 -0
  16. package/dist/SolanaRelayer.d.ts.map +1 -0
  17. package/dist/SolanaRelayer.js +377 -0
  18. package/dist/SolanaRelayer.js.map +1 -0
  19. package/dist/SolanaRpc.d.ts +427 -0
  20. package/dist/SolanaRpc.d.ts.map +1 -0
  21. package/dist/SolanaRpc.js +216 -0
  22. package/dist/SolanaRpc.js.map +1 -0
  23. package/dist/SolanaSigner.d.ts +49 -0
  24. package/dist/SolanaSigner.d.ts.map +1 -0
  25. package/dist/SolanaSigner.js +82 -0
  26. package/dist/SolanaSigner.js.map +1 -0
  27. package/dist/SolanaTransactionHash.d.ts +14 -0
  28. package/dist/SolanaTransactionHash.d.ts.map +1 -0
  29. package/dist/SolanaTransactionHash.js +34 -0
  30. package/dist/SolanaTransactionHash.js.map +1 -0
  31. package/dist/index.d.ts +32 -0
  32. package/dist/index.d.ts.map +1 -0
  33. package/dist/index.js +33 -0
  34. package/dist/index.js.map +1 -0
  35. package/dist/internal/bigIntJson.d.ts +2 -0
  36. package/dist/internal/bigIntJson.d.ts.map +1 -0
  37. package/dist/internal/bigIntJson.js +9 -0
  38. package/dist/internal/bigIntJson.js.map +1 -0
  39. package/dist/internal/confirmations.d.ts +2 -0
  40. package/dist/internal/confirmations.d.ts.map +1 -0
  41. package/dist/internal/confirmations.js +15 -0
  42. package/dist/internal/confirmations.js.map +1 -0
  43. package/dist/internal/rpcMethods.d.ts +2 -0
  44. package/dist/internal/rpcMethods.d.ts.map +1 -0
  45. package/dist/internal/rpcMethods.js +223 -0
  46. package/dist/internal/rpcMethods.js.map +1 -0
  47. package/package.json +66 -3
  48. package/src/SolanaAddress.ts +40 -0
  49. package/src/SolanaIndexer.ts +552 -0
  50. package/src/SolanaNetwork.ts +105 -0
  51. package/src/SolanaRelayer.ts +493 -0
  52. package/src/SolanaRpc.ts +595 -0
  53. package/src/SolanaSigner.ts +98 -0
  54. package/src/SolanaTransactionHash.ts +41 -0
  55. package/src/index.ts +40 -0
  56. package/src/internal/bigIntJson.ts +18 -0
  57. package/src/internal/confirmations.ts +17 -0
  58. package/src/internal/rpcMethods.ts +260 -0
@@ -0,0 +1,427 @@
1
+ /**
2
+ * Typed Solana JSON-RPC methods over an ordered list of endpoints with fallback.
3
+ *
4
+ * A call starts at the first endpoint and moves to the next one on failure, except on `WrongNetwork`. Each endpoint
5
+ * is checked once to serve the configured network (`getGenesisHash`). Every method but `sendTransaction` is a read,
6
+ * so retries and fallback are safe; `sendTransaction` documents its own case. Methods are named after the JSON-RPC
7
+ * method. Every JSON integer in a reply is read as an exact `bigint`, so lamport amounts above 2^53 are never rounded.
8
+ *
9
+ * @example
10
+ * ```ts
11
+ * import type { SolanaAddress } from "@effect-blockchain/solana/SolanaAddress"
12
+ * import * as SolanaRpc from "@effect-blockchain/solana/SolanaRpc"
13
+ * import * as Effect from "effect/Effect"
14
+ *
15
+ * declare const address: SolanaAddress
16
+ *
17
+ * // the 10 latest finalized transactions touching `address`
18
+ * const latest = Effect.gen(function*() {
19
+ * const rpc = yield* SolanaRpc.SolanaRpc
20
+ * const signatures = yield* rpc.getSignaturesForAddress({ address, limit: 10, commitment: "finalized" })
21
+ * return yield* Effect.forEach(signatures, ({ signature }) =>
22
+ * rpc.getTransaction({ signature, commitment: "finalized" }))
23
+ * })
24
+ * ```
25
+ *
26
+ * @since 0.1.0
27
+ */
28
+ import * as JsonRpc from "@effect-blockchain/core/JsonRpc";
29
+ import type * as Arr from "effect/Array";
30
+ import * as Config from "effect/Config";
31
+ import * as Context from "effect/Context";
32
+ import type * as Duration from "effect/Duration";
33
+ import * as Effect from "effect/Effect";
34
+ import type * as HttpClient from "effect/http/HttpClient";
35
+ import * as Layer from "effect/Layer";
36
+ import type * as Redacted from "effect/Redacted";
37
+ import * as Schema from "effect/Schema";
38
+ import type { SolanaAddress } from "./SolanaAddress.ts";
39
+ import { type SolanaGenesisHash, type SolanaNetwork } from "./SolanaNetwork.ts";
40
+ import type { SolanaTransactionHash } from "./SolanaTransactionHash.ts";
41
+ /**
42
+ * A JSON-RPC endpoint. The `name` is shown in errors and spans, the `url` is never logged.
43
+ *
44
+ * @since 0.1.0
45
+ * @category models
46
+ */
47
+ export interface SolanaRpcEndpoint {
48
+ readonly name: string;
49
+ readonly url: Redacted.Redacted<string>;
50
+ }
51
+ declare const SolanaRpcError_base: Schema.Class<SolanaRpcError, Schema.TaggedStruct<"SolanaRpcError", {
52
+ readonly reason: Schema.Union<readonly [typeof JsonRpc.Unavailable, typeof JsonRpc.InvalidResponse, typeof JsonRpc.Lagging, typeof JsonRpc.Pruned, typeof JsonRpc.Rejected, typeof JsonRpc.WrongNetwork]>;
53
+ readonly method: Schema.String;
54
+ readonly endpoint: Schema.String;
55
+ readonly code: Schema.optional<Schema.Number>;
56
+ readonly cause: Schema.Defect;
57
+ }>, import("effect/Cause").YieldableError>;
58
+ /**
59
+ * A failed call: its `reason` (a {@link JsonRpc.Reason}, matched with `Effect.catchReason`), the JSON-RPC error code or
60
+ * HTTP status as `code`, and a `cause` without the endpoint URL. After several endpoints, the error is the last one
61
+ * and `cause` is an `AggregateError` of each endpoint's error, in order.
62
+ *
63
+ * On Solana, `Unavailable` includes the codes 429, -32603, -32005 and -32019, `Lagging` a `minContextSlot` not reached
64
+ * or a block not available yet, and `Pruned` a cleaned-up or skipped slot or a `getTransaction` returning `null`.
65
+ *
66
+ * @since 0.1.0
67
+ * @category errors
68
+ */
69
+ export declare class SolanaRpcError extends SolanaRpcError_base {
70
+ /**
71
+ * @since 0.1.0
72
+ */
73
+ get message(): string;
74
+ }
75
+ /**
76
+ * The commitment a read waits for. `processed` is left out: a processed block can still be dropped.
77
+ *
78
+ * @since 0.1.0
79
+ * @category models
80
+ */
81
+ export type SolanaCommitment = "confirmed" | "finalized";
82
+ /**
83
+ * One `getSignaturesForAddress` page: signatures touching `address`, newest first, older than `before` and newer than
84
+ * `until` when given, at most `limit` (the node's default and maximum is 1000).
85
+ *
86
+ * @since 0.1.0
87
+ * @category models
88
+ */
89
+ export interface SolanaSignaturesQuery {
90
+ readonly address: SolanaAddress;
91
+ readonly before?: SolanaTransactionHash | undefined;
92
+ readonly until?: SolanaTransactionHash | undefined;
93
+ readonly limit?: number | undefined;
94
+ readonly commitment: SolanaCommitment;
95
+ /**
96
+ * An endpoint that honours it answers `Lagging` until it has reached this slot. Some providers ignore it and answer
97
+ * from wherever they are, so a caller that needs the guarantee checks the head itself, e.g. with `getSlot`.
98
+ */
99
+ readonly minContextSlot?: bigint | undefined;
100
+ }
101
+ /**
102
+ * A `getSignaturesForAddress` entry. `blockTime` is a Unix timestamp in seconds, `null` when the node does not know
103
+ * it. `err` is the raw transaction error as JSON (integers as decimal strings), `null` when the transaction succeeded.
104
+ *
105
+ * @since 0.1.0
106
+ * @category models
107
+ */
108
+ export interface SolanaSignatureInfo {
109
+ readonly signature: SolanaTransactionHash;
110
+ readonly slot: bigint;
111
+ readonly blockTime: bigint | null;
112
+ readonly err: Schema.Json;
113
+ readonly memo: string | null;
114
+ }
115
+ /**
116
+ * The `getTransaction` encodings. `base64` is the signed wire transaction, for the `@solana/kit` decoders (e.g.
117
+ * `getTransactionDecoder`) and for storing the exact bytes. `json` splits it into signatures, account keys and compiled
118
+ * instructions; `jsonParsed` is not offered, as its shape depends on the programs the node knows.
119
+ *
120
+ * @since 0.1.0
121
+ * @category models
122
+ */
123
+ export type SolanaTransactionEncoding = "base64" | "json";
124
+ /**
125
+ * A compiled instruction of a `json` transaction: `programIdIndex` and `accounts` index the message's account keys,
126
+ * followed by the addresses loaded from the lookup tables (writable then readonly), and `data` is base58.
127
+ *
128
+ * @since 0.1.0
129
+ * @category models
130
+ */
131
+ export interface SolanaCompiledInstruction {
132
+ readonly programIdIndex: number;
133
+ readonly accounts: ReadonlyArray<number>;
134
+ readonly data: string;
135
+ }
136
+ /**
137
+ * A `json` transaction. `addressTableLookups` is absent from legacy transactions.
138
+ *
139
+ * @since 0.1.0
140
+ * @category models
141
+ */
142
+ export interface SolanaJsonTransaction {
143
+ readonly signatures: ReadonlyArray<SolanaTransactionHash>;
144
+ readonly message: {
145
+ readonly accountKeys: ReadonlyArray<SolanaAddress>;
146
+ readonly header: {
147
+ readonly numRequiredSignatures: number;
148
+ readonly numReadonlySignedAccounts: number;
149
+ readonly numReadonlyUnsignedAccounts: number;
150
+ };
151
+ readonly recentBlockhash: string;
152
+ readonly instructions: ReadonlyArray<SolanaCompiledInstruction>;
153
+ readonly addressTableLookups?: ReadonlyArray<{
154
+ readonly accountKey: SolanaAddress;
155
+ readonly writableIndexes: ReadonlyArray<number>;
156
+ readonly readonlyIndexes: ReadonlyArray<number>;
157
+ }>;
158
+ };
159
+ }
160
+ /**
161
+ * The `transaction` of a `getTransaction` result, by encoding: the base64 wire transaction or a
162
+ * {@link SolanaJsonTransaction}.
163
+ *
164
+ * @since 0.1.0
165
+ * @category models
166
+ */
167
+ export interface SolanaEncodedTransaction {
168
+ readonly base64: string;
169
+ readonly json: SolanaJsonTransaction;
170
+ }
171
+ /**
172
+ * The status meta of a transaction, reduced to its outcome and lamport balances. `err` is the raw transaction error as
173
+ * JSON (integers as decimal strings), `null` when it succeeded. `preBalances` and `postBalances` follow the account
174
+ * keys, then `loadedAddresses` (absent from transactions older than versioned transactions).
175
+ *
176
+ * @since 0.2.0
177
+ * @category models
178
+ */
179
+ export interface SolanaTransactionMeta {
180
+ readonly err: Schema.Json;
181
+ readonly fee: bigint;
182
+ readonly preBalances: ReadonlyArray<bigint>;
183
+ readonly postBalances: ReadonlyArray<bigint>;
184
+ readonly loadedAddresses?: {
185
+ readonly writable: ReadonlyArray<SolanaAddress>;
186
+ readonly readonly: ReadonlyArray<SolanaAddress>;
187
+ };
188
+ }
189
+ /**
190
+ * A `getTransaction` result. `transaction` follows the requested encoding (see {@link SolanaEncodedTransaction}).
191
+ * `meta` is `null` when the node does not have it.
192
+ *
193
+ * @since 0.1.0
194
+ * @category models
195
+ */
196
+ export interface SolanaTransactionInfo<Encoding extends SolanaTransactionEncoding = "base64"> {
197
+ readonly slot: bigint;
198
+ readonly blockTime: bigint | null;
199
+ readonly transaction: SolanaEncodedTransaction[Encoding];
200
+ readonly meta: SolanaTransactionMeta | null;
201
+ }
202
+ /**
203
+ * A `getBalance` result: the lamports of the account (`value`) at the context `slot`.
204
+ *
205
+ * @since 0.2.0
206
+ * @category models
207
+ */
208
+ export interface SolanaBalance {
209
+ readonly slot: bigint;
210
+ readonly value: bigint;
211
+ }
212
+ /**
213
+ * Why an instruction failed, as the node returns it: the variant's name (`"ProgramFailedToComplete"`), the program's
214
+ * own error code (`{ Custom: 6001 }`), or any other variant carrying data as raw JSON (integers as decimal strings).
215
+ *
216
+ * @since 0.2.0
217
+ * @category models
218
+ */
219
+ export type SolanaInstructionError = string | {
220
+ readonly Custom: number;
221
+ } | {
222
+ readonly [variant: string]: Schema.Json;
223
+ };
224
+ /**
225
+ * Why a transaction failed, as the node returns it: the variant's name (`"BlockhashNotFound"`), the failing
226
+ * instruction's index and error (`{ InstructionError: [2, { Custom: 6001 }] }`), or any other variant carrying data
227
+ * as raw JSON (integers as decimal strings).
228
+ *
229
+ * @since 0.2.0
230
+ * @category models
231
+ */
232
+ export type SolanaTransactionError = string | {
233
+ readonly InstructionError: readonly [index: number, error: SolanaInstructionError];
234
+ } | {
235
+ readonly [variant: string]: Schema.Json;
236
+ };
237
+ /**
238
+ * A `getSignatureStatuses` entry: the `slot` holding the transaction, its `err` (`null` when it succeeded) and the
239
+ * commitment its block has reached. `confirmations` counts the blocks built on it, `null` once it is finalized.
240
+ *
241
+ * @since 0.2.0
242
+ * @category models
243
+ */
244
+ export interface SolanaSignatureStatus {
245
+ readonly slot: bigint;
246
+ readonly confirmations: number | null;
247
+ readonly err: SolanaTransactionError | null;
248
+ readonly confirmationStatus: "processed" | "confirmed" | "finalized" | null;
249
+ }
250
+ /**
251
+ * A `getSignatureStatuses` result: one entry of `value` per signature, in order, `null` for a signature the endpoint
252
+ * does not know, as seen at the context `slot`.
253
+ *
254
+ * @since 0.2.0
255
+ * @category models
256
+ */
257
+ export interface SolanaSignatureStatuses {
258
+ readonly slot: bigint;
259
+ readonly value: ReadonlyArray<SolanaSignatureStatus | null>;
260
+ }
261
+ /**
262
+ * A `getLatestBlockhash` result at the context `slot`: a transaction signed with `blockhash` can land while the block
263
+ * height is at most `lastValidBlockHeight`.
264
+ *
265
+ * @since 0.2.0
266
+ * @category models
267
+ */
268
+ export interface SolanaLatestBlockhash {
269
+ readonly slot: bigint;
270
+ readonly blockhash: string;
271
+ readonly lastValidBlockHeight: bigint;
272
+ }
273
+ /**
274
+ * A `simulateTransaction` result at the context `slot`: `err` is `null` when the transaction would succeed, `logs` the
275
+ * program logs and `unitsConsumed` the compute units used, both `null` when the simulation did not run.
276
+ *
277
+ * @since 0.2.0
278
+ * @category models
279
+ */
280
+ export interface SolanaSimulation {
281
+ readonly slot: bigint;
282
+ readonly err: SolanaTransactionError | null;
283
+ readonly logs: ReadonlyArray<string> | null;
284
+ readonly unitsConsumed: bigint | null;
285
+ }
286
+ /**
287
+ * A `getRecentPrioritizationFees` entry: the lowest compute unit price, in micro-lamports, of a transaction that
288
+ * landed in `slot` and locked the queried accounts. It is 0 for a slot where such a transaction paid none.
289
+ *
290
+ * @since 0.2.0
291
+ * @category models
292
+ */
293
+ export interface SolanaPrioritizationFee {
294
+ readonly slot: bigint;
295
+ readonly prioritizationFee: bigint;
296
+ }
297
+ /**
298
+ * The `getTransaction` options.
299
+ *
300
+ * @since 0.1.0
301
+ * @category models
302
+ */
303
+ export interface SolanaTransactionQuery {
304
+ readonly signature: SolanaTransactionHash;
305
+ readonly commitment: SolanaCommitment;
306
+ }
307
+ declare const SolanaRpc_base: Context.ServiceClass<SolanaRpc, "@effect-blockchain/solana/SolanaRpc", {
308
+ readonly network: SolanaNetwork;
309
+ /** `getGenesisHash`, verified against `network` once per endpoint then served from that check. */
310
+ readonly getGenesisHash: Effect.Effect<SolanaGenesisHash, SolanaRpcError>;
311
+ /** `getSlot` */
312
+ readonly getSlot: (options: {
313
+ readonly commitment: SolanaCommitment;
314
+ }) => Effect.Effect<bigint, SolanaRpcError>;
315
+ /** `getBlockHeight`: the number of blocks below the head, lower than its slot as skipped slots hold no block. */
316
+ readonly getBlockHeight: (options: {
317
+ readonly commitment: SolanaCommitment;
318
+ }) => Effect.Effect<bigint, SolanaRpcError>;
319
+ /**
320
+ * `getSignatureStatuses` of at most 256 `signatures`, read from the blocks the node has processed, whatever their
321
+ * commitment. Without `searchTransactionHistory`, only the node's cache of recent slots is searched: an older
322
+ * transaction is `null`.
323
+ */
324
+ readonly getSignatureStatuses: (options: {
325
+ readonly signatures: ReadonlyArray<SolanaTransactionHash>;
326
+ readonly searchTransactionHistory?: boolean | undefined;
327
+ }) => Effect.Effect<SolanaSignatureStatuses, SolanaRpcError>;
328
+ /** `getBalance` at `finalized` commitment. */
329
+ readonly getBalance: (options: {
330
+ readonly address: SolanaAddress;
331
+ }) => Effect.Effect<SolanaBalance, SolanaRpcError>;
332
+ /** `getSignaturesForAddress`, one page. */
333
+ readonly getSignaturesForAddress: (query: SolanaSignaturesQuery) => Effect.Effect<ReadonlyArray<SolanaSignatureInfo>, SolanaRpcError>;
334
+ /**
335
+ * `getTransaction` in `encoding`, `base64` by default, versioned transactions included. A transaction the endpoint
336
+ * lacks fails `Pruned`.
337
+ */
338
+ readonly getTransaction: {
339
+ (options: SolanaTransactionQuery & {
340
+ readonly encoding?: "base64" | undefined;
341
+ }): Effect.Effect<SolanaTransactionInfo, SolanaRpcError>;
342
+ <Encoding extends SolanaTransactionEncoding>(options: SolanaTransactionQuery & {
343
+ readonly encoding: Encoding;
344
+ }): Effect.Effect<SolanaTransactionInfo<Encoding>, SolanaRpcError>;
345
+ };
346
+ /** `getLatestBlockhash` */
347
+ readonly getLatestBlockhash: (options: {
348
+ readonly commitment: SolanaCommitment;
349
+ }) => Effect.Effect<SolanaLatestBlockhash, SolanaRpcError>;
350
+ /**
351
+ * `simulateTransaction` of a base64 wire `transaction`, run against the bank at `commitment` without being sent. A
352
+ * transaction that would fail is a success whose `err` says why. `sigVerify` checks the signatures, and
353
+ * `replaceRecentBlockhash` swaps the blockhash for the latest one, which unsigned transactions need: the node
354
+ * refuses both together.
355
+ */
356
+ readonly simulateTransaction: (options: {
357
+ readonly transaction: string;
358
+ readonly commitment: SolanaCommitment;
359
+ readonly sigVerify?: boolean | undefined;
360
+ readonly replaceRecentBlockhash?: boolean | undefined;
361
+ }) => Effect.Effect<SolanaSimulation, SolanaRpcError>;
362
+ /**
363
+ * `getRecentPrioritizationFees` over the node's cache of recent slots (up to 150) for the transactions locking every
364
+ * one of `addresses` as writable, at most 128 of them. Without `addresses`, any transaction counts.
365
+ */
366
+ readonly getRecentPrioritizationFees: (options: {
367
+ readonly addresses: ReadonlyArray<SolanaAddress>;
368
+ }) => Effect.Effect<ReadonlyArray<SolanaPrioritizationFee>, SolanaRpcError>;
369
+ /**
370
+ * `sendTransaction`: submits a signed base64 wire `transaction` and returns its first signature. The node simulates
371
+ * it first at `preflightCommitment` (`finalized` by default) unless `skipPreflight`, then forwards it to the leader
372
+ * and rebroadcasts it `maxRetries` times, or until its blockhash expires when left out. A retry or a fallback sends
373
+ * the same bytes, so it never creates a second transaction, but a node that has processed them refuses the second
374
+ * copy. A refusal (a failed preflight, `BlockhashNotFound`, `AlreadyProcessed`...) is `Rejected`, with the node's
375
+ * message in `cause`.
376
+ */
377
+ readonly sendTransaction: (options: {
378
+ readonly transaction: string;
379
+ readonly skipPreflight?: boolean | undefined;
380
+ readonly preflightCommitment?: SolanaCommitment | undefined;
381
+ readonly maxRetries?: number | undefined;
382
+ }) => Effect.Effect<SolanaTransactionHash, SolanaRpcError>;
383
+ }>;
384
+ /**
385
+ * @since 0.1.0
386
+ * @category services
387
+ */
388
+ export declare class SolanaRpc extends SolanaRpc_base {
389
+ }
390
+ /**
391
+ * Builds a {@link SolanaRpc} over `endpoints`, tried in order, sending requests with the provided `HttpClient`
392
+ * (e.g. `FetchHttpClient.layer`). `timeout` (default 30 seconds) bounds each attempt, `retries` (default 3) and
393
+ * `retryDelay` (default 500 millis) set the backoff before falling back: see {@link JsonRpc.Unavailable}.
394
+ * `genesisHash` replaces the genesis hash of `network`, for a local validator or a private cluster, which have their
395
+ * own.
396
+ *
397
+ * @since 0.1.0
398
+ * @category layers
399
+ */
400
+ export declare const layer: (options: {
401
+ readonly network: SolanaNetwork;
402
+ readonly genesisHash?: SolanaGenesisHash | undefined;
403
+ readonly endpoints: Arr.NonEmptyReadonlyArray<SolanaRpcEndpoint>;
404
+ readonly timeout?: Duration.Input | undefined;
405
+ readonly retries?: number | undefined;
406
+ readonly retryDelay?: Duration.Input | undefined;
407
+ }) => Layer.Layer<SolanaRpc, never, HttpClient.HttpClient>;
408
+ /**
409
+ * Builds an {@link SolanaRpc} like {@link layer}, reading the options from `Config`. Endpoint URLs stay `Redacted`.
410
+ *
411
+ * @example
412
+ * ```ts
413
+ * import * as SolanaRpc from "@effect-blockchain/solana/SolanaRpc"
414
+ * import * as Config from "effect/Config"
415
+ *
416
+ * const RpcLive = SolanaRpc.layerConfig({
417
+ * network: Config.succeed("Solana"),
418
+ * endpoints: Config.all([Config.all({ name: Config.succeed("main"), url: Config.Redacted("SOLANA_RPC_URL") })])
419
+ * })
420
+ * ```
421
+ *
422
+ * @since 0.1.0
423
+ * @category layers
424
+ */
425
+ export declare const layerConfig: (options: Config.Wrap<Parameters<typeof layer>[0]>) => Layer.Layer<SolanaRpc, Config.ConfigError, HttpClient.HttpClient>;
426
+ export {};
427
+ //# sourceMappingURL=SolanaRpc.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"SolanaRpc.d.ts","sourceRoot":"","sources":["../src/SolanaRpc.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;GA0BG;AACH,OAAO,KAAK,OAAO,MAAM,iCAAiC,CAAA;AAc1D,OAAO,KAAK,KAAK,GAAG,MAAM,cAAc,CAAA;AACxC,OAAO,KAAK,MAAM,MAAM,eAAe,CAAA;AACvC,OAAO,KAAK,OAAO,MAAM,gBAAgB,CAAA;AACzC,OAAO,KAAK,KAAK,QAAQ,MAAM,iBAAiB,CAAA;AAChD,OAAO,KAAK,MAAM,MAAM,eAAe,CAAA;AACvC,OAAO,KAAK,KAAK,UAAU,MAAM,wBAAwB,CAAA;AACzD,OAAO,KAAK,KAAK,MAAM,cAAc,CAAA;AACrC,OAAO,KAAK,KAAK,QAAQ,MAAM,iBAAiB,CAAA;AAChD,OAAO,KAAK,MAAM,MAAM,eAAe,CAAA;AAGvC,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAA;AACvD,OAAO,EAAE,KAAK,iBAAiB,EAAE,KAAK,aAAa,EAAiB,MAAM,oBAAoB,CAAA;AAC9F,OAAO,KAAK,EAAE,qBAAqB,EAAE,MAAM,4BAA4B,CAAA;AAEvE;;;;;GAKG;AACH,MAAM,WAAW,iBAAiB;IAChC,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAA;IACrB,QAAQ,CAAC,GAAG,EAAE,QAAQ,CAAC,QAAQ,CAAC,MAAM,CAAC,CAAA;CACxC;;;;;;;;AAED;;;;;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C,SAAS,EAAE,KAAK,EAAE,UAAU,CAAC,UAAU,CAgHpD,CAAA;AAEH;;;;;;;;;;;;;;;;GAgBG;AACH,eAAO,MAAM,WAAW,YACb,MAAM,CAAC,IAAI,CAAC,UAAU,CAAC,OAAO,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC,KAChD,KAAK,CAAC,KAAK,CAAC,SAAS,EAAE,MAAM,CAAC,WAAW,EAAE,UAAU,CAAC,UAAU,CACV,CAAA"}
@@ -0,0 +1,216 @@
1
+ /**
2
+ * Typed Solana JSON-RPC methods over an ordered list of endpoints with fallback.
3
+ *
4
+ * A call starts at the first endpoint and moves to the next one on failure, except on `WrongNetwork`. Each endpoint
5
+ * is checked once to serve the configured network (`getGenesisHash`). Every method but `sendTransaction` is a read,
6
+ * so retries and fallback are safe; `sendTransaction` documents its own case. Methods are named after the JSON-RPC
7
+ * method. Every JSON integer in a reply is read as an exact `bigint`, so lamport amounts above 2^53 are never rounded.
8
+ *
9
+ * @example
10
+ * ```ts
11
+ * import type { SolanaAddress } from "@effect-blockchain/solana/SolanaAddress"
12
+ * import * as SolanaRpc from "@effect-blockchain/solana/SolanaRpc"
13
+ * import * as Effect from "effect/Effect"
14
+ *
15
+ * declare const address: SolanaAddress
16
+ *
17
+ * // the 10 latest finalized transactions touching `address`
18
+ * const latest = Effect.gen(function*() {
19
+ * const rpc = yield* SolanaRpc.SolanaRpc
20
+ * const signatures = yield* rpc.getSignaturesForAddress({ address, limit: 10, commitment: "finalized" })
21
+ * return yield* Effect.forEach(signatures, ({ signature }) =>
22
+ * rpc.getTransaction({ signature, commitment: "finalized" }))
23
+ * })
24
+ * ```
25
+ *
26
+ * @since 0.1.0
27
+ */
28
+ import * as JsonRpc from "@effect-blockchain/core/JsonRpc";
29
+ import { SOLANA_ERROR__JSON_RPC__INTERNAL_ERROR, SOLANA_ERROR__JSON_RPC__SERVER_ERROR_BLOCK_CLEANED_UP, SOLANA_ERROR__JSON_RPC__SERVER_ERROR_BLOCK_NOT_AVAILABLE, SOLANA_ERROR__JSON_RPC__SERVER_ERROR_BLOCK_STATUS_NOT_AVAILABLE_YET, SOLANA_ERROR__JSON_RPC__SERVER_ERROR_KEY_EXCLUDED_FROM_SECONDARY_INDEX, SOLANA_ERROR__JSON_RPC__SERVER_ERROR_LONG_TERM_STORAGE_SLOT_SKIPPED, SOLANA_ERROR__JSON_RPC__SERVER_ERROR_LONG_TERM_STORAGE_UNREACHABLE, SOLANA_ERROR__JSON_RPC__SERVER_ERROR_MIN_CONTEXT_SLOT_NOT_REACHED, SOLANA_ERROR__JSON_RPC__SERVER_ERROR_NODE_UNHEALTHY, SOLANA_ERROR__JSON_RPC__SERVER_ERROR_SLOT_SKIPPED, SOLANA_ERROR__JSON_RPC__SERVER_ERROR_TRANSACTION_HISTORY_NOT_AVAILABLE } from "@solana/kit";
30
+ import * as Config from "effect/Config";
31
+ import * as Context from "effect/Context";
32
+ import * as Effect from "effect/Effect";
33
+ import * as Layer from "effect/Layer";
34
+ import * as Schema from "effect/Schema";
35
+ import * as BigIntJson from "./internal/bigIntJson.js";
36
+ import * as RpcMethods from "./internal/rpcMethods.js";
37
+ import { toGenesisHash } from "./SolanaNetwork.js";
38
+ /**
39
+ * A failed call: its `reason` (a {@link JsonRpc.Reason}, matched with `Effect.catchReason`), the JSON-RPC error code or
40
+ * HTTP status as `code`, and a `cause` without the endpoint URL. After several endpoints, the error is the last one
41
+ * and `cause` is an `AggregateError` of each endpoint's error, in order.
42
+ *
43
+ * On Solana, `Unavailable` includes the codes 429, -32603, -32005 and -32019, `Lagging` a `minContextSlot` not reached
44
+ * or a block not available yet, and `Pruned` a cleaned-up or skipped slot or a `getTransaction` returning `null`.
45
+ *
46
+ * @since 0.1.0
47
+ * @category errors
48
+ */
49
+ export class SolanaRpcError extends /*#__PURE__*/Schema.TaggedError()("SolanaRpcError", {
50
+ reason: JsonRpc.Reason,
51
+ method: Schema.String,
52
+ endpoint: Schema.String,
53
+ code: /*#__PURE__*/Schema.optional(Schema.Number),
54
+ cause: /*#__PURE__*/Schema.Defect()
55
+ }) {
56
+ /**
57
+ * @since 0.1.0
58
+ */
59
+ get message() {
60
+ return `${this.method} failed on ${this.endpoint}: ${this.reason._tag}${this.code === undefined ? "" : ` (${this.code})`}`;
61
+ }
62
+ }
63
+ /**
64
+ * @since 0.1.0
65
+ * @category services
66
+ */
67
+ export class SolanaRpc extends /*#__PURE__*/Context.Service()("@effect-blockchain/solana/SolanaRpc") {}
68
+ // JSON-RPC codes from @solana/errors, any other code is `Rejected`
69
+ const codes = /*#__PURE__*/new Map([[429, "Unavailable"], [SOLANA_ERROR__JSON_RPC__INTERNAL_ERROR, "Unavailable"], [SOLANA_ERROR__JSON_RPC__SERVER_ERROR_NODE_UNHEALTHY, "Unavailable"], [SOLANA_ERROR__JSON_RPC__SERVER_ERROR_LONG_TERM_STORAGE_UNREACHABLE, "Unavailable"], [SOLANA_ERROR__JSON_RPC__SERVER_ERROR_MIN_CONTEXT_SLOT_NOT_REACHED, "Lagging"], [SOLANA_ERROR__JSON_RPC__SERVER_ERROR_BLOCK_NOT_AVAILABLE, "Lagging"], [SOLANA_ERROR__JSON_RPC__SERVER_ERROR_BLOCK_STATUS_NOT_AVAILABLE_YET, "Lagging"], [SOLANA_ERROR__JSON_RPC__SERVER_ERROR_BLOCK_CLEANED_UP, "Pruned"], [SOLANA_ERROR__JSON_RPC__SERVER_ERROR_SLOT_SKIPPED, "Pruned"], [SOLANA_ERROR__JSON_RPC__SERVER_ERROR_LONG_TERM_STORAGE_SLOT_SKIPPED, "Pruned"], [SOLANA_ERROR__JSON_RPC__SERVER_ERROR_TRANSACTION_HISTORY_NOT_AVAILABLE, "Pruned"], [SOLANA_ERROR__JSON_RPC__SERVER_ERROR_KEY_EXCLUDED_FROM_SECONDARY_INDEX, "Pruned"]]);
70
+ /**
71
+ * Builds a {@link SolanaRpc} over `endpoints`, tried in order, sending requests with the provided `HttpClient`
72
+ * (e.g. `FetchHttpClient.layer`). `timeout` (default 30 seconds) bounds each attempt, `retries` (default 3) and
73
+ * `retryDelay` (default 500 millis) set the backoff before falling back: see {@link JsonRpc.Unavailable}.
74
+ * `genesisHash` replaces the genesis hash of `network`, for a local validator or a private cluster, which have their
75
+ * own.
76
+ *
77
+ * @since 0.1.0
78
+ * @category layers
79
+ */
80
+ export const layer = options => Layer.effect(SolanaRpc, Effect.gen(function* () {
81
+ const {
82
+ network
83
+ } = options;
84
+ const expectedGenesisHash = options.genesisHash ?? toGenesisHash(network);
85
+ const rpc = yield* JsonRpc.make({
86
+ spanPrefix: "SolanaRpc",
87
+ network,
88
+ endpoints: options.endpoints,
89
+ timeout: options.timeout,
90
+ retries: options.retries,
91
+ retryDelay: options.retryDelay,
92
+ codes,
93
+ parseBody: BigIntJson.parse,
94
+ checkNetwork: (send, endpoint) => send(RpcMethods.getGenesisHash, []).pipe(Effect.flatMap(genesisHash => genesisHash === expectedGenesisHash ? Effect.succeed(expectedGenesisHash) : Effect.fail(new SolanaRpcError({
95
+ reason: new JsonRpc.WrongNetwork({
96
+ expected: expectedGenesisHash,
97
+ actual: genesisHash
98
+ }),
99
+ method: RpcMethods.getGenesisHash.name,
100
+ endpoint,
101
+ cause: new Error(`expected genesis hash ${expectedGenesisHash} for ${network}, got ${genesisHash}`)
102
+ })))),
103
+ makeError: fields => new SolanaRpcError(fields)
104
+ });
105
+ const getTransactionOn = (endpoint, {
106
+ commitment,
107
+ encoding,
108
+ signature
109
+ }) => rpc.call(endpoint, RpcMethods.getTransaction(encoding), [signature, {
110
+ commitment,
111
+ encoding,
112
+ maxSupportedTransactionVersion: 0
113
+ }]).pipe(Effect.flatMap(tx => tx === null ? Effect.fail(rpc.fail(endpoint, RpcMethods.getTransaction.name, new JsonRpc.Pruned(), new Error(`transaction ${signature} not found`))) : Effect.succeed(tx)));
114
+ function getTransaction({
115
+ encoding = "base64",
116
+ ...options
117
+ }) {
118
+ return rpc.withFallback(endpoint => getTransactionOn(endpoint, {
119
+ ...options,
120
+ encoding
121
+ }));
122
+ }
123
+ return SolanaRpc.of({
124
+ network,
125
+ getGenesisHash: rpc.withFallback(rpc.checkNetwork),
126
+ getSlot: ({
127
+ commitment
128
+ }) => rpc.withFallback(endpoint => rpc.call(endpoint, RpcMethods.getSlot, [{
129
+ commitment
130
+ }])),
131
+ getBlockHeight: ({
132
+ commitment
133
+ }) => rpc.withFallback(endpoint => rpc.call(endpoint, RpcMethods.getBlockHeight, [{
134
+ commitment
135
+ }])),
136
+ getSignatureStatuses: ({
137
+ signatures,
138
+ ...config
139
+ }) => rpc.withFallback(endpoint => rpc.call(endpoint, RpcMethods.getSignatureStatuses, [signatures, config]).pipe(Effect.map(({
140
+ context,
141
+ value
142
+ }) => ({
143
+ slot: context.slot,
144
+ value
145
+ })))),
146
+ getBalance: ({
147
+ address
148
+ }) => rpc.withFallback(endpoint => rpc.call(endpoint, RpcMethods.getBalance, [address, {
149
+ commitment: "finalized"
150
+ }]).pipe(Effect.map(({
151
+ context,
152
+ value
153
+ }) => ({
154
+ slot: context.slot,
155
+ value
156
+ })))),
157
+ getSignaturesForAddress: ({
158
+ address,
159
+ ...config
160
+ }) => rpc.withFallback(endpoint => rpc.call(endpoint, RpcMethods.getSignaturesForAddress, [address, config])),
161
+ getTransaction,
162
+ getLatestBlockhash: ({
163
+ commitment
164
+ }) => rpc.withFallback(endpoint => rpc.call(endpoint, RpcMethods.getLatestBlockhash, [{
165
+ commitment
166
+ }]).pipe(Effect.map(({
167
+ context,
168
+ value
169
+ }) => ({
170
+ slot: context.slot,
171
+ ...value
172
+ })))),
173
+ simulateTransaction: ({
174
+ transaction,
175
+ ...config
176
+ }) => rpc.withFallback(endpoint => rpc.call(endpoint, RpcMethods.simulateTransaction, [transaction, {
177
+ encoding: "base64",
178
+ ...config
179
+ }]).pipe(Effect.map(({
180
+ context,
181
+ value
182
+ }) => ({
183
+ slot: context.slot,
184
+ ...value
185
+ })))),
186
+ getRecentPrioritizationFees: ({
187
+ addresses
188
+ }) => rpc.withFallback(endpoint => rpc.call(endpoint, RpcMethods.getRecentPrioritizationFees, [addresses])),
189
+ sendTransaction: ({
190
+ transaction,
191
+ ...config
192
+ }) => rpc.withFallback(endpoint => rpc.call(endpoint, RpcMethods.sendTransaction, [transaction, {
193
+ encoding: "base64",
194
+ ...config
195
+ }]))
196
+ });
197
+ }));
198
+ /**
199
+ * Builds an {@link SolanaRpc} like {@link layer}, reading the options from `Config`. Endpoint URLs stay `Redacted`.
200
+ *
201
+ * @example
202
+ * ```ts
203
+ * import * as SolanaRpc from "@effect-blockchain/solana/SolanaRpc"
204
+ * import * as Config from "effect/Config"
205
+ *
206
+ * const RpcLive = SolanaRpc.layerConfig({
207
+ * network: Config.succeed("Solana"),
208
+ * endpoints: Config.all([Config.all({ name: Config.succeed("main"), url: Config.Redacted("SOLANA_RPC_URL") })])
209
+ * })
210
+ * ```
211
+ *
212
+ * @since 0.1.0
213
+ * @category layers
214
+ */
215
+ export const layerConfig = options => Layer.unwrap(Effect.map(Config.unwrap(options), layer));
216
+ //# sourceMappingURL=SolanaRpc.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"SolanaRpc.js","names":[],"sources":["../src/SolanaRpc.ts"],"sourcesContent":[null],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;AA2BA,OAAO,KAAK,OAAO,MAAM,iCAAiC;AAC1D,SACE,sCAAsC,EACtC,qDAAqD,EACrD,wDAAwD,EACxD,mEAAmE,EACnE,sEAAsE,EACtE,mEAAmE,EACnE,kEAAkE,EAClE,iEAAiE,EACjE,mDAAmD,EACnD,iDAAiD,EACjD,sEAAsE,QACjE,aAAa;AAEpB,OAAO,KAAK,MAAM,MAAM,eAAe;AACvC,OAAO,KAAK,OAAO,MAAM,gBAAgB;AAEzC,OAAO,KAAK,MAAM,MAAM,eAAe;AAEvC,OAAO,KAAK,KAAK,MAAM,cAAc;AAErC,OAAO,KAAK,MAAM,MAAM,eAAe;AACvC,OAAO,KAAK,UAAU,MAAM,0BAA0B;AACtD,OAAO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