@morpho-org/blue-sdk 2.0.0-next.31 → 2.0.0-next.32
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
CHANGED
|
@@ -102,21 +102,21 @@ export declare class Market implements InputMarket {
|
|
|
102
102
|
*/
|
|
103
103
|
get apyAtTarget(): bigint | undefined;
|
|
104
104
|
/**
|
|
105
|
-
* Returns the rate at which interest accrued
|
|
105
|
+
* Returns the rate at which interest accrued for suppliers of this market,
|
|
106
106
|
* since the last time the market was updated (scaled by WAD).
|
|
107
107
|
*/
|
|
108
108
|
get supplyRate(): bigint;
|
|
109
109
|
/**
|
|
110
|
-
* Returns the rate at which interest accrued
|
|
110
|
+
* Returns the rate at which interest accrued for borrowers of this market,
|
|
111
111
|
* since the last time the market was updated (scaled by WAD).
|
|
112
112
|
*/
|
|
113
113
|
get borrowRate(): bigint;
|
|
114
114
|
/**
|
|
115
|
-
* The market's supply Annual Percentage Yield (APY) (scaled by WAD).
|
|
115
|
+
* The market's supply-side Annual Percentage Yield (APY) (scaled by WAD).
|
|
116
116
|
*/
|
|
117
117
|
get supplyApy(): bigint;
|
|
118
118
|
/**
|
|
119
|
-
* The market's borrow Annual Percentage Yield (APY) (scaled by WAD).
|
|
119
|
+
* The market's borrow-side Annual Percentage Yield (APY) (scaled by WAD).
|
|
120
120
|
*/
|
|
121
121
|
get borrowApy(): bigint;
|
|
122
122
|
/**
|
package/lib/market/Market.js
CHANGED
|
@@ -98,17 +98,17 @@ class Market {
|
|
|
98
98
|
get apyAtTarget() {
|
|
99
99
|
if (this.rateAtTarget == null)
|
|
100
100
|
return;
|
|
101
|
-
return MarketUtils_js_1.MarketUtils.
|
|
101
|
+
return MarketUtils_js_1.MarketUtils.compoundRate(this.rateAtTarget);
|
|
102
102
|
}
|
|
103
103
|
/**
|
|
104
|
-
* Returns the rate at which interest accrued
|
|
104
|
+
* Returns the rate at which interest accrued for suppliers of this market,
|
|
105
105
|
* since the last time the market was updated (scaled by WAD).
|
|
106
106
|
*/
|
|
107
107
|
get supplyRate() {
|
|
108
108
|
return MarketUtils_js_1.MarketUtils.getSupplyRate(this.borrowRate, this);
|
|
109
109
|
}
|
|
110
110
|
/**
|
|
111
|
-
* Returns the rate at which interest accrued
|
|
111
|
+
* Returns the rate at which interest accrued for borrowers of this market,
|
|
112
112
|
* since the last time the market was updated (scaled by WAD).
|
|
113
113
|
*/
|
|
114
114
|
get borrowRate() {
|
|
@@ -117,16 +117,16 @@ class Market {
|
|
|
117
117
|
return index_js_1.AdaptiveCurveIrmLib.getBorrowRate(this.utilization, this.rateAtTarget, 0n).avgBorrowRate;
|
|
118
118
|
}
|
|
119
119
|
/**
|
|
120
|
-
* The market's supply Annual Percentage Yield (APY) (scaled by WAD).
|
|
120
|
+
* The market's supply-side Annual Percentage Yield (APY) (scaled by WAD).
|
|
121
121
|
*/
|
|
122
122
|
get supplyApy() {
|
|
123
|
-
return MarketUtils_js_1.MarketUtils.
|
|
123
|
+
return MarketUtils_js_1.MarketUtils.compoundRate(this.supplyRate);
|
|
124
124
|
}
|
|
125
125
|
/**
|
|
126
|
-
* The market's borrow Annual Percentage Yield (APY) (scaled by WAD).
|
|
126
|
+
* The market's borrow-side Annual Percentage Yield (APY) (scaled by WAD).
|
|
127
127
|
*/
|
|
128
128
|
get borrowApy() {
|
|
129
|
-
return MarketUtils_js_1.MarketUtils.
|
|
129
|
+
return MarketUtils_js_1.MarketUtils.compoundRate(this.borrowRate);
|
|
130
130
|
}
|
|
131
131
|
/**
|
|
132
132
|
* Returns a new market derived from this market, whose interest has been accrued up to the given timestamp.
|
|
@@ -26,7 +26,7 @@ export declare namespace MarketUtils {
|
|
|
26
26
|
totalBorrowAssets: BigIntish;
|
|
27
27
|
}): bigint;
|
|
28
28
|
/**
|
|
29
|
-
* Returns the rate at which interest accrued
|
|
29
|
+
* Returns the rate at which interest accrued for suppliers on the corresponding market,
|
|
30
30
|
* since the last time the market was updated (scaled by WAD).
|
|
31
31
|
* @param borrowRate The average borrow rate since the last market update (scaled by WAD).
|
|
32
32
|
* @param market The market state.
|
|
@@ -36,10 +36,12 @@ export declare namespace MarketUtils {
|
|
|
36
36
|
fee: BigIntish;
|
|
37
37
|
}): bigint;
|
|
38
38
|
/**
|
|
39
|
-
* Returns the
|
|
40
|
-
*
|
|
39
|
+
* Returns the per-second rate continuously compounded over the given period, as calculated in Morpho Blue (scaled by WAD).
|
|
40
|
+
* If the period is 1 year, the compounded rate correspond to the Annual Percentage Yield (APY)
|
|
41
|
+
* @param rate The per-second rate to compound (scaled by WAD).
|
|
42
|
+
* @param period The period to compound the rate over (in seconds). Defaults to 1 year.
|
|
41
43
|
*/
|
|
42
|
-
function
|
|
44
|
+
function compoundRate(rate: BigIntish, period?: BigIntish): bigint;
|
|
43
45
|
/**
|
|
44
46
|
* Returns the interest accrued on both sides of the given market
|
|
45
47
|
* as well as the supply shares minted to the fee recipient.
|
|
@@ -50,7 +50,7 @@ var MarketUtils;
|
|
|
50
50
|
}
|
|
51
51
|
MarketUtils.getUtilization = getUtilization;
|
|
52
52
|
/**
|
|
53
|
-
* Returns the rate at which interest accrued
|
|
53
|
+
* Returns the rate at which interest accrued for suppliers on the corresponding market,
|
|
54
54
|
* since the last time the market was updated (scaled by WAD).
|
|
55
55
|
* @param borrowRate The average borrow rate since the last market update (scaled by WAD).
|
|
56
56
|
* @param market The market state.
|
|
@@ -61,13 +61,15 @@ var MarketUtils;
|
|
|
61
61
|
}
|
|
62
62
|
MarketUtils.getSupplyRate = getSupplyRate;
|
|
63
63
|
/**
|
|
64
|
-
* Returns the
|
|
65
|
-
*
|
|
64
|
+
* Returns the per-second rate continuously compounded over the given period, as calculated in Morpho Blue (scaled by WAD).
|
|
65
|
+
* If the period is 1 year, the compounded rate correspond to the Annual Percentage Yield (APY)
|
|
66
|
+
* @param rate The per-second rate to compound (scaled by WAD).
|
|
67
|
+
* @param period The period to compound the rate over (in seconds). Defaults to 1 year.
|
|
66
68
|
*/
|
|
67
|
-
function
|
|
68
|
-
return index_js_1.MathLib.wTaylorCompounded(rate,
|
|
69
|
+
function compoundRate(rate, period = constants_js_1.SECONDS_PER_YEAR) {
|
|
70
|
+
return index_js_1.MathLib.wTaylorCompounded(rate, period);
|
|
69
71
|
}
|
|
70
|
-
MarketUtils.
|
|
72
|
+
MarketUtils.compoundRate = compoundRate;
|
|
71
73
|
/**
|
|
72
74
|
* Returns the interest accrued on both sides of the given market
|
|
73
75
|
* as well as the supply shares minted to the fee recipient.
|
package/lib/math/MathLib.d.ts
CHANGED
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import { Time } from "@morpho-org/morpho-ts";
|
|
2
1
|
import type { BigIntish } from "../types.js";
|
|
3
2
|
export type RoundingDirection = "Up" | "Down";
|
|
4
3
|
/**
|
|
@@ -88,24 +87,10 @@ export declare namespace MathLib {
|
|
|
88
87
|
function mulDiv(x: BigIntish, y: BigIntish, denominator: BigIntish, rounding: RoundingDirection): bigint;
|
|
89
88
|
/**
|
|
90
89
|
* The sum of the first three non-zero terms of a Taylor expansion of e^(nx) - 1,
|
|
91
|
-
* to approximate a
|
|
90
|
+
* to approximate a continuously compounded interest rate.
|
|
92
91
|
*
|
|
93
92
|
* @param x The base of the exponent
|
|
94
93
|
* @param n The exponent
|
|
95
94
|
*/
|
|
96
95
|
function wTaylorCompounded(x: BigIntish, n: BigIntish): bigint;
|
|
97
|
-
/**
|
|
98
|
-
* Converts an rate to compounded apy
|
|
99
|
-
*
|
|
100
|
-
* @param rate The rate to convert (in WAD)
|
|
101
|
-
* @param period The compounding basis
|
|
102
|
-
*/
|
|
103
|
-
function rateToApy(rate: BigIntish, period: Time.PeriodLike): number;
|
|
104
|
-
/**
|
|
105
|
-
* Converts an apr to compounded apy
|
|
106
|
-
*
|
|
107
|
-
* @param apr The apr to convert (in WAD)
|
|
108
|
-
* @param compounding The compounding basis
|
|
109
|
-
*/
|
|
110
|
-
function aprToApy(apr: BigIntish, compounding: Time.PeriodLike): number;
|
|
111
96
|
}
|
package/lib/math/MathLib.js
CHANGED
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.MathLib = void 0;
|
|
4
|
-
const morpho_ts_1 = require("@morpho-org/morpho-ts");
|
|
5
4
|
/**
|
|
6
5
|
* Library to manage fixed-point arithmetic.
|
|
7
6
|
* https://github.com/morpho-org/morpho-blue/blob/main/src/libraries/MathLib.sol
|
|
@@ -148,7 +147,7 @@ var MathLib;
|
|
|
148
147
|
MathLib.mulDiv = mulDiv;
|
|
149
148
|
/**
|
|
150
149
|
* The sum of the first three non-zero terms of a Taylor expansion of e^(nx) - 1,
|
|
151
|
-
* to approximate a
|
|
150
|
+
* to approximate a continuously compounded interest rate.
|
|
152
151
|
*
|
|
153
152
|
* @param x The base of the exponent
|
|
154
153
|
* @param n The exponent
|
|
@@ -160,29 +159,4 @@ var MathLib;
|
|
|
160
159
|
return firstTerm + secondTerm + thirdTerm;
|
|
161
160
|
}
|
|
162
161
|
MathLib.wTaylorCompounded = wTaylorCompounded;
|
|
163
|
-
/**
|
|
164
|
-
* Converts an rate to compounded apy
|
|
165
|
-
*
|
|
166
|
-
* @param rate The rate to convert (in WAD)
|
|
167
|
-
* @param period The compounding basis
|
|
168
|
-
*/
|
|
169
|
-
function rateToApy(rate, period) {
|
|
170
|
-
const { unit, duration } = morpho_ts_1.Time.toPeriod(period);
|
|
171
|
-
const factor = morpho_ts_1.Time[unit].from.y(1) / duration;
|
|
172
|
-
return ((1 + Number(morpho_ts_1.format.number.locale("en").of(BigInt(rate), 18))) ** factor -
|
|
173
|
-
1);
|
|
174
|
-
}
|
|
175
|
-
MathLib.rateToApy = rateToApy;
|
|
176
|
-
/**
|
|
177
|
-
* Converts an apr to compounded apy
|
|
178
|
-
*
|
|
179
|
-
* @param apr The apr to convert (in WAD)
|
|
180
|
-
* @param compounding The compounding basis
|
|
181
|
-
*/
|
|
182
|
-
function aprToApy(apr, compounding) {
|
|
183
|
-
const { unit, duration } = morpho_ts_1.Time.toPeriod(compounding);
|
|
184
|
-
const rate = (BigInt(apr) * BigInt(duration)) / morpho_ts_1.Time[unit].from.y(1n);
|
|
185
|
-
return rateToApy(rate, compounding);
|
|
186
|
-
}
|
|
187
|
-
MathLib.aprToApy = aprToApy;
|
|
188
162
|
})(MathLib || (exports.MathLib = MathLib = {}));
|
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": "2.0.0-next.
|
|
4
|
+
"version": "2.0.0-next.32",
|
|
5
5
|
"author": "Morpho Association <contact@morpho.org>",
|
|
6
6
|
"contributors": [
|
|
7
7
|
"Rubilmax <rmilon@gmail.com>"
|
|
@@ -28,7 +28,7 @@
|
|
|
28
28
|
"viem": "^2.21.54",
|
|
29
29
|
"vitest": "^2.1.8",
|
|
30
30
|
"@morpho-org/morpho-ts": "^2.0.0-next.16",
|
|
31
|
-
"@morpho-org/test": "^2.0.0-next.
|
|
31
|
+
"@morpho-org/test": "^2.0.0-next.27"
|
|
32
32
|
},
|
|
33
33
|
"scripts": {
|
|
34
34
|
"prepublish": "$npm_execpath build",
|