@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
package/dist/esm/types.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.js","names":[],"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":[],"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,SAAS,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 @@
|
|
|
1
|
+
{"version":3,"file":"storedTransactions.d.ts","names":[],"sources":["../../../src/utils/storedTransactions.ts"],"mappings":";;;YAUY;EACV,cAAc;;EAEd;;EAEA,WAAW;;;;;;;;;;;;;wBAcG,yBACd,2BAA2B,cAC3B;;wBAgBc,eAAe;;;;;;;;;;wBAaf,yBACd,gBACC"}
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
import { base64ToUint8Array } from "./base64ToUint8Array.js";
|
|
2
|
+
import { getBase64Decoder, getSignatureFromTransaction, getTransactionCodec } from "@solana/kit";
|
|
3
|
+
//#region src/utils/storedTransactions.ts
|
|
4
|
+
/**
|
|
5
|
+
* Serializes signed wire transactions for `action.txHex`: the base64 wire
|
|
6
|
+
* transaction for a single one, a JSON array of them for a bundle.
|
|
7
|
+
*
|
|
8
|
+
* The array stays for a one-element bundle too: the leading `[` is the only
|
|
9
|
+
* record of `isBundleExecution` a resume gets.
|
|
10
|
+
*
|
|
11
|
+
* Throws for an empty list, which would store a value
|
|
12
|
+
* `decodeStoredTransactions` rejects, and for more than one transaction
|
|
13
|
+
* outside a bundle, of which the base64 would keep only the first.
|
|
14
|
+
*/
|
|
15
|
+
function encodeStoredTransactions(wireTransactions, isBundle) {
|
|
16
|
+
if (wireTransactions.length === 0) throw new Error("No signed transactions to store.");
|
|
17
|
+
if (!isBundle && wireTransactions.length !== 1) throw new Error(`Expected one signed transaction outside a bundle, got ${wireTransactions.length}.`);
|
|
18
|
+
const base64 = getBase64Decoder();
|
|
19
|
+
const encoded = wireTransactions.map((bytes) => base64.decode(bytes));
|
|
20
|
+
return isBundle ? JSON.stringify(encoded) : encoded[0];
|
|
21
|
+
}
|
|
22
|
+
/** A leading `[` marks a bundle; base64 never starts with one. */
|
|
23
|
+
function isStoredBundle(txHex) {
|
|
24
|
+
return txHex.startsWith("[");
|
|
25
|
+
}
|
|
26
|
+
/**
|
|
27
|
+
* Decodes `action.txHex` back into signed transactions.
|
|
28
|
+
*
|
|
29
|
+
* Returns `undefined` for anything a resume cannot send: a value that is not
|
|
30
|
+
* base64 or JSON, an empty bundle, bytes that do not decode, or a
|
|
31
|
+
* transaction without its fee payer signature. The sign task stores only
|
|
32
|
+
* values that pass these checks, so `undefined` means the stored value was
|
|
33
|
+
* damaged after it was written.
|
|
34
|
+
*/
|
|
35
|
+
function decodeStoredTransactions(txHex) {
|
|
36
|
+
try {
|
|
37
|
+
const isBundle = isStoredBundle(txHex);
|
|
38
|
+
const encoded = isBundle ? JSON.parse(txHex) : [txHex];
|
|
39
|
+
if (!Array.isArray(encoded) || encoded.length === 0 || !encoded.every((entry) => typeof entry === "string")) return;
|
|
40
|
+
const codec = getTransactionCodec();
|
|
41
|
+
const transactions = encoded.map((entry) => codec.decode(base64ToUint8Array(entry)));
|
|
42
|
+
return {
|
|
43
|
+
transactions,
|
|
44
|
+
isBundle,
|
|
45
|
+
signature: transactions.map((transaction) => getSignatureFromTransaction(transaction))[0]
|
|
46
|
+
};
|
|
47
|
+
} catch (_) {
|
|
48
|
+
return;
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
//#endregion
|
|
52
|
+
export { decodeStoredTransactions, encodeStoredTransactions, isStoredBundle };
|
|
53
|
+
|
|
54
|
+
//# sourceMappingURL=storedTransactions.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"storedTransactions.js","names":[],"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,SAAS,iBAAiB;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,QAAQ,oBAAoB;EAClC,MAAM,eAAe,QAAQ,KAAK,UAChC,MAAM,OAAO,mBAAmB,KAAK,CAAC,CACxC;EAOA,OAAO;GAAE;GAAc;GAAU,WAHd,aAAa,KAAK,gBACnC,4BAA4B,WAAW,CAEY,CAAC,CAAC;EAAG;CAC5D,SAAS,GAAG;EACV;CACF;AACF"}
|
package/dist/esm/version.d.ts
CHANGED
package/dist/esm/version.js
CHANGED
package/dist/esm/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"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@lifi/sdk-provider-solana",
|
|
3
|
-
"version": "4.3.
|
|
3
|
+
"version": "4.3.4",
|
|
4
4
|
"description": "LI.FI Solana SDK Provider for Any-to-Any Cross-Chain-Swap",
|
|
5
5
|
"homepage": "https://github.com/lifinance/sdk",
|
|
6
6
|
"bugs": {
|
|
@@ -28,7 +28,7 @@
|
|
|
28
28
|
"./package.json": "./package.json"
|
|
29
29
|
},
|
|
30
30
|
"dependencies": {
|
|
31
|
-
"@lifi/sdk": "4.
|
|
31
|
+
"@lifi/sdk": "4.11.0",
|
|
32
32
|
"@solana/kit": "^8.4.0",
|
|
33
33
|
"@solana/wallet-standard-features": "^1.5.0",
|
|
34
34
|
"@wallet-standard/base": "^1.1.1"
|
|
@@ -0,0 +1,444 @@
|
|
|
1
|
+
import type { SDKClient } from '@lifi/sdk'
|
|
2
|
+
import { isSignature, type Signature } from '@solana/kit'
|
|
3
|
+
import {
|
|
4
|
+
isConfirmedCommitment,
|
|
5
|
+
type SignatureStatus,
|
|
6
|
+
} from '../confirmation/types.js'
|
|
7
|
+
import { getSolanaRpcs } from '../rpc/registry.js'
|
|
8
|
+
import type { SolanaRpcType } from '../rpc/types.js'
|
|
9
|
+
|
|
10
|
+
/** Budget of each `getSignatureStatuses` call, the status request. A hung
|
|
11
|
+
* endpoint would otherwise hold the `allSettled` below - and the wait task
|
|
12
|
+
* with it - open for good. */
|
|
13
|
+
export const SIGNATURE_LOOKUP_TIMEOUT_MS = 15_000
|
|
14
|
+
/** Budget of each `getSlot` and `getBlock` call of the proof search. An RPC
|
|
15
|
+
* that has not answered by then counts as silent, as a rejection does, and
|
|
16
|
+
* is left out of the rest of the search: a single hung RPC must not block a
|
|
17
|
+
* verdict when other RPCs answer. */
|
|
18
|
+
export const CANARY_CALL_TIMEOUT_MS = 3_000
|
|
19
|
+
/** Budget of the whole proof search. Past it the lookup asks for the target
|
|
20
|
+
* alone: it can still find the transaction, but it cannot prove absence. */
|
|
21
|
+
export const COVERAGE_PROOF_TIMEOUT_MS = 10_000
|
|
22
|
+
/** Target slot time. Real slots are rarely faster, so `ceil(age / 400)`
|
|
23
|
+
* slots back reach at or before the anchor; the anchor's clock-skew margin
|
|
24
|
+
* absorbs the rest. */
|
|
25
|
+
export const SLOT_DURATION_MS = 400
|
|
26
|
+
/** How far each canary search steps over skipped or empty slots. */
|
|
27
|
+
export const CANARY_SLOT_STEPS = 32
|
|
28
|
+
|
|
29
|
+
export type LookupBounds = {
|
|
30
|
+
/** The earliest time the transaction can have landed, in ms since the
|
|
31
|
+
* epoch: `execution.signedAt - CLOCK_SKEW_MARGIN_MS`. */
|
|
32
|
+
anchor: number
|
|
33
|
+
/** The slot of the expiry verdict (the `expired` result): the highest
|
|
34
|
+
* slot of the expiry streak. A node's head at or past it (`>=`) has seen
|
|
35
|
+
* every slot the transaction could land in. Without a verdict the freshest
|
|
36
|
+
* current slot of the RPCs is the head. */
|
|
37
|
+
expiredAtSlot?: bigint
|
|
38
|
+
/** Injectable clock for the canary bound. */
|
|
39
|
+
now?: number
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
export type SignatureLookup =
|
|
43
|
+
/** An RPC returned a status, of any commitment: the caller decides what
|
|
44
|
+
* counts as landed. */
|
|
45
|
+
| { kind: 'found'; status: SignatureStatus }
|
|
46
|
+
/** An RPC answered `null` in a response that also proves it covers the
|
|
47
|
+
* signing time and has seen every slot the transaction could land in, and
|
|
48
|
+
* no RPC returned a status. */
|
|
49
|
+
| { kind: 'not-found' }
|
|
50
|
+
/** Nothing proves either way. `answered` separates silent RPCs - an
|
|
51
|
+
* outage - from RPCs that gave a usable answer without proof. */
|
|
52
|
+
| { kind: 'unknown'; answered: boolean; errors: Error[] }
|
|
53
|
+
|
|
54
|
+
/** What makes one RPC's `null` count as absence. */
|
|
55
|
+
type CoverageProof = {
|
|
56
|
+
/** A landed signature from before the anchor: the node's history reaches
|
|
57
|
+
* back to the signing time. */
|
|
58
|
+
historyCanary: Canary
|
|
59
|
+
/** A signature from a confirmed block at or after the expiry slot (or,
|
|
60
|
+
* without a verdict, a recent one): the node is on the majority fork. */
|
|
61
|
+
headCanary: Canary
|
|
62
|
+
/** The slot the answering node's head has to reach. */
|
|
63
|
+
headSlot: bigint
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
/** A canary signature and the slot of the block that supplied it. */
|
|
67
|
+
type Canary = { signature: Signature; slot: bigint }
|
|
68
|
+
|
|
69
|
+
/** The history canary block. Old enough to be finalized everywhere. */
|
|
70
|
+
const HISTORY_BLOCK_CONFIG = {
|
|
71
|
+
transactionDetails: 'signatures',
|
|
72
|
+
rewards: false,
|
|
73
|
+
maxSupportedTransactionVersion: 0,
|
|
74
|
+
} as const
|
|
75
|
+
/** The head canary block: only a block the majority confirmed. */
|
|
76
|
+
const HEAD_BLOCK_CONFIG = {
|
|
77
|
+
commitment: 'confirmed',
|
|
78
|
+
...HISTORY_BLOCK_CONFIG,
|
|
79
|
+
} as const
|
|
80
|
+
|
|
81
|
+
/** Never throws: `String()` throws on an object without a prototype, and a
|
|
82
|
+
* proxy can throw on `instanceof`. */
|
|
83
|
+
const toError = (reason: unknown): Error => {
|
|
84
|
+
try {
|
|
85
|
+
return reason instanceof Error ? reason : new Error(String(reason))
|
|
86
|
+
} catch {
|
|
87
|
+
return new Error('An RPC call failed with a reason that cannot be read.')
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
/** Only an object is a status. Unvalidated wire data, so `true` or a
|
|
92
|
+
* string is no answer. */
|
|
93
|
+
const isStatus = (entry: unknown): entry is SignatureStatus =>
|
|
94
|
+
typeof entry === 'object' && entry !== null
|
|
95
|
+
|
|
96
|
+
/** A canary status counts only with the slot of the block that supplied the
|
|
97
|
+
* canary. A node on a minority fork can hold the head canary transaction if
|
|
98
|
+
* the same transaction also landed on its fork; its status then has another
|
|
99
|
+
* slot. This also rejects `{}`, arrays and a status without a bigint slot. */
|
|
100
|
+
const isCanaryStatus = (entry: unknown, canary: Canary): boolean =>
|
|
101
|
+
isStatus(entry) &&
|
|
102
|
+
typeof entry.slot === 'bigint' &&
|
|
103
|
+
entry.slot === canary.slot
|
|
104
|
+
|
|
105
|
+
/** `isSignature` throws on a 64-88 character string that is not base58.
|
|
106
|
+
* Here a throw means "not a signature". */
|
|
107
|
+
const isSignatureEntry = (entry: unknown): entry is Signature => {
|
|
108
|
+
if (typeof entry !== 'string') {
|
|
109
|
+
return false
|
|
110
|
+
}
|
|
111
|
+
try {
|
|
112
|
+
return isSignature(entry)
|
|
113
|
+
} catch {
|
|
114
|
+
return false
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
class CallTimeoutError extends Error {}
|
|
119
|
+
|
|
120
|
+
/**
|
|
121
|
+
* Runs `call` with its own abort signal and a budget of `timeoutMs`. Past
|
|
122
|
+
* the budget it rejects with a `CallTimeoutError` and aborts the call. The
|
|
123
|
+
* race does not rely on the transport to honour the abort. A synchronous
|
|
124
|
+
* throw of `call` becomes a rejection too.
|
|
125
|
+
*/
|
|
126
|
+
function callWithin<T>(
|
|
127
|
+
call: (abortSignal: AbortSignal) => Promise<T>,
|
|
128
|
+
timeoutMs: number
|
|
129
|
+
): Promise<T> {
|
|
130
|
+
const controller = new AbortController()
|
|
131
|
+
let timer: ReturnType<typeof setTimeout> | undefined
|
|
132
|
+
const timeout = new Promise<never>((_resolve, reject) => {
|
|
133
|
+
timer = setTimeout(() => {
|
|
134
|
+
const error = new CallTimeoutError(
|
|
135
|
+
`This RPC did not answer within ${timeoutMs}ms.`
|
|
136
|
+
)
|
|
137
|
+
controller.abort(error)
|
|
138
|
+
reject(error)
|
|
139
|
+
}, timeoutMs)
|
|
140
|
+
})
|
|
141
|
+
const answer = new Promise<T>((resolve) => resolve(call(controller.signal)))
|
|
142
|
+
return Promise.race([answer, timeout]).finally(() => clearTimeout(timer))
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
/**
|
|
146
|
+
* Looks a signature up on every Solana RPC, the transaction history
|
|
147
|
+
* included.
|
|
148
|
+
*
|
|
149
|
+
* Not `raceRpcs`: a race returns the first answer, and one pruned or lagging
|
|
150
|
+
* node answering `null` would then read as "the transaction does not exist".
|
|
151
|
+
* A node's `null` proves nothing on its own either: a default RPC forgets
|
|
152
|
+
* signatures after about two days, a node on a minority fork has not seen
|
|
153
|
+
* the majority's blocks, and a pool may route each request to another
|
|
154
|
+
* backend. So with `bounds` the same request also asks for two canaries:
|
|
155
|
+
* one that landed before the transaction could, and one from a confirmed
|
|
156
|
+
* block at or after the expiry. The `null` counts only when that response
|
|
157
|
+
* knows both canaries and its head is at or past the last slot the
|
|
158
|
+
* transaction could land in.
|
|
159
|
+
*
|
|
160
|
+
* Takes at most `COVERAGE_PROOF_TIMEOUT_MS + CANARY_CALL_TIMEOUT_MS` for
|
|
161
|
+
* the proof search and `SIGNATURE_LOOKUP_TIMEOUT_MS` for the status
|
|
162
|
+
* request. Never throws.
|
|
163
|
+
*/
|
|
164
|
+
export async function lookupSignatureStatus(
|
|
165
|
+
client: SDKClient,
|
|
166
|
+
signature: Signature,
|
|
167
|
+
bounds?: LookupBounds
|
|
168
|
+
): Promise<SignatureLookup> {
|
|
169
|
+
try {
|
|
170
|
+
const rpcs = await getSolanaRpcs(client)
|
|
171
|
+
const proof = bounds ? await findCoverageProof(rpcs, bounds) : undefined
|
|
172
|
+
const signatures = proof
|
|
173
|
+
? [signature, proof.historyCanary.signature, proof.headCanary.signature]
|
|
174
|
+
: [signature]
|
|
175
|
+
// Every RPC, also one that timed out in the proof search: it may still
|
|
176
|
+
// return the target.
|
|
177
|
+
const reads = await Promise.allSettled(
|
|
178
|
+
rpcs.map((rpc) =>
|
|
179
|
+
callWithin(
|
|
180
|
+
(abortSignal) =>
|
|
181
|
+
rpc
|
|
182
|
+
.getSignatureStatuses(signatures, {
|
|
183
|
+
searchTransactionHistory: true,
|
|
184
|
+
})
|
|
185
|
+
.send({ abortSignal }),
|
|
186
|
+
SIGNATURE_LOOKUP_TIMEOUT_MS
|
|
187
|
+
)
|
|
188
|
+
)
|
|
189
|
+
)
|
|
190
|
+
return classifyReads(reads, proof)
|
|
191
|
+
} catch (error) {
|
|
192
|
+
// An unexpected fault proves nothing either way.
|
|
193
|
+
return { kind: 'unknown', answered: false, errors: [toError(error)] }
|
|
194
|
+
}
|
|
195
|
+
}
|
|
196
|
+
|
|
197
|
+
function classifyReads(
|
|
198
|
+
reads: PromiseSettledResult<{
|
|
199
|
+
context?: { slot?: unknown }
|
|
200
|
+
value?: unknown
|
|
201
|
+
}>[],
|
|
202
|
+
proof: CoverageProof | undefined
|
|
203
|
+
): SignatureLookup {
|
|
204
|
+
let found: SignatureStatus | undefined
|
|
205
|
+
let provenAbsent = false
|
|
206
|
+
let answered = false
|
|
207
|
+
const errors: Error[] = []
|
|
208
|
+
|
|
209
|
+
for (const read of reads) {
|
|
210
|
+
if (read.status === 'rejected') {
|
|
211
|
+
errors.push(toError(read.reason))
|
|
212
|
+
continue
|
|
213
|
+
}
|
|
214
|
+
// Unvalidated wire data: only entries of a `value` array are answers.
|
|
215
|
+
// `{ value: null }` responded but said nothing about the signature.
|
|
216
|
+
const statuses = read.value?.value
|
|
217
|
+
if (!Array.isArray(statuses) || statuses.length === 0) {
|
|
218
|
+
errors.push(
|
|
219
|
+
new Error('The signature status response carried no statuses.')
|
|
220
|
+
)
|
|
221
|
+
continue
|
|
222
|
+
}
|
|
223
|
+
const [target, historyCanary, headCanary]: unknown[] = statuses
|
|
224
|
+
|
|
225
|
+
if (isStatus(target)) {
|
|
226
|
+
answered = true
|
|
227
|
+
// A lagging RPC may still report `processed` for a confirmed one.
|
|
228
|
+
if (
|
|
229
|
+
!found ||
|
|
230
|
+
(!isConfirmedCommitment(found.confirmationStatus) &&
|
|
231
|
+
isConfirmedCommitment(target.confirmationStatus))
|
|
232
|
+
) {
|
|
233
|
+
found = target
|
|
234
|
+
}
|
|
235
|
+
continue
|
|
236
|
+
}
|
|
237
|
+
if (target !== null) {
|
|
238
|
+
errors.push(new Error('The signature status response was unusable.'))
|
|
239
|
+
continue
|
|
240
|
+
}
|
|
241
|
+
answered = true
|
|
242
|
+
|
|
243
|
+
// A `null` for the target. It proves absence only together with the
|
|
244
|
+
// coverage and head proof from this very response.
|
|
245
|
+
const headSlot = read.value?.context?.slot
|
|
246
|
+
if (!proof) {
|
|
247
|
+
errors.push(
|
|
248
|
+
new Error(
|
|
249
|
+
'This null carries no coverage proof: no canary was asked for.'
|
|
250
|
+
)
|
|
251
|
+
)
|
|
252
|
+
} else if (!isCanaryStatus(historyCanary, proof.historyCanary)) {
|
|
253
|
+
errors.push(
|
|
254
|
+
new Error(
|
|
255
|
+
'This RPC does not cover the signing time: it has no status for the history canary at the slot of its block.'
|
|
256
|
+
)
|
|
257
|
+
)
|
|
258
|
+
} else if (!isCanaryStatus(headCanary, proof.headCanary)) {
|
|
259
|
+
errors.push(
|
|
260
|
+
new Error(
|
|
261
|
+
'This RPC does not know the confirmed block at the head: it has no status for the head canary at the slot of its block.'
|
|
262
|
+
)
|
|
263
|
+
)
|
|
264
|
+
} else if (typeof headSlot !== 'bigint' || headSlot < proof.headSlot) {
|
|
265
|
+
errors.push(
|
|
266
|
+
new Error(
|
|
267
|
+
'This RPC has not reached the last slot the transaction could land in.'
|
|
268
|
+
)
|
|
269
|
+
)
|
|
270
|
+
} else {
|
|
271
|
+
provenAbsent = true
|
|
272
|
+
}
|
|
273
|
+
}
|
|
274
|
+
|
|
275
|
+
if (found) {
|
|
276
|
+
return { kind: 'found', status: found }
|
|
277
|
+
}
|
|
278
|
+
if (provenAbsent) {
|
|
279
|
+
return { kind: 'not-found' }
|
|
280
|
+
}
|
|
281
|
+
return { kind: 'unknown', answered, errors }
|
|
282
|
+
}
|
|
283
|
+
|
|
284
|
+
/** Up to `CANARY_SLOT_STEPS` slots from `from` in `direction`, within
|
|
285
|
+
* `[0, last]`. */
|
|
286
|
+
function slotsFrom(
|
|
287
|
+
from: bigint,
|
|
288
|
+
direction: 1n | -1n,
|
|
289
|
+
last: bigint = from
|
|
290
|
+
): bigint[] {
|
|
291
|
+
const slots: bigint[] = []
|
|
292
|
+
for (let step = 0n; step < BigInt(CANARY_SLOT_STEPS); step += 1n) {
|
|
293
|
+
const slot = from + direction * step
|
|
294
|
+
if (slot < 0n || (direction === 1n && slot > last)) {
|
|
295
|
+
break
|
|
296
|
+
}
|
|
297
|
+
slots.push(slot)
|
|
298
|
+
}
|
|
299
|
+
return slots
|
|
300
|
+
}
|
|
301
|
+
|
|
302
|
+
/**
|
|
303
|
+
* The canaries and the head a `null` has to meet. `undefined` when no RPC
|
|
304
|
+
* reports its current slot, no RPC supplies a canary block, the age is not
|
|
305
|
+
* positive, or the search runs out of time - then no answer can prove
|
|
306
|
+
* absence.
|
|
307
|
+
*
|
|
308
|
+
* - History canary: a block at or before
|
|
309
|
+
* `lowest current slot - ceil(age / SLOT_DURATION_MS)`, stepping down.
|
|
310
|
+
* The lowest slot places it: one RPC ahead of the others - or wrong - must
|
|
311
|
+
* not move it after the anchor.
|
|
312
|
+
* - Head canary: a `confirmed` block at or after `expiredAtSlot`, stepping
|
|
313
|
+
* up toward the current slot. Without a verdict, the freshest confirmed
|
|
314
|
+
* block, stepping down from the highest current slot, which is then also
|
|
315
|
+
* the head.
|
|
316
|
+
*/
|
|
317
|
+
async function findCoverageProof(
|
|
318
|
+
rpcs: SolanaRpcType[],
|
|
319
|
+
bounds: LookupBounds
|
|
320
|
+
): Promise<CoverageProof | undefined> {
|
|
321
|
+
const age = (bounds.now ?? Date.now()) - bounds.anchor
|
|
322
|
+
// A clock before the anchor cannot place the history canary: an age of 0
|
|
323
|
+
// would put it at the current slot, the weakest canary there is.
|
|
324
|
+
if (!Number.isFinite(age) || age <= 0) {
|
|
325
|
+
return undefined
|
|
326
|
+
}
|
|
327
|
+
|
|
328
|
+
let outOfTime = false
|
|
329
|
+
const deadline = setTimeout(() => {
|
|
330
|
+
outOfTime = true
|
|
331
|
+
}, COVERAGE_PROOF_TIMEOUT_MS)
|
|
332
|
+
// RPCs that let a call run out of its budget. A rejection does not count:
|
|
333
|
+
// a pruned node rejects an old block but can still supply the head canary.
|
|
334
|
+
const silent = new Set<SolanaRpcType>()
|
|
335
|
+
|
|
336
|
+
/** The answers of the RPCs that are not silent, each within its budget. */
|
|
337
|
+
const ask = async <T>(
|
|
338
|
+
call: (rpc: SolanaRpcType, abortSignal: AbortSignal) => Promise<T>
|
|
339
|
+
): Promise<T[]> => {
|
|
340
|
+
const asked = rpcs.filter((rpc) => !silent.has(rpc))
|
|
341
|
+
const results = await Promise.allSettled(
|
|
342
|
+
asked.map((rpc) =>
|
|
343
|
+
callWithin(
|
|
344
|
+
(abortSignal) => call(rpc, abortSignal),
|
|
345
|
+
CANARY_CALL_TIMEOUT_MS
|
|
346
|
+
)
|
|
347
|
+
)
|
|
348
|
+
)
|
|
349
|
+
const answers: T[] = []
|
|
350
|
+
results.forEach((result, index) => {
|
|
351
|
+
if (result.status === 'fulfilled') {
|
|
352
|
+
answers.push(result.value)
|
|
353
|
+
} else if (result.reason instanceof CallTimeoutError) {
|
|
354
|
+
silent.add(asked[index])
|
|
355
|
+
}
|
|
356
|
+
})
|
|
357
|
+
return answers
|
|
358
|
+
}
|
|
359
|
+
|
|
360
|
+
/** A signature from the first of `slots` whose block any RPC supplies,
|
|
361
|
+
* with the slot of that block. */
|
|
362
|
+
const canaryFrom = async (
|
|
363
|
+
slots: bigint[],
|
|
364
|
+
config: typeof HISTORY_BLOCK_CONFIG | typeof HEAD_BLOCK_CONFIG
|
|
365
|
+
): Promise<Canary | undefined> => {
|
|
366
|
+
for (const slot of slots) {
|
|
367
|
+
if (outOfTime) {
|
|
368
|
+
return undefined
|
|
369
|
+
}
|
|
370
|
+
const blocks = await ask<unknown>((rpc, abortSignal) =>
|
|
371
|
+
rpc.getBlock(slot, config).send({ abortSignal })
|
|
372
|
+
)
|
|
373
|
+
const signature = firstSignatureOf(blocks)
|
|
374
|
+
if (signature) {
|
|
375
|
+
return { signature, slot }
|
|
376
|
+
}
|
|
377
|
+
}
|
|
378
|
+
return undefined
|
|
379
|
+
}
|
|
380
|
+
|
|
381
|
+
try {
|
|
382
|
+
const slots = (
|
|
383
|
+
await ask<unknown>((rpc, abortSignal) =>
|
|
384
|
+
rpc.getSlot({ commitment: 'confirmed' }).send({ abortSignal })
|
|
385
|
+
)
|
|
386
|
+
).filter((slot): slot is bigint => typeof slot === 'bigint')
|
|
387
|
+
if (slots.length === 0) {
|
|
388
|
+
return undefined
|
|
389
|
+
}
|
|
390
|
+
const lowestSlot = slots.reduce((low, slot) => (slot < low ? slot : low))
|
|
391
|
+
const highestSlot = slots.reduce((high, slot) =>
|
|
392
|
+
slot > high ? slot : high
|
|
393
|
+
)
|
|
394
|
+
|
|
395
|
+
const historyCanary = await canaryFrom(
|
|
396
|
+
slotsFrom(lowestSlot - BigInt(Math.ceil(age / SLOT_DURATION_MS)), -1n),
|
|
397
|
+
HISTORY_BLOCK_CONFIG
|
|
398
|
+
)
|
|
399
|
+
if (!historyCanary) {
|
|
400
|
+
return undefined
|
|
401
|
+
}
|
|
402
|
+
|
|
403
|
+
const { expiredAtSlot } = bounds
|
|
404
|
+
const headCanary = await canaryFrom(
|
|
405
|
+
expiredAtSlot === undefined
|
|
406
|
+
? slotsFrom(highestSlot, -1n)
|
|
407
|
+
: slotsFrom(
|
|
408
|
+
expiredAtSlot,
|
|
409
|
+
1n,
|
|
410
|
+
highestSlot > expiredAtSlot ? highestSlot : expiredAtSlot
|
|
411
|
+
),
|
|
412
|
+
HEAD_BLOCK_CONFIG
|
|
413
|
+
)
|
|
414
|
+
if (!headCanary) {
|
|
415
|
+
return undefined
|
|
416
|
+
}
|
|
417
|
+
return {
|
|
418
|
+
historyCanary,
|
|
419
|
+
headCanary,
|
|
420
|
+
headSlot: expiredAtSlot ?? highestSlot,
|
|
421
|
+
}
|
|
422
|
+
} finally {
|
|
423
|
+
clearTimeout(deadline)
|
|
424
|
+
}
|
|
425
|
+
}
|
|
426
|
+
|
|
427
|
+
/** A signature from the first block that has one. `undefined` for skipped
|
|
428
|
+
* or empty slots, pruned history or an outage. */
|
|
429
|
+
function firstSignatureOf(blocks: unknown[]): Signature | undefined {
|
|
430
|
+
for (const block of blocks) {
|
|
431
|
+
if (typeof block !== 'object' || block === null) {
|
|
432
|
+
continue
|
|
433
|
+
}
|
|
434
|
+
const { signatures } = block as { signatures?: unknown }
|
|
435
|
+
if (!Array.isArray(signatures)) {
|
|
436
|
+
continue
|
|
437
|
+
}
|
|
438
|
+
const canary = signatures.find(isSignatureEntry)
|
|
439
|
+
if (canary) {
|
|
440
|
+
return canary
|
|
441
|
+
}
|
|
442
|
+
}
|
|
443
|
+
return undefined
|
|
444
|
+
}
|
|
@@ -34,6 +34,13 @@ export async function sendAndConfirmTransaction(
|
|
|
34
34
|
options?: {
|
|
35
35
|
/** Runs once, when the first RPC accepts a send. */
|
|
36
36
|
onBroadcast?: () => void
|
|
37
|
+
/**
|
|
38
|
+
* Asked before every send, the resends included. `false` refuses the
|
|
39
|
+
* send as a failed one, and polling goes on. The wait tasks close it at
|
|
40
|
+
* the resend age cap, so stored bytes without their own expiry are never
|
|
41
|
+
* sent past it.
|
|
42
|
+
*/
|
|
43
|
+
mayResend?: () => boolean
|
|
37
44
|
}
|
|
38
45
|
): Promise<RaceResult<SignatureStatus>> {
|
|
39
46
|
const [solanaRpcs, writeRpcUrls = []] = await Promise.all([
|
|
@@ -89,6 +96,13 @@ export async function sendAndConfirmTransaction(
|
|
|
89
96
|
rpc: SolanaRpcType,
|
|
90
97
|
signal: AbortSignal
|
|
91
98
|
): Promise<void> => {
|
|
99
|
+
// Refused as a failed send, so the branch keeps polling: the bytes may
|
|
100
|
+
// already be on their way from an earlier send.
|
|
101
|
+
if (options?.mayResend && !options.mayResend()) {
|
|
102
|
+
throw new Error(
|
|
103
|
+
'The resend age cap has passed; the stored transaction is not sent again.'
|
|
104
|
+
)
|
|
105
|
+
}
|
|
92
106
|
await rpc
|
|
93
107
|
.sendTransaction(signedTxSerialized, rawTransactionOptions)
|
|
94
108
|
.send({ abortSignal: signal })
|
|
@@ -197,6 +211,10 @@ export async function sendAndConfirmTransaction(
|
|
|
197
211
|
// Reads `sendAccepted`, never `broadcastReported`: the latter is false
|
|
198
212
|
// whenever the integrator's callback threw, which says nothing about whether
|
|
199
213
|
// the network took the transaction.
|
|
214
|
+
//
|
|
215
|
+
// `expired` is left alone: once the blockhash is dead every send may be
|
|
216
|
+
// rejected, so "nothing was accepted" is expected there. Rewriting it would
|
|
217
|
+
// block the dropped verdict for good.
|
|
200
218
|
if (result.kind === 'not-confirmed' && !sendAccepted) {
|
|
201
219
|
return { kind: 'rpc-unavailable', errors: result.errors }
|
|
202
220
|
}
|