@streamflow/common 7.5.3 → 8.0.0-alpha.p287.5172056

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.
Files changed (45) hide show
  1. package/dist/cjs/index.cjs +90 -0
  2. package/dist/cjs/index.cjs.map +1 -0
  3. package/dist/cjs/index.d.cts +66 -0
  4. package/dist/cjs/solana/index.cjs +1121 -0
  5. package/dist/cjs/solana/index.cjs.map +1 -0
  6. package/dist/cjs/solana/index.d.cts +262 -0
  7. package/dist/cjs/solana/rpc/index.cjs +117 -0
  8. package/dist/cjs/solana/rpc/index.cjs.map +1 -0
  9. package/dist/cjs/solana/rpc/index.d.cts +89 -0
  10. package/dist/esm/index.d.ts +66 -3
  11. package/dist/esm/index.js +76 -3
  12. package/dist/esm/index.js.map +1 -0
  13. package/dist/esm/solana/index.d.ts +262 -5
  14. package/dist/esm/solana/index.js +1086 -5
  15. package/dist/esm/solana/index.js.map +1 -0
  16. package/dist/esm/solana/rpc/index.d.ts +89 -0
  17. package/dist/esm/solana/rpc/index.js +114 -0
  18. package/dist/esm/solana/rpc/index.js.map +1 -0
  19. package/package.json +33 -15
  20. package/dist/cjs/index.js +0 -19
  21. package/dist/cjs/lib/assertions.js +0 -13
  22. package/dist/cjs/lib/utils.js +0 -62
  23. package/dist/cjs/solana/account-filters.js +0 -19
  24. package/dist/cjs/solana/index.js +0 -21
  25. package/dist/cjs/solana/instructions.js +0 -22
  26. package/dist/cjs/solana/public-key.js +0 -13
  27. package/dist/cjs/solana/types.js +0 -11
  28. package/dist/cjs/solana/utils.js +0 -478
  29. package/dist/cjs/types.js +0 -40
  30. package/dist/esm/lib/assertions.d.ts +0 -1
  31. package/dist/esm/lib/assertions.js +0 -9
  32. package/dist/esm/lib/utils.d.ts +0 -28
  33. package/dist/esm/lib/utils.js +0 -51
  34. package/dist/esm/solana/account-filters.d.ts +0 -2
  35. package/dist/esm/solana/account-filters.js +0 -15
  36. package/dist/esm/solana/instructions.d.ts +0 -3
  37. package/dist/esm/solana/instructions.js +0 -18
  38. package/dist/esm/solana/public-key.d.ts +0 -7
  39. package/dist/esm/solana/public-key.js +0 -9
  40. package/dist/esm/solana/types.d.ts +0 -39
  41. package/dist/esm/solana/types.js +0 -7
  42. package/dist/esm/solana/utils.d.ts +0 -187
  43. package/dist/esm/solana/utils.js +0 -450
  44. package/dist/esm/types.d.ts +0 -32
  45. package/dist/esm/types.js +0 -38
@@ -0,0 +1,89 @@
1
+ import * as _solana_web3_js from '@solana/web3.js';
2
+ import { PublicKey, Connection } from '@solana/web3.js';
3
+
4
+ /**
5
+ * @interface GetPriorityFeeEstimateOptions - The options for the priority fee estimate
6
+ */
7
+ interface GetPriorityFeeEstimateOptions {
8
+ /**
9
+ * The accounts or transaction to get the priority fee estimate for.
10
+ * `string` is a serialized base64 transaction.
11
+ * `array` is interpreted as an array of public keys in string format or as PublicKey instances (writable accounts).
12
+ */
13
+ accountsOrTx: (string | PublicKey)[] | string;
14
+ /**
15
+ * The percentile of the priority fee estimate to return.
16
+ *
17
+ * examples: Triton RPC - [0, 10000]
18
+ * @default 5000
19
+ */
20
+ percentile?: number;
21
+ /**
22
+ * The safe area increase to apply to the priority fee estimate.
23
+ * @default 0.05 = 5%
24
+ */
25
+ safeAreaIncrease?: number;
26
+ }
27
+
28
+ /**
29
+ * @category GetPriorityFeeEstimateOptions
30
+ * @interface RecentPrioritizationFee
31
+ * @property result - The result of the recent prioritization fees.
32
+ * @property result.prioritizationFee - The prioritization fee.
33
+ * @property result.slot - The slot of the prioritization fee.
34
+ */
35
+ interface RecentPrioritizationFee {
36
+ result: Array<{
37
+ prioritizationFee: number;
38
+ slot: number;
39
+ }>;
40
+ }
41
+ /**
42
+ * Fetch the recent prioritization fees from the RPC [getRecentPrioritizationFees]
43
+ * @param connection - The connection to the RPC
44
+ * @param options - The options for the RPC
45
+ * @returns The priority fee estimate
46
+ */
47
+ declare const getPriorityFeeEstimate$1: (connection: Connection, options: GetPriorityFeeEstimateOptions) => Promise<{
48
+ median: number;
49
+ data: RecentPrioritizationFee;
50
+ }>;
51
+ /**
52
+ * If an RPC of use supports percentile value, aka {@link https://docs.triton.one/chains/solana/improved-priority-fees-api}
53
+ * @param connection - The connection to the RPC
54
+ * @param options - The options for the RPC
55
+ * @returns The priority fee estimate
56
+ */
57
+ declare const getRecentPrioritizationFee$1: (connection: Connection, options: Pick<GetPriorityFeeEstimateOptions, "accountsOrTx" | "percentile">) => Promise<RecentPrioritizationFee>;
58
+
59
+ declare namespace percentile {
60
+ export { getPriorityFeeEstimate$1 as getPriorityFeeEstimate, getRecentPrioritizationFee$1 as getRecentPrioritizationFee };
61
+ }
62
+
63
+ /**
64
+ * Fetch the recent prioritization fees from the RPC [getRecentPrioritizationFees] (https://solana.com/docs/rpc/http/getrecentprioritizationfees)
65
+ * @deprecated Not recommended for use because it provides a single number per slot to indicate the minimum priority fee amount.
66
+ * @param connection - The connection to the RPC
67
+ * @param options - The options for the RPC
68
+ * @returns The priority fee estimate
69
+ */
70
+ declare const getPriorityFeeEstimate: (connection: Connection, options: GetPriorityFeeEstimateOptions) => Promise<{
71
+ median: number;
72
+ data: _solana_web3_js.RecentPrioritizationFees[];
73
+ }>;
74
+ /**
75
+ * Fetch the recent prioritization fees from the RPC [getRecentPrioritizationFees] (https://solana.com/docs/rpc/http/getrecentprioritizationfees)
76
+ * @deprecated Not recommended for use because it provides a single number per slot to indicate the minimum priority fee amount.
77
+ * @param connection - The connection to the RPC
78
+ * @param options - The options for the RPC
79
+ * @returns The priority fee estimate
80
+ */
81
+ declare const getRecentPrioritizationFee: (connection: Connection, options: Pick<GetPriorityFeeEstimateOptions, "accountsOrTx">) => Promise<_solana_web3_js.RecentPrioritizationFees[]>;
82
+
83
+ declare const general_getPriorityFeeEstimate: typeof getPriorityFeeEstimate;
84
+ declare const general_getRecentPrioritizationFee: typeof getRecentPrioritizationFee;
85
+ declare namespace general {
86
+ export { general_getPriorityFeeEstimate as getPriorityFeeEstimate, general_getRecentPrioritizationFee as getRecentPrioritizationFee };
87
+ }
88
+
89
+ export { type GetPriorityFeeEstimateOptions, general as priorityFeeEstimation, percentile as priorityFeeEstimationPercentile };
@@ -1,3 +1,66 @@
1
- export * from "./types.js";
2
- export * from "./lib/assertions.js";
3
- export * from "./lib/utils.js";
1
+ import { TransactionInstruction } from '@solana/web3.js';
2
+ import BN from 'bn.js';
3
+
4
+ interface ITransactionResult {
5
+ ixs: TransactionInstruction[];
6
+ txId: string;
7
+ }
8
+ declare enum ICluster {
9
+ Mainnet = "mainnet",
10
+ Devnet = "devnet",
11
+ Testnet = "testnet",
12
+ Local = "local"
13
+ }
14
+ declare enum IChain {
15
+ Solana = "Solana",
16
+ Aptos = "Aptos",
17
+ Ethereum = "Ethereum",
18
+ BNB = "BNB",
19
+ Polygon = "Polygon",
20
+ Sui = "Sui"
21
+ }
22
+ /**
23
+ * Error wrapper for calls made to the contract on chain
24
+ */
25
+ declare class ContractError extends Error {
26
+ contractErrorCode: string | null;
27
+ description: string | null;
28
+ /**
29
+ * Constructs the Error Wrapper
30
+ * @param error Original error raised probably by the chain SDK
31
+ * @param code extracted code from the error if managed to parse it
32
+ */
33
+ constructor(error: Error, code?: string | null, description?: string | null);
34
+ }
35
+
36
+ declare const invariant: (condition: any, message?: string | (() => string)) => asserts condition;
37
+
38
+ /**
39
+ * Used for conversion of token amounts to their Big Number representation.
40
+ * Get Big Number representation in the smallest units from the same value in the highest units.
41
+ * @param {number} value - Number of tokens you want to convert to its BN representation.
42
+ * @param {number} decimals - Number of decimals the token has.
43
+ */
44
+ declare const getBN: (value: number, decimals: number) => BN;
45
+ /**
46
+ * Used for token amounts conversion from their Big Number representation to number.
47
+ * Get value in the highest units from BN representation of the same value in the smallest units.
48
+ * @param {BN} value - Big Number representation of value in the smallest units.
49
+ * @param {number} decimals - Number of decimals the token has.
50
+ */
51
+ declare const getNumberFromBN: (value: BN, decimals: number) => number;
52
+ /**
53
+ * Used to make on chain calls to the contract and wrap raised errors if any
54
+ * @param func function that interacts with the contract
55
+ * @param callback callback that may be used to extract error code
56
+ * @returns {T}
57
+ */
58
+ declare function handleContractError<T>(func: () => Promise<T>, callback?: (err: Error) => string | null): Promise<T>;
59
+ /**
60
+ * Pause async function execution for given amount of milliseconds
61
+ * @param ms millisecond to sleep for
62
+ */
63
+ declare function sleep(ms: number): Promise<void>;
64
+ declare const divCeilN: (n: bigint, d: bigint) => bigint;
65
+
66
+ export { ContractError, IChain, ICluster, type ITransactionResult, divCeilN, getBN, getNumberFromBN, handleContractError, invariant, sleep };
package/dist/esm/index.js CHANGED
@@ -1,3 +1,76 @@
1
- export * from "./types.js";
2
- export * from "./lib/assertions.js";
3
- export * from "./lib/utils.js";
1
+ import '@solana/web3.js';
2
+ import BN from 'bn.js';
3
+
4
+ // types.ts
5
+ var ICluster = /* @__PURE__ */ ((ICluster2) => {
6
+ ICluster2["Mainnet"] = "mainnet";
7
+ ICluster2["Devnet"] = "devnet";
8
+ ICluster2["Testnet"] = "testnet";
9
+ ICluster2["Local"] = "local";
10
+ return ICluster2;
11
+ })(ICluster || {});
12
+ var IChain = /* @__PURE__ */ ((IChain2) => {
13
+ IChain2["Solana"] = "Solana";
14
+ IChain2["Aptos"] = "Aptos";
15
+ IChain2["Ethereum"] = "Ethereum";
16
+ IChain2["BNB"] = "BNB";
17
+ IChain2["Polygon"] = "Polygon";
18
+ IChain2["Sui"] = "Sui";
19
+ return IChain2;
20
+ })(IChain || {});
21
+ var ContractError = class _ContractError extends Error {
22
+ /**
23
+ * Constructs the Error Wrapper
24
+ * @param error Original error raised probably by the chain SDK
25
+ * @param code extracted code from the error if managed to parse it
26
+ */
27
+ constructor(error, code, description) {
28
+ super(error.message, { cause: error });
29
+ this.contractErrorCode = code ?? null;
30
+ this.description = description ?? null;
31
+ Object.setPrototypeOf(this, _ContractError.prototype);
32
+ this.name = "ContractError";
33
+ this.stack = error.stack;
34
+ }
35
+ };
36
+
37
+ // lib/assertions.ts
38
+ var prefix = "Assertion failed";
39
+ var invariant = (condition, message) => {
40
+ if (condition) {
41
+ return;
42
+ }
43
+ const provided = typeof message === "function" ? message() : message;
44
+ const value = provided ? `${prefix}: ${provided}` : prefix;
45
+ throw new Error(value);
46
+ };
47
+ var getBN = (value, decimals) => {
48
+ const decimalPart = value - Math.trunc(value);
49
+ const integerPart = new BN(Math.trunc(value));
50
+ const decimalE = new BN(decimalPart * 1e9);
51
+ const sum = integerPart.mul(new BN(1e9)).add(decimalE);
52
+ const resultE = sum.mul(new BN(10).pow(new BN(decimals)));
53
+ return resultE.div(new BN(1e9));
54
+ };
55
+ var getNumberFromBN = (value, decimals) => value.gt(new BN(2 ** 53 - 1)) ? value.div(new BN(10 ** decimals)).toNumber() : value.toNumber() / 10 ** decimals;
56
+ async function handleContractError(func, callback) {
57
+ try {
58
+ return await func();
59
+ } catch (err) {
60
+ if (err instanceof Error) {
61
+ if (callback) {
62
+ throw new ContractError(err, callback(err));
63
+ }
64
+ throw new ContractError(err);
65
+ }
66
+ throw err;
67
+ }
68
+ }
69
+ function sleep(ms) {
70
+ return new Promise((resolve) => setTimeout(resolve, ms));
71
+ }
72
+ var divCeilN = (n, d) => n / d + (n % d ? BigInt(1) : BigInt(0));
73
+
74
+ export { ContractError, IChain, ICluster, divCeilN, getBN, getNumberFromBN, handleContractError, invariant, sleep };
75
+ //# sourceMappingURL=index.js.map
76
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../types.ts","../../lib/assertions.ts","../../lib/utils.ts"],"names":["ICluster","IChain"],"mappings":";;;;AAQY,IAAA,QAAA,qBAAAA,SAAL,KAAA;AACL,EAAAA,UAAA,SAAU,CAAA,GAAA,SAAA;AACV,EAAAA,UAAA,QAAS,CAAA,GAAA,QAAA;AACT,EAAAA,UAAA,SAAU,CAAA,GAAA,SAAA;AACV,EAAAA,UAAA,OAAQ,CAAA,GAAA,OAAA;AAJE,EAAAA,OAAAA,SAAAA;AAAA,CAAA,EAAA,QAAA,IAAA,EAAA;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;AAE7B,IAAM,MAAA,GAAA;AAAA;AAEV;AAMO,SAAS,MAAM,EAA2B,EAAA;AAC/C,EAAA,OAAO,IAAI,OAAQ,CAAA,CAAC,YAAY,UAAW,CAAA,OAAA,EAAS,EAAE,CAAC,CAAA;AACzD;AAEO,IAAM,QAAW,GAAA,CAAC,CAAW,EAAA,CAAA,KAAsB,CAAI,GAAA,CAAA,IAAK,CAAI,GAAA,CAAA,GAAI,MAAO,CAAA,CAAC,CAAI,GAAA,MAAA,CAAO,CAAC,CAAA","file":"index.js","sourcesContent":["import { type TransactionInstruction } from \"@solana/web3.js\";\n\nexport interface ITransactionResult {\n ixs: TransactionInstruction[];\n txId: string;\n}\n\n// Utility types\nexport enum ICluster {\n Mainnet = \"mainnet\",\n Devnet = \"devnet\",\n Testnet = \"testnet\",\n Local = \"local\",\n}\n\nexport enum IChain {\n Solana = \"Solana\",\n Aptos = \"Aptos\",\n Ethereum = \"Ethereum\",\n BNB = \"BNB\",\n Polygon = \"Polygon\",\n Sui = \"Sui\",\n}\n\n/**\n * Error wrapper for calls made to the contract on chain\n */\nexport class ContractError extends Error {\n public contractErrorCode: string | null;\n\n public description: string | null;\n\n /**\n * Constructs the Error Wrapper\n * @param error Original error raised probably by the chain SDK\n * @param code extracted code from the error if managed to parse it\n */\n constructor(error: Error, code?: string | null, description?: string | null) {\n super(error.message, { cause: error }); // Call the base class constructor with the error message\n this.contractErrorCode = code ?? null;\n this.description = description ?? null;\n // Copy properties from the original error\n Object.setPrototypeOf(this, ContractError.prototype);\n this.name = \"ContractError\"; // Set the name property\n this.stack = error.stack;\n }\n}\n","const prefix = \"Assertion failed\";\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\nexport const invariant: (condition: any, message?: string | (() => string)) => asserts condition = (\n condition,\n message,\n) => {\n if (condition) {\n return;\n }\n const provided: string | undefined = typeof message === \"function\" ? message() : message;\n const value: string = provided ? `${prefix}: ${provided}` : prefix;\n throw new Error(value);\n};\n","import BN from \"bn.js\";\n\nimport { ContractError } from \"../types.js\";\n\n/**\n * Used for conversion of token amounts to their Big Number representation.\n * Get Big Number representation in the smallest units from the same value in the highest units.\n * @param {number} value - Number of tokens you want to convert to its BN representation.\n * @param {number} decimals - Number of decimals the token has.\n */\nexport const getBN = (value: number, decimals: number): BN => {\n const decimalPart = value - Math.trunc(value);\n const integerPart = new BN(Math.trunc(value));\n\n const decimalE = new BN(decimalPart * 1e9);\n\n const sum = integerPart.mul(new BN(1e9)).add(decimalE);\n const resultE = sum.mul(new BN(10).pow(new BN(decimals)));\n return resultE.div(new BN(1e9));\n};\n\n/**\n * Used for token amounts conversion from their Big Number representation to number.\n * Get value in the highest units from BN representation of the same value in the smallest units.\n * @param {BN} value - Big Number representation of value in the smallest units.\n * @param {number} decimals - Number of decimals the token has.\n */\nexport const getNumberFromBN = (value: BN, decimals: number): number =>\n value.gt(new BN(2 ** 53 - 1)) ? value.div(new BN(10 ** decimals)).toNumber() : value.toNumber() / 10 ** decimals;\n\n/**\n * Used to make on chain calls to the contract and wrap raised errors if any\n * @param func function that interacts with the contract\n * @param callback callback that may be used to extract error code\n * @returns {T}\n */\nexport async function handleContractError<T>(\n func: () => Promise<T>,\n callback?: (err: Error) => string | null,\n): Promise<T> {\n try {\n return await func();\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n } catch (err: any) {\n if (err instanceof Error) {\n if (callback) {\n throw new ContractError(err, callback(err));\n }\n throw new ContractError(err);\n }\n throw err;\n }\n}\n\n/**\n * Pause async function execution for given amount of milliseconds\n * @param ms millisecond to sleep for\n */\nexport function sleep(ms: number): Promise<void> {\n return new Promise((resolve) => setTimeout(resolve, ms));\n}\n\nexport const divCeilN = (n: bigint, d: bigint): bigint => n / d + (n % d ? BigInt(1) : BigInt(0));\n"]}
@@ -1,5 +1,262 @@
1
- export * from "./account-filters.js";
2
- export * from "./instructions.js";
3
- export * from "./public-key.js";
4
- export * from "./types.js";
5
- export * from "./utils.js";
1
+ import { PublicKey, MemcmpFilter, Connection, TransactionInstruction, AccountInfo, BlockhashWithExpiryBlockHeight, Context, Commitment, Keypair, Transaction, VersionedTransaction, RpcResponseAndContext, SimulatedTransactionResponse, SignatureStatus } from '@solana/web3.js';
2
+ import BN from 'bn.js';
3
+ import PQueue from 'p-queue';
4
+ import { Mint } from '@solana/spl-token';
5
+ import { SignerWalletAdapter } from '@solana/wallet-adapter-base';
6
+
7
+ declare const getFilters: <T extends Record<string, number | PublicKey>>(criteria: T, byteOffsets: Record<keyof T, number>) => MemcmpFilter[];
8
+
9
+ declare const prepareWrappedAccount: (connection: Connection, senderAddress: PublicKey, amount: BN) => Promise<TransactionInstruction[]>;
10
+
11
+ /**
12
+ * Converts a string or PublicKey to a PublicKey object.
13
+ * @param address - The input address as a string or PublicKey.
14
+ * @returns The PublicKey object.
15
+ */
16
+ declare const pk: (address: string | PublicKey) => PublicKey;
17
+
18
+ type ComputePriceEstimate = (tx: string | (string | PublicKey)[]) => Promise<number>;
19
+ interface ITransactionSolanaExt {
20
+ computePrice?: number | ComputePriceEstimate;
21
+ computeLimit?: number;
22
+ }
23
+ interface IInteractSolanaExt extends ITransactionSolanaExt {
24
+ invoker: {
25
+ publicKey: string | PublicKey | null;
26
+ };
27
+ }
28
+ interface Account {
29
+ pubkey: PublicKey;
30
+ account: AccountInfo<Buffer>;
31
+ }
32
+ interface CheckAssociatedTokenAccountsData {
33
+ sender: PublicKey;
34
+ recipient: PublicKey;
35
+ partner: PublicKey;
36
+ streamflowTreasury: PublicKey;
37
+ mint: PublicKey;
38
+ }
39
+ interface AtaParams {
40
+ mint: PublicKey;
41
+ owner: PublicKey;
42
+ programId?: PublicKey;
43
+ }
44
+ interface ConfirmationParams {
45
+ hash: BlockhashWithExpiryBlockHeight;
46
+ context: Context;
47
+ commitment?: Commitment;
48
+ }
49
+ interface ThrottleParams {
50
+ sendRate?: number;
51
+ sendThrottler?: PQueue;
52
+ waitBeforeConfirming?: number | undefined;
53
+ }
54
+ interface IProgramAccount<T> {
55
+ publicKey: PublicKey;
56
+ account: T;
57
+ }
58
+ declare class TransactionFailedError extends Error {
59
+ constructor(m: string);
60
+ }
61
+
62
+ declare const buildSendThrottler: (sendRate: number, sendInterval?: number) => PQueue;
63
+ /**
64
+ * Wrapper function for Solana web3 getProgramAccounts with slightly better call interface
65
+ * @param {Connection} connection - Solana web3 connection object.
66
+ * @param {PublicKey} wallet - PublicKey to compare against.
67
+ * @param {number} offset - Offset of bits of the PublicKey in the account binary.
68
+ * @param {PublicKey} programId - Solana program ID.
69
+ * @return {Promise<Account[]>} - Array of resulting accounts.
70
+ */
71
+ declare function getProgramAccounts(connection: Connection, wallet: PublicKey, offset: number, programId: PublicKey): Promise<Account[]>;
72
+ /**
73
+ * Utility function to check if the transaction initiator is a Wallet object
74
+ * @param {Keypair | SignerWalletAdapter} walletOrKeypair - Wallet or Keypair in question
75
+ * @return {boolean} - Returns true if parameter is a Wallet.
76
+ */
77
+ declare function isSignerWallet(walletOrKeypair: Keypair | SignerWalletAdapter): walletOrKeypair is SignerWalletAdapter;
78
+ /**
79
+ * Utility function to check if the transaction initiator a Keypair object, tries to mitigate version mismatch issues
80
+ * @param walletOrKeypair {Keypair | SignerWalletAdapter} walletOrKeypair - Wallet or Keypair in question
81
+ * @returns {boolean} - Returns true if parameter is a Keypair.
82
+ */
83
+ declare function isSignerKeypair(walletOrKeypair: Keypair | SignerWalletAdapter): walletOrKeypair is Keypair;
84
+ /**
85
+ * Utility function to check whether given transaction is Versioned
86
+ * @param tx {Transaction | VersionedTransaction} - Transaction to check
87
+ * @returns {boolean} - Returns true if transaction is Versioned.
88
+ */
89
+ declare function isTransactionVersioned(tx: Transaction | VersionedTransaction): tx is VersionedTransaction;
90
+ /**
91
+ * Creates a Transaction with given instructions and optionally signs it.
92
+ * @param connection - Solana client connection
93
+ * @param ixs - Instructions to add to the Transaction
94
+ * @param payer - PublicKey of payer
95
+ * @param commitment - optional Commitment that will be used to fetch latest blockhash
96
+ * @param partialSigners - optional signers that will be used to partially sign a Transaction
97
+ * @returns Transaction and Blockhash
98
+ */
99
+ declare function prepareTransaction(connection: Connection, ixs: TransactionInstruction[], payer: PublicKey | undefined | null, commitment?: Commitment, partialSigners?: (Keypair | undefined)[]): Promise<{
100
+ tx: VersionedTransaction;
101
+ hash: BlockhashWithExpiryBlockHeight;
102
+ context: Context;
103
+ }>;
104
+ declare function createVersionedTransaction(ixs: TransactionInstruction[], payer: PublicKey | undefined | null, recentBlockhash: BlockhashWithExpiryBlockHeight["blockhash"], partialSigners?: (Keypair | undefined)[]): VersionedTransaction;
105
+ declare function signTransaction<T extends Transaction | VersionedTransaction>(invoker: Keypair | SignerWalletAdapter, tx: T): Promise<T>;
106
+ /**
107
+ * Signs, sends and confirms Transaction
108
+ * @param connection - Solana client connection
109
+ * @param invoker - Keypair used as signer
110
+ * @param tx - Transaction instance
111
+ * @param confirmationParams - Confirmation Params that will be used for execution
112
+ * @param throttleParams - rate or throttler instance to throttle TX sending - to not spam the blockchain too much
113
+ * @returns Transaction signature
114
+ */
115
+ declare function signAndExecuteTransaction(connection: Connection, invoker: Keypair | SignerWalletAdapter, tx: Transaction | VersionedTransaction, confirmationParams: ConfirmationParams, throttleParams: ThrottleParams): Promise<string>;
116
+ /**
117
+ * Sends and confirms Transaction
118
+ * Uses custom confirmation logic that:
119
+ * - simulates tx before sending separately
120
+ * - sends transaction without preFlight checks but with some valuable flags https://twitter.com/jordaaash/status/1774892862049800524?s=46&t=bhZ10V0r7IX5Lk5kKzxfGw
121
+ * - rebroadcasts a tx every 500 ms
122
+ * - after broadcasting check whether tx has executed once
123
+ * - catch errors for every actionable item, throw only the ones that signal that tx has failed
124
+ * - otherwise there is a chance of marking a landed tx as failed if it was broadcasted at least once
125
+ * @param connection - Solana client connection
126
+ * @param tx - Transaction instance
127
+ * @param confirmationParams - Confirmation Params that will be used for execution
128
+ * @param throttleParams - rate or throttler instance to throttle TX sending - to not spam the blockchain too much
129
+ * @returns Transaction signature
130
+ */
131
+ declare function executeTransaction(connection: Connection, tx: Transaction | VersionedTransaction, confirmationParams: ConfirmationParams, throttleParams: ThrottleParams): Promise<string>;
132
+ /**
133
+ * Launches a PromisePool with all transaction being executed at the same time, allows to throttle all TXs through one Queue
134
+ * @param connection - Solana client connection
135
+ * @param txs - Transactions
136
+ * @param confirmationParams - Confirmation Params that will be used for execution
137
+ * @param throttleParams - rate or throttler instance to throttle TX sending - to not spam the blockchain too much
138
+ * @param throttleParams.sendRate - rate
139
+ * @param throttleParams.sendThrottler - throttler instance
140
+ * @returns Raw Promise Results - should be handled by the consumer and unwrapped accordingly
141
+ */
142
+ declare function executeMultipleTransactions(connection: Connection, txs: (Transaction | VersionedTransaction)[], confirmationParams: ConfirmationParams, { sendRate, sendThrottler, ...throttlingParams }: ThrottleParams): Promise<PromiseSettledResult<string>[]>;
143
+ /**
144
+ * Sends and confirm transaction in a loop, constantly re-broadcsting the tx until Blockheight expires.
145
+ * - we add additional 30 bocks to account for validators in an PRC pool divergence
146
+ * @param connection - Solana client connection
147
+ * @param tx - Transaction instance
148
+ * @param confirmationParams - Confirmation Params that will be used for execution
149
+ * @param confirmationParams.hash - blockhash information, the same hash should be used in the Transaction
150
+ * @param confirmationParams.context - context at which blockhash has been retrieve
151
+ * @param confirmationParams.commitment - optional commitment that will be used for simulation and confirmation
152
+ * @param throttleParams - rate or throttler instance to throttle TX sending - to not spam the blockchain too much
153
+ * @param throttleParams.sendRate - rate
154
+ * @param throttleParams.sendThrottler - throttler instance
155
+ */
156
+ declare function sendAndConfirmTransaction(connection: Connection, tx: Transaction | VersionedTransaction, { hash, context, commitment }: ConfirmationParams, { sendRate, sendThrottler, waitBeforeConfirming }: ThrottleParams): Promise<string>;
157
+ declare function simulateTransaction(connection: Connection, tx: Transaction | VersionedTransaction): Promise<RpcResponseAndContext<SimulatedTransactionResponse>>;
158
+ /**
159
+ * Confirms and validates transaction success once
160
+ * @param connection - Solana client connection
161
+ * @param signature - Transaction signature
162
+ * @param ignoreError - return status even if tx failed
163
+ * @returns Transaction Status
164
+ */
165
+ declare function confirmAndEnsureTransaction(connection: Connection, signature: string, ignoreError?: boolean): Promise<SignatureStatus | null>;
166
+ /**
167
+ * Shorthand call signature for getAssociatedTokenAddress, with allowance for address to be offCurve
168
+ * @param {PublicKey} mint - SPL token Mint address.
169
+ * @param {PublicKey} owner - Owner of the Associated Token Address
170
+ * @param {PublicKey} programId - Program ID of the mint
171
+ * @return {Promise<PublicKey>} - Associated Token Address
172
+ */
173
+ declare function ata(mint: PublicKey, owner: PublicKey, programId?: PublicKey): Promise<PublicKey>;
174
+ /**
175
+ * Function that checks whether ATA exists for each provided owner
176
+ * @param connection - Solana client connection
177
+ * @param paramsBatch - Array of Params for each ATA account: {mint, owner}
178
+ * @returns Array of boolean where each member corresponds to an owner
179
+ */
180
+ declare function ataBatchExist(connection: Connection, paramsBatch: AtaParams[]): Promise<boolean[]>;
181
+ declare function enrichAtaParams(connection: Connection, paramsBatch: AtaParams[]): Promise<AtaParams[]>;
182
+ /**
183
+ * Generates a Transaction to create ATA for an array of owners
184
+ * @param connection - Solana client connection
185
+ * @param payer - Transaction invoker, should be a signer
186
+ * @param paramsBatch - Array of Params for an each ATA account: {mint, owner}
187
+ * @param commitment - optional commitment that will be used to fetch Blockhash
188
+ * @returns Unsigned Transaction with create ATA instructions
189
+ */
190
+ declare function generateCreateAtaBatchTx(connection: Connection, payer: PublicKey, paramsBatch: AtaParams[], commitment?: Commitment): Promise<{
191
+ tx: VersionedTransaction;
192
+ hash: BlockhashWithExpiryBlockHeight;
193
+ context: Context;
194
+ }>;
195
+ /**
196
+ * Creates ATA for an array of owners
197
+ * @param connection - Solana client connection
198
+ * @param invoker - Transaction invoker and payer
199
+ * @param paramsBatch - Array of Params for an each ATA account: {mint, owner}
200
+ * @param commitment - optional commitment that will be used to fetch Blockhash
201
+ * @param rate - throttle rate for tx sending
202
+ * @returns Transaction signature
203
+ */
204
+ declare function createAtaBatch(connection: Connection, invoker: Keypair | SignerWalletAdapter, paramsBatch: AtaParams[], commitment?: Commitment, rate?: number): Promise<string>;
205
+ /**
206
+ * Utility function that checks whether associated token accounts exist and return instructions to populate them if not
207
+ * @param connection - Solana client connection
208
+ * @param owners - Array of ATA owners
209
+ * @param mint - Mint for which ATA will be checked
210
+ * @param invoker - Transaction invoker and payer
211
+ * @param programId - Program ID of the Mint
212
+ * @returns Array of Transaction Instructions that should be added to a transaction
213
+ */
214
+ declare function checkOrCreateAtaBatch(connection: Connection, owners: PublicKey[], mint: PublicKey, invoker: SignerWalletAdapter | Keypair, programId?: PublicKey): Promise<TransactionInstruction[]>;
215
+ /**
216
+ * Create Base instructions for Solana
217
+ * - sets compute price if `computePrice` is provided. If `computePrice` is a function, it will be ignored (the value must be resolved before calling this function).
218
+ * - sets compute limit if `computeLimit` is provided
219
+ */
220
+ declare function prepareBaseInstructions(connection: Connection, { computePrice, computeLimit }: ITransactionSolanaExt): TransactionInstruction[];
221
+ /**
222
+ * Retrieve information about a mint and its program ID, support all Token Programs.
223
+ *
224
+ * @param connection Connection to use
225
+ * @param address Mint account
226
+ * @param commitment Desired level of commitment for querying the state
227
+ *
228
+ * @return Mint information
229
+ */
230
+ declare function getMintAndProgram(connection: Connection, address: PublicKey, commitment?: Commitment): Promise<{
231
+ mint: Mint;
232
+ tokenProgramId: PublicKey;
233
+ }>;
234
+ /**
235
+ * Split fetching of Multiple Accounts Info into batches of 100
236
+ * as the maximum number of accounts that can be fetched in a single call is 100
237
+ *
238
+ * @param connection Connection to use
239
+ * @param pubKeys Array of public keys to fetch account info for
240
+ * @param commitment Desired level of commitment for querying the state
241
+ *
242
+ * @return Array of AccountInfo objects
243
+ */
244
+ declare function getMultipleAccountsInfoBatched(connection: Connection, pubKeys: PublicKey[], commitment?: Commitment): Promise<(AccountInfo<Buffer> | null)[]>;
245
+
246
+ declare function estimateComputeUnitPrice(estimate: ComputePriceEstimate, ixs: Parameters<typeof createVersionedTransaction>[0], payer: Parameters<typeof createVersionedTransaction>[1], recentBlockhash?: Parameters<typeof createVersionedTransaction>[2], partialSigners?: Parameters<typeof createVersionedTransaction>[3]): Promise<number>;
247
+ declare function createAndEstimateTransaction<CreateFn extends (extParams: IInteractSolanaExt) => Promise<TransactionInstruction[]>>(createFn: CreateFn, extParams: IInteractSolanaExt): Promise<Awaited<ReturnType<CreateFn>>>;
248
+ declare function createAndEstimateTransaction<CreateFn extends (extParams: IInteractSolanaExt) => Promise<any>>(createFn: CreateFn, extParams: IInteractSolanaExt, select: (result: Awaited<ReturnType<CreateFn>>) => TransactionInstruction[]): Promise<Awaited<ReturnType<CreateFn>>>;
249
+
250
+ declare function deserializeRawTransaction(serializedTx: string): {
251
+ type: string;
252
+ transaction: Transaction;
253
+ accounts: PublicKey[];
254
+ writableAccounts: PublicKey[];
255
+ } | {
256
+ type: string;
257
+ transaction: VersionedTransaction;
258
+ accounts: PublicKey[];
259
+ writableAccounts: PublicKey[];
260
+ };
261
+
262
+ export { type Account, type AtaParams, type CheckAssociatedTokenAccountsData, type ComputePriceEstimate, type ConfirmationParams, type IInteractSolanaExt, type IProgramAccount, type ITransactionSolanaExt, type ThrottleParams, TransactionFailedError, ata, ataBatchExist, buildSendThrottler, checkOrCreateAtaBatch, confirmAndEnsureTransaction, createAndEstimateTransaction, createAtaBatch, createVersionedTransaction, deserializeRawTransaction, enrichAtaParams, estimateComputeUnitPrice, executeMultipleTransactions, executeTransaction, generateCreateAtaBatchTx, getFilters, getMintAndProgram, getMultipleAccountsInfoBatched, getProgramAccounts, isSignerKeypair, isSignerWallet, isTransactionVersioned, pk, prepareBaseInstructions, prepareTransaction, prepareWrappedAccount, sendAndConfirmTransaction, signAndExecuteTransaction, signTransaction, simulateTransaction };