@morpho-org/blue-sdk 4.4.0 → 4.5.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/market/Market.d.ts +68 -14
- package/lib/market/Market.js +87 -26
- package/package.json +1 -1
package/lib/market/Market.d.ts
CHANGED
|
@@ -107,19 +107,35 @@ export declare class Market implements IMarket {
|
|
|
107
107
|
* @deprecated There's no such thing as a supply rate in Morpho. Only the supply APY is meaningful.
|
|
108
108
|
*/
|
|
109
109
|
get supplyRate(): bigint;
|
|
110
|
+
/**
|
|
111
|
+
* @deprecated Use `avgBorrowRate` instead.
|
|
112
|
+
*/
|
|
113
|
+
get borrowRate(): bigint;
|
|
114
|
+
/**
|
|
115
|
+
* Returns the instantaneous rate at which interest accrues for borrowers of this market,
|
|
116
|
+
* if `accrueInterest` was called immediately onchain (scaled by WAD).
|
|
117
|
+
*
|
|
118
|
+
* Even if `accrueInterest` is called immediately onchain,
|
|
119
|
+
* the instantaneous rate only corresponds to an intermediary value used to calculate
|
|
120
|
+
* the actual average rate experienced by borrowers of this market.
|
|
121
|
+
*
|
|
122
|
+
* If interested in the instantaneous rate experienced by existing market actors at a specific timestamp,
|
|
123
|
+
* use `getEndBorrowRate(timestamp)`, `getBorrowApy(timestamp)`, or `getSupplyApy(timestamp)` instead.
|
|
124
|
+
*/
|
|
125
|
+
get endBorrowRate(): bigint;
|
|
110
126
|
/**
|
|
111
127
|
* Returns the average rate at which interest _would_ accrue from `lastUpdate`
|
|
112
128
|
* till now, if `accrueInterest` was called immediately onchain (scaled by WAD).
|
|
113
129
|
* If `accrueInterest` was just called, the average rate equals the instantaneous rate,
|
|
114
130
|
* so it is equivalent to `getBorrowRate(lastUpdate)`.
|
|
115
131
|
*
|
|
116
|
-
* In most cases, `accrueInterest` will not be called immediately onchain,
|
|
117
|
-
* average rate
|
|
132
|
+
* In most cases, `accrueInterest` will not be called immediately onchain,
|
|
133
|
+
* so the average rate is only an intermediary value.
|
|
118
134
|
*
|
|
119
|
-
* If interested in the
|
|
120
|
-
* use `
|
|
135
|
+
* If interested in the average rate experienced by existing market actors at a specific timestamp,
|
|
136
|
+
* use `getAvgBorrowRate(timestamp)`, `getAvgBorrowApy(timestamp)`, or `getAvgSupplyApy(timestamp)` instead.
|
|
121
137
|
*/
|
|
122
|
-
get
|
|
138
|
+
get avgBorrowRate(): bigint;
|
|
123
139
|
/**
|
|
124
140
|
* The market's current, instantaneous supply-side Annual Percentage Yield (APY) (scaled by WAD).
|
|
125
141
|
* If interested in the APY at a specific timestamp, use `getSupplyApy(timestamp)` instead.
|
|
@@ -130,20 +146,36 @@ export declare class Market implements IMarket {
|
|
|
130
146
|
* If interested in the APY at a specific timestamp, use `getBorrowApy(timestamp)` instead.
|
|
131
147
|
*/
|
|
132
148
|
get borrowApy(): bigint;
|
|
149
|
+
/**
|
|
150
|
+
* @deprecated Use `getEndBorrowRate(timestamp)` instead.
|
|
151
|
+
*/
|
|
152
|
+
getBorrowRate(timestamp?: BigIntish): bigint;
|
|
133
153
|
/**
|
|
134
154
|
* Returns the instantaneous rate at which interest accrues for borrowers of this market,
|
|
135
155
|
* at the given timestamp, if the state remains unchanged (not accrued) (scaled by WAD).
|
|
136
156
|
* It is fundamentally different from the rate at which interest is paid by borrowers to lenders in the case of an interest accrual,
|
|
137
157
|
* as in the case of the AdaptiveCurveIRM, the (approximated) average rate since the last update is used instead.
|
|
138
|
-
* @param timestamp The timestamp at which to calculate the borrow rate.
|
|
158
|
+
* @param timestamp The timestamp at which to calculate the borrow rate.
|
|
159
|
+
* Must be greater than or equal to `lastUpdate`.
|
|
160
|
+
* Defaults to `Time.timestamp()` (returns the current borrow rate).
|
|
139
161
|
*/
|
|
140
|
-
|
|
162
|
+
getEndBorrowRate(timestamp?: BigIntish): bigint;
|
|
141
163
|
/**
|
|
142
|
-
* Returns the rate at which interest
|
|
143
|
-
*
|
|
144
|
-
* @param timestamp The timestamp at which to calculate the
|
|
164
|
+
* Returns the average rate at which interest _would_ accrue for borrowers of this market,
|
|
165
|
+
* if `accrueInterest` was called at the given timestamp (scaled by WAD).
|
|
166
|
+
* @param timestamp The timestamp at which to calculate the average borrow rate.
|
|
167
|
+
* Must be greater than or equal to `lastUpdate`.
|
|
168
|
+
* Defaults to `Time.timestamp()` (returns the current average borrow rate).
|
|
145
169
|
*/
|
|
146
|
-
|
|
170
|
+
getAvgBorrowRate(timestamp?: BigIntish): bigint;
|
|
171
|
+
/**
|
|
172
|
+
* Returns the rates that _would_ apply to interest accrual for borrowers of this market,
|
|
173
|
+
* if `accrueInterest` was called at the given timestamp (scaled by WAD).
|
|
174
|
+
* @param timestamp The timestamp at which to calculate the accrual borrow rate.
|
|
175
|
+
* Must be greater than or equal to `lastUpdate`.
|
|
176
|
+
* Defaults to `Time.timestamp()` (returns the current accrual borrow rate).
|
|
177
|
+
*/
|
|
178
|
+
protected getAccrualBorrowRates(timestamp?: BigIntish): {
|
|
147
179
|
elapsed: bigint;
|
|
148
180
|
avgBorrowRate: bigint;
|
|
149
181
|
endBorrowRate: bigint;
|
|
@@ -152,18 +184,40 @@ export declare class Market implements IMarket {
|
|
|
152
184
|
/**
|
|
153
185
|
* The market's instantaneous borrow-side Annual Percentage Yield (APY) at the given timestamp,
|
|
154
186
|
* if the state remains unchanged (not accrued) (scaled by WAD).
|
|
155
|
-
* @param timestamp The timestamp at which to calculate the borrow APY.
|
|
187
|
+
* @param timestamp The timestamp at which to calculate the borrow APY.
|
|
188
|
+
* Must be greater than or equal to `lastUpdate`.
|
|
189
|
+
* Defaults to `Time.timestamp()` (returns the current borrow APY).
|
|
156
190
|
*/
|
|
157
191
|
getBorrowApy(timestamp?: BigIntish): bigint;
|
|
158
192
|
/**
|
|
159
193
|
* The market's instantaneous supply-side Annual Percentage Yield (APY) at the given timestamp,
|
|
160
194
|
* if the state remains unchanged (not accrued) (scaled by WAD).
|
|
161
|
-
* @param timestamp The timestamp at which to calculate the supply APY.
|
|
195
|
+
* @param timestamp The timestamp at which to calculate the supply APY.
|
|
196
|
+
* Must be greater than or equal to `lastUpdate`.
|
|
197
|
+
* Defaults to `Time.timestamp()` (returns the current supply APY).
|
|
162
198
|
*/
|
|
163
199
|
getSupplyApy(timestamp?: BigIntish): bigint;
|
|
200
|
+
/**
|
|
201
|
+
* The market's experienced borrow-side Annual Percentage Yield (APY),
|
|
202
|
+
* if interest was to be accrued at the given timestamp (scaled by WAD).
|
|
203
|
+
* @param timestamp The timestamp at which to calculate the borrow APY.
|
|
204
|
+
* Must be greater than or equal to `lastUpdate`.
|
|
205
|
+
* Defaults to `Time.timestamp()` (returns the current borrow APY).
|
|
206
|
+
*/
|
|
207
|
+
getAvgBorrowApy(timestamp?: BigIntish): bigint;
|
|
208
|
+
/**
|
|
209
|
+
* The market's experienced supply-side Annual Percentage Yield (APY),
|
|
210
|
+
* if interest was to be accrued at the given timestamp (scaled by WAD).
|
|
211
|
+
* @param timestamp The timestamp at which to calculate the supply APY.
|
|
212
|
+
* Must be greater than or equal to `lastUpdate`.
|
|
213
|
+
* Defaults to `Time.timestamp()` (returns the current supply APY).
|
|
214
|
+
*/
|
|
215
|
+
getAvgSupplyApy(timestamp?: BigIntish): bigint;
|
|
164
216
|
/**
|
|
165
217
|
* Returns a new market derived from this market, whose interest has been accrued up to the given timestamp.
|
|
166
|
-
* @param timestamp The timestamp at which to accrue interest.
|
|
218
|
+
* @param timestamp The timestamp at which to accrue interest.
|
|
219
|
+
* Must be greater than or equal to `lastUpdate`.
|
|
220
|
+
* Defaults to `lastUpdate` (returns a copy of the market).
|
|
167
221
|
*/
|
|
168
222
|
accrueInterest(timestamp?: BigIntish): Market;
|
|
169
223
|
supply(assets: bigint, shares: bigint, timestamp?: BigIntish): {
|
package/lib/market/Market.js
CHANGED
|
@@ -107,7 +107,27 @@ class Market {
|
|
|
107
107
|
* @deprecated There's no such thing as a supply rate in Morpho. Only the supply APY is meaningful.
|
|
108
108
|
*/
|
|
109
109
|
get supplyRate() {
|
|
110
|
-
return MarketUtils_js_1.MarketUtils.getSupplyRate(this.
|
|
110
|
+
return MarketUtils_js_1.MarketUtils.getSupplyRate(this.avgBorrowRate, this);
|
|
111
|
+
}
|
|
112
|
+
/**
|
|
113
|
+
* @deprecated Use `avgBorrowRate` instead.
|
|
114
|
+
*/
|
|
115
|
+
get borrowRate() {
|
|
116
|
+
return this.getAccrualBorrowRates().avgBorrowRate;
|
|
117
|
+
}
|
|
118
|
+
/**
|
|
119
|
+
* Returns the instantaneous rate at which interest accrues for borrowers of this market,
|
|
120
|
+
* if `accrueInterest` was called immediately onchain (scaled by WAD).
|
|
121
|
+
*
|
|
122
|
+
* Even if `accrueInterest` is called immediately onchain,
|
|
123
|
+
* the instantaneous rate only corresponds to an intermediary value used to calculate
|
|
124
|
+
* the actual average rate experienced by borrowers of this market.
|
|
125
|
+
*
|
|
126
|
+
* If interested in the instantaneous rate experienced by existing market actors at a specific timestamp,
|
|
127
|
+
* use `getEndBorrowRate(timestamp)`, `getBorrowApy(timestamp)`, or `getSupplyApy(timestamp)` instead.
|
|
128
|
+
*/
|
|
129
|
+
get endBorrowRate() {
|
|
130
|
+
return this.getAccrualBorrowRates().endBorrowRate;
|
|
111
131
|
}
|
|
112
132
|
/**
|
|
113
133
|
* Returns the average rate at which interest _would_ accrue from `lastUpdate`
|
|
@@ -115,14 +135,14 @@ class Market {
|
|
|
115
135
|
* If `accrueInterest` was just called, the average rate equals the instantaneous rate,
|
|
116
136
|
* so it is equivalent to `getBorrowRate(lastUpdate)`.
|
|
117
137
|
*
|
|
118
|
-
* In most cases, `accrueInterest` will not be called immediately onchain,
|
|
119
|
-
* average rate
|
|
138
|
+
* In most cases, `accrueInterest` will not be called immediately onchain,
|
|
139
|
+
* so the average rate is only an intermediary value.
|
|
120
140
|
*
|
|
121
|
-
* If interested in the
|
|
122
|
-
* use `
|
|
141
|
+
* If interested in the average rate experienced by existing market actors at a specific timestamp,
|
|
142
|
+
* use `getAvgBorrowRate(timestamp)`, `getAvgBorrowApy(timestamp)`, or `getAvgSupplyApy(timestamp)` instead.
|
|
123
143
|
*/
|
|
124
|
-
get
|
|
125
|
-
return this.
|
|
144
|
+
get avgBorrowRate() {
|
|
145
|
+
return this.getAccrualBorrowRates().avgBorrowRate;
|
|
126
146
|
}
|
|
127
147
|
/**
|
|
128
148
|
* The market's current, instantaneous supply-side Annual Percentage Yield (APY) (scaled by WAD).
|
|
@@ -138,29 +158,42 @@ class Market {
|
|
|
138
158
|
get borrowApy() {
|
|
139
159
|
return this.getBorrowApy();
|
|
140
160
|
}
|
|
161
|
+
/**
|
|
162
|
+
* @deprecated Use `getEndBorrowRate(timestamp)` instead.
|
|
163
|
+
*/
|
|
164
|
+
getBorrowRate(timestamp = morpho_ts_1.Time.timestamp()) {
|
|
165
|
+
return this.getAccrualBorrowRates(timestamp).endBorrowRate;
|
|
166
|
+
}
|
|
141
167
|
/**
|
|
142
168
|
* Returns the instantaneous rate at which interest accrues for borrowers of this market,
|
|
143
169
|
* at the given timestamp, if the state remains unchanged (not accrued) (scaled by WAD).
|
|
144
170
|
* It is fundamentally different from the rate at which interest is paid by borrowers to lenders in the case of an interest accrual,
|
|
145
171
|
* as in the case of the AdaptiveCurveIRM, the (approximated) average rate since the last update is used instead.
|
|
146
|
-
* @param timestamp The timestamp at which to calculate the borrow rate.
|
|
172
|
+
* @param timestamp The timestamp at which to calculate the borrow rate.
|
|
173
|
+
* Must be greater than or equal to `lastUpdate`.
|
|
174
|
+
* Defaults to `Time.timestamp()` (returns the current borrow rate).
|
|
147
175
|
*/
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
return 0n;
|
|
151
|
-
timestamp = BigInt(timestamp);
|
|
152
|
-
const elapsed = timestamp - this.lastUpdate;
|
|
153
|
-
if (elapsed < 0n)
|
|
154
|
-
throw new errors_js_1.BlueErrors.InvalidInterestAccrual(this.id, timestamp, this.lastUpdate);
|
|
155
|
-
const { endBorrowRate } = index_js_1.AdaptiveCurveIrmLib.getBorrowRate(this.utilization, this.rateAtTarget, elapsed);
|
|
156
|
-
return endBorrowRate;
|
|
176
|
+
getEndBorrowRate(timestamp = morpho_ts_1.Time.timestamp()) {
|
|
177
|
+
return this.getAccrualBorrowRates(timestamp).endBorrowRate;
|
|
157
178
|
}
|
|
158
179
|
/**
|
|
159
|
-
* Returns the rate at which interest
|
|
160
|
-
*
|
|
161
|
-
* @param timestamp The timestamp at which to calculate the
|
|
180
|
+
* Returns the average rate at which interest _would_ accrue for borrowers of this market,
|
|
181
|
+
* if `accrueInterest` was called at the given timestamp (scaled by WAD).
|
|
182
|
+
* @param timestamp The timestamp at which to calculate the average borrow rate.
|
|
183
|
+
* Must be greater than or equal to `lastUpdate`.
|
|
184
|
+
* Defaults to `Time.timestamp()` (returns the current average borrow rate).
|
|
185
|
+
*/
|
|
186
|
+
getAvgBorrowRate(timestamp = morpho_ts_1.Time.timestamp()) {
|
|
187
|
+
return this.getAccrualBorrowRates(timestamp).avgBorrowRate;
|
|
188
|
+
}
|
|
189
|
+
/**
|
|
190
|
+
* Returns the rates that _would_ apply to interest accrual for borrowers of this market,
|
|
191
|
+
* if `accrueInterest` was called at the given timestamp (scaled by WAD).
|
|
192
|
+
* @param timestamp The timestamp at which to calculate the accrual borrow rate.
|
|
193
|
+
* Must be greater than or equal to `lastUpdate`.
|
|
194
|
+
* Defaults to `Time.timestamp()` (returns the current accrual borrow rate).
|
|
162
195
|
*/
|
|
163
|
-
|
|
196
|
+
getAccrualBorrowRates(timestamp = morpho_ts_1.Time.timestamp()) {
|
|
164
197
|
timestamp = BigInt(timestamp);
|
|
165
198
|
const elapsed = timestamp - this.lastUpdate;
|
|
166
199
|
if (elapsed < 0n)
|
|
@@ -179,28 +212,56 @@ class Market {
|
|
|
179
212
|
/**
|
|
180
213
|
* The market's instantaneous borrow-side Annual Percentage Yield (APY) at the given timestamp,
|
|
181
214
|
* if the state remains unchanged (not accrued) (scaled by WAD).
|
|
182
|
-
* @param timestamp The timestamp at which to calculate the borrow APY.
|
|
215
|
+
* @param timestamp The timestamp at which to calculate the borrow APY.
|
|
216
|
+
* Must be greater than or equal to `lastUpdate`.
|
|
217
|
+
* Defaults to `Time.timestamp()` (returns the current borrow APY).
|
|
183
218
|
*/
|
|
184
219
|
getBorrowApy(timestamp = morpho_ts_1.Time.timestamp()) {
|
|
185
|
-
const borrowRate = this.
|
|
220
|
+
const borrowRate = this.getEndBorrowRate(timestamp);
|
|
186
221
|
return MarketUtils_js_1.MarketUtils.compoundRate(borrowRate);
|
|
187
222
|
}
|
|
188
223
|
/**
|
|
189
224
|
* The market's instantaneous supply-side Annual Percentage Yield (APY) at the given timestamp,
|
|
190
225
|
* if the state remains unchanged (not accrued) (scaled by WAD).
|
|
191
|
-
* @param timestamp The timestamp at which to calculate the supply APY.
|
|
226
|
+
* @param timestamp The timestamp at which to calculate the supply APY.
|
|
227
|
+
* Must be greater than or equal to `lastUpdate`.
|
|
228
|
+
* Defaults to `Time.timestamp()` (returns the current supply APY).
|
|
192
229
|
*/
|
|
193
230
|
getSupplyApy(timestamp = morpho_ts_1.Time.timestamp()) {
|
|
194
231
|
const borrowApy = this.getBorrowApy(timestamp);
|
|
195
232
|
return index_js_1.MathLib.wMulUp(index_js_1.MathLib.wMulDown(borrowApy, this.utilization), index_js_1.MathLib.WAD - this.fee);
|
|
196
233
|
}
|
|
234
|
+
/**
|
|
235
|
+
* The market's experienced borrow-side Annual Percentage Yield (APY),
|
|
236
|
+
* if interest was to be accrued at the given timestamp (scaled by WAD).
|
|
237
|
+
* @param timestamp The timestamp at which to calculate the borrow APY.
|
|
238
|
+
* Must be greater than or equal to `lastUpdate`.
|
|
239
|
+
* Defaults to `Time.timestamp()` (returns the current borrow APY).
|
|
240
|
+
*/
|
|
241
|
+
getAvgBorrowApy(timestamp = morpho_ts_1.Time.timestamp()) {
|
|
242
|
+
const borrowRate = this.getAvgBorrowRate(timestamp);
|
|
243
|
+
return MarketUtils_js_1.MarketUtils.compoundRate(borrowRate);
|
|
244
|
+
}
|
|
245
|
+
/**
|
|
246
|
+
* The market's experienced supply-side Annual Percentage Yield (APY),
|
|
247
|
+
* if interest was to be accrued at the given timestamp (scaled by WAD).
|
|
248
|
+
* @param timestamp The timestamp at which to calculate the supply APY.
|
|
249
|
+
* Must be greater than or equal to `lastUpdate`.
|
|
250
|
+
* Defaults to `Time.timestamp()` (returns the current supply APY).
|
|
251
|
+
*/
|
|
252
|
+
getAvgSupplyApy(timestamp = morpho_ts_1.Time.timestamp()) {
|
|
253
|
+
const borrowApy = this.getAvgBorrowApy(timestamp);
|
|
254
|
+
return index_js_1.MathLib.wMulUp(index_js_1.MathLib.wMulDown(borrowApy, this.utilization), index_js_1.MathLib.WAD - this.fee);
|
|
255
|
+
}
|
|
197
256
|
/**
|
|
198
257
|
* Returns a new market derived from this market, whose interest has been accrued up to the given timestamp.
|
|
199
|
-
* @param timestamp The timestamp at which to accrue interest.
|
|
258
|
+
* @param timestamp The timestamp at which to accrue interest.
|
|
259
|
+
* Must be greater than or equal to `lastUpdate`.
|
|
260
|
+
* Defaults to `lastUpdate` (returns a copy of the market).
|
|
200
261
|
*/
|
|
201
262
|
accrueInterest(timestamp = this.lastUpdate) {
|
|
202
263
|
timestamp = BigInt(timestamp);
|
|
203
|
-
const { elapsed, avgBorrowRate, endRateAtTarget } = this.
|
|
264
|
+
const { elapsed, avgBorrowRate, endRateAtTarget } = this.getAccrualBorrowRates(timestamp);
|
|
204
265
|
const { interest, feeShares } = MarketUtils_js_1.MarketUtils.getAccruedInterest(avgBorrowRate, this, elapsed);
|
|
205
266
|
return new Market({
|
|
206
267
|
...this,
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@morpho-org/blue-sdk",
|
|
3
3
|
"description": "Framework-agnostic package that defines Morpho-related entity classes (such as `Market`, `Token`, `Vault`).",
|
|
4
|
-
"version": "4.
|
|
4
|
+
"version": "4.5.0",
|
|
5
5
|
"author": "Morpho Association <contact@morpho.org>",
|
|
6
6
|
"contributors": [
|
|
7
7
|
"Rubilmax <rmilon@gmail.com>"
|