@streamflow/stream 3.0.18 → 3.0.19

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (52) hide show
  1. package/dist/Stream.d.ts +87 -0
  2. package/dist/Stream.js +503 -0
  3. package/dist/StreamClient.d.ts +146 -0
  4. package/dist/{solana/StreamClient.js → StreamClient.js} +397 -301
  5. package/dist/__tests__/test_dependencies/airdrop/airdrop-request.d.ts +3 -0
  6. package/dist/__tests__/test_dependencies/airdrop/airdrop-request.js +67 -0
  7. package/dist/__tests__/test_dependencies/airdrop/airdrop.d.ts +6 -0
  8. package/dist/__tests__/test_dependencies/airdrop/airdrop.js +215 -0
  9. package/dist/__tests__/test_dependencies/constants/index.d.ts +122 -0
  10. package/dist/__tests__/test_dependencies/constants/index.js +158 -0
  11. package/dist/__tests__/test_dependencies/idl/airdrop.d.ts +27 -0
  12. package/dist/__tests__/test_dependencies/idl/airdrop.js +171 -0
  13. package/dist/{solana/constants.d.ts → constants.d.ts} +1 -1
  14. package/dist/{solana/constants.js → constants.js} +5 -5
  15. package/dist/{solana/timelockIDL.d.ts → idl/timelock.d.ts} +0 -0
  16. package/dist/{solana/timelockIDL.js → idl/timelock.js} +0 -0
  17. package/dist/index.d.ts +6 -5
  18. package/dist/index.js +10 -19
  19. package/dist/{solana/instructions.d.ts → instructions.d.ts} +2 -8
  20. package/dist/{solana/instructions.js → instructions.js} +38 -55
  21. package/dist/layout.d.ts +22 -0
  22. package/dist/{solana/layout.js → layout.js} +3 -65
  23. package/dist/{solana/types.d.ts → types.d.ts} +34 -37
  24. package/dist/{solana/types.js → types.js} +20 -3
  25. package/dist/{common/utils.d.ts → utils.d.ts} +4 -0
  26. package/dist/utils.js +126 -0
  27. package/package.json +1 -1
  28. package/dist/__tests__/aptos/streamClient.spec.d.ts +0 -1
  29. package/dist/__tests__/aptos/streamClient.spec.js +0 -160
  30. package/dist/aptos/StreamClient.d.ts +0 -49
  31. package/dist/aptos/StreamClient.js +0 -362
  32. package/dist/aptos/constants.d.ts +0 -2
  33. package/dist/aptos/constants.js +0 -12
  34. package/dist/aptos/index.d.ts +0 -2
  35. package/dist/aptos/index.js +0 -24
  36. package/dist/aptos/types.d.ts +0 -145
  37. package/dist/aptos/types.js +0 -65
  38. package/dist/common/BaseStreamClient.d.ts +0 -11
  39. package/dist/common/BaseStreamClient.js +0 -9
  40. package/dist/common/GenericStreamClient.d.ts +0 -60
  41. package/dist/common/GenericStreamClient.js +0 -137
  42. package/dist/common/types.d.ts +0 -71
  43. package/dist/common/types.js +0 -28
  44. package/dist/common/utils.js +0 -31
  45. package/dist/solana/StreamClient.d.ts +0 -71
  46. package/dist/solana/index.d.ts +0 -7
  47. package/dist/solana/index.js +0 -43
  48. package/dist/solana/instructionTypes.d.ts +0 -86
  49. package/dist/solana/instructionTypes.js +0 -2
  50. package/dist/solana/layout.d.ts +0 -27
  51. package/dist/solana/utils.d.ts +0 -42
  52. package/dist/solana/utils.js +0 -271
@@ -1,271 +0,0 @@
1
- "use strict";
2
- var __assign = (this && this.__assign) || function () {
3
- __assign = Object.assign || function(t) {
4
- for (var s, i = 1, n = arguments.length; i < n; i++) {
5
- s = arguments[i];
6
- for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
7
- t[p] = s[p];
8
- }
9
- return t;
10
- };
11
- return __assign.apply(this, arguments);
12
- };
13
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
14
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
15
- return new (P || (P = Promise))(function (resolve, reject) {
16
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
17
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
18
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
19
- step((generator = generator.apply(thisArg, _arguments || [])).next());
20
- });
21
- };
22
- var __generator = (this && this.__generator) || function (thisArg, body) {
23
- var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
24
- return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
25
- function verb(n) { return function (v) { return step([n, v]); }; }
26
- function step(op) {
27
- if (f) throw new TypeError("Generator is already executing.");
28
- while (_) try {
29
- 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;
30
- if (y = 0, t) op = [op[0] & 2, t.value];
31
- switch (op[0]) {
32
- case 0: case 1: t = op; break;
33
- case 4: _.label++; return { value: op[1], done: false };
34
- case 5: _.label++; y = op[1]; op = [0]; continue;
35
- case 7: op = _.ops.pop(); _.trys.pop(); continue;
36
- default:
37
- if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
38
- if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
39
- if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
40
- if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
41
- if (t[2]) _.ops.pop();
42
- _.trys.pop(); continue;
43
- }
44
- op = body.call(thisArg, _);
45
- } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
46
- if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
47
- }
48
- };
49
- var __importDefault = (this && this.__importDefault) || function (mod) {
50
- return (mod && mod.__esModule) ? mod : { "default": mod };
51
- };
52
- Object.defineProperty(exports, "__esModule", { value: true });
53
- exports.ata = exports.sendAndConfirmStreamRawTransaction = exports.signAllTransactionWithRecipients = exports.isSignerWallet = exports.getProgramAccounts = exports.formatDecodedStream = exports.decodeStream = void 0;
54
- var spl_token_1 = require("@solana/spl-token");
55
- var web3_js_1 = require("@solana/web3.js");
56
- var bn_js_1 = __importDefault(require("bn.js"));
57
- var bs58_1 = __importDefault(require("bs58"));
58
- var layout_1 = require("./layout");
59
- var decoder = new TextDecoder("utf-8");
60
- var LE = "le"; //little endian
61
- var decodeStream = function (buf) {
62
- var raw = layout_1.streamLayout.decode(buf);
63
- return {
64
- magic: new bn_js_1.default(raw.magic, LE),
65
- version: new bn_js_1.default(raw.version, LE),
66
- createdAt: new bn_js_1.default(raw.created_at, LE),
67
- withdrawnAmount: new bn_js_1.default(raw.withdrawn_amount, LE),
68
- canceledAt: new bn_js_1.default(raw.canceled_at, LE),
69
- end: new bn_js_1.default(raw.end_time, LE),
70
- lastWithdrawnAt: new bn_js_1.default(raw.last_withdrawn_at, LE),
71
- sender: new web3_js_1.PublicKey(raw.sender),
72
- senderTokens: new web3_js_1.PublicKey(raw.sender_tokens),
73
- recipient: new web3_js_1.PublicKey(raw.recipient),
74
- recipientTokens: new web3_js_1.PublicKey(raw.recipient_tokens),
75
- mint: new web3_js_1.PublicKey(raw.mint),
76
- escrowTokens: new web3_js_1.PublicKey(raw.escrow_tokens),
77
- streamflowTreasury: new web3_js_1.PublicKey(raw.streamflow_treasury),
78
- streamflowTreasuryTokens: new web3_js_1.PublicKey(raw.streamflow_treasury_tokens),
79
- streamflowFeeTotal: new bn_js_1.default(raw.streamflow_fee_total, LE),
80
- streamflowFeeWithdrawn: new bn_js_1.default(raw.streamflow_fee_withdrawn, LE),
81
- streamflowFeePercent: new bn_js_1.default(raw.streamflow_fee_percent, LE),
82
- partnerFeeTotal: new bn_js_1.default(raw.partner_fee_total, LE),
83
- partnerFeeWithdrawn: new bn_js_1.default(raw.partner_fee_withdrawn, LE),
84
- partnerFeePercent: new bn_js_1.default(raw.partner_fee_percent, LE),
85
- partner: new web3_js_1.PublicKey(raw.partner),
86
- partnerTokens: new web3_js_1.PublicKey(raw.partner_tokens),
87
- start: new bn_js_1.default(raw.start_time, LE),
88
- depositedAmount: new bn_js_1.default(raw.net_amount_deposited, LE),
89
- period: new bn_js_1.default(raw.period, LE),
90
- amountPerPeriod: new bn_js_1.default(raw.amount_per_period, LE),
91
- cliff: new bn_js_1.default(raw.cliff, LE),
92
- cliffAmount: new bn_js_1.default(raw.cliff_amount, LE),
93
- cancelableBySender: Boolean(raw.cancelable_by_sender),
94
- cancelableByRecipient: Boolean(raw.cancelable_by_recipient),
95
- automaticWithdrawal: Boolean(raw.automatic_withdrawal),
96
- transferableBySender: Boolean(raw.transferable_by_sender),
97
- transferableByRecipient: Boolean(raw.transferable_by_recipient),
98
- canTopup: Boolean(raw.can_topup),
99
- name: decoder.decode(raw.stream_name),
100
- withdrawFrequency: new bn_js_1.default(raw.withdraw_frequency, LE),
101
- };
102
- };
103
- exports.decodeStream = decodeStream;
104
- // DeprecationWarning: This object will be deprecated starting from the version 4.0.0. Use
105
- // types/Contract instead
106
- var formatDecodedStream = function (stream) {
107
- var _a;
108
- var resp = {
109
- magic: stream.magic.toNumber(),
110
- version: stream.version.toNumber(),
111
- createdAt: stream.createdAt.toNumber(),
112
- withdrawnAmount: stream.withdrawnAmount,
113
- canceledAt: stream.canceledAt.toNumber(),
114
- end: stream.end.toNumber(),
115
- lastWithdrawnAt: stream.lastWithdrawnAt.toNumber(),
116
- sender: stream.sender.toBase58(),
117
- senderTokens: stream.senderTokens.toBase58(),
118
- recipient: stream.recipient.toBase58(),
119
- recipientTokens: stream.recipientTokens.toBase58(),
120
- mint: stream.mint.toBase58(),
121
- escrowTokens: stream.escrowTokens.toBase58(),
122
- streamflowTreasury: stream.streamflowTreasury.toBase58(),
123
- streamflowTreasuryTokens: stream.streamflowTreasuryTokens.toBase58(),
124
- streamflowFeeTotal: stream.streamflowFeeTotal,
125
- streamflowFeeWithdrawn: stream.streamflowFeeWithdrawn,
126
- streamflowFeePercent: stream.streamflowFeePercent.toNumber(),
127
- partnerFeeTotal: stream.partnerFeeTotal,
128
- partnerFeeWithdrawn: stream.partnerFeeWithdrawn,
129
- partnerFeePercent: stream.partnerFeePercent.toNumber(),
130
- partner: stream.partner.toBase58(),
131
- partnerTokens: (_a = stream.partnerTokens) === null || _a === void 0 ? void 0 : _a.toBase58(),
132
- start: stream.start.toNumber(),
133
- depositedAmount: stream.depositedAmount,
134
- period: stream.period.toNumber(),
135
- amountPerPeriod: stream.amountPerPeriod,
136
- cliff: stream.cliff.toNumber(),
137
- cliffAmount: stream.cliffAmount,
138
- cancelableBySender: stream.cancelableBySender,
139
- cancelableByRecipient: stream.cancelableByRecipient,
140
- automaticWithdrawal: stream.automaticWithdrawal,
141
- transferableBySender: stream.transferableBySender,
142
- transferableByRecipient: stream.transferableByRecipient,
143
- canTopup: stream.canTopup,
144
- name: stream.name,
145
- withdrawalFrequency: stream.withdrawFrequency.toNumber(),
146
- unlocked: function () {
147
- return 0;
148
- },
149
- withdrawn: function () {
150
- return new bn_js_1.default(0);
151
- }, //phantom method to preserve partial support of this object
152
- };
153
- return resp;
154
- };
155
- exports.formatDecodedStream = formatDecodedStream;
156
- /**
157
- * Wrapper function for Solana web3 getProgramAccounts with slightly better call interface
158
- * @param {Connection} connection - Solana web3 connection object.
159
- * @param {PublicKey} wallet - PublicKey to compare against.
160
- * @param {number} offset - Offset of bits of the PublicKey in the account binary.
161
- * @param {PublicKey} programId - Solana program ID.
162
- * @return {Promise<Account[]>} - Array of resulting accounts.
163
- */
164
- function getProgramAccounts(connection, wallet, offset, programId) {
165
- return __awaiter(this, void 0, void 0, function () {
166
- return __generator(this, function (_a) {
167
- return [2 /*return*/, connection === null || connection === void 0 ? void 0 : connection.getProgramAccounts(programId, {
168
- filters: [
169
- {
170
- memcmp: {
171
- offset: offset,
172
- bytes: wallet.toBase58(),
173
- },
174
- },
175
- ],
176
- })];
177
- });
178
- });
179
- }
180
- exports.getProgramAccounts = getProgramAccounts;
181
- /**
182
- * Utility function to check if the transaction initiator is a KeyPair or a Wallet object
183
- * @param {Keypair | SignerWalletAdapter} walletOrKeypair - Wallet or Keypair in question
184
- * @return {boolean} - Returns true if parameter is a Wallet.
185
- */
186
- function isSignerWallet(walletOrKeypair) {
187
- return walletOrKeypair.signTransaction !== undefined;
188
- }
189
- exports.isSignerWallet = isSignerWallet;
190
- /**
191
- * Sign passed BatchItems with wallet request or KeyPair
192
- * @param {Keypair | SignerWalletAdapter} sender - Wallet or Keypair of sendin account
193
- * @param {BatchItem[]} items - Multiple recipient contracts split into separate items
194
- * @return {BatchItem[]} - Returns items with signatures.
195
- */
196
- function signAllTransactionWithRecipients(sender, items) {
197
- return __awaiter(this, void 0, void 0, function () {
198
- var isKeypair, isWallet, signedTxs_1;
199
- return __generator(this, function (_a) {
200
- switch (_a.label) {
201
- case 0:
202
- isKeypair = sender instanceof web3_js_1.Keypair;
203
- isWallet = isSignerWallet(sender);
204
- if (!isKeypair) return [3 /*break*/, 1];
205
- return [2 /*return*/, items.map(function (t) {
206
- t.tx.partialSign(sender);
207
- return { tx: t.tx, recipient: t.recipient };
208
- })];
209
- case 1:
210
- if (!isWallet) return [3 /*break*/, 3];
211
- return [4 /*yield*/, sender.signAllTransactions(items.map(function (t) { return t.tx; }))];
212
- case 2:
213
- signedTxs_1 = _a.sent();
214
- return [2 /*return*/, items.map(function (item, index) { return (__assign(__assign({}, item), { tx: signedTxs_1[index] })); })];
215
- case 3:
216
- // If signer is not passed
217
- return [2 /*return*/, []];
218
- }
219
- });
220
- });
221
- }
222
- exports.signAllTransactionWithRecipients = signAllTransactionWithRecipients;
223
- /**
224
- * Sign passed BatchItems with wallet request or KeyPair
225
- * @param {Connection} connection - Solana web3 connection object.
226
- * @param {BatchItem} batchItem - Signed transaction ready to be send.
227
- * @return {Promise<BatchItemResult>} - Returns settled transaction item
228
- */
229
- function sendAndConfirmStreamRawTransaction(connection, batchItem) {
230
- var _a, _b;
231
- return __awaiter(this, void 0, void 0, function () {
232
- var rawTx, _c, lastValidBlockHeight, signature, recentBlockhash, confirmationStrategy, completedTxSignature, error_1;
233
- return __generator(this, function (_d) {
234
- switch (_d.label) {
235
- case 0:
236
- _d.trys.push([0, 2, , 3]);
237
- rawTx = batchItem.tx.serialize();
238
- _c = batchItem.tx, lastValidBlockHeight = _c.lastValidBlockHeight, signature = _c.signature, recentBlockhash = _c.recentBlockhash;
239
- if (!lastValidBlockHeight || !signature || !recentBlockhash)
240
- throw { recipient: batchItem.recipient, error: "no recent blockhash" };
241
- confirmationStrategy = {
242
- lastValidBlockHeight: lastValidBlockHeight,
243
- signature: bs58_1.default.encode(signature),
244
- blockhash: recentBlockhash,
245
- };
246
- return [4 /*yield*/, (0, web3_js_1.sendAndConfirmRawTransaction)(connection, rawTx, confirmationStrategy, { skipPreflight: true })];
247
- case 1:
248
- completedTxSignature = _d.sent();
249
- return [2 /*return*/, __assign(__assign({}, batchItem), { signature: completedTxSignature })];
250
- case 2:
251
- error_1 = _d.sent();
252
- throw {
253
- recipient: batchItem.recipient,
254
- error: (_b = (_a = error_1 === null || error_1 === void 0 ? void 0 : error_1.error) !== null && _a !== void 0 ? _a : error_1 === null || error_1 === void 0 ? void 0 : error_1.message) !== null && _b !== void 0 ? _b : error_1.toString(),
255
- };
256
- case 3: return [2 /*return*/];
257
- }
258
- });
259
- });
260
- }
261
- exports.sendAndConfirmStreamRawTransaction = sendAndConfirmStreamRawTransaction;
262
- /**
263
- * Shorthand call signature for getAssociatedTokenAddress, with allowance for address to be offCurve
264
- * @param {PublicKey} mint - SPL token Mint address.
265
- * @param {PublicKey} owner - Owner of the Associated Token Address
266
- * @return {Promise<PublicKey>} - Associated Token Address
267
- */
268
- function ata(mint, owner) {
269
- return (0, spl_token_1.getAssociatedTokenAddress)(mint, owner, true);
270
- }
271
- exports.ata = ata;