@streamflow/stream 7.0.0-alpha.1 → 7.0.0-alpha.11
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +65 -68
- package/dist/cjs/__tests__/aptos/streamClient.spec.js +83 -134
- package/dist/cjs/__tests__/common/GenericStreamClient.spec.js +9 -9
- package/dist/cjs/aptos/StreamClient.js +162 -367
- package/dist/cjs/aptos/constants.js +7 -8
- package/dist/cjs/aptos/index.js +3 -3
- package/dist/cjs/aptos/types.js +32 -41
- package/dist/cjs/aptos/utils.js +4 -4
- package/dist/cjs/aptos/wallet.js +20 -75
- package/dist/cjs/common/BaseStreamClient.js +11 -59
- package/dist/cjs/common/GenericStreamClient.js +46 -72
- package/dist/cjs/common/constants.js +2 -2
- package/dist/cjs/common/contractUtils.js +16 -17
- package/dist/cjs/common/utils.js +34 -84
- package/dist/cjs/evm/StreamClient.js +198 -456
- package/dist/cjs/evm/constants.js +19 -20
- package/dist/cjs/evm/types.js +25 -34
- package/dist/cjs/evm/utils.js +2 -2
- package/dist/cjs/index.js +10 -10
- package/dist/cjs/solana/StreamClient.js +608 -1090
- package/dist/cjs/solana/constants.js +16 -11
- package/dist/cjs/solana/instructions.js +76 -80
- package/dist/cjs/solana/layout.js +7 -8
- package/dist/cjs/solana/types.js +15 -25
- package/dist/cjs/solana/utils.js +77 -154
- package/dist/cjs/sui/StreamClient.js +325 -571
- package/dist/cjs/sui/constants.js +19 -20
- package/dist/cjs/sui/types.js +28 -62
- package/dist/cjs/sui/utils.js +7 -7
- package/dist/cjs/sui/wallet.js +13 -63
- package/dist/esm/__tests__/aptos/streamClient.spec.js +4 -4
- package/dist/esm/aptos/index.d.ts +3 -3
- package/dist/esm/aptos/index.js +3 -3
- package/dist/esm/aptos/types.d.ts +12 -12
- package/dist/esm/aptos/types.js +13 -13
- package/dist/esm/common/GenericStreamClient.d.ts +4 -4
- package/dist/esm/common/GenericStreamClient.js +4 -4
- package/dist/esm/common/constants.d.ts +2 -2
- package/dist/esm/common/constants.js +2 -2
- package/dist/esm/common/contractUtils.d.ts +14 -14
- package/dist/esm/common/contractUtils.js +6 -6
- package/dist/esm/common/types.d.ts +19 -19
- package/dist/esm/common/utils.d.ts +11 -11
- package/dist/esm/common/utils.js +16 -19
- package/dist/esm/evm/StreamClient.d.ts +2 -2
- package/dist/esm/evm/StreamClient.js +7 -7
- package/dist/esm/evm/types.d.ts +37 -37
- package/dist/esm/evm/types.js +13 -13
- package/dist/esm/index.d.ts +9 -9
- package/dist/esm/index.js +9 -9
- package/dist/esm/solana/StreamClient.d.ts +3 -1
- package/dist/esm/solana/StreamClient.js +38 -22
- package/dist/esm/solana/constants.d.ts +3 -0
- package/dist/esm/solana/constants.js +6 -0
- package/dist/esm/solana/instructions.d.ts +17 -17
- package/dist/esm/solana/instructions.js +19 -18
- package/dist/esm/solana/types.d.ts +41 -36
- package/dist/esm/solana/types.js +2 -2
- package/dist/esm/solana/utils.d.ts +2 -0
- package/dist/esm/solana/utils.js +32 -26
- package/dist/esm/sui/StreamClient.js +1 -1
- package/dist/esm/sui/types.d.ts +12 -12
- package/dist/esm/sui/types.js +13 -13
- package/package.json +10 -11
|
@@ -1,31 +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
|
-
var __assign = (this && this.__assign) || function () {
|
|
19
|
-
__assign = Object.assign || function(t) {
|
|
20
|
-
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
|
21
|
-
s = arguments[i];
|
|
22
|
-
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
|
|
23
|
-
t[p] = s[p];
|
|
24
|
-
}
|
|
25
|
-
return t;
|
|
26
|
-
};
|
|
27
|
-
return __assign.apply(this, arguments);
|
|
28
|
-
};
|
|
29
3
|
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
30
4
|
if (k2 === undefined) k2 = k;
|
|
31
5
|
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
@@ -49,247 +23,128 @@ var __importStar = (this && this.__importStar) || function (mod) {
|
|
|
49
23
|
__setModuleDefault(result, mod);
|
|
50
24
|
return result;
|
|
51
25
|
};
|
|
52
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
53
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
54
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
55
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
56
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
57
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
58
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
59
|
-
});
|
|
60
|
-
};
|
|
61
|
-
var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
62
|
-
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
|
|
63
|
-
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
|
64
|
-
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
65
|
-
function step(op) {
|
|
66
|
-
if (f) throw new TypeError("Generator is already executing.");
|
|
67
|
-
while (g && (g = 0, op[0] && (_ = 0)), _) try {
|
|
68
|
-
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;
|
|
69
|
-
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
70
|
-
switch (op[0]) {
|
|
71
|
-
case 0: case 1: t = op; break;
|
|
72
|
-
case 4: _.label++; return { value: op[1], done: false };
|
|
73
|
-
case 5: _.label++; y = op[1]; op = [0]; continue;
|
|
74
|
-
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
|
75
|
-
default:
|
|
76
|
-
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
|
77
|
-
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
|
78
|
-
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
|
79
|
-
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
|
80
|
-
if (t[2]) _.ops.pop();
|
|
81
|
-
_.trys.pop(); continue;
|
|
82
|
-
}
|
|
83
|
-
op = body.call(thisArg, _);
|
|
84
|
-
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
|
85
|
-
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
86
|
-
}
|
|
87
|
-
};
|
|
88
|
-
var __read = (this && this.__read) || function (o, n) {
|
|
89
|
-
var m = typeof Symbol === "function" && o[Symbol.iterator];
|
|
90
|
-
if (!m) return o;
|
|
91
|
-
var i = m.call(o), r, ar = [], e;
|
|
92
|
-
try {
|
|
93
|
-
while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);
|
|
94
|
-
}
|
|
95
|
-
catch (error) { e = { error: error }; }
|
|
96
|
-
finally {
|
|
97
|
-
try {
|
|
98
|
-
if (r && !r.done && (m = i["return"])) m.call(i);
|
|
99
|
-
}
|
|
100
|
-
finally { if (e) throw e.error; }
|
|
101
|
-
}
|
|
102
|
-
return ar;
|
|
103
|
-
};
|
|
104
|
-
var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
|
|
105
|
-
if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
|
|
106
|
-
if (ar || !(i in from)) {
|
|
107
|
-
if (!ar) ar = Array.prototype.slice.call(from, 0, i);
|
|
108
|
-
ar[i] = from[i];
|
|
109
|
-
}
|
|
110
|
-
}
|
|
111
|
-
return to.concat(ar || Array.prototype.slice.call(from));
|
|
112
|
-
};
|
|
113
|
-
var __values = (this && this.__values) || function(o) {
|
|
114
|
-
var s = typeof Symbol === "function" && Symbol.iterator, m = s && o[s], i = 0;
|
|
115
|
-
if (m) return m.call(o);
|
|
116
|
-
if (o && typeof o.length === "number") return {
|
|
117
|
-
next: function () {
|
|
118
|
-
if (o && i >= o.length) o = void 0;
|
|
119
|
-
return { value: o && o[i++], done: !o };
|
|
120
|
-
}
|
|
121
|
-
};
|
|
122
|
-
throw new TypeError(s ? "Object is not iterable." : "Symbol.iterator is not defined.");
|
|
123
|
-
};
|
|
124
26
|
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
125
27
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
126
28
|
};
|
|
127
29
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
128
30
|
exports.SolanaStreamClient = void 0;
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
__extends(SolanaStreamClient, _super);
|
|
31
|
+
const bignumber_js_1 = __importDefault(require("bignumber.js"));
|
|
32
|
+
const buffer_1 = require("buffer");
|
|
33
|
+
const spl_token_1 = require("@solana/spl-token");
|
|
34
|
+
const web3_js_1 = require("@solana/web3.js");
|
|
35
|
+
const solana_1 = require("@streamflow/common/solana");
|
|
36
|
+
const borsh = __importStar(require("borsh"));
|
|
37
|
+
const types_js_1 = require("./types.js");
|
|
38
|
+
const utils_js_1 = require("./utils.js");
|
|
39
|
+
const constants_js_1 = require("./constants.js");
|
|
40
|
+
const instructions_js_1 = require("./instructions.js");
|
|
41
|
+
const types_js_2 = require("../common/types.js");
|
|
42
|
+
const BaseStreamClient_js_1 = require("../common/BaseStreamClient.js");
|
|
43
|
+
const utils_js_2 = require("../common/utils.js");
|
|
44
|
+
const constants_js_2 = require("../common/constants.js");
|
|
45
|
+
const METADATA_ACC_SIZE = 1104;
|
|
46
|
+
class SolanaStreamClient extends BaseStreamClient_js_1.BaseStreamClient {
|
|
146
47
|
/**
|
|
147
48
|
* Create Stream instance
|
|
148
49
|
*/
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
_this.commitment = commitment;
|
|
156
|
-
_this.connection = new web3_js_1.Connection(clusterUrl, _this.commitment);
|
|
157
|
-
_this.programId = programId !== "" ? new web3_js_1.PublicKey(programId) : new web3_js_1.PublicKey(constants_js_1.PROGRAM_ID[cluster]);
|
|
158
|
-
_this.sendThrottler = sendThrottler !== null && sendThrottler !== void 0 ? sendThrottler : (0, solana_1.buildSendThrottler)(sendRate);
|
|
159
|
-
return _this;
|
|
50
|
+
constructor(clusterUrl, cluster = types_js_2.ICluster.Mainnet, commitment = "confirmed", programId = "", sendRate = 1, sendThrottler) {
|
|
51
|
+
super();
|
|
52
|
+
this.commitment = commitment;
|
|
53
|
+
this.connection = new web3_js_1.Connection(clusterUrl, this.commitment);
|
|
54
|
+
this.programId = programId !== "" ? new web3_js_1.PublicKey(programId) : new web3_js_1.PublicKey(constants_js_1.PROGRAM_ID[cluster]);
|
|
55
|
+
this.sendThrottler = sendThrottler ?? (0, solana_1.buildSendThrottler)(sendRate);
|
|
160
56
|
}
|
|
161
|
-
|
|
57
|
+
getConnection() {
|
|
162
58
|
return this.connection;
|
|
163
|
-
}
|
|
164
|
-
|
|
59
|
+
}
|
|
60
|
+
getCommitment() {
|
|
165
61
|
return typeof this.commitment == "string" ? this.commitment : this.commitment.commitment;
|
|
166
|
-
}
|
|
167
|
-
|
|
62
|
+
}
|
|
63
|
+
getProgramId() {
|
|
168
64
|
return this.programId.toBase58();
|
|
169
|
-
}
|
|
65
|
+
}
|
|
170
66
|
/**
|
|
171
67
|
* Creates a new stream/vesting contract.
|
|
172
68
|
* All fees are paid by sender (escrow metadata account rent, escrow token account rent, recipient's associated token account rent, Streamflow's service fee).
|
|
173
69
|
*/
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
_b = _c.sent(), tx = _b.tx, hash = _b.hash, context = _b.context;
|
|
185
|
-
return [4 /*yield*/, (0, solana_1.signAndExecuteTransaction)(this.connection, extParams.sender, tx, {
|
|
186
|
-
hash: hash,
|
|
187
|
-
context: context,
|
|
188
|
-
commitment: this.getCommitment(),
|
|
189
|
-
}, { sendThrottler: this.sendThrottler })];
|
|
190
|
-
case 3:
|
|
191
|
-
signature = _c.sent();
|
|
192
|
-
return [2 /*return*/, { ixs: ixs, txId: signature, metadataId: metadataPubKey.toBase58() }];
|
|
193
|
-
}
|
|
194
|
-
});
|
|
195
|
-
});
|
|
196
|
-
};
|
|
70
|
+
async create(data, extParams) {
|
|
71
|
+
const { ixs, metadata, metadataPubKey } = await this.prepareCreateInstructions(data, extParams);
|
|
72
|
+
const { tx, hash, context } = await (0, solana_1.prepareTransaction)(this.connection, ixs, extParams.sender.publicKey, undefined, metadata);
|
|
73
|
+
const signature = await (0, solana_1.signAndExecuteTransaction)(this.connection, extParams.sender, tx, {
|
|
74
|
+
hash,
|
|
75
|
+
context,
|
|
76
|
+
commitment: this.getCommitment(),
|
|
77
|
+
}, { sendThrottler: this.sendThrottler });
|
|
78
|
+
return { ixs, txId: signature, metadataId: metadataPubKey.toBase58() };
|
|
79
|
+
}
|
|
197
80
|
/**
|
|
198
81
|
* Creates a new stream/vesting contract.
|
|
199
82
|
* All fees are paid by sender (escrow metadata account rent, escrow token account rent, recipient's associated token account rent, Streamflow's service fee).
|
|
200
83
|
*/
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
case 0:
|
|
209
|
-
if (!sender.publicKey) {
|
|
210
|
-
throw new Error("Sender's PublicKey is not available, check passed wallet adapter!");
|
|
211
|
-
}
|
|
212
|
-
ixs = (0, solana_1.prepareBaseInstructions)(this.connection, {
|
|
213
|
-
computePrice: computePrice,
|
|
214
|
-
computeLimit: computeLimit,
|
|
215
|
-
});
|
|
216
|
-
mintPublicKey = isNative ? spl_token_1.NATIVE_MINT : new web3_js_1.PublicKey(mint);
|
|
217
|
-
recipientPublicKey = new web3_js_1.PublicKey(recipient);
|
|
218
|
-
_f = this.getOrCreateStreamMetadata(metadataPubKeys), metadata = _f.metadata, metadataPubKey = _f.metadataPubKey;
|
|
219
|
-
_g = __read(web3_js_1.PublicKey.findProgramAddressSync([buffer_1.Buffer.from("strm"), metadataPubKey.toBuffer()], this.programId), 1), escrowTokens = _g[0];
|
|
220
|
-
return [4 /*yield*/, (0, solana_1.getMintAndProgram)(this.connection, mintPublicKey)];
|
|
221
|
-
case 1:
|
|
222
|
-
tokenProgramId = (_m.sent()).tokenProgramId;
|
|
223
|
-
return [4 /*yield*/, (0, solana_1.ata)(mintPublicKey, sender.publicKey, tokenProgramId)];
|
|
224
|
-
case 2:
|
|
225
|
-
senderTokens = _m.sent();
|
|
226
|
-
return [4 /*yield*/, (0, solana_1.ata)(mintPublicKey, recipientPublicKey, tokenProgramId)];
|
|
227
|
-
case 3:
|
|
228
|
-
recipientTokens = _m.sent();
|
|
229
|
-
return [4 /*yield*/, (0, solana_1.ata)(mintPublicKey, constants_js_1.STREAMFLOW_TREASURY_PUBLIC_KEY, tokenProgramId)];
|
|
230
|
-
case 4:
|
|
231
|
-
streamflowTreasuryTokens = _m.sent();
|
|
232
|
-
partnerPublicKey = partner ? new web3_js_1.PublicKey(partner) : constants_js_1.STREAMFLOW_TREASURY_PUBLIC_KEY;
|
|
233
|
-
return [4 /*yield*/, (0, solana_1.ata)(mintPublicKey, partnerPublicKey, tokenProgramId)];
|
|
234
|
-
case 5:
|
|
235
|
-
partnerTokens = _m.sent();
|
|
236
|
-
if (!isNative) return [3 /*break*/, 8];
|
|
237
|
-
return [4 /*yield*/, this.getTotalFee({
|
|
238
|
-
address: partner !== null && partner !== void 0 ? partner : sender.publicKey.toBase58(),
|
|
239
|
-
})];
|
|
240
|
-
case 6:
|
|
241
|
-
totalFee = _m.sent();
|
|
242
|
-
totalAmount = (0, utils_js_2.calculateTotalAmountToDeposit)(depositedAmount, totalFee);
|
|
243
|
-
_j = (_h = ixs.push).apply;
|
|
244
|
-
_k = [ixs];
|
|
245
|
-
_l = [[]];
|
|
246
|
-
return [4 /*yield*/, (0, solana_1.prepareWrappedAccount)(this.connection, sender.publicKey, totalAmount)];
|
|
247
|
-
case 7:
|
|
248
|
-
_j.apply(_h, _k.concat([__spreadArray.apply(void 0, _l.concat([__read.apply(void 0, [(_m.sent())]), false]))]));
|
|
249
|
-
_m.label = 8;
|
|
250
|
-
case 8:
|
|
251
|
-
ixs.push((0, instructions_js_1.createStreamInstruction)({
|
|
252
|
-
start: new bn_js_1.default(start),
|
|
253
|
-
depositedAmount: depositedAmount,
|
|
254
|
-
period: new bn_js_1.default(period),
|
|
255
|
-
amountPerPeriod: amountPerPeriod,
|
|
256
|
-
cliff: new bn_js_1.default(cliff),
|
|
257
|
-
cliffAmount: cliffAmount,
|
|
258
|
-
cancelableBySender: cancelableBySender,
|
|
259
|
-
cancelableByRecipient: cancelableByRecipient,
|
|
260
|
-
automaticWithdrawal: automaticWithdrawal,
|
|
261
|
-
transferableBySender: transferableBySender,
|
|
262
|
-
transferableByRecipient: transferableByRecipient,
|
|
263
|
-
canTopup: canTopup,
|
|
264
|
-
canUpdateRate: !!canUpdateRate,
|
|
265
|
-
canPause: !!canPause,
|
|
266
|
-
name: name,
|
|
267
|
-
withdrawFrequency: new bn_js_1.default(automaticWithdrawal ? withdrawalFrequency : period),
|
|
268
|
-
}, this.programId, {
|
|
269
|
-
sender: sender.publicKey,
|
|
270
|
-
senderTokens: senderTokens,
|
|
271
|
-
recipient: new web3_js_1.PublicKey(recipient),
|
|
272
|
-
metadata: metadataPubKey,
|
|
273
|
-
escrowTokens: escrowTokens,
|
|
274
|
-
recipientTokens: recipientTokens,
|
|
275
|
-
streamflowTreasury: constants_js_1.STREAMFLOW_TREASURY_PUBLIC_KEY,
|
|
276
|
-
streamflowTreasuryTokens: streamflowTreasuryTokens,
|
|
277
|
-
partner: partnerPublicKey,
|
|
278
|
-
partnerTokens: partnerTokens,
|
|
279
|
-
mint: new web3_js_1.PublicKey(mint),
|
|
280
|
-
feeOracle: constants_js_1.FEE_ORACLE_PUBLIC_KEY,
|
|
281
|
-
rent: web3_js_1.SYSVAR_RENT_PUBKEY,
|
|
282
|
-
timelockProgram: this.programId,
|
|
283
|
-
tokenProgram: tokenProgramId,
|
|
284
|
-
associatedTokenProgram: spl_token_1.ASSOCIATED_TOKEN_PROGRAM_ID,
|
|
285
|
-
withdrawor: constants_js_1.WITHDRAWOR_PUBLIC_KEY,
|
|
286
|
-
systemProgram: web3_js_1.SystemProgram.programId,
|
|
287
|
-
}));
|
|
288
|
-
return [2 /*return*/, { ixs: ixs, metadata: metadata, metadataPubKey: metadataPubKey }];
|
|
289
|
-
}
|
|
290
|
-
});
|
|
84
|
+
async prepareCreateInstructions({ recipient, tokenId: mint, start, amount: depositedAmount, period, cliff, cliffAmount, amountPerPeriod, name, canPause, canUpdateRate, canTopup, cancelableBySender, cancelableByRecipient, transferableBySender, transferableByRecipient, automaticWithdrawal = false, withdrawalFrequency = 0, partner, }, { sender, metadataPubKeys, isNative = false, computePrice, computeLimit }) {
|
|
85
|
+
if (!sender.publicKey) {
|
|
86
|
+
throw new Error("Sender's PublicKey is not available, check passed wallet adapter!");
|
|
87
|
+
}
|
|
88
|
+
const ixs = (0, solana_1.prepareBaseInstructions)(this.connection, {
|
|
89
|
+
computePrice,
|
|
90
|
+
computeLimit,
|
|
291
91
|
});
|
|
292
|
-
|
|
92
|
+
const mintPublicKey = isNative ? spl_token_1.NATIVE_MINT : new web3_js_1.PublicKey(mint);
|
|
93
|
+
const recipientPublicKey = new web3_js_1.PublicKey(recipient);
|
|
94
|
+
const { metadata, metadataPubKey } = this.getOrCreateStreamMetadata(metadataPubKeys);
|
|
95
|
+
const [escrowTokens] = web3_js_1.PublicKey.findProgramAddressSync([buffer_1.Buffer.from("strm"), metadataPubKey.toBuffer()], this.programId);
|
|
96
|
+
const { tokenProgramId } = await (0, solana_1.getMintAndProgram)(this.connection, mintPublicKey);
|
|
97
|
+
const senderTokens = await (0, solana_1.ata)(mintPublicKey, sender.publicKey, tokenProgramId);
|
|
98
|
+
const recipientTokens = await (0, solana_1.ata)(mintPublicKey, recipientPublicKey, tokenProgramId);
|
|
99
|
+
const streamflowTreasuryTokens = await (0, solana_1.ata)(mintPublicKey, constants_js_1.STREAMFLOW_TREASURY_PUBLIC_KEY, tokenProgramId);
|
|
100
|
+
const partnerPublicKey = partner ? new web3_js_1.PublicKey(partner) : constants_js_1.WITHDRAWOR_PUBLIC_KEY;
|
|
101
|
+
const partnerTokens = await (0, solana_1.ata)(mintPublicKey, partnerPublicKey, tokenProgramId);
|
|
102
|
+
if (isNative) {
|
|
103
|
+
const totalFee = await this.getTotalFee({
|
|
104
|
+
address: partnerPublicKey.toString(),
|
|
105
|
+
});
|
|
106
|
+
const totalAmount = (0, utils_js_2.calculateTotalAmountToDeposit)(depositedAmount, totalFee);
|
|
107
|
+
ixs.push(...(await (0, solana_1.prepareWrappedAccount)(this.connection, sender.publicKey, totalAmount)));
|
|
108
|
+
}
|
|
109
|
+
ixs.push((0, instructions_js_1.createStreamInstruction)({
|
|
110
|
+
start: (0, bignumber_js_1.default)(start),
|
|
111
|
+
depositedAmount,
|
|
112
|
+
period: (0, bignumber_js_1.default)(period),
|
|
113
|
+
amountPerPeriod,
|
|
114
|
+
cliff: (0, bignumber_js_1.default)(cliff),
|
|
115
|
+
cliffAmount: (0, bignumber_js_1.default)(cliffAmount),
|
|
116
|
+
cancelableBySender,
|
|
117
|
+
cancelableByRecipient,
|
|
118
|
+
automaticWithdrawal,
|
|
119
|
+
transferableBySender,
|
|
120
|
+
transferableByRecipient,
|
|
121
|
+
canTopup,
|
|
122
|
+
canUpdateRate: !!canUpdateRate,
|
|
123
|
+
canPause: !!canPause,
|
|
124
|
+
name,
|
|
125
|
+
withdrawFrequency: (0, bignumber_js_1.default)(automaticWithdrawal ? withdrawalFrequency : period),
|
|
126
|
+
}, this.programId, {
|
|
127
|
+
sender: sender.publicKey,
|
|
128
|
+
senderTokens,
|
|
129
|
+
recipient: new web3_js_1.PublicKey(recipient),
|
|
130
|
+
metadata: metadataPubKey,
|
|
131
|
+
escrowTokens,
|
|
132
|
+
recipientTokens,
|
|
133
|
+
streamflowTreasury: constants_js_1.STREAMFLOW_TREASURY_PUBLIC_KEY,
|
|
134
|
+
streamflowTreasuryTokens: streamflowTreasuryTokens,
|
|
135
|
+
partner: partnerPublicKey,
|
|
136
|
+
partnerTokens: partnerTokens,
|
|
137
|
+
mint: new web3_js_1.PublicKey(mint),
|
|
138
|
+
feeOracle: constants_js_1.FEE_ORACLE_PUBLIC_KEY,
|
|
139
|
+
rent: web3_js_1.SYSVAR_RENT_PUBKEY,
|
|
140
|
+
timelockProgram: this.programId,
|
|
141
|
+
tokenProgram: tokenProgramId,
|
|
142
|
+
associatedTokenProgram: spl_token_1.ASSOCIATED_TOKEN_PROGRAM_ID,
|
|
143
|
+
withdrawor: constants_js_1.WITHDRAWOR_PUBLIC_KEY,
|
|
144
|
+
systemProgram: web3_js_1.SystemProgram.programId,
|
|
145
|
+
}));
|
|
146
|
+
return { ixs, metadata, metadataPubKey };
|
|
147
|
+
}
|
|
293
148
|
/**
|
|
294
149
|
* Creates a new stream/vesting contract using unchecked instruction.
|
|
295
150
|
*
|
|
@@ -300,881 +155,560 @@ var SolanaStreamClient = /** @class */ (function (_super) {
|
|
|
300
155
|
*
|
|
301
156
|
* If you are not sure if you should use create or create_unchecked, go for create to be safer.
|
|
302
157
|
*/
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
_b = _c.sent(), tx = _b.tx, hash = _b.hash, context = _b.context;
|
|
314
|
-
return [4 /*yield*/, (0, solana_1.signAndExecuteTransaction)(this.connection, extParams.sender, tx, {
|
|
315
|
-
hash: hash,
|
|
316
|
-
context: context,
|
|
317
|
-
commitment: this.getCommitment(),
|
|
318
|
-
}, { sendThrottler: this.sendThrottler })];
|
|
319
|
-
case 3:
|
|
320
|
-
signature = _c.sent();
|
|
321
|
-
return [2 /*return*/, { ixs: ixs, txId: signature, metadataId: metadataPubKey.toBase58() }];
|
|
322
|
-
}
|
|
323
|
-
});
|
|
324
|
-
});
|
|
325
|
-
};
|
|
158
|
+
async createUnchecked(data, extParams) {
|
|
159
|
+
const { ixs, metadata, metadataPubKey } = await this.prepareCreateUncheckedInstructions(data, extParams);
|
|
160
|
+
const { tx, hash, context } = await (0, solana_1.prepareTransaction)(this.connection, ixs, extParams.sender.publicKey, undefined, metadata);
|
|
161
|
+
const signature = await (0, solana_1.signAndExecuteTransaction)(this.connection, extParams.sender, tx, {
|
|
162
|
+
hash,
|
|
163
|
+
context,
|
|
164
|
+
commitment: this.getCommitment(),
|
|
165
|
+
}, { sendThrottler: this.sendThrottler });
|
|
166
|
+
return { ixs, txId: signature, metadataId: metadataPubKey.toBase58() };
|
|
167
|
+
}
|
|
326
168
|
/**
|
|
327
169
|
* Create Transaction instructions for `createUnchecked`
|
|
328
170
|
*/
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
return [4 /*yield*/, this.connection.getMinimumBalanceForRentExemption(METADATA_ACC_SIZE)];
|
|
344
|
-
case 1:
|
|
345
|
-
rentToExempt = _m.sent();
|
|
346
|
-
createMetadataInstruction = web3_js_1.SystemProgram.createAccount({
|
|
347
|
-
programId: this.programId,
|
|
348
|
-
space: METADATA_ACC_SIZE,
|
|
349
|
-
lamports: rentToExempt,
|
|
350
|
-
fromPubkey: sender === null || sender === void 0 ? void 0 : sender.publicKey,
|
|
351
|
-
newAccountPubkey: metadataPubKey,
|
|
352
|
-
});
|
|
353
|
-
_g = __read(web3_js_1.PublicKey.findProgramAddressSync([buffer_1.Buffer.from("strm"), metadataPubKey.toBuffer()], this.programId), 1), escrowTokens = _g[0];
|
|
354
|
-
return [4 /*yield*/, (0, solana_1.getMintAndProgram)(this.connection, mintPublicKey)];
|
|
355
|
-
case 2:
|
|
356
|
-
tokenProgramId = (_m.sent()).tokenProgramId;
|
|
357
|
-
return [4 /*yield*/, (0, solana_1.ata)(mintPublicKey, sender.publicKey, tokenProgramId)];
|
|
358
|
-
case 3:
|
|
359
|
-
senderTokens = _m.sent();
|
|
360
|
-
partnerPublicKey = partner ? new web3_js_1.PublicKey(partner) : constants_js_1.STREAMFLOW_TREASURY_PUBLIC_KEY;
|
|
361
|
-
ixs = (0, solana_1.prepareBaseInstructions)(this.connection, {
|
|
362
|
-
computePrice: computePrice,
|
|
363
|
-
computeLimit: computeLimit,
|
|
364
|
-
});
|
|
365
|
-
if (!isNative) return [3 /*break*/, 6];
|
|
366
|
-
return [4 /*yield*/, this.getTotalFee({ address: partner !== null && partner !== void 0 ? partner : sender.publicKey.toBase58() })];
|
|
367
|
-
case 4:
|
|
368
|
-
totalFee = _m.sent();
|
|
369
|
-
totalAmount = (0, utils_js_2.calculateTotalAmountToDeposit)(depositedAmount, totalFee);
|
|
370
|
-
_j = (_h = ixs.push).apply;
|
|
371
|
-
_k = [ixs];
|
|
372
|
-
_l = [[]];
|
|
373
|
-
return [4 /*yield*/, (0, solana_1.prepareWrappedAccount)(this.connection, sender.publicKey, totalAmount)];
|
|
374
|
-
case 5:
|
|
375
|
-
_j.apply(_h, _k.concat([__spreadArray.apply(void 0, _l.concat([__read.apply(void 0, [(_m.sent())]), false]))]));
|
|
376
|
-
_m.label = 6;
|
|
377
|
-
case 6:
|
|
378
|
-
createInstruction = (0, instructions_js_1.createUncheckedStreamInstruction)({
|
|
379
|
-
start: new bn_js_1.default(start),
|
|
380
|
-
depositedAmount: depositedAmount,
|
|
381
|
-
period: new bn_js_1.default(period),
|
|
382
|
-
amountPerPeriod: amountPerPeriod,
|
|
383
|
-
cliff: new bn_js_1.default(cliff),
|
|
384
|
-
cliffAmount: cliffAmount,
|
|
385
|
-
cancelableBySender: cancelableBySender,
|
|
386
|
-
cancelableByRecipient: cancelableByRecipient,
|
|
387
|
-
automaticWithdrawal: automaticWithdrawal,
|
|
388
|
-
transferableBySender: transferableBySender,
|
|
389
|
-
transferableByRecipient: transferableByRecipient,
|
|
390
|
-
canTopup: canTopup,
|
|
391
|
-
canUpdateRate: !!canUpdateRate,
|
|
392
|
-
canPause: !!canPause,
|
|
393
|
-
name: name,
|
|
394
|
-
withdrawFrequency: new bn_js_1.default(automaticWithdrawal ? withdrawalFrequency : period),
|
|
395
|
-
recipient: recipientPublicKey,
|
|
396
|
-
partner: partnerPublicKey,
|
|
397
|
-
}, this.programId, {
|
|
398
|
-
sender: sender.publicKey,
|
|
399
|
-
senderTokens: senderTokens,
|
|
400
|
-
metadata: metadataPubKey,
|
|
401
|
-
escrowTokens: escrowTokens,
|
|
402
|
-
mint: new web3_js_1.PublicKey(mint),
|
|
403
|
-
feeOracle: constants_js_1.FEE_ORACLE_PUBLIC_KEY,
|
|
404
|
-
rent: web3_js_1.SYSVAR_RENT_PUBKEY,
|
|
405
|
-
timelockProgram: this.programId,
|
|
406
|
-
tokenProgram: tokenProgramId,
|
|
407
|
-
withdrawor: constants_js_1.WITHDRAWOR_PUBLIC_KEY,
|
|
408
|
-
systemProgram: web3_js_1.SystemProgram.programId,
|
|
409
|
-
});
|
|
410
|
-
ixs.push(createMetadataInstruction, createInstruction);
|
|
411
|
-
return [2 /*return*/, { ixs: ixs, metadata: metadata, metadataPubKey: metadataPubKey }];
|
|
412
|
-
}
|
|
413
|
-
});
|
|
171
|
+
async prepareCreateUncheckedInstructions({ recipient, tokenId: mint, start, amount: depositedAmount, period, cliff, cliffAmount, amountPerPeriod, name, canTopup, canUpdateRate, canPause, cancelableBySender, cancelableByRecipient, transferableBySender, transferableByRecipient, automaticWithdrawal = false, withdrawalFrequency = 0, partner, }, { sender, metadataPubKeys, isNative = false, computePrice, computeLimit }) {
|
|
172
|
+
if (!sender.publicKey) {
|
|
173
|
+
throw new Error("Sender's PublicKey is not available, check passed wallet adapter!");
|
|
174
|
+
}
|
|
175
|
+
const mintPublicKey = new web3_js_1.PublicKey(mint);
|
|
176
|
+
const recipientPublicKey = new web3_js_1.PublicKey(recipient);
|
|
177
|
+
const { metadata, metadataPubKey } = this.getOrCreateStreamMetadata(metadataPubKeys);
|
|
178
|
+
const rentToExempt = await this.connection.getMinimumBalanceForRentExemption(METADATA_ACC_SIZE);
|
|
179
|
+
const createMetadataInstruction = web3_js_1.SystemProgram.createAccount({
|
|
180
|
+
programId: this.programId,
|
|
181
|
+
space: METADATA_ACC_SIZE,
|
|
182
|
+
lamports: rentToExempt,
|
|
183
|
+
fromPubkey: sender?.publicKey,
|
|
184
|
+
newAccountPubkey: metadataPubKey,
|
|
414
185
|
});
|
|
415
|
-
|
|
186
|
+
const [escrowTokens] = web3_js_1.PublicKey.findProgramAddressSync([buffer_1.Buffer.from("strm"), metadataPubKey.toBuffer()], this.programId);
|
|
187
|
+
const { tokenProgramId } = await (0, solana_1.getMintAndProgram)(this.connection, mintPublicKey);
|
|
188
|
+
const senderTokens = await (0, solana_1.ata)(mintPublicKey, sender.publicKey, tokenProgramId);
|
|
189
|
+
const partnerPublicKey = partner ? new web3_js_1.PublicKey(partner) : constants_js_1.WITHDRAWOR_PUBLIC_KEY;
|
|
190
|
+
const ixs = (0, solana_1.prepareBaseInstructions)(this.connection, {
|
|
191
|
+
computePrice,
|
|
192
|
+
computeLimit,
|
|
193
|
+
});
|
|
194
|
+
if (isNative) {
|
|
195
|
+
const totalFee = await this.getTotalFee({ address: partnerPublicKey.toString() });
|
|
196
|
+
const totalAmount = (0, utils_js_2.calculateTotalAmountToDeposit)(depositedAmount, totalFee);
|
|
197
|
+
ixs.push(...(await (0, solana_1.prepareWrappedAccount)(this.connection, sender.publicKey, totalAmount)));
|
|
198
|
+
}
|
|
199
|
+
const createInstruction = (0, instructions_js_1.createUncheckedStreamInstruction)({
|
|
200
|
+
start: (0, bignumber_js_1.default)(start),
|
|
201
|
+
depositedAmount,
|
|
202
|
+
period: (0, bignumber_js_1.default)(period),
|
|
203
|
+
amountPerPeriod,
|
|
204
|
+
cliff: (0, bignumber_js_1.default)(cliff),
|
|
205
|
+
cliffAmount: (0, bignumber_js_1.default)(cliffAmount),
|
|
206
|
+
cancelableBySender,
|
|
207
|
+
cancelableByRecipient,
|
|
208
|
+
automaticWithdrawal,
|
|
209
|
+
transferableBySender,
|
|
210
|
+
transferableByRecipient,
|
|
211
|
+
canTopup,
|
|
212
|
+
canUpdateRate: !!canUpdateRate,
|
|
213
|
+
canPause: !!canPause,
|
|
214
|
+
name,
|
|
215
|
+
withdrawFrequency: (0, bignumber_js_1.default)(automaticWithdrawal ? withdrawalFrequency : period),
|
|
216
|
+
recipient: recipientPublicKey,
|
|
217
|
+
partner: partnerPublicKey,
|
|
218
|
+
}, this.programId, {
|
|
219
|
+
sender: sender.publicKey,
|
|
220
|
+
senderTokens,
|
|
221
|
+
metadata: metadataPubKey,
|
|
222
|
+
escrowTokens,
|
|
223
|
+
mint: new web3_js_1.PublicKey(mint),
|
|
224
|
+
feeOracle: constants_js_1.FEE_ORACLE_PUBLIC_KEY,
|
|
225
|
+
rent: web3_js_1.SYSVAR_RENT_PUBKEY,
|
|
226
|
+
timelockProgram: this.programId,
|
|
227
|
+
tokenProgram: tokenProgramId,
|
|
228
|
+
withdrawor: constants_js_1.WITHDRAWOR_PUBLIC_KEY,
|
|
229
|
+
systemProgram: web3_js_1.SystemProgram.programId,
|
|
230
|
+
});
|
|
231
|
+
ixs.push(createMetadataInstruction, createInstruction);
|
|
232
|
+
return { ixs, metadata, metadataPubKey };
|
|
233
|
+
}
|
|
416
234
|
/**
|
|
417
235
|
* Creates multiple stream/vesting contracts.
|
|
418
236
|
* All fees are paid by sender (escrow metadata account rent, escrow token account rent, recipient's associated token account rent, Streamflow's service fee).
|
|
419
237
|
*/
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
metadataPubKeys = metadataPubKeys || [];
|
|
440
|
-
i = 0;
|
|
441
|
-
_r.label = 1;
|
|
442
|
-
case 1:
|
|
443
|
-
if (!(i < recipients.length)) return [3 /*break*/, 4];
|
|
444
|
-
recipientData = recipients[i];
|
|
445
|
-
return [4 /*yield*/, this.prepareStreamInstructions(recipientData, data, {
|
|
446
|
-
sender: sender,
|
|
447
|
-
metadataPubKeys: metadataPubKeys[i] ? [metadataPubKeys[i]] : undefined,
|
|
448
|
-
computePrice: computePrice,
|
|
449
|
-
computeLimit: computeLimit,
|
|
450
|
-
})];
|
|
451
|
-
case 2:
|
|
452
|
-
_c = _r.sent(), ixs = _c.ixs, metadata = _c.metadata, metadataPubKey = _c.metadataPubKey;
|
|
453
|
-
metadataToRecipient[metadataPubKey.toBase58()] = recipientData;
|
|
454
|
-
metadatas.push(metadataPubKey.toBase58());
|
|
455
|
-
instructionsBatch.push({
|
|
456
|
-
ixs: ixs,
|
|
457
|
-
metadata: metadata,
|
|
458
|
-
recipient: recipientData.recipient,
|
|
459
|
-
});
|
|
460
|
-
_r.label = 3;
|
|
461
|
-
case 3:
|
|
462
|
-
i++;
|
|
463
|
-
return [3 /*break*/, 1];
|
|
464
|
-
case 4: return [4 /*yield*/, this.connection.getLatestBlockhashAndContext()];
|
|
465
|
-
case 5:
|
|
466
|
-
_d = _r.sent(), hash = _d.value, context = _d.context;
|
|
467
|
-
try {
|
|
468
|
-
for (instructionsBatch_1 = __values(instructionsBatch), instructionsBatch_1_1 = instructionsBatch_1.next(); !instructionsBatch_1_1.done; instructionsBatch_1_1 = instructionsBatch_1.next()) {
|
|
469
|
-
_e = instructionsBatch_1_1.value, ixs = _e.ixs, metadata = _e.metadata, recipient = _e.recipient;
|
|
470
|
-
messageV0 = new web3_js_1.TransactionMessage({
|
|
471
|
-
payerKey: sender.publicKey,
|
|
472
|
-
recentBlockhash: hash.blockhash,
|
|
473
|
-
instructions: ixs,
|
|
474
|
-
}).compileToV0Message();
|
|
475
|
-
tx = new web3_js_1.VersionedTransaction(messageV0);
|
|
476
|
-
if (metadata) {
|
|
477
|
-
tx.sign([metadata]);
|
|
478
|
-
}
|
|
479
|
-
batch.push({ tx: tx, recipient: recipient });
|
|
480
|
-
}
|
|
481
|
-
}
|
|
482
|
-
catch (e_2_1) { e_2 = { error: e_2_1 }; }
|
|
483
|
-
finally {
|
|
484
|
-
try {
|
|
485
|
-
if (instructionsBatch_1_1 && !instructionsBatch_1_1.done && (_p = instructionsBatch_1.return)) _p.call(instructionsBatch_1);
|
|
486
|
-
}
|
|
487
|
-
finally { if (e_2) throw e_2.error; }
|
|
488
|
-
}
|
|
489
|
-
if (!isNative) return [3 /*break*/, 7];
|
|
490
|
-
totalDepositedAmount = recipients.reduce(function (acc, recipient) { return recipient.amount.add(acc); }, new bn_js_1.default(0));
|
|
491
|
-
return [4 /*yield*/, (0, solana_1.prepareWrappedAccount)(this.connection, sender.publicKey, totalDepositedAmount)];
|
|
492
|
-
case 6:
|
|
493
|
-
nativeInstructions = _r.sent();
|
|
494
|
-
messageV0 = new web3_js_1.TransactionMessage({
|
|
495
|
-
payerKey: sender.publicKey,
|
|
496
|
-
recentBlockhash: hash.blockhash,
|
|
497
|
-
instructions: nativeInstructions,
|
|
498
|
-
}).compileToV0Message();
|
|
499
|
-
tx = new web3_js_1.VersionedTransaction(messageV0);
|
|
500
|
-
batch.push({
|
|
501
|
-
tx: tx,
|
|
502
|
-
recipient: sender.publicKey.toBase58(),
|
|
503
|
-
});
|
|
504
|
-
_r.label = 7;
|
|
505
|
-
case 7: return [4 /*yield*/, (0, utils_js_1.signAllTransactionWithRecipients)(sender, batch)];
|
|
506
|
-
case 8:
|
|
507
|
-
signedBatch = _r.sent();
|
|
508
|
-
if (!isNative) return [3 /*break*/, 10];
|
|
509
|
-
prepareTx = signedBatch.pop();
|
|
510
|
-
return [4 /*yield*/, (0, utils_js_1.sendAndConfirmStreamRawTransaction)(this.connection, prepareTx, { hash: hash, context: context }, { sendThrottler: this.sendThrottler })];
|
|
511
|
-
case 9:
|
|
512
|
-
_r.sent();
|
|
513
|
-
_r.label = 10;
|
|
514
|
-
case 10:
|
|
515
|
-
responses = [];
|
|
516
|
-
if (!(metadataPubKeys.length > 0)) return [3 /*break*/, 19];
|
|
517
|
-
_r.label = 11;
|
|
518
|
-
case 11:
|
|
519
|
-
_r.trys.push([11, 16, 17, 18]);
|
|
520
|
-
signedBatch_1 = __values(signedBatch), signedBatch_1_1 = signedBatch_1.next();
|
|
521
|
-
_r.label = 12;
|
|
522
|
-
case 12:
|
|
523
|
-
if (!!signedBatch_1_1.done) return [3 /*break*/, 15];
|
|
524
|
-
batchTx = signedBatch_1_1.value;
|
|
525
|
-
_g = (_f = responses.push).apply;
|
|
526
|
-
_h = [responses];
|
|
527
|
-
_j = [[]];
|
|
528
|
-
return [4 /*yield*/, Promise.allSettled([
|
|
529
|
-
(0, solana_1.executeTransaction)(this.connection, batchTx.tx, { hash: hash, context: context }, { sendThrottler: this.sendThrottler }),
|
|
530
|
-
])];
|
|
531
|
-
case 13:
|
|
532
|
-
_g.apply(_f, _h.concat([__spreadArray.apply(void 0, _j.concat([__read.apply(void 0, [(_r.sent())]), false]))]));
|
|
533
|
-
_r.label = 14;
|
|
534
|
-
case 14:
|
|
535
|
-
signedBatch_1_1 = signedBatch_1.next();
|
|
536
|
-
return [3 /*break*/, 12];
|
|
537
|
-
case 15: return [3 /*break*/, 18];
|
|
538
|
-
case 16:
|
|
539
|
-
e_1_1 = _r.sent();
|
|
540
|
-
e_1 = { error: e_1_1 };
|
|
541
|
-
return [3 /*break*/, 18];
|
|
542
|
-
case 17:
|
|
543
|
-
try {
|
|
544
|
-
if (signedBatch_1_1 && !signedBatch_1_1.done && (_q = signedBatch_1.return)) _q.call(signedBatch_1);
|
|
545
|
-
}
|
|
546
|
-
finally { if (e_1) throw e_1.error; }
|
|
547
|
-
return [7 /*endfinally*/];
|
|
548
|
-
case 18: return [3 /*break*/, 21];
|
|
549
|
-
case 19:
|
|
550
|
-
_l =
|
|
551
|
-
//send all transactions in parallel and wait for them to settle.
|
|
552
|
-
//it allows to speed up the process of sending transactions
|
|
553
|
-
//we then filter all promise responses and handle failed transactions
|
|
554
|
-
(_k = responses.push).apply;
|
|
555
|
-
_m = [
|
|
556
|
-
//send all transactions in parallel and wait for them to settle.
|
|
557
|
-
//it allows to speed up the process of sending transactions
|
|
558
|
-
//we then filter all promise responses and handle failed transactions
|
|
559
|
-
responses];
|
|
560
|
-
_o = [[]];
|
|
561
|
-
return [4 /*yield*/, (0, solana_1.executeMultipleTransactions)(this.connection, signedBatch.map(function (item) { return item.tx; }), { hash: hash, context: context }, { sendThrottler: this.sendThrottler })];
|
|
562
|
-
case 20:
|
|
563
|
-
//send all transactions in parallel and wait for them to settle.
|
|
564
|
-
//it allows to speed up the process of sending transactions
|
|
565
|
-
//we then filter all promise responses and handle failed transactions
|
|
566
|
-
_l.apply(_k, _m.concat([__spreadArray.apply(void 0, _o.concat([__read.apply(void 0, [(_r.sent())]), false]))]));
|
|
567
|
-
_r.label = 21;
|
|
568
|
-
case 21:
|
|
569
|
-
responses.forEach(function (item, index) {
|
|
570
|
-
if (item.status === "fulfilled") {
|
|
571
|
-
signatures.push(item.value);
|
|
572
|
-
}
|
|
573
|
-
else {
|
|
574
|
-
errors.push({
|
|
575
|
-
recipient: signedBatch[index].recipient,
|
|
576
|
-
error: item.reason,
|
|
577
|
-
contractErrorCode: _this.extractErrorCode(item.reason) || undefined,
|
|
578
|
-
});
|
|
579
|
-
}
|
|
580
|
-
});
|
|
581
|
-
return [2 /*return*/, { txs: signatures, metadatas: metadatas, metadataToRecipient: metadataToRecipient, errors: errors }];
|
|
582
|
-
}
|
|
238
|
+
async createMultiple(data, { sender, metadataPubKeys, isNative = false, computePrice, computeLimit }) {
|
|
239
|
+
const { recipients } = data;
|
|
240
|
+
if (!sender.publicKey) {
|
|
241
|
+
throw new Error("Sender's PublicKey is not available, check passed wallet adapter!");
|
|
242
|
+
}
|
|
243
|
+
const metadatas = [];
|
|
244
|
+
const metadataToRecipient = {};
|
|
245
|
+
const errors = [];
|
|
246
|
+
const signatures = [];
|
|
247
|
+
const batch = [];
|
|
248
|
+
const instructionsBatch = [];
|
|
249
|
+
metadataPubKeys = metadataPubKeys || [];
|
|
250
|
+
for (let i = 0; i < recipients.length; i++) {
|
|
251
|
+
const recipientData = recipients[i];
|
|
252
|
+
const { ixs, metadata, metadataPubKey } = await this.prepareStreamInstructions(recipientData, data, {
|
|
253
|
+
sender,
|
|
254
|
+
metadataPubKeys: metadataPubKeys[i] ? [metadataPubKeys[i]] : undefined,
|
|
255
|
+
computePrice,
|
|
256
|
+
computeLimit,
|
|
583
257
|
});
|
|
258
|
+
metadataToRecipient[metadataPubKey.toBase58()] = recipientData;
|
|
259
|
+
metadatas.push(metadataPubKey.toBase58());
|
|
260
|
+
instructionsBatch.push({
|
|
261
|
+
ixs,
|
|
262
|
+
metadata,
|
|
263
|
+
recipient: recipientData.recipient,
|
|
264
|
+
});
|
|
265
|
+
}
|
|
266
|
+
const { value: hash, context } = await this.connection.getLatestBlockhashAndContext();
|
|
267
|
+
for (const { ixs, metadata, recipient } of instructionsBatch) {
|
|
268
|
+
const messageV0 = new web3_js_1.TransactionMessage({
|
|
269
|
+
payerKey: sender.publicKey,
|
|
270
|
+
recentBlockhash: hash.blockhash,
|
|
271
|
+
instructions: ixs,
|
|
272
|
+
}).compileToV0Message();
|
|
273
|
+
const tx = new web3_js_1.VersionedTransaction(messageV0);
|
|
274
|
+
if (metadata) {
|
|
275
|
+
tx.sign([metadata]);
|
|
276
|
+
}
|
|
277
|
+
batch.push({ tx, recipient });
|
|
278
|
+
}
|
|
279
|
+
if (isNative) {
|
|
280
|
+
const totalDepositedAmount = recipients.reduce((acc, recipient) => recipient.amount.plus(acc), (0, bignumber_js_1.default)(0));
|
|
281
|
+
const nativeInstructions = await (0, solana_1.prepareWrappedAccount)(this.connection, sender.publicKey, totalDepositedAmount);
|
|
282
|
+
const messageV0 = new web3_js_1.TransactionMessage({
|
|
283
|
+
payerKey: sender.publicKey,
|
|
284
|
+
recentBlockhash: hash.blockhash,
|
|
285
|
+
instructions: nativeInstructions,
|
|
286
|
+
}).compileToV0Message();
|
|
287
|
+
const tx = new web3_js_1.VersionedTransaction(messageV0);
|
|
288
|
+
batch.push({
|
|
289
|
+
tx,
|
|
290
|
+
recipient: sender.publicKey.toBase58(),
|
|
291
|
+
});
|
|
292
|
+
}
|
|
293
|
+
const signedBatch = await (0, utils_js_1.signAllTransactionWithRecipients)(sender, batch);
|
|
294
|
+
if (isNative) {
|
|
295
|
+
const prepareTx = signedBatch.pop();
|
|
296
|
+
await (0, utils_js_1.sendAndConfirmStreamRawTransaction)(this.connection, prepareTx, { hash, context }, { sendThrottler: this.sendThrottler });
|
|
297
|
+
}
|
|
298
|
+
const responses = [];
|
|
299
|
+
if (metadataPubKeys.length > 0) {
|
|
300
|
+
//if metadata pub keys were passed we should execute transaction sequentially
|
|
301
|
+
//ephemeral signer need to be used first before proceeding with the next
|
|
302
|
+
for (const batchTx of signedBatch) {
|
|
303
|
+
responses.push(...(await Promise.allSettled([
|
|
304
|
+
(0, solana_1.executeTransaction)(this.connection, batchTx.tx, { hash, context }, { sendThrottler: this.sendThrottler }),
|
|
305
|
+
])));
|
|
306
|
+
}
|
|
307
|
+
}
|
|
308
|
+
else {
|
|
309
|
+
//send all transactions in parallel and wait for them to settle.
|
|
310
|
+
//it allows to speed up the process of sending transactions
|
|
311
|
+
//we then filter all promise responses and handle failed transactions
|
|
312
|
+
responses.push(...(await (0, solana_1.executeMultipleTransactions)(this.connection, signedBatch.map((item) => item.tx), { hash, context }, { sendThrottler: this.sendThrottler })));
|
|
313
|
+
}
|
|
314
|
+
responses.forEach((item, index) => {
|
|
315
|
+
if (item.status === "fulfilled") {
|
|
316
|
+
signatures.push(item.value);
|
|
317
|
+
}
|
|
318
|
+
else {
|
|
319
|
+
errors.push({
|
|
320
|
+
recipient: signedBatch[index].recipient,
|
|
321
|
+
error: item.reason,
|
|
322
|
+
contractErrorCode: this.extractErrorCode(item.reason) || undefined,
|
|
323
|
+
});
|
|
324
|
+
}
|
|
584
325
|
});
|
|
585
|
-
|
|
326
|
+
return { txs: signatures, metadatas, metadataToRecipient, errors };
|
|
327
|
+
}
|
|
586
328
|
/**
|
|
587
329
|
* Attempts withdrawing from the specified stream.
|
|
588
330
|
*/
|
|
589
|
-
|
|
590
|
-
|
|
591
|
-
|
|
592
|
-
|
|
593
|
-
|
|
594
|
-
|
|
595
|
-
|
|
596
|
-
|
|
597
|
-
|
|
598
|
-
|
|
599
|
-
case 2:
|
|
600
|
-
_c = _d.sent(), tx = _c.tx, hash = _c.hash, context = _c.context;
|
|
601
|
-
return [4 /*yield*/, (0, solana_1.signAndExecuteTransaction)(this.connection, extParams.invoker, tx, {
|
|
602
|
-
hash: hash,
|
|
603
|
-
context: context,
|
|
604
|
-
commitment: this.getCommitment(),
|
|
605
|
-
}, { sendThrottler: this.sendThrottler })];
|
|
606
|
-
case 3:
|
|
607
|
-
signature = _d.sent();
|
|
608
|
-
return [2 /*return*/, { ixs: ixs, txId: signature }];
|
|
609
|
-
}
|
|
610
|
-
});
|
|
611
|
-
});
|
|
612
|
-
};
|
|
331
|
+
async withdraw({ id, amount = constants_js_2.WITHDRAW_AVAILABLE_AMOUNT }, extParams) {
|
|
332
|
+
const ixs = await this.prepareWithdrawInstructions({ id, amount }, extParams);
|
|
333
|
+
const { tx, hash, context } = await (0, solana_1.prepareTransaction)(this.connection, ixs, extParams.invoker.publicKey);
|
|
334
|
+
const signature = await (0, solana_1.signAndExecuteTransaction)(this.connection, extParams.invoker, tx, {
|
|
335
|
+
hash,
|
|
336
|
+
context,
|
|
337
|
+
commitment: this.getCommitment(),
|
|
338
|
+
}, { sendThrottler: this.sendThrottler });
|
|
339
|
+
return { ixs, txId: signature };
|
|
340
|
+
}
|
|
613
341
|
/**
|
|
614
342
|
* Creates Transaction Instructions for withdrawal
|
|
615
343
|
*/
|
|
616
|
-
|
|
617
|
-
|
|
618
|
-
|
|
619
|
-
|
|
620
|
-
|
|
621
|
-
|
|
622
|
-
|
|
623
|
-
case 0:
|
|
624
|
-
if (!invoker.publicKey) {
|
|
625
|
-
throw new Error("Invoker's PublicKey is not available, check passed wallet adapter!");
|
|
626
|
-
}
|
|
627
|
-
ixs = (0, solana_1.prepareBaseInstructions)(this.connection, {
|
|
628
|
-
computePrice: computePrice,
|
|
629
|
-
computeLimit: computeLimit,
|
|
630
|
-
});
|
|
631
|
-
streamPublicKey = new web3_js_1.PublicKey(id);
|
|
632
|
-
return [4 /*yield*/, this.connection.getAccountInfo(streamPublicKey)];
|
|
633
|
-
case 1:
|
|
634
|
-
escrow = _d.sent();
|
|
635
|
-
if (!(escrow === null || escrow === void 0 ? void 0 : escrow.data)) {
|
|
636
|
-
throw new Error("Couldn't get account info");
|
|
637
|
-
}
|
|
638
|
-
data = (0, utils_js_1.decodeStream)(escrow.data);
|
|
639
|
-
return [4 /*yield*/, (0, solana_1.getMintAndProgram)(this.connection, data.mint)];
|
|
640
|
-
case 2:
|
|
641
|
-
tokenProgramId = (_d.sent()).tokenProgramId;
|
|
642
|
-
return [4 /*yield*/, (0, solana_1.ata)(data.mint, constants_js_1.STREAMFLOW_TREASURY_PUBLIC_KEY, tokenProgramId)];
|
|
643
|
-
case 3:
|
|
644
|
-
streamflowTreasuryTokens = _d.sent();
|
|
645
|
-
return [4 /*yield*/, (0, solana_1.ata)(data.mint, data.partner, tokenProgramId)];
|
|
646
|
-
case 4:
|
|
647
|
-
partnerTokens = _d.sent();
|
|
648
|
-
return [4 /*yield*/, this.checkAssociatedTokenAccounts(data, { invoker: invoker, checkTokenAccounts: checkTokenAccounts }, ixs, tokenProgramId)];
|
|
649
|
-
case 5:
|
|
650
|
-
_d.sent();
|
|
651
|
-
ixs.push((0, instructions_js_1.withdrawStreamInstruction)(amount, this.programId, {
|
|
652
|
-
authority: invoker.publicKey,
|
|
653
|
-
recipient: invoker.publicKey,
|
|
654
|
-
recipientTokens: data.recipientTokens,
|
|
655
|
-
metadata: streamPublicKey,
|
|
656
|
-
escrowTokens: data.escrowTokens,
|
|
657
|
-
streamflowTreasury: constants_js_1.STREAMFLOW_TREASURY_PUBLIC_KEY,
|
|
658
|
-
streamflowTreasuryTokens: streamflowTreasuryTokens,
|
|
659
|
-
partner: data.partner,
|
|
660
|
-
partnerTokens: partnerTokens,
|
|
661
|
-
mint: data.mint,
|
|
662
|
-
tokenProgram: tokenProgramId,
|
|
663
|
-
}));
|
|
664
|
-
return [2 /*return*/, ixs];
|
|
665
|
-
}
|
|
666
|
-
});
|
|
344
|
+
async prepareWithdrawInstructions({ id, amount = constants_js_2.WITHDRAW_AVAILABLE_AMOUNT }, { invoker, checkTokenAccounts, computePrice, computeLimit }) {
|
|
345
|
+
if (!invoker.publicKey) {
|
|
346
|
+
throw new Error("Invoker's PublicKey is not available, check passed wallet adapter!");
|
|
347
|
+
}
|
|
348
|
+
const ixs = (0, solana_1.prepareBaseInstructions)(this.connection, {
|
|
349
|
+
computePrice,
|
|
350
|
+
computeLimit,
|
|
667
351
|
});
|
|
668
|
-
|
|
352
|
+
const streamPublicKey = new web3_js_1.PublicKey(id);
|
|
353
|
+
const escrow = await this.connection.getAccountInfo(streamPublicKey);
|
|
354
|
+
if (!escrow?.data) {
|
|
355
|
+
throw new Error("Couldn't get account info");
|
|
356
|
+
}
|
|
357
|
+
const data = (0, utils_js_1.decodeStream)(escrow.data);
|
|
358
|
+
const { tokenProgramId } = await (0, solana_1.getMintAndProgram)(this.connection, data.mint);
|
|
359
|
+
const streamflowTreasuryTokens = await (0, solana_1.ata)(data.mint, constants_js_1.STREAMFLOW_TREASURY_PUBLIC_KEY, tokenProgramId);
|
|
360
|
+
const partnerTokens = await (0, solana_1.ata)(data.mint, data.partner, tokenProgramId);
|
|
361
|
+
await this.checkAssociatedTokenAccounts(data, { invoker, checkTokenAccounts }, ixs, tokenProgramId);
|
|
362
|
+
ixs.push((0, instructions_js_1.withdrawStreamInstruction)(amount, this.programId, {
|
|
363
|
+
authority: invoker.publicKey,
|
|
364
|
+
recipient: invoker.publicKey,
|
|
365
|
+
recipientTokens: data.recipientTokens,
|
|
366
|
+
metadata: streamPublicKey,
|
|
367
|
+
escrowTokens: data.escrowTokens,
|
|
368
|
+
streamflowTreasury: constants_js_1.STREAMFLOW_TREASURY_PUBLIC_KEY,
|
|
369
|
+
streamflowTreasuryTokens,
|
|
370
|
+
partner: data.partner,
|
|
371
|
+
partnerTokens,
|
|
372
|
+
mint: data.mint,
|
|
373
|
+
tokenProgram: tokenProgramId,
|
|
374
|
+
}));
|
|
375
|
+
return ixs;
|
|
376
|
+
}
|
|
669
377
|
/**
|
|
670
378
|
* Attempts canceling the specified stream.
|
|
671
379
|
*/
|
|
672
|
-
|
|
673
|
-
|
|
674
|
-
|
|
675
|
-
|
|
676
|
-
|
|
677
|
-
|
|
678
|
-
|
|
679
|
-
|
|
680
|
-
|
|
681
|
-
|
|
682
|
-
case 2:
|
|
683
|
-
_b = _c.sent(), tx = _b.tx, hash = _b.hash, context = _b.context;
|
|
684
|
-
return [4 /*yield*/, (0, solana_1.signAndExecuteTransaction)(this.connection, extParams.invoker, tx, {
|
|
685
|
-
hash: hash,
|
|
686
|
-
context: context,
|
|
687
|
-
commitment: this.getCommitment(),
|
|
688
|
-
}, { sendThrottler: this.sendThrottler })];
|
|
689
|
-
case 3:
|
|
690
|
-
signature = _c.sent();
|
|
691
|
-
return [2 /*return*/, { ixs: ixs, txId: signature }];
|
|
692
|
-
}
|
|
693
|
-
});
|
|
694
|
-
});
|
|
695
|
-
};
|
|
380
|
+
async cancel({ id }, extParams) {
|
|
381
|
+
const ixs = await this.prepareCancelInstructions({ id }, extParams);
|
|
382
|
+
const { tx, hash, context } = await (0, solana_1.prepareTransaction)(this.connection, ixs, extParams.invoker.publicKey);
|
|
383
|
+
const signature = await (0, solana_1.signAndExecuteTransaction)(this.connection, extParams.invoker, tx, {
|
|
384
|
+
hash,
|
|
385
|
+
context,
|
|
386
|
+
commitment: this.getCommitment(),
|
|
387
|
+
}, { sendThrottler: this.sendThrottler });
|
|
388
|
+
return { ixs, txId: signature };
|
|
389
|
+
}
|
|
696
390
|
/**
|
|
697
391
|
* Creates Transaction Instructions for cancel
|
|
698
392
|
*/
|
|
699
|
-
|
|
700
|
-
|
|
701
|
-
|
|
702
|
-
|
|
703
|
-
|
|
704
|
-
|
|
705
|
-
|
|
706
|
-
|
|
707
|
-
|
|
708
|
-
|
|
709
|
-
|
|
710
|
-
|
|
711
|
-
|
|
712
|
-
|
|
713
|
-
|
|
714
|
-
|
|
715
|
-
throw new Error("Couldn't get account info");
|
|
716
|
-
}
|
|
717
|
-
data = (0, utils_js_1.decodeStream)(escrowAcc === null || escrowAcc === void 0 ? void 0 : escrowAcc.data);
|
|
718
|
-
return [4 /*yield*/, (0, solana_1.getMintAndProgram)(this.connection, data.mint)];
|
|
719
|
-
case 2:
|
|
720
|
-
tokenProgramId = (_c.sent()).tokenProgramId;
|
|
721
|
-
return [4 /*yield*/, (0, solana_1.ata)(data.mint, constants_js_1.STREAMFLOW_TREASURY_PUBLIC_KEY, tokenProgramId)];
|
|
722
|
-
case 3:
|
|
723
|
-
streamflowTreasuryTokens = _c.sent();
|
|
724
|
-
return [4 /*yield*/, (0, solana_1.ata)(data.mint, data.partner, tokenProgramId)];
|
|
725
|
-
case 4:
|
|
726
|
-
partnerTokens = _c.sent();
|
|
727
|
-
ixs = (0, solana_1.prepareBaseInstructions)(this.connection, {
|
|
728
|
-
computePrice: computePrice,
|
|
729
|
-
computeLimit: computeLimit,
|
|
730
|
-
});
|
|
731
|
-
return [4 /*yield*/, this.checkAssociatedTokenAccounts(data, { invoker: invoker, checkTokenAccounts: checkTokenAccounts }, ixs, tokenProgramId)];
|
|
732
|
-
case 5:
|
|
733
|
-
_c.sent();
|
|
734
|
-
ixs.push((0, instructions_js_1.cancelStreamInstruction)(this.programId, {
|
|
735
|
-
authority: invoker.publicKey,
|
|
736
|
-
sender: data.sender,
|
|
737
|
-
senderTokens: data.senderTokens,
|
|
738
|
-
recipient: data.recipient,
|
|
739
|
-
recipientTokens: data.recipientTokens,
|
|
740
|
-
metadata: streamPublicKey,
|
|
741
|
-
escrowTokens: data.escrowTokens,
|
|
742
|
-
streamflowTreasury: constants_js_1.STREAMFLOW_TREASURY_PUBLIC_KEY,
|
|
743
|
-
streamflowTreasuryTokens: streamflowTreasuryTokens,
|
|
744
|
-
partner: data.partner,
|
|
745
|
-
partnerTokens: partnerTokens,
|
|
746
|
-
mint: data.mint,
|
|
747
|
-
tokenProgram: tokenProgramId,
|
|
748
|
-
}));
|
|
749
|
-
return [2 /*return*/, ixs];
|
|
750
|
-
}
|
|
751
|
-
});
|
|
393
|
+
async prepareCancelInstructions({ id }, { invoker, checkTokenAccounts, computePrice, computeLimit }) {
|
|
394
|
+
if (!invoker.publicKey) {
|
|
395
|
+
throw new Error("Invoker's PublicKey is not available, check passed wallet adapter!");
|
|
396
|
+
}
|
|
397
|
+
const streamPublicKey = new web3_js_1.PublicKey(id);
|
|
398
|
+
const escrowAcc = await this.connection.getAccountInfo(streamPublicKey);
|
|
399
|
+
if (!escrowAcc?.data) {
|
|
400
|
+
throw new Error("Couldn't get account info");
|
|
401
|
+
}
|
|
402
|
+
const data = (0, utils_js_1.decodeStream)(escrowAcc?.data);
|
|
403
|
+
const { tokenProgramId } = await (0, solana_1.getMintAndProgram)(this.connection, data.mint);
|
|
404
|
+
const streamflowTreasuryTokens = await (0, solana_1.ata)(data.mint, constants_js_1.STREAMFLOW_TREASURY_PUBLIC_KEY, tokenProgramId);
|
|
405
|
+
const partnerTokens = await (0, solana_1.ata)(data.mint, data.partner, tokenProgramId);
|
|
406
|
+
const ixs = (0, solana_1.prepareBaseInstructions)(this.connection, {
|
|
407
|
+
computePrice,
|
|
408
|
+
computeLimit,
|
|
752
409
|
});
|
|
753
|
-
|
|
410
|
+
await this.checkAssociatedTokenAccounts(data, { invoker, checkTokenAccounts }, ixs, tokenProgramId);
|
|
411
|
+
ixs.push((0, instructions_js_1.cancelStreamInstruction)(this.programId, {
|
|
412
|
+
authority: invoker.publicKey,
|
|
413
|
+
sender: data.sender,
|
|
414
|
+
senderTokens: data.senderTokens,
|
|
415
|
+
recipient: data.recipient,
|
|
416
|
+
recipientTokens: data.recipientTokens,
|
|
417
|
+
metadata: streamPublicKey,
|
|
418
|
+
escrowTokens: data.escrowTokens,
|
|
419
|
+
streamflowTreasury: constants_js_1.STREAMFLOW_TREASURY_PUBLIC_KEY,
|
|
420
|
+
streamflowTreasuryTokens: streamflowTreasuryTokens,
|
|
421
|
+
partner: data.partner,
|
|
422
|
+
partnerTokens,
|
|
423
|
+
mint: data.mint,
|
|
424
|
+
tokenProgram: tokenProgramId,
|
|
425
|
+
}));
|
|
426
|
+
return ixs;
|
|
427
|
+
}
|
|
754
428
|
/**
|
|
755
429
|
* Attempts changing the stream/vesting contract's recipient (effectively transferring the stream/vesting contract).
|
|
756
430
|
* Potential associated token account rent fee (to make it rent-exempt) is paid by the transaction initiator.
|
|
757
431
|
*/
|
|
758
|
-
|
|
759
|
-
|
|
760
|
-
|
|
761
|
-
|
|
762
|
-
|
|
763
|
-
|
|
764
|
-
|
|
765
|
-
|
|
766
|
-
|
|
767
|
-
|
|
768
|
-
case 2:
|
|
769
|
-
_b = _c.sent(), tx = _b.tx, hash = _b.hash, context = _b.context;
|
|
770
|
-
return [4 /*yield*/, (0, solana_1.signAndExecuteTransaction)(this.connection, extParams.invoker, tx, {
|
|
771
|
-
hash: hash,
|
|
772
|
-
context: context,
|
|
773
|
-
commitment: this.getCommitment(),
|
|
774
|
-
}, { sendThrottler: this.sendThrottler })];
|
|
775
|
-
case 3:
|
|
776
|
-
signature = _c.sent();
|
|
777
|
-
return [2 /*return*/, { ixs: ixs, txId: signature }];
|
|
778
|
-
}
|
|
779
|
-
});
|
|
780
|
-
});
|
|
781
|
-
};
|
|
432
|
+
async transfer({ id, newRecipient }, extParams) {
|
|
433
|
+
const ixs = await this.prepareTransferInstructions({ id, newRecipient }, extParams);
|
|
434
|
+
const { tx, hash, context } = await (0, solana_1.prepareTransaction)(this.connection, ixs, extParams.invoker.publicKey);
|
|
435
|
+
const signature = await (0, solana_1.signAndExecuteTransaction)(this.connection, extParams.invoker, tx, {
|
|
436
|
+
hash,
|
|
437
|
+
context,
|
|
438
|
+
commitment: this.getCommitment(),
|
|
439
|
+
}, { sendThrottler: this.sendThrottler });
|
|
440
|
+
return { ixs, txId: signature };
|
|
441
|
+
}
|
|
782
442
|
/**
|
|
783
443
|
* Attempts changing the stream/vesting contract's recipient (effectively transferring the stream/vesting contract).
|
|
784
444
|
* Potential associated token account rent fee (to make it rent-exempt) is paid by the transaction initiator.
|
|
785
445
|
*/
|
|
786
|
-
|
|
787
|
-
|
|
788
|
-
|
|
789
|
-
|
|
790
|
-
|
|
791
|
-
|
|
792
|
-
|
|
793
|
-
case 0:
|
|
794
|
-
if (!invoker.publicKey) {
|
|
795
|
-
throw new Error("Invoker's PublicKey is not available, check passed wallet adapter!");
|
|
796
|
-
}
|
|
797
|
-
ixs = (0, solana_1.prepareBaseInstructions)(this.connection, {
|
|
798
|
-
computePrice: computePrice,
|
|
799
|
-
computeLimit: computeLimit,
|
|
800
|
-
});
|
|
801
|
-
stream = new web3_js_1.PublicKey(id);
|
|
802
|
-
newRecipientPublicKey = new web3_js_1.PublicKey(newRecipient);
|
|
803
|
-
return [4 /*yield*/, this.connection.getAccountInfo(stream)];
|
|
804
|
-
case 1:
|
|
805
|
-
escrow = _d.sent();
|
|
806
|
-
if (!(escrow === null || escrow === void 0 ? void 0 : escrow.data)) {
|
|
807
|
-
throw new Error("Couldn't get account info");
|
|
808
|
-
}
|
|
809
|
-
mint = (0, utils_js_1.decodeStream)(escrow === null || escrow === void 0 ? void 0 : escrow.data).mint;
|
|
810
|
-
return [4 /*yield*/, (0, solana_1.getMintAndProgram)(this.connection, mint)];
|
|
811
|
-
case 2:
|
|
812
|
-
tokenProgramId = (_d.sent()).tokenProgramId;
|
|
813
|
-
return [4 /*yield*/, (0, solana_1.ata)(mint, newRecipientPublicKey, tokenProgramId)];
|
|
814
|
-
case 3:
|
|
815
|
-
newRecipientTokens = _d.sent();
|
|
816
|
-
ixs.push((0, instructions_js_1.transferStreamInstruction)(this.programId, {
|
|
817
|
-
authority: invoker.publicKey,
|
|
818
|
-
newRecipient: newRecipientPublicKey,
|
|
819
|
-
newRecipientTokens: newRecipientTokens,
|
|
820
|
-
metadata: stream,
|
|
821
|
-
mint: mint,
|
|
822
|
-
rent: web3_js_1.SYSVAR_RENT_PUBKEY,
|
|
823
|
-
tokenProgram: tokenProgramId,
|
|
824
|
-
associatedTokenProgram: spl_token_1.ASSOCIATED_TOKEN_PROGRAM_ID,
|
|
825
|
-
systemProgram: web3_js_1.SystemProgram.programId,
|
|
826
|
-
}));
|
|
827
|
-
return [2 /*return*/, ixs];
|
|
828
|
-
}
|
|
829
|
-
});
|
|
446
|
+
async prepareTransferInstructions({ id, newRecipient }, { invoker, computePrice, computeLimit = 100001 }) {
|
|
447
|
+
if (!invoker.publicKey) {
|
|
448
|
+
throw new Error("Invoker's PublicKey is not available, check passed wallet adapter!");
|
|
449
|
+
}
|
|
450
|
+
const ixs = (0, solana_1.prepareBaseInstructions)(this.connection, {
|
|
451
|
+
computePrice,
|
|
452
|
+
computeLimit,
|
|
830
453
|
});
|
|
831
|
-
|
|
454
|
+
const stream = new web3_js_1.PublicKey(id);
|
|
455
|
+
const newRecipientPublicKey = new web3_js_1.PublicKey(newRecipient);
|
|
456
|
+
const escrow = await this.connection.getAccountInfo(stream);
|
|
457
|
+
if (!escrow?.data) {
|
|
458
|
+
throw new Error("Couldn't get account info");
|
|
459
|
+
}
|
|
460
|
+
const { mint } = (0, utils_js_1.decodeStream)(escrow?.data);
|
|
461
|
+
const { tokenProgramId } = await (0, solana_1.getMintAndProgram)(this.connection, mint);
|
|
462
|
+
const newRecipientTokens = await (0, solana_1.ata)(mint, newRecipientPublicKey, tokenProgramId);
|
|
463
|
+
ixs.push((0, instructions_js_1.transferStreamInstruction)(this.programId, {
|
|
464
|
+
authority: invoker.publicKey,
|
|
465
|
+
newRecipient: newRecipientPublicKey,
|
|
466
|
+
newRecipientTokens,
|
|
467
|
+
metadata: stream,
|
|
468
|
+
mint,
|
|
469
|
+
rent: web3_js_1.SYSVAR_RENT_PUBKEY,
|
|
470
|
+
tokenProgram: tokenProgramId,
|
|
471
|
+
associatedTokenProgram: spl_token_1.ASSOCIATED_TOKEN_PROGRAM_ID,
|
|
472
|
+
systemProgram: web3_js_1.SystemProgram.programId,
|
|
473
|
+
}));
|
|
474
|
+
return ixs;
|
|
475
|
+
}
|
|
832
476
|
/**
|
|
833
477
|
* Tops up stream account with specified amount.
|
|
834
478
|
*/
|
|
835
|
-
|
|
836
|
-
|
|
837
|
-
|
|
838
|
-
|
|
839
|
-
|
|
840
|
-
|
|
841
|
-
|
|
842
|
-
|
|
843
|
-
|
|
844
|
-
|
|
845
|
-
case 2:
|
|
846
|
-
_b = _c.sent(), tx = _b.tx, hash = _b.hash, context = _b.context;
|
|
847
|
-
return [4 /*yield*/, (0, solana_1.signAndExecuteTransaction)(this.connection, extParams.invoker, tx, {
|
|
848
|
-
hash: hash,
|
|
849
|
-
context: context,
|
|
850
|
-
commitment: this.getCommitment(),
|
|
851
|
-
}, { sendThrottler: this.sendThrottler })];
|
|
852
|
-
case 3:
|
|
853
|
-
signature = _c.sent();
|
|
854
|
-
return [2 /*return*/, { ixs: ixs, txId: signature }];
|
|
855
|
-
}
|
|
856
|
-
});
|
|
857
|
-
});
|
|
858
|
-
};
|
|
479
|
+
async topup({ id, amount }, extParams) {
|
|
480
|
+
const ixs = await this.prepareTopupInstructions({ id, amount }, extParams);
|
|
481
|
+
const { tx, hash, context } = await (0, solana_1.prepareTransaction)(this.connection, ixs, extParams.invoker.publicKey);
|
|
482
|
+
const signature = await (0, solana_1.signAndExecuteTransaction)(this.connection, extParams.invoker, tx, {
|
|
483
|
+
hash,
|
|
484
|
+
context,
|
|
485
|
+
commitment: this.getCommitment(),
|
|
486
|
+
}, { sendThrottler: this.sendThrottler });
|
|
487
|
+
return { ixs, txId: signature };
|
|
488
|
+
}
|
|
859
489
|
/**
|
|
860
490
|
* Create Transaction instructions for topup
|
|
861
491
|
*/
|
|
862
|
-
|
|
863
|
-
|
|
864
|
-
|
|
865
|
-
|
|
866
|
-
|
|
867
|
-
|
|
868
|
-
|
|
869
|
-
case 0:
|
|
870
|
-
if (!invoker.publicKey) {
|
|
871
|
-
throw new Error("Invoker's PublicKey is not available, check passed wallet adapter!");
|
|
872
|
-
}
|
|
873
|
-
ixs = (0, solana_1.prepareBaseInstructions)(this.connection, {
|
|
874
|
-
computePrice: computePrice,
|
|
875
|
-
computeLimit: computeLimit,
|
|
876
|
-
});
|
|
877
|
-
streamPublicKey = new web3_js_1.PublicKey(id);
|
|
878
|
-
return [4 /*yield*/, this.connection.getAccountInfo(streamPublicKey)];
|
|
879
|
-
case 1:
|
|
880
|
-
escrow = _h.sent();
|
|
881
|
-
if (!(escrow === null || escrow === void 0 ? void 0 : escrow.data)) {
|
|
882
|
-
throw new Error("Couldn't get account info");
|
|
883
|
-
}
|
|
884
|
-
_c = (0, utils_js_1.decodeStream)(escrow === null || escrow === void 0 ? void 0 : escrow.data), mint = _c.mint, partner = _c.partner, senderTokens = _c.senderTokens, escrowTokens = _c.escrowTokens;
|
|
885
|
-
return [4 /*yield*/, (0, solana_1.getMintAndProgram)(this.connection, mint)];
|
|
886
|
-
case 2:
|
|
887
|
-
tokenProgramId = (_h.sent()).tokenProgramId;
|
|
888
|
-
return [4 /*yield*/, (0, solana_1.ata)(mint, constants_js_1.STREAMFLOW_TREASURY_PUBLIC_KEY, tokenProgramId)];
|
|
889
|
-
case 3:
|
|
890
|
-
streamflowTreasuryTokens = _h.sent();
|
|
891
|
-
return [4 /*yield*/, (0, solana_1.ata)(mint, partner, tokenProgramId)];
|
|
892
|
-
case 4:
|
|
893
|
-
partnerTokens = _h.sent();
|
|
894
|
-
if (!isNative) return [3 /*break*/, 6];
|
|
895
|
-
_e = (_d = ixs.push).apply;
|
|
896
|
-
_f = [ixs];
|
|
897
|
-
_g = [[]];
|
|
898
|
-
return [4 /*yield*/, (0, solana_1.prepareWrappedAccount)(this.connection, invoker.publicKey, amount)];
|
|
899
|
-
case 5:
|
|
900
|
-
_e.apply(_d, _f.concat([__spreadArray.apply(void 0, _g.concat([__read.apply(void 0, [(_h.sent())]), false]))]));
|
|
901
|
-
_h.label = 6;
|
|
902
|
-
case 6:
|
|
903
|
-
ixs.push((0, instructions_js_1.topupStreamInstruction)(amount, this.programId, {
|
|
904
|
-
sender: invoker.publicKey,
|
|
905
|
-
senderTokens: senderTokens,
|
|
906
|
-
metadata: streamPublicKey,
|
|
907
|
-
escrowTokens: escrowTokens,
|
|
908
|
-
streamflowTreasury: constants_js_1.STREAMFLOW_TREASURY_PUBLIC_KEY,
|
|
909
|
-
streamflowTreasuryTokens: streamflowTreasuryTokens,
|
|
910
|
-
partner: partner,
|
|
911
|
-
partnerTokens: partnerTokens,
|
|
912
|
-
mint: mint,
|
|
913
|
-
tokenProgram: tokenProgramId,
|
|
914
|
-
withdrawor: constants_js_1.WITHDRAWOR_PUBLIC_KEY,
|
|
915
|
-
systemProgram: web3_js_1.SystemProgram.programId,
|
|
916
|
-
}));
|
|
917
|
-
return [2 /*return*/, ixs];
|
|
918
|
-
}
|
|
919
|
-
});
|
|
492
|
+
async prepareTopupInstructions({ id, amount }, { invoker, isNative, computePrice, computeLimit }) {
|
|
493
|
+
if (!invoker.publicKey) {
|
|
494
|
+
throw new Error("Invoker's PublicKey is not available, check passed wallet adapter!");
|
|
495
|
+
}
|
|
496
|
+
const ixs = (0, solana_1.prepareBaseInstructions)(this.connection, {
|
|
497
|
+
computePrice,
|
|
498
|
+
computeLimit,
|
|
920
499
|
});
|
|
921
|
-
|
|
500
|
+
const streamPublicKey = new web3_js_1.PublicKey(id);
|
|
501
|
+
const escrow = await this.connection.getAccountInfo(streamPublicKey);
|
|
502
|
+
if (!escrow?.data) {
|
|
503
|
+
throw new Error("Couldn't get account info");
|
|
504
|
+
}
|
|
505
|
+
const { mint, partner, senderTokens, escrowTokens } = (0, utils_js_1.decodeStream)(escrow?.data);
|
|
506
|
+
const { tokenProgramId } = await (0, solana_1.getMintAndProgram)(this.connection, mint);
|
|
507
|
+
const streamflowTreasuryTokens = await (0, solana_1.ata)(mint, constants_js_1.STREAMFLOW_TREASURY_PUBLIC_KEY, tokenProgramId);
|
|
508
|
+
const partnerTokens = await (0, solana_1.ata)(mint, partner, tokenProgramId);
|
|
509
|
+
if (isNative) {
|
|
510
|
+
ixs.push(...(await (0, solana_1.prepareWrappedAccount)(this.connection, invoker.publicKey, amount)));
|
|
511
|
+
}
|
|
512
|
+
ixs.push((0, instructions_js_1.topupStreamInstruction)(amount, this.programId, {
|
|
513
|
+
sender: invoker.publicKey,
|
|
514
|
+
senderTokens,
|
|
515
|
+
metadata: streamPublicKey,
|
|
516
|
+
escrowTokens,
|
|
517
|
+
streamflowTreasury: constants_js_1.STREAMFLOW_TREASURY_PUBLIC_KEY,
|
|
518
|
+
streamflowTreasuryTokens: streamflowTreasuryTokens,
|
|
519
|
+
partner: partner,
|
|
520
|
+
partnerTokens: partnerTokens,
|
|
521
|
+
mint,
|
|
522
|
+
tokenProgram: tokenProgramId,
|
|
523
|
+
withdrawor: constants_js_1.WITHDRAWOR_PUBLIC_KEY,
|
|
524
|
+
systemProgram: web3_js_1.SystemProgram.programId,
|
|
525
|
+
}));
|
|
526
|
+
return ixs;
|
|
527
|
+
}
|
|
922
528
|
/**
|
|
923
529
|
* Fetch stream data by its id (address).
|
|
924
530
|
*/
|
|
925
|
-
|
|
926
|
-
|
|
927
|
-
|
|
928
|
-
|
|
929
|
-
|
|
930
|
-
|
|
931
|
-
|
|
932
|
-
case 1:
|
|
933
|
-
escrow = _b.sent();
|
|
934
|
-
if (!(escrow === null || escrow === void 0 ? void 0 : escrow.data)) {
|
|
935
|
-
throw new Error("Couldn't get account info.");
|
|
936
|
-
}
|
|
937
|
-
return [2 /*return*/, new types_js_1.Contract((0, utils_js_1.decodeStream)(escrow === null || escrow === void 0 ? void 0 : escrow.data))];
|
|
938
|
-
}
|
|
939
|
-
});
|
|
940
|
-
});
|
|
941
|
-
};
|
|
531
|
+
async getOne({ id }) {
|
|
532
|
+
const escrow = await this.connection.getAccountInfo(new web3_js_1.PublicKey(id), constants_js_1.TX_FINALITY_CONFIRMED);
|
|
533
|
+
if (!escrow?.data) {
|
|
534
|
+
throw new Error("Couldn't get account info.");
|
|
535
|
+
}
|
|
536
|
+
return new types_js_1.Contract((0, utils_js_1.decodeStream)(escrow?.data));
|
|
537
|
+
}
|
|
942
538
|
/**
|
|
943
539
|
* Fetch streams/contracts by providing direction.
|
|
944
540
|
* Streams are sorted by start time in ascending order.
|
|
945
541
|
*/
|
|
946
|
-
|
|
947
|
-
|
|
948
|
-
|
|
949
|
-
|
|
950
|
-
|
|
951
|
-
|
|
952
|
-
|
|
953
|
-
|
|
954
|
-
|
|
955
|
-
|
|
956
|
-
|
|
957
|
-
|
|
958
|
-
|
|
959
|
-
|
|
960
|
-
|
|
961
|
-
|
|
962
|
-
|
|
963
|
-
return [3 /*break*/, 5];
|
|
964
|
-
case 3:
|
|
965
|
-
offset = direction === "outgoing" ? constants_js_1.STREAM_STRUCT_OFFSET_SENDER : constants_js_1.STREAM_STRUCT_OFFSET_RECIPIENT;
|
|
966
|
-
return [4 /*yield*/, (0, solana_1.getProgramAccounts)(this.connection, publicKey, offset, this.programId)];
|
|
967
|
-
case 4:
|
|
968
|
-
accounts = _d.sent();
|
|
969
|
-
_d.label = 5;
|
|
970
|
-
case 5:
|
|
971
|
-
streams = {};
|
|
972
|
-
accounts.forEach(function (account) {
|
|
973
|
-
var _a;
|
|
974
|
-
var decoded = new types_js_1.Contract((0, utils_js_1.decodeStream)(account.account.data));
|
|
975
|
-
streams = __assign(__assign({}, streams), (_a = {}, _a[account.pubkey.toBase58()] = decoded, _a));
|
|
976
|
-
});
|
|
977
|
-
sortedStreams = Object.entries(streams).sort(function (_a, _b) {
|
|
978
|
-
var _c = __read(_a, 2), stream1 = _c[1];
|
|
979
|
-
var _d = __read(_b, 2), stream2 = _d[1];
|
|
980
|
-
return stream2.start - stream1.start;
|
|
981
|
-
});
|
|
982
|
-
if (type === "all")
|
|
983
|
-
return [2 /*return*/, sortedStreams];
|
|
984
|
-
return [2 /*return*/, sortedStreams.filter(function (stream) { return stream[1].type === type; })];
|
|
985
|
-
}
|
|
986
|
-
});
|
|
542
|
+
async get({ address, type = types_js_2.StreamType.All, direction = types_js_2.StreamDirection.All, }) {
|
|
543
|
+
const publicKey = new web3_js_1.PublicKey(address);
|
|
544
|
+
let accounts = [];
|
|
545
|
+
//todo: we need to be smart with our layout so we minimize rpc calls to the chain
|
|
546
|
+
if (direction === "all") {
|
|
547
|
+
const outgoingAccounts = await (0, solana_1.getProgramAccounts)(this.connection, publicKey, constants_js_1.STREAM_STRUCT_OFFSET_SENDER, this.programId);
|
|
548
|
+
const incomingAccounts = await (0, solana_1.getProgramAccounts)(this.connection, publicKey, constants_js_1.STREAM_STRUCT_OFFSET_RECIPIENT, this.programId);
|
|
549
|
+
accounts = [...outgoingAccounts, ...incomingAccounts];
|
|
550
|
+
}
|
|
551
|
+
else {
|
|
552
|
+
const offset = direction === "outgoing" ? constants_js_1.STREAM_STRUCT_OFFSET_SENDER : constants_js_1.STREAM_STRUCT_OFFSET_RECIPIENT;
|
|
553
|
+
accounts = await (0, solana_1.getProgramAccounts)(this.connection, publicKey, offset, this.programId);
|
|
554
|
+
}
|
|
555
|
+
let streams = {};
|
|
556
|
+
accounts.forEach((account) => {
|
|
557
|
+
const decoded = new types_js_1.Contract((0, utils_js_1.decodeStream)(account.account.data));
|
|
558
|
+
streams = { ...streams, [account.pubkey.toBase58()]: decoded };
|
|
987
559
|
});
|
|
988
|
-
|
|
560
|
+
const sortedStreams = Object.entries(streams).sort(([, stream1], [, stream2]) => stream2.start - stream1.start);
|
|
561
|
+
if (type === "all")
|
|
562
|
+
return sortedStreams;
|
|
563
|
+
return sortedStreams.filter((stream) => stream[1].type === type);
|
|
564
|
+
}
|
|
565
|
+
async searchStreams(data) {
|
|
566
|
+
const filters = Object.entries(data)
|
|
567
|
+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
568
|
+
.filter(([_, value]) => value) // Only keep entries where the value is truthy
|
|
569
|
+
.map(([key, value]) => ({
|
|
570
|
+
memcmp: {
|
|
571
|
+
offset: constants_js_1.STREAM_STRUCT_OFFSETS[key],
|
|
572
|
+
bytes: value,
|
|
573
|
+
},
|
|
574
|
+
}));
|
|
575
|
+
const accounts = await this.connection.getProgramAccounts(this.programId, { filters });
|
|
576
|
+
return accounts.map(({ pubkey, account }) => ({
|
|
577
|
+
publicKey: pubkey,
|
|
578
|
+
account: new types_js_1.Contract((0, utils_js_1.decodeStream)(account.data)),
|
|
579
|
+
}));
|
|
580
|
+
}
|
|
989
581
|
/**
|
|
990
582
|
* Attempts updating the stream auto withdrawal params and amount per period
|
|
991
583
|
*/
|
|
992
|
-
|
|
993
|
-
|
|
994
|
-
|
|
995
|
-
|
|
996
|
-
|
|
997
|
-
|
|
998
|
-
|
|
999
|
-
|
|
1000
|
-
|
|
1001
|
-
|
|
1002
|
-
|
|
1003
|
-
|
|
1004
|
-
|
|
1005
|
-
context: context,
|
|
1006
|
-
commitment: this.getCommitment(),
|
|
1007
|
-
}, { sendThrottler: this.sendThrottler })];
|
|
1008
|
-
case 3:
|
|
1009
|
-
signature = _b.sent();
|
|
1010
|
-
return [2 /*return*/, {
|
|
1011
|
-
ixs: ixs,
|
|
1012
|
-
txId: signature,
|
|
1013
|
-
}];
|
|
1014
|
-
}
|
|
1015
|
-
});
|
|
1016
|
-
});
|
|
1017
|
-
};
|
|
584
|
+
async update(data, extParams) {
|
|
585
|
+
const ixs = await this.prepareUpdateInstructions(data, extParams);
|
|
586
|
+
const { tx, hash, context } = await (0, solana_1.prepareTransaction)(this.connection, ixs, extParams.invoker.publicKey);
|
|
587
|
+
const signature = await (0, solana_1.signAndExecuteTransaction)(this.connection, extParams.invoker, tx, {
|
|
588
|
+
hash,
|
|
589
|
+
context,
|
|
590
|
+
commitment: this.getCommitment(),
|
|
591
|
+
}, { sendThrottler: this.sendThrottler });
|
|
592
|
+
return {
|
|
593
|
+
ixs,
|
|
594
|
+
txId: signature,
|
|
595
|
+
};
|
|
596
|
+
}
|
|
1018
597
|
/**
|
|
1019
598
|
* Create Transaction instructions for update
|
|
1020
599
|
*/
|
|
1021
|
-
|
|
1022
|
-
|
|
1023
|
-
|
|
1024
|
-
|
|
1025
|
-
|
|
1026
|
-
|
|
1027
|
-
|
|
1028
|
-
|
|
1029
|
-
|
|
1030
|
-
|
|
1031
|
-
|
|
1032
|
-
|
|
1033
|
-
case 1:
|
|
1034
|
-
escrow = _b.sent();
|
|
1035
|
-
if (!escrow) {
|
|
1036
|
-
throw new Error("Couldn't get account info");
|
|
1037
|
-
}
|
|
1038
|
-
ixs = (0, solana_1.prepareBaseInstructions)(this.connection, {
|
|
1039
|
-
computePrice: computePrice,
|
|
1040
|
-
computeLimit: computeLimit,
|
|
1041
|
-
});
|
|
1042
|
-
ixs.push((0, instructions_js_1.updateStreamInstruction)(data, this.programId, {
|
|
1043
|
-
authority: invoker.publicKey,
|
|
1044
|
-
metadata: streamPublicKey,
|
|
1045
|
-
withdrawor: constants_js_1.WITHDRAWOR_PUBLIC_KEY,
|
|
1046
|
-
systemProgram: web3_js_1.SystemProgram.programId,
|
|
1047
|
-
}));
|
|
1048
|
-
return [2 /*return*/, ixs];
|
|
1049
|
-
}
|
|
1050
|
-
});
|
|
1051
|
-
});
|
|
1052
|
-
};
|
|
1053
|
-
SolanaStreamClient.prototype.getFees = function (_a) {
|
|
1054
|
-
var address = _a.address;
|
|
1055
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
1056
|
-
var _b, metadataPubKey, data, partners, filteredPartners;
|
|
1057
|
-
return __generator(this, function (_c) {
|
|
1058
|
-
switch (_c.label) {
|
|
1059
|
-
case 0:
|
|
1060
|
-
_b = __read(web3_js_1.PublicKey.findProgramAddressSync([buffer_1.Buffer.from(constants_js_1.FEES_METADATA_SEED)], new web3_js_1.PublicKey(constants_js_1.PARTNER_ORACLE_PROGRAM_ID)), 1), metadataPubKey = _b[0];
|
|
1061
|
-
return [4 /*yield*/, this.connection.getAccountInfo(metadataPubKey)];
|
|
1062
|
-
case 1:
|
|
1063
|
-
data = _c.sent();
|
|
1064
|
-
if (!data) {
|
|
1065
|
-
return [2 /*return*/, null];
|
|
1066
|
-
}
|
|
1067
|
-
partners = borsh.deserialize(constants_js_1.PARTNERS_SCHEMA, data.data);
|
|
1068
|
-
filteredPartners = partners.filter(function (item) { return new web3_js_1.PublicKey(item.pubkey).toString() === address; });
|
|
1069
|
-
if (filteredPartners.length === 0) {
|
|
1070
|
-
return [2 /*return*/, null];
|
|
1071
|
-
}
|
|
1072
|
-
return [2 /*return*/, {
|
|
1073
|
-
streamflowFee: Number(filteredPartners[0].strm_fee.toFixed(4)),
|
|
1074
|
-
partnerFee: Number(filteredPartners[0].partner_fee.toFixed(4)),
|
|
1075
|
-
}];
|
|
1076
|
-
}
|
|
1077
|
-
});
|
|
1078
|
-
});
|
|
1079
|
-
};
|
|
1080
|
-
SolanaStreamClient.prototype.getDefaultStreamflowFee = function () {
|
|
1081
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
1082
|
-
return __generator(this, function (_a) {
|
|
1083
|
-
return [2 /*return*/, constants_js_1.DEFAULT_STREAMFLOW_FEE];
|
|
1084
|
-
});
|
|
600
|
+
async prepareUpdateInstructions(data, { invoker, computePrice, computeLimit }) {
|
|
601
|
+
if (!invoker.publicKey) {
|
|
602
|
+
throw new Error("Invoker's PublicKey is not available, check passed wallet adapter!");
|
|
603
|
+
}
|
|
604
|
+
const streamPublicKey = new web3_js_1.PublicKey(data.id);
|
|
605
|
+
const escrow = await this.connection.getAccountInfo(streamPublicKey);
|
|
606
|
+
if (!escrow) {
|
|
607
|
+
throw new Error("Couldn't get account info");
|
|
608
|
+
}
|
|
609
|
+
const ixs = (0, solana_1.prepareBaseInstructions)(this.connection, {
|
|
610
|
+
computePrice,
|
|
611
|
+
computeLimit,
|
|
1085
612
|
});
|
|
1086
|
-
|
|
1087
|
-
|
|
1088
|
-
|
|
1089
|
-
|
|
1090
|
-
|
|
1091
|
-
|
|
613
|
+
ixs.push((0, instructions_js_1.updateStreamInstruction)(data, this.programId, {
|
|
614
|
+
authority: invoker.publicKey,
|
|
615
|
+
metadata: streamPublicKey,
|
|
616
|
+
withdrawor: constants_js_1.WITHDRAWOR_PUBLIC_KEY,
|
|
617
|
+
systemProgram: web3_js_1.SystemProgram.programId,
|
|
618
|
+
}));
|
|
619
|
+
return ixs;
|
|
620
|
+
}
|
|
621
|
+
async getFees({ address }) {
|
|
622
|
+
const [metadataPubKey] = web3_js_1.PublicKey.findProgramAddressSync([buffer_1.Buffer.from(constants_js_1.FEES_METADATA_SEED)], new web3_js_1.PublicKey(constants_js_1.PARTNER_ORACLE_PROGRAM_ID));
|
|
623
|
+
const data = await this.connection.getAccountInfo(metadataPubKey);
|
|
624
|
+
if (!data) {
|
|
625
|
+
return null;
|
|
626
|
+
}
|
|
627
|
+
const partners = borsh.deserialize(constants_js_1.PARTNERS_SCHEMA, data.data);
|
|
628
|
+
const filteredPartners = partners.filter((item) => new web3_js_1.PublicKey(item.pubkey).toString() === address);
|
|
629
|
+
if (filteredPartners.length === 0) {
|
|
630
|
+
return null;
|
|
631
|
+
}
|
|
632
|
+
return {
|
|
633
|
+
streamflowFee: Number(filteredPartners[0].strm_fee.toFixed(4)),
|
|
634
|
+
partnerFee: Number(filteredPartners[0].partner_fee.toFixed(4)),
|
|
635
|
+
};
|
|
636
|
+
}
|
|
637
|
+
async getDefaultStreamflowFee() {
|
|
638
|
+
return constants_js_1.DEFAULT_STREAMFLOW_FEE;
|
|
639
|
+
}
|
|
640
|
+
extractErrorCode(err) {
|
|
641
|
+
const logs = "logs" in err && Array.isArray(err.logs) ? err.logs : undefined;
|
|
642
|
+
return (0, utils_js_1.extractSolanaErrorCode)(err.toString() ?? "Unknown error!", logs);
|
|
643
|
+
}
|
|
1092
644
|
/**
|
|
1093
645
|
* Forms instructions from params, creates a raw transaction and fetch recent blockhash.
|
|
1094
646
|
*/
|
|
1095
|
-
|
|
1096
|
-
|
|
1097
|
-
|
|
1098
|
-
|
|
1099
|
-
|
|
1100
|
-
|
|
1101
|
-
|
|
1102
|
-
|
|
1103
|
-
|
|
1104
|
-
throw new Error("Sender's PublicKey is not available, check passed wallet adapter!");
|
|
1105
|
-
}
|
|
1106
|
-
ixs = (0, solana_1.prepareBaseInstructions)(this.connection, {
|
|
1107
|
-
computePrice: computePrice,
|
|
1108
|
-
computeLimit: computeLimit,
|
|
1109
|
-
});
|
|
1110
|
-
recipientPublicKey = new web3_js_1.PublicKey(recipient.recipient);
|
|
1111
|
-
mintPublicKey = new web3_js_1.PublicKey(mint);
|
|
1112
|
-
_c = this.getOrCreateStreamMetadata(metadataPubKeys), metadata = _c.metadata, metadataPubKey = _c.metadataPubKey;
|
|
1113
|
-
_d = __read(web3_js_1.PublicKey.findProgramAddressSync([buffer_1.Buffer.from("strm"), metadataPubKey.toBuffer()], this.programId), 1), escrowTokens = _d[0];
|
|
1114
|
-
return [4 /*yield*/, (0, solana_1.getMintAndProgram)(this.connection, mintPublicKey)];
|
|
1115
|
-
case 1:
|
|
1116
|
-
tokenProgramId = (_e.sent()).tokenProgramId;
|
|
1117
|
-
return [4 /*yield*/, (0, solana_1.ata)(mintPublicKey, sender.publicKey, tokenProgramId)];
|
|
1118
|
-
case 2:
|
|
1119
|
-
senderTokens = _e.sent();
|
|
1120
|
-
return [4 /*yield*/, (0, solana_1.ata)(mintPublicKey, recipientPublicKey, tokenProgramId)];
|
|
1121
|
-
case 3:
|
|
1122
|
-
recipientTokens = _e.sent();
|
|
1123
|
-
return [4 /*yield*/, (0, solana_1.ata)(mintPublicKey, constants_js_1.STREAMFLOW_TREASURY_PUBLIC_KEY, tokenProgramId)];
|
|
1124
|
-
case 4:
|
|
1125
|
-
streamflowTreasuryTokens = _e.sent();
|
|
1126
|
-
partnerPublicKey = partner ? new web3_js_1.PublicKey(partner) : constants_js_1.WITHDRAWOR_PUBLIC_KEY;
|
|
1127
|
-
return [4 /*yield*/, (0, solana_1.ata)(mintPublicKey, partnerPublicKey, tokenProgramId)];
|
|
1128
|
-
case 5:
|
|
1129
|
-
partnerTokens = _e.sent();
|
|
1130
|
-
ixs.push((0, instructions_js_1.createStreamInstruction)({
|
|
1131
|
-
start: new bn_js_1.default(start),
|
|
1132
|
-
depositedAmount: recipient.amount,
|
|
1133
|
-
period: new bn_js_1.default(period),
|
|
1134
|
-
amountPerPeriod: recipient.amountPerPeriod,
|
|
1135
|
-
cliff: new bn_js_1.default(cliff),
|
|
1136
|
-
cliffAmount: recipient.cliffAmount,
|
|
1137
|
-
cancelableBySender: cancelableBySender,
|
|
1138
|
-
cancelableByRecipient: cancelableByRecipient,
|
|
1139
|
-
automaticWithdrawal: automaticWithdrawal,
|
|
1140
|
-
transferableBySender: transferableBySender,
|
|
1141
|
-
transferableByRecipient: transferableByRecipient,
|
|
1142
|
-
canTopup: canTopup,
|
|
1143
|
-
canUpdateRate: !!canUpdateRate,
|
|
1144
|
-
canPause: !!canPause,
|
|
1145
|
-
name: recipient.name,
|
|
1146
|
-
withdrawFrequency: new bn_js_1.default(automaticWithdrawal ? withdrawalFrequency : period),
|
|
1147
|
-
}, this.programId, {
|
|
1148
|
-
sender: sender.publicKey,
|
|
1149
|
-
senderTokens: senderTokens,
|
|
1150
|
-
recipient: new web3_js_1.PublicKey(recipient.recipient),
|
|
1151
|
-
metadata: metadataPubKey,
|
|
1152
|
-
escrowTokens: escrowTokens,
|
|
1153
|
-
recipientTokens: recipientTokens,
|
|
1154
|
-
streamflowTreasury: constants_js_1.STREAMFLOW_TREASURY_PUBLIC_KEY,
|
|
1155
|
-
streamflowTreasuryTokens: streamflowTreasuryTokens,
|
|
1156
|
-
partner: partnerPublicKey,
|
|
1157
|
-
partnerTokens: partnerTokens,
|
|
1158
|
-
mint: new web3_js_1.PublicKey(mint),
|
|
1159
|
-
feeOracle: constants_js_1.FEE_ORACLE_PUBLIC_KEY,
|
|
1160
|
-
rent: web3_js_1.SYSVAR_RENT_PUBKEY,
|
|
1161
|
-
timelockProgram: this.programId,
|
|
1162
|
-
tokenProgram: tokenProgramId,
|
|
1163
|
-
associatedTokenProgram: spl_token_1.ASSOCIATED_TOKEN_PROGRAM_ID,
|
|
1164
|
-
withdrawor: constants_js_1.WITHDRAWOR_PUBLIC_KEY,
|
|
1165
|
-
systemProgram: web3_js_1.SystemProgram.programId,
|
|
1166
|
-
}));
|
|
1167
|
-
return [2 /*return*/, { ixs: ixs, metadata: metadata, metadataPubKey: metadataPubKey }];
|
|
1168
|
-
}
|
|
1169
|
-
});
|
|
647
|
+
async prepareStreamInstructions(recipient, streamParams, extParams) {
|
|
648
|
+
const { tokenId: mint, start, period, cliff, canTopup, canUpdateRate, canPause, cancelableBySender, cancelableByRecipient, transferableBySender, transferableByRecipient, automaticWithdrawal = false, withdrawalFrequency = 0, partner, } = streamParams;
|
|
649
|
+
const { sender, metadataPubKeys, computeLimit, computePrice } = extParams;
|
|
650
|
+
if (!sender.publicKey) {
|
|
651
|
+
throw new Error("Sender's PublicKey is not available, check passed wallet adapter!");
|
|
652
|
+
}
|
|
653
|
+
const ixs = (0, solana_1.prepareBaseInstructions)(this.connection, {
|
|
654
|
+
computePrice,
|
|
655
|
+
computeLimit,
|
|
1170
656
|
});
|
|
1171
|
-
|
|
657
|
+
const recipientPublicKey = new web3_js_1.PublicKey(recipient.recipient);
|
|
658
|
+
const mintPublicKey = new web3_js_1.PublicKey(mint);
|
|
659
|
+
const { metadata, metadataPubKey } = this.getOrCreateStreamMetadata(metadataPubKeys);
|
|
660
|
+
const [escrowTokens] = web3_js_1.PublicKey.findProgramAddressSync([buffer_1.Buffer.from("strm"), metadataPubKey.toBuffer()], this.programId);
|
|
661
|
+
const { tokenProgramId } = await (0, solana_1.getMintAndProgram)(this.connection, mintPublicKey);
|
|
662
|
+
const senderTokens = await (0, solana_1.ata)(mintPublicKey, sender.publicKey, tokenProgramId);
|
|
663
|
+
const recipientTokens = await (0, solana_1.ata)(mintPublicKey, recipientPublicKey, tokenProgramId);
|
|
664
|
+
const streamflowTreasuryTokens = await (0, solana_1.ata)(mintPublicKey, constants_js_1.STREAMFLOW_TREASURY_PUBLIC_KEY, tokenProgramId);
|
|
665
|
+
const partnerPublicKey = partner ? new web3_js_1.PublicKey(partner) : constants_js_1.WITHDRAWOR_PUBLIC_KEY;
|
|
666
|
+
const partnerTokens = await (0, solana_1.ata)(mintPublicKey, partnerPublicKey, tokenProgramId);
|
|
667
|
+
ixs.push((0, instructions_js_1.createStreamInstruction)({
|
|
668
|
+
start: (0, bignumber_js_1.default)(start),
|
|
669
|
+
depositedAmount: recipient.amount,
|
|
670
|
+
period: (0, bignumber_js_1.default)(period),
|
|
671
|
+
amountPerPeriod: recipient.amountPerPeriod,
|
|
672
|
+
cliff: (0, bignumber_js_1.default)(cliff),
|
|
673
|
+
cliffAmount: (0, bignumber_js_1.default)(recipient.cliffAmount),
|
|
674
|
+
cancelableBySender,
|
|
675
|
+
cancelableByRecipient,
|
|
676
|
+
automaticWithdrawal,
|
|
677
|
+
transferableBySender,
|
|
678
|
+
transferableByRecipient,
|
|
679
|
+
canTopup,
|
|
680
|
+
canUpdateRate: !!canUpdateRate,
|
|
681
|
+
canPause: !!canPause,
|
|
682
|
+
name: recipient.name,
|
|
683
|
+
withdrawFrequency: (0, bignumber_js_1.default)(automaticWithdrawal ? withdrawalFrequency : period),
|
|
684
|
+
}, this.programId, {
|
|
685
|
+
sender: sender.publicKey,
|
|
686
|
+
senderTokens,
|
|
687
|
+
recipient: new web3_js_1.PublicKey(recipient.recipient),
|
|
688
|
+
metadata: metadataPubKey,
|
|
689
|
+
escrowTokens,
|
|
690
|
+
recipientTokens,
|
|
691
|
+
streamflowTreasury: constants_js_1.STREAMFLOW_TREASURY_PUBLIC_KEY,
|
|
692
|
+
streamflowTreasuryTokens: streamflowTreasuryTokens,
|
|
693
|
+
partner: partnerPublicKey,
|
|
694
|
+
partnerTokens: partnerTokens,
|
|
695
|
+
mint: new web3_js_1.PublicKey(mint),
|
|
696
|
+
feeOracle: constants_js_1.FEE_ORACLE_PUBLIC_KEY,
|
|
697
|
+
rent: web3_js_1.SYSVAR_RENT_PUBKEY,
|
|
698
|
+
timelockProgram: this.programId,
|
|
699
|
+
tokenProgram: tokenProgramId,
|
|
700
|
+
associatedTokenProgram: spl_token_1.ASSOCIATED_TOKEN_PROGRAM_ID,
|
|
701
|
+
withdrawor: constants_js_1.WITHDRAWOR_PUBLIC_KEY,
|
|
702
|
+
systemProgram: web3_js_1.SystemProgram.programId,
|
|
703
|
+
}));
|
|
704
|
+
return { ixs, metadata, metadataPubKey };
|
|
705
|
+
}
|
|
1172
706
|
/**
|
|
1173
707
|
* Utility function to generate metadata for a Contract or return existing Pubkey
|
|
1174
708
|
*/
|
|
1175
|
-
|
|
1176
|
-
|
|
1177
|
-
|
|
709
|
+
getOrCreateStreamMetadata(metadataPubKeys) {
|
|
710
|
+
let metadata;
|
|
711
|
+
let metadataPubKey;
|
|
1178
712
|
if (!metadataPubKeys) {
|
|
1179
713
|
metadata = web3_js_1.Keypair.generate();
|
|
1180
714
|
metadataPubKey = metadata.publicKey;
|
|
@@ -1182,38 +716,22 @@ var SolanaStreamClient = /** @class */ (function (_super) {
|
|
|
1182
716
|
else {
|
|
1183
717
|
metadataPubKey = metadataPubKeys[0];
|
|
1184
718
|
}
|
|
1185
|
-
return { metadata
|
|
1186
|
-
}
|
|
719
|
+
return { metadata, metadataPubKey };
|
|
720
|
+
}
|
|
1187
721
|
/**
|
|
1188
722
|
* Utility function that checks whether associated token accounts still exist and adds instructions to add them if not
|
|
1189
723
|
*/
|
|
1190
|
-
|
|
1191
|
-
|
|
1192
|
-
|
|
1193
|
-
|
|
1194
|
-
|
|
1195
|
-
|
|
1196
|
-
|
|
1197
|
-
|
|
1198
|
-
|
|
1199
|
-
|
|
1200
|
-
|
|
1201
|
-
|
|
1202
|
-
|
|
1203
|
-
data.partner.toBase58(),
|
|
1204
|
-
data.streamflowTreasury.toBase58(),
|
|
1205
|
-
]), function (address) { return new web3_js_1.PublicKey(address); });
|
|
1206
|
-
_c = (_b = ixs.push).apply;
|
|
1207
|
-
_d = [ixs];
|
|
1208
|
-
_e = [[]];
|
|
1209
|
-
return [4 /*yield*/, (0, solana_1.checkOrCreateAtaBatch)(this.connection, owners, data.mint, invoker, programId)];
|
|
1210
|
-
case 1:
|
|
1211
|
-
_c.apply(_b, _d.concat([__spreadArray.apply(void 0, _e.concat([__read.apply(void 0, [(_f.sent())]), false]))]));
|
|
1212
|
-
return [2 /*return*/];
|
|
1213
|
-
}
|
|
1214
|
-
});
|
|
1215
|
-
});
|
|
1216
|
-
};
|
|
1217
|
-
return SolanaStreamClient;
|
|
1218
|
-
}(BaseStreamClient_js_1.BaseStreamClient));
|
|
724
|
+
async checkAssociatedTokenAccounts(data, { invoker, checkTokenAccounts }, ixs, programId) {
|
|
725
|
+
if (!checkTokenAccounts) {
|
|
726
|
+
return;
|
|
727
|
+
}
|
|
728
|
+
const owners = Array.from(new Set([
|
|
729
|
+
data.sender.toBase58(),
|
|
730
|
+
data.recipient.toBase58(),
|
|
731
|
+
data.partner.toBase58(),
|
|
732
|
+
data.streamflowTreasury.toBase58(),
|
|
733
|
+
]), (address) => new web3_js_1.PublicKey(address));
|
|
734
|
+
ixs.push(...(await (0, solana_1.checkOrCreateAtaBatch)(this.connection, owners, data.mint, invoker, programId)));
|
|
735
|
+
}
|
|
736
|
+
}
|
|
1219
737
|
exports.SolanaStreamClient = SolanaStreamClient;
|