@morpho-org/blue-sdk 5.3.0-next.0 → 5.3.0-next.1

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.
@@ -204,5 +204,5 @@ export declare class AccrualVault extends Vault implements IAccrualVault {
204
204
  * Returns a new vault derived from this vault, whose interest has been accrued up to the given timestamp.
205
205
  * @param timestamp The timestamp at which to accrue interest. Must be greater than or equal to each of the vault's market's `lastUpdate`.
206
206
  */
207
- accrueInterest(timestamp: BigIntish): AccrualVault;
207
+ accrueInterest(timestamp?: BigIntish): AccrualVault;
208
208
  }
@@ -6,7 +6,6 @@ const errors_1 = require("../../errors");
6
6
  const math_1 = require("../../math");
7
7
  const token_1 = require("../../token");
8
8
  const utils_1 = require("../../utils");
9
- const VaultV2MorphoVaultV1Adapter_1 = require("./VaultV2MorphoVaultV1Adapter");
10
9
  class VaultV2 extends token_1.WrappedToken {
11
10
  asset;
12
11
  totalAssets;
@@ -73,9 +72,8 @@ class AccrualVaultV2 extends VaultV2 {
73
72
  if (this.liquidityAdapter === viem_1.zeroAddress)
74
73
  return { value: BigInt(assets), limiter: utils_1.CapacityLimitReason.balance };
75
74
  let liquidityAdapterLimit;
76
- if (this.accrualLiquidityAdapter instanceof VaultV2MorphoVaultV1Adapter_1.AccrualVaultV2MorphoVaultV1Adapter) {
75
+ if (this.accrualLiquidityAdapter != null)
77
76
  liquidityAdapterLimit = this.accrualLiquidityAdapter.maxDeposit(this.liquidityData, assets);
78
- }
79
77
  if (this.liquidityAllocations == null || liquidityAdapterLimit == null)
80
78
  throw new errors_1.VaultV2Errors.UnsupportedLiquidityAdapter(this.liquidityAdapter);
81
79
  // At this stage: `liquidityAdapterLimit.value <= assets`
@@ -109,7 +107,7 @@ class AccrualVaultV2 extends VaultV2 {
109
107
  if (this.liquidityAdapter === viem_1.zeroAddress)
110
108
  return { value: BigInt(assets), limiter: utils_1.CapacityLimitReason.balance };
111
109
  let liquidity = this.assetBalance;
112
- if (this.accrualLiquidityAdapter instanceof VaultV2MorphoVaultV1Adapter_1.AccrualVaultV2MorphoVaultV1Adapter)
110
+ if (this.accrualLiquidityAdapter != null)
113
111
  liquidity += this.accrualLiquidityAdapter.maxWithdraw(this.liquidityData).value;
114
112
  if (assets > liquidity)
115
113
  return {
@@ -0,0 +1,30 @@
1
+ import { type Address, type Hex } from "viem";
2
+ import { type IMarketParams, MarketParams } from "../../market";
3
+ import type { AccrualPosition } from "../../position";
4
+ import type { BigIntish } from "../../types";
5
+ import { CapacityLimitReason } from "../../utils";
6
+ import { VaultV2Adapter } from "./VaultV2Adapter";
7
+ import type { IAccrualVaultV2Adapter, IVaultV2Adapter } from "./VaultV2Adapter";
8
+ export interface IVaultV2MorphoMarketV1Adapter extends Omit<IVaultV2Adapter, "adapterId"> {
9
+ marketParamsList: IMarketParams[];
10
+ }
11
+ export declare class VaultV2MorphoMarketV1Adapter extends VaultV2Adapter implements IVaultV2MorphoMarketV1Adapter {
12
+ static adapterId(address: Address): `0x${string}`;
13
+ static collateralId(address: Address): `0x${string}`;
14
+ static marketParamsId(address: Address, params: MarketParams): `0x${string}`;
15
+ marketParamsList: MarketParams[];
16
+ constructor({ marketParamsList, ...vaultV2Adapter }: IVaultV2MorphoMarketV1Adapter);
17
+ ids(params: MarketParams): `0x${string}`[];
18
+ }
19
+ export interface IAccrualVaultV2MorphoMarketV1Adapter extends IVaultV2MorphoMarketV1Adapter {
20
+ }
21
+ export declare class AccrualVaultV2MorphoMarketV1Adapter extends VaultV2MorphoMarketV1Adapter implements IAccrualVaultV2MorphoMarketV1Adapter, IAccrualVaultV2Adapter {
22
+ positions: AccrualPosition[];
23
+ constructor(adapter: IAccrualVaultV2MorphoMarketV1Adapter, positions: AccrualPosition[]);
24
+ realAssets(timestamp?: BigIntish): bigint;
25
+ maxDeposit(_data: Hex, assets: BigIntish): {
26
+ value: bigint;
27
+ limiter: CapacityLimitReason;
28
+ };
29
+ maxWithdraw(_data: Hex): import("../../utils").CapacityLimit;
30
+ }
@@ -0,0 +1,70 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.AccrualVaultV2MorphoMarketV1Adapter = exports.VaultV2MorphoMarketV1Adapter = void 0;
4
+ const viem_1 = require("viem");
5
+ const market_1 = require("../../market");
6
+ const utils_1 = require("../../utils");
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
+ class VaultV2MorphoMarketV1Adapter extends VaultV2Adapter_1.VaultV2Adapter {
19
+ static adapterId(address) {
20
+ return (0, viem_1.keccak256)((0, viem_1.encodeAbiParameters)([{ type: "string" }, { type: "address" }], ["this", address]));
21
+ }
22
+ static collateralId(address) {
23
+ return (0, viem_1.keccak256)((0, viem_1.encodeAbiParameters)([{ type: "string" }, { type: "address" }], ["collateralToken", address]));
24
+ }
25
+ static marketParamsId(address, params) {
26
+ return (0, viem_1.keccak256)((0, viem_1.encodeAbiParameters)([{ type: "string" }, { type: "address" }, marketParamsAbi], ["this/marketParams", address, params]));
27
+ }
28
+ marketParamsList;
29
+ constructor({ marketParamsList, ...vaultV2Adapter }) {
30
+ super({
31
+ ...vaultV2Adapter,
32
+ adapterId: VaultV2MorphoMarketV1Adapter.adapterId(vaultV2Adapter.address),
33
+ });
34
+ this.marketParamsList = marketParamsList.map((params) => new market_1.MarketParams(params));
35
+ }
36
+ ids(params) {
37
+ return [
38
+ this.adapterId,
39
+ VaultV2MorphoMarketV1Adapter.collateralId(params.collateralToken),
40
+ VaultV2MorphoMarketV1Adapter.marketParamsId(this.address, params),
41
+ ];
42
+ }
43
+ }
44
+ exports.VaultV2MorphoMarketV1Adapter = VaultV2MorphoMarketV1Adapter;
45
+ class AccrualVaultV2MorphoMarketV1Adapter extends VaultV2MorphoMarketV1Adapter {
46
+ positions;
47
+ constructor(adapter, positions) {
48
+ super(adapter);
49
+ this.positions = positions;
50
+ }
51
+ realAssets(timestamp) {
52
+ return this.positions.reduce((total, position) => total + position.accrueInterest(timestamp).supplyAssets, 0n);
53
+ }
54
+ maxDeposit(_data, assets) {
55
+ return {
56
+ value: BigInt(assets),
57
+ limiter: utils_1.CapacityLimitReason.balance,
58
+ };
59
+ }
60
+ maxWithdraw(_data) {
61
+ const [marketParams] = (0, viem_1.decodeAbiParameters)([marketParamsAbi], _data);
62
+ const marketId = new market_1.MarketParams(marketParams).id;
63
+ const position = this.positions.find((position) => position.marketId === marketId);
64
+ return (position?.market?.getWithdrawCapacityLimit(position) ?? {
65
+ value: 0n,
66
+ limiter: utils_1.CapacityLimitReason.position,
67
+ });
68
+ }
69
+ }
70
+ exports.AccrualVaultV2MorphoMarketV1Adapter = AccrualVaultV2MorphoMarketV1Adapter;
@@ -1,6 +1,6 @@
1
1
  import { type Address, type Hex } from "viem";
2
2
  import { VaultV2Adapter } from "./VaultV2Adapter";
3
- export interface IVaultV2MorphoVaultV1Adapter extends IVaultV2Adapter {
3
+ export interface IVaultV2MorphoVaultV1Adapter extends Omit<IVaultV2Adapter, "adapterId"> {
4
4
  morphoVaultV1: Address;
5
5
  }
6
6
  import type { BigIntish } from "../../types";
@@ -18,7 +18,7 @@ export declare class AccrualVaultV2MorphoVaultV1Adapter extends VaultV2MorphoVau
18
18
  accrualVaultV1: AccrualVault;
19
19
  shares: bigint;
20
20
  constructor(adapter: IAccrualVaultV2MorphoVaultV1Adapter, accrualVaultV1: AccrualVault, shares: bigint);
21
- realAssets(timestamp: BigIntish): bigint;
21
+ realAssets(timestamp?: BigIntish): bigint;
22
22
  maxDeposit(_data: Hex, assets: BigIntish): import("../..").CapacityLimit;
23
23
  maxWithdraw(_data: Hex): import("../..").CapacityLimit;
24
24
  }
@@ -1,3 +1,4 @@
1
1
  export * from "./VaultV2.js";
2
2
  export * from "./VaultV2Adapter.js";
3
+ export * from "./VaultV2MorphoMarketV1Adapter.js";
3
4
  export * from "./VaultV2MorphoVaultV1Adapter.js";
@@ -16,4 +16,5 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
16
16
  Object.defineProperty(exports, "__esModule", { value: true });
17
17
  __exportStar(require("./VaultV2.js"), exports);
18
18
  __exportStar(require("./VaultV2Adapter.js"), exports);
19
+ __exportStar(require("./VaultV2MorphoMarketV1Adapter.js"), exports);
19
20
  __exportStar(require("./VaultV2MorphoVaultV1Adapter.js"), exports);
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.0",
4
+ "version": "5.3.0-next.1",
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/morpho-ts": "^2.4.3",
35
- "@morpho-org/test": "^2.6.0"
34
+ "@morpho-org/test": "^2.6.0",
35
+ "@morpho-org/morpho-ts": "^2.4.3"
36
36
  },
37
37
  "scripts": {
38
38
  "prepublish": "$npm_execpath build",