@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,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 as TransactionError$1 } 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$1 | null;
8
- confirmationStatus: Commitment | null;
9
- status: Readonly<{
10
- Err: TransactionError$1;
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 +1 @@
1
- {"version":3,"file":"sendAndConfirmTransaction.d.ts","names":[],"sources":["../../../src/actions/sendAndConfirmTransaction.ts"],"mappings":";;;KAUK;EACH;EACA;EACA,KAAK;EACL,oBAAoB;EACpB,QAAQ;IAAW,KAAK;OAAsB;IAAW;;;KAGtD;EACH,iBAAiB;EACjB;;;;;;;;;iBAcoB,0BACpB,QAAQ,WACR,mBAAmB,cAClB,QAAQ"}
1
+ {"version":3,"file":"sendAndConfirmTransaction.d.ts","names":[],"sources":["../../../src/actions/sendAndConfirmTransaction.ts"],"mappings":";;;;;;;;;;;;;;iBAwBsB,0BACpB,QAAQ,WACR,mBAAmB,aACnB;;EAEE;IAED,QAAQ,WAAW"}
@@ -1,73 +1,56 @@
1
1
  import { getSolanaRpcs } from "../rpc/registry.js";
2
- import { sleep } from "@lifi/sdk";
2
+ import { BRANCH_TIMEOUT_MS } from "../confirmation/createConfirmationDeadline.js";
3
+ import { raceRpcs } from "../confirmation/raceRpcs.js";
4
+ import { getTransactionLifetime } from "../utils/getTransactionLifetime.js";
5
+ import { confirmSignature } from "../confirmation/confirmSignature.js";
3
6
  import { getBase64EncodedWireTransaction, getSignatureFromTransaction } from "@solana/kit";
4
7
  //#region src/actions/sendAndConfirmTransaction.ts
5
- const NULL_CONFIRMATION_RESULT = /* @__PURE__ */ new Error("Transaction was not confirmed by this RPC");
6
8
  /**
7
- * Sends a Solana transaction to multiple RPC endpoints and returns the confirmation
8
- * as soon as any of them confirm the transaction.
9
- * @param client - The SDK client.
10
- * @param signedTransaction - The signed transaction to send.
11
- * @returns - The confirmation result of the transaction.
9
+ * Sends a Solana transaction to every configured RPC and returns as soon as
10
+ * one of them confirms it.
11
+ *
12
+ * The polling horizon comes from the signed transaction's own blockhash and a
13
+ * wall-clock ceiling. It deliberately never comes from `getBlockHeight`: at
14
+ * least one endpoint in the default LI.FI set answers that call with the slot
15
+ * number.
12
16
  */
13
- async function sendAndConfirmTransaction(client, signedTransaction) {
17
+ async function sendAndConfirmTransaction(client, signedTransaction, options) {
14
18
  const solanaRpcs = await getSolanaRpcs(client);
19
+ let broadcastReported = false;
20
+ let sendAccepted = false;
21
+ const reportBroadcast = () => {
22
+ sendAccepted = true;
23
+ if (broadcastReported) return;
24
+ try {
25
+ options?.onBroadcast?.();
26
+ broadcastReported = true;
27
+ } catch (_) {}
28
+ };
15
29
  const signedTxSerialized = getBase64EncodedWireTransaction(signedTransaction);
16
30
  const txSignature = getSignatureFromTransaction(signedTransaction);
17
- if (!txSignature) throw new Error("Transaction signature is missing.");
31
+ const lifetime = await getTransactionLifetime(signedTransaction);
18
32
  const rawTransactionOptions = {
19
33
  skipPreflight: true,
20
34
  maxRetries: BigInt(0),
21
35
  preflightCommitment: "confirmed",
22
36
  encoding: "base64"
23
37
  };
24
- const abortController = new AbortController();
25
- const confirmPromises = solanaRpcs.map(async (rpc) => {
26
- try {
27
- try {
28
- await rpc.sendTransaction(signedTxSerialized, rawTransactionOptions).send();
29
- } catch (_) {}
30
- const [{ value: blockhashResult }, initialBlockHeight] = await Promise.all([rpc.getLatestBlockhash({ commitment: "confirmed" }).send(), rpc.getBlockHeight({ commitment: "confirmed" }).send()]);
31
- let signatureResult = null;
32
- let blockHeight = initialBlockHeight;
33
- const pollingPromise = (async () => {
34
- while (blockHeight < blockhashResult.lastValidBlockHeight && !abortController.signal.aborted) {
35
- const status = (await rpc.getSignatureStatuses([txSignature]).send()).value[0];
36
- if (status && (status.confirmationStatus === "confirmed" || status.confirmationStatus === "finalized")) {
37
- signatureResult = status;
38
- abortController.abort();
39
- return status;
40
- }
41
- await sleep(400);
42
- }
43
- return null;
44
- })();
45
- const sendingPromise = (async () => {
46
- while (blockHeight < blockhashResult.lastValidBlockHeight && !abortController.signal.aborted && !signatureResult) {
47
- try {
48
- await rpc.sendTransaction(signedTxSerialized, rawTransactionOptions).send();
49
- } catch (_) {}
50
- await sleep(1e3);
51
- if (!abortController.signal.aborted) blockHeight = await rpc.getBlockHeight({ commitment: "confirmed" }).send();
52
- }
53
- return null;
54
- })();
55
- return await Promise.race([pollingPromise, sendingPromise]);
56
- } catch (error) {
57
- if (abortController.signal.aborted) return null;
58
- throw error;
59
- }
60
- });
61
- const signatureResult = await Promise.any(confirmPromises.map(async (promise) => {
62
- const result = await promise;
63
- if (!result) throw NULL_CONFIRMATION_RESULT;
64
- return result;
65
- })).catch(() => null);
66
- if (!abortController.signal.aborted) abortController.abort();
67
- return {
68
- signatureResult,
69
- txSignature
38
+ const resend = async (rpc, signal) => {
39
+ await rpc.sendTransaction(signedTxSerialized, rawTransactionOptions).send({ abortSignal: signal });
40
+ };
41
+ const result = await raceRpcs(solanaRpcs, (rpc, signal) => confirmSignature({
42
+ rpc,
43
+ signal,
44
+ signature: txSignature,
45
+ lifetimes: [lifetime],
46
+ resend,
47
+ onBroadcast: reportBroadcast
48
+ }), { timeoutMs: BRANCH_TIMEOUT_MS });
49
+ if (result.kind === "not-confirmed" && !sendAccepted) return {
50
+ kind: "rpc-unavailable",
51
+ errors: result.errors
70
52
  };
53
+ return result;
71
54
  }
72
55
  //#endregion
73
56
  export { sendAndConfirmTransaction };
@@ -1 +1 @@
1
- {"version":3,"file":"sendAndConfirmTransaction.js","names":[],"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,MAAM,cAAc,MAAM;CAE7C,MAAM,qBAAqB,gCAAgC,iBAAiB;CAE5E,MAAM,cAAc,4BAA4B,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,MAAM,MAAM,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,MAAM,MAAM,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":[],"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,MAAM,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,qBAAqB,gCAAgC,iBAAiB;CAC5E,MAAM,cAAc,4BAA4B,iBAAiB;CAEjE,MAAM,WAAW,MAAM,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,MAAM,SACnB,aACC,KAAK,WACJ,iBAAiB;EACf;EACA;EACA,WAAW;EACX,WAAW,CAAC,QAAQ;EACpB;EACA,aAAa;CACf,CAAC,GACH,EAAE,WAAW,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 @@
1
+ {"version":3,"file":"abortableSleep.d.ts","names":[],"sources":["../../../src/confirmation/abortableSleep.ts"],"mappings":";;;;;;;;;;;;;;;iBAcgB,eAAe,YAAY,QAAQ,cAAc"}
@@ -0,0 +1,31 @@
1
+ //#region src/confirmation/abortableSleep.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
+ function abortableSleep(ms, signal) {
17
+ if (signal.aborted) return Promise.resolve();
18
+ return new Promise((resolve) => {
19
+ const settle = () => {
20
+ clearTimeout(timer);
21
+ signal.removeEventListener("abort", settle);
22
+ resolve();
23
+ };
24
+ const timer = setTimeout(settle, ms);
25
+ signal.addEventListener("abort", settle, { once: true });
26
+ });
27
+ }
28
+ //#endregion
29
+ export { abortableSleep };
30
+
31
+ //# 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
@@ -0,0 +1 @@
1
+ {"version":3,"file":"confirmBundle.d.ts","names":[],"sources":["../../../src/confirmation/confirmBundle.ts"],"mappings":";;;;;;;;cAca;KAED;;EAEV;;;EAGA,cAAc;EACd,4BAA4B;;;EAG5B;;;;;;;;;iBAUoB,cAAc;EAClC,KAAK;EACL,QAAQ;EACR,WAAW;EACX,YAAY;;;;;;;EAOZ;IACE,QAAQ,oBAAoB"}
@@ -0,0 +1,55 @@
1
+ import { createConfirmationDeadline } from "./createConfirmationDeadline.js";
2
+ import { pollUntilDeadline } from "./pollUntilDeadline.js";
3
+ import { isConfirmedCommitment } from "./types.js";
4
+ //#region src/confirmation/confirmBundle.ts
5
+ /** Slower than the signature poller's 400 ms: Jito documents 1 req/s per IP
6
+ * per region. At 2 s this holds 0.5 req/s, leaving room for the deadline's
7
+ * blockhash probes on the same endpoint. */
8
+ const BUNDLE_POLL_INTERVAL_MS = 2e3;
9
+ /**
10
+ * Confirms one Jito bundle against one Jito RPC.
11
+ *
12
+ * Bundles submit once, so there is no resend loop. `send` is owned here so the
13
+ * deadline starts before submission rather than after it. A `send` failure
14
+ * throws, which `raceRpcs` buckets as `rpc-unavailable`.
15
+ */
16
+ async function confirmBundle(options) {
17
+ const { rpc, signal, lifetimes, send } = options;
18
+ const deadline = createConfirmationDeadline({
19
+ lifetimes,
20
+ rpc
21
+ });
22
+ const bundleId = await send();
23
+ if (!signal.aborted) options.onBroadcast?.();
24
+ const readBundle = async () => {
25
+ const bundleStatus = (await rpc.getBundleStatuses([bundleId]).send({ abortSignal: signal }))?.value?.[0];
26
+ if (!bundleStatus || !isConfirmedCommitment(bundleStatus.confirmation_status)) return null;
27
+ const txSignatures = Array.isArray(bundleStatus.transactions) ? bundleStatus.transactions : [];
28
+ let signatureResults;
29
+ if (txSignatures.length === 0) signatureResults = [];
30
+ else try {
31
+ const sigResponse = await rpc.getSignatureStatuses(txSignatures).send({ abortSignal: signal });
32
+ signatureResults = Array.isArray(sigResponse?.value) ? sigResponse.value : txSignatures.map(() => null);
33
+ } catch (_) {
34
+ signatureResults = txSignatures.map(() => null);
35
+ }
36
+ return {
37
+ bundleId,
38
+ txSignatures,
39
+ signatureResults,
40
+ bundleErr: bundleStatus.err
41
+ };
42
+ };
43
+ return pollUntilDeadline({
44
+ deadline,
45
+ signal,
46
+ pollIntervalMs: BUNDLE_POLL_INTERVAL_MS,
47
+ probe: readBundle,
48
+ read: "bundle status read",
49
+ subject: "bundle"
50
+ });
51
+ }
52
+ //#endregion
53
+ export { BUNDLE_POLL_INTERVAL_MS, confirmBundle };
54
+
55
+ //# sourceMappingURL=confirmBundle.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"confirmBundle.js","names":[],"sources":["../../../src/confirmation/confirmBundle.ts"],"sourcesContent":["import type { Signature } from '@solana/kit'\nimport type { JitoRpcType } from '../rpc/types.js'\nimport type { TransactionLifetime } from '../utils/getTransactionLifetime.js'\nimport { createConfirmationDeadline } from './createConfirmationDeadline.js'\nimport { pollUntilDeadline } from './pollUntilDeadline.js'\nimport {\n type ConfirmationOutcome,\n isConfirmedCommitment,\n type SignatureStatus,\n} from './types.js'\n\n/** Slower than the signature poller's 400 ms: Jito documents 1 req/s per IP\n * per region. At 2 s this holds 0.5 req/s, leaving room for the deadline's\n * blockhash probes on the same endpoint. */\nexport const BUNDLE_POLL_INTERVAL_MS = 2_000\n\nexport type BundleConfirmation = {\n /** The submission's own id, carried for diagnostics. */\n bundleId: string\n /** Never read for a `txHash` - its order is Jito's to choose. Kept so the\n * reversed-list regression stays expressible in the wait-task spec. */\n txSignatures: Signature[]\n signatureResults: readonly (SignatureStatus | null)[]\n /** Bundle-level `err`, verbatim. Jito encodes it as a Rust `Result`, so a\n * landed bundle carries `{ Ok: null }` - never truthiness-check it. */\n bundleErr: unknown\n}\n\n/**\n * Confirms one Jito bundle against one Jito RPC.\n *\n * Bundles submit once, so there is no resend loop. `send` is owned here so the\n * deadline starts before submission rather than after it. A `send` failure\n * throws, which `raceRpcs` buckets as `rpc-unavailable`.\n */\nexport async function confirmBundle(options: {\n rpc: JitoRpcType\n signal: AbortSignal\n lifetimes: TransactionLifetime[]\n send: () => Promise<string>\n /**\n * Reports that this RPC accepted the bundle submission. Must not throw -\n * `sendAndConfirmBundle` contains any throw from the integrator callback it\n * wraps, because a throw here would reject a branch whose bundle Jito had\n * already accepted.\n */\n onBroadcast?: () => void\n}): Promise<ConfirmationOutcome<BundleConfirmation>> {\n const { rpc, signal, lifetimes, send } = options\n const deadline = createConfirmationDeadline({ lifetimes, rpc })\n\n const bundleId = await send()\n // Guarded like `confirmSignature`'s send sites: the caller's once-guard\n // latches only after the callback returns, so a throwing integrator hook\n // leaves it open and a late `sendBundle` fulfilment would re-write a\n // finalized action back to PENDING.\n if (!signal.aborted) {\n options.onBroadcast?.()\n }\n\n const readBundle = async (): Promise<BundleConfirmation | null> => {\n const statusResponse = await rpc\n .getBundleStatuses([bundleId])\n .send({ abortSignal: signal })\n // A `{ value: null }` answer responded but said nothing - poll again\n // rather than throw a `TypeError` into the read-failure budget.\n const bundleStatus = statusResponse?.value?.[0]\n if (\n !bundleStatus ||\n !isConfirmedCommitment(bundleStatus.confirmation_status)\n ) {\n return null\n }\n\n // Unvalidated wire data: without this guard a confirmed status carrying\n // no `transactions` makes every `.map` below a `TypeError`, and a landed\n // bundle would report as `rpc-unavailable`.\n // `Array.isArray`, not `??`: the wire data is unvalidated, and a truthy\n // non-array keeps the declared array type while throwing out of `.map`.\n const txSignatures = Array.isArray(bundleStatus.transactions)\n ? bundleStatus.transactions\n : []\n\n // The bundle status is the atomic fact: a bundle lands whole or not at\n // all. `getSignatureStatuses` only enriches it with per-transaction `err`\n // detail, so an unusable response degrades to all-`null` and must never\n // veto a confirmation the status already made.\n let signatureResults: BundleConfirmation['signatureResults']\n if (txSignatures.length === 0) {\n // Nothing to enrich; the status already confirmed the bundle.\n signatureResults = []\n } else {\n try {\n const sigResponse = await rpc\n .getSignatureStatuses(txSignatures)\n .send({ abortSignal: signal })\n signatureResults = Array.isArray(sigResponse?.value)\n ? sigResponse.value\n : txSignatures.map(() => null)\n } catch (_) {\n signatureResults = txSignatures.map(() => null)\n }\n }\n\n return {\n bundleId,\n txSignatures,\n signatureResults,\n bundleErr: bundleStatus.err,\n }\n }\n\n return pollUntilDeadline({\n deadline,\n signal,\n pollIntervalMs: BUNDLE_POLL_INTERVAL_MS,\n probe: readBundle,\n read: 'bundle status read',\n subject: 'bundle',\n })\n}\n"],"mappings":";;;;;;;AAcA,MAAa,0BAA0B;;;;;;;;AAqBvC,eAAsB,cAAc,SAYiB;CACnD,MAAM,EAAE,KAAK,QAAQ,WAAW,SAAS;CACzC,MAAM,WAAW,2BAA2B;EAAE;EAAW;CAAI,CAAC;CAE9D,MAAM,WAAW,MAAM,KAAK;CAK5B,IAAI,CAAC,OAAO,SACV,QAAQ,cAAc;CAGxB,MAAM,aAAa,YAAgD;EAMjE,MAAM,gBAAe,MALQ,IAC1B,kBAAkB,CAAC,QAAQ,CAAC,CAAC,CAC7B,KAAK,EAAE,aAAa,OAAO,CAAC,EAAA,EAGM,QAAQ;EAC7C,IACE,CAAC,gBACD,CAAC,sBAAsB,aAAa,mBAAmB,GAEvD,OAAO;EAQT,MAAM,eAAe,MAAM,QAAQ,aAAa,YAAY,IACxD,aAAa,eACb,CAAC;EAML,IAAI;EACJ,IAAI,aAAa,WAAW,GAE1B,mBAAmB,CAAC;OAEpB,IAAI;GACF,MAAM,cAAc,MAAM,IACvB,qBAAqB,YAAY,CAAC,CAClC,KAAK,EAAE,aAAa,OAAO,CAAC;GAC/B,mBAAmB,MAAM,QAAQ,aAAa,KAAK,IAC/C,YAAY,QACZ,aAAa,UAAU,IAAI;EACjC,SAAS,GAAG;GACV,mBAAmB,aAAa,UAAU,IAAI;EAChD;EAGF,OAAO;GACL;GACA;GACA;GACA,WAAW,aAAa;EAC1B;CACF;CAEA,OAAO,kBAAkB;EACvB;EACA;EACA,gBAAgB;EAChB,OAAO;EACP,MAAM;EACN,SAAS;CACX,CAAC;AACH"}
@@ -0,0 +1,29 @@
1
+ import { SolanaRpcType } 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/confirmSignature.d.ts
6
+ /**
7
+ * How often this poller re-reads `getSignatureStatuses`. The default Solana
8
+ * RPCs tolerate 2.5 req/s of status reads; the Jito bundle poller runs slower
9
+ * because its endpoints do not (see `confirmBundle`).
10
+ */
11
+ declare const SIGNATURE_POLL_INTERVAL_MS = 400;
12
+ /** Confirms one transaction against one RPC. Holds no policy: the deadline
13
+ * decides when to stop, and the resend loop only observes an `AbortSignal`. */
14
+ declare function confirmSignature(options: {
15
+ rpc: SolanaRpcType;
16
+ signal: AbortSignal;
17
+ signature: Signature;
18
+ lifetimes: TransactionLifetime[];
19
+ resend: (rpc: SolanaRpcType, signal: AbortSignal) => Promise<void>;
20
+ /**
21
+ * Reports that this RPC accepted a send of the transaction. Must not throw -
22
+ * `sendAndConfirmTransaction` contains any throw from the integrator
23
+ * callback it wraps.
24
+ */
25
+ onBroadcast?: () => void;
26
+ }): Promise<ConfirmationOutcome<SignatureStatus>>;
27
+ //#endregion
28
+ export { SIGNATURE_POLL_INTERVAL_MS, confirmSignature };
29
+ //# sourceMappingURL=confirmSignature.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"confirmSignature.d.ts","names":[],"sources":["../../../src/confirmation/confirmSignature.ts"],"mappings":";;;;;;;;;;cAkBa;;;iBAIS,iBAAiB;EACrC,KAAK;EACL,QAAQ;EACR,WAAW;EACX,WAAW;EACX,SAAS,KAAK,eAAe,QAAQ,gBAAgB;;;;;;EAMrD;IACE,QAAQ,oBAAoB"}
@@ -0,0 +1,64 @@
1
+ import { createConfirmationDeadline } from "./createConfirmationDeadline.js";
2
+ import { abortableSleep } from "./abortableSleep.js";
3
+ import { pollUntilDeadline } from "./pollUntilDeadline.js";
4
+ import { isConfirmedCommitment } from "./types.js";
5
+ //#region src/confirmation/confirmSignature.ts
6
+ const RESEND_INTERVAL_MS = 1e3;
7
+ /**
8
+ * How often this poller re-reads `getSignatureStatuses`. The default Solana
9
+ * RPCs tolerate 2.5 req/s of status reads; the Jito bundle poller runs slower
10
+ * because its endpoints do not (see `confirmBundle`).
11
+ */
12
+ const SIGNATURE_POLL_INTERVAL_MS = 400;
13
+ /** Confirms one transaction against one RPC. Holds no policy: the deadline
14
+ * decides when to stop, and the resend loop only observes an `AbortSignal`. */
15
+ async function confirmSignature(options) {
16
+ const { rpc, signal, signature, lifetimes, resend } = options;
17
+ const deadline = createConfirmationDeadline({
18
+ lifetimes,
19
+ rpc
20
+ });
21
+ const branch = new AbortController();
22
+ const abortBranch = () => branch.abort();
23
+ signal.addEventListener("abort", abortBranch, { once: true });
24
+ let sendSucceeded = false;
25
+ try {
26
+ await resend(rpc, signal);
27
+ sendSucceeded = true;
28
+ if (!signal.aborted) options.onBroadcast?.();
29
+ } catch (_) {}
30
+ (async () => {
31
+ while (!branch.signal.aborted) {
32
+ await abortableSleep(RESEND_INTERVAL_MS, branch.signal);
33
+ if (branch.signal.aborted) break;
34
+ try {
35
+ await resend(rpc, branch.signal);
36
+ sendSucceeded = true;
37
+ if (!branch.signal.aborted) options.onBroadcast?.();
38
+ } catch (_) {}
39
+ }
40
+ })().catch(() => {});
41
+ const readStatus = async () => {
42
+ const status = (await rpc.getSignatureStatuses([signature]).send({ abortSignal: signal }))?.value?.[0];
43
+ if (status && isConfirmedCommitment(status.confirmationStatus)) return status;
44
+ return null;
45
+ };
46
+ try {
47
+ return await pollUntilDeadline({
48
+ deadline,
49
+ signal,
50
+ pollIntervalMs: 400,
51
+ probe: readStatus,
52
+ read: "signature status read",
53
+ subject: "transaction",
54
+ neverBroadcast: () => !sendSucceeded
55
+ });
56
+ } finally {
57
+ branch.abort();
58
+ signal.removeEventListener("abort", abortBranch);
59
+ }
60
+ }
61
+ //#endregion
62
+ export { SIGNATURE_POLL_INTERVAL_MS, confirmSignature };
63
+
64
+ //# sourceMappingURL=confirmSignature.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"confirmSignature.js","names":[],"sources":["../../../src/confirmation/confirmSignature.ts"],"sourcesContent":["import type { Signature } from '@solana/kit'\nimport type { SolanaRpcType } from '../rpc/types.js'\nimport type { TransactionLifetime } from '../utils/getTransactionLifetime.js'\nimport { abortableSleep } from './abortableSleep.js'\nimport { createConfirmationDeadline } from './createConfirmationDeadline.js'\nimport { pollUntilDeadline } from './pollUntilDeadline.js'\nimport {\n type ConfirmationOutcome,\n isConfirmedCommitment,\n type SignatureStatus,\n} from './types.js'\n\nconst RESEND_INTERVAL_MS = 1000\n/**\n * How often this poller re-reads `getSignatureStatuses`. The default Solana\n * RPCs tolerate 2.5 req/s of status reads; the Jito bundle poller runs slower\n * because its endpoints do not (see `confirmBundle`).\n */\nexport const SIGNATURE_POLL_INTERVAL_MS = 400\n\n/** Confirms one transaction against one RPC. Holds no policy: the deadline\n * decides when to stop, and the resend loop only observes an `AbortSignal`. */\nexport async function confirmSignature(options: {\n rpc: SolanaRpcType\n signal: AbortSignal\n signature: Signature\n lifetimes: TransactionLifetime[]\n resend: (rpc: SolanaRpcType, signal: AbortSignal) => Promise<void>\n /**\n * Reports that this RPC accepted a send of the transaction. Must not throw -\n * `sendAndConfirmTransaction` contains any throw from the integrator\n * callback it wraps.\n */\n onBroadcast?: () => void\n}): Promise<ConfirmationOutcome<SignatureStatus>> {\n const { rpc, signal, signature, lifetimes, resend } = options\n const deadline = createConfirmationDeadline({ lifetimes, rpc })\n\n // Ends the resend loop when this branch finishes.\n const branch = new AbortController()\n const abortBranch = (): void => branch.abort()\n signal.addEventListener('abort', abortBranch, { once: true })\n\n let sendSucceeded = false\n\n // Awaited so \"did this RPC ever accept the transaction?\" has a settled\n // answer by the time polling ends, rather than one that depends on\n // microtask ordering.\n try {\n await resend(rpc, signal)\n sendSucceeded = true\n // A send can fulfil after the abort; reporting a broadcast then would\n // regress an action status the wait task already finalized.\n // `sendSucceeded` still latches - the RPC did accept it.\n if (!signal.aborted) {\n options.onBroadcast?.()\n }\n } catch (_) {\n // Continue with confirmation even if the initial send fails — another RPC\n // may already have propagated the transaction.\n }\n\n const resending = (async () => {\n while (!branch.signal.aborted) {\n await abortableSleep(RESEND_INTERVAL_MS, branch.signal)\n if (branch.signal.aborted) {\n break\n }\n try {\n await resend(rpc, branch.signal)\n sendSucceeded = true\n // Same late-fulfilment guard as the first send.\n if (!branch.signal.aborted) {\n options.onBroadcast?.()\n }\n } catch (_) {\n // Resending is best-effort. A total failure is caught by the\n // neverBroadcast check in the verdict.\n }\n }\n })()\n resending.catch(() => {})\n\n const readStatus = async (): Promise<SignatureStatus | null> => {\n const response = await rpc\n .getSignatureStatuses([signature])\n .send({ abortSignal: signal })\n // A `{ value: null }` answer responded but said nothing - poll again\n // rather than throw a `TypeError` into the read-failure budget.\n const status = response?.value?.[0]\n if (status && isConfirmedCommitment(status.confirmationStatus)) {\n return status\n }\n return null\n }\n\n try {\n return await pollUntilDeadline({\n deadline,\n signal,\n pollIntervalMs: SIGNATURE_POLL_INTERVAL_MS,\n probe: readStatus,\n read: 'signature status read',\n subject: 'transaction',\n // Read at verdict time, not captured: the resend loop may succeed long\n // after the awaited first send failed.\n neverBroadcast: () => !sendSucceeded,\n })\n } finally {\n branch.abort()\n signal.removeEventListener('abort', abortBranch)\n }\n}\n"],"mappings":";;;;;AAYA,MAAM,qBAAqB;;;;;;AAM3B,MAAa,6BAA6B;;;AAI1C,eAAsB,iBAAiB,SAYW;CAChD,MAAM,EAAE,KAAK,QAAQ,WAAW,WAAW,WAAW;CACtD,MAAM,WAAW,2BAA2B;EAAE;EAAW;CAAI,CAAC;CAG9D,MAAM,SAAS,IAAI,gBAAgB;CACnC,MAAM,oBAA0B,OAAO,MAAM;CAC7C,OAAO,iBAAiB,SAAS,aAAa,EAAE,MAAM,KAAK,CAAC;CAE5D,IAAI,gBAAgB;CAKpB,IAAI;EACF,MAAM,OAAO,KAAK,MAAM;EACxB,gBAAgB;EAIhB,IAAI,CAAC,OAAO,SACV,QAAQ,cAAc;CAE1B,SAAS,GAAG,CAGZ;CAqBA,CAnBmB,YAAY;EAC7B,OAAO,CAAC,OAAO,OAAO,SAAS;GAC7B,MAAM,eAAe,oBAAoB,OAAO,MAAM;GACtD,IAAI,OAAO,OAAO,SAChB;GAEF,IAAI;IACF,MAAM,OAAO,KAAK,OAAO,MAAM;IAC/B,gBAAgB;IAEhB,IAAI,CAAC,OAAO,OAAO,SACjB,QAAQ,cAAc;GAE1B,SAAS,GAAG,CAGZ;EACF;CACF,EAAA,CACQ,CAAC,CAAC,YAAY,CAAC,CAAC;CAExB,MAAM,aAAa,YAA6C;EAM9D,MAAM,UAAS,MALQ,IACpB,qBAAqB,CAAC,SAAS,CAAC,CAAC,CACjC,KAAK,EAAE,aAAa,OAAO,CAAC,EAAA,EAGN,QAAQ;EACjC,IAAI,UAAU,sBAAsB,OAAO,kBAAkB,GAC3D,OAAO;EAET,OAAO;CACT;CAEA,IAAI;EACF,OAAO,MAAM,kBAAkB;GAC7B;GACA;GACA,gBAAA;GACA,OAAO;GACP,MAAM;GACN,SAAS;GAGT,sBAAsB,CAAC;EACzB,CAAC;CACH,UAAU;EACR,OAAO,MAAM;EACb,OAAO,oBAAoB,SAAS,WAAW;CACjD;AACF"}
@@ -0,0 +1,51 @@
1
+ import { SolanaRpcType } from "../rpc/types.js";
2
+ import { TransactionLifetime } from "../utils/getTransactionLifetime.js";
3
+ //#region src/confirmation/createConfirmationDeadline.d.ts
4
+ /** Give-up point for a branch's polling. Read between iterations only, so a
5
+ * hung RPC call needs `BRANCH_TIMEOUT_MS` to close the gap. */
6
+ declare const CONFIRMATION_TIMEOUT_MS = 9e4;
7
+ /** Head-room for the final probe after the deadline.
8
+ * `STATUS_RETRY_BACKOFF_CAP_MS` must stay below it. */
9
+ declare const FINAL_PROBE_MARGIN_MS = 5e3;
10
+ /** Hard bound on a branch, in-flight requests included. Above the ceiling so
11
+ * an abort cannot pre-empt the final probe. */
12
+ declare const BRANCH_TIMEOUT_MS: number;
13
+ /** How long a healthy-but-lagging node may need to catch up. A premise, not a
14
+ * knob: `isBlockhashValid` answers `false` for lag and for death alike, so no
15
+ * verdict may land inside this window. */
16
+ declare const NODE_LAG_WINDOW_MS = 12e3;
17
+ /** Gap between `isBlockhashValid` probes. Spacing them is what makes the
18
+ * consecutive-`false` rule meaningful: quantized to the 400 ms tick, probes
19
+ * land at 0.4/7.6/14.8 s, so no verdict lands inside `NODE_LAG_WINDOW_MS`. */
20
+ declare const EXPIRY_PROBE_INTERVAL_MS = 7e3;
21
+ /** Consecutive `false` results before a blockhash is believed dead. Derived so
22
+ * a change to either premise moves it automatically; `+ 2` keeps the
23
+ * inequality strict when the window divides exactly. */
24
+ declare const EXPIRY_CONFIRMATIONS: number;
25
+ /** Probe failures per blockhash before that blockhash stops being probed.
26
+ * Prober-only; the status pollers have `MAX_STATUS_READ_SILENCE_MS`. */
27
+ declare const MAX_PROBE_ERRORS = 5;
28
+ /** Structural, so one implementation serves both the Solana and Jito RPC. */
29
+ type BlockhashProbeRpc = Pick<SolanaRpcType, "isBlockhashValid">;
30
+ interface ConfirmationDeadline {
31
+ /** Checked at the top of every poll iteration. */
32
+ reached(): boolean;
33
+ /** Advances the policy; never throws. Probes at most once per
34
+ * `EXPIRY_PROBE_INTERVAL_MS`. */
35
+ tick(signal: AbortSignal): Promise<void>;
36
+ }
37
+ /**
38
+ * Owns every "should I stop polling?" decision.
39
+ *
40
+ * Never reads `getBlockHeight`: at least one default LI.FI RPC answers it with
41
+ * the slot number, making any `lastValidBlockHeight` comparison false on its
42
+ * first evaluation.
43
+ */
44
+ declare function createConfirmationDeadline(options: {
45
+ lifetimes: TransactionLifetime[];
46
+ rpc: BlockhashProbeRpc;
47
+ now?: () => number;
48
+ }): ConfirmationDeadline;
49
+ //#endregion
50
+ export { BRANCH_TIMEOUT_MS, BlockhashProbeRpc, CONFIRMATION_TIMEOUT_MS, ConfirmationDeadline, EXPIRY_CONFIRMATIONS, EXPIRY_PROBE_INTERVAL_MS, FINAL_PROBE_MARGIN_MS, MAX_PROBE_ERRORS, NODE_LAG_WINDOW_MS, createConfirmationDeadline };
51
+ //# sourceMappingURL=createConfirmationDeadline.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"createConfirmationDeadline.d.ts","names":[],"sources":["../../../src/confirmation/createConfirmationDeadline.ts"],"mappings":";;;;;cAMa;;;cAGA;;;cAGA;;;;cAKA;;;;cAIA;;;;cAIA;;;cAIA;;KAGD,oBAAoB,KAAK;UAEpB;;EAEf;;;EAGA,KAAK,QAAQ,cAAc;;;;;;;;;iBAUb,2BAA2B;EACzC,WAAW;EACX,KAAK;EACL;IACE"}