@morpho-org/blue-sdk 4.0.0-next.2 → 4.0.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/errors.d.ts +7 -1
- package/lib/errors.js +14 -2
- package/lib/market/Market.d.ts +2 -2
- package/lib/market/Market.js +10 -9
- package/package.json +4 -4
package/lib/errors.d.ts
CHANGED
|
@@ -38,7 +38,9 @@ export declare namespace BlueErrors {
|
|
|
38
38
|
constructor(marketId: MarketId, timestamp: bigint, lastUpdate: bigint);
|
|
39
39
|
}
|
|
40
40
|
class InconsistentInput extends Error {
|
|
41
|
-
|
|
41
|
+
readonly assets: bigint;
|
|
42
|
+
readonly shares: bigint;
|
|
43
|
+
constructor(assets: bigint, shares: bigint);
|
|
42
44
|
}
|
|
43
45
|
class InsufficientLiquidity extends Error {
|
|
44
46
|
readonly marketId: MarketId;
|
|
@@ -58,6 +60,10 @@ export declare namespace BlueErrors {
|
|
|
58
60
|
readonly marketId: MarketId;
|
|
59
61
|
constructor(user: Address, marketId: MarketId);
|
|
60
62
|
}
|
|
63
|
+
class ExpiredSignature extends Error {
|
|
64
|
+
readonly deadline: bigint;
|
|
65
|
+
constructor(deadline: bigint);
|
|
66
|
+
}
|
|
61
67
|
}
|
|
62
68
|
export interface ErrorClass<E extends Error> {
|
|
63
69
|
new (...args: any[]): E;
|
package/lib/errors.js
CHANGED
|
@@ -79,8 +79,12 @@ var BlueErrors;
|
|
|
79
79
|
}
|
|
80
80
|
BlueErrors.InvalidInterestAccrual = InvalidInterestAccrual;
|
|
81
81
|
class InconsistentInput extends Error {
|
|
82
|
-
|
|
83
|
-
|
|
82
|
+
assets;
|
|
83
|
+
shares;
|
|
84
|
+
constructor(assets, shares) {
|
|
85
|
+
super(`inconsistent input assets "${assets}" and shares "${shares}"`);
|
|
86
|
+
this.assets = assets;
|
|
87
|
+
this.shares = shares;
|
|
84
88
|
}
|
|
85
89
|
}
|
|
86
90
|
BlueErrors.InconsistentInput = InconsistentInput;
|
|
@@ -120,6 +124,14 @@ var BlueErrors;
|
|
|
120
124
|
}
|
|
121
125
|
}
|
|
122
126
|
BlueErrors.InsufficientCollateral = InsufficientCollateral;
|
|
127
|
+
class ExpiredSignature extends Error {
|
|
128
|
+
deadline;
|
|
129
|
+
constructor(deadline) {
|
|
130
|
+
super(`expired signature deadline "${deadline}"`);
|
|
131
|
+
this.deadline = deadline;
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
BlueErrors.ExpiredSignature = ExpiredSignature;
|
|
123
135
|
})(BlueErrors || (exports.BlueErrors = BlueErrors = {}));
|
|
124
136
|
function _try(accessor, ...errorClasses) {
|
|
125
137
|
const maybeCatchError = (error) => {
|
package/lib/market/Market.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { type RoundingDirection } from "../math/index.js";
|
|
2
2
|
import type { BigIntish } from "../types.js";
|
|
3
|
-
import type
|
|
3
|
+
import { type IMarketParams, MarketParams } from "./MarketParams.js";
|
|
4
4
|
export declare enum CapacityLimitReason {
|
|
5
5
|
liquidity = "Liquidity",
|
|
6
6
|
balance = "Balance",
|
|
@@ -27,7 +27,7 @@ export interface MaxPositionCapacities {
|
|
|
27
27
|
withdrawCollateral: CapacityLimit | undefined;
|
|
28
28
|
}
|
|
29
29
|
export interface IMarket {
|
|
30
|
-
params:
|
|
30
|
+
params: IMarketParams;
|
|
31
31
|
totalSupplyAssets: bigint;
|
|
32
32
|
totalBorrowAssets: bigint;
|
|
33
33
|
totalSupplyShares: bigint;
|
package/lib/market/Market.js
CHANGED
|
@@ -4,6 +4,7 @@ exports.Market = exports.CapacityLimitReason = void 0;
|
|
|
4
4
|
const morpho_ts_1 = require("@morpho-org/morpho-ts");
|
|
5
5
|
const errors_js_1 = require("../errors.js");
|
|
6
6
|
const index_js_1 = require("../math/index.js");
|
|
7
|
+
const MarketParams_js_1 = require("./MarketParams.js");
|
|
7
8
|
const MarketUtils_js_1 = require("./MarketUtils.js");
|
|
8
9
|
var CapacityLimitReason;
|
|
9
10
|
(function (CapacityLimitReason) {
|
|
@@ -56,7 +57,7 @@ class Market {
|
|
|
56
57
|
*/
|
|
57
58
|
rateAtTarget;
|
|
58
59
|
constructor({ params, totalSupplyAssets, totalBorrowAssets, totalSupplyShares, totalBorrowShares, lastUpdate, fee, price, rateAtTarget, }) {
|
|
59
|
-
this.params = params;
|
|
60
|
+
this.params = new MarketParams_js_1.MarketParams(params);
|
|
60
61
|
this.totalSupplyAssets = totalSupplyAssets;
|
|
61
62
|
this.totalBorrowAssets = totalBorrowAssets;
|
|
62
63
|
this.totalSupplyShares = totalSupplyShares;
|
|
@@ -211,8 +212,8 @@ class Market {
|
|
|
211
212
|
});
|
|
212
213
|
}
|
|
213
214
|
supply(assets, shares, timestamp) {
|
|
214
|
-
if (assets === 0n
|
|
215
|
-
throw new errors_js_1.BlueErrors.InconsistentInput();
|
|
215
|
+
if ((assets === 0n) === (shares === 0n))
|
|
216
|
+
throw new errors_js_1.BlueErrors.InconsistentInput(assets, shares);
|
|
216
217
|
const market = this.accrueInterest(timestamp);
|
|
217
218
|
if (shares === 0n)
|
|
218
219
|
shares = market.toSupplyShares(assets, "Down");
|
|
@@ -223,8 +224,8 @@ class Market {
|
|
|
223
224
|
return { market, assets, shares };
|
|
224
225
|
}
|
|
225
226
|
withdraw(assets, shares, timestamp) {
|
|
226
|
-
if (assets === 0n
|
|
227
|
-
throw new errors_js_1.BlueErrors.InconsistentInput();
|
|
227
|
+
if ((assets === 0n) === (shares === 0n))
|
|
228
|
+
throw new errors_js_1.BlueErrors.InconsistentInput(assets, shares);
|
|
228
229
|
const market = this.accrueInterest(timestamp);
|
|
229
230
|
if (shares === 0n)
|
|
230
231
|
shares = market.toSupplyShares(assets, "Up");
|
|
@@ -237,8 +238,8 @@ class Market {
|
|
|
237
238
|
return { market, assets, shares };
|
|
238
239
|
}
|
|
239
240
|
borrow(assets, shares, timestamp) {
|
|
240
|
-
if (assets === 0n
|
|
241
|
-
throw new errors_js_1.BlueErrors.InconsistentInput();
|
|
241
|
+
if ((assets === 0n) === (shares === 0n))
|
|
242
|
+
throw new errors_js_1.BlueErrors.InconsistentInput(assets, shares);
|
|
242
243
|
const market = this.accrueInterest(timestamp);
|
|
243
244
|
if (shares === 0n)
|
|
244
245
|
shares = market.toBorrowShares(assets, "Up");
|
|
@@ -251,8 +252,8 @@ class Market {
|
|
|
251
252
|
return { market, assets, shares };
|
|
252
253
|
}
|
|
253
254
|
repay(assets, shares, timestamp) {
|
|
254
|
-
if (assets === 0n
|
|
255
|
-
throw new errors_js_1.BlueErrors.InconsistentInput();
|
|
255
|
+
if ((assets === 0n) === (shares === 0n))
|
|
256
|
+
throw new errors_js_1.BlueErrors.InconsistentInput(assets, shares);
|
|
256
257
|
const market = this.accrueInterest(timestamp);
|
|
257
258
|
if (shares === 0n)
|
|
258
259
|
shares = market.toBorrowShares(assets, "Down");
|
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.0.0
|
|
4
|
+
"version": "4.0.0",
|
|
5
5
|
"author": "Morpho Association <contact@morpho.org>",
|
|
6
6
|
"contributors": [
|
|
7
7
|
"Rubilmax <rmilon@gmail.com>"
|
|
@@ -25,14 +25,14 @@
|
|
|
25
25
|
"lodash.mergewith": "^4.6.2"
|
|
26
26
|
},
|
|
27
27
|
"peerDependencies": {
|
|
28
|
-
"@morpho-org/morpho-ts": "^2.
|
|
28
|
+
"@morpho-org/morpho-ts": "^2.4.0"
|
|
29
29
|
},
|
|
30
30
|
"devDependencies": {
|
|
31
31
|
"typescript": "^5.7.2",
|
|
32
32
|
"viem": "^2.23.0",
|
|
33
33
|
"vitest": "^3.0.5",
|
|
34
|
-
"@morpho-org/morpho-ts": "^2.
|
|
35
|
-
"@morpho-org/test": "^2.1.
|
|
34
|
+
"@morpho-org/morpho-ts": "^2.4.0",
|
|
35
|
+
"@morpho-org/test": "^2.1.4"
|
|
36
36
|
},
|
|
37
37
|
"scripts": {
|
|
38
38
|
"prepublish": "$npm_execpath build",
|