@streamflow/stream 3.0.8 → 3.0.11
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 +31 -0
- package/dist/StreamClient.js +151 -25
- package/dist/__tests__/streams.spec.d.ts +0 -15
- package/dist/__tests__/streams.spec.js +165 -249
- package/dist/instructions.d.ts +32 -0
- package/dist/instructions.js +52 -1
- package/dist/layout.d.ts +4 -0
- package/dist/layout.js +24 -1
- package/package.json +5 -1
package/dist/StreamClient.d.ts
CHANGED
|
@@ -36,6 +36,37 @@ export default class StreamClient {
|
|
|
36
36
|
* @param {string | null} [data.partner = null] - Partner's wallet address (optional).
|
|
37
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
|
+
/**
|
|
40
|
+
* Creates a new stream/vesting contract using unchecked instruction.
|
|
41
|
+
*
|
|
42
|
+
* Unchecked instruction differes from the regular in:
|
|
43
|
+
* - does not check for initialized associated token account (wallets with no control over their ATA should not be used
|
|
44
|
+
* as sender/recipient/partner or there are risks of funds being locked in the contract)
|
|
45
|
+
* - initialized contract PDA off chain
|
|
46
|
+
*
|
|
47
|
+
* If you are not sure if you should use create or create_unchecked, go for create to be safer.
|
|
48
|
+
*
|
|
49
|
+
* @param {CreateParams} data
|
|
50
|
+
* @param {Wallet | Keypair} data.sender - Wallet signing the transaction. Its address should match the authorized wallet (sender) or transaction will fail.
|
|
51
|
+
* @param {string} data.recipient - Solana address of the recipient. Associated token account will be derived using this address and token mint address.
|
|
52
|
+
* @param {string} data.mint - SPL Token mint.
|
|
53
|
+
* @param {number} data.start - Timestamp (in seconds) when the stream/token vesting starts.
|
|
54
|
+
* @param {BN} data.depositedAmount - Initially deposited amount of tokens (in the smallest units).
|
|
55
|
+
* @param {number} data.period - Time step (period) in seconds per which the unlocking occurs.
|
|
56
|
+
* @param {number} data.cliff - Vesting contract "cliff" timestamp in seconds.
|
|
57
|
+
* @param {BN} data.cliffAmount - Amount unlocked at the "cliff".
|
|
58
|
+
* @param {BN} data.amountPerPeriod - Amount unlocked per each period.
|
|
59
|
+
* @param {string} data.name - Stream name/subject.
|
|
60
|
+
* @param {boolean} data.canTopup - TRUE for streams, FALSE for vesting contracts.
|
|
61
|
+
* @param {boolean} data.cancelableBySender - Whether or not sender can cancel the stream.
|
|
62
|
+
* @param {boolean} data.cancelableByRecipient - Whether or not recipient can cancel the stream.
|
|
63
|
+
* @param {boolean} data.transferableBySender - Whether or not sender can transfer the stream.
|
|
64
|
+
* @param {boolean} data.transferableByRecipient - Whether or not recipient can transfer the stream.
|
|
65
|
+
* @param {boolean} data.automaticWithdrawal - Whether or not a 3rd party can initiate withdraw in the name of recipient.
|
|
66
|
+
* @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 {string | null} [data.partner = null] - Partner's wallet address (optional).
|
|
68
|
+
*/
|
|
69
|
+
createUnchecked({ sender, recipient, mint, start, depositedAmount, period, cliff, cliffAmount, amountPerPeriod, name, canTopup, cancelableBySender, cancelableByRecipient, transferableBySender, transferableByRecipient, automaticWithdrawal, withdrawalFrequency, partner, }: CreateParams): Promise<CreateResponse>;
|
|
39
70
|
/**
|
|
40
71
|
* Creates a new stream/vesting contract.
|
|
41
72
|
* All fees are paid by sender (escrow metadata account rent, escrow token account rent, recipient's associated token account rent, Streamflow's service fee).
|
package/dist/StreamClient.js
CHANGED
|
@@ -98,6 +98,7 @@ var constants_1 = require("./constants");
|
|
|
98
98
|
var instructions_1 = require("./instructions");
|
|
99
99
|
var common_1 = require("@project-serum/common");
|
|
100
100
|
var bs58_1 = require("@project-serum/anchor/dist/cjs/utils/bytes/bs58");
|
|
101
|
+
var METADATA_ACC_SIZE = 1104;
|
|
101
102
|
var StreamClient = /** @class */ (function () {
|
|
102
103
|
/**
|
|
103
104
|
* Create Stream instance
|
|
@@ -211,15 +212,16 @@ var StreamClient = /** @class */ (function () {
|
|
|
211
212
|
commitment = typeof this.commitment == "string"
|
|
212
213
|
? this.commitment
|
|
213
214
|
: this.commitment.commitment;
|
|
214
|
-
return [4 /*yield*/, this.connection.
|
|
215
|
+
return [4 /*yield*/, this.connection.getLatestBlockhash(commitment)];
|
|
215
216
|
case 6:
|
|
216
217
|
hash = _g.sent();
|
|
217
218
|
tx = (_f = new web3_js_1.Transaction({
|
|
218
219
|
feePayer: sender.publicKey,
|
|
219
|
-
|
|
220
|
+
blockhash: hash.blockhash,
|
|
221
|
+
lastValidBlockHeight: hash.lastValidBlockHeight,
|
|
220
222
|
})).add.apply(_f, __spreadArray([], __read(ixs), false));
|
|
221
223
|
tx.partialSign(metadata);
|
|
222
|
-
return [4 /*yield*/, this.sign(sender, tx)];
|
|
224
|
+
return [4 /*yield*/, this.sign(sender, tx, hash)];
|
|
223
225
|
case 7:
|
|
224
226
|
signature = _g.sent();
|
|
225
227
|
return [2 /*return*/, { ixs: ixs, tx: signature, metadata: metadata }];
|
|
@@ -227,6 +229,120 @@ var StreamClient = /** @class */ (function () {
|
|
|
227
229
|
});
|
|
228
230
|
});
|
|
229
231
|
};
|
|
232
|
+
/**
|
|
233
|
+
* Creates a new stream/vesting contract using unchecked instruction.
|
|
234
|
+
*
|
|
235
|
+
* Unchecked instruction differes from the regular in:
|
|
236
|
+
* - does not check for initialized associated token account (wallets with no control over their ATA should not be used
|
|
237
|
+
* as sender/recipient/partner or there are risks of funds being locked in the contract)
|
|
238
|
+
* - initialized contract PDA off chain
|
|
239
|
+
*
|
|
240
|
+
* If you are not sure if you should use create or create_unchecked, go for create to be safer.
|
|
241
|
+
*
|
|
242
|
+
* @param {CreateParams} data
|
|
243
|
+
* @param {Wallet | Keypair} data.sender - Wallet signing the transaction. Its address should match the authorized wallet (sender) or transaction will fail.
|
|
244
|
+
* @param {string} data.recipient - Solana address of the recipient. Associated token account will be derived using this address and token mint address.
|
|
245
|
+
* @param {string} data.mint - SPL Token mint.
|
|
246
|
+
* @param {number} data.start - Timestamp (in seconds) when the stream/token vesting starts.
|
|
247
|
+
* @param {BN} data.depositedAmount - Initially deposited amount of tokens (in the smallest units).
|
|
248
|
+
* @param {number} data.period - Time step (period) in seconds per which the unlocking occurs.
|
|
249
|
+
* @param {number} data.cliff - Vesting contract "cliff" timestamp in seconds.
|
|
250
|
+
* @param {BN} data.cliffAmount - Amount unlocked at the "cliff".
|
|
251
|
+
* @param {BN} data.amountPerPeriod - Amount unlocked per each period.
|
|
252
|
+
* @param {string} data.name - Stream name/subject.
|
|
253
|
+
* @param {boolean} data.canTopup - TRUE for streams, FALSE for vesting contracts.
|
|
254
|
+
* @param {boolean} data.cancelableBySender - Whether or not sender can cancel the stream.
|
|
255
|
+
* @param {boolean} data.cancelableByRecipient - Whether or not recipient can cancel the stream.
|
|
256
|
+
* @param {boolean} data.transferableBySender - Whether or not sender can transfer the stream.
|
|
257
|
+
* @param {boolean} data.transferableByRecipient - Whether or not recipient can transfer the stream.
|
|
258
|
+
* @param {boolean} data.automaticWithdrawal - Whether or not a 3rd party can initiate withdraw in the name of recipient.
|
|
259
|
+
* @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 {string | null} [data.partner = null] - Partner's wallet address (optional).
|
|
261
|
+
*/
|
|
262
|
+
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;
|
|
264
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
265
|
+
var mintPublicKey, recipientPublicKey, metadata, rentToExempt, createMetadataInstruction, _e, escrowTokens, senderTokens, partnerPublicKey, createInstruction, commitment, ixs, hash, tx, signature;
|
|
266
|
+
var _f;
|
|
267
|
+
return __generator(this, function (_g) {
|
|
268
|
+
switch (_g.label) {
|
|
269
|
+
case 0:
|
|
270
|
+
mintPublicKey = new web3_js_1.PublicKey(mint);
|
|
271
|
+
recipientPublicKey = new web3_js_1.PublicKey(recipient);
|
|
272
|
+
metadata = web3_js_1.Keypair.generate();
|
|
273
|
+
return [4 /*yield*/, this.connection.getMinimumBalanceForRentExemption(METADATA_ACC_SIZE)];
|
|
274
|
+
case 1:
|
|
275
|
+
rentToExempt = _g.sent();
|
|
276
|
+
createMetadataInstruction = web3_js_1.SystemProgram.createAccount({
|
|
277
|
+
programId: this.programId,
|
|
278
|
+
space: METADATA_ACC_SIZE,
|
|
279
|
+
lamports: rentToExempt,
|
|
280
|
+
fromPubkey: sender === null || sender === void 0 ? void 0 : sender.publicKey,
|
|
281
|
+
newAccountPubkey: metadata.publicKey,
|
|
282
|
+
});
|
|
283
|
+
return [4 /*yield*/, web3_js_1.PublicKey.findProgramAddress([buffer_1.Buffer.from("strm"), metadata.publicKey.toBuffer()], this.programId)];
|
|
284
|
+
case 2:
|
|
285
|
+
_e = __read.apply(void 0, [_g.sent(), 1]), escrowTokens = _e[0];
|
|
286
|
+
return [4 /*yield*/, ata(mintPublicKey, sender.publicKey)];
|
|
287
|
+
case 3:
|
|
288
|
+
senderTokens = _g.sent();
|
|
289
|
+
partnerPublicKey = partner
|
|
290
|
+
? new web3_js_1.PublicKey(partner)
|
|
291
|
+
: constants_1.STREAMFLOW_TREASURY_PUBLIC_KEY;
|
|
292
|
+
createInstruction = (0, instructions_1.createUncheckedStreamInstruction)({
|
|
293
|
+
start: new bn_js_1.default(start),
|
|
294
|
+
depositedAmount: depositedAmount,
|
|
295
|
+
period: new bn_js_1.default(period),
|
|
296
|
+
amountPerPeriod: amountPerPeriod,
|
|
297
|
+
cliff: new bn_js_1.default(cliff),
|
|
298
|
+
cliffAmount: cliffAmount,
|
|
299
|
+
cancelableBySender: cancelableBySender,
|
|
300
|
+
cancelableByRecipient: cancelableByRecipient,
|
|
301
|
+
automaticWithdrawal: automaticWithdrawal,
|
|
302
|
+
transferableBySender: transferableBySender,
|
|
303
|
+
transferableByRecipient: transferableByRecipient,
|
|
304
|
+
canTopup: canTopup,
|
|
305
|
+
name: name,
|
|
306
|
+
withdrawFrequency: new bn_js_1.default(automaticWithdrawal ? withdrawalFrequency : period),
|
|
307
|
+
recipient: recipientPublicKey,
|
|
308
|
+
partner: partnerPublicKey,
|
|
309
|
+
}, this.programId, {
|
|
310
|
+
sender: sender.publicKey,
|
|
311
|
+
senderTokens: senderTokens,
|
|
312
|
+
metadata: metadata.publicKey,
|
|
313
|
+
escrowTokens: escrowTokens,
|
|
314
|
+
mint: new web3_js_1.PublicKey(mint),
|
|
315
|
+
feeOracle: constants_1.FEE_ORACLE_PUBLIC_KEY,
|
|
316
|
+
rent: web3_js_1.SYSVAR_RENT_PUBKEY,
|
|
317
|
+
timelockProgram: this.programId,
|
|
318
|
+
tokenProgram: spl_token_1.TOKEN_PROGRAM_ID,
|
|
319
|
+
withdrawor: constants_1.WITHDRAWOR_PUBLIC_KEY,
|
|
320
|
+
systemProgram: web3_js_1.SystemProgram.programId,
|
|
321
|
+
});
|
|
322
|
+
commitment = typeof this.commitment == "string"
|
|
323
|
+
? this.commitment
|
|
324
|
+
: this.commitment.commitment;
|
|
325
|
+
ixs = [
|
|
326
|
+
createMetadataInstruction,
|
|
327
|
+
createInstruction,
|
|
328
|
+
];
|
|
329
|
+
return [4 /*yield*/, this.connection.getLatestBlockhash(commitment)];
|
|
330
|
+
case 4:
|
|
331
|
+
hash = _g.sent();
|
|
332
|
+
tx = (_f = new web3_js_1.Transaction({
|
|
333
|
+
feePayer: sender.publicKey,
|
|
334
|
+
blockhash: hash.blockhash,
|
|
335
|
+
lastValidBlockHeight: hash.lastValidBlockHeight,
|
|
336
|
+
})).add.apply(_f, __spreadArray([], __read(ixs), false));
|
|
337
|
+
tx.partialSign(metadata);
|
|
338
|
+
return [4 /*yield*/, this.sign(sender, tx, hash)];
|
|
339
|
+
case 5:
|
|
340
|
+
signature = _g.sent();
|
|
341
|
+
return [2 /*return*/, { ixs: ixs, tx: signature, metadata: metadata }];
|
|
342
|
+
}
|
|
343
|
+
});
|
|
344
|
+
});
|
|
345
|
+
};
|
|
230
346
|
/**
|
|
231
347
|
* Creates a new stream/vesting contract.
|
|
232
348
|
* All fees are paid by sender (escrow metadata account rent, escrow token account rent, recipient's associated token account rent, Streamflow's service fee).
|
|
@@ -393,14 +509,15 @@ var StreamClient = /** @class */ (function () {
|
|
|
393
509
|
commitment = typeof this.commitment == "string"
|
|
394
510
|
? this.commitment
|
|
395
511
|
: this.commitment.commitment;
|
|
396
|
-
return [4 /*yield*/, this.connection.
|
|
512
|
+
return [4 /*yield*/, this.connection.getLatestBlockhash(commitment)];
|
|
397
513
|
case 4:
|
|
398
514
|
hash = _c.sent();
|
|
399
515
|
tx = (_b = new web3_js_1.Transaction({
|
|
400
516
|
feePayer: invoker.publicKey,
|
|
401
|
-
|
|
517
|
+
blockhash: hash.blockhash,
|
|
518
|
+
lastValidBlockHeight: hash.lastValidBlockHeight,
|
|
402
519
|
})).add.apply(_b, __spreadArray([], __read(ixs), false));
|
|
403
|
-
return [4 /*yield*/, this.sign(invoker, tx)];
|
|
520
|
+
return [4 /*yield*/, this.sign(invoker, tx, hash)];
|
|
404
521
|
case 5:
|
|
405
522
|
signature = _c.sent();
|
|
406
523
|
return [2 /*return*/, { ixs: ixs, tx: signature }];
|
|
@@ -455,14 +572,15 @@ var StreamClient = /** @class */ (function () {
|
|
|
455
572
|
commitment = typeof this.commitment == "string"
|
|
456
573
|
? this.commitment
|
|
457
574
|
: this.commitment.commitment;
|
|
458
|
-
return [4 /*yield*/, this.connection.
|
|
575
|
+
return [4 /*yield*/, this.connection.getLatestBlockhash(commitment)];
|
|
459
576
|
case 4:
|
|
460
577
|
hash = _c.sent();
|
|
461
578
|
tx = (_b = new web3_js_1.Transaction({
|
|
462
579
|
feePayer: invoker.publicKey,
|
|
463
|
-
|
|
580
|
+
blockhash: hash.blockhash,
|
|
581
|
+
lastValidBlockHeight: hash.lastValidBlockHeight,
|
|
464
582
|
})).add.apply(_b, __spreadArray([], __read(ixs), false));
|
|
465
|
-
return [4 /*yield*/, this.sign(invoker, tx)];
|
|
583
|
+
return [4 /*yield*/, this.sign(invoker, tx, hash)];
|
|
466
584
|
case 5:
|
|
467
585
|
signature = _c.sent();
|
|
468
586
|
return [2 /*return*/, { ixs: ixs, tx: signature }];
|
|
@@ -513,14 +631,15 @@ var StreamClient = /** @class */ (function () {
|
|
|
513
631
|
commitment = typeof this.commitment == "string"
|
|
514
632
|
? this.commitment
|
|
515
633
|
: this.commitment.commitment;
|
|
516
|
-
return [4 /*yield*/, this.connection.
|
|
634
|
+
return [4 /*yield*/, this.connection.getLatestBlockhash(commitment)];
|
|
517
635
|
case 3:
|
|
518
636
|
hash = _c.sent();
|
|
519
637
|
tx = (_b = new web3_js_1.Transaction({
|
|
520
638
|
feePayer: invoker.publicKey,
|
|
521
|
-
|
|
639
|
+
blockhash: hash.blockhash,
|
|
640
|
+
lastValidBlockHeight: hash.lastValidBlockHeight,
|
|
522
641
|
})).add.apply(_b, __spreadArray([], __read(ixs), false));
|
|
523
|
-
return [4 /*yield*/, this.sign(invoker, tx)];
|
|
642
|
+
return [4 /*yield*/, this.sign(invoker, tx, hash)];
|
|
524
643
|
case 4:
|
|
525
644
|
signature = _c.sent();
|
|
526
645
|
return [2 /*return*/, { ixs: ixs, tx: signature }];
|
|
@@ -575,14 +694,15 @@ var StreamClient = /** @class */ (function () {
|
|
|
575
694
|
commitment = typeof this.commitment == "string"
|
|
576
695
|
? this.commitment
|
|
577
696
|
: this.commitment.commitment;
|
|
578
|
-
return [4 /*yield*/, this.connection.
|
|
697
|
+
return [4 /*yield*/, this.connection.getLatestBlockhash(commitment)];
|
|
579
698
|
case 4:
|
|
580
699
|
hash = _d.sent();
|
|
581
700
|
tx = (_c = new web3_js_1.Transaction({
|
|
582
701
|
feePayer: invoker.publicKey,
|
|
583
|
-
|
|
702
|
+
blockhash: hash.blockhash,
|
|
703
|
+
lastValidBlockHeight: hash.lastValidBlockHeight,
|
|
584
704
|
})).add.apply(_c, __spreadArray([], __read(ixs), false));
|
|
585
|
-
return [4 /*yield*/, this.sign(invoker, tx)];
|
|
705
|
+
return [4 /*yield*/, this.sign(invoker, tx, hash)];
|
|
586
706
|
case 5:
|
|
587
707
|
signature = _d.sent();
|
|
588
708
|
return [2 /*return*/, { ixs: ixs, tx: signature }];
|
|
@@ -664,24 +784,30 @@ var StreamClient = /** @class */ (function () {
|
|
|
664
784
|
});
|
|
665
785
|
});
|
|
666
786
|
};
|
|
667
|
-
StreamClient.prototype.sign = function (invoker, tx) {
|
|
787
|
+
StreamClient.prototype.sign = function (invoker, tx, hash) {
|
|
668
788
|
return __awaiter(this, void 0, void 0, function () {
|
|
669
|
-
var rawTx, signature;
|
|
789
|
+
var rawTx, confirmationStrategy, signature;
|
|
670
790
|
return __generator(this, function (_a) {
|
|
671
791
|
switch (_a.label) {
|
|
672
792
|
case 0:
|
|
673
|
-
if (!(invoker
|
|
674
|
-
tx.partialSign(invoker);
|
|
675
|
-
return [3 /*break*/, 3];
|
|
676
|
-
case 1:
|
|
677
|
-
if (!(invoker === null || invoker === void 0 ? void 0 : invoker.signTransaction)) return [3 /*break*/, 3];
|
|
793
|
+
if (!isAnchorWallet(invoker)) return [3 /*break*/, 2];
|
|
678
794
|
return [4 /*yield*/, invoker.signTransaction(tx)];
|
|
679
|
-
case
|
|
795
|
+
case 1:
|
|
680
796
|
_a.sent();
|
|
797
|
+
return [3 /*break*/, 3];
|
|
798
|
+
case 2:
|
|
799
|
+
tx.partialSign(invoker);
|
|
681
800
|
_a.label = 3;
|
|
682
801
|
case 3:
|
|
683
802
|
rawTx = tx.serialize();
|
|
684
|
-
|
|
803
|
+
if (!hash.lastValidBlockHeight || !tx.signature || !hash.blockhash)
|
|
804
|
+
throw Error("Error with transaction parameters.");
|
|
805
|
+
confirmationStrategy = {
|
|
806
|
+
lastValidBlockHeight: hash.lastValidBlockHeight,
|
|
807
|
+
signature: (0, bs58_1.encode)(tx.signature),
|
|
808
|
+
blockhash: hash.blockhash,
|
|
809
|
+
};
|
|
810
|
+
return [4 /*yield*/, (0, web3_js_1.sendAndConfirmRawTransaction)(this.connection, rawTx, confirmationStrategy)];
|
|
685
811
|
case 4:
|
|
686
812
|
signature = _a.sent();
|
|
687
813
|
return [2 /*return*/, signature];
|
|
@@ -799,7 +925,7 @@ function ata(mint, account) {
|
|
|
799
925
|
return __awaiter(this, void 0, void 0, function () {
|
|
800
926
|
return __generator(this, function (_a) {
|
|
801
927
|
switch (_a.label) {
|
|
802
|
-
case 0: return [4 /*yield*/, spl_token_1.Token.getAssociatedTokenAddress(spl_token_1.ASSOCIATED_TOKEN_PROGRAM_ID, spl_token_1.TOKEN_PROGRAM_ID, mint, account)];
|
|
928
|
+
case 0: return [4 /*yield*/, spl_token_1.Token.getAssociatedTokenAddress(spl_token_1.ASSOCIATED_TOKEN_PROGRAM_ID, spl_token_1.TOKEN_PROGRAM_ID, mint, account, true)];
|
|
803
929
|
case 1: return [2 /*return*/, _a.sent()];
|
|
804
930
|
}
|
|
805
931
|
});
|
|
@@ -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 +1,166 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
}
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
})
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
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);
|
|
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);
|
package/dist/instructions.d.ts
CHANGED
|
@@ -37,6 +37,38 @@ interface CreateStreamAccounts {
|
|
|
37
37
|
systemProgram: PublicKey;
|
|
38
38
|
}
|
|
39
39
|
export declare const createStreamInstruction: (data: CreateStreamData, programId: PublicKey, accounts: CreateStreamAccounts) => TransactionInstruction;
|
|
40
|
+
interface CreateUncheckedStreamData {
|
|
41
|
+
start: BN;
|
|
42
|
+
depositedAmount: BN;
|
|
43
|
+
period: BN;
|
|
44
|
+
amountPerPeriod: BN;
|
|
45
|
+
cliff: BN;
|
|
46
|
+
cliffAmount: BN;
|
|
47
|
+
cancelableBySender: boolean;
|
|
48
|
+
cancelableByRecipient: boolean;
|
|
49
|
+
automaticWithdrawal: boolean;
|
|
50
|
+
transferableBySender: boolean;
|
|
51
|
+
transferableByRecipient: boolean;
|
|
52
|
+
canTopup: boolean;
|
|
53
|
+
name: string;
|
|
54
|
+
withdrawFrequency: BN;
|
|
55
|
+
recipient: PublicKey;
|
|
56
|
+
partner: PublicKey;
|
|
57
|
+
}
|
|
58
|
+
interface CreateUncheckedStreamAccounts {
|
|
59
|
+
sender: PublicKey;
|
|
60
|
+
senderTokens: PublicKey;
|
|
61
|
+
metadata: PublicKey;
|
|
62
|
+
escrowTokens: PublicKey;
|
|
63
|
+
mint: PublicKey;
|
|
64
|
+
feeOracle: PublicKey;
|
|
65
|
+
rent: PublicKey;
|
|
66
|
+
timelockProgram: PublicKey;
|
|
67
|
+
tokenProgram: PublicKey;
|
|
68
|
+
withdrawor: PublicKey;
|
|
69
|
+
systemProgram: PublicKey;
|
|
70
|
+
}
|
|
71
|
+
export declare const createUncheckedStreamInstruction: (data: CreateUncheckedStreamData, programId: PublicKey, accounts: CreateUncheckedStreamAccounts) => TransactionInstruction;
|
|
40
72
|
interface WithdrawAccounts {
|
|
41
73
|
authority: PublicKey;
|
|
42
74
|
recipient: PublicKey;
|
package/dist/instructions.js
CHANGED
|
@@ -23,7 +23,7 @@ var __importStar = (this && this.__importStar) || function (mod) {
|
|
|
23
23
|
return result;
|
|
24
24
|
};
|
|
25
25
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
26
|
-
exports.topupStreamInstruction = exports.transferStreamInstruction = exports.cancelStreamInstruction = exports.withdrawStreamInstruction = exports.createStreamInstruction = void 0;
|
|
26
|
+
exports.topupStreamInstruction = exports.transferStreamInstruction = exports.cancelStreamInstruction = exports.withdrawStreamInstruction = exports.createUncheckedStreamInstruction = exports.createStreamInstruction = void 0;
|
|
27
27
|
var buffer_1 = require("buffer");
|
|
28
28
|
var web3_js_1 = require("@solana/web3.js");
|
|
29
29
|
var js_sha256_1 = require("js-sha256");
|
|
@@ -94,6 +94,57 @@ var createStreamInstruction = function (data, programId, accounts) {
|
|
|
94
94
|
});
|
|
95
95
|
};
|
|
96
96
|
exports.createStreamInstruction = createStreamInstruction;
|
|
97
|
+
var createUncheckedStreamInstruction = function (data, programId, accounts) {
|
|
98
|
+
var keys = [
|
|
99
|
+
{ pubkey: accounts.sender, isSigner: true, isWritable: true },
|
|
100
|
+
{ pubkey: accounts.senderTokens, isSigner: false, isWritable: true },
|
|
101
|
+
{ pubkey: accounts.metadata, isSigner: false, isWritable: true },
|
|
102
|
+
{ pubkey: accounts.escrowTokens, isSigner: false, isWritable: true },
|
|
103
|
+
{ pubkey: accounts.withdrawor, isSigner: false, isWritable: true },
|
|
104
|
+
{ pubkey: accounts.mint, isSigner: false, isWritable: false },
|
|
105
|
+
{ pubkey: accounts.feeOracle, isSigner: false, isWritable: false },
|
|
106
|
+
{ pubkey: accounts.rent, isSigner: false, isWritable: false },
|
|
107
|
+
{ pubkey: accounts.timelockProgram, isSigner: false, isWritable: false },
|
|
108
|
+
{ pubkey: accounts.tokenProgram, isSigner: false, isWritable: false },
|
|
109
|
+
{ pubkey: accounts.systemProgram, isSigner: false, isWritable: false },
|
|
110
|
+
];
|
|
111
|
+
var bufferData = buffer_1.Buffer.alloc(Layout.createUncheckedStreamLayout.span);
|
|
112
|
+
var encodedUIntArray = new TextEncoder().encode(data.name);
|
|
113
|
+
var streamNameBuffer = buffer_1.Buffer.alloc(64).fill(encodedUIntArray, 0, encodedUIntArray.byteLength);
|
|
114
|
+
var decodedData = {
|
|
115
|
+
start_time: data.start.toArrayLike(buffer_1.Buffer, "le", 8),
|
|
116
|
+
net_amount_deposited: data.depositedAmount.toArrayLike(buffer_1.Buffer, "le", 8),
|
|
117
|
+
period: data.period.toArrayLike(buffer_1.Buffer, "le", 8),
|
|
118
|
+
amount_per_period: data.amountPerPeriod.toArrayLike(buffer_1.Buffer, "le", 8),
|
|
119
|
+
cliff: data.cliff.toArrayLike(buffer_1.Buffer, "le", 8),
|
|
120
|
+
cliff_amount: data.cliffAmount.toArrayLike(buffer_1.Buffer, "le", 8),
|
|
121
|
+
cancelable_by_sender: data.cancelableBySender,
|
|
122
|
+
cancelable_by_recipient: data.cancelableByRecipient,
|
|
123
|
+
automatic_withdrawal: data.automaticWithdrawal,
|
|
124
|
+
transferable_by_sender: data.transferableBySender,
|
|
125
|
+
transferable_by_recipient: data.transferableByRecipient,
|
|
126
|
+
can_topup: data.canTopup,
|
|
127
|
+
stream_name: streamNameBuffer,
|
|
128
|
+
withdraw_frequency: data.withdrawFrequency.toArrayLike(buffer_1.Buffer, "le", 8),
|
|
129
|
+
recipient: data.recipient.toBuffer(),
|
|
130
|
+
partner: data.partner.toBuffer(),
|
|
131
|
+
pausable: buffer_1.Buffer.alloc(1),
|
|
132
|
+
can_update_rate: buffer_1.Buffer.alloc(1),
|
|
133
|
+
};
|
|
134
|
+
var encodeLength = Layout.createUncheckedStreamLayout.encode(decodedData, bufferData);
|
|
135
|
+
bufferData = bufferData.slice(0, encodeLength);
|
|
136
|
+
bufferData = buffer_1.Buffer.concat([
|
|
137
|
+
buffer_1.Buffer.from(js_sha256_1.sha256.digest("global:create_unchecked")).slice(0, 8),
|
|
138
|
+
bufferData,
|
|
139
|
+
buffer_1.Buffer.alloc(10),
|
|
140
|
+
]);
|
|
141
|
+
return new web3_js_1.TransactionInstruction({
|
|
142
|
+
keys: keys,
|
|
143
|
+
programId: programId,
|
|
144
|
+
data: bufferData,
|
|
145
|
+
});
|
|
146
|
+
};
|
|
147
|
+
exports.createUncheckedStreamInstruction = createUncheckedStreamInstruction;
|
|
97
148
|
var withdrawStreamInstruction = function (amount, programId, _a) {
|
|
98
149
|
var authority = _a.authority, recipient = _a.recipient, recipientTokens = _a.recipientTokens, metadata = _a.metadata, escrowTokens = _a.escrowTokens, streamflowTreasury = _a.streamflowTreasury, streamflowTreasuryTokens = _a.streamflowTreasuryTokens, partner = _a.partner, partnerTokens = _a.partnerTokens, mint = _a.mint, tokenProgram = _a.tokenProgram;
|
|
99
150
|
var keys = [
|
package/dist/layout.d.ts
CHANGED
|
@@ -7,6 +7,10 @@ export declare const streamLayout: typeof BufferLayout.Structure;
|
|
|
7
7
|
* Create stream instruction layout
|
|
8
8
|
*/
|
|
9
9
|
export declare const createStreamLayout: typeof BufferLayout.Structure;
|
|
10
|
+
/**
|
|
11
|
+
* Create unchecked stream instruction layout
|
|
12
|
+
*/
|
|
13
|
+
export declare const createUncheckedStreamLayout: typeof BufferLayout.Structure;
|
|
10
14
|
/**
|
|
11
15
|
* Withdraw stream instruction layout
|
|
12
16
|
*/
|
package/dist/layout.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.topupStreamLayout = exports.withdrawStreamLayout = exports.createStreamLayout = exports.streamLayout = void 0;
|
|
3
|
+
exports.topupStreamLayout = exports.withdrawStreamLayout = exports.createUncheckedStreamLayout = exports.createStreamLayout = exports.streamLayout = void 0;
|
|
4
4
|
var BufferLayout = require("buffer-layout");
|
|
5
5
|
/**
|
|
6
6
|
* Stream layout
|
|
@@ -63,6 +63,29 @@ exports.createStreamLayout = BufferLayout.struct([
|
|
|
63
63
|
BufferLayout.blob(64, "stream_name"),
|
|
64
64
|
BufferLayout.blob(8, "withdraw_frequency"),
|
|
65
65
|
]);
|
|
66
|
+
/**
|
|
67
|
+
* Create unchecked stream instruction layout
|
|
68
|
+
*/
|
|
69
|
+
exports.createUncheckedStreamLayout = BufferLayout.struct([
|
|
70
|
+
BufferLayout.blob(8, "start_time"),
|
|
71
|
+
BufferLayout.blob(8, "net_amount_deposited"),
|
|
72
|
+
BufferLayout.blob(8, "period"),
|
|
73
|
+
BufferLayout.blob(8, "amount_per_period"),
|
|
74
|
+
BufferLayout.blob(8, "cliff"),
|
|
75
|
+
BufferLayout.blob(8, "cliff_amount"),
|
|
76
|
+
BufferLayout.u8("cancelable_by_sender"),
|
|
77
|
+
BufferLayout.u8("cancelable_by_recipient"),
|
|
78
|
+
BufferLayout.u8("automatic_withdrawal"),
|
|
79
|
+
BufferLayout.u8("transferable_by_sender"),
|
|
80
|
+
BufferLayout.u8("transferable_by_recipient"),
|
|
81
|
+
BufferLayout.u8("can_topup"),
|
|
82
|
+
BufferLayout.blob(64, "stream_name"),
|
|
83
|
+
BufferLayout.blob(8, "withdraw_frequency"),
|
|
84
|
+
BufferLayout.blob(32, "recipient"),
|
|
85
|
+
BufferLayout.blob(32, "partner"),
|
|
86
|
+
BufferLayout.u8("pausable"),
|
|
87
|
+
BufferLayout.u8("can_update_rate"),
|
|
88
|
+
]);
|
|
66
89
|
/**
|
|
67
90
|
* Withdraw stream instruction layout
|
|
68
91
|
*/
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@streamflow/stream",
|
|
3
|
-
"version": "3.0.
|
|
3
|
+
"version": "3.0.11",
|
|
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/",
|
|
@@ -12,7 +12,11 @@
|
|
|
12
12
|
"gitHead": "a37306eba0e762af096db642fa22f07194014cfd",
|
|
13
13
|
"devDependencies": {
|
|
14
14
|
"@types/bn.js": "^5.1.0",
|
|
15
|
+
"@types/jest": "^28.1.4",
|
|
16
|
+
"@types/mocha": "^9.1.1",
|
|
15
17
|
"date-fns": "^2.28.0",
|
|
18
|
+
"jest": "^28.1.2",
|
|
19
|
+
"mocha": "^10.0.0",
|
|
16
20
|
"typescript": "^4.6.4"
|
|
17
21
|
},
|
|
18
22
|
"dependencies": {
|