@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
@@ -1,16 +1,27 @@
1
1
  import { LiFiErrorCode, type SDKClient, TransactionError } from '@lifi/sdk'
2
- import { rpc } from '@stellar/stellar-sdk'
2
+ import { Api } from '@stellar/stellar-sdk/rpc'
3
3
  import { callStellarRpcsWithRetry } from '../../../client/getStellarRpc.js'
4
4
 
5
- const CONFIRM_POLL_ATTEMPTS = 30
6
5
  const CONFIRM_POLL_INTERVAL_MS = 3_000
7
6
 
7
+ /**
8
+ * Outlives the backend's `[0, now + 300 s]` timebounds, so a transaction that
9
+ * has not been applied by the deadline is genuinely dead rather than still in
10
+ * flight. Expressed as a deadline, not an attempt count, so a caller-supplied
11
+ * polling interval cannot shorten the budget.
12
+ */
13
+ const CONFIRM_TIMEOUT_MS = 330_000
14
+
8
15
  /**
9
16
  * Polls `getTransaction` until the transaction is included in a ledger.
10
17
  *
11
18
  * `NOT_FOUND` is not an error — Soroban RPC only knows a transaction once it has
12
- * been applied — so polling continues until the attempt budget runs out and the
13
- * result is reported as a timeout rather than a failure.
19
+ * been applied — so polling continues until the deadline passes and the result
20
+ * is reported as a timeout rather than a failure.
21
+ *
22
+ * A transport failure costs one interval rather than the whole wait: every RPC
23
+ * can reject one read during a rate-limit burst while the transaction is
24
+ * perfectly healthy. The last such error rides along as the timeout's cause.
14
25
  *
15
26
  * The terminal classification is deliberately done outside
16
27
  * {@link callStellarRpcsWithRetry}; only the read goes through the failover
@@ -20,23 +31,35 @@ export const waitForStellarTransaction = async (
20
31
  client: SDKClient,
21
32
  transactionHash: string,
22
33
  pollingIntervalMs: number = CONFIRM_POLL_INTERVAL_MS
23
- ): Promise<rpc.Api.GetSuccessfulTransactionResponse> => {
24
- for (let attempt = 0; attempt < CONFIRM_POLL_ATTEMPTS; attempt++) {
25
- const response = await callStellarRpcsWithRetry(client, (server) =>
26
- server.getTransaction(transactionHash)
27
- )
28
-
29
- if (response.status === rpc.Api.GetTransactionStatus.SUCCESS) {
30
- return response
31
- }
34
+ ): Promise<Api.GetSuccessfulTransactionResponse> => {
35
+ const deadline = Date.now() + CONFIRM_TIMEOUT_MS
36
+ let lastTransportError: Error | undefined
32
37
 
33
- if (response.status === rpc.Api.GetTransactionStatus.FAILED) {
34
- throw new TransactionError(
35
- LiFiErrorCode.TransactionFailed,
36
- `Stellar transaction ${transactionHash} failed: ${
37
- response.resultXdr?.result().switch().name ?? 'unknown reason'
38
- }`
38
+ while (Date.now() < deadline) {
39
+ try {
40
+ const response = await callStellarRpcsWithRetry(client, (server) =>
41
+ server.getTransaction(transactionHash)
39
42
  )
43
+
44
+ if (response.status === Api.GetTransactionStatus.SUCCESS) {
45
+ return response
46
+ }
47
+
48
+ if (response.status === Api.GetTransactionStatus.FAILED) {
49
+ throw new TransactionError(
50
+ LiFiErrorCode.TransactionFailed,
51
+ `Stellar transaction ${transactionHash} failed: ${
52
+ response.resultXdr?.result().switch().name ?? 'unknown reason'
53
+ }`
54
+ )
55
+ }
56
+ } catch (error) {
57
+ // The ledger's verdict is terminal; only transport failures are retried.
58
+ if (error instanceof TransactionError) {
59
+ throw error
60
+ }
61
+ lastTransportError =
62
+ error instanceof Error ? error : new Error(String(error))
40
63
  }
41
64
 
42
65
  await new Promise((resolve) => setTimeout(resolve, pollingIntervalMs))
@@ -44,6 +67,7 @@ export const waitForStellarTransaction = async (
44
67
 
45
68
  throw new TransactionError(
46
69
  LiFiErrorCode.Timeout,
47
- `Stellar transaction ${transactionHash} was not confirmed in time.`
70
+ `Stellar transaction ${transactionHash} was not confirmed in time.`,
71
+ lastTransportError
48
72
  )
49
73
  }
@@ -25,7 +25,23 @@ export const parseStellarErrors = async (
25
25
  return new SDKError(baseError, step, action)
26
26
  }
27
27
 
28
- const handleSpecificErrors = (e: any) => {
28
+ const handleSpecificErrors = (e: any): BaseError => {
29
+ // `callStellarRpcsWithRetry` collapses every rejection into an AggregateError,
30
+ // whose own message says nothing useful. Classify from the error it hides,
31
+ // preferring one this package already classified.
32
+ if (e instanceof AggregateError && e.errors.length) {
33
+ const classified = e.errors.find(
34
+ (error: unknown) => error instanceof BaseError
35
+ )
36
+ return handleSpecificErrors(classified ?? e.errors[0])
37
+ }
38
+
39
+ // A code this package set on purpose wins over message matching: an allowance
40
+ // the SDK could not read is not an allowance the user has to grant.
41
+ if (e instanceof BaseError) {
42
+ return e
43
+ }
44
+
29
45
  // Stellar Wallets Kit surfaces wallet rejections as messages rather than typed
30
46
  // errors, and the shape varies per wallet — match on the text, as Sui does.
31
47
  const message: string = typeof e === 'string' ? e : (e?.message ?? '')
@@ -89,9 +105,5 @@ const handleSpecificErrors = (e: any) => {
89
105
  )
90
106
  }
91
107
 
92
- if (e instanceof BaseError) {
93
- return e
94
- }
95
-
96
108
  return new UnknownError(message || ErrorMessage.UnknownError, e)
97
109
  }
package/src/index.ts CHANGED
@@ -1,5 +1,8 @@
1
1
  // biome-ignore lint/performance/noBarrelFile: module entrypoint
2
- export { StellarProvider } from './StellarProvider.js'
2
+ export {
3
+ DEFAULT_NETWORK_PASSPHRASE,
4
+ StellarProvider,
5
+ } from './StellarProvider.js'
3
6
  export type {
4
7
  StellarProviderOptions,
5
8
  StellarSDKProvider,
package/src/types.ts CHANGED
@@ -48,7 +48,11 @@ export interface StellarWallet {
48
48
  xdr: string,
49
49
  opts?: StellarSignOptions
50
50
  ) => Promise<StellarSignedTransaction>
51
- signAuthEntry: (
51
+ /**
52
+ * Optional: the router routes use source-account auth, so the SDK never calls
53
+ * this. Present so an adapter can forward the Stellar Wallets Kit method.
54
+ */
55
+ signAuthEntry?: (
52
56
  authEntry: string,
53
57
  opts?: StellarSignOptions
54
58
  ) => Promise<StellarSignedAuthEntry>
@@ -59,13 +63,13 @@ export interface StellarProviderOptions {
59
63
  /**
60
64
  * Network passphrase for the Stellar network this provider targets.
61
65
  * Defaults to the public (mainnet) network.
66
+ *
67
+ * Balance reads follow this option alone. Signing prefers it and falls back
68
+ * to the connected wallet's passphrase, and `StellarStepExecutor.checkWallet`
69
+ * refuses to sign when the two disagree — so a wallet on a different network
70
+ * fails before the user signs, while balances still read against the option.
62
71
  */
63
72
  networkPassphrase?: string
64
- /**
65
- * Optional Horizon REST endpoint used for balance/account reads. When omitted
66
- * the provider falls back to the Stellar RPC URLs resolved from the SDK client.
67
- */
68
- horizonUrl?: string
69
73
  }
70
74
 
71
75
  export interface StellarSDKProvider extends SDKProvider {
package/src/version.ts CHANGED
@@ -1,2 +1,2 @@
1
1
  export const name = '@lifi/sdk-provider-stellar'
2
- export const version = '0.0.0-preview-c328023'
2
+ export const version = '4.2.0'