@streamflow/common 6.5.0 → 7.0.0-alpha.10

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.
@@ -0,0 +1,416 @@
1
+ import { createAssociatedTokenAccountInstruction, getAssociatedTokenAddress, unpackMint, TOKEN_PROGRAM_ID, TOKEN_2022_PROGRAM_ID, } from "@solana/spl-token";
2
+ import { ComputeBudgetProgram, Keypair, TransactionMessage, VersionedTransaction, SendTransactionError, } from "@solana/web3.js";
3
+ import bs58 from "bs58";
4
+ import PQueue from "p-queue";
5
+ import { TransactionFailedError, } from "./types.js";
6
+ import { sleep } from "../utils.js";
7
+ const SIMULATE_TRIES = 3;
8
+ export const buildSendThrottler = (sendRate) => {
9
+ return new PQueue({ concurrency: sendRate, intervalCap: 1, interval: 1000 });
10
+ };
11
+ /**
12
+ * Wrapper function for Solana web3 getProgramAccounts with slightly better call interface
13
+ * @param {Connection} connection - Solana web3 connection object.
14
+ * @param {PublicKey} wallet - PublicKey to compare against.
15
+ * @param {number} offset - Offset of bits of the PublicKey in the account binary.
16
+ * @param {PublicKey} programId - Solana program ID.
17
+ * @return {Promise<Account[]>} - Array of resulting accounts.
18
+ */
19
+ export async function getProgramAccounts(connection, wallet, offset, programId) {
20
+ const programAccounts = await connection?.getProgramAccounts(programId, {
21
+ filters: [
22
+ {
23
+ memcmp: {
24
+ offset,
25
+ bytes: wallet.toBase58(),
26
+ },
27
+ },
28
+ ],
29
+ });
30
+ return [...programAccounts];
31
+ }
32
+ /**
33
+ * Utility function to check if the transaction initiator is a Wallet object
34
+ * @param {Keypair | SignerWalletAdapter} walletOrKeypair - Wallet or Keypair in question
35
+ * @return {boolean} - Returns true if parameter is a Wallet.
36
+ */
37
+ export function isSignerWallet(walletOrKeypair) {
38
+ return walletOrKeypair.signTransaction !== undefined;
39
+ }
40
+ /**
41
+ * Utility function to check if the transaction initiator a Keypair object, tries to mitigate version mismatch issues
42
+ * @param walletOrKeypair {Keypair | SignerWalletAdapter} walletOrKeypair - Wallet or Keypair in question
43
+ * @returns {boolean} - Returns true if parameter is a Keypair.
44
+ */
45
+ export function isSignerKeypair(walletOrKeypair) {
46
+ return (walletOrKeypair instanceof Keypair ||
47
+ walletOrKeypair.constructor === Keypair ||
48
+ walletOrKeypair.constructor.name === Keypair.prototype.constructor.name);
49
+ }
50
+ /**
51
+ * Utility function to check whether given transaction is Versioned
52
+ * @param tx {Transaction | VersionedTransaction} - Transaction to check
53
+ * @returns {boolean} - Returns true if transaction is Versioned.
54
+ */
55
+ export function isTransactionVersioned(tx) {
56
+ return "message" in tx;
57
+ }
58
+ /**
59
+ * Creates a Transaction with given instructions and optionally signs it.
60
+ * @param connection - Solana client connection
61
+ * @param ixs - Instructions to add to the Transaction
62
+ * @param payer - PublicKey of payer
63
+ * @param commitment - optional Commitment that will be used to fetch latest blockhash
64
+ * @param partialSigners - optional signers that will be used to partially sign a Transaction
65
+ * @returns Transaction and Blockhash
66
+ */
67
+ export async function prepareTransaction(connection, ixs, payer, commitment, ...partialSigners) {
68
+ if (!payer) {
69
+ throw new Error("Payer public key is not provided!");
70
+ }
71
+ const { value: hash, context } = await connection.getLatestBlockhashAndContext(commitment);
72
+ const messageV0 = new TransactionMessage({
73
+ payerKey: payer,
74
+ recentBlockhash: hash.blockhash,
75
+ instructions: ixs,
76
+ }).compileToV0Message();
77
+ const tx = new VersionedTransaction(messageV0);
78
+ const signers = partialSigners.filter((item) => !!item);
79
+ tx.sign(signers);
80
+ return { tx, context, hash };
81
+ }
82
+ export async function signTransaction(invoker, tx) {
83
+ let signedTx;
84
+ if (isSignerWallet(invoker)) {
85
+ signedTx = await invoker.signTransaction(tx);
86
+ }
87
+ else {
88
+ if (isTransactionVersioned(tx)) {
89
+ tx.sign([invoker]);
90
+ }
91
+ else {
92
+ tx.partialSign(invoker);
93
+ }
94
+ signedTx = tx;
95
+ }
96
+ return signedTx;
97
+ }
98
+ /**
99
+ * Signs, sends and confirms Transaction
100
+ * @param connection - Solana client connection
101
+ * @param invoker - Keypair used as signer
102
+ * @param tx - Transaction instance
103
+ * @param confirmationParams - Confirmation Params that will be used for execution
104
+ * @param throttleParams - rate or throttler instance to throttle TX sending - to not spam the blockchain too much
105
+ * @returns Transaction signature
106
+ */
107
+ export async function signAndExecuteTransaction(connection, invoker, tx, confirmationParams, throttleParams) {
108
+ const signedTx = await signTransaction(invoker, tx);
109
+ return executeTransaction(connection, signedTx, confirmationParams, throttleParams);
110
+ }
111
+ /**
112
+ * Sends and confirms Transaction
113
+ * Uses custom confirmation logic that:
114
+ * - simulates tx before sending separately
115
+ * - sends transaction without preFlight checks but with some valuable flags https://twitter.com/jordaaash/status/1774892862049800524?s=46&t=bhZ10V0r7IX5Lk5kKzxfGw
116
+ * - rebroadcasts a tx every 500 ms
117
+ * - after broadcasting check whether tx has executed once
118
+ * - catch errors for every actionable item, throw only the ones that signal that tx has failed
119
+ * - otherwise there is a chance of marking a landed tx as failed if it was broadcasted at least once
120
+ * @param connection - Solana client connection
121
+ * @param tx - Transaction instance
122
+ * @param confirmationParams - Confirmation Params that will be used for execution
123
+ * @param throttleParams - rate or throttler instance to throttle TX sending - to not spam the blockchain too much
124
+ * @returns Transaction signature
125
+ */
126
+ export async function executeTransaction(connection, tx, confirmationParams, throttleParams) {
127
+ if (tx.signatures.length === 0) {
128
+ throw Error("Error with transaction parameters.");
129
+ }
130
+ await simulateTransaction(connection, tx);
131
+ return sendAndConfirmTransaction(connection, tx, confirmationParams, throttleParams);
132
+ }
133
+ /**
134
+ * Launches a PromisePool with all transaction being executed at the same time, allows to throttle all TXs through one Queue
135
+ * @param connection - Solana client connection
136
+ * @param txs - Transactions
137
+ * @param confirmationParams - Confirmation Params that will be used for execution
138
+ * @param throttleParams - rate or throttler instance to throttle TX sending - to not spam the blockchain too much
139
+ * @param throttleParams.sendRate - rate
140
+ * @param throttleParams.sendThrottler - throttler instance
141
+ * @returns Raw Promise Results - should be handled by the consumer and unwrapped accordingly
142
+ */
143
+ export async function executeMultipleTransactions(connection, txs, confirmationParams, { sendRate = 1, sendThrottler }) {
144
+ if (!sendThrottler) {
145
+ sendThrottler = buildSendThrottler(sendRate);
146
+ }
147
+ return Promise.allSettled(txs.map((tx) => executeTransaction(connection, tx, confirmationParams, { sendRate: sendRate, sendThrottler: sendThrottler })));
148
+ }
149
+ /**
150
+ * Sends and confirm transaction in a loop, constantly re-broadcsting the tx until Blockheight expires.
151
+ * - we add additional 30 bocks to account for validators in an PRC pool divergence
152
+ * @param connection - Solana client connection
153
+ * @param tx - Transaction instance
154
+ * @param confirmationParams - Confirmation Params that will be used for execution
155
+ * @param confirmationParams.hash - blockhash information, the same hash should be used in the Transaction
156
+ * @param confirmationParams.context - context at which blockhash has been retrieve
157
+ * @param confirmationParams.commitment - optional commitment that will be used for simulation and confirmation
158
+ * @param throttleParams - rate or throttler instance to throttle TX sending - to not spam the blockchain too much
159
+ * @param throttleParams.sendRate - rate
160
+ * @param throttleParams.sendThrottler - throttler instance
161
+ */
162
+ export async function sendAndConfirmTransaction(connection, tx, { hash, context, commitment }, { sendRate = 1, sendThrottler }) {
163
+ const isVersioned = isTransactionVersioned(tx);
164
+ let signature;
165
+ if (isVersioned) {
166
+ signature = bs58.encode(tx.signatures[0]);
167
+ }
168
+ else {
169
+ signature = bs58.encode(tx.signature);
170
+ }
171
+ if (!sendThrottler) {
172
+ sendThrottler = buildSendThrottler(sendRate);
173
+ }
174
+ let blockheight = await connection.getBlockHeight(commitment);
175
+ let transactionSent = false;
176
+ const rawTransaction = tx.serialize();
177
+ while (blockheight < hash.lastValidBlockHeight + 15) {
178
+ try {
179
+ if (blockheight < hash.lastValidBlockHeight || !transactionSent) {
180
+ await sendThrottler.add(async () => connection.sendRawTransaction(rawTransaction, {
181
+ maxRetries: 0,
182
+ minContextSlot: context.slot,
183
+ preflightCommitment: commitment,
184
+ skipPreflight: true,
185
+ }));
186
+ transactionSent = true;
187
+ }
188
+ }
189
+ catch (e) {
190
+ if (transactionSent ||
191
+ (e instanceof SendTransactionError && e.message.includes("Minimum context slot has not been reached"))) {
192
+ await sleep(500);
193
+ continue;
194
+ }
195
+ throw e;
196
+ }
197
+ await sleep(500);
198
+ try {
199
+ const value = await confirmAndEnsureTransaction(connection, signature);
200
+ if (value) {
201
+ return signature;
202
+ }
203
+ }
204
+ catch (e) {
205
+ if (e instanceof TransactionFailedError) {
206
+ throw e;
207
+ }
208
+ await sleep(500);
209
+ }
210
+ try {
211
+ blockheight = await connection.getBlockHeight(commitment);
212
+ }
213
+ catch (_e) {
214
+ await sleep(500);
215
+ }
216
+ }
217
+ throw new Error(`Transaction ${signature} expired.`);
218
+ }
219
+ export async function simulateTransaction(connection, tx) {
220
+ let res;
221
+ for (let i = 0; i < SIMULATE_TRIES; i++) {
222
+ if (isTransactionVersioned(tx)) {
223
+ res = await connection.simulateTransaction(tx);
224
+ }
225
+ else {
226
+ res = await connection.simulateTransaction(tx);
227
+ }
228
+ if (res.value.err) {
229
+ const errMessage = JSON.stringify(res.value.err);
230
+ if (!errMessage.includes("BlockhashNotFound") || i === SIMULATE_TRIES - 1) {
231
+ throw new SendTransactionError("failed to simulate transaction: " + errMessage, res.value.logs || undefined);
232
+ }
233
+ continue;
234
+ }
235
+ return res;
236
+ }
237
+ throw new SendTransactionError("failed to simulate transaction");
238
+ }
239
+ /**
240
+ * Confirms and validates transaction success once
241
+ * @param connection - Solana client connection
242
+ * @param signature - Transaction signature
243
+ * @param ignoreError - return status even if tx failed
244
+ * @returns Transaction Status
245
+ */
246
+ export async function confirmAndEnsureTransaction(connection, signature, ignoreError) {
247
+ const response = await connection.getSignatureStatuses([signature]);
248
+ if (!response || response.value.length === 0 || response.value[0] === null) {
249
+ return null;
250
+ }
251
+ const value = response.value[0];
252
+ if (!value) {
253
+ return null;
254
+ }
255
+ if (!ignoreError && value.err) {
256
+ // That's how solana-web3js does it, `err` here is an object that won't really be handled
257
+ throw new TransactionFailedError(`Raw transaction ${signature} failed (${JSON.stringify({ err: value.err })})`);
258
+ }
259
+ switch (connection.commitment) {
260
+ case "confirmed":
261
+ case "single":
262
+ case "singleGossip": {
263
+ if (value.confirmationStatus === "processed") {
264
+ return null;
265
+ }
266
+ break;
267
+ }
268
+ case "finalized":
269
+ case "max":
270
+ case "root": {
271
+ if (value.confirmationStatus === "processed" || value.confirmationStatus === "confirmed") {
272
+ return null;
273
+ }
274
+ break;
275
+ }
276
+ // exhaust enums to ensure full coverage
277
+ case "processed":
278
+ case "recent":
279
+ }
280
+ return value;
281
+ }
282
+ /**
283
+ * Shorthand call signature for getAssociatedTokenAddress, with allowance for address to be offCurve
284
+ * @param {PublicKey} mint - SPL token Mint address.
285
+ * @param {PublicKey} owner - Owner of the Associated Token Address
286
+ * @param {PublicKey} programId - Program ID of the mint
287
+ * @return {Promise<PublicKey>} - Associated Token Address
288
+ */
289
+ export function ata(mint, owner, programId) {
290
+ return getAssociatedTokenAddress(mint, owner, true, programId);
291
+ }
292
+ /**
293
+ * Function that checks whether ATA exists for each provided owner
294
+ * @param connection - Solana client connection
295
+ * @param paramsBatch - Array of Params for each ATA account: {mint, owner}
296
+ * @returns Array of boolean where each member corresponds to an owner
297
+ */
298
+ export async function ataBatchExist(connection, paramsBatch) {
299
+ const tokenAccounts = await Promise.all(paramsBatch.map(async ({ mint, owner, programId }) => {
300
+ return ata(mint, owner, programId);
301
+ }));
302
+ const response = await connection.getMultipleAccountsInfo(tokenAccounts);
303
+ return response.map((accInfo) => !!accInfo);
304
+ }
305
+ export async function enrichAtaParams(connection, paramsBatch) {
306
+ const programIdByMint = {};
307
+ return Promise.all(paramsBatch.map(async (params) => {
308
+ if (params.programId) {
309
+ return params;
310
+ }
311
+ const mintStr = params.mint.toString();
312
+ if (!(mintStr in programIdByMint)) {
313
+ const { tokenProgramId } = await getMintAndProgram(connection, params.mint);
314
+ programIdByMint[mintStr] = tokenProgramId;
315
+ }
316
+ params.programId = programIdByMint[mintStr];
317
+ return params;
318
+ }));
319
+ }
320
+ /**
321
+ * Generates a Transaction to create ATA for an array of owners
322
+ * @param connection - Solana client connection
323
+ * @param payer - Transaction invoker, should be a signer
324
+ * @param paramsBatch - Array of Params for an each ATA account: {mint, owner}
325
+ * @param commitment - optional commitment that will be used to fetch Blockhash
326
+ * @returns Unsigned Transaction with create ATA instructions
327
+ */
328
+ export async function generateCreateAtaBatchTx(connection, payer, paramsBatch, commitment) {
329
+ paramsBatch = await enrichAtaParams(connection, paramsBatch);
330
+ const ixs = await Promise.all(paramsBatch.map(async ({ mint, owner, programId }) => {
331
+ return createAssociatedTokenAccountInstruction(payer, await ata(mint, owner), owner, mint, programId);
332
+ }));
333
+ const { value: hash, context } = await connection.getLatestBlockhashAndContext({ commitment });
334
+ const messageV0 = new TransactionMessage({
335
+ payerKey: payer,
336
+ recentBlockhash: hash.blockhash,
337
+ instructions: ixs,
338
+ }).compileToV0Message();
339
+ const tx = new VersionedTransaction(messageV0);
340
+ return { tx, hash, context };
341
+ }
342
+ /**
343
+ * Creates ATA for an array of owners
344
+ * @param connection - Solana client connection
345
+ * @param invoker - Transaction invoker and payer
346
+ * @param paramsBatch - Array of Params for an each ATA account: {mint, owner}
347
+ * @param commitment - optional commitment that will be used to fetch Blockhash
348
+ * @param rate - throttle rate for tx sending
349
+ * @returns Transaction signature
350
+ */
351
+ export async function createAtaBatch(connection, invoker, paramsBatch, commitment, rate) {
352
+ const { tx, hash, context } = await generateCreateAtaBatchTx(connection, invoker.publicKey, await enrichAtaParams(connection, paramsBatch), commitment);
353
+ return signAndExecuteTransaction(connection, invoker, tx, { hash, context, commitment }, { sendRate: rate });
354
+ }
355
+ /**
356
+ * Utility function that checks whether associated token accounts exist and return instructions to populate them if not
357
+ * @param connection - Solana client connection
358
+ * @param owners - Array of ATA owners
359
+ * @param mint - Mint for which ATA will be checked
360
+ * @param invoker - Transaction invoker and payer
361
+ * @param programId - Program ID of the Mint
362
+ * @returns Array of Transaction Instructions that should be added to a transaction
363
+ */
364
+ export async function checkOrCreateAtaBatch(connection, owners, mint, invoker, programId) {
365
+ const ixs = [];
366
+ if (!programId) {
367
+ programId = (await getMintAndProgram(connection, mint)).tokenProgramId;
368
+ }
369
+ // TODO: optimize fetching and maps/arrays
370
+ const atas = [];
371
+ for (const owner of owners) {
372
+ atas.push(await ata(mint, owner, programId));
373
+ }
374
+ const response = await connection.getMultipleAccountsInfo(atas);
375
+ for (let i = 0; i < response.length; i++) {
376
+ if (!response[i]) {
377
+ ixs.push(createAssociatedTokenAccountInstruction(invoker.publicKey, atas[i], owners[i], mint, programId));
378
+ }
379
+ }
380
+ return ixs;
381
+ }
382
+ /**
383
+ * Create Base instructions for Solana
384
+ * - sets compute price if `computePrice` is provided
385
+ * - sets compute limit if `computeLimit` is provided
386
+ */
387
+ export function prepareBaseInstructions(connection, { computePrice, computeLimit }) {
388
+ const ixs = [];
389
+ if (computePrice) {
390
+ ixs.push(ComputeBudgetProgram.setComputeUnitPrice({ microLamports: computePrice }));
391
+ }
392
+ if (computeLimit) {
393
+ ixs.push(ComputeBudgetProgram.setComputeUnitLimit({ units: computeLimit }));
394
+ }
395
+ return ixs;
396
+ }
397
+ /**
398
+ * Retrieve information about a mint and its program ID, support all Token Programs.
399
+ *
400
+ * @param connection Connection to use
401
+ * @param address Mint account
402
+ * @param commitment Desired level of commitment for querying the state
403
+ *
404
+ * @return Mint information
405
+ */
406
+ export async function getMintAndProgram(connection, address, commitment) {
407
+ const accountInfo = await connection.getAccountInfo(address, commitment);
408
+ let programId = accountInfo?.owner;
409
+ if (!programId?.equals(TOKEN_PROGRAM_ID) && !programId?.equals(TOKEN_2022_PROGRAM_ID)) {
410
+ programId = TOKEN_PROGRAM_ID;
411
+ }
412
+ return {
413
+ mint: unpackMint(address, accountInfo, programId),
414
+ tokenProgramId: programId,
415
+ };
416
+ }
@@ -1,7 +1,6 @@
1
1
  import { TransactionInstruction } from "@solana/web3.js";
2
- import { Types } from "aptos";
3
2
  export interface ITransactionResult {
4
- ixs: (TransactionInstruction | Types.TransactionPayload)[];
3
+ ixs: TransactionInstruction[];
5
4
  txId: string;
6
5
  }
7
6
  export declare enum ICluster {
@@ -0,0 +1,38 @@
1
+ // Utility types
2
+ export var ICluster;
3
+ (function (ICluster) {
4
+ ICluster["Mainnet"] = "mainnet";
5
+ ICluster["Devnet"] = "devnet";
6
+ ICluster["Testnet"] = "testnet";
7
+ ICluster["Local"] = "local";
8
+ })(ICluster || (ICluster = {}));
9
+ export var IChain;
10
+ (function (IChain) {
11
+ IChain["Solana"] = "Solana";
12
+ IChain["Aptos"] = "Aptos";
13
+ IChain["Ethereum"] = "Ethereum";
14
+ IChain["BNB"] = "BNB";
15
+ IChain["Polygon"] = "Polygon";
16
+ IChain["Sui"] = "Sui";
17
+ })(IChain || (IChain = {}));
18
+ /**
19
+ * Error wrapper for calls made to the contract on chain
20
+ */
21
+ export class ContractError extends Error {
22
+ contractErrorCode;
23
+ description;
24
+ /**
25
+ * Constructs the Error Wrapper
26
+ * @param error Original error raised probably by the chain SDK
27
+ * @param code extracted code from the error if managed to parse it
28
+ */
29
+ constructor(error, code, description) {
30
+ super(error.message); // Call the base class constructor with the error message
31
+ this.contractErrorCode = code ?? null;
32
+ this.description = description ?? null;
33
+ // Copy properties from the original error
34
+ Object.setPrototypeOf(this, ContractError.prototype);
35
+ this.name = "ContractError"; // Set the name property
36
+ this.stack = error.stack;
37
+ }
38
+ }
@@ -1,18 +1,18 @@
1
- import BN from "bn.js";
1
+ import BigNumber from "bignumber.js";
2
2
  /**
3
- * Used for conversion of token amounts to their Big Number representation.
4
- * Get Big Number representation in the smallest units from the same value in the highest units.
5
- * @param {number} value - Number of tokens you want to convert to its BN representation.
3
+ * Used for token amounts conversion from their Big Number representation to number.
4
+ * Get value in the highest units from BigNumber representation of the same value in the smallest units.
5
+ * @param {BigNumber} value - Big Number representation of value in the smallest units.
6
6
  * @param {number} decimals - Number of decimals the token has.
7
7
  */
8
- export declare const getBN: (value: number, decimals: number) => BN;
8
+ export declare const getNumberFromBigNumber: (bigNum: BigNumber, decimals: number) => number;
9
9
  /**
10
- * Used for token amounts conversion from their Big Number representation to number.
11
- * Get value in the highest units from BN representation of the same value in the smallest units.
12
- * @param {BN} value - Big Number representation of value in the smallest units.
10
+ * Used for conversion of token amounts to their Big Number representation.
11
+ * Get Big Number representation in the smallest units from the same value in the highest units.
12
+ * @param {number} value - Number of tokens you want to convert to its BigNumber representation.
13
13
  * @param {number} decimals - Number of decimals the token has.
14
14
  */
15
- export declare const getNumberFromBN: (value: BN, decimals: number) => number;
15
+ export declare const getScaledBigNumber: (value: number | string | BigNumber, decimals: number) => BigNumber;
16
16
  /**
17
17
  * Used to make on chain calls to the contract and wrap raised errors if any
18
18
  * @param func function that interacts with the contract
@@ -0,0 +1,47 @@
1
+ import BigNumber from "bignumber.js";
2
+ import { ContractError } from "./types.js";
3
+ /**
4
+ * Used for token amounts conversion from their Big Number representation to number.
5
+ * Get value in the highest units from BigNumber representation of the same value in the smallest units.
6
+ * @param {BigNumber} value - Big Number representation of value in the smallest units.
7
+ * @param {number} decimals - Number of decimals the token has.
8
+ */
9
+ export const getNumberFromBigNumber = (bigNum, decimals) => {
10
+ return bigNum.div(BigNumber(10).pow(decimals)).toNumber();
11
+ };
12
+ /**
13
+ * Used for conversion of token amounts to their Big Number representation.
14
+ * Get Big Number representation in the smallest units from the same value in the highest units.
15
+ * @param {number} value - Number of tokens you want to convert to its BigNumber representation.
16
+ * @param {number} decimals - Number of decimals the token has.
17
+ */
18
+ export const getScaledBigNumber = (value, decimals) => {
19
+ return new BigNumber(value).times(new BigNumber(10).pow(decimals));
20
+ };
21
+ /**
22
+ * Used to make on chain calls to the contract and wrap raised errors if any
23
+ * @param func function that interacts with the contract
24
+ * @param callback callback that may be used to extract error code
25
+ * @returns {T}
26
+ */
27
+ export async function handleContractError(func, callback) {
28
+ try {
29
+ return await func();
30
+ }
31
+ catch (err) {
32
+ if (err instanceof Error) {
33
+ if (callback) {
34
+ throw new ContractError(err, callback(err));
35
+ }
36
+ throw new ContractError(err);
37
+ }
38
+ throw err;
39
+ }
40
+ }
41
+ /**
42
+ * Pause async function execution for given amount of milliseconds
43
+ * @param ms millisecond to sleep for
44
+ */
45
+ export function sleep(ms) {
46
+ return new Promise((resolve) => setTimeout(resolve, ms));
47
+ }
package/package.json CHANGED
@@ -1,36 +1,36 @@
1
1
  {
2
2
  "name": "@streamflow/common",
3
- "version": "6.5.0",
3
+ "version": "7.0.0-alpha.10",
4
4
  "description": "Common utilities and types used by streamflow packages.",
5
5
  "homepage": "https://github.com/streamflow-finance/js-sdk/",
6
- "main": "dist/index.js",
7
- "types": "dist/index.d.ts",
6
+ "main": "./dist/esm/index.js",
7
+ "types": "./dist/esm/index.d.ts",
8
+ "type": "module",
8
9
  "exports": {
9
- ".": "./dist/index.js",
10
- "./solana": "./dist/solana/index.js"
11
- },
12
- "typesVersions": {
13
- "*": {
14
- "solana": [
15
- "dist/solana/index.d.ts"
16
- ]
10
+ ".": {
11
+ "import": "./dist/esm/index.js",
12
+ "require": "./dist/cjs/index.js",
13
+ "types": "./dist/esm/index.d.ts"
14
+ },
15
+ "./solana": {
16
+ "import": "./dist/esm/solana/index.js",
17
+ "require": "./dist/cjs/solana/index.js",
18
+ "types": "./dist/esm/solana/index.d.ts"
17
19
  }
18
20
  },
19
21
  "scripts": {
20
- "build": "rm -rf dist; tsc -p tsconfig.json",
22
+ "build:cjs": "rm -rf dist/cjs; tsc -p tsconfig.cjs.json",
23
+ "build:esm": "rm -rf dist/esm; tsc -p tsconfig.esm.json",
24
+ "build": "rm -rf dist; pnpm run build:cjs && pnpm run build:esm",
21
25
  "pack": "pnpm build && pnpm pack",
22
26
  "lint": "eslint --fix .",
23
27
  "lint-config": "eslint --print-config",
24
28
  "prepublishOnly": "npm run lint && npm run build"
25
29
  },
26
- "gitHead": "799b73f95e7914ee0462e9cbb9da5e370278bd78",
30
+ "gitHead": "263638b9fd29395dcb64c33dfc2197df47f526af",
27
31
  "devDependencies": {
28
- "@streamflow/eslint-config": "6.5.0",
29
- "@types/bn.js": "5.1.1",
30
- "@types/jest": "29.2.4",
32
+ "@streamflow/eslint-config": "7.0.0-alpha.10",
31
33
  "date-fns": "2.28.0",
32
- "jest": "29.3.1",
33
- "ts-jest": "29.0.3",
34
34
  "typescript": "^4.9.5"
35
35
  },
36
36
  "dependencies": {
@@ -40,9 +40,9 @@
40
40
  "@solana/wallet-adapter-base": "0.9.19",
41
41
  "@solana/web3.js": "1.90.2",
42
42
  "aptos": "1.21.0",
43
- "bn.js": "5.2.1",
43
+ "bignumber.js": "^9.1.2",
44
44
  "borsh": "^2.0.0",
45
45
  "bs58": "5.0.0",
46
- "p-queue": "^6.6.2"
46
+ "p-queue": "^8.0.1"
47
47
  }
48
48
  }
package/dist/index.d.ts DELETED
@@ -1,2 +0,0 @@
1
- export * from "./types";
2
- export * from "./utils";
@@ -1,3 +0,0 @@
1
- export * from "./instructions";
2
- export * from "./types";
3
- export * from "./utils";