@morpho-org/morpho-sdk 3.1.0 → 3.1.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.
package/README.md CHANGED
@@ -31,10 +31,12 @@ pnpm add @morpho-org/morpho-sdk
31
31
  | **VaultV1** | `deposit` | Bundler (general adapter) | Same ERC-4626 inflation attack prevention as V2. Supports native token wrapping. |
32
32
  | | `withdraw` | Direct vault call | No attack surface |
33
33
  | | `redeem` | Direct vault call | No attack surface |
34
- | **MarketV1** | `supplyCollateral` | Bundler (general adapter) | `erc20TransferFrom` + `morphoSupplyCollateral`. Supports native wrapping. |
34
+ | **MarketV1** | `supply` | Bundler (general adapter) | `erc20TransferFrom` + `morphoSupply` with `maxSharePrice` (inflation guard). Supports native wrapping when `loanToken === wNative`. |
35
+ | | `supplyCollateral` | Bundler (general adapter) | `erc20TransferFrom` + `morphoSupplyCollateral`. Supports native wrapping. |
35
36
  | | `borrow` | Bundler (general adapter) | `morphoBorrow` with `minSharePrice` slippage protection. Requires GA1 auth. Supports reallocations. |
36
37
  | | `supplyCollateralBorrow` | Bundler (general adapter) | Atomic supply + borrow. LLTV buffer prevents instant liquidation. Supports reallocations. |
37
38
  | | `repay` | Bundler (general adapter) | `erc20TransferFrom` + `morphoRepay` with `maxSharePrice` protection. Supports partial or full. |
39
+ | | `withdraw` | Bundler (general adapter) | `morphoWithdraw` with `minSharePrice` slippage protection. Requires GA1 auth. Supports reallocations. |
38
40
  | | `withdrawCollateral` | Direct Morpho call | No bundler overhead. Validates position health after withdrawal. |
39
41
  | | `repayWithdrawCollateral` | Bundler (general adapter) | Atomic repay + withdraw. Bundle order matters: repay first, then withdraw. |
40
42
 
@@ -81,9 +83,11 @@ const tx = buildTx(permitSignature);
81
83
  | | `withdraw` | Direct vault call | No attack surface |
82
84
  | | `redeem` | Direct vault call | No attack surface |
83
85
  | | `migrateToV2` | Bundler (general adapter) | Atomic V1 → V2 migration: redeem V1 shares + deposit into V2 in one tx. Slippage-protected. |
84
- | **MarketV1** | `supplyCollateral` | Bundler (general adapter) | `erc20TransferFrom` + `morphoSupplyCollateral`. Supports native wrapping. |
86
+ | **MarketV1** | `supply` | Bundler (general adapter) | `erc20TransferFrom` + `morphoSupply` with `maxSharePrice` (inflation guard). Supports native wrapping when `loanToken === wNative`. |
87
+ | | `supplyCollateral` | Bundler (general adapter) | `erc20TransferFrom` + `morphoSupplyCollateral`. Supports native wrapping. |
85
88
  | | `borrow` | Bundler (general adapter) | `morphoBorrow` with `minSharePrice` slippage protection. Requires GA1 auth. Supports reallocations. |
86
89
  | | `supplyCollateralBorrow` | Bundler (general adapter) | Atomic supply + borrow. LLTV buffer prevents instant liquidation. Supports reallocations. |
90
+ | | `withdraw` | Bundler (general adapter) | `morphoWithdraw` with `minSharePrice` slippage protection. Requires GA1 auth. Supports reallocations. |
87
91
 
88
92
  ### VaultV2
89
93
 
@@ -252,6 +256,37 @@ const market = client.morpho.marketV1(
252
256
  );
253
257
  ```
254
258
 
259
+ #### Supply (loan asset)
260
+
261
+ Supply the loan asset to earn yield on the market.
262
+
263
+ ```typescript
264
+ const marketData = await market.getMarketData();
265
+
266
+ const { buildTx, getRequirements } = market.supply({
267
+ amount: 1000000000n,
268
+ userAddress: "0xUser...",
269
+ marketData,
270
+ });
271
+
272
+ const requirements = await getRequirements();
273
+ const tx = buildTx(requirementSignature);
274
+ ```
275
+
276
+ ##### Supply with native token wrapping
277
+
278
+ If the market's `loanToken` is the chain's wNative, you can supply native token that will be wrapped automatically:
279
+
280
+ ```typescript
281
+ const { buildTx, getRequirements } = market.supply({
282
+ nativeAmount: 1000000000000000000n,
283
+ userAddress: "0xUser...",
284
+ marketData,
285
+ });
286
+ ```
287
+
288
+ The bundle routes through `GeneralAdapter1` with `maxSharePrice` slippage protection (anti-inflation guard).
289
+
255
290
  #### Supply Collateral
256
291
 
257
292
  ```typescript
@@ -322,6 +357,33 @@ const tx = buildTx(requirementSignature);
322
357
 
323
358
  Repay does **not** require Morpho authorization (it only requires a loan token approval for `GeneralAdapter1`).
324
359
 
360
+ #### Withdraw (loan asset)
361
+
362
+ Two modes — `assets` (exact amount) or `shares` (full close, immune to interest accrual between quote and inclusion). Routed through bundler3 with `minSharePrice` slippage protection; the withdrawn assets are sent directly to `receiver` (defaults to `userAddress`). Optional `reallocations` top up market liquidity via the **PublicAllocator** when the on-market liquidity is insufficient (same mechanism as `borrow`).
363
+
364
+ ```typescript
365
+ const positionData = await market.getPositionData("0xUser...");
366
+
367
+ // Withdraw an exact amount of loan asset
368
+ const { buildTx, getRequirements } = market.withdraw({
369
+ assets: 500000000n,
370
+ userAddress: "0xUser...",
371
+ positionData,
372
+ });
373
+
374
+ // Or close the full supply position by shares
375
+ const { buildTx, getRequirements } = market.withdraw({
376
+ shares: positionData.supplyShares,
377
+ userAddress: "0xUser...",
378
+ positionData,
379
+ });
380
+
381
+ const requirements = await getRequirements();
382
+ const tx = buildTx();
383
+ ```
384
+
385
+ Loan-asset withdraw requires Morpho authorization for `GeneralAdapter1` (returned by `getRequirements` when missing). It does **not** require a token approval.
386
+
325
387
  #### Withdraw Collateral
326
388
 
327
389
  ```typescript
@@ -443,13 +505,17 @@ graph LR
443
505
 
444
506
  subgraph MarketV1 Flow
445
507
  MM1[MorphoMarketV1]
508
+ MM1 --> M1S[marketV1Supply]
446
509
  MM1 --> M1SC[marketV1SupplyCollateral]
447
510
  MM1 --> M1B[marketV1Borrow]
448
511
  MM1 --> M1SCB[marketV1SupplyCollateralBorrow]
512
+ MM1 --> M1W[marketV1Withdraw]
449
513
 
450
- M1SC -->|erc20TransferFrom + morphoSupplyCollateral| B3[Bundler3]
514
+ M1S -->|nativeWrap? + erc20TransferFrom + morphoSupply| B3[Bundler3]
515
+ M1SC -->|erc20TransferFrom + morphoSupplyCollateral| B3
451
516
  M1B -->|reallocateTo? + morphoBorrow| B3
452
517
  M1SCB -->|transfer + supplyCollateral + reallocateTo? + borrow| B3
518
+ M1W -->|reallocateTo? + morphoWithdraw| B3
453
519
 
454
520
  B3 -.->|reallocateTo| PA[PublicAllocator]
455
521
  end
@@ -421,7 +421,7 @@ export declare namespace BundlerAction {
421
421
  * @param market - Morpho Blue market parameters.
422
422
  * @param assets - Borrow asset amount.
423
423
  * @param shares - Borrow share amount.
424
- * @param slippageAmount - Slippage guard amount.
424
+ * @param minSharePrice - Minimum amount of borrowed assets per borrow share minted, scaled by 1e27.
425
425
  * @param receiver - Recipient of borrowed assets.
426
426
  * @param skipRevert - Whether Bundler3 should tolerate a revert.
427
427
  * @returns Encoded Bundler3 calls.
@@ -453,7 +453,7 @@ export declare namespace BundlerAction {
453
453
  * );
454
454
  * ```
455
455
  */
456
- function morphoBorrow(chainId: number, market: InputMarketParams, assets: bigint, shares: bigint, slippageAmount: bigint, receiver: Address, skipRevert?: boolean): BundlerCall[];
456
+ function morphoBorrow(chainId: number, market: InputMarketParams, assets: bigint, shares: bigint, minSharePrice: bigint, receiver: Address, skipRevert?: boolean): BundlerCall[];
457
457
  /**
458
458
  * Encodes a GeneralAdapter1 Morpho Blue repay call.
459
459
  *
@@ -461,7 +461,7 @@ export declare namespace BundlerAction {
461
461
  * @param market - Morpho Blue market parameters.
462
462
  * @param assets - Repay asset amount.
463
463
  * @param shares - Repay share amount.
464
- * @param slippageAmount - Slippage guard amount.
464
+ * @param maxSharePrice - Maximum amount of repaid assets per borrow share redeemed, scaled by 1e27.
465
465
  * @param onBehalf - Account whose borrow is repaid.
466
466
  * @param callbackCalls - Calls executed in Morpho's callback.
467
467
  * @param skipRevert - Whether Bundler3 should tolerate a revert.
@@ -495,7 +495,7 @@ export declare namespace BundlerAction {
495
495
  * );
496
496
  * ```
497
497
  */
498
- function morphoRepay(chainId: number, market: InputMarketParams, assets: bigint, shares: bigint, slippageAmount: bigint, onBehalf: Address, callbackCalls: BundlerCall[], skipRevert?: boolean): BundlerCall[];
498
+ function morphoRepay(chainId: number, market: InputMarketParams, assets: bigint, shares: bigint, maxSharePrice: bigint, onBehalf: Address, callbackCalls: BundlerCall[], skipRevert?: boolean): BundlerCall[];
499
499
  /**
500
500
  * Encodes a GeneralAdapter1 Morpho Blue withdraw call.
501
501
  *
@@ -176,8 +176,8 @@ var BundlerAction;
176
176
  return BundlerAction.morphoWithdraw(chainId, ...args);
177
177
  }
178
178
  case "morphoRepay": {
179
- const [market, assets, shares, slippageAmount, onBehalf, onMorphoRepay, skipRevert,] = args;
180
- return BundlerAction.morphoRepay(chainId, market, assets, shares, slippageAmount, onBehalf, onMorphoRepay.flatMap(BundlerAction.encode.bind(null, chainId)), skipRevert);
179
+ const [market, assets, shares, maxSharePrice, onBehalf, onMorphoRepay, skipRevert,] = args;
180
+ return BundlerAction.morphoRepay(chainId, market, assets, shares, maxSharePrice, onBehalf, onMorphoRepay.flatMap(BundlerAction.encode.bind(null, chainId)), skipRevert);
181
181
  }
182
182
  case "morphoWithdrawCollateral": {
183
183
  return BundlerAction.morphoWithdrawCollateral(chainId, ...args);
@@ -766,7 +766,7 @@ var BundlerAction;
766
766
  * @param market - Morpho Blue market parameters.
767
767
  * @param assets - Borrow asset amount.
768
768
  * @param shares - Borrow share amount.
769
- * @param slippageAmount - Slippage guard amount.
769
+ * @param minSharePrice - Minimum amount of borrowed assets per borrow share minted, scaled by 1e27.
770
770
  * @param receiver - Recipient of borrowed assets.
771
771
  * @param skipRevert - Whether Bundler3 should tolerate a revert.
772
772
  * @returns Encoded Bundler3 calls.
@@ -799,7 +799,7 @@ var BundlerAction;
799
799
  * ```
800
800
  */
801
801
  // biome-ignore lint/complexity/useMaxParams: TODO refactor to ≤2 params
802
- function morphoBorrow(chainId, market, assets, shares, slippageAmount, receiver, skipRevert = false) {
802
+ function morphoBorrow(chainId, market, assets, shares, minSharePrice, receiver, skipRevert = false) {
803
803
  const { bundler3: { generalAdapter1 }, } = (0, blue_sdk_1.getChainAddresses)(chainId);
804
804
  return [
805
805
  {
@@ -807,7 +807,7 @@ var BundlerAction;
807
807
  data: (0, viem_1.encodeFunctionData)({
808
808
  abi: abis_js_1.generalAdapter1Abi,
809
809
  functionName: "morphoBorrow",
810
- args: [market, assets, shares, slippageAmount, receiver],
810
+ args: [market, assets, shares, minSharePrice, receiver],
811
811
  }),
812
812
  value: 0n,
813
813
  skipRevert,
@@ -823,7 +823,7 @@ var BundlerAction;
823
823
  * @param market - Morpho Blue market parameters.
824
824
  * @param assets - Repay asset amount.
825
825
  * @param shares - Repay share amount.
826
- * @param slippageAmount - Slippage guard amount.
826
+ * @param maxSharePrice - Maximum amount of repaid assets per borrow share redeemed, scaled by 1e27.
827
827
  * @param onBehalf - Account whose borrow is repaid.
828
828
  * @param callbackCalls - Calls executed in Morpho's callback.
829
829
  * @param skipRevert - Whether Bundler3 should tolerate a revert.
@@ -858,7 +858,7 @@ var BundlerAction;
858
858
  * ```
859
859
  */
860
860
  // biome-ignore lint/complexity/useMaxParams: TODO refactor to ≤2 params
861
- function morphoRepay(chainId, market, assets, shares, slippageAmount, onBehalf, callbackCalls, skipRevert = false) {
861
+ function morphoRepay(chainId, market, assets, shares, maxSharePrice, onBehalf, callbackCalls, skipRevert = false) {
862
862
  const { bundler3: { generalAdapter1 }, } = (0, blue_sdk_1.getChainAddresses)(chainId);
863
863
  const { callbackHash, reenterData } = encodeCallbackCalls(callbackCalls);
864
864
  return [
@@ -867,7 +867,7 @@ var BundlerAction;
867
867
  data: (0, viem_1.encodeFunctionData)({
868
868
  abi: abis_js_1.generalAdapter1Abi,
869
869
  functionName: "morphoRepay",
870
- args: [market, assets, shares, slippageAmount, onBehalf, reenterData],
870
+ args: [market, assets, shares, maxSharePrice, onBehalf, reenterData],
871
871
  }),
872
872
  value: 0n,
873
873
  skipRevert,
@@ -131,21 +131,21 @@ export interface ActionArgs {
131
131
  onMorphoSupply: Action[],
132
132
  skipRevert?: boolean
133
133
  ];
134
- /** Morpho Blue borrow call for `market`, `assets` or `shares`, `slippageAmount`, and `receiver`; `skipRevert` controls Bundler3 revert handling. */
134
+ /** Morpho Blue borrow call for `market`, `assets` or `shares`, `minSharePrice`, and `receiver`; `skipRevert` controls Bundler3 revert handling. */
135
135
  readonly morphoBorrow: [
136
136
  market: InputMarketParams,
137
137
  assets: bigint,
138
138
  shares: bigint,
139
- slippageAmount: bigint,
139
+ minSharePrice: bigint,
140
140
  receiver: Address,
141
141
  skipRevert?: boolean
142
142
  ];
143
- /** Morpho Blue repay call for `market`, `assets` or `shares`, `slippageAmount`, `onBehalf`, and callback actions; `skipRevert` controls Bundler3 revert handling. */
143
+ /** Morpho Blue repay call for `market`, `assets` or `shares`, `maxSharePrice`, `onBehalf`, and callback actions; `skipRevert` controls Bundler3 revert handling. */
144
144
  readonly morphoRepay: [
145
145
  market: InputMarketParams,
146
146
  assets: bigint,
147
147
  shares: bigint,
148
- slippageAmount: bigint,
148
+ maxSharePrice: bigint,
149
149
  onBehalf: Address,
150
150
  onMorphoRepay: Action[],
151
151
  skipRevert?: boolean
@@ -285,6 +285,7 @@ class ReallocationData {
285
285
  if (count <= 1)
286
286
  continue;
287
287
  const vaultPublicAllocatorConfig = data.getVault(vault).publicAllocatorConfig;
288
+ /* v8 ignore next: repeated withdrawals require a configured public allocator earlier in the flow. */
288
289
  if (vaultPublicAllocatorConfig == null)
289
290
  throw new index_js_1.MissingPublicAllocatorConfigError(vault);
290
291
  vaultPublicAllocatorConfig.accruedFee -=
@@ -357,7 +358,9 @@ class ReallocationData {
357
358
  applyPublicReallocation({ vault, supplyMarketId, withdrawal, timestamp, }) {
358
359
  const data = this.forkAliasedState();
359
360
  data.vaults[vault] = cloneVault(this.getVault(vault));
361
+ /* v8 ignore next: forkAliasedState keeps vault position buckets initialized for known vaults. */
360
362
  data.positions[vault] = { ...(this.positions[vault] ?? {}) };
363
+ /* v8 ignore next: forkAliasedState keeps vault market config buckets initialized for known vaults. */
361
364
  data.vaultMarketConfigs[vault] = {
362
365
  ...(this.vaultMarketConfigs[vault] ?? {}),
363
366
  };
@@ -38,6 +38,7 @@ const capVaultWithdrawals = (withdrawals, assets) => {
38
38
  let remainingAssets = assets;
39
39
  for (const withdrawal of withdrawals) {
40
40
  const cappedAssets = blue_sdk_1.MathLib.min(withdrawal.assets, remainingAssets);
41
+ /* v8 ignore next: grouped withdrawals and positive reallocation cap keep this defensive guard unreachable. */
41
42
  if (cappedAssets <= 0n)
42
43
  continue;
43
44
  const existing = cappedWithdrawals.find((item) => item.id === withdrawal.id);
@@ -188,6 +189,7 @@ const computeReallocations = ({ reallocationData: data, marketId, operation, amo
188
189
  let remainingRequiredAssets = requiredAssets;
189
190
  for (const group of groupWithdrawalsByVault(withdrawals)) {
190
191
  const reallocatedAssets = blue_sdk_1.MathLib.min(group.totalAssets, remainingRequiredAssets);
192
+ /* v8 ignore next: groups with non-positive assets are filtered before this point. */
191
193
  if (reallocatedAssets <= 0n)
192
194
  continue;
193
195
  reallocations.push({
@@ -421,7 +421,7 @@ export declare namespace BundlerAction {
421
421
  * @param market - Morpho Blue market parameters.
422
422
  * @param assets - Borrow asset amount.
423
423
  * @param shares - Borrow share amount.
424
- * @param slippageAmount - Slippage guard amount.
424
+ * @param minSharePrice - Minimum amount of borrowed assets per borrow share minted, scaled by 1e27.
425
425
  * @param receiver - Recipient of borrowed assets.
426
426
  * @param skipRevert - Whether Bundler3 should tolerate a revert.
427
427
  * @returns Encoded Bundler3 calls.
@@ -453,7 +453,7 @@ export declare namespace BundlerAction {
453
453
  * );
454
454
  * ```
455
455
  */
456
- function morphoBorrow(chainId: number, market: InputMarketParams, assets: bigint, shares: bigint, slippageAmount: bigint, receiver: Address, skipRevert?: boolean): BundlerCall[];
456
+ function morphoBorrow(chainId: number, market: InputMarketParams, assets: bigint, shares: bigint, minSharePrice: bigint, receiver: Address, skipRevert?: boolean): BundlerCall[];
457
457
  /**
458
458
  * Encodes a GeneralAdapter1 Morpho Blue repay call.
459
459
  *
@@ -461,7 +461,7 @@ export declare namespace BundlerAction {
461
461
  * @param market - Morpho Blue market parameters.
462
462
  * @param assets - Repay asset amount.
463
463
  * @param shares - Repay share amount.
464
- * @param slippageAmount - Slippage guard amount.
464
+ * @param maxSharePrice - Maximum amount of repaid assets per borrow share redeemed, scaled by 1e27.
465
465
  * @param onBehalf - Account whose borrow is repaid.
466
466
  * @param callbackCalls - Calls executed in Morpho's callback.
467
467
  * @param skipRevert - Whether Bundler3 should tolerate a revert.
@@ -495,7 +495,7 @@ export declare namespace BundlerAction {
495
495
  * );
496
496
  * ```
497
497
  */
498
- function morphoRepay(chainId: number, market: InputMarketParams, assets: bigint, shares: bigint, slippageAmount: bigint, onBehalf: Address, callbackCalls: BundlerCall[], skipRevert?: boolean): BundlerCall[];
498
+ function morphoRepay(chainId: number, market: InputMarketParams, assets: bigint, shares: bigint, maxSharePrice: bigint, onBehalf: Address, callbackCalls: BundlerCall[], skipRevert?: boolean): BundlerCall[];
499
499
  /**
500
500
  * Encodes a GeneralAdapter1 Morpho Blue withdraw call.
501
501
  *
@@ -173,8 +173,8 @@ export var BundlerAction;
173
173
  return BundlerAction.morphoWithdraw(chainId, ...args);
174
174
  }
175
175
  case "morphoRepay": {
176
- const [market, assets, shares, slippageAmount, onBehalf, onMorphoRepay, skipRevert,] = args;
177
- return BundlerAction.morphoRepay(chainId, market, assets, shares, slippageAmount, onBehalf, onMorphoRepay.flatMap(BundlerAction.encode.bind(null, chainId)), skipRevert);
176
+ const [market, assets, shares, maxSharePrice, onBehalf, onMorphoRepay, skipRevert,] = args;
177
+ return BundlerAction.morphoRepay(chainId, market, assets, shares, maxSharePrice, onBehalf, onMorphoRepay.flatMap(BundlerAction.encode.bind(null, chainId)), skipRevert);
178
178
  }
179
179
  case "morphoWithdrawCollateral": {
180
180
  return BundlerAction.morphoWithdrawCollateral(chainId, ...args);
@@ -763,7 +763,7 @@ export var BundlerAction;
763
763
  * @param market - Morpho Blue market parameters.
764
764
  * @param assets - Borrow asset amount.
765
765
  * @param shares - Borrow share amount.
766
- * @param slippageAmount - Slippage guard amount.
766
+ * @param minSharePrice - Minimum amount of borrowed assets per borrow share minted, scaled by 1e27.
767
767
  * @param receiver - Recipient of borrowed assets.
768
768
  * @param skipRevert - Whether Bundler3 should tolerate a revert.
769
769
  * @returns Encoded Bundler3 calls.
@@ -796,7 +796,7 @@ export var BundlerAction;
796
796
  * ```
797
797
  */
798
798
  // biome-ignore lint/complexity/useMaxParams: TODO refactor to ≤2 params
799
- function morphoBorrow(chainId, market, assets, shares, slippageAmount, receiver, skipRevert = false) {
799
+ function morphoBorrow(chainId, market, assets, shares, minSharePrice, receiver, skipRevert = false) {
800
800
  const { bundler3: { generalAdapter1 }, } = getChainAddresses(chainId);
801
801
  return [
802
802
  {
@@ -804,7 +804,7 @@ export var BundlerAction;
804
804
  data: encodeFunctionData({
805
805
  abi: generalAdapter1Abi,
806
806
  functionName: "morphoBorrow",
807
- args: [market, assets, shares, slippageAmount, receiver],
807
+ args: [market, assets, shares, minSharePrice, receiver],
808
808
  }),
809
809
  value: 0n,
810
810
  skipRevert,
@@ -820,7 +820,7 @@ export var BundlerAction;
820
820
  * @param market - Morpho Blue market parameters.
821
821
  * @param assets - Repay asset amount.
822
822
  * @param shares - Repay share amount.
823
- * @param slippageAmount - Slippage guard amount.
823
+ * @param maxSharePrice - Maximum amount of repaid assets per borrow share redeemed, scaled by 1e27.
824
824
  * @param onBehalf - Account whose borrow is repaid.
825
825
  * @param callbackCalls - Calls executed in Morpho's callback.
826
826
  * @param skipRevert - Whether Bundler3 should tolerate a revert.
@@ -855,7 +855,7 @@ export var BundlerAction;
855
855
  * ```
856
856
  */
857
857
  // biome-ignore lint/complexity/useMaxParams: TODO refactor to ≤2 params
858
- function morphoRepay(chainId, market, assets, shares, slippageAmount, onBehalf, callbackCalls, skipRevert = false) {
858
+ function morphoRepay(chainId, market, assets, shares, maxSharePrice, onBehalf, callbackCalls, skipRevert = false) {
859
859
  const { bundler3: { generalAdapter1 }, } = getChainAddresses(chainId);
860
860
  const { callbackHash, reenterData } = encodeCallbackCalls(callbackCalls);
861
861
  return [
@@ -864,7 +864,7 @@ export var BundlerAction;
864
864
  data: encodeFunctionData({
865
865
  abi: generalAdapter1Abi,
866
866
  functionName: "morphoRepay",
867
- args: [market, assets, shares, slippageAmount, onBehalf, reenterData],
867
+ args: [market, assets, shares, maxSharePrice, onBehalf, reenterData],
868
868
  }),
869
869
  value: 0n,
870
870
  skipRevert,
@@ -131,21 +131,21 @@ export interface ActionArgs {
131
131
  onMorphoSupply: Action[],
132
132
  skipRevert?: boolean
133
133
  ];
134
- /** Morpho Blue borrow call for `market`, `assets` or `shares`, `slippageAmount`, and `receiver`; `skipRevert` controls Bundler3 revert handling. */
134
+ /** Morpho Blue borrow call for `market`, `assets` or `shares`, `minSharePrice`, and `receiver`; `skipRevert` controls Bundler3 revert handling. */
135
135
  readonly morphoBorrow: [
136
136
  market: InputMarketParams,
137
137
  assets: bigint,
138
138
  shares: bigint,
139
- slippageAmount: bigint,
139
+ minSharePrice: bigint,
140
140
  receiver: Address,
141
141
  skipRevert?: boolean
142
142
  ];
143
- /** Morpho Blue repay call for `market`, `assets` or `shares`, `slippageAmount`, `onBehalf`, and callback actions; `skipRevert` controls Bundler3 revert handling. */
143
+ /** Morpho Blue repay call for `market`, `assets` or `shares`, `maxSharePrice`, `onBehalf`, and callback actions; `skipRevert` controls Bundler3 revert handling. */
144
144
  readonly morphoRepay: [
145
145
  market: InputMarketParams,
146
146
  assets: bigint,
147
147
  shares: bigint,
148
- slippageAmount: bigint,
148
+ maxSharePrice: bigint,
149
149
  onBehalf: Address,
150
150
  onMorphoRepay: Action[],
151
151
  skipRevert?: boolean
@@ -282,6 +282,7 @@ export class ReallocationData {
282
282
  if (count <= 1)
283
283
  continue;
284
284
  const vaultPublicAllocatorConfig = data.getVault(vault).publicAllocatorConfig;
285
+ /* v8 ignore next: repeated withdrawals require a configured public allocator earlier in the flow. */
285
286
  if (vaultPublicAllocatorConfig == null)
286
287
  throw new MissingPublicAllocatorConfigError(vault);
287
288
  vaultPublicAllocatorConfig.accruedFee -=
@@ -354,7 +355,9 @@ export class ReallocationData {
354
355
  applyPublicReallocation({ vault, supplyMarketId, withdrawal, timestamp, }) {
355
356
  const data = this.forkAliasedState();
356
357
  data.vaults[vault] = cloneVault(this.getVault(vault));
358
+ /* v8 ignore next: forkAliasedState keeps vault position buckets initialized for known vaults. */
357
359
  data.positions[vault] = { ...(this.positions[vault] ?? {}) };
360
+ /* v8 ignore next: forkAliasedState keeps vault market config buckets initialized for known vaults. */
358
361
  data.vaultMarketConfigs[vault] = {
359
362
  ...(this.vaultMarketConfigs[vault] ?? {}),
360
363
  };
@@ -35,6 +35,7 @@ const capVaultWithdrawals = (withdrawals, assets) => {
35
35
  let remainingAssets = assets;
36
36
  for (const withdrawal of withdrawals) {
37
37
  const cappedAssets = MathLib.min(withdrawal.assets, remainingAssets);
38
+ /* v8 ignore next: grouped withdrawals and positive reallocation cap keep this defensive guard unreachable. */
38
39
  if (cappedAssets <= 0n)
39
40
  continue;
40
41
  const existing = cappedWithdrawals.find((item) => item.id === withdrawal.id);
@@ -185,6 +186,7 @@ export const computeReallocations = ({ reallocationData: data, marketId, operati
185
186
  let remainingRequiredAssets = requiredAssets;
186
187
  for (const group of groupWithdrawalsByVault(withdrawals)) {
187
188
  const reallocatedAssets = MathLib.min(group.totalAssets, remainingRequiredAssets);
189
+ /* v8 ignore next: groups with non-positive assets are filtered before this point. */
188
190
  if (reallocatedAssets <= 0n)
189
191
  continue;
190
192
  reallocations.push({
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@morpho-org/morpho-sdk",
3
3
  "description": "Abstraction layer for Morpho's complexity.",
4
- "version": "3.1.0",
4
+ "version": "3.1.1",
5
5
  "author": "Morpho Association <contact@morpho.org>",
6
6
  "contributors": [
7
7
  "Foulks-Plb <https://x.com/FoulkPlb>"
@@ -137,9 +137,9 @@
137
137
  ],
138
138
  "dependencies": {
139
139
  "zod": "^4.4.3",
140
- "@morpho-org/blue-sdk": "^6.0.1",
141
- "@morpho-org/blue-sdk-viem": "^5.0.1",
142
- "@morpho-org/morpho-ts": "^2.5.3"
140
+ "@morpho-org/blue-sdk": "^6.1.0",
141
+ "@morpho-org/blue-sdk-viem": "^5.1.0",
142
+ "@morpho-org/morpho-ts": "^2.6.0"
143
143
  },
144
144
  "peerDependencies": {
145
145
  "viem": "^2.0.0"
@@ -150,8 +150,8 @@
150
150
  "typescript": "^6.0.3",
151
151
  "viem": "^2.50.4",
152
152
  "vitest": "^4.1.7",
153
- "@morpho-org/bundler-sdk-viem": "^5.0.2",
154
- "@morpho-org/simulation-sdk": "^4.0.2",
153
+ "@morpho-org/bundler-sdk-viem": "^5.0.3",
154
+ "@morpho-org/simulation-sdk": "^4.0.3",
155
155
  "@morpho-org/test": "^2.8.1"
156
156
  },
157
157
  "scripts": {