@streamflow/common 7.5.3 → 8.0.0-alpha.p284.726ba98
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cjs/index.cjs +90 -0
- package/dist/cjs/index.cjs.map +1 -0
- package/dist/cjs/index.d.cts +66 -0
- package/dist/cjs/solana/index.cjs +1039 -0
- package/dist/cjs/solana/index.cjs.map +1 -0
- package/dist/{esm/solana/utils.d.ts → cjs/solana/index.d.cts} +79 -27
- package/dist/esm/index.d.ts +66 -3
- package/dist/esm/index.js +76 -3
- package/dist/esm/index.js.map +1 -0
- package/dist/esm/solana/index.d.ts +239 -5
- package/dist/esm/solana/index.js +1008 -5
- package/dist/esm/solana/index.js.map +1 -0
- package/package.json +25 -15
- package/dist/cjs/index.js +0 -19
- package/dist/cjs/lib/assertions.js +0 -13
- package/dist/cjs/lib/utils.js +0 -62
- package/dist/cjs/solana/account-filters.js +0 -19
- package/dist/cjs/solana/index.js +0 -21
- package/dist/cjs/solana/instructions.js +0 -22
- package/dist/cjs/solana/public-key.js +0 -13
- package/dist/cjs/solana/types.js +0 -11
- package/dist/cjs/solana/utils.js +0 -478
- package/dist/cjs/types.js +0 -40
- package/dist/esm/lib/assertions.d.ts +0 -1
- package/dist/esm/lib/assertions.js +0 -9
- package/dist/esm/lib/utils.d.ts +0 -28
- package/dist/esm/lib/utils.js +0 -51
- package/dist/esm/solana/account-filters.d.ts +0 -2
- package/dist/esm/solana/account-filters.js +0 -15
- package/dist/esm/solana/instructions.d.ts +0 -3
- package/dist/esm/solana/instructions.js +0 -18
- package/dist/esm/solana/public-key.d.ts +0 -7
- package/dist/esm/solana/public-key.js +0 -9
- package/dist/esm/solana/types.d.ts +0 -39
- package/dist/esm/solana/types.js +0 -7
- package/dist/esm/solana/utils.js +0 -450
- package/dist/esm/types.d.ts +0 -32
- package/dist/esm/types.js +0 -38
|
@@ -1,5 +1,239 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
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
|
+
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
|
+
declare const buildSendThrottler: (sendRate: number, sendInterval?: number) => PQueue;
|
|
57
|
+
/**
|
|
58
|
+
* Wrapper function for Solana web3 getProgramAccounts with slightly better call interface
|
|
59
|
+
* @param {Connection} connection - Solana web3 connection object.
|
|
60
|
+
* @param {PublicKey} wallet - PublicKey to compare against.
|
|
61
|
+
* @param {number} offset - Offset of bits of the PublicKey in the account binary.
|
|
62
|
+
* @param {PublicKey} programId - Solana program ID.
|
|
63
|
+
* @return {Promise<Account[]>} - Array of resulting accounts.
|
|
64
|
+
*/
|
|
65
|
+
declare function getProgramAccounts(connection: Connection, wallet: PublicKey, offset: number, programId: PublicKey): Promise<Account[]>;
|
|
66
|
+
/**
|
|
67
|
+
* Utility function to check if the transaction initiator is a Wallet object
|
|
68
|
+
* @param {Keypair | SignerWalletAdapter} walletOrKeypair - Wallet or Keypair in question
|
|
69
|
+
* @return {boolean} - Returns true if parameter is a Wallet.
|
|
70
|
+
*/
|
|
71
|
+
declare function isSignerWallet(walletOrKeypair: Keypair | SignerWalletAdapter): walletOrKeypair is SignerWalletAdapter;
|
|
72
|
+
/**
|
|
73
|
+
* Utility function to check if the transaction initiator a Keypair object, tries to mitigate version mismatch issues
|
|
74
|
+
* @param walletOrKeypair {Keypair | SignerWalletAdapter} walletOrKeypair - Wallet or Keypair in question
|
|
75
|
+
* @returns {boolean} - Returns true if parameter is a Keypair.
|
|
76
|
+
*/
|
|
77
|
+
declare function isSignerKeypair(walletOrKeypair: Keypair | SignerWalletAdapter): walletOrKeypair is Keypair;
|
|
78
|
+
/**
|
|
79
|
+
* Utility function to check whether given transaction is Versioned
|
|
80
|
+
* @param tx {Transaction | VersionedTransaction} - Transaction to check
|
|
81
|
+
* @returns {boolean} - Returns true if transaction is Versioned.
|
|
82
|
+
*/
|
|
83
|
+
declare function isTransactionVersioned(tx: Transaction | VersionedTransaction): tx is VersionedTransaction;
|
|
84
|
+
/**
|
|
85
|
+
* Creates a Transaction with given instructions and optionally signs it.
|
|
86
|
+
* @param connection - Solana client connection
|
|
87
|
+
* @param ixs - Instructions to add to the Transaction
|
|
88
|
+
* @param payer - PublicKey of payer
|
|
89
|
+
* @param commitment - optional Commitment that will be used to fetch latest blockhash
|
|
90
|
+
* @param partialSigners - optional signers that will be used to partially sign a Transaction
|
|
91
|
+
* @returns Transaction and Blockhash
|
|
92
|
+
*/
|
|
93
|
+
declare function prepareTransaction(connection: Connection, ixs: TransactionInstruction[], payer: PublicKey | undefined | null, commitment?: Commitment, ...partialSigners: (Keypair | undefined)[]): Promise<{
|
|
94
|
+
tx: VersionedTransaction;
|
|
95
|
+
hash: BlockhashWithExpiryBlockHeight;
|
|
96
|
+
context: Context;
|
|
97
|
+
}>;
|
|
98
|
+
declare function signTransaction<T extends Transaction | VersionedTransaction>(invoker: Keypair | SignerWalletAdapter, tx: T): Promise<T>;
|
|
99
|
+
/**
|
|
100
|
+
* Signs, sends and confirms Transaction
|
|
101
|
+
* @param connection - Solana client connection
|
|
102
|
+
* @param invoker - Keypair used as signer
|
|
103
|
+
* @param tx - Transaction instance
|
|
104
|
+
* @param confirmationParams - Confirmation Params that will be used for execution
|
|
105
|
+
* @param throttleParams - rate or throttler instance to throttle TX sending - to not spam the blockchain too much
|
|
106
|
+
* @returns Transaction signature
|
|
107
|
+
*/
|
|
108
|
+
declare function signAndExecuteTransaction(connection: Connection, invoker: Keypair | SignerWalletAdapter, tx: Transaction | VersionedTransaction, confirmationParams: ConfirmationParams, throttleParams: ThrottleParams): Promise<string>;
|
|
109
|
+
/**
|
|
110
|
+
* Sends and confirms Transaction
|
|
111
|
+
* Uses custom confirmation logic that:
|
|
112
|
+
* - simulates tx before sending separately
|
|
113
|
+
* - sends transaction without preFlight checks but with some valuable flags https://twitter.com/jordaaash/status/1774892862049800524?s=46&t=bhZ10V0r7IX5Lk5kKzxfGw
|
|
114
|
+
* - rebroadcasts a tx every 500 ms
|
|
115
|
+
* - after broadcasting check whether tx has executed once
|
|
116
|
+
* - catch errors for every actionable item, throw only the ones that signal that tx has failed
|
|
117
|
+
* - otherwise there is a chance of marking a landed tx as failed if it was broadcasted at least once
|
|
118
|
+
* @param connection - Solana client connection
|
|
119
|
+
* @param tx - Transaction instance
|
|
120
|
+
* @param confirmationParams - Confirmation Params that will be used for execution
|
|
121
|
+
* @param throttleParams - rate or throttler instance to throttle TX sending - to not spam the blockchain too much
|
|
122
|
+
* @returns Transaction signature
|
|
123
|
+
*/
|
|
124
|
+
declare function executeTransaction(connection: Connection, tx: Transaction | VersionedTransaction, confirmationParams: ConfirmationParams, throttleParams: ThrottleParams): Promise<string>;
|
|
125
|
+
/**
|
|
126
|
+
* Launches a PromisePool with all transaction being executed at the same time, allows to throttle all TXs through one Queue
|
|
127
|
+
* @param connection - Solana client connection
|
|
128
|
+
* @param txs - Transactions
|
|
129
|
+
* @param confirmationParams - Confirmation Params that will be used for execution
|
|
130
|
+
* @param throttleParams - rate or throttler instance to throttle TX sending - to not spam the blockchain too much
|
|
131
|
+
* @param throttleParams.sendRate - rate
|
|
132
|
+
* @param throttleParams.sendThrottler - throttler instance
|
|
133
|
+
* @returns Raw Promise Results - should be handled by the consumer and unwrapped accordingly
|
|
134
|
+
*/
|
|
135
|
+
declare function executeMultipleTransactions(connection: Connection, txs: (Transaction | VersionedTransaction)[], confirmationParams: ConfirmationParams, { sendRate, sendThrottler, ...throttlingParams }: ThrottleParams): Promise<PromiseSettledResult<string>[]>;
|
|
136
|
+
/**
|
|
137
|
+
* Sends and confirm transaction in a loop, constantly re-broadcsting the tx until Blockheight expires.
|
|
138
|
+
* - we add additional 30 bocks to account for validators in an PRC pool divergence
|
|
139
|
+
* @param connection - Solana client connection
|
|
140
|
+
* @param tx - Transaction instance
|
|
141
|
+
* @param confirmationParams - Confirmation Params that will be used for execution
|
|
142
|
+
* @param confirmationParams.hash - blockhash information, the same hash should be used in the Transaction
|
|
143
|
+
* @param confirmationParams.context - context at which blockhash has been retrieve
|
|
144
|
+
* @param confirmationParams.commitment - optional commitment that will be used for simulation and confirmation
|
|
145
|
+
* @param throttleParams - rate or throttler instance to throttle TX sending - to not spam the blockchain too much
|
|
146
|
+
* @param throttleParams.sendRate - rate
|
|
147
|
+
* @param throttleParams.sendThrottler - throttler instance
|
|
148
|
+
*/
|
|
149
|
+
declare function sendAndConfirmTransaction(connection: Connection, tx: Transaction | VersionedTransaction, { hash, context, commitment }: ConfirmationParams, { sendRate, sendThrottler, waitBeforeConfirming }: ThrottleParams): Promise<string>;
|
|
150
|
+
declare function simulateTransaction(connection: Connection, tx: Transaction | VersionedTransaction): Promise<RpcResponseAndContext<SimulatedTransactionResponse>>;
|
|
151
|
+
/**
|
|
152
|
+
* Confirms and validates transaction success once
|
|
153
|
+
* @param connection - Solana client connection
|
|
154
|
+
* @param signature - Transaction signature
|
|
155
|
+
* @param ignoreError - return status even if tx failed
|
|
156
|
+
* @returns Transaction Status
|
|
157
|
+
*/
|
|
158
|
+
declare function confirmAndEnsureTransaction(connection: Connection, signature: string, ignoreError?: boolean): Promise<SignatureStatus | null>;
|
|
159
|
+
/**
|
|
160
|
+
* Shorthand call signature for getAssociatedTokenAddress, with allowance for address to be offCurve
|
|
161
|
+
* @param {PublicKey} mint - SPL token Mint address.
|
|
162
|
+
* @param {PublicKey} owner - Owner of the Associated Token Address
|
|
163
|
+
* @param {PublicKey} programId - Program ID of the mint
|
|
164
|
+
* @return {Promise<PublicKey>} - Associated Token Address
|
|
165
|
+
*/
|
|
166
|
+
declare function ata(mint: PublicKey, owner: PublicKey, programId?: PublicKey): Promise<PublicKey>;
|
|
167
|
+
/**
|
|
168
|
+
* Function that checks whether ATA exists for each provided owner
|
|
169
|
+
* @param connection - Solana client connection
|
|
170
|
+
* @param paramsBatch - Array of Params for each ATA account: {mint, owner}
|
|
171
|
+
* @returns Array of boolean where each member corresponds to an owner
|
|
172
|
+
*/
|
|
173
|
+
declare function ataBatchExist(connection: Connection, paramsBatch: AtaParams[]): Promise<boolean[]>;
|
|
174
|
+
declare function enrichAtaParams(connection: Connection, paramsBatch: AtaParams[]): Promise<AtaParams[]>;
|
|
175
|
+
/**
|
|
176
|
+
* Generates a Transaction to create ATA for an array of owners
|
|
177
|
+
* @param connection - Solana client connection
|
|
178
|
+
* @param payer - Transaction invoker, should be a signer
|
|
179
|
+
* @param paramsBatch - Array of Params for an each ATA account: {mint, owner}
|
|
180
|
+
* @param commitment - optional commitment that will be used to fetch Blockhash
|
|
181
|
+
* @returns Unsigned Transaction with create ATA instructions
|
|
182
|
+
*/
|
|
183
|
+
declare function generateCreateAtaBatchTx(connection: Connection, payer: PublicKey, paramsBatch: AtaParams[], commitment?: Commitment): Promise<{
|
|
184
|
+
tx: VersionedTransaction;
|
|
185
|
+
hash: BlockhashWithExpiryBlockHeight;
|
|
186
|
+
context: Context;
|
|
187
|
+
}>;
|
|
188
|
+
/**
|
|
189
|
+
* Creates ATA for an array of owners
|
|
190
|
+
* @param connection - Solana client connection
|
|
191
|
+
* @param invoker - Transaction invoker and payer
|
|
192
|
+
* @param paramsBatch - Array of Params for an each ATA account: {mint, owner}
|
|
193
|
+
* @param commitment - optional commitment that will be used to fetch Blockhash
|
|
194
|
+
* @param rate - throttle rate for tx sending
|
|
195
|
+
* @returns Transaction signature
|
|
196
|
+
*/
|
|
197
|
+
declare function createAtaBatch(connection: Connection, invoker: Keypair | SignerWalletAdapter, paramsBatch: AtaParams[], commitment?: Commitment, rate?: number): Promise<string>;
|
|
198
|
+
/**
|
|
199
|
+
* Utility function that checks whether associated token accounts exist and return instructions to populate them if not
|
|
200
|
+
* @param connection - Solana client connection
|
|
201
|
+
* @param owners - Array of ATA owners
|
|
202
|
+
* @param mint - Mint for which ATA will be checked
|
|
203
|
+
* @param invoker - Transaction invoker and payer
|
|
204
|
+
* @param programId - Program ID of the Mint
|
|
205
|
+
* @returns Array of Transaction Instructions that should be added to a transaction
|
|
206
|
+
*/
|
|
207
|
+
declare function checkOrCreateAtaBatch(connection: Connection, owners: PublicKey[], mint: PublicKey, invoker: SignerWalletAdapter | Keypair, programId?: PublicKey): Promise<TransactionInstruction[]>;
|
|
208
|
+
/**
|
|
209
|
+
* Create Base instructions for Solana
|
|
210
|
+
* - sets compute price if `computePrice` is provided
|
|
211
|
+
* - sets compute limit if `computeLimit` is provided
|
|
212
|
+
*/
|
|
213
|
+
declare function prepareBaseInstructions(connection: Connection, { computePrice, computeLimit }: ITransactionSolanaExt): TransactionInstruction[];
|
|
214
|
+
/**
|
|
215
|
+
* Retrieve information about a mint and its program ID, support all Token Programs.
|
|
216
|
+
*
|
|
217
|
+
* @param connection Connection to use
|
|
218
|
+
* @param address Mint account
|
|
219
|
+
* @param commitment Desired level of commitment for querying the state
|
|
220
|
+
*
|
|
221
|
+
* @return Mint information
|
|
222
|
+
*/
|
|
223
|
+
declare function getMintAndProgram(connection: Connection, address: PublicKey, commitment?: Commitment): Promise<{
|
|
224
|
+
mint: Mint;
|
|
225
|
+
tokenProgramId: PublicKey;
|
|
226
|
+
}>;
|
|
227
|
+
/**
|
|
228
|
+
* Split fetching of Multiple Accounts Info into batches of 100
|
|
229
|
+
* as the maximum number of accounts that can be fetched in a single call is 100
|
|
230
|
+
*
|
|
231
|
+
* @param connection Connection to use
|
|
232
|
+
* @param pubKeys Array of public keys to fetch account info for
|
|
233
|
+
* @param commitment Desired level of commitment for querying the state
|
|
234
|
+
*
|
|
235
|
+
* @return Array of AccountInfo objects
|
|
236
|
+
*/
|
|
237
|
+
declare function getMultipleAccountsInfoBatched(connection: Connection, pubKeys: PublicKey[], commitment?: Commitment): Promise<(AccountInfo<Buffer> | null)[]>;
|
|
238
|
+
|
|
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 };
|