@morpho-org/consumer-sdk 0.4.0 → 0.5.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 (56) hide show
  1. package/README.md +136 -10
  2. package/lib/actions/index.d.ts +1 -0
  3. package/lib/actions/index.js +1 -0
  4. package/lib/actions/marketV1/borrow.d.ts +34 -0
  5. package/lib/actions/marketV1/borrow.js +62 -0
  6. package/lib/actions/marketV1/buildReallocationActions.d.ts +17 -0
  7. package/lib/actions/marketV1/buildReallocationActions.js +36 -0
  8. package/lib/actions/marketV1/index.d.ts +6 -0
  9. package/lib/actions/marketV1/index.js +22 -0
  10. package/lib/actions/marketV1/repay.d.ts +44 -0
  11. package/lib/actions/marketV1/repay.js +93 -0
  12. package/lib/actions/marketV1/repayWithdrawCollateral.d.ts +51 -0
  13. package/lib/actions/marketV1/repayWithdrawCollateral.js +108 -0
  14. package/lib/actions/marketV1/supplyCollateral.d.ts +28 -0
  15. package/lib/actions/marketV1/supplyCollateral.js +85 -0
  16. package/lib/actions/marketV1/supplyCollateralBorrow.d.ts +37 -0
  17. package/lib/actions/marketV1/supplyCollateralBorrow.js +109 -0
  18. package/lib/actions/marketV1/withdrawCollateral.d.ts +28 -0
  19. package/lib/actions/marketV1/withdrawCollateral.js +51 -0
  20. package/lib/actions/requirements/encode/encodeErc20Permit.js +4 -1
  21. package/lib/actions/requirements/encode/encodeErc20Permit2.js +4 -1
  22. package/lib/actions/requirements/getMorphoAuthorizationRequirement.d.ts +21 -0
  23. package/lib/actions/requirements/getMorphoAuthorizationRequirement.js +55 -0
  24. package/lib/actions/requirements/index.d.ts +1 -0
  25. package/lib/actions/requirements/index.js +1 -0
  26. package/lib/actions/vaultV2/forceWithdraw.js +5 -1
  27. package/lib/client/morphoClient.d.ts +3 -1
  28. package/lib/client/morphoClient.js +3 -0
  29. package/lib/entities/index.d.ts +1 -0
  30. package/lib/entities/index.js +1 -0
  31. package/lib/entities/marketV1/index.d.ts +1 -0
  32. package/lib/entities/marketV1/index.js +17 -0
  33. package/lib/entities/marketV1/marketV1.d.ts +290 -0
  34. package/lib/entities/marketV1/marketV1.js +528 -0
  35. package/lib/entities/vaultV1/vaultV1.js +4 -0
  36. package/lib/entities/vaultV2/vaultV2.js +4 -0
  37. package/lib/helpers/computeReallocations.d.ts +23 -0
  38. package/lib/helpers/computeReallocations.js +98 -0
  39. package/lib/helpers/constant.d.ts +5 -0
  40. package/lib/helpers/constant.js +6 -1
  41. package/lib/helpers/index.d.ts +3 -0
  42. package/lib/helpers/index.js +18 -1
  43. package/lib/helpers/slippage.d.ts +46 -0
  44. package/lib/helpers/slippage.js +73 -0
  45. package/lib/helpers/validate.d.ts +150 -0
  46. package/lib/helpers/validate.js +279 -0
  47. package/lib/types/action.d.ts +75 -3
  48. package/lib/types/action.js +12 -1
  49. package/lib/types/client.d.ts +3 -1
  50. package/lib/types/error.d.ts +106 -1
  51. package/lib/types/error.js +165 -3
  52. package/lib/types/index.d.ts +1 -0
  53. package/lib/types/index.js +1 -0
  54. package/lib/types/sharedLiquidity.d.ts +41 -0
  55. package/lib/types/sharedLiquidity.js +2 -0
  56. package/package.json +1 -1
@@ -72,7 +72,78 @@ export interface VaultV1RedeemAction extends BaseAction<"vaultV1Redeem", {
72
72
  recipient: Address;
73
73
  }> {
74
74
  }
75
- export type TransactionAction = ERC20ApprovalAction | VaultV2DepositAction | VaultV2WithdrawAction | VaultV2RedeemAction | VaultV2ForceWithdrawAction | VaultV2ForceRedeemAction | VaultV1DepositAction | VaultV1WithdrawAction | VaultV1RedeemAction;
75
+ export interface MarketV1SupplyCollateralAction extends BaseAction<"marketV1SupplyCollateral", {
76
+ market: Hex;
77
+ amount: bigint;
78
+ onBehalf: Address;
79
+ nativeAmount?: bigint;
80
+ }> {
81
+ }
82
+ export interface MarketV1BorrowAction extends BaseAction<"marketV1Borrow", {
83
+ market: Hex;
84
+ amount: bigint;
85
+ receiver: Address;
86
+ minSharePrice: bigint;
87
+ reallocationFee: bigint;
88
+ }> {
89
+ }
90
+ export interface MarketV1SupplyCollateralBorrowAction extends BaseAction<"marketV1SupplyCollateralBorrow", {
91
+ market: Hex;
92
+ collateralAmount: bigint;
93
+ borrowAmount: bigint;
94
+ minSharePrice: bigint;
95
+ onBehalf: Address;
96
+ receiver: Address;
97
+ nativeAmount?: bigint;
98
+ reallocationFee: bigint;
99
+ }> {
100
+ }
101
+ export interface MarketV1RepayAction extends BaseAction<"marketV1Repay", {
102
+ market: Hex;
103
+ assets: bigint;
104
+ shares: bigint;
105
+ transferAmount: bigint;
106
+ onBehalf: Address;
107
+ receiver: Address;
108
+ maxSharePrice: bigint;
109
+ }> {
110
+ }
111
+ export interface MarketV1WithdrawCollateralAction extends BaseAction<"marketV1WithdrawCollateral", {
112
+ market: Hex;
113
+ amount: bigint;
114
+ onBehalf: Address;
115
+ receiver: Address;
116
+ }> {
117
+ }
118
+ export interface MarketV1RepayWithdrawCollateralAction extends BaseAction<"marketV1RepayWithdrawCollateral", {
119
+ market: Hex;
120
+ repayAssets: bigint;
121
+ repayShares: bigint;
122
+ transferAmount: bigint;
123
+ withdrawAmount: bigint;
124
+ maxSharePrice: bigint;
125
+ onBehalf: Address;
126
+ receiver: Address;
127
+ }> {
128
+ }
129
+ /**
130
+ * Enforces that exactly one repay amount source is provided.
131
+ *
132
+ * - `assets`: partial repay by exact asset amount.
133
+ * - `shares`: full repay by exact share count (guarantees full debt repayment
134
+ * regardless of interest accrued between tx construction and execution).
135
+ */
136
+ export type RepayAmountArgs = {
137
+ assets: bigint;
138
+ } | {
139
+ shares: bigint;
140
+ };
141
+ export interface MorphoAuthorizationAction extends BaseAction<"morphoAuthorization", {
142
+ authorized: Address;
143
+ isAuthorized: boolean;
144
+ }> {
145
+ }
146
+ export type TransactionAction = ERC20ApprovalAction | VaultV2DepositAction | VaultV2WithdrawAction | VaultV2RedeemAction | VaultV2ForceWithdrawAction | VaultV2ForceRedeemAction | VaultV1DepositAction | VaultV1WithdrawAction | VaultV1RedeemAction | MarketV1SupplyCollateralAction | MarketV1BorrowAction | MarketV1SupplyCollateralBorrowAction | MarketV1RepayAction | MarketV1WithdrawCollateralAction | MarketV1RepayWithdrawCollateralAction | MorphoAuthorizationAction;
76
147
  export interface Transaction<TAction extends BaseAction = TransactionAction> {
77
148
  readonly to: Address;
78
149
  readonly value: bigint;
@@ -131,5 +202,6 @@ export interface RequirementSignature {
131
202
  args: PermitArgs | Permit2Args;
132
203
  action: PermitAction | Permit2Action;
133
204
  }
134
- export declare function isRequirementApproval(requirement: Transaction<ERC20ApprovalAction> | Requirement | undefined): requirement is Transaction<ERC20ApprovalAction>;
135
- export declare function isRequirementSignature(requirement: Transaction<ERC20ApprovalAction> | Requirement | undefined): requirement is Requirement;
205
+ export declare function isRequirementApproval(requirement: Transaction<ERC20ApprovalAction> | Transaction<MorphoAuthorizationAction> | Requirement | undefined): requirement is Transaction<ERC20ApprovalAction>;
206
+ export declare function isRequirementAuthorization(requirement: Transaction<ERC20ApprovalAction> | Transaction<MorphoAuthorizationAction> | Requirement | undefined): requirement is Transaction<MorphoAuthorizationAction>;
207
+ export declare function isRequirementSignature(requirement: Transaction<ERC20ApprovalAction> | Transaction<MorphoAuthorizationAction> | Requirement | undefined): requirement is Requirement;
@@ -1,12 +1,23 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.isRequirementApproval = isRequirementApproval;
4
+ exports.isRequirementAuthorization = isRequirementAuthorization;
4
5
  exports.isRequirementSignature = isRequirementSignature;
5
6
  function isRequirementApproval(requirement) {
6
7
  return (requirement !== undefined &&
7
8
  "to" in requirement &&
8
9
  "value" in requirement &&
9
- "data" in requirement);
10
+ "data" in requirement &&
11
+ "action" in requirement &&
12
+ requirement.action.type === "erc20Approval");
13
+ }
14
+ function isRequirementAuthorization(requirement) {
15
+ return (requirement !== undefined &&
16
+ "to" in requirement &&
17
+ "value" in requirement &&
18
+ "data" in requirement &&
19
+ "action" in requirement &&
20
+ requirement.action.type === "morphoAuthorization");
10
21
  }
11
22
  function isRequirementSignature(requirement) {
12
23
  return (requirement !== undefined &&
@@ -1,5 +1,6 @@
1
+ import type { MarketParams } from "@morpho-org/blue-sdk";
1
2
  import type { Address, Client } from "viem";
2
- import type { VaultV1Actions, VaultV2Actions } from "../entities";
3
+ import type { MarketV1Actions, VaultV1Actions, VaultV2Actions } from "../entities";
3
4
  import type { Metadata } from "./index";
4
5
  export interface MorphoClientType {
5
6
  readonly viemClient: Client;
@@ -10,4 +11,5 @@ export interface MorphoClientType {
10
11
  };
11
12
  vaultV1: (vault: Address, chainId: number) => VaultV1Actions;
12
13
  vaultV2: (vault: Address, chainId: number) => VaultV2Actions;
14
+ marketV1: (marketParams: MarketParams, chainId: number) => MarketV1Actions;
13
15
  }
@@ -23,6 +23,9 @@ export declare class ApprovalAmountLessThanSpendAmountError extends Error {
23
23
  export declare class NegativeSlippageToleranceError extends Error {
24
24
  constructor(slippageTolerance: bigint);
25
25
  }
26
+ export declare class MissingAccrualPositionError extends Error {
27
+ constructor(market: string);
28
+ }
26
29
  export declare class ExcessiveSlippageToleranceError extends Error {
27
30
  constructor(slippageTolerance: bigint);
28
31
  }
@@ -36,7 +39,11 @@ export declare class DepositAssetMismatchError extends Error {
36
39
  constructor(depositAsset: Address, signatureAsset: Address);
37
40
  }
38
41
  export declare class DeallocationsExceedWithdrawError extends Error {
39
- constructor(vault: Address, withdrawAmount: bigint, totalDeallocated: bigint);
42
+ constructor(params: {
43
+ vault: Address;
44
+ withdrawAmount: bigint;
45
+ totalDeallocated: bigint;
46
+ });
40
47
  }
41
48
  export declare class NativeAmountOnNonWNativeVaultError extends Error {
42
49
  constructor(vaultAsset: Address, wNative: Address);
@@ -53,3 +60,101 @@ export declare class ZeroDepositAmountError extends Error {
53
60
  export declare class VaultAddressMismatchError extends Error {
54
61
  constructor(vaultAddress: Address, argsVaultAddress: Address);
55
62
  }
63
+ export declare class NonPositiveBorrowAmountError extends Error {
64
+ constructor(market: string);
65
+ }
66
+ export declare class ZeroCollateralAmountError extends Error {
67
+ constructor(market: string);
68
+ }
69
+ export declare class NativeAmountOnNonWNativeCollateralError extends Error {
70
+ constructor(collateralToken: Address, wNative: Address);
71
+ }
72
+ export declare class BorrowExceedsSafeLtvError extends Error {
73
+ constructor(borrowAmount: bigint, maxSafeBorrow: bigint);
74
+ }
75
+ export declare class MissingMarketPriceError extends Error {
76
+ constructor(market: string);
77
+ }
78
+ export declare class MarketIdMismatchError extends Error {
79
+ constructor(marketId: string, expectedMarketId: string);
80
+ }
81
+ export declare class AccrualPositionUserMismatchError extends Error {
82
+ constructor(positionUser: string, expectedUser: string);
83
+ }
84
+ export declare class NegativeReallocationFeeError extends Error {
85
+ constructor(vault: string);
86
+ }
87
+ export declare class EmptyReallocationWithdrawalsError extends Error {
88
+ constructor(vault: string);
89
+ }
90
+ export declare class NonPositiveReallocationAmountError extends Error {
91
+ constructor(vault: string, market: string);
92
+ }
93
+ export declare class ReallocationWithdrawalOnTargetMarketError extends Error {
94
+ constructor(vault: string, marketId: string);
95
+ }
96
+ export declare class UnsortedReallocationWithdrawalsError extends Error {
97
+ constructor(vault: string, marketId: string);
98
+ }
99
+ export declare class NonPositiveTransferAmountError extends Error {
100
+ constructor(market: string);
101
+ }
102
+ export declare class TransferAmountNotEqualToAssetsError extends Error {
103
+ constructor(params: {
104
+ transferAmount: bigint;
105
+ assets: bigint;
106
+ market: string;
107
+ });
108
+ }
109
+ export declare class MutuallyExclusiveRepayAmountsError extends Error {
110
+ constructor(market: string);
111
+ }
112
+ export declare class NonPositiveRepayAmountError extends Error {
113
+ constructor(market: string);
114
+ }
115
+ export declare class NonPositiveRepayMaxSharePriceError extends Error {
116
+ constructor(market: string);
117
+ }
118
+ export declare class NonPositiveWithdrawCollateralAmountError extends Error {
119
+ constructor(market: string);
120
+ }
121
+ export declare class WithdrawExceedsCollateralError extends Error {
122
+ constructor(params: {
123
+ withdrawAmount: bigint;
124
+ available: bigint;
125
+ market: string;
126
+ });
127
+ }
128
+ export declare class WithdrawMakesPositionUnhealthyError extends Error {
129
+ constructor(params: {
130
+ withdrawAmount: bigint;
131
+ borrowAssets: bigint;
132
+ maxSafeBorrow: bigint;
133
+ });
134
+ }
135
+ export declare class ShareDivideByZeroError extends Error {
136
+ constructor(market: string);
137
+ }
138
+ export declare class RepayExceedsDebtError extends Error {
139
+ constructor(params: {
140
+ repayAmount: bigint;
141
+ debt: bigint;
142
+ market: string;
143
+ });
144
+ }
145
+ export declare class InvalidSignatureError extends Error {
146
+ constructor();
147
+ }
148
+ export declare class RepaySharesExceedDebtError extends Error {
149
+ constructor(params: {
150
+ repayShares: bigint;
151
+ borrowShares: bigint;
152
+ market: string;
153
+ });
154
+ }
155
+ export declare class MissingPublicAllocatorConfigError extends Error {
156
+ constructor(vault: string);
157
+ }
158
+ export declare class NonPositiveMinBorrowSharePriceError extends Error {
159
+ constructor(market: string);
160
+ }
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.VaultAddressMismatchError = exports.ZeroDepositAmountError = exports.NegativeNativeAmountError = exports.ChainWNativeMissingError = exports.NativeAmountOnNonWNativeVaultError = exports.DeallocationsExceedWithdrawError = exports.DepositAssetMismatchError = exports.DepositAmountMismatchError = exports.EmptyDeallocationsError = exports.ExcessiveSlippageToleranceError = exports.NegativeSlippageToleranceError = exports.ApprovalAmountLessThanSpendAmountError = exports.MissingClientPropertyError = exports.ChainIdMismatchError = exports.AddressMismatchError = exports.NonPositiveMaxSharePriceError = exports.NonPositiveSharesAmountError = exports.NonPositiveAssetAmountError = void 0;
3
+ exports.NonPositiveMinBorrowSharePriceError = exports.MissingPublicAllocatorConfigError = exports.RepaySharesExceedDebtError = exports.InvalidSignatureError = exports.RepayExceedsDebtError = exports.ShareDivideByZeroError = exports.WithdrawMakesPositionUnhealthyError = exports.WithdrawExceedsCollateralError = exports.NonPositiveWithdrawCollateralAmountError = exports.NonPositiveRepayMaxSharePriceError = exports.NonPositiveRepayAmountError = exports.MutuallyExclusiveRepayAmountsError = exports.TransferAmountNotEqualToAssetsError = exports.NonPositiveTransferAmountError = exports.UnsortedReallocationWithdrawalsError = exports.ReallocationWithdrawalOnTargetMarketError = exports.NonPositiveReallocationAmountError = exports.EmptyReallocationWithdrawalsError = exports.NegativeReallocationFeeError = exports.AccrualPositionUserMismatchError = exports.MarketIdMismatchError = exports.MissingMarketPriceError = exports.BorrowExceedsSafeLtvError = exports.NativeAmountOnNonWNativeCollateralError = exports.ZeroCollateralAmountError = exports.NonPositiveBorrowAmountError = exports.VaultAddressMismatchError = exports.ZeroDepositAmountError = exports.NegativeNativeAmountError = exports.ChainWNativeMissingError = exports.NativeAmountOnNonWNativeVaultError = exports.DeallocationsExceedWithdrawError = exports.DepositAssetMismatchError = exports.DepositAmountMismatchError = exports.EmptyDeallocationsError = exports.ExcessiveSlippageToleranceError = exports.MissingAccrualPositionError = exports.NegativeSlippageToleranceError = exports.ApprovalAmountLessThanSpendAmountError = exports.MissingClientPropertyError = exports.ChainIdMismatchError = exports.AddressMismatchError = exports.NonPositiveMaxSharePriceError = exports.NonPositiveSharesAmountError = exports.NonPositiveAssetAmountError = void 0;
4
4
  class NonPositiveAssetAmountError extends Error {
5
5
  constructor(origin) {
6
6
  super(`Asset amount must be positive for address ${origin}`);
@@ -49,6 +49,12 @@ class NegativeSlippageToleranceError extends Error {
49
49
  }
50
50
  }
51
51
  exports.NegativeSlippageToleranceError = NegativeSlippageToleranceError;
52
+ class MissingAccrualPositionError extends Error {
53
+ constructor(market) {
54
+ super(`Accrual position is missing for market: ${market}`);
55
+ }
56
+ }
57
+ exports.MissingAccrualPositionError = MissingAccrualPositionError;
52
58
  class ExcessiveSlippageToleranceError extends Error {
53
59
  constructor(slippageTolerance) {
54
60
  super(`Slippage tolerance ${slippageTolerance} exceeds maximum allowed (10%)`);
@@ -74,8 +80,8 @@ class DepositAssetMismatchError extends Error {
74
80
  }
75
81
  exports.DepositAssetMismatchError = DepositAssetMismatchError;
76
82
  class DeallocationsExceedWithdrawError extends Error {
77
- constructor(vault, withdrawAmount, totalDeallocated) {
78
- super(`Total deallocated amount (${totalDeallocated}) exceed withdraw amount (${withdrawAmount}) for vault: ${vault}`);
83
+ constructor(params) {
84
+ super(`Total deallocated amount (${params.totalDeallocated}) exceed withdraw amount (${params.withdrawAmount}) for vault: ${params.vault}`);
79
85
  }
80
86
  }
81
87
  exports.DeallocationsExceedWithdrawError = DeallocationsExceedWithdrawError;
@@ -109,3 +115,159 @@ class VaultAddressMismatchError extends Error {
109
115
  }
110
116
  }
111
117
  exports.VaultAddressMismatchError = VaultAddressMismatchError;
118
+ class NonPositiveBorrowAmountError extends Error {
119
+ constructor(market) {
120
+ super(`Borrow amount must be positive for market: ${market}`);
121
+ }
122
+ }
123
+ exports.NonPositiveBorrowAmountError = NonPositiveBorrowAmountError;
124
+ class ZeroCollateralAmountError extends Error {
125
+ constructor(market) {
126
+ super(`Total collateral amount must be positive for market: ${market}. Both amount and nativeAmount are zero.`);
127
+ }
128
+ }
129
+ exports.ZeroCollateralAmountError = ZeroCollateralAmountError;
130
+ class NativeAmountOnNonWNativeCollateralError extends Error {
131
+ constructor(collateralToken, wNative) {
132
+ super(`Cannot use nativeAmount: collateral token ${collateralToken} is not the wrapped native token ${wNative}`);
133
+ }
134
+ }
135
+ exports.NativeAmountOnNonWNativeCollateralError = NativeAmountOnNonWNativeCollateralError;
136
+ class BorrowExceedsSafeLtvError extends Error {
137
+ constructor(borrowAmount, maxSafeBorrow) {
138
+ super(`Borrow amount ${borrowAmount} exceeds safe maximum ${maxSafeBorrow} (LLTV minus buffer). Reduce borrow or increase collateral.`);
139
+ }
140
+ }
141
+ exports.BorrowExceedsSafeLtvError = BorrowExceedsSafeLtvError;
142
+ class MissingMarketPriceError extends Error {
143
+ constructor(market) {
144
+ super(`Oracle price unavailable for market ${market}. Cannot validate position health.`);
145
+ }
146
+ }
147
+ exports.MissingMarketPriceError = MissingMarketPriceError;
148
+ class MarketIdMismatchError extends Error {
149
+ constructor(marketId, expectedMarketId) {
150
+ super(`Market ${marketId} does not match expected market ${expectedMarketId}`);
151
+ }
152
+ }
153
+ exports.MarketIdMismatchError = MarketIdMismatchError;
154
+ class AccrualPositionUserMismatchError extends Error {
155
+ constructor(positionUser, expectedUser) {
156
+ super(`Accrual position user ${positionUser} does not match expected user ${expectedUser}`);
157
+ }
158
+ }
159
+ exports.AccrualPositionUserMismatchError = AccrualPositionUserMismatchError;
160
+ class NegativeReallocationFeeError extends Error {
161
+ constructor(vault) {
162
+ super(`Reallocation fee must not be negative for vault: ${vault}`);
163
+ }
164
+ }
165
+ exports.NegativeReallocationFeeError = NegativeReallocationFeeError;
166
+ class EmptyReallocationWithdrawalsError extends Error {
167
+ constructor(vault) {
168
+ super(`Reallocation withdrawals list cannot be empty for vault: ${vault}`);
169
+ }
170
+ }
171
+ exports.EmptyReallocationWithdrawalsError = EmptyReallocationWithdrawalsError;
172
+ class NonPositiveReallocationAmountError extends Error {
173
+ constructor(vault, market) {
174
+ super(`Reallocation withdrawal amount must be positive for vault ${vault} on market ${market}`);
175
+ }
176
+ }
177
+ exports.NonPositiveReallocationAmountError = NonPositiveReallocationAmountError;
178
+ class ReallocationWithdrawalOnTargetMarketError extends Error {
179
+ constructor(vault, marketId) {
180
+ super(`Reallocation withdrawal cannot include the borrow target market ${marketId} for vault ${vault}.`);
181
+ }
182
+ }
183
+ exports.ReallocationWithdrawalOnTargetMarketError = ReallocationWithdrawalOnTargetMarketError;
184
+ class UnsortedReallocationWithdrawalsError extends Error {
185
+ constructor(vault, marketId) {
186
+ super(`Reallocation withdrawals must be strictly sorted by market ID for vault ${vault}. Market ${marketId} is out of order.`);
187
+ }
188
+ }
189
+ exports.UnsortedReallocationWithdrawalsError = UnsortedReallocationWithdrawalsError;
190
+ class NonPositiveTransferAmountError extends Error {
191
+ constructor(market) {
192
+ super(`Transfer amount must be positive for market: ${market}`);
193
+ }
194
+ }
195
+ exports.NonPositiveTransferAmountError = NonPositiveTransferAmountError;
196
+ class TransferAmountNotEqualToAssetsError extends Error {
197
+ constructor(params) {
198
+ super(`Transfer amount ${params.transferAmount} is not equal to repay assets ${params.assets} for market: ${params.market}`);
199
+ }
200
+ }
201
+ exports.TransferAmountNotEqualToAssetsError = TransferAmountNotEqualToAssetsError;
202
+ class MutuallyExclusiveRepayAmountsError extends Error {
203
+ constructor(market) {
204
+ super(`Exactly one of assets or shares must be non-zero for market: ${market}. Both were provided.`);
205
+ }
206
+ }
207
+ exports.MutuallyExclusiveRepayAmountsError = MutuallyExclusiveRepayAmountsError;
208
+ class NonPositiveRepayAmountError extends Error {
209
+ constructor(market) {
210
+ super(`Repay amount must be positive for market: ${market}`);
211
+ }
212
+ }
213
+ exports.NonPositiveRepayAmountError = NonPositiveRepayAmountError;
214
+ class NonPositiveRepayMaxSharePriceError extends Error {
215
+ constructor(market) {
216
+ super(`Max share price must be positive for market: ${market}`);
217
+ }
218
+ }
219
+ exports.NonPositiveRepayMaxSharePriceError = NonPositiveRepayMaxSharePriceError;
220
+ class NonPositiveWithdrawCollateralAmountError extends Error {
221
+ constructor(market) {
222
+ super(`Withdraw collateral amount must be positive for market: ${market}`);
223
+ }
224
+ }
225
+ exports.NonPositiveWithdrawCollateralAmountError = NonPositiveWithdrawCollateralAmountError;
226
+ class WithdrawExceedsCollateralError extends Error {
227
+ constructor(params) {
228
+ super(`Withdraw amount ${params.withdrawAmount} exceeds available collateral ${params.available} for market: ${params.market}`);
229
+ }
230
+ }
231
+ exports.WithdrawExceedsCollateralError = WithdrawExceedsCollateralError;
232
+ class WithdrawMakesPositionUnhealthyError extends Error {
233
+ constructor(params) {
234
+ super(`Withdrawing ${params.withdrawAmount} collateral would make position unhealthy. Max safe borrow after withdrawal: ${params.maxSafeBorrow}. Actual Borrow assets: ${params.borrowAssets}.`);
235
+ }
236
+ }
237
+ exports.WithdrawMakesPositionUnhealthyError = WithdrawMakesPositionUnhealthyError;
238
+ class ShareDivideByZeroError extends Error {
239
+ constructor(market) {
240
+ super(`Share divide by zero error for market: ${market}`);
241
+ }
242
+ }
243
+ exports.ShareDivideByZeroError = ShareDivideByZeroError;
244
+ class RepayExceedsDebtError extends Error {
245
+ constructor(params) {
246
+ super(`Repay amount ${params.repayAmount} exceeds outstanding debt ${params.debt} for market: ${params.market}`);
247
+ }
248
+ }
249
+ exports.RepayExceedsDebtError = RepayExceedsDebtError;
250
+ class InvalidSignatureError extends Error {
251
+ constructor() {
252
+ super("Signature verification failed: the signed data does not match the expected signer address");
253
+ }
254
+ }
255
+ exports.InvalidSignatureError = InvalidSignatureError;
256
+ class RepaySharesExceedDebtError extends Error {
257
+ constructor(params) {
258
+ super(`Repay shares ${params.repayShares} exceed outstanding borrow shares ${params.borrowShares} for market: ${params.market}`);
259
+ }
260
+ }
261
+ exports.RepaySharesExceedDebtError = RepaySharesExceedDebtError;
262
+ class MissingPublicAllocatorConfigError extends Error {
263
+ constructor(vault) {
264
+ super(`Vault ${vault} has no public allocator configured but was selected for reallocation`);
265
+ }
266
+ }
267
+ exports.MissingPublicAllocatorConfigError = MissingPublicAllocatorConfigError;
268
+ class NonPositiveMinBorrowSharePriceError extends Error {
269
+ constructor(market) {
270
+ super(`Min share price must be non-negative for market: ${market}`);
271
+ }
272
+ }
273
+ exports.NonPositiveMinBorrowSharePriceError = NonPositiveMinBorrowSharePriceError;
@@ -4,3 +4,4 @@ export * from "./deallocation";
4
4
  export * from "./entity";
5
5
  export * from "./error";
6
6
  export * from "./metadata";
7
+ export * from "./sharedLiquidity";
@@ -20,3 +20,4 @@ __exportStar(require("./deallocation"), exports);
20
20
  __exportStar(require("./entity"), exports);
21
21
  __exportStar(require("./error"), exports);
22
22
  __exportStar(require("./metadata"), exports);
23
+ __exportStar(require("./sharedLiquidity"), exports);
@@ -0,0 +1,41 @@
1
+ import type { MarketId, MarketParams } from "@morpho-org/blue-sdk";
2
+ import type { PublicAllocatorOptions } from "@morpho-org/simulation-sdk";
3
+ import type { Address } from "viem";
4
+ /** A single withdrawal from a source market within a vault reallocation. */
5
+ export interface ReallocationWithdrawal {
6
+ readonly marketParams: MarketParams;
7
+ readonly amount: bigint;
8
+ }
9
+ /**
10
+ * A computed reallocation for a single vault.
11
+ *
12
+ * Maps 1:1 to a `PublicAllocator.reallocateTo()` call.
13
+ * Withdraws from source markets and supplies to the target market.
14
+ */
15
+ export interface VaultReallocation {
16
+ readonly vault: Address;
17
+ /** Fee in native token (ETH) paid to the PublicAllocator for this vault. */
18
+ readonly fee: bigint;
19
+ /** Source markets to withdraw from before supplying to the target market. */
20
+ readonly withdrawals: readonly ReallocationWithdrawal[];
21
+ }
22
+ /**
23
+ * Options for computing vault reallocations via the public allocator.
24
+ *
25
+ * Extends {@link PublicAllocatorOptions} with supply-side utilization targets
26
+ * that determine when reallocation is triggered.
27
+ */
28
+ export interface ReallocationComputeOptions extends PublicAllocatorOptions {
29
+ /**
30
+ * Per-market target utilization above which the shared liquidity algorithm
31
+ * is triggered (scaled by WAD). Overrides `defaultSupplyTargetUtilization`
32
+ * for the specified market.
33
+ */
34
+ readonly supplyTargetUtilization?: Record<MarketId, bigint | undefined>;
35
+ /**
36
+ * The default target utilization above which the shared liquidity algorithm
37
+ * is triggered (scaled by WAD).
38
+ * @default 90.5% (905000000000000000n)
39
+ */
40
+ readonly defaultSupplyTargetUtilization?: bigint;
41
+ }
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@morpho-org/consumer-sdk",
3
3
  "description": "Abstraction layer for Morpho's complexity.",
4
- "version": "0.4.0",
4
+ "version": "0.5.0",
5
5
  "author": "Morpho Association <contact@morpho.org>",
6
6
  "contributors": [
7
7
  "Foulks-Plb <https://x.com/FoulkPlb>"