@streamflow/common 6.0.1 → 6.0.3

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.
@@ -18,4 +18,5 @@ export interface CheckAssociatedTokenAccountsData {
18
18
  export interface AtaParams {
19
19
  mint: PublicKey;
20
20
  owner: PublicKey;
21
+ programId?: PublicKey;
21
22
  }
@@ -1,5 +1,6 @@
1
+ import { Mint } from "@solana/spl-token";
1
2
  import { SignerWalletAdapter } from "@solana/wallet-adapter-base";
2
- import { BlockhashWithExpiryBlockHeight, Commitment, Connection, Keypair, PublicKey, Transaction, TransactionInstruction } from "@solana/web3.js";
3
+ import { BlockhashWithExpiryBlockHeight, Commitment, Connection, Keypair, PublicKey, Transaction, TransactionInstruction, SignatureStatus } from "@solana/web3.js";
3
4
  import { Account, AtaParams, ITransactionSolanaExt } from "./types";
4
5
  /**
5
6
  * Wrapper function for Solana web3 getProgramAccounts with slightly better call interface
@@ -38,31 +39,49 @@ export declare function prepareTransaction(connection: Connection, ixs: Transact
38
39
  export declare function signTransaction(invoker: Keypair | SignerWalletAdapter, tx: Transaction): Promise<Transaction>;
39
40
  /**
40
41
  * Signs, sends and confirms Transaction
42
+ * @param connection - Solana client connection
43
+ * @param invoker - Keypair used as signer
44
+ * @param tx - Transaction instance
45
+ * @param hash - blockhash information, the same hash should be used in the Transaction
46
+ * @returns Transaction signature
47
+ */
48
+ export declare function signAndExecuteTransaction(connection: Connection, invoker: Keypair | SignerWalletAdapter, tx: Transaction, hash: BlockhashWithExpiryBlockHeight): Promise<string>;
49
+ /**
50
+ * Sends and confirms Transaction
41
51
  * Confirmation strategy is not 100% reliable here as in times of congestion there can be a case that tx is executed,
42
52
  * but is not in `commitment` state and so it's not considered executed by the `sendAndConfirmRawTransaction` method,
43
53
  * and it raises an expiry error even though transaction may be executed soon.
44
- * So we add additional 50 blocks for checks to account for such issues.
54
+ * - so we add additional 50 blocks for checks to account for such issues;
55
+ * - also, we check for SignatureStatus one last time as it could be that websocket was slow to respond.
45
56
  * @param connection - Solana client connection
46
- * @param invoker - Keypair used as signer
47
57
  * @param tx - Transaction instance
48
58
  * @param hash - blockhash information, the same hash should be used in the Transaction
49
59
  * @returns Transaction signature
50
60
  */
51
- export declare function signAndExecuteTransaction(connection: Connection, invoker: Keypair | SignerWalletAdapter, tx: Transaction, hash: BlockhashWithExpiryBlockHeight): Promise<string>;
61
+ export declare function executeTransaction(connection: Connection, tx: Transaction, hash: BlockhashWithExpiryBlockHeight): Promise<string>;
62
+ /**
63
+ * Confirms and validates transaction success once
64
+ * @param connection - Solana client connection
65
+ * @param signature - Transaction signature
66
+ * @returns Transaction Status
67
+ */
68
+ export declare function confirmAndEnsureTransaction(connection: Connection, signature: string): Promise<SignatureStatus | null>;
52
69
  /**
53
70
  * Shorthand call signature for getAssociatedTokenAddress, with allowance for address to be offCurve
54
71
  * @param {PublicKey} mint - SPL token Mint address.
55
72
  * @param {PublicKey} owner - Owner of the Associated Token Address
73
+ * @param {PublicKey} programId - Program ID of the mint
56
74
  * @return {Promise<PublicKey>} - Associated Token Address
57
75
  */
58
- export declare function ata(mint: PublicKey, owner: PublicKey): Promise<PublicKey>;
76
+ export declare function ata(mint: PublicKey, owner: PublicKey, programId?: PublicKey): Promise<PublicKey>;
59
77
  /**
60
78
  * Function that checks whether ATA exists for each provided owner
61
79
  * @param connection - Solana client connection
62
- * @param paramsBatch - Array of Params for an each ATA account: {mint, owner}
63
- * @returns Array of boolean where each members corresponds to owners member
80
+ * @param paramsBatch - Array of Params for each ATA account: {mint, owner}
81
+ * @returns Array of boolean where each member corresponds to an owner
64
82
  */
65
83
  export declare function ataBatchExist(connection: Connection, paramsBatch: AtaParams[]): Promise<boolean[]>;
84
+ export declare function enrichAtaParams(connection: Connection, paramsBatch: AtaParams[]): Promise<AtaParams[]>;
66
85
  /**
67
86
  * Generates a Transaction to create ATA for an array of owners
68
87
  * @param connection - Solana client connection
@@ -88,12 +107,26 @@ export declare function createAtaBatch(connection: Connection, invoker: Keypair
88
107
  * @param owners - Array of ATA owners
89
108
  * @param mint - Mint for which ATA will be checked
90
109
  * @param invoker - Transaction invoker and payer
110
+ * @param programId - Program ID of the Mint
91
111
  * @returns Array of Transaction Instructions that should be added to a transaction
92
112
  */
93
- export declare function checkOrCreateAtaBatch(connection: Connection, owners: PublicKey[], mint: PublicKey, invoker: SignerWalletAdapter | Keypair): Promise<TransactionInstruction[]>;
113
+ export declare function checkOrCreateAtaBatch(connection: Connection, owners: PublicKey[], mint: PublicKey, invoker: SignerWalletAdapter | Keypair, programId?: PublicKey): Promise<TransactionInstruction[]>;
94
114
  /**
95
115
  * Create Base instructions for Solana
96
116
  * - sets compute price if `computePrice` is provided
97
117
  * - sets compute limit if `computeLimit` is provided
98
118
  */
99
119
  export declare function prepareBaseInstructions(connection: Connection, { computePrice, computeLimit }: ITransactionSolanaExt): TransactionInstruction[];
120
+ /**
121
+ * Retrieve information about a mint and its program ID, support all Token Programs.
122
+ *
123
+ * @param connection Connection to use
124
+ * @param address Mint account
125
+ * @param commitment Desired level of commitment for querying the state
126
+ *
127
+ * @return Mint information
128
+ */
129
+ export declare function getMintAndProgram(connection: Connection, address: PublicKey, commitment?: Commitment): Promise<{
130
+ mint: Mint;
131
+ programId: PublicKey;
132
+ }>;
@@ -75,10 +75,11 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
75
75
  return (mod && mod.__esModule) ? mod : { "default": mod };
76
76
  };
77
77
  Object.defineProperty(exports, "__esModule", { value: true });
78
- exports.prepareBaseInstructions = exports.checkOrCreateAtaBatch = exports.createAtaBatch = exports.generateCreateAtaBatchTx = exports.ataBatchExist = exports.ata = exports.signAndExecuteTransaction = exports.signTransaction = exports.prepareTransaction = exports.isSignerKeypair = exports.isSignerWallet = exports.getProgramAccounts = void 0;
78
+ exports.getMintAndProgram = exports.prepareBaseInstructions = exports.checkOrCreateAtaBatch = exports.createAtaBatch = exports.generateCreateAtaBatchTx = exports.enrichAtaParams = exports.ataBatchExist = exports.ata = exports.confirmAndEnsureTransaction = exports.executeTransaction = exports.signAndExecuteTransaction = exports.signTransaction = exports.prepareTransaction = exports.isSignerKeypair = exports.isSignerWallet = exports.getProgramAccounts = void 0;
79
79
  var spl_token_1 = require("@solana/spl-token");
80
80
  var web3_js_1 = require("@solana/web3.js");
81
81
  var bs58_1 = __importDefault(require("bs58"));
82
+ var utils_1 = require("../utils");
82
83
  /**
83
84
  * Wrapper function for Solana web3 getProgramAccounts with slightly better call interface
84
85
  * @param {Connection} connection - Solana web3 connection object.
@@ -195,10 +196,6 @@ function signTransaction(invoker, tx) {
195
196
  exports.signTransaction = signTransaction;
196
197
  /**
197
198
  * Signs, sends and confirms Transaction
198
- * Confirmation strategy is not 100% reliable here as in times of congestion there can be a case that tx is executed,
199
- * but is not in `commitment` state and so it's not considered executed by the `sendAndConfirmRawTransaction` method,
200
- * and it raises an expiry error even though transaction may be executed soon.
201
- * So we add additional 50 blocks for checks to account for such issues.
202
199
  * @param connection - Solana client connection
203
200
  * @param invoker - Keypair used as signer
204
201
  * @param tx - Transaction instance
@@ -207,41 +204,138 @@ exports.signTransaction = signTransaction;
207
204
  */
208
205
  function signAndExecuteTransaction(connection, invoker, tx, hash) {
209
206
  return __awaiter(this, void 0, void 0, function () {
210
- var signedTx, rawTx, confirmationStrategy;
207
+ var signedTx;
211
208
  return __generator(this, function (_a) {
212
209
  switch (_a.label) {
213
210
  case 0: return [4 /*yield*/, signTransaction(invoker, tx)];
214
211
  case 1:
215
212
  signedTx = _a.sent();
216
- rawTx = signedTx.serialize();
217
- if (!hash.lastValidBlockHeight || !signedTx.signature || !hash.blockhash)
213
+ return [2 /*return*/, executeTransaction(connection, signedTx, hash)];
214
+ }
215
+ });
216
+ });
217
+ }
218
+ exports.signAndExecuteTransaction = signAndExecuteTransaction;
219
+ /**
220
+ * Sends and confirms Transaction
221
+ * Confirmation strategy is not 100% reliable here as in times of congestion there can be a case that tx is executed,
222
+ * but is not in `commitment` state and so it's not considered executed by the `sendAndConfirmRawTransaction` method,
223
+ * and it raises an expiry error even though transaction may be executed soon.
224
+ * - so we add additional 50 blocks for checks to account for such issues;
225
+ * - also, we check for SignatureStatus one last time as it could be that websocket was slow to respond.
226
+ * @param connection - Solana client connection
227
+ * @param tx - Transaction instance
228
+ * @param hash - blockhash information, the same hash should be used in the Transaction
229
+ * @returns Transaction signature
230
+ */
231
+ function executeTransaction(connection, tx, hash) {
232
+ return __awaiter(this, void 0, void 0, function () {
233
+ var rawTx, signature, confirmationStrategy, e_2, value;
234
+ return __generator(this, function (_a) {
235
+ switch (_a.label) {
236
+ case 0:
237
+ rawTx = tx.serialize();
238
+ if (!hash.lastValidBlockHeight || !tx.signature || !hash.blockhash)
218
239
  throw Error("Error with transaction parameters.");
240
+ signature = bs58_1.default.encode(tx.signature);
219
241
  confirmationStrategy = {
220
242
  lastValidBlockHeight: hash.lastValidBlockHeight + 50,
221
- signature: bs58_1.default.encode(signedTx.signature),
243
+ signature: signature,
222
244
  blockhash: hash.blockhash,
223
245
  };
224
- return [2 /*return*/, (0, web3_js_1.sendAndConfirmRawTransaction)(connection, rawTx, confirmationStrategy)];
246
+ _a.label = 1;
247
+ case 1:
248
+ _a.trys.push([1, 3, , 7]);
249
+ return [4 /*yield*/, (0, web3_js_1.sendAndConfirmRawTransaction)(connection, rawTx, confirmationStrategy)];
250
+ case 2: return [2 /*return*/, _a.sent()];
251
+ case 3:
252
+ e_2 = _a.sent();
253
+ if (!(e_2 instanceof web3_js_1.TransactionExpiredBlockheightExceededError)) return [3 /*break*/, 6];
254
+ return [4 /*yield*/, (0, utils_1.sleep)(1000)];
255
+ case 4:
256
+ _a.sent();
257
+ return [4 /*yield*/, confirmAndEnsureTransaction(connection, signature)];
258
+ case 5:
259
+ value = _a.sent();
260
+ if (!value) {
261
+ throw e_2;
262
+ }
263
+ return [2 /*return*/, signature];
264
+ case 6: throw e_2;
265
+ case 7: return [2 /*return*/];
225
266
  }
226
267
  });
227
268
  });
228
269
  }
229
- exports.signAndExecuteTransaction = signAndExecuteTransaction;
270
+ exports.executeTransaction = executeTransaction;
271
+ /**
272
+ * Confirms and validates transaction success once
273
+ * @param connection - Solana client connection
274
+ * @param signature - Transaction signature
275
+ * @returns Transaction Status
276
+ */
277
+ function confirmAndEnsureTransaction(connection, signature) {
278
+ return __awaiter(this, void 0, void 0, function () {
279
+ var response, value;
280
+ return __generator(this, function (_a) {
281
+ switch (_a.label) {
282
+ case 0: return [4 /*yield*/, connection.getSignatureStatus(signature)];
283
+ case 1:
284
+ response = _a.sent();
285
+ if (!response) {
286
+ return [2 /*return*/, null];
287
+ }
288
+ value = response.value;
289
+ if (!value) {
290
+ return [2 /*return*/, null];
291
+ }
292
+ if (value.err) {
293
+ // That's how solana-web3js does it, `err` here is an object that won't really be handled
294
+ throw new Error("Raw transaction ".concat(signature, " failed (").concat(JSON.stringify({ err: value.err }), ")"));
295
+ }
296
+ switch (connection.commitment) {
297
+ case "confirmed":
298
+ case "single":
299
+ case "singleGossip": {
300
+ if (value.confirmationStatus === "processed") {
301
+ return [2 /*return*/, null];
302
+ }
303
+ break;
304
+ }
305
+ case "finalized":
306
+ case "max":
307
+ case "root": {
308
+ if (value.confirmationStatus === "processed" || value.confirmationStatus === "confirmed") {
309
+ return [2 /*return*/, null];
310
+ }
311
+ break;
312
+ }
313
+ // exhaust enums to ensure full coverage
314
+ case "processed":
315
+ case "recent":
316
+ }
317
+ return [2 /*return*/, value];
318
+ }
319
+ });
320
+ });
321
+ }
322
+ exports.confirmAndEnsureTransaction = confirmAndEnsureTransaction;
230
323
  /**
231
324
  * Shorthand call signature for getAssociatedTokenAddress, with allowance for address to be offCurve
232
325
  * @param {PublicKey} mint - SPL token Mint address.
233
326
  * @param {PublicKey} owner - Owner of the Associated Token Address
327
+ * @param {PublicKey} programId - Program ID of the mint
234
328
  * @return {Promise<PublicKey>} - Associated Token Address
235
329
  */
236
- function ata(mint, owner) {
237
- return (0, spl_token_1.getAssociatedTokenAddress)(mint, owner, true);
330
+ function ata(mint, owner, programId) {
331
+ return (0, spl_token_1.getAssociatedTokenAddress)(mint, owner, true, programId);
238
332
  }
239
333
  exports.ata = ata;
240
334
  /**
241
335
  * Function that checks whether ATA exists for each provided owner
242
336
  * @param connection - Solana client connection
243
- * @param paramsBatch - Array of Params for an each ATA account: {mint, owner}
244
- * @returns Array of boolean where each members corresponds to owners member
337
+ * @param paramsBatch - Array of Params for each ATA account: {mint, owner}
338
+ * @returns Array of boolean where each member corresponds to an owner
245
339
  */
246
340
  function ataBatchExist(connection, paramsBatch) {
247
341
  return __awaiter(this, void 0, void 0, function () {
@@ -250,16 +344,10 @@ function ataBatchExist(connection, paramsBatch) {
250
344
  return __generator(this, function (_a) {
251
345
  switch (_a.label) {
252
346
  case 0: return [4 /*yield*/, Promise.all(paramsBatch.map(function (_a) {
253
- var mint = _a.mint, owner = _a.owner;
347
+ var mint = _a.mint, owner = _a.owner, programId = _a.programId;
254
348
  return __awaiter(_this, void 0, void 0, function () {
255
- var pubkey;
256
349
  return __generator(this, function (_b) {
257
- switch (_b.label) {
258
- case 0: return [4 /*yield*/, ata(mint, owner)];
259
- case 1:
260
- pubkey = _b.sent();
261
- return [2 /*return*/, pubkey];
262
- }
350
+ return [2 /*return*/, ata(mint, owner, programId)];
263
351
  });
264
352
  });
265
353
  }))];
@@ -274,6 +362,37 @@ function ataBatchExist(connection, paramsBatch) {
274
362
  });
275
363
  }
276
364
  exports.ataBatchExist = ataBatchExist;
365
+ function enrichAtaParams(connection, paramsBatch) {
366
+ return __awaiter(this, void 0, void 0, function () {
367
+ var programIdByMint;
368
+ var _this = this;
369
+ return __generator(this, function (_a) {
370
+ programIdByMint = {};
371
+ return [2 /*return*/, Promise.all(paramsBatch.map(function (params) { return __awaiter(_this, void 0, void 0, function () {
372
+ var mintStr, programId;
373
+ return __generator(this, function (_a) {
374
+ switch (_a.label) {
375
+ case 0:
376
+ if (params.programId) {
377
+ return [2 /*return*/, params];
378
+ }
379
+ mintStr = params.mint.toString();
380
+ if (!!(mintStr in programIdByMint)) return [3 /*break*/, 2];
381
+ return [4 /*yield*/, getMintAndProgram(connection, params.mint)];
382
+ case 1:
383
+ programId = (_a.sent()).programId;
384
+ programIdByMint[mintStr] = programId;
385
+ _a.label = 2;
386
+ case 2:
387
+ params.programId = programIdByMint[mintStr];
388
+ return [2 /*return*/, params];
389
+ }
390
+ });
391
+ }); }))];
392
+ });
393
+ });
394
+ }
395
+ exports.enrichAtaParams = enrichAtaParams;
277
396
  /**
278
397
  * Generates a Transaction to create ATA for an array of owners
279
398
  * @param connection - Solana client connection
@@ -288,25 +407,28 @@ function generateCreateAtaBatchTx(connection, payer, paramsBatch) {
288
407
  var _this = this;
289
408
  return __generator(this, function (_b) {
290
409
  switch (_b.label) {
291
- case 0: return [4 /*yield*/, Promise.all(paramsBatch.map(function (_a) {
292
- var mint = _a.mint, owner = _a.owner;
293
- return __awaiter(_this, void 0, void 0, function () {
294
- var _b, _c;
295
- return __generator(this, function (_d) {
296
- switch (_d.label) {
297
- case 0:
298
- _b = spl_token_1.createAssociatedTokenAccountInstruction;
299
- _c = [payer];
300
- return [4 /*yield*/, ata(mint, owner)];
301
- case 1: return [2 /*return*/, _b.apply(void 0, _c.concat([_d.sent(), owner, mint]))];
302
- }
303
- });
304
- });
305
- }))];
410
+ case 0: return [4 /*yield*/, enrichAtaParams(connection, paramsBatch)];
306
411
  case 1:
412
+ paramsBatch = _b.sent();
413
+ return [4 /*yield*/, Promise.all(paramsBatch.map(function (_a) {
414
+ var mint = _a.mint, owner = _a.owner, programId = _a.programId;
415
+ return __awaiter(_this, void 0, void 0, function () {
416
+ var _b, _c;
417
+ return __generator(this, function (_d) {
418
+ switch (_d.label) {
419
+ case 0:
420
+ _b = spl_token_1.createAssociatedTokenAccountInstruction;
421
+ _c = [payer];
422
+ return [4 /*yield*/, ata(mint, owner)];
423
+ case 1: return [2 /*return*/, _b.apply(void 0, _c.concat([_d.sent(), owner, mint, programId]))];
424
+ }
425
+ });
426
+ });
427
+ }))];
428
+ case 2:
307
429
  ixs = _b.sent();
308
430
  return [4 /*yield*/, connection.getLatestBlockhash()];
309
- case 2:
431
+ case 3:
310
432
  hash = _b.sent();
311
433
  tx = (_a = new web3_js_1.Transaction({
312
434
  feePayer: payer,
@@ -328,12 +450,17 @@ exports.generateCreateAtaBatchTx = generateCreateAtaBatchTx;
328
450
  */
329
451
  function createAtaBatch(connection, invoker, paramsBatch) {
330
452
  return __awaiter(this, void 0, void 0, function () {
331
- var _a, tx, hash;
332
- return __generator(this, function (_b) {
333
- switch (_b.label) {
334
- case 0: return [4 /*yield*/, generateCreateAtaBatchTx(connection, invoker.publicKey, paramsBatch)];
335
- case 1:
336
- _a = _b.sent(), tx = _a.tx, hash = _a.hash;
453
+ var _a, tx, hash, _b, _c;
454
+ return __generator(this, function (_d) {
455
+ switch (_d.label) {
456
+ case 0:
457
+ _b = generateCreateAtaBatchTx;
458
+ _c = [connection,
459
+ invoker.publicKey];
460
+ return [4 /*yield*/, enrichAtaParams(connection, paramsBatch)];
461
+ case 1: return [4 /*yield*/, _b.apply(void 0, _c.concat([_d.sent()]))];
462
+ case 2:
463
+ _a = _d.sent(), tx = _a.tx, hash = _a.hash;
337
464
  return [2 /*return*/, signAndExecuteTransaction(connection, invoker, tx, hash)];
338
465
  }
339
466
  });
@@ -346,12 +473,13 @@ exports.createAtaBatch = createAtaBatch;
346
473
  * @param owners - Array of ATA owners
347
474
  * @param mint - Mint for which ATA will be checked
348
475
  * @param invoker - Transaction invoker and payer
476
+ * @param programId - Program ID of the Mint
349
477
  * @returns Array of Transaction Instructions that should be added to a transaction
350
478
  */
351
- function checkOrCreateAtaBatch(connection, owners, mint, invoker) {
479
+ function checkOrCreateAtaBatch(connection, owners, mint, invoker, programId) {
352
480
  return __awaiter(this, void 0, void 0, function () {
353
- var ixs, atas, owners_1, owners_1_1, owner, _a, _b, e_2_1, response, i;
354
- var e_2, _c;
481
+ var ixs, atas, owners_1, owners_1_1, owner, _a, _b, e_3_1, response, i;
482
+ var e_3, _c;
355
483
  return __generator(this, function (_d) {
356
484
  switch (_d.label) {
357
485
  case 0:
@@ -366,7 +494,7 @@ function checkOrCreateAtaBatch(connection, owners, mint, invoker) {
366
494
  if (!!owners_1_1.done) return [3 /*break*/, 5];
367
495
  owner = owners_1_1.value;
368
496
  _b = (_a = atas).push;
369
- return [4 /*yield*/, ata(mint, owner)];
497
+ return [4 /*yield*/, ata(mint, owner, programId)];
370
498
  case 3:
371
499
  _b.apply(_a, [_d.sent()]);
372
500
  _d.label = 4;
@@ -375,21 +503,21 @@ function checkOrCreateAtaBatch(connection, owners, mint, invoker) {
375
503
  return [3 /*break*/, 2];
376
504
  case 5: return [3 /*break*/, 8];
377
505
  case 6:
378
- e_2_1 = _d.sent();
379
- e_2 = { error: e_2_1 };
506
+ e_3_1 = _d.sent();
507
+ e_3 = { error: e_3_1 };
380
508
  return [3 /*break*/, 8];
381
509
  case 7:
382
510
  try {
383
511
  if (owners_1_1 && !owners_1_1.done && (_c = owners_1.return)) _c.call(owners_1);
384
512
  }
385
- finally { if (e_2) throw e_2.error; }
513
+ finally { if (e_3) throw e_3.error; }
386
514
  return [7 /*endfinally*/];
387
515
  case 8: return [4 /*yield*/, connection.getMultipleAccountsInfo(atas)];
388
516
  case 9:
389
517
  response = _d.sent();
390
518
  for (i = 0; i < response.length; i++) {
391
519
  if (!response[i]) {
392
- ixs.push((0, spl_token_1.createAssociatedTokenAccountInstruction)(invoker.publicKey, atas[i], owners[i], mint));
520
+ ixs.push((0, spl_token_1.createAssociatedTokenAccountInstruction)(invoker.publicKey, atas[i], owners[i], mint, programId));
393
521
  }
394
522
  }
395
523
  return [2 /*return*/, ixs];
@@ -415,3 +543,33 @@ function prepareBaseInstructions(connection, _a) {
415
543
  return ixs;
416
544
  }
417
545
  exports.prepareBaseInstructions = prepareBaseInstructions;
546
+ /**
547
+ * Retrieve information about a mint and its program ID, support all Token Programs.
548
+ *
549
+ * @param connection Connection to use
550
+ * @param address Mint account
551
+ * @param commitment Desired level of commitment for querying the state
552
+ *
553
+ * @return Mint information
554
+ */
555
+ function getMintAndProgram(connection, address, commitment) {
556
+ return __awaiter(this, void 0, void 0, function () {
557
+ var accountInfo, programId;
558
+ return __generator(this, function (_a) {
559
+ switch (_a.label) {
560
+ case 0: return [4 /*yield*/, connection.getAccountInfo(address, commitment)];
561
+ case 1:
562
+ accountInfo = _a.sent();
563
+ programId = accountInfo === null || accountInfo === void 0 ? void 0 : accountInfo.owner;
564
+ if (!(programId === null || programId === void 0 ? void 0 : programId.equals(spl_token_1.TOKEN_PROGRAM_ID)) && !(programId === null || programId === void 0 ? void 0 : programId.equals(spl_token_1.TOKEN_2022_PROGRAM_ID))) {
565
+ programId = spl_token_1.TOKEN_PROGRAM_ID;
566
+ }
567
+ return [2 /*return*/, {
568
+ mint: (0, spl_token_1.unpackMint)(address, accountInfo, programId),
569
+ programId: programId,
570
+ }];
571
+ }
572
+ });
573
+ });
574
+ }
575
+ exports.getMintAndProgram = getMintAndProgram;
package/dist/utils.d.ts CHANGED
@@ -20,3 +20,8 @@ export declare const getNumberFromBN: (value: BN, decimals: number) => number;
20
20
  * @returns {T}
21
21
  */
22
22
  export declare function handleContractError<T>(func: () => Promise<T>, callback?: (err: Error) => string | null): Promise<T>;
23
+ /**
24
+ * Pause async function execution for given amount of milliseconds
25
+ * @param ms millisecond to sleep for
26
+ */
27
+ export declare function sleep(ms: number): Promise<void>;
package/dist/utils.js CHANGED
@@ -39,7 +39,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
39
39
  return (mod && mod.__esModule) ? mod : { "default": mod };
40
40
  };
41
41
  Object.defineProperty(exports, "__esModule", { value: true });
42
- exports.handleContractError = exports.getNumberFromBN = exports.getBN = void 0;
42
+ exports.sleep = exports.handleContractError = exports.getNumberFromBN = exports.getBN = void 0;
43
43
  var bn_js_1 = __importDefault(require("bn.js"));
44
44
  var types_1 = require("./types");
45
45
  /**
@@ -97,3 +97,11 @@ function handleContractError(func, callback) {
97
97
  });
98
98
  }
99
99
  exports.handleContractError = handleContractError;
100
+ /**
101
+ * Pause async function execution for given amount of milliseconds
102
+ * @param ms millisecond to sleep for
103
+ */
104
+ function sleep(ms) {
105
+ return new Promise(function (resolve) { return setTimeout(resolve, ms); });
106
+ }
107
+ exports.sleep = sleep;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@streamflow/common",
3
- "version": "6.0.1",
3
+ "version": "6.0.3",
4
4
  "description": "Common utilities and types used by streamflow packages.",
5
5
  "homepage": "https://github.com/streamflow-finance/js-sdk/",
6
6
  "main": "dist/index.js",
@@ -23,7 +23,7 @@
23
23
  "lint-config": "eslint --print-config",
24
24
  "prepublishOnly": "npm run lint && npm run build"
25
25
  },
26
- "gitHead": "07782122a48131b4589edd9c536bb7f29dcbe0c9",
26
+ "gitHead": "d8f882dcb32394efb4ca997fff05e8c30128f14f",
27
27
  "devDependencies": {
28
28
  "@streamflow/eslint-config": "6.0.0",
29
29
  "@types/bn.js": "5.1.1",