@streamflow/common 7.0.0-alpha.11 → 7.0.0-alpha.12

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
@@ -3,29 +3,32 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
3
3
  return (mod && mod.__esModule) ? mod : { "default": mod };
4
4
  };
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.sleep = exports.handleContractError = exports.getScaledBigNumber = exports.getNumberFromBigNumber = void 0;
7
- const bignumber_js_1 = __importDefault(require("bignumber.js"));
6
+ exports.sleep = exports.handleContractError = exports.getNumberFromBN = exports.getBN = void 0;
7
+ const bn_js_1 = __importDefault(require("bn.js"));
8
8
  const types_js_1 = require("./types.js");
9
9
  /**
10
- * Used for token amounts conversion from their Big Number representation to number.
11
- * Get value in the highest units from BigNumber representation of the same value in the smallest units.
12
- * @param {BigNumber} 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 BN representation.
13
13
  * @param {number} decimals - Number of decimals the token has.
14
14
  */
15
- const getNumberFromBigNumber = (bigNum, decimals) => {
16
- return bigNum.div((0, bignumber_js_1.default)(10).pow(decimals)).toNumber();
15
+ const getBN = (value, decimals) => {
16
+ const decimalPart = value - Math.trunc(value);
17
+ const integerPart = new bn_js_1.default(Math.trunc(value));
18
+ const decimalE = new bn_js_1.default(decimalPart * 1e9);
19
+ const sum = integerPart.mul(new bn_js_1.default(1e9)).add(decimalE);
20
+ const resultE = sum.mul(new bn_js_1.default(10).pow(new bn_js_1.default(decimals)));
21
+ return resultE.div(new bn_js_1.default(1e9));
17
22
  };
18
- exports.getNumberFromBigNumber = getNumberFromBigNumber;
23
+ exports.getBN = getBN;
19
24
  /**
20
- * Used for conversion of token amounts to their Big Number representation.
21
- * Get Big Number representation in the smallest units from the same value in the highest units.
22
- * @param {number} value - Number of tokens you want to convert to its BigNumber representation.
25
+ * Used for token amounts conversion from their Big Number representation to number.
26
+ * Get value in the highest units from BN representation of the same value in the smallest units.
27
+ * @param {BN} value - Big Number representation of value in the smallest units.
23
28
  * @param {number} decimals - Number of decimals the token has.
24
29
  */
25
- const getScaledBigNumber = (value, decimals) => {
26
- return new bignumber_js_1.default(value).times(new bignumber_js_1.default(10).pow(decimals));
27
- };
28
- exports.getScaledBigNumber = getScaledBigNumber;
30
+ 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;
31
+ exports.getNumberFromBN = getNumberFromBN;
29
32
  /**
30
33
  * Used to make on chain calls to the contract and wrap raised errors if any
31
34
  * @param func function that interacts with the contract
@@ -1,3 +1,3 @@
1
1
  import { Connection, PublicKey, TransactionInstruction } from "@solana/web3.js";
2
- import BigNumber from "bignumber.js";
3
- export declare const prepareWrappedAccount: (connection: Connection, senderAddress: PublicKey, amount: BigNumber) => Promise<TransactionInstruction[]>;
2
+ import BN from "bn.js";
3
+ export declare const prepareWrappedAccount: (connection: Connection, senderAddress: PublicKey, amount: BN) => Promise<TransactionInstruction[]>;
@@ -1,18 +1,18 @@
1
- import BigNumber from "bignumber.js";
1
+ import BN from "bn.js";
2
2
  /**
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.
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.
6
6
  * @param {number} decimals - Number of decimals the token has.
7
7
  */
8
- export declare const getNumberFromBigNumber: (bigNum: BigNumber, decimals: number) => number;
8
+ export declare const getBN: (value: number, decimals: number) => BN;
9
9
  /**
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.
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.
13
13
  * @param {number} decimals - Number of decimals the token has.
14
14
  */
15
- export declare const getScaledBigNumber: (value: number | string | BigNumber, decimals: number) => BigNumber;
15
+ export declare const getNumberFromBN: (value: BN, decimals: number) => number;
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,23 +1,26 @@
1
- import BigNumber from "bignumber.js";
1
+ import BN from "bn.js";
2
2
  import { ContractError } from "./types.js";
3
3
  /**
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.
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.
7
7
  * @param {number} decimals - Number of decimals the token has.
8
8
  */
9
- export const getNumberFromBigNumber = (bigNum, decimals) => {
10
- return bigNum.div(BigNumber(10).pow(decimals)).toNumber();
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));
11
16
  };
12
17
  /**
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.
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.
16
21
  * @param {number} decimals - Number of decimals the token has.
17
22
  */
18
- export const getScaledBigNumber = (value, decimals) => {
19
- return new BigNumber(value).times(new BigNumber(10).pow(decimals));
20
- };
23
+ export const getNumberFromBN = (value, decimals) => value.gt(new BN(2 ** 53 - 1)) ? value.div(new BN(10 ** decimals)).toNumber() : value.toNumber() / 10 ** decimals;
21
24
  /**
22
25
  * Used to make on chain calls to the contract and wrap raised errors if any
23
26
  * @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.11",
3
+ "version": "7.0.0-alpha.12",
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,9 +27,10 @@
27
27
  "lint-config": "eslint --print-config",
28
28
  "prepublishOnly": "npm run lint && npm run build"
29
29
  },
30
- "gitHead": "679b809cff3ff71f90122bbe985da3f35834452e",
30
+ "gitHead": "7669dc9be1788d091991591bb69525f61767a437",
31
31
  "devDependencies": {
32
- "@streamflow/eslint-config": "7.0.0-alpha.11",
32
+ "@streamflow/eslint-config": "7.0.0-alpha.12",
33
+ "@types/bn.js": "5.1.1",
33
34
  "date-fns": "2.28.0",
34
35
  "typescript": "^4.9.5"
35
36
  },
@@ -40,7 +41,7 @@
40
41
  "@solana/wallet-adapter-base": "0.9.19",
41
42
  "@solana/web3.js": "1.90.2",
42
43
  "aptos": "1.21.0",
43
- "bignumber.js": "^9.1.2",
44
+ "bn.js": "5.2.1",
44
45
  "borsh": "^2.0.0",
45
46
  "bs58": "5.0.0",
46
47
  "p-queue": "^8.0.1"