@streamflow/stream 7.0.0-alpha.2 → 7.0.0-alpha.20
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 +70 -67
- 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 +28 -37
- 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 +4 -3
- package/dist/cjs/common/contractUtils.js +33 -18
- package/dist/cjs/common/types.js +30 -1
- package/dist/cjs/common/utils.js +38 -80
- 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 +759 -1090
- package/dist/cjs/solana/constants.js +44 -11
- package/dist/cjs/solana/descriptor/idl/streamflow_aligned_unlocks.json +1471 -0
- package/dist/cjs/solana/descriptor/streamflow_aligned_unlocks.js +2 -0
- package/dist/cjs/solana/index.js +2 -1
- package/dist/cjs/solana/instructions.js +75 -81
- package/dist/cjs/solana/layout.js +7 -8
- package/dist/cjs/solana/lib/derive-accounts.js +17 -0
- package/dist/cjs/solana/lib/utils.js +127 -0
- package/dist/cjs/solana/types.js +40 -27
- 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 +14 -14
- 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 +3 -2
- package/dist/esm/common/constants.js +3 -2
- package/dist/esm/common/contractUtils.d.ts +18 -15
- package/dist/esm/common/contractUtils.js +19 -6
- package/dist/esm/common/types.d.ts +112 -57
- package/dist/esm/common/types.js +29 -0
- package/dist/esm/common/utils.d.ts +11 -11
- package/dist/esm/common/utils.js +19 -16
- package/dist/esm/evm/StreamClient.d.ts +2 -2
- package/dist/esm/evm/StreamClient.js +7 -7
- package/dist/esm/evm/types.d.ts +14 -14
- 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 +24 -16
- package/dist/esm/solana/StreamClient.js +324 -156
- package/dist/esm/solana/constants.d.ts +17 -0
- package/dist/esm/solana/constants.js +35 -1
- package/dist/esm/solana/descriptor/idl/streamflow_aligned_unlocks.json +1471 -0
- package/dist/esm/solana/descriptor/streamflow_aligned_unlocks.d.ts +1272 -0
- package/dist/esm/solana/descriptor/streamflow_aligned_unlocks.js +1 -0
- package/dist/esm/solana/index.d.ts +2 -1
- package/dist/esm/solana/index.js +2 -1
- package/dist/esm/solana/instructions.d.ts +17 -17
- package/dist/esm/solana/instructions.js +18 -19
- package/dist/esm/solana/lib/derive-accounts.d.ts +4 -0
- package/dist/esm/solana/lib/derive-accounts.js +11 -0
- package/dist/esm/solana/{utils.d.ts → lib/utils.d.ts} +1 -3
- package/dist/esm/solana/{utils.js → lib/utils.js} +28 -34
- package/dist/esm/solana/types.d.ts +72 -39
- package/dist/esm/solana/types.js +32 -4
- package/dist/esm/sui/StreamClient.js +1 -1
- package/dist/esm/sui/types.d.ts +14 -14
- package/dist/esm/sui/types.js +13 -13
- package/package.json +12 -10
- package/dist/cjs/solana/utils.js +0 -222
package/dist/cjs/common/utils.js
CHANGED
|
@@ -1,82 +1,49 @@
|
|
|
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 (g && (g = 0, op[0] && (_ = 0)), _) 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
|
-
};
|
|
38
2
|
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
39
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
40
4
|
};
|
|
41
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
42
|
-
exports.handleContractError = exports.calculateTotalAmountToDeposit = exports.
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
6
|
+
exports.handleContractError = exports.calculateTotalAmountToDeposit = exports.getNumberFromBN = exports.getBN = void 0;
|
|
7
|
+
const bn_js_1 = __importDefault(require("bn.js"));
|
|
8
|
+
const types_js_1 = require("./types.js");
|
|
9
|
+
const FEE_PRECISION = 4;
|
|
10
|
+
const FEE_NORMALIZER = 10 ** FEE_PRECISION;
|
|
11
|
+
const FEE_MULTIPLIER = new bn_js_1.default(10 ** 6);
|
|
48
12
|
/**
|
|
49
|
-
* Used for token amounts
|
|
50
|
-
* Get
|
|
51
|
-
* @param {
|
|
13
|
+
* Used for conversion of token amounts to their Big Number representation.
|
|
14
|
+
* Get Big Number representation in the smallest units from the same value in the highest units.
|
|
15
|
+
* @param {number} value - Number of tokens you want to convert to its BN representation.
|
|
52
16
|
* @param {number} decimals - Number of decimals the token has.
|
|
53
17
|
*/
|
|
54
|
-
|
|
55
|
-
|
|
18
|
+
const getBN = (value, decimals) => {
|
|
19
|
+
const decimalPart = value - Math.trunc(value);
|
|
20
|
+
const integerPart = new bn_js_1.default(Math.trunc(value));
|
|
21
|
+
const decimalE = new bn_js_1.default(decimalPart * 1e9);
|
|
22
|
+
const sum = integerPart.mul(new bn_js_1.default(1e9)).add(decimalE);
|
|
23
|
+
const resultE = sum.mul(new bn_js_1.default(10).pow(new bn_js_1.default(decimals)));
|
|
24
|
+
return resultE.div(new bn_js_1.default(1e9));
|
|
56
25
|
};
|
|
57
|
-
exports.
|
|
26
|
+
exports.getBN = getBN;
|
|
58
27
|
/**
|
|
59
|
-
* Used for
|
|
60
|
-
* Get
|
|
61
|
-
* @param {
|
|
28
|
+
* Used for token amounts conversion from their Big Number representation to number.
|
|
29
|
+
* Get value in the highest units from BN representation of the same value in the smallest units.
|
|
30
|
+
* @param {BN} value - Big Number representation of value in the smallest units.
|
|
62
31
|
* @param {number} decimals - Number of decimals the token has.
|
|
63
32
|
*/
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
};
|
|
67
|
-
exports.getScaledBigNumber = getScaledBigNumber;
|
|
33
|
+
const getNumberFromBN = (value, decimals) => value.gt(new bn_js_1.default(2 ** 53 - 1)) ? value.div(new bn_js_1.default(10 ** decimals)).toNumber() : value.toNumber() / 10 ** decimals;
|
|
34
|
+
exports.getNumberFromBN = getNumberFromBN;
|
|
68
35
|
/**
|
|
69
36
|
* Calculate total amount of a Contract including all fees.
|
|
70
|
-
* - first we convert fee floating to a
|
|
37
|
+
* - first we convert fee floating to a BN with up to 4 decimals precision
|
|
71
38
|
* - then we reverse the fee with `FEE_MULTIPLIER` to safely multiply it by depositedAmount
|
|
72
39
|
* to receive a total number and not percentage of depositedAmount
|
|
73
40
|
* @param depositedAmount deposited raw tokens
|
|
74
41
|
* @param totalFee sum of all fees in percentage as floating number, e.g. 0.99% should be supplied as 0.99
|
|
75
42
|
* @returns total tokens amount that Contract will retrieve from the Sender
|
|
76
43
|
*/
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
return depositedAmount.
|
|
44
|
+
const calculateTotalAmountToDeposit = (depositedAmount, totalFee) => {
|
|
45
|
+
const totalFeeNormalized = new bn_js_1.default(totalFee * FEE_NORMALIZER);
|
|
46
|
+
return depositedAmount.mul(totalFeeNormalized.add(FEE_MULTIPLIER)).div(FEE_MULTIPLIER);
|
|
80
47
|
};
|
|
81
48
|
exports.calculateTotalAmountToDeposit = calculateTotalAmountToDeposit;
|
|
82
49
|
/**
|
|
@@ -85,27 +52,18 @@ exports.calculateTotalAmountToDeposit = calculateTotalAmountToDeposit;
|
|
|
85
52
|
* @param callback callback that may be used to extract error code
|
|
86
53
|
* @returns {T}
|
|
87
54
|
*/
|
|
88
|
-
function handleContractError(func, callback) {
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
case 1: return [2 /*return*/, _a.sent()];
|
|
97
|
-
case 2:
|
|
98
|
-
err_1 = _a.sent();
|
|
99
|
-
if (err_1 instanceof Error) {
|
|
100
|
-
if (callback) {
|
|
101
|
-
throw new types_js_1.ContractError(err_1, callback(err_1));
|
|
102
|
-
}
|
|
103
|
-
throw new types_js_1.ContractError(err_1);
|
|
104
|
-
}
|
|
105
|
-
throw err_1;
|
|
106
|
-
case 3: return [2 /*return*/];
|
|
55
|
+
async function handleContractError(func, callback) {
|
|
56
|
+
try {
|
|
57
|
+
return await func();
|
|
58
|
+
}
|
|
59
|
+
catch (err) {
|
|
60
|
+
if (err instanceof Error) {
|
|
61
|
+
if (callback) {
|
|
62
|
+
throw new types_js_1.ContractError(err, callback(err));
|
|
107
63
|
}
|
|
108
|
-
|
|
109
|
-
|
|
64
|
+
throw new types_js_1.ContractError(err);
|
|
65
|
+
}
|
|
66
|
+
throw err;
|
|
67
|
+
}
|
|
110
68
|
}
|
|
111
69
|
exports.handleContractError = handleContractError;
|