@streamflow/common 7.0.0-alpha.1 → 7.0.0-alpha.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/cjs/utils.js CHANGED
@@ -39,34 +39,29 @@ 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.sleep = exports.handleContractError = exports.getNumberFromBN = exports.getBN = void 0;
43
- var bn_js_1 = __importDefault(require("bn.js"));
42
+ exports.sleep = exports.handleContractError = exports.getScaledBigNumber = exports.getNumberFromBigNumber = void 0;
43
+ var bignumber_js_1 = __importDefault(require("bignumber.js"));
44
44
  var types_js_1 = require("./types.js");
45
45
  /**
46
- * Used for conversion of token amounts to their Big Number representation.
47
- * Get Big Number representation in the smallest units from the same value in the highest units.
48
- * @param {number} value - Number of tokens you want to convert to its BN representation.
46
+ * Used for token amounts conversion from their Big Number representation to number.
47
+ * Get value in the highest units from BigNumber representation of the same value in the smallest units.
48
+ * @param {BigNumber} value - Big Number representation of value in the smallest units.
49
49
  * @param {number} decimals - Number of decimals the token has.
50
50
  */
51
- var getBN = function (value, decimals) {
52
- var decimalPart = value - Math.trunc(value);
53
- var integerPart = new bn_js_1.default(Math.trunc(value));
54
- var decimalE = new bn_js_1.default(decimalPart * 1e9);
55
- var sum = integerPart.mul(new bn_js_1.default(1e9)).add(decimalE);
56
- var resultE = sum.mul(new bn_js_1.default(10).pow(new bn_js_1.default(decimals)));
57
- return resultE.div(new bn_js_1.default(1e9));
51
+ var getNumberFromBigNumber = function (bigNum, decimals) {
52
+ return bigNum.div((0, bignumber_js_1.default)(10).pow(decimals)).toNumber();
58
53
  };
59
- exports.getBN = getBN;
54
+ exports.getNumberFromBigNumber = getNumberFromBigNumber;
60
55
  /**
61
- * Used for token amounts conversion from their Big Number representation to number.
62
- * Get value in the highest units from BN representation of the same value in the smallest units.
63
- * @param {BN} value - Big Number representation of value in the smallest units.
56
+ * Used for conversion of token amounts to their Big Number representation.
57
+ * Get Big Number representation in the smallest units from the same value in the highest units.
58
+ * @param {number} value - Number of tokens you want to convert to its BigNumber representation.
64
59
  * @param {number} decimals - Number of decimals the token has.
65
60
  */
66
- var getNumberFromBN = function (value, decimals) {
67
- return value.gt(new bn_js_1.default(Math.pow(2, 53) - 1)) ? value.div(new bn_js_1.default(Math.pow(10, decimals))).toNumber() : value.toNumber() / Math.pow(10, decimals);
61
+ var getScaledBigNumber = function (value, decimals) {
62
+ return new bignumber_js_1.default(value).times(new bignumber_js_1.default(10).pow(decimals));
68
63
  };
69
- exports.getNumberFromBN = getNumberFromBN;
64
+ exports.getScaledBigNumber = getScaledBigNumber;
70
65
  /**
71
66
  * Used to make on chain calls to the contract and wrap raised errors if any
72
67
  * @param func function that interacts with the contract
@@ -1,3 +1,3 @@
1
1
  import { Connection, PublicKey, TransactionInstruction } from "@solana/web3.js";
2
- import BN from "bn.js";
3
- export declare const prepareWrappedAccount: (connection: Connection, senderAddress: PublicKey, amount: BN) => Promise<TransactionInstruction[]>;
2
+ import BigNumber from "bignumber.js";
3
+ export declare const prepareWrappedAccount: (connection: Connection, senderAddress: PublicKey, amount: BigNumber) => Promise<TransactionInstruction[]>;
@@ -1,18 +1,18 @@
1
- import BN from "bn.js";
1
+ import BigNumber from "bignumber.js";
2
2
  /**
3
- * Used for conversion of token amounts to their Big Number representation.
4
- * Get Big Number representation in the smallest units from the same value in the highest units.
5
- * @param {number} value - Number of tokens you want to convert to its BN representation.
3
+ * Used for token amounts conversion from their Big Number representation to number.
4
+ * Get value in the highest units from BigNumber representation of the same value in the smallest units.
5
+ * @param {BigNumber} value - Big Number representation of value in the smallest units.
6
6
  * @param {number} decimals - Number of decimals the token has.
7
7
  */
8
- export declare const getBN: (value: number, decimals: number) => BN;
8
+ export declare const getNumberFromBigNumber: (bigNum: BigNumber, decimals: number) => number;
9
9
  /**
10
- * Used for token amounts conversion from their Big Number representation to number.
11
- * Get value in the highest units from BN representation of the same value in the smallest units.
12
- * @param {BN} value - Big Number representation of value in the smallest units.
10
+ * Used for conversion of token amounts to their Big Number representation.
11
+ * Get Big Number representation in the smallest units from the same value in the highest units.
12
+ * @param {number} value - Number of tokens you want to convert to its BigNumber representation.
13
13
  * @param {number} decimals - Number of decimals the token has.
14
14
  */
15
- export declare const getNumberFromBN: (value: BN, decimals: number) => number;
15
+ export declare const getScaledBigNumber: (value: number | string | BigNumber, decimals: number) => BigNumber;
16
16
  /**
17
17
  * Used to make on chain calls to the contract and wrap raised errors if any
18
18
  * @param func function that interacts with the contract
package/dist/esm/utils.js CHANGED
@@ -1,26 +1,23 @@
1
- import BN from "bn.js";
1
+ import BigNumber from "bignumber.js";
2
2
  import { ContractError } from "./types.js";
3
3
  /**
4
- * Used for conversion of token amounts to their Big Number representation.
5
- * Get Big Number representation in the smallest units from the same value in the highest units.
6
- * @param {number} value - Number of tokens you want to convert to its BN representation.
4
+ * Used for token amounts conversion from their Big Number representation to number.
5
+ * Get value in the highest units from BigNumber representation of the same value in the smallest units.
6
+ * @param {BigNumber} value - Big Number representation of value in the smallest units.
7
7
  * @param {number} decimals - Number of decimals the token has.
8
8
  */
9
- export const getBN = (value, decimals) => {
10
- const decimalPart = value - Math.trunc(value);
11
- const integerPart = new BN(Math.trunc(value));
12
- const decimalE = new BN(decimalPart * 1e9);
13
- const sum = integerPart.mul(new BN(1e9)).add(decimalE);
14
- const resultE = sum.mul(new BN(10).pow(new BN(decimals)));
15
- return resultE.div(new BN(1e9));
9
+ export const getNumberFromBigNumber = (bigNum, decimals) => {
10
+ return bigNum.div(BigNumber(10).pow(decimals)).toNumber();
16
11
  };
17
12
  /**
18
- * Used for token amounts conversion from their Big Number representation to number.
19
- * Get value in the highest units from BN representation of the same value in the smallest units.
20
- * @param {BN} value - Big Number representation of value in the smallest units.
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 BigNumber representation.
21
16
  * @param {number} decimals - Number of decimals the token has.
22
17
  */
23
- export const getNumberFromBN = (value, decimals) => value.gt(new BN(2 ** 53 - 1)) ? value.div(new BN(10 ** decimals)).toNumber() : value.toNumber() / 10 ** decimals;
18
+ export const getScaledBigNumber = (value, decimals) => {
19
+ return new BigNumber(value).times(new BigNumber(10).pow(decimals));
20
+ };
24
21
  /**
25
22
  * Used to make on chain calls to the contract and wrap raised errors if any
26
23
  * @param func function that interacts with the contract
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@streamflow/common",
3
- "version": "7.0.0-alpha.1",
3
+ "version": "7.0.0-alpha.2",
4
4
  "description": "Common utilities and types used by streamflow packages.",
5
5
  "homepage": "https://github.com/streamflow-finance/js-sdk/",
6
6
  "main": "./dist/esm/index.js",
@@ -27,10 +27,9 @@
27
27
  "lint-config": "eslint --print-config",
28
28
  "prepublishOnly": "npm run lint && npm run build"
29
29
  },
30
- "gitHead": "8b2be143ac1bfeaca3bcecc11eb5fa1e81f2ffb7",
30
+ "gitHead": "64926e169007ef5a65c5342a57d8e37047831015",
31
31
  "devDependencies": {
32
- "@streamflow/eslint-config": "7.0.0-alpha.1",
33
- "@types/bn.js": "5.1.1",
32
+ "@streamflow/eslint-config": "7.0.0-alpha.2",
34
33
  "date-fns": "2.28.0",
35
34
  "typescript": "^4.9.5"
36
35
  },
@@ -41,7 +40,7 @@
41
40
  "@solana/wallet-adapter-base": "0.9.19",
42
41
  "@solana/web3.js": "1.70.1",
43
42
  "aptos": "1.4.0",
44
- "bn.js": "5.2.1",
43
+ "bignumber.js": "^9.1.2",
45
44
  "borsh": "^2.0.0",
46
45
  "bs58": "5.0.0",
47
46
  "p-queue": "^8.0.1"