@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,12 +1,15 @@
|
|
|
1
1
|
import { MathLib, } from "@morpho-org/blue-sdk";
|
|
2
2
|
import { fetchAccrualPosition, fetchAccrualVaultV2, fetchMarket, fetchVaultV2BluePublicAllocatorData, } from "@morpho-org/blue-sdk-viem";
|
|
3
3
|
import { getChainAddress, getChainAddresses, Time, } from "@morpho-org/morpho-ts";
|
|
4
|
-
import { isAddressEqual, maxUint256 } from "viem";
|
|
4
|
+
import { erc20Abi, isAddressEqual, maxUint256 } from "viem";
|
|
5
|
+
import { readContract } from "viem/actions";
|
|
5
6
|
import { getBlueBundlesV1PenaltyAssets, getBlueBundlesV1PublicAllocations, getBlueBundlesV1ReferralFeeAssets, normalizeBlueBundlesV1CommonParams, selectBlueBundlesV1RequirementSignatures, validateBlueBundlesV1NativeFunding, } from "../../actions/blue/common.js";
|
|
6
7
|
import { blueBorrow, blueRefinance, blueRepay, blueRepayWithdrawCollateral, blueSupply, blueSupplyCollateral, blueSupplyCollateralBorrow, blueWithdraw, blueWithdrawCollateral, getBlueAuthorizationRequirement, } from "../../actions/index.js";
|
|
7
8
|
import { validateClientChainId } from "../../actions/requirements/validateClientChainId.js";
|
|
9
|
+
import { validateBlueMarketDeadShares } from "../../helpers/deadShares.js";
|
|
8
10
|
import { DEFAULT_LLTV_BUFFER, validateAccrualPosition, validateChainId, validatePositionHealth, validatePositionHealthAfterWithdraw, validateRepayAmount, validateRepayShares, validateWithdrawAmount, validateWithdrawShares, } from "../../helpers/index.js";
|
|
9
|
-
import {
|
|
11
|
+
import { validateMarketParamsId } from "../../helpers/validate.js";
|
|
12
|
+
import { ExpiredDeadlineError, InputExceedsMaxError, MarketIdMismatchError, MaxRepayAssetsBelowRepayAssetsError, MissingAccrualPositionError, MutuallyExclusiveRepayAmountsError, MutuallyExclusiveWithdrawAmountsError, NegativeInputError, NonPositiveInputError, ReallocationsRequireBorrowError, RefinanceSameMarketError, RefinanceTokenMismatchError, } from "../../types/index.js";
|
|
10
13
|
import { assertRegistryTargetsHaveCode } from "../requirements/assertContractCode.js";
|
|
11
14
|
import { getBundlesTokenRequirements } from "../requirements/index.js";
|
|
12
15
|
import { VaultV2BlueReallocationData } from "../vaultV2BlueReallocationData.js";
|
|
@@ -15,11 +18,20 @@ export class MorphoBlue {
|
|
|
15
18
|
client;
|
|
16
19
|
marketParams;
|
|
17
20
|
chainId;
|
|
21
|
+
/**
|
|
22
|
+
* Binds `client` to the market described by `marketParams` on `chainId`.
|
|
23
|
+
*
|
|
24
|
+
* @param client - Morpho client used for reads and requirement lookups.
|
|
25
|
+
* @param marketParams - Market params whose `id` must hash from their five tuple fields.
|
|
26
|
+
* @param chainId - Chain the market lives on.
|
|
27
|
+
* @throws {MarketIdMismatchError} when `marketParams.id` does not hash from its tuple fields.
|
|
28
|
+
*/
|
|
18
29
|
// biome-ignore lint/complexity/useMaxParams: TODO refactor to ≤2 params
|
|
19
30
|
constructor(client, marketParams, chainId) {
|
|
20
31
|
this.client = client;
|
|
21
32
|
this.marketParams = marketParams;
|
|
22
33
|
this.chainId = chainId;
|
|
34
|
+
validateMarketParamsId(marketParams);
|
|
23
35
|
}
|
|
24
36
|
validateDeadline(deadline, now = Time.timestamp()) {
|
|
25
37
|
if (deadline <= now) {
|
|
@@ -114,7 +126,6 @@ export class MorphoBlue {
|
|
|
114
126
|
deployless: this.client.options.supportDeployless,
|
|
115
127
|
});
|
|
116
128
|
}
|
|
117
|
-
/** {@inheritDoc BlueActions.supply} */
|
|
118
129
|
supply(params) {
|
|
119
130
|
const { userAddress, assets, nativeAmount, deadline, referralFeePct, referralFeeRecipient, } = params;
|
|
120
131
|
this.validateWriteCommon(params);
|
|
@@ -126,6 +137,13 @@ export class MorphoBlue {
|
|
|
126
137
|
fundedAmount: assets,
|
|
127
138
|
nativeAmount,
|
|
128
139
|
});
|
|
140
|
+
if (params.marketData != null) {
|
|
141
|
+
if (params.marketData.id !== this.marketParams.id) {
|
|
142
|
+
throw new MarketIdMismatchError(params.marketData.id, this.marketParams.id);
|
|
143
|
+
}
|
|
144
|
+
// Throws when the market lacks a sufficient dead deposit; nothing to return.
|
|
145
|
+
validateBlueMarketDeadShares(params.marketData);
|
|
146
|
+
}
|
|
129
147
|
return {
|
|
130
148
|
getRequirements: (requirementsParams) => {
|
|
131
149
|
const now = Time.timestamp();
|
|
@@ -637,6 +655,7 @@ export class MorphoBlue {
|
|
|
637
655
|
refinance(params) {
|
|
638
656
|
const { userAddress, positionData, destination, deadline, referralFeeRecipient, } = params;
|
|
639
657
|
this.validateWriteCommon(params);
|
|
658
|
+
validateMarketParamsId(destination.marketParams);
|
|
640
659
|
// `validateWriteCommon` returns void, so default an omitted `referralFeePct` to `0n`
|
|
641
660
|
// here, matching the pure action's normalization.
|
|
642
661
|
const referralFeePct = params.referralFeePct ?? 0n;
|
|
@@ -720,10 +739,20 @@ export class MorphoBlue {
|
|
|
720
739
|
*
|
|
721
740
|
* Reads the target Morpho Blue market, each Vault V2 accrual tree, and each
|
|
722
741
|
* vault's BluePublicAllocator permissions and allocation caps at one block.
|
|
742
|
+
* The snapshot keeps the fetched block's timestamp as its default planning time.
|
|
743
|
+
* It always records Blue's loan-token balance in `blueBalances` at that
|
|
744
|
+
* block, so balance-based rejection applies to plans from this fetcher.
|
|
745
|
+
* Sizing has zero margin over that snapshot balance; activity on other Blue
|
|
746
|
+
* markets with the same loan token can make a plan revert. Refetch close to
|
|
747
|
+
* submission; there is no balance-buffer option.
|
|
748
|
+
* Hand-built data without a balance uses summed snapshot-market liquidity
|
|
749
|
+
* only to size plans and may add about the penalty in extra paid assets.
|
|
723
750
|
*
|
|
724
751
|
* @param params.vaultAddresses - Vault V2 addresses to inspect for market or idle liquidity.
|
|
725
752
|
* @param params.block.number - Block number used for every RPC read.
|
|
726
|
-
* @param params.block.timestamp - Timestamp
|
|
753
|
+
* @param params.block.timestamp - Timestamp of the fetched block. Stored on the snapshot and used as the
|
|
754
|
+
* planning timestamp when `options.timestamp` is omitted, never earlier than the latest market/vault
|
|
755
|
+
* `lastUpdate`. An explicit `options.timestamp` is used as given.
|
|
727
756
|
* @returns A `VaultV2BlueReallocationData` snapshot ready for {@link getVaultV2BlueReallocations}.
|
|
728
757
|
* @throws {ChainIdMismatchError} when the client declares another chain or its RPC reports another
|
|
729
758
|
* chain via `eth_chainId`.
|
|
@@ -766,7 +795,7 @@ export class MorphoBlue {
|
|
|
766
795
|
chainId: this.chainId,
|
|
767
796
|
deployless: this.client.options.supportDeployless,
|
|
768
797
|
};
|
|
769
|
-
const [targetMarket, vaultEntries] = await Promise.all([
|
|
798
|
+
const [targetMarket, vaultEntries, blueBalance] = await Promise.all([
|
|
770
799
|
fetchMarket(this.marketParams.id, client, fetchParams),
|
|
771
800
|
Promise.all(vaultAddresses.map(async (address) => {
|
|
772
801
|
const vault = await fetchAccrualVaultV2(address, client, fetchParams);
|
|
@@ -776,9 +805,18 @@ export class MorphoBlue {
|
|
|
776
805
|
});
|
|
777
806
|
return { publicAllocatorData, vault };
|
|
778
807
|
})),
|
|
808
|
+
readContract(client, {
|
|
809
|
+
address: this.marketParams.loanToken,
|
|
810
|
+
abi: erc20Abi,
|
|
811
|
+
functionName: "balanceOf",
|
|
812
|
+
args: [getChainAddresses(this.chainId).blue],
|
|
813
|
+
blockNumber: block.number,
|
|
814
|
+
}),
|
|
779
815
|
]);
|
|
780
816
|
return new VaultV2BlueReallocationData({
|
|
781
817
|
chainId: this.chainId,
|
|
818
|
+
timestamp: block.timestamp,
|
|
819
|
+
blueBalances: { [this.marketParams.loanToken]: blueBalance },
|
|
782
820
|
markets: { [targetMarket.id]: targetMarket },
|
|
783
821
|
vaults: Object.fromEntries(vaultEntries.map(({ vault }) => [vault.address, vault])),
|
|
784
822
|
allocations: Object.fromEntries(vaultEntries.map(({ publicAllocatorData, vault }) => [
|
|
@@ -809,14 +847,28 @@ export class MorphoBlue {
|
|
|
809
847
|
* persist across every leg of a plan. Operation plans keep
|
|
810
848
|
* `allocatorCapHeadroom` (1% of the cap by default) free under each target
|
|
811
849
|
* BluePublicAllocator cap unless the operation shortfall needs it.
|
|
850
|
+
* With an explicit `blueBalances` value, plans are rejected when Blue cannot
|
|
851
|
+
* fund the penalty flash loan, an earlier market-sourced withdrawal, or the
|
|
852
|
+
* final transfer. A missing balance uses summed snapshot-market liquidity
|
|
853
|
+
* only to size plans and may make them larger; it cannot cause a balance-based
|
|
854
|
+
* rejection.
|
|
855
|
+
* For `refinance`, compute the plan on the destination-market handle (for
|
|
856
|
+
* example, `client.morpho.blue(destination.marketParams, chainId)`), not the
|
|
857
|
+
* source-market handle. Pass the source position's `borrowAssets` accrued to
|
|
858
|
+
* `max(now, source.lastUpdate, destination.lastUpdate) + 2h` as
|
|
859
|
+
* `operation.amount`; the optional `operation.referralFeePct` is WAD-scaled.
|
|
860
|
+
* The planner includes the referral fee and its own planned allocator-leg
|
|
861
|
+
* penalties in destination debt. Refinance never uses vaults with a 100%
|
|
862
|
+
* penalty.
|
|
812
863
|
*
|
|
813
864
|
* @param params.reallocationData - State returned by {@link getVaultV2BlueReallocationData}.
|
|
814
865
|
* @param params.options - Optional allocator discovery controls and operation to support.
|
|
815
866
|
* @returns Action-ready reallocations and their post-simulation state.
|
|
816
867
|
* @throws {ChainIdMismatchError} when `reallocationData` belongs to another chain.
|
|
817
868
|
* @throws {UnsupportedBlueMarketIrmError} when a market with positive debt uses an unsupported IRM.
|
|
818
|
-
* @throws {NegativeInputError} when the cap-accrual buffer, allocator cap headroom, utilization,
|
|
819
|
-
* @throws {InputExceedsMaxError} when the allocator cap headroom, a utilization, or a penalty limit exceeds WAD.
|
|
869
|
+
* @throws {NegativeInputError} when the cap-accrual buffer, allocator cap headroom, utilization, penalty limit, or referral-fee percentage is negative.
|
|
870
|
+
* @throws {InputExceedsMaxError} when the allocator cap headroom, a utilization, or a penalty limit exceeds WAD, or a selected borrow/withdraw plan otherwise covers its shortfall but its planned penalty exceeds the operation amount.
|
|
871
|
+
* @throws {ReferralFeePctExceededError} when the referral-fee percentage is at least WAD.
|
|
820
872
|
* @throws {NonPositiveInputError} when an enabled operation amount is not positive.
|
|
821
873
|
* @throws {UnknownReallocationMarketError} when a required market is absent.
|
|
822
874
|
* @throws {UnknownReallocationVaultError} when configured vault state is absent.
|
|
@@ -826,7 +878,7 @@ export class MorphoBlue {
|
|
|
826
878
|
* @throws {UnknownReallocationAllocationError} when required allocation state is absent.
|
|
827
879
|
* @throws {ReallocationAdapterSupplySharesUnderflowError} when an inconsistent adapter snapshot underflows during the final transition.
|
|
828
880
|
* @throws {ReallocationAllocationUnderflowError} when an inconsistent allocation snapshot underflows during the final transition.
|
|
829
|
-
* @throws {InsufficientSharedLiquidityError} when selected liquidity cannot cover the shortfall.
|
|
881
|
+
* @throws {InsufficientSharedLiquidityError} when selected liquidity cannot cover the operation shortfall or refinance penalties, or an explicit Blue balance cannot fund a required transfer.
|
|
830
882
|
* @throws {ReallocationWithdrawExceedsMarketSupplyError} when a withdrawal exceeds market supply.
|
|
831
883
|
* @example
|
|
832
884
|
* ```ts
|
|
@@ -1,13 +1,13 @@
|
|
|
1
|
-
export type { IAccrualPosition as IBlueAccrualPosition, IAccrualVault, IAccrualVaultV2, IAccrualVaultV2Adapter,
|
|
1
|
+
export type { IAccrualPosition as IBlueAccrualPosition, IAccrualVault, IAccrualVaultV2, IAccrualVaultV2Adapter, IAccrualVaultV2MorphoMarketV1Adapter, IAccrualVaultV2MorphoMarketV1AdapterV2, IAccrualVaultV2MorphoVaultV1Adapter, IAssetBalances, IEip5267Domain, IHolding, IMarket as IBlueMarket, IMarketParams as IBlueMarketParams, IPosition as IBluePosition,
|
|
2
2
|
/** @deprecated Pre-liquidation support is deprecated and will be removed in the next major. */
|
|
3
3
|
IPreLiquidationParams as IBluePreLiquidationParams,
|
|
4
4
|
/** @deprecated Pre-liquidation support is deprecated and will be removed in the next major. */
|
|
5
|
-
IPreLiquidationPosition as IBluePreLiquidationPosition, IToken, IVault, IVaultConfig, IVaultMarketAllocation, IVaultMarketConfig, IVaultToken, IVaultUser, IVaultV2, IVaultV2Adapter, IVaultV2Allocation, IVaultV2BlueMarketPublicAllocatorConfig, IVaultV2BluePublicAllocatorConfig,
|
|
6
|
-
export { AccrualPosition as BlueAccrualPosition, AccrualVault, AccrualVaultV2,
|
|
5
|
+
IPreLiquidationPosition as IBluePreLiquidationPosition, IToken, IVault, IVaultConfig, IVaultMarketAllocation, IVaultMarketConfig, IVaultToken, IVaultUser, IVaultV2, IVaultV2Adapter, IVaultV2Allocation, IVaultV2BlueMarketPublicAllocatorConfig, IVaultV2BluePublicAllocatorConfig, IVaultV2MorphoMarketV1Adapter, IVaultV2MorphoMarketV1AdapterV2, IVaultV2MorphoVaultV1Adapter, PeripheralBalance, PeripheralBalanceType, } from "@morpho-org/blue-sdk";
|
|
6
|
+
export { AccrualPosition as BlueAccrualPosition, AccrualVault, AccrualVaultV2, AccrualVaultV2MorphoMarketV1Adapter, AccrualVaultV2MorphoMarketV1AdapterV2, AccrualVaultV2MorphoVaultV1Adapter, AssetBalances, ConstantWrappedToken, Eip5267Domain, ExchangeRateWrappedToken, Holding, Market as BlueMarket, MarketParams as BlueMarketParams, Position as BluePosition,
|
|
7
7
|
/** @deprecated Pre-liquidation support is deprecated and will be removed in the next major. */
|
|
8
8
|
PreLiquidationParams as BluePreLiquidationParams,
|
|
9
9
|
/** @deprecated Pre-liquidation support is deprecated and will be removed in the next major. */
|
|
10
|
-
PreLiquidationPosition as BluePreLiquidationPosition, Token, User as BlueUser, Vault, VaultConfig, VaultMarketAllocation, VaultMarketConfig, VaultToken, VaultUser, VaultV2, VaultV2Adapter, VaultV2BlueMarketPublicAllocatorConfig, VaultV2BluePublicAllocatorConfig,
|
|
10
|
+
PreLiquidationPosition as BluePreLiquidationPosition, Token, User as BlueUser, Vault, VaultConfig, VaultMarketAllocation, VaultMarketConfig, VaultToken, VaultUser, VaultV2, VaultV2Adapter, VaultV2BlueMarketPublicAllocatorConfig, VaultV2BluePublicAllocatorConfig, VaultV2MorphoMarketV1Adapter, VaultV2MorphoMarketV1AdapterV2, VaultV2MorphoVaultV1Adapter, WrappedToken, } from "@morpho-org/blue-sdk";
|
|
11
11
|
export type { AnyTree as MidnightAnyTree, AnyTreeSnapshot as MidnightAnyTreeSnapshot, BuildOfferParams as MidnightBuildOfferParams, CollateralParams as MidnightCollateralParams, EcrecoverTreeCreateRequest as MidnightEcrecoverTreeCreateRequest, GroupInput as MidnightGroupInput, IAccrualPosition as IMidnightAccrualPosition, ICollateralParams as IMidnightCollateralParams, IGroup as IMidnightGroup, IMarket as IMidnightMarket, IMarketParams as IMidnightMarketParams, IOffer as IMidnightOffer, IPosition as IMidnightPosition, MarketInput as MidnightMarketInput, OfferStruct as MidnightOfferStruct, PriceRatifierV1TreeCreateRequest as MidnightPriceRatifierV1TreeCreateRequest, RateRatifierV1TreeCreateRequest as MidnightRateRatifierV1TreeCreateRequest, RatifierKind as MidnightRatifierKind, RatifierTreeInput as MidnightRatifierTreeInput, RatifierTypes as MidnightRatifierTypes, SetterTreeCreateRequest as MidnightSetterTreeCreateRequest, SettlementFeeCbps as MidnightSettlementFeeCbps, TreeCreateParams as MidnightTreeCreateParams, TreeCreateRequest as MidnightTreeCreateRequest, TreeData as MidnightTreeData, TreeDescriptor as MidnightTreeDescriptor, TreeEntry as MidnightTreeEntry, TreeInput as MidnightTreeInput, TreeLike as MidnightTreeLike, TreeMempoolValidateParams as MidnightTreeMempoolValidateParams, TreeMempoolValidateRatification as MidnightTreeMempoolValidateRatification, TreeProof as MidnightTreeProof, TreeSnapshot as MidnightTreeSnapshot, TypedRatifierTreeInput as MidnightTypedRatifierTreeInput, TypedTreeMempoolValidateParams as MidnightTypedTreeMempoolValidateParams, } from "@morpho-org/midnight-sdk";
|
|
12
12
|
export { AccrualPosition as MidnightAccrualPosition, Group as MidnightGroup, Market as MidnightMarket, MarketParams as MidnightMarketParams, Offer as MidnightOffer, Position as MidnightPosition, Tree as MidnightTree, } from "@morpho-org/midnight-sdk";
|
|
13
13
|
export type { BlueActions, BlueTokenRequirementsParams, } from "./blue/index.js";
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
export { AccrualPosition as BlueAccrualPosition, AccrualVault, AccrualVaultV2,
|
|
1
|
+
export { AccrualPosition as BlueAccrualPosition, AccrualVault, AccrualVaultV2, AccrualVaultV2MorphoMarketV1Adapter, AccrualVaultV2MorphoMarketV1AdapterV2, AccrualVaultV2MorphoVaultV1Adapter, AssetBalances, ConstantWrappedToken, Eip5267Domain, ExchangeRateWrappedToken, Holding, Market as BlueMarket, MarketParams as BlueMarketParams, Position as BluePosition,
|
|
2
2
|
/** @deprecated Pre-liquidation support is deprecated and will be removed in the next major. */
|
|
3
3
|
PreLiquidationParams as BluePreLiquidationParams,
|
|
4
4
|
/** @deprecated Pre-liquidation support is deprecated and will be removed in the next major. */
|
|
5
|
-
PreLiquidationPosition as BluePreLiquidationPosition, Token, User as BlueUser, Vault, VaultConfig, VaultMarketAllocation, VaultMarketConfig, VaultToken, VaultUser, VaultV2, VaultV2Adapter, VaultV2BlueMarketPublicAllocatorConfig, VaultV2BluePublicAllocatorConfig,
|
|
5
|
+
PreLiquidationPosition as BluePreLiquidationPosition, Token, User as BlueUser, Vault, VaultConfig, VaultMarketAllocation, VaultMarketConfig, VaultToken, VaultUser, VaultV2, VaultV2Adapter, VaultV2BlueMarketPublicAllocatorConfig, VaultV2BluePublicAllocatorConfig, VaultV2MorphoMarketV1Adapter, VaultV2MorphoMarketV1AdapterV2, VaultV2MorphoVaultV1Adapter, WrappedToken, } from "@morpho-org/blue-sdk";
|
|
6
6
|
export { AccrualPosition as MidnightAccrualPosition, Group as MidnightGroup, Market as MidnightMarket, MarketParams as MidnightMarketParams, Offer as MidnightOffer, Position as MidnightPosition, Tree as MidnightTree, } from "@morpho-org/midnight-sdk";
|
|
7
7
|
export { MorphoBlue } from "./blue/index.js";
|
|
8
8
|
export { MorphoMidnight, } from "./midnight/index.js";
|
|
@@ -197,6 +197,7 @@ export declare class MorphoMidnight {
|
|
|
197
197
|
* @throws {EmptyMidnightTakeableOffersError} when no offers are supplied.
|
|
198
198
|
* @throws {MidnightOfferSideMismatchError} when an offer has the wrong maker side.
|
|
199
199
|
* @throws {MidnightTakeableOfferMarketMismatchError} when an offer targets another market.
|
|
200
|
+
* @throws {MidnightTakeableOfferZeroSellerReceiverError} when a sell offer routes seller proceeds to the zero address.
|
|
200
201
|
* @throws {ReferralFeePctExceededError} when `referralFeePct` is not below WAD.
|
|
201
202
|
* @throws {MidnightReferralFeePctExceededError} when `referralFeePct` exceeds 10% (`WAD / 10n`).
|
|
202
203
|
* @throws {ReferralFeeRecipientMissingError} when a positive referral fee has no recipient.
|
|
@@ -552,6 +553,7 @@ export declare class MorphoMidnight {
|
|
|
552
553
|
* @throws {EmptyMidnightTakeableOffersError} when no offers are supplied.
|
|
553
554
|
* @throws {MidnightOfferSideMismatchError} when an offer has the wrong maker side.
|
|
554
555
|
* @throws {MidnightTakeableOfferMarketMismatchError} when an offer targets another market.
|
|
556
|
+
* @throws {MidnightTakeableOfferZeroSellerReceiverError} when a sell offer routes seller proceeds to the zero address.
|
|
555
557
|
* @throws {ExpiredDeadlineError} when `deadline` has expired.
|
|
556
558
|
* @throws {MidnightTakeDeadlineTooFarError} when `deadline` is more than one hour from now.
|
|
557
559
|
* @throws {ReferralFeePctExceededError} when `referralFeePct` is not below WAD.
|
|
@@ -636,14 +638,14 @@ export declare class MorphoMidnight {
|
|
|
636
638
|
* for a new publication. Calls the Midnight mempool validation API while preparing the tree;
|
|
637
639
|
* `validation: false` skips that call.
|
|
638
640
|
*
|
|
639
|
-
* @param params - Maker, lend-side offers,
|
|
641
|
+
* @param params - Maker, lend-side offers, `loanAssets` and `reservedLoanAssets` allowance thresholds, cancellations, and deadline.
|
|
640
642
|
* @param params.accountAddress - Maker expected on every offer; must send the transaction.
|
|
641
643
|
* @param params.offers - PriceRatifierV1 or RateRatifierV1 tree, or its `Tree.create` request.
|
|
642
644
|
* @param params.cancellations - Previous groups to cancel with their consumption ceilings.
|
|
643
645
|
* @param params.deadline - Bundle execution deadline timestamp.
|
|
644
646
|
* @param params.validation - Midnight mempool API request controls, or `false` to skip the API call.
|
|
645
647
|
* @param params.loanToken - Loan token shared by every offer market.
|
|
646
|
-
* @param params.loanAssets -
|
|
648
|
+
* @param params.loanAssets - Minimum Midnight allowance (with `reservedLoanAssets`) that `getRequirements()` checks; the approval it returns is unlimited. The signed offer caps bound fills.
|
|
647
649
|
* @param params.reservedLoanAssets - Existing loan assets reserved by other open groups, excluding groups in `cancellations`.
|
|
648
650
|
* @returns Prepared group metadata, lazy approval/authorization requirements, and a synchronous transaction builder.
|
|
649
651
|
* @throws {ChainIdMismatchError} when the client declares, or its RPC reports via `eth_chainId` during `getOffersData()` or `getRequirements`, another chain than this entity's.
|
|
@@ -846,7 +848,8 @@ export declare class MorphoMidnight {
|
|
|
846
848
|
* @throws {MidnightMarketLiquidationCursorNotEnabledError} when an uncreated market uses a disabled liquidation cursor.
|
|
847
849
|
* @throws {MidnightMarketOracleWithoutCodeError} when an uncreated market's oracle has no code.
|
|
848
850
|
* @throws {viem.BaseError} when a pinned block, multicall, or oracle-code read fails.
|
|
849
|
-
* @throws {
|
|
851
|
+
* @throws {MissingDeadSharesDataError} when the fetched `blueMarket` snapshot has no `deadSupplyShares`.
|
|
852
|
+
* @throws {InsufficientDeadSharesError} when `blueMarket` holds fewer than `MIN_DEAD_SHARES` supply shares at `DEAD_ADDRESS`.
|
|
850
853
|
* @throws {ZeroBlueParkingSharesError} when `assetsToPark` would mint no supply shares at the current share price (checked at preparation time only).
|
|
851
854
|
* @throws {MidnightReplacementGroupCancelledError} when a published group is also cancelled.
|
|
852
855
|
* @throws {InvalidMidnightHexInputError} when a cancellation group or `callbackSalt` is not 32-byte hex.
|
|
@@ -946,7 +949,7 @@ export declare class MorphoMidnight {
|
|
|
946
949
|
*
|
|
947
950
|
* Shares the lend-side publication and requirement handling of {@link MorphoMidnight.makeLend}.
|
|
948
951
|
* Loan assets are pulled by Midnight when the offers fill, not during publication.
|
|
949
|
-
*
|
|
952
|
+
* `loanAssets` is only the allowance threshold `getRequirements()` checks, as in `makeLend`; the signed offer caps bound fills.
|
|
950
953
|
* A partially consumed offer group remains publishable with its shared remaining cap reduced.
|
|
951
954
|
* No repay offer can be live after market maturity; late borrowers should repay directly with
|
|
952
955
|
* {@link MorphoMidnight.repayWithdrawCollateral}.
|
|
@@ -954,14 +957,14 @@ export declare class MorphoMidnight {
|
|
|
954
957
|
* Every offer must already have `buy = true` and `reduceOnly = true`.
|
|
955
958
|
* The supplied tree, group caps and prices are preserved; no separate root signature is needed.
|
|
956
959
|
*
|
|
957
|
-
* @param params - Maker, reduce-only offers, optional cancellations,
|
|
960
|
+
* @param params - Maker, reduce-only offers, optional cancellations, `loanAssets` and `reservedLoanAssets` allowance thresholds, and deadline.
|
|
958
961
|
* @param params.accountAddress - Maker expected on every offer; must send the transaction.
|
|
959
962
|
* @param params.offers - PriceRatifierV1 or RateRatifierV1 tree, or its `Tree.create` request.
|
|
960
963
|
* @param params.cancellations - Previous groups to cancel with their consumption ceilings.
|
|
961
964
|
* @param params.deadline - Bundle execution deadline timestamp.
|
|
962
965
|
* @param params.validation - Midnight mempool API request controls, or `false` to skip the API call.
|
|
963
966
|
* @param params.loanToken - Loan token shared by every offer market.
|
|
964
|
-
* @param params.loanAssets -
|
|
967
|
+
* @param params.loanAssets - Minimum Midnight allowance (with `reservedLoanAssets`) that `getRequirements()` checks; the approval it returns is unlimited. The signed offer caps bound fills.
|
|
965
968
|
* @param params.reservedLoanAssets - Existing loan assets reserved by other open groups.
|
|
966
969
|
* @returns Prepared root and groups, lazy requirements, and a synchronous publication builder.
|
|
967
970
|
* @throws {ChainIdMismatchError} when the client declares, or its RPC reports via `eth_chainId` during `getOffersData()` or `getRequirements`, another chain than this entity's.
|
|
@@ -8,6 +8,7 @@ import { getMidnightApprovalRequirements, getMidnightAuthorizationRequirement, }
|
|
|
8
8
|
import { validateClientChainId } from "../../actions/requirements/validateClientChainId.js";
|
|
9
9
|
import { getMidnightBlueBuyCallbackAddress, getMidnightBlueBuyCallbackData, } from "../../helpers/callback.js";
|
|
10
10
|
import { MIDNIGHT_TAKE_MAX_DEADLINE_SECONDS } from "../../helpers/constant.js";
|
|
11
|
+
import { validateBlueMarketDeadShares } from "../../helpers/deadShares.js";
|
|
11
12
|
import { encodeMidnightMarketId, wrapMidnightEncoding, } from "../../helpers/encodeMidnightCalldata.js";
|
|
12
13
|
import { getMidnightMaxSafeDebt, validateChainId, } from "../../helpers/index.js";
|
|
13
14
|
import { validateMidnightAccount, validateMidnightAddress, } from "../../helpers/validateMidnightAccount.js";
|
|
@@ -16,7 +17,7 @@ import { validateMidnightMarket } from "../../helpers/validateMidnightMarket.js"
|
|
|
16
17
|
import { validateMidnightBytes32 } from "../../helpers/validateMidnightPublication.js";
|
|
17
18
|
import { validateMidnightTakeFeasibility } from "../../helpers/validateMidnightTakeFeasibility.js";
|
|
18
19
|
import { validateOfferSides } from "../../helpers/validateOfferSides.js";
|
|
19
|
-
import { AccrualPositionUserMismatchError, BorrowExceedsSafeLtvError,
|
|
20
|
+
import { AccrualPositionUserMismatchError, BorrowExceedsSafeLtvError, InsufficientMidnightWithdrawableLiquidityError, MarketIdMismatchError, MidnightInvalidAccountAddressError, MidnightOfferCallbackDataMismatchError, MidnightOfferCallbackMismatchError, MidnightOfferContinuousFeeCapError, MidnightOfferMakerMismatchError, MidnightOfferMarketAddressMismatchError, MidnightOfferMarketChainMismatchError, MidnightOfferMarketLoanTokenMismatchError, MidnightOfferNotReduceOnlyError, MidnightOfferRatifierMismatchError, MidnightOfferReduceOnlyError, MidnightOfferSellerReceiverMismatchError, MidnightRedeemExceedsCreditError, MidnightRepayExceedsDebtError, MidnightTakeDeadlineTooFarError, MidnightTakeTargetUnreachableError, MidnightZeroOnBehalfError, MissingAccrualPositionError, NegativeInputError, NoMidnightCreditToRedeemError, NonPositiveInputError, WithdrawExceedsCollateralError, WithdrawMakesPositionUnhealthyError, ZeroBlueParkingSharesError, } from "../../types/index.js";
|
|
20
21
|
import { validateMidnightDeadline } from "./deadline.js";
|
|
21
22
|
import { fetchMidnightMakerOfferStates, offerMarketParams, validateMidnightMakerOfferCallbacks, validateMidnightMakerOfferStates, } from "./publication.js";
|
|
22
23
|
const validatePositionBinding = (params) => {
|
|
@@ -339,6 +340,7 @@ export class MorphoMidnight {
|
|
|
339
340
|
* @throws {EmptyMidnightTakeableOffersError} when no offers are supplied.
|
|
340
341
|
* @throws {MidnightOfferSideMismatchError} when an offer has the wrong maker side.
|
|
341
342
|
* @throws {MidnightTakeableOfferMarketMismatchError} when an offer targets another market.
|
|
343
|
+
* @throws {MidnightTakeableOfferZeroSellerReceiverError} when a sell offer routes seller proceeds to the zero address.
|
|
342
344
|
* @throws {ReferralFeePctExceededError} when `referralFeePct` is not below WAD.
|
|
343
345
|
* @throws {MidnightReferralFeePctExceededError} when `referralFeePct` exceeds 10% (`WAD / 10n`).
|
|
344
346
|
* @throws {ReferralFeeRecipientMissingError} when a positive referral fee has no recipient.
|
|
@@ -927,6 +929,7 @@ export class MorphoMidnight {
|
|
|
927
929
|
* @throws {EmptyMidnightTakeableOffersError} when no offers are supplied.
|
|
928
930
|
* @throws {MidnightOfferSideMismatchError} when an offer has the wrong maker side.
|
|
929
931
|
* @throws {MidnightTakeableOfferMarketMismatchError} when an offer targets another market.
|
|
932
|
+
* @throws {MidnightTakeableOfferZeroSellerReceiverError} when a sell offer routes seller proceeds to the zero address.
|
|
930
933
|
* @throws {ExpiredDeadlineError} when `deadline` has expired.
|
|
931
934
|
* @throws {MidnightTakeDeadlineTooFarError} when `deadline` is more than one hour from now.
|
|
932
935
|
* @throws {ReferralFeePctExceededError} when `referralFeePct` is not below WAD.
|
|
@@ -1151,14 +1154,14 @@ export class MorphoMidnight {
|
|
|
1151
1154
|
* for a new publication. Calls the Midnight mempool validation API while preparing the tree;
|
|
1152
1155
|
* `validation: false` skips that call.
|
|
1153
1156
|
*
|
|
1154
|
-
* @param params - Maker, lend-side offers,
|
|
1157
|
+
* @param params - Maker, lend-side offers, `loanAssets` and `reservedLoanAssets` allowance thresholds, cancellations, and deadline.
|
|
1155
1158
|
* @param params.accountAddress - Maker expected on every offer; must send the transaction.
|
|
1156
1159
|
* @param params.offers - PriceRatifierV1 or RateRatifierV1 tree, or its `Tree.create` request.
|
|
1157
1160
|
* @param params.cancellations - Previous groups to cancel with their consumption ceilings.
|
|
1158
1161
|
* @param params.deadline - Bundle execution deadline timestamp.
|
|
1159
1162
|
* @param params.validation - Midnight mempool API request controls, or `false` to skip the API call.
|
|
1160
1163
|
* @param params.loanToken - Loan token shared by every offer market.
|
|
1161
|
-
* @param params.loanAssets -
|
|
1164
|
+
* @param params.loanAssets - Minimum Midnight allowance (with `reservedLoanAssets`) that `getRequirements()` checks; the approval it returns is unlimited. The signed offer caps bound fills.
|
|
1162
1165
|
* @param params.reservedLoanAssets - Existing loan assets reserved by other open groups, excluding groups in `cancellations`.
|
|
1163
1166
|
* @returns Prepared group metadata, lazy approval/authorization requirements, and a synchronous transaction builder.
|
|
1164
1167
|
* @throws {ChainIdMismatchError} when the client declares, or its RPC reports via `eth_chainId` during `getOffersData()` or `getRequirements`, another chain than this entity's.
|
|
@@ -1433,7 +1436,8 @@ export class MorphoMidnight {
|
|
|
1433
1436
|
* @throws {MidnightMarketLiquidationCursorNotEnabledError} when an uncreated market uses a disabled liquidation cursor.
|
|
1434
1437
|
* @throws {MidnightMarketOracleWithoutCodeError} when an uncreated market's oracle has no code.
|
|
1435
1438
|
* @throws {viem.BaseError} when a pinned block, multicall, or oracle-code read fails.
|
|
1436
|
-
* @throws {
|
|
1439
|
+
* @throws {MissingDeadSharesDataError} when the fetched `blueMarket` snapshot has no `deadSupplyShares`.
|
|
1440
|
+
* @throws {InsufficientDeadSharesError} when `blueMarket` holds fewer than `MIN_DEAD_SHARES` supply shares at `DEAD_ADDRESS`.
|
|
1437
1441
|
* @throws {ZeroBlueParkingSharesError} when `assetsToPark` would mint no supply shares at the current share price (checked at preparation time only).
|
|
1438
1442
|
* @throws {MidnightReplacementGroupCancelledError} when a published group is also cancelled.
|
|
1439
1443
|
* @throws {InvalidMidnightHexInputError} when a cancellation group or `callbackSalt` is not 32-byte hex.
|
|
@@ -1489,9 +1493,8 @@ export class MorphoMidnight {
|
|
|
1489
1493
|
}),
|
|
1490
1494
|
]);
|
|
1491
1495
|
const market = _try(() => fetched.accrueInterest(MathLib.max(Time.timestamp(), fetched.lastUpdate)), UnsupportedMarketIrmError) ?? fetched;
|
|
1492
|
-
|
|
1493
|
-
|
|
1494
|
-
}
|
|
1496
|
+
// Throws when the parking market lacks a sufficient dead deposit; nothing to return.
|
|
1497
|
+
validateBlueMarketDeadShares(fetched);
|
|
1495
1498
|
if (market.toSupplyShares(params.assetsToPark, "Down") === 0n) {
|
|
1496
1499
|
throw new ZeroBlueParkingSharesError({
|
|
1497
1500
|
marketId: blueMarketId,
|
|
@@ -1677,7 +1680,7 @@ export class MorphoMidnight {
|
|
|
1677
1680
|
*
|
|
1678
1681
|
* Shares the lend-side publication and requirement handling of {@link MorphoMidnight.makeLend}.
|
|
1679
1682
|
* Loan assets are pulled by Midnight when the offers fill, not during publication.
|
|
1680
|
-
*
|
|
1683
|
+
* `loanAssets` is only the allowance threshold `getRequirements()` checks, as in `makeLend`; the signed offer caps bound fills.
|
|
1681
1684
|
* A partially consumed offer group remains publishable with its shared remaining cap reduced.
|
|
1682
1685
|
* No repay offer can be live after market maturity; late borrowers should repay directly with
|
|
1683
1686
|
* {@link MorphoMidnight.repayWithdrawCollateral}.
|
|
@@ -1685,14 +1688,14 @@ export class MorphoMidnight {
|
|
|
1685
1688
|
* Every offer must already have `buy = true` and `reduceOnly = true`.
|
|
1686
1689
|
* The supplied tree, group caps and prices are preserved; no separate root signature is needed.
|
|
1687
1690
|
*
|
|
1688
|
-
* @param params - Maker, reduce-only offers, optional cancellations,
|
|
1691
|
+
* @param params - Maker, reduce-only offers, optional cancellations, `loanAssets` and `reservedLoanAssets` allowance thresholds, and deadline.
|
|
1689
1692
|
* @param params.accountAddress - Maker expected on every offer; must send the transaction.
|
|
1690
1693
|
* @param params.offers - PriceRatifierV1 or RateRatifierV1 tree, or its `Tree.create` request.
|
|
1691
1694
|
* @param params.cancellations - Previous groups to cancel with their consumption ceilings.
|
|
1692
1695
|
* @param params.deadline - Bundle execution deadline timestamp.
|
|
1693
1696
|
* @param params.validation - Midnight mempool API request controls, or `false` to skip the API call.
|
|
1694
1697
|
* @param params.loanToken - Loan token shared by every offer market.
|
|
1695
|
-
* @param params.loanAssets -
|
|
1698
|
+
* @param params.loanAssets - Minimum Midnight allowance (with `reservedLoanAssets`) that `getRequirements()` checks; the approval it returns is unlimited. The signed offer caps bound fills.
|
|
1696
1699
|
* @param params.reservedLoanAssets - Existing loan assets reserved by other open groups.
|
|
1697
1700
|
* @returns Prepared root and groups, lazy requirements, and a synchronous publication builder.
|
|
1698
1701
|
* @throws {ChainIdMismatchError} when the client declares, or its RPC reports via `eth_chainId` during `getOffersData()` or `getRequirements`, another chain than this entity's.
|
|
@@ -51,7 +51,14 @@ export interface MakeOffersParams {
|
|
|
51
51
|
/** Parameters for a Midnight lend maker flow. */
|
|
52
52
|
export interface MakeLendParams extends MakeOffersParams {
|
|
53
53
|
readonly loanToken: Address;
|
|
54
|
-
/**
|
|
54
|
+
/**
|
|
55
|
+
* Minimum Midnight loan-token allowance, together with `reservedLoanAssets`, that `getRequirements()` checks.
|
|
56
|
+
* When the allowance is lower, it returns an unlimited approval (`maxUint256`, capped per token by `MAX_TOKEN_APPROVALS`).
|
|
57
|
+
* Not checked against the offers: their signed `maxAssets`/`maxUnits` caps, the maker's balance and the
|
|
58
|
+
* allowance bound what takers can fill, so size those caps to what you mean to lend
|
|
59
|
+
* (`maxAssets` counts loan assets, `maxUnits` counts position units).
|
|
60
|
+
* For grouped OCA offers, pass the group amount once instead of summing every leg.
|
|
61
|
+
*/
|
|
55
62
|
readonly loanAssets: bigint;
|
|
56
63
|
/** Existing loan assets reserved across the maker's other open groups, including consumed amounts when available. Leave out groups listed in `cancellations`; this transaction cancels them. */
|
|
57
64
|
readonly reservedLoanAssets?: bigint;
|
|
@@ -104,6 +104,10 @@ export interface VaultV1Actions {
|
|
|
104
104
|
* const tx = action.buildTx(); // For a client configured with supportSignature: false.
|
|
105
105
|
* // tx satisfies Readonly<Transaction<VaultV1DepositAction>>
|
|
106
106
|
* ```
|
|
107
|
+
* @throws {MissingDeadSharesDataError} when `vaultData` lacks the dead-share, cap or adapter data
|
|
108
|
+
* the dead-deposit check needs, such as a hand-built or API-sourced snapshot.
|
|
109
|
+
* @throws {InsufficientDeadSharesError} when the vault, or a market or vault it can allocate to,
|
|
110
|
+
* holds less than the required dead deposit.
|
|
107
111
|
*/
|
|
108
112
|
deposit: (params: {
|
|
109
113
|
readonly userAddress: Address;
|
|
@@ -457,6 +461,10 @@ export interface VaultV1Actions {
|
|
|
457
461
|
* const tx = migration.buildTx(signatures);
|
|
458
462
|
* // tx satisfies Readonly<Transaction<VaultV1MigrateToV2Action>>
|
|
459
463
|
* ```
|
|
464
|
+
* @throws {MissingDeadSharesDataError} when `targetVault` lacks the dead-share, cap or adapter data
|
|
465
|
+
* the dead-deposit check needs. The source Vault V1 is not checked.
|
|
466
|
+
* @throws {InsufficientDeadSharesError} when `targetVault`, or a market or vault it can allocate
|
|
467
|
+
* to, holds less than the required dead deposit.
|
|
460
468
|
*/
|
|
461
469
|
migrateToV2: (params: {
|
|
462
470
|
readonly userAddress: Address;
|
|
@@ -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, vaultV1Deposit, vaultV1InKindRedeem, vaultV1MigrateToV2, vaultV1Redeem, vaultV1Withdraw, } from "../../actions/index.js";
|
|
8
8
|
import { validateClientChainId } from "../../actions/requirements/validateClientChainId.js";
|
|
9
|
+
import { validateVaultV1DeadShares, validateVaultV2DeadShares, } from "../../helpers/deadShares.js";
|
|
9
10
|
import { computeVaultMaxShareAllowance, computeVaultMaxSharePrice, validateChainId, validateSlippageTolerance, } from "../../helpers/index.js";
|
|
10
11
|
import { validateDeadline, validateNativeVaultAsset, validateUint256Field, } from "../../helpers/validate.js";
|
|
11
12
|
import { AmountAndSharesExclusiveError, EmptyMarketParamsListError, ExpiredDeadlineError, InKindRedeemCoverageError, InsufficientBlueBalanceForInKindRedeemError, NonPositiveInputError, SameVaultMigrationError, VaultAddressMismatchError, VaultAssetMismatchError, VaultIsBlueFeeRecipientError, VaultMorphoMismatchError, } from "../../types/index.js";
|
|
@@ -75,6 +76,8 @@ export class MorphoVaultV1 {
|
|
|
75
76
|
// The native path must target the chain's registered wrapped-native asset.
|
|
76
77
|
validateNativeVaultAsset(this.chainId, vaultAsset);
|
|
77
78
|
}
|
|
79
|
+
// Throws when the vault, or a market it can allocate to, lacks a sufficient dead deposit.
|
|
80
|
+
validateVaultV1DeadShares(vaultData);
|
|
78
81
|
const referralFeeAssets = getBundlesReferralFeeAssets(funding.assets, common.referralFeePct);
|
|
79
82
|
const maxSharePrice = computeVaultMaxSharePrice({
|
|
80
83
|
vaultData,
|
|
@@ -469,6 +472,8 @@ export class MorphoVaultV1 {
|
|
|
469
472
|
referralFeePct: params.referralFeePct,
|
|
470
473
|
referralFeeRecipient: params.referralFeeRecipient,
|
|
471
474
|
});
|
|
475
|
+
// Only the destination receives a deposit; the source vault is an exit.
|
|
476
|
+
validateVaultV2DeadShares(params.targetVault);
|
|
472
477
|
// V1 redeem accrues market interest and performance fees before converting shares.
|
|
473
478
|
const grossAssets = assets ??
|
|
474
479
|
params.sourceVault
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { type AccrualVaultV2,
|
|
1
|
+
import { type AccrualVaultV2, MarketParams } from "@morpho-org/blue-sdk";
|
|
2
2
|
import { fetchAccrualVaultV2 } from "@morpho-org/blue-sdk-viem";
|
|
3
3
|
import { type Address } from "viem";
|
|
4
4
|
import type { FetchParameters } from "../../types/data.js";
|
|
@@ -69,9 +69,8 @@ export interface VaultV2Actions {
|
|
|
69
69
|
* owner is consumed and none was passed explicitly.
|
|
70
70
|
* @throws {Permit2SignatureTransferNonceAlreadyUsedError} from `getRequirements()` when the
|
|
71
71
|
* explicit Permit2 nonce is consumed.
|
|
72
|
-
* @throws {InputExceedsMaxError} when funding or the deadline exceeds uint256,
|
|
73
|
-
*
|
|
74
|
-
* fits and `max` is `0n`), or from `getRequirements()` when the Permit2 nonce exceeds uint256.
|
|
72
|
+
* @throws {InputExceedsMaxError} when funding or the deadline exceeds uint256, or from
|
|
73
|
+
* `getRequirements()` when the Permit2 nonce exceeds uint256.
|
|
75
74
|
* @throws {AmbiguousRequirementSignaturesError} from `buildTx()` when multiple token signatures are supplied.
|
|
76
75
|
* @throws {UnexpectedRequirementSignatureError} from `buildTx()` when an unsupported signature is supplied.
|
|
77
76
|
* @throws {BundlesPermitMismatchError} from `buildTx()` when the signature's spender, amount or
|
|
@@ -111,6 +110,10 @@ export interface VaultV2Actions {
|
|
|
111
110
|
* const tx = action.buildTx(); // For a client configured with supportSignature: false.
|
|
112
111
|
* // tx satisfies Readonly<Transaction<VaultV2DepositAction>>
|
|
113
112
|
* ```
|
|
113
|
+
* @throws {MissingDeadSharesDataError} when `vaultData` lacks the dead-share, cap or adapter data
|
|
114
|
+
* the dead-deposit check needs, such as a hand-built or API-sourced snapshot.
|
|
115
|
+
* @throws {InsufficientDeadSharesError} when the vault, or a market or vault it can allocate to,
|
|
116
|
+
* holds less than the required dead deposit.
|
|
114
117
|
*/
|
|
115
118
|
deposit: (params: {
|
|
116
119
|
readonly userAddress: Address;
|
|
@@ -153,9 +156,7 @@ export interface VaultV2Actions {
|
|
|
153
156
|
* @throws {NonPositiveInputError} when `amount` or the computed required share amount is not positive.
|
|
154
157
|
* @throws {ExpiredDeadlineError} when `deadline` is not in the future at handle creation or
|
|
155
158
|
* at any `getRequirements()` call.
|
|
156
|
-
* @throws {InputExceedsMaxError} when `amount` or `deadline` exceeds uint256 at handle creation
|
|
157
|
-
* or when the vault's liquidity adapter is a Midnight adapter and `amount` exceeds the vault's
|
|
158
|
-
* idle assets.
|
|
159
|
+
* @throws {InputExceedsMaxError} when `amount` or `deadline` exceeds uint256 at handle creation.
|
|
159
160
|
* @throws {NegativeInputError} when `referralFeePct` or `slippageTolerance` is negative.
|
|
160
161
|
* @throws {ReferralFeePctExceededError} when `referralFeePct` is at least WAD.
|
|
161
162
|
* @throws {ReferralFeeRecipientMissingError} when a positive referral fee has no nonzero recipient.
|
|
@@ -221,24 +222,7 @@ export interface VaultV2Actions {
|
|
|
221
222
|
* @throws {NonPositiveInputError} when `shares` is not positive.
|
|
222
223
|
* @throws {ExpiredDeadlineError} when `deadline` is not in the future at handle creation or
|
|
223
224
|
* requirement resolution.
|
|
224
|
-
* @throws {InputExceedsMaxError} when `shares` or `deadline` exceeds uint256
|
|
225
|
-
* `getRequirements()` when the vault's liquidity adapter is a Midnight adapter and `shares`
|
|
226
|
-
* are worth more than the vault's idle assets.
|
|
227
|
-
* @throws {UnknownBlueFactory} from `getRequirements()` when the configured chain has no VaultV2 factory.
|
|
228
|
-
* @throws {UnknownBlueOfFactory} from `getRequirements()` when the vault is not a VaultV2 from the
|
|
229
|
-
* configured factory.
|
|
230
|
-
* @throws {UnsupportedBlueVaultV2AdapterError} from `getRequirements()` when the vault or one of its
|
|
231
|
-
* adapters uses an unsupported adapter class.
|
|
232
|
-
* @throws {UnsupportedBlueMarketIrmError} from `getRequirements()` when the vault's liquidity adapter
|
|
233
|
-
* is a Midnight adapter and accrual projects an underlying market with positive debt that uses an
|
|
234
|
-
* unsupported IRM.
|
|
235
|
-
* @throws {UnknownBlueMarketAllocationError} from `getRequirements()` when the vault's liquidity
|
|
236
|
-
* adapter is a Midnight adapter and accrual meets a nested Vault V1 withdraw queue market without
|
|
237
|
-
* allocation data.
|
|
238
|
-
* @throws {InvalidMidnightPositionLossFactorError} from `getRequirements()` when the vault's liquidity
|
|
239
|
-
* adapter is a Midnight adapter and accrual meets a market loss factor below a position's.
|
|
240
|
-
* @throws {InvalidMidnightPositionAccrualStateError} from `getRequirements()` when the vault's
|
|
241
|
-
* liquidity adapter is a Midnight adapter and accrual meets invalid Midnight position inputs.
|
|
225
|
+
* @throws {InputExceedsMaxError} when `shares` or `deadline` exceeds uint256.
|
|
242
226
|
* @throws {NegativeInputError} when `referralFeePct` is negative.
|
|
243
227
|
* @throws {ReferralFeePctExceededError} when `referralFeePct` is not below WAD.
|
|
244
228
|
* @throws {ReferralFeeRecipientMissingError} when a positive fee has no non-zero recipient.
|
|
@@ -246,7 +230,7 @@ export interface VaultV2Actions {
|
|
|
246
230
|
* @throws {UnknownAddressError} when VaultBundlesV1 is not registered on the target chain.
|
|
247
231
|
* @throws {MissingContractCodeError} from `getRequirements()` when a fixed bundles or protocol
|
|
248
232
|
* contract has no code at its registered address.
|
|
249
|
-
* @throws {viem.BaseError} from `getRequirements()` when
|
|
233
|
+
* @throws {viem.BaseError} from `getRequirements()` when an allowance, nonce, `eth_chainId`, or
|
|
250
234
|
* `eth_getCode` read fails.
|
|
251
235
|
* @throws {UnknownTokenError} from `getRequirements()` when the share token fetched by
|
|
252
236
|
* `getData()` has unusable decimals.
|
|
@@ -324,11 +308,9 @@ export interface VaultV2Actions {
|
|
|
324
308
|
* @throws {InputExceedsMaxError} when `deadline` exceeds `uint256`.
|
|
325
309
|
* @throws {ExpiredDeadlineError} when `deadline` is not in the future at handle creation or
|
|
326
310
|
* requirement resolution.
|
|
327
|
-
* @throws {VaultV2SingleAdapterRequiredError} when the vault does not have one adapter
|
|
328
|
-
* a vault that mixes Blue and Midnight adapters.
|
|
311
|
+
* @throws {VaultV2SingleAdapterRequiredError} when the vault does not have one adapter.
|
|
329
312
|
* @throws {AdapterNotPartOfVaultError} when `adapter` is not the vault's adapter.
|
|
330
|
-
* @throws {VaultV2UnsupportedExitAdapterError} when the adapter is not a MorphoMarketV1AdapterV2
|
|
331
|
-
* including a Midnight adapter.
|
|
313
|
+
* @throws {VaultV2UnsupportedExitAdapterError} when the adapter is not a MorphoMarketV1AdapterV2.
|
|
332
314
|
* @throws {InKindRedeemCoverageError} when the deduplicated list cannot cover the exit.
|
|
333
315
|
* @throws {UnsupportedChainIdError} when no address registry exists for the target chain.
|
|
334
316
|
* @throws {UnknownAddressError} when VaultExitBundlesV1 is not registered on the target chain.
|
|
@@ -453,11 +435,9 @@ export interface VaultV2Actions {
|
|
|
453
435
|
* @throws {ExpiredDeadlineError} when `deadline` is not in the future at handle creation or
|
|
454
436
|
* requirement resolution.
|
|
455
437
|
* @throws {ExcessiveSlippageToleranceError} when `slippageTolerance` exceeds the SDK maximum.
|
|
456
|
-
* @throws {VaultV2SingleAdapterRequiredError} when the vault does not have exactly one adapter
|
|
457
|
-
* including a vault that mixes Blue and Midnight adapters.
|
|
438
|
+
* @throws {VaultV2SingleAdapterRequiredError} when the vault does not have exactly one adapter.
|
|
458
439
|
* @throws {AdapterNotPartOfVaultError} when `adapter` is not the vault's adapter.
|
|
459
|
-
* @throws {VaultV2UnsupportedExitAdapterError} when the adapter is not a MorphoMarketV1AdapterV2
|
|
460
|
-
* including a Midnight adapter.
|
|
440
|
+
* @throws {VaultV2UnsupportedExitAdapterError} when the adapter is not a MorphoMarketV1AdapterV2.
|
|
461
441
|
* @throws {VaultV2UnsupportedLiquidityAdapterError} when the vault routes liquidity through
|
|
462
442
|
* another adapter.
|
|
463
443
|
* @throws {VaultV2UndecodableLiquidityDataError} when the vault's `liquidityData` does not decode
|
|
@@ -528,6 +508,8 @@ export interface VaultV2Actions {
|
|
|
528
508
|
* This is the share-based counterpart to forceWithdraw, useful for maximum withdrawal scenarios
|
|
529
509
|
* where specifying an exact asset amount is impractical.
|
|
530
510
|
*
|
|
511
|
+
* Inputs are copied when the handle is created, so later changes to them are not encoded.
|
|
512
|
+
*
|
|
531
513
|
* The total assets passed to forceDeallocate calls must be greater than or equal to the
|
|
532
514
|
* asset-equivalent of the redeemed shares. The caller should apply a buffer on the deallocated
|
|
533
515
|
* amounts to account for share-price drift between submission and execution.
|