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