@morpho-org/blue-sdk 5.16.0 → 5.17.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/lib/cjs/package.json +1 -0
- package/lib/{position → cjs/position}/PreLiquidationPosition.d.ts +3 -3
- package/lib/{position → cjs/position}/PreLiquidationPosition.js +16 -16
- package/lib/{preLiquidation.d.ts → cjs/preLiquidation.d.ts} +1 -1
- package/lib/{preLiquidation.js → cjs/preLiquidation.js} +2 -2
- package/lib/{vault → cjs/vault}/index.d.ts +1 -1
- package/lib/{vault → cjs/vault}/index.js +1 -1
- package/lib/{vault → cjs/vault}/v2/VaultV2.d.ts +5 -5
- package/lib/{vault → cjs/vault}/v2/VaultV2.js +25 -25
- package/lib/{vault → cjs/vault}/v2/VaultV2Adapter.d.ts +2 -2
- package/lib/{vault → cjs/vault}/v2/VaultV2MorphoMarketV1Adapter.d.ts +7 -7
- package/lib/{vault → cjs/vault}/v2/VaultV2MorphoMarketV1Adapter.js +9 -9
- package/lib/{vault → cjs/vault}/v2/VaultV2MorphoMarketV1AdapterV2.d.ts +6 -6
- package/lib/{vault → cjs/vault}/v2/VaultV2MorphoMarketV1AdapterV2.js +8 -8
- package/lib/{vault → cjs/vault}/v2/VaultV2MorphoVaultV1Adapter.d.ts +6 -6
- package/lib/{vault → cjs/vault}/v2/VaultV2MorphoVaultV1Adapter.js +2 -2
- package/lib/esm/addresses.d.ts +2231 -0
- package/lib/esm/addresses.js +1309 -0
- package/lib/esm/chain.d.ts +405 -0
- package/lib/esm/chain.js +276 -0
- package/lib/esm/constants.d.ts +20 -0
- package/lib/esm/constants.js +21 -0
- package/lib/esm/errors.d.ts +101 -0
- package/lib/esm/errors.js +192 -0
- package/lib/esm/holding/AssetBalances.d.ts +48 -0
- package/lib/esm/holding/AssetBalances.js +38 -0
- package/lib/esm/holding/Holding.d.ts +63 -0
- package/lib/esm/holding/Holding.js +63 -0
- package/lib/esm/holding/index.d.ts +2 -0
- package/lib/esm/holding/index.js +2 -0
- package/lib/esm/index.d.ts +14 -0
- package/lib/esm/index.js +14 -0
- package/lib/esm/market/Market.d.ts +424 -0
- package/lib/esm/market/Market.js +576 -0
- package/lib/esm/market/MarketParams.d.ts +74 -0
- package/lib/esm/market/MarketParams.js +91 -0
- package/lib/esm/market/MarketUtils.d.ts +273 -0
- package/lib/esm/market/MarketUtils.js +323 -0
- package/lib/esm/market/index.d.ts +3 -0
- package/lib/esm/market/index.js +3 -0
- package/lib/esm/math/AdaptiveCurveIrmLib.d.ts +40 -0
- package/lib/esm/math/AdaptiveCurveIrmLib.js +133 -0
- package/lib/esm/math/MathLib.d.ts +102 -0
- package/lib/esm/math/MathLib.js +168 -0
- package/lib/esm/math/SharesMath.d.ts +12 -0
- package/lib/esm/math/SharesMath.js +18 -0
- package/lib/esm/math/index.d.ts +3 -0
- package/lib/esm/math/index.js +3 -0
- package/lib/esm/package.json +1 -0
- package/lib/esm/position/Position.d.ts +147 -0
- package/lib/esm/position/Position.js +237 -0
- package/lib/esm/position/PreLiquidationPosition.d.ts +60 -0
- package/lib/esm/position/PreLiquidationPosition.js +97 -0
- package/lib/esm/position/index.d.ts +2 -0
- package/lib/esm/position/index.js +2 -0
- package/lib/esm/preLiquidation.d.ts +15 -0
- package/lib/esm/preLiquidation.js +91 -0
- package/lib/esm/token/ConstantWrappedToken.d.ts +17 -0
- package/lib/esm/token/ConstantWrappedToken.js +30 -0
- package/lib/esm/token/Eip5267Domain.d.ts +55 -0
- package/lib/esm/token/Eip5267Domain.js +66 -0
- package/lib/esm/token/ExchangeRateWrappedToken.d.ts +11 -0
- package/lib/esm/token/ExchangeRateWrappedToken.js +17 -0
- package/lib/esm/token/Token.d.ts +52 -0
- package/lib/esm/token/Token.js +62 -0
- package/lib/esm/token/VaultToken.d.ts +23 -0
- package/lib/esm/token/VaultToken.js +27 -0
- package/lib/esm/token/WrappedToken.d.ts +17 -0
- package/lib/esm/token/WrappedToken.js +29 -0
- package/lib/esm/token/index.d.ts +6 -0
- package/lib/esm/token/index.js +6 -0
- package/lib/esm/types.d.ts +26 -0
- package/lib/esm/types.js +13 -0
- package/lib/esm/user/User.d.ts +20 -0
- package/lib/esm/user/User.js +19 -0
- package/lib/esm/user/index.d.ts +1 -0
- package/lib/esm/user/index.js +1 -0
- package/lib/esm/utils.d.ts +13 -0
- package/lib/esm/utils.js +10 -0
- package/lib/esm/vault/Vault.d.ts +214 -0
- package/lib/esm/vault/Vault.js +289 -0
- package/lib/esm/vault/VaultConfig.d.ts +11 -0
- package/lib/esm/vault/VaultConfig.js +10 -0
- package/lib/esm/vault/VaultMarketAllocation.d.ts +20 -0
- package/lib/esm/vault/VaultMarketAllocation.js +27 -0
- package/lib/esm/vault/VaultMarketConfig.d.ts +43 -0
- package/lib/esm/vault/VaultMarketConfig.js +39 -0
- package/lib/esm/vault/VaultMarketPublicAllocatorConfig.d.ts +29 -0
- package/lib/esm/vault/VaultMarketPublicAllocatorConfig.js +24 -0
- package/lib/esm/vault/VaultUser.d.ts +26 -0
- package/lib/esm/vault/VaultUser.js +24 -0
- package/lib/esm/vault/VaultUtils.d.ts +16 -0
- package/lib/esm/vault/VaultUtils.js +17 -0
- package/lib/esm/vault/index.d.ts +8 -0
- package/lib/esm/vault/index.js +8 -0
- package/lib/esm/vault/v2/VaultV2.d.ts +87 -0
- package/lib/esm/vault/v2/VaultV2.js +154 -0
- package/lib/esm/vault/v2/VaultV2Adapter.d.ts +29 -0
- package/lib/esm/vault/v2/VaultV2Adapter.js +12 -0
- package/lib/esm/vault/v2/VaultV2MorphoMarketV1Adapter.d.ts +30 -0
- package/lib/esm/vault/v2/VaultV2MorphoMarketV1Adapter.js +54 -0
- package/lib/esm/vault/v2/VaultV2MorphoMarketV1AdapterV2.d.ts +33 -0
- package/lib/esm/vault/v2/VaultV2MorphoMarketV1AdapterV2.js +63 -0
- package/lib/esm/vault/v2/VaultV2MorphoVaultV1Adapter.d.ts +24 -0
- package/lib/esm/vault/v2/VaultV2MorphoVaultV1Adapter.js +36 -0
- package/lib/esm/vault/v2/index.d.ts +5 -0
- package/lib/esm/vault/v2/index.js +5 -0
- package/package.json +16 -7
- package/src/index.ts +14 -0
- /package/lib/{addresses.d.ts → cjs/addresses.d.ts} +0 -0
- /package/lib/{addresses.js → cjs/addresses.js} +0 -0
- /package/lib/{chain.d.ts → cjs/chain.d.ts} +0 -0
- /package/lib/{chain.js → cjs/chain.js} +0 -0
- /package/lib/{constants.d.ts → cjs/constants.d.ts} +0 -0
- /package/lib/{constants.js → cjs/constants.js} +0 -0
- /package/lib/{errors.d.ts → cjs/errors.d.ts} +0 -0
- /package/lib/{errors.js → cjs/errors.js} +0 -0
- /package/lib/{holding → cjs/holding}/AssetBalances.d.ts +0 -0
- /package/lib/{holding → cjs/holding}/AssetBalances.js +0 -0
- /package/lib/{holding → cjs/holding}/Holding.d.ts +0 -0
- /package/lib/{holding → cjs/holding}/Holding.js +0 -0
- /package/lib/{holding → cjs/holding}/index.d.ts +0 -0
- /package/lib/{holding → cjs/holding}/index.js +0 -0
- /package/lib/{index.d.ts → cjs/index.d.ts} +0 -0
- /package/lib/{index.js → cjs/index.js} +0 -0
- /package/lib/{market → cjs/market}/Market.d.ts +0 -0
- /package/lib/{market → cjs/market}/Market.js +0 -0
- /package/lib/{market → cjs/market}/MarketParams.d.ts +0 -0
- /package/lib/{market → cjs/market}/MarketParams.js +0 -0
- /package/lib/{market → cjs/market}/MarketUtils.d.ts +0 -0
- /package/lib/{market → cjs/market}/MarketUtils.js +0 -0
- /package/lib/{market → cjs/market}/index.d.ts +0 -0
- /package/lib/{market → cjs/market}/index.js +0 -0
- /package/lib/{math → cjs/math}/AdaptiveCurveIrmLib.d.ts +0 -0
- /package/lib/{math → cjs/math}/AdaptiveCurveIrmLib.js +0 -0
- /package/lib/{math → cjs/math}/MathLib.d.ts +0 -0
- /package/lib/{math → cjs/math}/MathLib.js +0 -0
- /package/lib/{math → cjs/math}/SharesMath.d.ts +0 -0
- /package/lib/{math → cjs/math}/SharesMath.js +0 -0
- /package/lib/{math → cjs/math}/index.d.ts +0 -0
- /package/lib/{math → cjs/math}/index.js +0 -0
- /package/lib/{position → cjs/position}/Position.d.ts +0 -0
- /package/lib/{position → cjs/position}/Position.js +0 -0
- /package/lib/{position → cjs/position}/index.d.ts +0 -0
- /package/lib/{position → cjs/position}/index.js +0 -0
- /package/lib/{token → cjs/token}/ConstantWrappedToken.d.ts +0 -0
- /package/lib/{token → cjs/token}/ConstantWrappedToken.js +0 -0
- /package/lib/{token → cjs/token}/Eip5267Domain.d.ts +0 -0
- /package/lib/{token → cjs/token}/Eip5267Domain.js +0 -0
- /package/lib/{token → cjs/token}/ExchangeRateWrappedToken.d.ts +0 -0
- /package/lib/{token → cjs/token}/ExchangeRateWrappedToken.js +0 -0
- /package/lib/{token → cjs/token}/Token.d.ts +0 -0
- /package/lib/{token → cjs/token}/Token.js +0 -0
- /package/lib/{token → cjs/token}/VaultToken.d.ts +0 -0
- /package/lib/{token → cjs/token}/VaultToken.js +0 -0
- /package/lib/{token → cjs/token}/WrappedToken.d.ts +0 -0
- /package/lib/{token → cjs/token}/WrappedToken.js +0 -0
- /package/lib/{token → cjs/token}/index.d.ts +0 -0
- /package/lib/{token → cjs/token}/index.js +0 -0
- /package/lib/{types.d.ts → cjs/types.d.ts} +0 -0
- /package/lib/{types.js → cjs/types.js} +0 -0
- /package/lib/{user → cjs/user}/User.d.ts +0 -0
- /package/lib/{user → cjs/user}/User.js +0 -0
- /package/lib/{user → cjs/user}/index.d.ts +0 -0
- /package/lib/{user → cjs/user}/index.js +0 -0
- /package/lib/{utils.d.ts → cjs/utils.d.ts} +0 -0
- /package/lib/{utils.js → cjs/utils.js} +0 -0
- /package/lib/{vault → cjs/vault}/Vault.d.ts +0 -0
- /package/lib/{vault → cjs/vault}/Vault.js +0 -0
- /package/lib/{vault → cjs/vault}/VaultConfig.d.ts +0 -0
- /package/lib/{vault → cjs/vault}/VaultConfig.js +0 -0
- /package/lib/{vault → cjs/vault}/VaultMarketAllocation.d.ts +0 -0
- /package/lib/{vault → cjs/vault}/VaultMarketAllocation.js +0 -0
- /package/lib/{vault → cjs/vault}/VaultMarketConfig.d.ts +0 -0
- /package/lib/{vault → cjs/vault}/VaultMarketConfig.js +0 -0
- /package/lib/{vault → cjs/vault}/VaultMarketPublicAllocatorConfig.d.ts +0 -0
- /package/lib/{vault → cjs/vault}/VaultMarketPublicAllocatorConfig.js +0 -0
- /package/lib/{vault → cjs/vault}/VaultUser.d.ts +0 -0
- /package/lib/{vault → cjs/vault}/VaultUser.js +0 -0
- /package/lib/{vault → cjs/vault}/VaultUtils.d.ts +0 -0
- /package/lib/{vault → cjs/vault}/VaultUtils.js +0 -0
- /package/lib/{vault → cjs/vault}/v2/VaultV2Adapter.js +0 -0
- /package/lib/{vault → cjs/vault}/v2/index.d.ts +0 -0
- /package/lib/{vault → cjs/vault}/v2/index.js +0 -0
|
@@ -0,0 +1,576 @@
|
|
|
1
|
+
import { Time, ZERO_ADDRESS } from "@morpho-org/morpho-ts";
|
|
2
|
+
import { BlueErrors } from "../errors.js";
|
|
3
|
+
import { AdaptiveCurveIrmLib, MathLib, } from "../math/index.js";
|
|
4
|
+
import { CapacityLimitReason } from "../utils.js";
|
|
5
|
+
import { MarketParams } from "./MarketParams.js";
|
|
6
|
+
import { MarketUtils } from "./MarketUtils.js";
|
|
7
|
+
/**
|
|
8
|
+
* Represents a lending market on Morpho Blue.
|
|
9
|
+
*/
|
|
10
|
+
export class Market {
|
|
11
|
+
/**
|
|
12
|
+
* The market's params.
|
|
13
|
+
*/
|
|
14
|
+
params;
|
|
15
|
+
/**
|
|
16
|
+
* The amount of loan assets supplied in total on the market.
|
|
17
|
+
*/
|
|
18
|
+
totalSupplyAssets;
|
|
19
|
+
/**
|
|
20
|
+
* The amount of loan assets supplied in total on the market.
|
|
21
|
+
*/
|
|
22
|
+
totalBorrowAssets;
|
|
23
|
+
/**
|
|
24
|
+
* The amount of loan assets supplied in total on the market.
|
|
25
|
+
*/
|
|
26
|
+
totalSupplyShares;
|
|
27
|
+
/**
|
|
28
|
+
* The amount of loan assets supplied in total on the market.
|
|
29
|
+
*/
|
|
30
|
+
totalBorrowShares;
|
|
31
|
+
/**
|
|
32
|
+
* The block timestamp (in __seconds__) when the interest was last accrued.
|
|
33
|
+
*/
|
|
34
|
+
lastUpdate;
|
|
35
|
+
/**
|
|
36
|
+
* The fee percentage of the market, scaled by WAD.
|
|
37
|
+
*/
|
|
38
|
+
fee;
|
|
39
|
+
/**
|
|
40
|
+
* The price as returned by the market's oracle.
|
|
41
|
+
* `undefined` if the oracle is undefined or reverts.
|
|
42
|
+
*/
|
|
43
|
+
price;
|
|
44
|
+
/**
|
|
45
|
+
* If the market uses the Adaptive Curve IRM, the rate at target utilization.
|
|
46
|
+
* Undefined otherwise.
|
|
47
|
+
*/
|
|
48
|
+
rateAtTarget;
|
|
49
|
+
constructor({ params, totalSupplyAssets, totalBorrowAssets, totalSupplyShares, totalBorrowShares, lastUpdate, fee, price, rateAtTarget, }) {
|
|
50
|
+
this.params =
|
|
51
|
+
params instanceof MarketParams ? params : new MarketParams(params);
|
|
52
|
+
this.totalSupplyAssets = totalSupplyAssets;
|
|
53
|
+
this.totalBorrowAssets = totalBorrowAssets;
|
|
54
|
+
this.totalSupplyShares = totalSupplyShares;
|
|
55
|
+
this.totalBorrowShares = totalBorrowShares;
|
|
56
|
+
this.lastUpdate = lastUpdate;
|
|
57
|
+
this.fee = fee;
|
|
58
|
+
this.price = price;
|
|
59
|
+
if (rateAtTarget != null)
|
|
60
|
+
this.rateAtTarget = rateAtTarget;
|
|
61
|
+
}
|
|
62
|
+
/**
|
|
63
|
+
* The market's hex-encoded id, defined as the hash of the market params.
|
|
64
|
+
*/
|
|
65
|
+
get id() {
|
|
66
|
+
return this.params.id;
|
|
67
|
+
}
|
|
68
|
+
/**
|
|
69
|
+
* Whether the market satisfies the canonical definition of an idle market (i.e. collateral token is the zero address).
|
|
70
|
+
*/
|
|
71
|
+
get isIdle() {
|
|
72
|
+
return this.params.collateralToken === ZERO_ADDRESS;
|
|
73
|
+
}
|
|
74
|
+
/**
|
|
75
|
+
* @warning Cannot be used to calculate the liquidity available inside a callback,
|
|
76
|
+
* because the balance of Blue may be lower than the market's liquidity due to assets being transferred out prior to the callback.
|
|
77
|
+
*/
|
|
78
|
+
get liquidity() {
|
|
79
|
+
return this.totalSupplyAssets - this.totalBorrowAssets;
|
|
80
|
+
}
|
|
81
|
+
/**
|
|
82
|
+
* The market's utilization rate (scaled by WAD).
|
|
83
|
+
*/
|
|
84
|
+
get utilization() {
|
|
85
|
+
return MarketUtils.getUtilization(this);
|
|
86
|
+
}
|
|
87
|
+
/**
|
|
88
|
+
* The market's Annual Percentage Yield (APY) at the IRM's target utilization rate, if applicable.
|
|
89
|
+
*/
|
|
90
|
+
get apyAtTarget() {
|
|
91
|
+
if (this.rateAtTarget == null)
|
|
92
|
+
return;
|
|
93
|
+
return MarketUtils.rateToApy(this.rateAtTarget);
|
|
94
|
+
}
|
|
95
|
+
/**
|
|
96
|
+
* Returns the instantaneous rate at which interest accrues for borrowers of this market,
|
|
97
|
+
* if `accrueInterest` was called immediately onchain (scaled by WAD).
|
|
98
|
+
*
|
|
99
|
+
* Even if `accrueInterest` is called immediately onchain,
|
|
100
|
+
* the instantaneous rate only corresponds to an intermediary value used to calculate
|
|
101
|
+
* the actual average rate experienced by borrowers of this market.
|
|
102
|
+
*
|
|
103
|
+
* If interested in the instantaneous rate experienced by existing market actors at a specific timestamp,
|
|
104
|
+
* use `getEndBorrowRate(timestamp)`, `getBorrowApy(timestamp)`, or `getSupplyApy(timestamp)` instead.
|
|
105
|
+
*/
|
|
106
|
+
get endBorrowRate() {
|
|
107
|
+
return this.getAccrualBorrowRates().endBorrowRate;
|
|
108
|
+
}
|
|
109
|
+
/**
|
|
110
|
+
* Returns the average rate at which interest _would_ accrue from `lastUpdate`
|
|
111
|
+
* till now, if `accrueInterest` was called immediately onchain (scaled by WAD).
|
|
112
|
+
* If `accrueInterest` was just called, the average rate equals the instantaneous rate,
|
|
113
|
+
* so it is equivalent to `getBorrowRate(lastUpdate)`.
|
|
114
|
+
*
|
|
115
|
+
* In most cases, `accrueInterest` will not be called immediately onchain,
|
|
116
|
+
* so the average rate is only an intermediary value.
|
|
117
|
+
*
|
|
118
|
+
* If interested in the average rate experienced by existing market actors at a specific timestamp,
|
|
119
|
+
* use `getAvgBorrowRate(timestamp)`, `getAvgBorrowApy(timestamp)`, or `getAvgSupplyApy(timestamp)` instead.
|
|
120
|
+
*/
|
|
121
|
+
get avgBorrowRate() {
|
|
122
|
+
return this.getAccrualBorrowRates().avgBorrowRate;
|
|
123
|
+
}
|
|
124
|
+
/**
|
|
125
|
+
* The market's current, instantaneous supply-side Annual Percentage Yield (APY).
|
|
126
|
+
* If interested in the APY at a specific timestamp, use `getSupplyApy(timestamp)` instead.
|
|
127
|
+
*/
|
|
128
|
+
get supplyApy() {
|
|
129
|
+
return this.getSupplyApy();
|
|
130
|
+
}
|
|
131
|
+
/**
|
|
132
|
+
* The market's current, instantaneous borrow-side Annual Percentage Yield (APY).
|
|
133
|
+
* If interested in the APY at a specific timestamp, use `getBorrowApy(timestamp)` instead.
|
|
134
|
+
*/
|
|
135
|
+
get borrowApy() {
|
|
136
|
+
return this.getBorrowApy();
|
|
137
|
+
}
|
|
138
|
+
/**
|
|
139
|
+
* Returns the instantaneous rate at which interest accrues for borrowers of this market,
|
|
140
|
+
* at the given timestamp, if the state remains unchanged (not accrued) (scaled by WAD).
|
|
141
|
+
* It is fundamentally different from the rate at which interest is paid by borrowers to lenders in the case of an interest accrual,
|
|
142
|
+
* as in the case of the AdaptiveCurveIRM, the (approximated) average rate since the last update is used instead.
|
|
143
|
+
* @param timestamp The timestamp at which to calculate the borrow rate.
|
|
144
|
+
* Must be greater than or equal to `lastUpdate`.
|
|
145
|
+
* Defaults to `Time.timestamp()` (returns the current borrow rate).
|
|
146
|
+
*/
|
|
147
|
+
getEndBorrowRate(timestamp = Time.timestamp()) {
|
|
148
|
+
return this.getAccrualBorrowRates(timestamp).endBorrowRate;
|
|
149
|
+
}
|
|
150
|
+
/**
|
|
151
|
+
* Returns the average rate at which interest _would_ accrue for borrowers of this market,
|
|
152
|
+
* if `accrueInterest` was called at the given timestamp (scaled by WAD).
|
|
153
|
+
* @param timestamp The timestamp at which to calculate the average borrow rate.
|
|
154
|
+
* Must be greater than or equal to `lastUpdate`.
|
|
155
|
+
* Defaults to `Time.timestamp()` (returns the current average borrow rate).
|
|
156
|
+
*/
|
|
157
|
+
getAvgBorrowRate(timestamp = Time.timestamp()) {
|
|
158
|
+
return this.getAccrualBorrowRates(timestamp).avgBorrowRate;
|
|
159
|
+
}
|
|
160
|
+
/**
|
|
161
|
+
* Returns the rates that _would_ apply to interest accrual for borrowers of this market,
|
|
162
|
+
* if `accrueInterest` was called at the given timestamp (scaled by WAD).
|
|
163
|
+
* @param timestamp The timestamp at which to calculate the accrual borrow rate.
|
|
164
|
+
* Must be greater than or equal to `lastUpdate`.
|
|
165
|
+
* Defaults to `Time.timestamp()` (returns the current accrual borrow rate).
|
|
166
|
+
*/
|
|
167
|
+
getAccrualBorrowRates(timestamp = Time.timestamp()) {
|
|
168
|
+
timestamp = BigInt(timestamp);
|
|
169
|
+
const elapsed = timestamp - this.lastUpdate;
|
|
170
|
+
if (elapsed < 0n)
|
|
171
|
+
throw new BlueErrors.InvalidInterestAccrual(this.id, timestamp, this.lastUpdate);
|
|
172
|
+
if (this.rateAtTarget == null)
|
|
173
|
+
return {
|
|
174
|
+
elapsed,
|
|
175
|
+
avgBorrowRate: 0n,
|
|
176
|
+
endBorrowRate: 0n,
|
|
177
|
+
};
|
|
178
|
+
return {
|
|
179
|
+
elapsed,
|
|
180
|
+
...AdaptiveCurveIrmLib.getBorrowRate(this.utilization, this.rateAtTarget, elapsed),
|
|
181
|
+
};
|
|
182
|
+
}
|
|
183
|
+
/**
|
|
184
|
+
* The market's instantaneous borrow-side Annual Percentage Yield (APY) at the given timestamp,
|
|
185
|
+
* if the state remains unchanged (not accrued).
|
|
186
|
+
* @param timestamp The timestamp at which to calculate the borrow APY.
|
|
187
|
+
* Must be greater than or equal to `lastUpdate`.
|
|
188
|
+
* Defaults to `Time.timestamp()` (returns the current borrow APY).
|
|
189
|
+
*/
|
|
190
|
+
getBorrowApy(timestamp = Time.timestamp()) {
|
|
191
|
+
const borrowRate = this.getEndBorrowRate(timestamp);
|
|
192
|
+
return MarketUtils.rateToApy(borrowRate);
|
|
193
|
+
}
|
|
194
|
+
/**
|
|
195
|
+
* The market's instantaneous supply-side Annual Percentage Yield (APY) at the given timestamp,
|
|
196
|
+
* if the state remains unchanged (not accrued).
|
|
197
|
+
* @param timestamp The timestamp at which to calculate the supply APY.
|
|
198
|
+
* Must be greater than or equal to `lastUpdate`.
|
|
199
|
+
* Defaults to `Time.timestamp()` (returns the current supply APY).
|
|
200
|
+
*/
|
|
201
|
+
getSupplyApy(timestamp = Time.timestamp()) {
|
|
202
|
+
const borrowRate = this.getEndBorrowRate(timestamp);
|
|
203
|
+
return MarketUtils.rateToApy(MathLib.wMulUp(MathLib.wMulDown(borrowRate, this.utilization), MathLib.WAD - this.fee));
|
|
204
|
+
}
|
|
205
|
+
/**
|
|
206
|
+
* The market's experienced borrow-side Annual Percentage Yield (APY),
|
|
207
|
+
* if interest was to be accrued at the given timestamp.
|
|
208
|
+
* @param timestamp The timestamp at which to calculate the borrow APY.
|
|
209
|
+
* Must be greater than or equal to `lastUpdate`.
|
|
210
|
+
* Defaults to `Time.timestamp()` (returns the current borrow APY).
|
|
211
|
+
*/
|
|
212
|
+
getAvgBorrowApy(timestamp = Time.timestamp()) {
|
|
213
|
+
const borrowRate = this.getAvgBorrowRate(timestamp);
|
|
214
|
+
return MarketUtils.rateToApy(borrowRate);
|
|
215
|
+
}
|
|
216
|
+
/**
|
|
217
|
+
* Returns the average rate at which interest _would_ accrue for suppliers of this market,
|
|
218
|
+
* if `accrueInterest` was called at the given timestamp (scaled by WAD).
|
|
219
|
+
* @param timestamp The timestamp at which to calculate the average supply rate.
|
|
220
|
+
* Must be greater than or equal to `lastUpdate`.
|
|
221
|
+
* Defaults to `Time.timestamp()` (returns the current average supply rate).
|
|
222
|
+
*/
|
|
223
|
+
getAvgSupplyRate(timestamp = Time.timestamp()) {
|
|
224
|
+
const borrowRate = this.getAvgBorrowRate(timestamp);
|
|
225
|
+
return MathLib.wMulUp(MathLib.wMulDown(borrowRate, this.utilization), MathLib.WAD - this.fee);
|
|
226
|
+
}
|
|
227
|
+
/**
|
|
228
|
+
* The market's experienced supply-side Annual Percentage Yield (APY),
|
|
229
|
+
* if interest was to be accrued at the given timestamp.
|
|
230
|
+
* @param timestamp The timestamp at which to calculate the supply APY.
|
|
231
|
+
* Must be greater than or equal to `lastUpdate`.
|
|
232
|
+
* Defaults to `Time.timestamp()` (returns the current supply APY).
|
|
233
|
+
*/
|
|
234
|
+
getAvgSupplyApy(timestamp = Time.timestamp()) {
|
|
235
|
+
return MarketUtils.rateToApy(this.getAvgSupplyRate(timestamp));
|
|
236
|
+
}
|
|
237
|
+
/**
|
|
238
|
+
* Returns a new market derived from this market, whose interest has been accrued up to the given timestamp.
|
|
239
|
+
* @param timestamp The timestamp at which to accrue interest.
|
|
240
|
+
* Must be greater than or equal to `lastUpdate`.
|
|
241
|
+
* Defaults to `lastUpdate` (returns a copy of the market).
|
|
242
|
+
*/
|
|
243
|
+
accrueInterest(timestamp = this.lastUpdate) {
|
|
244
|
+
timestamp = BigInt(timestamp);
|
|
245
|
+
const { elapsed, avgBorrowRate, endRateAtTarget } = this.getAccrualBorrowRates(timestamp);
|
|
246
|
+
const { interest, feeShares } = MarketUtils.getAccruedInterest(avgBorrowRate, this, elapsed);
|
|
247
|
+
return new Market({
|
|
248
|
+
...this,
|
|
249
|
+
totalSupplyAssets: this.totalSupplyAssets + interest,
|
|
250
|
+
totalBorrowAssets: this.totalBorrowAssets + interest,
|
|
251
|
+
totalSupplyShares: this.totalSupplyShares + feeShares,
|
|
252
|
+
lastUpdate: timestamp,
|
|
253
|
+
rateAtTarget: endRateAtTarget,
|
|
254
|
+
});
|
|
255
|
+
}
|
|
256
|
+
supply(assets, shares, timestamp) {
|
|
257
|
+
if ((assets === 0n) === (shares === 0n))
|
|
258
|
+
throw new BlueErrors.InconsistentInput(assets, shares);
|
|
259
|
+
const market = this.accrueInterest(timestamp);
|
|
260
|
+
if (shares === 0n)
|
|
261
|
+
shares = market.toSupplyShares(assets, "Down");
|
|
262
|
+
else
|
|
263
|
+
assets = market.toSupplyAssets(shares, "Up");
|
|
264
|
+
market.totalSupplyAssets += assets;
|
|
265
|
+
market.totalSupplyShares += shares;
|
|
266
|
+
return { market, assets, shares };
|
|
267
|
+
}
|
|
268
|
+
withdraw(assets, shares, timestamp) {
|
|
269
|
+
if ((assets === 0n) === (shares === 0n))
|
|
270
|
+
throw new BlueErrors.InconsistentInput(assets, shares);
|
|
271
|
+
const market = this.accrueInterest(timestamp);
|
|
272
|
+
if (shares === 0n)
|
|
273
|
+
shares = market.toSupplyShares(assets, "Up");
|
|
274
|
+
else
|
|
275
|
+
assets = market.toSupplyAssets(shares, "Down");
|
|
276
|
+
market.totalSupplyAssets -= assets;
|
|
277
|
+
market.totalSupplyShares -= shares;
|
|
278
|
+
if (market.totalBorrowAssets > market.totalSupplyAssets)
|
|
279
|
+
throw new BlueErrors.InsufficientLiquidity(market.id);
|
|
280
|
+
return { market, assets, shares };
|
|
281
|
+
}
|
|
282
|
+
borrow(assets, shares, timestamp) {
|
|
283
|
+
if ((assets === 0n) === (shares === 0n))
|
|
284
|
+
throw new BlueErrors.InconsistentInput(assets, shares);
|
|
285
|
+
const market = this.accrueInterest(timestamp);
|
|
286
|
+
if (shares === 0n)
|
|
287
|
+
shares = market.toBorrowShares(assets, "Up");
|
|
288
|
+
else
|
|
289
|
+
assets = market.toBorrowAssets(shares, "Down");
|
|
290
|
+
market.totalBorrowAssets += assets;
|
|
291
|
+
market.totalBorrowShares += shares;
|
|
292
|
+
if (market.totalBorrowAssets > market.totalSupplyAssets)
|
|
293
|
+
throw new BlueErrors.InsufficientLiquidity(market.id);
|
|
294
|
+
return { market, assets, shares };
|
|
295
|
+
}
|
|
296
|
+
repay(assets, shares, timestamp) {
|
|
297
|
+
if ((assets === 0n) === (shares === 0n))
|
|
298
|
+
throw new BlueErrors.InconsistentInput(assets, shares);
|
|
299
|
+
const market = this.accrueInterest(timestamp);
|
|
300
|
+
if (shares === 0n)
|
|
301
|
+
shares = market.toBorrowShares(assets, "Down");
|
|
302
|
+
else
|
|
303
|
+
assets = market.toBorrowAssets(shares, "Up");
|
|
304
|
+
market.totalBorrowAssets -= assets;
|
|
305
|
+
market.totalBorrowShares -= shares;
|
|
306
|
+
return { market, assets, shares };
|
|
307
|
+
}
|
|
308
|
+
/**
|
|
309
|
+
* Converts a given amount of supply shares into supply loan assets.
|
|
310
|
+
* @param shares The amount of shares to convert.
|
|
311
|
+
* @param rounding The rounding direction to use (defaults to "Down").
|
|
312
|
+
*/
|
|
313
|
+
toSupplyAssets(shares, rounding) {
|
|
314
|
+
return MarketUtils.toSupplyAssets(shares, this, rounding);
|
|
315
|
+
}
|
|
316
|
+
/**
|
|
317
|
+
* Converts a given amount of supply loan assets into supply shares.
|
|
318
|
+
* @param shares The amount of assets to convert.
|
|
319
|
+
* @param rounding The rounding direction to use (defaults to "Up").
|
|
320
|
+
*/
|
|
321
|
+
toSupplyShares(assets, rounding) {
|
|
322
|
+
return MarketUtils.toSupplyShares(assets, this, rounding);
|
|
323
|
+
}
|
|
324
|
+
/**
|
|
325
|
+
* Converts a given amount of borrow shares into borrow loan assets.
|
|
326
|
+
* @param shares The amount of shares to convert.
|
|
327
|
+
* @param rounding The rounding direction to use (defaults to "Up").
|
|
328
|
+
*/
|
|
329
|
+
toBorrowAssets(shares, rounding) {
|
|
330
|
+
return MarketUtils.toBorrowAssets(shares, this, rounding);
|
|
331
|
+
}
|
|
332
|
+
/**
|
|
333
|
+
* Converts a given amount of borrow loan assets into borrow shares.
|
|
334
|
+
* @param shares The amount of assets to convert.
|
|
335
|
+
* @param rounding The rounding direction to use (defaults to "Down").
|
|
336
|
+
*/
|
|
337
|
+
toBorrowShares(assets, rounding) {
|
|
338
|
+
return MarketUtils.toBorrowShares(assets, this, rounding);
|
|
339
|
+
}
|
|
340
|
+
/**
|
|
341
|
+
* Returns the smallest volume to supply until the market gets the closest to the given utilization rate.
|
|
342
|
+
* @param utilization The target utilization rate (scaled by WAD).
|
|
343
|
+
*/
|
|
344
|
+
getSupplyToUtilization(utilization) {
|
|
345
|
+
return MarketUtils.getSupplyToUtilization(this, utilization);
|
|
346
|
+
}
|
|
347
|
+
/**
|
|
348
|
+
* Returns the liquidity available to withdraw until the market gets the closest to the given utilization rate.
|
|
349
|
+
* @param utilization The target utilization rate (scaled by WAD).
|
|
350
|
+
*/
|
|
351
|
+
getWithdrawToUtilization(utilization) {
|
|
352
|
+
return MarketUtils.getWithdrawToUtilization(this, utilization);
|
|
353
|
+
}
|
|
354
|
+
/**
|
|
355
|
+
* Returns the liquidity available to borrow until the market gets the closest to the given utilization rate.
|
|
356
|
+
* @param utilization The target utilization rate (scaled by WAD).
|
|
357
|
+
*/
|
|
358
|
+
getBorrowToUtilization(utilization) {
|
|
359
|
+
return MarketUtils.getBorrowToUtilization(this, utilization);
|
|
360
|
+
}
|
|
361
|
+
/**
|
|
362
|
+
* Returns the smallest volume to repay until the market gets the closest to the given utilization rate.
|
|
363
|
+
* @param utilization The target utilization rate (scaled by WAD).
|
|
364
|
+
*/
|
|
365
|
+
getRepayToUtilization(utilization) {
|
|
366
|
+
return MarketUtils.getRepayToUtilization(this, utilization);
|
|
367
|
+
}
|
|
368
|
+
/**
|
|
369
|
+
* Returns the value of a given amount of collateral quoted in loan assets.
|
|
370
|
+
* `undefined` iff the market's oracle is undefined or reverts.
|
|
371
|
+
* @param collateral The amount of collateral to quote.
|
|
372
|
+
*/
|
|
373
|
+
getCollateralValue(collateral) {
|
|
374
|
+
return MarketUtils.getCollateralValue(collateral, this);
|
|
375
|
+
}
|
|
376
|
+
/**
|
|
377
|
+
* Returns the maximum debt allowed given a certain amount of collateral.
|
|
378
|
+
* `undefined` iff the market's oracle is undefined or reverts.
|
|
379
|
+
* To calculate the amount of loan assets that can be borrowed, use `getMaxBorrowableAssets`.
|
|
380
|
+
* @param collateral The amount of collateral to consider.
|
|
381
|
+
*/
|
|
382
|
+
getMaxBorrowAssets(collateral, { maxLtv = this.params.lltv } = {}) {
|
|
383
|
+
return MarketUtils.getMaxBorrowAssets(collateral, this, {
|
|
384
|
+
lltv: MathLib.min(maxLtv, this.params.lltv),
|
|
385
|
+
});
|
|
386
|
+
}
|
|
387
|
+
/**
|
|
388
|
+
* Returns the maximum amount of loan assets that can be borrowed given a certain borrow position.
|
|
389
|
+
* `undefined` iff the market's oracle is undefined or reverts.
|
|
390
|
+
* @param position The borrow position to consider.
|
|
391
|
+
*/
|
|
392
|
+
getMaxBorrowableAssets(position) {
|
|
393
|
+
return MarketUtils.getMaxBorrowableAssets(position, this, this.params);
|
|
394
|
+
}
|
|
395
|
+
/**
|
|
396
|
+
* Returns the amount of collateral that would be seized in a liquidation given a certain amount of repaid shares.
|
|
397
|
+
* `undefined` iff the market's oracle is undefined or reverts.
|
|
398
|
+
* @param repaidShares The amount of shares hypothetically repaid.
|
|
399
|
+
*/
|
|
400
|
+
getLiquidationSeizedAssets(repaidShares) {
|
|
401
|
+
return MarketUtils.getLiquidationSeizedAssets(repaidShares, this, this.params);
|
|
402
|
+
}
|
|
403
|
+
/**
|
|
404
|
+
* Returns the amount of borrow shares that would be repaid in a liquidation given a certain amount of seized collateral.
|
|
405
|
+
* `undefined` iff the market's oracle is undefined or reverts.
|
|
406
|
+
* @param seizedAssets The amount of collateral hypothetically seized.
|
|
407
|
+
*/
|
|
408
|
+
getLiquidationRepaidShares(seizedAssets) {
|
|
409
|
+
return MarketUtils.getLiquidationRepaidShares(seizedAssets, this, this.params);
|
|
410
|
+
}
|
|
411
|
+
/**
|
|
412
|
+
* Returns the maximum amount of collateral that is worth being seized in a liquidation given a certain borrow position.
|
|
413
|
+
* `undefined` iff the market's oracle is undefined or reverts.
|
|
414
|
+
* @param position The borrow position to consider.
|
|
415
|
+
*/
|
|
416
|
+
getSeizableCollateral(position) {
|
|
417
|
+
return MarketUtils.getSeizableCollateral(position, this, this.params);
|
|
418
|
+
}
|
|
419
|
+
/**
|
|
420
|
+
* Returns the amount of collateral that can be withdrawn given a certain borrow position.
|
|
421
|
+
* `undefined` iff the market's oracle is undefined or reverts.
|
|
422
|
+
* @param position The borrow position to consider.
|
|
423
|
+
*/
|
|
424
|
+
getWithdrawableCollateral(position, { maxLtv = this.params.lltv } = {}) {
|
|
425
|
+
return MarketUtils.getWithdrawableCollateral(position, this, {
|
|
426
|
+
lltv: MathLib.min(maxLtv, this.params.lltv),
|
|
427
|
+
});
|
|
428
|
+
}
|
|
429
|
+
/**
|
|
430
|
+
* Returns whether a given borrow position is healthy.
|
|
431
|
+
* `undefined` iff the market's oracle is undefined or reverts.
|
|
432
|
+
* @param position The borrow position to check.
|
|
433
|
+
*/
|
|
434
|
+
isHealthy(position) {
|
|
435
|
+
return MarketUtils.isHealthy(position, this, this.params);
|
|
436
|
+
}
|
|
437
|
+
/**
|
|
438
|
+
* Returns the liquidation price of a given borrow position.
|
|
439
|
+
* @param position The borrow position to consider.
|
|
440
|
+
*/
|
|
441
|
+
getLiquidationPrice(position) {
|
|
442
|
+
return MarketUtils.getLiquidationPrice(position, this, this.params);
|
|
443
|
+
}
|
|
444
|
+
/**
|
|
445
|
+
* Returns the price variation required for the given position to reach its liquidation threshold (scaled by WAD).
|
|
446
|
+
* Negative when healthy (the price needs to drop x%), positive when unhealthy (the price needs to soar x%).
|
|
447
|
+
* Returns `undefined` iff the market's price is undefined.
|
|
448
|
+
* Returns null if the position is not a borrow.
|
|
449
|
+
* @param position The borrow position to consider.
|
|
450
|
+
*/
|
|
451
|
+
getPriceVariationToLiquidationPrice(position) {
|
|
452
|
+
return MarketUtils.getPriceVariationToLiquidationPrice(position, this, this.params);
|
|
453
|
+
}
|
|
454
|
+
/**
|
|
455
|
+
* Returns the health factor of a given borrow position (scaled by WAD).
|
|
456
|
+
* @param position The borrow position to consider.
|
|
457
|
+
*/
|
|
458
|
+
getHealthFactor(position) {
|
|
459
|
+
return MarketUtils.getHealthFactor(position, this, this.params);
|
|
460
|
+
}
|
|
461
|
+
/**
|
|
462
|
+
* Returns the loan-to-value ratio of a given borrow position (scaled by WAD).
|
|
463
|
+
* @param position The borrow position to consider.
|
|
464
|
+
*/
|
|
465
|
+
getLtv(position) {
|
|
466
|
+
return MarketUtils.getLtv(position, this);
|
|
467
|
+
}
|
|
468
|
+
/**
|
|
469
|
+
* Returns the usage ratio of the maximum borrow capacity given a certain borrow position (scaled by WAD).
|
|
470
|
+
* @param position The borrow position to consider.
|
|
471
|
+
*/
|
|
472
|
+
getBorrowCapacityUsage(position) {
|
|
473
|
+
return MarketUtils.getBorrowCapacityUsage(position, this, this.params);
|
|
474
|
+
}
|
|
475
|
+
/**
|
|
476
|
+
* Returns the maximum amount of loan assets that can be borrowed given a certain borrow position
|
|
477
|
+
* and the reason for the limit.
|
|
478
|
+
* Returns `undefined` iff the market's price is undefined.
|
|
479
|
+
* @param position The borrow position to consider.
|
|
480
|
+
*/
|
|
481
|
+
getBorrowCapacityLimit({ collateral, borrowShares = 0n, }, options) {
|
|
482
|
+
const maxBorrowAssets = this.getMaxBorrowAssets(collateral, options);
|
|
483
|
+
if (maxBorrowAssets == null)
|
|
484
|
+
return;
|
|
485
|
+
// handle edge cases when the user is liquidatable (maxBorrow < borrow)
|
|
486
|
+
const maxBorrowableAssets = MathLib.zeroFloorSub(maxBorrowAssets, this.toBorrowAssets(borrowShares));
|
|
487
|
+
const { liquidity } = this;
|
|
488
|
+
if (maxBorrowableAssets > liquidity)
|
|
489
|
+
return {
|
|
490
|
+
value: liquidity,
|
|
491
|
+
limiter: CapacityLimitReason.liquidity,
|
|
492
|
+
};
|
|
493
|
+
return {
|
|
494
|
+
value: maxBorrowableAssets,
|
|
495
|
+
limiter: CapacityLimitReason.collateral,
|
|
496
|
+
};
|
|
497
|
+
}
|
|
498
|
+
/**
|
|
499
|
+
* Returns the maximum amount of loan assets that can be repaid given a certain borrow position
|
|
500
|
+
* and a balance of loan assets, and the reason for the limit.
|
|
501
|
+
* @param position The borrow position to consider.
|
|
502
|
+
*/
|
|
503
|
+
getRepayCapacityLimit(borrowShares, loanTokenBalance) {
|
|
504
|
+
const borrowAssets = this.toBorrowAssets(borrowShares);
|
|
505
|
+
if (borrowAssets > loanTokenBalance)
|
|
506
|
+
return {
|
|
507
|
+
value: loanTokenBalance,
|
|
508
|
+
limiter: CapacityLimitReason.balance,
|
|
509
|
+
};
|
|
510
|
+
return {
|
|
511
|
+
value: borrowAssets,
|
|
512
|
+
limiter: CapacityLimitReason.position,
|
|
513
|
+
};
|
|
514
|
+
}
|
|
515
|
+
/**
|
|
516
|
+
* Returns the maximum amount of loan assets that can be withdrawn given a certain supply position
|
|
517
|
+
* and a balance of loan assets, and the reason for the limit.
|
|
518
|
+
* @param position The supply position to consider.
|
|
519
|
+
*/
|
|
520
|
+
getWithdrawCapacityLimit({ supplyShares, }) {
|
|
521
|
+
const supplyAssets = this.toSupplyAssets(supplyShares);
|
|
522
|
+
const { liquidity } = this;
|
|
523
|
+
if (supplyAssets > liquidity)
|
|
524
|
+
return {
|
|
525
|
+
value: liquidity,
|
|
526
|
+
limiter: CapacityLimitReason.liquidity,
|
|
527
|
+
};
|
|
528
|
+
return {
|
|
529
|
+
value: supplyAssets,
|
|
530
|
+
limiter: CapacityLimitReason.position,
|
|
531
|
+
};
|
|
532
|
+
}
|
|
533
|
+
/**
|
|
534
|
+
* Returns the maximum amount of collateral assets that can be withdrawn given a certain borrow position
|
|
535
|
+
* and the reason for the limit.
|
|
536
|
+
* Returns `undefined` iff the market's price is undefined.
|
|
537
|
+
* @param position The borrow position to consider.
|
|
538
|
+
*/
|
|
539
|
+
getWithdrawCollateralCapacityLimit(position, options) {
|
|
540
|
+
const withdrawableCollateral = this.getWithdrawableCollateral(position, options);
|
|
541
|
+
if (withdrawableCollateral == null)
|
|
542
|
+
return;
|
|
543
|
+
if (position.collateral > withdrawableCollateral)
|
|
544
|
+
return {
|
|
545
|
+
value: withdrawableCollateral,
|
|
546
|
+
limiter: CapacityLimitReason.collateral,
|
|
547
|
+
};
|
|
548
|
+
return {
|
|
549
|
+
value: position.collateral,
|
|
550
|
+
limiter: CapacityLimitReason.position,
|
|
551
|
+
};
|
|
552
|
+
}
|
|
553
|
+
/**
|
|
554
|
+
* Returns the maximum capacity for all interactions with Morpho Blue given a certain position
|
|
555
|
+
* and loan and collateral balances.
|
|
556
|
+
* @param position The position to consider.
|
|
557
|
+
* @param loanTokenBalance The balance of loan assets.
|
|
558
|
+
* @param collateralTokenBalance The balance of collateral assets.
|
|
559
|
+
*/
|
|
560
|
+
getMaxCapacities(position, loanTokenBalance, collateralTokenBalance, options) {
|
|
561
|
+
return {
|
|
562
|
+
supply: {
|
|
563
|
+
value: loanTokenBalance,
|
|
564
|
+
limiter: CapacityLimitReason.balance,
|
|
565
|
+
},
|
|
566
|
+
withdraw: this.getWithdrawCapacityLimit(position),
|
|
567
|
+
borrow: this.getBorrowCapacityLimit(position, options?.borrow),
|
|
568
|
+
repay: this.getRepayCapacityLimit(position.borrowShares, loanTokenBalance),
|
|
569
|
+
supplyCollateral: {
|
|
570
|
+
value: collateralTokenBalance,
|
|
571
|
+
limiter: CapacityLimitReason.balance,
|
|
572
|
+
},
|
|
573
|
+
withdrawCollateral: this.getWithdrawCollateralCapacityLimit(position, options?.withdrawCollateral),
|
|
574
|
+
};
|
|
575
|
+
}
|
|
576
|
+
}
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
import type { Address, BigIntish, MarketId } from "../types.js";
|
|
2
|
+
import { type Hex } from "viem";
|
|
3
|
+
export interface IMarketParams {
|
|
4
|
+
loanToken: Address;
|
|
5
|
+
collateralToken: Address;
|
|
6
|
+
oracle: Address;
|
|
7
|
+
irm: Address;
|
|
8
|
+
lltv: BigIntish;
|
|
9
|
+
}
|
|
10
|
+
export type InputMarketParams = Pick<MarketParams, "loanToken" | "collateralToken" | "oracle" | "irm" | "lltv">;
|
|
11
|
+
export declare const marketParamsAbi: {
|
|
12
|
+
readonly type: "tuple";
|
|
13
|
+
readonly components: readonly [{
|
|
14
|
+
readonly type: "address";
|
|
15
|
+
readonly name: "loanToken";
|
|
16
|
+
}, {
|
|
17
|
+
readonly type: "address";
|
|
18
|
+
readonly name: "collateralToken";
|
|
19
|
+
}, {
|
|
20
|
+
readonly type: "address";
|
|
21
|
+
readonly name: "oracle";
|
|
22
|
+
}, {
|
|
23
|
+
readonly type: "address";
|
|
24
|
+
readonly name: "irm";
|
|
25
|
+
}, {
|
|
26
|
+
readonly type: "uint256";
|
|
27
|
+
readonly name: "lltv";
|
|
28
|
+
}];
|
|
29
|
+
};
|
|
30
|
+
/**
|
|
31
|
+
* Represents a market's configuration (also called market params).
|
|
32
|
+
*/
|
|
33
|
+
export declare class MarketParams implements IMarketParams {
|
|
34
|
+
private static readonly _CACHE;
|
|
35
|
+
/**
|
|
36
|
+
* Returns the previously cached market config for the given id, if any.
|
|
37
|
+
* @throws {UnknownMarketParamsError} If no market config is cached.
|
|
38
|
+
*/
|
|
39
|
+
static get(id: MarketId): MarketParams;
|
|
40
|
+
/**
|
|
41
|
+
* Returns the canonical idle market configuration for the given loan token.
|
|
42
|
+
*/
|
|
43
|
+
static idle(token: Address): MarketParams;
|
|
44
|
+
static fromHex(data: Hex): MarketParams;
|
|
45
|
+
/**
|
|
46
|
+
* The market's collateral token address.
|
|
47
|
+
*/
|
|
48
|
+
readonly collateralToken: Address;
|
|
49
|
+
/**
|
|
50
|
+
* The market's loan token address.
|
|
51
|
+
*/
|
|
52
|
+
readonly loanToken: Address;
|
|
53
|
+
/**
|
|
54
|
+
* The market's oracle address.
|
|
55
|
+
*/
|
|
56
|
+
readonly oracle: Address;
|
|
57
|
+
/**
|
|
58
|
+
* The market's interest rate model address.
|
|
59
|
+
*/
|
|
60
|
+
readonly irm: Address;
|
|
61
|
+
/**
|
|
62
|
+
* The market's liquidation Loan-To-Value (scaled by WAD).
|
|
63
|
+
*/
|
|
64
|
+
readonly lltv: bigint;
|
|
65
|
+
/**
|
|
66
|
+
* The market's hex-encoded id, defined as the hash of the market params.
|
|
67
|
+
*/
|
|
68
|
+
readonly id: MarketId;
|
|
69
|
+
/**
|
|
70
|
+
* The market's liquidation incentive factor.
|
|
71
|
+
*/
|
|
72
|
+
readonly liquidationIncentiveFactor: bigint;
|
|
73
|
+
constructor(params: IMarketParams);
|
|
74
|
+
}
|