@streamflow/common 8.0.0-alpha.p284.726ba98 → 8.0.0-alpha.p287.84ff30f

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.
@@ -0,0 +1,117 @@
1
+ 'use strict';
2
+
3
+ var web3_js = require('@solana/web3.js');
4
+ var buffer = require('buffer');
5
+
6
+ var __defProp = Object.defineProperty;
7
+ var __export = (target, all) => {
8
+ for (var name in all)
9
+ __defProp(target, name, { get: all[name], enumerable: true });
10
+ };
11
+
12
+ // solana/rpc/priority-fee-estimate/percentile.ts
13
+ var percentile_exports = {};
14
+ __export(percentile_exports, {
15
+ getPriorityFeeEstimate: () => getPriorityFeeEstimate,
16
+ getRecentPrioritizationFee: () => getRecentPrioritizationFee
17
+ });
18
+ function deserializeRawTransaction(serializedTx) {
19
+ const txBuffer = buffer.Buffer.from(serializedTx, "base64");
20
+ try {
21
+ const tx = web3_js.Transaction.from(txBuffer);
22
+ const message = tx.compileMessage();
23
+ const accounts = message.accountKeys;
24
+ const writableAccounts = accounts.filter((_, idx) => message.isAccountWritable(idx));
25
+ return {
26
+ type: "legacy",
27
+ transaction: tx,
28
+ accounts,
29
+ writableAccounts
30
+ };
31
+ } catch (error) {
32
+ try {
33
+ const vtx = web3_js.VersionedTransaction.deserialize(txBuffer);
34
+ const message = vtx.message;
35
+ const accounts = "staticAccountKeys" in message ? message.staticAccountKeys : message.accountKeys;
36
+ const writableAccounts = accounts.filter((_, idx) => message.isAccountWritable(idx));
37
+ return {
38
+ type: "versioned",
39
+ transaction: vtx,
40
+ accounts,
41
+ writableAccounts
42
+ };
43
+ } catch (vError) {
44
+ throw new Error("Failed to deserialize transaction: " + (vError instanceof Error ? vError.message : vError), {
45
+ cause: vError
46
+ });
47
+ }
48
+ }
49
+ }
50
+
51
+ // solana/rpc/priority-fee-estimate/calc-fee.ts
52
+ var resolveMedian = (values) => {
53
+ if (values.length < 2) {
54
+ return 0;
55
+ }
56
+ const sortedRates = [...values].sort((a, b) => a - b);
57
+ const medianIndex = Math.floor(sortedRates.length / 2);
58
+ const medianArrValue = sortedRates[medianIndex];
59
+ const medianPrevValue = sortedRates[medianIndex - 1];
60
+ if (medianPrevValue === void 0 || medianArrValue === void 0) {
61
+ return 0;
62
+ }
63
+ const medianValue = sortedRates.length % 2 === 0 ? (medianPrevValue + medianArrValue) / 2 : medianArrValue;
64
+ return medianValue;
65
+ };
66
+
67
+ // solana/rpc/priority-fee-estimate/percentile.ts
68
+ var getPriorityFeeEstimate = async (connection, options) => {
69
+ const recentPrioritizationFee = await getRecentPrioritizationFee(connection, options);
70
+ const median = resolveMedian(recentPrioritizationFee.result.map((r) => r.prioritizationFee));
71
+ return { median: median * (1 + (options.safeAreaIncrease ?? 0.05)), data: recentPrioritizationFee };
72
+ };
73
+ var getRecentPrioritizationFee = async (connection, options) => {
74
+ const { accountsOrTx, percentile = 5e3 } = options;
75
+ return connection._rpcRequest(
76
+ "getRecentPrioritizationFees",
77
+ buildArgs(accountsOrTx, percentile)
78
+ );
79
+ };
80
+ var buildArgs = (accountsOrTx, percentile) => {
81
+ const accountsArray = accountsOrTx instanceof Array ? accountsOrTx.map((a) => a.toString()) : deserializeRawTransaction(accountsOrTx).writableAccounts.map((a) => a.toString());
82
+ return [
83
+ accountsArray,
84
+ {
85
+ percentile
86
+ }
87
+ ];
88
+ };
89
+
90
+ // solana/rpc/priority-fee-estimate/general.ts
91
+ var general_exports = {};
92
+ __export(general_exports, {
93
+ getPriorityFeeEstimate: () => getPriorityFeeEstimate2,
94
+ getRecentPrioritizationFee: () => getRecentPrioritizationFee2
95
+ });
96
+ var pk = (address) => {
97
+ return typeof address === "string" ? new web3_js.PublicKey(address) : address;
98
+ };
99
+
100
+ // solana/rpc/priority-fee-estimate/general.ts
101
+ var getPriorityFeeEstimate2 = async (connection, options) => {
102
+ const recentPrioritizationFee = await getRecentPrioritizationFee2(connection, options);
103
+ const median = resolveMedian(recentPrioritizationFee.map((r) => r.prioritizationFee));
104
+ return { median: median * (1 + (options.safeAreaIncrease ?? 0.05)), data: recentPrioritizationFee };
105
+ };
106
+ var getRecentPrioritizationFee2 = async (connection, options) => {
107
+ return connection.getRecentPrioritizationFees({ lockedWritableAccounts: buildArgs2(options.accountsOrTx)[0] });
108
+ };
109
+ var buildArgs2 = (accountsOrTx) => {
110
+ const accountsArray = accountsOrTx instanceof Array ? accountsOrTx.map(pk) : deserializeRawTransaction(accountsOrTx).writableAccounts;
111
+ return [accountsArray];
112
+ };
113
+
114
+ exports.priorityFeeEstimation = general_exports;
115
+ exports.priorityFeeEstimationPercentile = percentile_exports;
116
+ //# sourceMappingURL=index.cjs.map
117
+ //# sourceMappingURL=index.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../../../solana/rpc/priority-fee-estimate/percentile.ts","../../../../solana/deserialize-raw-transaction.ts","../../../../solana/rpc/priority-fee-estimate/calc-fee.ts","../../../../solana/rpc/priority-fee-estimate/general.ts","../../../../solana/public-key.ts"],"names":["Buffer","Transaction","VersionedTransaction","getPriorityFeeEstimate","getRecentPrioritizationFee","PublicKey","buildArgs"],"mappings":";;;;;;;;;;;;AAAA,IAAA,kBAAA,GAAA;AAAA,QAAA,CAAA,kBAAA,EAAA;AAAA,EAAA,sBAAA,EAAA,MAAA,sBAAA;AAAA,EAAA,0BAAA,EAAA,MAAA;AAAA,CAAA,CAAA;ACOO,SAAS,0BAA0B,YAAsB,EAAA;AAC9D,EAAA,MAAM,QAAWA,GAAAA,aAAAA,CAAO,IAAK,CAAA,YAAA,EAAc,QAAQ,CAAA;AACnD,EAAI,IAAA;AACF,IAAM,MAAA,EAAA,GAAKC,mBAAY,CAAA,IAAA,CAAK,QAAQ,CAAA;AACpC,IAAM,MAAA,OAAA,GAAU,GAAG,cAAe,EAAA;AAClC,IAAA,MAAM,WAAW,OAAQ,CAAA,WAAA;AACzB,IAAM,MAAA,gBAAA,GAAmB,SAAS,MAAO,CAAA,CAAC,GAAG,GAAQ,KAAA,OAAA,C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ction } from \"../../deserialize-raw-transaction.js\";\nimport type { GetPriorityFeeEstimateOptions } from \"../../types.js\";\nimport { resolveMedian } from \"./calc-fee.js\";\n\ntype RpcRequest = (methodName: string, args: Array<any> | ReadonlyArray<any>) => Promise<any>;\ninterface RecentPrioritizationFee {\n result: Array<{ prioritizationFee: number; slot: number }>;\n}\n\nexport const getPriorityFeeEstimate = async (connection: Connection, options: GetPriorityFeeEstimateOptions) => {\n const recentPrioritizationFee = await getRecentPrioritizationFee(connection, options);\n const median = resolveMedian(recentPrioritizationFee.result.map((r) => r.prioritizationFee));\n return { median: median * (1 + (options.safeAreaIncrease ?? 0.05)), data: recentPrioritizationFee };\n};\n\n/**\n * If an RPC of use supports percentile value, aka {@link https://docs.triton.one/chains/solana/improved-priority-fees-api}\n * @param connection - The connection to the RPC\n * @param options - The options for the RPC\n * @returns The priority fee estimate\n */\nexport const getRecentPrioritizationFee = async (\n connection: Connection,\n options: Pick<GetPriorityFeeEstimateOptions, \"accountsOrTx\" | \"percentile\">,\n): Promise<RecentPrioritizationFee> => {\n const { accountsOrTx, percentile = 5000 } = options;\n\n return (connection as unknown as { _rpcRequest: RpcRequest })._rpcRequest(\n \"getRecentPrioritizationFees\",\n buildArgs(accountsOrTx, percentile),\n ) as Promise<RecentPrioritizationFee>;\n};\n\nconst buildArgs = (accountsOrTx: (string | PublicKey)[] | string, percentile: number) => {\n const accountsArray =\n accountsOrTx instanceof Array\n ? accountsOrTx.map((a) => a.toString())\n : deserializeRawTransaction(accountsOrTx).writableAccounts.map((a) => a.toString());\n return [\n accountsArray,\n {\n percentile,\n },\n ] as const;\n};\n","import { Transaction, VersionedTransaction, type PublicKey } from \"@solana/web3.js\";\nimport { Buffer } from \"buffer\";\n\ninterface TransactionAccountsProvider {\n accountKeys: PublicKey[];\n}\n\nexport function deserializeRawTransaction(serializedTx: string) {\n const txBuffer = Buffer.from(serializedTx, \"base64\");\n try {\n const tx = Transaction.from(txBuffer);\n const message = tx.compileMessage();\n const accounts = message.accountKeys;\n const writableAccounts = accounts.filter((_, idx) => message.isAccountWritable(idx));\n return {\n type: \"legacy\",\n transaction: tx,\n accounts,\n writableAccounts,\n };\n } catch (error) {\n try {\n const vtx = VersionedTransaction.deserialize(txBuffer);\n const message = vtx.message;\n const accounts =\n \"staticAccountKeys\" in message\n ? message.staticAccountKeys\n : (message as unknown as TransactionAccountsProvider).accountKeys;\n\n const writableAccounts = accounts.filter((_, idx) => message.isAccountWritable(idx));\n return {\n type: \"versioned\",\n transaction: vtx,\n accounts,\n writableAccounts,\n };\n } catch (vError) {\n throw new Error(\"Failed to deserialize transaction: \" + (vError instanceof Error ? vError.message : vError), {\n cause: vError,\n });\n }\n }\n}\n","export const resolveMedian = (values: number[]) => {\n if (values.length < 2) {\n return 0;\n }\n\n const sortedRates = [...values].sort((a, b) => a - b);\n const medianIndex = Math.floor(sortedRates.length / 2);\n const medianArrValue = sortedRates[medianIndex];\n const medianPrevValue = sortedRates[medianIndex - 1];\n\n if (medianPrevValue === undefined || medianArrValue === undefined) {\n return 0;\n }\n\n const medianValue = sortedRates.length % 2 === 0 ? (medianPrevValue + medianArrValue) / 2 : medianArrValue;\n\n return medianValue;\n};\n","import type { Connection, PublicKey } from \"@solana/web3.js\";\n\nimport { deserializeRawTransaction } from \"../../deserialize-raw-transaction.js\";\nimport { pk } from \"../../public-key.js\";\nimport type { GetPriorityFeeEstimateOptions } from \"../../types.js\";\nimport { resolveMedian } from \"./calc-fee.js\";\n\nexport const getPriorityFeeEstimate = async (connection: Connection, options: GetPriorityFeeEstimateOptions) => {\n const recentPrioritizationFee = await getRecentPrioritizationFee(connection, options);\n const median = resolveMedian(recentPrioritizationFee.map((r) => r.prioritizationFee));\n return { median: median * (1 + (options.safeAreaIncrease ?? 0.05)), data: recentPrioritizationFee };\n};\n\nexport const getRecentPrioritizationFee = async (\n connection: Connection,\n options: Pick<GetPriorityFeeEstimateOptions, \"accountsOrTx\">,\n) => {\n return connection.getRecentPrioritizationFees({ lockedWritableAccounts: buildArgs(options.accountsOrTx)[0] });\n};\n\nconst buildArgs = (accountsOrTx: (string | PublicKey)[] | string) => {\n const accountsArray =\n accountsOrTx instanceof Array ? accountsOrTx.map(pk) : deserializeRawTransaction(accountsOrTx).writableAccounts;\n return [accountsArray] as const;\n};\n","import { PublicKey } from \"@solana/web3.js\";\n\n/**\n * Converts a string or PublicKey to a PublicKey object.\n * @param address - The input address as a string or PublicKey.\n * @returns The PublicKey object.\n */\nexport const pk = (address: string | PublicKey): PublicKey => {\n return typeof address === \"string\" ? new PublicKey(address) : address;\n};\n"]}
@@ -0,0 +1,40 @@
1
+ import * as _solana_web3_js from '@solana/web3.js';
2
+ import { Connection } from '@solana/web3.js';
3
+ import { G as GetPriorityFeeEstimateOptions } from '../../types-DGCX8JLm.cjs';
4
+ import 'p-queue';
5
+
6
+ interface RecentPrioritizationFee {
7
+ result: Array<{
8
+ prioritizationFee: number;
9
+ slot: number;
10
+ }>;
11
+ }
12
+ declare const getPriorityFeeEstimate$1: (connection: Connection, options: GetPriorityFeeEstimateOptions) => Promise<{
13
+ median: number;
14
+ data: RecentPrioritizationFee;
15
+ }>;
16
+ /**
17
+ * If an RPC of use supports percentile value, aka {@link https://docs.triton.one/chains/solana/improved-priority-fees-api}
18
+ * @param connection - The connection to the RPC
19
+ * @param options - The options for the RPC
20
+ * @returns The priority fee estimate
21
+ */
22
+ declare const getRecentPrioritizationFee$1: (connection: Connection, options: Pick<GetPriorityFeeEstimateOptions, "accountsOrTx" | "percentile">) => Promise<RecentPrioritizationFee>;
23
+
24
+ declare namespace percentile {
25
+ export { getPriorityFeeEstimate$1 as getPriorityFeeEstimate, getRecentPrioritizationFee$1 as getRecentPrioritizationFee };
26
+ }
27
+
28
+ declare const getPriorityFeeEstimate: (connection: Connection, options: GetPriorityFeeEstimateOptions) => Promise<{
29
+ median: number;
30
+ data: _solana_web3_js.RecentPrioritizationFees[];
31
+ }>;
32
+ declare const getRecentPrioritizationFee: (connection: Connection, options: Pick<GetPriorityFeeEstimateOptions, "accountsOrTx">) => Promise<_solana_web3_js.RecentPrioritizationFees[]>;
33
+
34
+ declare const general_getPriorityFeeEstimate: typeof getPriorityFeeEstimate;
35
+ declare const general_getRecentPrioritizationFee: typeof getRecentPrioritizationFee;
36
+ declare namespace general {
37
+ export { general_getPriorityFeeEstimate as getPriorityFeeEstimate, general_getRecentPrioritizationFee as getRecentPrioritizationFee };
38
+ }
39
+
40
+ export { general as priorityFeeEstimation, percentile as priorityFeeEstimationPercentile };
@@ -0,0 +1,73 @@
1
+ import { PublicKey, AccountInfo, BlockhashWithExpiryBlockHeight, Context, Commitment } from '@solana/web3.js';
2
+ import PQueue from 'p-queue';
3
+
4
+ type ComputePriceEstimate = (tx: string | (string | PublicKey)[]) => Promise<number>;
5
+ interface ITransactionSolanaExt {
6
+ computePrice?: number | ComputePriceEstimate;
7
+ computeLimit?: number;
8
+ }
9
+ interface IInteractSolanaExt extends ITransactionSolanaExt {
10
+ invoker: {
11
+ publicKey: string | PublicKey | null;
12
+ };
13
+ }
14
+ interface Account {
15
+ pubkey: PublicKey;
16
+ account: AccountInfo<Buffer>;
17
+ }
18
+ interface CheckAssociatedTokenAccountsData {
19
+ sender: PublicKey;
20
+ recipient: PublicKey;
21
+ partner: PublicKey;
22
+ streamflowTreasury: PublicKey;
23
+ mint: PublicKey;
24
+ }
25
+ interface AtaParams {
26
+ mint: PublicKey;
27
+ owner: PublicKey;
28
+ programId?: PublicKey;
29
+ }
30
+ interface ConfirmationParams {
31
+ hash: BlockhashWithExpiryBlockHeight;
32
+ context: Context;
33
+ commitment?: Commitment;
34
+ }
35
+ interface ThrottleParams {
36
+ sendRate?: number;
37
+ sendThrottler?: PQueue;
38
+ waitBeforeConfirming?: number | undefined;
39
+ }
40
+ interface IProgramAccount<T> {
41
+ publicKey: PublicKey;
42
+ account: T;
43
+ }
44
+ declare class TransactionFailedError extends Error {
45
+ constructor(m: string);
46
+ }
47
+ /**
48
+ * @interface GetPriorityFeeEstimateOptions - The options for the priority fee estimate
49
+ * @property accountsOrTx - The accounts or transaction to get the priority fee estimate for.
50
+ * @property percentile - The percentile of the priority fee estimate to return.
51
+ * @property safeAreaIncrease - The safe area increase to apply to the priority fee estimate.
52
+ */
53
+ interface GetPriorityFeeEstimateOptions {
54
+ /**
55
+ * The accounts or transaction to get the priority fee estimate for.
56
+ * String is a serialized base64 transaction.
57
+ * Array is interpreted as an array of public keys in string format or as PublicKey instances.
58
+ */
59
+ accountsOrTx: (string | PublicKey)[] | string;
60
+ /**
61
+ * The percentile of the priority fee estimate to return.
62
+ * [0, 10000] for Triton RPC signature
63
+ * Default: 5000
64
+ */
65
+ percentile?: number;
66
+ /**
67
+ * The safe area increase to apply to the priority fee estimate.
68
+ * Default: 0.05 = 5%
69
+ */
70
+ safeAreaIncrease?: number;
71
+ }
72
+
73
+ export { type Account as A, type ConfirmationParams as C, type GetPriorityFeeEstimateOptions as G, type ITransactionSolanaExt as I, type ThrottleParams as T, type AtaParams as a, type ComputePriceEstimate as b, type IInteractSolanaExt as c, type CheckAssociatedTokenAccountsData as d, type IProgramAccount as e, TransactionFailedError as f };
@@ -1,8 +1,10 @@
1
- import { PublicKey, MemcmpFilter, Connection, TransactionInstruction, AccountInfo, BlockhashWithExpiryBlockHeight, Context, Commitment, Keypair, Transaction, VersionedTransaction, RpcResponseAndContext, SimulatedTransactionResponse, SignatureStatus } from '@solana/web3.js';
1
+ import { PublicKey, MemcmpFilter, Connection, TransactionInstruction, Keypair, Transaction, VersionedTransaction, Commitment, BlockhashWithExpiryBlockHeight, Context, RpcResponseAndContext, SimulatedTransactionResponse, SignatureStatus, AccountInfo } from '@solana/web3.js';
2
2
  import BN from 'bn.js';
3
- import PQueue from 'p-queue';
3
+ import { A as Account, C as ConfirmationParams, T as ThrottleParams, a as AtaParams, I as ITransactionSolanaExt, b as ComputePriceEstimate, c as IInteractSolanaExt } from '../types-DGCX8JLm.js';
4
+ export { d as CheckAssociatedTokenAccountsData, G as GetPriorityFeeEstimateOptions, e as IProgramAccount, f as TransactionFailedError } from '../types-DGCX8JLm.js';
4
5
  import { Mint } from '@solana/spl-token';
5
6
  import { SignerWalletAdapter } from '@solana/wallet-adapter-base';
7
+ import PQueue from 'p-queue';
6
8
 
7
9
  declare const getFilters: <T extends Record<string, number | PublicKey>>(criteria: T, byteOffsets: Record<keyof T, number>) => MemcmpFilter[];
8
10
 
@@ -15,44 +17,6 @@ declare const prepareWrappedAccount: (connection: Connection, senderAddress: Pub
15
17
  */
16
18
  declare const pk: (address: string | PublicKey) => PublicKey;
17
19
 
18
- interface ITransactionSolanaExt {
19
- computePrice?: number;
20
- computeLimit?: number;
21
- }
22
- interface Account {
23
- pubkey: PublicKey;
24
- account: AccountInfo<Buffer>;
25
- }
26
- interface CheckAssociatedTokenAccountsData {
27
- sender: PublicKey;
28
- recipient: PublicKey;
29
- partner: PublicKey;
30
- streamflowTreasury: PublicKey;
31
- mint: PublicKey;
32
- }
33
- interface AtaParams {
34
- mint: PublicKey;
35
- owner: PublicKey;
36
- programId?: PublicKey;
37
- }
38
- interface ConfirmationParams {
39
- hash: BlockhashWithExpiryBlockHeight;
40
- context: Context;
41
- commitment?: Commitment;
42
- }
43
- interface ThrottleParams {
44
- sendRate?: number;
45
- sendThrottler?: PQueue;
46
- waitBeforeConfirming?: number | undefined;
47
- }
48
- interface IProgramAccount<T> {
49
- publicKey: PublicKey;
50
- account: T;
51
- }
52
- declare class TransactionFailedError extends Error {
53
- constructor(m: string);
54
- }
55
-
56
20
  declare const buildSendThrottler: (sendRate: number, sendInterval?: number) => PQueue;
57
21
  /**
58
22
  * Wrapper function for Solana web3 getProgramAccounts with slightly better call interface
@@ -90,11 +54,12 @@ declare function isTransactionVersioned(tx: Transaction | VersionedTransaction):
90
54
  * @param partialSigners - optional signers that will be used to partially sign a Transaction
91
55
  * @returns Transaction and Blockhash
92
56
  */
93
- declare function prepareTransaction(connection: Connection, ixs: TransactionInstruction[], payer: PublicKey | undefined | null, commitment?: Commitment, ...partialSigners: (Keypair | undefined)[]): Promise<{
57
+ declare function prepareTransaction(connection: Connection, ixs: TransactionInstruction[], payer: PublicKey | undefined | null, commitment?: Commitment, partialSigners?: (Keypair | undefined)[]): Promise<{
94
58
  tx: VersionedTransaction;
95
59
  hash: BlockhashWithExpiryBlockHeight;
96
60
  context: Context;
97
61
  }>;
62
+ declare function createVersionedTransaction(ixs: TransactionInstruction[], payer: PublicKey | undefined | null, recentBlockhash: BlockhashWithExpiryBlockHeight["blockhash"], partialSigners?: (Keypair | undefined)[]): VersionedTransaction;
98
63
  declare function signTransaction<T extends Transaction | VersionedTransaction>(invoker: Keypair | SignerWalletAdapter, tx: T): Promise<T>;
99
64
  /**
100
65
  * Signs, sends and confirms Transaction
@@ -236,4 +201,20 @@ declare function getMintAndProgram(connection: Connection, address: PublicKey, c
236
201
  */
237
202
  declare function getMultipleAccountsInfoBatched(connection: Connection, pubKeys: PublicKey[], commitment?: Commitment): Promise<(AccountInfo<Buffer> | null)[]>;
238
203
 
239
- export { type Account, type AtaParams, type CheckAssociatedTokenAccountsData, type ConfirmationParams, type IProgramAccount, type ITransactionSolanaExt, type ThrottleParams, TransactionFailedError, ata, ataBatchExist, buildSendThrottler, checkOrCreateAtaBatch, confirmAndEnsureTransaction, createAtaBatch, enrichAtaParams, executeMultipleTransactions, executeTransaction, generateCreateAtaBatchTx, getFilters, getMintAndProgram, getMultipleAccountsInfoBatched, getProgramAccounts, isSignerKeypair, isSignerWallet, isTransactionVersioned, pk, prepareBaseInstructions, prepareTransaction, prepareWrappedAccount, sendAndConfirmTransaction, signAndExecuteTransaction, signTransaction, simulateTransaction };
204
+ 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>;
205
+ declare function createAndEstimateTransaction<CreateFn extends (extParams: IInteractSolanaExt) => Promise<TransactionInstruction[]>>(createFn: CreateFn, extParams: IInteractSolanaExt): Promise<Awaited<ReturnType<CreateFn>>>;
206
+ declare function createAndEstimateTransaction<CreateFn extends (extParams: IInteractSolanaExt) => Promise<any>>(createFn: CreateFn, extParams: IInteractSolanaExt, select: (result: Awaited<ReturnType<CreateFn>>) => TransactionInstruction[]): Promise<Awaited<ReturnType<CreateFn>>>;
207
+
208
+ declare function deserializeRawTransaction(serializedTx: string): {
209
+ type: string;
210
+ transaction: Transaction;
211
+ accounts: PublicKey[];
212
+ writableAccounts: PublicKey[];
213
+ } | {
214
+ type: string;
215
+ transaction: VersionedTransaction;
216
+ accounts: PublicKey[];
217
+ writableAccounts: PublicKey[];
218
+ };
219
+
220
+ export { Account, AtaParams, ComputePriceEstimate, ConfirmationParams, IInteractSolanaExt, ITransactionSolanaExt, ThrottleParams, 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 };
@@ -1,7 +1,8 @@
1
1
  import { getAssociatedTokenAddress, NATIVE_MINT, createAssociatedTokenAccountInstruction, createSyncNativeInstruction, TOKEN_PROGRAM_ID, TOKEN_2022_PROGRAM_ID, unpackMint } from '@solana/spl-token';
2
- import { SystemProgram, PublicKey, Keypair, TransactionMessage, VersionedTransaction, SendTransactionError, ComputeBudgetProgram } from '@solana/web3.js';
2
+ import { SystemProgram, PublicKey, Keypair, TransactionMessage, VersionedTransaction, SendTransactionError, ComputeBudgetProgram, Transaction } from '@solana/web3.js';
3
3
  import bs58 from 'bs58';
4
4
  import 'bn.js';
5
+ import { Buffer as Buffer$1 } from 'buffer';
5
6
 
6
7
  var __create = Object.create;
7
8
  var __defProp = Object.defineProperty;
@@ -51,12 +52,12 @@ var __privateWrapper = (obj, member, setter, getter) => ({
51
52
  var require_eventemitter3 = __commonJS({
52
53
  "../../node_modules/.pnpm/eventemitter3@5.0.1/node_modules/eventemitter3/index.js"(exports, module) {
53
54
  var has = Object.prototype.hasOwnProperty;
54
- var prefix = "~";
55
+ var prefix2 = "~";
55
56
  function Events() {
56
57
  }
57
58
  if (Object.create) {
58
59
  Events.prototype = /* @__PURE__ */ Object.create(null);
59
- if (!new Events().__proto__) prefix = false;
60
+ if (!new Events().__proto__) prefix2 = false;
60
61
  }
61
62
  function EE(fn, context, once) {
62
63
  this.fn = fn;
@@ -67,7 +68,7 @@ var require_eventemitter3 = __commonJS({
67
68
  if (typeof fn !== "function") {
68
69
  throw new TypeError("The listener must be a function");
69
70
  }
70
- var listener = new EE(fn, context || emitter, once), evt = prefix ? prefix + event : event;
71
+ var listener = new EE(fn, context || emitter, once), evt = prefix2 ? prefix2 + event : event;
71
72
  if (!emitter._events[evt]) emitter._events[evt] = listener, emitter._eventsCount++;
72
73
  else if (!emitter._events[evt].fn) emitter._events[evt].push(listener);
73
74
  else emitter._events[evt] = [emitter._events[evt], listener];
@@ -85,7 +86,7 @@ var require_eventemitter3 = __commonJS({
85
86
  var names = [], events, name;
86
87
  if (this._eventsCount === 0) return names;
87
88
  for (name in events = this._events) {
88
- if (has.call(events, name)) names.push(prefix ? name.slice(1) : name);
89
+ if (has.call(events, name)) names.push(prefix2 ? name.slice(1) : name);
89
90
  }
90
91
  if (Object.getOwnPropertySymbols) {
91
92
  return names.concat(Object.getOwnPropertySymbols(events));
@@ -93,7 +94,7 @@ var require_eventemitter3 = __commonJS({
93
94
  return names;
94
95
  };
95
96
  EventEmitter2.prototype.listeners = function listeners(event) {
96
- var evt = prefix ? prefix + event : event, handlers = this._events[evt];
97
+ var evt = prefix2 ? prefix2 + event : event, handlers = this._events[evt];
97
98
  if (!handlers) return [];
98
99
  if (handlers.fn) return [handlers.fn];
99
100
  for (var i = 0, l = handlers.length, ee = new Array(l); i < l; i++) {
@@ -102,13 +103,13 @@ var require_eventemitter3 = __commonJS({
102
103
  return ee;
103
104
  };
104
105
  EventEmitter2.prototype.listenerCount = function listenerCount(event) {
105
- var evt = prefix ? prefix + event : event, listeners = this._events[evt];
106
+ var evt = prefix2 ? prefix2 + event : event, listeners = this._events[evt];
106
107
  if (!listeners) return 0;
107
108
  if (listeners.fn) return 1;
108
109
  return listeners.length;
109
110
  };
110
111
  EventEmitter2.prototype.emit = function emit(event, a1, a2, a3, a4, a5) {
111
- var evt = prefix ? prefix + event : event;
112
+ var evt = prefix2 ? prefix2 + event : event;
112
113
  if (!this._events[evt]) return false;
113
114
  var listeners = this._events[evt], len = arguments.length, args, i;
114
115
  if (listeners.fn) {
@@ -165,7 +166,7 @@ var require_eventemitter3 = __commonJS({
165
166
  return addListener(this, event, fn, context, true);
166
167
  };
167
168
  EventEmitter2.prototype.removeListener = function removeListener(event, fn, context, once) {
168
- var evt = prefix ? prefix + event : event;
169
+ var evt = prefix2 ? prefix2 + event : event;
169
170
  if (!this._events[evt]) return this;
170
171
  if (!fn) {
171
172
  clearEvent(this, evt);
@@ -190,7 +191,7 @@ var require_eventemitter3 = __commonJS({
190
191
  EventEmitter2.prototype.removeAllListeners = function removeAllListeners(event) {
191
192
  var evt;
192
193
  if (event) {
193
- evt = prefix ? prefix + event : event;
194
+ evt = prefix2 ? prefix2 + event : event;
194
195
  if (this._events[evt]) clearEvent(this, evt);
195
196
  } else {
196
197
  this._events = new Events();
@@ -200,7 +201,7 @@ var require_eventemitter3 = __commonJS({
200
201
  };
201
202
  EventEmitter2.prototype.off = EventEmitter2.prototype.removeListener;
202
203
  EventEmitter2.prototype.addListener = EventEmitter2.prototype.on;
203
- EventEmitter2.prefixed = prefix;
204
+ EventEmitter2.prefixed = prefix2;
204
205
  EventEmitter2.EventEmitter = EventEmitter2;
205
206
  if ("undefined" !== typeof module) {
206
207
  module.exports = EventEmitter2;
@@ -705,6 +706,17 @@ function sleep(ms) {
705
706
  return new Promise((resolve) => setTimeout(resolve, ms));
706
707
  }
707
708
 
709
+ // lib/assertions.ts
710
+ var prefix = "Assertion failed";
711
+ var invariant = (condition, message) => {
712
+ if (condition) {
713
+ return;
714
+ }
715
+ const provided = typeof message === "function" ? message() : message;
716
+ const value = provided ? `${prefix}: ${provided}` : prefix;
717
+ throw new Error(value);
718
+ };
719
+
708
720
  // solana/utils.ts
709
721
  var SIMULATE_TRIES = 3;
710
722
  var buildSendThrottler = (sendRate, sendInterval = 1e3) => {
@@ -732,20 +744,30 @@ function isSignerKeypair(walletOrKeypair) {
732
744
  function isTransactionVersioned(tx) {
733
745
  return "message" in tx;
734
746
  }
735
- async function prepareTransaction(connection, ixs, payer, commitment, ...partialSigners) {
747
+ async function prepareTransaction(connection, ixs, payer, commitment, partialSigners) {
736
748
  if (!payer) {
737
749
  throw new Error("Payer public key is not provided!");
738
750
  }
739
751
  const { value: hash, context } = await connection.getLatestBlockhashAndContext(commitment);
752
+ return {
753
+ tx: createVersionedTransaction(ixs, payer, hash.blockhash, partialSigners),
754
+ hash,
755
+ context
756
+ };
757
+ }
758
+ function createVersionedTransaction(ixs, payer, recentBlockhash, partialSigners) {
759
+ invariant(payer, "Payer public key is not provided!");
740
760
  const messageV0 = new TransactionMessage({
741
761
  payerKey: payer,
742
- recentBlockhash: hash.blockhash,
762
+ recentBlockhash,
743
763
  instructions: ixs
744
764
  }).compileToV0Message();
745
765
  const tx = new VersionedTransaction(messageV0);
746
- const signers = partialSigners.filter((item) => !!item);
747
- tx.sign(signers);
748
- return { tx, context, hash };
766
+ const signers = partialSigners?.filter((item) => !!item) ?? void 0;
767
+ if (signers) {
768
+ tx.sign(signers);
769
+ }
770
+ return tx;
749
771
  }
750
772
  async function signTransaction(invoker, tx) {
751
773
  let signedTx;
@@ -937,13 +959,7 @@ async function generateCreateAtaBatchTx(connection, payer, paramsBatch, commitme
937
959
  })
938
960
  );
939
961
  const { value: hash, context } = await connection.getLatestBlockhashAndContext({ commitment });
940
- const messageV0 = new TransactionMessage({
941
- payerKey: payer,
942
- recentBlockhash: hash.blockhash,
943
- instructions: ixs
944
- }).compileToV0Message();
945
- const tx = new VersionedTransaction(messageV0);
946
- return { tx, hash, context };
962
+ return { tx: createVersionedTransaction(ixs, payer, hash.blockhash), hash, context };
947
963
  }
948
964
  async function createAtaBatch(connection, invoker, paramsBatch, commitment, rate) {
949
965
  const { tx, hash, context } = await generateCreateAtaBatchTx(
@@ -973,7 +989,7 @@ async function checkOrCreateAtaBatch(connection, owners, mint, invoker, programI
973
989
  }
974
990
  function prepareBaseInstructions(connection, { computePrice, computeLimit }) {
975
991
  const ixs = [];
976
- if (computePrice) {
992
+ if (computePrice && typeof computePrice === "number") {
977
993
  ixs.push(ComputeBudgetProgram.setComputeUnitPrice({ microLamports: computePrice }));
978
994
  }
979
995
  if (computeLimit) {
@@ -1003,6 +1019,68 @@ async function getMultipleAccountsInfoBatched(connection, pubKeys, commitment) {
1003
1019
  return results.flat();
1004
1020
  }
1005
1021
 
1006
- export { TransactionFailedError, ata, ataBatchExist, buildSendThrottler, checkOrCreateAtaBatch, confirmAndEnsureTransaction, createAtaBatch, enrichAtaParams, executeMultipleTransactions, executeTransaction, generateCreateAtaBatchTx, getFilters, getMintAndProgram, getMultipleAccountsInfoBatched, getProgramAccounts, isSignerKeypair, isSignerWallet, isTransactionVersioned, pk, prepareBaseInstructions, prepareTransaction, prepareWrappedAccount, sendAndConfirmTransaction, signAndExecuteTransaction, signTransaction, simulateTransaction };
1022
+ // solana/lib/estimate.ts
1023
+ async function estimateComputeUnitPrice(estimate, ixs, payer, recentBlockhash, partialSigners) {
1024
+ const tx = createVersionedTransaction(
1025
+ ixs,
1026
+ payer,
1027
+ recentBlockhash ?? "11111111111111111111111111111111",
1028
+ partialSigners
1029
+ );
1030
+ return estimate(Buffer.from(tx.serialize()).toString("base64"));
1031
+ }
1032
+ async function createAndEstimateTransaction(createFn, extParams, select) {
1033
+ select = select ?? ((value) => value);
1034
+ const createResult = await createFn(extParams);
1035
+ const prepareIxs = select(createResult);
1036
+ const priorityFee = extParams.computePrice;
1037
+ if (priorityFee === void 0 || typeof priorityFee === "number") {
1038
+ return createResult;
1039
+ }
1040
+ const invoker = extParams.invoker.publicKey;
1041
+ invariant(invoker, "Invoker's PublicKey is not available, check passed wallet adapter!");
1042
+ const estimatedComputeUnitPrice = typeof priorityFee === "function" ? await estimateComputeUnitPrice(priorityFee, prepareIxs, pk(invoker)) : (
1043
+ // unachievable because we don't execute estimation for constant or undefined priority fee
1044
+ priorityFee
1045
+ );
1046
+ return createFn({
1047
+ ...extParams,
1048
+ computePrice: estimatedComputeUnitPrice
1049
+ });
1050
+ }
1051
+ function deserializeRawTransaction(serializedTx) {
1052
+ const txBuffer = Buffer$1.from(serializedTx, "base64");
1053
+ try {
1054
+ const tx = Transaction.from(txBuffer);
1055
+ const message = tx.compileMessage();
1056
+ const accounts = message.accountKeys;
1057
+ const writableAccounts = accounts.filter((_, idx) => message.isAccountWritable(idx));
1058
+ return {
1059
+ type: "legacy",
1060
+ transaction: tx,
1061
+ accounts,
1062
+ writableAccounts
1063
+ };
1064
+ } catch (error) {
1065
+ try {
1066
+ const vtx = VersionedTransaction.deserialize(txBuffer);
1067
+ const message = vtx.message;
1068
+ const accounts = "staticAccountKeys" in message ? message.staticAccountKeys : message.accountKeys;
1069
+ const writableAccounts = accounts.filter((_, idx) => message.isAccountWritable(idx));
1070
+ return {
1071
+ type: "versioned",
1072
+ transaction: vtx,
1073
+ accounts,
1074
+ writableAccounts
1075
+ };
1076
+ } catch (vError) {
1077
+ throw new Error("Failed to deserialize transaction: " + (vError instanceof Error ? vError.message : vError), {
1078
+ cause: vError
1079
+ });
1080
+ }
1081
+ }
1082
+ }
1083
+
1084
+ export { 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 };
1007
1085
  //# sourceMappingURL=index.js.map
1008
1086
  //# sourceMappingURL=index.js.map