@morpho-org/morpho-sdk 9.8.0 → 10.0.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/MIGRATION-v9-to-v10.md +114 -0
- package/README.md +109 -13
- package/lib/cjs/actions/blue/common.js +4 -2
- package/lib/cjs/actions/blue/withdrawBuyCallback.js +2 -1
- package/lib/cjs/actions/bundles/common.js +20 -14
- package/lib/cjs/actions/bundles/resolveBundlesTokenRequirements.d.ts +3 -4
- package/lib/cjs/actions/bundles/resolveBundlesTokenRequirements.js +3 -2
- package/lib/cjs/actions/midnight/cancelAndMake.d.ts +2 -1
- package/lib/cjs/actions/midnight/cancelAndMake.js +2 -1
- package/lib/cjs/actions/midnight/cancelOffers.d.ts +54 -0
- package/lib/cjs/actions/midnight/cancelOffers.js +108 -0
- package/lib/cjs/actions/midnight/index.d.ts +1 -0
- package/lib/cjs/actions/midnight/index.js +1 -0
- package/lib/cjs/actions/midnight/supplyCollateralBatch.js +4 -2
- package/lib/cjs/actions/midnight/supplyCollateralTakeBorrow.d.ts +1 -1
- package/lib/cjs/actions/midnight/supplyCollateralTakeBorrow.js +3 -2
- package/lib/cjs/actions/midnight/takeBorrow.d.ts +1 -1
- package/lib/cjs/actions/midnight/takeBorrow.js +3 -2
- package/lib/cjs/actions/midnight/takeLend.d.ts +1 -1
- package/lib/cjs/actions/midnight/takeLend.js +3 -2
- package/lib/cjs/actions/midnight/takeRepayWithdrawCollateral.d.ts +1 -1
- package/lib/cjs/actions/midnight/takeRepayWithdrawCollateral.js +3 -2
- package/lib/cjs/actions/midnight/takeWithdraw.d.ts +1 -1
- package/lib/cjs/actions/midnight/takeWithdraw.js +3 -2
- package/lib/cjs/actions/midnight/withdrawCollateralBatch.js +4 -2
- package/lib/cjs/actions/requirements/blue/getBlueAuthorizationRequirement.d.ts +3 -4
- package/lib/cjs/actions/requirements/blue/getBlueAuthorizationRequirement.js +1 -1
- package/lib/cjs/actions/requirements/encode/encodeBlueSignatureAuthorization.d.ts +4 -6
- package/lib/cjs/actions/requirements/encode/encodeBlueSignatureAuthorization.js +3 -3
- package/lib/cjs/actions/requirements/encode/encodeErc20Permit.d.ts +4 -6
- package/lib/cjs/actions/requirements/encode/encodeErc20Permit.js +3 -3
- package/lib/cjs/actions/requirements/encode/encodeErc20Permit2SignatureTransfer.d.ts +5 -6
- package/lib/cjs/actions/requirements/encode/encodeErc20Permit2SignatureTransfer.js +5 -13
- package/lib/cjs/actions/requirements/encode/encodeVaultSharesPermit.d.ts +3 -5
- package/lib/cjs/actions/requirements/encode/encodeVaultSharesPermit.js +26 -23
- package/lib/cjs/actions/requirements/midnight/getMidnightApprovalRequirements.js +2 -1
- package/lib/cjs/actions/requirements/midnight/getMidnightAuthorizationRequirement.js +2 -1
- package/lib/cjs/actions/vaultV1/inKindRedeem.js +6 -3
- package/lib/cjs/actions/vaultV1/migrateToV2.js +1 -1
- package/lib/cjs/actions/vaultV2/forceWithdraw.js +4 -2
- package/lib/cjs/actions/vaultV2/inKindRedeem.js +4 -2
- package/lib/cjs/entities/blue/blue.d.ts +34 -28
- package/lib/cjs/entities/blue/blue.js +107 -77
- package/lib/cjs/entities/midnight/deadline.d.ts +2 -2
- package/lib/cjs/entities/midnight/deadline.js +4 -3
- package/lib/cjs/entities/midnight/midnight.d.ts +49 -51
- package/lib/cjs/entities/midnight/midnight.js +158 -138
- package/lib/cjs/entities/midnight/publication.d.ts +2 -0
- package/lib/cjs/entities/midnight/publication.js +193 -138
- package/lib/cjs/entities/midnight/types.d.ts +4 -4
- package/lib/cjs/entities/requirements/assertContractCode.js +4 -2
- package/lib/cjs/entities/requirements/getBundlesTokenRequirements.d.ts +3 -5
- package/lib/cjs/entities/requirements/getBundlesTokenRequirements.js +24 -28
- package/lib/cjs/entities/requirements/getErc2612Permit.js +10 -5
- package/lib/cjs/entities/requirements/getVaultBundlesSharesRequirements.d.ts +5 -4
- package/lib/cjs/entities/requirements/getVaultBundlesSharesRequirements.js +8 -2
- package/lib/cjs/entities/requirements/getVaultV1InKindRedeemRequirements.d.ts +21 -0
- package/lib/cjs/entities/requirements/getVaultV1InKindRedeemRequirements.js +111 -0
- package/lib/cjs/entities/requirements/getVaultV2ForceWithdrawRequirements.d.ts +20 -0
- package/lib/cjs/entities/requirements/getVaultV2ForceWithdrawRequirements.js +76 -0
- package/lib/cjs/entities/requirements/getVaultV2InKindRedeemRequirements.d.ts +21 -0
- package/lib/cjs/entities/requirements/getVaultV2InKindRedeemRequirements.js +93 -0
- package/lib/cjs/entities/vaultV1/inKindRedeemQuote.d.ts +25 -0
- package/lib/cjs/entities/vaultV1/inKindRedeemQuote.js +85 -0
- package/lib/cjs/entities/vaultV1/migrateToV2Quote.d.ts +20 -0
- package/lib/cjs/entities/vaultV1/migrateToV2Quote.js +37 -0
- package/lib/cjs/entities/vaultV1/vaultV1.d.ts +12 -12
- package/lib/cjs/entities/vaultV1/vaultV1.js +90 -194
- package/lib/cjs/entities/vaultV2/forceWithdrawQuote.d.ts +25 -0
- package/lib/cjs/entities/vaultV2/forceWithdrawQuote.js +189 -0
- package/lib/cjs/entities/vaultV2/inKindRedeemQuote.d.ts +28 -0
- package/lib/cjs/entities/vaultV2/inKindRedeemQuote.js +110 -0
- package/lib/cjs/entities/vaultV2/vaultV2.d.ts +16 -16
- package/lib/cjs/entities/vaultV2/vaultV2.js +94 -385
- package/lib/cjs/entities/vaultV2BlueReallocationData.d.ts +14 -0
- package/lib/cjs/entities/vaultV2BlueReallocationData.js +1599 -883
- package/lib/cjs/errors.d.ts +1 -1
- package/lib/cjs/errors.js +2 -1
- package/lib/cjs/helpers/deadShares.js +83 -47
- package/lib/cjs/helpers/encodeMidnightCalldata.js +4 -2
- package/lib/cjs/helpers/metadata.d.ts +14 -2
- package/lib/cjs/helpers/metadata.js +49 -8
- package/lib/cjs/helpers/previewVaultV2ForceWithdraw.js +44 -27
- package/lib/cjs/helpers/previewVaultV2InKindRedeem.js +11 -2
- package/lib/cjs/helpers/utilization.js +10 -5
- package/lib/cjs/helpers/validate.js +88 -67
- package/lib/cjs/helpers/validateMidnightBounds.js +2 -1
- package/lib/cjs/helpers/validateMidnightCollateralBatch.js +2 -1
- package/lib/cjs/helpers/validateMidnightPublication.js +4 -2
- package/lib/cjs/helpers/validateMidnightTakeFeasibility.js +177 -104
- package/lib/cjs/helpers/validatePositiveInput.js +2 -1
- package/lib/cjs/helpers/validateTakeableOffers.js +2 -1
- package/lib/cjs/helpers/vaultV2ForceWithdrawPlan.js +40 -22
- package/lib/cjs/index.d.ts +2 -2
- package/lib/cjs/index.js +10 -1
- package/lib/cjs/transactionPlan/approval.js +12 -1
- package/lib/cjs/transactionPlan/deposit.d.ts +22 -0
- package/lib/cjs/transactionPlan/deposit.js +139 -0
- package/lib/cjs/transactionPlan/error.d.ts +10 -8
- package/lib/cjs/transactionPlan/error.js +10 -8
- package/lib/cjs/transactionPlan/getTokenPermit.js +2 -1
- package/lib/cjs/transactionPlan/index.d.ts +18 -0
- package/lib/cjs/transactionPlan/index.js +23 -5
- package/lib/cjs/transactionPlan/intent.d.ts +3 -3
- package/lib/cjs/transactionPlan/intent.js +14 -7
- package/lib/cjs/transactionPlan/permit.d.ts +1 -1
- package/lib/cjs/transactionPlan/permit.js +86 -20
- package/lib/cjs/transactionPlan/plan.d.ts +16 -6
- package/lib/cjs/transactionPlan/plan.js +77 -24
- package/lib/cjs/transactionPlan/redeem.d.ts +18 -0
- package/lib/cjs/transactionPlan/redeem.js +63 -0
- package/lib/cjs/transactionPlan/requirements.d.ts +4 -3
- package/lib/cjs/transactionPlan/requirements.js +12 -6
- package/lib/cjs/transactionPlan/serde.d.ts +2 -2
- package/lib/cjs/transactionPlan/serde.js +45 -19
- package/lib/cjs/transactionPlan/shareSpending.d.ts +18 -0
- package/lib/cjs/transactionPlan/shareSpending.js +50 -0
- package/lib/cjs/transactionPlan/types.d.ts +117 -11
- package/lib/cjs/transactionPlan/validateActions.js +11 -1
- package/lib/cjs/transactionPlan/validation.js +6 -3
- package/lib/cjs/transactionPlan/vaultv1/deposit.d.ts +93 -0
- package/lib/cjs/transactionPlan/vaultv1/deposit.js +94 -0
- package/lib/cjs/transactionPlan/vaultv1/inKindRedeem.d.ts +96 -0
- package/lib/cjs/transactionPlan/vaultv1/inKindRedeem.js +203 -0
- package/lib/cjs/transactionPlan/vaultv1/migrateToV2.d.ts +94 -0
- package/lib/cjs/transactionPlan/vaultv1/migrateToV2.js +217 -0
- package/lib/cjs/transactionPlan/vaultv1/redeem.d.ts +69 -0
- package/lib/cjs/transactionPlan/vaultv1/redeem.js +78 -0
- package/lib/cjs/transactionPlan/vaultv1/withdraw.d.ts +77 -0
- package/lib/cjs/transactionPlan/vaultv1/withdraw.js +88 -0
- package/lib/cjs/transactionPlan/vaultv2/deposit.d.ts +18 -33
- package/lib/cjs/transactionPlan/vaultv2/deposit.js +19 -143
- package/lib/cjs/transactionPlan/vaultv2/forceRedeem.d.ts +74 -0
- package/lib/cjs/transactionPlan/vaultv2/forceRedeem.js +155 -0
- package/lib/cjs/transactionPlan/vaultv2/forceWithdraw.d.ts +98 -0
- package/lib/cjs/transactionPlan/vaultv2/forceWithdraw.js +206 -0
- package/lib/cjs/transactionPlan/vaultv2/inKindRedeem.d.ts +113 -0
- package/lib/cjs/transactionPlan/vaultv2/inKindRedeem.js +206 -0
- package/lib/cjs/transactionPlan/vaultv2/redeem.d.ts +84 -0
- package/lib/cjs/transactionPlan/vaultv2/redeem.js +86 -0
- package/lib/cjs/transactionPlan/vaultv2/withdraw.d.ts +18 -29
- package/lib/cjs/transactionPlan/vaultv2/withdraw.js +21 -126
- package/lib/cjs/transactionPlan/version.js +2 -1
- package/lib/cjs/transactionPlan/withdraw.d.ts +18 -0
- package/lib/cjs/transactionPlan/withdraw.js +94 -0
- package/lib/cjs/types/action.d.ts +26 -2
- package/lib/cjs/types/action.js +17 -9
- package/lib/cjs/types/error.d.ts +8 -1
- package/lib/cjs/types/error.js +21 -6
- package/lib/cjs/types/metadata.d.ts +12 -2
- package/lib/cjs/version.d.ts +1 -1
- package/lib/cjs/version.js +1 -1
- package/lib/esm/actions/blue/common.js +4 -2
- package/lib/esm/actions/blue/withdrawBuyCallback.js +2 -1
- package/lib/esm/actions/bundles/common.js +20 -14
- package/lib/esm/actions/bundles/resolveBundlesTokenRequirements.d.ts +3 -4
- package/lib/esm/actions/bundles/resolveBundlesTokenRequirements.js +3 -2
- package/lib/esm/actions/midnight/cancelAndMake.d.ts +2 -1
- package/lib/esm/actions/midnight/cancelAndMake.js +2 -1
- package/lib/esm/actions/midnight/cancelOffers.d.ts +54 -0
- package/lib/esm/actions/midnight/cancelOffers.js +104 -0
- package/lib/esm/actions/midnight/index.d.ts +1 -0
- package/lib/esm/actions/midnight/index.js +1 -0
- package/lib/esm/actions/midnight/supplyCollateralBatch.js +4 -2
- package/lib/esm/actions/midnight/supplyCollateralTakeBorrow.d.ts +1 -1
- package/lib/esm/actions/midnight/supplyCollateralTakeBorrow.js +3 -2
- package/lib/esm/actions/midnight/takeBorrow.d.ts +1 -1
- package/lib/esm/actions/midnight/takeBorrow.js +3 -2
- package/lib/esm/actions/midnight/takeLend.d.ts +1 -1
- package/lib/esm/actions/midnight/takeLend.js +3 -2
- package/lib/esm/actions/midnight/takeRepayWithdrawCollateral.d.ts +1 -1
- package/lib/esm/actions/midnight/takeRepayWithdrawCollateral.js +3 -2
- package/lib/esm/actions/midnight/takeWithdraw.d.ts +1 -1
- package/lib/esm/actions/midnight/takeWithdraw.js +3 -2
- package/lib/esm/actions/midnight/withdrawCollateralBatch.js +4 -2
- package/lib/esm/actions/requirements/blue/getBlueAuthorizationRequirement.d.ts +3 -4
- package/lib/esm/actions/requirements/blue/getBlueAuthorizationRequirement.js +1 -1
- package/lib/esm/actions/requirements/encode/encodeBlueSignatureAuthorization.d.ts +4 -6
- package/lib/esm/actions/requirements/encode/encodeBlueSignatureAuthorization.js +3 -3
- package/lib/esm/actions/requirements/encode/encodeErc20Permit.d.ts +4 -6
- package/lib/esm/actions/requirements/encode/encodeErc20Permit.js +3 -3
- package/lib/esm/actions/requirements/encode/encodeErc20Permit2SignatureTransfer.d.ts +5 -6
- package/lib/esm/actions/requirements/encode/encodeErc20Permit2SignatureTransfer.js +7 -15
- package/lib/esm/actions/requirements/encode/encodeVaultSharesPermit.d.ts +3 -5
- package/lib/esm/actions/requirements/encode/encodeVaultSharesPermit.js +26 -23
- package/lib/esm/actions/requirements/midnight/getMidnightApprovalRequirements.js +2 -1
- package/lib/esm/actions/requirements/midnight/getMidnightAuthorizationRequirement.js +2 -1
- package/lib/esm/actions/vaultV1/inKindRedeem.js +6 -3
- package/lib/esm/actions/vaultV1/migrateToV2.js +1 -1
- package/lib/esm/actions/vaultV2/forceWithdraw.js +4 -2
- package/lib/esm/actions/vaultV2/inKindRedeem.js +4 -2
- package/lib/esm/entities/blue/blue.d.ts +34 -28
- package/lib/esm/entities/blue/blue.js +107 -77
- package/lib/esm/entities/midnight/deadline.d.ts +2 -2
- package/lib/esm/entities/midnight/deadline.js +4 -3
- package/lib/esm/entities/midnight/midnight.d.ts +49 -51
- package/lib/esm/entities/midnight/midnight.js +159 -139
- package/lib/esm/entities/midnight/publication.d.ts +2 -0
- package/lib/esm/entities/midnight/publication.js +193 -138
- package/lib/esm/entities/midnight/types.d.ts +4 -4
- package/lib/esm/entities/requirements/assertContractCode.js +4 -2
- package/lib/esm/entities/requirements/getBundlesTokenRequirements.d.ts +3 -5
- package/lib/esm/entities/requirements/getBundlesTokenRequirements.js +25 -29
- package/lib/esm/entities/requirements/getErc2612Permit.js +10 -5
- package/lib/esm/entities/requirements/getVaultBundlesSharesRequirements.d.ts +5 -4
- package/lib/esm/entities/requirements/getVaultBundlesSharesRequirements.js +8 -2
- package/lib/esm/entities/requirements/getVaultV1InKindRedeemRequirements.d.ts +21 -0
- package/lib/esm/entities/requirements/getVaultV1InKindRedeemRequirements.js +108 -0
- package/lib/esm/entities/requirements/getVaultV2ForceWithdrawRequirements.d.ts +20 -0
- package/lib/esm/entities/requirements/getVaultV2ForceWithdrawRequirements.js +73 -0
- package/lib/esm/entities/requirements/getVaultV2InKindRedeemRequirements.d.ts +21 -0
- package/lib/esm/entities/requirements/getVaultV2InKindRedeemRequirements.js +90 -0
- package/lib/esm/entities/vaultV1/inKindRedeemQuote.d.ts +25 -0
- package/lib/esm/entities/vaultV1/inKindRedeemQuote.js +82 -0
- package/lib/esm/entities/vaultV1/migrateToV2Quote.d.ts +20 -0
- package/lib/esm/entities/vaultV1/migrateToV2Quote.js +34 -0
- package/lib/esm/entities/vaultV1/vaultV1.d.ts +12 -12
- package/lib/esm/entities/vaultV1/vaultV1.js +96 -200
- package/lib/esm/entities/vaultV2/forceWithdrawQuote.d.ts +25 -0
- package/lib/esm/entities/vaultV2/forceWithdrawQuote.js +186 -0
- package/lib/esm/entities/vaultV2/inKindRedeemQuote.d.ts +28 -0
- package/lib/esm/entities/vaultV2/inKindRedeemQuote.js +107 -0
- package/lib/esm/entities/vaultV2/vaultV2.d.ts +16 -16
- package/lib/esm/entities/vaultV2/vaultV2.js +102 -393
- package/lib/esm/entities/vaultV2BlueReallocationData.d.ts +14 -0
- package/lib/esm/entities/vaultV2BlueReallocationData.js +1599 -883
- package/lib/esm/errors.d.ts +1 -1
- package/lib/esm/errors.js +1 -1
- package/lib/esm/helpers/deadShares.js +83 -47
- package/lib/esm/helpers/encodeMidnightCalldata.js +4 -2
- package/lib/esm/helpers/metadata.d.ts +14 -2
- package/lib/esm/helpers/metadata.js +48 -8
- package/lib/esm/helpers/previewVaultV2ForceWithdraw.js +44 -27
- package/lib/esm/helpers/previewVaultV2InKindRedeem.js +11 -2
- package/lib/esm/helpers/utilization.js +10 -5
- package/lib/esm/helpers/validate.js +88 -67
- package/lib/esm/helpers/validateMidnightBounds.js +2 -1
- package/lib/esm/helpers/validateMidnightCollateralBatch.js +2 -1
- package/lib/esm/helpers/validateMidnightPublication.js +4 -2
- package/lib/esm/helpers/validateMidnightTakeFeasibility.js +176 -103
- package/lib/esm/helpers/validatePositiveInput.js +2 -1
- package/lib/esm/helpers/validateTakeableOffers.js +2 -1
- package/lib/esm/helpers/vaultV2ForceWithdrawPlan.js +40 -22
- package/lib/esm/index.d.ts +2 -2
- package/lib/esm/index.js +1 -1
- package/lib/esm/transactionPlan/approval.js +13 -2
- package/lib/esm/transactionPlan/deposit.d.ts +22 -0
- package/lib/esm/transactionPlan/deposit.js +135 -0
- package/lib/esm/transactionPlan/error.d.ts +10 -8
- package/lib/esm/transactionPlan/error.js +10 -8
- package/lib/esm/transactionPlan/getTokenPermit.js +2 -1
- package/lib/esm/transactionPlan/index.d.ts +18 -0
- package/lib/esm/transactionPlan/index.js +9 -0
- package/lib/esm/transactionPlan/intent.d.ts +3 -3
- package/lib/esm/transactionPlan/intent.js +14 -7
- package/lib/esm/transactionPlan/permit.d.ts +1 -1
- package/lib/esm/transactionPlan/permit.js +86 -20
- package/lib/esm/transactionPlan/plan.d.ts +16 -6
- package/lib/esm/transactionPlan/plan.js +73 -20
- package/lib/esm/transactionPlan/redeem.d.ts +18 -0
- package/lib/esm/transactionPlan/redeem.js +59 -0
- package/lib/esm/transactionPlan/requirements.d.ts +4 -3
- package/lib/esm/transactionPlan/requirements.js +12 -6
- package/lib/esm/transactionPlan/serde.d.ts +2 -2
- package/lib/esm/transactionPlan/serde.js +45 -19
- package/lib/esm/transactionPlan/shareSpending.d.ts +18 -0
- package/lib/esm/transactionPlan/shareSpending.js +47 -0
- package/lib/esm/transactionPlan/types.d.ts +117 -11
- package/lib/esm/transactionPlan/validateActions.js +11 -1
- package/lib/esm/transactionPlan/validation.js +6 -3
- package/lib/esm/transactionPlan/vaultv1/deposit.d.ts +93 -0
- package/lib/esm/transactionPlan/vaultv1/deposit.js +90 -0
- package/lib/esm/transactionPlan/vaultv1/inKindRedeem.d.ts +96 -0
- package/lib/esm/transactionPlan/vaultv1/inKindRedeem.js +198 -0
- package/lib/esm/transactionPlan/vaultv1/migrateToV2.d.ts +94 -0
- package/lib/esm/transactionPlan/vaultv1/migrateToV2.js +212 -0
- package/lib/esm/transactionPlan/vaultv1/redeem.d.ts +69 -0
- package/lib/esm/transactionPlan/vaultv1/redeem.js +74 -0
- package/lib/esm/transactionPlan/vaultv1/withdraw.d.ts +77 -0
- package/lib/esm/transactionPlan/vaultv1/withdraw.js +84 -0
- package/lib/esm/transactionPlan/vaultv2/deposit.d.ts +18 -33
- package/lib/esm/transactionPlan/vaultv2/deposit.js +21 -144
- package/lib/esm/transactionPlan/vaultv2/forceRedeem.d.ts +74 -0
- package/lib/esm/transactionPlan/vaultv2/forceRedeem.js +150 -0
- package/lib/esm/transactionPlan/vaultv2/forceWithdraw.d.ts +98 -0
- package/lib/esm/transactionPlan/vaultv2/forceWithdraw.js +201 -0
- package/lib/esm/transactionPlan/vaultv2/inKindRedeem.d.ts +113 -0
- package/lib/esm/transactionPlan/vaultv2/inKindRedeem.js +201 -0
- package/lib/esm/transactionPlan/vaultv2/redeem.d.ts +84 -0
- package/lib/esm/transactionPlan/vaultv2/redeem.js +82 -0
- package/lib/esm/transactionPlan/vaultv2/withdraw.d.ts +18 -29
- package/lib/esm/transactionPlan/vaultv2/withdraw.js +23 -127
- package/lib/esm/transactionPlan/version.js +2 -1
- package/lib/esm/transactionPlan/withdraw.d.ts +18 -0
- package/lib/esm/transactionPlan/withdraw.js +90 -0
- package/lib/esm/types/action.d.ts +26 -2
- package/lib/esm/types/action.js +17 -9
- package/lib/esm/types/error.d.ts +8 -1
- package/lib/esm/types/error.js +21 -6
- package/lib/esm/types/metadata.d.ts +12 -2
- package/lib/esm/version.d.ts +1 -1
- package/lib/esm/version.js +1 -1
- package/package.json +15 -14
|
@@ -13,6 +13,7 @@ const callback_js_1 = require("../../helpers/callback.js");
|
|
|
13
13
|
const constant_js_1 = require("../../helpers/constant.js");
|
|
14
14
|
const encodeMidnightCalldata_js_1 = require("../../helpers/encodeMidnightCalldata.js");
|
|
15
15
|
const index_js_3 = require("../../helpers/index.js");
|
|
16
|
+
const metadata_js_1 = require("../../helpers/metadata.js");
|
|
16
17
|
const validateMidnightAccount_js_1 = require("../../helpers/validateMidnightAccount.js");
|
|
17
18
|
const validateMidnightBounds_js_1 = require("../../helpers/validateMidnightBounds.js");
|
|
18
19
|
const validateMidnightCollateralBatch_js_1 = require("../../helpers/validateMidnightCollateralBatch.js");
|
|
@@ -33,8 +34,7 @@ const validatePositionBinding = (params) => {
|
|
|
33
34
|
throw new index_js_4.AccrualPositionUserMismatchError(params.positionData.user, params.accountAddress);
|
|
34
35
|
}
|
|
35
36
|
};
|
|
36
|
-
const validateTakeDeadlineWindow = (deadline) => {
|
|
37
|
-
const now = morpho_ts_1.Time.timestamp();
|
|
37
|
+
const validateTakeDeadlineWindow = (deadline, now = morpho_ts_1.Time.timestamp()) => {
|
|
38
38
|
// Throws when the deadline is at or before now.
|
|
39
39
|
(0, deadline_js_1.validateMidnightDeadline)(deadline, now);
|
|
40
40
|
const maxDeadline = now + constant_js_1.MIDNIGHT_TAKE_MAX_DEADLINE_SECONDS;
|
|
@@ -43,17 +43,20 @@ const validateTakeDeadlineWindow = (deadline) => {
|
|
|
43
43
|
}
|
|
44
44
|
};
|
|
45
45
|
const assertNonNegativeAmount = (label, amount) => {
|
|
46
|
-
if (amount < 0n)
|
|
46
|
+
if (amount < 0n) {
|
|
47
47
|
throw new index_js_4.NegativeInputError(label, amount);
|
|
48
|
+
}
|
|
48
49
|
};
|
|
49
50
|
const assertPositiveAmount = (label, amount) => {
|
|
50
|
-
if (amount <= 0n)
|
|
51
|
+
if (amount <= 0n) {
|
|
51
52
|
throw new index_js_4.NonPositiveInputError(label, amount);
|
|
53
|
+
}
|
|
52
54
|
};
|
|
53
55
|
const rejectReduceOnlyOffers = (offers) => {
|
|
54
56
|
offers.forEach((offer, index) => {
|
|
55
|
-
if (offer.reduceOnly)
|
|
57
|
+
if (offer.reduceOnly) {
|
|
56
58
|
throw new index_js_4.MidnightOfferReduceOnlyError({ index });
|
|
59
|
+
}
|
|
57
60
|
});
|
|
58
61
|
};
|
|
59
62
|
const getOffersDataInternal = async ({ client, chainId, params, marketCreationTime = "expiry", }) => {
|
|
@@ -150,6 +153,29 @@ const getOffersDataInternal = async ({ client, chainId, params, marketCreationTi
|
|
|
150
153
|
payload: await midnight_sdk_1.Payload.encode(items),
|
|
151
154
|
};
|
|
152
155
|
};
|
|
156
|
+
const getPostWithdrawalCollateral = (params) => {
|
|
157
|
+
const market = params.marketData.params;
|
|
158
|
+
const collateralWithdrawals = params.collateralWithdrawals ?? [];
|
|
159
|
+
const postCollateral = Array.from({ length: market.collateralParams.length }, (_, index) => params.positionData.collateral[index] ?? 0n);
|
|
160
|
+
let withdrawAmount = 0n;
|
|
161
|
+
for (const withdrawal of collateralWithdrawals) {
|
|
162
|
+
// Reject unconfigured collateral indexes before updating postCollateral.
|
|
163
|
+
midnight_sdk_1.MarketUtils.getCollateralByIndex(market, withdrawal.collateralIndex);
|
|
164
|
+
const index = Number(withdrawal.collateralIndex);
|
|
165
|
+
const available = postCollateral[index] ?? 0n;
|
|
166
|
+
const amount = withdrawal.assets === viem_1.maxUint256 ? available : withdrawal.assets;
|
|
167
|
+
if (amount > available) {
|
|
168
|
+
throw new index_js_4.WithdrawExceedsCollateralError({
|
|
169
|
+
withdrawAmount: amount,
|
|
170
|
+
available,
|
|
171
|
+
market: params.marketData.id,
|
|
172
|
+
});
|
|
173
|
+
}
|
|
174
|
+
postCollateral[index] = available - amount;
|
|
175
|
+
withdrawAmount += amount;
|
|
176
|
+
}
|
|
177
|
+
return { postCollateral, withdrawAmount };
|
|
178
|
+
};
|
|
153
179
|
const validateMarketData = (market, chainId) => {
|
|
154
180
|
// Reject snapshots from another chain deployment before exposing requirements.
|
|
155
181
|
(0, validateMidnightMarket_js_1.validateMidnightMarket)({ market, chainId });
|
|
@@ -364,15 +390,18 @@ class MorphoMidnight {
|
|
|
364
390
|
* target: { type: "assets", assets: 1_000_000n, minUnits: 900_000n },
|
|
365
391
|
* takeableOffers: quote.data.takeableOffers,
|
|
366
392
|
* maxContinuousFee: maxUint256,
|
|
367
|
-
*
|
|
393
|
+
* now: (await client.getBlock()).timestamp,
|
|
394
|
+
* deadline: (await client.getBlock()).timestamp + 600n,
|
|
368
395
|
* });
|
|
369
396
|
* ```
|
|
370
397
|
*/
|
|
371
398
|
takeLend(params) {
|
|
399
|
+
const metadata = (0, metadata_js_1.resolveTransactionMetadata)(this.client.options.metadata, params.now);
|
|
372
400
|
(0, index_js_3.validateChainId)(this.client.viemClient.chain?.id, this.chainId);
|
|
373
401
|
// Reject the zero account before preparing anything for it.
|
|
374
402
|
(0, validateMidnightAccount_js_1.validateMidnightAccount)("accountAddress", params.accountAddress);
|
|
375
|
-
|
|
403
|
+
const now = params.now ?? morpho_ts_1.Time.timestamp();
|
|
404
|
+
validateTakeDeadlineWindow(params.deadline, now);
|
|
376
405
|
const market = params.marketData.params;
|
|
377
406
|
const rawParams = {
|
|
378
407
|
chainId: this.chainId,
|
|
@@ -384,7 +413,7 @@ class MorphoMidnight {
|
|
|
384
413
|
deadline: params.deadline,
|
|
385
414
|
referralFeePct: params.referralFeePct,
|
|
386
415
|
referralFeeRecipient: params.referralFeeRecipient,
|
|
387
|
-
metadata
|
|
416
|
+
metadata,
|
|
388
417
|
};
|
|
389
418
|
let tx = (0, index_js_1.midnightTakeLend)(rawParams);
|
|
390
419
|
const takeableOffers = (0, validateMidnightTakeFeasibility_js_1.validateMidnightTakeFeasibility)({
|
|
@@ -392,7 +421,7 @@ class MorphoMidnight {
|
|
|
392
421
|
takeableOffers: params.takeableOffers,
|
|
393
422
|
accountAddress: params.accountAddress,
|
|
394
423
|
marketData: params.marketData,
|
|
395
|
-
now: morpho_ts_1.Time.timestamp(),
|
|
424
|
+
now: params.now ?? morpho_ts_1.Time.timestamp(),
|
|
396
425
|
deadline: params.deadline,
|
|
397
426
|
referralFeePct: tx.action.args.referralFeePct,
|
|
398
427
|
fallbackUnits: 0n,
|
|
@@ -511,15 +540,18 @@ class MorphoMidnight {
|
|
|
511
540
|
* collateralPrices,
|
|
512
541
|
* target: { type: "assets", assets: 1_000_000n, maxUnits: 1_100_000n },
|
|
513
542
|
* takeableOffers: quote.data.takeableOffers,
|
|
514
|
-
*
|
|
543
|
+
* now: (await client.getBlock()).timestamp,
|
|
544
|
+
* deadline: (await client.getBlock()).timestamp + 600n,
|
|
515
545
|
* });
|
|
516
546
|
* ```
|
|
517
547
|
*/
|
|
518
548
|
takeBorrow(params) {
|
|
549
|
+
const metadata = (0, metadata_js_1.resolveTransactionMetadata)(this.client.options.metadata, params.now);
|
|
519
550
|
(0, index_js_3.validateChainId)(this.client.viemClient.chain?.id, this.chainId);
|
|
520
551
|
// Reject the zero account before preparing anything for it.
|
|
521
552
|
(0, validateMidnightAccount_js_1.validateMidnightAccount)("accountAddress", params.accountAddress);
|
|
522
|
-
|
|
553
|
+
const now = params.now ?? morpho_ts_1.Time.timestamp();
|
|
554
|
+
validateTakeDeadlineWindow(params.deadline, now);
|
|
523
555
|
const rawParams = {
|
|
524
556
|
chainId: this.chainId,
|
|
525
557
|
market: params.marketData.params,
|
|
@@ -529,7 +561,7 @@ class MorphoMidnight {
|
|
|
529
561
|
deadline: params.deadline,
|
|
530
562
|
referralFeePct: params.referralFeePct,
|
|
531
563
|
referralFeeRecipient: params.referralFeeRecipient,
|
|
532
|
-
metadata
|
|
564
|
+
metadata,
|
|
533
565
|
};
|
|
534
566
|
let tx = (0, index_js_1.midnightTakeBorrow)(rawParams);
|
|
535
567
|
validatePositionBinding({
|
|
@@ -551,7 +583,6 @@ class MorphoMidnight {
|
|
|
551
583
|
throw new index_js_4.BorrowExceedsSafeLtvError(requestedUnits, blue_sdk_1.MathLib.zeroFloorSub(maxSafeDebt, params.positionData.debt));
|
|
552
584
|
}
|
|
553
585
|
}
|
|
554
|
-
const now = morpho_ts_1.Time.timestamp();
|
|
555
586
|
const takeableOffers = (0, validateMidnightTakeFeasibility_js_1.validateMidnightTakeFeasibility)({
|
|
556
587
|
side: "sell",
|
|
557
588
|
takeableOffers: params.takeableOffers,
|
|
@@ -638,15 +669,18 @@ class MorphoMidnight {
|
|
|
638
669
|
* marketData,
|
|
639
670
|
* target: { type: "units", units: credit, minSellerAssets: 990_000n },
|
|
640
671
|
* takeableOffers: quote.data.takeableOffers,
|
|
641
|
-
*
|
|
672
|
+
* now: (await client.getBlock()).timestamp,
|
|
673
|
+
* deadline: (await client.getBlock()).timestamp + 600n,
|
|
642
674
|
* });
|
|
643
675
|
* ```
|
|
644
676
|
*/
|
|
645
677
|
takeWithdraw(params) {
|
|
678
|
+
const metadata = (0, metadata_js_1.resolveTransactionMetadata)(this.client.options.metadata, params.now);
|
|
646
679
|
(0, index_js_3.validateChainId)(this.client.viemClient.chain?.id, this.chainId);
|
|
647
680
|
// Reject the zero account before preparing anything for it.
|
|
648
681
|
(0, validateMidnightAccount_js_1.validateMidnightAccount)("accountAddress", params.accountAddress);
|
|
649
|
-
|
|
682
|
+
const now = params.now ?? morpho_ts_1.Time.timestamp();
|
|
683
|
+
validateTakeDeadlineWindow(params.deadline, now);
|
|
650
684
|
const rawParams = {
|
|
651
685
|
chainId: this.chainId,
|
|
652
686
|
market: params.marketData.params,
|
|
@@ -656,7 +690,7 @@ class MorphoMidnight {
|
|
|
656
690
|
deadline: params.deadline,
|
|
657
691
|
referralFeePct: params.referralFeePct,
|
|
658
692
|
referralFeeRecipient: params.referralFeeRecipient,
|
|
659
|
-
metadata
|
|
693
|
+
metadata,
|
|
660
694
|
};
|
|
661
695
|
let tx = (0, index_js_1.midnightTakeWithdraw)(rawParams);
|
|
662
696
|
const takeableOffers = (0, validateMidnightTakeFeasibility_js_1.validateMidnightTakeFeasibility)({
|
|
@@ -664,7 +698,7 @@ class MorphoMidnight {
|
|
|
664
698
|
takeableOffers: params.takeableOffers,
|
|
665
699
|
accountAddress: params.accountAddress,
|
|
666
700
|
marketData: params.marketData,
|
|
667
|
-
now: morpho_ts_1.Time.timestamp(),
|
|
701
|
+
now: params.now ?? morpho_ts_1.Time.timestamp(),
|
|
668
702
|
deadline: params.deadline,
|
|
669
703
|
referralFeePct: tx.action.args.referralFeePct,
|
|
670
704
|
// The bundle redeems credit first, up to the market's withdrawable liquidity.
|
|
@@ -771,15 +805,18 @@ class MorphoMidnight {
|
|
|
771
805
|
* collateralSupplies: [{ collateralIndex: 0n, assets: 2_000_000n }],
|
|
772
806
|
* target: { type: "assets", assets: 1_000_000n, maxUnits: 1_100_000n },
|
|
773
807
|
* takeableOffers: quote.data.takeableOffers,
|
|
774
|
-
*
|
|
808
|
+
* now: (await client.getBlock()).timestamp,
|
|
809
|
+
* deadline: (await client.getBlock()).timestamp + 600n,
|
|
775
810
|
* });
|
|
776
811
|
* ```
|
|
777
812
|
*/
|
|
778
813
|
supplyCollateralTakeBorrow(params) {
|
|
814
|
+
const metadata = (0, metadata_js_1.resolveTransactionMetadata)(this.client.options.metadata, params.now);
|
|
779
815
|
(0, index_js_3.validateChainId)(this.client.viemClient.chain?.id, this.chainId);
|
|
780
816
|
// Reject the zero account before preparing anything for it.
|
|
781
817
|
(0, validateMidnightAccount_js_1.validateMidnightAccount)("accountAddress", params.accountAddress);
|
|
782
|
-
|
|
818
|
+
const now = params.now ?? morpho_ts_1.Time.timestamp();
|
|
819
|
+
validateTakeDeadlineWindow(params.deadline, now);
|
|
783
820
|
const market = params.marketData.params;
|
|
784
821
|
const rawParams = {
|
|
785
822
|
chainId: this.chainId,
|
|
@@ -792,7 +829,7 @@ class MorphoMidnight {
|
|
|
792
829
|
deadline: params.deadline,
|
|
793
830
|
referralFeePct: params.referralFeePct,
|
|
794
831
|
referralFeeRecipient: params.referralFeeRecipient,
|
|
795
|
-
metadata
|
|
832
|
+
metadata,
|
|
796
833
|
};
|
|
797
834
|
let tx = (0, index_js_1.midnightSupplyCollateralTakeBorrow)(rawParams);
|
|
798
835
|
validatePositionBinding({
|
|
@@ -821,7 +858,6 @@ class MorphoMidnight {
|
|
|
821
858
|
throw new index_js_4.BorrowExceedsSafeLtvError(requestedUnits, blue_sdk_1.MathLib.zeroFloorSub(maxSafeDebt, params.positionData.debt));
|
|
822
859
|
}
|
|
823
860
|
}
|
|
824
|
-
const now = morpho_ts_1.Time.timestamp();
|
|
825
861
|
const takeableOffers = (0, validateMidnightTakeFeasibility_js_1.validateMidnightTakeFeasibility)({
|
|
826
862
|
side: "sell",
|
|
827
863
|
takeableOffers: params.takeableOffers,
|
|
@@ -965,15 +1001,18 @@ class MorphoMidnight {
|
|
|
965
1001
|
* repayEnabled: true,
|
|
966
1002
|
* collateralWithdrawals: [{ collateralIndex: 0n, assets: maxUint256 }],
|
|
967
1003
|
* maxContinuousFee: maxUint256,
|
|
968
|
-
*
|
|
1004
|
+
* now: (await client.getBlock()).timestamp,
|
|
1005
|
+
* deadline: (await client.getBlock()).timestamp + 600n,
|
|
969
1006
|
* });
|
|
970
1007
|
* ```
|
|
971
1008
|
*/
|
|
972
1009
|
takeRepayWithdrawCollateral(params) {
|
|
1010
|
+
const metadata = (0, metadata_js_1.resolveTransactionMetadata)(this.client.options.metadata, params.now);
|
|
973
1011
|
(0, index_js_3.validateChainId)(this.client.viemClient.chain?.id, this.chainId);
|
|
974
1012
|
// Reject the zero account before preparing anything for it.
|
|
975
1013
|
(0, validateMidnightAccount_js_1.validateMidnightAccount)("accountAddress", params.accountAddress);
|
|
976
|
-
|
|
1014
|
+
const now = params.now ?? morpho_ts_1.Time.timestamp();
|
|
1015
|
+
validateTakeDeadlineWindow(params.deadline, now);
|
|
977
1016
|
const market = params.marketData.params;
|
|
978
1017
|
const rawParams = {
|
|
979
1018
|
chainId: this.chainId,
|
|
@@ -988,7 +1027,7 @@ class MorphoMidnight {
|
|
|
988
1027
|
deadline: params.deadline,
|
|
989
1028
|
referralFeePct: params.referralFeePct,
|
|
990
1029
|
referralFeeRecipient: params.referralFeeRecipient,
|
|
991
|
-
metadata
|
|
1030
|
+
metadata,
|
|
992
1031
|
};
|
|
993
1032
|
let tx = (0, index_js_1.midnightTakeRepayWithdrawCollateral)(rawParams);
|
|
994
1033
|
validatePositionBinding({
|
|
@@ -997,24 +1036,7 @@ class MorphoMidnight {
|
|
|
997
1036
|
marketData: params.marketData,
|
|
998
1037
|
});
|
|
999
1038
|
const collateralWithdrawals = params.collateralWithdrawals ?? [];
|
|
1000
|
-
const
|
|
1001
|
-
let withdrawAmount = 0n;
|
|
1002
|
-
for (const withdrawal of collateralWithdrawals) {
|
|
1003
|
-
// Reject unconfigured collateral indexes before updating postCollateral.
|
|
1004
|
-
midnight_sdk_1.MarketUtils.getCollateralByIndex(market, withdrawal.collateralIndex);
|
|
1005
|
-
const index = Number(withdrawal.collateralIndex);
|
|
1006
|
-
const available = postCollateral[index] ?? 0n;
|
|
1007
|
-
const amount = withdrawal.assets === viem_1.maxUint256 ? available : withdrawal.assets;
|
|
1008
|
-
if (amount > available) {
|
|
1009
|
-
throw new index_js_4.WithdrawExceedsCollateralError({
|
|
1010
|
-
withdrawAmount: amount,
|
|
1011
|
-
available,
|
|
1012
|
-
market: params.marketData.id,
|
|
1013
|
-
});
|
|
1014
|
-
}
|
|
1015
|
-
postCollateral[index] = available - amount;
|
|
1016
|
-
withdrawAmount += amount;
|
|
1017
|
-
}
|
|
1039
|
+
const { postCollateral, withdrawAmount } = getPostWithdrawalCollateral(params);
|
|
1018
1040
|
const debtReduction = params.target.type === "units"
|
|
1019
1041
|
? params.target.units
|
|
1020
1042
|
: params.target.minUnits;
|
|
@@ -1040,7 +1062,7 @@ class MorphoMidnight {
|
|
|
1040
1062
|
takeableOffers: params.takeableOffers,
|
|
1041
1063
|
accountAddress: params.accountAddress,
|
|
1042
1064
|
marketData: params.marketData,
|
|
1043
|
-
now: morpho_ts_1.Time.timestamp(),
|
|
1065
|
+
now: params.now ?? morpho_ts_1.Time.timestamp(),
|
|
1044
1066
|
deadline: params.deadline,
|
|
1045
1067
|
referralFeePct: tx.action.args.referralFeePct,
|
|
1046
1068
|
// With repayEnabled the bundle repays the unfilled debt directly, at par.
|
|
@@ -1120,6 +1142,7 @@ class MorphoMidnight {
|
|
|
1120
1142
|
* ```
|
|
1121
1143
|
*/
|
|
1122
1144
|
withdrawCollateral(params) {
|
|
1145
|
+
const metadata = (0, metadata_js_1.resolveTransactionMetadata)(this.client.options.metadata, params.now);
|
|
1123
1146
|
(0, index_js_3.validateChainId)(this.client.viemClient.chain?.id, this.chainId);
|
|
1124
1147
|
// Reject invalid owners before preparing the direct call.
|
|
1125
1148
|
(0, validateMidnightAccount_js_1.validateMidnightAccount)("accountAddress", params.accountAddress);
|
|
@@ -1138,7 +1161,7 @@ class MorphoMidnight {
|
|
|
1138
1161
|
assets,
|
|
1139
1162
|
onBehalf: params.accountAddress,
|
|
1140
1163
|
receiver: params.receiver ?? params.accountAddress,
|
|
1141
|
-
metadata
|
|
1164
|
+
metadata,
|
|
1142
1165
|
});
|
|
1143
1166
|
if (assets > available) {
|
|
1144
1167
|
throw new index_js_4.WithdrawExceedsCollateralError({
|
|
@@ -1211,6 +1234,7 @@ class MorphoMidnight {
|
|
|
1211
1234
|
* ```
|
|
1212
1235
|
*/
|
|
1213
1236
|
withdrawCollateralBatch(params) {
|
|
1237
|
+
const metadata = (0, metadata_js_1.resolveTransactionMetadata)(this.client.options.metadata, params.now);
|
|
1214
1238
|
(0, index_js_3.validateChainId)(this.client.viemClient.chain?.id, this.chainId);
|
|
1215
1239
|
// Reject invalid owners before preparing the direct call.
|
|
1216
1240
|
(0, validateMidnightAccount_js_1.validateMidnightAccount)("accountAddress", params.accountAddress);
|
|
@@ -1234,12 +1258,12 @@ class MorphoMidnight {
|
|
|
1234
1258
|
collateralWithdrawals,
|
|
1235
1259
|
onBehalf: params.accountAddress,
|
|
1236
1260
|
receiver: params.receiver ?? params.accountAddress,
|
|
1237
|
-
metadata
|
|
1261
|
+
metadata,
|
|
1238
1262
|
});
|
|
1239
1263
|
const collateral = Array.from({ length: params.marketData.params.collateralParams.length }, (_, i) => params.positionData.collateral[i] ?? 0n);
|
|
1240
1264
|
for (const { collateralIndex, assets } of collateralWithdrawals) {
|
|
1241
1265
|
const index = Number(collateralIndex);
|
|
1242
|
-
const available = collateral[index];
|
|
1266
|
+
const available = collateral[index] ?? 0n;
|
|
1243
1267
|
if (assets > available) {
|
|
1244
1268
|
throw new index_js_4.WithdrawExceedsCollateralError({
|
|
1245
1269
|
withdrawAmount: assets,
|
|
@@ -1303,6 +1327,7 @@ class MorphoMidnight {
|
|
|
1303
1327
|
* ```
|
|
1304
1328
|
*/
|
|
1305
1329
|
supplyCollateral(params) {
|
|
1330
|
+
const metadata = (0, metadata_js_1.resolveTransactionMetadata)(this.client.options.metadata, params.now);
|
|
1306
1331
|
(0, index_js_3.validateChainId)(this.client.viemClient.chain?.id, this.chainId);
|
|
1307
1332
|
// Reject a malformed account here; the builder rejects the zero account.
|
|
1308
1333
|
(0, validateMidnightAccount_js_1.validateMidnightAddress)("accountAddress", params.accountAddress);
|
|
@@ -1335,7 +1360,7 @@ class MorphoMidnight {
|
|
|
1335
1360
|
collateralIndex,
|
|
1336
1361
|
assets: params.collateralAssets,
|
|
1337
1362
|
onBehalf: params.accountAddress,
|
|
1338
|
-
metadata
|
|
1363
|
+
metadata,
|
|
1339
1364
|
}),
|
|
1340
1365
|
};
|
|
1341
1366
|
}
|
|
@@ -1367,6 +1392,7 @@ class MorphoMidnight {
|
|
|
1367
1392
|
* ```
|
|
1368
1393
|
*/
|
|
1369
1394
|
supplyCollateralBatch(params) {
|
|
1395
|
+
const metadata = (0, metadata_js_1.resolveTransactionMetadata)(this.client.options.metadata, params.now);
|
|
1370
1396
|
(0, index_js_3.validateChainId)(this.client.viemClient.chain?.id, this.chainId);
|
|
1371
1397
|
// Reject malformed accounts before resolving token requirements.
|
|
1372
1398
|
(0, validateMidnightAccount_js_1.validateMidnightAddress)("accountAddress", params.accountAddress);
|
|
@@ -1408,7 +1434,7 @@ class MorphoMidnight {
|
|
|
1408
1434
|
market: params.marketData.params,
|
|
1409
1435
|
collateralSupplies: params.collateralSupplies.map(({ collateralIndex, assets }) => ({ collateralIndex, assets })),
|
|
1410
1436
|
onBehalf: params.accountAddress,
|
|
1411
|
-
metadata
|
|
1437
|
+
metadata,
|
|
1412
1438
|
}),
|
|
1413
1439
|
};
|
|
1414
1440
|
}
|
|
@@ -1468,7 +1494,7 @@ class MorphoMidnight {
|
|
|
1468
1494
|
* @throws {MidnightMarketLiquidationCursorNotEnabledError} when an uncreated market uses a disabled liquidation cursor.
|
|
1469
1495
|
* @throws {MidnightMarketOracleWithoutCodeError} when an uncreated market's oracle has no code.
|
|
1470
1496
|
* @throws {viem.BaseError} when a pinned block, contract, or oracle-code read fails.
|
|
1471
|
-
* @throws {ExpiredDeadlineError} when `params.deadline` is at or before the
|
|
1497
|
+
* @throws {ExpiredDeadlineError} when `params.deadline` is at or before the reference timestamp (`params.now`, or the deprecated device-clock fallback), including zero or negative values.
|
|
1472
1498
|
* @example
|
|
1473
1499
|
* ```ts
|
|
1474
1500
|
* const output = await midnight.makeLend({
|
|
@@ -1486,7 +1512,8 @@ class MorphoMidnight {
|
|
|
1486
1512
|
// Reject the zero account before preparing anything for it.
|
|
1487
1513
|
(0, validateMidnightAccount_js_1.validateMidnightAccount)("accountAddress", params.accountAddress);
|
|
1488
1514
|
// Fails before any API read or build when the deadline has already passed.
|
|
1489
|
-
|
|
1515
|
+
const now = params.now ?? morpho_ts_1.Time.timestamp();
|
|
1516
|
+
(0, deadline_js_1.validateMidnightDeadline)(params.deadline, now);
|
|
1490
1517
|
const tree = (0, encodeMidnightCalldata_js_1.wrapMidnightEncoding)("offers", () => midnight_sdk_1.Tree.from(params.offers));
|
|
1491
1518
|
rejectReduceOnlyOffers(tree.offers);
|
|
1492
1519
|
return this.prepareLendOffers({ ...params, offers: tree });
|
|
@@ -1542,7 +1569,7 @@ class MorphoMidnight {
|
|
|
1542
1569
|
* @throws {MidnightReplacementGroupCancelledError} when a published group is also cancelled.
|
|
1543
1570
|
* @throws {InvalidMidnightHexInputError} when a cancellation group is not 32-byte hex.
|
|
1544
1571
|
* @throws {DuplicateMidnightGroupCancellationError} when a cancelled group appears more than once.
|
|
1545
|
-
* @throws {ExpiredDeadlineError} when `params.deadline` is at or before the
|
|
1572
|
+
* @throws {ExpiredDeadlineError} when `params.deadline` is at or before the reference timestamp (`params.now`, or the deprecated device-clock fallback), including zero or negative values.
|
|
1546
1573
|
* @example
|
|
1547
1574
|
* ```ts
|
|
1548
1575
|
* const output = await midnight.makeBorrow({
|
|
@@ -1557,7 +1584,8 @@ class MorphoMidnight {
|
|
|
1557
1584
|
// Reject the zero account before preparing anything for it.
|
|
1558
1585
|
(0, validateMidnightAccount_js_1.validateMidnightAccount)("accountAddress", params.accountAddress);
|
|
1559
1586
|
// Fails before any API read or build when the deadline has already passed.
|
|
1560
|
-
|
|
1587
|
+
const now = params.now ?? morpho_ts_1.Time.timestamp();
|
|
1588
|
+
(0, deadline_js_1.validateMidnightDeadline)(params.deadline, now);
|
|
1561
1589
|
const tree = (0, encodeMidnightCalldata_js_1.wrapMidnightEncoding)("offers", () => midnight_sdk_1.Tree.from(params.offers));
|
|
1562
1590
|
rejectReduceOnlyOffers(tree.offers);
|
|
1563
1591
|
return this.prepareBorrowOffers({ ...params, offers: tree });
|
|
@@ -1566,6 +1594,7 @@ class MorphoMidnight {
|
|
|
1566
1594
|
* Prepares lend-side offers for publication.
|
|
1567
1595
|
*/
|
|
1568
1596
|
async prepareLendOffers(params) {
|
|
1597
|
+
const metadata = (0, metadata_js_1.resolveTransactionMetadata)(this.client.options.metadata, params.now);
|
|
1569
1598
|
// Reject a malformed address before viem compares offer markets with it.
|
|
1570
1599
|
(0, validateMidnightAccount_js_1.validateMidnightAddress)("loanToken", params.loanToken);
|
|
1571
1600
|
assertPositiveAmount("loanAssets", params.loanAssets);
|
|
@@ -1592,7 +1621,7 @@ class MorphoMidnight {
|
|
|
1592
1621
|
chainId: this.chainId,
|
|
1593
1622
|
cancellations: params.cancellations ?? [],
|
|
1594
1623
|
deadline: params.deadline,
|
|
1595
|
-
metadata
|
|
1624
|
+
metadata,
|
|
1596
1625
|
publication: {
|
|
1597
1626
|
ratifier: data.ratifier,
|
|
1598
1627
|
root: data.tree.root,
|
|
@@ -1708,7 +1737,7 @@ class MorphoMidnight {
|
|
|
1708
1737
|
* @throws {MidnightReplacementGroupCancelledError} when a published group is also cancelled.
|
|
1709
1738
|
* @throws {InvalidMidnightHexInputError} when a cancellation group or `callbackSalt` is not 32-byte hex.
|
|
1710
1739
|
* @throws {DuplicateMidnightGroupCancellationError} when a cancelled group appears more than once.
|
|
1711
|
-
* @throws {ExpiredDeadlineError} when `params.deadline` is at or before the
|
|
1740
|
+
* @throws {ExpiredDeadlineError} when `params.deadline` is at or before the reference timestamp (`params.now`, or the deprecated device-clock fallback), including zero or negative values.
|
|
1712
1741
|
* @example
|
|
1713
1742
|
* ```ts
|
|
1714
1743
|
* const callback = getMidnightBlueBuyCallbackAddress({ chainId, owner: maker, salt: callbackSalt });
|
|
@@ -1727,6 +1756,8 @@ class MorphoMidnight {
|
|
|
1727
1756
|
* ```
|
|
1728
1757
|
*/
|
|
1729
1758
|
async supplyBlueMakeLend(params) {
|
|
1759
|
+
const suppliedNow = params.now;
|
|
1760
|
+
const metadata = (0, metadata_js_1.resolveTransactionMetadata)(this.client.options.metadata, suppliedNow);
|
|
1730
1761
|
// Reject the zero account before preparing anything for it.
|
|
1731
1762
|
(0, validateMidnightAccount_js_1.validateMidnightAccount)("accountAddress", params.accountAddress);
|
|
1732
1763
|
// Reject wrong-sized salts before callback derivation pads them or any read occurs.
|
|
@@ -1738,7 +1769,8 @@ class MorphoMidnight {
|
|
|
1738
1769
|
rejectReduceOnlyOffers(tree.offers);
|
|
1739
1770
|
await (0, validateClientChainId_js_1.validateClientChainId)(this.client.viemClient, this.chainId);
|
|
1740
1771
|
// Fails before any API read or build when the deadline has already passed.
|
|
1741
|
-
|
|
1772
|
+
const now = suppliedNow ?? morpho_ts_1.Time.timestamp();
|
|
1773
|
+
(0, deadline_js_1.validateMidnightDeadline)(params.deadline, now);
|
|
1742
1774
|
const { callbackSalt } = params;
|
|
1743
1775
|
// Encode the whole Blue market first so a malformed field fails typed, before the RPC read.
|
|
1744
1776
|
const callbackData = (0, encodeMidnightCalldata_js_1.wrapMidnightEncoding)("blueMarket", () => (0, callback_js_1.getMidnightBlueBuyCallbackData)(params.blueMarket));
|
|
@@ -1758,7 +1790,7 @@ class MorphoMidnight {
|
|
|
1758
1790
|
deployless: this.client.options.supportDeployless,
|
|
1759
1791
|
}),
|
|
1760
1792
|
]);
|
|
1761
|
-
const market = (0, morpho_ts_1._try)(() => fetched.accrueInterest(blue_sdk_1.MathLib.max(morpho_ts_1.Time.timestamp(), fetched.lastUpdate)), blue_sdk_1.UnsupportedMarketIrmError) ?? fetched;
|
|
1793
|
+
const market = (0, morpho_ts_1._try)(() => fetched.accrueInterest(blue_sdk_1.MathLib.max(suppliedNow ?? morpho_ts_1.Time.timestamp(), fetched.lastUpdate)), blue_sdk_1.UnsupportedMarketIrmError) ?? fetched;
|
|
1762
1794
|
if (market.totalSupplyShares === 0n) {
|
|
1763
1795
|
throw new index_js_4.EmptyBlueParkingMarketError({ marketId: blueMarketId });
|
|
1764
1796
|
}
|
|
@@ -1808,7 +1840,7 @@ class MorphoMidnight {
|
|
|
1808
1840
|
nativeAmount: params.nativeAmount,
|
|
1809
1841
|
cancellations: params.cancellations ?? [],
|
|
1810
1842
|
deadline: params.deadline,
|
|
1811
|
-
metadata
|
|
1843
|
+
metadata,
|
|
1812
1844
|
});
|
|
1813
1845
|
return {
|
|
1814
1846
|
groups: data.groups,
|
|
@@ -1833,6 +1865,7 @@ class MorphoMidnight {
|
|
|
1833
1865
|
* Prepares borrow-side offers for publication.
|
|
1834
1866
|
*/
|
|
1835
1867
|
async prepareBorrowOffers(params) {
|
|
1868
|
+
const metadata = (0, metadata_js_1.resolveTransactionMetadata)(this.client.options.metadata, params.now);
|
|
1836
1869
|
const tree = (0, encodeMidnightCalldata_js_1.wrapMidnightEncoding)("offers", () => midnight_sdk_1.Tree.from(params.offers));
|
|
1837
1870
|
(0, validateOfferSides_js_1.validateOfferSides)(tree.offers, false);
|
|
1838
1871
|
(0, publication_js_1.validateMidnightMakerOfferCallbacks)(tree.offers);
|
|
@@ -1845,7 +1878,7 @@ class MorphoMidnight {
|
|
|
1845
1878
|
chainId: this.chainId,
|
|
1846
1879
|
cancellations: params.cancellations ?? [],
|
|
1847
1880
|
deadline: params.deadline,
|
|
1848
|
-
metadata
|
|
1881
|
+
metadata,
|
|
1849
1882
|
publication: {
|
|
1850
1883
|
ratifier: data.ratifier,
|
|
1851
1884
|
root: data.tree.root,
|
|
@@ -1915,7 +1948,7 @@ class MorphoMidnight {
|
|
|
1915
1948
|
* @throws {InvalidMidnightHexInputError} when a cancellation group is not 32-byte hex.
|
|
1916
1949
|
* @throws {DuplicateMidnightGroupCancellationError} when a cancelled group appears more than once.
|
|
1917
1950
|
* @throws {MidnightReplacementGroupCancelledError} when a published group is also cancelled.
|
|
1918
|
-
* @throws {ExpiredDeadlineError} when `params.deadline` is at or before the
|
|
1951
|
+
* @throws {ExpiredDeadlineError} when `params.deadline` is at or before the reference timestamp (`params.now`, or the deprecated device-clock fallback), including zero or negative values.
|
|
1919
1952
|
* @example
|
|
1920
1953
|
* ```ts
|
|
1921
1954
|
* const output = await midnight.makeWithdraw({
|
|
@@ -1932,13 +1965,15 @@ class MorphoMidnight {
|
|
|
1932
1965
|
// Reject the zero account before preparing anything for it.
|
|
1933
1966
|
(0, validateMidnightAccount_js_1.validateMidnightAccount)("accountAddress", params.accountAddress);
|
|
1934
1967
|
// Fails before any API read or build when the deadline has already passed.
|
|
1935
|
-
|
|
1968
|
+
const now = params.now ?? morpho_ts_1.Time.timestamp();
|
|
1969
|
+
(0, deadline_js_1.validateMidnightDeadline)(params.deadline, now);
|
|
1936
1970
|
const tree = (0, encodeMidnightCalldata_js_1.wrapMidnightEncoding)("offers", () => midnight_sdk_1.Tree.from(params.offers));
|
|
1937
1971
|
// Reject the wrong exit intent before calling the mempool validation API.
|
|
1938
1972
|
(0, validateOfferSides_js_1.validateOfferSides)(tree.offers, false);
|
|
1939
1973
|
for (const [index, offer] of tree.offers.entries()) {
|
|
1940
|
-
if (!offer.reduceOnly)
|
|
1974
|
+
if (!offer.reduceOnly) {
|
|
1941
1975
|
throw new index_js_4.MidnightOfferNotReduceOnlyError({ index });
|
|
1976
|
+
}
|
|
1942
1977
|
}
|
|
1943
1978
|
return this.prepareBorrowOffers({ ...params, offers: tree });
|
|
1944
1979
|
}
|
|
@@ -2003,7 +2038,7 @@ class MorphoMidnight {
|
|
|
2003
2038
|
* @throws {InvalidMidnightHexInputError} when a cancellation group is not 32-byte hex.
|
|
2004
2039
|
* @throws {DuplicateMidnightGroupCancellationError} when a cancelled group appears more than once.
|
|
2005
2040
|
* @throws {MidnightReplacementGroupCancelledError} when a published group is also cancelled.
|
|
2006
|
-
* @throws {ExpiredDeadlineError} when `params.deadline` is at or before the
|
|
2041
|
+
* @throws {ExpiredDeadlineError} when `params.deadline` is at or before the reference timestamp (`params.now`, or the deprecated device-clock fallback), including zero or negative values.
|
|
2007
2042
|
* @example
|
|
2008
2043
|
* ```ts
|
|
2009
2044
|
* const output = await midnight.makeRepay({
|
|
@@ -2022,13 +2057,15 @@ class MorphoMidnight {
|
|
|
2022
2057
|
// Reject the zero account before preparing anything for it.
|
|
2023
2058
|
(0, validateMidnightAccount_js_1.validateMidnightAccount)("accountAddress", params.accountAddress);
|
|
2024
2059
|
// Fails before any API read or build when the deadline has already passed.
|
|
2025
|
-
|
|
2060
|
+
const now = params.now ?? morpho_ts_1.Time.timestamp();
|
|
2061
|
+
(0, deadline_js_1.validateMidnightDeadline)(params.deadline, now);
|
|
2026
2062
|
const tree = (0, encodeMidnightCalldata_js_1.wrapMidnightEncoding)("offers", () => midnight_sdk_1.Tree.from(params.offers));
|
|
2027
2063
|
// Reject the wrong exit intent before calling the mempool validation API.
|
|
2028
2064
|
(0, validateOfferSides_js_1.validateOfferSides)(tree.offers, true);
|
|
2029
2065
|
for (const [index, offer] of tree.offers.entries()) {
|
|
2030
|
-
if (!offer.reduceOnly)
|
|
2066
|
+
if (!offer.reduceOnly) {
|
|
2031
2067
|
throw new index_js_4.MidnightOfferNotReduceOnlyError({ index });
|
|
2068
|
+
}
|
|
2032
2069
|
}
|
|
2033
2070
|
return this.prepareLendOffers({ ...params, offers: tree });
|
|
2034
2071
|
}
|
|
@@ -2100,7 +2137,7 @@ class MorphoMidnight {
|
|
|
2100
2137
|
* @throws {MidnightReplacementGroupCancelledError} when a published group is also cancelled.
|
|
2101
2138
|
* @throws {InvalidMidnightHexInputError} when a cancellation group is not 32-byte hex.
|
|
2102
2139
|
* @throws {DuplicateMidnightGroupCancellationError} when a cancelled group appears more than once.
|
|
2103
|
-
* @throws {ExpiredDeadlineError} when `params.deadline` is at or before the
|
|
2140
|
+
* @throws {ExpiredDeadlineError} when `params.deadline` is at or before the reference timestamp (`params.now`, or the deprecated device-clock fallback), including zero or negative values.
|
|
2104
2141
|
* @example
|
|
2105
2142
|
* ```ts
|
|
2106
2143
|
* const output = await midnight.supplyCollateralMakeBorrow({
|
|
@@ -2115,11 +2152,13 @@ class MorphoMidnight {
|
|
|
2115
2152
|
* ```
|
|
2116
2153
|
*/
|
|
2117
2154
|
async supplyCollateralMakeBorrow(params) {
|
|
2155
|
+
const metadata = (0, metadata_js_1.resolveTransactionMetadata)(this.client.options.metadata, params.now);
|
|
2118
2156
|
(0, index_js_3.validateChainId)(this.client.viemClient.chain?.id, this.chainId);
|
|
2119
2157
|
// Reject the zero account before preparing anything for it.
|
|
2120
2158
|
(0, validateMidnightAccount_js_1.validateMidnightAccount)("accountAddress", params.accountAddress);
|
|
2121
2159
|
// Fails before any API read or build when the deadline has already passed.
|
|
2122
|
-
|
|
2160
|
+
const now = params.now ?? morpho_ts_1.Time.timestamp();
|
|
2161
|
+
(0, deadline_js_1.validateMidnightDeadline)(params.deadline, now);
|
|
2123
2162
|
const market = params.collateral.market instanceof midnight_sdk_1.MarketParams
|
|
2124
2163
|
? params.collateral.market
|
|
2125
2164
|
: midnight_sdk_1.MarketParams.from(params.collateral.market);
|
|
@@ -2145,7 +2184,7 @@ class MorphoMidnight {
|
|
|
2145
2184
|
nativeAmount: params.nativeAmount,
|
|
2146
2185
|
cancellations: params.cancellations ?? [],
|
|
2147
2186
|
deadline: params.deadline,
|
|
2148
|
-
metadata
|
|
2187
|
+
metadata,
|
|
2149
2188
|
publication: {
|
|
2150
2189
|
ratifier: data.ratifier,
|
|
2151
2190
|
root: data.tree.root,
|
|
@@ -2231,14 +2270,16 @@ class MorphoMidnight {
|
|
|
2231
2270
|
* ```
|
|
2232
2271
|
*/
|
|
2233
2272
|
redeem(params) {
|
|
2273
|
+
const metadata = (0, metadata_js_1.resolveTransactionMetadata)(this.client.options.metadata, params.now);
|
|
2234
2274
|
(0, index_js_3.validateChainId)(this.client.viemClient.chain?.id, this.chainId);
|
|
2235
2275
|
// Reject a malformed account here; the builder rejects the zero account.
|
|
2236
2276
|
(0, validateMidnightAccount_js_1.validateMidnightAddress)("accountAddress", params.accountAddress);
|
|
2237
2277
|
if (!params.positionData) {
|
|
2238
2278
|
throw new index_js_4.MissingAccrualPositionError();
|
|
2239
2279
|
}
|
|
2240
|
-
if (params.positionData.user != null)
|
|
2280
|
+
if (params.positionData.user != null) {
|
|
2241
2281
|
(0, validateMidnightAccount_js_1.validateMidnightAddress)("positionData.user", params.positionData.user);
|
|
2282
|
+
}
|
|
2242
2283
|
if (params.positionData.user == null ||
|
|
2243
2284
|
!(0, viem_1.isAddressEqual)(params.positionData.user, params.accountAddress)) {
|
|
2244
2285
|
throw new index_js_4.AccrualPositionUserMismatchError(params.positionData.user ?? "unbound", params.accountAddress);
|
|
@@ -2247,13 +2288,15 @@ class MorphoMidnight {
|
|
|
2247
2288
|
validateMarketData(market, this.chainId);
|
|
2248
2289
|
// Apply realized losses and continuous fees the way `Midnight._updatePosition` does before a
|
|
2249
2290
|
// withdrawal; never accrue to before the snapshot's `lastAccrual`.
|
|
2250
|
-
const
|
|
2291
|
+
const now = params.now ?? morpho_ts_1.Time.timestamp();
|
|
2292
|
+
const accrued = params.positionData.accrueInterest(blue_sdk_1.MathLib.max(now, params.positionData.lastAccrual));
|
|
2251
2293
|
const units = params.units ?? accrued.faceValue;
|
|
2252
2294
|
if (params.units !== undefined && units <= 0n) {
|
|
2253
2295
|
throw new index_js_4.NonPositiveInputError("units", units);
|
|
2254
2296
|
}
|
|
2255
|
-
if (units <= 0n)
|
|
2297
|
+
if (units <= 0n) {
|
|
2256
2298
|
throw new index_js_4.NoMidnightCreditToRedeemError(market.id);
|
|
2299
|
+
}
|
|
2257
2300
|
(0, validateMidnightBounds_js_1.validateMidnightUint128Field)("units", units);
|
|
2258
2301
|
if (accrued.credit < units) {
|
|
2259
2302
|
throw new index_js_4.MidnightRedeemExceedsCreditError({
|
|
@@ -2276,7 +2319,7 @@ class MorphoMidnight {
|
|
|
2276
2319
|
units,
|
|
2277
2320
|
onBehalf: params.accountAddress,
|
|
2278
2321
|
receiver: params.receiver,
|
|
2279
|
-
metadata
|
|
2322
|
+
metadata,
|
|
2280
2323
|
});
|
|
2281
2324
|
return {
|
|
2282
2325
|
getRequirements: async () => [],
|
|
@@ -2341,7 +2384,7 @@ class MorphoMidnight {
|
|
|
2341
2384
|
* during this method call, before the lazy output is returned.
|
|
2342
2385
|
* @throws {MidnightContractReceiverError} when `collateralReceiver` is a Midnight protocol
|
|
2343
2386
|
* contract or a market token contract.
|
|
2344
|
-
* @throws {ExpiredDeadlineError} when `params.deadline` is at or before the
|
|
2387
|
+
* @throws {ExpiredDeadlineError} when `params.deadline` is at or before the reference timestamp (`params.now`, or the deprecated device-clock fallback), including zero or negative values.
|
|
2345
2388
|
* @example
|
|
2346
2389
|
* ```ts
|
|
2347
2390
|
* // Close the position: repay all debt, withdraw all collateral.
|
|
@@ -2357,11 +2400,13 @@ class MorphoMidnight {
|
|
|
2357
2400
|
* ```
|
|
2358
2401
|
*/
|
|
2359
2402
|
repayWithdrawCollateral(params) {
|
|
2403
|
+
const metadata = (0, metadata_js_1.resolveTransactionMetadata)(this.client.options.metadata, params.now);
|
|
2360
2404
|
(0, index_js_3.validateChainId)(this.client.viemClient.chain?.id, this.chainId);
|
|
2361
2405
|
// Reject the zero account before preparing anything for it.
|
|
2362
2406
|
(0, validateMidnightAccount_js_1.validateMidnightAccount)("accountAddress", params.accountAddress);
|
|
2363
2407
|
// Fails before any API read or build when the deadline has already passed.
|
|
2364
|
-
|
|
2408
|
+
const now = params.now ?? morpho_ts_1.Time.timestamp();
|
|
2409
|
+
(0, deadline_js_1.validateMidnightDeadline)(params.deadline, now);
|
|
2365
2410
|
const market = params.marketData.params;
|
|
2366
2411
|
const tx = (0, index_js_1.midnightRepayWithdrawCollateral)({
|
|
2367
2412
|
chainId: this.chainId,
|
|
@@ -2371,7 +2416,7 @@ class MorphoMidnight {
|
|
|
2371
2416
|
collateralWithdrawals: params.collateralWithdrawals ?? [],
|
|
2372
2417
|
collateralReceiver: params.collateralReceiver ?? params.accountAddress,
|
|
2373
2418
|
deadline: params.deadline,
|
|
2374
|
-
metadata
|
|
2419
|
+
metadata,
|
|
2375
2420
|
});
|
|
2376
2421
|
validatePositionBinding({
|
|
2377
2422
|
positionData: params.positionData,
|
|
@@ -2379,24 +2424,7 @@ class MorphoMidnight {
|
|
|
2379
2424
|
marketData: params.marketData,
|
|
2380
2425
|
});
|
|
2381
2426
|
const collateralWithdrawals = params.collateralWithdrawals ?? [];
|
|
2382
|
-
const
|
|
2383
|
-
let withdrawAmount = 0n;
|
|
2384
|
-
for (const withdrawal of collateralWithdrawals) {
|
|
2385
|
-
// Reject unconfigured collateral indexes before updating postCollateral.
|
|
2386
|
-
midnight_sdk_1.MarketUtils.getCollateralByIndex(market, withdrawal.collateralIndex);
|
|
2387
|
-
const index = Number(withdrawal.collateralIndex);
|
|
2388
|
-
const available = postCollateral[index] ?? 0n;
|
|
2389
|
-
const amount = withdrawal.assets === viem_1.maxUint256 ? available : withdrawal.assets;
|
|
2390
|
-
if (amount > available) {
|
|
2391
|
-
throw new index_js_4.WithdrawExceedsCollateralError({
|
|
2392
|
-
withdrawAmount: amount,
|
|
2393
|
-
available,
|
|
2394
|
-
market: params.marketData.id,
|
|
2395
|
-
});
|
|
2396
|
-
}
|
|
2397
|
-
postCollateral[index] = available - amount;
|
|
2398
|
-
withdrawAmount += amount;
|
|
2399
|
-
}
|
|
2427
|
+
const { postCollateral, withdrawAmount } = getPostWithdrawalCollateral(params);
|
|
2400
2428
|
// The bundle must fill the whole assets target and the direct repay is capped at the debt, so a repay above it reverts `OutOfOffers()`.
|
|
2401
2429
|
if (params.repay.type === "assets" &&
|
|
2402
2430
|
params.repay.assets > params.positionData.debt) {
|
|
@@ -2414,11 +2442,11 @@ class MorphoMidnight {
|
|
|
2414
2442
|
limit: params.positionData.debt,
|
|
2415
2443
|
});
|
|
2416
2444
|
}
|
|
2417
|
-
|
|
2418
|
-
|
|
2419
|
-
|
|
2420
|
-
|
|
2421
|
-
|
|
2445
|
+
let postDebt = 0n;
|
|
2446
|
+
if (params.repay.type !== "full" &&
|
|
2447
|
+
params.positionData.debt > params.repay.assets) {
|
|
2448
|
+
postDebt = params.positionData.debt - params.repay.assets;
|
|
2449
|
+
}
|
|
2422
2450
|
if (collateralWithdrawals.length > 0 && postDebt > 0n) {
|
|
2423
2451
|
const maxSafeDebt = (0, index_js_3.getMidnightMaxSafeDebt)({
|
|
2424
2452
|
market: params.marketData,
|
|
@@ -2455,42 +2483,37 @@ class MorphoMidnight {
|
|
|
2455
2483
|
};
|
|
2456
2484
|
}
|
|
2457
2485
|
/**
|
|
2458
|
-
* Prepares
|
|
2486
|
+
* Prepares a full cancellation of one or more maker offer groups as a direct call to Midnight.
|
|
2459
2487
|
*
|
|
2460
|
-
*
|
|
2461
|
-
* `
|
|
2488
|
+
* One group builds a bare `setConsumed(group, maxUint128, accountAddress)`. Two or more groups
|
|
2489
|
+
* build one Midnight `multicall` of such calls, in list order, which cancels every group or
|
|
2490
|
+
* none. Only the single-group transaction is matchable by a wallet policy that allows
|
|
2491
|
+
* `setConsumed` by method name; cancel one group per transaction when the signer's policy names
|
|
2492
|
+
* `setConsumed`.
|
|
2462
2493
|
*
|
|
2463
|
-
*
|
|
2464
|
-
*
|
|
2465
|
-
*
|
|
2466
|
-
*
|
|
2467
|
-
*
|
|
2468
|
-
*
|
|
2469
|
-
*
|
|
2470
|
-
*
|
|
2471
|
-
*
|
|
2472
|
-
*
|
|
2473
|
-
*
|
|
2474
|
-
*
|
|
2475
|
-
* @
|
|
2476
|
-
* @throws {ChainIdMismatchError} when the client targets another chain, or from
|
|
2477
|
-
* `getRequirements()` when the RPC reports another chain via `eth_chainId`.
|
|
2478
|
-
* @throws {MidnightCalldataEncodingError} when an input cannot be ABI-encoded, such as an out-of-range integer.
|
|
2479
|
-
* @throws {viem.BaseError} from `getRequirements()` when an `eth_chainId` request or requirement
|
|
2480
|
-
* RPC read fails.
|
|
2481
|
-
* @throws {UnsupportedChainIdError} when the chain is absent from the address registry.
|
|
2482
|
-
* @throws {UnknownAddressError} when the chain has no `midnightBundlesV2` deployment.
|
|
2483
|
-
* @throws {EmptyMidnightGroupCancellationsError} when no groups are provided.
|
|
2494
|
+
* Nothing is required before sending: no Midnight authorization, approval, signature or
|
|
2495
|
+
* deadline. Cancellation is per group and always full; it does not unratify roots or revoke
|
|
2496
|
+
* authorizations, and cancelling a group again succeeds.
|
|
2497
|
+
*
|
|
2498
|
+
* @param params - Maker account and the offer groups to cancel.
|
|
2499
|
+
* @param params.accountAddress - Maker whose groups are cancelled. The maker, or an operator it
|
|
2500
|
+
* authorized on Midnight, must send the transaction; a transaction from any other account
|
|
2501
|
+
* reverts `Unauthorized()` and changes no group.
|
|
2502
|
+
* @param params.groups - Nonempty list of distinct 32-byte offer groups to cancel.
|
|
2503
|
+
* @param params.now - Optional reference timestamp used to resolve `metadata.timestamp: true`.
|
|
2504
|
+
* @returns A handle whose `getRequirements()` resolves to an empty list without reading the
|
|
2505
|
+
* chain, and whose synchronous `buildTx()` returns the transaction targeting `Midnight`.
|
|
2506
|
+
* @throws {ChainIdMismatchError} when the client targets another chain.
|
|
2484
2507
|
* @throws {MidnightInvalidAccountAddressError} when `accountAddress` is malformed or zero.
|
|
2485
|
-
* @throws {
|
|
2508
|
+
* @throws {EmptyMidnightGroupCancellationsError} when no groups are provided.
|
|
2509
|
+
* @throws {InvalidMidnightHexInputError} when a group is not 32-byte hex.
|
|
2486
2510
|
* @throws {DuplicateMidnightGroupCancellationError} when a group appears more than once.
|
|
2487
|
-
* @throws {
|
|
2488
|
-
* @throws {
|
|
2489
|
-
* @throws {ExpiredDeadlineError} when `params.deadline` is at or before the local clock (`Time.timestamp()`), including zero or negative values.
|
|
2511
|
+
* @throws {UnsupportedChainIdError} when the chain is absent from the address registry.
|
|
2512
|
+
* @throws {UnknownAddressError} when the chain has no `midnight` deployment.
|
|
2490
2513
|
* @example
|
|
2491
2514
|
* ```ts
|
|
2492
2515
|
* import { morphoViemExtension } from "@morpho-org/morpho-sdk";
|
|
2493
|
-
* import { createPublicClient, http,
|
|
2516
|
+
* import { createPublicClient, http, type Address, type Hex } from "viem";
|
|
2494
2517
|
* import { base } from "viem/chains";
|
|
2495
2518
|
*
|
|
2496
2519
|
* declare const maker: Address;
|
|
@@ -2499,30 +2522,27 @@ class MorphoMidnight {
|
|
|
2499
2522
|
* morphoViemExtension(),
|
|
2500
2523
|
* );
|
|
2501
2524
|
* const midnight = client.morpho.midnight(base.id);
|
|
2502
|
-
* const output = midnight.cancelOffers({
|
|
2503
|
-
*
|
|
2504
|
-
*
|
|
2505
|
-
* deadline: maxUint256,
|
|
2506
|
-
* });
|
|
2525
|
+
* const output = midnight.cancelOffers({ accountAddress: maker, groups: [group] });
|
|
2526
|
+
* await output.getRequirements(); // => []
|
|
2527
|
+
* const tx = output.buildTx(); // calldata: setConsumed(group, maxUint128, maker)
|
|
2507
2528
|
* ```
|
|
2508
2529
|
*/
|
|
2509
2530
|
cancelOffers(params) {
|
|
2531
|
+
const metadata = (0, metadata_js_1.resolveTransactionMetadata)(this.client.options.metadata, params.now);
|
|
2510
2532
|
(0, index_js_3.validateChainId)(this.client.viemClient.chain?.id, this.chainId);
|
|
2511
2533
|
const { accountAddress } = params;
|
|
2512
2534
|
if (!(0, viem_1.isAddress)(accountAddress) ||
|
|
2513
2535
|
(0, viem_1.isAddressEqual)(accountAddress, viem_1.zeroAddress)) {
|
|
2514
2536
|
throw new index_js_4.MidnightInvalidAccountAddressError(accountAddress);
|
|
2515
2537
|
}
|
|
2516
|
-
|
|
2517
|
-
(0, deadline_js_1.validateMidnightDeadline)(params.deadline);
|
|
2518
|
-
const tx = (0, index_js_1.midnightCancelAndMake)({
|
|
2538
|
+
const tx = (0, index_js_1.midnightCancelOffers)({
|
|
2519
2539
|
chainId: this.chainId,
|
|
2520
|
-
|
|
2521
|
-
|
|
2522
|
-
metadata
|
|
2540
|
+
groups: params.groups,
|
|
2541
|
+
onBehalf: accountAddress,
|
|
2542
|
+
metadata,
|
|
2523
2543
|
});
|
|
2524
2544
|
return {
|
|
2525
|
-
getRequirements: () =>
|
|
2545
|
+
getRequirements: async () => [],
|
|
2526
2546
|
buildTx: () => tx,
|
|
2527
2547
|
};
|
|
2528
2548
|
}
|