@streamflow/stream 5.10.4 → 6.0.0-alpha.1

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.
@@ -22,73 +22,11 @@ var __importStar = (this && this.__importStar) || function (mod) {
22
22
  __setModuleDefault(result, mod);
23
23
  return result;
24
24
  };
25
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
26
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
27
- return new (P || (P = Promise))(function (resolve, reject) {
28
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
29
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
30
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
31
- step((generator = generator.apply(thisArg, _arguments || [])).next());
32
- });
33
- };
34
- var __generator = (this && this.__generator) || function (thisArg, body) {
35
- var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
36
- return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
37
- function verb(n) { return function (v) { return step([n, v]); }; }
38
- function step(op) {
39
- if (f) throw new TypeError("Generator is already executing.");
40
- while (g && (g = 0, op[0] && (_ = 0)), _) try {
41
- if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
42
- if (y = 0, t) op = [op[0] & 2, t.value];
43
- switch (op[0]) {
44
- case 0: case 1: t = op; break;
45
- case 4: _.label++; return { value: op[1], done: false };
46
- case 5: _.label++; y = op[1]; op = [0]; continue;
47
- case 7: op = _.ops.pop(); _.trys.pop(); continue;
48
- default:
49
- if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
50
- if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
51
- if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
52
- if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
53
- if (t[2]) _.ops.pop();
54
- _.trys.pop(); continue;
55
- }
56
- op = body.call(thisArg, _);
57
- } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
58
- if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
59
- }
60
- };
61
- var __read = (this && this.__read) || function (o, n) {
62
- var m = typeof Symbol === "function" && o[Symbol.iterator];
63
- if (!m) return o;
64
- var i = m.call(o), r, ar = [], e;
65
- try {
66
- while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);
67
- }
68
- catch (error) { e = { error: error }; }
69
- finally {
70
- try {
71
- if (r && !r.done && (m = i["return"])) m.call(i);
72
- }
73
- finally { if (e) throw e.error; }
74
- }
75
- return ar;
76
- };
77
- var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
78
- if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
79
- if (ar || !(i in from)) {
80
- if (!ar) ar = Array.prototype.slice.call(from, 0, i);
81
- ar[i] = from[i];
82
- }
83
- }
84
- return to.concat(ar || Array.prototype.slice.call(from));
85
- };
86
25
  Object.defineProperty(exports, "__esModule", { value: true });
87
- exports.prepareWrappedAccount = exports.topupStreamInstruction = exports.transferStreamInstruction = exports.cancelStreamInstruction = exports.updateStreamInstruction = exports.withdrawStreamInstruction = exports.createUncheckedStreamInstruction = exports.createStreamInstruction = void 0;
26
+ exports.topupStreamInstruction = exports.transferStreamInstruction = exports.cancelStreamInstruction = exports.updateStreamInstruction = exports.withdrawStreamInstruction = exports.createUncheckedStreamInstruction = exports.createStreamInstruction = void 0;
88
27
  var buffer_1 = require("buffer");
89
28
  var web3_js_1 = require("@solana/web3.js");
90
29
  var js_sha256_1 = require("js-sha256");
91
- var spl_token_1 = require("@solana/spl-token");
92
30
  var Layout = __importStar(require("./layout"));
93
31
  var createStreamInstruction = function (data, programId, accounts) {
94
32
  var keys = [
@@ -144,11 +82,7 @@ var createStreamInstruction = function (data, programId, accounts) {
144
82
  };
145
83
  var encodeLength = Layout.createStreamLayout.encode(decodedData, bufferData);
146
84
  bufferData = bufferData.slice(0, encodeLength);
147
- bufferData = buffer_1.Buffer.concat([
148
- buffer_1.Buffer.from(js_sha256_1.sha256.digest("global:create")).slice(0, 8),
149
- bufferData,
150
- buffer_1.Buffer.alloc(10),
151
- ]);
85
+ bufferData = buffer_1.Buffer.concat([buffer_1.Buffer.from(js_sha256_1.sha256.digest("global:create")).slice(0, 8), bufferData, buffer_1.Buffer.alloc(10)]);
152
86
  return new web3_js_1.TransactionInstruction({
153
87
  keys: keys,
154
88
  programId: programId,
@@ -236,11 +170,7 @@ var withdrawStreamInstruction = function (amount, programId, _a) {
236
170
  var decodedData = { amount: amount.toArrayLike(buffer_1.Buffer, "le", 8) };
237
171
  var encodeLength = Layout.withdrawStreamLayout.encode(decodedData, data);
238
172
  data = data.slice(0, encodeLength);
239
- data = buffer_1.Buffer.concat([
240
- buffer_1.Buffer.from(js_sha256_1.sha256.digest("global:withdraw")).slice(0, 8),
241
- data,
242
- buffer_1.Buffer.alloc(10),
243
- ]);
173
+ data = buffer_1.Buffer.concat([buffer_1.Buffer.from(js_sha256_1.sha256.digest("global:withdraw")).slice(0, 8), data, buffer_1.Buffer.alloc(10)]);
244
174
  return new web3_js_1.TransactionInstruction({
245
175
  keys: keys,
246
176
  programId: programId,
@@ -259,20 +189,12 @@ var updateStreamInstruction = function (params, programId, _a) {
259
189
  var data = buffer_1.Buffer.alloc(100);
260
190
  var decodedData = {
261
191
  enable_automatic_withdrawal: Number(params.enableAutomaticWithdrawal),
262
- withdraw_frequency: params.withdrawFrequency
263
- ? params.withdrawFrequency.toArrayLike(buffer_1.Buffer, "le", 8)
264
- : undefined,
265
- amount_per_period: params.amountPerPeriod
266
- ? params.amountPerPeriod.toArrayLike(buffer_1.Buffer, "le", 8)
267
- : undefined,
192
+ withdraw_frequency: params.withdrawFrequency ? params.withdrawFrequency.toArrayLike(buffer_1.Buffer, "le", 8) : undefined,
193
+ amount_per_period: params.amountPerPeriod ? params.amountPerPeriod.toArrayLike(buffer_1.Buffer, "le", 8) : undefined,
268
194
  };
269
195
  var encodeLength = Layout.encodeUpdateStream(decodedData, data);
270
196
  data = data.slice(0, encodeLength);
271
- data = buffer_1.Buffer.concat([
272
- buffer_1.Buffer.from(js_sha256_1.sha256.digest("global:update")).slice(0, 8),
273
- data,
274
- buffer_1.Buffer.alloc(20),
275
- ]);
197
+ data = buffer_1.Buffer.concat([buffer_1.Buffer.from(js_sha256_1.sha256.digest("global:update")).slice(0, 8), data, buffer_1.Buffer.alloc(20)]);
276
198
  return new web3_js_1.TransactionInstruction({
277
199
  keys: keys,
278
200
  programId: programId,
@@ -301,10 +223,7 @@ var cancelStreamInstruction = function (programId, _a) {
301
223
  { pubkey: mint, isSigner: false, isWritable: false },
302
224
  { pubkey: tokenProgram, isSigner: false, isWritable: false },
303
225
  ];
304
- var data = buffer_1.Buffer.concat([
305
- buffer_1.Buffer.from(js_sha256_1.sha256.digest("global:cancel")).slice(0, 8),
306
- buffer_1.Buffer.alloc(10),
307
- ]);
226
+ var data = buffer_1.Buffer.concat([buffer_1.Buffer.from(js_sha256_1.sha256.digest("global:cancel")).slice(0, 8), buffer_1.Buffer.alloc(10)]);
308
227
  return new web3_js_1.TransactionInstruction({
309
228
  keys: keys,
310
229
  programId: programId,
@@ -325,10 +244,7 @@ var transferStreamInstruction = function (programId, _a) {
325
244
  { pubkey: associatedTokenProgram, isSigner: false, isWritable: false },
326
245
  { pubkey: systemProgram, isSigner: false, isWritable: false },
327
246
  ];
328
- var data = buffer_1.Buffer.concat([
329
- buffer_1.Buffer.from(js_sha256_1.sha256.digest("global:transfer_recipient")).slice(0, 8),
330
- buffer_1.Buffer.alloc(10),
331
- ]);
247
+ var data = buffer_1.Buffer.concat([buffer_1.Buffer.from(js_sha256_1.sha256.digest("global:transfer_recipient")).slice(0, 8), buffer_1.Buffer.alloc(10)]);
332
248
  return new web3_js_1.TransactionInstruction({
333
249
  keys: keys,
334
250
  programId: programId,
@@ -360,11 +276,7 @@ var topupStreamInstruction = function (amount, programId, _a) {
360
276
  var decodedData = { amount: amount.toArrayLike(buffer_1.Buffer, "le", 8) };
361
277
  var encodeLength = Layout.topupStreamLayout.encode(decodedData, data);
362
278
  data = data.slice(0, encodeLength);
363
- data = buffer_1.Buffer.concat([
364
- buffer_1.Buffer.from(js_sha256_1.sha256.digest("global:topup")).slice(0, 8),
365
- data,
366
- buffer_1.Buffer.alloc(10),
367
- ]);
279
+ data = buffer_1.Buffer.concat([buffer_1.Buffer.from(js_sha256_1.sha256.digest("global:topup")).slice(0, 8), data, buffer_1.Buffer.alloc(10)]);
368
280
  return new web3_js_1.TransactionInstruction({
369
281
  keys: keys,
370
282
  programId: programId,
@@ -372,31 +284,3 @@ var topupStreamInstruction = function (amount, programId, _a) {
372
284
  });
373
285
  };
374
286
  exports.topupStreamInstruction = topupStreamInstruction;
375
- var prepareWrappedAccount = function (connection, senderAddress, amount) { return __awaiter(void 0, void 0, void 0, function () {
376
- var tokenAccount, accInfo, instructions;
377
- var _a, _b;
378
- return __generator(this, function (_c) {
379
- switch (_c.label) {
380
- case 0: return [4 /*yield*/, (0, spl_token_1.getAssociatedTokenAddress)(spl_token_1.NATIVE_MINT, senderAddress, true)];
381
- case 1:
382
- tokenAccount = _c.sent();
383
- return [4 /*yield*/, connection.getParsedAccountInfo(tokenAccount)];
384
- case 2:
385
- accInfo = _c.sent();
386
- instructions = ((_b = (_a = accInfo.value) === null || _a === void 0 ? void 0 : _a.lamports) !== null && _b !== void 0 ? _b : 0) > 0
387
- ? []
388
- : [
389
- (0, spl_token_1.createAssociatedTokenAccountInstruction)(senderAddress, tokenAccount, senderAddress, spl_token_1.NATIVE_MINT),
390
- ];
391
- return [2 /*return*/, __spreadArray(__spreadArray([], __read(instructions), false), [
392
- web3_js_1.SystemProgram.transfer({
393
- fromPubkey: senderAddress,
394
- toPubkey: tokenAccount,
395
- lamports: amount.toNumber(),
396
- }),
397
- (0, spl_token_1.createSyncNativeInstruction)(tokenAccount),
398
- ], false)];
399
- }
400
- });
401
- }); };
402
- exports.prepareWrappedAccount = prepareWrappedAccount;
@@ -1,4 +1,3 @@
1
- /// <reference types="node" />
2
1
  import * as BufferLayout from "@solana/buffer-layout";
3
2
  import { ICreateStreamLayout, ICreateUncheckedStreamLayout, IPartnerLayout, IStreamLayout, ITopupStreamLayout, IUpdateStreamLayout, IWithdrawStreamLayout } from "./instructionTypes";
4
3
  /**
@@ -129,7 +129,9 @@ exports.createUncheckedStreamLayout = BufferLayout.struct([
129
129
  /**
130
130
  * Withdraw stream instruction layout
131
131
  */
132
- exports.withdrawStreamLayout = BufferLayout.struct([BufferLayout.blob(8, "amount")]);
132
+ exports.withdrawStreamLayout = BufferLayout.struct([
133
+ BufferLayout.blob(8, "amount"),
134
+ ]);
133
135
  /**
134
136
  * Encode stream instruction layout
135
137
  */
@@ -1,6 +1,6 @@
1
- /// <reference types="node" />
2
1
  import { SignerWalletAdapter } from "@solana/wallet-adapter-base";
3
- import { AccountInfo, Connection, PublicKey, Keypair, TransactionSignature, TransactionInstruction, Transaction } from "@solana/web3.js";
2
+ import { AccountInfo, Connection, PublicKey, Keypair, TransactionSignature, Transaction } from "@solana/web3.js";
3
+ import { TransactionResponse, TxResponse } from "@streamflow/common/solana";
4
4
  import BN from "bn.js";
5
5
  import { IRecipient, Stream, StreamDirection, StreamType } from "../common/types";
6
6
  export { WalletAdapterNetwork as Cluster } from "@solana/wallet-adapter-base";
@@ -8,11 +8,13 @@ export interface Account {
8
8
  pubkey: PublicKey;
9
9
  account: AccountInfo<Buffer>;
10
10
  }
11
- export interface ICreateStreamSolanaExt {
11
+ export interface ICreateSolanaExt {
12
12
  sender: SignerWalletAdapter | Keypair;
13
+ isNative?: boolean;
14
+ }
15
+ export interface ICreateStreamSolanaExt extends ICreateSolanaExt {
13
16
  metadataPubKeys?: PublicKey[];
14
17
  partner?: string | null;
15
- isNative?: boolean;
16
18
  }
17
19
  export interface IInteractStreamSolanaExt {
18
20
  invoker: SignerWalletAdapter | Keypair;
@@ -227,16 +229,9 @@ export interface DecodedStream {
227
229
  lastRateChangeTime: BN;
228
230
  fundsUnlockedAtLastRateChange: BN;
229
231
  }
230
- export interface TransactionResponse {
231
- tx: TransactionSignature;
232
- }
233
232
  export interface CreateStreamResponse extends TransactionResponse {
234
233
  id: string;
235
234
  }
236
- export interface TxResponse {
237
- ixs: TransactionInstruction[];
238
- tx: TransactionSignature;
239
- }
240
235
  export interface CreateResponse extends TxResponse {
241
236
  metadata: Keypair;
242
237
  }
@@ -281,17 +276,6 @@ export interface CreateMultipleStreamsValues {
281
276
  referral: string;
282
277
  recipients: Recipient[];
283
278
  }
284
- export interface CheckAssociatedTokenAccountsData {
285
- sender: PublicKey;
286
- senderTokens: PublicKey;
287
- recipient: PublicKey;
288
- recipientTokens: PublicKey;
289
- partner: PublicKey;
290
- partnerTokens: PublicKey;
291
- streamflowTreasury: PublicKey;
292
- streamflowTreasuryTokens: PublicKey;
293
- mint: PublicKey;
294
- }
295
279
  export interface BatchItem {
296
280
  recipient: string;
297
281
  tx: Transaction;
@@ -302,8 +286,4 @@ export interface BatchItemSuccess extends BatchItem {
302
286
  export interface BatchItemError extends BatchItem {
303
287
  error: string;
304
288
  }
305
- export interface AtaParams {
306
- mint: PublicKey;
307
- owner: PublicKey;
308
- }
309
289
  export type BatchItemResult = BatchItemSuccess | BatchItemError;
@@ -1,30 +1,7 @@
1
- /// <reference types="node" />
2
1
  import { SignerWalletAdapter } from "@solana/wallet-adapter-base";
3
- import { Connection, Keypair, PublicKey, Transaction, BlockhashWithExpiryBlockHeight } from "@solana/web3.js";
4
- import { AtaParams, DecodedStream, Account, BatchItem, BatchItemResult } from "./types";
2
+ import { Connection, Keypair } from "@solana/web3.js";
3
+ import { DecodedStream, BatchItem, BatchItemResult } from "./types";
5
4
  export declare const decodeStream: (buf: Buffer) => DecodedStream;
6
- /**
7
- * Wrapper function for Solana web3 getProgramAccounts with slightly better call interface
8
- * @param {Connection} connection - Solana web3 connection object.
9
- * @param {PublicKey} wallet - PublicKey to compare against.
10
- * @param {number} offset - Offset of bits of the PublicKey in the account binary.
11
- * @param {PublicKey} programId - Solana program ID.
12
- * @return {Promise<Account[]>} - Array of resulting accounts.
13
- */
14
- export declare function getProgramAccounts(connection: Connection, wallet: PublicKey, offset: number, programId: PublicKey): Promise<Account[]>;
15
- /**
16
- * Utility function to check if the transaction initiator is a Wallet object
17
- * @param {Keypair | SignerWalletAdapter} walletOrKeypair - Wallet or Keypair in question
18
- * @return {boolean} - Returns true if parameter is a Wallet.
19
- */
20
- export declare function isSignerWallet(walletOrKeypair: Keypair | SignerWalletAdapter): walletOrKeypair is SignerWalletAdapter;
21
- /**
22
- * Utility function to check if the transaction initiator a Keypair object, tries to mitigate version mismatch issues
23
- * @param walletOrKeypair {Keypair | SignerWalletAdapter} walletOrKeypair - Wallet or Keypair in question
24
- * @returns {boolean} - Returns true if parameter is a Keypair.
25
- */
26
- export declare function isSignerKeypair(walletOrKeypair: Keypair | SignerWalletAdapter): walletOrKeypair is Keypair;
27
- export declare function signTransaction(invoker: Keypair | SignerWalletAdapter, tx: Transaction): Promise<Transaction>;
28
5
  /**
29
6
  * Sign passed BatchItems with wallet request or KeyPair
30
7
  * @param {Keypair | SignerWalletAdapter} sender - Wallet or Keypair of sendin account
@@ -32,15 +9,6 @@ export declare function signTransaction(invoker: Keypair | SignerWalletAdapter,
32
9
  * @return {BatchItem[]} - Returns items with signatures.
33
10
  */
34
11
  export declare function signAllTransactionWithRecipients(sender: Keypair | SignerWalletAdapter, items: BatchItem[]): Promise<BatchItem[]>;
35
- /**
36
- * Signs, sends and confirms Transaction
37
- * @param connection - Solana client connection
38
- * @param invoker - Keypair used as signer
39
- * @param tx - Transaction instance
40
- * @param hash - blockhash information, the same hash should be used in the Transaction
41
- * @returns Transaction signature
42
- */
43
- export declare function signAndExecuteTransaction(connection: Connection, invoker: Keypair | SignerWalletAdapter, tx: Transaction, hash: BlockhashWithExpiryBlockHeight): Promise<string>;
44
12
  /**
45
13
  * Sign passed BatchItems with wallet request or KeyPair
46
14
  * @param {Connection} connection - Solana web3 connection object.
@@ -48,37 +16,4 @@ export declare function signAndExecuteTransaction(connection: Connection, invoke
48
16
  * @return {Promise<BatchItemResult>} - Returns settled transaction item
49
17
  */
50
18
  export declare function sendAndConfirmStreamRawTransaction(connection: Connection, batchItem: BatchItem): Promise<BatchItemResult>;
51
- /**
52
- * Shorthand call signature for getAssociatedTokenAddress, with allowance for address to be offCurve
53
- * @param {PublicKey} mint - SPL token Mint address.
54
- * @param {PublicKey} owner - Owner of the Associated Token Address
55
- * @return {Promise<PublicKey>} - Associated Token Address
56
- */
57
- export declare function ata(mint: PublicKey, owner: PublicKey): Promise<PublicKey>;
58
- /**
59
- * Function that checks whether ATA exists for each provided owner
60
- * @param connection - Solana client connection
61
- * @param paramsBatch - Array of Params for an each ATA account: {mint, owner}
62
- * @returns Array of boolean where each members corresponds to owners member
63
- */
64
- export declare function ataBatchExist(connection: Connection, paramsBatch: AtaParams[]): Promise<boolean[]>;
65
- /**
66
- * Generates a Transaction to create ATA for an array of owners
67
- * @param connection - Solana client connection
68
- * @param payer - Transaction invoker, should be a signer
69
- * @param coparamsBatchnfigs - Array of Params for an each ATA account: {mint, owner}
70
- * @returns Unsigned Transaction with create ATA instructions
71
- */
72
- export declare function generateCreateAtaBatchTx(connection: Connection, payer: PublicKey, paramsBatch: AtaParams[]): Promise<{
73
- tx: Transaction;
74
- hash: BlockhashWithExpiryBlockHeight;
75
- }>;
76
- /**
77
- * Creates ATA for an array of owners
78
- * @param connection - Solana client connection
79
- * @param invoker - Transaction invoker and payer
80
- * @param paramsBatch - Array of Params for an each ATA account: {mint, owner}
81
- * @returns Transaction signature
82
- */
83
- export declare function createAtaBatch(connection: Connection, invoker: Keypair | SignerWalletAdapter, paramsBatch: AtaParams[]): Promise<string>;
84
19
  export declare function extractSolanaErrorCode(errorText: string): string | null;
@@ -46,38 +46,13 @@ var __generator = (this && this.__generator) || function (thisArg, body) {
46
46
  if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
47
47
  }
48
48
  };
49
- var __read = (this && this.__read) || function (o, n) {
50
- var m = typeof Symbol === "function" && o[Symbol.iterator];
51
- if (!m) return o;
52
- var i = m.call(o), r, ar = [], e;
53
- try {
54
- while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);
55
- }
56
- catch (error) { e = { error: error }; }
57
- finally {
58
- try {
59
- if (r && !r.done && (m = i["return"])) m.call(i);
60
- }
61
- finally { if (e) throw e.error; }
62
- }
63
- return ar;
64
- };
65
- var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
66
- if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
67
- if (ar || !(i in from)) {
68
- if (!ar) ar = Array.prototype.slice.call(from, 0, i);
69
- ar[i] = from[i];
70
- }
71
- }
72
- return to.concat(ar || Array.prototype.slice.call(from));
73
- };
74
49
  var __importDefault = (this && this.__importDefault) || function (mod) {
75
50
  return (mod && mod.__esModule) ? mod : { "default": mod };
76
51
  };
77
52
  Object.defineProperty(exports, "__esModule", { value: true });
78
- exports.extractSolanaErrorCode = exports.createAtaBatch = exports.generateCreateAtaBatchTx = exports.ataBatchExist = exports.ata = exports.sendAndConfirmStreamRawTransaction = exports.signAndExecuteTransaction = exports.signAllTransactionWithRecipients = exports.signTransaction = exports.isSignerKeypair = exports.isSignerWallet = exports.getProgramAccounts = exports.decodeStream = void 0;
79
- var spl_token_1 = require("@solana/spl-token");
53
+ exports.extractSolanaErrorCode = exports.sendAndConfirmStreamRawTransaction = exports.signAllTransactionWithRecipients = exports.decodeStream = void 0;
80
54
  var web3_js_1 = require("@solana/web3.js");
55
+ var solana_1 = require("@streamflow/common/solana");
81
56
  var bn_js_1 = __importDefault(require("bn.js"));
82
57
  var bs58_1 = __importDefault(require("bs58"));
83
58
  var layout_1 = require("./layout");
@@ -132,72 +107,6 @@ var decodeStream = function (buf) {
132
107
  };
133
108
  };
134
109
  exports.decodeStream = decodeStream;
135
- /**
136
- * Wrapper function for Solana web3 getProgramAccounts with slightly better call interface
137
- * @param {Connection} connection - Solana web3 connection object.
138
- * @param {PublicKey} wallet - PublicKey to compare against.
139
- * @param {number} offset - Offset of bits of the PublicKey in the account binary.
140
- * @param {PublicKey} programId - Solana program ID.
141
- * @return {Promise<Account[]>} - Array of resulting accounts.
142
- */
143
- function getProgramAccounts(connection, wallet, offset, programId) {
144
- return __awaiter(this, void 0, void 0, function () {
145
- return __generator(this, function (_a) {
146
- return [2 /*return*/, connection === null || connection === void 0 ? void 0 : connection.getProgramAccounts(programId, {
147
- filters: [
148
- {
149
- memcmp: {
150
- offset: offset,
151
- bytes: wallet.toBase58(),
152
- },
153
- },
154
- ],
155
- })];
156
- });
157
- });
158
- }
159
- exports.getProgramAccounts = getProgramAccounts;
160
- /**
161
- * Utility function to check if the transaction initiator is a Wallet object
162
- * @param {Keypair | SignerWalletAdapter} walletOrKeypair - Wallet or Keypair in question
163
- * @return {boolean} - Returns true if parameter is a Wallet.
164
- */
165
- function isSignerWallet(walletOrKeypair) {
166
- return walletOrKeypair.signTransaction !== undefined;
167
- }
168
- exports.isSignerWallet = isSignerWallet;
169
- /**
170
- * Utility function to check if the transaction initiator a Keypair object, tries to mitigate version mismatch issues
171
- * @param walletOrKeypair {Keypair | SignerWalletAdapter} walletOrKeypair - Wallet or Keypair in question
172
- * @returns {boolean} - Returns true if parameter is a Keypair.
173
- */
174
- function isSignerKeypair(walletOrKeypair) {
175
- return (walletOrKeypair instanceof web3_js_1.Keypair ||
176
- walletOrKeypair.constructor === web3_js_1.Keypair ||
177
- walletOrKeypair.constructor.name === web3_js_1.Keypair.prototype.constructor.name);
178
- }
179
- exports.isSignerKeypair = isSignerKeypair;
180
- function signTransaction(invoker, tx) {
181
- return __awaiter(this, void 0, void 0, function () {
182
- var signedTx;
183
- return __generator(this, function (_a) {
184
- switch (_a.label) {
185
- case 0:
186
- if (!isSignerWallet(invoker)) return [3 /*break*/, 2];
187
- return [4 /*yield*/, invoker.signTransaction(tx)];
188
- case 1:
189
- signedTx = _a.sent();
190
- return [3 /*break*/, 3];
191
- case 2:
192
- tx.partialSign(invoker);
193
- signedTx = tx;
194
- _a.label = 3;
195
- case 3: return [2 /*return*/, signedTx];
196
- }
197
- });
198
- });
199
- }
200
- exports.signTransaction = signTransaction;
201
110
  /**
202
111
  * Sign passed BatchItems with wallet request or KeyPair
203
112
  * @param {Keypair | SignerWalletAdapter} sender - Wallet or Keypair of sendin account
@@ -210,8 +119,8 @@ function signAllTransactionWithRecipients(sender, items) {
210
119
  return __generator(this, function (_a) {
211
120
  switch (_a.label) {
212
121
  case 0:
213
- isKeypair = isSignerKeypair(sender);
214
- isWallet = isSignerWallet(sender);
122
+ isKeypair = (0, solana_1.isSignerKeypair)(sender);
123
+ isWallet = (0, solana_1.isSignerWallet)(sender);
215
124
  if (!isKeypair) return [3 /*break*/, 1];
216
125
  return [2 /*return*/, items.map(function (t) {
217
126
  t.tx.partialSign(sender);
@@ -231,39 +140,6 @@ function signAllTransactionWithRecipients(sender, items) {
231
140
  });
232
141
  }
233
142
  exports.signAllTransactionWithRecipients = signAllTransactionWithRecipients;
234
- /**
235
- * Signs, sends and confirms Transaction
236
- * @param connection - Solana client connection
237
- * @param invoker - Keypair used as signer
238
- * @param tx - Transaction instance
239
- * @param hash - blockhash information, the same hash should be used in the Transaction
240
- * @returns Transaction signature
241
- */
242
- function signAndExecuteTransaction(connection, invoker, tx, hash) {
243
- return __awaiter(this, void 0, void 0, function () {
244
- var signedTx, rawTx, confirmationStrategy, signature;
245
- return __generator(this, function (_a) {
246
- switch (_a.label) {
247
- case 0: return [4 /*yield*/, signTransaction(invoker, tx)];
248
- case 1:
249
- signedTx = _a.sent();
250
- rawTx = signedTx.serialize();
251
- if (!hash.lastValidBlockHeight || !signedTx.signature || !hash.blockhash)
252
- throw Error("Error with transaction parameters.");
253
- confirmationStrategy = {
254
- lastValidBlockHeight: hash.lastValidBlockHeight,
255
- signature: bs58_1.default.encode(signedTx.signature),
256
- blockhash: hash.blockhash,
257
- };
258
- return [4 /*yield*/, (0, web3_js_1.sendAndConfirmRawTransaction)(connection, rawTx, confirmationStrategy)];
259
- case 2:
260
- signature = _a.sent();
261
- return [2 /*return*/, signature];
262
- }
263
- });
264
- });
265
- }
266
- exports.signAndExecuteTransaction = signAndExecuteTransaction;
267
143
  /**
268
144
  * Sign passed BatchItems with wallet request or KeyPair
269
145
  * @param {Connection} connection - Solana web3 connection object.
@@ -303,122 +179,6 @@ function sendAndConfirmStreamRawTransaction(connection, batchItem) {
303
179
  });
304
180
  }
305
181
  exports.sendAndConfirmStreamRawTransaction = sendAndConfirmStreamRawTransaction;
306
- /**
307
- * Shorthand call signature for getAssociatedTokenAddress, with allowance for address to be offCurve
308
- * @param {PublicKey} mint - SPL token Mint address.
309
- * @param {PublicKey} owner - Owner of the Associated Token Address
310
- * @return {Promise<PublicKey>} - Associated Token Address
311
- */
312
- function ata(mint, owner) {
313
- return (0, spl_token_1.getAssociatedTokenAddress)(mint, owner, true);
314
- }
315
- exports.ata = ata;
316
- /**
317
- * Function that checks whether ATA exists for each provided owner
318
- * @param connection - Solana client connection
319
- * @param paramsBatch - Array of Params for an each ATA account: {mint, owner}
320
- * @returns Array of boolean where each members corresponds to owners member
321
- */
322
- function ataBatchExist(connection, paramsBatch) {
323
- return __awaiter(this, void 0, void 0, function () {
324
- var tokenAccounts, response;
325
- var _this = this;
326
- return __generator(this, function (_a) {
327
- switch (_a.label) {
328
- case 0: return [4 /*yield*/, Promise.all(paramsBatch.map(function (_a) {
329
- var mint = _a.mint, owner = _a.owner;
330
- return __awaiter(_this, void 0, void 0, function () {
331
- var pubkey;
332
- return __generator(this, function (_b) {
333
- switch (_b.label) {
334
- case 0: return [4 /*yield*/, ata(mint, owner)];
335
- case 1:
336
- pubkey = _b.sent();
337
- return [2 /*return*/, pubkey];
338
- }
339
- });
340
- });
341
- }))];
342
- case 1:
343
- tokenAccounts = _a.sent();
344
- return [4 /*yield*/, connection.getMultipleAccountsInfo(tokenAccounts)];
345
- case 2:
346
- response = _a.sent();
347
- return [2 /*return*/, response.map(function (accInfo) { return !!accInfo; })];
348
- }
349
- });
350
- });
351
- }
352
- exports.ataBatchExist = ataBatchExist;
353
- /**
354
- * Generates a Transaction to create ATA for an array of owners
355
- * @param connection - Solana client connection
356
- * @param payer - Transaction invoker, should be a signer
357
- * @param coparamsBatchnfigs - Array of Params for an each ATA account: {mint, owner}
358
- * @returns Unsigned Transaction with create ATA instructions
359
- */
360
- function generateCreateAtaBatchTx(connection, payer, paramsBatch) {
361
- return __awaiter(this, void 0, void 0, function () {
362
- var ixs, hash, tx;
363
- var _a;
364
- var _this = this;
365
- return __generator(this, function (_b) {
366
- switch (_b.label) {
367
- case 0: return [4 /*yield*/, Promise.all(paramsBatch.map(function (_a) {
368
- var mint = _a.mint, owner = _a.owner;
369
- return __awaiter(_this, void 0, void 0, function () {
370
- var _b, _c;
371
- return __generator(this, function (_d) {
372
- switch (_d.label) {
373
- case 0:
374
- _b = spl_token_1.createAssociatedTokenAccountInstruction;
375
- _c = [payer];
376
- return [4 /*yield*/, ata(mint, owner)];
377
- case 1: return [2 /*return*/, _b.apply(void 0, _c.concat([_d.sent(), owner, mint]))];
378
- }
379
- });
380
- });
381
- }))];
382
- case 1:
383
- ixs = _b.sent();
384
- return [4 /*yield*/, connection.getLatestBlockhash()];
385
- case 2:
386
- hash = _b.sent();
387
- tx = (_a = new web3_js_1.Transaction({
388
- feePayer: payer,
389
- blockhash: hash.blockhash,
390
- lastValidBlockHeight: hash.lastValidBlockHeight,
391
- })).add.apply(_a, __spreadArray([], __read(ixs), false));
392
- return [2 /*return*/, { tx: tx, hash: hash }];
393
- }
394
- });
395
- });
396
- }
397
- exports.generateCreateAtaBatchTx = generateCreateAtaBatchTx;
398
- /**
399
- * Creates ATA for an array of owners
400
- * @param connection - Solana client connection
401
- * @param invoker - Transaction invoker and payer
402
- * @param paramsBatch - Array of Params for an each ATA account: {mint, owner}
403
- * @returns Transaction signature
404
- */
405
- function createAtaBatch(connection, invoker, paramsBatch) {
406
- return __awaiter(this, void 0, void 0, function () {
407
- var _a, tx, hash, signature;
408
- return __generator(this, function (_b) {
409
- switch (_b.label) {
410
- case 0: return [4 /*yield*/, generateCreateAtaBatchTx(connection, invoker.publicKey, paramsBatch)];
411
- case 1:
412
- _a = _b.sent(), tx = _a.tx, hash = _a.hash;
413
- return [4 /*yield*/, signAndExecuteTransaction(connection, invoker, tx, hash)];
414
- case 2:
415
- signature = _b.sent();
416
- return [2 /*return*/, signature];
417
- }
418
- });
419
- });
420
- }
421
- exports.createAtaBatch = createAtaBatch;
422
182
  function extractSolanaErrorCode(errorText) {
423
183
  var match = constants_1.SOLANA_ERROR_MATCH_REGEX.exec(errorText);
424
184
  if (!match) {