@morpho-org/morpho-sdk 9.1.0-next.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 +7 -1
- package/lib/cjs/abis.d.ts +2 -2
- package/lib/cjs/abis.js +3 -5
- package/lib/cjs/actions/blue/borrow.d.ts +1 -0
- package/lib/cjs/actions/blue/borrow.js +1 -0
- package/lib/cjs/actions/blue/refinance.d.ts +1 -0
- package/lib/cjs/actions/blue/refinance.js +3 -0
- package/lib/cjs/actions/blue/repay.d.ts +1 -0
- package/lib/cjs/actions/blue/repay.js +1 -0
- package/lib/cjs/actions/blue/repayWithdrawCollateral.d.ts +1 -0
- package/lib/cjs/actions/blue/repayWithdrawCollateral.js +2 -0
- package/lib/cjs/actions/blue/supply.d.ts +1 -0
- package/lib/cjs/actions/blue/supply.js +2 -0
- package/lib/cjs/actions/blue/supplyCollateral.d.ts +1 -0
- package/lib/cjs/actions/blue/supplyCollateral.js +1 -0
- package/lib/cjs/actions/blue/supplyCollateralBorrow.d.ts +1 -0
- package/lib/cjs/actions/blue/supplyCollateralBorrow.js +2 -0
- package/lib/cjs/actions/blue/withdraw.d.ts +1 -0
- package/lib/cjs/actions/blue/withdraw.js +2 -0
- package/lib/cjs/actions/blue/withdrawCollateral.d.ts +1 -0
- package/lib/cjs/actions/blue/withdrawCollateral.js +1 -0
- package/lib/cjs/actions/midnight/takeLend.d.ts +1 -0
- package/lib/cjs/actions/midnight/takeLend.js +1 -0
- package/lib/cjs/actions/midnight/takeRepayWithdrawCollateral.d.ts +1 -0
- package/lib/cjs/actions/midnight/takeRepayWithdrawCollateral.js +1 -0
- package/lib/cjs/blue/abis.d.ts +1 -1
- package/lib/cjs/blue/abis.js +1 -5
- package/lib/cjs/blue/constants.d.ts +1 -1
- package/lib/cjs/blue/constants.js +2 -1
- package/lib/cjs/blue/entities.d.ts +4 -4
- package/lib/cjs/blue/entities.js +1 -3
- package/lib/cjs/blue/errors.d.ts +2 -2
- package/lib/cjs/blue/errors.js +2 -5
- package/lib/cjs/blue/fetch.d.ts +2 -2
- package/lib/cjs/blue/fetch.js +1 -3
- package/lib/cjs/blue/utils.d.ts +1 -1
- package/lib/cjs/blue/utils.js +1 -2
- package/lib/cjs/client/morphoViemExtension.d.ts +1 -1
- package/lib/cjs/client/morphoViemExtension.js +1 -7
- package/lib/cjs/constants.d.ts +2 -2
- package/lib/cjs/constants.js +4 -1
- package/lib/cjs/entities/blue/blue.d.ts +112 -21
- package/lib/cjs/entities/blue/blue.js +58 -6
- package/lib/cjs/entities/index.d.ts +4 -4
- package/lib/cjs/entities/index.js +1 -3
- package/lib/cjs/entities/midnight/midnight.d.ts +9 -6
- package/lib/cjs/entities/midnight/midnight.js +12 -9
- package/lib/cjs/entities/midnight/types.d.ts +8 -1
- 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 +16 -34
- package/lib/cjs/entities/vaultV2/vaultV2.js +12 -38
- package/lib/cjs/entities/vaultV2BlueReallocationData.d.ts +77 -19
- package/lib/cjs/entities/vaultV2BlueReallocationData.js +376 -80
- package/lib/cjs/errors.d.ts +4 -4
- package/lib/cjs/errors.js +6 -10
- package/lib/cjs/fetch.d.ts +2 -2
- package/lib/cjs/fetch.js +1 -3
- 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/helpers/validate.d.ts +11 -1
- package/lib/cjs/helpers/validate.js +17 -1
- package/lib/cjs/helpers/validateTakeableOffers.d.ts +4 -2
- package/lib/cjs/helpers/validateTakeableOffers.js +12 -1
- package/lib/cjs/midnight/abis.d.ts +1 -1
- package/lib/cjs/midnight/abis.js +3 -1
- package/lib/cjs/midnight/errors.d.ts +1 -2
- package/lib/cjs/midnight/errors.js +4 -5
- package/lib/cjs/types/error.d.ts +60 -5
- package/lib/cjs/types/error.js +68 -6
- package/lib/cjs/types/sharedLiquidity.d.ts +31 -11
- package/lib/cjs/utils.d.ts +2 -2
- package/lib/cjs/utils.js +2 -4
- package/lib/esm/abis.d.ts +2 -2
- package/lib/esm/abis.js +2 -2
- package/lib/esm/actions/blue/borrow.d.ts +1 -0
- package/lib/esm/actions/blue/borrow.js +1 -0
- package/lib/esm/actions/blue/refinance.d.ts +1 -0
- package/lib/esm/actions/blue/refinance.js +4 -1
- package/lib/esm/actions/blue/repay.d.ts +1 -0
- package/lib/esm/actions/blue/repay.js +1 -0
- package/lib/esm/actions/blue/repayWithdrawCollateral.d.ts +1 -0
- package/lib/esm/actions/blue/repayWithdrawCollateral.js +3 -1
- package/lib/esm/actions/blue/supply.d.ts +1 -0
- package/lib/esm/actions/blue/supply.js +3 -1
- package/lib/esm/actions/blue/supplyCollateral.d.ts +1 -0
- package/lib/esm/actions/blue/supplyCollateral.js +1 -0
- package/lib/esm/actions/blue/supplyCollateralBorrow.d.ts +1 -0
- package/lib/esm/actions/blue/supplyCollateralBorrow.js +3 -1
- package/lib/esm/actions/blue/withdraw.d.ts +1 -0
- package/lib/esm/actions/blue/withdraw.js +3 -1
- package/lib/esm/actions/blue/withdrawCollateral.d.ts +1 -0
- package/lib/esm/actions/blue/withdrawCollateral.js +1 -0
- package/lib/esm/actions/midnight/takeLend.d.ts +1 -0
- package/lib/esm/actions/midnight/takeLend.js +1 -0
- package/lib/esm/actions/midnight/takeRepayWithdrawCollateral.d.ts +1 -0
- package/lib/esm/actions/midnight/takeRepayWithdrawCollateral.js +1 -0
- package/lib/esm/blue/abis.d.ts +1 -1
- package/lib/esm/blue/abis.js +1 -1
- package/lib/esm/blue/constants.d.ts +1 -1
- package/lib/esm/blue/constants.js +1 -1
- package/lib/esm/blue/entities.d.ts +4 -4
- package/lib/esm/blue/entities.js +2 -2
- package/lib/esm/blue/errors.d.ts +2 -2
- package/lib/esm/blue/errors.js +2 -2
- package/lib/esm/blue/fetch.d.ts +2 -2
- package/lib/esm/blue/fetch.js +2 -2
- package/lib/esm/blue/utils.d.ts +1 -1
- package/lib/esm/blue/utils.js +1 -1
- package/lib/esm/client/morphoViemExtension.d.ts +1 -1
- package/lib/esm/client/morphoViemExtension.js +1 -7
- package/lib/esm/constants.d.ts +2 -2
- package/lib/esm/constants.js +2 -2
- package/lib/esm/entities/blue/blue.d.ts +112 -21
- package/lib/esm/entities/blue/blue.js +60 -8
- package/lib/esm/entities/index.d.ts +4 -4
- package/lib/esm/entities/index.js +2 -2
- package/lib/esm/entities/midnight/midnight.d.ts +9 -6
- package/lib/esm/entities/midnight/midnight.js +13 -10
- package/lib/esm/entities/midnight/types.d.ts +8 -1
- 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 +16 -34
- package/lib/esm/entities/vaultV2/vaultV2.js +13 -39
- package/lib/esm/entities/vaultV2BlueReallocationData.d.ts +77 -19
- package/lib/esm/entities/vaultV2BlueReallocationData.js +377 -81
- package/lib/esm/errors.d.ts +4 -4
- package/lib/esm/errors.js +4 -4
- package/lib/esm/fetch.d.ts +2 -2
- package/lib/esm/fetch.js +2 -2
- 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/helpers/validate.d.ts +11 -1
- package/lib/esm/helpers/validate.js +15 -0
- package/lib/esm/helpers/validateTakeableOffers.d.ts +4 -2
- package/lib/esm/helpers/validateTakeableOffers.js +13 -2
- package/lib/esm/midnight/abis.d.ts +1 -1
- package/lib/esm/midnight/abis.js +1 -1
- package/lib/esm/midnight/errors.d.ts +1 -2
- package/lib/esm/midnight/errors.js +1 -2
- package/lib/esm/types/error.d.ts +60 -5
- package/lib/esm/types/error.js +64 -5
- package/lib/esm/types/sharedLiquidity.d.ts +31 -11
- package/lib/esm/utils.d.ts +2 -2
- package/lib/esm/utils.js +2 -2
- package/package.json +9 -8
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { AccrualVaultV2MorphoMarketV1AdapterV2, DEFAULT_SLIPPAGE_TOLERANCE, MarketUtils, MathLib, } from "@morpho-org/blue-sdk";
|
|
1
|
+
import { AccrualVaultV2MorphoMarketV1AdapterV2, DEFAULT_SLIPPAGE_TOLERANCE, MarketParams, MarketUtils, MathLib, } from "@morpho-org/blue-sdk";
|
|
2
2
|
import { erc2612Abi, fetchAccrualVaultV2 } from "@morpho-org/blue-sdk-viem";
|
|
3
3
|
import { _try, getChainAddress, getChainAddresses, Time, } from "@morpho-org/morpho-ts";
|
|
4
4
|
import { erc20Abi, isAddressEqual, maxUint256 } from "viem";
|
|
@@ -6,6 +6,7 @@ import { readContract } from "viem/actions";
|
|
|
6
6
|
import { getBundlesReferralFeeAssets, normalizeBundlesCommonParams, resolveBundlesFunding, selectBundlesSharesPermitSignature, selectBundlesTokenRequirementSignature, } from "../../actions/bundles/common.js";
|
|
7
7
|
import { encodeErc20Approval, encodeVaultSharesPermit, vaultV2Deposit, vaultV2ForceRedeem, vaultV2ForceWithdraw, vaultV2InKindRedeem, vaultV2Redeem, vaultV2Withdraw, } from "../../actions/index.js";
|
|
8
8
|
import { validateClientChainId } from "../../actions/requirements/validateClientChainId.js";
|
|
9
|
+
import { validateVaultV2DeadShares } from "../../helpers/deadShares.js";
|
|
9
10
|
import { computeMinForceWithdrawSharePrice, computeVaultMaxShareAllowance, computeVaultMaxSharePrice, computeVaultV2ForceWithdrawFeeSharesMinted, computeVaultV2ForceWithdrawMinSharesBurnt, computeVaultV2ForceWithdrawPlan, computeVaultV2ForceWithdrawSharesBurnt, MAX_SLIPPAGE_TOLERANCE, resolveVaultV2ForceWithdrawEligibility, validateChainId, validateSlippageTolerance, } from "../../helpers/index.js";
|
|
10
11
|
import { validateDeadline, validateNativeVaultAsset, validateReferralFee, validateUint256Field, } from "../../helpers/validate.js";
|
|
11
12
|
import { AdapterNotPartOfVaultError, EmptyMarketParamsListError, ExpiredDeadlineError, InKindRedeemCoverageError, InKindRedeemZeroDeallocationError, InputExceedsMaxError, InsufficientBlueBalanceForInKindRedeemError, NonPositiveInputError, VaultAddressMismatchError, VaultV2ForceWithdrawCoverageError, VaultV2ForceWithdrawFeeSharesExceedBurnError, VaultV2ForceWithdrawSharePriceBelowFloorError, VaultV2ForceWithdrawZeroSharePriceError, VaultV2ForceWithdrawZeroWithdrawalError, VaultV2SingleAdapterRequiredError, VaultV2UndecodableLiquidityDataError, VaultV2UnsupportedExitAdapterError, VaultV2UnsupportedLiquidityAdapterError, } from "../../types/index.js";
|
|
@@ -15,11 +16,6 @@ import { getBundlesTokenRequirements } from "../requirements/index.js";
|
|
|
15
16
|
// Maximum accepted deadline horizon; the on-chain management fee is capped at 5%/yr so the
|
|
16
17
|
// accrual model stays well-defined inside it.
|
|
17
18
|
const VAULT_V2_FEE_PROJECTION_HORIZON = Time.s.from.y(1n);
|
|
18
|
-
/**
|
|
19
|
-
* Midnight adapters revert vault-initiated `allocate` and `deallocate` (`SelfAllocationOnly`), so a
|
|
20
|
-
* vault routing liquidity through one accepts no deposit and serves exits from idle assets only.
|
|
21
|
-
*/
|
|
22
|
-
const isMidnightLiquidityAdapter = (vaultData) => vaultData.accrualLiquidityAdapter?.type === "VaultV2MidnightAdapter";
|
|
23
19
|
/** Binds a viem client to a Vault V2 vault's action builders. */
|
|
24
20
|
export class MorphoVaultV2 {
|
|
25
21
|
client;
|
|
@@ -83,13 +79,8 @@ export class MorphoVaultV2 {
|
|
|
83
79
|
// The native path must target the chain's registered wrapped-native asset.
|
|
84
80
|
validateNativeVaultAsset(this.chainId, vaultAsset);
|
|
85
81
|
}
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
field: funding.value > 0n ? "nativeAmount" : "amount",
|
|
89
|
-
value: funding.assets,
|
|
90
|
-
max: 0n,
|
|
91
|
-
});
|
|
92
|
-
}
|
|
82
|
+
// Throws when the vault, or a market it can allocate to, lacks a sufficient dead deposit.
|
|
83
|
+
validateVaultV2DeadShares(vaultData);
|
|
93
84
|
const referralFeeAssets = getBundlesReferralFeeAssets(funding.assets, common.referralFeePct);
|
|
94
85
|
const maxSharePrice = computeVaultMaxSharePrice({
|
|
95
86
|
vaultData,
|
|
@@ -173,14 +164,6 @@ export class MorphoVaultV2 {
|
|
|
173
164
|
throw new NonPositiveInputError("amount", amount);
|
|
174
165
|
// Reject values outside the ABI range before resolving any requirements.
|
|
175
166
|
validateUint256Field("amount", amount);
|
|
176
|
-
if (isMidnightLiquidityAdapter(vaultData) &&
|
|
177
|
-
amount > vaultData.assetBalance) {
|
|
178
|
-
throw new InputExceedsMaxError({
|
|
179
|
-
field: "amount",
|
|
180
|
-
value: amount,
|
|
181
|
-
max: vaultData.assetBalance,
|
|
182
|
-
});
|
|
183
|
-
}
|
|
184
167
|
const createdAt = Time.timestamp();
|
|
185
168
|
const deadline = params.deadline ?? createdAt + Time.s.from.h(2n);
|
|
186
169
|
if (deadline <= createdAt)
|
|
@@ -261,20 +244,8 @@ export class MorphoVaultV2 {
|
|
|
261
244
|
if (deadline <= now)
|
|
262
245
|
throw new ExpiredDeadlineError(deadline, now);
|
|
263
246
|
await this.assertWriteTargets(["bundles.vaultBundlesV1"]);
|
|
264
|
-
const vaultData = await this.getData();
|
|
265
|
-
if (isMidnightLiquidityAdapter(vaultData)) {
|
|
266
|
-
// Onchain redeem accrues interest before converting shares to assets.
|
|
267
|
-
const { vault: accrued } = vaultData.accrueInterest(now);
|
|
268
|
-
if (accrued.toAssets(shares) > accrued.assetBalance) {
|
|
269
|
-
throw new InputExceedsMaxError({
|
|
270
|
-
field: "shares",
|
|
271
|
-
value: shares,
|
|
272
|
-
max: accrued.toShares(accrued.assetBalance),
|
|
273
|
-
});
|
|
274
|
-
}
|
|
275
|
-
}
|
|
276
247
|
return getVaultBundlesSharesRequirements(this.client.viemClient, {
|
|
277
|
-
vaultData,
|
|
248
|
+
vaultData: await this.getData(),
|
|
278
249
|
version: "vaultV2",
|
|
279
250
|
owner: userAddress,
|
|
280
251
|
chainId: this.chainId,
|
|
@@ -726,15 +697,18 @@ export class MorphoVaultV2 {
|
|
|
726
697
|
}
|
|
727
698
|
forceRedeem({ deallocations, redeem, userAddress, }) {
|
|
728
699
|
validateChainId(this.client.viemClient.chain?.id, this.chainId);
|
|
700
|
+
const shares = redeem.shares;
|
|
701
|
+
const deallocationsSnapshot = deallocations.map(({ adapter, marketParams, amount }) => ({
|
|
702
|
+
adapter,
|
|
703
|
+
amount,
|
|
704
|
+
...(marketParams && { marketParams: new MarketParams(marketParams) }),
|
|
705
|
+
}));
|
|
729
706
|
return {
|
|
730
707
|
buildTx: () => vaultV2ForceRedeem({
|
|
731
708
|
vault: { address: this.vault },
|
|
732
709
|
args: {
|
|
733
|
-
deallocations,
|
|
734
|
-
redeem: {
|
|
735
|
-
shares: redeem.shares,
|
|
736
|
-
recipient: userAddress,
|
|
737
|
-
},
|
|
710
|
+
deallocations: deallocationsSnapshot,
|
|
711
|
+
redeem: { shares, recipient: userAddress },
|
|
738
712
|
onBehalf: userAddress,
|
|
739
713
|
},
|
|
740
714
|
metadata: this.client.options.metadata,
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { AccrualVaultV2, AccrualVaultV2MorphoMarketV1AdapterV2, type IAccrualVaultV2Adapter, type IVaultV2Allocation, type IVaultV2BlueMarketPublicAllocatorConfig, type IVaultV2BluePublicAllocatorConfig, Market, type MarketId, VaultV2BlueMarketPublicAllocatorConfig, VaultV2BluePublicAllocatorConfig } from "@morpho-org/blue-sdk";
|
|
1
|
+
import { AccrualVaultV2, AccrualVaultV2MorphoMarketV1AdapterV2, type BigIntish, type IAccrualVaultV2Adapter, type IVaultV2Allocation, type IVaultV2BlueMarketPublicAllocatorConfig, type IVaultV2BluePublicAllocatorConfig, Market, type MarketId, VaultV2BlueMarketPublicAllocatorConfig, VaultV2BluePublicAllocatorConfig } from "@morpho-org/blue-sdk";
|
|
2
2
|
import { type Address, type Hash } from "viem";
|
|
3
3
|
import type { VaultV2BluePublicAllocatorOptions, VaultV2BlueReallocation } from "../types/index.js";
|
|
4
4
|
type ReadonlyMarketSnapshot = Readonly<Market>;
|
|
@@ -19,6 +19,23 @@ type ReadonlyVaultSnapshot = Readonly<Omit<AccrualVaultV2, "adapters" | "liquidi
|
|
|
19
19
|
export interface InputVaultV2BlueReallocationData {
|
|
20
20
|
/** Chain id associated with the fetched state. */
|
|
21
21
|
readonly chainId: number;
|
|
22
|
+
/**
|
|
23
|
+
* Timestamp of the block the state was fetched at. When present, this is the
|
|
24
|
+
* default planning timestamp when `options.timestamp` is omitted, never
|
|
25
|
+
* earlier than the latest market/vault `lastUpdate`; when absent, planning
|
|
26
|
+
* defaults to the latest market/vault `lastUpdate`.
|
|
27
|
+
*/
|
|
28
|
+
readonly timestamp?: BigIntish;
|
|
29
|
+
/**
|
|
30
|
+
* Morpho Blue's ERC-20 balances at the snapshot block, indexed by token address.
|
|
31
|
+
* Explicit balances increase with idle-sourced reallocations in returned
|
|
32
|
+
* post-states. Sizing has zero margin over the snapshot balance, so activity
|
|
33
|
+
* on other Blue markets with the same loan token can make a plan revert;
|
|
34
|
+
* refetch close to submission. A missing token uses summed non-negative
|
|
35
|
+
* snapshot-market supply-minus-borrow only to size plans; balance-based
|
|
36
|
+
* rejection requires an explicit balance.
|
|
37
|
+
*/
|
|
38
|
+
readonly blueBalances?: Readonly<Record<Address, BigIntish | undefined>>;
|
|
22
39
|
/** Markets indexed by market id. */
|
|
23
40
|
readonly markets?: Readonly<Record<MarketId, ReadonlyMarketSnapshot | undefined>>;
|
|
24
41
|
/** Accrued Vault V2 entities indexed by vault address. */
|
|
@@ -39,9 +56,8 @@ export interface InputVaultV2BlueReallocationData {
|
|
|
39
56
|
/**
|
|
40
57
|
* Immutable-by-convention state container for Vault V2 BluePublicAllocator simulations.
|
|
41
58
|
*
|
|
42
|
-
* Constructor inputs are cloned
|
|
43
|
-
*
|
|
44
|
-
* reallocation returns a new instance. Planning keeps the transaction-scoped `firstTotalAssets`
|
|
59
|
+
* Constructor inputs are cloned. Every simulated reallocation returns a new
|
|
60
|
+
* instance. Planning keeps the transaction-scoped `firstTotalAssets`
|
|
45
61
|
* denominator outside the durable snapshot while applying reallocations in
|
|
46
62
|
* contract order. Penalty donations update simulated vault accounting but are
|
|
47
63
|
* excluded from same-plan idle liquidity so round-up dust cannot create
|
|
@@ -77,8 +93,22 @@ export declare class VaultV2BlueReallocationData implements InputVaultV2BlueReal
|
|
|
77
93
|
private readonly mutableVaults;
|
|
78
94
|
/** Mutable allocation state used only by cloned simulation transitions. */
|
|
79
95
|
private readonly mutableAllocations;
|
|
96
|
+
/** Mutable Blue token balances used only by cloned simulation transitions. */
|
|
97
|
+
private readonly mutableBlueBalances;
|
|
80
98
|
/** Chain id associated with this snapshot. */
|
|
81
99
|
readonly chainId: number;
|
|
100
|
+
/** Timestamp of the block the state was fetched at. */
|
|
101
|
+
readonly timestamp?: bigint;
|
|
102
|
+
/**
|
|
103
|
+
* Morpho Blue's ERC-20 balances at the snapshot block, indexed by token address.
|
|
104
|
+
* Explicit balances increase with idle-sourced reallocations in returned
|
|
105
|
+
* post-states. Sizing has zero margin over the snapshot balance, so activity
|
|
106
|
+
* on other Blue markets with the same loan token can make a plan revert;
|
|
107
|
+
* refetch close to submission. A missing token uses summed non-negative
|
|
108
|
+
* snapshot-market supply-minus-borrow only to size plans; balance-based
|
|
109
|
+
* rejection requires an explicit balance.
|
|
110
|
+
*/
|
|
111
|
+
readonly blueBalances: Readonly<Record<Address, bigint | undefined>>;
|
|
82
112
|
/** Markets indexed by market id. */
|
|
83
113
|
readonly markets: Readonly<Record<MarketId, ReadonlyMarketSnapshot | undefined>>;
|
|
84
114
|
/** Vault V2 entities indexed by address. */
|
|
@@ -101,8 +131,7 @@ export declare class VaultV2BlueReallocationData implements InputVaultV2BlueReal
|
|
|
101
131
|
/**
|
|
102
132
|
* Clones the complete simulation snapshot.
|
|
103
133
|
*
|
|
104
|
-
* @returns A deep clone of this simulation state.
|
|
105
|
-
* shared by reference and must be treated as read-only.
|
|
134
|
+
* @returns A deep clone of this simulation state.
|
|
106
135
|
* @example
|
|
107
136
|
* ```ts
|
|
108
137
|
* import { markets } from "@morpho-org/morpho-test";
|
|
@@ -358,16 +387,40 @@ export declare class VaultV2BlueReallocationData implements InputVaultV2BlueReal
|
|
|
358
387
|
* Computes Vault V2 BluePublicAllocator calls available for a target market.
|
|
359
388
|
*
|
|
360
389
|
* Without `options.operation`, discovers every friendly call. With an
|
|
361
|
-
* operation,
|
|
362
|
-
*
|
|
363
|
-
*
|
|
364
|
-
*
|
|
365
|
-
*
|
|
366
|
-
*
|
|
367
|
-
* `
|
|
368
|
-
*
|
|
369
|
-
* `
|
|
370
|
-
*
|
|
390
|
+
* operation, penalty tiers are considered ascending, starting with free
|
|
391
|
+
* vaults. The free tier aims to bring the target market back to 90%
|
|
392
|
+
* utilization; positive tiers cover the remaining absolute shortfall or,
|
|
393
|
+
* when larger, Blue's loan-token balance deficit while the penalty is
|
|
394
|
+
* flash-loaned. Within each tier, source markets go to the
|
|
395
|
+
* friendly source utilization (90% by default) before 100%. Free capacity
|
|
396
|
+
* inside `allocatorCapHeadroom` is kept unused, so a penalized leg can cover
|
|
397
|
+
* it instead. Discovery and liquidity getters still count every vault up to
|
|
398
|
+
* `options.maxPenalty`. A shared relative-cap lower bound may require one call
|
|
399
|
+
* to exceed the targeted amount. For `refinance`, compute the plan on the
|
|
400
|
+
* destination-market handle (for example,
|
|
401
|
+
* `client.morpho.blue(destination.marketParams, chainId)`), not the source
|
|
402
|
+
* handle. Pass the source position's `borrowAssets` accrued to
|
|
403
|
+
* `max(now, source.lastUpdate, destination.lastUpdate) + 2h` as
|
|
404
|
+
* `operation.amount`; the optional `operation.referralFeePct` is WAD-scaled.
|
|
405
|
+
* The planner includes the referral fee and its allocator-leg penalties in
|
|
406
|
+
* destination debt, so penalized legs also cover their own penalty.
|
|
407
|
+
* Refinance never uses vaults with a 100% penalty.
|
|
408
|
+
* BlueBundlesV1 flash-loans the plan's penalty from Blue before executing
|
|
409
|
+
* reallocation legs. When an explicit `blueBalances` value is supplied, plans
|
|
410
|
+
* throw `InsufficientSharedLiquidityError` if Blue cannot fund that flash
|
|
411
|
+
* loan or a market-sourced leg's withdrawal before later idle legs arrive.
|
|
412
|
+
* Legs are not reordered. A missing balance falls back to summed snapshot-
|
|
413
|
+
* market liquidity only to size plans and may make them larger; it cannot
|
|
414
|
+
* cause rejection for Blue-balance constraints.
|
|
415
|
+
* Sizing has zero margin over the snapshot balance; activity on other Blue
|
|
416
|
+
* markets with the same loan token can make a plan revert. Refetch close to
|
|
417
|
+
* submission; there is no balance-buffer option.
|
|
418
|
+
* Friendly source utilization defaults to 90% and is configurable through
|
|
419
|
+
* `options.maxWithdrawalUtilization`. Market/vault state and the returned
|
|
420
|
+
* post-state stay at `timestamp`. An enabled operation that needs no
|
|
421
|
+
* reallocation still returns a clone accrued to `timestamp`. Only
|
|
422
|
+
* target-market cap checks reserve interest the vault's existing allocation
|
|
423
|
+
* would accrue through `timestamp + capAccrualBuffer`
|
|
371
424
|
* (two hours by default; `0n` disables it). When an operation's plan would
|
|
372
425
|
* come within `allocatorCapHeadroom` (1% of the cap by default) of a target
|
|
373
426
|
* BluePublicAllocator cap, the plan is reduced to the larger of the
|
|
@@ -408,8 +461,9 @@ export declare class VaultV2BlueReallocationData implements InputVaultV2BlueReal
|
|
|
408
461
|
* every leg of a plan.
|
|
409
462
|
* @returns Flat action-ready reallocations and their post-simulation state.
|
|
410
463
|
* @throws {UnsupportedBlueMarketIrmError} when a market with positive debt uses an unsupported IRM.
|
|
411
|
-
* @throws {NegativeInputError} when `capAccrualBuffer`, `allocatorCapHeadroom`, `maxWithdrawalUtilization`, or `
|
|
412
|
-
* @throws {InputExceedsMaxError} when `allocatorCapHeadroom`, `maxWithdrawalUtilization`, or `maxPenalty` exceeds WAD.
|
|
464
|
+
* @throws {NegativeInputError} when `capAccrualBuffer`, `allocatorCapHeadroom`, `maxWithdrawalUtilization`, `maxPenalty`, or `referralFeePct` is negative.
|
|
465
|
+
* @throws {InputExceedsMaxError} when `allocatorCapHeadroom`, `maxWithdrawalUtilization`, or `maxPenalty` exceeds WAD, or an enabled borrow/withdraw plan otherwise covers its shortfall but its planned penalty exceeds the operation amount.
|
|
466
|
+
* @throws {ReferralFeePctExceededError} when `referralFeePct` is at least WAD.
|
|
413
467
|
* @throws {NonPositiveInputError} when the operation amount is not positive and planning is enabled.
|
|
414
468
|
* @throws {UnknownReallocationMarketError} when a required market is absent.
|
|
415
469
|
* @throws {UnknownReallocationVaultError} when configured vault state is absent.
|
|
@@ -417,7 +471,7 @@ export declare class VaultV2BlueReallocationData implements InputVaultV2BlueReal
|
|
|
417
471
|
* @throws {UnknownReallocationActiveAdaptersError} when active-adapter state is absent for a vault.
|
|
418
472
|
* @throws {UnknownReallocationMarketPublicAllocatorConfigError} when an adapter-market allocator configuration is absent.
|
|
419
473
|
* @throws {UnknownReallocationAllocationError} when required allocation state is absent.
|
|
420
|
-
* @throws {InsufficientSharedLiquidityError} when selected liquidity cannot cover the
|
|
474
|
+
* @throws {InsufficientSharedLiquidityError} when selected liquidity cannot cover the operation shortfall or refinance penalties, or an explicit Blue balance cannot fund the penalty flash loan, an earlier market-sourced withdrawal, or the final operation transfer.
|
|
421
475
|
* @throws {ReallocationWithdrawExceedsMarketSupplyError} when a withdraw exceeds market supply.
|
|
422
476
|
* @example
|
|
423
477
|
* ```ts
|
|
@@ -452,6 +506,10 @@ export declare class VaultV2BlueReallocationData implements InputVaultV2BlueReal
|
|
|
452
506
|
readonly operation?: {
|
|
453
507
|
readonly type: "borrow" | "withdraw";
|
|
454
508
|
readonly amount: bigint;
|
|
509
|
+
} | {
|
|
510
|
+
readonly type: "refinance";
|
|
511
|
+
readonly amount: bigint;
|
|
512
|
+
readonly referralFeePct?: bigint;
|
|
455
513
|
};
|
|
456
514
|
}): {
|
|
457
515
|
readonly reallocations: readonly VaultV2BlueReallocation[];
|