@morpho-org/blue-sdk 6.1.0 → 6.3.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 (37) hide show
  1. package/lib/cjs/addresses.d.ts +2 -2768
  2. package/lib/cjs/addresses.js +17 -1627
  3. package/lib/cjs/chain.d.ts +2 -576
  4. package/lib/cjs/chain.js +3 -415
  5. package/lib/cjs/constants.d.ts +1 -1
  6. package/lib/cjs/constants.js +1 -1
  7. package/lib/cjs/errors.d.ts +5 -20
  8. package/lib/cjs/errors.js +16 -31
  9. package/lib/cjs/math/AdaptiveCurveIrmLib.js +1 -1
  10. package/lib/cjs/math/MathLib.d.ts +2 -250
  11. package/lib/cjs/math/MathLib.js +2 -329
  12. package/lib/cjs/token/Eip5267Domain.d.ts +1 -1
  13. package/lib/cjs/types.d.ts +2 -1
  14. package/lib/cjs/vault/Vault.d.ts +2 -0
  15. package/lib/cjs/vault/Vault.js +12 -1
  16. package/lib/cjs/vault/VaultUtils.js +2 -2
  17. package/lib/cjs/vault/v2/VaultV2MorphoMarketV1Adapter.js +1 -1
  18. package/lib/cjs/vault/v2/VaultV2MorphoMarketV1AdapterV2.js +1 -1
  19. package/lib/esm/addresses.d.ts +2 -2768
  20. package/lib/esm/addresses.js +1 -1619
  21. package/lib/esm/chain.d.ts +2 -576
  22. package/lib/esm/chain.js +1 -415
  23. package/lib/esm/constants.d.ts +1 -1
  24. package/lib/esm/constants.js +2 -2
  25. package/lib/esm/errors.d.ts +5 -20
  26. package/lib/esm/errors.js +7 -28
  27. package/lib/esm/math/AdaptiveCurveIrmLib.js +1 -1
  28. package/lib/esm/math/MathLib.d.ts +2 -250
  29. package/lib/esm/math/MathLib.js +1 -329
  30. package/lib/esm/token/Eip5267Domain.d.ts +1 -1
  31. package/lib/esm/types.d.ts +2 -1
  32. package/lib/esm/vault/Vault.d.ts +2 -0
  33. package/lib/esm/vault/Vault.js +12 -1
  34. package/lib/esm/vault/VaultUtils.js +2 -2
  35. package/lib/esm/vault/v2/VaultV2MorphoMarketV1Adapter.js +1 -1
  36. package/lib/esm/vault/v2/VaultV2MorphoMarketV1AdapterV2.js +1 -1
  37. package/package.json +6 -10
@@ -1,250 +1,2 @@
1
- import type { BigIntish } from "../types.js";
2
- /** Rounding direction used by fixed-point math helpers. */
3
- export type RoundingDirection = "Up" | "Down";
4
- /**
5
- * Library to manage fixed-point arithmetic.
6
- * https://github.com/morpho-org/morpho-blue/blob/main/src/libraries/MathLib.sol
7
- */
8
- export declare namespace MathLib {
9
- /** WAD scale used for 18-decimal fixed-point values. */
10
- const WAD = 1000000000000000000n;
11
- /** RAY scale used for 27-decimal fixed-point values. */
12
- const RAY = 1000000000000000000000000000n;
13
- /** Maximum unsigned integer representable with 256 bits. */
14
- const MAX_UINT_256: bigint;
15
- /** Maximum unsigned integer representable with 160 bits. */
16
- const MAX_UINT_160: bigint;
17
- /** Maximum unsigned integer representable with 128 bits. */
18
- const MAX_UINT_128: bigint;
19
- /** Maximum unsigned integer representable with 48 bits. */
20
- const MAX_UINT_48: bigint;
21
- /**
22
- * Returns the maximum unsigned integer representable with a bit width.
23
- *
24
- * @param nBits - The bit width, which must be divisible by 4.
25
- * @returns The maximum unsigned integer representable by `nBits`.
26
- * @example
27
- * ```ts
28
- * import { MathLib } from "@morpho-org/blue-sdk";
29
- *
30
- * const max = MathLib.maxUint(8);
31
- * // max === 255n
32
- * ```
33
- */
34
- function maxUint(nBits: number): bigint;
35
- /**
36
- * Returns the absolute value of a number
37
- * @param a The number
38
- * @returns The absolute value as a bigint.
39
- * @example
40
- * ```ts
41
- * import { MathLib } from "@morpho-org/blue-sdk";
42
- *
43
- * const value = MathLib.abs(-2n);
44
- * // value === 2n
45
- * ```
46
- */
47
- function abs(a: BigIntish): bigint;
48
- /**
49
- * Returns the smallest number given as param
50
- * @param xs The numbers to compare.
51
- * @returns The smallest value as a bigint.
52
- * @example
53
- * ```ts
54
- * import { MathLib } from "@morpho-org/blue-sdk";
55
- *
56
- * const value = MathLib.min(2n, 1n, 3n);
57
- * // value === 1n
58
- * ```
59
- */
60
- function min(...xs: BigIntish[]): bigint;
61
- /**
62
- * Returns the greatest number given as param
63
- * @param xs The numbers to compare.
64
- * @returns The greatest value as a bigint.
65
- * @example
66
- * ```ts
67
- * import { MathLib } from "@morpho-org/blue-sdk";
68
- *
69
- * const value = MathLib.max(2n, 1n, 3n);
70
- * // value === 3n
71
- * ```
72
- */
73
- function max(...xs: BigIntish[]): bigint;
74
- /**
75
- * Returns the subtraction of b from a, floored to zero if negative
76
- * @param x The first number
77
- * @param y The second number
78
- * @returns `x - y`, floored to `0n`.
79
- * @example
80
- * ```ts
81
- * import { MathLib } from "@morpho-org/blue-sdk";
82
- *
83
- * const value = MathLib.zeroFloorSub(1n, 2n);
84
- * // value === 0n
85
- * ```
86
- */
87
- function zeroFloorSub(x: BigIntish, y: BigIntish): bigint;
88
- /**
89
- * Perform the WAD-based multiplication of 2 numbers, rounded down
90
- * @param x The first number
91
- * @param y The second number
92
- * @returns The WAD-scaled product rounded down.
93
- * @example
94
- * ```ts
95
- * import { MathLib } from "@morpho-org/blue-sdk";
96
- *
97
- * const value = MathLib.wMulDown(MathLib.WAD, 2n * MathLib.WAD);
98
- * // value === 2n * MathLib.WAD
99
- * ```
100
- */
101
- function wMulDown(x: BigIntish, y: BigIntish): bigint;
102
- /**
103
- * Perform the WAD-based multiplication of 2 numbers, rounded up
104
- * @param x The first number
105
- * @param y The second number
106
- * @returns The WAD-scaled product rounded up.
107
- * @example
108
- * ```ts
109
- * import { MathLib } from "@morpho-org/blue-sdk";
110
- *
111
- * const value = MathLib.wMulUp(1n, MathLib.WAD);
112
- * // value === 1n
113
- * ```
114
- */
115
- function wMulUp(x: BigIntish, y: BigIntish): bigint;
116
- /**
117
- * Perform the WAD-based multiplication of 2 numbers with a provided rounding direction
118
- * @param x The first number
119
- * @param y The second number
120
- * @param rounding The rounding direction.
121
- * @returns The WAD-scaled product rounded as requested.
122
- * @example
123
- * ```ts
124
- * import { MathLib } from "@morpho-org/blue-sdk";
125
- *
126
- * const value = MathLib.wMul(MathLib.WAD, MathLib.WAD, "Down");
127
- * // value === MathLib.WAD
128
- * ```
129
- */
130
- function wMul(x: BigIntish, y: BigIntish, rounding: RoundingDirection): bigint;
131
- /**
132
- * Perform the WAD-based division of 2 numbers, rounded down
133
- * @param x The first number
134
- * @param y The second number
135
- * @returns The WAD-scaled quotient rounded down.
136
- * @example
137
- * ```ts
138
- * import { MathLib } from "@morpho-org/blue-sdk";
139
- *
140
- * const value = MathLib.wDivDown(MathLib.WAD, 2n * MathLib.WAD);
141
- * // value === 500000000000000000n
142
- * ```
143
- */
144
- function wDivDown(x: BigIntish, y: BigIntish): bigint;
145
- /**
146
- * Perform the WAD-based multiplication of 2 numbers, rounded up
147
- * @param x The first number
148
- * @param y The second number
149
- * @returns The WAD-scaled quotient rounded up.
150
- * @example
151
- * ```ts
152
- * import { MathLib } from "@morpho-org/blue-sdk";
153
- *
154
- * const value = MathLib.wDivUp(MathLib.WAD, 2n * MathLib.WAD);
155
- * // value === 500000000000000000n
156
- * ```
157
- */
158
- function wDivUp(x: BigIntish, y: BigIntish): bigint;
159
- /**
160
- * Perform the WAD-based multiplication of 2 numbers with a provided rounding direction
161
- * @param x The first number
162
- * @param y The second number
163
- * @param rounding The rounding direction.
164
- * @returns The WAD-scaled quotient rounded as requested.
165
- * @example
166
- * ```ts
167
- * import { MathLib } from "@morpho-org/blue-sdk";
168
- *
169
- * const value = MathLib.wDiv(MathLib.WAD, MathLib.WAD, "Down");
170
- * // value === MathLib.WAD
171
- * ```
172
- */
173
- function wDiv(x: BigIntish, y: BigIntish, rounding: RoundingDirection): bigint;
174
- /**
175
- * Multiply two numbers and divide by a denominator, rounding down the result
176
- * @param x The first number
177
- * @param y The second number
178
- * @param denominator The denominator
179
- * @returns `x * y / denominator`, rounded down.
180
- * @example
181
- * ```ts
182
- * import { MathLib } from "@morpho-org/blue-sdk";
183
- *
184
- * const value = MathLib.mulDivDown(5n, 2n, 3n);
185
- * // value === 3n
186
- * ```
187
- */
188
- function mulDivDown(x: BigIntish, y: BigIntish, denominator: BigIntish): bigint;
189
- /**
190
- * Multiply two numbers and divide by a denominator, rounding up the result
191
- * @param x The first number
192
- * @param y The second number
193
- * @param denominator The denominator
194
- * @returns `x * y / denominator`, rounded up.
195
- * @example
196
- * ```ts
197
- * import { MathLib } from "@morpho-org/blue-sdk";
198
- *
199
- * const value = MathLib.mulDivUp(5n, 2n, 3n);
200
- * // value === 4n
201
- * ```
202
- */
203
- function mulDivUp(x: BigIntish, y: BigIntish, denominator: BigIntish): bigint;
204
- /**
205
- * Multiplies two numbers and divides by a denominator.
206
- *
207
- * @param x - The first number.
208
- * @param y - The second number.
209
- * @param denominator - The denominator.
210
- * @param rounding - The rounding direction.
211
- * @returns `x * y / denominator`, rounded as requested.
212
- * @example
213
- * ```ts
214
- * import { MathLib } from "@morpho-org/blue-sdk";
215
- *
216
- * const value = MathLib.mulDiv(5n, 2n, 3n, "Down");
217
- * // value === 3n
218
- * ```
219
- */
220
- function mulDiv(x: BigIntish, y: BigIntish, denominator: BigIntish, rounding: RoundingDirection): bigint;
221
- /**
222
- * The sum of the first three non-zero terms of a Taylor expansion of e^(nx) - 1,
223
- * to approximate a continuously compounded interest rate.
224
- *
225
- * @param x The base of the exponent
226
- * @param n The exponent
227
- * @returns The WAD-scaled compounded rate approximation.
228
- * @example
229
- * ```ts
230
- * import { MathLib } from "@morpho-org/blue-sdk";
231
- *
232
- * const compounded = MathLib.wTaylorCompounded(1n, 1n);
233
- * // compounded satisfies bigint
234
- * ```
235
- */
236
- function wTaylorCompounded(x: BigIntish, n: BigIntish): bigint;
237
- /**
238
- * Converts a WAD-based quantity to a RAY-based quantity.
239
- * @param x The WAD-based quantity.
240
- * @returns The same quantity scaled to RAY precision.
241
- * @example
242
- * ```ts
243
- * import { MathLib } from "@morpho-org/blue-sdk";
244
- *
245
- * const ray = MathLib.wToRay(MathLib.WAD);
246
- * // ray === MathLib.RAY
247
- * ```
248
- */
249
- function wToRay(x: BigIntish): bigint;
250
- }
1
+ export type { RoundingDirection } from "@morpho-org/morpho-ts";
2
+ export { MathLib } from "@morpho-org/morpho-ts";
@@ -1,332 +1,5 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.MathLib = void 0;
4
- /**
5
- * Library to manage fixed-point arithmetic.
6
- * https://github.com/morpho-org/morpho-blue/blob/main/src/libraries/MathLib.sol
7
- */
8
- var MathLib;
9
- (function (MathLib) {
10
- /** WAD scale used for 18-decimal fixed-point values. */
11
- MathLib.WAD = 1000000000000000000n;
12
- /** RAY scale used for 27-decimal fixed-point values. */
13
- MathLib.RAY = 1000000000000000000000000000n;
14
- /** Maximum unsigned integer representable with 256 bits. */
15
- MathLib.MAX_UINT_256 = maxUint(256);
16
- /** Maximum unsigned integer representable with 160 bits. */
17
- MathLib.MAX_UINT_160 = maxUint(160);
18
- /** Maximum unsigned integer representable with 128 bits. */
19
- MathLib.MAX_UINT_128 = maxUint(128);
20
- /** Maximum unsigned integer representable with 48 bits. */
21
- MathLib.MAX_UINT_48 = maxUint(48);
22
- /**
23
- * Returns the maximum unsigned integer representable with a bit width.
24
- *
25
- * @param nBits - The bit width, which must be divisible by 4.
26
- * @returns The maximum unsigned integer representable by `nBits`.
27
- * @example
28
- * ```ts
29
- * import { MathLib } from "@morpho-org/blue-sdk";
30
- *
31
- * const max = MathLib.maxUint(8);
32
- * // max === 255n
33
- * ```
34
- */
35
- function maxUint(nBits) {
36
- if (nBits % 4 !== 0)
37
- throw new Error(`Invalid number of bits: ${nBits}`);
38
- return BigInt(`0x${"f".repeat(nBits / 4)}`);
39
- }
40
- MathLib.maxUint = maxUint;
41
- /**
42
- * Returns the absolute value of a number
43
- * @param a The number
44
- * @returns The absolute value as a bigint.
45
- * @example
46
- * ```ts
47
- * import { MathLib } from "@morpho-org/blue-sdk";
48
- *
49
- * const value = MathLib.abs(-2n);
50
- * // value === 2n
51
- * ```
52
- */
53
- function abs(a) {
54
- // biome-ignore lint/style/noParameterAssign: TODO refactor to avoid mutating parameter
55
- a = BigInt(a);
56
- return a >= 0 ? a : -a;
57
- }
58
- MathLib.abs = abs;
59
- /**
60
- * Returns the smallest number given as param
61
- * @param xs The numbers to compare.
62
- * @returns The smallest value as a bigint.
63
- * @example
64
- * ```ts
65
- * import { MathLib } from "@morpho-org/blue-sdk";
66
- *
67
- * const value = MathLib.min(2n, 1n, 3n);
68
- * // value === 1n
69
- * ```
70
- */
71
- function min(...xs) {
72
- return xs.map(BigInt).reduce((x, y) => (x <= y ? x : y));
73
- }
74
- MathLib.min = min;
75
- /**
76
- * Returns the greatest number given as param
77
- * @param xs The numbers to compare.
78
- * @returns The greatest value as a bigint.
79
- * @example
80
- * ```ts
81
- * import { MathLib } from "@morpho-org/blue-sdk";
82
- *
83
- * const value = MathLib.max(2n, 1n, 3n);
84
- * // value === 3n
85
- * ```
86
- */
87
- function max(...xs) {
88
- return xs.map(BigInt).reduce((x, y) => (x <= y ? y : x));
89
- }
90
- MathLib.max = max;
91
- /**
92
- * Returns the subtraction of b from a, floored to zero if negative
93
- * @param x The first number
94
- * @param y The second number
95
- * @returns `x - y`, floored to `0n`.
96
- * @example
97
- * ```ts
98
- * import { MathLib } from "@morpho-org/blue-sdk";
99
- *
100
- * const value = MathLib.zeroFloorSub(1n, 2n);
101
- * // value === 0n
102
- * ```
103
- */
104
- function zeroFloorSub(x, y) {
105
- // biome-ignore lint/style/noParameterAssign: TODO refactor to avoid mutating parameter
106
- x = BigInt(x);
107
- // biome-ignore lint/style/noParameterAssign: TODO refactor to avoid mutating parameter
108
- y = BigInt(y);
109
- return x <= y ? 0n : x - y;
110
- }
111
- MathLib.zeroFloorSub = zeroFloorSub;
112
- /**
113
- * Perform the WAD-based multiplication of 2 numbers, rounded down
114
- * @param x The first number
115
- * @param y The second number
116
- * @returns The WAD-scaled product rounded down.
117
- * @example
118
- * ```ts
119
- * import { MathLib } from "@morpho-org/blue-sdk";
120
- *
121
- * const value = MathLib.wMulDown(MathLib.WAD, 2n * MathLib.WAD);
122
- * // value === 2n * MathLib.WAD
123
- * ```
124
- */
125
- function wMulDown(x, y) {
126
- return MathLib.wMul(x, y, "Down");
127
- }
128
- MathLib.wMulDown = wMulDown;
129
- /**
130
- * Perform the WAD-based multiplication of 2 numbers, rounded up
131
- * @param x The first number
132
- * @param y The second number
133
- * @returns The WAD-scaled product rounded up.
134
- * @example
135
- * ```ts
136
- * import { MathLib } from "@morpho-org/blue-sdk";
137
- *
138
- * const value = MathLib.wMulUp(1n, MathLib.WAD);
139
- * // value === 1n
140
- * ```
141
- */
142
- function wMulUp(x, y) {
143
- return MathLib.wMul(x, y, "Up");
144
- }
145
- MathLib.wMulUp = wMulUp;
146
- /**
147
- * Perform the WAD-based multiplication of 2 numbers with a provided rounding direction
148
- * @param x The first number
149
- * @param y The second number
150
- * @param rounding The rounding direction.
151
- * @returns The WAD-scaled product rounded as requested.
152
- * @example
153
- * ```ts
154
- * import { MathLib } from "@morpho-org/blue-sdk";
155
- *
156
- * const value = MathLib.wMul(MathLib.WAD, MathLib.WAD, "Down");
157
- * // value === MathLib.WAD
158
- * ```
159
- */
160
- // biome-ignore lint/complexity/useMaxParams: TODO refactor to ≤2 params
161
- function wMul(x, y, rounding) {
162
- return MathLib.mulDiv(x, y, MathLib.WAD, rounding);
163
- }
164
- MathLib.wMul = wMul;
165
- /**
166
- * Perform the WAD-based division of 2 numbers, rounded down
167
- * @param x The first number
168
- * @param y The second number
169
- * @returns The WAD-scaled quotient rounded down.
170
- * @example
171
- * ```ts
172
- * import { MathLib } from "@morpho-org/blue-sdk";
173
- *
174
- * const value = MathLib.wDivDown(MathLib.WAD, 2n * MathLib.WAD);
175
- * // value === 500000000000000000n
176
- * ```
177
- */
178
- function wDivDown(x, y) {
179
- return MathLib.wDiv(x, y, "Down");
180
- }
181
- MathLib.wDivDown = wDivDown;
182
- /**
183
- * Perform the WAD-based multiplication of 2 numbers, rounded up
184
- * @param x The first number
185
- * @param y The second number
186
- * @returns The WAD-scaled quotient rounded up.
187
- * @example
188
- * ```ts
189
- * import { MathLib } from "@morpho-org/blue-sdk";
190
- *
191
- * const value = MathLib.wDivUp(MathLib.WAD, 2n * MathLib.WAD);
192
- * // value === 500000000000000000n
193
- * ```
194
- */
195
- function wDivUp(x, y) {
196
- return MathLib.wDiv(x, y, "Up");
197
- }
198
- MathLib.wDivUp = wDivUp;
199
- /**
200
- * Perform the WAD-based multiplication of 2 numbers with a provided rounding direction
201
- * @param x The first number
202
- * @param y The second number
203
- * @param rounding The rounding direction.
204
- * @returns The WAD-scaled quotient rounded as requested.
205
- * @example
206
- * ```ts
207
- * import { MathLib } from "@morpho-org/blue-sdk";
208
- *
209
- * const value = MathLib.wDiv(MathLib.WAD, MathLib.WAD, "Down");
210
- * // value === MathLib.WAD
211
- * ```
212
- */
213
- // biome-ignore lint/complexity/useMaxParams: TODO refactor to ≤2 params
214
- function wDiv(x, y, rounding) {
215
- return MathLib.mulDiv(x, MathLib.WAD, y, rounding);
216
- }
217
- MathLib.wDiv = wDiv;
218
- /**
219
- * Multiply two numbers and divide by a denominator, rounding down the result
220
- * @param x The first number
221
- * @param y The second number
222
- * @param denominator The denominator
223
- * @returns `x * y / denominator`, rounded down.
224
- * @example
225
- * ```ts
226
- * import { MathLib } from "@morpho-org/blue-sdk";
227
- *
228
- * const value = MathLib.mulDivDown(5n, 2n, 3n);
229
- * // value === 3n
230
- * ```
231
- */
232
- // biome-ignore lint/complexity/useMaxParams: TODO refactor to ≤2 params
233
- function mulDivDown(x, y, denominator) {
234
- // biome-ignore lint/style/noParameterAssign: TODO refactor to avoid mutating parameter
235
- x = BigInt(x);
236
- // biome-ignore lint/style/noParameterAssign: TODO refactor to avoid mutating parameter
237
- y = BigInt(y);
238
- // biome-ignore lint/style/noParameterAssign: TODO refactor to avoid mutating parameter
239
- denominator = BigInt(denominator);
240
- if (denominator === 0n)
241
- throw Error("MathLib: DIVISION_BY_ZERO");
242
- return (x * y) / denominator;
243
- }
244
- MathLib.mulDivDown = mulDivDown;
245
- /**
246
- * Multiply two numbers and divide by a denominator, rounding up the result
247
- * @param x The first number
248
- * @param y The second number
249
- * @param denominator The denominator
250
- * @returns `x * y / denominator`, rounded up.
251
- * @example
252
- * ```ts
253
- * import { MathLib } from "@morpho-org/blue-sdk";
254
- *
255
- * const value = MathLib.mulDivUp(5n, 2n, 3n);
256
- * // value === 4n
257
- * ```
258
- */
259
- // biome-ignore lint/complexity/useMaxParams: TODO refactor to ≤2 params
260
- function mulDivUp(x, y, denominator) {
261
- // biome-ignore lint/style/noParameterAssign: TODO refactor to avoid mutating parameter
262
- x = BigInt(x);
263
- // biome-ignore lint/style/noParameterAssign: TODO refactor to avoid mutating parameter
264
- y = BigInt(y);
265
- // biome-ignore lint/style/noParameterAssign: TODO refactor to avoid mutating parameter
266
- denominator = BigInt(denominator);
267
- if (denominator === 0n)
268
- throw Error("MathLib: DIVISION_BY_ZERO");
269
- const roundup = (x * y) % denominator > 0 ? 1n : 0n;
270
- return (x * y) / denominator + roundup;
271
- }
272
- MathLib.mulDivUp = mulDivUp;
273
- /**
274
- * Multiplies two numbers and divides by a denominator.
275
- *
276
- * @param x - The first number.
277
- * @param y - The second number.
278
- * @param denominator - The denominator.
279
- * @param rounding - The rounding direction.
280
- * @returns `x * y / denominator`, rounded as requested.
281
- * @example
282
- * ```ts
283
- * import { MathLib } from "@morpho-org/blue-sdk";
284
- *
285
- * const value = MathLib.mulDiv(5n, 2n, 3n, "Down");
286
- * // value === 3n
287
- * ```
288
- */
289
- // biome-ignore lint/complexity/useMaxParams: TODO refactor to ≤2 params
290
- function mulDiv(x, y, denominator, rounding) {
291
- return MathLib[`mulDiv${rounding}`](x, y, denominator);
292
- }
293
- MathLib.mulDiv = mulDiv;
294
- /**
295
- * The sum of the first three non-zero terms of a Taylor expansion of e^(nx) - 1,
296
- * to approximate a continuously compounded interest rate.
297
- *
298
- * @param x The base of the exponent
299
- * @param n The exponent
300
- * @returns The WAD-scaled compounded rate approximation.
301
- * @example
302
- * ```ts
303
- * import { MathLib } from "@morpho-org/blue-sdk";
304
- *
305
- * const compounded = MathLib.wTaylorCompounded(1n, 1n);
306
- * // compounded satisfies bigint
307
- * ```
308
- */
309
- function wTaylorCompounded(x, n) {
310
- const firstTerm = BigInt(x) * BigInt(n);
311
- const secondTerm = MathLib.mulDivDown(firstTerm, firstTerm, 2n * MathLib.WAD);
312
- const thirdTerm = MathLib.mulDivDown(secondTerm, firstTerm, 3n * MathLib.WAD);
313
- return firstTerm + secondTerm + thirdTerm;
314
- }
315
- MathLib.wTaylorCompounded = wTaylorCompounded;
316
- /**
317
- * Converts a WAD-based quantity to a RAY-based quantity.
318
- * @param x The WAD-based quantity.
319
- * @returns The same quantity scaled to RAY precision.
320
- * @example
321
- * ```ts
322
- * import { MathLib } from "@morpho-org/blue-sdk";
323
- *
324
- * const ray = MathLib.wToRay(MathLib.WAD);
325
- * // ray === MathLib.RAY
326
- * ```
327
- */
328
- function wToRay(x) {
329
- return BigInt(x) * 1000000000n;
330
- }
331
- MathLib.wToRay = wToRay;
332
- })(MathLib || (exports.MathLib = MathLib = {}));
4
+ var morpho_ts_1 = require("@morpho-org/morpho-ts");
5
+ Object.defineProperty(exports, "MathLib", { enumerable: true, get: function () { return morpho_ts_1.MathLib; } });
@@ -48,8 +48,8 @@ export declare class Eip5267Domain implements IEip5267Domain {
48
48
  */
49
49
  readonly extensions: readonly bigint[];
50
50
  readonly eip712Domain: {
51
- name?: string | undefined;
52
51
  chainId?: number | undefined;
52
+ name?: string | undefined;
53
53
  version?: string | undefined;
54
54
  verifyingContract?: `0x${string}` | undefined;
55
55
  salt?: `0x${string}` | undefined;
@@ -1,3 +1,4 @@
1
+ import type { BigIntish as SharedBigIntish } from "@morpho-org/morpho-ts";
1
2
  /**
2
3
  * The address of a Contract, or an EOA
3
4
  */
@@ -9,7 +10,7 @@ export type MarketId = `0x${string}` & {
9
10
  __TYPE__: "marketId";
10
11
  };
11
12
  /** Primitive values accepted at SDK boundaries and normalized to `bigint`. */
12
- export type BigIntish = bigint | string | number | boolean;
13
+ export type BigIntish = SharedBigIntish;
13
14
  /**
14
15
  * The possible transaction type on the Blue contract
15
16
  */
@@ -216,6 +216,8 @@ export declare class AccrualVault extends Vault implements IAccrualVault {
216
216
  /**
217
217
  * Returns a new vault derived from this vault, whose interest has been accrued up to the given timestamp.
218
218
  * @param timestamp The timestamp at which to accrue interest. Must be greater than or equal to each of the vault's market's `lastUpdate`.
219
+ * @returns A new vault whose market positions and fee accounting reflect accrued interest.
220
+ * @throws {UnknownMarketAllocationError} when the withdraw queue references a market without an allocation.
219
221
  */
220
222
  accrueInterest(timestamp?: BigIntish): AccrualVault;
221
223
  }
@@ -2,6 +2,7 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.AccrualVault = exports.Vault = void 0;
4
4
  const morpho_ts_1 = require("@morpho-org/morpho-ts");
5
+ const errors_js_1 = require("../errors.js");
5
6
  const index_js_1 = require("../market/index.js");
6
7
  const index_js_2 = require("../math/index.js");
7
8
  const index_js_3 = require("../token/index.js");
@@ -270,12 +271,22 @@ class AccrualVault extends Vault {
270
271
  /**
271
272
  * Returns a new vault derived from this vault, whose interest has been accrued up to the given timestamp.
272
273
  * @param timestamp The timestamp at which to accrue interest. Must be greater than or equal to each of the vault's market's `lastUpdate`.
274
+ * @returns A new vault whose market positions and fee accounting reflect accrued interest.
275
+ * @throws {UnknownMarketAllocationError} when the withdraw queue references a market without an allocation.
273
276
  */
274
277
  accrueInterest(timestamp) {
275
278
  const vault = new AccrualVault(this,
276
279
  // Keep withdraw queue order.
277
280
  this.withdrawQueue.map((marketId) => {
278
- const { config, position } = this.allocations.get(marketId);
281
+ const allocation = this.allocations.get(marketId);
282
+ // Fail loudly rather than silently dropping the market: a stale
283
+ // `withdrawQueue` entry (e.g., one mutated after construction to
284
+ // reference a market that is no longer allocated) would otherwise
285
+ // crash with an opaque "Cannot destructure property 'config' of
286
+ // 'undefined'" via the non-null assertion below.
287
+ if (allocation == null)
288
+ throw new errors_js_1.UnknownMarketAllocationError(marketId);
289
+ const { config, position } = allocation;
279
290
  return {
280
291
  config,
281
292
  position: position.accrueInterest(timestamp),
@@ -43,7 +43,7 @@ var VaultUtils;
43
43
  */
44
44
  // biome-ignore lint/complexity/useMaxParams: TODO refactor to ≤2 params
45
45
  function toAssets(shares, { totalAssets, totalSupply,
46
- // biome-ignore lint/nursery/noShadow: TODO rename to avoid shadowing
46
+ // biome-ignore lint/suspicious/noShadow: TODO rename to avoid shadowing
47
47
  decimalsOffset, }, rounding = "Down") {
48
48
  return index_js_1.MathLib.mulDiv(shares, BigInt(totalAssets) + VaultUtils.VIRTUAL_ASSETS, BigInt(totalSupply) + 10n ** BigInt(decimalsOffset), rounding);
49
49
  }
@@ -67,7 +67,7 @@ var VaultUtils;
67
67
  */
68
68
  // biome-ignore lint/complexity/useMaxParams: TODO refactor to ≤2 params
69
69
  function toShares(assets, { totalAssets, totalSupply,
70
- // biome-ignore lint/nursery/noShadow: TODO rename to avoid shadowing
70
+ // biome-ignore lint/suspicious/noShadow: TODO rename to avoid shadowing
71
71
  decimalsOffset, }, rounding = "Up") {
72
72
  return index_js_1.MathLib.mulDiv(assets, BigInt(totalSupply) + 10n ** BigInt(decimalsOffset), BigInt(totalAssets) + VaultUtils.VIRTUAL_ASSETS, rounding);
73
73
  }
@@ -53,7 +53,7 @@ class AccrualVaultV2MorphoMarketV1Adapter extends VaultV2MorphoMarketV1Adapter {
53
53
  maxWithdraw(data) {
54
54
  const marketId = index_js_1.MarketParams.fromHex(data).id;
55
55
  const position = this.positions.find(
56
- // biome-ignore lint/nursery/noShadow: TODO rename to avoid shadowing
56
+ // biome-ignore lint/suspicious/noShadow: TODO rename to avoid shadowing
57
57
  (position) => position.marketId === marketId);
58
58
  return (position?.market?.getWithdrawCapacityLimit(position) ?? {
59
59
  value: 0n,
@@ -59,7 +59,7 @@ class AccrualVaultV2MorphoMarketV1AdapterV2 extends VaultV2MorphoMarketV1Adapter
59
59
  }
60
60
  maxWithdraw(data) {
61
61
  const marketId = index_js_1.MarketParams.fromHex(data).id;
62
- // biome-ignore lint/nursery/noShadow: TODO rename to avoid shadowing
62
+ // biome-ignore lint/suspicious/noShadow: TODO rename to avoid shadowing
63
63
  const market = this.markets.find((market) => market.id === marketId);
64
64
  return (market?.getWithdrawCapacityLimit({
65
65
  supplyShares: this.supplyShares[marketId] ?? 0n,