@lifi/sdk-provider-solana 4.3.5 → 4.3.6

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 (56) hide show
  1. package/CHANGELOG.md +8 -0
  2. package/dist/cjs/actions/sendAndConfirmBundle.d.ts +8 -7
  3. package/dist/cjs/actions/sendAndConfirmBundle.js +22 -16
  4. package/dist/cjs/actions/sendAndConfirmBundle.js.map +1 -1
  5. package/dist/cjs/confirmation/confirmBundle.d.ts +18 -19
  6. package/dist/cjs/confirmation/confirmBundle.js +10 -23
  7. package/dist/cjs/confirmation/confirmBundle.js.map +1 -1
  8. package/dist/cjs/confirmation/confirmSignature.d.ts +2 -2
  9. package/dist/cjs/confirmation/confirmSignature.js +2 -2
  10. package/dist/cjs/confirmation/confirmSignature.js.map +1 -1
  11. package/dist/cjs/confirmation/createConfirmationDeadline.d.ts +1 -1
  12. package/dist/cjs/confirmation/createConfirmationDeadline.js.map +1 -1
  13. package/dist/cjs/confirmation/types.d.ts +1 -1
  14. package/dist/cjs/confirmation/types.js.map +1 -1
  15. package/dist/cjs/core/tasks/SolanaJitoWaitForTransactionTask.js +9 -18
  16. package/dist/cjs/core/tasks/SolanaJitoWaitForTransactionTask.js.map +1 -1
  17. package/dist/cjs/rpc/registry.d.ts +4 -3
  18. package/dist/cjs/rpc/registry.js +4 -3
  19. package/dist/cjs/rpc/registry.js.map +1 -1
  20. package/dist/cjs/version.d.ts +1 -1
  21. package/dist/cjs/version.js +1 -1
  22. package/dist/cjs/version.js.map +1 -1
  23. package/dist/esm/actions/sendAndConfirmBundle.d.ts +8 -7
  24. package/dist/esm/actions/sendAndConfirmBundle.d.ts.map +1 -1
  25. package/dist/esm/actions/sendAndConfirmBundle.js +24 -18
  26. package/dist/esm/actions/sendAndConfirmBundle.js.map +1 -1
  27. package/dist/esm/confirmation/confirmBundle.d.ts +18 -19
  28. package/dist/esm/confirmation/confirmBundle.d.ts.map +1 -1
  29. package/dist/esm/confirmation/confirmBundle.js +10 -23
  30. package/dist/esm/confirmation/confirmBundle.js.map +1 -1
  31. package/dist/esm/confirmation/confirmSignature.d.ts +2 -2
  32. package/dist/esm/confirmation/confirmSignature.js +2 -2
  33. package/dist/esm/confirmation/confirmSignature.js.map +1 -1
  34. package/dist/esm/confirmation/createConfirmationDeadline.d.ts +1 -1
  35. package/dist/esm/confirmation/createConfirmationDeadline.js.map +1 -1
  36. package/dist/esm/confirmation/types.d.ts +1 -1
  37. package/dist/esm/confirmation/types.js.map +1 -1
  38. package/dist/esm/core/tasks/SolanaJitoWaitForTransactionTask.d.ts.map +1 -1
  39. package/dist/esm/core/tasks/SolanaJitoWaitForTransactionTask.js +10 -19
  40. package/dist/esm/core/tasks/SolanaJitoWaitForTransactionTask.js.map +1 -1
  41. package/dist/esm/rpc/registry.d.ts +4 -3
  42. package/dist/esm/rpc/registry.d.ts.map +1 -1
  43. package/dist/esm/rpc/registry.js +4 -3
  44. package/dist/esm/rpc/registry.js.map +1 -1
  45. package/dist/esm/version.d.ts +1 -1
  46. package/dist/esm/version.js +1 -1
  47. package/dist/esm/version.js.map +1 -1
  48. package/package.json +2 -2
  49. package/src/actions/sendAndConfirmBundle.ts +48 -48
  50. package/src/confirmation/confirmBundle.ts +34 -69
  51. package/src/confirmation/confirmSignature.ts +2 -2
  52. package/src/confirmation/createConfirmationDeadline.ts +1 -1
  53. package/src/confirmation/types.ts +1 -1
  54. package/src/core/tasks/SolanaJitoWaitForTransactionTask.ts +13 -27
  55. package/src/rpc/registry.ts +4 -3
  56. package/src/version.ts +1 -1
@@ -1,30 +1,19 @@
1
1
  import { readSignature } from "./readSignature.js";
2
2
  import { getTransactionLifetime } from "../../utils/getTransactionLifetime.js";
3
3
  import { sendAndConfirmBundle } from "../../actions/sendAndConfirmBundle.js";
4
- import { canResendStored, clearStoredTransactions, getTxLink, sendAndSettle } from "./transactionOutcome.js";
4
+ import { canResendStored, clearStoredTransactions, failureOf, getTxLink, sendAndSettle } from "./transactionOutcome.js";
5
5
  import { resumeFromStore } from "./resumeFromStore.js";
6
6
  import { BaseStepExecutionTask, LiFiErrorCode, TransactionError } from "@lifi/sdk";
7
7
  //#region src/core/tasks/SolanaJitoWaitForTransactionTask.ts
8
8
  const MESSAGES = {
9
- rpcUnavailable: "Unable to confirm bundle: every configured Jito RPC failed.",
9
+ rpcUnavailable: "Unable to confirm bundle: every configured Solana RPC failed.",
10
10
  notConfirmed: "Bundle was not confirmed before the SDK stopped waiting.",
11
- allRpcsFailed: "All Jito RPCs failed",
12
- someRpcsFailed: "Some Jito RPCs failed while the confirmation window was open"
11
+ allRpcsFailed: "All Solana RPCs failed",
12
+ someRpcsFailed: "Some Solana RPCs failed while the confirmation window was open"
13
13
  };
14
- /** Jito encodes `err` as a Rust `Result`: a landed bundle carries
15
- * `{ Ok: null }`, so only an explicit `{ Err: … }` counts as a failure. */
16
- function getBundleFailure(err) {
17
- if (typeof err !== "object" || err === null || !("Err" in err)) return;
18
- return { failure: err.Err };
19
- }
20
- /** The failure of a landed bundle, if any. A `null` in `signatureResults` is
21
- * indexing lag, never failure. The bundle-level `err` is checked first: it
22
- * survives a failed `getSignatureStatuses` read. */
14
+ /** The failure of a landed bundle, if any: the first transaction `err`. */
23
15
  function bundleFailureOf(confirmation) {
24
- const bundleFailure = getBundleFailure(confirmation.bundleErr);
25
- if (bundleFailure) return { err: bundleFailure.failure };
26
- const failedResult = confirmation.signatureResults.find((signatureResult) => signatureResult?.err);
27
- return failedResult?.err ? { err: failedResult.err } : void 0;
16
+ return confirmation.signatureResults.map(failureOf).find(Boolean);
28
17
  }
29
18
  var SolanaJitoWaitForTransactionTask = class extends BaseStepExecutionTask {
30
19
  async run(context) {
@@ -59,8 +48,10 @@ var SolanaJitoWaitForTransactionTask = class extends BaseStepExecutionTask {
59
48
  };
60
49
  /**
61
50
  * Submits the signed bundle once, confirms it and applies the result rules
62
- * of `sendAndSettle`, on the first run and on a resume alike. A bundle lands
63
- * whole or not at all, so the first transaction's signature stands for it.
51
+ * of `sendAndSettle`, on the first run and on a resume alike. A Jito bundle
52
+ * lands whole or not at all, so the first transaction's signature stands for
53
+ * it. A sender that is not Jito can land the transactions one by one; a
54
+ * lookup by the first signature then misses a partial landing.
64
55
  */
65
56
  function sendSigned(context, action, options) {
66
57
  const { client, step, statusManager } = context;
@@ -1 +1 @@
1
- {"version":3,"file":"SolanaJitoWaitForTransactionTask.js","names":[],"sources":["../../../../src/core/tasks/SolanaJitoWaitForTransactionTask.ts"],"sourcesContent":["import {\n BaseStepExecutionTask,\n type ExecutionAction,\n LiFiErrorCode,\n type TaskResult,\n TransactionError,\n} from '@lifi/sdk'\nimport type { Signature, Transaction } from '@solana/kit'\nimport { sendAndConfirmBundle } from '../../actions/sendAndConfirmBundle.js'\nimport type { BundleConfirmation } from '../../confirmation/confirmBundle.js'\nimport type { RaceResult } from '../../confirmation/raceRpcs.js'\nimport type { SolanaStepExecutorContext } from '../../types.js'\nimport {\n getTransactionLifetime,\n type TransactionLifetime,\n} from '../../utils/getTransactionLifetime.js'\nimport type { ConfirmationMessages } from './confirmationError.js'\nimport { readSignature } from './readSignature.js'\nimport { resumeFromStore } from './resumeFromStore.js'\nimport {\n canResendStored,\n clearStoredTransactions,\n getTxLink,\n sendAndSettle,\n} from './transactionOutcome.js'\n\n// The `rpc-unavailable` message is distinct from the empty-list throw inside\n// `sendAndConfirmBundle`: RPCs were configured and every one of them failed.\n// That is an outage, and the collected branch errors say what each endpoint\n// did.\nconst MESSAGES: ConfirmationMessages = {\n rpcUnavailable: 'Unable to confirm bundle: every configured Jito RPC failed.',\n notConfirmed: 'Bundle was not confirmed before the SDK stopped waiting.',\n allRpcsFailed: 'All Jito RPCs failed',\n someRpcsFailed:\n 'Some Jito RPCs failed while the confirmation window was open',\n}\n\n/** Jito encodes `err` as a Rust `Result`: a landed bundle carries\n * `{ Ok: null }`, so only an explicit `{ Err: … }` counts as a failure. */\nfunction getBundleFailure(err: unknown): { failure: unknown } | undefined {\n if (typeof err !== 'object' || err === null || !('Err' in err)) {\n return undefined\n }\n return { failure: (err as { Err: unknown }).Err }\n}\n\n/** The failure of a landed bundle, if any. A `null` in `signatureResults` is\n * indexing lag, never failure. The bundle-level `err` is checked first: it\n * survives a failed `getSignatureStatuses` read. */\nfunction bundleFailureOf(\n confirmation: BundleConfirmation\n): { err: unknown } | undefined {\n const bundleFailure = getBundleFailure(confirmation.bundleErr)\n if (bundleFailure) {\n return { err: bundleFailure.failure }\n }\n const failedResult = confirmation.signatureResults.find(\n (signatureResult) => signatureResult?.err\n )\n return failedResult?.err ? { err: failedResult.err } : undefined\n}\n\nexport class SolanaJitoWaitForTransactionTask extends BaseStepExecutionTask {\n async run(context: SolanaStepExecutorContext): Promise<TaskResult> {\n const { step, statusManager, isBridgeExecution, signedTransactions } =\n context\n\n const action = statusManager.findAction(\n step,\n isBridgeExecution ? 'CROSS_CHAIN' : 'SWAP'\n )\n if (!action) {\n throw new TransactionError(\n LiFiErrorCode.TransactionUnprepared,\n 'Unable to prepare transaction. Action not found.'\n )\n }\n\n // Resume mode: the sign task did not run in this session, so the signed\n // bundle comes from `txHex`, or only the first hash from `txHash`.\n if (!signedTransactions) {\n return resumeFromStore(context, action, {\n messages: MESSAGES,\n // Submitted once, as on the first run.\n send: (stored, lifetimes) =>\n sendSigned(context, action, {\n transactions: stored.transactions,\n signature: stored.signature,\n lifetimes,\n resuming: true,\n }),\n })\n }\n\n if (!signedTransactions.length) {\n throw new TransactionError(\n LiFiErrorCode.TransactionUnprepared,\n 'Unable to prepare transaction. Signed transactions are not found.'\n )\n }\n\n let txSignature: Signature\n try {\n txSignature = readSignature(signedTransactions[0])\n } catch (error) {\n // Nothing left the SDK: the bytes go, so \"Try again\" signs again.\n clearStoredTransactions(context, action)\n throw error\n }\n\n const lifetimes = await Promise.all(\n signedTransactions.map((transaction) =>\n getTransactionLifetime(transaction)\n )\n )\n\n return sendSigned(context, action, {\n transactions: signedTransactions,\n signature: txSignature,\n lifetimes,\n resuming: false,\n })\n }\n}\n\n/**\n * Submits the signed bundle once, confirms it and applies the result rules\n * of `sendAndSettle`, on the first run and on a resume alike. A bundle lands\n * whole or not at all, so the first transaction's signature stands for it.\n */\nfunction sendSigned(\n context: SolanaStepExecutorContext,\n action: ExecutionAction,\n options: {\n transactions: Transaction[]\n signature: Signature\n lifetimes: TransactionLifetime[]\n /** An earlier run may already have submitted this bundle. */\n resuming: boolean\n }\n): Promise<TaskResult> {\n const { client, step, statusManager } = context\n const { transactions, signature, lifetimes, resuming } = options\n const txLink = getTxLink(context, signature)\n\n return sendAndSettle(context, action, {\n signature,\n send: async (): Promise<RaceResult<BundleConfirmation>> => {\n // Read right before the one submission: a bundle without its own\n // expiry goes out only inside the resend age cap. Past it nothing is\n // sent, and the outcome stays unknown until the dropped rule holds.\n if (!canResendStored(lifetimes, step.execution?.signedAt)) {\n return {\n kind: 'not-confirmed',\n errors: [\n new Error(\n 'The resend age cap has passed; the stored bundle is not sent.'\n ),\n ],\n }\n }\n // An empty Jito RPC list - the configuration gap, as opposed to an\n // outage - throws inside `sendAndConfirmBundle` with its own message,\n // before anything is submitted.\n return sendAndConfirmBundle(client, transactions, {\n onBroadcast: () => {\n // The earliest honest point for both: an RPC has accepted the\n // transaction, so the signature now resolves on chain.\n statusManager.updateAction(step, action.type, 'PENDING', {\n txHash: signature,\n txLink,\n })\n },\n })\n },\n confirmedFailure: bundleFailureOf,\n resuming,\n messages: MESSAGES,\n })\n}\n"],"mappings":";;;;;;;AA8BA,MAAM,WAAiC;CACrC,gBAAgB;CAChB,cAAc;CACd,eAAe;CACf,gBACE;AACJ;;;AAIA,SAAS,iBAAiB,KAAgD;CACxE,IAAI,OAAO,QAAQ,YAAY,QAAQ,QAAQ,EAAE,SAAS,MACxD;CAEF,OAAO,EAAE,SAAU,IAAyB,IAAI;AAClD;;;;AAKA,SAAS,gBACP,cAC8B;CAC9B,MAAM,gBAAgB,iBAAiB,aAAa,SAAS;CAC7D,IAAI,eACF,OAAO,EAAE,KAAK,cAAc,QAAQ;CAEtC,MAAM,eAAe,aAAa,iBAAiB,MAChD,oBAAoB,iBAAiB,GACxC;CACA,OAAO,cAAc,MAAM,EAAE,KAAK,aAAa,IAAI,IAAI,KAAA;AACzD;AAEA,IAAa,mCAAb,cAAsD,sBAAsB;CAC1E,MAAM,IAAI,SAAyD;EACjE,MAAM,EAAE,MAAM,eAAe,mBAAmB,uBAC9C;EAEF,MAAM,SAAS,cAAc,WAC3B,MACA,oBAAoB,gBAAgB,MACtC;EACA,IAAI,CAAC,QACH,MAAM,IAAI,iBACR,cAAc,uBACd,kDACF;EAKF,IAAI,CAAC,oBACH,OAAO,gBAAgB,SAAS,QAAQ;GACtC,UAAU;GAEV,OAAO,QAAQ,cACb,WAAW,SAAS,QAAQ;IAC1B,cAAc,OAAO;IACrB,WAAW,OAAO;IAClB;IACA,UAAU;GACZ,CAAC;EACL,CAAC;EAGH,IAAI,CAAC,mBAAmB,QACtB,MAAM,IAAI,iBACR,cAAc,uBACd,mEACF;EAGF,IAAI;EACJ,IAAI;GACF,cAAc,cAAc,mBAAmB,EAAE;EACnD,SAAS,OAAO;GAEd,wBAAwB,SAAS,MAAM;GACvC,MAAM;EACR;EAEA,MAAM,YAAY,MAAM,QAAQ,IAC9B,mBAAmB,KAAK,gBACtB,uBAAuB,WAAW,CACpC,CACF;EAEA,OAAO,WAAW,SAAS,QAAQ;GACjC,cAAc;GACd,WAAW;GACX;GACA,UAAU;EACZ,CAAC;CACH;AACF;;;;;;AAOA,SAAS,WACP,SACA,QACA,SAOqB;CACrB,MAAM,EAAE,QAAQ,MAAM,kBAAkB;CACxC,MAAM,EAAE,cAAc,WAAW,WAAW,aAAa;CACzD,MAAM,SAAS,UAAU,SAAS,SAAS;CAE3C,OAAO,cAAc,SAAS,QAAQ;EACpC;EACA,MAAM,YAAqD;GAIzD,IAAI,CAAC,gBAAgB,WAAW,KAAK,WAAW,QAAQ,GACtD,OAAO;IACL,MAAM;IACN,QAAQ,iBACN,IAAI,MACF,+DACF,CACF;GACF;GAKF,OAAO,qBAAqB,QAAQ,cAAc,EAChD,mBAAmB;IAGjB,cAAc,aAAa,MAAM,OAAO,MAAM,WAAW;KACvD,QAAQ;KACR;IACF,CAAC;GACH,EACF,CAAC;EACH;EACA,kBAAkB;EAClB;EACA,UAAU;CACZ,CAAC;AACH"}
1
+ {"version":3,"file":"SolanaJitoWaitForTransactionTask.js","names":[],"sources":["../../../../src/core/tasks/SolanaJitoWaitForTransactionTask.ts"],"sourcesContent":["import {\n BaseStepExecutionTask,\n type ExecutionAction,\n LiFiErrorCode,\n type TaskResult,\n TransactionError,\n} from '@lifi/sdk'\nimport type { Signature, Transaction } from '@solana/kit'\nimport { sendAndConfirmBundle } from '../../actions/sendAndConfirmBundle.js'\nimport type { BundleConfirmation } from '../../confirmation/confirmBundle.js'\nimport type { RaceResult } from '../../confirmation/raceRpcs.js'\nimport type { SolanaStepExecutorContext } from '../../types.js'\nimport {\n getTransactionLifetime,\n type TransactionLifetime,\n} from '../../utils/getTransactionLifetime.js'\nimport type { ConfirmationMessages } from './confirmationError.js'\nimport { readSignature } from './readSignature.js'\nimport { resumeFromStore } from './resumeFromStore.js'\nimport {\n canResendStored,\n clearStoredTransactions,\n failureOf,\n getTxLink,\n sendAndSettle,\n} from './transactionOutcome.js'\n\n// The `rpc-unavailable` message is distinct from the empty-list throw inside\n// `sendAndConfirmBundle`: RPCs were configured and every one of them failed.\n// Every read RPC confirms and waits for the one shared submission, so a\n// refused submission fails every branch with the same error.\nconst MESSAGES: ConfirmationMessages = {\n rpcUnavailable:\n 'Unable to confirm bundle: every configured Solana RPC failed.',\n notConfirmed: 'Bundle was not confirmed before the SDK stopped waiting.',\n allRpcsFailed: 'All Solana RPCs failed',\n someRpcsFailed:\n 'Some Solana RPCs failed while the confirmation window was open',\n}\n\n/** The failure of a landed bundle, if any: the first transaction `err`. */\nfunction bundleFailureOf(\n confirmation: BundleConfirmation\n): { err: unknown } | undefined {\n return confirmation.signatureResults.map(failureOf).find(Boolean)\n}\n\nexport class SolanaJitoWaitForTransactionTask extends BaseStepExecutionTask {\n async run(context: SolanaStepExecutorContext): Promise<TaskResult> {\n const { step, statusManager, isBridgeExecution, signedTransactions } =\n context\n\n const action = statusManager.findAction(\n step,\n isBridgeExecution ? 'CROSS_CHAIN' : 'SWAP'\n )\n if (!action) {\n throw new TransactionError(\n LiFiErrorCode.TransactionUnprepared,\n 'Unable to prepare transaction. Action not found.'\n )\n }\n\n // Resume mode: the sign task did not run in this session, so the signed\n // bundle comes from `txHex`, or only the first hash from `txHash`.\n if (!signedTransactions) {\n return resumeFromStore(context, action, {\n messages: MESSAGES,\n // Submitted once, as on the first run.\n send: (stored, lifetimes) =>\n sendSigned(context, action, {\n transactions: stored.transactions,\n signature: stored.signature,\n lifetimes,\n resuming: true,\n }),\n })\n }\n\n if (!signedTransactions.length) {\n throw new TransactionError(\n LiFiErrorCode.TransactionUnprepared,\n 'Unable to prepare transaction. Signed transactions are not found.'\n )\n }\n\n let txSignature: Signature\n try {\n txSignature = readSignature(signedTransactions[0])\n } catch (error) {\n // Nothing left the SDK: the bytes go, so \"Try again\" signs again.\n clearStoredTransactions(context, action)\n throw error\n }\n\n const lifetimes = await Promise.all(\n signedTransactions.map((transaction) =>\n getTransactionLifetime(transaction)\n )\n )\n\n return sendSigned(context, action, {\n transactions: signedTransactions,\n signature: txSignature,\n lifetimes,\n resuming: false,\n })\n }\n}\n\n/**\n * Submits the signed bundle once, confirms it and applies the result rules\n * of `sendAndSettle`, on the first run and on a resume alike. A Jito bundle\n * lands whole or not at all, so the first transaction's signature stands for\n * it. A sender that is not Jito can land the transactions one by one; a\n * lookup by the first signature then misses a partial landing.\n */\nfunction sendSigned(\n context: SolanaStepExecutorContext,\n action: ExecutionAction,\n options: {\n transactions: Transaction[]\n signature: Signature\n lifetimes: TransactionLifetime[]\n /** An earlier run may already have submitted this bundle. */\n resuming: boolean\n }\n): Promise<TaskResult> {\n const { client, step, statusManager } = context\n const { transactions, signature, lifetimes, resuming } = options\n const txLink = getTxLink(context, signature)\n\n return sendAndSettle(context, action, {\n signature,\n send: async (): Promise<RaceResult<BundleConfirmation>> => {\n // Read right before the one submission: a bundle without its own\n // expiry goes out only inside the resend age cap. Past it nothing is\n // sent, and the outcome stays unknown until the dropped rule holds.\n if (!canResendStored(lifetimes, step.execution?.signedAt)) {\n return {\n kind: 'not-confirmed',\n errors: [\n new Error(\n 'The resend age cap has passed; the stored bundle is not sent.'\n ),\n ],\n }\n }\n // An empty Jito RPC list - the configuration gap, as opposed to an\n // outage - throws inside `sendAndConfirmBundle` with its own message,\n // before anything is submitted.\n return sendAndConfirmBundle(client, transactions, {\n onBroadcast: () => {\n // The earliest honest point for both: an RPC has accepted the\n // transaction, so the signature now resolves on chain.\n statusManager.updateAction(step, action.type, 'PENDING', {\n txHash: signature,\n txLink,\n })\n },\n })\n },\n confirmedFailure: bundleFailureOf,\n resuming,\n messages: MESSAGES,\n })\n}\n"],"mappings":";;;;;;;AA+BA,MAAM,WAAiC;CACrC,gBACE;CACF,cAAc;CACd,eAAe;CACf,gBACE;AACJ;;AAGA,SAAS,gBACP,cAC8B;CAC9B,OAAO,aAAa,iBAAiB,IAAI,SAAS,CAAC,CAAC,KAAK,OAAO;AAClE;AAEA,IAAa,mCAAb,cAAsD,sBAAsB;CAC1E,MAAM,IAAI,SAAyD;EACjE,MAAM,EAAE,MAAM,eAAe,mBAAmB,uBAC9C;EAEF,MAAM,SAAS,cAAc,WAC3B,MACA,oBAAoB,gBAAgB,MACtC;EACA,IAAI,CAAC,QACH,MAAM,IAAI,iBACR,cAAc,uBACd,kDACF;EAKF,IAAI,CAAC,oBACH,OAAO,gBAAgB,SAAS,QAAQ;GACtC,UAAU;GAEV,OAAO,QAAQ,cACb,WAAW,SAAS,QAAQ;IAC1B,cAAc,OAAO;IACrB,WAAW,OAAO;IAClB;IACA,UAAU;GACZ,CAAC;EACL,CAAC;EAGH,IAAI,CAAC,mBAAmB,QACtB,MAAM,IAAI,iBACR,cAAc,uBACd,mEACF;EAGF,IAAI;EACJ,IAAI;GACF,cAAc,cAAc,mBAAmB,EAAE;EACnD,SAAS,OAAO;GAEd,wBAAwB,SAAS,MAAM;GACvC,MAAM;EACR;EAEA,MAAM,YAAY,MAAM,QAAQ,IAC9B,mBAAmB,KAAK,gBACtB,uBAAuB,WAAW,CACpC,CACF;EAEA,OAAO,WAAW,SAAS,QAAQ;GACjC,cAAc;GACd,WAAW;GACX;GACA,UAAU;EACZ,CAAC;CACH;AACF;;;;;;;;AASA,SAAS,WACP,SACA,QACA,SAOqB;CACrB,MAAM,EAAE,QAAQ,MAAM,kBAAkB;CACxC,MAAM,EAAE,cAAc,WAAW,WAAW,aAAa;CACzD,MAAM,SAAS,UAAU,SAAS,SAAS;CAE3C,OAAO,cAAc,SAAS,QAAQ;EACpC;EACA,MAAM,YAAqD;GAIzD,IAAI,CAAC,gBAAgB,WAAW,KAAK,WAAW,QAAQ,GACtD,OAAO;IACL,MAAM;IACN,QAAQ,iBACN,IAAI,MACF,+DACF,CACF;GACF;GAKF,OAAO,qBAAqB,QAAQ,cAAc,EAChD,mBAAmB;IAGjB,cAAc,aAAa,MAAM,OAAO,MAAM,WAAW;KACvD,QAAQ;KACR;IACF,CAAC;GACH,EACF,CAAC;EACH;EACA,kBAAkB;EAClB;EACA,UAAU;CACZ,CAAC;AACH"}
@@ -25,9 +25,10 @@ export declare const JITO_PROBE_RETRY_MS = 3e4;
25
25
  * pre-submission latency path twice a minute, forever. */
26
26
  export declare const JITO_PROBE_GATEWAY_RETRY_MS: number;
27
27
  /**
28
- * Probes with `getBundleStatuses` rather than `getTipAccounts`: it is the
29
- * method bundle confirmation actually uses, and providers such as Helius
30
- * support it without exposing `getTipAccounts`.
28
+ * Picks the RPCs that may submit a bundle; confirmation reads signatures on
29
+ * every read RPC. Probes with `getBundleStatuses` rather than
30
+ * `getTipAccounts`: providers such as Helius support it without exposing
31
+ * `getTipAccounts`.
31
32
  */
32
33
  export declare const probeJitoRpc: (rpcUrl: string) => Promise<JitoProbeResult>;
33
34
  /**
@@ -1 +1 @@
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"}
1
+ {"version":3,"file":"registry.d.ts","names":[],"sources":["../../../src/rpc/registry.ts"],"mappings":";;;;;YAyBY;;;;YAKA;EACV,SAAS;;EAET;;;;;qBAMW;;;;;;;;qBASA;;;;;;;qBA+EA,eACX,mBACC,QAAQ;;;;;qBAyHE,gBACX,QAAQ,cACP,QAAQ;;;;;;;;qBAWE,qBAAsB,sBAAoB;;;;;;qBAU1C,cACX,QAAQ,cACP;EAAU,MAAM;EAAe;;;;;;;;;;qBAarB,qBACX,sBACC;EAAU,MAAM;EAAe"}
@@ -70,9 +70,10 @@ const readProbeFailure = (error) => {
70
70
  */
71
71
  const PROBE_TIMEOUT_MS = 5e3;
72
72
  /**
73
- * Probes with `getBundleStatuses` rather than `getTipAccounts`: it is the
74
- * method bundle confirmation actually uses, and providers such as Helius
75
- * support it without exposing `getTipAccounts`.
73
+ * Picks the RPCs that may submit a bundle; confirmation reads signatures on
74
+ * every read RPC. Probes with `getBundleStatuses` rather than
75
+ * `getTipAccounts`: providers such as Helius support it without exposing
76
+ * `getTipAccounts`.
76
77
  */
77
78
  const probeJitoRpc = async (rpcUrl) => {
78
79
  const controller = new AbortController();
@@ -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\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":"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"}
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 * Picks the RPCs that may submit a bundle; confirmation reads signatures on\n * every read RPC. Probes with `getBundleStatuses` rather than\n * `getTipAccounts`: providers such as Helius support it without exposing\n * `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":"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"}
@@ -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.3.5";
3
+ export declare const version = "4.3.6";
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.3.5";
3
+ const version = "4.3.6";
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.3.5'\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.6'\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.3.5",
3
+ "version": "4.3.6",
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.12.0",
31
+ "@lifi/sdk": "4.12.1",
32
32
  "@solana/kit": "^8.4.0",
33
33
  "@solana/wallet-standard-features": "^1.5.0",
34
34
  "@wallet-standard/base": "^1.1.1"
@@ -1,18 +1,26 @@
1
1
  import { ChainId, LiFiErrorCode, RPCError, type SDKClient } from '@lifi/sdk'
2
- import { getBase64EncodedWireTransaction, type Transaction } from '@solana/kit'
2
+ import {
3
+ getBase64EncodedWireTransaction,
4
+ getSignatureFromTransaction,
5
+ type Transaction,
6
+ } from '@solana/kit'
3
7
  import {
4
8
  type BundleConfirmation,
5
9
  confirmBundle,
6
10
  } from '../confirmation/confirmBundle.js'
7
11
  import { BRANCH_TIMEOUT_MS } from '../confirmation/createConfirmationDeadline.js'
8
12
  import { type RaceResult, raceRpcs } from '../confirmation/raceRpcs.js'
9
- import { getJitoCapableRpcs, getJitoRpcs } from '../rpc/registry.js'
13
+ import {
14
+ getJitoCapableRpcs,
15
+ getJitoRpcs,
16
+ getSolanaRpcs,
17
+ } from '../rpc/registry.js'
10
18
  import type { JitoRpcType } from '../rpc/types.js'
11
19
  import { getTransactionLifetime } from '../utils/getTransactionLifetime.js'
12
20
 
13
21
  /**
14
- * Sends a Jito bundle to every Jito-capable RPC and returns as soon as one of
15
- * them confirms it.
22
+ * Sends a Jito bundle once and returns as soon as one read RPC sees every
23
+ * transaction of it confirmed.
16
24
  *
17
25
  * The deadline receives the lifetime of *every* signed transaction, not just
18
26
  * the first: a bundle is an array of independently built backend transactions
@@ -22,23 +30,24 @@ import { getTransactionLifetime } from '../utils/getTransactionLifetime.js'
22
30
  * deadline starts on the same clock as `BRANCH_TIMEOUT_MS` instead of after
23
31
  * the submission returns.
24
32
  *
25
- * When the client has Solana bundle or write RPCs (`rpcUrls[ChainId.SOL]`),
26
- * the bundle is submitted once through those that pass the Jito probe - the
27
- * bundle list first, else the write list - and the read Jito RPCs only poll.
28
- * With either list set, bundles never go to the read RPCs.
33
+ * The bundle is submitted once through the RPCs that pass the Jito probe: the
34
+ * bundle list of `rpcUrls[ChainId.SOL]` first, else the write list, else the
35
+ * read RPCs. With either list set, bundles never go to the read RPCs. Every
36
+ * read RPC confirms the bundle by its transaction signatures, so no read RPC
37
+ * needs Jito support and the `sendBundle` answer is not read.
29
38
  */
30
39
  export async function sendAndConfirmBundle(
31
40
  client: SDKClient,
32
41
  signedTransactions: Transaction[],
33
42
  options?: {
34
- /** Runs once, when the first Jito RPC accepts the submission. */
43
+ /** Runs once, when the first submit RPC accepts the submission. */
35
44
  onBroadcast?: () => void
36
45
  }
37
46
  ): Promise<RaceResult<BundleConfirmation>> {
38
47
  // With a bundle or write list set, bundles go only to those: the bundle
39
48
  // RPCs that pass the Jito probe, else the write RPCs that do. The write list
40
- // is probed only when it is needed. With neither list, each branch submits
41
- // through its own read Jito RPC, as before.
49
+ // is probed only when it is needed. With neither list, the read RPCs that
50
+ // pass the Jito probe submit.
42
51
  const [bundleUrls = [], writeUrls = []] = await Promise.all([
43
52
  client.getBundleRpcUrlsByChainId?.(ChainId.SOL),
44
53
  client.getWriteRpcUrlsByChainId?.(ChainId.SOL),
@@ -57,39 +66,32 @@ export async function sendAndConfirmBundle(
57
66
  unreachable: bundle.unreachable + write.unreachable,
58
67
  }
59
68
  }
60
- const [
61
- { rpcs: jitoRpcs, unreachable },
62
- { rpcs: submitRpcs, unreachable: submitUnreachable },
63
- ] = await Promise.all([getJitoRpcs(client), findSubmitRpcs()])
69
+ const hasSubmitLists = bundleUrls.length > 0 || writeUrls.length > 0
70
+ const [{ rpcs: submitRpcs, unreachable }, confirmRpcs] = await Promise.all([
71
+ hasSubmitLists ? findSubmitRpcs() : getJitoRpcs(client),
72
+ getSolanaRpcs(client),
73
+ ])
64
74
 
65
- if ((bundleUrls.length || writeUrls.length) && !submitRpcs.length) {
66
- const lists = [
67
- bundleUrls.length && '`rpcUrls[ChainId.SOL].bundle`',
68
- writeUrls.length && '`rpcUrls[ChainId.SOL].write`',
69
- ]
70
- .filter(Boolean)
75
+ if (hasSubmitLists && !submitRpcs.length) {
76
+ // Names only the lists that are set.
77
+ const lists = Object.entries({ bundle: bundleUrls, write: writeUrls })
78
+ .filter(([, urls]) => urls.length > 0)
79
+ .map(([name]) => `\`rpcUrls[ChainId.SOL].${name}\``)
71
80
  .join(' or ')
72
81
  throw new RPCError(
73
82
  LiFiErrorCode.RpcUnavailable,
74
83
  [
75
84
  `Jito bundle required, but no URL in ${lists} passed the Jito capability probe.`,
76
- submitUnreachable > 0
85
+ unreachable > 0
77
86
  ? '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.'
78
87
  : 'They do not support `sendBundle`: add a Jito-capable URL to `rpcUrls[ChainId.SOL].bundle`.',
79
88
  'Bundles never go to the read RPCs while `bundle` or `write` is set.',
80
- // Only a definite gap: a read RPC that did not answer the probe may
81
- // support bundles, and the next attempt reports that case itself.
82
- jitoRpcs.length === 0 &&
83
- unreachable === 0 &&
84
- 'No read RPC supports `getBundleStatuses` to confirm a bundle either: also add a Jito-capable URL to `rpcUrls[ChainId.SOL].read`.',
85
- ]
86
- .filter(Boolean)
87
- .join(' ')
89
+ ].join(' ')
88
90
  )
89
91
  }
90
92
 
91
- // Named here, where the emptiness is known: racing zero RPCs would surface
92
- // as a bare `rpc-unavailable`, indistinguishable from a total outage. The
93
+ // Named here, where the emptiness is known: submitting to zero RPCs would
94
+ // surface as a bare `rpc-unavailable`, indistinguishable from an outage. The
93
95
  // two causes get different messages - a configuration gap the integrator can
94
96
  // close, or endpoints that never answered.
95
97
  //
@@ -98,14 +100,12 @@ export async function sendAndConfirmBundle(
98
100
  // cannot tell a gated endpoint from a provider mid-deploy and classifies
99
101
  // both as `unreachable`. "Retry" alone would loop an integrator forever on a
100
102
  // gate no retry can clear.
101
- if (jitoRpcs.length === 0) {
103
+ if (!submitRpcs.length) {
102
104
  throw new RPCError(
103
105
  LiFiErrorCode.RpcUnavailable,
104
106
  unreachable > 0
105
107
  ? `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.`
106
- : submitRpcs.length > 0
107
- ? '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`.'
108
- : 'Jito bundle required, but no configured Solana RPC supports `sendBundle`. Supply a Jito-capable URL via the `rpcUrls` client config option.'
108
+ : 'Jito bundle required, but no configured Solana RPC supports `sendBundle`. Supply a Jito-capable URL via the `rpcUrls` client config option.'
109
109
  )
110
110
  }
111
111
 
@@ -134,6 +134,9 @@ export async function sendAndConfirmBundle(
134
134
  }
135
135
  }
136
136
 
137
+ const signatures = signedTransactions.map((transaction) =>
138
+ getSignatureFromTransaction(transaction)
139
+ )
137
140
  const serializedTransactions = signedTransactions.map((transaction) =>
138
141
  getBase64EncodedWireTransaction(transaction)
139
142
  )
@@ -142,11 +145,12 @@ export async function sendAndConfirmBundle(
142
145
  signedTransactions.map((transaction) => getTransactionLifetime(transaction))
143
146
  )
144
147
 
145
- // One submission for every polling branch: the bundle id is derived from
146
- // the transactions, so each branch polls the same bundle. Started by the
147
- // first branch that asks, so its deadline already runs.
148
- let submission: Promise<string> | undefined
149
- const submitOnce = (signal: AbortSignal): Promise<string> => {
148
+ // One submission for every confirming branch. Its answer is not read: the
149
+ // branches read the signatures, and senders answer `sendBundle` in different
150
+ // shapes. Started by the first branch that asks, so its deadline already
151
+ // runs.
152
+ let submission: Promise<unknown> | undefined
153
+ const submitOnce = (signal: AbortSignal): Promise<unknown> => {
150
154
  submission ??= Promise.any(
151
155
  submitRpcs.map((rpc) =>
152
156
  rpc.sendBundle(serializedTransactions).send({ abortSignal: signal })
@@ -160,18 +164,14 @@ export async function sendAndConfirmBundle(
160
164
  }
161
165
 
162
166
  return raceRpcs(
163
- jitoRpcs,
167
+ confirmRpcs,
164
168
  (rpc, signal) =>
165
169
  confirmBundle({
166
170
  rpc,
167
171
  signal,
172
+ signatures,
168
173
  lifetimes,
169
- send: () =>
170
- submitRpcs.length
171
- ? submitOnce(signal)
172
- : rpc
173
- .sendBundle(serializedTransactions)
174
- .send({ abortSignal: signal }),
174
+ send: () => submitOnce(signal),
175
175
  onBroadcast: reportBroadcast,
176
176
  }),
177
177
  { timeoutMs: BRANCH_TIMEOUT_MS }
@@ -1,5 +1,5 @@
1
1
  import type { Signature } from '@solana/kit'
2
- import type { JitoRpcType } from '../rpc/types.js'
2
+ import type { SolanaRpcType } from '../rpc/types.js'
3
3
  import type { TransactionLifetime } from '../utils/getTransactionLifetime.js'
4
4
  import { createConfirmationDeadline } from './createConfirmationDeadline.js'
5
5
  import { pollUntilDeadline } from './pollUntilDeadline.js'
@@ -9,47 +9,46 @@ import {
9
9
  type SignatureStatus,
10
10
  } from './types.js'
11
11
 
12
- /** Slower than the signature poller's 400 ms: Jito documents 1 req/s per IP
13
- * per region. At 2 s this holds 0.5 req/s, leaving room for the deadline's
14
- * blockhash probes on the same endpoint. */
12
+ /** Slower than the signature poller's 400 ms, to spend fewer requests: the
13
+ * bundle is never resent, so a slower read delays only the verdict, by 2 s at
14
+ * most. `STATUS_RETRY_BACKOFF_CAP_MS` is set against this value. */
15
15
  export const BUNDLE_POLL_INTERVAL_MS = 2_000
16
16
 
17
17
  export type BundleConfirmation = {
18
- /** The submission's own id, carried for diagnostics. */
19
- bundleId: string
20
- /** Never read for a `txHash` - its order is Jito's to choose. Kept so the
21
- * reversed-list regression stays expressible in the wait-task spec. */
22
- txSignatures: Signature[]
23
- signatureResults: readonly (SignatureStatus | null)[]
24
- /** Bundle-level `err`, verbatim. Jito encodes it as a Rust `Result`, so a
25
- * landed bundle carries `{ Ok: null }` - never truthiness-check it. */
26
- bundleErr: unknown
18
+ /** One confirmed status per bundle transaction, in bundle order. */
19
+ signatureResults: readonly SignatureStatus[]
27
20
  }
28
21
 
29
22
  /**
30
- * Confirms one Jito bundle against one Jito RPC.
23
+ * Confirms one Jito bundle against one RPC, by the signatures of its
24
+ * transactions. Every Solana RPC can read them, and a bundle lands whole in
25
+ * one slot, so one read shows all of them confirmed.
31
26
  *
32
27
  * Bundles submit once, so there is no resend loop. `send` is owned here so the
33
28
  * deadline starts before submission rather than after it. A `send` failure
34
29
  * throws, which `raceRpcs` buckets as `rpc-unavailable`.
35
30
  */
36
31
  export async function confirmBundle(options: {
37
- rpc: JitoRpcType
32
+ rpc: SolanaRpcType
38
33
  signal: AbortSignal
34
+ /** The signatures of the bundle's transactions, in bundle order. */
35
+ signatures: Signature[]
39
36
  lifetimes: TransactionLifetime[]
40
- send: () => Promise<string>
37
+ /** Its answer is not read: senders answer `sendBundle` in different
38
+ * shapes, and the signatures are known before the send. */
39
+ send: () => Promise<unknown>
41
40
  /**
42
- * Reports that this RPC accepted the bundle submission. Must not throw -
41
+ * Reports that the shared submission was accepted. Must not throw -
43
42
  * `sendAndConfirmBundle` contains any throw from the integrator callback it
44
- * wraps, because a throw here would reject a branch whose bundle Jito had
45
- * already accepted.
43
+ * wraps, because a throw here would reject a branch whose bundle a submit
44
+ * RPC had already accepted.
46
45
  */
47
46
  onBroadcast?: () => void
48
47
  }): Promise<ConfirmationOutcome<BundleConfirmation>> {
49
- const { rpc, signal, lifetimes, send } = options
48
+ const { rpc, signal, signatures, lifetimes, send } = options
50
49
  const deadline = createConfirmationDeadline({ lifetimes, rpc })
51
50
 
52
- const bundleId = await send()
51
+ await send()
53
52
  // Guarded like `confirmSignature`'s send sites: the caller's once-guard
54
53
  // latches only after the callback returns, so a throwing integrator hook
55
54
  // leaves it open and a late `sendBundle` fulfilment would re-write a
@@ -59,55 +58,21 @@ export async function confirmBundle(options: {
59
58
  }
60
59
 
61
60
  const readBundle = async (): Promise<BundleConfirmation | null> => {
62
- const statusResponse = await rpc
63
- .getBundleStatuses([bundleId])
61
+ const response = await rpc
62
+ .getSignatureStatuses(signatures)
64
63
  .send({ abortSignal: signal })
65
- // A `{ value: null }` answer responded but said nothing - poll again
66
- // rather than throw a `TypeError` into the read-failure budget.
67
- const bundleStatus = statusResponse?.value?.[0]
68
- if (
69
- !bundleStatus ||
70
- !isConfirmedCommitment(bundleStatus.confirmation_status)
71
- ) {
72
- return null
73
- }
74
-
75
- // Unvalidated wire data: without this guard a confirmed status carrying
76
- // no `transactions` makes every `.map` below a `TypeError`, and a landed
77
- // bundle would report as `rpc-unavailable`.
78
- // `Array.isArray`, not `??`: the wire data is unvalidated, and a truthy
79
- // non-array keeps the declared array type while throwing out of `.map`.
80
- const txSignatures = Array.isArray(bundleStatus.transactions)
81
- ? bundleStatus.transactions
82
- : []
83
-
84
- // The bundle status is the atomic fact: a bundle lands whole or not at
85
- // all. `getSignatureStatuses` only enriches it with per-transaction `err`
86
- // detail, so an unusable response degrades to all-`null` and must never
87
- // veto a confirmation the status already made.
88
- let signatureResults: BundleConfirmation['signatureResults']
89
- if (txSignatures.length === 0) {
90
- // Nothing to enrich; the status already confirmed the bundle.
91
- signatureResults = []
92
- } else {
93
- try {
94
- const sigResponse = await rpc
95
- .getSignatureStatuses(txSignatures)
96
- .send({ abortSignal: signal })
97
- signatureResults = Array.isArray(sigResponse?.value)
98
- ? sigResponse.value
99
- : txSignatures.map(() => null)
100
- } catch (_) {
101
- signatureResults = txSignatures.map(() => null)
102
- }
103
- }
104
-
105
- return {
106
- bundleId,
107
- txSignatures,
108
- signatureResults,
109
- bundleErr: bundleStatus.err,
110
- }
64
+ // A `{ value: null }`, non-array or short answer responded but said
65
+ // nothing - poll again rather than throw a `TypeError` into the
66
+ // read-failure budget.
67
+ const statuses = response?.value
68
+ return Array.isArray(statuses) &&
69
+ statuses.length === signatures.length &&
70
+ statuses.every(
71
+ (status: SignatureStatus | null): status is SignatureStatus =>
72
+ isConfirmedCommitment(status?.confirmationStatus)
73
+ )
74
+ ? { signatureResults: statuses }
75
+ : null
111
76
  }
112
77
 
113
78
  return pollUntilDeadline({
@@ -14,8 +14,8 @@ import {
14
14
  export const RESEND_INTERVAL_MS = 1000
15
15
  /**
16
16
  * How often this poller re-reads `getSignatureStatuses`. The default Solana
17
- * RPCs tolerate 2.5 req/s of status reads; the Jito bundle poller runs slower
18
- * because its endpoints do not (see `confirmBundle`).
17
+ * RPCs tolerate 2.5 req/s of status reads; the bundle poller runs slower
18
+ * (see `confirmBundle`).
19
19
  */
20
20
  export const SIGNATURE_POLL_INTERVAL_MS = 400
21
21
 
@@ -29,7 +29,7 @@ export const EXPIRY_CONFIRMATIONS: number =
29
29
  * Prober-only; the status pollers have `MAX_STATUS_READ_SILENCE_MS`. */
30
30
  export const MAX_PROBE_ERRORS = 5
31
31
 
32
- /** Structural, so one implementation serves both the Solana and Jito RPC. */
32
+ /** Structural: the deadline needs nothing but `isBlockhashValid`. */
33
33
  export type BlockhashProbeRpc = Pick<SolanaRpcType, 'isBlockhashValid'>
34
34
 
35
35
  export interface ConfirmationDeadline {
@@ -6,7 +6,7 @@ type SignatureStatusesResponse = Awaited<
6
6
  >
7
7
 
8
8
  /** Derived from the RPC type rather than hand-written, which removes every
9
- * `as SignatureStatus` cast. A `JitoRpcType` response assigns without one. */
9
+ * `as SignatureStatus` cast. */
10
10
  export type SignatureStatus = NonNullable<
11
11
  SignatureStatusesResponse['value'][number]
12
12
  >