@streamflow/stream 2.0.2-beta.24 → 2.1.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/README.md +47 -34
- package/dist/constants.d.ts +0 -2
- package/dist/constants.js +1 -3
- package/dist/index.d.ts +1 -2
- package/dist/index.js +3 -4
- package/dist/sdk.d.ts +28 -26
- package/dist/sdk.js +194 -251
- package/dist/types.d.ts +54 -40
- package/dist/utils.d.ts +6 -6
- package/dist/utils.js +74 -32
- package/package.json +1 -1
- package/dist/instructions.d.ts +0 -97
- package/dist/instructions.js +0 -210
- package/dist/layout.d.ts +0 -18
- package/dist/layout.js +0 -73
package/dist/sdk.js
CHANGED
|
@@ -71,138 +71,107 @@ var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
|
|
|
71
71
|
}
|
|
72
72
|
return to.concat(ar || Array.prototype.slice.call(from));
|
|
73
73
|
};
|
|
74
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
75
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
76
|
+
};
|
|
74
77
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
75
78
|
var anchor_1 = require("@project-serum/anchor");
|
|
76
79
|
var spl_token_1 = require("@solana/spl-token");
|
|
77
|
-
var buffer_1 = require("buffer");
|
|
78
|
-
var spl_token_2 = require("@solana/spl-token");
|
|
79
80
|
var web3_js_1 = require("@solana/web3.js");
|
|
80
81
|
var types_1 = require("./types");
|
|
81
82
|
var utils_1 = require("./utils");
|
|
82
83
|
var constants_1 = require("./constants");
|
|
83
|
-
var
|
|
84
|
+
var idl_1 = __importDefault(require("./idl"));
|
|
84
85
|
var encoder = new TextEncoder();
|
|
86
|
+
var initProgram = function (connection, wallet, cluster) {
|
|
87
|
+
var provider = new anchor_1.Provider(connection, wallet, {});
|
|
88
|
+
return new anchor_1.Program(idl_1.default, constants_1.PROGRAM_ID[cluster], provider);
|
|
89
|
+
};
|
|
85
90
|
var Stream = /** @class */ (function () {
|
|
86
|
-
|
|
87
|
-
* Create Stream instance
|
|
88
|
-
*/
|
|
89
|
-
function Stream(clusterUrl, cluster, commitment) {
|
|
90
|
-
if (cluster === void 0) { cluster = types_1.Cluster.Mainnet; }
|
|
91
|
-
if (commitment === void 0) { commitment = "confirmed"; }
|
|
92
|
-
this.commitment = commitment;
|
|
93
|
-
this.cluster = cluster;
|
|
94
|
-
this.connection = new web3_js_1.Connection(clusterUrl, this.commitment);
|
|
95
|
-
this.programId = new web3_js_1.PublicKey(constants_1.PROGRAM_ID[cluster]);
|
|
91
|
+
function Stream() {
|
|
96
92
|
}
|
|
97
|
-
Stream.prototype.getConnection = function () {
|
|
98
|
-
return this.connection;
|
|
99
|
-
};
|
|
100
93
|
/**
|
|
101
94
|
* Creates a new stream/vesting contract.
|
|
102
95
|
* All fees are paid by sender (escrow metadata account rent, escrow token account rent, recipient's associated token account rent, Streamflow's service fee).
|
|
103
96
|
* @param {CreateStreamParams} data
|
|
97
|
+
* @param {Connection} data.connection - A connection to the cluster.
|
|
104
98
|
* @param {Wallet} data.sender - Wallet signing the transaction. Its address should match the authorized wallet (sender) or transaction will fail.
|
|
105
99
|
* @param {string} data.recipient - Solana address of the recipient. Associated token account will be derived using this address and token mint address.
|
|
106
100
|
* @param {string} data.mint - SPL Token mint.
|
|
107
101
|
* @param {number} data.start - Timestamp (in seconds) when the stream/token vesting starts.
|
|
108
|
-
* @param {
|
|
102
|
+
* @param {BN} data.depositedAmount - Initially deposited amount of tokens (in the smallest units).
|
|
109
103
|
* @param {number} data.period - Time step (period) in seconds per which the unlocking occurs.
|
|
110
104
|
* @param {number} data.cliff - Vesting contract "cliff" timestamp in seconds.
|
|
111
|
-
* @param {
|
|
112
|
-
* @param {
|
|
105
|
+
* @param {BN} data.cliffAmount - Amount unlocked at the "cliff".
|
|
106
|
+
* @param {BN} data.amountPerPeriod - Amount unlocked per each period.
|
|
113
107
|
* @param {string} data.name - Stream name/subject.
|
|
114
108
|
* @param {boolean} data.canTopup - TRUE for streams, FALSE for vesting contracts.
|
|
115
109
|
* @param {boolean} data.cancelableBySender - Whether or not sender can cancel the stream.
|
|
116
110
|
* @param {boolean} data.cancelableByRecipient - Whether or not recipient can cancel the stream.
|
|
117
111
|
* @param {boolean} data.transferableBySender - Whether or not sender can transfer the stream.
|
|
118
112
|
* @param {boolean} data.transferableByRecipient - Whether or not recipient can transfer the stream.
|
|
119
|
-
* @param {boolean} data.automaticWithdrawal - Whether or not a 3rd party can initiate withdraw in the name of recipient.
|
|
120
|
-
* @param {
|
|
113
|
+
* @param {boolean} [data.automaticWithdrawal = false] - Whether or not a 3rd party can initiate withdraw in the name of recipient.
|
|
114
|
+
* @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.
|
|
115
|
+
* @param {string} [data.partner = STREAMFLOW_TREASURY] - Partner's wallet address (optional).
|
|
116
|
+
* @param {ClusterExtended} [data.cluster = Cluster.Mainnet] - Cluster: devnet, mainnet-beta, testnet or local (optional).
|
|
121
117
|
*/
|
|
122
|
-
Stream.
|
|
123
|
-
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,
|
|
118
|
+
Stream.create = function (_a) {
|
|
119
|
+
var connection = _a.connection, 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 ? constants_1.STREAMFLOW_TREASURY_PUBLIC_KEY.toString() : _d, _e = _a.cluster, cluster = _e === void 0 ? types_1.Cluster.Mainnet : _e;
|
|
124
120
|
return __awaiter(this, void 0, void 0, function () {
|
|
125
|
-
var
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
switch (_d.label) {
|
|
121
|
+
var program, mintPublicKey, recipientPublicKey, metadata, _f, escrowTokens, senderTokens, recipientTokens, streamflowTreasuryTokens, partnerPublicKey, partnerTokens, signers, nameUtf8EncodedBytes, tx;
|
|
122
|
+
return __generator(this, function (_g) {
|
|
123
|
+
switch (_g.label) {
|
|
129
124
|
case 0:
|
|
130
|
-
|
|
125
|
+
program = initProgram(connection, sender, cluster);
|
|
131
126
|
mintPublicKey = new web3_js_1.PublicKey(mint);
|
|
132
127
|
recipientPublicKey = new web3_js_1.PublicKey(recipient);
|
|
133
128
|
metadata = web3_js_1.Keypair.generate();
|
|
134
|
-
return [4 /*yield*/, anchor_1.web3.PublicKey.findProgramAddress([
|
|
129
|
+
return [4 /*yield*/, anchor_1.web3.PublicKey.findProgramAddress([Buffer.from("strm"), metadata.publicKey.toBuffer()], program.programId)];
|
|
135
130
|
case 1:
|
|
136
|
-
|
|
131
|
+
_f = __read.apply(void 0, [_g.sent(), 1]), escrowTokens = _f[0];
|
|
137
132
|
return [4 /*yield*/, ata(mintPublicKey, sender.publicKey)];
|
|
138
133
|
case 2:
|
|
139
|
-
senderTokens =
|
|
134
|
+
senderTokens = _g.sent();
|
|
140
135
|
return [4 /*yield*/, ata(mintPublicKey, recipientPublicKey)];
|
|
141
136
|
case 3:
|
|
142
|
-
recipientTokens =
|
|
137
|
+
recipientTokens = _g.sent();
|
|
143
138
|
return [4 /*yield*/, ata(mintPublicKey, constants_1.STREAMFLOW_TREASURY_PUBLIC_KEY)];
|
|
144
139
|
case 4:
|
|
145
|
-
streamflowTreasuryTokens =
|
|
146
|
-
partnerPublicKey = partner
|
|
147
|
-
? new web3_js_1.PublicKey(partner)
|
|
148
|
-
: constants_1.STREAMFLOW_TREASURY_PUBLIC_KEY;
|
|
140
|
+
streamflowTreasuryTokens = _g.sent();
|
|
141
|
+
partnerPublicKey = new web3_js_1.PublicKey(partner);
|
|
149
142
|
return [4 /*yield*/, ata(mintPublicKey, partnerPublicKey)];
|
|
150
143
|
case 5:
|
|
151
|
-
partnerTokens =
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
amountPerPeriod:
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
feeOracle: constants_1.STREAMFLOW_TREASURY_PUBLIC_KEY,
|
|
180
|
-
rent: web3_js_1.SYSVAR_RENT_PUBKEY,
|
|
181
|
-
timelockProgram: this.programId,
|
|
182
|
-
tokenProgram: spl_token_2.TOKEN_PROGRAM_ID,
|
|
183
|
-
associatedTokenProgram: spl_token_2.ASSOCIATED_TOKEN_PROGRAM_ID,
|
|
184
|
-
withdrawor: constants_1.WITHDRAWOR_PUBLIC_KEY,
|
|
185
|
-
systemProgram: web3_js_1.SystemProgram.programId,
|
|
186
|
-
}));
|
|
187
|
-
commitment = typeof this.commitment == "string"
|
|
188
|
-
? this.commitment
|
|
189
|
-
: this.commitment.commitment;
|
|
190
|
-
return [4 /*yield*/, this.connection.getRecentBlockhash(commitment)];
|
|
144
|
+
partnerTokens = _g.sent();
|
|
145
|
+
signers = [metadata];
|
|
146
|
+
nameUtf8EncodedBytes = formatStringToBytesArray(encoder, name);
|
|
147
|
+
return [4 /*yield*/, program.rpc.create(
|
|
148
|
+
// Order of the parameters must match the ones in the program
|
|
149
|
+
new anchor_1.BN(start), depositedAmount, new anchor_1.BN(period), amountPerPeriod, new anchor_1.BN(cliff), cliffAmount, cancelableBySender, cancelableByRecipient, automaticWithdrawal, transferableBySender, transferableByRecipient, canTopup, nameUtf8EncodedBytes, new anchor_1.BN(automaticWithdrawal ? withdrawalFrequency : period), {
|
|
150
|
+
accounts: {
|
|
151
|
+
sender: sender.publicKey,
|
|
152
|
+
senderTokens: senderTokens,
|
|
153
|
+
recipient: recipient,
|
|
154
|
+
metadata: metadata.publicKey,
|
|
155
|
+
escrowTokens: escrowTokens,
|
|
156
|
+
recipientTokens: recipientTokens,
|
|
157
|
+
streamflowTreasury: constants_1.STREAMFLOW_TREASURY_PUBLIC_KEY,
|
|
158
|
+
streamflowTreasuryTokens: streamflowTreasuryTokens,
|
|
159
|
+
partner: partnerPublicKey,
|
|
160
|
+
partnerTokens: partnerTokens,
|
|
161
|
+
mint: mint,
|
|
162
|
+
feeOracle: constants_1.STREAMFLOW_TREASURY_PUBLIC_KEY,
|
|
163
|
+
rent: web3_js_1.SYSVAR_RENT_PUBKEY,
|
|
164
|
+
timelockProgram: program.programId,
|
|
165
|
+
tokenProgram: spl_token_1.TOKEN_PROGRAM_ID,
|
|
166
|
+
associatedTokenProgram: spl_token_1.ASSOCIATED_TOKEN_PROGRAM_ID,
|
|
167
|
+
withdrawor: constants_1.WITHDRAWOR_PUBLIC_KEY,
|
|
168
|
+
systemProgram: web3_js_1.SystemProgram.programId,
|
|
169
|
+
},
|
|
170
|
+
signers: signers,
|
|
171
|
+
})];
|
|
191
172
|
case 6:
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
feePayer: sender.publicKey,
|
|
195
|
-
recentBlockhash: hash.blockhash,
|
|
196
|
-
})).add.apply(_c, __spreadArray([], __read(ixs), false));
|
|
197
|
-
tx.partialSign(metadata);
|
|
198
|
-
return [4 /*yield*/, sender.signTransaction(tx)];
|
|
199
|
-
case 7:
|
|
200
|
-
_d.sent();
|
|
201
|
-
rawTx = tx.serialize();
|
|
202
|
-
return [4 /*yield*/, (0, web3_js_1.sendAndConfirmRawTransaction)(this.connection, rawTx)];
|
|
203
|
-
case 8:
|
|
204
|
-
signature = _d.sent();
|
|
205
|
-
return [2 /*return*/, { ixs: ixs, tx: signature, metadata: metadata }];
|
|
173
|
+
tx = _g.sent();
|
|
174
|
+
return [2 /*return*/, { tx: tx, id: metadata.publicKey.toBase58() }];
|
|
206
175
|
}
|
|
207
176
|
});
|
|
208
177
|
});
|
|
@@ -210,21 +179,22 @@ var Stream = /** @class */ (function () {
|
|
|
210
179
|
/**
|
|
211
180
|
* Attempts withdrawal from the specified stream.
|
|
212
181
|
* @param {WithdrawStreamParams} data
|
|
182
|
+
* @param {Connection} data.connection - A connection to the cluster.
|
|
213
183
|
* @param {Wallet} data.invoker - Wallet signing the transaction. It's address should match authorized wallet (recipient) or transaction will fail.
|
|
214
184
|
* @param {string} data.id - Identifier of a stream (escrow account with metadata) to be withdrawn from.
|
|
215
|
-
* @param {
|
|
185
|
+
* @param {BN} data.amount - Requested amount (in the smallest units) to withdraw (while streaming). If stream is completed, the whole amount will be withdrawn.
|
|
186
|
+
* @param {ClusterExtended} [data.cluster = Cluster.Mainnet] - Cluster: devnet, mainnet-beta, testnet or local (optional).
|
|
216
187
|
*/
|
|
217
|
-
Stream.
|
|
218
|
-
var invoker = _a.invoker, id = _a.id, amount = _a.amount;
|
|
188
|
+
Stream.withdraw = function (_a) {
|
|
189
|
+
var connection = _a.connection, invoker = _a.invoker, id = _a.id, amount = _a.amount, _b = _a.cluster, cluster = _b === void 0 ? types_1.Cluster.Mainnet : _b;
|
|
219
190
|
return __awaiter(this, void 0, void 0, function () {
|
|
220
|
-
var
|
|
221
|
-
var _b;
|
|
191
|
+
var program, streamPublicKey, escrow, data, streamflowTreasuryTokens, partnerTokens, tx;
|
|
222
192
|
return __generator(this, function (_c) {
|
|
223
193
|
switch (_c.label) {
|
|
224
194
|
case 0:
|
|
225
|
-
|
|
195
|
+
program = initProgram(connection, invoker, cluster);
|
|
226
196
|
streamPublicKey = new web3_js_1.PublicKey(id);
|
|
227
|
-
return [4 /*yield*/,
|
|
197
|
+
return [4 /*yield*/, connection.getAccountInfo(streamPublicKey)];
|
|
228
198
|
case 1:
|
|
229
199
|
escrow = _c.sent();
|
|
230
200
|
if (!(escrow === null || escrow === void 0 ? void 0 : escrow.data)) {
|
|
@@ -237,36 +207,24 @@ var Stream = /** @class */ (function () {
|
|
|
237
207
|
return [4 /*yield*/, ata(data.mint, data.partner)];
|
|
238
208
|
case 3:
|
|
239
209
|
partnerTokens = _c.sent();
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
: this.commitment.commitment;
|
|
256
|
-
return [4 /*yield*/, this.connection.getRecentBlockhash(commitment)];
|
|
210
|
+
return [4 /*yield*/, program.rpc.withdraw(amount, {
|
|
211
|
+
accounts: {
|
|
212
|
+
authority: invoker.publicKey,
|
|
213
|
+
recipient: data.recipient,
|
|
214
|
+
recipientTokens: data.recipientTokens,
|
|
215
|
+
metadata: streamPublicKey,
|
|
216
|
+
escrowTokens: data.escrowTokens,
|
|
217
|
+
streamflowTreasury: constants_1.STREAMFLOW_TREASURY_PUBLIC_KEY,
|
|
218
|
+
streamflowTreasuryTokens: streamflowTreasuryTokens,
|
|
219
|
+
partner: data.partner,
|
|
220
|
+
partnerTokens: partnerTokens,
|
|
221
|
+
mint: data.mint,
|
|
222
|
+
tokenProgram: spl_token_1.TOKEN_PROGRAM_ID,
|
|
223
|
+
},
|
|
224
|
+
})];
|
|
257
225
|
case 4:
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
feePayer: invoker.publicKey,
|
|
261
|
-
recentBlockhash: hash.blockhash,
|
|
262
|
-
})).add.apply(_b, __spreadArray([], __read(ixs), false));
|
|
263
|
-
return [4 /*yield*/, invoker.signTransaction(tx)];
|
|
264
|
-
case 5:
|
|
265
|
-
signedAndSerializedTx = (_c.sent()).serialize();
|
|
266
|
-
return [4 /*yield*/, (0, web3_js_1.sendAndConfirmRawTransaction)(this.connection, signedAndSerializedTx)];
|
|
267
|
-
case 6:
|
|
268
|
-
signature = _c.sent();
|
|
269
|
-
return [2 /*return*/, { ixs: ixs, tx: signature }];
|
|
226
|
+
tx = _c.sent();
|
|
227
|
+
return [2 /*return*/, { tx: tx }];
|
|
270
228
|
}
|
|
271
229
|
});
|
|
272
230
|
});
|
|
@@ -274,19 +232,21 @@ var Stream = /** @class */ (function () {
|
|
|
274
232
|
/**
|
|
275
233
|
* Attempts canceling the specified stream.
|
|
276
234
|
* @param {CancelStreamParams} data
|
|
235
|
+
* @param {Connection} data.connection - A connection to the cluster.
|
|
277
236
|
* @param {Wallet} data.invoker - Wallet signing the transaction. It's address should match authorized wallet (sender or recipient) or transaction will fail.
|
|
278
237
|
* @param {string} data.id - Identifier of a stream (escrow account with metadata) to be canceled.
|
|
238
|
+
* @param {ClusterExtended} [data.cluster = Cluster.Mainnet] - Cluster: devnet, mainnet-beta, testnet or local (optional).
|
|
279
239
|
*/
|
|
280
|
-
Stream.
|
|
281
|
-
var invoker = _a.invoker, id = _a.id;
|
|
240
|
+
Stream.cancel = function (_a) {
|
|
241
|
+
var connection = _a.connection, invoker = _a.invoker, id = _a.id, _b = _a.cluster, cluster = _b === void 0 ? types_1.Cluster.Mainnet : _b;
|
|
282
242
|
return __awaiter(this, void 0, void 0, function () {
|
|
283
|
-
var streamPublicKey, escrow_acc, data, streamflowTreasuryTokens, partnerTokens,
|
|
284
|
-
var _b;
|
|
243
|
+
var program, streamPublicKey, escrow_acc, data, streamflowTreasuryTokens, partnerTokens, tx;
|
|
285
244
|
return __generator(this, function (_c) {
|
|
286
245
|
switch (_c.label) {
|
|
287
246
|
case 0:
|
|
247
|
+
program = initProgram(connection, invoker, cluster);
|
|
288
248
|
streamPublicKey = new web3_js_1.PublicKey(id);
|
|
289
|
-
return [4 /*yield*/,
|
|
249
|
+
return [4 /*yield*/, connection.getAccountInfo(streamPublicKey)];
|
|
290
250
|
case 1:
|
|
291
251
|
escrow_acc = _c.sent();
|
|
292
252
|
if (!(escrow_acc === null || escrow_acc === void 0 ? void 0 : escrow_acc.data)) {
|
|
@@ -299,40 +259,26 @@ var Stream = /** @class */ (function () {
|
|
|
299
259
|
return [4 /*yield*/, ata(data.mint, data.partner)];
|
|
300
260
|
case 3:
|
|
301
261
|
partnerTokens = _c.sent();
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
? this.commitment
|
|
320
|
-
: this.commitment.commitment;
|
|
321
|
-
return [4 /*yield*/, this.connection.getRecentBlockhash(commitment)];
|
|
262
|
+
return [4 /*yield*/, program.rpc.cancel({
|
|
263
|
+
accounts: {
|
|
264
|
+
authority: invoker.publicKey,
|
|
265
|
+
sender: data.sender,
|
|
266
|
+
senderTokens: data.senderTokens,
|
|
267
|
+
recipient: data.recipient,
|
|
268
|
+
recipientTokens: data.recipientTokens,
|
|
269
|
+
metadata: streamPublicKey,
|
|
270
|
+
escrowTokens: data.escrowTokens,
|
|
271
|
+
streamflowTreasury: constants_1.STREAMFLOW_TREASURY_PUBLIC_KEY,
|
|
272
|
+
streamflowTreasuryTokens: streamflowTreasuryTokens,
|
|
273
|
+
partner: data.partner,
|
|
274
|
+
partnerTokens: partnerTokens,
|
|
275
|
+
mint: data.mint,
|
|
276
|
+
tokenProgram: spl_token_1.TOKEN_PROGRAM_ID,
|
|
277
|
+
},
|
|
278
|
+
})];
|
|
322
279
|
case 4:
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
feePayer: invoker.publicKey,
|
|
326
|
-
recentBlockhash: hash.blockhash,
|
|
327
|
-
})).add.apply(_b, __spreadArray([], __read(ixs), false));
|
|
328
|
-
return [4 /*yield*/, invoker.signTransaction(tx)];
|
|
329
|
-
case 5:
|
|
330
|
-
_c.sent();
|
|
331
|
-
rawTx = tx.serialize();
|
|
332
|
-
return [4 /*yield*/, (0, web3_js_1.sendAndConfirmRawTransaction)(this.connection, rawTx)];
|
|
333
|
-
case 6:
|
|
334
|
-
signature = _c.sent();
|
|
335
|
-
return [2 /*return*/, { ixs: ixs, tx: signature }];
|
|
280
|
+
tx = _c.sent();
|
|
281
|
+
return [2 /*return*/, { tx: tx }];
|
|
336
282
|
}
|
|
337
283
|
});
|
|
338
284
|
});
|
|
@@ -341,22 +287,23 @@ var Stream = /** @class */ (function () {
|
|
|
341
287
|
* Attempts changing the stream/vesting contract's recipient (effectively transferring the stream/vesting contract).
|
|
342
288
|
* Potential associated token account rent fee (to make it rent-exempt) is paid by the transaction initiator.
|
|
343
289
|
* @param {TransferStreamParams} data
|
|
290
|
+
* @param {Connection} data.connection - A connection to the cluster.
|
|
344
291
|
* @param {Wallet} data.invoker - Wallet signing the transaction. It's address should match authorized wallet (sender or recipient) or transaction will fail.
|
|
345
292
|
* @param {string} data.id - Identifier of a stream (escrow account with metadata) to be transferred.
|
|
346
293
|
* @param {string} data.recipientId - Address of a new recipient.
|
|
294
|
+
* @param {ClusterExtended} [data.cluster = Cluster.Mainnet] - Cluster: devnet, mainnet-beta, testnet or local (optional).
|
|
347
295
|
*/
|
|
348
|
-
Stream.
|
|
349
|
-
var invoker = _a.invoker, id = _a.id, recipientId = _a.recipientId;
|
|
296
|
+
Stream.transfer = function (_a) {
|
|
297
|
+
var connection = _a.connection, invoker = _a.invoker, id = _a.id, recipientId = _a.recipientId, _b = _a.cluster, cluster = _b === void 0 ? types_1.Cluster.Mainnet : _b;
|
|
350
298
|
return __awaiter(this, void 0, void 0, function () {
|
|
351
|
-
var
|
|
352
|
-
var _b;
|
|
299
|
+
var program, stream, newRecipient, escrow, mint, newRecipientTokens, tx;
|
|
353
300
|
return __generator(this, function (_c) {
|
|
354
301
|
switch (_c.label) {
|
|
355
302
|
case 0:
|
|
356
|
-
|
|
303
|
+
program = initProgram(connection, invoker, cluster);
|
|
357
304
|
stream = new web3_js_1.PublicKey(id);
|
|
358
305
|
newRecipient = new web3_js_1.PublicKey(recipientId);
|
|
359
|
-
return [4 /*yield*/,
|
|
306
|
+
return [4 /*yield*/, connection.getAccountInfo(stream)];
|
|
360
307
|
case 1:
|
|
361
308
|
escrow = _c.sent();
|
|
362
309
|
if (!(escrow === null || escrow === void 0 ? void 0 : escrow.data)) {
|
|
@@ -366,35 +313,22 @@ var Stream = /** @class */ (function () {
|
|
|
366
313
|
return [4 /*yield*/, ata(mint, newRecipient)];
|
|
367
314
|
case 2:
|
|
368
315
|
newRecipientTokens = _c.sent();
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
: this.commitment.commitment;
|
|
383
|
-
return [4 /*yield*/, this.connection.getRecentBlockhash(commitment)];
|
|
316
|
+
return [4 /*yield*/, program.rpc.transferRecipient({
|
|
317
|
+
accounts: {
|
|
318
|
+
authority: invoker.publicKey,
|
|
319
|
+
newRecipient: newRecipient,
|
|
320
|
+
newRecipientTokens: newRecipientTokens,
|
|
321
|
+
metadata: stream,
|
|
322
|
+
mint: mint,
|
|
323
|
+
rent: web3_js_1.SYSVAR_RENT_PUBKEY,
|
|
324
|
+
tokenProgram: spl_token_1.TOKEN_PROGRAM_ID,
|
|
325
|
+
associatedTokenProgram: spl_token_1.ASSOCIATED_TOKEN_PROGRAM_ID,
|
|
326
|
+
systemProgram: anchor_1.web3.SystemProgram.programId,
|
|
327
|
+
},
|
|
328
|
+
})];
|
|
384
329
|
case 3:
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
feePayer: invoker.publicKey,
|
|
388
|
-
recentBlockhash: hash.blockhash,
|
|
389
|
-
})).add.apply(_b, __spreadArray([], __read(ixs), false));
|
|
390
|
-
return [4 /*yield*/, invoker.signTransaction(tx)];
|
|
391
|
-
case 4:
|
|
392
|
-
_c.sent();
|
|
393
|
-
rawTx = tx.serialize();
|
|
394
|
-
return [4 /*yield*/, (0, web3_js_1.sendAndConfirmRawTransaction)(this.connection, rawTx)];
|
|
395
|
-
case 5:
|
|
396
|
-
signature = _c.sent();
|
|
397
|
-
return [2 /*return*/, { ixs: ixs, tx: signature }];
|
|
330
|
+
tx = _c.sent();
|
|
331
|
+
return [2 /*return*/, { tx: tx }];
|
|
398
332
|
}
|
|
399
333
|
});
|
|
400
334
|
});
|
|
@@ -402,64 +336,53 @@ var Stream = /** @class */ (function () {
|
|
|
402
336
|
/**
|
|
403
337
|
* Tops up stream account deposited amount.
|
|
404
338
|
* @param {TopupStreamParams} data
|
|
339
|
+
* @param {Connection} data.connection - A connection to the cluster.
|
|
405
340
|
* @param {Wallet} data.invoker - Wallet signing the transaction. It's address should match current stream sender or transaction will fail.
|
|
406
341
|
* @param {string} data.id - Identifier of a stream (escrow account with metadata) to be topped up.
|
|
407
|
-
* @param {
|
|
342
|
+
* @param {BN} data.amount - Specified amount (in the smallest units) to topup (increases deposited amount).
|
|
343
|
+
* @param {ClusterExtended} [data.cluster = Cluster.Mainnet] - Cluster: devnet, mainnet-beta, testnet or local (optional).
|
|
408
344
|
*/
|
|
409
|
-
Stream.
|
|
410
|
-
var invoker = _a.invoker, id = _a.id, amount = _a.amount;
|
|
345
|
+
Stream.topup = function (_a) {
|
|
346
|
+
var connection = _a.connection, invoker = _a.invoker, id = _a.id, amount = _a.amount, _b = _a.cluster, cluster = _b === void 0 ? types_1.Cluster.Mainnet : _b;
|
|
411
347
|
return __awaiter(this, void 0, void 0, function () {
|
|
412
|
-
var
|
|
413
|
-
var _c;
|
|
348
|
+
var program, streamPublicKey, escrow, _c, mint, partner, senderTokens, escrowTokens, streamflowTreasuryTokens, partnerTokens, tx;
|
|
414
349
|
return __generator(this, function (_d) {
|
|
415
350
|
switch (_d.label) {
|
|
416
351
|
case 0:
|
|
417
|
-
|
|
352
|
+
program = initProgram(connection, invoker, cluster);
|
|
418
353
|
streamPublicKey = new web3_js_1.PublicKey(id);
|
|
419
|
-
return [4 /*yield*/,
|
|
354
|
+
return [4 /*yield*/, connection.getAccountInfo(streamPublicKey)];
|
|
420
355
|
case 1:
|
|
421
356
|
escrow = _d.sent();
|
|
422
357
|
if (!(escrow === null || escrow === void 0 ? void 0 : escrow.data)) {
|
|
423
358
|
throw new Error("Couldn't get account info");
|
|
424
359
|
}
|
|
425
|
-
|
|
360
|
+
_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;
|
|
426
361
|
return [4 /*yield*/, ata(mint, constants_1.STREAMFLOW_TREASURY_PUBLIC_KEY)];
|
|
427
362
|
case 2:
|
|
428
363
|
streamflowTreasuryTokens = _d.sent();
|
|
429
364
|
return [4 /*yield*/, ata(mint, partner)];
|
|
430
365
|
case 3:
|
|
431
366
|
partnerTokens = _d.sent();
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
: this.commitment.commitment;
|
|
449
|
-
return [4 /*yield*/, this.connection.getRecentBlockhash(commitment)];
|
|
367
|
+
return [4 /*yield*/, program.rpc.topup(amount, {
|
|
368
|
+
accounts: {
|
|
369
|
+
sender: invoker.publicKey,
|
|
370
|
+
senderTokens: senderTokens,
|
|
371
|
+
metadata: streamPublicKey,
|
|
372
|
+
escrowTokens: escrowTokens,
|
|
373
|
+
streamflowTreasury: constants_1.STREAMFLOW_TREASURY_PUBLIC_KEY,
|
|
374
|
+
streamflowTreasuryTokens: streamflowTreasuryTokens,
|
|
375
|
+
partner: partner,
|
|
376
|
+
partnerTokens: partnerTokens,
|
|
377
|
+
mint: mint,
|
|
378
|
+
tokenProgram: spl_token_1.TOKEN_PROGRAM_ID,
|
|
379
|
+
withdrawor: constants_1.WITHDRAWOR_PUBLIC_KEY,
|
|
380
|
+
systemProgram: anchor_1.web3.SystemProgram.programId,
|
|
381
|
+
},
|
|
382
|
+
})];
|
|
450
383
|
case 4:
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
feePayer: invoker.publicKey,
|
|
454
|
-
recentBlockhash: hash.blockhash,
|
|
455
|
-
})).add.apply(_c, __spreadArray([], __read(ixs), false));
|
|
456
|
-
return [4 /*yield*/, invoker.signTransaction(tx)];
|
|
457
|
-
case 5:
|
|
458
|
-
signedAndSerializedTx = (_d.sent()).serialize();
|
|
459
|
-
return [4 /*yield*/, (0, web3_js_1.sendAndConfirmRawTransaction)(this.connection, signedAndSerializedTx)];
|
|
460
|
-
case 6:
|
|
461
|
-
signature = _d.sent();
|
|
462
|
-
return [2 /*return*/, { ixs: ixs, tx: signature }];
|
|
384
|
+
tx = _d.sent();
|
|
385
|
+
return [2 /*return*/, { tx: tx }];
|
|
463
386
|
}
|
|
464
387
|
});
|
|
465
388
|
});
|
|
@@ -470,13 +393,13 @@ var Stream = /** @class */ (function () {
|
|
|
470
393
|
* @param {Connection} data.connection - A connection to the cluster.
|
|
471
394
|
* @param {string} data.id - Identifier of a stream that is fetched.
|
|
472
395
|
*/
|
|
473
|
-
Stream.
|
|
474
|
-
var id = _a.id;
|
|
396
|
+
Stream.getOne = function (_a) {
|
|
397
|
+
var connection = _a.connection, id = _a.id;
|
|
475
398
|
return __awaiter(this, void 0, void 0, function () {
|
|
476
399
|
var escrow;
|
|
477
400
|
return __generator(this, function (_b) {
|
|
478
401
|
switch (_b.label) {
|
|
479
|
-
case 0: return [4 /*yield*/,
|
|
402
|
+
case 0: return [4 /*yield*/, connection.getAccountInfo(new web3_js_1.PublicKey(id), constants_1.TX_FINALITY_CONFIRMED)];
|
|
480
403
|
case 1:
|
|
481
404
|
escrow = _b.sent();
|
|
482
405
|
if (!(escrow === null || escrow === void 0 ? void 0 : escrow.data)) {
|
|
@@ -491,35 +414,37 @@ var Stream = /** @class */ (function () {
|
|
|
491
414
|
* Fetch streams/contracts by providing direction.
|
|
492
415
|
* Streams are sorted by start time in ascending order.
|
|
493
416
|
* @param {GetStreamsParams} data
|
|
417
|
+
* @param {Connection} data.connection - A connection to the cluster.
|
|
494
418
|
* @param {PublicKey} data.wallet - PublicKey of the wallet for which the streams/contracts are fetched.
|
|
495
419
|
* @param {StreamType} [data.type = StreamType.All] - It can be one of: stream, vesting, all.
|
|
496
420
|
* @param {StreamDirection} [data.direction = StreamDirection.All] - It can be one of: incoming, outgoing, all.
|
|
421
|
+
* @param {ClusterExtended} [data.cluster = Cluster.Mainnet] - Cluster: devnet, mainnet-beta, testnet or local (optional).
|
|
497
422
|
*/
|
|
498
|
-
Stream.
|
|
499
|
-
var wallet = _a.wallet, _b = _a.type, type = _b === void 0 ? types_1.StreamType.All : _b, _c = _a.direction, direction = _c === void 0 ? types_1.StreamDirection.All : _c;
|
|
423
|
+
Stream.get = function (_a) {
|
|
424
|
+
var connection = _a.connection, wallet = _a.wallet, _b = _a.type, type = _b === void 0 ? types_1.StreamType.All : _b, _c = _a.direction, direction = _c === void 0 ? types_1.StreamDirection.All : _c, _d = _a.cluster, cluster = _d === void 0 ? types_1.Cluster.Mainnet : _d;
|
|
500
425
|
return __awaiter(this, void 0, void 0, function () {
|
|
501
426
|
var accounts, outgoingAccounts, incomingAccounts, offset, streams, sortedStreams;
|
|
502
|
-
return __generator(this, function (
|
|
503
|
-
switch (
|
|
427
|
+
return __generator(this, function (_e) {
|
|
428
|
+
switch (_e.label) {
|
|
504
429
|
case 0:
|
|
505
430
|
accounts = [];
|
|
506
431
|
if (!(direction === "all")) return [3 /*break*/, 3];
|
|
507
|
-
return [4 /*yield*/, getProgramAccounts(
|
|
432
|
+
return [4 /*yield*/, getProgramAccounts(connection, wallet, constants_1.STREAM_STRUCT_OFFSET_SENDER, cluster)];
|
|
508
433
|
case 1:
|
|
509
|
-
outgoingAccounts =
|
|
510
|
-
return [4 /*yield*/, getProgramAccounts(
|
|
434
|
+
outgoingAccounts = _e.sent();
|
|
435
|
+
return [4 /*yield*/, getProgramAccounts(connection, wallet, constants_1.STREAM_STRUCT_OFFSET_RECIPIENT, cluster)];
|
|
511
436
|
case 2:
|
|
512
|
-
incomingAccounts =
|
|
437
|
+
incomingAccounts = _e.sent();
|
|
513
438
|
accounts = __spreadArray(__spreadArray([], __read(outgoingAccounts), false), __read(incomingAccounts), false);
|
|
514
439
|
return [3 /*break*/, 5];
|
|
515
440
|
case 3:
|
|
516
441
|
offset = direction === "outgoing"
|
|
517
442
|
? constants_1.STREAM_STRUCT_OFFSET_SENDER
|
|
518
443
|
: constants_1.STREAM_STRUCT_OFFSET_RECIPIENT;
|
|
519
|
-
return [4 /*yield*/, getProgramAccounts(
|
|
444
|
+
return [4 /*yield*/, getProgramAccounts(connection, wallet, offset, cluster)];
|
|
520
445
|
case 4:
|
|
521
|
-
accounts =
|
|
522
|
-
|
|
446
|
+
accounts = _e.sent();
|
|
447
|
+
_e.label = 5;
|
|
523
448
|
case 5:
|
|
524
449
|
streams = {};
|
|
525
450
|
accounts.forEach(function (account) {
|
|
@@ -565,9 +490,27 @@ function ata(mint, account) {
|
|
|
565
490
|
return __awaiter(this, void 0, void 0, function () {
|
|
566
491
|
return __generator(this, function (_a) {
|
|
567
492
|
switch (_a.label) {
|
|
568
|
-
case 0: return [4 /*yield*/,
|
|
493
|
+
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)];
|
|
569
494
|
case 1: return [2 /*return*/, _a.sent()];
|
|
570
495
|
}
|
|
571
496
|
});
|
|
572
497
|
});
|
|
573
498
|
}
|
|
499
|
+
function formatStringToBytesArray(encoder, text) {
|
|
500
|
+
var textCopy = __spreadArray([], __read(text), false);
|
|
501
|
+
var characters = Array.from(textCopy);
|
|
502
|
+
var utf8EncodedBytes = [];
|
|
503
|
+
characters.every(function (char) {
|
|
504
|
+
if (utf8EncodedBytes.length > 64)
|
|
505
|
+
return false;
|
|
506
|
+
var encoded = encoder.encode(char);
|
|
507
|
+
if (utf8EncodedBytes.length + encoded.length > 64)
|
|
508
|
+
return false;
|
|
509
|
+
encoded.forEach(function (elem) { return utf8EncodedBytes.push(new anchor_1.BN(elem)); });
|
|
510
|
+
return true;
|
|
511
|
+
});
|
|
512
|
+
var numberOfBytes = utf8EncodedBytes.length;
|
|
513
|
+
var fill = new Array(64 - numberOfBytes).fill(new anchor_1.BN(0));
|
|
514
|
+
utf8EncodedBytes.push.apply(utf8EncodedBytes, __spreadArray([], __read(fill), false));
|
|
515
|
+
return utf8EncodedBytes;
|
|
516
|
+
}
|