@morpho-org/morpho-sdk 9.1.0-next.0 → 9.1.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 +3 -1
- package/lib/cjs/abis.d.ts +1 -1
- package/lib/cjs/abis.js +1 -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/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/entities/blue/blue.d.ts +43 -7
- package/lib/cjs/entities/blue/blue.js +27 -3
- 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 +7 -5
- package/lib/cjs/entities/midnight/midnight.js +7 -5
- package/lib/cjs/entities/midnight/types.d.ts +8 -1
- package/lib/cjs/entities/vaultV2/vaultV2.d.ts +12 -34
- package/lib/cjs/entities/vaultV2/vaultV2.js +9 -38
- package/lib/cjs/entities/vaultV2BlueReallocationData.d.ts +43 -18
- package/lib/cjs/entities/vaultV2BlueReallocationData.js +210 -79
- 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/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/errors.d.ts +1 -2
- package/lib/cjs/midnight/errors.js +4 -5
- package/lib/cjs/types/error.d.ts +6 -0
- package/lib/cjs/types/error.js +9 -1
- package/lib/cjs/types/sharedLiquidity.d.ts +27 -11
- package/lib/cjs/utils.d.ts +2 -2
- package/lib/cjs/utils.js +2 -4
- package/lib/esm/abis.d.ts +1 -1
- package/lib/esm/abis.js +1 -1
- 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/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/entities/blue/blue.d.ts +43 -7
- package/lib/esm/entities/blue/blue.js +27 -3
- 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 +7 -5
- package/lib/esm/entities/midnight/midnight.js +7 -5
- package/lib/esm/entities/midnight/types.d.ts +8 -1
- package/lib/esm/entities/vaultV2/vaultV2.d.ts +12 -34
- package/lib/esm/entities/vaultV2/vaultV2.js +10 -39
- package/lib/esm/entities/vaultV2BlueReallocationData.d.ts +43 -18
- package/lib/esm/entities/vaultV2BlueReallocationData.js +211 -80
- 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/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/errors.d.ts +1 -2
- package/lib/esm/midnight/errors.js +1 -2
- package/lib/esm/types/error.d.ts +6 -0
- package/lib/esm/types/error.js +7 -0
- package/lib/esm/types/sharedLiquidity.d.ts +27 -11
- package/lib/esm/utils.d.ts +2 -2
- package/lib/esm/utils.js +2 -2
- package/package.json +6 -6
|
@@ -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.
|
|
@@ -946,7 +948,7 @@ export declare class MorphoMidnight {
|
|
|
946
948
|
*
|
|
947
949
|
* Shares the lend-side publication and requirement handling of {@link MorphoMidnight.makeLend}.
|
|
948
950
|
* Loan assets are pulled by Midnight when the offers fill, not during publication.
|
|
949
|
-
*
|
|
951
|
+
* `loanAssets` is only the allowance threshold `getRequirements()` checks, as in `makeLend`; the signed offer caps bound fills.
|
|
950
952
|
* A partially consumed offer group remains publishable with its shared remaining cap reduced.
|
|
951
953
|
* No repay offer can be live after market maturity; late borrowers should repay directly with
|
|
952
954
|
* {@link MorphoMidnight.repayWithdrawCollateral}.
|
|
@@ -954,14 +956,14 @@ export declare class MorphoMidnight {
|
|
|
954
956
|
* Every offer must already have `buy = true` and `reduceOnly = true`.
|
|
955
957
|
* The supplied tree, group caps and prices are preserved; no separate root signature is needed.
|
|
956
958
|
*
|
|
957
|
-
* @param params - Maker, reduce-only offers, optional cancellations,
|
|
959
|
+
* @param params - Maker, reduce-only offers, optional cancellations, `loanAssets` and `reservedLoanAssets` allowance thresholds, and deadline.
|
|
958
960
|
* @param params.accountAddress - Maker expected on every offer; must send the transaction.
|
|
959
961
|
* @param params.offers - PriceRatifierV1 or RateRatifierV1 tree, or its `Tree.create` request.
|
|
960
962
|
* @param params.cancellations - Previous groups to cancel with their consumption ceilings.
|
|
961
963
|
* @param params.deadline - Bundle execution deadline timestamp.
|
|
962
964
|
* @param params.validation - Midnight mempool API request controls, or `false` to skip the API call.
|
|
963
965
|
* @param params.loanToken - Loan token shared by every offer market.
|
|
964
|
-
* @param params.loanAssets -
|
|
966
|
+
* @param params.loanAssets - Minimum Midnight allowance (with `reservedLoanAssets`) that `getRequirements()` checks; the approval it returns is unlimited. The signed offer caps bound fills.
|
|
965
967
|
* @param params.reservedLoanAssets - Existing loan assets reserved by other open groups.
|
|
966
968
|
* @returns Prepared root and groups, lazy requirements, and a synchronous publication builder.
|
|
967
969
|
* @throws {ChainIdMismatchError} when the client declares, or its RPC reports via `eth_chainId` during `getOffersData()` or `getRequirements`, another chain than this entity's.
|
|
@@ -339,6 +339,7 @@ export class MorphoMidnight {
|
|
|
339
339
|
* @throws {EmptyMidnightTakeableOffersError} when no offers are supplied.
|
|
340
340
|
* @throws {MidnightOfferSideMismatchError} when an offer has the wrong maker side.
|
|
341
341
|
* @throws {MidnightTakeableOfferMarketMismatchError} when an offer targets another market.
|
|
342
|
+
* @throws {MidnightTakeableOfferZeroSellerReceiverError} when a sell offer routes seller proceeds to the zero address.
|
|
342
343
|
* @throws {ReferralFeePctExceededError} when `referralFeePct` is not below WAD.
|
|
343
344
|
* @throws {MidnightReferralFeePctExceededError} when `referralFeePct` exceeds 10% (`WAD / 10n`).
|
|
344
345
|
* @throws {ReferralFeeRecipientMissingError} when a positive referral fee has no recipient.
|
|
@@ -927,6 +928,7 @@ export class MorphoMidnight {
|
|
|
927
928
|
* @throws {EmptyMidnightTakeableOffersError} when no offers are supplied.
|
|
928
929
|
* @throws {MidnightOfferSideMismatchError} when an offer has the wrong maker side.
|
|
929
930
|
* @throws {MidnightTakeableOfferMarketMismatchError} when an offer targets another market.
|
|
931
|
+
* @throws {MidnightTakeableOfferZeroSellerReceiverError} when a sell offer routes seller proceeds to the zero address.
|
|
930
932
|
* @throws {ExpiredDeadlineError} when `deadline` has expired.
|
|
931
933
|
* @throws {MidnightTakeDeadlineTooFarError} when `deadline` is more than one hour from now.
|
|
932
934
|
* @throws {ReferralFeePctExceededError} when `referralFeePct` is not below WAD.
|
|
@@ -1151,14 +1153,14 @@ export class MorphoMidnight {
|
|
|
1151
1153
|
* for a new publication. Calls the Midnight mempool validation API while preparing the tree;
|
|
1152
1154
|
* `validation: false` skips that call.
|
|
1153
1155
|
*
|
|
1154
|
-
* @param params - Maker, lend-side offers,
|
|
1156
|
+
* @param params - Maker, lend-side offers, `loanAssets` and `reservedLoanAssets` allowance thresholds, cancellations, and deadline.
|
|
1155
1157
|
* @param params.accountAddress - Maker expected on every offer; must send the transaction.
|
|
1156
1158
|
* @param params.offers - PriceRatifierV1 or RateRatifierV1 tree, or its `Tree.create` request.
|
|
1157
1159
|
* @param params.cancellations - Previous groups to cancel with their consumption ceilings.
|
|
1158
1160
|
* @param params.deadline - Bundle execution deadline timestamp.
|
|
1159
1161
|
* @param params.validation - Midnight mempool API request controls, or `false` to skip the API call.
|
|
1160
1162
|
* @param params.loanToken - Loan token shared by every offer market.
|
|
1161
|
-
* @param params.loanAssets -
|
|
1163
|
+
* @param params.loanAssets - Minimum Midnight allowance (with `reservedLoanAssets`) that `getRequirements()` checks; the approval it returns is unlimited. The signed offer caps bound fills.
|
|
1162
1164
|
* @param params.reservedLoanAssets - Existing loan assets reserved by other open groups, excluding groups in `cancellations`.
|
|
1163
1165
|
* @returns Prepared group metadata, lazy approval/authorization requirements, and a synchronous transaction builder.
|
|
1164
1166
|
* @throws {ChainIdMismatchError} when the client declares, or its RPC reports via `eth_chainId` during `getOffersData()` or `getRequirements`, another chain than this entity's.
|
|
@@ -1677,7 +1679,7 @@ export class MorphoMidnight {
|
|
|
1677
1679
|
*
|
|
1678
1680
|
* Shares the lend-side publication and requirement handling of {@link MorphoMidnight.makeLend}.
|
|
1679
1681
|
* Loan assets are pulled by Midnight when the offers fill, not during publication.
|
|
1680
|
-
*
|
|
1682
|
+
* `loanAssets` is only the allowance threshold `getRequirements()` checks, as in `makeLend`; the signed offer caps bound fills.
|
|
1681
1683
|
* A partially consumed offer group remains publishable with its shared remaining cap reduced.
|
|
1682
1684
|
* No repay offer can be live after market maturity; late borrowers should repay directly with
|
|
1683
1685
|
* {@link MorphoMidnight.repayWithdrawCollateral}.
|
|
@@ -1685,14 +1687,14 @@ export class MorphoMidnight {
|
|
|
1685
1687
|
* Every offer must already have `buy = true` and `reduceOnly = true`.
|
|
1686
1688
|
* The supplied tree, group caps and prices are preserved; no separate root signature is needed.
|
|
1687
1689
|
*
|
|
1688
|
-
* @param params - Maker, reduce-only offers, optional cancellations,
|
|
1690
|
+
* @param params - Maker, reduce-only offers, optional cancellations, `loanAssets` and `reservedLoanAssets` allowance thresholds, and deadline.
|
|
1689
1691
|
* @param params.accountAddress - Maker expected on every offer; must send the transaction.
|
|
1690
1692
|
* @param params.offers - PriceRatifierV1 or RateRatifierV1 tree, or its `Tree.create` request.
|
|
1691
1693
|
* @param params.cancellations - Previous groups to cancel with their consumption ceilings.
|
|
1692
1694
|
* @param params.deadline - Bundle execution deadline timestamp.
|
|
1693
1695
|
* @param params.validation - Midnight mempool API request controls, or `false` to skip the API call.
|
|
1694
1696
|
* @param params.loanToken - Loan token shared by every offer market.
|
|
1695
|
-
* @param params.loanAssets -
|
|
1697
|
+
* @param params.loanAssets - Minimum Midnight allowance (with `reservedLoanAssets`) that `getRequirements()` checks; the approval it returns is unlimited. The signed offer caps bound fills.
|
|
1696
1698
|
* @param params.reservedLoanAssets - Existing loan assets reserved by other open groups.
|
|
1697
1699
|
* @returns Prepared root and groups, lazy requirements, and a synchronous publication builder.
|
|
1698
1700
|
* @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;
|
|
@@ -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
|
|
@@ -153,9 +152,7 @@ export interface VaultV2Actions {
|
|
|
153
152
|
* @throws {NonPositiveInputError} when `amount` or the computed required share amount is not positive.
|
|
154
153
|
* @throws {ExpiredDeadlineError} when `deadline` is not in the future at handle creation or
|
|
155
154
|
* 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.
|
|
155
|
+
* @throws {InputExceedsMaxError} when `amount` or `deadline` exceeds uint256 at handle creation.
|
|
159
156
|
* @throws {NegativeInputError} when `referralFeePct` or `slippageTolerance` is negative.
|
|
160
157
|
* @throws {ReferralFeePctExceededError} when `referralFeePct` is at least WAD.
|
|
161
158
|
* @throws {ReferralFeeRecipientMissingError} when a positive referral fee has no nonzero recipient.
|
|
@@ -221,24 +218,7 @@ export interface VaultV2Actions {
|
|
|
221
218
|
* @throws {NonPositiveInputError} when `shares` is not positive.
|
|
222
219
|
* @throws {ExpiredDeadlineError} when `deadline` is not in the future at handle creation or
|
|
223
220
|
* 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.
|
|
221
|
+
* @throws {InputExceedsMaxError} when `shares` or `deadline` exceeds uint256.
|
|
242
222
|
* @throws {NegativeInputError} when `referralFeePct` is negative.
|
|
243
223
|
* @throws {ReferralFeePctExceededError} when `referralFeePct` is not below WAD.
|
|
244
224
|
* @throws {ReferralFeeRecipientMissingError} when a positive fee has no non-zero recipient.
|
|
@@ -246,7 +226,7 @@ export interface VaultV2Actions {
|
|
|
246
226
|
* @throws {UnknownAddressError} when VaultBundlesV1 is not registered on the target chain.
|
|
247
227
|
* @throws {MissingContractCodeError} from `getRequirements()` when a fixed bundles or protocol
|
|
248
228
|
* contract has no code at its registered address.
|
|
249
|
-
* @throws {viem.BaseError} from `getRequirements()` when
|
|
229
|
+
* @throws {viem.BaseError} from `getRequirements()` when an allowance, nonce, `eth_chainId`, or
|
|
250
230
|
* `eth_getCode` read fails.
|
|
251
231
|
* @throws {UnknownTokenError} from `getRequirements()` when the share token fetched by
|
|
252
232
|
* `getData()` has unusable decimals.
|
|
@@ -324,11 +304,9 @@ export interface VaultV2Actions {
|
|
|
324
304
|
* @throws {InputExceedsMaxError} when `deadline` exceeds `uint256`.
|
|
325
305
|
* @throws {ExpiredDeadlineError} when `deadline` is not in the future at handle creation or
|
|
326
306
|
* requirement resolution.
|
|
327
|
-
* @throws {VaultV2SingleAdapterRequiredError} when the vault does not have one adapter
|
|
328
|
-
* a vault that mixes Blue and Midnight adapters.
|
|
307
|
+
* @throws {VaultV2SingleAdapterRequiredError} when the vault does not have one adapter.
|
|
329
308
|
* @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.
|
|
309
|
+
* @throws {VaultV2UnsupportedExitAdapterError} when the adapter is not a MorphoMarketV1AdapterV2.
|
|
332
310
|
* @throws {InKindRedeemCoverageError} when the deduplicated list cannot cover the exit.
|
|
333
311
|
* @throws {UnsupportedChainIdError} when no address registry exists for the target chain.
|
|
334
312
|
* @throws {UnknownAddressError} when VaultExitBundlesV1 is not registered on the target chain.
|
|
@@ -453,11 +431,9 @@ export interface VaultV2Actions {
|
|
|
453
431
|
* @throws {ExpiredDeadlineError} when `deadline` is not in the future at handle creation or
|
|
454
432
|
* requirement resolution.
|
|
455
433
|
* @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.
|
|
434
|
+
* @throws {VaultV2SingleAdapterRequiredError} when the vault does not have exactly one adapter.
|
|
458
435
|
* @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.
|
|
436
|
+
* @throws {VaultV2UnsupportedExitAdapterError} when the adapter is not a MorphoMarketV1AdapterV2.
|
|
461
437
|
* @throws {VaultV2UnsupportedLiquidityAdapterError} when the vault routes liquidity through
|
|
462
438
|
* another adapter.
|
|
463
439
|
* @throws {VaultV2UndecodableLiquidityDataError} when the vault's `liquidityData` does not decode
|
|
@@ -528,6 +504,8 @@ export interface VaultV2Actions {
|
|
|
528
504
|
* This is the share-based counterpart to forceWithdraw, useful for maximum withdrawal scenarios
|
|
529
505
|
* where specifying an exact asset amount is impractical.
|
|
530
506
|
*
|
|
507
|
+
* Inputs are copied when the handle is created, so later changes to them are not encoded.
|
|
508
|
+
*
|
|
531
509
|
* The total assets passed to forceDeallocate calls must be greater than or equal to the
|
|
532
510
|
* asset-equivalent of the redeemed shares. The caller should apply a buffer on the deallocated
|
|
533
511
|
* amounts to account for share-price drift between submission and execution.
|
|
@@ -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";
|
|
@@ -15,11 +15,6 @@ import { getBundlesTokenRequirements } from "../requirements/index.js";
|
|
|
15
15
|
// Maximum accepted deadline horizon; the on-chain management fee is capped at 5%/yr so the
|
|
16
16
|
// accrual model stays well-defined inside it.
|
|
17
17
|
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
18
|
/** Binds a viem client to a Vault V2 vault's action builders. */
|
|
24
19
|
export class MorphoVaultV2 {
|
|
25
20
|
client;
|
|
@@ -83,13 +78,6 @@ export class MorphoVaultV2 {
|
|
|
83
78
|
// The native path must target the chain's registered wrapped-native asset.
|
|
84
79
|
validateNativeVaultAsset(this.chainId, vaultAsset);
|
|
85
80
|
}
|
|
86
|
-
if (isMidnightLiquidityAdapter(vaultData)) {
|
|
87
|
-
throw new InputExceedsMaxError({
|
|
88
|
-
field: funding.value > 0n ? "nativeAmount" : "amount",
|
|
89
|
-
value: funding.assets,
|
|
90
|
-
max: 0n,
|
|
91
|
-
});
|
|
92
|
-
}
|
|
93
81
|
const referralFeeAssets = getBundlesReferralFeeAssets(funding.assets, common.referralFeePct);
|
|
94
82
|
const maxSharePrice = computeVaultMaxSharePrice({
|
|
95
83
|
vaultData,
|
|
@@ -173,14 +161,6 @@ export class MorphoVaultV2 {
|
|
|
173
161
|
throw new NonPositiveInputError("amount", amount);
|
|
174
162
|
// Reject values outside the ABI range before resolving any requirements.
|
|
175
163
|
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
164
|
const createdAt = Time.timestamp();
|
|
185
165
|
const deadline = params.deadline ?? createdAt + Time.s.from.h(2n);
|
|
186
166
|
if (deadline <= createdAt)
|
|
@@ -261,20 +241,8 @@ export class MorphoVaultV2 {
|
|
|
261
241
|
if (deadline <= now)
|
|
262
242
|
throw new ExpiredDeadlineError(deadline, now);
|
|
263
243
|
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
244
|
return getVaultBundlesSharesRequirements(this.client.viemClient, {
|
|
277
|
-
vaultData,
|
|
245
|
+
vaultData: await this.getData(),
|
|
278
246
|
version: "vaultV2",
|
|
279
247
|
owner: userAddress,
|
|
280
248
|
chainId: this.chainId,
|
|
@@ -726,15 +694,18 @@ export class MorphoVaultV2 {
|
|
|
726
694
|
}
|
|
727
695
|
forceRedeem({ deallocations, redeem, userAddress, }) {
|
|
728
696
|
validateChainId(this.client.viemClient.chain?.id, this.chainId);
|
|
697
|
+
const shares = redeem.shares;
|
|
698
|
+
const deallocationsSnapshot = deallocations.map(({ adapter, marketParams, amount }) => ({
|
|
699
|
+
adapter,
|
|
700
|
+
amount,
|
|
701
|
+
...(marketParams && { marketParams: new MarketParams(marketParams) }),
|
|
702
|
+
}));
|
|
729
703
|
return {
|
|
730
704
|
buildTx: () => vaultV2ForceRedeem({
|
|
731
705
|
vault: { address: this.vault },
|
|
732
706
|
args: {
|
|
733
|
-
deallocations,
|
|
734
|
-
redeem: {
|
|
735
|
-
shares: redeem.shares,
|
|
736
|
-
recipient: userAddress,
|
|
737
|
-
},
|
|
707
|
+
deallocations: deallocationsSnapshot,
|
|
708
|
+
redeem: { shares, recipient: userAddress },
|
|
738
709
|
onBehalf: userAddress,
|
|
739
710
|
},
|
|
740
711
|
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,13 @@ 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;
|
|
22
29
|
/** Markets indexed by market id. */
|
|
23
30
|
readonly markets?: Readonly<Record<MarketId, ReadonlyMarketSnapshot | undefined>>;
|
|
24
31
|
/** Accrued Vault V2 entities indexed by vault address. */
|
|
@@ -39,9 +46,8 @@ export interface InputVaultV2BlueReallocationData {
|
|
|
39
46
|
/**
|
|
40
47
|
* Immutable-by-convention state container for Vault V2 BluePublicAllocator simulations.
|
|
41
48
|
*
|
|
42
|
-
* Constructor inputs are cloned
|
|
43
|
-
*
|
|
44
|
-
* reallocation returns a new instance. Planning keeps the transaction-scoped `firstTotalAssets`
|
|
49
|
+
* Constructor inputs are cloned. Every simulated reallocation returns a new
|
|
50
|
+
* instance. Planning keeps the transaction-scoped `firstTotalAssets`
|
|
45
51
|
* denominator outside the durable snapshot while applying reallocations in
|
|
46
52
|
* contract order. Penalty donations update simulated vault accounting but are
|
|
47
53
|
* excluded from same-plan idle liquidity so round-up dust cannot create
|
|
@@ -79,6 +85,8 @@ export declare class VaultV2BlueReallocationData implements InputVaultV2BlueReal
|
|
|
79
85
|
private readonly mutableAllocations;
|
|
80
86
|
/** Chain id associated with this snapshot. */
|
|
81
87
|
readonly chainId: number;
|
|
88
|
+
/** Timestamp of the block the state was fetched at. */
|
|
89
|
+
readonly timestamp?: bigint;
|
|
82
90
|
/** Markets indexed by market id. */
|
|
83
91
|
readonly markets: Readonly<Record<MarketId, ReadonlyMarketSnapshot | undefined>>;
|
|
84
92
|
/** Vault V2 entities indexed by address. */
|
|
@@ -101,8 +109,7 @@ export declare class VaultV2BlueReallocationData implements InputVaultV2BlueReal
|
|
|
101
109
|
/**
|
|
102
110
|
* Clones the complete simulation snapshot.
|
|
103
111
|
*
|
|
104
|
-
* @returns A deep clone of this simulation state.
|
|
105
|
-
* shared by reference and must be treated as read-only.
|
|
112
|
+
* @returns A deep clone of this simulation state.
|
|
106
113
|
* @example
|
|
107
114
|
* ```ts
|
|
108
115
|
* import { markets } from "@morpho-org/morpho-test";
|
|
@@ -358,16 +365,29 @@ export declare class VaultV2BlueReallocationData implements InputVaultV2BlueReal
|
|
|
358
365
|
* Computes Vault V2 BluePublicAllocator calls available for a target market.
|
|
359
366
|
*
|
|
360
367
|
* Without `options.operation`, discovers every friendly call. With an
|
|
361
|
-
* operation,
|
|
362
|
-
*
|
|
363
|
-
*
|
|
364
|
-
*
|
|
365
|
-
*
|
|
366
|
-
* `
|
|
367
|
-
*
|
|
368
|
-
*
|
|
369
|
-
*
|
|
370
|
-
*
|
|
368
|
+
* operation, penalty tiers are considered ascending, starting with free
|
|
369
|
+
* vaults. The free tier aims to bring the target market back to 90%
|
|
370
|
+
* utilization; positive tiers cover only the remaining absolute shortfall
|
|
371
|
+
* (borrows minus supply). Within each tier, source markets go to the
|
|
372
|
+
* friendly source utilization (90% by default) before 100%. Free capacity
|
|
373
|
+
* inside `allocatorCapHeadroom` is kept unused, so a penalized leg can cover
|
|
374
|
+
* it instead. Discovery and liquidity getters still count every vault up to
|
|
375
|
+
* `options.maxPenalty`. A shared relative-cap lower bound may require one call
|
|
376
|
+
* to exceed the targeted amount. For `refinance`, compute the plan on the
|
|
377
|
+
* destination-market handle (for example,
|
|
378
|
+
* `client.morpho.blue(destination.marketParams, chainId)`), not the source
|
|
379
|
+
* handle. Pass the source position's `borrowAssets` accrued to
|
|
380
|
+
* `max(now, source.lastUpdate, destination.lastUpdate) + 2h` as
|
|
381
|
+
* `operation.amount`; the optional `operation.referralFeePct` is WAD-scaled.
|
|
382
|
+
* The planner includes the referral fee and its allocator-leg penalties in
|
|
383
|
+
* destination debt, so penalized legs also cover their own penalty.
|
|
384
|
+
* Refinance never uses vaults with a 100% penalty.
|
|
385
|
+
* Friendly source utilization defaults to 90% and is configurable through
|
|
386
|
+
* `options.maxWithdrawalUtilization`. Market/vault state and the returned
|
|
387
|
+
* post-state stay at `timestamp`. An enabled operation that needs no
|
|
388
|
+
* reallocation still returns a clone accrued to `timestamp`. Only
|
|
389
|
+
* target-market cap checks reserve interest the vault's existing allocation
|
|
390
|
+
* would accrue through `timestamp + capAccrualBuffer`
|
|
371
391
|
* (two hours by default; `0n` disables it). When an operation's plan would
|
|
372
392
|
* come within `allocatorCapHeadroom` (1% of the cap by default) of a target
|
|
373
393
|
* BluePublicAllocator cap, the plan is reduced to the larger of the
|
|
@@ -408,8 +428,9 @@ export declare class VaultV2BlueReallocationData implements InputVaultV2BlueReal
|
|
|
408
428
|
* every leg of a plan.
|
|
409
429
|
* @returns Flat action-ready reallocations and their post-simulation state.
|
|
410
430
|
* @throws {UnsupportedBlueMarketIrmError} when a market with positive debt uses an unsupported IRM.
|
|
411
|
-
* @throws {NegativeInputError} when `capAccrualBuffer`, `allocatorCapHeadroom`, `maxWithdrawalUtilization`, or `
|
|
431
|
+
* @throws {NegativeInputError} when `capAccrualBuffer`, `allocatorCapHeadroom`, `maxWithdrawalUtilization`, `maxPenalty`, or `referralFeePct` is negative.
|
|
412
432
|
* @throws {InputExceedsMaxError} when `allocatorCapHeadroom`, `maxWithdrawalUtilization`, or `maxPenalty` exceeds WAD.
|
|
433
|
+
* @throws {ReferralFeePctExceededError} when `referralFeePct` is at least WAD.
|
|
413
434
|
* @throws {NonPositiveInputError} when the operation amount is not positive and planning is enabled.
|
|
414
435
|
* @throws {UnknownReallocationMarketError} when a required market is absent.
|
|
415
436
|
* @throws {UnknownReallocationVaultError} when configured vault state is absent.
|
|
@@ -417,7 +438,7 @@ export declare class VaultV2BlueReallocationData implements InputVaultV2BlueReal
|
|
|
417
438
|
* @throws {UnknownReallocationActiveAdaptersError} when active-adapter state is absent for a vault.
|
|
418
439
|
* @throws {UnknownReallocationMarketPublicAllocatorConfigError} when an adapter-market allocator configuration is absent.
|
|
419
440
|
* @throws {UnknownReallocationAllocationError} when required allocation state is absent.
|
|
420
|
-
* @throws {InsufficientSharedLiquidityError} when selected liquidity cannot cover the absolute shortfall.
|
|
441
|
+
* @throws {InsufficientSharedLiquidityError} when selected liquidity cannot cover the absolute shortfall and, for refinance, its planned allocator penalties.
|
|
421
442
|
* @throws {ReallocationWithdrawExceedsMarketSupplyError} when a withdraw exceeds market supply.
|
|
422
443
|
* @example
|
|
423
444
|
* ```ts
|
|
@@ -452,6 +473,10 @@ export declare class VaultV2BlueReallocationData implements InputVaultV2BlueReal
|
|
|
452
473
|
readonly operation?: {
|
|
453
474
|
readonly type: "borrow" | "withdraw";
|
|
454
475
|
readonly amount: bigint;
|
|
476
|
+
} | {
|
|
477
|
+
readonly type: "refinance";
|
|
478
|
+
readonly amount: bigint;
|
|
479
|
+
readonly referralFeePct?: bigint;
|
|
455
480
|
};
|
|
456
481
|
}): {
|
|
457
482
|
readonly reallocations: readonly VaultV2BlueReallocation[];
|