@morpho-org/blue-sdk 2.2.0 → 2.3.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.
@@ -1,4 +1,4 @@
1
- import { Market, type MaxBorrowOptions, type MaxWithdrawCollateralOptions } from "../market/index.js";
1
+ import { Market, type MaxBorrowOptions, type MaxPositionCapacities, type MaxWithdrawCollateralOptions } from "../market/index.js";
2
2
  import type { Address, BigIntish, MarketId } from "../types.js";
3
3
  export interface IPosition {
4
4
  user: Address;
@@ -98,8 +98,24 @@ export declare class AccrualPosition extends Position implements IAccrualPositio
98
98
  * If the collateral price is 0, usage is `MaxUint256`.
99
99
  */
100
100
  get borrowCapacityUsage(): bigint | undefined;
101
+ /**
102
+ * Returns the maximum amount of loan assets that can be borrowed given a certain borrow position
103
+ * and the reason for the limit.
104
+ * Returns `undefined` iff the market's price is undefined.
105
+ * @deprecated Use `getBorrowCapacityLimit` instead.
106
+ */
101
107
  get borrowCapacityLimit(): import("../market/Market.js").CapacityLimit | undefined;
108
+ /**
109
+ * Returns the maximum amount of loan assets that can be withdrawn given a certain supply position
110
+ * and a balance of loan assets, and the reason for the limit.
111
+ */
102
112
  get withdrawCapacityLimit(): import("../market/Market.js").CapacityLimit;
113
+ /**
114
+ * Returns the maximum amount of collateral assets that can be withdrawn given a certain borrow position
115
+ * and the reason for the limit.
116
+ * Returns `undefined` iff the market's price is undefined.
117
+ * @deprecated Use `getWithdrawCollateralCapacityLimit` instead.
118
+ */
103
119
  get withdrawCollateralCapacityLimit(): import("../market/Market.js").CapacityLimit | undefined;
104
120
  /**
105
121
  * Returns a new position derived from this position, whose interest has been accrued up to the given timestamp.
@@ -128,9 +144,11 @@ export declare class AccrualPosition extends Position implements IAccrualPositio
128
144
  assets: bigint;
129
145
  shares: bigint;
130
146
  };
147
+ getBorrowCapacityLimit(options?: MaxBorrowOptions): import("../market/Market.js").CapacityLimit | undefined;
148
+ getWithdrawCollateralCapacityLimit(options?: MaxWithdrawCollateralOptions): import("../market/Market.js").CapacityLimit | undefined;
131
149
  getRepayCapacityLimit(loanTokenBalance: bigint): import("../market/Market.js").CapacityLimit;
132
150
  getMaxCapacities(loanTokenBalance: bigint, collateralTokenBalance: bigint, options?: {
133
151
  borrow?: MaxBorrowOptions;
134
152
  withdrawCollateral?: MaxWithdrawCollateralOptions;
135
- }): import("../market/Market.js").MaxPositionCapacities;
153
+ }): MaxPositionCapacities;
136
154
  }
@@ -3,6 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.AccrualPosition = exports.Position = void 0;
4
4
  const errors_js_1 = require("../errors.js");
5
5
  const index_js_1 = require("../market/index.js");
6
+ const MathLib_js_1 = require("../math/MathLib.js");
6
7
  class Position {
7
8
  /**
8
9
  * The user holding this position.
@@ -67,7 +68,10 @@ class AccrualPosition extends Position {
67
68
  * `undefined` iff the market's oracle is undefined or reverts.
68
69
  */
69
70
  get maxBorrowableAssets() {
70
- return this.market.getMaxBorrowableAssets(this);
71
+ const { maxBorrowAssets } = this;
72
+ if (maxBorrowAssets == null)
73
+ return;
74
+ return MathLib_js_1.MathLib.zeroFloorSub(maxBorrowAssets, this.borrowAssets);
71
75
  }
72
76
  /**
73
77
  * The maximum amount of collateral that can be seized in exchange for the outstanding debt.
@@ -128,12 +132,28 @@ class AccrualPosition extends Position {
128
132
  get borrowCapacityUsage() {
129
133
  return this.market.getBorrowCapacityUsage(this);
130
134
  }
135
+ /**
136
+ * Returns the maximum amount of loan assets that can be borrowed given a certain borrow position
137
+ * and the reason for the limit.
138
+ * Returns `undefined` iff the market's price is undefined.
139
+ * @deprecated Use `getBorrowCapacityLimit` instead.
140
+ */
131
141
  get borrowCapacityLimit() {
132
142
  return this.market.getBorrowCapacityLimit(this);
133
143
  }
144
+ /**
145
+ * Returns the maximum amount of loan assets that can be withdrawn given a certain supply position
146
+ * and a balance of loan assets, and the reason for the limit.
147
+ */
134
148
  get withdrawCapacityLimit() {
135
149
  return this.market.getWithdrawCapacityLimit(this);
136
150
  }
151
+ /**
152
+ * Returns the maximum amount of collateral assets that can be withdrawn given a certain borrow position
153
+ * and the reason for the limit.
154
+ * Returns `undefined` iff the market's price is undefined.
155
+ * @deprecated Use `getWithdrawCollateralCapacityLimit` instead.
156
+ */
137
157
  get withdrawCollateralCapacityLimit() {
138
158
  return this.market.getWithdrawCollateralCapacityLimit(this);
139
159
  }
@@ -195,11 +215,30 @@ class AccrualPosition extends Position {
195
215
  throw new errors_js_1.BlueErrors.InsufficientPosition(position.user, position.marketId);
196
216
  return { position, assets, shares };
197
217
  }
218
+ getBorrowCapacityLimit(options) {
219
+ return this.market.getBorrowCapacityLimit(this, options);
220
+ }
221
+ getWithdrawCollateralCapacityLimit(options) {
222
+ return this.market.getWithdrawCollateralCapacityLimit(this, options);
223
+ }
198
224
  getRepayCapacityLimit(loanTokenBalance) {
199
225
  return this.market.getRepayCapacityLimit(this.borrowShares, loanTokenBalance);
200
226
  }
201
227
  getMaxCapacities(loanTokenBalance, collateralTokenBalance, options) {
202
- return this.market.getMaxCapacities(this, loanTokenBalance, collateralTokenBalance, options);
228
+ return {
229
+ supply: {
230
+ value: loanTokenBalance,
231
+ limiter: index_js_1.CapacityLimitReason.balance,
232
+ },
233
+ withdraw: this.withdrawCapacityLimit,
234
+ borrow: this.getBorrowCapacityLimit(options?.borrow),
235
+ repay: this.getRepayCapacityLimit(loanTokenBalance),
236
+ supplyCollateral: {
237
+ value: collateralTokenBalance,
238
+ limiter: index_js_1.CapacityLimitReason.balance,
239
+ },
240
+ withdrawCollateral: this.getWithdrawCollateralCapacityLimit(options?.withdrawCollateral),
241
+ };
203
242
  }
204
243
  }
205
244
  exports.AccrualPosition = AccrualPosition;
@@ -38,6 +38,7 @@ export interface IVault extends IVaultConfig {
38
38
  totalSupply: bigint;
39
39
  totalAssets: bigint;
40
40
  lastTotalAssets: bigint;
41
+ lostAssets?: bigint;
41
42
  publicAllocatorConfig?: VaultPublicAllocatorConfig;
42
43
  }
43
44
  export declare class Vault extends VaultToken implements IVault {
@@ -101,11 +102,16 @@ export declare class Vault extends VaultToken implements IVault {
101
102
  * The MetaMorpho vault's last total assets used to calculate performance fees.
102
103
  */
103
104
  lastTotalAssets: bigint;
105
+ /**
106
+ * The MetaMorpho vault's lost assets due to realized bad debt.
107
+ * Only defined for MetaMorpho V1.1 vaults.
108
+ */
109
+ lostAssets?: bigint;
104
110
  /**
105
111
  * The MetaMorpho vault's public allocator configuration.
106
112
  */
107
113
  publicAllocatorConfig?: VaultPublicAllocatorConfig;
108
- constructor({ curator, owner, guardian, publicAllocatorConfig, fee, feeRecipient, skimRecipient, pendingTimelock, pendingGuardian, pendingOwner, timelock, supplyQueue, withdrawQueue, totalSupply, totalAssets, lastTotalAssets, ...config }: IVault);
114
+ constructor({ curator, owner, guardian, publicAllocatorConfig, fee, feeRecipient, skimRecipient, pendingTimelock, pendingGuardian, pendingOwner, timelock, supplyQueue, withdrawQueue, totalSupply, totalAssets, lastTotalAssets, lostAssets, ...config }: IVault);
109
115
  /**
110
116
  * The amount of interest in assets accrued since the last interaction with the vault.
111
117
  */
@@ -58,11 +58,16 @@ class Vault extends index_js_3.VaultToken {
58
58
  * The MetaMorpho vault's last total assets used to calculate performance fees.
59
59
  */
60
60
  lastTotalAssets;
61
+ /**
62
+ * The MetaMorpho vault's lost assets due to realized bad debt.
63
+ * Only defined for MetaMorpho V1.1 vaults.
64
+ */
65
+ lostAssets;
61
66
  /**
62
67
  * The MetaMorpho vault's public allocator configuration.
63
68
  */
64
69
  publicAllocatorConfig;
65
- constructor({ curator, owner, guardian, publicAllocatorConfig, fee, feeRecipient, skimRecipient, pendingTimelock, pendingGuardian, pendingOwner, timelock, supplyQueue, withdrawQueue, totalSupply, totalAssets, lastTotalAssets, ...config }) {
70
+ constructor({ curator, owner, guardian, publicAllocatorConfig, fee, feeRecipient, skimRecipient, pendingTimelock, pendingGuardian, pendingOwner, timelock, supplyQueue, withdrawQueue, totalSupply, totalAssets, lastTotalAssets, lostAssets, ...config }) {
66
71
  super(config, { totalAssets, totalSupply });
67
72
  this.curator = curator;
68
73
  this.owner = owner;
@@ -80,6 +85,7 @@ class Vault extends index_js_3.VaultToken {
80
85
  this.supplyQueue = supplyQueue;
81
86
  this.withdrawQueue = withdrawQueue;
82
87
  this.lastTotalAssets = lastTotalAssets;
88
+ this.lostAssets = lostAssets;
83
89
  this.publicAllocatorConfig = publicAllocatorConfig;
84
90
  }
85
91
  /**
@@ -214,6 +220,10 @@ class AccrualVault extends Vault {
214
220
  position: position.accrueInterest(timestamp),
215
221
  };
216
222
  }));
223
+ if (vault.lostAssets != null) {
224
+ vault.lostAssets += index_js_2.MathLib.max(vault.lastTotalAssets - vault.lostAssets - vault.totalAssets, 0n);
225
+ vault.totalAssets += vault.lostAssets;
226
+ }
217
227
  const feeAssets = index_js_2.MathLib.wMulDown(vault.totalInterest, vault.fee);
218
228
  vault.totalAssets -= feeAssets;
219
229
  const feeShares = vault.toShares(feeAssets, "Down");
@@ -5,8 +5,15 @@ export interface IVaultConfig extends Omit<IToken, "decimals"> {
5
5
  asset: Address;
6
6
  }
7
7
  export declare class VaultConfig extends Token implements IVaultConfig {
8
+ /**
9
+ * @deprecated Kept for backward compatibility.
10
+ */
8
11
  readonly chainId?: number | undefined;
9
12
  readonly decimalsOffset: bigint;
10
13
  readonly asset: `0x${string}`;
11
- constructor({ decimalsOffset, asset, ...config }: IVaultConfig, chainId?: number | undefined);
14
+ constructor({ decimalsOffset, asset, ...config }: IVaultConfig,
15
+ /**
16
+ * @deprecated Kept for backward compatibility.
17
+ */
18
+ chainId?: number | undefined);
12
19
  }
@@ -6,7 +6,11 @@ class VaultConfig extends Token_js_1.Token {
6
6
  chainId;
7
7
  decimalsOffset;
8
8
  asset;
9
- constructor({ decimalsOffset, asset, ...config }, chainId) {
9
+ constructor({ decimalsOffset, asset, ...config },
10
+ /**
11
+ * @deprecated Kept for backward compatibility.
12
+ */
13
+ chainId) {
10
14
  super({ ...config, decimals: 18 });
11
15
  this.chainId = chainId;
12
16
  this.decimalsOffset = BigInt(decimalsOffset);
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.2.0",
4
+ "version": "2.3.0",
5
5
  "author": "Morpho Association <contact@morpho.org>",
6
6
  "contributors": [
7
7
  "Rubilmax <rmilon@gmail.com>"