@streamflow/stream 3.0.11 → 3.0.13
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.
- package/dist/StreamClient.d.ts +7 -4
- package/dist/StreamClient.js +123 -121
- package/dist/constants.d.ts +1 -0
- package/dist/constants.js +2 -1
- package/dist/instructions.d.ts +4 -1
- package/dist/instructions.js +107 -1
- package/dist/types.d.ts +3 -0
- package/package.json +4 -8
- package/dist/__tests__/streams.spec.d.ts +0 -0
- package/dist/__tests__/streams.spec.js +0 -166
package/dist/StreamClient.d.ts
CHANGED
|
@@ -33,9 +33,10 @@ export default class StreamClient {
|
|
|
33
33
|
* @param {boolean} data.transferableByRecipient - Whether or not recipient can transfer the stream.
|
|
34
34
|
* @param {boolean} data.automaticWithdrawal - Whether or not a 3rd party can initiate withdraw in the name of recipient.
|
|
35
35
|
* @param {number} [data.withdrawalFrequency = 0] - Relevant when automatic withdrawal is enabled. If greater than 0 our withdrawor will take care of withdrawals. If equal to 0 our withdrawor will skip, but everyone else can initiate withdrawals.
|
|
36
|
+
* @param {boolean} [data.isNative = false] - When true Automatically wraps SOLs to WrappedSOL and creates wSOL stream
|
|
36
37
|
* @param {string | null} [data.partner = null] - Partner's wallet address (optional).
|
|
37
38
|
*/
|
|
38
|
-
create({ sender, recipient, mint, start, depositedAmount, period, cliff, cliffAmount, amountPerPeriod, name, canTopup, cancelableBySender, cancelableByRecipient, transferableBySender, transferableByRecipient, automaticWithdrawal, withdrawalFrequency, partner, }: CreateParams): Promise<CreateResponse>;
|
|
39
|
+
create({ sender, recipient, mint, start, depositedAmount, period, cliff, cliffAmount, amountPerPeriod, name, canTopup, cancelableBySender, cancelableByRecipient, transferableBySender, transferableByRecipient, automaticWithdrawal, withdrawalFrequency, partner, isNative, }: CreateParams): Promise<CreateResponse>;
|
|
39
40
|
/**
|
|
40
41
|
* Creates a new stream/vesting contract using unchecked instruction.
|
|
41
42
|
*
|
|
@@ -64,9 +65,10 @@ export default class StreamClient {
|
|
|
64
65
|
* @param {boolean} data.transferableByRecipient - Whether or not recipient can transfer the stream.
|
|
65
66
|
* @param {boolean} data.automaticWithdrawal - Whether or not a 3rd party can initiate withdraw in the name of recipient.
|
|
66
67
|
* @param {number} [data.withdrawalFrequency = 0] - Relevant when automatic withdrawal is enabled. If greater than 0 our withdrawor will take care of withdrawals. If equal to 0 our withdrawor will skip, but everyone else can initiate withdrawals.
|
|
67
|
-
* @param {
|
|
68
|
+
* @param {boolean} [data.isNative = false] - When true Automatically wraps SOLs to WrappedSOL and creates wSOL stream
|
|
69
|
+
* @param {string | null} [data.partner = null] - Partner's wallet address (optional).
|
|
68
70
|
*/
|
|
69
|
-
createUnchecked({ sender, recipient, mint, start, depositedAmount, period, cliff, cliffAmount, amountPerPeriod, name, canTopup, cancelableBySender, cancelableByRecipient, transferableBySender, transferableByRecipient, automaticWithdrawal, withdrawalFrequency, partner, }: CreateParams): Promise<CreateResponse>;
|
|
71
|
+
createUnchecked({ sender, recipient, mint, start, depositedAmount, period, cliff, cliffAmount, amountPerPeriod, name, canTopup, cancelableBySender, cancelableByRecipient, transferableBySender, transferableByRecipient, automaticWithdrawal, withdrawalFrequency, partner, isNative, }: CreateParams): Promise<CreateResponse>;
|
|
70
72
|
/**
|
|
71
73
|
* Creates a new stream/vesting contract.
|
|
72
74
|
* All fees are paid by sender (escrow metadata account rent, escrow token account rent, recipient's associated token account rent, Streamflow's service fee).
|
|
@@ -84,6 +86,7 @@ export default class StreamClient {
|
|
|
84
86
|
* @param {boolean} data.transferableByRecipient - Whether or not recipient can transfer the stream.
|
|
85
87
|
* @param {boolean} data.automaticWithdrawal - Whether or not a 3rd party can initiate withdraw in the name of recipient.
|
|
86
88
|
* @param {number} [data.withdrawalFrequency = 0] - Relevant when automatic withdrawal is enabled. If greater than 0 our withdrawor will take care of withdrawals. If equal to 0 our withdrawor will skip, but everyone else can initiate withdrawals.
|
|
89
|
+
* @param {boolean} [data.isNative = false] - When true Automatically wraps SOLs to WrappedSOL and creates wSOL stream
|
|
87
90
|
* @param {string | null} [data.partner = null] - Partner's wallet address (optional).
|
|
88
91
|
*/
|
|
89
92
|
createMultiple(data: CreateMultiParams): Promise<CreateMultiResponse>;
|
|
@@ -118,7 +121,7 @@ export default class StreamClient {
|
|
|
118
121
|
* @param {string} data.id - Identifier of a stream (escrow account with metadata) to be topped up.
|
|
119
122
|
* @param {BN} data.amount - Specified amount (in the smallest units) to topup (increases deposited amount).
|
|
120
123
|
*/
|
|
121
|
-
topup({ invoker, id, amount, }: TopupParams): Promise<TxResponse>;
|
|
124
|
+
topup({ invoker, id, amount, isNative, }: TopupParams): Promise<TxResponse>;
|
|
122
125
|
/**
|
|
123
126
|
* Fetch stream data by its id (address).
|
|
124
127
|
* @param {string} id - Identifier of a stream that is fetched.
|
package/dist/StreamClient.js
CHANGED
|
@@ -96,7 +96,6 @@ var types_1 = require("./types");
|
|
|
96
96
|
var utils_1 = require("./utils");
|
|
97
97
|
var constants_1 = require("./constants");
|
|
98
98
|
var instructions_1 = require("./instructions");
|
|
99
|
-
var common_1 = require("@project-serum/common");
|
|
100
99
|
var bs58_1 = require("@project-serum/anchor/dist/cjs/utils/bytes/bs58");
|
|
101
100
|
var METADATA_ACC_SIZE = 1104;
|
|
102
101
|
var StreamClient = /** @class */ (function () {
|
|
@@ -142,38 +141,49 @@ var StreamClient = /** @class */ (function () {
|
|
|
142
141
|
* @param {boolean} data.transferableByRecipient - Whether or not recipient can transfer the stream.
|
|
143
142
|
* @param {boolean} data.automaticWithdrawal - Whether or not a 3rd party can initiate withdraw in the name of recipient.
|
|
144
143
|
* @param {number} [data.withdrawalFrequency = 0] - Relevant when automatic withdrawal is enabled. If greater than 0 our withdrawor will take care of withdrawals. If equal to 0 our withdrawor will skip, but everyone else can initiate withdrawals.
|
|
144
|
+
* @param {boolean} [data.isNative = false] - When true Automatically wraps SOLs to WrappedSOL and creates wSOL stream
|
|
145
145
|
* @param {string | null} [data.partner = null] - Partner's wallet address (optional).
|
|
146
146
|
*/
|
|
147
147
|
StreamClient.prototype.create = function (_a) {
|
|
148
|
-
var sender = _a.sender, recipient = _a.recipient, mint = _a.mint, start = _a.start, depositedAmount = _a.depositedAmount, period = _a.period, cliff = _a.cliff, cliffAmount = _a.cliffAmount, amountPerPeriod = _a.amountPerPeriod, name = _a.name, canTopup = _a.canTopup, cancelableBySender = _a.cancelableBySender, cancelableByRecipient = _a.cancelableByRecipient, transferableBySender = _a.transferableBySender, transferableByRecipient = _a.transferableByRecipient, _b = _a.automaticWithdrawal, automaticWithdrawal = _b === void 0 ? false : _b, _c = _a.withdrawalFrequency, withdrawalFrequency = _c === void 0 ? 0 : _c, _d = _a.partner, partner = _d === void 0 ? null : _d;
|
|
148
|
+
var sender = _a.sender, recipient = _a.recipient, mint = _a.mint, start = _a.start, depositedAmount = _a.depositedAmount, period = _a.period, cliff = _a.cliff, cliffAmount = _a.cliffAmount, amountPerPeriod = _a.amountPerPeriod, name = _a.name, canTopup = _a.canTopup, cancelableBySender = _a.cancelableBySender, cancelableByRecipient = _a.cancelableByRecipient, transferableBySender = _a.transferableBySender, transferableByRecipient = _a.transferableByRecipient, _b = _a.automaticWithdrawal, automaticWithdrawal = _b === void 0 ? false : _b, _c = _a.withdrawalFrequency, withdrawalFrequency = _c === void 0 ? 0 : _c, _d = _a.partner, partner = _d === void 0 ? null : _d, _e = _a.isNative, isNative = _e === void 0 ? false : _e;
|
|
149
149
|
return __awaiter(this, void 0, void 0, function () {
|
|
150
|
-
var ixs, mintPublicKey, recipientPublicKey, metadata,
|
|
151
|
-
var
|
|
152
|
-
return __generator(this, function (
|
|
153
|
-
switch (
|
|
150
|
+
var ixs, mintPublicKey, recipientPublicKey, metadata, _f, escrowTokens, senderTokens, recipientTokens, streamflowTreasuryTokens, partnerPublicKey, partnerTokens, nativeInstructions, _g, commitment, hash, tx, signature;
|
|
151
|
+
var _h;
|
|
152
|
+
return __generator(this, function (_j) {
|
|
153
|
+
switch (_j.label) {
|
|
154
154
|
case 0:
|
|
155
155
|
ixs = [];
|
|
156
|
-
mintPublicKey = new web3_js_1.PublicKey(mint);
|
|
156
|
+
mintPublicKey = isNative ? new web3_js_1.PublicKey(mint) : spl_token_1.NATIVE_MINT;
|
|
157
157
|
recipientPublicKey = new web3_js_1.PublicKey(recipient);
|
|
158
158
|
metadata = web3_js_1.Keypair.generate();
|
|
159
159
|
return [4 /*yield*/, web3_js_1.PublicKey.findProgramAddress([buffer_1.Buffer.from("strm"), metadata.publicKey.toBuffer()], this.programId)];
|
|
160
160
|
case 1:
|
|
161
|
-
|
|
161
|
+
_f = __read.apply(void 0, [_j.sent(), 1]), escrowTokens = _f[0];
|
|
162
162
|
return [4 /*yield*/, ata(mintPublicKey, sender.publicKey)];
|
|
163
163
|
case 2:
|
|
164
|
-
senderTokens =
|
|
164
|
+
senderTokens = _j.sent();
|
|
165
165
|
return [4 /*yield*/, ata(mintPublicKey, recipientPublicKey)];
|
|
166
166
|
case 3:
|
|
167
|
-
recipientTokens =
|
|
167
|
+
recipientTokens = _j.sent();
|
|
168
168
|
return [4 /*yield*/, ata(mintPublicKey, constants_1.STREAMFLOW_TREASURY_PUBLIC_KEY)];
|
|
169
169
|
case 4:
|
|
170
|
-
streamflowTreasuryTokens =
|
|
170
|
+
streamflowTreasuryTokens = _j.sent();
|
|
171
171
|
partnerPublicKey = partner
|
|
172
172
|
? new web3_js_1.PublicKey(partner)
|
|
173
173
|
: constants_1.STREAMFLOW_TREASURY_PUBLIC_KEY;
|
|
174
174
|
return [4 /*yield*/, ata(mintPublicKey, partnerPublicKey)];
|
|
175
175
|
case 5:
|
|
176
|
-
partnerTokens =
|
|
176
|
+
partnerTokens = _j.sent();
|
|
177
|
+
if (!isNative) return [3 /*break*/, 7];
|
|
178
|
+
return [4 /*yield*/, (0, instructions_1.prepareWrappedAccount)(this.connection, sender.publicKey, depositedAmount)];
|
|
179
|
+
case 6:
|
|
180
|
+
_g = _j.sent();
|
|
181
|
+
return [3 /*break*/, 8];
|
|
182
|
+
case 7:
|
|
183
|
+
_g = [];
|
|
184
|
+
_j.label = 8;
|
|
185
|
+
case 8:
|
|
186
|
+
nativeInstructions = _g;
|
|
177
187
|
ixs.push((0, instructions_1.createStreamInstruction)({
|
|
178
188
|
start: new bn_js_1.default(start),
|
|
179
189
|
depositedAmount: depositedAmount,
|
|
@@ -213,17 +223,17 @@ var StreamClient = /** @class */ (function () {
|
|
|
213
223
|
? this.commitment
|
|
214
224
|
: this.commitment.commitment;
|
|
215
225
|
return [4 /*yield*/, this.connection.getLatestBlockhash(commitment)];
|
|
216
|
-
case
|
|
217
|
-
hash =
|
|
218
|
-
tx = (
|
|
226
|
+
case 9:
|
|
227
|
+
hash = _j.sent();
|
|
228
|
+
tx = (_h = new web3_js_1.Transaction({
|
|
219
229
|
feePayer: sender.publicKey,
|
|
220
230
|
blockhash: hash.blockhash,
|
|
221
231
|
lastValidBlockHeight: hash.lastValidBlockHeight,
|
|
222
|
-
})).add.apply(
|
|
232
|
+
})).add.apply(_h, __spreadArray(__spreadArray([], __read(nativeInstructions), false), __read(ixs), false));
|
|
223
233
|
tx.partialSign(metadata);
|
|
224
234
|
return [4 /*yield*/, this.sign(sender, tx, hash)];
|
|
225
|
-
case
|
|
226
|
-
signature =
|
|
235
|
+
case 10:
|
|
236
|
+
signature = _j.sent();
|
|
227
237
|
return [2 /*return*/, { ixs: ixs, tx: signature, metadata: metadata }];
|
|
228
238
|
}
|
|
229
239
|
});
|
|
@@ -257,22 +267,23 @@ var StreamClient = /** @class */ (function () {
|
|
|
257
267
|
* @param {boolean} data.transferableByRecipient - Whether or not recipient can transfer the stream.
|
|
258
268
|
* @param {boolean} data.automaticWithdrawal - Whether or not a 3rd party can initiate withdraw in the name of recipient.
|
|
259
269
|
* @param {number} [data.withdrawalFrequency = 0] - Relevant when automatic withdrawal is enabled. If greater than 0 our withdrawor will take care of withdrawals. If equal to 0 our withdrawor will skip, but everyone else can initiate withdrawals.
|
|
260
|
-
* @param {
|
|
270
|
+
* @param {boolean} [data.isNative = false] - When true Automatically wraps SOLs to WrappedSOL and creates wSOL stream
|
|
271
|
+
* @param {string | null} [data.partner = null] - Partner's wallet address (optional).
|
|
261
272
|
*/
|
|
262
273
|
StreamClient.prototype.createUnchecked = function (_a) {
|
|
263
|
-
var sender = _a.sender, recipient = _a.recipient, mint = _a.mint, start = _a.start, depositedAmount = _a.depositedAmount, period = _a.period, cliff = _a.cliff, cliffAmount = _a.cliffAmount, amountPerPeriod = _a.amountPerPeriod, name = _a.name, canTopup = _a.canTopup, cancelableBySender = _a.cancelableBySender, cancelableByRecipient = _a.cancelableByRecipient, transferableBySender = _a.transferableBySender, transferableByRecipient = _a.transferableByRecipient, _b = _a.automaticWithdrawal, automaticWithdrawal = _b === void 0 ? false : _b, _c = _a.withdrawalFrequency, withdrawalFrequency = _c === void 0 ? 0 : _c, _d = _a.partner, partner = _d === void 0 ? null : _d;
|
|
274
|
+
var sender = _a.sender, recipient = _a.recipient, mint = _a.mint, start = _a.start, depositedAmount = _a.depositedAmount, period = _a.period, cliff = _a.cliff, cliffAmount = _a.cliffAmount, amountPerPeriod = _a.amountPerPeriod, name = _a.name, canTopup = _a.canTopup, cancelableBySender = _a.cancelableBySender, cancelableByRecipient = _a.cancelableByRecipient, transferableBySender = _a.transferableBySender, transferableByRecipient = _a.transferableByRecipient, _b = _a.automaticWithdrawal, automaticWithdrawal = _b === void 0 ? false : _b, _c = _a.withdrawalFrequency, withdrawalFrequency = _c === void 0 ? 0 : _c, _d = _a.partner, partner = _d === void 0 ? null : _d, _e = _a.isNative, isNative = _e === void 0 ? false : _e;
|
|
264
275
|
return __awaiter(this, void 0, void 0, function () {
|
|
265
|
-
var mintPublicKey, recipientPublicKey, metadata, rentToExempt, createMetadataInstruction,
|
|
266
|
-
var
|
|
267
|
-
return __generator(this, function (
|
|
268
|
-
switch (
|
|
276
|
+
var mintPublicKey, recipientPublicKey, metadata, rentToExempt, createMetadataInstruction, _f, escrowTokens, senderTokens, partnerPublicKey, nativeInstructions, _g, createInstruction, commitment, ixs, hash, tx, signature;
|
|
277
|
+
var _h;
|
|
278
|
+
return __generator(this, function (_j) {
|
|
279
|
+
switch (_j.label) {
|
|
269
280
|
case 0:
|
|
270
281
|
mintPublicKey = new web3_js_1.PublicKey(mint);
|
|
271
282
|
recipientPublicKey = new web3_js_1.PublicKey(recipient);
|
|
272
283
|
metadata = web3_js_1.Keypair.generate();
|
|
273
284
|
return [4 /*yield*/, this.connection.getMinimumBalanceForRentExemption(METADATA_ACC_SIZE)];
|
|
274
285
|
case 1:
|
|
275
|
-
rentToExempt =
|
|
286
|
+
rentToExempt = _j.sent();
|
|
276
287
|
createMetadataInstruction = web3_js_1.SystemProgram.createAccount({
|
|
277
288
|
programId: this.programId,
|
|
278
289
|
space: METADATA_ACC_SIZE,
|
|
@@ -282,13 +293,23 @@ var StreamClient = /** @class */ (function () {
|
|
|
282
293
|
});
|
|
283
294
|
return [4 /*yield*/, web3_js_1.PublicKey.findProgramAddress([buffer_1.Buffer.from("strm"), metadata.publicKey.toBuffer()], this.programId)];
|
|
284
295
|
case 2:
|
|
285
|
-
|
|
296
|
+
_f = __read.apply(void 0, [_j.sent(), 1]), escrowTokens = _f[0];
|
|
286
297
|
return [4 /*yield*/, ata(mintPublicKey, sender.publicKey)];
|
|
287
298
|
case 3:
|
|
288
|
-
senderTokens =
|
|
299
|
+
senderTokens = _j.sent();
|
|
289
300
|
partnerPublicKey = partner
|
|
290
301
|
? new web3_js_1.PublicKey(partner)
|
|
291
302
|
: constants_1.STREAMFLOW_TREASURY_PUBLIC_KEY;
|
|
303
|
+
if (!isNative) return [3 /*break*/, 5];
|
|
304
|
+
return [4 /*yield*/, (0, instructions_1.prepareWrappedAccount)(this.connection, sender.publicKey, depositedAmount)];
|
|
305
|
+
case 4:
|
|
306
|
+
_g = _j.sent();
|
|
307
|
+
return [3 /*break*/, 6];
|
|
308
|
+
case 5:
|
|
309
|
+
_g = [];
|
|
310
|
+
_j.label = 6;
|
|
311
|
+
case 6:
|
|
312
|
+
nativeInstructions = _g;
|
|
292
313
|
createInstruction = (0, instructions_1.createUncheckedStreamInstruction)({
|
|
293
314
|
start: new bn_js_1.default(start),
|
|
294
315
|
depositedAmount: depositedAmount,
|
|
@@ -327,17 +348,17 @@ var StreamClient = /** @class */ (function () {
|
|
|
327
348
|
createInstruction,
|
|
328
349
|
];
|
|
329
350
|
return [4 /*yield*/, this.connection.getLatestBlockhash(commitment)];
|
|
330
|
-
case
|
|
331
|
-
hash =
|
|
332
|
-
tx = (
|
|
351
|
+
case 7:
|
|
352
|
+
hash = _j.sent();
|
|
353
|
+
tx = (_h = new web3_js_1.Transaction({
|
|
333
354
|
feePayer: sender.publicKey,
|
|
334
355
|
blockhash: hash.blockhash,
|
|
335
356
|
lastValidBlockHeight: hash.lastValidBlockHeight,
|
|
336
|
-
})).add.apply(
|
|
357
|
+
})).add.apply(_h, __spreadArray(__spreadArray([], __read(nativeInstructions), false), __read(ixs), false));
|
|
337
358
|
tx.partialSign(metadata);
|
|
338
359
|
return [4 /*yield*/, this.sign(sender, tx, hash)];
|
|
339
|
-
case
|
|
340
|
-
signature =
|
|
360
|
+
case 8:
|
|
361
|
+
signature = _j.sent();
|
|
341
362
|
return [2 /*return*/, { ixs: ixs, tx: signature, metadata: metadata }];
|
|
342
363
|
}
|
|
343
364
|
});
|
|
@@ -360,12 +381,13 @@ var StreamClient = /** @class */ (function () {
|
|
|
360
381
|
* @param {boolean} data.transferableByRecipient - Whether or not recipient can transfer the stream.
|
|
361
382
|
* @param {boolean} data.automaticWithdrawal - Whether or not a 3rd party can initiate withdraw in the name of recipient.
|
|
362
383
|
* @param {number} [data.withdrawalFrequency = 0] - Relevant when automatic withdrawal is enabled. If greater than 0 our withdrawor will take care of withdrawals. If equal to 0 our withdrawor will skip, but everyone else can initiate withdrawals.
|
|
384
|
+
* @param {boolean} [data.isNative = false] - When true Automatically wraps SOLs to WrappedSOL and creates wSOL stream
|
|
363
385
|
* @param {string | null} [data.partner = null] - Partner's wallet address (optional).
|
|
364
386
|
*/
|
|
365
387
|
StreamClient.prototype.createMultiple = function (data) {
|
|
366
388
|
return __awaiter(this, void 0, void 0, function () {
|
|
367
|
-
var sender, recipientsData, metadatas, metadataToRecipient, errors, signatures,
|
|
368
|
-
var e_1, _b,
|
|
389
|
+
var sender, recipientsData, metadatas, metadataToRecipient, errors, signatures, batch, recipientsData_1, recipientsData_1_1, recipientData, _a, tx, metadata, metadataPubKey, e_1_1, totalDepositedAmount, nativeInstructions, commitment, hash, prepareTransaction, signed_batch, prepareTx, batchTransactionsCalls, responses, successes, failures;
|
|
390
|
+
var e_1, _b, _c;
|
|
369
391
|
var _this = this;
|
|
370
392
|
return __generator(this, function (_d) {
|
|
371
393
|
switch (_d.label) {
|
|
@@ -375,8 +397,6 @@ var StreamClient = /** @class */ (function () {
|
|
|
375
397
|
metadataToRecipient = {};
|
|
376
398
|
errors = [];
|
|
377
399
|
signatures = [];
|
|
378
|
-
chunkSize = 100;
|
|
379
|
-
chunkes = [];
|
|
380
400
|
batch = [];
|
|
381
401
|
_d.label = 1;
|
|
382
402
|
case 1:
|
|
@@ -409,26 +429,39 @@ var StreamClient = /** @class */ (function () {
|
|
|
409
429
|
finally { if (e_1) throw e_1.error; }
|
|
410
430
|
return [7 /*endfinally*/];
|
|
411
431
|
case 8:
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
}
|
|
416
|
-
_d.label = 9;
|
|
432
|
+
if (!data.isNative) return [3 /*break*/, 11];
|
|
433
|
+
totalDepositedAmount = recipientsData.reduce(function (acc, recipient) { return recipient.depositedAmount.add(acc); }, new bn_js_1.default(0));
|
|
434
|
+
return [4 /*yield*/, (0, instructions_1.prepareWrappedAccount)(this.connection, sender.publicKey, totalDepositedAmount)];
|
|
417
435
|
case 9:
|
|
418
|
-
_d.
|
|
419
|
-
|
|
420
|
-
|
|
436
|
+
nativeInstructions = _d.sent();
|
|
437
|
+
commitment = typeof this.commitment == "string"
|
|
438
|
+
? this.commitment
|
|
439
|
+
: this.commitment.commitment;
|
|
440
|
+
return [4 /*yield*/, this.connection.getLatestBlockhash(commitment)];
|
|
421
441
|
case 10:
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
442
|
+
hash = _d.sent();
|
|
443
|
+
prepareTransaction = (_c = new web3_js_1.Transaction({
|
|
444
|
+
feePayer: sender.publicKey,
|
|
445
|
+
blockhash: hash.blockhash,
|
|
446
|
+
lastValidBlockHeight: hash.lastValidBlockHeight,
|
|
447
|
+
})).add.apply(_c, __spreadArray([], __read(nativeInstructions), false));
|
|
448
|
+
batch.push({ tx: prepareTransaction, recipient: sender.publicKey.toBase58() });
|
|
449
|
+
_d.label = 11;
|
|
450
|
+
case 11: return [4 /*yield*/, signAllTransactionWithRecipients(sender, batch)];
|
|
451
|
+
case 12:
|
|
426
452
|
signed_batch = _d.sent();
|
|
453
|
+
if (!data.isNative) return [3 /*break*/, 14];
|
|
454
|
+
prepareTx = signed_batch.pop();
|
|
455
|
+
return [4 /*yield*/, sendAndConfirmStreamRawTransaction(this.connection, prepareTx)];
|
|
456
|
+
case 13:
|
|
457
|
+
_d.sent();
|
|
458
|
+
_d.label = 14;
|
|
459
|
+
case 14:
|
|
427
460
|
batchTransactionsCalls = signed_batch.map(function (el) {
|
|
428
461
|
return sendAndConfirmStreamRawTransaction(_this.connection, el);
|
|
429
462
|
});
|
|
430
463
|
return [4 /*yield*/, Promise.allSettled(batchTransactionsCalls)];
|
|
431
|
-
case
|
|
464
|
+
case 15:
|
|
432
465
|
responses = _d.sent();
|
|
433
466
|
successes = responses
|
|
434
467
|
.filter(function (el) {
|
|
@@ -440,25 +473,7 @@ var StreamClient = /** @class */ (function () {
|
|
|
440
473
|
.filter(function (el) { return el.status === "rejected"; })
|
|
441
474
|
.map(function (el) { return el.reason; });
|
|
442
475
|
errors.push.apply(errors, __spreadArray([], __read(failures), false));
|
|
443
|
-
return [
|
|
444
|
-
case 13:
|
|
445
|
-
_d.sent();
|
|
446
|
-
_d.label = 14;
|
|
447
|
-
case 14:
|
|
448
|
-
chunkes_1_1 = chunkes_1.next();
|
|
449
|
-
return [3 /*break*/, 10];
|
|
450
|
-
case 15: return [3 /*break*/, 18];
|
|
451
|
-
case 16:
|
|
452
|
-
e_2_1 = _d.sent();
|
|
453
|
-
e_2 = { error: e_2_1 };
|
|
454
|
-
return [3 /*break*/, 18];
|
|
455
|
-
case 17:
|
|
456
|
-
try {
|
|
457
|
-
if (chunkes_1_1 && !chunkes_1_1.done && (_c = chunkes_1.return)) _c.call(chunkes_1);
|
|
458
|
-
}
|
|
459
|
-
finally { if (e_2) throw e_2.error; }
|
|
460
|
-
return [7 /*endfinally*/];
|
|
461
|
-
case 18: return [2 /*return*/, { txs: signatures, metadatas: metadatas, metadataToRecipient: metadataToRecipient, errors: errors }];
|
|
476
|
+
return [2 /*return*/, { txs: signatures, metadatas: metadatas, metadataToRecipient: metadataToRecipient, errors: errors }];
|
|
462
477
|
}
|
|
463
478
|
});
|
|
464
479
|
});
|
|
@@ -655,28 +670,38 @@ var StreamClient = /** @class */ (function () {
|
|
|
655
670
|
* @param {BN} data.amount - Specified amount (in the smallest units) to topup (increases deposited amount).
|
|
656
671
|
*/
|
|
657
672
|
StreamClient.prototype.topup = function (_a) {
|
|
658
|
-
var invoker = _a.invoker, id = _a.id, amount = _a.amount;
|
|
673
|
+
var invoker = _a.invoker, id = _a.id, amount = _a.amount, isNative = _a.isNative;
|
|
659
674
|
return __awaiter(this, void 0, void 0, function () {
|
|
660
|
-
var ixs, streamPublicKey, escrow, _b, mint, partner, senderTokens, escrowTokens, streamflowTreasuryTokens, partnerTokens, commitment, hash, tx, signature;
|
|
661
|
-
var
|
|
662
|
-
return __generator(this, function (
|
|
663
|
-
switch (
|
|
675
|
+
var ixs, streamPublicKey, escrow, _b, mint, partner, senderTokens, escrowTokens, streamflowTreasuryTokens, partnerTokens, nativeInstructions, _c, commitment, hash, tx, signature;
|
|
676
|
+
var _d;
|
|
677
|
+
return __generator(this, function (_e) {
|
|
678
|
+
switch (_e.label) {
|
|
664
679
|
case 0:
|
|
665
680
|
ixs = [];
|
|
666
681
|
streamPublicKey = new web3_js_1.PublicKey(id);
|
|
667
682
|
return [4 /*yield*/, this.connection.getAccountInfo(streamPublicKey)];
|
|
668
683
|
case 1:
|
|
669
|
-
escrow =
|
|
684
|
+
escrow = _e.sent();
|
|
670
685
|
if (!(escrow === null || escrow === void 0 ? void 0 : escrow.data)) {
|
|
671
686
|
throw new Error("Couldn't get account info");
|
|
672
687
|
}
|
|
673
688
|
_b = (0, utils_1.decodeStream)(escrow === null || escrow === void 0 ? void 0 : escrow.data), mint = _b.mint, partner = _b.partner, senderTokens = _b.senderTokens, escrowTokens = _b.escrowTokens;
|
|
674
689
|
return [4 /*yield*/, ata(mint, constants_1.STREAMFLOW_TREASURY_PUBLIC_KEY)];
|
|
675
690
|
case 2:
|
|
676
|
-
streamflowTreasuryTokens =
|
|
691
|
+
streamflowTreasuryTokens = _e.sent();
|
|
677
692
|
return [4 /*yield*/, ata(mint, partner)];
|
|
678
693
|
case 3:
|
|
679
|
-
partnerTokens =
|
|
694
|
+
partnerTokens = _e.sent();
|
|
695
|
+
if (!isNative) return [3 /*break*/, 5];
|
|
696
|
+
return [4 /*yield*/, (0, instructions_1.prepareWrappedAccount)(this.connection, invoker.publicKey, amount)];
|
|
697
|
+
case 4:
|
|
698
|
+
_c = _e.sent();
|
|
699
|
+
return [3 /*break*/, 6];
|
|
700
|
+
case 5:
|
|
701
|
+
_c = [];
|
|
702
|
+
_e.label = 6;
|
|
703
|
+
case 6:
|
|
704
|
+
nativeInstructions = _c;
|
|
680
705
|
ixs.push((0, instructions_1.topupStreamInstruction)(amount, this.programId, {
|
|
681
706
|
sender: invoker.publicKey,
|
|
682
707
|
senderTokens: senderTokens,
|
|
@@ -695,16 +720,16 @@ var StreamClient = /** @class */ (function () {
|
|
|
695
720
|
? this.commitment
|
|
696
721
|
: this.commitment.commitment;
|
|
697
722
|
return [4 /*yield*/, this.connection.getLatestBlockhash(commitment)];
|
|
698
|
-
case
|
|
699
|
-
hash =
|
|
700
|
-
tx = (
|
|
723
|
+
case 7:
|
|
724
|
+
hash = _e.sent();
|
|
725
|
+
tx = (_d = new web3_js_1.Transaction({
|
|
701
726
|
feePayer: invoker.publicKey,
|
|
702
727
|
blockhash: hash.blockhash,
|
|
703
728
|
lastValidBlockHeight: hash.lastValidBlockHeight,
|
|
704
|
-
})).add.apply(
|
|
729
|
+
})).add.apply(_d, __spreadArray(__spreadArray([], __read(nativeInstructions), false), __read(ixs), false));
|
|
705
730
|
return [4 /*yield*/, this.sign(invoker, tx, hash)];
|
|
706
|
-
case
|
|
707
|
-
signature =
|
|
731
|
+
case 8:
|
|
732
|
+
signature = _e.sent();
|
|
708
733
|
return [2 /*return*/, { ixs: ixs, tx: signature }];
|
|
709
734
|
}
|
|
710
735
|
});
|
|
@@ -936,51 +961,28 @@ function isAnchorWallet(wallet) {
|
|
|
936
961
|
}
|
|
937
962
|
function signAllTransactionWithRecipients(sender, batch) {
|
|
938
963
|
return __awaiter(this, void 0, void 0, function () {
|
|
939
|
-
var signed_batch, isKeypair, isWallet
|
|
940
|
-
|
|
941
|
-
|
|
942
|
-
switch (_b.label) {
|
|
964
|
+
var signed_batch, isKeypair, isWallet;
|
|
965
|
+
return __generator(this, function (_a) {
|
|
966
|
+
switch (_a.label) {
|
|
943
967
|
case 0:
|
|
944
968
|
signed_batch = [];
|
|
945
969
|
isKeypair = sender instanceof web3_js_1.Keypair;
|
|
946
970
|
isWallet = isAnchorWallet(sender);
|
|
947
971
|
if (!isKeypair && !isWallet)
|
|
948
972
|
return [2 /*return*/, signed_batch];
|
|
949
|
-
if (isKeypair)
|
|
950
|
-
|
|
951
|
-
|
|
952
|
-
|
|
953
|
-
});
|
|
954
|
-
}
|
|
955
|
-
if (!isWallet) return [3 /*break*/, 2];
|
|
956
|
-
recipientToBlockhashMap_1 = new Map();
|
|
957
|
-
try {
|
|
958
|
-
for (batch_1 = __values(batch), batch_1_1 = batch_1.next(); !batch_1_1.done; batch_1_1 = batch_1.next()) {
|
|
959
|
-
item = batch_1_1.value;
|
|
960
|
-
recipientToBlockhashMap_1.set(item.tx.recentBlockhash, item);
|
|
961
|
-
}
|
|
962
|
-
}
|
|
963
|
-
catch (e_3_1) { e_3 = { error: e_3_1 }; }
|
|
964
|
-
finally {
|
|
965
|
-
try {
|
|
966
|
-
if (batch_1_1 && !batch_1_1.done && (_a = batch_1.return)) _a.call(batch_1);
|
|
967
|
-
}
|
|
968
|
-
finally { if (e_3) throw e_3.error; }
|
|
969
|
-
}
|
|
970
|
-
return [4 /*yield*/, sender.signAllTransactions(batch.map(function (t) { return t.tx; }))];
|
|
971
|
-
case 1:
|
|
972
|
-
txs = _b.sent();
|
|
973
|
-
txs.map(function (tx) {
|
|
974
|
-
var item = recipientToBlockhashMap_1.get(tx.recentBlockhash);
|
|
975
|
-
if (item) {
|
|
976
|
-
signed_batch.push({
|
|
977
|
-
tx: tx,
|
|
978
|
-
recipient: item.recipient,
|
|
979
|
-
});
|
|
980
|
-
}
|
|
973
|
+
if (!isKeypair) return [3 /*break*/, 1];
|
|
974
|
+
batch.map(function (t) {
|
|
975
|
+
t.tx.partialSign(sender);
|
|
976
|
+
return { tx: t.tx, recipient: t.recipient };
|
|
981
977
|
});
|
|
982
|
-
|
|
983
|
-
case
|
|
978
|
+
return [3 /*break*/, 3];
|
|
979
|
+
case 1:
|
|
980
|
+
if (!isWallet) return [3 /*break*/, 3];
|
|
981
|
+
return [4 /*yield*/, sender.signAllTransactions(batch.map(function (t) { return t.tx; }))];
|
|
982
|
+
case 2:
|
|
983
|
+
_a.sent();
|
|
984
|
+
_a.label = 3;
|
|
985
|
+
case 3: return [2 /*return*/, batch];
|
|
984
986
|
}
|
|
985
987
|
});
|
|
986
988
|
});
|
package/dist/constants.d.ts
CHANGED
|
@@ -15,3 +15,4 @@ export declare const WITHDRAWOR_PUBLIC_KEY: PublicKey;
|
|
|
15
15
|
export declare const FEE_ORACLE_PUBLIC_KEY: PublicKey;
|
|
16
16
|
export declare const AIRDROP_TEST_TOKEN = "Gssm3vfi8s65R31SBdmQRq6cKeYojGgup7whkw4VCiQj";
|
|
17
17
|
export declare const AIRDROP_AMOUNT = 1;
|
|
18
|
+
export declare const BASE_FEE = 1002500;
|
package/dist/constants.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
var _a;
|
|
3
3
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
|
-
exports.AIRDROP_AMOUNT = exports.AIRDROP_TEST_TOKEN = exports.FEE_ORACLE_PUBLIC_KEY = exports.WITHDRAWOR_PUBLIC_KEY = exports.STREAMFLOW_TREASURY_PUBLIC_KEY = exports.STREAMFLOW_DEVNET_PROGRAM_ID = exports.STREAMFLOW_PROGRAM_ID = exports.PROGRAM_ID = exports.STREAM_STRUCT_OFFSET_RECIPIENT = exports.STREAM_STRUCT_OFFSET_SENDER = exports.TX_FINALITY_CONFIRMED = void 0;
|
|
4
|
+
exports.BASE_FEE = exports.AIRDROP_AMOUNT = exports.AIRDROP_TEST_TOKEN = exports.FEE_ORACLE_PUBLIC_KEY = exports.WITHDRAWOR_PUBLIC_KEY = exports.STREAMFLOW_TREASURY_PUBLIC_KEY = exports.STREAMFLOW_DEVNET_PROGRAM_ID = exports.STREAMFLOW_PROGRAM_ID = exports.PROGRAM_ID = exports.STREAM_STRUCT_OFFSET_RECIPIENT = exports.STREAM_STRUCT_OFFSET_SENDER = exports.TX_FINALITY_CONFIRMED = void 0;
|
|
5
5
|
var web3_js_1 = require("@solana/web3.js");
|
|
6
6
|
var types_1 = require("./types");
|
|
7
7
|
exports.TX_FINALITY_CONFIRMED = "confirmed";
|
|
@@ -20,3 +20,4 @@ exports.WITHDRAWOR_PUBLIC_KEY = new web3_js_1.PublicKey("wdrwhnCv4pzW8beKsbPa4S2
|
|
|
20
20
|
exports.FEE_ORACLE_PUBLIC_KEY = new web3_js_1.PublicKey("B743wFVk2pCYhV91cn287e1xY7f1vt4gdY48hhNiuQmT");
|
|
21
21
|
exports.AIRDROP_TEST_TOKEN = "Gssm3vfi8s65R31SBdmQRq6cKeYojGgup7whkw4VCiQj";
|
|
22
22
|
exports.AIRDROP_AMOUNT = 1; // 1 SOL is the cap on the testnet
|
|
23
|
+
exports.BASE_FEE = 1002500; // Basic buffer for intermediary swaps
|
package/dist/instructions.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { PublicKey, TransactionInstruction } from "@solana/web3.js";
|
|
1
|
+
import { Connection, PublicKey, TransactionInstruction } from "@solana/web3.js";
|
|
2
2
|
import BN from "bn.js";
|
|
3
3
|
interface CreateStreamData {
|
|
4
4
|
start: BN;
|
|
@@ -126,4 +126,7 @@ interface TopupAccounts {
|
|
|
126
126
|
systemProgram: PublicKey;
|
|
127
127
|
}
|
|
128
128
|
export declare const topupStreamInstruction: (amount: BN, programId: PublicKey, { sender, senderTokens, metadata, escrowTokens, streamflowTreasury, streamflowTreasuryTokens, partner, partnerTokens, mint, tokenProgram, withdrawor, systemProgram, }: TopupAccounts) => TransactionInstruction;
|
|
129
|
+
export declare const syncNativeInstructionData: import("@solana/buffer-layout").Structure<any>;
|
|
130
|
+
export declare const createSyncNativeInstruction: (account: PublicKey) => TransactionInstruction;
|
|
131
|
+
export declare const prepareWrappedAccount: (connection: Connection, senderAddress: PublicKey, amount: BN) => Promise<TransactionInstruction[]>;
|
|
129
132
|
export {};
|
package/dist/instructions.js
CHANGED
|
@@ -22,12 +22,80 @@ 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 (_) 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
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
87
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
88
|
+
};
|
|
25
89
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
26
|
-
exports.topupStreamInstruction = exports.transferStreamInstruction = exports.cancelStreamInstruction = exports.withdrawStreamInstruction = exports.createUncheckedStreamInstruction = exports.createStreamInstruction = void 0;
|
|
90
|
+
exports.prepareWrappedAccount = exports.createSyncNativeInstruction = exports.syncNativeInstructionData = exports.topupStreamInstruction = exports.transferStreamInstruction = exports.cancelStreamInstruction = exports.withdrawStreamInstruction = exports.createUncheckedStreamInstruction = exports.createStreamInstruction = void 0;
|
|
27
91
|
var buffer_1 = require("buffer");
|
|
28
92
|
var web3_js_1 = require("@solana/web3.js");
|
|
93
|
+
var bn_js_1 = __importDefault(require("bn.js"));
|
|
29
94
|
var js_sha256_1 = require("js-sha256");
|
|
95
|
+
var buffer_layout_1 = require("@solana/buffer-layout");
|
|
30
96
|
var Layout = __importStar(require("./layout"));
|
|
97
|
+
var spl_token_1 = require("@solana/spl-token");
|
|
98
|
+
var constants_1 = require("./constants");
|
|
31
99
|
var createStreamInstruction = function (data, programId, accounts) {
|
|
32
100
|
var keys = [
|
|
33
101
|
{ pubkey: accounts.sender, isSigner: true, isWritable: true },
|
|
@@ -272,3 +340,41 @@ var topupStreamInstruction = function (amount, programId, _a) {
|
|
|
272
340
|
});
|
|
273
341
|
};
|
|
274
342
|
exports.topupStreamInstruction = topupStreamInstruction;
|
|
343
|
+
// TODO: Use native createSyncNativeInstruction after migrating to newer @solana/spl-token
|
|
344
|
+
var SyncNativeIndex = 17;
|
|
345
|
+
exports.syncNativeInstructionData = (0, buffer_layout_1.struct)([(0, buffer_layout_1.u8)('instruction')]);
|
|
346
|
+
var createSyncNativeInstruction = function (account) {
|
|
347
|
+
var keys = [{ pubkey: account, isSigner: false, isWritable: true }];
|
|
348
|
+
var data = buffer_1.Buffer.alloc(exports.syncNativeInstructionData.span);
|
|
349
|
+
exports.syncNativeInstructionData.encode({ instruction: SyncNativeIndex }, data);
|
|
350
|
+
return new web3_js_1.TransactionInstruction({ keys: keys, programId: spl_token_1.TOKEN_PROGRAM_ID, data: data });
|
|
351
|
+
};
|
|
352
|
+
exports.createSyncNativeInstruction = createSyncNativeInstruction;
|
|
353
|
+
var prepareWrappedAccount = function (connection, senderAddress, amount) { return __awaiter(void 0, void 0, void 0, function () {
|
|
354
|
+
var tokenAccount, accInfo, instructions;
|
|
355
|
+
var _a, _b;
|
|
356
|
+
return __generator(this, function (_c) {
|
|
357
|
+
switch (_c.label) {
|
|
358
|
+
case 0: return [4 /*yield*/, spl_token_1.Token.getAssociatedTokenAddress(spl_token_1.ASSOCIATED_TOKEN_PROGRAM_ID, spl_token_1.TOKEN_PROGRAM_ID, spl_token_1.NATIVE_MINT, senderAddress, true)];
|
|
359
|
+
case 1:
|
|
360
|
+
tokenAccount = _c.sent();
|
|
361
|
+
return [4 /*yield*/, connection.getParsedAccountInfo(tokenAccount)];
|
|
362
|
+
case 2:
|
|
363
|
+
accInfo = _c.sent();
|
|
364
|
+
instructions = ((_b = (_a = accInfo.value) === null || _a === void 0 ? void 0 : _a.lamports) !== null && _b !== void 0 ? _b : 0) > 0
|
|
365
|
+
? []
|
|
366
|
+
: [
|
|
367
|
+
spl_token_1.Token.createAssociatedTokenAccountInstruction(spl_token_1.ASSOCIATED_TOKEN_PROGRAM_ID, spl_token_1.TOKEN_PROGRAM_ID, spl_token_1.NATIVE_MINT, tokenAccount, senderAddress, senderAddress),
|
|
368
|
+
];
|
|
369
|
+
return [2 /*return*/, __spreadArray(__spreadArray([], __read(instructions), false), [
|
|
370
|
+
web3_js_1.SystemProgram.transfer({
|
|
371
|
+
fromPubkey: senderAddress,
|
|
372
|
+
toPubkey: tokenAccount,
|
|
373
|
+
lamports: amount.mul(new bn_js_1.default(constants_1.BASE_FEE)).div(new bn_js_1.default(1000000)).toNumber(),
|
|
374
|
+
}),
|
|
375
|
+
(0, exports.createSyncNativeInstruction)(tokenAccount),
|
|
376
|
+
], false)];
|
|
377
|
+
}
|
|
378
|
+
});
|
|
379
|
+
}); };
|
|
380
|
+
exports.prepareWrappedAccount = prepareWrappedAccount;
|
package/dist/types.d.ts
CHANGED
|
@@ -70,10 +70,12 @@ export interface CreateStreamParams extends CreateStreamData {
|
|
|
70
70
|
export interface CreateParams extends CreateStreamData {
|
|
71
71
|
sender: Wallet | Keypair;
|
|
72
72
|
partner?: string | null;
|
|
73
|
+
isNative?: boolean;
|
|
73
74
|
}
|
|
74
75
|
export interface CreateMultiParams extends CreateMultiData {
|
|
75
76
|
sender: Wallet | Keypair;
|
|
76
77
|
partner?: string | null;
|
|
78
|
+
isNative?: boolean;
|
|
77
79
|
}
|
|
78
80
|
export interface WithdrawStreamData {
|
|
79
81
|
id: string;
|
|
@@ -98,6 +100,7 @@ export interface TopupStreamParams extends TopupStreamData {
|
|
|
98
100
|
}
|
|
99
101
|
export interface TopupParams extends TopupStreamData {
|
|
100
102
|
invoker: Wallet | Keypair;
|
|
103
|
+
isNative?: boolean;
|
|
101
104
|
}
|
|
102
105
|
export interface CancelStreamData {
|
|
103
106
|
id: string;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@streamflow/stream",
|
|
3
|
-
"version": "3.0.
|
|
3
|
+
"version": "3.0.13",
|
|
4
4
|
"description": "JavaScript SDK to interact with Streamflow protocol.",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"homepage": "https://github.com/streamflow-finance/js-sdk/",
|
|
@@ -11,13 +11,9 @@
|
|
|
11
11
|
},
|
|
12
12
|
"gitHead": "a37306eba0e762af096db642fa22f07194014cfd",
|
|
13
13
|
"devDependencies": {
|
|
14
|
-
"@types/bn.js": "
|
|
15
|
-
"
|
|
16
|
-
"
|
|
17
|
-
"date-fns": "^2.28.0",
|
|
18
|
-
"jest": "^28.1.2",
|
|
19
|
-
"mocha": "^10.0.0",
|
|
20
|
-
"typescript": "^4.6.4"
|
|
14
|
+
"@types/bn.js": "5.1.0",
|
|
15
|
+
"date-fns": "2.28.0",
|
|
16
|
+
"typescript": "4.6.4"
|
|
21
17
|
},
|
|
22
18
|
"dependencies": {
|
|
23
19
|
"@project-serum/anchor": "^0.16.2",
|
|
File without changes
|
|
@@ -1,166 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
// import StreamClient from "../StreamClient";
|
|
3
|
-
// import {
|
|
4
|
-
// Cluster,
|
|
5
|
-
// CreateMultiParams,
|
|
6
|
-
// CreateMultipleStreamsValues,
|
|
7
|
-
// LocalCluster,
|
|
8
|
-
// TransferCancelOptions,
|
|
9
|
-
// } from "../types";
|
|
10
|
-
// import * as web3 from "@solana/web3.js";
|
|
11
|
-
// import { getBN } from "../utils";
|
|
12
|
-
// import { requestAirdrop } from "./test_dependencies/airdrop/airdrop-request";
|
|
13
|
-
// import { Wallet } from "@project-serum/anchor";
|
|
14
|
-
// import { AIRDROP_TEST_TOKEN } from "../constants";
|
|
15
|
-
// import { BN } from "bn.js";
|
|
16
|
-
// let streamInstance: StreamClient | null = null;
|
|
17
|
-
// let sender: Wallet;
|
|
18
|
-
// let recipient: Wallet;
|
|
19
|
-
// let recipients: Wallet[] = [];
|
|
20
|
-
// let connection: web3.Connection | null = null;
|
|
21
|
-
// import { add, addMinutes, format, getUnixTime } from "date-fns";
|
|
22
|
-
// const CLUSTER_LOCAL = "local";
|
|
23
|
-
//
|
|
24
|
-
// const clusterUrls: { [s: string]: () => string } = {
|
|
25
|
-
// [CLUSTER_LOCAL]: () => "http://localhost:8899", // http://127.0.0.1:8899",
|
|
26
|
-
// [Cluster.Devnet]: () => "https://api.devnet.solana.com",
|
|
27
|
-
// [Cluster.Mainnet]: () => "https://api.mainnet-beta.solana.com",
|
|
28
|
-
// };
|
|
29
|
-
// beforeAll(async () => {
|
|
30
|
-
// streamInstance = new StreamClient(
|
|
31
|
-
// clusterUrls[Cluster.Devnet](),
|
|
32
|
-
// Cluster.Devnet,
|
|
33
|
-
// {
|
|
34
|
-
// commitment: "confirmed",
|
|
35
|
-
// disableRetryOnRateLimit: true,
|
|
36
|
-
// }
|
|
37
|
-
// );
|
|
38
|
-
// connection = new web3.Connection(web3.clusterApiUrl(), "confirmed");
|
|
39
|
-
//
|
|
40
|
-
// sender = new Wallet(web3.Keypair.generate());
|
|
41
|
-
// recipient = new Wallet(web3.Keypair.generate());
|
|
42
|
-
// recipients = [...new Array(10)].map(
|
|
43
|
-
// () => new Wallet(web3.Keypair.generate())
|
|
44
|
-
// );
|
|
45
|
-
// await requestAirdrop(sender, connection);
|
|
46
|
-
// }, 100000);
|
|
47
|
-
//
|
|
48
|
-
// test("Sender wallet airdropped funds", async () => {
|
|
49
|
-
// expect(await connection?.getBalance(sender.publicKey)).toBeGreaterThan(0);
|
|
50
|
-
// }, 100000);
|
|
51
|
-
//
|
|
52
|
-
// test("Stream client connects to cluster", async () => {
|
|
53
|
-
// expect(streamInstance).toBeTruthy();
|
|
54
|
-
// const streamInstanceConnection = await streamInstance?.getConnection();
|
|
55
|
-
// expect(streamInstanceConnection).toBeTruthy();
|
|
56
|
-
// });
|
|
57
|
-
//
|
|
58
|
-
// const newCreateMultipleStreamsPayload = (
|
|
59
|
-
// values: CreateMultipleStreamsValues,
|
|
60
|
-
// sender: Wallet
|
|
61
|
-
// ) => {
|
|
62
|
-
// const {
|
|
63
|
-
// recipients,
|
|
64
|
-
// releaseAmount,
|
|
65
|
-
// startDate,
|
|
66
|
-
// startTime,
|
|
67
|
-
// releaseFrequencyCounter,
|
|
68
|
-
// releaseFrequencyPeriod,
|
|
69
|
-
// whoCanTransfer,
|
|
70
|
-
// whoCanCancel,
|
|
71
|
-
// referral,
|
|
72
|
-
// } = values;
|
|
73
|
-
//
|
|
74
|
-
// const start = getUnixTime(new Date(startDate + "T" + startTime));
|
|
75
|
-
//
|
|
76
|
-
// const recipientsFormatted = recipients.map(
|
|
77
|
-
// ({ depositedAmount, recipient, name }) => ({
|
|
78
|
-
// recipient,
|
|
79
|
-
// name,
|
|
80
|
-
// depositedAmount: getBN(depositedAmount, 9),
|
|
81
|
-
// amountPerPeriod: getBN(releaseAmount, 9),
|
|
82
|
-
// cliffAmount: new BN(0),
|
|
83
|
-
// })
|
|
84
|
-
// );
|
|
85
|
-
// const data: CreateMultiParams = {
|
|
86
|
-
// sender,
|
|
87
|
-
// recipientsData: recipientsFormatted,
|
|
88
|
-
// mint: AIRDROP_TEST_TOKEN,
|
|
89
|
-
// start,
|
|
90
|
-
// period: releaseFrequencyCounter * releaseFrequencyPeriod,
|
|
91
|
-
// cliff: start,
|
|
92
|
-
// cancelableBySender:
|
|
93
|
-
// whoCanCancel === TransferCancelOptions.Sender ||
|
|
94
|
-
// whoCanCancel === TransferCancelOptions.Both,
|
|
95
|
-
// cancelableByRecipient:
|
|
96
|
-
// whoCanCancel === TransferCancelOptions.Recipient ||
|
|
97
|
-
// whoCanCancel === TransferCancelOptions.Both,
|
|
98
|
-
// transferableBySender:
|
|
99
|
-
// whoCanTransfer === TransferCancelOptions.Sender ||
|
|
100
|
-
// whoCanTransfer === TransferCancelOptions.Both,
|
|
101
|
-
// transferableByRecipient:
|
|
102
|
-
// whoCanTransfer === TransferCancelOptions.Recipient ||
|
|
103
|
-
// whoCanTransfer === TransferCancelOptions.Both,
|
|
104
|
-
// automaticWithdrawal: false,
|
|
105
|
-
// withdrawalFrequency: 0,
|
|
106
|
-
// canTopup: true,
|
|
107
|
-
// partner: referral,
|
|
108
|
-
// };
|
|
109
|
-
//
|
|
110
|
-
// return data;
|
|
111
|
-
// };
|
|
112
|
-
//
|
|
113
|
-
// export const DATE_FORMAT = "yyyy-MM-dd";
|
|
114
|
-
// export const TIME_FORMAT = "HH:mm";
|
|
115
|
-
//
|
|
116
|
-
// export const PERIOD = {
|
|
117
|
-
// SECOND: 1,
|
|
118
|
-
// MINUTE: 60,
|
|
119
|
-
// HOUR: 3600,
|
|
120
|
-
// DAY: 24 * 3600,
|
|
121
|
-
// WEEK: 7 * 24 * 3600,
|
|
122
|
-
// MONTH: Math.floor(30.4167 * 24 * 3600), //30.4167 days
|
|
123
|
-
// YEAR: 365 * 24 * 3600, // 365 days
|
|
124
|
-
// };
|
|
125
|
-
//
|
|
126
|
-
// export const timePeriodOptions = [
|
|
127
|
-
// { value: PERIOD.SECOND, label: "second" },
|
|
128
|
-
// { value: PERIOD.MINUTE, label: "minute" },
|
|
129
|
-
// { value: PERIOD.HOUR, label: "hour" },
|
|
130
|
-
// { value: PERIOD.DAY, label: "day" },
|
|
131
|
-
// { value: PERIOD.WEEK, label: "week" },
|
|
132
|
-
// { value: PERIOD.MONTH, label: "month" },
|
|
133
|
-
// { value: PERIOD.YEAR, label: "year" },
|
|
134
|
-
// ];
|
|
135
|
-
//
|
|
136
|
-
// test("Can create multiple stremas", async () => {
|
|
137
|
-
// const now = new Date();
|
|
138
|
-
// const recipientsPayload = recipients.map((recipient, i) => ({
|
|
139
|
-
// recipient: recipient.publicKey.toBase58(),
|
|
140
|
-
// recipientEmail: "",
|
|
141
|
-
// name: "Recipient " + i,
|
|
142
|
-
// depositedAmount: 0.0001,
|
|
143
|
-
// }));
|
|
144
|
-
//
|
|
145
|
-
// const values: CreateMultipleStreamsValues = {
|
|
146
|
-
// releaseAmount: 0.00001,
|
|
147
|
-
// tokenSymbol: "",
|
|
148
|
-
// startDate: format(now, DATE_FORMAT),
|
|
149
|
-
// startTime: format(add(now, { minutes: 5 }), TIME_FORMAT),
|
|
150
|
-
// releaseFrequencyCounter: 1,
|
|
151
|
-
// releaseFrequencyPeriod: timePeriodOptions[0].value,
|
|
152
|
-
// whoCanTransfer: TransferCancelOptions.Recipient,
|
|
153
|
-
// whoCanCancel: TransferCancelOptions.Sender,
|
|
154
|
-
// automaticWithdrawal: false,
|
|
155
|
-
// withdrawalFrequencyCounter: 1,
|
|
156
|
-
// withdrawalFrequencyPeriod: timePeriodOptions[1].value,
|
|
157
|
-
// referral: "",
|
|
158
|
-
// email: "",
|
|
159
|
-
// recipients: recipientsPayload,
|
|
160
|
-
// };
|
|
161
|
-
// const data = newCreateMultipleStreamsPayload(values, sender);
|
|
162
|
-
// const response = await streamInstance?.createMultiple(data);
|
|
163
|
-
// const errors = response?.errors;
|
|
164
|
-
// console.log(errors);
|
|
165
|
-
// return response;
|
|
166
|
-
// }, 600000);
|