@streamflow/stream 5.10.4 → 5.11.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/aptos/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 +57 -12
- package/dist/solana/StreamClient.js +307 -197
- 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, 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, utils_1.prepareTransaction)(this.connection, ixs, extParams.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, 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 = 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, extParams) {
|
|
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, extParams)];
|
|
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, extParams.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, extParams.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
|
});
|
|
@@ -368,9 +395,9 @@ var SolanaStreamClient = /** @class */ (function (_super) {
|
|
|
368
395
|
* All fees are paid by sender (escrow metadata account rent, escrow token account rent, recipient's associated token account rent, Streamflow's service fee).
|
|
369
396
|
*/
|
|
370
397
|
SolanaStreamClient.prototype.createMultiple = function (data, _a) {
|
|
371
|
-
var sender = _a.sender, metadataPubKeys = _a.metadataPubKeys, _b = _a.isNative, isNative = _b === void 0 ? false : _b;
|
|
398
|
+
var sender = _a.sender, metadataPubKeys = _a.metadataPubKeys, _b = _a.isNative, isNative = _b === void 0 ? false : _b, computePrice = _a.computePrice, computeLimit = _a.computeLimit;
|
|
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) {
|
|
@@ -395,6 +422,8 @@ var SolanaStreamClient = /** @class */ (function (_super) {
|
|
|
395
422
|
return [4 /*yield*/, this.prepareStreamInstructions(recipientData, data, {
|
|
396
423
|
sender: sender,
|
|
397
424
|
metadataPubKeys: metadataPubKeys[i] ? [metadataPubKeys[i]] : undefined,
|
|
425
|
+
computePrice: computePrice,
|
|
426
|
+
computeLimit: computeLimit,
|
|
398
427
|
})];
|
|
399
428
|
case 2:
|
|
400
429
|
_c = _s.sent(), ixs = _c.ixs, metadata = _c.metadata, metadataPubKey = _c.metadataPubKey;
|
|
@@ -436,12 +465,12 @@ var SolanaStreamClient = /** @class */ (function (_super) {
|
|
|
436
465
|
return [4 /*yield*/, (0, instructions_1.prepareWrappedAccount)(this.connection, sender.publicKey, totalDepositedAmount)];
|
|
437
466
|
case 6:
|
|
438
467
|
nativeInstructions = _s.sent();
|
|
439
|
-
|
|
468
|
+
prepareTransaction_1 = (_q = new web3_js_1.Transaction({
|
|
440
469
|
feePayer: sender.publicKey,
|
|
441
470
|
blockhash: hash.blockhash,
|
|
442
471
|
lastValidBlockHeight: hash.lastValidBlockHeight,
|
|
443
472
|
})).add.apply(_q, __spreadArray([], __read(nativeInstructions), false));
|
|
444
|
-
batch.push({ tx:
|
|
473
|
+
batch.push({ tx: prepareTransaction_1, recipient: sender.publicKey.toBase58() });
|
|
445
474
|
_s.label = 7;
|
|
446
475
|
case 7: return [4 /*yield*/, (0, utils_1.signAllTransactionWithRecipients)(sender, batch)];
|
|
447
476
|
case 8:
|
|
@@ -518,19 +547,44 @@ var SolanaStreamClient = /** @class */ (function (_super) {
|
|
|
518
547
|
/**
|
|
519
548
|
* Attempts withdrawing from the specified stream.
|
|
520
549
|
*/
|
|
521
|
-
SolanaStreamClient.prototype.withdraw = function (_a,
|
|
522
|
-
var id = _a.id,
|
|
523
|
-
|
|
550
|
+
SolanaStreamClient.prototype.withdraw = function (_a, extParams) {
|
|
551
|
+
var id = _a.id, _b = _a.amount, amount = _b === void 0 ? constants_2.WITHDRAW_AVAILABLE_AMOUNT : _b;
|
|
552
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
553
|
+
var ixs, _c, tx, hash, signature;
|
|
554
|
+
return __generator(this, function (_d) {
|
|
555
|
+
switch (_d.label) {
|
|
556
|
+
case 0: return [4 /*yield*/, this.prepareWithdawInstructions({ id: id, amount: amount }, extParams)];
|
|
557
|
+
case 1:
|
|
558
|
+
ixs = _d.sent();
|
|
559
|
+
return [4 /*yield*/, (0, utils_1.prepareTransaction)(this.connection, ixs, extParams.invoker.publicKey, this.getCommitment())];
|
|
560
|
+
case 2:
|
|
561
|
+
_c = _d.sent(), tx = _c.tx, hash = _c.hash;
|
|
562
|
+
return [4 /*yield*/, (0, utils_1.signAndExecuteTransaction)(this.connection, extParams.invoker, tx, hash)];
|
|
563
|
+
case 3:
|
|
564
|
+
signature = _d.sent();
|
|
565
|
+
return [2 /*return*/, { ixs: ixs, txId: signature }];
|
|
566
|
+
}
|
|
567
|
+
});
|
|
568
|
+
});
|
|
569
|
+
};
|
|
570
|
+
/**
|
|
571
|
+
* Creates Transaction Instructions for withdrawal
|
|
572
|
+
*/
|
|
573
|
+
SolanaStreamClient.prototype.prepareWithdawInstructions = function (_a, _b) {
|
|
574
|
+
var id = _a.id, _c = _a.amount, amount = _c === void 0 ? constants_2.WITHDRAW_AVAILABLE_AMOUNT : _c;
|
|
575
|
+
var invoker = _b.invoker, checkTokenAccounts = _b.checkTokenAccounts, computePrice = _b.computePrice, computeLimit = _b.computeLimit;
|
|
524
576
|
return __awaiter(this, void 0, void 0, function () {
|
|
525
|
-
var ixs, streamPublicKey, escrow, data, streamflowTreasuryTokens, partnerTokens
|
|
526
|
-
var _c;
|
|
577
|
+
var ixs, streamPublicKey, escrow, data, streamflowTreasuryTokens, partnerTokens;
|
|
527
578
|
return __generator(this, function (_d) {
|
|
528
579
|
switch (_d.label) {
|
|
529
580
|
case 0:
|
|
530
581
|
if (!invoker.publicKey) {
|
|
531
582
|
throw new Error("Invoker's PublicKey is not available, check passed wallet adapter!");
|
|
532
583
|
}
|
|
533
|
-
ixs =
|
|
584
|
+
ixs = this.prepareBaseInstructions({
|
|
585
|
+
computePrice: computePrice,
|
|
586
|
+
computeLimit: computeLimit,
|
|
587
|
+
});
|
|
534
588
|
streamPublicKey = new web3_js_1.PublicKey(id);
|
|
535
589
|
return [4 /*yield*/, this.connection.getAccountInfo(streamPublicKey)];
|
|
536
590
|
case 1:
|
|
@@ -561,19 +615,7 @@ var SolanaStreamClient = /** @class */ (function (_super) {
|
|
|
561
615
|
mint: data.mint,
|
|
562
616
|
tokenProgram: spl_token_1.TOKEN_PROGRAM_ID,
|
|
563
617
|
}));
|
|
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 }];
|
|
618
|
+
return [2 /*return*/, ixs];
|
|
577
619
|
}
|
|
578
620
|
});
|
|
579
621
|
});
|
|
@@ -581,14 +623,36 @@ var SolanaStreamClient = /** @class */ (function (_super) {
|
|
|
581
623
|
/**
|
|
582
624
|
* Attempts canceling the specified stream.
|
|
583
625
|
*/
|
|
584
|
-
SolanaStreamClient.prototype.cancel = function (_a,
|
|
626
|
+
SolanaStreamClient.prototype.cancel = function (_a, extParams) {
|
|
585
627
|
var id = _a.id;
|
|
586
|
-
var invoker = _b.invoker, checkTokenAccounts = _b.checkTokenAccounts;
|
|
587
628
|
return __awaiter(this, void 0, void 0, function () {
|
|
588
|
-
var
|
|
589
|
-
|
|
590
|
-
|
|
591
|
-
|
|
629
|
+
var ixs, _b, tx, hash, signature;
|
|
630
|
+
return __generator(this, function (_c) {
|
|
631
|
+
switch (_c.label) {
|
|
632
|
+
case 0: return [4 /*yield*/, this.prepareCancelInstructions({ id: id }, extParams)];
|
|
633
|
+
case 1:
|
|
634
|
+
ixs = _c.sent();
|
|
635
|
+
return [4 /*yield*/, (0, utils_1.prepareTransaction)(this.connection, ixs, extParams.invoker.publicKey, this.getCommitment())];
|
|
636
|
+
case 2:
|
|
637
|
+
_b = _c.sent(), tx = _b.tx, hash = _b.hash;
|
|
638
|
+
return [4 /*yield*/, (0, utils_1.signAndExecuteTransaction)(this.connection, extParams.invoker, tx, hash)];
|
|
639
|
+
case 3:
|
|
640
|
+
signature = _c.sent();
|
|
641
|
+
return [2 /*return*/, { ixs: ixs, txId: signature }];
|
|
642
|
+
}
|
|
643
|
+
});
|
|
644
|
+
});
|
|
645
|
+
};
|
|
646
|
+
/**
|
|
647
|
+
* Creates Transaction Instructions for cancel
|
|
648
|
+
*/
|
|
649
|
+
SolanaStreamClient.prototype.prepareCancelInstructions = function (_a, _b) {
|
|
650
|
+
var id = _a.id;
|
|
651
|
+
var invoker = _b.invoker, checkTokenAccounts = _b.checkTokenAccounts, computePrice = _b.computePrice, computeLimit = _b.computeLimit;
|
|
652
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
653
|
+
var streamPublicKey, escrowAcc, data, streamflowTreasuryTokens, partnerTokens, ixs;
|
|
654
|
+
return __generator(this, function (_c) {
|
|
655
|
+
switch (_c.label) {
|
|
592
656
|
case 0:
|
|
593
657
|
if (!invoker.publicKey) {
|
|
594
658
|
throw new Error("Invoker's PublicKey is not available, check passed wallet adapter!");
|
|
@@ -596,21 +660,24 @@ var SolanaStreamClient = /** @class */ (function (_super) {
|
|
|
596
660
|
streamPublicKey = new web3_js_1.PublicKey(id);
|
|
597
661
|
return [4 /*yield*/, this.connection.getAccountInfo(streamPublicKey)];
|
|
598
662
|
case 1:
|
|
599
|
-
escrowAcc =
|
|
663
|
+
escrowAcc = _c.sent();
|
|
600
664
|
if (!(escrowAcc === null || escrowAcc === void 0 ? void 0 : escrowAcc.data)) {
|
|
601
665
|
throw new Error("Couldn't get account info");
|
|
602
666
|
}
|
|
603
667
|
data = (0, utils_1.decodeStream)(escrowAcc === null || escrowAcc === void 0 ? void 0 : escrowAcc.data);
|
|
604
668
|
return [4 /*yield*/, (0, utils_1.ata)(data.mint, constants_1.STREAMFLOW_TREASURY_PUBLIC_KEY)];
|
|
605
669
|
case 2:
|
|
606
|
-
streamflowTreasuryTokens =
|
|
670
|
+
streamflowTreasuryTokens = _c.sent();
|
|
607
671
|
return [4 /*yield*/, (0, utils_1.ata)(data.mint, data.partner)];
|
|
608
672
|
case 3:
|
|
609
|
-
partnerTokens =
|
|
610
|
-
ixs =
|
|
673
|
+
partnerTokens = _c.sent();
|
|
674
|
+
ixs = this.prepareBaseInstructions({
|
|
675
|
+
computePrice: computePrice,
|
|
676
|
+
computeLimit: computeLimit,
|
|
677
|
+
});
|
|
611
678
|
return [4 /*yield*/, this.checkAssociatedTokenAccounts(data, { invoker: invoker, checkTokenAccounts: checkTokenAccounts }, ixs)];
|
|
612
679
|
case 4:
|
|
613
|
-
|
|
680
|
+
_c.sent();
|
|
614
681
|
ixs.push((0, instructions_1.cancelStreamInstruction)(this.programId, {
|
|
615
682
|
authority: invoker.publicKey,
|
|
616
683
|
sender: data.sender,
|
|
@@ -626,18 +693,30 @@ var SolanaStreamClient = /** @class */ (function (_super) {
|
|
|
626
693
|
mint: data.mint,
|
|
627
694
|
tokenProgram: spl_token_1.TOKEN_PROGRAM_ID,
|
|
628
695
|
}));
|
|
629
|
-
|
|
630
|
-
|
|
631
|
-
|
|
632
|
-
|
|
633
|
-
|
|
634
|
-
|
|
635
|
-
|
|
636
|
-
|
|
637
|
-
|
|
638
|
-
|
|
639
|
-
|
|
640
|
-
|
|
696
|
+
return [2 /*return*/, ixs];
|
|
697
|
+
}
|
|
698
|
+
});
|
|
699
|
+
});
|
|
700
|
+
};
|
|
701
|
+
/**
|
|
702
|
+
* Attempts changing the stream/vesting contract's recipient (effectively transferring the stream/vesting contract).
|
|
703
|
+
* Potential associated token account rent fee (to make it rent-exempt) is paid by the transaction initiator.
|
|
704
|
+
*/
|
|
705
|
+
SolanaStreamClient.prototype.transfer = function (_a, extParams) {
|
|
706
|
+
var id = _a.id, newRecipient = _a.newRecipient;
|
|
707
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
708
|
+
var ixs, _b, tx, hash, signature;
|
|
709
|
+
return __generator(this, function (_c) {
|
|
710
|
+
switch (_c.label) {
|
|
711
|
+
case 0: return [4 /*yield*/, this.prepareTransferInstructions({ id: id, newRecipient: newRecipient }, extParams)];
|
|
712
|
+
case 1:
|
|
713
|
+
ixs = _c.sent();
|
|
714
|
+
return [4 /*yield*/, (0, utils_1.prepareTransaction)(this.connection, ixs, extParams.invoker.publicKey, this.getCommitment())];
|
|
715
|
+
case 2:
|
|
716
|
+
_b = _c.sent(), tx = _b.tx, hash = _b.hash;
|
|
717
|
+
return [4 /*yield*/, (0, utils_1.signAndExecuteTransaction)(this.connection, extParams.invoker, tx, hash)];
|
|
718
|
+
case 3:
|
|
719
|
+
signature = _c.sent();
|
|
641
720
|
return [2 /*return*/, { ixs: ixs, txId: signature }];
|
|
642
721
|
}
|
|
643
722
|
});
|
|
@@ -647,21 +726,23 @@ var SolanaStreamClient = /** @class */ (function (_super) {
|
|
|
647
726
|
* Attempts changing the stream/vesting contract's recipient (effectively transferring the stream/vesting contract).
|
|
648
727
|
* Potential associated token account rent fee (to make it rent-exempt) is paid by the transaction initiator.
|
|
649
728
|
*/
|
|
650
|
-
SolanaStreamClient.prototype.
|
|
651
|
-
var id = _a.id,
|
|
652
|
-
var invoker = _b.invoker;
|
|
729
|
+
SolanaStreamClient.prototype.prepareTransferInstructions = function (_a, _b) {
|
|
730
|
+
var id = _a.id, newRecipient = _a.newRecipient;
|
|
731
|
+
var invoker = _b.invoker, computePrice = _b.computePrice, _c = _b.computeLimit, computeLimit = _c === void 0 ? 100001 : _c;
|
|
653
732
|
return __awaiter(this, void 0, void 0, function () {
|
|
654
|
-
var ixs, stream,
|
|
655
|
-
var _c;
|
|
733
|
+
var ixs, stream, newRecipientPublicKey, escrow, mint, newRecipientTokens;
|
|
656
734
|
return __generator(this, function (_d) {
|
|
657
735
|
switch (_d.label) {
|
|
658
736
|
case 0:
|
|
659
737
|
if (!invoker.publicKey) {
|
|
660
738
|
throw new Error("Invoker's PublicKey is not available, check passed wallet adapter!");
|
|
661
739
|
}
|
|
662
|
-
ixs =
|
|
740
|
+
ixs = this.prepareBaseInstructions({
|
|
741
|
+
computePrice: computePrice,
|
|
742
|
+
computeLimit: computeLimit,
|
|
743
|
+
});
|
|
663
744
|
stream = new web3_js_1.PublicKey(id);
|
|
664
|
-
|
|
745
|
+
newRecipientPublicKey = new web3_js_1.PublicKey(newRecipient);
|
|
665
746
|
return [4 /*yield*/, this.connection.getAccountInfo(stream)];
|
|
666
747
|
case 1:
|
|
667
748
|
escrow = _d.sent();
|
|
@@ -669,13 +750,12 @@ var SolanaStreamClient = /** @class */ (function (_super) {
|
|
|
669
750
|
throw new Error("Couldn't get account info");
|
|
670
751
|
}
|
|
671
752
|
mint = (0, utils_1.decodeStream)(escrow === null || escrow === void 0 ? void 0 : escrow.data).mint;
|
|
672
|
-
return [4 /*yield*/, (0, utils_1.ata)(mint,
|
|
753
|
+
return [4 /*yield*/, (0, utils_1.ata)(mint, newRecipientPublicKey)];
|
|
673
754
|
case 2:
|
|
674
755
|
newRecipientTokens = _d.sent();
|
|
675
|
-
ixs.push(web3_js_1.ComputeBudgetProgram.setComputeUnitLimit({ units: 100001 }));
|
|
676
756
|
ixs.push((0, instructions_1.transferStreamInstruction)(this.programId, {
|
|
677
757
|
authority: invoker.publicKey,
|
|
678
|
-
newRecipient:
|
|
758
|
+
newRecipient: newRecipientPublicKey,
|
|
679
759
|
newRecipientTokens: newRecipientTokens,
|
|
680
760
|
metadata: stream,
|
|
681
761
|
mint: mint,
|
|
@@ -684,63 +764,75 @@ var SolanaStreamClient = /** @class */ (function (_super) {
|
|
|
684
764
|
associatedTokenProgram: spl_token_1.ASSOCIATED_TOKEN_PROGRAM_ID,
|
|
685
765
|
systemProgram: web3_js_1.SystemProgram.programId,
|
|
686
766
|
}));
|
|
687
|
-
|
|
688
|
-
|
|
767
|
+
return [2 /*return*/, ixs];
|
|
768
|
+
}
|
|
769
|
+
});
|
|
770
|
+
});
|
|
771
|
+
};
|
|
772
|
+
/**
|
|
773
|
+
* Tops up stream account with specified amount.
|
|
774
|
+
*/
|
|
775
|
+
SolanaStreamClient.prototype.topup = function (_a, extParams) {
|
|
776
|
+
var id = _a.id, amount = _a.amount;
|
|
777
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
778
|
+
var ixs, _b, tx, hash, signature;
|
|
779
|
+
return __generator(this, function (_c) {
|
|
780
|
+
switch (_c.label) {
|
|
781
|
+
case 0: return [4 /*yield*/, this.prepareTopupInstructions({ id: id, amount: amount }, extParams)];
|
|
782
|
+
case 1:
|
|
783
|
+
ixs = _c.sent();
|
|
784
|
+
return [4 /*yield*/, (0, utils_1.prepareTransaction)(this.connection, ixs, extParams.invoker.publicKey, this.getCommitment())];
|
|
785
|
+
case 2:
|
|
786
|
+
_b = _c.sent(), tx = _b.tx, hash = _b.hash;
|
|
787
|
+
return [4 /*yield*/, (0, utils_1.signAndExecuteTransaction)(this.connection, extParams.invoker, tx, hash)];
|
|
689
788
|
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();
|
|
789
|
+
signature = _c.sent();
|
|
699
790
|
return [2 /*return*/, { ixs: ixs, txId: signature }];
|
|
700
791
|
}
|
|
701
792
|
});
|
|
702
793
|
});
|
|
703
794
|
};
|
|
704
795
|
/**
|
|
705
|
-
*
|
|
796
|
+
* Create Transaction instructions for topup
|
|
706
797
|
*/
|
|
707
|
-
SolanaStreamClient.prototype.
|
|
798
|
+
SolanaStreamClient.prototype.prepareTopupInstructions = function (_a, _b) {
|
|
708
799
|
var id = _a.id, amount = _a.amount;
|
|
709
|
-
var invoker = _b.invoker, isNative = _b.isNative;
|
|
800
|
+
var invoker = _b.invoker, isNative = _b.isNative, computePrice = _b.computePrice, computeLimit = _b.computeLimit;
|
|
710
801
|
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) {
|
|
802
|
+
var ixs, streamPublicKey, escrow, _c, mint, partner, senderTokens, escrowTokens, streamflowTreasuryTokens, partnerTokens, _d, _e, _f, _g;
|
|
803
|
+
return __generator(this, function (_h) {
|
|
804
|
+
switch (_h.label) {
|
|
715
805
|
case 0:
|
|
716
806
|
if (!invoker.publicKey) {
|
|
717
807
|
throw new Error("Invoker's PublicKey is not available, check passed wallet adapter!");
|
|
718
808
|
}
|
|
719
|
-
ixs =
|
|
809
|
+
ixs = this.prepareBaseInstructions({
|
|
810
|
+
computePrice: computePrice,
|
|
811
|
+
computeLimit: computeLimit,
|
|
812
|
+
});
|
|
720
813
|
streamPublicKey = new web3_js_1.PublicKey(id);
|
|
721
814
|
return [4 /*yield*/, this.connection.getAccountInfo(streamPublicKey)];
|
|
722
815
|
case 1:
|
|
723
|
-
escrow =
|
|
816
|
+
escrow = _h.sent();
|
|
724
817
|
if (!(escrow === null || escrow === void 0 ? void 0 : escrow.data)) {
|
|
725
818
|
throw new Error("Couldn't get account info");
|
|
726
819
|
}
|
|
727
820
|
_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
821
|
return [4 /*yield*/, (0, utils_1.ata)(mint, constants_1.STREAMFLOW_TREASURY_PUBLIC_KEY)];
|
|
729
822
|
case 2:
|
|
730
|
-
streamflowTreasuryTokens =
|
|
823
|
+
streamflowTreasuryTokens = _h.sent();
|
|
731
824
|
return [4 /*yield*/, (0, utils_1.ata)(mint, partner)];
|
|
732
825
|
case 3:
|
|
733
|
-
partnerTokens =
|
|
826
|
+
partnerTokens = _h.sent();
|
|
734
827
|
if (!isNative) return [3 /*break*/, 5];
|
|
828
|
+
_e = (_d = ixs.push).apply;
|
|
829
|
+
_f = [ixs];
|
|
830
|
+
_g = [[]];
|
|
735
831
|
return [4 /*yield*/, (0, instructions_1.prepareWrappedAccount)(this.connection, invoker.publicKey, amount)];
|
|
736
832
|
case 4:
|
|
737
|
-
_d
|
|
738
|
-
|
|
833
|
+
_e.apply(_d, _f.concat([__spreadArray.apply(void 0, _g.concat([__read.apply(void 0, [(_h.sent())]), false]))]));
|
|
834
|
+
_h.label = 5;
|
|
739
835
|
case 5:
|
|
740
|
-
_d = [];
|
|
741
|
-
_f.label = 6;
|
|
742
|
-
case 6:
|
|
743
|
-
nativeInstructions = _d;
|
|
744
836
|
ixs.push((0, instructions_1.topupStreamInstruction)(amount, this.programId, {
|
|
745
837
|
sender: invoker.publicKey,
|
|
746
838
|
senderTokens: senderTokens,
|
|
@@ -755,19 +847,7 @@ var SolanaStreamClient = /** @class */ (function (_super) {
|
|
|
755
847
|
withdrawor: constants_1.WITHDRAWOR_PUBLIC_KEY,
|
|
756
848
|
systemProgram: web3_js_1.SystemProgram.programId,
|
|
757
849
|
}));
|
|
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 }];
|
|
850
|
+
return [2 /*return*/, ixs];
|
|
771
851
|
}
|
|
772
852
|
});
|
|
773
853
|
});
|
|
@@ -842,10 +922,35 @@ var SolanaStreamClient = /** @class */ (function (_super) {
|
|
|
842
922
|
/**
|
|
843
923
|
* Attempts updating the stream auto withdrawal params and amount per period
|
|
844
924
|
*/
|
|
845
|
-
SolanaStreamClient.prototype.update = function (data,
|
|
846
|
-
|
|
925
|
+
SolanaStreamClient.prototype.update = function (data, extParams) {
|
|
926
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
927
|
+
var ixs, _a, tx, hash, signature;
|
|
928
|
+
return __generator(this, function (_b) {
|
|
929
|
+
switch (_b.label) {
|
|
930
|
+
case 0: return [4 /*yield*/, this.prepareUpdateInstructions(data, extParams)];
|
|
931
|
+
case 1:
|
|
932
|
+
ixs = _b.sent();
|
|
933
|
+
return [4 /*yield*/, (0, utils_1.prepareTransaction)(this.connection, ixs, extParams.invoker.publicKey, this.getCommitment())];
|
|
934
|
+
case 2:
|
|
935
|
+
_a = _b.sent(), tx = _a.tx, hash = _a.hash;
|
|
936
|
+
return [4 /*yield*/, (0, utils_1.signAndExecuteTransaction)(this.connection, extParams.invoker, tx, hash)];
|
|
937
|
+
case 3:
|
|
938
|
+
signature = _b.sent();
|
|
939
|
+
return [2 /*return*/, {
|
|
940
|
+
ixs: ixs,
|
|
941
|
+
txId: signature,
|
|
942
|
+
}];
|
|
943
|
+
}
|
|
944
|
+
});
|
|
945
|
+
});
|
|
946
|
+
};
|
|
947
|
+
/**
|
|
948
|
+
* Create Transaction instructions for update
|
|
949
|
+
*/
|
|
950
|
+
SolanaStreamClient.prototype.prepareUpdateInstructions = function (data, _a) {
|
|
951
|
+
var invoker = _a.invoker, computePrice = _a.computePrice, computeLimit = _a.computeLimit;
|
|
847
952
|
return __awaiter(this, void 0, void 0, function () {
|
|
848
|
-
var streamPublicKey, escrow,
|
|
953
|
+
var streamPublicKey, escrow, ixs;
|
|
849
954
|
return __generator(this, function (_b) {
|
|
850
955
|
switch (_b.label) {
|
|
851
956
|
case 0:
|
|
@@ -859,28 +964,17 @@ var SolanaStreamClient = /** @class */ (function (_super) {
|
|
|
859
964
|
if (!escrow) {
|
|
860
965
|
throw new Error("Couldn't get account info");
|
|
861
966
|
}
|
|
862
|
-
|
|
967
|
+
ixs = this.prepareBaseInstructions({
|
|
968
|
+
computePrice: computePrice,
|
|
969
|
+
computeLimit: computeLimit,
|
|
970
|
+
});
|
|
971
|
+
ixs.push((0, instructions_1.updateStreamInstruction)(data, this.programId, {
|
|
863
972
|
authority: invoker.publicKey,
|
|
864
973
|
metadata: streamPublicKey,
|
|
865
974
|
withdrawor: constants_1.WITHDRAWOR_PUBLIC_KEY,
|
|
866
975
|
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
|
-
}];
|
|
976
|
+
}));
|
|
977
|
+
return [2 /*return*/, ixs];
|
|
884
978
|
}
|
|
885
979
|
});
|
|
886
980
|
});
|
|
@@ -926,14 +1020,14 @@ var SolanaStreamClient = /** @class */ (function (_super) {
|
|
|
926
1020
|
/**
|
|
927
1021
|
* Forms instructions from params, creates a raw transaction and fetch recent blockhash.
|
|
928
1022
|
*/
|
|
929
|
-
SolanaStreamClient.prototype.prepareStreamInstructions = function (recipient, streamParams,
|
|
1023
|
+
SolanaStreamClient.prototype.prepareStreamInstructions = function (recipient, streamParams, extParams) {
|
|
930
1024
|
return __awaiter(this, void 0, void 0, function () {
|
|
931
1025
|
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;
|
|
932
1026
|
return __generator(this, function (_e) {
|
|
933
1027
|
switch (_e.label) {
|
|
934
1028
|
case 0:
|
|
935
1029
|
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;
|
|
936
|
-
sender =
|
|
1030
|
+
sender = extParams.sender, metadataPubKeys = extParams.metadataPubKeys;
|
|
937
1031
|
if (!sender.publicKey) {
|
|
938
1032
|
throw new Error("Sender's PublicKey is not available, check passed wallet adapter!");
|
|
939
1033
|
}
|
|
@@ -995,6 +1089,37 @@ var SolanaStreamClient = /** @class */ (function (_super) {
|
|
|
995
1089
|
});
|
|
996
1090
|
});
|
|
997
1091
|
};
|
|
1092
|
+
/**
|
|
1093
|
+
* Create Base instructions for Solana
|
|
1094
|
+
* - sets compute price if `computePrice` is provided
|
|
1095
|
+
* - sets compute limit if `computeLimit` is provided
|
|
1096
|
+
*/
|
|
1097
|
+
SolanaStreamClient.prototype.prepareBaseInstructions = function (_a) {
|
|
1098
|
+
var computePrice = _a.computePrice, computeLimit = _a.computeLimit;
|
|
1099
|
+
var ixs = [];
|
|
1100
|
+
if (computePrice) {
|
|
1101
|
+
ixs.push(web3_js_1.ComputeBudgetProgram.setComputeUnitPrice({ microLamports: computePrice }));
|
|
1102
|
+
}
|
|
1103
|
+
if (computeLimit) {
|
|
1104
|
+
ixs.push(web3_js_1.ComputeBudgetProgram.setComputeUnitLimit({ units: computeLimit }));
|
|
1105
|
+
}
|
|
1106
|
+
return ixs;
|
|
1107
|
+
};
|
|
1108
|
+
/**
|
|
1109
|
+
* Utility function to generate metadata for a Contract or return existing Pubkey
|
|
1110
|
+
*/
|
|
1111
|
+
SolanaStreamClient.prototype.getOrCreateStreamMetadata = function (metadataPubKeys) {
|
|
1112
|
+
var metadata;
|
|
1113
|
+
var metadataPubKey;
|
|
1114
|
+
if (!metadataPubKeys) {
|
|
1115
|
+
metadata = web3_js_1.Keypair.generate();
|
|
1116
|
+
metadataPubKey = metadata.publicKey;
|
|
1117
|
+
}
|
|
1118
|
+
else {
|
|
1119
|
+
metadataPubKey = metadataPubKeys[0];
|
|
1120
|
+
}
|
|
1121
|
+
return { metadata: metadata, metadataPubKey: metadataPubKey };
|
|
1122
|
+
};
|
|
998
1123
|
/**
|
|
999
1124
|
* Utility function that checks whether associated token accounts still exist and adds instructions to add them if not
|
|
1000
1125
|
*/
|
|
@@ -1034,21 +1159,6 @@ var SolanaStreamClient = /** @class */ (function (_super) {
|
|
|
1034
1159
|
});
|
|
1035
1160
|
});
|
|
1036
1161
|
};
|
|
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
1162
|
return SolanaStreamClient;
|
|
1053
1163
|
}(BaseStreamClient_1.BaseStreamClient));
|
|
1054
1164
|
exports.default = SolanaStreamClient;
|