@lifi/sdk-provider-solana 4.3.2 → 4.3.4
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 +14 -0
- package/README.md +9 -0
- package/dist/cjs/actions/lookupSignatureStatus.d.ts +66 -0
- package/dist/cjs/actions/lookupSignatureStatus.js +258 -0
- package/dist/cjs/actions/lookupSignatureStatus.js.map +1 -0
- package/dist/cjs/actions/sendAndConfirmTransaction.d.ts +7 -0
- package/dist/cjs/actions/sendAndConfirmTransaction.js +1 -0
- package/dist/cjs/actions/sendAndConfirmTransaction.js.map +1 -1
- package/dist/cjs/confirmation/confirmBundle.d.ts +1 -1
- package/dist/cjs/confirmation/confirmSignature.d.ts +1 -1
- package/dist/cjs/confirmation/createConfirmationDeadline.d.ts +6 -0
- package/dist/cjs/confirmation/createConfirmationDeadline.js +24 -8
- package/dist/cjs/confirmation/createConfirmationDeadline.js.map +1 -1
- package/dist/cjs/confirmation/pollUntilDeadline.js +9 -1
- package/dist/cjs/confirmation/pollUntilDeadline.js.map +1 -1
- package/dist/cjs/confirmation/raceRpcs.d.ts +8 -0
- package/dist/cjs/confirmation/raceRpcs.js +9 -1
- package/dist/cjs/confirmation/raceRpcs.js.map +1 -1
- package/dist/cjs/confirmation/types.d.ts +3 -0
- package/dist/cjs/confirmation/types.js.map +1 -1
- package/dist/cjs/core/SolanaStepExecutor.js +4 -5
- package/dist/cjs/core/SolanaStepExecutor.js.map +1 -1
- package/dist/cjs/core/tasks/SolanaJitoWaitForTransactionTask.js +69 -33
- package/dist/cjs/core/tasks/SolanaJitoWaitForTransactionTask.js.map +1 -1
- package/dist/cjs/core/tasks/SolanaSignAndExecuteTask.js +13 -5
- package/dist/cjs/core/tasks/SolanaSignAndExecuteTask.js.map +1 -1
- package/dist/cjs/core/tasks/SolanaStandardWaitForTransactionTask.js +71 -38
- package/dist/cjs/core/tasks/SolanaStandardWaitForTransactionTask.js.map +1 -1
- package/dist/cjs/core/tasks/SolanaWaitForTransactionTask.js +13 -1
- package/dist/cjs/core/tasks/SolanaWaitForTransactionTask.js.map +1 -1
- package/dist/cjs/core/tasks/confirmationError.d.ts +29 -0
- package/dist/cjs/core/tasks/confirmationError.js +26 -0
- package/dist/cjs/core/tasks/confirmationError.js.map +1 -0
- package/dist/cjs/core/tasks/resumeFromStore.d.ts +31 -0
- package/dist/cjs/core/tasks/resumeFromStore.js +81 -0
- package/dist/cjs/core/tasks/resumeFromStore.js.map +1 -0
- package/dist/cjs/core/tasks/transactionOutcome.d.ts +107 -0
- package/dist/cjs/core/tasks/transactionOutcome.js +158 -0
- package/dist/cjs/core/tasks/transactionOutcome.js.map +1 -0
- package/dist/cjs/types.d.ts +13 -2
- package/dist/cjs/types.js.map +1 -1
- package/dist/cjs/utils/storedTransactions.d.ts +36 -0
- package/dist/cjs/utils/storedTransactions.js +57 -0
- package/dist/cjs/utils/storedTransactions.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/lookupSignatureStatus.d.ts +66 -0
- package/dist/esm/actions/lookupSignatureStatus.d.ts.map +1 -0
- package/dist/esm/actions/lookupSignatureStatus.js +252 -0
- package/dist/esm/actions/lookupSignatureStatus.js.map +1 -0
- package/dist/esm/actions/sendAndConfirmTransaction.d.ts +7 -0
- package/dist/esm/actions/sendAndConfirmTransaction.d.ts.map +1 -1
- package/dist/esm/actions/sendAndConfirmTransaction.js +1 -0
- package/dist/esm/actions/sendAndConfirmTransaction.js.map +1 -1
- package/dist/esm/confirmation/confirmBundle.d.ts +1 -1
- package/dist/esm/confirmation/confirmSignature.d.ts +1 -1
- package/dist/esm/confirmation/createConfirmationDeadline.d.ts +6 -0
- package/dist/esm/confirmation/createConfirmationDeadline.d.ts.map +1 -1
- package/dist/esm/confirmation/createConfirmationDeadline.js +24 -8
- package/dist/esm/confirmation/createConfirmationDeadline.js.map +1 -1
- package/dist/esm/confirmation/pollUntilDeadline.js +9 -1
- package/dist/esm/confirmation/pollUntilDeadline.js.map +1 -1
- package/dist/esm/confirmation/raceRpcs.d.ts +8 -0
- package/dist/esm/confirmation/raceRpcs.d.ts.map +1 -1
- package/dist/esm/confirmation/raceRpcs.js +9 -1
- package/dist/esm/confirmation/raceRpcs.js.map +1 -1
- package/dist/esm/confirmation/types.d.ts +3 -0
- package/dist/esm/confirmation/types.d.ts.map +1 -1
- package/dist/esm/confirmation/types.js.map +1 -1
- package/dist/esm/core/SolanaStepExecutor.d.ts.map +1 -1
- package/dist/esm/core/SolanaStepExecutor.js +5 -6
- package/dist/esm/core/SolanaStepExecutor.js.map +1 -1
- package/dist/esm/core/tasks/SolanaJitoWaitForTransactionTask.d.ts.map +1 -1
- package/dist/esm/core/tasks/SolanaJitoWaitForTransactionTask.js +69 -33
- package/dist/esm/core/tasks/SolanaJitoWaitForTransactionTask.js.map +1 -1
- package/dist/esm/core/tasks/SolanaSignAndExecuteTask.d.ts.map +1 -1
- package/dist/esm/core/tasks/SolanaSignAndExecuteTask.js +14 -6
- 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 +71 -38
- package/dist/esm/core/tasks/SolanaStandardWaitForTransactionTask.js.map +1 -1
- package/dist/esm/core/tasks/SolanaWaitForTransactionTask.d.ts.map +1 -1
- package/dist/esm/core/tasks/SolanaWaitForTransactionTask.js +13 -1
- package/dist/esm/core/tasks/SolanaWaitForTransactionTask.js.map +1 -1
- package/dist/esm/core/tasks/confirmationError.d.ts +29 -0
- package/dist/esm/core/tasks/confirmationError.d.ts.map +1 -0
- package/dist/esm/core/tasks/confirmationError.js +25 -0
- package/dist/esm/core/tasks/confirmationError.js.map +1 -0
- package/dist/esm/core/tasks/resumeFromStore.d.ts +31 -0
- package/dist/esm/core/tasks/resumeFromStore.d.ts.map +1 -0
- package/dist/esm/core/tasks/resumeFromStore.js +80 -0
- package/dist/esm/core/tasks/resumeFromStore.js.map +1 -0
- package/dist/esm/core/tasks/transactionOutcome.d.ts +107 -0
- package/dist/esm/core/tasks/transactionOutcome.d.ts.map +1 -0
- package/dist/esm/core/tasks/transactionOutcome.js +150 -0
- package/dist/esm/core/tasks/transactionOutcome.js.map +1 -0
- package/dist/esm/types.d.ts +13 -2
- package/dist/esm/types.d.ts.map +1 -1
- package/dist/esm/types.js.map +1 -1
- package/dist/esm/utils/storedTransactions.d.ts +36 -0
- package/dist/esm/utils/storedTransactions.d.ts.map +1 -0
- package/dist/esm/utils/storedTransactions.js +54 -0
- package/dist/esm/utils/storedTransactions.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 +2 -2
- package/src/actions/lookupSignatureStatus.ts +444 -0
- package/src/actions/sendAndConfirmTransaction.ts +18 -0
- package/src/confirmation/createConfirmationDeadline.ts +43 -11
- package/src/confirmation/pollUntilDeadline.ts +14 -1
- package/src/confirmation/raceRpcs.ts +27 -1
- package/src/confirmation/types.ts +5 -0
- package/src/core/SolanaStepExecutor.ts +26 -11
- package/src/core/tasks/SolanaJitoWaitForTransactionTask.ts +133 -71
- package/src/core/tasks/SolanaSignAndExecuteTask.ts +51 -10
- package/src/core/tasks/SolanaStandardWaitForTransactionTask.ts +130 -76
- package/src/core/tasks/SolanaWaitForTransactionTask.ts +19 -1
- package/src/core/tasks/confirmationError.ts +60 -0
- package/src/core/tasks/resumeFromStore.ts +160 -0
- package/src/core/tasks/transactionOutcome.ts +273 -0
- package/src/types.ts +13 -1
- package/src/utils/storedTransactions.ts +88 -0
- package/src/version.ts +1 -1
- package/dist/cjs/core/tasks/unwrapConfirmation.d.ts +0 -24
- package/dist/cjs/core/tasks/unwrapConfirmation.js +0 -24
- package/dist/cjs/core/tasks/unwrapConfirmation.js.map +0 -1
- package/dist/esm/core/tasks/unwrapConfirmation.d.ts +0 -24
- package/dist/esm/core/tasks/unwrapConfirmation.d.ts.map +0 -1
- package/dist/esm/core/tasks/unwrapConfirmation.js +0 -23
- package/dist/esm/core/tasks/unwrapConfirmation.js.map +0 -1
- package/src/core/tasks/unwrapConfirmation.ts +0 -59
|
@@ -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 {
|
|
1
|
+
{"version":3,"file":"SolanaStandardWaitForTransactionTask.js","names":[],"sources":["../../../../src/core/tasks/SolanaStandardWaitForTransactionTask.ts"],"sourcesContent":["import {\n BaseStepExecutionTask,\n type ExecutionAction,\n LiFiErrorCode,\n type TaskResult,\n TransactionError,\n} from '@lifi/sdk'\nimport {\n getBase64EncodedWireTransaction,\n type Signature,\n type Transaction,\n} from '@solana/kit'\nimport { sendAndConfirmTransaction } from '../../actions/sendAndConfirmTransaction.js'\nimport { callSolanaRpcsWithRetry } from '../../rpc/utils.js'\nimport type { SolanaStepExecutorContext } from '../../types.js'\nimport {\n getTransactionLifetime,\n type TransactionLifetime,\n} from '../../utils/getTransactionLifetime.js'\nimport { SolanaTransactionDetailsError } from '../../utils/solanaErrorCause.js'\nimport type { ConfirmationMessages } from './confirmationError.js'\nimport { readSignature } from './readSignature.js'\nimport { resumeFromStore } from './resumeFromStore.js'\nimport {\n canResendStored,\n clearStoredTransactions,\n failureOf,\n getTxLink,\n sendAndSettle,\n} from './transactionOutcome.js'\n\nconst MESSAGES: ConfirmationMessages = {\n rpcUnavailable:\n 'Unable to confirm transaction: no Solana RPC returned a usable response.',\n notConfirmed: '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\nexport class SolanaStandardWaitForTransactionTask extends BaseStepExecutionTask {\n async run(context: SolanaStepExecutorContext): Promise<TaskResult> {\n const { step, statusManager, isBridgeExecution, signedTransactions } =\n context\n\n const action = statusManager.findAction(\n step,\n isBridgeExecution ? 'CROSS_CHAIN' : 'SWAP'\n )\n if (!action) {\n throw new TransactionError(\n LiFiErrorCode.TransactionUnprepared,\n 'Unable to prepare transaction. Action not found.'\n )\n }\n\n // Resume mode: the sign task did not run in this session, so the signed\n // bytes come from `txHex`, or only the hash from `txHash`.\n if (!signedTransactions) {\n return resumeFromStore(context, action, {\n messages: MESSAGES,\n send: (stored, lifetimes) =>\n sendSigned(context, action, {\n transaction: stored.transactions[0],\n signature: stored.signature,\n lifetimes,\n resuming: true,\n }),\n })\n }\n\n if (!signedTransactions.length) {\n throw new TransactionError(\n LiFiErrorCode.TransactionUnprepared,\n 'Unable to prepare transaction. Signed transactions are not found.'\n )\n }\n\n // Use regular transaction submission\n const signedTransaction = signedTransactions[0]\n\n let txSignature: Signature\n let lifetime: TransactionLifetime\n try {\n if (!context.skipSimulation) {\n await simulate(context, signedTransaction)\n }\n txSignature = readSignature(signedTransaction)\n lifetime = await getTransactionLifetime(signedTransaction)\n } catch (error) {\n // Nothing left the SDK: the bytes go, so \"Try again\" signs again\n // instead of resending a transaction that failed before it was sent.\n clearStoredTransactions(context, action)\n throw error\n }\n\n return sendSigned(context, action, {\n transaction: signedTransaction,\n signature: txSignature,\n lifetimes: [lifetime],\n resuming: false,\n })\n }\n}\n\n/**\n * Sends one signed transaction, confirms it and applies the result rules of\n * `sendAndSettle`, on the first run and on a resume alike.\n */\nfunction sendSigned(\n context: SolanaStepExecutorContext,\n action: ExecutionAction,\n options: {\n transaction: Transaction\n signature: Signature\n lifetimes: TransactionLifetime[]\n /** An earlier run may already have sent these bytes. */\n resuming: boolean\n }\n): Promise<TaskResult> {\n const { client, step, statusManager } = context\n const { transaction, signature, lifetimes, resuming } = options\n const txLink = getTxLink(context, signature)\n\n return sendAndSettle(context, action, {\n signature,\n send: () =>\n sendAndConfirmTransaction(client, transaction, {\n onBroadcast: () => {\n // The earliest honest point for both: an RPC has accepted the\n // transaction, so the signature now resolves on chain.\n statusManager.updateAction(step, action.type, 'PENDING', {\n txHash: signature,\n txLink,\n })\n },\n // Read at every send: bytes without their own expiry go out only\n // inside the resend age cap, however long the resend loop runs.\n mayResend: () => canResendStored(lifetimes, step.execution?.signedAt),\n }),\n confirmedFailure: failureOf,\n resuming,\n messages: MESSAGES,\n })\n}\n\n/** First run only: a resend never simulates. */\nasync function simulate(\n context: SolanaStepExecutorContext,\n signedTransaction: Transaction\n): Promise<void> {\n const encodedTransaction = getBase64EncodedWireTransaction(signedTransaction)\n\n const simulationResult = await callSolanaRpcsWithRetry(\n context.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"],"mappings":";;;;;;;;;;AA+BA,MAAM,WAAiC;CACrC,gBACE;CACF,cAAc;CACd,eAAe;CACf,gBACE;AACJ;AAEA,IAAa,uCAAb,cAA0D,sBAAsB;CAC9E,MAAM,IAAI,SAAyD;EACjE,MAAM,EAAE,MAAM,eAAe,mBAAmB,uBAC9C;EAEF,MAAM,SAAS,cAAc,WAC3B,MACA,oBAAoB,gBAAgB,MACtC;EACA,IAAI,CAAC,QACH,MAAM,IAAI,iBACR,cAAc,uBACd,kDACF;EAKF,IAAI,CAAC,oBACH,OAAO,gBAAgB,SAAS,QAAQ;GACtC,UAAU;GACV,OAAO,QAAQ,cACb,WAAW,SAAS,QAAQ;IAC1B,aAAa,OAAO,aAAa;IACjC,WAAW,OAAO;IAClB;IACA,UAAU;GACZ,CAAC;EACL,CAAC;EAGH,IAAI,CAAC,mBAAmB,QACtB,MAAM,IAAI,iBACR,cAAc,uBACd,mEACF;EAIF,MAAM,oBAAoB,mBAAmB;EAE7C,IAAI;EACJ,IAAI;EACJ,IAAI;GACF,IAAI,CAAC,QAAQ,gBACX,MAAM,SAAS,SAAS,iBAAiB;GAE3C,cAAc,cAAc,iBAAiB;GAC7C,WAAW,MAAM,uBAAuB,iBAAiB;EAC3D,SAAS,OAAO;GAGd,wBAAwB,SAAS,MAAM;GACvC,MAAM;EACR;EAEA,OAAO,WAAW,SAAS,QAAQ;GACjC,aAAa;GACb,WAAW;GACX,WAAW,CAAC,QAAQ;GACpB,UAAU;EACZ,CAAC;CACH;AACF;;;;;AAMA,SAAS,WACP,SACA,QACA,SAOqB;CACrB,MAAM,EAAE,QAAQ,MAAM,kBAAkB;CACxC,MAAM,EAAE,aAAa,WAAW,WAAW,aAAa;CACxD,MAAM,SAAS,UAAU,SAAS,SAAS;CAE3C,OAAO,cAAc,SAAS,QAAQ;EACpC;EACA,YACE,0BAA0B,QAAQ,aAAa;GAC7C,mBAAmB;IAGjB,cAAc,aAAa,MAAM,OAAO,MAAM,WAAW;KACvD,QAAQ;KACR;IACF,CAAC;GACH;GAGA,iBAAiB,gBAAgB,WAAW,KAAK,WAAW,QAAQ;EACtE,CAAC;EACH,kBAAkB;EAClB;EACA,UAAU;CACZ,CAAC;AACH;;AAGA,eAAe,SACb,SACA,mBACe;CACf,MAAM,qBAAqB,gCAAgC,iBAAiB;CAE5E,MAAM,mBAAmB,MAAM,wBAC7B,QAAQ,SACP,eACC,WACG,oBAAoB,oBAAoB;EACvC,YAAY;EACZ,wBAAwB;EACxB,UAAU;CACZ,CAAC,CAAC,CACD,KAAK,CACZ;CAEA,IAAI,iBAAiB,MAAM,KAAK;EAC9B,MAAM,QAAQ,IAAI,8BAChB,iBAAiB,MAAM,KACvB,iBAAiB,MAAM,IACzB;EACA,MAAM,IAAI,iBACR,cAAc,6BACd,kCAAkC,MAAM,WACxC,KACF;CACF;AACF"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"SolanaWaitForTransactionTask.d.ts","names":[],"sources":["../../../../src/core/tasks/SolanaWaitForTransactionTask.ts"],"mappings":";;;
|
|
1
|
+
{"version":3,"file":"SolanaWaitForTransactionTask.d.ts","names":[],"sources":["../../../../src/core/tasks/SolanaWaitForTransactionTask.ts"],"mappings":";;;qBAuBa,qCAAqC;EAChD,IAAU,SAAS,4BAA4B,QAAQ"}
|
|
@@ -1,10 +1,22 @@
|
|
|
1
|
+
import { isStoredBundle } from "../../utils/storedTransactions.js";
|
|
1
2
|
import { SolanaJitoWaitForTransactionTask } from "./SolanaJitoWaitForTransactionTask.js";
|
|
2
3
|
import { SolanaStandardWaitForTransactionTask } from "./SolanaStandardWaitForTransactionTask.js";
|
|
3
4
|
import { BaseStepExecutionTask } from "@lifi/sdk";
|
|
4
5
|
//#region src/core/tasks/SolanaWaitForTransactionTask.ts
|
|
6
|
+
/**
|
|
7
|
+
* On a resume the sign task did not run, so the flag is missing and the
|
|
8
|
+
* stored bytes keep the shape instead: a leading `[` marks a bundle. With a
|
|
9
|
+
* `txHash` alone the standard task looks the signature up, which works for a
|
|
10
|
+
* bundle's first signature too.
|
|
11
|
+
*/
|
|
12
|
+
function isBundleExecution(context) {
|
|
13
|
+
if (context.isBundleExecution !== void 0) return context.isBundleExecution;
|
|
14
|
+
const action = context.statusManager.findAction(context.step, context.isBridgeExecution ? "CROSS_CHAIN" : "SWAP");
|
|
15
|
+
return action?.txHex ? isStoredBundle(action.txHex) : false;
|
|
16
|
+
}
|
|
5
17
|
var SolanaWaitForTransactionTask = class extends BaseStepExecutionTask {
|
|
6
18
|
async run(context) {
|
|
7
|
-
if (context
|
|
19
|
+
if (isBundleExecution(context)) return new SolanaJitoWaitForTransactionTask().run(context);
|
|
8
20
|
return new SolanaStandardWaitForTransactionTask().run(context);
|
|
9
21
|
}
|
|
10
22
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"SolanaWaitForTransactionTask.js","names":[],"sources":["../../../../src/core/tasks/SolanaWaitForTransactionTask.ts"],"sourcesContent":["import { BaseStepExecutionTask, type TaskResult } from '@lifi/sdk'\nimport type { SolanaStepExecutorContext } from '../../types.js'\nimport { SolanaJitoWaitForTransactionTask } from './SolanaJitoWaitForTransactionTask.js'\nimport { SolanaStandardWaitForTransactionTask } from './SolanaStandardWaitForTransactionTask.js'\n\nexport class SolanaWaitForTransactionTask extends BaseStepExecutionTask {\n async run(context: SolanaStepExecutorContext): Promise<TaskResult> {\n // The submission method is determined by the shape of the backend's\n // `transactionRequest.data` (resolved in SolanaSignAndExecuteTask):\n // a bundle (array) must go through `sendBundle`, a single transaction\n // (string) through `sendTransaction`.\n if (context
|
|
1
|
+
{"version":3,"file":"SolanaWaitForTransactionTask.js","names":[],"sources":["../../../../src/core/tasks/SolanaWaitForTransactionTask.ts"],"sourcesContent":["import { BaseStepExecutionTask, type TaskResult } from '@lifi/sdk'\nimport type { SolanaStepExecutorContext } from '../../types.js'\nimport { isStoredBundle } from '../../utils/storedTransactions.js'\nimport { SolanaJitoWaitForTransactionTask } from './SolanaJitoWaitForTransactionTask.js'\nimport { SolanaStandardWaitForTransactionTask } from './SolanaStandardWaitForTransactionTask.js'\n\n/**\n * On a resume the sign task did not run, so the flag is missing and the\n * stored bytes keep the shape instead: a leading `[` marks a bundle. With a\n * `txHash` alone the standard task looks the signature up, which works for a\n * bundle's first signature too.\n */\nfunction isBundleExecution(context: SolanaStepExecutorContext): boolean {\n if (context.isBundleExecution !== undefined) {\n return context.isBundleExecution\n }\n const action = context.statusManager.findAction(\n context.step,\n context.isBridgeExecution ? 'CROSS_CHAIN' : 'SWAP'\n )\n return action?.txHex ? isStoredBundle(action.txHex) : false\n}\n\nexport class SolanaWaitForTransactionTask extends BaseStepExecutionTask {\n async run(context: SolanaStepExecutorContext): Promise<TaskResult> {\n // The submission method is determined by the shape of the backend's\n // `transactionRequest.data` (resolved in SolanaSignAndExecuteTask):\n // a bundle (array) must go through `sendBundle`, a single transaction\n // (string) through `sendTransaction`.\n if (isBundleExecution(context)) {\n return new SolanaJitoWaitForTransactionTask().run(context)\n }\n return new SolanaStandardWaitForTransactionTask().run(context)\n }\n}\n"],"mappings":";;;;;;;;;;;AAYA,SAAS,kBAAkB,SAA6C;CACtE,IAAI,QAAQ,sBAAsB,KAAA,GAChC,OAAO,QAAQ;CAEjB,MAAM,SAAS,QAAQ,cAAc,WACnC,QAAQ,MACR,QAAQ,oBAAoB,gBAAgB,MAC9C;CACA,OAAO,QAAQ,QAAQ,eAAe,OAAO,KAAK,IAAI;AACxD;AAEA,IAAa,+BAAb,cAAkD,sBAAsB;CACtE,MAAM,IAAI,SAAyD;EAKjE,IAAI,kBAAkB,OAAO,GAC3B,OAAO,IAAI,iCAAiC,CAAC,CAAC,IAAI,OAAO;EAE3D,OAAO,IAAI,qCAAqC,CAAC,CAAC,IAAI,OAAO;CAC/D;AACF"}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { UnconfirmedRaceResult } from "../../confirmation/raceRpcs.js";
|
|
2
|
+
import { RPCError, TransactionError } from "@lifi/sdk";
|
|
3
|
+
//#region src/core/tasks/confirmationError.d.ts
|
|
4
|
+
/** Only the nouns differ between the standard and bundle paths. */
|
|
5
|
+
export type ConfirmationMessages = {
|
|
6
|
+
/** Every branch failed: an outage, not a verdict about the transaction. */
|
|
7
|
+
rpcUnavailable: string;
|
|
8
|
+
/** A branch polled to its deadline and saw nothing, or the blockhash
|
|
9
|
+
* expired. Also the text of a final "dropped" verdict. */
|
|
10
|
+
notConfirmed: string;
|
|
11
|
+
/** Heading of the `AggregateError` chained onto `rpcUnavailable`. */
|
|
12
|
+
allRpcsFailed: string;
|
|
13
|
+
/** Heading of the `AggregateError` chained onto `notConfirmed`. */
|
|
14
|
+
someRpcsFailed: string;
|
|
15
|
+
};
|
|
16
|
+
/**
|
|
17
|
+
* The error the integrator sees for a result that did not confirm.
|
|
18
|
+
*
|
|
19
|
+
* `rpc-unavailable` and `not-confirmed` must stay distinct: collapsing them
|
|
20
|
+
* reported a live RPC defect as an expired transaction.
|
|
21
|
+
*
|
|
22
|
+
* `expired` maps exactly like `not-confirmed` - same code, same message - so
|
|
23
|
+
* no text changes. The wait tasks tell the two apart by `result.kind` before
|
|
24
|
+
* they call this: only they can run the history lookup and the status API a
|
|
25
|
+
* final "dropped" needs, so the final marker is theirs to add.
|
|
26
|
+
*/
|
|
27
|
+
export declare function confirmationError(result: UnconfirmedRaceResult, messages: ConfirmationMessages): RPCError | TransactionError;
|
|
28
|
+
//#endregion
|
|
29
|
+
//# sourceMappingURL=confirmationError.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"confirmationError.d.ts","names":[],"sources":["../../../../src/core/tasks/confirmationError.ts"],"mappings":";;;;YAIY;;EAEV;;;EAGA;;EAEA;;EAEA;;;;;;;;;;;;;wBAyBc,kBACd,QAAQ,uBACR,UAAU,uBACT,WAAW"}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { LiFiErrorCode, RPCError, TransactionError } from "@lifi/sdk";
|
|
2
|
+
//#region src/core/tasks/confirmationError.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
|
+
* The error the integrator sees for a result that did not confirm.
|
|
9
|
+
*
|
|
10
|
+
* `rpc-unavailable` and `not-confirmed` must stay distinct: collapsing them
|
|
11
|
+
* reported a live RPC defect as an expired transaction.
|
|
12
|
+
*
|
|
13
|
+
* `expired` maps exactly like `not-confirmed` - same code, same message - so
|
|
14
|
+
* no text changes. The wait tasks tell the two apart by `result.kind` before
|
|
15
|
+
* they call this: only they can run the history lookup and the status API a
|
|
16
|
+
* final "dropped" needs, so the final marker is theirs to add.
|
|
17
|
+
*/
|
|
18
|
+
function confirmationError(result, messages) {
|
|
19
|
+
if (result.kind === "rpc-unavailable") return new RPCError(LiFiErrorCode.RpcUnavailable, messages.rpcUnavailable, chainErrors(result.errors, messages.allRpcsFailed));
|
|
20
|
+
return new TransactionError(LiFiErrorCode.TransactionExpired, messages.notConfirmed, chainErrors(result.errors, messages.someRpcsFailed));
|
|
21
|
+
}
|
|
22
|
+
//#endregion
|
|
23
|
+
export { confirmationError };
|
|
24
|
+
|
|
25
|
+
//# sourceMappingURL=confirmationError.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"confirmationError.js","names":[],"sources":["../../../../src/core/tasks/confirmationError.ts"],"sourcesContent":["import { LiFiErrorCode, RPCError, TransactionError } from '@lifi/sdk'\nimport type { UnconfirmedRaceResult } 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, or the blockhash\n * expired. Also the text of a final \"dropped\" verdict. */\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 * The error the integrator sees for a result that did not confirm.\n *\n * `rpc-unavailable` and `not-confirmed` must stay distinct: collapsing them\n * reported a live RPC defect as an expired transaction.\n *\n * `expired` maps exactly like `not-confirmed` - same code, same message - so\n * no text changes. The wait tasks tell the two apart by `result.kind` before\n * they call this: only they can run the history lookup and the status API a\n * final \"dropped\" needs, so the final marker is theirs to add.\n */\nexport function confirmationError(\n result: UnconfirmedRaceResult,\n messages: ConfirmationMessages\n): RPCError | TransactionError {\n if (result.kind === 'rpc-unavailable') {\n return new RPCError(\n LiFiErrorCode.RpcUnavailable,\n messages.rpcUnavailable,\n chainErrors(result.errors, messages.allRpcsFailed)\n )\n }\n\n // The verdict came from branches that polled to their deadline or saw the\n // blockhash expire, but other branches may have died trying - and their\n // errors are the only trail explaining, say, an endpoint that never\n // answered.\n return new TransactionError(\n LiFiErrorCode.TransactionExpired,\n messages.notConfirmed,\n chainErrors(result.errors, messages.someRpcsFailed)\n )\n}\n"],"mappings":";;;;;AAmBA,MAAM,eACJ,QACA,YAEA,OAAO,SACH,IAAI,eAAe,QAAQ,SAAS,EAAE,OAAO,OAAO,GAAG,CAAC,IACxD,KAAA;;;;;;;;;;;;AAaN,SAAgB,kBACd,QACA,UAC6B;CAC7B,IAAI,OAAO,SAAS,mBAClB,OAAO,IAAI,SACT,cAAc,gBACd,SAAS,gBACT,YAAY,OAAO,QAAQ,SAAS,aAAa,CACnD;CAOF,OAAO,IAAI,iBACT,cAAc,oBACd,SAAS,cACT,YAAY,OAAO,QAAQ,SAAS,cAAc,CACpD;AACF"}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { SolanaStepExecutorContext } from "../../types.js";
|
|
2
|
+
import { TransactionLifetime } from "../../utils/getTransactionLifetime.js";
|
|
3
|
+
import { ConfirmationMessages } from "./confirmationError.js";
|
|
4
|
+
import { StoredTransactions } from "../../utils/storedTransactions.js";
|
|
5
|
+
import { ExecutionAction, TaskResult } from "@lifi/sdk";
|
|
6
|
+
//#region src/core/tasks/resumeFromStore.d.ts
|
|
7
|
+
/**
|
|
8
|
+
* Resume mode of both wait tasks: the sign task did not run in this session,
|
|
9
|
+
* so the transaction comes from the action.
|
|
10
|
+
*
|
|
11
|
+
* 1. Look the signature up on every RPC. A confirmed status goes straight to
|
|
12
|
+
* the result rules: the transaction may have landed after the page closed.
|
|
13
|
+
* This look only has to find, so it asks for no canary.
|
|
14
|
+
* 2. Otherwise resend the stored bytes through `send` when that is allowed -
|
|
15
|
+
* the task's normal send path, without simulation.
|
|
16
|
+
* 3. Otherwise - a hash alone, or bytes past the resend age cap - nothing is
|
|
17
|
+
* sent, and only the dropped rule can make the outcome final.
|
|
18
|
+
*
|
|
19
|
+
* Bytes that are not the stored txHash's transaction are never sent, and the
|
|
20
|
+
* dropped rule never runs for them: the outcome stays unknown unless the
|
|
21
|
+
* lookup by txHash finds it confirmed.
|
|
22
|
+
*/
|
|
23
|
+
export declare function resumeFromStore(context: SolanaStepExecutorContext, action: ExecutionAction, options: {
|
|
24
|
+
messages: ConfirmationMessages;
|
|
25
|
+
/** Sends the stored bytes and applies the result rules, as the first
|
|
26
|
+
* run does, but never simulates: a transaction that already landed, or
|
|
27
|
+
* funds it already spent, would fail the simulation falsely. */
|
|
28
|
+
send: (stored: StoredTransactions, lifetimes: TransactionLifetime[]) => Promise<TaskResult>;
|
|
29
|
+
}): Promise<TaskResult>;
|
|
30
|
+
//#endregion
|
|
31
|
+
//# sourceMappingURL=resumeFromStore.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"resumeFromStore.d.ts","names":[],"sources":["../../../../src/core/tasks/resumeFromStore.ts"],"mappings":";;;;;;;;;;;;;;;;;;;;;;wBAyFsB,gBACpB,SAAS,2BACT,QAAQ,iBACR;EACE,UAAU;;;;EAIV,OACE,QAAQ,oBACR,WAAW,0BACR,QAAQ;IAEd,QAAQ"}
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
import { decodeStoredTransactions } from "../../utils/storedTransactions.js";
|
|
2
|
+
import { isConfirmedCommitment } from "../../confirmation/types.js";
|
|
3
|
+
import { getTransactionLifetime } from "../../utils/getTransactionLifetime.js";
|
|
4
|
+
import { lookupSignatureStatus } from "../../actions/lookupSignatureStatus.js";
|
|
5
|
+
import { confirmationError } from "./confirmationError.js";
|
|
6
|
+
import { canResendStored, clearStoredTransactions, failureOf, recordLanded, resolveUnconfirmed } from "./transactionOutcome.js";
|
|
7
|
+
import { LiFiErrorCode, TransactionError } from "@lifi/sdk";
|
|
8
|
+
//#region src/core/tasks/resumeFromStore.ts
|
|
9
|
+
function readResumeSource(context, action) {
|
|
10
|
+
if (action.txHex) {
|
|
11
|
+
const stored = decodeStoredTransactions(action.txHex);
|
|
12
|
+
if (stored) {
|
|
13
|
+
if (action.txHash && action.txHash !== stored.signature) return {
|
|
14
|
+
kind: "mismatch",
|
|
15
|
+
signature: action.txHash
|
|
16
|
+
};
|
|
17
|
+
return {
|
|
18
|
+
kind: "bytes",
|
|
19
|
+
stored
|
|
20
|
+
};
|
|
21
|
+
}
|
|
22
|
+
clearStoredTransactions(context, action);
|
|
23
|
+
}
|
|
24
|
+
if (action.txHash) return {
|
|
25
|
+
kind: "hash",
|
|
26
|
+
signature: action.txHash
|
|
27
|
+
};
|
|
28
|
+
throw new TransactionError(LiFiErrorCode.TransactionUnprepared, "Unable to prepare transaction. Signed transactions are not found.");
|
|
29
|
+
}
|
|
30
|
+
/**
|
|
31
|
+
* Resume mode of both wait tasks: the sign task did not run in this session,
|
|
32
|
+
* so the transaction comes from the action.
|
|
33
|
+
*
|
|
34
|
+
* 1. Look the signature up on every RPC. A confirmed status goes straight to
|
|
35
|
+
* the result rules: the transaction may have landed after the page closed.
|
|
36
|
+
* This look only has to find, so it asks for no canary.
|
|
37
|
+
* 2. Otherwise resend the stored bytes through `send` when that is allowed -
|
|
38
|
+
* the task's normal send path, without simulation.
|
|
39
|
+
* 3. Otherwise - a hash alone, or bytes past the resend age cap - nothing is
|
|
40
|
+
* sent, and only the dropped rule can make the outcome final.
|
|
41
|
+
*
|
|
42
|
+
* Bytes that are not the stored txHash's transaction are never sent, and the
|
|
43
|
+
* dropped rule never runs for them: the outcome stays unknown unless the
|
|
44
|
+
* lookup by txHash finds it confirmed.
|
|
45
|
+
*/
|
|
46
|
+
async function resumeFromStore(context, action, options) {
|
|
47
|
+
const { client, step } = context;
|
|
48
|
+
const source = readResumeSource(context, action);
|
|
49
|
+
const signature = source.kind === "bytes" ? source.stored.signature : source.signature;
|
|
50
|
+
const lookup = await lookupSignatureStatus(client, signature);
|
|
51
|
+
if (lookup.kind === "found" && isConfirmedCommitment(lookup.status.confirmationStatus)) return recordLanded(context, action, {
|
|
52
|
+
signature,
|
|
53
|
+
failure: failureOf(lookup.status)
|
|
54
|
+
});
|
|
55
|
+
const lifetimes = source.kind === "bytes" ? await Promise.all(source.stored.transactions.map((transaction) => getTransactionLifetime(transaction))) : [];
|
|
56
|
+
if (source.kind === "bytes" && canResendStored(lifetimes, step.execution?.signedAt)) return options.send(source.stored, lifetimes);
|
|
57
|
+
const silent = lookup.kind === "unknown" && !lookup.answered;
|
|
58
|
+
const error = confirmationError(silent ? {
|
|
59
|
+
kind: "rpc-unavailable",
|
|
60
|
+
errors: lookup.errors
|
|
61
|
+
} : {
|
|
62
|
+
kind: "not-confirmed",
|
|
63
|
+
errors: []
|
|
64
|
+
}, options.messages);
|
|
65
|
+
if (source.kind === "mismatch") throw error;
|
|
66
|
+
const status = await resolveUnconfirmed(context, action, {
|
|
67
|
+
signature,
|
|
68
|
+
error,
|
|
69
|
+
expiredAtSlot: void 0,
|
|
70
|
+
messages: options.messages
|
|
71
|
+
});
|
|
72
|
+
return recordLanded(context, action, {
|
|
73
|
+
signature,
|
|
74
|
+
failure: failureOf(status)
|
|
75
|
+
});
|
|
76
|
+
}
|
|
77
|
+
//#endregion
|
|
78
|
+
export { resumeFromStore };
|
|
79
|
+
|
|
80
|
+
//# sourceMappingURL=resumeFromStore.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"resumeFromStore.js","names":[],"sources":["../../../../src/core/tasks/resumeFromStore.ts"],"sourcesContent":["import {\n type ExecutionAction,\n LiFiErrorCode,\n type TaskResult,\n TransactionError,\n} from '@lifi/sdk'\nimport type { Signature } from '@solana/kit'\nimport { lookupSignatureStatus } from '../../actions/lookupSignatureStatus.js'\nimport { isConfirmedCommitment } from '../../confirmation/types.js'\nimport type { SolanaStepExecutorContext } from '../../types.js'\nimport {\n getTransactionLifetime,\n type TransactionLifetime,\n} from '../../utils/getTransactionLifetime.js'\nimport {\n decodeStoredTransactions,\n type StoredTransactions,\n} from '../../utils/storedTransactions.js'\nimport {\n type ConfirmationMessages,\n confirmationError,\n} from './confirmationError.js'\nimport {\n canResendStored,\n clearStoredTransactions,\n failureOf,\n recordLanded,\n resolveUnconfirmed,\n} from './transactionOutcome.js'\n\n/** What a resumed wait task can work from. */\ntype ResumeSource =\n /** Signed bytes that may still need to be sent. */\n | { kind: 'bytes'; stored: StoredTransactions }\n /** A broadcast signature alone: a route stored before the upgrade, or\n * bytes that no longer decode. */\n | { kind: 'hash'; signature: Signature }\n /** Bytes whose first signature is not the stored txHash (damaged\n * storage). They prove nothing about that transaction, and they may have\n * been sent: nothing is sent and nothing is dropped. */\n | { kind: 'mismatch'; signature: Signature }\n\nfunction readResumeSource(\n context: SolanaStepExecutorContext,\n action: ExecutionAction\n): ResumeSource {\n if (action.txHex) {\n const stored = decodeStoredTransactions(action.txHex)\n if (stored) {\n if (action.txHash && action.txHash !== stored.signature) {\n return { kind: 'mismatch', signature: action.txHash as Signature }\n }\n return { kind: 'bytes', stored }\n }\n // The sign task stores only bytes that decode, so these were damaged\n // after the write - by the integrator's storage, say. They would fail\n // every resume the same way.\n clearStoredTransactions(context, action)\n }\n\n if (action.txHash) {\n return { kind: 'hash', signature: action.txHash as Signature }\n }\n\n // Without a hash no RPC ever accepted a send - `txHash` is written on the\n // first accepted one - so nothing can land. No final marker: \"Try again\"\n // signs again.\n throw new TransactionError(\n LiFiErrorCode.TransactionUnprepared,\n 'Unable to prepare transaction. Signed transactions are not found.'\n )\n}\n\n/**\n * Resume mode of both wait tasks: the sign task did not run in this session,\n * so the transaction comes from the action.\n *\n * 1. Look the signature up on every RPC. A confirmed status goes straight to\n * the result rules: the transaction may have landed after the page closed.\n * This look only has to find, so it asks for no canary.\n * 2. Otherwise resend the stored bytes through `send` when that is allowed -\n * the task's normal send path, without simulation.\n * 3. Otherwise - a hash alone, or bytes past the resend age cap - nothing is\n * sent, and only the dropped rule can make the outcome final.\n *\n * Bytes that are not the stored txHash's transaction are never sent, and the\n * dropped rule never runs for them: the outcome stays unknown unless the\n * lookup by txHash finds it confirmed.\n */\nexport async function resumeFromStore(\n context: SolanaStepExecutorContext,\n action: ExecutionAction,\n options: {\n messages: ConfirmationMessages\n /** Sends the stored bytes and applies the result rules, as the first\n * run does, but never simulates: a transaction that already landed, or\n * funds it already spent, would fail the simulation falsely. */\n send: (\n stored: StoredTransactions,\n lifetimes: TransactionLifetime[]\n ) => Promise<TaskResult>\n }\n): Promise<TaskResult> {\n const { client, step } = context\n const source = readResumeSource(context, action)\n const signature =\n source.kind === 'bytes' ? source.stored.signature : source.signature\n\n const lookup = await lookupSignatureStatus(client, signature)\n if (\n lookup.kind === 'found' &&\n isConfirmedCommitment(lookup.status.confirmationStatus)\n ) {\n return recordLanded(context, action, {\n signature,\n failure: failureOf(lookup.status),\n })\n }\n\n const lifetimes =\n source.kind === 'bytes'\n ? await Promise.all(\n source.stored.transactions.map((transaction) =>\n getTransactionLifetime(transaction)\n )\n )\n : []\n\n // A `processed` status resends too: a signature executes at most once.\n if (\n source.kind === 'bytes' &&\n canResendStored(lifetimes, step.execution?.signedAt)\n ) {\n return options.send(source.stored, lifetimes)\n }\n\n // No RPC answered at all: an outage, as today. Otherwise the transaction\n // was simply not seen.\n const silent = lookup.kind === 'unknown' && !lookup.answered\n const error = confirmationError(\n silent\n ? { kind: 'rpc-unavailable', errors: lookup.errors }\n : { kind: 'not-confirmed', errors: [] },\n options.messages\n )\n if (source.kind === 'mismatch') {\n // Damaged storage: no dropped rule, so the outcome stays unknown.\n throw error\n }\n const status = await resolveUnconfirmed(context, action, {\n signature,\n error,\n expiredAtSlot: undefined,\n messages: options.messages,\n })\n return recordLanded(context, action, {\n signature,\n failure: failureOf(status),\n })\n}\n"],"mappings":";;;;;;;;AA0CA,SAAS,iBACP,SACA,QACc;CACd,IAAI,OAAO,OAAO;EAChB,MAAM,SAAS,yBAAyB,OAAO,KAAK;EACpD,IAAI,QAAQ;GACV,IAAI,OAAO,UAAU,OAAO,WAAW,OAAO,WAC5C,OAAO;IAAE,MAAM;IAAY,WAAW,OAAO;GAAoB;GAEnE,OAAO;IAAE,MAAM;IAAS;GAAO;EACjC;EAIA,wBAAwB,SAAS,MAAM;CACzC;CAEA,IAAI,OAAO,QACT,OAAO;EAAE,MAAM;EAAQ,WAAW,OAAO;CAAoB;CAM/D,MAAM,IAAI,iBACR,cAAc,uBACd,mEACF;AACF;;;;;;;;;;;;;;;;;AAkBA,eAAsB,gBACpB,SACA,QACA,SAUqB;CACrB,MAAM,EAAE,QAAQ,SAAS;CACzB,MAAM,SAAS,iBAAiB,SAAS,MAAM;CAC/C,MAAM,YACJ,OAAO,SAAS,UAAU,OAAO,OAAO,YAAY,OAAO;CAE7D,MAAM,SAAS,MAAM,sBAAsB,QAAQ,SAAS;CAC5D,IACE,OAAO,SAAS,WAChB,sBAAsB,OAAO,OAAO,kBAAkB,GAEtD,OAAO,aAAa,SAAS,QAAQ;EACnC;EACA,SAAS,UAAU,OAAO,MAAM;CAClC,CAAC;CAGH,MAAM,YACJ,OAAO,SAAS,UACZ,MAAM,QAAQ,IACZ,OAAO,OAAO,aAAa,KAAK,gBAC9B,uBAAuB,WAAW,CACpC,CACF,IACA,CAAC;CAGP,IACE,OAAO,SAAS,WAChB,gBAAgB,WAAW,KAAK,WAAW,QAAQ,GAEnD,OAAO,QAAQ,KAAK,OAAO,QAAQ,SAAS;CAK9C,MAAM,SAAS,OAAO,SAAS,aAAa,CAAC,OAAO;CACpD,MAAM,QAAQ,kBACZ,SACI;EAAE,MAAM;EAAmB,QAAQ,OAAO;CAAO,IACjD;EAAE,MAAM;EAAiB,QAAQ,CAAC;CAAE,GACxC,QAAQ,QACV;CACA,IAAI,OAAO,SAAS,YAElB,MAAM;CAER,MAAM,SAAS,MAAM,mBAAmB,SAAS,QAAQ;EACvD;EACA;EACA,eAAe,KAAA;EACf,UAAU,QAAQ;CACpB,CAAC;CACD,OAAO,aAAa,SAAS,QAAQ;EACnC;EACA,SAAS,UAAU,MAAM;CAC3B,CAAC;AACH"}
|
|
@@ -0,0 +1,107 @@
|
|
|
1
|
+
import { SolanaStepExecutorContext } from "../../types.js";
|
|
2
|
+
import { SignatureStatus } from "../../confirmation/types.js";
|
|
3
|
+
import { TransactionLifetime } from "../../utils/getTransactionLifetime.js";
|
|
4
|
+
import { RaceResult } from "../../confirmation/raceRpcs.js";
|
|
5
|
+
import { ConfirmationMessages } from "./confirmationError.js";
|
|
6
|
+
import { ExecutionAction, TaskResult } from "@lifi/sdk";
|
|
7
|
+
import { Signature } from "@solana/kit";
|
|
8
|
+
//#region src/core/tasks/transactionOutcome.d.ts
|
|
9
|
+
/** Explorer link for a signature, as both wait tasks write it. */
|
|
10
|
+
export declare function getTxLink(context: Pick<SolanaStepExecutorContext, "fromChain">, signature: string): string;
|
|
11
|
+
/**
|
|
12
|
+
* May stored bytes be sent (again)? A blockhash transaction always: the
|
|
13
|
+
* chain rejects it once the blockhash dies, and the deadline's probe tells
|
|
14
|
+
* when. Anything else - a durable nonce, a lifetime that did not decode -
|
|
15
|
+
* only inside the resend age cap, so a page load hours later cannot execute
|
|
16
|
+
* a swap on an old quote.
|
|
17
|
+
*/
|
|
18
|
+
export declare function canResendStored(lifetimes: TransactionLifetime[], signedAt: number | undefined, now?: number): boolean;
|
|
19
|
+
/**
|
|
20
|
+
* Condition (a) of the dropped rule in `resolveUnconfirmed`: the chain says
|
|
21
|
+
* the transaction can no longer land.
|
|
22
|
+
*
|
|
23
|
+
* - An `expired` verdict: the blockhash probe saw it dead.
|
|
24
|
+
* - Without a verdict, `isOldEnoughToDrop` for every lifetime. For a
|
|
25
|
+
* blockhash transaction that is the five-minute time fallback. For a
|
|
26
|
+
* durable nonce or an undecodable lifetime it is the age cap passed plus a
|
|
27
|
+
* margin: sends stop at the cap, and the three minutes after it put the
|
|
28
|
+
* lookup's current-slot head safely past any slot the transaction could
|
|
29
|
+
* still land in.
|
|
30
|
+
*
|
|
31
|
+
* An unknown signing time never holds by time.
|
|
32
|
+
*/
|
|
33
|
+
export declare function cannotLandAnymore(options: {
|
|
34
|
+
expired: boolean;
|
|
35
|
+
signedAt: number | undefined;
|
|
36
|
+
now?: number;
|
|
37
|
+
}): boolean;
|
|
38
|
+
/** Drops the stored bytes: never sent, landed, or final. */
|
|
39
|
+
export declare function clearStoredTransactions(context: SolanaStepExecutorContext, action: ExecutionAction): void;
|
|
40
|
+
/** A signature status's `err` as the failure `recordLanded` takes. */
|
|
41
|
+
export declare function failureOf(status: Pick<SignatureStatus, "err">): {
|
|
42
|
+
err: unknown;
|
|
43
|
+
} | undefined;
|
|
44
|
+
/**
|
|
45
|
+
* Result rule for a transaction the chain has: writes `txHash` and `txLink`,
|
|
46
|
+
* clears the stored bytes, then completes - or throws the final
|
|
47
|
+
* `TransactionFailed` for one that failed on chain.
|
|
48
|
+
*
|
|
49
|
+
* The hash is written for a failed transaction too: it exists on chain, and
|
|
50
|
+
* a resume that found it by lookup has no `txHash` yet.
|
|
51
|
+
*/
|
|
52
|
+
export declare function recordLanded(context: SolanaStepExecutorContext, action: ExecutionAction, options: {
|
|
53
|
+
signature: Signature;
|
|
54
|
+
failure: {
|
|
55
|
+
err: unknown;
|
|
56
|
+
} | undefined;
|
|
57
|
+
}): TaskResult;
|
|
58
|
+
/**
|
|
59
|
+
* Decides what a transaction that did not confirm is: landed after all
|
|
60
|
+
* (returns its status), dropped (throws a final `TransactionExpired`), or
|
|
61
|
+
* unknown (rethrows `error`, the error the task built for today's outcome).
|
|
62
|
+
*
|
|
63
|
+
* Dropped (see the resume rules in `transactionState.ts`) = (a)
|
|
64
|
+
* `cannotLandAnymore`, AND (b) a lookup that proves the absence - a covering
|
|
65
|
+
* RPC whose head is past the landing window answered `null` in the same
|
|
66
|
+
* response, and no RPC has the transaction - AND (c) the status API does not
|
|
67
|
+
* know the hash. The status API only vetoes: it answers 404 for landed
|
|
68
|
+
* transactions it does not index too, so a miss there proves nothing.
|
|
69
|
+
*/
|
|
70
|
+
export declare function resolveUnconfirmed(context: SolanaStepExecutorContext, action: ExecutionAction, options: {
|
|
71
|
+
signature: Signature;
|
|
72
|
+
/** What the integrator sees when the outcome stays unknown. */
|
|
73
|
+
error: unknown;
|
|
74
|
+
/** The slot of the `expired` verdict; `undefined` without one. */
|
|
75
|
+
expiredAtSlot: bigint | undefined;
|
|
76
|
+
messages: ConfirmationMessages;
|
|
77
|
+
}): Promise<SignatureStatus>;
|
|
78
|
+
/**
|
|
79
|
+
* The send-and-settle tail both wait tasks share: runs `send`, then applies
|
|
80
|
+
* the result rules to what it reports.
|
|
81
|
+
*
|
|
82
|
+
* - A confirmation goes to `recordLanded`, with `confirmedFailure` reading
|
|
83
|
+
* its on-chain failure.
|
|
84
|
+
* - Every other result - `rpc-unavailable` included - goes to
|
|
85
|
+
* `resolveUnconfirmed`. Only an `expired` verdict passes its slot: the
|
|
86
|
+
* dropped check reads any defined slot as a verdict.
|
|
87
|
+
* - A rejection comes before the first send of this run. On the first run
|
|
88
|
+
* nothing ever left the SDK, so the bytes are cleared and the error is
|
|
89
|
+
* rethrown: "Try again" signs again. On a resume an earlier run may have
|
|
90
|
+
* sent the same bytes: they stay, and only the chain can make the outcome
|
|
91
|
+
* final.
|
|
92
|
+
*/
|
|
93
|
+
export declare function sendAndSettle<T>(context: SolanaStepExecutorContext, action: ExecutionAction, options: {
|
|
94
|
+
signature: Signature;
|
|
95
|
+
/** Sends and races the confirmation. Rejects only before its first
|
|
96
|
+
* send; the race itself never rejects. */
|
|
97
|
+
send: () => Promise<RaceResult<T>>;
|
|
98
|
+
/** The on-chain failure of a confirmed value. */
|
|
99
|
+
confirmedFailure: (value: T) => {
|
|
100
|
+
err: unknown;
|
|
101
|
+
} | undefined;
|
|
102
|
+
/** An earlier run may already have sent these bytes. */
|
|
103
|
+
resuming: boolean;
|
|
104
|
+
messages: ConfirmationMessages;
|
|
105
|
+
}): Promise<TaskResult>;
|
|
106
|
+
//#endregion
|
|
107
|
+
//# sourceMappingURL=transactionOutcome.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"transactionOutcome.d.ts","names":[],"sources":["../../../../src/core/tasks/transactionOutcome.ts"],"mappings":";;;;;;;;;wBA0BgB,UACd,SAAS,KAAK,yCACd;;;;;;;;wBAYc,gBACd,WAAW,uBACX,8BACA;;;;;;;;;;;;;;;wBAsBc,kBAAkB;EAChC;EACA;EACA;;;wBAMc,wBACd,SAAS,2BACT,QAAQ;;wBAQM,UACd,QAAQ,KAAK;EACV;;;;;;;;;;wBAYW,aACd,SAAS,2BACT,QAAQ,iBACR;EAAW,WAAW;EAAW;IAAW;;IAC3C;;;;;;;;;;;;;wBAuCmB,mBACpB,SAAS,2BACT,QAAQ,iBACR;EACE,WAAW;;EAEX;;EAEA;EACA,UAAU;IAEX,QAAQ;;;;;;;;;;;;;;;;wBA8DW,cAAc,GAClC,SAAS,2BACT,QAAQ,iBACR;EACE,WAAW;;;EAGX,YAAY,QAAQ,WAAW;;EAE/B,mBAAmB,OAAO;IAAQ;;;EAElC;EACA,UAAU;IAEX,QAAQ"}
|
|
@@ -0,0 +1,150 @@
|
|
|
1
|
+
import { isConfirmedCommitment } from "../../confirmation/types.js";
|
|
2
|
+
import { lookupSignatureStatus } from "../../actions/lookupSignatureStatus.js";
|
|
3
|
+
import { confirmationError } from "./confirmationError.js";
|
|
4
|
+
import { SolanaTransactionDetailsError } from "../../utils/solanaErrorCause.js";
|
|
5
|
+
import { CLOCK_SKEW_MARGIN_MS, LiFiErrorCode, TransactionError, isKnownToStatusApi, isOldEnoughToDrop, isResendAllowed } from "@lifi/sdk";
|
|
6
|
+
//#region src/core/tasks/transactionOutcome.ts
|
|
7
|
+
/** Explorer link for a signature, as both wait tasks write it. */
|
|
8
|
+
function getTxLink(context, signature) {
|
|
9
|
+
return `${context.fromChain.metamask.blockExplorerUrls[0]}tx/${signature}`;
|
|
10
|
+
}
|
|
11
|
+
/**
|
|
12
|
+
* May stored bytes be sent (again)? A blockhash transaction always: the
|
|
13
|
+
* chain rejects it once the blockhash dies, and the deadline's probe tells
|
|
14
|
+
* when. Anything else - a durable nonce, a lifetime that did not decode -
|
|
15
|
+
* only inside the resend age cap, so a page load hours later cannot execute
|
|
16
|
+
* a swap on an old quote.
|
|
17
|
+
*/
|
|
18
|
+
function canResendStored(lifetimes, signedAt, now) {
|
|
19
|
+
return lifetimes.length > 0 && lifetimes.every((lifetime) => lifetime.kind === "blockhash") || isResendAllowed(signedAt, now);
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* Condition (a) of the dropped rule in `resolveUnconfirmed`: the chain says
|
|
23
|
+
* the transaction can no longer land.
|
|
24
|
+
*
|
|
25
|
+
* - An `expired` verdict: the blockhash probe saw it dead.
|
|
26
|
+
* - Without a verdict, `isOldEnoughToDrop` for every lifetime. For a
|
|
27
|
+
* blockhash transaction that is the five-minute time fallback. For a
|
|
28
|
+
* durable nonce or an undecodable lifetime it is the age cap passed plus a
|
|
29
|
+
* margin: sends stop at the cap, and the three minutes after it put the
|
|
30
|
+
* lookup's current-slot head safely past any slot the transaction could
|
|
31
|
+
* still land in.
|
|
32
|
+
*
|
|
33
|
+
* An unknown signing time never holds by time.
|
|
34
|
+
*/
|
|
35
|
+
function cannotLandAnymore(options) {
|
|
36
|
+
return options.expired || isOldEnoughToDrop(options.signedAt, options.now);
|
|
37
|
+
}
|
|
38
|
+
/** Drops the stored bytes: never sent, landed, or final. */
|
|
39
|
+
function clearStoredTransactions(context, action) {
|
|
40
|
+
context.statusManager.updateAction(context.step, action.type, "PENDING", { txHex: void 0 });
|
|
41
|
+
}
|
|
42
|
+
/** A signature status's `err` as the failure `recordLanded` takes. */
|
|
43
|
+
function failureOf(status) {
|
|
44
|
+
return status.err ? { err: status.err } : void 0;
|
|
45
|
+
}
|
|
46
|
+
/**
|
|
47
|
+
* Result rule for a transaction the chain has: writes `txHash` and `txLink`,
|
|
48
|
+
* clears the stored bytes, then completes - or throws the final
|
|
49
|
+
* `TransactionFailed` for one that failed on chain.
|
|
50
|
+
*
|
|
51
|
+
* The hash is written for a failed transaction too: it exists on chain, and
|
|
52
|
+
* a resume that found it by lookup has no `txHash` yet.
|
|
53
|
+
*/
|
|
54
|
+
function recordLanded(context, action, options) {
|
|
55
|
+
const { step, statusManager, isBridgeExecution } = context;
|
|
56
|
+
const { signature, failure } = options;
|
|
57
|
+
statusManager.updateAction(step, action.type, "PENDING", {
|
|
58
|
+
txHash: signature,
|
|
59
|
+
txLink: getTxLink(context, signature),
|
|
60
|
+
txHex: void 0
|
|
61
|
+
});
|
|
62
|
+
if (failure) {
|
|
63
|
+
const cause = new SolanaTransactionDetailsError(failure.err);
|
|
64
|
+
throw new TransactionError(LiFiErrorCode.TransactionFailed, `Transaction failed: ${cause.message}`, cause, { final: true });
|
|
65
|
+
}
|
|
66
|
+
if (isBridgeExecution) statusManager.updateAction(step, action.type, "DONE");
|
|
67
|
+
return { status: "COMPLETED" };
|
|
68
|
+
}
|
|
69
|
+
/**
|
|
70
|
+
* Decides what a transaction that did not confirm is: landed after all
|
|
71
|
+
* (returns its status), dropped (throws a final `TransactionExpired`), or
|
|
72
|
+
* unknown (rethrows `error`, the error the task built for today's outcome).
|
|
73
|
+
*
|
|
74
|
+
* Dropped (see the resume rules in `transactionState.ts`) = (a)
|
|
75
|
+
* `cannotLandAnymore`, AND (b) a lookup that proves the absence - a covering
|
|
76
|
+
* RPC whose head is past the landing window answered `null` in the same
|
|
77
|
+
* response, and no RPC has the transaction - AND (c) the status API does not
|
|
78
|
+
* know the hash. The status API only vetoes: it answers 404 for landed
|
|
79
|
+
* transactions it does not index too, so a miss there proves nothing.
|
|
80
|
+
*/
|
|
81
|
+
async function resolveUnconfirmed(context, action, options) {
|
|
82
|
+
const { client, step } = context;
|
|
83
|
+
const { signature, error, expiredAtSlot } = options;
|
|
84
|
+
const signedAt = step.execution?.signedAt;
|
|
85
|
+
if (!cannotLandAnymore({
|
|
86
|
+
expired: expiredAtSlot !== void 0,
|
|
87
|
+
signedAt
|
|
88
|
+
})) throw error;
|
|
89
|
+
if (signedAt === void 0) throw error;
|
|
90
|
+
const lookup = await lookupSignatureStatus(client, signature, {
|
|
91
|
+
anchor: signedAt - CLOCK_SKEW_MARGIN_MS,
|
|
92
|
+
expiredAtSlot
|
|
93
|
+
});
|
|
94
|
+
if (lookup.kind === "found" && isConfirmedCommitment(lookup.status.confirmationStatus)) return lookup.status;
|
|
95
|
+
if (lookup.kind !== "not-found") throw error;
|
|
96
|
+
if (await isKnownToStatusApi(client, step, signature)) throw error;
|
|
97
|
+
clearStoredTransactions(context, action);
|
|
98
|
+
throw new TransactionError(LiFiErrorCode.TransactionExpired, options.messages.notConfirmed, error instanceof Error ? error : void 0, { final: true });
|
|
99
|
+
}
|
|
100
|
+
/**
|
|
101
|
+
* The send-and-settle tail both wait tasks share: runs `send`, then applies
|
|
102
|
+
* the result rules to what it reports.
|
|
103
|
+
*
|
|
104
|
+
* - A confirmation goes to `recordLanded`, with `confirmedFailure` reading
|
|
105
|
+
* its on-chain failure.
|
|
106
|
+
* - Every other result - `rpc-unavailable` included - goes to
|
|
107
|
+
* `resolveUnconfirmed`. Only an `expired` verdict passes its slot: the
|
|
108
|
+
* dropped check reads any defined slot as a verdict.
|
|
109
|
+
* - A rejection comes before the first send of this run. On the first run
|
|
110
|
+
* nothing ever left the SDK, so the bytes are cleared and the error is
|
|
111
|
+
* rethrown: "Try again" signs again. On a resume an earlier run may have
|
|
112
|
+
* sent the same bytes: they stay, and only the chain can make the outcome
|
|
113
|
+
* final.
|
|
114
|
+
*/
|
|
115
|
+
async function sendAndSettle(context, action, options) {
|
|
116
|
+
const { signature, messages } = options;
|
|
117
|
+
/** `resolveUnconfirmed` throws for an unknown or dropped outcome, so only
|
|
118
|
+
* a confirmed status reaches `recordLanded`. */
|
|
119
|
+
const settleUnconfirmed = async (error, expiredAtSlot) => {
|
|
120
|
+
const status = await resolveUnconfirmed(context, action, {
|
|
121
|
+
signature,
|
|
122
|
+
error,
|
|
123
|
+
expiredAtSlot,
|
|
124
|
+
messages
|
|
125
|
+
});
|
|
126
|
+
return recordLanded(context, action, {
|
|
127
|
+
signature,
|
|
128
|
+
failure: failureOf(status)
|
|
129
|
+
});
|
|
130
|
+
};
|
|
131
|
+
let result;
|
|
132
|
+
try {
|
|
133
|
+
result = await options.send();
|
|
134
|
+
} catch (error) {
|
|
135
|
+
if (!options.resuming) {
|
|
136
|
+
clearStoredTransactions(context, action);
|
|
137
|
+
throw error;
|
|
138
|
+
}
|
|
139
|
+
return settleUnconfirmed(error, void 0);
|
|
140
|
+
}
|
|
141
|
+
if (result.kind === "confirmed") return recordLanded(context, action, {
|
|
142
|
+
signature,
|
|
143
|
+
failure: options.confirmedFailure(result.value)
|
|
144
|
+
});
|
|
145
|
+
return settleUnconfirmed(confirmationError(result, messages), result.kind === "expired" ? result.slot : void 0);
|
|
146
|
+
}
|
|
147
|
+
//#endregion
|
|
148
|
+
export { canResendStored, cannotLandAnymore, clearStoredTransactions, failureOf, getTxLink, recordLanded, resolveUnconfirmed, sendAndSettle };
|
|
149
|
+
|
|
150
|
+
//# sourceMappingURL=transactionOutcome.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"transactionOutcome.js","names":[],"sources":["../../../../src/core/tasks/transactionOutcome.ts"],"sourcesContent":["import {\n CLOCK_SKEW_MARGIN_MS,\n type ExecutionAction,\n isKnownToStatusApi,\n isOldEnoughToDrop,\n isResendAllowed,\n LiFiErrorCode,\n type TaskResult,\n TransactionError,\n} from '@lifi/sdk'\nimport type { Signature } from '@solana/kit'\nimport { lookupSignatureStatus } from '../../actions/lookupSignatureStatus.js'\nimport type { RaceResult } from '../../confirmation/raceRpcs.js'\nimport {\n isConfirmedCommitment,\n type SignatureStatus,\n} from '../../confirmation/types.js'\nimport type { SolanaStepExecutorContext } from '../../types.js'\nimport type { TransactionLifetime } from '../../utils/getTransactionLifetime.js'\nimport { SolanaTransactionDetailsError } from '../../utils/solanaErrorCause.js'\nimport {\n type ConfirmationMessages,\n confirmationError,\n} from './confirmationError.js'\n\n/** Explorer link for a signature, as both wait tasks write it. */\nexport function getTxLink(\n context: Pick<SolanaStepExecutorContext, 'fromChain'>,\n signature: string\n): string {\n return `${context.fromChain.metamask.blockExplorerUrls[0]}tx/${signature}`\n}\n\n/**\n * May stored bytes be sent (again)? A blockhash transaction always: the\n * chain rejects it once the blockhash dies, and the deadline's probe tells\n * when. Anything else - a durable nonce, a lifetime that did not decode -\n * only inside the resend age cap, so a page load hours later cannot execute\n * a swap on an old quote.\n */\nexport function canResendStored(\n lifetimes: TransactionLifetime[],\n signedAt: number | undefined,\n now?: number\n): boolean {\n const expiresOnItsOwn =\n lifetimes.length > 0 &&\n lifetimes.every((lifetime) => lifetime.kind === 'blockhash')\n return expiresOnItsOwn || isResendAllowed(signedAt, now)\n}\n\n/**\n * Condition (a) of the dropped rule in `resolveUnconfirmed`: the chain says\n * the transaction can no longer land.\n *\n * - An `expired` verdict: the blockhash probe saw it dead.\n * - Without a verdict, `isOldEnoughToDrop` for every lifetime. For a\n * blockhash transaction that is the five-minute time fallback. For a\n * durable nonce or an undecodable lifetime it is the age cap passed plus a\n * margin: sends stop at the cap, and the three minutes after it put the\n * lookup's current-slot head safely past any slot the transaction could\n * still land in.\n *\n * An unknown signing time never holds by time.\n */\nexport function cannotLandAnymore(options: {\n expired: boolean\n signedAt: number | undefined\n now?: number\n}): boolean {\n return options.expired || isOldEnoughToDrop(options.signedAt, options.now)\n}\n\n/** Drops the stored bytes: never sent, landed, or final. */\nexport function clearStoredTransactions(\n context: SolanaStepExecutorContext,\n action: ExecutionAction\n): void {\n context.statusManager.updateAction(context.step, action.type, 'PENDING', {\n txHex: undefined,\n })\n}\n\n/** A signature status's `err` as the failure `recordLanded` takes. */\nexport function failureOf(\n status: Pick<SignatureStatus, 'err'>\n): { err: unknown } | undefined {\n return status.err ? { err: status.err } : undefined\n}\n\n/**\n * Result rule for a transaction the chain has: writes `txHash` and `txLink`,\n * clears the stored bytes, then completes - or throws the final\n * `TransactionFailed` for one that failed on chain.\n *\n * The hash is written for a failed transaction too: it exists on chain, and\n * a resume that found it by lookup has no `txHash` yet.\n */\nexport function recordLanded(\n context: SolanaStepExecutorContext,\n action: ExecutionAction,\n options: { signature: Signature; failure: { err: unknown } | undefined }\n): TaskResult {\n const { step, statusManager, isBridgeExecution } = context\n const { signature, failure } = options\n\n statusManager.updateAction(step, action.type, 'PENDING', {\n txHash: signature,\n txLink: getTxLink(context, signature),\n txHex: undefined,\n })\n\n if (failure) {\n const cause = new SolanaTransactionDetailsError(failure.err)\n throw new TransactionError(\n LiFiErrorCode.TransactionFailed,\n `Transaction failed: ${cause.message}`,\n cause,\n { final: true }\n )\n }\n\n if (isBridgeExecution) {\n statusManager.updateAction(step, action.type, 'DONE')\n }\n\n return { status: 'COMPLETED' }\n}\n\n/**\n * Decides what a transaction that did not confirm is: landed after all\n * (returns its status), dropped (throws a final `TransactionExpired`), or\n * unknown (rethrows `error`, the error the task built for today's outcome).\n *\n * Dropped (see the resume rules in `transactionState.ts`) = (a)\n * `cannotLandAnymore`, AND (b) a lookup that proves the absence - a covering\n * RPC whose head is past the landing window answered `null` in the same\n * response, and no RPC has the transaction - AND (c) the status API does not\n * know the hash. The status API only vetoes: it answers 404 for landed\n * transactions it does not index too, so a miss there proves nothing.\n */\nexport async function resolveUnconfirmed(\n context: SolanaStepExecutorContext,\n action: ExecutionAction,\n options: {\n signature: Signature\n /** What the integrator sees when the outcome stays unknown. */\n error: unknown\n /** The slot of the `expired` verdict; `undefined` without one. */\n expiredAtSlot: bigint | undefined\n messages: ConfirmationMessages\n }\n): Promise<SignatureStatus> {\n const { client, step } = context\n const { signature, error, expiredAtSlot } = options\n const signedAt = step.execution?.signedAt\n\n // (a) The local check runs first, so a young transaction costs no request.\n if (!cannotLandAnymore({ expired: expiredAtSlot !== undefined, signedAt })) {\n throw error\n }\n // Without a signing time there is no anchor, so no canary can prove that a\n // node's history covers the transaction.\n if (signedAt === undefined) {\n throw error\n }\n\n // (b) Absence, proven by the same response that proves coverage and head.\n // Every other lookup result - also `unknown` with `answered: false`, an\n // outage - keeps the outcome unknown.\n const lookup = await lookupSignatureStatus(client, signature, {\n anchor: signedAt - CLOCK_SKEW_MARGIN_MS,\n expiredAtSlot,\n })\n if (\n lookup.kind === 'found' &&\n isConfirmedCommitment(lookup.status.confirmationStatus)\n ) {\n return lookup.status\n }\n if (lookup.kind !== 'not-found') {\n throw error\n }\n\n // (c) The veto.\n if (await isKnownToStatusApi(client, step, signature)) {\n throw error\n }\n\n clearStoredTransactions(context, action)\n // Today's expiry code and text: only the marker is new.\n throw new TransactionError(\n LiFiErrorCode.TransactionExpired,\n options.messages.notConfirmed,\n error instanceof Error ? error : undefined,\n { final: true }\n )\n}\n\n/**\n * The send-and-settle tail both wait tasks share: runs `send`, then applies\n * the result rules to what it reports.\n *\n * - A confirmation goes to `recordLanded`, with `confirmedFailure` reading\n * its on-chain failure.\n * - Every other result - `rpc-unavailable` included - goes to\n * `resolveUnconfirmed`. Only an `expired` verdict passes its slot: the\n * dropped check reads any defined slot as a verdict.\n * - A rejection comes before the first send of this run. On the first run\n * nothing ever left the SDK, so the bytes are cleared and the error is\n * rethrown: \"Try again\" signs again. On a resume an earlier run may have\n * sent the same bytes: they stay, and only the chain can make the outcome\n * final.\n */\nexport async function sendAndSettle<T>(\n context: SolanaStepExecutorContext,\n action: ExecutionAction,\n options: {\n signature: Signature\n /** Sends and races the confirmation. Rejects only before its first\n * send; the race itself never rejects. */\n send: () => Promise<RaceResult<T>>\n /** The on-chain failure of a confirmed value. */\n confirmedFailure: (value: T) => { err: unknown } | undefined\n /** An earlier run may already have sent these bytes. */\n resuming: boolean\n messages: ConfirmationMessages\n }\n): Promise<TaskResult> {\n const { signature, messages } = options\n\n /** `resolveUnconfirmed` throws for an unknown or dropped outcome, so only\n * a confirmed status reaches `recordLanded`. */\n const settleUnconfirmed = async (\n error: unknown,\n expiredAtSlot: bigint | undefined\n ): Promise<TaskResult> => {\n const status = await resolveUnconfirmed(context, action, {\n signature,\n error,\n expiredAtSlot,\n messages,\n })\n return recordLanded(context, action, {\n signature,\n failure: failureOf(status),\n })\n }\n\n let result: RaceResult<T>\n try {\n result = await options.send()\n } catch (error) {\n if (!options.resuming) {\n clearStoredTransactions(context, action)\n throw error\n }\n return settleUnconfirmed(error, undefined)\n }\n\n if (result.kind === 'confirmed') {\n return recordLanded(context, action, {\n signature,\n failure: options.confirmedFailure(result.value),\n })\n }\n\n return settleUnconfirmed(\n confirmationError(result, messages),\n // The head a covering RPC has to reach before its `null` counts.\n result.kind === 'expired' ? result.slot : undefined\n )\n}\n"],"mappings":";;;;;;;AA0BA,SAAgB,UACd,SACA,WACQ;CACR,OAAO,GAAG,QAAQ,UAAU,SAAS,kBAAkB,GAAG,KAAK;AACjE;;;;;;;;AASA,SAAgB,gBACd,WACA,UACA,KACS;CAIT,OAFE,UAAU,SAAS,KACnB,UAAU,OAAO,aAAa,SAAS,SAAS,WAAW,KACnC,gBAAgB,UAAU,GAAG;AACzD;;;;;;;;;;;;;;;AAgBA,SAAgB,kBAAkB,SAItB;CACV,OAAO,QAAQ,WAAW,kBAAkB,QAAQ,UAAU,QAAQ,GAAG;AAC3E;;AAGA,SAAgB,wBACd,SACA,QACM;CACN,QAAQ,cAAc,aAAa,QAAQ,MAAM,OAAO,MAAM,WAAW,EACvE,OAAO,KAAA,EACT,CAAC;AACH;;AAGA,SAAgB,UACd,QAC8B;CAC9B,OAAO,OAAO,MAAM,EAAE,KAAK,OAAO,IAAI,IAAI,KAAA;AAC5C;;;;;;;;;AAUA,SAAgB,aACd,SACA,QACA,SACY;CACZ,MAAM,EAAE,MAAM,eAAe,sBAAsB;CACnD,MAAM,EAAE,WAAW,YAAY;CAE/B,cAAc,aAAa,MAAM,OAAO,MAAM,WAAW;EACvD,QAAQ;EACR,QAAQ,UAAU,SAAS,SAAS;EACpC,OAAO,KAAA;CACT,CAAC;CAED,IAAI,SAAS;EACX,MAAM,QAAQ,IAAI,8BAA8B,QAAQ,GAAG;EAC3D,MAAM,IAAI,iBACR,cAAc,mBACd,uBAAuB,MAAM,WAC7B,OACA,EAAE,OAAO,KAAK,CAChB;CACF;CAEA,IAAI,mBACF,cAAc,aAAa,MAAM,OAAO,MAAM,MAAM;CAGtD,OAAO,EAAE,QAAQ,YAAY;AAC/B;;;;;;;;;;;;;AAcA,eAAsB,mBACpB,SACA,QACA,SAQ0B;CAC1B,MAAM,EAAE,QAAQ,SAAS;CACzB,MAAM,EAAE,WAAW,OAAO,kBAAkB;CAC5C,MAAM,WAAW,KAAK,WAAW;CAGjC,IAAI,CAAC,kBAAkB;EAAE,SAAS,kBAAkB,KAAA;EAAW;CAAS,CAAC,GACvE,MAAM;CAIR,IAAI,aAAa,KAAA,GACf,MAAM;CAMR,MAAM,SAAS,MAAM,sBAAsB,QAAQ,WAAW;EAC5D,QAAQ,WAAW;EACnB;CACF,CAAC;CACD,IACE,OAAO,SAAS,WAChB,sBAAsB,OAAO,OAAO,kBAAkB,GAEtD,OAAO,OAAO;CAEhB,IAAI,OAAO,SAAS,aAClB,MAAM;CAIR,IAAI,MAAM,mBAAmB,QAAQ,MAAM,SAAS,GAClD,MAAM;CAGR,wBAAwB,SAAS,MAAM;CAEvC,MAAM,IAAI,iBACR,cAAc,oBACd,QAAQ,SAAS,cACjB,iBAAiB,QAAQ,QAAQ,KAAA,GACjC,EAAE,OAAO,KAAK,CAChB;AACF;;;;;;;;;;;;;;;;AAiBA,eAAsB,cACpB,SACA,QACA,SAWqB;CACrB,MAAM,EAAE,WAAW,aAAa;;;CAIhC,MAAM,oBAAoB,OACxB,OACA,kBACwB;EACxB,MAAM,SAAS,MAAM,mBAAmB,SAAS,QAAQ;GACvD;GACA;GACA;GACA;EACF,CAAC;EACD,OAAO,aAAa,SAAS,QAAQ;GACnC;GACA,SAAS,UAAU,MAAM;EAC3B,CAAC;CACH;CAEA,IAAI;CACJ,IAAI;EACF,SAAS,MAAM,QAAQ,KAAK;CAC9B,SAAS,OAAO;EACd,IAAI,CAAC,QAAQ,UAAU;GACrB,wBAAwB,SAAS,MAAM;GACvC,MAAM;EACR;EACA,OAAO,kBAAkB,OAAO,KAAA,CAAS;CAC3C;CAEA,IAAI,OAAO,SAAS,aAClB,OAAO,aAAa,SAAS,QAAQ;EACnC;EACA,SAAS,QAAQ,iBAAiB,OAAO,KAAK;CAChD,CAAC;CAGH,OAAO,kBACL,kBAAkB,QAAQ,QAAQ,GAElC,OAAO,SAAS,YAAY,OAAO,OAAO,KAAA,CAC5C;AACF"}
|
package/dist/esm/types.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { SDKProvider, StepExecutorContext, StepExecutorOptions } from "@lifi/sdk";
|
|
1
|
+
import { LiFiStepExtended, SDKProvider, StepExecutorContext, StepExecutorOptions } from "@lifi/sdk";
|
|
2
2
|
import { Transaction } from "@solana/kit";
|
|
3
3
|
import { Wallet, WalletAccount } from "@wallet-standard/base";
|
|
4
4
|
//#region src/types.d.ts
|
|
@@ -7,16 +7,27 @@ export interface SolanaProviderOptions {
|
|
|
7
7
|
skipSimulation?: boolean;
|
|
8
8
|
}
|
|
9
9
|
export interface SolanaTaskContext {
|
|
10
|
+
/**
|
|
11
|
+
* Set by the sign task. Absent on a resume: the wait tasks then read the
|
|
12
|
+
* signed bytes from the action's `txHex`.
|
|
13
|
+
*/
|
|
10
14
|
signedTransactions?: Transaction[];
|
|
11
15
|
/**
|
|
12
16
|
* Whether the backend returned a Jito bundle (array `transactionRequest.data`)
|
|
13
17
|
* that must be submitted via `sendBundle` instead of `sendTransaction`.
|
|
18
|
+
* Absent on a resume: a leading `[` in `txHex` marks a bundle then.
|
|
14
19
|
*/
|
|
15
20
|
isBundleExecution?: boolean;
|
|
16
21
|
}
|
|
17
22
|
export interface SolanaStepExecutorContext extends StepExecutorContext, SolanaTaskContext {
|
|
18
23
|
wallet: Wallet;
|
|
19
|
-
|
|
24
|
+
/**
|
|
25
|
+
* Resolves the account that requested the quote. Only the sign task calls
|
|
26
|
+
* it, so a resume that only waits does not need the wallet to have
|
|
27
|
+
* reconnected. Throws `WalletChangedDuringExecution` when the account is
|
|
28
|
+
* gone.
|
|
29
|
+
*/
|
|
30
|
+
getWalletAccount: (step: LiFiStepExtended) => WalletAccount;
|
|
20
31
|
skipSimulation: boolean;
|
|
21
32
|
}
|
|
22
33
|
export interface SolanaSDKProvider extends SDKProvider {
|
package/dist/esm/types.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.ts","names":[],"sources":["../../src/types.ts"],"mappings":";;;;
|
|
1
|
+
{"version":3,"file":"types.d.ts","names":[],"sources":["../../src/types.ts"],"mappings":";;;;iBAUiB;EACf,kBAAkB,QAAQ;EAC1B;;iBAGe;;;;;EAKf,qBAAqB;;;;;;EAMrB;;iBAGe,kCACP,qBACN;EACF,QAAQ;;;;;;;EAOR,mBAAmB,MAAM,qBAAqB;EAC9C;;iBAGe,0BAA0B;EACzC,WAAW,SAAS;;wBAGN,iBACd,UAAU,cACT,YAAY;iBAIE,kCAAkC;EACjD,QAAQ;EACR"}
|