@lifi/sdk-provider-solana 4.2.3 → 4.3.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 (54) hide show
  1. package/CHANGELOG.md +19 -0
  2. package/dist/cjs/actions/sendAndConfirmBundle.d.ts +5 -0
  3. package/dist/cjs/actions/sendAndConfirmBundle.js +38 -3
  4. package/dist/cjs/actions/sendAndConfirmBundle.js.map +1 -1
  5. package/dist/cjs/actions/sendAndConfirmTransaction.d.ts +3 -0
  6. package/dist/cjs/actions/sendAndConfirmTransaction.js +56 -10
  7. package/dist/cjs/actions/sendAndConfirmTransaction.js.map +1 -1
  8. package/dist/cjs/confirmation/abortableSleep.d.ts +4 -6
  9. package/dist/cjs/confirmation/abortableSleep.js +4 -6
  10. package/dist/cjs/confirmation/abortableSleep.js.map +1 -1
  11. package/dist/cjs/confirmation/confirmSignature.d.ts +2 -0
  12. package/dist/cjs/confirmation/confirmSignature.js +2 -0
  13. package/dist/cjs/confirmation/confirmSignature.js.map +1 -1
  14. package/dist/cjs/errors/parseSolanaErrors.js +9 -0
  15. package/dist/cjs/errors/parseSolanaErrors.js.map +1 -1
  16. package/dist/cjs/rpc/registry.d.ts +20 -0
  17. package/dist/cjs/rpc/registry.js +54 -11
  18. package/dist/cjs/rpc/registry.js.map +1 -1
  19. package/dist/cjs/version.d.ts +1 -1
  20. package/dist/cjs/version.js +1 -1
  21. package/dist/cjs/version.js.map +1 -1
  22. package/dist/esm/actions/sendAndConfirmBundle.d.ts +5 -0
  23. package/dist/esm/actions/sendAndConfirmBundle.d.ts.map +1 -1
  24. package/dist/esm/actions/sendAndConfirmBundle.js +40 -5
  25. package/dist/esm/actions/sendAndConfirmBundle.js.map +1 -1
  26. package/dist/esm/actions/sendAndConfirmTransaction.d.ts +3 -0
  27. package/dist/esm/actions/sendAndConfirmTransaction.d.ts.map +1 -1
  28. package/dist/esm/actions/sendAndConfirmTransaction.js +58 -12
  29. package/dist/esm/actions/sendAndConfirmTransaction.js.map +1 -1
  30. package/dist/esm/confirmation/abortableSleep.d.ts +4 -6
  31. package/dist/esm/confirmation/abortableSleep.d.ts.map +1 -1
  32. package/dist/esm/confirmation/abortableSleep.js +4 -6
  33. package/dist/esm/confirmation/abortableSleep.js.map +1 -1
  34. package/dist/esm/confirmation/confirmSignature.d.ts +2 -0
  35. package/dist/esm/confirmation/confirmSignature.d.ts.map +1 -1
  36. package/dist/esm/confirmation/confirmSignature.js +2 -1
  37. package/dist/esm/confirmation/confirmSignature.js.map +1 -1
  38. package/dist/esm/errors/parseSolanaErrors.js +9 -0
  39. package/dist/esm/errors/parseSolanaErrors.js.map +1 -1
  40. package/dist/esm/rpc/registry.d.ts +20 -0
  41. package/dist/esm/rpc/registry.d.ts.map +1 -1
  42. package/dist/esm/rpc/registry.js +53 -12
  43. package/dist/esm/rpc/registry.js.map +1 -1
  44. package/dist/esm/version.d.ts +1 -1
  45. package/dist/esm/version.js +1 -1
  46. package/dist/esm/version.js.map +1 -1
  47. package/package.json +2 -2
  48. package/src/actions/sendAndConfirmBundle.ts +85 -5
  49. package/src/actions/sendAndConfirmTransaction.ts +108 -18
  50. package/src/confirmation/abortableSleep.ts +4 -6
  51. package/src/confirmation/confirmSignature.ts +2 -1
  52. package/src/errors/parseSolanaErrors.ts +22 -0
  53. package/src/rpc/registry.ts +66 -21
  54. package/src/version.ts +1 -1
package/CHANGELOG.md CHANGED
@@ -1,5 +1,24 @@
1
1
  # @lifi/sdk-provider-solana
2
2
 
3
+ ## 4.3.1
4
+
5
+ ### Patch Changes
6
+
7
+ - [#499](https://github.com/lifinance/sdk/pull/499) [`2d60ab4`](https://github.com/lifinance/sdk/commit/2d60ab43af2ecd1c17a3bbb126de408952a46d80) Thanks [@chybisov](https://github.com/chybisov)! - A user rejection from a Wallet Standard wallet (code `4001`, or a message such as "User rejected the request") is now reported as `SignatureRejected` instead of `UnknownError`. An `AbortError` is not treated as a rejection.
8
+ - Updated dependencies [[`dcbbdcc`](https://github.com/lifinance/sdk/commit/dcbbdccc2684c4549cbfe06444698f11347206af), [`2d60ab4`](https://github.com/lifinance/sdk/commit/2d60ab43af2ecd1c17a3bbb126de408952a46d80), [`2d60ab4`](https://github.com/lifinance/sdk/commit/2d60ab43af2ecd1c17a3bbb126de408952a46d80), [`2d60ab4`](https://github.com/lifinance/sdk/commit/2d60ab43af2ecd1c17a3bbb126de408952a46d80), [`2d60ab4`](https://github.com/lifinance/sdk/commit/2d60ab43af2ecd1c17a3bbb126de408952a46d80), [`2d60ab4`](https://github.com/lifinance/sdk/commit/2d60ab43af2ecd1c17a3bbb126de408952a46d80)]:
9
+ - @lifi/sdk@4.10.0
10
+
11
+ ## 4.3.0
12
+
13
+ ### Minor Changes
14
+
15
+ - [#493](https://github.com/lifinance/sdk/pull/493) [`145f2b4`](https://github.com/lifinance/sdk/commit/145f2b49dbbc55776e0b0fe34b0b890f3e5be199) Thanks [@chybisov](https://github.com/chybisov)! - Send transactions and Jito bundles through dedicated RPCs set by role in `rpcUrls[ChainId.SOL]`. Transactions go to the `write` RPCs. Bundles go to the `bundle` RPCs that pass the Jito probe, else to the Jito-capable `write` RPCs; while either list is set they never go to the read RPCs, and a Jito route fails with a configuration error if no URL in either list passes the probe. Reads, simulation and confirmation stay on the read RPCs; a write or bundle RPC receives no other reads than the Jito probe, which is cached per URL and repeated only after a failed probe's retry window. All confirmation branches share one send per resend interval, and a write RPC that has not answered its last send gets no new one, so each write RPC holds at most one open send, and a slow one delays confirmation polling by at most one resend interval. Without write or bundle lists, nothing changes.
16
+
17
+ ### Patch Changes
18
+
19
+ - Updated dependencies [[`a65b003`](https://github.com/lifinance/sdk/commit/a65b00391698c3e8c2a1cd826bb0969c6977ecb6), [`9e815bd`](https://github.com/lifinance/sdk/commit/9e815bdd0d818b7e0866c78bdf48065185b64210), [`145f2b4`](https://github.com/lifinance/sdk/commit/145f2b49dbbc55776e0b0fe34b0b890f3e5be199)]:
20
+ - @lifi/sdk@4.9.0
21
+
3
22
  ## 4.2.3
4
23
 
5
24
  ### Patch Changes
@@ -14,6 +14,11 @@ import { Transaction } from "@solana/kit";
14
14
  * `sendBundle` is handed to `confirmBundle` rather than awaited here, so the
15
15
  * deadline starts on the same clock as `BRANCH_TIMEOUT_MS` instead of after
16
16
  * the submission returns.
17
+ *
18
+ * When the client has Solana bundle or write RPCs (`rpcUrls[ChainId.SOL]`),
19
+ * the bundle is submitted once through those that pass the Jito probe - the
20
+ * bundle list first, else the write list - and the read Jito RPCs only poll.
21
+ * With either list set, bundles never go to the read RPCs.
17
22
  */
18
23
  export declare function sendAndConfirmBundle(client: SDKClient, signedTransactions: Transaction[], options?: {
19
24
  /** Runs once, when the first Jito RPC accepts the submission. */
@@ -18,10 +18,38 @@ let _solana_kit = require("@solana/kit");
18
18
  * `sendBundle` is handed to `confirmBundle` rather than awaited here, so the
19
19
  * deadline starts on the same clock as `BRANCH_TIMEOUT_MS` instead of after
20
20
  * the submission returns.
21
+ *
22
+ * When the client has Solana bundle or write RPCs (`rpcUrls[ChainId.SOL]`),
23
+ * the bundle is submitted once through those that pass the Jito probe - the
24
+ * bundle list first, else the write list - and the read Jito RPCs only poll.
25
+ * With either list set, bundles never go to the read RPCs.
21
26
  */
22
27
  async function sendAndConfirmBundle(client, signedTransactions, options) {
23
- const { rpcs: jitoRpcs, unreachable } = await require_rpc_registry.getJitoRpcs(client);
24
- if (jitoRpcs.length === 0) throw new _lifi_sdk.RPCError(_lifi_sdk.LiFiErrorCode.RpcUnavailable, unreachable > 0 ? `Jito bundle required, but the capability probe failed against ${unreachable} configured Solana RPC(s). This is usually temporary - retry. If it persists, the endpoint may refuse \`sendBundle\` for your plan.` : "Jito bundle required, but no configured Solana RPC supports `sendBundle`. Supply a Jito-capable URL via the `rpcUrls` client config option.");
28
+ const [bundleUrls = [], writeUrls = []] = await Promise.all([client.getBundleRpcUrlsByChainId?.(_lifi_sdk.ChainId.SOL), client.getWriteRpcUrlsByChainId?.(_lifi_sdk.ChainId.SOL)]);
29
+ const noSubmitRpcs = {
30
+ rpcs: [],
31
+ unreachable: 0
32
+ };
33
+ const findSubmitRpcs = async () => {
34
+ const bundle = bundleUrls.length ? await require_rpc_registry.getJitoCapableRpcs(bundleUrls) : noSubmitRpcs;
35
+ if (bundle.rpcs.length || !writeUrls.length) return bundle;
36
+ const write = await require_rpc_registry.getJitoCapableRpcs(writeUrls);
37
+ return {
38
+ rpcs: write.rpcs,
39
+ unreachable: bundle.unreachable + write.unreachable
40
+ };
41
+ };
42
+ const [{ rpcs: jitoRpcs, unreachable }, { rpcs: submitRpcs, unreachable: submitUnreachable }] = await Promise.all([require_rpc_registry.getJitoRpcs(client), findSubmitRpcs()]);
43
+ if ((bundleUrls.length || writeUrls.length) && !submitRpcs.length) {
44
+ const lists = [bundleUrls.length && "`rpcUrls[ChainId.SOL].bundle`", writeUrls.length && "`rpcUrls[ChainId.SOL].write`"].filter(Boolean).join(" or ");
45
+ throw new _lifi_sdk.RPCError(_lifi_sdk.LiFiErrorCode.RpcUnavailable, [
46
+ `Jito bundle required, but no URL in ${lists} passed the Jito capability probe.`,
47
+ submitUnreachable > 0 ? "The probe got no answer from some of them. This is usually temporary - retry. If it persists, the endpoint may refuse `sendBundle` for your plan." : "They do not support `sendBundle`: add a Jito-capable URL to `rpcUrls[ChainId.SOL].bundle`.",
48
+ "Bundles never go to the read RPCs while `bundle` or `write` is set.",
49
+ jitoRpcs.length === 0 && unreachable === 0 && "No read RPC supports `getBundleStatuses` to confirm a bundle either: also add a Jito-capable URL to `rpcUrls[ChainId.SOL].read`."
50
+ ].filter(Boolean).join(" "));
51
+ }
52
+ if (jitoRpcs.length === 0) throw new _lifi_sdk.RPCError(_lifi_sdk.LiFiErrorCode.RpcUnavailable, unreachable > 0 ? `Jito bundle required, but the capability probe failed against ${unreachable} configured Solana RPC(s). This is usually temporary - retry. If it persists, the endpoint may refuse \`sendBundle\` for your plan.` : submitRpcs.length > 0 ? "Jito bundle required. A bundle or write RPC can submit it, but no read RPC supports `getBundleStatuses` to confirm it. Add a Jito-capable URL to `rpcUrls[ChainId.SOL].read`." : "Jito bundle required, but no configured Solana RPC supports `sendBundle`. Supply a Jito-capable URL via the `rpcUrls` client config option.");
25
53
  let broadcastReported = false;
26
54
  const reportBroadcast = () => {
27
55
  if (broadcastReported) return;
@@ -32,11 +60,18 @@ async function sendAndConfirmBundle(client, signedTransactions, options) {
32
60
  };
33
61
  const serializedTransactions = signedTransactions.map((transaction) => (0, _solana_kit.getBase64EncodedWireTransaction)(transaction));
34
62
  const lifetimes = await Promise.all(signedTransactions.map((transaction) => require_utils_getTransactionLifetime.getTransactionLifetime(transaction)));
63
+ let submission;
64
+ const submitOnce = (signal) => {
65
+ submission ??= Promise.any(submitRpcs.map((rpc) => rpc.sendBundle(serializedTransactions).send({ abortSignal: signal }))).catch((error) => {
66
+ throw error instanceof AggregateError ? error.errors[0] : error;
67
+ });
68
+ return submission;
69
+ };
35
70
  return require_confirmation_raceRpcs.raceRpcs(jitoRpcs, (rpc, signal) => require_confirmation_confirmBundle.confirmBundle({
36
71
  rpc,
37
72
  signal,
38
73
  lifetimes,
39
- send: () => rpc.sendBundle(serializedTransactions).send({ abortSignal: signal }),
74
+ send: () => submitRpcs.length ? submitOnce(signal) : rpc.sendBundle(serializedTransactions).send({ abortSignal: signal }),
40
75
  onBroadcast: reportBroadcast
41
76
  }), { timeoutMs: require_confirmation_createConfirmationDeadline.BRANCH_TIMEOUT_MS });
42
77
  }
@@ -1 +1 @@
1
- {"version":3,"file":"sendAndConfirmBundle.js","names":["getJitoRpcs","RPCError","LiFiErrorCode","getBase64EncodedWireTransaction","getTransactionLifetime","raceRpcs","confirmBundle","BRANCH_TIMEOUT_MS"],"sources":["../../../src/actions/sendAndConfirmBundle.ts"],"sourcesContent":["import { LiFiErrorCode, RPCError, type SDKClient } from '@lifi/sdk'\nimport { getBase64EncodedWireTransaction, type Transaction } from '@solana/kit'\nimport {\n type BundleConfirmation,\n confirmBundle,\n} from '../confirmation/confirmBundle.js'\nimport { BRANCH_TIMEOUT_MS } from '../confirmation/createConfirmationDeadline.js'\nimport { type RaceResult, raceRpcs } from '../confirmation/raceRpcs.js'\nimport { getJitoRpcs } from '../rpc/registry.js'\nimport { getTransactionLifetime } from '../utils/getTransactionLifetime.js'\n\n/**\n * Sends a Jito bundle to every Jito-capable RPC and returns as soon as one of\n * them confirms it.\n *\n * The deadline receives the lifetime of *every* signed transaction, not just\n * the first: a bundle is an array of independently built backend transactions\n * and they may not share a blockhash.\n *\n * `sendBundle` is handed to `confirmBundle` rather than awaited here, so the\n * deadline starts on the same clock as `BRANCH_TIMEOUT_MS` instead of after\n * the submission returns.\n */\nexport async function sendAndConfirmBundle(\n client: SDKClient,\n signedTransactions: Transaction[],\n options?: {\n /** Runs once, when the first Jito RPC accepts the submission. */\n onBroadcast?: () => void\n }\n): Promise<RaceResult<BundleConfirmation>> {\n const { rpcs: jitoRpcs, unreachable } = await getJitoRpcs(client)\n\n // Named here, where the emptiness is known: racing zero RPCs would surface\n // as a bare `rpc-unavailable`, indistinguishable from a total outage. The\n // two causes get different messages - a configuration gap the integrator can\n // close, or endpoints that never answered.\n //\n // The `unreachable` message names a plan gate as well as an outage: a bare\n // HTTP 401/403 never reaches the JSON-RPC layer, so `readProbeFailure`\n // cannot tell a gated endpoint from a provider mid-deploy and classifies\n // both as `unreachable`. \"Retry\" alone would loop an integrator forever on a\n // gate no retry can clear.\n if (jitoRpcs.length === 0) {\n throw new RPCError(\n LiFiErrorCode.RpcUnavailable,\n unreachable > 0\n ? `Jito bundle required, but the capability probe failed against ${unreachable} configured Solana RPC(s). This is usually temporary - retry. If it persists, the endpoint may refuse \\`sendBundle\\` for your plan.`\n : 'Jito bundle required, but no configured Solana RPC supports `sendBundle`. Supply a Jito-capable URL via the `rpcUrls` client config option.'\n )\n }\n\n let broadcastReported = false\n // No `sendAccepted` twin here: a bundle submits once, and a failed `send()`\n // throws out of `confirmBundle` before polling starts, so this action has no\n // not-confirmed-but-never-sent case to disambiguate. See\n // `sendAndConfirmTransaction` for the signature path's version.\n const reportBroadcast = (): void => {\n if (broadcastReported) {\n return\n }\n try {\n options?.onBroadcast?.()\n // Latched only after the callback returned. A callback that threw wrote\n // nothing, so the next successful send must be allowed to try again -\n // latching first made one failed `txLink` write permanent.\n broadcastReported = true\n } catch (_) {\n // This runs integrator code: the callback reaches `updateRouteHook` via\n // `StatusManager.updateAction`. Its failure must never reject the branch\n // that called it - the send has already been accepted by the network at\n // this point, so a throw here would report a landed transaction as an\n // RPC outage. Swallowed rather than surfaced because there is no verdict\n // it could honestly change.\n }\n }\n\n const serializedTransactions = signedTransactions.map((transaction) =>\n getBase64EncodedWireTransaction(transaction)\n )\n\n const lifetimes = await Promise.all(\n signedTransactions.map((transaction) => getTransactionLifetime(transaction))\n )\n\n return raceRpcs(\n jitoRpcs,\n (rpc, signal) =>\n confirmBundle({\n rpc,\n signal,\n lifetimes,\n send: () =>\n rpc.sendBundle(serializedTransactions).send({ abortSignal: signal }),\n onBroadcast: reportBroadcast,\n }),\n { timeoutMs: BRANCH_TIMEOUT_MS }\n )\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;AAuBA,eAAsB,qBACpB,QACA,oBACA,SAIyC;CACzC,MAAM,EAAE,MAAM,UAAU,gBAAgB,MAAMA,qBAAAA,YAAY,MAAM;CAYhE,IAAI,SAAS,WAAW,GACtB,MAAM,IAAIC,UAAAA,SACRC,UAAAA,cAAc,gBACd,cAAc,IACV,iEAAiE,YAAY,uIAC7E,6IACN;CAGF,IAAI,oBAAoB;CAKxB,MAAM,wBAA8B;EAClC,IAAI,mBACF;EAEF,IAAI;GACF,SAAS,cAAc;GAIvB,oBAAoB;EACtB,SAAS,GAAG,CAOZ;CACF;CAEA,MAAM,yBAAyB,mBAAmB,KAAK,iBAAA,GACrDC,YAAAA,gCAAAA,CAAgC,WAAW,CAC7C;CAEA,MAAM,YAAY,MAAM,QAAQ,IAC9B,mBAAmB,KAAK,gBAAgBC,qCAAAA,uBAAuB,WAAW,CAAC,CAC7E;CAEA,OAAOC,8BAAAA,SACL,WACC,KAAK,WACJC,mCAAAA,cAAc;EACZ;EACA;EACA;EACA,YACE,IAAI,WAAW,sBAAsB,CAAC,CAAC,KAAK,EAAE,aAAa,OAAO,CAAC;EACrE,aAAa;CACf,CAAC,GACH,EAAE,WAAWC,gDAAAA,kBAAkB,CACjC;AACF"}
1
+ {"version":3,"file":"sendAndConfirmBundle.js","names":["ChainId","getJitoCapableRpcs","getJitoRpcs","RPCError","LiFiErrorCode","getBase64EncodedWireTransaction","getTransactionLifetime","raceRpcs","confirmBundle","BRANCH_TIMEOUT_MS"],"sources":["../../../src/actions/sendAndConfirmBundle.ts"],"sourcesContent":["import { ChainId, LiFiErrorCode, RPCError, type SDKClient } from '@lifi/sdk'\nimport { getBase64EncodedWireTransaction, type Transaction } from '@solana/kit'\nimport {\n type BundleConfirmation,\n confirmBundle,\n} from '../confirmation/confirmBundle.js'\nimport { BRANCH_TIMEOUT_MS } from '../confirmation/createConfirmationDeadline.js'\nimport { type RaceResult, raceRpcs } from '../confirmation/raceRpcs.js'\nimport { getJitoCapableRpcs, getJitoRpcs } from '../rpc/registry.js'\nimport type { JitoRpcType } from '../rpc/types.js'\nimport { getTransactionLifetime } from '../utils/getTransactionLifetime.js'\n\n/**\n * Sends a Jito bundle to every Jito-capable RPC and returns as soon as one of\n * them confirms it.\n *\n * The deadline receives the lifetime of *every* signed transaction, not just\n * the first: a bundle is an array of independently built backend transactions\n * and they may not share a blockhash.\n *\n * `sendBundle` is handed to `confirmBundle` rather than awaited here, so the\n * deadline starts on the same clock as `BRANCH_TIMEOUT_MS` instead of after\n * the submission returns.\n *\n * When the client has Solana bundle or write RPCs (`rpcUrls[ChainId.SOL]`),\n * the bundle is submitted once through those that pass the Jito probe - the\n * bundle list first, else the write list - and the read Jito RPCs only poll.\n * With either list set, bundles never go to the read RPCs.\n */\nexport async function sendAndConfirmBundle(\n client: SDKClient,\n signedTransactions: Transaction[],\n options?: {\n /** Runs once, when the first Jito RPC accepts the submission. */\n onBroadcast?: () => void\n }\n): Promise<RaceResult<BundleConfirmation>> {\n // With a bundle or write list set, bundles go only to those: the bundle\n // RPCs that pass the Jito probe, else the write RPCs that do. The write list\n // is probed only when it is needed. With neither list, each branch submits\n // through its own read Jito RPC, as before.\n const [bundleUrls = [], writeUrls = []] = await Promise.all([\n client.getBundleRpcUrlsByChainId?.(ChainId.SOL),\n client.getWriteRpcUrlsByChainId?.(ChainId.SOL),\n ])\n const noSubmitRpcs = { rpcs: [] as JitoRpcType[], unreachable: 0 }\n const findSubmitRpcs = async (): Promise<typeof noSubmitRpcs> => {\n const bundle = bundleUrls.length\n ? await getJitoCapableRpcs(bundleUrls)\n : noSubmitRpcs\n if (bundle.rpcs.length || !writeUrls.length) {\n return bundle\n }\n const write = await getJitoCapableRpcs(writeUrls)\n return {\n rpcs: write.rpcs,\n unreachable: bundle.unreachable + write.unreachable,\n }\n }\n const [\n { rpcs: jitoRpcs, unreachable },\n { rpcs: submitRpcs, unreachable: submitUnreachable },\n ] = await Promise.all([getJitoRpcs(client), findSubmitRpcs()])\n\n if ((bundleUrls.length || writeUrls.length) && !submitRpcs.length) {\n const lists = [\n bundleUrls.length && '`rpcUrls[ChainId.SOL].bundle`',\n writeUrls.length && '`rpcUrls[ChainId.SOL].write`',\n ]\n .filter(Boolean)\n .join(' or ')\n throw new RPCError(\n LiFiErrorCode.RpcUnavailable,\n [\n `Jito bundle required, but no URL in ${lists} passed the Jito capability probe.`,\n submitUnreachable > 0\n ? 'The probe got no answer from some of them. This is usually temporary - retry. If it persists, the endpoint may refuse `sendBundle` for your plan.'\n : 'They do not support `sendBundle`: add a Jito-capable URL to `rpcUrls[ChainId.SOL].bundle`.',\n 'Bundles never go to the read RPCs while `bundle` or `write` is set.',\n // Only a definite gap: a read RPC that did not answer the probe may\n // support bundles, and the next attempt reports that case itself.\n jitoRpcs.length === 0 &&\n unreachable === 0 &&\n 'No read RPC supports `getBundleStatuses` to confirm a bundle either: also add a Jito-capable URL to `rpcUrls[ChainId.SOL].read`.',\n ]\n .filter(Boolean)\n .join(' ')\n )\n }\n\n // Named here, where the emptiness is known: racing zero RPCs would surface\n // as a bare `rpc-unavailable`, indistinguishable from a total outage. The\n // two causes get different messages - a configuration gap the integrator can\n // close, or endpoints that never answered.\n //\n // The `unreachable` message names a plan gate as well as an outage: a bare\n // HTTP 401/403 never reaches the JSON-RPC layer, so `readProbeFailure`\n // cannot tell a gated endpoint from a provider mid-deploy and classifies\n // both as `unreachable`. \"Retry\" alone would loop an integrator forever on a\n // gate no retry can clear.\n if (jitoRpcs.length === 0) {\n throw new RPCError(\n LiFiErrorCode.RpcUnavailable,\n unreachable > 0\n ? `Jito bundle required, but the capability probe failed against ${unreachable} configured Solana RPC(s). This is usually temporary - retry. If it persists, the endpoint may refuse \\`sendBundle\\` for your plan.`\n : submitRpcs.length > 0\n ? 'Jito bundle required. A bundle or write RPC can submit it, but no read RPC supports `getBundleStatuses` to confirm it. Add a Jito-capable URL to `rpcUrls[ChainId.SOL].read`.'\n : 'Jito bundle required, but no configured Solana RPC supports `sendBundle`. Supply a Jito-capable URL via the `rpcUrls` client config option.'\n )\n }\n\n let broadcastReported = false\n // No `sendAccepted` twin here: a bundle submits once, and a failed `send()`\n // throws out of `confirmBundle` before polling starts, so this action has no\n // not-confirmed-but-never-sent case to disambiguate. See\n // `sendAndConfirmTransaction` for the signature path's version.\n const reportBroadcast = (): void => {\n if (broadcastReported) {\n return\n }\n try {\n options?.onBroadcast?.()\n // Latched only after the callback returned. A callback that threw wrote\n // nothing, so the next successful send must be allowed to try again -\n // latching first made one failed `txLink` write permanent.\n broadcastReported = true\n } catch (_) {\n // This runs integrator code: the callback reaches `updateRouteHook` via\n // `StatusManager.updateAction`. Its failure must never reject the branch\n // that called it - the send has already been accepted by the network at\n // this point, so a throw here would report a landed transaction as an\n // RPC outage. Swallowed rather than surfaced because there is no verdict\n // it could honestly change.\n }\n }\n\n const serializedTransactions = signedTransactions.map((transaction) =>\n getBase64EncodedWireTransaction(transaction)\n )\n\n const lifetimes = await Promise.all(\n signedTransactions.map((transaction) => getTransactionLifetime(transaction))\n )\n\n // One submission for every polling branch: the bundle id is derived from\n // the transactions, so each branch polls the same bundle. Started by the\n // first branch that asks, so its deadline already runs.\n let submission: Promise<string> | undefined\n const submitOnce = (signal: AbortSignal): Promise<string> => {\n submission ??= Promise.any(\n submitRpcs.map((rpc) =>\n rpc.sendBundle(serializedTransactions).send({ abortSignal: signal })\n )\n ).catch((error: unknown) => {\n // Surface a refusal the way a single configured RPC would, not as a\n // nested AggregateError inside the race's own error list.\n throw error instanceof AggregateError ? error.errors[0] : error\n })\n return submission\n }\n\n return raceRpcs(\n jitoRpcs,\n (rpc, signal) =>\n confirmBundle({\n rpc,\n signal,\n lifetimes,\n send: () =>\n submitRpcs.length\n ? submitOnce(signal)\n : rpc\n .sendBundle(serializedTransactions)\n .send({ abortSignal: signal }),\n onBroadcast: reportBroadcast,\n }),\n { timeoutMs: BRANCH_TIMEOUT_MS }\n )\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;AA6BA,eAAsB,qBACpB,QACA,oBACA,SAIyC;CAKzC,MAAM,CAAC,aAAa,CAAC,GAAG,YAAY,CAAC,KAAK,MAAM,QAAQ,IAAI,CAC1D,OAAO,4BAA4BA,UAAAA,QAAQ,GAAG,GAC9C,OAAO,2BAA2BA,UAAAA,QAAQ,GAAG,CAC/C,CAAC;CACD,MAAM,eAAe;EAAE,MAAM,CAAC;EAAoB,aAAa;CAAE;CACjE,MAAM,iBAAiB,YAA0C;EAC/D,MAAM,SAAS,WAAW,SACtB,MAAMC,qBAAAA,mBAAmB,UAAU,IACnC;EACJ,IAAI,OAAO,KAAK,UAAU,CAAC,UAAU,QACnC,OAAO;EAET,MAAM,QAAQ,MAAMA,qBAAAA,mBAAmB,SAAS;EAChD,OAAO;GACL,MAAM,MAAM;GACZ,aAAa,OAAO,cAAc,MAAM;EAC1C;CACF;CACA,MAAM,CACJ,EAAE,MAAM,UAAU,eAClB,EAAE,MAAM,YAAY,aAAa,uBAC/B,MAAM,QAAQ,IAAI,CAACC,qBAAAA,YAAY,MAAM,GAAG,eAAe,CAAC,CAAC;CAE7D,KAAK,WAAW,UAAU,UAAU,WAAW,CAAC,WAAW,QAAQ;EACjE,MAAM,QAAQ,CACZ,WAAW,UAAU,iCACrB,UAAU,UAAU,8BACtB,CAAC,CACE,OAAO,OAAO,CAAC,CACf,KAAK,MAAM;EACd,MAAM,IAAIC,UAAAA,SACRC,UAAAA,cAAc,gBACd;GACE,uCAAuC,MAAM;GAC7C,oBAAoB,IAChB,sJACA;GACJ;GAGA,SAAS,WAAW,KAClB,gBAAgB,KAChB;EACJ,CAAC,CACE,OAAO,OAAO,CAAC,CACf,KAAK,GAAG,CACb;CACF;CAYA,IAAI,SAAS,WAAW,GACtB,MAAM,IAAID,UAAAA,SACRC,UAAAA,cAAc,gBACd,cAAc,IACV,iEAAiE,YAAY,uIAC7E,WAAW,SAAS,IAClB,kLACA,6IACR;CAGF,IAAI,oBAAoB;CAKxB,MAAM,wBAA8B;EAClC,IAAI,mBACF;EAEF,IAAI;GACF,SAAS,cAAc;GAIvB,oBAAoB;EACtB,SAAS,GAAG,CAOZ;CACF;CAEA,MAAM,yBAAyB,mBAAmB,KAAK,iBAAA,GACrDC,YAAAA,gCAAAA,CAAgC,WAAW,CAC7C;CAEA,MAAM,YAAY,MAAM,QAAQ,IAC9B,mBAAmB,KAAK,gBAAgBC,qCAAAA,uBAAuB,WAAW,CAAC,CAC7E;CAKA,IAAI;CACJ,MAAM,cAAc,WAAyC;EAC3D,eAAe,QAAQ,IACrB,WAAW,KAAK,QACd,IAAI,WAAW,sBAAsB,CAAC,CAAC,KAAK,EAAE,aAAa,OAAO,CAAC,CACrE,CACF,CAAC,CAAC,OAAO,UAAmB;GAG1B,MAAM,iBAAiB,iBAAiB,MAAM,OAAO,KAAK;EAC5D,CAAC;EACD,OAAO;CACT;CAEA,OAAOC,8BAAAA,SACL,WACC,KAAK,WACJC,mCAAAA,cAAc;EACZ;EACA;EACA;EACA,YACE,WAAW,SACP,WAAW,MAAM,IACjB,IACG,WAAW,sBAAsB,CAAC,CAClC,KAAK,EAAE,aAAa,OAAO,CAAC;EACrC,aAAa;CACf,CAAC,GACH,EAAE,WAAWC,gDAAAA,kBAAkB,CACjC;AACF"}
@@ -7,6 +7,9 @@ import { Transaction } from "@solana/kit";
7
7
  * Sends a Solana transaction to every configured RPC and returns as soon as
8
8
  * one of them confirms it.
9
9
  *
10
+ * When the client has Solana write RPCs (`rpcUrls[ChainId.SOL].write`), the
11
+ * transaction is sent only through those, and the read RPCs only confirm it.
12
+ *
10
13
  * The polling horizon comes from the signed transaction's own blockhash and a
11
14
  * wall-clock ceiling. It deliberately never comes from `getBlockHeight`: at
12
15
  * least one endpoint in the default LI.FI set answers that call with the slot
@@ -4,19 +4,23 @@ const require_confirmation_createConfirmationDeadline = require("../confirmation
4
4
  const require_confirmation_raceRpcs = require("../confirmation/raceRpcs.js");
5
5
  const require_utils_getTransactionLifetime = require("../utils/getTransactionLifetime.js");
6
6
  const require_confirmation_confirmSignature = require("../confirmation/confirmSignature.js");
7
+ let _lifi_sdk = require("@lifi/sdk");
7
8
  let _solana_kit = require("@solana/kit");
8
9
  //#region src/actions/sendAndConfirmTransaction.ts
9
10
  /**
10
11
  * Sends a Solana transaction to every configured RPC and returns as soon as
11
12
  * one of them confirms it.
12
13
  *
14
+ * When the client has Solana write RPCs (`rpcUrls[ChainId.SOL].write`), the
15
+ * transaction is sent only through those, and the read RPCs only confirm it.
16
+ *
13
17
  * The polling horizon comes from the signed transaction's own blockhash and a
14
18
  * wall-clock ceiling. It deliberately never comes from `getBlockHeight`: at
15
19
  * least one endpoint in the default LI.FI set answers that call with the slot
16
20
  * number.
17
21
  */
18
22
  async function sendAndConfirmTransaction(client, signedTransaction, options) {
19
- const solanaRpcs = await require_rpc_registry.getSolanaRpcs(client);
23
+ const [solanaRpcs, writeRpcUrls = []] = await Promise.all([require_rpc_registry.getSolanaRpcs(client), client.getWriteRpcUrlsByChainId?.(_lifi_sdk.ChainId.SOL)]);
20
24
  let broadcastReported = false;
21
25
  let sendAccepted = false;
22
26
  const reportBroadcast = () => {
@@ -36,17 +40,59 @@ async function sendAndConfirmTransaction(client, signedTransaction, options) {
36
40
  preflightCommitment: "confirmed",
37
41
  encoding: "base64"
38
42
  };
39
- const resend = async (rpc, signal) => {
43
+ const send = async (rpc, signal) => {
40
44
  await rpc.sendTransaction(signedTxSerialized, rawTransactionOptions).send({ abortSignal: signal });
41
45
  };
42
- const result = await require_confirmation_raceRpcs.raceRpcs(solanaRpcs, (rpc, signal) => require_confirmation_confirmSignature.confirmSignature({
43
- rpc,
44
- signal,
45
- signature: txSignature,
46
- lifetimes: [lifetime],
47
- resend,
48
- onBroadcast: reportBroadcast
49
- }), { timeoutMs: require_confirmation_createConfirmationDeadline.BRANCH_TIMEOUT_MS });
46
+ const writeRpcs = writeRpcUrls.length ? require_rpc_registry.getSolanaWriteRpcs(writeRpcUrls) : void 0;
47
+ const writes = new AbortController();
48
+ let lastWrite;
49
+ const openSends = /* @__PURE__ */ new Set();
50
+ const sendToWriteRpc = async (rpc) => {
51
+ openSends.add(rpc);
52
+ try {
53
+ await send(rpc, writes.signal);
54
+ } finally {
55
+ openSends.delete(rpc);
56
+ }
57
+ };
58
+ const sendToWriteRpcs = (rpcs) => {
59
+ const now = Date.now();
60
+ if (lastWrite && now - lastWrite.at < 1e3) return lastWrite.sent;
61
+ const ready = rpcs.filter((rpc) => !openSends.has(rpc));
62
+ const sent = Promise.any(ready.map(sendToWriteRpc)).then(() => void 0);
63
+ sent.then(() => {
64
+ if (!writes.signal.aborted) reportBroadcast();
65
+ }, () => {});
66
+ lastWrite = {
67
+ at: now,
68
+ sent
69
+ };
70
+ return sent;
71
+ };
72
+ const waitForWrite = (sent) => new Promise((resolve, reject) => {
73
+ const timer = setTimeout(() => reject(/* @__PURE__ */ new Error("No write RPC accepted the transaction in time.")), require_confirmation_confirmSignature.RESEND_INTERVAL_MS);
74
+ sent.then(() => {
75
+ clearTimeout(timer);
76
+ resolve();
77
+ }, (error) => {
78
+ clearTimeout(timer);
79
+ reject(error);
80
+ });
81
+ });
82
+ const resend = writeRpcs ? () => waitForWrite(sendToWriteRpcs(writeRpcs)) : send;
83
+ let result;
84
+ try {
85
+ result = await require_confirmation_raceRpcs.raceRpcs(solanaRpcs, (rpc, signal) => require_confirmation_confirmSignature.confirmSignature({
86
+ rpc,
87
+ signal,
88
+ signature: txSignature,
89
+ lifetimes: [lifetime],
90
+ resend,
91
+ onBroadcast: reportBroadcast
92
+ }), { timeoutMs: require_confirmation_createConfirmationDeadline.BRANCH_TIMEOUT_MS });
93
+ } finally {
94
+ writes.abort();
95
+ }
50
96
  if (result.kind === "not-confirmed" && !sendAccepted) return {
51
97
  kind: "rpc-unavailable",
52
98
  errors: result.errors
@@ -1 +1 @@
1
- {"version":3,"file":"sendAndConfirmTransaction.js","names":["getSolanaRpcs","getBase64EncodedWireTransaction","getSignatureFromTransaction","getTransactionLifetime","raceRpcs","confirmSignature","BRANCH_TIMEOUT_MS"],"sources":["../../../src/actions/sendAndConfirmTransaction.ts"],"sourcesContent":["import type { SDKClient } from '@lifi/sdk'\nimport {\n type Commitment,\n getBase64EncodedWireTransaction,\n getSignatureFromTransaction,\n type Transaction,\n} from '@solana/kit'\nimport { confirmSignature } from '../confirmation/confirmSignature.js'\nimport { BRANCH_TIMEOUT_MS } from '../confirmation/createConfirmationDeadline.js'\nimport { type RaceResult, raceRpcs } from '../confirmation/raceRpcs.js'\nimport type { SignatureStatus } from '../confirmation/types.js'\nimport { getSolanaRpcs } from '../rpc/registry.js'\nimport type { SolanaRpcType } from '../rpc/types.js'\nimport { getTransactionLifetime } from '../utils/getTransactionLifetime.js'\n\n/**\n * Sends a Solana transaction to every configured RPC and returns as soon as\n * one of them confirms it.\n *\n * The polling horizon comes from the signed transaction's own blockhash and a\n * wall-clock ceiling. It deliberately never comes from `getBlockHeight`: at\n * least one endpoint in the default LI.FI set answers that call with the slot\n * number.\n */\nexport async function sendAndConfirmTransaction(\n client: SDKClient,\n signedTransaction: Transaction,\n options?: {\n /** Runs once, when the first RPC accepts a send. */\n onBroadcast?: () => void\n }\n): Promise<RaceResult<SignatureStatus>> {\n const solanaRpcs = await getSolanaRpcs(client)\n\n let broadcastReported = false\n // Distinct from `broadcastReported`, which records whether the integrator\n // callback has *succeeded*. This one answers \"did any RPC accept the send?\",\n // and only that question may steer the verdict below. Set before the callback\n // runs, so a hook that throws on every resend cannot make a real expiry look\n // like an outage.\n let sendAccepted = false\n const reportBroadcast = (): void => {\n sendAccepted = true\n if (broadcastReported) {\n return\n }\n try {\n options?.onBroadcast?.()\n // Latched only after the callback returned. A callback that threw wrote\n // nothing, so the next successful send must be allowed to try again -\n // latching first made one failed `txLink` write permanent.\n broadcastReported = true\n } catch (_) {\n // This runs integrator code: the callback reaches `updateRouteHook` via\n // `StatusManager.updateAction`. Its failure must never reject the branch\n // that called it - the send has already been accepted by the network at\n // this point, so a throw here would report a landed transaction as an\n // RPC outage. Swallowed rather than surfaced because there is no verdict\n // it could honestly change.\n }\n }\n\n const signedTxSerialized = getBase64EncodedWireTransaction(signedTransaction)\n const txSignature = getSignatureFromTransaction(signedTransaction)\n\n const lifetime = await getTransactionLifetime(signedTransaction)\n\n const rawTransactionOptions = {\n // We can skip preflight check after the first transaction has been sent\n // https://solana.com/docs/advanced/retry#the-cost-of-skipping-preflight\n skipPreflight: true,\n // Setting max retries to 0 as we are handling retries manually\n maxRetries: BigInt(0),\n // https://solana.com/docs/advanced/confirmation#use-an-appropriate-preflight-commitment-level\n preflightCommitment: 'confirmed' as Commitment,\n encoding: 'base64' as const,\n }\n\n const resend = async (\n rpc: SolanaRpcType,\n signal: AbortSignal\n ): Promise<void> => {\n await rpc\n .sendTransaction(signedTxSerialized, rawTransactionOptions)\n .send({ abortSignal: signal })\n }\n\n const result = await raceRpcs(\n solanaRpcs,\n (rpc, signal) =>\n confirmSignature({\n rpc,\n signal,\n signature: txSignature,\n lifetimes: [lifetime],\n resend,\n onBroadcast: reportBroadcast,\n }),\n { timeoutMs: BRANCH_TIMEOUT_MS }\n )\n\n // Only this scope knows whether ANY branch accepted the send. A branch that\n // polls to its deadline reports `not-confirmed` regardless - correct per\n // branch, but across the whole race it would claim a transaction expired\n // when nothing ever submitted it. That is an outage, not an expiry.\n //\n // Reads `sendAccepted`, never `broadcastReported`: the latter is false\n // whenever the integrator's callback threw, which says nothing about whether\n // the network took the transaction.\n if (result.kind === 'not-confirmed' && !sendAccepted) {\n return { kind: 'rpc-unavailable', errors: result.errors }\n }\n\n return result\n}\n"],"mappings":";;;;;;;;;;;;;;;;;AAwBA,eAAsB,0BACpB,QACA,mBACA,SAIsC;CACtC,MAAM,aAAa,MAAMA,qBAAAA,cAAc,MAAM;CAE7C,IAAI,oBAAoB;CAMxB,IAAI,eAAe;CACnB,MAAM,wBAA8B;EAClC,eAAe;EACf,IAAI,mBACF;EAEF,IAAI;GACF,SAAS,cAAc;GAIvB,oBAAoB;EACtB,SAAS,GAAG,CAOZ;CACF;CAEA,MAAM,sBAAA,GAAqBC,YAAAA,gCAAAA,CAAgC,iBAAiB;CAC5E,MAAM,eAAA,GAAcC,YAAAA,4BAAAA,CAA4B,iBAAiB;CAEjE,MAAM,WAAW,MAAMC,qCAAAA,uBAAuB,iBAAiB;CAE/D,MAAM,wBAAwB;EAG5B,eAAe;EAEf,YAAY,OAAO,CAAC;EAEpB,qBAAqB;EACrB,UAAU;CACZ;CAEA,MAAM,SAAS,OACb,KACA,WACkB;EAClB,MAAM,IACH,gBAAgB,oBAAoB,qBAAqB,CAAC,CAC1D,KAAK,EAAE,aAAa,OAAO,CAAC;CACjC;CAEA,MAAM,SAAS,MAAMC,8BAAAA,SACnB,aACC,KAAK,WACJC,sCAAAA,iBAAiB;EACf;EACA;EACA,WAAW;EACX,WAAW,CAAC,QAAQ;EACpB;EACA,aAAa;CACf,CAAC,GACH,EAAE,WAAWC,gDAAAA,kBAAkB,CACjC;CAUA,IAAI,OAAO,SAAS,mBAAmB,CAAC,cACtC,OAAO;EAAE,MAAM;EAAmB,QAAQ,OAAO;CAAO;CAG1D,OAAO;AACT"}
1
+ {"version":3,"file":"sendAndConfirmTransaction.js","names":["getSolanaRpcs","ChainId","getBase64EncodedWireTransaction","getSignatureFromTransaction","getTransactionLifetime","getSolanaWriteRpcs","RESEND_INTERVAL_MS","raceRpcs","confirmSignature","BRANCH_TIMEOUT_MS"],"sources":["../../../src/actions/sendAndConfirmTransaction.ts"],"sourcesContent":["import { ChainId, type SDKClient } from '@lifi/sdk'\nimport {\n type Commitment,\n getBase64EncodedWireTransaction,\n getSignatureFromTransaction,\n type Transaction,\n} from '@solana/kit'\nimport {\n confirmSignature,\n RESEND_INTERVAL_MS,\n} 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, getSolanaWriteRpcs } 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 * When the client has Solana write RPCs (`rpcUrls[ChainId.SOL].write`), the\n * transaction is sent only through those, and the read RPCs only confirm 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, writeRpcUrls = []] = await Promise.all([\n getSolanaRpcs(client),\n client.getWriteRpcUrlsByChainId?.(ChainId.SOL),\n ])\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 send = 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 writeRpcs = writeRpcUrls.length\n ? getSolanaWriteRpcs(writeRpcUrls)\n : undefined\n\n // Sends to the write RPCs belong to the whole call, not to one branch:\n // other branches wait on the same send, so the branch that started it must\n // not cancel it by ending. They end when the race does.\n const writes = new AbortController()\n\n // Every confirmation branch resends about once a second. Branches share one\n // send to the write RPCs per interval, so each write RPC sees the same rate\n // it would as a configured RPC, however many configured RPCs are polling.\n let lastWrite: { at: number; sent: Promise<void> } | undefined\n // A write RPC that has not answered its last send gets no new one, so a\n // hung endpoint holds one open request, not one per interval.\n const openSends = new Set<SolanaRpcType>()\n const sendToWriteRpc = async (rpc: SolanaRpcType): Promise<void> => {\n openSends.add(rpc)\n try {\n await send(rpc, writes.signal)\n } finally {\n openSends.delete(rpc)\n }\n }\n const sendToWriteRpcs = (rpcs: SolanaRpcType[]): Promise<void> => {\n const now = Date.now()\n if (lastWrite && now - lastWrite.at < RESEND_INTERVAL_MS) {\n return lastWrite.sent\n }\n // With every write RPC busy this rejects at once, and the branch polls.\n const ready = rpcs.filter((rpc) => !openSends.has(rpc))\n // Accepted as soon as one write RPC accepts it.\n const sent = Promise.any(ready.map(sendToWriteRpc)).then(() => undefined)\n // Recorded here, not only by the branches: a branch stops waiting after\n // one interval (below), and an acceptance after that must still count.\n // Skipped once the race is over, so a late acceptance cannot regress an\n // action status the wait task already finalized.\n sent.then(\n () => {\n if (!writes.signal.aborted) {\n reportBroadcast()\n }\n },\n () => {}\n )\n lastWrite = { at: now, sent }\n return sent\n }\n\n // `confirmSignature` awaits its first send before it starts polling. Every\n // branch waits on the same shared send, so a write RPC that hangs would hold\n // up polling on all of them - even for a transaction that already landed.\n // A branch waits at most one resend interval, then polls either way.\n const waitForWrite = (sent: Promise<void>): Promise<void> =>\n new Promise((resolve, reject) => {\n const timer = setTimeout(\n () =>\n reject(new Error('No write RPC accepted the transaction in time.')),\n RESEND_INTERVAL_MS\n )\n sent.then(\n () => {\n clearTimeout(timer)\n resolve()\n },\n (error: unknown) => {\n clearTimeout(timer)\n reject(error)\n }\n )\n })\n\n const resend = writeRpcs\n ? (): Promise<void> => waitForWrite(sendToWriteRpcs(writeRpcs))\n : send\n\n let result: RaceResult<SignatureStatus>\n try {\n 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 } finally {\n writes.abort()\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":";;;;;;;;;;;;;;;;;;;;;AA8BA,eAAsB,0BACpB,QACA,mBACA,SAIsC;CACtC,MAAM,CAAC,YAAY,eAAe,CAAC,KAAK,MAAM,QAAQ,IAAI,CACxDA,qBAAAA,cAAc,MAAM,GACpB,OAAO,2BAA2BC,UAAAA,QAAQ,GAAG,CAC/C,CAAC;CAED,IAAI,oBAAoB;CAMxB,IAAI,eAAe;CACnB,MAAM,wBAA8B;EAClC,eAAe;EACf,IAAI,mBACF;EAEF,IAAI;GACF,SAAS,cAAc;GAIvB,oBAAoB;EACtB,SAAS,GAAG,CAOZ;CACF;CAEA,MAAM,sBAAA,GAAqBC,YAAAA,gCAAAA,CAAgC,iBAAiB;CAC5E,MAAM,eAAA,GAAcC,YAAAA,4BAAAA,CAA4B,iBAAiB;CAEjE,MAAM,WAAW,MAAMC,qCAAAA,uBAAuB,iBAAiB;CAE/D,MAAM,wBAAwB;EAG5B,eAAe;EAEf,YAAY,OAAO,CAAC;EAEpB,qBAAqB;EACrB,UAAU;CACZ;CAEA,MAAM,OAAO,OACX,KACA,WACkB;EAClB,MAAM,IACH,gBAAgB,oBAAoB,qBAAqB,CAAC,CAC1D,KAAK,EAAE,aAAa,OAAO,CAAC;CACjC;CAEA,MAAM,YAAY,aAAa,SAC3BC,qBAAAA,mBAAmB,YAAY,IAC/B,KAAA;CAKJ,MAAM,SAAS,IAAI,gBAAgB;CAKnC,IAAI;CAGJ,MAAM,4BAAY,IAAI,IAAmB;CACzC,MAAM,iBAAiB,OAAO,QAAsC;EAClE,UAAU,IAAI,GAAG;EACjB,IAAI;GACF,MAAM,KAAK,KAAK,OAAO,MAAM;EAC/B,UAAU;GACR,UAAU,OAAO,GAAG;EACtB;CACF;CACA,MAAM,mBAAmB,SAAyC;EAChE,MAAM,MAAM,KAAK,IAAI;EACrB,IAAI,aAAa,MAAM,UAAU,KAAA,KAC/B,OAAO,UAAU;EAGnB,MAAM,QAAQ,KAAK,QAAQ,QAAQ,CAAC,UAAU,IAAI,GAAG,CAAC;EAEtD,MAAM,OAAO,QAAQ,IAAI,MAAM,IAAI,cAAc,CAAC,CAAC,CAAC,WAAW,KAAA,CAAS;EAKxE,KAAK,WACG;GACJ,IAAI,CAAC,OAAO,OAAO,SACjB,gBAAgB;EAEpB,SACM,CAAC,CACT;EACA,YAAY;GAAE,IAAI;GAAK;EAAK;EAC5B,OAAO;CACT;CAMA,MAAM,gBAAgB,SACpB,IAAI,SAAS,SAAS,WAAW;EAC/B,MAAM,QAAQ,iBAEV,uBAAO,IAAI,MAAM,gDAAgD,CAAC,GACpEC,sCAAAA,kBACF;EACA,KAAK,WACG;GACJ,aAAa,KAAK;GAClB,QAAQ;EACV,IACC,UAAmB;GAClB,aAAa,KAAK;GAClB,OAAO,KAAK;EACd,CACF;CACF,CAAC;CAEH,MAAM,SAAS,kBACU,aAAa,gBAAgB,SAAS,CAAC,IAC5D;CAEJ,IAAI;CACJ,IAAI;EACF,SAAS,MAAMC,8BAAAA,SACb,aACC,KAAK,WACJC,sCAAAA,iBAAiB;GACf;GACA;GACA,WAAW;GACX,WAAW,CAAC,QAAQ;GACpB;GACA,aAAa;EACf,CAAC,GACH,EAAE,WAAWC,gDAAAA,kBAAkB,CACjC;CACF,UAAU;EACR,OAAO,MAAM;CACf;CAUA,IAAI,OAAO,SAAS,mBAAmB,CAAC,cACtC,OAAO;EAAE,MAAM;EAAmB,QAAQ,OAAO;CAAO;CAG1D,OAAO;AACT"}
@@ -2,16 +2,14 @@
2
2
  /**
3
3
  * Sleeps for `ms`, or until `signal` aborts - whichever comes first.
4
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
5
+ * The confirmation branches need the abort, because both detached loops
8
6
  * here sleep between iterations and a plain timer stays alive for the whole
9
7
  * interval after the branch has already returned - one live timer per RPC,
10
8
  * holding the Node event loop open past the end of a race.
11
9
  *
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.
10
+ * Never rejects on abort, unlike `@lifi/sdk`'s `sleep(ms, { signal })`. The
11
+ * callers re-check `signal.aborted` and exit through their own loop
12
+ * condition, so a rejection here would only add a catch to every call site.
15
13
  */
16
14
  export declare function abortableSleep(ms: number, signal: AbortSignal): Promise<void>;
17
15
  //#endregion
@@ -3,16 +3,14 @@ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
3
3
  /**
4
4
  * Sleeps for `ms`, or until `signal` aborts - whichever comes first.
5
5
  *
6
- * Not `@lifi/sdk`'s `sleep`: that one is publicly exported, so making its
7
- * timer abortable or unref'd would change behaviour for every caller in the
8
- * repo. The confirmation branches need the abort, because both detached loops
6
+ * The confirmation branches need the abort, because both detached loops
9
7
  * here sleep between iterations and a plain timer stays alive for the whole
10
8
  * interval after the branch has already returned - one live timer per RPC,
11
9
  * holding the Node event loop open past the end of a race.
12
10
  *
13
- * Never rejects on abort. The callers re-check `signal.aborted` and exit
14
- * through their own loop condition, so a rejection here would only add a
15
- * catch to every call site.
11
+ * Never rejects on abort, unlike `@lifi/sdk`'s `sleep(ms, { signal })`. The
12
+ * callers re-check `signal.aborted` and exit through their own loop
13
+ * condition, so a rejection here would only add a catch to every call site.
16
14
  */
17
15
  function abortableSleep(ms, signal) {
18
16
  if (signal.aborted) return Promise.resolve();
@@ -1 +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"}
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 * 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, unlike `@lifi/sdk`'s `sleep(ms, { signal })`. The\n * callers re-check `signal.aborted` and exit through their own loop\n * condition, so a rejection here would only add a 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":";;;;;;;;;;;;;;AAYA,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"}
@@ -3,6 +3,8 @@ import { TransactionLifetime } from "../utils/getTransactionLifetime.js";
3
3
  import { ConfirmationOutcome, SignatureStatus } from "./types.js";
4
4
  import { Signature } from "@solana/kit";
5
5
  //#region src/confirmation/confirmSignature.d.ts
6
+ /** How often each confirmation branch resends the transaction. */
7
+ export declare const RESEND_INTERVAL_MS = 1e3;
6
8
  /**
7
9
  * How often this poller re-reads `getSignatureStatuses`. The default Solana
8
10
  * RPCs tolerate 2.5 req/s of status reads; the Jito bundle poller runs slower
@@ -4,6 +4,7 @@ const require_confirmation_abortableSleep = require("./abortableSleep.js");
4
4
  const require_confirmation_pollUntilDeadline = require("./pollUntilDeadline.js");
5
5
  const require_confirmation_types = require("./types.js");
6
6
  //#region src/confirmation/confirmSignature.ts
7
+ /** How often each confirmation branch resends the transaction. */
7
8
  const RESEND_INTERVAL_MS = 1e3;
8
9
  /**
9
10
  * How often this poller re-reads `getSignatureStatuses`. The default Solana
@@ -60,6 +61,7 @@ async function confirmSignature(options) {
60
61
  }
61
62
  }
62
63
  //#endregion
64
+ exports.RESEND_INTERVAL_MS = RESEND_INTERVAL_MS;
63
65
  exports.SIGNATURE_POLL_INTERVAL_MS = SIGNATURE_POLL_INTERVAL_MS;
64
66
  exports.confirmSignature = confirmSignature;
65
67
 
@@ -1 +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"}
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\n/** How often each confirmation branch resends the transaction. */\nexport const 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":";;;;;;;AAaA,MAAa,qBAAqB;;;;;;AAMlC,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"}
@@ -10,10 +10,19 @@ const parseSolanaErrors = async (e, step, action) => {
10
10
  const baseError = handleSpecificErrors(e);
11
11
  return new _lifi_sdk.SDKError(baseError, step, action);
12
12
  };
13
+ const userRejectionMessage = /(^|\W)user\W+(has\W+)?(rejected|denied|cancell?ed)|\b(rejected|denied|cancell?ed)\W+by\W+(the\W+)?user\b/i;
14
+ /**
15
+ * The SDK calls the Wallet Standard features directly, so a wallet's own error
16
+ * arrives here unwrapped. Wallets report a rejection with the EIP-1193 code
17
+ * 4001 or only with a message. An `AbortError` is not a rejection: nothing
18
+ * says the user caused it. The SDK's own errors keep their code.
19
+ */
20
+ const isUserRejection = (e) => !(e instanceof _lifi_sdk.BaseError) && (e.code === 4001 || typeof e.message === "string" && userRejectionMessage.test(e.message));
13
21
  const handleSpecificErrors = (e) => {
14
22
  if (e.name === "WalletSignTransactionError") return new _lifi_sdk.TransactionError(_lifi_sdk.LiFiErrorCode.SignatureRejected, e.message, e);
15
23
  if (e.name === "SendTransactionError") return new _lifi_sdk.TransactionError(_lifi_sdk.LiFiErrorCode.TransactionFailed, e.message, e);
16
24
  if (e.name === "TransactionExpiredBlockheightExceededError") return new _lifi_sdk.TransactionError(_lifi_sdk.LiFiErrorCode.TransactionExpired, e.message, e);
25
+ if (isUserRejection(e)) return new _lifi_sdk.TransactionError(_lifi_sdk.LiFiErrorCode.SignatureRejected, e.message, e);
17
26
  if (e.message?.includes("simulate")) return new _lifi_sdk.TransactionError(_lifi_sdk.LiFiErrorCode.TransactionSimulationFailed, e.message, e);
18
27
  if (e instanceof _lifi_sdk.BaseError) return e;
19
28
  return new _lifi_sdk.UnknownError(e.message || _lifi_sdk.ErrorMessage.UnknownError, e);
@@ -1 +1 @@
1
- {"version":3,"file":"parseSolanaErrors.js","names":["SDKError","TransactionError","LiFiErrorCode","BaseError","UnknownError","ErrorMessage"],"sources":["../../../src/errors/parseSolanaErrors.ts"],"sourcesContent":["import {\n BaseError,\n ErrorMessage,\n type ExecutionAction,\n LiFiErrorCode,\n type LiFiStep,\n SDKError,\n TransactionError,\n UnknownError,\n} from '@lifi/sdk'\n\nexport const parseSolanaErrors = async (\n e: Error,\n step?: LiFiStep,\n action?: ExecutionAction\n): Promise<SDKError> => {\n if (e instanceof SDKError) {\n e.step = e.step ?? step\n e.action = e.action ?? action\n return e\n }\n\n const baseError = handleSpecificErrors(e)\n\n return new SDKError(baseError, step, action)\n}\n\nconst handleSpecificErrors = (e: any) => {\n if (e.name === 'WalletSignTransactionError') {\n return new TransactionError(LiFiErrorCode.SignatureRejected, e.message, e)\n }\n\n if (e.name === 'SendTransactionError') {\n return new TransactionError(LiFiErrorCode.TransactionFailed, e.message, e)\n }\n\n if (e.name === 'TransactionExpiredBlockheightExceededError') {\n return new TransactionError(LiFiErrorCode.TransactionExpired, e.message, e)\n }\n\n if (e.message?.includes('simulate')) {\n return new TransactionError(\n LiFiErrorCode.TransactionSimulationFailed,\n e.message,\n e\n )\n }\n\n if (e instanceof BaseError) {\n return e\n }\n\n return new UnknownError(e.message || ErrorMessage.UnknownError, e)\n}\n"],"mappings":";;;AAWA,MAAa,oBAAoB,OAC/B,GACA,MACA,WACsB;CACtB,IAAI,aAAaA,UAAAA,UAAU;EACzB,EAAE,OAAO,EAAE,QAAQ;EACnB,EAAE,SAAS,EAAE,UAAU;EACvB,OAAO;CACT;CAEA,MAAM,YAAY,qBAAqB,CAAC;CAExC,OAAO,IAAIA,UAAAA,SAAS,WAAW,MAAM,MAAM;AAC7C;AAEA,MAAM,wBAAwB,MAAW;CACvC,IAAI,EAAE,SAAS,8BACb,OAAO,IAAIC,UAAAA,iBAAiBC,UAAAA,cAAc,mBAAmB,EAAE,SAAS,CAAC;CAG3E,IAAI,EAAE,SAAS,wBACb,OAAO,IAAID,UAAAA,iBAAiBC,UAAAA,cAAc,mBAAmB,EAAE,SAAS,CAAC;CAG3E,IAAI,EAAE,SAAS,8CACb,OAAO,IAAID,UAAAA,iBAAiBC,UAAAA,cAAc,oBAAoB,EAAE,SAAS,CAAC;CAG5E,IAAI,EAAE,SAAS,SAAS,UAAU,GAChC,OAAO,IAAID,UAAAA,iBACTC,UAAAA,cAAc,6BACd,EAAE,SACF,CACF;CAGF,IAAI,aAAaC,UAAAA,WACf,OAAO;CAGT,OAAO,IAAIC,UAAAA,aAAa,EAAE,WAAWC,UAAAA,aAAa,cAAc,CAAC;AACnE"}
1
+ {"version":3,"file":"parseSolanaErrors.js","names":["SDKError","BaseError","TransactionError","LiFiErrorCode","UnknownError","ErrorMessage"],"sources":["../../../src/errors/parseSolanaErrors.ts"],"sourcesContent":["import {\n BaseError,\n ErrorMessage,\n type ExecutionAction,\n LiFiErrorCode,\n type LiFiStep,\n SDKError,\n TransactionError,\n UnknownError,\n} from '@lifi/sdk'\n\nexport const parseSolanaErrors = async (\n e: Error,\n step?: LiFiStep,\n action?: ExecutionAction\n): Promise<SDKError> => {\n if (e instanceof SDKError) {\n e.step = e.step ?? step\n e.action = e.action ?? action\n return e\n }\n\n const baseError = handleSpecificErrors(e)\n\n return new SDKError(baseError, step, action)\n}\n\n// Same pattern as bigmi's `isUserRejection`. It is anchored on \"user\", so a\n// refusal by a node or a host does not count as a rejection.\nconst userRejectionMessage =\n /(^|\\W)user\\W+(has\\W+)?(rejected|denied|cancell?ed)|\\b(rejected|denied|cancell?ed)\\W+by\\W+(the\\W+)?user\\b/i\n\n/**\n * The SDK calls the Wallet Standard features directly, so a wallet's own error\n * arrives here unwrapped. Wallets report a rejection with the EIP-1193 code\n * 4001 or only with a message. An `AbortError` is not a rejection: nothing\n * says the user caused it. The SDK's own errors keep their code.\n */\nconst isUserRejection = (e: any): boolean =>\n !(e instanceof BaseError) &&\n (e.code === 4001 ||\n (typeof e.message === 'string' && userRejectionMessage.test(e.message)))\n\nconst handleSpecificErrors = (e: any) => {\n if (e.name === 'WalletSignTransactionError') {\n return new TransactionError(LiFiErrorCode.SignatureRejected, e.message, e)\n }\n\n if (e.name === 'SendTransactionError') {\n return new TransactionError(LiFiErrorCode.TransactionFailed, e.message, e)\n }\n\n if (e.name === 'TransactionExpiredBlockheightExceededError') {\n return new TransactionError(LiFiErrorCode.TransactionExpired, e.message, e)\n }\n\n // After the name checks: a known error keeps its code, even when its\n // message quotes program logs that look like a rejection.\n if (isUserRejection(e)) {\n return new TransactionError(LiFiErrorCode.SignatureRejected, e.message, e)\n }\n\n if (e.message?.includes('simulate')) {\n return new TransactionError(\n LiFiErrorCode.TransactionSimulationFailed,\n e.message,\n e\n )\n }\n\n if (e instanceof BaseError) {\n return e\n }\n\n return new UnknownError(e.message || ErrorMessage.UnknownError, e)\n}\n"],"mappings":";;;AAWA,MAAa,oBAAoB,OAC/B,GACA,MACA,WACsB;CACtB,IAAI,aAAaA,UAAAA,UAAU;EACzB,EAAE,OAAO,EAAE,QAAQ;EACnB,EAAE,SAAS,EAAE,UAAU;EACvB,OAAO;CACT;CAEA,MAAM,YAAY,qBAAqB,CAAC;CAExC,OAAO,IAAIA,UAAAA,SAAS,WAAW,MAAM,MAAM;AAC7C;AAIA,MAAM,uBACJ;;;;;;;AAQF,MAAM,mBAAmB,MACvB,EAAE,aAAaC,UAAAA,eACd,EAAE,SAAS,QACT,OAAO,EAAE,YAAY,YAAY,qBAAqB,KAAK,EAAE,OAAO;AAEzE,MAAM,wBAAwB,MAAW;CACvC,IAAI,EAAE,SAAS,8BACb,OAAO,IAAIC,UAAAA,iBAAiBC,UAAAA,cAAc,mBAAmB,EAAE,SAAS,CAAC;CAG3E,IAAI,EAAE,SAAS,wBACb,OAAO,IAAID,UAAAA,iBAAiBC,UAAAA,cAAc,mBAAmB,EAAE,SAAS,CAAC;CAG3E,IAAI,EAAE,SAAS,8CACb,OAAO,IAAID,UAAAA,iBAAiBC,UAAAA,cAAc,oBAAoB,EAAE,SAAS,CAAC;CAK5E,IAAI,gBAAgB,CAAC,GACnB,OAAO,IAAID,UAAAA,iBAAiBC,UAAAA,cAAc,mBAAmB,EAAE,SAAS,CAAC;CAG3E,IAAI,EAAE,SAAS,SAAS,UAAU,GAChC,OAAO,IAAID,UAAAA,iBACTC,UAAAA,cAAc,6BACd,EAAE,SACF,CACF;CAGF,IAAI,aAAaF,UAAAA,WACf,OAAO;CAGT,OAAO,IAAIG,UAAAA,aAAa,EAAE,WAAWC,UAAAA,aAAa,cAAc,CAAC;AACnE"}
@@ -35,6 +35,14 @@ export declare const probeJitoRpc: (rpcUrl: string) => Promise<JitoProbeResult>;
35
35
  * @returns - Solana RPCs
36
36
  */
37
37
  export declare const getSolanaRpcs: (client: SDKClient) => Promise<SolanaRpcType[]>;
38
+ /**
39
+ * Clients for the write RPCs (`rpcUrls[ChainId.SOL].write`). They only
40
+ * send transactions; the one read they get is the Jito probe in
41
+ * `getJitoCapableRpcs`.
42
+ * @param rpcUrls - The write RPC URLs.
43
+ * @returns - Solana RPCs to send transactions through.
44
+ */
45
+ export declare const getSolanaWriteRpcs: (rpcUrls: string[]) => SolanaRpcType[];
38
46
  /** `unreachable` counts endpoints whose probe failed without naming the
39
47
  * method unknown. Empty `rpcs` with a non-zero count is usually an outage, but
40
48
  * not always: a bare 401/403 lands here too, and that can be a plan gate the
@@ -44,5 +52,17 @@ export declare const getJitoRpcs: (client: SDKClient) => Promise<{
44
52
  rpcs: JitoRpcType[];
45
53
  unreachable: number;
46
54
  }>;
55
+ /**
56
+ * The given URLs that pass the Jito probe - the bundle or write RPCs of
57
+ * `rpcUrls[ChainId.SOL]`. They share the probe cache with the read RPCs.
58
+ * `unreachable` counts the URLs whose probe failed without an answer, as in
59
+ * `getJitoRpcs`.
60
+ * @param rpcUrls - The URLs to probe.
61
+ * @returns - Jito RPCs to submit bundles through, and the unreachable count.
62
+ */
63
+ export declare const getJitoCapableRpcs: (rpcUrls: string[]) => Promise<{
64
+ rpcs: JitoRpcType[];
65
+ unreachable: number;
66
+ }>;
47
67
  //#endregion
48
68
  //# sourceMappingURL=registry.d.ts.map
@@ -3,8 +3,8 @@ const require_rpc_jito_createJitoRpc = require("./jito/createJitoRpc.js");
3
3
  let _lifi_sdk = require("@lifi/sdk");
4
4
  let _solana_kit = require("@solana/kit");
5
5
  //#region src/rpc/registry.ts
6
- const solanaRpcs = new _lifi_sdk.LruMap(12);
7
- const jitoRpcs = new _lifi_sdk.LruMap(12);
6
+ const solanaRpcs = new _lifi_sdk.LruMap(64);
7
+ const jitoRpcs = new _lifi_sdk.LruMap(64);
8
8
  /**
9
9
  * A well-formed but non-existent Jito bundle id used solely to probe RPC
10
10
  * capability. It forces `getBundleStatuses` to actually execute, so we can tell
@@ -32,7 +32,7 @@ const JITO_PROBE_GATEWAY_RETRY_MS = 9e5;
32
32
  * set never shrinks, and every bundle submission re-probes every non-Jito
33
33
  * endpoint at up to `PROBE_TIMEOUT_MS` each, on the latency path before
34
34
  * submission can start. */
35
- const jitoProbes = new _lifi_sdk.LruMap(12);
35
+ const jitoProbes = new _lifi_sdk.LruMap(64);
36
36
  /** One rule for every outcome: a record is fresh until its own window closes.
37
37
  * `Infinity` covers the answers that cannot change. */
38
38
  const isProbeFresh = (record) => record !== void 0 && Date.now() - record.at < record.retryMs;
@@ -96,20 +96,26 @@ const probeJitoRpc = async (rpcUrl) => {
96
96
  */
97
97
  const ensureSolanaRpcs = async (client) => {
98
98
  const rpcUrls = await client.getRpcUrlsByChainId(_lifi_sdk.ChainId.SOL);
99
- for (const rpcUrl of rpcUrls) if (!solanaRpcs.has(rpcUrl)) solanaRpcs.set(rpcUrl, (0, _solana_kit.createSolanaRpc)(rpcUrl));
99
+ ensureSolanaRpcsFor(rpcUrls);
100
100
  return rpcUrls;
101
101
  };
102
+ /** Creates and caches a client for each URL that has none yet. */
103
+ const ensureSolanaRpcsFor = (rpcUrls) => {
104
+ for (const rpcUrl of rpcUrls) if (!solanaRpcs.has(rpcUrl)) solanaRpcs.set(rpcUrl, (0, _solana_kit.createSolanaRpc)(rpcUrl));
105
+ };
106
+ const cachedSolanaRpcs = (rpcUrls) => rpcUrls.map((rpcUrl) => solanaRpcs.get(rpcUrl)).filter((rpc) => Boolean(rpc));
102
107
  /**
103
- * Initializes and caches Jito RPCs for every configured Solana RPC URL.
108
+ * Probes each URL for Jito support and caches a client for every supported
109
+ * one. The configured RPCs and the write RPCs share this cache.
104
110
  *
105
111
  * Every probe outcome is cached, so a non-Jito endpoint is probed once rather
106
112
  * than once per bundle submission. Each record carries its own retry window:
107
113
  * see `JITO_PROBE_RETRY_MS` and `JITO_PROBE_GATEWAY_RETRY_MS` for the two that
108
114
  * expire.
109
- * @param client - The SDK client used to fetch RPC URLs.
115
+ * @param rpcUrls - The URLs to probe.
116
+ * @returns - How many of the URLs are currently unreachable.
110
117
  */
111
- const ensureJitoRpcs = async (client) => {
112
- const rpcUrls = await client.getRpcUrlsByChainId(_lifi_sdk.ChainId.SOL);
118
+ const ensureJitoRpcsFor = async (rpcUrls) => {
113
119
  const unprobed = rpcUrls.filter((rpcUrl) => !isProbeFresh(jitoProbes.get(rpcUrl)));
114
120
  (await Promise.all(unprobed.map((rpcUrl) => (0, _lifi_sdk.withDedupe)(() => probeJitoRpc(rpcUrl), { id: `jito-probe:${rpcUrl}` })))).forEach(({ outcome, retryMs }, index) => {
115
121
  const rpcUrl = unprobed[index];
@@ -121,17 +127,37 @@ const ensureJitoRpcs = async (client) => {
121
127
  if (outcome === "supported") jitoRpcs.set(rpcUrl, require_rpc_jito_createJitoRpc.createJitoRpc(rpcUrl));
122
128
  else jitoRpcs.delete(rpcUrl);
123
129
  });
130
+ return rpcUrls.filter((rpcUrl) => jitoProbes.get(rpcUrl)?.outcome === "unreachable").length;
131
+ };
132
+ /**
133
+ * Initializes and caches Jito RPCs for every configured Solana RPC URL.
134
+ * @param client - The SDK client used to fetch RPC URLs.
135
+ */
136
+ const ensureJitoRpcs = async (client) => {
137
+ const rpcUrls = await client.getRpcUrlsByChainId(_lifi_sdk.ChainId.SOL);
124
138
  return {
125
139
  rpcUrls,
126
- unreachable: rpcUrls.filter((rpcUrl) => jitoProbes.get(rpcUrl)?.outcome === "unreachable").length
140
+ unreachable: await ensureJitoRpcsFor(rpcUrls)
127
141
  };
128
142
  };
143
+ const cachedJitoRpcs = (rpcUrls) => rpcUrls.map((rpcUrl) => jitoRpcs.get(rpcUrl)).filter((rpc) => Boolean(rpc));
129
144
  /**
130
145
  * Wrapper around getting the Solana RPCs
131
146
  * @returns - Solana RPCs
132
147
  */
133
148
  const getSolanaRpcs = async (client) => {
134
- return (await ensureSolanaRpcs(client)).map((rpcUrl) => solanaRpcs.get(rpcUrl)).filter((rpc) => Boolean(rpc));
149
+ return cachedSolanaRpcs(await ensureSolanaRpcs(client));
150
+ };
151
+ /**
152
+ * Clients for the write RPCs (`rpcUrls[ChainId.SOL].write`). They only
153
+ * send transactions; the one read they get is the Jito probe in
154
+ * `getJitoCapableRpcs`.
155
+ * @param rpcUrls - The write RPC URLs.
156
+ * @returns - Solana RPCs to send transactions through.
157
+ */
158
+ const getSolanaWriteRpcs = (rpcUrls) => {
159
+ ensureSolanaRpcsFor(rpcUrls);
160
+ return cachedSolanaRpcs(rpcUrls);
135
161
  };
136
162
  /** `unreachable` counts endpoints whose probe failed without naming the
137
163
  * method unknown. Empty `rpcs` with a non-zero count is usually an outage, but
@@ -141,15 +167,32 @@ const getSolanaRpcs = async (client) => {
141
167
  const getJitoRpcs = async (client) => {
142
168
  const { rpcUrls, unreachable } = await ensureJitoRpcs(client);
143
169
  return {
144
- rpcs: rpcUrls.map((rpcUrl) => jitoRpcs.get(rpcUrl)).filter((rpc) => Boolean(rpc)),
170
+ rpcs: cachedJitoRpcs(rpcUrls),
171
+ unreachable
172
+ };
173
+ };
174
+ /**
175
+ * The given URLs that pass the Jito probe - the bundle or write RPCs of
176
+ * `rpcUrls[ChainId.SOL]`. They share the probe cache with the read RPCs.
177
+ * `unreachable` counts the URLs whose probe failed without an answer, as in
178
+ * `getJitoRpcs`.
179
+ * @param rpcUrls - The URLs to probe.
180
+ * @returns - Jito RPCs to submit bundles through, and the unreachable count.
181
+ */
182
+ const getJitoCapableRpcs = async (rpcUrls) => {
183
+ const unreachable = await ensureJitoRpcsFor(rpcUrls);
184
+ return {
185
+ rpcs: cachedJitoRpcs(rpcUrls),
145
186
  unreachable
146
187
  };
147
188
  };
148
189
  //#endregion
149
190
  exports.JITO_PROBE_GATEWAY_RETRY_MS = JITO_PROBE_GATEWAY_RETRY_MS;
150
191
  exports.JITO_PROBE_RETRY_MS = JITO_PROBE_RETRY_MS;
192
+ exports.getJitoCapableRpcs = getJitoCapableRpcs;
151
193
  exports.getJitoRpcs = getJitoRpcs;
152
194
  exports.getSolanaRpcs = getSolanaRpcs;
195
+ exports.getSolanaWriteRpcs = getSolanaWriteRpcs;
153
196
  exports.probeJitoRpc = probeJitoRpc;
154
197
 
155
198
  //# sourceMappingURL=registry.js.map