@morpho-org/morpho-sdk 3.0.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.
Files changed (60) hide show
  1. package/README.md +69 -3
  2. package/lib/cjs/actions/marketV1/index.d.ts +2 -0
  3. package/lib/cjs/actions/marketV1/index.js +2 -0
  4. package/lib/cjs/actions/marketV1/supply.d.ts +69 -0
  5. package/lib/cjs/actions/marketV1/supply.js +128 -0
  6. package/lib/cjs/actions/marketV1/supplyCollateral.d.ts +1 -1
  7. package/lib/cjs/actions/marketV1/supplyCollateral.js +2 -2
  8. package/lib/cjs/actions/marketV1/supplyCollateralBorrow.d.ts +1 -1
  9. package/lib/cjs/actions/marketV1/supplyCollateralBorrow.js +2 -2
  10. package/lib/cjs/actions/marketV1/withdraw.d.ts +83 -0
  11. package/lib/cjs/actions/marketV1/withdraw.js +110 -0
  12. package/lib/cjs/bundler/actions.d.ts +86 -4
  13. package/lib/cjs/bundler/actions.js +143 -8
  14. package/lib/cjs/bundler/types.d.ts +23 -4
  15. package/lib/cjs/entities/marketV1/marketV1.d.ts +121 -18
  16. package/lib/cjs/entities/marketV1/marketV1.js +144 -12
  17. package/lib/cjs/entities/reallocationData.js +3 -0
  18. package/lib/cjs/helpers/computeReallocations.d.ts +17 -6
  19. package/lib/cjs/helpers/computeReallocations.js +44 -11
  20. package/lib/cjs/helpers/index.d.ts +2 -2
  21. package/lib/cjs/helpers/index.js +6 -2
  22. package/lib/cjs/helpers/slippage.d.ts +57 -0
  23. package/lib/cjs/helpers/slippage.js +82 -0
  24. package/lib/cjs/helpers/validate.d.ts +38 -7
  25. package/lib/cjs/helpers/validate.js +54 -11
  26. package/lib/cjs/types/action.d.ts +27 -6
  27. package/lib/cjs/types/error.d.ts +68 -6
  28. package/lib/cjs/types/error.js +85 -12
  29. package/lib/cjs/utils.d.ts +1 -1
  30. package/lib/cjs/utils.js +2 -2
  31. package/lib/esm/actions/marketV1/index.d.ts +2 -0
  32. package/lib/esm/actions/marketV1/index.js +2 -0
  33. package/lib/esm/actions/marketV1/supply.d.ts +69 -0
  34. package/lib/esm/actions/marketV1/supply.js +124 -0
  35. package/lib/esm/actions/marketV1/supplyCollateral.d.ts +1 -1
  36. package/lib/esm/actions/marketV1/supplyCollateral.js +3 -3
  37. package/lib/esm/actions/marketV1/supplyCollateralBorrow.d.ts +1 -1
  38. package/lib/esm/actions/marketV1/supplyCollateralBorrow.js +3 -3
  39. package/lib/esm/actions/marketV1/withdraw.d.ts +83 -0
  40. package/lib/esm/actions/marketV1/withdraw.js +106 -0
  41. package/lib/esm/bundler/actions.d.ts +86 -4
  42. package/lib/esm/bundler/actions.js +143 -8
  43. package/lib/esm/bundler/types.d.ts +23 -4
  44. package/lib/esm/entities/marketV1/marketV1.d.ts +121 -18
  45. package/lib/esm/entities/marketV1/marketV1.js +147 -15
  46. package/lib/esm/entities/reallocationData.js +3 -0
  47. package/lib/esm/helpers/computeReallocations.d.ts +17 -6
  48. package/lib/esm/helpers/computeReallocations.js +45 -12
  49. package/lib/esm/helpers/index.d.ts +2 -2
  50. package/lib/esm/helpers/index.js +2 -2
  51. package/lib/esm/helpers/slippage.d.ts +57 -0
  52. package/lib/esm/helpers/slippage.js +80 -0
  53. package/lib/esm/helpers/validate.d.ts +38 -7
  54. package/lib/esm/helpers/validate.js +51 -10
  55. package/lib/esm/types/action.d.ts +27 -6
  56. package/lib/esm/types/error.d.ts +68 -6
  57. package/lib/esm/types/error.js +73 -9
  58. package/lib/esm/utils.d.ts +1 -1
  59. package/lib/esm/utils.js +1 -1
  60. package/package.json +14 -10
@@ -162,12 +162,19 @@ export var BundlerAction;
162
162
  const [market, amount, onBehalf, onMorphoSupplyCollateral, skipRevert] = args;
163
163
  return BundlerAction.morphoSupplyCollateral(chainId, market, amount, onBehalf, onMorphoSupplyCollateral.flatMap(BundlerAction.encode.bind(null, chainId)), skipRevert);
164
164
  }
165
+ case "morphoSupply": {
166
+ const [market, assets, shares, slippageAmount, onBehalf, onMorphoSupply, skipRevert,] = args;
167
+ return BundlerAction.morphoSupply(chainId, market, assets, shares, slippageAmount, onBehalf, onMorphoSupply.flatMap(BundlerAction.encode.bind(null, chainId)), skipRevert);
168
+ }
165
169
  case "morphoBorrow": {
166
170
  return BundlerAction.morphoBorrow(chainId, ...args);
167
171
  }
172
+ case "morphoWithdraw": {
173
+ return BundlerAction.morphoWithdraw(chainId, ...args);
174
+ }
168
175
  case "morphoRepay": {
169
- const [market, assets, shares, slippageAmount, onBehalf, onMorphoRepay, skipRevert,] = args;
170
- 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);
171
178
  }
172
179
  case "morphoWithdrawCollateral": {
173
180
  return BundlerAction.morphoWithdrawCollateral(chainId, ...args);
@@ -209,6 +216,17 @@ export var BundlerAction;
209
216
  nextValueState = encodedCallback.valueState;
210
217
  }
211
218
  }
219
+ if (action.type === "morphoSupply") {
220
+ const [, , , , , onMorphoSupply] = action.args;
221
+ for (const callbackAction of onMorphoSupply) {
222
+ const encodedCallback = encodeBundleAction({
223
+ chainId,
224
+ action: callbackAction,
225
+ valueState: nextValueState,
226
+ });
227
+ nextValueState = encodedCallback.valueState;
228
+ }
229
+ }
212
230
  if (action.type === "morphoRepay") {
213
231
  const [, , , , , onMorphoRepay] = action.args;
214
232
  for (const callbackAction of onMorphoRepay) {
@@ -678,6 +696,66 @@ export var BundlerAction;
678
696
  ];
679
697
  }
680
698
  BundlerAction.morphoSupplyCollateral = morphoSupplyCollateral;
699
+ /**
700
+ * Encodes a GeneralAdapter1 Morpho Blue supply call.
701
+ *
702
+ * @param chainId - Chain where the action will execute.
703
+ * @param market - Morpho Blue market parameters.
704
+ * @param assets - Supply asset amount.
705
+ * @param shares - Supply share amount.
706
+ * @param slippageAmount - Slippage guard amount (max share price in RAY for share-price slippage).
707
+ * @param onBehalf - Account receiving the supply position.
708
+ * @param callbackCalls - Calls executed in Morpho's callback.
709
+ * @param skipRevert - Whether Bundler3 should tolerate a revert.
710
+ * @returns Encoded Bundler3 calls.
711
+ *
712
+ * @example
713
+ * ```ts
714
+ * import { BundlerAction } from "@morpho-org/morpho-sdk/bundler";
715
+ *
716
+ * const loanToken = "0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48";
717
+ * const collateralToken = "0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2";
718
+ * const oracle = "0x5f4eC3Df9cbd43714FE2740f5E3616155c5b8419";
719
+ * const irm = "0x870aC11D48B15DB9a138Cf899d20F13F79Ba00BC";
720
+ * const onBehalf = "0xd8dA6BF26964aF9D7eEd9e03E53415D37aA96045";
721
+ * const marketParams = {
722
+ * loanToken,
723
+ * collateralToken,
724
+ * oracle,
725
+ * irm,
726
+ * lltv: 860_000000000000000000n,
727
+ * };
728
+ *
729
+ * const calls = BundlerAction.morphoSupply(
730
+ * 1,
731
+ * marketParams,
732
+ * 100n,
733
+ * 0n,
734
+ * 1_010000000000000000000000000n,
735
+ * onBehalf,
736
+ * [],
737
+ * );
738
+ * ```
739
+ */
740
+ // biome-ignore lint/complexity/useMaxParams: TODO refactor to ≤2 params
741
+ function morphoSupply(chainId, market, assets, shares, slippageAmount, onBehalf, callbackCalls, skipRevert = false) {
742
+ const { bundler3: { generalAdapter1 }, } = getChainAddresses(chainId);
743
+ const { callbackHash, reenterData } = encodeCallbackCalls(callbackCalls);
744
+ return [
745
+ {
746
+ to: generalAdapter1,
747
+ data: encodeFunctionData({
748
+ abi: generalAdapter1Abi,
749
+ functionName: "morphoSupply",
750
+ args: [market, assets, shares, slippageAmount, onBehalf, reenterData],
751
+ }),
752
+ value: 0n,
753
+ skipRevert,
754
+ callbackHash,
755
+ },
756
+ ];
757
+ }
758
+ BundlerAction.morphoSupply = morphoSupply;
681
759
  /**
682
760
  * Encodes a GeneralAdapter1 Morpho Blue borrow call.
683
761
  *
@@ -685,7 +763,7 @@ export var BundlerAction;
685
763
  * @param market - Morpho Blue market parameters.
686
764
  * @param assets - Borrow asset amount.
687
765
  * @param shares - Borrow share amount.
688
- * @param slippageAmount - Slippage guard amount.
766
+ * @param minSharePrice - Minimum amount of borrowed assets per borrow share minted, scaled by 1e27.
689
767
  * @param receiver - Recipient of borrowed assets.
690
768
  * @param skipRevert - Whether Bundler3 should tolerate a revert.
691
769
  * @returns Encoded Bundler3 calls.
@@ -718,7 +796,7 @@ export var BundlerAction;
718
796
  * ```
719
797
  */
720
798
  // biome-ignore lint/complexity/useMaxParams: TODO refactor to ≤2 params
721
- function morphoBorrow(chainId, market, assets, shares, slippageAmount, receiver, skipRevert = false) {
799
+ function morphoBorrow(chainId, market, assets, shares, minSharePrice, receiver, skipRevert = false) {
722
800
  const { bundler3: { generalAdapter1 }, } = getChainAddresses(chainId);
723
801
  return [
724
802
  {
@@ -726,7 +804,7 @@ export var BundlerAction;
726
804
  data: encodeFunctionData({
727
805
  abi: generalAdapter1Abi,
728
806
  functionName: "morphoBorrow",
729
- args: [market, assets, shares, slippageAmount, receiver],
807
+ args: [market, assets, shares, minSharePrice, receiver],
730
808
  }),
731
809
  value: 0n,
732
810
  skipRevert,
@@ -742,7 +820,7 @@ export var BundlerAction;
742
820
  * @param market - Morpho Blue market parameters.
743
821
  * @param assets - Repay asset amount.
744
822
  * @param shares - Repay share amount.
745
- * @param slippageAmount - Slippage guard amount.
823
+ * @param maxSharePrice - Maximum amount of repaid assets per borrow share redeemed, scaled by 1e27.
746
824
  * @param onBehalf - Account whose borrow is repaid.
747
825
  * @param callbackCalls - Calls executed in Morpho's callback.
748
826
  * @param skipRevert - Whether Bundler3 should tolerate a revert.
@@ -777,7 +855,7 @@ export var BundlerAction;
777
855
  * ```
778
856
  */
779
857
  // biome-ignore lint/complexity/useMaxParams: TODO refactor to ≤2 params
780
- function morphoRepay(chainId, market, assets, shares, slippageAmount, onBehalf, callbackCalls, skipRevert = false) {
858
+ function morphoRepay(chainId, market, assets, shares, maxSharePrice, onBehalf, callbackCalls, skipRevert = false) {
781
859
  const { bundler3: { generalAdapter1 }, } = getChainAddresses(chainId);
782
860
  const { callbackHash, reenterData } = encodeCallbackCalls(callbackCalls);
783
861
  return [
@@ -786,7 +864,7 @@ export var BundlerAction;
786
864
  data: encodeFunctionData({
787
865
  abi: generalAdapter1Abi,
788
866
  functionName: "morphoRepay",
789
- args: [market, assets, shares, slippageAmount, onBehalf, reenterData],
867
+ args: [market, assets, shares, maxSharePrice, onBehalf, reenterData],
790
868
  }),
791
869
  value: 0n,
792
870
  skipRevert,
@@ -795,6 +873,63 @@ export var BundlerAction;
795
873
  ];
796
874
  }
797
875
  BundlerAction.morphoRepay = morphoRepay;
876
+ /**
877
+ * Encodes a GeneralAdapter1 Morpho Blue withdraw call.
878
+ *
879
+ * @param chainId - Chain where the action will execute.
880
+ * @param market - Morpho Blue market parameters.
881
+ * @param assets - Withdraw asset amount.
882
+ * @param shares - Withdraw share amount.
883
+ * @param slippageAmount - Slippage guard amount (min share price in RAY for share-price slippage).
884
+ * @param receiver - Recipient of withdrawn assets.
885
+ * @param skipRevert - Whether Bundler3 should tolerate a revert.
886
+ * @returns Encoded Bundler3 calls.
887
+ *
888
+ * @example
889
+ * ```ts
890
+ * import { BundlerAction } from "@morpho-org/morpho-sdk/bundler";
891
+ *
892
+ * const loanToken = "0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48";
893
+ * const collateralToken = "0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2";
894
+ * const oracle = "0x5f4eC3Df9cbd43714FE2740f5E3616155c5b8419";
895
+ * const irm = "0x870aC11D48B15DB9a138Cf899d20F13F79Ba00BC";
896
+ * const receiver = "0xd8dA6BF26964aF9D7eEd9e03E53415D37aA96045";
897
+ * const marketParams = {
898
+ * loanToken,
899
+ * collateralToken,
900
+ * oracle,
901
+ * irm,
902
+ * lltv: 860_000000000000000000n,
903
+ * };
904
+ *
905
+ * const calls = BundlerAction.morphoWithdraw(
906
+ * 1,
907
+ * marketParams,
908
+ * 100n,
909
+ * 0n,
910
+ * 990000000000000000000000000n,
911
+ * receiver,
912
+ * );
913
+ * ```
914
+ */
915
+ // biome-ignore lint/complexity/useMaxParams: TODO refactor to ≤2 params
916
+ function morphoWithdraw(chainId, market, assets, shares, slippageAmount, receiver, skipRevert = false) {
917
+ const { bundler3: { generalAdapter1 }, } = getChainAddresses(chainId);
918
+ return [
919
+ {
920
+ to: generalAdapter1,
921
+ data: encodeFunctionData({
922
+ abi: generalAdapter1Abi,
923
+ functionName: "morphoWithdraw",
924
+ args: [market, assets, shares, slippageAmount, receiver],
925
+ }),
926
+ value: 0n,
927
+ skipRevert,
928
+ callbackHash: zeroHash,
929
+ },
930
+ ];
931
+ }
932
+ BundlerAction.morphoWithdraw = morphoWithdraw;
798
933
  /**
799
934
  * Encodes a GeneralAdapter1 Morpho Blue withdraw-collateral call.
800
935
  *
@@ -121,25 +121,44 @@ export interface ActionArgs {
121
121
  onMorphoSupplyCollateral: Action[],
122
122
  skipRevert?: boolean
123
123
  ];
124
- /** Morpho Blue borrow call for `market`, `assets` or `shares`, `slippageAmount`, and `receiver`; `skipRevert` controls Bundler3 revert handling. */
125
- readonly morphoBorrow: [
124
+ /** Morpho Blue supply call for `market`, `assets` or `shares`, `slippageAmount`, `onBehalf`, and callback actions; `skipRevert` controls Bundler3 revert handling. */
125
+ readonly morphoSupply: [
126
126
  market: InputMarketParams,
127
127
  assets: bigint,
128
128
  shares: bigint,
129
129
  slippageAmount: bigint,
130
+ onBehalf: Address,
131
+ onMorphoSupply: Action[],
132
+ skipRevert?: boolean
133
+ ];
134
+ /** Morpho Blue borrow call for `market`, `assets` or `shares`, `minSharePrice`, and `receiver`; `skipRevert` controls Bundler3 revert handling. */
135
+ readonly morphoBorrow: [
136
+ market: InputMarketParams,
137
+ assets: bigint,
138
+ shares: bigint,
139
+ minSharePrice: bigint,
130
140
  receiver: Address,
131
141
  skipRevert?: boolean
132
142
  ];
133
- /** 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. */
134
144
  readonly morphoRepay: [
135
145
  market: InputMarketParams,
136
146
  assets: bigint,
137
147
  shares: bigint,
138
- slippageAmount: bigint,
148
+ maxSharePrice: bigint,
139
149
  onBehalf: Address,
140
150
  onMorphoRepay: Action[],
141
151
  skipRevert?: boolean
142
152
  ];
153
+ /** Morpho Blue withdraw call for `market`, `assets` or `shares`, `slippageAmount`, and `receiver`; `skipRevert` controls Bundler3 revert handling. */
154
+ readonly morphoWithdraw: [
155
+ market: InputMarketParams,
156
+ assets: bigint,
157
+ shares: bigint,
158
+ slippageAmount: bigint,
159
+ receiver: Address,
160
+ skipRevert?: boolean
161
+ ];
143
162
  /** Morpho Blue withdraw-collateral call for `market`, `assets`, and `receiver`; `skipRevert` controls Bundler3 revert handling. */
144
163
  readonly morphoWithdrawCollateral: [
145
164
  market: InputMarketParams,
@@ -1,7 +1,7 @@
1
1
  import { type AccrualPosition, type Market, type MarketParams } from "@morpho-org/blue-sdk";
2
2
  import type { Address } from "viem";
3
3
  import type { FetchParameters } from "../../types/data.js";
4
- import { type DepositAmountArgs, type ERC20ApprovalAction, type MarketV1BorrowAction, type MarketV1RepayAction, type MarketV1RepayWithdrawCollateralAction, type MarketV1SupplyCollateralAction, type MarketV1SupplyCollateralBorrowAction, type MarketV1WithdrawCollateralAction, type MorphoAuthorizationAction, type MorphoClientType, type ReallocationComputeOptions, type RepayAmountArgs, type Requirement, type RequirementSignature, type Transaction, type VaultReallocation } from "../../types/index.js";
4
+ import { type AssetsOrSharesArgs, type DepositAmountArgs, type ERC20ApprovalAction, type MarketV1BorrowAction, type MarketV1RepayAction, type MarketV1RepayWithdrawCollateralAction, type MarketV1SupplyAction, type MarketV1SupplyCollateralAction, type MarketV1SupplyCollateralBorrowAction, type MarketV1WithdrawAction, type MarketV1WithdrawCollateralAction, type MorphoAuthorizationAction, type MorphoClientType, type ReallocationComputeOptions, type RepayAmountArgs, type Requirement, type RequirementSignature, type Transaction, type VaultReallocation } from "../../types/index.js";
5
5
  import { ReallocationData } from "../reallocationData.js";
6
6
  export interface MarketV1Actions {
7
7
  /**
@@ -37,6 +37,61 @@ export interface MarketV1Actions {
37
37
  useSimplePermit?: boolean;
38
38
  }) => Promise<(Readonly<Transaction<ERC20ApprovalAction>> | Requirement)[]>;
39
39
  };
40
+ /**
41
+ * Prepares a loan-asset supply transaction.
42
+ *
43
+ * Routed through bundler via GeneralAdapter1. Computes `maxSharePrice` from market supply
44
+ * state and `slippageTolerance` to protect against share-price inflation.
45
+ * `getRequirements` returns ERC20 approval or permit for `GeneralAdapter1` on the loan token.
46
+ * When `nativeAmount` is provided, native token is wrapped; the loan token must be wNative.
47
+ *
48
+ * No Morpho authorization required (supplier is crediting, not withdrawing).
49
+ *
50
+ * @param params - Supply parameters.
51
+ * @returns Object with `buildTx` and `getRequirements`.
52
+ */
53
+ supply: (params: {
54
+ userAddress: Address;
55
+ marketData: Market;
56
+ slippageTolerance?: bigint;
57
+ } & DepositAmountArgs) => {
58
+ buildTx: (requirementSignature?: RequirementSignature) => Readonly<Transaction<MarketV1SupplyAction>>;
59
+ getRequirements: (params?: {
60
+ useSimplePermit?: boolean;
61
+ }) => Promise<(Readonly<Transaction<ERC20ApprovalAction>> | Requirement)[]>;
62
+ };
63
+ /**
64
+ * Prepares a loan-asset withdraw transaction.
65
+ *
66
+ * Routed through bundler3 via `morphoWithdraw`. Supports two modes via {@link AssetsOrSharesArgs}:
67
+ * - **By assets** (`{ assets }`): withdraws an exact asset amount.
68
+ * - **By shares** (`{ shares }`): burns an exact share count (full close, immune to interest accrual).
69
+ *
70
+ * Computes `minSharePrice` from market supply state and `slippageTolerance`.
71
+ *
72
+ * When `reallocations` is provided, `reallocateTo` actions are prepended to the bundle,
73
+ * moving liquidity from other markets via the PublicAllocator before withdrawing — used to
74
+ * unblock withdraws that exceed on-market liquidity.
75
+ *
76
+ * `getRequirements` returns `morpho.setAuthorization(generalAdapter1, true)` if GA1 is not
77
+ * yet authorized on Morpho (returns `[]` when already authorized), since the bundler calls
78
+ * `withdraw(...,onBehalf=user,...)`.
79
+ *
80
+ * **Stale `positionData` may cause unexpected supply share calculations.**
81
+ *
82
+ * @param params - Withdraw parameters including pre-fetched `positionData`.
83
+ * @returns Object with `buildTx` and `getRequirements`.
84
+ */
85
+ withdraw: (params: {
86
+ userAddress: Address;
87
+ receiver?: Address;
88
+ positionData: AccrualPosition;
89
+ slippageTolerance?: bigint;
90
+ reallocations?: readonly VaultReallocation[];
91
+ } & AssetsOrSharesArgs) => {
92
+ buildTx: () => Readonly<Transaction<MarketV1WithdrawAction>>;
93
+ getRequirements: () => Promise<Readonly<Transaction<MorphoAuthorizationAction>>[]>;
94
+ };
40
95
  /**
41
96
  * Prepares a borrow transaction.
42
97
  *
@@ -201,29 +256,43 @@ export interface MarketV1Actions {
201
256
  };
202
257
  }) => Promise<ReallocationData>;
203
258
  /**
204
- * Computes vault reallocations for a borrow on this market.
259
+ * Computes vault reallocations for a borrow or withdraw on this market.
205
260
  *
206
- * Uses the shared liquidity algorithm to determine which vaults should
207
- * reallocate liquidity to this market via the PublicAllocator, based on
208
- * post-borrow utilization targets.
261
+ * Uses the shared-liquidity algorithm to determine which vaults should reallocate liquidity to
262
+ * this market via the PublicAllocator, based on the post-operation utilization target.
263
+ *
264
+ * Pass `{ borrowAmount }` for a borrow (legacy alias, equivalent to `{ operation: "borrow",
265
+ * amount }`) or `{ operation: "withdraw", amount }` for a loan-asset withdraw.
209
266
  *
210
267
  * @param params.reallocationData - The current on-chain state (from {@link getReallocationData}).
211
- * @param params.borrowAmount - The intended borrow amount.
268
+ * @param params.operation - The operation driving the reallocation (`"borrow"` or `"withdraw"`).
269
+ * Defaults to `"borrow"` when `borrowAmount` is provided.
270
+ * @param params.amount - The borrow or withdraw amount used to compute the post-state utilization.
271
+ * @param params.borrowAmount - {@deprecated} Equivalent to `{ operation: "borrow", amount }`. Use the
272
+ * `operation` + `amount` form on new code.
212
273
  * @param params.options - Optional reallocation computation options
213
274
  * (timestamp, utilization targets, reallocatable vaults filter, etc.).
214
275
  * Pass the fetched block timestamp to compute reallocations at the same block.
215
- * @returns Array of vault reallocations ready to pass to `borrow()` or
216
- * `supplyCollateralBorrow()`. Empty array if no reallocation is needed.
276
+ * @returns Array of vault reallocations ready to pass to `borrow()`, `supplyCollateralBorrow()`,
277
+ * or `withdraw()`. Empty array if no reallocation is needed.
217
278
  * @throws {ChainIdMismatchError} when `reallocationData` belongs to a different chain than this market.
218
- * @throws {InsufficientSharedLiquidityError} when shared liquidity cannot cover the borrow shortfall on the target market.
279
+ * @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.
219
280
  * @throws {MissingPublicAllocatorConfigError} when a selected vault is missing its public allocator config.
220
281
  * @throws {UnknownReallocationMarketError} when the target market is absent from the reallocation data.
221
282
  */
222
283
  getReallocations: (params: {
223
284
  reallocationData: ReallocationData;
224
- borrowAmount: bigint;
225
285
  options?: ReallocationComputeOptions;
226
- }) => readonly VaultReallocation[];
286
+ } & ({
287
+ operation: "borrow" | "withdraw";
288
+ amount: bigint;
289
+ borrowAmount?: never;
290
+ } | {
291
+ /** @deprecated Pass `{ operation: "borrow", amount }` instead. */
292
+ borrowAmount: bigint;
293
+ operation?: never;
294
+ amount?: never;
295
+ })) => readonly VaultReallocation[];
227
296
  }
228
297
  export declare class MorphoMarketV1 implements MarketV1Actions {
229
298
  private readonly client;
@@ -232,6 +301,26 @@ export declare class MorphoMarketV1 implements MarketV1Actions {
232
301
  constructor(client: MorphoClientType, marketParams: MarketParams, chainId: number);
233
302
  getMarketData(parameters?: FetchParameters): Promise<Market>;
234
303
  getPositionData(userAddress: Address, parameters?: FetchParameters): Promise<AccrualPosition>;
304
+ supply({ amount, userAddress, nativeAmount, marketData, slippageTolerance, }: {
305
+ userAddress: Address;
306
+ marketData: Market;
307
+ slippageTolerance?: bigint;
308
+ } & DepositAmountArgs): {
309
+ getRequirements: (params?: {
310
+ useSimplePermit?: boolean;
311
+ }) => Promise<(Requirement | Readonly<Transaction<ERC20ApprovalAction>>)[]>;
312
+ buildTx: (requirementSignature?: RequirementSignature) => Readonly<Transaction<MarketV1SupplyAction>>;
313
+ };
314
+ withdraw(params: {
315
+ userAddress: Address;
316
+ receiver?: Address;
317
+ positionData: AccrualPosition;
318
+ slippageTolerance?: bigint;
319
+ reallocations?: readonly VaultReallocation[];
320
+ } & AssetsOrSharesArgs): {
321
+ getRequirements: () => Promise<Readonly<Transaction<MorphoAuthorizationAction>>[]>;
322
+ buildTx: () => Readonly<Transaction<MarketV1WithdrawAction>>;
323
+ };
235
324
  supplyCollateral({ amount, userAddress, nativeAmount, }: {
236
325
  userAddress: Address;
237
326
  } & DepositAmountArgs): {
@@ -307,21 +396,35 @@ export declare class MorphoMarketV1 implements MarketV1Actions {
307
396
  };
308
397
  }): Promise<ReallocationData>;
309
398
  /**
310
- * Computes public allocator reallocations for a borrow on this market.
399
+ * Computes public allocator reallocations for a borrow or withdraw on this market.
400
+ *
401
+ * Pass `{ borrowAmount }` for a borrow (legacy alias, equivalent to `{ operation: "borrow", amount }`)
402
+ * or `{ operation, amount }` for a borrow or loan-asset withdraw.
311
403
  *
312
404
  * @param params - Reallocation computation parameters.
313
405
  * @param params.reallocationData - State returned by {@link getReallocationData}.
314
- * @param params.borrowAmount - Borrow amount to test against post-borrow utilization.
406
+ * @param params.operation - The operation driving the reallocation (`"borrow"` or `"withdraw"`).
407
+ * @param params.amount - The borrow or withdraw amount used to compute the post-state utilization.
408
+ * @param params.borrowAmount - {@deprecated Pass `{ operation: "borrow", amount }` instead.}
315
409
  * @param params.options - Optional allocator and utilization options.
316
- * @returns Vault reallocations ready to pass to `borrow` or `supplyCollateralBorrow`.
410
+ * @returns Vault reallocations ready to pass to `borrow`, `supplyCollateralBorrow`, or `withdraw`.
317
411
  * @throws {ChainIdMismatchError} when `reallocationData` belongs to a different chain than this market.
318
- * @throws {InsufficientSharedLiquidityError} when shared liquidity cannot cover the borrow shortfall on the target market.
412
+ * @throws {InsufficientSharedLiquidityError} when shared liquidity cannot cover the operation's absolute shortfall on the target market.
413
+ * @throws {ReallocationWithdrawExceedsMarketSupplyError} when `operation === "withdraw"` and `amount` exceeds the target market's `totalSupplyAssets`.
319
414
  * @throws {MissingPublicAllocatorConfigError} when a selected vault is missing its public allocator config.
320
415
  * @throws {UnknownReallocationMarketError} when the target market is absent from the reallocation data.
321
416
  */
322
- getReallocations({ reallocationData, borrowAmount, options, }: {
417
+ getReallocations(params: {
323
418
  reallocationData: ReallocationData;
324
- borrowAmount: bigint;
325
419
  options?: ReallocationComputeOptions;
326
- }): readonly VaultReallocation[];
420
+ } & ({
421
+ operation: "borrow" | "withdraw";
422
+ amount: bigint;
423
+ borrowAmount?: never;
424
+ } | {
425
+ /** @deprecated Pass `{ operation: "borrow", amount }` instead. */
426
+ borrowAmount: bigint;
427
+ operation?: never;
428
+ amount?: never;
429
+ })): readonly VaultReallocation[];
327
430
  }