@lifi/sdk-provider-solana 4.2.3 → 4.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (41) hide show
  1. package/CHANGELOG.md +11 -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/confirmSignature.d.ts +2 -0
  9. package/dist/cjs/confirmation/confirmSignature.js +2 -0
  10. package/dist/cjs/confirmation/confirmSignature.js.map +1 -1
  11. package/dist/cjs/rpc/registry.d.ts +20 -0
  12. package/dist/cjs/rpc/registry.js +54 -11
  13. package/dist/cjs/rpc/registry.js.map +1 -1
  14. package/dist/cjs/version.d.ts +1 -1
  15. package/dist/cjs/version.js +1 -1
  16. package/dist/cjs/version.js.map +1 -1
  17. package/dist/esm/actions/sendAndConfirmBundle.d.ts +5 -0
  18. package/dist/esm/actions/sendAndConfirmBundle.d.ts.map +1 -1
  19. package/dist/esm/actions/sendAndConfirmBundle.js +40 -5
  20. package/dist/esm/actions/sendAndConfirmBundle.js.map +1 -1
  21. package/dist/esm/actions/sendAndConfirmTransaction.d.ts +3 -0
  22. package/dist/esm/actions/sendAndConfirmTransaction.d.ts.map +1 -1
  23. package/dist/esm/actions/sendAndConfirmTransaction.js +58 -12
  24. package/dist/esm/actions/sendAndConfirmTransaction.js.map +1 -1
  25. package/dist/esm/confirmation/confirmSignature.d.ts +2 -0
  26. package/dist/esm/confirmation/confirmSignature.d.ts.map +1 -1
  27. package/dist/esm/confirmation/confirmSignature.js +2 -1
  28. package/dist/esm/confirmation/confirmSignature.js.map +1 -1
  29. package/dist/esm/rpc/registry.d.ts +20 -0
  30. package/dist/esm/rpc/registry.d.ts.map +1 -1
  31. package/dist/esm/rpc/registry.js +53 -12
  32. package/dist/esm/rpc/registry.js.map +1 -1
  33. package/dist/esm/version.d.ts +1 -1
  34. package/dist/esm/version.js +1 -1
  35. package/dist/esm/version.js.map +1 -1
  36. package/package.json +2 -2
  37. package/src/actions/sendAndConfirmBundle.ts +85 -5
  38. package/src/actions/sendAndConfirmTransaction.ts +108 -18
  39. package/src/confirmation/confirmSignature.ts +2 -1
  40. package/src/rpc/registry.ts +66 -21
  41. package/src/version.ts +1 -1
@@ -1,9 +1,9 @@
1
- import { getJitoRpcs } from "../rpc/registry.js";
1
+ import { getJitoCapableRpcs, getJitoRpcs } from "../rpc/registry.js";
2
2
  import { BRANCH_TIMEOUT_MS } from "../confirmation/createConfirmationDeadline.js";
3
3
  import { confirmBundle } from "../confirmation/confirmBundle.js";
4
4
  import { raceRpcs } from "../confirmation/raceRpcs.js";
5
5
  import { getTransactionLifetime } from "../utils/getTransactionLifetime.js";
6
- import { LiFiErrorCode, RPCError } from "@lifi/sdk";
6
+ import { ChainId, LiFiErrorCode, RPCError } from "@lifi/sdk";
7
7
  import { getBase64EncodedWireTransaction } from "@solana/kit";
8
8
  //#region src/actions/sendAndConfirmBundle.ts
9
9
  /**
@@ -17,10 +17,38 @@ import { getBase64EncodedWireTransaction } from "@solana/kit";
17
17
  * `sendBundle` is handed to `confirmBundle` rather than awaited here, so the
18
18
  * deadline starts on the same clock as `BRANCH_TIMEOUT_MS` instead of after
19
19
  * the submission returns.
20
+ *
21
+ * When the client has Solana bundle or write RPCs (`rpcUrls[ChainId.SOL]`),
22
+ * the bundle is submitted once through those that pass the Jito probe - the
23
+ * bundle list first, else the write list - and the read Jito RPCs only poll.
24
+ * With either list set, bundles never go to the read RPCs.
20
25
  */
21
26
  async function sendAndConfirmBundle(client, signedTransactions, options) {
22
- const { rpcs: jitoRpcs, unreachable } = await getJitoRpcs(client);
23
- if (jitoRpcs.length === 0) throw new RPCError(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.");
27
+ const [bundleUrls = [], writeUrls = []] = await Promise.all([client.getBundleRpcUrlsByChainId?.(ChainId.SOL), client.getWriteRpcUrlsByChainId?.(ChainId.SOL)]);
28
+ const noSubmitRpcs = {
29
+ rpcs: [],
30
+ unreachable: 0
31
+ };
32
+ const findSubmitRpcs = async () => {
33
+ const bundle = bundleUrls.length ? await getJitoCapableRpcs(bundleUrls) : noSubmitRpcs;
34
+ if (bundle.rpcs.length || !writeUrls.length) return bundle;
35
+ const write = await getJitoCapableRpcs(writeUrls);
36
+ return {
37
+ rpcs: write.rpcs,
38
+ unreachable: bundle.unreachable + write.unreachable
39
+ };
40
+ };
41
+ const [{ rpcs: jitoRpcs, unreachable }, { rpcs: submitRpcs, unreachable: submitUnreachable }] = await Promise.all([getJitoRpcs(client), findSubmitRpcs()]);
42
+ if ((bundleUrls.length || writeUrls.length) && !submitRpcs.length) {
43
+ const lists = [bundleUrls.length && "`rpcUrls[ChainId.SOL].bundle`", writeUrls.length && "`rpcUrls[ChainId.SOL].write`"].filter(Boolean).join(" or ");
44
+ throw new RPCError(LiFiErrorCode.RpcUnavailable, [
45
+ `Jito bundle required, but no URL in ${lists} passed the Jito capability probe.`,
46
+ 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`.",
47
+ "Bundles never go to the read RPCs while `bundle` or `write` is set.",
48
+ 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`."
49
+ ].filter(Boolean).join(" "));
50
+ }
51
+ if (jitoRpcs.length === 0) throw new RPCError(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.");
24
52
  let broadcastReported = false;
25
53
  const reportBroadcast = () => {
26
54
  if (broadcastReported) return;
@@ -31,11 +59,18 @@ async function sendAndConfirmBundle(client, signedTransactions, options) {
31
59
  };
32
60
  const serializedTransactions = signedTransactions.map((transaction) => getBase64EncodedWireTransaction(transaction));
33
61
  const lifetimes = await Promise.all(signedTransactions.map((transaction) => getTransactionLifetime(transaction)));
62
+ let submission;
63
+ const submitOnce = (signal) => {
64
+ submission ??= Promise.any(submitRpcs.map((rpc) => rpc.sendBundle(serializedTransactions).send({ abortSignal: signal }))).catch((error) => {
65
+ throw error instanceof AggregateError ? error.errors[0] : error;
66
+ });
67
+ return submission;
68
+ };
34
69
  return raceRpcs(jitoRpcs, (rpc, signal) => confirmBundle({
35
70
  rpc,
36
71
  signal,
37
72
  lifetimes,
38
- send: () => rpc.sendBundle(serializedTransactions).send({ abortSignal: signal }),
73
+ send: () => submitRpcs.length ? submitOnce(signal) : rpc.sendBundle(serializedTransactions).send({ abortSignal: signal }),
39
74
  onBroadcast: reportBroadcast
40
75
  }), { timeoutMs: BRANCH_TIMEOUT_MS });
41
76
  }
@@ -1 +1 @@
1
- {"version":3,"file":"sendAndConfirmBundle.js","names":[],"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,MAAM,YAAY,MAAM;CAYhE,IAAI,SAAS,WAAW,GACtB,MAAM,IAAI,SACR,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,gBACrD,gCAAgC,WAAW,CAC7C;CAEA,MAAM,YAAY,MAAM,QAAQ,IAC9B,mBAAmB,KAAK,gBAAgB,uBAAuB,WAAW,CAAC,CAC7E;CAEA,OAAO,SACL,WACC,KAAK,WACJ,cAAc;EACZ;EACA;EACA;EACA,YACE,IAAI,WAAW,sBAAsB,CAAC,CAAC,KAAK,EAAE,aAAa,OAAO,CAAC;EACrE,aAAa;CACf,CAAC,GACH,EAAE,WAAW,kBAAkB,CACjC;AACF"}
1
+ {"version":3,"file":"sendAndConfirmBundle.js","names":[],"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,4BAA4B,QAAQ,GAAG,GAC9C,OAAO,2BAA2B,QAAQ,GAAG,CAC/C,CAAC;CACD,MAAM,eAAe;EAAE,MAAM,CAAC;EAAoB,aAAa;CAAE;CACjE,MAAM,iBAAiB,YAA0C;EAC/D,MAAM,SAAS,WAAW,SACtB,MAAM,mBAAmB,UAAU,IACnC;EACJ,IAAI,OAAO,KAAK,UAAU,CAAC,UAAU,QACnC,OAAO;EAET,MAAM,QAAQ,MAAM,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,CAAC,YAAY,MAAM,GAAG,eAAe,CAAC,CAAC;CAE7D,KAAK,WAAW,UAAU,UAAU,WAAW,CAAC,WAAW,QAAQ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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
@@ -1 +1 @@
1
- {"version":3,"file":"sendAndConfirmTransaction.d.ts","names":[],"sources":["../../../src/actions/sendAndConfirmTransaction.ts"],"mappings":";;;;;;;;;;;;;;wBAwBsB,0BACpB,QAAQ,WACR,mBAAmB,aACnB;;EAEE;IAED,QAAQ,WAAW"}
1
+ {"version":3,"file":"sendAndConfirmTransaction.d.ts","names":[],"sources":["../../../src/actions/sendAndConfirmTransaction.ts"],"mappings":";;;;;;;;;;;;;;;;;wBA8BsB,0BACpB,QAAQ,WACR,mBAAmB,aACnB;;EAEE;IAED,QAAQ,WAAW"}
@@ -1,21 +1,25 @@
1
- import { getSolanaRpcs } from "../rpc/registry.js";
1
+ import { getSolanaRpcs, getSolanaWriteRpcs } from "../rpc/registry.js";
2
2
  import { BRANCH_TIMEOUT_MS } from "../confirmation/createConfirmationDeadline.js";
3
3
  import { raceRpcs } from "../confirmation/raceRpcs.js";
4
4
  import { getTransactionLifetime } from "../utils/getTransactionLifetime.js";
5
- import { confirmSignature } from "../confirmation/confirmSignature.js";
5
+ import { RESEND_INTERVAL_MS, confirmSignature } from "../confirmation/confirmSignature.js";
6
+ import { ChainId } from "@lifi/sdk";
6
7
  import { getBase64EncodedWireTransaction, getSignatureFromTransaction } from "@solana/kit";
7
8
  //#region src/actions/sendAndConfirmTransaction.ts
8
9
  /**
9
10
  * Sends a Solana transaction to every configured RPC and returns as soon as
10
11
  * one of them confirms it.
11
12
  *
13
+ * When the client has Solana write RPCs (`rpcUrls[ChainId.SOL].write`), the
14
+ * transaction is sent only through those, and the read RPCs only confirm it.
15
+ *
12
16
  * The polling horizon comes from the signed transaction's own blockhash and a
13
17
  * wall-clock ceiling. It deliberately never comes from `getBlockHeight`: at
14
18
  * least one endpoint in the default LI.FI set answers that call with the slot
15
19
  * number.
16
20
  */
17
21
  async function sendAndConfirmTransaction(client, signedTransaction, options) {
18
- const solanaRpcs = await getSolanaRpcs(client);
22
+ const [solanaRpcs, writeRpcUrls = []] = await Promise.all([getSolanaRpcs(client), client.getWriteRpcUrlsByChainId?.(ChainId.SOL)]);
19
23
  let broadcastReported = false;
20
24
  let sendAccepted = false;
21
25
  const reportBroadcast = () => {
@@ -35,17 +39,59 @@ async function sendAndConfirmTransaction(client, signedTransaction, options) {
35
39
  preflightCommitment: "confirmed",
36
40
  encoding: "base64"
37
41
  };
38
- const resend = async (rpc, signal) => {
42
+ const send = async (rpc, signal) => {
39
43
  await rpc.sendTransaction(signedTxSerialized, rawTransactionOptions).send({ abortSignal: signal });
40
44
  };
41
- const result = await raceRpcs(solanaRpcs, (rpc, signal) => confirmSignature({
42
- rpc,
43
- signal,
44
- signature: txSignature,
45
- lifetimes: [lifetime],
46
- resend,
47
- onBroadcast: reportBroadcast
48
- }), { timeoutMs: BRANCH_TIMEOUT_MS });
45
+ const writeRpcs = writeRpcUrls.length ? getSolanaWriteRpcs(writeRpcUrls) : void 0;
46
+ const writes = new AbortController();
47
+ let lastWrite;
48
+ const openSends = /* @__PURE__ */ new Set();
49
+ const sendToWriteRpc = async (rpc) => {
50
+ openSends.add(rpc);
51
+ try {
52
+ await send(rpc, writes.signal);
53
+ } finally {
54
+ openSends.delete(rpc);
55
+ }
56
+ };
57
+ const sendToWriteRpcs = (rpcs) => {
58
+ const now = Date.now();
59
+ if (lastWrite && now - lastWrite.at < 1e3) return lastWrite.sent;
60
+ const ready = rpcs.filter((rpc) => !openSends.has(rpc));
61
+ const sent = Promise.any(ready.map(sendToWriteRpc)).then(() => void 0);
62
+ sent.then(() => {
63
+ if (!writes.signal.aborted) reportBroadcast();
64
+ }, () => {});
65
+ lastWrite = {
66
+ at: now,
67
+ sent
68
+ };
69
+ return sent;
70
+ };
71
+ const waitForWrite = (sent) => new Promise((resolve, reject) => {
72
+ const timer = setTimeout(() => reject(/* @__PURE__ */ new Error("No write RPC accepted the transaction in time.")), RESEND_INTERVAL_MS);
73
+ sent.then(() => {
74
+ clearTimeout(timer);
75
+ resolve();
76
+ }, (error) => {
77
+ clearTimeout(timer);
78
+ reject(error);
79
+ });
80
+ });
81
+ const resend = writeRpcs ? () => waitForWrite(sendToWriteRpcs(writeRpcs)) : send;
82
+ let result;
83
+ try {
84
+ result = await raceRpcs(solanaRpcs, (rpc, signal) => confirmSignature({
85
+ rpc,
86
+ signal,
87
+ signature: txSignature,
88
+ lifetimes: [lifetime],
89
+ resend,
90
+ onBroadcast: reportBroadcast
91
+ }), { timeoutMs: BRANCH_TIMEOUT_MS });
92
+ } finally {
93
+ writes.abort();
94
+ }
49
95
  if (result.kind === "not-confirmed" && !sendAccepted) return {
50
96
  kind: "rpc-unavailable",
51
97
  errors: result.errors
@@ -1 +1 @@
1
- {"version":3,"file":"sendAndConfirmTransaction.js","names":[],"sources":["../../../src/actions/sendAndConfirmTransaction.ts"],"sourcesContent":["import type { SDKClient } from '@lifi/sdk'\nimport {\n type Commitment,\n getBase64EncodedWireTransaction,\n getSignatureFromTransaction,\n type Transaction,\n} from '@solana/kit'\nimport { confirmSignature } from '../confirmation/confirmSignature.js'\nimport { BRANCH_TIMEOUT_MS } from '../confirmation/createConfirmationDeadline.js'\nimport { type RaceResult, raceRpcs } from '../confirmation/raceRpcs.js'\nimport type { SignatureStatus } from '../confirmation/types.js'\nimport { getSolanaRpcs } from '../rpc/registry.js'\nimport type { SolanaRpcType } from '../rpc/types.js'\nimport { getTransactionLifetime } from '../utils/getTransactionLifetime.js'\n\n/**\n * Sends a Solana transaction to every configured RPC and returns as soon as\n * one of them confirms it.\n *\n * The polling horizon comes from the signed transaction's own blockhash and a\n * wall-clock ceiling. It deliberately never comes from `getBlockHeight`: at\n * least one endpoint in the default LI.FI set answers that call with the slot\n * number.\n */\nexport async function sendAndConfirmTransaction(\n client: SDKClient,\n signedTransaction: Transaction,\n options?: {\n /** Runs once, when the first RPC accepts a send. */\n onBroadcast?: () => void\n }\n): Promise<RaceResult<SignatureStatus>> {\n const solanaRpcs = await getSolanaRpcs(client)\n\n let broadcastReported = false\n // Distinct from `broadcastReported`, which records whether the integrator\n // callback has *succeeded*. This one answers \"did any RPC accept the send?\",\n // and only that question may steer the verdict below. Set before the callback\n // runs, so a hook that throws on every resend cannot make a real expiry look\n // like an outage.\n let sendAccepted = false\n const reportBroadcast = (): void => {\n sendAccepted = true\n if (broadcastReported) {\n return\n }\n try {\n options?.onBroadcast?.()\n // Latched only after the callback returned. A callback that threw wrote\n // nothing, so the next successful send must be allowed to try again -\n // latching first made one failed `txLink` write permanent.\n broadcastReported = true\n } catch (_) {\n // This runs integrator code: the callback reaches `updateRouteHook` via\n // `StatusManager.updateAction`. Its failure must never reject the branch\n // that called it - the send has already been accepted by the network at\n // this point, so a throw here would report a landed transaction as an\n // RPC outage. Swallowed rather than surfaced because there is no verdict\n // it could honestly change.\n }\n }\n\n const signedTxSerialized = getBase64EncodedWireTransaction(signedTransaction)\n const txSignature = getSignatureFromTransaction(signedTransaction)\n\n const lifetime = await getTransactionLifetime(signedTransaction)\n\n const rawTransactionOptions = {\n // We can skip preflight check after the first transaction has been sent\n // https://solana.com/docs/advanced/retry#the-cost-of-skipping-preflight\n skipPreflight: true,\n // Setting max retries to 0 as we are handling retries manually\n maxRetries: BigInt(0),\n // https://solana.com/docs/advanced/confirmation#use-an-appropriate-preflight-commitment-level\n preflightCommitment: 'confirmed' as Commitment,\n encoding: 'base64' as const,\n }\n\n const resend = async (\n rpc: SolanaRpcType,\n signal: AbortSignal\n ): Promise<void> => {\n await rpc\n .sendTransaction(signedTxSerialized, rawTransactionOptions)\n .send({ abortSignal: signal })\n }\n\n const result = await raceRpcs(\n solanaRpcs,\n (rpc, signal) =>\n confirmSignature({\n rpc,\n signal,\n signature: txSignature,\n lifetimes: [lifetime],\n resend,\n onBroadcast: reportBroadcast,\n }),\n { timeoutMs: BRANCH_TIMEOUT_MS }\n )\n\n // Only this scope knows whether ANY branch accepted the send. A branch that\n // polls to its deadline reports `not-confirmed` regardless - correct per\n // branch, but across the whole race it would claim a transaction expired\n // when nothing ever submitted it. That is an outage, not an expiry.\n //\n // Reads `sendAccepted`, never `broadcastReported`: the latter is false\n // whenever the integrator's callback threw, which says nothing about whether\n // the network took the transaction.\n if (result.kind === 'not-confirmed' && !sendAccepted) {\n return { kind: 'rpc-unavailable', errors: result.errors }\n }\n\n return result\n}\n"],"mappings":";;;;;;;;;;;;;;;;AAwBA,eAAsB,0BACpB,QACA,mBACA,SAIsC;CACtC,MAAM,aAAa,MAAM,cAAc,MAAM;CAE7C,IAAI,oBAAoB;CAMxB,IAAI,eAAe;CACnB,MAAM,wBAA8B;EAClC,eAAe;EACf,IAAI,mBACF;EAEF,IAAI;GACF,SAAS,cAAc;GAIvB,oBAAoB;EACtB,SAAS,GAAG,CAOZ;CACF;CAEA,MAAM,qBAAqB,gCAAgC,iBAAiB;CAC5E,MAAM,cAAc,4BAA4B,iBAAiB;CAEjE,MAAM,WAAW,MAAM,uBAAuB,iBAAiB;CAE/D,MAAM,wBAAwB;EAG5B,eAAe;EAEf,YAAY,OAAO,CAAC;EAEpB,qBAAqB;EACrB,UAAU;CACZ;CAEA,MAAM,SAAS,OACb,KACA,WACkB;EAClB,MAAM,IACH,gBAAgB,oBAAoB,qBAAqB,CAAC,CAC1D,KAAK,EAAE,aAAa,OAAO,CAAC;CACjC;CAEA,MAAM,SAAS,MAAM,SACnB,aACC,KAAK,WACJ,iBAAiB;EACf;EACA;EACA,WAAW;EACX,WAAW,CAAC,QAAQ;EACpB;EACA,aAAa;CACf,CAAC,GACH,EAAE,WAAW,kBAAkB,CACjC;CAUA,IAAI,OAAO,SAAS,mBAAmB,CAAC,cACtC,OAAO;EAAE,MAAM;EAAmB,QAAQ,OAAO;CAAO;CAG1D,OAAO;AACT"}
1
+ {"version":3,"file":"sendAndConfirmTransaction.js","names":[],"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,CACxD,cAAc,MAAM,GACpB,OAAO,2BAA2B,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,qBAAqB,gCAAgC,iBAAiB;CAC5E,MAAM,cAAc,4BAA4B,iBAAiB;CAEjE,MAAM,WAAW,MAAM,uBAAuB,iBAAiB;CAE/D,MAAM,wBAAwB;EAG5B,eAAe;EAEf,YAAY,OAAO,CAAC;EAEpB,qBAAqB;EACrB,UAAU;CACZ;CAEA,MAAM,OAAO,OACX,KACA,WACkB;EAClB,MAAM,IACH,gBAAgB,oBAAoB,qBAAqB,CAAC,CAC1D,KAAK,EAAE,aAAa,OAAO,CAAC;CACjC;CAEA,MAAM,YAAY,aAAa,SAC3B,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,GACpE,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,MAAM,SACb,aACC,KAAK,WACJ,iBAAiB;GACf;GACA;GACA,WAAW;GACX,WAAW,CAAC,QAAQ;GACpB;GACA,aAAa;EACf,CAAC,GACH,EAAE,WAAW,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"}
@@ -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
@@ -1 +1 @@
1
- {"version":3,"file":"confirmSignature.d.ts","names":[],"sources":["../../../src/confirmation/confirmSignature.ts"],"mappings":";;;;;;;;;;qBAkBa;;;wBAIS,iBAAiB;EACrC,KAAK;EACL,QAAQ;EACR,WAAW;EACX,WAAW;EACX,SAAS,KAAK,eAAe,QAAQ,gBAAgB;;;;;;EAMrD;IACE,QAAQ,oBAAoB"}
1
+ {"version":3,"file":"confirmSignature.d.ts","names":[],"sources":["../../../src/confirmation/confirmSignature.ts"],"mappings":";;;;;;qBAaa;;;;;;qBAMA;;;wBAIS,iBAAiB;EACrC,KAAK;EACL,QAAQ;EACR,WAAW;EACX,WAAW;EACX,SAAS,KAAK,eAAe,QAAQ,gBAAgB;;;;;;EAMrD;IACE,QAAQ,oBAAoB"}
@@ -3,6 +3,7 @@ import { abortableSleep } from "./abortableSleep.js";
3
3
  import { pollUntilDeadline } from "./pollUntilDeadline.js";
4
4
  import { isConfirmedCommitment } from "./types.js";
5
5
  //#region src/confirmation/confirmSignature.ts
6
+ /** How often each confirmation branch resends the transaction. */
6
7
  const RESEND_INTERVAL_MS = 1e3;
7
8
  /**
8
9
  * How often this poller re-reads `getSignatureStatuses`. The default Solana
@@ -59,6 +60,6 @@ async function confirmSignature(options) {
59
60
  }
60
61
  }
61
62
  //#endregion
62
- export { SIGNATURE_POLL_INTERVAL_MS, confirmSignature };
63
+ export { RESEND_INTERVAL_MS, SIGNATURE_POLL_INTERVAL_MS, confirmSignature };
63
64
 
64
65
  //# sourceMappingURL=confirmSignature.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"confirmSignature.js","names":[],"sources":["../../../src/confirmation/confirmSignature.ts"],"sourcesContent":["import type { Signature } from '@solana/kit'\nimport type { SolanaRpcType } from '../rpc/types.js'\nimport type { TransactionLifetime } from '../utils/getTransactionLifetime.js'\nimport { abortableSleep } from './abortableSleep.js'\nimport { createConfirmationDeadline } from './createConfirmationDeadline.js'\nimport { pollUntilDeadline } from './pollUntilDeadline.js'\nimport {\n type ConfirmationOutcome,\n isConfirmedCommitment,\n type SignatureStatus,\n} from './types.js'\n\nconst RESEND_INTERVAL_MS = 1000\n/**\n * How often this poller re-reads `getSignatureStatuses`. The default Solana\n * RPCs tolerate 2.5 req/s of status reads; the Jito bundle poller runs slower\n * because its endpoints do not (see `confirmBundle`).\n */\nexport const SIGNATURE_POLL_INTERVAL_MS = 400\n\n/** Confirms one transaction against one RPC. Holds no policy: the deadline\n * decides when to stop, and the resend loop only observes an `AbortSignal`. */\nexport async function confirmSignature(options: {\n rpc: SolanaRpcType\n signal: AbortSignal\n signature: Signature\n lifetimes: TransactionLifetime[]\n resend: (rpc: SolanaRpcType, signal: AbortSignal) => Promise<void>\n /**\n * Reports that this RPC accepted a send of the transaction. Must not throw -\n * `sendAndConfirmTransaction` contains any throw from the integrator\n * callback it wraps.\n */\n onBroadcast?: () => void\n}): Promise<ConfirmationOutcome<SignatureStatus>> {\n const { rpc, signal, signature, lifetimes, resend } = options\n const deadline = createConfirmationDeadline({ lifetimes, rpc })\n\n // Ends the resend loop when this branch finishes.\n const branch = new AbortController()\n const abortBranch = (): void => branch.abort()\n signal.addEventListener('abort', abortBranch, { once: true })\n\n let sendSucceeded = false\n\n // Awaited so \"did this RPC ever accept the transaction?\" has a settled\n // answer by the time polling ends, rather than one that depends on\n // microtask ordering.\n try {\n await resend(rpc, signal)\n sendSucceeded = true\n // A send can fulfil after the abort; reporting a broadcast then would\n // regress an action status the wait task already finalized.\n // `sendSucceeded` still latches - the RPC did accept it.\n if (!signal.aborted) {\n options.onBroadcast?.()\n }\n } catch (_) {\n // Continue with confirmation even if the initial send fails — another RPC\n // may already have propagated the transaction.\n }\n\n const resending = (async () => {\n while (!branch.signal.aborted) {\n await abortableSleep(RESEND_INTERVAL_MS, branch.signal)\n if (branch.signal.aborted) {\n break\n }\n try {\n await resend(rpc, branch.signal)\n sendSucceeded = true\n // Same late-fulfilment guard as the first send.\n if (!branch.signal.aborted) {\n options.onBroadcast?.()\n }\n } catch (_) {\n // Resending is best-effort. A total failure is caught by the\n // neverBroadcast check in the verdict.\n }\n }\n })()\n resending.catch(() => {})\n\n const readStatus = async (): Promise<SignatureStatus | null> => {\n const response = await rpc\n .getSignatureStatuses([signature])\n .send({ abortSignal: signal })\n // A `{ value: null }` answer responded but said nothing - poll again\n // rather than throw a `TypeError` into the read-failure budget.\n const status = response?.value?.[0]\n if (status && isConfirmedCommitment(status.confirmationStatus)) {\n return status\n }\n return null\n }\n\n try {\n return await pollUntilDeadline({\n deadline,\n signal,\n pollIntervalMs: SIGNATURE_POLL_INTERVAL_MS,\n probe: readStatus,\n read: 'signature status read',\n subject: 'transaction',\n // Read at verdict time, not captured: the resend loop may succeed long\n // after the awaited first send failed.\n neverBroadcast: () => !sendSucceeded,\n })\n } finally {\n branch.abort()\n signal.removeEventListener('abort', abortBranch)\n }\n}\n"],"mappings":";;;;;AAYA,MAAM,qBAAqB;;;;;;AAM3B,MAAa,6BAA6B;;;AAI1C,eAAsB,iBAAiB,SAYW;CAChD,MAAM,EAAE,KAAK,QAAQ,WAAW,WAAW,WAAW;CACtD,MAAM,WAAW,2BAA2B;EAAE;EAAW;CAAI,CAAC;CAG9D,MAAM,SAAS,IAAI,gBAAgB;CACnC,MAAM,oBAA0B,OAAO,MAAM;CAC7C,OAAO,iBAAiB,SAAS,aAAa,EAAE,MAAM,KAAK,CAAC;CAE5D,IAAI,gBAAgB;CAKpB,IAAI;EACF,MAAM,OAAO,KAAK,MAAM;EACxB,gBAAgB;EAIhB,IAAI,CAAC,OAAO,SACV,QAAQ,cAAc;CAE1B,SAAS,GAAG,CAGZ;CAqBA,CAnBmB,YAAY;EAC7B,OAAO,CAAC,OAAO,OAAO,SAAS;GAC7B,MAAM,eAAe,oBAAoB,OAAO,MAAM;GACtD,IAAI,OAAO,OAAO,SAChB;GAEF,IAAI;IACF,MAAM,OAAO,KAAK,OAAO,MAAM;IAC/B,gBAAgB;IAEhB,IAAI,CAAC,OAAO,OAAO,SACjB,QAAQ,cAAc;GAE1B,SAAS,GAAG,CAGZ;EACF;CACF,EAAA,CACQ,CAAC,CAAC,YAAY,CAAC,CAAC;CAExB,MAAM,aAAa,YAA6C;EAM9D,MAAM,UAAS,MALQ,IACpB,qBAAqB,CAAC,SAAS,CAAC,CAAC,CACjC,KAAK,EAAE,aAAa,OAAO,CAAC,EAAA,EAGN,QAAQ;EACjC,IAAI,UAAU,sBAAsB,OAAO,kBAAkB,GAC3D,OAAO;EAET,OAAO;CACT;CAEA,IAAI;EACF,OAAO,MAAM,kBAAkB;GAC7B;GACA;GACA,gBAAA;GACA,OAAO;GACP,MAAM;GACN,SAAS;GAGT,sBAAsB,CAAC;EACzB,CAAC;CACH,UAAU;EACR,OAAO,MAAM;EACb,OAAO,oBAAoB,SAAS,WAAW;CACjD;AACF"}
1
+ {"version":3,"file":"confirmSignature.js","names":[],"sources":["../../../src/confirmation/confirmSignature.ts"],"sourcesContent":["import type { Signature } from '@solana/kit'\nimport type { SolanaRpcType } from '../rpc/types.js'\nimport type { TransactionLifetime } from '../utils/getTransactionLifetime.js'\nimport { abortableSleep } from './abortableSleep.js'\nimport { createConfirmationDeadline } from './createConfirmationDeadline.js'\nimport { pollUntilDeadline } from './pollUntilDeadline.js'\nimport {\n type ConfirmationOutcome,\n isConfirmedCommitment,\n type SignatureStatus,\n} from './types.js'\n\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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;EACb,OAAO,oBAAoB,SAAS,WAAW;CACjD;AACF"}
@@ -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
@@ -1 +1 @@
1
- {"version":3,"file":"registry.d.ts","names":[],"sources":["../../../src/rpc/registry.ts"],"mappings":";;;;;YAuBY;;;;YAKA;EACV,SAAS;;EAET;;;;;qBAMW;;;;;;;;qBASA;;;;;;qBA8EA,eACX,mBACC,QAAQ;;;;;qBAiGE,gBACX,QAAQ,cACP,QAAQ;;;;;;qBAYE,cACX,QAAQ,cACP;EAAU,MAAM;EAAe"}
1
+ {"version":3,"file":"registry.d.ts","names":[],"sources":["../../../src/rpc/registry.ts"],"mappings":";;;;;YAyBY;;;;YAKA;EACV,SAAS;;EAET;;;;;qBAMW;;;;;;;;qBASA;;;;;;qBA8EA,eACX,mBACC,QAAQ;;;;;qBAyHE,gBACX,QAAQ,cACP,QAAQ;;;;;;;;qBAWE,qBAAsB,sBAAoB;;;;;;qBAU1C,cACX,QAAQ,cACP;EAAU,MAAM;EAAe;;;;;;;;;;qBAarB,qBACX,sBACC;EAAU,MAAM;EAAe"}
@@ -2,8 +2,8 @@ import { createJitoRpc } from "./jito/createJitoRpc.js";
2
2
  import { ChainId, LruMap, withDedupe } from "@lifi/sdk";
3
3
  import { createSolanaRpc } from "@solana/kit";
4
4
  //#region src/rpc/registry.ts
5
- const solanaRpcs = new LruMap(12);
6
- const jitoRpcs = new LruMap(12);
5
+ const solanaRpcs = new LruMap(64);
6
+ const jitoRpcs = new LruMap(64);
7
7
  /**
8
8
  * A well-formed but non-existent Jito bundle id used solely to probe RPC
9
9
  * capability. It forces `getBundleStatuses` to actually execute, so we can tell
@@ -31,7 +31,7 @@ const JITO_PROBE_GATEWAY_RETRY_MS = 9e5;
31
31
  * set never shrinks, and every bundle submission re-probes every non-Jito
32
32
  * endpoint at up to `PROBE_TIMEOUT_MS` each, on the latency path before
33
33
  * submission can start. */
34
- const jitoProbes = new LruMap(12);
34
+ const jitoProbes = new LruMap(64);
35
35
  /** One rule for every outcome: a record is fresh until its own window closes.
36
36
  * `Infinity` covers the answers that cannot change. */
37
37
  const isProbeFresh = (record) => record !== void 0 && Date.now() - record.at < record.retryMs;
@@ -95,20 +95,26 @@ const probeJitoRpc = async (rpcUrl) => {
95
95
  */
96
96
  const ensureSolanaRpcs = async (client) => {
97
97
  const rpcUrls = await client.getRpcUrlsByChainId(ChainId.SOL);
98
- for (const rpcUrl of rpcUrls) if (!solanaRpcs.has(rpcUrl)) solanaRpcs.set(rpcUrl, createSolanaRpc(rpcUrl));
98
+ ensureSolanaRpcsFor(rpcUrls);
99
99
  return rpcUrls;
100
100
  };
101
+ /** Creates and caches a client for each URL that has none yet. */
102
+ const ensureSolanaRpcsFor = (rpcUrls) => {
103
+ for (const rpcUrl of rpcUrls) if (!solanaRpcs.has(rpcUrl)) solanaRpcs.set(rpcUrl, createSolanaRpc(rpcUrl));
104
+ };
105
+ const cachedSolanaRpcs = (rpcUrls) => rpcUrls.map((rpcUrl) => solanaRpcs.get(rpcUrl)).filter((rpc) => Boolean(rpc));
101
106
  /**
102
- * Initializes and caches Jito RPCs for every configured Solana RPC URL.
107
+ * Probes each URL for Jito support and caches a client for every supported
108
+ * one. The configured RPCs and the write RPCs share this cache.
103
109
  *
104
110
  * Every probe outcome is cached, so a non-Jito endpoint is probed once rather
105
111
  * than once per bundle submission. Each record carries its own retry window:
106
112
  * see `JITO_PROBE_RETRY_MS` and `JITO_PROBE_GATEWAY_RETRY_MS` for the two that
107
113
  * expire.
108
- * @param client - The SDK client used to fetch RPC URLs.
114
+ * @param rpcUrls - The URLs to probe.
115
+ * @returns - How many of the URLs are currently unreachable.
109
116
  */
110
- const ensureJitoRpcs = async (client) => {
111
- const rpcUrls = await client.getRpcUrlsByChainId(ChainId.SOL);
117
+ const ensureJitoRpcsFor = async (rpcUrls) => {
112
118
  const unprobed = rpcUrls.filter((rpcUrl) => !isProbeFresh(jitoProbes.get(rpcUrl)));
113
119
  (await Promise.all(unprobed.map((rpcUrl) => withDedupe(() => probeJitoRpc(rpcUrl), { id: `jito-probe:${rpcUrl}` })))).forEach(({ outcome, retryMs }, index) => {
114
120
  const rpcUrl = unprobed[index];
@@ -120,17 +126,37 @@ const ensureJitoRpcs = async (client) => {
120
126
  if (outcome === "supported") jitoRpcs.set(rpcUrl, createJitoRpc(rpcUrl));
121
127
  else jitoRpcs.delete(rpcUrl);
122
128
  });
129
+ return rpcUrls.filter((rpcUrl) => jitoProbes.get(rpcUrl)?.outcome === "unreachable").length;
130
+ };
131
+ /**
132
+ * Initializes and caches Jito RPCs for every configured Solana RPC URL.
133
+ * @param client - The SDK client used to fetch RPC URLs.
134
+ */
135
+ const ensureJitoRpcs = async (client) => {
136
+ const rpcUrls = await client.getRpcUrlsByChainId(ChainId.SOL);
123
137
  return {
124
138
  rpcUrls,
125
- unreachable: rpcUrls.filter((rpcUrl) => jitoProbes.get(rpcUrl)?.outcome === "unreachable").length
139
+ unreachable: await ensureJitoRpcsFor(rpcUrls)
126
140
  };
127
141
  };
142
+ const cachedJitoRpcs = (rpcUrls) => rpcUrls.map((rpcUrl) => jitoRpcs.get(rpcUrl)).filter((rpc) => Boolean(rpc));
128
143
  /**
129
144
  * Wrapper around getting the Solana RPCs
130
145
  * @returns - Solana RPCs
131
146
  */
132
147
  const getSolanaRpcs = async (client) => {
133
- return (await ensureSolanaRpcs(client)).map((rpcUrl) => solanaRpcs.get(rpcUrl)).filter((rpc) => Boolean(rpc));
148
+ return cachedSolanaRpcs(await ensureSolanaRpcs(client));
149
+ };
150
+ /**
151
+ * Clients for the write RPCs (`rpcUrls[ChainId.SOL].write`). They only
152
+ * send transactions; the one read they get is the Jito probe in
153
+ * `getJitoCapableRpcs`.
154
+ * @param rpcUrls - The write RPC URLs.
155
+ * @returns - Solana RPCs to send transactions through.
156
+ */
157
+ const getSolanaWriteRpcs = (rpcUrls) => {
158
+ ensureSolanaRpcsFor(rpcUrls);
159
+ return cachedSolanaRpcs(rpcUrls);
134
160
  };
135
161
  /** `unreachable` counts endpoints whose probe failed without naming the
136
162
  * method unknown. Empty `rpcs` with a non-zero count is usually an outage, but
@@ -140,11 +166,26 @@ const getSolanaRpcs = async (client) => {
140
166
  const getJitoRpcs = async (client) => {
141
167
  const { rpcUrls, unreachable } = await ensureJitoRpcs(client);
142
168
  return {
143
- rpcs: rpcUrls.map((rpcUrl) => jitoRpcs.get(rpcUrl)).filter((rpc) => Boolean(rpc)),
169
+ rpcs: cachedJitoRpcs(rpcUrls),
170
+ unreachable
171
+ };
172
+ };
173
+ /**
174
+ * The given URLs that pass the Jito probe - the bundle or write RPCs of
175
+ * `rpcUrls[ChainId.SOL]`. They share the probe cache with the read RPCs.
176
+ * `unreachable` counts the URLs whose probe failed without an answer, as in
177
+ * `getJitoRpcs`.
178
+ * @param rpcUrls - The URLs to probe.
179
+ * @returns - Jito RPCs to submit bundles through, and the unreachable count.
180
+ */
181
+ const getJitoCapableRpcs = async (rpcUrls) => {
182
+ const unreachable = await ensureJitoRpcsFor(rpcUrls);
183
+ return {
184
+ rpcs: cachedJitoRpcs(rpcUrls),
144
185
  unreachable
145
186
  };
146
187
  };
147
188
  //#endregion
148
- export { JITO_PROBE_GATEWAY_RETRY_MS, JITO_PROBE_RETRY_MS, getJitoRpcs, getSolanaRpcs, probeJitoRpc };
189
+ export { JITO_PROBE_GATEWAY_RETRY_MS, JITO_PROBE_RETRY_MS, getJitoCapableRpcs, getJitoRpcs, getSolanaRpcs, getSolanaWriteRpcs, probeJitoRpc };
149
190
 
150
191
  //# sourceMappingURL=registry.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"registry.js","names":[],"sources":["../../../src/rpc/registry.ts"],"sourcesContent":["import { ChainId, LruMap, type SDKClient, withDedupe } from '@lifi/sdk'\nimport { createSolanaRpc } from '@solana/kit'\nimport { createJitoRpc } from './jito/createJitoRpc.js'\nimport type { JitoRpcType, SolanaRpcType } from './types.js'\n\nconst solanaRpcs = new LruMap<SolanaRpcType>(12)\nconst jitoRpcs = new LruMap<JitoRpcType>(12)\n\n/**\n * A well-formed but non-existent Jito bundle id used solely to probe RPC\n * capability. It forces `getBundleStatuses` to actually execute, so we can tell\n * a Jito-capable RPC (resolves with `{ value: [null] }` — bundle not found)\n * apart from a standard Solana RPC (throws \"Method not found\").\n *\n * Uses all `1`s: 64 chars, valid as both hex and base-58 (base-58 excludes\n * `0`/`O`/`I`/`l`), so a provider that validates the id in either encoding\n * still accepts it and performs the lookup instead of rejecting the probe.\n */\nconst PROBE_BUNDLE_ID =\n '1111111111111111111111111111111111111111111111111111111111111111'\n\n/** Both leave the endpoint out of the Jito list, but only `unsupported` is a\n * configuration gap the integrator can act on. */\nexport type JitoProbeOutcome = 'supported' | 'unsupported' | 'unreachable'\n\n/** An outcome plus how long it may be trusted. The classifier decides both,\n * because how long an answer is worth is a property of the evidence that\n * produced it, not of the outcome alone. */\nexport type JitoProbeResult = {\n outcome: JitoProbeOutcome\n /** `Infinity` for an answer that cannot change. */\n retryMs: number\n}\n\n/** Retry window for a probe that failed without naming the method unknown.\n * An outage heals, so a permanent entry would keep a recovered endpoint out of\n * the Jito list for the whole process. */\nexport const JITO_PROBE_RETRY_MS = 30_000\n\n/** Retry window for a bare HTTP 401/403. Longer than an outage's, shorter than\n * forever. The refusal never reached the JSON-RPC layer, so it proves nothing\n * about capability: a plan gate, a provider deploy and an allowlist entry\n * still propagating are indistinguishable here. Treating it as permanent meant\n * one transient 403 removed a working endpoint for the process lifetime;\n * treating it as a 30 s outage would re-probe a real plan gate on the\n * pre-submission latency path twice a minute, forever. */\nexport const JITO_PROBE_GATEWAY_RETRY_MS: number = 15 * 60_000\n\ntype JitoProbeRecord = JitoProbeResult & { at: number }\n\n/** Every answered probe, the negative ones included. Without them the unprobed\n * set never shrinks, and every bundle submission re-probes every non-Jito\n * endpoint at up to `PROBE_TIMEOUT_MS` each, on the latency path before\n * submission can start. */\nconst jitoProbes = new LruMap<JitoProbeRecord>(12)\n\n/** One rule for every outcome: a record is fresh until its own window closes.\n * `Infinity` covers the answers that cannot change. */\nconst isProbeFresh = (record: JitoProbeRecord | undefined): boolean =>\n record !== undefined && Date.now() - record.at < record.retryMs\n\n/** `@solana/kit` puts the JSON-RPC code on `context.__code`, not `error.code`.\n * The message is a last resort - a provider can reword it. An unrecognized\n * failure counts as `unreachable`, so a misread blames an outage. */\nconst JSON_RPC_METHOD_NOT_FOUND = -32601\n/** Non-standard; providers use it for \"your plan lacks this method\". */\nconst PROVIDER_PLAN_RESTRICTED = -32403\n\nconst CAPABILITY_CODES: number[] = [\n JSON_RPC_METHOD_NOT_FOUND,\n PROVIDER_PLAN_RESTRICTED,\n]\n\n/** A plan gate rejects before JSON-RPC, so no `-32601` arrives - Helius\n * answers with a bare 403. Unlike a JSON-RPC code this never reached the RPC\n * layer, so it is a gateway verdict rather than a capability answer, and it\n * earns a window instead of permanence. 429 and 5xx are absent: those take the\n * shorter outage window. */\nconst GATEWAY_REFUSAL_HTTP_STATUSES: number[] = [401, 403]\n\nconst readProbeFailure = (error: unknown): JitoProbeResult => {\n const candidate = error as\n | {\n code?: unknown\n context?: { __code?: unknown; statusCode?: unknown }\n }\n | undefined\n\n // kit's `__code` is 8100002 for every HTTP failure, so only a JSON-RPC code\n // that reached the body is meaningful.\n const rpcCode = candidate?.code ?? candidate?.context?.__code\n if (typeof rpcCode === 'number' && CAPABILITY_CODES.includes(rpcCode)) {\n // The server parsed the request and said it has no such method. Definitive.\n return { outcome: 'unsupported', retryMs: Number.POSITIVE_INFINITY }\n }\n\n const status = candidate?.context?.statusCode\n if (\n typeof status === 'number' &&\n GATEWAY_REFUSAL_HTTP_STATUSES.includes(status)\n ) {\n return { outcome: 'unreachable', retryMs: JITO_PROBE_GATEWAY_RETRY_MS }\n }\n\n const message = error instanceof Error ? error.message : String(error)\n return /method not found|method does not exist|-32601|method .* not supported|unsupported method|only available for business plans/i.test(\n message\n )\n ? { outcome: 'unsupported', retryMs: Number.POSITIVE_INFINITY }\n : { outcome: 'unreachable', retryMs: JITO_PROBE_RETRY_MS }\n}\n\n/**\n * Bounded because it runs upstream of `raceRpcs`, outside the confirmation\n * budget the SDK documents: an endpoint that accepts the connection and never\n * answers would otherwise stall bundle submission indefinitely.\n */\nconst PROBE_TIMEOUT_MS = 5_000\n\n/**\n * Probes with `getBundleStatuses` rather than `getTipAccounts`: it is the\n * method bundle confirmation actually uses, and providers such as Helius\n * support it without exposing `getTipAccounts`.\n */\nexport const probeJitoRpc = async (\n rpcUrl: string\n): Promise<JitoProbeResult> => {\n const controller = new AbortController()\n const timer = setTimeout(() => controller.abort(), PROBE_TIMEOUT_MS)\n try {\n const rpc = createJitoRpc(rpcUrl)\n await rpc\n .getBundleStatuses([PROBE_BUNDLE_ID])\n .send({ abortSignal: controller.signal })\n return { outcome: 'supported', retryMs: Number.POSITIVE_INFINITY }\n } catch (error) {\n return readProbeFailure(error)\n } finally {\n clearTimeout(timer)\n }\n}\n\n/**\n * Initializes Solana RPCs for all available RPC URLs if they haven't been cached yet.\n * @param client - The SDK client used to fetch RPC URLs.\n */\nconst ensureSolanaRpcs = async (client: SDKClient): Promise<string[]> => {\n const rpcUrls = await client.getRpcUrlsByChainId(ChainId.SOL)\n for (const rpcUrl of rpcUrls) {\n if (!solanaRpcs.has(rpcUrl)) {\n solanaRpcs.set(rpcUrl, createSolanaRpc(rpcUrl))\n }\n }\n return rpcUrls\n}\n\n/**\n * Initializes and caches Jito RPCs for every configured Solana RPC URL.\n *\n * Every probe outcome is cached, so a non-Jito endpoint is probed once rather\n * than once per bundle submission. Each record carries its own retry window:\n * see `JITO_PROBE_RETRY_MS` and `JITO_PROBE_GATEWAY_RETRY_MS` for the two that\n * expire.\n * @param client - The SDK client used to fetch RPC URLs.\n */\nconst ensureJitoRpcs = async (\n client: SDKClient\n): Promise<{ rpcUrls: string[]; unreachable: number }> => {\n const rpcUrls = await client.getRpcUrlsByChainId(ChainId.SOL)\n // Probed in parallel: serially, one slow endpoint delayed every URL behind\n // it before submission could start.\n const unprobed = rpcUrls.filter(\n (rpcUrl) => !isProbeFresh(jitoProbes.get(rpcUrl))\n )\n // Deduplicated per URL: without it two concurrent submissions each probe\n // every unprobed endpoint, and the slower probe writes last - a 5 s timeout\n // resolving `unreachable` used to overwrite a `supported` answer that landed\n // at 300 ms, evicting a verified-healthy endpoint.\n //\n // `withDedupe` drops its entry in a `.finally`, so this guarantees at most\n // one probe *in flight* per URL, not one probe per URL. The write below waits\n // for the whole batch, so a fast URL's record is unwritten while a slow\n // sibling is still running - up to `PROBE_TIMEOUT_MS` - and every caller\n // arriving in that window re-probes the fast URL. Repeats are therefore\n // bounded by arrivals, not by one.\n //\n // What this does rule out is the clobber: a second probe can only begin\n // after the first has settled, so it always carries the newer answer and\n // always writes second. Write order matches result recency, which is why no\n // timestamp comparison is needed here.\n const results = await Promise.all(\n unprobed.map((rpcUrl) =>\n withDedupe(() => probeJitoRpc(rpcUrl), { id: `jito-probe:${rpcUrl}` })\n )\n )\n\n results.forEach(({ outcome, retryMs }, index) => {\n const rpcUrl = unprobed[index]\n jitoProbes.set(rpcUrl, { outcome, retryMs, at: Date.now() })\n if (outcome === 'supported') {\n jitoRpcs.set(rpcUrl, createJitoRpc(rpcUrl))\n } else {\n // An endpoint that used to answer and now does not must leave the list,\n // or `getJitoRpcs` keeps handing out a client for it.\n jitoRpcs.delete(rpcUrl)\n }\n })\n\n // Counted over every URL, not only the freshly probed ones: a cached\n // `unreachable` still has to reach `sendAndConfirmBundle`, which uses the\n // count to choose between \"retry, likely temporary\" and \"supply a\n // Jito-capable URL\".\n const unreachable = rpcUrls.filter(\n (rpcUrl) => jitoProbes.get(rpcUrl)?.outcome === 'unreachable'\n ).length\n\n return { rpcUrls, unreachable }\n}\n\n/**\n * Wrapper around getting the Solana RPCs\n * @returns - Solana RPCs\n */\nexport const getSolanaRpcs = async (\n client: SDKClient\n): Promise<SolanaRpcType[]> => {\n const rpcUrls = await ensureSolanaRpcs(client)\n return rpcUrls\n .map((rpcUrl) => solanaRpcs.get(rpcUrl))\n .filter((rpc): rpc is SolanaRpcType => Boolean(rpc))\n}\n\n/** `unreachable` counts endpoints whose probe failed without naming the\n * method unknown. Empty `rpcs` with a non-zero count is usually an outage, but\n * not always: a bare 401/403 lands here too, and that can be a plan gate the\n * integrator has to fix. `sendAndConfirmBundle`'s message names both, because\n * this count cannot tell them apart. */\nexport const getJitoRpcs = async (\n client: SDKClient\n): Promise<{ rpcs: JitoRpcType[]; unreachable: number }> => {\n const { rpcUrls, unreachable } = await ensureJitoRpcs(client)\n return {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ACzB,WAC0D;CAC1D,MAAM,EAAE,SAAS,gBAAgB,MAAM,eAAe,MAAM;CAC5D,OAAO;EACL,MAAM,QACH,KAAK,WAAW,SAAS,IAAI,MAAM,CAAC,CAAC,CACrC,QAAQ,QAA4B,QAAQ,GAAG,CAAC;EACnD;CACF;AACF"}
1
+ {"version":3,"file":"registry.js","names":[],"sources":["../../../src/rpc/registry.ts"],"sourcesContent":["import { ChainId, LruMap, type SDKClient, withDedupe } from '@lifi/sdk'\nimport { createSolanaRpc } from '@solana/kit'\nimport { createJitoRpc } from './jito/createJitoRpc.js'\nimport type { JitoRpcType, SolanaRpcType } from './types.js'\n\n// Read, write and bundle URLs share these caches, so they hold more than one\n// list's worth: an entry evicted mid-use is probed or built again.\nconst solanaRpcs = new LruMap<SolanaRpcType>(64)\nconst jitoRpcs = new LruMap<JitoRpcType>(64)\n\n/**\n * A well-formed but non-existent Jito bundle id used solely to probe RPC\n * capability. It forces `getBundleStatuses` to actually execute, so we can tell\n * a Jito-capable RPC (resolves with `{ value: [null] }` — bundle not found)\n * apart from a standard Solana RPC (throws \"Method not found\").\n *\n * Uses all `1`s: 64 chars, valid as both hex and base-58 (base-58 excludes\n * `0`/`O`/`I`/`l`), so a provider that validates the id in either encoding\n * still accepts it and performs the lookup instead of rejecting the probe.\n */\nconst PROBE_BUNDLE_ID =\n '1111111111111111111111111111111111111111111111111111111111111111'\n\n/** Both leave the endpoint out of the Jito list, but only `unsupported` is a\n * configuration gap the integrator can act on. */\nexport type JitoProbeOutcome = 'supported' | 'unsupported' | 'unreachable'\n\n/** An outcome plus how long it may be trusted. The classifier decides both,\n * because how long an answer is worth is a property of the evidence that\n * produced it, not of the outcome alone. */\nexport type JitoProbeResult = {\n outcome: JitoProbeOutcome\n /** `Infinity` for an answer that cannot change. */\n retryMs: number\n}\n\n/** Retry window for a probe that failed without naming the method unknown.\n * An outage heals, so a permanent entry would keep a recovered endpoint out of\n * the Jito list for the whole process. */\nexport const JITO_PROBE_RETRY_MS = 30_000\n\n/** Retry window for a bare HTTP 401/403. Longer than an outage's, shorter than\n * forever. The refusal never reached the JSON-RPC layer, so it proves nothing\n * about capability: a plan gate, a provider deploy and an allowlist entry\n * still propagating are indistinguishable here. Treating it as permanent meant\n * one transient 403 removed a working endpoint for the process lifetime;\n * treating it as a 30 s outage would re-probe a real plan gate on the\n * pre-submission latency path twice a minute, forever. */\nexport const JITO_PROBE_GATEWAY_RETRY_MS: number = 15 * 60_000\n\ntype JitoProbeRecord = JitoProbeResult & { at: number }\n\n/** Every answered probe, the negative ones included. Without them the unprobed\n * set never shrinks, and every bundle submission re-probes every non-Jito\n * endpoint at up to `PROBE_TIMEOUT_MS` each, on the latency path before\n * submission can start. */\nconst jitoProbes = new LruMap<JitoProbeRecord>(64)\n\n/** One rule for every outcome: a record is fresh until its own window closes.\n * `Infinity` covers the answers that cannot change. */\nconst isProbeFresh = (record: JitoProbeRecord | undefined): boolean =>\n record !== undefined && Date.now() - record.at < record.retryMs\n\n/** `@solana/kit` puts the JSON-RPC code on `context.__code`, not `error.code`.\n * The message is a last resort - a provider can reword it. An unrecognized\n * failure counts as `unreachable`, so a misread blames an outage. */\nconst JSON_RPC_METHOD_NOT_FOUND = -32601\n/** Non-standard; providers use it for \"your plan lacks this method\". */\nconst PROVIDER_PLAN_RESTRICTED = -32403\n\nconst CAPABILITY_CODES: number[] = [\n JSON_RPC_METHOD_NOT_FOUND,\n PROVIDER_PLAN_RESTRICTED,\n]\n\n/** A plan gate rejects before JSON-RPC, so no `-32601` arrives - Helius\n * answers with a bare 403. Unlike a JSON-RPC code this never reached the RPC\n * layer, so it is a gateway verdict rather than a capability answer, and it\n * earns a window instead of permanence. 429 and 5xx are absent: those take the\n * shorter outage window. */\nconst GATEWAY_REFUSAL_HTTP_STATUSES: number[] = [401, 403]\n\nconst readProbeFailure = (error: unknown): JitoProbeResult => {\n const candidate = error as\n | {\n code?: unknown\n context?: { __code?: unknown; statusCode?: unknown }\n }\n | undefined\n\n // kit's `__code` is 8100002 for every HTTP failure, so only a JSON-RPC code\n // that reached the body is meaningful.\n const rpcCode = candidate?.code ?? candidate?.context?.__code\n if (typeof rpcCode === 'number' && CAPABILITY_CODES.includes(rpcCode)) {\n // The server parsed the request and said it has no such method. Definitive.\n return { outcome: 'unsupported', retryMs: Number.POSITIVE_INFINITY }\n }\n\n const status = candidate?.context?.statusCode\n if (\n typeof status === 'number' &&\n GATEWAY_REFUSAL_HTTP_STATUSES.includes(status)\n ) {\n return { outcome: 'unreachable', retryMs: JITO_PROBE_GATEWAY_RETRY_MS }\n }\n\n const message = error instanceof Error ? error.message : String(error)\n return /method not found|method does not exist|-32601|method .* not supported|unsupported method|only available for business plans/i.test(\n message\n )\n ? { outcome: 'unsupported', retryMs: Number.POSITIVE_INFINITY }\n : { outcome: 'unreachable', retryMs: JITO_PROBE_RETRY_MS }\n}\n\n/**\n * Bounded because it runs upstream of `raceRpcs`, outside the confirmation\n * budget the SDK documents: an endpoint that accepts the connection and never\n * answers would otherwise stall bundle submission indefinitely.\n */\nconst PROBE_TIMEOUT_MS = 5_000\n\n/**\n * Probes with `getBundleStatuses` rather than `getTipAccounts`: it is the\n * method bundle confirmation actually uses, and providers such as Helius\n * support it without exposing `getTipAccounts`.\n */\nexport const probeJitoRpc = async (\n rpcUrl: string\n): Promise<JitoProbeResult> => {\n const controller = new AbortController()\n const timer = setTimeout(() => controller.abort(), PROBE_TIMEOUT_MS)\n try {\n const rpc = createJitoRpc(rpcUrl)\n await rpc\n .getBundleStatuses([PROBE_BUNDLE_ID])\n .send({ abortSignal: controller.signal })\n return { outcome: 'supported', retryMs: Number.POSITIVE_INFINITY }\n } catch (error) {\n return readProbeFailure(error)\n } finally {\n clearTimeout(timer)\n }\n}\n\n/**\n * Initializes Solana RPCs for all available RPC URLs if they haven't been cached yet.\n * @param client - The SDK client used to fetch RPC URLs.\n */\nconst ensureSolanaRpcs = async (client: SDKClient): Promise<string[]> => {\n const rpcUrls = await client.getRpcUrlsByChainId(ChainId.SOL)\n ensureSolanaRpcsFor(rpcUrls)\n return rpcUrls\n}\n\n/** Creates and caches a client for each URL that has none yet. */\nconst ensureSolanaRpcsFor = (rpcUrls: string[]): void => {\n for (const rpcUrl of rpcUrls) {\n if (!solanaRpcs.has(rpcUrl)) {\n solanaRpcs.set(rpcUrl, createSolanaRpc(rpcUrl))\n }\n }\n}\n\nconst cachedSolanaRpcs = (rpcUrls: string[]): SolanaRpcType[] =>\n rpcUrls\n .map((rpcUrl) => solanaRpcs.get(rpcUrl))\n .filter((rpc): rpc is SolanaRpcType => Boolean(rpc))\n\n/**\n * Probes each URL for Jito support and caches a client for every supported\n * one. The configured RPCs and the write RPCs share this cache.\n *\n * Every probe outcome is cached, so a non-Jito endpoint is probed once rather\n * than once per bundle submission. Each record carries its own retry window:\n * see `JITO_PROBE_RETRY_MS` and `JITO_PROBE_GATEWAY_RETRY_MS` for the two that\n * expire.\n * @param rpcUrls - The URLs to probe.\n * @returns - How many of the URLs are currently unreachable.\n */\nconst ensureJitoRpcsFor = async (rpcUrls: string[]): Promise<number> => {\n // Probed in parallel: serially, one slow endpoint delayed every URL behind\n // it before submission could start.\n const unprobed = rpcUrls.filter(\n (rpcUrl) => !isProbeFresh(jitoProbes.get(rpcUrl))\n )\n // Deduplicated per URL: without it two concurrent submissions each probe\n // every unprobed endpoint, and the slower probe writes last - a 5 s timeout\n // resolving `unreachable` used to overwrite a `supported` answer that landed\n // at 300 ms, evicting a verified-healthy endpoint.\n //\n // `withDedupe` drops its entry in a `.finally`, so this guarantees at most\n // one probe *in flight* per URL, not one probe per URL. The write below waits\n // for the whole batch, so a fast URL's record is unwritten while a slow\n // sibling is still running - up to `PROBE_TIMEOUT_MS` - and every caller\n // arriving in that window re-probes the fast URL. Repeats are therefore\n // bounded by arrivals, not by one.\n //\n // What this does rule out is the clobber: a second probe can only begin\n // after the first has settled, so it always carries the newer answer and\n // always writes second. Write order matches result recency, which is why no\n // timestamp comparison is needed here.\n const results = await Promise.all(\n unprobed.map((rpcUrl) =>\n withDedupe(() => probeJitoRpc(rpcUrl), { id: `jito-probe:${rpcUrl}` })\n )\n )\n\n results.forEach(({ outcome, retryMs }, index) => {\n const rpcUrl = unprobed[index]\n jitoProbes.set(rpcUrl, { outcome, retryMs, at: Date.now() })\n if (outcome === 'supported') {\n jitoRpcs.set(rpcUrl, createJitoRpc(rpcUrl))\n } else {\n // An endpoint that used to answer and now does not must leave the list,\n // or `getJitoRpcs` keeps handing out a client for it.\n jitoRpcs.delete(rpcUrl)\n }\n })\n\n // Counted over every URL, not only the freshly probed ones: a cached\n // `unreachable` still has to reach `sendAndConfirmBundle`, which uses the\n // count to choose between \"retry, likely temporary\" and \"supply a\n // Jito-capable URL\".\n return rpcUrls.filter(\n (rpcUrl) => jitoProbes.get(rpcUrl)?.outcome === 'unreachable'\n ).length\n}\n\n/**\n * Initializes and caches Jito RPCs for every configured Solana RPC URL.\n * @param client - The SDK client used to fetch RPC URLs.\n */\nconst ensureJitoRpcs = async (\n client: SDKClient\n): Promise<{ rpcUrls: string[]; unreachable: number }> => {\n const rpcUrls = await client.getRpcUrlsByChainId(ChainId.SOL)\n const unreachable = await ensureJitoRpcsFor(rpcUrls)\n return { rpcUrls, unreachable }\n}\n\nconst cachedJitoRpcs = (rpcUrls: string[]): JitoRpcType[] =>\n rpcUrls\n .map((rpcUrl) => jitoRpcs.get(rpcUrl))\n .filter((rpc): rpc is JitoRpcType => Boolean(rpc))\n\n/**\n * Wrapper around getting the Solana RPCs\n * @returns - Solana RPCs\n */\nexport const getSolanaRpcs = async (\n client: SDKClient\n): Promise<SolanaRpcType[]> => {\n return cachedSolanaRpcs(await ensureSolanaRpcs(client))\n}\n\n/**\n * Clients for the write RPCs (`rpcUrls[ChainId.SOL].write`). They only\n * send transactions; the one read they get is the Jito probe in\n * `getJitoCapableRpcs`.\n * @param rpcUrls - The write RPC URLs.\n * @returns - Solana RPCs to send transactions through.\n */\nexport const getSolanaWriteRpcs = (rpcUrls: string[]): SolanaRpcType[] => {\n ensureSolanaRpcsFor(rpcUrls)\n return cachedSolanaRpcs(rpcUrls)\n}\n\n/** `unreachable` counts endpoints whose probe failed without naming the\n * method unknown. Empty `rpcs` with a non-zero count is usually an outage, but\n * not always: a bare 401/403 lands here too, and that can be a plan gate the\n * integrator has to fix. `sendAndConfirmBundle`'s message names both, because\n * this count cannot tell them apart. */\nexport const getJitoRpcs = async (\n client: SDKClient\n): Promise<{ rpcs: JitoRpcType[]; unreachable: number }> => {\n const { rpcUrls, unreachable } = await ensureJitoRpcs(client)\n return { rpcs: cachedJitoRpcs(rpcUrls), unreachable }\n}\n\n/**\n * The given URLs that pass the Jito probe - the bundle or write RPCs of\n * `rpcUrls[ChainId.SOL]`. They share the probe cache with the read RPCs.\n * `unreachable` counts the URLs whose probe failed without an answer, as in\n * `getJitoRpcs`.\n * @param rpcUrls - The URLs to probe.\n * @returns - Jito RPCs to submit bundles through, and the unreachable count.\n */\nexport const getJitoCapableRpcs = async (\n rpcUrls: string[]\n): Promise<{ rpcs: JitoRpcType[]; unreachable: number }> => {\n const unreachable = await ensureJitoRpcsFor(rpcUrls)\n return { rpcs: cachedJitoRpcs(rpcUrls), unreachable }\n}\n"],"mappings":";;;;AAOA,MAAM,aAAa,IAAI,OAAsB,EAAE;AAC/C,MAAM,WAAW,IAAI,OAAoB,EAAE;;;;;;;;;;;AAY3C,MAAM,kBACJ;;;;AAkBF,MAAa,sBAAsB;;;;;;;;AASnC,MAAa,8BAAsC;;;;;AAQnD,MAAM,aAAa,IAAI,OAAwB,EAAE;;;AAIjD,MAAM,gBAAgB,WACpB,WAAW,KAAA,KAAa,KAAK,IAAI,IAAI,OAAO,KAAK,OAAO;AAS1D,MAAM,mBAA6B,CACjC,QACA,MACF;;;;;;AAOA,MAAM,gCAA0C,CAAC,KAAK,GAAG;AAEzD,MAAM,oBAAoB,UAAoC;CAC5D,MAAM,YAAY;CASlB,MAAM,UAAU,WAAW,QAAQ,WAAW,SAAS;CACvD,IAAI,OAAO,YAAY,YAAY,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G;CAAY;AACtD"}
@@ -1,5 +1,5 @@
1
1
  //#region src/version.d.ts
2
2
  export declare const name = "@lifi/sdk-provider-solana";
3
- export declare const version = "4.2.3";
3
+ export declare const version = "4.3.0";
4
4
  //#endregion
5
5
  //# sourceMappingURL=version.d.ts.map
@@ -1,6 +1,6 @@
1
1
  //#region src/version.ts
2
2
  const name = "@lifi/sdk-provider-solana";
3
- const version = "4.2.3";
3
+ const version = "4.3.0";
4
4
  //#endregion
5
5
  export { name, version };
6
6
 
@@ -1 +1 @@
1
- {"version":3,"file":"version.js","names":[],"sources":["../../src/version.ts"],"sourcesContent":["export const name = '@lifi/sdk-provider-solana'\nexport const version = '4.2.3'\n"],"mappings":";AAAA,MAAa,OAAO;AACpB,MAAa,UAAU"}
1
+ {"version":3,"file":"version.js","names":[],"sources":["../../src/version.ts"],"sourcesContent":["export const name = '@lifi/sdk-provider-solana'\nexport const version = '4.3.0'\n"],"mappings":";AAAA,MAAa,OAAO;AACpB,MAAa,UAAU"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lifi/sdk-provider-solana",
3
- "version": "4.2.3",
3
+ "version": "4.3.0",
4
4
  "description": "LI.FI Solana SDK Provider for Any-to-Any Cross-Chain-Swap",
5
5
  "homepage": "https://github.com/lifinance/sdk",
6
6
  "bugs": {
@@ -28,7 +28,7 @@
28
28
  "./package.json": "./package.json"
29
29
  },
30
30
  "dependencies": {
31
- "@lifi/sdk": "4.8.2",
31
+ "@lifi/sdk": "4.9.0",
32
32
  "@solana/kit": "^8.3.0",
33
33
  "@solana/wallet-standard-features": "^1.5.0",
34
34
  "@wallet-standard/base": "^1.1.1"