@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.
Files changed (133) hide show
  1. package/CHANGELOG.md +14 -0
  2. package/README.md +9 -0
  3. package/dist/cjs/actions/lookupSignatureStatus.d.ts +66 -0
  4. package/dist/cjs/actions/lookupSignatureStatus.js +258 -0
  5. package/dist/cjs/actions/lookupSignatureStatus.js.map +1 -0
  6. package/dist/cjs/actions/sendAndConfirmTransaction.d.ts +7 -0
  7. package/dist/cjs/actions/sendAndConfirmTransaction.js +1 -0
  8. package/dist/cjs/actions/sendAndConfirmTransaction.js.map +1 -1
  9. package/dist/cjs/confirmation/confirmBundle.d.ts +1 -1
  10. package/dist/cjs/confirmation/confirmSignature.d.ts +1 -1
  11. package/dist/cjs/confirmation/createConfirmationDeadline.d.ts +6 -0
  12. package/dist/cjs/confirmation/createConfirmationDeadline.js +24 -8
  13. package/dist/cjs/confirmation/createConfirmationDeadline.js.map +1 -1
  14. package/dist/cjs/confirmation/pollUntilDeadline.js +9 -1
  15. package/dist/cjs/confirmation/pollUntilDeadline.js.map +1 -1
  16. package/dist/cjs/confirmation/raceRpcs.d.ts +8 -0
  17. package/dist/cjs/confirmation/raceRpcs.js +9 -1
  18. package/dist/cjs/confirmation/raceRpcs.js.map +1 -1
  19. package/dist/cjs/confirmation/types.d.ts +3 -0
  20. package/dist/cjs/confirmation/types.js.map +1 -1
  21. package/dist/cjs/core/SolanaStepExecutor.js +4 -5
  22. package/dist/cjs/core/SolanaStepExecutor.js.map +1 -1
  23. package/dist/cjs/core/tasks/SolanaJitoWaitForTransactionTask.js +69 -33
  24. package/dist/cjs/core/tasks/SolanaJitoWaitForTransactionTask.js.map +1 -1
  25. package/dist/cjs/core/tasks/SolanaSignAndExecuteTask.js +13 -5
  26. package/dist/cjs/core/tasks/SolanaSignAndExecuteTask.js.map +1 -1
  27. package/dist/cjs/core/tasks/SolanaStandardWaitForTransactionTask.js +71 -38
  28. package/dist/cjs/core/tasks/SolanaStandardWaitForTransactionTask.js.map +1 -1
  29. package/dist/cjs/core/tasks/SolanaWaitForTransactionTask.js +13 -1
  30. package/dist/cjs/core/tasks/SolanaWaitForTransactionTask.js.map +1 -1
  31. package/dist/cjs/core/tasks/confirmationError.d.ts +29 -0
  32. package/dist/cjs/core/tasks/confirmationError.js +26 -0
  33. package/dist/cjs/core/tasks/confirmationError.js.map +1 -0
  34. package/dist/cjs/core/tasks/resumeFromStore.d.ts +31 -0
  35. package/dist/cjs/core/tasks/resumeFromStore.js +81 -0
  36. package/dist/cjs/core/tasks/resumeFromStore.js.map +1 -0
  37. package/dist/cjs/core/tasks/transactionOutcome.d.ts +107 -0
  38. package/dist/cjs/core/tasks/transactionOutcome.js +158 -0
  39. package/dist/cjs/core/tasks/transactionOutcome.js.map +1 -0
  40. package/dist/cjs/types.d.ts +13 -2
  41. package/dist/cjs/types.js.map +1 -1
  42. package/dist/cjs/utils/storedTransactions.d.ts +36 -0
  43. package/dist/cjs/utils/storedTransactions.js +57 -0
  44. package/dist/cjs/utils/storedTransactions.js.map +1 -0
  45. package/dist/cjs/version.d.ts +1 -1
  46. package/dist/cjs/version.js +1 -1
  47. package/dist/cjs/version.js.map +1 -1
  48. package/dist/esm/actions/lookupSignatureStatus.d.ts +66 -0
  49. package/dist/esm/actions/lookupSignatureStatus.d.ts.map +1 -0
  50. package/dist/esm/actions/lookupSignatureStatus.js +252 -0
  51. package/dist/esm/actions/lookupSignatureStatus.js.map +1 -0
  52. package/dist/esm/actions/sendAndConfirmTransaction.d.ts +7 -0
  53. package/dist/esm/actions/sendAndConfirmTransaction.d.ts.map +1 -1
  54. package/dist/esm/actions/sendAndConfirmTransaction.js +1 -0
  55. package/dist/esm/actions/sendAndConfirmTransaction.js.map +1 -1
  56. package/dist/esm/confirmation/confirmBundle.d.ts +1 -1
  57. package/dist/esm/confirmation/confirmSignature.d.ts +1 -1
  58. package/dist/esm/confirmation/createConfirmationDeadline.d.ts +6 -0
  59. package/dist/esm/confirmation/createConfirmationDeadline.d.ts.map +1 -1
  60. package/dist/esm/confirmation/createConfirmationDeadline.js +24 -8
  61. package/dist/esm/confirmation/createConfirmationDeadline.js.map +1 -1
  62. package/dist/esm/confirmation/pollUntilDeadline.js +9 -1
  63. package/dist/esm/confirmation/pollUntilDeadline.js.map +1 -1
  64. package/dist/esm/confirmation/raceRpcs.d.ts +8 -0
  65. package/dist/esm/confirmation/raceRpcs.d.ts.map +1 -1
  66. package/dist/esm/confirmation/raceRpcs.js +9 -1
  67. package/dist/esm/confirmation/raceRpcs.js.map +1 -1
  68. package/dist/esm/confirmation/types.d.ts +3 -0
  69. package/dist/esm/confirmation/types.d.ts.map +1 -1
  70. package/dist/esm/confirmation/types.js.map +1 -1
  71. package/dist/esm/core/SolanaStepExecutor.d.ts.map +1 -1
  72. package/dist/esm/core/SolanaStepExecutor.js +5 -6
  73. package/dist/esm/core/SolanaStepExecutor.js.map +1 -1
  74. package/dist/esm/core/tasks/SolanaJitoWaitForTransactionTask.d.ts.map +1 -1
  75. package/dist/esm/core/tasks/SolanaJitoWaitForTransactionTask.js +69 -33
  76. package/dist/esm/core/tasks/SolanaJitoWaitForTransactionTask.js.map +1 -1
  77. package/dist/esm/core/tasks/SolanaSignAndExecuteTask.d.ts.map +1 -1
  78. package/dist/esm/core/tasks/SolanaSignAndExecuteTask.js +14 -6
  79. package/dist/esm/core/tasks/SolanaSignAndExecuteTask.js.map +1 -1
  80. package/dist/esm/core/tasks/SolanaStandardWaitForTransactionTask.d.ts.map +1 -1
  81. package/dist/esm/core/tasks/SolanaStandardWaitForTransactionTask.js +71 -38
  82. package/dist/esm/core/tasks/SolanaStandardWaitForTransactionTask.js.map +1 -1
  83. package/dist/esm/core/tasks/SolanaWaitForTransactionTask.d.ts.map +1 -1
  84. package/dist/esm/core/tasks/SolanaWaitForTransactionTask.js +13 -1
  85. package/dist/esm/core/tasks/SolanaWaitForTransactionTask.js.map +1 -1
  86. package/dist/esm/core/tasks/confirmationError.d.ts +29 -0
  87. package/dist/esm/core/tasks/confirmationError.d.ts.map +1 -0
  88. package/dist/esm/core/tasks/confirmationError.js +25 -0
  89. package/dist/esm/core/tasks/confirmationError.js.map +1 -0
  90. package/dist/esm/core/tasks/resumeFromStore.d.ts +31 -0
  91. package/dist/esm/core/tasks/resumeFromStore.d.ts.map +1 -0
  92. package/dist/esm/core/tasks/resumeFromStore.js +80 -0
  93. package/dist/esm/core/tasks/resumeFromStore.js.map +1 -0
  94. package/dist/esm/core/tasks/transactionOutcome.d.ts +107 -0
  95. package/dist/esm/core/tasks/transactionOutcome.d.ts.map +1 -0
  96. package/dist/esm/core/tasks/transactionOutcome.js +150 -0
  97. package/dist/esm/core/tasks/transactionOutcome.js.map +1 -0
  98. package/dist/esm/types.d.ts +13 -2
  99. package/dist/esm/types.d.ts.map +1 -1
  100. package/dist/esm/types.js.map +1 -1
  101. package/dist/esm/utils/storedTransactions.d.ts +36 -0
  102. package/dist/esm/utils/storedTransactions.d.ts.map +1 -0
  103. package/dist/esm/utils/storedTransactions.js +54 -0
  104. package/dist/esm/utils/storedTransactions.js.map +1 -0
  105. package/dist/esm/version.d.ts +1 -1
  106. package/dist/esm/version.js +1 -1
  107. package/dist/esm/version.js.map +1 -1
  108. package/package.json +2 -2
  109. package/src/actions/lookupSignatureStatus.ts +444 -0
  110. package/src/actions/sendAndConfirmTransaction.ts +18 -0
  111. package/src/confirmation/createConfirmationDeadline.ts +43 -11
  112. package/src/confirmation/pollUntilDeadline.ts +14 -1
  113. package/src/confirmation/raceRpcs.ts +27 -1
  114. package/src/confirmation/types.ts +5 -0
  115. package/src/core/SolanaStepExecutor.ts +26 -11
  116. package/src/core/tasks/SolanaJitoWaitForTransactionTask.ts +133 -71
  117. package/src/core/tasks/SolanaSignAndExecuteTask.ts +51 -10
  118. package/src/core/tasks/SolanaStandardWaitForTransactionTask.ts +130 -76
  119. package/src/core/tasks/SolanaWaitForTransactionTask.ts +19 -1
  120. package/src/core/tasks/confirmationError.ts +60 -0
  121. package/src/core/tasks/resumeFromStore.ts +160 -0
  122. package/src/core/tasks/transactionOutcome.ts +273 -0
  123. package/src/types.ts +13 -1
  124. package/src/utils/storedTransactions.ts +88 -0
  125. package/src/version.ts +1 -1
  126. package/dist/cjs/core/tasks/unwrapConfirmation.d.ts +0 -24
  127. package/dist/cjs/core/tasks/unwrapConfirmation.js +0 -24
  128. package/dist/cjs/core/tasks/unwrapConfirmation.js.map +0 -1
  129. package/dist/esm/core/tasks/unwrapConfirmation.d.ts +0 -24
  130. package/dist/esm/core/tasks/unwrapConfirmation.d.ts.map +0 -1
  131. package/dist/esm/core/tasks/unwrapConfirmation.js +0 -23
  132. package/dist/esm/core/tasks/unwrapConfirmation.js.map +0 -1
  133. package/src/core/tasks/unwrapConfirmation.ts +0 -59
@@ -1,58 +1,91 @@
1
1
  Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
2
2
  const require_rpc_utils = require("../../rpc/utils.js");
3
- const require_utils_solanaErrorCause = require("../../utils/solanaErrorCause.js");
4
3
  const require_core_tasks_readSignature = require("./readSignature.js");
5
- const require_core_tasks_unwrapConfirmation = require("./unwrapConfirmation.js");
4
+ const require_utils_getTransactionLifetime = require("../../utils/getTransactionLifetime.js");
5
+ const require_utils_solanaErrorCause = require("../../utils/solanaErrorCause.js");
6
+ const require_core_tasks_transactionOutcome = require("./transactionOutcome.js");
7
+ const require_core_tasks_resumeFromStore = require("./resumeFromStore.js");
6
8
  const require_actions_sendAndConfirmTransaction = require("../../actions/sendAndConfirmTransaction.js");
7
9
  let _lifi_sdk = require("@lifi/sdk");
8
10
  let _solana_kit = require("@solana/kit");
9
11
  //#region src/core/tasks/SolanaStandardWaitForTransactionTask.ts
12
+ const MESSAGES = {
13
+ rpcUnavailable: "Unable to confirm transaction: no Solana RPC returned a usable response.",
14
+ notConfirmed: "Transaction was not confirmed before the SDK stopped waiting.",
15
+ allRpcsFailed: "All Solana RPCs failed",
16
+ someRpcsFailed: "Some Solana RPCs failed while the confirmation window was open"
17
+ };
10
18
  var SolanaStandardWaitForTransactionTask = class extends _lifi_sdk.BaseStepExecutionTask {
11
19
  async run(context) {
12
- const { client, step, statusManager, fromChain, isBridgeExecution, signedTransactions: contextSignedTransactions } = context;
13
- const signedTransactions = contextSignedTransactions ?? [];
20
+ const { step, statusManager, isBridgeExecution, signedTransactions } = context;
14
21
  const action = statusManager.findAction(step, isBridgeExecution ? "CROSS_CHAIN" : "SWAP");
15
22
  if (!action) throw new _lifi_sdk.TransactionError(_lifi_sdk.LiFiErrorCode.TransactionUnprepared, "Unable to prepare transaction. Action not found.");
23
+ if (!signedTransactions) return require_core_tasks_resumeFromStore.resumeFromStore(context, action, {
24
+ messages: MESSAGES,
25
+ send: (stored, lifetimes) => sendSigned(context, action, {
26
+ transaction: stored.transactions[0],
27
+ signature: stored.signature,
28
+ lifetimes,
29
+ resuming: true
30
+ })
31
+ });
16
32
  if (!signedTransactions.length) throw new _lifi_sdk.TransactionError(_lifi_sdk.LiFiErrorCode.TransactionUnprepared, "Unable to prepare transaction. Signed transactions are not found.");
17
33
  const signedTransaction = signedTransactions[0];
18
- const encodedTransaction = (0, _solana_kit.getBase64EncodedWireTransaction)(signedTransaction);
19
- if (!context.skipSimulation) {
20
- const simulationResult = await require_rpc_utils.callSolanaRpcsWithRetry(client, (connection) => connection.simulateTransaction(encodedTransaction, {
21
- commitment: "confirmed",
22
- replaceRecentBlockhash: true,
23
- encoding: "base64"
24
- }).send());
25
- if (simulationResult.value.err) {
26
- const cause = new require_utils_solanaErrorCause.SolanaTransactionDetailsError(simulationResult.value.err, simulationResult.value.logs);
27
- throw new _lifi_sdk.TransactionError(_lifi_sdk.LiFiErrorCode.TransactionSimulationFailed, `Transaction simulation failed: ${cause.message}`, cause);
28
- }
34
+ let txSignature;
35
+ let lifetime;
36
+ try {
37
+ if (!context.skipSimulation) await simulate(context, signedTransaction);
38
+ txSignature = require_core_tasks_readSignature.readSignature(signedTransaction);
39
+ lifetime = await require_utils_getTransactionLifetime.getTransactionLifetime(signedTransaction);
40
+ } catch (error) {
41
+ require_core_tasks_transactionOutcome.clearStoredTransactions(context, action);
42
+ throw error;
29
43
  }
30
- const txSignature = require_core_tasks_readSignature.readSignature(signedTransaction);
31
- const txLink = `${fromChain.metamask.blockExplorerUrls[0]}tx/${txSignature}`;
32
- const result = await require_actions_sendAndConfirmTransaction.sendAndConfirmTransaction(client, signedTransaction, { onBroadcast: () => {
33
- statusManager.updateAction(step, action.type, "PENDING", {
34
- txHash: txSignature,
35
- txLink
36
- });
37
- } });
38
- const status = require_core_tasks_unwrapConfirmation.unwrapConfirmation(result, {
39
- rpcUnavailable: "Unable to confirm transaction: no Solana RPC returned a usable response.",
40
- notConfirmed: "Transaction was not confirmed before the SDK stopped waiting.",
41
- allRpcsFailed: "All Solana RPCs failed",
42
- someRpcsFailed: "Some Solana RPCs failed while the confirmation window was open"
44
+ return sendSigned(context, action, {
45
+ transaction: signedTransaction,
46
+ signature: txSignature,
47
+ lifetimes: [lifetime],
48
+ resuming: false
43
49
  });
44
- if (status.err) {
45
- const cause = new require_utils_solanaErrorCause.SolanaTransactionDetailsError(status.err);
46
- throw new _lifi_sdk.TransactionError(_lifi_sdk.LiFiErrorCode.TransactionFailed, `Transaction failed: ${cause.message}`, cause);
47
- }
48
- statusManager.updateAction(step, action.type, "PENDING", {
49
- txHash: txSignature,
50
- txLink
51
- });
52
- if (isBridgeExecution) statusManager.updateAction(step, action.type, "DONE");
53
- return { status: "COMPLETED" };
54
50
  }
55
51
  };
52
+ /**
53
+ * Sends one signed transaction, confirms it and applies the result rules of
54
+ * `sendAndSettle`, on the first run and on a resume alike.
55
+ */
56
+ function sendSigned(context, action, options) {
57
+ const { client, step, statusManager } = context;
58
+ const { transaction, signature, lifetimes, resuming } = options;
59
+ const txLink = require_core_tasks_transactionOutcome.getTxLink(context, signature);
60
+ return require_core_tasks_transactionOutcome.sendAndSettle(context, action, {
61
+ signature,
62
+ send: () => require_actions_sendAndConfirmTransaction.sendAndConfirmTransaction(client, transaction, {
63
+ onBroadcast: () => {
64
+ statusManager.updateAction(step, action.type, "PENDING", {
65
+ txHash: signature,
66
+ txLink
67
+ });
68
+ },
69
+ mayResend: () => require_core_tasks_transactionOutcome.canResendStored(lifetimes, step.execution?.signedAt)
70
+ }),
71
+ confirmedFailure: require_core_tasks_transactionOutcome.failureOf,
72
+ resuming,
73
+ messages: MESSAGES
74
+ });
75
+ }
76
+ /** First run only: a resend never simulates. */
77
+ async function simulate(context, signedTransaction) {
78
+ const encodedTransaction = (0, _solana_kit.getBase64EncodedWireTransaction)(signedTransaction);
79
+ const simulationResult = await require_rpc_utils.callSolanaRpcsWithRetry(context.client, (connection) => connection.simulateTransaction(encodedTransaction, {
80
+ commitment: "confirmed",
81
+ replaceRecentBlockhash: true,
82
+ encoding: "base64"
83
+ }).send());
84
+ if (simulationResult.value.err) {
85
+ const cause = new require_utils_solanaErrorCause.SolanaTransactionDetailsError(simulationResult.value.err, simulationResult.value.logs);
86
+ throw new _lifi_sdk.TransactionError(_lifi_sdk.LiFiErrorCode.TransactionSimulationFailed, `Transaction simulation failed: ${cause.message}`, cause);
87
+ }
88
+ }
56
89
  //#endregion
57
90
  exports.SolanaStandardWaitForTransactionTask = SolanaStandardWaitForTransactionTask;
58
91
 
@@ -1 +1 @@
1
- {"version":3,"file":"SolanaStandardWaitForTransactionTask.js","names":["BaseStepExecutionTask","TransactionError","LiFiErrorCode","getBase64EncodedWireTransaction","callSolanaRpcsWithRetry","SolanaTransactionDetailsError","readSignature","sendAndConfirmTransaction","unwrapConfirmation"],"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,cAA0DA,UAAAA,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,IAAIC,UAAAA,iBACRC,UAAAA,cAAc,uBACd,kDACF;EAGF,IAAI,CAAC,mBAAmB,QACtB,MAAM,IAAID,UAAAA,iBACRC,UAAAA,cAAc,uBACd,mEACF;EAIF,MAAM,oBAAoB,mBAAmB;EAE7C,MAAM,sBAAA,GACJC,YAAAA,gCAAAA,CAAgC,iBAAiB;EAEnD,IAAI,CAAC,QAAQ,gBAAgB;GAC3B,MAAM,mBAAmB,MAAMC,kBAAAA,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,IAAIC,+BAAAA,8BAChB,iBAAiB,MAAM,KACvB,iBAAiB,MAAM,IACzB;IACA,MAAM,IAAIJ,UAAAA,iBACRC,UAAAA,cAAc,6BACd,kCAAkC,MAAM,WACxC,KACF;GACF;EACF;EAEA,MAAM,cAAcI,iCAAAA,cAAc,iBAAiB;EACnD,MAAM,SAAS,GAAG,UAAU,SAAS,kBAAkB,GAAG,KAAK;EAE/D,MAAM,SAAS,MAAMC,0CAAAA,0BAA0B,QAAQ,mBAAmB,EACxE,mBAAmB;GAGjB,cAAc,aAAa,MAAM,OAAO,MAAM,WAAW;IACvD,QAAQ;IACR;GACF,CAAC;EACH,EACF,CAAC;EAED,MAAM,SAASC,sCAAAA,mBAAmB,QAAQ;GACxC,gBACE;GACF,cACE;GACF,eAAe;GACf,gBACE;EACJ,CAAC;EAED,IAAI,OAAO,KAAK;GACd,MAAM,QAAQ,IAAIH,+BAAAA,8BAA8B,OAAO,GAAG;GAC1D,MAAM,IAAIJ,UAAAA,iBACRC,UAAAA,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"}
1
+ {"version":3,"file":"SolanaStandardWaitForTransactionTask.js","names":["BaseStepExecutionTask","TransactionError","LiFiErrorCode","resumeFromStore","readSignature","getTransactionLifetime","getTxLink","sendAndSettle","sendAndConfirmTransaction","canResendStored","failureOf","getBase64EncodedWireTransaction","callSolanaRpcsWithRetry","SolanaTransactionDetailsError"],"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,cAA0DA,UAAAA,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,IAAIC,UAAAA,iBACRC,UAAAA,cAAc,uBACd,kDACF;EAKF,IAAI,CAAC,oBACH,OAAOC,mCAAAA,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,IAAIF,UAAAA,iBACRC,UAAAA,cAAc,uBACd,mEACF;EAIF,MAAM,oBAAoB,mBAAmB;EAE7C,IAAI;EACJ,IAAI;EACJ,IAAI;GACF,IAAI,CAAC,QAAQ,gBACX,MAAM,SAAS,SAAS,iBAAiB;GAE3C,cAAcE,iCAAAA,cAAc,iBAAiB;GAC7C,WAAW,MAAMC,qCAAAA,uBAAuB,iBAAiB;EAC3D,SAAS,OAAO;GAGd,sCAAA,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,SAASC,sCAAAA,UAAU,SAAS,SAAS;CAE3C,OAAOC,sCAAAA,cAAc,SAAS,QAAQ;EACpC;EACA,YACEC,0CAAAA,0BAA0B,QAAQ,aAAa;GAC7C,mBAAmB;IAGjB,cAAc,aAAa,MAAM,OAAO,MAAM,WAAW;KACvD,QAAQ;KACR;IACF,CAAC;GACH;GAGA,iBAAiBC,sCAAAA,gBAAgB,WAAW,KAAK,WAAW,QAAQ;EACtE,CAAC;EACH,kBAAkBC,sCAAAA;EAClB;EACA,UAAU;CACZ,CAAC;AACH;;AAGA,eAAe,SACb,SACA,mBACe;CACf,MAAM,sBAAA,GAAqBC,YAAAA,gCAAAA,CAAgC,iBAAiB;CAE5E,MAAM,mBAAmB,MAAMC,kBAAAA,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,IAAIC,+BAAAA,8BAChB,iBAAiB,MAAM,KACvB,iBAAiB,MAAM,IACzB;EACA,MAAM,IAAIZ,UAAAA,iBACRC,UAAAA,cAAc,6BACd,kCAAkC,MAAM,WACxC,KACF;CACF;AACF"}
@@ -1,11 +1,23 @@
1
1
  Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
2
+ const require_utils_storedTransactions = require("../../utils/storedTransactions.js");
2
3
  const require_core_tasks_SolanaJitoWaitForTransactionTask = require("./SolanaJitoWaitForTransactionTask.js");
3
4
  const require_core_tasks_SolanaStandardWaitForTransactionTask = require("./SolanaStandardWaitForTransactionTask.js");
4
5
  let _lifi_sdk = require("@lifi/sdk");
5
6
  //#region src/core/tasks/SolanaWaitForTransactionTask.ts
7
+ /**
8
+ * On a resume the sign task did not run, so the flag is missing and the
9
+ * stored bytes keep the shape instead: a leading `[` marks a bundle. With a
10
+ * `txHash` alone the standard task looks the signature up, which works for a
11
+ * bundle's first signature too.
12
+ */
13
+ function isBundleExecution(context) {
14
+ if (context.isBundleExecution !== void 0) return context.isBundleExecution;
15
+ const action = context.statusManager.findAction(context.step, context.isBridgeExecution ? "CROSS_CHAIN" : "SWAP");
16
+ return action?.txHex ? require_utils_storedTransactions.isStoredBundle(action.txHex) : false;
17
+ }
6
18
  var SolanaWaitForTransactionTask = class extends _lifi_sdk.BaseStepExecutionTask {
7
19
  async run(context) {
8
- if (context.isBundleExecution) return new require_core_tasks_SolanaJitoWaitForTransactionTask.SolanaJitoWaitForTransactionTask().run(context);
20
+ if (isBundleExecution(context)) return new require_core_tasks_SolanaJitoWaitForTransactionTask.SolanaJitoWaitForTransactionTask().run(context);
9
21
  return new require_core_tasks_SolanaStandardWaitForTransactionTask.SolanaStandardWaitForTransactionTask().run(context);
10
22
  }
11
23
  };
@@ -1 +1 @@
1
- {"version":3,"file":"SolanaWaitForTransactionTask.js","names":["BaseStepExecutionTask","SolanaJitoWaitForTransactionTask","SolanaStandardWaitForTransactionTask"],"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.isBundleExecution) {\n return new SolanaJitoWaitForTransactionTask().run(context)\n }\n return new SolanaStandardWaitForTransactionTask().run(context)\n }\n}\n"],"mappings":";;;;;AAKA,IAAa,+BAAb,cAAkDA,UAAAA,sBAAsB;CACtE,MAAM,IAAI,SAAyD;EAKjE,IAAI,QAAQ,mBACV,OAAO,IAAIC,oDAAAA,iCAAiC,CAAC,CAAC,IAAI,OAAO;EAE3D,OAAO,IAAIC,wDAAAA,qCAAqC,CAAC,CAAC,IAAI,OAAO;CAC/D;AACF"}
1
+ {"version":3,"file":"SolanaWaitForTransactionTask.js","names":["isStoredBundle","BaseStepExecutionTask","SolanaJitoWaitForTransactionTask","SolanaStandardWaitForTransactionTask"],"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,QAAQA,iCAAAA,eAAe,OAAO,KAAK,IAAI;AACxD;AAEA,IAAa,+BAAb,cAAkDC,UAAAA,sBAAsB;CACtE,MAAM,IAAI,SAAyD;EAKjE,IAAI,kBAAkB,OAAO,GAC3B,OAAO,IAAIC,oDAAAA,iCAAiC,CAAC,CAAC,IAAI,OAAO;EAE3D,OAAO,IAAIC,wDAAAA,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,26 @@
1
+ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
2
+ let _lifi_sdk = require("@lifi/sdk");
3
+ //#region src/core/tasks/confirmationError.ts
4
+ /** `cause` is the first collected error on purpose: `BaseError` overwrites its
5
+ * stack with `getRootCause(cause).stack`, and an `AggregateError` has no
6
+ * `cause`, so without it the stack would point at this file. */
7
+ const chainErrors = (errors, message) => errors.length ? new AggregateError(errors, message, { cause: errors[0] }) : void 0;
8
+ /**
9
+ * The error the integrator sees for a result that did not confirm.
10
+ *
11
+ * `rpc-unavailable` and `not-confirmed` must stay distinct: collapsing them
12
+ * reported a live RPC defect as an expired transaction.
13
+ *
14
+ * `expired` maps exactly like `not-confirmed` - same code, same message - so
15
+ * no text changes. The wait tasks tell the two apart by `result.kind` before
16
+ * they call this: only they can run the history lookup and the status API a
17
+ * final "dropped" needs, so the final marker is theirs to add.
18
+ */
19
+ function confirmationError(result, messages) {
20
+ if (result.kind === "rpc-unavailable") return new _lifi_sdk.RPCError(_lifi_sdk.LiFiErrorCode.RpcUnavailable, messages.rpcUnavailable, chainErrors(result.errors, messages.allRpcsFailed));
21
+ return new _lifi_sdk.TransactionError(_lifi_sdk.LiFiErrorCode.TransactionExpired, messages.notConfirmed, chainErrors(result.errors, messages.someRpcsFailed));
22
+ }
23
+ //#endregion
24
+ exports.confirmationError = confirmationError;
25
+
26
+ //# sourceMappingURL=confirmationError.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"confirmationError.js","names":["RPCError","LiFiErrorCode","TransactionError"],"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,IAAIA,UAAAA,SACTC,UAAAA,cAAc,gBACd,SAAS,gBACT,YAAY,OAAO,QAAQ,SAAS,aAAa,CACnD;CAOF,OAAO,IAAIC,UAAAA,iBACTD,UAAAA,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,81 @@
1
+ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
2
+ const require_utils_storedTransactions = require("../../utils/storedTransactions.js");
3
+ const require_confirmation_types = require("../../confirmation/types.js");
4
+ const require_utils_getTransactionLifetime = require("../../utils/getTransactionLifetime.js");
5
+ const require_actions_lookupSignatureStatus = require("../../actions/lookupSignatureStatus.js");
6
+ const require_core_tasks_confirmationError = require("./confirmationError.js");
7
+ const require_core_tasks_transactionOutcome = require("./transactionOutcome.js");
8
+ let _lifi_sdk = require("@lifi/sdk");
9
+ //#region src/core/tasks/resumeFromStore.ts
10
+ function readResumeSource(context, action) {
11
+ if (action.txHex) {
12
+ const stored = require_utils_storedTransactions.decodeStoredTransactions(action.txHex);
13
+ if (stored) {
14
+ if (action.txHash && action.txHash !== stored.signature) return {
15
+ kind: "mismatch",
16
+ signature: action.txHash
17
+ };
18
+ return {
19
+ kind: "bytes",
20
+ stored
21
+ };
22
+ }
23
+ require_core_tasks_transactionOutcome.clearStoredTransactions(context, action);
24
+ }
25
+ if (action.txHash) return {
26
+ kind: "hash",
27
+ signature: action.txHash
28
+ };
29
+ throw new _lifi_sdk.TransactionError(_lifi_sdk.LiFiErrorCode.TransactionUnprepared, "Unable to prepare transaction. Signed transactions are not found.");
30
+ }
31
+ /**
32
+ * Resume mode of both wait tasks: the sign task did not run in this session,
33
+ * so the transaction comes from the action.
34
+ *
35
+ * 1. Look the signature up on every RPC. A confirmed status goes straight to
36
+ * the result rules: the transaction may have landed after the page closed.
37
+ * This look only has to find, so it asks for no canary.
38
+ * 2. Otherwise resend the stored bytes through `send` when that is allowed -
39
+ * the task's normal send path, without simulation.
40
+ * 3. Otherwise - a hash alone, or bytes past the resend age cap - nothing is
41
+ * sent, and only the dropped rule can make the outcome final.
42
+ *
43
+ * Bytes that are not the stored txHash's transaction are never sent, and the
44
+ * dropped rule never runs for them: the outcome stays unknown unless the
45
+ * lookup by txHash finds it confirmed.
46
+ */
47
+ async function resumeFromStore(context, action, options) {
48
+ const { client, step } = context;
49
+ const source = readResumeSource(context, action);
50
+ const signature = source.kind === "bytes" ? source.stored.signature : source.signature;
51
+ const lookup = await require_actions_lookupSignatureStatus.lookupSignatureStatus(client, signature);
52
+ if (lookup.kind === "found" && require_confirmation_types.isConfirmedCommitment(lookup.status.confirmationStatus)) return require_core_tasks_transactionOutcome.recordLanded(context, action, {
53
+ signature,
54
+ failure: require_core_tasks_transactionOutcome.failureOf(lookup.status)
55
+ });
56
+ const lifetimes = source.kind === "bytes" ? await Promise.all(source.stored.transactions.map((transaction) => require_utils_getTransactionLifetime.getTransactionLifetime(transaction))) : [];
57
+ if (source.kind === "bytes" && require_core_tasks_transactionOutcome.canResendStored(lifetimes, step.execution?.signedAt)) return options.send(source.stored, lifetimes);
58
+ const silent = lookup.kind === "unknown" && !lookup.answered;
59
+ const error = require_core_tasks_confirmationError.confirmationError(silent ? {
60
+ kind: "rpc-unavailable",
61
+ errors: lookup.errors
62
+ } : {
63
+ kind: "not-confirmed",
64
+ errors: []
65
+ }, options.messages);
66
+ if (source.kind === "mismatch") throw error;
67
+ const status = await require_core_tasks_transactionOutcome.resolveUnconfirmed(context, action, {
68
+ signature,
69
+ error,
70
+ expiredAtSlot: void 0,
71
+ messages: options.messages
72
+ });
73
+ return require_core_tasks_transactionOutcome.recordLanded(context, action, {
74
+ signature,
75
+ failure: require_core_tasks_transactionOutcome.failureOf(status)
76
+ });
77
+ }
78
+ //#endregion
79
+ exports.resumeFromStore = resumeFromStore;
80
+
81
+ //# sourceMappingURL=resumeFromStore.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"resumeFromStore.js","names":["decodeStoredTransactions","TransactionError","LiFiErrorCode","lookupSignatureStatus","isConfirmedCommitment","recordLanded","failureOf","getTransactionLifetime","canResendStored","confirmationError","resolveUnconfirmed"],"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,SAASA,iCAAAA,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,sCAAA,wBAAwB,SAAS,MAAM;CACzC;CAEA,IAAI,OAAO,QACT,OAAO;EAAE,MAAM;EAAQ,WAAW,OAAO;CAAoB;CAM/D,MAAM,IAAIC,UAAAA,iBACRC,UAAAA,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,MAAMC,sCAAAA,sBAAsB,QAAQ,SAAS;CAC5D,IACE,OAAO,SAAS,WAChBC,2BAAAA,sBAAsB,OAAO,OAAO,kBAAkB,GAEtD,OAAOC,sCAAAA,aAAa,SAAS,QAAQ;EACnC;EACA,SAASC,sCAAAA,UAAU,OAAO,MAAM;CAClC,CAAC;CAGH,MAAM,YACJ,OAAO,SAAS,UACZ,MAAM,QAAQ,IACZ,OAAO,OAAO,aAAa,KAAK,gBAC9BC,qCAAAA,uBAAuB,WAAW,CACpC,CACF,IACA,CAAC;CAGP,IACE,OAAO,SAAS,WAChBC,sCAAAA,gBAAgB,WAAW,KAAK,WAAW,QAAQ,GAEnD,OAAO,QAAQ,KAAK,OAAO,QAAQ,SAAS;CAK9C,MAAM,SAAS,OAAO,SAAS,aAAa,CAAC,OAAO;CACpD,MAAM,QAAQC,qCAAAA,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,MAAMC,sCAAAA,mBAAmB,SAAS,QAAQ;EACvD;EACA;EACA,eAAe,KAAA;EACf,UAAU,QAAQ;CACpB,CAAC;CACD,OAAOL,sCAAAA,aAAa,SAAS,QAAQ;EACnC;EACA,SAASC,sCAAAA,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