@morpho-org/morpho-sdk 2.1.1 → 3.1.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 (206) hide show
  1. package/lib/cjs/abis.d.ts +2816 -0
  2. package/lib/cjs/abis.js +1951 -0
  3. package/lib/cjs/actions/index.d.ts +3 -0
  4. package/lib/cjs/actions/marketV1/borrow.js +7 -10
  5. package/lib/cjs/actions/marketV1/buildReallocationActions.d.ts +2 -3
  6. package/lib/cjs/actions/marketV1/buildReallocationActions.js +1 -2
  7. package/lib/cjs/actions/marketV1/index.d.ts +2 -0
  8. package/lib/cjs/actions/marketV1/index.js +2 -0
  9. package/lib/cjs/actions/marketV1/repay.d.ts +2 -0
  10. package/lib/cjs/actions/marketV1/repay.js +7 -8
  11. package/lib/cjs/actions/marketV1/repayWithdrawCollateral.d.ts +2 -0
  12. package/lib/cjs/actions/marketV1/repayWithdrawCollateral.js +9 -10
  13. package/lib/cjs/actions/marketV1/supply.d.ts +69 -0
  14. package/lib/cjs/actions/marketV1/supply.js +128 -0
  15. package/lib/cjs/actions/marketV1/supplyCollateral.d.ts +3 -1
  16. package/lib/cjs/actions/marketV1/supplyCollateral.js +12 -13
  17. package/lib/cjs/actions/marketV1/supplyCollateralBorrow.d.ts +3 -1
  18. package/lib/cjs/actions/marketV1/supplyCollateralBorrow.js +14 -15
  19. package/lib/cjs/actions/marketV1/withdraw.d.ts +83 -0
  20. package/lib/cjs/actions/marketV1/withdraw.js +110 -0
  21. package/lib/cjs/actions/requirements/encode/encodeErc20Approval.js +2 -2
  22. package/lib/cjs/actions/requirements/getRequirementsAction.d.ts +1 -1
  23. package/lib/cjs/actions/requirements/getRequirementsApproval.js +2 -2
  24. package/lib/cjs/actions/vaultV1/deposit.d.ts +2 -0
  25. package/lib/cjs/actions/vaultV1/deposit.js +13 -14
  26. package/lib/cjs/actions/vaultV1/migrateToV2.d.ts +2 -0
  27. package/lib/cjs/actions/vaultV1/migrateToV2.js +11 -9
  28. package/lib/cjs/actions/vaultV2/deposit.d.ts +2 -0
  29. package/lib/cjs/actions/vaultV2/deposit.js +13 -14
  30. package/lib/cjs/addresses.d.ts +2 -0
  31. package/lib/cjs/addresses.js +18 -0
  32. package/lib/cjs/augment/AccrualPosition.d.ts +9 -0
  33. package/lib/cjs/augment/AccrualPosition.js +8 -0
  34. package/lib/cjs/augment/AccrualVault.d.ts +8 -0
  35. package/lib/cjs/augment/AccrualVault.js +7 -0
  36. package/lib/cjs/augment/Holding.d.ts +8 -0
  37. package/lib/cjs/augment/Holding.js +7 -0
  38. package/lib/cjs/augment/Market.d.ts +8 -0
  39. package/lib/cjs/augment/Market.js +7 -0
  40. package/lib/cjs/augment/MarketParams.d.ts +8 -0
  41. package/lib/cjs/augment/MarketParams.js +7 -0
  42. package/lib/cjs/augment/Position.d.ts +8 -0
  43. package/lib/cjs/augment/Position.js +7 -0
  44. package/lib/cjs/augment/Token.d.ts +8 -0
  45. package/lib/cjs/augment/Token.js +7 -0
  46. package/lib/cjs/augment/User.d.ts +8 -0
  47. package/lib/cjs/augment/User.js +7 -0
  48. package/lib/cjs/augment/Vault.d.ts +8 -0
  49. package/lib/cjs/augment/Vault.js +7 -0
  50. package/lib/cjs/augment/VaultConfig.d.ts +8 -0
  51. package/lib/cjs/augment/VaultConfig.js +7 -0
  52. package/lib/cjs/augment/VaultMarketAllocation.d.ts +8 -0
  53. package/lib/cjs/augment/VaultMarketAllocation.js +7 -0
  54. package/lib/cjs/augment/VaultMarketConfig.d.ts +8 -0
  55. package/lib/cjs/augment/VaultMarketConfig.js +7 -0
  56. package/lib/cjs/augment/VaultMarketPublicAllocatorConfig.d.ts +8 -0
  57. package/lib/cjs/augment/VaultMarketPublicAllocatorConfig.js +8 -0
  58. package/lib/cjs/augment/VaultUser.d.ts +8 -0
  59. package/lib/cjs/augment/VaultUser.js +7 -0
  60. package/lib/cjs/augment.d.ts +14 -0
  61. package/lib/cjs/augment.js +16 -0
  62. package/lib/cjs/bundler/actions.d.ts +637 -0
  63. package/lib/cjs/bundler/actions.js +1088 -0
  64. package/lib/cjs/bundler/index.d.ts +2 -0
  65. package/lib/cjs/bundler/index.js +18 -0
  66. package/lib/cjs/bundler/types.d.ts +200 -0
  67. package/lib/cjs/bundler/types.js +2 -0
  68. package/lib/cjs/constants.d.ts +3 -0
  69. package/lib/cjs/constants.js +32 -0
  70. package/lib/cjs/entities/index.d.ts +6 -3
  71. package/lib/cjs/entities/index.js +41 -17
  72. package/lib/cjs/entities/marketV1/marketV1.d.ts +161 -24
  73. package/lib/cjs/entities/marketV1/marketV1.js +166 -19
  74. package/lib/cjs/entities/reallocationData.d.ts +193 -0
  75. package/lib/cjs/entities/reallocationData.js +406 -0
  76. package/lib/cjs/errors.d.ts +2 -0
  77. package/lib/cjs/errors.js +18 -0
  78. package/lib/cjs/fetch.d.ts +1 -0
  79. package/lib/cjs/fetch.js +30 -0
  80. package/lib/cjs/format.d.ts +2 -0
  81. package/lib/cjs/format.js +22 -0
  82. package/lib/cjs/helpers/computeReallocations.d.ts +63 -12
  83. package/lib/cjs/helpers/computeReallocations.js +160 -41
  84. package/lib/cjs/helpers/constant.d.ts +17 -0
  85. package/lib/cjs/helpers/constant.js +30 -1
  86. package/lib/cjs/helpers/index.d.ts +3 -2
  87. package/lib/cjs/helpers/index.js +14 -2
  88. package/lib/cjs/helpers/slippage.d.ts +57 -0
  89. package/lib/cjs/helpers/slippage.js +82 -0
  90. package/lib/cjs/helpers/validate.d.ts +40 -7
  91. package/lib/cjs/helpers/validate.js +67 -12
  92. package/lib/cjs/index.d.ts +0 -1
  93. package/lib/cjs/index.js +0 -1
  94. package/lib/cjs/types/action.d.ts +27 -6
  95. package/lib/cjs/types/client.d.ts +1 -1
  96. package/lib/cjs/types/error.d.ts +155 -7
  97. package/lib/cjs/types/error.js +202 -11
  98. package/lib/cjs/types/sharedLiquidity.d.ts +43 -3
  99. package/lib/cjs/types.d.ts +3 -0
  100. package/lib/cjs/types.js +17 -0
  101. package/lib/cjs/utils.d.ts +9 -0
  102. package/lib/cjs/utils.js +65 -0
  103. package/lib/esm/abis.d.ts +2816 -0
  104. package/lib/esm/abis.js +1922 -0
  105. package/lib/esm/actions/index.d.ts +3 -0
  106. package/lib/esm/actions/marketV1/borrow.js +2 -5
  107. package/lib/esm/actions/marketV1/buildReallocationActions.d.ts +2 -3
  108. package/lib/esm/actions/marketV1/buildReallocationActions.js +1 -2
  109. package/lib/esm/actions/marketV1/index.d.ts +2 -0
  110. package/lib/esm/actions/marketV1/index.js +2 -0
  111. package/lib/esm/actions/marketV1/repay.d.ts +2 -0
  112. package/lib/esm/actions/marketV1/repay.js +4 -5
  113. package/lib/esm/actions/marketV1/repayWithdrawCollateral.d.ts +2 -0
  114. package/lib/esm/actions/marketV1/repayWithdrawCollateral.js +4 -5
  115. package/lib/esm/actions/marketV1/supply.d.ts +69 -0
  116. package/lib/esm/actions/marketV1/supply.js +124 -0
  117. package/lib/esm/actions/marketV1/supplyCollateral.d.ts +3 -1
  118. package/lib/esm/actions/marketV1/supplyCollateral.js +7 -8
  119. package/lib/esm/actions/marketV1/supplyCollateralBorrow.d.ts +3 -1
  120. package/lib/esm/actions/marketV1/supplyCollateralBorrow.js +7 -8
  121. package/lib/esm/actions/marketV1/withdraw.d.ts +83 -0
  122. package/lib/esm/actions/marketV1/withdraw.js +106 -0
  123. package/lib/esm/actions/requirements/encode/encodeErc20Approval.js +1 -1
  124. package/lib/esm/actions/requirements/getRequirementsAction.d.ts +1 -1
  125. package/lib/esm/actions/requirements/getRequirementsApproval.js +1 -1
  126. package/lib/esm/actions/vaultV1/deposit.d.ts +2 -0
  127. package/lib/esm/actions/vaultV1/deposit.js +3 -4
  128. package/lib/esm/actions/vaultV1/migrateToV2.d.ts +2 -0
  129. package/lib/esm/actions/vaultV1/migrateToV2.js +3 -1
  130. package/lib/esm/actions/vaultV2/deposit.d.ts +2 -0
  131. package/lib/esm/actions/vaultV2/deposit.js +3 -4
  132. package/lib/esm/addresses.d.ts +2 -0
  133. package/lib/esm/addresses.js +1 -0
  134. package/lib/esm/augment/AccrualPosition.d.ts +9 -0
  135. package/lib/esm/augment/AccrualPosition.js +5 -0
  136. package/lib/esm/augment/AccrualVault.d.ts +8 -0
  137. package/lib/esm/augment/AccrualVault.js +4 -0
  138. package/lib/esm/augment/Holding.d.ts +8 -0
  139. package/lib/esm/augment/Holding.js +4 -0
  140. package/lib/esm/augment/Market.d.ts +8 -0
  141. package/lib/esm/augment/Market.js +4 -0
  142. package/lib/esm/augment/MarketParams.d.ts +8 -0
  143. package/lib/esm/augment/MarketParams.js +4 -0
  144. package/lib/esm/augment/Position.d.ts +8 -0
  145. package/lib/esm/augment/Position.js +4 -0
  146. package/lib/esm/augment/Token.d.ts +8 -0
  147. package/lib/esm/augment/Token.js +4 -0
  148. package/lib/esm/augment/User.d.ts +8 -0
  149. package/lib/esm/augment/User.js +4 -0
  150. package/lib/esm/augment/Vault.d.ts +8 -0
  151. package/lib/esm/augment/Vault.js +4 -0
  152. package/lib/esm/augment/VaultConfig.d.ts +8 -0
  153. package/lib/esm/augment/VaultConfig.js +4 -0
  154. package/lib/esm/augment/VaultMarketAllocation.d.ts +8 -0
  155. package/lib/esm/augment/VaultMarketAllocation.js +4 -0
  156. package/lib/esm/augment/VaultMarketConfig.d.ts +8 -0
  157. package/lib/esm/augment/VaultMarketConfig.js +4 -0
  158. package/lib/esm/augment/VaultMarketPublicAllocatorConfig.d.ts +8 -0
  159. package/lib/esm/augment/VaultMarketPublicAllocatorConfig.js +5 -0
  160. package/lib/esm/augment/VaultUser.d.ts +8 -0
  161. package/lib/esm/augment/VaultUser.js +4 -0
  162. package/lib/esm/augment.d.ts +14 -0
  163. package/lib/esm/augment.js +14 -0
  164. package/lib/esm/bundler/actions.d.ts +637 -0
  165. package/lib/esm/bundler/actions.js +1085 -0
  166. package/lib/esm/bundler/index.d.ts +2 -0
  167. package/lib/esm/bundler/index.js +2 -0
  168. package/lib/esm/bundler/types.d.ts +200 -0
  169. package/lib/esm/bundler/types.js +1 -0
  170. package/lib/esm/constants.d.ts +3 -0
  171. package/lib/esm/constants.js +3 -0
  172. package/lib/esm/entities/index.d.ts +6 -3
  173. package/lib/esm/entities/index.js +5 -3
  174. package/lib/esm/entities/marketV1/marketV1.d.ts +161 -24
  175. package/lib/esm/entities/marketV1/marketV1.js +170 -23
  176. package/lib/esm/entities/reallocationData.d.ts +193 -0
  177. package/lib/esm/entities/reallocationData.js +402 -0
  178. package/lib/esm/errors.d.ts +2 -0
  179. package/lib/esm/errors.js +1 -0
  180. package/lib/esm/fetch.d.ts +1 -0
  181. package/lib/esm/fetch.js +1 -0
  182. package/lib/esm/format.d.ts +2 -0
  183. package/lib/esm/format.js +1 -0
  184. package/lib/esm/helpers/computeReallocations.d.ts +63 -12
  185. package/lib/esm/helpers/computeReallocations.js +160 -41
  186. package/lib/esm/helpers/constant.d.ts +17 -0
  187. package/lib/esm/helpers/constant.js +30 -1
  188. package/lib/esm/helpers/index.d.ts +3 -2
  189. package/lib/esm/helpers/index.js +3 -2
  190. package/lib/esm/helpers/slippage.d.ts +57 -0
  191. package/lib/esm/helpers/slippage.js +80 -0
  192. package/lib/esm/helpers/validate.d.ts +40 -7
  193. package/lib/esm/helpers/validate.js +63 -11
  194. package/lib/esm/index.d.ts +0 -1
  195. package/lib/esm/index.js +0 -1
  196. package/lib/esm/types/action.d.ts +27 -6
  197. package/lib/esm/types/client.d.ts +1 -1
  198. package/lib/esm/types/error.d.ts +155 -7
  199. package/lib/esm/types/error.js +185 -9
  200. package/lib/esm/types/sharedLiquidity.d.ts +43 -3
  201. package/lib/esm/types.d.ts +3 -0
  202. package/lib/esm/types.js +1 -0
  203. package/lib/esm/utils.d.ts +9 -0
  204. package/lib/esm/utils.js +7 -0
  205. package/package.json +128 -17
  206. package/src/index.ts +0 -1
@@ -0,0 +1,2 @@
1
+ export * from "./actions.js";
2
+ export * from "./types.js";
@@ -0,0 +1,2 @@
1
+ export * from "./actions.js";
2
+ export * from "./types.js";
@@ -0,0 +1,200 @@
1
+ import type { InputMarketParams } from "@morpho-org/blue-sdk";
2
+ import type { Address, Hex } from "viem";
3
+ /**
4
+ * Morpho authorization payload signed by a user for Bundler3-mediated Morpho
5
+ * Blue execution.
6
+ */
7
+ export interface Authorization {
8
+ /** Address granting or revoking authorization. */
9
+ readonly authorizer: Address;
10
+ /** Address receiving authorization. */
11
+ readonly authorized: Address;
12
+ /** Whether authorization is granted (`true`) or revoked (`false`). */
13
+ readonly isAuthorized: boolean;
14
+ /** Morpho authorization nonce consumed by the signature. */
15
+ readonly nonce: bigint;
16
+ /** Signature deadline timestamp in seconds. */
17
+ readonly deadline: bigint;
18
+ }
19
+ /**
20
+ * Public allocator withdrawal input used by a `reallocateTo` Bundler3 action.
21
+ */
22
+ export interface InputReallocation {
23
+ /** Market to withdraw liquidity from. */
24
+ readonly marketParams: InputMarketParams;
25
+ /** Amount of loan assets to withdraw from the market. */
26
+ readonly amount: bigint;
27
+ }
28
+ /**
29
+ * Permit2 single-permit token allowance details.
30
+ */
31
+ export interface Permit2PermitSingleDetails {
32
+ /** ERC20 token approved through Permit2. */
33
+ readonly token: Address;
34
+ /** Allowance amount approved through Permit2. */
35
+ readonly amount: bigint;
36
+ /** Permit2 allowance expiration timestamp in seconds. */
37
+ readonly expiration: number;
38
+ /** Permit2 nonce consumed by the signature. */
39
+ readonly nonce: number;
40
+ }
41
+ /**
42
+ * Permit2 single-permit payload signed by the token owner.
43
+ */
44
+ export interface Permit2PermitSingle {
45
+ /** Token, amount, expiration, and nonce being approved. */
46
+ readonly details: Permit2PermitSingleDetails;
47
+ /** Deadline timestamp for consuming the Permit2 signature. */
48
+ readonly sigDeadline: bigint;
49
+ }
50
+ /**
51
+ * Argument tuples for Bundler3 actions supported by `morpho-sdk`.
52
+ */
53
+ export interface ActionArgs {
54
+ /** Native-token transfer from `owner` to `recipient` for `amount`; `skipRevert` controls Bundler3 revert handling. */
55
+ readonly nativeTransfer: [
56
+ owner: Address,
57
+ recipient: Address,
58
+ amount: bigint,
59
+ skipRevert?: boolean
60
+ ];
61
+ /** ERC20 transfer from `adapter` to `recipient` for `amount` of `asset`; `skipRevert` controls Bundler3 revert handling. */
62
+ readonly erc20Transfer: [
63
+ asset: Address,
64
+ recipient: Address,
65
+ amount: bigint,
66
+ adapter: Address,
67
+ skipRevert?: boolean
68
+ ];
69
+ /** GeneralAdapter1 ERC20 `transferFrom` of `asset` and `amount` to `recipient`; `skipRevert` controls Bundler3 revert handling. */
70
+ readonly erc20TransferFrom: [
71
+ asset: Address,
72
+ amount: bigint,
73
+ recipient: Address,
74
+ skipRevert?: boolean
75
+ ];
76
+ /** ERC-2612 permit from `owner` for `asset`, `amount`, `deadline`, and `signature`; `skipRevert` controls Bundler3 revert handling. */
77
+ readonly permit: [
78
+ owner: Address,
79
+ asset: Address,
80
+ amount: bigint,
81
+ deadline: bigint,
82
+ signature: Hex | null,
83
+ skipRevert?: boolean
84
+ ];
85
+ /** Permit2 approval from `owner` for `permitSingle` and `signature`; `skipRevert` controls Bundler3 revert handling. */
86
+ readonly approve2: [
87
+ owner: Address,
88
+ permitSingle: Permit2PermitSingle,
89
+ signature: Hex | null,
90
+ skipRevert?: boolean
91
+ ];
92
+ /** GeneralAdapter1 Permit2 transfer of `asset` and `amount` to `recipient`; `skipRevert` controls Bundler3 revert handling. */
93
+ readonly transferFrom2: [
94
+ asset: Address,
95
+ amount: bigint,
96
+ recipient: Address,
97
+ skipRevert?: boolean
98
+ ];
99
+ /** ERC4626 deposit into `erc4626` for `assets`, `maxSharePrice`, and `receiver`; `skipRevert` controls Bundler3 revert handling. */
100
+ readonly erc4626Deposit: [
101
+ erc4626: Address,
102
+ assets: bigint,
103
+ maxSharePrice: bigint,
104
+ receiver: Address,
105
+ skipRevert?: boolean
106
+ ];
107
+ /** ERC4626 redeem from `erc4626` for `shares`, `minSharePrice`, `receiver`, and `owner`; `skipRevert` controls Bundler3 revert handling. */
108
+ readonly erc4626Redeem: [
109
+ erc4626: Address,
110
+ shares: bigint,
111
+ minSharePrice: bigint,
112
+ receiver: Address,
113
+ owner: Address,
114
+ skipRevert?: boolean
115
+ ];
116
+ /** Morpho Blue supply-collateral call for `market`, `assets`, `onBehalf`, and callback actions; `skipRevert` controls Bundler3 revert handling. */
117
+ readonly morphoSupplyCollateral: [
118
+ market: InputMarketParams,
119
+ assets: bigint,
120
+ onBehalf: Address,
121
+ onMorphoSupplyCollateral: Action[],
122
+ skipRevert?: boolean
123
+ ];
124
+ /** Morpho Blue supply call for `market`, `assets` or `shares`, `slippageAmount`, `onBehalf`, and callback actions; `skipRevert` controls Bundler3 revert handling. */
125
+ readonly morphoSupply: [
126
+ market: InputMarketParams,
127
+ assets: bigint,
128
+ shares: bigint,
129
+ slippageAmount: bigint,
130
+ onBehalf: Address,
131
+ onMorphoSupply: Action[],
132
+ skipRevert?: boolean
133
+ ];
134
+ /** Morpho Blue borrow call for `market`, `assets` or `shares`, `slippageAmount`, and `receiver`; `skipRevert` controls Bundler3 revert handling. */
135
+ readonly morphoBorrow: [
136
+ market: InputMarketParams,
137
+ assets: bigint,
138
+ shares: bigint,
139
+ slippageAmount: bigint,
140
+ receiver: Address,
141
+ skipRevert?: boolean
142
+ ];
143
+ /** Morpho Blue repay call for `market`, `assets` or `shares`, `slippageAmount`, `onBehalf`, and callback actions; `skipRevert` controls Bundler3 revert handling. */
144
+ readonly morphoRepay: [
145
+ market: InputMarketParams,
146
+ assets: bigint,
147
+ shares: bigint,
148
+ slippageAmount: bigint,
149
+ onBehalf: Address,
150
+ onMorphoRepay: Action[],
151
+ skipRevert?: boolean
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
+ ];
162
+ /** Morpho Blue withdraw-collateral call for `market`, `assets`, and `receiver`; `skipRevert` controls Bundler3 revert handling. */
163
+ readonly morphoWithdrawCollateral: [
164
+ market: InputMarketParams,
165
+ assets: bigint,
166
+ receiver: Address,
167
+ skipRevert?: boolean
168
+ ];
169
+ /** PublicAllocator reallocation to `supplyMarket` from `vault` withdrawals while paying `fee`; `skipRevert` controls Bundler3 revert handling. */
170
+ readonly reallocateTo: [
171
+ vault: Address,
172
+ fee: bigint,
173
+ withdrawals: InputReallocation[],
174
+ supplyMarket: InputMarketParams,
175
+ skipRevert?: boolean
176
+ ];
177
+ /** GeneralAdapter1 native wrap of `amount` to `recipient`; `skipRevert` controls Bundler3 revert handling. */
178
+ readonly wrapNative: [
179
+ amount: bigint,
180
+ recipient: Address,
181
+ skipRevert?: boolean
182
+ ];
183
+ }
184
+ /**
185
+ * Supported Bundler3 action discriminator.
186
+ */
187
+ export type ActionType = keyof ActionArgs;
188
+ /**
189
+ * Supported Bundler3 action object map keyed by action discriminator.
190
+ */
191
+ export type Actions = {
192
+ readonly [T in ActionType]: {
193
+ readonly type: T;
194
+ readonly args: ActionArgs[T];
195
+ };
196
+ };
197
+ /**
198
+ * Discriminated union of Bundler3 actions supported by `morpho-sdk`.
199
+ */
200
+ export type Action = Actions[ActionType];
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,3 @@
1
+ export { ChainId, ChainUtils, DEFAULT_SLIPPAGE_TOLERANCE, EIP_712_FIELDS, isMarketId, LIQUIDATION_CURSOR, MAX_LIQUIDATION_INCENTIVE_FACTOR, ORACLE_PRICE_SCALE, SECONDS_PER_YEAR, TransactionType, } from "@morpho-org/blue-sdk";
2
+ export { BLUE_API_BASE_URL, BLUE_API_GRAPHQL_URL, CDN_BASE_URL, DOCS_BASE_URL, MORPHO_DOMAIN, OPTIMIZERS_API_BASE_URL, OPTIMIZERS_BASE_URL, REWARDS_BASE_URL, ZERO_ADDRESS, } from "@morpho-org/morpho-ts";
3
+ export { APPROVE_ONLY_ONCE_TOKENS, DEFAULT_LLTV_BUFFER, DEFAULT_SUPPLY_TARGET_UTILIZATION, DEFAULT_WITHDRAWAL_TARGET_UTILIZATION, MAX_ABSOLUTE_SHARE_PRICE, MAX_SLIPPAGE_TOLERANCE, MAX_TOKEN_APPROVALS, } from "./helpers/constant.js";
@@ -0,0 +1,3 @@
1
+ export { ChainId, ChainUtils, DEFAULT_SLIPPAGE_TOLERANCE, EIP_712_FIELDS, isMarketId, LIQUIDATION_CURSOR, MAX_LIQUIDATION_INCENTIVE_FACTOR, ORACLE_PRICE_SCALE, SECONDS_PER_YEAR, TransactionType, } from "@morpho-org/blue-sdk";
2
+ export { BLUE_API_BASE_URL, BLUE_API_GRAPHQL_URL, CDN_BASE_URL, DOCS_BASE_URL, MORPHO_DOMAIN, OPTIMIZERS_API_BASE_URL, OPTIMIZERS_BASE_URL, REWARDS_BASE_URL, ZERO_ADDRESS, } from "@morpho-org/morpho-ts";
3
+ export { APPROVE_ONLY_ONCE_TOKENS, DEFAULT_LLTV_BUFFER, DEFAULT_SUPPLY_TARGET_UTILIZATION, DEFAULT_WITHDRAWAL_TARGET_UTILIZATION, MAX_ABSOLUTE_SHARE_PRICE, MAX_SLIPPAGE_TOLERANCE, MAX_TOKEN_APPROVALS, } from "./helpers/constant.js";
@@ -1,3 +1,6 @@
1
- export * from "./marketV1/index.js";
2
- export * from "./vaultV1/index.js";
3
- export * from "./vaultV2/index.js";
1
+ export type { IAccrualPosition, IAccrualVault, IAccrualVaultV2, IAccrualVaultV2Adapter, IAccrualVaultV2MorphoMarketV1Adapter, IAccrualVaultV2MorphoMarketV1AdapterV2, IAccrualVaultV2MorphoVaultV1Adapter, IAssetBalances, IEip5267Domain, IHolding, IMarket, IMarketParams, IPosition, IPreLiquidationParams, IPreLiquidationPosition, IToken, IVault, IVaultConfig, IVaultMarketAllocation, IVaultMarketConfig, IVaultMarketPublicAllocatorConfig, IVaultToken, IVaultUser, IVaultV2, IVaultV2Adapter, IVaultV2Allocation, IVaultV2MorphoMarketV1Adapter, IVaultV2MorphoMarketV1AdapterV2, IVaultV2MorphoVaultV1Adapter, PeripheralBalance, PeripheralBalanceType, VaultPublicAllocatorConfig, } from "@morpho-org/blue-sdk";
2
+ export { AccrualPosition, AccrualVault, AccrualVaultV2, AccrualVaultV2MorphoMarketV1Adapter, AccrualVaultV2MorphoMarketV1AdapterV2, AccrualVaultV2MorphoVaultV1Adapter, AssetBalances, ConstantWrappedToken, Eip5267Domain, ExchangeRateWrappedToken, Holding, Market, MarketParams, Position, PreLiquidationParams, PreLiquidationPosition, Token, User, Vault, VaultConfig, VaultMarketAllocation, VaultMarketConfig, VaultMarketPublicAllocatorConfig, VaultToken, VaultUser, VaultV2, VaultV2Adapter, VaultV2MorphoMarketV1Adapter, VaultV2MorphoMarketV1AdapterV2, VaultV2MorphoVaultV1Adapter, WrappedToken, } from "@morpho-org/blue-sdk";
3
+ export { MorphoMarketV1 } from "./marketV1/index.js";
4
+ export { type InputReallocationData, ReallocationData, } from "./reallocationData.js";
5
+ export { MorphoVaultV1 } from "./vaultV1/index.js";
6
+ export { MorphoVaultV2 } from "./vaultV2/index.js";
@@ -1,3 +1,5 @@
1
- export * from "./marketV1/index.js";
2
- export * from "./vaultV1/index.js";
3
- export * from "./vaultV2/index.js";
1
+ export { AccrualPosition, AccrualVault, AccrualVaultV2, AccrualVaultV2MorphoMarketV1Adapter, AccrualVaultV2MorphoMarketV1AdapterV2, AccrualVaultV2MorphoVaultV1Adapter, AssetBalances, ConstantWrappedToken, Eip5267Domain, ExchangeRateWrappedToken, Holding, Market, MarketParams, Position, PreLiquidationParams, PreLiquidationPosition, Token, User, Vault, VaultConfig, VaultMarketAllocation, VaultMarketConfig, VaultMarketPublicAllocatorConfig, VaultToken, VaultUser, VaultV2, VaultV2Adapter, VaultV2MorphoMarketV1Adapter, VaultV2MorphoMarketV1AdapterV2, VaultV2MorphoVaultV1Adapter, WrappedToken, } from "@morpho-org/blue-sdk";
2
+ export { MorphoMarketV1 } from "./marketV1/index.js";
3
+ export { ReallocationData, } from "./reallocationData.js";
4
+ export { MorphoVaultV1 } from "./vaultV1/index.js";
5
+ export { MorphoVaultV2 } from "./vaultV2/index.js";
@@ -1,8 +1,8 @@
1
1
  import { type AccrualPosition, type Market, type MarketParams } from "@morpho-org/blue-sdk";
2
- import { type MinimalBlock, SimulationState } from "@morpho-org/simulation-sdk";
3
2
  import type { Address } from "viem";
4
3
  import type { FetchParameters } from "../../types/data.js";
5
- 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
+ import { ReallocationData } from "../reallocationData.js";
6
6
  export interface MarketV1Actions {
7
7
  /**
8
8
  * Fetches the latest market data with accrued interest.
@@ -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
  *
@@ -173,7 +228,7 @@ export interface MarketV1Actions {
173
228
  }) => Promise<(Readonly<Transaction<ERC20ApprovalAction>> | Readonly<Transaction<MorphoAuthorizationAction>> | Requirement)[]>;
174
229
  };
175
230
  /**
176
- * Fetches all on-chain data needed to construct a {@link SimulationState}
231
+ * Fetches all on-chain data needed to construct a {@link ReallocationData}
177
232
  * for computing vault reallocations via the public allocator.
178
233
  *
179
234
  * The target market is refetched internally at `block.number` so the
@@ -182,7 +237,7 @@ export interface MarketV1Actions {
182
237
  * inject unnecessary `reallocateTo` actions (and their PublicAllocator
183
238
  * fees) into the resulting bundle.
184
239
  *
185
- * The returned simulation state can be passed to {@link getReallocations}
240
+ * The returned reallocation data can be passed to {@link getReallocations}
186
241
  * to compute the `VaultReallocation[]` array for `borrow()` or
187
242
  * `supplyCollateralBorrow()`.
188
243
  *
@@ -190,31 +245,54 @@ export interface MarketV1Actions {
190
245
  *
191
246
  * @param params.vaultAddresses - Addresses of MetaMorpho vaults that allocate to this market.
192
247
  * @param params.block - The block to fetch data at (number and timestamp).
193
- * @returns A SimulationState populated with all required data.
248
+ * @returns A ReallocationData instance populated with all required data.
249
+ * @throws {ChainIdMismatchError} when the client chain does not match this market.
194
250
  */
195
251
  getReallocationData: (params: {
196
252
  vaultAddresses: readonly Address[];
197
- block: MinimalBlock;
198
- }) => Promise<SimulationState>;
253
+ block: {
254
+ readonly number: bigint;
255
+ readonly timestamp: bigint;
256
+ };
257
+ }) => Promise<ReallocationData>;
199
258
  /**
200
- * Computes vault reallocations for a borrow on this market.
259
+ * Computes vault reallocations for a borrow or withdraw on this market.
201
260
  *
202
- * Uses the shared liquidity algorithm to determine which vaults should
203
- * reallocate liquidity to this market via the PublicAllocator, based on
204
- * 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.
205
266
  *
206
267
  * @param params.reallocationData - The current on-chain state (from {@link getReallocationData}).
207
- * @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.
208
273
  * @param params.options - Optional reallocation computation options
209
- * (utilization targets, reallocatable vaults filter, etc.).
210
- * @returns Array of vault reallocations ready to pass to `borrow()` or
211
- * `supplyCollateralBorrow()`. Empty array if no reallocation is needed.
274
+ * (timestamp, utilization targets, reallocatable vaults filter, etc.).
275
+ * Pass the fetched block timestamp to compute reallocations at the same block.
276
+ * @returns Array of vault reallocations ready to pass to `borrow()`, `supplyCollateralBorrow()`,
277
+ * or `withdraw()`. Empty array if no reallocation is needed.
278
+ * @throws {ChainIdMismatchError} when `reallocationData` belongs to a different chain than this 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.
280
+ * @throws {MissingPublicAllocatorConfigError} when a selected vault is missing its public allocator config.
281
+ * @throws {UnknownReallocationMarketError} when the target market is absent from the reallocation data.
212
282
  */
213
283
  getReallocations: (params: {
214
- reallocationData: SimulationState;
215
- borrowAmount: bigint;
284
+ reallocationData: ReallocationData;
216
285
  options?: ReallocationComputeOptions;
217
- }) => 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[];
218
296
  }
219
297
  export declare class MorphoMarketV1 implements MarketV1Actions {
220
298
  private readonly client;
@@ -223,6 +301,26 @@ export declare class MorphoMarketV1 implements MarketV1Actions {
223
301
  constructor(client: MorphoClientType, marketParams: MarketParams, chainId: number);
224
302
  getMarketData(parameters?: FetchParameters): Promise<Market>;
225
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
+ };
226
324
  supplyCollateral({ amount, userAddress, nativeAmount, }: {
227
325
  userAddress: Address;
228
326
  } & DepositAmountArgs): {
@@ -281,13 +379,52 @@ export declare class MorphoMarketV1 implements MarketV1Actions {
281
379
  }) => Promise<(Requirement | Readonly<Transaction<ERC20ApprovalAction>> | Readonly<Transaction<MorphoAuthorizationAction>>)[]>;
282
380
  buildTx: (requirementSignature?: RequirementSignature) => Readonly<Transaction<MarketV1SupplyCollateralBorrowAction>>;
283
381
  };
382
+ /**
383
+ * Fetches all on-chain inputs needed to compute public allocator reallocations.
384
+ *
385
+ * @param params - Reallocation data fetch parameters.
386
+ * @param params.vaultAddresses - Vaults to inspect for source-market liquidity.
387
+ * @param params.block - Block number and timestamp used for consistent RPC reads.
388
+ * @returns Reallocation data ready for {@link getReallocations}.
389
+ * @throws {ChainIdMismatchError} when the client chain does not match this market.
390
+ */
284
391
  getReallocationData({ vaultAddresses, block, }: {
285
392
  vaultAddresses: readonly Address[];
286
- block: MinimalBlock;
287
- }): Promise<SimulationState>;
288
- getReallocations({ reallocationData, borrowAmount, options, }: {
289
- reallocationData: SimulationState;
290
- borrowAmount: bigint;
393
+ block: {
394
+ readonly number: bigint;
395
+ readonly timestamp: bigint;
396
+ };
397
+ }): Promise<ReallocationData>;
398
+ /**
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.
403
+ *
404
+ * @param params - Reallocation computation parameters.
405
+ * @param params.reallocationData - State returned by {@link getReallocationData}.
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.}
409
+ * @param params.options - Optional allocator and utilization options.
410
+ * @returns Vault reallocations ready to pass to `borrow`, `supplyCollateralBorrow`, or `withdraw`.
411
+ * @throws {ChainIdMismatchError} when `reallocationData` belongs to a different chain than this 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`.
414
+ * @throws {MissingPublicAllocatorConfigError} when a selected vault is missing its public allocator config.
415
+ * @throws {UnknownReallocationMarketError} when the target market is absent from the reallocation data.
416
+ */
417
+ getReallocations(params: {
418
+ reallocationData: ReallocationData;
291
419
  options?: ReallocationComputeOptions;
292
- }): 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[];
293
430
  }