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