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

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.
@@ -1,10 +1,8 @@
1
- import { PublicKey, MemcmpFilter, Connection, TransactionInstruction, Keypair, Transaction, VersionedTransaction, Commitment, BlockhashWithExpiryBlockHeight, Context, RpcResponseAndContext, SimulatedTransactionResponse, SignatureStatus, AccountInfo } from '@solana/web3.js';
1
+ import { PublicKey, MemcmpFilter, Connection, TransactionInstruction, AccountInfo, BlockhashWithExpiryBlockHeight, Context, Commitment, Keypair, Transaction, VersionedTransaction, RpcResponseAndContext, SimulatedTransactionResponse, SignatureStatus } from '@solana/web3.js';
2
2
  import BN from 'bn.js';
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';
3
+ import PQueue from 'p-queue';
5
4
  import { Mint } from '@solana/spl-token';
6
5
  import { SignerWalletAdapter } from '@solana/wallet-adapter-base';
7
- import PQueue from 'p-queue';
8
6
 
9
7
  declare const getFilters: <T extends Record<string, number | PublicKey>>(criteria: T, byteOffsets: Record<keyof T, number>) => MemcmpFilter[];
10
8
 
@@ -17,6 +15,44 @@ declare const prepareWrappedAccount: (connection: Connection, senderAddress: Pub
17
15
  */
18
16
  declare const pk: (address: string | PublicKey) => PublicKey;
19
17
 
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
+
20
56
  declare const buildSendThrottler: (sendRate: number, sendInterval?: number) => PQueue;
21
57
  /**
22
58
  * Wrapper function for Solana web3 getProgramAccounts with slightly better call interface
@@ -54,12 +90,11 @@ declare function isTransactionVersioned(tx: Transaction | VersionedTransaction):
54
90
  * @param partialSigners - optional signers that will be used to partially sign a Transaction
55
91
  * @returns Transaction and Blockhash
56
92
  */
57
- declare function prepareTransaction(connection: Connection, ixs: TransactionInstruction[], payer: PublicKey | undefined | null, commitment?: Commitment, partialSigners?: (Keypair | undefined)[]): Promise<{
93
+ declare function prepareTransaction(connection: Connection, ixs: TransactionInstruction[], payer: PublicKey | undefined | null, commitment?: Commitment, ...partialSigners: (Keypair | undefined)[]): Promise<{
58
94
  tx: VersionedTransaction;
59
95
  hash: BlockhashWithExpiryBlockHeight;
60
96
  context: Context;
61
97
  }>;
62
- declare function createVersionedTransaction(ixs: TransactionInstruction[], payer: PublicKey | undefined | null, recentBlockhash: BlockhashWithExpiryBlockHeight["blockhash"], partialSigners?: (Keypair | undefined)[]): VersionedTransaction;
63
98
  declare function signTransaction<T extends Transaction | VersionedTransaction>(invoker: Keypair | SignerWalletAdapter, tx: T): Promise<T>;
64
99
  /**
65
100
  * Signs, sends and confirms Transaction
@@ -201,20 +236,4 @@ declare function getMintAndProgram(connection: Connection, address: PublicKey, c
201
236
  */
202
237
  declare function getMultipleAccountsInfoBatched(connection: Connection, pubKeys: PublicKey[], commitment?: Commitment): Promise<(AccountInfo<Buffer> | null)[]>;
203
238
 
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 };
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 };
@@ -1,8 +1,7 @@
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, Transaction } from '@solana/web3.js';
2
+ import { SystemProgram, PublicKey, Keypair, TransactionMessage, VersionedTransaction, SendTransactionError, ComputeBudgetProgram } from '@solana/web3.js';
3
3
  import bs58 from 'bs58';
4
4
  import 'bn.js';
5
- import { Buffer as Buffer$1 } from 'buffer';
6
5
 
7
6
  var __create = Object.create;
8
7
  var __defProp = Object.defineProperty;
@@ -52,12 +51,12 @@ var __privateWrapper = (obj, member, setter, getter) => ({
52
51
  var require_eventemitter3 = __commonJS({
53
52
  "../../node_modules/.pnpm/eventemitter3@5.0.1/node_modules/eventemitter3/index.js"(exports, module) {
54
53
  var has = Object.prototype.hasOwnProperty;
55
- var prefix2 = "~";
54
+ var prefix = "~";
56
55
  function Events() {
57
56
  }
58
57
  if (Object.create) {
59
58
  Events.prototype = /* @__PURE__ */ Object.create(null);
60
- if (!new Events().__proto__) prefix2 = false;
59
+ if (!new Events().__proto__) prefix = false;
61
60
  }
62
61
  function EE(fn, context, once) {
63
62
  this.fn = fn;
@@ -68,7 +67,7 @@ var require_eventemitter3 = __commonJS({
68
67
  if (typeof fn !== "function") {
69
68
  throw new TypeError("The listener must be a function");
70
69
  }
71
- var listener = new EE(fn, context || emitter, once), evt = prefix2 ? prefix2 + event : event;
70
+ var listener = new EE(fn, context || emitter, once), evt = prefix ? prefix + event : event;
72
71
  if (!emitter._events[evt]) emitter._events[evt] = listener, emitter._eventsCount++;
73
72
  else if (!emitter._events[evt].fn) emitter._events[evt].push(listener);
74
73
  else emitter._events[evt] = [emitter._events[evt], listener];
@@ -86,7 +85,7 @@ var require_eventemitter3 = __commonJS({
86
85
  var names = [], events, name;
87
86
  if (this._eventsCount === 0) return names;
88
87
  for (name in events = this._events) {
89
- if (has.call(events, name)) names.push(prefix2 ? name.slice(1) : name);
88
+ if (has.call(events, name)) names.push(prefix ? name.slice(1) : name);
90
89
  }
91
90
  if (Object.getOwnPropertySymbols) {
92
91
  return names.concat(Object.getOwnPropertySymbols(events));
@@ -94,7 +93,7 @@ var require_eventemitter3 = __commonJS({
94
93
  return names;
95
94
  };
96
95
  EventEmitter2.prototype.listeners = function listeners(event) {
97
- var evt = prefix2 ? prefix2 + event : event, handlers = this._events[evt];
96
+ var evt = prefix ? prefix + event : event, handlers = this._events[evt];
98
97
  if (!handlers) return [];
99
98
  if (handlers.fn) return [handlers.fn];
100
99
  for (var i = 0, l = handlers.length, ee = new Array(l); i < l; i++) {
@@ -103,13 +102,13 @@ var require_eventemitter3 = __commonJS({
103
102
  return ee;
104
103
  };
105
104
  EventEmitter2.prototype.listenerCount = function listenerCount(event) {
106
- var evt = prefix2 ? prefix2 + event : event, listeners = this._events[evt];
105
+ var evt = prefix ? prefix + event : event, listeners = this._events[evt];
107
106
  if (!listeners) return 0;
108
107
  if (listeners.fn) return 1;
109
108
  return listeners.length;
110
109
  };
111
110
  EventEmitter2.prototype.emit = function emit(event, a1, a2, a3, a4, a5) {
112
- var evt = prefix2 ? prefix2 + event : event;
111
+ var evt = prefix ? prefix + event : event;
113
112
  if (!this._events[evt]) return false;
114
113
  var listeners = this._events[evt], len = arguments.length, args, i;
115
114
  if (listeners.fn) {
@@ -166,7 +165,7 @@ var require_eventemitter3 = __commonJS({
166
165
  return addListener(this, event, fn, context, true);
167
166
  };
168
167
  EventEmitter2.prototype.removeListener = function removeListener(event, fn, context, once) {
169
- var evt = prefix2 ? prefix2 + event : event;
168
+ var evt = prefix ? prefix + event : event;
170
169
  if (!this._events[evt]) return this;
171
170
  if (!fn) {
172
171
  clearEvent(this, evt);
@@ -191,7 +190,7 @@ var require_eventemitter3 = __commonJS({
191
190
  EventEmitter2.prototype.removeAllListeners = function removeAllListeners(event) {
192
191
  var evt;
193
192
  if (event) {
194
- evt = prefix2 ? prefix2 + event : event;
193
+ evt = prefix ? prefix + event : event;
195
194
  if (this._events[evt]) clearEvent(this, evt);
196
195
  } else {
197
196
  this._events = new Events();
@@ -201,7 +200,7 @@ var require_eventemitter3 = __commonJS({
201
200
  };
202
201
  EventEmitter2.prototype.off = EventEmitter2.prototype.removeListener;
203
202
  EventEmitter2.prototype.addListener = EventEmitter2.prototype.on;
204
- EventEmitter2.prefixed = prefix2;
203
+ EventEmitter2.prefixed = prefix;
205
204
  EventEmitter2.EventEmitter = EventEmitter2;
206
205
  if ("undefined" !== typeof module) {
207
206
  module.exports = EventEmitter2;
@@ -706,17 +705,6 @@ function sleep(ms) {
706
705
  return new Promise((resolve) => setTimeout(resolve, ms));
707
706
  }
708
707
 
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
-
720
708
  // solana/utils.ts
721
709
  var SIMULATE_TRIES = 3;
722
710
  var buildSendThrottler = (sendRate, sendInterval = 1e3) => {
@@ -744,30 +732,20 @@ function isSignerKeypair(walletOrKeypair) {
744
732
  function isTransactionVersioned(tx) {
745
733
  return "message" in tx;
746
734
  }
747
- async function prepareTransaction(connection, ixs, payer, commitment, partialSigners) {
735
+ async function prepareTransaction(connection, ixs, payer, commitment, ...partialSigners) {
748
736
  if (!payer) {
749
737
  throw new Error("Payer public key is not provided!");
750
738
  }
751
739
  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!");
760
740
  const messageV0 = new TransactionMessage({
761
741
  payerKey: payer,
762
- recentBlockhash,
742
+ recentBlockhash: hash.blockhash,
763
743
  instructions: ixs
764
744
  }).compileToV0Message();
765
745
  const tx = new VersionedTransaction(messageV0);
766
- const signers = partialSigners?.filter((item) => !!item) ?? void 0;
767
- if (signers) {
768
- tx.sign(signers);
769
- }
770
- return tx;
746
+ const signers = partialSigners.filter((item) => !!item);
747
+ tx.sign(signers);
748
+ return { tx, context, hash };
771
749
  }
772
750
  async function signTransaction(invoker, tx) {
773
751
  let signedTx;
@@ -959,7 +937,13 @@ async function generateCreateAtaBatchTx(connection, payer, paramsBatch, commitme
959
937
  })
960
938
  );
961
939
  const { value: hash, context } = await connection.getLatestBlockhashAndContext({ commitment });
962
- return { tx: createVersionedTransaction(ixs, payer, hash.blockhash), hash, context };
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 };
963
947
  }
964
948
  async function createAtaBatch(connection, invoker, paramsBatch, commitment, rate) {
965
949
  const { tx, hash, context } = await generateCreateAtaBatchTx(
@@ -989,7 +973,7 @@ async function checkOrCreateAtaBatch(connection, owners, mint, invoker, programI
989
973
  }
990
974
  function prepareBaseInstructions(connection, { computePrice, computeLimit }) {
991
975
  const ixs = [];
992
- if (computePrice && typeof computePrice === "number") {
976
+ if (computePrice) {
993
977
  ixs.push(ComputeBudgetProgram.setComputeUnitPrice({ microLamports: computePrice }));
994
978
  }
995
979
  if (computeLimit) {
@@ -1019,68 +1003,6 @@ async function getMultipleAccountsInfoBatched(connection, pubKeys, commitment) {
1019
1003
  return results.flat();
1020
1004
  }
1021
1005
 
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 };
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 };
1085
1007
  //# sourceMappingURL=index.js.map
1086
1008
  //# sourceMappingURL=index.js.map