@streamflow/common 8.4.0 → 8.7.0-alpha.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,5 +1,5 @@
1
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';
2
+ import { PublicKey, MemcmpFilter, Connection, TransactionInstruction, VersionedTransaction, AccountInfo, BlockhashWithExpiryBlockHeight, Context, Commitment, Keypair, Transaction, AddressLookupTableAccount, RpcResponseAndContext, SimulatedTransactionResponse, SignatureStatus } from '@solana/web3.js';
3
3
  import BN from 'bn.js';
4
4
  import PQueue from 'p-queue';
5
5
  import { Mint } from '@solana/spl-token';
@@ -11,9 +11,24 @@ declare const prepareWrappedAccount: (connection: Connection, senderAddress: Pub
11
11
 
12
12
  type ComputePriceEstimate = (tx: string | (string | PublicKey)[]) => Promise<number>;
13
13
  type ComputeLimitEstimate = (tx: VersionedTransaction) => Promise<number>;
14
+ /**
15
+ * Additional parameter for Solana Transaction processing.
16
+ *
17
+ * computePrice - compute price per CU in micro-lamports to be set in a transaction - priority fee, accepts:
18
+ * - a constant number;
19
+ * - a callable that returns a price for a built transaction;
20
+ * computeLimit - compute limit in CUs to set for a transaction, `computePrice` is paid per every allocated CU, accepts:
21
+ * - a constant number;
22
+ * - a callable that returns a CU limit for a built transaction;
23
+ * - `autoSimulate` - will be unwrapped by `unwrapExecutionParams` and converted to a callable that runs a simulation to estimate CUs and set a limit with some margin;
24
+ * feePayer - account that will be set as sol fee payer in instructions that accept such account, i.e. ATA creation:
25
+ * - should be only when building instructions via `prepare` methods, as tx executing methods will fail without a signer;
26
+ * - currently supported only when claiming an Airdrop;
27
+ */
14
28
  interface ITransactionSolanaExt {
15
29
  computePrice?: number | ComputePriceEstimate;
16
30
  computeLimit?: number | ComputeLimitEstimate | "autoSimulate";
31
+ feePayer?: PublicKey;
17
32
  }
18
33
  /**
19
34
  * Acceptable type with resolved values.
@@ -22,6 +37,7 @@ interface ITransactionSolanaExt {
22
37
  type ITransactionSolanaExtResolvedValues = {
23
38
  computePrice?: number | ComputePriceEstimate;
24
39
  computeLimit?: number | ComputeLimitEstimate;
40
+ feePayer?: PublicKey;
25
41
  };
26
42
  type KeysNotOfA<T, ToExclude> = Pick<T, Exclude<keyof T, keyof ToExclude>>;
27
43
  type ITransactionSolanaExtResolved<T extends ITransactionSolanaExt = ITransactionSolanaExt> = {
@@ -104,14 +120,15 @@ declare function isTransactionVersioned(tx: Transaction | VersionedTransaction):
104
120
  * @param payer - PublicKey of payer
105
121
  * @param commitment - optional Commitment that will be used to fetch latest blockhash
106
122
  * @param partialSigners - optional signers that will be used to partially sign a Transaction
123
+ * @param lookupTables - lookup table accounts to use in the transaction
107
124
  * @returns Transaction and Blockhash
108
125
  */
109
- declare function prepareTransaction(connection: Connection, ixs: TransactionInstruction[], payer: PublicKey | undefined | null, commitment?: Commitment, partialSigners?: (Keypair | undefined)[]): Promise<{
126
+ declare function prepareTransaction(connection: Connection, ixs: TransactionInstruction[], payer: PublicKey | undefined | null, commitment?: Commitment, partialSigners?: (Keypair | undefined)[], lookupTables?: AddressLookupTableAccount[]): Promise<{
110
127
  tx: VersionedTransaction;
111
128
  hash: BlockhashWithExpiryBlockHeight;
112
129
  context: Context;
113
130
  }>;
114
- declare function createVersionedTransaction(ixs: TransactionInstruction[], payer: PublicKey | undefined | null, recentBlockhash: BlockhashWithExpiryBlockHeight["blockhash"], partialSigners?: (Keypair | undefined)[]): VersionedTransaction;
131
+ declare function createVersionedTransaction(ixs: TransactionInstruction[], payer: PublicKey | undefined | null, recentBlockhash: BlockhashWithExpiryBlockHeight["blockhash"], partialSigners?: (Keypair | undefined)[], lookupTables?: AddressLookupTableAccount[]): VersionedTransaction;
115
132
  declare function signTransaction<T extends Transaction | VersionedTransaction>(invoker: Keypair | SignerWalletAdapter, tx: T): Promise<T>;
116
133
  /**
117
134
  * Signs, sends and confirms Transaction
@@ -219,9 +236,10 @@ declare function createAtaBatch(connection: Connection, invoker: Keypair | Signe
219
236
  * @param mint - Mint for which ATA will be checked
220
237
  * @param invoker - Transaction invoker and payer
221
238
  * @param programId - Program ID of the Mint
239
+ * @param payer - optional payer account, will be used instead of invoker as `source`
222
240
  * @returns Array of Transaction Instructions that should be added to a transaction
223
241
  */
224
- declare function checkOrCreateAtaBatch(connection: Connection, owners: PublicKey[], mint: PublicKey, invoker: SignerWalletAdapter | Keypair, programId?: PublicKey): Promise<TransactionInstruction[]>;
242
+ declare function checkOrCreateAtaBatch(connection: Connection, owners: PublicKey[], mint: PublicKey, invoker: SignerWalletAdapter | Keypair, programId?: PublicKey, payer?: PublicKey): Promise<TransactionInstruction[]>;
225
243
  /**
226
244
  * Create Base instructions for Solana
227
245
  * - 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).
@@ -1,5 +1,5 @@
1
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';
2
+ import { PublicKey, MemcmpFilter, Connection, TransactionInstruction, VersionedTransaction, AccountInfo, BlockhashWithExpiryBlockHeight, Context, Commitment, Keypair, Transaction, AddressLookupTableAccount, RpcResponseAndContext, SimulatedTransactionResponse, SignatureStatus } from '@solana/web3.js';
3
3
  import BN from 'bn.js';
4
4
  import PQueue from 'p-queue';
5
5
  import { Mint } from '@solana/spl-token';
@@ -11,9 +11,24 @@ declare const prepareWrappedAccount: (connection: Connection, senderAddress: Pub
11
11
 
12
12
  type ComputePriceEstimate = (tx: string | (string | PublicKey)[]) => Promise<number>;
13
13
  type ComputeLimitEstimate = (tx: VersionedTransaction) => Promise<number>;
14
+ /**
15
+ * Additional parameter for Solana Transaction processing.
16
+ *
17
+ * computePrice - compute price per CU in micro-lamports to be set in a transaction - priority fee, accepts:
18
+ * - a constant number;
19
+ * - a callable that returns a price for a built transaction;
20
+ * computeLimit - compute limit in CUs to set for a transaction, `computePrice` is paid per every allocated CU, accepts:
21
+ * - a constant number;
22
+ * - a callable that returns a CU limit for a built transaction;
23
+ * - `autoSimulate` - will be unwrapped by `unwrapExecutionParams` and converted to a callable that runs a simulation to estimate CUs and set a limit with some margin;
24
+ * feePayer - account that will be set as sol fee payer in instructions that accept such account, i.e. ATA creation:
25
+ * - should be only when building instructions via `prepare` methods, as tx executing methods will fail without a signer;
26
+ * - currently supported only when claiming an Airdrop;
27
+ */
14
28
  interface ITransactionSolanaExt {
15
29
  computePrice?: number | ComputePriceEstimate;
16
30
  computeLimit?: number | ComputeLimitEstimate | "autoSimulate";
31
+ feePayer?: PublicKey;
17
32
  }
18
33
  /**
19
34
  * Acceptable type with resolved values.
@@ -22,6 +37,7 @@ interface ITransactionSolanaExt {
22
37
  type ITransactionSolanaExtResolvedValues = {
23
38
  computePrice?: number | ComputePriceEstimate;
24
39
  computeLimit?: number | ComputeLimitEstimate;
40
+ feePayer?: PublicKey;
25
41
  };
26
42
  type KeysNotOfA<T, ToExclude> = Pick<T, Exclude<keyof T, keyof ToExclude>>;
27
43
  type ITransactionSolanaExtResolved<T extends ITransactionSolanaExt = ITransactionSolanaExt> = {
@@ -104,14 +120,15 @@ declare function isTransactionVersioned(tx: Transaction | VersionedTransaction):
104
120
  * @param payer - PublicKey of payer
105
121
  * @param commitment - optional Commitment that will be used to fetch latest blockhash
106
122
  * @param partialSigners - optional signers that will be used to partially sign a Transaction
123
+ * @param lookupTables - lookup table accounts to use in the transaction
107
124
  * @returns Transaction and Blockhash
108
125
  */
109
- declare function prepareTransaction(connection: Connection, ixs: TransactionInstruction[], payer: PublicKey | undefined | null, commitment?: Commitment, partialSigners?: (Keypair | undefined)[]): Promise<{
126
+ declare function prepareTransaction(connection: Connection, ixs: TransactionInstruction[], payer: PublicKey | undefined | null, commitment?: Commitment, partialSigners?: (Keypair | undefined)[], lookupTables?: AddressLookupTableAccount[]): Promise<{
110
127
  tx: VersionedTransaction;
111
128
  hash: BlockhashWithExpiryBlockHeight;
112
129
  context: Context;
113
130
  }>;
114
- declare function createVersionedTransaction(ixs: TransactionInstruction[], payer: PublicKey | undefined | null, recentBlockhash: BlockhashWithExpiryBlockHeight["blockhash"], partialSigners?: (Keypair | undefined)[]): VersionedTransaction;
131
+ declare function createVersionedTransaction(ixs: TransactionInstruction[], payer: PublicKey | undefined | null, recentBlockhash: BlockhashWithExpiryBlockHeight["blockhash"], partialSigners?: (Keypair | undefined)[], lookupTables?: AddressLookupTableAccount[]): VersionedTransaction;
115
132
  declare function signTransaction<T extends Transaction | VersionedTransaction>(invoker: Keypair | SignerWalletAdapter, tx: T): Promise<T>;
116
133
  /**
117
134
  * Signs, sends and confirms Transaction
@@ -219,9 +236,10 @@ declare function createAtaBatch(connection: Connection, invoker: Keypair | Signe
219
236
  * @param mint - Mint for which ATA will be checked
220
237
  * @param invoker - Transaction invoker and payer
221
238
  * @param programId - Program ID of the Mint
239
+ * @param payer - optional payer account, will be used instead of invoker as `source`
222
240
  * @returns Array of Transaction Instructions that should be added to a transaction
223
241
  */
224
- declare function checkOrCreateAtaBatch(connection: Connection, owners: PublicKey[], mint: PublicKey, invoker: SignerWalletAdapter | Keypair, programId?: PublicKey): Promise<TransactionInstruction[]>;
242
+ declare function checkOrCreateAtaBatch(connection: Connection, owners: PublicKey[], mint: PublicKey, invoker: SignerWalletAdapter | Keypair, programId?: PublicKey, payer?: PublicKey): Promise<TransactionInstruction[]>;
225
243
  /**
226
244
  * Create Base instructions for Solana
227
245
  * - 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).
@@ -741,24 +741,24 @@ function isSignerKeypair(walletOrKeypair) {
741
741
  function isTransactionVersioned(tx) {
742
742
  return "message" in tx;
743
743
  }
744
- async function prepareTransaction(connection, ixs, payer, commitment, partialSigners) {
744
+ async function prepareTransaction(connection, ixs, payer, commitment, partialSigners, lookupTables) {
745
745
  if (!payer) {
746
746
  throw new Error("Payer public key is not provided!");
747
747
  }
748
748
  const { value: hash, context } = await connection.getLatestBlockhashAndContext(commitment);
749
749
  return {
750
- tx: createVersionedTransaction(ixs, payer, hash.blockhash, partialSigners),
750
+ tx: createVersionedTransaction(ixs, payer, hash.blockhash, partialSigners, lookupTables),
751
751
  hash,
752
752
  context
753
753
  };
754
754
  }
755
- function createVersionedTransaction(ixs, payer, recentBlockhash, partialSigners) {
755
+ function createVersionedTransaction(ixs, payer, recentBlockhash, partialSigners, lookupTables) {
756
756
  invariant(payer, "Payer public key is not provided!");
757
757
  const messageV0 = new TransactionMessage({
758
758
  payerKey: payer,
759
759
  recentBlockhash,
760
760
  instructions: ixs
761
- }).compileToV0Message();
761
+ }).compileToV0Message(lookupTables);
762
762
  const tx = new VersionedTransaction(messageV0);
763
763
  const signers = partialSigners?.filter((item) => !!item) ?? void 0;
764
764
  if (signers) {
@@ -969,7 +969,7 @@ async function createAtaBatch(connection, invoker, paramsBatch, commitment, rate
969
969
  );
970
970
  return signAndExecuteTransaction(connection, invoker, tx, { hash, context, commitment }, { sendRate: rate });
971
971
  }
972
- async function checkOrCreateAtaBatch(connection, owners, mint, invoker, programId) {
972
+ async function checkOrCreateAtaBatch(connection, owners, mint, invoker, programId, payer) {
973
973
  const ixs = [];
974
974
  if (!programId) {
975
975
  programId = (await getMintAndProgram(connection, mint)).tokenProgramId;
@@ -981,7 +981,9 @@ async function checkOrCreateAtaBatch(connection, owners, mint, invoker, programI
981
981
  const response = await connection.getMultipleAccountsInfo(atas);
982
982
  for (let i = 0; i < response.length; i++) {
983
983
  if (!response[i]) {
984
- ixs.push(createAssociatedTokenAccountInstruction(invoker.publicKey, atas[i], owners[i], mint, programId));
984
+ ixs.push(
985
+ createAssociatedTokenAccountInstruction(payer ?? invoker.publicKey, atas[i], owners[i], mint, programId)
986
+ );
985
987
  }
986
988
  }
987
989
  return ixs;