@lifi/sdk-provider-solana 4.3.3 → 4.3.5
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/README.md +9 -0
- package/dist/cjs/actions/lookupSignatureStatus.d.ts +66 -0
- package/dist/cjs/actions/lookupSignatureStatus.js +258 -0
- package/dist/cjs/actions/lookupSignatureStatus.js.map +1 -0
- package/dist/cjs/actions/sendAndConfirmTransaction.d.ts +7 -0
- package/dist/cjs/actions/sendAndConfirmTransaction.js +1 -0
- package/dist/cjs/actions/sendAndConfirmTransaction.js.map +1 -1
- package/dist/cjs/confirmation/confirmBundle.d.ts +1 -1
- package/dist/cjs/confirmation/confirmSignature.d.ts +1 -1
- package/dist/cjs/confirmation/createConfirmationDeadline.d.ts +6 -0
- package/dist/cjs/confirmation/createConfirmationDeadline.js +24 -8
- package/dist/cjs/confirmation/createConfirmationDeadline.js.map +1 -1
- package/dist/cjs/confirmation/pollUntilDeadline.js +9 -1
- package/dist/cjs/confirmation/pollUntilDeadline.js.map +1 -1
- package/dist/cjs/confirmation/raceRpcs.d.ts +8 -0
- package/dist/cjs/confirmation/raceRpcs.js +9 -1
- package/dist/cjs/confirmation/raceRpcs.js.map +1 -1
- package/dist/cjs/confirmation/types.d.ts +3 -0
- package/dist/cjs/confirmation/types.js.map +1 -1
- package/dist/cjs/core/SolanaStepExecutor.js +2 -4
- package/dist/cjs/core/SolanaStepExecutor.js.map +1 -1
- package/dist/cjs/core/tasks/SolanaJitoWaitForTransactionTask.js +69 -33
- package/dist/cjs/core/tasks/SolanaJitoWaitForTransactionTask.js.map +1 -1
- package/dist/cjs/core/tasks/SolanaSignAndExecuteTask.js +13 -5
- package/dist/cjs/core/tasks/SolanaSignAndExecuteTask.js.map +1 -1
- package/dist/cjs/core/tasks/SolanaStandardWaitForTransactionTask.js +71 -38
- package/dist/cjs/core/tasks/SolanaStandardWaitForTransactionTask.js.map +1 -1
- package/dist/cjs/core/tasks/SolanaWaitForTransactionTask.js +13 -1
- package/dist/cjs/core/tasks/SolanaWaitForTransactionTask.js.map +1 -1
- package/dist/cjs/core/tasks/confirmationError.d.ts +29 -0
- package/dist/cjs/core/tasks/confirmationError.js +26 -0
- package/dist/cjs/core/tasks/confirmationError.js.map +1 -0
- package/dist/cjs/core/tasks/resumeFromStore.d.ts +31 -0
- package/dist/cjs/core/tasks/resumeFromStore.js +81 -0
- package/dist/cjs/core/tasks/resumeFromStore.js.map +1 -0
- package/dist/cjs/core/tasks/transactionOutcome.d.ts +107 -0
- package/dist/cjs/core/tasks/transactionOutcome.js +158 -0
- package/dist/cjs/core/tasks/transactionOutcome.js.map +1 -0
- package/dist/cjs/types.d.ts +13 -2
- package/dist/cjs/types.js.map +1 -1
- package/dist/cjs/utils/storedTransactions.d.ts +36 -0
- package/dist/cjs/utils/storedTransactions.js +57 -0
- package/dist/cjs/utils/storedTransactions.js.map +1 -0
- 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/lookupSignatureStatus.d.ts +66 -0
- package/dist/esm/actions/lookupSignatureStatus.d.ts.map +1 -0
- package/dist/esm/actions/lookupSignatureStatus.js +252 -0
- package/dist/esm/actions/lookupSignatureStatus.js.map +1 -0
- package/dist/esm/actions/sendAndConfirmTransaction.d.ts +7 -0
- package/dist/esm/actions/sendAndConfirmTransaction.d.ts.map +1 -1
- package/dist/esm/actions/sendAndConfirmTransaction.js +1 -0
- package/dist/esm/actions/sendAndConfirmTransaction.js.map +1 -1
- package/dist/esm/confirmation/confirmBundle.d.ts +1 -1
- package/dist/esm/confirmation/confirmSignature.d.ts +1 -1
- package/dist/esm/confirmation/createConfirmationDeadline.d.ts +6 -0
- package/dist/esm/confirmation/createConfirmationDeadline.d.ts.map +1 -1
- package/dist/esm/confirmation/createConfirmationDeadline.js +24 -8
- package/dist/esm/confirmation/createConfirmationDeadline.js.map +1 -1
- package/dist/esm/confirmation/pollUntilDeadline.js +9 -1
- package/dist/esm/confirmation/pollUntilDeadline.js.map +1 -1
- package/dist/esm/confirmation/raceRpcs.d.ts +8 -0
- package/dist/esm/confirmation/raceRpcs.d.ts.map +1 -1
- package/dist/esm/confirmation/raceRpcs.js +9 -1
- package/dist/esm/confirmation/raceRpcs.js.map +1 -1
- package/dist/esm/confirmation/types.d.ts +3 -0
- package/dist/esm/confirmation/types.d.ts.map +1 -1
- package/dist/esm/confirmation/types.js.map +1 -1
- package/dist/esm/core/SolanaStepExecutor.d.ts.map +1 -1
- package/dist/esm/core/SolanaStepExecutor.js +3 -5
- package/dist/esm/core/SolanaStepExecutor.js.map +1 -1
- package/dist/esm/core/tasks/SolanaJitoWaitForTransactionTask.d.ts.map +1 -1
- package/dist/esm/core/tasks/SolanaJitoWaitForTransactionTask.js +69 -33
- package/dist/esm/core/tasks/SolanaJitoWaitForTransactionTask.js.map +1 -1
- package/dist/esm/core/tasks/SolanaSignAndExecuteTask.d.ts.map +1 -1
- package/dist/esm/core/tasks/SolanaSignAndExecuteTask.js +14 -6
- package/dist/esm/core/tasks/SolanaSignAndExecuteTask.js.map +1 -1
- package/dist/esm/core/tasks/SolanaStandardWaitForTransactionTask.d.ts.map +1 -1
- package/dist/esm/core/tasks/SolanaStandardWaitForTransactionTask.js +71 -38
- package/dist/esm/core/tasks/SolanaStandardWaitForTransactionTask.js.map +1 -1
- package/dist/esm/core/tasks/SolanaWaitForTransactionTask.d.ts.map +1 -1
- package/dist/esm/core/tasks/SolanaWaitForTransactionTask.js +13 -1
- package/dist/esm/core/tasks/SolanaWaitForTransactionTask.js.map +1 -1
- package/dist/esm/core/tasks/confirmationError.d.ts +29 -0
- package/dist/esm/core/tasks/confirmationError.d.ts.map +1 -0
- package/dist/esm/core/tasks/confirmationError.js +25 -0
- package/dist/esm/core/tasks/confirmationError.js.map +1 -0
- package/dist/esm/core/tasks/resumeFromStore.d.ts +31 -0
- package/dist/esm/core/tasks/resumeFromStore.d.ts.map +1 -0
- package/dist/esm/core/tasks/resumeFromStore.js +80 -0
- package/dist/esm/core/tasks/resumeFromStore.js.map +1 -0
- package/dist/esm/core/tasks/transactionOutcome.d.ts +107 -0
- package/dist/esm/core/tasks/transactionOutcome.d.ts.map +1 -0
- package/dist/esm/core/tasks/transactionOutcome.js +150 -0
- package/dist/esm/core/tasks/transactionOutcome.js.map +1 -0
- package/dist/esm/types.d.ts +13 -2
- package/dist/esm/types.d.ts.map +1 -1
- package/dist/esm/types.js.map +1 -1
- package/dist/esm/utils/storedTransactions.d.ts +36 -0
- package/dist/esm/utils/storedTransactions.d.ts.map +1 -0
- package/dist/esm/utils/storedTransactions.js +54 -0
- package/dist/esm/utils/storedTransactions.js.map +1 -0
- 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/lookupSignatureStatus.ts +444 -0
- package/src/actions/sendAndConfirmTransaction.ts +18 -0
- package/src/confirmation/createConfirmationDeadline.ts +43 -11
- package/src/confirmation/pollUntilDeadline.ts +14 -1
- package/src/confirmation/raceRpcs.ts +27 -1
- package/src/confirmation/types.ts +5 -0
- package/src/core/SolanaStepExecutor.ts +15 -8
- package/src/core/tasks/SolanaJitoWaitForTransactionTask.ts +133 -71
- package/src/core/tasks/SolanaSignAndExecuteTask.ts +50 -10
- package/src/core/tasks/SolanaStandardWaitForTransactionTask.ts +130 -76
- package/src/core/tasks/SolanaWaitForTransactionTask.ts +19 -1
- package/src/core/tasks/confirmationError.ts +60 -0
- package/src/core/tasks/resumeFromStore.ts +160 -0
- package/src/core/tasks/transactionOutcome.ts +273 -0
- package/src/types.ts +13 -1
- package/src/utils/storedTransactions.ts +88 -0
- package/src/version.ts +1 -1
- package/dist/cjs/core/tasks/unwrapConfirmation.d.ts +0 -24
- package/dist/cjs/core/tasks/unwrapConfirmation.js +0 -24
- package/dist/cjs/core/tasks/unwrapConfirmation.js.map +0 -1
- package/dist/esm/core/tasks/unwrapConfirmation.d.ts +0 -24
- package/dist/esm/core/tasks/unwrapConfirmation.d.ts.map +0 -1
- package/dist/esm/core/tasks/unwrapConfirmation.js +0 -23
- package/dist/esm/core/tasks/unwrapConfirmation.js.map +0 -1
- package/src/core/tasks/unwrapConfirmation.ts +0 -59
|
@@ -35,6 +35,12 @@ export type BlockhashProbeRpc = Pick<SolanaRpcType, 'isBlockhashValid'>
|
|
|
35
35
|
export interface ConfirmationDeadline {
|
|
36
36
|
/** Checked at the top of every poll iteration. */
|
|
37
37
|
reached(): boolean
|
|
38
|
+
/** The slot at which the blockhash probe confirmed expiry - the highest
|
|
39
|
+
* `context.slot` of the `false` answers in the streak - or `undefined`
|
|
40
|
+
* without a verdict. Tells the two reasons `reached()` fires apart: a dead
|
|
41
|
+
* blockhash may later count as "dropped", the wall-clock ceiling never
|
|
42
|
+
* does. */
|
|
43
|
+
expiredAt(): bigint | undefined
|
|
38
44
|
/** Advances the policy; never throws. Probes at most once per
|
|
39
45
|
* `EXPIRY_PROBE_INTERVAL_MS`. */
|
|
40
46
|
tick(signal: AbortSignal): Promise<void>
|
|
@@ -72,6 +78,10 @@ export function createConfirmationDeadline(options: {
|
|
|
72
78
|
|
|
73
79
|
// Keyed by blockhash: expiry is a property of a blockhash, not of the set.
|
|
74
80
|
const expiredStreaks = new Map<Blockhash, number>()
|
|
81
|
+
// The highest `context.slot` of each blockhash's current `false` streak:
|
|
82
|
+
// where a dropped check has to find a node's head before it trusts a
|
|
83
|
+
// `null`. A reset of the streak deletes it.
|
|
84
|
+
const expiredSlots = new Map<Blockhash, bigint>()
|
|
75
85
|
// Keyed for the same reason: a sibling's broken probe is not evidence about
|
|
76
86
|
// this blockhash, so it must not spend this blockhash's error budget.
|
|
77
87
|
const errorStreaks = new Map<Blockhash, number>()
|
|
@@ -81,14 +91,21 @@ export function createConfirmationDeadline(options: {
|
|
|
81
91
|
let lastProbeAt: number | undefined
|
|
82
92
|
|
|
83
93
|
/** Derived, not latched: a blockhash that reads valid again zeroes its
|
|
84
|
-
* streak and clears the verdict with it.
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
94
|
+
* streak and clears the verdict with it. The highest slot among the expired
|
|
95
|
+
* blockhashes is the strictest head bound. */
|
|
96
|
+
const expiredAt = (): bigint | undefined => {
|
|
97
|
+
let slot: bigint | undefined
|
|
98
|
+
for (const [blockhash, streak] of expiredStreaks) {
|
|
99
|
+
const observedAt = expiredSlots.get(blockhash)
|
|
100
|
+
if (
|
|
101
|
+
streak >= EXPIRY_CONFIRMATIONS &&
|
|
102
|
+
observedAt !== undefined &&
|
|
103
|
+
(slot === undefined || observedAt > slot)
|
|
104
|
+
) {
|
|
105
|
+
slot = observedAt
|
|
89
106
|
}
|
|
90
107
|
}
|
|
91
|
-
return
|
|
108
|
+
return slot
|
|
92
109
|
}
|
|
93
110
|
|
|
94
111
|
return {
|
|
@@ -97,8 +114,9 @@ export function createConfirmationDeadline(options: {
|
|
|
97
114
|
if (elapsed >= CONFIRMATION_TIMEOUT_MS) {
|
|
98
115
|
return true
|
|
99
116
|
}
|
|
100
|
-
return
|
|
117
|
+
return expiredAt() !== undefined
|
|
101
118
|
},
|
|
119
|
+
expiredAt,
|
|
102
120
|
async tick(signal: AbortSignal): Promise<void> {
|
|
103
121
|
if (probeable.size === 0 || signal.aborted) {
|
|
104
122
|
return
|
|
@@ -123,16 +141,17 @@ export function createConfirmationDeadline(options: {
|
|
|
123
141
|
const result = await rpc
|
|
124
142
|
.isBlockhashValid(blockhash, { commitment: 'confirmed' })
|
|
125
143
|
.send({ abortSignal: signal })
|
|
126
|
-
return result
|
|
144
|
+
return { value: result?.value, slot: result?.context?.slot }
|
|
127
145
|
})
|
|
128
146
|
)
|
|
129
147
|
|
|
130
148
|
// A read that produced no usable answer says nothing about this
|
|
131
149
|
// blockhash: it must never spend the expiry streak, only the error
|
|
132
150
|
// budget. Shared by a rejected probe and by a fulfilled one whose
|
|
133
|
-
// response carried no
|
|
151
|
+
// response carried no usable verdict.
|
|
134
152
|
const recordFailedProbe = (blockhash: Blockhash): void => {
|
|
135
153
|
expiredStreaks.set(blockhash, 0)
|
|
154
|
+
expiredSlots.delete(blockhash)
|
|
136
155
|
const errors = (errorStreaks.get(blockhash) ?? 0) + 1
|
|
137
156
|
errorStreaks.set(blockhash, errors)
|
|
138
157
|
if (errors >= MAX_PROBE_ERRORS) {
|
|
@@ -149,21 +168,34 @@ export function createConfirmationDeadline(options: {
|
|
|
149
168
|
return
|
|
150
169
|
}
|
|
151
170
|
|
|
171
|
+
const { value, slot } = probe.value
|
|
172
|
+
|
|
152
173
|
// `=== true` / `=== false`, never truthiness: a response carrying no
|
|
153
174
|
// `value` is not a `false`, and reading it as one is the only coercion
|
|
154
175
|
// here that can invent an expiry.
|
|
155
|
-
if (
|
|
176
|
+
if (value === true) {
|
|
156
177
|
errorStreaks.set(blockhash, 0)
|
|
157
178
|
expiredStreaks.set(blockhash, 0)
|
|
179
|
+
expiredSlots.delete(blockhash)
|
|
158
180
|
return
|
|
159
181
|
}
|
|
160
182
|
|
|
161
|
-
|
|
183
|
+
// A `false` counts only with the slot it was observed at: a verdict
|
|
184
|
+
// without one could not bound the head of the dropped check.
|
|
185
|
+
if (value === false && typeof slot === 'bigint') {
|
|
162
186
|
errorStreaks.set(blockhash, 0)
|
|
163
187
|
expiredStreaks.set(
|
|
164
188
|
blockhash,
|
|
165
189
|
(expiredStreaks.get(blockhash) ?? 0) + 1
|
|
166
190
|
)
|
|
191
|
+
// The highest slot, not the latest: a `false` from a node whose head
|
|
192
|
+
// is behind the others must not lower the bound below the slots
|
|
193
|
+
// where the transaction can still land.
|
|
194
|
+
const previous = expiredSlots.get(blockhash)
|
|
195
|
+
expiredSlots.set(
|
|
196
|
+
blockhash,
|
|
197
|
+
previous === undefined || slot > previous ? slot : previous
|
|
198
|
+
)
|
|
167
199
|
return
|
|
168
200
|
}
|
|
169
201
|
|
|
@@ -86,9 +86,13 @@ export async function pollUntilDeadline<T>(options: {
|
|
|
86
86
|
// mid-read is not. The final probe below is a bonus on top of a complete
|
|
87
87
|
// observation, so losing it must not downgrade the verdict.
|
|
88
88
|
let deadlineReached = false
|
|
89
|
+
// Latched when the loop ends: did the blockhash verdict end it, or the
|
|
90
|
+
// ceiling? Only the verdict may later count as "dropped".
|
|
91
|
+
let expiredAtDeadline: bigint | undefined
|
|
89
92
|
while (!signal.aborted) {
|
|
90
93
|
if (deadline.reached()) {
|
|
91
94
|
deadlineReached = true
|
|
95
|
+
expiredAtDeadline = deadline.expiredAt()
|
|
92
96
|
break
|
|
93
97
|
}
|
|
94
98
|
try {
|
|
@@ -151,7 +155,16 @@ export async function pollUntilDeadline<T>(options: {
|
|
|
151
155
|
// would discard every observation and report a fleet-wide expiry as an
|
|
152
156
|
// outage.
|
|
153
157
|
if (probeSucceeded && deadlineReached) {
|
|
154
|
-
|
|
158
|
+
// `expired` needs the verdict both when the loop ended and now. The
|
|
159
|
+
// detached loop keeps probing through the final probe, and a blockhash
|
|
160
|
+
// that reads valid again withdraws the verdict. A withdrawn verdict and
|
|
161
|
+
// one that arrived only after the ceiling are both no expiry. The slot
|
|
162
|
+
// is the one the deadline reports now.
|
|
163
|
+
const expiredAt =
|
|
164
|
+
expiredAtDeadline === undefined ? undefined : deadline.expiredAt()
|
|
165
|
+
return expiredAt === undefined
|
|
166
|
+
? { kind: 'not-confirmed' }
|
|
167
|
+
: { kind: 'expired', slot: expiredAt }
|
|
155
168
|
}
|
|
156
169
|
|
|
157
170
|
if (options.neverBroadcast?.()) {
|
|
@@ -2,9 +2,18 @@ import type { ConfirmationOutcome } from './types.js'
|
|
|
2
2
|
|
|
3
3
|
export type RaceResult<T> =
|
|
4
4
|
| { kind: 'confirmed'; value: T }
|
|
5
|
+
/** `slot`: the highest verdict slot of the branches. The transaction can
|
|
6
|
+
* no longer land after it. */
|
|
7
|
+
| { kind: 'expired'; slot: bigint; errors: Error[] }
|
|
5
8
|
| { kind: 'not-confirmed'; errors: Error[] }
|
|
6
9
|
| { kind: 'rpc-unavailable'; errors: Error[] }
|
|
7
10
|
|
|
11
|
+
/** Every result that is not a confirmation. Independent of the value type. */
|
|
12
|
+
export type UnconfirmedRaceResult = Exclude<
|
|
13
|
+
RaceResult<unknown>,
|
|
14
|
+
{ kind: 'confirmed' }
|
|
15
|
+
>
|
|
16
|
+
|
|
8
17
|
const toError = (reason: unknown): Error =>
|
|
9
18
|
reason instanceof Error ? reason : new Error(String(reason))
|
|
10
19
|
|
|
@@ -88,6 +97,7 @@ export async function raceRpcs<Rpc, T>(
|
|
|
88
97
|
const classify = (
|
|
89
98
|
results: PromiseSettledResult<ConfirmationOutcome<T>>[]
|
|
90
99
|
): RaceResult<T> => {
|
|
100
|
+
let expiredAtSlot: bigint | undefined
|
|
91
101
|
let sawNotConfirmed = false
|
|
92
102
|
const errors: Error[] = []
|
|
93
103
|
|
|
@@ -98,7 +108,15 @@ export async function raceRpcs<Rpc, T>(
|
|
|
98
108
|
if (entry.value.kind === 'confirmed') {
|
|
99
109
|
return { kind: 'confirmed', value: entry.value.value }
|
|
100
110
|
}
|
|
101
|
-
|
|
111
|
+
if (entry.value.kind === 'expired') {
|
|
112
|
+
// The highest verdict slot: the strictest head a dropped check can
|
|
113
|
+
// demand.
|
|
114
|
+
if (expiredAtSlot === undefined || entry.value.slot > expiredAtSlot) {
|
|
115
|
+
expiredAtSlot = entry.value.slot
|
|
116
|
+
}
|
|
117
|
+
} else {
|
|
118
|
+
sawNotConfirmed = true
|
|
119
|
+
}
|
|
102
120
|
continue
|
|
103
121
|
}
|
|
104
122
|
// Cancelled branches are not failures. A branch the timeout killed is,
|
|
@@ -111,9 +129,17 @@ export async function raceRpcs<Rpc, T>(
|
|
|
111
129
|
|
|
112
130
|
// A completed observation outranks a thrown error, but the collected
|
|
113
131
|
// errors still travel with it as the expiry's `cause`.
|
|
132
|
+
//
|
|
133
|
+
// Among the observations, the ceiling outranks an expiry: `expired` may
|
|
134
|
+
// end in a final "dropped", so every branch that observed has to agree
|
|
135
|
+
// on it. A stale node alone must not drop a transaction that another
|
|
136
|
+
// endpoint still watched to its ceiling.
|
|
114
137
|
if (sawNotConfirmed) {
|
|
115
138
|
return { kind: 'not-confirmed', errors }
|
|
116
139
|
}
|
|
140
|
+
if (expiredAtSlot !== undefined) {
|
|
141
|
+
return { kind: 'expired', slot: expiredAtSlot, errors }
|
|
142
|
+
}
|
|
117
143
|
return { kind: 'rpc-unavailable', errors }
|
|
118
144
|
}
|
|
119
145
|
|
|
@@ -14,6 +14,11 @@ export type SignatureStatus = NonNullable<
|
|
|
14
14
|
/** What a single RPC branch is allowed to report. Failure is a throw. */
|
|
15
15
|
export type ConfirmationOutcome<T> =
|
|
16
16
|
| { kind: 'confirmed'; value: T }
|
|
17
|
+
/** The blockhash probe confirmed expiry: the transaction can no longer
|
|
18
|
+
* land after `slot`, the `isBlockhashValid` context slot of the verdict.
|
|
19
|
+
* The only outcome that may end in a final "dropped". */
|
|
20
|
+
| { kind: 'expired'; slot: bigint }
|
|
21
|
+
/** The wall-clock ceiling ended the observation without a verdict. */
|
|
17
22
|
| { kind: 'not-confirmed' }
|
|
18
23
|
|
|
19
24
|
export function isConfirmedCommitment(
|
|
@@ -2,6 +2,7 @@ import {
|
|
|
2
2
|
BaseStepExecutor,
|
|
3
3
|
CheckBalanceTask,
|
|
4
4
|
type ExecutionAction,
|
|
5
|
+
hasOpenTransaction,
|
|
5
6
|
LiFiErrorCode,
|
|
6
7
|
type LiFiStepExtended,
|
|
7
8
|
PrepareTransactionTask,
|
|
@@ -54,14 +55,12 @@ export class SolanaStepExecutor extends BaseStepExecutor {
|
|
|
54
55
|
override createContext = async (
|
|
55
56
|
baseContext: StepExecutorBaseContext
|
|
56
57
|
): Promise<SolanaStepExecutorContext> => {
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
const walletAccount = this.getWalletAccount(step)
|
|
60
|
-
|
|
58
|
+
// The account is resolved by the sign task, not here: a resume that only
|
|
59
|
+
// waits must not fail because the wallet has not reconnected yet.
|
|
61
60
|
return {
|
|
62
61
|
...baseContext,
|
|
63
62
|
wallet: this.wallet,
|
|
64
|
-
|
|
63
|
+
getWalletAccount: this.getWalletAccount,
|
|
65
64
|
skipSimulation: this.skipSimulation,
|
|
66
65
|
}
|
|
67
66
|
}
|
|
@@ -86,10 +85,18 @@ export class SolanaStepExecutor extends BaseStepExecutor {
|
|
|
86
85
|
isBridgeExecution ? 'CROSS_CHAIN' : 'SWAP'
|
|
87
86
|
)
|
|
88
87
|
|
|
89
|
-
|
|
90
|
-
|
|
88
|
+
// Three-way, as Stellar and Bitcoin do. An open transaction - a broadcast
|
|
89
|
+
// signature, or signed bytes that may have been sent - resumes at the
|
|
90
|
+
// wait task, which looks it up and resends the same bytes. Starting at
|
|
91
|
+
// CheckBalanceTask would fetch a new quote and sign a second transaction
|
|
92
|
+
// while the first can still land. A same-chain swap stays PENDING with
|
|
93
|
+
// its signature until the LI.FI status is DONE, so this is the common
|
|
94
|
+
// reload.
|
|
95
|
+
const firstTask = hasOpenTransaction(swapOrBridgeAction)
|
|
96
|
+
? swapOrBridgeAction?.status === 'DONE'
|
|
91
97
|
? WaitForTransactionStatusTask
|
|
92
|
-
:
|
|
98
|
+
: SolanaWaitForTransactionTask
|
|
99
|
+
: CheckBalanceTask
|
|
93
100
|
|
|
94
101
|
// Compare classes, not names: a minifier can give two task classes the
|
|
95
102
|
// same name.
|
|
@@ -1,14 +1,40 @@
|
|
|
1
1
|
import {
|
|
2
2
|
BaseStepExecutionTask,
|
|
3
|
+
type ExecutionAction,
|
|
3
4
|
LiFiErrorCode,
|
|
4
5
|
type TaskResult,
|
|
5
6
|
TransactionError,
|
|
6
7
|
} from '@lifi/sdk'
|
|
8
|
+
import type { Signature, Transaction } from '@solana/kit'
|
|
7
9
|
import { sendAndConfirmBundle } from '../../actions/sendAndConfirmBundle.js'
|
|
10
|
+
import type { BundleConfirmation } from '../../confirmation/confirmBundle.js'
|
|
11
|
+
import type { RaceResult } from '../../confirmation/raceRpcs.js'
|
|
8
12
|
import type { SolanaStepExecutorContext } from '../../types.js'
|
|
9
|
-
import {
|
|
13
|
+
import {
|
|
14
|
+
getTransactionLifetime,
|
|
15
|
+
type TransactionLifetime,
|
|
16
|
+
} from '../../utils/getTransactionLifetime.js'
|
|
17
|
+
import type { ConfirmationMessages } from './confirmationError.js'
|
|
10
18
|
import { readSignature } from './readSignature.js'
|
|
11
|
-
import {
|
|
19
|
+
import { resumeFromStore } from './resumeFromStore.js'
|
|
20
|
+
import {
|
|
21
|
+
canResendStored,
|
|
22
|
+
clearStoredTransactions,
|
|
23
|
+
getTxLink,
|
|
24
|
+
sendAndSettle,
|
|
25
|
+
} from './transactionOutcome.js'
|
|
26
|
+
|
|
27
|
+
// The `rpc-unavailable` message is distinct from the empty-list throw inside
|
|
28
|
+
// `sendAndConfirmBundle`: RPCs were configured and every one of them failed.
|
|
29
|
+
// That is an outage, and the collected branch errors say what each endpoint
|
|
30
|
+
// did.
|
|
31
|
+
const MESSAGES: ConfirmationMessages = {
|
|
32
|
+
rpcUnavailable: 'Unable to confirm bundle: every configured Jito RPC failed.',
|
|
33
|
+
notConfirmed: 'Bundle was not confirmed before the SDK stopped waiting.',
|
|
34
|
+
allRpcsFailed: 'All Jito RPCs failed',
|
|
35
|
+
someRpcsFailed:
|
|
36
|
+
'Some Jito RPCs failed while the confirmation window was open',
|
|
37
|
+
}
|
|
12
38
|
|
|
13
39
|
/** Jito encodes `err` as a Rust `Result`: a landed bundle carries
|
|
14
40
|
* `{ Ok: null }`, so only an explicit `{ Err: … }` counts as a failure. */
|
|
@@ -19,18 +45,26 @@ function getBundleFailure(err: unknown): { failure: unknown } | undefined {
|
|
|
19
45
|
return { failure: (err as { Err: unknown }).Err }
|
|
20
46
|
}
|
|
21
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. */
|
|
51
|
+
function bundleFailureOf(
|
|
52
|
+
confirmation: BundleConfirmation
|
|
53
|
+
): { err: unknown } | undefined {
|
|
54
|
+
const bundleFailure = getBundleFailure(confirmation.bundleErr)
|
|
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
|
|
62
|
+
}
|
|
63
|
+
|
|
22
64
|
export class SolanaJitoWaitForTransactionTask extends BaseStepExecutionTask {
|
|
23
65
|
async run(context: SolanaStepExecutorContext): Promise<TaskResult> {
|
|
24
|
-
const {
|
|
25
|
-
|
|
26
|
-
step,
|
|
27
|
-
statusManager,
|
|
28
|
-
fromChain,
|
|
29
|
-
isBridgeExecution,
|
|
30
|
-
signedTransactions: contextSignedTransactions,
|
|
31
|
-
} = context
|
|
32
|
-
|
|
33
|
-
const signedTransactions = contextSignedTransactions ?? []
|
|
66
|
+
const { step, statusManager, isBridgeExecution, signedTransactions } =
|
|
67
|
+
context
|
|
34
68
|
|
|
35
69
|
const action = statusManager.findAction(
|
|
36
70
|
step,
|
|
@@ -43,6 +77,22 @@ export class SolanaJitoWaitForTransactionTask extends BaseStepExecutionTask {
|
|
|
43
77
|
)
|
|
44
78
|
}
|
|
45
79
|
|
|
80
|
+
// Resume mode: the sign task did not run in this session, so the signed
|
|
81
|
+
// bundle comes from `txHex`, or only the first hash from `txHash`.
|
|
82
|
+
if (!signedTransactions) {
|
|
83
|
+
return resumeFromStore(context, action, {
|
|
84
|
+
messages: MESSAGES,
|
|
85
|
+
// Submitted once, as on the first run.
|
|
86
|
+
send: (stored, lifetimes) =>
|
|
87
|
+
sendSigned(context, action, {
|
|
88
|
+
transactions: stored.transactions,
|
|
89
|
+
signature: stored.signature,
|
|
90
|
+
lifetimes,
|
|
91
|
+
resuming: true,
|
|
92
|
+
}),
|
|
93
|
+
})
|
|
94
|
+
}
|
|
95
|
+
|
|
46
96
|
if (!signedTransactions.length) {
|
|
47
97
|
throw new TransactionError(
|
|
48
98
|
LiFiErrorCode.TransactionUnprepared,
|
|
@@ -50,70 +100,82 @@ export class SolanaJitoWaitForTransactionTask extends BaseStepExecutionTask {
|
|
|
50
100
|
)
|
|
51
101
|
}
|
|
52
102
|
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
onBroadcast: () => {
|
|
61
|
-
// The earliest honest point for both: an RPC has accepted the
|
|
62
|
-
// transaction, so the signature now resolves on chain.
|
|
63
|
-
statusManager.updateAction(step, action.type, 'PENDING', {
|
|
64
|
-
txHash: txSignature,
|
|
65
|
-
txLink,
|
|
66
|
-
})
|
|
67
|
-
},
|
|
68
|
-
})
|
|
69
|
-
|
|
70
|
-
// The `rpc-unavailable` message is distinct from the empty-list throw
|
|
71
|
-
// above: RPCs were configured and every one of them failed. That is an
|
|
72
|
-
// outage, and the collected branch errors say what each endpoint did.
|
|
73
|
-
const bundleResult = unwrapConfirmation(result, {
|
|
74
|
-
rpcUnavailable:
|
|
75
|
-
'Unable to confirm bundle: every configured Jito RPC failed.',
|
|
76
|
-
notConfirmed: 'Bundle was not confirmed before the SDK stopped waiting.',
|
|
77
|
-
allRpcsFailed: 'All Jito RPCs failed',
|
|
78
|
-
someRpcsFailed:
|
|
79
|
-
'Some Jito RPCs failed while the confirmation window was open',
|
|
80
|
-
})
|
|
81
|
-
|
|
82
|
-
// A `null` in `signatureResults` is indexing lag, never failure. The
|
|
83
|
-
// bundle-level `err` is checked first: it survives a failed
|
|
84
|
-
// `getSignatureStatuses` read.
|
|
85
|
-
const bundleFailure = getBundleFailure(bundleResult.bundleErr)
|
|
86
|
-
if (bundleFailure) {
|
|
87
|
-
const cause = new SolanaTransactionDetailsError(bundleFailure.failure)
|
|
88
|
-
throw new TransactionError(
|
|
89
|
-
LiFiErrorCode.TransactionFailed,
|
|
90
|
-
`Transaction failed: ${cause.message}`,
|
|
91
|
-
cause
|
|
92
|
-
)
|
|
103
|
+
let txSignature: Signature
|
|
104
|
+
try {
|
|
105
|
+
txSignature = readSignature(signedTransactions[0])
|
|
106
|
+
} catch (error) {
|
|
107
|
+
// Nothing left the SDK: the bytes go, so "Try again" signs again.
|
|
108
|
+
clearStoredTransactions(context, action)
|
|
109
|
+
throw error
|
|
93
110
|
}
|
|
94
111
|
|
|
95
|
-
const
|
|
96
|
-
(
|
|
97
|
-
|
|
98
|
-
if (failedResult?.err) {
|
|
99
|
-
const cause = new SolanaTransactionDetailsError(failedResult.err)
|
|
100
|
-
throw new TransactionError(
|
|
101
|
-
LiFiErrorCode.TransactionFailed,
|
|
102
|
-
`Transaction failed: ${cause.message}`,
|
|
103
|
-
cause
|
|
112
|
+
const lifetimes = await Promise.all(
|
|
113
|
+
signedTransactions.map((transaction) =>
|
|
114
|
+
getTransactionLifetime(transaction)
|
|
104
115
|
)
|
|
105
|
-
|
|
116
|
+
)
|
|
106
117
|
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
118
|
+
return sendSigned(context, action, {
|
|
119
|
+
transactions: signedTransactions,
|
|
120
|
+
signature: txSignature,
|
|
121
|
+
lifetimes,
|
|
122
|
+
resuming: false,
|
|
111
123
|
})
|
|
124
|
+
}
|
|
125
|
+
}
|
|
112
126
|
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
127
|
+
/**
|
|
128
|
+
* 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 lands
|
|
130
|
+
* whole or not at all, so the first transaction's signature stands for it.
|
|
131
|
+
*/
|
|
132
|
+
function sendSigned(
|
|
133
|
+
context: SolanaStepExecutorContext,
|
|
134
|
+
action: ExecutionAction,
|
|
135
|
+
options: {
|
|
136
|
+
transactions: Transaction[]
|
|
137
|
+
signature: Signature
|
|
138
|
+
lifetimes: TransactionLifetime[]
|
|
139
|
+
/** An earlier run may already have submitted this bundle. */
|
|
140
|
+
resuming: boolean
|
|
118
141
|
}
|
|
142
|
+
): Promise<TaskResult> {
|
|
143
|
+
const { client, step, statusManager } = context
|
|
144
|
+
const { transactions, signature, lifetimes, resuming } = options
|
|
145
|
+
const txLink = getTxLink(context, signature)
|
|
146
|
+
|
|
147
|
+
return sendAndSettle(context, action, {
|
|
148
|
+
signature,
|
|
149
|
+
send: async (): Promise<RaceResult<BundleConfirmation>> => {
|
|
150
|
+
// Read right before the one submission: a bundle without its own
|
|
151
|
+
// expiry goes out only inside the resend age cap. Past it nothing is
|
|
152
|
+
// sent, and the outcome stays unknown until the dropped rule holds.
|
|
153
|
+
if (!canResendStored(lifetimes, step.execution?.signedAt)) {
|
|
154
|
+
return {
|
|
155
|
+
kind: 'not-confirmed',
|
|
156
|
+
errors: [
|
|
157
|
+
new Error(
|
|
158
|
+
'The resend age cap has passed; the stored bundle is not sent.'
|
|
159
|
+
),
|
|
160
|
+
],
|
|
161
|
+
}
|
|
162
|
+
}
|
|
163
|
+
// An empty Jito RPC list - the configuration gap, as opposed to an
|
|
164
|
+
// outage - throws inside `sendAndConfirmBundle` with its own message,
|
|
165
|
+
// before anything is submitted.
|
|
166
|
+
return sendAndConfirmBundle(client, transactions, {
|
|
167
|
+
onBroadcast: () => {
|
|
168
|
+
// The earliest honest point for both: an RPC has accepted the
|
|
169
|
+
// transaction, so the signature now resolves on chain.
|
|
170
|
+
statusManager.updateAction(step, action.type, 'PENDING', {
|
|
171
|
+
txHash: signature,
|
|
172
|
+
txLink,
|
|
173
|
+
})
|
|
174
|
+
},
|
|
175
|
+
})
|
|
176
|
+
},
|
|
177
|
+
confirmedFailure: bundleFailureOf,
|
|
178
|
+
resuming,
|
|
179
|
+
messages: MESSAGES,
|
|
180
|
+
})
|
|
119
181
|
}
|
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
import {
|
|
2
|
+
assertNoOpenTransaction,
|
|
2
3
|
BaseStepExecutionTask,
|
|
4
|
+
CLEARED_TRANSACTION_FIELDS,
|
|
3
5
|
getTransactionRequestData,
|
|
4
6
|
LiFiErrorCode,
|
|
5
7
|
type TaskResult,
|
|
@@ -11,13 +13,15 @@ import { SolanaSignTransaction } from '@solana/wallet-standard-features'
|
|
|
11
13
|
import type { SolanaStepExecutorContext } from '../../types.js'
|
|
12
14
|
import { base64ToUint8Array } from '../../utils/base64ToUint8Array.js'
|
|
13
15
|
import { getWalletFeature } from '../../utils/getWalletFeature.js'
|
|
16
|
+
import { encodeStoredTransactions } from '../../utils/storedTransactions.js'
|
|
17
|
+
import { readSignature } from './readSignature.js'
|
|
14
18
|
|
|
15
19
|
export class SolanaSignAndExecuteTask extends BaseStepExecutionTask {
|
|
16
20
|
async run(context: SolanaStepExecutorContext): Promise<TaskResult> {
|
|
17
21
|
const {
|
|
18
22
|
step,
|
|
19
23
|
wallet,
|
|
20
|
-
|
|
24
|
+
getWalletAccount,
|
|
21
25
|
statusManager,
|
|
22
26
|
executionOptions,
|
|
23
27
|
isBridgeExecution,
|
|
@@ -27,6 +31,12 @@ export class SolanaSignAndExecuteTask extends BaseStepExecutionTask {
|
|
|
27
31
|
step,
|
|
28
32
|
isBridgeExecution ? 'CROSS_CHAIN' : 'SWAP'
|
|
29
33
|
)
|
|
34
|
+
|
|
35
|
+
// Defence in depth: the selector sends an action with an open
|
|
36
|
+
// transaction to the wait task. Signing here could put a second
|
|
37
|
+
// transaction on chain while the first can still land.
|
|
38
|
+
assertNoOpenTransaction(action)
|
|
39
|
+
|
|
30
40
|
if (!action) {
|
|
31
41
|
throw new TransactionError(
|
|
32
42
|
LiFiErrorCode.TransactionUnprepared,
|
|
@@ -34,6 +44,11 @@ export class SolanaSignAndExecuteTask extends BaseStepExecutionTask {
|
|
|
34
44
|
)
|
|
35
45
|
}
|
|
36
46
|
|
|
47
|
+
// Resolved here and not in `createContext`: a resume that only waits
|
|
48
|
+
// never signs, so it must not fail because the wallet has not
|
|
49
|
+
// reconnected yet.
|
|
50
|
+
const walletAccount = getWalletAccount(step)
|
|
51
|
+
|
|
37
52
|
const transactionRequestData = (await getTransactionRequestData(
|
|
38
53
|
step,
|
|
39
54
|
executionOptions
|
|
@@ -52,6 +67,10 @@ export class SolanaSignAndExecuteTask extends BaseStepExecutionTask {
|
|
|
52
67
|
base64ToUint8Array(data)
|
|
53
68
|
)
|
|
54
69
|
|
|
70
|
+
// Checked again right before the wallet: a late write of an older run
|
|
71
|
+
// can merge its transaction into this action during the await above.
|
|
72
|
+
assertNoOpenTransaction(statusManager.findAction(step, action.type))
|
|
73
|
+
|
|
55
74
|
const signedTransactionOutputs = await withTimeout(
|
|
56
75
|
async () => {
|
|
57
76
|
const { signTransaction } = getWalletFeature(
|
|
@@ -77,6 +96,12 @@ export class SolanaSignAndExecuteTask extends BaseStepExecutionTask {
|
|
|
77
96
|
}
|
|
78
97
|
)
|
|
79
98
|
|
|
99
|
+
// Checked once more after the wallet: a stopped run's late write can
|
|
100
|
+
// merge its transaction into this action while the prompt is open.
|
|
101
|
+
// Nothing awaits from here to the two writes below, so no late write can
|
|
102
|
+
// land between this check and either of them.
|
|
103
|
+
assertNoOpenTransaction(statusManager.findAction(step, action.type))
|
|
104
|
+
|
|
80
105
|
if (signedTransactionOutputs.length === 0) {
|
|
81
106
|
throw new TransactionError(
|
|
82
107
|
LiFiErrorCode.TransactionUnprepared,
|
|
@@ -90,17 +115,14 @@ export class SolanaSignAndExecuteTask extends BaseStepExecutionTask {
|
|
|
90
115
|
// every send failure all sit between this task and the first broadcast.
|
|
91
116
|
// The wait tasks write both on `onBroadcast`, when an RPC has accepted it.
|
|
92
117
|
//
|
|
93
|
-
//
|
|
94
|
-
//
|
|
95
|
-
//
|
|
96
|
-
//
|
|
97
|
-
//
|
|
98
|
-
// BEFORE the decode below, which can throw on a malformed wallet
|
|
99
|
-
// output and would otherwise strand the previous run's signature.
|
|
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.
|
|
100
123
|
statusManager.updateAction(step, action.type, 'PENDING', {
|
|
124
|
+
...CLEARED_TRANSACTION_FIELDS,
|
|
101
125
|
signedAt: Date.now(),
|
|
102
|
-
txHash: undefined,
|
|
103
|
-
txLink: undefined,
|
|
104
126
|
})
|
|
105
127
|
|
|
106
128
|
const transactionCodec = getTransactionCodec()
|
|
@@ -110,6 +132,24 @@ export class SolanaSignAndExecuteTask extends BaseStepExecutionTask {
|
|
|
110
132
|
transactionCodec.decode(output.signedTransaction)
|
|
111
133
|
)
|
|
112
134
|
|
|
135
|
+
// Every transaction must carry its fee payer signature before its bytes
|
|
136
|
+
// are stored: an unreadable value would fail every resume the same way.
|
|
137
|
+
// Nothing has been sent yet, so the `TransactionUnprepared` this throws
|
|
138
|
+
// leaves "Try again" free to sign again.
|
|
139
|
+
for (const signedTransaction of signedTransactions) {
|
|
140
|
+
readSignature(signedTransaction)
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
// Stored before any send: a reload from here on resends these bytes
|
|
144
|
+
// instead of asking the wallet again. A bundle stays a JSON array, which
|
|
145
|
+
// is how a resume knows to submit it with `sendBundle`.
|
|
146
|
+
statusManager.updateAction(step, action.type, 'PENDING', {
|
|
147
|
+
txHex: encodeStoredTransactions(
|
|
148
|
+
signedTransactionOutputs.map((output) => output.signedTransaction),
|
|
149
|
+
isBundleExecution
|
|
150
|
+
),
|
|
151
|
+
})
|
|
152
|
+
|
|
113
153
|
return {
|
|
114
154
|
status: 'COMPLETED',
|
|
115
155
|
context: { signedTransactions, isBundleExecution },
|