@lifi/sdk-provider-solana 4.2.2 → 4.3.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 (46) hide show
  1. package/CHANGELOG.md +19 -0
  2. package/dist/cjs/actions/getSolanaBalance.js +3 -3
  3. package/dist/cjs/actions/getSolanaBalance.js.map +1 -1
  4. package/dist/cjs/actions/sendAndConfirmBundle.d.ts +5 -0
  5. package/dist/cjs/actions/sendAndConfirmBundle.js +38 -3
  6. package/dist/cjs/actions/sendAndConfirmBundle.js.map +1 -1
  7. package/dist/cjs/actions/sendAndConfirmTransaction.d.ts +3 -0
  8. package/dist/cjs/actions/sendAndConfirmTransaction.js +56 -10
  9. package/dist/cjs/actions/sendAndConfirmTransaction.js.map +1 -1
  10. package/dist/cjs/confirmation/confirmSignature.d.ts +2 -0
  11. package/dist/cjs/confirmation/confirmSignature.js +2 -0
  12. package/dist/cjs/confirmation/confirmSignature.js.map +1 -1
  13. package/dist/cjs/rpc/registry.d.ts +20 -0
  14. package/dist/cjs/rpc/registry.js +54 -11
  15. package/dist/cjs/rpc/registry.js.map +1 -1
  16. package/dist/cjs/version.d.ts +1 -1
  17. package/dist/cjs/version.js +1 -1
  18. package/dist/cjs/version.js.map +1 -1
  19. package/dist/esm/actions/getSolanaBalance.js +3 -3
  20. package/dist/esm/actions/getSolanaBalance.js.map +1 -1
  21. package/dist/esm/actions/sendAndConfirmBundle.d.ts +5 -0
  22. package/dist/esm/actions/sendAndConfirmBundle.d.ts.map +1 -1
  23. package/dist/esm/actions/sendAndConfirmBundle.js +40 -5
  24. package/dist/esm/actions/sendAndConfirmBundle.js.map +1 -1
  25. package/dist/esm/actions/sendAndConfirmTransaction.d.ts +3 -0
  26. package/dist/esm/actions/sendAndConfirmTransaction.d.ts.map +1 -1
  27. package/dist/esm/actions/sendAndConfirmTransaction.js +58 -12
  28. package/dist/esm/actions/sendAndConfirmTransaction.js.map +1 -1
  29. package/dist/esm/confirmation/confirmSignature.d.ts +2 -0
  30. package/dist/esm/confirmation/confirmSignature.d.ts.map +1 -1
  31. package/dist/esm/confirmation/confirmSignature.js +2 -1
  32. package/dist/esm/confirmation/confirmSignature.js.map +1 -1
  33. package/dist/esm/rpc/registry.d.ts +20 -0
  34. package/dist/esm/rpc/registry.d.ts.map +1 -1
  35. package/dist/esm/rpc/registry.js +53 -12
  36. package/dist/esm/rpc/registry.js.map +1 -1
  37. package/dist/esm/version.d.ts +1 -1
  38. package/dist/esm/version.js +1 -1
  39. package/dist/esm/version.js.map +1 -1
  40. package/package.json +2 -2
  41. package/src/actions/getSolanaBalance.ts +3 -3
  42. package/src/actions/sendAndConfirmBundle.ts +85 -5
  43. package/src/actions/sendAndConfirmTransaction.ts +108 -18
  44. package/src/confirmation/confirmSignature.ts +2 -1
  45. package/src/rpc/registry.ts +66 -21
  46. package/src/version.ts +1 -1
@@ -3,8 +3,10 @@ import { createSolanaRpc } from '@solana/kit'
3
3
  import { createJitoRpc } from './jito/createJitoRpc.js'
4
4
  import type { JitoRpcType, SolanaRpcType } from './types.js'
5
5
 
6
- const solanaRpcs = new LruMap<SolanaRpcType>(12)
7
- const jitoRpcs = new LruMap<JitoRpcType>(12)
6
+ // Read, write and bundle URLs share these caches, so they hold more than one
7
+ // list's worth: an entry evicted mid-use is probed or built again.
8
+ const solanaRpcs = new LruMap<SolanaRpcType>(64)
9
+ const jitoRpcs = new LruMap<JitoRpcType>(64)
8
10
 
9
11
  /**
10
12
  * A well-formed but non-existent Jito bundle id used solely to probe RPC
@@ -52,7 +54,7 @@ type JitoProbeRecord = JitoProbeResult & { at: number }
52
54
  * set never shrinks, and every bundle submission re-probes every non-Jito
53
55
  * endpoint at up to `PROBE_TIMEOUT_MS` each, on the latency path before
54
56
  * submission can start. */
55
- const jitoProbes = new LruMap<JitoProbeRecord>(12)
57
+ const jitoProbes = new LruMap<JitoProbeRecord>(64)
56
58
 
57
59
  /** One rule for every outcome: a record is fresh until its own window closes.
58
60
  * `Infinity` covers the answers that cannot change. */
@@ -146,27 +148,36 @@ export const probeJitoRpc = async (
146
148
  */
147
149
  const ensureSolanaRpcs = async (client: SDKClient): Promise<string[]> => {
148
150
  const rpcUrls = await client.getRpcUrlsByChainId(ChainId.SOL)
151
+ ensureSolanaRpcsFor(rpcUrls)
152
+ return rpcUrls
153
+ }
154
+
155
+ /** Creates and caches a client for each URL that has none yet. */
156
+ const ensureSolanaRpcsFor = (rpcUrls: string[]): void => {
149
157
  for (const rpcUrl of rpcUrls) {
150
158
  if (!solanaRpcs.has(rpcUrl)) {
151
159
  solanaRpcs.set(rpcUrl, createSolanaRpc(rpcUrl))
152
160
  }
153
161
  }
154
- return rpcUrls
155
162
  }
156
163
 
164
+ const cachedSolanaRpcs = (rpcUrls: string[]): SolanaRpcType[] =>
165
+ rpcUrls
166
+ .map((rpcUrl) => solanaRpcs.get(rpcUrl))
167
+ .filter((rpc): rpc is SolanaRpcType => Boolean(rpc))
168
+
157
169
  /**
158
- * Initializes and caches Jito RPCs for every configured Solana RPC URL.
170
+ * Probes each URL for Jito support and caches a client for every supported
171
+ * one. The configured RPCs and the write RPCs share this cache.
159
172
  *
160
173
  * Every probe outcome is cached, so a non-Jito endpoint is probed once rather
161
174
  * than once per bundle submission. Each record carries its own retry window:
162
175
  * see `JITO_PROBE_RETRY_MS` and `JITO_PROBE_GATEWAY_RETRY_MS` for the two that
163
176
  * expire.
164
- * @param client - The SDK client used to fetch RPC URLs.
177
+ * @param rpcUrls - The URLs to probe.
178
+ * @returns - How many of the URLs are currently unreachable.
165
179
  */
166
- const ensureJitoRpcs = async (
167
- client: SDKClient
168
- ): Promise<{ rpcUrls: string[]; unreachable: number }> => {
169
- const rpcUrls = await client.getRpcUrlsByChainId(ChainId.SOL)
180
+ const ensureJitoRpcsFor = async (rpcUrls: string[]): Promise<number> => {
170
181
  // Probed in parallel: serially, one slow endpoint delayed every URL behind
171
182
  // it before submission could start.
172
183
  const unprobed = rpcUrls.filter(
@@ -210,13 +221,28 @@ const ensureJitoRpcs = async (
210
221
  // `unreachable` still has to reach `sendAndConfirmBundle`, which uses the
211
222
  // count to choose between "retry, likely temporary" and "supply a
212
223
  // Jito-capable URL".
213
- const unreachable = rpcUrls.filter(
224
+ return rpcUrls.filter(
214
225
  (rpcUrl) => jitoProbes.get(rpcUrl)?.outcome === 'unreachable'
215
226
  ).length
227
+ }
216
228
 
229
+ /**
230
+ * Initializes and caches Jito RPCs for every configured Solana RPC URL.
231
+ * @param client - The SDK client used to fetch RPC URLs.
232
+ */
233
+ const ensureJitoRpcs = async (
234
+ client: SDKClient
235
+ ): Promise<{ rpcUrls: string[]; unreachable: number }> => {
236
+ const rpcUrls = await client.getRpcUrlsByChainId(ChainId.SOL)
237
+ const unreachable = await ensureJitoRpcsFor(rpcUrls)
217
238
  return { rpcUrls, unreachable }
218
239
  }
219
240
 
241
+ const cachedJitoRpcs = (rpcUrls: string[]): JitoRpcType[] =>
242
+ rpcUrls
243
+ .map((rpcUrl) => jitoRpcs.get(rpcUrl))
244
+ .filter((rpc): rpc is JitoRpcType => Boolean(rpc))
245
+
220
246
  /**
221
247
  * Wrapper around getting the Solana RPCs
222
248
  * @returns - Solana RPCs
@@ -224,10 +250,19 @@ const ensureJitoRpcs = async (
224
250
  export const getSolanaRpcs = async (
225
251
  client: SDKClient
226
252
  ): Promise<SolanaRpcType[]> => {
227
- const rpcUrls = await ensureSolanaRpcs(client)
228
- return rpcUrls
229
- .map((rpcUrl) => solanaRpcs.get(rpcUrl))
230
- .filter((rpc): rpc is SolanaRpcType => Boolean(rpc))
253
+ return cachedSolanaRpcs(await ensureSolanaRpcs(client))
254
+ }
255
+
256
+ /**
257
+ * Clients for the write RPCs (`rpcUrls[ChainId.SOL].write`). They only
258
+ * send transactions; the one read they get is the Jito probe in
259
+ * `getJitoCapableRpcs`.
260
+ * @param rpcUrls - The write RPC URLs.
261
+ * @returns - Solana RPCs to send transactions through.
262
+ */
263
+ export const getSolanaWriteRpcs = (rpcUrls: string[]): SolanaRpcType[] => {
264
+ ensureSolanaRpcsFor(rpcUrls)
265
+ return cachedSolanaRpcs(rpcUrls)
231
266
  }
232
267
 
233
268
  /** `unreachable` counts endpoints whose probe failed without naming the
@@ -239,10 +274,20 @@ export const getJitoRpcs = async (
239
274
  client: SDKClient
240
275
  ): Promise<{ rpcs: JitoRpcType[]; unreachable: number }> => {
241
276
  const { rpcUrls, unreachable } = await ensureJitoRpcs(client)
242
- return {
243
- rpcs: rpcUrls
244
- .map((rpcUrl) => jitoRpcs.get(rpcUrl))
245
- .filter((rpc): rpc is JitoRpcType => Boolean(rpc)),
246
- unreachable,
247
- }
277
+ return { rpcs: cachedJitoRpcs(rpcUrls), unreachable }
278
+ }
279
+
280
+ /**
281
+ * The given URLs that pass the Jito probe - the bundle or write RPCs of
282
+ * `rpcUrls[ChainId.SOL]`. They share the probe cache with the read RPCs.
283
+ * `unreachable` counts the URLs whose probe failed without an answer, as in
284
+ * `getJitoRpcs`.
285
+ * @param rpcUrls - The URLs to probe.
286
+ * @returns - Jito RPCs to submit bundles through, and the unreachable count.
287
+ */
288
+ export const getJitoCapableRpcs = async (
289
+ rpcUrls: string[]
290
+ ): Promise<{ rpcs: JitoRpcType[]; unreachable: number }> => {
291
+ const unreachable = await ensureJitoRpcsFor(rpcUrls)
292
+ return { rpcs: cachedJitoRpcs(rpcUrls), unreachable }
248
293
  }
package/src/version.ts CHANGED
@@ -1,2 +1,2 @@
1
1
  export const name = '@lifi/sdk-provider-solana'
2
- export const version = '4.2.2'
2
+ export const version = '4.3.0'