@morpho-org/blue-sdk 2.0.0-test.1 → 2.1.0

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.
Files changed (85) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +46 -26
  3. package/lib/addresses.d.ts +59 -55
  4. package/lib/addresses.js +42 -43
  5. package/lib/chain.d.ts +1 -1
  6. package/lib/chain.js +3 -3
  7. package/lib/constants.d.ts +0 -9
  8. package/lib/constants.js +1 -10
  9. package/lib/errors.d.ts +7 -8
  10. package/lib/errors.js +21 -19
  11. package/lib/holding/AssetBalances.d.ts +3 -3
  12. package/lib/holding/Holding.d.ts +10 -5
  13. package/lib/holding/Holding.js +14 -4
  14. package/lib/holding/index.d.ts +2 -2
  15. package/lib/holding/index.js +2 -2
  16. package/lib/index.d.ts +12 -25
  17. package/lib/index.js +12 -38
  18. package/lib/market/Market.d.ts +48 -34
  19. package/lib/market/Market.js +76 -57
  20. package/lib/market/{MarketConfig.d.ts → MarketParams.d.ts} +8 -7
  21. package/lib/market/{MarketConfig.js → MarketParams.js} +20 -21
  22. package/lib/market/MarketUtils.d.ts +94 -42
  23. package/lib/market/MarketUtils.js +145 -67
  24. package/lib/market/index.d.ts +3 -3
  25. package/lib/market/index.js +3 -3
  26. package/lib/{maths → math}/AdaptiveCurveIrmLib.d.ts +1 -1
  27. package/lib/{maths → math}/AdaptiveCurveIrmLib.js +20 -20
  28. package/lib/{maths → math}/MathLib.d.ts +24 -42
  29. package/lib/{maths → math}/MathLib.js +41 -54
  30. package/lib/{maths → math}/SharesMath.d.ts +2 -2
  31. package/lib/{maths → math}/SharesMath.js +3 -3
  32. package/lib/math/index.d.ts +3 -0
  33. package/lib/{helpers/format → math}/index.js +3 -1
  34. package/lib/position/Position.d.ts +35 -25
  35. package/lib/position/Position.js +46 -44
  36. package/lib/position/index.d.ts +1 -1
  37. package/lib/position/index.js +1 -1
  38. package/lib/token/ConstantWrappedToken.d.ts +6 -7
  39. package/lib/token/ConstantWrappedToken.js +8 -10
  40. package/lib/token/ExchangeRateWrappedToken.d.ts +5 -5
  41. package/lib/token/ExchangeRateWrappedToken.js +5 -5
  42. package/lib/token/Token.d.ts +18 -18
  43. package/lib/token/Token.js +24 -27
  44. package/lib/token/VaultToken.d.ts +20 -11
  45. package/lib/token/VaultToken.js +15 -7
  46. package/lib/token/WrappedToken.d.ts +4 -4
  47. package/lib/token/WrappedToken.js +7 -7
  48. package/lib/token/index.d.ts +5 -5
  49. package/lib/token/index.js +5 -5
  50. package/lib/types.d.ts +3 -6
  51. package/lib/user/User.d.ts +1 -1
  52. package/lib/user/index.d.ts +1 -1
  53. package/lib/user/index.js +1 -1
  54. package/lib/vault/Vault.d.ts +22 -28
  55. package/lib/vault/Vault.js +43 -51
  56. package/lib/vault/VaultConfig.d.ts +6 -7
  57. package/lib/vault/VaultConfig.js +5 -5
  58. package/lib/vault/VaultMarketAllocation.d.ts +8 -8
  59. package/lib/vault/VaultMarketAllocation.js +3 -3
  60. package/lib/vault/VaultMarketConfig.d.ts +10 -10
  61. package/lib/vault/VaultMarketPublicAllocatorConfig.d.ts +6 -6
  62. package/lib/vault/VaultUser.d.ts +26 -0
  63. package/lib/vault/VaultUser.js +28 -0
  64. package/lib/vault/VaultUtils.d.ts +4 -6
  65. package/lib/vault/VaultUtils.js +6 -6
  66. package/lib/vault/index.d.ts +7 -6
  67. package/lib/vault/index.js +7 -6
  68. package/package.json +25 -56
  69. package/lib/chain.test.d.ts +0 -1
  70. package/lib/chain.test.js +0 -21
  71. package/lib/helpers/format/format.d.ts +0 -122
  72. package/lib/helpers/format/format.js +0 -286
  73. package/lib/helpers/format/format.test.d.ts +0 -1
  74. package/lib/helpers/format/format.test.js +0 -255
  75. package/lib/helpers/format/index.d.ts +0 -1
  76. package/lib/helpers/index.d.ts +0 -2
  77. package/lib/helpers/index.js +0 -18
  78. package/lib/helpers/locale.d.ts +0 -46
  79. package/lib/helpers/locale.js +0 -96
  80. package/lib/market/MarketUtils.test.d.ts +0 -1
  81. package/lib/market/MarketUtils.test.js +0 -38
  82. package/lib/maths/index.d.ts +0 -3
  83. package/lib/maths/index.js +0 -19
  84. package/lib/tests/mocks/markets.d.ts +0 -19
  85. package/lib/tests/mocks/markets.js +0 -121
package/package.json CHANGED
@@ -1,70 +1,39 @@
1
1
  {
2
2
  "name": "@morpho-org/blue-sdk",
3
- "version": "2.0.0-test.1",
3
+ "description": "Framework-agnostic package that defines Morpho-related entity classes (such as `Market`, `Token`, `Vault`).",
4
+ "version": "2.1.0",
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",
6
16
  "main": "lib/index.js",
7
17
  "files": [
8
18
  "lib"
9
19
  ],
10
- "scripts": {
11
- "prepublish": "yarn build",
12
- "build": "tsc --build tsconfig.build.json",
13
- "test-jest": "jest",
14
- "test-hardhat": "hardhat test"
15
- },
16
20
  "dependencies": {
17
- "keccak256": "^1.0.6"
18
- },
19
- "devDependencies": {
20
- "@morpho-org/morpho-test": "^2.0.0-test.1",
21
- "@morpho-org/morpho-ts": "^2.0.0-test.1",
22
- "@nomicfoundation/hardhat-ethers": "^3.0.6",
23
- "@nomicfoundation/hardhat-network-helpers": "^1.0.11",
24
- "@types/chai": "^4.3.14",
25
- "@types/chai-as-promised": "^7.1.2",
26
- "@types/jest": "^29.5.12",
27
- "@types/mocha": "^10.0.6",
28
- "@types/node": "^22.1.0",
29
- "chai": "^4.3.10",
30
- "chai-as-promised": "^7.1.2",
31
- "chai-ts": "^0.0.3",
32
- "dotenv": "^16.4.5",
33
- "ethers": "^6.13.2",
34
- "ethers-types": "^3.17.0",
35
- "hardhat": "^2.22.6",
36
- "hardhat-deal": "^3.1.0",
37
- "hardhat-tracer": "^3.1.0",
38
- "jest": "^29.7.0",
39
- "mocha": "^10.4.0",
40
- "ts-jest": "^29.2.4",
41
- "ts-node": "^10.9.2",
42
- "typescript": "^5.4.5"
21
+ "@noble/hashes": "^1.5.0"
43
22
  },
44
23
  "peerDependencies": {
45
- "@morpho-org/morpho-ts": "^2.0.0-test.1"
24
+ "@morpho-org/morpho-ts": "^2.0.0"
46
25
  },
47
- "publishConfig": {
48
- "access": "public"
26
+ "devDependencies": {
27
+ "typescript": "^5.7.2",
28
+ "viem": "^2.21.54",
29
+ "vitest": "^2.1.8",
30
+ "@morpho-org/morpho-ts": "^2.0.0",
31
+ "@morpho-org/test": "^2.0.0"
49
32
  },
50
- "jest": {
51
- "verbose": true,
52
- "testTimeout": 15000,
53
- "maxWorkers": 1,
54
- "transform": {
55
- "^.+\\.tsx?$": [
56
- "ts-jest",
57
- {
58
- "tsconfig": "tsconfig.json"
59
- }
60
- ]
61
- },
62
- "testRegex": "(/src/.*|(\\.|/)(test|spec)+)\\.test\\.(jsx?|tsx?)$",
63
- "moduleFileExtensions": [
64
- "js",
65
- "ts"
66
- ],
67
- "preset": "ts-jest"
33
+ "scripts": {
34
+ "prepublish": "$npm_execpath build",
35
+ "build": "tsc --build tsconfig.build.json",
36
+ "test": "vitest"
68
37
  },
69
- "gitHead": "c435f8f652383995fd6bb52379d0b570138e43d9"
70
- }
38
+ "types": "lib/index.d.ts"
39
+ }
@@ -1 +0,0 @@
1
- export {};
package/lib/chain.test.js DELETED
@@ -1,21 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- const morpho_ts_1 = require("@morpho-org/morpho-ts");
4
- const chain_1 = require("./chain");
5
- describe("Network", () => {
6
- it("Should have consistent chainIds", () => {
7
- (0, morpho_ts_1.entries)(chain_1.ChainUtils.CHAIN_METADATA).forEach(([chainId, { id }]) => {
8
- expect(+chainId).toEqual(id);
9
- });
10
- });
11
- it("Should have Testnet in the name for testnet chains", () => {
12
- Object.values(chain_1.ChainUtils.CHAIN_METADATA)
13
- .filter(({ isTestnet }) => isTestnet)
14
- .forEach(({ name }) => {
15
- expect(name).toMatch(/Testnet/);
16
- });
17
- });
18
- it("Should convert correctly a chainId to hexChainId", () => {
19
- expect(chain_1.ChainUtils.toHexChainId(chain_1.ChainId.BaseMainnet)).toEqual("0x2105");
20
- });
21
- });
@@ -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
- };
@@ -1 +0,0 @@
1
- export {};