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