@morpho-org/morpho-sdk 2.0.0 → 3.0.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 (202) 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/repay.d.ts +2 -0
  8. package/lib/cjs/actions/marketV1/repay.js +7 -8
  9. package/lib/cjs/actions/marketV1/repayWithdrawCollateral.d.ts +2 -0
  10. package/lib/cjs/actions/marketV1/repayWithdrawCollateral.js +9 -10
  11. package/lib/cjs/actions/marketV1/supplyCollateral.d.ts +2 -0
  12. package/lib/cjs/actions/marketV1/supplyCollateral.js +11 -12
  13. package/lib/cjs/actions/marketV1/supplyCollateralBorrow.d.ts +2 -0
  14. package/lib/cjs/actions/marketV1/supplyCollateralBorrow.js +13 -14
  15. package/lib/cjs/actions/requirements/encode/encodeErc20Approval.js +2 -2
  16. package/lib/cjs/actions/requirements/getRequirementsAction.d.ts +28 -4
  17. package/lib/cjs/actions/requirements/getRequirementsAction.js +28 -4
  18. package/lib/cjs/actions/requirements/getRequirementsApproval.js +2 -2
  19. package/lib/cjs/actions/requirements/index.d.ts +1 -0
  20. package/lib/cjs/actions/requirements/index.js +1 -0
  21. package/lib/cjs/actions/vaultV1/deposit.d.ts +2 -0
  22. package/lib/cjs/actions/vaultV1/deposit.js +13 -14
  23. package/lib/cjs/actions/vaultV1/migrateToV2.d.ts +2 -0
  24. package/lib/cjs/actions/vaultV1/migrateToV2.js +11 -9
  25. package/lib/cjs/actions/vaultV2/deposit.d.ts +2 -0
  26. package/lib/cjs/actions/vaultV2/deposit.js +13 -14
  27. package/lib/cjs/addresses.d.ts +2 -0
  28. package/lib/cjs/addresses.js +18 -0
  29. package/lib/cjs/augment/AccrualPosition.d.ts +9 -0
  30. package/lib/cjs/augment/AccrualPosition.js +8 -0
  31. package/lib/cjs/augment/AccrualVault.d.ts +8 -0
  32. package/lib/cjs/augment/AccrualVault.js +7 -0
  33. package/lib/cjs/augment/Holding.d.ts +8 -0
  34. package/lib/cjs/augment/Holding.js +7 -0
  35. package/lib/cjs/augment/Market.d.ts +8 -0
  36. package/lib/cjs/augment/Market.js +7 -0
  37. package/lib/cjs/augment/MarketParams.d.ts +8 -0
  38. package/lib/cjs/augment/MarketParams.js +7 -0
  39. package/lib/cjs/augment/Position.d.ts +8 -0
  40. package/lib/cjs/augment/Position.js +7 -0
  41. package/lib/cjs/augment/Token.d.ts +8 -0
  42. package/lib/cjs/augment/Token.js +7 -0
  43. package/lib/cjs/augment/User.d.ts +8 -0
  44. package/lib/cjs/augment/User.js +7 -0
  45. package/lib/cjs/augment/Vault.d.ts +8 -0
  46. package/lib/cjs/augment/Vault.js +7 -0
  47. package/lib/cjs/augment/VaultConfig.d.ts +8 -0
  48. package/lib/cjs/augment/VaultConfig.js +7 -0
  49. package/lib/cjs/augment/VaultMarketAllocation.d.ts +8 -0
  50. package/lib/cjs/augment/VaultMarketAllocation.js +7 -0
  51. package/lib/cjs/augment/VaultMarketConfig.d.ts +8 -0
  52. package/lib/cjs/augment/VaultMarketConfig.js +7 -0
  53. package/lib/cjs/augment/VaultMarketPublicAllocatorConfig.d.ts +8 -0
  54. package/lib/cjs/augment/VaultMarketPublicAllocatorConfig.js +8 -0
  55. package/lib/cjs/augment/VaultUser.d.ts +8 -0
  56. package/lib/cjs/augment/VaultUser.js +7 -0
  57. package/lib/cjs/augment.d.ts +14 -0
  58. package/lib/cjs/augment.js +16 -0
  59. package/lib/cjs/bundler/actions.d.ts +555 -0
  60. package/lib/cjs/bundler/actions.js +953 -0
  61. package/lib/cjs/bundler/index.d.ts +2 -0
  62. package/lib/cjs/bundler/index.js +18 -0
  63. package/lib/cjs/bundler/types.d.ts +181 -0
  64. package/lib/cjs/bundler/types.js +2 -0
  65. package/lib/cjs/constants.d.ts +3 -0
  66. package/lib/cjs/constants.js +32 -0
  67. package/lib/cjs/entities/index.d.ts +6 -3
  68. package/lib/cjs/entities/index.js +41 -17
  69. package/lib/cjs/entities/marketV1/marketV1.d.ts +45 -11
  70. package/lib/cjs/entities/marketV1/marketV1.js +45 -23
  71. package/lib/cjs/entities/reallocationData.d.ts +193 -0
  72. package/lib/cjs/entities/reallocationData.js +406 -0
  73. package/lib/cjs/entities/vaultV1/vaultV1.js +6 -2
  74. package/lib/cjs/entities/vaultV2/vaultV2.js +6 -1
  75. package/lib/cjs/errors.d.ts +2 -0
  76. package/lib/cjs/errors.js +18 -0
  77. package/lib/cjs/fetch.d.ts +1 -0
  78. package/lib/cjs/fetch.js +30 -0
  79. package/lib/cjs/format.d.ts +2 -0
  80. package/lib/cjs/format.js +22 -0
  81. package/lib/cjs/helpers/computeReallocations.d.ts +48 -8
  82. package/lib/cjs/helpers/computeReallocations.js +120 -32
  83. package/lib/cjs/helpers/constant.d.ts +17 -0
  84. package/lib/cjs/helpers/constant.js +30 -1
  85. package/lib/cjs/helpers/index.d.ts +1 -0
  86. package/lib/cjs/helpers/index.js +9 -1
  87. package/lib/cjs/helpers/metadata.d.ts +10 -0
  88. package/lib/cjs/helpers/metadata.js +20 -1
  89. package/lib/cjs/helpers/validate.d.ts +2 -0
  90. package/lib/cjs/helpers/validate.js +14 -2
  91. package/lib/cjs/index.d.ts +0 -1
  92. package/lib/cjs/index.js +0 -1
  93. package/lib/cjs/types/client.d.ts +1 -1
  94. package/lib/cjs/types/error.d.ts +91 -1
  95. package/lib/cjs/types/error.js +126 -1
  96. package/lib/cjs/types/sharedLiquidity.d.ts +43 -3
  97. package/lib/cjs/types.d.ts +3 -0
  98. package/lib/cjs/types.js +17 -0
  99. package/lib/cjs/utils.d.ts +9 -0
  100. package/lib/cjs/utils.js +65 -0
  101. package/lib/esm/abis.d.ts +2816 -0
  102. package/lib/esm/abis.js +1922 -0
  103. package/lib/esm/actions/index.d.ts +3 -0
  104. package/lib/esm/actions/marketV1/borrow.js +2 -5
  105. package/lib/esm/actions/marketV1/buildReallocationActions.d.ts +2 -3
  106. package/lib/esm/actions/marketV1/buildReallocationActions.js +1 -2
  107. package/lib/esm/actions/marketV1/repay.d.ts +2 -0
  108. package/lib/esm/actions/marketV1/repay.js +4 -5
  109. package/lib/esm/actions/marketV1/repayWithdrawCollateral.d.ts +2 -0
  110. package/lib/esm/actions/marketV1/repayWithdrawCollateral.js +4 -5
  111. package/lib/esm/actions/marketV1/supplyCollateral.d.ts +2 -0
  112. package/lib/esm/actions/marketV1/supplyCollateral.js +4 -5
  113. package/lib/esm/actions/marketV1/supplyCollateralBorrow.d.ts +2 -0
  114. package/lib/esm/actions/marketV1/supplyCollateralBorrow.js +4 -5
  115. package/lib/esm/actions/requirements/encode/encodeErc20Approval.js +1 -1
  116. package/lib/esm/actions/requirements/getRequirementsAction.d.ts +28 -4
  117. package/lib/esm/actions/requirements/getRequirementsAction.js +29 -5
  118. package/lib/esm/actions/requirements/getRequirementsApproval.js +1 -1
  119. package/lib/esm/actions/requirements/index.d.ts +1 -0
  120. package/lib/esm/actions/requirements/index.js +1 -0
  121. package/lib/esm/actions/vaultV1/deposit.d.ts +2 -0
  122. package/lib/esm/actions/vaultV1/deposit.js +3 -4
  123. package/lib/esm/actions/vaultV1/migrateToV2.d.ts +2 -0
  124. package/lib/esm/actions/vaultV1/migrateToV2.js +3 -1
  125. package/lib/esm/actions/vaultV2/deposit.d.ts +2 -0
  126. package/lib/esm/actions/vaultV2/deposit.js +3 -4
  127. package/lib/esm/addresses.d.ts +2 -0
  128. package/lib/esm/addresses.js +1 -0
  129. package/lib/esm/augment/AccrualPosition.d.ts +9 -0
  130. package/lib/esm/augment/AccrualPosition.js +5 -0
  131. package/lib/esm/augment/AccrualVault.d.ts +8 -0
  132. package/lib/esm/augment/AccrualVault.js +4 -0
  133. package/lib/esm/augment/Holding.d.ts +8 -0
  134. package/lib/esm/augment/Holding.js +4 -0
  135. package/lib/esm/augment/Market.d.ts +8 -0
  136. package/lib/esm/augment/Market.js +4 -0
  137. package/lib/esm/augment/MarketParams.d.ts +8 -0
  138. package/lib/esm/augment/MarketParams.js +4 -0
  139. package/lib/esm/augment/Position.d.ts +8 -0
  140. package/lib/esm/augment/Position.js +4 -0
  141. package/lib/esm/augment/Token.d.ts +8 -0
  142. package/lib/esm/augment/Token.js +4 -0
  143. package/lib/esm/augment/User.d.ts +8 -0
  144. package/lib/esm/augment/User.js +4 -0
  145. package/lib/esm/augment/Vault.d.ts +8 -0
  146. package/lib/esm/augment/Vault.js +4 -0
  147. package/lib/esm/augment/VaultConfig.d.ts +8 -0
  148. package/lib/esm/augment/VaultConfig.js +4 -0
  149. package/lib/esm/augment/VaultMarketAllocation.d.ts +8 -0
  150. package/lib/esm/augment/VaultMarketAllocation.js +4 -0
  151. package/lib/esm/augment/VaultMarketConfig.d.ts +8 -0
  152. package/lib/esm/augment/VaultMarketConfig.js +4 -0
  153. package/lib/esm/augment/VaultMarketPublicAllocatorConfig.d.ts +8 -0
  154. package/lib/esm/augment/VaultMarketPublicAllocatorConfig.js +5 -0
  155. package/lib/esm/augment/VaultUser.d.ts +8 -0
  156. package/lib/esm/augment/VaultUser.js +4 -0
  157. package/lib/esm/augment.d.ts +14 -0
  158. package/lib/esm/augment.js +14 -0
  159. package/lib/esm/bundler/actions.d.ts +555 -0
  160. package/lib/esm/bundler/actions.js +950 -0
  161. package/lib/esm/bundler/index.d.ts +2 -0
  162. package/lib/esm/bundler/index.js +2 -0
  163. package/lib/esm/bundler/types.d.ts +181 -0
  164. package/lib/esm/bundler/types.js +1 -0
  165. package/lib/esm/constants.d.ts +3 -0
  166. package/lib/esm/constants.js +3 -0
  167. package/lib/esm/entities/index.d.ts +6 -3
  168. package/lib/esm/entities/index.js +5 -3
  169. package/lib/esm/entities/marketV1/marketV1.d.ts +45 -11
  170. package/lib/esm/entities/marketV1/marketV1.js +46 -24
  171. package/lib/esm/entities/reallocationData.d.ts +193 -0
  172. package/lib/esm/entities/reallocationData.js +402 -0
  173. package/lib/esm/entities/vaultV1/vaultV1.js +6 -2
  174. package/lib/esm/entities/vaultV2/vaultV2.js +6 -1
  175. package/lib/esm/errors.d.ts +2 -0
  176. package/lib/esm/errors.js +1 -0
  177. package/lib/esm/fetch.d.ts +1 -0
  178. package/lib/esm/fetch.js +1 -0
  179. package/lib/esm/format.d.ts +2 -0
  180. package/lib/esm/format.js +1 -0
  181. package/lib/esm/helpers/computeReallocations.d.ts +48 -8
  182. package/lib/esm/helpers/computeReallocations.js +119 -31
  183. package/lib/esm/helpers/constant.d.ts +17 -0
  184. package/lib/esm/helpers/constant.js +30 -1
  185. package/lib/esm/helpers/index.d.ts +1 -0
  186. package/lib/esm/helpers/index.js +1 -0
  187. package/lib/esm/helpers/metadata.d.ts +10 -0
  188. package/lib/esm/helpers/metadata.js +20 -1
  189. package/lib/esm/helpers/validate.d.ts +2 -0
  190. package/lib/esm/helpers/validate.js +12 -1
  191. package/lib/esm/index.d.ts +0 -1
  192. package/lib/esm/index.js +0 -1
  193. package/lib/esm/types/client.d.ts +1 -1
  194. package/lib/esm/types/error.d.ts +91 -1
  195. package/lib/esm/types/error.js +118 -0
  196. package/lib/esm/types/sharedLiquidity.d.ts +43 -3
  197. package/lib/esm/types.d.ts +3 -0
  198. package/lib/esm/types.js +1 -0
  199. package/lib/esm/utils.d.ts +9 -0
  200. package/lib/esm/utils.js +7 -0
  201. package/package.json +121 -14
  202. package/src/index.ts +0 -1
@@ -0,0 +1,2 @@
1
+ export * from "./actions.js";
2
+ export * from "./types.js";
@@ -0,0 +1,18 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
+ };
16
+ Object.defineProperty(exports, "__esModule", { value: true });
17
+ __exportStar(require("./actions.js"), exports);
18
+ __exportStar(require("./types.js"), exports);
@@ -0,0 +1,181 @@
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 borrow call for `market`, `assets` or `shares`, `slippageAmount`, and `receiver`; `skipRevert` controls Bundler3 revert handling. */
125
+ readonly morphoBorrow: [
126
+ market: InputMarketParams,
127
+ assets: bigint,
128
+ shares: bigint,
129
+ slippageAmount: bigint,
130
+ receiver: Address,
131
+ skipRevert?: boolean
132
+ ];
133
+ /** Morpho Blue repay call for `market`, `assets` or `shares`, `slippageAmount`, `onBehalf`, and callback actions; `skipRevert` controls Bundler3 revert handling. */
134
+ readonly morphoRepay: [
135
+ market: InputMarketParams,
136
+ assets: bigint,
137
+ shares: bigint,
138
+ slippageAmount: bigint,
139
+ onBehalf: Address,
140
+ onMorphoRepay: Action[],
141
+ skipRevert?: boolean
142
+ ];
143
+ /** Morpho Blue withdraw-collateral call for `market`, `assets`, and `receiver`; `skipRevert` controls Bundler3 revert handling. */
144
+ readonly morphoWithdrawCollateral: [
145
+ market: InputMarketParams,
146
+ assets: bigint,
147
+ receiver: Address,
148
+ skipRevert?: boolean
149
+ ];
150
+ /** PublicAllocator reallocation to `supplyMarket` from `vault` withdrawals while paying `fee`; `skipRevert` controls Bundler3 revert handling. */
151
+ readonly reallocateTo: [
152
+ vault: Address,
153
+ fee: bigint,
154
+ withdrawals: InputReallocation[],
155
+ supplyMarket: InputMarketParams,
156
+ skipRevert?: boolean
157
+ ];
158
+ /** GeneralAdapter1 native wrap of `amount` to `recipient`; `skipRevert` controls Bundler3 revert handling. */
159
+ readonly wrapNative: [
160
+ amount: bigint,
161
+ recipient: Address,
162
+ skipRevert?: boolean
163
+ ];
164
+ }
165
+ /**
166
+ * Supported Bundler3 action discriminator.
167
+ */
168
+ export type ActionType = keyof ActionArgs;
169
+ /**
170
+ * Supported Bundler3 action object map keyed by action discriminator.
171
+ */
172
+ export type Actions = {
173
+ readonly [T in ActionType]: {
174
+ readonly type: T;
175
+ readonly args: ActionArgs[T];
176
+ };
177
+ };
178
+ /**
179
+ * Discriminated union of Bundler3 actions supported by `morpho-sdk`.
180
+ */
181
+ export type Action = Actions[ActionType];
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -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,32 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.MAX_TOKEN_APPROVALS = exports.MAX_SLIPPAGE_TOLERANCE = exports.MAX_ABSOLUTE_SHARE_PRICE = exports.DEFAULT_WITHDRAWAL_TARGET_UTILIZATION = exports.DEFAULT_SUPPLY_TARGET_UTILIZATION = exports.DEFAULT_LLTV_BUFFER = exports.APPROVE_ONLY_ONCE_TOKENS = exports.ZERO_ADDRESS = exports.REWARDS_BASE_URL = exports.OPTIMIZERS_BASE_URL = exports.OPTIMIZERS_API_BASE_URL = exports.MORPHO_DOMAIN = exports.DOCS_BASE_URL = exports.CDN_BASE_URL = exports.BLUE_API_GRAPHQL_URL = exports.BLUE_API_BASE_URL = exports.TransactionType = exports.SECONDS_PER_YEAR = exports.ORACLE_PRICE_SCALE = exports.MAX_LIQUIDATION_INCENTIVE_FACTOR = exports.LIQUIDATION_CURSOR = exports.isMarketId = exports.EIP_712_FIELDS = exports.DEFAULT_SLIPPAGE_TOLERANCE = exports.ChainUtils = exports.ChainId = void 0;
4
+ var blue_sdk_1 = require("@morpho-org/blue-sdk");
5
+ Object.defineProperty(exports, "ChainId", { enumerable: true, get: function () { return blue_sdk_1.ChainId; } });
6
+ Object.defineProperty(exports, "ChainUtils", { enumerable: true, get: function () { return blue_sdk_1.ChainUtils; } });
7
+ Object.defineProperty(exports, "DEFAULT_SLIPPAGE_TOLERANCE", { enumerable: true, get: function () { return blue_sdk_1.DEFAULT_SLIPPAGE_TOLERANCE; } });
8
+ Object.defineProperty(exports, "EIP_712_FIELDS", { enumerable: true, get: function () { return blue_sdk_1.EIP_712_FIELDS; } });
9
+ Object.defineProperty(exports, "isMarketId", { enumerable: true, get: function () { return blue_sdk_1.isMarketId; } });
10
+ Object.defineProperty(exports, "LIQUIDATION_CURSOR", { enumerable: true, get: function () { return blue_sdk_1.LIQUIDATION_CURSOR; } });
11
+ Object.defineProperty(exports, "MAX_LIQUIDATION_INCENTIVE_FACTOR", { enumerable: true, get: function () { return blue_sdk_1.MAX_LIQUIDATION_INCENTIVE_FACTOR; } });
12
+ Object.defineProperty(exports, "ORACLE_PRICE_SCALE", { enumerable: true, get: function () { return blue_sdk_1.ORACLE_PRICE_SCALE; } });
13
+ Object.defineProperty(exports, "SECONDS_PER_YEAR", { enumerable: true, get: function () { return blue_sdk_1.SECONDS_PER_YEAR; } });
14
+ Object.defineProperty(exports, "TransactionType", { enumerable: true, get: function () { return blue_sdk_1.TransactionType; } });
15
+ var morpho_ts_1 = require("@morpho-org/morpho-ts");
16
+ Object.defineProperty(exports, "BLUE_API_BASE_URL", { enumerable: true, get: function () { return morpho_ts_1.BLUE_API_BASE_URL; } });
17
+ Object.defineProperty(exports, "BLUE_API_GRAPHQL_URL", { enumerable: true, get: function () { return morpho_ts_1.BLUE_API_GRAPHQL_URL; } });
18
+ Object.defineProperty(exports, "CDN_BASE_URL", { enumerable: true, get: function () { return morpho_ts_1.CDN_BASE_URL; } });
19
+ Object.defineProperty(exports, "DOCS_BASE_URL", { enumerable: true, get: function () { return morpho_ts_1.DOCS_BASE_URL; } });
20
+ Object.defineProperty(exports, "MORPHO_DOMAIN", { enumerable: true, get: function () { return morpho_ts_1.MORPHO_DOMAIN; } });
21
+ Object.defineProperty(exports, "OPTIMIZERS_API_BASE_URL", { enumerable: true, get: function () { return morpho_ts_1.OPTIMIZERS_API_BASE_URL; } });
22
+ Object.defineProperty(exports, "OPTIMIZERS_BASE_URL", { enumerable: true, get: function () { return morpho_ts_1.OPTIMIZERS_BASE_URL; } });
23
+ Object.defineProperty(exports, "REWARDS_BASE_URL", { enumerable: true, get: function () { return morpho_ts_1.REWARDS_BASE_URL; } });
24
+ Object.defineProperty(exports, "ZERO_ADDRESS", { enumerable: true, get: function () { return morpho_ts_1.ZERO_ADDRESS; } });
25
+ var constant_js_1 = require("./helpers/constant.js");
26
+ Object.defineProperty(exports, "APPROVE_ONLY_ONCE_TOKENS", { enumerable: true, get: function () { return constant_js_1.APPROVE_ONLY_ONCE_TOKENS; } });
27
+ Object.defineProperty(exports, "DEFAULT_LLTV_BUFFER", { enumerable: true, get: function () { return constant_js_1.DEFAULT_LLTV_BUFFER; } });
28
+ Object.defineProperty(exports, "DEFAULT_SUPPLY_TARGET_UTILIZATION", { enumerable: true, get: function () { return constant_js_1.DEFAULT_SUPPLY_TARGET_UTILIZATION; } });
29
+ Object.defineProperty(exports, "DEFAULT_WITHDRAWAL_TARGET_UTILIZATION", { enumerable: true, get: function () { return constant_js_1.DEFAULT_WITHDRAWAL_TARGET_UTILIZATION; } });
30
+ Object.defineProperty(exports, "MAX_ABSOLUTE_SHARE_PRICE", { enumerable: true, get: function () { return constant_js_1.MAX_ABSOLUTE_SHARE_PRICE; } });
31
+ Object.defineProperty(exports, "MAX_SLIPPAGE_TOLERANCE", { enumerable: true, get: function () { return constant_js_1.MAX_SLIPPAGE_TOLERANCE; } });
32
+ Object.defineProperty(exports, "MAX_TOKEN_APPROVALS", { enumerable: true, get: function () { return constant_js_1.MAX_TOKEN_APPROVALS; } });
@@ -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,19 +1,43 @@
1
1
  "use strict";
2
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
- if (k2 === undefined) k2 = k;
4
- var desc = Object.getOwnPropertyDescriptor(m, k);
5
- if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
- desc = { enumerable: true, get: function() { return m[k]; } };
7
- }
8
- Object.defineProperty(o, k2, desc);
9
- }) : (function(o, m, k, k2) {
10
- if (k2 === undefined) k2 = k;
11
- o[k2] = m[k];
12
- }));
13
- var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
- for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
- };
16
2
  Object.defineProperty(exports, "__esModule", { value: true });
17
- __exportStar(require("./marketV1/index.js"), exports);
18
- __exportStar(require("./vaultV1/index.js"), exports);
19
- __exportStar(require("./vaultV2/index.js"), exports);
3
+ exports.MorphoVaultV2 = exports.MorphoVaultV1 = exports.ReallocationData = exports.MorphoMarketV1 = exports.WrappedToken = exports.VaultV2MorphoVaultV1Adapter = exports.VaultV2MorphoMarketV1AdapterV2 = exports.VaultV2MorphoMarketV1Adapter = exports.VaultV2Adapter = exports.VaultV2 = exports.VaultUser = exports.VaultToken = exports.VaultMarketPublicAllocatorConfig = exports.VaultMarketConfig = exports.VaultMarketAllocation = exports.VaultConfig = exports.Vault = exports.User = exports.Token = exports.PreLiquidationPosition = exports.PreLiquidationParams = exports.Position = exports.MarketParams = exports.Market = exports.Holding = exports.ExchangeRateWrappedToken = exports.Eip5267Domain = exports.ConstantWrappedToken = exports.AssetBalances = exports.AccrualVaultV2MorphoVaultV1Adapter = exports.AccrualVaultV2MorphoMarketV1AdapterV2 = exports.AccrualVaultV2MorphoMarketV1Adapter = exports.AccrualVaultV2 = exports.AccrualVault = exports.AccrualPosition = void 0;
4
+ var blue_sdk_1 = require("@morpho-org/blue-sdk");
5
+ Object.defineProperty(exports, "AccrualPosition", { enumerable: true, get: function () { return blue_sdk_1.AccrualPosition; } });
6
+ Object.defineProperty(exports, "AccrualVault", { enumerable: true, get: function () { return blue_sdk_1.AccrualVault; } });
7
+ Object.defineProperty(exports, "AccrualVaultV2", { enumerable: true, get: function () { return blue_sdk_1.AccrualVaultV2; } });
8
+ Object.defineProperty(exports, "AccrualVaultV2MorphoMarketV1Adapter", { enumerable: true, get: function () { return blue_sdk_1.AccrualVaultV2MorphoMarketV1Adapter; } });
9
+ Object.defineProperty(exports, "AccrualVaultV2MorphoMarketV1AdapterV2", { enumerable: true, get: function () { return blue_sdk_1.AccrualVaultV2MorphoMarketV1AdapterV2; } });
10
+ Object.defineProperty(exports, "AccrualVaultV2MorphoVaultV1Adapter", { enumerable: true, get: function () { return blue_sdk_1.AccrualVaultV2MorphoVaultV1Adapter; } });
11
+ Object.defineProperty(exports, "AssetBalances", { enumerable: true, get: function () { return blue_sdk_1.AssetBalances; } });
12
+ Object.defineProperty(exports, "ConstantWrappedToken", { enumerable: true, get: function () { return blue_sdk_1.ConstantWrappedToken; } });
13
+ Object.defineProperty(exports, "Eip5267Domain", { enumerable: true, get: function () { return blue_sdk_1.Eip5267Domain; } });
14
+ Object.defineProperty(exports, "ExchangeRateWrappedToken", { enumerable: true, get: function () { return blue_sdk_1.ExchangeRateWrappedToken; } });
15
+ Object.defineProperty(exports, "Holding", { enumerable: true, get: function () { return blue_sdk_1.Holding; } });
16
+ Object.defineProperty(exports, "Market", { enumerable: true, get: function () { return blue_sdk_1.Market; } });
17
+ Object.defineProperty(exports, "MarketParams", { enumerable: true, get: function () { return blue_sdk_1.MarketParams; } });
18
+ Object.defineProperty(exports, "Position", { enumerable: true, get: function () { return blue_sdk_1.Position; } });
19
+ Object.defineProperty(exports, "PreLiquidationParams", { enumerable: true, get: function () { return blue_sdk_1.PreLiquidationParams; } });
20
+ Object.defineProperty(exports, "PreLiquidationPosition", { enumerable: true, get: function () { return blue_sdk_1.PreLiquidationPosition; } });
21
+ Object.defineProperty(exports, "Token", { enumerable: true, get: function () { return blue_sdk_1.Token; } });
22
+ Object.defineProperty(exports, "User", { enumerable: true, get: function () { return blue_sdk_1.User; } });
23
+ Object.defineProperty(exports, "Vault", { enumerable: true, get: function () { return blue_sdk_1.Vault; } });
24
+ Object.defineProperty(exports, "VaultConfig", { enumerable: true, get: function () { return blue_sdk_1.VaultConfig; } });
25
+ Object.defineProperty(exports, "VaultMarketAllocation", { enumerable: true, get: function () { return blue_sdk_1.VaultMarketAllocation; } });
26
+ Object.defineProperty(exports, "VaultMarketConfig", { enumerable: true, get: function () { return blue_sdk_1.VaultMarketConfig; } });
27
+ Object.defineProperty(exports, "VaultMarketPublicAllocatorConfig", { enumerable: true, get: function () { return blue_sdk_1.VaultMarketPublicAllocatorConfig; } });
28
+ Object.defineProperty(exports, "VaultToken", { enumerable: true, get: function () { return blue_sdk_1.VaultToken; } });
29
+ Object.defineProperty(exports, "VaultUser", { enumerable: true, get: function () { return blue_sdk_1.VaultUser; } });
30
+ Object.defineProperty(exports, "VaultV2", { enumerable: true, get: function () { return blue_sdk_1.VaultV2; } });
31
+ Object.defineProperty(exports, "VaultV2Adapter", { enumerable: true, get: function () { return blue_sdk_1.VaultV2Adapter; } });
32
+ Object.defineProperty(exports, "VaultV2MorphoMarketV1Adapter", { enumerable: true, get: function () { return blue_sdk_1.VaultV2MorphoMarketV1Adapter; } });
33
+ Object.defineProperty(exports, "VaultV2MorphoMarketV1AdapterV2", { enumerable: true, get: function () { return blue_sdk_1.VaultV2MorphoMarketV1AdapterV2; } });
34
+ Object.defineProperty(exports, "VaultV2MorphoVaultV1Adapter", { enumerable: true, get: function () { return blue_sdk_1.VaultV2MorphoVaultV1Adapter; } });
35
+ Object.defineProperty(exports, "WrappedToken", { enumerable: true, get: function () { return blue_sdk_1.WrappedToken; } });
36
+ var index_js_1 = require("./marketV1/index.js");
37
+ Object.defineProperty(exports, "MorphoMarketV1", { enumerable: true, get: function () { return index_js_1.MorphoMarketV1; } });
38
+ var reallocationData_js_1 = require("./reallocationData.js");
39
+ Object.defineProperty(exports, "ReallocationData", { enumerable: true, get: function () { return reallocationData_js_1.ReallocationData; } });
40
+ var index_js_2 = require("./vaultV1/index.js");
41
+ Object.defineProperty(exports, "MorphoVaultV1", { enumerable: true, get: function () { return index_js_2.MorphoVaultV1; } });
42
+ var index_js_3 = require("./vaultV2/index.js");
43
+ Object.defineProperty(exports, "MorphoVaultV2", { enumerable: true, get: function () { return index_js_3.MorphoVaultV2; } });
@@ -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
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";
5
+ import { ReallocationData } from "../reallocationData.js";
6
6
  export interface MarketV1Actions {
7
7
  /**
8
8
  * Fetches the latest market data with accrued interest.
@@ -173,7 +173,7 @@ export interface MarketV1Actions {
173
173
  }) => Promise<(Readonly<Transaction<ERC20ApprovalAction>> | Readonly<Transaction<MorphoAuthorizationAction>> | Requirement)[]>;
174
174
  };
175
175
  /**
176
- * Fetches all on-chain data needed to construct a {@link SimulationState}
176
+ * Fetches all on-chain data needed to construct a {@link ReallocationData}
177
177
  * for computing vault reallocations via the public allocator.
178
178
  *
179
179
  * The target market is refetched internally at `block.number` so the
@@ -182,7 +182,7 @@ export interface MarketV1Actions {
182
182
  * inject unnecessary `reallocateTo` actions (and their PublicAllocator
183
183
  * fees) into the resulting bundle.
184
184
  *
185
- * The returned simulation state can be passed to {@link getReallocations}
185
+ * The returned reallocation data can be passed to {@link getReallocations}
186
186
  * to compute the `VaultReallocation[]` array for `borrow()` or
187
187
  * `supplyCollateralBorrow()`.
188
188
  *
@@ -190,12 +190,16 @@ export interface MarketV1Actions {
190
190
  *
191
191
  * @param params.vaultAddresses - Addresses of MetaMorpho vaults that allocate to this market.
192
192
  * @param params.block - The block to fetch data at (number and timestamp).
193
- * @returns A SimulationState populated with all required data.
193
+ * @returns A ReallocationData instance populated with all required data.
194
+ * @throws {ChainIdMismatchError} when the client chain does not match this market.
194
195
  */
195
196
  getReallocationData: (params: {
196
197
  vaultAddresses: readonly Address[];
197
- block: MinimalBlock;
198
- }) => Promise<SimulationState>;
198
+ block: {
199
+ readonly number: bigint;
200
+ readonly timestamp: bigint;
201
+ };
202
+ }) => Promise<ReallocationData>;
199
203
  /**
200
204
  * Computes vault reallocations for a borrow on this market.
201
205
  *
@@ -206,12 +210,17 @@ export interface MarketV1Actions {
206
210
  * @param params.reallocationData - The current on-chain state (from {@link getReallocationData}).
207
211
  * @param params.borrowAmount - The intended borrow amount.
208
212
  * @param params.options - Optional reallocation computation options
209
- * (utilization targets, reallocatable vaults filter, etc.).
213
+ * (timestamp, utilization targets, reallocatable vaults filter, etc.).
214
+ * Pass the fetched block timestamp to compute reallocations at the same block.
210
215
  * @returns Array of vault reallocations ready to pass to `borrow()` or
211
216
  * `supplyCollateralBorrow()`. Empty array if no reallocation is needed.
217
+ * @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.
219
+ * @throws {MissingPublicAllocatorConfigError} when a selected vault is missing its public allocator config.
220
+ * @throws {UnknownReallocationMarketError} when the target market is absent from the reallocation data.
212
221
  */
213
222
  getReallocations: (params: {
214
- reallocationData: SimulationState;
223
+ reallocationData: ReallocationData;
215
224
  borrowAmount: bigint;
216
225
  options?: ReallocationComputeOptions;
217
226
  }) => readonly VaultReallocation[];
@@ -281,12 +290,37 @@ export declare class MorphoMarketV1 implements MarketV1Actions {
281
290
  }) => Promise<(Requirement | Readonly<Transaction<ERC20ApprovalAction>> | Readonly<Transaction<MorphoAuthorizationAction>>)[]>;
282
291
  buildTx: (requirementSignature?: RequirementSignature) => Readonly<Transaction<MarketV1SupplyCollateralBorrowAction>>;
283
292
  };
293
+ /**
294
+ * Fetches all on-chain inputs needed to compute public allocator reallocations.
295
+ *
296
+ * @param params - Reallocation data fetch parameters.
297
+ * @param params.vaultAddresses - Vaults to inspect for source-market liquidity.
298
+ * @param params.block - Block number and timestamp used for consistent RPC reads.
299
+ * @returns Reallocation data ready for {@link getReallocations}.
300
+ * @throws {ChainIdMismatchError} when the client chain does not match this market.
301
+ */
284
302
  getReallocationData({ vaultAddresses, block, }: {
285
303
  vaultAddresses: readonly Address[];
286
- block: MinimalBlock;
287
- }): Promise<SimulationState>;
304
+ block: {
305
+ readonly number: bigint;
306
+ readonly timestamp: bigint;
307
+ };
308
+ }): Promise<ReallocationData>;
309
+ /**
310
+ * Computes public allocator reallocations for a borrow on this market.
311
+ *
312
+ * @param params - Reallocation computation parameters.
313
+ * @param params.reallocationData - State returned by {@link getReallocationData}.
314
+ * @param params.borrowAmount - Borrow amount to test against post-borrow utilization.
315
+ * @param params.options - Optional allocator and utilization options.
316
+ * @returns Vault reallocations ready to pass to `borrow` or `supplyCollateralBorrow`.
317
+ * @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.
319
+ * @throws {MissingPublicAllocatorConfigError} when a selected vault is missing its public allocator config.
320
+ * @throws {UnknownReallocationMarketError} when the target market is absent from the reallocation data.
321
+ */
288
322
  getReallocations({ reallocationData, borrowAmount, options, }: {
289
- reallocationData: SimulationState;
323
+ reallocationData: ReallocationData;
290
324
  borrowAmount: bigint;
291
325
  options?: ReallocationComputeOptions;
292
326
  }): readonly VaultReallocation[];
@@ -4,10 +4,10 @@ exports.MorphoMarketV1 = void 0;
4
4
  const blue_sdk_1 = require("@morpho-org/blue-sdk");
5
5
  const blue_sdk_viem_1 = require("@morpho-org/blue-sdk-viem");
6
6
  const morpho_ts_1 = require("@morpho-org/morpho-ts");
7
- const simulation_sdk_1 = require("@morpho-org/simulation-sdk");
8
7
  const index_js_1 = require("../../actions/index.js");
9
8
  const index_js_2 = require("../../helpers/index.js");
10
9
  const index_js_3 = require("../../types/index.js");
10
+ const reallocationData_js_1 = require("../reallocationData.js");
11
11
  class MorphoMarketV1 {
12
12
  client;
13
13
  marketParams;
@@ -152,6 +152,7 @@ class MorphoMarketV1 {
152
152
  let assets;
153
153
  let shares;
154
154
  let transferAmount;
155
+ let marketForRepay;
155
156
  if (isSharesMode) {
156
157
  (0, index_js_2.validateRepayShares)({
157
158
  positionData,
@@ -160,10 +161,12 @@ class MorphoMarketV1 {
160
161
  });
161
162
  assets = 0n;
162
163
  shares = params.shares;
163
- // Add slippage buffer to cover interest accrued between tx construction and execution.
164
- // Without this, the on-chain repay amount may exceed the pre-transferred ERC20 amount.
165
- const baseTransferAmount = positionData.market.toBorrowAssets(shares, "Up");
166
- transferAmount = blue_sdk_1.MathLib.wMulUp(baseTransferAmount, blue_sdk_1.MathLib.WAD + slippageTolerance);
164
+ // 2h forward accrual upper-bounds the on-chain repay price; bundle
165
+ // skims residual back to the receiver.
166
+ const accrualTimestamp = blue_sdk_1.MathLib.max(morpho_ts_1.Time.timestamp(), positionData.market.lastUpdate) +
167
+ morpho_ts_1.Time.s.from.h(2n);
168
+ marketForRepay = positionData.market.accrueInterest(accrualTimestamp);
169
+ transferAmount = marketForRepay.toBorrowAssets(shares, "Up");
167
170
  }
168
171
  else {
169
172
  (0, index_js_2.validateRepayAmount)({
@@ -174,11 +177,12 @@ class MorphoMarketV1 {
174
177
  assets = params.assets;
175
178
  shares = 0n;
176
179
  transferAmount = params.assets;
180
+ marketForRepay = positionData.market;
177
181
  }
178
182
  const maxSharePrice = (0, index_js_2.computeMaxRepaySharePrice)({
179
183
  repayAssets: assets,
180
184
  repayShares: shares,
181
- market: positionData.market,
185
+ market: marketForRepay,
182
186
  slippageTolerance,
183
187
  });
184
188
  return {
@@ -281,6 +285,11 @@ class MorphoMarketV1 {
281
285
  let assets;
282
286
  let shares;
283
287
  let transferAmount;
288
+ let marketForRepay;
289
+ // 2h forward accrual upper-bounds the on-chain repay price (shares
290
+ // mode) and the post-repay health check; bundle skims residual back.
291
+ const accrualTimestamp = blue_sdk_1.MathLib.max(morpho_ts_1.Time.timestamp(), positionData.market.lastUpdate) +
292
+ morpho_ts_1.Time.s.from.h(2n);
284
293
  if (isSharesMode) {
285
294
  (0, index_js_2.validateRepayShares)({
286
295
  positionData,
@@ -289,8 +298,8 @@ class MorphoMarketV1 {
289
298
  });
290
299
  assets = 0n;
291
300
  shares = params.shares;
292
- const baseTransferAmount = positionData.market.toBorrowAssets(shares, "Up");
293
- transferAmount = blue_sdk_1.MathLib.wMulUp(baseTransferAmount, blue_sdk_1.MathLib.WAD + slippageTolerance);
301
+ marketForRepay = positionData.market.accrueInterest(accrualTimestamp);
302
+ transferAmount = marketForRepay.toBorrowAssets(shares, "Up");
294
303
  }
295
304
  else {
296
305
  (0, index_js_2.validateRepayAmount)({
@@ -301,6 +310,7 @@ class MorphoMarketV1 {
301
310
  assets = params.assets;
302
311
  shares = 0n;
303
312
  transferAmount = params.assets;
313
+ marketForRepay = positionData.market;
304
314
  }
305
315
  if (withdrawAmount > positionData.collateral) {
306
316
  throw new index_js_3.WithdrawExceedsCollateralError({
@@ -309,9 +319,6 @@ class MorphoMarketV1 {
309
319
  market: positionData.marketId,
310
320
  });
311
321
  }
312
- // +10 min accrual buffer: residual debt grows between build and execute.
313
- const accrualTimestamp = blue_sdk_1.MathLib.max(morpho_ts_1.Time.timestamp(), positionData.market.lastUpdate) +
314
- morpho_ts_1.Time.s.from.min(10n);
315
322
  const { position: positionAfterRepay } = positionData.repay(assets, shares, accrualTimestamp);
316
323
  (0, index_js_2.validatePositionHealthAfterWithdraw)({
317
324
  positionData: positionAfterRepay,
@@ -322,7 +329,7 @@ class MorphoMarketV1 {
322
329
  const maxSharePrice = (0, index_js_2.computeMaxRepaySharePrice)({
323
330
  repayAssets: assets,
324
331
  repayShares: shares,
325
- market: positionData.market,
332
+ market: marketForRepay,
326
333
  slippageTolerance,
327
334
  });
328
335
  return {
@@ -440,6 +447,15 @@ class MorphoMarketV1 {
440
447
  }),
441
448
  };
442
449
  }
450
+ /**
451
+ * Fetches all on-chain inputs needed to compute public allocator reallocations.
452
+ *
453
+ * @param params - Reallocation data fetch parameters.
454
+ * @param params.vaultAddresses - Vaults to inspect for source-market liquidity.
455
+ * @param params.block - Block number and timestamp used for consistent RPC reads.
456
+ * @returns Reallocation data ready for {@link getReallocations}.
457
+ * @throws {ChainIdMismatchError} when the client chain does not match this market.
458
+ */
443
459
  async getReallocationData({ vaultAddresses, block, }) {
444
460
  (0, index_js_2.validateChainId)(this.client.viemClient.chain?.id, this.chainId);
445
461
  const client = this.client.viemClient;
@@ -471,8 +487,7 @@ class MorphoMarketV1 {
471
487
  }
472
488
  // Phase 2: Fetch all source markets, vault configs, and positions in parallel.
473
489
  const sourceMarketIds = [...allMarketIds].filter((mid) => mid !== targetMarketId);
474
- const loanToken = targetMarket.params.loanToken;
475
- const [markets, configs, positions, holdings] = await Promise.all([
490
+ const [markets, configs, positions] = await Promise.all([
476
491
  Promise.all(sourceMarketIds.map((mid) => (0, blue_sdk_viem_1.fetchMarket)(mid, client, fetchParams))),
477
492
  Promise.all(vaultMarketPairs.map(({ vault, marketId: mid }) => (0, blue_sdk_viem_1.fetchVaultMarketConfig)(vault, mid, client, fetchParams).then((config) => ({ vault, mid, config })))),
478
493
  Promise.all(vaultMarketPairs.map(({ vault, marketId: mid }) => (0, blue_sdk_viem_1.fetchPosition)(vault, mid, client, fetchParams).then((position) => ({
@@ -480,9 +495,8 @@ class MorphoMarketV1 {
480
495
  mid,
481
496
  position,
482
497
  })))),
483
- Promise.all(vaultAddresses.map((addr) => (0, blue_sdk_viem_1.fetchHolding)(addr, loanToken, client, fetchParams))),
484
498
  ]);
485
- // Assemble records for SimulationState.
499
+ // Assemble records for ReallocationData.
486
500
  const marketsRecord = {
487
501
  [targetMarketId]: targetMarket,
488
502
  };
@@ -501,21 +515,29 @@ class MorphoMarketV1 {
501
515
  for (const { vault, mid, position } of positions) {
502
516
  (positionsRecord[vault] ??= {})[mid] = position;
503
517
  }
504
- const holdingsRecord = {};
505
- for (const holding of holdings) {
506
- (holdingsRecord[holding.user] ??= {})[holding.token] = holding;
507
- }
508
- return new simulation_sdk_1.SimulationState({
518
+ return new reallocationData_js_1.ReallocationData({
509
519
  chainId: this.chainId,
510
- block,
511
520
  markets: marketsRecord,
512
521
  vaults: vaultsRecord,
513
522
  vaultMarketConfigs: vaultMarketConfigsRecord,
514
523
  positions: positionsRecord,
515
- holdings: holdingsRecord,
516
524
  });
517
525
  }
526
+ /**
527
+ * Computes public allocator reallocations for a borrow on this market.
528
+ *
529
+ * @param params - Reallocation computation parameters.
530
+ * @param params.reallocationData - State returned by {@link getReallocationData}.
531
+ * @param params.borrowAmount - Borrow amount to test against post-borrow utilization.
532
+ * @param params.options - Optional allocator and utilization options.
533
+ * @returns Vault reallocations ready to pass to `borrow` or `supplyCollateralBorrow`.
534
+ * @throws {ChainIdMismatchError} when `reallocationData` belongs to a different chain than this market.
535
+ * @throws {InsufficientSharedLiquidityError} when shared liquidity cannot cover the borrow shortfall on the target market.
536
+ * @throws {MissingPublicAllocatorConfigError} when a selected vault is missing its public allocator config.
537
+ * @throws {UnknownReallocationMarketError} when the target market is absent from the reallocation data.
538
+ */
518
539
  getReallocations({ reallocationData, borrowAmount, options, }) {
540
+ (0, index_js_2.validateChainId)(reallocationData.chainId, this.chainId);
519
541
  return (0, index_js_2.computeReallocations)({
520
542
  reallocationData,
521
543
  marketId: this.marketParams.id,