@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
|
@@ -60,6 +60,7 @@ export interface MidnightMakerOfferState {
|
|
|
60
60
|
* @returns Nothing when every offer can be published.
|
|
61
61
|
* @throws {MidnightOfferExpiredError} when expiry is not later than `now`.
|
|
62
62
|
* @throws {MidnightOfferExpiryAfterMaturityError} when expiry exceeds market maturity.
|
|
63
|
+
* @throws {UnknownDataError} when an offer's state or rate entry is missing.
|
|
63
64
|
* @throws {MidnightOfferGroupConsumedError} when the group's remaining cap is zero.
|
|
64
65
|
* @throws {MidnightOfferTickSpacingError} when the tick is inaccessible.
|
|
65
66
|
* @throws {MidnightOfferContinuousFeeCapBelowMarketFeeError} when the market fee exceeds the offer cap.
|
|
@@ -98,6 +99,7 @@ export declare function validateMidnightMakerOfferStates(params: {
|
|
|
98
99
|
* @throws {ChainIdMismatchError} when the client declares, or its RPC reports via `eth_chainId`,
|
|
99
100
|
* another chain than `params.chainId`.
|
|
100
101
|
* @throws {viem.BaseError} when block, contract, or oracle-code reads fail.
|
|
102
|
+
* @throws {UnknownDataError} when required publication state is missing.
|
|
101
103
|
* @example
|
|
102
104
|
* ```ts
|
|
103
105
|
* const { states, now } = await fetchMidnightMakerOfferStates({
|
|
@@ -4,6 +4,7 @@ exports.offerMarketParams = void 0;
|
|
|
4
4
|
exports.validateMidnightMakerOfferStates = validateMidnightMakerOfferStates;
|
|
5
5
|
exports.fetchMidnightMakerOfferStates = fetchMidnightMakerOfferStates;
|
|
6
6
|
exports.validateMidnightMakerOfferCallbacks = validateMidnightMakerOfferCallbacks;
|
|
7
|
+
const blue_sdk_1 = require("@morpho-org/blue-sdk");
|
|
7
8
|
const midnight_sdk_1 = require("@morpho-org/midnight-sdk");
|
|
8
9
|
const morpho_ts_1 = require("@morpho-org/morpho-ts");
|
|
9
10
|
const viem_1 = require("viem");
|
|
@@ -12,9 +13,103 @@ const validateClientChainId_js_1 = require("../../actions/requirements/validateC
|
|
|
12
13
|
const midnightPublicationError_js_1 = require("../../types/midnightPublicationError.js");
|
|
13
14
|
// Midnight.sol `touchMarket` rejects markets maturing more than 100 years after creation.
|
|
14
15
|
const MAX_TIME_TO_MATURITY = 100n * 365n * 86400n;
|
|
16
|
+
function requirePublicationState(value) {
|
|
17
|
+
if (value === undefined) {
|
|
18
|
+
throw new blue_sdk_1.UnknownDataError("Missing Midnight publication state.");
|
|
19
|
+
}
|
|
20
|
+
return value;
|
|
21
|
+
}
|
|
15
22
|
/** @internal */
|
|
16
23
|
const offerMarketParams = (offer) => "params" in offer.market ? offer.market.params : offer.market;
|
|
17
24
|
exports.offerMarketParams = offerMarketParams;
|
|
25
|
+
function validateOfferTerms({ offer, state, index, marketId, }) {
|
|
26
|
+
const capacity = BigInt(offer.maxAssets) > 0n
|
|
27
|
+
? BigInt(offer.maxAssets)
|
|
28
|
+
: BigInt(offer.maxUnits);
|
|
29
|
+
if (state.consumed >= capacity) {
|
|
30
|
+
throw new midnightPublicationError_js_1.MidnightOfferGroupConsumedError({
|
|
31
|
+
index,
|
|
32
|
+
group: offer.group,
|
|
33
|
+
consumed: state.consumed,
|
|
34
|
+
});
|
|
35
|
+
}
|
|
36
|
+
const tickSpacing = state.tickSpacing || Number(midnight_sdk_1.DEFAULT_TICK_SPACING);
|
|
37
|
+
if (BigInt(offer.tick) % BigInt(tickSpacing) !== 0n) {
|
|
38
|
+
throw new midnightPublicationError_js_1.MidnightOfferTickSpacingError({
|
|
39
|
+
index,
|
|
40
|
+
tick: BigInt(offer.tick),
|
|
41
|
+
tickSpacing,
|
|
42
|
+
});
|
|
43
|
+
}
|
|
44
|
+
if (BigInt(offer.continuousFeeCap) < state.continuousFee) {
|
|
45
|
+
throw new midnightPublicationError_js_1.MidnightOfferContinuousFeeCapBelowMarketFeeError({
|
|
46
|
+
index,
|
|
47
|
+
marketId,
|
|
48
|
+
continuousFeeCap: BigInt(offer.continuousFeeCap),
|
|
49
|
+
continuousFee: state.continuousFee,
|
|
50
|
+
});
|
|
51
|
+
}
|
|
52
|
+
if (!offer.buy && BigInt(offer.tick) === 0n) {
|
|
53
|
+
throw new midnightPublicationError_js_1.MidnightOfferZeroPriceSellError({ index });
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
function validateOfferRate({ offer, state, index, rate, now, expiry, }) {
|
|
57
|
+
let timestamp = offer.buy ? expiry : morpho_ts_1.MathLib.max(now, BigInt(offer.start));
|
|
58
|
+
if (!offer.buy && rate > 0n) {
|
|
59
|
+
const maxTimeToMaturity = (viem_1.maxUint256 - morpho_ts_1.MathLib.WAD * morpho_ts_1.MathLib.WAD - morpho_ts_1.MathLib.WAD + 1n) / rate;
|
|
60
|
+
const marketMaturity = state.market.params.maturity;
|
|
61
|
+
timestamp = morpho_ts_1.MathLib.max(timestamp, marketMaturity - maxTimeToMaturity);
|
|
62
|
+
if (timestamp > expiry || timestamp > marketMaturity) {
|
|
63
|
+
throw new midnightPublicationError_js_1.MidnightOfferRateBoundUnreachableError({
|
|
64
|
+
index,
|
|
65
|
+
rate,
|
|
66
|
+
tick: BigInt(offer.tick),
|
|
67
|
+
});
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
if (!midnight_sdk_1.RateRatifierV1.isPriceAcceptable({
|
|
71
|
+
offer: { ...offer, market: state.market },
|
|
72
|
+
rate,
|
|
73
|
+
timestamp,
|
|
74
|
+
})) {
|
|
75
|
+
throw new midnightPublicationError_js_1.MidnightOfferRateBoundUnreachableError({
|
|
76
|
+
index,
|
|
77
|
+
rate,
|
|
78
|
+
tick: BigInt(offer.tick),
|
|
79
|
+
});
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
function validateUncreatedMarket({ state, index, offerMarket, maturity, expiry, now, marketCreationTime, }) {
|
|
83
|
+
const marketCreationTimestamp = marketCreationTime === "now" ? now : expiry;
|
|
84
|
+
const maxMaturity = marketCreationTimestamp + MAX_TIME_TO_MATURITY;
|
|
85
|
+
if (maturity > maxMaturity) {
|
|
86
|
+
throw new midnightPublicationError_js_1.MidnightMarketMaturityTooFarError({
|
|
87
|
+
index,
|
|
88
|
+
maturity,
|
|
89
|
+
maxMaturity,
|
|
90
|
+
});
|
|
91
|
+
}
|
|
92
|
+
for (const [collateralIndex, collateral,] of offerMarket.collateralParams.entries()) {
|
|
93
|
+
if (!state.lltvEnabled[collateralIndex]) {
|
|
94
|
+
throw new midnightPublicationError_js_1.MidnightMarketLltvNotEnabledError({
|
|
95
|
+
index,
|
|
96
|
+
lltv: BigInt(collateral.lltv),
|
|
97
|
+
});
|
|
98
|
+
}
|
|
99
|
+
if (!state.liquidationCursorEnabled[collateralIndex]) {
|
|
100
|
+
throw new midnightPublicationError_js_1.MidnightMarketLiquidationCursorNotEnabledError({
|
|
101
|
+
index,
|
|
102
|
+
liquidationCursor: BigInt(collateral.liquidationCursor),
|
|
103
|
+
});
|
|
104
|
+
}
|
|
105
|
+
if (!state.oracleHasCode[collateralIndex]) {
|
|
106
|
+
throw new midnightPublicationError_js_1.MidnightMarketOracleWithoutCodeError({
|
|
107
|
+
index,
|
|
108
|
+
oracle: collateral.oracle,
|
|
109
|
+
});
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
}
|
|
18
113
|
/**
|
|
19
114
|
* Rejects the first maker offer that cannot be filled at or after publication.
|
|
20
115
|
*
|
|
@@ -31,6 +126,7 @@ exports.offerMarketParams = offerMarketParams;
|
|
|
31
126
|
* @returns Nothing when every offer can be published.
|
|
32
127
|
* @throws {MidnightOfferExpiredError} when expiry is not later than `now`.
|
|
33
128
|
* @throws {MidnightOfferExpiryAfterMaturityError} when expiry exceeds market maturity.
|
|
129
|
+
* @throws {UnknownDataError} when an offer's state or rate entry is missing.
|
|
34
130
|
* @throws {MidnightOfferGroupConsumedError} when the group's remaining cap is zero.
|
|
35
131
|
* @throws {MidnightOfferTickSpacingError} when the tick is inaccessible.
|
|
36
132
|
* @throws {MidnightOfferContinuousFeeCapBelowMarketFeeError} when the market fee exceeds the offer cap.
|
|
@@ -50,7 +146,7 @@ exports.offerMarketParams = offerMarketParams;
|
|
|
50
146
|
function validateMidnightMakerOfferStates(params) {
|
|
51
147
|
const rateEntries = params.tree.type === "rateV1" ? params.tree.entries : [];
|
|
52
148
|
params.tree.offers.forEach((offer, index) => {
|
|
53
|
-
const state = params.states[index];
|
|
149
|
+
const state = requirePublicationState(params.states[index]);
|
|
54
150
|
const expiry = BigInt(offer.expiry);
|
|
55
151
|
const offerMarket = (0, exports.offerMarketParams)(offer);
|
|
56
152
|
const maturity = BigInt(offerMarket.maturity);
|
|
@@ -69,63 +165,12 @@ function validateMidnightMakerOfferStates(params) {
|
|
|
69
165
|
maturity,
|
|
70
166
|
});
|
|
71
167
|
}
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
: BigInt(offer.maxUnits);
|
|
75
|
-
if (state.consumed >= capacity) {
|
|
76
|
-
throw new midnightPublicationError_js_1.MidnightOfferGroupConsumedError({
|
|
77
|
-
index,
|
|
78
|
-
group: offer.group,
|
|
79
|
-
consumed: state.consumed,
|
|
80
|
-
});
|
|
81
|
-
}
|
|
82
|
-
const tickSpacing = state.tickSpacing || Number(midnight_sdk_1.DEFAULT_TICK_SPACING);
|
|
83
|
-
if (BigInt(offer.tick) % BigInt(tickSpacing) !== 0n) {
|
|
84
|
-
throw new midnightPublicationError_js_1.MidnightOfferTickSpacingError({
|
|
85
|
-
index,
|
|
86
|
-
tick: BigInt(offer.tick),
|
|
87
|
-
tickSpacing,
|
|
88
|
-
});
|
|
89
|
-
}
|
|
90
|
-
if (BigInt(offer.continuousFeeCap) < state.continuousFee) {
|
|
91
|
-
throw new midnightPublicationError_js_1.MidnightOfferContinuousFeeCapBelowMarketFeeError({
|
|
92
|
-
index,
|
|
93
|
-
marketId,
|
|
94
|
-
continuousFeeCap: BigInt(offer.continuousFeeCap),
|
|
95
|
-
continuousFee: state.continuousFee,
|
|
96
|
-
});
|
|
97
|
-
}
|
|
98
|
-
if (!offer.buy && BigInt(offer.tick) === 0n) {
|
|
99
|
-
throw new midnightPublicationError_js_1.MidnightOfferZeroPriceSellError({ index });
|
|
100
|
-
}
|
|
168
|
+
// Reject inaccessible terms before evaluating rate reachability.
|
|
169
|
+
validateOfferTerms({ offer, state, index, marketId });
|
|
101
170
|
if (params.tree.type === "rateV1") {
|
|
102
|
-
const rate = BigInt(rateEntries[index].rate);
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
: morpho_ts_1.MathLib.max(params.now, BigInt(offer.start));
|
|
106
|
-
if (!offer.buy && rate > 0n) {
|
|
107
|
-
const maxTimeToMaturity = (viem_1.maxUint256 - morpho_ts_1.MathLib.WAD * morpho_ts_1.MathLib.WAD - morpho_ts_1.MathLib.WAD + 1n) / rate;
|
|
108
|
-
const marketMaturity = state.market.params.maturity;
|
|
109
|
-
timestamp = morpho_ts_1.MathLib.max(timestamp, marketMaturity - maxTimeToMaturity);
|
|
110
|
-
if (timestamp > expiry || timestamp > marketMaturity) {
|
|
111
|
-
throw new midnightPublicationError_js_1.MidnightOfferRateBoundUnreachableError({
|
|
112
|
-
index,
|
|
113
|
-
rate,
|
|
114
|
-
tick: BigInt(offer.tick),
|
|
115
|
-
});
|
|
116
|
-
}
|
|
117
|
-
}
|
|
118
|
-
if (!midnight_sdk_1.RateRatifierV1.isPriceAcceptable({
|
|
119
|
-
offer: { ...offer, market: state.market },
|
|
120
|
-
rate,
|
|
121
|
-
timestamp,
|
|
122
|
-
})) {
|
|
123
|
-
throw new midnightPublicationError_js_1.MidnightOfferRateBoundUnreachableError({
|
|
124
|
-
index,
|
|
125
|
-
rate,
|
|
126
|
-
tick: BigInt(offer.tick),
|
|
127
|
-
});
|
|
128
|
-
}
|
|
171
|
+
const rate = BigInt(requirePublicationState(rateEntries[index]).rate);
|
|
172
|
+
// Reject rate bounds that cannot become fillable.
|
|
173
|
+
validateOfferRate({ offer, state, index, rate, now: params.now, expiry });
|
|
129
174
|
}
|
|
130
175
|
if (offer.reduceOnly && offer.buy && state.debt === 0n) {
|
|
131
176
|
throw new midnightPublicationError_js_1.MidnightOfferNoDebtError({ index, marketId });
|
|
@@ -134,35 +179,16 @@ function validateMidnightMakerOfferStates(params) {
|
|
|
134
179
|
throw new midnightPublicationError_js_1.MidnightOfferNoCreditError({ index, marketId });
|
|
135
180
|
}
|
|
136
181
|
if (state.tickSpacing === 0) {
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
if (!state.lltvEnabled[collateralIndex]) {
|
|
148
|
-
throw new midnightPublicationError_js_1.MidnightMarketLltvNotEnabledError({
|
|
149
|
-
index,
|
|
150
|
-
lltv: BigInt(collateral.lltv),
|
|
151
|
-
});
|
|
152
|
-
}
|
|
153
|
-
if (!state.liquidationCursorEnabled[collateralIndex]) {
|
|
154
|
-
throw new midnightPublicationError_js_1.MidnightMarketLiquidationCursorNotEnabledError({
|
|
155
|
-
index,
|
|
156
|
-
liquidationCursor: BigInt(collateral.liquidationCursor),
|
|
157
|
-
});
|
|
158
|
-
}
|
|
159
|
-
if (!state.oracleHasCode[collateralIndex]) {
|
|
160
|
-
throw new midnightPublicationError_js_1.MidnightMarketOracleWithoutCodeError({
|
|
161
|
-
index,
|
|
162
|
-
oracle: collateral.oracle,
|
|
163
|
-
});
|
|
164
|
-
}
|
|
165
|
-
}
|
|
182
|
+
// Reject market parameters that cannot be created.
|
|
183
|
+
validateUncreatedMarket({
|
|
184
|
+
state,
|
|
185
|
+
index,
|
|
186
|
+
offerMarket,
|
|
187
|
+
maturity,
|
|
188
|
+
expiry,
|
|
189
|
+
now: params.now,
|
|
190
|
+
marketCreationTime: params.marketCreationTime,
|
|
191
|
+
});
|
|
166
192
|
}
|
|
167
193
|
});
|
|
168
194
|
}
|
|
@@ -182,6 +208,7 @@ function validateMidnightMakerOfferStates(params) {
|
|
|
182
208
|
* @throws {ChainIdMismatchError} when the client declares, or its RPC reports via `eth_chainId`,
|
|
183
209
|
* another chain than `params.chainId`.
|
|
184
210
|
* @throws {viem.BaseError} when block, contract, or oracle-code reads fail.
|
|
211
|
+
* @throws {UnknownDataError} when required publication state is missing.
|
|
185
212
|
* @example
|
|
186
213
|
* ```ts
|
|
187
214
|
* const { states, now } = await fetchMidnightMakerOfferStates({
|
|
@@ -196,21 +223,65 @@ async function fetchMidnightMakerOfferStates(params) {
|
|
|
196
223
|
const blockNumber = params.blockNumber ?? (await (0, actions_1.getBlockNumber)(params.client));
|
|
197
224
|
const block = await (0, actions_1.getBlock)(params.client, { blockNumber });
|
|
198
225
|
const midnight = (0, morpho_ts_1.getChainAddress)(params.chainId, "midnight");
|
|
226
|
+
const targets = collectPublicationReadTargets(params.tree);
|
|
227
|
+
const { collaterals } = targets;
|
|
228
|
+
const values = await readPublicationContractState({
|
|
229
|
+
client: params.client,
|
|
230
|
+
midnight,
|
|
231
|
+
blockNumber,
|
|
232
|
+
targets,
|
|
233
|
+
});
|
|
234
|
+
const { marketById, consumedByGroup, positionByOwner, collateralStateByMarket, } = indexPublicationContractState({ targets, values });
|
|
235
|
+
const codeByOracle = new Map(await Promise.all([...new Set(collaterals.map(({ oracleKey }) => oracleKey))].map(async (oracleKey) => [
|
|
236
|
+
oracleKey,
|
|
237
|
+
await (0, actions_1.getCode)(params.client, {
|
|
238
|
+
address: requirePublicationState(collaterals.find(({ oracleKey: key }) => key === oracleKey)).collateral.oracle,
|
|
239
|
+
blockNumber,
|
|
240
|
+
}),
|
|
241
|
+
])));
|
|
242
|
+
const states = params.tree.offers.map((offer) => {
|
|
243
|
+
const id = midnight_sdk_1.MarketUtils.toId(offer.market);
|
|
244
|
+
const market = requirePublicationState(marketById.get(id.toLowerCase()));
|
|
245
|
+
const groupKey = `${offer.maker.toLowerCase()}:${offer.group.toLowerCase()}`;
|
|
246
|
+
const owner = requirePublicationState(positionByOwner.get(`${id.toLowerCase()}:${offer.maker.toLowerCase()}`));
|
|
247
|
+
const uncreated = market.tickSpacing === 0;
|
|
248
|
+
const collateralStates = uncreated
|
|
249
|
+
? requirePublicationState(collateralStateByMarket.get(id.toLowerCase()))
|
|
250
|
+
: [];
|
|
251
|
+
return {
|
|
252
|
+
consumed: requirePublicationState(consumedByGroup.get(groupKey)),
|
|
253
|
+
tickSpacing: market.tickSpacing,
|
|
254
|
+
continuousFee: BigInt(market.continuousFee),
|
|
255
|
+
credit: owner.credit,
|
|
256
|
+
debt: owner.debt,
|
|
257
|
+
market,
|
|
258
|
+
lltvEnabled: collateralStates.map(({ lltvEnabled }) => lltvEnabled),
|
|
259
|
+
liquidationCursorEnabled: collateralStates.map(({ liquidationCursorEnabled }) => liquidationCursorEnabled),
|
|
260
|
+
oracleHasCode: uncreated
|
|
261
|
+
? (0, exports.offerMarketParams)(offer).collateralParams.map((collateral) => codeByOracle.get(collateral.oracle.toLowerCase()) !== undefined &&
|
|
262
|
+
codeByOracle.get(collateral.oracle.toLowerCase()) !== "0x")
|
|
263
|
+
: [],
|
|
264
|
+
};
|
|
265
|
+
});
|
|
266
|
+
return { states, now: block.timestamp };
|
|
267
|
+
}
|
|
268
|
+
/** Deduplicates the market, group, owner and collateral reads for a maker tree. @internal */
|
|
269
|
+
function collectPublicationReadTargets(tree) {
|
|
199
270
|
const markets = [
|
|
200
|
-
...new Map(
|
|
271
|
+
...new Map(tree.offers.map((offer) => {
|
|
201
272
|
const market = midnight_sdk_1.MarketParams.from((0, exports.offerMarketParams)(offer));
|
|
202
273
|
const id = midnight_sdk_1.MarketUtils.toId(market);
|
|
203
274
|
return [id.toLowerCase(), { id, market }];
|
|
204
275
|
})).values(),
|
|
205
276
|
];
|
|
206
277
|
const groups = [
|
|
207
|
-
...new Map(
|
|
278
|
+
...new Map(tree.offers.map((offer) => [
|
|
208
279
|
`${offer.maker.toLowerCase()}:${offer.group.toLowerCase()}`,
|
|
209
280
|
{ maker: offer.maker, group: offer.group },
|
|
210
281
|
])).values(),
|
|
211
282
|
];
|
|
212
283
|
const owners = [
|
|
213
|
-
...new Map(
|
|
284
|
+
...new Map(tree.offers.map((offer) => {
|
|
214
285
|
const id = midnight_sdk_1.MarketUtils.toId(offer.market);
|
|
215
286
|
return [
|
|
216
287
|
`${id.toLowerCase()}:${offer.maker.toLowerCase()}`,
|
|
@@ -229,50 +300,55 @@ async function fetchMidnightMakerOfferStates(params) {
|
|
|
229
300
|
market.loanToken,
|
|
230
301
|
])).values(),
|
|
231
302
|
];
|
|
232
|
-
|
|
233
|
-
|
|
303
|
+
return { markets, groups, owners, collaterals, defaultFeeTokens };
|
|
304
|
+
}
|
|
305
|
+
/** Reads contract state concurrently at the pinned publication block. @internal */
|
|
306
|
+
async function readPublicationContractState({ client, midnight, blockNumber, targets, }) {
|
|
307
|
+
const { markets, groups, owners, collaterals, defaultFeeTokens } = targets;
|
|
308
|
+
return Promise.all([
|
|
309
|
+
Promise.all(markets.map(({ id }) => (0, actions_1.readContract)(client, {
|
|
234
310
|
address: midnight,
|
|
235
311
|
abi: midnight_sdk_1.midnightAbi,
|
|
236
312
|
functionName: "marketState",
|
|
237
313
|
args: [id],
|
|
238
314
|
blockNumber,
|
|
239
315
|
}))),
|
|
240
|
-
Promise.all(groups.map(({ maker, group }) => (0, actions_1.readContract)(
|
|
316
|
+
Promise.all(groups.map(({ maker, group }) => (0, actions_1.readContract)(client, {
|
|
241
317
|
address: midnight,
|
|
242
318
|
abi: midnight_sdk_1.midnightAbi,
|
|
243
319
|
functionName: "consumed",
|
|
244
320
|
args: [maker, group],
|
|
245
321
|
blockNumber,
|
|
246
322
|
}))),
|
|
247
|
-
Promise.all(owners.map(({ id, maker }) => (0, actions_1.readContract)(
|
|
323
|
+
Promise.all(owners.map(({ id, maker }) => (0, actions_1.readContract)(client, {
|
|
248
324
|
address: midnight,
|
|
249
325
|
abi: midnight_sdk_1.midnightAbi,
|
|
250
326
|
functionName: "credit",
|
|
251
327
|
args: [id, maker],
|
|
252
328
|
blockNumber,
|
|
253
329
|
}))),
|
|
254
|
-
Promise.all(owners.map(({ id, maker }) => (0, actions_1.readContract)(
|
|
330
|
+
Promise.all(owners.map(({ id, maker }) => (0, actions_1.readContract)(client, {
|
|
255
331
|
address: midnight,
|
|
256
332
|
abi: midnight_sdk_1.midnightAbi,
|
|
257
333
|
functionName: "debt",
|
|
258
334
|
args: [id, maker],
|
|
259
335
|
blockNumber,
|
|
260
336
|
}))),
|
|
261
|
-
Promise.all(defaultFeeTokens.map((loanToken) => (0, actions_1.readContract)(
|
|
337
|
+
Promise.all(defaultFeeTokens.map((loanToken) => (0, actions_1.readContract)(client, {
|
|
262
338
|
address: midnight,
|
|
263
339
|
abi: midnight_sdk_1.midnightAbi,
|
|
264
340
|
functionName: "defaultContinuousFee",
|
|
265
341
|
args: [loanToken],
|
|
266
342
|
blockNumber,
|
|
267
343
|
}))),
|
|
268
|
-
Promise.all(collaterals.map(({ collateral }) => (0, actions_1.readContract)(
|
|
344
|
+
Promise.all(collaterals.map(({ collateral }) => (0, actions_1.readContract)(client, {
|
|
269
345
|
address: midnight,
|
|
270
346
|
abi: midnight_sdk_1.midnightAbi,
|
|
271
347
|
functionName: "isLltvEnabled",
|
|
272
348
|
args: [collateral.lltv],
|
|
273
349
|
blockNumber,
|
|
274
350
|
}))),
|
|
275
|
-
Promise.all(collaterals.map(({ collateral }) => (0, actions_1.readContract)(
|
|
351
|
+
Promise.all(collaterals.map(({ collateral }) => (0, actions_1.readContract)(client, {
|
|
276
352
|
address: midnight,
|
|
277
353
|
abi: midnight_sdk_1.midnightAbi,
|
|
278
354
|
functionName: "isLiquidationCursorEnabled",
|
|
@@ -280,14 +356,19 @@ async function fetchMidnightMakerOfferStates(params) {
|
|
|
280
356
|
blockNumber,
|
|
281
357
|
}))),
|
|
282
358
|
]);
|
|
359
|
+
}
|
|
360
|
+
/** Indexes validated contract results for per-offer publication state. @internal */
|
|
361
|
+
function indexPublicationContractState({ targets, values, }) {
|
|
362
|
+
const { markets, groups, owners, collaterals, defaultFeeTokens } = targets;
|
|
363
|
+
const [marketStates, consumedValues, creditValues, debtValues, defaultFees, lltvEnabledByCollateral, liquidationCursorEnabledByCollateral,] = values;
|
|
283
364
|
const defaultFeeByLoanToken = new Map(defaultFeeTokens.map((loanToken, index) => [
|
|
284
365
|
loanToken.toLowerCase(),
|
|
285
|
-
defaultFees[index],
|
|
366
|
+
requirePublicationState(defaultFees[index]),
|
|
286
367
|
]));
|
|
287
368
|
const marketById = new Map(markets.map(({ id, market: marketParams }, index) => {
|
|
288
|
-
const [totalUnits, lossFactor, withdrawable, continuousFeeCredit, fee0, fee1, fee2, fee3, fee4, fee5, fee6, continuousFee, tickSpacing,] = marketStates[index];
|
|
369
|
+
const [totalUnits, lossFactor, withdrawable, continuousFeeCredit, fee0, fee1, fee2, fee3, fee4, fee5, fee6, continuousFee, tickSpacing,] = requirePublicationState(marketStates[index]);
|
|
289
370
|
const effectiveContinuousFee = tickSpacing === 0
|
|
290
|
-
? defaultFeeByLoanToken.get(marketParams.loanToken.toLowerCase())
|
|
371
|
+
? requirePublicationState(defaultFeeByLoanToken.get(marketParams.loanToken.toLowerCase()))
|
|
291
372
|
: continuousFee;
|
|
292
373
|
return [
|
|
293
374
|
id.toLowerCase(),
|
|
@@ -305,58 +386,32 @@ async function fetchMidnightMakerOfferStates(params) {
|
|
|
305
386
|
}));
|
|
306
387
|
const consumedByGroup = new Map(groups.map(({ maker, group }, index) => [
|
|
307
388
|
`${maker.toLowerCase()}:${group.toLowerCase()}`,
|
|
308
|
-
consumedValues[index],
|
|
389
|
+
requirePublicationState(consumedValues[index]),
|
|
309
390
|
]));
|
|
310
391
|
const positionByOwner = new Map(owners.map(({ id, maker }, index) => [
|
|
311
392
|
`${id.toLowerCase()}:${maker.toLowerCase()}`,
|
|
312
393
|
{
|
|
313
|
-
credit: creditValues[index],
|
|
314
|
-
debt: debtValues[index],
|
|
394
|
+
credit: requirePublicationState(creditValues[index]),
|
|
395
|
+
debt: requirePublicationState(debtValues[index]),
|
|
315
396
|
},
|
|
316
397
|
]));
|
|
317
398
|
const collateralStateByKey = new Map(collaterals.map(({ key }, index) => [
|
|
318
399
|
key,
|
|
319
400
|
{
|
|
320
|
-
lltvEnabled: lltvEnabledByCollateral[index],
|
|
321
|
-
liquidationCursorEnabled: liquidationCursorEnabledByCollateral[index],
|
|
401
|
+
lltvEnabled: requirePublicationState(lltvEnabledByCollateral[index]),
|
|
402
|
+
liquidationCursorEnabled: requirePublicationState(liquidationCursorEnabledByCollateral[index]),
|
|
322
403
|
},
|
|
323
404
|
]));
|
|
324
405
|
const collateralStateByMarket = new Map(markets.map(({ id, market }) => [
|
|
325
406
|
id.toLowerCase(),
|
|
326
|
-
market.collateralParams.map((_, index) => collateralStateByKey.get(`${id.toLowerCase()}:${index}`)),
|
|
407
|
+
market.collateralParams.map((_, index) => requirePublicationState(collateralStateByKey.get(`${id.toLowerCase()}:${index}`))),
|
|
327
408
|
]));
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
])));
|
|
335
|
-
const states = params.tree.offers.map((offer) => {
|
|
336
|
-
const id = midnight_sdk_1.MarketUtils.toId(offer.market);
|
|
337
|
-
const market = marketById.get(id.toLowerCase());
|
|
338
|
-
const groupKey = `${offer.maker.toLowerCase()}:${offer.group.toLowerCase()}`;
|
|
339
|
-
const owner = positionByOwner.get(`${id.toLowerCase()}:${offer.maker.toLowerCase()}`);
|
|
340
|
-
const uncreated = market.tickSpacing === 0;
|
|
341
|
-
const collateralStates = uncreated
|
|
342
|
-
? collateralStateByMarket.get(id.toLowerCase())
|
|
343
|
-
: [];
|
|
344
|
-
return {
|
|
345
|
-
consumed: consumedByGroup.get(groupKey),
|
|
346
|
-
tickSpacing: market.tickSpacing,
|
|
347
|
-
continuousFee: BigInt(market.continuousFee),
|
|
348
|
-
credit: owner.credit,
|
|
349
|
-
debt: owner.debt,
|
|
350
|
-
market,
|
|
351
|
-
lltvEnabled: collateralStates.map(({ lltvEnabled }) => lltvEnabled),
|
|
352
|
-
liquidationCursorEnabled: collateralStates.map(({ liquidationCursorEnabled }) => liquidationCursorEnabled),
|
|
353
|
-
oracleHasCode: uncreated
|
|
354
|
-
? (0, exports.offerMarketParams)(offer).collateralParams.map((collateral) => codeByOracle.get(collateral.oracle.toLowerCase()) !== undefined &&
|
|
355
|
-
codeByOracle.get(collateral.oracle.toLowerCase()) !== "0x")
|
|
356
|
-
: [],
|
|
357
|
-
};
|
|
358
|
-
});
|
|
359
|
-
return { states, now: block.timestamp };
|
|
409
|
+
return {
|
|
410
|
+
marketById,
|
|
411
|
+
consumedByGroup,
|
|
412
|
+
positionByOwner,
|
|
413
|
+
collateralStateByMarket,
|
|
414
|
+
};
|
|
360
415
|
}
|
|
361
416
|
/**
|
|
362
417
|
* Rejects offers with callbacks that the selected maker flow cannot execute.
|
|
@@ -3,7 +3,7 @@ import type { AccrualPosition, Market, MidnightFetchParams, PriceRatifierV1TreeC
|
|
|
3
3
|
import type { Address, Hex } from "viem";
|
|
4
4
|
import type { MidnightMakeBorrowCollateral } from "../../actions/midnight/cancelAndMake.js";
|
|
5
5
|
import type { MidnightReferralFeeParams, MidnightTakeableOffer } from "../../actions/midnight/types.js";
|
|
6
|
-
import type { ActionOutput, BaseAction, MidnightBuyTarget, MidnightCancelAndMakeAction, MidnightCollateralTransfer, MidnightGroupCancellation, MidnightRepay, MidnightSellTarget } from "../../types/action.js";
|
|
6
|
+
import type { ActionOutput, BaseAction, MidnightBuyTarget, MidnightCancelAndMakeAction, MidnightCollateralTransfer, MidnightGroupCancellation, MidnightRepay, MidnightSellTarget, ReferenceTimestampParams } from "../../types/action.js";
|
|
7
7
|
/** Optional Midnight API validation controls for make-offer flows. */
|
|
8
8
|
export type OfferValidationParams = Omit<TreeMempoolValidateParams, "chainId" | "ratification">;
|
|
9
9
|
/**
|
|
@@ -33,7 +33,7 @@ export interface OffersData {
|
|
|
33
33
|
readonly payload: Hex;
|
|
34
34
|
}
|
|
35
35
|
/** Parameters shared by Midnight maker flows. */
|
|
36
|
-
export interface MakeOffersParams {
|
|
36
|
+
export interface MakeOffersParams extends ReferenceTimestampParams {
|
|
37
37
|
/** Maker expected on every offer. Must send the transaction: V2 acts on `msg.sender`. */
|
|
38
38
|
readonly accountAddress: Address;
|
|
39
39
|
readonly offers: MidnightMakerTreeInput;
|
|
@@ -146,7 +146,7 @@ export interface MakeOffersOutput extends MidnightActionOutput<MidnightCancelAnd
|
|
|
146
146
|
readonly ratifierType: "priceV1" | "rateV1";
|
|
147
147
|
}
|
|
148
148
|
/** Parameters shared by Midnight market action flows. */
|
|
149
|
-
export interface MarketActionParams {
|
|
149
|
+
export interface MarketActionParams extends ReferenceTimestampParams {
|
|
150
150
|
readonly accountAddress: Address;
|
|
151
151
|
readonly marketData: Market;
|
|
152
152
|
}
|
|
@@ -260,7 +260,7 @@ export interface WithdrawCollateralBatchParams extends MarketActionParams, Midni
|
|
|
260
260
|
readonly receiver?: Address;
|
|
261
261
|
}
|
|
262
262
|
/** Parameters for the Midnight redeem flow. */
|
|
263
|
-
export interface RedeemParams {
|
|
263
|
+
export interface RedeemParams extends ReferenceTimestampParams {
|
|
264
264
|
readonly accountAddress: Address;
|
|
265
265
|
/** Owner-bound snapshot returned by `getPositionData`; manually constructed ownerless snapshots are rejected. */
|
|
266
266
|
readonly positionData: AccrualPosition;
|
|
@@ -53,8 +53,9 @@ exports.assertContractCode = assertContractCode;
|
|
|
53
53
|
const assertRegistryTargetsHaveCode = async (client, chainId, targets) => {
|
|
54
54
|
const seen = new Set();
|
|
55
55
|
for (const target of targets) {
|
|
56
|
-
if (seen.has(target.address))
|
|
56
|
+
if (seen.has(target.address)) {
|
|
57
57
|
continue;
|
|
58
|
+
}
|
|
58
59
|
seen.add(target.address);
|
|
59
60
|
try {
|
|
60
61
|
await (0, exports.assertContractCode)(client, {
|
|
@@ -64,8 +65,9 @@ const assertRegistryTargetsHaveCode = async (client, chainId, targets) => {
|
|
|
64
65
|
});
|
|
65
66
|
}
|
|
66
67
|
catch (error) {
|
|
67
|
-
if (!(error instanceof index_js_1.MissingContractCodeError))
|
|
68
|
+
if (!(error instanceof index_js_1.MissingContractCodeError)) {
|
|
68
69
|
throw error;
|
|
70
|
+
}
|
|
69
71
|
try {
|
|
70
72
|
await (0, validateClientChainId_js_1.validateClientChainId)(client, chainId);
|
|
71
73
|
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { type Address, type Client } from "viem";
|
|
2
|
-
import { type BundlesTokenSignatureRequirement, type ERC20ApprovalAction, type Transaction } from "../../types/index.js";
|
|
2
|
+
import { type BundlesTokenSignatureRequirement, type ERC20ApprovalAction, type ReferenceTimestampParams, type Transaction } from "../../types/index.js";
|
|
3
3
|
/** Parameters for {@link getBundlesTokenRequirements}. */
|
|
4
|
-
export interface GetBundlesTokenRequirementsParams {
|
|
4
|
+
export interface GetBundlesTokenRequirementsParams extends ReferenceTimestampParams {
|
|
5
5
|
/** ERC-20 token funded by the operation. */
|
|
6
6
|
readonly token: Address;
|
|
7
7
|
/** Registered fixed bundles contract that pulls the token. */
|
|
@@ -22,8 +22,6 @@ export interface GetBundlesTokenRequirementsParams {
|
|
|
22
22
|
readonly useSimplePermit?: boolean;
|
|
23
23
|
/** @deprecated Ignored. The SDK no longer requests Permit2 funding; use ERC-2612 permits or ERC-20 approvals. */
|
|
24
24
|
readonly permit2Nonce?: bigint;
|
|
25
|
-
/** Timestamp the deadline is validated against; defaults to the current time. */
|
|
26
|
-
readonly now?: bigint;
|
|
27
25
|
}
|
|
28
26
|
/**
|
|
29
27
|
* Resolves direct approval or ERC-2612 prerequisites for a registered fixed bundles contract.
|
|
@@ -40,7 +38,7 @@ export interface GetBundlesTokenRequirementsParams {
|
|
|
40
38
|
* @param params.owner - Account funding the operation.
|
|
41
39
|
* @param params.chainId - Target chain id; must match the client chain.
|
|
42
40
|
* @param params.deadline - Final-call and signature deadline.
|
|
43
|
-
* @param params.now -
|
|
41
|
+
* @param params.now - See {@link ReferenceTimestampParams.now}.
|
|
44
42
|
* @param params.supportSignature - Whether ERC-2612 signatures may be requested.
|
|
45
43
|
* @param params.supportDeployless - Whether ERC-2612 metadata reads may use deployless calls.
|
|
46
44
|
* @param params.useSimplePermit - Defaults to true when signatures are supported. Prefer ERC-2612 when `nonces()` succeeds and the token's
|