@lifi/sdk-provider-solana 4.0.7 → 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 +110 -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
package/CHANGELOG.md CHANGED
@@ -1,5 +1,115 @@
1
1
  # @lifi/sdk-provider-solana
2
2
 
3
+ ## 4.1.0
4
+
5
+ ### Minor Changes
6
+
7
+ - [#454](https://github.com/lifinance/sdk/pull/454) [`d86f36f`](https://github.com/lifinance/sdk/commit/d86f36f6c85d738a97ad8207e5e519fbefee7040) Thanks [@chybisov](https://github.com/chybisov)! - Bump `@solana/kit` from 7.1.0 to 8.0.0.
8
+
9
+ v8 removes the deprecated compute-unit-limit estimation helpers
10
+ (`estimateComputeUnitLimitFactory`, `estimateAndSetComputeUnitLimitFactory`,
11
+ `fillTransactionMessageProvisoryComputeUnitLimit`), `getBigIntDowncastRequestTransformer`,
12
+ the fixed transaction size constants (`TRANSACTION_PACKET_SIZE`,
13
+ `TRANSACTION_PACKET_HEADER`, `TRANSACTION_SIZE_LIMIT`), and several
14
+ `@solana/instruction-plans` result types, and it stops writing to the execution context in
15
+ `createTransactionPlanExecutor`. This package uses none of them, so no migration was
16
+ needed. `assertIsTransactionWithinSizeLimit` survives, and its threshold is now
17
+ transaction-version-aware rather than a single constant.
18
+
19
+ Minor rather than patch: no exported signature changes, but `@solana/kit` is a regular
20
+ dependency whose types reach this package's public surface — `toAddress` is re-exported
21
+ from it, and `SolanaProviderOptions.signedTransactions` is typed with its `Transaction`.
22
+ Integrators who also depend on `@solana/kit` directly must move to 8.x, or they will
23
+ resolve two copies whose types do not interchange.
24
+
25
+ - [#448](https://github.com/lifinance/sdk/pull/448) [`1ab67e5`](https://github.com/lifinance/sdk/commit/1ab67e5b5d89446a9c08530c6d9c296179e1a359) Thanks [@chybisov](https://github.com/chybisov)! - Fix false `TransactionExpired` errors on Solana swaps that confirmed on-chain.
26
+
27
+ Confirmation stopped polling by comparing `getBlockHeight()` against a freshly
28
+ fetched blockhash's `lastValidBlockHeight`. At least one endpoint in the
29
+ default RPC set answers `getBlockHeight` with the slot number (~22M higher), so
30
+ that comparison was false on its first evaluation and the endpoint never polled
31
+ at all. Every swap then depended on the remaining endpoint alone.
32
+
33
+ Polling now stops when the signed transaction's own blockhash dies, probed via
34
+ `isBlockhashValid`, and in any case after a 90 second ceiling. `getBlockHeight`
35
+ is never read. The wait is hard-bounded: branches abort 5 seconds after the
36
+ ceiling, so allow ~95 seconds for the confirmation phase. A branch also gives up
37
+ early once its endpoint has gone 30 seconds without answering a status read,
38
+ which is long enough to ride out a throttling window rather than end the swap
39
+ inside one.
40
+
41
+ Minor rather than patch: no exported signature changes, but the error
42
+ classification integrators branch on does. Transitions, old → new:
43
+
44
+ - Standard path, no RPC returned a usable response: `TransactionError`
45
+ `TransactionExpired` (1018) → `RPCError` `RpcUnavailable` (1027).
46
+ - Jito path, bundle never confirmed: `UnknownError` `InternalError` (1000) →
47
+ `TransactionError` `TransactionExpired` (1018).
48
+ - Jito path, every Jito RPC failed: `UnknownError` (1000) → `RPCError` (1027).
49
+ - Jito path, no RPC supports bundle methods: `UnknownError` (1000) → `RPCError`
50
+ (1027).
51
+ - Jito path, confirmed bundle whose signatures an RPC had not indexed yet:
52
+ `TransactionError` `TransactionFailed` (1003) → success.
53
+ - Jito path, confirmed bundle whose status omits `transactions`:
54
+ `UnknownError` (1000) → success.
55
+ - Either path, a signed transaction carrying no fee payer signature: raw
56
+ `SolanaError` → `TransactionError` `TransactionUnprepared` (1002). Both wait
57
+ tasks read the signature before they submit, so this throw now stays inside
58
+ the `LiFiErrorCode` contract instead of reaching integrator error branching
59
+ as an unclassified error.
60
+
61
+ A confirmed Jito bundle no longer fails on missing per-signature data. A bundle
62
+ is atomic, so a `confirmed` status means every transaction in it landed; a
63
+ `null` or absent `getSignatureStatuses` result is indexing lag, not failure.
64
+ The bundle-level `err` is now read as well.
65
+
66
+ `txHash` and `txLink` are both recorded when the first RPC accepts the send,
67
+ rather than only after confirmation. A swap that broadcast and then failed to
68
+ confirm now reports its signature, so it can be looked up on chain. Neither is
69
+ written at signing time: a signed-but-unsent signature resolves to `null` on
70
+ every explorer, and simulation, a send failure, or a bundle route with no
71
+ Jito-capable RPC all sit between signing and the first broadcast. Signing does
72
+ clear both fields, so a route resumed from storage no longer reports the previous
73
+ run's signature - including when decoding the signed transaction fails, since
74
+ the clearing write now precedes the decode. A throwing `updateRouteHook` no
75
+ longer fails the step from the broadcast callback, and no longer changes which
76
+ error a failed confirmation reports. The action writes that follow a verdict
77
+ are not guarded: a hook that throws there still fails the step, as before.
78
+
79
+ Jito capability is probed once per endpoint and cached, rather than re-probed
80
+ before every bundle submission, and concurrent submissions now share one probe
81
+ per URL instead of each firing their own. Each cached answer carries its own
82
+ retry window. An endpoint that names the method unknown over JSON-RPC is
83
+ believed permanently; a bare HTTP 401 or 403 is not, because it never reached
84
+ the JSON-RPC layer and cannot distinguish a plan restriction from a provider
85
+ mid-deploy or an allowlist entry still propagating. Those retry after 15
86
+ minutes, so one transient refusal no longer removes a working endpoint for the
87
+ lifetime of the process.
88
+
89
+ For integrators: routes the backend builds as Jito bundles need a Jito-capable
90
+ Solana RPC. The default set has none, and for `ChainId.SOL` URLs supplied via
91
+ `rpcUrls` replace the defaults rather than merging. Without one, such a route
92
+ fails before submission with `RpcUnavailable` (1027).
93
+
94
+ ### Patch Changes
95
+
96
+ - [#448](https://github.com/lifinance/sdk/pull/448) [`1ab67e5`](https://github.com/lifinance/sdk/commit/1ab67e5b5d89446a9c08530c6d9c296179e1a359) Thanks [@chybisov](https://github.com/chybisov)! - Fix `KeypairWalletAdapter`, which could not sign any real transaction.
97
+
98
+ `assertIsTransactionWithBlockhashLifetime` tested for a `lifetimeConstraint`
99
+ property that no `@solana/kit` decoder reconstructs, so every transaction was
100
+ rejected with `Transaction does not have a blockhash lifetime`. Signing never
101
+ needed it — the blockhash travels inside `messageBytes`.
102
+
103
+ The result then re-encoded the pre-signing object, discarding the signature,
104
+ because `partiallySignTransaction` returns a new transaction rather than
105
+ mutating its argument.
106
+
107
+ The adapter is test-only, so no production integration is affected.
108
+
109
+ Also removes the unused `isJitoRpc` helper, superseded by `probeJitoRpc`.
110
+ - Updated dependencies [[`1ab67e5`](https://github.com/lifinance/sdk/commit/1ab67e5b5d89446a9c08530c6d9c296179e1a359)]:
111
+ - @lifi/sdk@4.5.0
112
+
3
113
  ## 4.0.7
4
114
 
5
115
  ### Patch Changes
@@ -1,31 +1,24 @@
1
+ import { BundleConfirmation } from "../confirmation/confirmBundle.js";
2
+ import { RaceResult } from "../confirmation/raceRpcs.js";
1
3
  import { SDKClient } from "@lifi/sdk";
2
- import { Commitment, Signature, Transaction, TransactionError } from "@solana/kit";
4
+ import { Transaction } from "@solana/kit";
3
5
  //#region src/actions/sendAndConfirmBundle.d.ts
4
- type SignatureStatus = {
5
- slot: bigint;
6
- confirmations: bigint | null;
7
- err: TransactionError | null;
8
- confirmationStatus: Commitment | null;
9
- status: Readonly<{
10
- Err: TransactionError;
11
- }> | Readonly<{
12
- Ok: null;
13
- }>;
14
- };
15
- type BundleResult = {
16
- bundleId: string;
17
- txSignatures: Signature[];
18
- signatureResults: (SignatureStatus | null)[];
19
- };
20
6
  /**
21
- * Send and confirm a bundle of transactions using Jito.
22
- * Automatically selects a Jito-enabled RPC connection and polls for confirmation
23
- * across multiple Jito RPCs in parallel.
24
- * @param client - The SDK client.
25
- * @param signedTransactions - Array of signed transactions to bundle.
26
- * @returns BundleResult containing Bundle ID, transaction signatures, and confirmation results.
7
+ * Sends a Jito bundle to every Jito-capable RPC and returns as soon as one of
8
+ * them confirms it.
9
+ *
10
+ * The deadline receives the lifetime of *every* signed transaction, not just
11
+ * the first: a bundle is an array of independently built backend transactions
12
+ * and they may not share a blockhash.
13
+ *
14
+ * `sendBundle` is handed to `confirmBundle` rather than awaited here, so the
15
+ * deadline starts on the same clock as `BRANCH_TIMEOUT_MS` instead of after
16
+ * the submission returns.
27
17
  */
28
- declare function sendAndConfirmBundle(client: SDKClient, signedTransactions: Transaction[]): Promise<BundleResult>;
18
+ declare function sendAndConfirmBundle(client: SDKClient, signedTransactions: Transaction[], options?: {
19
+ /** Runs once, when the first Jito RPC accepts the submission. */
20
+ onBroadcast?: () => void;
21
+ }): Promise<RaceResult<BundleConfirmation>>;
29
22
  //#endregion
30
- export { BundleResult, sendAndConfirmBundle };
23
+ export { sendAndConfirmBundle };
31
24
  //# sourceMappingURL=sendAndConfirmBundle.d.ts.map
@@ -1,65 +1,44 @@
1
1
  Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
2
2
  const require_rpc_registry = require("../rpc/registry.js");
3
+ const require_confirmation_createConfirmationDeadline = require("../confirmation/createConfirmationDeadline.js");
4
+ const require_confirmation_confirmBundle = require("../confirmation/confirmBundle.js");
5
+ const require_confirmation_raceRpcs = require("../confirmation/raceRpcs.js");
6
+ const require_utils_getTransactionLifetime = require("../utils/getTransactionLifetime.js");
3
7
  let _lifi_sdk = require("@lifi/sdk");
4
8
  let _solana_kit = require("@solana/kit");
5
9
  //#region src/actions/sendAndConfirmBundle.ts
6
- const NULL_BUNDLE_RESULT = /* @__PURE__ */ new Error("Bundle was not confirmed by this RPC");
7
10
  /**
8
- * Send and confirm a bundle of transactions using Jito.
9
- * Automatically selects a Jito-enabled RPC connection and polls for confirmation
10
- * across multiple Jito RPCs in parallel.
11
- * @param client - The SDK client.
12
- * @param signedTransactions - Array of signed transactions to bundle.
13
- * @returns BundleResult containing Bundle ID, transaction signatures, and confirmation results.
11
+ * Sends a Jito bundle to every Jito-capable RPC and returns as soon as one of
12
+ * them confirms it.
13
+ *
14
+ * The deadline receives the lifetime of *every* signed transaction, not just
15
+ * the first: a bundle is an array of independently built backend transactions
16
+ * and they may not share a blockhash.
17
+ *
18
+ * `sendBundle` is handed to `confirmBundle` rather than awaited here, so the
19
+ * deadline starts on the same clock as `BRANCH_TIMEOUT_MS` instead of after
20
+ * the submission returns.
14
21
  */
15
- async function sendAndConfirmBundle(client, signedTransactions) {
16
- const jitoRpcs = await require_rpc_registry.getJitoRpcs(client);
17
- if (jitoRpcs.length === 0) throw new Error("No Jito-enabled RPC connection available for bundle submission");
18
- const serializedTransactions = signedTransactions.map((tx) => (0, _solana_kit.getBase64EncodedWireTransaction)(tx));
19
- const abortController = new AbortController();
20
- const confirmPromises = jitoRpcs.map(async (jitoRpc) => {
22
+ async function sendAndConfirmBundle(client, signedTransactions, options) {
23
+ const { rpcs: jitoRpcs, unreachable } = await require_rpc_registry.getJitoRpcs(client);
24
+ if (jitoRpcs.length === 0) throw new _lifi_sdk.RPCError(_lifi_sdk.LiFiErrorCode.RpcUnavailable, unreachable > 0 ? `Jito bundle required, but the capability probe failed against ${unreachable} configured Solana RPC(s). This is usually temporary - retry. If it persists, the endpoint may refuse \`sendBundle\` for your plan.` : "Jito bundle required, but no configured Solana RPC supports `sendBundle`. Supply a Jito-capable URL via the `rpcUrls` client config option.");
25
+ let broadcastReported = false;
26
+ const reportBroadcast = () => {
27
+ if (broadcastReported) return;
21
28
  try {
22
- let bundleId;
23
- try {
24
- bundleId = await jitoRpc.sendBundle(serializedTransactions).send();
25
- } catch (_) {
26
- return null;
27
- }
28
- const [{ value: blockhashResult }, initialBlockHeight] = await Promise.all([jitoRpc.getLatestBlockhash({ commitment: "confirmed" }).send(), jitoRpc.getBlockHeight({ commitment: "confirmed" }).send()]);
29
- let currentBlockHeight = initialBlockHeight;
30
- while (currentBlockHeight < blockhashResult.lastValidBlockHeight && !abortController.signal.aborted) {
31
- const bundleStatus = (await jitoRpc.getBundleStatuses([bundleId]).send()).value[0];
32
- if (bundleStatus && (bundleStatus.confirmation_status === "confirmed" || bundleStatus.confirmation_status === "finalized")) {
33
- const txSignatures = bundleStatus.transactions;
34
- const sigResponse = await jitoRpc.getSignatureStatuses(txSignatures).send();
35
- if (!sigResponse?.value || !Array.isArray(sigResponse.value)) {
36
- await (0, _lifi_sdk.sleep)(400);
37
- continue;
38
- }
39
- abortController.abort();
40
- return {
41
- bundleId,
42
- txSignatures,
43
- signatureResults: sigResponse.value
44
- };
45
- }
46
- await (0, _lifi_sdk.sleep)(400);
47
- if (!abortController.signal.aborted) currentBlockHeight = await jitoRpc.getBlockHeight({ commitment: "confirmed" }).send();
48
- }
49
- return null;
50
- } catch (error) {
51
- if (abortController.signal.aborted) return null;
52
- throw error;
53
- }
54
- });
55
- const result = await Promise.any(confirmPromises.map(async (promise) => {
56
- const bundleResult = await promise;
57
- if (!bundleResult) throw NULL_BUNDLE_RESULT;
58
- return bundleResult;
59
- })).catch(() => null);
60
- if (!abortController.signal.aborted) abortController.abort();
61
- if (!result) throw new Error("Failed to send and confirm bundle");
62
- return result;
29
+ options?.onBroadcast?.();
30
+ broadcastReported = true;
31
+ } catch (_) {}
32
+ };
33
+ const serializedTransactions = signedTransactions.map((transaction) => (0, _solana_kit.getBase64EncodedWireTransaction)(transaction));
34
+ const lifetimes = await Promise.all(signedTransactions.map((transaction) => require_utils_getTransactionLifetime.getTransactionLifetime(transaction)));
35
+ return require_confirmation_raceRpcs.raceRpcs(jitoRpcs, (rpc, signal) => require_confirmation_confirmBundle.confirmBundle({
36
+ rpc,
37
+ signal,
38
+ lifetimes,
39
+ send: () => rpc.sendBundle(serializedTransactions).send({ abortSignal: signal }),
40
+ onBroadcast: reportBroadcast
41
+ }), { timeoutMs: require_confirmation_createConfirmationDeadline.BRANCH_TIMEOUT_MS });
63
42
  }
64
43
  //#endregion
65
44
  exports.sendAndConfirmBundle = sendAndConfirmBundle;
@@ -1 +1 @@
1
- {"version":3,"file":"sendAndConfirmBundle.js","names":["getJitoRpcs","getBase64EncodedWireTransaction","sleep"],"sources":["../../../src/actions/sendAndConfirmBundle.ts"],"sourcesContent":["import { type SDKClient, sleep } from '@lifi/sdk'\nimport {\n type Commitment,\n getBase64EncodedWireTransaction,\n type Signature,\n type Transaction,\n type TransactionError,\n} from '@solana/kit'\n\nimport { getJitoRpcs } from '../rpc/registry.js'\n\ntype SignatureStatus = {\n slot: bigint\n confirmations: bigint | null\n err: TransactionError | null\n confirmationStatus: Commitment | null\n status: Readonly<{ Err: TransactionError }> | Readonly<{ Ok: null }>\n}\n\nexport type BundleResult = {\n bundleId: string\n txSignatures: Signature[]\n signatureResults: (SignatureStatus | null)[]\n}\n\nconst NULL_BUNDLE_RESULT = new Error('Bundle was not confirmed by this RPC')\n\n/**\n * Send and confirm a bundle of transactions using Jito.\n * Automatically selects a Jito-enabled RPC connection and polls for confirmation\n * across multiple Jito RPCs in parallel.\n * @param client - The SDK client.\n * @param signedTransactions - Array of signed transactions to bundle.\n * @returns BundleResult containing Bundle ID, transaction signatures, and confirmation results.\n */\nexport async function sendAndConfirmBundle(\n client: SDKClient,\n signedTransactions: Transaction[]\n): Promise<BundleResult> {\n const jitoRpcs = await getJitoRpcs(client)\n\n if (jitoRpcs.length === 0) {\n throw new Error(\n 'No Jito-enabled RPC connection available for bundle submission'\n )\n }\n\n // Serialize transactions to base64\n const serializedTransactions = signedTransactions.map((tx) =>\n getBase64EncodedWireTransaction(tx)\n )\n\n const abortController = new AbortController()\n\n const confirmPromises = jitoRpcs.map(async (jitoRpc) => {\n try {\n // Send bundle to Jito\n let bundleId: string\n try {\n bundleId = await jitoRpc.sendBundle(serializedTransactions).send()\n } catch (_) {\n return null\n }\n\n const [{ value: blockhashResult }, initialBlockHeight] =\n await Promise.all([\n jitoRpc\n .getLatestBlockhash({\n commitment: 'confirmed',\n })\n .send(),\n jitoRpc\n .getBlockHeight({\n commitment: 'confirmed',\n })\n .send(),\n ])\n\n let currentBlockHeight = initialBlockHeight\n\n while (\n currentBlockHeight < blockhashResult.lastValidBlockHeight &&\n !abortController.signal.aborted\n ) {\n const statusResponse = await jitoRpc\n .getBundleStatuses([bundleId])\n .send()\n\n const bundleStatus = statusResponse.value[0]\n\n // Check if bundle is confirmed or finalized\n if (\n bundleStatus &&\n (bundleStatus.confirmation_status === 'confirmed' ||\n bundleStatus.confirmation_status === 'finalized')\n ) {\n // Bundle confirmed! Extract transaction signatures from bundle status\n const txSignatures = bundleStatus.transactions\n\n // Fetch individual signature results from Jito RPC\n const sigResponse = await jitoRpc\n .getSignatureStatuses(txSignatures)\n .send()\n\n if (!sigResponse?.value || !Array.isArray(sigResponse.value)) {\n // Keep polling if can't find signature results\n await sleep(400)\n continue\n }\n\n // Immediately abort all other connections when we find a result\n abortController.abort()\n return {\n bundleId,\n txSignatures,\n signatureResults: sigResponse.value,\n }\n }\n\n await sleep(400)\n if (!abortController.signal.aborted) {\n currentBlockHeight = await jitoRpc\n .getBlockHeight({\n commitment: 'confirmed',\n })\n .send()\n }\n }\n\n return null\n } catch (error) {\n if (abortController.signal.aborted) {\n return null // Don't treat abortion as an error\n }\n throw error\n }\n })\n\n // Wait for first successful confirmation\n const result = await Promise.any(\n confirmPromises.map(async (promise) => {\n const bundleResult = await promise\n if (!bundleResult) {\n throw NULL_BUNDLE_RESULT\n }\n return bundleResult\n })\n ).catch(() => null)\n\n if (!abortController.signal.aborted) {\n abortController.abort()\n }\n\n if (!result) {\n throw new Error('Failed to send and confirm bundle')\n }\n\n return result\n}\n"],"mappings":";;;;;AAyBA,MAAM,qCAAqB,IAAI,MAAM,sCAAsC;;;;;;;;;AAU3E,eAAsB,qBACpB,QACA,oBACuB;CACvB,MAAM,WAAW,MAAMA,qBAAAA,YAAY,MAAM;CAEzC,IAAI,SAAS,WAAW,GACtB,MAAM,IAAI,MACR,gEACF;CAIF,MAAM,yBAAyB,mBAAmB,KAAK,QAAA,GACrDC,YAAAA,gCAAAA,CAAgC,EAAE,CACpC;CAEA,MAAM,kBAAkB,IAAI,gBAAgB;CAE5C,MAAM,kBAAkB,SAAS,IAAI,OAAO,YAAY;EACtD,IAAI;GAEF,IAAI;GACJ,IAAI;IACF,WAAW,MAAM,QAAQ,WAAW,sBAAsB,CAAC,CAAC,KAAK;GACnE,SAAS,GAAG;IACV,OAAO;GACT;GAEA,MAAM,CAAC,EAAE,OAAO,mBAAmB,sBACjC,MAAM,QAAQ,IAAI,CAChB,QACG,mBAAmB,EAClB,YAAY,YACd,CAAC,CAAC,CACD,KAAK,GACR,QACG,eAAe,EACd,YAAY,YACd,CAAC,CAAC,CACD,KAAK,CACV,CAAC;GAEH,IAAI,qBAAqB;GAEzB,OACE,qBAAqB,gBAAgB,wBACrC,CAAC,gBAAgB,OAAO,SACxB;IAKA,MAAM,gBAAe,MAJQ,QAC1B,kBAAkB,CAAC,QAAQ,CAAC,CAAC,CAC7B,KAAK,EAAA,CAE4B,MAAM;IAG1C,IACE,iBACC,aAAa,wBAAwB,eACpC,aAAa,wBAAwB,cACvC;KAEA,MAAM,eAAe,aAAa;KAGlC,MAAM,cAAc,MAAM,QACvB,qBAAqB,YAAY,CAAC,CAClC,KAAK;KAER,IAAI,CAAC,aAAa,SAAS,CAAC,MAAM,QAAQ,YAAY,KAAK,GAAG;MAE5D,OAAA,GAAMC,UAAAA,MAAAA,CAAM,GAAG;MACf;KACF;KAGA,gBAAgB,MAAM;KACtB,OAAO;MACL;MACA;MACA,kBAAkB,YAAY;KAChC;IACF;IAEA,OAAA,GAAMA,UAAAA,MAAAA,CAAM,GAAG;IACf,IAAI,CAAC,gBAAgB,OAAO,SAC1B,qBAAqB,MAAM,QACxB,eAAe,EACd,YAAY,YACd,CAAC,CAAC,CACD,KAAK;GAEZ;GAEA,OAAO;EACT,SAAS,OAAO;GACd,IAAI,gBAAgB,OAAO,SACzB,OAAO;GAET,MAAM;EACR;CACF,CAAC;CAGD,MAAM,SAAS,MAAM,QAAQ,IAC3B,gBAAgB,IAAI,OAAO,YAAY;EACrC,MAAM,eAAe,MAAM;EAC3B,IAAI,CAAC,cACH,MAAM;EAER,OAAO;CACT,CAAC,CACH,CAAC,CAAC,YAAY,IAAI;CAElB,IAAI,CAAC,gBAAgB,OAAO,SAC1B,gBAAgB,MAAM;CAGxB,IAAI,CAAC,QACH,MAAM,IAAI,MAAM,mCAAmC;CAGrD,OAAO;AACT"}
1
+ {"version":3,"file":"sendAndConfirmBundle.js","names":["getJitoRpcs","RPCError","LiFiErrorCode","getBase64EncodedWireTransaction","getTransactionLifetime","raceRpcs","confirmBundle","BRANCH_TIMEOUT_MS"],"sources":["../../../src/actions/sendAndConfirmBundle.ts"],"sourcesContent":["import { LiFiErrorCode, RPCError, type SDKClient } from '@lifi/sdk'\nimport { getBase64EncodedWireTransaction, type Transaction } from '@solana/kit'\nimport {\n type BundleConfirmation,\n confirmBundle,\n} from '../confirmation/confirmBundle.js'\nimport { BRANCH_TIMEOUT_MS } from '../confirmation/createConfirmationDeadline.js'\nimport { type RaceResult, raceRpcs } from '../confirmation/raceRpcs.js'\nimport { getJitoRpcs } from '../rpc/registry.js'\nimport { getTransactionLifetime } from '../utils/getTransactionLifetime.js'\n\n/**\n * Sends a Jito bundle to every Jito-capable RPC and returns as soon as one of\n * them confirms it.\n *\n * The deadline receives the lifetime of *every* signed transaction, not just\n * the first: a bundle is an array of independently built backend transactions\n * and they may not share a blockhash.\n *\n * `sendBundle` is handed to `confirmBundle` rather than awaited here, so the\n * deadline starts on the same clock as `BRANCH_TIMEOUT_MS` instead of after\n * the submission returns.\n */\nexport async function sendAndConfirmBundle(\n client: SDKClient,\n signedTransactions: Transaction[],\n options?: {\n /** Runs once, when the first Jito RPC accepts the submission. */\n onBroadcast?: () => void\n }\n): Promise<RaceResult<BundleConfirmation>> {\n const { rpcs: jitoRpcs, unreachable } = await getJitoRpcs(client)\n\n // Named here, where the emptiness is known: racing zero RPCs would surface\n // as a bare `rpc-unavailable`, indistinguishable from a total outage. The\n // two causes get different messages - a configuration gap the integrator can\n // close, or endpoints that never answered.\n //\n // The `unreachable` message names a plan gate as well as an outage: a bare\n // HTTP 401/403 never reaches the JSON-RPC layer, so `readProbeFailure`\n // cannot tell a gated endpoint from a provider mid-deploy and classifies\n // both as `unreachable`. \"Retry\" alone would loop an integrator forever on a\n // gate no retry can clear.\n if (jitoRpcs.length === 0) {\n throw new RPCError(\n LiFiErrorCode.RpcUnavailable,\n unreachable > 0\n ? `Jito bundle required, but the capability probe failed against ${unreachable} configured Solana RPC(s). This is usually temporary - retry. If it persists, the endpoint may refuse \\`sendBundle\\` for your plan.`\n : 'Jito bundle required, but no configured Solana RPC supports `sendBundle`. Supply a Jito-capable URL via the `rpcUrls` client config option.'\n )\n }\n\n let broadcastReported = false\n // No `sendAccepted` twin here: a bundle submits once, and a failed `send()`\n // throws out of `confirmBundle` before polling starts, so this action has no\n // not-confirmed-but-never-sent case to disambiguate. See\n // `sendAndConfirmTransaction` for the signature path's version.\n const reportBroadcast = (): void => {\n if (broadcastReported) {\n return\n }\n try {\n options?.onBroadcast?.()\n // Latched only after the callback returned. A callback that threw wrote\n // nothing, so the next successful send must be allowed to try again -\n // latching first made one failed `txLink` write permanent.\n broadcastReported = true\n } catch (_) {\n // This runs integrator code: the callback reaches `updateRouteHook` via\n // `StatusManager.updateAction`. Its failure must never reject the branch\n // that called it - the send has already been accepted by the network at\n // this point, so a throw here would report a landed transaction as an\n // RPC outage. Swallowed rather than surfaced because there is no verdict\n // it could honestly change.\n }\n }\n\n const serializedTransactions = signedTransactions.map((transaction) =>\n getBase64EncodedWireTransaction(transaction)\n )\n\n const lifetimes = await Promise.all(\n signedTransactions.map((transaction) => getTransactionLifetime(transaction))\n )\n\n return raceRpcs(\n jitoRpcs,\n (rpc, signal) =>\n confirmBundle({\n rpc,\n signal,\n lifetimes,\n send: () =>\n rpc.sendBundle(serializedTransactions).send({ abortSignal: signal }),\n onBroadcast: reportBroadcast,\n }),\n { timeoutMs: BRANCH_TIMEOUT_MS }\n )\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;AAuBA,eAAsB,qBACpB,QACA,oBACA,SAIyC;CACzC,MAAM,EAAE,MAAM,UAAU,gBAAgB,MAAMA,qBAAAA,YAAY,MAAM;CAYhE,IAAI,SAAS,WAAW,GACtB,MAAM,IAAIC,UAAAA,SACRC,UAAAA,cAAc,gBACd,cAAc,IACV,iEAAiE,YAAY,uIAC7E,6IACN;CAGF,IAAI,oBAAoB;CAKxB,MAAM,wBAA8B;EAClC,IAAI,mBACF;EAEF,IAAI;GACF,SAAS,cAAc;GAIvB,oBAAoB;EACtB,SAAS,GAAG,CAOZ;CACF;CAEA,MAAM,yBAAyB,mBAAmB,KAAK,iBAAA,GACrDC,YAAAA,gCAAAA,CAAgC,WAAW,CAC7C;CAEA,MAAM,YAAY,MAAM,QAAQ,IAC9B,mBAAmB,KAAK,gBAAgBC,qCAAAA,uBAAuB,WAAW,CAAC,CAC7E;CAEA,OAAOC,8BAAAA,SACL,WACC,KAAK,WACJC,mCAAAA,cAAc;EACZ;EACA;EACA;EACA,YACE,IAAI,WAAW,sBAAsB,CAAC,CAAC,KAAK,EAAE,aAAa,OAAO,CAAC;EACrE,aAAa;CACf,CAAC,GACH,EAAE,WAAWC,gDAAAA,kBAAkB,CACjC;AACF"}
@@ -1,29 +1,21 @@
1
+ import { SignatureStatus } from "../confirmation/types.js";
2
+ import { RaceResult } from "../confirmation/raceRpcs.js";
1
3
  import { SDKClient } from "@lifi/sdk";
2
- import { Commitment, Transaction, TransactionError } from "@solana/kit";
4
+ import { Transaction } from "@solana/kit";
3
5
  //#region src/actions/sendAndConfirmTransaction.d.ts
4
- type SignatureStatus = {
5
- slot: bigint;
6
- confirmations: bigint | null;
7
- err: TransactionError | null;
8
- confirmationStatus: Commitment | null;
9
- status: Readonly<{
10
- Err: TransactionError;
11
- }> | Readonly<{
12
- Ok: null;
13
- }>;
14
- };
15
- type ConfirmedTransactionResult = {
16
- signatureResult: SignatureStatus | null;
17
- txSignature: string;
18
- };
19
6
  /**
20
- * Sends a Solana transaction to multiple RPC endpoints and returns the confirmation
21
- * as soon as any of them confirm the transaction.
22
- * @param client - The SDK client.
23
- * @param signedTransaction - The signed transaction to send.
24
- * @returns - The confirmation result of the transaction.
7
+ * Sends a Solana transaction to every configured RPC and returns as soon as
8
+ * one of them confirms it.
9
+ *
10
+ * The polling horizon comes from the signed transaction's own blockhash and a
11
+ * wall-clock ceiling. It deliberately never comes from `getBlockHeight`: at
12
+ * least one endpoint in the default LI.FI set answers that call with the slot
13
+ * number.
25
14
  */
26
- declare function sendAndConfirmTransaction(client: SDKClient, signedTransaction: Transaction): Promise<ConfirmedTransactionResult>;
15
+ declare function sendAndConfirmTransaction(client: SDKClient, signedTransaction: Transaction, options?: {
16
+ /** Runs once, when the first RPC accepts a send. */
17
+ onBroadcast?: () => void;
18
+ }): Promise<RaceResult<SignatureStatus>>;
27
19
  //#endregion
28
20
  export { sendAndConfirmTransaction };
29
21
  //# sourceMappingURL=sendAndConfirmTransaction.d.ts.map
@@ -1,74 +1,57 @@
1
1
  Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
2
2
  const require_rpc_registry = require("../rpc/registry.js");
3
- let _lifi_sdk = require("@lifi/sdk");
3
+ const require_confirmation_createConfirmationDeadline = require("../confirmation/createConfirmationDeadline.js");
4
+ const require_confirmation_raceRpcs = require("../confirmation/raceRpcs.js");
5
+ const require_utils_getTransactionLifetime = require("../utils/getTransactionLifetime.js");
6
+ const require_confirmation_confirmSignature = require("../confirmation/confirmSignature.js");
4
7
  let _solana_kit = require("@solana/kit");
5
8
  //#region src/actions/sendAndConfirmTransaction.ts
6
- const NULL_CONFIRMATION_RESULT = /* @__PURE__ */ new Error("Transaction was not confirmed by this RPC");
7
9
  /**
8
- * Sends a Solana transaction to multiple RPC endpoints and returns the confirmation
9
- * as soon as any of them confirm the transaction.
10
- * @param client - The SDK client.
11
- * @param signedTransaction - The signed transaction to send.
12
- * @returns - The confirmation result of the transaction.
10
+ * Sends a Solana transaction to every configured RPC and returns as soon as
11
+ * one of them confirms it.
12
+ *
13
+ * The polling horizon comes from the signed transaction's own blockhash and a
14
+ * wall-clock ceiling. It deliberately never comes from `getBlockHeight`: at
15
+ * least one endpoint in the default LI.FI set answers that call with the slot
16
+ * number.
13
17
  */
14
- async function sendAndConfirmTransaction(client, signedTransaction) {
18
+ async function sendAndConfirmTransaction(client, signedTransaction, options) {
15
19
  const solanaRpcs = await require_rpc_registry.getSolanaRpcs(client);
20
+ let broadcastReported = false;
21
+ let sendAccepted = false;
22
+ const reportBroadcast = () => {
23
+ sendAccepted = true;
24
+ if (broadcastReported) return;
25
+ try {
26
+ options?.onBroadcast?.();
27
+ broadcastReported = true;
28
+ } catch (_) {}
29
+ };
16
30
  const signedTxSerialized = (0, _solana_kit.getBase64EncodedWireTransaction)(signedTransaction);
17
31
  const txSignature = (0, _solana_kit.getSignatureFromTransaction)(signedTransaction);
18
- if (!txSignature) throw new Error("Transaction signature is missing.");
32
+ const lifetime = await require_utils_getTransactionLifetime.getTransactionLifetime(signedTransaction);
19
33
  const rawTransactionOptions = {
20
34
  skipPreflight: true,
21
35
  maxRetries: BigInt(0),
22
36
  preflightCommitment: "confirmed",
23
37
  encoding: "base64"
24
38
  };
25
- const abortController = new AbortController();
26
- const confirmPromises = solanaRpcs.map(async (rpc) => {
27
- try {
28
- try {
29
- await rpc.sendTransaction(signedTxSerialized, rawTransactionOptions).send();
30
- } catch (_) {}
31
- const [{ value: blockhashResult }, initialBlockHeight] = await Promise.all([rpc.getLatestBlockhash({ commitment: "confirmed" }).send(), rpc.getBlockHeight({ commitment: "confirmed" }).send()]);
32
- let signatureResult = null;
33
- let blockHeight = initialBlockHeight;
34
- const pollingPromise = (async () => {
35
- while (blockHeight < blockhashResult.lastValidBlockHeight && !abortController.signal.aborted) {
36
- const status = (await rpc.getSignatureStatuses([txSignature]).send()).value[0];
37
- if (status && (status.confirmationStatus === "confirmed" || status.confirmationStatus === "finalized")) {
38
- signatureResult = status;
39
- abortController.abort();
40
- return status;
41
- }
42
- await (0, _lifi_sdk.sleep)(400);
43
- }
44
- return null;
45
- })();
46
- const sendingPromise = (async () => {
47
- while (blockHeight < blockhashResult.lastValidBlockHeight && !abortController.signal.aborted && !signatureResult) {
48
- try {
49
- await rpc.sendTransaction(signedTxSerialized, rawTransactionOptions).send();
50
- } catch (_) {}
51
- await (0, _lifi_sdk.sleep)(1e3);
52
- if (!abortController.signal.aborted) blockHeight = await rpc.getBlockHeight({ commitment: "confirmed" }).send();
53
- }
54
- return null;
55
- })();
56
- return await Promise.race([pollingPromise, sendingPromise]);
57
- } catch (error) {
58
- if (abortController.signal.aborted) return null;
59
- throw error;
60
- }
61
- });
62
- const signatureResult = await Promise.any(confirmPromises.map(async (promise) => {
63
- const result = await promise;
64
- if (!result) throw NULL_CONFIRMATION_RESULT;
65
- return result;
66
- })).catch(() => null);
67
- if (!abortController.signal.aborted) abortController.abort();
68
- return {
69
- signatureResult,
70
- txSignature
39
+ const resend = async (rpc, signal) => {
40
+ await rpc.sendTransaction(signedTxSerialized, rawTransactionOptions).send({ abortSignal: signal });
41
+ };
42
+ const result = await require_confirmation_raceRpcs.raceRpcs(solanaRpcs, (rpc, signal) => require_confirmation_confirmSignature.confirmSignature({
43
+ rpc,
44
+ signal,
45
+ signature: txSignature,
46
+ lifetimes: [lifetime],
47
+ resend,
48
+ onBroadcast: reportBroadcast
49
+ }), { timeoutMs: require_confirmation_createConfirmationDeadline.BRANCH_TIMEOUT_MS });
50
+ if (result.kind === "not-confirmed" && !sendAccepted) return {
51
+ kind: "rpc-unavailable",
52
+ errors: result.errors
71
53
  };
54
+ return result;
72
55
  }
73
56
  //#endregion
74
57
  exports.sendAndConfirmTransaction = sendAndConfirmTransaction;
@@ -1 +1 @@
1
- {"version":3,"file":"sendAndConfirmTransaction.js","names":["getSolanaRpcs","getBase64EncodedWireTransaction","getSignatureFromTransaction","sleep"],"sources":["../../../src/actions/sendAndConfirmTransaction.ts"],"sourcesContent":["import { type SDKClient, sleep } from '@lifi/sdk'\nimport {\n type Commitment,\n getBase64EncodedWireTransaction,\n getSignatureFromTransaction,\n type Transaction,\n type TransactionError,\n} from '@solana/kit'\nimport { getSolanaRpcs } from '../rpc/registry.js'\n\ntype SignatureStatus = {\n slot: bigint\n confirmations: bigint | null\n err: TransactionError | null\n confirmationStatus: Commitment | null\n status: Readonly<{ Err: TransactionError }> | Readonly<{ Ok: null }>\n}\n\ntype ConfirmedTransactionResult = {\n signatureResult: SignatureStatus | null\n txSignature: string\n}\n\nconst NULL_CONFIRMATION_RESULT = new Error(\n 'Transaction was not confirmed by this RPC'\n)\n\n/**\n * Sends a Solana transaction to multiple RPC endpoints and returns the confirmation\n * as soon as any of them confirm the transaction.\n * @param client - The SDK client.\n * @param signedTransaction - The signed transaction to send.\n * @returns - The confirmation result of the transaction.\n */\nexport async function sendAndConfirmTransaction(\n client: SDKClient,\n signedTransaction: Transaction\n): Promise<ConfirmedTransactionResult> {\n const solanaRpcs = await getSolanaRpcs(client)\n\n const signedTxSerialized = getBase64EncodedWireTransaction(signedTransaction)\n // Create transaction hash (signature)\n const txSignature = getSignatureFromTransaction(signedTransaction)\n\n if (!txSignature) {\n throw new Error('Transaction signature is missing.')\n }\n\n const rawTransactionOptions = {\n // We can skip preflight check after the first transaction has been sent\n // https://solana.com/docs/advanced/retry#the-cost-of-skipping-preflight\n skipPreflight: true,\n // Setting max retries to 0 as we are handling retries manually\n maxRetries: BigInt(0),\n // https://solana.com/docs/advanced/confirmation#use-an-appropriate-preflight-commitment-level\n preflightCommitment: 'confirmed' as Commitment,\n encoding: 'base64' as const,\n }\n\n const abortController = new AbortController()\n\n const confirmPromises = solanaRpcs.map(async (rpc) => {\n try {\n // Send initial transaction for this RPC\n try {\n await rpc\n .sendTransaction(signedTxSerialized, rawTransactionOptions)\n .send()\n } catch (_) {\n // Continue with confirmation even if initial send fails\n }\n\n const [{ value: blockhashResult }, initialBlockHeight] =\n await Promise.all([\n rpc\n .getLatestBlockhash({\n commitment: 'confirmed',\n })\n .send(),\n rpc\n .getBlockHeight({\n commitment: 'confirmed',\n })\n .send(),\n ])\n\n let signatureResult: SignatureStatus | null = null\n let blockHeight = initialBlockHeight\n const pollingPromise = (async () => {\n while (\n blockHeight < blockhashResult.lastValidBlockHeight &&\n !abortController.signal.aborted\n ) {\n const statusResponse = await rpc\n .getSignatureStatuses([txSignature])\n .send()\n\n const status = statusResponse.value[0]\n if (\n status &&\n (status.confirmationStatus === 'confirmed' ||\n status.confirmationStatus === 'finalized')\n ) {\n signatureResult = status\n // Immediately abort all other RPCs when we find a result\n abortController.abort()\n return status\n }\n\n await sleep(400)\n }\n return null\n })()\n\n const sendingPromise = (async () => {\n while (\n blockHeight < blockhashResult.lastValidBlockHeight &&\n !abortController.signal.aborted &&\n !signatureResult\n ) {\n try {\n await rpc\n .sendTransaction(signedTxSerialized, rawTransactionOptions)\n .send()\n } catch (_) {\n // Continue trying even if individual sends fail\n }\n\n await sleep(1000)\n if (!abortController.signal.aborted) {\n blockHeight = await rpc\n .getBlockHeight({\n commitment: 'confirmed',\n })\n .send()\n }\n }\n return null\n })()\n\n // Wait for polling to find the result\n const result = await Promise.race([pollingPromise, sendingPromise])\n return result\n } catch (error) {\n if (abortController.signal.aborted) {\n return null // Don't treat abortion as an error\n }\n throw error\n }\n })\n\n const signatureResult = await Promise.any(\n confirmPromises.map(async (promise) => {\n const result = await promise\n if (!result) {\n throw NULL_CONFIRMATION_RESULT\n }\n return result\n })\n ).catch(() => null)\n\n if (!abortController.signal.aborted) {\n abortController.abort()\n }\n\n return { signatureResult, txSignature }\n}\n"],"mappings":";;;;;AAuBA,MAAM,2CAA2B,IAAI,MACnC,2CACF;;;;;;;;AASA,eAAsB,0BACpB,QACA,mBACqC;CACrC,MAAM,aAAa,MAAMA,qBAAAA,cAAc,MAAM;CAE7C,MAAM,sBAAA,GAAqBC,YAAAA,gCAAAA,CAAgC,iBAAiB;CAE5E,MAAM,eAAA,GAAcC,YAAAA,4BAAAA,CAA4B,iBAAiB;CAEjE,IAAI,CAAC,aACH,MAAM,IAAI,MAAM,mCAAmC;CAGrD,MAAM,wBAAwB;EAG5B,eAAe;EAEf,YAAY,OAAO,CAAC;EAEpB,qBAAqB;EACrB,UAAU;CACZ;CAEA,MAAM,kBAAkB,IAAI,gBAAgB;CAE5C,MAAM,kBAAkB,WAAW,IAAI,OAAO,QAAQ;EACpD,IAAI;GAEF,IAAI;IACF,MAAM,IACH,gBAAgB,oBAAoB,qBAAqB,CAAC,CAC1D,KAAK;GACV,SAAS,GAAG,CAEZ;GAEA,MAAM,CAAC,EAAE,OAAO,mBAAmB,sBACjC,MAAM,QAAQ,IAAI,CAChB,IACG,mBAAmB,EAClB,YAAY,YACd,CAAC,CAAC,CACD,KAAK,GACR,IACG,eAAe,EACd,YAAY,YACd,CAAC,CAAC,CACD,KAAK,CACV,CAAC;GAEH,IAAI,kBAA0C;GAC9C,IAAI,cAAc;GAClB,MAAM,kBAAkB,YAAY;IAClC,OACE,cAAc,gBAAgB,wBAC9B,CAAC,gBAAgB,OAAO,SACxB;KAKA,MAAM,UAAS,MAJc,IAC1B,qBAAqB,CAAC,WAAW,CAAC,CAAC,CACnC,KAAK,EAAA,CAEsB,MAAM;KACpC,IACE,WACC,OAAO,uBAAuB,eAC7B,OAAO,uBAAuB,cAChC;MACA,kBAAkB;MAElB,gBAAgB,MAAM;MACtB,OAAO;KACT;KAEA,OAAA,GAAMC,UAAAA,MAAAA,CAAM,GAAG;IACjB;IACA,OAAO;GACT,EAAA,CAAG;GAEH,MAAM,kBAAkB,YAAY;IAClC,OACE,cAAc,gBAAgB,wBAC9B,CAAC,gBAAgB,OAAO,WACxB,CAAC,iBACD;KACA,IAAI;MACF,MAAM,IACH,gBAAgB,oBAAoB,qBAAqB,CAAC,CAC1D,KAAK;KACV,SAAS,GAAG,CAEZ;KAEA,OAAA,GAAMA,UAAAA,MAAAA,CAAM,GAAI;KAChB,IAAI,CAAC,gBAAgB,OAAO,SAC1B,cAAc,MAAM,IACjB,eAAe,EACd,YAAY,YACd,CAAC,CAAC,CACD,KAAK;IAEZ;IACA,OAAO;GACT,EAAA,CAAG;GAIH,OAAO,MADc,QAAQ,KAAK,CAAC,gBAAgB,cAAc,CAAC;EAEpE,SAAS,OAAO;GACd,IAAI,gBAAgB,OAAO,SACzB,OAAO;GAET,MAAM;EACR;CACF,CAAC;CAED,MAAM,kBAAkB,MAAM,QAAQ,IACpC,gBAAgB,IAAI,OAAO,YAAY;EACrC,MAAM,SAAS,MAAM;EACrB,IAAI,CAAC,QACH,MAAM;EAER,OAAO;CACT,CAAC,CACH,CAAC,CAAC,YAAY,IAAI;CAElB,IAAI,CAAC,gBAAgB,OAAO,SAC1B,gBAAgB,MAAM;CAGxB,OAAO;EAAE;EAAiB;CAAY;AACxC"}
1
+ {"version":3,"file":"sendAndConfirmTransaction.js","names":["getSolanaRpcs","getBase64EncodedWireTransaction","getSignatureFromTransaction","getTransactionLifetime","raceRpcs","confirmSignature","BRANCH_TIMEOUT_MS"],"sources":["../../../src/actions/sendAndConfirmTransaction.ts"],"sourcesContent":["import type { SDKClient } from '@lifi/sdk'\nimport {\n type Commitment,\n getBase64EncodedWireTransaction,\n getSignatureFromTransaction,\n type Transaction,\n} from '@solana/kit'\nimport { confirmSignature } from '../confirmation/confirmSignature.js'\nimport { BRANCH_TIMEOUT_MS } from '../confirmation/createConfirmationDeadline.js'\nimport { type RaceResult, raceRpcs } from '../confirmation/raceRpcs.js'\nimport type { SignatureStatus } from '../confirmation/types.js'\nimport { getSolanaRpcs } from '../rpc/registry.js'\nimport type { SolanaRpcType } from '../rpc/types.js'\nimport { getTransactionLifetime } from '../utils/getTransactionLifetime.js'\n\n/**\n * Sends a Solana transaction to every configured RPC and returns as soon as\n * one of them confirms it.\n *\n * The polling horizon comes from the signed transaction's own blockhash and a\n * wall-clock ceiling. It deliberately never comes from `getBlockHeight`: at\n * least one endpoint in the default LI.FI set answers that call with the slot\n * number.\n */\nexport async function sendAndConfirmTransaction(\n client: SDKClient,\n signedTransaction: Transaction,\n options?: {\n /** Runs once, when the first RPC accepts a send. */\n onBroadcast?: () => void\n }\n): Promise<RaceResult<SignatureStatus>> {\n const solanaRpcs = await getSolanaRpcs(client)\n\n let broadcastReported = false\n // Distinct from `broadcastReported`, which records whether the integrator\n // callback has *succeeded*. This one answers \"did any RPC accept the send?\",\n // and only that question may steer the verdict below. Set before the callback\n // runs, so a hook that throws on every resend cannot make a real expiry look\n // like an outage.\n let sendAccepted = false\n const reportBroadcast = (): void => {\n sendAccepted = true\n if (broadcastReported) {\n return\n }\n try {\n options?.onBroadcast?.()\n // Latched only after the callback returned. A callback that threw wrote\n // nothing, so the next successful send must be allowed to try again -\n // latching first made one failed `txLink` write permanent.\n broadcastReported = true\n } catch (_) {\n // This runs integrator code: the callback reaches `updateRouteHook` via\n // `StatusManager.updateAction`. Its failure must never reject the branch\n // that called it - the send has already been accepted by the network at\n // this point, so a throw here would report a landed transaction as an\n // RPC outage. Swallowed rather than surfaced because there is no verdict\n // it could honestly change.\n }\n }\n\n const signedTxSerialized = getBase64EncodedWireTransaction(signedTransaction)\n const txSignature = getSignatureFromTransaction(signedTransaction)\n\n const lifetime = await getTransactionLifetime(signedTransaction)\n\n const rawTransactionOptions = {\n // We can skip preflight check after the first transaction has been sent\n // https://solana.com/docs/advanced/retry#the-cost-of-skipping-preflight\n skipPreflight: true,\n // Setting max retries to 0 as we are handling retries manually\n maxRetries: BigInt(0),\n // https://solana.com/docs/advanced/confirmation#use-an-appropriate-preflight-commitment-level\n preflightCommitment: 'confirmed' as Commitment,\n encoding: 'base64' as const,\n }\n\n const resend = async (\n rpc: SolanaRpcType,\n signal: AbortSignal\n ): Promise<void> => {\n await rpc\n .sendTransaction(signedTxSerialized, rawTransactionOptions)\n .send({ abortSignal: signal })\n }\n\n const result = await raceRpcs(\n solanaRpcs,\n (rpc, signal) =>\n confirmSignature({\n rpc,\n signal,\n signature: txSignature,\n lifetimes: [lifetime],\n resend,\n onBroadcast: reportBroadcast,\n }),\n { timeoutMs: BRANCH_TIMEOUT_MS }\n )\n\n // Only this scope knows whether ANY branch accepted the send. A branch that\n // polls to its deadline reports `not-confirmed` regardless - correct per\n // branch, but across the whole race it would claim a transaction expired\n // when nothing ever submitted it. That is an outage, not an expiry.\n //\n // Reads `sendAccepted`, never `broadcastReported`: the latter is false\n // whenever the integrator's callback threw, which says nothing about whether\n // the network took the transaction.\n if (result.kind === 'not-confirmed' && !sendAccepted) {\n return { kind: 'rpc-unavailable', errors: result.errors }\n }\n\n return result\n}\n"],"mappings":";;;;;;;;;;;;;;;;;AAwBA,eAAsB,0BACpB,QACA,mBACA,SAIsC;CACtC,MAAM,aAAa,MAAMA,qBAAAA,cAAc,MAAM;CAE7C,IAAI,oBAAoB;CAMxB,IAAI,eAAe;CACnB,MAAM,wBAA8B;EAClC,eAAe;EACf,IAAI,mBACF;EAEF,IAAI;GACF,SAAS,cAAc;GAIvB,oBAAoB;EACtB,SAAS,GAAG,CAOZ;CACF;CAEA,MAAM,sBAAA,GAAqBC,YAAAA,gCAAAA,CAAgC,iBAAiB;CAC5E,MAAM,eAAA,GAAcC,YAAAA,4BAAAA,CAA4B,iBAAiB;CAEjE,MAAM,WAAW,MAAMC,qCAAAA,uBAAuB,iBAAiB;CAE/D,MAAM,wBAAwB;EAG5B,eAAe;EAEf,YAAY,OAAO,CAAC;EAEpB,qBAAqB;EACrB,UAAU;CACZ;CAEA,MAAM,SAAS,OACb,KACA,WACkB;EAClB,MAAM,IACH,gBAAgB,oBAAoB,qBAAqB,CAAC,CAC1D,KAAK,EAAE,aAAa,OAAO,CAAC;CACjC;CAEA,MAAM,SAAS,MAAMC,8BAAAA,SACnB,aACC,KAAK,WACJC,sCAAAA,iBAAiB;EACf;EACA;EACA,WAAW;EACX,WAAW,CAAC,QAAQ;EACpB;EACA,aAAa;CACf,CAAC,GACH,EAAE,WAAWC,gDAAAA,kBAAkB,CACjC;CAUA,IAAI,OAAO,SAAS,mBAAmB,CAAC,cACtC,OAAO;EAAE,MAAM;EAAmB,QAAQ,OAAO;CAAO;CAG1D,OAAO;AACT"}
@@ -0,0 +1,19 @@
1
+ //#region src/confirmation/abortableSleep.d.ts
2
+ /**
3
+ * Sleeps for `ms`, or until `signal` aborts - whichever comes first.
4
+ *
5
+ * Not `@lifi/sdk`'s `sleep`: that one is publicly exported, so making its
6
+ * timer abortable or unref'd would change behaviour for every caller in the
7
+ * repo. The confirmation branches need the abort, because both detached loops
8
+ * here sleep between iterations and a plain timer stays alive for the whole
9
+ * interval after the branch has already returned - one live timer per RPC,
10
+ * holding the Node event loop open past the end of a race.
11
+ *
12
+ * Never rejects on abort. The callers re-check `signal.aborted` and exit
13
+ * through their own loop condition, so a rejection here would only add a
14
+ * catch to every call site.
15
+ */
16
+ declare function abortableSleep(ms: number, signal: AbortSignal): Promise<void>;
17
+ //#endregion
18
+ export { abortableSleep };
19
+ //# sourceMappingURL=abortableSleep.d.ts.map
@@ -0,0 +1,32 @@
1
+ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
2
+ //#region src/confirmation/abortableSleep.ts
3
+ /**
4
+ * Sleeps for `ms`, or until `signal` aborts - whichever comes first.
5
+ *
6
+ * Not `@lifi/sdk`'s `sleep`: that one is publicly exported, so making its
7
+ * timer abortable or unref'd would change behaviour for every caller in the
8
+ * repo. The confirmation branches need the abort, because both detached loops
9
+ * here sleep between iterations and a plain timer stays alive for the whole
10
+ * interval after the branch has already returned - one live timer per RPC,
11
+ * holding the Node event loop open past the end of a race.
12
+ *
13
+ * Never rejects on abort. The callers re-check `signal.aborted` and exit
14
+ * through their own loop condition, so a rejection here would only add a
15
+ * catch to every call site.
16
+ */
17
+ function abortableSleep(ms, signal) {
18
+ if (signal.aborted) return Promise.resolve();
19
+ return new Promise((resolve) => {
20
+ const settle = () => {
21
+ clearTimeout(timer);
22
+ signal.removeEventListener("abort", settle);
23
+ resolve();
24
+ };
25
+ const timer = setTimeout(settle, ms);
26
+ signal.addEventListener("abort", settle, { once: true });
27
+ });
28
+ }
29
+ //#endregion
30
+ exports.abortableSleep = abortableSleep;
31
+
32
+ //# sourceMappingURL=abortableSleep.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"abortableSleep.js","names":[],"sources":["../../../src/confirmation/abortableSleep.ts"],"sourcesContent":["/**\n * Sleeps for `ms`, or until `signal` aborts - whichever comes first.\n *\n * Not `@lifi/sdk`'s `sleep`: that one is publicly exported, so making its\n * timer abortable or unref'd would change behaviour for every caller in the\n * repo. The confirmation branches need the abort, because both detached loops\n * here sleep between iterations and a plain timer stays alive for the whole\n * interval after the branch has already returned - one live timer per RPC,\n * holding the Node event loop open past the end of a race.\n *\n * Never rejects on abort. The callers re-check `signal.aborted` and exit\n * through their own loop condition, so a rejection here would only add a\n * catch to every call site.\n */\nexport function abortableSleep(ms: number, signal: AbortSignal): Promise<void> {\n if (signal.aborted) {\n return Promise.resolve()\n }\n\n return new Promise<void>((resolve) => {\n const settle = (): void => {\n clearTimeout(timer)\n signal.removeEventListener('abort', settle)\n resolve()\n }\n\n const timer = setTimeout(settle, ms)\n signal.addEventListener('abort', settle, { once: true })\n })\n}\n"],"mappings":";;;;;;;;;;;;;;;;AAcA,SAAgB,eAAe,IAAY,QAAoC;CAC7E,IAAI,OAAO,SACT,OAAO,QAAQ,QAAQ;CAGzB,OAAO,IAAI,SAAe,YAAY;EACpC,MAAM,eAAqB;GACzB,aAAa,KAAK;GAClB,OAAO,oBAAoB,SAAS,MAAM;GAC1C,QAAQ;EACV;EAEA,MAAM,QAAQ,WAAW,QAAQ,EAAE;EACnC,OAAO,iBAAiB,SAAS,QAAQ,EAAE,MAAM,KAAK,CAAC;CACzD,CAAC;AACH"}
@@ -0,0 +1,43 @@
1
+ import { JitoRpcType } from "../rpc/types.js";
2
+ import { TransactionLifetime } from "../utils/getTransactionLifetime.js";
3
+ import { ConfirmationOutcome, SignatureStatus } from "./types.js";
4
+ import { Signature } from "@solana/kit";
5
+ //#region src/confirmation/confirmBundle.d.ts
6
+ /** Slower than the signature poller's 400 ms: Jito documents 1 req/s per IP
7
+ * per region. At 2 s this holds 0.5 req/s, leaving room for the deadline's
8
+ * blockhash probes on the same endpoint. */
9
+ declare const BUNDLE_POLL_INTERVAL_MS = 2e3;
10
+ type BundleConfirmation = {
11
+ /** The submission's own id, carried for diagnostics. */
12
+ bundleId: string;
13
+ /** Never read for a `txHash` - its order is Jito's to choose. Kept so the
14
+ * reversed-list regression stays expressible in the wait-task spec. */
15
+ txSignatures: Signature[];
16
+ signatureResults: readonly (SignatureStatus | null)[];
17
+ /** Bundle-level `err`, verbatim. Jito encodes it as a Rust `Result`, so a
18
+ * landed bundle carries `{ Ok: null }` - never truthiness-check it. */
19
+ bundleErr: unknown;
20
+ };
21
+ /**
22
+ * Confirms one Jito bundle against one Jito RPC.
23
+ *
24
+ * Bundles submit once, so there is no resend loop. `send` is owned here so the
25
+ * deadline starts before submission rather than after it. A `send` failure
26
+ * throws, which `raceRpcs` buckets as `rpc-unavailable`.
27
+ */
28
+ declare function confirmBundle(options: {
29
+ rpc: JitoRpcType;
30
+ signal: AbortSignal;
31
+ lifetimes: TransactionLifetime[];
32
+ send: () => Promise<string>;
33
+ /**
34
+ * Reports that this RPC accepted the bundle submission. Must not throw -
35
+ * `sendAndConfirmBundle` contains any throw from the integrator callback it
36
+ * wraps, because a throw here would reject a branch whose bundle Jito had
37
+ * already accepted.
38
+ */
39
+ onBroadcast?: () => void;
40
+ }): Promise<ConfirmationOutcome<BundleConfirmation>>;
41
+ //#endregion
42
+ export { BUNDLE_POLL_INTERVAL_MS, BundleConfirmation, confirmBundle };
43
+ //# sourceMappingURL=confirmBundle.d.ts.map