@morpho-org/blue-sdk 1.0.6 → 1.2.1

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 (104) hide show
  1. package/README.md +2 -2
  2. package/lib/addresses.d.ts +34 -20
  3. package/lib/addresses.js +50 -13
  4. package/lib/chain.d.ts +30 -0
  5. package/lib/chain.js +288 -0
  6. package/lib/chain.test.js +22 -0
  7. package/lib/constants.d.ts +27 -6
  8. package/lib/constants.js +28 -8
  9. package/lib/errors.d.ts +18 -7
  10. package/lib/errors.js +38 -10
  11. package/lib/helpers/format/format.js +21 -60
  12. package/lib/helpers/index.d.ts +0 -2
  13. package/lib/helpers/index.js +0 -2
  14. package/lib/holding/Holding.d.ts +3 -4
  15. package/lib/holding/Holding.js +32 -4
  16. package/lib/index.d.ts +0 -8
  17. package/lib/index.js +1 -9
  18. package/lib/market/Market.d.ts +202 -54
  19. package/lib/market/Market.js +263 -62
  20. package/lib/market/MarketConfig.d.ts +17 -9
  21. package/lib/market/MarketConfig.js +39 -21
  22. package/lib/market/MarketUtils.d.ts +151 -102
  23. package/lib/market/MarketUtils.js +91 -39
  24. package/lib/market/MarketUtils.test.js +1 -2
  25. package/lib/maths/AdaptiveCurveIrmLib.d.ts +5 -4
  26. package/lib/maths/AdaptiveCurveIrmLib.js +10 -7
  27. package/lib/maths/MathLib.d.ts +35 -15
  28. package/lib/maths/MathLib.js +53 -33
  29. package/lib/maths/SharesMath.d.ts +3 -3
  30. package/lib/maths/SharesMath.js +2 -3
  31. package/lib/maths/index.d.ts +0 -1
  32. package/lib/maths/index.js +0 -1
  33. package/lib/position/Position.d.ts +5 -26
  34. package/lib/position/Position.js +28 -35
  35. package/lib/tests/mocks/markets.d.ts +1 -0
  36. package/lib/tests/mocks/markets.js +35 -29
  37. package/lib/token/Token.d.ts +4 -3
  38. package/lib/token/Token.js +28 -3
  39. package/lib/token/WrappedToken.js +12 -6
  40. package/lib/token/index.d.ts +1 -1
  41. package/lib/token/index.js +1 -1
  42. package/lib/types.d.ts +1 -0
  43. package/lib/types.js +3 -4
  44. package/lib/user/User.js +12 -0
  45. package/lib/vault/Vault.d.ts +12 -12
  46. package/lib/vault/Vault.js +102 -18
  47. package/lib/vault/VaultConfig.js +9 -3
  48. package/lib/vault/VaultMarketAllocation.d.ts +20 -0
  49. package/lib/vault/VaultMarketAllocation.js +30 -0
  50. package/lib/vault/VaultMarketConfig.d.ts +43 -0
  51. package/lib/vault/VaultMarketConfig.js +43 -0
  52. package/lib/vault/VaultMarketPublicAllocatorConfig.d.ts +29 -0
  53. package/lib/vault/VaultMarketPublicAllocatorConfig.js +28 -0
  54. package/lib/vault/VaultUtils.d.ts +8 -9
  55. package/lib/vault/VaultUtils.js +2 -3
  56. package/lib/vault/index.d.ts +3 -1
  57. package/lib/vault/index.js +3 -1
  58. package/package.json +6 -11
  59. package/lib/chain/chain.constants.d.ts +0 -3
  60. package/lib/chain/chain.constants.js +0 -232
  61. package/lib/chain/chain.test.js +0 -37
  62. package/lib/chain/chain.types.d.ts +0 -20
  63. package/lib/chain/chain.types.js +0 -30
  64. package/lib/chain/chain.utils.d.ts +0 -14
  65. package/lib/chain/chain.utils.js +0 -30
  66. package/lib/chain/index.d.ts +0 -2
  67. package/lib/chain/index.js +0 -18
  68. package/lib/ethers/ethers.test.d.ts +0 -1
  69. package/lib/ethers/ethers.test.js +0 -11
  70. package/lib/ethers/index.d.ts +0 -2
  71. package/lib/ethers/index.js +0 -18
  72. package/lib/ethers/safeGetAddress.d.ts +0 -1
  73. package/lib/ethers/safeGetAddress.js +0 -6
  74. package/lib/ethers/safeParseUnits.d.ts +0 -2
  75. package/lib/ethers/safeParseUnits.js +0 -25
  76. package/lib/evm.d.ts +0 -36
  77. package/lib/evm.js +0 -113
  78. package/lib/helpers/getChecksumedAddress.d.ts +0 -7
  79. package/lib/helpers/getChecksumedAddress.js +0 -17
  80. package/lib/helpers/isZeroAddressOrUnset.d.ts +0 -7
  81. package/lib/helpers/isZeroAddressOrUnset.js +0 -14
  82. package/lib/maths/MathUtils.d.ts +0 -15
  83. package/lib/maths/MathUtils.js +0 -33
  84. package/lib/notifications.d.ts +0 -98
  85. package/lib/notifications.js +0 -52
  86. package/lib/signatures/index.d.ts +0 -12
  87. package/lib/signatures/index.js +0 -39
  88. package/lib/signatures/manager.d.ts +0 -10
  89. package/lib/signatures/manager.js +0 -37
  90. package/lib/signatures/permit.d.ts +0 -21
  91. package/lib/signatures/permit.js +0 -101
  92. package/lib/signatures/permit2.d.ts +0 -20
  93. package/lib/signatures/permit2.js +0 -91
  94. package/lib/signatures/types.d.ts +0 -13
  95. package/lib/signatures/types.js +0 -2
  96. package/lib/signatures/utils.d.ts +0 -6
  97. package/lib/signatures/utils.js +0 -44
  98. package/lib/token/ERC20Metadata.d.ts +0 -249
  99. package/lib/token/ERC20Metadata.js +0 -81
  100. package/lib/token/TokenNamespace.d.ts +0 -18
  101. package/lib/token/TokenNamespace.js +0 -55
  102. package/lib/vault/VaultAllocation.d.ts +0 -38
  103. package/lib/vault/VaultAllocation.js +0 -18
  104. /package/lib/{chain/chain.test.d.ts → chain.test.d.ts} +0 -0
@@ -1,8 +1,5 @@
1
- import { BigNumberish, Provider } from "ethers";
2
- import { ViewOverrides } from "ethers-types/dist/common";
3
- import { ChainId } from "../chain";
4
1
  import { RoundingDirection } from "../maths";
5
- import { MarketId } from "../types";
2
+ import { BigIntish } from "../types";
6
3
  import { MarketConfig } from "./MarketConfig";
7
4
  export declare enum CapacityLimitReason {
8
5
  liquidity = "Liquidity",
@@ -25,28 +22,19 @@ export interface MaxPositionCapacities {
25
22
  }
26
23
  export interface InputMarket {
27
24
  config: MarketConfig;
28
- totalSupplyAssets: BigNumberish;
29
- totalBorrowAssets: BigNumberish;
30
- totalSupplyShares: BigNumberish;
31
- totalBorrowShares: BigNumberish;
32
- lastUpdate: BigNumberish;
33
- fee: BigNumberish;
34
- price: BigNumberish;
35
- rateAtTarget?: BigNumberish;
25
+ totalSupplyAssets: bigint;
26
+ totalBorrowAssets: bigint;
27
+ totalSupplyShares: bigint;
28
+ totalBorrowShares: bigint;
29
+ lastUpdate: bigint;
30
+ fee: bigint;
31
+ price: bigint;
32
+ rateAtTarget?: bigint;
36
33
  }
34
+ /**
35
+ * Represents a lending market on Morpho Blue.
36
+ */
37
37
  export declare class Market implements InputMarket {
38
- static fetchFromId(id: MarketId, runner: {
39
- provider: Provider;
40
- }, { chainId, overrides, }?: {
41
- chainId?: ChainId;
42
- overrides?: ViewOverrides;
43
- }): Promise<Market>;
44
- static fetchFromConfig(config: MarketConfig, runner: {
45
- provider: Provider;
46
- }, { chainId, overrides, }?: {
47
- chainId?: ChainId;
48
- overrides?: ViewOverrides;
49
- }): Promise<Market>;
50
38
  /**
51
39
  * The market's config.
52
40
  */
@@ -85,75 +73,235 @@ export declare class Market implements InputMarket {
85
73
  */
86
74
  rateAtTarget?: bigint;
87
75
  constructor({ config, totalSupplyAssets, totalBorrowAssets, totalSupplyShares, totalBorrowShares, lastUpdate, fee, price, rateAtTarget, }: InputMarket);
88
- get id(): MarketId;
76
+ /**
77
+ * The market's hex-encoded id, defined as the hash of the market params.
78
+ */
79
+ get id(): import("../types").MarketId;
80
+ /**
81
+ * Whether the market satisfies the canonical definition of an idle market (i.e. collateral token is the zero address).
82
+ */
89
83
  get isIdle(): boolean;
90
84
  /**
91
85
  * @warning Cannot be used to calculate the liquidity available inside a callback,
92
86
  * because the balance of Blue may be lower than the market's liquidity due to assets being transferred out prior to the callback.
93
87
  */
94
88
  get liquidity(): bigint;
89
+ /**
90
+ * The market's utilization rate (scaled by WAD).
91
+ */
95
92
  get utilization(): bigint;
93
+ /**
94
+ * The market's Annual Percentage Yield (APY) at the IRM's target utilization rate, if applicable (scaled by WAD).
95
+ */
96
96
  get apyAtTarget(): bigint | undefined;
97
+ /**
98
+ * Returns the rate at which interest accrued on average for suppliers of this market,
99
+ * since the last time the market was updated (scaled by WAD).
100
+ */
97
101
  get supplyRate(): bigint;
102
+ /**
103
+ * Returns the rate at which interest accrued on average for borrowers of this market,
104
+ * since the last time the market was updated (scaled by WAD).
105
+ */
98
106
  get borrowRate(): bigint;
107
+ /**
108
+ * The market's supply Annual Percentage Yield (APY) (scaled by WAD).
109
+ */
99
110
  get supplyApy(): bigint;
111
+ /**
112
+ * The market's borrow Annual Percentage Yield (APY) (scaled by WAD).
113
+ */
100
114
  get borrowApy(): bigint;
101
- accrueInterest(timestamp: BigNumberish): Market;
102
- getLiquidityToUtilization(utilization: BigNumberish): bigint;
103
- getCollateralValue(collateral: BigNumberish): bigint;
104
- getMaxBorrowAssets(collateral: BigNumberish): bigint;
115
+ /**
116
+ * Returns a new market derived from this market, whose interest has been accrued up to the given timestamp.
117
+ * @param timestamp The timestamp at which to accrue interest. Must be greater than or equal to `lastUpdate`.
118
+ */
119
+ accrueInterest(timestamp: BigIntish): Market;
120
+ supply(assets: bigint, shares: bigint, timestamp?: bigint): {
121
+ market: Market;
122
+ assets: bigint;
123
+ shares: bigint;
124
+ };
125
+ withdraw(assets: bigint, shares: bigint, timestamp?: bigint): {
126
+ market: Market;
127
+ assets: bigint;
128
+ shares: bigint;
129
+ };
130
+ borrow(assets: bigint, shares: bigint, timestamp?: bigint): {
131
+ market: Market;
132
+ assets: bigint;
133
+ shares: bigint;
134
+ };
135
+ repay(assets: bigint, shares: bigint, timestamp?: bigint): {
136
+ market: Market;
137
+ assets: bigint;
138
+ shares: bigint;
139
+ };
140
+ /**
141
+ * Converts a given amount of supply shares into supply loan assets.
142
+ * @param shares The amount of shares to convert.
143
+ * @param rounding The rounding direction to use (defaults to "Down").
144
+ */
145
+ toSupplyAssets(shares: bigint, rounding?: RoundingDirection): bigint;
146
+ /**
147
+ * Converts a given amount of supply loan assets into supply shares.
148
+ * @param shares The amount of assets to convert.
149
+ * @param rounding The rounding direction to use (defaults to "Up").
150
+ */
151
+ toSupplyShares(assets: bigint, rounding?: RoundingDirection): bigint;
152
+ /**
153
+ * Converts a given amount of borrow shares into borrow loan assets.
154
+ * @param shares The amount of shares to convert.
155
+ * @param rounding The rounding direction to use (defaults to "Up").
156
+ */
157
+ toBorrowAssets(shares: bigint, rounding?: RoundingDirection): bigint;
158
+ /**
159
+ * Converts a given amount of borrow loan assets into borrow shares.
160
+ * @param shares The amount of assets to convert.
161
+ * @param rounding The rounding direction to use (defaults to "Down").
162
+ */
163
+ toBorrowShares(assets: bigint, rounding?: RoundingDirection): bigint;
164
+ /**
165
+ * Returns the liquidity available to borrow until the market reach the given utilization rate.
166
+ * @param utilization The target utilization rate (scaled by WAD).
167
+ */
168
+ getSupplyLiquidityToUtilization(utilization: bigint): BigIntish;
169
+ /**
170
+ * Returns the liquidity available to borrow until the market reach the given utilization rate.
171
+ * @param utilization The target utilization rate (scaled by WAD).
172
+ */
173
+ getBorrowLiquidityToUtilization(utilization: bigint): bigint;
174
+ /**
175
+ * Returns the value of a given amount of collateral quoted in loan assets.
176
+ * @param collateral The amount of collateral to quote.
177
+ */
178
+ getCollateralValue(collateral: bigint): bigint;
179
+ /**
180
+ * Returns the maximum amount of loan assets that can be borrowed given a certain amount of collateral.
181
+ * @param collateral The amount of collateral to consider.
182
+ */
183
+ getMaxBorrowAssets(collateral: bigint): bigint;
184
+ /**
185
+ * Returns the maximum amount of loan assets that can be borrowed given a certain borrow position.
186
+ * @param position The borrow position to consider.
187
+ */
105
188
  getMaxBorrowableAssets(position: {
106
- collateral: BigNumberish;
107
- borrowShares: BigNumberish;
189
+ collateral: bigint;
190
+ borrowShares: bigint;
108
191
  }): bigint;
109
- getLiquidationSeizedAssets(repaidShares: BigNumberish): bigint;
110
- getLiquidationRepaidShares(seizedAssets: BigNumberish): bigint;
192
+ /**
193
+ * Returns the amount of collateral that would be seized in a liquidation given a certain amount of repaid shares.
194
+ * @param repaidShares The amount of shares hypothetically repaid.
195
+ */
196
+ getLiquidationSeizedAssets(repaidShares: bigint): bigint;
197
+ /**
198
+ * Returns the amount of borrow shares that would be repaid in a liquidation given a certain amount of seized collateral.
199
+ * @param seizedAssets The amount of collateral hypothetically seized.
200
+ */
201
+ getLiquidationRepaidShares(seizedAssets: bigint): bigint;
202
+ /**
203
+ * Returns the maximum amount of collateral that is worth being seized in a liquidation given a certain borrow position.
204
+ * @param position The borrow position to consider.
205
+ */
111
206
  getSeizableCollateral(position: {
112
- collateral: BigNumberish;
113
- borrowShares: BigNumberish;
207
+ collateral: bigint;
208
+ borrowShares: bigint;
114
209
  }): bigint;
210
+ /**
211
+ * Returns the amount of collateral that can be withdrawn given a certain borrow position.
212
+ * @param position The borrow position to consider.
213
+ */
115
214
  getWithdrawableCollateral(position: {
116
- collateral: BigNumberish;
117
- borrowShares: BigNumberish;
215
+ collateral: bigint;
216
+ borrowShares: bigint;
118
217
  }): bigint;
218
+ /**
219
+ * Returns whether a given borrow position is healthy.
220
+ * @param position The borrow position to check.
221
+ */
119
222
  isHealthy(position: {
120
- collateral: BigNumberish;
121
- borrowShares: BigNumberish;
223
+ collateral: bigint;
224
+ borrowShares: bigint;
122
225
  }): boolean;
226
+ /**
227
+ * Returns the liquidation price of a given borrow position.
228
+ * @param position The borrow position to consider.
229
+ */
123
230
  getLiquidationPrice(position: {
124
- collateral: BigNumberish;
125
- borrowShares: BigNumberish;
231
+ collateral: bigint;
232
+ borrowShares: bigint;
126
233
  }): bigint | null;
234
+ /**
235
+ * Returns the price deviation required for the given borrow position to be unhealthy (scaled by WAD).
236
+ * @param position The borrow position to consider.
237
+ */
127
238
  getPriceVariationToLiquidation(position: {
128
- collateral: BigNumberish;
129
- borrowShares: BigNumberish;
239
+ collateral: bigint;
240
+ borrowShares: bigint;
130
241
  }): bigint | null;
242
+ /**
243
+ * Returns the health factor of a given borrow position (scaled by WAD).
244
+ * @param position The borrow position to consider.
245
+ */
131
246
  getHealthFactor(position: {
132
- collateral: BigNumberish;
133
- borrowShares: BigNumberish;
247
+ collateral: bigint;
248
+ borrowShares: bigint;
134
249
  }): bigint | null;
250
+ /**
251
+ * Returns the loan-to-value ratio of a given borrow position (scaled by WAD).
252
+ * @param position The borrow position to consider.
253
+ */
135
254
  getLtv(position: {
136
- collateral: BigNumberish;
137
- borrowShares: BigNumberish;
255
+ collateral: bigint;
256
+ borrowShares: bigint;
138
257
  }): bigint | null;
258
+ /**
259
+ * Returns the usage ratio of the maximum borrow capacity given a certain borrow position (scaled by WAD).
260
+ * @param position The borrow position to consider.
261
+ */
139
262
  getBorrowCapacityUsage(position: {
140
- collateral: BigNumberish;
141
- borrowShares: BigNumberish;
263
+ collateral: bigint;
264
+ borrowShares: bigint;
142
265
  }): bigint | null;
143
- toSupplyAssets(shares: BigNumberish, rounding?: RoundingDirection): bigint;
144
- toSupplyShares(assets: BigNumberish, rounding?: RoundingDirection): bigint;
145
- toBorrowAssets(shares: BigNumberish, rounding?: RoundingDirection): bigint;
146
- toBorrowShares(assets: BigNumberish, rounding?: RoundingDirection): bigint;
266
+ /**
267
+ * Returns the maximum amount of loan assets that can be borrowed given a certain borrow position
268
+ * and the reason for the limit.
269
+ * @param position The borrow position to consider.
270
+ */
147
271
  getBorrowCapacityLimit({ collateral, borrowShares, }: {
148
272
  collateral: bigint;
149
273
  borrowShares?: bigint;
150
274
  }): CapacityLimit;
275
+ /**
276
+ * Returns the maximum amount of loan assets that can be repaid given a certain borrow position
277
+ * and a balance of loan assets, and the reason for the limit.
278
+ * @param position The borrow position to consider.
279
+ */
151
280
  getRepayCapacityLimit(borrowShares: bigint, loanTokenBalance: bigint): CapacityLimit;
152
- getWithdrawCapacityLimit(supplyShares: bigint): CapacityLimit;
281
+ /**
282
+ * Returns the maximum amount of loan assets that can be withdrawn given a certain supply position
283
+ * and a balance of loan assets, and the reason for the limit.
284
+ * @param position The supply position to consider.
285
+ */
286
+ getWithdrawCapacityLimit({ supplyShares, }: {
287
+ supplyShares: bigint;
288
+ }): CapacityLimit;
289
+ /**
290
+ * Returns the maximum amount of collateral assets that can be withdrawn given a certain borrow position
291
+ * and the reason for the limit.
292
+ * @param position The borrow position to consider.
293
+ */
153
294
  getWithdrawCollateralCapacityLimit(position: {
154
295
  collateral: bigint;
155
296
  borrowShares: bigint;
156
297
  }): CapacityLimit;
298
+ /**
299
+ * Returns the maximum capacity for all interactions with Morpho Blue given a certain position
300
+ * and loan and collateral balances.
301
+ * @param position The position to consider.
302
+ * @param loanTokenBalance The balance of loan assets.
303
+ * @param collateralTokenBalance The balance of collateral assets.
304
+ */
157
305
  getMaxCapacities(position: {
158
306
  collateral: bigint;
159
307
  supplyShares: bigint;