@streamflow/stream 3.0.16 → 3.0.18
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/__tests__/aptos/streamClient.spec.d.ts +1 -0
- package/dist/__tests__/aptos/streamClient.spec.js +160 -0
- package/dist/aptos/StreamClient.d.ts +49 -0
- package/dist/aptos/StreamClient.js +362 -0
- package/dist/aptos/constants.d.ts +2 -0
- package/dist/aptos/constants.js +12 -0
- package/dist/aptos/index.d.ts +2 -0
- package/dist/aptos/index.js +24 -0
- package/dist/aptos/types.d.ts +145 -0
- package/dist/aptos/types.js +65 -0
- package/dist/common/BaseStreamClient.d.ts +11 -0
- package/dist/common/BaseStreamClient.js +9 -0
- package/dist/common/GenericStreamClient.d.ts +60 -0
- package/dist/common/GenericStreamClient.js +137 -0
- package/dist/common/types.d.ts +71 -0
- package/dist/common/types.js +28 -0
- package/dist/{utils.d.ts → common/utils.d.ts} +0 -4
- package/dist/common/utils.js +31 -0
- package/dist/index.d.ts +5 -6
- package/dist/index.js +19 -10
- package/dist/solana/StreamClient.d.ts +71 -0
- package/dist/{StreamClient.js → solana/StreamClient.js} +304 -397
- package/dist/{constants.d.ts → solana/constants.d.ts} +1 -1
- package/dist/{constants.js → solana/constants.js} +5 -5
- package/dist/solana/index.d.ts +7 -0
- package/dist/solana/index.js +43 -0
- package/dist/solana/instructionTypes.d.ts +86 -0
- package/dist/solana/instructionTypes.js +2 -0
- package/dist/{instructions.d.ts → solana/instructions.d.ts} +8 -2
- package/dist/{instructions.js → solana/instructions.js} +55 -38
- package/dist/solana/layout.d.ts +27 -0
- package/dist/{layout.js → solana/layout.js} +65 -3
- package/dist/{idl/timelock.d.ts → solana/timelockIDL.d.ts} +0 -0
- package/dist/{idl/timelock.js → solana/timelockIDL.js} +0 -0
- package/dist/{types.d.ts → solana/types.d.ts} +37 -34
- package/dist/{types.js → solana/types.js} +3 -20
- package/dist/solana/utils.d.ts +42 -0
- package/dist/solana/utils.js +271 -0
- package/package.json +1 -1
- package/dist/Stream.d.ts +0 -87
- package/dist/Stream.js +0 -503
- package/dist/StreamClient.d.ts +0 -146
- package/dist/__tests__/test_dependencies/airdrop/airdrop-request.d.ts +0 -3
- package/dist/__tests__/test_dependencies/airdrop/airdrop-request.js +0 -67
- package/dist/__tests__/test_dependencies/airdrop/airdrop.d.ts +0 -6
- package/dist/__tests__/test_dependencies/airdrop/airdrop.js +0 -215
- package/dist/__tests__/test_dependencies/constants/index.d.ts +0 -122
- package/dist/__tests__/test_dependencies/constants/index.js +0 -158
- package/dist/__tests__/test_dependencies/idl/airdrop.d.ts +0 -27
- package/dist/__tests__/test_dependencies/idl/airdrop.js +0 -171
- package/dist/layout.d.ts +0 -22
- package/dist/utils.js +0 -126
|
@@ -1,5 +1,20 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
// Latest version of the SDK that does not use Anchor. It supports raw instructions.
|
|
3
|
+
var __extends = (this && this.__extends) || (function () {
|
|
4
|
+
var extendStatics = function (d, b) {
|
|
5
|
+
extendStatics = Object.setPrototypeOf ||
|
|
6
|
+
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
|
|
7
|
+
function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
|
|
8
|
+
return extendStatics(d, b);
|
|
9
|
+
};
|
|
10
|
+
return function (d, b) {
|
|
11
|
+
if (typeof b !== "function" && b !== null)
|
|
12
|
+
throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
|
|
13
|
+
extendStatics(d, b);
|
|
14
|
+
function __() { this.constructor = d; }
|
|
15
|
+
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
|
|
16
|
+
};
|
|
17
|
+
})();
|
|
3
18
|
var __assign = (this && this.__assign) || function () {
|
|
4
19
|
__assign = Object.assign || function(t) {
|
|
5
20
|
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
|
@@ -89,101 +104,84 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
89
104
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
90
105
|
var bn_js_1 = __importDefault(require("bn.js"));
|
|
91
106
|
var buffer_1 = require("buffer");
|
|
92
|
-
var
|
|
107
|
+
var bs58_1 = __importDefault(require("bs58"));
|
|
93
108
|
var spl_token_1 = require("@solana/spl-token");
|
|
94
109
|
var web3_js_1 = require("@solana/web3.js");
|
|
95
110
|
var types_1 = require("./types");
|
|
96
111
|
var utils_1 = require("./utils");
|
|
97
112
|
var constants_1 = require("./constants");
|
|
98
113
|
var instructions_1 = require("./instructions");
|
|
99
|
-
var
|
|
114
|
+
var types_2 = require("../common/types");
|
|
115
|
+
var BaseStreamClient_1 = require("../common/BaseStreamClient");
|
|
100
116
|
var METADATA_ACC_SIZE = 1104;
|
|
101
|
-
var
|
|
117
|
+
var SolanaStreamClient = /** @class */ (function (_super) {
|
|
118
|
+
__extends(SolanaStreamClient, _super);
|
|
102
119
|
/**
|
|
103
120
|
* Create Stream instance
|
|
104
121
|
*/
|
|
105
|
-
function
|
|
106
|
-
if (cluster === void 0) { cluster =
|
|
122
|
+
function SolanaStreamClient(clusterUrl, cluster, commitment, programId) {
|
|
123
|
+
if (cluster === void 0) { cluster = types_2.ICluster.Mainnet; }
|
|
107
124
|
if (commitment === void 0) { commitment = "confirmed"; }
|
|
108
125
|
if (programId === void 0) { programId = ""; }
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
}
|
|
126
|
+
var _this = _super.call(this) || this;
|
|
127
|
+
_this.commitment = commitment;
|
|
128
|
+
_this.connection = new web3_js_1.Connection(clusterUrl, _this.commitment);
|
|
129
|
+
_this.programId =
|
|
130
|
+
programId !== "" ? new web3_js_1.PublicKey(programId) : new web3_js_1.PublicKey(constants_1.PROGRAM_ID[cluster]);
|
|
131
|
+
return _this;
|
|
116
132
|
}
|
|
117
|
-
|
|
133
|
+
SolanaStreamClient.prototype.getConnection = function () {
|
|
118
134
|
return this.connection;
|
|
119
135
|
};
|
|
120
|
-
|
|
136
|
+
SolanaStreamClient.prototype.getProgramId = function () {
|
|
121
137
|
return this.programId.toBase58();
|
|
122
138
|
};
|
|
123
139
|
/**
|
|
124
140
|
* Creates a new stream/vesting contract.
|
|
125
141
|
* All fees are paid by sender (escrow metadata account rent, escrow token account rent, recipient's associated token account rent, Streamflow's service fee).
|
|
126
|
-
* @param {CreateParams} data
|
|
127
|
-
* @param {Wallet | Keypair} data.sender - Wallet signing the transaction. Its address should match the authorized wallet (sender) or transaction will fail.
|
|
128
|
-
* @param {string} data.recipient - Solana address of the recipient. Associated token account will be derived using this address and token mint address.
|
|
129
|
-
* @param {string} data.mint - SPL Token mint.
|
|
130
|
-
* @param {number} data.start - Timestamp (in seconds) when the stream/token vesting starts.
|
|
131
|
-
* @param {BN} data.depositedAmount - Initially deposited amount of tokens (in the smallest units).
|
|
132
|
-
* @param {number} data.period - Time step (period) in seconds per which the unlocking occurs.
|
|
133
|
-
* @param {number} data.cliff - Vesting contract "cliff" timestamp in seconds.
|
|
134
|
-
* @param {BN} data.cliffAmount - Amount unlocked at the "cliff".
|
|
135
|
-
* @param {BN} data.amountPerPeriod - Amount unlocked per each period.
|
|
136
|
-
* @param {string} data.name - Stream name/subject.
|
|
137
|
-
* @param {boolean} data.canTopup - TRUE for streams, FALSE for vesting contracts.
|
|
138
|
-
* @param {boolean} data.cancelableBySender - Whether or not sender can cancel the stream.
|
|
139
|
-
* @param {boolean} data.cancelableByRecipient - Whether or not recipient can cancel the stream.
|
|
140
|
-
* @param {boolean} data.transferableBySender - Whether or not sender can transfer the stream.
|
|
141
|
-
* @param {boolean} data.transferableByRecipient - Whether or not recipient can transfer the stream.
|
|
142
|
-
* @param {boolean} data.automaticWithdrawal - Whether or not a 3rd party can initiate withdraw in the name of recipient.
|
|
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
|
|
145
|
-
* @param {string | null} [data.partner = null] - Partner's wallet address (optional).
|
|
146
142
|
*/
|
|
147
|
-
|
|
148
|
-
var
|
|
143
|
+
SolanaStreamClient.prototype.create = function (_a, _b) {
|
|
144
|
+
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;
|
|
145
|
+
var sender = _b.sender, _e = _b.partner, partner = _e === void 0 ? null : _e, _f = _b.isNative, isNative = _f === void 0 ? false : _f;
|
|
149
146
|
return __awaiter(this, void 0, void 0, function () {
|
|
150
|
-
var ixs, mintPublicKey, recipientPublicKey, metadata,
|
|
151
|
-
var
|
|
152
|
-
return __generator(this, function (
|
|
153
|
-
switch (
|
|
147
|
+
var ixs, mintPublicKey, recipientPublicKey, metadata, _g, escrowTokens, senderTokens, recipientTokens, streamflowTreasuryTokens, partnerPublicKey, partnerTokens, nativeInstructions, _h, commitment, hash, tx, signature;
|
|
148
|
+
var _j;
|
|
149
|
+
return __generator(this, function (_k) {
|
|
150
|
+
switch (_k.label) {
|
|
154
151
|
case 0:
|
|
152
|
+
if (!sender.publicKey) {
|
|
153
|
+
throw new Error("Sender's PublicKey is not available, check passed wallet adapter!");
|
|
154
|
+
}
|
|
155
155
|
ixs = [];
|
|
156
|
-
mintPublicKey = isNative ? new web3_js_1.PublicKey(mint)
|
|
156
|
+
mintPublicKey = isNative ? spl_token_1.NATIVE_MINT : new web3_js_1.PublicKey(mint);
|
|
157
157
|
recipientPublicKey = new web3_js_1.PublicKey(recipient);
|
|
158
158
|
metadata = web3_js_1.Keypair.generate();
|
|
159
159
|
return [4 /*yield*/, web3_js_1.PublicKey.findProgramAddress([buffer_1.Buffer.from("strm"), metadata.publicKey.toBuffer()], this.programId)];
|
|
160
160
|
case 1:
|
|
161
|
-
|
|
162
|
-
return [4 /*yield*/, ata(mintPublicKey, sender.publicKey)];
|
|
161
|
+
_g = __read.apply(void 0, [_k.sent(), 1]), escrowTokens = _g[0];
|
|
162
|
+
return [4 /*yield*/, (0, utils_1.ata)(mintPublicKey, sender.publicKey)];
|
|
163
163
|
case 2:
|
|
164
|
-
senderTokens =
|
|
165
|
-
return [4 /*yield*/, ata(mintPublicKey, recipientPublicKey)];
|
|
164
|
+
senderTokens = _k.sent();
|
|
165
|
+
return [4 /*yield*/, (0, utils_1.ata)(mintPublicKey, recipientPublicKey)];
|
|
166
166
|
case 3:
|
|
167
|
-
recipientTokens =
|
|
168
|
-
return [4 /*yield*/, ata(mintPublicKey, constants_1.STREAMFLOW_TREASURY_PUBLIC_KEY)];
|
|
167
|
+
recipientTokens = _k.sent();
|
|
168
|
+
return [4 /*yield*/, (0, utils_1.ata)(mintPublicKey, constants_1.STREAMFLOW_TREASURY_PUBLIC_KEY)];
|
|
169
169
|
case 4:
|
|
170
|
-
streamflowTreasuryTokens =
|
|
171
|
-
partnerPublicKey = partner
|
|
172
|
-
|
|
173
|
-
: constants_1.STREAMFLOW_TREASURY_PUBLIC_KEY;
|
|
174
|
-
return [4 /*yield*/, ata(mintPublicKey, partnerPublicKey)];
|
|
170
|
+
streamflowTreasuryTokens = _k.sent();
|
|
171
|
+
partnerPublicKey = partner ? new web3_js_1.PublicKey(partner) : constants_1.STREAMFLOW_TREASURY_PUBLIC_KEY;
|
|
172
|
+
return [4 /*yield*/, (0, utils_1.ata)(mintPublicKey, partnerPublicKey)];
|
|
175
173
|
case 5:
|
|
176
|
-
partnerTokens =
|
|
174
|
+
partnerTokens = _k.sent();
|
|
177
175
|
if (!isNative) return [3 /*break*/, 7];
|
|
178
176
|
return [4 /*yield*/, (0, instructions_1.prepareWrappedAccount)(this.connection, sender.publicKey, depositedAmount)];
|
|
179
177
|
case 6:
|
|
180
|
-
|
|
178
|
+
_h = _k.sent();
|
|
181
179
|
return [3 /*break*/, 8];
|
|
182
180
|
case 7:
|
|
183
|
-
|
|
184
|
-
|
|
181
|
+
_h = [];
|
|
182
|
+
_k.label = 8;
|
|
185
183
|
case 8:
|
|
186
|
-
nativeInstructions =
|
|
184
|
+
nativeInstructions = _h;
|
|
187
185
|
ixs.push((0, instructions_1.createStreamInstruction)({
|
|
188
186
|
start: new bn_js_1.default(start),
|
|
189
187
|
depositedAmount: depositedAmount,
|
|
@@ -219,21 +217,19 @@ var StreamClient = /** @class */ (function () {
|
|
|
219
217
|
withdrawor: constants_1.WITHDRAWOR_PUBLIC_KEY,
|
|
220
218
|
systemProgram: web3_js_1.SystemProgram.programId,
|
|
221
219
|
}));
|
|
222
|
-
commitment = typeof this.commitment == "string"
|
|
223
|
-
? this.commitment
|
|
224
|
-
: this.commitment.commitment;
|
|
220
|
+
commitment = typeof this.commitment == "string" ? this.commitment : this.commitment.commitment;
|
|
225
221
|
return [4 /*yield*/, this.connection.getLatestBlockhash(commitment)];
|
|
226
222
|
case 9:
|
|
227
|
-
hash =
|
|
228
|
-
tx = (
|
|
223
|
+
hash = _k.sent();
|
|
224
|
+
tx = (_j = new web3_js_1.Transaction({
|
|
229
225
|
feePayer: sender.publicKey,
|
|
230
226
|
blockhash: hash.blockhash,
|
|
231
227
|
lastValidBlockHeight: hash.lastValidBlockHeight,
|
|
232
|
-
})).add.apply(
|
|
228
|
+
})).add.apply(_j, __spreadArray(__spreadArray([], __read(nativeInstructions), false), __read(ixs), false));
|
|
233
229
|
tx.partialSign(metadata);
|
|
234
230
|
return [4 /*yield*/, this.sign(sender, tx, hash)];
|
|
235
231
|
case 10:
|
|
236
|
-
signature =
|
|
232
|
+
signature = _k.sent();
|
|
237
233
|
return [2 /*return*/, { ixs: ixs, tx: signature, metadata: metadata }];
|
|
238
234
|
}
|
|
239
235
|
});
|
|
@@ -248,42 +244,25 @@ var StreamClient = /** @class */ (function () {
|
|
|
248
244
|
* - initialized contract PDA off chain
|
|
249
245
|
*
|
|
250
246
|
* If you are not sure if you should use create or create_unchecked, go for create to be safer.
|
|
251
|
-
*
|
|
252
|
-
* @param {CreateParams} data
|
|
253
|
-
* @param {Wallet | Keypair} data.sender - Wallet signing the transaction. Its address should match the authorized wallet (sender) or transaction will fail.
|
|
254
|
-
* @param {string} data.recipient - Solana address of the recipient. Associated token account will be derived using this address and token mint address.
|
|
255
|
-
* @param {string} data.mint - SPL Token mint.
|
|
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).
|
|
258
|
-
* @param {number} data.period - Time step (period) in seconds per which the unlocking occurs.
|
|
259
|
-
* @param {number} data.cliff - Vesting contract "cliff" timestamp in seconds.
|
|
260
|
-
* @param {BN} data.cliffAmount - Amount unlocked at the "cliff".
|
|
261
|
-
* @param {BN} data.amountPerPeriod - Amount unlocked per each period.
|
|
262
|
-
* @param {string} data.name - Stream name/subject.
|
|
263
|
-
* @param {boolean} data.canTopup - TRUE for streams, FALSE for vesting contracts.
|
|
264
|
-
* @param {boolean} data.cancelableBySender - Whether or not sender can cancel the stream.
|
|
265
|
-
* @param {boolean} data.cancelableByRecipient - Whether or not recipient can cancel the stream.
|
|
266
|
-
* @param {boolean} data.transferableBySender - Whether or not sender can transfer the stream.
|
|
267
|
-
* @param {boolean} data.transferableByRecipient - Whether or not recipient can transfer the stream.
|
|
268
|
-
* @param {boolean} data.automaticWithdrawal - Whether or not a 3rd party can initiate withdraw in the name of recipient.
|
|
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.
|
|
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).
|
|
272
247
|
*/
|
|
273
|
-
|
|
274
|
-
var
|
|
248
|
+
SolanaStreamClient.prototype.createUnchecked = function (_a, _b) {
|
|
249
|
+
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;
|
|
250
|
+
var sender = _b.sender, _e = _b.partner, partner = _e === void 0 ? null : _e, _f = _b.isNative, isNative = _f === void 0 ? false : _f;
|
|
275
251
|
return __awaiter(this, void 0, void 0, function () {
|
|
276
|
-
var mintPublicKey, recipientPublicKey, metadata, rentToExempt, createMetadataInstruction,
|
|
277
|
-
var
|
|
278
|
-
return __generator(this, function (
|
|
279
|
-
switch (
|
|
252
|
+
var mintPublicKey, recipientPublicKey, metadata, rentToExempt, createMetadataInstruction, _g, escrowTokens, senderTokens, partnerPublicKey, nativeInstructions, _h, createInstruction, commitment, ixs, hash, tx, signature;
|
|
253
|
+
var _j;
|
|
254
|
+
return __generator(this, function (_k) {
|
|
255
|
+
switch (_k.label) {
|
|
280
256
|
case 0:
|
|
257
|
+
if (!sender.publicKey) {
|
|
258
|
+
throw new Error("Sender's PublicKey is not available, check passed wallet adapter!");
|
|
259
|
+
}
|
|
281
260
|
mintPublicKey = new web3_js_1.PublicKey(mint);
|
|
282
261
|
recipientPublicKey = new web3_js_1.PublicKey(recipient);
|
|
283
262
|
metadata = web3_js_1.Keypair.generate();
|
|
284
263
|
return [4 /*yield*/, this.connection.getMinimumBalanceForRentExemption(METADATA_ACC_SIZE)];
|
|
285
264
|
case 1:
|
|
286
|
-
rentToExempt =
|
|
265
|
+
rentToExempt = _k.sent();
|
|
287
266
|
createMetadataInstruction = web3_js_1.SystemProgram.createAccount({
|
|
288
267
|
programId: this.programId,
|
|
289
268
|
space: METADATA_ACC_SIZE,
|
|
@@ -293,23 +272,21 @@ var StreamClient = /** @class */ (function () {
|
|
|
293
272
|
});
|
|
294
273
|
return [4 /*yield*/, web3_js_1.PublicKey.findProgramAddress([buffer_1.Buffer.from("strm"), metadata.publicKey.toBuffer()], this.programId)];
|
|
295
274
|
case 2:
|
|
296
|
-
|
|
297
|
-
return [4 /*yield*/, ata(mintPublicKey, sender.publicKey)];
|
|
275
|
+
_g = __read.apply(void 0, [_k.sent(), 1]), escrowTokens = _g[0];
|
|
276
|
+
return [4 /*yield*/, (0, utils_1.ata)(mintPublicKey, sender.publicKey)];
|
|
298
277
|
case 3:
|
|
299
|
-
senderTokens =
|
|
300
|
-
partnerPublicKey = partner
|
|
301
|
-
? new web3_js_1.PublicKey(partner)
|
|
302
|
-
: constants_1.STREAMFLOW_TREASURY_PUBLIC_KEY;
|
|
278
|
+
senderTokens = _k.sent();
|
|
279
|
+
partnerPublicKey = partner ? new web3_js_1.PublicKey(partner) : constants_1.STREAMFLOW_TREASURY_PUBLIC_KEY;
|
|
303
280
|
if (!isNative) return [3 /*break*/, 5];
|
|
304
281
|
return [4 /*yield*/, (0, instructions_1.prepareWrappedAccount)(this.connection, sender.publicKey, depositedAmount)];
|
|
305
282
|
case 4:
|
|
306
|
-
|
|
283
|
+
_h = _k.sent();
|
|
307
284
|
return [3 /*break*/, 6];
|
|
308
285
|
case 5:
|
|
309
|
-
|
|
310
|
-
|
|
286
|
+
_h = [];
|
|
287
|
+
_k.label = 6;
|
|
311
288
|
case 6:
|
|
312
|
-
nativeInstructions =
|
|
289
|
+
nativeInstructions = _h;
|
|
313
290
|
createInstruction = (0, instructions_1.createUncheckedStreamInstruction)({
|
|
314
291
|
start: new bn_js_1.default(start),
|
|
315
292
|
depositedAmount: depositedAmount,
|
|
@@ -340,133 +317,118 @@ var StreamClient = /** @class */ (function () {
|
|
|
340
317
|
withdrawor: constants_1.WITHDRAWOR_PUBLIC_KEY,
|
|
341
318
|
systemProgram: web3_js_1.SystemProgram.programId,
|
|
342
319
|
});
|
|
343
|
-
commitment = typeof this.commitment == "string"
|
|
344
|
-
|
|
345
|
-
: this.commitment.commitment;
|
|
346
|
-
ixs = [
|
|
347
|
-
createMetadataInstruction,
|
|
348
|
-
createInstruction,
|
|
349
|
-
];
|
|
320
|
+
commitment = typeof this.commitment == "string" ? this.commitment : this.commitment.commitment;
|
|
321
|
+
ixs = [createMetadataInstruction, createInstruction];
|
|
350
322
|
return [4 /*yield*/, this.connection.getLatestBlockhash(commitment)];
|
|
351
323
|
case 7:
|
|
352
|
-
hash =
|
|
353
|
-
tx = (
|
|
324
|
+
hash = _k.sent();
|
|
325
|
+
tx = (_j = new web3_js_1.Transaction({
|
|
354
326
|
feePayer: sender.publicKey,
|
|
355
327
|
blockhash: hash.blockhash,
|
|
356
328
|
lastValidBlockHeight: hash.lastValidBlockHeight,
|
|
357
|
-
})).add.apply(
|
|
329
|
+
})).add.apply(_j, __spreadArray(__spreadArray([], __read(nativeInstructions), false), __read(ixs), false));
|
|
358
330
|
tx.partialSign(metadata);
|
|
359
331
|
return [4 /*yield*/, this.sign(sender, tx, hash)];
|
|
360
332
|
case 8:
|
|
361
|
-
signature =
|
|
333
|
+
signature = _k.sent();
|
|
362
334
|
return [2 /*return*/, { ixs: ixs, tx: signature, metadata: metadata }];
|
|
363
335
|
}
|
|
364
336
|
});
|
|
365
337
|
});
|
|
366
338
|
};
|
|
367
339
|
/**
|
|
368
|
-
* Creates
|
|
340
|
+
* Creates multiple stream/vesting contracts.
|
|
369
341
|
* 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
342
|
*/
|
|
387
|
-
|
|
343
|
+
SolanaStreamClient.prototype.createMultiple = function (data, _a) {
|
|
344
|
+
var sender = _a.sender, _b = _a.partner, partner = _b === void 0 ? null : _b, _c = _a.isNative, isNative = _c === void 0 ? false : _c;
|
|
388
345
|
return __awaiter(this, void 0, void 0, function () {
|
|
389
|
-
var
|
|
390
|
-
var e_1,
|
|
346
|
+
var recipients, metadatas, metadataToRecipient, errors, signatures, batch, recipients_1, recipients_1_1, recipientData, _d, tx, metadata, metadataPubKey, e_1_1, totalDepositedAmount, nativeInstructions, commitment, hash, prepareTransaction, signedBatch, prepareTx, batchTransactionsCalls, responses, successes, failures;
|
|
347
|
+
var e_1, _e, _f;
|
|
391
348
|
var _this = this;
|
|
392
|
-
return __generator(this, function (
|
|
393
|
-
switch (
|
|
349
|
+
return __generator(this, function (_g) {
|
|
350
|
+
switch (_g.label) {
|
|
394
351
|
case 0:
|
|
395
|
-
|
|
352
|
+
recipients = data.recipients;
|
|
353
|
+
if (!sender.publicKey) {
|
|
354
|
+
throw new Error("Sender's PublicKey is not available, check passed wallet adapter!");
|
|
355
|
+
}
|
|
396
356
|
metadatas = [];
|
|
397
357
|
metadataToRecipient = {};
|
|
398
358
|
errors = [];
|
|
399
359
|
signatures = [];
|
|
400
360
|
batch = [];
|
|
401
|
-
|
|
361
|
+
_g.label = 1;
|
|
402
362
|
case 1:
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
363
|
+
_g.trys.push([1, 6, 7, 8]);
|
|
364
|
+
recipients_1 = __values(recipients), recipients_1_1 = recipients_1.next();
|
|
365
|
+
_g.label = 2;
|
|
406
366
|
case 2:
|
|
407
|
-
if (!!
|
|
408
|
-
recipientData =
|
|
409
|
-
return [4 /*yield*/, this.prepareStreamTransaction(recipientData, data
|
|
367
|
+
if (!!recipients_1_1.done) return [3 /*break*/, 5];
|
|
368
|
+
recipientData = recipients_1_1.value;
|
|
369
|
+
return [4 /*yield*/, this.prepareStreamTransaction(recipientData, data, {
|
|
370
|
+
sender: sender,
|
|
371
|
+
partner: partner,
|
|
372
|
+
})];
|
|
410
373
|
case 3:
|
|
411
|
-
|
|
374
|
+
_d = _g.sent(), tx = _d.tx, metadata = _d.metadata;
|
|
412
375
|
metadataPubKey = metadata.publicKey.toBase58();
|
|
413
376
|
metadataToRecipient[metadataPubKey] = recipientData;
|
|
414
377
|
metadatas.push(metadata);
|
|
415
378
|
batch.push({ tx: tx, recipient: recipientData.recipient });
|
|
416
|
-
|
|
379
|
+
_g.label = 4;
|
|
417
380
|
case 4:
|
|
418
|
-
|
|
381
|
+
recipients_1_1 = recipients_1.next();
|
|
419
382
|
return [3 /*break*/, 2];
|
|
420
383
|
case 5: return [3 /*break*/, 8];
|
|
421
384
|
case 6:
|
|
422
|
-
e_1_1 =
|
|
385
|
+
e_1_1 = _g.sent();
|
|
423
386
|
e_1 = { error: e_1_1 };
|
|
424
387
|
return [3 /*break*/, 8];
|
|
425
388
|
case 7:
|
|
426
389
|
try {
|
|
427
|
-
if (
|
|
390
|
+
if (recipients_1_1 && !recipients_1_1.done && (_e = recipients_1.return)) _e.call(recipients_1);
|
|
428
391
|
}
|
|
429
392
|
finally { if (e_1) throw e_1.error; }
|
|
430
393
|
return [7 /*endfinally*/];
|
|
431
394
|
case 8:
|
|
432
|
-
if (!
|
|
433
|
-
totalDepositedAmount =
|
|
395
|
+
if (!isNative) return [3 /*break*/, 11];
|
|
396
|
+
totalDepositedAmount = recipients.reduce(function (acc, recipient) { return recipient.amount.add(acc); }, new bn_js_1.default(0));
|
|
434
397
|
return [4 /*yield*/, (0, instructions_1.prepareWrappedAccount)(this.connection, sender.publicKey, totalDepositedAmount)];
|
|
435
398
|
case 9:
|
|
436
|
-
nativeInstructions =
|
|
437
|
-
commitment = typeof this.commitment == "string"
|
|
438
|
-
? this.commitment
|
|
439
|
-
: this.commitment.commitment;
|
|
399
|
+
nativeInstructions = _g.sent();
|
|
400
|
+
commitment = typeof this.commitment == "string" ? this.commitment : this.commitment.commitment;
|
|
440
401
|
return [4 /*yield*/, this.connection.getLatestBlockhash(commitment)];
|
|
441
402
|
case 10:
|
|
442
|
-
hash =
|
|
443
|
-
prepareTransaction = (
|
|
403
|
+
hash = _g.sent();
|
|
404
|
+
prepareTransaction = (_f = new web3_js_1.Transaction({
|
|
444
405
|
feePayer: sender.publicKey,
|
|
445
406
|
blockhash: hash.blockhash,
|
|
446
407
|
lastValidBlockHeight: hash.lastValidBlockHeight,
|
|
447
|
-
})).add.apply(
|
|
408
|
+
})).add.apply(_f, __spreadArray([], __read(nativeInstructions), false));
|
|
448
409
|
batch.push({ tx: prepareTransaction, recipient: sender.publicKey.toBase58() });
|
|
449
|
-
|
|
450
|
-
case 11: return [4 /*yield*/, signAllTransactionWithRecipients(sender, batch)];
|
|
410
|
+
_g.label = 11;
|
|
411
|
+
case 11: return [4 /*yield*/, (0, utils_1.signAllTransactionWithRecipients)(sender, batch)];
|
|
451
412
|
case 12:
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
413
|
+
signedBatch = _g.sent();
|
|
414
|
+
signedBatch.forEach(function (item, index) {
|
|
415
|
+
item.tx.lastValidBlockHeight = batch[index].tx.lastValidBlockHeight;
|
|
416
|
+
});
|
|
417
|
+
if (!isNative) return [3 /*break*/, 14];
|
|
418
|
+
prepareTx = signedBatch.pop();
|
|
419
|
+
return [4 /*yield*/, (0, utils_1.sendAndConfirmStreamRawTransaction)(this.connection, prepareTx)];
|
|
456
420
|
case 13:
|
|
457
|
-
|
|
458
|
-
|
|
421
|
+
_g.sent();
|
|
422
|
+
_g.label = 14;
|
|
459
423
|
case 14:
|
|
460
|
-
batchTransactionsCalls =
|
|
461
|
-
return sendAndConfirmStreamRawTransaction(_this.connection, el);
|
|
424
|
+
batchTransactionsCalls = signedBatch.map(function (el) {
|
|
425
|
+
return (0, utils_1.sendAndConfirmStreamRawTransaction)(_this.connection, el);
|
|
462
426
|
});
|
|
463
427
|
return [4 /*yield*/, Promise.allSettled(batchTransactionsCalls)];
|
|
464
428
|
case 15:
|
|
465
|
-
responses =
|
|
429
|
+
responses = _g.sent();
|
|
466
430
|
successes = responses
|
|
467
|
-
.filter(function (el) {
|
|
468
|
-
return el.status === "fulfilled";
|
|
469
|
-
})
|
|
431
|
+
.filter(function (el) { return el.status === "fulfilled"; })
|
|
470
432
|
.map(function (el) { return el.value; });
|
|
471
433
|
signatures.push.apply(signatures, __spreadArray([], __read(successes.map(function (el) { return el.signature; })), false));
|
|
472
434
|
failures = responses
|
|
@@ -479,35 +441,35 @@ var StreamClient = /** @class */ (function () {
|
|
|
479
441
|
});
|
|
480
442
|
};
|
|
481
443
|
/**
|
|
482
|
-
* Attempts
|
|
483
|
-
* @param {WithdrawParams} data
|
|
484
|
-
* @param {Wallet | Keypair} data.invoker - Wallet signing the transaction. It's address should match authorized wallet (recipient) or transaction will fail.
|
|
485
|
-
* @param {string} data.id - Identifier of a stream (escrow account with metadata) to be withdrawn from.
|
|
486
|
-
* @param {BN} data.amount - Requested amount (in the smallest units) to withdraw (while streaming). If stream is completed, the whole amount will be withdrawn.
|
|
444
|
+
* Attempts withdrawing from the specified stream.
|
|
487
445
|
*/
|
|
488
|
-
|
|
489
|
-
var
|
|
446
|
+
SolanaStreamClient.prototype.withdraw = function (_a, _b) {
|
|
447
|
+
var id = _a.id, amount = _a.amount;
|
|
448
|
+
var invoker = _b.invoker;
|
|
490
449
|
return __awaiter(this, void 0, void 0, function () {
|
|
491
450
|
var ixs, streamPublicKey, escrow, data, streamflowTreasuryTokens, partnerTokens, commitment, hash, tx, signature;
|
|
492
|
-
var
|
|
493
|
-
return __generator(this, function (
|
|
494
|
-
switch (
|
|
451
|
+
var _c;
|
|
452
|
+
return __generator(this, function (_d) {
|
|
453
|
+
switch (_d.label) {
|
|
495
454
|
case 0:
|
|
455
|
+
if (!invoker.publicKey) {
|
|
456
|
+
throw new Error("Invoker's PublicKey is not available, check passed wallet adapter!");
|
|
457
|
+
}
|
|
496
458
|
ixs = [];
|
|
497
459
|
streamPublicKey = new web3_js_1.PublicKey(id);
|
|
498
460
|
return [4 /*yield*/, this.connection.getAccountInfo(streamPublicKey)];
|
|
499
461
|
case 1:
|
|
500
|
-
escrow =
|
|
462
|
+
escrow = _d.sent();
|
|
501
463
|
if (!(escrow === null || escrow === void 0 ? void 0 : escrow.data)) {
|
|
502
464
|
throw new Error("Couldn't get account info");
|
|
503
465
|
}
|
|
504
466
|
data = (0, utils_1.decodeStream)(escrow.data);
|
|
505
|
-
return [4 /*yield*/, ata(data.mint, constants_1.STREAMFLOW_TREASURY_PUBLIC_KEY)];
|
|
467
|
+
return [4 /*yield*/, (0, utils_1.ata)(data.mint, constants_1.STREAMFLOW_TREASURY_PUBLIC_KEY)];
|
|
506
468
|
case 2:
|
|
507
|
-
streamflowTreasuryTokens =
|
|
508
|
-
return [4 /*yield*/, ata(data.mint, data.partner)];
|
|
469
|
+
streamflowTreasuryTokens = _d.sent();
|
|
470
|
+
return [4 /*yield*/, (0, utils_1.ata)(data.mint, data.partner)];
|
|
509
471
|
case 3:
|
|
510
|
-
partnerTokens =
|
|
472
|
+
partnerTokens = _d.sent();
|
|
511
473
|
ixs.push((0, instructions_1.withdrawStreamInstruction)(amount, this.programId, {
|
|
512
474
|
authority: invoker.publicKey,
|
|
513
475
|
recipient: invoker.publicKey,
|
|
@@ -521,20 +483,18 @@ var StreamClient = /** @class */ (function () {
|
|
|
521
483
|
mint: data.mint,
|
|
522
484
|
tokenProgram: spl_token_1.TOKEN_PROGRAM_ID,
|
|
523
485
|
}));
|
|
524
|
-
commitment = typeof this.commitment == "string"
|
|
525
|
-
? this.commitment
|
|
526
|
-
: this.commitment.commitment;
|
|
486
|
+
commitment = typeof this.commitment == "string" ? this.commitment : this.commitment.commitment;
|
|
527
487
|
return [4 /*yield*/, this.connection.getLatestBlockhash(commitment)];
|
|
528
488
|
case 4:
|
|
529
|
-
hash =
|
|
530
|
-
tx = (
|
|
489
|
+
hash = _d.sent();
|
|
490
|
+
tx = (_c = new web3_js_1.Transaction({
|
|
531
491
|
feePayer: invoker.publicKey,
|
|
532
492
|
blockhash: hash.blockhash,
|
|
533
493
|
lastValidBlockHeight: hash.lastValidBlockHeight,
|
|
534
|
-
})).add.apply(
|
|
494
|
+
})).add.apply(_c, __spreadArray([], __read(ixs), false));
|
|
535
495
|
return [4 /*yield*/, this.sign(invoker, tx, hash)];
|
|
536
496
|
case 5:
|
|
537
|
-
signature =
|
|
497
|
+
signature = _d.sent();
|
|
538
498
|
return [2 /*return*/, { ixs: ixs, tx: signature }];
|
|
539
499
|
}
|
|
540
500
|
});
|
|
@@ -542,32 +502,33 @@ var StreamClient = /** @class */ (function () {
|
|
|
542
502
|
};
|
|
543
503
|
/**
|
|
544
504
|
* Attempts canceling the specified stream.
|
|
545
|
-
* @param {CancelParams} data
|
|
546
|
-
* @param {Wallet | Keypair} data.invoker - Wallet signing the transaction. It's address should match authorized wallet (sender or recipient) or transaction will fail.
|
|
547
|
-
* @param {string} data.id - Identifier of a stream (escrow account with metadata) to be canceled.
|
|
548
505
|
*/
|
|
549
|
-
|
|
550
|
-
var
|
|
506
|
+
SolanaStreamClient.prototype.cancel = function (_a, _b) {
|
|
507
|
+
var id = _a.id;
|
|
508
|
+
var invoker = _b.invoker;
|
|
551
509
|
return __awaiter(this, void 0, void 0, function () {
|
|
552
510
|
var streamPublicKey, escrow_acc, data, streamflowTreasuryTokens, partnerTokens, ixs, commitment, hash, tx, signature;
|
|
553
|
-
var
|
|
554
|
-
return __generator(this, function (
|
|
555
|
-
switch (
|
|
511
|
+
var _c;
|
|
512
|
+
return __generator(this, function (_d) {
|
|
513
|
+
switch (_d.label) {
|
|
556
514
|
case 0:
|
|
515
|
+
if (!invoker.publicKey) {
|
|
516
|
+
throw new Error("Invoker's PublicKey is not available, check passed wallet adapter!");
|
|
517
|
+
}
|
|
557
518
|
streamPublicKey = new web3_js_1.PublicKey(id);
|
|
558
519
|
return [4 /*yield*/, this.connection.getAccountInfo(streamPublicKey)];
|
|
559
520
|
case 1:
|
|
560
|
-
escrow_acc =
|
|
521
|
+
escrow_acc = _d.sent();
|
|
561
522
|
if (!(escrow_acc === null || escrow_acc === void 0 ? void 0 : escrow_acc.data)) {
|
|
562
523
|
throw new Error("Couldn't get account info");
|
|
563
524
|
}
|
|
564
525
|
data = (0, utils_1.decodeStream)(escrow_acc === null || escrow_acc === void 0 ? void 0 : escrow_acc.data);
|
|
565
|
-
return [4 /*yield*/, ata(data.mint, constants_1.STREAMFLOW_TREASURY_PUBLIC_KEY)];
|
|
526
|
+
return [4 /*yield*/, (0, utils_1.ata)(data.mint, constants_1.STREAMFLOW_TREASURY_PUBLIC_KEY)];
|
|
566
527
|
case 2:
|
|
567
|
-
streamflowTreasuryTokens =
|
|
568
|
-
return [4 /*yield*/, ata(data.mint, data.partner)];
|
|
528
|
+
streamflowTreasuryTokens = _d.sent();
|
|
529
|
+
return [4 /*yield*/, (0, utils_1.ata)(data.mint, data.partner)];
|
|
569
530
|
case 3:
|
|
570
|
-
partnerTokens =
|
|
531
|
+
partnerTokens = _d.sent();
|
|
571
532
|
ixs = [];
|
|
572
533
|
ixs.push((0, instructions_1.cancelStreamInstruction)(this.programId, {
|
|
573
534
|
authority: invoker.publicKey,
|
|
@@ -584,20 +545,18 @@ var StreamClient = /** @class */ (function () {
|
|
|
584
545
|
mint: data.mint,
|
|
585
546
|
tokenProgram: spl_token_1.TOKEN_PROGRAM_ID,
|
|
586
547
|
}));
|
|
587
|
-
commitment = typeof this.commitment == "string"
|
|
588
|
-
? this.commitment
|
|
589
|
-
: this.commitment.commitment;
|
|
548
|
+
commitment = typeof this.commitment == "string" ? this.commitment : this.commitment.commitment;
|
|
590
549
|
return [4 /*yield*/, this.connection.getLatestBlockhash(commitment)];
|
|
591
550
|
case 4:
|
|
592
|
-
hash =
|
|
593
|
-
tx = (
|
|
551
|
+
hash = _d.sent();
|
|
552
|
+
tx = (_c = new web3_js_1.Transaction({
|
|
594
553
|
feePayer: invoker.publicKey,
|
|
595
554
|
blockhash: hash.blockhash,
|
|
596
555
|
lastValidBlockHeight: hash.lastValidBlockHeight,
|
|
597
|
-
})).add.apply(
|
|
556
|
+
})).add.apply(_c, __spreadArray([], __read(ixs), false));
|
|
598
557
|
return [4 /*yield*/, this.sign(invoker, tx, hash)];
|
|
599
558
|
case 5:
|
|
600
|
-
signature =
|
|
559
|
+
signature = _d.sent();
|
|
601
560
|
return [2 /*return*/, { ixs: ixs, tx: signature }];
|
|
602
561
|
}
|
|
603
562
|
});
|
|
@@ -606,32 +565,32 @@ var StreamClient = /** @class */ (function () {
|
|
|
606
565
|
/**
|
|
607
566
|
* Attempts changing the stream/vesting contract's recipient (effectively transferring the stream/vesting contract).
|
|
608
567
|
* Potential associated token account rent fee (to make it rent-exempt) is paid by the transaction initiator.
|
|
609
|
-
* @param {TransferParams} data
|
|
610
|
-
* @param {Wallet | Keypair} data.invoker - Wallet signing the transaction. It's address should match authorized wallet (sender or recipient) or transaction will fail.
|
|
611
|
-
* @param {string} data.id - Identifier of a stream (escrow account with metadata) to be transferred.
|
|
612
|
-
* @param {string} data.recipientId - Address of a new recipient.
|
|
613
568
|
*/
|
|
614
|
-
|
|
615
|
-
var
|
|
569
|
+
SolanaStreamClient.prototype.transfer = function (_a, _b) {
|
|
570
|
+
var id = _a.id, newRecipientString = _a.newRecipient;
|
|
571
|
+
var invoker = _b.invoker;
|
|
616
572
|
return __awaiter(this, void 0, void 0, function () {
|
|
617
573
|
var ixs, stream, newRecipient, escrow, mint, newRecipientTokens, commitment, hash, tx, signature;
|
|
618
|
-
var
|
|
619
|
-
return __generator(this, function (
|
|
620
|
-
switch (
|
|
574
|
+
var _c;
|
|
575
|
+
return __generator(this, function (_d) {
|
|
576
|
+
switch (_d.label) {
|
|
621
577
|
case 0:
|
|
578
|
+
if (!invoker.publicKey) {
|
|
579
|
+
throw new Error("Invoker's PublicKey is not available, check passed wallet adapter!");
|
|
580
|
+
}
|
|
622
581
|
ixs = [];
|
|
623
582
|
stream = new web3_js_1.PublicKey(id);
|
|
624
|
-
newRecipient = new web3_js_1.PublicKey(
|
|
583
|
+
newRecipient = new web3_js_1.PublicKey(newRecipientString);
|
|
625
584
|
return [4 /*yield*/, this.connection.getAccountInfo(stream)];
|
|
626
585
|
case 1:
|
|
627
|
-
escrow =
|
|
586
|
+
escrow = _d.sent();
|
|
628
587
|
if (!(escrow === null || escrow === void 0 ? void 0 : escrow.data)) {
|
|
629
588
|
throw new Error("Couldn't get account info");
|
|
630
589
|
}
|
|
631
590
|
mint = (0, utils_1.decodeStream)(escrow === null || escrow === void 0 ? void 0 : escrow.data).mint;
|
|
632
|
-
return [4 /*yield*/, ata(mint, newRecipient)];
|
|
591
|
+
return [4 /*yield*/, (0, utils_1.ata)(mint, newRecipient)];
|
|
633
592
|
case 2:
|
|
634
|
-
newRecipientTokens =
|
|
593
|
+
newRecipientTokens = _d.sent();
|
|
635
594
|
ixs.push((0, instructions_1.transferStreamInstruction)(this.programId, {
|
|
636
595
|
authority: invoker.publicKey,
|
|
637
596
|
newRecipient: newRecipient,
|
|
@@ -643,65 +602,63 @@ var StreamClient = /** @class */ (function () {
|
|
|
643
602
|
associatedTokenProgram: spl_token_1.ASSOCIATED_TOKEN_PROGRAM_ID,
|
|
644
603
|
systemProgram: web3_js_1.SystemProgram.programId,
|
|
645
604
|
}));
|
|
646
|
-
commitment = typeof this.commitment == "string"
|
|
647
|
-
? this.commitment
|
|
648
|
-
: this.commitment.commitment;
|
|
605
|
+
commitment = typeof this.commitment == "string" ? this.commitment : this.commitment.commitment;
|
|
649
606
|
return [4 /*yield*/, this.connection.getLatestBlockhash(commitment)];
|
|
650
607
|
case 3:
|
|
651
|
-
hash =
|
|
652
|
-
tx = (
|
|
608
|
+
hash = _d.sent();
|
|
609
|
+
tx = (_c = new web3_js_1.Transaction({
|
|
653
610
|
feePayer: invoker.publicKey,
|
|
654
611
|
blockhash: hash.blockhash,
|
|
655
612
|
lastValidBlockHeight: hash.lastValidBlockHeight,
|
|
656
|
-
})).add.apply(
|
|
613
|
+
})).add.apply(_c, __spreadArray([], __read(ixs), false));
|
|
657
614
|
return [4 /*yield*/, this.sign(invoker, tx, hash)];
|
|
658
615
|
case 4:
|
|
659
|
-
signature =
|
|
616
|
+
signature = _d.sent();
|
|
660
617
|
return [2 /*return*/, { ixs: ixs, tx: signature }];
|
|
661
618
|
}
|
|
662
619
|
});
|
|
663
620
|
});
|
|
664
621
|
};
|
|
665
622
|
/**
|
|
666
|
-
* Tops up stream account
|
|
667
|
-
* @param {TopupParams} data
|
|
668
|
-
* @param {Wallet | Keypair} data.invoker - Wallet signing the transaction. It's address should match current stream sender or transaction will fail.
|
|
669
|
-
* @param {string} data.id - Identifier of a stream (escrow account with metadata) to be topped up.
|
|
670
|
-
* @param {BN} data.amount - Specified amount (in the smallest units) to topup (increases deposited amount).
|
|
623
|
+
* Tops up stream account with specified amount.
|
|
671
624
|
*/
|
|
672
|
-
|
|
673
|
-
var
|
|
625
|
+
SolanaStreamClient.prototype.topup = function (_a, _b) {
|
|
626
|
+
var id = _a.id, amount = _a.amount;
|
|
627
|
+
var invoker = _b.invoker, isNative = _b.isNative;
|
|
674
628
|
return __awaiter(this, void 0, void 0, function () {
|
|
675
|
-
var ixs, streamPublicKey, escrow,
|
|
676
|
-
var
|
|
677
|
-
return __generator(this, function (
|
|
678
|
-
switch (
|
|
629
|
+
var ixs, streamPublicKey, escrow, _c, mint, partner, senderTokens, escrowTokens, streamflowTreasuryTokens, partnerTokens, nativeInstructions, _d, commitment, hash, tx, signature;
|
|
630
|
+
var _e;
|
|
631
|
+
return __generator(this, function (_f) {
|
|
632
|
+
switch (_f.label) {
|
|
679
633
|
case 0:
|
|
634
|
+
if (!invoker.publicKey) {
|
|
635
|
+
throw new Error("Invoker's PublicKey is not available, check passed wallet adapter!");
|
|
636
|
+
}
|
|
680
637
|
ixs = [];
|
|
681
638
|
streamPublicKey = new web3_js_1.PublicKey(id);
|
|
682
639
|
return [4 /*yield*/, this.connection.getAccountInfo(streamPublicKey)];
|
|
683
640
|
case 1:
|
|
684
|
-
escrow =
|
|
641
|
+
escrow = _f.sent();
|
|
685
642
|
if (!(escrow === null || escrow === void 0 ? void 0 : escrow.data)) {
|
|
686
643
|
throw new Error("Couldn't get account info");
|
|
687
644
|
}
|
|
688
|
-
|
|
689
|
-
return [4 /*yield*/, ata(mint, constants_1.STREAMFLOW_TREASURY_PUBLIC_KEY)];
|
|
645
|
+
_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;
|
|
646
|
+
return [4 /*yield*/, (0, utils_1.ata)(mint, constants_1.STREAMFLOW_TREASURY_PUBLIC_KEY)];
|
|
690
647
|
case 2:
|
|
691
|
-
streamflowTreasuryTokens =
|
|
692
|
-
return [4 /*yield*/, ata(mint, partner)];
|
|
648
|
+
streamflowTreasuryTokens = _f.sent();
|
|
649
|
+
return [4 /*yield*/, (0, utils_1.ata)(mint, partner)];
|
|
693
650
|
case 3:
|
|
694
|
-
partnerTokens =
|
|
651
|
+
partnerTokens = _f.sent();
|
|
695
652
|
if (!isNative) return [3 /*break*/, 5];
|
|
696
653
|
return [4 /*yield*/, (0, instructions_1.prepareWrappedAccount)(this.connection, invoker.publicKey, amount)];
|
|
697
654
|
case 4:
|
|
698
|
-
|
|
655
|
+
_d = _f.sent();
|
|
699
656
|
return [3 /*break*/, 6];
|
|
700
657
|
case 5:
|
|
701
|
-
|
|
702
|
-
|
|
658
|
+
_d = [];
|
|
659
|
+
_f.label = 6;
|
|
703
660
|
case 6:
|
|
704
|
-
nativeInstructions =
|
|
661
|
+
nativeInstructions = _d;
|
|
705
662
|
ixs.push((0, instructions_1.topupStreamInstruction)(amount, this.programId, {
|
|
706
663
|
sender: invoker.publicKey,
|
|
707
664
|
senderTokens: senderTokens,
|
|
@@ -716,20 +673,18 @@ var StreamClient = /** @class */ (function () {
|
|
|
716
673
|
withdrawor: constants_1.WITHDRAWOR_PUBLIC_KEY,
|
|
717
674
|
systemProgram: web3_js_1.SystemProgram.programId,
|
|
718
675
|
}));
|
|
719
|
-
commitment = typeof this.commitment == "string"
|
|
720
|
-
? this.commitment
|
|
721
|
-
: this.commitment.commitment;
|
|
676
|
+
commitment = typeof this.commitment == "string" ? this.commitment : this.commitment.commitment;
|
|
722
677
|
return [4 /*yield*/, this.connection.getLatestBlockhash(commitment)];
|
|
723
678
|
case 7:
|
|
724
|
-
hash =
|
|
725
|
-
tx = (
|
|
679
|
+
hash = _f.sent();
|
|
680
|
+
tx = (_e = new web3_js_1.Transaction({
|
|
726
681
|
feePayer: invoker.publicKey,
|
|
727
682
|
blockhash: hash.blockhash,
|
|
728
683
|
lastValidBlockHeight: hash.lastValidBlockHeight,
|
|
729
|
-
})).add.apply(
|
|
684
|
+
})).add.apply(_e, __spreadArray(__spreadArray([], __read(nativeInstructions), false), __read(ixs), false));
|
|
730
685
|
return [4 /*yield*/, this.sign(invoker, tx, hash)];
|
|
731
686
|
case 8:
|
|
732
|
-
signature =
|
|
687
|
+
signature = _f.sent();
|
|
733
688
|
return [2 /*return*/, { ixs: ixs, tx: signature }];
|
|
734
689
|
}
|
|
735
690
|
});
|
|
@@ -737,16 +692,16 @@ var StreamClient = /** @class */ (function () {
|
|
|
737
692
|
};
|
|
738
693
|
/**
|
|
739
694
|
* Fetch stream data by its id (address).
|
|
740
|
-
* @param {string} id - Identifier of a stream that is fetched.
|
|
741
695
|
*/
|
|
742
|
-
|
|
696
|
+
SolanaStreamClient.prototype.getOne = function (_a) {
|
|
697
|
+
var id = _a.id;
|
|
743
698
|
return __awaiter(this, void 0, void 0, function () {
|
|
744
699
|
var escrow;
|
|
745
|
-
return __generator(this, function (
|
|
746
|
-
switch (
|
|
700
|
+
return __generator(this, function (_b) {
|
|
701
|
+
switch (_b.label) {
|
|
747
702
|
case 0: return [4 /*yield*/, this.connection.getAccountInfo(new web3_js_1.PublicKey(id), constants_1.TX_FINALITY_CONFIRMED)];
|
|
748
703
|
case 1:
|
|
749
|
-
escrow =
|
|
704
|
+
escrow = _b.sent();
|
|
750
705
|
if (!(escrow === null || escrow === void 0 ? void 0 : escrow.data)) {
|
|
751
706
|
throw new Error("Couldn't get account info.");
|
|
752
707
|
}
|
|
@@ -758,13 +713,9 @@ var StreamClient = /** @class */ (function () {
|
|
|
758
713
|
/**
|
|
759
714
|
* Fetch streams/contracts by providing direction.
|
|
760
715
|
* Streams are sorted by start time in ascending order.
|
|
761
|
-
* @param {GetAllParams} data
|
|
762
|
-
* @param {PublicKey} data.wallet - PublicKey of the wallet for which the streams/contracts are fetched.
|
|
763
|
-
* @param {StreamType} [data.type = StreamType.All] - It can be one of: stream, vesting, all.
|
|
764
|
-
* @param {StreamDirection} [data.direction = StreamDirection.All] - It can be one of: incoming, outgoing, all.
|
|
765
716
|
*/
|
|
766
|
-
|
|
767
|
-
var wallet = _a.wallet, _b = _a.type, type = _b === void 0 ?
|
|
717
|
+
SolanaStreamClient.prototype.get = function (_a) {
|
|
718
|
+
var wallet = _a.wallet, _b = _a.type, type = _b === void 0 ? types_2.StreamType.All : _b, _c = _a.direction, direction = _c === void 0 ? types_2.StreamDirection.All : _c;
|
|
768
719
|
return __awaiter(this, void 0, void 0, function () {
|
|
769
720
|
var accounts, outgoingAccounts, incomingAccounts, offset, streams, sortedStreams;
|
|
770
721
|
return __generator(this, function (_d) {
|
|
@@ -772,19 +723,17 @@ var StreamClient = /** @class */ (function () {
|
|
|
772
723
|
case 0:
|
|
773
724
|
accounts = [];
|
|
774
725
|
if (!(direction === "all")) return [3 /*break*/, 3];
|
|
775
|
-
return [4 /*yield*/, getProgramAccounts(this.connection, wallet, constants_1.STREAM_STRUCT_OFFSET_SENDER, this.programId)];
|
|
726
|
+
return [4 /*yield*/, (0, utils_1.getProgramAccounts)(this.connection, wallet, constants_1.STREAM_STRUCT_OFFSET_SENDER, this.programId)];
|
|
776
727
|
case 1:
|
|
777
728
|
outgoingAccounts = _d.sent();
|
|
778
|
-
return [4 /*yield*/, getProgramAccounts(this.connection, wallet, constants_1.STREAM_STRUCT_OFFSET_RECIPIENT, this.programId)];
|
|
729
|
+
return [4 /*yield*/, (0, utils_1.getProgramAccounts)(this.connection, wallet, constants_1.STREAM_STRUCT_OFFSET_RECIPIENT, this.programId)];
|
|
779
730
|
case 2:
|
|
780
731
|
incomingAccounts = _d.sent();
|
|
781
732
|
accounts = __spreadArray(__spreadArray([], __read(outgoingAccounts), false), __read(incomingAccounts), false);
|
|
782
733
|
return [3 /*break*/, 5];
|
|
783
734
|
case 3:
|
|
784
|
-
offset = direction === "outgoing"
|
|
785
|
-
|
|
786
|
-
: constants_1.STREAM_STRUCT_OFFSET_RECIPIENT;
|
|
787
|
-
return [4 /*yield*/, getProgramAccounts(this.connection, wallet, offset, this.programId)];
|
|
735
|
+
offset = direction === "outgoing" ? constants_1.STREAM_STRUCT_OFFSET_SENDER : constants_1.STREAM_STRUCT_OFFSET_RECIPIENT;
|
|
736
|
+
return [4 /*yield*/, (0, utils_1.getProgramAccounts)(this.connection, wallet, offset, this.programId)];
|
|
788
737
|
case 4:
|
|
789
738
|
accounts = _d.sent();
|
|
790
739
|
_d.label = 5;
|
|
@@ -809,30 +758,31 @@ var StreamClient = /** @class */ (function () {
|
|
|
809
758
|
});
|
|
810
759
|
});
|
|
811
760
|
};
|
|
812
|
-
|
|
761
|
+
SolanaStreamClient.prototype.sign = function (invoker, tx, hash) {
|
|
813
762
|
return __awaiter(this, void 0, void 0, function () {
|
|
814
|
-
var rawTx, confirmationStrategy, signature;
|
|
763
|
+
var signedTx, rawTx, confirmationStrategy, signature;
|
|
815
764
|
return __generator(this, function (_a) {
|
|
816
765
|
switch (_a.label) {
|
|
817
766
|
case 0:
|
|
818
|
-
if (!
|
|
767
|
+
if (!(0, utils_1.isSignerWallet)(invoker)) return [3 /*break*/, 2];
|
|
819
768
|
return [4 /*yield*/, invoker.signTransaction(tx)];
|
|
820
769
|
case 1:
|
|
821
|
-
_a.sent();
|
|
770
|
+
signedTx = _a.sent();
|
|
822
771
|
return [3 /*break*/, 3];
|
|
823
772
|
case 2:
|
|
824
773
|
tx.partialSign(invoker);
|
|
774
|
+
signedTx = tx;
|
|
825
775
|
_a.label = 3;
|
|
826
776
|
case 3:
|
|
827
|
-
rawTx =
|
|
828
|
-
if (!hash.lastValidBlockHeight || !
|
|
777
|
+
rawTx = signedTx.serialize();
|
|
778
|
+
if (!hash.lastValidBlockHeight || !signedTx.signature || !hash.blockhash)
|
|
829
779
|
throw Error("Error with transaction parameters.");
|
|
830
780
|
confirmationStrategy = {
|
|
831
781
|
lastValidBlockHeight: hash.lastValidBlockHeight,
|
|
832
|
-
signature:
|
|
782
|
+
signature: bs58_1.default.encode(signedTx.signature),
|
|
833
783
|
blockhash: hash.blockhash,
|
|
834
784
|
};
|
|
835
|
-
return [4 /*yield*/, (0, web3_js_1.sendAndConfirmRawTransaction)(this.connection, rawTx, confirmationStrategy)];
|
|
785
|
+
return [4 /*yield*/, (0, web3_js_1.sendAndConfirmRawTransaction)(this.connection, rawTx, confirmationStrategy, { skipPreflight: true })];
|
|
836
786
|
case 4:
|
|
837
787
|
signature = _a.sent();
|
|
838
788
|
return [2 /*return*/, signature];
|
|
@@ -840,47 +790,89 @@ var StreamClient = /** @class */ (function () {
|
|
|
840
790
|
});
|
|
841
791
|
});
|
|
842
792
|
};
|
|
793
|
+
/**
|
|
794
|
+
* Attempts updating the stream auto withdrawal params and amount per period
|
|
795
|
+
*/
|
|
796
|
+
SolanaStreamClient.prototype.update = function (data, _a) {
|
|
797
|
+
var invoker = _a.invoker;
|
|
798
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
799
|
+
var streamPublicKey, escrow, updateIx, commitment, hash, tx, signature;
|
|
800
|
+
return __generator(this, function (_b) {
|
|
801
|
+
switch (_b.label) {
|
|
802
|
+
case 0:
|
|
803
|
+
if (!invoker.publicKey) {
|
|
804
|
+
throw new Error("Invoker's PublicKey is not available, check passed wallet adapter!");
|
|
805
|
+
}
|
|
806
|
+
streamPublicKey = new web3_js_1.PublicKey(data.id);
|
|
807
|
+
return [4 /*yield*/, this.connection.getAccountInfo(streamPublicKey)];
|
|
808
|
+
case 1:
|
|
809
|
+
escrow = _b.sent();
|
|
810
|
+
if (!escrow) {
|
|
811
|
+
throw new Error("Couldn't get account info");
|
|
812
|
+
}
|
|
813
|
+
updateIx = (0, instructions_1.updateStreamInstruction)(data, this.programId, {
|
|
814
|
+
authority: invoker.publicKey,
|
|
815
|
+
metadata: streamPublicKey,
|
|
816
|
+
withdrawor: constants_1.WITHDRAWOR_PUBLIC_KEY,
|
|
817
|
+
systemProgram: web3_js_1.SystemProgram.programId,
|
|
818
|
+
});
|
|
819
|
+
commitment = typeof this.commitment == "string" ? this.commitment : this.commitment.commitment;
|
|
820
|
+
return [4 /*yield*/, this.connection.getLatestBlockhash(commitment)];
|
|
821
|
+
case 2:
|
|
822
|
+
hash = _b.sent();
|
|
823
|
+
tx = new web3_js_1.Transaction({
|
|
824
|
+
feePayer: invoker.publicKey,
|
|
825
|
+
blockhash: hash.blockhash,
|
|
826
|
+
lastValidBlockHeight: hash.lastValidBlockHeight,
|
|
827
|
+
}).add(updateIx);
|
|
828
|
+
return [4 /*yield*/, this.sign(invoker, tx, hash)];
|
|
829
|
+
case 3:
|
|
830
|
+
signature = _b.sent();
|
|
831
|
+
return [2 /*return*/, {
|
|
832
|
+
ixs: [updateIx],
|
|
833
|
+
tx: signature,
|
|
834
|
+
}];
|
|
835
|
+
}
|
|
836
|
+
});
|
|
837
|
+
});
|
|
838
|
+
};
|
|
843
839
|
/**
|
|
844
840
|
* 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
841
|
*/
|
|
848
|
-
|
|
842
|
+
SolanaStreamClient.prototype.prepareStreamTransaction = function (recipient, streamParams, solanaExtendedConfig) {
|
|
849
843
|
return __awaiter(this, void 0, void 0, function () {
|
|
850
|
-
var
|
|
844
|
+
var mint, start, period, cliff, canTopup, cancelableBySender, cancelableByRecipient, transferableBySender, transferableByRecipient, _a, automaticWithdrawal, _b, withdrawalFrequency, sender, _c, partner, ixs, commitment, recipientPublicKey, mintPublicKey, metadata, _d, escrowTokens, senderTokens, recipientTokens, streamflowTreasuryTokens, partnerPublicKey, partnerTokens, hash, tx;
|
|
851
845
|
var _e;
|
|
852
846
|
return __generator(this, function (_f) {
|
|
853
847
|
switch (_f.label) {
|
|
854
848
|
case 0:
|
|
855
|
-
|
|
849
|
+
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;
|
|
850
|
+
sender = solanaExtendedConfig.sender, _c = solanaExtendedConfig.partner, partner = _c === void 0 ? null : _c;
|
|
851
|
+
if (!sender.publicKey) {
|
|
852
|
+
throw new Error("Sender's PublicKey is not available, check passed wallet adapter!");
|
|
853
|
+
}
|
|
856
854
|
ixs = [];
|
|
857
|
-
commitment = typeof this.commitment == "string"
|
|
858
|
-
? this.commitment
|
|
859
|
-
: this.commitment.commitment;
|
|
855
|
+
commitment = typeof this.commitment == "string" ? this.commitment : this.commitment.commitment;
|
|
860
856
|
recipientPublicKey = new web3_js_1.PublicKey(recipient.recipient);
|
|
861
857
|
mintPublicKey = new web3_js_1.PublicKey(mint);
|
|
862
858
|
metadata = web3_js_1.Keypair.generate();
|
|
863
|
-
|
|
859
|
+
_d = __read(web3_js_1.PublicKey.findProgramAddressSync([buffer_1.Buffer.from("strm"), metadata.publicKey.toBuffer()], this.programId), 1), escrowTokens = _d[0];
|
|
860
|
+
return [4 /*yield*/, (0, utils_1.ata)(mintPublicKey, sender.publicKey)];
|
|
864
861
|
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
862
|
senderTokens = _f.sent();
|
|
869
|
-
return [4 /*yield*/, ata(mintPublicKey, recipientPublicKey)];
|
|
870
|
-
case
|
|
863
|
+
return [4 /*yield*/, (0, utils_1.ata)(mintPublicKey, recipientPublicKey)];
|
|
864
|
+
case 2:
|
|
871
865
|
recipientTokens = _f.sent();
|
|
872
|
-
return [4 /*yield*/, ata(mintPublicKey, constants_1.STREAMFLOW_TREASURY_PUBLIC_KEY)];
|
|
873
|
-
case
|
|
866
|
+
return [4 /*yield*/, (0, utils_1.ata)(mintPublicKey, constants_1.STREAMFLOW_TREASURY_PUBLIC_KEY)];
|
|
867
|
+
case 3:
|
|
874
868
|
streamflowTreasuryTokens = _f.sent();
|
|
875
|
-
partnerPublicKey = partner
|
|
876
|
-
|
|
877
|
-
|
|
878
|
-
return [4 /*yield*/, ata(mintPublicKey, partnerPublicKey)];
|
|
879
|
-
case 5:
|
|
869
|
+
partnerPublicKey = partner ? new web3_js_1.PublicKey(partner) : constants_1.STREAMFLOW_TREASURY_PUBLIC_KEY;
|
|
870
|
+
return [4 /*yield*/, (0, utils_1.ata)(mintPublicKey, partnerPublicKey)];
|
|
871
|
+
case 4:
|
|
880
872
|
partnerTokens = _f.sent();
|
|
881
873
|
ixs.push((0, instructions_1.createStreamInstruction)({
|
|
882
874
|
start: new bn_js_1.default(start),
|
|
883
|
-
depositedAmount: recipient.
|
|
875
|
+
depositedAmount: recipient.amount,
|
|
884
876
|
period: new bn_js_1.default(period),
|
|
885
877
|
amountPerPeriod: recipient.amountPerPeriod,
|
|
886
878
|
cliff: new bn_js_1.default(cliff),
|
|
@@ -914,7 +906,7 @@ var StreamClient = /** @class */ (function () {
|
|
|
914
906
|
systemProgram: web3_js_1.SystemProgram.programId,
|
|
915
907
|
}));
|
|
916
908
|
return [4 /*yield*/, this.connection.getLatestBlockhash(commitment)];
|
|
917
|
-
case
|
|
909
|
+
case 5:
|
|
918
910
|
hash = _f.sent();
|
|
919
911
|
tx = (_e = new web3_js_1.Transaction({
|
|
920
912
|
feePayer: sender.publicKey,
|
|
@@ -927,91 +919,6 @@ var StreamClient = /** @class */ (function () {
|
|
|
927
919
|
});
|
|
928
920
|
});
|
|
929
921
|
};
|
|
930
|
-
return
|
|
931
|
-
}());
|
|
932
|
-
exports.default =
|
|
933
|
-
function getProgramAccounts(connection, wallet, offset, programId) {
|
|
934
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
935
|
-
return __generator(this, function (_a) {
|
|
936
|
-
return [2 /*return*/, connection === null || connection === void 0 ? void 0 : connection.getProgramAccounts(programId, {
|
|
937
|
-
filters: [
|
|
938
|
-
{
|
|
939
|
-
memcmp: {
|
|
940
|
-
offset: offset,
|
|
941
|
-
bytes: wallet.toBase58(),
|
|
942
|
-
},
|
|
943
|
-
},
|
|
944
|
-
],
|
|
945
|
-
})];
|
|
946
|
-
});
|
|
947
|
-
});
|
|
948
|
-
}
|
|
949
|
-
function ata(mint, account) {
|
|
950
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
951
|
-
return __generator(this, function (_a) {
|
|
952
|
-
switch (_a.label) {
|
|
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)];
|
|
954
|
-
case 1: return [2 /*return*/, _a.sent()];
|
|
955
|
-
}
|
|
956
|
-
});
|
|
957
|
-
});
|
|
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
|
-
}
|
|
922
|
+
return SolanaStreamClient;
|
|
923
|
+
}(BaseStreamClient_1.BaseStreamClient));
|
|
924
|
+
exports.default = SolanaStreamClient;
|