@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({
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { UnknownDataError } from "@morpho-org/blue-sdk";
|
|
1
2
|
import { DEFAULT_TICK_SPACING, Market, MarketParams, MarketUtils, midnightAbi, RateRatifierV1, } from "@morpho-org/midnight-sdk";
|
|
2
3
|
import { getChainAddress, MathLib } from "@morpho-org/morpho-ts";
|
|
3
4
|
import { maxUint256, zeroAddress } from "viem";
|
|
@@ -6,8 +7,102 @@ import { validateClientChainId } from "../../actions/requirements/validateClient
|
|
|
6
7
|
import { MidnightMarketLiquidationCursorNotEnabledError, MidnightMarketLltvNotEnabledError, MidnightMarketMaturityTooFarError, MidnightMarketOracleWithoutCodeError, MidnightOfferCallbackNotSupportedError, MidnightOfferContinuousFeeCapBelowMarketFeeError, MidnightOfferExpiredError, MidnightOfferExpiryAfterMaturityError, MidnightOfferGroupConsumedError, MidnightOfferNoCreditError, MidnightOfferNoDebtError, MidnightOfferRateBoundUnreachableError, MidnightOfferTickSpacingError, MidnightOfferZeroPriceSellError, } from "../../types/midnightPublicationError.js";
|
|
7
8
|
// Midnight.sol `touchMarket` rejects markets maturing more than 100 years after creation.
|
|
8
9
|
const MAX_TIME_TO_MATURITY = 100n * 365n * 86400n;
|
|
10
|
+
function requirePublicationState(value) {
|
|
11
|
+
if (value === undefined) {
|
|
12
|
+
throw new UnknownDataError("Missing Midnight publication state.");
|
|
13
|
+
}
|
|
14
|
+
return value;
|
|
15
|
+
}
|
|
9
16
|
/** @internal */
|
|
10
17
|
export const offerMarketParams = (offer) => "params" in offer.market ? offer.market.params : offer.market;
|
|
18
|
+
function validateOfferTerms({ offer, state, index, marketId, }) {
|
|
19
|
+
const capacity = BigInt(offer.maxAssets) > 0n
|
|
20
|
+
? BigInt(offer.maxAssets)
|
|
21
|
+
: BigInt(offer.maxUnits);
|
|
22
|
+
if (state.consumed >= capacity) {
|
|
23
|
+
throw new MidnightOfferGroupConsumedError({
|
|
24
|
+
index,
|
|
25
|
+
group: offer.group,
|
|
26
|
+
consumed: state.consumed,
|
|
27
|
+
});
|
|
28
|
+
}
|
|
29
|
+
const tickSpacing = state.tickSpacing || Number(DEFAULT_TICK_SPACING);
|
|
30
|
+
if (BigInt(offer.tick) % BigInt(tickSpacing) !== 0n) {
|
|
31
|
+
throw new MidnightOfferTickSpacingError({
|
|
32
|
+
index,
|
|
33
|
+
tick: BigInt(offer.tick),
|
|
34
|
+
tickSpacing,
|
|
35
|
+
});
|
|
36
|
+
}
|
|
37
|
+
if (BigInt(offer.continuousFeeCap) < state.continuousFee) {
|
|
38
|
+
throw new MidnightOfferContinuousFeeCapBelowMarketFeeError({
|
|
39
|
+
index,
|
|
40
|
+
marketId,
|
|
41
|
+
continuousFeeCap: BigInt(offer.continuousFeeCap),
|
|
42
|
+
continuousFee: state.continuousFee,
|
|
43
|
+
});
|
|
44
|
+
}
|
|
45
|
+
if (!offer.buy && BigInt(offer.tick) === 0n) {
|
|
46
|
+
throw new MidnightOfferZeroPriceSellError({ index });
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
function validateOfferRate({ offer, state, index, rate, now, expiry, }) {
|
|
50
|
+
let timestamp = offer.buy ? expiry : MathLib.max(now, BigInt(offer.start));
|
|
51
|
+
if (!offer.buy && rate > 0n) {
|
|
52
|
+
const maxTimeToMaturity = (maxUint256 - MathLib.WAD * MathLib.WAD - MathLib.WAD + 1n) / rate;
|
|
53
|
+
const marketMaturity = state.market.params.maturity;
|
|
54
|
+
timestamp = MathLib.max(timestamp, marketMaturity - maxTimeToMaturity);
|
|
55
|
+
if (timestamp > expiry || timestamp > marketMaturity) {
|
|
56
|
+
throw new MidnightOfferRateBoundUnreachableError({
|
|
57
|
+
index,
|
|
58
|
+
rate,
|
|
59
|
+
tick: BigInt(offer.tick),
|
|
60
|
+
});
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
if (!RateRatifierV1.isPriceAcceptable({
|
|
64
|
+
offer: { ...offer, market: state.market },
|
|
65
|
+
rate,
|
|
66
|
+
timestamp,
|
|
67
|
+
})) {
|
|
68
|
+
throw new MidnightOfferRateBoundUnreachableError({
|
|
69
|
+
index,
|
|
70
|
+
rate,
|
|
71
|
+
tick: BigInt(offer.tick),
|
|
72
|
+
});
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
function validateUncreatedMarket({ state, index, offerMarket, maturity, expiry, now, marketCreationTime, }) {
|
|
76
|
+
const marketCreationTimestamp = marketCreationTime === "now" ? now : expiry;
|
|
77
|
+
const maxMaturity = marketCreationTimestamp + MAX_TIME_TO_MATURITY;
|
|
78
|
+
if (maturity > maxMaturity) {
|
|
79
|
+
throw new MidnightMarketMaturityTooFarError({
|
|
80
|
+
index,
|
|
81
|
+
maturity,
|
|
82
|
+
maxMaturity,
|
|
83
|
+
});
|
|
84
|
+
}
|
|
85
|
+
for (const [collateralIndex, collateral,] of offerMarket.collateralParams.entries()) {
|
|
86
|
+
if (!state.lltvEnabled[collateralIndex]) {
|
|
87
|
+
throw new MidnightMarketLltvNotEnabledError({
|
|
88
|
+
index,
|
|
89
|
+
lltv: BigInt(collateral.lltv),
|
|
90
|
+
});
|
|
91
|
+
}
|
|
92
|
+
if (!state.liquidationCursorEnabled[collateralIndex]) {
|
|
93
|
+
throw new MidnightMarketLiquidationCursorNotEnabledError({
|
|
94
|
+
index,
|
|
95
|
+
liquidationCursor: BigInt(collateral.liquidationCursor),
|
|
96
|
+
});
|
|
97
|
+
}
|
|
98
|
+
if (!state.oracleHasCode[collateralIndex]) {
|
|
99
|
+
throw new MidnightMarketOracleWithoutCodeError({
|
|
100
|
+
index,
|
|
101
|
+
oracle: collateral.oracle,
|
|
102
|
+
});
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
}
|
|
11
106
|
/**
|
|
12
107
|
* Rejects the first maker offer that cannot be filled at or after publication.
|
|
13
108
|
*
|
|
@@ -24,6 +119,7 @@ export const offerMarketParams = (offer) => "params" in offer.market ? offer.mar
|
|
|
24
119
|
* @returns Nothing when every offer can be published.
|
|
25
120
|
* @throws {MidnightOfferExpiredError} when expiry is not later than `now`.
|
|
26
121
|
* @throws {MidnightOfferExpiryAfterMaturityError} when expiry exceeds market maturity.
|
|
122
|
+
* @throws {UnknownDataError} when an offer's state or rate entry is missing.
|
|
27
123
|
* @throws {MidnightOfferGroupConsumedError} when the group's remaining cap is zero.
|
|
28
124
|
* @throws {MidnightOfferTickSpacingError} when the tick is inaccessible.
|
|
29
125
|
* @throws {MidnightOfferContinuousFeeCapBelowMarketFeeError} when the market fee exceeds the offer cap.
|
|
@@ -43,7 +139,7 @@ export const offerMarketParams = (offer) => "params" in offer.market ? offer.mar
|
|
|
43
139
|
export function validateMidnightMakerOfferStates(params) {
|
|
44
140
|
const rateEntries = params.tree.type === "rateV1" ? params.tree.entries : [];
|
|
45
141
|
params.tree.offers.forEach((offer, index) => {
|
|
46
|
-
const state = params.states[index];
|
|
142
|
+
const state = requirePublicationState(params.states[index]);
|
|
47
143
|
const expiry = BigInt(offer.expiry);
|
|
48
144
|
const offerMarket = offerMarketParams(offer);
|
|
49
145
|
const maturity = BigInt(offerMarket.maturity);
|
|
@@ -62,63 +158,12 @@ export function validateMidnightMakerOfferStates(params) {
|
|
|
62
158
|
maturity,
|
|
63
159
|
});
|
|
64
160
|
}
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
: BigInt(offer.maxUnits);
|
|
68
|
-
if (state.consumed >= capacity) {
|
|
69
|
-
throw new MidnightOfferGroupConsumedError({
|
|
70
|
-
index,
|
|
71
|
-
group: offer.group,
|
|
72
|
-
consumed: state.consumed,
|
|
73
|
-
});
|
|
74
|
-
}
|
|
75
|
-
const tickSpacing = state.tickSpacing || Number(DEFAULT_TICK_SPACING);
|
|
76
|
-
if (BigInt(offer.tick) % BigInt(tickSpacing) !== 0n) {
|
|
77
|
-
throw new MidnightOfferTickSpacingError({
|
|
78
|
-
index,
|
|
79
|
-
tick: BigInt(offer.tick),
|
|
80
|
-
tickSpacing,
|
|
81
|
-
});
|
|
82
|
-
}
|
|
83
|
-
if (BigInt(offer.continuousFeeCap) < state.continuousFee) {
|
|
84
|
-
throw new MidnightOfferContinuousFeeCapBelowMarketFeeError({
|
|
85
|
-
index,
|
|
86
|
-
marketId,
|
|
87
|
-
continuousFeeCap: BigInt(offer.continuousFeeCap),
|
|
88
|
-
continuousFee: state.continuousFee,
|
|
89
|
-
});
|
|
90
|
-
}
|
|
91
|
-
if (!offer.buy && BigInt(offer.tick) === 0n) {
|
|
92
|
-
throw new MidnightOfferZeroPriceSellError({ index });
|
|
93
|
-
}
|
|
161
|
+
// Reject inaccessible terms before evaluating rate reachability.
|
|
162
|
+
validateOfferTerms({ offer, state, index, marketId });
|
|
94
163
|
if (params.tree.type === "rateV1") {
|
|
95
|
-
const rate = BigInt(rateEntries[index].rate);
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
: MathLib.max(params.now, BigInt(offer.start));
|
|
99
|
-
if (!offer.buy && rate > 0n) {
|
|
100
|
-
const maxTimeToMaturity = (maxUint256 - MathLib.WAD * MathLib.WAD - MathLib.WAD + 1n) / rate;
|
|
101
|
-
const marketMaturity = state.market.params.maturity;
|
|
102
|
-
timestamp = MathLib.max(timestamp, marketMaturity - maxTimeToMaturity);
|
|
103
|
-
if (timestamp > expiry || timestamp > marketMaturity) {
|
|
104
|
-
throw new MidnightOfferRateBoundUnreachableError({
|
|
105
|
-
index,
|
|
106
|
-
rate,
|
|
107
|
-
tick: BigInt(offer.tick),
|
|
108
|
-
});
|
|
109
|
-
}
|
|
110
|
-
}
|
|
111
|
-
if (!RateRatifierV1.isPriceAcceptable({
|
|
112
|
-
offer: { ...offer, market: state.market },
|
|
113
|
-
rate,
|
|
114
|
-
timestamp,
|
|
115
|
-
})) {
|
|
116
|
-
throw new MidnightOfferRateBoundUnreachableError({
|
|
117
|
-
index,
|
|
118
|
-
rate,
|
|
119
|
-
tick: BigInt(offer.tick),
|
|
120
|
-
});
|
|
121
|
-
}
|
|
164
|
+
const rate = BigInt(requirePublicationState(rateEntries[index]).rate);
|
|
165
|
+
// Reject rate bounds that cannot become fillable.
|
|
166
|
+
validateOfferRate({ offer, state, index, rate, now: params.now, expiry });
|
|
122
167
|
}
|
|
123
168
|
if (offer.reduceOnly && offer.buy && state.debt === 0n) {
|
|
124
169
|
throw new MidnightOfferNoDebtError({ index, marketId });
|
|
@@ -127,35 +172,16 @@ export function validateMidnightMakerOfferStates(params) {
|
|
|
127
172
|
throw new MidnightOfferNoCreditError({ index, marketId });
|
|
128
173
|
}
|
|
129
174
|
if (state.tickSpacing === 0) {
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
if (!state.lltvEnabled[collateralIndex]) {
|
|
141
|
-
throw new MidnightMarketLltvNotEnabledError({
|
|
142
|
-
index,
|
|
143
|
-
lltv: BigInt(collateral.lltv),
|
|
144
|
-
});
|
|
145
|
-
}
|
|
146
|
-
if (!state.liquidationCursorEnabled[collateralIndex]) {
|
|
147
|
-
throw new MidnightMarketLiquidationCursorNotEnabledError({
|
|
148
|
-
index,
|
|
149
|
-
liquidationCursor: BigInt(collateral.liquidationCursor),
|
|
150
|
-
});
|
|
151
|
-
}
|
|
152
|
-
if (!state.oracleHasCode[collateralIndex]) {
|
|
153
|
-
throw new MidnightMarketOracleWithoutCodeError({
|
|
154
|
-
index,
|
|
155
|
-
oracle: collateral.oracle,
|
|
156
|
-
});
|
|
157
|
-
}
|
|
158
|
-
}
|
|
175
|
+
// Reject market parameters that cannot be created.
|
|
176
|
+
validateUncreatedMarket({
|
|
177
|
+
state,
|
|
178
|
+
index,
|
|
179
|
+
offerMarket,
|
|
180
|
+
maturity,
|
|
181
|
+
expiry,
|
|
182
|
+
now: params.now,
|
|
183
|
+
marketCreationTime: params.marketCreationTime,
|
|
184
|
+
});
|
|
159
185
|
}
|
|
160
186
|
});
|
|
161
187
|
}
|
|
@@ -175,6 +201,7 @@ export function validateMidnightMakerOfferStates(params) {
|
|
|
175
201
|
* @throws {ChainIdMismatchError} when the client declares, or its RPC reports via `eth_chainId`,
|
|
176
202
|
* another chain than `params.chainId`.
|
|
177
203
|
* @throws {viem.BaseError} when block, contract, or oracle-code reads fail.
|
|
204
|
+
* @throws {UnknownDataError} when required publication state is missing.
|
|
178
205
|
* @example
|
|
179
206
|
* ```ts
|
|
180
207
|
* const { states, now } = await fetchMidnightMakerOfferStates({
|
|
@@ -189,21 +216,65 @@ export async function fetchMidnightMakerOfferStates(params) {
|
|
|
189
216
|
const blockNumber = params.blockNumber ?? (await getBlockNumber(params.client));
|
|
190
217
|
const block = await getBlock(params.client, { blockNumber });
|
|
191
218
|
const midnight = getChainAddress(params.chainId, "midnight");
|
|
219
|
+
const targets = collectPublicationReadTargets(params.tree);
|
|
220
|
+
const { collaterals } = targets;
|
|
221
|
+
const values = await readPublicationContractState({
|
|
222
|
+
client: params.client,
|
|
223
|
+
midnight,
|
|
224
|
+
blockNumber,
|
|
225
|
+
targets,
|
|
226
|
+
});
|
|
227
|
+
const { marketById, consumedByGroup, positionByOwner, collateralStateByMarket, } = indexPublicationContractState({ targets, values });
|
|
228
|
+
const codeByOracle = new Map(await Promise.all([...new Set(collaterals.map(({ oracleKey }) => oracleKey))].map(async (oracleKey) => [
|
|
229
|
+
oracleKey,
|
|
230
|
+
await getCode(params.client, {
|
|
231
|
+
address: requirePublicationState(collaterals.find(({ oracleKey: key }) => key === oracleKey)).collateral.oracle,
|
|
232
|
+
blockNumber,
|
|
233
|
+
}),
|
|
234
|
+
])));
|
|
235
|
+
const states = params.tree.offers.map((offer) => {
|
|
236
|
+
const id = MarketUtils.toId(offer.market);
|
|
237
|
+
const market = requirePublicationState(marketById.get(id.toLowerCase()));
|
|
238
|
+
const groupKey = `${offer.maker.toLowerCase()}:${offer.group.toLowerCase()}`;
|
|
239
|
+
const owner = requirePublicationState(positionByOwner.get(`${id.toLowerCase()}:${offer.maker.toLowerCase()}`));
|
|
240
|
+
const uncreated = market.tickSpacing === 0;
|
|
241
|
+
const collateralStates = uncreated
|
|
242
|
+
? requirePublicationState(collateralStateByMarket.get(id.toLowerCase()))
|
|
243
|
+
: [];
|
|
244
|
+
return {
|
|
245
|
+
consumed: requirePublicationState(consumedByGroup.get(groupKey)),
|
|
246
|
+
tickSpacing: market.tickSpacing,
|
|
247
|
+
continuousFee: BigInt(market.continuousFee),
|
|
248
|
+
credit: owner.credit,
|
|
249
|
+
debt: owner.debt,
|
|
250
|
+
market,
|
|
251
|
+
lltvEnabled: collateralStates.map(({ lltvEnabled }) => lltvEnabled),
|
|
252
|
+
liquidationCursorEnabled: collateralStates.map(({ liquidationCursorEnabled }) => liquidationCursorEnabled),
|
|
253
|
+
oracleHasCode: uncreated
|
|
254
|
+
? offerMarketParams(offer).collateralParams.map((collateral) => codeByOracle.get(collateral.oracle.toLowerCase()) !== undefined &&
|
|
255
|
+
codeByOracle.get(collateral.oracle.toLowerCase()) !== "0x")
|
|
256
|
+
: [],
|
|
257
|
+
};
|
|
258
|
+
});
|
|
259
|
+
return { states, now: block.timestamp };
|
|
260
|
+
}
|
|
261
|
+
/** Deduplicates the market, group, owner and collateral reads for a maker tree. @internal */
|
|
262
|
+
function collectPublicationReadTargets(tree) {
|
|
192
263
|
const markets = [
|
|
193
|
-
...new Map(
|
|
264
|
+
...new Map(tree.offers.map((offer) => {
|
|
194
265
|
const market = MarketParams.from(offerMarketParams(offer));
|
|
195
266
|
const id = MarketUtils.toId(market);
|
|
196
267
|
return [id.toLowerCase(), { id, market }];
|
|
197
268
|
})).values(),
|
|
198
269
|
];
|
|
199
270
|
const groups = [
|
|
200
|
-
...new Map(
|
|
271
|
+
...new Map(tree.offers.map((offer) => [
|
|
201
272
|
`${offer.maker.toLowerCase()}:${offer.group.toLowerCase()}`,
|
|
202
273
|
{ maker: offer.maker, group: offer.group },
|
|
203
274
|
])).values(),
|
|
204
275
|
];
|
|
205
276
|
const owners = [
|
|
206
|
-
...new Map(
|
|
277
|
+
...new Map(tree.offers.map((offer) => {
|
|
207
278
|
const id = MarketUtils.toId(offer.market);
|
|
208
279
|
return [
|
|
209
280
|
`${id.toLowerCase()}:${offer.maker.toLowerCase()}`,
|
|
@@ -222,50 +293,55 @@ export async function fetchMidnightMakerOfferStates(params) {
|
|
|
222
293
|
market.loanToken,
|
|
223
294
|
])).values(),
|
|
224
295
|
];
|
|
225
|
-
|
|
226
|
-
|
|
296
|
+
return { markets, groups, owners, collaterals, defaultFeeTokens };
|
|
297
|
+
}
|
|
298
|
+
/** Reads contract state concurrently at the pinned publication block. @internal */
|
|
299
|
+
async function readPublicationContractState({ client, midnight, blockNumber, targets, }) {
|
|
300
|
+
const { markets, groups, owners, collaterals, defaultFeeTokens } = targets;
|
|
301
|
+
return Promise.all([
|
|
302
|
+
Promise.all(markets.map(({ id }) => readContract(client, {
|
|
227
303
|
address: midnight,
|
|
228
304
|
abi: midnightAbi,
|
|
229
305
|
functionName: "marketState",
|
|
230
306
|
args: [id],
|
|
231
307
|
blockNumber,
|
|
232
308
|
}))),
|
|
233
|
-
Promise.all(groups.map(({ maker, group }) => readContract(
|
|
309
|
+
Promise.all(groups.map(({ maker, group }) => readContract(client, {
|
|
234
310
|
address: midnight,
|
|
235
311
|
abi: midnightAbi,
|
|
236
312
|
functionName: "consumed",
|
|
237
313
|
args: [maker, group],
|
|
238
314
|
blockNumber,
|
|
239
315
|
}))),
|
|
240
|
-
Promise.all(owners.map(({ id, maker }) => readContract(
|
|
316
|
+
Promise.all(owners.map(({ id, maker }) => readContract(client, {
|
|
241
317
|
address: midnight,
|
|
242
318
|
abi: midnightAbi,
|
|
243
319
|
functionName: "credit",
|
|
244
320
|
args: [id, maker],
|
|
245
321
|
blockNumber,
|
|
246
322
|
}))),
|
|
247
|
-
Promise.all(owners.map(({ id, maker }) => readContract(
|
|
323
|
+
Promise.all(owners.map(({ id, maker }) => readContract(client, {
|
|
248
324
|
address: midnight,
|
|
249
325
|
abi: midnightAbi,
|
|
250
326
|
functionName: "debt",
|
|
251
327
|
args: [id, maker],
|
|
252
328
|
blockNumber,
|
|
253
329
|
}))),
|
|
254
|
-
Promise.all(defaultFeeTokens.map((loanToken) => readContract(
|
|
330
|
+
Promise.all(defaultFeeTokens.map((loanToken) => readContract(client, {
|
|
255
331
|
address: midnight,
|
|
256
332
|
abi: midnightAbi,
|
|
257
333
|
functionName: "defaultContinuousFee",
|
|
258
334
|
args: [loanToken],
|
|
259
335
|
blockNumber,
|
|
260
336
|
}))),
|
|
261
|
-
Promise.all(collaterals.map(({ collateral }) => readContract(
|
|
337
|
+
Promise.all(collaterals.map(({ collateral }) => readContract(client, {
|
|
262
338
|
address: midnight,
|
|
263
339
|
abi: midnightAbi,
|
|
264
340
|
functionName: "isLltvEnabled",
|
|
265
341
|
args: [collateral.lltv],
|
|
266
342
|
blockNumber,
|
|
267
343
|
}))),
|
|
268
|
-
Promise.all(collaterals.map(({ collateral }) => readContract(
|
|
344
|
+
Promise.all(collaterals.map(({ collateral }) => readContract(client, {
|
|
269
345
|
address: midnight,
|
|
270
346
|
abi: midnightAbi,
|
|
271
347
|
functionName: "isLiquidationCursorEnabled",
|
|
@@ -273,14 +349,19 @@ export async function fetchMidnightMakerOfferStates(params) {
|
|
|
273
349
|
blockNumber,
|
|
274
350
|
}))),
|
|
275
351
|
]);
|
|
352
|
+
}
|
|
353
|
+
/** Indexes validated contract results for per-offer publication state. @internal */
|
|
354
|
+
function indexPublicationContractState({ targets, values, }) {
|
|
355
|
+
const { markets, groups, owners, collaterals, defaultFeeTokens } = targets;
|
|
356
|
+
const [marketStates, consumedValues, creditValues, debtValues, defaultFees, lltvEnabledByCollateral, liquidationCursorEnabledByCollateral,] = values;
|
|
276
357
|
const defaultFeeByLoanToken = new Map(defaultFeeTokens.map((loanToken, index) => [
|
|
277
358
|
loanToken.toLowerCase(),
|
|
278
|
-
defaultFees[index],
|
|
359
|
+
requirePublicationState(defaultFees[index]),
|
|
279
360
|
]));
|
|
280
361
|
const marketById = new Map(markets.map(({ id, market: marketParams }, index) => {
|
|
281
|
-
const [totalUnits, lossFactor, withdrawable, continuousFeeCredit, fee0, fee1, fee2, fee3, fee4, fee5, fee6, continuousFee, tickSpacing,] = marketStates[index];
|
|
362
|
+
const [totalUnits, lossFactor, withdrawable, continuousFeeCredit, fee0, fee1, fee2, fee3, fee4, fee5, fee6, continuousFee, tickSpacing,] = requirePublicationState(marketStates[index]);
|
|
282
363
|
const effectiveContinuousFee = tickSpacing === 0
|
|
283
|
-
? defaultFeeByLoanToken.get(marketParams.loanToken.toLowerCase())
|
|
364
|
+
? requirePublicationState(defaultFeeByLoanToken.get(marketParams.loanToken.toLowerCase()))
|
|
284
365
|
: continuousFee;
|
|
285
366
|
return [
|
|
286
367
|
id.toLowerCase(),
|
|
@@ -298,58 +379,32 @@ export async function fetchMidnightMakerOfferStates(params) {
|
|
|
298
379
|
}));
|
|
299
380
|
const consumedByGroup = new Map(groups.map(({ maker, group }, index) => [
|
|
300
381
|
`${maker.toLowerCase()}:${group.toLowerCase()}`,
|
|
301
|
-
consumedValues[index],
|
|
382
|
+
requirePublicationState(consumedValues[index]),
|
|
302
383
|
]));
|
|
303
384
|
const positionByOwner = new Map(owners.map(({ id, maker }, index) => [
|
|
304
385
|
`${id.toLowerCase()}:${maker.toLowerCase()}`,
|
|
305
386
|
{
|
|
306
|
-
credit: creditValues[index],
|
|
307
|
-
debt: debtValues[index],
|
|
387
|
+
credit: requirePublicationState(creditValues[index]),
|
|
388
|
+
debt: requirePublicationState(debtValues[index]),
|
|
308
389
|
},
|
|
309
390
|
]));
|
|
310
391
|
const collateralStateByKey = new Map(collaterals.map(({ key }, index) => [
|
|
311
392
|
key,
|
|
312
393
|
{
|
|
313
|
-
lltvEnabled: lltvEnabledByCollateral[index],
|
|
314
|
-
liquidationCursorEnabled: liquidationCursorEnabledByCollateral[index],
|
|
394
|
+
lltvEnabled: requirePublicationState(lltvEnabledByCollateral[index]),
|
|
395
|
+
liquidationCursorEnabled: requirePublicationState(liquidationCursorEnabledByCollateral[index]),
|
|
315
396
|
},
|
|
316
397
|
]));
|
|
317
398
|
const collateralStateByMarket = new Map(markets.map(({ id, market }) => [
|
|
318
399
|
id.toLowerCase(),
|
|
319
|
-
market.collateralParams.map((_, index) => collateralStateByKey.get(`${id.toLowerCase()}:${index}`)),
|
|
400
|
+
market.collateralParams.map((_, index) => requirePublicationState(collateralStateByKey.get(`${id.toLowerCase()}:${index}`))),
|
|
320
401
|
]));
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
])));
|
|
328
|
-
const states = params.tree.offers.map((offer) => {
|
|
329
|
-
const id = MarketUtils.toId(offer.market);
|
|
330
|
-
const market = marketById.get(id.toLowerCase());
|
|
331
|
-
const groupKey = `${offer.maker.toLowerCase()}:${offer.group.toLowerCase()}`;
|
|
332
|
-
const owner = positionByOwner.get(`${id.toLowerCase()}:${offer.maker.toLowerCase()}`);
|
|
333
|
-
const uncreated = market.tickSpacing === 0;
|
|
334
|
-
const collateralStates = uncreated
|
|
335
|
-
? collateralStateByMarket.get(id.toLowerCase())
|
|
336
|
-
: [];
|
|
337
|
-
return {
|
|
338
|
-
consumed: consumedByGroup.get(groupKey),
|
|
339
|
-
tickSpacing: market.tickSpacing,
|
|
340
|
-
continuousFee: BigInt(market.continuousFee),
|
|
341
|
-
credit: owner.credit,
|
|
342
|
-
debt: owner.debt,
|
|
343
|
-
market,
|
|
344
|
-
lltvEnabled: collateralStates.map(({ lltvEnabled }) => lltvEnabled),
|
|
345
|
-
liquidationCursorEnabled: collateralStates.map(({ liquidationCursorEnabled }) => liquidationCursorEnabled),
|
|
346
|
-
oracleHasCode: uncreated
|
|
347
|
-
? offerMarketParams(offer).collateralParams.map((collateral) => codeByOracle.get(collateral.oracle.toLowerCase()) !== undefined &&
|
|
348
|
-
codeByOracle.get(collateral.oracle.toLowerCase()) !== "0x")
|
|
349
|
-
: [],
|
|
350
|
-
};
|
|
351
|
-
});
|
|
352
|
-
return { states, now: block.timestamp };
|
|
402
|
+
return {
|
|
403
|
+
marketById,
|
|
404
|
+
consumedByGroup,
|
|
405
|
+
positionByOwner,
|
|
406
|
+
collateralStateByMarket,
|
|
407
|
+
};
|
|
353
408
|
}
|
|
354
409
|
/**
|
|
355
410
|
* 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;
|
|
@@ -49,8 +49,9 @@ export const assertContractCode = async (client, params) => {
|
|
|
49
49
|
export const assertRegistryTargetsHaveCode = async (client, chainId, targets) => {
|
|
50
50
|
const seen = new Set();
|
|
51
51
|
for (const target of targets) {
|
|
52
|
-
if (seen.has(target.address))
|
|
52
|
+
if (seen.has(target.address)) {
|
|
53
53
|
continue;
|
|
54
|
+
}
|
|
54
55
|
seen.add(target.address);
|
|
55
56
|
try {
|
|
56
57
|
await assertContractCode(client, {
|
|
@@ -60,8 +61,9 @@ export const assertRegistryTargetsHaveCode = async (client, chainId, targets) =>
|
|
|
60
61
|
});
|
|
61
62
|
}
|
|
62
63
|
catch (error) {
|
|
63
|
-
if (!(error instanceof MissingContractCodeError))
|
|
64
|
+
if (!(error instanceof MissingContractCodeError)) {
|
|
64
65
|
throw error;
|
|
66
|
+
}
|
|
65
67
|
try {
|
|
66
68
|
await validateClientChainId(client, chainId);
|
|
67
69
|
}
|
|
@@ -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
|