@effect-blockchain/solana 0.0.0-stage → 0.1.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 (43) 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 +156 -0
  8. package/dist/SolanaIndexer.d.ts.map +1 -0
  9. package/dist/SolanaIndexer.js +227 -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/SolanaRpc.d.ts +258 -0
  16. package/dist/SolanaRpc.d.ts.map +1 -0
  17. package/dist/SolanaRpc.js +154 -0
  18. package/dist/SolanaRpc.js.map +1 -0
  19. package/dist/SolanaTransactionHash.d.ts +14 -0
  20. package/dist/SolanaTransactionHash.d.ts.map +1 -0
  21. package/dist/SolanaTransactionHash.js +34 -0
  22. package/dist/SolanaTransactionHash.js.map +1 -0
  23. package/dist/index.d.ts +24 -0
  24. package/dist/index.d.ts.map +1 -0
  25. package/dist/index.js +25 -0
  26. package/dist/index.js.map +1 -0
  27. package/dist/internal/bigIntJson.d.ts +2 -0
  28. package/dist/internal/bigIntJson.d.ts.map +1 -0
  29. package/dist/internal/bigIntJson.js +9 -0
  30. package/dist/internal/bigIntJson.js.map +1 -0
  31. package/dist/internal/rpcMethods.d.ts +2 -0
  32. package/dist/internal/rpcMethods.d.ts.map +1 -0
  33. package/dist/internal/rpcMethods.js +105 -0
  34. package/dist/internal/rpcMethods.js.map +1 -0
  35. package/package.json +66 -3
  36. package/src/SolanaAddress.ts +40 -0
  37. package/src/SolanaIndexer.ts +376 -0
  38. package/src/SolanaNetwork.ts +105 -0
  39. package/src/SolanaRpc.ts +387 -0
  40. package/src/SolanaTransactionHash.ts +41 -0
  41. package/src/index.ts +30 -0
  42. package/src/internal/bigIntJson.ts +18 -0
  43. package/src/internal/rpcMethods.ts +143 -0
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2025 Spiko
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md CHANGED
@@ -1,3 +1,13 @@
1
- # Temporary Holding Version
1
+ # `@effect-blockchain/solana`
2
2
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
3
+ Solana blockchain toolkit for Effect.
4
+
5
+ ## Installation
6
+
7
+ ```bash
8
+ pnpm add @effect-blockchain/solana effect @solana/kit
9
+ ```
10
+
11
+ ## License
12
+
13
+ MIT
@@ -0,0 +1,21 @@
1
+ import * as Schema from "effect/Schema";
2
+ /**
3
+ * A base58-encoded Solana address (32 bytes), validated with `@solana/kit`.
4
+ *
5
+ * @since 0.1.0
6
+ * @category schemas
7
+ */
8
+ export declare const SolanaAddress: Schema.brand<Schema.String, "SolanaAddress">;
9
+ /**
10
+ * @since 0.1.0
11
+ * @category models
12
+ */
13
+ export type SolanaAddress = typeof SolanaAddress.Type;
14
+ /**
15
+ * The Solana System Program address.
16
+ *
17
+ * @since 0.1.0
18
+ * @category constants
19
+ */
20
+ export declare const SYSTEM_PROGRAM_ADDRESS: SolanaAddress;
21
+ //# sourceMappingURL=SolanaAddress.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"SolanaAddress.d.ts","sourceRoot":"","sources":["../src/SolanaAddress.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,MAAM,MAAM,eAAe,CAAA;AAIvC;;;;;GAKG;AACH,eAAO,MAAM,aAAa,8CAWzB,CAAA;AAED;;;GAGG;AACH,MAAM,MAAM,aAAa,GAAG,OAAO,aAAa,CAAC,IAAI,CAAA;AAErD;;;;;GAKG;AACH,eAAO,MAAM,sBAAsB,EAAE,aAAsE,CAAA"}
@@ -0,0 +1,33 @@
1
+ /**
2
+ * @since 0.1.0
3
+ */
4
+ import { isAddress } from "@solana/kit";
5
+ import * as Schema from "effect/Schema";
6
+ const solanaAddressOf32BytesPattern = "^[2-9A-H][1-9A-HJ-NP-Za-km-z]{43}$";
7
+ /**
8
+ * A base58-encoded Solana address (32 bytes), validated with `@solana/kit`.
9
+ *
10
+ * @since 0.1.0
11
+ * @category schemas
12
+ */
13
+ export const SolanaAddress = /*#__PURE__*/Schema.String.annotate({
14
+ title: "Solana address",
15
+ description: "a valid Solana address, consisting of 32 to 44 base58 characters"
16
+ }).pipe(/*#__PURE__*/Schema.check(/*#__PURE__*/Schema.makeFilter(a => isAddress(a) || `${a} is not a valid Solana address`, {
17
+ arbitraryConstraint: {
18
+ patterns: [{
19
+ source: solanaAddressOf32BytesPattern,
20
+ flags: ""
21
+ }]
22
+ }
23
+ })), /*#__PURE__*/Schema.brand("SolanaAddress"), /*#__PURE__*/Schema.annotate({
24
+ identifier: "SolanaAddress"
25
+ }));
26
+ /**
27
+ * The Solana System Program address.
28
+ *
29
+ * @since 0.1.0
30
+ * @category constants
31
+ */
32
+ export const SYSTEM_PROGRAM_ADDRESS = /*#__PURE__*/SolanaAddress.make("11111111111111111111111111111111");
33
+ //# sourceMappingURL=SolanaAddress.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"SolanaAddress.js","names":[],"sources":["../src/SolanaAddress.ts"],"sourcesContent":[null],"mappings":"AAAA;;;AAGA,SAAS,SAAS,QAAQ,aAAa;AACvC,OAAO,KAAK,MAAM,MAAM,eAAe;AAEvC,MAAM,6BAA6B,GAAG,oCAAoC;AAE1E;;;;;;AAMA,OAAO,MAAM,aAAa,gBAAG,MAAM,CAAC,MAAM,CAAC,QAAQ,CAAC;EAClD,KAAK,EAAE,gBAAgB;EACvB,WAAW,EAAE;CACd,CAAC,CAAC,IAAI,cACL,MAAM,CAAC,KAAK,cACV,MAAM,CAAC,UAAU,CAAE,CAAS,IAAK,SAAS,CAAC,CAAC,CAAC,IAAI,GAAG,CAAC,gCAAgC,EAAE;EACrF,mBAAmB,EAAE;IAAE,QAAQ,EAAE,CAAC;MAAE,MAAM,EAAE,6BAA6B;MAAE,KAAK,EAAE;IAAE,CAAE;EAAC;CACxF,CAAC,CACH,eACD,MAAM,CAAC,KAAK,CAAC,eAAe,CAAC,eAC7B,MAAM,CAAC,QAAQ,CAAC;EAAE,UAAU,EAAE;AAAe,CAAE,CAAC,CACjD;AAQD;;;;;;AAMA,OAAO,MAAM,sBAAsB,gBAAkB,aAAa,CAAC,IAAI,CAAC,kCAAkC,CAAC","ignoreList":[]}
@@ -0,0 +1,156 @@
1
+ import * as Config from "effect/Config";
2
+ import * as Context from "effect/Context";
3
+ import * as Duration from "effect/Duration";
4
+ import * as Effect from "effect/Effect";
5
+ import * as Layer from "effect/Layer";
6
+ import * as Schedule from "effect/Schedule";
7
+ import type * as Schema from "effect/Schema";
8
+ import * as Stream from "effect/Stream";
9
+ import type { SolanaAddress } from "./SolanaAddress.ts";
10
+ import type { SolanaRpcError, SolanaTransactionEncoding, SolanaTransactionInfo } from "./SolanaRpc.ts";
11
+ import { SolanaRpc } from "./SolanaRpc.ts";
12
+ import type { SolanaTransactionHash } from "./SolanaTransactionHash.ts";
13
+ /**
14
+ * A transaction touching the indexed address, kept raw: the `getTransaction` result with its `signature` and the
15
+ * `err` listed by `getSignaturesForAddress` (raw JSON, `null` when it succeeded). Failed transactions are kept: they
16
+ * still paid their fee. `transaction` follows the requested encoding.
17
+ *
18
+ * @since 0.1.0
19
+ * @category models
20
+ */
21
+ export interface SolanaIndexedTransaction<Encoding extends SolanaTransactionEncoding = "base64"> extends SolanaTransactionInfo<Encoding> {
22
+ readonly signature: SolanaTransactionHash;
23
+ readonly err: Schema.Json;
24
+ }
25
+ /**
26
+ * A {@link SolanaIndexer} `fetchTransactions` filter: the address whose transactions are read, over the inclusive slot
27
+ * range `[fromBlock, toBlock]`.
28
+ *
29
+ * @since 0.1.0
30
+ * @category models
31
+ */
32
+ export interface SolanaIndexerFilter {
33
+ readonly address: SolanaAddress;
34
+ readonly fromBlock: bigint;
35
+ readonly toBlock: bigint;
36
+ }
37
+ /**
38
+ * The transactions of slots `[fromBlock, toBlock]` (both inclusive), in chain order, emitted by
39
+ * {@link SolanaIndexer.Service.streamTransactions}.
40
+ *
41
+ * A batch is emitted for every range, even without transactions. Delivery is at-least-once: save `batch.toBlock` once
42
+ * the batch is handled and resume from `toBlock + 1`. A batch holds at most `maxBatchSize` transactions, more when a
43
+ * single slot has more, as a slot is never split.
44
+ *
45
+ * @since 0.1.0
46
+ * @category models
47
+ */
48
+ export interface SolanaIndexerBatch<Encoding extends SolanaTransactionEncoding = "base64"> {
49
+ readonly fromBlock: bigint;
50
+ readonly toBlock: bigint;
51
+ readonly transactions: ReadonlyArray<SolanaIndexedTransaction<Encoding>>;
52
+ }
53
+ /**
54
+ * The {@link SolanaIndexer.Service.streamTransactions} options, `encoding` aside.
55
+ *
56
+ * @since 0.1.0
57
+ * @category models
58
+ */
59
+ export interface SolanaIndexerStreamOptions {
60
+ readonly filter: Omit<SolanaIndexerFilter, "fromBlock" | "toBlock">;
61
+ readonly fromBlock: bigint;
62
+ /** The stream ends after the batch reaching it, and is empty when `fromBlock > toBlock`. */
63
+ readonly toBlock?: bigint | undefined;
64
+ /**
65
+ * When to read the head again once caught up, `Schedule.spaced(DEFAULT_POLL_INTERVAL)` by default. It restarts after
66
+ * each batch, and its end ends the stream: `Schedule.recurs(0)` drains to the head and stops.
67
+ */
68
+ readonly poll?: Schedule.Schedule<unknown> | undefined;
69
+ /**
70
+ * Retries a step (the signature paging or one batch's transactions) failing with a transient reason
71
+ * ({@link JsonRpc.isTransient}) at the same position. Off by default.
72
+ */
73
+ readonly retry?: Schedule.Schedule<unknown, SolanaRpcError> | undefined;
74
+ }
75
+ declare const SolanaIndexer_base: Context.ServiceClass<SolanaIndexer, "@effect-blockchain/solana/SolanaIndexer", {
76
+ /** The `finalized` slot minus the confirmations, never below 0. */
77
+ readonly lastConfirmedBlock: Effect.Effect<bigint, SolanaRpcError>;
78
+ /**
79
+ * The transactions touching `address` in slots `fromBlock..toBlock` (both inclusive), in chain order. Empty when
80
+ * `fromBlock > toBlock`. `encoding` defaults to `base64`.
81
+ */
82
+ readonly fetchTransactions: {
83
+ (filter: SolanaIndexerFilter, options?: {
84
+ readonly encoding?: "base64" | undefined;
85
+ }): Effect.Effect<ReadonlyArray<SolanaIndexedTransaction>, SolanaRpcError>;
86
+ <Encoding extends SolanaTransactionEncoding>(filter: SolanaIndexerFilter, options: {
87
+ readonly encoding: Encoding;
88
+ }): Effect.Effect<ReadonlyArray<SolanaIndexedTransaction<Encoding>>, SolanaRpcError>;
89
+ };
90
+ /**
91
+ * The transactions touching `filter.address` from slot `fromBlock` on, in batches of at most `maxBatchSize`
92
+ * signatures, following the confirmed head. `encoding` defaults to `base64`.
93
+ */
94
+ readonly streamTransactions: {
95
+ (options: SolanaIndexerStreamOptions & {
96
+ readonly encoding?: "base64" | undefined;
97
+ }): Stream.Stream<SolanaIndexerBatch, SolanaRpcError>;
98
+ <Encoding extends SolanaTransactionEncoding>(options: SolanaIndexerStreamOptions & {
99
+ readonly encoding: Encoding;
100
+ }): Stream.Stream<SolanaIndexerBatch<Encoding>, SolanaRpcError>;
101
+ };
102
+ }>;
103
+ /**
104
+ * @since 0.1.0
105
+ * @category services
106
+ */
107
+ export declare class SolanaIndexer extends SolanaIndexer_base {
108
+ }
109
+ /**
110
+ * The default `maxBatchSize`: each signature costs one sequential `getTransaction`, so 100 keeps a batch to a few
111
+ * dozen seconds of calls and about 100 transactions in memory between two saved cursors.
112
+ *
113
+ * @since 0.1.0
114
+ * @category constants
115
+ */
116
+ export declare const DEFAULT_MAX_BATCH_SIZE = 100;
117
+ /**
118
+ * The default `poll` spacing of {@link SolanaIndexer.Service.streamTransactions}: 10 seconds.
119
+ *
120
+ * @since 0.1.0
121
+ * @category constants
122
+ */
123
+ export declare const DEFAULT_POLL_INTERVAL: Duration.Duration;
124
+ /**
125
+ * Builds a {@link SolanaIndexer} on the provided {@link SolanaRpc}.
126
+ *
127
+ * - `confirmations` defaults to {@link SolanaNetwork.defaultConfirmations} for the RPC's network.
128
+ * - `maxBatchSize`, a positive integer, the signatures per `streamTransactions` batch, defaults to
129
+ * {@link DEFAULT_MAX_BATCH_SIZE}.
130
+ *
131
+ * There is no `maxBlockRange`: `getSignaturesForAddress` takes no slot range to split.
132
+ *
133
+ * @since 0.1.0
134
+ * @category layers
135
+ */
136
+ export declare const layer: (options?: {
137
+ readonly confirmations?: number | undefined;
138
+ readonly maxBatchSize?: number | undefined;
139
+ }) => Layer.Layer<SolanaIndexer, never, SolanaRpc>;
140
+ /**
141
+ * Builds an {@link SolanaIndexer} like {@link layer}, reading the options from `Config`.
142
+ *
143
+ * @example
144
+ * ```ts
145
+ * import * as SolanaIndexer from "@effect-blockchain/solana/SolanaIndexer"
146
+ * import * as Config from "effect/Config"
147
+ *
148
+ * const IndexerLive = SolanaIndexer.layerConfig({ confirmations: Config.Int("SOLANA_CONFIRMATIONS") })
149
+ * ```
150
+ *
151
+ * @since 0.1.0
152
+ * @category layers
153
+ */
154
+ export declare const layerConfig: (options: Config.Wrap<NonNullable<Parameters<typeof layer>[0]>>) => Layer.Layer<SolanaIndexer, Config.ConfigError, SolanaRpc>;
155
+ export {};
156
+ //# sourceMappingURL=SolanaIndexer.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"SolanaIndexer.d.ts","sourceRoot":"","sources":["../src/SolanaIndexer.ts"],"names":[],"mappings":"AAoCA,OAAO,KAAK,MAAM,MAAM,eAAe,CAAA;AACvC,OAAO,KAAK,OAAO,MAAM,gBAAgB,CAAA;AACzC,OAAO,KAAK,QAAQ,MAAM,iBAAiB,CAAA;AAC3C,OAAO,KAAK,MAAM,MAAM,eAAe,CAAA;AACvC,OAAO,KAAK,KAAK,MAAM,cAAc,CAAA;AAErC,OAAO,KAAK,QAAQ,MAAM,iBAAiB,CAAA;AAC3C,OAAO,KAAK,KAAK,MAAM,MAAM,eAAe,CAAA;AAC5C,OAAO,KAAK,MAAM,MAAM,eAAe,CAAA;AACvC,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAA;AAEvD,OAAO,KAAK,EACV,cAAc,EAEd,yBAAyB,EACzB,qBAAqB,EACtB,MAAM,gBAAgB,CAAA;AACvB,OAAO,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAA;AAC1C,OAAO,KAAK,EAAE,qBAAqB,EAAE,MAAM,4BAA4B,CAAA;AAEvE;;;;;;;GAOG;AACH,MAAM,WAAW,wBAAwB,CAAC,QAAQ,SAAS,yBAAyB,GAAG,QAAQ,CAC7F,SAAQ,qBAAqB,CAAC,QAAQ,CAAC;IAEvC,QAAQ,CAAC,SAAS,EAAE,qBAAqB,CAAA;IACzC,QAAQ,CAAC,GA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O,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,KAC7D,KAAK,CAAC,KAAK,CAAC,aAAa,EAAE,MAAM,CAAC,WAAW,EAAE,SAAS,CAA4D,CAAA"}
@@ -0,0 +1,227 @@
1
+ /**
2
+ * Solana transaction indexing on top of {@link SolanaRpc}: the last confirmed slot, the transactions touching an
3
+ * address over a slot range, and a stream of them following the confirmed head. Blocks are slots.
4
+ *
5
+ * Everything is read at `finalized` commitment. `getSignaturesForAddress` has no slot range, so a range is paged from
6
+ * the head backwards until it passes `fromBlock`: the cost grows with the address's history since `fromBlock`, then
7
+ * each transaction costs one `getTransaction`. Each page sends `minContextSlot: toBlock`, so a lagging endpoint that
8
+ * honours it falls back. Any failure fails the whole call and nothing is returned: the caller retries the same range.
9
+ *
10
+ * @example
11
+ * ```ts
12
+ * import type { SolanaIndexerFilter } from "@effect-blockchain/solana/SolanaIndexer"
13
+ * import { SolanaIndexer } from "@effect-blockchain/solana/SolanaIndexer"
14
+ * import * as Effect from "effect/Effect"
15
+ * import * as Schedule from "effect/Schedule"
16
+ * import * as Stream from "effect/Stream"
17
+ *
18
+ * declare const filter: Omit<SolanaIndexerFilter, "fromBlock" | "toBlock">
19
+ * declare const cursor: bigint
20
+ * declare const save: (slot: bigint) => Effect.Effect<void>
21
+ *
22
+ * const program = Effect.gen(function*() {
23
+ * const indexer = yield* SolanaIndexer
24
+ * // once caught up, read the head after 1 s, 2 s, 4 s... at most every minute
25
+ * const poll = Schedule.min([Schedule.exponential("1 second"), Schedule.spaced("1 minute")])
26
+ * yield* indexer.streamTransactions({ filter, fromBlock: cursor + BigInt(1), poll }).pipe(
27
+ * Stream.runForEach((batch) => save(batch.toBlock))
28
+ * )
29
+ * })
30
+ * ```
31
+ *
32
+ * @since 0.1.0
33
+ */
34
+ import * as JsonRpc from "@effect-blockchain/core/JsonRpc";
35
+ import * as Arr from "effect/Array";
36
+ import * as BigInt_ from "effect/BigInt";
37
+ import * as Config from "effect/Config";
38
+ import * as Context from "effect/Context";
39
+ import * as Duration from "effect/Duration";
40
+ import * as Effect from "effect/Effect";
41
+ import * as Layer from "effect/Layer";
42
+ import * as Option from "effect/Option";
43
+ import * as Schedule from "effect/Schedule";
44
+ import * as Stream from "effect/Stream";
45
+ import * as SolanaNetwork from "./SolanaNetwork.js";
46
+ import { SolanaRpc } from "./SolanaRpc.js";
47
+ /**
48
+ * @since 0.1.0
49
+ * @category services
50
+ */
51
+ export class SolanaIndexer extends /*#__PURE__*/Context.Service()("@effect-blockchain/solana/SolanaIndexer") {}
52
+ // the node's maximum `limit`
53
+ const PAGE_SIZE = 1000;
54
+ const COMMITMENT = "finalized";
55
+ /**
56
+ * The default `maxBatchSize`: each signature costs one sequential `getTransaction`, so 100 keeps a batch to a few
57
+ * dozen seconds of calls and about 100 transactions in memory between two saved cursors.
58
+ *
59
+ * @since 0.1.0
60
+ * @category constants
61
+ */
62
+ export const DEFAULT_MAX_BATCH_SIZE = 100;
63
+ /**
64
+ * The default `poll` spacing of {@link SolanaIndexer.Service.streamTransactions}: 10 seconds.
65
+ *
66
+ * @since 0.1.0
67
+ * @category constants
68
+ */
69
+ export const DEFAULT_POLL_INTERVAL = /*#__PURE__*/Duration.seconds(10);
70
+ // consecutive groups of at most `max` signatures, a slot never split: a full group still takes its last slot's others
71
+ const groupBySlot = (signatures, max) => {
72
+ const groups = [];
73
+ for (const info of signatures) {
74
+ const last = groups.at(-1);
75
+ if (last !== undefined && (last.length < max || Arr.lastNonEmpty(last).slot === info.slot)) last.push(info);else groups.push([info]);
76
+ }
77
+ return groups;
78
+ };
79
+ /**
80
+ * Builds a {@link SolanaIndexer} on the provided {@link SolanaRpc}.
81
+ *
82
+ * - `confirmations` defaults to {@link SolanaNetwork.defaultConfirmations} for the RPC's network.
83
+ * - `maxBatchSize`, a positive integer, the signatures per `streamTransactions` batch, defaults to
84
+ * {@link DEFAULT_MAX_BATCH_SIZE}.
85
+ *
86
+ * There is no `maxBlockRange`: `getSignaturesForAddress` takes no slot range to split.
87
+ *
88
+ * @since 0.1.0
89
+ * @category layers
90
+ */
91
+ export const layer = (options = {}) => Layer.effect(SolanaIndexer, Effect.gen(function* () {
92
+ const rpc = yield* SolanaRpc;
93
+ const maxBatchSize = options.maxBatchSize ?? DEFAULT_MAX_BATCH_SIZE;
94
+ if (!Number.isSafeInteger(maxBatchSize) || maxBatchSize < 1) {
95
+ return yield* Effect.die(new RangeError(`maxBatchSize must be a positive integer, got ${maxBatchSize}`));
96
+ }
97
+ const confirmations = BigInt(options.confirmations ?? SolanaNetwork.defaultConfirmations(rpc.network));
98
+ const lastConfirmedBlock = rpc.getSlot({
99
+ commitment: COMMITMENT
100
+ }).pipe(Effect.map(slot => BigInt_.max(slot - confirmations, BigInt(0))), Effect.withSpan("SolanaIndexer.lastConfirmedBlock"));
101
+ // the signatures of `[fromBlock, toBlock]` in chain order, paged from the head back to the first short page or
102
+ // the first page reaching below `fromBlock`
103
+ const fetchSignatures = filter => Stream.paginate(Option.none(), before => rpc.getSignaturesForAddress({
104
+ address: filter.address,
105
+ before: Option.getOrUndefined(before),
106
+ limit: PAGE_SIZE,
107
+ commitment: COMMITMENT,
108
+ minContextSlot: filter.toBlock
109
+ }).pipe(Effect.map(page => {
110
+ const last = page.at(-1);
111
+ return [page, last === undefined || page.length < PAGE_SIZE || last.slot < filter.fromBlock ? Option.none() : Option.some(Option.some(last.signature))];
112
+ }))).pipe(Stream.runCollect,
113
+ // newest first, so reversed slots ascend. The order within a slot is undocumented: reversing it is a best
114
+ // guess at execution order (`transactionIndex`, which some providers add, is not in the RPC model)
115
+ Effect.map(signatures => Arr.reverse(Arr.filter(signatures, ({
116
+ slot
117
+ }) => slot >= filter.fromBlock && slot <= filter.toBlock))));
118
+ const fetchEach = (signatures, encoding) => Effect.forEach(signatures, ({
119
+ err,
120
+ signature
121
+ }) => rpc.getTransaction({
122
+ signature,
123
+ commitment: COMMITMENT,
124
+ encoding
125
+ }).pipe(Effect.map(tx => ({
126
+ signature,
127
+ err,
128
+ ...tx
129
+ }))));
130
+ const fetchRange = Effect.fn("SolanaIndexer.fetchTransactions")(function* (filter, encoding) {
131
+ if (filter.fromBlock > filter.toBlock) {
132
+ return [];
133
+ }
134
+ return yield* fetchEach(yield* fetchSignatures(filter), encoding);
135
+ });
136
+ function fetchTransactions(filter, {
137
+ encoding = "base64"
138
+ } = {}) {
139
+ return fetchRange(filter, encoding);
140
+ }
141
+ function streamTransactions(options) {
142
+ const {
143
+ encoding = "base64",
144
+ filter,
145
+ fromBlock,
146
+ retry,
147
+ toBlock
148
+ } = options;
149
+ const poll = options.poll ?? Schedule.spaced(DEFAULT_POLL_INTERVAL);
150
+ if (toBlock !== undefined && fromBlock > toBlock) {
151
+ return Stream.empty;
152
+ }
153
+ const after = (end, cap, groups) => end === toBlock ? Option.none() : Option.some({
154
+ next: end + BigInt(1),
155
+ cap,
156
+ groups
157
+ });
158
+ // one step: the transactions of the next pending group, else the signatures up to the polled confirmed head
159
+ const step = position => {
160
+ const {
161
+ cap,
162
+ groups,
163
+ next
164
+ } = position;
165
+ if (Arr.isReadonlyArrayNonEmpty(groups)) {
166
+ const [group, ...rest] = groups;
167
+ const end = rest.length === 0 ? cap : Arr.lastNonEmpty(group).slot;
168
+ return fetchEach(group, encoding).pipe(Effect.map(transactions => [[{
169
+ fromBlock: next,
170
+ toBlock: end,
171
+ transactions
172
+ }], after(end, cap, rest)]), Effect.withSpan("SolanaIndexer.streamTransactions.fetchGroup"));
173
+ }
174
+ return lastConfirmedBlock.pipe(Effect.repeat({
175
+ schedule: poll,
176
+ until: confirmed => confirmed >= next
177
+ }), Effect.flatMap(confirmed => {
178
+ const end = toBlock === undefined ? confirmed : BigInt_.min(confirmed, toBlock);
179
+ if (next > end) {
180
+ return Effect.succeed([[], Option.none()]);
181
+ }
182
+ return fetchSignatures({
183
+ address: filter.address,
184
+ fromBlock: next,
185
+ toBlock: end
186
+ }).pipe(Effect.map(signatures => Arr.isReadonlyArrayNonEmpty(signatures) ? [[], Option.some({
187
+ next,
188
+ cap: end,
189
+ groups: groupBySlot(signatures, maxBatchSize)
190
+ })] : [[{
191
+ fromBlock: next,
192
+ toBlock: end,
193
+ transactions: []
194
+ }], after(end, end, [])]), Effect.withSpan("SolanaIndexer.streamTransactions.fetchSignatures"));
195
+ }));
196
+ };
197
+ return Stream.paginate({
198
+ next: fromBlock,
199
+ cap: fromBlock,
200
+ groups: []
201
+ }, retry === undefined ? step : position => Effect.retry(step(position), {
202
+ schedule: retry,
203
+ while: error => JsonRpc.isTransient(error.reason)
204
+ }));
205
+ }
206
+ return SolanaIndexer.of({
207
+ lastConfirmedBlock,
208
+ fetchTransactions,
209
+ streamTransactions
210
+ });
211
+ }));
212
+ /**
213
+ * Builds an {@link SolanaIndexer} like {@link layer}, reading the options from `Config`.
214
+ *
215
+ * @example
216
+ * ```ts
217
+ * import * as SolanaIndexer from "@effect-blockchain/solana/SolanaIndexer"
218
+ * import * as Config from "effect/Config"
219
+ *
220
+ * const IndexerLive = SolanaIndexer.layerConfig({ confirmations: Config.Int("SOLANA_CONFIRMATIONS") })
221
+ * ```
222
+ *
223
+ * @since 0.1.0
224
+ * @category layers
225
+ */
226
+ export const layerConfig = options => Layer.unwrap(Effect.map(Config.unwrap(options), layer));
227
+ //# sourceMappingURL=SolanaIndexer.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"SolanaIndexer.js","names":[],"sources":["../src/SolanaIndexer.ts"],"sourcesContent":[null],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAiCA,OAAO,KAAK,OAAO,MAAM,iCAAiC;AAC1D,OAAO,KAAK,GAAG,MAAM,cAAc;AACnC,OAAO,KAAK,OAAO,MAAM,eAAe;AACxC,OAAO,KAAK,MAAM,MAAM,eAAe;AACvC,OAAO,KAAK,OAAO,MAAM,gBAAgB;AACzC,OAAO,KAAK,QAAQ,MAAM,iBAAiB;AAC3C,OAAO,KAAK,MAAM,MAAM,eAAe;AACvC,OAAO,KAAK,KAAK,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O,aAAa,CAAC,EAAE,CAAC;IAAE,kBAAkB;IAAE,iBAAiB;IAAE;EAAkB,CAAE,CAAC;AACxF,CAAC,CAAC,CACH;AAEH;;;;;;;;;;;;;;AAcA,OAAO,MAAM,WAAW,GACtB,OAA8D,IACA,KAAK,CAAC,MAAM,CAAC,MAAM,CAAC,GAAG,CAAC,MAAM,CAAC,MAAM,CAAC,OAAO,CAAC,EAAE,KAAK,CAAC,CAAC","ignoreList":[]}
@@ -0,0 +1,64 @@
1
+ import * as Schema from "effect/Schema";
2
+ /**
3
+ * @since 0.1.0
4
+ * @category constants
5
+ */
6
+ export declare const mainnets: readonly ["Solana"];
7
+ /**
8
+ * @since 0.1.0
9
+ * @category constants
10
+ */
11
+ export declare const testnets: readonly ["SolanaDevnet", "SolanaTestnet"];
12
+ /**
13
+ * Every supported network, mainnets first.
14
+ *
15
+ * @since 0.1.0
16
+ * @category constants
17
+ */
18
+ export declare const networks: readonly ["Solana", "SolanaDevnet", "SolanaTestnet"];
19
+ /**
20
+ * A named Solana cluster.
21
+ *
22
+ * @since 0.1.0
23
+ * @category schemas
24
+ */
25
+ export declare const SolanaNetwork: Schema.Literals<readonly ["Solana", "SolanaDevnet", "SolanaTestnet"]>;
26
+ /**
27
+ * @since 0.1.0
28
+ * @category models
29
+ */
30
+ export type SolanaNetwork = typeof SolanaNetwork.Type;
31
+ /**
32
+ * A Solana genesis hash: a base58-encoded 32-byte hash, validated with `@solana/kit`.
33
+ *
34
+ * @since 0.1.0
35
+ * @category schemas
36
+ */
37
+ export declare const SolanaGenesisHash: Schema.brand<Schema.String, "SolanaGenesisHash">;
38
+ /**
39
+ * @since 0.1.0
40
+ * @category models
41
+ */
42
+ export type SolanaGenesisHash = typeof SolanaGenesisHash.Type;
43
+ /**
44
+ * The cluster's genesis hash, reported by `getGenesisHash`.
45
+ *
46
+ * @since 0.1.0
47
+ * @category conversions
48
+ */
49
+ export declare const toGenesisHash: (network: SolanaNetwork) => SolanaGenesisHash;
50
+ /**
51
+ * @since 0.1.0
52
+ * @category predicates
53
+ */
54
+ export declare const isTestnet: (network: SolanaNetwork) => boolean;
55
+ /**
56
+ * Default number of slots `SolanaIndexer` stays behind the head: 0 on every network. The indexer reads at `finalized`
57
+ * commitment, and a block is finalized once 31+ confirmed blocks are built on top of it
58
+ * (https://docs.anza.xyz/consensus/commitments), so the finalized slot needs no further margin.
59
+ *
60
+ * @since 0.1.0
61
+ * @category getters
62
+ */
63
+ export declare const defaultConfirmations: (_network: SolanaNetwork) => number;
64
+ //# sourceMappingURL=SolanaNetwork.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"SolanaNetwork.d.ts","sourceRoot":"","sources":["../src/SolanaNetwork.ts"],"names":[],"mappings":"AAMA,OAAO,KAAK,MAAM,MAAM,eAAe,CAAA;AAEvC;;;GAGG;AACH,eAAO,MAAM,QAAQ,YAAI,QAAQ,CAAU,CAAA;AAE3C;;;GAGG;AACH,eAAO,MAAM,QAAQ,YAAI,cAAc,EAAE,eAAe,CAAU,CAAA;AAElE;;;;;GAKG;AACH,eAAO,MAAM,QAAQ,sDAAsC,CAAA;AAE3D;;;;;GAKG;AACH,eAAO,MAAM,aAAa,uEAIxB,CAAA;AAEF;;;GAGG;AACH,MAAM,MAAM,aAAa,GAAG,OAAO,aAAa,CAAC,IAAI,CAAA;AAKrD;;;;;GAKG;AACH,eAAO,MAAM,iBAAiB,kDAW7B,CAAA;AAED;;;GAGG;AACH,MAAM,MAAM,iBAAiB,GAAG,OAAO,iBAAiB,CAAC,IAAI,CAAA;AAS7D;;;;;GAKG;AACH,eAAO,MAAM,aAAa,YAAa,aAAa,KAAG,iBAA2C,CAAA;AAElG;;;GAGG;AACH,eAAO,MAAM,SAAS,YAAa,aAAa,KAAG,OACW,CAAA;AAE9D;;;;;;;GAOG;AACH,eAAO,MAAM,oBAAoB,aAAc,aAAa,KAAG,MAAW,CAAA"}
@@ -0,0 +1,84 @@
1
+ /**
2
+ * Named Solana clusters and their genesis hashes.
3
+ *
4
+ * @since 0.1.0
5
+ */
6
+ import { isBlockhash } from "@solana/kit";
7
+ import * as Schema from "effect/Schema";
8
+ /**
9
+ * @since 0.1.0
10
+ * @category constants
11
+ */
12
+ export const mainnets = ["Solana"];
13
+ /**
14
+ * @since 0.1.0
15
+ * @category constants
16
+ */
17
+ export const testnets = ["SolanaDevnet", "SolanaTestnet"];
18
+ /**
19
+ * Every supported network, mainnets first.
20
+ *
21
+ * @since 0.1.0
22
+ * @category constants
23
+ */
24
+ export const networks = [...mainnets, ...testnets];
25
+ /**
26
+ * A named Solana cluster.
27
+ *
28
+ * @since 0.1.0
29
+ * @category schemas
30
+ */
31
+ export const SolanaNetwork = /*#__PURE__*/Schema.Literals(networks).annotate({
32
+ identifier: "SolanaNetwork",
33
+ title: "Solana network",
34
+ description: "a named Solana cluster: Solana (mainnet-beta), SolanaDevnet or SolanaTestnet"
35
+ });
36
+ // like `SolanaAddress`: always 32 bytes once decoded
37
+ const solanaGenesisHashPattern = "^[2-9A-H][1-9A-HJ-NP-Za-km-z]{43}$";
38
+ /**
39
+ * A Solana genesis hash: a base58-encoded 32-byte hash, validated with `@solana/kit`.
40
+ *
41
+ * @since 0.1.0
42
+ * @category schemas
43
+ */
44
+ export const SolanaGenesisHash = /*#__PURE__*/Schema.String.annotate({
45
+ title: "Solana genesis hash",
46
+ description: "a valid Solana genesis hash (base58-encoded 32-byte hash)"
47
+ }).pipe(/*#__PURE__*/Schema.check(/*#__PURE__*/Schema.makeFilter(s => isBlockhash(s) || `${s} is not a valid Solana genesis hash`, {
48
+ arbitraryConstraint: {
49
+ patterns: [{
50
+ source: solanaGenesisHashPattern,
51
+ flags: ""
52
+ }]
53
+ }
54
+ })), /*#__PURE__*/Schema.brand("SolanaGenesisHash"), /*#__PURE__*/Schema.annotate({
55
+ identifier: "SolanaGenesisHash"
56
+ }));
57
+ // `--expected-genesis-hash` of each cluster, https://docs.anza.xyz/clusters/available
58
+ const genesisHashes = {
59
+ Solana: /*#__PURE__*/SolanaGenesisHash.make("5eykt4UsFv8P8NJdTREpY1vzqKqZKvdpKuc147dw2N9d"),
60
+ SolanaDevnet: /*#__PURE__*/SolanaGenesisHash.make("EtWTRABZaYq6iMfeYKouRu166VU2xqa1wcaWoxPkrZBG"),
61
+ SolanaTestnet: /*#__PURE__*/SolanaGenesisHash.make("4uhcVJyU9pJkvQyS88uRDiswHXSCkY3zQawwpjk2NsNY")
62
+ };
63
+ /**
64
+ * The cluster's genesis hash, reported by `getGenesisHash`.
65
+ *
66
+ * @since 0.1.0
67
+ * @category conversions
68
+ */
69
+ export const toGenesisHash = network => genesisHashes[network];
70
+ /**
71
+ * @since 0.1.0
72
+ * @category predicates
73
+ */
74
+ export const isTestnet = network => testnets.includes(network);
75
+ /**
76
+ * Default number of slots `SolanaIndexer` stays behind the head: 0 on every network. The indexer reads at `finalized`
77
+ * commitment, and a block is finalized once 31+ confirmed blocks are built on top of it
78
+ * (https://docs.anza.xyz/consensus/commitments), so the finalized slot needs no further margin.
79
+ *
80
+ * @since 0.1.0
81
+ * @category getters
82
+ */
83
+ export const defaultConfirmations = _network => 0;
84
+ //# sourceMappingURL=SolanaNetwork.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"SolanaNetwork.js","names":[],"sources":["../src/SolanaNetwork.ts"],"sourcesContent":[null],"mappings":"AAAA;;;;;AAKA,SAAS,WAAW,QAAQ,aAAa;AACzC,OAAO,KAAK,MAAM,MAAM,eAAe;AAEvC;;;;AAIA,OAAO,MAAM,QAAQ,GAAG,CAAC,QAAQ,CAAU;AAE3C;;;;AAIA,OAAO,MAAM,QAAQ,GAAG,CAAC,cAAc,EAAE,eAAe,CAAU;AAElE;;;;;;AAMA,OAAO,MAAM,QAAQ,GAAG,CAAC,GAAG,QAAQ,EAAE,GAAG,QAAQ,CAAU;AAE3D;;;;;;AAMA,OAAO,MAAM,aAAa,gBAAG,MAAM,CAAC,QAAQ,CAAC,QAAQ,CAAC,CAAC,QAAQ,CAAC;EAC9D,UAAU,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