@streamflow/stream 5.10.0 → 5.10.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/common/BaseStreamClient.d.ts +9 -2
- package/dist/common/BaseStreamClient.js +58 -0
- package/dist/common/utils.d.ts +10 -0
- package/dist/common/utils.js +18 -1
- package/dist/solana/StreamClient.d.ts +1 -1
- package/dist/solana/StreamClient.js +89 -76
- package/dist/solana/instructions.js +1 -6
- package/dist/sui/StreamClient.js +50 -41
- package/package.json +2 -2
|
@@ -9,7 +9,14 @@ export declare abstract class BaseStreamClient {
|
|
|
9
9
|
abstract getOne(getOneData: IGetOneData, chainSpecificParams: any): Promise<Stream>;
|
|
10
10
|
abstract get(getAllData: IGetAllData, chainSpecificParams: any): Promise<[string, Stream][]>;
|
|
11
11
|
abstract update(updateData: IUpdateData, chainSpecificParams: any): Promise<ITransactionResult>;
|
|
12
|
-
abstract getFees(getFeesData: IGetFeesData, chainSpecificParams
|
|
13
|
-
abstract getDefaultStreamflowFee(chainSpecificParams
|
|
12
|
+
abstract getFees(getFeesData: IGetFeesData, chainSpecificParams?: any): Promise<IFees | null>;
|
|
13
|
+
abstract getDefaultStreamflowFee(chainSpecificParams?: any): Promise<number>;
|
|
14
|
+
/**
|
|
15
|
+
* Returns total fee percent, streamflow fees + partner fees
|
|
16
|
+
* @param getFeesData structure with address for which we need to derive fee, either sender or partner usually
|
|
17
|
+
* @param chainSpecificParams additional parameters required by chain client
|
|
18
|
+
* @returns fee as floating number, so if fee is 0.99%, it will return 0.99
|
|
19
|
+
*/
|
|
20
|
+
getTotalFee(getFeesData: IGetFeesData, chainSpecificParams?: any): Promise<number>;
|
|
14
21
|
extractErrorCode(err: Error): string | null;
|
|
15
22
|
}
|
|
@@ -1,9 +1,67 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
12
|
+
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
|
|
13
|
+
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
|
14
|
+
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
15
|
+
function step(op) {
|
|
16
|
+
if (f) throw new TypeError("Generator is already executing.");
|
|
17
|
+
while (_) try {
|
|
18
|
+
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;
|
|
19
|
+
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
20
|
+
switch (op[0]) {
|
|
21
|
+
case 0: case 1: t = op; break;
|
|
22
|
+
case 4: _.label++; return { value: op[1], done: false };
|
|
23
|
+
case 5: _.label++; y = op[1]; op = [0]; continue;
|
|
24
|
+
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
|
25
|
+
default:
|
|
26
|
+
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
|
27
|
+
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
|
28
|
+
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
|
29
|
+
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
|
30
|
+
if (t[2]) _.ops.pop();
|
|
31
|
+
_.trys.pop(); continue;
|
|
32
|
+
}
|
|
33
|
+
op = body.call(thisArg, _);
|
|
34
|
+
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
|
35
|
+
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
36
|
+
}
|
|
37
|
+
};
|
|
2
38
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
39
|
exports.BaseStreamClient = void 0;
|
|
4
40
|
var BaseStreamClient = /** @class */ (function () {
|
|
5
41
|
function BaseStreamClient() {
|
|
6
42
|
}
|
|
43
|
+
/**
|
|
44
|
+
* Returns total fee percent, streamflow fees + partner fees
|
|
45
|
+
* @param getFeesData structure with address for which we need to derive fee, either sender or partner usually
|
|
46
|
+
* @param chainSpecificParams additional parameters required by chain client
|
|
47
|
+
* @returns fee as floating number, so if fee is 0.99%, it will return 0.99
|
|
48
|
+
*/
|
|
49
|
+
BaseStreamClient.prototype.getTotalFee = function (getFeesData, chainSpecificParams) {
|
|
50
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
51
|
+
var fees;
|
|
52
|
+
return __generator(this, function (_a) {
|
|
53
|
+
switch (_a.label) {
|
|
54
|
+
case 0: return [4 /*yield*/, this.getFees(getFeesData, chainSpecificParams)];
|
|
55
|
+
case 1:
|
|
56
|
+
fees = _a.sent();
|
|
57
|
+
if (fees) {
|
|
58
|
+
return [2 /*return*/, fees.partnerFee + fees.streamflowFee];
|
|
59
|
+
}
|
|
60
|
+
return [2 /*return*/, this.getDefaultStreamflowFee(chainSpecificParams)];
|
|
61
|
+
}
|
|
62
|
+
});
|
|
63
|
+
});
|
|
64
|
+
};
|
|
7
65
|
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
8
66
|
BaseStreamClient.prototype.extractErrorCode = function (err) {
|
|
9
67
|
return null;
|
package/dist/common/utils.d.ts
CHANGED
|
@@ -13,6 +13,16 @@ export declare const getBN: (value: number, decimals: number) => BN;
|
|
|
13
13
|
* @param {number} decimals - Number of decimals the token has.
|
|
14
14
|
*/
|
|
15
15
|
export declare const getNumberFromBN: (value: BN, decimals: number) => number;
|
|
16
|
+
/**
|
|
17
|
+
* Calculate total amount of a Contract including all fees.
|
|
18
|
+
* - first we convert fee floating to a BN with up to 4 decimals precision
|
|
19
|
+
* - then we reverse the fee with `FEE_MULTIPLIER` to safely multiply it by depositedAmount
|
|
20
|
+
* to receive a total number and not percentage of depositedAmount
|
|
21
|
+
* @param depositedAmount deposited raw tokens
|
|
22
|
+
* @param totalFee sum of all fees in percentage as floating number, e.g. 0.99% should be supplied as 0.99
|
|
23
|
+
* @returns total tokens amount that Contract will retrieve from the Sender
|
|
24
|
+
*/
|
|
25
|
+
export declare const calculateTotalAmountToDeposit: (depositedAmount: BN, totalFee: number) => BN;
|
|
16
26
|
/**
|
|
17
27
|
* Used to make on chain calls to the contract and wrap raised errors if any
|
|
18
28
|
* @param func function that interacts with the contract
|
package/dist/common/utils.js
CHANGED
|
@@ -39,9 +39,12 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
39
39
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
40
40
|
};
|
|
41
41
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
42
|
-
exports.normalizeAptosAddress = exports.handleContractError = exports.getNumberFromBN = exports.getBN = void 0;
|
|
42
|
+
exports.normalizeAptosAddress = exports.handleContractError = exports.calculateTotalAmountToDeposit = exports.getNumberFromBN = exports.getBN = void 0;
|
|
43
43
|
var bn_js_1 = __importDefault(require("bn.js"));
|
|
44
44
|
var types_1 = require("./types");
|
|
45
|
+
var FEE_PRECISION = 4;
|
|
46
|
+
var FEE_NORMALIZER = Math.pow(10, FEE_PRECISION);
|
|
47
|
+
var FEE_MULTIPLIER = new bn_js_1.default(Math.pow(10, 6));
|
|
45
48
|
/**
|
|
46
49
|
* Used for conversion of token amounts to their Big Number representation.
|
|
47
50
|
* Get Big Number representation in the smallest units from the same value in the highest units.
|
|
@@ -69,6 +72,20 @@ var getNumberFromBN = function (value, decimals) {
|
|
|
69
72
|
: value.toNumber() / Math.pow(10, decimals);
|
|
70
73
|
};
|
|
71
74
|
exports.getNumberFromBN = getNumberFromBN;
|
|
75
|
+
/**
|
|
76
|
+
* Calculate total amount of a Contract including all fees.
|
|
77
|
+
* - first we convert fee floating to a BN with up to 4 decimals precision
|
|
78
|
+
* - then we reverse the fee with `FEE_MULTIPLIER` to safely multiply it by depositedAmount
|
|
79
|
+
* to receive a total number and not percentage of depositedAmount
|
|
80
|
+
* @param depositedAmount deposited raw tokens
|
|
81
|
+
* @param totalFee sum of all fees in percentage as floating number, e.g. 0.99% should be supplied as 0.99
|
|
82
|
+
* @returns total tokens amount that Contract will retrieve from the Sender
|
|
83
|
+
*/
|
|
84
|
+
var calculateTotalAmountToDeposit = function (depositedAmount, totalFee) {
|
|
85
|
+
var totalFeeNormalized = new bn_js_1.default(totalFee * FEE_NORMALIZER);
|
|
86
|
+
return depositedAmount.mul(totalFeeNormalized.add(FEE_MULTIPLIER)).div(FEE_MULTIPLIER);
|
|
87
|
+
};
|
|
88
|
+
exports.calculateTotalAmountToDeposit = calculateTotalAmountToDeposit;
|
|
72
89
|
/**
|
|
73
90
|
* Used to make on chain calls to the contract and wrap raised errors if any
|
|
74
91
|
* @param func function that interacts with the contract
|
|
@@ -69,7 +69,7 @@ export default class SolanaStreamClient extends BaseStreamClient {
|
|
|
69
69
|
/**
|
|
70
70
|
* Forms instructions from params, creates a raw transaction and fetch recent blockhash.
|
|
71
71
|
*/
|
|
72
|
-
private
|
|
72
|
+
private prepareStreamInstructions;
|
|
73
73
|
/**
|
|
74
74
|
* Utility function that checks whether associated token accounts still exist and adds instructions to add them if not
|
|
75
75
|
*/
|
|
@@ -137,6 +137,7 @@ var constants_1 = require("./constants");
|
|
|
137
137
|
var instructions_1 = require("./instructions");
|
|
138
138
|
var types_2 = require("../common/types");
|
|
139
139
|
var BaseStreamClient_1 = require("../common/BaseStreamClient");
|
|
140
|
+
var utils_2 = require("../common/utils");
|
|
140
141
|
var METADATA_ACC_SIZE = 1104;
|
|
141
142
|
var SolanaStreamClient = /** @class */ (function (_super) {
|
|
142
143
|
__extends(SolanaStreamClient, _super);
|
|
@@ -168,10 +169,10 @@ var SolanaStreamClient = /** @class */ (function (_super) {
|
|
|
168
169
|
var recipient = _a.recipient, mint = _a.tokenId, start = _a.start, depositedAmount = _a.amount, period = _a.period, cliff = _a.cliff, cliffAmount = _a.cliffAmount, amountPerPeriod = _a.amountPerPeriod, name = _a.name, canTopup = _a.canTopup, cancelableBySender = _a.cancelableBySender, cancelableByRecipient = _a.cancelableByRecipient, transferableBySender = _a.transferableBySender, transferableByRecipient = _a.transferableByRecipient, _c = _a.automaticWithdrawal, automaticWithdrawal = _c === void 0 ? false : _c, _d = _a.withdrawalFrequency, withdrawalFrequency = _d === void 0 ? 0 : _d, partner = _a.partner;
|
|
169
170
|
var sender = _b.sender, metadataPubKeys = _b.metadataPubKeys, _e = _b.isNative, isNative = _e === void 0 ? false : _e;
|
|
170
171
|
return __awaiter(this, void 0, void 0, function () {
|
|
171
|
-
var ixs, mintPublicKey, recipientPublicKey, _f, metadata, metadataPubKey, _g, escrowTokens, senderTokens, recipientTokens, streamflowTreasuryTokens, partnerPublicKey, partnerTokens,
|
|
172
|
-
var
|
|
173
|
-
return __generator(this, function (
|
|
174
|
-
switch (
|
|
172
|
+
var ixs, mintPublicKey, recipientPublicKey, _f, metadata, metadataPubKey, _g, escrowTokens, senderTokens, recipientTokens, streamflowTreasuryTokens, partnerPublicKey, partnerTokens, totalFee, totalAmount, _h, _j, _k, _l, commitment, hash, tx, signature;
|
|
173
|
+
var _m;
|
|
174
|
+
return __generator(this, function (_o) {
|
|
175
|
+
switch (_o.label) {
|
|
175
176
|
case 0:
|
|
176
177
|
if (!sender.publicKey) {
|
|
177
178
|
throw new Error("Sender's PublicKey is not available, check passed wallet adapter!");
|
|
@@ -183,27 +184,30 @@ var SolanaStreamClient = /** @class */ (function (_super) {
|
|
|
183
184
|
_g = __read(web3_js_1.PublicKey.findProgramAddressSync([buffer_1.Buffer.from("strm"), metadataPubKey.toBuffer()], this.programId), 1), escrowTokens = _g[0];
|
|
184
185
|
return [4 /*yield*/, (0, utils_1.ata)(mintPublicKey, sender.publicKey)];
|
|
185
186
|
case 1:
|
|
186
|
-
senderTokens =
|
|
187
|
+
senderTokens = _o.sent();
|
|
187
188
|
return [4 /*yield*/, (0, utils_1.ata)(mintPublicKey, recipientPublicKey)];
|
|
188
189
|
case 2:
|
|
189
|
-
recipientTokens =
|
|
190
|
+
recipientTokens = _o.sent();
|
|
190
191
|
return [4 /*yield*/, (0, utils_1.ata)(mintPublicKey, constants_1.STREAMFLOW_TREASURY_PUBLIC_KEY)];
|
|
191
192
|
case 3:
|
|
192
|
-
streamflowTreasuryTokens =
|
|
193
|
+
streamflowTreasuryTokens = _o.sent();
|
|
193
194
|
partnerPublicKey = partner ? new web3_js_1.PublicKey(partner) : constants_1.STREAMFLOW_TREASURY_PUBLIC_KEY;
|
|
194
195
|
return [4 /*yield*/, (0, utils_1.ata)(mintPublicKey, partnerPublicKey)];
|
|
195
196
|
case 4:
|
|
196
|
-
partnerTokens =
|
|
197
|
-
if (!isNative) return [3 /*break*/,
|
|
198
|
-
return [4 /*yield*/, (0
|
|
197
|
+
partnerTokens = _o.sent();
|
|
198
|
+
if (!isNative) return [3 /*break*/, 7];
|
|
199
|
+
return [4 /*yield*/, this.getTotalFee({ address: partner !== null && partner !== void 0 ? partner : sender.publicKey.toBase58() })];
|
|
199
200
|
case 5:
|
|
200
|
-
|
|
201
|
-
|
|
201
|
+
totalFee = _o.sent();
|
|
202
|
+
totalAmount = (0, utils_2.calculateTotalAmountToDeposit)(depositedAmount, totalFee);
|
|
203
|
+
_j = (_h = ixs.push).apply;
|
|
204
|
+
_k = [ixs];
|
|
205
|
+
_l = [[]];
|
|
206
|
+
return [4 /*yield*/, (0, instructions_1.prepareWrappedAccount)(this.connection, sender.publicKey, totalAmount)];
|
|
202
207
|
case 6:
|
|
203
|
-
_h
|
|
204
|
-
|
|
208
|
+
_j.apply(_h, _k.concat([__spreadArray.apply(void 0, _l.concat([__read.apply(void 0, [(_o.sent())]), false]))]));
|
|
209
|
+
_o.label = 7;
|
|
205
210
|
case 7:
|
|
206
|
-
nativeInstructions = _h;
|
|
207
211
|
ixs.push((0, instructions_1.createStreamInstruction)({
|
|
208
212
|
start: new bn_js_1.default(start),
|
|
209
213
|
depositedAmount: depositedAmount,
|
|
@@ -242,18 +246,18 @@ var SolanaStreamClient = /** @class */ (function (_super) {
|
|
|
242
246
|
commitment = typeof this.commitment == "string" ? this.commitment : this.commitment.commitment;
|
|
243
247
|
return [4 /*yield*/, this.connection.getLatestBlockhash(commitment)];
|
|
244
248
|
case 8:
|
|
245
|
-
hash =
|
|
246
|
-
tx = (
|
|
249
|
+
hash = _o.sent();
|
|
250
|
+
tx = (_m = new web3_js_1.Transaction({
|
|
247
251
|
feePayer: sender.publicKey,
|
|
248
252
|
blockhash: hash.blockhash,
|
|
249
253
|
lastValidBlockHeight: hash.lastValidBlockHeight,
|
|
250
|
-
})).add.apply(
|
|
254
|
+
})).add.apply(_m, __spreadArray([], __read(ixs), false));
|
|
251
255
|
if (metadata) {
|
|
252
256
|
tx.partialSign(metadata);
|
|
253
257
|
}
|
|
254
258
|
return [4 /*yield*/, (0, utils_1.signAndExecuteTransaction)(this.connection, sender, tx, hash)];
|
|
255
259
|
case 9:
|
|
256
|
-
signature =
|
|
260
|
+
signature = _o.sent();
|
|
257
261
|
return [2 /*return*/, { ixs: ixs, txId: signature, metadataId: metadataPubKey.toBase58() }];
|
|
258
262
|
}
|
|
259
263
|
});
|
|
@@ -367,11 +371,11 @@ var SolanaStreamClient = /** @class */ (function (_super) {
|
|
|
367
371
|
SolanaStreamClient.prototype.createMultiple = function (data, _a) {
|
|
368
372
|
var sender = _a.sender, metadataPubKeys = _a.metadataPubKeys, _b = _a.isNative, isNative = _b === void 0 ? false : _b;
|
|
369
373
|
return __awaiter(this, void 0, void 0, function () {
|
|
370
|
-
var recipients, metadatas, metadataToRecipient, errors, signatures, batch, i, recipientData, _c,
|
|
371
|
-
var
|
|
374
|
+
var recipients, metadatas, metadataToRecipient, errors, signatures, batch, instructionsBatch, i, recipientData, _c, ixs, metadata, metadataPubKey, commitment, hash, instructionsBatch_1, instructionsBatch_1_1, _d, ixs, metadata, recipient, tx, totalDepositedAmount, nativeInstructions, prepareTransaction, signedBatch, prepareTx, responses, signedBatch_1, signedBatch_1_1, batchTx, _e, _f, _g, _h, e_1_1, batchTransactionsCalls, _j, _k, _l, _m, successes, failures;
|
|
375
|
+
var e_2, _o, _p, _q, e_1, _r;
|
|
372
376
|
var _this = this;
|
|
373
|
-
return __generator(this, function (
|
|
374
|
-
switch (
|
|
377
|
+
return __generator(this, function (_s) {
|
|
378
|
+
switch (_s.label) {
|
|
375
379
|
case 0:
|
|
376
380
|
recipients = data.recipients;
|
|
377
381
|
if (!sender.publicKey) {
|
|
@@ -382,45 +386,67 @@ var SolanaStreamClient = /** @class */ (function (_super) {
|
|
|
382
386
|
errors = [];
|
|
383
387
|
signatures = [];
|
|
384
388
|
batch = [];
|
|
389
|
+
instructionsBatch = [];
|
|
385
390
|
metadataPubKeys = metadataPubKeys || [];
|
|
386
391
|
i = 0;
|
|
387
|
-
|
|
392
|
+
_s.label = 1;
|
|
388
393
|
case 1:
|
|
389
394
|
if (!(i < recipients.length)) return [3 /*break*/, 4];
|
|
390
395
|
recipientData = recipients[i];
|
|
391
|
-
return [4 /*yield*/, this.
|
|
396
|
+
return [4 /*yield*/, this.prepareStreamInstructions(recipientData, data, {
|
|
392
397
|
sender: sender,
|
|
393
398
|
metadataPubKeys: metadataPubKeys[i] ? [metadataPubKeys[i]] : undefined,
|
|
394
399
|
})];
|
|
395
400
|
case 2:
|
|
396
|
-
_c =
|
|
401
|
+
_c = _s.sent(), ixs = _c.ixs, metadata = _c.metadata, metadataPubKey = _c.metadataPubKey;
|
|
397
402
|
metadataToRecipient[metadataPubKey.toBase58()] = recipientData;
|
|
398
403
|
metadatas.push(metadataPubKey.toBase58());
|
|
399
|
-
|
|
400
|
-
|
|
404
|
+
instructionsBatch.push({ ixs: ixs, metadata: metadata, recipient: recipientData.recipient });
|
|
405
|
+
_s.label = 3;
|
|
401
406
|
case 3:
|
|
402
407
|
i++;
|
|
403
408
|
return [3 /*break*/, 1];
|
|
404
409
|
case 4:
|
|
410
|
+
commitment = typeof this.commitment == "string" ? this.commitment : this.commitment.commitment;
|
|
411
|
+
return [4 /*yield*/, this.connection.getLatestBlockhash(commitment)];
|
|
412
|
+
case 5:
|
|
413
|
+
hash = _s.sent();
|
|
414
|
+
try {
|
|
415
|
+
for (instructionsBatch_1 = __values(instructionsBatch), instructionsBatch_1_1 = instructionsBatch_1.next(); !instructionsBatch_1_1.done; instructionsBatch_1_1 = instructionsBatch_1.next()) {
|
|
416
|
+
_d = instructionsBatch_1_1.value, ixs = _d.ixs, metadata = _d.metadata, recipient = _d.recipient;
|
|
417
|
+
tx = (_p = new web3_js_1.Transaction({
|
|
418
|
+
feePayer: sender.publicKey,
|
|
419
|
+
blockhash: hash.blockhash,
|
|
420
|
+
lastValidBlockHeight: hash.lastValidBlockHeight,
|
|
421
|
+
})).add.apply(_p, __spreadArray([], __read(ixs), false));
|
|
422
|
+
if (metadata) {
|
|
423
|
+
tx.partialSign(metadata);
|
|
424
|
+
}
|
|
425
|
+
batch.push({ tx: tx, recipient: recipient });
|
|
426
|
+
}
|
|
427
|
+
}
|
|
428
|
+
catch (e_2_1) { e_2 = { error: e_2_1 }; }
|
|
429
|
+
finally {
|
|
430
|
+
try {
|
|
431
|
+
if (instructionsBatch_1_1 && !instructionsBatch_1_1.done && (_o = instructionsBatch_1.return)) _o.call(instructionsBatch_1);
|
|
432
|
+
}
|
|
433
|
+
finally { if (e_2) throw e_2.error; }
|
|
434
|
+
}
|
|
405
435
|
if (!isNative) return [3 /*break*/, 7];
|
|
406
436
|
totalDepositedAmount = recipients.reduce(function (acc, recipient) { return recipient.amount.add(acc); }, new bn_js_1.default(0));
|
|
407
437
|
return [4 /*yield*/, (0, instructions_1.prepareWrappedAccount)(this.connection, sender.publicKey, totalDepositedAmount)];
|
|
408
|
-
case 5:
|
|
409
|
-
nativeInstructions = _p.sent();
|
|
410
|
-
commitment = typeof this.commitment == "string" ? this.commitment : this.commitment.commitment;
|
|
411
|
-
return [4 /*yield*/, this.connection.getLatestBlockhash(commitment)];
|
|
412
438
|
case 6:
|
|
413
|
-
|
|
414
|
-
prepareTransaction = (
|
|
439
|
+
nativeInstructions = _s.sent();
|
|
440
|
+
prepareTransaction = (_q = new web3_js_1.Transaction({
|
|
415
441
|
feePayer: sender.publicKey,
|
|
416
442
|
blockhash: hash.blockhash,
|
|
417
443
|
lastValidBlockHeight: hash.lastValidBlockHeight,
|
|
418
|
-
})).add.apply(
|
|
444
|
+
})).add.apply(_q, __spreadArray([], __read(nativeInstructions), false));
|
|
419
445
|
batch.push({ tx: prepareTransaction, recipient: sender.publicKey.toBase58() });
|
|
420
|
-
|
|
446
|
+
_s.label = 7;
|
|
421
447
|
case 7: return [4 /*yield*/, (0, utils_1.signAllTransactionWithRecipients)(sender, batch)];
|
|
422
448
|
case 8:
|
|
423
|
-
signedBatch =
|
|
449
|
+
signedBatch = _s.sent();
|
|
424
450
|
signedBatch.forEach(function (item, index) {
|
|
425
451
|
item.tx.lastValidBlockHeight = batch[index].tx.lastValidBlockHeight;
|
|
426
452
|
});
|
|
@@ -428,39 +454,39 @@ var SolanaStreamClient = /** @class */ (function (_super) {
|
|
|
428
454
|
prepareTx = signedBatch.pop();
|
|
429
455
|
return [4 /*yield*/, (0, utils_1.sendAndConfirmStreamRawTransaction)(this.connection, prepareTx)];
|
|
430
456
|
case 9:
|
|
431
|
-
|
|
432
|
-
|
|
457
|
+
_s.sent();
|
|
458
|
+
_s.label = 10;
|
|
433
459
|
case 10:
|
|
434
460
|
responses = [];
|
|
435
461
|
if (!(metadataPubKeys.length > 0)) return [3 /*break*/, 19];
|
|
436
|
-
|
|
462
|
+
_s.label = 11;
|
|
437
463
|
case 11:
|
|
438
|
-
|
|
464
|
+
_s.trys.push([11, 16, 17, 18]);
|
|
439
465
|
signedBatch_1 = __values(signedBatch), signedBatch_1_1 = signedBatch_1.next();
|
|
440
|
-
|
|
466
|
+
_s.label = 12;
|
|
441
467
|
case 12:
|
|
442
468
|
if (!!signedBatch_1_1.done) return [3 /*break*/, 15];
|
|
443
469
|
batchTx = signedBatch_1_1.value;
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
470
|
+
_f = (_e = responses.push).apply;
|
|
471
|
+
_g = [responses];
|
|
472
|
+
_h = [[]];
|
|
447
473
|
return [4 /*yield*/, Promise.allSettled([
|
|
448
474
|
(0, utils_1.sendAndConfirmStreamRawTransaction)(this.connection, batchTx),
|
|
449
475
|
])];
|
|
450
476
|
case 13:
|
|
451
|
-
|
|
452
|
-
|
|
477
|
+
_f.apply(_e, _g.concat([__spreadArray.apply(void 0, _h.concat([__read.apply(void 0, [(_s.sent())]), false]))]));
|
|
478
|
+
_s.label = 14;
|
|
453
479
|
case 14:
|
|
454
480
|
signedBatch_1_1 = signedBatch_1.next();
|
|
455
481
|
return [3 /*break*/, 12];
|
|
456
482
|
case 15: return [3 /*break*/, 18];
|
|
457
483
|
case 16:
|
|
458
|
-
e_1_1 =
|
|
484
|
+
e_1_1 = _s.sent();
|
|
459
485
|
e_1 = { error: e_1_1 };
|
|
460
486
|
return [3 /*break*/, 18];
|
|
461
487
|
case 17:
|
|
462
488
|
try {
|
|
463
|
-
if (signedBatch_1_1 && !signedBatch_1_1.done && (
|
|
489
|
+
if (signedBatch_1_1 && !signedBatch_1_1.done && (_r = signedBatch_1.return)) _r.call(signedBatch_1);
|
|
464
490
|
}
|
|
465
491
|
finally { if (e_1) throw e_1.error; }
|
|
466
492
|
return [7 /*endfinally*/];
|
|
@@ -469,13 +495,13 @@ var SolanaStreamClient = /** @class */ (function (_super) {
|
|
|
469
495
|
batchTransactionsCalls = signedBatch.map(function (el) {
|
|
470
496
|
return (0, utils_1.sendAndConfirmStreamRawTransaction)(_this.connection, el);
|
|
471
497
|
});
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
498
|
+
_k = (_j = responses.push).apply;
|
|
499
|
+
_l = [responses];
|
|
500
|
+
_m = [[]];
|
|
475
501
|
return [4 /*yield*/, Promise.allSettled(batchTransactionsCalls)];
|
|
476
502
|
case 20:
|
|
477
|
-
|
|
478
|
-
|
|
503
|
+
_k.apply(_j, _l.concat([__spreadArray.apply(void 0, _m.concat([__read.apply(void 0, [(_s.sent())]), false]))]));
|
|
504
|
+
_s.label = 21;
|
|
479
505
|
case 21:
|
|
480
506
|
successes = responses
|
|
481
507
|
.filter(function (el) { return el.status === "fulfilled"; })
|
|
@@ -901,12 +927,11 @@ var SolanaStreamClient = /** @class */ (function (_super) {
|
|
|
901
927
|
/**
|
|
902
928
|
* Forms instructions from params, creates a raw transaction and fetch recent blockhash.
|
|
903
929
|
*/
|
|
904
|
-
SolanaStreamClient.prototype.
|
|
930
|
+
SolanaStreamClient.prototype.prepareStreamInstructions = function (recipient, streamParams, solanaExtendedConfig) {
|
|
905
931
|
return __awaiter(this, void 0, void 0, function () {
|
|
906
|
-
var mint, start, period, cliff, canTopup, cancelableBySender, cancelableByRecipient, transferableBySender, transferableByRecipient, _a, automaticWithdrawal, _b, withdrawalFrequency, partner, sender, metadataPubKeys, ixs,
|
|
907
|
-
|
|
908
|
-
|
|
909
|
-
switch (_f.label) {
|
|
932
|
+
var mint, start, period, cliff, canTopup, cancelableBySender, cancelableByRecipient, transferableBySender, transferableByRecipient, _a, automaticWithdrawal, _b, withdrawalFrequency, partner, sender, metadataPubKeys, ixs, recipientPublicKey, mintPublicKey, _c, metadata, metadataPubKey, _d, escrowTokens, senderTokens, recipientTokens, streamflowTreasuryTokens, partnerPublicKey, partnerTokens;
|
|
933
|
+
return __generator(this, function (_e) {
|
|
934
|
+
switch (_e.label) {
|
|
910
935
|
case 0:
|
|
911
936
|
mint = streamParams.tokenId, start = streamParams.start, period = streamParams.period, cliff = streamParams.cliff, canTopup = streamParams.canTopup, cancelableBySender = streamParams.cancelableBySender, cancelableByRecipient = streamParams.cancelableByRecipient, transferableBySender = streamParams.transferableBySender, transferableByRecipient = streamParams.transferableByRecipient, _a = streamParams.automaticWithdrawal, automaticWithdrawal = _a === void 0 ? false : _a, _b = streamParams.withdrawalFrequency, withdrawalFrequency = _b === void 0 ? 0 : _b, partner = streamParams.partner;
|
|
912
937
|
sender = solanaExtendedConfig.sender, metadataPubKeys = solanaExtendedConfig.metadataPubKeys;
|
|
@@ -914,24 +939,23 @@ var SolanaStreamClient = /** @class */ (function (_super) {
|
|
|
914
939
|
throw new Error("Sender's PublicKey is not available, check passed wallet adapter!");
|
|
915
940
|
}
|
|
916
941
|
ixs = [];
|
|
917
|
-
commitment = typeof this.commitment == "string" ? this.commitment : this.commitment.commitment;
|
|
918
942
|
recipientPublicKey = new web3_js_1.PublicKey(recipient.recipient);
|
|
919
943
|
mintPublicKey = new web3_js_1.PublicKey(mint);
|
|
920
944
|
_c = this.getOrCreateStreamMetadata(metadataPubKeys), metadata = _c.metadata, metadataPubKey = _c.metadataPubKey;
|
|
921
945
|
_d = __read(web3_js_1.PublicKey.findProgramAddressSync([buffer_1.Buffer.from("strm"), metadataPubKey.toBuffer()], this.programId), 1), escrowTokens = _d[0];
|
|
922
946
|
return [4 /*yield*/, (0, utils_1.ata)(mintPublicKey, sender.publicKey)];
|
|
923
947
|
case 1:
|
|
924
|
-
senderTokens =
|
|
948
|
+
senderTokens = _e.sent();
|
|
925
949
|
return [4 /*yield*/, (0, utils_1.ata)(mintPublicKey, recipientPublicKey)];
|
|
926
950
|
case 2:
|
|
927
|
-
recipientTokens =
|
|
951
|
+
recipientTokens = _e.sent();
|
|
928
952
|
return [4 /*yield*/, (0, utils_1.ata)(mintPublicKey, constants_1.STREAMFLOW_TREASURY_PUBLIC_KEY)];
|
|
929
953
|
case 3:
|
|
930
|
-
streamflowTreasuryTokens =
|
|
954
|
+
streamflowTreasuryTokens = _e.sent();
|
|
931
955
|
partnerPublicKey = partner ? new web3_js_1.PublicKey(partner) : constants_1.STREAMFLOW_TREASURY_PUBLIC_KEY;
|
|
932
956
|
return [4 /*yield*/, (0, utils_1.ata)(mintPublicKey, partnerPublicKey)];
|
|
933
957
|
case 4:
|
|
934
|
-
partnerTokens =
|
|
958
|
+
partnerTokens = _e.sent();
|
|
935
959
|
ixs.push((0, instructions_1.createStreamInstruction)({
|
|
936
960
|
start: new bn_js_1.default(start),
|
|
937
961
|
depositedAmount: recipient.amount,
|
|
@@ -967,18 +991,7 @@ var SolanaStreamClient = /** @class */ (function (_super) {
|
|
|
967
991
|
withdrawor: constants_1.WITHDRAWOR_PUBLIC_KEY,
|
|
968
992
|
systemProgram: web3_js_1.SystemProgram.programId,
|
|
969
993
|
}));
|
|
970
|
-
return [
|
|
971
|
-
case 5:
|
|
972
|
-
hash = _f.sent();
|
|
973
|
-
tx = (_e = new web3_js_1.Transaction({
|
|
974
|
-
feePayer: sender.publicKey,
|
|
975
|
-
blockhash: hash.blockhash,
|
|
976
|
-
lastValidBlockHeight: hash.lastValidBlockHeight,
|
|
977
|
-
})).add.apply(_e, __spreadArray([], __read(ixs), false));
|
|
978
|
-
if (metadata) {
|
|
979
|
-
tx.partialSign(metadata);
|
|
980
|
-
}
|
|
981
|
-
return [2 /*return*/, { tx: tx, metadataPubKey: metadataPubKey }];
|
|
994
|
+
return [2 /*return*/, { ixs: ixs, metadata: metadata, metadataPubKey: metadataPubKey }];
|
|
982
995
|
}
|
|
983
996
|
});
|
|
984
997
|
});
|
|
@@ -83,18 +83,13 @@ var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
|
|
|
83
83
|
}
|
|
84
84
|
return to.concat(ar || Array.prototype.slice.call(from));
|
|
85
85
|
};
|
|
86
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
87
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
88
|
-
};
|
|
89
86
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
90
87
|
exports.prepareWrappedAccount = exports.topupStreamInstruction = exports.transferStreamInstruction = exports.cancelStreamInstruction = exports.updateStreamInstruction = exports.withdrawStreamInstruction = exports.createUncheckedStreamInstruction = exports.createStreamInstruction = void 0;
|
|
91
88
|
var buffer_1 = require("buffer");
|
|
92
89
|
var web3_js_1 = require("@solana/web3.js");
|
|
93
|
-
var bn_js_1 = __importDefault(require("bn.js"));
|
|
94
90
|
var js_sha256_1 = require("js-sha256");
|
|
95
91
|
var spl_token_1 = require("@solana/spl-token");
|
|
96
92
|
var Layout = __importStar(require("./layout"));
|
|
97
|
-
var constants_1 = require("../common/constants");
|
|
98
93
|
var createStreamInstruction = function (data, programId, accounts) {
|
|
99
94
|
var keys = [
|
|
100
95
|
{ pubkey: accounts.sender, isSigner: true, isWritable: true },
|
|
@@ -397,7 +392,7 @@ var prepareWrappedAccount = function (connection, senderAddress, amount) { retur
|
|
|
397
392
|
web3_js_1.SystemProgram.transfer({
|
|
398
393
|
fromPubkey: senderAddress,
|
|
399
394
|
toPubkey: tokenAccount,
|
|
400
|
-
lamports: amount.
|
|
395
|
+
lamports: amount.toNumber(),
|
|
401
396
|
}),
|
|
402
397
|
(0, spl_token_1.createSyncNativeInstruction)(tokenAccount),
|
|
403
398
|
], false)];
|
package/dist/sui/StreamClient.js
CHANGED
|
@@ -86,29 +86,25 @@ var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
|
|
|
86
86
|
}
|
|
87
87
|
return to.concat(ar || Array.prototype.slice.call(from));
|
|
88
88
|
};
|
|
89
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
90
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
91
|
-
};
|
|
92
89
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
93
|
-
var bn_js_1 = __importDefault(require("bn.js"));
|
|
94
90
|
var client_1 = require("@mysten/sui.js/client");
|
|
95
91
|
var transactions_1 = require("@mysten/sui.js/transactions");
|
|
96
92
|
var utils_1 = require("@mysten/sui.js/utils");
|
|
97
93
|
var BaseStreamClient_1 = require("../common/BaseStreamClient");
|
|
98
94
|
var types_1 = require("../common/types");
|
|
99
|
-
var constants_1 = require("
|
|
100
|
-
var constants_2 = require("./constants");
|
|
95
|
+
var constants_1 = require("./constants");
|
|
101
96
|
var types_2 = require("./types");
|
|
102
97
|
var utils_2 = require("./utils");
|
|
103
98
|
var wallet_1 = require("./wallet");
|
|
99
|
+
var utils_3 = require("../common/utils");
|
|
104
100
|
var SuiStreamClient = /** @class */ (function (_super) {
|
|
105
101
|
__extends(SuiStreamClient, _super);
|
|
106
102
|
function SuiStreamClient(clusterUrl, cluster, ids) {
|
|
107
103
|
if (cluster === void 0) { cluster = types_1.ICluster.Mainnet; }
|
|
108
104
|
var _this = _super.call(this) || this;
|
|
109
|
-
_this.programId = (ids === null || ids === void 0 ? void 0 : ids.program) ? ids.program :
|
|
110
|
-
_this.configId = (ids === null || ids === void 0 ? void 0 : ids.config) ? ids.config :
|
|
111
|
-
_this.feeTableId = (ids === null || ids === void 0 ? void 0 : ids.feeTable) ? ids.feeTable :
|
|
105
|
+
_this.programId = (ids === null || ids === void 0 ? void 0 : ids.program) ? ids.program : constants_1.SUI_PROGRAM_IDS[cluster];
|
|
106
|
+
_this.configId = (ids === null || ids === void 0 ? void 0 : ids.config) ? ids.config : constants_1.SUI_CONFIG_IDS[cluster];
|
|
107
|
+
_this.feeTableId = (ids === null || ids === void 0 ? void 0 : ids.feeTable) ? ids.feeTable : constants_1.SUI_FEE_TABLE_IDS[cluster];
|
|
112
108
|
_this.client = new client_1.SuiClient({ url: clusterUrl });
|
|
113
109
|
return _this;
|
|
114
110
|
}
|
|
@@ -116,22 +112,26 @@ var SuiStreamClient = /** @class */ (function (_super) {
|
|
|
116
112
|
* Creates a new stream/vesting contract.
|
|
117
113
|
*/
|
|
118
114
|
SuiStreamClient.prototype.create = function (streamData, _a) {
|
|
115
|
+
var _b;
|
|
119
116
|
var senderWallet = _a.senderWallet;
|
|
120
117
|
return __awaiter(this, void 0, void 0, function () {
|
|
121
|
-
var wallet,
|
|
122
|
-
return __generator(this, function (
|
|
123
|
-
switch (
|
|
118
|
+
var wallet, totalFee, _c, txb, _d, digest, events;
|
|
119
|
+
return __generator(this, function (_e) {
|
|
120
|
+
switch (_e.label) {
|
|
124
121
|
case 0:
|
|
125
122
|
wallet = new wallet_1.SuiWalletWrapper(senderWallet, this.client);
|
|
126
|
-
return [4 /*yield*/, this.
|
|
123
|
+
return [4 /*yield*/, this.getTotalFee({ address: (_b = streamData.partner) !== null && _b !== void 0 ? _b : wallet.address })];
|
|
127
124
|
case 1:
|
|
128
|
-
|
|
125
|
+
totalFee = _e.sent();
|
|
126
|
+
return [4 /*yield*/, this.generateCreateBlock(wallet.address, __assign(__assign({}, streamData), { recipients: [__assign({}, streamData)] }), totalFee)];
|
|
127
|
+
case 2:
|
|
128
|
+
_c = __read.apply(void 0, [_e.sent(), 1]), txb = _c[0];
|
|
129
129
|
return [4 /*yield*/, wallet.signAndExecuteTransactionBlock({
|
|
130
130
|
transactionBlock: txb,
|
|
131
131
|
options: { showEvents: true },
|
|
132
132
|
})];
|
|
133
|
-
case
|
|
134
|
-
|
|
133
|
+
case 3:
|
|
134
|
+
_d = _e.sent(), digest = _d.digest, events = _d.events;
|
|
135
135
|
return [2 /*return*/, {
|
|
136
136
|
ixs: [],
|
|
137
137
|
txId: digest,
|
|
@@ -146,30 +146,35 @@ var SuiStreamClient = /** @class */ (function (_super) {
|
|
|
146
146
|
* We don't chain transactions in one Block so that one failed transaction does not revert all others.
|
|
147
147
|
*/
|
|
148
148
|
SuiStreamClient.prototype.createMultiple = function (multipleStreamData, _a) {
|
|
149
|
-
var _b;
|
|
149
|
+
var _b, _c;
|
|
150
150
|
var senderWallet = _a.senderWallet;
|
|
151
151
|
return __awaiter(this, void 0, void 0, function () {
|
|
152
|
-
var wallet,
|
|
153
|
-
return __generator(this, function (
|
|
154
|
-
switch (
|
|
152
|
+
var wallet, totalFee, _d, txb, firstIndex, txs, metadatas, metadataToRecipient, errors, _e, digest, events_1, effects_1, e_1, errorInfo_1;
|
|
153
|
+
return __generator(this, function (_f) {
|
|
154
|
+
switch (_f.label) {
|
|
155
155
|
case 0:
|
|
156
156
|
wallet = new wallet_1.SuiWalletWrapper(senderWallet, this.client);
|
|
157
|
-
return [4 /*yield*/, this.
|
|
157
|
+
return [4 /*yield*/, this.getTotalFee({
|
|
158
|
+
address: (_b = multipleStreamData.partner) !== null && _b !== void 0 ? _b : wallet.address,
|
|
159
|
+
})];
|
|
158
160
|
case 1:
|
|
159
|
-
|
|
161
|
+
totalFee = _f.sent();
|
|
162
|
+
return [4 /*yield*/, this.generateCreateBlock(wallet.address, multipleStreamData, totalFee)];
|
|
163
|
+
case 2:
|
|
164
|
+
_d = __read.apply(void 0, [_f.sent(), 2]), txb = _d[0], firstIndex = _d[1];
|
|
160
165
|
txs = [];
|
|
161
166
|
metadatas = [];
|
|
162
167
|
metadataToRecipient = {};
|
|
163
168
|
errors = [];
|
|
164
|
-
|
|
165
|
-
case
|
|
166
|
-
|
|
169
|
+
_f.label = 3;
|
|
170
|
+
case 3:
|
|
171
|
+
_f.trys.push([3, 5, , 6]);
|
|
167
172
|
return [4 /*yield*/, wallet.signAndExecuteTransactionBlock({
|
|
168
173
|
transactionBlock: txb,
|
|
169
174
|
options: { showEffects: true, showEvents: true },
|
|
170
175
|
})];
|
|
171
|
-
case
|
|
172
|
-
|
|
176
|
+
case 4:
|
|
177
|
+
_e = _f.sent(), digest = _e.digest, events_1 = _e.events, effects_1 = _e.effects;
|
|
173
178
|
txs.push(digest);
|
|
174
179
|
if (effects_1.status.status === "failure") {
|
|
175
180
|
multipleStreamData.recipients.forEach(function (recipient) {
|
|
@@ -187,10 +192,10 @@ var SuiStreamClient = /** @class */ (function (_super) {
|
|
|
187
192
|
metadataToRecipient[metadataId] = recipient;
|
|
188
193
|
});
|
|
189
194
|
}
|
|
190
|
-
return [3 /*break*/,
|
|
191
|
-
case
|
|
192
|
-
e_1 =
|
|
193
|
-
errorInfo_1 = (0, utils_2.extractSuiErrorInfo)((
|
|
195
|
+
return [3 /*break*/, 6];
|
|
196
|
+
case 5:
|
|
197
|
+
e_1 = _f.sent();
|
|
198
|
+
errorInfo_1 = (0, utils_2.extractSuiErrorInfo)((_c = e_1.toString()) !== null && _c !== void 0 ? _c : "Unknown error!");
|
|
194
199
|
multipleStreamData.recipients.forEach(function (recipient, index) {
|
|
195
200
|
var _a;
|
|
196
201
|
if (errorInfo_1.index === undefined ||
|
|
@@ -204,8 +209,8 @@ var SuiStreamClient = /** @class */ (function (_super) {
|
|
|
204
209
|
});
|
|
205
210
|
}
|
|
206
211
|
});
|
|
207
|
-
return [3 /*break*/,
|
|
208
|
-
case
|
|
212
|
+
return [3 /*break*/, 6];
|
|
213
|
+
case 6: return [2 /*return*/, {
|
|
209
214
|
txs: txs,
|
|
210
215
|
metadatas: metadatas,
|
|
211
216
|
metadataToRecipient: metadataToRecipient,
|
|
@@ -320,7 +325,7 @@ var SuiStreamClient = /** @class */ (function (_super) {
|
|
|
320
325
|
SuiStreamClient.prototype.topup = function (topupData, _a) {
|
|
321
326
|
var senderWallet = _a.senderWallet, tokenId = _a.tokenId;
|
|
322
327
|
return __awaiter(this, void 0, void 0, function () {
|
|
323
|
-
var wallet, txb, coins, coinObject, digest;
|
|
328
|
+
var wallet, txb, coins, stream, totalFee, coinObject, digest;
|
|
324
329
|
return __generator(this, function (_b) {
|
|
325
330
|
switch (_b.label) {
|
|
326
331
|
case 0:
|
|
@@ -329,7 +334,11 @@ var SuiStreamClient = /** @class */ (function (_super) {
|
|
|
329
334
|
return [4 /*yield*/, this.getAllCoins(wallet.address, tokenId)];
|
|
330
335
|
case 1:
|
|
331
336
|
coins = _b.sent();
|
|
332
|
-
|
|
337
|
+
return [4 /*yield*/, this.getOne({ id: topupData.id })];
|
|
338
|
+
case 2:
|
|
339
|
+
stream = _b.sent();
|
|
340
|
+
totalFee = (stream.partnerFeePercent + stream.streamflowFeePercent) / 100;
|
|
341
|
+
coinObject = this.splitCoinObjectForAmount(txb, topupData.amount, tokenId, coins, totalFee);
|
|
333
342
|
txb.moveCall({
|
|
334
343
|
target: "".concat(this.programId, "::protocol::topup"),
|
|
335
344
|
typeArguments: [tokenId],
|
|
@@ -345,7 +354,7 @@ var SuiStreamClient = /** @class */ (function (_super) {
|
|
|
345
354
|
return [4 /*yield*/, wallet.signAndExecuteTransactionBlock({
|
|
346
355
|
transactionBlock: txb,
|
|
347
356
|
})];
|
|
348
|
-
case
|
|
357
|
+
case 3:
|
|
349
358
|
digest = (_b.sent()).digest;
|
|
350
359
|
return [2 /*return*/, {
|
|
351
360
|
ixs: [],
|
|
@@ -519,7 +528,7 @@ var SuiStreamClient = /** @class */ (function (_super) {
|
|
|
519
528
|
/**
|
|
520
529
|
* Utility function to generate Transaction Block to create streams
|
|
521
530
|
*/
|
|
522
|
-
SuiStreamClient.prototype.generateCreateBlock = function (walletAddress, multipleStreamData) {
|
|
531
|
+
SuiStreamClient.prototype.generateCreateBlock = function (walletAddress, multipleStreamData, totalFee) {
|
|
523
532
|
return __awaiter(this, void 0, void 0, function () {
|
|
524
533
|
var coins, totalAmount, txb, coinObject, firstIndex;
|
|
525
534
|
var _this = this;
|
|
@@ -532,7 +541,7 @@ var SuiStreamClient = /** @class */ (function (_super) {
|
|
|
532
541
|
.map(function (recipiient) { return recipiient.amount; })
|
|
533
542
|
.reduce(function (prev, current) { return current.add(prev); });
|
|
534
543
|
txb = new transactions_1.TransactionBlock();
|
|
535
|
-
coinObject = this.splitCoinObjectForAmount(txb, totalAmount, multipleStreamData.tokenId, coins);
|
|
544
|
+
coinObject = this.splitCoinObjectForAmount(txb, totalAmount, multipleStreamData.tokenId, coins, totalFee);
|
|
536
545
|
coins = [coins[0]];
|
|
537
546
|
firstIndex = null;
|
|
538
547
|
multipleStreamData.recipients.forEach(function (recipient) {
|
|
@@ -619,13 +628,13 @@ var SuiStreamClient = /** @class */ (function (_super) {
|
|
|
619
628
|
* @param coins array of owned coins of the same type
|
|
620
629
|
* @returns Coin Object to use in a Move Call
|
|
621
630
|
*/
|
|
622
|
-
SuiStreamClient.prototype.splitCoinObjectForAmount = function (txb, amount, coinType, coins) {
|
|
631
|
+
SuiStreamClient.prototype.splitCoinObjectForAmount = function (txb, amount, coinType, coins, totalFee) {
|
|
623
632
|
var coinObject = coinType === utils_1.SUI_TYPE_ARG ? txb.gas : txb.object(coins[0].coinObjectId);
|
|
624
633
|
if (coins.length > 1) {
|
|
625
634
|
txb.mergeCoins(coinObject, coins.slice(1).map(function (item) { return txb.object(item.coinObjectId); }));
|
|
626
635
|
}
|
|
627
|
-
var
|
|
628
|
-
return txb.splitCoins(coinObject, [txb.pure(
|
|
636
|
+
var totalAmount = (0, utils_3.calculateTotalAmountToDeposit)(amount, totalFee);
|
|
637
|
+
return txb.splitCoins(coinObject, [txb.pure(totalAmount.toString())])[0];
|
|
629
638
|
};
|
|
630
639
|
/**
|
|
631
640
|
* Return previously splitted Coin Object to owner and merge it to to rebate storage fees
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@streamflow/stream",
|
|
3
|
-
"version": "5.10.
|
|
3
|
+
"version": "5.10.2",
|
|
4
4
|
"description": "JavaScript SDK to interact with Streamflow protocol.",
|
|
5
5
|
"homepage": "https://github.com/streamflow-finance/js-sdk/",
|
|
6
6
|
"main": "dist/index.js",
|
|
@@ -11,7 +11,7 @@
|
|
|
11
11
|
"lint": "eslint .",
|
|
12
12
|
"prepublishOnly": "npm run lint && npm test && npm run build"
|
|
13
13
|
},
|
|
14
|
-
"gitHead": "
|
|
14
|
+
"gitHead": "d410590014861b421cc7daf79b8e803092663959",
|
|
15
15
|
"devDependencies": {
|
|
16
16
|
"@types/bn.js": "5.1.1",
|
|
17
17
|
"@types/ethereum-checksum-address": "^0.0.0",
|