@morpho-org/blue-sdk 2.0.0-alpha.6 → 2.0.0-next.10
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/LICENSE +21 -0
- package/README.md +46 -26
- package/lib/addresses.d.ts +58 -54
- package/lib/addresses.js +60 -66
- package/lib/chain.d.ts +1 -1
- package/lib/chain.js +7 -10
- package/lib/constants.js +9 -12
- package/lib/errors.d.ts +2 -2
- package/lib/errors.js +9 -19
- package/lib/holding/AssetBalances.d.ts +1 -1
- package/lib/holding/AssetBalances.js +1 -5
- package/lib/holding/Holding.d.ts +1 -1
- package/lib/holding/Holding.js +5 -9
- package/lib/holding/index.d.ts +2 -2
- package/lib/holding/index.js +2 -18
- package/lib/index.d.ts +12 -23
- package/lib/index.js +12 -52
- package/lib/market/Market.d.ts +12 -10
- package/lib/market/Market.js +58 -60
- package/lib/market/{MarketConfig.d.ts → MarketParams.d.ts} +7 -7
- package/lib/market/{MarketConfig.js → MarketParams.js} +18 -23
- package/lib/market/MarketUtils.d.ts +15 -14
- package/lib/market/MarketUtils.js +58 -64
- package/lib/market/index.d.ts +3 -3
- package/lib/market/index.js +3 -19
- package/lib/{maths → math}/AdaptiveCurveIrmLib.d.ts +1 -1
- package/lib/{maths → math}/AdaptiveCurveIrmLib.js +22 -25
- package/lib/{maths → math}/MathLib.d.ts +25 -28
- package/lib/{maths → math}/MathLib.js +51 -40
- package/lib/{maths → math}/SharesMath.d.ts +2 -2
- package/lib/{maths → math}/SharesMath.js +5 -8
- package/lib/math/index.d.ts +3 -0
- package/lib/math/index.js +3 -0
- package/lib/position/Position.d.ts +11 -10
- package/lib/position/Position.js +15 -19
- package/lib/position/index.d.ts +1 -1
- package/lib/position/index.js +1 -17
- package/lib/token/ConstantWrappedToken.d.ts +4 -4
- package/lib/token/ConstantWrappedToken.js +5 -9
- package/lib/token/ExchangeRateWrappedToken.d.ts +4 -4
- package/lib/token/ExchangeRateWrappedToken.js +5 -9
- package/lib/token/Token.d.ts +3 -3
- package/lib/token/Token.js +9 -14
- package/lib/token/VaultToken.d.ts +20 -11
- package/lib/token/VaultToken.js +14 -10
- package/lib/token/WrappedToken.d.ts +3 -3
- package/lib/token/WrappedToken.js +7 -11
- package/lib/token/index.d.ts +5 -5
- package/lib/token/index.js +5 -21
- package/lib/types.d.ts +1 -1
- package/lib/types.js +4 -9
- package/lib/user/User.d.ts +1 -1
- package/lib/user/User.js +1 -5
- package/lib/user/index.d.ts +1 -1
- package/lib/user/index.js +1 -17
- package/lib/vault/Vault.d.ts +8 -22
- package/lib/vault/Vault.js +41 -54
- package/lib/vault/VaultConfig.d.ts +2 -2
- package/lib/vault/VaultConfig.js +3 -7
- package/lib/vault/VaultMarketAllocation.d.ts +3 -3
- package/lib/vault/VaultMarketAllocation.js +4 -8
- package/lib/vault/VaultMarketConfig.d.ts +3 -3
- package/lib/vault/VaultMarketConfig.js +1 -5
- package/lib/vault/VaultMarketPublicAllocatorConfig.d.ts +1 -1
- package/lib/vault/VaultMarketPublicAllocatorConfig.js +1 -5
- package/lib/vault/VaultUser.d.ts +1 -1
- package/lib/vault/VaultUser.js +1 -5
- package/lib/vault/VaultUtils.d.ts +4 -6
- package/lib/vault/VaultUtils.js +8 -11
- package/lib/vault/index.d.ts +7 -7
- package/lib/vault/index.js +7 -23
- package/package.json +35 -34
- package/lib/helpers/format/format.d.ts +0 -122
- package/lib/helpers/format/format.js +0 -286
- package/lib/helpers/locale.d.ts +0 -46
- package/lib/helpers/locale.js +0 -96
- package/lib/maths/index.d.ts +0 -3
- package/lib/maths/index.js +0 -19
- package/lib/tests/mocks/markets.d.ts +0 -19
- package/lib/tests/mocks/markets.js +0 -121
package/lib/vault/index.js
CHANGED
|
@@ -1,23 +1,7 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
Object.defineProperty(o, k2, desc);
|
|
9
|
-
}) : (function(o, m, k, k2) {
|
|
10
|
-
if (k2 === undefined) k2 = k;
|
|
11
|
-
o[k2] = m[k];
|
|
12
|
-
}));
|
|
13
|
-
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
-
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
-
};
|
|
16
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
-
__exportStar(require("./VaultUtils"), exports);
|
|
18
|
-
__exportStar(require("./VaultConfig"), exports);
|
|
19
|
-
__exportStar(require("./VaultMarketAllocation"), exports);
|
|
20
|
-
__exportStar(require("./VaultMarketConfig"), exports);
|
|
21
|
-
__exportStar(require("./VaultMarketPublicAllocatorConfig"), exports);
|
|
22
|
-
__exportStar(require("./VaultUser"), exports);
|
|
23
|
-
__exportStar(require("./Vault"), exports);
|
|
1
|
+
export * from "./VaultUtils.js";
|
|
2
|
+
export * from "./VaultConfig.js";
|
|
3
|
+
export * from "./VaultMarketAllocation.js";
|
|
4
|
+
export * from "./VaultMarketConfig.js";
|
|
5
|
+
export * from "./VaultMarketPublicAllocatorConfig.js";
|
|
6
|
+
export * from "./VaultUser.js";
|
|
7
|
+
export * from "./Vault.js";
|
package/package.json
CHANGED
|
@@ -1,48 +1,49 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@morpho-org/blue-sdk",
|
|
3
|
-
"
|
|
3
|
+
"description": "Framework-agnostic package that defines Morpho-related entity classes (such as `Market`, `Token`, `Vault`).",
|
|
4
|
+
"version": "2.0.0-next.10",
|
|
4
5
|
"author": "Morpho Association <contact@morpho.org>",
|
|
6
|
+
"contributors": [
|
|
7
|
+
"Rubilmax <rmilon@gmail.com>"
|
|
8
|
+
],
|
|
9
|
+
"repository": "github:morpho-org/sdks",
|
|
10
|
+
"homepage": "https://github.com/morpho-org/sdks",
|
|
11
|
+
"bugs": {
|
|
12
|
+
"url": "https://github.com/morpho-org/sdks/issues",
|
|
13
|
+
"email": "contact@morpho.org"
|
|
14
|
+
},
|
|
5
15
|
"license": "MIT",
|
|
16
|
+
"type": "module",
|
|
6
17
|
"main": "lib/index.js",
|
|
7
18
|
"files": [
|
|
8
19
|
"lib"
|
|
9
20
|
],
|
|
10
|
-
"scripts": {
|
|
11
|
-
"prepublish": "yarn build",
|
|
12
|
-
"build": "tsc --build tsconfig.build.json",
|
|
13
|
-
"test": "hardhat test"
|
|
14
|
-
},
|
|
15
21
|
"dependencies": {
|
|
16
22
|
"keccak256": "^1.0.6"
|
|
17
23
|
},
|
|
18
|
-
"devDependencies": {
|
|
19
|
-
"@morpho-org/morpho-test": "^2.0.0-alpha.6",
|
|
20
|
-
"@morpho-org/morpho-ts": "^2.0.0-alpha.6",
|
|
21
|
-
"@nomicfoundation/hardhat-ethers": "^3.0.6",
|
|
22
|
-
"@nomicfoundation/hardhat-network-helpers": "^1.0.11",
|
|
23
|
-
"@types/chai": "^4.3.14",
|
|
24
|
-
"@types/chai-as-promised": "^7.1.2",
|
|
25
|
-
"@types/mocha": "^10.0.6",
|
|
26
|
-
"@types/node": "^22.1.0",
|
|
27
|
-
"chai": "^4.3.10",
|
|
28
|
-
"chai-as-promised": "^7.1.2",
|
|
29
|
-
"chai-ts": "^0.0.3",
|
|
30
|
-
"dotenv": "^16.4.5",
|
|
31
|
-
"ethers": "^6.13.2",
|
|
32
|
-
"ethers-types": "^3.17.0",
|
|
33
|
-
"hardhat": "^2.22.6",
|
|
34
|
-
"hardhat-deal": "^3.1.0",
|
|
35
|
-
"hardhat-tracer": "^3.1.0",
|
|
36
|
-
"mocha": "^10.4.0",
|
|
37
|
-
"ts-node": "^10.9.2",
|
|
38
|
-
"typescript": "^5.6.2",
|
|
39
|
-
"vitest": "^2.1.1"
|
|
40
|
-
},
|
|
41
24
|
"peerDependencies": {
|
|
42
|
-
"@morpho-org/morpho-ts": "^2.0.0-
|
|
25
|
+
"@morpho-org/morpho-ts": "^2.0.0-next.7"
|
|
26
|
+
},
|
|
27
|
+
"devDependencies": {
|
|
28
|
+
"@types/node": "^22.7.7",
|
|
29
|
+
"typescript": "^5.6.3",
|
|
30
|
+
"viem": "^2.21.32",
|
|
31
|
+
"viem-deal": "^2.0.1",
|
|
32
|
+
"vitest": "^2.1.3",
|
|
33
|
+
"@morpho-org/test": "^2.0.0-next.11",
|
|
34
|
+
"@morpho-org/morpho-ts": "^2.0.0-next.7",
|
|
35
|
+
"@morpho-org/test-viem": "^2.0.0-next.15"
|
|
43
36
|
},
|
|
44
|
-
"
|
|
45
|
-
"
|
|
37
|
+
"scripts": {
|
|
38
|
+
"prepublish": "$npm_execpath build",
|
|
39
|
+
"build": "tsc --build tsconfig.build.json",
|
|
40
|
+
"test": "vitest"
|
|
46
41
|
},
|
|
47
|
-
"
|
|
48
|
-
|
|
42
|
+
"types": "lib/index.d.ts",
|
|
43
|
+
"exports": {
|
|
44
|
+
".": {
|
|
45
|
+
"types": "./lib/index.d.ts",
|
|
46
|
+
"default": "./lib/index.js"
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
}
|
|
@@ -1,122 +0,0 @@
|
|
|
1
|
-
declare enum Format {
|
|
2
|
-
number = "number",
|
|
3
|
-
commas = "commas",
|
|
4
|
-
short = "short",
|
|
5
|
-
hex = "hex",
|
|
6
|
-
percent = "percent"
|
|
7
|
-
}
|
|
8
|
-
interface BaseFormatOptions {
|
|
9
|
-
format: Format;
|
|
10
|
-
digits?: number;
|
|
11
|
-
removeTrailingZero?: boolean;
|
|
12
|
-
min?: number;
|
|
13
|
-
max?: number;
|
|
14
|
-
sign?: boolean;
|
|
15
|
-
unit?: string;
|
|
16
|
-
readable?: boolean;
|
|
17
|
-
locale?: string;
|
|
18
|
-
}
|
|
19
|
-
interface FormatShortOptions extends BaseFormatOptions {
|
|
20
|
-
format: Format.short;
|
|
21
|
-
smallValuesWithCommas?: boolean;
|
|
22
|
-
}
|
|
23
|
-
interface FormatHexOptions {
|
|
24
|
-
format: Format.hex;
|
|
25
|
-
}
|
|
26
|
-
interface FormatCommasOptions extends BaseFormatOptions {
|
|
27
|
-
format: Format.commas;
|
|
28
|
-
}
|
|
29
|
-
interface FormatNumberOptions extends BaseFormatOptions {
|
|
30
|
-
format: Format.number;
|
|
31
|
-
}
|
|
32
|
-
interface FormatPercentOptions extends BaseFormatOptions {
|
|
33
|
-
format: Format.percent;
|
|
34
|
-
}
|
|
35
|
-
type FormatOptions = FormatHexOptions | FormatShortOptions | FormatNumberOptions | FormatCommasOptions | FormatPercentOptions;
|
|
36
|
-
declare global {
|
|
37
|
-
interface String {
|
|
38
|
-
insert(index: number, substr: string, fillWith?: string): string;
|
|
39
|
-
}
|
|
40
|
-
}
|
|
41
|
-
/**
|
|
42
|
-
* @deprecated Import from `@morpho-org/morpho-ts`
|
|
43
|
-
*/
|
|
44
|
-
export declare abstract class BaseFormatter {
|
|
45
|
-
protected abstract _options: FormatOptions;
|
|
46
|
-
constructor();
|
|
47
|
-
of(value: bigint, decimals: number): string;
|
|
48
|
-
of(value: number): string;
|
|
49
|
-
}
|
|
50
|
-
/**
|
|
51
|
-
* @deprecated Import from `@morpho-org/morpho-ts`
|
|
52
|
-
*/
|
|
53
|
-
export declare class HexFormatter extends BaseFormatter {
|
|
54
|
-
protected _options: {
|
|
55
|
-
format: Format;
|
|
56
|
-
};
|
|
57
|
-
}
|
|
58
|
-
/**
|
|
59
|
-
* @deprecated Import from `@morpho-org/morpho-ts`
|
|
60
|
-
*/
|
|
61
|
-
export declare abstract class CommonFormatter extends BaseFormatter {
|
|
62
|
-
protected abstract _options: BaseFormatOptions;
|
|
63
|
-
digits(_d: number): this;
|
|
64
|
-
removeTrailingZero(): this;
|
|
65
|
-
readable(): this;
|
|
66
|
-
min(_m: number): this;
|
|
67
|
-
max(_m: number): this;
|
|
68
|
-
sign(): this;
|
|
69
|
-
unit(_u: string): this;
|
|
70
|
-
locale(_l: string): this;
|
|
71
|
-
}
|
|
72
|
-
/**
|
|
73
|
-
* @deprecated Import from `@morpho-org/morpho-ts`
|
|
74
|
-
*/
|
|
75
|
-
export declare class NumberFormatter extends CommonFormatter {
|
|
76
|
-
protected _options: FormatNumberOptions;
|
|
77
|
-
}
|
|
78
|
-
/**
|
|
79
|
-
* @deprecated Import from `@morpho-org/morpho-ts`
|
|
80
|
-
*/
|
|
81
|
-
export declare class CommasFormatter extends CommonFormatter {
|
|
82
|
-
protected _options: FormatCommasOptions;
|
|
83
|
-
}
|
|
84
|
-
/**
|
|
85
|
-
* @deprecated Import from `@morpho-org/morpho-ts`
|
|
86
|
-
*/
|
|
87
|
-
export declare class ShortFormatter extends CommonFormatter {
|
|
88
|
-
protected _options: FormatShortOptions;
|
|
89
|
-
smallValuesWithCommas(): this;
|
|
90
|
-
}
|
|
91
|
-
/**
|
|
92
|
-
* @deprecated Import from `@morpho-org/morpho-ts`
|
|
93
|
-
*/
|
|
94
|
-
export declare class PercentFormatter extends CommonFormatter {
|
|
95
|
-
protected _options: FormatPercentOptions;
|
|
96
|
-
}
|
|
97
|
-
/**
|
|
98
|
-
* @deprecated Import from `@morpho-org/morpho-ts`
|
|
99
|
-
*/
|
|
100
|
-
export declare const format: {
|
|
101
|
-
/**
|
|
102
|
-
* Return the value as an integer in hex format
|
|
103
|
-
*/
|
|
104
|
-
readonly hex: HexFormatter;
|
|
105
|
-
/**
|
|
106
|
-
* Return the value as a stringified number (12345.6789)
|
|
107
|
-
*/
|
|
108
|
-
readonly number: NumberFormatter;
|
|
109
|
-
/**
|
|
110
|
-
* Return the value as a commas-separated stringified number (12,345.6789)
|
|
111
|
-
*/
|
|
112
|
-
readonly commas: CommasFormatter;
|
|
113
|
-
/**
|
|
114
|
-
* Return the value as a shorted stringified number (12.3456789k)
|
|
115
|
-
*/
|
|
116
|
-
readonly short: ShortFormatter;
|
|
117
|
-
/**
|
|
118
|
-
* Return the value as a percent based stringified number (10.00 instead of 0.1)
|
|
119
|
-
*/
|
|
120
|
-
readonly percent: PercentFormatter;
|
|
121
|
-
};
|
|
122
|
-
export {};
|
|
@@ -1,286 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.format = exports.PercentFormatter = exports.ShortFormatter = exports.CommasFormatter = exports.NumberFormatter = exports.CommonFormatter = exports.HexFormatter = exports.BaseFormatter = void 0;
|
|
4
|
-
const locale_1 = require("../locale");
|
|
5
|
-
var Format;
|
|
6
|
-
(function (Format) {
|
|
7
|
-
Format["number"] = "number";
|
|
8
|
-
Format["commas"] = "commas";
|
|
9
|
-
Format["short"] = "short";
|
|
10
|
-
Format["hex"] = "hex";
|
|
11
|
-
Format["percent"] = "percent";
|
|
12
|
-
})(Format || (Format = {}));
|
|
13
|
-
String.prototype.insert = function (index, substr, fillWith) {
|
|
14
|
-
if (index < 0)
|
|
15
|
-
index = this.length + index;
|
|
16
|
-
let filler = "";
|
|
17
|
-
if (index < 0) {
|
|
18
|
-
if (fillWith)
|
|
19
|
-
filler = fillWith.repeat(-index).slice(index);
|
|
20
|
-
index = 0;
|
|
21
|
-
}
|
|
22
|
-
return this.slice(0, index) + substr + filler + this.slice(index);
|
|
23
|
-
};
|
|
24
|
-
const RANGES = [
|
|
25
|
-
{
|
|
26
|
-
minDecimals: 24,
|
|
27
|
-
symbol: "Y",
|
|
28
|
-
},
|
|
29
|
-
{
|
|
30
|
-
minDecimals: 21,
|
|
31
|
-
symbol: "Z",
|
|
32
|
-
},
|
|
33
|
-
{
|
|
34
|
-
minDecimals: 18,
|
|
35
|
-
symbol: "E",
|
|
36
|
-
},
|
|
37
|
-
{
|
|
38
|
-
minDecimals: 15,
|
|
39
|
-
symbol: "P",
|
|
40
|
-
},
|
|
41
|
-
{
|
|
42
|
-
minDecimals: 12,
|
|
43
|
-
symbol: "T",
|
|
44
|
-
},
|
|
45
|
-
{
|
|
46
|
-
minDecimals: 9,
|
|
47
|
-
symbol: "B",
|
|
48
|
-
},
|
|
49
|
-
{
|
|
50
|
-
minDecimals: 6,
|
|
51
|
-
symbol: "M",
|
|
52
|
-
},
|
|
53
|
-
{
|
|
54
|
-
minDecimals: 4,
|
|
55
|
-
power: 3,
|
|
56
|
-
symbol: "k",
|
|
57
|
-
},
|
|
58
|
-
];
|
|
59
|
-
const _formatShort = (bi, decimals, formatOptions) => {
|
|
60
|
-
const stringValue = bi.toString();
|
|
61
|
-
const params = RANGES.find((range) => stringValue.length > range.minDecimals + decimals);
|
|
62
|
-
if (params) {
|
|
63
|
-
return (_applyOptions(stringValue.insert(-((params.power ?? params.minDecimals) + decimals), ".", "0"), formatOptions) + params.symbol);
|
|
64
|
-
}
|
|
65
|
-
if (formatOptions.smallValuesWithCommas) {
|
|
66
|
-
return _formatCommas(bi, decimals, formatOptions);
|
|
67
|
-
}
|
|
68
|
-
return _applyOptions(stringValue.insert(-decimals, ".", "0"), formatOptions);
|
|
69
|
-
};
|
|
70
|
-
const _formatCommas = (bi, decimals, formatOptions) => {
|
|
71
|
-
const stringValue = decimals
|
|
72
|
-
? bi.toString().insert(-decimals, ".", "0")
|
|
73
|
-
: bi.toString();
|
|
74
|
-
const [wholePart, decimalPart] = stringValue.split(".");
|
|
75
|
-
return _applyOptions(wholePart
|
|
76
|
-
.split("")
|
|
77
|
-
.reduce((formattedNumber, digit, i, arr) => `${formattedNumber}${!i || (arr.length - i) % 3 ? "" : ","}${digit}`, "") + (decimalPart ? "." + decimalPart : ""), formatOptions);
|
|
78
|
-
};
|
|
79
|
-
const _formatNumber = (bi, decimals, formatOptions) => {
|
|
80
|
-
if (decimals === 0)
|
|
81
|
-
return _applyOptions(bi.toString(), formatOptions);
|
|
82
|
-
return _applyOptions(bi.toString().insert(-decimals, ".", "0"), formatOptions);
|
|
83
|
-
};
|
|
84
|
-
const _withUnit = (value, unit) => {
|
|
85
|
-
switch (unit) {
|
|
86
|
-
case "$":
|
|
87
|
-
return `$${value}`;
|
|
88
|
-
case "":
|
|
89
|
-
case "%":
|
|
90
|
-
return `${value}${unit}`;
|
|
91
|
-
default:
|
|
92
|
-
return `${value} ${unit}`;
|
|
93
|
-
}
|
|
94
|
-
};
|
|
95
|
-
const _applyOptions = (value, formatOptions) => {
|
|
96
|
-
let [wholePart, decimalPart = ""] = value.split(".");
|
|
97
|
-
const isZero = value.match(/[1-9]/)?.index === undefined;
|
|
98
|
-
if (formatOptions.digits !== undefined) {
|
|
99
|
-
decimalPart = decimalPart + "0".repeat(formatOptions.digits);
|
|
100
|
-
decimalPart = decimalPart.slice(0, formatOptions.digits);
|
|
101
|
-
}
|
|
102
|
-
if (formatOptions.removeTrailingZero) {
|
|
103
|
-
decimalPart = decimalPart.replace(/\.?0+$/, "");
|
|
104
|
-
}
|
|
105
|
-
value = (wholePart || "0") + (decimalPart ? "." + decimalPart : "");
|
|
106
|
-
const { value: _value, decimalSymbol } = (0, locale_1.getEnUSNumberToLocalParts)(value, formatOptions.locale);
|
|
107
|
-
value = _value;
|
|
108
|
-
const firstNonZero = value.match(/[1-9]/);
|
|
109
|
-
if (firstNonZero?.index === undefined &&
|
|
110
|
-
formatOptions.digits &&
|
|
111
|
-
!isZero &&
|
|
112
|
-
formatOptions.readable)
|
|
113
|
-
return `< 0${decimalSymbol}${"0".repeat(formatOptions.digits - 1)}1`;
|
|
114
|
-
return value;
|
|
115
|
-
};
|
|
116
|
-
function formatBI(bi, decimals, formatOptions = { format: Format.hex }) {
|
|
117
|
-
if (formatOptions.format === Format.hex)
|
|
118
|
-
return bi.toString(16);
|
|
119
|
-
if (formatOptions.max != null) {
|
|
120
|
-
const maxBI = BigInt(formatOptions.max.toFixed(decimals).replace(".", ""));
|
|
121
|
-
if (bi > maxBI)
|
|
122
|
-
return `> ${formatBI(maxBI, decimals, formatOptions)}`;
|
|
123
|
-
}
|
|
124
|
-
if (formatOptions.min != null) {
|
|
125
|
-
const minBI = BigInt(formatOptions.min.toFixed(decimals).replace(".", ""));
|
|
126
|
-
if (bi < minBI && bi !== 0n)
|
|
127
|
-
return `< ${formatBI(minBI, decimals, formatOptions)}`;
|
|
128
|
-
}
|
|
129
|
-
let value;
|
|
130
|
-
const isNegative = bi < 0n;
|
|
131
|
-
const absBI = bi > 0n ? bi : -bi;
|
|
132
|
-
switch (formatOptions.format) {
|
|
133
|
-
case Format.commas:
|
|
134
|
-
value = _formatCommas(absBI, decimals, formatOptions);
|
|
135
|
-
break;
|
|
136
|
-
case Format.number:
|
|
137
|
-
value = _formatNumber(absBI, decimals, formatOptions);
|
|
138
|
-
break;
|
|
139
|
-
case Format.short:
|
|
140
|
-
value = _formatShort(absBI, decimals, formatOptions);
|
|
141
|
-
break;
|
|
142
|
-
case Format.percent:
|
|
143
|
-
value = _formatNumber(absBI * 100n, decimals, formatOptions);
|
|
144
|
-
break;
|
|
145
|
-
}
|
|
146
|
-
const formattedValue = (isNegative && !/^0\.0+$/.test(value)
|
|
147
|
-
? "-"
|
|
148
|
-
: formatOptions.sign
|
|
149
|
-
? "+"
|
|
150
|
-
: "") + value;
|
|
151
|
-
if (formatOptions.unit) {
|
|
152
|
-
return _withUnit(formattedValue, formatOptions.unit);
|
|
153
|
-
}
|
|
154
|
-
return formattedValue;
|
|
155
|
-
}
|
|
156
|
-
/**
|
|
157
|
-
* @deprecated Import from `@morpho-org/morpho-ts`
|
|
158
|
-
*/
|
|
159
|
-
class BaseFormatter {
|
|
160
|
-
constructor() { }
|
|
161
|
-
of(value, decimals) {
|
|
162
|
-
if (typeof value === "number") {
|
|
163
|
-
const str = value.toString();
|
|
164
|
-
const [significant] = str.split(/[eE]/);
|
|
165
|
-
const [, digits = ""] = significant.split(".");
|
|
166
|
-
decimals =
|
|
167
|
-
Math.min(100, Math.max(0, Math.floor(-Math.log10(value)))) +
|
|
168
|
-
digits.length;
|
|
169
|
-
value = BigInt(value.toFixed(decimals).replace(".", ""));
|
|
170
|
-
}
|
|
171
|
-
return formatBI(value, decimals, this._options);
|
|
172
|
-
}
|
|
173
|
-
}
|
|
174
|
-
exports.BaseFormatter = BaseFormatter;
|
|
175
|
-
/**
|
|
176
|
-
* @deprecated Import from `@morpho-org/morpho-ts`
|
|
177
|
-
*/
|
|
178
|
-
class HexFormatter extends BaseFormatter {
|
|
179
|
-
_options = { format: Format.hex };
|
|
180
|
-
}
|
|
181
|
-
exports.HexFormatter = HexFormatter;
|
|
182
|
-
/**
|
|
183
|
-
* @deprecated Import from `@morpho-org/morpho-ts`
|
|
184
|
-
*/
|
|
185
|
-
class CommonFormatter extends BaseFormatter {
|
|
186
|
-
digits(_d) {
|
|
187
|
-
this._options.digits = _d;
|
|
188
|
-
return this;
|
|
189
|
-
}
|
|
190
|
-
removeTrailingZero() {
|
|
191
|
-
this._options.removeTrailingZero = true;
|
|
192
|
-
return this;
|
|
193
|
-
}
|
|
194
|
-
readable() {
|
|
195
|
-
this._options.readable = true;
|
|
196
|
-
return this;
|
|
197
|
-
}
|
|
198
|
-
min(_m) {
|
|
199
|
-
this._options.min = _m;
|
|
200
|
-
return this;
|
|
201
|
-
}
|
|
202
|
-
max(_m) {
|
|
203
|
-
this._options.max = _m;
|
|
204
|
-
return this;
|
|
205
|
-
}
|
|
206
|
-
sign() {
|
|
207
|
-
this._options.sign = true;
|
|
208
|
-
return this;
|
|
209
|
-
}
|
|
210
|
-
unit(_u) {
|
|
211
|
-
this._options.unit = _u;
|
|
212
|
-
return this;
|
|
213
|
-
}
|
|
214
|
-
locale(_l) {
|
|
215
|
-
this._options.locale = _l;
|
|
216
|
-
return this;
|
|
217
|
-
}
|
|
218
|
-
}
|
|
219
|
-
exports.CommonFormatter = CommonFormatter;
|
|
220
|
-
/**
|
|
221
|
-
* @deprecated Import from `@morpho-org/morpho-ts`
|
|
222
|
-
*/
|
|
223
|
-
class NumberFormatter extends CommonFormatter {
|
|
224
|
-
_options = { format: Format.number };
|
|
225
|
-
}
|
|
226
|
-
exports.NumberFormatter = NumberFormatter;
|
|
227
|
-
/**
|
|
228
|
-
* @deprecated Import from `@morpho-org/morpho-ts`
|
|
229
|
-
*/
|
|
230
|
-
class CommasFormatter extends CommonFormatter {
|
|
231
|
-
_options = { format: Format.commas };
|
|
232
|
-
}
|
|
233
|
-
exports.CommasFormatter = CommasFormatter;
|
|
234
|
-
/**
|
|
235
|
-
* @deprecated Import from `@morpho-org/morpho-ts`
|
|
236
|
-
*/
|
|
237
|
-
class ShortFormatter extends CommonFormatter {
|
|
238
|
-
_options = { format: Format.short };
|
|
239
|
-
smallValuesWithCommas() {
|
|
240
|
-
this._options.smallValuesWithCommas = true;
|
|
241
|
-
return this;
|
|
242
|
-
}
|
|
243
|
-
}
|
|
244
|
-
exports.ShortFormatter = ShortFormatter;
|
|
245
|
-
/**
|
|
246
|
-
* @deprecated Import from `@morpho-org/morpho-ts`
|
|
247
|
-
*/
|
|
248
|
-
class PercentFormatter extends CommonFormatter {
|
|
249
|
-
_options = { format: Format.percent };
|
|
250
|
-
}
|
|
251
|
-
exports.PercentFormatter = PercentFormatter;
|
|
252
|
-
/**
|
|
253
|
-
* @deprecated Import from `@morpho-org/morpho-ts`
|
|
254
|
-
*/
|
|
255
|
-
exports.format = {
|
|
256
|
-
/**
|
|
257
|
-
* Return the value as an integer in hex format
|
|
258
|
-
*/
|
|
259
|
-
get hex() {
|
|
260
|
-
return new HexFormatter();
|
|
261
|
-
},
|
|
262
|
-
/**
|
|
263
|
-
* Return the value as a stringified number (12345.6789)
|
|
264
|
-
*/
|
|
265
|
-
get number() {
|
|
266
|
-
return new NumberFormatter();
|
|
267
|
-
},
|
|
268
|
-
/**
|
|
269
|
-
* Return the value as a commas-separated stringified number (12,345.6789)
|
|
270
|
-
*/
|
|
271
|
-
get commas() {
|
|
272
|
-
return new CommasFormatter();
|
|
273
|
-
},
|
|
274
|
-
/**
|
|
275
|
-
* Return the value as a shorted stringified number (12.3456789k)
|
|
276
|
-
*/
|
|
277
|
-
get short() {
|
|
278
|
-
return new ShortFormatter();
|
|
279
|
-
},
|
|
280
|
-
/**
|
|
281
|
-
* Return the value as a percent based stringified number (10.00 instead of 0.1)
|
|
282
|
-
*/
|
|
283
|
-
get percent() {
|
|
284
|
-
return new PercentFormatter();
|
|
285
|
-
},
|
|
286
|
-
};
|
package/lib/helpers/locale.d.ts
DELETED
|
@@ -1,46 +0,0 @@
|
|
|
1
|
-
type LocaleSymbols = {
|
|
2
|
-
decimalSymbol: string;
|
|
3
|
-
groupSymbol: string;
|
|
4
|
-
locale: string;
|
|
5
|
-
};
|
|
6
|
-
export type LocaleParts = LocaleSymbols & {
|
|
7
|
-
value: string;
|
|
8
|
-
};
|
|
9
|
-
/**
|
|
10
|
-
* @returns the locale symbols for the given locale defaulting to en-US
|
|
11
|
-
*
|
|
12
|
-
* @deprecated Import from `@morpho-org/morpho-ts`
|
|
13
|
-
*/
|
|
14
|
-
export declare const getLocaleSymbols: (locale: string) => LocaleSymbols;
|
|
15
|
-
/**
|
|
16
|
-
* @returns the effective browser locale
|
|
17
|
-
*
|
|
18
|
-
* @deprecated Import from `@morpho-org/morpho-ts`
|
|
19
|
-
*/
|
|
20
|
-
export declare const getEffectiveLocale: () => string;
|
|
21
|
-
/**
|
|
22
|
-
* @returns the value as a string with the given locale symbols
|
|
23
|
-
* @param numStr the number as a string in the "from" locale (e.g. "1,2345.6" for en-US)
|
|
24
|
-
* @param from the locale the numStr is in (e.g. "en-US")
|
|
25
|
-
* @param to the locale to convert to (e.g. "fr-FR")
|
|
26
|
-
*
|
|
27
|
-
* @deprecated Import from `@morpho-org/morpho-ts`
|
|
28
|
-
*/
|
|
29
|
-
export declare const convertNumStrToLocal: (numStr: string, from: string, to: string) => string;
|
|
30
|
-
/**
|
|
31
|
-
* @returns the value as a string in the effective browser locale
|
|
32
|
-
* @param numStr the number as a string in the effective browser locale (e.g. "1,2345.6" for en-US)
|
|
33
|
-
* @param to the locale to use (e.g. "fr-FR")
|
|
34
|
-
*
|
|
35
|
-
* @deprecated Import from `@morpho-org/morpho-ts`
|
|
36
|
-
*/
|
|
37
|
-
export declare const convertNumStrFromEffectiveTo: (numStr: string, to: string) => string;
|
|
38
|
-
/**
|
|
39
|
-
* @returns the value as a string with the given locale symbols either from the given locale or the effective browser locale
|
|
40
|
-
* @param numStr the number as a string in english format (e.g. "1,2345.6")
|
|
41
|
-
* @param locale optional - the locale to use (e.g. "fr-FR")
|
|
42
|
-
*
|
|
43
|
-
* @deprecated Import from `@morpho-org/morpho-ts`
|
|
44
|
-
*/
|
|
45
|
-
export declare const getEnUSNumberToLocalParts: (numStr: string, locale?: string) => LocaleParts;
|
|
46
|
-
export {};
|
package/lib/helpers/locale.js
DELETED
|
@@ -1,96 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.getEnUSNumberToLocalParts = exports.convertNumStrFromEffectiveTo = exports.convertNumStrToLocal = exports.getEffectiveLocale = exports.getLocaleSymbols = void 0;
|
|
4
|
-
const _convertEnNumStrToLocale = (numStr, localSymbols) => {
|
|
5
|
-
return numStr
|
|
6
|
-
.replaceAll(",", "#TEMP#")
|
|
7
|
-
.replaceAll(".", localSymbols.decimalSymbol)
|
|
8
|
-
.replaceAll("#TEMP#", localSymbols.groupSymbol);
|
|
9
|
-
};
|
|
10
|
-
/**
|
|
11
|
-
* @returns the locale symbols for the given locale defaulting to en-US
|
|
12
|
-
*
|
|
13
|
-
* @deprecated Import from `@morpho-org/morpho-ts`
|
|
14
|
-
*/
|
|
15
|
-
const getLocaleSymbols = (locale) => {
|
|
16
|
-
let formatter;
|
|
17
|
-
const formatterOptions = {
|
|
18
|
-
useGrouping: true,
|
|
19
|
-
maximumFractionDigits: 1,
|
|
20
|
-
minimumFractionDigits: 1,
|
|
21
|
-
};
|
|
22
|
-
try {
|
|
23
|
-
formatter = new Intl.NumberFormat(locale, formatterOptions);
|
|
24
|
-
}
|
|
25
|
-
catch {
|
|
26
|
-
formatter = new Intl.NumberFormat("en-US", formatterOptions);
|
|
27
|
-
}
|
|
28
|
-
const parts = formatter.formatToParts(12345.6);
|
|
29
|
-
const decimalSymbol = parts.find((part) => part.type === "decimal").value;
|
|
30
|
-
const groupSymbol = parts.find((part) => part.type === "group").value;
|
|
31
|
-
return { decimalSymbol, groupSymbol, locale };
|
|
32
|
-
};
|
|
33
|
-
exports.getLocaleSymbols = getLocaleSymbols;
|
|
34
|
-
/**
|
|
35
|
-
* @returns the effective browser locale
|
|
36
|
-
*
|
|
37
|
-
* @deprecated Import from `@morpho-org/morpho-ts`
|
|
38
|
-
*/
|
|
39
|
-
const getEffectiveLocale = () => {
|
|
40
|
-
if (typeof window !== "undefined") {
|
|
41
|
-
try {
|
|
42
|
-
const locale = navigator?.language || document?.documentElement?.lang || "en-US";
|
|
43
|
-
new Intl.NumberFormat(locale);
|
|
44
|
-
return locale;
|
|
45
|
-
}
|
|
46
|
-
catch {
|
|
47
|
-
return "en-US";
|
|
48
|
-
}
|
|
49
|
-
}
|
|
50
|
-
return "en-US";
|
|
51
|
-
};
|
|
52
|
-
exports.getEffectiveLocale = getEffectiveLocale;
|
|
53
|
-
/**
|
|
54
|
-
* @returns the value as a string with the given locale symbols
|
|
55
|
-
* @param numStr the number as a string in the "from" locale (e.g. "1,2345.6" for en-US)
|
|
56
|
-
* @param from the locale the numStr is in (e.g. "en-US")
|
|
57
|
-
* @param to the locale to convert to (e.g. "fr-FR")
|
|
58
|
-
*
|
|
59
|
-
* @deprecated Import from `@morpho-org/morpho-ts`
|
|
60
|
-
*/
|
|
61
|
-
const convertNumStrToLocal = (numStr, from, to) => {
|
|
62
|
-
const fromSymbols = (0, exports.getLocaleSymbols)(from);
|
|
63
|
-
const toSymbols = (0, exports.getLocaleSymbols)(to);
|
|
64
|
-
return numStr
|
|
65
|
-
.replaceAll(fromSymbols.groupSymbol, "#GROUP#")
|
|
66
|
-
.replaceAll(fromSymbols.decimalSymbol, "#DECIMAL#")
|
|
67
|
-
.replaceAll("#GROUP#", toSymbols.groupSymbol)
|
|
68
|
-
.replaceAll("#DECIMAL#", toSymbols.decimalSymbol);
|
|
69
|
-
};
|
|
70
|
-
exports.convertNumStrToLocal = convertNumStrToLocal;
|
|
71
|
-
/**
|
|
72
|
-
* @returns the value as a string in the effective browser locale
|
|
73
|
-
* @param numStr the number as a string in the effective browser locale (e.g. "1,2345.6" for en-US)
|
|
74
|
-
* @param to the locale to use (e.g. "fr-FR")
|
|
75
|
-
*
|
|
76
|
-
* @deprecated Import from `@morpho-org/morpho-ts`
|
|
77
|
-
*/
|
|
78
|
-
const convertNumStrFromEffectiveTo = (numStr, to) => {
|
|
79
|
-
const from = (0, exports.getEffectiveLocale)();
|
|
80
|
-
return (0, exports.convertNumStrToLocal)(numStr, from, to);
|
|
81
|
-
};
|
|
82
|
-
exports.convertNumStrFromEffectiveTo = convertNumStrFromEffectiveTo;
|
|
83
|
-
/**
|
|
84
|
-
* @returns the value as a string with the given locale symbols either from the given locale or the effective browser locale
|
|
85
|
-
* @param numStr the number as a string in english format (e.g. "1,2345.6")
|
|
86
|
-
* @param locale optional - the locale to use (e.g. "fr-FR")
|
|
87
|
-
*
|
|
88
|
-
* @deprecated Import from `@morpho-org/morpho-ts`
|
|
89
|
-
*/
|
|
90
|
-
const getEnUSNumberToLocalParts = (numStr, locale) => {
|
|
91
|
-
const _locale = locale || (0, exports.getEffectiveLocale)();
|
|
92
|
-
const localSymbols = (0, exports.getLocaleSymbols)(_locale);
|
|
93
|
-
const value = _convertEnNumStrToLocale(numStr, localSymbols);
|
|
94
|
-
return { ...localSymbols, value };
|
|
95
|
-
};
|
|
96
|
-
exports.getEnUSNumberToLocalParts = getEnUSNumberToLocalParts;
|
package/lib/maths/index.d.ts
DELETED
package/lib/maths/index.js
DELETED
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
-
if (k2 === undefined) k2 = k;
|
|
4
|
-
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
-
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
-
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
-
}
|
|
8
|
-
Object.defineProperty(o, k2, desc);
|
|
9
|
-
}) : (function(o, m, k, k2) {
|
|
10
|
-
if (k2 === undefined) k2 = k;
|
|
11
|
-
o[k2] = m[k];
|
|
12
|
-
}));
|
|
13
|
-
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
-
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
-
};
|
|
16
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
-
__exportStar(require("./MathLib"), exports);
|
|
18
|
-
__exportStar(require("./SharesMath"), exports);
|
|
19
|
-
__exportStar(require("./AdaptiveCurveIrmLib"), exports);
|