@streamflow/stream 6.0.0-alpha.0 → 6.0.0-alpha.10
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/StreamClient.d.ts +1 -1
- package/dist/aptos/StreamClient.js +8 -6
- package/dist/common/GenericStreamClient.d.ts +1 -1
- package/dist/common/GenericStreamClient.js +4 -2
- package/dist/common/constants.d.ts +2 -0
- package/dist/common/constants.js +6 -1
- package/dist/common/types.d.ts +9 -14
- package/dist/evm/StreamClient.d.ts +1 -1
- package/dist/evm/StreamClient.js +6 -5
- package/dist/solana/StreamClient.d.ts +52 -13
- package/dist/solana/StreamClient.js +297 -202
- package/dist/solana/constants.d.ts +0 -2
- package/dist/solana/constants.js +1 -3
- package/dist/solana/types.d.ts +6 -164
- package/dist/solana/types.js +1 -10
- package/dist/sui/StreamClient.d.ts +1 -1
- package/dist/sui/StreamClient.js +9 -7
- package/package.json +4 -4
|
@@ -138,6 +138,7 @@ var instructions_1 = require("./instructions");
|
|
|
138
138
|
var types_2 = require("../common/types");
|
|
139
139
|
var BaseStreamClient_1 = require("../common/BaseStreamClient");
|
|
140
140
|
var utils_2 = require("../common/utils");
|
|
141
|
+
var constants_2 = require("../common/constants");
|
|
141
142
|
var METADATA_ACC_SIZE = 1104;
|
|
142
143
|
var SolanaStreamClient = /** @class */ (function (_super) {
|
|
143
144
|
__extends(SolanaStreamClient, _super);
|
|
@@ -157,6 +158,9 @@ var SolanaStreamClient = /** @class */ (function (_super) {
|
|
|
157
158
|
SolanaStreamClient.prototype.getConnection = function () {
|
|
158
159
|
return this.connection;
|
|
159
160
|
};
|
|
161
|
+
SolanaStreamClient.prototype.getCommitment = function () {
|
|
162
|
+
return typeof this.commitment == "string" ? this.commitment : this.commitment.commitment;
|
|
163
|
+
};
|
|
160
164
|
SolanaStreamClient.prototype.getProgramId = function () {
|
|
161
165
|
return this.programId.toBase58();
|
|
162
166
|
};
|
|
@@ -164,50 +168,75 @@ var SolanaStreamClient = /** @class */ (function (_super) {
|
|
|
164
168
|
* Creates a new stream/vesting contract.
|
|
165
169
|
* All fees are paid by sender (escrow metadata account rent, escrow token account rent, recipient's associated token account rent, Streamflow's service fee).
|
|
166
170
|
*/
|
|
167
|
-
SolanaStreamClient.prototype.create = function (
|
|
171
|
+
SolanaStreamClient.prototype.create = function (data, extParams) {
|
|
172
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
173
|
+
var _a, ixs, metadata, metadataPubKey, _b, tx, hash, signature;
|
|
174
|
+
return __generator(this, function (_c) {
|
|
175
|
+
switch (_c.label) {
|
|
176
|
+
case 0: return [4 /*yield*/, this.prepareCreateInstructions(data, extParams)];
|
|
177
|
+
case 1:
|
|
178
|
+
_a = _c.sent(), ixs = _a.ixs, metadata = _a.metadata, metadataPubKey = _a.metadataPubKey;
|
|
179
|
+
return [4 /*yield*/, (0, solana_1.prepareTransaction)(this.connection, ixs, extParams.sender.publicKey, undefined, metadata)];
|
|
180
|
+
case 2:
|
|
181
|
+
_b = _c.sent(), tx = _b.tx, hash = _b.hash;
|
|
182
|
+
return [4 /*yield*/, (0, solana_1.signAndExecuteTransaction)(this.connection, extParams.sender, tx, hash)];
|
|
183
|
+
case 3:
|
|
184
|
+
signature = _c.sent();
|
|
185
|
+
return [2 /*return*/, { ixs: ixs, txId: signature, metadataId: metadataPubKey.toBase58() }];
|
|
186
|
+
}
|
|
187
|
+
});
|
|
188
|
+
});
|
|
189
|
+
};
|
|
190
|
+
/**
|
|
191
|
+
* Creates a new stream/vesting contract.
|
|
192
|
+
* All fees are paid by sender (escrow metadata account rent, escrow token account rent, recipient's associated token account rent, Streamflow's service fee).
|
|
193
|
+
*/
|
|
194
|
+
SolanaStreamClient.prototype.prepareCreateInstructions = function (_a, _b) {
|
|
168
195
|
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;
|
|
169
|
-
var sender = _b.sender, metadataPubKeys = _b.metadataPubKeys, _e = _b.isNative, isNative = _e === void 0 ? false : _e;
|
|
196
|
+
var sender = _b.sender, metadataPubKeys = _b.metadataPubKeys, _e = _b.isNative, isNative = _e === void 0 ? false : _e, computePrice = _b.computePrice, computeLimit = _b.computeLimit;
|
|
170
197
|
return __awaiter(this, void 0, void 0, function () {
|
|
171
|
-
var ixs, mintPublicKey, recipientPublicKey, _f, metadata, metadataPubKey, _g, escrowTokens, senderTokens, recipientTokens, streamflowTreasuryTokens, partnerPublicKey, partnerTokens, totalFee, totalAmount, _h, _j, _k, _l
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
switch (_o.label) {
|
|
198
|
+
var ixs, mintPublicKey, recipientPublicKey, _f, metadata, metadataPubKey, _g, escrowTokens, senderTokens, recipientTokens, streamflowTreasuryTokens, partnerPublicKey, partnerTokens, totalFee, totalAmount, _h, _j, _k, _l;
|
|
199
|
+
return __generator(this, function (_m) {
|
|
200
|
+
switch (_m.label) {
|
|
175
201
|
case 0:
|
|
176
202
|
if (!sender.publicKey) {
|
|
177
203
|
throw new Error("Sender's PublicKey is not available, check passed wallet adapter!");
|
|
178
204
|
}
|
|
179
|
-
ixs =
|
|
205
|
+
ixs = (0, solana_1.prepareBaseInstructions)(this.connection, {
|
|
206
|
+
computePrice: computePrice,
|
|
207
|
+
computeLimit: computeLimit,
|
|
208
|
+
});
|
|
180
209
|
mintPublicKey = isNative ? spl_token_1.NATIVE_MINT : new web3_js_1.PublicKey(mint);
|
|
181
210
|
recipientPublicKey = new web3_js_1.PublicKey(recipient);
|
|
182
211
|
_f = this.getOrCreateStreamMetadata(metadataPubKeys), metadata = _f.metadata, metadataPubKey = _f.metadataPubKey;
|
|
183
212
|
_g = __read(web3_js_1.PublicKey.findProgramAddressSync([buffer_1.Buffer.from("strm"), metadataPubKey.toBuffer()], this.programId), 1), escrowTokens = _g[0];
|
|
184
213
|
return [4 /*yield*/, (0, solana_1.ata)(mintPublicKey, sender.publicKey)];
|
|
185
214
|
case 1:
|
|
186
|
-
senderTokens =
|
|
215
|
+
senderTokens = _m.sent();
|
|
187
216
|
return [4 /*yield*/, (0, solana_1.ata)(mintPublicKey, recipientPublicKey)];
|
|
188
217
|
case 2:
|
|
189
|
-
recipientTokens =
|
|
218
|
+
recipientTokens = _m.sent();
|
|
190
219
|
return [4 /*yield*/, (0, solana_1.ata)(mintPublicKey, constants_1.STREAMFLOW_TREASURY_PUBLIC_KEY)];
|
|
191
220
|
case 3:
|
|
192
|
-
streamflowTreasuryTokens =
|
|
221
|
+
streamflowTreasuryTokens = _m.sent();
|
|
193
222
|
partnerPublicKey = partner ? new web3_js_1.PublicKey(partner) : constants_1.STREAMFLOW_TREASURY_PUBLIC_KEY;
|
|
194
223
|
return [4 /*yield*/, (0, solana_1.ata)(mintPublicKey, partnerPublicKey)];
|
|
195
224
|
case 4:
|
|
196
|
-
partnerTokens =
|
|
225
|
+
partnerTokens = _m.sent();
|
|
197
226
|
if (!isNative) return [3 /*break*/, 7];
|
|
198
227
|
return [4 /*yield*/, this.getTotalFee({
|
|
199
228
|
address: partner !== null && partner !== void 0 ? partner : sender.publicKey.toBase58(),
|
|
200
229
|
})];
|
|
201
230
|
case 5:
|
|
202
|
-
totalFee =
|
|
231
|
+
totalFee = _m.sent();
|
|
203
232
|
totalAmount = (0, utils_2.calculateTotalAmountToDeposit)(depositedAmount, totalFee);
|
|
204
233
|
_j = (_h = ixs.push).apply;
|
|
205
234
|
_k = [ixs];
|
|
206
235
|
_l = [[]];
|
|
207
236
|
return [4 /*yield*/, (0, solana_1.prepareWrappedAccount)(this.connection, sender.publicKey, totalAmount)];
|
|
208
237
|
case 6:
|
|
209
|
-
_j.apply(_h, _k.concat([__spreadArray.apply(void 0, _l.concat([__read.apply(void 0, [(
|
|
210
|
-
|
|
238
|
+
_j.apply(_h, _k.concat([__spreadArray.apply(void 0, _l.concat([__read.apply(void 0, [(_m.sent())]), false]))]));
|
|
239
|
+
_m.label = 7;
|
|
211
240
|
case 7:
|
|
212
241
|
ixs.push((0, instructions_1.createStreamInstruction)({
|
|
213
242
|
start: new bn_js_1.default(start),
|
|
@@ -244,22 +273,7 @@ var SolanaStreamClient = /** @class */ (function (_super) {
|
|
|
244
273
|
withdrawor: constants_1.WITHDRAWOR_PUBLIC_KEY,
|
|
245
274
|
systemProgram: web3_js_1.SystemProgram.programId,
|
|
246
275
|
}));
|
|
247
|
-
|
|
248
|
-
return [4 /*yield*/, this.connection.getLatestBlockhash(commitment)];
|
|
249
|
-
case 8:
|
|
250
|
-
hash = _o.sent();
|
|
251
|
-
tx = (_m = new web3_js_1.Transaction({
|
|
252
|
-
feePayer: sender.publicKey,
|
|
253
|
-
blockhash: hash.blockhash,
|
|
254
|
-
lastValidBlockHeight: hash.lastValidBlockHeight,
|
|
255
|
-
})).add.apply(_m, __spreadArray([], __read(ixs), false));
|
|
256
|
-
if (metadata) {
|
|
257
|
-
tx.partialSign(metadata);
|
|
258
|
-
}
|
|
259
|
-
return [4 /*yield*/, (0, solana_1.signAndExecuteTransaction)(this.connection, sender, tx, hash)];
|
|
260
|
-
case 9:
|
|
261
|
-
signature = _o.sent();
|
|
262
|
-
return [2 /*return*/, { ixs: ixs, txId: signature, metadataId: metadataPubKey.toBase58() }];
|
|
276
|
+
return [2 /*return*/, { ixs: ixs, metadata: metadata, metadataPubKey: metadataPubKey }];
|
|
263
277
|
}
|
|
264
278
|
});
|
|
265
279
|
});
|
|
@@ -274,14 +288,35 @@ var SolanaStreamClient = /** @class */ (function (_super) {
|
|
|
274
288
|
*
|
|
275
289
|
* If you are not sure if you should use create or create_unchecked, go for create to be safer.
|
|
276
290
|
*/
|
|
277
|
-
SolanaStreamClient.prototype.createUnchecked = function (
|
|
291
|
+
SolanaStreamClient.prototype.createUnchecked = function (data, extParams) {
|
|
292
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
293
|
+
var _a, ixs, metadata, metadataPubKey, _b, tx, hash, signature;
|
|
294
|
+
return __generator(this, function (_c) {
|
|
295
|
+
switch (_c.label) {
|
|
296
|
+
case 0: return [4 /*yield*/, this.prepareCreateUncheckedInstructions(data, extParams)];
|
|
297
|
+
case 1:
|
|
298
|
+
_a = _c.sent(), ixs = _a.ixs, metadata = _a.metadata, metadataPubKey = _a.metadataPubKey;
|
|
299
|
+
return [4 /*yield*/, (0, solana_1.prepareTransaction)(this.connection, ixs, extParams.sender.publicKey, undefined, metadata)];
|
|
300
|
+
case 2:
|
|
301
|
+
_b = _c.sent(), tx = _b.tx, hash = _b.hash;
|
|
302
|
+
return [4 /*yield*/, (0, solana_1.signAndExecuteTransaction)(this.connection, extParams.sender, tx, hash)];
|
|
303
|
+
case 3:
|
|
304
|
+
signature = _c.sent();
|
|
305
|
+
return [2 /*return*/, { ixs: ixs, txId: signature, metadataId: metadataPubKey.toBase58() }];
|
|
306
|
+
}
|
|
307
|
+
});
|
|
308
|
+
});
|
|
309
|
+
};
|
|
310
|
+
/**
|
|
311
|
+
* Create Transaction instructions for `createUnchecked`
|
|
312
|
+
*/
|
|
313
|
+
SolanaStreamClient.prototype.prepareCreateUncheckedInstructions = function (_a, _b) {
|
|
278
314
|
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;
|
|
279
|
-
var sender = _b.sender, metadataPubKeys = _b.metadataPubKeys, _e = _b.isNative, isNative = _e === void 0 ? false : _e;
|
|
315
|
+
var sender = _b.sender, metadataPubKeys = _b.metadataPubKeys, _e = _b.isNative, isNative = _e === void 0 ? false : _e, computePrice = _b.computePrice, computeLimit = _b.computeLimit;
|
|
280
316
|
return __awaiter(this, void 0, void 0, function () {
|
|
281
|
-
var mintPublicKey, recipientPublicKey, _f, metadata, metadataPubKey, rentToExempt, createMetadataInstruction, _g, escrowTokens, senderTokens, partnerPublicKey,
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
switch (_k.label) {
|
|
317
|
+
var mintPublicKey, recipientPublicKey, _f, metadata, metadataPubKey, rentToExempt, createMetadataInstruction, _g, escrowTokens, senderTokens, partnerPublicKey, ixs, totalFee, totalAmount, _h, _j, _k, _l, createInstruction;
|
|
318
|
+
return __generator(this, function (_m) {
|
|
319
|
+
switch (_m.label) {
|
|
285
320
|
case 0:
|
|
286
321
|
if (!sender.publicKey) {
|
|
287
322
|
throw new Error("Sender's PublicKey is not available, check passed wallet adapter!");
|
|
@@ -291,7 +326,7 @@ var SolanaStreamClient = /** @class */ (function (_super) {
|
|
|
291
326
|
_f = this.getOrCreateStreamMetadata(metadataPubKeys), metadata = _f.metadata, metadataPubKey = _f.metadataPubKey;
|
|
292
327
|
return [4 /*yield*/, this.connection.getMinimumBalanceForRentExemption(METADATA_ACC_SIZE)];
|
|
293
328
|
case 1:
|
|
294
|
-
rentToExempt =
|
|
329
|
+
rentToExempt = _m.sent();
|
|
295
330
|
createMetadataInstruction = web3_js_1.SystemProgram.createAccount({
|
|
296
331
|
programId: this.programId,
|
|
297
332
|
space: METADATA_ACC_SIZE,
|
|
@@ -302,18 +337,25 @@ var SolanaStreamClient = /** @class */ (function (_super) {
|
|
|
302
337
|
_g = __read(web3_js_1.PublicKey.findProgramAddressSync([buffer_1.Buffer.from("strm"), metadataPubKey.toBuffer()], this.programId), 1), escrowTokens = _g[0];
|
|
303
338
|
return [4 /*yield*/, (0, solana_1.ata)(mintPublicKey, sender.publicKey)];
|
|
304
339
|
case 2:
|
|
305
|
-
senderTokens =
|
|
340
|
+
senderTokens = _m.sent();
|
|
306
341
|
partnerPublicKey = partner ? new web3_js_1.PublicKey(partner) : constants_1.STREAMFLOW_TREASURY_PUBLIC_KEY;
|
|
307
|
-
|
|
308
|
-
|
|
342
|
+
ixs = (0, solana_1.prepareBaseInstructions)(this.connection, {
|
|
343
|
+
computePrice: computePrice,
|
|
344
|
+
computeLimit: computeLimit,
|
|
345
|
+
});
|
|
346
|
+
if (!isNative) return [3 /*break*/, 5];
|
|
347
|
+
return [4 /*yield*/, this.getTotalFee({ address: partner !== null && partner !== void 0 ? partner : sender.publicKey.toBase58() })];
|
|
309
348
|
case 3:
|
|
310
|
-
|
|
311
|
-
|
|
349
|
+
totalFee = _m.sent();
|
|
350
|
+
totalAmount = (0, utils_2.calculateTotalAmountToDeposit)(depositedAmount, totalFee);
|
|
351
|
+
_j = (_h = ixs.push).apply;
|
|
352
|
+
_k = [ixs];
|
|
353
|
+
_l = [[]];
|
|
354
|
+
return [4 /*yield*/, (0, solana_1.prepareWrappedAccount)(this.connection, sender.publicKey, totalAmount)];
|
|
312
355
|
case 4:
|
|
313
|
-
_h
|
|
314
|
-
|
|
356
|
+
_j.apply(_h, _k.concat([__spreadArray.apply(void 0, _l.concat([__read.apply(void 0, [(_m.sent())]), false]))]));
|
|
357
|
+
_m.label = 5;
|
|
315
358
|
case 5:
|
|
316
|
-
nativeInstructions = _h;
|
|
317
359
|
createInstruction = (0, instructions_1.createUncheckedStreamInstruction)({
|
|
318
360
|
start: new bn_js_1.default(start),
|
|
319
361
|
depositedAmount: depositedAmount,
|
|
@@ -344,23 +386,8 @@ var SolanaStreamClient = /** @class */ (function (_super) {
|
|
|
344
386
|
withdrawor: constants_1.WITHDRAWOR_PUBLIC_KEY,
|
|
345
387
|
systemProgram: web3_js_1.SystemProgram.programId,
|
|
346
388
|
});
|
|
347
|
-
|
|
348
|
-
ixs
|
|
349
|
-
return [4 /*yield*/, this.connection.getLatestBlockhash(commitment)];
|
|
350
|
-
case 6:
|
|
351
|
-
hash = _k.sent();
|
|
352
|
-
tx = (_j = new web3_js_1.Transaction({
|
|
353
|
-
feePayer: sender.publicKey,
|
|
354
|
-
blockhash: hash.blockhash,
|
|
355
|
-
lastValidBlockHeight: hash.lastValidBlockHeight,
|
|
356
|
-
})).add.apply(_j, __spreadArray(__spreadArray([], __read(nativeInstructions), false), __read(ixs), false));
|
|
357
|
-
if (metadata) {
|
|
358
|
-
tx.partialSign(metadata);
|
|
359
|
-
}
|
|
360
|
-
return [4 /*yield*/, (0, solana_1.signAndExecuteTransaction)(this.connection, sender, tx, hash)];
|
|
361
|
-
case 7:
|
|
362
|
-
signature = _k.sent();
|
|
363
|
-
return [2 /*return*/, { ixs: ixs, txId: signature, metadataId: metadataPubKey.toBase58() }];
|
|
389
|
+
ixs.push(createMetadataInstruction, createInstruction);
|
|
390
|
+
return [2 /*return*/, { ixs: ixs, metadata: metadata, metadataPubKey: metadataPubKey }];
|
|
364
391
|
}
|
|
365
392
|
});
|
|
366
393
|
});
|
|
@@ -370,9 +397,9 @@ var SolanaStreamClient = /** @class */ (function (_super) {
|
|
|
370
397
|
* All fees are paid by sender (escrow metadata account rent, escrow token account rent, recipient's associated token account rent, Streamflow's service fee).
|
|
371
398
|
*/
|
|
372
399
|
SolanaStreamClient.prototype.createMultiple = function (data, _a) {
|
|
373
|
-
var sender = _a.sender, metadataPubKeys = _a.metadataPubKeys, _b = _a.isNative, isNative = _b === void 0 ? false : _b;
|
|
400
|
+
var sender = _a.sender, metadataPubKeys = _a.metadataPubKeys, _b = _a.isNative, isNative = _b === void 0 ? false : _b, computePrice = _a.computePrice, computeLimit = _a.computeLimit;
|
|
374
401
|
return __awaiter(this, void 0, void 0, function () {
|
|
375
|
-
var recipients, metadatas, metadataToRecipient, errors, signatures, batch, instructionsBatch, i, recipientData, _c, ixs, metadata, metadataPubKey,
|
|
402
|
+
var recipients, metadatas, metadataToRecipient, errors, signatures, batch, instructionsBatch, i, recipientData, _c, ixs, metadata, metadataPubKey, hash, instructionsBatch_1, instructionsBatch_1_1, _d, ixs, metadata, recipient, tx, totalDepositedAmount, nativeInstructions, tx, signedBatch, prepareTx, responses, signedBatch_1, signedBatch_1_1, batchTx, _e, _f, _g, _h, e_1_1, batchTransactionsCalls, _j, _k, _l, _m, successes, failures;
|
|
376
403
|
var e_2, _o, _p, _q, e_1, _r;
|
|
377
404
|
var _this = this;
|
|
378
405
|
return __generator(this, function (_s) {
|
|
@@ -397,6 +424,8 @@ var SolanaStreamClient = /** @class */ (function (_super) {
|
|
|
397
424
|
return [4 /*yield*/, this.prepareStreamInstructions(recipientData, data, {
|
|
398
425
|
sender: sender,
|
|
399
426
|
metadataPubKeys: metadataPubKeys[i] ? [metadataPubKeys[i]] : undefined,
|
|
427
|
+
computePrice: computePrice,
|
|
428
|
+
computeLimit: computeLimit,
|
|
400
429
|
})];
|
|
401
430
|
case 2:
|
|
402
431
|
_c = _s.sent(), ixs = _c.ixs, metadata = _c.metadata, metadataPubKey = _c.metadataPubKey;
|
|
@@ -411,9 +440,7 @@ var SolanaStreamClient = /** @class */ (function (_super) {
|
|
|
411
440
|
case 3:
|
|
412
441
|
i++;
|
|
413
442
|
return [3 /*break*/, 1];
|
|
414
|
-
case 4:
|
|
415
|
-
commitment = typeof this.commitment == "string" ? this.commitment : this.commitment.commitment;
|
|
416
|
-
return [4 /*yield*/, this.connection.getLatestBlockhash(commitment)];
|
|
443
|
+
case 4: return [4 /*yield*/, this.connection.getLatestBlockhash()];
|
|
417
444
|
case 5:
|
|
418
445
|
hash = _s.sent();
|
|
419
446
|
try {
|
|
@@ -442,13 +469,13 @@ var SolanaStreamClient = /** @class */ (function (_super) {
|
|
|
442
469
|
return [4 /*yield*/, (0, solana_1.prepareWrappedAccount)(this.connection, sender.publicKey, totalDepositedAmount)];
|
|
443
470
|
case 6:
|
|
444
471
|
nativeInstructions = _s.sent();
|
|
445
|
-
|
|
472
|
+
tx = (_q = new web3_js_1.Transaction({
|
|
446
473
|
feePayer: sender.publicKey,
|
|
447
474
|
blockhash: hash.blockhash,
|
|
448
475
|
lastValidBlockHeight: hash.lastValidBlockHeight,
|
|
449
476
|
})).add.apply(_q, __spreadArray([], __read(nativeInstructions), false));
|
|
450
477
|
batch.push({
|
|
451
|
-
tx:
|
|
478
|
+
tx: tx,
|
|
452
479
|
recipient: sender.publicKey.toBase58(),
|
|
453
480
|
});
|
|
454
481
|
_s.label = 7;
|
|
@@ -523,19 +550,44 @@ var SolanaStreamClient = /** @class */ (function (_super) {
|
|
|
523
550
|
/**
|
|
524
551
|
* Attempts withdrawing from the specified stream.
|
|
525
552
|
*/
|
|
526
|
-
SolanaStreamClient.prototype.withdraw = function (_a,
|
|
527
|
-
var id = _a.id,
|
|
528
|
-
|
|
553
|
+
SolanaStreamClient.prototype.withdraw = function (_a, extParams) {
|
|
554
|
+
var id = _a.id, _b = _a.amount, amount = _b === void 0 ? constants_2.WITHDRAW_AVAILABLE_AMOUNT : _b;
|
|
555
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
556
|
+
var ixs, _c, tx, hash, signature;
|
|
557
|
+
return __generator(this, function (_d) {
|
|
558
|
+
switch (_d.label) {
|
|
559
|
+
case 0: return [4 /*yield*/, this.prepareWithdrawInstructions({ id: id, amount: amount }, extParams)];
|
|
560
|
+
case 1:
|
|
561
|
+
ixs = _d.sent();
|
|
562
|
+
return [4 /*yield*/, (0, solana_1.prepareTransaction)(this.connection, ixs, extParams.invoker.publicKey)];
|
|
563
|
+
case 2:
|
|
564
|
+
_c = _d.sent(), tx = _c.tx, hash = _c.hash;
|
|
565
|
+
return [4 /*yield*/, (0, solana_1.signAndExecuteTransaction)(this.connection, extParams.invoker, tx, hash)];
|
|
566
|
+
case 3:
|
|
567
|
+
signature = _d.sent();
|
|
568
|
+
return [2 /*return*/, { ixs: ixs, txId: signature }];
|
|
569
|
+
}
|
|
570
|
+
});
|
|
571
|
+
});
|
|
572
|
+
};
|
|
573
|
+
/**
|
|
574
|
+
* Creates Transaction Instructions for withdrawal
|
|
575
|
+
*/
|
|
576
|
+
SolanaStreamClient.prototype.prepareWithdrawInstructions = function (_a, _b) {
|
|
577
|
+
var id = _a.id, _c = _a.amount, amount = _c === void 0 ? constants_2.WITHDRAW_AVAILABLE_AMOUNT : _c;
|
|
578
|
+
var invoker = _b.invoker, checkTokenAccounts = _b.checkTokenAccounts, computePrice = _b.computePrice, computeLimit = _b.computeLimit;
|
|
529
579
|
return __awaiter(this, void 0, void 0, function () {
|
|
530
|
-
var ixs, streamPublicKey, escrow, data, streamflowTreasuryTokens, partnerTokens
|
|
531
|
-
var _c;
|
|
580
|
+
var ixs, streamPublicKey, escrow, data, streamflowTreasuryTokens, partnerTokens;
|
|
532
581
|
return __generator(this, function (_d) {
|
|
533
582
|
switch (_d.label) {
|
|
534
583
|
case 0:
|
|
535
584
|
if (!invoker.publicKey) {
|
|
536
585
|
throw new Error("Invoker's PublicKey is not available, check passed wallet adapter!");
|
|
537
586
|
}
|
|
538
|
-
ixs =
|
|
587
|
+
ixs = (0, solana_1.prepareBaseInstructions)(this.connection, {
|
|
588
|
+
computePrice: computePrice,
|
|
589
|
+
computeLimit: computeLimit,
|
|
590
|
+
});
|
|
539
591
|
streamPublicKey = new web3_js_1.PublicKey(id);
|
|
540
592
|
return [4 /*yield*/, this.connection.getAccountInfo(streamPublicKey)];
|
|
541
593
|
case 1:
|
|
@@ -566,19 +618,7 @@ var SolanaStreamClient = /** @class */ (function (_super) {
|
|
|
566
618
|
mint: data.mint,
|
|
567
619
|
tokenProgram: spl_token_1.TOKEN_PROGRAM_ID,
|
|
568
620
|
}));
|
|
569
|
-
|
|
570
|
-
return [4 /*yield*/, this.connection.getLatestBlockhash(commitment)];
|
|
571
|
-
case 5:
|
|
572
|
-
hash = _d.sent();
|
|
573
|
-
tx = (_c = new web3_js_1.Transaction({
|
|
574
|
-
feePayer: invoker.publicKey,
|
|
575
|
-
blockhash: hash.blockhash,
|
|
576
|
-
lastValidBlockHeight: hash.lastValidBlockHeight,
|
|
577
|
-
})).add.apply(_c, __spreadArray([], __read(ixs), false));
|
|
578
|
-
return [4 /*yield*/, (0, solana_1.signAndExecuteTransaction)(this.connection, invoker, tx, hash)];
|
|
579
|
-
case 6:
|
|
580
|
-
signature = _d.sent();
|
|
581
|
-
return [2 /*return*/, { ixs: ixs, txId: signature }];
|
|
621
|
+
return [2 /*return*/, ixs];
|
|
582
622
|
}
|
|
583
623
|
});
|
|
584
624
|
});
|
|
@@ -586,14 +626,36 @@ var SolanaStreamClient = /** @class */ (function (_super) {
|
|
|
586
626
|
/**
|
|
587
627
|
* Attempts canceling the specified stream.
|
|
588
628
|
*/
|
|
589
|
-
SolanaStreamClient.prototype.cancel = function (_a,
|
|
629
|
+
SolanaStreamClient.prototype.cancel = function (_a, extParams) {
|
|
590
630
|
var id = _a.id;
|
|
591
|
-
var invoker = _b.invoker, checkTokenAccounts = _b.checkTokenAccounts;
|
|
592
631
|
return __awaiter(this, void 0, void 0, function () {
|
|
593
|
-
var
|
|
594
|
-
|
|
595
|
-
|
|
596
|
-
|
|
632
|
+
var ixs, _b, tx, hash, signature;
|
|
633
|
+
return __generator(this, function (_c) {
|
|
634
|
+
switch (_c.label) {
|
|
635
|
+
case 0: return [4 /*yield*/, this.prepareCancelInstructions({ id: id }, extParams)];
|
|
636
|
+
case 1:
|
|
637
|
+
ixs = _c.sent();
|
|
638
|
+
return [4 /*yield*/, (0, solana_1.prepareTransaction)(this.connection, ixs, extParams.invoker.publicKey)];
|
|
639
|
+
case 2:
|
|
640
|
+
_b = _c.sent(), tx = _b.tx, hash = _b.hash;
|
|
641
|
+
return [4 /*yield*/, (0, solana_1.signAndExecuteTransaction)(this.connection, extParams.invoker, tx, hash)];
|
|
642
|
+
case 3:
|
|
643
|
+
signature = _c.sent();
|
|
644
|
+
return [2 /*return*/, { ixs: ixs, txId: signature }];
|
|
645
|
+
}
|
|
646
|
+
});
|
|
647
|
+
});
|
|
648
|
+
};
|
|
649
|
+
/**
|
|
650
|
+
* Creates Transaction Instructions for cancel
|
|
651
|
+
*/
|
|
652
|
+
SolanaStreamClient.prototype.prepareCancelInstructions = function (_a, _b) {
|
|
653
|
+
var id = _a.id;
|
|
654
|
+
var invoker = _b.invoker, checkTokenAccounts = _b.checkTokenAccounts, computePrice = _b.computePrice, computeLimit = _b.computeLimit;
|
|
655
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
656
|
+
var streamPublicKey, escrowAcc, data, streamflowTreasuryTokens, partnerTokens, ixs;
|
|
657
|
+
return __generator(this, function (_c) {
|
|
658
|
+
switch (_c.label) {
|
|
597
659
|
case 0:
|
|
598
660
|
if (!invoker.publicKey) {
|
|
599
661
|
throw new Error("Invoker's PublicKey is not available, check passed wallet adapter!");
|
|
@@ -601,21 +663,24 @@ var SolanaStreamClient = /** @class */ (function (_super) {
|
|
|
601
663
|
streamPublicKey = new web3_js_1.PublicKey(id);
|
|
602
664
|
return [4 /*yield*/, this.connection.getAccountInfo(streamPublicKey)];
|
|
603
665
|
case 1:
|
|
604
|
-
escrowAcc =
|
|
666
|
+
escrowAcc = _c.sent();
|
|
605
667
|
if (!(escrowAcc === null || escrowAcc === void 0 ? void 0 : escrowAcc.data)) {
|
|
606
668
|
throw new Error("Couldn't get account info");
|
|
607
669
|
}
|
|
608
670
|
data = (0, utils_1.decodeStream)(escrowAcc === null || escrowAcc === void 0 ? void 0 : escrowAcc.data);
|
|
609
671
|
return [4 /*yield*/, (0, solana_1.ata)(data.mint, constants_1.STREAMFLOW_TREASURY_PUBLIC_KEY)];
|
|
610
672
|
case 2:
|
|
611
|
-
streamflowTreasuryTokens =
|
|
673
|
+
streamflowTreasuryTokens = _c.sent();
|
|
612
674
|
return [4 /*yield*/, (0, solana_1.ata)(data.mint, data.partner)];
|
|
613
675
|
case 3:
|
|
614
|
-
partnerTokens =
|
|
615
|
-
ixs =
|
|
676
|
+
partnerTokens = _c.sent();
|
|
677
|
+
ixs = (0, solana_1.prepareBaseInstructions)(this.connection, {
|
|
678
|
+
computePrice: computePrice,
|
|
679
|
+
computeLimit: computeLimit,
|
|
680
|
+
});
|
|
616
681
|
return [4 /*yield*/, this.checkAssociatedTokenAccounts(data, { invoker: invoker, checkTokenAccounts: checkTokenAccounts }, ixs)];
|
|
617
682
|
case 4:
|
|
618
|
-
|
|
683
|
+
_c.sent();
|
|
619
684
|
ixs.push((0, instructions_1.cancelStreamInstruction)(this.programId, {
|
|
620
685
|
authority: invoker.publicKey,
|
|
621
686
|
sender: data.sender,
|
|
@@ -631,18 +696,30 @@ var SolanaStreamClient = /** @class */ (function (_super) {
|
|
|
631
696
|
mint: data.mint,
|
|
632
697
|
tokenProgram: spl_token_1.TOKEN_PROGRAM_ID,
|
|
633
698
|
}));
|
|
634
|
-
|
|
635
|
-
|
|
636
|
-
|
|
637
|
-
|
|
638
|
-
|
|
639
|
-
|
|
640
|
-
|
|
641
|
-
|
|
642
|
-
|
|
643
|
-
|
|
644
|
-
|
|
645
|
-
|
|
699
|
+
return [2 /*return*/, ixs];
|
|
700
|
+
}
|
|
701
|
+
});
|
|
702
|
+
});
|
|
703
|
+
};
|
|
704
|
+
/**
|
|
705
|
+
* Attempts changing the stream/vesting contract's recipient (effectively transferring the stream/vesting contract).
|
|
706
|
+
* Potential associated token account rent fee (to make it rent-exempt) is paid by the transaction initiator.
|
|
707
|
+
*/
|
|
708
|
+
SolanaStreamClient.prototype.transfer = function (_a, extParams) {
|
|
709
|
+
var id = _a.id, newRecipient = _a.newRecipient;
|
|
710
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
711
|
+
var ixs, _b, tx, hash, signature;
|
|
712
|
+
return __generator(this, function (_c) {
|
|
713
|
+
switch (_c.label) {
|
|
714
|
+
case 0: return [4 /*yield*/, this.prepareTransferInstructions({ id: id, newRecipient: newRecipient }, extParams)];
|
|
715
|
+
case 1:
|
|
716
|
+
ixs = _c.sent();
|
|
717
|
+
return [4 /*yield*/, (0, solana_1.prepareTransaction)(this.connection, ixs, extParams.invoker.publicKey)];
|
|
718
|
+
case 2:
|
|
719
|
+
_b = _c.sent(), tx = _b.tx, hash = _b.hash;
|
|
720
|
+
return [4 /*yield*/, (0, solana_1.signAndExecuteTransaction)(this.connection, extParams.invoker, tx, hash)];
|
|
721
|
+
case 3:
|
|
722
|
+
signature = _c.sent();
|
|
646
723
|
return [2 /*return*/, { ixs: ixs, txId: signature }];
|
|
647
724
|
}
|
|
648
725
|
});
|
|
@@ -652,21 +729,23 @@ var SolanaStreamClient = /** @class */ (function (_super) {
|
|
|
652
729
|
* Attempts changing the stream/vesting contract's recipient (effectively transferring the stream/vesting contract).
|
|
653
730
|
* Potential associated token account rent fee (to make it rent-exempt) is paid by the transaction initiator.
|
|
654
731
|
*/
|
|
655
|
-
SolanaStreamClient.prototype.
|
|
656
|
-
var id = _a.id,
|
|
657
|
-
var invoker = _b.invoker;
|
|
732
|
+
SolanaStreamClient.prototype.prepareTransferInstructions = function (_a, _b) {
|
|
733
|
+
var id = _a.id, newRecipient = _a.newRecipient;
|
|
734
|
+
var invoker = _b.invoker, computePrice = _b.computePrice, _c = _b.computeLimit, computeLimit = _c === void 0 ? 100001 : _c;
|
|
658
735
|
return __awaiter(this, void 0, void 0, function () {
|
|
659
|
-
var ixs, stream,
|
|
660
|
-
var _c;
|
|
736
|
+
var ixs, stream, newRecipientPublicKey, escrow, mint, newRecipientTokens;
|
|
661
737
|
return __generator(this, function (_d) {
|
|
662
738
|
switch (_d.label) {
|
|
663
739
|
case 0:
|
|
664
740
|
if (!invoker.publicKey) {
|
|
665
741
|
throw new Error("Invoker's PublicKey is not available, check passed wallet adapter!");
|
|
666
742
|
}
|
|
667
|
-
ixs =
|
|
743
|
+
ixs = (0, solana_1.prepareBaseInstructions)(this.connection, {
|
|
744
|
+
computePrice: computePrice,
|
|
745
|
+
computeLimit: computeLimit,
|
|
746
|
+
});
|
|
668
747
|
stream = new web3_js_1.PublicKey(id);
|
|
669
|
-
|
|
748
|
+
newRecipientPublicKey = new web3_js_1.PublicKey(newRecipient);
|
|
670
749
|
return [4 /*yield*/, this.connection.getAccountInfo(stream)];
|
|
671
750
|
case 1:
|
|
672
751
|
escrow = _d.sent();
|
|
@@ -674,13 +753,12 @@ var SolanaStreamClient = /** @class */ (function (_super) {
|
|
|
674
753
|
throw new Error("Couldn't get account info");
|
|
675
754
|
}
|
|
676
755
|
mint = (0, utils_1.decodeStream)(escrow === null || escrow === void 0 ? void 0 : escrow.data).mint;
|
|
677
|
-
return [4 /*yield*/, (0, solana_1.ata)(mint,
|
|
756
|
+
return [4 /*yield*/, (0, solana_1.ata)(mint, newRecipientPublicKey)];
|
|
678
757
|
case 2:
|
|
679
758
|
newRecipientTokens = _d.sent();
|
|
680
|
-
ixs.push(web3_js_1.ComputeBudgetProgram.setComputeUnitLimit({ units: 100001 }));
|
|
681
759
|
ixs.push((0, instructions_1.transferStreamInstruction)(this.programId, {
|
|
682
760
|
authority: invoker.publicKey,
|
|
683
|
-
newRecipient:
|
|
761
|
+
newRecipient: newRecipientPublicKey,
|
|
684
762
|
newRecipientTokens: newRecipientTokens,
|
|
685
763
|
metadata: stream,
|
|
686
764
|
mint: mint,
|
|
@@ -689,63 +767,75 @@ var SolanaStreamClient = /** @class */ (function (_super) {
|
|
|
689
767
|
associatedTokenProgram: spl_token_1.ASSOCIATED_TOKEN_PROGRAM_ID,
|
|
690
768
|
systemProgram: web3_js_1.SystemProgram.programId,
|
|
691
769
|
}));
|
|
692
|
-
|
|
693
|
-
|
|
770
|
+
return [2 /*return*/, ixs];
|
|
771
|
+
}
|
|
772
|
+
});
|
|
773
|
+
});
|
|
774
|
+
};
|
|
775
|
+
/**
|
|
776
|
+
* Tops up stream account with specified amount.
|
|
777
|
+
*/
|
|
778
|
+
SolanaStreamClient.prototype.topup = function (_a, extParams) {
|
|
779
|
+
var id = _a.id, amount = _a.amount;
|
|
780
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
781
|
+
var ixs, _b, tx, hash, signature;
|
|
782
|
+
return __generator(this, function (_c) {
|
|
783
|
+
switch (_c.label) {
|
|
784
|
+
case 0: return [4 /*yield*/, this.prepareTopupInstructions({ id: id, amount: amount }, extParams)];
|
|
785
|
+
case 1:
|
|
786
|
+
ixs = _c.sent();
|
|
787
|
+
return [4 /*yield*/, (0, solana_1.prepareTransaction)(this.connection, ixs, extParams.invoker.publicKey)];
|
|
788
|
+
case 2:
|
|
789
|
+
_b = _c.sent(), tx = _b.tx, hash = _b.hash;
|
|
790
|
+
return [4 /*yield*/, (0, solana_1.signAndExecuteTransaction)(this.connection, extParams.invoker, tx, hash)];
|
|
694
791
|
case 3:
|
|
695
|
-
|
|
696
|
-
tx = (_c = new web3_js_1.Transaction({
|
|
697
|
-
feePayer: invoker.publicKey,
|
|
698
|
-
blockhash: hash.blockhash,
|
|
699
|
-
lastValidBlockHeight: hash.lastValidBlockHeight,
|
|
700
|
-
})).add.apply(_c, __spreadArray([], __read(ixs), false));
|
|
701
|
-
return [4 /*yield*/, (0, solana_1.signAndExecuteTransaction)(this.connection, invoker, tx, hash)];
|
|
702
|
-
case 4:
|
|
703
|
-
signature = _d.sent();
|
|
792
|
+
signature = _c.sent();
|
|
704
793
|
return [2 /*return*/, { ixs: ixs, txId: signature }];
|
|
705
794
|
}
|
|
706
795
|
});
|
|
707
796
|
});
|
|
708
797
|
};
|
|
709
798
|
/**
|
|
710
|
-
*
|
|
799
|
+
* Create Transaction instructions for topup
|
|
711
800
|
*/
|
|
712
|
-
SolanaStreamClient.prototype.
|
|
801
|
+
SolanaStreamClient.prototype.prepareTopupInstructions = function (_a, _b) {
|
|
713
802
|
var id = _a.id, amount = _a.amount;
|
|
714
|
-
var invoker = _b.invoker, isNative = _b.isNative;
|
|
803
|
+
var invoker = _b.invoker, isNative = _b.isNative, computePrice = _b.computePrice, computeLimit = _b.computeLimit;
|
|
715
804
|
return __awaiter(this, void 0, void 0, function () {
|
|
716
|
-
var ixs, streamPublicKey, escrow, _c, mint, partner, senderTokens, escrowTokens, streamflowTreasuryTokens, partnerTokens,
|
|
717
|
-
|
|
718
|
-
|
|
719
|
-
switch (_f.label) {
|
|
805
|
+
var ixs, streamPublicKey, escrow, _c, mint, partner, senderTokens, escrowTokens, streamflowTreasuryTokens, partnerTokens, _d, _e, _f, _g;
|
|
806
|
+
return __generator(this, function (_h) {
|
|
807
|
+
switch (_h.label) {
|
|
720
808
|
case 0:
|
|
721
809
|
if (!invoker.publicKey) {
|
|
722
810
|
throw new Error("Invoker's PublicKey is not available, check passed wallet adapter!");
|
|
723
811
|
}
|
|
724
|
-
ixs =
|
|
812
|
+
ixs = (0, solana_1.prepareBaseInstructions)(this.connection, {
|
|
813
|
+
computePrice: computePrice,
|
|
814
|
+
computeLimit: computeLimit,
|
|
815
|
+
});
|
|
725
816
|
streamPublicKey = new web3_js_1.PublicKey(id);
|
|
726
817
|
return [4 /*yield*/, this.connection.getAccountInfo(streamPublicKey)];
|
|
727
818
|
case 1:
|
|
728
|
-
escrow =
|
|
819
|
+
escrow = _h.sent();
|
|
729
820
|
if (!(escrow === null || escrow === void 0 ? void 0 : escrow.data)) {
|
|
730
821
|
throw new Error("Couldn't get account info");
|
|
731
822
|
}
|
|
732
823
|
_c = (0, utils_1.decodeStream)(escrow === null || escrow === void 0 ? void 0 : escrow.data), mint = _c.mint, partner = _c.partner, senderTokens = _c.senderTokens, escrowTokens = _c.escrowTokens;
|
|
733
824
|
return [4 /*yield*/, (0, solana_1.ata)(mint, constants_1.STREAMFLOW_TREASURY_PUBLIC_KEY)];
|
|
734
825
|
case 2:
|
|
735
|
-
streamflowTreasuryTokens =
|
|
826
|
+
streamflowTreasuryTokens = _h.sent();
|
|
736
827
|
return [4 /*yield*/, (0, solana_1.ata)(mint, partner)];
|
|
737
828
|
case 3:
|
|
738
|
-
partnerTokens =
|
|
829
|
+
partnerTokens = _h.sent();
|
|
739
830
|
if (!isNative) return [3 /*break*/, 5];
|
|
831
|
+
_e = (_d = ixs.push).apply;
|
|
832
|
+
_f = [ixs];
|
|
833
|
+
_g = [[]];
|
|
740
834
|
return [4 /*yield*/, (0, solana_1.prepareWrappedAccount)(this.connection, invoker.publicKey, amount)];
|
|
741
835
|
case 4:
|
|
742
|
-
_d
|
|
743
|
-
|
|
836
|
+
_e.apply(_d, _f.concat([__spreadArray.apply(void 0, _g.concat([__read.apply(void 0, [(_h.sent())]), false]))]));
|
|
837
|
+
_h.label = 5;
|
|
744
838
|
case 5:
|
|
745
|
-
_d = [];
|
|
746
|
-
_f.label = 6;
|
|
747
|
-
case 6:
|
|
748
|
-
nativeInstructions = _d;
|
|
749
839
|
ixs.push((0, instructions_1.topupStreamInstruction)(amount, this.programId, {
|
|
750
840
|
sender: invoker.publicKey,
|
|
751
841
|
senderTokens: senderTokens,
|
|
@@ -760,19 +850,7 @@ var SolanaStreamClient = /** @class */ (function (_super) {
|
|
|
760
850
|
withdrawor: constants_1.WITHDRAWOR_PUBLIC_KEY,
|
|
761
851
|
systemProgram: web3_js_1.SystemProgram.programId,
|
|
762
852
|
}));
|
|
763
|
-
|
|
764
|
-
return [4 /*yield*/, this.connection.getLatestBlockhash(commitment)];
|
|
765
|
-
case 7:
|
|
766
|
-
hash = _f.sent();
|
|
767
|
-
tx = (_e = new web3_js_1.Transaction({
|
|
768
|
-
feePayer: invoker.publicKey,
|
|
769
|
-
blockhash: hash.blockhash,
|
|
770
|
-
lastValidBlockHeight: hash.lastValidBlockHeight,
|
|
771
|
-
})).add.apply(_e, __spreadArray(__spreadArray([], __read(nativeInstructions), false), __read(ixs), false));
|
|
772
|
-
return [4 /*yield*/, (0, solana_1.signAndExecuteTransaction)(this.connection, invoker, tx, hash)];
|
|
773
|
-
case 8:
|
|
774
|
-
signature = _f.sent();
|
|
775
|
-
return [2 /*return*/, { ixs: ixs, txId: signature }];
|
|
853
|
+
return [2 /*return*/, ixs];
|
|
776
854
|
}
|
|
777
855
|
});
|
|
778
856
|
});
|
|
@@ -847,10 +925,35 @@ var SolanaStreamClient = /** @class */ (function (_super) {
|
|
|
847
925
|
/**
|
|
848
926
|
* Attempts updating the stream auto withdrawal params and amount per period
|
|
849
927
|
*/
|
|
850
|
-
SolanaStreamClient.prototype.update = function (data,
|
|
851
|
-
|
|
928
|
+
SolanaStreamClient.prototype.update = function (data, extParams) {
|
|
929
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
930
|
+
var ixs, _a, tx, hash, signature;
|
|
931
|
+
return __generator(this, function (_b) {
|
|
932
|
+
switch (_b.label) {
|
|
933
|
+
case 0: return [4 /*yield*/, this.prepareUpdateInstructions(data, extParams)];
|
|
934
|
+
case 1:
|
|
935
|
+
ixs = _b.sent();
|
|
936
|
+
return [4 /*yield*/, (0, solana_1.prepareTransaction)(this.connection, ixs, extParams.invoker.publicKey)];
|
|
937
|
+
case 2:
|
|
938
|
+
_a = _b.sent(), tx = _a.tx, hash = _a.hash;
|
|
939
|
+
return [4 /*yield*/, (0, solana_1.signAndExecuteTransaction)(this.connection, extParams.invoker, tx, hash)];
|
|
940
|
+
case 3:
|
|
941
|
+
signature = _b.sent();
|
|
942
|
+
return [2 /*return*/, {
|
|
943
|
+
ixs: ixs,
|
|
944
|
+
txId: signature,
|
|
945
|
+
}];
|
|
946
|
+
}
|
|
947
|
+
});
|
|
948
|
+
});
|
|
949
|
+
};
|
|
950
|
+
/**
|
|
951
|
+
* Create Transaction instructions for update
|
|
952
|
+
*/
|
|
953
|
+
SolanaStreamClient.prototype.prepareUpdateInstructions = function (data, _a) {
|
|
954
|
+
var invoker = _a.invoker, computePrice = _a.computePrice, computeLimit = _a.computeLimit;
|
|
852
955
|
return __awaiter(this, void 0, void 0, function () {
|
|
853
|
-
var streamPublicKey, escrow,
|
|
956
|
+
var streamPublicKey, escrow, ixs;
|
|
854
957
|
return __generator(this, function (_b) {
|
|
855
958
|
switch (_b.label) {
|
|
856
959
|
case 0:
|
|
@@ -864,28 +967,17 @@ var SolanaStreamClient = /** @class */ (function (_super) {
|
|
|
864
967
|
if (!escrow) {
|
|
865
968
|
throw new Error("Couldn't get account info");
|
|
866
969
|
}
|
|
867
|
-
|
|
970
|
+
ixs = (0, solana_1.prepareBaseInstructions)(this.connection, {
|
|
971
|
+
computePrice: computePrice,
|
|
972
|
+
computeLimit: computeLimit,
|
|
973
|
+
});
|
|
974
|
+
ixs.push((0, instructions_1.updateStreamInstruction)(data, this.programId, {
|
|
868
975
|
authority: invoker.publicKey,
|
|
869
976
|
metadata: streamPublicKey,
|
|
870
977
|
withdrawor: constants_1.WITHDRAWOR_PUBLIC_KEY,
|
|
871
978
|
systemProgram: web3_js_1.SystemProgram.programId,
|
|
872
|
-
});
|
|
873
|
-
|
|
874
|
-
return [4 /*yield*/, this.connection.getLatestBlockhash(commitment)];
|
|
875
|
-
case 2:
|
|
876
|
-
hash = _b.sent();
|
|
877
|
-
tx = new web3_js_1.Transaction({
|
|
878
|
-
feePayer: invoker.publicKey,
|
|
879
|
-
blockhash: hash.blockhash,
|
|
880
|
-
lastValidBlockHeight: hash.lastValidBlockHeight,
|
|
881
|
-
}).add(updateIx);
|
|
882
|
-
return [4 /*yield*/, (0, solana_1.signAndExecuteTransaction)(this.connection, invoker, tx, hash)];
|
|
883
|
-
case 3:
|
|
884
|
-
signature = _b.sent();
|
|
885
|
-
return [2 /*return*/, {
|
|
886
|
-
ixs: [updateIx],
|
|
887
|
-
txId: signature,
|
|
888
|
-
}];
|
|
979
|
+
}));
|
|
980
|
+
return [2 /*return*/, ixs];
|
|
889
981
|
}
|
|
890
982
|
});
|
|
891
983
|
});
|
|
@@ -931,18 +1023,21 @@ var SolanaStreamClient = /** @class */ (function (_super) {
|
|
|
931
1023
|
/**
|
|
932
1024
|
* Forms instructions from params, creates a raw transaction and fetch recent blockhash.
|
|
933
1025
|
*/
|
|
934
|
-
SolanaStreamClient.prototype.prepareStreamInstructions = function (recipient, streamParams,
|
|
1026
|
+
SolanaStreamClient.prototype.prepareStreamInstructions = function (recipient, streamParams, extParams) {
|
|
935
1027
|
return __awaiter(this, void 0, void 0, function () {
|
|
936
|
-
var mint, start, period, cliff, canTopup, cancelableBySender, cancelableByRecipient, transferableBySender, transferableByRecipient, _a, automaticWithdrawal, _b, withdrawalFrequency, partner, sender, metadataPubKeys, ixs, recipientPublicKey, mintPublicKey, _c, metadata, metadataPubKey, _d, escrowTokens, senderTokens, recipientTokens, streamflowTreasuryTokens, partnerPublicKey, partnerTokens;
|
|
1028
|
+
var mint, start, period, cliff, canTopup, cancelableBySender, cancelableByRecipient, transferableBySender, transferableByRecipient, _a, automaticWithdrawal, _b, withdrawalFrequency, partner, sender, metadataPubKeys, computeLimit, computePrice, ixs, recipientPublicKey, mintPublicKey, _c, metadata, metadataPubKey, _d, escrowTokens, senderTokens, recipientTokens, streamflowTreasuryTokens, partnerPublicKey, partnerTokens;
|
|
937
1029
|
return __generator(this, function (_e) {
|
|
938
1030
|
switch (_e.label) {
|
|
939
1031
|
case 0:
|
|
940
1032
|
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;
|
|
941
|
-
sender =
|
|
1033
|
+
sender = extParams.sender, metadataPubKeys = extParams.metadataPubKeys, computeLimit = extParams.computeLimit, computePrice = extParams.computePrice;
|
|
942
1034
|
if (!sender.publicKey) {
|
|
943
1035
|
throw new Error("Sender's PublicKey is not available, check passed wallet adapter!");
|
|
944
1036
|
}
|
|
945
|
-
ixs =
|
|
1037
|
+
ixs = (0, solana_1.prepareBaseInstructions)(this.connection, {
|
|
1038
|
+
computePrice: computePrice,
|
|
1039
|
+
computeLimit: computeLimit,
|
|
1040
|
+
});
|
|
946
1041
|
recipientPublicKey = new web3_js_1.PublicKey(recipient.recipient);
|
|
947
1042
|
mintPublicKey = new web3_js_1.PublicKey(mint);
|
|
948
1043
|
_c = this.getOrCreateStreamMetadata(metadataPubKeys), metadata = _c.metadata, metadataPubKey = _c.metadataPubKey;
|
|
@@ -1000,6 +1095,21 @@ var SolanaStreamClient = /** @class */ (function (_super) {
|
|
|
1000
1095
|
});
|
|
1001
1096
|
});
|
|
1002
1097
|
};
|
|
1098
|
+
/**
|
|
1099
|
+
* Utility function to generate metadata for a Contract or return existing Pubkey
|
|
1100
|
+
*/
|
|
1101
|
+
SolanaStreamClient.prototype.getOrCreateStreamMetadata = function (metadataPubKeys) {
|
|
1102
|
+
var metadata;
|
|
1103
|
+
var metadataPubKey;
|
|
1104
|
+
if (!metadataPubKeys) {
|
|
1105
|
+
metadata = web3_js_1.Keypair.generate();
|
|
1106
|
+
metadataPubKey = metadata.publicKey;
|
|
1107
|
+
}
|
|
1108
|
+
else {
|
|
1109
|
+
metadataPubKey = metadataPubKeys[0];
|
|
1110
|
+
}
|
|
1111
|
+
return { metadata: metadata, metadataPubKey: metadataPubKey };
|
|
1112
|
+
};
|
|
1003
1113
|
/**
|
|
1004
1114
|
* Utility function that checks whether associated token accounts still exist and adds instructions to add them if not
|
|
1005
1115
|
*/
|
|
@@ -1030,21 +1140,6 @@ var SolanaStreamClient = /** @class */ (function (_super) {
|
|
|
1030
1140
|
});
|
|
1031
1141
|
});
|
|
1032
1142
|
};
|
|
1033
|
-
/**
|
|
1034
|
-
* Utility function to generate metadata for a Contract or return existing Pubkey
|
|
1035
|
-
*/
|
|
1036
|
-
SolanaStreamClient.prototype.getOrCreateStreamMetadata = function (metadataPubKeys) {
|
|
1037
|
-
var metadata;
|
|
1038
|
-
var metadataPubKey;
|
|
1039
|
-
if (!metadataPubKeys) {
|
|
1040
|
-
metadata = web3_js_1.Keypair.generate();
|
|
1041
|
-
metadataPubKey = metadata.publicKey;
|
|
1042
|
-
}
|
|
1043
|
-
else {
|
|
1044
|
-
metadataPubKey = metadataPubKeys[0];
|
|
1045
|
-
}
|
|
1046
|
-
return { metadata: metadata, metadataPubKey: metadataPubKey };
|
|
1047
|
-
};
|
|
1048
1143
|
return SolanaStreamClient;
|
|
1049
1144
|
}(BaseStreamClient_1.BaseStreamClient));
|
|
1050
1145
|
exports.default = SolanaStreamClient;
|