@streamflow/stream 3.0.12 → 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 +119 -60
- 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 -4
- package/dist/__tests__/streams.spec.d.ts +0 -15
- package/dist/__tests__/streams.spec.js +0 -250
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
|
@@ -141,38 +141,49 @@ var StreamClient = /** @class */ (function () {
|
|
|
141
141
|
* @param {boolean} data.transferableByRecipient - Whether or not recipient can transfer the stream.
|
|
142
142
|
* @param {boolean} data.automaticWithdrawal - Whether or not a 3rd party can initiate withdraw in the name of recipient.
|
|
143
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
|
|
144
145
|
* @param {string | null} [data.partner = null] - Partner's wallet address (optional).
|
|
145
146
|
*/
|
|
146
147
|
StreamClient.prototype.create = function (_a) {
|
|
147
|
-
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;
|
|
148
149
|
return __awaiter(this, void 0, void 0, function () {
|
|
149
|
-
var ixs, mintPublicKey, recipientPublicKey, metadata,
|
|
150
|
-
var
|
|
151
|
-
return __generator(this, function (
|
|
152
|
-
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) {
|
|
153
154
|
case 0:
|
|
154
155
|
ixs = [];
|
|
155
|
-
mintPublicKey = new web3_js_1.PublicKey(mint);
|
|
156
|
+
mintPublicKey = isNative ? new web3_js_1.PublicKey(mint) : spl_token_1.NATIVE_MINT;
|
|
156
157
|
recipientPublicKey = new web3_js_1.PublicKey(recipient);
|
|
157
158
|
metadata = web3_js_1.Keypair.generate();
|
|
158
159
|
return [4 /*yield*/, web3_js_1.PublicKey.findProgramAddress([buffer_1.Buffer.from("strm"), metadata.publicKey.toBuffer()], this.programId)];
|
|
159
160
|
case 1:
|
|
160
|
-
|
|
161
|
+
_f = __read.apply(void 0, [_j.sent(), 1]), escrowTokens = _f[0];
|
|
161
162
|
return [4 /*yield*/, ata(mintPublicKey, sender.publicKey)];
|
|
162
163
|
case 2:
|
|
163
|
-
senderTokens =
|
|
164
|
+
senderTokens = _j.sent();
|
|
164
165
|
return [4 /*yield*/, ata(mintPublicKey, recipientPublicKey)];
|
|
165
166
|
case 3:
|
|
166
|
-
recipientTokens =
|
|
167
|
+
recipientTokens = _j.sent();
|
|
167
168
|
return [4 /*yield*/, ata(mintPublicKey, constants_1.STREAMFLOW_TREASURY_PUBLIC_KEY)];
|
|
168
169
|
case 4:
|
|
169
|
-
streamflowTreasuryTokens =
|
|
170
|
+
streamflowTreasuryTokens = _j.sent();
|
|
170
171
|
partnerPublicKey = partner
|
|
171
172
|
? new web3_js_1.PublicKey(partner)
|
|
172
173
|
: constants_1.STREAMFLOW_TREASURY_PUBLIC_KEY;
|
|
173
174
|
return [4 /*yield*/, ata(mintPublicKey, partnerPublicKey)];
|
|
174
175
|
case 5:
|
|
175
|
-
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;
|
|
176
187
|
ixs.push((0, instructions_1.createStreamInstruction)({
|
|
177
188
|
start: new bn_js_1.default(start),
|
|
178
189
|
depositedAmount: depositedAmount,
|
|
@@ -212,17 +223,17 @@ var StreamClient = /** @class */ (function () {
|
|
|
212
223
|
? this.commitment
|
|
213
224
|
: this.commitment.commitment;
|
|
214
225
|
return [4 /*yield*/, this.connection.getLatestBlockhash(commitment)];
|
|
215
|
-
case
|
|
216
|
-
hash =
|
|
217
|
-
tx = (
|
|
226
|
+
case 9:
|
|
227
|
+
hash = _j.sent();
|
|
228
|
+
tx = (_h = new web3_js_1.Transaction({
|
|
218
229
|
feePayer: sender.publicKey,
|
|
219
230
|
blockhash: hash.blockhash,
|
|
220
231
|
lastValidBlockHeight: hash.lastValidBlockHeight,
|
|
221
|
-
})).add.apply(
|
|
232
|
+
})).add.apply(_h, __spreadArray(__spreadArray([], __read(nativeInstructions), false), __read(ixs), false));
|
|
222
233
|
tx.partialSign(metadata);
|
|
223
234
|
return [4 /*yield*/, this.sign(sender, tx, hash)];
|
|
224
|
-
case
|
|
225
|
-
signature =
|
|
235
|
+
case 10:
|
|
236
|
+
signature = _j.sent();
|
|
226
237
|
return [2 /*return*/, { ixs: ixs, tx: signature, metadata: metadata }];
|
|
227
238
|
}
|
|
228
239
|
});
|
|
@@ -256,22 +267,23 @@ var StreamClient = /** @class */ (function () {
|
|
|
256
267
|
* @param {boolean} data.transferableByRecipient - Whether or not recipient can transfer the stream.
|
|
257
268
|
* @param {boolean} data.automaticWithdrawal - Whether or not a 3rd party can initiate withdraw in the name of recipient.
|
|
258
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.
|
|
259
|
-
* @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).
|
|
260
272
|
*/
|
|
261
273
|
StreamClient.prototype.createUnchecked = function (_a) {
|
|
262
|
-
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;
|
|
263
275
|
return __awaiter(this, void 0, void 0, function () {
|
|
264
|
-
var mintPublicKey, recipientPublicKey, metadata, rentToExempt, createMetadataInstruction,
|
|
265
|
-
var
|
|
266
|
-
return __generator(this, function (
|
|
267
|
-
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) {
|
|
268
280
|
case 0:
|
|
269
281
|
mintPublicKey = new web3_js_1.PublicKey(mint);
|
|
270
282
|
recipientPublicKey = new web3_js_1.PublicKey(recipient);
|
|
271
283
|
metadata = web3_js_1.Keypair.generate();
|
|
272
284
|
return [4 /*yield*/, this.connection.getMinimumBalanceForRentExemption(METADATA_ACC_SIZE)];
|
|
273
285
|
case 1:
|
|
274
|
-
rentToExempt =
|
|
286
|
+
rentToExempt = _j.sent();
|
|
275
287
|
createMetadataInstruction = web3_js_1.SystemProgram.createAccount({
|
|
276
288
|
programId: this.programId,
|
|
277
289
|
space: METADATA_ACC_SIZE,
|
|
@@ -281,13 +293,23 @@ var StreamClient = /** @class */ (function () {
|
|
|
281
293
|
});
|
|
282
294
|
return [4 /*yield*/, web3_js_1.PublicKey.findProgramAddress([buffer_1.Buffer.from("strm"), metadata.publicKey.toBuffer()], this.programId)];
|
|
283
295
|
case 2:
|
|
284
|
-
|
|
296
|
+
_f = __read.apply(void 0, [_j.sent(), 1]), escrowTokens = _f[0];
|
|
285
297
|
return [4 /*yield*/, ata(mintPublicKey, sender.publicKey)];
|
|
286
298
|
case 3:
|
|
287
|
-
senderTokens =
|
|
299
|
+
senderTokens = _j.sent();
|
|
288
300
|
partnerPublicKey = partner
|
|
289
301
|
? new web3_js_1.PublicKey(partner)
|
|
290
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;
|
|
291
313
|
createInstruction = (0, instructions_1.createUncheckedStreamInstruction)({
|
|
292
314
|
start: new bn_js_1.default(start),
|
|
293
315
|
depositedAmount: depositedAmount,
|
|
@@ -326,17 +348,17 @@ var StreamClient = /** @class */ (function () {
|
|
|
326
348
|
createInstruction,
|
|
327
349
|
];
|
|
328
350
|
return [4 /*yield*/, this.connection.getLatestBlockhash(commitment)];
|
|
329
|
-
case
|
|
330
|
-
hash =
|
|
331
|
-
tx = (
|
|
351
|
+
case 7:
|
|
352
|
+
hash = _j.sent();
|
|
353
|
+
tx = (_h = new web3_js_1.Transaction({
|
|
332
354
|
feePayer: sender.publicKey,
|
|
333
355
|
blockhash: hash.blockhash,
|
|
334
356
|
lastValidBlockHeight: hash.lastValidBlockHeight,
|
|
335
|
-
})).add.apply(
|
|
357
|
+
})).add.apply(_h, __spreadArray(__spreadArray([], __read(nativeInstructions), false), __read(ixs), false));
|
|
336
358
|
tx.partialSign(metadata);
|
|
337
359
|
return [4 /*yield*/, this.sign(sender, tx, hash)];
|
|
338
|
-
case
|
|
339
|
-
signature =
|
|
360
|
+
case 8:
|
|
361
|
+
signature = _j.sent();
|
|
340
362
|
return [2 /*return*/, { ixs: ixs, tx: signature, metadata: metadata }];
|
|
341
363
|
}
|
|
342
364
|
});
|
|
@@ -359,15 +381,16 @@ var StreamClient = /** @class */ (function () {
|
|
|
359
381
|
* @param {boolean} data.transferableByRecipient - Whether or not recipient can transfer the stream.
|
|
360
382
|
* @param {boolean} data.automaticWithdrawal - Whether or not a 3rd party can initiate withdraw in the name of recipient.
|
|
361
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
|
|
362
385
|
* @param {string | null} [data.partner = null] - Partner's wallet address (optional).
|
|
363
386
|
*/
|
|
364
387
|
StreamClient.prototype.createMultiple = function (data) {
|
|
365
388
|
return __awaiter(this, void 0, void 0, function () {
|
|
366
|
-
var sender, recipientsData, metadatas, metadataToRecipient, errors, signatures, batch, recipientsData_1, recipientsData_1_1, recipientData, _a, tx, metadata, metadataPubKey, e_1_1, signed_batch, batchTransactionsCalls, responses, successes, failures;
|
|
367
|
-
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;
|
|
368
391
|
var _this = this;
|
|
369
|
-
return __generator(this, function (
|
|
370
|
-
switch (
|
|
392
|
+
return __generator(this, function (_d) {
|
|
393
|
+
switch (_d.label) {
|
|
371
394
|
case 0:
|
|
372
395
|
sender = data.sender, recipientsData = data.recipientsData;
|
|
373
396
|
metadatas = [];
|
|
@@ -375,28 +398,28 @@ var StreamClient = /** @class */ (function () {
|
|
|
375
398
|
errors = [];
|
|
376
399
|
signatures = [];
|
|
377
400
|
batch = [];
|
|
378
|
-
|
|
401
|
+
_d.label = 1;
|
|
379
402
|
case 1:
|
|
380
|
-
|
|
403
|
+
_d.trys.push([1, 6, 7, 8]);
|
|
381
404
|
recipientsData_1 = __values(recipientsData), recipientsData_1_1 = recipientsData_1.next();
|
|
382
|
-
|
|
405
|
+
_d.label = 2;
|
|
383
406
|
case 2:
|
|
384
407
|
if (!!recipientsData_1_1.done) return [3 /*break*/, 5];
|
|
385
408
|
recipientData = recipientsData_1_1.value;
|
|
386
409
|
return [4 /*yield*/, this.prepareStreamTransaction(recipientData, data)];
|
|
387
410
|
case 3:
|
|
388
|
-
_a =
|
|
411
|
+
_a = _d.sent(), tx = _a.tx, metadata = _a.metadata;
|
|
389
412
|
metadataPubKey = metadata.publicKey.toBase58();
|
|
390
413
|
metadataToRecipient[metadataPubKey] = recipientData;
|
|
391
414
|
metadatas.push(metadata);
|
|
392
415
|
batch.push({ tx: tx, recipient: recipientData.recipient });
|
|
393
|
-
|
|
416
|
+
_d.label = 4;
|
|
394
417
|
case 4:
|
|
395
418
|
recipientsData_1_1 = recipientsData_1.next();
|
|
396
419
|
return [3 /*break*/, 2];
|
|
397
420
|
case 5: return [3 /*break*/, 8];
|
|
398
421
|
case 6:
|
|
399
|
-
e_1_1 =
|
|
422
|
+
e_1_1 = _d.sent();
|
|
400
423
|
e_1 = { error: e_1_1 };
|
|
401
424
|
return [3 /*break*/, 8];
|
|
402
425
|
case 7:
|
|
@@ -405,15 +428,41 @@ var StreamClient = /** @class */ (function () {
|
|
|
405
428
|
}
|
|
406
429
|
finally { if (e_1) throw e_1.error; }
|
|
407
430
|
return [7 /*endfinally*/];
|
|
408
|
-
case 8:
|
|
431
|
+
case 8:
|
|
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)];
|
|
409
435
|
case 9:
|
|
410
|
-
|
|
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)];
|
|
441
|
+
case 10:
|
|
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:
|
|
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:
|
|
411
460
|
batchTransactionsCalls = signed_batch.map(function (el) {
|
|
412
461
|
return sendAndConfirmStreamRawTransaction(_this.connection, el);
|
|
413
462
|
});
|
|
414
463
|
return [4 /*yield*/, Promise.allSettled(batchTransactionsCalls)];
|
|
415
|
-
case
|
|
416
|
-
responses =
|
|
464
|
+
case 15:
|
|
465
|
+
responses = _d.sent();
|
|
417
466
|
successes = responses
|
|
418
467
|
.filter(function (el) {
|
|
419
468
|
return el.status === "fulfilled";
|
|
@@ -621,28 +670,38 @@ var StreamClient = /** @class */ (function () {
|
|
|
621
670
|
* @param {BN} data.amount - Specified amount (in the smallest units) to topup (increases deposited amount).
|
|
622
671
|
*/
|
|
623
672
|
StreamClient.prototype.topup = function (_a) {
|
|
624
|
-
var invoker = _a.invoker, id = _a.id, amount = _a.amount;
|
|
673
|
+
var invoker = _a.invoker, id = _a.id, amount = _a.amount, isNative = _a.isNative;
|
|
625
674
|
return __awaiter(this, void 0, void 0, function () {
|
|
626
|
-
var ixs, streamPublicKey, escrow, _b, mint, partner, senderTokens, escrowTokens, streamflowTreasuryTokens, partnerTokens, commitment, hash, tx, signature;
|
|
627
|
-
var
|
|
628
|
-
return __generator(this, function (
|
|
629
|
-
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) {
|
|
630
679
|
case 0:
|
|
631
680
|
ixs = [];
|
|
632
681
|
streamPublicKey = new web3_js_1.PublicKey(id);
|
|
633
682
|
return [4 /*yield*/, this.connection.getAccountInfo(streamPublicKey)];
|
|
634
683
|
case 1:
|
|
635
|
-
escrow =
|
|
684
|
+
escrow = _e.sent();
|
|
636
685
|
if (!(escrow === null || escrow === void 0 ? void 0 : escrow.data)) {
|
|
637
686
|
throw new Error("Couldn't get account info");
|
|
638
687
|
}
|
|
639
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;
|
|
640
689
|
return [4 /*yield*/, ata(mint, constants_1.STREAMFLOW_TREASURY_PUBLIC_KEY)];
|
|
641
690
|
case 2:
|
|
642
|
-
streamflowTreasuryTokens =
|
|
691
|
+
streamflowTreasuryTokens = _e.sent();
|
|
643
692
|
return [4 /*yield*/, ata(mint, partner)];
|
|
644
693
|
case 3:
|
|
645
|
-
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;
|
|
646
705
|
ixs.push((0, instructions_1.topupStreamInstruction)(amount, this.programId, {
|
|
647
706
|
sender: invoker.publicKey,
|
|
648
707
|
senderTokens: senderTokens,
|
|
@@ -661,16 +720,16 @@ var StreamClient = /** @class */ (function () {
|
|
|
661
720
|
? this.commitment
|
|
662
721
|
: this.commitment.commitment;
|
|
663
722
|
return [4 /*yield*/, this.connection.getLatestBlockhash(commitment)];
|
|
664
|
-
case
|
|
665
|
-
hash =
|
|
666
|
-
tx = (
|
|
723
|
+
case 7:
|
|
724
|
+
hash = _e.sent();
|
|
725
|
+
tx = (_d = new web3_js_1.Transaction({
|
|
667
726
|
feePayer: invoker.publicKey,
|
|
668
727
|
blockhash: hash.blockhash,
|
|
669
728
|
lastValidBlockHeight: hash.lastValidBlockHeight,
|
|
670
|
-
})).add.apply(
|
|
729
|
+
})).add.apply(_d, __spreadArray(__spreadArray([], __read(nativeInstructions), false), __read(ixs), false));
|
|
671
730
|
return [4 /*yield*/, this.sign(invoker, tx, hash)];
|
|
672
|
-
case
|
|
673
|
-
signature =
|
|
731
|
+
case 8:
|
|
732
|
+
signature = _e.sent();
|
|
674
733
|
return [2 /*return*/, { ixs: ixs, tx: signature }];
|
|
675
734
|
}
|
|
676
735
|
});
|
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,9 +11,9 @@
|
|
|
11
11
|
},
|
|
12
12
|
"gitHead": "a37306eba0e762af096db642fa22f07194014cfd",
|
|
13
13
|
"devDependencies": {
|
|
14
|
-
"@types/bn.js": "
|
|
15
|
-
"date-fns": "
|
|
16
|
-
"typescript": "
|
|
14
|
+
"@types/bn.js": "5.1.0",
|
|
15
|
+
"date-fns": "2.28.0",
|
|
16
|
+
"typescript": "4.6.4"
|
|
17
17
|
},
|
|
18
18
|
"dependencies": {
|
|
19
19
|
"@project-serum/anchor": "^0.16.2",
|
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
export declare const DATE_FORMAT = "yyyy-MM-dd";
|
|
2
|
-
export declare const TIME_FORMAT = "HH:mm";
|
|
3
|
-
export declare const PERIOD: {
|
|
4
|
-
SECOND: number;
|
|
5
|
-
MINUTE: number;
|
|
6
|
-
HOUR: number;
|
|
7
|
-
DAY: number;
|
|
8
|
-
WEEK: number;
|
|
9
|
-
MONTH: number;
|
|
10
|
-
YEAR: number;
|
|
11
|
-
};
|
|
12
|
-
export declare const timePeriodOptions: {
|
|
13
|
-
value: number;
|
|
14
|
-
label: string;
|
|
15
|
-
}[];
|
|
@@ -1,250 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
-
if (k2 === undefined) k2 = k;
|
|
4
|
-
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
-
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
-
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
-
}
|
|
8
|
-
Object.defineProperty(o, k2, desc);
|
|
9
|
-
}) : (function(o, m, k, k2) {
|
|
10
|
-
if (k2 === undefined) k2 = k;
|
|
11
|
-
o[k2] = m[k];
|
|
12
|
-
}));
|
|
13
|
-
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
-
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
-
}) : function(o, v) {
|
|
16
|
-
o["default"] = v;
|
|
17
|
-
});
|
|
18
|
-
var __importStar = (this && this.__importStar) || function (mod) {
|
|
19
|
-
if (mod && mod.__esModule) return mod;
|
|
20
|
-
var result = {};
|
|
21
|
-
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
22
|
-
__setModuleDefault(result, mod);
|
|
23
|
-
return result;
|
|
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
|
-
};
|
|
89
|
-
var _a;
|
|
90
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
91
|
-
exports.timePeriodOptions = exports.PERIOD = exports.TIME_FORMAT = exports.DATE_FORMAT = void 0;
|
|
92
|
-
var StreamClient_1 = __importDefault(require("../StreamClient"));
|
|
93
|
-
var types_1 = require("../types");
|
|
94
|
-
var web3 = __importStar(require("@solana/web3.js"));
|
|
95
|
-
var utils_1 = require("../utils");
|
|
96
|
-
var airdrop_request_1 = require("./test_dependencies/airdrop/airdrop-request");
|
|
97
|
-
var anchor_1 = require("@project-serum/anchor");
|
|
98
|
-
var constants_1 = require("../constants");
|
|
99
|
-
var bn_js_1 = require("bn.js");
|
|
100
|
-
var streamInstance = null;
|
|
101
|
-
var sender;
|
|
102
|
-
var recipient;
|
|
103
|
-
var recipients = [];
|
|
104
|
-
var connection = null;
|
|
105
|
-
var date_fns_1 = require("date-fns");
|
|
106
|
-
var CLUSTER_LOCAL = "local";
|
|
107
|
-
var clusterUrls = (_a = {},
|
|
108
|
-
_a[CLUSTER_LOCAL] = function () { return "http://localhost:8899"; },
|
|
109
|
-
_a[types_1.Cluster.Devnet] = function () { return "https://api.devnet.solana.com"; },
|
|
110
|
-
_a[types_1.Cluster.Mainnet] = function () { return "https://api.mainnet-beta.solana.com"; },
|
|
111
|
-
_a);
|
|
112
|
-
beforeAll(function () { return __awaiter(void 0, void 0, void 0, function () {
|
|
113
|
-
return __generator(this, function (_a) {
|
|
114
|
-
switch (_a.label) {
|
|
115
|
-
case 0:
|
|
116
|
-
streamInstance = new StreamClient_1.default(clusterUrls[types_1.Cluster.Devnet](), types_1.Cluster.Devnet, {
|
|
117
|
-
commitment: "confirmed",
|
|
118
|
-
disableRetryOnRateLimit: true,
|
|
119
|
-
});
|
|
120
|
-
connection = new web3.Connection(web3.clusterApiUrl(), "confirmed");
|
|
121
|
-
sender = new anchor_1.Wallet(web3.Keypair.generate());
|
|
122
|
-
recipient = new anchor_1.Wallet(web3.Keypair.generate());
|
|
123
|
-
recipients = __spreadArray([], __read(new Array(10)), false).map(function () { return new anchor_1.Wallet(web3.Keypair.generate()); });
|
|
124
|
-
return [4 /*yield*/, (0, airdrop_request_1.requestAirdrop)(sender, connection)];
|
|
125
|
-
case 1:
|
|
126
|
-
_a.sent();
|
|
127
|
-
return [2 /*return*/];
|
|
128
|
-
}
|
|
129
|
-
});
|
|
130
|
-
}); }, 100000);
|
|
131
|
-
test("Sender wallet airdropped funds", function () { return __awaiter(void 0, void 0, void 0, function () {
|
|
132
|
-
var _a;
|
|
133
|
-
return __generator(this, function (_b) {
|
|
134
|
-
switch (_b.label) {
|
|
135
|
-
case 0:
|
|
136
|
-
_a = expect;
|
|
137
|
-
return [4 /*yield*/, (connection === null || connection === void 0 ? void 0 : connection.getBalance(sender.publicKey))];
|
|
138
|
-
case 1:
|
|
139
|
-
_a.apply(void 0, [_b.sent()]).toBeGreaterThan(0);
|
|
140
|
-
return [2 /*return*/];
|
|
141
|
-
}
|
|
142
|
-
});
|
|
143
|
-
}); }, 100000);
|
|
144
|
-
test("Stream client connects to cluster", function () { return __awaiter(void 0, void 0, void 0, function () {
|
|
145
|
-
var streamInstanceConnection;
|
|
146
|
-
return __generator(this, function (_a) {
|
|
147
|
-
switch (_a.label) {
|
|
148
|
-
case 0:
|
|
149
|
-
expect(streamInstance).toBeTruthy();
|
|
150
|
-
return [4 /*yield*/, (streamInstance === null || streamInstance === void 0 ? void 0 : streamInstance.getConnection())];
|
|
151
|
-
case 1:
|
|
152
|
-
streamInstanceConnection = _a.sent();
|
|
153
|
-
expect(streamInstanceConnection).toBeTruthy();
|
|
154
|
-
return [2 /*return*/];
|
|
155
|
-
}
|
|
156
|
-
});
|
|
157
|
-
}); });
|
|
158
|
-
var newCreateMultipleStreamsPayload = function (values, sender) {
|
|
159
|
-
var recipients = values.recipients, releaseAmount = values.releaseAmount, startDate = values.startDate, startTime = values.startTime, releaseFrequencyCounter = values.releaseFrequencyCounter, releaseFrequencyPeriod = values.releaseFrequencyPeriod, whoCanTransfer = values.whoCanTransfer, whoCanCancel = values.whoCanCancel, referral = values.referral;
|
|
160
|
-
var start = (0, date_fns_1.getUnixTime)(new Date(startDate + "T" + startTime));
|
|
161
|
-
var recipientsFormatted = recipients.map(function (_a) {
|
|
162
|
-
var depositedAmount = _a.depositedAmount, recipient = _a.recipient, name = _a.name;
|
|
163
|
-
return ({
|
|
164
|
-
recipient: recipient,
|
|
165
|
-
name: name,
|
|
166
|
-
depositedAmount: (0, utils_1.getBN)(depositedAmount, 9),
|
|
167
|
-
amountPerPeriod: (0, utils_1.getBN)(releaseAmount, 9),
|
|
168
|
-
cliffAmount: new bn_js_1.BN(0),
|
|
169
|
-
});
|
|
170
|
-
});
|
|
171
|
-
var data = {
|
|
172
|
-
sender: sender,
|
|
173
|
-
recipientsData: recipientsFormatted,
|
|
174
|
-
mint: constants_1.AIRDROP_TEST_TOKEN,
|
|
175
|
-
start: start,
|
|
176
|
-
period: releaseFrequencyCounter * releaseFrequencyPeriod,
|
|
177
|
-
cliff: start,
|
|
178
|
-
cancelableBySender: whoCanCancel === types_1.TransferCancelOptions.Sender ||
|
|
179
|
-
whoCanCancel === types_1.TransferCancelOptions.Both,
|
|
180
|
-
cancelableByRecipient: whoCanCancel === types_1.TransferCancelOptions.Recipient ||
|
|
181
|
-
whoCanCancel === types_1.TransferCancelOptions.Both,
|
|
182
|
-
transferableBySender: whoCanTransfer === types_1.TransferCancelOptions.Sender ||
|
|
183
|
-
whoCanTransfer === types_1.TransferCancelOptions.Both,
|
|
184
|
-
transferableByRecipient: whoCanTransfer === types_1.TransferCancelOptions.Recipient ||
|
|
185
|
-
whoCanTransfer === types_1.TransferCancelOptions.Both,
|
|
186
|
-
automaticWithdrawal: false,
|
|
187
|
-
withdrawalFrequency: 0,
|
|
188
|
-
canTopup: true,
|
|
189
|
-
partner: referral,
|
|
190
|
-
};
|
|
191
|
-
return data;
|
|
192
|
-
};
|
|
193
|
-
exports.DATE_FORMAT = "yyyy-MM-dd";
|
|
194
|
-
exports.TIME_FORMAT = "HH:mm";
|
|
195
|
-
exports.PERIOD = {
|
|
196
|
-
SECOND: 1,
|
|
197
|
-
MINUTE: 60,
|
|
198
|
-
HOUR: 3600,
|
|
199
|
-
DAY: 24 * 3600,
|
|
200
|
-
WEEK: 7 * 24 * 3600,
|
|
201
|
-
MONTH: Math.floor(30.4167 * 24 * 3600),
|
|
202
|
-
YEAR: 365 * 24 * 3600, // 365 days
|
|
203
|
-
};
|
|
204
|
-
exports.timePeriodOptions = [
|
|
205
|
-
{ value: exports.PERIOD.SECOND, label: "second" },
|
|
206
|
-
{ value: exports.PERIOD.MINUTE, label: "minute" },
|
|
207
|
-
{ value: exports.PERIOD.HOUR, label: "hour" },
|
|
208
|
-
{ value: exports.PERIOD.DAY, label: "day" },
|
|
209
|
-
{ value: exports.PERIOD.WEEK, label: "week" },
|
|
210
|
-
{ value: exports.PERIOD.MONTH, label: "month" },
|
|
211
|
-
{ value: exports.PERIOD.YEAR, label: "year" },
|
|
212
|
-
];
|
|
213
|
-
test("Can create multiple stremas", function () { return __awaiter(void 0, void 0, void 0, function () {
|
|
214
|
-
var now, recipientsPayload, values, data, response, errors;
|
|
215
|
-
return __generator(this, function (_a) {
|
|
216
|
-
switch (_a.label) {
|
|
217
|
-
case 0:
|
|
218
|
-
now = new Date();
|
|
219
|
-
recipientsPayload = recipients.map(function (recipient, i) { return ({
|
|
220
|
-
recipient: recipient.publicKey.toBase58(),
|
|
221
|
-
recipientEmail: "",
|
|
222
|
-
name: "Recipient " + i,
|
|
223
|
-
depositedAmount: 0.0001,
|
|
224
|
-
}); });
|
|
225
|
-
values = {
|
|
226
|
-
releaseAmount: 0.00001,
|
|
227
|
-
tokenSymbol: "",
|
|
228
|
-
startDate: (0, date_fns_1.format)(now, exports.DATE_FORMAT),
|
|
229
|
-
startTime: (0, date_fns_1.format)((0, date_fns_1.add)(now, { minutes: 5 }), exports.TIME_FORMAT),
|
|
230
|
-
releaseFrequencyCounter: 1,
|
|
231
|
-
releaseFrequencyPeriod: exports.timePeriodOptions[0].value,
|
|
232
|
-
whoCanTransfer: types_1.TransferCancelOptions.Recipient,
|
|
233
|
-
whoCanCancel: types_1.TransferCancelOptions.Sender,
|
|
234
|
-
automaticWithdrawal: false,
|
|
235
|
-
withdrawalFrequencyCounter: 1,
|
|
236
|
-
withdrawalFrequencyPeriod: exports.timePeriodOptions[1].value,
|
|
237
|
-
referral: "",
|
|
238
|
-
email: "",
|
|
239
|
-
recipients: recipientsPayload,
|
|
240
|
-
};
|
|
241
|
-
data = newCreateMultipleStreamsPayload(values, sender);
|
|
242
|
-
return [4 /*yield*/, (streamInstance === null || streamInstance === void 0 ? void 0 : streamInstance.createMultiple(data))];
|
|
243
|
-
case 1:
|
|
244
|
-
response = _a.sent();
|
|
245
|
-
errors = response === null || response === void 0 ? void 0 : response.errors;
|
|
246
|
-
console.log(errors);
|
|
247
|
-
return [2 /*return*/, response];
|
|
248
|
-
}
|
|
249
|
-
});
|
|
250
|
-
}); }, 600000);
|