@streamflow/stream 4.1.0-beta.0 → 4.1.0-beta.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/aptos/types.d.ts +2 -2
- package/dist/aptos/types.js +5 -6
- package/dist/common/types.d.ts +1 -0
- package/dist/evm/StreamClient.d.ts +1 -0
- package/dist/evm/StreamClient.js +87 -44
- package/dist/evm/abi.js +981 -166
- package/dist/evm/types.d.ts +6 -2
- package/dist/evm/types.js +5 -6
- package/dist/solana/StreamClient.d.ts +3 -3
- package/dist/solana/StreamClient.js +71 -72
- package/dist/solana/types.d.ts +2 -2
- package/dist/solana/types.js +5 -6
- package/dist/solana/utils.js +1 -1
- package/package.json +3 -1
package/dist/evm/types.d.ts
CHANGED
|
@@ -13,6 +13,9 @@ export interface StreamAbiResult {
|
|
|
13
13
|
streamflow_fee_percentage: BigNumber;
|
|
14
14
|
streamflow_fee: BigNumber;
|
|
15
15
|
streamflow_fee_withdrawn: BigNumber;
|
|
16
|
+
partner_fee_percentage: BigNumber;
|
|
17
|
+
partner_fee: BigNumber;
|
|
18
|
+
partner_fee_withdrawn: BigNumber;
|
|
16
19
|
tx_fee: BigNumber;
|
|
17
20
|
};
|
|
18
21
|
funds_unlocked_at_last_rate_change: BigNumber;
|
|
@@ -34,6 +37,7 @@ export interface StreamAbiResult {
|
|
|
34
37
|
period: BigNumber;
|
|
35
38
|
recipient: string;
|
|
36
39
|
sender: string;
|
|
40
|
+
partner: string;
|
|
37
41
|
start: BigNumber;
|
|
38
42
|
token: string;
|
|
39
43
|
withdrawn: BigNumber;
|
|
@@ -76,7 +80,7 @@ export interface Stream {
|
|
|
76
80
|
canTopup: boolean;
|
|
77
81
|
name: string;
|
|
78
82
|
withdrawalFrequency: number;
|
|
79
|
-
unlocked(currentTimestamp: number, decimals: number):
|
|
83
|
+
unlocked(currentTimestamp: number, decimals: number): BN;
|
|
80
84
|
}
|
|
81
85
|
export declare class EvmContract implements Stream {
|
|
82
86
|
magic: number;
|
|
@@ -117,6 +121,6 @@ export declare class EvmContract implements Stream {
|
|
|
117
121
|
name: string;
|
|
118
122
|
withdrawalFrequency: number;
|
|
119
123
|
constructor(stream: StreamAbiResult);
|
|
120
|
-
unlocked(currentTimestamp: number
|
|
124
|
+
unlocked(currentTimestamp: number): BN;
|
|
121
125
|
remaining(decimals: number): number;
|
|
122
126
|
}
|
package/dist/evm/types.js
CHANGED
|
@@ -46,15 +46,14 @@ var EvmContract = /** @class */ (function () {
|
|
|
46
46
|
this.name = stream.meta.contract_name;
|
|
47
47
|
this.withdrawalFrequency = stream.meta.withdrawal_frequency.toNumber();
|
|
48
48
|
}
|
|
49
|
-
EvmContract.prototype.unlocked = function (currentTimestamp
|
|
50
|
-
var deposited =
|
|
49
|
+
EvmContract.prototype.unlocked = function (currentTimestamp) {
|
|
50
|
+
var deposited = this.depositedAmount;
|
|
51
51
|
if (currentTimestamp < this.cliff)
|
|
52
|
-
return 0;
|
|
52
|
+
return new bn_js_1.default(0);
|
|
53
53
|
if (currentTimestamp > this.end)
|
|
54
54
|
return deposited;
|
|
55
|
-
var
|
|
56
|
-
|
|
57
|
-
return streamed < deposited ? streamed : deposited;
|
|
55
|
+
var streamed = this.cliffAmount.add(new bn_js_1.default(Math.floor((currentTimestamp - this.cliff) / this.period)).mul(this.amountPerPeriod));
|
|
56
|
+
return streamed.lt(deposited) ? streamed : deposited;
|
|
58
57
|
};
|
|
59
58
|
EvmContract.prototype.remaining = function (decimals) {
|
|
60
59
|
return (0, utils_1.getNumberFromBN)(this.depositedAmount.sub(this.withdrawnAmount), decimals);
|
|
@@ -16,7 +16,7 @@ export default class SolanaStreamClient extends BaseStreamClient {
|
|
|
16
16
|
* Creates a new stream/vesting contract.
|
|
17
17
|
* All fees are paid by sender (escrow metadata account rent, escrow token account rent, recipient's associated token account rent, Streamflow's service fee).
|
|
18
18
|
*/
|
|
19
|
-
create({ recipient, tokenId: mint, start, amount: depositedAmount, period, cliff, cliffAmount, amountPerPeriod, name, canTopup, cancelableBySender, cancelableByRecipient, transferableBySender, transferableByRecipient, automaticWithdrawal, withdrawalFrequency, }: ICreateStreamData, { sender,
|
|
19
|
+
create({ recipient, tokenId: mint, start, amount: depositedAmount, period, cliff, cliffAmount, amountPerPeriod, name, canTopup, cancelableBySender, cancelableByRecipient, transferableBySender, transferableByRecipient, automaticWithdrawal, withdrawalFrequency, partner, }: ICreateStreamData, { sender, isNative }: ICreateStreamSolanaExt): Promise<ICreateResult>;
|
|
20
20
|
/**
|
|
21
21
|
* Creates a new stream/vesting contract using unchecked instruction.
|
|
22
22
|
*
|
|
@@ -27,12 +27,12 @@ export default class SolanaStreamClient extends BaseStreamClient {
|
|
|
27
27
|
*
|
|
28
28
|
* If you are not sure if you should use create or create_unchecked, go for create to be safer.
|
|
29
29
|
*/
|
|
30
|
-
createUnchecked({ recipient, tokenId: mint, start, amount: depositedAmount, period, cliff, cliffAmount, amountPerPeriod, name, canTopup, cancelableBySender, cancelableByRecipient, transferableBySender, transferableByRecipient, automaticWithdrawal, withdrawalFrequency, }: ICreateStreamData, { sender,
|
|
30
|
+
createUnchecked({ recipient, tokenId: mint, start, amount: depositedAmount, period, cliff, cliffAmount, amountPerPeriod, name, canTopup, cancelableBySender, cancelableByRecipient, transferableBySender, transferableByRecipient, automaticWithdrawal, withdrawalFrequency, partner, }: ICreateStreamData, { sender, isNative }: ICreateStreamSolanaExt): Promise<ICreateResult>;
|
|
31
31
|
/**
|
|
32
32
|
* Creates multiple stream/vesting contracts.
|
|
33
33
|
* All fees are paid by sender (escrow metadata account rent, escrow token account rent, recipient's associated token account rent, Streamflow's service fee).
|
|
34
34
|
*/
|
|
35
|
-
createMultiple(data: ICreateMultipleStreamData, { sender,
|
|
35
|
+
createMultiple(data: ICreateMultipleStreamData, { sender, isNative }: ICreateStreamSolanaExt): Promise<IMultiTransactionResult>;
|
|
36
36
|
/**
|
|
37
37
|
* Attempts withdrawing from the specified stream.
|
|
38
38
|
*/
|
|
@@ -141,13 +141,13 @@ var SolanaStreamClient = /** @class */ (function (_super) {
|
|
|
141
141
|
* All fees are paid by sender (escrow metadata account rent, escrow token account rent, recipient's associated token account rent, Streamflow's service fee).
|
|
142
142
|
*/
|
|
143
143
|
SolanaStreamClient.prototype.create = function (_a, _b) {
|
|
144
|
-
var recipient = _a.recipient, mint = _a.tokenId, start = _a.start, depositedAmount = _a.amount, 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, _c = _a.automaticWithdrawal, automaticWithdrawal = _c === void 0 ? false : _c, _d = _a.withdrawalFrequency, withdrawalFrequency = _d === void 0 ? 0 : _d;
|
|
145
|
-
var sender = _b.sender, _e = _b.
|
|
144
|
+
var recipient = _a.recipient, mint = _a.tokenId, start = _a.start, depositedAmount = _a.amount, 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, _c = _a.automaticWithdrawal, automaticWithdrawal = _c === void 0 ? false : _c, _d = _a.withdrawalFrequency, withdrawalFrequency = _d === void 0 ? 0 : _d, partner = _a.partner;
|
|
145
|
+
var sender = _b.sender, _e = _b.isNative, isNative = _e === void 0 ? false : _e;
|
|
146
146
|
return __awaiter(this, void 0, void 0, function () {
|
|
147
|
-
var ixs, mintPublicKey, recipientPublicKey, metadata,
|
|
148
|
-
var
|
|
149
|
-
return __generator(this, function (
|
|
150
|
-
switch (
|
|
147
|
+
var ixs, mintPublicKey, recipientPublicKey, metadata, _f, escrowTokens, senderTokens, recipientTokens, streamflowTreasuryTokens, partnerPublicKey, partnerTokens, nativeInstructions, _g, commitment, hash, tx, signature;
|
|
148
|
+
var _h;
|
|
149
|
+
return __generator(this, function (_j) {
|
|
150
|
+
switch (_j.label) {
|
|
151
151
|
case 0:
|
|
152
152
|
if (!sender.publicKey) {
|
|
153
153
|
throw new Error("Sender's PublicKey is not available, check passed wallet adapter!");
|
|
@@ -158,30 +158,30 @@ var SolanaStreamClient = /** @class */ (function (_super) {
|
|
|
158
158
|
metadata = web3_js_1.Keypair.generate();
|
|
159
159
|
return [4 /*yield*/, web3_js_1.PublicKey.findProgramAddress([buffer_1.Buffer.from("strm"), metadata.publicKey.toBuffer()], this.programId)];
|
|
160
160
|
case 1:
|
|
161
|
-
|
|
161
|
+
_f = __read.apply(void 0, [_j.sent(), 1]), escrowTokens = _f[0];
|
|
162
162
|
return [4 /*yield*/, (0, utils_1.ata)(mintPublicKey, sender.publicKey)];
|
|
163
163
|
case 2:
|
|
164
|
-
senderTokens =
|
|
164
|
+
senderTokens = _j.sent();
|
|
165
165
|
return [4 /*yield*/, (0, utils_1.ata)(mintPublicKey, recipientPublicKey)];
|
|
166
166
|
case 3:
|
|
167
|
-
recipientTokens =
|
|
167
|
+
recipientTokens = _j.sent();
|
|
168
168
|
return [4 /*yield*/, (0, utils_1.ata)(mintPublicKey, constants_1.STREAMFLOW_TREASURY_PUBLIC_KEY)];
|
|
169
169
|
case 4:
|
|
170
|
-
streamflowTreasuryTokens =
|
|
170
|
+
streamflowTreasuryTokens = _j.sent();
|
|
171
171
|
partnerPublicKey = partner ? new web3_js_1.PublicKey(partner) : constants_1.STREAMFLOW_TREASURY_PUBLIC_KEY;
|
|
172
172
|
return [4 /*yield*/, (0, utils_1.ata)(mintPublicKey, partnerPublicKey)];
|
|
173
173
|
case 5:
|
|
174
|
-
partnerTokens =
|
|
174
|
+
partnerTokens = _j.sent();
|
|
175
175
|
if (!isNative) return [3 /*break*/, 7];
|
|
176
176
|
return [4 /*yield*/, (0, instructions_1.prepareWrappedAccount)(this.connection, sender.publicKey, depositedAmount)];
|
|
177
177
|
case 6:
|
|
178
|
-
|
|
178
|
+
_g = _j.sent();
|
|
179
179
|
return [3 /*break*/, 8];
|
|
180
180
|
case 7:
|
|
181
|
-
|
|
182
|
-
|
|
181
|
+
_g = [];
|
|
182
|
+
_j.label = 8;
|
|
183
183
|
case 8:
|
|
184
|
-
nativeInstructions =
|
|
184
|
+
nativeInstructions = _g;
|
|
185
185
|
ixs.push((0, instructions_1.createStreamInstruction)({
|
|
186
186
|
start: new bn_js_1.default(start),
|
|
187
187
|
depositedAmount: depositedAmount,
|
|
@@ -220,16 +220,16 @@ var SolanaStreamClient = /** @class */ (function (_super) {
|
|
|
220
220
|
commitment = typeof this.commitment == "string" ? this.commitment : this.commitment.commitment;
|
|
221
221
|
return [4 /*yield*/, this.connection.getLatestBlockhash(commitment)];
|
|
222
222
|
case 9:
|
|
223
|
-
hash =
|
|
224
|
-
tx = (
|
|
223
|
+
hash = _j.sent();
|
|
224
|
+
tx = (_h = new web3_js_1.Transaction({
|
|
225
225
|
feePayer: sender.publicKey,
|
|
226
226
|
blockhash: hash.blockhash,
|
|
227
227
|
lastValidBlockHeight: hash.lastValidBlockHeight,
|
|
228
|
-
})).add.apply(
|
|
228
|
+
})).add.apply(_h, __spreadArray(__spreadArray([], __read(nativeInstructions), false), __read(ixs), false));
|
|
229
229
|
tx.partialSign(metadata);
|
|
230
230
|
return [4 /*yield*/, this.sign(sender, tx, hash)];
|
|
231
231
|
case 10:
|
|
232
|
-
signature =
|
|
232
|
+
signature = _j.sent();
|
|
233
233
|
return [2 /*return*/, { ixs: ixs, txId: signature, metadataId: metadata.publicKey.toBase58() }];
|
|
234
234
|
}
|
|
235
235
|
});
|
|
@@ -246,13 +246,13 @@ var SolanaStreamClient = /** @class */ (function (_super) {
|
|
|
246
246
|
* If you are not sure if you should use create or create_unchecked, go for create to be safer.
|
|
247
247
|
*/
|
|
248
248
|
SolanaStreamClient.prototype.createUnchecked = function (_a, _b) {
|
|
249
|
-
var recipient = _a.recipient, mint = _a.tokenId, start = _a.start, depositedAmount = _a.amount, 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, _c = _a.automaticWithdrawal, automaticWithdrawal = _c === void 0 ? false : _c, _d = _a.withdrawalFrequency, withdrawalFrequency = _d === void 0 ? 0 : _d;
|
|
250
|
-
var sender = _b.sender, _e = _b.
|
|
249
|
+
var recipient = _a.recipient, mint = _a.tokenId, start = _a.start, depositedAmount = _a.amount, 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, _c = _a.automaticWithdrawal, automaticWithdrawal = _c === void 0 ? false : _c, _d = _a.withdrawalFrequency, withdrawalFrequency = _d === void 0 ? 0 : _d, partner = _a.partner;
|
|
250
|
+
var sender = _b.sender, _e = _b.isNative, isNative = _e === void 0 ? false : _e;
|
|
251
251
|
return __awaiter(this, void 0, void 0, function () {
|
|
252
|
-
var mintPublicKey, recipientPublicKey, metadata, rentToExempt, createMetadataInstruction,
|
|
253
|
-
var
|
|
254
|
-
return __generator(this, function (
|
|
255
|
-
switch (
|
|
252
|
+
var mintPublicKey, recipientPublicKey, metadata, rentToExempt, createMetadataInstruction, _f, escrowTokens, senderTokens, partnerPublicKey, nativeInstructions, _g, createInstruction, commitment, ixs, hash, tx, signature;
|
|
253
|
+
var _h;
|
|
254
|
+
return __generator(this, function (_j) {
|
|
255
|
+
switch (_j.label) {
|
|
256
256
|
case 0:
|
|
257
257
|
if (!sender.publicKey) {
|
|
258
258
|
throw new Error("Sender's PublicKey is not available, check passed wallet adapter!");
|
|
@@ -262,7 +262,7 @@ var SolanaStreamClient = /** @class */ (function (_super) {
|
|
|
262
262
|
metadata = web3_js_1.Keypair.generate();
|
|
263
263
|
return [4 /*yield*/, this.connection.getMinimumBalanceForRentExemption(METADATA_ACC_SIZE)];
|
|
264
264
|
case 1:
|
|
265
|
-
rentToExempt =
|
|
265
|
+
rentToExempt = _j.sent();
|
|
266
266
|
createMetadataInstruction = web3_js_1.SystemProgram.createAccount({
|
|
267
267
|
programId: this.programId,
|
|
268
268
|
space: METADATA_ACC_SIZE,
|
|
@@ -272,21 +272,21 @@ var SolanaStreamClient = /** @class */ (function (_super) {
|
|
|
272
272
|
});
|
|
273
273
|
return [4 /*yield*/, web3_js_1.PublicKey.findProgramAddress([buffer_1.Buffer.from("strm"), metadata.publicKey.toBuffer()], this.programId)];
|
|
274
274
|
case 2:
|
|
275
|
-
|
|
275
|
+
_f = __read.apply(void 0, [_j.sent(), 1]), escrowTokens = _f[0];
|
|
276
276
|
return [4 /*yield*/, (0, utils_1.ata)(mintPublicKey, sender.publicKey)];
|
|
277
277
|
case 3:
|
|
278
|
-
senderTokens =
|
|
278
|
+
senderTokens = _j.sent();
|
|
279
279
|
partnerPublicKey = partner ? new web3_js_1.PublicKey(partner) : constants_1.STREAMFLOW_TREASURY_PUBLIC_KEY;
|
|
280
280
|
if (!isNative) return [3 /*break*/, 5];
|
|
281
281
|
return [4 /*yield*/, (0, instructions_1.prepareWrappedAccount)(this.connection, sender.publicKey, depositedAmount)];
|
|
282
282
|
case 4:
|
|
283
|
-
|
|
283
|
+
_g = _j.sent();
|
|
284
284
|
return [3 /*break*/, 6];
|
|
285
285
|
case 5:
|
|
286
|
-
|
|
287
|
-
|
|
286
|
+
_g = [];
|
|
287
|
+
_j.label = 6;
|
|
288
288
|
case 6:
|
|
289
|
-
nativeInstructions =
|
|
289
|
+
nativeInstructions = _g;
|
|
290
290
|
createInstruction = (0, instructions_1.createUncheckedStreamInstruction)({
|
|
291
291
|
start: new bn_js_1.default(start),
|
|
292
292
|
depositedAmount: depositedAmount,
|
|
@@ -321,16 +321,16 @@ var SolanaStreamClient = /** @class */ (function (_super) {
|
|
|
321
321
|
ixs = [createMetadataInstruction, createInstruction];
|
|
322
322
|
return [4 /*yield*/, this.connection.getLatestBlockhash(commitment)];
|
|
323
323
|
case 7:
|
|
324
|
-
hash =
|
|
325
|
-
tx = (
|
|
324
|
+
hash = _j.sent();
|
|
325
|
+
tx = (_h = new web3_js_1.Transaction({
|
|
326
326
|
feePayer: sender.publicKey,
|
|
327
327
|
blockhash: hash.blockhash,
|
|
328
328
|
lastValidBlockHeight: hash.lastValidBlockHeight,
|
|
329
|
-
})).add.apply(
|
|
329
|
+
})).add.apply(_h, __spreadArray(__spreadArray([], __read(nativeInstructions), false), __read(ixs), false));
|
|
330
330
|
tx.partialSign(metadata);
|
|
331
331
|
return [4 /*yield*/, this.sign(sender, tx, hash)];
|
|
332
332
|
case 8:
|
|
333
|
-
signature =
|
|
333
|
+
signature = _j.sent();
|
|
334
334
|
return [2 /*return*/, { ixs: ixs, txId: signature, metadataId: metadata.publicKey.toBase58() }];
|
|
335
335
|
}
|
|
336
336
|
});
|
|
@@ -341,13 +341,13 @@ var SolanaStreamClient = /** @class */ (function (_super) {
|
|
|
341
341
|
* All fees are paid by sender (escrow metadata account rent, escrow token account rent, recipient's associated token account rent, Streamflow's service fee).
|
|
342
342
|
*/
|
|
343
343
|
SolanaStreamClient.prototype.createMultiple = function (data, _a) {
|
|
344
|
-
var sender = _a.sender, _b = _a.
|
|
344
|
+
var sender = _a.sender, _b = _a.isNative, isNative = _b === void 0 ? false : _b;
|
|
345
345
|
return __awaiter(this, void 0, void 0, function () {
|
|
346
|
-
var recipients, metadatas, metadataToRecipient, errors, signatures, batch, recipients_1, recipients_1_1, recipientData,
|
|
347
|
-
var e_1,
|
|
346
|
+
var recipients, metadatas, metadataToRecipient, errors, signatures, batch, recipients_1, recipients_1_1, recipientData, _c, tx, metadata, metadataPubKey, e_1_1, totalDepositedAmount, nativeInstructions, commitment, hash, prepareTransaction, signedBatch, prepareTx, batchTransactionsCalls, responses, successes, failures, metadataIds;
|
|
347
|
+
var e_1, _d, _e;
|
|
348
348
|
var _this = this;
|
|
349
|
-
return __generator(this, function (
|
|
350
|
-
switch (
|
|
349
|
+
return __generator(this, function (_f) {
|
|
350
|
+
switch (_f.label) {
|
|
351
351
|
case 0:
|
|
352
352
|
recipients = data.recipients;
|
|
353
353
|
if (!sender.publicKey) {
|
|
@@ -358,36 +358,35 @@ var SolanaStreamClient = /** @class */ (function (_super) {
|
|
|
358
358
|
errors = [];
|
|
359
359
|
signatures = [];
|
|
360
360
|
batch = [];
|
|
361
|
-
|
|
361
|
+
_f.label = 1;
|
|
362
362
|
case 1:
|
|
363
|
-
|
|
363
|
+
_f.trys.push([1, 6, 7, 8]);
|
|
364
364
|
recipients_1 = __values(recipients), recipients_1_1 = recipients_1.next();
|
|
365
|
-
|
|
365
|
+
_f.label = 2;
|
|
366
366
|
case 2:
|
|
367
367
|
if (!!recipients_1_1.done) return [3 /*break*/, 5];
|
|
368
368
|
recipientData = recipients_1_1.value;
|
|
369
369
|
return [4 /*yield*/, this.prepareStreamTransaction(recipientData, data, {
|
|
370
370
|
sender: sender,
|
|
371
|
-
partner: partner,
|
|
372
371
|
})];
|
|
373
372
|
case 3:
|
|
374
|
-
|
|
373
|
+
_c = _f.sent(), tx = _c.tx, metadata = _c.metadata;
|
|
375
374
|
metadataPubKey = metadata.publicKey.toBase58();
|
|
376
375
|
metadataToRecipient[metadataPubKey] = recipientData;
|
|
377
376
|
metadatas.push(metadata);
|
|
378
377
|
batch.push({ tx: tx, recipient: recipientData.recipient });
|
|
379
|
-
|
|
378
|
+
_f.label = 4;
|
|
380
379
|
case 4:
|
|
381
380
|
recipients_1_1 = recipients_1.next();
|
|
382
381
|
return [3 /*break*/, 2];
|
|
383
382
|
case 5: return [3 /*break*/, 8];
|
|
384
383
|
case 6:
|
|
385
|
-
e_1_1 =
|
|
384
|
+
e_1_1 = _f.sent();
|
|
386
385
|
e_1 = { error: e_1_1 };
|
|
387
386
|
return [3 /*break*/, 8];
|
|
388
387
|
case 7:
|
|
389
388
|
try {
|
|
390
|
-
if (recipients_1_1 && !recipients_1_1.done && (
|
|
389
|
+
if (recipients_1_1 && !recipients_1_1.done && (_d = recipients_1.return)) _d.call(recipients_1);
|
|
391
390
|
}
|
|
392
391
|
finally { if (e_1) throw e_1.error; }
|
|
393
392
|
return [7 /*endfinally*/];
|
|
@@ -396,21 +395,21 @@ var SolanaStreamClient = /** @class */ (function (_super) {
|
|
|
396
395
|
totalDepositedAmount = recipients.reduce(function (acc, recipient) { return recipient.amount.add(acc); }, new bn_js_1.default(0));
|
|
397
396
|
return [4 /*yield*/, (0, instructions_1.prepareWrappedAccount)(this.connection, sender.publicKey, totalDepositedAmount)];
|
|
398
397
|
case 9:
|
|
399
|
-
nativeInstructions =
|
|
398
|
+
nativeInstructions = _f.sent();
|
|
400
399
|
commitment = typeof this.commitment == "string" ? this.commitment : this.commitment.commitment;
|
|
401
400
|
return [4 /*yield*/, this.connection.getLatestBlockhash(commitment)];
|
|
402
401
|
case 10:
|
|
403
|
-
hash =
|
|
404
|
-
prepareTransaction = (
|
|
402
|
+
hash = _f.sent();
|
|
403
|
+
prepareTransaction = (_e = new web3_js_1.Transaction({
|
|
405
404
|
feePayer: sender.publicKey,
|
|
406
405
|
blockhash: hash.blockhash,
|
|
407
406
|
lastValidBlockHeight: hash.lastValidBlockHeight,
|
|
408
|
-
})).add.apply(
|
|
407
|
+
})).add.apply(_e, __spreadArray([], __read(nativeInstructions), false));
|
|
409
408
|
batch.push({ tx: prepareTransaction, recipient: sender.publicKey.toBase58() });
|
|
410
|
-
|
|
409
|
+
_f.label = 11;
|
|
411
410
|
case 11: return [4 /*yield*/, (0, utils_1.signAllTransactionWithRecipients)(sender, batch)];
|
|
412
411
|
case 12:
|
|
413
|
-
signedBatch =
|
|
412
|
+
signedBatch = _f.sent();
|
|
414
413
|
signedBatch.forEach(function (item, index) {
|
|
415
414
|
item.tx.lastValidBlockHeight = batch[index].tx.lastValidBlockHeight;
|
|
416
415
|
});
|
|
@@ -418,15 +417,15 @@ var SolanaStreamClient = /** @class */ (function (_super) {
|
|
|
418
417
|
prepareTx = signedBatch.pop();
|
|
419
418
|
return [4 /*yield*/, (0, utils_1.sendAndConfirmStreamRawTransaction)(this.connection, prepareTx)];
|
|
420
419
|
case 13:
|
|
421
|
-
|
|
422
|
-
|
|
420
|
+
_f.sent();
|
|
421
|
+
_f.label = 14;
|
|
423
422
|
case 14:
|
|
424
423
|
batchTransactionsCalls = signedBatch.map(function (el) {
|
|
425
424
|
return (0, utils_1.sendAndConfirmStreamRawTransaction)(_this.connection, el);
|
|
426
425
|
});
|
|
427
426
|
return [4 /*yield*/, Promise.allSettled(batchTransactionsCalls)];
|
|
428
427
|
case 15:
|
|
429
|
-
responses =
|
|
428
|
+
responses = _f.sent();
|
|
430
429
|
successes = responses
|
|
431
430
|
.filter(function (el) { return el.status === "fulfilled"; })
|
|
432
431
|
.map(function (el) { return el.value; });
|
|
@@ -843,13 +842,13 @@ var SolanaStreamClient = /** @class */ (function (_super) {
|
|
|
843
842
|
*/
|
|
844
843
|
SolanaStreamClient.prototype.prepareStreamTransaction = function (recipient, streamParams, solanaExtendedConfig) {
|
|
845
844
|
return __awaiter(this, void 0, void 0, function () {
|
|
846
|
-
var mint, start, period, cliff, canTopup, cancelableBySender, cancelableByRecipient, transferableBySender, transferableByRecipient, _a, automaticWithdrawal, _b, withdrawalFrequency,
|
|
847
|
-
var
|
|
848
|
-
return __generator(this, function (
|
|
849
|
-
switch (
|
|
845
|
+
var mint, start, period, cliff, canTopup, cancelableBySender, cancelableByRecipient, transferableBySender, transferableByRecipient, _a, automaticWithdrawal, _b, withdrawalFrequency, partner, sender, ixs, commitment, recipientPublicKey, mintPublicKey, metadata, _c, escrowTokens, senderTokens, recipientTokens, streamflowTreasuryTokens, partnerPublicKey, partnerTokens, hash, tx;
|
|
846
|
+
var _d;
|
|
847
|
+
return __generator(this, function (_e) {
|
|
848
|
+
switch (_e.label) {
|
|
850
849
|
case 0:
|
|
851
|
-
mint = streamParams.tokenId, start = streamParams.start, period = streamParams.period, cliff = streamParams.cliff, canTopup = streamParams.canTopup, cancelableBySender = streamParams.cancelableBySender, cancelableByRecipient = streamParams.cancelableByRecipient, transferableBySender = streamParams.transferableBySender, transferableByRecipient = streamParams.transferableByRecipient, _a = streamParams.automaticWithdrawal, automaticWithdrawal = _a === void 0 ? false : _a, _b = streamParams.withdrawalFrequency, withdrawalFrequency = _b === void 0 ? 0 : _b;
|
|
852
|
-
sender = solanaExtendedConfig.sender
|
|
850
|
+
mint = streamParams.tokenId, start = streamParams.start, period = streamParams.period, cliff = streamParams.cliff, canTopup = streamParams.canTopup, cancelableBySender = streamParams.cancelableBySender, cancelableByRecipient = streamParams.cancelableByRecipient, transferableBySender = streamParams.transferableBySender, transferableByRecipient = streamParams.transferableByRecipient, _a = streamParams.automaticWithdrawal, automaticWithdrawal = _a === void 0 ? false : _a, _b = streamParams.withdrawalFrequency, withdrawalFrequency = _b === void 0 ? 0 : _b, partner = streamParams.partner;
|
|
851
|
+
sender = solanaExtendedConfig.sender;
|
|
853
852
|
if (!sender.publicKey) {
|
|
854
853
|
throw new Error("Sender's PublicKey is not available, check passed wallet adapter!");
|
|
855
854
|
}
|
|
@@ -858,20 +857,20 @@ var SolanaStreamClient = /** @class */ (function (_super) {
|
|
|
858
857
|
recipientPublicKey = new web3_js_1.PublicKey(recipient.recipient);
|
|
859
858
|
mintPublicKey = new web3_js_1.PublicKey(mint);
|
|
860
859
|
metadata = web3_js_1.Keypair.generate();
|
|
861
|
-
|
|
860
|
+
_c = __read(web3_js_1.PublicKey.findProgramAddressSync([buffer_1.Buffer.from("strm"), metadata.publicKey.toBuffer()], this.programId), 1), escrowTokens = _c[0];
|
|
862
861
|
return [4 /*yield*/, (0, utils_1.ata)(mintPublicKey, sender.publicKey)];
|
|
863
862
|
case 1:
|
|
864
|
-
senderTokens =
|
|
863
|
+
senderTokens = _e.sent();
|
|
865
864
|
return [4 /*yield*/, (0, utils_1.ata)(mintPublicKey, recipientPublicKey)];
|
|
866
865
|
case 2:
|
|
867
|
-
recipientTokens =
|
|
866
|
+
recipientTokens = _e.sent();
|
|
868
867
|
return [4 /*yield*/, (0, utils_1.ata)(mintPublicKey, constants_1.STREAMFLOW_TREASURY_PUBLIC_KEY)];
|
|
869
868
|
case 3:
|
|
870
|
-
streamflowTreasuryTokens =
|
|
869
|
+
streamflowTreasuryTokens = _e.sent();
|
|
871
870
|
partnerPublicKey = partner ? new web3_js_1.PublicKey(partner) : constants_1.STREAMFLOW_TREASURY_PUBLIC_KEY;
|
|
872
871
|
return [4 /*yield*/, (0, utils_1.ata)(mintPublicKey, partnerPublicKey)];
|
|
873
872
|
case 4:
|
|
874
|
-
partnerTokens =
|
|
873
|
+
partnerTokens = _e.sent();
|
|
875
874
|
ixs.push((0, instructions_1.createStreamInstruction)({
|
|
876
875
|
start: new bn_js_1.default(start),
|
|
877
876
|
depositedAmount: recipient.amount,
|
|
@@ -909,12 +908,12 @@ var SolanaStreamClient = /** @class */ (function (_super) {
|
|
|
909
908
|
}));
|
|
910
909
|
return [4 /*yield*/, this.connection.getLatestBlockhash(commitment)];
|
|
911
910
|
case 5:
|
|
912
|
-
hash =
|
|
913
|
-
tx = (
|
|
911
|
+
hash = _e.sent();
|
|
912
|
+
tx = (_d = new web3_js_1.Transaction({
|
|
914
913
|
feePayer: sender.publicKey,
|
|
915
914
|
blockhash: hash.blockhash,
|
|
916
915
|
lastValidBlockHeight: hash.lastValidBlockHeight,
|
|
917
|
-
})).add.apply(
|
|
916
|
+
})).add.apply(_d, __spreadArray([], __read(ixs), false));
|
|
918
917
|
tx.partialSign(metadata);
|
|
919
918
|
return [2 /*return*/, { tx: tx, metadata: metadata }];
|
|
920
919
|
}
|
package/dist/solana/types.d.ts
CHANGED
|
@@ -171,7 +171,7 @@ export interface Stream {
|
|
|
171
171
|
canTopup: boolean;
|
|
172
172
|
name: string;
|
|
173
173
|
withdrawalFrequency: number;
|
|
174
|
-
unlocked(currentTimestamp: number
|
|
174
|
+
unlocked(currentTimestamp: number): BN;
|
|
175
175
|
}
|
|
176
176
|
export declare class Contract implements Stream {
|
|
177
177
|
magic: number;
|
|
@@ -212,7 +212,7 @@ export declare class Contract implements Stream {
|
|
|
212
212
|
name: string;
|
|
213
213
|
withdrawalFrequency: number;
|
|
214
214
|
constructor(stream: DecodedStream);
|
|
215
|
-
unlocked(currentTimestamp: number
|
|
215
|
+
unlocked(currentTimestamp: number): BN;
|
|
216
216
|
remaining(decimals: number): number;
|
|
217
217
|
}
|
|
218
218
|
export interface DecodedStream {
|
package/dist/solana/types.js
CHANGED
|
@@ -49,15 +49,14 @@ var Contract = /** @class */ (function () {
|
|
|
49
49
|
this.name = stream.name;
|
|
50
50
|
this.withdrawalFrequency = stream.withdrawFrequency.toNumber();
|
|
51
51
|
}
|
|
52
|
-
Contract.prototype.unlocked = function (currentTimestamp
|
|
53
|
-
var deposited =
|
|
52
|
+
Contract.prototype.unlocked = function (currentTimestamp) {
|
|
53
|
+
var deposited = this.depositedAmount;
|
|
54
54
|
if (currentTimestamp < this.cliff)
|
|
55
|
-
return 0;
|
|
55
|
+
return new bn_js_1.default(0);
|
|
56
56
|
if (currentTimestamp > this.end)
|
|
57
57
|
return deposited;
|
|
58
|
-
var
|
|
59
|
-
|
|
60
|
-
return streamed < deposited ? streamed : deposited;
|
|
58
|
+
var streamed = this.cliffAmount.add(new bn_js_1.default(Math.floor((currentTimestamp - this.cliff) / this.period)).mul(this.amountPerPeriod));
|
|
59
|
+
return streamed.lt(deposited) ? streamed : deposited;
|
|
61
60
|
};
|
|
62
61
|
Contract.prototype.remaining = function (decimals) {
|
|
63
62
|
return (0, utils_1.getNumberFromBN)(this.depositedAmount.sub(this.withdrawnAmount), decimals);
|
package/dist/solana/utils.js
CHANGED
|
@@ -144,7 +144,7 @@ var formatDecodedStream = function (stream) {
|
|
|
144
144
|
name: stream.name,
|
|
145
145
|
withdrawalFrequency: stream.withdrawFrequency.toNumber(),
|
|
146
146
|
unlocked: function () {
|
|
147
|
-
return 0;
|
|
147
|
+
return new bn_js_1.default(0);
|
|
148
148
|
},
|
|
149
149
|
withdrawn: function () {
|
|
150
150
|
return new bn_js_1.default(0);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@streamflow/stream",
|
|
3
|
-
"version": "4.1.0-beta.
|
|
3
|
+
"version": "4.1.0-beta.1",
|
|
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/",
|
|
@@ -14,6 +14,7 @@
|
|
|
14
14
|
"gitHead": "a37306eba0e762af096db642fa22f07194014cfd",
|
|
15
15
|
"devDependencies": {
|
|
16
16
|
"@types/bn.js": "5.1.1",
|
|
17
|
+
"@types/ethereum-checksum-address": "^0.0.0",
|
|
17
18
|
"@types/jest": "29.2.4",
|
|
18
19
|
"date-fns": "2.28.0",
|
|
19
20
|
"eslint": "8.29.0",
|
|
@@ -35,6 +36,7 @@
|
|
|
35
36
|
"aptos": "1.4.0",
|
|
36
37
|
"bn.js": "5.2.1",
|
|
37
38
|
"bs58": "5.0.0",
|
|
39
|
+
"ethereum-checksum-address": "0.0.8",
|
|
38
40
|
"ethers": "5.7.2",
|
|
39
41
|
"js-sha256": "0.9.0"
|
|
40
42
|
}
|