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

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (45) hide show
  1. package/dist/cjs/index.cjs +90 -0
  2. package/dist/cjs/index.cjs.map +1 -0
  3. package/dist/cjs/index.d.cts +66 -0
  4. package/dist/cjs/solana/index.cjs +1121 -0
  5. package/dist/cjs/solana/index.cjs.map +1 -0
  6. package/dist/cjs/solana/index.d.cts +262 -0
  7. package/dist/cjs/solana/rpc/index.cjs +117 -0
  8. package/dist/cjs/solana/rpc/index.cjs.map +1 -0
  9. package/dist/cjs/solana/rpc/index.d.cts +89 -0
  10. package/dist/esm/index.d.ts +66 -3
  11. package/dist/esm/index.js +76 -3
  12. package/dist/esm/index.js.map +1 -0
  13. package/dist/esm/solana/index.d.ts +262 -5
  14. package/dist/esm/solana/index.js +1086 -5
  15. package/dist/esm/solana/index.js.map +1 -0
  16. package/dist/esm/solana/rpc/index.d.ts +89 -0
  17. package/dist/esm/solana/rpc/index.js +114 -0
  18. package/dist/esm/solana/rpc/index.js.map +1 -0
  19. package/package.json +33 -15
  20. package/dist/cjs/index.js +0 -19
  21. package/dist/cjs/lib/assertions.js +0 -13
  22. package/dist/cjs/lib/utils.js +0 -62
  23. package/dist/cjs/solana/account-filters.js +0 -19
  24. package/dist/cjs/solana/index.js +0 -21
  25. package/dist/cjs/solana/instructions.js +0 -22
  26. package/dist/cjs/solana/public-key.js +0 -13
  27. package/dist/cjs/solana/types.js +0 -11
  28. package/dist/cjs/solana/utils.js +0 -478
  29. package/dist/cjs/types.js +0 -40
  30. package/dist/esm/lib/assertions.d.ts +0 -1
  31. package/dist/esm/lib/assertions.js +0 -9
  32. package/dist/esm/lib/utils.d.ts +0 -28
  33. package/dist/esm/lib/utils.js +0 -51
  34. package/dist/esm/solana/account-filters.d.ts +0 -2
  35. package/dist/esm/solana/account-filters.js +0 -15
  36. package/dist/esm/solana/instructions.d.ts +0 -3
  37. package/dist/esm/solana/instructions.js +0 -18
  38. package/dist/esm/solana/public-key.d.ts +0 -7
  39. package/dist/esm/solana/public-key.js +0 -9
  40. package/dist/esm/solana/types.d.ts +0 -39
  41. package/dist/esm/solana/types.js +0 -7
  42. package/dist/esm/solana/utils.d.ts +0 -187
  43. package/dist/esm/solana/utils.js +0 -450
  44. package/dist/esm/types.d.ts +0 -32
  45. package/dist/esm/types.js +0 -38
@@ -1,51 +0,0 @@
1
- import BN from "bn.js";
2
- import { ContractError } from "../types.js";
3
- /**
4
- * Used for conversion of token amounts to their Big Number representation.
5
- * Get Big Number representation in the smallest units from the same value in the highest units.
6
- * @param {number} value - Number of tokens you want to convert to its BN representation.
7
- * @param {number} decimals - Number of decimals the token has.
8
- */
9
- export const getBN = (value, decimals) => {
10
- const decimalPart = value - Math.trunc(value);
11
- const integerPart = new BN(Math.trunc(value));
12
- const decimalE = new BN(decimalPart * 1e9);
13
- const sum = integerPart.mul(new BN(1e9)).add(decimalE);
14
- const resultE = sum.mul(new BN(10).pow(new BN(decimals)));
15
- return resultE.div(new BN(1e9));
16
- };
17
- /**
18
- * Used for token amounts conversion from their Big Number representation to number.
19
- * Get value in the highest units from BN representation of the same value in the smallest units.
20
- * @param {BN} value - Big Number representation of value in the smallest units.
21
- * @param {number} decimals - Number of decimals the token has.
22
- */
23
- export const getNumberFromBN = (value, decimals) => value.gt(new BN(2 ** 53 - 1)) ? value.div(new BN(10 ** decimals)).toNumber() : value.toNumber() / 10 ** decimals;
24
- /**
25
- * Used to make on chain calls to the contract and wrap raised errors if any
26
- * @param func function that interacts with the contract
27
- * @param callback callback that may be used to extract error code
28
- * @returns {T}
29
- */
30
- export async function handleContractError(func, callback) {
31
- try {
32
- return await func();
33
- }
34
- catch (err) {
35
- if (err instanceof Error) {
36
- if (callback) {
37
- throw new ContractError(err, callback(err));
38
- }
39
- throw new ContractError(err);
40
- }
41
- throw err;
42
- }
43
- }
44
- /**
45
- * Pause async function execution for given amount of milliseconds
46
- * @param ms millisecond to sleep for
47
- */
48
- export function sleep(ms) {
49
- return new Promise((resolve) => setTimeout(resolve, ms));
50
- }
51
- export const divCeilN = (n, d) => n / d + (n % d ? BigInt(1) : BigInt(0));
@@ -1,2 +0,0 @@
1
- import { MemcmpFilter, PublicKey } from "@solana/web3.js";
2
- export declare const getFilters: <T extends Record<string, number | PublicKey>>(criteria: T, byteOffsets: Record<keyof T, number>) => MemcmpFilter[];
@@ -1,15 +0,0 @@
1
- export const getFilters = (criteria, byteOffsets) => {
2
- return Object.entries(criteria).reduce((acc, [key, value]) => {
3
- const criteriaKey = key;
4
- const effectiveByteOffset = byteOffsets[criteriaKey];
5
- if (criteria[criteriaKey] && effectiveByteOffset) {
6
- acc.push({
7
- memcmp: {
8
- offset: effectiveByteOffset,
9
- bytes: value.toString(),
10
- },
11
- });
12
- }
13
- return acc;
14
- }, []);
15
- };
@@ -1,3 +0,0 @@
1
- import { Connection, PublicKey, TransactionInstruction } from "@solana/web3.js";
2
- import BN from "bn.js";
3
- export declare const prepareWrappedAccount: (connection: Connection, senderAddress: PublicKey, amount: BN) => Promise<TransactionInstruction[]>;
@@ -1,18 +0,0 @@
1
- import { getAssociatedTokenAddress, NATIVE_MINT, createAssociatedTokenAccountInstruction, createSyncNativeInstruction, } from "@solana/spl-token";
2
- import { SystemProgram } from "@solana/web3.js";
3
- export const prepareWrappedAccount = async (connection, senderAddress, amount) => {
4
- const tokenAccount = await getAssociatedTokenAddress(NATIVE_MINT, senderAddress, true);
5
- const accInfo = await connection.getParsedAccountInfo(tokenAccount);
6
- const instructions = (accInfo.value?.lamports ?? 0) > 0
7
- ? []
8
- : [createAssociatedTokenAccountInstruction(senderAddress, tokenAccount, senderAddress, NATIVE_MINT)];
9
- return [
10
- ...instructions,
11
- SystemProgram.transfer({
12
- fromPubkey: senderAddress,
13
- toPubkey: tokenAccount,
14
- lamports: amount.toNumber(),
15
- }),
16
- createSyncNativeInstruction(tokenAccount),
17
- ];
18
- };
@@ -1,7 +0,0 @@
1
- import { PublicKey } from "@solana/web3.js";
2
- /**
3
- * Converts a string or PublicKey to a PublicKey object.
4
- * @param address - The input address as a string or PublicKey.
5
- * @returns The PublicKey object.
6
- */
7
- export declare const pk: (address: string | PublicKey) => PublicKey;
@@ -1,9 +0,0 @@
1
- import { PublicKey } from "@solana/web3.js";
2
- /**
3
- * Converts a string or PublicKey to a PublicKey object.
4
- * @param address - The input address as a string or PublicKey.
5
- * @returns The PublicKey object.
6
- */
7
- export const pk = (address) => {
8
- return typeof address === "string" ? new PublicKey(address) : address;
9
- };
@@ -1,39 +0,0 @@
1
- import { AccountInfo, BlockhashWithExpiryBlockHeight, Commitment, Context, PublicKey } from "@solana/web3.js";
2
- import PQueue from "p-queue";
3
- export interface ITransactionSolanaExt {
4
- computePrice?: number;
5
- computeLimit?: number;
6
- }
7
- export interface Account {
8
- pubkey: PublicKey;
9
- account: AccountInfo<Buffer>;
10
- }
11
- export interface CheckAssociatedTokenAccountsData {
12
- sender: PublicKey;
13
- recipient: PublicKey;
14
- partner: PublicKey;
15
- streamflowTreasury: PublicKey;
16
- mint: PublicKey;
17
- }
18
- export interface AtaParams {
19
- mint: PublicKey;
20
- owner: PublicKey;
21
- programId?: PublicKey;
22
- }
23
- export interface ConfirmationParams {
24
- hash: BlockhashWithExpiryBlockHeight;
25
- context: Context;
26
- commitment?: Commitment;
27
- }
28
- export interface ThrottleParams {
29
- sendRate?: number;
30
- sendThrottler?: PQueue;
31
- waitBeforeConfirming?: number | undefined;
32
- }
33
- export interface IProgramAccount<T> {
34
- publicKey: PublicKey;
35
- account: T;
36
- }
37
- export declare class TransactionFailedError extends Error {
38
- constructor(m: string);
39
- }
@@ -1,7 +0,0 @@
1
- export class TransactionFailedError extends Error {
2
- constructor(m) {
3
- super(m);
4
- Object.setPrototypeOf(this, TransactionFailedError.prototype);
5
- this.name = "TransactionFailedError";
6
- }
7
- }
@@ -1,187 +0,0 @@
1
- import { Mint } from "@solana/spl-token";
2
- import { SignerWalletAdapter } from "@solana/wallet-adapter-base";
3
- import { BlockhashWithExpiryBlockHeight, Commitment, Connection, Keypair, PublicKey, Transaction, TransactionInstruction, SignatureStatus, VersionedTransaction, Context, RpcResponseAndContext, SimulatedTransactionResponse, AccountInfo } from "@solana/web3.js";
4
- import PQueue from "p-queue";
5
- import { Account, AtaParams, ConfirmationParams, ITransactionSolanaExt, ThrottleParams } from "./types.js";
6
- export declare const buildSendThrottler: (sendRate: number, sendInterval?: number) => PQueue;
7
- /**
8
- * Wrapper function for Solana web3 getProgramAccounts with slightly better call interface
9
- * @param {Connection} connection - Solana web3 connection object.
10
- * @param {PublicKey} wallet - PublicKey to compare against.
11
- * @param {number} offset - Offset of bits of the PublicKey in the account binary.
12
- * @param {PublicKey} programId - Solana program ID.
13
- * @return {Promise<Account[]>} - Array of resulting accounts.
14
- */
15
- export declare function getProgramAccounts(connection: Connection, wallet: PublicKey, offset: number, programId: PublicKey): Promise<Account[]>;
16
- /**
17
- * Utility function to check if the transaction initiator is a Wallet object
18
- * @param {Keypair | SignerWalletAdapter} walletOrKeypair - Wallet or Keypair in question
19
- * @return {boolean} - Returns true if parameter is a Wallet.
20
- */
21
- export declare function isSignerWallet(walletOrKeypair: Keypair | SignerWalletAdapter): walletOrKeypair is SignerWalletAdapter;
22
- /**
23
- * Utility function to check if the transaction initiator a Keypair object, tries to mitigate version mismatch issues
24
- * @param walletOrKeypair {Keypair | SignerWalletAdapter} walletOrKeypair - Wallet or Keypair in question
25
- * @returns {boolean} - Returns true if parameter is a Keypair.
26
- */
27
- export declare function isSignerKeypair(walletOrKeypair: Keypair | SignerWalletAdapter): walletOrKeypair is Keypair;
28
- /**
29
- * Utility function to check whether given transaction is Versioned
30
- * @param tx {Transaction | VersionedTransaction} - Transaction to check
31
- * @returns {boolean} - Returns true if transaction is Versioned.
32
- */
33
- export declare function isTransactionVersioned(tx: Transaction | VersionedTransaction): tx is VersionedTransaction;
34
- /**
35
- * Creates a Transaction with given instructions and optionally signs it.
36
- * @param connection - Solana client connection
37
- * @param ixs - Instructions to add to the Transaction
38
- * @param payer - PublicKey of payer
39
- * @param commitment - optional Commitment that will be used to fetch latest blockhash
40
- * @param partialSigners - optional signers that will be used to partially sign a Transaction
41
- * @returns Transaction and Blockhash
42
- */
43
- export declare function prepareTransaction(connection: Connection, ixs: TransactionInstruction[], payer: PublicKey | undefined | null, commitment?: Commitment, ...partialSigners: (Keypair | undefined)[]): Promise<{
44
- tx: VersionedTransaction;
45
- hash: BlockhashWithExpiryBlockHeight;
46
- context: Context;
47
- }>;
48
- export declare function signTransaction<T extends Transaction | VersionedTransaction>(invoker: Keypair | SignerWalletAdapter, tx: T): Promise<T>;
49
- /**
50
- * Signs, sends and confirms Transaction
51
- * @param connection - Solana client connection
52
- * @param invoker - Keypair used as signer
53
- * @param tx - Transaction instance
54
- * @param confirmationParams - Confirmation Params that will be used for execution
55
- * @param throttleParams - rate or throttler instance to throttle TX sending - to not spam the blockchain too much
56
- * @returns Transaction signature
57
- */
58
- export declare function signAndExecuteTransaction(connection: Connection, invoker: Keypair | SignerWalletAdapter, tx: Transaction | VersionedTransaction, confirmationParams: ConfirmationParams, throttleParams: ThrottleParams): Promise<string>;
59
- /**
60
- * Sends and confirms Transaction
61
- * Uses custom confirmation logic that:
62
- * - simulates tx before sending separately
63
- * - sends transaction without preFlight checks but with some valuable flags https://twitter.com/jordaaash/status/1774892862049800524?s=46&t=bhZ10V0r7IX5Lk5kKzxfGw
64
- * - rebroadcasts a tx every 500 ms
65
- * - after broadcasting check whether tx has executed once
66
- * - catch errors for every actionable item, throw only the ones that signal that tx has failed
67
- * - otherwise there is a chance of marking a landed tx as failed if it was broadcasted at least once
68
- * @param connection - Solana client connection
69
- * @param tx - Transaction instance
70
- * @param confirmationParams - Confirmation Params that will be used for execution
71
- * @param throttleParams - rate or throttler instance to throttle TX sending - to not spam the blockchain too much
72
- * @returns Transaction signature
73
- */
74
- export declare function executeTransaction(connection: Connection, tx: Transaction | VersionedTransaction, confirmationParams: ConfirmationParams, throttleParams: ThrottleParams): Promise<string>;
75
- /**
76
- * Launches a PromisePool with all transaction being executed at the same time, allows to throttle all TXs through one Queue
77
- * @param connection - Solana client connection
78
- * @param txs - Transactions
79
- * @param confirmationParams - Confirmation Params that will be used for execution
80
- * @param throttleParams - rate or throttler instance to throttle TX sending - to not spam the blockchain too much
81
- * @param throttleParams.sendRate - rate
82
- * @param throttleParams.sendThrottler - throttler instance
83
- * @returns Raw Promise Results - should be handled by the consumer and unwrapped accordingly
84
- */
85
- export declare function executeMultipleTransactions(connection: Connection, txs: (Transaction | VersionedTransaction)[], confirmationParams: ConfirmationParams, { sendRate, sendThrottler, ...throttlingParams }: ThrottleParams): Promise<PromiseSettledResult<string>[]>;
86
- /**
87
- * Sends and confirm transaction in a loop, constantly re-broadcsting the tx until Blockheight expires.
88
- * - we add additional 30 bocks to account for validators in an PRC pool divergence
89
- * @param connection - Solana client connection
90
- * @param tx - Transaction instance
91
- * @param confirmationParams - Confirmation Params that will be used for execution
92
- * @param confirmationParams.hash - blockhash information, the same hash should be used in the Transaction
93
- * @param confirmationParams.context - context at which blockhash has been retrieve
94
- * @param confirmationParams.commitment - optional commitment that will be used for simulation and confirmation
95
- * @param throttleParams - rate or throttler instance to throttle TX sending - to not spam the blockchain too much
96
- * @param throttleParams.sendRate - rate
97
- * @param throttleParams.sendThrottler - throttler instance
98
- */
99
- export declare function sendAndConfirmTransaction(connection: Connection, tx: Transaction | VersionedTransaction, { hash, context, commitment }: ConfirmationParams, { sendRate, sendThrottler, waitBeforeConfirming }: ThrottleParams): Promise<string>;
100
- export declare function simulateTransaction(connection: Connection, tx: Transaction | VersionedTransaction): Promise<RpcResponseAndContext<SimulatedTransactionResponse>>;
101
- /**
102
- * Confirms and validates transaction success once
103
- * @param connection - Solana client connection
104
- * @param signature - Transaction signature
105
- * @param ignoreError - return status even if tx failed
106
- * @returns Transaction Status
107
- */
108
- export declare function confirmAndEnsureTransaction(connection: Connection, signature: string, ignoreError?: boolean): Promise<SignatureStatus | null>;
109
- /**
110
- * Shorthand call signature for getAssociatedTokenAddress, with allowance for address to be offCurve
111
- * @param {PublicKey} mint - SPL token Mint address.
112
- * @param {PublicKey} owner - Owner of the Associated Token Address
113
- * @param {PublicKey} programId - Program ID of the mint
114
- * @return {Promise<PublicKey>} - Associated Token Address
115
- */
116
- export declare function ata(mint: PublicKey, owner: PublicKey, programId?: PublicKey): Promise<PublicKey>;
117
- /**
118
- * Function that checks whether ATA exists for each provided owner
119
- * @param connection - Solana client connection
120
- * @param paramsBatch - Array of Params for each ATA account: {mint, owner}
121
- * @returns Array of boolean where each member corresponds to an owner
122
- */
123
- export declare function ataBatchExist(connection: Connection, paramsBatch: AtaParams[]): Promise<boolean[]>;
124
- export declare function enrichAtaParams(connection: Connection, paramsBatch: AtaParams[]): Promise<AtaParams[]>;
125
- /**
126
- * Generates a Transaction to create ATA for an array of owners
127
- * @param connection - Solana client connection
128
- * @param payer - Transaction invoker, should be a signer
129
- * @param paramsBatch - Array of Params for an each ATA account: {mint, owner}
130
- * @param commitment - optional commitment that will be used to fetch Blockhash
131
- * @returns Unsigned Transaction with create ATA instructions
132
- */
133
- export declare function generateCreateAtaBatchTx(connection: Connection, payer: PublicKey, paramsBatch: AtaParams[], commitment?: Commitment): Promise<{
134
- tx: VersionedTransaction;
135
- hash: BlockhashWithExpiryBlockHeight;
136
- context: Context;
137
- }>;
138
- /**
139
- * Creates ATA for an array of owners
140
- * @param connection - Solana client connection
141
- * @param invoker - Transaction invoker and payer
142
- * @param paramsBatch - Array of Params for an each ATA account: {mint, owner}
143
- * @param commitment - optional commitment that will be used to fetch Blockhash
144
- * @param rate - throttle rate for tx sending
145
- * @returns Transaction signature
146
- */
147
- export declare function createAtaBatch(connection: Connection, invoker: Keypair | SignerWalletAdapter, paramsBatch: AtaParams[], commitment?: Commitment, rate?: number): Promise<string>;
148
- /**
149
- * Utility function that checks whether associated token accounts exist and return instructions to populate them if not
150
- * @param connection - Solana client connection
151
- * @param owners - Array of ATA owners
152
- * @param mint - Mint for which ATA will be checked
153
- * @param invoker - Transaction invoker and payer
154
- * @param programId - Program ID of the Mint
155
- * @returns Array of Transaction Instructions that should be added to a transaction
156
- */
157
- export declare function checkOrCreateAtaBatch(connection: Connection, owners: PublicKey[], mint: PublicKey, invoker: SignerWalletAdapter | Keypair, programId?: PublicKey): Promise<TransactionInstruction[]>;
158
- /**
159
- * Create Base instructions for Solana
160
- * - sets compute price if `computePrice` is provided
161
- * - sets compute limit if `computeLimit` is provided
162
- */
163
- export declare function prepareBaseInstructions(connection: Connection, { computePrice, computeLimit }: ITransactionSolanaExt): TransactionInstruction[];
164
- /**
165
- * Retrieve information about a mint and its program ID, support all Token Programs.
166
- *
167
- * @param connection Connection to use
168
- * @param address Mint account
169
- * @param commitment Desired level of commitment for querying the state
170
- *
171
- * @return Mint information
172
- */
173
- export declare function getMintAndProgram(connection: Connection, address: PublicKey, commitment?: Commitment): Promise<{
174
- mint: Mint;
175
- tokenProgramId: PublicKey;
176
- }>;
177
- /**
178
- * Split fetching of Multiple Accounts Info into batches of 100
179
- * as the maximum number of accounts that can be fetched in a single call is 100
180
- *
181
- * @param connection Connection to use
182
- * @param pubKeys Array of public keys to fetch account info for
183
- * @param commitment Desired level of commitment for querying the state
184
- *
185
- * @return Array of AccountInfo objects
186
- */
187
- export declare function getMultipleAccountsInfoBatched(connection: Connection, pubKeys: PublicKey[], commitment?: Commitment): Promise<(AccountInfo<Buffer> | null)[]>;