@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
|
@@ -76,6 +76,8 @@ class MorphoVaultV1 {
|
|
|
76
76
|
throw new index_js_2.VaultAddressMismatchError(this.vault, vaultData.address);
|
|
77
77
|
}
|
|
78
78
|
const createdAt = suppliedNow ?? morpho_ts_1.Time.timestamp();
|
|
79
|
+
// Reject a non-bigint clock before deriving the default deadline.
|
|
80
|
+
(0, validate_js_1.validateReferenceTime)(createdAt);
|
|
79
81
|
const deadline = params.deadline ?? createdAt + morpho_ts_1.Time.s.from.h(2n);
|
|
80
82
|
if (deadline <= createdAt) {
|
|
81
83
|
throw new index_js_2.ExpiredDeadlineError(deadline, createdAt);
|
|
@@ -92,6 +94,8 @@ class MorphoVaultV1 {
|
|
|
92
94
|
(0, validate_js_1.validateNativeVaultAsset)(this.chainId, vaultAsset);
|
|
93
95
|
}
|
|
94
96
|
const referralFeeAssets = (0, common_js_1.getBundlesReferralFeeAssets)(funding.assets, common.referralFeePct);
|
|
97
|
+
// Bound forward accrual before deriving the deposit price protection.
|
|
98
|
+
(0, validate_js_1.validateVaultDepositDeadline)(deadline, { now: createdAt });
|
|
95
99
|
const maxSharePrice = (0, index_js_1.computeVaultMaxSharePrice)({
|
|
96
100
|
vaultData,
|
|
97
101
|
deadline,
|
|
@@ -420,6 +424,8 @@ class MorphoVaultV1 {
|
|
|
420
424
|
const slippageTolerance = params.slippageTolerance ?? blue_sdk_1.DEFAULT_SLIPPAGE_TOLERANCE;
|
|
421
425
|
(0, index_js_1.validateSlippageTolerance)(slippageTolerance);
|
|
422
426
|
const createdAt = suppliedNow ?? morpho_ts_1.Time.timestamp();
|
|
427
|
+
// Reject a non-bigint clock before deriving the default deadline.
|
|
428
|
+
(0, validate_js_1.validateReferenceTime)(createdAt);
|
|
423
429
|
const deadline = params.deadline ?? createdAt + morpho_ts_1.Time.s.from.h(2n);
|
|
424
430
|
if (deadline <= createdAt) {
|
|
425
431
|
throw new index_js_2.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.
|
|
@@ -77,6 +77,8 @@ class MorphoVaultV2 {
|
|
|
77
77
|
throw new index_js_2.VaultAddressMismatchError(this.vault, vaultData.address);
|
|
78
78
|
}
|
|
79
79
|
const createdAt = suppliedNow ?? morpho_ts_1.Time.timestamp();
|
|
80
|
+
// Reject a non-bigint clock before deriving the default deadline.
|
|
81
|
+
(0, validate_js_1.validateReferenceTime)(createdAt);
|
|
80
82
|
const deadline = params.deadline ?? createdAt + morpho_ts_1.Time.s.from.h(2n);
|
|
81
83
|
if (deadline <= createdAt) {
|
|
82
84
|
throw new index_js_2.ExpiredDeadlineError(deadline, createdAt);
|
|
@@ -93,6 +95,8 @@ class MorphoVaultV2 {
|
|
|
93
95
|
(0, validate_js_1.validateNativeVaultAsset)(this.chainId, vaultAsset);
|
|
94
96
|
}
|
|
95
97
|
const referralFeeAssets = (0, common_js_1.getBundlesReferralFeeAssets)(funding.assets, common.referralFeePct);
|
|
98
|
+
// Bound forward accrual before deriving the deposit price protection.
|
|
99
|
+
(0, validate_js_1.validateVaultDepositDeadline)(deadline, { now: createdAt });
|
|
96
100
|
const maxSharePrice = (0, index_js_1.computeVaultMaxSharePrice)({
|
|
97
101
|
vaultData,
|
|
98
102
|
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.
|
|
@@ -6,7 +6,9 @@ const morpho_ts_1 = require("@morpho-org/morpho-ts");
|
|
|
6
6
|
const viem_1 = require("viem");
|
|
7
7
|
const common_js_1 = require("../actions/blue/common.js");
|
|
8
8
|
const constant_js_1 = require("../helpers/constant.js");
|
|
9
|
+
const reallocationPenalty_js_1 = require("../helpers/reallocationPenalty.js");
|
|
9
10
|
const utilization_js_1 = require("../helpers/utilization.js");
|
|
11
|
+
const validateMidnightBounds_js_1 = require("../helpers/validateMidnightBounds.js");
|
|
10
12
|
const index_js_1 = require("../types/index.js");
|
|
11
13
|
const MAX_SHARED_CAP_SEARCH_STEPS = 1024n;
|
|
12
14
|
const createCapReserveState = (markets) => ({
|
|
@@ -66,20 +68,6 @@ const getAdapterIds = (cache, adapter, market) => {
|
|
|
66
68
|
cache.set(key, ids);
|
|
67
69
|
return ids;
|
|
68
70
|
};
|
|
69
|
-
const resolveMaxPenalty = (value) => {
|
|
70
|
-
const penalty = value ?? constant_js_1.DEFAULT_MAX_REALLOCATION_PENALTY;
|
|
71
|
-
if (penalty < 0n) {
|
|
72
|
-
throw new index_js_1.NegativeInputError("maxPenalty", penalty);
|
|
73
|
-
}
|
|
74
|
-
if (penalty > constant_js_1.MAX_REALLOCATION_PENALTY) {
|
|
75
|
-
throw new index_js_1.InputExceedsMaxError({
|
|
76
|
-
field: "maxPenalty",
|
|
77
|
-
value: penalty,
|
|
78
|
-
max: constant_js_1.MAX_REALLOCATION_PENALTY,
|
|
79
|
-
});
|
|
80
|
-
}
|
|
81
|
-
return penalty;
|
|
82
|
-
};
|
|
83
71
|
const getCanonicalMarket = (markets, market) => (markets[market.id] ??= new blue_sdk_1.Market({ ...market }));
|
|
84
72
|
const clonePosition = (position, markets) => new blue_sdk_1.AccrualPosition(position, getCanonicalMarket(markets, position.market));
|
|
85
73
|
const cloneAccrualVault = (vault, markets) => new blue_sdk_1.AccrualVault({
|
|
@@ -607,8 +595,13 @@ class VaultV2BlueReallocationData {
|
|
|
607
595
|
* destination-market handle (for example,
|
|
608
596
|
* `client.morpho.blue(destination.marketParams, chainId)`), not the source
|
|
609
597
|
* handle. Pass the source position's `borrowAssets` accrued to
|
|
610
|
-
*
|
|
611
|
-
* `
|
|
598
|
+
* the resolved plan expiry (or the required action deadline for entity
|
|
599
|
+
* `refinance`) as `operation.amount`. With
|
|
600
|
+
* `minTs = max(now, source.lastUpdate, destination.lastUpdate)`, the horizon is
|
|
601
|
+
* `max(minTs, resolved expiry)`. For `prepareBlueRefinance`, omitted `expiresAt`
|
|
602
|
+
* resolves to `now + 2h`, not `minTs + 2h`. Only when the resolved expiry exceeds
|
|
603
|
+
* `minTs + 365 days`, use `minTs + 2h` for unlimited-deadline sentinel
|
|
604
|
+
* compatibility. The optional `operation.referralFeePct` is WAD-scaled.
|
|
612
605
|
* The planner includes the referral fee and its allocator-leg penalties in
|
|
613
606
|
* destination debt, so penalized legs also cover their own penalty.
|
|
614
607
|
* Refinance never uses vaults with a 100% penalty.
|
|
@@ -672,8 +665,10 @@ class VaultV2BlueReallocationData {
|
|
|
672
665
|
* @returns Flat action-ready reallocations and their post-simulation state.
|
|
673
666
|
* @throws {UnsupportedBlueMarketIrmError} when a market with positive debt uses an unsupported IRM.
|
|
674
667
|
* @throws {NegativeInputError} when `capAccrualBuffer`, `allocatorCapHeadroom`, `maxWithdrawalUtilization`, `maxPenalty`, or `referralFeePct` is negative.
|
|
668
|
+
* @throws {InvalidBigIntInputError} when a supplied maxPenalty is not a bigint.
|
|
675
669
|
* @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.
|
|
676
670
|
* @throws {ReferralFeePctExceededError} when `referralFeePct` is at least WAD.
|
|
671
|
+
* @throws {MidnightReferralFeePctExceededError} when the fee is above 10% but below WAD.
|
|
677
672
|
* @throws {NonPositiveInputError} when the operation amount is not positive and planning is enabled.
|
|
678
673
|
* @throws {UnknownReallocationMarketError} when a required market is absent.
|
|
679
674
|
* @throws {UnknownReallocationVaultError} when configured vault state is absent.
|
|
@@ -717,7 +712,7 @@ class VaultV2BlueReallocationData {
|
|
|
717
712
|
return { reallocations: [], data: this };
|
|
718
713
|
}
|
|
719
714
|
const maxWithdrawalUtilization = (0, utilization_js_1.resolveMaxWithdrawalUtilization)(options.maxWithdrawalUtilization);
|
|
720
|
-
const maxPenalty = resolveMaxPenalty(options.maxPenalty);
|
|
715
|
+
const maxPenalty = (0, reallocationPenalty_js_1.resolveMaxPenalty)(options.maxPenalty);
|
|
721
716
|
const capAccrualBuffer = (0, utilization_js_1.resolveCapAccrualBuffer)(options.capAccrualBuffer);
|
|
722
717
|
const allocatorCapHeadroom = (0, utilization_js_1.resolveAllocatorCapHeadroom)(options.allocatorCapHeadroom);
|
|
723
718
|
const resolvedOptions = { ...options, maxPenalty };
|
|
@@ -943,6 +938,7 @@ class VaultV2BlueReallocationData {
|
|
|
943
938
|
* @returns Reallocatable market and idle assets, or `0n` when none are available; rounding-only shared-cap fits may be conservatively omitted.
|
|
944
939
|
* @throws {UnsupportedBlueMarketIrmError} when a market with positive debt uses an unsupported IRM.
|
|
945
940
|
* @throws {NegativeInputError} when `capAccrualBuffer`, `maxWithdrawalUtilization`, or `maxPenalty` is negative.
|
|
941
|
+
* @throws {InvalidBigIntInputError} when a supplied maxPenalty is not a bigint.
|
|
946
942
|
* @throws {InputExceedsMaxError} when `maxWithdrawalUtilization` or `maxPenalty` exceeds WAD.
|
|
947
943
|
* @throws {UnknownReallocationMarketError} when a required market is absent.
|
|
948
944
|
* @throws {UnknownReallocationVaultError} when configured vault state is absent.
|
|
@@ -978,7 +974,7 @@ class VaultV2BlueReallocationData {
|
|
|
978
974
|
return 0n;
|
|
979
975
|
}
|
|
980
976
|
const capAccrualBuffer = (0, utilization_js_1.resolveCapAccrualBuffer)(options?.capAccrualBuffer);
|
|
981
|
-
const maxPenalty = resolveMaxPenalty(options?.maxPenalty);
|
|
977
|
+
const maxPenalty = (0, reallocationPenalty_js_1.resolveMaxPenalty)(options?.maxPenalty);
|
|
982
978
|
return this.clone()
|
|
983
979
|
.computeVaultV2BlueReallocationsAtUtilizationInPlace({
|
|
984
980
|
context: createSimulationContext(),
|
|
@@ -1006,6 +1002,7 @@ class VaultV2BlueReallocationData {
|
|
|
1006
1002
|
* @returns Borrowable assets while remaining at or below `utilization`; rounding-only shared-cap fits may be conservatively omitted.
|
|
1007
1003
|
* @throws {UnsupportedBlueMarketIrmError} when a market with positive debt uses an unsupported IRM.
|
|
1008
1004
|
* @throws {NegativeInputError} when `capAccrualBuffer`, `maxWithdrawalUtilization`, or `maxPenalty` is negative.
|
|
1005
|
+
* @throws {InvalidBigIntInputError} when a supplied maxPenalty is not a bigint.
|
|
1009
1006
|
* @throws {InputExceedsMaxError} when `maxWithdrawalUtilization` or `maxPenalty` exceeds WAD.
|
|
1010
1007
|
* @throws {UnknownReallocationMarketError} when a required market is absent.
|
|
1011
1008
|
* @throws {UnknownReallocationVaultError} when configured vault state is absent.
|
|
@@ -1058,7 +1055,7 @@ class VaultV2BlueReallocationData {
|
|
|
1058
1055
|
options: {
|
|
1059
1056
|
...options,
|
|
1060
1057
|
timestamp,
|
|
1061
|
-
maxPenalty: resolveMaxPenalty(options?.maxPenalty),
|
|
1058
|
+
maxPenalty: (0, reallocationPenalty_js_1.resolveMaxPenalty)(options?.maxPenalty),
|
|
1062
1059
|
},
|
|
1063
1060
|
})
|
|
1064
1061
|
.reallocations.reduce((total, { assets }) => total + assets, 0n);
|
|
@@ -1595,8 +1592,7 @@ function resolveVaultCandidateIdleState(params) {
|
|
|
1595
1592
|
}
|
|
1596
1593
|
const vault = data.getVault(vaultAddress);
|
|
1597
1594
|
if (!(0, viem_1.isAddressEqual)(publicAllocatorConfig.vault, vaultAddress) ||
|
|
1598
|
-
publicAllocatorConfig.penalty >
|
|
1599
|
-
(options.maxPenalty ?? constant_js_1.DEFAULT_MAX_REALLOCATION_PENALTY)) {
|
|
1595
|
+
publicAllocatorConfig.penalty > (0, reallocationPenalty_js_1.resolveMaxPenalty)(options.maxPenalty)) {
|
|
1600
1596
|
return;
|
|
1601
1597
|
}
|
|
1602
1598
|
if (penalty != null && publicAllocatorConfig.penalty !== penalty) {
|
|
@@ -2468,6 +2464,8 @@ function resolveOperationFeeAssets(operation) {
|
|
|
2468
2464
|
if (referralFeePct >= blue_sdk_1.MathLib.WAD) {
|
|
2469
2465
|
throw new index_js_1.ReferralFeePctExceededError(referralFeePct);
|
|
2470
2466
|
}
|
|
2467
|
+
// Reject fees that the refinance bundle builder would reject.
|
|
2468
|
+
(0, validateMidnightBounds_js_1.validateMidnightReferralFeeCap)(referralFeePct);
|
|
2471
2469
|
const feeAssets = operation.type === "refinance"
|
|
2472
2470
|
? (0, common_js_1.getBlueBundlesV1ReferralFeeAssets)(amount, referralFeePct)
|
|
2473
2471
|
: 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,9 +1,11 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.MAX_TOKEN_APPROVALS = exports.APPROVE_ONLY_ONCE_TOKENS = exports.DEFAULT_SUPPLY_TARGET_UTILIZATION = exports.DEFAULT_WITHDRAWAL_TARGET_UTILIZATION = exports.MAX_ABSOLUTE_SHARE_PRICE = exports.MIN_VAULT_V2_DEAD_ASSETS = exports.MIN_DEAD_SHARES = exports.DEFAULT_ALLOCATOR_CAP_HEADROOM = exports.DEFAULT_CAP_ACCRUAL_BUFFER = exports.DEFAULT_LLTV_BUFFER = exports.MAX_REALLOCATION_PENALTY = exports.DEFAULT_MAX_REALLOCATION_PENALTY = exports.MAX_SLIPPAGE_TOLERANCE = exports.MIDNIGHT_MAX_REFERRAL_FEE_PCT = exports.MIDNIGHT_TAKE_MAX_DEADLINE_SECONDS = void 0;
|
|
3
|
+
exports.MAX_TOKEN_APPROVALS = exports.APPROVE_ONLY_ONCE_TOKENS = exports.DEFAULT_SUPPLY_TARGET_UTILIZATION = exports.DEFAULT_WITHDRAWAL_TARGET_UTILIZATION = exports.MAX_ABSOLUTE_SHARE_PRICE = exports.MIN_VAULT_V2_DEAD_ASSETS = exports.MIN_DEAD_SHARES = exports.DEFAULT_ALLOCATOR_CAP_HEADROOM = exports.DEFAULT_CAP_ACCRUAL_BUFFER = exports.DEFAULT_LLTV_BUFFER = exports.MAX_REALLOCATION_PENALTY = exports.DEFAULT_MAX_REALLOCATION_PENALTY = exports.MAX_SLIPPAGE_TOLERANCE = exports.MIDNIGHT_MAX_REFERRAL_FEE_PCT = exports.MIDNIGHT_TAKE_MAX_DEADLINE_SECONDS = exports.VAULT_DEPOSIT_MAX_DEADLINE_SECONDS = void 0;
|
|
4
4
|
const blue_sdk_1 = require("@morpho-org/blue-sdk");
|
|
5
5
|
const morpho_ts_1 = require("@morpho-org/morpho-ts");
|
|
6
6
|
const viem_1 = require("viem");
|
|
7
|
+
/** Maximum forward accrual window for vault deposits and V1-to-V2 migration, in seconds. */
|
|
8
|
+
exports.VAULT_DEPOSIT_MAX_DEADLINE_SECONDS = 604800n;
|
|
7
9
|
/** Maximum time between now and a Midnight taker-flow deadline, in seconds. */
|
|
8
10
|
exports.MIDNIGHT_TAKE_MAX_DEADLINE_SECONDS = 3600n;
|
|
9
11
|
/**
|
|
@@ -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,18 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.getBlueBundlesV1QuoteTimestamp = getBlueBundlesV1QuoteTimestamp;
|
|
4
|
+
const blue_sdk_1 = require("@morpho-org/blue-sdk");
|
|
5
|
+
const morpho_ts_1 = require("@morpho-org/morpho-ts");
|
|
6
|
+
const MAX_BLUE_HEALTH_DEADLINE_HORIZON = morpho_ts_1.Time.s.from.d(365n);
|
|
7
|
+
/**
|
|
8
|
+
* @internal Projects health to realistic finite deadlines, never before now or the market snapshot.
|
|
9
|
+
* Deadlines more than 365 days out (maxUint256/maxUint48-style unlimited sentinels) use
|
|
10
|
+
* the legacy two-hour projection to avoid interest-accrual overflow.
|
|
11
|
+
*/
|
|
12
|
+
function getBlueBundlesV1QuoteTimestamp({ lastUpdate, now, deadline, }) {
|
|
13
|
+
const minTimestamp = blue_sdk_1.MathLib.max(now, lastUpdate);
|
|
14
|
+
return deadline === undefined ||
|
|
15
|
+
deadline > minTimestamp + MAX_BLUE_HEALTH_DEADLINE_HORIZON
|
|
16
|
+
? minTimestamp + morpho_ts_1.Time.s.from.h(2n)
|
|
17
|
+
: blue_sdk_1.MathLib.max(minTimestamp, deadline);
|
|
18
|
+
}
|
|
@@ -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/cjs/helpers/index.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.resolveVaultV2ForceWithdrawEligibility = exports.computeVaultV2ForceWithdrawSharesBurnt = exports.computeVaultV2ForceWithdrawPlan = exports.computeVaultV2ForceWithdrawMinSharesBurnt = exports.computeVaultV2ForceWithdrawFeeSharesMinted = exports.validateRequirementSpender = exports.validateOfferSides = exports.validateWithdrawShares = exports.validateWithdrawAmount = exports.validateUserAddress = exports.validateSlippageTolerance = exports.validateRepayShares = exports.validateRepayAmount = exports.validatePositionHealthAfterWithdraw = exports.validatePositionHealth = exports.validateNativeAsset = exports.validateMidnightNativeAmount = exports.validateMidnightMarketChainId = exports.validateChainId = exports.validateAccrualPosition = exports.getMidnightMaxSafeDebt = exports.computeVaultMaxSharePrice = exports.computeVaultMaxShareAllowance = exports.computeMinForceWithdrawSharePrice = exports.signAndVerifyTypedData = exports.grossFromNetAssets = exports.previewVaultV2InKindRedeem = exports.previewVaultV2ForceWithdraw = exports.addTransactionMetadata = exports.validateVaultV2DeadShares = exports.validateVaultV1DeadShares = exports.validateBlueMarketDeadShares = exports.MIN_VAULT_V2_DEAD_ASSETS = exports.MIN_DEAD_SHARES = exports.MIDNIGHT_TAKE_MAX_DEADLINE_SECONDS = exports.MAX_TOKEN_APPROVALS = exports.MAX_SLIPPAGE_TOLERANCE = exports.MAX_REALLOCATION_PENALTY = exports.MAX_ABSOLUTE_SHARE_PRICE = exports.DEFAULT_WITHDRAWAL_TARGET_UTILIZATION = exports.DEFAULT_SUPPLY_TARGET_UTILIZATION = exports.DEFAULT_MAX_REALLOCATION_PENALTY = exports.DEFAULT_LLTV_BUFFER = exports.DEFAULT_CAP_ACCRUAL_BUFFER = exports.DEFAULT_ALLOCATOR_CAP_HEADROOM = exports.APPROVE_ONLY_ONCE_TOKENS = exports.getMidnightBlueBuyCallbackData = exports.getMidnightBlueBuyCallbackAddress = void 0;
|
|
3
|
+
exports.resolveVaultV2ForceWithdrawEligibility = exports.computeVaultV2ForceWithdrawSharesBurnt = exports.computeVaultV2ForceWithdrawPlan = exports.computeVaultV2ForceWithdrawMinSharesBurnt = exports.computeVaultV2ForceWithdrawFeeSharesMinted = exports.validateRequirementSpender = exports.validateOfferSides = exports.validateWithdrawShares = exports.validateWithdrawAmount = exports.validateUserAddress = exports.validateSlippageTolerance = exports.validateRepayShares = exports.validateRepayAmount = exports.validatePositionHealthAfterWithdraw = exports.validatePositionHealth = exports.validateNativeAsset = exports.validateMidnightNativeAmount = exports.validateMidnightMarketChainId = exports.validateChainId = exports.validateAccrualPosition = exports.getMidnightMaxSafeDebt = exports.computeVaultMaxSharePrice = exports.computeVaultMaxShareAllowance = exports.computeMinForceWithdrawSharePrice = exports.signAndVerifyTypedData = exports.grossFromNetAssets = exports.previewVaultV2InKindRedeem = exports.previewVaultV2ForceWithdraw = exports.addTransactionMetadata = exports.validateVaultV2DeadShares = exports.validateVaultV1DeadShares = exports.validateBlueMarketDeadShares = exports.VAULT_DEPOSIT_MAX_DEADLINE_SECONDS = exports.MIN_VAULT_V2_DEAD_ASSETS = exports.MIN_DEAD_SHARES = exports.MIDNIGHT_TAKE_MAX_DEADLINE_SECONDS = exports.MAX_TOKEN_APPROVALS = exports.MAX_SLIPPAGE_TOLERANCE = exports.MAX_REALLOCATION_PENALTY = exports.MAX_ABSOLUTE_SHARE_PRICE = exports.DEFAULT_WITHDRAWAL_TARGET_UTILIZATION = exports.DEFAULT_SUPPLY_TARGET_UTILIZATION = exports.DEFAULT_MAX_REALLOCATION_PENALTY = exports.DEFAULT_LLTV_BUFFER = exports.DEFAULT_CAP_ACCRUAL_BUFFER = exports.DEFAULT_ALLOCATOR_CAP_HEADROOM = exports.APPROVE_ONLY_ONCE_TOKENS = exports.getMidnightBlueBuyCallbackData = exports.getMidnightBlueBuyCallbackAddress = void 0;
|
|
4
4
|
var callback_js_1 = require("./callback.js");
|
|
5
5
|
Object.defineProperty(exports, "getMidnightBlueBuyCallbackAddress", { enumerable: true, get: function () { return callback_js_1.getMidnightBlueBuyCallbackAddress; } });
|
|
6
6
|
Object.defineProperty(exports, "getMidnightBlueBuyCallbackData", { enumerable: true, get: function () { return callback_js_1.getMidnightBlueBuyCallbackData; } });
|
|
@@ -19,6 +19,7 @@ Object.defineProperty(exports, "MAX_TOKEN_APPROVALS", { enumerable: true, get: f
|
|
|
19
19
|
Object.defineProperty(exports, "MIDNIGHT_TAKE_MAX_DEADLINE_SECONDS", { enumerable: true, get: function () { return constant_js_1.MIDNIGHT_TAKE_MAX_DEADLINE_SECONDS; } });
|
|
20
20
|
Object.defineProperty(exports, "MIN_DEAD_SHARES", { enumerable: true, get: function () { return constant_js_1.MIN_DEAD_SHARES; } });
|
|
21
21
|
Object.defineProperty(exports, "MIN_VAULT_V2_DEAD_ASSETS", { enumerable: true, get: function () { return constant_js_1.MIN_VAULT_V2_DEAD_ASSETS; } });
|
|
22
|
+
Object.defineProperty(exports, "VAULT_DEPOSIT_MAX_DEADLINE_SECONDS", { enumerable: true, get: function () { return constant_js_1.VAULT_DEPOSIT_MAX_DEADLINE_SECONDS; } });
|
|
22
23
|
var deadShares_js_1 = require("./deadShares.js");
|
|
23
24
|
Object.defineProperty(exports, "validateBlueMarketDeadShares", { enumerable: true, get: function () { return deadShares_js_1.validateBlueMarketDeadShares; } });
|
|
24
25
|
Object.defineProperty(exports, "validateVaultV1DeadShares", { enumerable: true, get: function () { return deadShares_js_1.validateVaultV1DeadShares; } });
|
|
@@ -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
|
|
@@ -3,6 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.previewVaultV2ForceWithdraw = previewVaultV2ForceWithdraw;
|
|
4
4
|
const blue_sdk_1 = require("@morpho-org/blue-sdk");
|
|
5
5
|
const viem_1 = require("viem");
|
|
6
|
+
const constant_js_1 = require("./constant.js");
|
|
6
7
|
const vaultV2ForceWithdrawPlan_js_1 = require("./vaultV2ForceWithdrawPlan.js");
|
|
7
8
|
/**
|
|
8
9
|
* Previews what a Vault V2 force withdrawal delivers, without any RPC.
|
|
@@ -27,7 +28,7 @@ const vaultV2ForceWithdrawPlan_js_1 = require("./vaultV2ForceWithdrawPlan.js");
|
|
|
27
28
|
* `timestamp`. Pass the `forceWithdraw` deadline you will submit; the entity rejects deadlines
|
|
28
29
|
* more than one year after handle creation (`InputExceedsMaxError`) instead of clamping them, so
|
|
29
30
|
* keep the deadline itself within that horizon. Ignored without `userAddress`.
|
|
30
|
-
* @param params.referralFeePct - Optional WAD-scaled referral fee percentage. Defaults to `0n`.
|
|
31
|
+
* @param params.referralFeePct - Optional WAD-scaled referral fee percentage from 0% to 10%, inclusive. Defaults to `0n`.
|
|
31
32
|
* @param params.referralFeeRecipient - Optional referral fee recipient. Required when
|
|
32
33
|
* `referralFeePct` is positive, as the entity enforces (`ReferralFeeRecipientMissingError`).
|
|
33
34
|
* When it equals `userAddress`, the fee is paid back to the exiting account and `netAssets`
|
|
@@ -35,7 +36,7 @@ const vaultV2ForceWithdrawPlan_js_1 = require("./vaultV2ForceWithdrawPlan.js");
|
|
|
35
36
|
* @returns The preview, or `undefined` when the exit is not previewable: not exactly one adapter, an
|
|
36
37
|
* `adapter` override that is not the vault's sole adapter, an adapter that is not a
|
|
37
38
|
* MorphoMarketV1AdapterV2, an unresolvable liquidity adapter, undecodable liquidity data, a
|
|
38
|
-
* `referralFeePct` outside `[0, WAD
|
|
39
|
+
* `referralFeePct` outside `[0, WAD / 10n]`, a positive `referralFeePct` without a non-zero
|
|
39
40
|
* `referralFeeRecipient`, a non-positive request, a request that yields nothing, a fee-recipient
|
|
40
41
|
* whose positive fee mints projected to `feeProjectionTimestamp` reach the lower burn bound, an
|
|
41
42
|
* exit whose realized share price rounds down to zero at the default slippage tolerance (which
|
|
@@ -62,9 +63,7 @@ function previewVaultV2ForceWithdraw(vaultData, params) {
|
|
|
62
63
|
if (requestedExitAssets <= 0n) {
|
|
63
64
|
return undefined;
|
|
64
65
|
}
|
|
65
|
-
|
|
66
|
-
// deliver — above `withdrawnAssets` for a negative fee, non-positive at or beyond WAD.
|
|
67
|
-
if (referralFeePct < 0n || referralFeePct >= blue_sdk_1.MathLib.WAD) {
|
|
66
|
+
if (referralFeePct < 0n || referralFeePct > constant_js_1.MIDNIGHT_MAX_REFERRAL_FEE_PCT) {
|
|
68
67
|
return undefined;
|
|
69
68
|
}
|
|
70
69
|
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;
|
|
@@ -17,8 +17,11 @@ function quoteBlueRepayFunding(params) {
|
|
|
17
17
|
}
|
|
18
18
|
return params.repayAssets;
|
|
19
19
|
}
|
|
20
|
-
/**
|
|
21
|
-
|
|
20
|
+
/**
|
|
21
|
+
* @internal Quotes repayment funding at the deadline independently of an optional withdrawal-health timestamp.
|
|
22
|
+
* Debt-free positions retain their snapshot without projecting market-wide interest.
|
|
23
|
+
*/
|
|
24
|
+
function quoteBlueRepay({ positionData, marketId, repayAssets, repayShares, deadline, now, healthTimestamp, }) {
|
|
22
25
|
const saturatedRepay = repayShares === viem_1.maxUint256;
|
|
23
26
|
const simulatedRepayShares = saturatedRepay
|
|
24
27
|
? positionData.borrowShares
|
|
@@ -37,10 +40,20 @@ function quoteBlueRepay({ positionData, marketId, repayAssets, repayShares, dead
|
|
|
37
40
|
max: quoteHorizon,
|
|
38
41
|
});
|
|
39
42
|
}
|
|
40
|
-
const accrualTimestamp = repayShares > 0n ? deadline : quoteHorizon;
|
|
41
|
-
const accruedPosition = positionData.
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
43
|
+
const accrualTimestamp = healthTimestamp ?? (repayShares > 0n ? deadline : quoteHorizon);
|
|
44
|
+
const accruedPosition = positionData.borrowShares === 0n
|
|
45
|
+
? new blue_sdk_1.AccrualPosition(positionData, positionData.market)
|
|
46
|
+
: positionData.accrueInterest(accrualTimestamp);
|
|
47
|
+
if (repayAssets > 0n || simulatedRepayShares <= 0n) {
|
|
48
|
+
return {
|
|
49
|
+
simulatedRepayShares,
|
|
50
|
+
accruedPosition,
|
|
51
|
+
expectedRepayAssets: repayAssets,
|
|
52
|
+
};
|
|
53
|
+
}
|
|
54
|
+
const fundingPosition = accrualTimestamp === deadline
|
|
55
|
+
? accruedPosition
|
|
56
|
+
: positionData.accrueInterest(deadline);
|
|
57
|
+
const expectedRepayAssets = fundingPosition.market.toBorrowAssets(simulatedRepayShares, "Up");
|
|
45
58
|
return { simulatedRepayShares, accruedPosition, expectedRepayAssets };
|
|
46
59
|
}
|
|
@@ -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,32 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.resolveMaxPenalty = void 0;
|
|
4
|
+
const error_js_1 = require("../types/error.js");
|
|
5
|
+
const constant_js_1 = require("./constant.js");
|
|
6
|
+
/**
|
|
7
|
+
* Resolves an omitted reallocation penalty bound and validates its runtime type and range.
|
|
8
|
+
* @param value - Optional WAD-scaled penalty bound.
|
|
9
|
+
* @returns A bigint in [0, WAD], defaulting only undefined to zero.
|
|
10
|
+
* @throws {InvalidBigIntInputError} when a supplied bound is not a bigint.
|
|
11
|
+
* @throws {NegativeInputError} when the bound is negative.
|
|
12
|
+
* @throws {InputExceedsMaxError} when the bound exceeds WAD.
|
|
13
|
+
* @internal
|
|
14
|
+
*/
|
|
15
|
+
const resolveMaxPenalty = (value) => {
|
|
16
|
+
const penalty = value === undefined ? constant_js_1.DEFAULT_MAX_REALLOCATION_PENALTY : value;
|
|
17
|
+
if (typeof penalty !== "bigint") {
|
|
18
|
+
throw new error_js_1.InvalidBigIntInputError("maxPenalty", penalty);
|
|
19
|
+
}
|
|
20
|
+
if (penalty < 0n) {
|
|
21
|
+
throw new error_js_1.NegativeInputError("maxPenalty", penalty);
|
|
22
|
+
}
|
|
23
|
+
if (penalty > constant_js_1.MAX_REALLOCATION_PENALTY) {
|
|
24
|
+
throw new error_js_1.InputExceedsMaxError({
|
|
25
|
+
field: "maxPenalty",
|
|
26
|
+
value: penalty,
|
|
27
|
+
max: constant_js_1.MAX_REALLOCATION_PENALTY,
|
|
28
|
+
});
|
|
29
|
+
}
|
|
30
|
+
return penalty;
|
|
31
|
+
};
|
|
32
|
+
exports.resolveMaxPenalty = resolveMaxPenalty;
|
|
@@ -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";
|
|
@@ -3,15 +3,17 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.grossFromNetAssets = void 0;
|
|
4
4
|
const blue_sdk_1 = require("@morpho-org/blue-sdk");
|
|
5
5
|
const index_js_1 = require("../types/index.js");
|
|
6
|
+
const validateMidnightBounds_js_1 = require("./validateMidnightBounds.js");
|
|
6
7
|
/**
|
|
7
8
|
* Computes the gross amount whose post-referral-fee proceeds equal `netAssets` exactly.
|
|
8
9
|
*
|
|
9
10
|
* @param params - Net target and WAD-scaled referral fee.
|
|
10
11
|
* @param params.netAssets - Required proceeds after the fee, in the asset's smallest unit.
|
|
11
|
-
* @param params.referralFeePct - Referral fee fraction scaled by WAD (`1e18`);
|
|
12
|
+
* @param params.referralFeePct - Referral fee fraction scaled by WAD (`1e18`); at most 10%.
|
|
12
13
|
* @returns The gross asset amount to pass to a bundles entrypoint.
|
|
13
14
|
* @throws {NegativeInputError} when `netAssets` or `referralFeePct` is negative.
|
|
14
15
|
* @throws {ReferralFeePctExceededError} when `referralFeePct >= WAD`.
|
|
16
|
+
* @throws {MidnightReferralFeePctExceededError} when the fee is above 10% but below WAD.
|
|
15
17
|
* @example
|
|
16
18
|
* ```ts
|
|
17
19
|
* import { grossFromNetAssets } from "@morpho-org/morpho-sdk";
|
|
@@ -30,6 +32,8 @@ const grossFromNetAssets = (params) => {
|
|
|
30
32
|
if (params.referralFeePct >= blue_sdk_1.MathLib.WAD) {
|
|
31
33
|
throw new index_js_1.ReferralFeePctExceededError(params.referralFeePct);
|
|
32
34
|
}
|
|
35
|
+
// Reject fees that the SDK's bundle builders would reject.
|
|
36
|
+
(0, validateMidnightBounds_js_1.validateMidnightReferralFeeCap)(params.referralFeePct);
|
|
33
37
|
return blue_sdk_1.MathLib.mulDivDown(params.netAssets, blue_sdk_1.MathLib.WAD, blue_sdk_1.MathLib.WAD - params.referralFeePct);
|
|
34
38
|
};
|
|
35
39
|
exports.grossFromNetAssets = grossFromNetAssets;
|