@lifi/sdk-provider-solana 4.3.4 → 4.3.6
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 +15 -0
- package/dist/cjs/actions/sendAndConfirmBundle.d.ts +8 -7
- package/dist/cjs/actions/sendAndConfirmBundle.js +22 -16
- package/dist/cjs/actions/sendAndConfirmBundle.js.map +1 -1
- package/dist/cjs/confirmation/confirmBundle.d.ts +18 -19
- package/dist/cjs/confirmation/confirmBundle.js +10 -23
- package/dist/cjs/confirmation/confirmBundle.js.map +1 -1
- package/dist/cjs/confirmation/confirmSignature.d.ts +2 -2
- package/dist/cjs/confirmation/confirmSignature.js +2 -2
- package/dist/cjs/confirmation/confirmSignature.js.map +1 -1
- package/dist/cjs/confirmation/createConfirmationDeadline.d.ts +1 -1
- package/dist/cjs/confirmation/createConfirmationDeadline.js.map +1 -1
- package/dist/cjs/confirmation/types.d.ts +1 -1
- package/dist/cjs/confirmation/types.js.map +1 -1
- package/dist/cjs/core/tasks/SolanaJitoWaitForTransactionTask.js +9 -18
- package/dist/cjs/core/tasks/SolanaJitoWaitForTransactionTask.js.map +1 -1
- package/dist/cjs/core/tasks/SolanaSignAndExecuteTask.js.map +1 -1
- package/dist/cjs/rpc/registry.d.ts +4 -3
- package/dist/cjs/rpc/registry.js +4 -3
- package/dist/cjs/rpc/registry.js.map +1 -1
- package/dist/cjs/version.d.ts +1 -1
- package/dist/cjs/version.js +1 -1
- package/dist/cjs/version.js.map +1 -1
- package/dist/esm/actions/sendAndConfirmBundle.d.ts +8 -7
- package/dist/esm/actions/sendAndConfirmBundle.d.ts.map +1 -1
- package/dist/esm/actions/sendAndConfirmBundle.js +24 -18
- package/dist/esm/actions/sendAndConfirmBundle.js.map +1 -1
- package/dist/esm/confirmation/confirmBundle.d.ts +18 -19
- package/dist/esm/confirmation/confirmBundle.d.ts.map +1 -1
- package/dist/esm/confirmation/confirmBundle.js +10 -23
- package/dist/esm/confirmation/confirmBundle.js.map +1 -1
- package/dist/esm/confirmation/confirmSignature.d.ts +2 -2
- package/dist/esm/confirmation/confirmSignature.js +2 -2
- package/dist/esm/confirmation/confirmSignature.js.map +1 -1
- package/dist/esm/confirmation/createConfirmationDeadline.d.ts +1 -1
- package/dist/esm/confirmation/createConfirmationDeadline.js.map +1 -1
- package/dist/esm/confirmation/types.d.ts +1 -1
- package/dist/esm/confirmation/types.js.map +1 -1
- package/dist/esm/core/tasks/SolanaJitoWaitForTransactionTask.d.ts.map +1 -1
- package/dist/esm/core/tasks/SolanaJitoWaitForTransactionTask.js +10 -19
- package/dist/esm/core/tasks/SolanaJitoWaitForTransactionTask.js.map +1 -1
- package/dist/esm/core/tasks/SolanaSignAndExecuteTask.js.map +1 -1
- package/dist/esm/rpc/registry.d.ts +4 -3
- package/dist/esm/rpc/registry.d.ts.map +1 -1
- package/dist/esm/rpc/registry.js +4 -3
- package/dist/esm/rpc/registry.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 +2 -2
- package/src/actions/sendAndConfirmBundle.ts +48 -48
- package/src/confirmation/confirmBundle.ts +34 -69
- package/src/confirmation/confirmSignature.ts +2 -2
- package/src/confirmation/createConfirmationDeadline.ts +1 -1
- package/src/confirmation/types.ts +1 -1
- package/src/core/tasks/SolanaJitoWaitForTransactionTask.ts +13 -27
- package/src/core/tasks/SolanaSignAndExecuteTask.ts +5 -6
- package/src/rpc/registry.ts +4 -3
- package/src/version.ts +1 -1
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { Signature } from '@solana/kit'
|
|
2
|
-
import type {
|
|
2
|
+
import type { SolanaRpcType } from '../rpc/types.js'
|
|
3
3
|
import type { TransactionLifetime } from '../utils/getTransactionLifetime.js'
|
|
4
4
|
import { createConfirmationDeadline } from './createConfirmationDeadline.js'
|
|
5
5
|
import { pollUntilDeadline } from './pollUntilDeadline.js'
|
|
@@ -9,47 +9,46 @@ import {
|
|
|
9
9
|
type SignatureStatus,
|
|
10
10
|
} from './types.js'
|
|
11
11
|
|
|
12
|
-
/** Slower than the signature poller's 400 ms
|
|
13
|
-
*
|
|
14
|
-
*
|
|
12
|
+
/** Slower than the signature poller's 400 ms, to spend fewer requests: the
|
|
13
|
+
* bundle is never resent, so a slower read delays only the verdict, by 2 s at
|
|
14
|
+
* most. `STATUS_RETRY_BACKOFF_CAP_MS` is set against this value. */
|
|
15
15
|
export const BUNDLE_POLL_INTERVAL_MS = 2_000
|
|
16
16
|
|
|
17
17
|
export type BundleConfirmation = {
|
|
18
|
-
/**
|
|
19
|
-
|
|
20
|
-
/** Never read for a `txHash` - its order is Jito's to choose. Kept so the
|
|
21
|
-
* reversed-list regression stays expressible in the wait-task spec. */
|
|
22
|
-
txSignatures: Signature[]
|
|
23
|
-
signatureResults: readonly (SignatureStatus | null)[]
|
|
24
|
-
/** Bundle-level `err`, verbatim. Jito encodes it as a Rust `Result`, so a
|
|
25
|
-
* landed bundle carries `{ Ok: null }` - never truthiness-check it. */
|
|
26
|
-
bundleErr: unknown
|
|
18
|
+
/** One confirmed status per bundle transaction, in bundle order. */
|
|
19
|
+
signatureResults: readonly SignatureStatus[]
|
|
27
20
|
}
|
|
28
21
|
|
|
29
22
|
/**
|
|
30
|
-
* Confirms one Jito bundle against one
|
|
23
|
+
* Confirms one Jito bundle against one RPC, by the signatures of its
|
|
24
|
+
* transactions. Every Solana RPC can read them, and a bundle lands whole in
|
|
25
|
+
* one slot, so one read shows all of them confirmed.
|
|
31
26
|
*
|
|
32
27
|
* Bundles submit once, so there is no resend loop. `send` is owned here so the
|
|
33
28
|
* deadline starts before submission rather than after it. A `send` failure
|
|
34
29
|
* throws, which `raceRpcs` buckets as `rpc-unavailable`.
|
|
35
30
|
*/
|
|
36
31
|
export async function confirmBundle(options: {
|
|
37
|
-
rpc:
|
|
32
|
+
rpc: SolanaRpcType
|
|
38
33
|
signal: AbortSignal
|
|
34
|
+
/** The signatures of the bundle's transactions, in bundle order. */
|
|
35
|
+
signatures: Signature[]
|
|
39
36
|
lifetimes: TransactionLifetime[]
|
|
40
|
-
|
|
37
|
+
/** Its answer is not read: senders answer `sendBundle` in different
|
|
38
|
+
* shapes, and the signatures are known before the send. */
|
|
39
|
+
send: () => Promise<unknown>
|
|
41
40
|
/**
|
|
42
|
-
* Reports that
|
|
41
|
+
* Reports that the shared submission was accepted. Must not throw -
|
|
43
42
|
* `sendAndConfirmBundle` contains any throw from the integrator callback it
|
|
44
|
-
* wraps, because a throw here would reject a branch whose bundle
|
|
45
|
-
* already accepted.
|
|
43
|
+
* wraps, because a throw here would reject a branch whose bundle a submit
|
|
44
|
+
* RPC had already accepted.
|
|
46
45
|
*/
|
|
47
46
|
onBroadcast?: () => void
|
|
48
47
|
}): Promise<ConfirmationOutcome<BundleConfirmation>> {
|
|
49
|
-
const { rpc, signal, lifetimes, send } = options
|
|
48
|
+
const { rpc, signal, signatures, lifetimes, send } = options
|
|
50
49
|
const deadline = createConfirmationDeadline({ lifetimes, rpc })
|
|
51
50
|
|
|
52
|
-
|
|
51
|
+
await send()
|
|
53
52
|
// Guarded like `confirmSignature`'s send sites: the caller's once-guard
|
|
54
53
|
// latches only after the callback returns, so a throwing integrator hook
|
|
55
54
|
// leaves it open and a late `sendBundle` fulfilment would re-write a
|
|
@@ -59,55 +58,21 @@ export async function confirmBundle(options: {
|
|
|
59
58
|
}
|
|
60
59
|
|
|
61
60
|
const readBundle = async (): Promise<BundleConfirmation | null> => {
|
|
62
|
-
const
|
|
63
|
-
.
|
|
61
|
+
const response = await rpc
|
|
62
|
+
.getSignatureStatuses(signatures)
|
|
64
63
|
.send({ abortSignal: signal })
|
|
65
|
-
// A `{ value: null }
|
|
66
|
-
// rather than throw a `TypeError` into the
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
// bundle would report as `rpc-unavailable`.
|
|
78
|
-
// `Array.isArray`, not `??`: the wire data is unvalidated, and a truthy
|
|
79
|
-
// non-array keeps the declared array type while throwing out of `.map`.
|
|
80
|
-
const txSignatures = Array.isArray(bundleStatus.transactions)
|
|
81
|
-
? bundleStatus.transactions
|
|
82
|
-
: []
|
|
83
|
-
|
|
84
|
-
// The bundle status is the atomic fact: a bundle lands whole or not at
|
|
85
|
-
// all. `getSignatureStatuses` only enriches it with per-transaction `err`
|
|
86
|
-
// detail, so an unusable response degrades to all-`null` and must never
|
|
87
|
-
// veto a confirmation the status already made.
|
|
88
|
-
let signatureResults: BundleConfirmation['signatureResults']
|
|
89
|
-
if (txSignatures.length === 0) {
|
|
90
|
-
// Nothing to enrich; the status already confirmed the bundle.
|
|
91
|
-
signatureResults = []
|
|
92
|
-
} else {
|
|
93
|
-
try {
|
|
94
|
-
const sigResponse = await rpc
|
|
95
|
-
.getSignatureStatuses(txSignatures)
|
|
96
|
-
.send({ abortSignal: signal })
|
|
97
|
-
signatureResults = Array.isArray(sigResponse?.value)
|
|
98
|
-
? sigResponse.value
|
|
99
|
-
: txSignatures.map(() => null)
|
|
100
|
-
} catch (_) {
|
|
101
|
-
signatureResults = txSignatures.map(() => null)
|
|
102
|
-
}
|
|
103
|
-
}
|
|
104
|
-
|
|
105
|
-
return {
|
|
106
|
-
bundleId,
|
|
107
|
-
txSignatures,
|
|
108
|
-
signatureResults,
|
|
109
|
-
bundleErr: bundleStatus.err,
|
|
110
|
-
}
|
|
64
|
+
// A `{ value: null }`, non-array or short answer responded but said
|
|
65
|
+
// nothing - poll again rather than throw a `TypeError` into the
|
|
66
|
+
// read-failure budget.
|
|
67
|
+
const statuses = response?.value
|
|
68
|
+
return Array.isArray(statuses) &&
|
|
69
|
+
statuses.length === signatures.length &&
|
|
70
|
+
statuses.every(
|
|
71
|
+
(status: SignatureStatus | null): status is SignatureStatus =>
|
|
72
|
+
isConfirmedCommitment(status?.confirmationStatus)
|
|
73
|
+
)
|
|
74
|
+
? { signatureResults: statuses }
|
|
75
|
+
: null
|
|
111
76
|
}
|
|
112
77
|
|
|
113
78
|
return pollUntilDeadline({
|
|
@@ -14,8 +14,8 @@ import {
|
|
|
14
14
|
export const RESEND_INTERVAL_MS = 1000
|
|
15
15
|
/**
|
|
16
16
|
* How often this poller re-reads `getSignatureStatuses`. The default Solana
|
|
17
|
-
* RPCs tolerate 2.5 req/s of status reads; the
|
|
18
|
-
*
|
|
17
|
+
* RPCs tolerate 2.5 req/s of status reads; the bundle poller runs slower
|
|
18
|
+
* (see `confirmBundle`).
|
|
19
19
|
*/
|
|
20
20
|
export const SIGNATURE_POLL_INTERVAL_MS = 400
|
|
21
21
|
|
|
@@ -29,7 +29,7 @@ export const EXPIRY_CONFIRMATIONS: number =
|
|
|
29
29
|
* Prober-only; the status pollers have `MAX_STATUS_READ_SILENCE_MS`. */
|
|
30
30
|
export const MAX_PROBE_ERRORS = 5
|
|
31
31
|
|
|
32
|
-
/** Structural
|
|
32
|
+
/** Structural: the deadline needs nothing but `isBlockhashValid`. */
|
|
33
33
|
export type BlockhashProbeRpc = Pick<SolanaRpcType, 'isBlockhashValid'>
|
|
34
34
|
|
|
35
35
|
export interface ConfirmationDeadline {
|
|
@@ -6,7 +6,7 @@ type SignatureStatusesResponse = Awaited<
|
|
|
6
6
|
>
|
|
7
7
|
|
|
8
8
|
/** Derived from the RPC type rather than hand-written, which removes every
|
|
9
|
-
* `as SignatureStatus` cast.
|
|
9
|
+
* `as SignatureStatus` cast. */
|
|
10
10
|
export type SignatureStatus = NonNullable<
|
|
11
11
|
SignatureStatusesResponse['value'][number]
|
|
12
12
|
>
|
|
@@ -20,45 +20,29 @@ import { resumeFromStore } from './resumeFromStore.js'
|
|
|
20
20
|
import {
|
|
21
21
|
canResendStored,
|
|
22
22
|
clearStoredTransactions,
|
|
23
|
+
failureOf,
|
|
23
24
|
getTxLink,
|
|
24
25
|
sendAndSettle,
|
|
25
26
|
} from './transactionOutcome.js'
|
|
26
27
|
|
|
27
28
|
// The `rpc-unavailable` message is distinct from the empty-list throw inside
|
|
28
29
|
// `sendAndConfirmBundle`: RPCs were configured and every one of them failed.
|
|
29
|
-
//
|
|
30
|
-
//
|
|
30
|
+
// Every read RPC confirms and waits for the one shared submission, so a
|
|
31
|
+
// refused submission fails every branch with the same error.
|
|
31
32
|
const MESSAGES: ConfirmationMessages = {
|
|
32
|
-
rpcUnavailable:
|
|
33
|
+
rpcUnavailable:
|
|
34
|
+
'Unable to confirm bundle: every configured Solana RPC failed.',
|
|
33
35
|
notConfirmed: 'Bundle was not confirmed before the SDK stopped waiting.',
|
|
34
|
-
allRpcsFailed: 'All
|
|
36
|
+
allRpcsFailed: 'All Solana RPCs failed',
|
|
35
37
|
someRpcsFailed:
|
|
36
|
-
'Some
|
|
38
|
+
'Some Solana RPCs failed while the confirmation window was open',
|
|
37
39
|
}
|
|
38
40
|
|
|
39
|
-
/**
|
|
40
|
-
* `{ Ok: null }`, so only an explicit `{ Err: … }` counts as a failure. */
|
|
41
|
-
function getBundleFailure(err: unknown): { failure: unknown } | undefined {
|
|
42
|
-
if (typeof err !== 'object' || err === null || !('Err' in err)) {
|
|
43
|
-
return undefined
|
|
44
|
-
}
|
|
45
|
-
return { failure: (err as { Err: unknown }).Err }
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
/** The failure of a landed bundle, if any. A `null` in `signatureResults` is
|
|
49
|
-
* indexing lag, never failure. The bundle-level `err` is checked first: it
|
|
50
|
-
* survives a failed `getSignatureStatuses` read. */
|
|
41
|
+
/** The failure of a landed bundle, if any: the first transaction `err`. */
|
|
51
42
|
function bundleFailureOf(
|
|
52
43
|
confirmation: BundleConfirmation
|
|
53
44
|
): { err: unknown } | undefined {
|
|
54
|
-
|
|
55
|
-
if (bundleFailure) {
|
|
56
|
-
return { err: bundleFailure.failure }
|
|
57
|
-
}
|
|
58
|
-
const failedResult = confirmation.signatureResults.find(
|
|
59
|
-
(signatureResult) => signatureResult?.err
|
|
60
|
-
)
|
|
61
|
-
return failedResult?.err ? { err: failedResult.err } : undefined
|
|
45
|
+
return confirmation.signatureResults.map(failureOf).find(Boolean)
|
|
62
46
|
}
|
|
63
47
|
|
|
64
48
|
export class SolanaJitoWaitForTransactionTask extends BaseStepExecutionTask {
|
|
@@ -126,8 +110,10 @@ export class SolanaJitoWaitForTransactionTask extends BaseStepExecutionTask {
|
|
|
126
110
|
|
|
127
111
|
/**
|
|
128
112
|
* Submits the signed bundle once, confirms it and applies the result rules
|
|
129
|
-
* of `sendAndSettle`, on the first run and on a resume alike. A bundle
|
|
130
|
-
* whole or not at all, so the first transaction's signature stands for
|
|
113
|
+
* of `sendAndSettle`, on the first run and on a resume alike. A Jito bundle
|
|
114
|
+
* lands whole or not at all, so the first transaction's signature stands for
|
|
115
|
+
* it. A sender that is not Jito can land the transactions one by one; a
|
|
116
|
+
* lookup by the first signature then misses a partial landing.
|
|
131
117
|
*/
|
|
132
118
|
function sendSigned(
|
|
133
119
|
context: SolanaStepExecutorContext,
|
|
@@ -115,12 +115,11 @@ export class SolanaSignAndExecuteTask extends BaseStepExecutionTask {
|
|
|
115
115
|
// every send failure all sit between this task and the first broadcast.
|
|
116
116
|
// The wait tasks write both on `onBroadcast`, when an RPC has accepted it.
|
|
117
117
|
//
|
|
118
|
-
// The previous transaction's fields (`CLEARED_TRANSACTION_FIELDS
|
|
119
|
-
//
|
|
120
|
-
//
|
|
121
|
-
//
|
|
122
|
-
//
|
|
123
|
-
// output and would otherwise strand the old fields.
|
|
118
|
+
// The previous transaction's fields (`CLEARED_TRANSACTION_FIELDS`) are
|
|
119
|
+
// cleared explicitly. Only a final failure reaches this task with them
|
|
120
|
+
// set, and a stale hash would look open again once its `txFinal` is gone.
|
|
121
|
+
// This write runs BEFORE the decode below, which can throw on a malformed
|
|
122
|
+
// wallet output and would otherwise strand the old fields.
|
|
124
123
|
statusManager.updateAction(step, action.type, 'PENDING', {
|
|
125
124
|
...CLEARED_TRANSACTION_FIELDS,
|
|
126
125
|
signedAt: Date.now(),
|
package/src/rpc/registry.ts
CHANGED
|
@@ -120,9 +120,10 @@ const readProbeFailure = (error: unknown): JitoProbeResult => {
|
|
|
120
120
|
const PROBE_TIMEOUT_MS = 5_000
|
|
121
121
|
|
|
122
122
|
/**
|
|
123
|
-
*
|
|
124
|
-
*
|
|
125
|
-
* support it without exposing
|
|
123
|
+
* Picks the RPCs that may submit a bundle; confirmation reads signatures on
|
|
124
|
+
* every read RPC. Probes with `getBundleStatuses` rather than
|
|
125
|
+
* `getTipAccounts`: providers such as Helius support it without exposing
|
|
126
|
+
* `getTipAccounts`.
|
|
126
127
|
*/
|
|
127
128
|
export const probeJitoRpc = async (
|
|
128
129
|
rpcUrl: string
|
package/src/version.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
export const name = '@lifi/sdk-provider-solana'
|
|
2
|
-
export const version = '4.3.
|
|
2
|
+
export const version = '4.3.6'
|