@morpho-org/morpho-sdk 5.10.1 → 5.12.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.
Files changed (79) hide show
  1. package/README.md +6 -0
  2. package/lib/cjs/abis.d.ts +17 -2
  3. package/lib/cjs/abis.js +14 -1
  4. package/lib/cjs/augment/VaultMarketPublicAllocatorConfig.d.ts +4 -1
  5. package/lib/cjs/blue/abis.d.ts +5 -1
  6. package/lib/cjs/blue/abis.js +2 -0
  7. package/lib/cjs/blue/entities.d.ts +8 -2
  8. package/lib/cjs/blue/entities.js +1 -0
  9. package/lib/cjs/blue/errors.d.ts +1 -1
  10. package/lib/cjs/blue/errors.js +2 -1
  11. package/lib/cjs/blue/fetch.d.ts +3 -1
  12. package/lib/cjs/blue/fetch.js +1 -0
  13. package/lib/cjs/entities/blue/blue.d.ts +10 -0
  14. package/lib/cjs/entities/blue/blue.js +9 -2
  15. package/lib/cjs/entities/index.d.ts +8 -2
  16. package/lib/cjs/entities/index.js +1 -0
  17. package/lib/cjs/entities/midnight/midnight.js +5 -13
  18. package/lib/cjs/entities/vaultV1/vaultV1.d.ts +2 -0
  19. package/lib/cjs/entities/vaultV1/vaultV1.js +2 -0
  20. package/lib/cjs/entities/vaultV1ReallocationData.d.ts +6 -0
  21. package/lib/cjs/entities/vaultV1ReallocationData.js +20 -5
  22. package/lib/cjs/entities/vaultV2/vaultV2.d.ts +2 -0
  23. package/lib/cjs/entities/vaultV2/vaultV2.js +3 -1
  24. package/lib/cjs/entities/vaultV2BlueReallocationData.d.ts +8 -1
  25. package/lib/cjs/entities/vaultV2BlueReallocationData.js +41 -12
  26. package/lib/cjs/errors.d.ts +1 -1
  27. package/lib/cjs/errors.js +3 -2
  28. package/lib/cjs/fetch.d.ts +3 -1
  29. package/lib/cjs/fetch.js +1 -0
  30. package/lib/cjs/helpers/computeVaultV1Reallocations.d.ts +2 -0
  31. package/lib/cjs/helpers/computeVaultV1Reallocations.js +2 -0
  32. package/lib/cjs/helpers/previewVaultV2InKindRedeem.d.ts +1 -0
  33. package/lib/cjs/helpers/previewVaultV2InKindRedeem.js +2 -0
  34. package/lib/cjs/helpers/validate.d.ts +30 -8
  35. package/lib/cjs/helpers/validate.js +30 -8
  36. package/lib/cjs/types/action.d.ts +57 -4
  37. package/lib/cjs/types/error.d.ts +1 -1
  38. package/lib/cjs/types/error.js +2 -2
  39. package/lib/cjs/types/sharedLiquidity.d.ts +2 -2
  40. package/lib/esm/abis.d.ts +17 -2
  41. package/lib/esm/abis.js +17 -2
  42. package/lib/esm/augment/VaultMarketPublicAllocatorConfig.d.ts +4 -1
  43. package/lib/esm/augment/VaultMarketPublicAllocatorConfig.js +3 -1
  44. package/lib/esm/blue/abis.d.ts +5 -1
  45. package/lib/esm/blue/abis.js +5 -1
  46. package/lib/esm/blue/entities.d.ts +8 -2
  47. package/lib/esm/blue/entities.js +3 -1
  48. package/lib/esm/blue/errors.d.ts +1 -1
  49. package/lib/esm/blue/errors.js +1 -1
  50. package/lib/esm/blue/fetch.d.ts +3 -1
  51. package/lib/esm/blue/fetch.js +3 -1
  52. package/lib/esm/entities/blue/blue.d.ts +10 -0
  53. package/lib/esm/entities/blue/blue.js +9 -2
  54. package/lib/esm/entities/index.d.ts +8 -2
  55. package/lib/esm/entities/index.js +3 -1
  56. package/lib/esm/entities/midnight/midnight.js +5 -13
  57. package/lib/esm/entities/vaultV1/vaultV1.d.ts +2 -0
  58. package/lib/esm/entities/vaultV1/vaultV1.js +2 -0
  59. package/lib/esm/entities/vaultV1ReallocationData.d.ts +6 -0
  60. package/lib/esm/entities/vaultV1ReallocationData.js +20 -5
  61. package/lib/esm/entities/vaultV2/vaultV2.d.ts +2 -0
  62. package/lib/esm/entities/vaultV2/vaultV2.js +3 -1
  63. package/lib/esm/entities/vaultV2BlueReallocationData.d.ts +8 -1
  64. package/lib/esm/entities/vaultV2BlueReallocationData.js +41 -12
  65. package/lib/esm/errors.d.ts +1 -1
  66. package/lib/esm/errors.js +1 -1
  67. package/lib/esm/fetch.d.ts +3 -1
  68. package/lib/esm/fetch.js +3 -1
  69. package/lib/esm/helpers/computeVaultV1Reallocations.d.ts +2 -0
  70. package/lib/esm/helpers/computeVaultV1Reallocations.js +2 -0
  71. package/lib/esm/helpers/previewVaultV2InKindRedeem.d.ts +1 -0
  72. package/lib/esm/helpers/previewVaultV2InKindRedeem.js +2 -0
  73. package/lib/esm/helpers/validate.d.ts +30 -8
  74. package/lib/esm/helpers/validate.js +30 -8
  75. package/lib/esm/types/action.d.ts +57 -4
  76. package/lib/esm/types/error.d.ts +1 -1
  77. package/lib/esm/types/error.js +2 -2
  78. package/lib/esm/types/sharedLiquidity.d.ts +2 -2
  79. package/package.json +5 -5
@@ -213,10 +213,13 @@ class VaultV1ReallocationData {
213
213
  * Returned `data` normalizes `vault.publicAllocatorConfig.accruedFee` to the
214
214
  * on-chain `reallocateTo` fee semantics: one fee charge per vault with at
215
215
  * least one computed withdrawal.
216
+ * Sources with zero allocator withdrawal capacity and destinations with no deposit capacity
217
+ * are skipped before projecting source interest.
216
218
  *
217
219
  * @param marketId - Target market to supply with shared liquidity.
218
220
  * @param options - Optional allocator discovery options.
219
221
  * @returns Computed source-market withdrawals and the post-reallocation state.
222
+ * @throws {UnsupportedBlueMarketIrmError} when a market with positive debt uses an unsupported IRM.
220
223
  * @throws {@link UnknownReallocationMarketError} when the target market is absent.
221
224
  * @deprecated Vault V1 shared-liquidity planning will be removed in the next major. Use
222
225
  * `VaultV2BlueReallocationData.computeVaultV2BlueReallocations`.
@@ -314,6 +317,7 @@ class VaultV1ReallocationData {
314
317
  * @param marketId - Target market to supply with shared liquidity.
315
318
  * @param options - Optional allocator discovery options.
316
319
  * @returns Computed source-market withdrawals and the post-reallocation state.
320
+ * @throws {UnsupportedBlueMarketIrmError} when a market with positive debt uses an unsupported IRM.
317
321
  * @throws {@link UnknownReallocationMarketError} when the target market is absent.
318
322
  * @deprecated Vault V1 shared-liquidity planning will be removed in the next major. Use
319
323
  * `VaultV2BlueReallocationData.computeVaultV2BlueReallocations`.
@@ -333,6 +337,7 @@ class VaultV1ReallocationData {
333
337
  * @param marketId - Target market that would receive the liquidity.
334
338
  * @param options - Optional allocator discovery options.
335
339
  * @returns Total reallocatable assets in loan-token units; `0n` when none is available.
340
+ * @throws {UnsupportedBlueMarketIrmError} when a market with positive debt uses an unsupported IRM.
336
341
  * @throws {@link UnknownReallocationMarketError} when the target market is absent.
337
342
  * @deprecated Vault V1 shared-liquidity metrics will be removed in the next major. Use
338
343
  * `VaultV2BlueReallocationData.getPublicReallocationLiquidity`.
@@ -389,6 +394,7 @@ class VaultV1ReallocationData {
389
394
  * @param utilization - Utilization to bring the market to, scaled by WAD. Defaults to {@link DEFAULT_SUPPLY_TARGET_UTILIZATION}.
390
395
  * @param options - Optional reallocation options (supply target utilization trigger, timestamp, withdrawal caps).
391
396
  * @returns Available liquidity to the given utilization in loan-token units; `0n` when none is available.
397
+ * @throws {UnsupportedBlueMarketIrmError} when a market with positive debt uses an unsupported IRM.
392
398
  * @throws {@link UnknownReallocationMarketError} when the target market is absent.
393
399
  * @deprecated Vault V1 shared-liquidity metrics will be removed in the next major. Use
394
400
  * `VaultV2BlueReallocationData.getAvailableLiquidityToUtilization`.
@@ -446,25 +452,34 @@ class VaultV1ReallocationData {
446
452
  getLargestVaultWithdrawal({ vault, marketId, withdrawals, defaultMaxWithdrawalUtilization, maxWithdrawalUtilization, timestamp, }) {
447
453
  return (0, morpho_ts_1._try)(() => {
448
454
  const { cap, pendingCap, publicAllocatorConfig } = this.getVaultMarketConfig(vault, marketId);
455
+ const maxIn = publicAllocatorConfig?.maxIn ?? 0n;
449
456
  const validCap = pendingCap.validAt >= timestamp
450
457
  ? blue_sdk_1.MathLib.min(pendingCap.value, cap)
451
458
  : cap;
459
+ if (maxIn === 0n || validCap === 0n)
460
+ return { vault };
452
461
  const suppliable = blue_sdk_1.MathLib.zeroFloorSub(validCap, this.getAccrualPosition(vault, marketId).accrueInterest(timestamp)
453
462
  .supplyAssets);
463
+ if (suppliable === 0n)
464
+ return { vault };
454
465
  const marketWithdrawals = this.getVault(vault)
455
466
  .withdrawQueue.filter((srcMarketId) => srcMarketId !== marketId &&
456
467
  !withdrawals.some((withdrawal) => withdrawal.id === srcMarketId && withdrawal.vault === vault))
457
468
  .map((srcMarketId) => {
458
469
  const withdrawal = (0, morpho_ts_1._try)(() => {
459
- const srcPosition = this.getAccrualPosition(vault, srcMarketId).accrueInterest(timestamp);
460
- const targetUtilizationLiquidity = srcPosition.market.getWithdrawToUtilization(maxWithdrawalUtilization[srcMarketId] ??
461
- defaultMaxWithdrawalUtilization);
462
470
  const srcConfig = this.getVaultMarketConfig(vault, srcMarketId);
463
- if (!srcConfig.enabled)
471
+ const maxOut = srcConfig.publicAllocatorConfig?.maxOut ?? 0n;
472
+ if (!srcConfig.enabled || maxOut === 0n)
473
+ return { id: srcMarketId, assets: 0n };
474
+ const rawSrcPosition = this.getAccrualPosition(vault, srcMarketId);
475
+ if (rawSrcPosition.supplyShares === 0n)
464
476
  return { id: srcMarketId, assets: 0n };
477
+ const srcPosition = rawSrcPosition.accrueInterest(timestamp);
478
+ const targetUtilizationLiquidity = srcPosition.market.getWithdrawToUtilization(maxWithdrawalUtilization[srcMarketId] ??
479
+ defaultMaxWithdrawalUtilization);
465
480
  return {
466
481
  id: srcMarketId,
467
- assets: blue_sdk_1.MathLib.min(srcPosition.supplyAssets, targetUtilizationLiquidity, suppliable, publicAllocatorConfig?.maxIn ?? 0n, srcConfig.publicAllocatorConfig?.maxOut ?? 0n),
482
+ assets: blue_sdk_1.MathLib.min(srcPosition.supplyAssets, targetUtilizationLiquidity, suppliable, maxIn, maxOut),
468
483
  };
469
484
  }, blue_sdk_1.UnknownDataError);
470
485
  return withdrawal ?? { id: srcMarketId, assets: 0n };
@@ -30,6 +30,7 @@ export interface VaultV2Actions {
30
30
  * @returns {Object} The result object.
31
31
  * @returns {Readonly<Transaction<VaultV2DepositAction>>} returns.tx The prepared deposit transaction.
32
32
  * @returns {Promise<(Readonly<Transaction<ERC20ApprovalAction>> | Requirement<PermitRequirementSignature>)[]>} returns.getRequirements The function for retrieving all required approval transactions.
33
+ * @throws {UnsupportedBlueMarketIrmError} when an underlying market with positive debt uses an unsupported IRM.
33
34
  */
34
35
  deposit: (params: {
35
36
  userAddress: Address;
@@ -101,6 +102,7 @@ export interface VaultV2Actions {
101
102
  * @param params.deadline - Optional shared permit/bundle deadline; defaults to two hours from now.
102
103
  * @returns Lazy prerequisite resolution and a synchronous transaction builder.
103
104
  * @throws {ChainIdMismatchError} when the client and entity target different chains.
105
+ * @throws {UnsupportedBlueMarketIrmError} when an adapter-listed market with positive debt uses an unsupported IRM.
104
106
  * @throws {VaultAddressMismatchError} when `vaultData` belongs to another vault.
105
107
  * @throws {NonPositiveInputError} when `amount` is not positive.
106
108
  * @throws {InKindRedeemZeroDeallocationError} when the vault has no idle assets and the
@@ -176,7 +176,9 @@ class MorphoVaultV2 {
176
176
  if (assetsToDeallocate > 0n && marketParamsListSnapshot.length === 0) {
177
177
  throw new index_js_3.EmptyMarketParamsListError();
178
178
  }
179
- const assetsByMarket = new Map(soleAdapter.markets.map((market) => [
179
+ const assetsByMarket = new Map(soleAdapter.markets
180
+ .filter((market) => (soleAdapter.supplyShares[market.id] ?? 0n) !== 0n)
181
+ .map((market) => [
180
182
  market.id,
181
183
  market
182
184
  .accrueInterest(now)
@@ -363,7 +363,11 @@ export declare class VaultV2BlueReallocationData implements InputVaultV2BlueReal
363
363
  * utilization defaults to 90% and is configurable through
364
364
  * `options.maxWithdrawalUtilization`. Vaults whose configured penalty exceeds
365
365
  * `options.maxPenalty` are ignored. By default, only zero-penalty vaults are
366
- * considered.
366
+ * considered. Targets with no remaining supply or allocator capacity are skipped before
367
+ * projecting source interest. The adapter's minimum share minting requirement, supply-share
368
+ * limits, and target absolute or zero relative caps are checked against a one-asset deposit.
369
+ * Shared cap IDs that a source withdrawal can reduce remain eligible, as do deposits whose
370
+ * allocation does not increase after rounding.
367
371
  *
368
372
  * Shared-cap discovery is conservative. Operation planning searches at most
369
373
  * 1,024 base units above its targeted amount for the nearest executable fit.
@@ -374,6 +378,7 @@ export declare class VaultV2BlueReallocationData implements InputVaultV2BlueReal
374
378
  * @param marketId - Target Blue market id.
375
379
  * @param options - Optional discovery controls and operation to support.
376
380
  * @returns Flat action-ready reallocations and their post-simulation state.
381
+ * @throws {UnsupportedBlueMarketIrmError} when a market with positive debt uses an unsupported IRM.
377
382
  * @throws {NegativeInputError} when `maxWithdrawalUtilization` or `maxPenalty` is negative.
378
383
  * @throws {InputExceedsMaxError} when `maxWithdrawalUtilization` or `maxPenalty` exceeds WAD.
379
384
  * @throws {NonPositiveInputError} when the operation amount is not positive and planning is enabled.
@@ -430,6 +435,7 @@ export declare class VaultV2BlueReallocationData implements InputVaultV2BlueReal
430
435
  * @param marketId - Target Blue market id.
431
436
  * @param options - Optional timestamp, enable flag, vault allowlist, source utilization ceiling, and maximum penalty.
432
437
  * @returns Reallocatable market and idle assets, or `0n` when none are available; rounding-only shared-cap fits may be conservatively omitted.
438
+ * @throws {UnsupportedBlueMarketIrmError} when a market with positive debt uses an unsupported IRM.
433
439
  * @throws {NegativeInputError} when `maxWithdrawalUtilization` or `maxPenalty` is negative.
434
440
  * @throws {InputExceedsMaxError} when `maxWithdrawalUtilization` or `maxPenalty` exceeds WAD.
435
441
  * @throws {UnknownReallocationMarketError} when a required market is absent.
@@ -470,6 +476,7 @@ export declare class VaultV2BlueReallocationData implements InputVaultV2BlueReal
470
476
  * @param utilization - Desired utilization, scaled by WAD. Defaults to 90%.
471
477
  * @param options - Optional timestamp, enable flag, vault allowlist, source utilization ceiling, and maximum penalty.
472
478
  * @returns Borrowable assets while remaining at or below `utilization`; rounding-only shared-cap fits may be conservatively omitted.
479
+ * @throws {UnsupportedBlueMarketIrmError} when a market with positive debt uses an unsupported IRM.
473
480
  * @throws {NegativeInputError} when `maxWithdrawalUtilization` or `maxPenalty` is negative.
474
481
  * @throws {InputExceedsMaxError} when `maxWithdrawalUtilization` or `maxPenalty` exceeds WAD.
475
482
  * @throws {UnknownReallocationMarketError} when a required market is absent.
@@ -575,7 +575,11 @@ class VaultV2BlueReallocationData {
575
575
  * utilization defaults to 90% and is configurable through
576
576
  * `options.maxWithdrawalUtilization`. Vaults whose configured penalty exceeds
577
577
  * `options.maxPenalty` are ignored. By default, only zero-penalty vaults are
578
- * considered.
578
+ * considered. Targets with no remaining supply or allocator capacity are skipped before
579
+ * projecting source interest. The adapter's minimum share minting requirement, supply-share
580
+ * limits, and target absolute or zero relative caps are checked against a one-asset deposit.
581
+ * Shared cap IDs that a source withdrawal can reduce remain eligible, as do deposits whose
582
+ * allocation does not increase after rounding.
579
583
  *
580
584
  * Shared-cap discovery is conservative. Operation planning searches at most
581
585
  * 1,024 base units above its targeted amount for the nearest executable fit.
@@ -586,6 +590,7 @@ class VaultV2BlueReallocationData {
586
590
  * @param marketId - Target Blue market id.
587
591
  * @param options - Optional discovery controls and operation to support.
588
592
  * @returns Flat action-ready reallocations and their post-simulation state.
593
+ * @throws {UnsupportedBlueMarketIrmError} when a market with positive debt uses an unsupported IRM.
589
594
  * @throws {NegativeInputError} when `maxWithdrawalUtilization` or `maxPenalty` is negative.
590
595
  * @throws {InputExceedsMaxError} when `maxWithdrawalUtilization` or `maxPenalty` exceeds WAD.
591
596
  * @throws {NonPositiveInputError} when the operation amount is not positive and planning is enabled.
@@ -726,9 +731,7 @@ class VaultV2BlueReallocationData {
726
731
  : BigInt(options.timestamp);
727
732
  let data = this;
728
733
  let simulationContext = context;
729
- data.setMarkets(Object.values(data.markets)
730
- .filter((market) => market != null)
731
- .map((market) => market.accrueInterest(timestamp)));
734
+ data.setMarkets([data.getMarket(marketId).accrueInterest(timestamp)]);
732
735
  const reallocations = [];
733
736
  const configuredVaults = Object.keys(data.vaults);
734
737
  const vaultKeyByLower = new Map(configuredVaults.map((vault) => [vault.toLowerCase(), vault]));
@@ -763,6 +766,7 @@ class VaultV2BlueReallocationData {
763
766
  activeAdaptersCache.set(vaultAddress, activeAdapters);
764
767
  }
765
768
  const targetSupplyHeadroom = blue_sdk_1.MathLib.zeroFloorSub(blue_sdk_1.MathLib.MAX_UINT_128, targetMarket.totalSupplyAssets);
769
+ const minimumSupply = targetMarket.supply(1n, 0n);
766
770
  const rawCandidates = [];
767
771
  // Missing nested allocator state means the snapshot is incomplete, so
768
772
  // typed getter errors below must propagate. Only explicit zero caps or
@@ -784,17 +788,35 @@ class VaultV2BlueReallocationData {
784
788
  const adapterCapAllocation = data.getAllocation(vaultAddress, adapterCapId);
785
789
  const collateralCapAllocation = data.getAllocation(vaultAddress, collateralCapId);
786
790
  const adapterMarketCapAllocation = data.getAllocation(vaultAddress, adapterMarketCapId);
787
- if ([
791
+ const targetAllocations = [
788
792
  adapterCapAllocation,
789
793
  collateralCapAllocation,
790
794
  adapterMarketCapAllocation,
791
- ].some(({ absoluteCap }) => absoluteCap === 0n))
795
+ ];
796
+ if (targetAllocations.some(({ absoluteCap }) => absoluteCap === 0n))
792
797
  continue;
793
798
  const expectedSupplyAssets = targetMarket.toSupplyAssets(adapter.supplyShares[marketId] ?? 0n);
794
799
  const untracked = blue_sdk_1.MathLib.zeroFloorSub(expectedSupplyAssets, adapterMarketCapAllocation.allocation);
795
800
  const allocatorHeadroom = marketPublicAllocatorConfig.getMaxIn(adapterMarketCapAllocation.allocation + untracked);
801
+ const minimumAllocation = minimumSupply.market.toSupplyAssets((adapter.supplyShares[marketId] ?? 0n) + minimumSupply.shares);
802
+ const minimumAllocationChange = minimumAllocation - adapterMarketCapAllocation.allocation;
803
+ const blockedTargetIds = targetAllocations
804
+ .filter(({ allocation, absoluteCap, relativeCap }) => {
805
+ const nextAllocation = allocation + minimumAllocationChange;
806
+ return (nextAllocation > absoluteCap ||
807
+ (relativeCap === 0n && nextAllocation > 0n));
808
+ })
809
+ .map(({ id }) => id);
810
+ // MorphoMarketV1AdapterV2 rejects supplies that mint fewer shares than assets.
811
+ if (targetSupplyHeadroom === 0n ||
812
+ allocatorHeadroom === 0n ||
813
+ minimumSupply.shares < minimumSupply.assets ||
814
+ minimumSupply.market.totalSupplyShares > blue_sdk_1.MathLib.MAX_UINT_128 ||
815
+ blockedTargetIds.includes(adapterMarketCapId))
816
+ continue;
796
817
  if (publicAllocatorConfig.canPullFromIdle &&
797
- availableIdleAssets > 0n) {
818
+ availableIdleAssets > 0n &&
819
+ blockedTargetIds.length === 0) {
798
820
  const assets = blue_sdk_1.MathLib.min(blue_sdk_1.MathLib.MAX_UINT_128, targetSupplyHeadroom, allocatorHeadroom, availableIdleAssets);
799
821
  if (assets > 0n) {
800
822
  rawCandidates.push({
@@ -830,8 +852,16 @@ class VaultV2BlueReallocationData {
830
852
  const sourceAllocations = sourceIds.map((id) => data.getAllocation(vaultAddress, id));
831
853
  if (sourceAllocations.some(({ allocation }) => allocation === 0n))
832
854
  continue;
833
- const expectedSourceSupplyAssets = sourceMarket.toSupplyAssets(sourceAdapter.supplyShares[sourceMarket.id] ?? 0n);
834
- const assets = blue_sdk_1.MathLib.min(blue_sdk_1.MathLib.MAX_UINT_128, targetSupplyHeadroom, allocatorHeadroom, expectedSourceSupplyAssets, sourceMarket.getWithdrawToUtilization(maxWithdrawalUtilization));
855
+ const sourceSupplyShares = sourceAdapter.supplyShares[sourceMarket.id] ?? 0n;
856
+ if (sourceSupplyShares === 0n)
857
+ continue;
858
+ // A withdrawal can create target headroom only for shared cap IDs.
859
+ if (blockedTargetIds.some((id) => !sourceIds.includes(id)))
860
+ continue;
861
+ const accruedSourceMarket = sourceMarket.accrueInterest(timestamp);
862
+ data.setMarkets([accruedSourceMarket]);
863
+ const expectedSourceSupplyAssets = accruedSourceMarket.toSupplyAssets(sourceSupplyShares);
864
+ const assets = blue_sdk_1.MathLib.min(blue_sdk_1.MathLib.MAX_UINT_128, targetSupplyHeadroom, allocatorHeadroom, expectedSourceSupplyAssets, accruedSourceMarket.getWithdrawToUtilization(maxWithdrawalUtilization));
835
865
  if (assets <= 0n)
836
866
  continue;
837
867
  rawCandidates.push({
@@ -852,9 +882,6 @@ class VaultV2BlueReallocationData {
852
882
  for (const reallocation of rawCandidates) {
853
883
  let lower = 0n;
854
884
  let upper = reallocation.assets;
855
- // MorphoMarketV1AdapterV2 rejects supplies that mint fewer shares than assets.
856
- if (targetMarket.toSupplyShares(upper, "Down") < upper)
857
- continue;
858
885
  const reallocationAdapter = data.getAdapter(reallocation.vault, reallocation.to.adapter);
859
886
  const targetIds = getAdapterIds(adapterIdsCache, reallocationAdapter, targetMarket);
860
887
  const sourceIds = new Set();
@@ -958,6 +985,7 @@ class VaultV2BlueReallocationData {
958
985
  * @param marketId - Target Blue market id.
959
986
  * @param options - Optional timestamp, enable flag, vault allowlist, source utilization ceiling, and maximum penalty.
960
987
  * @returns Reallocatable market and idle assets, or `0n` when none are available; rounding-only shared-cap fits may be conservatively omitted.
988
+ * @throws {UnsupportedBlueMarketIrmError} when a market with positive debt uses an unsupported IRM.
961
989
  * @throws {NegativeInputError} when `maxWithdrawalUtilization` or `maxPenalty` is negative.
962
990
  * @throws {InputExceedsMaxError} when `maxWithdrawalUtilization` or `maxPenalty` exceeds WAD.
963
991
  * @throws {UnknownReallocationMarketError} when a required market is absent.
@@ -1010,6 +1038,7 @@ class VaultV2BlueReallocationData {
1010
1038
  * @param utilization - Desired utilization, scaled by WAD. Defaults to 90%.
1011
1039
  * @param options - Optional timestamp, enable flag, vault allowlist, source utilization ceiling, and maximum penalty.
1012
1040
  * @returns Borrowable assets while remaining at or below `utilization`; rounding-only shared-cap fits may be conservatively omitted.
1041
+ * @throws {UnsupportedBlueMarketIrmError} when a market with positive debt uses an unsupported IRM.
1013
1042
  * @throws {NegativeInputError} when `maxWithdrawalUtilization` or `maxPenalty` is negative.
1014
1043
  * @throws {InputExceedsMaxError} when `maxWithdrawalUtilization` or `maxPenalty` exceeds WAD.
1015
1044
  * @throws {UnknownReallocationMarketError} when a required market is absent.
@@ -14,7 +14,7 @@ UnknownTokenError, UnknownTokenPriceError as UnknownBlueTokenPriceError,
14
14
  /** @deprecated Use UnknownBlueTokenPriceError or the raw protocol subpath. */
15
15
  UnknownTokenPriceError, UnknownVaultConfigError as UnknownBlueVaultConfigError,
16
16
  /** @deprecated Use UnknownBlueVaultConfigError or the raw protocol subpath. */
17
- UnknownVaultConfigError, UnsupportedChainIdError, UnsupportedPreLiquidationParamsError as UnsupportedBluePreLiquidationParamsError,
17
+ UnknownVaultConfigError, UnsupportedChainIdError, UnsupportedMarketIrmError as UnsupportedBlueMarketIrmError, UnsupportedPreLiquidationParamsError as UnsupportedBluePreLiquidationParamsError,
18
18
  /** @deprecated Use UnsupportedBluePreLiquidationParamsError or the raw protocol subpath. */
19
19
  UnsupportedPreLiquidationParamsError, UnsupportedVaultV2AdapterError as UnsupportedBlueVaultV2AdapterError,
20
20
  /** @deprecated Use UnsupportedBlueVaultV2AdapterError or the raw protocol subpath. */
package/lib/cjs/errors.js CHANGED
@@ -1,7 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.InvalidMidnightTreeHeightError = exports.InvalidTreeError = exports.InvalidMidnightTreeError = exports.InvalidTickSpacingError = exports.InvalidMidnightTickSpacingError = exports.InvalidPositionLossFactorError = exports.InvalidMidnightPositionLossFactorError = exports.InvalidPositionAccrualTimestampError = exports.InvalidMidnightPositionAccrualTimestampError = exports.InvalidPositionAccrualStateError = exports.InvalidMidnightPositionAccrualStateError = exports.InvalidOfferParameterError = exports.InvalidMidnightOfferParameterError = exports.InvalidOfferGroupError = exports.InvalidMidnightOfferGroupError = exports.InvalidMidnightApiResponseError = exports.InvalidMidnightMarketParameterError = exports.InvalidMidnightEcrecoverSignatureVError = exports.MidnightChainIdMismatchError = exports.UnsupportedPermitDomainExtensionsError = exports.isBlueUnknownOfFactoryError = exports.InvalidPermitDomainVerifyingContractError = exports.InvalidPermitDomainChainIdError = exports.getBlueUnsupportedVaultV2Adapter = exports.VaultV2Errors = exports.UnsupportedVaultV2AdapterError = exports.UnsupportedBlueVaultV2AdapterError = exports.UnsupportedPreLiquidationParamsError = exports.UnsupportedBluePreLiquidationParamsError = exports.UnsupportedChainIdError = exports.UnknownVaultConfigError = exports.UnknownBlueVaultConfigError = exports.UnknownTokenPriceError = exports.UnknownBlueTokenPriceError = exports.UnknownTokenError = exports.UnknownBlueTokenError = exports.UnknownOfFactory = exports.UnknownBlueOfFactory = exports.UnknownMarketParamsError = exports.UnknownBlueMarketParamsError = exports.UnknownBlueMarketAllocationError = exports.UnknownFactory = exports.UnknownBlueFactory = exports.UnknownDataError = exports.UnknownBlueDataError = exports.UnknownAddressError = exports.InvalidMarketParamsError = exports.InvalidBlueMarketParamsError = exports.IncompleteChainRegistryError = exports.BlueErrors = void 0;
4
- exports.RegistryValueAlreadyRegisteredError = exports.NegativeValueError = exports.InvalidBitLengthError = exports.DivisionByZeroError = exports._try = exports.UnknownCollateralIndexError = exports.UnknownMidnightCollateralIndexError = exports.TickOutOfRangeError = exports.MidnightTickOutOfRangeError = exports.SettlementFeeExceedsPriceError = exports.MidnightSettlementFeeExceedsPriceError = exports.PriceGreaterThanOneError = exports.MidnightPriceGreaterThanOneError = exports.MidnightPayloadDecodeError = exports.MidnightMempoolValidationError = exports.MidnightApiError = exports.InvalidMidnightTypedDataSignatureError = exports.InvalidTreeHeightError = void 0;
3
+ exports.InvalidTreeError = exports.InvalidMidnightTreeError = exports.InvalidTickSpacingError = exports.InvalidMidnightTickSpacingError = exports.InvalidPositionLossFactorError = exports.InvalidMidnightPositionLossFactorError = exports.InvalidPositionAccrualTimestampError = exports.InvalidMidnightPositionAccrualTimestampError = exports.InvalidPositionAccrualStateError = exports.InvalidMidnightPositionAccrualStateError = exports.InvalidOfferParameterError = exports.InvalidMidnightOfferParameterError = exports.InvalidOfferGroupError = exports.InvalidMidnightOfferGroupError = exports.InvalidMidnightApiResponseError = exports.InvalidMidnightMarketParameterError = exports.InvalidMidnightEcrecoverSignatureVError = exports.MidnightChainIdMismatchError = exports.UnsupportedPermitDomainExtensionsError = exports.isBlueUnknownOfFactoryError = exports.InvalidPermitDomainVerifyingContractError = exports.InvalidPermitDomainChainIdError = exports.getBlueUnsupportedVaultV2Adapter = exports.VaultV2Errors = exports.UnsupportedVaultV2AdapterError = exports.UnsupportedBlueVaultV2AdapterError = exports.UnsupportedPreLiquidationParamsError = exports.UnsupportedBluePreLiquidationParamsError = exports.UnsupportedBlueMarketIrmError = exports.UnsupportedChainIdError = exports.UnknownVaultConfigError = exports.UnknownBlueVaultConfigError = exports.UnknownTokenPriceError = exports.UnknownBlueTokenPriceError = exports.UnknownTokenError = exports.UnknownBlueTokenError = exports.UnknownOfFactory = exports.UnknownBlueOfFactory = exports.UnknownMarketParamsError = exports.UnknownBlueMarketParamsError = exports.UnknownBlueMarketAllocationError = exports.UnknownFactory = exports.UnknownBlueFactory = exports.UnknownDataError = exports.UnknownBlueDataError = exports.UnknownAddressError = exports.InvalidMarketParamsError = exports.InvalidBlueMarketParamsError = exports.IncompleteChainRegistryError = exports.BlueErrors = void 0;
4
+ exports.RegistryValueAlreadyRegisteredError = exports.NegativeValueError = exports.InvalidBitLengthError = exports.DivisionByZeroError = exports._try = exports.UnknownCollateralIndexError = exports.UnknownMidnightCollateralIndexError = exports.TickOutOfRangeError = exports.MidnightTickOutOfRangeError = exports.SettlementFeeExceedsPriceError = exports.MidnightSettlementFeeExceedsPriceError = exports.PriceGreaterThanOneError = exports.MidnightPriceGreaterThanOneError = exports.MidnightPayloadDecodeError = exports.MidnightMempoolValidationError = exports.MidnightApiError = exports.InvalidMidnightTypedDataSignatureError = exports.InvalidTreeHeightError = exports.InvalidMidnightTreeHeightError = void 0;
5
5
  var blue_sdk_1 = require("@morpho-org/blue-sdk");
6
6
  Object.defineProperty(exports, "BlueErrors", { enumerable: true, get: function () { return blue_sdk_1.BlueErrors; } });
7
7
  Object.defineProperty(exports, "IncompleteChainRegistryError", { enumerable: true, get: function () { return blue_sdk_1.IncompleteChainRegistryError; } });
@@ -32,6 +32,7 @@ Object.defineProperty(exports, "UnknownBlueVaultConfigError", { enumerable: true
32
32
  /** @deprecated Use UnknownBlueVaultConfigError or the raw protocol subpath. */
33
33
  Object.defineProperty(exports, "UnknownVaultConfigError", { enumerable: true, get: function () { return blue_sdk_1.UnknownVaultConfigError; } });
34
34
  Object.defineProperty(exports, "UnsupportedChainIdError", { enumerable: true, get: function () { return blue_sdk_1.UnsupportedChainIdError; } });
35
+ Object.defineProperty(exports, "UnsupportedBlueMarketIrmError", { enumerable: true, get: function () { return blue_sdk_1.UnsupportedMarketIrmError; } });
35
36
  Object.defineProperty(exports, "UnsupportedBluePreLiquidationParamsError", { enumerable: true, get: function () { return blue_sdk_1.UnsupportedPreLiquidationParamsError; } });
36
37
  /** @deprecated Use UnsupportedBluePreLiquidationParamsError or the raw protocol subpath. */
37
38
  Object.defineProperty(exports, "UnsupportedPreLiquidationParamsError", { enumerable: true, get: function () { return blue_sdk_1.UnsupportedPreLiquidationParamsError; } });
@@ -12,5 +12,7 @@ fetchPreLiquidationParams, fetchPreLiquidationPosition as fetchBluePreLiquidatio
12
12
  /** @deprecated Use `fetchBluePreLiquidationPosition` or the raw `/blue/fetch` subpath. */
13
13
  fetchPreLiquidationPosition, fetchToken, fetchUser as fetchBlueUser,
14
14
  /** @deprecated Use `fetchBlueUser` or the raw `/blue/fetch` subpath. */
15
- fetchUser, fetchVault, fetchVaultConfig, fetchVaultMarketAllocation, fetchVaultMarketConfig, fetchVaultMarketPublicAllocatorConfig, fetchVaultUser, fetchVaultV2, fetchVaultV2Adapter, fetchVaultV2BlueMarketPublicAllocatorConfig, fetchVaultV2BluePublicAllocatorConfig, fetchVaultV2BluePublicAllocatorData, fetchVaultV2MorphoMarketV1Adapter, fetchVaultV2MorphoMarketV1AdapterV2, fetchVaultV2MorphoVaultV1Adapter, } from "@morpho-org/blue-sdk-viem";
15
+ fetchUser, fetchVault, fetchVaultConfig, fetchVaultMarketAllocation, fetchVaultMarketConfig,
16
+ /** @deprecated Vault V1 PublicAllocator support will be removed in the next major. Use `fetchVaultV2BlueMarketPublicAllocatorConfig`. */
17
+ fetchVaultMarketPublicAllocatorConfig, fetchVaultUser, fetchVaultV2, fetchVaultV2Adapter, fetchVaultV2BlueMarketPublicAllocatorConfig, fetchVaultV2BluePublicAllocatorConfig, fetchVaultV2BluePublicAllocatorData, fetchVaultV2MorphoMarketV1Adapter, fetchVaultV2MorphoMarketV1AdapterV2, fetchVaultV2MorphoVaultV1Adapter, } from "@morpho-org/blue-sdk-viem";
16
18
  export { fetchAccrualPosition as fetchMidnightAccrualPosition, fetchMarket as fetchMidnightMarket, fetchMarketParams as fetchMidnightMarketParams, fetchPosition as fetchMidnightPosition, fetchRatifierInfo as fetchMidnightRatifierInfo, } from "@morpho-org/midnight-sdk";
package/lib/cjs/fetch.js CHANGED
@@ -35,6 +35,7 @@ Object.defineProperty(exports, "fetchVault", { enumerable: true, get: function (
35
35
  Object.defineProperty(exports, "fetchVaultConfig", { enumerable: true, get: function () { return blue_sdk_viem_1.fetchVaultConfig; } });
36
36
  Object.defineProperty(exports, "fetchVaultMarketAllocation", { enumerable: true, get: function () { return blue_sdk_viem_1.fetchVaultMarketAllocation; } });
37
37
  Object.defineProperty(exports, "fetchVaultMarketConfig", { enumerable: true, get: function () { return blue_sdk_viem_1.fetchVaultMarketConfig; } });
38
+ /** @deprecated Vault V1 PublicAllocator support will be removed in the next major. Use `fetchVaultV2BlueMarketPublicAllocatorConfig`. */
38
39
  Object.defineProperty(exports, "fetchVaultMarketPublicAllocatorConfig", { enumerable: true, get: function () { return blue_sdk_viem_1.fetchVaultMarketPublicAllocatorConfig; } });
39
40
  Object.defineProperty(exports, "fetchVaultUser", { enumerable: true, get: function () { return blue_sdk_viem_1.fetchVaultUser; } });
40
41
  Object.defineProperty(exports, "fetchVaultV2", { enumerable: true, get: function () { return blue_sdk_viem_1.fetchVaultV2; } });
@@ -22,6 +22,7 @@ import { type ReallocationComputeOptions, type VaultV1Reallocation } from "../ty
22
22
  * @param params.amount - The borrow or withdraw amount used to compute the post-state utilization.
23
23
  * @param params.options - Optional reallocation computation options.
24
24
  * @returns Array of vault reallocations, sorted with withdrawals in ascending market id order.
25
+ * @throws {UnsupportedBlueMarketIrmError} when a market with positive debt uses an unsupported IRM.
25
26
  * @throws {InsufficientSharedLiquidityError} when shared liquidity cannot cover the operation's absolute shortfall on the target market — preventing fee-bearing reallocations from being attached to a call that would still revert onchain.
26
27
  * @throws {ReallocationWithdrawExceedsMarketSupplyError} when `operation === "withdraw"` and `amount` exceeds the target market's `totalSupplyAssets` — the on-chain call would revert regardless of reallocations.
27
28
  * @throws {MissingPublicAllocatorConfigError} when a selected vault is missing its public allocator config.
@@ -78,6 +79,7 @@ export declare const computeVaultV1Reallocations: ({ reallocationData: data, mar
78
79
  /**
79
80
  * Deprecated name for the Vault V1 amount-aware reallocation planner.
80
81
  *
82
+ * @throws {UnsupportedBlueMarketIrmError} when a market with positive debt uses an unsupported IRM.
81
83
  * @deprecated Vault V1 shared-liquidity planning will be removed in the next major. Use
82
84
  * `VaultV2BlueReallocationData.computeVaultV2BlueReallocations`.
83
85
  */
@@ -78,6 +78,7 @@ const capVaultWithdrawals = (withdrawals, assets) => {
78
78
  * @param params.amount - The borrow or withdraw amount used to compute the post-state utilization.
79
79
  * @param params.options - Optional reallocation computation options.
80
80
  * @returns Array of vault reallocations, sorted with withdrawals in ascending market id order.
81
+ * @throws {UnsupportedBlueMarketIrmError} when a market with positive debt uses an unsupported IRM.
81
82
  * @throws {InsufficientSharedLiquidityError} when shared liquidity cannot cover the operation's absolute shortfall on the target market — preventing fee-bearing reallocations from being attached to a call that would still revert onchain.
82
83
  * @throws {ReallocationWithdrawExceedsMarketSupplyError} when `operation === "withdraw"` and `amount` exceeds the target market's `totalSupplyAssets` — the on-chain call would revert regardless of reallocations.
83
84
  * @throws {MissingPublicAllocatorConfigError} when a selected vault is missing its public allocator config.
@@ -243,6 +244,7 @@ exports.computeVaultV1Reallocations = computeVaultV1Reallocations;
243
244
  /**
244
245
  * Deprecated name for the Vault V1 amount-aware reallocation planner.
245
246
  *
247
+ * @throws {UnsupportedBlueMarketIrmError} when a market with positive debt uses an unsupported IRM.
246
248
  * @deprecated Vault V1 shared-liquidity planning will be removed in the next major. Use
247
249
  * `VaultV2BlueReallocationData.computeVaultV2BlueReallocations`.
248
250
  */
@@ -35,6 +35,7 @@ export interface VaultV2InKindRedeemMarketPreview {
35
35
  * @param params.requestedExitAssets - Positive penalty-inclusive amount the user wants to exit.
36
36
  * @param params.timestamp - Timestamp used to accrue Morpho Blue markets before calculating capacity.
37
37
  * @returns Frontend-ready market choices, or an empty list when no choices are available.
38
+ * @throws {UnsupportedBlueMarketIrmError} when an adapter-listed market with positive debt uses an unsupported IRM.
38
39
  * @example
39
40
  * ```ts
40
41
  * import { previewVaultV2InKindRedeem } from "@morpho-org/morpho-sdk";
@@ -14,6 +14,7 @@ const blue_sdk_1 = require("@morpho-org/blue-sdk");
14
14
  * @param params.requestedExitAssets - Positive penalty-inclusive amount the user wants to exit.
15
15
  * @param params.timestamp - Timestamp used to accrue Morpho Blue markets before calculating capacity.
16
16
  * @returns Frontend-ready market choices, or an empty list when no choices are available.
17
+ * @throws {UnsupportedBlueMarketIrmError} when an adapter-listed market with positive debt uses an unsupported IRM.
17
18
  * @example
18
19
  * ```ts
19
20
  * import { previewVaultV2InKindRedeem } from "@morpho-org/morpho-sdk";
@@ -40,6 +41,7 @@ function previewVaultV2InKindRedeem(vaultData, params) {
40
41
  const penalty = vaultData.forceDeallocatePenalties[adapter.address] ?? 0n;
41
42
  const availableIdleAssets = vaultData.assetBalance;
42
43
  const allocations = adapter.markets
44
+ .filter((market) => (adapter.supplyShares[market.id] ?? 0n) !== 0n)
43
45
  .map((market) => ({
44
46
  market,
45
47
  allocationAssets: market
@@ -23,22 +23,44 @@ export declare const validateMidnightMarketChainId: (market: MidnightMarketInput
23
23
  * Asserts that the client has a connected account AND that it matches
24
24
  * the provided user address.
25
25
  *
26
- * Used internally by the signature requirements (`encodeErc20Permit`,
27
- * `encodeErc20Permit2Approve`) to enforce builder = signer at `sign()` time:
28
- * the signing flow is the only path where an account/address mismatch
29
- * is a real security concern (rather than just an integrator footgun).
26
+ * Used at `sign()` time by the shared `signAndVerifyTypedData` helper (which
27
+ * backs the permit, Permit2, Blue authorization, and Midnight offer-root
28
+ * signature flows) and by `encodeVaultSharesPermit`, to enforce builder =
29
+ * signer: the signing flow is
30
+ * the only path where an account/address mismatch is a real security concern
31
+ * (rather than just an integrator footgun).
30
32
  *
31
33
  * Transaction builders no longer call this helper — callers are
32
34
  * responsible for keeping `userAddress` aligned with the signing account
33
35
  * at the builder layer.
34
36
  *
35
- * Throws {@link MissingClientPropertyError} if the client has no account.
36
- * Throws {@link AddressMismatchError} if the client account differs from
37
- * `userAddress`.
38
- *
39
37
  * @param clientAccountAddress - The client's account address; if undefined,
40
38
  * `MissingClientPropertyError` is thrown.
41
39
  * @param userAddress - The user address provided by the caller.
40
+ * @returns Nothing; narrows `clientAccountAddress` to a defined `Address` when
41
+ * it is present and equal to `userAddress`.
42
+ * @throws {MissingClientPropertyError} when the client has no connected account.
43
+ * @throws {AddressMismatchError} when the client account differs from
44
+ * `userAddress`.
45
+ * @example
46
+ * ```ts
47
+ * import { createWalletClient, http } from "viem";
48
+ * import { privateKeyToAccount } from "viem/accounts";
49
+ * import { mainnet } from "viem/chains";
50
+ * import { validateUserAddress } from "@morpho-org/morpho-sdk";
51
+ *
52
+ * const account = privateKeyToAccount("0x...");
53
+ * const walletClient = createWalletClient({
54
+ * account,
55
+ * chain: mainnet,
56
+ * transport: http(),
57
+ * });
58
+ *
59
+ * // Inside a `sign()` flow, before producing a typed-data signature:
60
+ * validateUserAddress(walletClient.account?.address, account.address);
61
+ * // Passes when the connected account equals the expected signer;
62
+ * // throws if the wallet has no account or signs for a different address.
63
+ * ```
42
64
  */
43
65
  export declare function validateUserAddress(clientAccountAddress: Address | undefined, userAddress: Address): asserts clientAccountAddress is Address;
44
66
  /**
@@ -41,22 +41,44 @@ exports.validateMidnightMarketChainId = validateMidnightMarketChainId;
41
41
  * Asserts that the client has a connected account AND that it matches
42
42
  * the provided user address.
43
43
  *
44
- * Used internally by the signature requirements (`encodeErc20Permit`,
45
- * `encodeErc20Permit2Approve`) to enforce builder = signer at `sign()` time:
46
- * the signing flow is the only path where an account/address mismatch
47
- * is a real security concern (rather than just an integrator footgun).
44
+ * Used at `sign()` time by the shared `signAndVerifyTypedData` helper (which
45
+ * backs the permit, Permit2, Blue authorization, and Midnight offer-root
46
+ * signature flows) and by `encodeVaultSharesPermit`, to enforce builder =
47
+ * signer: the signing flow is
48
+ * the only path where an account/address mismatch is a real security concern
49
+ * (rather than just an integrator footgun).
48
50
  *
49
51
  * Transaction builders no longer call this helper — callers are
50
52
  * responsible for keeping `userAddress` aligned with the signing account
51
53
  * at the builder layer.
52
54
  *
53
- * Throws {@link MissingClientPropertyError} if the client has no account.
54
- * Throws {@link AddressMismatchError} if the client account differs from
55
- * `userAddress`.
56
- *
57
55
  * @param clientAccountAddress - The client's account address; if undefined,
58
56
  * `MissingClientPropertyError` is thrown.
59
57
  * @param userAddress - The user address provided by the caller.
58
+ * @returns Nothing; narrows `clientAccountAddress` to a defined `Address` when
59
+ * it is present and equal to `userAddress`.
60
+ * @throws {MissingClientPropertyError} when the client has no connected account.
61
+ * @throws {AddressMismatchError} when the client account differs from
62
+ * `userAddress`.
63
+ * @example
64
+ * ```ts
65
+ * import { createWalletClient, http } from "viem";
66
+ * import { privateKeyToAccount } from "viem/accounts";
67
+ * import { mainnet } from "viem/chains";
68
+ * import { validateUserAddress } from "@morpho-org/morpho-sdk";
69
+ *
70
+ * const account = privateKeyToAccount("0x...");
71
+ * const walletClient = createWalletClient({
72
+ * account,
73
+ * chain: mainnet,
74
+ * transport: http(),
75
+ * });
76
+ *
77
+ * // Inside a `sign()` flow, before producing a typed-data signature:
78
+ * validateUserAddress(walletClient.account?.address, account.address);
79
+ * // Passes when the connected account equals the expected signer;
80
+ * // throws if the wallet has no account or signs for a different address.
81
+ * ```
60
82
  */
61
83
  function validateUserAddress(clientAccountAddress, userAddress) {
62
84
  if (clientAccountAddress === undefined) {
@@ -1,6 +1,17 @@
1
1
  import type { InputMarketParams } from "@morpho-org/blue-sdk";
2
2
  import type { Address, Hex, WalletClient } from "viem";
3
3
  import type { Deallocation } from "./deallocation.js";
4
+ /**
5
+ * Serves as the common discriminated action-metadata base shared by both
6
+ * {@link TransactionAction} (actions that carry encoded calldata) and
7
+ * {@link SignatureRequirementAction} (signature requirements whose metadata is
8
+ * exposed before any calldata exists). Each concrete action narrows
9
+ * {@link BaseAction} on its literal `type` tag and carries an
10
+ * operation-specific `args` record surfaced for tracing.
11
+ *
12
+ * @typeParam TType - Literal discriminator identifying the action.
13
+ * @typeParam TArgs - The action's argument record.
14
+ */
4
15
  export interface BaseAction<TType extends string = string, TArgs extends Record<string, unknown> = Record<string, unknown>> {
5
16
  readonly type: TType;
6
17
  readonly args: TArgs;
@@ -115,7 +126,11 @@ export interface BlueWithdrawAction extends BaseAction<"blueWithdraw", {
115
126
  shares: bigint;
116
127
  receiver: Address;
117
128
  minSharePrice: bigint;
118
- /** Native-token fees paid to PublicAllocator V1. */
129
+ /**
130
+ * Native-token fees paid to PublicAllocator V1.
131
+ * @deprecated Vault V1 PublicAllocator support will be removed in the next major.
132
+ * Vault V2 loan-token penalties are reported in `reallocationPenaltyAssets`.
133
+ */
119
134
  reallocationFee: bigint;
120
135
  /** Loan-token assets donated as BluePublicAllocator V2 penalties. */
121
136
  readonly reallocationPenaltyAssets: bigint;
@@ -133,7 +148,11 @@ export interface BlueBorrowAction extends BaseAction<"blueBorrow", {
133
148
  amount: bigint;
134
149
  receiver: Address;
135
150
  minSharePrice: bigint;
136
- /** Native-token fees paid to PublicAllocator V1. */
151
+ /**
152
+ * Native-token fees paid to PublicAllocator V1.
153
+ * @deprecated Vault V1 PublicAllocator support will be removed in the next major.
154
+ * Vault V2 loan-token penalties are reported in `reallocationPenaltyAssets`.
155
+ */
137
156
  reallocationFee: bigint;
138
157
  /** Loan-token assets donated as BluePublicAllocator V2 penalties. */
139
158
  readonly reallocationPenaltyAssets: bigint;
@@ -147,7 +166,11 @@ export interface BlueSupplyCollateralBorrowAction extends BaseAction<"blueSupply
147
166
  onBehalf: Address;
148
167
  receiver: Address;
149
168
  nativeAmount?: bigint;
150
- /** Native-token fees paid to PublicAllocator V1. */
169
+ /**
170
+ * Native-token fees paid to PublicAllocator V1.
171
+ * @deprecated Vault V1 PublicAllocator support will be removed in the next major.
172
+ * Vault V2 loan-token penalties are reported in `reallocationPenaltyAssets`.
173
+ */
151
174
  reallocationFee: bigint;
152
175
  /** Loan-token assets donated as BluePublicAllocator V2 penalties. */
153
176
  readonly reallocationPenaltyAssets: bigint;
@@ -194,7 +217,11 @@ export interface BlueRefinanceAction extends BaseAction<"blueRefinance", {
194
217
  readonly minBorrowSharePrice: bigint;
195
218
  readonly maxRepaySharePrice: bigint;
196
219
  readonly user: Address;
197
- /** Native-token fees paid to PublicAllocator V1. */
220
+ /**
221
+ * Native-token fees paid to PublicAllocator V1.
222
+ * @deprecated Vault V1 PublicAllocator support will be removed in the next major.
223
+ * Vault V2 loan-token penalties are reported in `reallocationPenaltyAssets`.
224
+ */
198
225
  readonly reallocationFee: bigint;
199
226
  /** Loan-token assets donated as BluePublicAllocator V2 penalties. */
200
227
  readonly reallocationPenaltyAssets: bigint;
@@ -358,7 +385,19 @@ export interface MidnightCancelOfferAction extends BaseAction<"midnightCancelOff
358
385
  readonly onBehalf: Address;
359
386
  }> {
360
387
  }
388
+ /**
389
+ * Enumerates every action a {@link Transaction} can describe across the VaultV1,
390
+ * VaultV2, Blue, and Midnight flows. The `type` tag discriminates the union so
391
+ * consumers can `switch` exhaustively on it.
392
+ */
361
393
  export type TransactionAction = ERC20ApprovalAction | VaultV2DepositAction | VaultV2WithdrawAction | VaultV2RedeemAction | VaultV2InKindRedeemAction | VaultV2ForceWithdrawAction | VaultV2ForceRedeemAction | VaultV1DepositAction | VaultV1WithdrawAction | VaultV1RedeemAction | VaultV1InKindRedeemAction | VaultV1MigrateToV2Action | BlueSupplyAction | BlueWithdrawAction | BlueSupplyCollateralAction | BlueBorrowAction | BlueSupplyCollateralBorrowAction | BlueRepayAction | BlueWithdrawCollateralAction | BlueRepayWithdrawCollateralAction | BlueRefinanceAction | BlueAuthorizationAction | MidnightAuthorizationAction | SetterRatifierRatifyRootAction | MidnightTakeLendAction | MidnightTakeBorrowAction | MidnightSupplyCollateralTakeBorrowAction | MidnightSupplyCollateralAction | MempoolSubmitOffersAction | MidnightRedeemAction | MidnightRepayWithdrawCollateralAction | MidnightCancelOfferAction;
394
+ /**
395
+ * Describes a single, immutable, deep-frozen transaction to submit on-chain:
396
+ * the target `to`, native `value`, encoded call `data`, and the originating
397
+ * {@link BaseAction} for tracing. Every action builder returns one.
398
+ *
399
+ * @typeParam TAction - The action that produced this transaction.
400
+ */
362
401
  export interface Transaction<TAction extends BaseAction = TransactionAction> {
363
402
  readonly to: Address;
364
403
  readonly value: bigint;
@@ -379,6 +418,14 @@ export type DepositAmountArgs = {
379
418
  nativeAmount: bigint;
380
419
  amount?: bigint;
381
420
  };
421
+ /**
422
+ * Holds the pre-resolved arguments for an ERC-2612 `permit`: the signed approval
423
+ * of `amount` of `asset` from `owner` to the permitted spender, bounded by the
424
+ * `deadline` timestamp and consuming the given `nonce`. The spender is the
425
+ * GeneralAdapter1/Bundler3 periphery for bundler permits, or the standalone
426
+ * `VaultExitBundlesV1` contract for an in-kind vault redemption permit produced
427
+ * by `encodeVaultSharesPermit`.
428
+ */
382
429
  export interface PermitArgs {
383
430
  owner: Address;
384
431
  nonce: bigint;
@@ -387,6 +434,12 @@ export interface PermitArgs {
387
434
  amount: bigint;
388
435
  deadline: bigint;
389
436
  }
437
+ /**
438
+ * Holds the pre-resolved arguments for a Permit2 `permit` bundler call. It
439
+ * mirrors {@link PermitArgs} but adds the Permit2 allowance `expiration` (when
440
+ * the on-chain allowance lapses) alongside the signature `deadline` (by when the
441
+ * signature must be submitted).
442
+ */
390
443
  export interface Permit2Args {
391
444
  owner: Address;
392
445
  nonce: bigint;
@@ -971,7 +971,7 @@ export declare class MidnightOfferRootOfferCountMismatchError extends Error {
971
971
  actualOffers: number;
972
972
  });
973
973
  }
974
- /** Thrown when a Midnight offer-root signature was not prepared by this maker flow. */
974
+ /** Thrown when a Midnight offer-root signature carries no encoded payload. */
975
975
  export declare class UnpreparedMidnightOfferRootSignatureError extends Error {
976
976
  constructor();
977
977
  }