@morpho-org/blue-sdk 1.0.5 → 1.2.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.
- package/README.md +2 -2
- package/lib/addresses.d.ts +35 -21
- package/lib/addresses.js +51 -14
- package/lib/chain.d.ts +30 -0
- package/lib/chain.js +288 -0
- package/lib/chain.test.js +22 -0
- package/lib/constants.d.ts +27 -6
- package/lib/constants.js +28 -8
- package/lib/errors.d.ts +18 -7
- package/lib/errors.js +38 -10
- package/lib/helpers/format/format.js +21 -60
- package/lib/helpers/index.d.ts +0 -2
- package/lib/helpers/index.js +0 -2
- package/lib/holding/Holding.d.ts +3 -4
- package/lib/holding/Holding.js +32 -4
- package/lib/index.d.ts +0 -8
- package/lib/index.js +1 -9
- package/lib/market/Market.d.ts +206 -55
- package/lib/market/Market.js +266 -64
- package/lib/market/MarketConfig.d.ts +17 -9
- package/lib/market/MarketConfig.js +39 -21
- package/lib/market/MarketUtils.d.ts +151 -102
- package/lib/market/MarketUtils.js +94 -38
- package/lib/market/MarketUtils.test.js +1 -2
- package/lib/maths/AdaptiveCurveIrmLib.d.ts +5 -4
- package/lib/maths/AdaptiveCurveIrmLib.js +10 -7
- package/lib/maths/MathLib.d.ts +35 -15
- package/lib/maths/MathLib.js +53 -33
- package/lib/maths/SharesMath.d.ts +3 -3
- package/lib/maths/SharesMath.js +2 -3
- package/lib/maths/index.d.ts +0 -1
- package/lib/maths/index.js +0 -1
- package/lib/position/Position.d.ts +5 -26
- package/lib/position/Position.js +29 -36
- package/lib/tests/mocks/markets.d.ts +1 -0
- package/lib/tests/mocks/markets.js +35 -29
- package/lib/token/Token.d.ts +4 -3
- package/lib/token/Token.js +28 -3
- package/lib/token/WrappedToken.d.ts +3 -3
- package/lib/token/WrappedToken.js +18 -11
- package/lib/token/index.d.ts +1 -1
- package/lib/token/index.js +1 -1
- package/lib/types.d.ts +1 -0
- package/lib/types.js +3 -4
- package/lib/user/User.js +12 -0
- package/lib/vault/Vault.d.ts +12 -12
- package/lib/vault/Vault.js +102 -18
- package/lib/vault/VaultConfig.js +9 -3
- package/lib/vault/VaultMarketAllocation.d.ts +20 -0
- package/lib/vault/VaultMarketAllocation.js +30 -0
- package/lib/vault/VaultMarketConfig.d.ts +43 -0
- package/lib/vault/VaultMarketConfig.js +43 -0
- package/lib/vault/VaultMarketPublicAllocatorConfig.d.ts +29 -0
- package/lib/vault/VaultMarketPublicAllocatorConfig.js +28 -0
- package/lib/vault/VaultUtils.d.ts +8 -9
- package/lib/vault/VaultUtils.js +2 -3
- package/lib/vault/index.d.ts +3 -1
- package/lib/vault/index.js +3 -1
- package/package.json +3 -6
- package/lib/chain/chain.constants.d.ts +0 -3
- package/lib/chain/chain.constants.js +0 -232
- package/lib/chain/chain.test.js +0 -37
- package/lib/chain/chain.types.d.ts +0 -20
- package/lib/chain/chain.types.js +0 -30
- package/lib/chain/chain.utils.d.ts +0 -14
- package/lib/chain/chain.utils.js +0 -30
- package/lib/chain/index.d.ts +0 -2
- package/lib/chain/index.js +0 -18
- package/lib/ethers/ethers.test.d.ts +0 -1
- package/lib/ethers/ethers.test.js +0 -11
- package/lib/ethers/index.d.ts +0 -2
- package/lib/ethers/index.js +0 -18
- package/lib/ethers/safeGetAddress.d.ts +0 -1
- package/lib/ethers/safeGetAddress.js +0 -6
- package/lib/ethers/safeParseUnits.d.ts +0 -2
- package/lib/ethers/safeParseUnits.js +0 -25
- package/lib/evm.d.ts +0 -36
- package/lib/evm.js +0 -113
- package/lib/helpers/getChecksumedAddress.d.ts +0 -7
- package/lib/helpers/getChecksumedAddress.js +0 -17
- package/lib/helpers/isZeroAddressOrUnset.d.ts +0 -7
- package/lib/helpers/isZeroAddressOrUnset.js +0 -14
- package/lib/maths/MathUtils.d.ts +0 -15
- package/lib/maths/MathUtils.js +0 -33
- package/lib/notifications.d.ts +0 -98
- package/lib/notifications.js +0 -52
- package/lib/signatures/index.d.ts +0 -12
- package/lib/signatures/index.js +0 -39
- package/lib/signatures/manager.d.ts +0 -10
- package/lib/signatures/manager.js +0 -37
- package/lib/signatures/permit.d.ts +0 -21
- package/lib/signatures/permit.js +0 -101
- package/lib/signatures/permit2.d.ts +0 -20
- package/lib/signatures/permit2.js +0 -91
- package/lib/signatures/types.d.ts +0 -13
- package/lib/signatures/types.js +0 -2
- package/lib/signatures/utils.d.ts +0 -6
- package/lib/signatures/utils.js +0 -44
- package/lib/token/ERC20Metadata.d.ts +0 -249
- package/lib/token/ERC20Metadata.js +0 -81
- package/lib/token/TokenNamespace.d.ts +0 -18
- package/lib/token/TokenNamespace.js +0 -55
- package/lib/vault/VaultAllocation.d.ts +0 -38
- package/lib/vault/VaultAllocation.js +0 -18
- /package/lib/{chain/chain.test.d.ts → chain.test.d.ts} +0 -0
package/lib/market/Market.d.ts
CHANGED
|
@@ -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 {
|
|
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:
|
|
29
|
-
totalBorrowAssets:
|
|
30
|
-
totalSupplyShares:
|
|
31
|
-
totalBorrowShares:
|
|
32
|
-
lastUpdate:
|
|
33
|
-
fee:
|
|
34
|
-
price:
|
|
35
|
-
rateAtTarget?:
|
|
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,72 +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
|
-
|
|
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
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
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:
|
|
107
|
-
borrowShares:
|
|
189
|
+
collateral: bigint;
|
|
190
|
+
borrowShares: bigint;
|
|
108
191
|
}): bigint;
|
|
109
|
-
|
|
110
|
-
|
|
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:
|
|
113
|
-
borrowShares:
|
|
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:
|
|
117
|
-
borrowShares:
|
|
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:
|
|
121
|
-
borrowShares:
|
|
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:
|
|
125
|
-
borrowShares:
|
|
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:
|
|
129
|
-
borrowShares:
|
|
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:
|
|
133
|
-
borrowShares:
|
|
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:
|
|
137
|
-
borrowShares:
|
|
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:
|
|
141
|
-
borrowShares:
|
|
263
|
+
collateral: bigint;
|
|
264
|
+
borrowShares: bigint;
|
|
142
265
|
}): bigint | null;
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
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
|
+
*/
|
|
271
|
+
getBorrowCapacityLimit({ collateral, borrowShares, }: {
|
|
272
|
+
collateral: bigint;
|
|
273
|
+
borrowShares?: bigint;
|
|
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
|
+
*/
|
|
148
280
|
getRepayCapacityLimit(borrowShares: bigint, loanTokenBalance: bigint): CapacityLimit;
|
|
149
|
-
|
|
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
|
+
*/
|
|
150
294
|
getWithdrawCollateralCapacityLimit(position: {
|
|
151
295
|
collateral: bigint;
|
|
152
296
|
borrowShares: bigint;
|
|
153
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
|
+
*/
|
|
154
305
|
getMaxCapacities(position: {
|
|
155
306
|
collateral: bigint;
|
|
156
307
|
supplyShares: bigint;
|