@lifi/sdk-provider-solana 4.0.6 → 4.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 (145) hide show
  1. package/CHANGELOG.md +116 -0
  2. package/dist/cjs/actions/sendAndConfirmBundle.d.ts +18 -25
  3. package/dist/cjs/actions/sendAndConfirmBundle.js +33 -54
  4. package/dist/cjs/actions/sendAndConfirmBundle.js.map +1 -1
  5. package/dist/cjs/actions/sendAndConfirmTransaction.d.ts +14 -22
  6. package/dist/cjs/actions/sendAndConfirmTransaction.js +38 -55
  7. package/dist/cjs/actions/sendAndConfirmTransaction.js.map +1 -1
  8. package/dist/cjs/confirmation/abortableSleep.d.ts +19 -0
  9. package/dist/cjs/confirmation/abortableSleep.js +32 -0
  10. package/dist/cjs/confirmation/abortableSleep.js.map +1 -0
  11. package/dist/cjs/confirmation/confirmBundle.d.ts +43 -0
  12. package/dist/cjs/confirmation/confirmBundle.js +57 -0
  13. package/dist/cjs/confirmation/confirmBundle.js.map +1 -0
  14. package/dist/cjs/confirmation/confirmSignature.d.ts +29 -0
  15. package/dist/cjs/confirmation/confirmSignature.js +66 -0
  16. package/dist/cjs/confirmation/confirmSignature.js.map +1 -0
  17. package/dist/cjs/confirmation/createConfirmationDeadline.d.ts +51 -0
  18. package/dist/cjs/confirmation/createConfirmationDeadline.js +101 -0
  19. package/dist/cjs/confirmation/createConfirmationDeadline.js.map +1 -0
  20. package/dist/cjs/confirmation/pollUntilDeadline.d.ts +58 -0
  21. package/dist/cjs/confirmation/pollUntilDeadline.js +97 -0
  22. package/dist/cjs/confirmation/pollUntilDeadline.js.map +1 -0
  23. package/dist/cjs/confirmation/raceRpcs.d.ts +26 -0
  24. package/dist/cjs/confirmation/raceRpcs.js +93 -0
  25. package/dist/cjs/confirmation/raceRpcs.js.map +1 -0
  26. package/dist/cjs/confirmation/types.d.ts +18 -0
  27. package/dist/cjs/confirmation/types.js +9 -0
  28. package/dist/cjs/confirmation/types.js.map +1 -0
  29. package/dist/cjs/core/tasks/SolanaJitoWaitForTransactionTask.js +30 -9
  30. package/dist/cjs/core/tasks/SolanaJitoWaitForTransactionTask.js.map +1 -1
  31. package/dist/cjs/core/tasks/SolanaSignAndExecuteTask.js +5 -1
  32. package/dist/cjs/core/tasks/SolanaSignAndExecuteTask.js.map +1 -1
  33. package/dist/cjs/core/tasks/SolanaStandardWaitForTransactionTask.js +20 -7
  34. package/dist/cjs/core/tasks/SolanaStandardWaitForTransactionTask.js.map +1 -1
  35. package/dist/cjs/core/tasks/readSignature.d.ts +17 -0
  36. package/dist/cjs/core/tasks/readSignature.js +26 -0
  37. package/dist/cjs/core/tasks/readSignature.js.map +1 -0
  38. package/dist/cjs/core/tasks/unwrapConfirmation.d.ts +25 -0
  39. package/dist/cjs/core/tasks/unwrapConfirmation.js +24 -0
  40. package/dist/cjs/core/tasks/unwrapConfirmation.js.map +1 -0
  41. package/dist/cjs/rpc/jito/api/getBundleStatuses.d.ts +4 -2
  42. package/dist/cjs/rpc/registry.d.ts +37 -11
  43. package/dist/cjs/rpc/registry.js +103 -18
  44. package/dist/cjs/rpc/registry.js.map +1 -1
  45. package/dist/cjs/rpc/utils.js +1 -1
  46. package/dist/cjs/rpc/utils.js.map +1 -1
  47. package/dist/cjs/utils/KeypairWalletAdapter.js +10 -4
  48. package/dist/cjs/utils/KeypairWalletAdapter.js.map +1 -1
  49. package/dist/cjs/utils/getTransactionLifetime.d.ts +21 -0
  50. package/dist/cjs/utils/getTransactionLifetime.js +28 -0
  51. package/dist/cjs/utils/getTransactionLifetime.js.map +1 -0
  52. package/dist/cjs/version.d.ts +1 -1
  53. package/dist/cjs/version.js +1 -1
  54. package/dist/cjs/version.js.map +1 -1
  55. package/dist/esm/actions/sendAndConfirmBundle.d.ts +18 -25
  56. package/dist/esm/actions/sendAndConfirmBundle.d.ts.map +1 -1
  57. package/dist/esm/actions/sendAndConfirmBundle.js +34 -55
  58. package/dist/esm/actions/sendAndConfirmBundle.js.map +1 -1
  59. package/dist/esm/actions/sendAndConfirmTransaction.d.ts +14 -22
  60. package/dist/esm/actions/sendAndConfirmTransaction.d.ts.map +1 -1
  61. package/dist/esm/actions/sendAndConfirmTransaction.js +38 -55
  62. package/dist/esm/actions/sendAndConfirmTransaction.js.map +1 -1
  63. package/dist/esm/confirmation/abortableSleep.d.ts +19 -0
  64. package/dist/esm/confirmation/abortableSleep.d.ts.map +1 -0
  65. package/dist/esm/confirmation/abortableSleep.js +31 -0
  66. package/dist/esm/confirmation/abortableSleep.js.map +1 -0
  67. package/dist/esm/confirmation/confirmBundle.d.ts +43 -0
  68. package/dist/esm/confirmation/confirmBundle.d.ts.map +1 -0
  69. package/dist/esm/confirmation/confirmBundle.js +55 -0
  70. package/dist/esm/confirmation/confirmBundle.js.map +1 -0
  71. package/dist/esm/confirmation/confirmSignature.d.ts +29 -0
  72. package/dist/esm/confirmation/confirmSignature.d.ts.map +1 -0
  73. package/dist/esm/confirmation/confirmSignature.js +64 -0
  74. package/dist/esm/confirmation/confirmSignature.js.map +1 -0
  75. package/dist/esm/confirmation/createConfirmationDeadline.d.ts +51 -0
  76. package/dist/esm/confirmation/createConfirmationDeadline.d.ts.map +1 -0
  77. package/dist/esm/confirmation/createConfirmationDeadline.js +93 -0
  78. package/dist/esm/confirmation/createConfirmationDeadline.js.map +1 -0
  79. package/dist/esm/confirmation/pollUntilDeadline.d.ts +58 -0
  80. package/dist/esm/confirmation/pollUntilDeadline.d.ts.map +1 -0
  81. package/dist/esm/confirmation/pollUntilDeadline.js +93 -0
  82. package/dist/esm/confirmation/pollUntilDeadline.js.map +1 -0
  83. package/dist/esm/confirmation/raceRpcs.d.ts +26 -0
  84. package/dist/esm/confirmation/raceRpcs.d.ts.map +1 -0
  85. package/dist/esm/confirmation/raceRpcs.js +92 -0
  86. package/dist/esm/confirmation/raceRpcs.js.map +1 -0
  87. package/dist/esm/confirmation/types.d.ts +18 -0
  88. package/dist/esm/confirmation/types.d.ts.map +1 -0
  89. package/dist/esm/confirmation/types.js +8 -0
  90. package/dist/esm/confirmation/types.js.map +1 -0
  91. package/dist/esm/core/tasks/SolanaJitoWaitForTransactionTask.d.ts.map +1 -1
  92. package/dist/esm/core/tasks/SolanaJitoWaitForTransactionTask.js +30 -9
  93. package/dist/esm/core/tasks/SolanaJitoWaitForTransactionTask.js.map +1 -1
  94. package/dist/esm/core/tasks/SolanaSignAndExecuteTask.js +5 -1
  95. package/dist/esm/core/tasks/SolanaSignAndExecuteTask.js.map +1 -1
  96. package/dist/esm/core/tasks/SolanaStandardWaitForTransactionTask.d.ts.map +1 -1
  97. package/dist/esm/core/tasks/SolanaStandardWaitForTransactionTask.js +20 -7
  98. package/dist/esm/core/tasks/SolanaStandardWaitForTransactionTask.js.map +1 -1
  99. package/dist/esm/core/tasks/readSignature.d.ts +17 -0
  100. package/dist/esm/core/tasks/readSignature.d.ts.map +1 -0
  101. package/dist/esm/core/tasks/readSignature.js +25 -0
  102. package/dist/esm/core/tasks/readSignature.js.map +1 -0
  103. package/dist/esm/core/tasks/unwrapConfirmation.d.ts +25 -0
  104. package/dist/esm/core/tasks/unwrapConfirmation.d.ts.map +1 -0
  105. package/dist/esm/core/tasks/unwrapConfirmation.js +23 -0
  106. package/dist/esm/core/tasks/unwrapConfirmation.js.map +1 -0
  107. package/dist/esm/rpc/jito/api/getBundleStatuses.d.ts +4 -2
  108. package/dist/esm/rpc/jito/api/getBundleStatuses.d.ts.map +1 -1
  109. package/dist/esm/rpc/registry.d.ts +37 -11
  110. package/dist/esm/rpc/registry.d.ts.map +1 -1
  111. package/dist/esm/rpc/registry.js +102 -19
  112. package/dist/esm/rpc/registry.js.map +1 -1
  113. package/dist/esm/rpc/utils.js +1 -1
  114. package/dist/esm/rpc/utils.js.map +1 -1
  115. package/dist/esm/utils/KeypairWalletAdapter.d.ts.map +1 -1
  116. package/dist/esm/utils/KeypairWalletAdapter.js +11 -5
  117. package/dist/esm/utils/KeypairWalletAdapter.js.map +1 -1
  118. package/dist/esm/utils/getTransactionLifetime.d.ts +21 -0
  119. package/dist/esm/utils/getTransactionLifetime.d.ts.map +1 -0
  120. package/dist/esm/utils/getTransactionLifetime.js +27 -0
  121. package/dist/esm/utils/getTransactionLifetime.js.map +1 -0
  122. package/dist/esm/version.d.ts +1 -1
  123. package/dist/esm/version.js +1 -1
  124. package/dist/esm/version.js.map +1 -1
  125. package/package.json +4 -4
  126. package/src/actions/sendAndConfirmBundle.ts +82 -142
  127. package/src/actions/sendAndConfirmTransaction.ts +82 -134
  128. package/src/confirmation/abortableSleep.ts +30 -0
  129. package/src/confirmation/confirmBundle.ts +121 -0
  130. package/src/confirmation/confirmSignature.ts +113 -0
  131. package/src/confirmation/createConfirmationDeadline.ts +174 -0
  132. package/src/confirmation/pollUntilDeadline.ts +182 -0
  133. package/src/confirmation/raceRpcs.ts +135 -0
  134. package/src/confirmation/types.ts +23 -0
  135. package/src/core/tasks/SolanaJitoWaitForTransactionTask.ts +49 -16
  136. package/src/core/tasks/SolanaSignAndExecuteTask.ts +15 -0
  137. package/src/core/tasks/SolanaStandardWaitForTransactionTask.ts +28 -17
  138. package/src/core/tasks/readSignature.ts +29 -0
  139. package/src/core/tasks/unwrapConfirmation.ts +59 -0
  140. package/src/rpc/jito/api/getBundleStatuses.ts +4 -2
  141. package/src/rpc/registry.ts +183 -25
  142. package/src/rpc/utils.ts +5 -2
  143. package/src/utils/KeypairWalletAdapter.ts +34 -9
  144. package/src/utils/getTransactionLifetime.ts +38 -0
  145. package/src/version.ts +1 -1
@@ -1,4 +1,4 @@
1
- import { ChainId, LruMap, type SDKClient } from '@lifi/sdk'
1
+ import { ChainId, LruMap, type SDKClient, withDedupe } from '@lifi/sdk'
2
2
  import { createSolanaRpc } from '@solana/kit'
3
3
  import { createJitoRpc } from './jito/createJitoRpc.js'
4
4
  import type { JitoRpcType, SolanaRpcType } from './types.js'
@@ -19,19 +19,124 @@ const jitoRpcs = new LruMap<JitoRpcType>(12)
19
19
  const PROBE_BUNDLE_ID =
20
20
  '1111111111111111111111111111111111111111111111111111111111111111'
21
21
 
22
+ /** Both leave the endpoint out of the Jito list, but only `unsupported` is a
23
+ * configuration gap the integrator can act on. */
24
+ export type JitoProbeOutcome = 'supported' | 'unsupported' | 'unreachable'
25
+
26
+ /** An outcome plus how long it may be trusted. The classifier decides both,
27
+ * because how long an answer is worth is a property of the evidence that
28
+ * produced it, not of the outcome alone. */
29
+ export type JitoProbeResult = {
30
+ outcome: JitoProbeOutcome
31
+ /** `Infinity` for an answer that cannot change. */
32
+ retryMs: number
33
+ }
34
+
35
+ /** Retry window for a probe that failed without naming the method unknown.
36
+ * An outage heals, so a permanent entry would keep a recovered endpoint out of
37
+ * the Jito list for the whole process. */
38
+ export const JITO_PROBE_RETRY_MS = 30_000
39
+
40
+ /** Retry window for a bare HTTP 401/403. Longer than an outage's, shorter than
41
+ * forever. The refusal never reached the JSON-RPC layer, so it proves nothing
42
+ * about capability: a plan gate, a provider deploy and an allowlist entry
43
+ * still propagating are indistinguishable here. Treating it as permanent meant
44
+ * one transient 403 removed a working endpoint for the process lifetime;
45
+ * treating it as a 30 s outage would re-probe a real plan gate on the
46
+ * pre-submission latency path twice a minute, forever. */
47
+ export const JITO_PROBE_GATEWAY_RETRY_MS: number = 15 * 60_000
48
+
49
+ type JitoProbeRecord = JitoProbeResult & { at: number }
50
+
51
+ /** Every answered probe, the negative ones included. Without them the unprobed
52
+ * set never shrinks, and every bundle submission re-probes every non-Jito
53
+ * endpoint at up to `PROBE_TIMEOUT_MS` each, on the latency path before
54
+ * submission can start. */
55
+ const jitoProbes = new LruMap<JitoProbeRecord>(12)
56
+
57
+ /** One rule for every outcome: a record is fresh until its own window closes.
58
+ * `Infinity` covers the answers that cannot change. */
59
+ const isProbeFresh = (record: JitoProbeRecord | undefined): boolean =>
60
+ record !== undefined && Date.now() - record.at < record.retryMs
61
+
62
+ /** `@solana/kit` puts the JSON-RPC code on `context.__code`, not `error.code`.
63
+ * The message is a last resort - a provider can reword it. An unrecognized
64
+ * failure counts as `unreachable`, so a misread blames an outage. */
65
+ const JSON_RPC_METHOD_NOT_FOUND = -32601
66
+ /** Non-standard; providers use it for "your plan lacks this method". */
67
+ const PROVIDER_PLAN_RESTRICTED = -32403
68
+
69
+ const CAPABILITY_CODES: number[] = [
70
+ JSON_RPC_METHOD_NOT_FOUND,
71
+ PROVIDER_PLAN_RESTRICTED,
72
+ ]
73
+
74
+ /** A plan gate rejects before JSON-RPC, so no `-32601` arrives - Helius
75
+ * answers with a bare 403. Unlike a JSON-RPC code this never reached the RPC
76
+ * layer, so it is a gateway verdict rather than a capability answer, and it
77
+ * earns a window instead of permanence. 429 and 5xx are absent: those take the
78
+ * shorter outage window. */
79
+ const GATEWAY_REFUSAL_HTTP_STATUSES: number[] = [401, 403]
80
+
81
+ const readProbeFailure = (error: unknown): JitoProbeResult => {
82
+ const candidate = error as
83
+ | {
84
+ code?: unknown
85
+ context?: { __code?: unknown; statusCode?: unknown }
86
+ }
87
+ | undefined
88
+
89
+ // kit's `__code` is 8100002 for every HTTP failure, so only a JSON-RPC code
90
+ // that reached the body is meaningful.
91
+ const rpcCode = candidate?.code ?? candidate?.context?.__code
92
+ if (typeof rpcCode === 'number' && CAPABILITY_CODES.includes(rpcCode)) {
93
+ // The server parsed the request and said it has no such method. Definitive.
94
+ return { outcome: 'unsupported', retryMs: Number.POSITIVE_INFINITY }
95
+ }
96
+
97
+ const status = candidate?.context?.statusCode
98
+ if (
99
+ typeof status === 'number' &&
100
+ GATEWAY_REFUSAL_HTTP_STATUSES.includes(status)
101
+ ) {
102
+ return { outcome: 'unreachable', retryMs: JITO_PROBE_GATEWAY_RETRY_MS }
103
+ }
104
+
105
+ const message = error instanceof Error ? error.message : String(error)
106
+ return /method not found|method does not exist|-32601|method .* not supported|unsupported method|only available for business plans/i.test(
107
+ message
108
+ )
109
+ ? { outcome: 'unsupported', retryMs: Number.POSITIVE_INFINITY }
110
+ : { outcome: 'unreachable', retryMs: JITO_PROBE_RETRY_MS }
111
+ }
112
+
113
+ /**
114
+ * Bounded because it runs upstream of `raceRpcs`, outside the confirmation
115
+ * budget the SDK documents: an endpoint that accepts the connection and never
116
+ * answers would otherwise stall bundle submission indefinitely.
117
+ */
118
+ const PROBE_TIMEOUT_MS = 5_000
119
+
22
120
  /**
23
- * Checks if an RPC URL supports Jito methods by calling getBundleStatuses.
24
- * We probe with getBundleStatuses (rather than getTipAccounts) because it is the
25
- * method actually used during bundle confirmation, and providers such as Helius
26
- * support sendBundle/getBundleStatuses without exposing getTipAccounts.
121
+ * Probes with `getBundleStatuses` rather than `getTipAccounts`: it is the
122
+ * method bundle confirmation actually uses, and providers such as Helius
123
+ * support it without exposing `getTipAccounts`.
27
124
  */
28
- export const isJitoRpc = async (rpcUrl: string): Promise<boolean> => {
125
+ export const probeJitoRpc = async (
126
+ rpcUrl: string
127
+ ): Promise<JitoProbeResult> => {
128
+ const controller = new AbortController()
129
+ const timer = setTimeout(() => controller.abort(), PROBE_TIMEOUT_MS)
29
130
  try {
30
131
  const rpc = createJitoRpc(rpcUrl)
31
- await rpc.getBundleStatuses([PROBE_BUNDLE_ID]).send()
32
- return true
33
- } catch {
34
- return false
132
+ await rpc
133
+ .getBundleStatuses([PROBE_BUNDLE_ID])
134
+ .send({ abortSignal: controller.signal })
135
+ return { outcome: 'supported', retryMs: Number.POSITIVE_INFINITY }
136
+ } catch (error) {
137
+ return readProbeFailure(error)
138
+ } finally {
139
+ clearTimeout(timer)
35
140
  }
36
141
  }
37
142
 
@@ -50,17 +155,66 @@ const ensureSolanaRpcs = async (client: SDKClient): Promise<string[]> => {
50
155
  }
51
156
 
52
157
  /**
53
- * Detects and caches Jito-capable RPCs by checking if they support the getTipAccounts method.
158
+ * Initializes and caches Jito RPCs for every configured Solana RPC URL.
159
+ *
160
+ * Every probe outcome is cached, so a non-Jito endpoint is probed once rather
161
+ * than once per bundle submission. Each record carries its own retry window:
162
+ * see `JITO_PROBE_RETRY_MS` and `JITO_PROBE_GATEWAY_RETRY_MS` for the two that
163
+ * expire.
54
164
  * @param client - The SDK client used to fetch RPC URLs.
55
165
  */
56
- const ensureJitoRpcs = async (client: SDKClient): Promise<string[]> => {
166
+ const ensureJitoRpcs = async (
167
+ client: SDKClient
168
+ ): Promise<{ rpcUrls: string[]; unreachable: number }> => {
57
169
  const rpcUrls = await client.getRpcUrlsByChainId(ChainId.SOL)
58
- for (const rpcUrl of rpcUrls) {
59
- if (!jitoRpcs.has(rpcUrl) && (await isJitoRpc(rpcUrl))) {
170
+ // Probed in parallel: serially, one slow endpoint delayed every URL behind
171
+ // it before submission could start.
172
+ const unprobed = rpcUrls.filter(
173
+ (rpcUrl) => !isProbeFresh(jitoProbes.get(rpcUrl))
174
+ )
175
+ // Deduplicated per URL: without it two concurrent submissions each probe
176
+ // every unprobed endpoint, and the slower probe writes last - a 5 s timeout
177
+ // resolving `unreachable` used to overwrite a `supported` answer that landed
178
+ // at 300 ms, evicting a verified-healthy endpoint.
179
+ //
180
+ // `withDedupe` drops its entry in a `.finally`, so this guarantees at most
181
+ // one probe *in flight* per URL, not one probe per URL. The write below waits
182
+ // for the whole batch, so a fast URL's record is unwritten while a slow
183
+ // sibling is still running - up to `PROBE_TIMEOUT_MS` - and every caller
184
+ // arriving in that window re-probes the fast URL. Repeats are therefore
185
+ // bounded by arrivals, not by one.
186
+ //
187
+ // What this does rule out is the clobber: a second probe can only begin
188
+ // after the first has settled, so it always carries the newer answer and
189
+ // always writes second. Write order matches result recency, which is why no
190
+ // timestamp comparison is needed here.
191
+ const results = await Promise.all(
192
+ unprobed.map((rpcUrl) =>
193
+ withDedupe(() => probeJitoRpc(rpcUrl), { id: `jito-probe:${rpcUrl}` })
194
+ )
195
+ )
196
+
197
+ results.forEach(({ outcome, retryMs }, index) => {
198
+ const rpcUrl = unprobed[index]
199
+ jitoProbes.set(rpcUrl, { outcome, retryMs, at: Date.now() })
200
+ if (outcome === 'supported') {
60
201
  jitoRpcs.set(rpcUrl, createJitoRpc(rpcUrl))
202
+ } else {
203
+ // An endpoint that used to answer and now does not must leave the list,
204
+ // or `getJitoRpcs` keeps handing out a client for it.
205
+ jitoRpcs.delete(rpcUrl)
61
206
  }
62
- }
63
- return rpcUrls
207
+ })
208
+
209
+ // Counted over every URL, not only the freshly probed ones: a cached
210
+ // `unreachable` still has to reach `sendAndConfirmBundle`, which uses the
211
+ // count to choose between "retry, likely temporary" and "supply a
212
+ // Jito-capable URL".
213
+ const unreachable = rpcUrls.filter(
214
+ (rpcUrl) => jitoProbes.get(rpcUrl)?.outcome === 'unreachable'
215
+ ).length
216
+
217
+ return { rpcUrls, unreachable }
64
218
  }
65
219
 
66
220
  /**
@@ -76,15 +230,19 @@ export const getSolanaRpcs = async (
76
230
  .filter((rpc): rpc is SolanaRpcType => Boolean(rpc))
77
231
  }
78
232
 
79
- /**
80
- * Wrapper around getting the Jito RPCs
81
- * @returns - Jito RPCs
82
- */
233
+ /** `unreachable` counts endpoints whose probe failed without naming the
234
+ * method unknown. Empty `rpcs` with a non-zero count is usually an outage, but
235
+ * not always: a bare 401/403 lands here too, and that can be a plan gate the
236
+ * integrator has to fix. `sendAndConfirmBundle`'s message names both, because
237
+ * this count cannot tell them apart. */
83
238
  export const getJitoRpcs = async (
84
239
  client: SDKClient
85
- ): Promise<JitoRpcType[]> => {
86
- const rpcUrls = await ensureJitoRpcs(client)
87
- return rpcUrls
88
- .map((rpcUrl) => jitoRpcs.get(rpcUrl))
89
- .filter((rpc): rpc is JitoRpcType => Boolean(rpc))
240
+ ): Promise<{ rpcs: JitoRpcType[]; unreachable: number }> => {
241
+ 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
+ }
90
248
  }
package/src/rpc/utils.ts CHANGED
@@ -97,5 +97,8 @@ export const callSolanaRpcsWithRetry: RetryFn<SolanaRpcType> =
97
97
  * )
98
98
  * ```
99
99
  */
100
- export const callJitoRpcsWithRetry: RetryFn<JitoRpcType> =
101
- createRetryFn(getJitoRpcs)
100
+ export const callJitoRpcsWithRetry: RetryFn<JitoRpcType> = createRetryFn(
101
+ // The probe diagnosis `getJitoRpcs` reports alongside the list is for the
102
+ // bundle path's error message; a sequential retry only needs the list.
103
+ async (client) => (await getJitoRpcs(client)).rpcs
104
+ )
@@ -1,5 +1,4 @@
1
1
  import {
2
- assertIsTransactionWithBlockhashLifetime,
3
2
  assertIsTransactionWithinSizeLimit,
4
3
  createKeyPairSignerFromBytes,
5
4
  getBase58Codec,
@@ -108,20 +107,46 @@ export class KeypairWalletAdapter implements Wallet {
108
107
  const transaction = getTransactionCodec().decode(input.transaction)
109
108
 
110
109
  assertIsTransactionWithinSizeLimit(transaction)
111
- assertIsTransactionWithBlockhashLifetime(transaction)
112
110
 
113
- const signatureDictionaries = await this._signer.signTransactions([
114
- transaction,
111
+ // `assertIsTransactionWithBlockhashLifetime` is deliberately NOT called
112
+ // here. It tests `'lifetimeConstraint' in transaction`, and no kit
113
+ // decoder reconstructs that property - decoding wire bytes yields
114
+ // `{ messageBytes, signatures }` alone, so the assert rejected every
115
+ // transaction a wallet is ever handed. Signing does not need it either:
116
+ // `partiallySignTransaction` signs `messageBytes` and never reads the
117
+ // lifetime. The blockhash still travels inside `messageBytes`, where
118
+ // `getTransactionLifetime` reads it for the confirmation deadline.
119
+ // Cast because `signTransactions` types its argument as carrying a
120
+ // lifetime, while the runtime path - `partiallySignTransaction` - reads
121
+ // only `messageBytes`. A decoded transaction never has the property, so
122
+ // without this the type demands something no decoder can produce.
123
+ const [signatureDictionary] = await this._signer.signTransactions([
124
+ transaction as Parameters<
125
+ typeof this._signer.signTransactions
126
+ >[0][number],
115
127
  ])
116
128
 
117
- if (
118
- signatureDictionaries.length === 0 ||
119
- !signatureDictionaries[0][this._signer.address]
120
- ) {
129
+ const signature = signatureDictionary?.[this._signer.address]
130
+ if (!signature) {
121
131
  throw new Error('Failed to sign transaction')
122
132
  }
123
133
 
124
- const signedTransaction = getBase64EncodedWireTransaction(transaction)
134
+ // The signature has to be merged back in. `partiallySignTransaction`
135
+ // returns a new frozen object rather than mutating its argument, so
136
+ // encoding `transaction` here shipped the unsigned original and threw
137
+ // the signature away - the transaction then failed on chain for a
138
+ // missing signature, far from the code that dropped it.
139
+ //
140
+ // The cast mirrors the one above: the wire format is `messageBytes`
141
+ // plus `signatures`, and the encoder reads nothing else - the lifetime
142
+ // already travels inside `messageBytes`.
143
+ const signedTransaction = getBase64EncodedWireTransaction({
144
+ ...transaction,
145
+ signatures: {
146
+ ...transaction.signatures,
147
+ [this._signer.address]: signature,
148
+ },
149
+ } as Parameters<typeof getBase64EncodedWireTransaction>[0])
125
150
 
126
151
  results.push({
127
152
  signedTransaction: base64ToUint8Array(signedTransaction),
@@ -0,0 +1,38 @@
1
+ import {
2
+ type Blockhash,
3
+ getCompiledTransactionMessageDecoder,
4
+ getTransactionLifetimeConstraintFromCompiledTransactionMessage,
5
+ type Transaction,
6
+ } from '@solana/kit'
7
+
8
+ export type TransactionLifetime =
9
+ | { kind: 'blockhash'; blockhash: Blockhash }
10
+ | { kind: 'nonce' }
11
+ | { kind: 'unknown' }
12
+
13
+ const decoder = getCompiledTransactionMessageDecoder()
14
+
15
+ /**
16
+ * Decoding yields `{ messageBytes, signatures }` alone, so the lifetime is
17
+ * recovered from the compiled message.
18
+ *
19
+ * Never throws: anything undecodable yields `unknown`, degrading confirmation
20
+ * to the wall-clock ceiling rather than aborting the send.
21
+ */
22
+ export async function getTransactionLifetime(
23
+ transaction: Transaction
24
+ ): Promise<TransactionLifetime> {
25
+ try {
26
+ const compiledMessage = decoder.decode(transaction.messageBytes)
27
+ const constraint =
28
+ await getTransactionLifetimeConstraintFromCompiledTransactionMessage(
29
+ compiledMessage
30
+ )
31
+ if ('blockhash' in constraint) {
32
+ return { kind: 'blockhash', blockhash: constraint.blockhash }
33
+ }
34
+ return { kind: 'nonce' }
35
+ } catch (_) {
36
+ return { kind: 'unknown' }
37
+ }
38
+ }
package/src/version.ts CHANGED
@@ -1,2 +1,2 @@
1
1
  export const name = '@lifi/sdk-provider-solana'
2
- export const version = '4.0.6'
2
+ export const version = '4.1.0'