@lifi/sdk-provider-solana 4.0.7 → 4.1.1

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 +117 -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
@@ -0,0 +1,135 @@
1
+ import type { ConfirmationOutcome } from './types.js'
2
+
3
+ export type RaceResult<T> =
4
+ | { kind: 'confirmed'; value: T }
5
+ | { kind: 'not-confirmed'; errors: Error[] }
6
+ | { kind: 'rpc-unavailable'; errors: Error[] }
7
+
8
+ const toError = (reason: unknown): Error =>
9
+ reason instanceof Error ? reason : new Error(String(reason))
10
+
11
+ /**
12
+ * Aborts when `signal` aborts or `timeoutMs` elapses, whichever is first.
13
+ *
14
+ * Not `AbortSignal.any` + `AbortSignal.timeout`: both are Baseline March 2024,
15
+ * and a published SDK should not raise its runtime floor for a convenience one
16
+ * controller and one timer already cover. The caller's signal is never aborted
17
+ * here, so "caller aborted" and "timeout fired" stay distinguishable.
18
+ */
19
+ function abortAfter(
20
+ signal: AbortSignal,
21
+ timeoutMs: number
22
+ ): { signal: AbortSignal; dispose: () => void } {
23
+ const linked = new AbortController()
24
+ const forward = (): void => linked.abort(signal.reason)
25
+
26
+ const timer = setTimeout(() => {
27
+ linked.abort(new Error(`This RPC did not answer within ${timeoutMs}ms.`))
28
+ }, timeoutMs)
29
+ // A pending timer keeps Node's event loop alive. `dispose` clears it; the
30
+ // unref only covers a path that skips `dispose`.
31
+ const handle = timer as unknown as { unref?: () => void }
32
+ handle.unref?.()
33
+
34
+ if (signal.aborted) {
35
+ forward()
36
+ } else {
37
+ signal.addEventListener('abort', forward, { once: true })
38
+ }
39
+
40
+ return {
41
+ signal: linked.signal,
42
+ dispose: (): void => {
43
+ clearTimeout(timer)
44
+ signal.removeEventListener('abort', forward)
45
+ },
46
+ }
47
+ }
48
+
49
+ /**
50
+ * Runs `run` against every RPC in parallel and reports the first confirmation.
51
+ *
52
+ * Not `Promise.any`: it turns "polled and saw nothing" into a thrown sentinel,
53
+ * collapsing the difference between an expired transaction and an RPC that
54
+ * never answered - the defect that reported live swaps as `TransactionExpired`.
55
+ * `timeoutMs` is the caller's; this module holds no confirmation policy.
56
+ */
57
+ export async function raceRpcs<Rpc, T>(
58
+ rpcs: Rpc[],
59
+ run: (rpc: Rpc, signal: AbortSignal) => Promise<ConfirmationOutcome<T>>,
60
+ options: { timeoutMs: number }
61
+ ): Promise<RaceResult<T>> {
62
+ if (rpcs.length === 0) {
63
+ return { kind: 'rpc-unavailable', errors: [] }
64
+ }
65
+
66
+ const controller = new AbortController()
67
+ // Kept distinct: `controller` means "another branch confirmed", the timeout
68
+ // means "this endpoint never answered". The timeout aborts the linked signal
69
+ // only.
70
+ const branch = abortAfter(controller.signal, options.timeoutMs)
71
+
72
+ let resolveConfirmed: ((value: T) => void) | undefined
73
+ const firstConfirmation = new Promise<T>((resolve) => {
74
+ resolveConfirmed = resolve
75
+ })
76
+
77
+ const settled = Promise.allSettled(
78
+ rpcs.map(async (rpc) => {
79
+ const outcome = await run(rpc, branch.signal)
80
+ if (outcome.kind === 'confirmed') {
81
+ resolveConfirmed?.(outcome.value)
82
+ controller.abort()
83
+ }
84
+ return outcome
85
+ })
86
+ )
87
+
88
+ const classify = (
89
+ results: PromiseSettledResult<ConfirmationOutcome<T>>[]
90
+ ): RaceResult<T> => {
91
+ let sawNotConfirmed = false
92
+ const errors: Error[] = []
93
+
94
+ for (const entry of results) {
95
+ if (entry.status === 'fulfilled') {
96
+ // Unreachable today - `firstConfirmation` always wins - but keeps
97
+ // `classify` correct if that structure changes.
98
+ if (entry.value.kind === 'confirmed') {
99
+ return { kind: 'confirmed', value: entry.value.value }
100
+ }
101
+ sawNotConfirmed = true
102
+ continue
103
+ }
104
+ // Cancelled branches are not failures. A branch the timeout killed is,
105
+ // so its error is collected.
106
+ if (controller.signal.aborted) {
107
+ continue
108
+ }
109
+ errors.push(toError(entry.reason))
110
+ }
111
+
112
+ // A completed observation outranks a thrown error, but the collected
113
+ // errors still travel with it as the expiry's `cause`.
114
+ if (sawNotConfirmed) {
115
+ return { kind: 'not-confirmed', errors }
116
+ }
117
+ return { kind: 'rpc-unavailable', errors }
118
+ }
119
+
120
+ try {
121
+ const result = await Promise.race([
122
+ firstConfirmation.then(
123
+ (value): RaceResult<T> => ({ kind: 'confirmed', value })
124
+ ),
125
+ settled.then(classify),
126
+ ])
127
+
128
+ return result
129
+ } finally {
130
+ // Cancels every in-flight branch on every path out, rejections included.
131
+ // Must run before `dispose`, which detaches the listener carrying it.
132
+ controller.abort()
133
+ branch.dispose()
134
+ }
135
+ }
@@ -0,0 +1,23 @@
1
+ import type { Commitment } from '@solana/kit'
2
+ import type { SolanaRpcType } from '../rpc/types.js'
3
+
4
+ type SignatureStatusesResponse = Awaited<
5
+ ReturnType<ReturnType<SolanaRpcType['getSignatureStatuses']>['send']>
6
+ >
7
+
8
+ /** Derived from the RPC type rather than hand-written, which removes every
9
+ * `as SignatureStatus` cast. A `JitoRpcType` response assigns without one. */
10
+ export type SignatureStatus = NonNullable<
11
+ SignatureStatusesResponse['value'][number]
12
+ >
13
+
14
+ /** What a single RPC branch is allowed to report. Failure is a throw. */
15
+ export type ConfirmationOutcome<T> =
16
+ | { kind: 'confirmed'; value: T }
17
+ | { kind: 'not-confirmed' }
18
+
19
+ export function isConfirmedCommitment(
20
+ status: Commitment | string | null | undefined
21
+ ): boolean {
22
+ return status === 'confirmed' || status === 'finalized'
23
+ }
@@ -7,6 +7,17 @@ import {
7
7
  import { sendAndConfirmBundle } from '../../actions/sendAndConfirmBundle.js'
8
8
  import type { SolanaStepExecutorContext } from '../../types.js'
9
9
  import { SolanaTransactionDetailsError } from '../../utils/solanaErrorCause.js'
10
+ import { readSignature } from './readSignature.js'
11
+ import { unwrapConfirmation } from './unwrapConfirmation.js'
12
+
13
+ /** Jito encodes `err` as a Rust `Result`: a landed bundle carries
14
+ * `{ Ok: null }`, so only an explicit `{ Err: … }` counts as a failure. */
15
+ function getBundleFailure(err: unknown): { failure: unknown } | undefined {
16
+ if (typeof err !== 'object' || err === null || !('Err' in err)) {
17
+ return undefined
18
+ }
19
+ return { failure: (err as { Err: unknown }).Err }
20
+ }
10
21
 
11
22
  export class SolanaJitoWaitForTransactionTask extends BaseStepExecutionTask {
12
23
  async run(context: SolanaStepExecutorContext): Promise<TaskResult> {
@@ -39,23 +50,50 @@ export class SolanaJitoWaitForTransactionTask extends BaseStepExecutionTask {
39
50
  )
40
51
  }
41
52
 
42
- // Use Jito bundle for transaction submission
43
- const bundleResult = await sendAndConfirmBundle(client, signedTransactions)
53
+ const txSignature = readSignature(signedTransactions[0])
54
+ const txLink = `${fromChain.metamask.blockExplorerUrls[0]}tx/${txSignature}`
44
55
 
45
- const allConfirmed = bundleResult.signatureResults.every(
46
- (result) => result !== null
47
- )
56
+ // Use Jito bundle for transaction submission. An empty Jito RPC list -
57
+ // the configuration gap, as opposed to an outage - throws inside
58
+ // `sendAndConfirmBundle` with its own message, before anything is sent.
59
+ const result = await sendAndConfirmBundle(client, signedTransactions, {
60
+ onBroadcast: () => {
61
+ // The earliest honest point for both: an RPC has accepted the
62
+ // transaction, so the signature now resolves on chain.
63
+ statusManager.updateAction(step, action.type, 'PENDING', {
64
+ txHash: txSignature,
65
+ txLink,
66
+ })
67
+ },
68
+ })
48
69
 
49
- if (!allConfirmed) {
70
+ // The `rpc-unavailable` message is distinct from the empty-list throw
71
+ // above: RPCs were configured and every one of them failed. That is an
72
+ // outage, and the collected branch errors say what each endpoint did.
73
+ const bundleResult = unwrapConfirmation(result, {
74
+ rpcUnavailable:
75
+ 'Unable to confirm bundle: every configured Jito RPC failed.',
76
+ notConfirmed: 'Bundle was not confirmed before the SDK stopped waiting.',
77
+ allRpcsFailed: 'All Jito RPCs failed',
78
+ someRpcsFailed:
79
+ 'Some Jito RPCs failed while the confirmation window was open',
80
+ })
81
+
82
+ // A `null` in `signatureResults` is indexing lag, never failure. The
83
+ // bundle-level `err` is checked first: it survives a failed
84
+ // `getSignatureStatuses` read.
85
+ const bundleFailure = getBundleFailure(bundleResult.bundleErr)
86
+ if (bundleFailure) {
87
+ const cause = new SolanaTransactionDetailsError(bundleFailure.failure)
50
88
  throw new TransactionError(
51
89
  LiFiErrorCode.TransactionFailed,
52
- 'Bundle confirmation failed: Not all transactions were confirmed.'
90
+ `Transaction failed: ${cause.message}`,
91
+ cause
53
92
  )
54
93
  }
55
94
 
56
- // Check for errors in any of the transactions
57
95
  const failedResult = bundleResult.signatureResults.find(
58
- (result) => result?.err
96
+ (signatureResult) => signatureResult?.err
59
97
  )
60
98
  if (failedResult?.err) {
61
99
  const cause = new SolanaTransactionDetailsError(failedResult.err)
@@ -66,15 +104,10 @@ export class SolanaJitoWaitForTransactionTask extends BaseStepExecutionTask {
66
104
  )
67
105
  }
68
106
 
69
- const confirmedTransaction = {
70
- txSignature: bundleResult.txSignatures[0],
71
- bundleId: bundleResult.bundleId,
72
- }
73
-
74
107
  // Transaction has been confirmed and we can update the action
75
108
  statusManager.updateAction(step, action.type, 'PENDING', {
76
- txHash: confirmedTransaction.txSignature,
77
- txLink: `${fromChain.metamask.blockExplorerUrls[0]}tx/${confirmedTransaction.txSignature}`,
109
+ txHash: txSignature,
110
+ txLink,
78
111
  })
79
112
 
80
113
  if (isBridgeExecution) {
@@ -84,8 +84,23 @@ export class SolanaSignAndExecuteTask extends BaseStepExecutionTask {
84
84
  )
85
85
  }
86
86
 
87
+ // Neither `txHash` nor `txLink` is written here. A signature is fixed at
88
+ // signing, but the transaction does not exist yet: `getTransaction`
89
+ // returns `null` for it, and simulation, the empty-Jito-RPC throw and
90
+ // every send failure all sit between this task and the first broadcast.
91
+ // The wait tasks write both on `onBroadcast`, when an RPC has accepted it.
92
+ //
93
+ // Both are still written as an explicit `undefined`, which clears what a
94
+ // restarted `PENDING` action carried over from a previous run.
95
+ // `prepareRestart` keeps that action *because* its `txHash` is truthy, so
96
+ // leaving the signature in place would report the previous run's hash if
97
+ // this run failed before its first broadcast. It therefore has to run
98
+ // BEFORE the decode below, which can throw on a malformed wallet
99
+ // output and would otherwise strand the previous run's signature.
87
100
  statusManager.updateAction(step, action.type, 'PENDING', {
88
101
  signedAt: Date.now(),
102
+ txHash: undefined,
103
+ txLink: undefined,
89
104
  })
90
105
 
91
106
  const transactionCodec = getTransactionCodec()
@@ -9,6 +9,8 @@ import { sendAndConfirmTransaction } from '../../actions/sendAndConfirmTransacti
9
9
  import { callSolanaRpcsWithRetry } from '../../rpc/utils.js'
10
10
  import type { SolanaStepExecutorContext } from '../../types.js'
11
11
  import { SolanaTransactionDetailsError } from '../../utils/solanaErrorCause.js'
12
+ import { readSignature } from './readSignature.js'
13
+ import { unwrapConfirmation } from './unwrapConfirmation.js'
12
14
 
13
15
  export class SolanaStandardWaitForTransactionTask extends BaseStepExecutionTask {
14
16
  async run(context: SolanaStepExecutorContext): Promise<TaskResult> {
@@ -73,19 +75,32 @@ export class SolanaStandardWaitForTransactionTask extends BaseStepExecutionTask
73
75
  }
74
76
  }
75
77
 
76
- const result = await sendAndConfirmTransaction(client, signedTransaction)
78
+ const txSignature = readSignature(signedTransaction)
79
+ const txLink = `${fromChain.metamask.blockExplorerUrls[0]}tx/${txSignature}`
77
80
 
78
- if (!result.signatureResult) {
79
- throw new TransactionError(
80
- LiFiErrorCode.TransactionExpired,
81
- 'Transaction has expired: The block height has exceeded the maximum allowed limit.'
82
- )
83
- }
81
+ const result = await sendAndConfirmTransaction(client, signedTransaction, {
82
+ onBroadcast: () => {
83
+ // The earliest honest point for both: an RPC has accepted the
84
+ // transaction, so the signature now resolves on chain.
85
+ statusManager.updateAction(step, action.type, 'PENDING', {
86
+ txHash: txSignature,
87
+ txLink,
88
+ })
89
+ },
90
+ })
84
91
 
85
- if (result.signatureResult.err) {
86
- const cause = new SolanaTransactionDetailsError(
87
- result.signatureResult.err
88
- )
92
+ const status = unwrapConfirmation(result, {
93
+ rpcUnavailable:
94
+ 'Unable to confirm transaction: no Solana RPC returned a usable response.',
95
+ notConfirmed:
96
+ 'Transaction was not confirmed before the SDK stopped waiting.',
97
+ allRpcsFailed: 'All Solana RPCs failed',
98
+ someRpcsFailed:
99
+ 'Some Solana RPCs failed while the confirmation window was open',
100
+ })
101
+
102
+ if (status.err) {
103
+ const cause = new SolanaTransactionDetailsError(status.err)
89
104
  throw new TransactionError(
90
105
  LiFiErrorCode.TransactionFailed,
91
106
  `Transaction failed: ${cause.message}`,
@@ -93,14 +108,10 @@ export class SolanaStandardWaitForTransactionTask extends BaseStepExecutionTask
93
108
  )
94
109
  }
95
110
 
96
- const confirmedTransaction = {
97
- txSignature: result.txSignature,
98
- }
99
-
100
111
  // Transaction has been confirmed and we can update the action
101
112
  statusManager.updateAction(step, action.type, 'PENDING', {
102
- txHash: confirmedTransaction.txSignature,
103
- txLink: `${fromChain.metamask.blockExplorerUrls[0]}tx/${confirmedTransaction.txSignature}`,
113
+ txHash: txSignature,
114
+ txLink,
104
115
  })
105
116
 
106
117
  if (isBridgeExecution) {
@@ -0,0 +1,29 @@
1
+ import { LiFiErrorCode, TransactionError } from '@lifi/sdk'
2
+ import {
3
+ getSignatureFromTransaction,
4
+ type Signature,
5
+ type Transaction,
6
+ } from '@solana/kit'
7
+
8
+ /**
9
+ * Reads a signed transaction's signature, restating a `@solana/kit` failure as
10
+ * a `TransactionError`.
11
+ *
12
+ * Both wait tasks derive the signature before they submit, so this call is on
13
+ * the execution path. `getSignatureFromTransaction` throws a bare
14
+ * `SolanaError` when the fee payer's slot is null - a wallet that returned a
15
+ * partially signed transaction, or a bundle whose first entry is signed by
16
+ * someone else. Integrator error branching switches on `LiFiErrorCode`, so an
17
+ * unwrapped throw lands in the unknown bucket.
18
+ */
19
+ export function readSignature(transaction: Transaction): Signature {
20
+ try {
21
+ return getSignatureFromTransaction(transaction)
22
+ } catch (error) {
23
+ throw new TransactionError(
24
+ LiFiErrorCode.TransactionUnprepared,
25
+ 'Unable to prepare transaction. The signed transaction carries no fee payer signature.',
26
+ error as Error
27
+ )
28
+ }
29
+ }
@@ -0,0 +1,59 @@
1
+ import { LiFiErrorCode, RPCError, TransactionError } from '@lifi/sdk'
2
+ import type { RaceResult } from '../../confirmation/raceRpcs.js'
3
+
4
+ /** Only the nouns differ between the standard and bundle paths. */
5
+ export type ConfirmationMessages = {
6
+ /** Every branch failed: an outage, not a verdict about the transaction. */
7
+ rpcUnavailable: string
8
+ /** A branch polled to its deadline and saw nothing. */
9
+ notConfirmed: string
10
+ /** Heading of the `AggregateError` chained onto `rpcUnavailable`. */
11
+ allRpcsFailed: string
12
+ /** Heading of the `AggregateError` chained onto `notConfirmed`. */
13
+ someRpcsFailed: string
14
+ }
15
+
16
+ /** `cause` is the first collected error on purpose: `BaseError` overwrites its
17
+ * stack with `getRootCause(cause).stack`, and an `AggregateError` has no
18
+ * `cause`, so without it the stack would point at this file. */
19
+ const chainErrors = (
20
+ errors: Error[],
21
+ message: string
22
+ ): AggregateError | undefined =>
23
+ errors.length
24
+ ? new AggregateError(errors, message, { cause: errors[0] })
25
+ : undefined
26
+
27
+ /**
28
+ * Returns the confirmed value, or throws the error the integrator sees.
29
+ *
30
+ * Both wait tasks map the same three outcomes onto the same two error classes,
31
+ * so the mapping lives here once. `rpc-unavailable` and `not-confirmed` must
32
+ * stay distinct: collapsing them reported a live RPC defect as an expired
33
+ * transaction.
34
+ */
35
+ export function unwrapConfirmation<T>(
36
+ result: RaceResult<T>,
37
+ messages: ConfirmationMessages
38
+ ): T {
39
+ if (result.kind === 'rpc-unavailable') {
40
+ throw new RPCError(
41
+ LiFiErrorCode.RpcUnavailable,
42
+ messages.rpcUnavailable,
43
+ chainErrors(result.errors, messages.allRpcsFailed)
44
+ )
45
+ }
46
+
47
+ if (result.kind === 'not-confirmed') {
48
+ // The verdict came from a branch that polled to its deadline and saw
49
+ // nothing, but other branches may have died trying - and their errors are
50
+ // the only trail explaining, say, an endpoint that never answered.
51
+ throw new TransactionError(
52
+ LiFiErrorCode.TransactionExpired,
53
+ messages.notConfirmed,
54
+ chainErrors(result.errors, messages.someRpcsFailed)
55
+ )
56
+ }
57
+
58
+ return result.value
59
+ }
@@ -4,7 +4,8 @@ import type { JitoRegion } from '../types.js'
4
4
 
5
5
  type BundleStatus = {
6
6
  bundle_id: string
7
- transactions: Signature[]
7
+ /** Optional: unvalidated wire data, so the reader must handle its absence. */
8
+ transactions?: Signature[]
8
9
  slot: number
9
10
  confirmation_status: 'processed' | 'confirmed' | 'finalized' | null
10
11
  err: unknown
@@ -14,7 +15,8 @@ type GetBundleStatusesResponse = {
14
15
  context: {
15
16
  slot: number
16
17
  }
17
- value: BundleStatus[]
18
+ /** Jito answers with `null` for a bundle id it does not know. */
19
+ value: (BundleStatus | null)[]
18
20
  }
19
21
 
20
22
  export type GetBundleStatusesApi = {