@morpho-org/morpho-sdk 9.1.0 → 9.2.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.
- package/README.md +4 -0
- package/lib/cjs/abis.d.ts +1 -1
- package/lib/cjs/abis.js +3 -1
- package/lib/cjs/blue/constants.d.ts +1 -1
- package/lib/cjs/blue/constants.js +2 -1
- package/lib/cjs/constants.d.ts +2 -2
- package/lib/cjs/constants.js +4 -1
- package/lib/cjs/entities/blue/blue.d.ts +71 -16
- package/lib/cjs/entities/blue/blue.js +32 -4
- package/lib/cjs/entities/midnight/midnight.d.ts +2 -1
- package/lib/cjs/entities/midnight/midnight.js +5 -4
- package/lib/cjs/entities/vaultV1/vaultV1.d.ts +8 -0
- package/lib/cjs/entities/vaultV1/vaultV1.js +5 -0
- package/lib/cjs/entities/vaultV2/vaultV2.d.ts +4 -0
- package/lib/cjs/entities/vaultV2/vaultV2.js +3 -0
- package/lib/cjs/entities/vaultV2BlueReallocationData.d.ts +37 -4
- package/lib/cjs/entities/vaultV2BlueReallocationData.js +197 -32
- package/lib/cjs/helpers/constant.d.ts +7 -0
- package/lib/cjs/helpers/constant.js +8 -1
- package/lib/cjs/helpers/deadShares.d.ts +82 -0
- package/lib/cjs/helpers/deadShares.js +200 -0
- package/lib/cjs/helpers/index.d.ts +2 -1
- package/lib/cjs/helpers/index.js +7 -1
- package/lib/cjs/midnight/abis.d.ts +1 -1
- package/lib/cjs/midnight/abis.js +3 -1
- package/lib/cjs/types/error.d.ts +54 -5
- package/lib/cjs/types/error.js +60 -6
- package/lib/cjs/types/sharedLiquidity.d.ts +10 -6
- package/lib/esm/abis.d.ts +1 -1
- package/lib/esm/abis.js +1 -1
- package/lib/esm/blue/constants.d.ts +1 -1
- package/lib/esm/blue/constants.js +1 -1
- package/lib/esm/constants.d.ts +2 -2
- package/lib/esm/constants.js +2 -2
- package/lib/esm/entities/blue/blue.d.ts +71 -16
- package/lib/esm/entities/blue/blue.js +34 -6
- package/lib/esm/entities/midnight/midnight.d.ts +2 -1
- package/lib/esm/entities/midnight/midnight.js +6 -5
- package/lib/esm/entities/vaultV1/vaultV1.d.ts +8 -0
- package/lib/esm/entities/vaultV1/vaultV1.js +5 -0
- package/lib/esm/entities/vaultV2/vaultV2.d.ts +4 -0
- package/lib/esm/entities/vaultV2/vaultV2.js +3 -0
- package/lib/esm/entities/vaultV2BlueReallocationData.d.ts +37 -4
- package/lib/esm/entities/vaultV2BlueReallocationData.js +197 -32
- package/lib/esm/helpers/constant.d.ts +7 -0
- package/lib/esm/helpers/constant.js +7 -0
- package/lib/esm/helpers/deadShares.d.ts +82 -0
- package/lib/esm/helpers/deadShares.js +195 -0
- package/lib/esm/helpers/index.d.ts +2 -1
- package/lib/esm/helpers/index.js +2 -1
- package/lib/esm/midnight/abis.d.ts +1 -1
- package/lib/esm/midnight/abis.js +1 -1
- package/lib/esm/types/error.d.ts +54 -5
- package/lib/esm/types/error.js +57 -5
- package/lib/esm/types/sharedLiquidity.d.ts +10 -6
- package/package.json +8 -7
|
@@ -0,0 +1,195 @@
|
|
|
1
|
+
import { AccrualVaultV2MorphoMarketV1Adapter, AccrualVaultV2MorphoMarketV1AdapterV2, AccrualVaultV2MorphoVaultV1Adapter, MarketParams, VaultV2MorphoMarketV1Adapter, VaultV2MorphoMarketV1AdapterV2, VaultV2MorphoVaultV1Adapter, } from "@morpho-org/blue-sdk";
|
|
2
|
+
import { InsufficientDeadSharesError, MissingDeadSharesDataError, } from "../types/error.js";
|
|
3
|
+
import { MIN_DEAD_SHARES, MIN_VAULT_V2_DEAD_ASSETS } from "./constant.js";
|
|
4
|
+
/**
|
|
5
|
+
* Checks that a Morpho Blue market holds at least `MIN_DEAD_SHARES` supply shares at `DEAD_ADDRESS`.
|
|
6
|
+
*
|
|
7
|
+
* @param market - Fetched market snapshot.
|
|
8
|
+
* @param path - Vaults leading to this market, outermost first; empty for a direct market.
|
|
9
|
+
* @returns Nothing; returns normally when the market passes.
|
|
10
|
+
* @throws {MissingDeadSharesDataError} when `market.deadSupplyShares` was not fetched.
|
|
11
|
+
* @throws {InsufficientDeadSharesError} when the market holds fewer than `MIN_DEAD_SHARES` dead supply shares.
|
|
12
|
+
* @example
|
|
13
|
+
* ```ts
|
|
14
|
+
* import { validateBlueMarketDeadShares } from "@morpho-org/morpho-sdk";
|
|
15
|
+
* import { fetchBlueMarket } from "@morpho-org/morpho-sdk/fetch";
|
|
16
|
+
* import { markets } from "@morpho-org/morpho-test";
|
|
17
|
+
* import { createPublicClient, http } from "viem";
|
|
18
|
+
* import { mainnet } from "viem/chains";
|
|
19
|
+
*
|
|
20
|
+
* const client = createPublicClient({ chain: mainnet, transport: http() });
|
|
21
|
+
* const market = await fetchBlueMarket(markets[mainnet.id].usdc_wbtc.id, client);
|
|
22
|
+
* validateBlueMarketDeadShares(market);
|
|
23
|
+
* // Returns void on success; throws if the snapshot fails the rule.
|
|
24
|
+
* ```
|
|
25
|
+
*/
|
|
26
|
+
export function validateBlueMarketDeadShares(market, path = []) {
|
|
27
|
+
const entity = [...path, market.id];
|
|
28
|
+
if (market.deadSupplyShares == null)
|
|
29
|
+
throw new MissingDeadSharesDataError({ entity, field: "deadSupplyShares" });
|
|
30
|
+
if (market.deadSupplyShares < MIN_DEAD_SHARES)
|
|
31
|
+
throw new InsufficientDeadSharesError({
|
|
32
|
+
entity,
|
|
33
|
+
reason: "deadShares",
|
|
34
|
+
observed: market.deadSupplyShares,
|
|
35
|
+
required: MIN_DEAD_SHARES,
|
|
36
|
+
});
|
|
37
|
+
}
|
|
38
|
+
/**
|
|
39
|
+
* Checks that a Vault V1 holds at least `MIN_DEAD_SHARES` shares at `DEAD_ADDRESS` and that every
|
|
40
|
+
* market in its withdraw queue passes `validateBlueMarketDeadShares`.
|
|
41
|
+
*
|
|
42
|
+
* @param vault - Fetched vault snapshot with its withdraw-queue allocations.
|
|
43
|
+
* @param path - Vaults leading to this vault, outermost first; empty for a direct deposit.
|
|
44
|
+
* @returns Nothing; returns normally when the vault and everything it can allocate to pass.
|
|
45
|
+
* @throws {MissingDeadSharesDataError} when `vault.deadShares`, a withdraw-queue allocation or a
|
|
46
|
+
* market's `deadSupplyShares` was not fetched.
|
|
47
|
+
* @throws {InsufficientDeadSharesError} when the vault or one of its withdraw-queue markets holds
|
|
48
|
+
* too few dead shares.
|
|
49
|
+
* @example
|
|
50
|
+
* ```ts
|
|
51
|
+
* import { validateVaultV1DeadShares } from "@morpho-org/morpho-sdk";
|
|
52
|
+
* import { fetchAccrualVault } from "@morpho-org/morpho-sdk/fetch";
|
|
53
|
+
* import { vaults } from "@morpho-org/morpho-test";
|
|
54
|
+
* import { createPublicClient, http } from "viem";
|
|
55
|
+
* import { mainnet } from "viem/chains";
|
|
56
|
+
*
|
|
57
|
+
* const client = createPublicClient({ chain: mainnet, transport: http() });
|
|
58
|
+
* const vault = await fetchAccrualVault(vaults[mainnet.id].steakUsdc.address, client);
|
|
59
|
+
* validateVaultV1DeadShares(vault);
|
|
60
|
+
* // Returns void on success; throws if the snapshot fails the rule.
|
|
61
|
+
* ```
|
|
62
|
+
*/
|
|
63
|
+
export function validateVaultV1DeadShares(vault, path = []) {
|
|
64
|
+
const entity = [...path, vault.address];
|
|
65
|
+
if (vault.deadShares == null)
|
|
66
|
+
throw new MissingDeadSharesDataError({ entity, field: "deadShares" });
|
|
67
|
+
if (vault.deadShares < MIN_DEAD_SHARES)
|
|
68
|
+
throw new InsufficientDeadSharesError({
|
|
69
|
+
entity,
|
|
70
|
+
reason: "deadShares",
|
|
71
|
+
observed: vault.deadShares,
|
|
72
|
+
required: MIN_DEAD_SHARES,
|
|
73
|
+
});
|
|
74
|
+
for (const marketId of vault.withdrawQueue) {
|
|
75
|
+
const allocation = vault.allocations.get(marketId);
|
|
76
|
+
if (allocation == null)
|
|
77
|
+
throw new MissingDeadSharesDataError({
|
|
78
|
+
entity: [...entity, marketId],
|
|
79
|
+
field: "allocation",
|
|
80
|
+
});
|
|
81
|
+
validateBlueMarketDeadShares(allocation.position.market, entity);
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
/**
|
|
85
|
+
* Checks a Vault V2 against the dead-deposit rule: at least `MIN_DEAD_SHARES` shares at
|
|
86
|
+
* `DEAD_ADDRESS` worth at least `MIN_VAULT_V2_DEAD_ASSETS` assets, a share price above
|
|
87
|
+
* `1 / (10 * virtualShares)`, and every Blue market or Vault V1 it can allocate to (non-zero
|
|
88
|
+
* absolute cap) passing its own rule. Zero-cap entries are skipped.
|
|
89
|
+
*
|
|
90
|
+
* @param vault - Fetched vault snapshot with its adapters and `absoluteCaps`.
|
|
91
|
+
* @param path - Vaults leading to this vault, outermost first; empty for a direct deposit.
|
|
92
|
+
* @returns Nothing; returns normally when the vault and everything it can allocate to pass.
|
|
93
|
+
* @throws {MissingDeadSharesDataError} when a dead-share field, an adapter cap, or the data of an
|
|
94
|
+
* adapter the SDK cannot hydrate is missing.
|
|
95
|
+
* @throws {InsufficientDeadSharesError} when the vault or an allocatable market or Vault V1 fails the rule.
|
|
96
|
+
* @example
|
|
97
|
+
* ```ts
|
|
98
|
+
* import { validateVaultV2DeadShares } from "@morpho-org/morpho-sdk";
|
|
99
|
+
* import { fetchAccrualVaultV2 } from "@morpho-org/morpho-sdk/fetch";
|
|
100
|
+
* import { createPublicClient, http } from "viem";
|
|
101
|
+
* import { mainnet } from "viem/chains";
|
|
102
|
+
*
|
|
103
|
+
* const client = createPublicClient({ chain: mainnet, transport: http() });
|
|
104
|
+
* const keyrockUsdcVaultV2 = "0x04422053aDDbc9bB2759b248B574e3FCA76Bc145";
|
|
105
|
+
* const vault = await fetchAccrualVaultV2(keyrockUsdcVaultV2, client);
|
|
106
|
+
* validateVaultV2DeadShares(vault);
|
|
107
|
+
* // Returns void on success; throws if the snapshot fails the rule.
|
|
108
|
+
* ```
|
|
109
|
+
*/
|
|
110
|
+
export function validateVaultV2DeadShares(vault, path = []) {
|
|
111
|
+
const entity = [...path, vault.address];
|
|
112
|
+
const { deadShares, deadAssets, absoluteCaps } = vault;
|
|
113
|
+
if (deadShares == null)
|
|
114
|
+
throw new MissingDeadSharesDataError({ entity, field: "deadShares" });
|
|
115
|
+
if (deadAssets == null)
|
|
116
|
+
throw new MissingDeadSharesDataError({ entity, field: "deadAssets" });
|
|
117
|
+
if (absoluteCaps == null)
|
|
118
|
+
throw new MissingDeadSharesDataError({ entity, field: "absoluteCaps" });
|
|
119
|
+
if (deadShares < MIN_DEAD_SHARES)
|
|
120
|
+
throw new InsufficientDeadSharesError({
|
|
121
|
+
entity,
|
|
122
|
+
reason: "deadShares",
|
|
123
|
+
observed: deadShares,
|
|
124
|
+
required: MIN_DEAD_SHARES,
|
|
125
|
+
});
|
|
126
|
+
if (deadAssets < MIN_VAULT_V2_DEAD_ASSETS)
|
|
127
|
+
throw new InsufficientDeadSharesError({
|
|
128
|
+
entity,
|
|
129
|
+
reason: "deadAssets",
|
|
130
|
+
observed: deadAssets,
|
|
131
|
+
required: MIN_VAULT_V2_DEAD_ASSETS,
|
|
132
|
+
});
|
|
133
|
+
// Share price (totalAssets + 1) / (totalSupply + virtualShares) must exceed 1 / (10 * virtualShares).
|
|
134
|
+
const priceNumerator = (vault._totalAssets + 1n) * 10n * vault.virtualShares;
|
|
135
|
+
const priceDenominator = vault.totalSupply + vault.virtualShares;
|
|
136
|
+
if (priceNumerator <= priceDenominator)
|
|
137
|
+
throw new InsufficientDeadSharesError({
|
|
138
|
+
entity,
|
|
139
|
+
reason: "sharePrice",
|
|
140
|
+
observed: priceNumerator,
|
|
141
|
+
required: priceDenominator + 1n,
|
|
142
|
+
});
|
|
143
|
+
const capOf = (id, adapter) => {
|
|
144
|
+
const cap = absoluteCaps[id];
|
|
145
|
+
if (cap == null)
|
|
146
|
+
throw new MissingDeadSharesDataError({
|
|
147
|
+
entity: [...entity, adapter],
|
|
148
|
+
field: "absoluteCaps",
|
|
149
|
+
});
|
|
150
|
+
return cap;
|
|
151
|
+
};
|
|
152
|
+
for (const adapter of vault.accrualAdapters) {
|
|
153
|
+
if (adapter instanceof AccrualVaultV2MorphoVaultV1Adapter) {
|
|
154
|
+
const id = VaultV2MorphoVaultV1Adapter.adapterCapId(adapter.address);
|
|
155
|
+
if (capOf(id, adapter.address) > 0n)
|
|
156
|
+
validateVaultV1DeadShares(adapter.accrualVaultV1, entity);
|
|
157
|
+
}
|
|
158
|
+
else if (adapter instanceof AccrualVaultV2MorphoMarketV1Adapter) {
|
|
159
|
+
for (const { market } of adapter.positions) {
|
|
160
|
+
const id = VaultV2MorphoMarketV1Adapter.adapterMarketCapId(adapter.address, market.params);
|
|
161
|
+
if (capOf(id, adapter.address) > 0n)
|
|
162
|
+
validateBlueMarketDeadShares(market, entity);
|
|
163
|
+
}
|
|
164
|
+
}
|
|
165
|
+
else if (adapter instanceof AccrualVaultV2MorphoMarketV1AdapterV2) {
|
|
166
|
+
for (const market of adapter.markets) {
|
|
167
|
+
const id = VaultV2MorphoMarketV1AdapterV2.adapterMarketCapId(adapter.address, market.params);
|
|
168
|
+
if (capOf(id, adapter.address) > 0n)
|
|
169
|
+
validateBlueMarketDeadShares(market, entity);
|
|
170
|
+
}
|
|
171
|
+
}
|
|
172
|
+
else {
|
|
173
|
+
throw new MissingDeadSharesDataError({
|
|
174
|
+
entity: [...entity, adapter.address],
|
|
175
|
+
field: "adapter",
|
|
176
|
+
});
|
|
177
|
+
}
|
|
178
|
+
}
|
|
179
|
+
// Deposits are allocated to the liquidity market, so the snapshot must hold it even when it
|
|
180
|
+
// has no allocation yet (the adapters only list markets they currently supply to).
|
|
181
|
+
const liquidityAdapter = vault.accrualLiquidityAdapter;
|
|
182
|
+
if (vault.liquidityData === "0x" ||
|
|
183
|
+
!(liquidityAdapter instanceof AccrualVaultV2MorphoMarketV1Adapter ||
|
|
184
|
+
liquidityAdapter instanceof AccrualVaultV2MorphoMarketV1AdapterV2))
|
|
185
|
+
return;
|
|
186
|
+
const liquidityMarketId = MarketParams.fromHex(vault.liquidityData).id;
|
|
187
|
+
const markets = liquidityAdapter instanceof AccrualVaultV2MorphoMarketV1Adapter
|
|
188
|
+
? liquidityAdapter.positions.map(({ market }) => market)
|
|
189
|
+
: liquidityAdapter.markets;
|
|
190
|
+
if (!markets.some(({ id }) => id === liquidityMarketId))
|
|
191
|
+
throw new MissingDeadSharesDataError({
|
|
192
|
+
entity: [...entity, liquidityAdapter.address, liquidityMarketId],
|
|
193
|
+
field: "liquidityMarket",
|
|
194
|
+
});
|
|
195
|
+
}
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
export { getMidnightBlueBuyCallbackAddress, getMidnightBlueBuyCallbackData, } from "./callback.js";
|
|
2
|
-
export { APPROVE_ONLY_ONCE_TOKENS, DEFAULT_ALLOCATOR_CAP_HEADROOM, DEFAULT_CAP_ACCRUAL_BUFFER, DEFAULT_LLTV_BUFFER, DEFAULT_MAX_REALLOCATION_PENALTY, DEFAULT_SUPPLY_TARGET_UTILIZATION, DEFAULT_WITHDRAWAL_TARGET_UTILIZATION, MAX_ABSOLUTE_SHARE_PRICE, MAX_REALLOCATION_PENALTY, MAX_SLIPPAGE_TOLERANCE, MAX_TOKEN_APPROVALS, MIDNIGHT_TAKE_MAX_DEADLINE_SECONDS, } from "./constant.js";
|
|
2
|
+
export { APPROVE_ONLY_ONCE_TOKENS, DEFAULT_ALLOCATOR_CAP_HEADROOM, DEFAULT_CAP_ACCRUAL_BUFFER, DEFAULT_LLTV_BUFFER, DEFAULT_MAX_REALLOCATION_PENALTY, DEFAULT_SUPPLY_TARGET_UTILIZATION, DEFAULT_WITHDRAWAL_TARGET_UTILIZATION, MAX_ABSOLUTE_SHARE_PRICE, MAX_REALLOCATION_PENALTY, MAX_SLIPPAGE_TOLERANCE, MAX_TOKEN_APPROVALS, MIDNIGHT_TAKE_MAX_DEADLINE_SECONDS, MIN_DEAD_SHARES, MIN_VAULT_V2_DEAD_ASSETS, } from "./constant.js";
|
|
3
|
+
export { validateBlueMarketDeadShares, validateVaultV1DeadShares, validateVaultV2DeadShares, } from "./deadShares.js";
|
|
3
4
|
export { addTransactionMetadata } from "./metadata.js";
|
|
4
5
|
export { type PreviewVaultV2ForceWithdrawParams, previewVaultV2ForceWithdraw, type VaultV2ForceWithdrawPreview, } from "./previewVaultV2ForceWithdraw.js";
|
|
5
6
|
export { type PreviewVaultV2InKindRedeemParams, previewVaultV2InKindRedeem, type VaultV2InKindRedeemMarketPreview, } from "./previewVaultV2InKindRedeem.js";
|
package/lib/esm/helpers/index.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
export { getMidnightBlueBuyCallbackAddress, getMidnightBlueBuyCallbackData, } from "./callback.js";
|
|
2
|
-
export { APPROVE_ONLY_ONCE_TOKENS, DEFAULT_ALLOCATOR_CAP_HEADROOM, DEFAULT_CAP_ACCRUAL_BUFFER, DEFAULT_LLTV_BUFFER, DEFAULT_MAX_REALLOCATION_PENALTY, DEFAULT_SUPPLY_TARGET_UTILIZATION, DEFAULT_WITHDRAWAL_TARGET_UTILIZATION, MAX_ABSOLUTE_SHARE_PRICE, MAX_REALLOCATION_PENALTY, MAX_SLIPPAGE_TOLERANCE, MAX_TOKEN_APPROVALS, MIDNIGHT_TAKE_MAX_DEADLINE_SECONDS, } from "./constant.js";
|
|
2
|
+
export { APPROVE_ONLY_ONCE_TOKENS, DEFAULT_ALLOCATOR_CAP_HEADROOM, DEFAULT_CAP_ACCRUAL_BUFFER, DEFAULT_LLTV_BUFFER, DEFAULT_MAX_REALLOCATION_PENALTY, DEFAULT_SUPPLY_TARGET_UTILIZATION, DEFAULT_WITHDRAWAL_TARGET_UTILIZATION, MAX_ABSOLUTE_SHARE_PRICE, MAX_REALLOCATION_PENALTY, MAX_SLIPPAGE_TOLERANCE, MAX_TOKEN_APPROVALS, MIDNIGHT_TAKE_MAX_DEADLINE_SECONDS, MIN_DEAD_SHARES, MIN_VAULT_V2_DEAD_ASSETS, } from "./constant.js";
|
|
3
|
+
export { validateBlueMarketDeadShares, validateVaultV1DeadShares, validateVaultV2DeadShares, } from "./deadShares.js";
|
|
3
4
|
export { addTransactionMetadata } from "./metadata.js";
|
|
4
5
|
export { previewVaultV2ForceWithdraw, } from "./previewVaultV2ForceWithdraw.js";
|
|
5
6
|
export { previewVaultV2InKindRedeem, } from "./previewVaultV2InKindRedeem.js";
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export { blueBuyCallbackFactoryAbi, ecrecoverRatifierAbi, midnightAbi, midnightBundlesV2Abi, priceRatifierV1Abi, rateRatifierV1Abi, setterRatifierAbi, } from "@morpho-org/midnight-sdk";
|
|
1
|
+
export { blueBuyCallbackFactoryAbi, ecrecoverAuthorizerAbi, ecrecoverRatifierAbi, midnightAbi, midnightBundlesV2Abi, midnightEventsAbi, priceRatifierV1Abi, rateRatifierV1Abi, setterRatifierAbi, } from "@morpho-org/midnight-sdk";
|
package/lib/esm/midnight/abis.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export { blueBuyCallbackFactoryAbi, ecrecoverRatifierAbi, midnightAbi, midnightBundlesV2Abi, priceRatifierV1Abi, rateRatifierV1Abi, setterRatifierAbi, } from "@morpho-org/midnight-sdk";
|
|
1
|
+
export { blueBuyCallbackFactoryAbi, ecrecoverAuthorizerAbi, ecrecoverRatifierAbi, midnightAbi, midnightBundlesV2Abi, midnightEventsAbi, priceRatifierV1Abi, rateRatifierV1Abi, setterRatifierAbi, } from "@morpho-org/midnight-sdk";
|
package/lib/esm/types/error.d.ts
CHANGED
|
@@ -929,11 +929,16 @@ export declare class RepaySharesExceedDebtError extends Error {
|
|
|
929
929
|
});
|
|
930
930
|
}
|
|
931
931
|
/**
|
|
932
|
-
* Thrown when shared liquidity
|
|
933
|
-
*
|
|
934
|
-
*
|
|
932
|
+
* Thrown when shared liquidity cannot cover the operation's required
|
|
933
|
+
* reallocated assets. When Blue's balance is explicit, it is also thrown if
|
|
934
|
+
* that balance cannot fund the penalty flash loan, an earlier market-sourced
|
|
935
|
+
* withdrawal, or the final operation transfer. A borrow or withdraw plan that
|
|
936
|
+
* otherwise covers its shortfall but whose planned penalty exceeds its amount
|
|
937
|
+
* instead throws `InputExceedsMaxError`.
|
|
935
938
|
*
|
|
936
|
-
*
|
|
939
|
+
* `shortfall` is the reallocated assets required by the operation and is
|
|
940
|
+
* comparable to `available`. Pattern-match on the class and inspect `params`
|
|
941
|
+
* to surface the gap to users.
|
|
937
942
|
*/
|
|
938
943
|
export declare class InsufficientSharedLiquidityError extends Error {
|
|
939
944
|
readonly params: {
|
|
@@ -1316,7 +1321,12 @@ export declare class MidnightOfferCallbackDataMismatchError extends Error {
|
|
|
1316
1321
|
readonly actualCallbackData: Hex;
|
|
1317
1322
|
});
|
|
1318
1323
|
}
|
|
1319
|
-
/**
|
|
1324
|
+
/**
|
|
1325
|
+
* Thrown when loan assets would be parked in a Morpho Blue market with no existing supply.
|
|
1326
|
+
*
|
|
1327
|
+
* @deprecated `supplyBlueMakeLend` now throws `InsufficientDeadSharesError` or
|
|
1328
|
+
* `MissingDeadSharesDataError` instead; kept exported so existing `instanceof` checks compile.
|
|
1329
|
+
*/
|
|
1320
1330
|
export declare class EmptyBlueParkingMarketError extends Error {
|
|
1321
1331
|
constructor(params: {
|
|
1322
1332
|
readonly marketId: MarketId;
|
|
@@ -1332,6 +1342,45 @@ export declare class ZeroBlueParkingSharesError extends Error {
|
|
|
1332
1342
|
readonly assets: bigint;
|
|
1333
1343
|
});
|
|
1334
1344
|
}
|
|
1345
|
+
/** Which dead-deposit condition an entity failed. */
|
|
1346
|
+
export type DeadSharesFailureReason = "deadShares" | "deadAssets" | "sharePrice";
|
|
1347
|
+
/**
|
|
1348
|
+
* Thrown when a Morpho Blue market or vault, or a market or Vault V1 it can allocate to, fails the
|
|
1349
|
+
* dead-deposit rule that protects deposits against share-price inflation.
|
|
1350
|
+
*/
|
|
1351
|
+
export declare class InsufficientDeadSharesError extends Error {
|
|
1352
|
+
/** Failing entity, outermost vault first; the last element is the market id or vault address. */
|
|
1353
|
+
readonly entity: readonly (Address | Hash)[];
|
|
1354
|
+
/** Failed condition. */
|
|
1355
|
+
readonly reason: DeadSharesFailureReason;
|
|
1356
|
+
/** Observed dead shares or assets; for `sharePrice`, `(totalAssets + 1) * 10 * virtualShares`. */
|
|
1357
|
+
readonly observed: bigint;
|
|
1358
|
+
/** Required minimum; for `sharePrice`, `totalSupply + virtualShares + 1`. */
|
|
1359
|
+
readonly required: bigint;
|
|
1360
|
+
constructor(params: {
|
|
1361
|
+
readonly entity: readonly (Address | Hash)[];
|
|
1362
|
+
readonly reason: DeadSharesFailureReason;
|
|
1363
|
+
readonly observed: bigint;
|
|
1364
|
+
readonly required: bigint;
|
|
1365
|
+
});
|
|
1366
|
+
}
|
|
1367
|
+
/** Snapshot field the dead-deposit check needs but the snapshot does not carry. */
|
|
1368
|
+
export type DeadSharesDataField = "deadSupplyShares" | "deadShares" | "deadAssets" | "absoluteCaps" | "allocation" | "adapter" | "liquidityMarket";
|
|
1369
|
+
/**
|
|
1370
|
+
* Thrown when a market or vault snapshot lacks the data the dead-deposit check needs, such as a
|
|
1371
|
+
* snapshot built by hand, from the Morpho API or by an older fetcher, or a Vault V2 adapter the
|
|
1372
|
+
* SDK cannot hydrate. The check fails closed rather than pass unverified data.
|
|
1373
|
+
*/
|
|
1374
|
+
export declare class MissingDeadSharesDataError extends Error {
|
|
1375
|
+
/** Entity missing the data, outermost vault first. */
|
|
1376
|
+
readonly entity: readonly (Address | Hash)[];
|
|
1377
|
+
/** Missing field. */
|
|
1378
|
+
readonly field: DeadSharesDataField;
|
|
1379
|
+
constructor(params: {
|
|
1380
|
+
readonly entity: readonly (Address | Hash)[];
|
|
1381
|
+
readonly field: DeadSharesDataField;
|
|
1382
|
+
});
|
|
1383
|
+
}
|
|
1335
1384
|
/** Thrown when a quoted Midnight takeable offer belongs to a different market than the requested flow. */
|
|
1336
1385
|
export declare class MidnightTakeableOfferMarketMismatchError extends Error {
|
|
1337
1386
|
constructor(params: {
|
package/lib/esm/types/error.js
CHANGED
|
@@ -1144,11 +1144,16 @@ export class RepaySharesExceedDebtError extends Error {
|
|
|
1144
1144
|
}
|
|
1145
1145
|
}
|
|
1146
1146
|
/**
|
|
1147
|
-
* Thrown when shared liquidity
|
|
1148
|
-
*
|
|
1149
|
-
*
|
|
1147
|
+
* Thrown when shared liquidity cannot cover the operation's required
|
|
1148
|
+
* reallocated assets. When Blue's balance is explicit, it is also thrown if
|
|
1149
|
+
* that balance cannot fund the penalty flash loan, an earlier market-sourced
|
|
1150
|
+
* withdrawal, or the final operation transfer. A borrow or withdraw plan that
|
|
1151
|
+
* otherwise covers its shortfall but whose planned penalty exceeds its amount
|
|
1152
|
+
* instead throws `InputExceedsMaxError`.
|
|
1150
1153
|
*
|
|
1151
|
-
*
|
|
1154
|
+
* `shortfall` is the reallocated assets required by the operation and is
|
|
1155
|
+
* comparable to `available`. Pattern-match on the class and inspect `params`
|
|
1156
|
+
* to surface the gap to users.
|
|
1152
1157
|
*/
|
|
1153
1158
|
export class InsufficientSharedLiquidityError extends Error {
|
|
1154
1159
|
params;
|
|
@@ -1580,7 +1585,12 @@ export class MidnightOfferCallbackDataMismatchError extends Error {
|
|
|
1580
1585
|
this.name = "MidnightOfferCallbackDataMismatchError";
|
|
1581
1586
|
}
|
|
1582
1587
|
}
|
|
1583
|
-
/**
|
|
1588
|
+
/**
|
|
1589
|
+
* Thrown when loan assets would be parked in a Morpho Blue market with no existing supply.
|
|
1590
|
+
*
|
|
1591
|
+
* @deprecated `supplyBlueMakeLend` now throws `InsufficientDeadSharesError` or
|
|
1592
|
+
* `MissingDeadSharesDataError` instead; kept exported so existing `instanceof` checks compile.
|
|
1593
|
+
*/
|
|
1584
1594
|
export class EmptyBlueParkingMarketError extends Error {
|
|
1585
1595
|
constructor(params) {
|
|
1586
1596
|
super(`Morpho Blue market "${params.marketId}" has no supply shares. Parking assets in an empty market is exposed to supply-share-price inflation; choose a market with existing supply.`);
|
|
@@ -1597,6 +1607,48 @@ export class ZeroBlueParkingSharesError extends Error {
|
|
|
1597
1607
|
this.name = "ZeroBlueParkingSharesError";
|
|
1598
1608
|
}
|
|
1599
1609
|
}
|
|
1610
|
+
/**
|
|
1611
|
+
* Thrown when a Morpho Blue market or vault, or a market or Vault V1 it can allocate to, fails the
|
|
1612
|
+
* dead-deposit rule that protects deposits against share-price inflation.
|
|
1613
|
+
*/
|
|
1614
|
+
export class InsufficientDeadSharesError extends Error {
|
|
1615
|
+
/** Failing entity, outermost vault first; the last element is the market id or vault address. */
|
|
1616
|
+
entity;
|
|
1617
|
+
/** Failed condition. */
|
|
1618
|
+
reason;
|
|
1619
|
+
/** Observed dead shares or assets; for `sharePrice`, `(totalAssets + 1) * 10 * virtualShares`. */
|
|
1620
|
+
observed;
|
|
1621
|
+
/** Required minimum; for `sharePrice`, `totalSupply + virtualShares + 1`. */
|
|
1622
|
+
required;
|
|
1623
|
+
constructor(params) {
|
|
1624
|
+
const target = params.entity.join(" > ");
|
|
1625
|
+
super(params.reason === "sharePrice"
|
|
1626
|
+
? `Vault V2 "${target}" share price is at or below 1 / (10 * virtualShares) ("${params.observed}" < "${params.required}"), so it may have been deflated before its dead deposit. Choose another vault.`
|
|
1627
|
+
: `"${target}" holds "${params.observed}" dead ${params.reason === "deadShares" ? "shares" : "assets"} at 0x000000000000000000000000000000000000dEaD, below the required "${params.required}". Choose a market or vault with a sufficient dead deposit.`);
|
|
1628
|
+
this.name = "InsufficientDeadSharesError";
|
|
1629
|
+
this.entity = params.entity;
|
|
1630
|
+
this.reason = params.reason;
|
|
1631
|
+
this.observed = params.observed;
|
|
1632
|
+
this.required = params.required;
|
|
1633
|
+
}
|
|
1634
|
+
}
|
|
1635
|
+
/**
|
|
1636
|
+
* Thrown when a market or vault snapshot lacks the data the dead-deposit check needs, such as a
|
|
1637
|
+
* snapshot built by hand, from the Morpho API or by an older fetcher, or a Vault V2 adapter the
|
|
1638
|
+
* SDK cannot hydrate. The check fails closed rather than pass unverified data.
|
|
1639
|
+
*/
|
|
1640
|
+
export class MissingDeadSharesDataError extends Error {
|
|
1641
|
+
/** Entity missing the data, outermost vault first. */
|
|
1642
|
+
entity;
|
|
1643
|
+
/** Missing field. */
|
|
1644
|
+
field;
|
|
1645
|
+
constructor(params) {
|
|
1646
|
+
super(`"${params.entity.join(" > ")}" has no "${params.field}" data for the dead-deposit check. Fetch the snapshot with the @morpho-org/blue-sdk-viem fetchers before building the transaction.`);
|
|
1647
|
+
this.name = "MissingDeadSharesDataError";
|
|
1648
|
+
this.entity = params.entity;
|
|
1649
|
+
this.field = params.field;
|
|
1650
|
+
}
|
|
1651
|
+
}
|
|
1600
1652
|
/** Thrown when a quoted Midnight takeable offer belongs to a different market than the requested flow. */
|
|
1601
1653
|
export class MidnightTakeableOfferMarketMismatchError extends Error {
|
|
1602
1654
|
constructor(params) {
|
|
@@ -56,9 +56,11 @@ export interface VaultV2BluePublicAllocatorOptions {
|
|
|
56
56
|
readonly reallocatableVaults?: Iterable<Address>;
|
|
57
57
|
/**
|
|
58
58
|
* Maximum utilization source markets may reach during friendly discovery,
|
|
59
|
-
* scaled by WAD. Within each penalty tier, the
|
|
60
|
-
* back to 100%
|
|
61
|
-
* shortfall
|
|
59
|
+
* scaled by WAD. Within each penalty tier, the planner tries this friendly
|
|
60
|
+
* utilization before falling back to 100% when required coverage remains.
|
|
61
|
+
* Positive-penalty tiers cover the remaining absolute shortfall or, when
|
|
62
|
+
* larger, Blue's loan-token balance deficit while BlueBundlesV1 flash-loans
|
|
63
|
+
* the penalty.
|
|
62
64
|
*
|
|
63
65
|
* @default 90% (900000000000000000n)
|
|
64
66
|
*/
|
|
@@ -66,9 +68,11 @@ export interface VaultV2BluePublicAllocatorOptions {
|
|
|
66
68
|
/**
|
|
67
69
|
* Maximum proportional vault-asset penalty accepted per call, scaled by
|
|
68
70
|
* WAD; higher-penalty vaults are ignored. Must not exceed WAD. Operation
|
|
69
|
-
* plans consider penalty tiers ascending, free first. Each tier
|
|
70
|
-
* source utilization (90% by default) before
|
|
71
|
-
*
|
|
71
|
+
* plans consider penalty tiers ascending, free first. Each tier tries
|
|
72
|
+
* friendly source utilization (90% by default) before falling back to 100%
|
|
73
|
+
* when required coverage remains. Positive-penalty tiers cover the remaining
|
|
74
|
+
* absolute shortfall or, when larger, Blue's loan-token balance deficit while
|
|
75
|
+
* BlueBundlesV1 flash-loans the penalty. Free capacity inside
|
|
72
76
|
* `allocatorCapHeadroom` stays unused, so a penalized leg can cover it.
|
|
73
77
|
* Getters count all vaults up to this limit. For `refinance`, compute the
|
|
74
78
|
* plan on the destination-market handle (for example,
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@morpho-org/morpho-sdk",
|
|
3
3
|
"description": "Abstraction layer for Morpho's complexity.",
|
|
4
|
-
"version": "9.
|
|
4
|
+
"version": "9.2.0",
|
|
5
5
|
"author": "Morpho Association <contact@morpho.org>",
|
|
6
6
|
"repository": {
|
|
7
7
|
"type": "git",
|
|
@@ -150,20 +150,21 @@
|
|
|
150
150
|
"MIGRATION-v5-to-v6.md",
|
|
151
151
|
"MIGRATION-v6-to-v7.md",
|
|
152
152
|
"MIGRATION-v7-to-v8.md",
|
|
153
|
-
"MIGRATION-v8-to-v9.md"
|
|
153
|
+
"MIGRATION-v8-to-v9.md",
|
|
154
|
+
"DEAD-SHARE-PROTECTION.md"
|
|
154
155
|
],
|
|
155
156
|
"dependencies": {
|
|
156
|
-
"@morpho-org/blue-sdk": "^8.0
|
|
157
|
-
"@morpho-org/blue-sdk-viem": "^7.
|
|
158
|
-
"@morpho-org/midnight-sdk": "^2.
|
|
157
|
+
"@morpho-org/blue-sdk": "^8.1.0",
|
|
158
|
+
"@morpho-org/blue-sdk-viem": "^7.2.0",
|
|
159
|
+
"@morpho-org/midnight-sdk": "^2.3.0",
|
|
159
160
|
"@morpho-org/morpho-ts": "^4.1.0"
|
|
160
161
|
},
|
|
161
162
|
"peerDependencies": {
|
|
162
163
|
"viem": "^2.0.0"
|
|
163
164
|
},
|
|
164
165
|
"devDependencies": {
|
|
165
|
-
"@morpho-org/morpho-test": "^4.
|
|
166
|
-
"@morpho-org/test": "^2.
|
|
166
|
+
"@morpho-org/morpho-test": "^4.2.0",
|
|
167
|
+
"@morpho-org/test": "^2.12.0",
|
|
167
168
|
"fast-check": "^4.9.0",
|
|
168
169
|
"typescript": "7.0.2",
|
|
169
170
|
"viem": "^2.55.10",
|