@lifi/sdk-provider-stellar 0.0.0-preview-c328023 → 4.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (75) hide show
  1. package/CHANGELOG.md +9 -5
  2. package/dist/esm/StellarProvider.d.ts +7 -1
  3. package/dist/esm/StellarProvider.d.ts.map +1 -1
  4. package/dist/esm/StellarProvider.js +8 -2
  5. package/dist/esm/StellarProvider.js.map +1 -1
  6. package/dist/esm/actions/getStellarBalance.js +14 -5
  7. package/dist/esm/actions/getStellarBalance.js.map +1 -1
  8. package/dist/esm/actions/resolveStellarAddress.d.ts +8 -1
  9. package/dist/esm/actions/resolveStellarAddress.d.ts.map +1 -1
  10. package/dist/esm/actions/resolveStellarAddress.js +11 -2
  11. package/dist/esm/actions/resolveStellarAddress.js.map +1 -1
  12. package/dist/esm/client/getStellarRpc.d.ts +3 -3
  13. package/dist/esm/client/getStellarRpc.d.ts.map +1 -1
  14. package/dist/esm/client/getStellarRpc.js +2 -2
  15. package/dist/esm/client/getStellarRpc.js.map +1 -1
  16. package/dist/esm/core/StellarStepExecutor.d.ts.map +1 -1
  17. package/dist/esm/core/StellarStepExecutor.js +3 -1
  18. package/dist/esm/core/StellarStepExecutor.js.map +1 -1
  19. package/dist/esm/core/tasks/StellarPrepareTransactionTask.d.ts +23 -16
  20. package/dist/esm/core/tasks/StellarPrepareTransactionTask.d.ts.map +1 -1
  21. package/dist/esm/core/tasks/StellarPrepareTransactionTask.js +28 -28
  22. package/dist/esm/core/tasks/StellarPrepareTransactionTask.js.map +1 -1
  23. package/dist/esm/core/tasks/StellarWaitForTransactionTask.d.ts.map +1 -1
  24. package/dist/esm/core/tasks/StellarWaitForTransactionTask.js +17 -3
  25. package/dist/esm/core/tasks/StellarWaitForTransactionTask.js.map +1 -1
  26. package/dist/esm/core/tasks/helpers/assertApprovalStillCovers.d.ts +21 -0
  27. package/dist/esm/core/tasks/helpers/assertApprovalStillCovers.d.ts.map +1 -0
  28. package/dist/esm/core/tasks/helpers/assertApprovalStillCovers.js +29 -0
  29. package/dist/esm/core/tasks/helpers/assertApprovalStillCovers.js.map +1 -0
  30. package/dist/esm/core/tasks/helpers/probeStellarTransaction.d.ts +20 -0
  31. package/dist/esm/core/tasks/helpers/probeStellarTransaction.d.ts.map +1 -0
  32. package/dist/esm/core/tasks/helpers/probeStellarTransaction.js +20 -0
  33. package/dist/esm/core/tasks/helpers/probeStellarTransaction.js.map +1 -0
  34. package/dist/esm/core/tasks/helpers/readAllowance.d.ts +4 -0
  35. package/dist/esm/core/tasks/helpers/readAllowance.d.ts.map +1 -1
  36. package/dist/esm/core/tasks/helpers/readAllowance.js +12 -6
  37. package/dist/esm/core/tasks/helpers/readAllowance.js.map +1 -1
  38. package/dist/esm/core/tasks/helpers/resolveApprovalRequirement.js +1 -2
  39. package/dist/esm/core/tasks/helpers/resolveApprovalRequirement.js.map +1 -1
  40. package/dist/esm/core/tasks/helpers/submitStellarTransaction.d.ts +3 -0
  41. package/dist/esm/core/tasks/helpers/submitStellarTransaction.d.ts.map +1 -1
  42. package/dist/esm/core/tasks/helpers/submitStellarTransaction.js +20 -6
  43. package/dist/esm/core/tasks/helpers/submitStellarTransaction.js.map +1 -1
  44. package/dist/esm/core/tasks/helpers/waitForStellarTransaction.d.ts +8 -4
  45. package/dist/esm/core/tasks/helpers/waitForStellarTransaction.d.ts.map +1 -1
  46. package/dist/esm/core/tasks/helpers/waitForStellarTransaction.js +26 -9
  47. package/dist/esm/core/tasks/helpers/waitForStellarTransaction.js.map +1 -1
  48. package/dist/esm/errors/parseStellarErrors.js +7 -2
  49. package/dist/esm/errors/parseStellarErrors.js.map +1 -1
  50. package/dist/esm/index.d.ts +2 -2
  51. package/dist/esm/index.js +2 -2
  52. package/dist/esm/types.d.ts +10 -6
  53. package/dist/esm/types.d.ts.map +1 -1
  54. package/dist/esm/types.js.map +1 -1
  55. package/dist/esm/version.d.ts +1 -1
  56. package/dist/esm/version.js +1 -1
  57. package/dist/esm/version.js.map +1 -1
  58. package/package.json +3 -3
  59. package/src/StellarProvider.ts +8 -1
  60. package/src/actions/getStellarBalance.ts +22 -6
  61. package/src/actions/resolveStellarAddress.ts +19 -2
  62. package/src/client/getStellarRpc.ts +6 -8
  63. package/src/core/StellarStepExecutor.ts +11 -0
  64. package/src/core/tasks/StellarPrepareTransactionTask.ts +31 -71
  65. package/src/core/tasks/StellarWaitForTransactionTask.ts +35 -7
  66. package/src/core/tasks/helpers/assertApprovalStillCovers.ts +48 -0
  67. package/src/core/tasks/helpers/probeStellarTransaction.ts +34 -0
  68. package/src/core/tasks/helpers/readAllowance.ts +42 -33
  69. package/src/core/tasks/helpers/resolveApprovalRequirement.ts +10 -10
  70. package/src/core/tasks/helpers/submitStellarTransaction.ts +41 -25
  71. package/src/core/tasks/helpers/waitForStellarTransaction.ts +44 -20
  72. package/src/errors/parseStellarErrors.ts +17 -5
  73. package/src/index.ts +4 -1
  74. package/src/types.ts +10 -6
  75. package/src/version.ts +1 -1
package/CHANGELOG.md CHANGED
@@ -1,14 +1,18 @@
1
1
  # @lifi/sdk-provider-stellar
2
2
 
3
- ## 0.0.0-preview-c328023
3
+ ## 4.2.0
4
4
 
5
5
  ### Minor Changes
6
6
 
7
- - [#427](https://github.com/lifinance/sdk/pull/427) [`03c1562`](https://github.com/lifinance/sdk/commit/03c15625c7d5515f91e24a555ec3b6b5e99dd6b5) Thanks [@chybisov](https://github.com/chybisov)! - Add Stellar (STL) ecosystem support. Introduces the `@lifi/sdk-provider-stellar` package — address validation, Federation resolution, SAC-based balance reads, and route execution via `StellarStepExecutor` — and registers `ChainType.STL` in the SDK client's chain fetching so Stellar chains and RPC URLs load.
8
-
7
+ - [`fd1e9b5`](https://github.com/lifinance/sdk/commit/fd1e9b5ff481b35683d7b8557011c9c726446cdd) Thanks [@chybisov](https://github.com/chybisov)! - Add Stellar (STL) ecosystem support. Introduces the `@lifi/sdk-provider-stellar` package — address validation, Federation resolution, SAC-based balance reads, and route execution via `StellarStepExecutor` — and registers `ChainType.STL` in the SDK client's chain fetching so Stellar chains and RPC URLs load.
8
+
9
9
  Execution signs the backend-generated Soroban envelope with the connected wallet, submits it over Stellar RPC, waits for on-chain confirmation, then tracks the transfer through the LI.FI status API. Because a Stellar envelope embeds the sender's account sequence number and a short-lived set of timebounds, the provider always requests a freshly built transaction immediately before signing rather than reusing the one attached to the quote. SAC allowances are granted first when a step requires one, and the approval is confirmed on-chain before the route transaction is requested.
10
+
11
+ `PrepareTransactionTask` gains a `shouldRefetchTransaction` hook. It defaults to the previous behaviour — fetch only when the step carries no transaction request — and the Stellar task overrides it, because a Stellar envelope embeds the sender's sequence number and cannot be reused.
12
+
13
+ `StellarProviderOptions.horizonUrl` is gone — nothing read it — and `StellarWallet.signAuthEntry` is now optional, because the router routes use source-account auth and the SDK never calls it. The provider also exports `DEFAULT_NETWORK_PASSPHRASE`, and refuses to sign when the connected wallet's network disagrees with the configured one.
10
14
 
11
15
  ### Patch Changes
12
16
 
13
- - Updated dependencies [[`03c1562`](https://github.com/lifinance/sdk/commit/03c15625c7d5515f91e24a555ec3b6b5e99dd6b5)]:
14
- - @lifi/sdk@0.0.0-preview-c328023
17
+ - Updated dependencies [[`fd1e9b5`](https://github.com/lifinance/sdk/commit/fd1e9b5ff481b35683d7b8557011c9c726446cdd)]:
18
+ - @lifi/sdk@4.4.0
@@ -1,6 +1,12 @@
1
1
  import { StellarProviderOptions, StellarSDKProvider } from "./types.js";
2
2
  //#region src/StellarProvider.d.ts
3
+ /**
4
+ * The network every read defaults to when the integrator configures none.
5
+ * Signing prefers the connected wallet's passphrase instead, and
6
+ * `StellarStepExecutor.checkWallet` refuses a route whose networks disagree.
7
+ */
8
+ declare const DEFAULT_NETWORK_PASSPHRASE: string;
3
9
  declare function StellarProvider(options?: StellarProviderOptions): StellarSDKProvider;
4
10
  //#endregion
5
- export { StellarProvider };
11
+ export { DEFAULT_NETWORK_PASSPHRASE, StellarProvider };
6
12
  //# sourceMappingURL=StellarProvider.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"StellarProvider.d.ts","names":[],"sources":["../../src/StellarProvider.ts"],"mappings":";;iBAyBgB,gBACd,UAAU,yBACT"}
1
+ {"version":3,"file":"StellarProvider.d.ts","names":[],"sources":["../../src/StellarProvider.ts"],"mappings":";;;;;;;cAqBa;iBAWG,gBACd,UAAU,yBACT"}
@@ -5,6 +5,12 @@ import { ChainType, LiFiErrorCode, ProviderError } from "@lifi/sdk";
5
5
  import { Networks, StrKey } from "@stellar/stellar-sdk";
6
6
  //#region src/StellarProvider.ts
7
7
  /**
8
+ * The network every read defaults to when the integrator configures none.
9
+ * Signing prefers the connected wallet's passphrase instead, and
10
+ * `StellarStepExecutor.checkWallet` refuses a route whose networks disagree.
11
+ */
12
+ const DEFAULT_NETWORK_PASSPHRASE = Networks.PUBLIC;
13
+ /**
8
14
  * Validates a Stellar account address. Only ed25519 G-addresses are accepted as
9
15
  * senders — muxed `M`-addresses and contract `C`-addresses are intentionally
10
16
  * rejected (see backend EXBE-227: muxed senders validate-and-throw).
@@ -20,7 +26,7 @@ function StellarProvider(options) {
20
26
  },
21
27
  isAddress: isStellarAddress,
22
28
  resolveAddress: resolveStellarAddress,
23
- getBalance: (client, walletAddress, tokens) => getStellarBalance(client, walletAddress, tokens, _options.networkPassphrase ?? Networks.PUBLIC),
29
+ getBalance: (client, walletAddress, tokens) => getStellarBalance(client, walletAddress, tokens, _options.networkPassphrase ?? DEFAULT_NETWORK_PASSPHRASE),
24
30
  async getStepExecutor(options) {
25
31
  if (!_options.getWallet) throw new ProviderError(LiFiErrorCode.ProviderUnavailable, "getWallet is not provided.");
26
32
  const wallet = await _options.getWallet();
@@ -37,6 +43,6 @@ function StellarProvider(options) {
37
43
  };
38
44
  }
39
45
  //#endregion
40
- export { StellarProvider };
46
+ export { DEFAULT_NETWORK_PASSPHRASE, StellarProvider };
41
47
 
42
48
  //# sourceMappingURL=StellarProvider.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"StellarProvider.js","names":[],"sources":["../../src/StellarProvider.ts"],"sourcesContent":["import {\n ChainType,\n LiFiErrorCode,\n ProviderError,\n type SDKClient,\n type StepExecutor,\n type StepExecutorOptions,\n type Token,\n type TokenAmount,\n} from '@lifi/sdk'\nimport { Networks, StrKey } from '@stellar/stellar-sdk'\nimport { getStellarBalance } from './actions/getStellarBalance.js'\nimport { resolveStellarAddress } from './actions/resolveStellarAddress.js'\nimport { StellarStepExecutor } from './core/StellarStepExecutor.js'\nimport type { StellarProviderOptions, StellarSDKProvider } from './types.js'\n\n/**\n * Validates a Stellar account address. Only ed25519 G-addresses are accepted as\n * senders — muxed `M`-addresses and contract `C`-addresses are intentionally\n * rejected (see backend EXBE-227: muxed senders validate-and-throw).\n */\nfunction isStellarAddress(address: string): boolean {\n return StrKey.isValidEd25519PublicKey(address)\n}\n\nexport function StellarProvider(\n options?: StellarProviderOptions\n): StellarSDKProvider {\n const _options: StellarProviderOptions = options ?? {}\n return {\n get type() {\n return ChainType.STL\n },\n isAddress: isStellarAddress,\n resolveAddress: resolveStellarAddress,\n getBalance: (\n client: SDKClient,\n walletAddress: string,\n tokens: Token[]\n ): Promise<TokenAmount[]> =>\n getStellarBalance(\n client,\n walletAddress,\n tokens,\n _options.networkPassphrase ?? Networks.PUBLIC\n ),\n async getStepExecutor(options: StepExecutorOptions): Promise<StepExecutor> {\n if (!_options.getWallet) {\n throw new ProviderError(\n LiFiErrorCode.ProviderUnavailable,\n 'getWallet is not provided.'\n )\n }\n const wallet = await _options.getWallet()\n return new StellarStepExecutor({\n wallet,\n networkPassphrase:\n _options.networkPassphrase ?? wallet.networkPassphrase,\n routeId: options.routeId,\n executionOptions: { ...options.executionOptions },\n })\n },\n setOptions(options: StellarProviderOptions) {\n Object.assign(_options, options)\n },\n }\n}\n"],"mappings":";;;;;;;;;;;AAqBA,SAAS,iBAAiB,SAA0B;CAClD,OAAO,OAAO,wBAAwB,OAAO;AAC/C;AAEA,SAAgB,gBACd,SACoB;CACpB,MAAM,WAAmC,WAAW,CAAC;CACrD,OAAO;EACL,IAAI,OAAO;GACT,OAAO,UAAU;EACnB;EACA,WAAW;EACX,gBAAgB;EAChB,aACE,QACA,eACA,WAEA,kBACE,QACA,eACA,QACA,SAAS,qBAAqB,SAAS,MACzC;EACF,MAAM,gBAAgB,SAAqD;GACzE,IAAI,CAAC,SAAS,WACZ,MAAM,IAAI,cACR,cAAc,qBACd,4BACF;GAEF,MAAM,SAAS,MAAM,SAAS,UAAU;GACxC,OAAO,IAAI,oBAAoB;IAC7B;IACA,mBACE,SAAS,qBAAqB,OAAO;IACvC,SAAS,QAAQ;IACjB,kBAAkB,EAAE,GAAG,QAAQ,iBAAiB;GAClD,CAAC;EACH;EACA,WAAW,SAAiC;GAC1C,OAAO,OAAO,UAAU,OAAO;EACjC;CACF;AACF"}
1
+ {"version":3,"file":"StellarProvider.js","names":[],"sources":["../../src/StellarProvider.ts"],"sourcesContent":["import {\n ChainType,\n LiFiErrorCode,\n ProviderError,\n type SDKClient,\n type StepExecutor,\n type StepExecutorOptions,\n type Token,\n type TokenAmount,\n} from '@lifi/sdk'\nimport { Networks, StrKey } from '@stellar/stellar-sdk'\nimport { getStellarBalance } from './actions/getStellarBalance.js'\nimport { resolveStellarAddress } from './actions/resolveStellarAddress.js'\nimport { StellarStepExecutor } from './core/StellarStepExecutor.js'\nimport type { StellarProviderOptions, StellarSDKProvider } from './types.js'\n\n/**\n * The network every read defaults to when the integrator configures none.\n * Signing prefers the connected wallet's passphrase instead, and\n * `StellarStepExecutor.checkWallet` refuses a route whose networks disagree.\n */\nexport const DEFAULT_NETWORK_PASSPHRASE: string = Networks.PUBLIC\n\n/**\n * Validates a Stellar account address. Only ed25519 G-addresses are accepted as\n * senders — muxed `M`-addresses and contract `C`-addresses are intentionally\n * rejected (see backend EXBE-227: muxed senders validate-and-throw).\n */\nfunction isStellarAddress(address: string): boolean {\n return StrKey.isValidEd25519PublicKey(address)\n}\n\nexport function StellarProvider(\n options?: StellarProviderOptions\n): StellarSDKProvider {\n const _options: StellarProviderOptions = options ?? {}\n return {\n get type() {\n return ChainType.STL\n },\n isAddress: isStellarAddress,\n resolveAddress: resolveStellarAddress,\n getBalance: (\n client: SDKClient,\n walletAddress: string,\n tokens: Token[]\n ): Promise<TokenAmount[]> =>\n getStellarBalance(\n client,\n walletAddress,\n tokens,\n _options.networkPassphrase ?? DEFAULT_NETWORK_PASSPHRASE\n ),\n async getStepExecutor(options: StepExecutorOptions): Promise<StepExecutor> {\n if (!_options.getWallet) {\n throw new ProviderError(\n LiFiErrorCode.ProviderUnavailable,\n 'getWallet is not provided.'\n )\n }\n const wallet = await _options.getWallet()\n return new StellarStepExecutor({\n wallet,\n networkPassphrase:\n _options.networkPassphrase ?? wallet.networkPassphrase,\n routeId: options.routeId,\n executionOptions: { ...options.executionOptions },\n })\n },\n setOptions(options: StellarProviderOptions) {\n Object.assign(_options, options)\n },\n }\n}\n"],"mappings":";;;;;;;;;;;AAqBA,MAAa,6BAAqC,SAAS;;;;;;AAO3D,SAAS,iBAAiB,SAA0B;CAClD,OAAO,OAAO,wBAAwB,OAAO;AAC/C;AAEA,SAAgB,gBACd,SACoB;CACpB,MAAM,WAAmC,WAAW,CAAC;CACrD,OAAO;EACL,IAAI,OAAO;GACT,OAAO,UAAU;EACnB;EACA,WAAW;EACX,gBAAgB;EAChB,aACE,QACA,eACA,WAEA,kBACE,QACA,eACA,QACA,SAAS,qBAAqB,0BAChC;EACF,MAAM,gBAAgB,SAAqD;GACzE,IAAI,CAAC,SAAS,WACZ,MAAM,IAAI,cACR,cAAc,qBACd,4BACF;GAEF,MAAM,SAAS,MAAM,SAAS,UAAU;GACxC,OAAO,IAAI,oBAAoB;IAC7B;IACA,mBACE,SAAS,qBAAqB,OAAO;IACvC,SAAS,QAAQ;IACjB,kBAAkB,EAAE,GAAG,QAAQ,iBAAiB;GAClD,CAAC;EACH;EACA,WAAW,SAAiC;GAC1C,OAAO,OAAO,UAAU,OAAO;EACjC;CACF;AACF"}
@@ -1,6 +1,7 @@
1
1
  import { callStellarRpcsWithRetry } from "../client/getStellarRpc.js";
2
2
  import { withDedupe } from "@lifi/sdk";
3
- import { Account, Address, BASE_FEE, Contract, Networks, TransactionBuilder, rpc, scValToNative } from "@stellar/stellar-sdk";
3
+ import { Account, Address, BASE_FEE, Contract, Networks, TransactionBuilder, scValToNative } from "@stellar/stellar-sdk";
4
+ import { Api } from "@stellar/stellar-sdk/rpc";
4
5
  //#region src/actions/getStellarBalance.ts
5
6
  /**
6
7
  * Fetches Stellar token balances for a wallet.
@@ -13,10 +14,18 @@ import { Account, Address, BASE_FEE, Contract, Networks, TransactionBuilder, rpc
13
14
  */
14
15
  const getStellarBalance = async (client, walletAddress, tokens, networkPassphrase = Networks.PUBLIC) => {
15
16
  if (tokens.length === 0) return [];
16
- const results = await Promise.all(tokens.map((token) => withDedupe(() => getSacBalance(client, walletAddress, token, networkPassphrase), { id: `${getStellarBalance.name}.${walletAddress}.${token.address}` }).catch(() => void 0)));
17
- const fallbackBlockNumber = results.reduce((latest, result) => result && (latest === void 0 || result.latestLedger > latest) ? result.latestLedger : latest, void 0);
17
+ const results = await Promise.all(tokens.map((token) => withDedupe(() => getSacBalance(client, walletAddress, token, networkPassphrase), { id: `${getStellarBalance.name}.${walletAddress}.${token.address}` }).then((value) => ({
18
+ value,
19
+ error: void 0
20
+ }), (error) => ({
21
+ value: void 0,
22
+ error: error instanceof Error ? error : new Error(String(error))
23
+ }))));
24
+ const firstError = results.find((result) => result.error)?.error;
25
+ if (firstError && results.every((result) => !result.value)) throw firstError;
26
+ const fallbackBlockNumber = results.reduce((latest, result) => result.value && (latest === void 0 || result.value.latestLedger > latest) ? result.value.latestLedger : latest, void 0);
18
27
  return tokens.map((token, index) => {
19
- const result = results[index];
28
+ const result = results[index].value;
20
29
  const blockNumber = result?.latestLedger ?? fallbackBlockNumber;
21
30
  return result?.amount !== void 0 ? {
22
31
  ...token,
@@ -44,7 +53,7 @@ const getSacBalance = async (client, walletAddress, token, networkPassphrase) =>
44
53
  }).addOperation(contract.call("balance", Address.fromString(walletAddress).toScVal())).setTimeout(30).build();
45
54
  const simulation = await server.simulateTransaction(transaction);
46
55
  const latestLedger = BigInt(simulation.latestLedger);
47
- if (!rpc.Api.isSimulationSuccess(simulation) || !simulation.result) return {
56
+ if (!Api.isSimulationSuccess(simulation) || !simulation.result) return {
48
57
  amount: void 0,
49
58
  latestLedger
50
59
  };
@@ -1 +1 @@
1
- {"version":3,"file":"getStellarBalance.js","names":[],"sources":["../../../src/actions/getStellarBalance.ts"],"sourcesContent":["import {\n type SDKClient,\n type Token,\n type TokenAmount,\n withDedupe,\n} from '@lifi/sdk'\nimport {\n Account,\n Address,\n BASE_FEE,\n Contract,\n Networks,\n rpc,\n scValToNative,\n TransactionBuilder,\n} from '@stellar/stellar-sdk'\nimport { callStellarRpcsWithRetry } from '../client/getStellarRpc.js'\n\ntype SacBalanceResult = {\n /** Absent when the balance could not be read. */\n amount: bigint | undefined\n /** Ledger the simulation was evaluated against. */\n latestLedger: bigint\n}\n\n/**\n * Fetches Stellar token balances for a wallet.\n *\n * Every LI.FI Stellar token — including native XLM — is addressed by its Soroban\n * Stellar-Asset-Contract (SAC) `C`-address (see backend EXBE-245). We therefore\n * read each balance uniformly by simulating the SAC `balance(account)` call over\n * Stellar RPC, which works for native XLM, wrapped classic assets, and\n * Soroban-native tokens alike.\n */\nexport const getStellarBalance = async (\n client: SDKClient,\n walletAddress: string,\n tokens: Token[],\n networkPassphrase: string = Networks.PUBLIC\n): Promise<TokenAmount[]> => {\n if (tokens.length === 0) {\n return []\n }\n\n const results = await Promise.all(\n tokens.map((token) =>\n withDedupe(\n () => getSacBalance(client, walletAddress, token, networkPassphrase),\n { id: `${getStellarBalance.name}.${walletAddress}.${token.address}` }\n ).catch(() => undefined)\n )\n )\n\n // Consumers treat a missing blockNumber as an unsettled read and keep\n // polling, so every token must carry one. The ledger rides along on the\n // simulation response; a token whose read threw borrows the batch's newest.\n const fallbackBlockNumber = results.reduce<bigint | undefined>(\n (latest, result) =>\n result && (latest === undefined || result.latestLedger > latest)\n ? result.latestLedger\n : latest,\n undefined\n )\n\n return tokens.map((token, index) => {\n const result = results[index]\n const blockNumber = result?.latestLedger ?? fallbackBlockNumber\n return result?.amount !== undefined\n ? { ...token, amount: result.amount, blockNumber }\n : { ...token, blockNumber }\n })\n}\n\n/**\n * Simulates a read-only `balance(account)` call on the token's SAC and decodes\n * the returned i128 into a bigint. The amount is `undefined` when the balance\n * cannot be read (e.g. contract not found, account not funded); the ledger the\n * simulation ran against is reported either way.\n */\nconst getSacBalance = async (\n client: SDKClient,\n walletAddress: string,\n token: Token,\n networkPassphrase: string\n): Promise<SacBalanceResult> => {\n return callStellarRpcsWithRetry(client, async (server) => {\n // A zero-sequence account is sufficient for read-only simulation.\n const source = new Account(walletAddress, '0')\n const contract = new Contract(token.address)\n const transaction = new TransactionBuilder(source, {\n fee: BASE_FEE,\n networkPassphrase,\n })\n .addOperation(\n contract.call('balance', Address.fromString(walletAddress).toScVal())\n )\n .setTimeout(30)\n .build()\n\n const simulation = await server.simulateTransaction(transaction)\n const latestLedger = BigInt(simulation.latestLedger)\n if (!rpc.Api.isSimulationSuccess(simulation) || !simulation.result) {\n return { amount: undefined, latestLedger }\n }\n const value = scValToNative(simulation.result.retval)\n return {\n amount: value != null ? BigInt(value) : undefined,\n latestLedger,\n }\n })\n}\n"],"mappings":";;;;;;;;;;;;;AAkCA,MAAa,oBAAoB,OAC/B,QACA,eACA,QACA,oBAA4B,SAAS,WACV;CAC3B,IAAI,OAAO,WAAW,GACpB,OAAO,CAAC;CAGV,MAAM,UAAU,MAAM,QAAQ,IAC5B,OAAO,KAAK,UACV,iBACQ,cAAc,QAAQ,eAAe,OAAO,iBAAiB,GACnE,EAAE,IAAI,GAAG,kBAAkB,KAAK,GAAG,cAAc,GAAG,MAAM,UAAU,CACtE,CAAC,CAAC,YAAY,KAAA,CAAS,CACzB,CACF;CAKA,MAAM,sBAAsB,QAAQ,QACjC,QAAQ,WACP,WAAW,WAAW,KAAA,KAAa,OAAO,eAAe,UACrD,OAAO,eACP,QACN,KAAA,CACF;CAEA,OAAO,OAAO,KAAK,OAAO,UAAU;EAClC,MAAM,SAAS,QAAQ;EACvB,MAAM,cAAc,QAAQ,gBAAgB;EAC5C,OAAO,QAAQ,WAAW,KAAA,IACtB;GAAE,GAAG;GAAO,QAAQ,OAAO;GAAQ;EAAY,IAC/C;GAAE,GAAG;GAAO;EAAY;CAC9B,CAAC;AACH;;;;;;;AAQA,MAAM,gBAAgB,OACpB,QACA,eACA,OACA,sBAC8B;CAC9B,OAAO,yBAAyB,QAAQ,OAAO,WAAW;EAExD,MAAM,SAAS,IAAI,QAAQ,eAAe,GAAG;EAC7C,MAAM,WAAW,IAAI,SAAS,MAAM,OAAO;EAC3C,MAAM,cAAc,IAAI,mBAAmB,QAAQ;GACjD,KAAK;GACL;EACF,CAAC,CAAC,CACC,aACC,SAAS,KAAK,WAAW,QAAQ,WAAW,aAAa,CAAC,CAAC,QAAQ,CAAC,CACtE,CAAC,CACA,WAAW,EAAE,CAAC,CACd,MAAM;EAET,MAAM,aAAa,MAAM,OAAO,oBAAoB,WAAW;EAC/D,MAAM,eAAe,OAAO,WAAW,YAAY;EACnD,IAAI,CAAC,IAAI,IAAI,oBAAoB,UAAU,KAAK,CAAC,WAAW,QAC1D,OAAO;GAAE,QAAQ,KAAA;GAAW;EAAa;EAE3C,MAAM,QAAQ,cAAc,WAAW,OAAO,MAAM;EACpD,OAAO;GACL,QAAQ,SAAS,OAAO,OAAO,KAAK,IAAI,KAAA;GACxC;EACF;CACF,CAAC;AACH"}
1
+ {"version":3,"file":"getStellarBalance.js","names":[],"sources":["../../../src/actions/getStellarBalance.ts"],"sourcesContent":["import {\n type SDKClient,\n type Token,\n type TokenAmount,\n withDedupe,\n} from '@lifi/sdk'\nimport {\n Account,\n Address,\n BASE_FEE,\n Contract,\n Networks,\n scValToNative,\n TransactionBuilder,\n} from '@stellar/stellar-sdk'\nimport { Api } from '@stellar/stellar-sdk/rpc'\nimport { callStellarRpcsWithRetry } from '../client/getStellarRpc.js'\n\ntype SacBalanceResult = {\n /** Absent when the balance could not be read. */\n amount: bigint | undefined\n /** Ledger the simulation was evaluated against. */\n latestLedger: bigint\n}\n\n/**\n * Fetches Stellar token balances for a wallet.\n *\n * Every LI.FI Stellar token — including native XLM — is addressed by its Soroban\n * Stellar-Asset-Contract (SAC) `C`-address (see backend EXBE-245). We therefore\n * read each balance uniformly by simulating the SAC `balance(account)` call over\n * Stellar RPC, which works for native XLM, wrapped classic assets, and\n * Soroban-native tokens alike.\n */\nexport const getStellarBalance = async (\n client: SDKClient,\n walletAddress: string,\n tokens: Token[],\n networkPassphrase: string = Networks.PUBLIC\n): Promise<TokenAmount[]> => {\n if (tokens.length === 0) {\n return []\n }\n\n const results = await Promise.all(\n tokens.map((token) =>\n withDedupe(\n () => getSacBalance(client, walletAddress, token, networkPassphrase),\n { id: `${getStellarBalance.name}.${walletAddress}.${token.address}` }\n ).then(\n (value) => ({ value, error: undefined as Error | undefined }),\n (error) => ({\n value: undefined,\n error: error instanceof Error ? error : new Error(String(error)),\n })\n )\n )\n )\n\n // Every read failed — the RPC list is unreachable, or the chain is not served\n // at all. Returning tokens with neither an amount nor a blockNumber reads to\n // consumers as a balance that has yet to settle, so they would poll forever\n // instead of seeing the failure.\n const firstError = results.find((result) => result.error)?.error\n if (firstError && results.every((result) => !result.value)) {\n throw firstError\n }\n\n // Consumers treat a missing blockNumber as an unsettled read and keep\n // polling, so every token must carry one. The ledger rides along on the\n // simulation response; a token whose read threw borrows the batch's newest.\n const fallbackBlockNumber = results.reduce<bigint | undefined>(\n (latest, result) =>\n result.value &&\n (latest === undefined || result.value.latestLedger > latest)\n ? result.value.latestLedger\n : latest,\n undefined\n )\n\n return tokens.map((token, index) => {\n const result = results[index].value\n const blockNumber = result?.latestLedger ?? fallbackBlockNumber\n return result?.amount !== undefined\n ? { ...token, amount: result.amount, blockNumber }\n : { ...token, blockNumber }\n })\n}\n\n/**\n * Simulates a read-only `balance(account)` call on the token's SAC and decodes\n * the returned i128 into a bigint. The amount is `undefined` when the balance\n * cannot be read (e.g. contract not found, account not funded); the ledger the\n * simulation ran against is reported either way.\n */\nconst getSacBalance = async (\n client: SDKClient,\n walletAddress: string,\n token: Token,\n networkPassphrase: string\n): Promise<SacBalanceResult> => {\n return callStellarRpcsWithRetry(client, async (server) => {\n // A zero-sequence account is sufficient for read-only simulation.\n const source = new Account(walletAddress, '0')\n const contract = new Contract(token.address)\n const transaction = new TransactionBuilder(source, {\n fee: BASE_FEE,\n networkPassphrase,\n })\n .addOperation(\n contract.call('balance', Address.fromString(walletAddress).toScVal())\n )\n .setTimeout(30)\n .build()\n\n const simulation = await server.simulateTransaction(transaction)\n const latestLedger = BigInt(simulation.latestLedger)\n if (!Api.isSimulationSuccess(simulation) || !simulation.result) {\n return { amount: undefined, latestLedger }\n }\n const value = scValToNative(simulation.result.retval)\n return {\n amount: value != null ? BigInt(value) : undefined,\n latestLedger,\n }\n })\n}\n"],"mappings":";;;;;;;;;;;;;;AAkCA,MAAa,oBAAoB,OAC/B,QACA,eACA,QACA,oBAA4B,SAAS,WACV;CAC3B,IAAI,OAAO,WAAW,GACpB,OAAO,CAAC;CAGV,MAAM,UAAU,MAAM,QAAQ,IAC5B,OAAO,KAAK,UACV,iBACQ,cAAc,QAAQ,eAAe,OAAO,iBAAiB,GACnE,EAAE,IAAI,GAAG,kBAAkB,KAAK,GAAG,cAAc,GAAG,MAAM,UAAU,CACtE,CAAC,CAAC,MACC,WAAW;EAAE;EAAO,OAAO,KAAA;CAA+B,KAC1D,WAAW;EACV,OAAO,KAAA;EACP,OAAO,iBAAiB,QAAQ,QAAQ,IAAI,MAAM,OAAO,KAAK,CAAC;CACjE,EACF,CACF,CACF;CAMA,MAAM,aAAa,QAAQ,MAAM,WAAW,OAAO,KAAK,CAAC,EAAE;CAC3D,IAAI,cAAc,QAAQ,OAAO,WAAW,CAAC,OAAO,KAAK,GACvD,MAAM;CAMR,MAAM,sBAAsB,QAAQ,QACjC,QAAQ,WACP,OAAO,UACN,WAAW,KAAA,KAAa,OAAO,MAAM,eAAe,UACjD,OAAO,MAAM,eACb,QACN,KAAA,CACF;CAEA,OAAO,OAAO,KAAK,OAAO,UAAU;EAClC,MAAM,SAAS,QAAQ,MAAM,CAAC;EAC9B,MAAM,cAAc,QAAQ,gBAAgB;EAC5C,OAAO,QAAQ,WAAW,KAAA,IACtB;GAAE,GAAG;GAAO,QAAQ,OAAO;GAAQ;EAAY,IAC/C;GAAE,GAAG;GAAO;EAAY;CAC9B,CAAC;AACH;;;;;;;AAQA,MAAM,gBAAgB,OACpB,QACA,eACA,OACA,sBAC8B;CAC9B,OAAO,yBAAyB,QAAQ,OAAO,WAAW;EAExD,MAAM,SAAS,IAAI,QAAQ,eAAe,GAAG;EAC7C,MAAM,WAAW,IAAI,SAAS,MAAM,OAAO;EAC3C,MAAM,cAAc,IAAI,mBAAmB,QAAQ;GACjD,KAAK;GACL;EACF,CAAC,CAAC,CACC,aACC,SAAS,KAAK,WAAW,QAAQ,WAAW,aAAa,CAAC,CAAC,QAAQ,CAAC,CACtE,CAAC,CACA,WAAW,EAAE,CAAC,CACd,MAAM;EAET,MAAM,aAAa,MAAM,OAAO,oBAAoB,WAAW;EAC/D,MAAM,eAAe,OAAO,WAAW,YAAY;EACnD,IAAI,CAAC,IAAI,oBAAoB,UAAU,KAAK,CAAC,WAAW,QACtD,OAAO;GAAE,QAAQ,KAAA;GAAW;EAAa;EAE3C,MAAM,QAAQ,cAAc,WAAW,OAAO,MAAM;EACpD,OAAO;GACL,QAAQ,SAAS,OAAO,OAAO,KAAK,IAAI,KAAA;GACxC;EACF;CACF,CAAC;AACH"}
@@ -2,7 +2,14 @@
2
2
  /**
3
3
  * Resolves a Stellar Federation address (SEP-2, `name*domain.com`) to a G-address.
4
4
  * Returns the input unchanged when it is already a valid G-address, and
5
- * `undefined` when it is neither a federation address nor resolvable.
5
+ * `undefined` when it is neither a federation address nor safely resolvable.
6
+ *
7
+ * `Federation` is imported statically on purpose. Loading it through
8
+ * `await import('@stellar/stellar-sdk')` was measured at +110 KB in the initial
9
+ * chunk: a dynamic import of the root asks for the whole namespace, which
10
+ * cannot be tree-shaken, so Horizon, WebAuth, Friendbot and StellarToml all
11
+ * materialise — and the entry's own static import of the root keeps that chunk
12
+ * eager anyway.
6
13
  */
7
14
  declare function resolveStellarAddress(name: string): Promise<string | undefined>;
8
15
  //#endregion
@@ -1 +1 @@
1
- {"version":3,"file":"resolveStellarAddress.d.ts","names":[],"sources":["../../../src/actions/resolveStellarAddress.ts"],"mappings":";;;;;;iBAOsB,sBACpB,eACC"}
1
+ {"version":3,"file":"resolveStellarAddress.d.ts","names":[],"sources":["../../../src/actions/resolveStellarAddress.ts"],"mappings":";;;;;;;;;;;;;iBAcsB,sBACpB,eACC"}
@@ -3,13 +3,22 @@ import { Federation, StrKey } from "@stellar/stellar-sdk";
3
3
  /**
4
4
  * Resolves a Stellar Federation address (SEP-2, `name*domain.com`) to a G-address.
5
5
  * Returns the input unchanged when it is already a valid G-address, and
6
- * `undefined` when it is neither a federation address nor resolvable.
6
+ * `undefined` when it is neither a federation address nor safely resolvable.
7
+ *
8
+ * `Federation` is imported statically on purpose. Loading it through
9
+ * `await import('@stellar/stellar-sdk')` was measured at +110 KB in the initial
10
+ * chunk: a dynamic import of the root asks for the whole namespace, which
11
+ * cannot be tree-shaken, so Horizon, WebAuth, Friendbot and StellarToml all
12
+ * materialise — and the entry's own static import of the root keeps that chunk
13
+ * eager anyway.
7
14
  */
8
15
  async function resolveStellarAddress(name) {
9
16
  if (StrKey.isValidEd25519PublicKey(name)) return name;
10
17
  if (!name.includes("*")) return;
11
18
  try {
12
- return (await Federation.Server.resolve(name)).account_id;
19
+ const record = await Federation.Server.resolve(name);
20
+ if (record.memo || record.memo_type) return;
21
+ return StrKey.isValidEd25519PublicKey(record.account_id) ? record.account_id : void 0;
13
22
  } catch {
14
23
  return;
15
24
  }
@@ -1 +1 @@
1
- {"version":3,"file":"resolveStellarAddress.js","names":[],"sources":["../../../src/actions/resolveStellarAddress.ts"],"sourcesContent":["import { Federation, StrKey } from '@stellar/stellar-sdk'\n\n/**\n * Resolves a Stellar Federation address (SEP-2, `name*domain.com`) to a G-address.\n * Returns the input unchanged when it is already a valid G-address, and\n * `undefined` when it is neither a federation address nor resolvable.\n */\nexport async function resolveStellarAddress(\n name: string\n): Promise<string | undefined> {\n if (StrKey.isValidEd25519PublicKey(name)) {\n return name\n }\n if (!name.includes('*')) {\n return undefined\n }\n try {\n const record = await Federation.Server.resolve(name)\n return record.account_id\n } catch {\n return undefined\n }\n}\n"],"mappings":";;;;;;;AAOA,eAAsB,sBACpB,MAC6B;CAC7B,IAAI,OAAO,wBAAwB,IAAI,GACrC,OAAO;CAET,IAAI,CAAC,KAAK,SAAS,GAAG,GACpB;CAEF,IAAI;EAEF,QAAO,MADc,WAAW,OAAO,QAAQ,IAAI,EAAA,CACrC;CAChB,QAAQ;EACN;CACF;AACF"}
1
+ {"version":3,"file":"resolveStellarAddress.js","names":[],"sources":["../../../src/actions/resolveStellarAddress.ts"],"sourcesContent":["import { Federation, StrKey } from '@stellar/stellar-sdk'\n\n/**\n * Resolves a Stellar Federation address (SEP-2, `name*domain.com`) to a G-address.\n * Returns the input unchanged when it is already a valid G-address, and\n * `undefined` when it is neither a federation address nor safely resolvable.\n *\n * `Federation` is imported statically on purpose. Loading it through\n * `await import('@stellar/stellar-sdk')` was measured at +110 KB in the initial\n * chunk: a dynamic import of the root asks for the whole namespace, which\n * cannot be tree-shaken, so Horizon, WebAuth, Friendbot and StellarToml all\n * materialise — and the entry's own static import of the root keeps that chunk\n * eager anyway.\n */\nexport async function resolveStellarAddress(\n name: string\n): Promise<string | undefined> {\n if (StrKey.isValidEd25519PublicKey(name)) {\n return name\n }\n if (!name.includes('*')) {\n return undefined\n }\n try {\n const record = await Federation.Server.resolve(name)\n // A memo is part of the destination for a custodial account, and neither\n // the SDK nor the route request can carry one. Resolving to the bare pooled\n // address would deliver funds nobody can attribute, so refuse instead.\n if (record.memo || record.memo_type) {\n return undefined\n }\n // The record comes from an arbitrary remote federation server. Re-apply the\n // G-address-only rule `isStellarAddress` exists to enforce.\n return StrKey.isValidEd25519PublicKey(record.account_id)\n ? record.account_id\n : undefined\n } catch {\n return undefined\n }\n}\n"],"mappings":";;;;;;;;;;;;;;AAcA,eAAsB,sBACpB,MAC6B;CAC7B,IAAI,OAAO,wBAAwB,IAAI,GACrC,OAAO;CAET,IAAI,CAAC,KAAK,SAAS,GAAG,GACpB;CAEF,IAAI;EACF,MAAM,SAAS,MAAM,WAAW,OAAO,QAAQ,IAAI;EAInD,IAAI,OAAO,QAAQ,OAAO,WACxB;EAIF,OAAO,OAAO,wBAAwB,OAAO,UAAU,IACnD,OAAO,aACP,KAAA;CACN,QAAQ;EACN;CACF;AACF"}
@@ -1,12 +1,12 @@
1
1
  import { SDKClient } from "@lifi/sdk";
2
- import { rpc } from "@stellar/stellar-sdk";
2
+ import { Server } from "@stellar/stellar-sdk/rpc";
3
3
  //#region src/client/getStellarRpc.d.ts
4
- declare const getStellarRpcs: (client: SDKClient) => Promise<rpc.Server[]>;
4
+ declare const getStellarRpcs: (client: SDKClient) => Promise<Server[]>;
5
5
  /**
6
6
  * Calls a function on Stellar RPC instances with retry logic. Tries each RPC in
7
7
  * sequence until one succeeds.
8
8
  */
9
- declare const callStellarRpcsWithRetry: <R>(client: SDKClient, fn: (server: rpc.Server) => Promise<R>) => Promise<R>;
9
+ declare const callStellarRpcsWithRetry: <R>(client: SDKClient, fn: (server: Server) => Promise<R>) => Promise<R>;
10
10
  //#endregion
11
11
  export { callStellarRpcsWithRetry, getStellarRpcs };
12
12
  //# sourceMappingURL=getStellarRpc.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"getStellarRpc.d.ts","names":[],"sources":["../../../src/client/getStellarRpc.ts"],"mappings":";;;cAmBa,iBACX,QAAQ,cACP,QAAQ,IAAI;;;;;cAWF,2BAAkC,GAC7C,QAAQ,WACR,KAAK,QAAQ,IAAI,WAAW,QAAQ,OACnC,QAAQ"}
1
+ {"version":3,"file":"getStellarRpc.d.ts","names":[],"sources":["../../../src/client/getStellarRpc.ts"],"mappings":";;;cAmBa,iBAAwB,QAAQ,cAAY,QAAQ;;;;;cAWpD,2BAAkC,GAC7C,QAAQ,WACR,KAAK,QAAQ,WAAW,QAAQ,OAC/B,QAAQ"}
@@ -1,5 +1,5 @@
1
1
  import { ChainId, LruMap } from "@lifi/sdk";
2
- import { rpc } from "@stellar/stellar-sdk";
2
+ import { Server } from "@stellar/stellar-sdk/rpc";
3
3
  //#region src/client/getStellarRpc.ts
4
4
  const stellarRpcs = new LruMap(12);
5
5
  /**
@@ -8,7 +8,7 @@ const stellarRpcs = new LruMap(12);
8
8
  */
9
9
  const ensureStellarRpcs = async (client) => {
10
10
  const rpcUrls = await client.getRpcUrlsByChainId(ChainId.XLM);
11
- for (const rpcUrl of rpcUrls) if (!stellarRpcs.has(rpcUrl)) stellarRpcs.set(rpcUrl, new rpc.Server(rpcUrl, { allowHttp: true }));
11
+ for (const rpcUrl of rpcUrls) if (!stellarRpcs.has(rpcUrl)) stellarRpcs.set(rpcUrl, new Server(rpcUrl, { allowHttp: true }));
12
12
  return rpcUrls;
13
13
  };
14
14
  const getStellarRpcs = async (client) => {
@@ -1 +1 @@
1
- {"version":3,"file":"getStellarRpc.js","names":[],"sources":["../../../src/client/getStellarRpc.ts"],"sourcesContent":["import { ChainId, LruMap, type SDKClient } from '@lifi/sdk'\nimport { rpc } from '@stellar/stellar-sdk'\n\nconst stellarRpcs = new LruMap<rpc.Server>(12)\n\n/**\n * Resolves and caches a Stellar RPC (JSON-RPC / Soroban RPC) server for each RPC\n * URL configured for the Stellar chain on the SDK client.\n */\nconst ensureStellarRpcs = async (client: SDKClient): Promise<string[]> => {\n const rpcUrls = await client.getRpcUrlsByChainId(ChainId.XLM)\n for (const rpcUrl of rpcUrls) {\n if (!stellarRpcs.has(rpcUrl)) {\n stellarRpcs.set(rpcUrl, new rpc.Server(rpcUrl, { allowHttp: true }))\n }\n }\n return rpcUrls\n}\n\nexport const getStellarRpcs = async (\n client: SDKClient\n): Promise<rpc.Server[]> => {\n const rpcUrls = await ensureStellarRpcs(client)\n return rpcUrls\n .map((rpcUrl) => stellarRpcs.get(rpcUrl))\n .filter((server): server is rpc.Server => Boolean(server))\n}\n\n/**\n * Calls a function on Stellar RPC instances with retry logic. Tries each RPC in\n * sequence until one succeeds.\n */\nexport const callStellarRpcsWithRetry = async <R>(\n client: SDKClient,\n fn: (server: rpc.Server) => Promise<R>\n): Promise<R> => {\n const servers = await getStellarRpcs(client)\n if (servers.length === 0) {\n throw new Error('No Stellar RPCs available')\n }\n const errors: Error[] = []\n for (const server of servers) {\n try {\n return await fn(server)\n } catch (error) {\n errors.push(error instanceof Error ? error : new Error(String(error)))\n }\n }\n throw new AggregateError(errors, `All ${servers.length} Stellar RPCs failed`)\n}\n"],"mappings":";;;AAGA,MAAM,cAAc,IAAI,OAAmB,EAAE;;;;;AAM7C,MAAM,oBAAoB,OAAO,WAAyC;CACxE,MAAM,UAAU,MAAM,OAAO,oBAAoB,QAAQ,GAAG;CAC5D,KAAK,MAAM,UAAU,SACnB,IAAI,CAAC,YAAY,IAAI,MAAM,GACzB,YAAY,IAAI,QAAQ,IAAI,IAAI,OAAO,QAAQ,EAAE,WAAW,KAAK,CAAC,CAAC;CAGvE,OAAO;AACT;AAEA,MAAa,iBAAiB,OAC5B,WAC0B;CAE1B,QAAO,MADe,kBAAkB,MAAM,EAAA,CAE3C,KAAK,WAAW,YAAY,IAAI,MAAM,CAAC,CAAC,CACxC,QAAQ,WAAiC,QAAQ,MAAM,CAAC;AAC7D;;;;;AAMA,MAAa,2BAA2B,OACtC,QACA,OACe;CACf,MAAM,UAAU,MAAM,eAAe,MAAM;CAC3C,IAAI,QAAQ,WAAW,GACrB,MAAM,IAAI,MAAM,2BAA2B;CAE7C,MAAM,SAAkB,CAAC;CACzB,KAAK,MAAM,UAAU,SACnB,IAAI;EACF,OAAO,MAAM,GAAG,MAAM;CACxB,SAAS,OAAO;EACd,OAAO,KAAK,iBAAiB,QAAQ,QAAQ,IAAI,MAAM,OAAO,KAAK,CAAC,CAAC;CACvE;CAEF,MAAM,IAAI,eAAe,QAAQ,OAAO,QAAQ,OAAO,qBAAqB;AAC9E"}
1
+ {"version":3,"file":"getStellarRpc.js","names":[],"sources":["../../../src/client/getStellarRpc.ts"],"sourcesContent":["import { ChainId, LruMap, type SDKClient } from '@lifi/sdk'\nimport { Server } from '@stellar/stellar-sdk/rpc'\n\nconst stellarRpcs = new LruMap<Server>(12)\n\n/**\n * Resolves and caches a Stellar RPC (JSON-RPC / Soroban RPC) server for each RPC\n * URL configured for the Stellar chain on the SDK client.\n */\nconst ensureStellarRpcs = async (client: SDKClient): Promise<string[]> => {\n const rpcUrls = await client.getRpcUrlsByChainId(ChainId.XLM)\n for (const rpcUrl of rpcUrls) {\n if (!stellarRpcs.has(rpcUrl)) {\n stellarRpcs.set(rpcUrl, new Server(rpcUrl, { allowHttp: true }))\n }\n }\n return rpcUrls\n}\n\nexport const getStellarRpcs = async (client: SDKClient): Promise<Server[]> => {\n const rpcUrls = await ensureStellarRpcs(client)\n return rpcUrls\n .map((rpcUrl) => stellarRpcs.get(rpcUrl))\n .filter((server): server is Server => Boolean(server))\n}\n\n/**\n * Calls a function on Stellar RPC instances with retry logic. Tries each RPC in\n * sequence until one succeeds.\n */\nexport const callStellarRpcsWithRetry = async <R>(\n client: SDKClient,\n fn: (server: Server) => Promise<R>\n): Promise<R> => {\n const servers = await getStellarRpcs(client)\n if (servers.length === 0) {\n throw new Error('No Stellar RPCs available')\n }\n const errors: Error[] = []\n for (const server of servers) {\n try {\n return await fn(server)\n } catch (error) {\n errors.push(error instanceof Error ? error : new Error(String(error)))\n }\n }\n throw new AggregateError(errors, `All ${servers.length} Stellar RPCs failed`)\n}\n"],"mappings":";;;AAGA,MAAM,cAAc,IAAI,OAAe,EAAE;;;;;AAMzC,MAAM,oBAAoB,OAAO,WAAyC;CACxE,MAAM,UAAU,MAAM,OAAO,oBAAoB,QAAQ,GAAG;CAC5D,KAAK,MAAM,UAAU,SACnB,IAAI,CAAC,YAAY,IAAI,MAAM,GACzB,YAAY,IAAI,QAAQ,IAAI,OAAO,QAAQ,EAAE,WAAW,KAAK,CAAC,CAAC;CAGnE,OAAO;AACT;AAEA,MAAa,iBAAiB,OAAO,WAAyC;CAE5E,QAAO,MADe,kBAAkB,MAAM,EAAA,CAE3C,KAAK,WAAW,YAAY,IAAI,MAAM,CAAC,CAAC,CACxC,QAAQ,WAA6B,QAAQ,MAAM,CAAC;AACzD;;;;;AAMA,MAAa,2BAA2B,OACtC,QACA,OACe;CACf,MAAM,UAAU,MAAM,eAAe,MAAM;CAC3C,IAAI,QAAQ,WAAW,GACrB,MAAM,IAAI,MAAM,2BAA2B;CAE7C,MAAM,SAAkB,CAAC;CACzB,KAAK,MAAM,UAAU,SACnB,IAAI;EACF,OAAO,MAAM,GAAG,MAAM;CACxB,SAAS,OAAO;EACd,OAAO,KAAK,iBAAiB,QAAQ,QAAQ,IAAI,MAAM,OAAO,KAAK,CAAC,CAAC;CACvE;CAEF,MAAM,IAAI,eAAe,QAAQ,OAAO,QAAQ,OAAO,qBAAqB;AAC9E"}
@@ -1 +1 @@
1
- {"version":3,"file":"StellarStepExecutor.d.ts","names":[],"sources":["../../../src/core/StellarStepExecutor.ts"],"mappings":";;;cAwBa,4BAA4B;UAC/B;UACA;EAER,YAAY,SAAS;EAMrB,cAAe,MAAM;WAUZ,cACP,OAAO,OACP,OAAO,kBACP,SAAS,oBACR,QAAQ;WAEF,gBACP,aAAa,4BACZ,QAAQ;WAUF,iBACP,SAAS,+BACR"}
1
+ {"version":3,"file":"StellarStepExecutor.d.ts","names":[],"sources":["../../../src/core/StellarStepExecutor.ts"],"mappings":";;;cAwBa,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"}
@@ -16,6 +16,7 @@ var StellarStepExecutor = class extends BaseStepExecutor {
16
16
  }
17
17
  checkWallet = (step) => {
18
18
  if (this.wallet.address !== step.action.fromAddress) throw new TransactionError(LiFiErrorCode.WalletChangedDuringExecution, "The wallet address that requested the quote does not match the wallet address attempting to sign the transaction.");
19
+ if (this.networkPassphrase !== this.wallet.networkPassphrase) throw new TransactionError(LiFiErrorCode.ChainSwitchError, "The connected Stellar wallet is on a different network than the route.");
19
20
  };
20
21
  parseErrors = (error, step, action) => parseStellarErrors(error, step, action);
21
22
  createContext = async (baseContext) => {
@@ -41,7 +42,8 @@ var StellarStepExecutor = class extends BaseStepExecutor {
41
42
  const swapOrBridgeAction = this.statusManager.findAction(step, isBridgeExecution ? "CROSS_CHAIN" : "SWAP");
42
43
  const taskName = swapOrBridgeAction?.txHash ? swapOrBridgeAction.status === "DONE" ? WaitForTransactionStatusTask.name : StellarWaitForTransactionTask.name : CheckBalanceTask.name;
43
44
  const firstTaskIndex = tasks.findIndex((task) => task.constructor.name === taskName);
44
- return new TaskPipeline(tasks.slice(firstTaskIndex));
45
+ const tasksToRun = tasks.slice(firstTaskIndex);
46
+ return new TaskPipeline(tasksToRun);
45
47
  };
46
48
  };
47
49
  //#endregion
@@ -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\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 taskName = swapOrBridgeAction?.txHash\n ? swapOrBridgeAction.status === 'DONE'\n ? WaitForTransactionStatusTask.name\n : StellarWaitForTransactionTask.name\n : CheckBalanceTask.name\n\n const firstTaskIndex = tasks.findIndex(\n (task) => task.constructor.name === taskName\n )\n\n const tasksToRun = tasks.slice(firstTaskIndex)\n\n return new TaskPipeline(tasksToRun)\n }\n}\n"],"mappings":";;;;;;;;AAwBA,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;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;EAQA,MAAM,WAAW,oBAAoB,SACjC,mBAAmB,WAAW,SAC5B,6BAA6B,OAC7B,8BAA8B,OAChC,iBAAiB;EAErB,MAAM,iBAAiB,MAAM,WAC1B,SAAS,KAAK,YAAY,SAAS,QACtC;EAIA,OAAO,IAAI,aAFQ,MAAM,MAAM,cAEE,CAAC;CACpC;AACF"}
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 taskName = swapOrBridgeAction?.txHash\n ? swapOrBridgeAction.status === 'DONE'\n ? WaitForTransactionStatusTask.name\n : StellarWaitForTransactionTask.name\n : CheckBalanceTask.name\n\n const firstTaskIndex = tasks.findIndex(\n (task) => task.constructor.name === taskName\n )\n\n const tasksToRun = tasks.slice(firstTaskIndex)\n\n return new TaskPipeline(tasksToRun)\n }\n}\n"],"mappings":";;;;;;;;AAwBA,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;EAQA,MAAM,WAAW,oBAAoB,SACjC,mBAAmB,WAAW,SAC5B,6BAA6B,OAC7B,8BAA8B,OAChC,iBAAiB;EAErB,MAAM,iBAAiB,MAAM,WAC1B,SAAS,KAAK,YAAY,SAAS,QACtC;EAEA,MAAM,aAAa,MAAM,MAAM,cAAc;EAE7C,OAAO,IAAI,aAAa,UAAU;CACpC;AACF"}
@@ -1,26 +1,33 @@
1
1
  import { StellarStepExecutorContext } from "../../types.js";
2
- import { BaseStepExecutionTask, TaskResult } from "@lifi/sdk";
2
+ import { PrepareTransactionTask, TaskResult } from "@lifi/sdk";
3
3
  //#region src/core/tasks/StellarPrepareTransactionTask.d.ts
4
4
  /**
5
- * Re-fetches the step transaction from the backend, **unconditionally**.
5
+ * Always re-fetches the step transaction, where the base task asks only when
6
+ * the step carries none.
6
7
  *
7
- * Do not reintroduce the base task's `if (!step.transactionRequest)` guard. A
8
- * Stellar envelope is not a reusable payload: the backend embeds the sender's
9
- * account sequence number and timebounds `[0, now + 300s]` at build time. Two
10
- * things follow.
8
+ * A Stellar envelope is not a reusable payload: the backend embeds the sender's
9
+ * account sequence number and timebounds `[0, now + 300s]` at build time.
11
10
  *
12
- * 1. Staleness. On the quote path `convertQuoteToRoute` carries the quote's
13
- * `transactionRequest` into the route, so the guarded base task would never
11
+ * 1. Approvals. `StellarSetAllowanceTask` submits a transaction of its own,
12
+ * which consumes the sender's sequence number. Any envelope built before
13
+ * that approval is invalid (`tx_bad_seq`), so the envelope has to be
14
+ * requested after it — which only happens if this task always asks for a
15
+ * fresh one.
16
+ * 2. Staleness. On the quote path `convertQuoteToRoute` carries the quote's
17
+ * `transactionRequest` into the route, so the base guard would never
14
18
  * re-fetch and would sign an envelope minted minutes earlier — expiring as
15
- * `tx_too_late` once the user lingers in their wallet. The retry path has the
16
- * same problem: it resets `step.execution` but not `step.transactionRequest`.
17
- * 2. Approvals. `StellarSetAllowanceTask` submits a transaction of its own, which
18
- * consumes the sender's sequence number. Any envelope built before that
19
- * approval is invalid (`tx_bad_seq`), so the envelope has to be requested
20
- * after it — which only happens if this task always asks for a fresh one.
19
+ * `tx_too_late` once the user lingers in their wallet.
20
+ *
21
+ * The `getRoutes` path never carries a `transactionRequest`, and `resumeRoute`
22
+ * clears it through `prepareRestart`, so the base guard already re-fetches for
23
+ * both. This override is what covers the quote path.
24
+ *
25
+ * Re-quoting also invalidates the allowance the pipeline just granted, so the
26
+ * refreshed route is re-checked against the chain before the step is signed.
21
27
  */
22
- declare class StellarPrepareTransactionTask extends BaseStepExecutionTask {
23
- run(context: StellarStepExecutorContext): Promise<TaskResult>;
28
+ declare class StellarPrepareTransactionTask extends PrepareTransactionTask {
29
+ protected override shouldRefetchTransaction(): boolean;
30
+ override run(context: StellarStepExecutorContext): Promise<TaskResult>;
24
31
  }
25
32
  //#endregion
26
33
  export { StellarPrepareTransactionTask };
@@ -1 +1 @@
1
- {"version":3,"file":"StellarPrepareTransactionTask.d.ts","names":[],"sources":["../../../../src/core/tasks/StellarPrepareTransactionTask.ts"],"mappings":";;;;;;;;;;;;;;;;;;;;;cA4Ba,sCAAsC;EACjD,IAAU,SAAS,6BAA6B,QAAQ"}
1
+ {"version":3,"file":"StellarPrepareTransactionTask.d.ts","names":[],"sources":["../../../../src/core/tasks/StellarPrepareTransactionTask.ts"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;cA4Ba,sCAAsC;qBAC9B;WAIJ,IAAI,SAAS,6BAA6B,QAAQ"}
@@ -1,38 +1,38 @@
1
- import { BaseStepExecutionTask, LiFiErrorCode, TransactionError, getStepTransaction, stepComparison } from "@lifi/sdk";
1
+ import { assertApprovalStillCovers } from "./helpers/assertApprovalStillCovers.js";
2
+ import { PrepareTransactionTask } from "@lifi/sdk";
2
3
  //#region src/core/tasks/StellarPrepareTransactionTask.ts
3
4
  /**
4
- * Re-fetches the step transaction from the backend, **unconditionally**.
5
+ * Always re-fetches the step transaction, where the base task asks only when
6
+ * the step carries none.
5
7
  *
6
- * Do not reintroduce the base task's `if (!step.transactionRequest)` guard. A
7
- * Stellar envelope is not a reusable payload: the backend embeds the sender's
8
- * account sequence number and timebounds `[0, now + 300s]` at build time. Two
9
- * things follow.
8
+ * A Stellar envelope is not a reusable payload: the backend embeds the sender's
9
+ * account sequence number and timebounds `[0, now + 300s]` at build time.
10
10
  *
11
- * 1. Staleness. On the quote path `convertQuoteToRoute` carries the quote's
12
- * `transactionRequest` into the route, so the guarded base task would never
11
+ * 1. Approvals. `StellarSetAllowanceTask` submits a transaction of its own,
12
+ * which consumes the sender's sequence number. Any envelope built before
13
+ * that approval is invalid (`tx_bad_seq`), so the envelope has to be
14
+ * requested after it — which only happens if this task always asks for a
15
+ * fresh one.
16
+ * 2. Staleness. On the quote path `convertQuoteToRoute` carries the quote's
17
+ * `transactionRequest` into the route, so the base guard would never
13
18
  * re-fetch and would sign an envelope minted minutes earlier — expiring as
14
- * `tx_too_late` once the user lingers in their wallet. The retry path has the
15
- * same problem: it resets `step.execution` but not `step.transactionRequest`.
16
- * 2. Approvals. `StellarSetAllowanceTask` submits a transaction of its own, which
17
- * consumes the sender's sequence number. Any envelope built before that
18
- * approval is invalid (`tx_bad_seq`), so the envelope has to be requested
19
- * after it — which only happens if this task always asks for a fresh one.
19
+ * `tx_too_late` once the user lingers in their wallet.
20
+ *
21
+ * The `getRoutes` path never carries a `transactionRequest`, and `resumeRoute`
22
+ * clears it through `prepareRestart`, so the base guard already re-fetches for
23
+ * both. This override is what covers the quote path.
24
+ *
25
+ * Re-quoting also invalidates the allowance the pipeline just granted, so the
26
+ * refreshed route is re-checked against the chain before the step is signed.
20
27
  */
21
- var StellarPrepareTransactionTask = class extends BaseStepExecutionTask {
28
+ var StellarPrepareTransactionTask = class extends PrepareTransactionTask {
29
+ shouldRefetchTransaction() {
30
+ return true;
31
+ }
22
32
  async run(context) {
23
- const { client, step, statusManager, allowUserInteraction, executionOptions, isBridgeExecution } = context;
24
- const action = statusManager.findAction(step, isBridgeExecution ? "CROSS_CHAIN" : "SWAP");
25
- if (!action) throw new TransactionError(LiFiErrorCode.TransactionUnprepared, "Unable to prepare transaction. Action not found.");
26
- const { execution: _execution, ...stepBase } = step;
27
- const comparedStep = await stepComparison(statusManager, step, await getStepTransaction(client, stepBase), allowUserInteraction, executionOptions);
28
- Object.assign(step, {
29
- ...comparedStep,
30
- execution: step.execution
31
- });
32
- if (!step.transactionRequest?.data) throw new TransactionError(LiFiErrorCode.TransactionUnprepared, "Unable to prepare transaction. Transaction request data is not found.");
33
- statusManager.updateAction(step, action.type, "ACTION_REQUIRED");
34
- if (!allowUserInteraction) return { status: "PAUSED" };
35
- return { status: "COMPLETED" };
33
+ const result = await super.run(context);
34
+ await assertApprovalStillCovers(context);
35
+ return result;
36
36
  }
37
37
  };
38
38
  //#endregion
@@ -1 +1 @@
1
- {"version":3,"file":"StellarPrepareTransactionTask.js","names":[],"sources":["../../../../src/core/tasks/StellarPrepareTransactionTask.ts"],"sourcesContent":["import {\n BaseStepExecutionTask,\n getStepTransaction,\n LiFiErrorCode,\n stepComparison,\n type TaskResult,\n TransactionError,\n} from '@lifi/sdk'\nimport type { StellarStepExecutorContext } from '../../types.js'\n\n/**\n * Re-fetches the step transaction from the backend, **unconditionally**.\n *\n * Do not reintroduce the base task's `if (!step.transactionRequest)` guard. A\n * Stellar envelope is not a reusable payload: the backend embeds the sender's\n * account sequence number and timebounds `[0, now + 300s]` at build time. Two\n * things follow.\n *\n * 1. Staleness. On the quote path `convertQuoteToRoute` carries the quote's\n * `transactionRequest` into the route, so the guarded base task would never\n * re-fetch and would sign an envelope minted minutes earlier — expiring as\n * `tx_too_late` once the user lingers in their wallet. The retry path has the\n * same problem: it resets `step.execution` but not `step.transactionRequest`.\n * 2. Approvals. `StellarSetAllowanceTask` submits a transaction of its own, which\n * consumes the sender's sequence number. Any envelope built before that\n * approval is invalid (`tx_bad_seq`), so the envelope has to be requested\n * after it — which only happens if this task always asks for a fresh one.\n */\nexport class StellarPrepareTransactionTask extends BaseStepExecutionTask {\n async run(context: StellarStepExecutorContext): Promise<TaskResult> {\n const {\n client,\n step,\n statusManager,\n allowUserInteraction,\n executionOptions,\n isBridgeExecution,\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 { execution: _execution, ...stepBase } = step\n const updatedStep = await getStepTransaction(client, stepBase)\n const comparedStep = await stepComparison(\n statusManager,\n step,\n updatedStep,\n allowUserInteraction,\n executionOptions\n )\n Object.assign(step, {\n ...comparedStep,\n execution: step.execution,\n })\n\n if (!step.transactionRequest?.data) {\n throw new TransactionError(\n LiFiErrorCode.TransactionUnprepared,\n 'Unable to prepare transaction. Transaction request data is not found.'\n )\n }\n\n statusManager.updateAction(step, action.type, 'ACTION_REQUIRED')\n\n if (!allowUserInteraction) {\n return { status: 'PAUSED' }\n }\n\n return { status: 'COMPLETED' }\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AA4BA,IAAa,gCAAb,cAAmD,sBAAsB;CACvE,MAAM,IAAI,SAA0D;EAClE,MAAM,EACJ,QACA,MACA,eACA,sBACA,kBACA,sBACE;EAEJ,MAAM,SAAS,cAAc,WAC3B,MACA,oBAAoB,gBAAgB,MACtC;EAEA,IAAI,CAAC,QACH,MAAM,IAAI,iBACR,cAAc,uBACd,kDACF;EAGF,MAAM,EAAE,WAAW,YAAY,GAAG,aAAa;EAE/C,MAAM,eAAe,MAAM,eACzB,eACA,MACA,MAJwB,mBAAmB,QAAQ,QAAQ,GAK3D,sBACA,gBACF;EACA,OAAO,OAAO,MAAM;GAClB,GAAG;GACH,WAAW,KAAK;EAClB,CAAC;EAED,IAAI,CAAC,KAAK,oBAAoB,MAC5B,MAAM,IAAI,iBACR,cAAc,uBACd,uEACF;EAGF,cAAc,aAAa,MAAM,OAAO,MAAM,iBAAiB;EAE/D,IAAI,CAAC,sBACH,OAAO,EAAE,QAAQ,SAAS;EAG5B,OAAO,EAAE,QAAQ,YAAY;CAC/B;AACF"}
1
+ {"version":3,"file":"StellarPrepareTransactionTask.js","names":[],"sources":["../../../../src/core/tasks/StellarPrepareTransactionTask.ts"],"sourcesContent":["import { PrepareTransactionTask, type TaskResult } from '@lifi/sdk'\nimport type { StellarStepExecutorContext } from '../../types.js'\nimport { assertApprovalStillCovers } from './helpers/assertApprovalStillCovers.js'\n\n/**\n * Always re-fetches the step transaction, where the base task asks only when\n * the step carries none.\n *\n * A Stellar envelope is not a reusable payload: the backend embeds the sender's\n * account sequence number and timebounds `[0, now + 300s]` at build time.\n *\n * 1. Approvals. `StellarSetAllowanceTask` submits a transaction of its own,\n * which consumes the sender's sequence number. Any envelope built before\n * that approval is invalid (`tx_bad_seq`), so the envelope has to be\n * requested after it — which only happens if this task always asks for a\n * fresh one.\n * 2. Staleness. On the quote path `convertQuoteToRoute` carries the quote's\n * `transactionRequest` into the route, so the base guard would never\n * re-fetch and would sign an envelope minted minutes earlier — expiring as\n * `tx_too_late` once the user lingers in their wallet.\n *\n * The `getRoutes` path never carries a `transactionRequest`, and `resumeRoute`\n * clears it through `prepareRestart`, so the base guard already re-fetches for\n * both. This override is what covers the quote path.\n *\n * Re-quoting also invalidates the allowance the pipeline just granted, so the\n * refreshed route is re-checked against the chain before the step is signed.\n */\nexport class StellarPrepareTransactionTask extends PrepareTransactionTask {\n protected override shouldRefetchTransaction(): boolean {\n return true\n }\n\n override async run(context: StellarStepExecutorContext): Promise<TaskResult> {\n const result = await super.run(context)\n // The refresh above may have re-quoted the route around a different\n // adapter or amount than the allowance was granted for.\n await assertApprovalStillCovers(context)\n return result\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;AA4BA,IAAa,gCAAb,cAAmD,uBAAuB;CACxE,2BAAuD;EACrD,OAAO;CACT;CAEA,MAAe,IAAI,SAA0D;EAC3E,MAAM,SAAS,MAAM,MAAM,IAAI,OAAO;EAGtC,MAAM,0BAA0B,OAAO;EACvC,OAAO;CACT;AACF"}
@@ -1 +1 @@
1
- {"version":3,"file":"StellarWaitForTransactionTask.d.ts","names":[],"sources":["../../../../src/core/tasks/StellarWaitForTransactionTask.ts"],"mappings":";;;cAUa,sCAAsC;EACjD,IAAU,SAAS,6BAA6B,QAAQ"}
1
+ {"version":3,"file":"StellarWaitForTransactionTask.d.ts","names":[],"sources":["../../../../src/core/tasks/StellarWaitForTransactionTask.ts"],"mappings":";;;cAYa,sCAAsC;EACjD,IAAU,SAAS,6BAA6B,QAAQ"}
@@ -1,6 +1,7 @@
1
1
  import { submitStellarTransaction } from "./helpers/submitStellarTransaction.js";
2
2
  import { waitForStellarTransaction } from "./helpers/waitForStellarTransaction.js";
3
- import { BaseStepExecutionTask, LiFiErrorCode, TransactionError } from "@lifi/sdk";
3
+ import { probeStellarTransaction } from "./helpers/probeStellarTransaction.js";
4
+ import { BaseError, BaseStepExecutionTask, LiFiErrorCode, TransactionError } from "@lifi/sdk";
4
5
  //#region src/core/tasks/StellarWaitForTransactionTask.ts
5
6
  var StellarWaitForTransactionTask = class extends BaseStepExecutionTask {
6
7
  async run(context) {
@@ -9,8 +10,21 @@ var StellarWaitForTransactionTask = class extends BaseStepExecutionTask {
9
10
  if (!action) throw new TransactionError(LiFiErrorCode.TransactionUnprepared, "Unable to prepare transaction. Action not found.");
10
11
  const hash = transactionHash ?? action.txHash;
11
12
  if (!hash) throw new TransactionError(LiFiErrorCode.TransactionUnprepared, "Unable to wait for transaction. Transaction hash is not found.");
12
- if (!transactionHash && action.txHex) await submitStellarTransaction(client, action.txHex, networkPassphrase);
13
- await waitForStellarTransaction(client, hash, pollingIntervalMs);
13
+ let resubmitError;
14
+ if (!transactionHash && action.txHex) {
15
+ const probe = await probeStellarTransaction(client, hash);
16
+ if (probe !== "landed") try {
17
+ await submitStellarTransaction(client, action.txHex, networkPassphrase);
18
+ } catch (error) {
19
+ resubmitError = probe === "not-found" ? error : void 0;
20
+ }
21
+ }
22
+ try {
23
+ await waitForStellarTransaction(client, hash, pollingIntervalMs);
24
+ } catch (error) {
25
+ if (resubmitError && error instanceof BaseError && error.code === LiFiErrorCode.Timeout) throw resubmitError;
26
+ throw error;
27
+ }
14
28
  if (isBridgeExecution) statusManager.updateAction(step, action.type, "DONE");
15
29
  return { status: "COMPLETED" };
16
30
  }
@@ -1 +1 @@
1
- {"version":3,"file":"StellarWaitForTransactionTask.js","names":[],"sources":["../../../../src/core/tasks/StellarWaitForTransactionTask.ts"],"sourcesContent":["import {\n BaseStepExecutionTask,\n LiFiErrorCode,\n type TaskResult,\n TransactionError,\n} from '@lifi/sdk'\nimport type { StellarStepExecutorContext } from '../../types.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. Re-submit it before polling — Soroban\n // submission is idempotent by hash and reports an already-known envelope as\n // DUPLICATE, which submitStellarTransaction treats as success. Without this,\n // a crash between persisting and submitting would strand the step polling\n // for a transaction that was never broadcast.\n if (!transactionHash && action.txHex) {\n await submitStellarTransaction(client, action.txHex, networkPassphrase)\n }\n\n await waitForStellarTransaction(client, hash, pollingIntervalMs)\n\n if (isBridgeExecution) {\n statusManager.updateAction(step, action.type, 'DONE')\n }\n\n return { status: 'COMPLETED' }\n }\n}\n"],"mappings":";;;;AAUA,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;EASF,IAAI,CAAC,mBAAmB,OAAO,OAC7B,MAAM,yBAAyB,QAAQ,OAAO,OAAO,iBAAiB;EAGxE,MAAM,0BAA0B,QAAQ,MAAM,iBAAiB;EAE/D,IAAI,mBACF,cAAc,aAAa,MAAM,OAAO,MAAM,MAAM;EAGtD,OAAO,EAAE,QAAQ,YAAY;CAC/B;AACF"}
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 && action.txHex) {\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.\n if (\n resubmitError &&\n error instanceof BaseError &&\n error.code === LiFiErrorCode.Timeout\n ) {\n throw resubmitError\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"],"mappings":";;;;;AAYA,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;EAQF,IAAI;EACJ,IAAI,CAAC,mBAAmB,OAAO,OAAO;GACpC,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;GAGd,IACE,iBACA,iBAAiB,aACjB,MAAM,SAAS,cAAc,SAE7B,MAAM;GAER,MAAM;EACR;EAEA,IAAI,mBACF,cAAc,aAAa,MAAM,OAAO,MAAM,MAAM;EAGtD,OAAO,EAAE,QAAQ,YAAY;CAC/B;AACF"}
@@ -0,0 +1,21 @@
1
+ import { StellarStepExecutorContext } from "../../../types.js";
2
+ //#region src/core/tasks/helpers/assertApprovalStillCovers.d.ts
3
+ /**
4
+ * Fails the step before signing when the refreshed route needs an allowance the
5
+ * sender does not have.
6
+ *
7
+ * `StellarPrepareTransactionTask` re-quotes after `StellarSetAllowanceTask` has
8
+ * already written an allowance, and the re-quote replaces `includedSteps` and
9
+ * `estimate` wholesale. A fresh quote that names a different adapter, a
10
+ * different intermediate token, or a larger amount would revert `transfer_from`
11
+ * on-chain after a second signature.
12
+ *
13
+ * The check reads the chain rather than comparing against the resolved
14
+ * requirement: when the allowance already existed, the on-chain ceiling can be
15
+ * far above what this route asked for, and comparing the two would reject a
16
+ * route that works.
17
+ */
18
+ declare const assertApprovalStillCovers: (context: StellarStepExecutorContext) => Promise<void>;
19
+ //#endregion
20
+ export { assertApprovalStillCovers };
21
+ //# sourceMappingURL=assertApprovalStillCovers.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"assertApprovalStillCovers.d.ts","names":[],"sources":["../../../../../src/core/tasks/helpers/assertApprovalStillCovers.ts"],"mappings":";;;;;;;;;;;;;;;;;cAoBa,4BACX,SAAS,+BACR"}