@streamflow/stream 5.10.4 → 5.11.0
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 +55 -10
- package/dist/solana/StreamClient.js +301 -192
- package/dist/solana/types.d.ts +10 -0
- package/dist/solana/utils.d.ts +14 -1
- package/dist/solana/utils.js +63 -10
- package/dist/sui/StreamClient.d.ts +1 -1
- package/dist/sui/StreamClient.js +9 -7
- package/package.json +2 -2
|
@@ -137,6 +137,7 @@ var instructions_1 = require("./instructions");
|
|
|
137
137
|
var types_2 = require("../common/types");
|
|
138
138
|
var BaseStreamClient_1 = require("../common/BaseStreamClient");
|
|
139
139
|
var utils_2 = require("../common/utils");
|
|
140
|
+
var constants_2 = require("../common/constants");
|
|
140
141
|
var METADATA_ACC_SIZE = 1104;
|
|
141
142
|
var SolanaStreamClient = /** @class */ (function (_super) {
|
|
142
143
|
__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,48 +168,73 @@ 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, extensions) {
|
|
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, extensions)];
|
|
177
|
+
case 1:
|
|
178
|
+
_a = _c.sent(), ixs = _a.ixs, metadata = _a.metadata, metadataPubKey = _a.metadataPubKey;
|
|
179
|
+
return [4 /*yield*/, (0, utils_1.prepareTransaction)(this.connection, ixs, extensions.sender.publicKey, this.getCommitment(), metadata)];
|
|
180
|
+
case 2:
|
|
181
|
+
_b = _c.sent(), tx = _b.tx, hash = _b.hash;
|
|
182
|
+
return [4 /*yield*/, (0, utils_1.signAndExecuteTransaction)(this.connection, extensions.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 = this.prepareBaseInstructions({
|
|
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, utils_1.ata)(mintPublicKey, sender.publicKey)];
|
|
185
214
|
case 1:
|
|
186
|
-
senderTokens =
|
|
215
|
+
senderTokens = _m.sent();
|
|
187
216
|
return [4 /*yield*/, (0, utils_1.ata)(mintPublicKey, recipientPublicKey)];
|
|
188
217
|
case 2:
|
|
189
|
-
recipientTokens =
|
|
218
|
+
recipientTokens = _m.sent();
|
|
190
219
|
return [4 /*yield*/, (0, utils_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, utils_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({ address: partner !== null && partner !== void 0 ? partner : sender.publicKey.toBase58() })];
|
|
199
228
|
case 5:
|
|
200
|
-
totalFee =
|
|
229
|
+
totalFee = _m.sent();
|
|
201
230
|
totalAmount = (0, utils_2.calculateTotalAmountToDeposit)(depositedAmount, totalFee);
|
|
202
231
|
_j = (_h = ixs.push).apply;
|
|
203
232
|
_k = [ixs];
|
|
204
233
|
_l = [[]];
|
|
205
234
|
return [4 /*yield*/, (0, instructions_1.prepareWrappedAccount)(this.connection, sender.publicKey, totalAmount)];
|
|
206
235
|
case 6:
|
|
207
|
-
_j.apply(_h, _k.concat([__spreadArray.apply(void 0, _l.concat([__read.apply(void 0, [(
|
|
208
|
-
|
|
236
|
+
_j.apply(_h, _k.concat([__spreadArray.apply(void 0, _l.concat([__read.apply(void 0, [(_m.sent())]), false]))]));
|
|
237
|
+
_m.label = 7;
|
|
209
238
|
case 7:
|
|
210
239
|
ixs.push((0, instructions_1.createStreamInstruction)({
|
|
211
240
|
start: new bn_js_1.default(start),
|
|
@@ -242,22 +271,7 @@ var SolanaStreamClient = /** @class */ (function (_super) {
|
|
|
242
271
|
withdrawor: constants_1.WITHDRAWOR_PUBLIC_KEY,
|
|
243
272
|
systemProgram: web3_js_1.SystemProgram.programId,
|
|
244
273
|
}));
|
|
245
|
-
|
|
246
|
-
return [4 /*yield*/, this.connection.getLatestBlockhash(commitment)];
|
|
247
|
-
case 8:
|
|
248
|
-
hash = _o.sent();
|
|
249
|
-
tx = (_m = new web3_js_1.Transaction({
|
|
250
|
-
feePayer: sender.publicKey,
|
|
251
|
-
blockhash: hash.blockhash,
|
|
252
|
-
lastValidBlockHeight: hash.lastValidBlockHeight,
|
|
253
|
-
})).add.apply(_m, __spreadArray([], __read(ixs), false));
|
|
254
|
-
if (metadata) {
|
|
255
|
-
tx.partialSign(metadata);
|
|
256
|
-
}
|
|
257
|
-
return [4 /*yield*/, (0, utils_1.signAndExecuteTransaction)(this.connection, sender, tx, hash)];
|
|
258
|
-
case 9:
|
|
259
|
-
signature = _o.sent();
|
|
260
|
-
return [2 /*return*/, { ixs: ixs, txId: signature, metadataId: metadataPubKey.toBase58() }];
|
|
274
|
+
return [2 /*return*/, { ixs: ixs, metadata: metadata, metadataPubKey: metadataPubKey }];
|
|
261
275
|
}
|
|
262
276
|
});
|
|
263
277
|
});
|
|
@@ -272,14 +286,35 @@ var SolanaStreamClient = /** @class */ (function (_super) {
|
|
|
272
286
|
*
|
|
273
287
|
* If you are not sure if you should use create or create_unchecked, go for create to be safer.
|
|
274
288
|
*/
|
|
275
|
-
SolanaStreamClient.prototype.createUnchecked = function (
|
|
289
|
+
SolanaStreamClient.prototype.createUnchecked = function (data, extensions) {
|
|
290
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
291
|
+
var _a, ixs, metadata, metadataPubKey, _b, tx, hash, signature;
|
|
292
|
+
return __generator(this, function (_c) {
|
|
293
|
+
switch (_c.label) {
|
|
294
|
+
case 0: return [4 /*yield*/, this.prepareCreateUncheckedInstructions(data, extensions)];
|
|
295
|
+
case 1:
|
|
296
|
+
_a = _c.sent(), ixs = _a.ixs, metadata = _a.metadata, metadataPubKey = _a.metadataPubKey;
|
|
297
|
+
return [4 /*yield*/, (0, utils_1.prepareTransaction)(this.connection, ixs, extensions.sender.publicKey, this.getCommitment(), metadata)];
|
|
298
|
+
case 2:
|
|
299
|
+
_b = _c.sent(), tx = _b.tx, hash = _b.hash;
|
|
300
|
+
return [4 /*yield*/, (0, utils_1.signAndExecuteTransaction)(this.connection, extensions.sender, tx, hash)];
|
|
301
|
+
case 3:
|
|
302
|
+
signature = _c.sent();
|
|
303
|
+
return [2 /*return*/, { ixs: ixs, txId: signature, metadataId: metadataPubKey.toBase58() }];
|
|
304
|
+
}
|
|
305
|
+
});
|
|
306
|
+
});
|
|
307
|
+
};
|
|
308
|
+
/**
|
|
309
|
+
* Create Transaction instructions for `createUnchecked`
|
|
310
|
+
*/
|
|
311
|
+
SolanaStreamClient.prototype.prepareCreateUncheckedInstructions = function (_a, _b) {
|
|
276
312
|
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;
|
|
277
|
-
var sender = _b.sender, metadataPubKeys = _b.metadataPubKeys, _e = _b.isNative, isNative = _e === void 0 ? false : _e;
|
|
313
|
+
var sender = _b.sender, metadataPubKeys = _b.metadataPubKeys, _e = _b.isNative, isNative = _e === void 0 ? false : _e, computePrice = _b.computePrice, computeLimit = _b.computeLimit;
|
|
278
314
|
return __awaiter(this, void 0, void 0, function () {
|
|
279
|
-
var mintPublicKey, recipientPublicKey, _f, metadata, metadataPubKey, rentToExempt, createMetadataInstruction, _g, escrowTokens, senderTokens, partnerPublicKey,
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
switch (_k.label) {
|
|
315
|
+
var mintPublicKey, recipientPublicKey, _f, metadata, metadataPubKey, rentToExempt, createMetadataInstruction, _g, escrowTokens, senderTokens, partnerPublicKey, ixs, totalFee, totalAmount, _h, _j, _k, _l, createInstruction;
|
|
316
|
+
return __generator(this, function (_m) {
|
|
317
|
+
switch (_m.label) {
|
|
283
318
|
case 0:
|
|
284
319
|
if (!sender.publicKey) {
|
|
285
320
|
throw new Error("Sender's PublicKey is not available, check passed wallet adapter!");
|
|
@@ -289,7 +324,7 @@ var SolanaStreamClient = /** @class */ (function (_super) {
|
|
|
289
324
|
_f = this.getOrCreateStreamMetadata(metadataPubKeys), metadata = _f.metadata, metadataPubKey = _f.metadataPubKey;
|
|
290
325
|
return [4 /*yield*/, this.connection.getMinimumBalanceForRentExemption(METADATA_ACC_SIZE)];
|
|
291
326
|
case 1:
|
|
292
|
-
rentToExempt =
|
|
327
|
+
rentToExempt = _m.sent();
|
|
293
328
|
createMetadataInstruction = web3_js_1.SystemProgram.createAccount({
|
|
294
329
|
programId: this.programId,
|
|
295
330
|
space: METADATA_ACC_SIZE,
|
|
@@ -300,18 +335,25 @@ var SolanaStreamClient = /** @class */ (function (_super) {
|
|
|
300
335
|
_g = __read(web3_js_1.PublicKey.findProgramAddressSync([buffer_1.Buffer.from("strm"), metadataPubKey.toBuffer()], this.programId), 1), escrowTokens = _g[0];
|
|
301
336
|
return [4 /*yield*/, (0, utils_1.ata)(mintPublicKey, sender.publicKey)];
|
|
302
337
|
case 2:
|
|
303
|
-
senderTokens =
|
|
338
|
+
senderTokens = _m.sent();
|
|
304
339
|
partnerPublicKey = partner ? new web3_js_1.PublicKey(partner) : constants_1.STREAMFLOW_TREASURY_PUBLIC_KEY;
|
|
305
|
-
|
|
306
|
-
|
|
340
|
+
ixs = this.prepareBaseInstructions({
|
|
341
|
+
computePrice: computePrice,
|
|
342
|
+
computeLimit: computeLimit,
|
|
343
|
+
});
|
|
344
|
+
if (!isNative) return [3 /*break*/, 5];
|
|
345
|
+
return [4 /*yield*/, this.getTotalFee({ address: partner !== null && partner !== void 0 ? partner : sender.publicKey.toBase58() })];
|
|
307
346
|
case 3:
|
|
308
|
-
|
|
309
|
-
|
|
347
|
+
totalFee = _m.sent();
|
|
348
|
+
totalAmount = (0, utils_2.calculateTotalAmountToDeposit)(depositedAmount, totalFee);
|
|
349
|
+
_j = (_h = ixs.push).apply;
|
|
350
|
+
_k = [ixs];
|
|
351
|
+
_l = [[]];
|
|
352
|
+
return [4 /*yield*/, (0, instructions_1.prepareWrappedAccount)(this.connection, sender.publicKey, totalAmount)];
|
|
310
353
|
case 4:
|
|
311
|
-
_h
|
|
312
|
-
|
|
354
|
+
_j.apply(_h, _k.concat([__spreadArray.apply(void 0, _l.concat([__read.apply(void 0, [(_m.sent())]), false]))]));
|
|
355
|
+
_m.label = 5;
|
|
313
356
|
case 5:
|
|
314
|
-
nativeInstructions = _h;
|
|
315
357
|
createInstruction = (0, instructions_1.createUncheckedStreamInstruction)({
|
|
316
358
|
start: new bn_js_1.default(start),
|
|
317
359
|
depositedAmount: depositedAmount,
|
|
@@ -342,23 +384,8 @@ var SolanaStreamClient = /** @class */ (function (_super) {
|
|
|
342
384
|
withdrawor: constants_1.WITHDRAWOR_PUBLIC_KEY,
|
|
343
385
|
systemProgram: web3_js_1.SystemProgram.programId,
|
|
344
386
|
});
|
|
345
|
-
|
|
346
|
-
ixs
|
|
347
|
-
return [4 /*yield*/, this.connection.getLatestBlockhash(commitment)];
|
|
348
|
-
case 6:
|
|
349
|
-
hash = _k.sent();
|
|
350
|
-
tx = (_j = new web3_js_1.Transaction({
|
|
351
|
-
feePayer: sender.publicKey,
|
|
352
|
-
blockhash: hash.blockhash,
|
|
353
|
-
lastValidBlockHeight: hash.lastValidBlockHeight,
|
|
354
|
-
})).add.apply(_j, __spreadArray(__spreadArray([], __read(nativeInstructions), false), __read(ixs), false));
|
|
355
|
-
if (metadata) {
|
|
356
|
-
tx.partialSign(metadata);
|
|
357
|
-
}
|
|
358
|
-
return [4 /*yield*/, (0, utils_1.signAndExecuteTransaction)(this.connection, sender, tx, hash)];
|
|
359
|
-
case 7:
|
|
360
|
-
signature = _k.sent();
|
|
361
|
-
return [2 /*return*/, { ixs: ixs, txId: signature, metadataId: metadataPubKey.toBase58() }];
|
|
387
|
+
ixs.push(createMetadataInstruction, createInstruction);
|
|
388
|
+
return [2 /*return*/, { ixs: ixs, metadata: metadata, metadataPubKey: metadataPubKey }];
|
|
362
389
|
}
|
|
363
390
|
});
|
|
364
391
|
});
|
|
@@ -370,7 +397,7 @@ var SolanaStreamClient = /** @class */ (function (_super) {
|
|
|
370
397
|
SolanaStreamClient.prototype.createMultiple = function (data, _a) {
|
|
371
398
|
var sender = _a.sender, metadataPubKeys = _a.metadataPubKeys, _b = _a.isNative, isNative = _b === void 0 ? false : _b;
|
|
372
399
|
return __awaiter(this, void 0, void 0, function () {
|
|
373
|
-
var recipients, metadatas, metadataToRecipient, errors, signatures, batch, instructionsBatch, i, recipientData, _c, ixs, metadata, metadataPubKey, commitment, hash, instructionsBatch_1, instructionsBatch_1_1, _d, ixs, metadata, recipient, tx, totalDepositedAmount, nativeInstructions,
|
|
400
|
+
var recipients, metadatas, metadataToRecipient, errors, signatures, batch, instructionsBatch, i, recipientData, _c, ixs, metadata, metadataPubKey, commitment, hash, instructionsBatch_1, instructionsBatch_1_1, _d, ixs, metadata, recipient, tx, totalDepositedAmount, nativeInstructions, prepareTransaction_1, signedBatch, prepareTx, responses, signedBatch_1, signedBatch_1_1, batchTx, _e, _f, _g, _h, e_1_1, batchTransactionsCalls, _j, _k, _l, _m, successes, failures;
|
|
374
401
|
var e_2, _o, _p, _q, e_1, _r;
|
|
375
402
|
var _this = this;
|
|
376
403
|
return __generator(this, function (_s) {
|
|
@@ -436,12 +463,12 @@ var SolanaStreamClient = /** @class */ (function (_super) {
|
|
|
436
463
|
return [4 /*yield*/, (0, instructions_1.prepareWrappedAccount)(this.connection, sender.publicKey, totalDepositedAmount)];
|
|
437
464
|
case 6:
|
|
438
465
|
nativeInstructions = _s.sent();
|
|
439
|
-
|
|
466
|
+
prepareTransaction_1 = (_q = new web3_js_1.Transaction({
|
|
440
467
|
feePayer: sender.publicKey,
|
|
441
468
|
blockhash: hash.blockhash,
|
|
442
469
|
lastValidBlockHeight: hash.lastValidBlockHeight,
|
|
443
470
|
})).add.apply(_q, __spreadArray([], __read(nativeInstructions), false));
|
|
444
|
-
batch.push({ tx:
|
|
471
|
+
batch.push({ tx: prepareTransaction_1, recipient: sender.publicKey.toBase58() });
|
|
445
472
|
_s.label = 7;
|
|
446
473
|
case 7: return [4 /*yield*/, (0, utils_1.signAllTransactionWithRecipients)(sender, batch)];
|
|
447
474
|
case 8:
|
|
@@ -519,18 +546,44 @@ var SolanaStreamClient = /** @class */ (function (_super) {
|
|
|
519
546
|
* Attempts withdrawing from the specified stream.
|
|
520
547
|
*/
|
|
521
548
|
SolanaStreamClient.prototype.withdraw = function (_a, _b) {
|
|
522
|
-
var id = _a.id,
|
|
549
|
+
var id = _a.id, _c = _a.amount, amount = _c === void 0 ? constants_2.WITHDRAW_AVAILABLE_AMOUNT : _c;
|
|
523
550
|
var invoker = _b.invoker, checkTokenAccounts = _b.checkTokenAccounts;
|
|
524
551
|
return __awaiter(this, void 0, void 0, function () {
|
|
525
|
-
var ixs,
|
|
526
|
-
|
|
552
|
+
var ixs, _d, tx, hash, signature;
|
|
553
|
+
return __generator(this, function (_e) {
|
|
554
|
+
switch (_e.label) {
|
|
555
|
+
case 0: return [4 /*yield*/, this.prepareWithdawInstructions({ id: id, amount: amount }, { invoker: invoker, checkTokenAccounts: checkTokenAccounts })];
|
|
556
|
+
case 1:
|
|
557
|
+
ixs = _e.sent();
|
|
558
|
+
return [4 /*yield*/, (0, utils_1.prepareTransaction)(this.connection, ixs, invoker.publicKey, this.getCommitment())];
|
|
559
|
+
case 2:
|
|
560
|
+
_d = _e.sent(), tx = _d.tx, hash = _d.hash;
|
|
561
|
+
return [4 /*yield*/, (0, utils_1.signAndExecuteTransaction)(this.connection, invoker, tx, hash)];
|
|
562
|
+
case 3:
|
|
563
|
+
signature = _e.sent();
|
|
564
|
+
return [2 /*return*/, { ixs: ixs, txId: signature }];
|
|
565
|
+
}
|
|
566
|
+
});
|
|
567
|
+
});
|
|
568
|
+
};
|
|
569
|
+
/**
|
|
570
|
+
* Creates Transaction Instructions for withdrawal
|
|
571
|
+
*/
|
|
572
|
+
SolanaStreamClient.prototype.prepareWithdawInstructions = function (_a, _b) {
|
|
573
|
+
var id = _a.id, _c = _a.amount, amount = _c === void 0 ? constants_2.WITHDRAW_AVAILABLE_AMOUNT : _c;
|
|
574
|
+
var invoker = _b.invoker, checkTokenAccounts = _b.checkTokenAccounts, computePrice = _b.computePrice, computeLimit = _b.computeLimit;
|
|
575
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
576
|
+
var ixs, streamPublicKey, escrow, data, streamflowTreasuryTokens, partnerTokens;
|
|
527
577
|
return __generator(this, function (_d) {
|
|
528
578
|
switch (_d.label) {
|
|
529
579
|
case 0:
|
|
530
580
|
if (!invoker.publicKey) {
|
|
531
581
|
throw new Error("Invoker's PublicKey is not available, check passed wallet adapter!");
|
|
532
582
|
}
|
|
533
|
-
ixs =
|
|
583
|
+
ixs = this.prepareBaseInstructions({
|
|
584
|
+
computePrice: computePrice,
|
|
585
|
+
computeLimit: computeLimit,
|
|
586
|
+
});
|
|
534
587
|
streamPublicKey = new web3_js_1.PublicKey(id);
|
|
535
588
|
return [4 /*yield*/, this.connection.getAccountInfo(streamPublicKey)];
|
|
536
589
|
case 1:
|
|
@@ -561,19 +614,7 @@ var SolanaStreamClient = /** @class */ (function (_super) {
|
|
|
561
614
|
mint: data.mint,
|
|
562
615
|
tokenProgram: spl_token_1.TOKEN_PROGRAM_ID,
|
|
563
616
|
}));
|
|
564
|
-
|
|
565
|
-
return [4 /*yield*/, this.connection.getLatestBlockhash(commitment)];
|
|
566
|
-
case 5:
|
|
567
|
-
hash = _d.sent();
|
|
568
|
-
tx = (_c = new web3_js_1.Transaction({
|
|
569
|
-
feePayer: invoker.publicKey,
|
|
570
|
-
blockhash: hash.blockhash,
|
|
571
|
-
lastValidBlockHeight: hash.lastValidBlockHeight,
|
|
572
|
-
})).add.apply(_c, __spreadArray([], __read(ixs), false));
|
|
573
|
-
return [4 /*yield*/, (0, utils_1.signAndExecuteTransaction)(this.connection, invoker, tx, hash)];
|
|
574
|
-
case 6:
|
|
575
|
-
signature = _d.sent();
|
|
576
|
-
return [2 /*return*/, { ixs: ixs, txId: signature }];
|
|
617
|
+
return [2 /*return*/, ixs];
|
|
577
618
|
}
|
|
578
619
|
});
|
|
579
620
|
});
|
|
@@ -581,14 +622,36 @@ var SolanaStreamClient = /** @class */ (function (_super) {
|
|
|
581
622
|
/**
|
|
582
623
|
* Attempts canceling the specified stream.
|
|
583
624
|
*/
|
|
584
|
-
SolanaStreamClient.prototype.cancel = function (_a,
|
|
625
|
+
SolanaStreamClient.prototype.cancel = function (_a, extensions) {
|
|
585
626
|
var id = _a.id;
|
|
586
|
-
var invoker = _b.invoker, checkTokenAccounts = _b.checkTokenAccounts;
|
|
587
627
|
return __awaiter(this, void 0, void 0, function () {
|
|
588
|
-
var
|
|
589
|
-
|
|
590
|
-
|
|
591
|
-
|
|
628
|
+
var ixs, _b, tx, hash, signature;
|
|
629
|
+
return __generator(this, function (_c) {
|
|
630
|
+
switch (_c.label) {
|
|
631
|
+
case 0: return [4 /*yield*/, this.prepareCancelInstructions({ id: id }, extensions)];
|
|
632
|
+
case 1:
|
|
633
|
+
ixs = _c.sent();
|
|
634
|
+
return [4 /*yield*/, (0, utils_1.prepareTransaction)(this.connection, ixs, extensions.invoker.publicKey, this.getCommitment())];
|
|
635
|
+
case 2:
|
|
636
|
+
_b = _c.sent(), tx = _b.tx, hash = _b.hash;
|
|
637
|
+
return [4 /*yield*/, (0, utils_1.signAndExecuteTransaction)(this.connection, extensions.invoker, tx, hash)];
|
|
638
|
+
case 3:
|
|
639
|
+
signature = _c.sent();
|
|
640
|
+
return [2 /*return*/, { ixs: ixs, txId: signature }];
|
|
641
|
+
}
|
|
642
|
+
});
|
|
643
|
+
});
|
|
644
|
+
};
|
|
645
|
+
/**
|
|
646
|
+
* Creates Transaction Instructions for cancel
|
|
647
|
+
*/
|
|
648
|
+
SolanaStreamClient.prototype.prepareCancelInstructions = function (_a, _b) {
|
|
649
|
+
var id = _a.id;
|
|
650
|
+
var invoker = _b.invoker, checkTokenAccounts = _b.checkTokenAccounts, computePrice = _b.computePrice, computeLimit = _b.computeLimit;
|
|
651
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
652
|
+
var streamPublicKey, escrowAcc, data, streamflowTreasuryTokens, partnerTokens, ixs;
|
|
653
|
+
return __generator(this, function (_c) {
|
|
654
|
+
switch (_c.label) {
|
|
592
655
|
case 0:
|
|
593
656
|
if (!invoker.publicKey) {
|
|
594
657
|
throw new Error("Invoker's PublicKey is not available, check passed wallet adapter!");
|
|
@@ -596,21 +659,24 @@ var SolanaStreamClient = /** @class */ (function (_super) {
|
|
|
596
659
|
streamPublicKey = new web3_js_1.PublicKey(id);
|
|
597
660
|
return [4 /*yield*/, this.connection.getAccountInfo(streamPublicKey)];
|
|
598
661
|
case 1:
|
|
599
|
-
escrowAcc =
|
|
662
|
+
escrowAcc = _c.sent();
|
|
600
663
|
if (!(escrowAcc === null || escrowAcc === void 0 ? void 0 : escrowAcc.data)) {
|
|
601
664
|
throw new Error("Couldn't get account info");
|
|
602
665
|
}
|
|
603
666
|
data = (0, utils_1.decodeStream)(escrowAcc === null || escrowAcc === void 0 ? void 0 : escrowAcc.data);
|
|
604
667
|
return [4 /*yield*/, (0, utils_1.ata)(data.mint, constants_1.STREAMFLOW_TREASURY_PUBLIC_KEY)];
|
|
605
668
|
case 2:
|
|
606
|
-
streamflowTreasuryTokens =
|
|
669
|
+
streamflowTreasuryTokens = _c.sent();
|
|
607
670
|
return [4 /*yield*/, (0, utils_1.ata)(data.mint, data.partner)];
|
|
608
671
|
case 3:
|
|
609
|
-
partnerTokens =
|
|
610
|
-
ixs =
|
|
672
|
+
partnerTokens = _c.sent();
|
|
673
|
+
ixs = this.prepareBaseInstructions({
|
|
674
|
+
computePrice: computePrice,
|
|
675
|
+
computeLimit: computeLimit,
|
|
676
|
+
});
|
|
611
677
|
return [4 /*yield*/, this.checkAssociatedTokenAccounts(data, { invoker: invoker, checkTokenAccounts: checkTokenAccounts }, ixs)];
|
|
612
678
|
case 4:
|
|
613
|
-
|
|
679
|
+
_c.sent();
|
|
614
680
|
ixs.push((0, instructions_1.cancelStreamInstruction)(this.programId, {
|
|
615
681
|
authority: invoker.publicKey,
|
|
616
682
|
sender: data.sender,
|
|
@@ -626,18 +692,30 @@ var SolanaStreamClient = /** @class */ (function (_super) {
|
|
|
626
692
|
mint: data.mint,
|
|
627
693
|
tokenProgram: spl_token_1.TOKEN_PROGRAM_ID,
|
|
628
694
|
}));
|
|
629
|
-
|
|
630
|
-
|
|
631
|
-
|
|
632
|
-
|
|
633
|
-
|
|
634
|
-
|
|
635
|
-
|
|
636
|
-
|
|
637
|
-
|
|
638
|
-
|
|
639
|
-
|
|
640
|
-
|
|
695
|
+
return [2 /*return*/, ixs];
|
|
696
|
+
}
|
|
697
|
+
});
|
|
698
|
+
});
|
|
699
|
+
};
|
|
700
|
+
/**
|
|
701
|
+
* Attempts changing the stream/vesting contract's recipient (effectively transferring the stream/vesting contract).
|
|
702
|
+
* Potential associated token account rent fee (to make it rent-exempt) is paid by the transaction initiator.
|
|
703
|
+
*/
|
|
704
|
+
SolanaStreamClient.prototype.transfer = function (_a, extensions) {
|
|
705
|
+
var id = _a.id, newRecipient = _a.newRecipient;
|
|
706
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
707
|
+
var ixs, _b, tx, hash, signature;
|
|
708
|
+
return __generator(this, function (_c) {
|
|
709
|
+
switch (_c.label) {
|
|
710
|
+
case 0: return [4 /*yield*/, this.prepareTransferInstructions({ id: id, newRecipient: newRecipient }, extensions)];
|
|
711
|
+
case 1:
|
|
712
|
+
ixs = _c.sent();
|
|
713
|
+
return [4 /*yield*/, (0, utils_1.prepareTransaction)(this.connection, ixs, extensions.invoker.publicKey, this.getCommitment())];
|
|
714
|
+
case 2:
|
|
715
|
+
_b = _c.sent(), tx = _b.tx, hash = _b.hash;
|
|
716
|
+
return [4 /*yield*/, (0, utils_1.signAndExecuteTransaction)(this.connection, extensions.invoker, tx, hash)];
|
|
717
|
+
case 3:
|
|
718
|
+
signature = _c.sent();
|
|
641
719
|
return [2 /*return*/, { ixs: ixs, txId: signature }];
|
|
642
720
|
}
|
|
643
721
|
});
|
|
@@ -647,21 +725,23 @@ var SolanaStreamClient = /** @class */ (function (_super) {
|
|
|
647
725
|
* Attempts changing the stream/vesting contract's recipient (effectively transferring the stream/vesting contract).
|
|
648
726
|
* Potential associated token account rent fee (to make it rent-exempt) is paid by the transaction initiator.
|
|
649
727
|
*/
|
|
650
|
-
SolanaStreamClient.prototype.
|
|
651
|
-
var id = _a.id,
|
|
652
|
-
var invoker = _b.invoker;
|
|
728
|
+
SolanaStreamClient.prototype.prepareTransferInstructions = function (_a, _b) {
|
|
729
|
+
var id = _a.id, newRecipient = _a.newRecipient;
|
|
730
|
+
var invoker = _b.invoker, computePrice = _b.computePrice, _c = _b.computeLimit, computeLimit = _c === void 0 ? 100001 : _c;
|
|
653
731
|
return __awaiter(this, void 0, void 0, function () {
|
|
654
|
-
var ixs, stream,
|
|
655
|
-
var _c;
|
|
732
|
+
var ixs, stream, newRecipientPublicKey, escrow, mint, newRecipientTokens;
|
|
656
733
|
return __generator(this, function (_d) {
|
|
657
734
|
switch (_d.label) {
|
|
658
735
|
case 0:
|
|
659
736
|
if (!invoker.publicKey) {
|
|
660
737
|
throw new Error("Invoker's PublicKey is not available, check passed wallet adapter!");
|
|
661
738
|
}
|
|
662
|
-
ixs =
|
|
739
|
+
ixs = this.prepareBaseInstructions({
|
|
740
|
+
computePrice: computePrice,
|
|
741
|
+
computeLimit: computeLimit,
|
|
742
|
+
});
|
|
663
743
|
stream = new web3_js_1.PublicKey(id);
|
|
664
|
-
|
|
744
|
+
newRecipientPublicKey = new web3_js_1.PublicKey(newRecipient);
|
|
665
745
|
return [4 /*yield*/, this.connection.getAccountInfo(stream)];
|
|
666
746
|
case 1:
|
|
667
747
|
escrow = _d.sent();
|
|
@@ -669,13 +749,12 @@ var SolanaStreamClient = /** @class */ (function (_super) {
|
|
|
669
749
|
throw new Error("Couldn't get account info");
|
|
670
750
|
}
|
|
671
751
|
mint = (0, utils_1.decodeStream)(escrow === null || escrow === void 0 ? void 0 : escrow.data).mint;
|
|
672
|
-
return [4 /*yield*/, (0, utils_1.ata)(mint,
|
|
752
|
+
return [4 /*yield*/, (0, utils_1.ata)(mint, newRecipientPublicKey)];
|
|
673
753
|
case 2:
|
|
674
754
|
newRecipientTokens = _d.sent();
|
|
675
|
-
ixs.push(web3_js_1.ComputeBudgetProgram.setComputeUnitLimit({ units: 100001 }));
|
|
676
755
|
ixs.push((0, instructions_1.transferStreamInstruction)(this.programId, {
|
|
677
756
|
authority: invoker.publicKey,
|
|
678
|
-
newRecipient:
|
|
757
|
+
newRecipient: newRecipientPublicKey,
|
|
679
758
|
newRecipientTokens: newRecipientTokens,
|
|
680
759
|
metadata: stream,
|
|
681
760
|
mint: mint,
|
|
@@ -684,63 +763,75 @@ var SolanaStreamClient = /** @class */ (function (_super) {
|
|
|
684
763
|
associatedTokenProgram: spl_token_1.ASSOCIATED_TOKEN_PROGRAM_ID,
|
|
685
764
|
systemProgram: web3_js_1.SystemProgram.programId,
|
|
686
765
|
}));
|
|
687
|
-
|
|
688
|
-
|
|
766
|
+
return [2 /*return*/, ixs];
|
|
767
|
+
}
|
|
768
|
+
});
|
|
769
|
+
});
|
|
770
|
+
};
|
|
771
|
+
/**
|
|
772
|
+
* Tops up stream account with specified amount.
|
|
773
|
+
*/
|
|
774
|
+
SolanaStreamClient.prototype.topup = function (_a, extensions) {
|
|
775
|
+
var id = _a.id, amount = _a.amount;
|
|
776
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
777
|
+
var ixs, _b, tx, hash, signature;
|
|
778
|
+
return __generator(this, function (_c) {
|
|
779
|
+
switch (_c.label) {
|
|
780
|
+
case 0: return [4 /*yield*/, this.prepareTopupInstructions({ id: id, amount: amount }, extensions)];
|
|
781
|
+
case 1:
|
|
782
|
+
ixs = _c.sent();
|
|
783
|
+
return [4 /*yield*/, (0, utils_1.prepareTransaction)(this.connection, ixs, extensions.invoker.publicKey, this.getCommitment())];
|
|
784
|
+
case 2:
|
|
785
|
+
_b = _c.sent(), tx = _b.tx, hash = _b.hash;
|
|
786
|
+
return [4 /*yield*/, (0, utils_1.signAndExecuteTransaction)(this.connection, extensions.invoker, tx, hash)];
|
|
689
787
|
case 3:
|
|
690
|
-
|
|
691
|
-
tx = (_c = new web3_js_1.Transaction({
|
|
692
|
-
feePayer: invoker.publicKey,
|
|
693
|
-
blockhash: hash.blockhash,
|
|
694
|
-
lastValidBlockHeight: hash.lastValidBlockHeight,
|
|
695
|
-
})).add.apply(_c, __spreadArray([], __read(ixs), false));
|
|
696
|
-
return [4 /*yield*/, (0, utils_1.signAndExecuteTransaction)(this.connection, invoker, tx, hash)];
|
|
697
|
-
case 4:
|
|
698
|
-
signature = _d.sent();
|
|
788
|
+
signature = _c.sent();
|
|
699
789
|
return [2 /*return*/, { ixs: ixs, txId: signature }];
|
|
700
790
|
}
|
|
701
791
|
});
|
|
702
792
|
});
|
|
703
793
|
};
|
|
704
794
|
/**
|
|
705
|
-
*
|
|
795
|
+
* Create Transaction instructions for topup
|
|
706
796
|
*/
|
|
707
|
-
SolanaStreamClient.prototype.
|
|
797
|
+
SolanaStreamClient.prototype.prepareTopupInstructions = function (_a, _b) {
|
|
708
798
|
var id = _a.id, amount = _a.amount;
|
|
709
|
-
var invoker = _b.invoker, isNative = _b.isNative;
|
|
799
|
+
var invoker = _b.invoker, isNative = _b.isNative, computePrice = _b.computePrice, computeLimit = _b.computeLimit;
|
|
710
800
|
return __awaiter(this, void 0, void 0, function () {
|
|
711
|
-
var ixs, streamPublicKey, escrow, _c, mint, partner, senderTokens, escrowTokens, streamflowTreasuryTokens, partnerTokens,
|
|
712
|
-
|
|
713
|
-
|
|
714
|
-
switch (_f.label) {
|
|
801
|
+
var ixs, streamPublicKey, escrow, _c, mint, partner, senderTokens, escrowTokens, streamflowTreasuryTokens, partnerTokens, _d, _e, _f, _g;
|
|
802
|
+
return __generator(this, function (_h) {
|
|
803
|
+
switch (_h.label) {
|
|
715
804
|
case 0:
|
|
716
805
|
if (!invoker.publicKey) {
|
|
717
806
|
throw new Error("Invoker's PublicKey is not available, check passed wallet adapter!");
|
|
718
807
|
}
|
|
719
|
-
ixs =
|
|
808
|
+
ixs = this.prepareBaseInstructions({
|
|
809
|
+
computePrice: computePrice,
|
|
810
|
+
computeLimit: computeLimit,
|
|
811
|
+
});
|
|
720
812
|
streamPublicKey = new web3_js_1.PublicKey(id);
|
|
721
813
|
return [4 /*yield*/, this.connection.getAccountInfo(streamPublicKey)];
|
|
722
814
|
case 1:
|
|
723
|
-
escrow =
|
|
815
|
+
escrow = _h.sent();
|
|
724
816
|
if (!(escrow === null || escrow === void 0 ? void 0 : escrow.data)) {
|
|
725
817
|
throw new Error("Couldn't get account info");
|
|
726
818
|
}
|
|
727
819
|
_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;
|
|
728
820
|
return [4 /*yield*/, (0, utils_1.ata)(mint, constants_1.STREAMFLOW_TREASURY_PUBLIC_KEY)];
|
|
729
821
|
case 2:
|
|
730
|
-
streamflowTreasuryTokens =
|
|
822
|
+
streamflowTreasuryTokens = _h.sent();
|
|
731
823
|
return [4 /*yield*/, (0, utils_1.ata)(mint, partner)];
|
|
732
824
|
case 3:
|
|
733
|
-
partnerTokens =
|
|
825
|
+
partnerTokens = _h.sent();
|
|
734
826
|
if (!isNative) return [3 /*break*/, 5];
|
|
827
|
+
_e = (_d = ixs.push).apply;
|
|
828
|
+
_f = [ixs];
|
|
829
|
+
_g = [[]];
|
|
735
830
|
return [4 /*yield*/, (0, instructions_1.prepareWrappedAccount)(this.connection, invoker.publicKey, amount)];
|
|
736
831
|
case 4:
|
|
737
|
-
_d
|
|
738
|
-
|
|
832
|
+
_e.apply(_d, _f.concat([__spreadArray.apply(void 0, _g.concat([__read.apply(void 0, [(_h.sent())]), false]))]));
|
|
833
|
+
_h.label = 5;
|
|
739
834
|
case 5:
|
|
740
|
-
_d = [];
|
|
741
|
-
_f.label = 6;
|
|
742
|
-
case 6:
|
|
743
|
-
nativeInstructions = _d;
|
|
744
835
|
ixs.push((0, instructions_1.topupStreamInstruction)(amount, this.programId, {
|
|
745
836
|
sender: invoker.publicKey,
|
|
746
837
|
senderTokens: senderTokens,
|
|
@@ -755,19 +846,7 @@ var SolanaStreamClient = /** @class */ (function (_super) {
|
|
|
755
846
|
withdrawor: constants_1.WITHDRAWOR_PUBLIC_KEY,
|
|
756
847
|
systemProgram: web3_js_1.SystemProgram.programId,
|
|
757
848
|
}));
|
|
758
|
-
|
|
759
|
-
return [4 /*yield*/, this.connection.getLatestBlockhash(commitment)];
|
|
760
|
-
case 7:
|
|
761
|
-
hash = _f.sent();
|
|
762
|
-
tx = (_e = new web3_js_1.Transaction({
|
|
763
|
-
feePayer: invoker.publicKey,
|
|
764
|
-
blockhash: hash.blockhash,
|
|
765
|
-
lastValidBlockHeight: hash.lastValidBlockHeight,
|
|
766
|
-
})).add.apply(_e, __spreadArray(__spreadArray([], __read(nativeInstructions), false), __read(ixs), false));
|
|
767
|
-
return [4 /*yield*/, (0, utils_1.signAndExecuteTransaction)(this.connection, invoker, tx, hash)];
|
|
768
|
-
case 8:
|
|
769
|
-
signature = _f.sent();
|
|
770
|
-
return [2 /*return*/, { ixs: ixs, txId: signature }];
|
|
849
|
+
return [2 /*return*/, ixs];
|
|
771
850
|
}
|
|
772
851
|
});
|
|
773
852
|
});
|
|
@@ -842,10 +921,35 @@ var SolanaStreamClient = /** @class */ (function (_super) {
|
|
|
842
921
|
/**
|
|
843
922
|
* Attempts updating the stream auto withdrawal params and amount per period
|
|
844
923
|
*/
|
|
845
|
-
SolanaStreamClient.prototype.update = function (data,
|
|
846
|
-
|
|
924
|
+
SolanaStreamClient.prototype.update = function (data, extensions) {
|
|
925
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
926
|
+
var ixs, _a, tx, hash, signature;
|
|
927
|
+
return __generator(this, function (_b) {
|
|
928
|
+
switch (_b.label) {
|
|
929
|
+
case 0: return [4 /*yield*/, this.prepareUpdateInstructions(data, extensions)];
|
|
930
|
+
case 1:
|
|
931
|
+
ixs = _b.sent();
|
|
932
|
+
return [4 /*yield*/, (0, utils_1.prepareTransaction)(this.connection, ixs, extensions.invoker.publicKey, this.getCommitment())];
|
|
933
|
+
case 2:
|
|
934
|
+
_a = _b.sent(), tx = _a.tx, hash = _a.hash;
|
|
935
|
+
return [4 /*yield*/, (0, utils_1.signAndExecuteTransaction)(this.connection, extensions.invoker, tx, hash)];
|
|
936
|
+
case 3:
|
|
937
|
+
signature = _b.sent();
|
|
938
|
+
return [2 /*return*/, {
|
|
939
|
+
ixs: ixs,
|
|
940
|
+
txId: signature,
|
|
941
|
+
}];
|
|
942
|
+
}
|
|
943
|
+
});
|
|
944
|
+
});
|
|
945
|
+
};
|
|
946
|
+
/**
|
|
947
|
+
* Create Transaction instructions for update
|
|
948
|
+
*/
|
|
949
|
+
SolanaStreamClient.prototype.prepareUpdateInstructions = function (data, _a) {
|
|
950
|
+
var invoker = _a.invoker, computePrice = _a.computePrice, computeLimit = _a.computeLimit;
|
|
847
951
|
return __awaiter(this, void 0, void 0, function () {
|
|
848
|
-
var streamPublicKey, escrow,
|
|
952
|
+
var streamPublicKey, escrow, ixs;
|
|
849
953
|
return __generator(this, function (_b) {
|
|
850
954
|
switch (_b.label) {
|
|
851
955
|
case 0:
|
|
@@ -859,28 +963,17 @@ var SolanaStreamClient = /** @class */ (function (_super) {
|
|
|
859
963
|
if (!escrow) {
|
|
860
964
|
throw new Error("Couldn't get account info");
|
|
861
965
|
}
|
|
862
|
-
|
|
966
|
+
ixs = this.prepareBaseInstructions({
|
|
967
|
+
computePrice: computePrice,
|
|
968
|
+
computeLimit: computeLimit,
|
|
969
|
+
});
|
|
970
|
+
ixs.push((0, instructions_1.updateStreamInstruction)(data, this.programId, {
|
|
863
971
|
authority: invoker.publicKey,
|
|
864
972
|
metadata: streamPublicKey,
|
|
865
973
|
withdrawor: constants_1.WITHDRAWOR_PUBLIC_KEY,
|
|
866
974
|
systemProgram: web3_js_1.SystemProgram.programId,
|
|
867
|
-
});
|
|
868
|
-
|
|
869
|
-
return [4 /*yield*/, this.connection.getLatestBlockhash(commitment)];
|
|
870
|
-
case 2:
|
|
871
|
-
hash = _b.sent();
|
|
872
|
-
tx = new web3_js_1.Transaction({
|
|
873
|
-
feePayer: invoker.publicKey,
|
|
874
|
-
blockhash: hash.blockhash,
|
|
875
|
-
lastValidBlockHeight: hash.lastValidBlockHeight,
|
|
876
|
-
}).add(updateIx);
|
|
877
|
-
return [4 /*yield*/, (0, utils_1.signAndExecuteTransaction)(this.connection, invoker, tx, hash)];
|
|
878
|
-
case 3:
|
|
879
|
-
signature = _b.sent();
|
|
880
|
-
return [2 /*return*/, {
|
|
881
|
-
ixs: [updateIx],
|
|
882
|
-
txId: signature,
|
|
883
|
-
}];
|
|
975
|
+
}));
|
|
976
|
+
return [2 /*return*/, ixs];
|
|
884
977
|
}
|
|
885
978
|
});
|
|
886
979
|
});
|
|
@@ -995,6 +1088,37 @@ var SolanaStreamClient = /** @class */ (function (_super) {
|
|
|
995
1088
|
});
|
|
996
1089
|
});
|
|
997
1090
|
};
|
|
1091
|
+
/**
|
|
1092
|
+
* Create Base instructions for Solana
|
|
1093
|
+
* - sets compute price if `computePrice` is provided
|
|
1094
|
+
* - sets compute limit if `computeLimit` is provided
|
|
1095
|
+
*/
|
|
1096
|
+
SolanaStreamClient.prototype.prepareBaseInstructions = function (_a) {
|
|
1097
|
+
var computePrice = _a.computePrice, computeLimit = _a.computeLimit;
|
|
1098
|
+
var ixs = [];
|
|
1099
|
+
if (computePrice) {
|
|
1100
|
+
ixs.push(web3_js_1.ComputeBudgetProgram.setComputeUnitPrice({ microLamports: computePrice }));
|
|
1101
|
+
}
|
|
1102
|
+
if (computeLimit) {
|
|
1103
|
+
ixs.push(web3_js_1.ComputeBudgetProgram.setComputeUnitLimit({ units: computeLimit }));
|
|
1104
|
+
}
|
|
1105
|
+
return ixs;
|
|
1106
|
+
};
|
|
1107
|
+
/**
|
|
1108
|
+
* Utility function to generate metadata for a Contract or return existing Pubkey
|
|
1109
|
+
*/
|
|
1110
|
+
SolanaStreamClient.prototype.getOrCreateStreamMetadata = function (metadataPubKeys) {
|
|
1111
|
+
var metadata;
|
|
1112
|
+
var metadataPubKey;
|
|
1113
|
+
if (!metadataPubKeys) {
|
|
1114
|
+
metadata = web3_js_1.Keypair.generate();
|
|
1115
|
+
metadataPubKey = metadata.publicKey;
|
|
1116
|
+
}
|
|
1117
|
+
else {
|
|
1118
|
+
metadataPubKey = metadataPubKeys[0];
|
|
1119
|
+
}
|
|
1120
|
+
return { metadata: metadata, metadataPubKey: metadataPubKey };
|
|
1121
|
+
};
|
|
998
1122
|
/**
|
|
999
1123
|
* Utility function that checks whether associated token accounts still exist and adds instructions to add them if not
|
|
1000
1124
|
*/
|
|
@@ -1034,21 +1158,6 @@ var SolanaStreamClient = /** @class */ (function (_super) {
|
|
|
1034
1158
|
});
|
|
1035
1159
|
});
|
|
1036
1160
|
};
|
|
1037
|
-
/**
|
|
1038
|
-
* Utility function to generate metadata for a Contract or return existing Pubkey
|
|
1039
|
-
*/
|
|
1040
|
-
SolanaStreamClient.prototype.getOrCreateStreamMetadata = function (metadataPubKeys) {
|
|
1041
|
-
var metadata;
|
|
1042
|
-
var metadataPubKey;
|
|
1043
|
-
if (!metadataPubKeys) {
|
|
1044
|
-
metadata = web3_js_1.Keypair.generate();
|
|
1045
|
-
metadataPubKey = metadata.publicKey;
|
|
1046
|
-
}
|
|
1047
|
-
else {
|
|
1048
|
-
metadataPubKey = metadataPubKeys[0];
|
|
1049
|
-
}
|
|
1050
|
-
return { metadata: metadata, metadataPubKey: metadataPubKey };
|
|
1051
|
-
};
|
|
1052
1161
|
return SolanaStreamClient;
|
|
1053
1162
|
}(BaseStreamClient_1.BaseStreamClient));
|
|
1054
1163
|
exports.default = SolanaStreamClient;
|