@streamflow/stream 5.10.0 → 5.10.1
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.js +23 -19
- 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
|
|
@@ -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
|
});
|
|
@@ -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.1",
|
|
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": "1cf6009bd62ccc6d141f45caa14ee58ae4a541d9",
|
|
15
15
|
"devDependencies": {
|
|
16
16
|
"@types/bn.js": "5.1.1",
|
|
17
17
|
"@types/ethereum-checksum-address": "^0.0.0",
|