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