@lifi/sdk-provider-solana 4.0.7 → 4.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +110 -0
- package/dist/cjs/actions/sendAndConfirmBundle.d.ts +18 -25
- package/dist/cjs/actions/sendAndConfirmBundle.js +33 -54
- package/dist/cjs/actions/sendAndConfirmBundle.js.map +1 -1
- package/dist/cjs/actions/sendAndConfirmTransaction.d.ts +14 -22
- package/dist/cjs/actions/sendAndConfirmTransaction.js +38 -55
- package/dist/cjs/actions/sendAndConfirmTransaction.js.map +1 -1
- package/dist/cjs/confirmation/abortableSleep.d.ts +19 -0
- package/dist/cjs/confirmation/abortableSleep.js +32 -0
- package/dist/cjs/confirmation/abortableSleep.js.map +1 -0
- package/dist/cjs/confirmation/confirmBundle.d.ts +43 -0
- package/dist/cjs/confirmation/confirmBundle.js +57 -0
- package/dist/cjs/confirmation/confirmBundle.js.map +1 -0
- package/dist/cjs/confirmation/confirmSignature.d.ts +29 -0
- package/dist/cjs/confirmation/confirmSignature.js +66 -0
- package/dist/cjs/confirmation/confirmSignature.js.map +1 -0
- package/dist/cjs/confirmation/createConfirmationDeadline.d.ts +51 -0
- package/dist/cjs/confirmation/createConfirmationDeadline.js +101 -0
- package/dist/cjs/confirmation/createConfirmationDeadline.js.map +1 -0
- package/dist/cjs/confirmation/pollUntilDeadline.d.ts +58 -0
- package/dist/cjs/confirmation/pollUntilDeadline.js +97 -0
- package/dist/cjs/confirmation/pollUntilDeadline.js.map +1 -0
- package/dist/cjs/confirmation/raceRpcs.d.ts +26 -0
- package/dist/cjs/confirmation/raceRpcs.js +93 -0
- package/dist/cjs/confirmation/raceRpcs.js.map +1 -0
- package/dist/cjs/confirmation/types.d.ts +18 -0
- package/dist/cjs/confirmation/types.js +9 -0
- package/dist/cjs/confirmation/types.js.map +1 -0
- package/dist/cjs/core/tasks/SolanaJitoWaitForTransactionTask.js +30 -9
- package/dist/cjs/core/tasks/SolanaJitoWaitForTransactionTask.js.map +1 -1
- package/dist/cjs/core/tasks/SolanaSignAndExecuteTask.js +5 -1
- package/dist/cjs/core/tasks/SolanaSignAndExecuteTask.js.map +1 -1
- package/dist/cjs/core/tasks/SolanaStandardWaitForTransactionTask.js +20 -7
- package/dist/cjs/core/tasks/SolanaStandardWaitForTransactionTask.js.map +1 -1
- package/dist/cjs/core/tasks/readSignature.d.ts +17 -0
- package/dist/cjs/core/tasks/readSignature.js +26 -0
- package/dist/cjs/core/tasks/readSignature.js.map +1 -0
- package/dist/cjs/core/tasks/unwrapConfirmation.d.ts +25 -0
- package/dist/cjs/core/tasks/unwrapConfirmation.js +24 -0
- package/dist/cjs/core/tasks/unwrapConfirmation.js.map +1 -0
- package/dist/cjs/rpc/jito/api/getBundleStatuses.d.ts +4 -2
- package/dist/cjs/rpc/registry.d.ts +37 -11
- package/dist/cjs/rpc/registry.js +103 -18
- package/dist/cjs/rpc/registry.js.map +1 -1
- package/dist/cjs/rpc/utils.js +1 -1
- package/dist/cjs/rpc/utils.js.map +1 -1
- package/dist/cjs/utils/KeypairWalletAdapter.js +10 -4
- package/dist/cjs/utils/KeypairWalletAdapter.js.map +1 -1
- package/dist/cjs/utils/getTransactionLifetime.d.ts +21 -0
- package/dist/cjs/utils/getTransactionLifetime.js +28 -0
- package/dist/cjs/utils/getTransactionLifetime.js.map +1 -0
- 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 +18 -25
- package/dist/esm/actions/sendAndConfirmBundle.d.ts.map +1 -1
- package/dist/esm/actions/sendAndConfirmBundle.js +34 -55
- package/dist/esm/actions/sendAndConfirmBundle.js.map +1 -1
- package/dist/esm/actions/sendAndConfirmTransaction.d.ts +14 -22
- package/dist/esm/actions/sendAndConfirmTransaction.d.ts.map +1 -1
- package/dist/esm/actions/sendAndConfirmTransaction.js +38 -55
- package/dist/esm/actions/sendAndConfirmTransaction.js.map +1 -1
- package/dist/esm/confirmation/abortableSleep.d.ts +19 -0
- package/dist/esm/confirmation/abortableSleep.d.ts.map +1 -0
- package/dist/esm/confirmation/abortableSleep.js +31 -0
- package/dist/esm/confirmation/abortableSleep.js.map +1 -0
- package/dist/esm/confirmation/confirmBundle.d.ts +43 -0
- package/dist/esm/confirmation/confirmBundle.d.ts.map +1 -0
- package/dist/esm/confirmation/confirmBundle.js +55 -0
- package/dist/esm/confirmation/confirmBundle.js.map +1 -0
- package/dist/esm/confirmation/confirmSignature.d.ts +29 -0
- package/dist/esm/confirmation/confirmSignature.d.ts.map +1 -0
- package/dist/esm/confirmation/confirmSignature.js +64 -0
- package/dist/esm/confirmation/confirmSignature.js.map +1 -0
- package/dist/esm/confirmation/createConfirmationDeadline.d.ts +51 -0
- package/dist/esm/confirmation/createConfirmationDeadline.d.ts.map +1 -0
- package/dist/esm/confirmation/createConfirmationDeadline.js +93 -0
- package/dist/esm/confirmation/createConfirmationDeadline.js.map +1 -0
- package/dist/esm/confirmation/pollUntilDeadline.d.ts +58 -0
- package/dist/esm/confirmation/pollUntilDeadline.d.ts.map +1 -0
- package/dist/esm/confirmation/pollUntilDeadline.js +93 -0
- package/dist/esm/confirmation/pollUntilDeadline.js.map +1 -0
- package/dist/esm/confirmation/raceRpcs.d.ts +26 -0
- package/dist/esm/confirmation/raceRpcs.d.ts.map +1 -0
- package/dist/esm/confirmation/raceRpcs.js +92 -0
- package/dist/esm/confirmation/raceRpcs.js.map +1 -0
- package/dist/esm/confirmation/types.d.ts +18 -0
- package/dist/esm/confirmation/types.d.ts.map +1 -0
- package/dist/esm/confirmation/types.js +8 -0
- package/dist/esm/confirmation/types.js.map +1 -0
- package/dist/esm/core/tasks/SolanaJitoWaitForTransactionTask.d.ts.map +1 -1
- package/dist/esm/core/tasks/SolanaJitoWaitForTransactionTask.js +30 -9
- package/dist/esm/core/tasks/SolanaJitoWaitForTransactionTask.js.map +1 -1
- package/dist/esm/core/tasks/SolanaSignAndExecuteTask.js +5 -1
- package/dist/esm/core/tasks/SolanaSignAndExecuteTask.js.map +1 -1
- package/dist/esm/core/tasks/SolanaStandardWaitForTransactionTask.d.ts.map +1 -1
- package/dist/esm/core/tasks/SolanaStandardWaitForTransactionTask.js +20 -7
- package/dist/esm/core/tasks/SolanaStandardWaitForTransactionTask.js.map +1 -1
- package/dist/esm/core/tasks/readSignature.d.ts +17 -0
- package/dist/esm/core/tasks/readSignature.d.ts.map +1 -0
- package/dist/esm/core/tasks/readSignature.js +25 -0
- package/dist/esm/core/tasks/readSignature.js.map +1 -0
- package/dist/esm/core/tasks/unwrapConfirmation.d.ts +25 -0
- package/dist/esm/core/tasks/unwrapConfirmation.d.ts.map +1 -0
- package/dist/esm/core/tasks/unwrapConfirmation.js +23 -0
- package/dist/esm/core/tasks/unwrapConfirmation.js.map +1 -0
- package/dist/esm/rpc/jito/api/getBundleStatuses.d.ts +4 -2
- package/dist/esm/rpc/jito/api/getBundleStatuses.d.ts.map +1 -1
- package/dist/esm/rpc/registry.d.ts +37 -11
- package/dist/esm/rpc/registry.d.ts.map +1 -1
- package/dist/esm/rpc/registry.js +102 -19
- package/dist/esm/rpc/registry.js.map +1 -1
- package/dist/esm/rpc/utils.js +1 -1
- package/dist/esm/rpc/utils.js.map +1 -1
- package/dist/esm/utils/KeypairWalletAdapter.d.ts.map +1 -1
- package/dist/esm/utils/KeypairWalletAdapter.js +11 -5
- package/dist/esm/utils/KeypairWalletAdapter.js.map +1 -1
- package/dist/esm/utils/getTransactionLifetime.d.ts +21 -0
- package/dist/esm/utils/getTransactionLifetime.d.ts.map +1 -0
- package/dist/esm/utils/getTransactionLifetime.js +27 -0
- package/dist/esm/utils/getTransactionLifetime.js.map +1 -0
- 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 +4 -4
- package/src/actions/sendAndConfirmBundle.ts +82 -142
- package/src/actions/sendAndConfirmTransaction.ts +82 -134
- package/src/confirmation/abortableSleep.ts +30 -0
- package/src/confirmation/confirmBundle.ts +121 -0
- package/src/confirmation/confirmSignature.ts +113 -0
- package/src/confirmation/createConfirmationDeadline.ts +174 -0
- package/src/confirmation/pollUntilDeadline.ts +182 -0
- package/src/confirmation/raceRpcs.ts +135 -0
- package/src/confirmation/types.ts +23 -0
- package/src/core/tasks/SolanaJitoWaitForTransactionTask.ts +49 -16
- package/src/core/tasks/SolanaSignAndExecuteTask.ts +15 -0
- package/src/core/tasks/SolanaStandardWaitForTransactionTask.ts +28 -17
- package/src/core/tasks/readSignature.ts +29 -0
- package/src/core/tasks/unwrapConfirmation.ts +59 -0
- package/src/rpc/jito/api/getBundleStatuses.ts +4 -2
- package/src/rpc/registry.ts +183 -25
- package/src/rpc/utils.ts +5 -2
- package/src/utils/KeypairWalletAdapter.ts +34 -9
- package/src/utils/getTransactionLifetime.ts +38 -0
- package/src/version.ts +1 -1
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
import { callSolanaRpcsWithRetry } from "../../rpc/utils.js";
|
|
2
2
|
import { SolanaTransactionDetailsError } from "../../utils/solanaErrorCause.js";
|
|
3
|
+
import { readSignature } from "./readSignature.js";
|
|
4
|
+
import { unwrapConfirmation } from "./unwrapConfirmation.js";
|
|
3
5
|
import { sendAndConfirmTransaction } from "../../actions/sendAndConfirmTransaction.js";
|
|
4
6
|
import { BaseStepExecutionTask, LiFiErrorCode, TransactionError } from "@lifi/sdk";
|
|
5
7
|
import { getBase64EncodedWireTransaction } from "@solana/kit";
|
|
@@ -24,16 +26,27 @@ var SolanaStandardWaitForTransactionTask = class extends BaseStepExecutionTask {
|
|
|
24
26
|
throw new TransactionError(LiFiErrorCode.TransactionSimulationFailed, `Transaction simulation failed: ${cause.message}`, cause);
|
|
25
27
|
}
|
|
26
28
|
}
|
|
27
|
-
const
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
29
|
+
const txSignature = readSignature(signedTransaction);
|
|
30
|
+
const txLink = `${fromChain.metamask.blockExplorerUrls[0]}tx/${txSignature}`;
|
|
31
|
+
const result = await sendAndConfirmTransaction(client, signedTransaction, { onBroadcast: () => {
|
|
32
|
+
statusManager.updateAction(step, action.type, "PENDING", {
|
|
33
|
+
txHash: txSignature,
|
|
34
|
+
txLink
|
|
35
|
+
});
|
|
36
|
+
} });
|
|
37
|
+
const status = unwrapConfirmation(result, {
|
|
38
|
+
rpcUnavailable: "Unable to confirm transaction: no Solana RPC returned a usable response.",
|
|
39
|
+
notConfirmed: "Transaction was not confirmed before the SDK stopped waiting.",
|
|
40
|
+
allRpcsFailed: "All Solana RPCs failed",
|
|
41
|
+
someRpcsFailed: "Some Solana RPCs failed while the confirmation window was open"
|
|
42
|
+
});
|
|
43
|
+
if (status.err) {
|
|
44
|
+
const cause = new SolanaTransactionDetailsError(status.err);
|
|
31
45
|
throw new TransactionError(LiFiErrorCode.TransactionFailed, `Transaction failed: ${cause.message}`, cause);
|
|
32
46
|
}
|
|
33
|
-
const confirmedTransaction = { txSignature: result.txSignature };
|
|
34
47
|
statusManager.updateAction(step, action.type, "PENDING", {
|
|
35
|
-
txHash:
|
|
36
|
-
txLink
|
|
48
|
+
txHash: txSignature,
|
|
49
|
+
txLink
|
|
37
50
|
});
|
|
38
51
|
if (isBridgeExecution) statusManager.updateAction(step, action.type, "DONE");
|
|
39
52
|
return { status: "COMPLETED" };
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"SolanaStandardWaitForTransactionTask.js","names":[],"sources":["../../../../src/core/tasks/SolanaStandardWaitForTransactionTask.ts"],"sourcesContent":["import {\n BaseStepExecutionTask,\n LiFiErrorCode,\n type TaskResult,\n TransactionError,\n} from '@lifi/sdk'\nimport { getBase64EncodedWireTransaction } from '@solana/kit'\nimport { sendAndConfirmTransaction } from '../../actions/sendAndConfirmTransaction.js'\nimport { callSolanaRpcsWithRetry } from '../../rpc/utils.js'\nimport type { SolanaStepExecutorContext } from '../../types.js'\nimport { SolanaTransactionDetailsError } from '../../utils/solanaErrorCause.js'\n\nexport class SolanaStandardWaitForTransactionTask extends BaseStepExecutionTask {\n async run(context: SolanaStepExecutorContext): Promise<TaskResult> {\n const {\n client,\n step,\n statusManager,\n fromChain,\n isBridgeExecution,\n signedTransactions: contextSignedTransactions,\n } = context\n\n const signedTransactions = contextSignedTransactions ?? []\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 if (!signedTransactions.length) {\n throw new TransactionError(\n LiFiErrorCode.TransactionUnprepared,\n 'Unable to prepare transaction. Signed transactions are not found.'\n )\n }\n\n // Use regular transaction submission\n const signedTransaction = signedTransactions[0]\n\n const encodedTransaction =\n getBase64EncodedWireTransaction(signedTransaction)\n\n if (!context.skipSimulation) {\n const simulationResult = await callSolanaRpcsWithRetry(\n client,\n (connection) =>\n connection\n .simulateTransaction(encodedTransaction, {\n commitment: 'confirmed',\n replaceRecentBlockhash: true,\n encoding: 'base64',\n })\n .send()\n )\n\n if (simulationResult.value.err) {\n const cause = new SolanaTransactionDetailsError(\n simulationResult.value.err,\n simulationResult.value.logs\n )\n throw new TransactionError(\n LiFiErrorCode.TransactionSimulationFailed,\n `Transaction simulation failed: ${cause.message}`,\n cause\n )\n }\n }\n\n const result = await sendAndConfirmTransaction(client, signedTransaction)\n\n
|
|
1
|
+
{"version":3,"file":"SolanaStandardWaitForTransactionTask.js","names":[],"sources":["../../../../src/core/tasks/SolanaStandardWaitForTransactionTask.ts"],"sourcesContent":["import {\n BaseStepExecutionTask,\n LiFiErrorCode,\n type TaskResult,\n TransactionError,\n} from '@lifi/sdk'\nimport { getBase64EncodedWireTransaction } from '@solana/kit'\nimport { sendAndConfirmTransaction } from '../../actions/sendAndConfirmTransaction.js'\nimport { callSolanaRpcsWithRetry } from '../../rpc/utils.js'\nimport type { SolanaStepExecutorContext } from '../../types.js'\nimport { SolanaTransactionDetailsError } from '../../utils/solanaErrorCause.js'\nimport { readSignature } from './readSignature.js'\nimport { unwrapConfirmation } from './unwrapConfirmation.js'\n\nexport class SolanaStandardWaitForTransactionTask extends BaseStepExecutionTask {\n async run(context: SolanaStepExecutorContext): Promise<TaskResult> {\n const {\n client,\n step,\n statusManager,\n fromChain,\n isBridgeExecution,\n signedTransactions: contextSignedTransactions,\n } = context\n\n const signedTransactions = contextSignedTransactions ?? []\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 if (!signedTransactions.length) {\n throw new TransactionError(\n LiFiErrorCode.TransactionUnprepared,\n 'Unable to prepare transaction. Signed transactions are not found.'\n )\n }\n\n // Use regular transaction submission\n const signedTransaction = signedTransactions[0]\n\n const encodedTransaction =\n getBase64EncodedWireTransaction(signedTransaction)\n\n if (!context.skipSimulation) {\n const simulationResult = await callSolanaRpcsWithRetry(\n client,\n (connection) =>\n connection\n .simulateTransaction(encodedTransaction, {\n commitment: 'confirmed',\n replaceRecentBlockhash: true,\n encoding: 'base64',\n })\n .send()\n )\n\n if (simulationResult.value.err) {\n const cause = new SolanaTransactionDetailsError(\n simulationResult.value.err,\n simulationResult.value.logs\n )\n throw new TransactionError(\n LiFiErrorCode.TransactionSimulationFailed,\n `Transaction simulation failed: ${cause.message}`,\n cause\n )\n }\n }\n\n const txSignature = readSignature(signedTransaction)\n const txLink = `${fromChain.metamask.blockExplorerUrls[0]}tx/${txSignature}`\n\n const result = await sendAndConfirmTransaction(client, signedTransaction, {\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: txSignature,\n txLink,\n })\n },\n })\n\n const status = unwrapConfirmation(result, {\n rpcUnavailable:\n 'Unable to confirm transaction: no Solana RPC returned a usable response.',\n notConfirmed:\n 'Transaction 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 if (status.err) {\n const cause = new SolanaTransactionDetailsError(status.err)\n throw new TransactionError(\n LiFiErrorCode.TransactionFailed,\n `Transaction failed: ${cause.message}`,\n cause\n )\n }\n\n // Transaction has been confirmed and we can update the action\n statusManager.updateAction(step, action.type, 'PENDING', {\n txHash: txSignature,\n txLink,\n })\n\n if (isBridgeExecution) {\n statusManager.updateAction(step, action.type, 'DONE')\n }\n\n return { status: 'COMPLETED' }\n }\n}\n"],"mappings":";;;;;;;;AAcA,IAAa,uCAAb,cAA0D,sBAAsB;CAC9E,MAAM,IAAI,SAAyD;EACjE,MAAM,EACJ,QACA,MACA,eACA,WACA,mBACA,oBAAoB,8BAClB;EAEJ,MAAM,qBAAqB,6BAA6B,CAAC;EAEzD,MAAM,SAAS,cAAc,WAC3B,MACA,oBAAoB,gBAAgB,MACtC;EACA,IAAI,CAAC,QACH,MAAM,IAAI,iBACR,cAAc,uBACd,kDACF;EAGF,IAAI,CAAC,mBAAmB,QACtB,MAAM,IAAI,iBACR,cAAc,uBACd,mEACF;EAIF,MAAM,oBAAoB,mBAAmB;EAE7C,MAAM,qBACJ,gCAAgC,iBAAiB;EAEnD,IAAI,CAAC,QAAQ,gBAAgB;GAC3B,MAAM,mBAAmB,MAAM,wBAC7B,SACC,eACC,WACG,oBAAoB,oBAAoB;IACvC,YAAY;IACZ,wBAAwB;IACxB,UAAU;GACZ,CAAC,CAAC,CACD,KAAK,CACZ;GAEA,IAAI,iBAAiB,MAAM,KAAK;IAC9B,MAAM,QAAQ,IAAI,8BAChB,iBAAiB,MAAM,KACvB,iBAAiB,MAAM,IACzB;IACA,MAAM,IAAI,iBACR,cAAc,6BACd,kCAAkC,MAAM,WACxC,KACF;GACF;EACF;EAEA,MAAM,cAAc,cAAc,iBAAiB;EACnD,MAAM,SAAS,GAAG,UAAU,SAAS,kBAAkB,GAAG,KAAK;EAE/D,MAAM,SAAS,MAAM,0BAA0B,QAAQ,mBAAmB,EACxE,mBAAmB;GAGjB,cAAc,aAAa,MAAM,OAAO,MAAM,WAAW;IACvD,QAAQ;IACR;GACF,CAAC;EACH,EACF,CAAC;EAED,MAAM,SAAS,mBAAmB,QAAQ;GACxC,gBACE;GACF,cACE;GACF,eAAe;GACf,gBACE;EACJ,CAAC;EAED,IAAI,OAAO,KAAK;GACd,MAAM,QAAQ,IAAI,8BAA8B,OAAO,GAAG;GAC1D,MAAM,IAAI,iBACR,cAAc,mBACd,uBAAuB,MAAM,WAC7B,KACF;EACF;EAGA,cAAc,aAAa,MAAM,OAAO,MAAM,WAAW;GACvD,QAAQ;GACR;EACF,CAAC;EAED,IAAI,mBACF,cAAc,aAAa,MAAM,OAAO,MAAM,MAAM;EAGtD,OAAO,EAAE,QAAQ,YAAY;CAC/B;AACF"}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { Signature, Transaction } from "@solana/kit";
|
|
2
|
+
//#region src/core/tasks/readSignature.d.ts
|
|
3
|
+
/**
|
|
4
|
+
* Reads a signed transaction's signature, restating a `@solana/kit` failure as
|
|
5
|
+
* a `TransactionError`.
|
|
6
|
+
*
|
|
7
|
+
* Both wait tasks derive the signature before they submit, so this call is on
|
|
8
|
+
* the execution path. `getSignatureFromTransaction` throws a bare
|
|
9
|
+
* `SolanaError` when the fee payer's slot is null - a wallet that returned a
|
|
10
|
+
* partially signed transaction, or a bundle whose first entry is signed by
|
|
11
|
+
* someone else. Integrator error branching switches on `LiFiErrorCode`, so an
|
|
12
|
+
* unwrapped throw lands in the unknown bucket.
|
|
13
|
+
*/
|
|
14
|
+
declare function readSignature(transaction: Transaction): Signature;
|
|
15
|
+
//#endregion
|
|
16
|
+
export { readSignature };
|
|
17
|
+
//# sourceMappingURL=readSignature.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"readSignature.d.ts","names":[],"sources":["../../../../src/core/tasks/readSignature.ts"],"mappings":";;;;;;;;;;;;;iBAkBgB,cAAc,aAAa,cAAc"}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { LiFiErrorCode, TransactionError } from "@lifi/sdk";
|
|
2
|
+
import { getSignatureFromTransaction } from "@solana/kit";
|
|
3
|
+
//#region src/core/tasks/readSignature.ts
|
|
4
|
+
/**
|
|
5
|
+
* Reads a signed transaction's signature, restating a `@solana/kit` failure as
|
|
6
|
+
* a `TransactionError`.
|
|
7
|
+
*
|
|
8
|
+
* Both wait tasks derive the signature before they submit, so this call is on
|
|
9
|
+
* the execution path. `getSignatureFromTransaction` throws a bare
|
|
10
|
+
* `SolanaError` when the fee payer's slot is null - a wallet that returned a
|
|
11
|
+
* partially signed transaction, or a bundle whose first entry is signed by
|
|
12
|
+
* someone else. Integrator error branching switches on `LiFiErrorCode`, so an
|
|
13
|
+
* unwrapped throw lands in the unknown bucket.
|
|
14
|
+
*/
|
|
15
|
+
function readSignature(transaction) {
|
|
16
|
+
try {
|
|
17
|
+
return getSignatureFromTransaction(transaction);
|
|
18
|
+
} catch (error) {
|
|
19
|
+
throw new TransactionError(LiFiErrorCode.TransactionUnprepared, "Unable to prepare transaction. The signed transaction carries no fee payer signature.", error);
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
//#endregion
|
|
23
|
+
export { readSignature };
|
|
24
|
+
|
|
25
|
+
//# sourceMappingURL=readSignature.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"readSignature.js","names":[],"sources":["../../../../src/core/tasks/readSignature.ts"],"sourcesContent":["import { LiFiErrorCode, TransactionError } from '@lifi/sdk'\nimport {\n getSignatureFromTransaction,\n type Signature,\n type Transaction,\n} from '@solana/kit'\n\n/**\n * Reads a signed transaction's signature, restating a `@solana/kit` failure as\n * a `TransactionError`.\n *\n * Both wait tasks derive the signature before they submit, so this call is on\n * the execution path. `getSignatureFromTransaction` throws a bare\n * `SolanaError` when the fee payer's slot is null - a wallet that returned a\n * partially signed transaction, or a bundle whose first entry is signed by\n * someone else. Integrator error branching switches on `LiFiErrorCode`, so an\n * unwrapped throw lands in the unknown bucket.\n */\nexport function readSignature(transaction: Transaction): Signature {\n try {\n return getSignatureFromTransaction(transaction)\n } catch (error) {\n throw new TransactionError(\n LiFiErrorCode.TransactionUnprepared,\n 'Unable to prepare transaction. The signed transaction carries no fee payer signature.',\n error as Error\n )\n }\n}\n"],"mappings":";;;;;;;;;;;;;;AAkBA,SAAgB,cAAc,aAAqC;CACjE,IAAI;EACF,OAAO,4BAA4B,WAAW;CAChD,SAAS,OAAO;EACd,MAAM,IAAI,iBACR,cAAc,uBACd,yFACA,KACF;CACF;AACF"}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { RaceResult } from "../../confirmation/raceRpcs.js";
|
|
2
|
+
//#region src/core/tasks/unwrapConfirmation.d.ts
|
|
3
|
+
/** Only the nouns differ between the standard and bundle paths. */
|
|
4
|
+
type ConfirmationMessages = {
|
|
5
|
+
/** Every branch failed: an outage, not a verdict about the transaction. */
|
|
6
|
+
rpcUnavailable: string;
|
|
7
|
+
/** A branch polled to its deadline and saw nothing. */
|
|
8
|
+
notConfirmed: string;
|
|
9
|
+
/** Heading of the `AggregateError` chained onto `rpcUnavailable`. */
|
|
10
|
+
allRpcsFailed: string;
|
|
11
|
+
/** Heading of the `AggregateError` chained onto `notConfirmed`. */
|
|
12
|
+
someRpcsFailed: string;
|
|
13
|
+
};
|
|
14
|
+
/**
|
|
15
|
+
* Returns the confirmed value, or throws the error the integrator sees.
|
|
16
|
+
*
|
|
17
|
+
* Both wait tasks map the same three outcomes onto the same two error classes,
|
|
18
|
+
* so the mapping lives here once. `rpc-unavailable` and `not-confirmed` must
|
|
19
|
+
* stay distinct: collapsing them reported a live RPC defect as an expired
|
|
20
|
+
* transaction.
|
|
21
|
+
*/
|
|
22
|
+
declare function unwrapConfirmation<T>(result: RaceResult<T>, messages: ConfirmationMessages): T;
|
|
23
|
+
//#endregion
|
|
24
|
+
export { ConfirmationMessages, unwrapConfirmation };
|
|
25
|
+
//# sourceMappingURL=unwrapConfirmation.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"unwrapConfirmation.d.ts","names":[],"sources":["../../../../src/core/tasks/unwrapConfirmation.ts"],"mappings":";;;KAIY;;EAEV;;EAEA;;EAEA;;EAEA;;;;;;;;;;iBAsBc,mBAAmB,GACjC,QAAQ,WAAW,IACnB,UAAU,uBACT"}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { LiFiErrorCode, RPCError, TransactionError } from "@lifi/sdk";
|
|
2
|
+
//#region src/core/tasks/unwrapConfirmation.ts
|
|
3
|
+
/** `cause` is the first collected error on purpose: `BaseError` overwrites its
|
|
4
|
+
* stack with `getRootCause(cause).stack`, and an `AggregateError` has no
|
|
5
|
+
* `cause`, so without it the stack would point at this file. */
|
|
6
|
+
const chainErrors = (errors, message) => errors.length ? new AggregateError(errors, message, { cause: errors[0] }) : void 0;
|
|
7
|
+
/**
|
|
8
|
+
* Returns the confirmed value, or throws the error the integrator sees.
|
|
9
|
+
*
|
|
10
|
+
* Both wait tasks map the same three outcomes onto the same two error classes,
|
|
11
|
+
* so the mapping lives here once. `rpc-unavailable` and `not-confirmed` must
|
|
12
|
+
* stay distinct: collapsing them reported a live RPC defect as an expired
|
|
13
|
+
* transaction.
|
|
14
|
+
*/
|
|
15
|
+
function unwrapConfirmation(result, messages) {
|
|
16
|
+
if (result.kind === "rpc-unavailable") throw new RPCError(LiFiErrorCode.RpcUnavailable, messages.rpcUnavailable, chainErrors(result.errors, messages.allRpcsFailed));
|
|
17
|
+
if (result.kind === "not-confirmed") throw new TransactionError(LiFiErrorCode.TransactionExpired, messages.notConfirmed, chainErrors(result.errors, messages.someRpcsFailed));
|
|
18
|
+
return result.value;
|
|
19
|
+
}
|
|
20
|
+
//#endregion
|
|
21
|
+
export { unwrapConfirmation };
|
|
22
|
+
|
|
23
|
+
//# sourceMappingURL=unwrapConfirmation.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"unwrapConfirmation.js","names":[],"sources":["../../../../src/core/tasks/unwrapConfirmation.ts"],"sourcesContent":["import { LiFiErrorCode, RPCError, TransactionError } from '@lifi/sdk'\nimport type { RaceResult } from '../../confirmation/raceRpcs.js'\n\n/** Only the nouns differ between the standard and bundle paths. */\nexport type ConfirmationMessages = {\n /** Every branch failed: an outage, not a verdict about the transaction. */\n rpcUnavailable: string\n /** A branch polled to its deadline and saw nothing. */\n notConfirmed: string\n /** Heading of the `AggregateError` chained onto `rpcUnavailable`. */\n allRpcsFailed: string\n /** Heading of the `AggregateError` chained onto `notConfirmed`. */\n someRpcsFailed: string\n}\n\n/** `cause` is the first collected error on purpose: `BaseError` overwrites its\n * stack with `getRootCause(cause).stack`, and an `AggregateError` has no\n * `cause`, so without it the stack would point at this file. */\nconst chainErrors = (\n errors: Error[],\n message: string\n): AggregateError | undefined =>\n errors.length\n ? new AggregateError(errors, message, { cause: errors[0] })\n : undefined\n\n/**\n * Returns the confirmed value, or throws the error the integrator sees.\n *\n * Both wait tasks map the same three outcomes onto the same two error classes,\n * so the mapping lives here once. `rpc-unavailable` and `not-confirmed` must\n * stay distinct: collapsing them reported a live RPC defect as an expired\n * transaction.\n */\nexport function unwrapConfirmation<T>(\n result: RaceResult<T>,\n messages: ConfirmationMessages\n): T {\n if (result.kind === 'rpc-unavailable') {\n throw new RPCError(\n LiFiErrorCode.RpcUnavailable,\n messages.rpcUnavailable,\n chainErrors(result.errors, messages.allRpcsFailed)\n )\n }\n\n if (result.kind === 'not-confirmed') {\n // The verdict came from a branch that polled to its deadline and saw\n // nothing, but other branches may have died trying - and their errors are\n // the only trail explaining, say, an endpoint that never answered.\n throw new TransactionError(\n LiFiErrorCode.TransactionExpired,\n messages.notConfirmed,\n chainErrors(result.errors, messages.someRpcsFailed)\n )\n }\n\n return result.value\n}\n"],"mappings":";;;;;AAkBA,MAAM,eACJ,QACA,YAEA,OAAO,SACH,IAAI,eAAe,QAAQ,SAAS,EAAE,OAAO,OAAO,GAAG,CAAC,IACxD,KAAA;;;;;;;;;AAUN,SAAgB,mBACd,QACA,UACG;CACH,IAAI,OAAO,SAAS,mBAClB,MAAM,IAAI,SACR,cAAc,gBACd,SAAS,gBACT,YAAY,OAAO,QAAQ,SAAS,aAAa,CACnD;CAGF,IAAI,OAAO,SAAS,iBAIlB,MAAM,IAAI,iBACR,cAAc,oBACd,SAAS,cACT,YAAY,OAAO,QAAQ,SAAS,cAAc,CACpD;CAGF,OAAO,OAAO;AAChB"}
|
|
@@ -3,7 +3,8 @@ import { Signature } from "@solana/kit";
|
|
|
3
3
|
//#region src/rpc/jito/api/getBundleStatuses.d.ts
|
|
4
4
|
type BundleStatus = {
|
|
5
5
|
bundle_id: string;
|
|
6
|
-
|
|
6
|
+
/** Optional: unvalidated wire data, so the reader must handle its absence. */
|
|
7
|
+
transactions?: Signature[];
|
|
7
8
|
slot: number;
|
|
8
9
|
confirmation_status: "processed" | "confirmed" | "finalized" | null;
|
|
9
10
|
err: unknown;
|
|
@@ -12,7 +13,8 @@ type GetBundleStatusesResponse = {
|
|
|
12
13
|
context: {
|
|
13
14
|
slot: number;
|
|
14
15
|
};
|
|
15
|
-
|
|
16
|
+
/** Jito answers with `null` for a bundle id it does not know. */
|
|
17
|
+
value: (BundleStatus | null)[];
|
|
16
18
|
};
|
|
17
19
|
type GetBundleStatusesApi = {
|
|
18
20
|
/**
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"getBundleStatuses.d.ts","names":[],"sources":["../../../../../src/rpc/jito/api/getBundleStatuses.ts"],"mappings":";;;KAIK;EACH
|
|
1
|
+
{"version":3,"file":"getBundleStatuses.d.ts","names":[],"sources":["../../../../../src/rpc/jito/api/getBundleStatuses.ts"],"mappings":";;;KAIK;EACH;;EAEA,eAAe;EACf;EACA;EACA;;KAGG;EACH;IACE;;;EAGF,QAAQ;;KAGE;;;;;EAKV,kBAEE,qBAEA,SAAS,aACR"}
|
|
@@ -1,23 +1,49 @@
|
|
|
1
1
|
import { JitoRpcType, SolanaRpcType } from "./types.js";
|
|
2
2
|
import { SDKClient } from "@lifi/sdk";
|
|
3
3
|
//#region src/rpc/registry.d.ts
|
|
4
|
+
/** Both leave the endpoint out of the Jito list, but only `unsupported` is a
|
|
5
|
+
* configuration gap the integrator can act on. */
|
|
6
|
+
type JitoProbeOutcome = "supported" | "unsupported" | "unreachable";
|
|
7
|
+
/** An outcome plus how long it may be trusted. The classifier decides both,
|
|
8
|
+
* because how long an answer is worth is a property of the evidence that
|
|
9
|
+
* produced it, not of the outcome alone. */
|
|
10
|
+
type JitoProbeResult = {
|
|
11
|
+
outcome: JitoProbeOutcome;
|
|
12
|
+
/** `Infinity` for an answer that cannot change. */
|
|
13
|
+
retryMs: number;
|
|
14
|
+
};
|
|
15
|
+
/** Retry window for a probe that failed without naming the method unknown.
|
|
16
|
+
* An outage heals, so a permanent entry would keep a recovered endpoint out of
|
|
17
|
+
* the Jito list for the whole process. */
|
|
18
|
+
declare const JITO_PROBE_RETRY_MS = 3e4;
|
|
19
|
+
/** Retry window for a bare HTTP 401/403. Longer than an outage's, shorter than
|
|
20
|
+
* forever. The refusal never reached the JSON-RPC layer, so it proves nothing
|
|
21
|
+
* about capability: a plan gate, a provider deploy and an allowlist entry
|
|
22
|
+
* still propagating are indistinguishable here. Treating it as permanent meant
|
|
23
|
+
* one transient 403 removed a working endpoint for the process lifetime;
|
|
24
|
+
* treating it as a 30 s outage would re-probe a real plan gate on the
|
|
25
|
+
* pre-submission latency path twice a minute, forever. */
|
|
26
|
+
declare const JITO_PROBE_GATEWAY_RETRY_MS: number;
|
|
4
27
|
/**
|
|
5
|
-
*
|
|
6
|
-
*
|
|
7
|
-
*
|
|
8
|
-
* support sendBundle/getBundleStatuses without exposing getTipAccounts.
|
|
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`.
|
|
9
31
|
*/
|
|
10
|
-
declare const
|
|
32
|
+
declare const probeJitoRpc: (rpcUrl: string) => Promise<JitoProbeResult>;
|
|
11
33
|
/**
|
|
12
34
|
* Wrapper around getting the Solana RPCs
|
|
13
35
|
* @returns - Solana RPCs
|
|
14
36
|
*/
|
|
15
37
|
declare const getSolanaRpcs: (client: SDKClient) => Promise<SolanaRpcType[]>;
|
|
16
|
-
/**
|
|
17
|
-
*
|
|
18
|
-
*
|
|
19
|
-
|
|
20
|
-
|
|
38
|
+
/** `unreachable` counts endpoints whose probe failed without naming the
|
|
39
|
+
* method unknown. Empty `rpcs` with a non-zero count is usually an outage, but
|
|
40
|
+
* not always: a bare 401/403 lands here too, and that can be a plan gate the
|
|
41
|
+
* integrator has to fix. `sendAndConfirmBundle`'s message names both, because
|
|
42
|
+
* this count cannot tell them apart. */
|
|
43
|
+
declare const getJitoRpcs: (client: SDKClient) => Promise<{
|
|
44
|
+
rpcs: JitoRpcType[];
|
|
45
|
+
unreachable: number;
|
|
46
|
+
}>;
|
|
21
47
|
//#endregion
|
|
22
|
-
export { getJitoRpcs, getSolanaRpcs,
|
|
48
|
+
export { JITO_PROBE_GATEWAY_RETRY_MS, JITO_PROBE_RETRY_MS, JitoProbeOutcome, JitoProbeResult, getJitoRpcs, getSolanaRpcs, probeJitoRpc };
|
|
23
49
|
//# sourceMappingURL=registry.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"registry.d.ts","names":[],"sources":["../../../src/rpc/registry.ts"],"mappings":"
|
|
1
|
+
{"version":3,"file":"registry.d.ts","names":[],"sources":["../../../src/rpc/registry.ts"],"mappings":";;;;;KAuBY;;;;KAKA;EACV,SAAS;;EAET;;;;;cAMW;;;;;;;;cASA;;;;;;cA8EA,eACX,mBACC,QAAQ;;;;;cAiGE,gBACX,QAAQ,cACP,QAAQ;;;;;;cAYE,cACX,QAAQ,cACP;EAAU,MAAM;EAAe"}
|
package/dist/esm/rpc/registry.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { createJitoRpc } from "./jito/createJitoRpc.js";
|
|
2
|
-
import { ChainId, LruMap } from "@lifi/sdk";
|
|
2
|
+
import { ChainId, LruMap, withDedupe } from "@lifi/sdk";
|
|
3
3
|
import { createSolanaRpc } from "@solana/kit";
|
|
4
4
|
//#region src/rpc/registry.ts
|
|
5
5
|
const solanaRpcs = new LruMap(12);
|
|
@@ -15,18 +15,78 @@ const jitoRpcs = new LruMap(12);
|
|
|
15
15
|
* still accepts it and performs the lookup instead of rejecting the probe.
|
|
16
16
|
*/
|
|
17
17
|
const PROBE_BUNDLE_ID = "1111111111111111111111111111111111111111111111111111111111111111";
|
|
18
|
+
/** Retry window for a probe that failed without naming the method unknown.
|
|
19
|
+
* An outage heals, so a permanent entry would keep a recovered endpoint out of
|
|
20
|
+
* the Jito list for the whole process. */
|
|
21
|
+
const JITO_PROBE_RETRY_MS = 3e4;
|
|
22
|
+
/** Retry window for a bare HTTP 401/403. Longer than an outage's, shorter than
|
|
23
|
+
* forever. The refusal never reached the JSON-RPC layer, so it proves nothing
|
|
24
|
+
* about capability: a plan gate, a provider deploy and an allowlist entry
|
|
25
|
+
* still propagating are indistinguishable here. Treating it as permanent meant
|
|
26
|
+
* one transient 403 removed a working endpoint for the process lifetime;
|
|
27
|
+
* treating it as a 30 s outage would re-probe a real plan gate on the
|
|
28
|
+
* pre-submission latency path twice a minute, forever. */
|
|
29
|
+
const JITO_PROBE_GATEWAY_RETRY_MS = 9e5;
|
|
30
|
+
/** Every answered probe, the negative ones included. Without them the unprobed
|
|
31
|
+
* set never shrinks, and every bundle submission re-probes every non-Jito
|
|
32
|
+
* endpoint at up to `PROBE_TIMEOUT_MS` each, on the latency path before
|
|
33
|
+
* submission can start. */
|
|
34
|
+
const jitoProbes = new LruMap(12);
|
|
35
|
+
/** One rule for every outcome: a record is fresh until its own window closes.
|
|
36
|
+
* `Infinity` covers the answers that cannot change. */
|
|
37
|
+
const isProbeFresh = (record) => record !== void 0 && Date.now() - record.at < record.retryMs;
|
|
38
|
+
const CAPABILITY_CODES = [-32601, -32403];
|
|
39
|
+
/** A plan gate rejects before JSON-RPC, so no `-32601` arrives - Helius
|
|
40
|
+
* answers with a bare 403. Unlike a JSON-RPC code this never reached the RPC
|
|
41
|
+
* layer, so it is a gateway verdict rather than a capability answer, and it
|
|
42
|
+
* earns a window instead of permanence. 429 and 5xx are absent: those take the
|
|
43
|
+
* shorter outage window. */
|
|
44
|
+
const GATEWAY_REFUSAL_HTTP_STATUSES = [401, 403];
|
|
45
|
+
const readProbeFailure = (error) => {
|
|
46
|
+
const candidate = error;
|
|
47
|
+
const rpcCode = candidate?.code ?? candidate?.context?.__code;
|
|
48
|
+
if (typeof rpcCode === "number" && CAPABILITY_CODES.includes(rpcCode)) return {
|
|
49
|
+
outcome: "unsupported",
|
|
50
|
+
retryMs: Number.POSITIVE_INFINITY
|
|
51
|
+
};
|
|
52
|
+
const status = candidate?.context?.statusCode;
|
|
53
|
+
if (typeof status === "number" && GATEWAY_REFUSAL_HTTP_STATUSES.includes(status)) return {
|
|
54
|
+
outcome: "unreachable",
|
|
55
|
+
retryMs: JITO_PROBE_GATEWAY_RETRY_MS
|
|
56
|
+
};
|
|
57
|
+
const message = error instanceof Error ? error.message : String(error);
|
|
58
|
+
return /method not found|method does not exist|-32601|method .* not supported|unsupported method|only available for business plans/i.test(message) ? {
|
|
59
|
+
outcome: "unsupported",
|
|
60
|
+
retryMs: Number.POSITIVE_INFINITY
|
|
61
|
+
} : {
|
|
62
|
+
outcome: "unreachable",
|
|
63
|
+
retryMs: JITO_PROBE_RETRY_MS
|
|
64
|
+
};
|
|
65
|
+
};
|
|
66
|
+
/**
|
|
67
|
+
* Bounded because it runs upstream of `raceRpcs`, outside the confirmation
|
|
68
|
+
* budget the SDK documents: an endpoint that accepts the connection and never
|
|
69
|
+
* answers would otherwise stall bundle submission indefinitely.
|
|
70
|
+
*/
|
|
71
|
+
const PROBE_TIMEOUT_MS = 5e3;
|
|
18
72
|
/**
|
|
19
|
-
*
|
|
20
|
-
*
|
|
21
|
-
*
|
|
22
|
-
* support sendBundle/getBundleStatuses without exposing getTipAccounts.
|
|
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`.
|
|
23
76
|
*/
|
|
24
|
-
const
|
|
77
|
+
const probeJitoRpc = async (rpcUrl) => {
|
|
78
|
+
const controller = new AbortController();
|
|
79
|
+
const timer = setTimeout(() => controller.abort(), PROBE_TIMEOUT_MS);
|
|
25
80
|
try {
|
|
26
|
-
await createJitoRpc(rpcUrl).getBundleStatuses([PROBE_BUNDLE_ID]).send();
|
|
27
|
-
return
|
|
28
|
-
|
|
29
|
-
|
|
81
|
+
await createJitoRpc(rpcUrl).getBundleStatuses([PROBE_BUNDLE_ID]).send({ abortSignal: controller.signal });
|
|
82
|
+
return {
|
|
83
|
+
outcome: "supported",
|
|
84
|
+
retryMs: Number.POSITIVE_INFINITY
|
|
85
|
+
};
|
|
86
|
+
} catch (error) {
|
|
87
|
+
return readProbeFailure(error);
|
|
88
|
+
} finally {
|
|
89
|
+
clearTimeout(timer);
|
|
30
90
|
}
|
|
31
91
|
};
|
|
32
92
|
/**
|
|
@@ -39,13 +99,31 @@ const ensureSolanaRpcs = async (client) => {
|
|
|
39
99
|
return rpcUrls;
|
|
40
100
|
};
|
|
41
101
|
/**
|
|
42
|
-
*
|
|
102
|
+
* Initializes and caches Jito RPCs for every configured Solana RPC URL.
|
|
103
|
+
*
|
|
104
|
+
* Every probe outcome is cached, so a non-Jito endpoint is probed once rather
|
|
105
|
+
* than once per bundle submission. Each record carries its own retry window:
|
|
106
|
+
* see `JITO_PROBE_RETRY_MS` and `JITO_PROBE_GATEWAY_RETRY_MS` for the two that
|
|
107
|
+
* expire.
|
|
43
108
|
* @param client - The SDK client used to fetch RPC URLs.
|
|
44
109
|
*/
|
|
45
110
|
const ensureJitoRpcs = async (client) => {
|
|
46
111
|
const rpcUrls = await client.getRpcUrlsByChainId(ChainId.SOL);
|
|
47
|
-
|
|
48
|
-
|
|
112
|
+
const unprobed = rpcUrls.filter((rpcUrl) => !isProbeFresh(jitoProbes.get(rpcUrl)));
|
|
113
|
+
(await Promise.all(unprobed.map((rpcUrl) => withDedupe(() => probeJitoRpc(rpcUrl), { id: `jito-probe:${rpcUrl}` })))).forEach(({ outcome, retryMs }, index) => {
|
|
114
|
+
const rpcUrl = unprobed[index];
|
|
115
|
+
jitoProbes.set(rpcUrl, {
|
|
116
|
+
outcome,
|
|
117
|
+
retryMs,
|
|
118
|
+
at: Date.now()
|
|
119
|
+
});
|
|
120
|
+
if (outcome === "supported") jitoRpcs.set(rpcUrl, createJitoRpc(rpcUrl));
|
|
121
|
+
else jitoRpcs.delete(rpcUrl);
|
|
122
|
+
});
|
|
123
|
+
return {
|
|
124
|
+
rpcUrls,
|
|
125
|
+
unreachable: rpcUrls.filter((rpcUrl) => jitoProbes.get(rpcUrl)?.outcome === "unreachable").length
|
|
126
|
+
};
|
|
49
127
|
};
|
|
50
128
|
/**
|
|
51
129
|
* Wrapper around getting the Solana RPCs
|
|
@@ -54,14 +132,19 @@ const ensureJitoRpcs = async (client) => {
|
|
|
54
132
|
const getSolanaRpcs = async (client) => {
|
|
55
133
|
return (await ensureSolanaRpcs(client)).map((rpcUrl) => solanaRpcs.get(rpcUrl)).filter((rpc) => Boolean(rpc));
|
|
56
134
|
};
|
|
57
|
-
/**
|
|
58
|
-
*
|
|
59
|
-
*
|
|
60
|
-
|
|
135
|
+
/** `unreachable` counts endpoints whose probe failed without naming the
|
|
136
|
+
* method unknown. Empty `rpcs` with a non-zero count is usually an outage, but
|
|
137
|
+
* not always: a bare 401/403 lands here too, and that can be a plan gate the
|
|
138
|
+
* integrator has to fix. `sendAndConfirmBundle`'s message names both, because
|
|
139
|
+
* this count cannot tell them apart. */
|
|
61
140
|
const getJitoRpcs = async (client) => {
|
|
62
|
-
|
|
141
|
+
const { rpcUrls, unreachable } = await ensureJitoRpcs(client);
|
|
142
|
+
return {
|
|
143
|
+
rpcs: rpcUrls.map((rpcUrl) => jitoRpcs.get(rpcUrl)).filter((rpc) => Boolean(rpc)),
|
|
144
|
+
unreachable
|
|
145
|
+
};
|
|
63
146
|
};
|
|
64
147
|
//#endregion
|
|
65
|
-
export { getJitoRpcs, getSolanaRpcs,
|
|
148
|
+
export { JITO_PROBE_GATEWAY_RETRY_MS, JITO_PROBE_RETRY_MS, getJitoRpcs, getSolanaRpcs, probeJitoRpc };
|
|
66
149
|
|
|
67
150
|
//# sourceMappingURL=registry.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"registry.js","names":[],"sources":["../../../src/rpc/registry.ts"],"sourcesContent":["import { ChainId, LruMap, type SDKClient } from '@lifi/sdk'\nimport { createSolanaRpc } from '@solana/kit'\nimport { createJitoRpc } from './jito/createJitoRpc.js'\nimport type { JitoRpcType, SolanaRpcType } from './types.js'\n\nconst solanaRpcs = new LruMap<SolanaRpcType>(12)\nconst jitoRpcs = new LruMap<JitoRpcType>(12)\n\n/**\n * A well-formed but non-existent Jito bundle id used solely to probe RPC\n * capability. It forces `getBundleStatuses` to actually execute, so we can tell\n * a Jito-capable RPC (resolves with `{ value: [null] }` — bundle not found)\n * apart from a standard Solana RPC (throws \"Method not found\").\n *\n * Uses all `1`s: 64 chars, valid as both hex and base-58 (base-58 excludes\n * `0`/`O`/`I`/`l`), so a provider that validates the id in either encoding\n * still accepts it and performs the lookup instead of rejecting the probe.\n */\nconst PROBE_BUNDLE_ID =\n '1111111111111111111111111111111111111111111111111111111111111111'\n\n/**\n * Checks if an RPC URL supports Jito methods by calling getBundleStatuses.\n * We probe with getBundleStatuses (rather than getTipAccounts) because it is the\n * method actually used during bundle confirmation, and providers such as Helius\n * support sendBundle/getBundleStatuses without exposing getTipAccounts.\n */\nexport const isJitoRpc = async (rpcUrl: string): Promise<boolean> => {\n try {\n const rpc = createJitoRpc(rpcUrl)\n await rpc.getBundleStatuses([PROBE_BUNDLE_ID]).send()\n return true\n } catch {\n return false\n }\n}\n\n/**\n * Initializes Solana RPCs for all available RPC URLs if they haven't been cached yet.\n * @param client - The SDK client used to fetch RPC URLs.\n */\nconst ensureSolanaRpcs = async (client: SDKClient): Promise<string[]> => {\n const rpcUrls = await client.getRpcUrlsByChainId(ChainId.SOL)\n for (const rpcUrl of rpcUrls) {\n if (!solanaRpcs.has(rpcUrl)) {\n solanaRpcs.set(rpcUrl, createSolanaRpc(rpcUrl))\n }\n }\n return rpcUrls\n}\n\n/**\n * Detects and caches Jito-capable RPCs by checking if they support the getTipAccounts method.\n * @param client - The SDK client used to fetch RPC URLs.\n */\nconst ensureJitoRpcs = async (client: SDKClient): Promise<string[]> => {\n const rpcUrls = await client.getRpcUrlsByChainId(ChainId.SOL)\n for (const rpcUrl of rpcUrls) {\n if (!jitoRpcs.has(rpcUrl) && (await isJitoRpc(rpcUrl))) {\n jitoRpcs.set(rpcUrl, createJitoRpc(rpcUrl))\n }\n }\n return rpcUrls\n}\n\n/**\n * Wrapper around getting the Solana RPCs\n * @returns - Solana RPCs\n */\nexport const getSolanaRpcs = async (\n client: SDKClient\n): Promise<SolanaRpcType[]> => {\n const rpcUrls = await ensureSolanaRpcs(client)\n return rpcUrls\n .map((rpcUrl) => solanaRpcs.get(rpcUrl))\n .filter((rpc): rpc is SolanaRpcType => Boolean(rpc))\n}\n\n/**\n * Wrapper around getting the Jito RPCs\n * @returns - Jito RPCs\n */\nexport const getJitoRpcs = async (\n client: SDKClient\n): Promise<JitoRpcType[]> => {\n const rpcUrls = await ensureJitoRpcs(client)\n return rpcUrls\n .map((rpcUrl) => jitoRpcs.get(rpcUrl))\n .filter((rpc): rpc is JitoRpcType => Boolean(rpc))\n}\n"],"mappings":";;;;AAKA,MAAM,aAAa,IAAI,OAAsB,EAAE;AAC/C,MAAM,WAAW,IAAI,OAAoB,EAAE;;;;;;;;;;;AAY3C,MAAM,kBACJ;;;;;;;AAQF,MAAa,YAAY,OAAO,WAAqC;CACnE,IAAI;EAEF,MADY,cAAc,MAClB,CAAC,CAAC,kBAAkB,CAAC,eAAe,CAAC,CAAC,CAAC,KAAK;EACpD,OAAO;CACT,QAAQ;EACN,OAAO;CACT;AACF;;;;;AAMA,MAAM,mBAAmB,OAAO,WAAyC;CACvE,MAAM,UAAU,MAAM,OAAO,oBAAoB,QAAQ,GAAG;CAC5D,KAAK,MAAM,UAAU,SACnB,IAAI,CAAC,WAAW,IAAI,MAAM,GACxB,WAAW,IAAI,QAAQ,gBAAgB,MAAM,CAAC;CAGlD,OAAO;AACT;;;;;AAMA,MAAM,iBAAiB,OAAO,WAAyC;CACrE,MAAM,UAAU,MAAM,OAAO,oBAAoB,QAAQ,GAAG;CAC5D,KAAK,MAAM,UAAU,SACnB,IAAI,CAAC,SAAS,IAAI,MAAM,KAAM,MAAM,UAAU,MAAM,GAClD,SAAS,IAAI,QAAQ,cAAc,MAAM,CAAC;CAG9C,OAAO;AACT;;;;;AAMA,MAAa,gBAAgB,OAC3B,WAC6B;CAE7B,QAAO,MADe,iBAAiB,MAAM,EAAA,CAE1C,KAAK,WAAW,WAAW,IAAI,MAAM,CAAC,CAAC,CACvC,QAAQ,QAA8B,QAAQ,GAAG,CAAC;AACvD;;;;;AAMA,MAAa,cAAc,OACzB,WAC2B;CAE3B,QAAO,MADe,eAAe,MAAM,EAAA,CAExC,KAAK,WAAW,SAAS,IAAI,MAAM,CAAC,CAAC,CACrC,QAAQ,QAA4B,QAAQ,GAAG,CAAC;AACrD"}
|
|
1
|
+
{"version":3,"file":"registry.js","names":[],"sources":["../../../src/rpc/registry.ts"],"sourcesContent":["import { ChainId, LruMap, type SDKClient, withDedupe } from '@lifi/sdk'\nimport { createSolanaRpc } from '@solana/kit'\nimport { createJitoRpc } from './jito/createJitoRpc.js'\nimport type { JitoRpcType, SolanaRpcType } from './types.js'\n\nconst solanaRpcs = new LruMap<SolanaRpcType>(12)\nconst jitoRpcs = new LruMap<JitoRpcType>(12)\n\n/**\n * A well-formed but non-existent Jito bundle id used solely to probe RPC\n * capability. It forces `getBundleStatuses` to actually execute, so we can tell\n * a Jito-capable RPC (resolves with `{ value: [null] }` — bundle not found)\n * apart from a standard Solana RPC (throws \"Method not found\").\n *\n * Uses all `1`s: 64 chars, valid as both hex and base-58 (base-58 excludes\n * `0`/`O`/`I`/`l`), so a provider that validates the id in either encoding\n * still accepts it and performs the lookup instead of rejecting the probe.\n */\nconst PROBE_BUNDLE_ID =\n '1111111111111111111111111111111111111111111111111111111111111111'\n\n/** Both leave the endpoint out of the Jito list, but only `unsupported` is a\n * configuration gap the integrator can act on. */\nexport type JitoProbeOutcome = 'supported' | 'unsupported' | 'unreachable'\n\n/** An outcome plus how long it may be trusted. The classifier decides both,\n * because how long an answer is worth is a property of the evidence that\n * produced it, not of the outcome alone. */\nexport type JitoProbeResult = {\n outcome: JitoProbeOutcome\n /** `Infinity` for an answer that cannot change. */\n retryMs: number\n}\n\n/** Retry window for a probe that failed without naming the method unknown.\n * An outage heals, so a permanent entry would keep a recovered endpoint out of\n * the Jito list for the whole process. */\nexport const JITO_PROBE_RETRY_MS = 30_000\n\n/** Retry window for a bare HTTP 401/403. Longer than an outage's, shorter than\n * forever. The refusal never reached the JSON-RPC layer, so it proves nothing\n * about capability: a plan gate, a provider deploy and an allowlist entry\n * still propagating are indistinguishable here. Treating it as permanent meant\n * one transient 403 removed a working endpoint for the process lifetime;\n * treating it as a 30 s outage would re-probe a real plan gate on the\n * pre-submission latency path twice a minute, forever. */\nexport const JITO_PROBE_GATEWAY_RETRY_MS: number = 15 * 60_000\n\ntype JitoProbeRecord = JitoProbeResult & { at: number }\n\n/** Every answered probe, the negative ones included. Without them the unprobed\n * set never shrinks, and every bundle submission re-probes every non-Jito\n * endpoint at up to `PROBE_TIMEOUT_MS` each, on the latency path before\n * submission can start. */\nconst jitoProbes = new LruMap<JitoProbeRecord>(12)\n\n/** One rule for every outcome: a record is fresh until its own window closes.\n * `Infinity` covers the answers that cannot change. */\nconst isProbeFresh = (record: JitoProbeRecord | undefined): boolean =>\n record !== undefined && Date.now() - record.at < record.retryMs\n\n/** `@solana/kit` puts the JSON-RPC code on `context.__code`, not `error.code`.\n * The message is a last resort - a provider can reword it. An unrecognized\n * failure counts as `unreachable`, so a misread blames an outage. */\nconst JSON_RPC_METHOD_NOT_FOUND = -32601\n/** Non-standard; providers use it for \"your plan lacks this method\". */\nconst PROVIDER_PLAN_RESTRICTED = -32403\n\nconst CAPABILITY_CODES: number[] = [\n JSON_RPC_METHOD_NOT_FOUND,\n PROVIDER_PLAN_RESTRICTED,\n]\n\n/** A plan gate rejects before JSON-RPC, so no `-32601` arrives - Helius\n * answers with a bare 403. Unlike a JSON-RPC code this never reached the RPC\n * layer, so it is a gateway verdict rather than a capability answer, and it\n * earns a window instead of permanence. 429 and 5xx are absent: those take the\n * shorter outage window. */\nconst GATEWAY_REFUSAL_HTTP_STATUSES: number[] = [401, 403]\n\nconst readProbeFailure = (error: unknown): JitoProbeResult => {\n const candidate = error as\n | {\n code?: unknown\n context?: { __code?: unknown; statusCode?: unknown }\n }\n | undefined\n\n // kit's `__code` is 8100002 for every HTTP failure, so only a JSON-RPC code\n // that reached the body is meaningful.\n const rpcCode = candidate?.code ?? candidate?.context?.__code\n if (typeof rpcCode === 'number' && CAPABILITY_CODES.includes(rpcCode)) {\n // The server parsed the request and said it has no such method. Definitive.\n return { outcome: 'unsupported', retryMs: Number.POSITIVE_INFINITY }\n }\n\n const status = candidate?.context?.statusCode\n if (\n typeof status === 'number' &&\n GATEWAY_REFUSAL_HTTP_STATUSES.includes(status)\n ) {\n return { outcome: 'unreachable', retryMs: JITO_PROBE_GATEWAY_RETRY_MS }\n }\n\n const message = error instanceof Error ? error.message : String(error)\n return /method not found|method does not exist|-32601|method .* not supported|unsupported method|only available for business plans/i.test(\n message\n )\n ? { outcome: 'unsupported', retryMs: Number.POSITIVE_INFINITY }\n : { outcome: 'unreachable', retryMs: JITO_PROBE_RETRY_MS }\n}\n\n/**\n * Bounded because it runs upstream of `raceRpcs`, outside the confirmation\n * budget the SDK documents: an endpoint that accepts the connection and never\n * answers would otherwise stall bundle submission indefinitely.\n */\nconst PROBE_TIMEOUT_MS = 5_000\n\n/**\n * Probes with `getBundleStatuses` rather than `getTipAccounts`: it is the\n * method bundle confirmation actually uses, and providers such as Helius\n * support it without exposing `getTipAccounts`.\n */\nexport const probeJitoRpc = async (\n rpcUrl: string\n): Promise<JitoProbeResult> => {\n const controller = new AbortController()\n const timer = setTimeout(() => controller.abort(), PROBE_TIMEOUT_MS)\n try {\n const rpc = createJitoRpc(rpcUrl)\n await rpc\n .getBundleStatuses([PROBE_BUNDLE_ID])\n .send({ abortSignal: controller.signal })\n return { outcome: 'supported', retryMs: Number.POSITIVE_INFINITY }\n } catch (error) {\n return readProbeFailure(error)\n } finally {\n clearTimeout(timer)\n }\n}\n\n/**\n * Initializes Solana RPCs for all available RPC URLs if they haven't been cached yet.\n * @param client - The SDK client used to fetch RPC URLs.\n */\nconst ensureSolanaRpcs = async (client: SDKClient): Promise<string[]> => {\n const rpcUrls = await client.getRpcUrlsByChainId(ChainId.SOL)\n for (const rpcUrl of rpcUrls) {\n if (!solanaRpcs.has(rpcUrl)) {\n solanaRpcs.set(rpcUrl, createSolanaRpc(rpcUrl))\n }\n }\n return rpcUrls\n}\n\n/**\n * Initializes and caches Jito RPCs for every configured Solana RPC URL.\n *\n * Every probe outcome is cached, so a non-Jito endpoint is probed once rather\n * than once per bundle submission. Each record carries its own retry window:\n * see `JITO_PROBE_RETRY_MS` and `JITO_PROBE_GATEWAY_RETRY_MS` for the two that\n * expire.\n * @param client - The SDK client used to fetch RPC URLs.\n */\nconst ensureJitoRpcs = async (\n client: SDKClient\n): Promise<{ rpcUrls: string[]; unreachable: number }> => {\n const rpcUrls = await client.getRpcUrlsByChainId(ChainId.SOL)\n // Probed in parallel: serially, one slow endpoint delayed every URL behind\n // it before submission could start.\n const unprobed = rpcUrls.filter(\n (rpcUrl) => !isProbeFresh(jitoProbes.get(rpcUrl))\n )\n // Deduplicated per URL: without it two concurrent submissions each probe\n // every unprobed endpoint, and the slower probe writes last - a 5 s timeout\n // resolving `unreachable` used to overwrite a `supported` answer that landed\n // at 300 ms, evicting a verified-healthy endpoint.\n //\n // `withDedupe` drops its entry in a `.finally`, so this guarantees at most\n // one probe *in flight* per URL, not one probe per URL. The write below waits\n // for the whole batch, so a fast URL's record is unwritten while a slow\n // sibling is still running - up to `PROBE_TIMEOUT_MS` - and every caller\n // arriving in that window re-probes the fast URL. Repeats are therefore\n // bounded by arrivals, not by one.\n //\n // What this does rule out is the clobber: a second probe can only begin\n // after the first has settled, so it always carries the newer answer and\n // always writes second. Write order matches result recency, which is why no\n // timestamp comparison is needed here.\n const results = await Promise.all(\n unprobed.map((rpcUrl) =>\n withDedupe(() => probeJitoRpc(rpcUrl), { id: `jito-probe:${rpcUrl}` })\n )\n )\n\n results.forEach(({ outcome, retryMs }, index) => {\n const rpcUrl = unprobed[index]\n jitoProbes.set(rpcUrl, { outcome, retryMs, at: Date.now() })\n if (outcome === 'supported') {\n jitoRpcs.set(rpcUrl, createJitoRpc(rpcUrl))\n } else {\n // An endpoint that used to answer and now does not must leave the list,\n // or `getJitoRpcs` keeps handing out a client for it.\n jitoRpcs.delete(rpcUrl)\n }\n })\n\n // Counted over every URL, not only the freshly probed ones: a cached\n // `unreachable` still has to reach `sendAndConfirmBundle`, which uses the\n // count to choose between \"retry, likely temporary\" and \"supply a\n // Jito-capable URL\".\n const unreachable = rpcUrls.filter(\n (rpcUrl) => jitoProbes.get(rpcUrl)?.outcome === 'unreachable'\n ).length\n\n return { rpcUrls, unreachable }\n}\n\n/**\n * Wrapper around getting the Solana RPCs\n * @returns - Solana RPCs\n */\nexport const getSolanaRpcs = async (\n client: SDKClient\n): Promise<SolanaRpcType[]> => {\n const rpcUrls = await ensureSolanaRpcs(client)\n return rpcUrls\n .map((rpcUrl) => solanaRpcs.get(rpcUrl))\n .filter((rpc): rpc is SolanaRpcType => Boolean(rpc))\n}\n\n/** `unreachable` counts endpoints whose probe failed without naming the\n * method unknown. Empty `rpcs` with a non-zero count is usually an outage, but\n * not always: a bare 401/403 lands here too, and that can be a plan gate the\n * integrator has to fix. `sendAndConfirmBundle`'s message names both, because\n * this count cannot tell them apart. */\nexport const getJitoRpcs = async (\n client: SDKClient\n): Promise<{ rpcs: JitoRpcType[]; unreachable: number }> => {\n const { rpcUrls, unreachable } = await ensureJitoRpcs(client)\n return {\n rpcs: rpcUrls\n .map((rpcUrl) => jitoRpcs.get(rpcUrl))\n .filter((rpc): rpc is JitoRpcType => Boolean(rpc)),\n unreachable,\n }\n}\n"],"mappings":";;;;AAKA,MAAM,aAAa,IAAI,OAAsB,EAAE;AAC/C,MAAM,WAAW,IAAI,OAAoB,EAAE;;;;;;;;;;;AAY3C,MAAM,kBACJ;;;;AAkBF,MAAa,sBAAsB;;;;;;;;AASnC,MAAa,8BAAsC;;;;;AAQnD,MAAM,aAAa,IAAI,OAAwB,EAAE;;;AAIjD,MAAM,gBAAgB,WACpB,WAAW,KAAA,KAAa,KAAK,IAAI,IAAI,OAAO,KAAK,OAAO;AAS1D,MAAM,mBAA6B,CACjC,QACA,MACF;;;;;;AAOA,MAAM,gCAA0C,CAAC,KAAK,GAAG;AAEzD,MAAM,oBAAoB,UAAoC;CAC5D,MAAM,YAAY;CASlB,MAAM,UAAU,WAAW,QAAQ,WAAW,SAAS;CACvD,IAAI,OAAO,YAAY,YAAY,iBAAiB,SAAS,OAAO,GAElE,OAAO;EAAE,SAAS;EAAe,SAAS,OAAO;CAAkB;CAGrE,MAAM,SAAS,WAAW,SAAS;CACnC,IACE,OAAO,WAAW,YAClB,8BAA8B,SAAS,MAAM,GAE7C,OAAO;EAAE,SAAS;EAAe,SAAS;CAA4B;CAGxE,MAAM,UAAU,iBAAiB,QAAQ,MAAM,UAAU,OAAO,KAAK;CACrE,OAAO,8HAA8H,KACnI,OACF,IACI;EAAE,SAAS;EAAe,SAAS,OAAO;CAAkB,IAC5D;EAAE,SAAS;EAAe,SAAS;CAAoB;AAC7D;;;;;;AAOA,MAAM,mBAAmB;;;;;;AAOzB,MAAa,eAAe,OAC1B,WAC6B;CAC7B,MAAM,aAAa,IAAI,gBAAgB;CACvC,MAAM,QAAQ,iBAAiB,WAAW,MAAM,GAAG,gBAAgB;CACnE,IAAI;EAEF,MADY,cAAc,MAClB,CAAC,CACN,kBAAkB,CAAC,eAAe,CAAC,CAAC,CACpC,KAAK,EAAE,aAAa,WAAW,OAAO,CAAC;EAC1C,OAAO;GAAE,SAAS;GAAa,SAAS,OAAO;EAAkB;CACnE,SAAS,OAAO;EACd,OAAO,iBAAiB,KAAK;CAC/B,UAAU;EACR,aAAa,KAAK;CACpB;AACF;;;;;AAMA,MAAM,mBAAmB,OAAO,WAAyC;CACvE,MAAM,UAAU,MAAM,OAAO,oBAAoB,QAAQ,GAAG;CAC5D,KAAK,MAAM,UAAU,SACnB,IAAI,CAAC,WAAW,IAAI,MAAM,GACxB,WAAW,IAAI,QAAQ,gBAAgB,MAAM,CAAC;CAGlD,OAAO;AACT;;;;;;;;;;AAWA,MAAM,iBAAiB,OACrB,WACwD;CACxD,MAAM,UAAU,MAAM,OAAO,oBAAoB,QAAQ,GAAG;CAG5D,MAAM,WAAW,QAAQ,QACtB,WAAW,CAAC,aAAa,WAAW,IAAI,MAAM,CAAC,CAClD;CAuBA,CAAA,MANsB,QAAQ,IAC5B,SAAS,KAAK,WACZ,iBAAiB,aAAa,MAAM,GAAG,EAAE,IAAI,cAAc,SAAS,CAAC,CACvE,CACF,EAAA,CAEQ,SAAS,EAAE,SAAS,WAAW,UAAU;EAC/C,MAAM,SAAS,SAAS;EACxB,WAAW,IAAI,QAAQ;GAAE;GAAS;GAAS,IAAI,KAAK,IAAI;EAAE,CAAC;EAC3D,IAAI,YAAY,aACd,SAAS,IAAI,QAAQ,cAAc,MAAM,CAAC;OAI1C,SAAS,OAAO,MAAM;CAE1B,CAAC;CAUD,OAAO;EAAE;EAAS,aAJE,QAAQ,QACzB,WAAW,WAAW,IAAI,MAAM,CAAC,EAAE,YAAY,aAClD,CAAC,CAAC;CAE4B;AAChC;;;;;AAMA,MAAa,gBAAgB,OAC3B,WAC6B;CAE7B,QAAO,MADe,iBAAiB,MAAM,EAAA,CAE1C,KAAK,WAAW,WAAW,IAAI,MAAM,CAAC,CAAC,CACvC,QAAQ,QAA8B,QAAQ,GAAG,CAAC;AACvD;;;;;;AAOA,MAAa,cAAc,OACzB,WAC0D;CAC1D,MAAM,EAAE,SAAS,gBAAgB,MAAM,eAAe,MAAM;CAC5D,OAAO;EACL,MAAM,QACH,KAAK,WAAW,SAAS,IAAI,MAAM,CAAC,CAAC,CACrC,QAAQ,QAA4B,QAAQ,GAAG,CAAC;EACnD;CACF;AACF"}
|
package/dist/esm/rpc/utils.js
CHANGED
|
@@ -74,7 +74,7 @@ const callSolanaRpcsWithRetry = createRetryFn(getSolanaRpcs);
|
|
|
74
74
|
* )
|
|
75
75
|
* ```
|
|
76
76
|
*/
|
|
77
|
-
const callJitoRpcsWithRetry = createRetryFn(getJitoRpcs);
|
|
77
|
+
const callJitoRpcsWithRetry = createRetryFn(async (client) => (await getJitoRpcs(client)).rpcs);
|
|
78
78
|
//#endregion
|
|
79
79
|
export { callJitoRpcsWithRetry, callSolanaRpcsWithRetry, callWithRetry };
|
|
80
80
|
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"utils.js","names":[],"sources":["../../../src/rpc/utils.ts"],"sourcesContent":["import type { SDKClient } from '@lifi/sdk'\nimport { getJitoRpcs, getSolanaRpcs } from './registry.js'\nimport type { JitoRpcType, SolanaRpcType } from './types.js'\n\ntype RetryFn<Rpc> = <R>(\n client: SDKClient,\n fn: (rpc: Rpc) => Promise<R>\n) => Promise<R>\n\n/**\n * Calls a function on RPC instances with retry logic.\n * Tries each RPC in sequence until one succeeds.\n *\n * @typeParam T - The type of the RPC instance.\n * @typeParam R - The return type of the function.\n * @param rpcs - An array of RPC instances to try.\n * @param fn - The async function to execute on each RPC until one succeeds.\n * @returns The result from the first successful RPC call.\n * @throws {Error} If no RPCs are available.\n * @throws {AggregateError} If all RPCs fail, containing all individual errors.\n *\n * @example\n * ```ts\n * const rpcs = await getSolanaRpcs(client)\n * const result = await callWithRetry(rpcs, (rpc) =>\n * rpc.getBalance(address).send()\n * )\n * ```\n */\nexport async function callWithRetry<T, R>(\n rpcs: T[],\n fn: (rpc: T) => Promise<R>\n): Promise<R> {\n if (rpcs.length === 0) {\n throw new Error('No RPCs available')\n }\n\n const errors: Error[] = []\n for (const rpc of rpcs) {\n try {\n return await fn(rpc)\n } catch (error) {\n errors.push(error instanceof Error ? error : new Error(String(error)))\n }\n }\n\n throw new AggregateError(errors, `All ${rpcs.length} RPCs failed`)\n}\n\n/**\n * Creates a retry function for a specific RPC type.\n * @internal\n */\nconst createRetryFn =\n <T>(getRpcs: (client: SDKClient) => Promise<T[]>) =>\n async <R>(client: SDKClient, fn: (rpc: T) => Promise<R>): Promise<R> => {\n const rpcs = await getRpcs(client)\n return callWithRetry(rpcs, fn)\n }\n\n/**\n * Calls a function on Solana RPC instances with retry logic.\n * Automatically fetches available Solana RPCs and tries each in sequence.\n *\n * @typeParam R - The return type of the function.\n * @param client - The SDK client used to fetch RPC URLs.\n * @param fn - The async function to execute on each RPC until one succeeds.\n * @returns The result from the first successful RPC call.\n * @throws {Error} If no Solana RPCs are available.\n * @throws {AggregateError} If all RPCs fail.\n *\n * @example\n * ```ts\n * const balance = await callSolanaRpcsWithRetry(client, (rpc) =>\n * rpc.getBalance(address).send()\n * )\n * ```\n */\nexport const callSolanaRpcsWithRetry: RetryFn<SolanaRpcType> =\n createRetryFn(getSolanaRpcs)\n\n/**\n * Calls a function on Jito RPC instances with retry logic.\n * Automatically fetches available Jito RPCs and tries each in sequence.\n *\n * @typeParam R - The return type of the function.\n * @param client - The SDK client used to fetch RPC URLs.\n * @param fn - The async function to execute on each RPC until one succeeds.\n * @returns The result from the first successful RPC call.\n * @throws {Error} If no Jito RPCs are available.\n * @throws {AggregateError} If all RPCs fail.\n *\n * @example\n * ```ts\n * const tipAccounts = await callJitoRpcsWithRetry(client, (rpc) =>\n * rpc.getTipAccounts().send()\n * )\n * ```\n */\nexport const callJitoRpcsWithRetry: RetryFn<JitoRpcType>
|
|
1
|
+
{"version":3,"file":"utils.js","names":[],"sources":["../../../src/rpc/utils.ts"],"sourcesContent":["import type { SDKClient } from '@lifi/sdk'\nimport { getJitoRpcs, getSolanaRpcs } from './registry.js'\nimport type { JitoRpcType, SolanaRpcType } from './types.js'\n\ntype RetryFn<Rpc> = <R>(\n client: SDKClient,\n fn: (rpc: Rpc) => Promise<R>\n) => Promise<R>\n\n/**\n * Calls a function on RPC instances with retry logic.\n * Tries each RPC in sequence until one succeeds.\n *\n * @typeParam T - The type of the RPC instance.\n * @typeParam R - The return type of the function.\n * @param rpcs - An array of RPC instances to try.\n * @param fn - The async function to execute on each RPC until one succeeds.\n * @returns The result from the first successful RPC call.\n * @throws {Error} If no RPCs are available.\n * @throws {AggregateError} If all RPCs fail, containing all individual errors.\n *\n * @example\n * ```ts\n * const rpcs = await getSolanaRpcs(client)\n * const result = await callWithRetry(rpcs, (rpc) =>\n * rpc.getBalance(address).send()\n * )\n * ```\n */\nexport async function callWithRetry<T, R>(\n rpcs: T[],\n fn: (rpc: T) => Promise<R>\n): Promise<R> {\n if (rpcs.length === 0) {\n throw new Error('No RPCs available')\n }\n\n const errors: Error[] = []\n for (const rpc of rpcs) {\n try {\n return await fn(rpc)\n } catch (error) {\n errors.push(error instanceof Error ? error : new Error(String(error)))\n }\n }\n\n throw new AggregateError(errors, `All ${rpcs.length} RPCs failed`)\n}\n\n/**\n * Creates a retry function for a specific RPC type.\n * @internal\n */\nconst createRetryFn =\n <T>(getRpcs: (client: SDKClient) => Promise<T[]>) =>\n async <R>(client: SDKClient, fn: (rpc: T) => Promise<R>): Promise<R> => {\n const rpcs = await getRpcs(client)\n return callWithRetry(rpcs, fn)\n }\n\n/**\n * Calls a function on Solana RPC instances with retry logic.\n * Automatically fetches available Solana RPCs and tries each in sequence.\n *\n * @typeParam R - The return type of the function.\n * @param client - The SDK client used to fetch RPC URLs.\n * @param fn - The async function to execute on each RPC until one succeeds.\n * @returns The result from the first successful RPC call.\n * @throws {Error} If no Solana RPCs are available.\n * @throws {AggregateError} If all RPCs fail.\n *\n * @example\n * ```ts\n * const balance = await callSolanaRpcsWithRetry(client, (rpc) =>\n * rpc.getBalance(address).send()\n * )\n * ```\n */\nexport const callSolanaRpcsWithRetry: RetryFn<SolanaRpcType> =\n createRetryFn(getSolanaRpcs)\n\n/**\n * Calls a function on Jito RPC instances with retry logic.\n * Automatically fetches available Jito RPCs and tries each in sequence.\n *\n * @typeParam R - The return type of the function.\n * @param client - The SDK client used to fetch RPC URLs.\n * @param fn - The async function to execute on each RPC until one succeeds.\n * @returns The result from the first successful RPC call.\n * @throws {Error} If no Jito RPCs are available.\n * @throws {AggregateError} If all RPCs fail.\n *\n * @example\n * ```ts\n * const tipAccounts = await callJitoRpcsWithRetry(client, (rpc) =>\n * rpc.getTipAccounts().send()\n * )\n * ```\n */\nexport const callJitoRpcsWithRetry: RetryFn<JitoRpcType> = createRetryFn(\n // The probe diagnosis `getJitoRpcs` reports alongside the list is for the\n // bundle path's error message; a sequential retry only needs the list.\n async (client) => (await getJitoRpcs(client)).rpcs\n)\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;AA6BA,eAAsB,cACpB,MACA,IACY;CACZ,IAAI,KAAK,WAAW,GAClB,MAAM,IAAI,MAAM,mBAAmB;CAGrC,MAAM,SAAkB,CAAC;CACzB,KAAK,MAAM,OAAO,MAChB,IAAI;EACF,OAAO,MAAM,GAAG,GAAG;CACrB,SAAS,OAAO;EACd,OAAO,KAAK,iBAAiB,QAAQ,QAAQ,IAAI,MAAM,OAAO,KAAK,CAAC,CAAC;CACvE;CAGF,MAAM,IAAI,eAAe,QAAQ,OAAO,KAAK,OAAO,aAAa;AACnE;;;;;AAMA,MAAM,iBACA,YACJ,OAAU,QAAmB,OAA2C;CAEtE,OAAO,cAAc,MADF,QAAQ,MAAM,GACN,EAAE;AAC/B;;;;;;;;;;;;;;;;;;;AAoBF,MAAa,0BACX,cAAc,aAAa;;;;;;;;;;;;;;;;;;;AAoB7B,MAAa,wBAA8C,cAGzD,OAAO,YAAY,MAAM,YAAY,MAAM,EAAA,CAAG,IAChD"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"KeypairWalletAdapter.d.ts","names":[],"sources":["../../../src/utils/KeypairWalletAdapter.ts"],"mappings":";;;;;;;
|
|
1
|
+
{"version":3,"file":"KeypairWalletAdapter.d.ts","names":[],"sources":["../../../src/utils/KeypairWalletAdapter.ts"],"mappings":";;;;;;;cAsBa,gCAAgC;;;;;UAKnC;UACA;mBACS;WAER;WACA;WACA;EAGT,YAAY;MAqBR;MAIA,qBAAqB;MAIrB,YAAY;EAUhB,WAAiB;EAejB,cAAoB;UAMN"}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { base64ToUint8Array } from "./base64ToUint8Array.js";
|
|
2
|
-
import {
|
|
2
|
+
import { assertIsTransactionWithinSizeLimit, createKeyPairSignerFromBytes, getBase58Codec, getBase64EncodedWireTransaction, getTransactionCodec } from "@solana/kit";
|
|
3
3
|
import { SolanaSignTransaction } from "@solana/wallet-standard-features";
|
|
4
4
|
//#region src/utils/KeypairWalletAdapter.ts
|
|
5
5
|
/**
|
|
@@ -66,10 +66,16 @@ var KeypairWalletAdapter = class {
|
|
|
66
66
|
for (const input of inputs) {
|
|
67
67
|
const transaction = getTransactionCodec().decode(input.transaction);
|
|
68
68
|
assertIsTransactionWithinSizeLimit(transaction);
|
|
69
|
-
|
|
70
|
-
const
|
|
71
|
-
if (
|
|
72
|
-
const signedTransaction = getBase64EncodedWireTransaction(
|
|
69
|
+
const [signatureDictionary] = await this._signer.signTransactions([transaction]);
|
|
70
|
+
const signature = signatureDictionary?.[this._signer.address];
|
|
71
|
+
if (!signature) throw new Error("Failed to sign transaction");
|
|
72
|
+
const signedTransaction = getBase64EncodedWireTransaction({
|
|
73
|
+
...transaction,
|
|
74
|
+
signatures: {
|
|
75
|
+
...transaction.signatures,
|
|
76
|
+
[this._signer.address]: signature
|
|
77
|
+
}
|
|
78
|
+
});
|
|
73
79
|
results.push({ signedTransaction: base64ToUint8Array(signedTransaction) });
|
|
74
80
|
}
|
|
75
81
|
return results;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"KeypairWalletAdapter.js","names":[],"sources":["../../../src/utils/KeypairWalletAdapter.ts"],"sourcesContent":["import {\n
|
|
1
|
+
{"version":3,"file":"KeypairWalletAdapter.js","names":[],"sources":["../../../src/utils/KeypairWalletAdapter.ts"],"sourcesContent":["import {\n assertIsTransactionWithinSizeLimit,\n createKeyPairSignerFromBytes,\n getBase58Codec,\n getBase64EncodedWireTransaction,\n getTransactionCodec,\n type KeyPairSigner,\n type ReadonlyUint8Array,\n} from '@solana/kit'\nimport {\n SolanaSignTransaction,\n type SolanaSignTransactionFeature,\n type SolanaSignTransactionInput,\n type SolanaSignTransactionOutput,\n} from '@solana/wallet-standard-features'\nimport type { Wallet, WalletAccount } from '@wallet-standard/base'\nimport { base64ToUint8Array } from './base64ToUint8Array.js'\n\n/**\n * This keypair wallet adapter is unsafe to use on the frontend and is only included to provide an easy way for applications to test\n * Wallet Adapter without using a third-party wallet.\n */\nexport class KeypairWalletAdapter implements Wallet {\n /**\n * Storing a keypair locally like this is not safe because any application using this adapter could retrieve the\n * secret key, and because the keypair will be lost any time the wallet is disconnected or the window is refreshed.\n */\n private _signer: KeyPairSigner | undefined\n private _account: WalletAccount | undefined\n private readonly _secretKeyBytes: ReadonlyUint8Array\n\n readonly version = '1.0.0' as const\n readonly name = 'Keypair Wallet' as const\n readonly icon =\n 'data:image/svg+xml;base64,PHN2ZyB3aWR0aD0iMzIiIGhlaWdodD0iMzIiIHZpZXdCb3g9IjAgMCAzMiAzMiIgZmlsbD0ibm9uZSIgeG1sbnM9Imh0dHA6Ly93d3cudzMub3JnLzIwMDAvc3ZnIj48L3N2Zz4=' as const\n\n constructor(secretKeyBase58: string) {\n if (!secretKeyBase58) {\n throw new Error('Private key is required')\n }\n\n const base58Codec = getBase58Codec()\n let encoded: ReadonlyUint8Array\n try {\n encoded = base58Codec.encode(secretKeyBase58)\n } catch {\n throw new Error('Invalid private key format')\n }\n\n if (encoded.length !== 64) {\n throw new Error('Invalid private key length. Expected 64 bytes.')\n }\n\n this._secretKeyBytes = encoded\n }\n\n // Wallet Standard interface properties\n get chains() {\n return ['solana:mainnet', 'solana:devnet', 'solana:testnet'] as const\n }\n\n get accounts(): readonly WalletAccount[] {\n return this._account ? [this._account] : []\n }\n\n get features(): SolanaSignTransactionFeature {\n return {\n [SolanaSignTransaction]: {\n version: '1.0.0' as const,\n supportedTransactionVersions: ['legacy', 0] as const,\n signTransaction: this._signTransactionFeature.bind(this),\n },\n }\n }\n\n async connect(): Promise<void> {\n this._signer = await createKeyPairSignerFromBytes(this._secretKeyBytes)\n\n const publicKeyBytes = new Uint8Array(\n await crypto.subtle.exportKey('raw', this._signer.keyPair.publicKey)\n )\n\n this._account = {\n address: this._signer.address,\n publicKey: publicKeyBytes,\n chains: this.chains,\n features: [SolanaSignTransaction],\n }\n }\n\n async disconnect(): Promise<void> {\n this._signer = undefined\n this._account = undefined\n }\n\n // Wallet Standard feature implementations\n private async _signTransactionFeature(\n ...inputs: readonly SolanaSignTransactionInput[]\n ): Promise<readonly SolanaSignTransactionOutput[]> {\n if (!this._signer) {\n throw new Error('Wallet is not connected')\n }\n\n const results: SolanaSignTransactionOutput[] = []\n\n for (const input of inputs) {\n const transaction = getTransactionCodec().decode(input.transaction)\n\n assertIsTransactionWithinSizeLimit(transaction)\n\n // `assertIsTransactionWithBlockhashLifetime` is deliberately NOT called\n // here. It tests `'lifetimeConstraint' in transaction`, and no kit\n // decoder reconstructs that property - decoding wire bytes yields\n // `{ messageBytes, signatures }` alone, so the assert rejected every\n // transaction a wallet is ever handed. Signing does not need it either:\n // `partiallySignTransaction` signs `messageBytes` and never reads the\n // lifetime. The blockhash still travels inside `messageBytes`, where\n // `getTransactionLifetime` reads it for the confirmation deadline.\n // Cast because `signTransactions` types its argument as carrying a\n // lifetime, while the runtime path - `partiallySignTransaction` - reads\n // only `messageBytes`. A decoded transaction never has the property, so\n // without this the type demands something no decoder can produce.\n const [signatureDictionary] = await this._signer.signTransactions([\n transaction as Parameters<\n typeof this._signer.signTransactions\n >[0][number],\n ])\n\n const signature = signatureDictionary?.[this._signer.address]\n if (!signature) {\n throw new Error('Failed to sign transaction')\n }\n\n // The signature has to be merged back in. `partiallySignTransaction`\n // returns a new frozen object rather than mutating its argument, so\n // encoding `transaction` here shipped the unsigned original and threw\n // the signature away - the transaction then failed on chain for a\n // missing signature, far from the code that dropped it.\n //\n // The cast mirrors the one above: the wire format is `messageBytes`\n // plus `signatures`, and the encoder reads nothing else - the lifetime\n // already travels inside `messageBytes`.\n const signedTransaction = getBase64EncodedWireTransaction({\n ...transaction,\n signatures: {\n ...transaction.signatures,\n [this._signer.address]: signature,\n },\n } as Parameters<typeof getBase64EncodedWireTransaction>[0])\n\n results.push({\n signedTransaction: base64ToUint8Array(signedTransaction),\n })\n }\n\n return results\n }\n}\n"],"mappings":";;;;;;;;AAsBA,IAAa,uBAAb,MAAoD;;;;;CAKlD;CACA;CACA;CAEA,UAAmB;CACnB,OAAgB;CAChB,OACE;CAEF,YAAY,iBAAyB;EACnC,IAAI,CAAC,iBACH,MAAM,IAAI,MAAM,yBAAyB;EAG3C,MAAM,cAAc,eAAe;EACnC,IAAI;EACJ,IAAI;GACF,UAAU,YAAY,OAAO,eAAe;EAC9C,QAAQ;GACN,MAAM,IAAI,MAAM,4BAA4B;EAC9C;EAEA,IAAI,QAAQ,WAAW,IACrB,MAAM,IAAI,MAAM,gDAAgD;EAGlE,KAAK,kBAAkB;CACzB;CAGA,IAAI,SAAS;EACX,OAAO;GAAC;GAAkB;GAAiB;EAAgB;CAC7D;CAEA,IAAI,WAAqC;EACvC,OAAO,KAAK,WAAW,CAAC,KAAK,QAAQ,IAAI,CAAC;CAC5C;CAEA,IAAI,WAAyC;EAC3C,OAAO,GACJ,wBAAwB;GACvB,SAAS;GACT,8BAA8B,CAAC,UAAU,CAAC;GAC1C,iBAAiB,KAAK,wBAAwB,KAAK,IAAI;EACzD,EACF;CACF;CAEA,MAAM,UAAyB;EAC7B,KAAK,UAAU,MAAM,6BAA6B,KAAK,eAAe;EAEtE,MAAM,iBAAiB,IAAI,WACzB,MAAM,OAAO,OAAO,UAAU,OAAO,KAAK,QAAQ,QAAQ,SAAS,CACrE;EAEA,KAAK,WAAW;GACd,SAAS,KAAK,QAAQ;GACtB,WAAW;GACX,QAAQ,KAAK;GACb,UAAU,CAAC,qBAAqB;EAClC;CACF;CAEA,MAAM,aAA4B;EAChC,KAAK,UAAU,KAAA;EACf,KAAK,WAAW,KAAA;CAClB;CAGA,MAAc,wBACZ,GAAG,QAC8C;EACjD,IAAI,CAAC,KAAK,SACR,MAAM,IAAI,MAAM,yBAAyB;EAG3C,MAAM,UAAyC,CAAC;EAEhD,KAAK,MAAM,SAAS,QAAQ;GAC1B,MAAM,cAAc,oBAAoB,CAAC,CAAC,OAAO,MAAM,WAAW;GAElE,mCAAmC,WAAW;GAc9C,MAAM,CAAC,uBAAuB,MAAM,KAAK,QAAQ,iBAAiB,CAChE,WAGF,CAAC;GAED,MAAM,YAAY,sBAAsB,KAAK,QAAQ;GACrD,IAAI,CAAC,WACH,MAAM,IAAI,MAAM,4BAA4B;GAY9C,MAAM,oBAAoB,gCAAgC;IACxD,GAAG;IACH,YAAY;KACV,GAAG,YAAY;MACd,KAAK,QAAQ,UAAU;IAC1B;GACF,CAA0D;GAE1D,QAAQ,KAAK,EACX,mBAAmB,mBAAmB,iBAAiB,EACzD,CAAC;EACH;EAEA,OAAO;CACT;AACF"}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { Blockhash, Transaction } from "@solana/kit";
|
|
2
|
+
//#region src/utils/getTransactionLifetime.d.ts
|
|
3
|
+
type TransactionLifetime = {
|
|
4
|
+
kind: "blockhash";
|
|
5
|
+
blockhash: Blockhash;
|
|
6
|
+
} | {
|
|
7
|
+
kind: "nonce";
|
|
8
|
+
} | {
|
|
9
|
+
kind: "unknown";
|
|
10
|
+
};
|
|
11
|
+
/**
|
|
12
|
+
* Decoding yields `{ messageBytes, signatures }` alone, so the lifetime is
|
|
13
|
+
* recovered from the compiled message.
|
|
14
|
+
*
|
|
15
|
+
* Never throws: anything undecodable yields `unknown`, degrading confirmation
|
|
16
|
+
* to the wall-clock ceiling rather than aborting the send.
|
|
17
|
+
*/
|
|
18
|
+
declare function getTransactionLifetime(transaction: Transaction): Promise<TransactionLifetime>;
|
|
19
|
+
//#endregion
|
|
20
|
+
export { TransactionLifetime, getTransactionLifetime };
|
|
21
|
+
//# sourceMappingURL=getTransactionLifetime.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"getTransactionLifetime.d.ts","names":[],"sources":["../../../src/utils/getTransactionLifetime.ts"],"mappings":";;KAOY;EACN;EAAmB,WAAW;;EAC9B;;EACA;;;;;;;;;iBAWgB,uBACpB,aAAa,cACZ,QAAQ"}
|