@morpho-org/morpho-sdk 5.4.1 → 5.6.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 (140) hide show
  1. package/README.md +23 -7
  2. package/lib/cjs/abis.d.ts +314 -1
  3. package/lib/cjs/abis.js +169 -1
  4. package/lib/cjs/actions/blue/borrow.d.ts +21 -15
  5. package/lib/cjs/actions/blue/borrow.js +25 -18
  6. package/lib/cjs/actions/blue/buildAssetFundingActions.d.ts +1 -1
  7. package/lib/cjs/actions/blue/buildAssetFundingActions.js +1 -1
  8. package/lib/cjs/actions/blue/buildReallocationActions.d.ts +62 -19
  9. package/lib/cjs/actions/blue/buildReallocationActions.js +123 -27
  10. package/lib/cjs/actions/blue/refinance.d.ts +14 -7
  11. package/lib/cjs/actions/blue/refinance.js +18 -10
  12. package/lib/cjs/actions/blue/supplyCollateralBorrow.d.ts +28 -19
  13. package/lib/cjs/actions/blue/supplyCollateralBorrow.js +39 -23
  14. package/lib/cjs/actions/blue/withdraw.d.ts +20 -13
  15. package/lib/cjs/actions/blue/withdraw.js +23 -18
  16. package/lib/cjs/actions/requirements/encode/encodeErc20Approval.d.ts +1 -1
  17. package/lib/cjs/actions/requirements/encode/encodeErc20Approval.js +9 -2
  18. package/lib/cjs/actions/requirements/encode/encodeVaultSharesPermit.d.ts +64 -0
  19. package/lib/cjs/actions/requirements/encode/encodeVaultSharesPermit.js +131 -0
  20. package/lib/cjs/actions/requirements/encode/index.d.ts +1 -0
  21. package/lib/cjs/actions/requirements/encode/index.js +1 -0
  22. package/lib/cjs/actions/requirements/getRequirementsApproval.d.ts +3 -2
  23. package/lib/cjs/actions/requirements/getRequirementsApproval.js +5 -3
  24. package/lib/cjs/actions/signatures/getVaultExitBundlesV1PermitStruct.d.ts +52 -0
  25. package/lib/cjs/actions/signatures/getVaultExitBundlesV1PermitStruct.js +91 -0
  26. package/lib/cjs/actions/signatures/index.d.ts +1 -0
  27. package/lib/cjs/actions/signatures/index.js +1 -0
  28. package/lib/cjs/actions/vaultV1/inKindRedeem.d.ts +54 -0
  29. package/lib/cjs/actions/vaultV1/inKindRedeem.js +96 -0
  30. package/lib/cjs/actions/vaultV1/index.d.ts +1 -0
  31. package/lib/cjs/actions/vaultV1/index.js +1 -0
  32. package/lib/cjs/actions/vaultV2/inKindRedeem.d.ts +56 -0
  33. package/lib/cjs/actions/vaultV2/inKindRedeem.js +97 -0
  34. package/lib/cjs/actions/vaultV2/index.d.ts +1 -0
  35. package/lib/cjs/actions/vaultV2/index.js +1 -0
  36. package/lib/cjs/bundler/actions.d.ts +118 -2
  37. package/lib/cjs/bundler/actions.js +212 -6
  38. package/lib/cjs/bundler/types.d.ts +20 -0
  39. package/lib/cjs/constants.d.ts +1 -1
  40. package/lib/cjs/constants.js +3 -1
  41. package/lib/cjs/entities/blue/blue.d.ts +365 -76
  42. package/lib/cjs/entities/blue/blue.js +285 -52
  43. package/lib/cjs/entities/index.d.ts +2 -1
  44. package/lib/cjs/entities/index.js +6 -3
  45. package/lib/cjs/entities/vaultV1/vaultV1.d.ts +82 -4
  46. package/lib/cjs/entities/vaultV1/vaultV1.js +164 -0
  47. package/lib/cjs/entities/{reallocationData.d.ts → vaultV1ReallocationData.d.ts} +41 -17
  48. package/lib/cjs/entities/{reallocationData.js → vaultV1ReallocationData.js} +30 -18
  49. package/lib/cjs/entities/vaultV2/vaultV2.d.ts +89 -3
  50. package/lib/cjs/entities/vaultV2/vaultV2.js +181 -0
  51. package/lib/cjs/entities/vaultV2BlueReallocationData.d.ts +511 -0
  52. package/lib/cjs/entities/vaultV2BlueReallocationData.js +1311 -0
  53. package/lib/{esm/helpers/computeReallocations.d.ts → cjs/helpers/computeVaultV1Reallocations.d.ts} +14 -8
  54. package/lib/cjs/helpers/{computeReallocations.js → computeVaultV1Reallocations.js} +27 -13
  55. package/lib/cjs/helpers/constant.d.ts +5 -3
  56. package/lib/cjs/helpers/constant.js +6 -4
  57. package/lib/cjs/helpers/index.d.ts +3 -2
  58. package/lib/cjs/helpers/index.js +8 -3
  59. package/lib/cjs/helpers/previewVaultV2InKindRedeem.d.ts +49 -0
  60. package/lib/cjs/helpers/previewVaultV2InKindRedeem.js +73 -0
  61. package/lib/cjs/helpers/validate.d.ts +31 -15
  62. package/lib/cjs/helpers/validate.js +140 -27
  63. package/lib/cjs/helpers/validateRequirementSpender.d.ts +1 -1
  64. package/lib/cjs/helpers/validateRequirementSpender.js +2 -1
  65. package/lib/cjs/types/action.d.ts +33 -1
  66. package/lib/cjs/types/error.d.ts +363 -5
  67. package/lib/cjs/types/error.js +455 -6
  68. package/lib/cjs/types/sharedLiquidity.d.ts +72 -8
  69. package/lib/cjs/utils.d.ts +2 -2
  70. package/lib/cjs/utils.js +6 -4
  71. package/lib/esm/abis.d.ts +314 -1
  72. package/lib/esm/abis.js +167 -1
  73. package/lib/esm/actions/blue/borrow.d.ts +21 -15
  74. package/lib/esm/actions/blue/borrow.js +26 -19
  75. package/lib/esm/actions/blue/buildAssetFundingActions.d.ts +1 -1
  76. package/lib/esm/actions/blue/buildAssetFundingActions.js +1 -1
  77. package/lib/esm/actions/blue/buildReallocationActions.d.ts +62 -19
  78. package/lib/esm/actions/blue/buildReallocationActions.js +119 -25
  79. package/lib/esm/actions/blue/refinance.d.ts +14 -7
  80. package/lib/esm/actions/blue/refinance.js +19 -11
  81. package/lib/esm/actions/blue/supplyCollateralBorrow.d.ts +28 -19
  82. package/lib/esm/actions/blue/supplyCollateralBorrow.js +40 -24
  83. package/lib/esm/actions/blue/withdraw.d.ts +20 -13
  84. package/lib/esm/actions/blue/withdraw.js +24 -19
  85. package/lib/esm/actions/requirements/encode/encodeErc20Approval.d.ts +1 -1
  86. package/lib/esm/actions/requirements/encode/encodeErc20Approval.js +9 -2
  87. package/lib/esm/actions/requirements/encode/encodeVaultSharesPermit.d.ts +64 -0
  88. package/lib/esm/actions/requirements/encode/encodeVaultSharesPermit.js +127 -0
  89. package/lib/esm/actions/requirements/encode/index.d.ts +1 -0
  90. package/lib/esm/actions/requirements/encode/index.js +1 -0
  91. package/lib/esm/actions/requirements/getRequirementsApproval.d.ts +3 -2
  92. package/lib/esm/actions/requirements/getRequirementsApproval.js +5 -3
  93. package/lib/esm/actions/signatures/getVaultExitBundlesV1PermitStruct.d.ts +52 -0
  94. package/lib/esm/actions/signatures/getVaultExitBundlesV1PermitStruct.js +87 -0
  95. package/lib/esm/actions/signatures/index.d.ts +1 -0
  96. package/lib/esm/actions/signatures/index.js +1 -0
  97. package/lib/esm/actions/vaultV1/inKindRedeem.d.ts +54 -0
  98. package/lib/esm/actions/vaultV1/inKindRedeem.js +92 -0
  99. package/lib/esm/actions/vaultV1/index.d.ts +1 -0
  100. package/lib/esm/actions/vaultV1/index.js +1 -0
  101. package/lib/esm/actions/vaultV2/inKindRedeem.d.ts +56 -0
  102. package/lib/esm/actions/vaultV2/inKindRedeem.js +93 -0
  103. package/lib/esm/actions/vaultV2/index.d.ts +1 -0
  104. package/lib/esm/actions/vaultV2/index.js +1 -0
  105. package/lib/esm/bundler/actions.d.ts +118 -2
  106. package/lib/esm/bundler/actions.js +215 -9
  107. package/lib/esm/bundler/types.d.ts +20 -0
  108. package/lib/esm/constants.d.ts +1 -1
  109. package/lib/esm/constants.js +1 -1
  110. package/lib/esm/entities/blue/blue.d.ts +362 -73
  111. package/lib/esm/entities/blue/blue.js +288 -55
  112. package/lib/esm/entities/index.d.ts +2 -1
  113. package/lib/esm/entities/index.js +2 -1
  114. package/lib/esm/entities/vaultV1/vaultV1.d.ts +80 -2
  115. package/lib/esm/entities/vaultV1/vaultV1.js +170 -6
  116. package/lib/esm/entities/{reallocationData.d.ts → vaultV1ReallocationData.d.ts} +41 -17
  117. package/lib/esm/entities/{reallocationData.js → vaultV1ReallocationData.js} +33 -16
  118. package/lib/esm/entities/vaultV2/vaultV2.d.ts +88 -2
  119. package/lib/esm/entities/vaultV2/vaultV2.js +187 -6
  120. package/lib/esm/entities/vaultV2BlueReallocationData.d.ts +511 -0
  121. package/lib/esm/entities/vaultV2BlueReallocationData.js +1307 -0
  122. package/lib/{cjs/helpers/computeReallocations.d.ts → esm/helpers/computeVaultV1Reallocations.d.ts} +14 -8
  123. package/lib/esm/helpers/{computeReallocations.js → computeVaultV1Reallocations.js} +25 -11
  124. package/lib/esm/helpers/constant.d.ts +5 -3
  125. package/lib/esm/helpers/constant.js +5 -3
  126. package/lib/esm/helpers/index.d.ts +3 -2
  127. package/lib/esm/helpers/index.js +3 -2
  128. package/lib/esm/helpers/previewVaultV2InKindRedeem.d.ts +49 -0
  129. package/lib/esm/helpers/previewVaultV2InKindRedeem.js +70 -0
  130. package/lib/esm/helpers/validate.d.ts +31 -15
  131. package/lib/esm/helpers/validate.js +141 -30
  132. package/lib/esm/helpers/validateRequirementSpender.d.ts +1 -1
  133. package/lib/esm/helpers/validateRequirementSpender.js +2 -1
  134. package/lib/esm/types/action.d.ts +33 -1
  135. package/lib/esm/types/error.d.ts +363 -5
  136. package/lib/esm/types/error.js +428 -4
  137. package/lib/esm/types/sharedLiquidity.d.ts +72 -8
  138. package/lib/esm/utils.d.ts +2 -2
  139. package/lib/esm/utils.js +2 -2
  140. package/package.json +9 -11
@@ -0,0 +1,511 @@
1
+ import { AccrualVaultV2, AccrualVaultV2MorphoMarketV1AdapterV2, type IAccrualVaultV2Adapter, type IVaultV2Allocation, type IVaultV2BlueMarketPublicAllocatorConfig, type IVaultV2BluePublicAllocatorConfig, Market, type MarketId, VaultV2BlueMarketPublicAllocatorConfig, VaultV2BluePublicAllocatorConfig } from "@morpho-org/blue-sdk";
2
+ import { type Address, type Hash } from "viem";
3
+ import type { VaultV2BluePublicAllocatorOptions, VaultV2BlueReallocation } from "../types/index.js";
4
+ type ReadonlyMarketSnapshot = Readonly<Market>;
5
+ type ReadonlyAdapterSnapshot = Readonly<IAccrualVaultV2Adapter>;
6
+ type ReadonlyMarketAdapterSnapshot = Readonly<Omit<AccrualVaultV2MorphoMarketV1AdapterV2, "marketIds" | "supplyShares" | "markets">> & {
7
+ readonly marketIds: readonly MarketId[];
8
+ readonly supplyShares: Readonly<Record<MarketId, bigint>>;
9
+ readonly markets: readonly ReadonlyMarketSnapshot[];
10
+ };
11
+ type ReadonlyVaultSnapshot = Readonly<Omit<AccrualVaultV2, "adapters" | "liquidityAllocations" | "accrualLiquidityAdapter" | "accrualAdapters" | "forceDeallocatePenalties">> & {
12
+ readonly adapters: readonly Address[];
13
+ readonly liquidityAllocations: readonly Readonly<IVaultV2Allocation>[] | undefined;
14
+ readonly accrualLiquidityAdapter: ReadonlyAdapterSnapshot | undefined;
15
+ readonly accrualAdapters: readonly ReadonlyAdapterSnapshot[];
16
+ readonly forceDeallocatePenalties: Readonly<Record<Address, bigint>>;
17
+ };
18
+ /** Input state required to simulate Vault V2 BluePublicAllocator reallocations. */
19
+ export interface InputVaultV2BlueReallocationData {
20
+ /** Chain id associated with the fetched state. */
21
+ readonly chainId: number;
22
+ /** Markets indexed by market id. */
23
+ readonly markets?: Readonly<Record<MarketId, ReadonlyMarketSnapshot | undefined>>;
24
+ /** Accrued Vault V2 entities indexed by vault address. */
25
+ readonly vaults?: Readonly<Record<Address, ReadonlyVaultSnapshot | undefined>>;
26
+ /** Vault cap state indexed by vault address and derived allocation id. */
27
+ readonly allocations?: Readonly<Record<Address, Readonly<Record<Hash, IVaultV2Allocation | undefined>> | undefined>>;
28
+ /** Vault-wide BluePublicAllocator configuration indexed by vault address. */
29
+ readonly publicAllocatorConfigs?: Readonly<Record<Address, IVaultV2BluePublicAllocatorConfig | undefined>>;
30
+ /**
31
+ * BluePublicAllocator-active adapters indexed by vault address.
32
+ * Arrays, readonly arrays, sets, and other iterables are copied to sets
33
+ * without changing address casing.
34
+ */
35
+ readonly activeAdapters?: Readonly<Record<Address, Iterable<Address> | undefined>>;
36
+ /** Adapter-market BluePublicAllocator configuration indexed by vault and `adapterMarketCapId`. */
37
+ readonly marketPublicAllocatorConfigs?: Readonly<Record<Address, Readonly<Record<Hash, IVaultV2BlueMarketPublicAllocatorConfig | undefined>> | undefined>>;
38
+ }
39
+ /**
40
+ * Immutable-by-convention state container for Vault V2 BluePublicAllocator simulations.
41
+ *
42
+ * Constructor inputs are cloned. Every simulated reallocation returns a new
43
+ * instance. Planning keeps the transaction-scoped `firstTotalAssets`
44
+ * denominator outside the durable snapshot while applying reallocations in
45
+ * contract order. Penalty donations update simulated vault accounting but are
46
+ * excluded from same-plan idle liquidity so round-up dust cannot create
47
+ * self-replenishing candidates.
48
+ * Address keys and values retain their supplied casing; lookups compare them
49
+ * case-insensitively.
50
+ *
51
+ * @example
52
+ * ```ts
53
+ * import { markets } from "@morpho-org/morpho-test";
54
+ * import { createPublicClient, http } from "viem";
55
+ * import { mainnet } from "viem/chains";
56
+ * import { morphoViemExtension } from "@morpho-org/morpho-sdk";
57
+ * import type { VaultV2BlueReallocationData } from "@morpho-org/morpho-sdk/entities";
58
+ *
59
+ * const client = createPublicClient({ chain: mainnet, transport: http() })
60
+ * .extend(morphoViemExtension());
61
+ * const marketParams = markets[mainnet.id].usdc_wbtc;
62
+ * const market = client.morpho.blue(marketParams, mainnet.id);
63
+ * const block = await client.getBlock();
64
+ * const keyrockUsdcVaultV2 = "0x04422053aDDbc9bB2759b248B574e3FCA76Bc145";
65
+ * const data: VaultV2BlueReallocationData =
66
+ * await market.getVaultV2BlueReallocationData({
67
+ * vaultAddresses: [keyrockUsdcVaultV2],
68
+ * block: { number: block.number, timestamp: block.timestamp },
69
+ * });
70
+ * ```
71
+ */
72
+ export declare class VaultV2BlueReallocationData implements InputVaultV2BlueReallocationData {
73
+ /** Mutable market state used only by cloned simulation transitions. */
74
+ private readonly mutableMarkets;
75
+ /** Mutable vault state used only by cloned simulation transitions. */
76
+ private readonly mutableVaults;
77
+ /** Mutable allocation state used only by cloned simulation transitions. */
78
+ private readonly mutableAllocations;
79
+ /** Chain id associated with this snapshot. */
80
+ readonly chainId: number;
81
+ /** Markets indexed by market id. */
82
+ readonly markets: Readonly<Record<MarketId, ReadonlyMarketSnapshot | undefined>>;
83
+ /** Vault V2 entities indexed by address. */
84
+ readonly vaults: Readonly<Record<Address, ReadonlyVaultSnapshot | undefined>>;
85
+ /** Vault cap state indexed by vault and derived allocation id. */
86
+ readonly allocations: Readonly<Record<Address, Readonly<Record<Hash, Readonly<IVaultV2Allocation> | undefined>> | undefined>>;
87
+ /** Vault-wide allocator configuration indexed by vault. */
88
+ readonly publicAllocatorConfigs: Readonly<Record<Address, VaultV2BluePublicAllocatorConfig | undefined>>;
89
+ /** BluePublicAllocator-active adapters indexed by vault address, preserving vault and adapter casing. */
90
+ readonly activeAdapters: Readonly<Record<Address, ReadonlySet<Address> | undefined>>;
91
+ /** Adapter-market allocator configuration indexed by vault and market-params id. */
92
+ readonly marketPublicAllocatorConfigs: Readonly<Record<Address, Readonly<Record<Hash, VaultV2BlueMarketPublicAllocatorConfig | undefined>> | undefined>>;
93
+ /**
94
+ * Creates a cloned Vault V2 reallocation snapshot.
95
+ *
96
+ * @param input - State fetched at one consistent block.
97
+ * @throws {UnsupportedVaultV2AdapterError} when a vault contains an unsupported adapter type.
98
+ */
99
+ constructor(input: InputVaultV2BlueReallocationData);
100
+ /**
101
+ * Clones the complete simulation snapshot.
102
+ *
103
+ * @returns A deep clone of this simulation state.
104
+ * @example
105
+ * ```ts
106
+ * import { markets } from "@morpho-org/morpho-test";
107
+ * import { createPublicClient, http } from "viem";
108
+ * import { mainnet } from "viem/chains";
109
+ * import { morphoViemExtension } from "@morpho-org/morpho-sdk";
110
+ * import type { VaultV2BlueReallocationData } from "@morpho-org/morpho-sdk/entities";
111
+ *
112
+ * const client = createPublicClient({ chain: mainnet, transport: http() })
113
+ * .extend(morphoViemExtension());
114
+ * const marketParams = markets[mainnet.id].usdc_wbtc;
115
+ * const market = client.morpho.blue(marketParams, mainnet.id);
116
+ * const block = await client.getBlock();
117
+ * const keyrockUsdcVaultV2 = "0x04422053aDDbc9bB2759b248B574e3FCA76Bc145";
118
+ * const data = await market.getVaultV2BlueReallocationData({
119
+ * vaultAddresses: [keyrockUsdcVaultV2],
120
+ * block: { number: block.number, timestamp: block.timestamp },
121
+ * });
122
+ * const cloned: VaultV2BlueReallocationData = data.clone();
123
+ * ```
124
+ */
125
+ clone(): VaultV2BlueReallocationData;
126
+ /**
127
+ * Gets a market from this snapshot.
128
+ *
129
+ * @param marketId - Market id to read.
130
+ * @returns The market state.
131
+ * @throws {UnknownReallocationMarketError} when the market is absent.
132
+ * @example
133
+ * ```ts
134
+ * import { markets } from "@morpho-org/morpho-test";
135
+ * import { createPublicClient, http } from "viem";
136
+ * import { mainnet } from "viem/chains";
137
+ * import { morphoViemExtension } from "@morpho-org/morpho-sdk";
138
+ * import type { VaultV2BlueReallocationData } from "@morpho-org/morpho-sdk/entities";
139
+ *
140
+ * const client = createPublicClient({ chain: mainnet, transport: http() })
141
+ * .extend(morphoViemExtension());
142
+ * const marketParams = markets[mainnet.id].usdc_wbtc;
143
+ * const market = client.morpho.blue(marketParams, mainnet.id);
144
+ * const block = await client.getBlock();
145
+ * const keyrockUsdcVaultV2 = "0x04422053aDDbc9bB2759b248B574e3FCA76Bc145";
146
+ * const data = await market.getVaultV2BlueReallocationData({
147
+ * vaultAddresses: [keyrockUsdcVaultV2],
148
+ * block: { number: block.number, timestamp: block.timestamp },
149
+ * });
150
+ * const targetMarket: ReturnType<
151
+ * VaultV2BlueReallocationData["getMarket"]
152
+ * > = data.getMarket(marketParams.id);
153
+ * ```
154
+ */
155
+ getMarket(marketId: MarketId): ReadonlyMarketSnapshot;
156
+ /**
157
+ * Gets a Vault V2 from this snapshot.
158
+ *
159
+ * @param vault - Vault V2 address.
160
+ * @returns The accrued Vault V2 state.
161
+ * @throws {UnknownReallocationVaultError} when the vault is absent.
162
+ * @example
163
+ * ```ts
164
+ * import { markets } from "@morpho-org/morpho-test";
165
+ * import { createPublicClient, http } from "viem";
166
+ * import { mainnet } from "viem/chains";
167
+ * import { morphoViemExtension } from "@morpho-org/morpho-sdk";
168
+ * import type { VaultV2BlueReallocationData } from "@morpho-org/morpho-sdk/entities";
169
+ *
170
+ * const client = createPublicClient({ chain: mainnet, transport: http() })
171
+ * .extend(morphoViemExtension());
172
+ * const marketParams = markets[mainnet.id].usdc_wbtc;
173
+ * const market = client.morpho.blue(marketParams, mainnet.id);
174
+ * const block = await client.getBlock();
175
+ * const keyrockUsdcVaultV2 = "0x04422053aDDbc9bB2759b248B574e3FCA76Bc145";
176
+ * const data = await market.getVaultV2BlueReallocationData({
177
+ * vaultAddresses: [keyrockUsdcVaultV2],
178
+ * block: { number: block.number, timestamp: block.timestamp },
179
+ * });
180
+ * const vault: ReturnType<VaultV2BlueReallocationData["getVault"]> =
181
+ * data.getVault(keyrockUsdcVaultV2);
182
+ * ```
183
+ */
184
+ getVault(vault: Address): ReadonlyVaultSnapshot;
185
+ private getMutableVault;
186
+ /**
187
+ * Gets one Vault V2 allocation record.
188
+ *
189
+ * @param vault - Vault V2 address.
190
+ * @param id - Derived allocation id.
191
+ * @returns The allocation and cap state.
192
+ * @throws {UnknownReallocationAllocationError} when the record is absent.
193
+ * @example
194
+ * ```ts
195
+ * import { markets } from "@morpho-org/morpho-test";
196
+ * import { createPublicClient, http, type Hash } from "viem";
197
+ * import { mainnet } from "viem/chains";
198
+ * import { morphoViemExtension } from "@morpho-org/morpho-sdk";
199
+ * import type { VaultV2BlueReallocationData } from "@morpho-org/morpho-sdk/entities";
200
+ *
201
+ * const client = createPublicClient({ chain: mainnet, transport: http() })
202
+ * .extend(morphoViemExtension());
203
+ * const marketParams = markets[mainnet.id].usdc_wbtc;
204
+ * const market = client.morpho.blue(marketParams, mainnet.id);
205
+ * const block = await client.getBlock();
206
+ * const keyrockUsdcVaultV2 = "0x04422053aDDbc9bB2759b248B574e3FCA76Bc145";
207
+ * const data = await market.getVaultV2BlueReallocationData({
208
+ * vaultAddresses: [keyrockUsdcVaultV2],
209
+ * block: { number: block.number, timestamp: block.timestamp },
210
+ * });
211
+ * const [allocationId] = Object.keys(
212
+ * data.allocations[keyrockUsdcVaultV2] ?? {},
213
+ * ) as Hash[];
214
+ * const allocation: ReturnType<
215
+ * VaultV2BlueReallocationData["getAllocation"]
216
+ * > = data.getAllocation(keyrockUsdcVaultV2, allocationId!);
217
+ * ```
218
+ */
219
+ getAllocation(vault: Address, id: Hash): Readonly<IVaultV2Allocation>;
220
+ /**
221
+ * Gets one vault-wide BluePublicAllocator configuration.
222
+ *
223
+ * @param vault - Vault V2 address.
224
+ * @returns The vault-wide allocator configuration.
225
+ * @throws {UnknownReallocationPublicAllocatorConfigError} when it is absent.
226
+ * @example
227
+ * ```ts
228
+ * import { markets } from "@morpho-org/morpho-test";
229
+ * import { createPublicClient, http } from "viem";
230
+ * import { mainnet } from "viem/chains";
231
+ * import { morphoViemExtension } from "@morpho-org/morpho-sdk";
232
+ * import type { VaultV2BlueReallocationData } from "@morpho-org/morpho-sdk/entities";
233
+ *
234
+ * const client = createPublicClient({ chain: mainnet, transport: http() })
235
+ * .extend(morphoViemExtension());
236
+ * const marketParams = markets[mainnet.id].usdc_wbtc;
237
+ * const market = client.morpho.blue(marketParams, mainnet.id);
238
+ * const block = await client.getBlock();
239
+ * const keyrockUsdcVaultV2 = "0x04422053aDDbc9bB2759b248B574e3FCA76Bc145";
240
+ * const data = await market.getVaultV2BlueReallocationData({
241
+ * vaultAddresses: [keyrockUsdcVaultV2],
242
+ * block: { number: block.number, timestamp: block.timestamp },
243
+ * });
244
+ * const config: ReturnType<
245
+ * VaultV2BlueReallocationData["getPublicAllocatorConfig"]
246
+ * > = data.getPublicAllocatorConfig(keyrockUsdcVaultV2);
247
+ * ```
248
+ */
249
+ getPublicAllocatorConfig(vault: Address): VaultV2BluePublicAllocatorConfig;
250
+ /**
251
+ * Gets fetched allocator authorization state, including an explicit absent value.
252
+ *
253
+ * @param vault - Vault V2 address.
254
+ * @returns The allocator config, or `undefined` when the fetched vault has not authorized it.
255
+ * @throws {UnknownReallocationPublicAllocatorConfigError} when the fetch state is absent.
256
+ */
257
+ private getOptionalPublicAllocatorConfig;
258
+ /**
259
+ * Gets the BluePublicAllocator-active adapters for a Vault V2.
260
+ *
261
+ * @param vault - Vault V2 address.
262
+ * @returns The active adapter addresses in their supplied casing, or an empty set when none are active.
263
+ * @throws {UnknownReallocationActiveAdaptersError} when the active-adapter state is absent.
264
+ * @example
265
+ * ```ts
266
+ * import { markets } from "@morpho-org/morpho-test";
267
+ * import { createPublicClient, http, type Address } from "viem";
268
+ * import { mainnet } from "viem/chains";
269
+ * import { morphoViemExtension } from "@morpho-org/morpho-sdk";
270
+ *
271
+ * const client = createPublicClient({ chain: mainnet, transport: http() })
272
+ * .extend(morphoViemExtension());
273
+ * const marketParams = markets[mainnet.id].usdc_wbtc;
274
+ * const market = client.morpho.blue(marketParams, mainnet.id);
275
+ * const block = await client.getBlock();
276
+ * const keyrockUsdcVaultV2 = "0x04422053aDDbc9bB2759b248B574e3FCA76Bc145";
277
+ * const data = await market.getVaultV2BlueReallocationData({
278
+ * vaultAddresses: [keyrockUsdcVaultV2],
279
+ * block: { number: block.number, timestamp: block.timestamp },
280
+ * });
281
+ * const activeAdapters: ReadonlySet<Address> =
282
+ * data.getActiveAdapters(keyrockUsdcVaultV2);
283
+ * ```
284
+ */
285
+ getActiveAdapters(vault: Address): ReadonlySet<Address>;
286
+ /**
287
+ * Gets one adapter-market BluePublicAllocator configuration.
288
+ *
289
+ * @param vault - Vault V2 address.
290
+ * @param adapterMarketCapId - Adapter-scoped market cap id.
291
+ * @returns The allocator cap and permissions.
292
+ * @throws {UnknownReallocationMarketPublicAllocatorConfigError} when it is absent.
293
+ * @example
294
+ * ```ts
295
+ * import { markets } from "@morpho-org/morpho-test";
296
+ * import { createPublicClient, http, type Hash } from "viem";
297
+ * import { mainnet } from "viem/chains";
298
+ * import { morphoViemExtension } from "@morpho-org/morpho-sdk";
299
+ * import type { VaultV2BlueReallocationData } from "@morpho-org/morpho-sdk/entities";
300
+ *
301
+ * const client = createPublicClient({ chain: mainnet, transport: http() })
302
+ * .extend(morphoViemExtension());
303
+ * const marketParams = markets[mainnet.id].usdc_wbtc;
304
+ * const market = client.morpho.blue(marketParams, mainnet.id);
305
+ * const block = await client.getBlock();
306
+ * const keyrockUsdcVaultV2 = "0x04422053aDDbc9bB2759b248B574e3FCA76Bc145";
307
+ * const data = await market.getVaultV2BlueReallocationData({
308
+ * vaultAddresses: [keyrockUsdcVaultV2],
309
+ * block: { number: block.number, timestamp: block.timestamp },
310
+ * });
311
+ * const [adapterMarketCapId] = Object.keys(
312
+ * data.marketPublicAllocatorConfigs[keyrockUsdcVaultV2] ?? {},
313
+ * ) as Hash[];
314
+ * const config: ReturnType<
315
+ * VaultV2BlueReallocationData["getMarketPublicAllocatorConfig"]
316
+ * > = data.getMarketPublicAllocatorConfig(
317
+ * keyrockUsdcVaultV2,
318
+ * adapterMarketCapId!,
319
+ * );
320
+ * ```
321
+ */
322
+ getMarketPublicAllocatorConfig(vault: Address, adapterMarketCapId: Hash): VaultV2BlueMarketPublicAllocatorConfig;
323
+ /**
324
+ * Gets a supported MorphoMarketV1AdapterV2 from a Vault V2.
325
+ *
326
+ * @param vault - Vault V2 address.
327
+ * @param adapter - Adapter address.
328
+ * @returns The accrued adapter state.
329
+ * @throws {UnknownReallocationAdapterError} when it is absent or unsupported.
330
+ * @example
331
+ * ```ts
332
+ * import { markets } from "@morpho-org/morpho-test";
333
+ * import { createPublicClient, http } from "viem";
334
+ * import { mainnet } from "viem/chains";
335
+ * import { morphoViemExtension } from "@morpho-org/morpho-sdk";
336
+ * import type { VaultV2BlueReallocationData } from "@morpho-org/morpho-sdk/entities";
337
+ *
338
+ * const client = createPublicClient({ chain: mainnet, transport: http() })
339
+ * .extend(morphoViemExtension());
340
+ * const marketParams = markets[mainnet.id].usdc_wbtc;
341
+ * const market = client.morpho.blue(marketParams, mainnet.id);
342
+ * const block = await client.getBlock();
343
+ * const keyrockUsdcVaultV2 = "0x04422053aDDbc9bB2759b248B574e3FCA76Bc145";
344
+ * const data = await market.getVaultV2BlueReallocationData({
345
+ * vaultAddresses: [keyrockUsdcVaultV2],
346
+ * block: { number: block.number, timestamp: block.timestamp },
347
+ * });
348
+ * const [adapterAddress] = data.activeAdapters[keyrockUsdcVaultV2] ?? [];
349
+ * const adapter: ReturnType<VaultV2BlueReallocationData["getAdapter"]> =
350
+ * data.getAdapter(keyrockUsdcVaultV2, adapterAddress!);
351
+ * ```
352
+ */
353
+ getAdapter(vault: Address, adapter: Address): ReadonlyMarketAdapterSnapshot;
354
+ private getMutableAdapter;
355
+ /**
356
+ * Computes Vault V2 BluePublicAllocator calls available for a target market.
357
+ *
358
+ * Without `options.operation`, discovers every friendly call. With an
359
+ * operation, targets the amount required by that borrow or loan-asset
360
+ * withdrawal and falls back to 100% source utilization only when friendly
361
+ * liquidity cannot cover the absolute shortfall. A shared relative-cap lower
362
+ * bound may require one call to exceed the targeted amount. Friendly source
363
+ * utilization defaults to 90% and is configurable through
364
+ * `options.maxWithdrawalUtilization`. Vaults whose configured penalty exceeds
365
+ * `options.maxPenalty` are ignored. By default, only zero-penalty vaults are
366
+ * considered.
367
+ *
368
+ * Shared-cap discovery is conservative: when the non-shared maximum violates
369
+ * a shared cap, the candidate is omitted instead of scanning smaller base-unit
370
+ * amounts for a rounding-only fit. This keeps planning bounded but can
371
+ * understate executable liquidity in an already-at-or-over-cap snapshot.
372
+ *
373
+ * @param marketId - Target Blue market id.
374
+ * @param options - Optional discovery controls and operation to support.
375
+ * @returns Flat action-ready reallocations and their post-simulation state.
376
+ * @throws {NegativeInputError} when `maxWithdrawalUtilization` or `maxPenalty` is negative.
377
+ * @throws {InputExceedsMaxError} when `maxWithdrawalUtilization` or `maxPenalty` exceeds WAD.
378
+ * @throws {NonPositiveInputError} when the operation amount is not positive and planning is enabled.
379
+ * @throws {UnknownReallocationMarketError} when a required market is absent.
380
+ * @throws {UnknownReallocationVaultError} when configured vault state is absent.
381
+ * @throws {UnknownReallocationPublicAllocatorConfigError} when allocator authorization state is absent.
382
+ * @throws {UnknownReallocationActiveAdaptersError} when active-adapter state is absent for a vault.
383
+ * @throws {UnknownReallocationMarketPublicAllocatorConfigError} when an adapter-market allocator configuration is absent.
384
+ * @throws {UnknownReallocationAllocationError} when required allocation state is absent.
385
+ * @throws {ReallocationAllocationUnderflowError} when an inconsistent allocation snapshot underflows during the final transition.
386
+ * @throws {InsufficientSharedLiquidityError} when selected liquidity cannot cover the absolute shortfall.
387
+ * @throws {ReallocationWithdrawExceedsMarketSupplyError} when a withdraw exceeds market supply.
388
+ * @example
389
+ * ```ts
390
+ * import { markets } from "@morpho-org/morpho-test";
391
+ * import { createPublicClient, http } from "viem";
392
+ * import { mainnet } from "viem/chains";
393
+ * import {
394
+ * morphoViemExtension,
395
+ * type VaultV2BlueReallocation,
396
+ * } from "@morpho-org/morpho-sdk";
397
+ * import type { VaultV2BlueReallocationData } from "@morpho-org/morpho-sdk/entities";
398
+ *
399
+ * const client = createPublicClient({ chain: mainnet, transport: http() })
400
+ * .extend(morphoViemExtension());
401
+ * const marketParams = markets[mainnet.id].usdc_wbtc;
402
+ * const market = client.morpho.blue(marketParams, mainnet.id);
403
+ * const block = await client.getBlock();
404
+ * const keyrockUsdcVaultV2 = "0x04422053aDDbc9bB2759b248B574e3FCA76Bc145";
405
+ * const data = await market.getVaultV2BlueReallocationData({
406
+ * vaultAddresses: [keyrockUsdcVaultV2],
407
+ * block: { number: block.number, timestamp: block.timestamp },
408
+ * });
409
+ * const result: {
410
+ * readonly reallocations: readonly VaultV2BlueReallocation[];
411
+ * readonly data: VaultV2BlueReallocationData;
412
+ * } = data.computeVaultV2BlueReallocations(marketParams.id, {
413
+ * timestamp: block.timestamp,
414
+ * });
415
+ * ```
416
+ */
417
+ computeVaultV2BlueReallocations(marketId: MarketId, options?: VaultV2BluePublicAllocatorOptions & {
418
+ readonly operation?: {
419
+ readonly type: "borrow" | "withdraw";
420
+ readonly amount: bigint;
421
+ };
422
+ }): {
423
+ readonly reallocations: readonly VaultV2BlueReallocation[];
424
+ readonly data: VaultV2BlueReallocationData;
425
+ };
426
+ private computeVaultV2BlueReallocationsAtUtilizationInPlace;
427
+ /**
428
+ * Sums friendly Vault V2 shared liquidity available to a target market.
429
+ *
430
+ * @param marketId - Target Blue market id.
431
+ * @param options - Optional timestamp, enable flag, vault allowlist, source utilization ceiling, and maximum penalty.
432
+ * @returns Reallocatable market and idle assets, or `0n` when none are available; rounding-only shared-cap fits may be conservatively omitted.
433
+ * @throws {NegativeInputError} when `maxWithdrawalUtilization` or `maxPenalty` is negative.
434
+ * @throws {InputExceedsMaxError} when `maxWithdrawalUtilization` or `maxPenalty` exceeds WAD.
435
+ * @throws {UnknownReallocationMarketError} when a required market is absent.
436
+ * @throws {UnknownReallocationVaultError} when configured vault state is absent.
437
+ * @throws {UnknownReallocationPublicAllocatorConfigError} when allocator authorization state is absent.
438
+ * @throws {UnknownReallocationActiveAdaptersError} when active-adapter state is absent for a vault.
439
+ * @throws {UnknownReallocationMarketPublicAllocatorConfigError} when an adapter-market allocator configuration is absent.
440
+ * @throws {UnknownReallocationAllocationError} when required allocation state is absent.
441
+ * @example
442
+ * ```ts
443
+ * import { markets } from "@morpho-org/morpho-test";
444
+ * import { createPublicClient, http } from "viem";
445
+ * import { mainnet } from "viem/chains";
446
+ * import { morphoViemExtension } from "@morpho-org/morpho-sdk";
447
+ *
448
+ * const client = createPublicClient({ chain: mainnet, transport: http() })
449
+ * .extend(morphoViemExtension());
450
+ * const marketParams = markets[mainnet.id].usdc_wbtc;
451
+ * const market = client.morpho.blue(marketParams, mainnet.id);
452
+ * const block = await client.getBlock();
453
+ * const keyrockUsdcVaultV2 = "0x04422053aDDbc9bB2759b248B574e3FCA76Bc145";
454
+ * const data = await market.getVaultV2BlueReallocationData({
455
+ * vaultAddresses: [keyrockUsdcVaultV2],
456
+ * block: { number: block.number, timestamp: block.timestamp },
457
+ * });
458
+ * const liquidity: bigint = data.getPublicReallocationLiquidity(
459
+ * marketParams.id,
460
+ * { timestamp: block.timestamp },
461
+ * );
462
+ * ```
463
+ */
464
+ getPublicReallocationLiquidity(marketId: MarketId, options?: VaultV2BluePublicAllocatorOptions): bigint;
465
+ /**
466
+ * Computes borrow liquidity to a target utilization, including friendly
467
+ * Vault V2 public reallocations.
468
+ *
469
+ * @param marketId - Target Blue market id.
470
+ * @param utilization - Desired utilization, scaled by WAD. Defaults to 90%.
471
+ * @param options - Optional timestamp, enable flag, vault allowlist, source utilization ceiling, and maximum penalty.
472
+ * @returns Borrowable assets while remaining at or below `utilization`; rounding-only shared-cap fits may be conservatively omitted.
473
+ * @throws {NegativeInputError} when `maxWithdrawalUtilization` or `maxPenalty` is negative.
474
+ * @throws {InputExceedsMaxError} when `maxWithdrawalUtilization` or `maxPenalty` exceeds WAD.
475
+ * @throws {UnknownReallocationMarketError} when a required market is absent.
476
+ * @throws {UnknownReallocationVaultError} when configured vault state is absent.
477
+ * @throws {UnknownReallocationPublicAllocatorConfigError} when allocator authorization state is absent.
478
+ * @throws {UnknownReallocationActiveAdaptersError} when active-adapter state is absent for a vault.
479
+ * @throws {UnknownReallocationMarketPublicAllocatorConfigError} when an adapter-market allocator configuration is absent.
480
+ * @throws {UnknownReallocationAllocationError} when required allocation state is absent.
481
+ * @example
482
+ * ```ts
483
+ * import { markets } from "@morpho-org/morpho-test";
484
+ * import { createPublicClient, http, parseEther } from "viem";
485
+ * import { mainnet } from "viem/chains";
486
+ * import { morphoViemExtension } from "@morpho-org/morpho-sdk";
487
+ *
488
+ * const client = createPublicClient({ chain: mainnet, transport: http() })
489
+ * .extend(morphoViemExtension());
490
+ * const marketParams = markets[mainnet.id].usdc_wbtc;
491
+ * const market = client.morpho.blue(marketParams, mainnet.id);
492
+ * const block = await client.getBlock();
493
+ * const keyrockUsdcVaultV2 = "0x04422053aDDbc9bB2759b248B574e3FCA76Bc145";
494
+ * const data = await market.getVaultV2BlueReallocationData({
495
+ * vaultAddresses: [keyrockUsdcVaultV2],
496
+ * block: { number: block.number, timestamp: block.timestamp },
497
+ * });
498
+ * const liquidity: bigint = data.getAvailableLiquidityToUtilization(
499
+ * marketParams.id,
500
+ * parseEther("0.9"),
501
+ * { timestamp: block.timestamp },
502
+ * );
503
+ * ```
504
+ */
505
+ getAvailableLiquidityToUtilization(marketId: MarketId, utilization?: bigint, options?: VaultV2BluePublicAllocatorOptions): bigint;
506
+ private getLatestSnapshotTimestamp;
507
+ private applyPublicReallocation;
508
+ /** Updates canonical markets in bulk and refreshes only dependent adapter views. */
509
+ private setMarkets;
510
+ }
511
+ export {};