@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.
- package/CHANGELOG.md +9 -5
- package/dist/esm/StellarProvider.d.ts +7 -1
- package/dist/esm/StellarProvider.d.ts.map +1 -1
- package/dist/esm/StellarProvider.js +8 -2
- package/dist/esm/StellarProvider.js.map +1 -1
- package/dist/esm/actions/getStellarBalance.js +14 -5
- package/dist/esm/actions/getStellarBalance.js.map +1 -1
- package/dist/esm/actions/resolveStellarAddress.d.ts +8 -1
- package/dist/esm/actions/resolveStellarAddress.d.ts.map +1 -1
- package/dist/esm/actions/resolveStellarAddress.js +11 -2
- package/dist/esm/actions/resolveStellarAddress.js.map +1 -1
- package/dist/esm/client/getStellarRpc.d.ts +3 -3
- package/dist/esm/client/getStellarRpc.d.ts.map +1 -1
- package/dist/esm/client/getStellarRpc.js +2 -2
- package/dist/esm/client/getStellarRpc.js.map +1 -1
- package/dist/esm/core/StellarStepExecutor.d.ts.map +1 -1
- package/dist/esm/core/StellarStepExecutor.js +3 -1
- package/dist/esm/core/StellarStepExecutor.js.map +1 -1
- package/dist/esm/core/tasks/StellarPrepareTransactionTask.d.ts +23 -16
- package/dist/esm/core/tasks/StellarPrepareTransactionTask.d.ts.map +1 -1
- package/dist/esm/core/tasks/StellarPrepareTransactionTask.js +28 -28
- package/dist/esm/core/tasks/StellarPrepareTransactionTask.js.map +1 -1
- package/dist/esm/core/tasks/StellarWaitForTransactionTask.d.ts.map +1 -1
- package/dist/esm/core/tasks/StellarWaitForTransactionTask.js +17 -3
- package/dist/esm/core/tasks/StellarWaitForTransactionTask.js.map +1 -1
- package/dist/esm/core/tasks/helpers/assertApprovalStillCovers.d.ts +21 -0
- package/dist/esm/core/tasks/helpers/assertApprovalStillCovers.d.ts.map +1 -0
- package/dist/esm/core/tasks/helpers/assertApprovalStillCovers.js +29 -0
- package/dist/esm/core/tasks/helpers/assertApprovalStillCovers.js.map +1 -0
- package/dist/esm/core/tasks/helpers/probeStellarTransaction.d.ts +20 -0
- package/dist/esm/core/tasks/helpers/probeStellarTransaction.d.ts.map +1 -0
- package/dist/esm/core/tasks/helpers/probeStellarTransaction.js +20 -0
- package/dist/esm/core/tasks/helpers/probeStellarTransaction.js.map +1 -0
- package/dist/esm/core/tasks/helpers/readAllowance.d.ts +4 -0
- package/dist/esm/core/tasks/helpers/readAllowance.d.ts.map +1 -1
- package/dist/esm/core/tasks/helpers/readAllowance.js +12 -6
- package/dist/esm/core/tasks/helpers/readAllowance.js.map +1 -1
- package/dist/esm/core/tasks/helpers/resolveApprovalRequirement.js +1 -2
- package/dist/esm/core/tasks/helpers/resolveApprovalRequirement.js.map +1 -1
- package/dist/esm/core/tasks/helpers/submitStellarTransaction.d.ts +3 -0
- package/dist/esm/core/tasks/helpers/submitStellarTransaction.d.ts.map +1 -1
- package/dist/esm/core/tasks/helpers/submitStellarTransaction.js +20 -6
- package/dist/esm/core/tasks/helpers/submitStellarTransaction.js.map +1 -1
- package/dist/esm/core/tasks/helpers/waitForStellarTransaction.d.ts +8 -4
- package/dist/esm/core/tasks/helpers/waitForStellarTransaction.d.ts.map +1 -1
- package/dist/esm/core/tasks/helpers/waitForStellarTransaction.js +26 -9
- package/dist/esm/core/tasks/helpers/waitForStellarTransaction.js.map +1 -1
- package/dist/esm/errors/parseStellarErrors.js +7 -2
- package/dist/esm/errors/parseStellarErrors.js.map +1 -1
- package/dist/esm/index.d.ts +2 -2
- package/dist/esm/index.js +2 -2
- package/dist/esm/types.d.ts +10 -6
- package/dist/esm/types.d.ts.map +1 -1
- package/dist/esm/types.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/StellarProvider.ts +8 -1
- package/src/actions/getStellarBalance.ts +22 -6
- package/src/actions/resolveStellarAddress.ts +19 -2
- package/src/client/getStellarRpc.ts +6 -8
- package/src/core/StellarStepExecutor.ts +11 -0
- package/src/core/tasks/StellarPrepareTransactionTask.ts +31 -71
- package/src/core/tasks/StellarWaitForTransactionTask.ts +35 -7
- package/src/core/tasks/helpers/assertApprovalStillCovers.ts +48 -0
- package/src/core/tasks/helpers/probeStellarTransaction.ts +34 -0
- package/src/core/tasks/helpers/readAllowance.ts +42 -33
- package/src/core/tasks/helpers/resolveApprovalRequirement.ts +10 -10
- package/src/core/tasks/helpers/submitStellarTransaction.ts +41 -25
- package/src/core/tasks/helpers/waitForStellarTransaction.ts +44 -20
- package/src/errors/parseStellarErrors.ts +17 -5
- package/src/index.ts +4 -1
- package/src/types.ts +10 -6
- package/src/version.ts +1 -1
|
@@ -1,16 +1,27 @@
|
|
|
1
1
|
import { LiFiErrorCode, type SDKClient, TransactionError } from '@lifi/sdk'
|
|
2
|
-
import {
|
|
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
|
|
13
|
-
*
|
|
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<
|
|
24
|
-
|
|
25
|
-
|
|
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
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
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 {
|
|
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
|
-
|
|
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 = '
|
|
2
|
+
export const version = '4.2.0'
|