@lifi/sdk-provider-solana 4.3.2 → 4.3.4
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 +14 -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 +4 -5
- 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 +5 -6
- 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 +26 -11
- package/src/core/tasks/SolanaJitoWaitForTransactionTask.ts +133 -71
- package/src/core/tasks/SolanaSignAndExecuteTask.ts +51 -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
|
@@ -0,0 +1,158 @@
|
|
|
1
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
|
+
const require_confirmation_types = require("../../confirmation/types.js");
|
|
3
|
+
const require_actions_lookupSignatureStatus = require("../../actions/lookupSignatureStatus.js");
|
|
4
|
+
const require_core_tasks_confirmationError = require("./confirmationError.js");
|
|
5
|
+
const require_utils_solanaErrorCause = require("../../utils/solanaErrorCause.js");
|
|
6
|
+
let _lifi_sdk = require("@lifi/sdk");
|
|
7
|
+
//#region src/core/tasks/transactionOutcome.ts
|
|
8
|
+
/** Explorer link for a signature, as both wait tasks write it. */
|
|
9
|
+
function getTxLink(context, signature) {
|
|
10
|
+
return `${context.fromChain.metamask.blockExplorerUrls[0]}tx/${signature}`;
|
|
11
|
+
}
|
|
12
|
+
/**
|
|
13
|
+
* May stored bytes be sent (again)? A blockhash transaction always: the
|
|
14
|
+
* chain rejects it once the blockhash dies, and the deadline's probe tells
|
|
15
|
+
* when. Anything else - a durable nonce, a lifetime that did not decode -
|
|
16
|
+
* only inside the resend age cap, so a page load hours later cannot execute
|
|
17
|
+
* a swap on an old quote.
|
|
18
|
+
*/
|
|
19
|
+
function canResendStored(lifetimes, signedAt, now) {
|
|
20
|
+
return lifetimes.length > 0 && lifetimes.every((lifetime) => lifetime.kind === "blockhash") || (0, _lifi_sdk.isResendAllowed)(signedAt, now);
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* Condition (a) of the dropped rule in `resolveUnconfirmed`: the chain says
|
|
24
|
+
* the transaction can no longer land.
|
|
25
|
+
*
|
|
26
|
+
* - An `expired` verdict: the blockhash probe saw it dead.
|
|
27
|
+
* - Without a verdict, `isOldEnoughToDrop` for every lifetime. For a
|
|
28
|
+
* blockhash transaction that is the five-minute time fallback. For a
|
|
29
|
+
* durable nonce or an undecodable lifetime it is the age cap passed plus a
|
|
30
|
+
* margin: sends stop at the cap, and the three minutes after it put the
|
|
31
|
+
* lookup's current-slot head safely past any slot the transaction could
|
|
32
|
+
* still land in.
|
|
33
|
+
*
|
|
34
|
+
* An unknown signing time never holds by time.
|
|
35
|
+
*/
|
|
36
|
+
function cannotLandAnymore(options) {
|
|
37
|
+
return options.expired || (0, _lifi_sdk.isOldEnoughToDrop)(options.signedAt, options.now);
|
|
38
|
+
}
|
|
39
|
+
/** Drops the stored bytes: never sent, landed, or final. */
|
|
40
|
+
function clearStoredTransactions(context, action) {
|
|
41
|
+
context.statusManager.updateAction(context.step, action.type, "PENDING", { txHex: void 0 });
|
|
42
|
+
}
|
|
43
|
+
/** A signature status's `err` as the failure `recordLanded` takes. */
|
|
44
|
+
function failureOf(status) {
|
|
45
|
+
return status.err ? { err: status.err } : void 0;
|
|
46
|
+
}
|
|
47
|
+
/**
|
|
48
|
+
* Result rule for a transaction the chain has: writes `txHash` and `txLink`,
|
|
49
|
+
* clears the stored bytes, then completes - or throws the final
|
|
50
|
+
* `TransactionFailed` for one that failed on chain.
|
|
51
|
+
*
|
|
52
|
+
* The hash is written for a failed transaction too: it exists on chain, and
|
|
53
|
+
* a resume that found it by lookup has no `txHash` yet.
|
|
54
|
+
*/
|
|
55
|
+
function recordLanded(context, action, options) {
|
|
56
|
+
const { step, statusManager, isBridgeExecution } = context;
|
|
57
|
+
const { signature, failure } = options;
|
|
58
|
+
statusManager.updateAction(step, action.type, "PENDING", {
|
|
59
|
+
txHash: signature,
|
|
60
|
+
txLink: getTxLink(context, signature),
|
|
61
|
+
txHex: void 0
|
|
62
|
+
});
|
|
63
|
+
if (failure) {
|
|
64
|
+
const cause = new require_utils_solanaErrorCause.SolanaTransactionDetailsError(failure.err);
|
|
65
|
+
throw new _lifi_sdk.TransactionError(_lifi_sdk.LiFiErrorCode.TransactionFailed, `Transaction failed: ${cause.message}`, cause, { final: true });
|
|
66
|
+
}
|
|
67
|
+
if (isBridgeExecution) statusManager.updateAction(step, action.type, "DONE");
|
|
68
|
+
return { status: "COMPLETED" };
|
|
69
|
+
}
|
|
70
|
+
/**
|
|
71
|
+
* Decides what a transaction that did not confirm is: landed after all
|
|
72
|
+
* (returns its status), dropped (throws a final `TransactionExpired`), or
|
|
73
|
+
* unknown (rethrows `error`, the error the task built for today's outcome).
|
|
74
|
+
*
|
|
75
|
+
* Dropped (see the resume rules in `transactionState.ts`) = (a)
|
|
76
|
+
* `cannotLandAnymore`, AND (b) a lookup that proves the absence - a covering
|
|
77
|
+
* RPC whose head is past the landing window answered `null` in the same
|
|
78
|
+
* response, and no RPC has the transaction - AND (c) the status API does not
|
|
79
|
+
* know the hash. The status API only vetoes: it answers 404 for landed
|
|
80
|
+
* transactions it does not index too, so a miss there proves nothing.
|
|
81
|
+
*/
|
|
82
|
+
async function resolveUnconfirmed(context, action, options) {
|
|
83
|
+
const { client, step } = context;
|
|
84
|
+
const { signature, error, expiredAtSlot } = options;
|
|
85
|
+
const signedAt = step.execution?.signedAt;
|
|
86
|
+
if (!cannotLandAnymore({
|
|
87
|
+
expired: expiredAtSlot !== void 0,
|
|
88
|
+
signedAt
|
|
89
|
+
})) throw error;
|
|
90
|
+
if (signedAt === void 0) throw error;
|
|
91
|
+
const lookup = await require_actions_lookupSignatureStatus.lookupSignatureStatus(client, signature, {
|
|
92
|
+
anchor: signedAt - _lifi_sdk.CLOCK_SKEW_MARGIN_MS,
|
|
93
|
+
expiredAtSlot
|
|
94
|
+
});
|
|
95
|
+
if (lookup.kind === "found" && require_confirmation_types.isConfirmedCommitment(lookup.status.confirmationStatus)) return lookup.status;
|
|
96
|
+
if (lookup.kind !== "not-found") throw error;
|
|
97
|
+
if (await (0, _lifi_sdk.isKnownToStatusApi)(client, step, signature)) throw error;
|
|
98
|
+
clearStoredTransactions(context, action);
|
|
99
|
+
throw new _lifi_sdk.TransactionError(_lifi_sdk.LiFiErrorCode.TransactionExpired, options.messages.notConfirmed, error instanceof Error ? error : void 0, { final: true });
|
|
100
|
+
}
|
|
101
|
+
/**
|
|
102
|
+
* The send-and-settle tail both wait tasks share: runs `send`, then applies
|
|
103
|
+
* the result rules to what it reports.
|
|
104
|
+
*
|
|
105
|
+
* - A confirmation goes to `recordLanded`, with `confirmedFailure` reading
|
|
106
|
+
* its on-chain failure.
|
|
107
|
+
* - Every other result - `rpc-unavailable` included - goes to
|
|
108
|
+
* `resolveUnconfirmed`. Only an `expired` verdict passes its slot: the
|
|
109
|
+
* dropped check reads any defined slot as a verdict.
|
|
110
|
+
* - A rejection comes before the first send of this run. On the first run
|
|
111
|
+
* nothing ever left the SDK, so the bytes are cleared and the error is
|
|
112
|
+
* rethrown: "Try again" signs again. On a resume an earlier run may have
|
|
113
|
+
* sent the same bytes: they stay, and only the chain can make the outcome
|
|
114
|
+
* final.
|
|
115
|
+
*/
|
|
116
|
+
async function sendAndSettle(context, action, options) {
|
|
117
|
+
const { signature, messages } = options;
|
|
118
|
+
/** `resolveUnconfirmed` throws for an unknown or dropped outcome, so only
|
|
119
|
+
* a confirmed status reaches `recordLanded`. */
|
|
120
|
+
const settleUnconfirmed = async (error, expiredAtSlot) => {
|
|
121
|
+
const status = await resolveUnconfirmed(context, action, {
|
|
122
|
+
signature,
|
|
123
|
+
error,
|
|
124
|
+
expiredAtSlot,
|
|
125
|
+
messages
|
|
126
|
+
});
|
|
127
|
+
return recordLanded(context, action, {
|
|
128
|
+
signature,
|
|
129
|
+
failure: failureOf(status)
|
|
130
|
+
});
|
|
131
|
+
};
|
|
132
|
+
let result;
|
|
133
|
+
try {
|
|
134
|
+
result = await options.send();
|
|
135
|
+
} catch (error) {
|
|
136
|
+
if (!options.resuming) {
|
|
137
|
+
clearStoredTransactions(context, action);
|
|
138
|
+
throw error;
|
|
139
|
+
}
|
|
140
|
+
return settleUnconfirmed(error, void 0);
|
|
141
|
+
}
|
|
142
|
+
if (result.kind === "confirmed") return recordLanded(context, action, {
|
|
143
|
+
signature,
|
|
144
|
+
failure: options.confirmedFailure(result.value)
|
|
145
|
+
});
|
|
146
|
+
return settleUnconfirmed(require_core_tasks_confirmationError.confirmationError(result, messages), result.kind === "expired" ? result.slot : void 0);
|
|
147
|
+
}
|
|
148
|
+
//#endregion
|
|
149
|
+
exports.canResendStored = canResendStored;
|
|
150
|
+
exports.cannotLandAnymore = cannotLandAnymore;
|
|
151
|
+
exports.clearStoredTransactions = clearStoredTransactions;
|
|
152
|
+
exports.failureOf = failureOf;
|
|
153
|
+
exports.getTxLink = getTxLink;
|
|
154
|
+
exports.recordLanded = recordLanded;
|
|
155
|
+
exports.resolveUnconfirmed = resolveUnconfirmed;
|
|
156
|
+
exports.sendAndSettle = sendAndSettle;
|
|
157
|
+
|
|
158
|
+
//# sourceMappingURL=transactionOutcome.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"transactionOutcome.js","names":["isResendAllowed","isOldEnoughToDrop","SolanaTransactionDetailsError","TransactionError","LiFiErrorCode","lookupSignatureStatus","CLOCK_SKEW_MARGIN_MS","isConfirmedCommitment","isKnownToStatusApi","confirmationError"],"sources":["../../../../src/core/tasks/transactionOutcome.ts"],"sourcesContent":["import {\n CLOCK_SKEW_MARGIN_MS,\n type ExecutionAction,\n isKnownToStatusApi,\n isOldEnoughToDrop,\n isResendAllowed,\n LiFiErrorCode,\n type TaskResult,\n TransactionError,\n} from '@lifi/sdk'\nimport type { Signature } from '@solana/kit'\nimport { lookupSignatureStatus } from '../../actions/lookupSignatureStatus.js'\nimport type { RaceResult } from '../../confirmation/raceRpcs.js'\nimport {\n isConfirmedCommitment,\n type SignatureStatus,\n} from '../../confirmation/types.js'\nimport type { SolanaStepExecutorContext } from '../../types.js'\nimport type { TransactionLifetime } from '../../utils/getTransactionLifetime.js'\nimport { SolanaTransactionDetailsError } from '../../utils/solanaErrorCause.js'\nimport {\n type ConfirmationMessages,\n confirmationError,\n} from './confirmationError.js'\n\n/** Explorer link for a signature, as both wait tasks write it. */\nexport function getTxLink(\n context: Pick<SolanaStepExecutorContext, 'fromChain'>,\n signature: string\n): string {\n return `${context.fromChain.metamask.blockExplorerUrls[0]}tx/${signature}`\n}\n\n/**\n * May stored bytes be sent (again)? A blockhash transaction always: the\n * chain rejects it once the blockhash dies, and the deadline's probe tells\n * when. Anything else - a durable nonce, a lifetime that did not decode -\n * only inside the resend age cap, so a page load hours later cannot execute\n * a swap on an old quote.\n */\nexport function canResendStored(\n lifetimes: TransactionLifetime[],\n signedAt: number | undefined,\n now?: number\n): boolean {\n const expiresOnItsOwn =\n lifetimes.length > 0 &&\n lifetimes.every((lifetime) => lifetime.kind === 'blockhash')\n return expiresOnItsOwn || isResendAllowed(signedAt, now)\n}\n\n/**\n * Condition (a) of the dropped rule in `resolveUnconfirmed`: the chain says\n * the transaction can no longer land.\n *\n * - An `expired` verdict: the blockhash probe saw it dead.\n * - Without a verdict, `isOldEnoughToDrop` for every lifetime. For a\n * blockhash transaction that is the five-minute time fallback. For a\n * durable nonce or an undecodable lifetime it is the age cap passed plus a\n * margin: sends stop at the cap, and the three minutes after it put the\n * lookup's current-slot head safely past any slot the transaction could\n * still land in.\n *\n * An unknown signing time never holds by time.\n */\nexport function cannotLandAnymore(options: {\n expired: boolean\n signedAt: number | undefined\n now?: number\n}): boolean {\n return options.expired || isOldEnoughToDrop(options.signedAt, options.now)\n}\n\n/** Drops the stored bytes: never sent, landed, or final. */\nexport function clearStoredTransactions(\n context: SolanaStepExecutorContext,\n action: ExecutionAction\n): void {\n context.statusManager.updateAction(context.step, action.type, 'PENDING', {\n txHex: undefined,\n })\n}\n\n/** A signature status's `err` as the failure `recordLanded` takes. */\nexport function failureOf(\n status: Pick<SignatureStatus, 'err'>\n): { err: unknown } | undefined {\n return status.err ? { err: status.err } : undefined\n}\n\n/**\n * Result rule for a transaction the chain has: writes `txHash` and `txLink`,\n * clears the stored bytes, then completes - or throws the final\n * `TransactionFailed` for one that failed on chain.\n *\n * The hash is written for a failed transaction too: it exists on chain, and\n * a resume that found it by lookup has no `txHash` yet.\n */\nexport function recordLanded(\n context: SolanaStepExecutorContext,\n action: ExecutionAction,\n options: { signature: Signature; failure: { err: unknown } | undefined }\n): TaskResult {\n const { step, statusManager, isBridgeExecution } = context\n const { signature, failure } = options\n\n statusManager.updateAction(step, action.type, 'PENDING', {\n txHash: signature,\n txLink: getTxLink(context, signature),\n txHex: undefined,\n })\n\n if (failure) {\n const cause = new SolanaTransactionDetailsError(failure.err)\n throw new TransactionError(\n LiFiErrorCode.TransactionFailed,\n `Transaction failed: ${cause.message}`,\n cause,\n { final: true }\n )\n }\n\n if (isBridgeExecution) {\n statusManager.updateAction(step, action.type, 'DONE')\n }\n\n return { status: 'COMPLETED' }\n}\n\n/**\n * Decides what a transaction that did not confirm is: landed after all\n * (returns its status), dropped (throws a final `TransactionExpired`), or\n * unknown (rethrows `error`, the error the task built for today's outcome).\n *\n * Dropped (see the resume rules in `transactionState.ts`) = (a)\n * `cannotLandAnymore`, AND (b) a lookup that proves the absence - a covering\n * RPC whose head is past the landing window answered `null` in the same\n * response, and no RPC has the transaction - AND (c) the status API does not\n * know the hash. The status API only vetoes: it answers 404 for landed\n * transactions it does not index too, so a miss there proves nothing.\n */\nexport async function resolveUnconfirmed(\n context: SolanaStepExecutorContext,\n action: ExecutionAction,\n options: {\n signature: Signature\n /** What the integrator sees when the outcome stays unknown. */\n error: unknown\n /** The slot of the `expired` verdict; `undefined` without one. */\n expiredAtSlot: bigint | undefined\n messages: ConfirmationMessages\n }\n): Promise<SignatureStatus> {\n const { client, step } = context\n const { signature, error, expiredAtSlot } = options\n const signedAt = step.execution?.signedAt\n\n // (a) The local check runs first, so a young transaction costs no request.\n if (!cannotLandAnymore({ expired: expiredAtSlot !== undefined, signedAt })) {\n throw error\n }\n // Without a signing time there is no anchor, so no canary can prove that a\n // node's history covers the transaction.\n if (signedAt === undefined) {\n throw error\n }\n\n // (b) Absence, proven by the same response that proves coverage and head.\n // Every other lookup result - also `unknown` with `answered: false`, an\n // outage - keeps the outcome unknown.\n const lookup = await lookupSignatureStatus(client, signature, {\n anchor: signedAt - CLOCK_SKEW_MARGIN_MS,\n expiredAtSlot,\n })\n if (\n lookup.kind === 'found' &&\n isConfirmedCommitment(lookup.status.confirmationStatus)\n ) {\n return lookup.status\n }\n if (lookup.kind !== 'not-found') {\n throw error\n }\n\n // (c) The veto.\n if (await isKnownToStatusApi(client, step, signature)) {\n throw error\n }\n\n clearStoredTransactions(context, action)\n // Today's expiry code and text: only the marker is new.\n throw new TransactionError(\n LiFiErrorCode.TransactionExpired,\n options.messages.notConfirmed,\n error instanceof Error ? error : undefined,\n { final: true }\n )\n}\n\n/**\n * The send-and-settle tail both wait tasks share: runs `send`, then applies\n * the result rules to what it reports.\n *\n * - A confirmation goes to `recordLanded`, with `confirmedFailure` reading\n * its on-chain failure.\n * - Every other result - `rpc-unavailable` included - goes to\n * `resolveUnconfirmed`. Only an `expired` verdict passes its slot: the\n * dropped check reads any defined slot as a verdict.\n * - A rejection comes before the first send of this run. On the first run\n * nothing ever left the SDK, so the bytes are cleared and the error is\n * rethrown: \"Try again\" signs again. On a resume an earlier run may have\n * sent the same bytes: they stay, and only the chain can make the outcome\n * final.\n */\nexport async function sendAndSettle<T>(\n context: SolanaStepExecutorContext,\n action: ExecutionAction,\n options: {\n signature: Signature\n /** Sends and races the confirmation. Rejects only before its first\n * send; the race itself never rejects. */\n send: () => Promise<RaceResult<T>>\n /** The on-chain failure of a confirmed value. */\n confirmedFailure: (value: T) => { err: unknown } | undefined\n /** An earlier run may already have sent these bytes. */\n resuming: boolean\n messages: ConfirmationMessages\n }\n): Promise<TaskResult> {\n const { signature, messages } = options\n\n /** `resolveUnconfirmed` throws for an unknown or dropped outcome, so only\n * a confirmed status reaches `recordLanded`. */\n const settleUnconfirmed = async (\n error: unknown,\n expiredAtSlot: bigint | undefined\n ): Promise<TaskResult> => {\n const status = await resolveUnconfirmed(context, action, {\n signature,\n error,\n expiredAtSlot,\n messages,\n })\n return recordLanded(context, action, {\n signature,\n failure: failureOf(status),\n })\n }\n\n let result: RaceResult<T>\n try {\n result = await options.send()\n } catch (error) {\n if (!options.resuming) {\n clearStoredTransactions(context, action)\n throw error\n }\n return settleUnconfirmed(error, undefined)\n }\n\n if (result.kind === 'confirmed') {\n return recordLanded(context, action, {\n signature,\n failure: options.confirmedFailure(result.value),\n })\n }\n\n return settleUnconfirmed(\n confirmationError(result, messages),\n // The head a covering RPC has to reach before its `null` counts.\n result.kind === 'expired' ? result.slot : undefined\n )\n}\n"],"mappings":"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"}
|
package/dist/cjs/types.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { SDKProvider, StepExecutorContext, StepExecutorOptions } from "@lifi/sdk";
|
|
1
|
+
import { LiFiStepExtended, SDKProvider, StepExecutorContext, StepExecutorOptions } from "@lifi/sdk";
|
|
2
2
|
import { Transaction } from "@solana/kit";
|
|
3
3
|
import { Wallet, WalletAccount } from "@wallet-standard/base";
|
|
4
4
|
//#region src/types.d.ts
|
|
@@ -7,16 +7,27 @@ export interface SolanaProviderOptions {
|
|
|
7
7
|
skipSimulation?: boolean;
|
|
8
8
|
}
|
|
9
9
|
export interface SolanaTaskContext {
|
|
10
|
+
/**
|
|
11
|
+
* Set by the sign task. Absent on a resume: the wait tasks then read the
|
|
12
|
+
* signed bytes from the action's `txHex`.
|
|
13
|
+
*/
|
|
10
14
|
signedTransactions?: Transaction[];
|
|
11
15
|
/**
|
|
12
16
|
* Whether the backend returned a Jito bundle (array `transactionRequest.data`)
|
|
13
17
|
* that must be submitted via `sendBundle` instead of `sendTransaction`.
|
|
18
|
+
* Absent on a resume: a leading `[` in `txHex` marks a bundle then.
|
|
14
19
|
*/
|
|
15
20
|
isBundleExecution?: boolean;
|
|
16
21
|
}
|
|
17
22
|
export interface SolanaStepExecutorContext extends StepExecutorContext, SolanaTaskContext {
|
|
18
23
|
wallet: Wallet;
|
|
19
|
-
|
|
24
|
+
/**
|
|
25
|
+
* Resolves the account that requested the quote. Only the sign task calls
|
|
26
|
+
* it, so a resume that only waits does not need the wallet to have
|
|
27
|
+
* reconnected. Throws `WalletChangedDuringExecution` when the account is
|
|
28
|
+
* gone.
|
|
29
|
+
*/
|
|
30
|
+
getWalletAccount: (step: LiFiStepExtended) => WalletAccount;
|
|
20
31
|
skipSimulation: boolean;
|
|
21
32
|
}
|
|
22
33
|
export interface SolanaSDKProvider extends SDKProvider {
|
package/dist/cjs/types.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.js","names":["ChainType"],"sources":["../../src/types.ts"],"sourcesContent":["import {\n ChainType,\n type SDKProvider,\n type StepExecutorContext,\n type StepExecutorOptions,\n} from '@lifi/sdk'\nimport type { Transaction } from '@solana/kit'\nimport type { Wallet, WalletAccount } from '@wallet-standard/base'\n\nexport interface SolanaProviderOptions {\n getWallet?: () => Promise<Wallet>\n skipSimulation?: boolean\n}\n\nexport interface SolanaTaskContext {\n signedTransactions?: Transaction[]\n /**\n * Whether the backend returned a Jito bundle (array `transactionRequest.data`)\n * that must be submitted via `sendBundle` instead of `sendTransaction`.\n */\n isBundleExecution?: boolean\n}\n\nexport interface SolanaStepExecutorContext\n extends StepExecutorContext,\n SolanaTaskContext {\n wallet: Wallet\n
|
|
1
|
+
{"version":3,"file":"types.js","names":["ChainType"],"sources":["../../src/types.ts"],"sourcesContent":["import {\n ChainType,\n type LiFiStepExtended,\n type SDKProvider,\n type StepExecutorContext,\n type StepExecutorOptions,\n} from '@lifi/sdk'\nimport type { Transaction } from '@solana/kit'\nimport type { Wallet, WalletAccount } from '@wallet-standard/base'\n\nexport interface SolanaProviderOptions {\n getWallet?: () => Promise<Wallet>\n skipSimulation?: boolean\n}\n\nexport interface SolanaTaskContext {\n /**\n * Set by the sign task. Absent on a resume: the wait tasks then read the\n * signed bytes from the action's `txHex`.\n */\n signedTransactions?: Transaction[]\n /**\n * Whether the backend returned a Jito bundle (array `transactionRequest.data`)\n * that must be submitted via `sendBundle` instead of `sendTransaction`.\n * Absent on a resume: a leading `[` in `txHex` marks a bundle then.\n */\n isBundleExecution?: boolean\n}\n\nexport interface SolanaStepExecutorContext\n extends StepExecutorContext,\n SolanaTaskContext {\n wallet: Wallet\n /**\n * Resolves the account that requested the quote. Only the sign task calls\n * it, so a resume that only waits does not need the wallet to have\n * reconnected. Throws `WalletChangedDuringExecution` when the account is\n * gone.\n */\n getWalletAccount: (step: LiFiStepExtended) => WalletAccount\n skipSimulation: boolean\n}\n\nexport interface SolanaSDKProvider extends SDKProvider {\n setOptions(options: SolanaProviderOptions): void\n}\n\nexport function isSolanaProvider(\n provider: SDKProvider\n): provider is SolanaSDKProvider {\n return provider.type === ChainType.SVM\n}\n\nexport interface SolanaStepExecutorOptions extends StepExecutorOptions {\n wallet: Wallet\n skipSimulation?: boolean\n}\n"],"mappings":";;;AA+CA,SAAgB,iBACd,UAC+B;CAC/B,OAAO,SAAS,SAASA,UAAAA,UAAU;AACrC"}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import { Signature, Transaction } from "@solana/kit";
|
|
2
|
+
//#region src/utils/storedTransactions.d.ts
|
|
3
|
+
/** Signed transactions decoded from `action.txHex`. */
|
|
4
|
+
export type StoredTransactions = {
|
|
5
|
+
transactions: Transaction[];
|
|
6
|
+
/** A Jito bundle: submitted with `sendBundle`, never one by one. */
|
|
7
|
+
isBundle: boolean;
|
|
8
|
+
/** The first transaction's signature: the action's `txHash` once sent. */
|
|
9
|
+
signature: Signature;
|
|
10
|
+
};
|
|
11
|
+
/**
|
|
12
|
+
* Serializes signed wire transactions for `action.txHex`: the base64 wire
|
|
13
|
+
* transaction for a single one, a JSON array of them for a bundle.
|
|
14
|
+
*
|
|
15
|
+
* The array stays for a one-element bundle too: the leading `[` is the only
|
|
16
|
+
* record of `isBundleExecution` a resume gets.
|
|
17
|
+
*
|
|
18
|
+
* Throws for an empty list, which would store a value
|
|
19
|
+
* `decodeStoredTransactions` rejects, and for more than one transaction
|
|
20
|
+
* outside a bundle, of which the base64 would keep only the first.
|
|
21
|
+
*/
|
|
22
|
+
export declare function encodeStoredTransactions(wireTransactions: readonly Uint8Array[], isBundle: boolean): string;
|
|
23
|
+
/** A leading `[` marks a bundle; base64 never starts with one. */
|
|
24
|
+
export declare function isStoredBundle(txHex: string): boolean;
|
|
25
|
+
/**
|
|
26
|
+
* Decodes `action.txHex` back into signed transactions.
|
|
27
|
+
*
|
|
28
|
+
* Returns `undefined` for anything a resume cannot send: a value that is not
|
|
29
|
+
* base64 or JSON, an empty bundle, bytes that do not decode, or a
|
|
30
|
+
* transaction without its fee payer signature. The sign task stores only
|
|
31
|
+
* values that pass these checks, so `undefined` means the stored value was
|
|
32
|
+
* damaged after it was written.
|
|
33
|
+
*/
|
|
34
|
+
export declare function decodeStoredTransactions(txHex: string): StoredTransactions | undefined;
|
|
35
|
+
//#endregion
|
|
36
|
+
//# sourceMappingURL=storedTransactions.d.ts.map
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
|
+
const require_utils_base64ToUint8Array = require("./base64ToUint8Array.js");
|
|
3
|
+
let _solana_kit = require("@solana/kit");
|
|
4
|
+
//#region src/utils/storedTransactions.ts
|
|
5
|
+
/**
|
|
6
|
+
* Serializes signed wire transactions for `action.txHex`: the base64 wire
|
|
7
|
+
* transaction for a single one, a JSON array of them for a bundle.
|
|
8
|
+
*
|
|
9
|
+
* The array stays for a one-element bundle too: the leading `[` is the only
|
|
10
|
+
* record of `isBundleExecution` a resume gets.
|
|
11
|
+
*
|
|
12
|
+
* Throws for an empty list, which would store a value
|
|
13
|
+
* `decodeStoredTransactions` rejects, and for more than one transaction
|
|
14
|
+
* outside a bundle, of which the base64 would keep only the first.
|
|
15
|
+
*/
|
|
16
|
+
function encodeStoredTransactions(wireTransactions, isBundle) {
|
|
17
|
+
if (wireTransactions.length === 0) throw new Error("No signed transactions to store.");
|
|
18
|
+
if (!isBundle && wireTransactions.length !== 1) throw new Error(`Expected one signed transaction outside a bundle, got ${wireTransactions.length}.`);
|
|
19
|
+
const base64 = (0, _solana_kit.getBase64Decoder)();
|
|
20
|
+
const encoded = wireTransactions.map((bytes) => base64.decode(bytes));
|
|
21
|
+
return isBundle ? JSON.stringify(encoded) : encoded[0];
|
|
22
|
+
}
|
|
23
|
+
/** A leading `[` marks a bundle; base64 never starts with one. */
|
|
24
|
+
function isStoredBundle(txHex) {
|
|
25
|
+
return txHex.startsWith("[");
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* Decodes `action.txHex` back into signed transactions.
|
|
29
|
+
*
|
|
30
|
+
* Returns `undefined` for anything a resume cannot send: a value that is not
|
|
31
|
+
* base64 or JSON, an empty bundle, bytes that do not decode, or a
|
|
32
|
+
* transaction without its fee payer signature. The sign task stores only
|
|
33
|
+
* values that pass these checks, so `undefined` means the stored value was
|
|
34
|
+
* damaged after it was written.
|
|
35
|
+
*/
|
|
36
|
+
function decodeStoredTransactions(txHex) {
|
|
37
|
+
try {
|
|
38
|
+
const isBundle = isStoredBundle(txHex);
|
|
39
|
+
const encoded = isBundle ? JSON.parse(txHex) : [txHex];
|
|
40
|
+
if (!Array.isArray(encoded) || encoded.length === 0 || !encoded.every((entry) => typeof entry === "string")) return;
|
|
41
|
+
const codec = (0, _solana_kit.getTransactionCodec)();
|
|
42
|
+
const transactions = encoded.map((entry) => codec.decode(require_utils_base64ToUint8Array.base64ToUint8Array(entry)));
|
|
43
|
+
return {
|
|
44
|
+
transactions,
|
|
45
|
+
isBundle,
|
|
46
|
+
signature: transactions.map((transaction) => (0, _solana_kit.getSignatureFromTransaction)(transaction))[0]
|
|
47
|
+
};
|
|
48
|
+
} catch (_) {
|
|
49
|
+
return;
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
//#endregion
|
|
53
|
+
exports.decodeStoredTransactions = decodeStoredTransactions;
|
|
54
|
+
exports.encodeStoredTransactions = encodeStoredTransactions;
|
|
55
|
+
exports.isStoredBundle = isStoredBundle;
|
|
56
|
+
|
|
57
|
+
//# sourceMappingURL=storedTransactions.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"storedTransactions.js","names":["getBase64Decoder","getTransactionCodec","base64ToUint8Array","getSignatureFromTransaction"],"sources":["../../../src/utils/storedTransactions.ts"],"sourcesContent":["import {\n getBase64Decoder,\n getSignatureFromTransaction,\n getTransactionCodec,\n type Signature,\n type Transaction,\n} from '@solana/kit'\nimport { base64ToUint8Array } from './base64ToUint8Array.js'\n\n/** Signed transactions decoded from `action.txHex`. */\nexport type StoredTransactions = {\n transactions: Transaction[]\n /** A Jito bundle: submitted with `sendBundle`, never one by one. */\n isBundle: boolean\n /** The first transaction's signature: the action's `txHash` once sent. */\n signature: Signature\n}\n\n/**\n * Serializes signed wire transactions for `action.txHex`: the base64 wire\n * transaction for a single one, a JSON array of them for a bundle.\n *\n * The array stays for a one-element bundle too: the leading `[` is the only\n * record of `isBundleExecution` a resume gets.\n *\n * Throws for an empty list, which would store a value\n * `decodeStoredTransactions` rejects, and for more than one transaction\n * outside a bundle, of which the base64 would keep only the first.\n */\nexport function encodeStoredTransactions(\n wireTransactions: readonly Uint8Array[],\n isBundle: boolean\n): string {\n if (wireTransactions.length === 0) {\n throw new Error('No signed transactions to store.')\n }\n if (!isBundle && wireTransactions.length !== 1) {\n throw new Error(\n `Expected one signed transaction outside a bundle, got ${wireTransactions.length}.`\n )\n }\n const base64 = getBase64Decoder()\n const encoded = wireTransactions.map((bytes) => base64.decode(bytes))\n return isBundle ? JSON.stringify(encoded) : encoded[0]\n}\n\n/** A leading `[` marks a bundle; base64 never starts with one. */\nexport function isStoredBundle(txHex: string): boolean {\n return txHex.startsWith('[')\n}\n\n/**\n * Decodes `action.txHex` back into signed transactions.\n *\n * Returns `undefined` for anything a resume cannot send: a value that is not\n * base64 or JSON, an empty bundle, bytes that do not decode, or a\n * transaction without its fee payer signature. The sign task stores only\n * values that pass these checks, so `undefined` means the stored value was\n * damaged after it was written.\n */\nexport function decodeStoredTransactions(\n txHex: string\n): StoredTransactions | undefined {\n try {\n const isBundle = isStoredBundle(txHex)\n const encoded: unknown = isBundle ? JSON.parse(txHex) : [txHex]\n if (\n !Array.isArray(encoded) ||\n encoded.length === 0 ||\n !encoded.every((entry) => typeof entry === 'string')\n ) {\n return undefined\n }\n const codec = getTransactionCodec()\n const transactions = encoded.map((entry: string) =>\n codec.decode(base64ToUint8Array(entry))\n )\n // Every entry must carry its fee payer signature, as the sign task\n // checked before it stored them. `getSignatureFromTransaction` throws\n // when one does not.\n const signatures = transactions.map((transaction) =>\n getSignatureFromTransaction(transaction)\n )\n return { transactions, isBundle, signature: signatures[0] }\n } catch (_) {\n return undefined\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;AA6BA,SAAgB,yBACd,kBACA,UACQ;CACR,IAAI,iBAAiB,WAAW,GAC9B,MAAM,IAAI,MAAM,kCAAkC;CAEpD,IAAI,CAAC,YAAY,iBAAiB,WAAW,GAC3C,MAAM,IAAI,MACR,yDAAyD,iBAAiB,OAAO,EACnF;CAEF,MAAM,UAAA,GAASA,YAAAA,iBAAAA,CAAiB;CAChC,MAAM,UAAU,iBAAiB,KAAK,UAAU,OAAO,OAAO,KAAK,CAAC;CACpE,OAAO,WAAW,KAAK,UAAU,OAAO,IAAI,QAAQ;AACtD;;AAGA,SAAgB,eAAe,OAAwB;CACrD,OAAO,MAAM,WAAW,GAAG;AAC7B;;;;;;;;;;AAWA,SAAgB,yBACd,OACgC;CAChC,IAAI;EACF,MAAM,WAAW,eAAe,KAAK;EACrC,MAAM,UAAmB,WAAW,KAAK,MAAM,KAAK,IAAI,CAAC,KAAK;EAC9D,IACE,CAAC,MAAM,QAAQ,OAAO,KACtB,QAAQ,WAAW,KACnB,CAAC,QAAQ,OAAO,UAAU,OAAO,UAAU,QAAQ,GAEnD;EAEF,MAAM,SAAA,GAAQC,YAAAA,oBAAAA,CAAoB;EAClC,MAAM,eAAe,QAAQ,KAAK,UAChC,MAAM,OAAOC,iCAAAA,mBAAmB,KAAK,CAAC,CACxC;EAOA,OAAO;GAAE;GAAc;GAAU,WAHd,aAAa,KAAK,iBAAA,GACnCC,YAAAA,4BAAAA,CAA4B,WAAW,CAEY,CAAC,CAAC;EAAG;CAC5D,SAAS,GAAG;EACV;CACF;AACF"}
|
package/dist/cjs/version.d.ts
CHANGED
package/dist/cjs/version.js
CHANGED
package/dist/cjs/version.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"version.js","names":[],"sources":["../../src/version.ts"],"sourcesContent":["export const name = '@lifi/sdk-provider-solana'\nexport const version = '4.3.
|
|
1
|
+
{"version":3,"file":"version.js","names":[],"sources":["../../src/version.ts"],"sourcesContent":["export const name = '@lifi/sdk-provider-solana'\nexport const version = '4.3.4'\n"],"mappings":";;AAAA,MAAa,OAAO;AACpB,MAAa,UAAU"}
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
import { SignatureStatus } from "../confirmation/types.js";
|
|
2
|
+
import { SDKClient } from "@lifi/sdk";
|
|
3
|
+
import { Signature } from "@solana/kit";
|
|
4
|
+
//#region src/actions/lookupSignatureStatus.d.ts
|
|
5
|
+
/** Budget of each `getSignatureStatuses` call, the status request. A hung
|
|
6
|
+
* endpoint would otherwise hold the `allSettled` below - and the wait task
|
|
7
|
+
* with it - open for good. */
|
|
8
|
+
export declare const SIGNATURE_LOOKUP_TIMEOUT_MS = 15e3;
|
|
9
|
+
/** Budget of each `getSlot` and `getBlock` call of the proof search. An RPC
|
|
10
|
+
* that has not answered by then counts as silent, as a rejection does, and
|
|
11
|
+
* is left out of the rest of the search: a single hung RPC must not block a
|
|
12
|
+
* verdict when other RPCs answer. */
|
|
13
|
+
export declare const CANARY_CALL_TIMEOUT_MS = 3e3;
|
|
14
|
+
/** Budget of the whole proof search. Past it the lookup asks for the target
|
|
15
|
+
* alone: it can still find the transaction, but it cannot prove absence. */
|
|
16
|
+
export declare const COVERAGE_PROOF_TIMEOUT_MS = 1e4;
|
|
17
|
+
/** Target slot time. Real slots are rarely faster, so `ceil(age / 400)`
|
|
18
|
+
* slots back reach at or before the anchor; the anchor's clock-skew margin
|
|
19
|
+
* absorbs the rest. */
|
|
20
|
+
export declare const SLOT_DURATION_MS = 400;
|
|
21
|
+
/** How far each canary search steps over skipped or empty slots. */
|
|
22
|
+
export declare const CANARY_SLOT_STEPS = 32;
|
|
23
|
+
export type LookupBounds = {
|
|
24
|
+
/** The earliest time the transaction can have landed, in ms since the
|
|
25
|
+
* epoch: `execution.signedAt - CLOCK_SKEW_MARGIN_MS`. */
|
|
26
|
+
anchor: number;
|
|
27
|
+
/** The slot of the expiry verdict (the `expired` result): the highest
|
|
28
|
+
* slot of the expiry streak. A node's head at or past it (`>=`) has seen
|
|
29
|
+
* every slot the transaction could land in. Without a verdict the freshest
|
|
30
|
+
* current slot of the RPCs is the head. */
|
|
31
|
+
expiredAtSlot?: bigint;
|
|
32
|
+
/** Injectable clock for the canary bound. */
|
|
33
|
+
now?: number;
|
|
34
|
+
};
|
|
35
|
+
export type SignatureLookup = {
|
|
36
|
+
kind: "found";
|
|
37
|
+
status: SignatureStatus;
|
|
38
|
+
} | {
|
|
39
|
+
kind: "not-found";
|
|
40
|
+
} | {
|
|
41
|
+
kind: "unknown";
|
|
42
|
+
answered: boolean;
|
|
43
|
+
errors: Error[];
|
|
44
|
+
};
|
|
45
|
+
/**
|
|
46
|
+
* Looks a signature up on every Solana RPC, the transaction history
|
|
47
|
+
* included.
|
|
48
|
+
*
|
|
49
|
+
* Not `raceRpcs`: a race returns the first answer, and one pruned or lagging
|
|
50
|
+
* node answering `null` would then read as "the transaction does not exist".
|
|
51
|
+
* A node's `null` proves nothing on its own either: a default RPC forgets
|
|
52
|
+
* signatures after about two days, a node on a minority fork has not seen
|
|
53
|
+
* the majority's blocks, and a pool may route each request to another
|
|
54
|
+
* backend. So with `bounds` the same request also asks for two canaries:
|
|
55
|
+
* one that landed before the transaction could, and one from a confirmed
|
|
56
|
+
* block at or after the expiry. The `null` counts only when that response
|
|
57
|
+
* knows both canaries and its head is at or past the last slot the
|
|
58
|
+
* transaction could land in.
|
|
59
|
+
*
|
|
60
|
+
* Takes at most `COVERAGE_PROOF_TIMEOUT_MS + CANARY_CALL_TIMEOUT_MS` for
|
|
61
|
+
* the proof search and `SIGNATURE_LOOKUP_TIMEOUT_MS` for the status
|
|
62
|
+
* request. Never throws.
|
|
63
|
+
*/
|
|
64
|
+
export declare function lookupSignatureStatus(client: SDKClient, signature: Signature, bounds?: LookupBounds): Promise<SignatureLookup>;
|
|
65
|
+
//#endregion
|
|
66
|
+
//# sourceMappingURL=lookupSignatureStatus.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"lookupSignatureStatus.d.ts","names":[],"sources":["../../../src/actions/lookupSignatureStatus.ts"],"mappings":";;;;;;;qBAYa;;;;;qBAKA;;;qBAGA;;;;qBAIA;;qBAEA;YAED;;;EAGV;;;;;EAKA;;EAEA;;YAGU;EAGN;EAAe,QAAQ;;EAIvB;;EAGA;EAAiB;EAAmB,QAAQ;;;;;;;;;;;;;;;;;;;;;wBAgH5B,sBACpB,QAAQ,WACR,WAAW,WACX,SAAS,eACR,QAAQ"}
|