@lifi/sdk-provider-solana 4.3.5 → 4.3.7

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 (70) hide show
  1. package/CHANGELOG.md +14 -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 +1 -1
  13. package/dist/cjs/confirmation/createConfirmationDeadline.js.map +1 -1
  14. package/dist/cjs/confirmation/types.d.ts +2 -1
  15. package/dist/cjs/confirmation/types.js.map +1 -1
  16. package/dist/cjs/core/tasks/SolanaJitoWaitForTransactionTask.js +9 -18
  17. package/dist/cjs/core/tasks/SolanaJitoWaitForTransactionTask.js.map +1 -1
  18. package/dist/cjs/rpc/jito/api/getBundleStatuses.d.ts +1 -0
  19. package/dist/cjs/rpc/jito/api/getTipAccounts.d.ts +1 -0
  20. package/dist/cjs/rpc/jito/api/sendBundle.d.ts +1 -0
  21. package/dist/cjs/rpc/jito/api/simulateBundle.d.ts +1 -0
  22. package/dist/cjs/rpc/registry.d.ts +4 -3
  23. package/dist/cjs/rpc/registry.js +4 -3
  24. package/dist/cjs/rpc/registry.js.map +1 -1
  25. package/dist/cjs/rpc/utils.d.ts +1 -0
  26. package/dist/cjs/utils/getWalletFeature.d.ts +1 -0
  27. package/dist/cjs/version.d.ts +1 -1
  28. package/dist/cjs/version.js +1 -1
  29. package/dist/cjs/version.js.map +1 -1
  30. package/dist/esm/actions/sendAndConfirmBundle.d.ts +8 -7
  31. package/dist/esm/actions/sendAndConfirmBundle.d.ts.map +1 -1
  32. package/dist/esm/actions/sendAndConfirmBundle.js +24 -18
  33. package/dist/esm/actions/sendAndConfirmBundle.js.map +1 -1
  34. package/dist/esm/confirmation/confirmBundle.d.ts +18 -19
  35. package/dist/esm/confirmation/confirmBundle.d.ts.map +1 -1
  36. package/dist/esm/confirmation/confirmBundle.js +10 -23
  37. package/dist/esm/confirmation/confirmBundle.js.map +1 -1
  38. package/dist/esm/confirmation/confirmSignature.d.ts +2 -2
  39. package/dist/esm/confirmation/confirmSignature.js +2 -2
  40. package/dist/esm/confirmation/confirmSignature.js.map +1 -1
  41. package/dist/esm/confirmation/createConfirmationDeadline.d.ts +1 -1
  42. package/dist/esm/confirmation/createConfirmationDeadline.js +1 -1
  43. package/dist/esm/confirmation/createConfirmationDeadline.js.map +1 -1
  44. package/dist/esm/confirmation/types.d.ts +2 -1
  45. package/dist/esm/confirmation/types.js.map +1 -1
  46. package/dist/esm/core/tasks/SolanaJitoWaitForTransactionTask.d.ts.map +1 -1
  47. package/dist/esm/core/tasks/SolanaJitoWaitForTransactionTask.js +10 -19
  48. package/dist/esm/core/tasks/SolanaJitoWaitForTransactionTask.js.map +1 -1
  49. package/dist/esm/rpc/jito/api/getBundleStatuses.d.ts +1 -0
  50. package/dist/esm/rpc/jito/api/getTipAccounts.d.ts +1 -0
  51. package/dist/esm/rpc/jito/api/sendBundle.d.ts +1 -0
  52. package/dist/esm/rpc/jito/api/simulateBundle.d.ts +1 -0
  53. package/dist/esm/rpc/registry.d.ts +4 -3
  54. package/dist/esm/rpc/registry.d.ts.map +1 -1
  55. package/dist/esm/rpc/registry.js +4 -3
  56. package/dist/esm/rpc/registry.js.map +1 -1
  57. package/dist/esm/rpc/utils.d.ts +1 -0
  58. package/dist/esm/utils/getWalletFeature.d.ts +1 -0
  59. package/dist/esm/version.d.ts +1 -1
  60. package/dist/esm/version.js +1 -1
  61. package/dist/esm/version.js.map +1 -1
  62. package/package.json +3 -3
  63. package/src/actions/sendAndConfirmBundle.ts +48 -48
  64. package/src/confirmation/confirmBundle.ts +34 -69
  65. package/src/confirmation/confirmSignature.ts +2 -2
  66. package/src/confirmation/createConfirmationDeadline.ts +1 -1
  67. package/src/confirmation/types.ts +1 -1
  68. package/src/core/tasks/SolanaJitoWaitForTransactionTask.ts +13 -27
  69. package/src/rpc/registry.ts +4 -3
  70. package/src/version.ts +1 -1
@@ -1 +1 @@
1
- {"version":3,"file":"createConfirmationDeadline.js","names":[],"sources":["../../../src/confirmation/createConfirmationDeadline.ts"],"sourcesContent":["import type { Blockhash } from '@solana/kit'\nimport type { SolanaRpcType } from '../rpc/types.js'\nimport type { TransactionLifetime } from '../utils/getTransactionLifetime.js'\n\n/** Give-up point for a branch's polling. Read between iterations only, so a\n * hung RPC call needs `BRANCH_TIMEOUT_MS` to close the gap. */\nexport const CONFIRMATION_TIMEOUT_MS = 90_000\n/** Head-room for the final probe after the deadline.\n * `STATUS_RETRY_BACKOFF_CAP_MS` must stay below it. */\nexport const FINAL_PROBE_MARGIN_MS = 5_000\n/** Hard bound on a branch, in-flight requests included. Above the ceiling so\n * an abort cannot pre-empt the final probe. */\nexport const BRANCH_TIMEOUT_MS: number =\n CONFIRMATION_TIMEOUT_MS + FINAL_PROBE_MARGIN_MS\n/** How long a healthy-but-lagging node may need to catch up. A premise, not a\n * knob: `isBlockhashValid` answers `false` for lag and for death alike, so no\n * verdict may land inside this window. */\nexport const NODE_LAG_WINDOW_MS = 12_000\n/** Gap between `isBlockhashValid` probes. Spacing them is what makes the\n * consecutive-`false` rule meaningful: quantized to the 400 ms tick, probes\n * land at 0.4/7.6/14.8 s, so no verdict lands inside `NODE_LAG_WINDOW_MS`. */\nexport const EXPIRY_PROBE_INTERVAL_MS = 7_000\n/** Consecutive `false` results before a blockhash is believed dead. Derived so\n * a change to either premise moves it automatically; `+ 2` keeps the\n * inequality strict when the window divides exactly. */\nexport const EXPIRY_CONFIRMATIONS: number =\n Math.floor(NODE_LAG_WINDOW_MS / EXPIRY_PROBE_INTERVAL_MS) + 2\n/** Probe failures per blockhash before that blockhash stops being probed.\n * Prober-only; the status pollers have `MAX_STATUS_READ_SILENCE_MS`. */\nexport const MAX_PROBE_ERRORS = 5\n\n/** Structural, so one implementation serves both the Solana and Jito RPC. */\nexport type BlockhashProbeRpc = Pick<SolanaRpcType, 'isBlockhashValid'>\n\nexport interface ConfirmationDeadline {\n /** Checked at the top of every poll iteration. */\n reached(): boolean\n /** The slot at which the blockhash probe confirmed expiry - the highest\n * `context.slot` of the `false` answers in the streak - or `undefined`\n * without a verdict. Tells the two reasons `reached()` fires apart: a dead\n * blockhash may later count as \"dropped\", the wall-clock ceiling never\n * does. */\n expiredAt(): bigint | undefined\n /** Advances the policy; never throws. Probes at most once per\n * `EXPIRY_PROBE_INTERVAL_MS`. */\n tick(signal: AbortSignal): Promise<void>\n}\n\n/**\n * Owns every \"should I stop polling?\" decision.\n *\n * Never reads `getBlockHeight`: at least one default LI.FI RPC answers it with\n * the slot number, making any `lastValidBlockHeight` comparison false on its\n * first evaluation.\n */\nexport function createConfirmationDeadline(options: {\n lifetimes: TransactionLifetime[]\n rpc: BlockhashProbeRpc\n now?: () => number\n}): ConfirmationDeadline {\n const { lifetimes, rpc } = options\n const now = options.now ?? Date.now\n const startedAt = now()\n\n const blockhashLifetimes = lifetimes.filter(\n (\n lifetime\n ): lifetime is Extract<TransactionLifetime, { kind: 'blockhash' }> =>\n lifetime.kind === 'blockhash'\n )\n // A single non-blockhash lifetime disables the early exit for the whole set:\n // we cannot know when such a transaction stops being landable.\n const allProbeable =\n lifetimes.length > 0 && blockhashLifetimes.length === lifetimes.length\n const blockhashes: Blockhash[] = allProbeable\n ? [...new Set(blockhashLifetimes.map((lifetime) => lifetime.blockhash))]\n : []\n\n // Keyed by blockhash: expiry is a property of a blockhash, not of the set.\n const expiredStreaks = new Map<Blockhash, number>()\n // The highest `context.slot` of each blockhash's current `false` streak:\n // where a dropped check has to find a node's head before it trusts a\n // `null`. A reset of the streak deletes it.\n const expiredSlots = new Map<Blockhash, bigint>()\n // Keyed for the same reason: a sibling's broken probe is not evidence about\n // this blockhash, so it must not spend this blockhash's error budget.\n const errorStreaks = new Map<Blockhash, number>()\n // The blockhashes still worth asking about. One leaves this set after\n // MAX_PROBE_ERRORS failures of its own; the others keep being probed.\n const probeable = new Set<Blockhash>(blockhashes)\n let lastProbeAt: number | undefined\n\n /** Derived, not latched: a blockhash that reads valid again zeroes its\n * streak and clears the verdict with it. The highest slot among the expired\n * blockhashes is the strictest head bound. */\n const expiredAt = (): bigint | undefined => {\n let slot: bigint | undefined\n for (const [blockhash, streak] of expiredStreaks) {\n const observedAt = expiredSlots.get(blockhash)\n if (\n streak >= EXPIRY_CONFIRMATIONS &&\n observedAt !== undefined &&\n (slot === undefined || observedAt > slot)\n ) {\n slot = observedAt\n }\n }\n return slot\n }\n\n return {\n reached(): boolean {\n const elapsed = now() - startedAt\n if (elapsed >= CONFIRMATION_TIMEOUT_MS) {\n return true\n }\n return expiredAt() !== undefined\n },\n expiredAt,\n async tick(signal: AbortSignal): Promise<void> {\n if (probeable.size === 0 || signal.aborted) {\n return\n }\n // The cadence is wall-clock, not iteration count, and it uses the\n // injected `now` so the policy stays testable without timers.\n const probeAt = now()\n if (\n lastProbeAt !== undefined &&\n probeAt - lastProbeAt < EXPIRY_PROBE_INTERVAL_MS\n ) {\n return\n }\n lastProbeAt = probeAt\n // `allSettled`, not `all`: `all` rejects on the first failure and\n // discards answers the other probes already produced. All state is keyed\n // by blockhash, so one broken probe cannot disable the early exit for\n // the rest.\n const active = [...probeable]\n const probes = await Promise.allSettled(\n active.map(async (blockhash) => {\n const result = await rpc\n .isBlockhashValid(blockhash, { commitment: 'confirmed' })\n .send({ abortSignal: signal })\n return { value: result?.value, slot: result?.context?.slot }\n })\n )\n\n // A read that produced no usable answer says nothing about this\n // blockhash: it must never spend the expiry streak, only the error\n // budget. Shared by a rejected probe and by a fulfilled one whose\n // response carried no usable verdict.\n const recordFailedProbe = (blockhash: Blockhash): void => {\n expiredStreaks.set(blockhash, 0)\n expiredSlots.delete(blockhash)\n const errors = (errorStreaks.get(blockhash) ?? 0) + 1\n errorStreaks.set(blockhash, errors)\n if (errors >= MAX_PROBE_ERRORS) {\n // Degrade to ceiling-only for this blockhash.\n probeable.delete(blockhash)\n }\n }\n\n probes.forEach((probe, index) => {\n const blockhash = active[index]\n\n if (probe.status === 'rejected') {\n recordFailedProbe(blockhash)\n return\n }\n\n const { value, slot } = probe.value\n\n // `=== true` / `=== false`, never truthiness: a response carrying no\n // `value` is not a `false`, and reading it as one is the only coercion\n // here that can invent an expiry.\n if (value === true) {\n errorStreaks.set(blockhash, 0)\n expiredStreaks.set(blockhash, 0)\n expiredSlots.delete(blockhash)\n return\n }\n\n // A `false` counts only with the slot it was observed at: a verdict\n // without one could not bound the head of the dropped check.\n if (value === false && typeof slot === 'bigint') {\n errorStreaks.set(blockhash, 0)\n expiredStreaks.set(\n blockhash,\n (expiredStreaks.get(blockhash) ?? 0) + 1\n )\n // The highest slot, not the latest: a `false` from a node whose head\n // is behind the others must not lower the bound below the slots\n // where the transaction can still land.\n const previous = expiredSlots.get(blockhash)\n expiredSlots.set(\n blockhash,\n previous === undefined || slot > previous ? slot : previous\n )\n return\n }\n\n recordFailedProbe(blockhash)\n })\n },\n }\n}\n"],"mappings":";;;AAMA,MAAa,0BAA0B;;;AAGvC,MAAa,wBAAwB;;;AAGrC,MAAa,oBACX;;;;AAIF,MAAa,qBAAqB;;;;AAIlC,MAAa,2BAA2B;;;;AAIxC,MAAa,uBACX,KAAK,MAAM,qBAAqB,wBAAwB,IAAI;;;AAG9D,MAAa,mBAAmB;;;;;;;;AA0BhC,SAAgB,2BAA2B,SAIlB;CACvB,MAAM,EAAE,WAAW,QAAQ;CAC3B,MAAM,MAAM,QAAQ,OAAO,KAAK;CAChC,MAA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MAAM,UAAU,aAAa,IAAI,SAAS,KAAK,KAAK;IACpD,aAAa,IAAI,WAAW,MAAM;IAClC,IAAI,UAAA,GAEF,UAAU,OAAO,SAAS;GAE9B;GAEA,OAAO,SAAS,OAAO,UAAU;IAC/B,MAAM,YAAY,OAAO;IAEzB,IAAI,MAAM,WAAW,YAAY;KAC/B,kBAAkB,SAAS;KAC3B;IACF;IAEA,MAAM,EAAE,OAAO,SAAS,MAAM;IAK9B,IAAI,UAAU,MAAM;KAClB,aAAa,IAAI,WAAW,CAAC;KAC7B,eAAe,IAAI,WAAW,CAAC;KAC/B,aAAa,OAAO,SAAS;KAC7B;IACF;IAIA,IAAI,UAAU,SAAS,OAAO,SAAS,UAAU;KAC/C,aAAa,IAAI,WAAW,CAAC;KAC7B,eAAe,IACb,YACC,eAAe,IAAI,SAAS,KAAK,KAAK,CACzC;KAIA,MAAM,WAAW,aAAa,IAAI,SAAS;KAC3C,aAAa,IACX,WACA,aAAa,KAAA,KAAa,OAAO,WAAW,OAAO,QACrD;KACA;IACF;IAEA,kBAAkB,SAAS;GAC7B,CAAC;EACH;CACF;AACF"}
1
+ {"version":3,"file":"createConfirmationDeadline.js","names":[],"sources":["../../../src/confirmation/createConfirmationDeadline.ts"],"sourcesContent":["import type { Blockhash } from '@solana/kit'\nimport type { SolanaRpcType } from '../rpc/types.js'\nimport type { TransactionLifetime } from '../utils/getTransactionLifetime.js'\n\n/** Give-up point for a branch's polling. Read between iterations only, so a\n * hung RPC call needs `BRANCH_TIMEOUT_MS` to close the gap. */\nexport const CONFIRMATION_TIMEOUT_MS = 90_000\n/** Head-room for the final probe after the deadline.\n * `STATUS_RETRY_BACKOFF_CAP_MS` must stay below it. */\nexport const FINAL_PROBE_MARGIN_MS = 5_000\n/** Hard bound on a branch, in-flight requests included. Above the ceiling so\n * an abort cannot pre-empt the final probe. */\nexport const BRANCH_TIMEOUT_MS: number =\n CONFIRMATION_TIMEOUT_MS + FINAL_PROBE_MARGIN_MS\n/** How long a healthy-but-lagging node may need to catch up. A premise, not a\n * knob: `isBlockhashValid` answers `false` for lag and for death alike, so no\n * verdict may land inside this window. */\nexport const NODE_LAG_WINDOW_MS = 12_000\n/** Gap between `isBlockhashValid` probes. Spacing them is what makes the\n * consecutive-`false` rule meaningful: quantized to the 400 ms tick, probes\n * land at 0.4/7.6/14.8 s, so no verdict lands inside `NODE_LAG_WINDOW_MS`. */\nexport const EXPIRY_PROBE_INTERVAL_MS = 7_000\n/** Consecutive `false` results before a blockhash is believed dead. Derived so\n * a change to either premise moves it automatically; `+ 2` keeps the\n * inequality strict when the window divides exactly. */\nexport const EXPIRY_CONFIRMATIONS: number =\n Math.floor(NODE_LAG_WINDOW_MS / EXPIRY_PROBE_INTERVAL_MS) + 2\n/** Probe failures per blockhash before that blockhash stops being probed.\n * Prober-only; the status pollers have `MAX_STATUS_READ_SILENCE_MS`. */\nexport const MAX_PROBE_ERRORS = 5\n\n/** Structural: the deadline needs nothing but `isBlockhashValid`. */\nexport type BlockhashProbeRpc = Pick<SolanaRpcType, 'isBlockhashValid'>\n\nexport interface ConfirmationDeadline {\n /** Checked at the top of every poll iteration. */\n reached(): boolean\n /** The slot at which the blockhash probe confirmed expiry - the highest\n * `context.slot` of the `false` answers in the streak - or `undefined`\n * without a verdict. Tells the two reasons `reached()` fires apart: a dead\n * blockhash may later count as \"dropped\", the wall-clock ceiling never\n * does. */\n expiredAt(): bigint | undefined\n /** Advances the policy; never throws. Probes at most once per\n * `EXPIRY_PROBE_INTERVAL_MS`. */\n tick(signal: AbortSignal): Promise<void>\n}\n\n/**\n * Owns every \"should I stop polling?\" decision.\n *\n * Never reads `getBlockHeight`: at least one default LI.FI RPC answers it with\n * the slot number, making any `lastValidBlockHeight` comparison false on its\n * first evaluation.\n */\nexport function createConfirmationDeadline(options: {\n lifetimes: TransactionLifetime[]\n rpc: BlockhashProbeRpc\n now?: () => number\n}): ConfirmationDeadline {\n const { lifetimes, rpc } = options\n const now = options.now ?? Date.now\n const startedAt = now()\n\n const blockhashLifetimes = lifetimes.filter(\n (\n lifetime\n ): lifetime is Extract<TransactionLifetime, { kind: 'blockhash' }> =>\n lifetime.kind === 'blockhash'\n )\n // A single non-blockhash lifetime disables the early exit for the whole set:\n // we cannot know when such a transaction stops being landable.\n const allProbeable =\n lifetimes.length > 0 && blockhashLifetimes.length === lifetimes.length\n const blockhashes: Blockhash[] = allProbeable\n ? [...new Set(blockhashLifetimes.map((lifetime) => lifetime.blockhash))]\n : []\n\n // Keyed by blockhash: expiry is a property of a blockhash, not of the set.\n const expiredStreaks = new Map<Blockhash, number>()\n // The highest `context.slot` of each blockhash's current `false` streak:\n // where a dropped check has to find a node's head before it trusts a\n // `null`. A reset of the streak deletes it.\n const expiredSlots = new Map<Blockhash, bigint>()\n // Keyed for the same reason: a sibling's broken probe is not evidence about\n // this blockhash, so it must not spend this blockhash's error budget.\n const errorStreaks = new Map<Blockhash, number>()\n // The blockhashes still worth asking about. One leaves this set after\n // MAX_PROBE_ERRORS failures of its own; the others keep being probed.\n const probeable = new Set<Blockhash>(blockhashes)\n let lastProbeAt: number | undefined\n\n /** Derived, not latched: a blockhash that reads valid again zeroes its\n * streak and clears the verdict with it. The highest slot among the expired\n * blockhashes is the strictest head bound. */\n const expiredAt = (): bigint | undefined => {\n let slot: bigint | undefined\n for (const [blockhash, streak] of expiredStreaks) {\n const observedAt = expiredSlots.get(blockhash)\n if (\n streak >= EXPIRY_CONFIRMATIONS &&\n observedAt !== undefined &&\n (slot === undefined || observedAt > slot)\n ) {\n slot = observedAt\n }\n }\n return slot\n }\n\n return {\n reached(): boolean {\n const elapsed = now() - startedAt\n if (elapsed >= CONFIRMATION_TIMEOUT_MS) {\n return true\n }\n return expiredAt() !== undefined\n },\n expiredAt,\n async tick(signal: AbortSignal): Promise<void> {\n if (probeable.size === 0 || signal.aborted) {\n return\n }\n // The cadence is wall-clock, not iteration count, and it uses the\n // injected `now` so the policy stays testable without timers.\n const probeAt = now()\n if (\n lastProbeAt !== undefined &&\n probeAt - lastProbeAt < EXPIRY_PROBE_INTERVAL_MS\n ) {\n return\n }\n lastProbeAt = probeAt\n // `allSettled`, not `all`: `all` rejects on the first failure and\n // discards answers the other probes already produced. All state is keyed\n // by blockhash, so one broken probe cannot disable the early exit for\n // the rest.\n const active = [...probeable]\n const probes = await Promise.allSettled(\n active.map(async (blockhash) => {\n const result = await rpc\n .isBlockhashValid(blockhash, { commitment: 'confirmed' })\n .send({ abortSignal: signal })\n return { value: result?.value, slot: result?.context?.slot }\n })\n )\n\n // A read that produced no usable answer says nothing about this\n // blockhash: it must never spend the expiry streak, only the error\n // budget. Shared by a rejected probe and by a fulfilled one whose\n // response carried no usable verdict.\n const recordFailedProbe = (blockhash: Blockhash): void => {\n expiredStreaks.set(blockhash, 0)\n expiredSlots.delete(blockhash)\n const errors = (errorStreaks.get(blockhash) ?? 0) + 1\n errorStreaks.set(blockhash, errors)\n if (errors >= MAX_PROBE_ERRORS) {\n // Degrade to ceiling-only for this blockhash.\n probeable.delete(blockhash)\n }\n }\n\n probes.forEach((probe, index) => {\n const blockhash = active[index]\n\n if (probe.status === 'rejected') {\n recordFailedProbe(blockhash)\n return\n }\n\n const { value, slot } = probe.value\n\n // `=== true` / `=== false`, never truthiness: a response carrying no\n // `value` is not a `false`, and reading it as one is the only coercion\n // here that can invent an expiry.\n if (value === true) {\n errorStreaks.set(blockhash, 0)\n expiredStreaks.set(blockhash, 0)\n expiredSlots.delete(blockhash)\n return\n }\n\n // A `false` counts only with the slot it was observed at: a verdict\n // without one could not bound the head of the dropped check.\n if (value === false && typeof slot === 'bigint') {\n errorStreaks.set(blockhash, 0)\n expiredStreaks.set(\n blockhash,\n (expiredStreaks.get(blockhash) ?? 0) + 1\n )\n // The highest slot, not the latest: a `false` from a node whose head\n // is behind the others must not lower the bound below the slots\n // where the transaction can still land.\n const previous = expiredSlots.get(blockhash)\n expiredSlots.set(\n blockhash,\n previous === undefined || slot > previous ? slot : previous\n )\n return\n }\n\n recordFailedProbe(blockhash)\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B,MAAM,SAAS,MAAM,QAAQ,WAC3B,OAAO,IAAI,OAAO,cAAc;IAC9B,MAAM,SAAS,MAAM,IAClB,iBAAiB,WAAW,EAAE,YAAY,YAAY,CAAC,CAAC,CACxD,KAAK,EAAE,aAAa,OAAO,CAAC;IAC/B,OAAO;KAAE,OAAO,QAAQ;KAAO,MAAM,QAAQ,SAAS;IAAK;GAC7D,CAAC,CACH;GAMA,MAAM,qBAAqB,cAA+B;IACxD,eAAe,IAAI,WAAW,CAAC;IAC/B,aAAa,OAAO,SAAS;IAC7B,MAAM,UAAU,aAAa,IAAI,SAAS,KAAK,KAAK;IACpD,aAAa,IAAI,WAAW,MAAM;IAClC,IAAI,UAAA,GAEF,UAAU,OAAO,SAAS;GAE9B;GAEA,OAAO,SAAS,OAAO,UAAU;IAC/B,MAAM,YAAY,OAAO;IAEzB,IAAI,MAAM,WAAW,YAAY;KAC/B,kBAAkB,SAAS;KAC3B;IACF;IAEA,MAAM,EAAE,OAAO,SAAS,MAAM;IAK9B,IAAI,UAAU,MAAM;KAClB,aAAa,IAAI,WAAW,CAAC;KAC7B,eAAe,IAAI,WAAW,CAAC;KAC/B,aAAa,OAAO,SAAS;KAC7B;IACF;IAIA,IAAI,UAAU,SAAS,OAAO,SAAS,UAAU;KAC/C,aAAa,IAAI,WAAW,CAAC;KAC7B,eAAe,IACb,YACC,eAAe,IAAI,SAAS,KAAK,KAAK,CACzC;KAIA,MAAM,WAAW,aAAa,IAAI,SAAS;KAC3C,aAAa,IACX,WACA,aAAa,KAAA,KAAa,OAAO,WAAW,OAAO,QACrD;KACA;IACF;IAEA,kBAAkB,SAAS;GAC7B,CAAC;EACH;CACF;AACF"}
@@ -3,7 +3,7 @@ import { Commitment } from "@solana/kit";
3
3
  //#region src/confirmation/types.d.ts
4
4
  type SignatureStatusesResponse = Awaited<ReturnType<ReturnType<SolanaRpcType["getSignatureStatuses"]>["send"]>>;
5
5
  /** Derived from the RPC type rather than hand-written, which removes every
6
- * `as SignatureStatus` cast. A `JitoRpcType` response assigns without one. */
6
+ * `as SignatureStatus` cast. */
7
7
  export type SignatureStatus = NonNullable<SignatureStatusesResponse["value"][number]>;
8
8
  /** What a single RPC branch is allowed to report. Failure is a throw. */
9
9
  export type ConfirmationOutcome<T> = {
@@ -17,4 +17,5 @@ export type ConfirmationOutcome<T> = {
17
17
  };
18
18
  export declare function isConfirmedCommitment(status: Commitment | string | null | undefined): boolean;
19
19
  //#endregion
20
+ export {};
20
21
  //# sourceMappingURL=types.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"types.js","names":[],"sources":["../../../src/confirmation/types.ts"],"sourcesContent":["import type { Commitment } from '@solana/kit'\nimport type { SolanaRpcType } from '../rpc/types.js'\n\ntype SignatureStatusesResponse = Awaited<\n ReturnType<ReturnType<SolanaRpcType['getSignatureStatuses']>['send']>\n>\n\n/** Derived from the RPC type rather than hand-written, which removes every\n * `as SignatureStatus` cast. A `JitoRpcType` response assigns without one. */\nexport type SignatureStatus = NonNullable<\n SignatureStatusesResponse['value'][number]\n>\n\n/** What a single RPC branch is allowed to report. Failure is a throw. */\nexport type ConfirmationOutcome<T> =\n | { kind: 'confirmed'; value: T }\n /** The blockhash probe confirmed expiry: the transaction can no longer\n * land after `slot`, the `isBlockhashValid` context slot of the verdict.\n * The only outcome that may end in a final \"dropped\". */\n | { kind: 'expired'; slot: bigint }\n /** The wall-clock ceiling ended the observation without a verdict. */\n | { kind: 'not-confirmed' }\n\nexport function isConfirmedCommitment(\n status: Commitment | string | null | undefined\n): boolean {\n return status === 'confirmed' || status === 'finalized'\n}\n"],"mappings":";AAuBA,SAAgB,sBACd,QACS;CACT,OAAO,WAAW,eAAe,WAAW;AAC9C"}
1
+ {"version":3,"file":"types.js","names":[],"sources":["../../../src/confirmation/types.ts"],"sourcesContent":["import type { Commitment } from '@solana/kit'\nimport type { SolanaRpcType } from '../rpc/types.js'\n\ntype SignatureStatusesResponse = Awaited<\n ReturnType<ReturnType<SolanaRpcType['getSignatureStatuses']>['send']>\n>\n\n/** Derived from the RPC type rather than hand-written, which removes every\n * `as SignatureStatus` cast. */\nexport type SignatureStatus = NonNullable<\n SignatureStatusesResponse['value'][number]\n>\n\n/** What a single RPC branch is allowed to report. Failure is a throw. */\nexport type ConfirmationOutcome<T> =\n | { kind: 'confirmed'; value: T }\n /** The blockhash probe confirmed expiry: the transaction can no longer\n * land after `slot`, the `isBlockhashValid` context slot of the verdict.\n * The only outcome that may end in a final \"dropped\". */\n | { kind: 'expired'; slot: bigint }\n /** The wall-clock ceiling ended the observation without a verdict. */\n | { kind: 'not-confirmed' }\n\nexport function isConfirmedCommitment(\n status: Commitment | string | null | undefined\n): boolean {\n return status === 'confirmed' || status === 'finalized'\n}\n"],"mappings":";AAuBA,SAAgB,sBACd,QACS;CACT,OAAO,WAAW,eAAe,WAAW;AAC9C"}
@@ -1 +1 @@
1
- {"version":3,"file":"SolanaJitoWaitForTransactionTask.d.ts","names":[],"sources":["../../../../src/core/tasks/SolanaJitoWaitForTransactionTask.ts"],"mappings":";;;qBA+Da,yCAAyC;EACpD,IAAU,SAAS,4BAA4B,QAAQ"}
1
+ {"version":3,"file":"SolanaJitoWaitForTransactionTask.d.ts","names":[],"sources":["../../../../src/core/tasks/SolanaJitoWaitForTransactionTask.ts"],"mappings":";;;qBA+Ca,yCAAyC;EACpD,IAAU,SAAS,4BAA4B,QAAQ"}
@@ -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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,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"}
@@ -24,4 +24,5 @@ export type GetBundleStatusesApi = {
24
24
  getBundleStatuses(bundleIds: string[], region?: JitoRegion): GetBundleStatusesResponse;
25
25
  };
26
26
  //#endregion
27
+ export {};
27
28
  //# sourceMappingURL=getBundleStatuses.d.ts.map
@@ -11,4 +11,5 @@ export type GetTipAccountsApi = {
11
11
  getTipAccounts(region?: JitoRegion): GetTipAccountsResponse;
12
12
  };
13
13
  //#endregion
14
+ export {};
14
15
  //# sourceMappingURL=getTipAccounts.d.ts.map
@@ -18,4 +18,5 @@ export type SendBundleApi = {
18
18
  sendBundle(transactions: Array<Base64EncodedWireTransaction>, region?: JitoRegion): SendBundleResponse;
19
19
  };
20
20
  //#endregion
21
+ export {};
21
22
  //# sourceMappingURL=sendBundle.d.ts.map
@@ -57,4 +57,5 @@ export type SimulateBundleApi = {
57
57
  }>): SimulateBundleResponse;
58
58
  };
59
59
  //#endregion
60
+ export {};
60
61
  //# sourceMappingURL=simulateBundle.d.ts.map
@@ -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":";;;;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;;;;;;AAO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AM,eAAe,OAAO;EAAG;CAAY;AACtD;;;;;;;;;AAUA,MAAa,qBAAqB,OAChC,YAC0D;CAC1D,MAAM,cAAc,MAAM,kBAAkB,OAAO;CACnD,OAAO;EAAE,MAAM,eAAe,OAAO;EAAG;CAAY;AACtD"}
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":";;;;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,YA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;EAAG;CAAY;AACtD"}
@@ -62,4 +62,5 @@ export declare const callSolanaRpcsWithRetry: RetryFn<SolanaRpcType>;
62
62
  */
63
63
  export declare const callJitoRpcsWithRetry: RetryFn<JitoRpcType>;
64
64
  //#endregion
65
+ export {};
65
66
  //# sourceMappingURL=utils.d.ts.map
@@ -25,4 +25,5 @@ type FeatureMap = {
25
25
  */
26
26
  export declare function getWalletFeature<K extends keyof FeatureMap>(wallet: Wallet, featureName: K): FeatureMap[K];
27
27
  //#endregion
28
+ export {};
28
29
  //# sourceMappingURL=getWalletFeature.d.ts.map
@@ -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.7";
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.7";
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.7'\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.7",
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,8 +28,8 @@
28
28
  "./package.json": "./package.json"
29
29
  },
30
30
  "dependencies": {
31
- "@lifi/sdk": "4.12.0",
32
- "@solana/kit": "^8.4.0",
31
+ "@lifi/sdk": "4.12.1",
32
+ "@solana/kit": "^8.5.0",
33
33
  "@solana/wallet-standard-features": "^1.5.0",
34
34
  "@wallet-standard/base": "^1.1.1"
35
35
  },
@@ -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 }