@streamflow/stream 6.0.0-alpha.0 → 6.0.0-alpha.2
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 +50 -11
- package/dist/solana/StreamClient.js +285 -192
- 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, 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, solana_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, solana_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 = (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, extensions) {
|
|
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, extensions)];
|
|
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, extensions.sender.publicKey, this.getCommitment(), metadata)];
|
|
300
|
+
case 2:
|
|
301
|
+
_b = _c.sent(), tx = _b.tx, hash = _b.hash;
|
|
302
|
+
return [4 /*yield*/, (0, solana_1.signAndExecuteTransaction)(this.connection, extensions.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
|
});
|
|
@@ -372,7 +399,7 @@ var SolanaStreamClient = /** @class */ (function (_super) {
|
|
|
372
399
|
SolanaStreamClient.prototype.createMultiple = function (data, _a) {
|
|
373
400
|
var sender = _a.sender, metadataPubKeys = _a.metadataPubKeys, _b = _a.isNative, isNative = _b === void 0 ? false : _b;
|
|
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, commitment, hash, instructionsBatch_1, instructionsBatch_1_1, _d, ixs, metadata, recipient, tx, totalDepositedAmount, nativeInstructions,
|
|
402
|
+
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;
|
|
376
403
|
var e_2, _o, _p, _q, e_1, _r;
|
|
377
404
|
var _this = this;
|
|
378
405
|
return __generator(this, function (_s) {
|
|
@@ -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
|
+
prepareTransaction_1 = (_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: prepareTransaction_1,
|
|
452
479
|
recipient: sender.publicKey.toBase58(),
|
|
453
480
|
});
|
|
454
481
|
_s.label = 7;
|
|
@@ -524,18 +551,44 @@ var SolanaStreamClient = /** @class */ (function (_super) {
|
|
|
524
551
|
* Attempts withdrawing from the specified stream.
|
|
525
552
|
*/
|
|
526
553
|
SolanaStreamClient.prototype.withdraw = function (_a, _b) {
|
|
527
|
-
var id = _a.id,
|
|
554
|
+
var id = _a.id, _c = _a.amount, amount = _c === void 0 ? constants_2.WITHDRAW_AVAILABLE_AMOUNT : _c;
|
|
528
555
|
var invoker = _b.invoker, checkTokenAccounts = _b.checkTokenAccounts;
|
|
529
556
|
return __awaiter(this, void 0, void 0, function () {
|
|
530
|
-
var ixs,
|
|
531
|
-
|
|
557
|
+
var ixs, _d, tx, hash, signature;
|
|
558
|
+
return __generator(this, function (_e) {
|
|
559
|
+
switch (_e.label) {
|
|
560
|
+
case 0: return [4 /*yield*/, this.prepareWithdawInstructions({ id: id, amount: amount }, { invoker: invoker, checkTokenAccounts: checkTokenAccounts })];
|
|
561
|
+
case 1:
|
|
562
|
+
ixs = _e.sent();
|
|
563
|
+
return [4 /*yield*/, (0, solana_1.prepareTransaction)(this.connection, ixs, invoker.publicKey, this.getCommitment())];
|
|
564
|
+
case 2:
|
|
565
|
+
_d = _e.sent(), tx = _d.tx, hash = _d.hash;
|
|
566
|
+
return [4 /*yield*/, (0, solana_1.signAndExecuteTransaction)(this.connection, invoker, tx, hash)];
|
|
567
|
+
case 3:
|
|
568
|
+
signature = _e.sent();
|
|
569
|
+
return [2 /*return*/, { ixs: ixs, txId: signature }];
|
|
570
|
+
}
|
|
571
|
+
});
|
|
572
|
+
});
|
|
573
|
+
};
|
|
574
|
+
/**
|
|
575
|
+
* Creates Transaction Instructions for withdrawal
|
|
576
|
+
*/
|
|
577
|
+
SolanaStreamClient.prototype.prepareWithdawInstructions = function (_a, _b) {
|
|
578
|
+
var id = _a.id, _c = _a.amount, amount = _c === void 0 ? constants_2.WITHDRAW_AVAILABLE_AMOUNT : _c;
|
|
579
|
+
var invoker = _b.invoker, checkTokenAccounts = _b.checkTokenAccounts, computePrice = _b.computePrice, computeLimit = _b.computeLimit;
|
|
580
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
581
|
+
var ixs, streamPublicKey, escrow, data, streamflowTreasuryTokens, partnerTokens;
|
|
532
582
|
return __generator(this, function (_d) {
|
|
533
583
|
switch (_d.label) {
|
|
534
584
|
case 0:
|
|
535
585
|
if (!invoker.publicKey) {
|
|
536
586
|
throw new Error("Invoker's PublicKey is not available, check passed wallet adapter!");
|
|
537
587
|
}
|
|
538
|
-
ixs =
|
|
588
|
+
ixs = (0, solana_1.prepareBaseInstructions)(this.connection, {
|
|
589
|
+
computePrice: computePrice,
|
|
590
|
+
computeLimit: computeLimit,
|
|
591
|
+
});
|
|
539
592
|
streamPublicKey = new web3_js_1.PublicKey(id);
|
|
540
593
|
return [4 /*yield*/, this.connection.getAccountInfo(streamPublicKey)];
|
|
541
594
|
case 1:
|
|
@@ -566,19 +619,7 @@ var SolanaStreamClient = /** @class */ (function (_super) {
|
|
|
566
619
|
mint: data.mint,
|
|
567
620
|
tokenProgram: spl_token_1.TOKEN_PROGRAM_ID,
|
|
568
621
|
}));
|
|
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 }];
|
|
622
|
+
return [2 /*return*/, ixs];
|
|
582
623
|
}
|
|
583
624
|
});
|
|
584
625
|
});
|
|
@@ -586,14 +627,36 @@ var SolanaStreamClient = /** @class */ (function (_super) {
|
|
|
586
627
|
/**
|
|
587
628
|
* Attempts canceling the specified stream.
|
|
588
629
|
*/
|
|
589
|
-
SolanaStreamClient.prototype.cancel = function (_a,
|
|
630
|
+
SolanaStreamClient.prototype.cancel = function (_a, extensions) {
|
|
590
631
|
var id = _a.id;
|
|
591
|
-
var invoker = _b.invoker, checkTokenAccounts = _b.checkTokenAccounts;
|
|
592
632
|
return __awaiter(this, void 0, void 0, function () {
|
|
593
|
-
var
|
|
594
|
-
|
|
595
|
-
|
|
596
|
-
|
|
633
|
+
var ixs, _b, tx, hash, signature;
|
|
634
|
+
return __generator(this, function (_c) {
|
|
635
|
+
switch (_c.label) {
|
|
636
|
+
case 0: return [4 /*yield*/, this.prepareCancelInstructions({ id: id }, extensions)];
|
|
637
|
+
case 1:
|
|
638
|
+
ixs = _c.sent();
|
|
639
|
+
return [4 /*yield*/, (0, solana_1.prepareTransaction)(this.connection, ixs, extensions.invoker.publicKey, this.getCommitment())];
|
|
640
|
+
case 2:
|
|
641
|
+
_b = _c.sent(), tx = _b.tx, hash = _b.hash;
|
|
642
|
+
return [4 /*yield*/, (0, solana_1.signAndExecuteTransaction)(this.connection, extensions.invoker, tx, hash)];
|
|
643
|
+
case 3:
|
|
644
|
+
signature = _c.sent();
|
|
645
|
+
return [2 /*return*/, { ixs: ixs, txId: signature }];
|
|
646
|
+
}
|
|
647
|
+
});
|
|
648
|
+
});
|
|
649
|
+
};
|
|
650
|
+
/**
|
|
651
|
+
* Creates Transaction Instructions for cancel
|
|
652
|
+
*/
|
|
653
|
+
SolanaStreamClient.prototype.prepareCancelInstructions = function (_a, _b) {
|
|
654
|
+
var id = _a.id;
|
|
655
|
+
var invoker = _b.invoker, checkTokenAccounts = _b.checkTokenAccounts, computePrice = _b.computePrice, computeLimit = _b.computeLimit;
|
|
656
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
657
|
+
var streamPublicKey, escrowAcc, data, streamflowTreasuryTokens, partnerTokens, ixs;
|
|
658
|
+
return __generator(this, function (_c) {
|
|
659
|
+
switch (_c.label) {
|
|
597
660
|
case 0:
|
|
598
661
|
if (!invoker.publicKey) {
|
|
599
662
|
throw new Error("Invoker's PublicKey is not available, check passed wallet adapter!");
|
|
@@ -601,21 +664,24 @@ var SolanaStreamClient = /** @class */ (function (_super) {
|
|
|
601
664
|
streamPublicKey = new web3_js_1.PublicKey(id);
|
|
602
665
|
return [4 /*yield*/, this.connection.getAccountInfo(streamPublicKey)];
|
|
603
666
|
case 1:
|
|
604
|
-
escrowAcc =
|
|
667
|
+
escrowAcc = _c.sent();
|
|
605
668
|
if (!(escrowAcc === null || escrowAcc === void 0 ? void 0 : escrowAcc.data)) {
|
|
606
669
|
throw new Error("Couldn't get account info");
|
|
607
670
|
}
|
|
608
671
|
data = (0, utils_1.decodeStream)(escrowAcc === null || escrowAcc === void 0 ? void 0 : escrowAcc.data);
|
|
609
672
|
return [4 /*yield*/, (0, solana_1.ata)(data.mint, constants_1.STREAMFLOW_TREASURY_PUBLIC_KEY)];
|
|
610
673
|
case 2:
|
|
611
|
-
streamflowTreasuryTokens =
|
|
674
|
+
streamflowTreasuryTokens = _c.sent();
|
|
612
675
|
return [4 /*yield*/, (0, solana_1.ata)(data.mint, data.partner)];
|
|
613
676
|
case 3:
|
|
614
|
-
partnerTokens =
|
|
615
|
-
ixs =
|
|
677
|
+
partnerTokens = _c.sent();
|
|
678
|
+
ixs = (0, solana_1.prepareBaseInstructions)(this.connection, {
|
|
679
|
+
computePrice: computePrice,
|
|
680
|
+
computeLimit: computeLimit,
|
|
681
|
+
});
|
|
616
682
|
return [4 /*yield*/, this.checkAssociatedTokenAccounts(data, { invoker: invoker, checkTokenAccounts: checkTokenAccounts }, ixs)];
|
|
617
683
|
case 4:
|
|
618
|
-
|
|
684
|
+
_c.sent();
|
|
619
685
|
ixs.push((0, instructions_1.cancelStreamInstruction)(this.programId, {
|
|
620
686
|
authority: invoker.publicKey,
|
|
621
687
|
sender: data.sender,
|
|
@@ -631,18 +697,30 @@ var SolanaStreamClient = /** @class */ (function (_super) {
|
|
|
631
697
|
mint: data.mint,
|
|
632
698
|
tokenProgram: spl_token_1.TOKEN_PROGRAM_ID,
|
|
633
699
|
}));
|
|
634
|
-
|
|
635
|
-
|
|
636
|
-
|
|
637
|
-
|
|
638
|
-
|
|
639
|
-
|
|
640
|
-
|
|
641
|
-
|
|
642
|
-
|
|
643
|
-
|
|
644
|
-
|
|
645
|
-
|
|
700
|
+
return [2 /*return*/, ixs];
|
|
701
|
+
}
|
|
702
|
+
});
|
|
703
|
+
});
|
|
704
|
+
};
|
|
705
|
+
/**
|
|
706
|
+
* Attempts changing the stream/vesting contract's recipient (effectively transferring the stream/vesting contract).
|
|
707
|
+
* Potential associated token account rent fee (to make it rent-exempt) is paid by the transaction initiator.
|
|
708
|
+
*/
|
|
709
|
+
SolanaStreamClient.prototype.transfer = function (_a, extensions) {
|
|
710
|
+
var id = _a.id, newRecipient = _a.newRecipient;
|
|
711
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
712
|
+
var ixs, _b, tx, hash, signature;
|
|
713
|
+
return __generator(this, function (_c) {
|
|
714
|
+
switch (_c.label) {
|
|
715
|
+
case 0: return [4 /*yield*/, this.prepareTransferInstructions({ id: id, newRecipient: newRecipient }, extensions)];
|
|
716
|
+
case 1:
|
|
717
|
+
ixs = _c.sent();
|
|
718
|
+
return [4 /*yield*/, (0, solana_1.prepareTransaction)(this.connection, ixs, extensions.invoker.publicKey, this.getCommitment())];
|
|
719
|
+
case 2:
|
|
720
|
+
_b = _c.sent(), tx = _b.tx, hash = _b.hash;
|
|
721
|
+
return [4 /*yield*/, (0, solana_1.signAndExecuteTransaction)(this.connection, extensions.invoker, tx, hash)];
|
|
722
|
+
case 3:
|
|
723
|
+
signature = _c.sent();
|
|
646
724
|
return [2 /*return*/, { ixs: ixs, txId: signature }];
|
|
647
725
|
}
|
|
648
726
|
});
|
|
@@ -652,21 +730,23 @@ var SolanaStreamClient = /** @class */ (function (_super) {
|
|
|
652
730
|
* Attempts changing the stream/vesting contract's recipient (effectively transferring the stream/vesting contract).
|
|
653
731
|
* Potential associated token account rent fee (to make it rent-exempt) is paid by the transaction initiator.
|
|
654
732
|
*/
|
|
655
|
-
SolanaStreamClient.prototype.
|
|
656
|
-
var id = _a.id,
|
|
657
|
-
var invoker = _b.invoker;
|
|
733
|
+
SolanaStreamClient.prototype.prepareTransferInstructions = function (_a, _b) {
|
|
734
|
+
var id = _a.id, newRecipient = _a.newRecipient;
|
|
735
|
+
var invoker = _b.invoker, computePrice = _b.computePrice, _c = _b.computeLimit, computeLimit = _c === void 0 ? 100001 : _c;
|
|
658
736
|
return __awaiter(this, void 0, void 0, function () {
|
|
659
|
-
var ixs, stream,
|
|
660
|
-
var _c;
|
|
737
|
+
var ixs, stream, newRecipientPublicKey, escrow, mint, newRecipientTokens;
|
|
661
738
|
return __generator(this, function (_d) {
|
|
662
739
|
switch (_d.label) {
|
|
663
740
|
case 0:
|
|
664
741
|
if (!invoker.publicKey) {
|
|
665
742
|
throw new Error("Invoker's PublicKey is not available, check passed wallet adapter!");
|
|
666
743
|
}
|
|
667
|
-
ixs =
|
|
744
|
+
ixs = (0, solana_1.prepareBaseInstructions)(this.connection, {
|
|
745
|
+
computePrice: computePrice,
|
|
746
|
+
computeLimit: computeLimit,
|
|
747
|
+
});
|
|
668
748
|
stream = new web3_js_1.PublicKey(id);
|
|
669
|
-
|
|
749
|
+
newRecipientPublicKey = new web3_js_1.PublicKey(newRecipient);
|
|
670
750
|
return [4 /*yield*/, this.connection.getAccountInfo(stream)];
|
|
671
751
|
case 1:
|
|
672
752
|
escrow = _d.sent();
|
|
@@ -674,13 +754,12 @@ var SolanaStreamClient = /** @class */ (function (_super) {
|
|
|
674
754
|
throw new Error("Couldn't get account info");
|
|
675
755
|
}
|
|
676
756
|
mint = (0, utils_1.decodeStream)(escrow === null || escrow === void 0 ? void 0 : escrow.data).mint;
|
|
677
|
-
return [4 /*yield*/, (0, solana_1.ata)(mint,
|
|
757
|
+
return [4 /*yield*/, (0, solana_1.ata)(mint, newRecipientPublicKey)];
|
|
678
758
|
case 2:
|
|
679
759
|
newRecipientTokens = _d.sent();
|
|
680
|
-
ixs.push(web3_js_1.ComputeBudgetProgram.setComputeUnitLimit({ units: 100001 }));
|
|
681
760
|
ixs.push((0, instructions_1.transferStreamInstruction)(this.programId, {
|
|
682
761
|
authority: invoker.publicKey,
|
|
683
|
-
newRecipient:
|
|
762
|
+
newRecipient: newRecipientPublicKey,
|
|
684
763
|
newRecipientTokens: newRecipientTokens,
|
|
685
764
|
metadata: stream,
|
|
686
765
|
mint: mint,
|
|
@@ -689,63 +768,75 @@ var SolanaStreamClient = /** @class */ (function (_super) {
|
|
|
689
768
|
associatedTokenProgram: spl_token_1.ASSOCIATED_TOKEN_PROGRAM_ID,
|
|
690
769
|
systemProgram: web3_js_1.SystemProgram.programId,
|
|
691
770
|
}));
|
|
692
|
-
|
|
693
|
-
|
|
771
|
+
return [2 /*return*/, ixs];
|
|
772
|
+
}
|
|
773
|
+
});
|
|
774
|
+
});
|
|
775
|
+
};
|
|
776
|
+
/**
|
|
777
|
+
* Tops up stream account with specified amount.
|
|
778
|
+
*/
|
|
779
|
+
SolanaStreamClient.prototype.topup = function (_a, extensions) {
|
|
780
|
+
var id = _a.id, amount = _a.amount;
|
|
781
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
782
|
+
var ixs, _b, tx, hash, signature;
|
|
783
|
+
return __generator(this, function (_c) {
|
|
784
|
+
switch (_c.label) {
|
|
785
|
+
case 0: return [4 /*yield*/, this.prepareTopupInstructions({ id: id, amount: amount }, extensions)];
|
|
786
|
+
case 1:
|
|
787
|
+
ixs = _c.sent();
|
|
788
|
+
return [4 /*yield*/, (0, solana_1.prepareTransaction)(this.connection, ixs, extensions.invoker.publicKey, this.getCommitment())];
|
|
789
|
+
case 2:
|
|
790
|
+
_b = _c.sent(), tx = _b.tx, hash = _b.hash;
|
|
791
|
+
return [4 /*yield*/, (0, solana_1.signAndExecuteTransaction)(this.connection, extensions.invoker, tx, hash)];
|
|
694
792
|
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();
|
|
793
|
+
signature = _c.sent();
|
|
704
794
|
return [2 /*return*/, { ixs: ixs, txId: signature }];
|
|
705
795
|
}
|
|
706
796
|
});
|
|
707
797
|
});
|
|
708
798
|
};
|
|
709
799
|
/**
|
|
710
|
-
*
|
|
800
|
+
* Create Transaction instructions for topup
|
|
711
801
|
*/
|
|
712
|
-
SolanaStreamClient.prototype.
|
|
802
|
+
SolanaStreamClient.prototype.prepareTopupInstructions = function (_a, _b) {
|
|
713
803
|
var id = _a.id, amount = _a.amount;
|
|
714
|
-
var invoker = _b.invoker, isNative = _b.isNative;
|
|
804
|
+
var invoker = _b.invoker, isNative = _b.isNative, computePrice = _b.computePrice, computeLimit = _b.computeLimit;
|
|
715
805
|
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) {
|
|
806
|
+
var ixs, streamPublicKey, escrow, _c, mint, partner, senderTokens, escrowTokens, streamflowTreasuryTokens, partnerTokens, _d, _e, _f, _g;
|
|
807
|
+
return __generator(this, function (_h) {
|
|
808
|
+
switch (_h.label) {
|
|
720
809
|
case 0:
|
|
721
810
|
if (!invoker.publicKey) {
|
|
722
811
|
throw new Error("Invoker's PublicKey is not available, check passed wallet adapter!");
|
|
723
812
|
}
|
|
724
|
-
ixs =
|
|
813
|
+
ixs = (0, solana_1.prepareBaseInstructions)(this.connection, {
|
|
814
|
+
computePrice: computePrice,
|
|
815
|
+
computeLimit: computeLimit,
|
|
816
|
+
});
|
|
725
817
|
streamPublicKey = new web3_js_1.PublicKey(id);
|
|
726
818
|
return [4 /*yield*/, this.connection.getAccountInfo(streamPublicKey)];
|
|
727
819
|
case 1:
|
|
728
|
-
escrow =
|
|
820
|
+
escrow = _h.sent();
|
|
729
821
|
if (!(escrow === null || escrow === void 0 ? void 0 : escrow.data)) {
|
|
730
822
|
throw new Error("Couldn't get account info");
|
|
731
823
|
}
|
|
732
824
|
_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
825
|
return [4 /*yield*/, (0, solana_1.ata)(mint, constants_1.STREAMFLOW_TREASURY_PUBLIC_KEY)];
|
|
734
826
|
case 2:
|
|
735
|
-
streamflowTreasuryTokens =
|
|
827
|
+
streamflowTreasuryTokens = _h.sent();
|
|
736
828
|
return [4 /*yield*/, (0, solana_1.ata)(mint, partner)];
|
|
737
829
|
case 3:
|
|
738
|
-
partnerTokens =
|
|
830
|
+
partnerTokens = _h.sent();
|
|
739
831
|
if (!isNative) return [3 /*break*/, 5];
|
|
832
|
+
_e = (_d = ixs.push).apply;
|
|
833
|
+
_f = [ixs];
|
|
834
|
+
_g = [[]];
|
|
740
835
|
return [4 /*yield*/, (0, solana_1.prepareWrappedAccount)(this.connection, invoker.publicKey, amount)];
|
|
741
836
|
case 4:
|
|
742
|
-
_d
|
|
743
|
-
|
|
837
|
+
_e.apply(_d, _f.concat([__spreadArray.apply(void 0, _g.concat([__read.apply(void 0, [(_h.sent())]), false]))]));
|
|
838
|
+
_h.label = 5;
|
|
744
839
|
case 5:
|
|
745
|
-
_d = [];
|
|
746
|
-
_f.label = 6;
|
|
747
|
-
case 6:
|
|
748
|
-
nativeInstructions = _d;
|
|
749
840
|
ixs.push((0, instructions_1.topupStreamInstruction)(amount, this.programId, {
|
|
750
841
|
sender: invoker.publicKey,
|
|
751
842
|
senderTokens: senderTokens,
|
|
@@ -760,19 +851,7 @@ var SolanaStreamClient = /** @class */ (function (_super) {
|
|
|
760
851
|
withdrawor: constants_1.WITHDRAWOR_PUBLIC_KEY,
|
|
761
852
|
systemProgram: web3_js_1.SystemProgram.programId,
|
|
762
853
|
}));
|
|
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 }];
|
|
854
|
+
return [2 /*return*/, ixs];
|
|
776
855
|
}
|
|
777
856
|
});
|
|
778
857
|
});
|
|
@@ -847,10 +926,35 @@ var SolanaStreamClient = /** @class */ (function (_super) {
|
|
|
847
926
|
/**
|
|
848
927
|
* Attempts updating the stream auto withdrawal params and amount per period
|
|
849
928
|
*/
|
|
850
|
-
SolanaStreamClient.prototype.update = function (data,
|
|
851
|
-
|
|
929
|
+
SolanaStreamClient.prototype.update = function (data, extensions) {
|
|
930
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
931
|
+
var ixs, _a, tx, hash, signature;
|
|
932
|
+
return __generator(this, function (_b) {
|
|
933
|
+
switch (_b.label) {
|
|
934
|
+
case 0: return [4 /*yield*/, this.prepareUpdateInstructions(data, extensions)];
|
|
935
|
+
case 1:
|
|
936
|
+
ixs = _b.sent();
|
|
937
|
+
return [4 /*yield*/, (0, solana_1.prepareTransaction)(this.connection, ixs, extensions.invoker.publicKey, this.getCommitment())];
|
|
938
|
+
case 2:
|
|
939
|
+
_a = _b.sent(), tx = _a.tx, hash = _a.hash;
|
|
940
|
+
return [4 /*yield*/, (0, solana_1.signAndExecuteTransaction)(this.connection, extensions.invoker, tx, hash)];
|
|
941
|
+
case 3:
|
|
942
|
+
signature = _b.sent();
|
|
943
|
+
return [2 /*return*/, {
|
|
944
|
+
ixs: ixs,
|
|
945
|
+
txId: signature,
|
|
946
|
+
}];
|
|
947
|
+
}
|
|
948
|
+
});
|
|
949
|
+
});
|
|
950
|
+
};
|
|
951
|
+
/**
|
|
952
|
+
* Create Transaction instructions for update
|
|
953
|
+
*/
|
|
954
|
+
SolanaStreamClient.prototype.prepareUpdateInstructions = function (data, _a) {
|
|
955
|
+
var invoker = _a.invoker, computePrice = _a.computePrice, computeLimit = _a.computeLimit;
|
|
852
956
|
return __awaiter(this, void 0, void 0, function () {
|
|
853
|
-
var streamPublicKey, escrow,
|
|
957
|
+
var streamPublicKey, escrow, ixs;
|
|
854
958
|
return __generator(this, function (_b) {
|
|
855
959
|
switch (_b.label) {
|
|
856
960
|
case 0:
|
|
@@ -864,28 +968,17 @@ var SolanaStreamClient = /** @class */ (function (_super) {
|
|
|
864
968
|
if (!escrow) {
|
|
865
969
|
throw new Error("Couldn't get account info");
|
|
866
970
|
}
|
|
867
|
-
|
|
971
|
+
ixs = (0, solana_1.prepareBaseInstructions)(this.connection, {
|
|
972
|
+
computePrice: computePrice,
|
|
973
|
+
computeLimit: computeLimit,
|
|
974
|
+
});
|
|
975
|
+
ixs.push((0, instructions_1.updateStreamInstruction)(data, this.programId, {
|
|
868
976
|
authority: invoker.publicKey,
|
|
869
977
|
metadata: streamPublicKey,
|
|
870
978
|
withdrawor: constants_1.WITHDRAWOR_PUBLIC_KEY,
|
|
871
979
|
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
|
-
}];
|
|
980
|
+
}));
|
|
981
|
+
return [2 /*return*/, ixs];
|
|
889
982
|
}
|
|
890
983
|
});
|
|
891
984
|
});
|
|
@@ -1000,6 +1093,21 @@ var SolanaStreamClient = /** @class */ (function (_super) {
|
|
|
1000
1093
|
});
|
|
1001
1094
|
});
|
|
1002
1095
|
};
|
|
1096
|
+
/**
|
|
1097
|
+
* Utility function to generate metadata for a Contract or return existing Pubkey
|
|
1098
|
+
*/
|
|
1099
|
+
SolanaStreamClient.prototype.getOrCreateStreamMetadata = function (metadataPubKeys) {
|
|
1100
|
+
var metadata;
|
|
1101
|
+
var metadataPubKey;
|
|
1102
|
+
if (!metadataPubKeys) {
|
|
1103
|
+
metadata = web3_js_1.Keypair.generate();
|
|
1104
|
+
metadataPubKey = metadata.publicKey;
|
|
1105
|
+
}
|
|
1106
|
+
else {
|
|
1107
|
+
metadataPubKey = metadataPubKeys[0];
|
|
1108
|
+
}
|
|
1109
|
+
return { metadata: metadata, metadataPubKey: metadataPubKey };
|
|
1110
|
+
};
|
|
1003
1111
|
/**
|
|
1004
1112
|
* Utility function that checks whether associated token accounts still exist and adds instructions to add them if not
|
|
1005
1113
|
*/
|
|
@@ -1030,21 +1138,6 @@ var SolanaStreamClient = /** @class */ (function (_super) {
|
|
|
1030
1138
|
});
|
|
1031
1139
|
});
|
|
1032
1140
|
};
|
|
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
1141
|
return SolanaStreamClient;
|
|
1049
1142
|
}(BaseStreamClient_1.BaseStreamClient));
|
|
1050
1143
|
exports.default = SolanaStreamClient;
|