@lifi/sdk-provider-solana 4.3.4 → 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.
- package/CHANGELOG.md +15 -0
- package/dist/cjs/actions/sendAndConfirmBundle.d.ts +8 -7
- package/dist/cjs/actions/sendAndConfirmBundle.js +22 -16
- package/dist/cjs/actions/sendAndConfirmBundle.js.map +1 -1
- package/dist/cjs/confirmation/confirmBundle.d.ts +18 -19
- package/dist/cjs/confirmation/confirmBundle.js +10 -23
- package/dist/cjs/confirmation/confirmBundle.js.map +1 -1
- package/dist/cjs/confirmation/confirmSignature.d.ts +2 -2
- package/dist/cjs/confirmation/confirmSignature.js +2 -2
- package/dist/cjs/confirmation/confirmSignature.js.map +1 -1
- package/dist/cjs/confirmation/createConfirmationDeadline.d.ts +1 -1
- package/dist/cjs/confirmation/createConfirmationDeadline.js.map +1 -1
- package/dist/cjs/confirmation/types.d.ts +1 -1
- package/dist/cjs/confirmation/types.js.map +1 -1
- package/dist/cjs/core/tasks/SolanaJitoWaitForTransactionTask.js +9 -18
- package/dist/cjs/core/tasks/SolanaJitoWaitForTransactionTask.js.map +1 -1
- package/dist/cjs/core/tasks/SolanaSignAndExecuteTask.js.map +1 -1
- package/dist/cjs/rpc/registry.d.ts +4 -3
- package/dist/cjs/rpc/registry.js +4 -3
- package/dist/cjs/rpc/registry.js.map +1 -1
- package/dist/cjs/version.d.ts +1 -1
- package/dist/cjs/version.js +1 -1
- package/dist/cjs/version.js.map +1 -1
- package/dist/esm/actions/sendAndConfirmBundle.d.ts +8 -7
- package/dist/esm/actions/sendAndConfirmBundle.d.ts.map +1 -1
- package/dist/esm/actions/sendAndConfirmBundle.js +24 -18
- package/dist/esm/actions/sendAndConfirmBundle.js.map +1 -1
- package/dist/esm/confirmation/confirmBundle.d.ts +18 -19
- package/dist/esm/confirmation/confirmBundle.d.ts.map +1 -1
- package/dist/esm/confirmation/confirmBundle.js +10 -23
- package/dist/esm/confirmation/confirmBundle.js.map +1 -1
- package/dist/esm/confirmation/confirmSignature.d.ts +2 -2
- package/dist/esm/confirmation/confirmSignature.js +2 -2
- package/dist/esm/confirmation/confirmSignature.js.map +1 -1
- package/dist/esm/confirmation/createConfirmationDeadline.d.ts +1 -1
- package/dist/esm/confirmation/createConfirmationDeadline.js.map +1 -1
- package/dist/esm/confirmation/types.d.ts +1 -1
- package/dist/esm/confirmation/types.js.map +1 -1
- package/dist/esm/core/tasks/SolanaJitoWaitForTransactionTask.d.ts.map +1 -1
- package/dist/esm/core/tasks/SolanaJitoWaitForTransactionTask.js +10 -19
- package/dist/esm/core/tasks/SolanaJitoWaitForTransactionTask.js.map +1 -1
- package/dist/esm/core/tasks/SolanaSignAndExecuteTask.js.map +1 -1
- package/dist/esm/rpc/registry.d.ts +4 -3
- package/dist/esm/rpc/registry.d.ts.map +1 -1
- package/dist/esm/rpc/registry.js +4 -3
- package/dist/esm/rpc/registry.js.map +1 -1
- package/dist/esm/version.d.ts +1 -1
- package/dist/esm/version.js +1 -1
- package/dist/esm/version.js.map +1 -1
- package/package.json +2 -2
- package/src/actions/sendAndConfirmBundle.ts +48 -48
- package/src/confirmation/confirmBundle.ts +34 -69
- package/src/confirmation/confirmSignature.ts +2 -2
- package/src/confirmation/createConfirmationDeadline.ts +1 -1
- package/src/confirmation/types.ts +1 -1
- package/src/core/tasks/SolanaJitoWaitForTransactionTask.ts +13 -27
- package/src/core/tasks/SolanaSignAndExecuteTask.ts +5 -6
- package/src/rpc/registry.ts +4 -3
- package/src/version.ts +1 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"SolanaSignAndExecuteTask.js","names":["BaseStepExecutionTask","TransactionError","LiFiErrorCode","getTransactionRequestData","base64ToUint8Array","withTimeout","getWalletFeature","SolanaSignTransaction","CLEARED_TRANSACTION_FIELDS","getTransactionCodec","encodeStoredTransactions"],"sources":["../../../../src/core/tasks/SolanaSignAndExecuteTask.ts"],"sourcesContent":["import {\n assertNoOpenTransaction,\n BaseStepExecutionTask,\n CLEARED_TRANSACTION_FIELDS,\n getTransactionRequestData,\n LiFiErrorCode,\n type TaskResult,\n TransactionError,\n withTimeout,\n} from '@lifi/sdk'\nimport { getTransactionCodec } from '@solana/kit'\nimport { SolanaSignTransaction } from '@solana/wallet-standard-features'\nimport type { SolanaStepExecutorContext } from '../../types.js'\nimport { base64ToUint8Array } from '../../utils/base64ToUint8Array.js'\nimport { getWalletFeature } from '../../utils/getWalletFeature.js'\nimport { encodeStoredTransactions } from '../../utils/storedTransactions.js'\nimport { readSignature } from './readSignature.js'\n\nexport class SolanaSignAndExecuteTask extends BaseStepExecutionTask {\n async run(context: SolanaStepExecutorContext): Promise<TaskResult> {\n const {\n step,\n wallet,\n getWalletAccount,\n statusManager,\n executionOptions,\n isBridgeExecution,\n } = context\n\n const action = statusManager.findAction(\n step,\n isBridgeExecution ? 'CROSS_CHAIN' : 'SWAP'\n )\n\n // Defence in depth: the selector sends an action with an open\n // transaction to the wait task. Signing here could put a second\n // transaction on chain while the first can still land.\n assertNoOpenTransaction(action)\n\n if (!action) {\n throw new TransactionError(\n LiFiErrorCode.TransactionUnprepared,\n 'Unable to prepare transaction. Action not found.'\n )\n }\n\n // Resolved here and not in `createContext`: a resume that only waits\n // never signs, so it must not fail because the wallet has not\n // reconnected yet.\n const walletAccount = getWalletAccount(step)\n\n const transactionRequestData = (await getTransactionRequestData(\n step,\n executionOptions\n )) as string | string[]\n\n // The backend returns an array when it produced a Jito bundle and a string\n // for a single transaction. The shape determines how we submit it later:\n // array -> sendBundle, string -> sendTransaction.\n const isBundleExecution = Array.isArray(transactionRequestData)\n\n const transactionDataArray = isBundleExecution\n ? transactionRequestData\n : [transactionRequestData]\n\n const transactionBytesArray = transactionDataArray.map((data) =>\n base64ToUint8Array(data)\n )\n\n // Checked again right before the wallet: a late write of an older run\n // can merge its transaction into this action during the await above.\n assertNoOpenTransaction(statusManager.findAction(step, action.type))\n\n const signedTransactionOutputs = await withTimeout(\n async () => {\n const { signTransaction } = getWalletFeature(\n wallet,\n SolanaSignTransaction\n )\n // Spread the inputs to sign all transactions at once\n return signTransaction(\n ...transactionBytesArray.map((transaction) => ({\n account: walletAccount,\n transaction,\n }))\n )\n },\n {\n // https://solana.com/docs/advanced/confirmation#transaction-expiration\n // Use 2 minutes to account for fluctuations\n timeout: 120_000,\n errorInstance: new TransactionError(\n LiFiErrorCode.TransactionExpired,\n 'Transaction has expired: blockhash is no longer recent enough.'\n ),\n }\n )\n\n // Checked once more after the wallet: a stopped run's late write can\n // merge its transaction into this action while the prompt is open.\n // Nothing awaits from here to the two writes below, so no late write can\n // land between this check and either of them.\n assertNoOpenTransaction(statusManager.findAction(step, action.type))\n\n if (signedTransactionOutputs.length === 0) {\n throw new TransactionError(\n LiFiErrorCode.TransactionUnprepared,\n 'No signed transaction returned from signer.'\n )\n }\n\n // Neither `txHash` nor `txLink` is written here. A signature is fixed at\n // signing, but the transaction does not exist yet: `getTransaction`\n // returns `null` for it, and simulation, the empty-Jito-RPC throw and\n // every send failure all sit between this task and the first broadcast.\n // The wait tasks write both on `onBroadcast`, when an RPC has accepted it.\n //\n // The previous transaction's fields (`CLEARED_TRANSACTION_FIELDS
|
|
1
|
+
{"version":3,"file":"SolanaSignAndExecuteTask.js","names":["BaseStepExecutionTask","TransactionError","LiFiErrorCode","getTransactionRequestData","base64ToUint8Array","withTimeout","getWalletFeature","SolanaSignTransaction","CLEARED_TRANSACTION_FIELDS","getTransactionCodec","encodeStoredTransactions"],"sources":["../../../../src/core/tasks/SolanaSignAndExecuteTask.ts"],"sourcesContent":["import {\n assertNoOpenTransaction,\n BaseStepExecutionTask,\n CLEARED_TRANSACTION_FIELDS,\n getTransactionRequestData,\n LiFiErrorCode,\n type TaskResult,\n TransactionError,\n withTimeout,\n} from '@lifi/sdk'\nimport { getTransactionCodec } from '@solana/kit'\nimport { SolanaSignTransaction } from '@solana/wallet-standard-features'\nimport type { SolanaStepExecutorContext } from '../../types.js'\nimport { base64ToUint8Array } from '../../utils/base64ToUint8Array.js'\nimport { getWalletFeature } from '../../utils/getWalletFeature.js'\nimport { encodeStoredTransactions } from '../../utils/storedTransactions.js'\nimport { readSignature } from './readSignature.js'\n\nexport class SolanaSignAndExecuteTask extends BaseStepExecutionTask {\n async run(context: SolanaStepExecutorContext): Promise<TaskResult> {\n const {\n step,\n wallet,\n getWalletAccount,\n statusManager,\n executionOptions,\n isBridgeExecution,\n } = context\n\n const action = statusManager.findAction(\n step,\n isBridgeExecution ? 'CROSS_CHAIN' : 'SWAP'\n )\n\n // Defence in depth: the selector sends an action with an open\n // transaction to the wait task. Signing here could put a second\n // transaction on chain while the first can still land.\n assertNoOpenTransaction(action)\n\n if (!action) {\n throw new TransactionError(\n LiFiErrorCode.TransactionUnprepared,\n 'Unable to prepare transaction. Action not found.'\n )\n }\n\n // Resolved here and not in `createContext`: a resume that only waits\n // never signs, so it must not fail because the wallet has not\n // reconnected yet.\n const walletAccount = getWalletAccount(step)\n\n const transactionRequestData = (await getTransactionRequestData(\n step,\n executionOptions\n )) as string | string[]\n\n // The backend returns an array when it produced a Jito bundle and a string\n // for a single transaction. The shape determines how we submit it later:\n // array -> sendBundle, string -> sendTransaction.\n const isBundleExecution = Array.isArray(transactionRequestData)\n\n const transactionDataArray = isBundleExecution\n ? transactionRequestData\n : [transactionRequestData]\n\n const transactionBytesArray = transactionDataArray.map((data) =>\n base64ToUint8Array(data)\n )\n\n // Checked again right before the wallet: a late write of an older run\n // can merge its transaction into this action during the await above.\n assertNoOpenTransaction(statusManager.findAction(step, action.type))\n\n const signedTransactionOutputs = await withTimeout(\n async () => {\n const { signTransaction } = getWalletFeature(\n wallet,\n SolanaSignTransaction\n )\n // Spread the inputs to sign all transactions at once\n return signTransaction(\n ...transactionBytesArray.map((transaction) => ({\n account: walletAccount,\n transaction,\n }))\n )\n },\n {\n // https://solana.com/docs/advanced/confirmation#transaction-expiration\n // Use 2 minutes to account for fluctuations\n timeout: 120_000,\n errorInstance: new TransactionError(\n LiFiErrorCode.TransactionExpired,\n 'Transaction has expired: blockhash is no longer recent enough.'\n ),\n }\n )\n\n // Checked once more after the wallet: a stopped run's late write can\n // merge its transaction into this action while the prompt is open.\n // Nothing awaits from here to the two writes below, so no late write can\n // land between this check and either of them.\n assertNoOpenTransaction(statusManager.findAction(step, action.type))\n\n if (signedTransactionOutputs.length === 0) {\n throw new TransactionError(\n LiFiErrorCode.TransactionUnprepared,\n 'No signed transaction returned from signer.'\n )\n }\n\n // Neither `txHash` nor `txLink` is written here. A signature is fixed at\n // signing, but the transaction does not exist yet: `getTransaction`\n // returns `null` for it, and simulation, the empty-Jito-RPC throw and\n // every send failure all sit between this task and the first broadcast.\n // The wait tasks write both on `onBroadcast`, when an RPC has accepted it.\n //\n // The previous transaction's fields (`CLEARED_TRANSACTION_FIELDS`) are\n // cleared explicitly. Only a final failure reaches this task with them\n // set, and a stale hash would look open again once its `txFinal` is gone.\n // This write runs BEFORE the decode below, which can throw on a malformed\n // wallet output and would otherwise strand the old fields.\n statusManager.updateAction(step, action.type, 'PENDING', {\n ...CLEARED_TRANSACTION_FIELDS,\n signedAt: Date.now(),\n })\n\n const transactionCodec = getTransactionCodec()\n\n // Decode all signed transactions\n const signedTransactions = signedTransactionOutputs.map((output) =>\n transactionCodec.decode(output.signedTransaction)\n )\n\n // Every transaction must carry its fee payer signature before its bytes\n // are stored: an unreadable value would fail every resume the same way.\n // Nothing has been sent yet, so the `TransactionUnprepared` this throws\n // leaves \"Try again\" free to sign again.\n for (const signedTransaction of signedTransactions) {\n readSignature(signedTransaction)\n }\n\n // Stored before any send: a reload from here on resends these bytes\n // instead of asking the wallet again. A bundle stays a JSON array, which\n // is how a resume knows to submit it with `sendBundle`.\n statusManager.updateAction(step, action.type, 'PENDING', {\n txHex: encodeStoredTransactions(\n signedTransactionOutputs.map((output) => output.signedTransaction),\n isBundleExecution\n ),\n })\n\n return {\n status: 'COMPLETED',\n context: { signedTransactions, isBundleExecution },\n }\n }\n}\n"],"mappings":";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CAAoB;EAG7C,MAAM,qBAAqB,yBAAyB,KAAK,WACvD,iBAAiB,OAAO,OAAO,iBAAiB,CAClD;EAMA,KAAK,MAAM,qBAAqB,oBAC9B,iCAAA,cAAc,iBAAiB;EAMjC,cAAc,aAAa,MAAM,OAAO,MAAM,WAAW,EACvD,OAAOC,iCAAAA,yBACL,yBAAyB,KAAK,WAAW,OAAO,iBAAiB,GACjE,iBACF,EACF,CAAC;EAED,OAAO;GACL,QAAQ;GACR,SAAS;IAAE;IAAoB;GAAkB;EACnD;CACF;AACF"}
|
|
@@ -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
|
-
*
|
|
29
|
-
*
|
|
30
|
-
* support it without exposing
|
|
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
|
/**
|
package/dist/cjs/rpc/registry.js
CHANGED
|
@@ -71,9 +71,10 @@ const readProbeFailure = (error) => {
|
|
|
71
71
|
*/
|
|
72
72
|
const PROBE_TIMEOUT_MS = 5e3;
|
|
73
73
|
/**
|
|
74
|
-
*
|
|
75
|
-
*
|
|
76
|
-
* support it without exposing
|
|
74
|
+
* Picks the RPCs that may submit a bundle; confirmation reads signatures on
|
|
75
|
+
* every read RPC. Probes with `getBundleStatuses` rather than
|
|
76
|
+
* `getTipAccounts`: providers such as Helius support it without exposing
|
|
77
|
+
* `getTipAccounts`.
|
|
77
78
|
*/
|
|
78
79
|
const probeJitoRpc = async (rpcUrl) => {
|
|
79
80
|
const controller = new AbortController();
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"registry.js","names":["LruMap","createJitoRpc","ChainId","createSolanaRpc","withDedupe"],"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,IAAIA,UAAAA,OAAsB,EAAE;AAC/C,MAAM,WAAW,IAAIA,UAAAA,OAAoB,EAAE;;;;;;;;;;;AAY3C,MAAM,kBACJ;;;;AAkBF,MAAa,sBAAsB;;;;;;;;AASnC,MAAa,8BAAsC;;;;;AAQnD,MAAM,aAAa,IAAIA,UAAAA,OAAwB,EAAE;;;AAIjD,MAAM,gBAAgB,WACpB,WAAW,KAAA,KAAa,KAAK,IAAI,IAAI,OAAO,KAAK,OAAO;AAS1D,MAAM,mBAA6B,CACjC,QACA,MACF;;;;;;AAOA,MAAM,gCAA0C,CAAC,KAAK,GAAG;AAEzD,MAAM,oBAAoB,UAAoC;CAC5D,MAAM,YAAY;CASlB,MAAM,UAAU,WAAW,QAAQ,WAAW,SAAS;CACvD,IAAI,OAAO,YAAY,YAAY,iBAAiB,SAAS,OAAO,GAElE,OAAO;EAAE,SAAS;EAAe,SAAS,OAAO;CAAkB;CAGrE,MAAM,SAAS,WAAW,SA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
|
+
{"version":3,"file":"registry.js","names":["LruMap","createJitoRpc","ChainId","createSolanaRpc","withDedupe"],"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,IAAIA,UAAAA,OAAsB,EAAE;AAC/C,MAAM,WAAW,IAAIA,UAAAA,OAAoB,EAAE;;;;;;;;;;;AAY3C,MAAM,kBACJ;;;;AAkBF,MAAa,sBAAsB;;;;;;;;AASnC,MAAa,8BAAsC;;;;;AAQnD,MAAM,aAAa,IAAIA,UAAAA,OAAwB,EAAE;;;AAIjD,MAAM,gBAAgB,WACpB,WAAW,KAAA,KAAa,KAAK,IAAI,IAAI,OAAO,KAAK,OAAO;AAS1D,MAAM,mBAA6B,CACjC,QACA,MACF;;;;;;AAOA,MAAM,gCAA0C,CAAC,KAAK,GAAG;AAEzD,MAAM,oBAAoB,UAAoC;CAC5D,MAAM,YAAY;CASlB,MAAM,UAAU,WAAW,QAAQ,WAAW,SAAS;CACvD,IAAI,OAAO,YAAY,YAAY,iBAAiB,SAAS,OAAO,GAElE,OAAO;EAAE,SAAS;EAAe,SAAS,OAAO;CAAkB;CAGrE,MAAM,SAAS,WAAW,SAAS;C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js/version.d.ts
CHANGED
package/dist/cjs/version.js
CHANGED
package/dist/cjs/version.js.map
CHANGED
|
@@ -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.
|
|
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"}
|
|
@@ -4,8 +4,8 @@ import { SDKClient } from "@lifi/sdk";
|
|
|
4
4
|
import { Transaction } from "@solana/kit";
|
|
5
5
|
//#region src/actions/sendAndConfirmBundle.d.ts
|
|
6
6
|
/**
|
|
7
|
-
* Sends a Jito bundle
|
|
8
|
-
*
|
|
7
|
+
* Sends a Jito bundle once and returns as soon as one read RPC sees every
|
|
8
|
+
* transaction of it confirmed.
|
|
9
9
|
*
|
|
10
10
|
* The deadline receives the lifetime of *every* signed transaction, not just
|
|
11
11
|
* the first: a bundle is an array of independently built backend transactions
|
|
@@ -15,13 +15,14 @@ import { Transaction } from "@solana/kit";
|
|
|
15
15
|
* deadline starts on the same clock as `BRANCH_TIMEOUT_MS` instead of after
|
|
16
16
|
* the submission returns.
|
|
17
17
|
*
|
|
18
|
-
*
|
|
19
|
-
*
|
|
20
|
-
*
|
|
21
|
-
*
|
|
18
|
+
* The bundle is submitted once through the RPCs that pass the Jito probe: the
|
|
19
|
+
* bundle list of `rpcUrls[ChainId.SOL]` first, else the write list, else the
|
|
20
|
+
* read RPCs. With either list set, bundles never go to the read RPCs. Every
|
|
21
|
+
* read RPC confirms the bundle by its transaction signatures, so no read RPC
|
|
22
|
+
* needs Jito support and the `sendBundle` answer is not read.
|
|
22
23
|
*/
|
|
23
24
|
export declare function sendAndConfirmBundle(client: SDKClient, signedTransactions: Transaction[], options?: {
|
|
24
|
-
/** Runs once, when the first
|
|
25
|
+
/** Runs once, when the first submit RPC accepts the submission. */
|
|
25
26
|
onBroadcast?: () => void;
|
|
26
27
|
}): Promise<RaceResult<BundleConfirmation>>;
|
|
27
28
|
//#endregion
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"sendAndConfirmBundle.d.ts","names":[],"sources":["../../../src/actions/sendAndConfirmBundle.ts"],"mappings":"
|
|
1
|
+
{"version":3,"file":"sendAndConfirmBundle.d.ts","names":[],"sources":["../../../src/actions/sendAndConfirmBundle.ts"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;wBAsCsB,qBACpB,QAAQ,WACR,oBAAoB,eACpB;;EAEE;IAED,QAAQ,WAAW"}
|
|
@@ -1,14 +1,14 @@
|
|
|
1
|
-
import { getJitoCapableRpcs, getJitoRpcs } from "../rpc/registry.js";
|
|
1
|
+
import { getJitoCapableRpcs, getJitoRpcs, getSolanaRpcs } from "../rpc/registry.js";
|
|
2
2
|
import { BRANCH_TIMEOUT_MS } from "../confirmation/createConfirmationDeadline.js";
|
|
3
3
|
import { confirmBundle } from "../confirmation/confirmBundle.js";
|
|
4
4
|
import { raceRpcs } from "../confirmation/raceRpcs.js";
|
|
5
5
|
import { getTransactionLifetime } from "../utils/getTransactionLifetime.js";
|
|
6
6
|
import { ChainId, LiFiErrorCode, RPCError } from "@lifi/sdk";
|
|
7
|
-
import { getBase64EncodedWireTransaction } from "@solana/kit";
|
|
7
|
+
import { getBase64EncodedWireTransaction, getSignatureFromTransaction } from "@solana/kit";
|
|
8
8
|
//#region src/actions/sendAndConfirmBundle.ts
|
|
9
9
|
/**
|
|
10
|
-
* Sends a Jito bundle
|
|
11
|
-
*
|
|
10
|
+
* Sends a Jito bundle once and returns as soon as one read RPC sees every
|
|
11
|
+
* transaction of it confirmed.
|
|
12
12
|
*
|
|
13
13
|
* The deadline receives the lifetime of *every* signed transaction, not just
|
|
14
14
|
* the first: a bundle is an array of independently built backend transactions
|
|
@@ -18,10 +18,11 @@ import { getBase64EncodedWireTransaction } from "@solana/kit";
|
|
|
18
18
|
* deadline starts on the same clock as `BRANCH_TIMEOUT_MS` instead of after
|
|
19
19
|
* the submission returns.
|
|
20
20
|
*
|
|
21
|
-
*
|
|
22
|
-
*
|
|
23
|
-
*
|
|
24
|
-
*
|
|
21
|
+
* The bundle is submitted once through the RPCs that pass the Jito probe: the
|
|
22
|
+
* bundle list of `rpcUrls[ChainId.SOL]` first, else the write list, else the
|
|
23
|
+
* read RPCs. With either list set, bundles never go to the read RPCs. Every
|
|
24
|
+
* read RPC confirms the bundle by its transaction signatures, so no read RPC
|
|
25
|
+
* needs Jito support and the `sendBundle` answer is not read.
|
|
25
26
|
*/
|
|
26
27
|
async function sendAndConfirmBundle(client, signedTransactions, options) {
|
|
27
28
|
const [bundleUrls = [], writeUrls = []] = await Promise.all([client.getBundleRpcUrlsByChainId?.(ChainId.SOL), client.getWriteRpcUrlsByChainId?.(ChainId.SOL)]);
|
|
@@ -38,17 +39,20 @@ async function sendAndConfirmBundle(client, signedTransactions, options) {
|
|
|
38
39
|
unreachable: bundle.unreachable + write.unreachable
|
|
39
40
|
};
|
|
40
41
|
};
|
|
41
|
-
const
|
|
42
|
-
|
|
43
|
-
|
|
42
|
+
const hasSubmitLists = bundleUrls.length > 0 || writeUrls.length > 0;
|
|
43
|
+
const [{ rpcs: submitRpcs, unreachable }, confirmRpcs] = await Promise.all([hasSubmitLists ? findSubmitRpcs() : getJitoRpcs(client), getSolanaRpcs(client)]);
|
|
44
|
+
if (hasSubmitLists && !submitRpcs.length) {
|
|
45
|
+
const lists = Object.entries({
|
|
46
|
+
bundle: bundleUrls,
|
|
47
|
+
write: writeUrls
|
|
48
|
+
}).filter(([, urls]) => urls.length > 0).map(([name]) => `\`rpcUrls[ChainId.SOL].${name}\``).join(" or ");
|
|
44
49
|
throw new RPCError(LiFiErrorCode.RpcUnavailable, [
|
|
45
50
|
`Jito bundle required, but no URL in ${lists} passed the Jito capability probe.`,
|
|
46
|
-
|
|
47
|
-
"Bundles never go to the read RPCs while `bundle` or `write` is set."
|
|
48
|
-
|
|
49
|
-
].filter(Boolean).join(" "));
|
|
51
|
+
unreachable > 0 ? "The probe got no answer from some of them. This is usually temporary - retry. If it persists, the endpoint may refuse `sendBundle` for your plan." : "They do not support `sendBundle`: add a Jito-capable URL to `rpcUrls[ChainId.SOL].bundle`.",
|
|
52
|
+
"Bundles never go to the read RPCs while `bundle` or `write` is set."
|
|
53
|
+
].join(" "));
|
|
50
54
|
}
|
|
51
|
-
if (
|
|
55
|
+
if (!submitRpcs.length) throw new RPCError(LiFiErrorCode.RpcUnavailable, unreachable > 0 ? `Jito bundle required, but the capability probe failed against ${unreachable} configured Solana RPC(s). This is usually temporary - retry. If it persists, the endpoint may refuse \`sendBundle\` for your plan.` : "Jito bundle required, but no configured Solana RPC supports `sendBundle`. Supply a Jito-capable URL via the `rpcUrls` client config option.");
|
|
52
56
|
let broadcastReported = false;
|
|
53
57
|
const reportBroadcast = () => {
|
|
54
58
|
if (broadcastReported) return;
|
|
@@ -57,6 +61,7 @@ async function sendAndConfirmBundle(client, signedTransactions, options) {
|
|
|
57
61
|
broadcastReported = true;
|
|
58
62
|
} catch (_) {}
|
|
59
63
|
};
|
|
64
|
+
const signatures = signedTransactions.map((transaction) => getSignatureFromTransaction(transaction));
|
|
60
65
|
const serializedTransactions = signedTransactions.map((transaction) => getBase64EncodedWireTransaction(transaction));
|
|
61
66
|
const lifetimes = await Promise.all(signedTransactions.map((transaction) => getTransactionLifetime(transaction)));
|
|
62
67
|
let submission;
|
|
@@ -66,11 +71,12 @@ async function sendAndConfirmBundle(client, signedTransactions, options) {
|
|
|
66
71
|
});
|
|
67
72
|
return submission;
|
|
68
73
|
};
|
|
69
|
-
return raceRpcs(
|
|
74
|
+
return raceRpcs(confirmRpcs, (rpc, signal) => confirmBundle({
|
|
70
75
|
rpc,
|
|
71
76
|
signal,
|
|
77
|
+
signatures,
|
|
72
78
|
lifetimes,
|
|
73
|
-
send: () =>
|
|
79
|
+
send: () => submitOnce(signal),
|
|
74
80
|
onBroadcast: reportBroadcast
|
|
75
81
|
}), { timeoutMs: BRANCH_TIMEOUT_MS });
|
|
76
82
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"sendAndConfirmBundle.js","names":[],"sources":["../../../src/actions/sendAndConfirmBundle.ts"],"sourcesContent":["import { ChainId, LiFiErrorCode, RPCError, type SDKClient } from '@lifi/sdk'\nimport {
|
|
1
|
+
{"version":3,"file":"sendAndConfirmBundle.js","names":[],"sources":["../../../src/actions/sendAndConfirmBundle.ts"],"sourcesContent":["import { ChainId, LiFiErrorCode, RPCError, type SDKClient } from '@lifi/sdk'\nimport {\n getBase64EncodedWireTransaction,\n getSignatureFromTransaction,\n type Transaction,\n} from '@solana/kit'\nimport {\n type BundleConfirmation,\n confirmBundle,\n} from '../confirmation/confirmBundle.js'\nimport { BRANCH_TIMEOUT_MS } from '../confirmation/createConfirmationDeadline.js'\nimport { type RaceResult, raceRpcs } from '../confirmation/raceRpcs.js'\nimport {\n getJitoCapableRpcs,\n getJitoRpcs,\n getSolanaRpcs,\n} from '../rpc/registry.js'\nimport type { JitoRpcType } from '../rpc/types.js'\nimport { getTransactionLifetime } from '../utils/getTransactionLifetime.js'\n\n/**\n * Sends a Jito bundle once and returns as soon as one read RPC sees every\n * transaction of it confirmed.\n *\n * The deadline receives the lifetime of *every* signed transaction, not just\n * the first: a bundle is an array of independently built backend transactions\n * and they may not share a blockhash.\n *\n * `sendBundle` is handed to `confirmBundle` rather than awaited here, so the\n * deadline starts on the same clock as `BRANCH_TIMEOUT_MS` instead of after\n * the submission returns.\n *\n * The bundle is submitted once through the RPCs that pass the Jito probe: the\n * bundle list of `rpcUrls[ChainId.SOL]` first, else the write list, else the\n * read RPCs. With either list set, bundles never go to the read RPCs. Every\n * read RPC confirms the bundle by its transaction signatures, so no read RPC\n * needs Jito support and the `sendBundle` answer is not read.\n */\nexport async function sendAndConfirmBundle(\n client: SDKClient,\n signedTransactions: Transaction[],\n options?: {\n /** Runs once, when the first submit RPC accepts the submission. */\n onBroadcast?: () => void\n }\n): Promise<RaceResult<BundleConfirmation>> {\n // With a bundle or write list set, bundles go only to those: the bundle\n // RPCs that pass the Jito probe, else the write RPCs that do. The write list\n // is probed only when it is needed. With neither list, the read RPCs that\n // pass the Jito probe submit.\n const [bundleUrls = [], writeUrls = []] = await Promise.all([\n client.getBundleRpcUrlsByChainId?.(ChainId.SOL),\n client.getWriteRpcUrlsByChainId?.(ChainId.SOL),\n ])\n const noSubmitRpcs = { rpcs: [] as JitoRpcType[], unreachable: 0 }\n const findSubmitRpcs = async (): Promise<typeof noSubmitRpcs> => {\n const bundle = bundleUrls.length\n ? await getJitoCapableRpcs(bundleUrls)\n : noSubmitRpcs\n if (bundle.rpcs.length || !writeUrls.length) {\n return bundle\n }\n const write = await getJitoCapableRpcs(writeUrls)\n return {\n rpcs: write.rpcs,\n unreachable: bundle.unreachable + write.unreachable,\n }\n }\n const hasSubmitLists = bundleUrls.length > 0 || writeUrls.length > 0\n const [{ rpcs: submitRpcs, unreachable }, confirmRpcs] = await Promise.all([\n hasSubmitLists ? findSubmitRpcs() : getJitoRpcs(client),\n getSolanaRpcs(client),\n ])\n\n if (hasSubmitLists && !submitRpcs.length) {\n // Names only the lists that are set.\n const lists = Object.entries({ bundle: bundleUrls, write: writeUrls })\n .filter(([, urls]) => urls.length > 0)\n .map(([name]) => `\\`rpcUrls[ChainId.SOL].${name}\\``)\n .join(' or ')\n throw new RPCError(\n LiFiErrorCode.RpcUnavailable,\n [\n `Jito bundle required, but no URL in ${lists} passed the Jito capability probe.`,\n unreachable > 0\n ? 'The probe got no answer from some of them. This is usually temporary - retry. If it persists, the endpoint may refuse `sendBundle` for your plan.'\n : 'They do not support `sendBundle`: add a Jito-capable URL to `rpcUrls[ChainId.SOL].bundle`.',\n 'Bundles never go to the read RPCs while `bundle` or `write` is set.',\n ].join(' ')\n )\n }\n\n // Named here, where the emptiness is known: submitting to zero RPCs would\n // surface as a bare `rpc-unavailable`, indistinguishable from an outage. The\n // two causes get different messages - a configuration gap the integrator can\n // close, or endpoints that never answered.\n //\n // The `unreachable` message names a plan gate as well as an outage: a bare\n // HTTP 401/403 never reaches the JSON-RPC layer, so `readProbeFailure`\n // cannot tell a gated endpoint from a provider mid-deploy and classifies\n // both as `unreachable`. \"Retry\" alone would loop an integrator forever on a\n // gate no retry can clear.\n if (!submitRpcs.length) {\n throw new RPCError(\n LiFiErrorCode.RpcUnavailable,\n unreachable > 0\n ? `Jito bundle required, but the capability probe failed against ${unreachable} configured Solana RPC(s). This is usually temporary - retry. If it persists, the endpoint may refuse \\`sendBundle\\` for your plan.`\n : 'Jito bundle required, but no configured Solana RPC supports `sendBundle`. Supply a Jito-capable URL via the `rpcUrls` client config option.'\n )\n }\n\n let broadcastReported = false\n // No `sendAccepted` twin here: a bundle submits once, and a failed `send()`\n // throws out of `confirmBundle` before polling starts, so this action has no\n // not-confirmed-but-never-sent case to disambiguate. See\n // `sendAndConfirmTransaction` for the signature path's version.\n const reportBroadcast = (): void => {\n if (broadcastReported) {\n return\n }\n try {\n options?.onBroadcast?.()\n // Latched only after the callback returned. A callback that threw wrote\n // nothing, so the next successful send must be allowed to try again -\n // latching first made one failed `txLink` write permanent.\n broadcastReported = true\n } catch (_) {\n // This runs integrator code: the callback reaches `updateRouteHook` via\n // `StatusManager.updateAction`. Its failure must never reject the branch\n // that called it - the send has already been accepted by the network at\n // this point, so a throw here would report a landed transaction as an\n // RPC outage. Swallowed rather than surfaced because there is no verdict\n // it could honestly change.\n }\n }\n\n const signatures = signedTransactions.map((transaction) =>\n getSignatureFromTransaction(transaction)\n )\n const serializedTransactions = signedTransactions.map((transaction) =>\n getBase64EncodedWireTransaction(transaction)\n )\n\n const lifetimes = await Promise.all(\n signedTransactions.map((transaction) => getTransactionLifetime(transaction))\n )\n\n // One submission for every confirming branch. Its answer is not read: the\n // branches read the signatures, and senders answer `sendBundle` in different\n // shapes. Started by the first branch that asks, so its deadline already\n // runs.\n let submission: Promise<unknown> | undefined\n const submitOnce = (signal: AbortSignal): Promise<unknown> => {\n submission ??= Promise.any(\n submitRpcs.map((rpc) =>\n rpc.sendBundle(serializedTransactions).send({ abortSignal: signal })\n )\n ).catch((error: unknown) => {\n // Surface a refusal the way a single configured RPC would, not as a\n // nested AggregateError inside the race's own error list.\n throw error instanceof AggregateError ? error.errors[0] : error\n })\n return submission\n }\n\n return raceRpcs(\n confirmRpcs,\n (rpc, signal) =>\n confirmBundle({\n rpc,\n signal,\n signatures,\n lifetimes,\n send: () => submitOnce(signal),\n onBroadcast: reportBroadcast,\n }),\n { timeoutMs: BRANCH_TIMEOUT_MS }\n )\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;AAsCA,eAAsB,qBACpB,QACA,oBACA,SAIyC;CAKzC,MAAM,CAAC,aAAa,CAAC,GAAG,YAAY,CAAC,KAAK,MAAM,QAAQ,IAAI,CAC1D,OAAO,4BAA4B,QAAQ,GAAG,GAC9C,OAAO,2BAA2B,QAAQ,GAAG,CAC/C,CAAC;CACD,MAAM,eAAe;EAAE,MAAM,CAAC;EAAoB,aAAa;CAAE;CACjE,MAAM,iBAAiB,YAA0C;EAC/D,MAAM,SAAS,WAAW,SACtB,MAAM,mBAAmB,UAAU,IACnC;EACJ,IAAI,OAAO,KAAK,UAAU,CAAC,UAAU,QACnC,OAAO;EAET,MAAM,QAAQ,MAAM,mBAAmB,SAAS;EAChD,OAAO;GACL,MAAM,MAAM;GACZ,aAAa,OAAO,cAAc,MAAM;EAC1C;CACF;CACA,MAAM,iBAAiB,WAAW,SAAS,KAAK,UAAU,SAAS;CACnE,MAAM,CAAC,EAAE,MAAM,YAAY,eAAe,eAAe,MAAM,QAAQ,IAAI,CACzE,iBAAiB,eAAe,IAAI,YAAY,MAAM,GACtD,cAAc,MAAM,CACtB,CAAC;CAED,IAAI,kBAAkB,CAAC,WAAW,QAAQ;EAExC,MAAM,QAAQ,OAAO,QAAQ;GAAE,QAAQ;GAAY,OAAO;EAAU,CAAC,CAAC,CACnE,QAAQ,GAAG,UAAU,KAAK,SAAS,CAAC,CAAC,CACrC,KAAK,CAAC,UAAU,0BAA0B,KAAK,GAAG,CAAC,CACnD,KAAK,MAAM;EACd,MAAM,IAAI,SACR,cAAc,gBACd;GACE,uCAAuC,MAAM;GAC7C,cAAc,IACV,sJACA;GACJ;EACF,CAAC,CAAC,KAAK,GAAG,CACZ;CACF;CAYA,IAAI,CAAC,WAAW,QACd,MAAM,IAAI,SACR,cAAc,gBACd,cAAc,IACV,iEAAiE,YAAY,uIAC7E,6IACN;CAGF,IAAI,oBAAoB;CAKxB,MAAM,wBAA8B;EAClC,IAAI,mBACF;EAEF,IAAI;GACF,SAAS,cAAc;GAIvB,oBAAoB;EACtB,SAAS,GAAG,CAOZ;CACF;CAEA,MAAM,aAAa,mBAAmB,KAAK,gBACzC,4BAA4B,WAAW,CACzC;CACA,MAAM,yBAAyB,mBAAmB,KAAK,gBACrD,gCAAgC,WAAW,CAC7C;CAEA,MAAM,YAAY,MAAM,QAAQ,IAC9B,mBAAmB,KAAK,gBAAgB,uBAAuB,WAAW,CAAC,CAC7E;CAMA,IAAI;CACJ,MAAM,cAAc,WAA0C;EAC5D,eAAe,QAAQ,IACrB,WAAW,KAAK,QACd,IAAI,WAAW,sBAAsB,CAAC,CAAC,KAAK,EAAE,aAAa,OAAO,CAAC,CACrE,CACF,CAAC,CAAC,OAAO,UAAmB;GAG1B,MAAM,iBAAiB,iBAAiB,MAAM,OAAO,KAAK;EAC5D,CAAC;EACD,OAAO;CACT;CAEA,OAAO,SACL,cACC,KAAK,WACJ,cAAc;EACZ;EACA;EACA;EACA;EACA,YAAY,WAAW,MAAM;EAC7B,aAAa;CACf,CAAC,GACH,EAAE,WAAW,kBAAkB,CACjC;AACF"}
|
|
@@ -1,40 +1,39 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { SolanaRpcType } from "../rpc/types.js";
|
|
2
2
|
import { ConfirmationOutcome, SignatureStatus } from "./types.js";
|
|
3
3
|
import { TransactionLifetime } from "../utils/getTransactionLifetime.js";
|
|
4
4
|
import { Signature } from "@solana/kit";
|
|
5
5
|
//#region src/confirmation/confirmBundle.d.ts
|
|
6
|
-
/** Slower than the signature poller's 400 ms
|
|
7
|
-
*
|
|
8
|
-
*
|
|
6
|
+
/** Slower than the signature poller's 400 ms, to spend fewer requests: the
|
|
7
|
+
* bundle is never resent, so a slower read delays only the verdict, by 2 s at
|
|
8
|
+
* most. `STATUS_RETRY_BACKOFF_CAP_MS` is set against this value. */
|
|
9
9
|
export declare const BUNDLE_POLL_INTERVAL_MS = 2e3;
|
|
10
10
|
export type BundleConfirmation = {
|
|
11
|
-
/**
|
|
12
|
-
|
|
13
|
-
/** Never read for a `txHash` - its order is Jito's to choose. Kept so the
|
|
14
|
-
* reversed-list regression stays expressible in the wait-task spec. */
|
|
15
|
-
txSignatures: Signature[];
|
|
16
|
-
signatureResults: readonly (SignatureStatus | null)[];
|
|
17
|
-
/** Bundle-level `err`, verbatim. Jito encodes it as a Rust `Result`, so a
|
|
18
|
-
* landed bundle carries `{ Ok: null }` - never truthiness-check it. */
|
|
19
|
-
bundleErr: unknown;
|
|
11
|
+
/** One confirmed status per bundle transaction, in bundle order. */
|
|
12
|
+
signatureResults: readonly SignatureStatus[];
|
|
20
13
|
};
|
|
21
14
|
/**
|
|
22
|
-
* Confirms one Jito bundle against one
|
|
15
|
+
* Confirms one Jito bundle against one RPC, by the signatures of its
|
|
16
|
+
* transactions. Every Solana RPC can read them, and a bundle lands whole in
|
|
17
|
+
* one slot, so one read shows all of them confirmed.
|
|
23
18
|
*
|
|
24
19
|
* Bundles submit once, so there is no resend loop. `send` is owned here so the
|
|
25
20
|
* deadline starts before submission rather than after it. A `send` failure
|
|
26
21
|
* throws, which `raceRpcs` buckets as `rpc-unavailable`.
|
|
27
22
|
*/
|
|
28
23
|
export declare function confirmBundle(options: {
|
|
29
|
-
rpc:
|
|
24
|
+
rpc: SolanaRpcType;
|
|
30
25
|
signal: AbortSignal;
|
|
26
|
+
/** The signatures of the bundle's transactions, in bundle order. */
|
|
27
|
+
signatures: Signature[];
|
|
31
28
|
lifetimes: TransactionLifetime[];
|
|
32
|
-
|
|
29
|
+
/** Its answer is not read: senders answer `sendBundle` in different
|
|
30
|
+
* shapes, and the signatures are known before the send. */
|
|
31
|
+
send: () => Promise<unknown>;
|
|
33
32
|
/**
|
|
34
|
-
* Reports that
|
|
33
|
+
* Reports that the shared submission was accepted. Must not throw -
|
|
35
34
|
* `sendAndConfirmBundle` contains any throw from the integrator callback it
|
|
36
|
-
* wraps, because a throw here would reject a branch whose bundle
|
|
37
|
-
* already accepted.
|
|
35
|
+
* wraps, because a throw here would reject a branch whose bundle a submit
|
|
36
|
+
* RPC had already accepted.
|
|
38
37
|
*/
|
|
39
38
|
onBroadcast?: () => void;
|
|
40
39
|
}): Promise<ConfirmationOutcome<BundleConfirmation>>;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"confirmBundle.d.ts","names":[],"sources":["../../../src/confirmation/confirmBundle.ts"],"mappings":";;;;;;;;qBAca;YAED;;EAEV
|
|
1
|
+
{"version":3,"file":"confirmBundle.d.ts","names":[],"sources":["../../../src/confirmation/confirmBundle.ts"],"mappings":";;;;;;;;qBAca;YAED;;EAEV,2BAA2B;;;;;;;;;;;wBAYP,cAAc;EAClC,KAAK;EACL,QAAQ;;EAER,YAAY;EACZ,WAAW;;;EAGX,YAAY;;;;;;;EAOZ;IACE,QAAQ,oBAAoB"}
|
|
@@ -2,43 +2,30 @@ import { createConfirmationDeadline } from "./createConfirmationDeadline.js";
|
|
|
2
2
|
import { pollUntilDeadline } from "./pollUntilDeadline.js";
|
|
3
3
|
import { isConfirmedCommitment } from "./types.js";
|
|
4
4
|
//#region src/confirmation/confirmBundle.ts
|
|
5
|
-
/** Slower than the signature poller's 400 ms
|
|
6
|
-
*
|
|
7
|
-
*
|
|
5
|
+
/** Slower than the signature poller's 400 ms, to spend fewer requests: the
|
|
6
|
+
* bundle is never resent, so a slower read delays only the verdict, by 2 s at
|
|
7
|
+
* most. `STATUS_RETRY_BACKOFF_CAP_MS` is set against this value. */
|
|
8
8
|
const BUNDLE_POLL_INTERVAL_MS = 2e3;
|
|
9
9
|
/**
|
|
10
|
-
* Confirms one Jito bundle against one
|
|
10
|
+
* Confirms one Jito bundle against one RPC, by the signatures of its
|
|
11
|
+
* transactions. Every Solana RPC can read them, and a bundle lands whole in
|
|
12
|
+
* one slot, so one read shows all of them confirmed.
|
|
11
13
|
*
|
|
12
14
|
* Bundles submit once, so there is no resend loop. `send` is owned here so the
|
|
13
15
|
* deadline starts before submission rather than after it. A `send` failure
|
|
14
16
|
* throws, which `raceRpcs` buckets as `rpc-unavailable`.
|
|
15
17
|
*/
|
|
16
18
|
async function confirmBundle(options) {
|
|
17
|
-
const { rpc, signal, lifetimes, send } = options;
|
|
19
|
+
const { rpc, signal, signatures, lifetimes, send } = options;
|
|
18
20
|
const deadline = createConfirmationDeadline({
|
|
19
21
|
lifetimes,
|
|
20
22
|
rpc
|
|
21
23
|
});
|
|
22
|
-
|
|
24
|
+
await send();
|
|
23
25
|
if (!signal.aborted) options.onBroadcast?.();
|
|
24
26
|
const readBundle = async () => {
|
|
25
|
-
const
|
|
26
|
-
|
|
27
|
-
const txSignatures = Array.isArray(bundleStatus.transactions) ? bundleStatus.transactions : [];
|
|
28
|
-
let signatureResults;
|
|
29
|
-
if (txSignatures.length === 0) signatureResults = [];
|
|
30
|
-
else try {
|
|
31
|
-
const sigResponse = await rpc.getSignatureStatuses(txSignatures).send({ abortSignal: signal });
|
|
32
|
-
signatureResults = Array.isArray(sigResponse?.value) ? sigResponse.value : txSignatures.map(() => null);
|
|
33
|
-
} catch (_) {
|
|
34
|
-
signatureResults = txSignatures.map(() => null);
|
|
35
|
-
}
|
|
36
|
-
return {
|
|
37
|
-
bundleId,
|
|
38
|
-
txSignatures,
|
|
39
|
-
signatureResults,
|
|
40
|
-
bundleErr: bundleStatus.err
|
|
41
|
-
};
|
|
27
|
+
const statuses = (await rpc.getSignatureStatuses(signatures).send({ abortSignal: signal }))?.value;
|
|
28
|
+
return Array.isArray(statuses) && statuses.length === signatures.length && statuses.every((status) => isConfirmedCommitment(status?.confirmationStatus)) ? { signatureResults: statuses } : null;
|
|
42
29
|
};
|
|
43
30
|
return pollUntilDeadline({
|
|
44
31
|
deadline,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"confirmBundle.js","names":[],"sources":["../../../src/confirmation/confirmBundle.ts"],"sourcesContent":["import type { Signature } from '@solana/kit'\nimport type {
|
|
1
|
+
{"version":3,"file":"confirmBundle.js","names":[],"sources":["../../../src/confirmation/confirmBundle.ts"],"sourcesContent":["import type { Signature } from '@solana/kit'\nimport type { SolanaRpcType } from '../rpc/types.js'\nimport type { TransactionLifetime } from '../utils/getTransactionLifetime.js'\nimport { createConfirmationDeadline } from './createConfirmationDeadline.js'\nimport { pollUntilDeadline } from './pollUntilDeadline.js'\nimport {\n type ConfirmationOutcome,\n isConfirmedCommitment,\n type SignatureStatus,\n} from './types.js'\n\n/** Slower than the signature poller's 400 ms, to spend fewer requests: the\n * bundle is never resent, so a slower read delays only the verdict, by 2 s at\n * most. `STATUS_RETRY_BACKOFF_CAP_MS` is set against this value. */\nexport const BUNDLE_POLL_INTERVAL_MS = 2_000\n\nexport type BundleConfirmation = {\n /** One confirmed status per bundle transaction, in bundle order. */\n signatureResults: readonly SignatureStatus[]\n}\n\n/**\n * Confirms one Jito bundle against one RPC, by the signatures of its\n * transactions. Every Solana RPC can read them, and a bundle lands whole in\n * one slot, so one read shows all of them confirmed.\n *\n * Bundles submit once, so there is no resend loop. `send` is owned here so the\n * deadline starts before submission rather than after it. A `send` failure\n * throws, which `raceRpcs` buckets as `rpc-unavailable`.\n */\nexport async function confirmBundle(options: {\n rpc: SolanaRpcType\n signal: AbortSignal\n /** The signatures of the bundle's transactions, in bundle order. */\n signatures: Signature[]\n lifetimes: TransactionLifetime[]\n /** Its answer is not read: senders answer `sendBundle` in different\n * shapes, and the signatures are known before the send. */\n send: () => Promise<unknown>\n /**\n * Reports that the shared submission was accepted. Must not throw -\n * `sendAndConfirmBundle` contains any throw from the integrator callback it\n * wraps, because a throw here would reject a branch whose bundle a submit\n * RPC had already accepted.\n */\n onBroadcast?: () => void\n}): Promise<ConfirmationOutcome<BundleConfirmation>> {\n const { rpc, signal, signatures, lifetimes, send } = options\n const deadline = createConfirmationDeadline({ lifetimes, rpc })\n\n await send()\n // Guarded like `confirmSignature`'s send sites: the caller's once-guard\n // latches only after the callback returns, so a throwing integrator hook\n // leaves it open and a late `sendBundle` fulfilment would re-write a\n // finalized action back to PENDING.\n if (!signal.aborted) {\n options.onBroadcast?.()\n }\n\n const readBundle = async (): Promise<BundleConfirmation | null> => {\n const response = await rpc\n .getSignatureStatuses(signatures)\n .send({ abortSignal: signal })\n // A `{ value: null }`, non-array or short answer responded but said\n // nothing - poll again rather than throw a `TypeError` into the\n // read-failure budget.\n const statuses = response?.value\n return Array.isArray(statuses) &&\n statuses.length === signatures.length &&\n statuses.every(\n (status: SignatureStatus | null): status is SignatureStatus =>\n isConfirmedCommitment(status?.confirmationStatus)\n )\n ? { signatureResults: statuses }\n : null\n }\n\n return pollUntilDeadline({\n deadline,\n signal,\n pollIntervalMs: BUNDLE_POLL_INTERVAL_MS,\n probe: readBundle,\n read: 'bundle status read',\n subject: 'bundle',\n })\n}\n"],"mappings":";;;;;;;AAcA,MAAa,0BAA0B;;;;;;;;;;AAgBvC,eAAsB,cAAc,SAgBiB;CACnD,MAAM,EAAE,KAAK,QAAQ,YAAY,WAAW,SAAS;CACrD,MAAM,WAAW,2BAA2B;EAAE;EAAW;CAAI,CAAC;CAE9D,MAAM,KAAK;CAKX,IAAI,CAAC,OAAO,SACV,QAAQ,cAAc;CAGxB,MAAM,aAAa,YAAgD;EAOjE,MAAM,YAAW,MANM,IACpB,qBAAqB,UAAU,CAAC,CAChC,KAAK,EAAE,aAAa,OAAO,CAAC,EAAA,EAIJ;EAC3B,OAAO,MAAM,QAAQ,QAAQ,KAC3B,SAAS,WAAW,WAAW,UAC/B,SAAS,OACN,WACC,sBAAsB,QAAQ,kBAAkB,CACpD,IACE,EAAE,kBAAkB,SAAS,IAC7B;CACN;CAEA,OAAO,kBAAkB;EACvB;EACA;EACA,gBAAgB;EAChB,OAAO;EACP,MAAM;EACN,SAAS;CACX,CAAC;AACH"}
|
|
@@ -7,8 +7,8 @@ import { Signature } from "@solana/kit";
|
|
|
7
7
|
export declare const RESEND_INTERVAL_MS = 1e3;
|
|
8
8
|
/**
|
|
9
9
|
* How often this poller re-reads `getSignatureStatuses`. The default Solana
|
|
10
|
-
* RPCs tolerate 2.5 req/s of status reads; the
|
|
11
|
-
*
|
|
10
|
+
* RPCs tolerate 2.5 req/s of status reads; the bundle poller runs slower
|
|
11
|
+
* (see `confirmBundle`).
|
|
12
12
|
*/
|
|
13
13
|
export declare const SIGNATURE_POLL_INTERVAL_MS = 400;
|
|
14
14
|
/** Confirms one transaction against one RPC. Holds no policy: the deadline
|
|
@@ -7,8 +7,8 @@ import { isConfirmedCommitment } from "./types.js";
|
|
|
7
7
|
const RESEND_INTERVAL_MS = 1e3;
|
|
8
8
|
/**
|
|
9
9
|
* How often this poller re-reads `getSignatureStatuses`. The default Solana
|
|
10
|
-
* RPCs tolerate 2.5 req/s of status reads; the
|
|
11
|
-
*
|
|
10
|
+
* RPCs tolerate 2.5 req/s of status reads; the bundle poller runs slower
|
|
11
|
+
* (see `confirmBundle`).
|
|
12
12
|
*/
|
|
13
13
|
const SIGNATURE_POLL_INTERVAL_MS = 400;
|
|
14
14
|
/** Confirms one transaction against one RPC. Holds no policy: the deadline
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"confirmSignature.js","names":[],"sources":["../../../src/confirmation/confirmSignature.ts"],"sourcesContent":["import type { Signature } from '@solana/kit'\nimport type { SolanaRpcType } from '../rpc/types.js'\nimport type { TransactionLifetime } from '../utils/getTransactionLifetime.js'\nimport { abortableSleep } from './abortableSleep.js'\nimport { createConfirmationDeadline } from './createConfirmationDeadline.js'\nimport { pollUntilDeadline } from './pollUntilDeadline.js'\nimport {\n type ConfirmationOutcome,\n isConfirmedCommitment,\n type SignatureStatus,\n} from './types.js'\n\n/** How often each confirmation branch resends the transaction. */\nexport const RESEND_INTERVAL_MS = 1000\n/**\n * How often this poller re-reads `getSignatureStatuses`. The default Solana\n * RPCs tolerate 2.5 req/s of status reads; the
|
|
1
|
+
{"version":3,"file":"confirmSignature.js","names":[],"sources":["../../../src/confirmation/confirmSignature.ts"],"sourcesContent":["import type { Signature } from '@solana/kit'\nimport type { SolanaRpcType } from '../rpc/types.js'\nimport type { TransactionLifetime } from '../utils/getTransactionLifetime.js'\nimport { abortableSleep } from './abortableSleep.js'\nimport { createConfirmationDeadline } from './createConfirmationDeadline.js'\nimport { pollUntilDeadline } from './pollUntilDeadline.js'\nimport {\n type ConfirmationOutcome,\n isConfirmedCommitment,\n type SignatureStatus,\n} from './types.js'\n\n/** How often each confirmation branch resends the transaction. */\nexport const RESEND_INTERVAL_MS = 1000\n/**\n * How often this poller re-reads `getSignatureStatuses`. The default Solana\n * RPCs tolerate 2.5 req/s of status reads; the bundle poller runs slower\n * (see `confirmBundle`).\n */\nexport const SIGNATURE_POLL_INTERVAL_MS = 400\n\n/** Confirms one transaction against one RPC. Holds no policy: the deadline\n * decides when to stop, and the resend loop only observes an `AbortSignal`. */\nexport async function confirmSignature(options: {\n rpc: SolanaRpcType\n signal: AbortSignal\n signature: Signature\n lifetimes: TransactionLifetime[]\n resend: (rpc: SolanaRpcType, signal: AbortSignal) => Promise<void>\n /**\n * Reports that this RPC accepted a send of the transaction. Must not throw -\n * `sendAndConfirmTransaction` contains any throw from the integrator\n * callback it wraps.\n */\n onBroadcast?: () => void\n}): Promise<ConfirmationOutcome<SignatureStatus>> {\n const { rpc, signal, signature, lifetimes, resend } = options\n const deadline = createConfirmationDeadline({ lifetimes, rpc })\n\n // Ends the resend loop when this branch finishes.\n const branch = new AbortController()\n const abortBranch = (): void => branch.abort()\n signal.addEventListener('abort', abortBranch, { once: true })\n\n let sendSucceeded = false\n\n // Awaited so \"did this RPC ever accept the transaction?\" has a settled\n // answer by the time polling ends, rather than one that depends on\n // microtask ordering.\n try {\n await resend(rpc, signal)\n sendSucceeded = true\n // A send can fulfil after the abort; reporting a broadcast then would\n // regress an action status the wait task already finalized.\n // `sendSucceeded` still latches - the RPC did accept it.\n if (!signal.aborted) {\n options.onBroadcast?.()\n }\n } catch (_) {\n // Continue with confirmation even if the initial send fails — another RPC\n // may already have propagated the transaction.\n }\n\n const resending = (async () => {\n while (!branch.signal.aborted) {\n await abortableSleep(RESEND_INTERVAL_MS, branch.signal)\n if (branch.signal.aborted) {\n break\n }\n try {\n await resend(rpc, branch.signal)\n sendSucceeded = true\n // Same late-fulfilment guard as the first send.\n if (!branch.signal.aborted) {\n options.onBroadcast?.()\n }\n } catch (_) {\n // Resending is best-effort. A total failure is caught by the\n // neverBroadcast check in the verdict.\n }\n }\n })()\n resending.catch(() => {})\n\n const readStatus = async (): Promise<SignatureStatus | null> => {\n const response = await rpc\n .getSignatureStatuses([signature])\n .send({ abortSignal: signal })\n // A `{ value: null }` answer responded but said nothing - poll again\n // rather than throw a `TypeError` into the read-failure budget.\n const status = response?.value?.[0]\n if (status && isConfirmedCommitment(status.confirmationStatus)) {\n return status\n }\n return null\n }\n\n try {\n return await pollUntilDeadline({\n deadline,\n signal,\n pollIntervalMs: SIGNATURE_POLL_INTERVAL_MS,\n probe: readStatus,\n read: 'signature status read',\n subject: 'transaction',\n // Read at verdict time, not captured: the resend loop may succeed long\n // after the awaited first send failed.\n neverBroadcast: () => !sendSucceeded,\n })\n } finally {\n branch.abort()\n signal.removeEventListener('abort', abortBranch)\n }\n}\n"],"mappings":";;;;;;AAaA,MAAa,qBAAqB;;;;;;AAMlC,MAAa,6BAA6B;;;AAI1C,eAAsB,iBAAiB,SAYW;CAChD,MAAM,EAAE,KAAK,QAAQ,WAAW,WAAW,WAAW;CACtD,MAAM,WAAW,2BAA2B;EAAE;EAAW;CAAI,CAAC;CAG9D,MAAM,SAAS,IAAI,gBAAgB;CACnC,MAAM,oBAA0B,OAAO,MAAM;CAC7C,OAAO,iBAAiB,SAAS,aAAa,EAAE,MAAM,KAAK,CAAC;CAE5D,IAAI,gBAAgB;CAKpB,IAAI;EACF,MAAM,OAAO,KAAK,MAAM;EACxB,gBAAgB;EAIhB,IAAI,CAAC,OAAO,SACV,QAAQ,cAAc;CAE1B,SAAS,GAAG,CAGZ;CAqBA,CAnBmB,YAAY;EAC7B,OAAO,CAAC,OAAO,OAAO,SAAS;GAC7B,MAAM,eAAe,oBAAoB,OAAO,MAAM;GACtD,IAAI,OAAO,OAAO,SAChB;GAEF,IAAI;IACF,MAAM,OAAO,KAAK,OAAO,MAAM;IAC/B,gBAAgB;IAEhB,IAAI,CAAC,OAAO,OAAO,SACjB,QAAQ,cAAc;GAE1B,SAAS,GAAG,CAGZ;EACF;CACF,EAAA,CACQ,CAAC,CAAC,YAAY,CAAC,CAAC;CAExB,MAAM,aAAa,YAA6C;EAM9D,MAAM,UAAS,MALQ,IACpB,qBAAqB,CAAC,SAAS,CAAC,CAAC,CACjC,KAAK,EAAE,aAAa,OAAO,CAAC,EAAA,EAGN,QAAQ;EACjC,IAAI,UAAU,sBAAsB,OAAO,kBAAkB,GAC3D,OAAO;EAET,OAAO;CACT;CAEA,IAAI;EACF,OAAO,MAAM,kBAAkB;GAC7B;GACA;GACA,gBAAA;GACA,OAAO;GACP,MAAM;GACN,SAAS;GAGT,sBAAsB,CAAC;EACzB,CAAC;CACH,UAAU;EACR,OAAO,MAAM;EACb,OAAO,oBAAoB,SAAS,WAAW;CACjD;AACF"}
|
|
@@ -25,7 +25,7 @@ export declare const EXPIRY_CONFIRMATIONS: number;
|
|
|
25
25
|
/** Probe failures per blockhash before that blockhash stops being probed.
|
|
26
26
|
* Prober-only; the status pollers have `MAX_STATUS_READ_SILENCE_MS`. */
|
|
27
27
|
export declare const MAX_PROBE_ERRORS = 5;
|
|
28
|
-
/** Structural
|
|
28
|
+
/** Structural: the deadline needs nothing but `isBlockhashValid`. */
|
|
29
29
|
export type BlockhashProbeRpc = Pick<SolanaRpcType, "isBlockhashValid">;
|
|
30
30
|
export interface ConfirmationDeadline {
|
|
31
31
|
/** Checked at the top of every poll iteration. */
|