@lifi/sdk-provider-solana 4.0.7 → 4.1.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (145) hide show
  1. package/CHANGELOG.md +117 -0
  2. package/dist/cjs/actions/sendAndConfirmBundle.d.ts +18 -25
  3. package/dist/cjs/actions/sendAndConfirmBundle.js +33 -54
  4. package/dist/cjs/actions/sendAndConfirmBundle.js.map +1 -1
  5. package/dist/cjs/actions/sendAndConfirmTransaction.d.ts +14 -22
  6. package/dist/cjs/actions/sendAndConfirmTransaction.js +38 -55
  7. package/dist/cjs/actions/sendAndConfirmTransaction.js.map +1 -1
  8. package/dist/cjs/confirmation/abortableSleep.d.ts +19 -0
  9. package/dist/cjs/confirmation/abortableSleep.js +32 -0
  10. package/dist/cjs/confirmation/abortableSleep.js.map +1 -0
  11. package/dist/cjs/confirmation/confirmBundle.d.ts +43 -0
  12. package/dist/cjs/confirmation/confirmBundle.js +57 -0
  13. package/dist/cjs/confirmation/confirmBundle.js.map +1 -0
  14. package/dist/cjs/confirmation/confirmSignature.d.ts +29 -0
  15. package/dist/cjs/confirmation/confirmSignature.js +66 -0
  16. package/dist/cjs/confirmation/confirmSignature.js.map +1 -0
  17. package/dist/cjs/confirmation/createConfirmationDeadline.d.ts +51 -0
  18. package/dist/cjs/confirmation/createConfirmationDeadline.js +101 -0
  19. package/dist/cjs/confirmation/createConfirmationDeadline.js.map +1 -0
  20. package/dist/cjs/confirmation/pollUntilDeadline.d.ts +58 -0
  21. package/dist/cjs/confirmation/pollUntilDeadline.js +97 -0
  22. package/dist/cjs/confirmation/pollUntilDeadline.js.map +1 -0
  23. package/dist/cjs/confirmation/raceRpcs.d.ts +26 -0
  24. package/dist/cjs/confirmation/raceRpcs.js +93 -0
  25. package/dist/cjs/confirmation/raceRpcs.js.map +1 -0
  26. package/dist/cjs/confirmation/types.d.ts +18 -0
  27. package/dist/cjs/confirmation/types.js +9 -0
  28. package/dist/cjs/confirmation/types.js.map +1 -0
  29. package/dist/cjs/core/tasks/SolanaJitoWaitForTransactionTask.js +30 -9
  30. package/dist/cjs/core/tasks/SolanaJitoWaitForTransactionTask.js.map +1 -1
  31. package/dist/cjs/core/tasks/SolanaSignAndExecuteTask.js +5 -1
  32. package/dist/cjs/core/tasks/SolanaSignAndExecuteTask.js.map +1 -1
  33. package/dist/cjs/core/tasks/SolanaStandardWaitForTransactionTask.js +20 -7
  34. package/dist/cjs/core/tasks/SolanaStandardWaitForTransactionTask.js.map +1 -1
  35. package/dist/cjs/core/tasks/readSignature.d.ts +17 -0
  36. package/dist/cjs/core/tasks/readSignature.js +26 -0
  37. package/dist/cjs/core/tasks/readSignature.js.map +1 -0
  38. package/dist/cjs/core/tasks/unwrapConfirmation.d.ts +25 -0
  39. package/dist/cjs/core/tasks/unwrapConfirmation.js +24 -0
  40. package/dist/cjs/core/tasks/unwrapConfirmation.js.map +1 -0
  41. package/dist/cjs/rpc/jito/api/getBundleStatuses.d.ts +4 -2
  42. package/dist/cjs/rpc/registry.d.ts +37 -11
  43. package/dist/cjs/rpc/registry.js +103 -18
  44. package/dist/cjs/rpc/registry.js.map +1 -1
  45. package/dist/cjs/rpc/utils.js +1 -1
  46. package/dist/cjs/rpc/utils.js.map +1 -1
  47. package/dist/cjs/utils/KeypairWalletAdapter.js +10 -4
  48. package/dist/cjs/utils/KeypairWalletAdapter.js.map +1 -1
  49. package/dist/cjs/utils/getTransactionLifetime.d.ts +21 -0
  50. package/dist/cjs/utils/getTransactionLifetime.js +28 -0
  51. package/dist/cjs/utils/getTransactionLifetime.js.map +1 -0
  52. package/dist/cjs/version.d.ts +1 -1
  53. package/dist/cjs/version.js +1 -1
  54. package/dist/cjs/version.js.map +1 -1
  55. package/dist/esm/actions/sendAndConfirmBundle.d.ts +18 -25
  56. package/dist/esm/actions/sendAndConfirmBundle.d.ts.map +1 -1
  57. package/dist/esm/actions/sendAndConfirmBundle.js +34 -55
  58. package/dist/esm/actions/sendAndConfirmBundle.js.map +1 -1
  59. package/dist/esm/actions/sendAndConfirmTransaction.d.ts +14 -22
  60. package/dist/esm/actions/sendAndConfirmTransaction.d.ts.map +1 -1
  61. package/dist/esm/actions/sendAndConfirmTransaction.js +38 -55
  62. package/dist/esm/actions/sendAndConfirmTransaction.js.map +1 -1
  63. package/dist/esm/confirmation/abortableSleep.d.ts +19 -0
  64. package/dist/esm/confirmation/abortableSleep.d.ts.map +1 -0
  65. package/dist/esm/confirmation/abortableSleep.js +31 -0
  66. package/dist/esm/confirmation/abortableSleep.js.map +1 -0
  67. package/dist/esm/confirmation/confirmBundle.d.ts +43 -0
  68. package/dist/esm/confirmation/confirmBundle.d.ts.map +1 -0
  69. package/dist/esm/confirmation/confirmBundle.js +55 -0
  70. package/dist/esm/confirmation/confirmBundle.js.map +1 -0
  71. package/dist/esm/confirmation/confirmSignature.d.ts +29 -0
  72. package/dist/esm/confirmation/confirmSignature.d.ts.map +1 -0
  73. package/dist/esm/confirmation/confirmSignature.js +64 -0
  74. package/dist/esm/confirmation/confirmSignature.js.map +1 -0
  75. package/dist/esm/confirmation/createConfirmationDeadline.d.ts +51 -0
  76. package/dist/esm/confirmation/createConfirmationDeadline.d.ts.map +1 -0
  77. package/dist/esm/confirmation/createConfirmationDeadline.js +93 -0
  78. package/dist/esm/confirmation/createConfirmationDeadline.js.map +1 -0
  79. package/dist/esm/confirmation/pollUntilDeadline.d.ts +58 -0
  80. package/dist/esm/confirmation/pollUntilDeadline.d.ts.map +1 -0
  81. package/dist/esm/confirmation/pollUntilDeadline.js +93 -0
  82. package/dist/esm/confirmation/pollUntilDeadline.js.map +1 -0
  83. package/dist/esm/confirmation/raceRpcs.d.ts +26 -0
  84. package/dist/esm/confirmation/raceRpcs.d.ts.map +1 -0
  85. package/dist/esm/confirmation/raceRpcs.js +92 -0
  86. package/dist/esm/confirmation/raceRpcs.js.map +1 -0
  87. package/dist/esm/confirmation/types.d.ts +18 -0
  88. package/dist/esm/confirmation/types.d.ts.map +1 -0
  89. package/dist/esm/confirmation/types.js +8 -0
  90. package/dist/esm/confirmation/types.js.map +1 -0
  91. package/dist/esm/core/tasks/SolanaJitoWaitForTransactionTask.d.ts.map +1 -1
  92. package/dist/esm/core/tasks/SolanaJitoWaitForTransactionTask.js +30 -9
  93. package/dist/esm/core/tasks/SolanaJitoWaitForTransactionTask.js.map +1 -1
  94. package/dist/esm/core/tasks/SolanaSignAndExecuteTask.js +5 -1
  95. package/dist/esm/core/tasks/SolanaSignAndExecuteTask.js.map +1 -1
  96. package/dist/esm/core/tasks/SolanaStandardWaitForTransactionTask.d.ts.map +1 -1
  97. package/dist/esm/core/tasks/SolanaStandardWaitForTransactionTask.js +20 -7
  98. package/dist/esm/core/tasks/SolanaStandardWaitForTransactionTask.js.map +1 -1
  99. package/dist/esm/core/tasks/readSignature.d.ts +17 -0
  100. package/dist/esm/core/tasks/readSignature.d.ts.map +1 -0
  101. package/dist/esm/core/tasks/readSignature.js +25 -0
  102. package/dist/esm/core/tasks/readSignature.js.map +1 -0
  103. package/dist/esm/core/tasks/unwrapConfirmation.d.ts +25 -0
  104. package/dist/esm/core/tasks/unwrapConfirmation.d.ts.map +1 -0
  105. package/dist/esm/core/tasks/unwrapConfirmation.js +23 -0
  106. package/dist/esm/core/tasks/unwrapConfirmation.js.map +1 -0
  107. package/dist/esm/rpc/jito/api/getBundleStatuses.d.ts +4 -2
  108. package/dist/esm/rpc/jito/api/getBundleStatuses.d.ts.map +1 -1
  109. package/dist/esm/rpc/registry.d.ts +37 -11
  110. package/dist/esm/rpc/registry.d.ts.map +1 -1
  111. package/dist/esm/rpc/registry.js +102 -19
  112. package/dist/esm/rpc/registry.js.map +1 -1
  113. package/dist/esm/rpc/utils.js +1 -1
  114. package/dist/esm/rpc/utils.js.map +1 -1
  115. package/dist/esm/utils/KeypairWalletAdapter.d.ts.map +1 -1
  116. package/dist/esm/utils/KeypairWalletAdapter.js +11 -5
  117. package/dist/esm/utils/KeypairWalletAdapter.js.map +1 -1
  118. package/dist/esm/utils/getTransactionLifetime.d.ts +21 -0
  119. package/dist/esm/utils/getTransactionLifetime.d.ts.map +1 -0
  120. package/dist/esm/utils/getTransactionLifetime.js +27 -0
  121. package/dist/esm/utils/getTransactionLifetime.js.map +1 -0
  122. package/dist/esm/version.d.ts +1 -1
  123. package/dist/esm/version.js +1 -1
  124. package/dist/esm/version.js.map +1 -1
  125. package/package.json +4 -4
  126. package/src/actions/sendAndConfirmBundle.ts +82 -142
  127. package/src/actions/sendAndConfirmTransaction.ts +82 -134
  128. package/src/confirmation/abortableSleep.ts +30 -0
  129. package/src/confirmation/confirmBundle.ts +121 -0
  130. package/src/confirmation/confirmSignature.ts +113 -0
  131. package/src/confirmation/createConfirmationDeadline.ts +174 -0
  132. package/src/confirmation/pollUntilDeadline.ts +182 -0
  133. package/src/confirmation/raceRpcs.ts +135 -0
  134. package/src/confirmation/types.ts +23 -0
  135. package/src/core/tasks/SolanaJitoWaitForTransactionTask.ts +49 -16
  136. package/src/core/tasks/SolanaSignAndExecuteTask.ts +15 -0
  137. package/src/core/tasks/SolanaStandardWaitForTransactionTask.ts +28 -17
  138. package/src/core/tasks/readSignature.ts +29 -0
  139. package/src/core/tasks/unwrapConfirmation.ts +59 -0
  140. package/src/rpc/jito/api/getBundleStatuses.ts +4 -2
  141. package/src/rpc/registry.ts +183 -25
  142. package/src/rpc/utils.ts +5 -2
  143. package/src/utils/KeypairWalletAdapter.ts +34 -9
  144. package/src/utils/getTransactionLifetime.ts +38 -0
  145. package/src/version.ts +1 -1
@@ -0,0 +1,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,57 @@
1
+ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
2
+ const require_confirmation_createConfirmationDeadline = require("./createConfirmationDeadline.js");
3
+ const require_confirmation_pollUntilDeadline = require("./pollUntilDeadline.js");
4
+ const require_confirmation_types = require("./types.js");
5
+ //#region src/confirmation/confirmBundle.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
+ const BUNDLE_POLL_INTERVAL_MS = 2e3;
10
+ /**
11
+ * Confirms one Jito bundle against one Jito RPC.
12
+ *
13
+ * Bundles submit once, so there is no resend loop. `send` is owned here so the
14
+ * deadline starts before submission rather than after it. A `send` failure
15
+ * throws, which `raceRpcs` buckets as `rpc-unavailable`.
16
+ */
17
+ async function confirmBundle(options) {
18
+ const { rpc, signal, lifetimes, send } = options;
19
+ const deadline = require_confirmation_createConfirmationDeadline.createConfirmationDeadline({
20
+ lifetimes,
21
+ rpc
22
+ });
23
+ const bundleId = await send();
24
+ if (!signal.aborted) options.onBroadcast?.();
25
+ const readBundle = async () => {
26
+ const bundleStatus = (await rpc.getBundleStatuses([bundleId]).send({ abortSignal: signal }))?.value?.[0];
27
+ if (!bundleStatus || !require_confirmation_types.isConfirmedCommitment(bundleStatus.confirmation_status)) return null;
28
+ const txSignatures = Array.isArray(bundleStatus.transactions) ? bundleStatus.transactions : [];
29
+ let signatureResults;
30
+ if (txSignatures.length === 0) signatureResults = [];
31
+ else try {
32
+ const sigResponse = await rpc.getSignatureStatuses(txSignatures).send({ abortSignal: signal });
33
+ signatureResults = Array.isArray(sigResponse?.value) ? sigResponse.value : txSignatures.map(() => null);
34
+ } catch (_) {
35
+ signatureResults = txSignatures.map(() => null);
36
+ }
37
+ return {
38
+ bundleId,
39
+ txSignatures,
40
+ signatureResults,
41
+ bundleErr: bundleStatus.err
42
+ };
43
+ };
44
+ return require_confirmation_pollUntilDeadline.pollUntilDeadline({
45
+ deadline,
46
+ signal,
47
+ pollIntervalMs: BUNDLE_POLL_INTERVAL_MS,
48
+ probe: readBundle,
49
+ read: "bundle status read",
50
+ subject: "bundle"
51
+ });
52
+ }
53
+ //#endregion
54
+ exports.BUNDLE_POLL_INTERVAL_MS = BUNDLE_POLL_INTERVAL_MS;
55
+ exports.confirmBundle = confirmBundle;
56
+
57
+ //# sourceMappingURL=confirmBundle.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"confirmBundle.js","names":["createConfirmationDeadline","isConfirmedCommitment","pollUntilDeadline"],"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,WAAWA,gDAAAA,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,CAACC,2BAAAA,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,OAAOC,uCAAAA,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,66 @@
1
+ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
2
+ const require_confirmation_createConfirmationDeadline = require("./createConfirmationDeadline.js");
3
+ const require_confirmation_abortableSleep = require("./abortableSleep.js");
4
+ const require_confirmation_pollUntilDeadline = require("./pollUntilDeadline.js");
5
+ const require_confirmation_types = require("./types.js");
6
+ //#region src/confirmation/confirmSignature.ts
7
+ const RESEND_INTERVAL_MS = 1e3;
8
+ /**
9
+ * How often this poller re-reads `getSignatureStatuses`. The default Solana
10
+ * RPCs tolerate 2.5 req/s of status reads; the Jito bundle poller runs slower
11
+ * because its endpoints do not (see `confirmBundle`).
12
+ */
13
+ const SIGNATURE_POLL_INTERVAL_MS = 400;
14
+ /** Confirms one transaction against one RPC. Holds no policy: the deadline
15
+ * decides when to stop, and the resend loop only observes an `AbortSignal`. */
16
+ async function confirmSignature(options) {
17
+ const { rpc, signal, signature, lifetimes, resend } = options;
18
+ const deadline = require_confirmation_createConfirmationDeadline.createConfirmationDeadline({
19
+ lifetimes,
20
+ rpc
21
+ });
22
+ const branch = new AbortController();
23
+ const abortBranch = () => branch.abort();
24
+ signal.addEventListener("abort", abortBranch, { once: true });
25
+ let sendSucceeded = false;
26
+ try {
27
+ await resend(rpc, signal);
28
+ sendSucceeded = true;
29
+ if (!signal.aborted) options.onBroadcast?.();
30
+ } catch (_) {}
31
+ (async () => {
32
+ while (!branch.signal.aborted) {
33
+ await require_confirmation_abortableSleep.abortableSleep(RESEND_INTERVAL_MS, branch.signal);
34
+ if (branch.signal.aborted) break;
35
+ try {
36
+ await resend(rpc, branch.signal);
37
+ sendSucceeded = true;
38
+ if (!branch.signal.aborted) options.onBroadcast?.();
39
+ } catch (_) {}
40
+ }
41
+ })().catch(() => {});
42
+ const readStatus = async () => {
43
+ const status = (await rpc.getSignatureStatuses([signature]).send({ abortSignal: signal }))?.value?.[0];
44
+ if (status && require_confirmation_types.isConfirmedCommitment(status.confirmationStatus)) return status;
45
+ return null;
46
+ };
47
+ try {
48
+ return await require_confirmation_pollUntilDeadline.pollUntilDeadline({
49
+ deadline,
50
+ signal,
51
+ pollIntervalMs: 400,
52
+ probe: readStatus,
53
+ read: "signature status read",
54
+ subject: "transaction",
55
+ neverBroadcast: () => !sendSucceeded
56
+ });
57
+ } finally {
58
+ branch.abort();
59
+ signal.removeEventListener("abort", abortBranch);
60
+ }
61
+ }
62
+ //#endregion
63
+ exports.SIGNATURE_POLL_INTERVAL_MS = SIGNATURE_POLL_INTERVAL_MS;
64
+ exports.confirmSignature = confirmSignature;
65
+
66
+ //# sourceMappingURL=confirmSignature.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"confirmSignature.js","names":["createConfirmationDeadline","abortableSleep","isConfirmedCommitment","pollUntilDeadline"],"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,WAAWA,gDAAAA,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,MAAMC,oCAAAA,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,UAAUC,2BAAAA,sBAAsB,OAAO,kBAAkB,GAC3D,OAAO;EAET,OAAO;CACT;CAEA,IAAI;EACF,OAAO,MAAMC,uCAAAA,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,101 @@
1
+ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
2
+ //#region src/confirmation/createConfirmationDeadline.ts
3
+ /** Give-up point for a branch's polling. Read between iterations only, so a
4
+ * hung RPC call needs `BRANCH_TIMEOUT_MS` to close the gap. */
5
+ const CONFIRMATION_TIMEOUT_MS = 9e4;
6
+ /** Head-room for the final probe after the deadline.
7
+ * `STATUS_RETRY_BACKOFF_CAP_MS` must stay below it. */
8
+ const FINAL_PROBE_MARGIN_MS = 5e3;
9
+ /** Hard bound on a branch, in-flight requests included. Above the ceiling so
10
+ * an abort cannot pre-empt the final probe. */
11
+ const BRANCH_TIMEOUT_MS = 95e3;
12
+ /** How long a healthy-but-lagging node may need to catch up. A premise, not a
13
+ * knob: `isBlockhashValid` answers `false` for lag and for death alike, so no
14
+ * verdict may land inside this window. */
15
+ const NODE_LAG_WINDOW_MS = 12e3;
16
+ /** Gap between `isBlockhashValid` probes. Spacing them is what makes the
17
+ * consecutive-`false` rule meaningful: quantized to the 400 ms tick, probes
18
+ * land at 0.4/7.6/14.8 s, so no verdict lands inside `NODE_LAG_WINDOW_MS`. */
19
+ const EXPIRY_PROBE_INTERVAL_MS = 7e3;
20
+ /** Consecutive `false` results before a blockhash is believed dead. Derived so
21
+ * a change to either premise moves it automatically; `+ 2` keeps the
22
+ * inequality strict when the window divides exactly. */
23
+ const EXPIRY_CONFIRMATIONS = Math.floor(NODE_LAG_WINDOW_MS / EXPIRY_PROBE_INTERVAL_MS) + 2;
24
+ /** Probe failures per blockhash before that blockhash stops being probed.
25
+ * Prober-only; the status pollers have `MAX_STATUS_READ_SILENCE_MS`. */
26
+ const MAX_PROBE_ERRORS = 5;
27
+ /**
28
+ * Owns every "should I stop polling?" decision.
29
+ *
30
+ * Never reads `getBlockHeight`: at least one default LI.FI RPC answers it with
31
+ * the slot number, making any `lastValidBlockHeight` comparison false on its
32
+ * first evaluation.
33
+ */
34
+ function createConfirmationDeadline(options) {
35
+ const { lifetimes, rpc } = options;
36
+ const now = options.now ?? Date.now;
37
+ const startedAt = now();
38
+ const blockhashLifetimes = lifetimes.filter((lifetime) => lifetime.kind === "blockhash");
39
+ const blockhashes = lifetimes.length > 0 && blockhashLifetimes.length === lifetimes.length ? [...new Set(blockhashLifetimes.map((lifetime) => lifetime.blockhash))] : [];
40
+ const expiredStreaks = /* @__PURE__ */ new Map();
41
+ const errorStreaks = /* @__PURE__ */ new Map();
42
+ const probeable = new Set(blockhashes);
43
+ let lastProbeAt;
44
+ /** Derived, not latched: a blockhash that reads valid again zeroes its
45
+ * streak and clears the verdict with it. */
46
+ const isExpired = () => {
47
+ for (const streak of expiredStreaks.values()) if (streak >= EXPIRY_CONFIRMATIONS) return true;
48
+ return false;
49
+ };
50
+ return {
51
+ reached() {
52
+ if (now() - startedAt >= 9e4) return true;
53
+ return isExpired();
54
+ },
55
+ async tick(signal) {
56
+ if (probeable.size === 0 || signal.aborted) return;
57
+ const probeAt = now();
58
+ if (lastProbeAt !== void 0 && probeAt - lastProbeAt < 7e3) return;
59
+ lastProbeAt = probeAt;
60
+ const active = [...probeable];
61
+ const probes = await Promise.allSettled(active.map(async (blockhash) => {
62
+ return (await rpc.isBlockhashValid(blockhash, { commitment: "confirmed" }).send({ abortSignal: signal })).value;
63
+ }));
64
+ const recordFailedProbe = (blockhash) => {
65
+ expiredStreaks.set(blockhash, 0);
66
+ const errors = (errorStreaks.get(blockhash) ?? 0) + 1;
67
+ errorStreaks.set(blockhash, errors);
68
+ if (errors >= 5) probeable.delete(blockhash);
69
+ };
70
+ probes.forEach((probe, index) => {
71
+ const blockhash = active[index];
72
+ if (probe.status === "rejected") {
73
+ recordFailedProbe(blockhash);
74
+ return;
75
+ }
76
+ if (probe.value === true) {
77
+ errorStreaks.set(blockhash, 0);
78
+ expiredStreaks.set(blockhash, 0);
79
+ return;
80
+ }
81
+ if (probe.value === false) {
82
+ errorStreaks.set(blockhash, 0);
83
+ expiredStreaks.set(blockhash, (expiredStreaks.get(blockhash) ?? 0) + 1);
84
+ return;
85
+ }
86
+ recordFailedProbe(blockhash);
87
+ });
88
+ }
89
+ };
90
+ }
91
+ //#endregion
92
+ exports.BRANCH_TIMEOUT_MS = BRANCH_TIMEOUT_MS;
93
+ exports.CONFIRMATION_TIMEOUT_MS = CONFIRMATION_TIMEOUT_MS;
94
+ exports.EXPIRY_CONFIRMATIONS = EXPIRY_CONFIRMATIONS;
95
+ exports.EXPIRY_PROBE_INTERVAL_MS = EXPIRY_PROBE_INTERVAL_MS;
96
+ exports.FINAL_PROBE_MARGIN_MS = FINAL_PROBE_MARGIN_MS;
97
+ exports.MAX_PROBE_ERRORS = MAX_PROBE_ERRORS;
98
+ exports.NODE_LAG_WINDOW_MS = NODE_LAG_WINDOW_MS;
99
+ exports.createConfirmationDeadline = createConfirmationDeadline;
100
+
101
+ //# sourceMappingURL=createConfirmationDeadline.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"createConfirmationDeadline.js","names":[],"sources":["../../../src/confirmation/createConfirmationDeadline.ts"],"sourcesContent":["import type { Blockhash } from '@solana/kit'\nimport type { SolanaRpcType } from '../rpc/types.js'\nimport type { TransactionLifetime } from '../utils/getTransactionLifetime.js'\n\n/** Give-up point for a branch's polling. Read between iterations only, so a\n * hung RPC call needs `BRANCH_TIMEOUT_MS` to close the gap. */\nexport const CONFIRMATION_TIMEOUT_MS = 90_000\n/** Head-room for the final probe after the deadline.\n * `STATUS_RETRY_BACKOFF_CAP_MS` must stay below it. */\nexport const FINAL_PROBE_MARGIN_MS = 5_000\n/** Hard bound on a branch, in-flight requests included. Above the ceiling so\n * an abort cannot pre-empt the final probe. */\nexport const BRANCH_TIMEOUT_MS: number =\n CONFIRMATION_TIMEOUT_MS + FINAL_PROBE_MARGIN_MS\n/** How long a healthy-but-lagging node may need to catch up. A premise, not a\n * knob: `isBlockhashValid` answers `false` for lag and for death alike, so no\n * verdict may land inside this window. */\nexport const NODE_LAG_WINDOW_MS = 12_000\n/** Gap between `isBlockhashValid` probes. Spacing them is what makes the\n * consecutive-`false` rule meaningful: quantized to the 400 ms tick, probes\n * land at 0.4/7.6/14.8 s, so no verdict lands inside `NODE_LAG_WINDOW_MS`. */\nexport const EXPIRY_PROBE_INTERVAL_MS = 7_000\n/** Consecutive `false` results before a blockhash is believed dead. Derived so\n * a change to either premise moves it automatically; `+ 2` keeps the\n * inequality strict when the window divides exactly. */\nexport const EXPIRY_CONFIRMATIONS: number =\n Math.floor(NODE_LAG_WINDOW_MS / EXPIRY_PROBE_INTERVAL_MS) + 2\n/** Probe failures per blockhash before that blockhash stops being probed.\n * Prober-only; the status pollers have `MAX_STATUS_READ_SILENCE_MS`. */\nexport const MAX_PROBE_ERRORS = 5\n\n/** Structural, so one implementation serves both the Solana and Jito RPC. */\nexport type BlockhashProbeRpc = Pick<SolanaRpcType, 'isBlockhashValid'>\n\nexport interface ConfirmationDeadline {\n /** Checked at the top of every poll iteration. */\n reached(): boolean\n /** Advances the policy; never throws. Probes at most once per\n * `EXPIRY_PROBE_INTERVAL_MS`. */\n tick(signal: AbortSignal): Promise<void>\n}\n\n/**\n * Owns every \"should I stop polling?\" decision.\n *\n * Never reads `getBlockHeight`: at least one default LI.FI RPC answers it with\n * the slot number, making any `lastValidBlockHeight` comparison false on its\n * first evaluation.\n */\nexport function createConfirmationDeadline(options: {\n lifetimes: TransactionLifetime[]\n rpc: BlockhashProbeRpc\n now?: () => number\n}): ConfirmationDeadline {\n const { lifetimes, rpc } = options\n const now = options.now ?? Date.now\n const startedAt = now()\n\n const blockhashLifetimes = lifetimes.filter(\n (\n lifetime\n ): lifetime is Extract<TransactionLifetime, { kind: 'blockhash' }> =>\n lifetime.kind === 'blockhash'\n )\n // A single non-blockhash lifetime disables the early exit for the whole set:\n // we cannot know when such a transaction stops being landable.\n const allProbeable =\n lifetimes.length > 0 && blockhashLifetimes.length === lifetimes.length\n const blockhashes: Blockhash[] = allProbeable\n ? [...new Set(blockhashLifetimes.map((lifetime) => lifetime.blockhash))]\n : []\n\n // Keyed by blockhash: expiry is a property of a blockhash, not of the set.\n const expiredStreaks = new Map<Blockhash, number>()\n // Keyed for the same reason: a sibling's broken probe is not evidence about\n // this blockhash, so it must not spend this blockhash's error budget.\n const errorStreaks = new Map<Blockhash, number>()\n // The blockhashes still worth asking about. One leaves this set after\n // MAX_PROBE_ERRORS failures of its own; the others keep being probed.\n const probeable = new Set<Blockhash>(blockhashes)\n let lastProbeAt: number | undefined\n\n /** Derived, not latched: a blockhash that reads valid again zeroes its\n * streak and clears the verdict with it. */\n const isExpired = (): boolean => {\n for (const streak of expiredStreaks.values()) {\n if (streak >= EXPIRY_CONFIRMATIONS) {\n return true\n }\n }\n return false\n }\n\n return {\n reached(): boolean {\n const elapsed = now() - startedAt\n if (elapsed >= CONFIRMATION_TIMEOUT_MS) {\n return true\n }\n return isExpired()\n },\n async tick(signal: AbortSignal): Promise<void> {\n if (probeable.size === 0 || signal.aborted) {\n return\n }\n // The cadence is wall-clock, not iteration count, and it uses the\n // injected `now` so the policy stays testable without timers.\n const probeAt = now()\n if (\n lastProbeAt !== undefined &&\n probeAt - lastProbeAt < EXPIRY_PROBE_INTERVAL_MS\n ) {\n return\n }\n lastProbeAt = probeAt\n // `allSettled`, not `all`: `all` rejects on the first failure and\n // discards answers the other probes already produced. All state is keyed\n // by blockhash, so one broken probe cannot disable the early exit for\n // the rest.\n const active = [...probeable]\n const probes = await Promise.allSettled(\n active.map(async (blockhash) => {\n const result = await rpc\n .isBlockhashValid(blockhash, { commitment: 'confirmed' })\n .send({ abortSignal: signal })\n return result.value\n })\n )\n\n // A read that produced no usable answer says nothing about this\n // blockhash: it must never spend the expiry streak, only the error\n // budget. Shared by a rejected probe and by a fulfilled one whose\n // response carried no boolean.\n const recordFailedProbe = (blockhash: Blockhash): void => {\n expiredStreaks.set(blockhash, 0)\n const errors = (errorStreaks.get(blockhash) ?? 0) + 1\n errorStreaks.set(blockhash, errors)\n if (errors >= MAX_PROBE_ERRORS) {\n // Degrade to ceiling-only for this blockhash.\n probeable.delete(blockhash)\n }\n }\n\n probes.forEach((probe, index) => {\n const blockhash = active[index]\n\n if (probe.status === 'rejected') {\n recordFailedProbe(blockhash)\n return\n }\n\n // `=== true` / `=== false`, never truthiness: a response carrying no\n // `value` is not a `false`, and reading it as one is the only coercion\n // here that can invent an expiry.\n if (probe.value === true) {\n errorStreaks.set(blockhash, 0)\n expiredStreaks.set(blockhash, 0)\n return\n }\n\n if (probe.value === false) {\n errorStreaks.set(blockhash, 0)\n expiredStreaks.set(\n blockhash,\n (expiredStreaks.get(blockhash) ?? 0) + 1\n )\n return\n }\n\n recordFailedProbe(blockhash)\n })\n },\n }\n}\n"],"mappings":";;;;AAMA,MAAa,0BAA0B;;;AAGvC,MAAa,wBAAwB;;;AAGrC,MAAa,oBACX;;;;AAIF,MAAa,qBAAqB;;;;AAIlC,MAAa,2BAA2B;;;;AAIxC,MAAa,uBACX,KAAK,MAAM,qBAAqB,wBAAwB,IAAI;;;AAG9D,MAAa,mBAAmB;;;;;;;;AAoBhC,SAAgB,2BAA2B,SAIlB;CACvB,MAAM,EAAE,WAAW,QAAQ;CAC3B,MAAM,MAAM,QAAQ,OAAO,KAAK;CAChC,MAAM,YAAY,IAAI;CAEtB,MAAM,qBAAqB,UAAU,QAEjC,aAEA,SAAS,SAAS,WACtB;CAKA,MAAM,cADJ,UAAU,SAAS,KAAK,mBAAmB,WAAW,UAAU,SAE9D,CAAC,GAAG,IAAI,IAAI,mBAAmB,KAAK,aAAa,SAAS,SAAS,CAAC,CAAC,IACrE,CAAC;CAGL,MAAM,iCAAiB,IAAI,IAAuB;CAGlD,MAAM,+BAAe,IAAI,IAAuB;CAGhD,MAAM,YAAY,IAAI,IAAe,WAAW;CAChD,IAAI;;;CAIJ,MAAM,kBAA2B;EAC/B,KAAK,MAAM,UAAU,eAAe,OAAO,GACzC,IAAI,UAAU,sBACZ,OAAO;EAGX,OAAO;CACT;CAEA,OAAO;EACL,UAAmB;GAEjB,IADgB,IAAI,IAAI,aAAA,KAEtB,OAAO;GAET,OAAO,UAAU;EACnB;EACA,MAAM,KAAK,QAAoC;GAC7C,IAAI,UAAU,SAAS,KAAK,OAAO,SACjC;GAIF,MAAM,UAAU,IAAI;GACpB,IACE,gBAAgB,KAAA,KAChB,UAAU,cAAA,KAEV;GAEF,cAAc;GAKd,MAAM,SAAS,CAAC,GAAG,SAAS;GAC5B,MAAM,SAAS,MAAM,QAAQ,WAC3B,OAAO,IAAI,OAAO,cAAc;IAI9B,QAAO,MAHc,IAClB,iBAAiB,WAAW,EAAE,YAAY,YAAY,CAAC,CAAC,CACxD,KAAK,EAAE,aAAa,OAAO,CAAC,EAAA,CACjB;GAChB,CAAC,CACH;GAMA,MAAM,qBAAqB,cAA+B;IACxD,eAAe,IAAI,WAAW,CAAC;IAC/B,MAAM,UAAU,aAAa,IAAI,SAAS,KAAK,KAAK;IACpD,aAAa,IAAI,WAAW,MAAM;IAClC,IAAI,UAAA,GAEF,UAAU,OAAO,SAAS;GAE9B;GAEA,OAAO,SAAS,OAAO,UAAU;IAC/B,MAAM,YAAY,OAAO;IAEzB,IAAI,MAAM,WAAW,YAAY;KAC/B,kBAAkB,SAAS;KAC3B;IACF;IAKA,IAAI,MAAM,UAAU,MAAM;KACxB,aAAa,IAAI,WAAW,CAAC;KAC7B,eAAe,IAAI,WAAW,CAAC;KAC/B;IACF;IAEA,IAAI,MAAM,UAAU,OAAO;KACzB,aAAa,IAAI,WAAW,CAAC;KAC7B,eAAe,IACb,YACC,eAAe,IAAI,SAAS,KAAK,KAAK,CACzC;KACA;IACF;IAEA,kBAAkB,SAAS;GAC7B,CAAC;EACH;CACF;AACF"}
@@ -0,0 +1,58 @@
1
+ import { ConfirmationOutcome } from "./types.js";
2
+ import { ConfirmationDeadline } from "./createConfirmationDeadline.js";
3
+ //#region src/confirmation/pollUntilDeadline.d.ts
4
+ /** Cadence of the detached deadline-advance loop. Independent of the
5
+ * status-poll interval, which each caller sets for its own rate limits. */
6
+ declare const DEADLINE_TICK_INTERVAL_MS = 400;
7
+ /** How long an endpoint may go without answering a status read before its
8
+ * branch gives up. Measured in wall-clock time, not in failures: a count is
9
+ * coupled to the backoff curve, and ten failures spanned only ~16.4 s, so a
10
+ * routine 20 s throttling window ended the branch 74 s inside the 90 s ceiling
11
+ * and reported an already-broadcast transaction as an outage. */
12
+ declare const MAX_STATUS_READ_SILENCE_MS = 3e4;
13
+ /** Ceiling on one backoff sleep. Squeezed between two bounds:
14
+ * - Above `BUNDLE_POLL_INTERVAL_MS`, the largest base interval any caller
15
+ * uses. At 2 s the two were equal, so `Math.max(pollIntervalMs, ...)` below
16
+ * returned the base interval for every failure count and the bundle path
17
+ * never backed off at all.
18
+ * - Far enough below `FINAL_PROBE_MARGIN_MS` to leave the final probe a
19
+ * usable window. A sleep straddling the ceiling delays that probe by up to
20
+ * the cap, so the window is the margin minus this value - 2 s here. `cap <
21
+ * margin` alone is not the constraint: 4 s satisfied it and left the probe
22
+ * 1 s, on the failing endpoints where the cap is reached and reads are
23
+ * slowest.
24
+ *
25
+ * The gap between the two bounds fits one doubling, so the bundle path's
26
+ * backoff is a single step rather than a curve. Widening it means raising
27
+ * `FINAL_PROBE_MARGIN_MS`, which lengthens the branch bound the SDK
28
+ * documents. */
29
+ declare const STATUS_RETRY_BACKOFF_CAP_MS = 3e3;
30
+ /**
31
+ * Polls one probe against one RPC until the deadline, and owns the verdict
32
+ * rules shared by the signature and bundle branches.
33
+ *
34
+ * `probe` resolves non-`null` for a confirmation, `null` for "answered, saw
35
+ * nothing", and rejects for a failed read. The deadline advances on a detached
36
+ * loop so a hung blockhash probe cannot stop status polling.
37
+ */
38
+ declare function pollUntilDeadline<T>(options: {
39
+ deadline: ConfirmationDeadline;
40
+ signal: AbortSignal;
41
+ /** Sleep between two status reads that answered. */
42
+ pollIntervalMs: number;
43
+ /** One status read. `null` means it answered but saw no confirmation. */
44
+ probe: () => Promise<T | null>;
45
+ /** Names the read in error messages, e.g. 'signature status read'. */
46
+ read: string;
47
+ /** Names the thing being confirmed in error messages, e.g. 'transaction'. */
48
+ subject: string;
49
+ /** `true` when this RPC never accepted the broadcast. Read at verdict time,
50
+ * and only when the observation did not complete. */
51
+ neverBroadcast?: () => boolean;
52
+ /** Injectable clock, so the silence budget is testable without timers.
53
+ * Mirrors `createConfirmationDeadline`. */
54
+ now?: () => number;
55
+ }): Promise<ConfirmationOutcome<T>>;
56
+ //#endregion
57
+ export { DEADLINE_TICK_INTERVAL_MS, MAX_STATUS_READ_SILENCE_MS, STATUS_RETRY_BACKOFF_CAP_MS, pollUntilDeadline };
58
+ //# sourceMappingURL=pollUntilDeadline.d.ts.map
@@ -0,0 +1,97 @@
1
+ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
2
+ const require_confirmation_abortableSleep = require("./abortableSleep.js");
3
+ //#region src/confirmation/pollUntilDeadline.ts
4
+ /** Cadence of the detached deadline-advance loop. Independent of the
5
+ * status-poll interval, which each caller sets for its own rate limits. */
6
+ const DEADLINE_TICK_INTERVAL_MS = 400;
7
+ /** How long an endpoint may go without answering a status read before its
8
+ * branch gives up. Measured in wall-clock time, not in failures: a count is
9
+ * coupled to the backoff curve, and ten failures spanned only ~16.4 s, so a
10
+ * routine 20 s throttling window ended the branch 74 s inside the 90 s ceiling
11
+ * and reported an already-broadcast transaction as an outage. */
12
+ const MAX_STATUS_READ_SILENCE_MS = 3e4;
13
+ /** Ceiling on one backoff sleep. Squeezed between two bounds:
14
+ * - Above `BUNDLE_POLL_INTERVAL_MS`, the largest base interval any caller
15
+ * uses. At 2 s the two were equal, so `Math.max(pollIntervalMs, ...)` below
16
+ * returned the base interval for every failure count and the bundle path
17
+ * never backed off at all.
18
+ * - Far enough below `FINAL_PROBE_MARGIN_MS` to leave the final probe a
19
+ * usable window. A sleep straddling the ceiling delays that probe by up to
20
+ * the cap, so the window is the margin minus this value - 2 s here. `cap <
21
+ * margin` alone is not the constraint: 4 s satisfied it and left the probe
22
+ * 1 s, on the failing endpoints where the cap is reached and reads are
23
+ * slowest.
24
+ *
25
+ * The gap between the two bounds fits one doubling, so the bundle path's
26
+ * backoff is a single step rather than a curve. Widening it means raising
27
+ * `FINAL_PROBE_MARGIN_MS`, which lengthens the branch bound the SDK
28
+ * documents. */
29
+ const STATUS_RETRY_BACKOFF_CAP_MS = 3e3;
30
+ /**
31
+ * Polls one probe against one RPC until the deadline, and owns the verdict
32
+ * rules shared by the signature and bundle branches.
33
+ *
34
+ * `probe` resolves non-`null` for a confirmation, `null` for "answered, saw
35
+ * nothing", and rejects for a failed read. The deadline advances on a detached
36
+ * loop so a hung blockhash probe cannot stop status polling.
37
+ */
38
+ async function pollUntilDeadline(options) {
39
+ const { deadline, signal, pollIntervalMs, probe, read, subject } = options;
40
+ const now = options.now ?? Date.now;
41
+ let settled = false;
42
+ (async () => {
43
+ while (!settled && !signal.aborted) {
44
+ await require_confirmation_abortableSleep.abortableSleep(400, signal);
45
+ if (settled || signal.aborted) break;
46
+ await deadline.tick(signal);
47
+ }
48
+ })().catch(() => {});
49
+ try {
50
+ let failures = 0;
51
+ let probeSucceeded = false;
52
+ let lastAnswerAt = now();
53
+ let deadlineReached = false;
54
+ while (!signal.aborted) {
55
+ if (deadline.reached()) {
56
+ deadlineReached = true;
57
+ break;
58
+ }
59
+ try {
60
+ const value = await probe();
61
+ failures = 0;
62
+ lastAnswerAt = now();
63
+ probeSucceeded = true;
64
+ if (value !== null) return {
65
+ kind: "confirmed",
66
+ value
67
+ };
68
+ } catch (error) {
69
+ failures += 1;
70
+ if (now() - lastAnswerAt >= 3e4) throw error;
71
+ }
72
+ const delay = failures === 0 ? pollIntervalMs : Math.max(pollIntervalMs, Math.min(pollIntervalMs * 2 ** failures, STATUS_RETRY_BACKOFF_CAP_MS));
73
+ await require_confirmation_abortableSleep.abortableSleep(delay, signal);
74
+ }
75
+ if (!signal.aborted) try {
76
+ const value = await probe();
77
+ probeSucceeded = true;
78
+ if (value !== null) return {
79
+ kind: "confirmed",
80
+ value
81
+ };
82
+ } catch (_) {}
83
+ if (probeSucceeded && deadlineReached) return { kind: "not-confirmed" };
84
+ if (options.neverBroadcast?.()) throw new Error(`Every ${subject} send to this RPC failed.`);
85
+ if (!probeSucceeded) throw new Error(`No ${read} against this RPC ever completed.`);
86
+ throw new Error(`This RPC stopped answering before a final ${read} could run.`);
87
+ } finally {
88
+ settled = true;
89
+ }
90
+ }
91
+ //#endregion
92
+ exports.DEADLINE_TICK_INTERVAL_MS = DEADLINE_TICK_INTERVAL_MS;
93
+ exports.MAX_STATUS_READ_SILENCE_MS = MAX_STATUS_READ_SILENCE_MS;
94
+ exports.STATUS_RETRY_BACKOFF_CAP_MS = STATUS_RETRY_BACKOFF_CAP_MS;
95
+ exports.pollUntilDeadline = pollUntilDeadline;
96
+
97
+ //# sourceMappingURL=pollUntilDeadline.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"pollUntilDeadline.js","names":["abortableSleep"],"sources":["../../../src/confirmation/pollUntilDeadline.ts"],"sourcesContent":["import { abortableSleep } from './abortableSleep.js'\nimport type { ConfirmationDeadline } from './createConfirmationDeadline.js'\nimport type { ConfirmationOutcome } from './types.js'\n\n/** Cadence of the detached deadline-advance loop. Independent of the\n * status-poll interval, which each caller sets for its own rate limits. */\nexport const DEADLINE_TICK_INTERVAL_MS = 400\n/** How long an endpoint may go without answering a status read before its\n * branch gives up. Measured in wall-clock time, not in failures: a count is\n * coupled to the backoff curve, and ten failures spanned only ~16.4 s, so a\n * routine 20 s throttling window ended the branch 74 s inside the 90 s ceiling\n * and reported an already-broadcast transaction as an outage. */\nexport const MAX_STATUS_READ_SILENCE_MS = 30_000\n/** Ceiling on one backoff sleep. Squeezed between two bounds:\n * - Above `BUNDLE_POLL_INTERVAL_MS`, the largest base interval any caller\n * uses. At 2 s the two were equal, so `Math.max(pollIntervalMs, ...)` below\n * returned the base interval for every failure count and the bundle path\n * never backed off at all.\n * - Far enough below `FINAL_PROBE_MARGIN_MS` to leave the final probe a\n * usable window. A sleep straddling the ceiling delays that probe by up to\n * the cap, so the window is the margin minus this value - 2 s here. `cap <\n * margin` alone is not the constraint: 4 s satisfied it and left the probe\n * 1 s, on the failing endpoints where the cap is reached and reads are\n * slowest.\n *\n * The gap between the two bounds fits one doubling, so the bundle path's\n * backoff is a single step rather than a curve. Widening it means raising\n * `FINAL_PROBE_MARGIN_MS`, which lengthens the branch bound the SDK\n * documents. */\nexport const STATUS_RETRY_BACKOFF_CAP_MS = 3_000\n\n/**\n * Polls one probe against one RPC until the deadline, and owns the verdict\n * rules shared by the signature and bundle branches.\n *\n * `probe` resolves non-`null` for a confirmation, `null` for \"answered, saw\n * nothing\", and rejects for a failed read. The deadline advances on a detached\n * loop so a hung blockhash probe cannot stop status polling.\n */\nexport async function pollUntilDeadline<T>(options: {\n deadline: ConfirmationDeadline\n signal: AbortSignal\n /** Sleep between two status reads that answered. */\n pollIntervalMs: number\n /** One status read. `null` means it answered but saw no confirmation. */\n probe: () => Promise<T | null>\n /** Names the read in error messages, e.g. 'signature status read'. */\n read: string\n /** Names the thing being confirmed in error messages, e.g. 'transaction'. */\n subject: string\n /** `true` when this RPC never accepted the broadcast. Read at verdict time,\n * and only when the observation did not complete. */\n neverBroadcast?: () => boolean\n /** Injectable clock, so the silence budget is testable without timers.\n * Mirrors `createConfirmationDeadline`. */\n now?: () => number\n}): Promise<ConfirmationOutcome<T>> {\n const { deadline, signal, pollIntervalMs, probe, read, subject } = options\n const now = options.now ?? Date.now\n\n let settled = false\n\n // Advances the deadline independently of the status reads.\n const advancing = (async () => {\n while (!settled && !signal.aborted) {\n await abortableSleep(DEADLINE_TICK_INTERVAL_MS, signal)\n if (settled || signal.aborted) {\n break\n }\n await deadline.tick(signal)\n }\n })()\n advancing.catch(() => {})\n\n try {\n let failures = 0\n // Did this RPC ever answer? A `null` read still answered. Separates\n // \"polled and saw nothing\" from \"never got a word out of this endpoint\".\n let probeSucceeded = false\n // When a read last answered; the branch start until one does. A `null` read\n // counts as an answer - the endpoint is alive and says nothing.\n let lastAnswerAt = now()\n\n // Records WHY the loop ended, because the two reasons earn different\n // verdicts. Reaching the deadline is a complete observation; being aborted\n // mid-read is not. The final probe below is a bonus on top of a complete\n // observation, so losing it must not downgrade the verdict.\n let deadlineReached = false\n while (!signal.aborted) {\n if (deadline.reached()) {\n deadlineReached = true\n break\n }\n try {\n const value = await probe()\n failures = 0\n lastAnswerAt = now()\n probeSucceeded = true\n if (value !== null) {\n return { kind: 'confirmed', value }\n }\n } catch (error) {\n // `failures` still drives the backoff below; only the give-up rule is\n // time-based.\n failures += 1\n if (now() - lastAnswerAt >= MAX_STATUS_READ_SILENCE_MS) {\n throw error\n }\n }\n // Exponential backoff, so a throttling burst meets a falling rate. The\n // outer `max` stops the cap inverting it for a caller whose base\n // interval already exceeds the cap.\n const delay =\n failures === 0\n ? pollIntervalMs\n : Math.max(\n pollIntervalMs,\n Math.min(\n pollIntervalMs * 2 ** failures,\n STATUS_RETRY_BACKOFF_CAP_MS\n )\n )\n await abortableSleep(delay, signal)\n }\n\n // The status may have flipped between the last poll and the deadline\n // being reached.\n if (!signal.aborted) {\n try {\n const value = await probe()\n probeSucceeded = true\n if (value !== null) {\n return { kind: 'confirmed', value }\n }\n } catch (_) {\n // The loop already ran. One failed final probe is not evidence that\n // this RPC is unusable.\n }\n }\n\n // A completed observation outranks everything below: polled to its own\n // deadline and saw nothing. It stays ahead of the send-failure signal on\n // purpose - a throw here is bucketed as `rpc-unavailable` by `raceRpcs`,\n // which would discard a real observation and misreport a genuinely expired\n // transaction as an outage. The never-broadcast case is answered one level\n // up, in the actions, which know whether ANY branch accepted the send.\n //\n // Keyed on `deadlineReached`, not on `!signal.aborted`: the final probe is\n // a bonus on top of the observation, and the shared BRANCH_TIMEOUT_MS timer\n // can abort that probe in every branch at once. Reading the abort here\n // would discard every observation and report a fleet-wide expiry as an\n // outage.\n if (probeSucceeded && deadlineReached) {\n return { kind: 'not-confirmed' }\n }\n\n if (options.neverBroadcast?.()) {\n throw new Error(`Every ${subject} send to this RPC failed.`)\n }\n\n // Every read hung until the abort: an in-flight read never answers, so it\n // never renews `lastAnswerAt` and never throws either - the abort arrives\n // first. `not-confirmed` here would report a hung endpoint as an expiry.\n if (!probeSucceeded) {\n throw new Error(`No ${read} against this RPC ever completed.`)\n }\n\n // Exiting via `signal.aborted` means the final observation never\n // happened — an in-flight read held the loop until the abort cut it off.\n // An answer received early in the window must not stand in for one near\n // the deadline: a branch that answered once and then went dark has no\n // basis to call the subject of the read expired. (A branch aborted because another\n // RPC already confirmed also throws here; `raceRpcs` drops a losing\n // branch's error once its controller has aborted, so nothing is\n // misreported.)\n throw new Error(\n `This RPC stopped answering before a final ${read} could run.`\n )\n } finally {\n settled = true\n }\n}\n"],"mappings":";;;;;AAMA,MAAa,4BAA4B;;;;;;AAMzC,MAAa,6BAA6B;;;;;;;;;;;;;;;;;AAiB1C,MAAa,8BAA8B;;;;;;;;;AAU3C,eAAsB,kBAAqB,SAiBP;CAClC,MAAM,EAAE,UAAU,QAAQ,gBAAgB,OAAO,MAAM,YAAY;CACnE,MAAM,MAAM,QAAQ,OAAO,KAAK;CAEhC,IAAI,UAAU;CAYd,CATmB,YAAY;EAC7B,OAAO,CAAC,WAAW,CAAC,OAAO,SAAS;GAClC,MAAMA,oCAAAA,eAAAA,KAA0C,MAAM;GACtD,IAAI,WAAW,OAAO,SACpB;GAEF,MAAM,SAAS,KAAK,MAAM;EAC5B;CACF,EAAA,CACQ,CAAC,CAAC,YAAY,CAAC,CAAC;CAExB,IAAI;EACF,IAAI,WAAW;EAGf,IAAI,iBAAiB;EAGrB,IAAI,eAAe,IAAI;EAMvB,IAAI,kBAAkB;EACtB,OAAO,CAAC,OAAO,SAAS;GACtB,IAAI,SAAS,QAAQ,GAAG;IACtB,kBAAkB;IAClB;GACF;GACA,IAAI;IACF,MAAM,QAAQ,MAAM,MAAM;IAC1B,WAAW;IACX,eAAe,IAAI;IACnB,iBAAiB;IACjB,IAAI,UAAU,MACZ,OAAO;KAAE,MAAM;KAAa;IAAM;GAEtC,SAAS,OAAO;IAGd,YAAY;IACZ,IAAI,IAAI,IAAI,gBAAA,KACV,MAAM;GAEV;GAIA,MAAM,QACJ,aAAa,IACT,iBACA,KAAK,IACH,gBACA,KAAK,IACH,iBAAiB,KAAK,UACtB,2BACF,CACF;GACN,MAAMA,oCAAAA,eAAe,OAAO,MAAM;EACpC;EAIA,IAAI,CAAC,OAAO,SACV,IAAI;GACF,MAAM,QAAQ,MAAM,MAAM;GAC1B,iBAAiB;GACjB,IAAI,UAAU,MACZ,OAAO;IAAE,MAAM;IAAa;GAAM;EAEtC,SAAS,GAAG,CAGZ;EAeF,IAAI,kBAAkB,iBACpB,OAAO,EAAE,MAAM,gBAAgB;EAGjC,IAAI,QAAQ,iBAAiB,GAC3B,MAAM,IAAI,MAAM,SAAS,QAAQ,0BAA0B;EAM7D,IAAI,CAAC,gBACH,MAAM,IAAI,MAAM,MAAM,KAAK,kCAAkC;EAW/D,MAAM,IAAI,MACR,6CAA6C,KAAK,YACpD;CACF,UAAU;EACR,UAAU;CACZ;AACF"}
@@ -0,0 +1,26 @@
1
+ import { ConfirmationOutcome } from "./types.js";
2
+ //#region src/confirmation/raceRpcs.d.ts
3
+ type RaceResult<T> = {
4
+ kind: "confirmed";
5
+ value: T;
6
+ } | {
7
+ kind: "not-confirmed";
8
+ errors: Error[];
9
+ } | {
10
+ kind: "rpc-unavailable";
11
+ errors: Error[];
12
+ };
13
+ /**
14
+ * Runs `run` against every RPC in parallel and reports the first confirmation.
15
+ *
16
+ * Not `Promise.any`: it turns "polled and saw nothing" into a thrown sentinel,
17
+ * collapsing the difference between an expired transaction and an RPC that
18
+ * never answered - the defect that reported live swaps as `TransactionExpired`.
19
+ * `timeoutMs` is the caller's; this module holds no confirmation policy.
20
+ */
21
+ declare function raceRpcs<Rpc, T>(rpcs: Rpc[], run: (rpc: Rpc, signal: AbortSignal) => Promise<ConfirmationOutcome<T>>, options: {
22
+ timeoutMs: number;
23
+ }): Promise<RaceResult<T>>;
24
+ //#endregion
25
+ export { RaceResult, raceRpcs };
26
+ //# sourceMappingURL=raceRpcs.d.ts.map