@morpho-org/morpho-sdk 10.1.0 → 10.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/lib/cjs/actions/blue/borrow.d.ts +11 -3
- package/lib/cjs/actions/blue/borrow.internal.js +1 -0
- package/lib/cjs/actions/blue/borrow.js +8 -2
- package/lib/cjs/actions/blue/common.d.ts +4 -1
- package/lib/cjs/actions/blue/common.js +17 -3
- package/lib/cjs/actions/blue/refinance.d.ts +11 -3
- package/lib/cjs/actions/blue/refinance.internal.js +4 -1
- package/lib/cjs/actions/blue/refinance.js +8 -2
- package/lib/cjs/actions/blue/refinanceValidation.d.ts +3 -2
- package/lib/cjs/actions/blue/refinanceValidation.js +10 -6
- package/lib/cjs/actions/blue/repay.d.ts +4 -3
- package/lib/cjs/actions/blue/repay.js +3 -2
- package/lib/cjs/actions/blue/repayWithdrawCollateral.d.ts +4 -3
- package/lib/cjs/actions/blue/repayWithdrawCollateral.js +3 -2
- package/lib/cjs/actions/blue/supply.d.ts +5 -3
- package/lib/cjs/actions/blue/supply.js +4 -2
- package/lib/cjs/actions/blue/supplyCollateral.d.ts +4 -3
- package/lib/cjs/actions/blue/supplyCollateral.js +3 -2
- package/lib/cjs/actions/blue/supplyCollateralBorrow.d.ts +11 -3
- package/lib/cjs/actions/blue/supplyCollateralBorrow.internal.d.ts +2 -0
- package/lib/cjs/actions/blue/supplyCollateralBorrow.internal.js +5 -1
- package/lib/cjs/actions/blue/supplyCollateralBorrow.js +8 -2
- package/lib/cjs/actions/blue/withdraw.d.ts +11 -3
- package/lib/cjs/actions/blue/withdraw.internal.js +4 -1
- package/lib/cjs/actions/blue/withdraw.js +8 -2
- package/lib/cjs/actions/blue/withdrawCollateral.d.ts +4 -3
- package/lib/cjs/actions/blue/withdrawCollateral.js +3 -2
- package/lib/cjs/actions/midnight/supplyCollateralTakeBorrow.js +0 -1
- package/lib/cjs/actions/midnight/takeBorrow.js +0 -1
- package/lib/cjs/actions/midnight/takeLend.js +0 -1
- package/lib/cjs/actions/midnight/takeRepayWithdrawCollateral.js +0 -1
- package/lib/cjs/actions/midnight/takeWithdraw.js +0 -1
- package/lib/cjs/actions/vaultV1/deposit.d.ts +2 -1
- package/lib/cjs/actions/vaultV1/deposit.js +2 -1
- package/lib/cjs/actions/vaultV1/migrateToV2.d.ts +3 -2
- package/lib/cjs/actions/vaultV1/migrateToV2.js +2 -1
- package/lib/cjs/actions/vaultV1/redeem.d.ts +3 -2
- package/lib/cjs/actions/vaultV1/redeem.js +2 -1
- package/lib/cjs/actions/vaultV1/withdraw.d.ts +2 -1
- package/lib/cjs/actions/vaultV1/withdraw.js +2 -1
- package/lib/cjs/actions/vaultV2/deposit.d.ts +2 -1
- package/lib/cjs/actions/vaultV2/deposit.js +2 -1
- package/lib/cjs/actions/vaultV2/forceWithdraw.d.ts +2 -1
- package/lib/cjs/actions/vaultV2/forceWithdraw.js +2 -1
- package/lib/cjs/actions/vaultV2/redeem.d.ts +3 -2
- package/lib/cjs/actions/vaultV2/redeem.js +2 -1
- package/lib/cjs/actions/vaultV2/withdraw.d.ts +2 -1
- package/lib/cjs/actions/vaultV2/withdraw.js +2 -1
- package/lib/cjs/constants.d.ts +1 -1
- package/lib/cjs/constants.js +2 -0
- package/lib/cjs/entities/blue/blue.d.ts +83 -20
- package/lib/cjs/entities/blue/blue.js +38 -12
- package/lib/cjs/entities/vaultV1/migrateToV2Quote.d.ts +2 -0
- package/lib/cjs/entities/vaultV1/migrateToV2Quote.js +5 -0
- package/lib/cjs/entities/vaultV1/vaultV1.d.ts +12 -6
- package/lib/cjs/entities/vaultV1/vaultV1.js +6 -0
- package/lib/cjs/entities/vaultV2/vaultV2.d.ts +12 -7
- package/lib/cjs/entities/vaultV2/vaultV2.js +4 -0
- package/lib/cjs/entities/vaultV2BlueReallocationData.d.ts +11 -2
- package/lib/cjs/entities/vaultV2BlueReallocationData.js +19 -21
- package/lib/cjs/helpers/constant.d.ts +2 -0
- package/lib/cjs/helpers/constant.js +3 -1
- package/lib/cjs/helpers/getBlueBundlesV1QuoteTimestamp.d.ts +10 -0
- package/lib/cjs/helpers/getBlueBundlesV1QuoteTimestamp.js +18 -0
- package/lib/cjs/helpers/index.d.ts +1 -1
- package/lib/cjs/helpers/index.js +2 -1
- package/lib/cjs/helpers/previewVaultV2ForceWithdraw.d.ts +3 -3
- package/lib/cjs/helpers/previewVaultV2ForceWithdraw.js +4 -5
- package/lib/cjs/helpers/quoteBlueRepay.d.ts +7 -3
- package/lib/cjs/helpers/quoteBlueRepay.js +20 -7
- package/lib/cjs/helpers/reallocationPenalty.d.ts +10 -0
- package/lib/cjs/helpers/reallocationPenalty.js +32 -0
- package/lib/cjs/helpers/referralFee.d.ts +2 -1
- package/lib/cjs/helpers/referralFee.js +5 -1
- package/lib/cjs/helpers/validate.d.ts +31 -4
- package/lib/cjs/helpers/validate.js +48 -9
- package/lib/cjs/helpers/validateMidnightBounds.d.ts +1 -2
- package/lib/cjs/helpers/validateMidnightBounds.js +1 -2
- package/lib/cjs/helpers/validateMidnightTakeFeasibility.d.ts +2 -2
- package/lib/cjs/helpers/validateMidnightTakeFeasibility.js +1 -1
- package/lib/cjs/transactionPlan/blue/borrow.d.ts +11 -5
- package/lib/cjs/transactionPlan/blue/borrow.js +26 -8
- package/lib/cjs/transactionPlan/blue/refinance.d.ts +9 -2
- package/lib/cjs/transactionPlan/blue/refinance.js +20 -3
- package/lib/cjs/transactionPlan/blue/repay.d.ts +1 -2
- package/lib/cjs/transactionPlan/blue/repay.js +1 -2
- package/lib/cjs/transactionPlan/blue/repayWithdrawCollateral.d.ts +4 -3
- package/lib/cjs/transactionPlan/blue/repayWithdrawCollateral.js +13 -4
- package/lib/cjs/transactionPlan/blue/supply.d.ts +1 -2
- package/lib/cjs/transactionPlan/blue/supply.js +1 -2
- package/lib/cjs/transactionPlan/blue/supplyCollateral.d.ts +2 -3
- package/lib/cjs/transactionPlan/blue/supplyCollateral.js +2 -3
- package/lib/cjs/transactionPlan/blue/supplyCollateralBorrow.d.ts +10 -4
- package/lib/cjs/transactionPlan/blue/supplyCollateralBorrow.js +23 -6
- package/lib/cjs/transactionPlan/blue/withdraw.d.ts +15 -5
- package/lib/cjs/transactionPlan/blue/withdraw.js +25 -6
- package/lib/cjs/transactionPlan/blue/withdrawCollateral.d.ts +5 -5
- package/lib/cjs/transactionPlan/blue/withdrawCollateral.js +11 -7
- package/lib/cjs/transactionPlan/deposit.js +4 -0
- package/lib/cjs/transactionPlan/intent.d.ts +1 -1
- package/lib/cjs/transactionPlan/intent.js +4 -2
- package/lib/cjs/transactionPlan/plan.d.ts +8 -4
- package/lib/cjs/transactionPlan/plan.js +8 -4
- package/lib/cjs/transactionPlan/types.d.ts +6 -0
- package/lib/cjs/transactionPlan/vaultv1/deposit.d.ts +3 -3
- package/lib/cjs/transactionPlan/vaultv1/deposit.js +3 -3
- package/lib/cjs/transactionPlan/vaultv1/migrateToV2.d.ts +3 -3
- package/lib/cjs/transactionPlan/vaultv1/migrateToV2.js +7 -3
- package/lib/cjs/transactionPlan/vaultv1/redeem.d.ts +1 -2
- package/lib/cjs/transactionPlan/vaultv1/redeem.js +1 -2
- package/lib/cjs/transactionPlan/vaultv1/withdraw.d.ts +2 -3
- package/lib/cjs/transactionPlan/vaultv1/withdraw.js +2 -3
- package/lib/cjs/transactionPlan/vaultv2/deposit.d.ts +3 -3
- package/lib/cjs/transactionPlan/vaultv2/deposit.js +3 -3
- package/lib/cjs/transactionPlan/vaultv2/forceWithdraw.d.ts +3 -3
- package/lib/cjs/transactionPlan/vaultv2/forceWithdraw.js +3 -3
- package/lib/cjs/transactionPlan/vaultv2/redeem.d.ts +2 -3
- package/lib/cjs/transactionPlan/vaultv2/redeem.js +2 -3
- package/lib/cjs/transactionPlan/vaultv2/withdraw.d.ts +2 -3
- package/lib/cjs/transactionPlan/vaultv2/withdraw.js +2 -3
- package/lib/cjs/types/error.d.ts +7 -6
- package/lib/cjs/types/error.js +10 -9
- package/lib/cjs/types/sharedLiquidity.d.ts +7 -2
- package/lib/cjs/version.d.ts +1 -1
- package/lib/cjs/version.js +1 -1
- package/lib/esm/actions/blue/borrow.d.ts +11 -3
- package/lib/esm/actions/blue/borrow.internal.js +1 -0
- package/lib/esm/actions/blue/borrow.js +8 -2
- package/lib/esm/actions/blue/common.d.ts +4 -1
- package/lib/esm/actions/blue/common.js +17 -3
- package/lib/esm/actions/blue/refinance.d.ts +11 -3
- package/lib/esm/actions/blue/refinance.internal.js +4 -1
- package/lib/esm/actions/blue/refinance.js +8 -2
- package/lib/esm/actions/blue/refinanceValidation.d.ts +3 -2
- package/lib/esm/actions/blue/refinanceValidation.js +10 -6
- package/lib/esm/actions/blue/repay.d.ts +4 -3
- package/lib/esm/actions/blue/repay.js +3 -2
- package/lib/esm/actions/blue/repayWithdrawCollateral.d.ts +4 -3
- package/lib/esm/actions/blue/repayWithdrawCollateral.js +3 -2
- package/lib/esm/actions/blue/supply.d.ts +5 -3
- package/lib/esm/actions/blue/supply.js +4 -2
- package/lib/esm/actions/blue/supplyCollateral.d.ts +4 -3
- package/lib/esm/actions/blue/supplyCollateral.js +3 -2
- package/lib/esm/actions/blue/supplyCollateralBorrow.d.ts +11 -3
- package/lib/esm/actions/blue/supplyCollateralBorrow.internal.d.ts +2 -0
- package/lib/esm/actions/blue/supplyCollateralBorrow.internal.js +5 -1
- package/lib/esm/actions/blue/supplyCollateralBorrow.js +8 -2
- package/lib/esm/actions/blue/withdraw.d.ts +11 -3
- package/lib/esm/actions/blue/withdraw.internal.js +4 -1
- package/lib/esm/actions/blue/withdraw.js +8 -2
- package/lib/esm/actions/blue/withdrawCollateral.d.ts +4 -3
- package/lib/esm/actions/blue/withdrawCollateral.js +3 -2
- package/lib/esm/actions/midnight/supplyCollateralTakeBorrow.js +1 -2
- package/lib/esm/actions/midnight/takeBorrow.js +1 -2
- package/lib/esm/actions/midnight/takeLend.js +1 -2
- package/lib/esm/actions/midnight/takeRepayWithdrawCollateral.js +1 -2
- package/lib/esm/actions/midnight/takeWithdraw.js +1 -2
- package/lib/esm/actions/vaultV1/deposit.d.ts +2 -1
- package/lib/esm/actions/vaultV1/deposit.js +2 -1
- package/lib/esm/actions/vaultV1/migrateToV2.d.ts +3 -2
- package/lib/esm/actions/vaultV1/migrateToV2.js +2 -1
- package/lib/esm/actions/vaultV1/redeem.d.ts +3 -2
- package/lib/esm/actions/vaultV1/redeem.js +2 -1
- package/lib/esm/actions/vaultV1/withdraw.d.ts +2 -1
- package/lib/esm/actions/vaultV1/withdraw.js +2 -1
- package/lib/esm/actions/vaultV2/deposit.d.ts +2 -1
- package/lib/esm/actions/vaultV2/deposit.js +2 -1
- package/lib/esm/actions/vaultV2/forceWithdraw.d.ts +2 -1
- package/lib/esm/actions/vaultV2/forceWithdraw.js +2 -1
- package/lib/esm/actions/vaultV2/redeem.d.ts +3 -2
- package/lib/esm/actions/vaultV2/redeem.js +2 -1
- package/lib/esm/actions/vaultV2/withdraw.d.ts +2 -1
- package/lib/esm/actions/vaultV2/withdraw.js +2 -1
- package/lib/esm/constants.d.ts +1 -1
- package/lib/esm/constants.js +1 -1
- package/lib/esm/entities/blue/blue.d.ts +83 -20
- package/lib/esm/entities/blue/blue.js +38 -12
- package/lib/esm/entities/vaultV1/migrateToV2Quote.d.ts +2 -0
- package/lib/esm/entities/vaultV1/migrateToV2Quote.js +5 -0
- package/lib/esm/entities/vaultV1/vaultV1.d.ts +12 -6
- package/lib/esm/entities/vaultV1/vaultV1.js +7 -1
- package/lib/esm/entities/vaultV2/vaultV2.d.ts +12 -7
- package/lib/esm/entities/vaultV2/vaultV2.js +5 -1
- package/lib/esm/entities/vaultV2BlueReallocationData.d.ts +11 -2
- package/lib/esm/entities/vaultV2BlueReallocationData.js +17 -19
- package/lib/esm/helpers/constant.d.ts +2 -0
- package/lib/esm/helpers/constant.js +2 -0
- package/lib/esm/helpers/getBlueBundlesV1QuoteTimestamp.d.ts +10 -0
- package/lib/esm/helpers/getBlueBundlesV1QuoteTimestamp.js +15 -0
- package/lib/esm/helpers/index.d.ts +1 -1
- package/lib/esm/helpers/index.js +1 -1
- package/lib/esm/helpers/previewVaultV2ForceWithdraw.d.ts +3 -3
- package/lib/esm/helpers/previewVaultV2ForceWithdraw.js +4 -5
- package/lib/esm/helpers/quoteBlueRepay.d.ts +7 -3
- package/lib/esm/helpers/quoteBlueRepay.js +21 -8
- package/lib/esm/helpers/reallocationPenalty.d.ts +10 -0
- package/lib/esm/helpers/reallocationPenalty.js +28 -0
- package/lib/esm/helpers/referralFee.d.ts +2 -1
- package/lib/esm/helpers/referralFee.js +5 -1
- package/lib/esm/helpers/validate.d.ts +31 -4
- package/lib/esm/helpers/validate.js +48 -11
- package/lib/esm/helpers/validateMidnightBounds.d.ts +1 -2
- package/lib/esm/helpers/validateMidnightBounds.js +1 -2
- package/lib/esm/helpers/validateMidnightTakeFeasibility.d.ts +2 -2
- package/lib/esm/helpers/validateMidnightTakeFeasibility.js +1 -1
- package/lib/esm/transactionPlan/blue/borrow.d.ts +11 -5
- package/lib/esm/transactionPlan/blue/borrow.js +27 -9
- package/lib/esm/transactionPlan/blue/refinance.d.ts +9 -2
- package/lib/esm/transactionPlan/blue/refinance.js +20 -3
- package/lib/esm/transactionPlan/blue/repay.d.ts +1 -2
- package/lib/esm/transactionPlan/blue/repay.js +1 -2
- package/lib/esm/transactionPlan/blue/repayWithdrawCollateral.d.ts +4 -3
- package/lib/esm/transactionPlan/blue/repayWithdrawCollateral.js +13 -4
- package/lib/esm/transactionPlan/blue/supply.d.ts +1 -2
- package/lib/esm/transactionPlan/blue/supply.js +1 -2
- package/lib/esm/transactionPlan/blue/supplyCollateral.d.ts +2 -3
- package/lib/esm/transactionPlan/blue/supplyCollateral.js +2 -3
- package/lib/esm/transactionPlan/blue/supplyCollateralBorrow.d.ts +10 -4
- package/lib/esm/transactionPlan/blue/supplyCollateralBorrow.js +23 -6
- package/lib/esm/transactionPlan/blue/withdraw.d.ts +15 -5
- package/lib/esm/transactionPlan/blue/withdraw.js +25 -6
- package/lib/esm/transactionPlan/blue/withdrawCollateral.d.ts +5 -5
- package/lib/esm/transactionPlan/blue/withdrawCollateral.js +11 -7
- package/lib/esm/transactionPlan/deposit.js +5 -1
- package/lib/esm/transactionPlan/intent.d.ts +1 -1
- package/lib/esm/transactionPlan/intent.js +4 -2
- package/lib/esm/transactionPlan/plan.d.ts +8 -4
- package/lib/esm/transactionPlan/plan.js +8 -4
- package/lib/esm/transactionPlan/types.d.ts +6 -0
- package/lib/esm/transactionPlan/vaultv1/deposit.d.ts +3 -3
- package/lib/esm/transactionPlan/vaultv1/deposit.js +3 -3
- package/lib/esm/transactionPlan/vaultv1/migrateToV2.d.ts +3 -3
- package/lib/esm/transactionPlan/vaultv1/migrateToV2.js +8 -4
- package/lib/esm/transactionPlan/vaultv1/redeem.d.ts +1 -2
- package/lib/esm/transactionPlan/vaultv1/redeem.js +1 -2
- package/lib/esm/transactionPlan/vaultv1/withdraw.d.ts +2 -3
- package/lib/esm/transactionPlan/vaultv1/withdraw.js +2 -3
- package/lib/esm/transactionPlan/vaultv2/deposit.d.ts +3 -3
- package/lib/esm/transactionPlan/vaultv2/deposit.js +3 -3
- package/lib/esm/transactionPlan/vaultv2/forceWithdraw.d.ts +3 -3
- package/lib/esm/transactionPlan/vaultv2/forceWithdraw.js +3 -3
- package/lib/esm/transactionPlan/vaultv2/redeem.d.ts +2 -3
- package/lib/esm/transactionPlan/vaultv2/redeem.js +2 -3
- package/lib/esm/transactionPlan/vaultv2/withdraw.d.ts +2 -3
- package/lib/esm/transactionPlan/vaultv2/withdraw.js +2 -3
- package/lib/esm/types/error.d.ts +7 -6
- package/lib/esm/types/error.js +11 -10
- package/lib/esm/types/sharedLiquidity.d.ts +7 -2
- package/lib/esm/version.d.ts +1 -1
- package/lib/esm/version.js +1 -1
- package/package.json +3 -3
|
@@ -12,7 +12,7 @@ import { buildVaultV1Withdraw, } from "../../actions/vaultV1/withdraw.js";
|
|
|
12
12
|
import { computeVaultMaxShareAllowance, computeVaultMaxSharePrice, validateChainId, validateSlippageTolerance, } from "../../helpers/index.js";
|
|
13
13
|
import { resolveTransactionMetadata } from "../../helpers/metadata.js";
|
|
14
14
|
import { parseUint256 } from "../../helpers/parse.js";
|
|
15
|
-
import { validateNativeVaultAsset } from "../../helpers/validate.js";
|
|
15
|
+
import { validateNativeVaultAsset, validateReferenceTime, validateVaultDepositDeadline, } from "../../helpers/validate.js";
|
|
16
16
|
import { AmountAndSharesExclusiveError, ExpiredDeadlineError, NonPositiveInputError, SameVaultMigrationError, VaultAddressMismatchError, VaultAssetMismatchError, } from "../../types/index.js";
|
|
17
17
|
import { assertRegistryTargetsHaveCode } from "../requirements/assertContractCode.js";
|
|
18
18
|
import { getParsedBundlesTokenRequirements, parseGetBundlesTokenRequirements, } from "../requirements/getBundlesTokenRequirements.js";
|
|
@@ -73,6 +73,8 @@ export class MorphoVaultV1 {
|
|
|
73
73
|
throw new VaultAddressMismatchError(this.vault, vaultData.address);
|
|
74
74
|
}
|
|
75
75
|
const createdAt = suppliedNow ?? Time.timestamp();
|
|
76
|
+
// Reject a non-bigint clock before deriving the default deadline.
|
|
77
|
+
validateReferenceTime(createdAt);
|
|
76
78
|
const deadline = params.deadline ?? createdAt + Time.s.from.h(2n);
|
|
77
79
|
if (deadline <= createdAt) {
|
|
78
80
|
throw new ExpiredDeadlineError(deadline, createdAt);
|
|
@@ -89,6 +91,8 @@ export class MorphoVaultV1 {
|
|
|
89
91
|
validateNativeVaultAsset(this.chainId, vaultAsset);
|
|
90
92
|
}
|
|
91
93
|
const referralFeeAssets = getBundlesReferralFeeAssets(funding.assets, common.referralFeePct);
|
|
94
|
+
// Bound forward accrual before deriving the deposit price protection.
|
|
95
|
+
validateVaultDepositDeadline(deadline, { now: createdAt });
|
|
92
96
|
const maxSharePrice = computeVaultMaxSharePrice({
|
|
93
97
|
vaultData,
|
|
94
98
|
deadline,
|
|
@@ -417,6 +421,8 @@ export class MorphoVaultV1 {
|
|
|
417
421
|
const slippageTolerance = params.slippageTolerance ?? DEFAULT_SLIPPAGE_TOLERANCE;
|
|
418
422
|
validateSlippageTolerance(slippageTolerance);
|
|
419
423
|
const createdAt = suppliedNow ?? Time.timestamp();
|
|
424
|
+
// Reject a non-bigint clock before deriving the default deadline.
|
|
425
|
+
validateReferenceTime(createdAt);
|
|
420
426
|
const deadline = params.deadline ?? createdAt + Time.s.from.h(2n);
|
|
421
427
|
if (deadline <= createdAt) {
|
|
422
428
|
throw new ExpiredDeadlineError(deadline, createdAt);
|
|
@@ -45,7 +45,7 @@ export interface VaultV2Actions {
|
|
|
45
45
|
* only for a wNative vault.
|
|
46
46
|
* @param params.slippageTolerance - Optional WAD-scaled tolerance; defaults to 0.03% and cannot
|
|
47
47
|
* exceed 10%.
|
|
48
|
-
* @param params.referralFeePct - Optional WAD-scaled referral fee
|
|
48
|
+
* @param params.referralFeePct - Optional WAD-scaled referral fee at most 10%, deducted before
|
|
49
49
|
* the vault deposit.
|
|
50
50
|
* @param params.referralFeeRecipient - Non-zero recipient required for a positive referral fee.
|
|
51
51
|
* @param params.deadline - Optional execution and permit deadline in Unix seconds; defaults to
|
|
@@ -56,16 +56,18 @@ export interface VaultV2Actions {
|
|
|
56
56
|
* `getRequirements()` when the RPC reports another chain via `eth_chainId`.
|
|
57
57
|
* @throws {UnsupportedBlueMarketIrmError} when an underlying market with positive debt uses an unsupported IRM.
|
|
58
58
|
* @throws {VaultAddressMismatchError} when `vaultData` belongs to another vault.
|
|
59
|
+
* @throws {InvalidBigIntInputError} when `now` is not a bigint.
|
|
59
60
|
* @throws {ExpiredDeadlineError} when the deadline is stale at creation or requirement resolution.
|
|
60
61
|
* @throws {MixedBundlesFundingError} when ERC-20 and native funding are both supplied.
|
|
61
62
|
* @throws {NegativeInputError} when funding, slippage, or the referral fee is negative.
|
|
62
63
|
* @throws {NonPositiveInputError} when funding or the previewed vault shares are not positive.
|
|
63
64
|
* @throws {ExcessiveSlippageToleranceError} when slippage tolerance exceeds the SDK maximum.
|
|
64
65
|
* @throws {ReferralFeePctExceededError} when the referral fee is at least WAD.
|
|
66
|
+
* @throws {MidnightReferralFeePctExceededError} when the referral fee is above 10% but below WAD.
|
|
65
67
|
* @throws {ReferralFeeRecipientMissingError} when a positive referral fee has no recipient.
|
|
66
68
|
* @throws {ChainWNativeMissingError} when native funding is requested on a chain without wNative.
|
|
67
69
|
* @throws {NativeAmountOnNonWNativeVaultError} when native funding targets a non-wNative vault.
|
|
68
|
-
* @throws {InputExceedsMaxError} when funding or the deadline exceeds uint256.
|
|
70
|
+
* @throws {InputExceedsMaxError} when the deadline exceeds seven days after creation or funding or the deadline exceeds uint256.
|
|
69
71
|
* @throws {AmbiguousRequirementSignaturesError} from `buildTx()` when multiple token signatures are supplied.
|
|
70
72
|
* @throws {UnexpectedRequirementSignatureError} from `buildTx()` when an unsupported signature is supplied.
|
|
71
73
|
* @throws {BundlesPermitMismatchError} from `buildTx()` when the signature's spender, amount or
|
|
@@ -128,7 +130,7 @@ export interface VaultV2Actions {
|
|
|
128
130
|
* @param params.slippageTolerance - Optional WAD-scaled tolerance used only to size the minimum
|
|
129
131
|
* share allowance. It does not impose an on-chain share-burn bound.
|
|
130
132
|
* Defaults to 0.03% and cannot exceed 10%.
|
|
131
|
-
* @param params.referralFeePct - Optional WAD-scaled fee
|
|
133
|
+
* @param params.referralFeePct - Optional WAD-scaled fee from 0% to 10%, inclusive, defaulting to zero;
|
|
132
134
|
* rounded down and deducted from the gross withdrawn assets.
|
|
133
135
|
* @param params.referralFeeRecipient - Optional nonzero recipient required for a positive fee.
|
|
134
136
|
* @param params.deadline - Optional execution and share-permit deadline in Unix seconds;
|
|
@@ -150,6 +152,7 @@ export interface VaultV2Actions {
|
|
|
150
152
|
* @throws {InputExceedsMaxError} when `amount` or `deadline` exceeds uint256 at handle creation.
|
|
151
153
|
* @throws {NegativeInputError} when `referralFeePct` or `slippageTolerance` is negative.
|
|
152
154
|
* @throws {ReferralFeePctExceededError} when `referralFeePct` is at least WAD.
|
|
155
|
+
* @throws {MidnightReferralFeePctExceededError} when the referral fee is above 10% but below WAD.
|
|
153
156
|
* @throws {ReferralFeeRecipientMissingError} when a positive referral fee has no nonzero recipient.
|
|
154
157
|
* @throws {ExcessiveSlippageToleranceError} when `slippageTolerance` exceeds 10%.
|
|
155
158
|
* @throws {VaultAddressMismatchError} when `vaultData` belongs to another vault.
|
|
@@ -204,7 +207,7 @@ export interface VaultV2Actions {
|
|
|
204
207
|
* @param params - The redeem parameters.
|
|
205
208
|
* @param params.shares - Exact vault shares to burn.
|
|
206
209
|
* @param params.userAddress - Account that must sign and submit the transaction; VaultBundlesV1 burns `msg.sender`'s shares and pays `msg.sender`.
|
|
207
|
-
* @param [params.referralFeePct=0n] - WAD-scaled referral fee deducted from the redeemed assets; must be
|
|
210
|
+
* @param [params.referralFeePct=0n] - WAD-scaled referral fee deducted from the redeemed assets; must be at most 10%.
|
|
208
211
|
* @param [params.referralFeeRecipient] - Non-zero recipient required when `referralFeePct` is positive.
|
|
209
212
|
* @param [params.deadline] - VaultBundlesV1 execution deadline; defaults to two hours from now.
|
|
210
213
|
* @returns Lazy share-allowance requirements and a synchronous transaction builder.
|
|
@@ -216,6 +219,7 @@ export interface VaultV2Actions {
|
|
|
216
219
|
* @throws {InputExceedsMaxError} when `shares` or `deadline` exceeds uint256.
|
|
217
220
|
* @throws {NegativeInputError} when `referralFeePct` is negative.
|
|
218
221
|
* @throws {ReferralFeePctExceededError} when `referralFeePct` is not below WAD.
|
|
222
|
+
* @throws {MidnightReferralFeePctExceededError} when the referral fee is above 10% but below WAD.
|
|
219
223
|
* @throws {ReferralFeeRecipientMissingError} when a positive fee has no non-zero recipient.
|
|
220
224
|
* @throws {UnsupportedChainIdError} when no address registry exists for the target chain.
|
|
221
225
|
* @throws {UnknownAddressError} when VaultBundlesV1 is not registered on the target chain.
|
|
@@ -410,7 +414,7 @@ export interface VaultV2Actions {
|
|
|
410
414
|
* derived at `MAX_SLIPPAGE_TOLERANCE`. When that floor rounds down to zero (dust exits) it is
|
|
411
415
|
* clamped to `1`, so any positive override is accepted.
|
|
412
416
|
* @param params.referralFeePct - Optional WAD-scaled share of the withdrawn assets routed to
|
|
413
|
-
* `referralFeeRecipient
|
|
417
|
+
* `referralFeeRecipient`, at most 10%. Defaults to `0n`.
|
|
414
418
|
* @param params.referralFeeRecipient - Optional referral fee recipient, required when
|
|
415
419
|
* `referralFeePct` is positive.
|
|
416
420
|
* @returns Lazy prerequisite resolution and a synchronous transaction builder.
|
|
@@ -421,8 +425,9 @@ export interface VaultV2Actions {
|
|
|
421
425
|
* `minSharePriceE27` is not positive.
|
|
422
426
|
* @throws {NegativeInputError} when `slippageTolerance` or `referralFeePct` is negative.
|
|
423
427
|
* @throws {InputExceedsMaxError} when `exitAssets`, `deadline`, or the effective
|
|
424
|
-
* `minSharePriceE27` (supplied or derived) exceeds `uint256`, or when `
|
|
425
|
-
*
|
|
428
|
+
* `minSharePriceE27` (supplied or derived) exceeds `uint256`, or when `deadline` is more than one year after handle creation.
|
|
429
|
+
* @throws {ReferralFeePctExceededError} when the referral fee is at least WAD.
|
|
430
|
+
* @throws {MidnightReferralFeePctExceededError} when the referral fee is above 10% but below WAD.
|
|
426
431
|
* @throws {ExpiredDeadlineError} when `deadline` is not in the future at handle creation or
|
|
427
432
|
* requirement resolution.
|
|
428
433
|
* @throws {ExcessiveSlippageToleranceError} when `slippageTolerance` exceeds the SDK maximum.
|
|
@@ -13,7 +13,7 @@ import { buildVaultV2Withdraw, } from "../../actions/vaultV2/withdraw.js";
|
|
|
13
13
|
import { computeVaultMaxShareAllowance, computeVaultMaxSharePrice, validateChainId, validateSlippageTolerance, } from "../../helpers/index.js";
|
|
14
14
|
import { resolveTransactionMetadata } from "../../helpers/metadata.js";
|
|
15
15
|
import { parseUint256 } from "../../helpers/parse.js";
|
|
16
|
-
import { validateNativeVaultAsset } from "../../helpers/validate.js";
|
|
16
|
+
import { validateNativeVaultAsset, validateReferenceTime, validateVaultDepositDeadline, } from "../../helpers/validate.js";
|
|
17
17
|
import { ExpiredDeadlineError, NonPositiveInputError, VaultAddressMismatchError, } from "../../types/index.js";
|
|
18
18
|
import { assertRegistryTargetsHaveCode } from "../requirements/assertContractCode.js";
|
|
19
19
|
import { getParsedBundlesTokenRequirements, parseGetBundlesTokenRequirements, } from "../requirements/getBundlesTokenRequirements.js";
|
|
@@ -74,6 +74,8 @@ export class MorphoVaultV2 {
|
|
|
74
74
|
throw new VaultAddressMismatchError(this.vault, vaultData.address);
|
|
75
75
|
}
|
|
76
76
|
const createdAt = suppliedNow ?? Time.timestamp();
|
|
77
|
+
// Reject a non-bigint clock before deriving the default deadline.
|
|
78
|
+
validateReferenceTime(createdAt);
|
|
77
79
|
const deadline = params.deadline ?? createdAt + Time.s.from.h(2n);
|
|
78
80
|
if (deadline <= createdAt) {
|
|
79
81
|
throw new ExpiredDeadlineError(deadline, createdAt);
|
|
@@ -90,6 +92,8 @@ export class MorphoVaultV2 {
|
|
|
90
92
|
validateNativeVaultAsset(this.chainId, vaultAsset);
|
|
91
93
|
}
|
|
92
94
|
const referralFeeAssets = getBundlesReferralFeeAssets(funding.assets, common.referralFeePct);
|
|
95
|
+
// Bound forward accrual before deriving the deposit price protection.
|
|
96
|
+
validateVaultDepositDeadline(deadline, { now: createdAt });
|
|
93
97
|
const maxSharePrice = computeVaultMaxSharePrice({
|
|
94
98
|
vaultData,
|
|
95
99
|
deadline,
|
|
@@ -402,8 +402,13 @@ export declare class VaultV2BlueReallocationData implements InputVaultV2BlueReal
|
|
|
402
402
|
* destination-market handle (for example,
|
|
403
403
|
* `client.morpho.blue(destination.marketParams, chainId)`), not the source
|
|
404
404
|
* handle. Pass the source position's `borrowAssets` accrued to
|
|
405
|
-
*
|
|
406
|
-
* `
|
|
405
|
+
* the resolved plan expiry (or the required action deadline for entity
|
|
406
|
+
* `refinance`) as `operation.amount`. With
|
|
407
|
+
* `minTs = max(now, source.lastUpdate, destination.lastUpdate)`, the horizon is
|
|
408
|
+
* `max(minTs, resolved expiry)`. For `prepareBlueRefinance`, omitted `expiresAt`
|
|
409
|
+
* resolves to `now + 2h`, not `minTs + 2h`. Only when the resolved expiry exceeds
|
|
410
|
+
* `minTs + 365 days`, use `minTs + 2h` for unlimited-deadline sentinel
|
|
411
|
+
* compatibility. The optional `operation.referralFeePct` is WAD-scaled.
|
|
407
412
|
* The planner includes the referral fee and its allocator-leg penalties in
|
|
408
413
|
* destination debt, so penalized legs also cover their own penalty.
|
|
409
414
|
* Refinance never uses vaults with a 100% penalty.
|
|
@@ -467,8 +472,10 @@ export declare class VaultV2BlueReallocationData implements InputVaultV2BlueReal
|
|
|
467
472
|
* @returns Flat action-ready reallocations and their post-simulation state.
|
|
468
473
|
* @throws {UnsupportedBlueMarketIrmError} when a market with positive debt uses an unsupported IRM.
|
|
469
474
|
* @throws {NegativeInputError} when `capAccrualBuffer`, `allocatorCapHeadroom`, `maxWithdrawalUtilization`, `maxPenalty`, or `referralFeePct` is negative.
|
|
475
|
+
* @throws {InvalidBigIntInputError} when a supplied maxPenalty is not a bigint.
|
|
470
476
|
* @throws {InputExceedsMaxError} when `allocatorCapHeadroom`, `maxWithdrawalUtilization`, or `maxPenalty` exceeds WAD, or an enabled borrow/withdraw plan otherwise covers its shortfall but its planned penalty exceeds the operation amount.
|
|
471
477
|
* @throws {ReferralFeePctExceededError} when `referralFeePct` is at least WAD.
|
|
478
|
+
* @throws {MidnightReferralFeePctExceededError} when the fee is above 10% but below WAD.
|
|
472
479
|
* @throws {NonPositiveInputError} when the operation amount is not positive and planning is enabled.
|
|
473
480
|
* @throws {UnknownReallocationMarketError} when a required market is absent.
|
|
474
481
|
* @throws {UnknownReallocationVaultError} when configured vault state is absent.
|
|
@@ -538,6 +545,7 @@ export declare class VaultV2BlueReallocationData implements InputVaultV2BlueReal
|
|
|
538
545
|
* @returns Reallocatable market and idle assets, or `0n` when none are available; rounding-only shared-cap fits may be conservatively omitted.
|
|
539
546
|
* @throws {UnsupportedBlueMarketIrmError} when a market with positive debt uses an unsupported IRM.
|
|
540
547
|
* @throws {NegativeInputError} when `capAccrualBuffer`, `maxWithdrawalUtilization`, or `maxPenalty` is negative.
|
|
548
|
+
* @throws {InvalidBigIntInputError} when a supplied maxPenalty is not a bigint.
|
|
541
549
|
* @throws {InputExceedsMaxError} when `maxWithdrawalUtilization` or `maxPenalty` exceeds WAD.
|
|
542
550
|
* @throws {UnknownReallocationMarketError} when a required market is absent.
|
|
543
551
|
* @throws {UnknownReallocationVaultError} when configured vault state is absent.
|
|
@@ -585,6 +593,7 @@ export declare class VaultV2BlueReallocationData implements InputVaultV2BlueReal
|
|
|
585
593
|
* @returns Borrowable assets while remaining at or below `utilization`; rounding-only shared-cap fits may be conservatively omitted.
|
|
586
594
|
* @throws {UnsupportedBlueMarketIrmError} when a market with positive debt uses an unsupported IRM.
|
|
587
595
|
* @throws {NegativeInputError} when `capAccrualBuffer`, `maxWithdrawalUtilization`, or `maxPenalty` is negative.
|
|
596
|
+
* @throws {InvalidBigIntInputError} when a supplied maxPenalty is not a bigint.
|
|
588
597
|
* @throws {InputExceedsMaxError} when `maxWithdrawalUtilization` or `maxPenalty` exceeds WAD.
|
|
589
598
|
* @throws {UnknownReallocationMarketError} when a required market is absent.
|
|
590
599
|
* @throws {UnknownReallocationVaultError} when configured vault state is absent.
|
|
@@ -2,8 +2,10 @@ import { AccrualPosition, AccrualVault, AccrualVaultV2, AccrualVaultV2MorphoMark
|
|
|
2
2
|
import { _try, bigIntComparator } from "@morpho-org/morpho-ts";
|
|
3
3
|
import { isAddressEqual } from "viem";
|
|
4
4
|
import { getBlueBundlesV1PenaltyAssets, getBlueBundlesV1ReferralFeeAssets, } from "../actions/blue/common.js";
|
|
5
|
-
import {
|
|
5
|
+
import { DEFAULT_SUPPLY_TARGET_UTILIZATION } from "../helpers/constant.js";
|
|
6
|
+
import { resolveMaxPenalty } from "../helpers/reallocationPenalty.js";
|
|
6
7
|
import { resolveAllocatorCapHeadroom, resolveCapAccrualBuffer, resolveMaxWithdrawalUtilization, } from "../helpers/utilization.js";
|
|
8
|
+
import { validateMidnightReferralFeeCap } from "../helpers/validateMidnightBounds.js";
|
|
7
9
|
import { InputExceedsMaxError, InsufficientSharedLiquidityError, NegativeInputError, NonPositiveInputError, ReallocationAdapterSupplySharesUnderflowError, ReallocationAllocationUnderflowError, ReallocationWithdrawExceedsMarketSupplyError, ReferralFeePctExceededError, UnknownReallocationActiveAdaptersError, UnknownReallocationAdapterError, UnknownReallocationAllocationError, UnknownReallocationMarketError, UnknownReallocationMarketPublicAllocatorConfigError, UnknownReallocationPublicAllocatorConfigError, UnknownReallocationVaultError, } from "../types/index.js";
|
|
8
10
|
const MAX_SHARED_CAP_SEARCH_STEPS = 1024n;
|
|
9
11
|
const createCapReserveState = (markets) => ({
|
|
@@ -63,20 +65,6 @@ const getAdapterIds = (cache, adapter, market) => {
|
|
|
63
65
|
cache.set(key, ids);
|
|
64
66
|
return ids;
|
|
65
67
|
};
|
|
66
|
-
const resolveMaxPenalty = (value) => {
|
|
67
|
-
const penalty = value ?? DEFAULT_MAX_REALLOCATION_PENALTY;
|
|
68
|
-
if (penalty < 0n) {
|
|
69
|
-
throw new NegativeInputError("maxPenalty", penalty);
|
|
70
|
-
}
|
|
71
|
-
if (penalty > MAX_REALLOCATION_PENALTY) {
|
|
72
|
-
throw new InputExceedsMaxError({
|
|
73
|
-
field: "maxPenalty",
|
|
74
|
-
value: penalty,
|
|
75
|
-
max: MAX_REALLOCATION_PENALTY,
|
|
76
|
-
});
|
|
77
|
-
}
|
|
78
|
-
return penalty;
|
|
79
|
-
};
|
|
80
68
|
const getCanonicalMarket = (markets, market) => (markets[market.id] ??= new Market({ ...market }));
|
|
81
69
|
const clonePosition = (position, markets) => new AccrualPosition(position, getCanonicalMarket(markets, position.market));
|
|
82
70
|
const cloneAccrualVault = (vault, markets) => new AccrualVault({
|
|
@@ -604,8 +592,13 @@ export class VaultV2BlueReallocationData {
|
|
|
604
592
|
* destination-market handle (for example,
|
|
605
593
|
* `client.morpho.blue(destination.marketParams, chainId)`), not the source
|
|
606
594
|
* handle. Pass the source position's `borrowAssets` accrued to
|
|
607
|
-
*
|
|
608
|
-
* `
|
|
595
|
+
* the resolved plan expiry (or the required action deadline for entity
|
|
596
|
+
* `refinance`) as `operation.amount`. With
|
|
597
|
+
* `minTs = max(now, source.lastUpdate, destination.lastUpdate)`, the horizon is
|
|
598
|
+
* `max(minTs, resolved expiry)`. For `prepareBlueRefinance`, omitted `expiresAt`
|
|
599
|
+
* resolves to `now + 2h`, not `minTs + 2h`. Only when the resolved expiry exceeds
|
|
600
|
+
* `minTs + 365 days`, use `minTs + 2h` for unlimited-deadline sentinel
|
|
601
|
+
* compatibility. The optional `operation.referralFeePct` is WAD-scaled.
|
|
609
602
|
* The planner includes the referral fee and its allocator-leg penalties in
|
|
610
603
|
* destination debt, so penalized legs also cover their own penalty.
|
|
611
604
|
* Refinance never uses vaults with a 100% penalty.
|
|
@@ -669,8 +662,10 @@ export class VaultV2BlueReallocationData {
|
|
|
669
662
|
* @returns Flat action-ready reallocations and their post-simulation state.
|
|
670
663
|
* @throws {UnsupportedBlueMarketIrmError} when a market with positive debt uses an unsupported IRM.
|
|
671
664
|
* @throws {NegativeInputError} when `capAccrualBuffer`, `allocatorCapHeadroom`, `maxWithdrawalUtilization`, `maxPenalty`, or `referralFeePct` is negative.
|
|
665
|
+
* @throws {InvalidBigIntInputError} when a supplied maxPenalty is not a bigint.
|
|
672
666
|
* @throws {InputExceedsMaxError} when `allocatorCapHeadroom`, `maxWithdrawalUtilization`, or `maxPenalty` exceeds WAD, or an enabled borrow/withdraw plan otherwise covers its shortfall but its planned penalty exceeds the operation amount.
|
|
673
667
|
* @throws {ReferralFeePctExceededError} when `referralFeePct` is at least WAD.
|
|
668
|
+
* @throws {MidnightReferralFeePctExceededError} when the fee is above 10% but below WAD.
|
|
674
669
|
* @throws {NonPositiveInputError} when the operation amount is not positive and planning is enabled.
|
|
675
670
|
* @throws {UnknownReallocationMarketError} when a required market is absent.
|
|
676
671
|
* @throws {UnknownReallocationVaultError} when configured vault state is absent.
|
|
@@ -940,6 +935,7 @@ export class VaultV2BlueReallocationData {
|
|
|
940
935
|
* @returns Reallocatable market and idle assets, or `0n` when none are available; rounding-only shared-cap fits may be conservatively omitted.
|
|
941
936
|
* @throws {UnsupportedBlueMarketIrmError} when a market with positive debt uses an unsupported IRM.
|
|
942
937
|
* @throws {NegativeInputError} when `capAccrualBuffer`, `maxWithdrawalUtilization`, or `maxPenalty` is negative.
|
|
938
|
+
* @throws {InvalidBigIntInputError} when a supplied maxPenalty is not a bigint.
|
|
943
939
|
* @throws {InputExceedsMaxError} when `maxWithdrawalUtilization` or `maxPenalty` exceeds WAD.
|
|
944
940
|
* @throws {UnknownReallocationMarketError} when a required market is absent.
|
|
945
941
|
* @throws {UnknownReallocationVaultError} when configured vault state is absent.
|
|
@@ -1003,6 +999,7 @@ export class VaultV2BlueReallocationData {
|
|
|
1003
999
|
* @returns Borrowable assets while remaining at or below `utilization`; rounding-only shared-cap fits may be conservatively omitted.
|
|
1004
1000
|
* @throws {UnsupportedBlueMarketIrmError} when a market with positive debt uses an unsupported IRM.
|
|
1005
1001
|
* @throws {NegativeInputError} when `capAccrualBuffer`, `maxWithdrawalUtilization`, or `maxPenalty` is negative.
|
|
1002
|
+
* @throws {InvalidBigIntInputError} when a supplied maxPenalty is not a bigint.
|
|
1006
1003
|
* @throws {InputExceedsMaxError} when `maxWithdrawalUtilization` or `maxPenalty` exceeds WAD.
|
|
1007
1004
|
* @throws {UnknownReallocationMarketError} when a required market is absent.
|
|
1008
1005
|
* @throws {UnknownReallocationVaultError} when configured vault state is absent.
|
|
@@ -1591,8 +1588,7 @@ function resolveVaultCandidateIdleState(params) {
|
|
|
1591
1588
|
}
|
|
1592
1589
|
const vault = data.getVault(vaultAddress);
|
|
1593
1590
|
if (!isAddressEqual(publicAllocatorConfig.vault, vaultAddress) ||
|
|
1594
|
-
publicAllocatorConfig.penalty >
|
|
1595
|
-
(options.maxPenalty ?? DEFAULT_MAX_REALLOCATION_PENALTY)) {
|
|
1591
|
+
publicAllocatorConfig.penalty > resolveMaxPenalty(options.maxPenalty)) {
|
|
1596
1592
|
return;
|
|
1597
1593
|
}
|
|
1598
1594
|
if (penalty != null && publicAllocatorConfig.penalty !== penalty) {
|
|
@@ -2464,6 +2460,8 @@ function resolveOperationFeeAssets(operation) {
|
|
|
2464
2460
|
if (referralFeePct >= MathLib.WAD) {
|
|
2465
2461
|
throw new ReferralFeePctExceededError(referralFeePct);
|
|
2466
2462
|
}
|
|
2463
|
+
// Reject fees that the refinance bundle builder would reject.
|
|
2464
|
+
validateMidnightReferralFeeCap(referralFeePct);
|
|
2467
2465
|
const feeAssets = operation.type === "refinance"
|
|
2468
2466
|
? getBlueBundlesV1ReferralFeeAssets(amount, referralFeePct)
|
|
2469
2467
|
: 0n;
|
|
@@ -1,4 +1,6 @@
|
|
|
1
1
|
import { type Address } from "viem";
|
|
2
|
+
/** Maximum forward accrual window for vault deposits and V1-to-V2 migration, in seconds. */
|
|
3
|
+
export declare const VAULT_DEPOSIT_MAX_DEADLINE_SECONDS = 604800n;
|
|
2
4
|
/** Maximum time between now and a Midnight taker-flow deadline, in seconds. */
|
|
3
5
|
export declare const MIDNIGHT_TAKE_MAX_DEADLINE_SECONDS = 3600n;
|
|
4
6
|
/**
|
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
import { ChainId, MathLib } from "@morpho-org/blue-sdk";
|
|
2
2
|
import { Time } from "@morpho-org/morpho-ts";
|
|
3
3
|
import { maxUint96 } from "viem";
|
|
4
|
+
/** Maximum forward accrual window for vault deposits and V1-to-V2 migration, in seconds. */
|
|
5
|
+
export const VAULT_DEPOSIT_MAX_DEADLINE_SECONDS = 604800n;
|
|
4
6
|
/** Maximum time between now and a Midnight taker-flow deadline, in seconds. */
|
|
5
7
|
export const MIDNIGHT_TAKE_MAX_DEADLINE_SECONDS = 3600n;
|
|
6
8
|
/**
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @internal Projects health to realistic finite deadlines, never before now or the market snapshot.
|
|
3
|
+
* Deadlines more than 365 days out (maxUint256/maxUint48-style unlimited sentinels) use
|
|
4
|
+
* the legacy two-hour projection to avoid interest-accrual overflow.
|
|
5
|
+
*/
|
|
6
|
+
export declare function getBlueBundlesV1QuoteTimestamp({ lastUpdate, now, deadline, }: {
|
|
7
|
+
readonly lastUpdate: bigint;
|
|
8
|
+
readonly now: bigint;
|
|
9
|
+
readonly deadline?: bigint;
|
|
10
|
+
}): bigint;
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { MathLib } from "@morpho-org/blue-sdk";
|
|
2
|
+
import { Time } from "@morpho-org/morpho-ts";
|
|
3
|
+
const MAX_BLUE_HEALTH_DEADLINE_HORIZON = Time.s.from.d(365n);
|
|
4
|
+
/**
|
|
5
|
+
* @internal Projects health to realistic finite deadlines, never before now or the market snapshot.
|
|
6
|
+
* Deadlines more than 365 days out (maxUint256/maxUint48-style unlimited sentinels) use
|
|
7
|
+
* the legacy two-hour projection to avoid interest-accrual overflow.
|
|
8
|
+
*/
|
|
9
|
+
export function getBlueBundlesV1QuoteTimestamp({ lastUpdate, now, deadline, }) {
|
|
10
|
+
const minTimestamp = MathLib.max(now, lastUpdate);
|
|
11
|
+
return deadline === undefined ||
|
|
12
|
+
deadline > minTimestamp + MAX_BLUE_HEALTH_DEADLINE_HORIZON
|
|
13
|
+
? minTimestamp + Time.s.from.h(2n)
|
|
14
|
+
: MathLib.max(minTimestamp, deadline);
|
|
15
|
+
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
export { getMidnightBlueBuyCallbackAddress, getMidnightBlueBuyCallbackData, } from "./callback.js";
|
|
2
|
-
export { APPROVE_ONLY_ONCE_TOKENS, DEFAULT_ALLOCATOR_CAP_HEADROOM, DEFAULT_CAP_ACCRUAL_BUFFER, DEFAULT_LLTV_BUFFER, DEFAULT_MAX_REALLOCATION_PENALTY, DEFAULT_SUPPLY_TARGET_UTILIZATION, DEFAULT_WITHDRAWAL_TARGET_UTILIZATION, MAX_ABSOLUTE_SHARE_PRICE, MAX_REALLOCATION_PENALTY, MAX_SLIPPAGE_TOLERANCE, MAX_TOKEN_APPROVALS, MIDNIGHT_TAKE_MAX_DEADLINE_SECONDS, MIN_DEAD_SHARES, MIN_VAULT_V2_DEAD_ASSETS, } from "./constant.js";
|
|
2
|
+
export { APPROVE_ONLY_ONCE_TOKENS, DEFAULT_ALLOCATOR_CAP_HEADROOM, DEFAULT_CAP_ACCRUAL_BUFFER, DEFAULT_LLTV_BUFFER, DEFAULT_MAX_REALLOCATION_PENALTY, DEFAULT_SUPPLY_TARGET_UTILIZATION, DEFAULT_WITHDRAWAL_TARGET_UTILIZATION, MAX_ABSOLUTE_SHARE_PRICE, MAX_REALLOCATION_PENALTY, MAX_SLIPPAGE_TOLERANCE, MAX_TOKEN_APPROVALS, MIDNIGHT_TAKE_MAX_DEADLINE_SECONDS, MIN_DEAD_SHARES, MIN_VAULT_V2_DEAD_ASSETS, VAULT_DEPOSIT_MAX_DEADLINE_SECONDS, } from "./constant.js";
|
|
3
3
|
export { validateBlueMarketDeadShares, validateVaultV1DeadShares, validateVaultV2DeadShares, } from "./deadShares.js";
|
|
4
4
|
export { addTransactionMetadata } from "./metadata.js";
|
|
5
5
|
export { type PreviewVaultV2ForceWithdrawParams, previewVaultV2ForceWithdraw, type VaultV2ForceWithdrawPreview, } from "./previewVaultV2ForceWithdraw.js";
|
package/lib/esm/helpers/index.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
export { getMidnightBlueBuyCallbackAddress, getMidnightBlueBuyCallbackData, } from "./callback.js";
|
|
2
|
-
export { APPROVE_ONLY_ONCE_TOKENS, DEFAULT_ALLOCATOR_CAP_HEADROOM, DEFAULT_CAP_ACCRUAL_BUFFER, DEFAULT_LLTV_BUFFER, DEFAULT_MAX_REALLOCATION_PENALTY, DEFAULT_SUPPLY_TARGET_UTILIZATION, DEFAULT_WITHDRAWAL_TARGET_UTILIZATION, MAX_ABSOLUTE_SHARE_PRICE, MAX_REALLOCATION_PENALTY, MAX_SLIPPAGE_TOLERANCE, MAX_TOKEN_APPROVALS, MIDNIGHT_TAKE_MAX_DEADLINE_SECONDS, MIN_DEAD_SHARES, MIN_VAULT_V2_DEAD_ASSETS, } from "./constant.js";
|
|
2
|
+
export { APPROVE_ONLY_ONCE_TOKENS, DEFAULT_ALLOCATOR_CAP_HEADROOM, DEFAULT_CAP_ACCRUAL_BUFFER, DEFAULT_LLTV_BUFFER, DEFAULT_MAX_REALLOCATION_PENALTY, DEFAULT_SUPPLY_TARGET_UTILIZATION, DEFAULT_WITHDRAWAL_TARGET_UTILIZATION, MAX_ABSOLUTE_SHARE_PRICE, MAX_REALLOCATION_PENALTY, MAX_SLIPPAGE_TOLERANCE, MAX_TOKEN_APPROVALS, MIDNIGHT_TAKE_MAX_DEADLINE_SECONDS, MIN_DEAD_SHARES, MIN_VAULT_V2_DEAD_ASSETS, VAULT_DEPOSIT_MAX_DEADLINE_SECONDS, } from "./constant.js";
|
|
3
3
|
export { validateBlueMarketDeadShares, validateVaultV1DeadShares, validateVaultV2DeadShares, } from "./deadShares.js";
|
|
4
4
|
export { addTransactionMetadata } from "./metadata.js";
|
|
5
5
|
export { previewVaultV2ForceWithdraw, } from "./previewVaultV2ForceWithdraw.js";
|
|
@@ -20,7 +20,7 @@ export interface PreviewVaultV2ForceWithdrawParams {
|
|
|
20
20
|
* without `userAddress`.
|
|
21
21
|
*/
|
|
22
22
|
readonly feeProjectionTimestamp?: bigint;
|
|
23
|
-
/** Optional WAD-scaled referral fee percentage. Defaults to `0n`. */
|
|
23
|
+
/** Optional WAD-scaled referral fee percentage from 0% to 10%, inclusive. Defaults to `0n`. */
|
|
24
24
|
readonly referralFeePct?: bigint;
|
|
25
25
|
/** Optional referral fee recipient. Required when `referralFeePct` is positive, as the entity
|
|
26
26
|
* enforces (`ReferralFeeRecipientMissingError`). When it equals `userAddress`, the fee is paid
|
|
@@ -78,7 +78,7 @@ export interface VaultV2ForceWithdrawPreview {
|
|
|
78
78
|
* `timestamp`. Pass the `forceWithdraw` deadline you will submit; the entity rejects deadlines
|
|
79
79
|
* more than one year after handle creation (`InputExceedsMaxError`) instead of clamping them, so
|
|
80
80
|
* keep the deadline itself within that horizon. Ignored without `userAddress`.
|
|
81
|
-
* @param params.referralFeePct - Optional WAD-scaled referral fee percentage. Defaults to `0n`.
|
|
81
|
+
* @param params.referralFeePct - Optional WAD-scaled referral fee percentage from 0% to 10%, inclusive. Defaults to `0n`.
|
|
82
82
|
* @param params.referralFeeRecipient - Optional referral fee recipient. Required when
|
|
83
83
|
* `referralFeePct` is positive, as the entity enforces (`ReferralFeeRecipientMissingError`).
|
|
84
84
|
* When it equals `userAddress`, the fee is paid back to the exiting account and `netAssets`
|
|
@@ -86,7 +86,7 @@ export interface VaultV2ForceWithdrawPreview {
|
|
|
86
86
|
* @returns The preview, or `undefined` when the exit is not previewable: not exactly one adapter, an
|
|
87
87
|
* `adapter` override that is not the vault's sole adapter, an adapter that is not a
|
|
88
88
|
* MorphoMarketV1AdapterV2, an unresolvable liquidity adapter, undecodable liquidity data, a
|
|
89
|
-
* `referralFeePct` outside `[0, WAD
|
|
89
|
+
* `referralFeePct` outside `[0, WAD / 10n]`, a positive `referralFeePct` without a non-zero
|
|
90
90
|
* `referralFeeRecipient`, a non-positive request, a request that yields nothing, a fee-recipient
|
|
91
91
|
* whose positive fee mints projected to `feeProjectionTimestamp` reach the lower burn bound, an
|
|
92
92
|
* exit whose realized share price rounds down to zero at the default slippage tolerance (which
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { DEFAULT_SLIPPAGE_TOLERANCE, MathLib, } from "@morpho-org/blue-sdk";
|
|
2
2
|
import { isAddressEqual, maxUint256, zeroAddress } from "viem";
|
|
3
|
+
import { MIDNIGHT_MAX_REFERRAL_FEE_PCT } from "./constant.js";
|
|
3
4
|
import { computeVaultV2ForceWithdrawFeeSharesMinted, computeVaultV2ForceWithdrawMinSharesBurnt, computeVaultV2ForceWithdrawPlan, computeVaultV2ForceWithdrawSharesBurnt, resolveVaultV2ForceWithdrawEligibility, } from "./vaultV2ForceWithdrawPlan.js";
|
|
4
5
|
/**
|
|
5
6
|
* Previews what a Vault V2 force withdrawal delivers, without any RPC.
|
|
@@ -24,7 +25,7 @@ import { computeVaultV2ForceWithdrawFeeSharesMinted, computeVaultV2ForceWithdraw
|
|
|
24
25
|
* `timestamp`. Pass the `forceWithdraw` deadline you will submit; the entity rejects deadlines
|
|
25
26
|
* more than one year after handle creation (`InputExceedsMaxError`) instead of clamping them, so
|
|
26
27
|
* keep the deadline itself within that horizon. Ignored without `userAddress`.
|
|
27
|
-
* @param params.referralFeePct - Optional WAD-scaled referral fee percentage. Defaults to `0n`.
|
|
28
|
+
* @param params.referralFeePct - Optional WAD-scaled referral fee percentage from 0% to 10%, inclusive. Defaults to `0n`.
|
|
28
29
|
* @param params.referralFeeRecipient - Optional referral fee recipient. Required when
|
|
29
30
|
* `referralFeePct` is positive, as the entity enforces (`ReferralFeeRecipientMissingError`).
|
|
30
31
|
* When it equals `userAddress`, the fee is paid back to the exiting account and `netAssets`
|
|
@@ -32,7 +33,7 @@ import { computeVaultV2ForceWithdrawFeeSharesMinted, computeVaultV2ForceWithdraw
|
|
|
32
33
|
* @returns The preview, or `undefined` when the exit is not previewable: not exactly one adapter, an
|
|
33
34
|
* `adapter` override that is not the vault's sole adapter, an adapter that is not a
|
|
34
35
|
* MorphoMarketV1AdapterV2, an unresolvable liquidity adapter, undecodable liquidity data, a
|
|
35
|
-
* `referralFeePct` outside `[0, WAD
|
|
36
|
+
* `referralFeePct` outside `[0, WAD / 10n]`, a positive `referralFeePct` without a non-zero
|
|
36
37
|
* `referralFeeRecipient`, a non-positive request, a request that yields nothing, a fee-recipient
|
|
37
38
|
* whose positive fee mints projected to `feeProjectionTimestamp` reach the lower burn bound, an
|
|
38
39
|
* exit whose realized share price rounds down to zero at the default slippage tolerance (which
|
|
@@ -59,9 +60,7 @@ export function previewVaultV2ForceWithdraw(vaultData, params) {
|
|
|
59
60
|
if (requestedExitAssets <= 0n) {
|
|
60
61
|
return undefined;
|
|
61
62
|
}
|
|
62
|
-
|
|
63
|
-
// deliver — above `withdrawnAssets` for a negative fee, non-positive at or beyond WAD.
|
|
64
|
-
if (referralFeePct < 0n || referralFeePct >= MathLib.WAD) {
|
|
63
|
+
if (referralFeePct < 0n || referralFeePct > MIDNIGHT_MAX_REFERRAL_FEE_PCT) {
|
|
65
64
|
return undefined;
|
|
66
65
|
}
|
|
67
66
|
if (referralFeePct > 0n &&
|
|
@@ -1,14 +1,18 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { AccrualPosition, type MarketId } from "@morpho-org/blue-sdk";
|
|
2
2
|
/** @internal Quotes repayment funding without projecting a position for health checks. */
|
|
3
3
|
export declare function quoteBlueRepayFunding(params: Parameters<typeof quoteBlueRepay>[0]): bigint;
|
|
4
|
-
/**
|
|
5
|
-
|
|
4
|
+
/**
|
|
5
|
+
* @internal Quotes repayment funding at the deadline independently of an optional withdrawal-health timestamp.
|
|
6
|
+
* Debt-free positions retain their snapshot without projecting market-wide interest.
|
|
7
|
+
*/
|
|
8
|
+
export declare function quoteBlueRepay({ positionData, marketId, repayAssets, repayShares, deadline, now, healthTimestamp, }: {
|
|
6
9
|
readonly positionData: AccrualPosition;
|
|
7
10
|
readonly marketId: MarketId;
|
|
8
11
|
readonly repayAssets: bigint;
|
|
9
12
|
readonly repayShares: bigint;
|
|
10
13
|
readonly deadline: bigint;
|
|
11
14
|
readonly now: bigint;
|
|
15
|
+
readonly healthTimestamp?: bigint;
|
|
12
16
|
}): {
|
|
13
17
|
simulatedRepayShares: bigint;
|
|
14
18
|
accruedPosition: AccrualPosition;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { AccrualPosition, MathLib } from "@morpho-org/blue-sdk";
|
|
2
2
|
import { Time } from "@morpho-org/morpho-ts";
|
|
3
3
|
import { maxUint256 } from "viem";
|
|
4
4
|
import { InputExceedsMaxError } from "../types/error.js";
|
|
@@ -13,8 +13,11 @@ export function quoteBlueRepayFunding(params) {
|
|
|
13
13
|
}
|
|
14
14
|
return params.repayAssets;
|
|
15
15
|
}
|
|
16
|
-
/**
|
|
17
|
-
|
|
16
|
+
/**
|
|
17
|
+
* @internal Quotes repayment funding at the deadline independently of an optional withdrawal-health timestamp.
|
|
18
|
+
* Debt-free positions retain their snapshot without projecting market-wide interest.
|
|
19
|
+
*/
|
|
20
|
+
export function quoteBlueRepay({ positionData, marketId, repayAssets, repayShares, deadline, now, healthTimestamp, }) {
|
|
18
21
|
const saturatedRepay = repayShares === maxUint256;
|
|
19
22
|
const simulatedRepayShares = saturatedRepay
|
|
20
23
|
? positionData.borrowShares
|
|
@@ -33,10 +36,20 @@ export function quoteBlueRepay({ positionData, marketId, repayAssets, repayShare
|
|
|
33
36
|
max: quoteHorizon,
|
|
34
37
|
});
|
|
35
38
|
}
|
|
36
|
-
const accrualTimestamp = repayShares > 0n ? deadline : quoteHorizon;
|
|
37
|
-
const accruedPosition = positionData.
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
39
|
+
const accrualTimestamp = healthTimestamp ?? (repayShares > 0n ? deadline : quoteHorizon);
|
|
40
|
+
const accruedPosition = positionData.borrowShares === 0n
|
|
41
|
+
? new AccrualPosition(positionData, positionData.market)
|
|
42
|
+
: positionData.accrueInterest(accrualTimestamp);
|
|
43
|
+
if (repayAssets > 0n || simulatedRepayShares <= 0n) {
|
|
44
|
+
return {
|
|
45
|
+
simulatedRepayShares,
|
|
46
|
+
accruedPosition,
|
|
47
|
+
expectedRepayAssets: repayAssets,
|
|
48
|
+
};
|
|
49
|
+
}
|
|
50
|
+
const fundingPosition = accrualTimestamp === deadline
|
|
51
|
+
? accruedPosition
|
|
52
|
+
: positionData.accrueInterest(deadline);
|
|
53
|
+
const expectedRepayAssets = fundingPosition.market.toBorrowAssets(simulatedRepayShares, "Up");
|
|
41
54
|
return { simulatedRepayShares, accruedPosition, expectedRepayAssets };
|
|
42
55
|
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Resolves an omitted reallocation penalty bound and validates its runtime type and range.
|
|
3
|
+
* @param value - Optional WAD-scaled penalty bound.
|
|
4
|
+
* @returns A bigint in [0, WAD], defaulting only undefined to zero.
|
|
5
|
+
* @throws {InvalidBigIntInputError} when a supplied bound is not a bigint.
|
|
6
|
+
* @throws {NegativeInputError} when the bound is negative.
|
|
7
|
+
* @throws {InputExceedsMaxError} when the bound exceeds WAD.
|
|
8
|
+
* @internal
|
|
9
|
+
*/
|
|
10
|
+
export declare const resolveMaxPenalty: (value: unknown) => bigint;
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { InputExceedsMaxError, InvalidBigIntInputError, NegativeInputError, } from "../types/error.js";
|
|
2
|
+
import { DEFAULT_MAX_REALLOCATION_PENALTY, MAX_REALLOCATION_PENALTY, } from "./constant.js";
|
|
3
|
+
/**
|
|
4
|
+
* Resolves an omitted reallocation penalty bound and validates its runtime type and range.
|
|
5
|
+
* @param value - Optional WAD-scaled penalty bound.
|
|
6
|
+
* @returns A bigint in [0, WAD], defaulting only undefined to zero.
|
|
7
|
+
* @throws {InvalidBigIntInputError} when a supplied bound is not a bigint.
|
|
8
|
+
* @throws {NegativeInputError} when the bound is negative.
|
|
9
|
+
* @throws {InputExceedsMaxError} when the bound exceeds WAD.
|
|
10
|
+
* @internal
|
|
11
|
+
*/
|
|
12
|
+
export const resolveMaxPenalty = (value) => {
|
|
13
|
+
const penalty = value === undefined ? DEFAULT_MAX_REALLOCATION_PENALTY : value;
|
|
14
|
+
if (typeof penalty !== "bigint") {
|
|
15
|
+
throw new InvalidBigIntInputError("maxPenalty", penalty);
|
|
16
|
+
}
|
|
17
|
+
if (penalty < 0n) {
|
|
18
|
+
throw new NegativeInputError("maxPenalty", penalty);
|
|
19
|
+
}
|
|
20
|
+
if (penalty > MAX_REALLOCATION_PENALTY) {
|
|
21
|
+
throw new InputExceedsMaxError({
|
|
22
|
+
field: "maxPenalty",
|
|
23
|
+
value: penalty,
|
|
24
|
+
max: MAX_REALLOCATION_PENALTY,
|
|
25
|
+
});
|
|
26
|
+
}
|
|
27
|
+
return penalty;
|
|
28
|
+
};
|
|
@@ -3,10 +3,11 @@
|
|
|
3
3
|
*
|
|
4
4
|
* @param params - Net target and WAD-scaled referral fee.
|
|
5
5
|
* @param params.netAssets - Required proceeds after the fee, in the asset's smallest unit.
|
|
6
|
-
* @param params.referralFeePct - Referral fee fraction scaled by WAD (`1e18`);
|
|
6
|
+
* @param params.referralFeePct - Referral fee fraction scaled by WAD (`1e18`); at most 10%.
|
|
7
7
|
* @returns The gross asset amount to pass to a bundles entrypoint.
|
|
8
8
|
* @throws {NegativeInputError} when `netAssets` or `referralFeePct` is negative.
|
|
9
9
|
* @throws {ReferralFeePctExceededError} when `referralFeePct >= WAD`.
|
|
10
|
+
* @throws {MidnightReferralFeePctExceededError} when the fee is above 10% but below WAD.
|
|
10
11
|
* @example
|
|
11
12
|
* ```ts
|
|
12
13
|
* import { grossFromNetAssets } from "@morpho-org/morpho-sdk";
|
|
@@ -1,14 +1,16 @@
|
|
|
1
1
|
import { MathLib } from "@morpho-org/blue-sdk";
|
|
2
2
|
import { NegativeInputError, ReferralFeePctExceededError, } from "../types/index.js";
|
|
3
|
+
import { validateMidnightReferralFeeCap } from "./validateMidnightBounds.js";
|
|
3
4
|
/**
|
|
4
5
|
* Computes the gross amount whose post-referral-fee proceeds equal `netAssets` exactly.
|
|
5
6
|
*
|
|
6
7
|
* @param params - Net target and WAD-scaled referral fee.
|
|
7
8
|
* @param params.netAssets - Required proceeds after the fee, in the asset's smallest unit.
|
|
8
|
-
* @param params.referralFeePct - Referral fee fraction scaled by WAD (`1e18`);
|
|
9
|
+
* @param params.referralFeePct - Referral fee fraction scaled by WAD (`1e18`); at most 10%.
|
|
9
10
|
* @returns The gross asset amount to pass to a bundles entrypoint.
|
|
10
11
|
* @throws {NegativeInputError} when `netAssets` or `referralFeePct` is negative.
|
|
11
12
|
* @throws {ReferralFeePctExceededError} when `referralFeePct >= WAD`.
|
|
13
|
+
* @throws {MidnightReferralFeePctExceededError} when the fee is above 10% but below WAD.
|
|
12
14
|
* @example
|
|
13
15
|
* ```ts
|
|
14
16
|
* import { grossFromNetAssets } from "@morpho-org/morpho-sdk";
|
|
@@ -27,5 +29,7 @@ export const grossFromNetAssets = (params) => {
|
|
|
27
29
|
if (params.referralFeePct >= MathLib.WAD) {
|
|
28
30
|
throw new ReferralFeePctExceededError(params.referralFeePct);
|
|
29
31
|
}
|
|
32
|
+
// Reject fees that the SDK's bundle builders would reject.
|
|
33
|
+
validateMidnightReferralFeeCap(params.referralFeePct);
|
|
30
34
|
return MathLib.mulDivDown(params.netAssets, MathLib.WAD, MathLib.WAD - params.referralFeePct);
|
|
31
35
|
};
|