@streamflow/common 7.5.3 → 8.0.0-alpha.p287.25d0c28

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 +1156 -0
  5. package/dist/cjs/solana/index.cjs.map +1 -0
  6. package/dist/cjs/solana/index.d.cts +297 -0
  7. package/dist/cjs/solana/rpc/index.cjs +137 -0
  8. package/dist/cjs/solana/rpc/index.cjs.map +1 -0
  9. package/dist/cjs/solana/rpc/index.d.cts +113 -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 +297 -5
  14. package/dist/esm/solana/index.js +1119 -5
  15. package/dist/esm/solana/index.js.map +1 -0
  16. package/dist/esm/solana/rpc/index.d.ts +113 -0
  17. package/dist/esm/solana/rpc/index.js +133 -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
@@ -1,5 +1,297 @@
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 * as _solana_web3_js from '@solana/web3.js';
2
+ import { PublicKey, MemcmpFilter, Connection, TransactionInstruction, VersionedTransaction, AccountInfo, BlockhashWithExpiryBlockHeight, Context, Commitment, Keypair, Transaction, RpcResponseAndContext, SimulatedTransactionResponse, SignatureStatus } from '@solana/web3.js';
3
+ import BN from 'bn.js';
4
+ import PQueue from 'p-queue';
5
+ import { Mint } from '@solana/spl-token';
6
+ import { SignerWalletAdapter } from '@solana/wallet-adapter-base';
7
+
8
+ declare const getFilters: <T extends Record<string, number | PublicKey>>(criteria: T, byteOffsets: Record<keyof T, number>) => MemcmpFilter[];
9
+
10
+ declare const prepareWrappedAccount: (connection: Connection, senderAddress: PublicKey, amount: BN) => Promise<TransactionInstruction[]>;
11
+
12
+ type ComputePriceEstimate = (tx: string | (string | PublicKey)[]) => Promise<number>;
13
+ type ComputeLimitEstimate = (tx: VersionedTransaction) => Promise<number>;
14
+ interface ITransactionSolanaExt {
15
+ computePrice?: number | ComputePriceEstimate;
16
+ computeLimit?: number | ComputeLimitEstimate | "autoSimulate";
17
+ }
18
+ /**
19
+ * Acceptable type with resolved values.
20
+ * Function types may be omitted if passed to destinations that do not support them.
21
+ */
22
+ type ITransactionSolanaExtResolvedValues = {
23
+ computePrice?: number | ComputePriceEstimate;
24
+ computeLimit?: number | ComputeLimitEstimate;
25
+ };
26
+ type KeysNotOfA<T, ToExclude> = Pick<T, Exclude<keyof T, keyof ToExclude>>;
27
+ type ITransactionSolanaExtResolved<T extends ITransactionSolanaExt = ITransactionSolanaExt> = {
28
+ [AK in keyof KeysNotOfA<T, ITransactionSolanaExt>]: T[AK];
29
+ } & ITransactionSolanaExtResolvedValues;
30
+ interface IInteractSolanaExt extends ITransactionSolanaExt {
31
+ invoker: {
32
+ publicKey: string | PublicKey | null;
33
+ };
34
+ }
35
+ interface Account {
36
+ pubkey: PublicKey;
37
+ account: AccountInfo<Buffer>;
38
+ }
39
+ interface CheckAssociatedTokenAccountsData {
40
+ sender: PublicKey;
41
+ recipient: PublicKey;
42
+ partner: PublicKey;
43
+ streamflowTreasury: PublicKey;
44
+ mint: PublicKey;
45
+ }
46
+ interface AtaParams {
47
+ mint: PublicKey;
48
+ owner: PublicKey;
49
+ programId?: PublicKey;
50
+ }
51
+ interface ConfirmationParams {
52
+ hash: BlockhashWithExpiryBlockHeight;
53
+ context: Context;
54
+ commitment?: Commitment;
55
+ }
56
+ interface ThrottleParams {
57
+ sendRate?: number;
58
+ sendThrottler?: PQueue;
59
+ waitBeforeConfirming?: number | undefined;
60
+ }
61
+ interface TransactionExecutionParams extends ThrottleParams {
62
+ skipSimulation?: boolean;
63
+ }
64
+ interface IProgramAccount<T> {
65
+ publicKey: PublicKey;
66
+ account: T;
67
+ }
68
+ declare class TransactionFailedError extends Error {
69
+ constructor(m: string);
70
+ }
71
+
72
+ declare const buildSendThrottler: (sendRate: number, sendInterval?: number) => PQueue;
73
+ /**
74
+ * Wrapper function for Solana web3 getProgramAccounts with slightly better call interface
75
+ * @param {Connection} connection - Solana web3 connection object.
76
+ * @param {PublicKey} wallet - PublicKey to compare against.
77
+ * @param {number} offset - Offset of bits of the PublicKey in the account binary.
78
+ * @param {PublicKey} programId - Solana program ID.
79
+ * @return {Promise<Account[]>} - Array of resulting accounts.
80
+ */
81
+ declare function getProgramAccounts(connection: Connection, wallet: PublicKey, offset: number, programId: PublicKey): Promise<Account[]>;
82
+ /**
83
+ * Utility function to check if the transaction initiator is a Wallet object
84
+ * @param {Keypair | SignerWalletAdapter} walletOrKeypair - Wallet or Keypair in question
85
+ * @return {boolean} - Returns true if parameter is a Wallet.
86
+ */
87
+ declare function isSignerWallet(walletOrKeypair: Keypair | SignerWalletAdapter): walletOrKeypair is SignerWalletAdapter;
88
+ /**
89
+ * Utility function to check if the transaction initiator a Keypair object, tries to mitigate version mismatch issues
90
+ * @param walletOrKeypair {Keypair | SignerWalletAdapter} walletOrKeypair - Wallet or Keypair in question
91
+ * @returns {boolean} - Returns true if parameter is a Keypair.
92
+ */
93
+ declare function isSignerKeypair(walletOrKeypair: Keypair | SignerWalletAdapter): walletOrKeypair is Keypair;
94
+ /**
95
+ * Utility function to check whether given transaction is Versioned
96
+ * @param tx {Transaction | VersionedTransaction} - Transaction to check
97
+ * @returns {boolean} - Returns true if transaction is Versioned.
98
+ */
99
+ declare function isTransactionVersioned(tx: Transaction | VersionedTransaction): tx is VersionedTransaction;
100
+ /**
101
+ * Creates a Transaction with given instructions and optionally signs it.
102
+ * @param connection - Solana client connection
103
+ * @param ixs - Instructions to add to the Transaction
104
+ * @param payer - PublicKey of payer
105
+ * @param commitment - optional Commitment that will be used to fetch latest blockhash
106
+ * @param partialSigners - optional signers that will be used to partially sign a Transaction
107
+ * @returns Transaction and Blockhash
108
+ */
109
+ declare function prepareTransaction(connection: Connection, ixs: TransactionInstruction[], payer: PublicKey | undefined | null, commitment?: Commitment, partialSigners?: (Keypair | undefined)[]): Promise<{
110
+ tx: VersionedTransaction;
111
+ hash: BlockhashWithExpiryBlockHeight;
112
+ context: Context;
113
+ }>;
114
+ declare function createVersionedTransaction(ixs: TransactionInstruction[], payer: PublicKey | undefined | null, recentBlockhash: BlockhashWithExpiryBlockHeight["blockhash"], partialSigners?: (Keypair | undefined)[]): VersionedTransaction;
115
+ declare function signTransaction<T extends Transaction | VersionedTransaction>(invoker: Keypair | SignerWalletAdapter, tx: T): Promise<T>;
116
+ /**
117
+ * Signs, sends and confirms Transaction
118
+ * @param connection - Solana client connection
119
+ * @param invoker - Keypair used as signer
120
+ * @param tx - Transaction instance
121
+ * @param confirmationParams - Confirmation Params that will be used for execution
122
+ * @param transactionExecutionParams - rate or throttler instance to throttle TX sending - to not spam the blockchain too much and solana execution params (eg. skipSimulation)
123
+ * @returns Transaction signature
124
+ */
125
+ declare function signAndExecuteTransaction(connection: Connection, invoker: Keypair | SignerWalletAdapter, tx: Transaction | VersionedTransaction, confirmationParams: ConfirmationParams, transactionExecutionParams: TransactionExecutionParams): Promise<string>;
126
+ /**
127
+ * Sends and confirms Transaction
128
+ * Uses custom confirmation logic that:
129
+ * - simulates tx before sending separately
130
+ * - sends transaction without preFlight checks but with some valuable flags https://twitter.com/jordaaash/status/1774892862049800524?s=46&t=bhZ10V0r7IX5Lk5kKzxfGw
131
+ * - rebroadcasts a tx every 500 ms
132
+ * - after broadcasting check whether tx has executed once
133
+ * - catch errors for every actionable item, throw only the ones that signal that tx has failed
134
+ * - otherwise there is a chance of marking a landed tx as failed if it was broadcasted at least once
135
+ * @param connection - Solana client connection
136
+ * @param tx - Transaction instance
137
+ * @param confirmationParams - Confirmation Params that will be used for execution
138
+ * @param transactionExecutionParams - rate or throttler instance to throttle TX sending - to not spam the blockchain too much and solana execution params (eg. skipSimulation)
139
+ * @returns Transaction signature
140
+ */
141
+ declare function executeTransaction(connection: Connection, tx: Transaction | VersionedTransaction, confirmationParams: ConfirmationParams, transactionExecutionParams: TransactionExecutionParams): Promise<string>;
142
+ /**
143
+ * Launches a PromisePool with all transaction being executed at the same time, allows to throttle all TXs through one Queue
144
+ * @param connection - Solana client connection
145
+ * @param txs - Transactions
146
+ * @param confirmationParams - Confirmation Params that will be used for execution
147
+ * @param throttleParams - rate or throttler instance to throttle TX sending - to not spam the blockchain too much
148
+ * @param throttleParams.sendRate - rate
149
+ * @param throttleParams.sendThrottler - throttler instance
150
+ * @returns Raw Promise Results - should be handled by the consumer and unwrapped accordingly
151
+ */
152
+ declare function executeMultipleTransactions(connection: Connection, txs: (Transaction | VersionedTransaction)[], confirmationParams: ConfirmationParams, { sendRate, sendThrottler, ...throttlingParams }: ThrottleParams): Promise<PromiseSettledResult<string>[]>;
153
+ /**
154
+ * Sends and confirm transaction in a loop, constantly re-broadcsting the tx until Blockheight expires.
155
+ * - we add additional 30 bocks to account for validators in an PRC pool divergence
156
+ * @param connection - Solana client connection
157
+ * @param tx - Transaction instance
158
+ * @param confirmationParams - Confirmation Params that will be used for execution
159
+ * @param confirmationParams.hash - blockhash information, the same hash should be used in the Transaction
160
+ * @param confirmationParams.context - context at which blockhash has been retrieve
161
+ * @param confirmationParams.commitment - optional commitment that will be used for simulation and confirmation
162
+ * @param throttleParams - rate or throttler instance to throttle TX sending - to not spam the blockchain too much
163
+ * @param throttleParams.sendRate - rate
164
+ * @param throttleParams.sendThrottler - throttler instance
165
+ */
166
+ declare function sendAndConfirmTransaction(connection: Connection, tx: Transaction | VersionedTransaction, { hash, context, commitment }: ConfirmationParams, { sendRate, sendThrottler, waitBeforeConfirming }: ThrottleParams): Promise<string>;
167
+ declare function simulateTransaction(connection: Connection, tx: Transaction | VersionedTransaction): Promise<RpcResponseAndContext<SimulatedTransactionResponse>>;
168
+ /**
169
+ * Confirms and validates transaction success once
170
+ * @param connection - Solana client connection
171
+ * @param signature - Transaction signature
172
+ * @param ignoreError - return status even if tx failed
173
+ * @returns Transaction Status
174
+ */
175
+ declare function confirmAndEnsureTransaction(connection: Connection, signature: string, ignoreError?: boolean): Promise<SignatureStatus | null>;
176
+ /**
177
+ * Shorthand call signature for getAssociatedTokenAddress, with allowance for address to be offCurve
178
+ * @param {PublicKey} mint - SPL token Mint address.
179
+ * @param {PublicKey} owner - Owner of the Associated Token Address
180
+ * @param {PublicKey} programId - Program ID of the mint
181
+ * @return {Promise<PublicKey>} - Associated Token Address
182
+ */
183
+ declare function ata(mint: PublicKey, owner: PublicKey, programId?: PublicKey): Promise<PublicKey>;
184
+ /**
185
+ * Function that checks whether ATA exists for each provided owner
186
+ * @param connection - Solana client connection
187
+ * @param paramsBatch - Array of Params for each ATA account: {mint, owner}
188
+ * @returns Array of boolean where each member corresponds to an owner
189
+ */
190
+ declare function ataBatchExist(connection: Connection, paramsBatch: AtaParams[]): Promise<boolean[]>;
191
+ declare function enrichAtaParams(connection: Connection, paramsBatch: AtaParams[]): Promise<AtaParams[]>;
192
+ /**
193
+ * Generates a Transaction to create ATA for an array of owners
194
+ * @param connection - Solana client connection
195
+ * @param payer - Transaction invoker, should be a signer
196
+ * @param paramsBatch - Array of Params for an each ATA account: {mint, owner}
197
+ * @param commitment - optional commitment that will be used to fetch Blockhash
198
+ * @returns Unsigned Transaction with create ATA instructions
199
+ */
200
+ declare function generateCreateAtaBatchTx(connection: Connection, payer: PublicKey, paramsBatch: AtaParams[], commitment?: Commitment): Promise<{
201
+ tx: VersionedTransaction;
202
+ hash: BlockhashWithExpiryBlockHeight;
203
+ context: Context;
204
+ }>;
205
+ /**
206
+ * Creates ATA for an array of owners
207
+ * @param connection - Solana client connection
208
+ * @param invoker - Transaction invoker and payer
209
+ * @param paramsBatch - Array of Params for an each ATA account: {mint, owner}
210
+ * @param commitment - optional commitment that will be used to fetch Blockhash
211
+ * @param rate - throttle rate for tx sending
212
+ * @returns Transaction signature
213
+ */
214
+ declare function createAtaBatch(connection: Connection, invoker: Keypair | SignerWalletAdapter, paramsBatch: AtaParams[], commitment?: Commitment, rate?: number): Promise<string>;
215
+ /**
216
+ * Utility function that checks whether associated token accounts exist and return instructions to populate them if not
217
+ * @param connection - Solana client connection
218
+ * @param owners - Array of ATA owners
219
+ * @param mint - Mint for which ATA will be checked
220
+ * @param invoker - Transaction invoker and payer
221
+ * @param programId - Program ID of the Mint
222
+ * @returns Array of Transaction Instructions that should be added to a transaction
223
+ */
224
+ declare function checkOrCreateAtaBatch(connection: Connection, owners: PublicKey[], mint: PublicKey, invoker: SignerWalletAdapter | Keypair, programId?: PublicKey): Promise<TransactionInstruction[]>;
225
+ /**
226
+ * Create Base instructions for Solana
227
+ * - 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).
228
+ * - sets compute limit if `computeLimit` is provided. If `computeLimit` is a function, it will be ignored (the value must be resolved before calling this function).
229
+ */
230
+ declare function prepareBaseInstructions(connection: Connection, { computePrice, computeLimit }: ITransactionSolanaExt): TransactionInstruction[];
231
+ /**
232
+ * Retrieve information about a mint and its program ID, support all Token Programs.
233
+ *
234
+ * @param connection Connection to use
235
+ * @param address Mint account
236
+ * @param commitment Desired level of commitment for querying the state
237
+ *
238
+ * @return Mint information
239
+ */
240
+ declare function getMintAndProgram(connection: Connection, address: PublicKey, commitment?: Commitment): Promise<{
241
+ mint: Mint;
242
+ tokenProgramId: PublicKey;
243
+ }>;
244
+ /**
245
+ * Split fetching of Multiple Accounts Info into batches of 100
246
+ * as the maximum number of accounts that can be fetched in a single call is 100
247
+ *
248
+ * @param connection Connection to use
249
+ * @param pubKeys Array of public keys to fetch account info for
250
+ * @param commitment Desired level of commitment for querying the state
251
+ *
252
+ * @return Array of AccountInfo objects
253
+ */
254
+ declare function getMultipleAccountsInfoBatched(connection: Connection, pubKeys: PublicKey[], commitment?: Commitment): Promise<(AccountInfo<Buffer> | null)[]>;
255
+
256
+ declare function deserializeRawTransaction(serializedTx: string): {
257
+ type: string;
258
+ transaction: Transaction;
259
+ accounts: PublicKey[];
260
+ writableAccounts: PublicKey[];
261
+ } | {
262
+ type: string;
263
+ transaction: VersionedTransaction;
264
+ accounts: PublicKey[];
265
+ writableAccounts: PublicKey[];
266
+ };
267
+ declare const resolveTransactionAccounts: (tx: VersionedTransaction | Transaction) => {
268
+ type: string;
269
+ transaction: Transaction;
270
+ accounts: PublicKey[];
271
+ writableAccounts: PublicKey[];
272
+ } | {
273
+ type: string;
274
+ transaction: VersionedTransaction;
275
+ accounts: PublicKey[];
276
+ writableAccounts: PublicKey[];
277
+ };
278
+
279
+ declare const createTestTransaction: (ixs: Parameters<typeof createVersionedTransaction>[0], payer: Parameters<typeof createVersionedTransaction>[1], recentBlockhash?: Parameters<typeof createVersionedTransaction>[2], partialSigners?: Parameters<typeof createVersionedTransaction>[3]) => _solana_web3_js.VersionedTransaction;
280
+ declare function estimateComputeUnitPrice(estimate: ComputePriceEstimate, testTx: ReturnType<typeof createTestTransaction>): Promise<number>;
281
+ declare function createAndEstimateTransaction<ParamsT extends ITransactionSolanaExtResolved<IInteractSolanaExt>, CreateFn extends (extParams: ParamsT) => Promise<TransactionInstruction[]>>(createFn: CreateFn, extParams: ParamsT): Promise<Awaited<ReturnType<CreateFn>>>;
282
+ declare function createAndEstimateTransaction<ParamsT extends ITransactionSolanaExtResolved<IInteractSolanaExt>, CreateFn extends (extParams: ParamsT) => Promise<any>>(createFn: CreateFn, extParams: ParamsT, select: (result: Awaited<ReturnType<CreateFn>>) => TransactionInstruction[]): Promise<Awaited<ReturnType<CreateFn>>>;
283
+
284
+ /**
285
+ * Converts a string or PublicKey to a PublicKey object.
286
+ * @param address - The input address as a string or PublicKey.
287
+ * @returns The PublicKey object.
288
+ */
289
+ declare const pk: (address: string | PublicKey) => PublicKey;
290
+
291
+ type UnwrapAutoSimulate<T extends IInteractSolanaExt = IInteractSolanaExt> = Omit<T, "computeLimit"> & {
292
+ skipSimulation: boolean;
293
+ computeLimit?: ITransactionSolanaExtResolved["computeLimit"];
294
+ };
295
+ declare const unwrapExecutionParams: <T extends IInteractSolanaExt>({ computeLimit, ...rest }: T, connection: Connection) => UnwrapAutoSimulate<T>;
296
+
297
+ export { type Account, type AtaParams, type CheckAssociatedTokenAccountsData, type ComputeLimitEstimate, type ComputePriceEstimate, type ConfirmationParams, type IInteractSolanaExt, type IProgramAccount, type ITransactionSolanaExt, type ITransactionSolanaExtResolved, type ThrottleParams, type TransactionExecutionParams, 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, resolveTransactionAccounts, sendAndConfirmTransaction, signAndExecuteTransaction, signTransaction, simulateTransaction, unwrapExecutionParams };