@lifi/sdk-provider-stellar 4.3.7 → 4.3.8
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 +11 -0
- package/README.md +9 -0
- package/dist/esm/core/StellarStepExecutor.d.ts.map +1 -1
- package/dist/esm/core/StellarStepExecutor.js +2 -2
- package/dist/esm/core/StellarStepExecutor.js.map +1 -1
- package/dist/esm/core/tasks/StellarSignAndExecuteTask.d.ts.map +1 -1
- package/dist/esm/core/tasks/StellarSignAndExecuteTask.js +17 -2
- package/dist/esm/core/tasks/StellarSignAndExecuteTask.js.map +1 -1
- package/dist/esm/core/tasks/StellarWaitForTransactionTask.d.ts.map +1 -1
- package/dist/esm/core/tasks/StellarWaitForTransactionTask.js +24 -2
- package/dist/esm/core/tasks/StellarWaitForTransactionTask.js.map +1 -1
- package/dist/esm/core/tasks/helpers/classifySubmitFailure.d.ts +33 -0
- package/dist/esm/core/tasks/helpers/classifySubmitFailure.d.ts.map +1 -0
- package/dist/esm/core/tasks/helpers/classifySubmitFailure.js +65 -0
- package/dist/esm/core/tasks/helpers/classifySubmitFailure.js.map +1 -0
- package/dist/esm/core/tasks/helpers/proveStellarTransactionAbsent.d.ts +27 -0
- package/dist/esm/core/tasks/helpers/proveStellarTransactionAbsent.d.ts.map +1 -0
- package/dist/esm/core/tasks/helpers/proveStellarTransactionAbsent.js +55 -0
- package/dist/esm/core/tasks/helpers/proveStellarTransactionAbsent.js.map +1 -0
- package/dist/esm/core/tasks/helpers/waitForStellarTransaction.d.ts.map +1 -1
- package/dist/esm/core/tasks/helpers/waitForStellarTransaction.js +7 -5
- package/dist/esm/core/tasks/helpers/waitForStellarTransaction.js.map +1 -1
- package/dist/esm/version.d.ts +1 -1
- package/dist/esm/version.js +1 -1
- package/dist/esm/version.js.map +1 -1
- package/package.json +3 -3
- package/src/core/StellarStepExecutor.ts +6 -3
- package/src/core/tasks/StellarSignAndExecuteTask.ts +31 -1
- package/src/core/tasks/StellarWaitForTransactionTask.ts +45 -3
- package/src/core/tasks/helpers/classifySubmitFailure.ts +123 -0
- package/src/core/tasks/helpers/proveStellarTransactionAbsent.ts +90 -0
- package/src/core/tasks/helpers/waitForStellarTransaction.ts +9 -5
- package/src/version.ts +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,16 @@
|
|
|
1
1
|
# @lifi/sdk-provider-stellar
|
|
2
2
|
|
|
3
|
+
## 4.3.8
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- [#510](https://github.com/lifinance/sdk/pull/510) [`bb964c0`](https://github.com/lifinance/sdk/commit/bb964c03d8ea1770303ab1bba803373a80e6388f) Thanks [@chybisov](https://github.com/chybisov)! - Bump runtime dependencies: viem to 2.57.3, @stellar/stellar-sdk to 17.2.1,
|
|
8
|
+
@mysten/sui to 2.35.0, @lifi/types to 18.13.0 and @bigmi/core to 0.9.3.
|
|
9
|
+
|
|
10
|
+
- [#507](https://github.com/lifinance/sdk/pull/507) [`14f4ecc`](https://github.com/lifinance/sdk/commit/14f4ecc2714799449d57b61ff06b040df505184e) Thanks [@chybisov](https://github.com/chybisov)! - Mark a FAILED result, and a rejected submission that the network confirms it never applied, as final so "Try again" signs a new transaction; any other failure after signing is re-checked instead. The check that the network never applied a rejected submission gives each RPC 10 seconds to answer; a node that does not answer in time gives no information, as a failed request does, so a hung node cannot hold this check. The sign task refuses to sign while the step has an open transaction. It checks the action again after the wallet returns: if a stopped run's transaction merged into it while the prompt was open, the step fails with `TransactionConflict` and the new signature is neither stored nor submitted.
|
|
11
|
+
- Updated dependencies [[`bb964c0`](https://github.com/lifinance/sdk/commit/bb964c03d8ea1770303ab1bba803373a80e6388f), [`48af3ae`](https://github.com/lifinance/sdk/commit/48af3aeb250299ef9d2ff9eb79a38a6b8f52d409), [`14f4ecc`](https://github.com/lifinance/sdk/commit/14f4ecc2714799449d57b61ff06b040df505184e)]:
|
|
12
|
+
- @lifi/sdk@4.11.0
|
|
13
|
+
|
|
3
14
|
## 4.3.7
|
|
4
15
|
|
|
5
16
|
### Patch Changes
|
package/README.md
CHANGED
|
@@ -83,6 +83,13 @@ needs no ecosystem library. To discover and connect browser wallets such as Frei
|
|
|
83
83
|
xBull, or Lobstr, we recommend
|
|
84
84
|
[Stellar Wallets Kit](https://github.com/Creit-Tech/Stellar-Wallets-Kit).
|
|
85
85
|
|
|
86
|
+
**Zcash**
|
|
87
|
+
```bash
|
|
88
|
+
pnpm add @lifi/sdk-provider-zcash
|
|
89
|
+
```
|
|
90
|
+
|
|
91
|
+
ZEC is a destination-only chain: `ZcashProvider` validates transparent `t1` and `t3` receivers, and unified `u1` receivers that carry an Orchard receiver, and needs no wallet. Register it after `BitcoinProvider`; it serves ZEC only.
|
|
92
|
+
|
|
86
93
|
## Architecture
|
|
87
94
|
|
|
88
95
|
The LI.FI SDK uses a modular provider architecture:
|
|
@@ -134,6 +141,7 @@ import { BitcoinProvider } from '@lifi/sdk-provider-bitcoin'
|
|
|
134
141
|
import { SuiProvider } from '@lifi/sdk-provider-sui'
|
|
135
142
|
import { TronProvider } from '@lifi/sdk-provider-tron'
|
|
136
143
|
import { StellarProvider } from '@lifi/sdk-provider-stellar'
|
|
144
|
+
import { ZcashProvider } from '@lifi/sdk-provider-zcash'
|
|
137
145
|
|
|
138
146
|
const client = createClient({
|
|
139
147
|
integrator: 'Your dApp/company name',
|
|
@@ -144,6 +152,7 @@ const client = createClient({
|
|
|
144
152
|
SuiProvider({ /* options */ }),
|
|
145
153
|
TronProvider({ /* options */ }),
|
|
146
154
|
StellarProvider({ /* options */ }),
|
|
155
|
+
ZcashProvider(),
|
|
147
156
|
],
|
|
148
157
|
})
|
|
149
158
|
```
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"StellarStepExecutor.d.ts","names":[],"sources":["../../../src/core/StellarStepExecutor.ts"],"mappings":";;;
|
|
1
|
+
{"version":3,"file":"StellarStepExecutor.d.ts","names":[],"sources":["../../../src/core/StellarStepExecutor.ts"],"mappings":";;;qBAyBa,4BAA4B;UAC/B;UACA;EAER,YAAY,SAAS;EAMrB,cAAe,MAAM;WAqBZ,cACP,OAAO,OACP,OAAO,kBACP,SAAS,oBACR,QAAQ;WAEF,gBACP,aAAa,4BACZ,QAAQ;WAUF,iBACP,SAAS,+BACR"}
|
|
@@ -4,7 +4,7 @@ import { StellarPrepareTransactionTask } from "./tasks/StellarPrepareTransaction
|
|
|
4
4
|
import { StellarSetAllowanceTask } from "./tasks/StellarSetAllowanceTask.js";
|
|
5
5
|
import { StellarSignAndExecuteTask } from "./tasks/StellarSignAndExecuteTask.js";
|
|
6
6
|
import { StellarWaitForTransactionTask } from "./tasks/StellarWaitForTransactionTask.js";
|
|
7
|
-
import { BaseStepExecutor, CheckBalanceTask, LiFiErrorCode, TaskPipeline, TransactionError, WaitForTransactionStatusTask } from "@lifi/sdk";
|
|
7
|
+
import { BaseStepExecutor, CheckBalanceTask, LiFiErrorCode, TaskPipeline, TransactionError, WaitForTransactionStatusTask, hasOpenTransaction } from "@lifi/sdk";
|
|
8
8
|
//#region src/core/StellarStepExecutor.ts
|
|
9
9
|
var StellarStepExecutor = class extends BaseStepExecutor {
|
|
10
10
|
wallet;
|
|
@@ -40,7 +40,7 @@ var StellarStepExecutor = class extends BaseStepExecutor {
|
|
|
40
40
|
new WaitForTransactionStatusTask(isBridgeExecution ? "RECEIVING_CHAIN" : "SWAP")
|
|
41
41
|
];
|
|
42
42
|
const swapOrBridgeAction = this.statusManager.findAction(step, isBridgeExecution ? "CROSS_CHAIN" : "SWAP");
|
|
43
|
-
const firstTask = swapOrBridgeAction
|
|
43
|
+
const firstTask = hasOpenTransaction(swapOrBridgeAction) ? swapOrBridgeAction?.status === "DONE" ? WaitForTransactionStatusTask : StellarWaitForTransactionTask : CheckBalanceTask;
|
|
44
44
|
const firstTaskIndex = tasks.findIndex((task) => task.constructor === firstTask);
|
|
45
45
|
if (firstTaskIndex === -1) throw new TransactionError(LiFiErrorCode.InternalError, "StellarStepExecutor.createPipeline: first task not found");
|
|
46
46
|
const tasksToRun = tasks.slice(firstTaskIndex);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"StellarStepExecutor.js","names":[],"sources":["../../../src/core/StellarStepExecutor.ts"],"sourcesContent":["import {\n BaseStepExecutor,\n CheckBalanceTask,\n type ExecutionAction,\n LiFiErrorCode,\n type LiFiStepExtended,\n type SDKError,\n type StepExecutorBaseContext,\n TaskPipeline,\n TransactionError,\n WaitForTransactionStatusTask,\n} from '@lifi/sdk'\nimport { parseStellarErrors } from '../errors/parseStellarErrors.js'\nimport type {\n StellarStepExecutorContext,\n StellarStepExecutorOptions,\n StellarWallet,\n} from '../types.js'\nimport { StellarCheckAllowanceTask } from './tasks/StellarCheckAllowanceTask.js'\nimport { StellarPrepareTransactionTask } from './tasks/StellarPrepareTransactionTask.js'\nimport { StellarSetAllowanceTask } from './tasks/StellarSetAllowanceTask.js'\nimport { StellarSignAndExecuteTask } from './tasks/StellarSignAndExecuteTask.js'\nimport { StellarWaitForTransactionTask } from './tasks/StellarWaitForTransactionTask.js'\n\nexport class StellarStepExecutor extends BaseStepExecutor {\n private wallet: StellarWallet\n private networkPassphrase: string\n\n constructor(options: StellarStepExecutorOptions) {\n super(options)\n this.wallet = options.wallet\n this.networkPassphrase = options.networkPassphrase\n }\n\n checkWallet = (step: LiFiStepExtended): void => {\n // Prevent execution of the quote by wallet different from the one which requested the quote\n if (this.wallet.address !== step.action.fromAddress) {\n throw new TransactionError(\n LiFiErrorCode.WalletChangedDuringExecution,\n 'The wallet address that requested the quote does not match the wallet address attempting to sign the transaction.'\n )\n }\n\n // The provider resolves this from options first and the wallet second, so a\n // disagreement means the integrator configured one network while the user\n // connected to another. Signing would produce a txBAD_AUTH the user pays\n // for in a wasted signature.\n if (this.networkPassphrase !== this.wallet.networkPassphrase) {\n throw new TransactionError(\n LiFiErrorCode.ChainSwitchError,\n 'The connected Stellar wallet is on a different network than the route.'\n )\n }\n }\n\n override parseErrors = (\n error: Error,\n step?: LiFiStepExtended,\n action?: ExecutionAction\n ): Promise<SDKError> => parseStellarErrors(error, step, action)\n\n override createContext = async (\n baseContext: StepExecutorBaseContext\n ): Promise<StellarStepExecutorContext> => {\n return {\n ...baseContext,\n pollingIntervalMs: 3_000,\n wallet: this.wallet,\n networkPassphrase: this.networkPassphrase,\n checkWallet: this.checkWallet,\n }\n }\n\n override createPipeline = (\n context: StellarStepExecutorContext\n ): TaskPipeline => {\n const { step, isBridgeExecution } = context\n\n // Order is load-bearing: the allowance tasks must complete before the\n // transaction is prepared. Granting an allowance submits a transaction that\n // consumes the sender's sequence number, and the backend builds the route\n // envelope from a live account read — so an envelope prepared first would be\n // invalidated by the approval that follows it.\n const tasks = [\n new CheckBalanceTask(),\n new StellarCheckAllowanceTask(),\n new StellarSetAllowanceTask(),\n new StellarPrepareTransactionTask(),\n new StellarSignAndExecuteTask(),\n new StellarWaitForTransactionTask(),\n new WaitForTransactionStatusTask(\n isBridgeExecution ? 'RECEIVING_CHAIN' : 'SWAP'\n ),\n ]\n\n const swapOrBridgeAction = this.statusManager.findAction(\n step,\n isBridgeExecution ? 'CROSS_CHAIN' : 'SWAP'\n )\n\n // Three-way entry, as Bitcoin does. Stellar derives and persists the\n // transaction hash BEFORE submitting, so a hash on the action means an\n // envelope was signed and very likely broadcast. Resuming such a step at\n // CheckBalanceTask would re-prepare, re-sign and submit a SECOND\n // transaction — executing the swap twice. Resume at the confirmation poll\n // instead and let the already-broadcast transaction settle.\n const firstTask = swapOrBridgeAction
|
|
1
|
+
{"version":3,"file":"StellarStepExecutor.js","names":[],"sources":["../../../src/core/StellarStepExecutor.ts"],"sourcesContent":["import {\n BaseStepExecutor,\n CheckBalanceTask,\n type ExecutionAction,\n hasOpenTransaction,\n LiFiErrorCode,\n type LiFiStepExtended,\n type SDKError,\n type StepExecutorBaseContext,\n TaskPipeline,\n TransactionError,\n WaitForTransactionStatusTask,\n} from '@lifi/sdk'\nimport { parseStellarErrors } from '../errors/parseStellarErrors.js'\nimport type {\n StellarStepExecutorContext,\n StellarStepExecutorOptions,\n StellarWallet,\n} from '../types.js'\nimport { StellarCheckAllowanceTask } from './tasks/StellarCheckAllowanceTask.js'\nimport { StellarPrepareTransactionTask } from './tasks/StellarPrepareTransactionTask.js'\nimport { StellarSetAllowanceTask } from './tasks/StellarSetAllowanceTask.js'\nimport { StellarSignAndExecuteTask } from './tasks/StellarSignAndExecuteTask.js'\nimport { StellarWaitForTransactionTask } from './tasks/StellarWaitForTransactionTask.js'\n\nexport class StellarStepExecutor extends BaseStepExecutor {\n private wallet: StellarWallet\n private networkPassphrase: string\n\n constructor(options: StellarStepExecutorOptions) {\n super(options)\n this.wallet = options.wallet\n this.networkPassphrase = options.networkPassphrase\n }\n\n checkWallet = (step: LiFiStepExtended): void => {\n // Prevent execution of the quote by wallet different from the one which requested the quote\n if (this.wallet.address !== step.action.fromAddress) {\n throw new TransactionError(\n LiFiErrorCode.WalletChangedDuringExecution,\n 'The wallet address that requested the quote does not match the wallet address attempting to sign the transaction.'\n )\n }\n\n // The provider resolves this from options first and the wallet second, so a\n // disagreement means the integrator configured one network while the user\n // connected to another. Signing would produce a txBAD_AUTH the user pays\n // for in a wasted signature.\n if (this.networkPassphrase !== this.wallet.networkPassphrase) {\n throw new TransactionError(\n LiFiErrorCode.ChainSwitchError,\n 'The connected Stellar wallet is on a different network than the route.'\n )\n }\n }\n\n override parseErrors = (\n error: Error,\n step?: LiFiStepExtended,\n action?: ExecutionAction\n ): Promise<SDKError> => parseStellarErrors(error, step, action)\n\n override createContext = async (\n baseContext: StepExecutorBaseContext\n ): Promise<StellarStepExecutorContext> => {\n return {\n ...baseContext,\n pollingIntervalMs: 3_000,\n wallet: this.wallet,\n networkPassphrase: this.networkPassphrase,\n checkWallet: this.checkWallet,\n }\n }\n\n override createPipeline = (\n context: StellarStepExecutorContext\n ): TaskPipeline => {\n const { step, isBridgeExecution } = context\n\n // Order is load-bearing: the allowance tasks must complete before the\n // transaction is prepared. Granting an allowance submits a transaction that\n // consumes the sender's sequence number, and the backend builds the route\n // envelope from a live account read — so an envelope prepared first would be\n // invalidated by the approval that follows it.\n const tasks = [\n new CheckBalanceTask(),\n new StellarCheckAllowanceTask(),\n new StellarSetAllowanceTask(),\n new StellarPrepareTransactionTask(),\n new StellarSignAndExecuteTask(),\n new StellarWaitForTransactionTask(),\n new WaitForTransactionStatusTask(\n isBridgeExecution ? 'RECEIVING_CHAIN' : 'SWAP'\n ),\n ]\n\n const swapOrBridgeAction = this.statusManager.findAction(\n step,\n isBridgeExecution ? 'CROSS_CHAIN' : 'SWAP'\n )\n\n // Three-way entry, as Bitcoin does. Stellar derives and persists the\n // transaction hash BEFORE submitting, so a hash on the action means an\n // envelope was signed and very likely broadcast. Resuming such a step at\n // CheckBalanceTask would re-prepare, re-sign and submit a SECOND\n // transaction — executing the swap twice. Resume at the confirmation poll\n // instead and let the already-broadcast transaction settle. Only a FAILED\n // action with a final outcome (`txFinal`) signs again; this is the same\n // predicate as the pre-sign guard.\n const firstTask = hasOpenTransaction(swapOrBridgeAction)\n ? swapOrBridgeAction?.status === 'DONE'\n ? WaitForTransactionStatusTask\n : StellarWaitForTransactionTask\n : CheckBalanceTask\n\n // Compare classes, not names: a minifier can give two task classes the\n // same name.\n const firstTaskIndex = tasks.findIndex(\n (task) => task.constructor === firstTask\n )\n if (firstTaskIndex === -1) {\n throw new TransactionError(\n LiFiErrorCode.InternalError,\n 'StellarStepExecutor.createPipeline: first task not found'\n )\n }\n\n const tasksToRun = tasks.slice(firstTaskIndex)\n\n return new TaskPipeline(tasksToRun)\n }\n}\n"],"mappings":";;;;;;;;AAyBA,IAAa,sBAAb,cAAyC,iBAAiB;CACxD;CACA;CAEA,YAAY,SAAqC;EAC/C,MAAM,OAAO;EACb,KAAK,SAAS,QAAQ;EACtB,KAAK,oBAAoB,QAAQ;CACnC;CAEA,eAAe,SAAiC;EAE9C,IAAI,KAAK,OAAO,YAAY,KAAK,OAAO,aACtC,MAAM,IAAI,iBACR,cAAc,8BACd,mHACF;EAOF,IAAI,KAAK,sBAAsB,KAAK,OAAO,mBACzC,MAAM,IAAI,iBACR,cAAc,kBACd,wEACF;CAEJ;CAEA,eACE,OACA,MACA,WACsB,mBAAmB,OAAO,MAAM,MAAM;CAE9D,gBAAyB,OACvB,gBACwC;EACxC,OAAO;GACL,GAAG;GACH,mBAAmB;GACnB,QAAQ,KAAK;GACb,mBAAmB,KAAK;GACxB,aAAa,KAAK;EACpB;CACF;CAEA,kBACE,YACiB;EACjB,MAAM,EAAE,MAAM,sBAAsB;EAOpC,MAAM,QAAQ;GACZ,IAAI,iBAAiB;GACrB,IAAI,0BAA0B;GAC9B,IAAI,wBAAwB;GAC5B,IAAI,8BAA8B;GAClC,IAAI,0BAA0B;GAC9B,IAAI,8BAA8B;GAClC,IAAI,6BACF,oBAAoB,oBAAoB,MAC1C;EACF;EAEA,MAAM,qBAAqB,KAAK,cAAc,WAC5C,MACA,oBAAoB,gBAAgB,MACtC;EAUA,MAAM,YAAY,mBAAmB,kBAAkB,IACnD,oBAAoB,WAAW,SAC7B,+BACA,gCACF;EAIJ,MAAM,iBAAiB,MAAM,WAC1B,SAAS,KAAK,gBAAgB,SACjC;EACA,IAAI,mBAAmB,IACrB,MAAM,IAAI,iBACR,cAAc,eACd,0DACF;EAGF,MAAM,aAAa,MAAM,MAAM,cAAc;EAE7C,OAAO,IAAI,aAAa,UAAU;CACpC;AACF"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"StellarSignAndExecuteTask.d.ts","names":[],"sources":["../../../../src/core/tasks/StellarSignAndExecuteTask.ts"],"mappings":";;;
|
|
1
|
+
{"version":3,"file":"StellarSignAndExecuteTask.d.ts","names":[],"sources":["../../../../src/core/tasks/StellarSignAndExecuteTask.ts"],"mappings":";;;qBAea,kCAAkC;EAC7C,IAAU,SAAS,6BAA6B,QAAQ"}
|
|
@@ -1,27 +1,42 @@
|
|
|
1
1
|
import { deriveTransactionHash } from "./helpers/deriveTransactionHash.js";
|
|
2
2
|
import { getStellarTxLink } from "./helpers/getStellarTxLink.js";
|
|
3
3
|
import { submitStellarTransaction } from "./helpers/submitStellarTransaction.js";
|
|
4
|
-
import {
|
|
4
|
+
import { classifySubmitFailure } from "./helpers/classifySubmitFailure.js";
|
|
5
|
+
import { BaseStepExecutionTask, CLEARED_TRANSACTION_FIELDS, LiFiErrorCode, TransactionError, assertNoOpenTransaction, getTransactionRequestData } from "@lifi/sdk";
|
|
5
6
|
//#region src/core/tasks/StellarSignAndExecuteTask.ts
|
|
6
7
|
var StellarSignAndExecuteTask = class extends BaseStepExecutionTask {
|
|
7
8
|
async run(context) {
|
|
8
9
|
const { step, client, wallet, fromChain, statusManager, executionOptions, networkPassphrase, isBridgeExecution, checkWallet } = context;
|
|
9
10
|
const action = statusManager.findAction(step, isBridgeExecution ? "CROSS_CHAIN" : "SWAP");
|
|
10
11
|
if (!action) throw new TransactionError(LiFiErrorCode.TransactionUnprepared, "Unable to prepare transaction. Action not found.");
|
|
12
|
+
assertNoOpenTransaction(action);
|
|
11
13
|
const transactionRequestData = await getTransactionRequestData(step, executionOptions);
|
|
12
14
|
checkWallet(step);
|
|
15
|
+
assertNoOpenTransaction(statusManager.findAction(step, action.type));
|
|
13
16
|
const { signedTxXdr } = await wallet.signTransaction(transactionRequestData, {
|
|
14
17
|
address: wallet.address,
|
|
15
18
|
networkPassphrase
|
|
16
19
|
});
|
|
20
|
+
assertNoOpenTransaction(statusManager.findAction(step, action.type));
|
|
17
21
|
const transactionHash = deriveTransactionHash(signedTxXdr, networkPassphrase);
|
|
18
22
|
statusManager.updateAction(step, action.type, "PENDING", {
|
|
23
|
+
...CLEARED_TRANSACTION_FIELDS,
|
|
19
24
|
txHash: transactionHash,
|
|
20
25
|
txLink: getStellarTxLink(fromChain, transactionHash),
|
|
21
26
|
txHex: signedTxXdr,
|
|
22
27
|
signedAt: Date.now()
|
|
23
28
|
});
|
|
24
|
-
|
|
29
|
+
try {
|
|
30
|
+
await submitStellarTransaction(client, signedTxXdr, networkPassphrase);
|
|
31
|
+
} catch (error) {
|
|
32
|
+
throw await classifySubmitFailure({
|
|
33
|
+
client,
|
|
34
|
+
step,
|
|
35
|
+
transactionHash,
|
|
36
|
+
signedTxXdr,
|
|
37
|
+
networkPassphrase
|
|
38
|
+
}, error);
|
|
39
|
+
}
|
|
25
40
|
return {
|
|
26
41
|
status: "COMPLETED",
|
|
27
42
|
context: { transactionHash }
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"StellarSignAndExecuteTask.js","names":[],"sources":["../../../../src/core/tasks/StellarSignAndExecuteTask.ts"],"sourcesContent":["import {\n BaseStepExecutionTask,\n getTransactionRequestData,\n LiFiErrorCode,\n type TaskResult,\n TransactionError,\n} from '@lifi/sdk'\nimport type { StellarStepExecutorContext } from '../../types.js'\nimport { deriveTransactionHash } from './helpers/deriveTransactionHash.js'\nimport { getStellarTxLink } from './helpers/getStellarTxLink.js'\nimport { submitStellarTransaction } from './helpers/submitStellarTransaction.js'\n\nexport class StellarSignAndExecuteTask extends BaseStepExecutionTask {\n async run(context: StellarStepExecutorContext): Promise<TaskResult> {\n const {\n step,\n client,\n wallet,\n fromChain,\n statusManager,\n executionOptions,\n networkPassphrase,\n isBridgeExecution,\n checkWallet,\n } = context\n\n const action = statusManager.findAction(\n step,\n isBridgeExecution ? 'CROSS_CHAIN' : 'SWAP'\n )\n\n if (!action) {\n throw new TransactionError(\n LiFiErrorCode.TransactionUnprepared,\n 'Unable to prepare transaction. Action not found.'\n )\n }\n\n const transactionRequestData = await getTransactionRequestData(\n step,\n executionOptions\n )\n\n checkWallet(step)\n\n const { signedTxXdr } = await wallet.signTransaction(\n transactionRequestData,\n {\n address: wallet.address,\n networkPassphrase,\n }\n )\n\n // Recorded before the network ever sees the envelope, so a crash between\n // submit and confirmation resumes by polling for this hash rather than\n // re-signing and executing the swap twice. StellarStepExecutor.createPipeline\n // relies on this ordering for its resume entry point.\n const transactionHash = deriveTransactionHash(\n signedTxXdr,\n networkPassphrase\n )\n\n statusManager.updateAction(step, action.type, 'PENDING', {\n txHash: transactionHash,\n txLink: getStellarTxLink(fromChain, transactionHash),\n txHex: signedTxXdr,\n signedAt: Date.now(),\n })\n\n await submitStellarTransaction(client, signedTxXdr, networkPassphrase)\n\n return { status: 'COMPLETED', context: { transactionHash } }\n }\n}\n"],"mappings":"
|
|
1
|
+
{"version":3,"file":"StellarSignAndExecuteTask.js","names":[],"sources":["../../../../src/core/tasks/StellarSignAndExecuteTask.ts"],"sourcesContent":["import {\n assertNoOpenTransaction,\n BaseStepExecutionTask,\n CLEARED_TRANSACTION_FIELDS,\n getTransactionRequestData,\n LiFiErrorCode,\n type TaskResult,\n TransactionError,\n} from '@lifi/sdk'\nimport type { StellarStepExecutorContext } from '../../types.js'\nimport { classifySubmitFailure } from './helpers/classifySubmitFailure.js'\nimport { deriveTransactionHash } from './helpers/deriveTransactionHash.js'\nimport { getStellarTxLink } from './helpers/getStellarTxLink.js'\nimport { submitStellarTransaction } from './helpers/submitStellarTransaction.js'\n\nexport class StellarSignAndExecuteTask extends BaseStepExecutionTask {\n async run(context: StellarStepExecutorContext): Promise<TaskResult> {\n const {\n step,\n client,\n wallet,\n fromChain,\n statusManager,\n executionOptions,\n networkPassphrase,\n isBridgeExecution,\n checkWallet,\n } = context\n\n const action = statusManager.findAction(\n step,\n isBridgeExecution ? 'CROSS_CHAIN' : 'SWAP'\n )\n\n if (!action) {\n throw new TransactionError(\n LiFiErrorCode.TransactionUnprepared,\n 'Unable to prepare transaction. Action not found.'\n )\n }\n\n // Defence in depth: the selector never routes an open transaction here,\n // and signing again could execute the swap twice.\n assertNoOpenTransaction(action)\n\n const transactionRequestData = await getTransactionRequestData(\n step,\n executionOptions\n )\n\n checkWallet(step)\n\n // Checked again right before the wallet: a late write of an older run\n // can merge its transaction into this action during the await above.\n assertNoOpenTransaction(statusManager.findAction(step, action.type))\n\n const { signedTxXdr } = await wallet.signTransaction(\n transactionRequestData,\n {\n address: wallet.address,\n networkPassphrase,\n }\n )\n\n // Checked once more after the wallet: a stopped run's late write can\n // merge its transaction into this action while the prompt is open.\n // Nothing awaits from here to the write below.\n assertNoOpenTransaction(statusManager.findAction(step, action.type))\n\n // Recorded before the network ever sees the envelope, so a crash between\n // submit and confirmation resumes by polling for this hash rather than\n // re-signing and executing the swap twice. StellarStepExecutor.createPipeline\n // relies on this ordering for its resume entry point.\n const transactionHash = deriveTransactionHash(\n signedTxXdr,\n networkPassphrase\n )\n\n statusManager.updateAction(step, action.type, 'PENDING', {\n // A new transaction: nothing of the previous one may survive, least of\n // all its `txFinal` verdict.\n ...CLEARED_TRANSACTION_FIELDS,\n txHash: transactionHash,\n txLink: getStellarTxLink(fromChain, transactionHash),\n txHex: signedTxXdr,\n signedAt: Date.now(),\n })\n\n try {\n await submitStellarTransaction(client, signedTxXdr, networkPassphrase)\n } catch (error) {\n // A rejection is final only with a chain proof that the envelope was never\n // applied and can no longer be, and when the LI.FI status API does not\n // know the hash. On the first run the envelope has usually not expired\n // yet, so the outcome stays unknown and a resume checks it again.\n throw await classifySubmitFailure(\n { client, step, transactionHash, signedTxXdr, networkPassphrase },\n error\n )\n }\n\n return { status: 'COMPLETED', context: { transactionHash } }\n }\n}\n"],"mappings":";;;;;;AAeA,IAAa,4BAAb,cAA+C,sBAAsB;CACnE,MAAM,IAAI,SAA0D;EAClE,MAAM,EACJ,MACA,QACA,QACA,WACA,eACA,kBACA,mBACA,mBACA,gBACE;EAEJ,MAAM,SAAS,cAAc,WAC3B,MACA,oBAAoB,gBAAgB,MACtC;EAEA,IAAI,CAAC,QACH,MAAM,IAAI,iBACR,cAAc,uBACd,kDACF;EAKF,wBAAwB,MAAM;EAE9B,MAAM,yBAAyB,MAAM,0BACnC,MACA,gBACF;EAEA,YAAY,IAAI;EAIhB,wBAAwB,cAAc,WAAW,MAAM,OAAO,IAAI,CAAC;EAEnE,MAAM,EAAE,gBAAgB,MAAM,OAAO,gBACnC,wBACA;GACE,SAAS,OAAO;GAChB;EACF,CACF;EAKA,wBAAwB,cAAc,WAAW,MAAM,OAAO,IAAI,CAAC;EAMnE,MAAM,kBAAkB,sBACtB,aACA,iBACF;EAEA,cAAc,aAAa,MAAM,OAAO,MAAM,WAAW;GAGvD,GAAG;GACH,QAAQ;GACR,QAAQ,iBAAiB,WAAW,eAAe;GACnD,OAAO;GACP,UAAU,KAAK,IAAI;EACrB,CAAC;EAED,IAAI;GACF,MAAM,yBAAyB,QAAQ,aAAa,iBAAiB;EACvE,SAAS,OAAO;GAKd,MAAM,MAAM,sBACV;IAAE;IAAQ;IAAM;IAAiB;IAAa;GAAkB,GAChE,KACF;EACF;EAEA,OAAO;GAAE,QAAQ;GAAa,SAAS,EAAE,gBAAgB;EAAE;CAC7D;AACF"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"StellarWaitForTransactionTask.d.ts","names":[],"sources":["../../../../src/core/tasks/StellarWaitForTransactionTask.ts"],"mappings":";;;
|
|
1
|
+
{"version":3,"file":"StellarWaitForTransactionTask.d.ts","names":[],"sources":["../../../../src/core/tasks/StellarWaitForTransactionTask.ts"],"mappings":";;;qBAca,sCAAsC;EACjD,IAAU,SAAS,6BAA6B,QAAQ"}
|
|
@@ -1,5 +1,7 @@
|
|
|
1
|
+
import { deriveTransactionHash } from "./helpers/deriveTransactionHash.js";
|
|
1
2
|
import { submitStellarTransaction } from "./helpers/submitStellarTransaction.js";
|
|
2
3
|
import { waitForStellarTransaction } from "./helpers/waitForStellarTransaction.js";
|
|
4
|
+
import { classifySubmitFailure } from "./helpers/classifySubmitFailure.js";
|
|
3
5
|
import { probeStellarTransaction } from "./helpers/probeStellarTransaction.js";
|
|
4
6
|
import { BaseError, BaseStepExecutionTask, LiFiErrorCode, TransactionError } from "@lifi/sdk";
|
|
5
7
|
//#region src/core/tasks/StellarWaitForTransactionTask.ts
|
|
@@ -11,7 +13,7 @@ var StellarWaitForTransactionTask = class extends BaseStepExecutionTask {
|
|
|
11
13
|
const hash = transactionHash ?? action.txHash;
|
|
12
14
|
if (!hash) throw new TransactionError(LiFiErrorCode.TransactionUnprepared, "Unable to wait for transaction. Transaction hash is not found.");
|
|
13
15
|
let resubmitError;
|
|
14
|
-
if (!transactionHash && action.txHex) {
|
|
16
|
+
if (!transactionHash && action.txHex && !isOtherTransaction(action.txHex, networkPassphrase, hash)) {
|
|
15
17
|
const probe = await probeStellarTransaction(client, hash);
|
|
16
18
|
if (probe !== "landed") try {
|
|
17
19
|
await submitStellarTransaction(client, action.txHex, networkPassphrase);
|
|
@@ -22,13 +24,33 @@ var StellarWaitForTransactionTask = class extends BaseStepExecutionTask {
|
|
|
22
24
|
try {
|
|
23
25
|
await waitForStellarTransaction(client, hash, pollingIntervalMs);
|
|
24
26
|
} catch (error) {
|
|
25
|
-
if (resubmitError && error instanceof BaseError && error.code === LiFiErrorCode.Timeout) throw
|
|
27
|
+
if (resubmitError && action.txHex && error instanceof BaseError && error.code === LiFiErrorCode.Timeout) throw await classifySubmitFailure({
|
|
28
|
+
client,
|
|
29
|
+
step,
|
|
30
|
+
transactionHash: hash,
|
|
31
|
+
signedTxXdr: action.txHex,
|
|
32
|
+
networkPassphrase
|
|
33
|
+
}, resubmitError);
|
|
26
34
|
throw error;
|
|
27
35
|
}
|
|
28
36
|
if (isBridgeExecution) statusManager.updateAction(step, action.type, "DONE");
|
|
29
37
|
return { status: "COMPLETED" };
|
|
30
38
|
}
|
|
31
39
|
};
|
|
40
|
+
/**
|
|
41
|
+
* True when the stored envelope decodes to a transaction other than `hash`.
|
|
42
|
+
* An envelope that does not decode has no hash to compare, and it can never
|
|
43
|
+
* be submitted either.
|
|
44
|
+
*/
|
|
45
|
+
function isOtherTransaction(signedTxXdr, networkPassphrase, hash) {
|
|
46
|
+
let derived;
|
|
47
|
+
try {
|
|
48
|
+
derived = deriveTransactionHash(signedTxXdr, networkPassphrase);
|
|
49
|
+
} catch {
|
|
50
|
+
return false;
|
|
51
|
+
}
|
|
52
|
+
return derived !== hash;
|
|
53
|
+
}
|
|
32
54
|
//#endregion
|
|
33
55
|
export { StellarWaitForTransactionTask };
|
|
34
56
|
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"StellarWaitForTransactionTask.js","names":[],"sources":["../../../../src/core/tasks/StellarWaitForTransactionTask.ts"],"sourcesContent":["import {\n BaseError,\n BaseStepExecutionTask,\n LiFiErrorCode,\n type TaskResult,\n TransactionError,\n} from '@lifi/sdk'\nimport type { StellarStepExecutorContext } from '../../types.js'\nimport { probeStellarTransaction } from './helpers/probeStellarTransaction.js'\nimport { submitStellarTransaction } from './helpers/submitStellarTransaction.js'\nimport { waitForStellarTransaction } from './helpers/waitForStellarTransaction.js'\n\nexport class StellarWaitForTransactionTask extends BaseStepExecutionTask {\n async run(context: StellarStepExecutorContext): Promise<TaskResult> {\n const {\n step,\n client,\n statusManager,\n isBridgeExecution,\n networkPassphrase,\n pollingIntervalMs,\n transactionHash,\n } = context\n\n const action = statusManager.findAction(\n step,\n isBridgeExecution ? 'CROSS_CHAIN' : 'SWAP'\n )\n\n if (!action) {\n throw new TransactionError(\n LiFiErrorCode.TransactionUnprepared,\n 'Unable to prepare transaction. Action not found.'\n )\n }\n\n // On a resumed route the signing task didn't run, so fall back to the hash\n // and envelope it persisted on the action. This is the entry point\n // StellarStepExecutor.createPipeline resumes to when a step was signed but\n // never confirmed.\n const hash = transactionHash ?? action.txHash\n\n if (!hash) {\n throw new TransactionError(\n LiFiErrorCode.TransactionUnprepared,\n 'Unable to wait for transaction. Transaction hash is not found.'\n )\n }\n\n // Resuming: the hash is persisted before submission, so the envelope may\n // never have reached the network — but it may equally have been applied\n // already, in which case its sequence number is spent and re-submitting can\n // only fail. Ask the network first, and let the poll below decide the\n // outcome either way.\n let resubmitError: unknown\n if (!transactionHash
|
|
1
|
+
{"version":3,"file":"StellarWaitForTransactionTask.js","names":[],"sources":["../../../../src/core/tasks/StellarWaitForTransactionTask.ts"],"sourcesContent":["import {\n BaseError,\n BaseStepExecutionTask,\n LiFiErrorCode,\n type TaskResult,\n TransactionError,\n} from '@lifi/sdk'\nimport type { StellarStepExecutorContext } from '../../types.js'\nimport { classifySubmitFailure } from './helpers/classifySubmitFailure.js'\nimport { deriveTransactionHash } from './helpers/deriveTransactionHash.js'\nimport { probeStellarTransaction } from './helpers/probeStellarTransaction.js'\nimport { submitStellarTransaction } from './helpers/submitStellarTransaction.js'\nimport { waitForStellarTransaction } from './helpers/waitForStellarTransaction.js'\n\nexport class StellarWaitForTransactionTask extends BaseStepExecutionTask {\n async run(context: StellarStepExecutorContext): Promise<TaskResult> {\n const {\n step,\n client,\n statusManager,\n isBridgeExecution,\n networkPassphrase,\n pollingIntervalMs,\n transactionHash,\n } = context\n\n const action = statusManager.findAction(\n step,\n isBridgeExecution ? 'CROSS_CHAIN' : 'SWAP'\n )\n\n if (!action) {\n throw new TransactionError(\n LiFiErrorCode.TransactionUnprepared,\n 'Unable to prepare transaction. Action not found.'\n )\n }\n\n // On a resumed route the signing task didn't run, so fall back to the hash\n // and envelope it persisted on the action. This is the entry point\n // StellarStepExecutor.createPipeline resumes to when a step was signed but\n // never confirmed.\n const hash = transactionHash ?? action.txHash\n\n if (!hash) {\n throw new TransactionError(\n LiFiErrorCode.TransactionUnprepared,\n 'Unable to wait for transaction. Transaction hash is not found.'\n )\n }\n\n // Resuming: the hash is persisted before submission, so the envelope may\n // never have reached the network — but it may equally have been applied\n // already, in which case its sequence number is spent and re-submitting can\n // only fail. Ask the network first, and let the poll below decide the\n // outcome either way.\n //\n // A stored envelope that hashes to another value than the stored hash\n // (damaged storage) proves nothing about that transaction, and it may have\n // been sent. Then the SDK neither submits nor classifies a failure; it only\n // polls by the hash, and the outcome stays unknown.\n let resubmitError: unknown\n if (\n !transactionHash &&\n action.txHex &&\n !isOtherTransaction(action.txHex, networkPassphrase, hash)\n ) {\n const probe = await probeStellarTransaction(client, hash)\n if (probe !== 'landed') {\n try {\n await submitStellarTransaction(\n client,\n action.txHex,\n networkPassphrase\n )\n } catch (error) {\n // Keep it only when the probe was definite. After a failed probe this\n // may be a txBAD_SEQ from a swap that in fact settled.\n resubmitError = probe === 'not-found' ? error : undefined\n }\n }\n }\n\n try {\n await waitForStellarTransaction(client, hash, pollingIntervalMs)\n } catch (error) {\n // The envelope never reached the network, and the poll can only report\n // that as a timeout. The submission error says why. It becomes final only\n // with a chain proof that the envelope was never applied and when the\n // LI.FI status API does not know the hash.\n if (\n resubmitError &&\n action.txHex &&\n error instanceof BaseError &&\n error.code === LiFiErrorCode.Timeout\n ) {\n throw await classifySubmitFailure(\n {\n client,\n step,\n transactionHash: hash,\n signedTxXdr: action.txHex,\n networkPassphrase,\n },\n resubmitError\n )\n }\n throw error\n }\n\n if (isBridgeExecution) {\n statusManager.updateAction(step, action.type, 'DONE')\n }\n\n return { status: 'COMPLETED' }\n }\n}\n\n/**\n * True when the stored envelope decodes to a transaction other than `hash`.\n * An envelope that does not decode has no hash to compare, and it can never\n * be submitted either.\n */\nfunction isOtherTransaction(\n signedTxXdr: string,\n networkPassphrase: string,\n hash: string\n): boolean {\n let derived: string\n try {\n derived = deriveTransactionHash(signedTxXdr, networkPassphrase)\n } catch {\n return false\n }\n return derived !== hash\n}\n"],"mappings":";;;;;;;AAcA,IAAa,gCAAb,cAAmD,sBAAsB;CACvE,MAAM,IAAI,SAA0D;EAClE,MAAM,EACJ,MACA,QACA,eACA,mBACA,mBACA,mBACA,oBACE;EAEJ,MAAM,SAAS,cAAc,WAC3B,MACA,oBAAoB,gBAAgB,MACtC;EAEA,IAAI,CAAC,QACH,MAAM,IAAI,iBACR,cAAc,uBACd,kDACF;EAOF,MAAM,OAAO,mBAAmB,OAAO;EAEvC,IAAI,CAAC,MACH,MAAM,IAAI,iBACR,cAAc,uBACd,gEACF;EAaF,IAAI;EACJ,IACE,CAAC,mBACD,OAAO,SACP,CAAC,mBAAmB,OAAO,OAAO,mBAAmB,IAAI,GACzD;GACA,MAAM,QAAQ,MAAM,wBAAwB,QAAQ,IAAI;GACxD,IAAI,UAAU,UACZ,IAAI;IACF,MAAM,yBACJ,QACA,OAAO,OACP,iBACF;GACF,SAAS,OAAO;IAGd,gBAAgB,UAAU,cAAc,QAAQ,KAAA;GAClD;EAEJ;EAEA,IAAI;GACF,MAAM,0BAA0B,QAAQ,MAAM,iBAAiB;EACjE,SAAS,OAAO;GAKd,IACE,iBACA,OAAO,SACP,iBAAiB,aACjB,MAAM,SAAS,cAAc,SAE7B,MAAM,MAAM,sBACV;IACE;IACA;IACA,iBAAiB;IACjB,aAAa,OAAO;IACpB;GACF,GACA,aACF;GAEF,MAAM;EACR;EAEA,IAAI,mBACF,cAAc,aAAa,MAAM,OAAO,MAAM,MAAM;EAGtD,OAAO,EAAE,QAAQ,YAAY;CAC/B;AACF;;;;;;AAOA,SAAS,mBACP,aACA,mBACA,MACS;CACT,IAAI;CACJ,IAAI;EACF,UAAU,sBAAsB,aAAa,iBAAiB;CAChE,QAAQ;EACN,OAAO;CACT;CACA,OAAO,YAAY;AACrB"}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { LiFiStepExtended, SDKClient } from "@lifi/sdk";
|
|
2
|
+
//#region src/core/tasks/helpers/classifySubmitFailure.d.ts
|
|
3
|
+
export interface StellarSubmitFailureContext {
|
|
4
|
+
client: SDKClient;
|
|
5
|
+
step: LiFiStepExtended;
|
|
6
|
+
/** Hash of the signed envelope, persisted before the submit. */
|
|
7
|
+
transactionHash: string;
|
|
8
|
+
/** The signed envelope (base64 XDR) that was submitted. */
|
|
9
|
+
signedTxXdr: string;
|
|
10
|
+
networkPassphrase: string;
|
|
11
|
+
}
|
|
12
|
+
/**
|
|
13
|
+
* Decides whether a failed submission is a final outcome, and returns the error
|
|
14
|
+
* to throw (see the resume rules in `transactionState.ts`).
|
|
15
|
+
*
|
|
16
|
+
* Only a rejection can be final: `submitStellarTransaction` throws
|
|
17
|
+
* `TransactionFailed` for a status other than PENDING, DUPLICATE or
|
|
18
|
+
* TRY_AGAIN_LATER. A rejection alone proves nothing, because a failover
|
|
19
|
+
* re-submit of an envelope that was already applied is rejected as well (for
|
|
20
|
+
* example txBAD_SEQ). A rejection is final only when:
|
|
21
|
+
* - a node answers NOT_FOUND in a response that itself covers the whole
|
|
22
|
+
* landing window of the envelope (see {@link proveStellarTransactionAbsent}),
|
|
23
|
+
* so the envelope was never applied and can no longer be; and
|
|
24
|
+
* - the LI.FI status API does not know the hash. That check is a veto only. A
|
|
25
|
+
* miss (HTTP 404 or an error) says nothing.
|
|
26
|
+
*
|
|
27
|
+
* Transport errors, `RateLimitExceeded`, decode errors and every inconclusive
|
|
28
|
+
* check return `error` itself, so the outcome stays unknown and a resume checks
|
|
29
|
+
* again. Code and message never change.
|
|
30
|
+
*/
|
|
31
|
+
export declare const classifySubmitFailure: ({ client, step, transactionHash, signedTxXdr, networkPassphrase }: StellarSubmitFailureContext, error: unknown) => Promise<unknown>;
|
|
32
|
+
//#endregion
|
|
33
|
+
//# sourceMappingURL=classifySubmitFailure.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"classifySubmitFailure.d.ts","names":[],"sources":["../../../../../src/core/tasks/helpers/classifySubmitFailure.ts"],"mappings":";;iBAciB;EACf,QAAQ;EACR,MAAM;;EAEN;;EAEA;EACA;;;;;;;;;;;;;;;;;;;;;qBAgEW,0BAET,QACA,MACA,iBACA,aACA,qBACC,6BACH,mBACC"}
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
import { proveStellarTransactionAbsent } from "./proveStellarTransactionAbsent.js";
|
|
2
|
+
import { CLOCK_SKEW_MARGIN_MS, LiFiErrorCode, TransactionError, isKnownToStatusApi } from "@lifi/sdk";
|
|
3
|
+
import { TransactionBuilder } from "@stellar/stellar-sdk";
|
|
4
|
+
//#region src/core/tasks/helpers/classifySubmitFailure.ts
|
|
5
|
+
/**
|
|
6
|
+
* When the envelope could have been applied, in chain time (unix seconds).
|
|
7
|
+
*
|
|
8
|
+
* The earliest landing time is the envelope's `minTime` when it has one (> 0).
|
|
9
|
+
* Otherwise it is `execution.signedAt - CLOCK_SKEW_MARGIN_MS`: `signedAt` comes
|
|
10
|
+
* from the local clock, and the margin covers its skew against ledger time. The
|
|
11
|
+
* function returns `undefined` when the envelope has no `maxTime` (it never
|
|
12
|
+
* expires), when neither anchor exists, or when the envelope does not decode.
|
|
13
|
+
* In each of these cases absence cannot be proven.
|
|
14
|
+
*/
|
|
15
|
+
const getLandingWindow = (signedTxXdr, networkPassphrase, signedAt) => {
|
|
16
|
+
let timeBounds;
|
|
17
|
+
try {
|
|
18
|
+
timeBounds = TransactionBuilder.fromXdr(signedTxXdr, networkPassphrase).timeBounds;
|
|
19
|
+
} catch {
|
|
20
|
+
return;
|
|
21
|
+
}
|
|
22
|
+
const maxTime = Number(timeBounds?.maxTime ?? 0);
|
|
23
|
+
if (!(maxTime > 0)) return;
|
|
24
|
+
const minTime = Number(timeBounds?.minTime ?? 0);
|
|
25
|
+
if (minTime > 0) return {
|
|
26
|
+
earliest: minTime,
|
|
27
|
+
maxTime
|
|
28
|
+
};
|
|
29
|
+
if (signedAt === void 0) return;
|
|
30
|
+
return {
|
|
31
|
+
earliest: Math.floor((signedAt - CLOCK_SKEW_MARGIN_MS) / 1e3),
|
|
32
|
+
maxTime
|
|
33
|
+
};
|
|
34
|
+
};
|
|
35
|
+
/**
|
|
36
|
+
* Decides whether a failed submission is a final outcome, and returns the error
|
|
37
|
+
* to throw (see the resume rules in `transactionState.ts`).
|
|
38
|
+
*
|
|
39
|
+
* Only a rejection can be final: `submitStellarTransaction` throws
|
|
40
|
+
* `TransactionFailed` for a status other than PENDING, DUPLICATE or
|
|
41
|
+
* TRY_AGAIN_LATER. A rejection alone proves nothing, because a failover
|
|
42
|
+
* re-submit of an envelope that was already applied is rejected as well (for
|
|
43
|
+
* example txBAD_SEQ). A rejection is final only when:
|
|
44
|
+
* - a node answers NOT_FOUND in a response that itself covers the whole
|
|
45
|
+
* landing window of the envelope (see {@link proveStellarTransactionAbsent}),
|
|
46
|
+
* so the envelope was never applied and can no longer be; and
|
|
47
|
+
* - the LI.FI status API does not know the hash. That check is a veto only. A
|
|
48
|
+
* miss (HTTP 404 or an error) says nothing.
|
|
49
|
+
*
|
|
50
|
+
* Transport errors, `RateLimitExceeded`, decode errors and every inconclusive
|
|
51
|
+
* check return `error` itself, so the outcome stays unknown and a resume checks
|
|
52
|
+
* again. Code and message never change.
|
|
53
|
+
*/
|
|
54
|
+
const classifySubmitFailure = async ({ client, step, transactionHash, signedTxXdr, networkPassphrase }, error) => {
|
|
55
|
+
if (!(error instanceof TransactionError) || error.code !== LiFiErrorCode.TransactionFailed) return error;
|
|
56
|
+
const window = getLandingWindow(signedTxXdr, networkPassphrase, step.execution?.signedAt);
|
|
57
|
+
if (!window) return error;
|
|
58
|
+
if (!await proveStellarTransactionAbsent(client, transactionHash, window)) return error;
|
|
59
|
+
if (await isKnownToStatusApi(client, step, transactionHash)) return error;
|
|
60
|
+
return new TransactionError(error.code, error.message, error, { final: true });
|
|
61
|
+
};
|
|
62
|
+
//#endregion
|
|
63
|
+
export { classifySubmitFailure };
|
|
64
|
+
|
|
65
|
+
//# sourceMappingURL=classifySubmitFailure.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"classifySubmitFailure.js","names":[],"sources":["../../../../../src/core/tasks/helpers/classifySubmitFailure.ts"],"sourcesContent":["import {\n CLOCK_SKEW_MARGIN_MS,\n isKnownToStatusApi,\n LiFiErrorCode,\n type LiFiStepExtended,\n type SDKClient,\n TransactionError,\n} from '@lifi/sdk'\nimport { type Transaction, TransactionBuilder } from '@stellar/stellar-sdk'\nimport {\n proveStellarTransactionAbsent,\n type StellarLandingWindow,\n} from './proveStellarTransactionAbsent.js'\n\nexport interface StellarSubmitFailureContext {\n client: SDKClient\n step: LiFiStepExtended\n /** Hash of the signed envelope, persisted before the submit. */\n transactionHash: string\n /** The signed envelope (base64 XDR) that was submitted. */\n signedTxXdr: string\n networkPassphrase: string\n}\n\n/**\n * When the envelope could have been applied, in chain time (unix seconds).\n *\n * The earliest landing time is the envelope's `minTime` when it has one (> 0).\n * Otherwise it is `execution.signedAt - CLOCK_SKEW_MARGIN_MS`: `signedAt` comes\n * from the local clock, and the margin covers its skew against ledger time. The\n * function returns `undefined` when the envelope has no `maxTime` (it never\n * expires), when neither anchor exists, or when the envelope does not decode.\n * In each of these cases absence cannot be proven.\n */\nconst getLandingWindow = (\n signedTxXdr: string,\n networkPassphrase: string,\n signedAt: number | undefined\n): StellarLandingWindow | undefined => {\n let timeBounds: Transaction['timeBounds']\n try {\n timeBounds = (\n TransactionBuilder.fromXdr(signedTxXdr, networkPassphrase) as Transaction\n ).timeBounds\n } catch {\n return undefined\n }\n\n const maxTime = Number(timeBounds?.maxTime ?? 0)\n if (!(maxTime > 0)) {\n return undefined\n }\n\n const minTime = Number(timeBounds?.minTime ?? 0)\n if (minTime > 0) {\n return { earliest: minTime, maxTime }\n }\n if (signedAt === undefined) {\n return undefined\n }\n return {\n earliest: Math.floor((signedAt - CLOCK_SKEW_MARGIN_MS) / 1000),\n maxTime,\n }\n}\n\n/**\n * Decides whether a failed submission is a final outcome, and returns the error\n * to throw (see the resume rules in `transactionState.ts`).\n *\n * Only a rejection can be final: `submitStellarTransaction` throws\n * `TransactionFailed` for a status other than PENDING, DUPLICATE or\n * TRY_AGAIN_LATER. A rejection alone proves nothing, because a failover\n * re-submit of an envelope that was already applied is rejected as well (for\n * example txBAD_SEQ). A rejection is final only when:\n * - a node answers NOT_FOUND in a response that itself covers the whole\n * landing window of the envelope (see {@link proveStellarTransactionAbsent}),\n * so the envelope was never applied and can no longer be; and\n * - the LI.FI status API does not know the hash. That check is a veto only. A\n * miss (HTTP 404 or an error) says nothing.\n *\n * Transport errors, `RateLimitExceeded`, decode errors and every inconclusive\n * check return `error` itself, so the outcome stays unknown and a resume checks\n * again. Code and message never change.\n */\nexport const classifySubmitFailure = async (\n {\n client,\n step,\n transactionHash,\n signedTxXdr,\n networkPassphrase,\n }: StellarSubmitFailureContext,\n error: unknown\n): Promise<unknown> => {\n if (\n !(error instanceof TransactionError) ||\n error.code !== LiFiErrorCode.TransactionFailed\n ) {\n return error\n }\n\n const window = getLandingWindow(\n signedTxXdr,\n networkPassphrase,\n step.execution?.signedAt\n )\n if (!window) {\n return error\n }\n\n if (!(await proveStellarTransactionAbsent(client, transactionHash, window))) {\n return error\n }\n\n if (await isKnownToStatusApi(client, step, transactionHash)) {\n return error\n }\n\n return new TransactionError(error.code, error.message, error, {\n final: true,\n })\n}\n"],"mappings":";;;;;;;;;;;;;;AAkCA,MAAM,oBACJ,aACA,mBACA,aACqC;CACrC,IAAI;CACJ,IAAI;EACF,aACE,mBAAmB,QAAQ,aAAa,iBAAiB,CAAC,CAC1D;CACJ,QAAQ;EACN;CACF;CAEA,MAAM,UAAU,OAAO,YAAY,WAAW,CAAC;CAC/C,IAAI,EAAE,UAAU,IACd;CAGF,MAAM,UAAU,OAAO,YAAY,WAAW,CAAC;CAC/C,IAAI,UAAU,GACZ,OAAO;EAAE,UAAU;EAAS;CAAQ;CAEtC,IAAI,aAAa,KAAA,GACf;CAEF,OAAO;EACL,UAAU,KAAK,OAAO,WAAW,wBAAwB,GAAI;EAC7D;CACF;AACF;;;;;;;;;;;;;;;;;;;;AAqBA,MAAa,wBAAwB,OACnC,EACE,QACA,MACA,iBACA,aACA,qBAEF,UACqB;CACrB,IACE,EAAE,iBAAiB,qBACnB,MAAM,SAAS,cAAc,mBAE7B,OAAO;CAGT,MAAM,SAAS,iBACb,aACA,mBACA,KAAK,WAAW,QAClB;CACA,IAAI,CAAC,QACH,OAAO;CAGT,IAAI,CAAE,MAAM,8BAA8B,QAAQ,iBAAiB,MAAM,GACvE,OAAO;CAGT,IAAI,MAAM,mBAAmB,QAAQ,MAAM,eAAe,GACxD,OAAO;CAGT,OAAO,IAAI,iBAAiB,MAAM,MAAM,MAAM,SAAS,OAAO,EAC5D,OAAO,KACT,CAAC;AACH"}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { SDKClient } from "@lifi/sdk";
|
|
2
|
+
//#region src/core/tasks/helpers/proveStellarTransactionAbsent.d.ts
|
|
3
|
+
/** When the transaction could have been applied, in unix seconds (chain time). */
|
|
4
|
+
export interface StellarLandingWindow {
|
|
5
|
+
/** Earliest time the transaction could have been applied (the anchor). */
|
|
6
|
+
earliest: number;
|
|
7
|
+
/** The envelope's `maxTime`: no ledger that closes later can include it. */
|
|
8
|
+
maxTime: number;
|
|
9
|
+
}
|
|
10
|
+
/**
|
|
11
|
+
* True only when the chain proves that the transaction was never applied.
|
|
12
|
+
*
|
|
13
|
+
* Every configured RPC is asked once. A NOT_FOUND counts only when the same
|
|
14
|
+
* response proves that its node would know the transaction: the node's history
|
|
15
|
+
* starts before `window.earliest` (`oldestLedgerCloseTime`), and its latest
|
|
16
|
+
* ledger closed after `window.maxTime` plus a margin (`latestLedgerCloseTime`).
|
|
17
|
+
* A separate `getHealth` or `getLatestLedger` request would prove nothing,
|
|
18
|
+
* because a URL can be a load-balanced pool of different backends.
|
|
19
|
+
*
|
|
20
|
+
* A node that returns the transaction (SUCCESS or FAILED) makes the answer
|
|
21
|
+
* false. A failed request, a request without an answer within
|
|
22
|
+
* `LOOKUP_TIMEOUT_MS`, and a NOT_FOUND that does not prove coverage give no
|
|
23
|
+
* information.
|
|
24
|
+
*/
|
|
25
|
+
export declare const proveStellarTransactionAbsent: (client: SDKClient, transactionHash: string, window: StellarLandingWindow) => Promise<boolean>;
|
|
26
|
+
//#endregion
|
|
27
|
+
//# sourceMappingURL=proveStellarTransactionAbsent.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"proveStellarTransactionAbsent.d.ts","names":[],"sources":["../../../../../src/core/tasks/helpers/proveStellarTransactionAbsent.ts"],"mappings":";;;iBAoBiB;;EAEf;;EAEA;;;;;;;;;;;;;;;;;qBAkBW,gCACX,QAAQ,WACR,yBACA,QAAQ,yBACP"}
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
import { getStellarRpcs } from "../../../client/getStellarRpc.js";
|
|
2
|
+
import { withTimeout } from "@lifi/sdk";
|
|
3
|
+
import { Api } from "@stellar/stellar-sdk/rpc";
|
|
4
|
+
//#region src/core/tasks/helpers/proveStellarTransactionAbsent.ts
|
|
5
|
+
/**
|
|
6
|
+
* A node's latest ledger must have closed this long after the envelope's
|
|
7
|
+
* `maxTime` before its NOT_FOUND counts. Close times only grow, so every ledger
|
|
8
|
+
* that could still include the envelope is then in that node's history. Five
|
|
9
|
+
* or six ledgers of slack.
|
|
10
|
+
*/
|
|
11
|
+
const HEAD_MARGIN_SECONDS = 30;
|
|
12
|
+
/**
|
|
13
|
+
* The time each RPC has to answer. stellar-sdk sets no request timeout, so a
|
|
14
|
+
* node that accepts the request and never answers would hold the route. A
|
|
15
|
+
* timeout counts as a failed request: it gives no information.
|
|
16
|
+
*/
|
|
17
|
+
const LOOKUP_TIMEOUT_MS = 1e4;
|
|
18
|
+
/**
|
|
19
|
+
* True only when the chain proves that the transaction was never applied.
|
|
20
|
+
*
|
|
21
|
+
* Every configured RPC is asked once. A NOT_FOUND counts only when the same
|
|
22
|
+
* response proves that its node would know the transaction: the node's history
|
|
23
|
+
* starts before `window.earliest` (`oldestLedgerCloseTime`), and its latest
|
|
24
|
+
* ledger closed after `window.maxTime` plus a margin (`latestLedgerCloseTime`).
|
|
25
|
+
* A separate `getHealth` or `getLatestLedger` request would prove nothing,
|
|
26
|
+
* because a URL can be a load-balanced pool of different backends.
|
|
27
|
+
*
|
|
28
|
+
* A node that returns the transaction (SUCCESS or FAILED) makes the answer
|
|
29
|
+
* false. A failed request, a request without an answer within
|
|
30
|
+
* `LOOKUP_TIMEOUT_MS`, and a NOT_FOUND that does not prove coverage give no
|
|
31
|
+
* information.
|
|
32
|
+
*/
|
|
33
|
+
const proveStellarTransactionAbsent = async (client, transactionHash, window) => {
|
|
34
|
+
let servers;
|
|
35
|
+
try {
|
|
36
|
+
servers = await getStellarRpcs(client);
|
|
37
|
+
} catch {
|
|
38
|
+
return false;
|
|
39
|
+
}
|
|
40
|
+
const results = await Promise.allSettled(servers.map((server) => withTimeout(() => server.getTransaction(transactionHash), { timeout: LOOKUP_TIMEOUT_MS })));
|
|
41
|
+
let provenAbsent = false;
|
|
42
|
+
for (const result of results) {
|
|
43
|
+
if (result.status === "rejected") continue;
|
|
44
|
+
const response = result.value;
|
|
45
|
+
if (response.status !== Api.GetTransactionStatus.NOT_FOUND) return false;
|
|
46
|
+
const oldest = Number(response.oldestLedgerCloseTime);
|
|
47
|
+
const latest = Number(response.latestLedgerCloseTime);
|
|
48
|
+
if (Number.isFinite(oldest) && Number.isFinite(latest) && oldest > 0 && oldest < window.earliest && latest > window.maxTime + HEAD_MARGIN_SECONDS) provenAbsent = true;
|
|
49
|
+
}
|
|
50
|
+
return provenAbsent;
|
|
51
|
+
};
|
|
52
|
+
//#endregion
|
|
53
|
+
export { proveStellarTransactionAbsent };
|
|
54
|
+
|
|
55
|
+
//# sourceMappingURL=proveStellarTransactionAbsent.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"proveStellarTransactionAbsent.js","names":[],"sources":["../../../../../src/core/tasks/helpers/proveStellarTransactionAbsent.ts"],"sourcesContent":["import { type SDKClient, withTimeout } from '@lifi/sdk'\nimport { Api, type Server } from '@stellar/stellar-sdk/rpc'\nimport { getStellarRpcs } from '../../../client/getStellarRpc.js'\n\n/**\n * A node's latest ledger must have closed this long after the envelope's\n * `maxTime` before its NOT_FOUND counts. Close times only grow, so every ledger\n * that could still include the envelope is then in that node's history. Five\n * or six ledgers of slack.\n */\nconst HEAD_MARGIN_SECONDS = 30\n\n/**\n * The time each RPC has to answer. stellar-sdk sets no request timeout, so a\n * node that accepts the request and never answers would hold the route. A\n * timeout counts as a failed request: it gives no information.\n */\nconst LOOKUP_TIMEOUT_MS = 10_000\n\n/** When the transaction could have been applied, in unix seconds (chain time). */\nexport interface StellarLandingWindow {\n /** Earliest time the transaction could have been applied (the anchor). */\n earliest: number\n /** The envelope's `maxTime`: no ledger that closes later can include it. */\n maxTime: number\n}\n\n/**\n * True only when the chain proves that the transaction was never applied.\n *\n * Every configured RPC is asked once. A NOT_FOUND counts only when the same\n * response proves that its node would know the transaction: the node's history\n * starts before `window.earliest` (`oldestLedgerCloseTime`), and its latest\n * ledger closed after `window.maxTime` plus a margin (`latestLedgerCloseTime`).\n * A separate `getHealth` or `getLatestLedger` request would prove nothing,\n * because a URL can be a load-balanced pool of different backends.\n *\n * A node that returns the transaction (SUCCESS or FAILED) makes the answer\n * false. A failed request, a request without an answer within\n * `LOOKUP_TIMEOUT_MS`, and a NOT_FOUND that does not prove coverage give no\n * information.\n */\nexport const proveStellarTransactionAbsent = async (\n client: SDKClient,\n transactionHash: string,\n window: StellarLandingWindow\n): Promise<boolean> => {\n let servers: Server[]\n try {\n servers = await getStellarRpcs(client)\n } catch {\n return false\n }\n\n // `getTransaction` takes no abort signal, so the deadline only races it.\n const results = await Promise.allSettled(\n servers.map((server) =>\n withTimeout(() => server.getTransaction(transactionHash), {\n timeout: LOOKUP_TIMEOUT_MS,\n })\n )\n )\n\n let provenAbsent = false\n for (const result of results) {\n if (result.status === 'rejected') {\n continue\n }\n const response = result.value\n if (response.status !== Api.GetTransactionStatus.NOT_FOUND) {\n return false\n }\n // Unix seconds. The SDK types say number, but the SDK passes the raw JSON\n // value through, so `Number` also accepts a string. `Number(null)` and\n // `Number('')` are 0, which is before every anchor, so only a positive\n // close time counts as the start of the node's history.\n const oldest = Number(response.oldestLedgerCloseTime)\n const latest = Number(response.latestLedgerCloseTime)\n if (\n Number.isFinite(oldest) &&\n Number.isFinite(latest) &&\n oldest > 0 &&\n oldest < window.earliest &&\n latest > window.maxTime + HEAD_MARGIN_SECONDS\n ) {\n provenAbsent = true\n }\n }\n return provenAbsent\n}\n"],"mappings":";;;;;;;;;;AAUA,MAAM,sBAAsB;;;;;;AAO5B,MAAM,oBAAoB;;;;;;;;;;;;;;;;AAyB1B,MAAa,gCAAgC,OAC3C,QACA,iBACA,WACqB;CACrB,IAAI;CACJ,IAAI;EACF,UAAU,MAAM,eAAe,MAAM;CACvC,QAAQ;EACN,OAAO;CACT;CAGA,MAAM,UAAU,MAAM,QAAQ,WAC5B,QAAQ,KAAK,WACX,kBAAkB,OAAO,eAAe,eAAe,GAAG,EACxD,SAAS,kBACX,CAAC,CACH,CACF;CAEA,IAAI,eAAe;CACnB,KAAK,MAAM,UAAU,SAAS;EAC5B,IAAI,OAAO,WAAW,YACpB;EAEF,MAAM,WAAW,OAAO;EACxB,IAAI,SAAS,WAAW,IAAI,qBAAqB,WAC/C,OAAO;EAMT,MAAM,SAAS,OAAO,SAAS,qBAAqB;EACpD,MAAM,SAAS,OAAO,SAAS,qBAAqB;EACpD,IACE,OAAO,SAAS,MAAM,KACtB,OAAO,SAAS,MAAM,KACtB,SAAS,KACT,SAAS,OAAO,YAChB,SAAS,OAAO,UAAU,qBAE1B,eAAe;CAEnB;CACA,OAAO;AACT"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"waitForStellarTransaction.d.ts","names":[],"sources":["../../../../../src/core/tasks/helpers/waitForStellarTransaction.ts"],"mappings":";;;;;;;;;;;;;;;;;;
|
|
1
|
+
{"version":3,"file":"waitForStellarTransaction.d.ts","names":[],"sources":["../../../../../src/core/tasks/helpers/waitForStellarTransaction.ts"],"mappings":";;;;;;;;;;;;;;;;;;qBA+Ba,4BACX,QAAQ,WACR,yBACA,+BACC,QAAQ,IAAI"}
|
|
@@ -4,10 +4,12 @@ import { Api } from "@stellar/stellar-sdk/rpc";
|
|
|
4
4
|
//#region src/core/tasks/helpers/waitForStellarTransaction.ts
|
|
5
5
|
const CONFIRM_POLL_INTERVAL_MS = 3e3;
|
|
6
6
|
/**
|
|
7
|
-
* Outlives the backend's `[0, now + 300 s]` timebounds, so
|
|
8
|
-
*
|
|
9
|
-
*
|
|
10
|
-
*
|
|
7
|
+
* Outlives the backend's `[0, now + 300 s]` timebounds, so the wait normally
|
|
8
|
+
* lasts until the envelope can no longer be applied. A timeout is still not
|
|
9
|
+
* proof that the transaction is dead: the RPC may lag, or its history may not
|
|
10
|
+
* reach the transaction, so the outcome stays unknown. Expressed as a deadline,
|
|
11
|
+
* not an attempt count, so a caller-supplied polling interval cannot shorten
|
|
12
|
+
* the budget.
|
|
11
13
|
*/
|
|
12
14
|
const CONFIRM_TIMEOUT_MS = 33e4;
|
|
13
15
|
/**
|
|
@@ -32,7 +34,7 @@ const waitForStellarTransaction = async (client, transactionHash, pollingInterva
|
|
|
32
34
|
try {
|
|
33
35
|
const response = await callStellarRpcsWithRetry(client, (server) => server.getTransaction(transactionHash));
|
|
34
36
|
if (response.status === Api.GetTransactionStatus.SUCCESS) return response;
|
|
35
|
-
if (response.status === Api.GetTransactionStatus.FAILED) throw new TransactionError(LiFiErrorCode.TransactionFailed, `Stellar transaction ${transactionHash} failed: ${response.resultXdr?.result.type ?? "unknown reason"}
|
|
37
|
+
if (response.status === Api.GetTransactionStatus.FAILED) throw new TransactionError(LiFiErrorCode.TransactionFailed, `Stellar transaction ${transactionHash} failed: ${response.resultXdr?.result.type ?? "unknown reason"}`, void 0, { final: true });
|
|
36
38
|
} catch (error) {
|
|
37
39
|
if (error instanceof TransactionError) throw error;
|
|
38
40
|
lastTransportError = error instanceof Error ? error : new Error(String(error));
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"waitForStellarTransaction.js","names":[],"sources":["../../../../../src/core/tasks/helpers/waitForStellarTransaction.ts"],"sourcesContent":["import { LiFiErrorCode, type SDKClient, TransactionError } from '@lifi/sdk'\nimport { Api } from '@stellar/stellar-sdk/rpc'\nimport { callStellarRpcsWithRetry } from '../../../client/getStellarRpc.js'\n\nconst CONFIRM_POLL_INTERVAL_MS = 3_000\n\n/**\n * Outlives the backend's `[0, now + 300 s]` timebounds, so
|
|
1
|
+
{"version":3,"file":"waitForStellarTransaction.js","names":[],"sources":["../../../../../src/core/tasks/helpers/waitForStellarTransaction.ts"],"sourcesContent":["import { LiFiErrorCode, type SDKClient, TransactionError } from '@lifi/sdk'\nimport { Api } from '@stellar/stellar-sdk/rpc'\nimport { callStellarRpcsWithRetry } from '../../../client/getStellarRpc.js'\n\nconst CONFIRM_POLL_INTERVAL_MS = 3_000\n\n/**\n * Outlives the backend's `[0, now + 300 s]` timebounds, so the wait normally\n * lasts until the envelope can no longer be applied. A timeout is still not\n * proof that the transaction is dead: the RPC may lag, or its history may not\n * reach the transaction, so the outcome stays unknown. Expressed as a deadline,\n * not an attempt count, so a caller-supplied polling interval cannot shorten\n * the budget.\n */\nconst CONFIRM_TIMEOUT_MS = 330_000\n\n/**\n * Polls `getTransaction` until the transaction is included in a ledger.\n *\n * `NOT_FOUND` is not an error — Soroban RPC only knows a transaction once it has\n * been applied — so polling continues until the deadline passes and the result\n * is reported as a timeout rather than a failure.\n *\n * A transport failure costs one interval rather than the whole wait: every RPC\n * can reject one read during a rate-limit burst while the transaction is\n * perfectly healthy. The last such error rides along as the timeout's cause.\n *\n * The terminal classification is deliberately done outside\n * {@link callStellarRpcsWithRetry}; only the read goes through the failover\n * wrapper, which would otherwise wrap a classified error in an `AggregateError`.\n */\nexport const waitForStellarTransaction = async (\n client: SDKClient,\n transactionHash: string,\n pollingIntervalMs: number = CONFIRM_POLL_INTERVAL_MS\n): Promise<Api.GetSuccessfulTransactionResponse> => {\n const deadline = Date.now() + CONFIRM_TIMEOUT_MS\n let lastTransportError: Error | undefined\n\n while (Date.now() < deadline) {\n try {\n const response = await callStellarRpcsWithRetry(client, (server) =>\n server.getTransaction(transactionHash)\n )\n\n if (response.status === Api.GetTransactionStatus.SUCCESS) {\n return response\n }\n\n if (response.status === Api.GetTransactionStatus.FAILED) {\n throw new TransactionError(\n LiFiErrorCode.TransactionFailed,\n `Stellar transaction ${transactionHash} failed: ${\n response.resultXdr?.result.type ?? 'unknown reason'\n }`,\n undefined,\n { final: true }\n )\n }\n } catch (error) {\n // The ledger's verdict is terminal; only transport failures are retried.\n if (error instanceof TransactionError) {\n throw error\n }\n lastTransportError =\n error instanceof Error ? error : new Error(String(error))\n }\n\n await new Promise((resolve) => setTimeout(resolve, pollingIntervalMs))\n }\n\n throw new TransactionError(\n LiFiErrorCode.Timeout,\n `Stellar transaction ${transactionHash} was not confirmed in time.`,\n lastTransportError\n )\n}\n"],"mappings":";;;;AAIA,MAAM,2BAA2B;;;;;;;;;AAUjC,MAAM,qBAAqB;;;;;;;;;;;;;;;;AAiB3B,MAAa,4BAA4B,OACvC,QACA,iBACA,oBAA4B,6BACsB;CAClD,MAAM,WAAW,KAAK,IAAI,IAAI;CAC9B,IAAI;CAEJ,OAAO,KAAK,IAAI,IAAI,UAAU;EAC5B,IAAI;GACF,MAAM,WAAW,MAAM,yBAAyB,SAAS,WACvD,OAAO,eAAe,eAAe,CACvC;GAEA,IAAI,SAAS,WAAW,IAAI,qBAAqB,SAC/C,OAAO;GAGT,IAAI,SAAS,WAAW,IAAI,qBAAqB,QAC/C,MAAM,IAAI,iBACR,cAAc,mBACd,uBAAuB,gBAAgB,WACrC,SAAS,WAAW,OAAO,QAAQ,oBAErC,KAAA,GACA,EAAE,OAAO,KAAK,CAChB;EAEJ,SAAS,OAAO;GAEd,IAAI,iBAAiB,kBACnB,MAAM;GAER,qBACE,iBAAiB,QAAQ,QAAQ,IAAI,MAAM,OAAO,KAAK,CAAC;EAC5D;EAEA,MAAM,IAAI,SAAS,YAAY,WAAW,SAAS,iBAAiB,CAAC;CACvE;CAEA,MAAM,IAAI,iBACR,cAAc,SACd,uBAAuB,gBAAgB,8BACvC,kBACF;AACF"}
|
package/dist/esm/version.d.ts
CHANGED
package/dist/esm/version.js
CHANGED
package/dist/esm/version.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"version.js","names":[],"sources":["../../src/version.ts"],"sourcesContent":["export const name = '@lifi/sdk-provider-stellar'\nexport const version = '4.3.
|
|
1
|
+
{"version":3,"file":"version.js","names":[],"sources":["../../src/version.ts"],"sourcesContent":["export const name = '@lifi/sdk-provider-stellar'\nexport const version = '4.3.8'\n"],"mappings":";AAAA,MAAa,OAAO;AACpB,MAAa,UAAU"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@lifi/sdk-provider-stellar",
|
|
3
|
-
"version": "4.3.
|
|
3
|
+
"version": "4.3.8",
|
|
4
4
|
"description": "LI.FI Stellar SDK Provider for Any-to-Any Cross-Chain-Swap",
|
|
5
5
|
"homepage": "https://github.com/lifinance/sdk",
|
|
6
6
|
"bugs": {
|
|
@@ -28,8 +28,8 @@
|
|
|
28
28
|
"./package.json": "./package.json"
|
|
29
29
|
},
|
|
30
30
|
"dependencies": {
|
|
31
|
-
"@lifi/sdk": "4.
|
|
32
|
-
"@stellar/stellar-sdk": "^17.2.
|
|
31
|
+
"@lifi/sdk": "4.11.0",
|
|
32
|
+
"@stellar/stellar-sdk": "^17.2.1"
|
|
33
33
|
},
|
|
34
34
|
"publishConfig": {
|
|
35
35
|
"access": "public"
|
|
@@ -2,6 +2,7 @@ import {
|
|
|
2
2
|
BaseStepExecutor,
|
|
3
3
|
CheckBalanceTask,
|
|
4
4
|
type ExecutionAction,
|
|
5
|
+
hasOpenTransaction,
|
|
5
6
|
LiFiErrorCode,
|
|
6
7
|
type LiFiStepExtended,
|
|
7
8
|
type SDKError,
|
|
@@ -103,9 +104,11 @@ export class StellarStepExecutor extends BaseStepExecutor {
|
|
|
103
104
|
// envelope was signed and very likely broadcast. Resuming such a step at
|
|
104
105
|
// CheckBalanceTask would re-prepare, re-sign and submit a SECOND
|
|
105
106
|
// transaction — executing the swap twice. Resume at the confirmation poll
|
|
106
|
-
// instead and let the already-broadcast transaction settle.
|
|
107
|
-
|
|
108
|
-
|
|
107
|
+
// instead and let the already-broadcast transaction settle. Only a FAILED
|
|
108
|
+
// action with a final outcome (`txFinal`) signs again; this is the same
|
|
109
|
+
// predicate as the pre-sign guard.
|
|
110
|
+
const firstTask = hasOpenTransaction(swapOrBridgeAction)
|
|
111
|
+
? swapOrBridgeAction?.status === 'DONE'
|
|
109
112
|
? WaitForTransactionStatusTask
|
|
110
113
|
: StellarWaitForTransactionTask
|
|
111
114
|
: CheckBalanceTask
|
|
@@ -1,11 +1,14 @@
|
|
|
1
1
|
import {
|
|
2
|
+
assertNoOpenTransaction,
|
|
2
3
|
BaseStepExecutionTask,
|
|
4
|
+
CLEARED_TRANSACTION_FIELDS,
|
|
3
5
|
getTransactionRequestData,
|
|
4
6
|
LiFiErrorCode,
|
|
5
7
|
type TaskResult,
|
|
6
8
|
TransactionError,
|
|
7
9
|
} from '@lifi/sdk'
|
|
8
10
|
import type { StellarStepExecutorContext } from '../../types.js'
|
|
11
|
+
import { classifySubmitFailure } from './helpers/classifySubmitFailure.js'
|
|
9
12
|
import { deriveTransactionHash } from './helpers/deriveTransactionHash.js'
|
|
10
13
|
import { getStellarTxLink } from './helpers/getStellarTxLink.js'
|
|
11
14
|
import { submitStellarTransaction } from './helpers/submitStellarTransaction.js'
|
|
@@ -36,6 +39,10 @@ export class StellarSignAndExecuteTask extends BaseStepExecutionTask {
|
|
|
36
39
|
)
|
|
37
40
|
}
|
|
38
41
|
|
|
42
|
+
// Defence in depth: the selector never routes an open transaction here,
|
|
43
|
+
// and signing again could execute the swap twice.
|
|
44
|
+
assertNoOpenTransaction(action)
|
|
45
|
+
|
|
39
46
|
const transactionRequestData = await getTransactionRequestData(
|
|
40
47
|
step,
|
|
41
48
|
executionOptions
|
|
@@ -43,6 +50,10 @@ export class StellarSignAndExecuteTask extends BaseStepExecutionTask {
|
|
|
43
50
|
|
|
44
51
|
checkWallet(step)
|
|
45
52
|
|
|
53
|
+
// Checked again right before the wallet: a late write of an older run
|
|
54
|
+
// can merge its transaction into this action during the await above.
|
|
55
|
+
assertNoOpenTransaction(statusManager.findAction(step, action.type))
|
|
56
|
+
|
|
46
57
|
const { signedTxXdr } = await wallet.signTransaction(
|
|
47
58
|
transactionRequestData,
|
|
48
59
|
{
|
|
@@ -51,6 +62,11 @@ export class StellarSignAndExecuteTask extends BaseStepExecutionTask {
|
|
|
51
62
|
}
|
|
52
63
|
)
|
|
53
64
|
|
|
65
|
+
// Checked once more after the wallet: a stopped run's late write can
|
|
66
|
+
// merge its transaction into this action while the prompt is open.
|
|
67
|
+
// Nothing awaits from here to the write below.
|
|
68
|
+
assertNoOpenTransaction(statusManager.findAction(step, action.type))
|
|
69
|
+
|
|
54
70
|
// Recorded before the network ever sees the envelope, so a crash between
|
|
55
71
|
// submit and confirmation resumes by polling for this hash rather than
|
|
56
72
|
// re-signing and executing the swap twice. StellarStepExecutor.createPipeline
|
|
@@ -61,13 +77,27 @@ export class StellarSignAndExecuteTask extends BaseStepExecutionTask {
|
|
|
61
77
|
)
|
|
62
78
|
|
|
63
79
|
statusManager.updateAction(step, action.type, 'PENDING', {
|
|
80
|
+
// A new transaction: nothing of the previous one may survive, least of
|
|
81
|
+
// all its `txFinal` verdict.
|
|
82
|
+
...CLEARED_TRANSACTION_FIELDS,
|
|
64
83
|
txHash: transactionHash,
|
|
65
84
|
txLink: getStellarTxLink(fromChain, transactionHash),
|
|
66
85
|
txHex: signedTxXdr,
|
|
67
86
|
signedAt: Date.now(),
|
|
68
87
|
})
|
|
69
88
|
|
|
70
|
-
|
|
89
|
+
try {
|
|
90
|
+
await submitStellarTransaction(client, signedTxXdr, networkPassphrase)
|
|
91
|
+
} catch (error) {
|
|
92
|
+
// A rejection is final only with a chain proof that the envelope was never
|
|
93
|
+
// applied and can no longer be, and when the LI.FI status API does not
|
|
94
|
+
// know the hash. On the first run the envelope has usually not expired
|
|
95
|
+
// yet, so the outcome stays unknown and a resume checks it again.
|
|
96
|
+
throw await classifySubmitFailure(
|
|
97
|
+
{ client, step, transactionHash, signedTxXdr, networkPassphrase },
|
|
98
|
+
error
|
|
99
|
+
)
|
|
100
|
+
}
|
|
71
101
|
|
|
72
102
|
return { status: 'COMPLETED', context: { transactionHash } }
|
|
73
103
|
}
|
|
@@ -6,6 +6,8 @@ import {
|
|
|
6
6
|
TransactionError,
|
|
7
7
|
} from '@lifi/sdk'
|
|
8
8
|
import type { StellarStepExecutorContext } from '../../types.js'
|
|
9
|
+
import { classifySubmitFailure } from './helpers/classifySubmitFailure.js'
|
|
10
|
+
import { deriveTransactionHash } from './helpers/deriveTransactionHash.js'
|
|
9
11
|
import { probeStellarTransaction } from './helpers/probeStellarTransaction.js'
|
|
10
12
|
import { submitStellarTransaction } from './helpers/submitStellarTransaction.js'
|
|
11
13
|
import { waitForStellarTransaction } from './helpers/waitForStellarTransaction.js'
|
|
@@ -52,8 +54,17 @@ export class StellarWaitForTransactionTask extends BaseStepExecutionTask {
|
|
|
52
54
|
// already, in which case its sequence number is spent and re-submitting can
|
|
53
55
|
// only fail. Ask the network first, and let the poll below decide the
|
|
54
56
|
// outcome either way.
|
|
57
|
+
//
|
|
58
|
+
// A stored envelope that hashes to another value than the stored hash
|
|
59
|
+
// (damaged storage) proves nothing about that transaction, and it may have
|
|
60
|
+
// been sent. Then the SDK neither submits nor classifies a failure; it only
|
|
61
|
+
// polls by the hash, and the outcome stays unknown.
|
|
55
62
|
let resubmitError: unknown
|
|
56
|
-
if (
|
|
63
|
+
if (
|
|
64
|
+
!transactionHash &&
|
|
65
|
+
action.txHex &&
|
|
66
|
+
!isOtherTransaction(action.txHex, networkPassphrase, hash)
|
|
67
|
+
) {
|
|
57
68
|
const probe = await probeStellarTransaction(client, hash)
|
|
58
69
|
if (probe !== 'landed') {
|
|
59
70
|
try {
|
|
@@ -74,13 +85,25 @@ export class StellarWaitForTransactionTask extends BaseStepExecutionTask {
|
|
|
74
85
|
await waitForStellarTransaction(client, hash, pollingIntervalMs)
|
|
75
86
|
} catch (error) {
|
|
76
87
|
// The envelope never reached the network, and the poll can only report
|
|
77
|
-
// that as a timeout. The submission error says why.
|
|
88
|
+
// that as a timeout. The submission error says why. It becomes final only
|
|
89
|
+
// with a chain proof that the envelope was never applied and when the
|
|
90
|
+
// LI.FI status API does not know the hash.
|
|
78
91
|
if (
|
|
79
92
|
resubmitError &&
|
|
93
|
+
action.txHex &&
|
|
80
94
|
error instanceof BaseError &&
|
|
81
95
|
error.code === LiFiErrorCode.Timeout
|
|
82
96
|
) {
|
|
83
|
-
throw
|
|
97
|
+
throw await classifySubmitFailure(
|
|
98
|
+
{
|
|
99
|
+
client,
|
|
100
|
+
step,
|
|
101
|
+
transactionHash: hash,
|
|
102
|
+
signedTxXdr: action.txHex,
|
|
103
|
+
networkPassphrase,
|
|
104
|
+
},
|
|
105
|
+
resubmitError
|
|
106
|
+
)
|
|
84
107
|
}
|
|
85
108
|
throw error
|
|
86
109
|
}
|
|
@@ -92,3 +115,22 @@ export class StellarWaitForTransactionTask extends BaseStepExecutionTask {
|
|
|
92
115
|
return { status: 'COMPLETED' }
|
|
93
116
|
}
|
|
94
117
|
}
|
|
118
|
+
|
|
119
|
+
/**
|
|
120
|
+
* True when the stored envelope decodes to a transaction other than `hash`.
|
|
121
|
+
* An envelope that does not decode has no hash to compare, and it can never
|
|
122
|
+
* be submitted either.
|
|
123
|
+
*/
|
|
124
|
+
function isOtherTransaction(
|
|
125
|
+
signedTxXdr: string,
|
|
126
|
+
networkPassphrase: string,
|
|
127
|
+
hash: string
|
|
128
|
+
): boolean {
|
|
129
|
+
let derived: string
|
|
130
|
+
try {
|
|
131
|
+
derived = deriveTransactionHash(signedTxXdr, networkPassphrase)
|
|
132
|
+
} catch {
|
|
133
|
+
return false
|
|
134
|
+
}
|
|
135
|
+
return derived !== hash
|
|
136
|
+
}
|
|
@@ -0,0 +1,123 @@
|
|
|
1
|
+
import {
|
|
2
|
+
CLOCK_SKEW_MARGIN_MS,
|
|
3
|
+
isKnownToStatusApi,
|
|
4
|
+
LiFiErrorCode,
|
|
5
|
+
type LiFiStepExtended,
|
|
6
|
+
type SDKClient,
|
|
7
|
+
TransactionError,
|
|
8
|
+
} from '@lifi/sdk'
|
|
9
|
+
import { type Transaction, TransactionBuilder } from '@stellar/stellar-sdk'
|
|
10
|
+
import {
|
|
11
|
+
proveStellarTransactionAbsent,
|
|
12
|
+
type StellarLandingWindow,
|
|
13
|
+
} from './proveStellarTransactionAbsent.js'
|
|
14
|
+
|
|
15
|
+
export interface StellarSubmitFailureContext {
|
|
16
|
+
client: SDKClient
|
|
17
|
+
step: LiFiStepExtended
|
|
18
|
+
/** Hash of the signed envelope, persisted before the submit. */
|
|
19
|
+
transactionHash: string
|
|
20
|
+
/** The signed envelope (base64 XDR) that was submitted. */
|
|
21
|
+
signedTxXdr: string
|
|
22
|
+
networkPassphrase: string
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
/**
|
|
26
|
+
* When the envelope could have been applied, in chain time (unix seconds).
|
|
27
|
+
*
|
|
28
|
+
* The earliest landing time is the envelope's `minTime` when it has one (> 0).
|
|
29
|
+
* Otherwise it is `execution.signedAt - CLOCK_SKEW_MARGIN_MS`: `signedAt` comes
|
|
30
|
+
* from the local clock, and the margin covers its skew against ledger time. The
|
|
31
|
+
* function returns `undefined` when the envelope has no `maxTime` (it never
|
|
32
|
+
* expires), when neither anchor exists, or when the envelope does not decode.
|
|
33
|
+
* In each of these cases absence cannot be proven.
|
|
34
|
+
*/
|
|
35
|
+
const getLandingWindow = (
|
|
36
|
+
signedTxXdr: string,
|
|
37
|
+
networkPassphrase: string,
|
|
38
|
+
signedAt: number | undefined
|
|
39
|
+
): StellarLandingWindow | undefined => {
|
|
40
|
+
let timeBounds: Transaction['timeBounds']
|
|
41
|
+
try {
|
|
42
|
+
timeBounds = (
|
|
43
|
+
TransactionBuilder.fromXdr(signedTxXdr, networkPassphrase) as Transaction
|
|
44
|
+
).timeBounds
|
|
45
|
+
} catch {
|
|
46
|
+
return undefined
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
const maxTime = Number(timeBounds?.maxTime ?? 0)
|
|
50
|
+
if (!(maxTime > 0)) {
|
|
51
|
+
return undefined
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
const minTime = Number(timeBounds?.minTime ?? 0)
|
|
55
|
+
if (minTime > 0) {
|
|
56
|
+
return { earliest: minTime, maxTime }
|
|
57
|
+
}
|
|
58
|
+
if (signedAt === undefined) {
|
|
59
|
+
return undefined
|
|
60
|
+
}
|
|
61
|
+
return {
|
|
62
|
+
earliest: Math.floor((signedAt - CLOCK_SKEW_MARGIN_MS) / 1000),
|
|
63
|
+
maxTime,
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
/**
|
|
68
|
+
* Decides whether a failed submission is a final outcome, and returns the error
|
|
69
|
+
* to throw (see the resume rules in `transactionState.ts`).
|
|
70
|
+
*
|
|
71
|
+
* Only a rejection can be final: `submitStellarTransaction` throws
|
|
72
|
+
* `TransactionFailed` for a status other than PENDING, DUPLICATE or
|
|
73
|
+
* TRY_AGAIN_LATER. A rejection alone proves nothing, because a failover
|
|
74
|
+
* re-submit of an envelope that was already applied is rejected as well (for
|
|
75
|
+
* example txBAD_SEQ). A rejection is final only when:
|
|
76
|
+
* - a node answers NOT_FOUND in a response that itself covers the whole
|
|
77
|
+
* landing window of the envelope (see {@link proveStellarTransactionAbsent}),
|
|
78
|
+
* so the envelope was never applied and can no longer be; and
|
|
79
|
+
* - the LI.FI status API does not know the hash. That check is a veto only. A
|
|
80
|
+
* miss (HTTP 404 or an error) says nothing.
|
|
81
|
+
*
|
|
82
|
+
* Transport errors, `RateLimitExceeded`, decode errors and every inconclusive
|
|
83
|
+
* check return `error` itself, so the outcome stays unknown and a resume checks
|
|
84
|
+
* again. Code and message never change.
|
|
85
|
+
*/
|
|
86
|
+
export const classifySubmitFailure = async (
|
|
87
|
+
{
|
|
88
|
+
client,
|
|
89
|
+
step,
|
|
90
|
+
transactionHash,
|
|
91
|
+
signedTxXdr,
|
|
92
|
+
networkPassphrase,
|
|
93
|
+
}: StellarSubmitFailureContext,
|
|
94
|
+
error: unknown
|
|
95
|
+
): Promise<unknown> => {
|
|
96
|
+
if (
|
|
97
|
+
!(error instanceof TransactionError) ||
|
|
98
|
+
error.code !== LiFiErrorCode.TransactionFailed
|
|
99
|
+
) {
|
|
100
|
+
return error
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
const window = getLandingWindow(
|
|
104
|
+
signedTxXdr,
|
|
105
|
+
networkPassphrase,
|
|
106
|
+
step.execution?.signedAt
|
|
107
|
+
)
|
|
108
|
+
if (!window) {
|
|
109
|
+
return error
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
if (!(await proveStellarTransactionAbsent(client, transactionHash, window))) {
|
|
113
|
+
return error
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
if (await isKnownToStatusApi(client, step, transactionHash)) {
|
|
117
|
+
return error
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
return new TransactionError(error.code, error.message, error, {
|
|
121
|
+
final: true,
|
|
122
|
+
})
|
|
123
|
+
}
|
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
import { type SDKClient, withTimeout } from '@lifi/sdk'
|
|
2
|
+
import { Api, type Server } from '@stellar/stellar-sdk/rpc'
|
|
3
|
+
import { getStellarRpcs } from '../../../client/getStellarRpc.js'
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* A node's latest ledger must have closed this long after the envelope's
|
|
7
|
+
* `maxTime` before its NOT_FOUND counts. Close times only grow, so every ledger
|
|
8
|
+
* that could still include the envelope is then in that node's history. Five
|
|
9
|
+
* or six ledgers of slack.
|
|
10
|
+
*/
|
|
11
|
+
const HEAD_MARGIN_SECONDS = 30
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* The time each RPC has to answer. stellar-sdk sets no request timeout, so a
|
|
15
|
+
* node that accepts the request and never answers would hold the route. A
|
|
16
|
+
* timeout counts as a failed request: it gives no information.
|
|
17
|
+
*/
|
|
18
|
+
const LOOKUP_TIMEOUT_MS = 10_000
|
|
19
|
+
|
|
20
|
+
/** When the transaction could have been applied, in unix seconds (chain time). */
|
|
21
|
+
export interface StellarLandingWindow {
|
|
22
|
+
/** Earliest time the transaction could have been applied (the anchor). */
|
|
23
|
+
earliest: number
|
|
24
|
+
/** The envelope's `maxTime`: no ledger that closes later can include it. */
|
|
25
|
+
maxTime: number
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
/**
|
|
29
|
+
* True only when the chain proves that the transaction was never applied.
|
|
30
|
+
*
|
|
31
|
+
* Every configured RPC is asked once. A NOT_FOUND counts only when the same
|
|
32
|
+
* response proves that its node would know the transaction: the node's history
|
|
33
|
+
* starts before `window.earliest` (`oldestLedgerCloseTime`), and its latest
|
|
34
|
+
* ledger closed after `window.maxTime` plus a margin (`latestLedgerCloseTime`).
|
|
35
|
+
* A separate `getHealth` or `getLatestLedger` request would prove nothing,
|
|
36
|
+
* because a URL can be a load-balanced pool of different backends.
|
|
37
|
+
*
|
|
38
|
+
* A node that returns the transaction (SUCCESS or FAILED) makes the answer
|
|
39
|
+
* false. A failed request, a request without an answer within
|
|
40
|
+
* `LOOKUP_TIMEOUT_MS`, and a NOT_FOUND that does not prove coverage give no
|
|
41
|
+
* information.
|
|
42
|
+
*/
|
|
43
|
+
export const proveStellarTransactionAbsent = async (
|
|
44
|
+
client: SDKClient,
|
|
45
|
+
transactionHash: string,
|
|
46
|
+
window: StellarLandingWindow
|
|
47
|
+
): Promise<boolean> => {
|
|
48
|
+
let servers: Server[]
|
|
49
|
+
try {
|
|
50
|
+
servers = await getStellarRpcs(client)
|
|
51
|
+
} catch {
|
|
52
|
+
return false
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
// `getTransaction` takes no abort signal, so the deadline only races it.
|
|
56
|
+
const results = await Promise.allSettled(
|
|
57
|
+
servers.map((server) =>
|
|
58
|
+
withTimeout(() => server.getTransaction(transactionHash), {
|
|
59
|
+
timeout: LOOKUP_TIMEOUT_MS,
|
|
60
|
+
})
|
|
61
|
+
)
|
|
62
|
+
)
|
|
63
|
+
|
|
64
|
+
let provenAbsent = false
|
|
65
|
+
for (const result of results) {
|
|
66
|
+
if (result.status === 'rejected') {
|
|
67
|
+
continue
|
|
68
|
+
}
|
|
69
|
+
const response = result.value
|
|
70
|
+
if (response.status !== Api.GetTransactionStatus.NOT_FOUND) {
|
|
71
|
+
return false
|
|
72
|
+
}
|
|
73
|
+
// Unix seconds. The SDK types say number, but the SDK passes the raw JSON
|
|
74
|
+
// value through, so `Number` also accepts a string. `Number(null)` and
|
|
75
|
+
// `Number('')` are 0, which is before every anchor, so only a positive
|
|
76
|
+
// close time counts as the start of the node's history.
|
|
77
|
+
const oldest = Number(response.oldestLedgerCloseTime)
|
|
78
|
+
const latest = Number(response.latestLedgerCloseTime)
|
|
79
|
+
if (
|
|
80
|
+
Number.isFinite(oldest) &&
|
|
81
|
+
Number.isFinite(latest) &&
|
|
82
|
+
oldest > 0 &&
|
|
83
|
+
oldest < window.earliest &&
|
|
84
|
+
latest > window.maxTime + HEAD_MARGIN_SECONDS
|
|
85
|
+
) {
|
|
86
|
+
provenAbsent = true
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
return provenAbsent
|
|
90
|
+
}
|
|
@@ -5,10 +5,12 @@ import { callStellarRpcsWithRetry } from '../../../client/getStellarRpc.js'
|
|
|
5
5
|
const CONFIRM_POLL_INTERVAL_MS = 3_000
|
|
6
6
|
|
|
7
7
|
/**
|
|
8
|
-
* Outlives the backend's `[0, now + 300 s]` timebounds, so
|
|
9
|
-
*
|
|
10
|
-
*
|
|
11
|
-
*
|
|
8
|
+
* Outlives the backend's `[0, now + 300 s]` timebounds, so the wait normally
|
|
9
|
+
* lasts until the envelope can no longer be applied. A timeout is still not
|
|
10
|
+
* proof that the transaction is dead: the RPC may lag, or its history may not
|
|
11
|
+
* reach the transaction, so the outcome stays unknown. Expressed as a deadline,
|
|
12
|
+
* not an attempt count, so a caller-supplied polling interval cannot shorten
|
|
13
|
+
* the budget.
|
|
12
14
|
*/
|
|
13
15
|
const CONFIRM_TIMEOUT_MS = 330_000
|
|
14
16
|
|
|
@@ -50,7 +52,9 @@ export const waitForStellarTransaction = async (
|
|
|
50
52
|
LiFiErrorCode.TransactionFailed,
|
|
51
53
|
`Stellar transaction ${transactionHash} failed: ${
|
|
52
54
|
response.resultXdr?.result.type ?? 'unknown reason'
|
|
53
|
-
}
|
|
55
|
+
}`,
|
|
56
|
+
undefined,
|
|
57
|
+
{ final: true }
|
|
54
58
|
)
|
|
55
59
|
}
|
|
56
60
|
} catch (error) {
|
package/src/version.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
export const name = '@lifi/sdk-provider-stellar'
|
|
2
|
-
export const version = '4.3.
|
|
2
|
+
export const version = '4.3.8'
|