@morpho-org/blue-sdk 5.3.0-next.1 → 5.3.0-next.2
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
CHANGED
|
@@ -1,4 +1,9 @@
|
|
|
1
|
+
import { type Hex } from "viem";
|
|
1
2
|
import type { Address, MarketId } from "./types.js";
|
|
3
|
+
export declare class InvalidMarketParamsError extends Error {
|
|
4
|
+
readonly data: Hex;
|
|
5
|
+
constructor(data: Hex);
|
|
6
|
+
}
|
|
2
7
|
export declare class UnknownDataError extends Error {
|
|
3
8
|
}
|
|
4
9
|
export declare class UnknownTokenError extends UnknownDataError {
|
package/lib/errors.js
CHANGED
|
@@ -1,8 +1,16 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.VaultV2Errors = exports.BlueErrors = exports.UnsupportedVaultV2AdapterError = exports.UnsupportedPreLiquidationParamsError = exports.UnsupportedChainIdError = exports.UnknownVaultConfigError = exports.UnknownMarketParamsError = exports.UnknownTokenPriceError = exports.UnknownTokenError = exports.UnknownDataError = void 0;
|
|
3
|
+
exports.VaultV2Errors = exports.BlueErrors = exports.UnsupportedVaultV2AdapterError = exports.UnsupportedPreLiquidationParamsError = exports.UnsupportedChainIdError = exports.UnknownVaultConfigError = exports.UnknownMarketParamsError = exports.UnknownTokenPriceError = exports.UnknownTokenError = exports.UnknownDataError = exports.InvalidMarketParamsError = void 0;
|
|
4
4
|
exports._try = _try;
|
|
5
5
|
const viem_1 = require("viem");
|
|
6
|
+
class InvalidMarketParamsError extends Error {
|
|
7
|
+
data;
|
|
8
|
+
constructor(data) {
|
|
9
|
+
super(`cannot decode valid MarketParams from "${data}"`);
|
|
10
|
+
this.data = data;
|
|
11
|
+
}
|
|
12
|
+
}
|
|
13
|
+
exports.InvalidMarketParamsError = InvalidMarketParamsError;
|
|
6
14
|
class UnknownDataError extends Error {
|
|
7
15
|
}
|
|
8
16
|
exports.UnknownDataError = UnknownDataError;
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import type { Address, BigIntish, MarketId } from "../types.js";
|
|
2
|
+
import { type Hex } from "viem";
|
|
2
3
|
export interface IMarketParams {
|
|
3
4
|
loanToken: Address;
|
|
4
5
|
collateralToken: Address;
|
|
@@ -7,6 +8,25 @@ export interface IMarketParams {
|
|
|
7
8
|
lltv: BigIntish;
|
|
8
9
|
}
|
|
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
|
+
};
|
|
10
30
|
/**
|
|
11
31
|
* Represents a market's configuration (also called market params).
|
|
12
32
|
*/
|
|
@@ -21,6 +41,7 @@ export declare class MarketParams implements IMarketParams {
|
|
|
21
41
|
* Returns the canonical idle market configuration for the given loan token.
|
|
22
42
|
*/
|
|
23
43
|
static idle(token: Address): MarketParams;
|
|
44
|
+
static fromHex(data: Hex): MarketParams;
|
|
24
45
|
/**
|
|
25
46
|
* The market's collateral token address.
|
|
26
47
|
*/
|
|
@@ -1,9 +1,20 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.MarketParams = void 0;
|
|
3
|
+
exports.MarketParams = exports.marketParamsAbi = void 0;
|
|
4
4
|
const morpho_ts_1 = require("@morpho-org/morpho-ts");
|
|
5
5
|
const errors_js_1 = require("../errors.js");
|
|
6
|
+
const viem_1 = require("viem");
|
|
6
7
|
const MarketUtils_js_1 = require("./MarketUtils.js");
|
|
8
|
+
exports.marketParamsAbi = {
|
|
9
|
+
type: "tuple",
|
|
10
|
+
components: [
|
|
11
|
+
{ type: "address", name: "loanToken" },
|
|
12
|
+
{ type: "address", name: "collateralToken" },
|
|
13
|
+
{ type: "address", name: "oracle" },
|
|
14
|
+
{ type: "address", name: "irm" },
|
|
15
|
+
{ type: "uint256", name: "lltv" },
|
|
16
|
+
],
|
|
17
|
+
};
|
|
7
18
|
/**
|
|
8
19
|
* Represents a market's configuration (also called market params).
|
|
9
20
|
*/
|
|
@@ -31,6 +42,15 @@ class MarketParams {
|
|
|
31
42
|
lltv: 0n,
|
|
32
43
|
});
|
|
33
44
|
}
|
|
45
|
+
static fromHex(data) {
|
|
46
|
+
try {
|
|
47
|
+
const [marketParams] = (0, viem_1.decodeAbiParameters)([exports.marketParamsAbi], data);
|
|
48
|
+
return new MarketParams(marketParams);
|
|
49
|
+
}
|
|
50
|
+
catch {
|
|
51
|
+
throw new errors_js_1.InvalidMarketParamsError(data);
|
|
52
|
+
}
|
|
53
|
+
}
|
|
34
54
|
/**
|
|
35
55
|
* The market's collateral token address.
|
|
36
56
|
*/
|
|
@@ -26,5 +26,5 @@ export declare class AccrualVaultV2MorphoMarketV1Adapter extends VaultV2MorphoMa
|
|
|
26
26
|
value: bigint;
|
|
27
27
|
limiter: CapacityLimitReason;
|
|
28
28
|
};
|
|
29
|
-
maxWithdraw(
|
|
29
|
+
maxWithdraw(data: Hex): import("../../utils").CapacityLimit;
|
|
30
30
|
}
|
|
@@ -5,16 +5,6 @@ const viem_1 = require("viem");
|
|
|
5
5
|
const market_1 = require("../../market");
|
|
6
6
|
const utils_1 = require("../../utils");
|
|
7
7
|
const VaultV2Adapter_1 = require("./VaultV2Adapter");
|
|
8
|
-
const marketParamsAbi = {
|
|
9
|
-
type: "tuple",
|
|
10
|
-
components: [
|
|
11
|
-
{ type: "address", name: "loanToken" },
|
|
12
|
-
{ type: "address", name: "collateralToken" },
|
|
13
|
-
{ type: "address", name: "oracle" },
|
|
14
|
-
{ type: "address", name: "irm" },
|
|
15
|
-
{ type: "uint256", name: "lltv" },
|
|
16
|
-
],
|
|
17
|
-
};
|
|
18
8
|
class VaultV2MorphoMarketV1Adapter extends VaultV2Adapter_1.VaultV2Adapter {
|
|
19
9
|
static adapterId(address) {
|
|
20
10
|
return (0, viem_1.keccak256)((0, viem_1.encodeAbiParameters)([{ type: "string" }, { type: "address" }], ["this", address]));
|
|
@@ -23,7 +13,7 @@ class VaultV2MorphoMarketV1Adapter extends VaultV2Adapter_1.VaultV2Adapter {
|
|
|
23
13
|
return (0, viem_1.keccak256)((0, viem_1.encodeAbiParameters)([{ type: "string" }, { type: "address" }], ["collateralToken", address]));
|
|
24
14
|
}
|
|
25
15
|
static marketParamsId(address, params) {
|
|
26
|
-
return (0, viem_1.keccak256)((0, viem_1.encodeAbiParameters)([{ type: "string" }, { type: "address" }, marketParamsAbi], ["this/marketParams", address, params]));
|
|
16
|
+
return (0, viem_1.keccak256)((0, viem_1.encodeAbiParameters)([{ type: "string" }, { type: "address" }, market_1.marketParamsAbi], ["this/marketParams", address, params]));
|
|
27
17
|
}
|
|
28
18
|
marketParamsList;
|
|
29
19
|
constructor({ marketParamsList, ...vaultV2Adapter }) {
|
|
@@ -57,9 +47,8 @@ class AccrualVaultV2MorphoMarketV1Adapter extends VaultV2MorphoMarketV1Adapter {
|
|
|
57
47
|
limiter: utils_1.CapacityLimitReason.balance,
|
|
58
48
|
};
|
|
59
49
|
}
|
|
60
|
-
maxWithdraw(
|
|
61
|
-
const
|
|
62
|
-
const marketId = new market_1.MarketParams(marketParams).id;
|
|
50
|
+
maxWithdraw(data) {
|
|
51
|
+
const marketId = market_1.MarketParams.fromHex(data).id;
|
|
63
52
|
const position = this.positions.find((position) => position.marketId === marketId);
|
|
64
53
|
return (position?.market?.getWithdrawCapacityLimit(position) ?? {
|
|
65
54
|
value: 0n,
|
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": "5.3.0-next.
|
|
4
|
+
"version": "5.3.0-next.2",
|
|
5
5
|
"author": "Morpho Association <contact@morpho.org>",
|
|
6
6
|
"contributors": [
|
|
7
7
|
"Rubilmax <rmilon@gmail.com>"
|
|
@@ -31,8 +31,8 @@
|
|
|
31
31
|
"typescript": "^5.7.2",
|
|
32
32
|
"viem": "^2.33.3",
|
|
33
33
|
"vitest": "^3.0.5",
|
|
34
|
-
"@morpho-org/
|
|
35
|
-
"@morpho-org/
|
|
34
|
+
"@morpho-org/morpho-ts": "^2.4.3",
|
|
35
|
+
"@morpho-org/test": "^2.6.0"
|
|
36
36
|
},
|
|
37
37
|
"scripts": {
|
|
38
38
|
"prepublish": "$npm_execpath build",
|