@streamflow/stream 3.0.0-test.4 → 3.0.1-3.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/Stream.js +4 -4
- package/dist/StreamClient.d.ts +45 -6
- package/dist/StreamClient.js +425 -158
- package/dist/__tests__/test_dependencies/airdrop/airdrop-request.d.ts +3 -0
- package/dist/__tests__/test_dependencies/airdrop/airdrop-request.js +67 -0
- package/dist/__tests__/test_dependencies/airdrop/airdrop.d.ts +6 -0
- package/dist/__tests__/test_dependencies/airdrop/airdrop.js +215 -0
- package/dist/__tests__/test_dependencies/constants/index.d.ts +122 -0
- package/dist/__tests__/test_dependencies/constants/index.js +158 -0
- package/dist/__tests__/test_dependencies/idl/airdrop.d.ts +27 -0
- package/dist/__tests__/test_dependencies/idl/airdrop.js +171 -0
- package/dist/constants.d.ts +3 -0
- package/dist/constants.js +4 -1
- package/dist/{idl.d.ts → idl/timelock.d.ts} +0 -0
- package/dist/{idl.js → idl/timelock.js} +0 -0
- package/dist/index.js +5 -1
- package/dist/instructions.d.ts +36 -1
- package/dist/instructions.js +174 -4
- package/dist/layout.d.ts +4 -0
- package/dist/layout.js +24 -1
- package/dist/types.d.ts +90 -6
- package/dist/types.js +71 -1
- package/dist/utils.js +7 -2
- package/package.json +16 -2
package/dist/StreamClient.js
CHANGED
|
@@ -96,21 +96,30 @@ var types_1 = require("./types");
|
|
|
96
96
|
var utils_1 = require("./utils");
|
|
97
97
|
var constants_1 = require("./constants");
|
|
98
98
|
var instructions_1 = require("./instructions");
|
|
99
|
+
var bs58_1 = require("@project-serum/anchor/dist/cjs/utils/bytes/bs58");
|
|
100
|
+
var METADATA_ACC_SIZE = 1104;
|
|
99
101
|
var StreamClient = /** @class */ (function () {
|
|
100
102
|
/**
|
|
101
103
|
* Create Stream instance
|
|
102
104
|
*/
|
|
103
|
-
function StreamClient(clusterUrl, cluster, commitment) {
|
|
105
|
+
function StreamClient(clusterUrl, cluster, commitment, programId) {
|
|
104
106
|
if (cluster === void 0) { cluster = types_1.Cluster.Mainnet; }
|
|
105
107
|
if (commitment === void 0) { commitment = "confirmed"; }
|
|
108
|
+
if (programId === void 0) { programId = ""; }
|
|
106
109
|
this.commitment = commitment;
|
|
107
110
|
this.cluster = cluster;
|
|
108
111
|
this.connection = new web3_js_1.Connection(clusterUrl, this.commitment);
|
|
109
112
|
this.programId = new web3_js_1.PublicKey(constants_1.PROGRAM_ID[cluster]);
|
|
113
|
+
if (programId != "") {
|
|
114
|
+
this.programId = new web3_js_1.PublicKey(programId);
|
|
115
|
+
}
|
|
110
116
|
}
|
|
111
117
|
StreamClient.prototype.getConnection = function () {
|
|
112
118
|
return this.connection;
|
|
113
119
|
};
|
|
120
|
+
StreamClient.prototype.getProgramId = function () {
|
|
121
|
+
return this.programId.toBase58();
|
|
122
|
+
};
|
|
114
123
|
/**
|
|
115
124
|
* Creates a new stream/vesting contract.
|
|
116
125
|
* All fees are paid by sender (escrow metadata account rent, escrow token account rent, recipient's associated token account rent, Streamflow's service fee).
|
|
@@ -132,38 +141,49 @@ var StreamClient = /** @class */ (function () {
|
|
|
132
141
|
* @param {boolean} data.transferableByRecipient - Whether or not recipient can transfer the stream.
|
|
133
142
|
* @param {boolean} data.automaticWithdrawal - Whether or not a 3rd party can initiate withdraw in the name of recipient.
|
|
134
143
|
* @param {number} [data.withdrawalFrequency = 0] - Relevant when automatic withdrawal is enabled. If greater than 0 our withdrawor will take care of withdrawals. If equal to 0 our withdrawor will skip, but everyone else can initiate withdrawals.
|
|
144
|
+
* @param {boolean} [data.isNative = false] - When true Automatically wraps SOLs to WrappedSOL and creates wSOL stream
|
|
135
145
|
* @param {string | null} [data.partner = null] - Partner's wallet address (optional).
|
|
136
146
|
*/
|
|
137
147
|
StreamClient.prototype.create = function (_a) {
|
|
138
|
-
var sender = _a.sender, recipient = _a.recipient, mint = _a.mint, start = _a.start, depositedAmount = _a.depositedAmount, 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, _b = _a.automaticWithdrawal, automaticWithdrawal = _b === void 0 ? false : _b, _c = _a.withdrawalFrequency, withdrawalFrequency = _c === void 0 ? 0 : _c, _d = _a.partner, partner = _d === void 0 ? null : _d;
|
|
148
|
+
var sender = _a.sender, recipient = _a.recipient, mint = _a.mint, start = _a.start, depositedAmount = _a.depositedAmount, 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, _b = _a.automaticWithdrawal, automaticWithdrawal = _b === void 0 ? false : _b, _c = _a.withdrawalFrequency, withdrawalFrequency = _c === void 0 ? 0 : _c, _d = _a.partner, partner = _d === void 0 ? null : _d, _e = _a.isNative, isNative = _e === void 0 ? false : _e;
|
|
139
149
|
return __awaiter(this, void 0, void 0, function () {
|
|
140
|
-
var ixs, mintPublicKey, recipientPublicKey, metadata,
|
|
141
|
-
var
|
|
142
|
-
return __generator(this, function (
|
|
143
|
-
switch (
|
|
150
|
+
var ixs, mintPublicKey, recipientPublicKey, metadata, _f, escrowTokens, senderTokens, recipientTokens, streamflowTreasuryTokens, partnerPublicKey, partnerTokens, nativeInstructions, _g, commitment, hash, tx, signature;
|
|
151
|
+
var _h;
|
|
152
|
+
return __generator(this, function (_j) {
|
|
153
|
+
switch (_j.label) {
|
|
144
154
|
case 0:
|
|
145
155
|
ixs = [];
|
|
146
|
-
mintPublicKey = new web3_js_1.PublicKey(mint);
|
|
156
|
+
mintPublicKey = isNative ? new web3_js_1.PublicKey(mint) : spl_token_1.NATIVE_MINT;
|
|
147
157
|
recipientPublicKey = new web3_js_1.PublicKey(recipient);
|
|
148
158
|
metadata = web3_js_1.Keypair.generate();
|
|
149
159
|
return [4 /*yield*/, web3_js_1.PublicKey.findProgramAddress([buffer_1.Buffer.from("strm"), metadata.publicKey.toBuffer()], this.programId)];
|
|
150
160
|
case 1:
|
|
151
|
-
|
|
161
|
+
_f = __read.apply(void 0, [_j.sent(), 1]), escrowTokens = _f[0];
|
|
152
162
|
return [4 /*yield*/, ata(mintPublicKey, sender.publicKey)];
|
|
153
163
|
case 2:
|
|
154
|
-
senderTokens =
|
|
164
|
+
senderTokens = _j.sent();
|
|
155
165
|
return [4 /*yield*/, ata(mintPublicKey, recipientPublicKey)];
|
|
156
166
|
case 3:
|
|
157
|
-
recipientTokens =
|
|
167
|
+
recipientTokens = _j.sent();
|
|
158
168
|
return [4 /*yield*/, ata(mintPublicKey, constants_1.STREAMFLOW_TREASURY_PUBLIC_KEY)];
|
|
159
169
|
case 4:
|
|
160
|
-
streamflowTreasuryTokens =
|
|
170
|
+
streamflowTreasuryTokens = _j.sent();
|
|
161
171
|
partnerPublicKey = partner
|
|
162
172
|
? new web3_js_1.PublicKey(partner)
|
|
163
173
|
: constants_1.STREAMFLOW_TREASURY_PUBLIC_KEY;
|
|
164
174
|
return [4 /*yield*/, ata(mintPublicKey, partnerPublicKey)];
|
|
165
175
|
case 5:
|
|
166
|
-
partnerTokens =
|
|
176
|
+
partnerTokens = _j.sent();
|
|
177
|
+
if (!isNative) return [3 /*break*/, 7];
|
|
178
|
+
return [4 /*yield*/, (0, instructions_1.prepareWrappedAccount)(this.connection, sender.publicKey, depositedAmount)];
|
|
179
|
+
case 6:
|
|
180
|
+
_g = _j.sent();
|
|
181
|
+
return [3 /*break*/, 8];
|
|
182
|
+
case 7:
|
|
183
|
+
_g = [];
|
|
184
|
+
_j.label = 8;
|
|
185
|
+
case 8:
|
|
186
|
+
nativeInstructions = _g;
|
|
167
187
|
ixs.push((0, instructions_1.createStreamInstruction)({
|
|
168
188
|
start: new bn_js_1.default(start),
|
|
169
189
|
depositedAmount: depositedAmount,
|
|
@@ -202,34 +222,44 @@ var StreamClient = /** @class */ (function () {
|
|
|
202
222
|
commitment = typeof this.commitment == "string"
|
|
203
223
|
? this.commitment
|
|
204
224
|
: this.commitment.commitment;
|
|
205
|
-
return [4 /*yield*/, this.connection.
|
|
206
|
-
case
|
|
207
|
-
hash =
|
|
208
|
-
tx = (
|
|
225
|
+
return [4 /*yield*/, this.connection.getLatestBlockhash(commitment)];
|
|
226
|
+
case 9:
|
|
227
|
+
hash = _j.sent();
|
|
228
|
+
tx = (_h = new web3_js_1.Transaction({
|
|
209
229
|
feePayer: sender.publicKey,
|
|
210
|
-
|
|
211
|
-
|
|
230
|
+
blockhash: hash.blockhash,
|
|
231
|
+
lastValidBlockHeight: hash.lastValidBlockHeight,
|
|
232
|
+
})).add.apply(_h, __spreadArray(__spreadArray([], __read(nativeInstructions), false), __read(ixs), false));
|
|
212
233
|
tx.partialSign(metadata);
|
|
213
|
-
return [4 /*yield*/, this.sign(sender, tx)];
|
|
214
|
-
case
|
|
215
|
-
signature =
|
|
234
|
+
return [4 /*yield*/, this.sign(sender, tx, hash)];
|
|
235
|
+
case 10:
|
|
236
|
+
signature = _j.sent();
|
|
216
237
|
return [2 /*return*/, { ixs: ixs, tx: signature, metadata: metadata }];
|
|
217
238
|
}
|
|
218
239
|
});
|
|
219
240
|
});
|
|
220
241
|
};
|
|
221
242
|
/**
|
|
222
|
-
* Creates a new stream/vesting contract.
|
|
223
|
-
*
|
|
224
|
-
*
|
|
243
|
+
* Creates a new stream/vesting contract using unchecked instruction.
|
|
244
|
+
*
|
|
245
|
+
* Unchecked instruction differes from the regular in:
|
|
246
|
+
* - does not check for initialized associated token account (wallets with no control over their ATA should not be used
|
|
247
|
+
* as sender/recipient/partner or there are risks of funds being locked in the contract)
|
|
248
|
+
* - initialized contract PDA off chain
|
|
249
|
+
*
|
|
250
|
+
* If you are not sure if you should use create or create_unchecked, go for create to be safer.
|
|
251
|
+
*
|
|
252
|
+
* @param {CreateParams} data
|
|
225
253
|
* @param {Wallet | Keypair} data.sender - Wallet signing the transaction. Its address should match the authorized wallet (sender) or transaction will fail.
|
|
226
|
-
* @param {
|
|
254
|
+
* @param {string} data.recipient - Solana address of the recipient. Associated token account will be derived using this address and token mint address.
|
|
227
255
|
* @param {string} data.mint - SPL Token mint.
|
|
228
256
|
* @param {number} data.start - Timestamp (in seconds) when the stream/token vesting starts.
|
|
257
|
+
* @param {BN} data.depositedAmount - Initially deposited amount of tokens (in the smallest units).
|
|
229
258
|
* @param {number} data.period - Time step (period) in seconds per which the unlocking occurs.
|
|
230
259
|
* @param {number} data.cliff - Vesting contract "cliff" timestamp in seconds.
|
|
231
260
|
* @param {BN} data.cliffAmount - Amount unlocked at the "cliff".
|
|
232
261
|
* @param {BN} data.amountPerPeriod - Amount unlocked per each period.
|
|
262
|
+
* @param {string} data.name - Stream name/subject.
|
|
233
263
|
* @param {boolean} data.canTopup - TRUE for streams, FALSE for vesting contracts.
|
|
234
264
|
* @param {boolean} data.cancelableBySender - Whether or not sender can cancel the stream.
|
|
235
265
|
* @param {boolean} data.cancelableByRecipient - Whether or not recipient can cancel the stream.
|
|
@@ -237,53 +267,52 @@ var StreamClient = /** @class */ (function () {
|
|
|
237
267
|
* @param {boolean} data.transferableByRecipient - Whether or not recipient can transfer the stream.
|
|
238
268
|
* @param {boolean} data.automaticWithdrawal - Whether or not a 3rd party can initiate withdraw in the name of recipient.
|
|
239
269
|
* @param {number} [data.withdrawalFrequency = 0] - Relevant when automatic withdrawal is enabled. If greater than 0 our withdrawor will take care of withdrawals. If equal to 0 our withdrawor will skip, but everyone else can initiate withdrawals.
|
|
240
|
-
* @param {
|
|
270
|
+
* @param {boolean} [data.isNative = false] - When true Automatically wraps SOLs to WrappedSOL and creates wSOL stream
|
|
271
|
+
* @param {string | null} [data.partner = null] - Partner's wallet address (optional).
|
|
241
272
|
*/
|
|
242
|
-
StreamClient.prototype.
|
|
243
|
-
var sender = _a.sender,
|
|
273
|
+
StreamClient.prototype.createUnchecked = function (_a) {
|
|
274
|
+
var sender = _a.sender, recipient = _a.recipient, mint = _a.mint, start = _a.start, depositedAmount = _a.depositedAmount, 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, _b = _a.automaticWithdrawal, automaticWithdrawal = _b === void 0 ? false : _b, _c = _a.withdrawalFrequency, withdrawalFrequency = _c === void 0 ? 0 : _c, _d = _a.partner, partner = _d === void 0 ? null : _d, _e = _a.isNative, isNative = _e === void 0 ? false : _e;
|
|
244
275
|
return __awaiter(this, void 0, void 0, function () {
|
|
245
|
-
var mintPublicKey,
|
|
246
|
-
var
|
|
247
|
-
return __generator(this, function (
|
|
248
|
-
switch (
|
|
276
|
+
var mintPublicKey, recipientPublicKey, metadata, rentToExempt, createMetadataInstruction, _f, escrowTokens, senderTokens, partnerPublicKey, nativeInstructions, _g, createInstruction, commitment, ixs, hash, tx, signature;
|
|
277
|
+
var _h;
|
|
278
|
+
return __generator(this, function (_j) {
|
|
279
|
+
switch (_j.label) {
|
|
249
280
|
case 0:
|
|
250
281
|
mintPublicKey = new web3_js_1.PublicKey(mint);
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
: this.commitment.commitment;
|
|
255
|
-
_h.label = 1;
|
|
282
|
+
recipientPublicKey = new web3_js_1.PublicKey(recipient);
|
|
283
|
+
metadata = web3_js_1.Keypair.generate();
|
|
284
|
+
return [4 /*yield*/, this.connection.getMinimumBalanceForRentExemption(METADATA_ACC_SIZE)];
|
|
256
285
|
case 1:
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
286
|
+
rentToExempt = _j.sent();
|
|
287
|
+
createMetadataInstruction = web3_js_1.SystemProgram.createAccount({
|
|
288
|
+
programId: this.programId,
|
|
289
|
+
space: METADATA_ACC_SIZE,
|
|
290
|
+
lamports: rentToExempt,
|
|
291
|
+
fromPubkey: sender === null || sender === void 0 ? void 0 : sender.publicKey,
|
|
292
|
+
newAccountPubkey: metadata.publicKey,
|
|
293
|
+
});
|
|
294
|
+
return [4 /*yield*/, web3_js_1.PublicKey.findProgramAddress([buffer_1.Buffer.from("strm"), metadata.publicKey.toBuffer()], this.programId)];
|
|
260
295
|
case 2:
|
|
261
|
-
|
|
262
|
-
recipient = recipientsData_1_1.value;
|
|
263
|
-
ixs = [];
|
|
264
|
-
recipientPublicKey = new web3_js_1.PublicKey(recipient.recipient);
|
|
265
|
-
metadata = web3_js_1.Keypair.generate();
|
|
266
|
-
return [4 /*yield*/, anchor_1.web3.PublicKey.findProgramAddress([buffer_1.Buffer.from("strm"), metadata.publicKey.toBuffer()], this.programId)];
|
|
267
|
-
case 3:
|
|
268
|
-
_e = __read.apply(void 0, [_h.sent(), 1]), escrowTokens = _e[0];
|
|
296
|
+
_f = __read.apply(void 0, [_j.sent(), 1]), escrowTokens = _f[0];
|
|
269
297
|
return [4 /*yield*/, ata(mintPublicKey, sender.publicKey)];
|
|
270
|
-
case
|
|
271
|
-
senderTokens =
|
|
272
|
-
return [4 /*yield*/, ata(mintPublicKey, recipientPublicKey)];
|
|
273
|
-
case 5:
|
|
274
|
-
recipientTokens = _h.sent();
|
|
275
|
-
return [4 /*yield*/, ata(mintPublicKey, constants_1.STREAMFLOW_TREASURY_PUBLIC_KEY)];
|
|
276
|
-
case 6:
|
|
277
|
-
streamflowTreasuryTokens = _h.sent();
|
|
298
|
+
case 3:
|
|
299
|
+
senderTokens = _j.sent();
|
|
278
300
|
partnerPublicKey = partner
|
|
279
301
|
? new web3_js_1.PublicKey(partner)
|
|
280
302
|
: constants_1.STREAMFLOW_TREASURY_PUBLIC_KEY;
|
|
281
|
-
return [
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
303
|
+
if (!isNative) return [3 /*break*/, 5];
|
|
304
|
+
return [4 /*yield*/, (0, instructions_1.prepareWrappedAccount)(this.connection, sender.publicKey, depositedAmount)];
|
|
305
|
+
case 4:
|
|
306
|
+
_g = _j.sent();
|
|
307
|
+
return [3 /*break*/, 6];
|
|
308
|
+
case 5:
|
|
309
|
+
_g = [];
|
|
310
|
+
_j.label = 6;
|
|
311
|
+
case 6:
|
|
312
|
+
nativeInstructions = _g;
|
|
313
|
+
createInstruction = (0, instructions_1.createUncheckedStreamInstruction)({
|
|
285
314
|
start: new bn_js_1.default(start),
|
|
286
|
-
depositedAmount:
|
|
315
|
+
depositedAmount: depositedAmount,
|
|
287
316
|
period: new bn_js_1.default(period),
|
|
288
317
|
amountPerPeriod: amountPerPeriod,
|
|
289
318
|
cliff: new bn_js_1.default(cliff),
|
|
@@ -294,84 +323,157 @@ var StreamClient = /** @class */ (function () {
|
|
|
294
323
|
transferableBySender: transferableBySender,
|
|
295
324
|
transferableByRecipient: transferableByRecipient,
|
|
296
325
|
canTopup: canTopup,
|
|
297
|
-
name:
|
|
326
|
+
name: name,
|
|
298
327
|
withdrawFrequency: new bn_js_1.default(automaticWithdrawal ? withdrawalFrequency : period),
|
|
328
|
+
recipient: recipientPublicKey,
|
|
329
|
+
partner: partnerPublicKey,
|
|
299
330
|
}, this.programId, {
|
|
300
331
|
sender: sender.publicKey,
|
|
301
332
|
senderTokens: senderTokens,
|
|
302
|
-
recipient: new web3_js_1.PublicKey(recipient.recipient),
|
|
303
333
|
metadata: metadata.publicKey,
|
|
304
334
|
escrowTokens: escrowTokens,
|
|
305
|
-
recipientTokens: recipientTokens,
|
|
306
|
-
streamflowTreasury: constants_1.STREAMFLOW_TREASURY_PUBLIC_KEY,
|
|
307
|
-
streamflowTreasuryTokens: streamflowTreasuryTokens,
|
|
308
|
-
partner: partnerPublicKey,
|
|
309
|
-
partnerTokens: partnerTokens,
|
|
310
335
|
mint: new web3_js_1.PublicKey(mint),
|
|
311
336
|
feeOracle: constants_1.FEE_ORACLE_PUBLIC_KEY,
|
|
312
337
|
rent: web3_js_1.SYSVAR_RENT_PUBKEY,
|
|
313
338
|
timelockProgram: this.programId,
|
|
314
339
|
tokenProgram: spl_token_1.TOKEN_PROGRAM_ID,
|
|
315
|
-
associatedTokenProgram: spl_token_1.ASSOCIATED_TOKEN_PROGRAM_ID,
|
|
316
340
|
withdrawor: constants_1.WITHDRAWOR_PUBLIC_KEY,
|
|
317
341
|
systemProgram: web3_js_1.SystemProgram.programId,
|
|
318
|
-
})
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
342
|
+
});
|
|
343
|
+
commitment = typeof this.commitment == "string"
|
|
344
|
+
? this.commitment
|
|
345
|
+
: this.commitment.commitment;
|
|
346
|
+
ixs = [
|
|
347
|
+
createMetadataInstruction,
|
|
348
|
+
createInstruction,
|
|
349
|
+
];
|
|
350
|
+
return [4 /*yield*/, this.connection.getLatestBlockhash(commitment)];
|
|
351
|
+
case 7:
|
|
352
|
+
hash = _j.sent();
|
|
353
|
+
tx = (_h = new web3_js_1.Transaction({
|
|
323
354
|
feePayer: sender.publicKey,
|
|
324
|
-
|
|
325
|
-
|
|
355
|
+
blockhash: hash.blockhash,
|
|
356
|
+
lastValidBlockHeight: hash.lastValidBlockHeight,
|
|
357
|
+
})).add.apply(_h, __spreadArray(__spreadArray([], __read(nativeInstructions), false), __read(ixs), false));
|
|
326
358
|
tx.partialSign(metadata);
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
359
|
+
return [4 /*yield*/, this.sign(sender, tx, hash)];
|
|
360
|
+
case 8:
|
|
361
|
+
signature = _j.sent();
|
|
362
|
+
return [2 /*return*/, { ixs: ixs, tx: signature, metadata: metadata }];
|
|
363
|
+
}
|
|
364
|
+
});
|
|
365
|
+
});
|
|
366
|
+
};
|
|
367
|
+
/**
|
|
368
|
+
* Creates a new stream/vesting contract.
|
|
369
|
+
* All fees are paid by sender (escrow metadata account rent, escrow token account rent, recipient's associated token account rent, Streamflow's service fee).
|
|
370
|
+
* @param {CreateMultiParams} data
|
|
371
|
+
* @param {Wallet | Keypair} data.sender - Wallet signing the transaction. Its address should match the authorized wallet (sender) or transaction will fail.
|
|
372
|
+
* @param {MultiRecipient[]} data.recipientsData
|
|
373
|
+
* @param {string} data.mint - SPL Token mint.
|
|
374
|
+
* @param {number} data.start - Timestamp (in seconds) when the stream/token vesting starts.
|
|
375
|
+
* @param {number} data.period - Time step (period) in seconds per which the unlocking occurs.
|
|
376
|
+
* @param {number} data.cliff - Vesting contract "cliff" timestamp in seconds.
|
|
377
|
+
* @param {boolean} data.canTopup - TRUE for streams, FALSE for vesting contracts.
|
|
378
|
+
* @param {boolean} data.cancelableBySender - Whether or not sender can cancel the stream.
|
|
379
|
+
* @param {boolean} data.cancelableByRecipient - Whether or not recipient can cancel the stream.
|
|
380
|
+
* @param {boolean} data.transferableBySender - Whether or not sender can transfer the stream.
|
|
381
|
+
* @param {boolean} data.transferableByRecipient - Whether or not recipient can transfer the stream.
|
|
382
|
+
* @param {boolean} data.automaticWithdrawal - Whether or not a 3rd party can initiate withdraw in the name of recipient.
|
|
383
|
+
* @param {number} [data.withdrawalFrequency = 0] - Relevant when automatic withdrawal is enabled. If greater than 0 our withdrawor will take care of withdrawals. If equal to 0 our withdrawor will skip, but everyone else can initiate withdrawals.
|
|
384
|
+
* @param {boolean} [data.isNative = false] - When true Automatically wraps SOLs to WrappedSOL and creates wSOL stream
|
|
385
|
+
* @param {string | null} [data.partner = null] - Partner's wallet address (optional).
|
|
386
|
+
*/
|
|
387
|
+
StreamClient.prototype.createMultiple = function (data) {
|
|
388
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
389
|
+
var sender, recipientsData, metadatas, metadataToRecipient, errors, signatures, batch, recipientsData_1, recipientsData_1_1, recipientData, _a, tx, metadata, metadataPubKey, e_1_1, totalDepositedAmount, nativeInstructions, commitment, hash, prepareTransaction, signed_batch, prepareTx, batchTransactionsCalls, responses, successes, failures;
|
|
390
|
+
var e_1, _b, _c;
|
|
391
|
+
var _this = this;
|
|
392
|
+
return __generator(this, function (_d) {
|
|
393
|
+
switch (_d.label) {
|
|
394
|
+
case 0:
|
|
395
|
+
sender = data.sender, recipientsData = data.recipientsData;
|
|
396
|
+
metadatas = [];
|
|
397
|
+
metadataToRecipient = {};
|
|
398
|
+
errors = [];
|
|
399
|
+
signatures = [];
|
|
400
|
+
batch = [];
|
|
401
|
+
_d.label = 1;
|
|
402
|
+
case 1:
|
|
403
|
+
_d.trys.push([1, 6, 7, 8]);
|
|
404
|
+
recipientsData_1 = __values(recipientsData), recipientsData_1_1 = recipientsData_1.next();
|
|
405
|
+
_d.label = 2;
|
|
406
|
+
case 2:
|
|
407
|
+
if (!!recipientsData_1_1.done) return [3 /*break*/, 5];
|
|
408
|
+
recipientData = recipientsData_1_1.value;
|
|
409
|
+
return [4 /*yield*/, this.prepareStreamTransaction(recipientData, data)];
|
|
410
|
+
case 3:
|
|
411
|
+
_a = _d.sent(), tx = _a.tx, metadata = _a.metadata;
|
|
412
|
+
metadataPubKey = metadata.publicKey.toBase58();
|
|
413
|
+
metadataToRecipient[metadataPubKey] = recipientData;
|
|
414
|
+
metadatas.push(metadata);
|
|
415
|
+
batch.push({ tx: tx, recipient: recipientData.recipient });
|
|
416
|
+
_d.label = 4;
|
|
417
|
+
case 4:
|
|
330
418
|
recipientsData_1_1 = recipientsData_1.next();
|
|
331
419
|
return [3 /*break*/, 2];
|
|
332
|
-
case
|
|
333
|
-
case
|
|
334
|
-
e_1_1 =
|
|
420
|
+
case 5: return [3 /*break*/, 8];
|
|
421
|
+
case 6:
|
|
422
|
+
e_1_1 = _d.sent();
|
|
335
423
|
e_1 = { error: e_1_1 };
|
|
336
|
-
return [3 /*break*/,
|
|
337
|
-
case
|
|
424
|
+
return [3 /*break*/, 8];
|
|
425
|
+
case 7:
|
|
338
426
|
try {
|
|
339
|
-
if (recipientsData_1_1 && !recipientsData_1_1.done && (
|
|
427
|
+
if (recipientsData_1_1 && !recipientsData_1_1.done && (_b = recipientsData_1.return)) _b.call(recipientsData_1);
|
|
340
428
|
}
|
|
341
429
|
finally { if (e_1) throw e_1.error; }
|
|
342
430
|
return [7 /*endfinally*/];
|
|
431
|
+
case 8:
|
|
432
|
+
if (!data.isNative) return [3 /*break*/, 11];
|
|
433
|
+
totalDepositedAmount = recipientsData.reduce(function (acc, recipient) { return recipient.depositedAmount.add(acc); }, new bn_js_1.default(0));
|
|
434
|
+
return [4 /*yield*/, (0, instructions_1.prepareWrappedAccount)(this.connection, sender.publicKey, totalDepositedAmount)];
|
|
435
|
+
case 9:
|
|
436
|
+
nativeInstructions = _d.sent();
|
|
437
|
+
commitment = typeof this.commitment == "string"
|
|
438
|
+
? this.commitment
|
|
439
|
+
: this.commitment.commitment;
|
|
440
|
+
return [4 /*yield*/, this.connection.getLatestBlockhash(commitment)];
|
|
441
|
+
case 10:
|
|
442
|
+
hash = _d.sent();
|
|
443
|
+
prepareTransaction = (_c = new web3_js_1.Transaction({
|
|
444
|
+
feePayer: sender.publicKey,
|
|
445
|
+
blockhash: hash.blockhash,
|
|
446
|
+
lastValidBlockHeight: hash.lastValidBlockHeight,
|
|
447
|
+
})).add.apply(_c, __spreadArray([], __read(nativeInstructions), false));
|
|
448
|
+
batch.push({ tx: prepareTransaction, recipient: sender.publicKey.toBase58() });
|
|
449
|
+
_d.label = 11;
|
|
450
|
+
case 11: return [4 /*yield*/, signAllTransactionWithRecipients(sender, batch)];
|
|
451
|
+
case 12:
|
|
452
|
+
signed_batch = _d.sent();
|
|
453
|
+
if (!data.isNative) return [3 /*break*/, 14];
|
|
454
|
+
prepareTx = signed_batch.pop();
|
|
455
|
+
return [4 /*yield*/, sendAndConfirmStreamRawTransaction(this.connection, prepareTx)];
|
|
343
456
|
case 13:
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
t.partialSign(sender);
|
|
347
|
-
return t;
|
|
348
|
-
});
|
|
349
|
-
return [3 /*break*/, 17];
|
|
457
|
+
_d.sent();
|
|
458
|
+
_d.label = 14;
|
|
350
459
|
case 14:
|
|
351
|
-
|
|
352
|
-
|
|
460
|
+
batchTransactionsCalls = signed_batch.map(function (el) {
|
|
461
|
+
return sendAndConfirmStreamRawTransaction(_this.connection, el);
|
|
462
|
+
});
|
|
463
|
+
return [4 /*yield*/, Promise.allSettled(batchTransactionsCalls)];
|
|
353
464
|
case 15:
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
return [4 /*yield*/, (0, web3_js_1.sendAndConfirmRawTransaction)(this.connection, buf)];
|
|
367
|
-
case 19:
|
|
368
|
-
signature = _h.sent();
|
|
369
|
-
sigs.push(signature);
|
|
370
|
-
_h.label = 20;
|
|
371
|
-
case 20:
|
|
372
|
-
i++;
|
|
373
|
-
return [3 /*break*/, 18];
|
|
374
|
-
case 21: return [2 /*return*/, { txs: sigs }];
|
|
465
|
+
responses = _d.sent();
|
|
466
|
+
successes = responses
|
|
467
|
+
.filter(function (el) {
|
|
468
|
+
return el.status === "fulfilled";
|
|
469
|
+
})
|
|
470
|
+
.map(function (el) { return el.value; });
|
|
471
|
+
signatures.push.apply(signatures, __spreadArray([], __read(successes.map(function (el) { return el.signature; })), false));
|
|
472
|
+
failures = responses
|
|
473
|
+
.filter(function (el) { return el.status === "rejected"; })
|
|
474
|
+
.map(function (el) { return el.reason; });
|
|
475
|
+
errors.push.apply(errors, __spreadArray([], __read(failures), false));
|
|
476
|
+
return [2 /*return*/, { txs: signatures, metadatas: metadatas, metadataToRecipient: metadataToRecipient, errors: errors }];
|
|
375
477
|
}
|
|
376
478
|
});
|
|
377
479
|
});
|
|
@@ -422,14 +524,15 @@ var StreamClient = /** @class */ (function () {
|
|
|
422
524
|
commitment = typeof this.commitment == "string"
|
|
423
525
|
? this.commitment
|
|
424
526
|
: this.commitment.commitment;
|
|
425
|
-
return [4 /*yield*/, this.connection.
|
|
527
|
+
return [4 /*yield*/, this.connection.getLatestBlockhash(commitment)];
|
|
426
528
|
case 4:
|
|
427
529
|
hash = _c.sent();
|
|
428
530
|
tx = (_b = new web3_js_1.Transaction({
|
|
429
531
|
feePayer: invoker.publicKey,
|
|
430
|
-
|
|
532
|
+
blockhash: hash.blockhash,
|
|
533
|
+
lastValidBlockHeight: hash.lastValidBlockHeight,
|
|
431
534
|
})).add.apply(_b, __spreadArray([], __read(ixs), false));
|
|
432
|
-
return [4 /*yield*/, this.sign(invoker, tx)];
|
|
535
|
+
return [4 /*yield*/, this.sign(invoker, tx, hash)];
|
|
433
536
|
case 5:
|
|
434
537
|
signature = _c.sent();
|
|
435
538
|
return [2 /*return*/, { ixs: ixs, tx: signature }];
|
|
@@ -484,14 +587,15 @@ var StreamClient = /** @class */ (function () {
|
|
|
484
587
|
commitment = typeof this.commitment == "string"
|
|
485
588
|
? this.commitment
|
|
486
589
|
: this.commitment.commitment;
|
|
487
|
-
return [4 /*yield*/, this.connection.
|
|
590
|
+
return [4 /*yield*/, this.connection.getLatestBlockhash(commitment)];
|
|
488
591
|
case 4:
|
|
489
592
|
hash = _c.sent();
|
|
490
593
|
tx = (_b = new web3_js_1.Transaction({
|
|
491
594
|
feePayer: invoker.publicKey,
|
|
492
|
-
|
|
595
|
+
blockhash: hash.blockhash,
|
|
596
|
+
lastValidBlockHeight: hash.lastValidBlockHeight,
|
|
493
597
|
})).add.apply(_b, __spreadArray([], __read(ixs), false));
|
|
494
|
-
return [4 /*yield*/, this.sign(invoker, tx)];
|
|
598
|
+
return [4 /*yield*/, this.sign(invoker, tx, hash)];
|
|
495
599
|
case 5:
|
|
496
600
|
signature = _c.sent();
|
|
497
601
|
return [2 /*return*/, { ixs: ixs, tx: signature }];
|
|
@@ -542,14 +646,15 @@ var StreamClient = /** @class */ (function () {
|
|
|
542
646
|
commitment = typeof this.commitment == "string"
|
|
543
647
|
? this.commitment
|
|
544
648
|
: this.commitment.commitment;
|
|
545
|
-
return [4 /*yield*/, this.connection.
|
|
649
|
+
return [4 /*yield*/, this.connection.getLatestBlockhash(commitment)];
|
|
546
650
|
case 3:
|
|
547
651
|
hash = _c.sent();
|
|
548
652
|
tx = (_b = new web3_js_1.Transaction({
|
|
549
653
|
feePayer: invoker.publicKey,
|
|
550
|
-
|
|
654
|
+
blockhash: hash.blockhash,
|
|
655
|
+
lastValidBlockHeight: hash.lastValidBlockHeight,
|
|
551
656
|
})).add.apply(_b, __spreadArray([], __read(ixs), false));
|
|
552
|
-
return [4 /*yield*/, this.sign(invoker, tx)];
|
|
657
|
+
return [4 /*yield*/, this.sign(invoker, tx, hash)];
|
|
553
658
|
case 4:
|
|
554
659
|
signature = _c.sent();
|
|
555
660
|
return [2 /*return*/, { ixs: ixs, tx: signature }];
|
|
@@ -565,28 +670,38 @@ var StreamClient = /** @class */ (function () {
|
|
|
565
670
|
* @param {BN} data.amount - Specified amount (in the smallest units) to topup (increases deposited amount).
|
|
566
671
|
*/
|
|
567
672
|
StreamClient.prototype.topup = function (_a) {
|
|
568
|
-
var invoker = _a.invoker, id = _a.id, amount = _a.amount;
|
|
673
|
+
var invoker = _a.invoker, id = _a.id, amount = _a.amount, isNative = _a.isNative;
|
|
569
674
|
return __awaiter(this, void 0, void 0, function () {
|
|
570
|
-
var ixs, streamPublicKey, escrow, _b, mint, partner, senderTokens, escrowTokens, streamflowTreasuryTokens, partnerTokens, commitment, hash, tx, signature;
|
|
571
|
-
var
|
|
572
|
-
return __generator(this, function (
|
|
573
|
-
switch (
|
|
675
|
+
var ixs, streamPublicKey, escrow, _b, mint, partner, senderTokens, escrowTokens, streamflowTreasuryTokens, partnerTokens, nativeInstructions, _c, commitment, hash, tx, signature;
|
|
676
|
+
var _d;
|
|
677
|
+
return __generator(this, function (_e) {
|
|
678
|
+
switch (_e.label) {
|
|
574
679
|
case 0:
|
|
575
680
|
ixs = [];
|
|
576
681
|
streamPublicKey = new web3_js_1.PublicKey(id);
|
|
577
682
|
return [4 /*yield*/, this.connection.getAccountInfo(streamPublicKey)];
|
|
578
683
|
case 1:
|
|
579
|
-
escrow =
|
|
684
|
+
escrow = _e.sent();
|
|
580
685
|
if (!(escrow === null || escrow === void 0 ? void 0 : escrow.data)) {
|
|
581
686
|
throw new Error("Couldn't get account info");
|
|
582
687
|
}
|
|
583
688
|
_b = (0, utils_1.decodeStream)(escrow === null || escrow === void 0 ? void 0 : escrow.data), mint = _b.mint, partner = _b.partner, senderTokens = _b.senderTokens, escrowTokens = _b.escrowTokens;
|
|
584
689
|
return [4 /*yield*/, ata(mint, constants_1.STREAMFLOW_TREASURY_PUBLIC_KEY)];
|
|
585
690
|
case 2:
|
|
586
|
-
streamflowTreasuryTokens =
|
|
691
|
+
streamflowTreasuryTokens = _e.sent();
|
|
587
692
|
return [4 /*yield*/, ata(mint, partner)];
|
|
588
693
|
case 3:
|
|
589
|
-
partnerTokens =
|
|
694
|
+
partnerTokens = _e.sent();
|
|
695
|
+
if (!isNative) return [3 /*break*/, 5];
|
|
696
|
+
return [4 /*yield*/, (0, instructions_1.prepareWrappedAccount)(this.connection, invoker.publicKey, amount)];
|
|
697
|
+
case 4:
|
|
698
|
+
_c = _e.sent();
|
|
699
|
+
return [3 /*break*/, 6];
|
|
700
|
+
case 5:
|
|
701
|
+
_c = [];
|
|
702
|
+
_e.label = 6;
|
|
703
|
+
case 6:
|
|
704
|
+
nativeInstructions = _c;
|
|
590
705
|
ixs.push((0, instructions_1.topupStreamInstruction)(amount, this.programId, {
|
|
591
706
|
sender: invoker.publicKey,
|
|
592
707
|
senderTokens: senderTokens,
|
|
@@ -604,16 +719,17 @@ var StreamClient = /** @class */ (function () {
|
|
|
604
719
|
commitment = typeof this.commitment == "string"
|
|
605
720
|
? this.commitment
|
|
606
721
|
: this.commitment.commitment;
|
|
607
|
-
return [4 /*yield*/, this.connection.
|
|
608
|
-
case
|
|
609
|
-
hash =
|
|
610
|
-
tx = (
|
|
722
|
+
return [4 /*yield*/, this.connection.getLatestBlockhash(commitment)];
|
|
723
|
+
case 7:
|
|
724
|
+
hash = _e.sent();
|
|
725
|
+
tx = (_d = new web3_js_1.Transaction({
|
|
611
726
|
feePayer: invoker.publicKey,
|
|
612
|
-
|
|
613
|
-
|
|
614
|
-
|
|
615
|
-
|
|
616
|
-
|
|
727
|
+
blockhash: hash.blockhash,
|
|
728
|
+
lastValidBlockHeight: hash.lastValidBlockHeight,
|
|
729
|
+
})).add.apply(_d, __spreadArray(__spreadArray([], __read(nativeInstructions), false), __read(ixs), false));
|
|
730
|
+
return [4 /*yield*/, this.sign(invoker, tx, hash)];
|
|
731
|
+
case 8:
|
|
732
|
+
signature = _e.sent();
|
|
617
733
|
return [2 /*return*/, { ixs: ixs, tx: signature }];
|
|
618
734
|
}
|
|
619
735
|
});
|
|
@@ -634,7 +750,7 @@ var StreamClient = /** @class */ (function () {
|
|
|
634
750
|
if (!(escrow === null || escrow === void 0 ? void 0 : escrow.data)) {
|
|
635
751
|
throw new Error("Couldn't get account info.");
|
|
636
752
|
}
|
|
637
|
-
return [2 /*return*/,
|
|
753
|
+
return [2 /*return*/, new types_1.Contract((0, utils_1.decodeStream)(escrow === null || escrow === void 0 ? void 0 : escrow.data))];
|
|
638
754
|
}
|
|
639
755
|
});
|
|
640
756
|
});
|
|
@@ -656,10 +772,10 @@ var StreamClient = /** @class */ (function () {
|
|
|
656
772
|
case 0:
|
|
657
773
|
accounts = [];
|
|
658
774
|
if (!(direction === "all")) return [3 /*break*/, 3];
|
|
659
|
-
return [4 /*yield*/, getProgramAccounts(this.connection, wallet, constants_1.STREAM_STRUCT_OFFSET_SENDER, this.
|
|
775
|
+
return [4 /*yield*/, getProgramAccounts(this.connection, wallet, constants_1.STREAM_STRUCT_OFFSET_SENDER, this.programId)];
|
|
660
776
|
case 1:
|
|
661
777
|
outgoingAccounts = _d.sent();
|
|
662
|
-
return [4 /*yield*/, getProgramAccounts(this.connection, wallet, constants_1.STREAM_STRUCT_OFFSET_RECIPIENT, this.
|
|
778
|
+
return [4 /*yield*/, getProgramAccounts(this.connection, wallet, constants_1.STREAM_STRUCT_OFFSET_RECIPIENT, this.programId)];
|
|
663
779
|
case 2:
|
|
664
780
|
incomingAccounts = _d.sent();
|
|
665
781
|
accounts = __spreadArray(__spreadArray([], __read(outgoingAccounts), false), __read(incomingAccounts), false);
|
|
@@ -668,7 +784,7 @@ var StreamClient = /** @class */ (function () {
|
|
|
668
784
|
offset = direction === "outgoing"
|
|
669
785
|
? constants_1.STREAM_STRUCT_OFFSET_SENDER
|
|
670
786
|
: constants_1.STREAM_STRUCT_OFFSET_RECIPIENT;
|
|
671
|
-
return [4 /*yield*/, getProgramAccounts(this.connection, wallet, offset, this.
|
|
787
|
+
return [4 /*yield*/, getProgramAccounts(this.connection, wallet, offset, this.programId)];
|
|
672
788
|
case 4:
|
|
673
789
|
accounts = _d.sent();
|
|
674
790
|
_d.label = 5;
|
|
@@ -676,7 +792,7 @@ var StreamClient = /** @class */ (function () {
|
|
|
676
792
|
streams = {};
|
|
677
793
|
accounts.forEach(function (account) {
|
|
678
794
|
var _a;
|
|
679
|
-
var decoded =
|
|
795
|
+
var decoded = new types_1.Contract((0, utils_1.decodeStream)(account.account.data));
|
|
680
796
|
streams = __assign(__assign({}, streams), (_a = {}, _a[account.pubkey.toBase58()] = decoded, _a));
|
|
681
797
|
});
|
|
682
798
|
sortedStreams = Object.entries(streams).sort(function (_a, _b) {
|
|
@@ -693,24 +809,30 @@ var StreamClient = /** @class */ (function () {
|
|
|
693
809
|
});
|
|
694
810
|
});
|
|
695
811
|
};
|
|
696
|
-
StreamClient.prototype.sign = function (invoker, tx) {
|
|
812
|
+
StreamClient.prototype.sign = function (invoker, tx, hash) {
|
|
697
813
|
return __awaiter(this, void 0, void 0, function () {
|
|
698
|
-
var rawTx, signature;
|
|
814
|
+
var rawTx, confirmationStrategy, signature;
|
|
699
815
|
return __generator(this, function (_a) {
|
|
700
816
|
switch (_a.label) {
|
|
701
817
|
case 0:
|
|
702
|
-
if (!(invoker
|
|
703
|
-
tx.partialSign(invoker);
|
|
704
|
-
return [3 /*break*/, 3];
|
|
705
|
-
case 1:
|
|
706
|
-
if (!(invoker === null || invoker === void 0 ? void 0 : invoker.signTransaction)) return [3 /*break*/, 3];
|
|
818
|
+
if (!isAnchorWallet(invoker)) return [3 /*break*/, 2];
|
|
707
819
|
return [4 /*yield*/, invoker.signTransaction(tx)];
|
|
708
|
-
case
|
|
820
|
+
case 1:
|
|
709
821
|
_a.sent();
|
|
822
|
+
return [3 /*break*/, 3];
|
|
823
|
+
case 2:
|
|
824
|
+
tx.partialSign(invoker);
|
|
710
825
|
_a.label = 3;
|
|
711
826
|
case 3:
|
|
712
827
|
rawTx = tx.serialize();
|
|
713
|
-
|
|
828
|
+
if (!hash.lastValidBlockHeight || !tx.signature || !hash.blockhash)
|
|
829
|
+
throw Error("Error with transaction parameters.");
|
|
830
|
+
confirmationStrategy = {
|
|
831
|
+
lastValidBlockHeight: hash.lastValidBlockHeight,
|
|
832
|
+
signature: (0, bs58_1.encode)(tx.signature),
|
|
833
|
+
blockhash: hash.blockhash,
|
|
834
|
+
};
|
|
835
|
+
return [4 /*yield*/, (0, web3_js_1.sendAndConfirmRawTransaction)(this.connection, rawTx, confirmationStrategy)];
|
|
714
836
|
case 4:
|
|
715
837
|
signature = _a.sent();
|
|
716
838
|
return [2 /*return*/, signature];
|
|
@@ -718,14 +840,100 @@ var StreamClient = /** @class */ (function () {
|
|
|
718
840
|
});
|
|
719
841
|
});
|
|
720
842
|
};
|
|
843
|
+
/**
|
|
844
|
+
* Forms instructions from params, creates a raw transaction and fetch recent blockhash.
|
|
845
|
+
* @param {MultiRecipient} recipient - Wallet sending stream to
|
|
846
|
+
* @param {CreateMultiParams} streamParams - Parameters of stream user wants to create.
|
|
847
|
+
*/
|
|
848
|
+
StreamClient.prototype.prepareStreamTransaction = function (recipient, streamParams) {
|
|
849
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
850
|
+
var sender, mint, start, period, cliff, canTopup, cancelableBySender, cancelableByRecipient, transferableBySender, transferableByRecipient, _a, automaticWithdrawal, _b, withdrawalFrequency, _c, partner, ixs, commitment, recipientPublicKey, mintPublicKey, metadata, _d, escrowTokens, senderTokens, recipientTokens, streamflowTreasuryTokens, partnerPublicKey, partnerTokens, hash, tx;
|
|
851
|
+
var _e;
|
|
852
|
+
return __generator(this, function (_f) {
|
|
853
|
+
switch (_f.label) {
|
|
854
|
+
case 0:
|
|
855
|
+
sender = streamParams.sender, mint = streamParams.mint, 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, _c = streamParams.partner, partner = _c === void 0 ? null : _c;
|
|
856
|
+
ixs = [];
|
|
857
|
+
commitment = typeof this.commitment == "string"
|
|
858
|
+
? this.commitment
|
|
859
|
+
: this.commitment.commitment;
|
|
860
|
+
recipientPublicKey = new web3_js_1.PublicKey(recipient.recipient);
|
|
861
|
+
mintPublicKey = new web3_js_1.PublicKey(mint);
|
|
862
|
+
metadata = web3_js_1.Keypair.generate();
|
|
863
|
+
return [4 /*yield*/, anchor_1.web3.PublicKey.findProgramAddress([buffer_1.Buffer.from("strm"), metadata.publicKey.toBuffer()], this.programId)];
|
|
864
|
+
case 1:
|
|
865
|
+
_d = __read.apply(void 0, [_f.sent(), 1]), escrowTokens = _d[0];
|
|
866
|
+
return [4 /*yield*/, ata(mintPublicKey, sender.publicKey)];
|
|
867
|
+
case 2:
|
|
868
|
+
senderTokens = _f.sent();
|
|
869
|
+
return [4 /*yield*/, ata(mintPublicKey, recipientPublicKey)];
|
|
870
|
+
case 3:
|
|
871
|
+
recipientTokens = _f.sent();
|
|
872
|
+
return [4 /*yield*/, ata(mintPublicKey, constants_1.STREAMFLOW_TREASURY_PUBLIC_KEY)];
|
|
873
|
+
case 4:
|
|
874
|
+
streamflowTreasuryTokens = _f.sent();
|
|
875
|
+
partnerPublicKey = partner
|
|
876
|
+
? new web3_js_1.PublicKey(partner)
|
|
877
|
+
: constants_1.STREAMFLOW_TREASURY_PUBLIC_KEY;
|
|
878
|
+
return [4 /*yield*/, ata(mintPublicKey, partnerPublicKey)];
|
|
879
|
+
case 5:
|
|
880
|
+
partnerTokens = _f.sent();
|
|
881
|
+
ixs.push((0, instructions_1.createStreamInstruction)({
|
|
882
|
+
start: new bn_js_1.default(start),
|
|
883
|
+
depositedAmount: recipient.depositedAmount,
|
|
884
|
+
period: new bn_js_1.default(period),
|
|
885
|
+
amountPerPeriod: recipient.amountPerPeriod,
|
|
886
|
+
cliff: new bn_js_1.default(cliff),
|
|
887
|
+
cliffAmount: recipient.cliffAmount,
|
|
888
|
+
cancelableBySender: cancelableBySender,
|
|
889
|
+
cancelableByRecipient: cancelableByRecipient,
|
|
890
|
+
automaticWithdrawal: automaticWithdrawal,
|
|
891
|
+
transferableBySender: transferableBySender,
|
|
892
|
+
transferableByRecipient: transferableByRecipient,
|
|
893
|
+
canTopup: canTopup,
|
|
894
|
+
name: recipient.name,
|
|
895
|
+
withdrawFrequency: new bn_js_1.default(automaticWithdrawal ? withdrawalFrequency : period),
|
|
896
|
+
}, this.programId, {
|
|
897
|
+
sender: sender.publicKey,
|
|
898
|
+
senderTokens: senderTokens,
|
|
899
|
+
recipient: new web3_js_1.PublicKey(recipient.recipient),
|
|
900
|
+
metadata: metadata.publicKey,
|
|
901
|
+
escrowTokens: escrowTokens,
|
|
902
|
+
recipientTokens: recipientTokens,
|
|
903
|
+
streamflowTreasury: constants_1.STREAMFLOW_TREASURY_PUBLIC_KEY,
|
|
904
|
+
streamflowTreasuryTokens: streamflowTreasuryTokens,
|
|
905
|
+
partner: partnerPublicKey,
|
|
906
|
+
partnerTokens: partnerTokens,
|
|
907
|
+
mint: new web3_js_1.PublicKey(mint),
|
|
908
|
+
feeOracle: constants_1.FEE_ORACLE_PUBLIC_KEY,
|
|
909
|
+
rent: web3_js_1.SYSVAR_RENT_PUBKEY,
|
|
910
|
+
timelockProgram: this.programId,
|
|
911
|
+
tokenProgram: spl_token_1.TOKEN_PROGRAM_ID,
|
|
912
|
+
associatedTokenProgram: spl_token_1.ASSOCIATED_TOKEN_PROGRAM_ID,
|
|
913
|
+
withdrawor: constants_1.WITHDRAWOR_PUBLIC_KEY,
|
|
914
|
+
systemProgram: web3_js_1.SystemProgram.programId,
|
|
915
|
+
}));
|
|
916
|
+
return [4 /*yield*/, this.connection.getLatestBlockhash(commitment)];
|
|
917
|
+
case 6:
|
|
918
|
+
hash = _f.sent();
|
|
919
|
+
tx = (_e = new web3_js_1.Transaction({
|
|
920
|
+
feePayer: sender.publicKey,
|
|
921
|
+
blockhash: hash.blockhash,
|
|
922
|
+
lastValidBlockHeight: hash.lastValidBlockHeight,
|
|
923
|
+
})).add.apply(_e, __spreadArray([], __read(ixs), false));
|
|
924
|
+
tx.partialSign(metadata);
|
|
925
|
+
return [2 /*return*/, { tx: tx, metadata: metadata }];
|
|
926
|
+
}
|
|
927
|
+
});
|
|
928
|
+
});
|
|
929
|
+
};
|
|
721
930
|
return StreamClient;
|
|
722
931
|
}());
|
|
723
932
|
exports.default = StreamClient;
|
|
724
|
-
function getProgramAccounts(connection, wallet, offset,
|
|
725
|
-
if (cluster === void 0) { cluster = types_1.Cluster.Mainnet; }
|
|
933
|
+
function getProgramAccounts(connection, wallet, offset, programId) {
|
|
726
934
|
return __awaiter(this, void 0, void 0, function () {
|
|
727
935
|
return __generator(this, function (_a) {
|
|
728
|
-
return [2 /*return*/, connection === null || connection === void 0 ? void 0 : connection.getProgramAccounts(
|
|
936
|
+
return [2 /*return*/, connection === null || connection === void 0 ? void 0 : connection.getProgramAccounts(programId, {
|
|
729
937
|
filters: [
|
|
730
938
|
{
|
|
731
939
|
memcmp: {
|
|
@@ -742,9 +950,68 @@ function ata(mint, account) {
|
|
|
742
950
|
return __awaiter(this, void 0, void 0, function () {
|
|
743
951
|
return __generator(this, function (_a) {
|
|
744
952
|
switch (_a.label) {
|
|
745
|
-
case 0: return [4 /*yield*/, spl_token_1.Token.getAssociatedTokenAddress(spl_token_1.ASSOCIATED_TOKEN_PROGRAM_ID, spl_token_1.TOKEN_PROGRAM_ID, mint, account)];
|
|
953
|
+
case 0: return [4 /*yield*/, spl_token_1.Token.getAssociatedTokenAddress(spl_token_1.ASSOCIATED_TOKEN_PROGRAM_ID, spl_token_1.TOKEN_PROGRAM_ID, mint, account, true)];
|
|
746
954
|
case 1: return [2 /*return*/, _a.sent()];
|
|
747
955
|
}
|
|
748
956
|
});
|
|
749
957
|
});
|
|
750
958
|
}
|
|
959
|
+
function isAnchorWallet(wallet) {
|
|
960
|
+
return wallet.signTransaction !== undefined;
|
|
961
|
+
}
|
|
962
|
+
function signAllTransactionWithRecipients(sender, batch) {
|
|
963
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
964
|
+
var signed_batch, isKeypair, isWallet;
|
|
965
|
+
return __generator(this, function (_a) {
|
|
966
|
+
switch (_a.label) {
|
|
967
|
+
case 0:
|
|
968
|
+
signed_batch = [];
|
|
969
|
+
isKeypair = sender instanceof web3_js_1.Keypair;
|
|
970
|
+
isWallet = isAnchorWallet(sender);
|
|
971
|
+
if (!isKeypair && !isWallet)
|
|
972
|
+
return [2 /*return*/, signed_batch];
|
|
973
|
+
if (!isKeypair) return [3 /*break*/, 1];
|
|
974
|
+
batch.map(function (t) {
|
|
975
|
+
t.tx.partialSign(sender);
|
|
976
|
+
return { tx: t.tx, recipient: t.recipient };
|
|
977
|
+
});
|
|
978
|
+
return [3 /*break*/, 3];
|
|
979
|
+
case 1:
|
|
980
|
+
if (!isWallet) return [3 /*break*/, 3];
|
|
981
|
+
return [4 /*yield*/, sender.signAllTransactions(batch.map(function (t) { return t.tx; }))];
|
|
982
|
+
case 2:
|
|
983
|
+
_a.sent();
|
|
984
|
+
_a.label = 3;
|
|
985
|
+
case 3: return [2 /*return*/, batch];
|
|
986
|
+
}
|
|
987
|
+
});
|
|
988
|
+
});
|
|
989
|
+
}
|
|
990
|
+
function sendAndConfirmStreamRawTransaction(connection, batchItem) {
|
|
991
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
992
|
+
var rawTx, _a, lastValidBlockHeight, signature, recentBlockhash, confirmationStrategy, completedTxSignature, error_1;
|
|
993
|
+
return __generator(this, function (_b) {
|
|
994
|
+
switch (_b.label) {
|
|
995
|
+
case 0:
|
|
996
|
+
_b.trys.push([0, 2, , 3]);
|
|
997
|
+
rawTx = batchItem.tx.serialize();
|
|
998
|
+
_a = batchItem.tx, lastValidBlockHeight = _a.lastValidBlockHeight, signature = _a.signature, recentBlockhash = _a.recentBlockhash;
|
|
999
|
+
if (!lastValidBlockHeight || !signature || !recentBlockhash)
|
|
1000
|
+
throw { recipient: batchItem.recipient, error: "no recent blockhash" };
|
|
1001
|
+
confirmationStrategy = {
|
|
1002
|
+
lastValidBlockHeight: lastValidBlockHeight,
|
|
1003
|
+
signature: (0, bs58_1.encode)(signature),
|
|
1004
|
+
blockhash: recentBlockhash,
|
|
1005
|
+
};
|
|
1006
|
+
return [4 /*yield*/, (0, web3_js_1.sendAndConfirmRawTransaction)(connection, rawTx, confirmationStrategy)];
|
|
1007
|
+
case 1:
|
|
1008
|
+
completedTxSignature = _b.sent();
|
|
1009
|
+
return [2 /*return*/, __assign(__assign({}, batchItem), { signature: completedTxSignature })];
|
|
1010
|
+
case 2:
|
|
1011
|
+
error_1 = _b.sent();
|
|
1012
|
+
throw { recipient: batchItem.recipient, error: error_1 };
|
|
1013
|
+
case 3: return [2 /*return*/];
|
|
1014
|
+
}
|
|
1015
|
+
});
|
|
1016
|
+
});
|
|
1017
|
+
}
|