@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
package/lib/cjs/types/error.js
CHANGED
|
@@ -896,7 +896,10 @@ class ChainIdMismatchError extends Error {
|
|
|
896
896
|
}
|
|
897
897
|
}
|
|
898
898
|
exports.ChainIdMismatchError = ChainIdMismatchError;
|
|
899
|
-
/**
|
|
899
|
+
/**
|
|
900
|
+
* Thrown when a runtime crypto API is required but unavailable.
|
|
901
|
+
* @deprecated This error is never thrown by the SDK and will be removed in the next major version.
|
|
902
|
+
*/
|
|
900
903
|
class CryptoUnavailableError extends Error {
|
|
901
904
|
constructor(feature) {
|
|
902
905
|
super(`Crypto API is required for ${feature} but is unavailable.`);
|
|
@@ -1007,9 +1010,15 @@ class ChainWNativeMissingError extends Error {
|
|
|
1007
1010
|
exports.ChainWNativeMissingError = ChainWNativeMissingError;
|
|
1008
1011
|
/** Thrown when a vault entity's address does not match the vault address embedded in the call's args. */
|
|
1009
1012
|
class VaultAddressMismatchError extends Error {
|
|
1013
|
+
/** Vault targeted by the caller. */
|
|
1014
|
+
expected;
|
|
1015
|
+
/** Vault address found in the supplied snapshot. */
|
|
1016
|
+
actual;
|
|
1010
1017
|
constructor(vaultAddress, argsVaultAddress) {
|
|
1011
1018
|
super(`Vault address mismatch between vault: ${vaultAddress} and args: ${argsVaultAddress}`);
|
|
1012
1019
|
this.name = "VaultAddressMismatchError";
|
|
1020
|
+
this.expected = vaultAddress;
|
|
1021
|
+
this.actual = argsVaultAddress;
|
|
1013
1022
|
}
|
|
1014
1023
|
}
|
|
1015
1024
|
exports.VaultAddressMismatchError = VaultAddressMismatchError;
|
|
@@ -1126,11 +1135,17 @@ class InvalidReallocationSourceTypeError extends Error {
|
|
|
1126
1135
|
* @param missingField - Required market-source field that is absent or malformed.
|
|
1127
1136
|
*/
|
|
1128
1137
|
constructor(sourceType, missingField) {
|
|
1129
|
-
|
|
1130
|
-
|
|
1131
|
-
|
|
1132
|
-
|
|
1133
|
-
|
|
1138
|
+
let message;
|
|
1139
|
+
if (missingField != null) {
|
|
1140
|
+
message = `Reallocation market source must include a valid "${missingField}".`;
|
|
1141
|
+
}
|
|
1142
|
+
else if (sourceType === undefined) {
|
|
1143
|
+
message = 'Reallocation source must specify type "market" or "idle".';
|
|
1144
|
+
}
|
|
1145
|
+
else {
|
|
1146
|
+
message = `Reallocation source type must be "market" or "idle", got "${sourceType}".`;
|
|
1147
|
+
}
|
|
1148
|
+
super(message);
|
|
1134
1149
|
this.sourceType = sourceType;
|
|
1135
1150
|
this.missingField = missingField;
|
|
1136
1151
|
this.name = "InvalidReallocationSourceTypeError";
|
|
@@ -5,6 +5,16 @@ export interface Metadata {
|
|
|
5
5
|
* Invalid values are dropped with a console warning.
|
|
6
6
|
*/
|
|
7
7
|
origin: string;
|
|
8
|
-
/**
|
|
9
|
-
|
|
8
|
+
/**
|
|
9
|
+
* Append a four-byte Unix timestamp before the origin. For entity flows, set
|
|
10
|
+
* `timestamp: true` in the client options and pass a fresh `now` to each flow
|
|
11
|
+
* to record that flow's reference timestamp. `true` without a flow `now` uses
|
|
12
|
+
* the device clock; only this fallback is deprecated.
|
|
13
|
+
*
|
|
14
|
+
* For direct action or `addTransactionMetadata` calls, pass a bigint per
|
|
15
|
+
* transaction, normally the latest block's `timestamp`. A bigint must be
|
|
16
|
+
* uint32 seconds (0 through 2^32 - 1, inclusive). Do not store a per-transaction
|
|
17
|
+
* block timestamp in long-lived client options. `false` or unset omits it.
|
|
18
|
+
*/
|
|
19
|
+
timestamp?: boolean | bigint;
|
|
10
20
|
}
|
package/lib/cjs/version.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
/** Installed @morpho-org/morpho-sdk package version. */
|
|
2
|
-
export declare const version = "
|
|
2
|
+
export declare const version = "10.0.0";
|
package/lib/cjs/version.js
CHANGED
|
@@ -25,8 +25,9 @@ export const validateBlueBundlesV1NativeFunding = (params) => {
|
|
|
25
25
|
if (nativeAmount < 0n) {
|
|
26
26
|
throw new NegativeInputError("nativeAmount", nativeAmount);
|
|
27
27
|
}
|
|
28
|
-
if (nativeAmount === 0n)
|
|
28
|
+
if (nativeAmount === 0n) {
|
|
29
29
|
return 0n;
|
|
30
|
+
}
|
|
30
31
|
validateNativeAsset(params.chainId, params.token);
|
|
31
32
|
if (nativeAmount !== params.fundedAmount) {
|
|
32
33
|
throw new NativeFundingAmountMismatchError(nativeAmount, params.fundedAmount);
|
|
@@ -49,8 +50,9 @@ export const getBlueBundlesV1TokenPermit = (params) => {
|
|
|
49
50
|
/** @internal */
|
|
50
51
|
export const getBlueBundlesV1SignedAuthorization = (params) => {
|
|
51
52
|
const { authorizationSignature } = params;
|
|
52
|
-
if (authorizationSignature == null)
|
|
53
|
+
if (authorizationSignature == null) {
|
|
53
54
|
return EMPTY_SIGNED_AUTHORIZATION;
|
|
55
|
+
}
|
|
54
56
|
const authorized = getChainAddress(params.chainId, "bundles.blueBundlesV1");
|
|
55
57
|
if (!isAddressEqual(authorizationSignature.args.owner, params.userAddress)) {
|
|
56
58
|
throw new DepositOwnerMismatchError(params.userAddress, authorizationSignature.args.owner);
|
|
@@ -46,8 +46,9 @@ export const blueWithdrawBuyCallback = (params) => {
|
|
|
46
46
|
const { callbackAddress, userAddress, shares } = params.args;
|
|
47
47
|
validateMarketParamsId(marketParams);
|
|
48
48
|
validateUint256Field("shares", shares);
|
|
49
|
-
if (shares === 0n)
|
|
49
|
+
if (shares === 0n) {
|
|
50
50
|
throw new NonPositiveInputError("shares", shares);
|
|
51
|
+
}
|
|
51
52
|
let tx = {
|
|
52
53
|
to: getChainAddress(chainId, "blue"),
|
|
53
54
|
value: 0n,
|
|
@@ -62,10 +62,10 @@ export const resolveBundlesFunding = (params) => {
|
|
|
62
62
|
}
|
|
63
63
|
const assets = amount ?? nativeAmount ?? 0n;
|
|
64
64
|
if (assets < 0n) {
|
|
65
|
-
throw new NegativeInputError(amount
|
|
65
|
+
throw new NegativeInputError(amount == null ? "nativeAmount" : "amount", assets);
|
|
66
66
|
}
|
|
67
67
|
if (assets === 0n) {
|
|
68
|
-
throw new NonPositiveInputError(amount
|
|
68
|
+
throw new NonPositiveInputError(amount == null ? "nativeAmount" : "amount", assets);
|
|
69
69
|
}
|
|
70
70
|
return { assets, value: nativeAmount ?? 0n };
|
|
71
71
|
};
|
|
@@ -102,11 +102,13 @@ export const resolveBundlesFunding = (params) => {
|
|
|
102
102
|
*/
|
|
103
103
|
export const getBundlesTokenPermit = (params) => {
|
|
104
104
|
const { requirementSignature } = params;
|
|
105
|
-
if (requirementSignature == null)
|
|
105
|
+
if (requirementSignature == null) {
|
|
106
106
|
return { ...EMPTY_TOKEN_PERMIT };
|
|
107
|
+
}
|
|
107
108
|
const { type } = requirementSignature.action;
|
|
108
|
-
if (type !== "permit" && type !== "permit2SignatureTransfer")
|
|
109
|
+
if (type !== "permit" && type !== "permit2SignatureTransfer") {
|
|
109
110
|
throw new UnsupportedRequirementSignatureError(type);
|
|
111
|
+
}
|
|
110
112
|
if (!isAddressEqual(requirementSignature.args.owner, params.userAddress)) {
|
|
111
113
|
throw new DepositOwnerMismatchError(params.userAddress, requirementSignature.args.owner);
|
|
112
114
|
}
|
|
@@ -354,10 +356,12 @@ export const getBundlesSharesPermit = (params) => {
|
|
|
354
356
|
* from the operation's, or when a carried action nonce is inconsistent with the signed nonce.
|
|
355
357
|
*/
|
|
356
358
|
export const selectBundlesTokenRequirementSignature = (signatures, expected) => {
|
|
357
|
-
if (signatures == null)
|
|
359
|
+
if (signatures == null) {
|
|
358
360
|
return undefined;
|
|
359
|
-
|
|
361
|
+
}
|
|
362
|
+
if (signatures.length === 0) {
|
|
360
363
|
return undefined;
|
|
364
|
+
}
|
|
361
365
|
const selected = signatures.filter((signature) => signature.action.type === "permit" ||
|
|
362
366
|
signature.action.type === "permit2SignatureTransfer");
|
|
363
367
|
if (selected.length !== signatures.length) {
|
|
@@ -369,8 +373,9 @@ export const selectBundlesTokenRequirementSignature = (signatures, expected) =>
|
|
|
369
373
|
throw new AmbiguousRequirementSignaturesError("permit", selected.length);
|
|
370
374
|
}
|
|
371
375
|
const selectedSignature = selected[0];
|
|
372
|
-
if (selectedSignature == null)
|
|
376
|
+
if (selectedSignature == null) {
|
|
373
377
|
return undefined;
|
|
378
|
+
}
|
|
374
379
|
const { action } = selectedSignature;
|
|
375
380
|
if (!isAddressEqual(action.args.spender, expected.spender)) {
|
|
376
381
|
throw new BundlesPermitMismatchError({
|
|
@@ -379,9 +384,9 @@ export const selectBundlesTokenRequirementSignature = (signatures, expected) =>
|
|
|
379
384
|
actual: action.args.spender,
|
|
380
385
|
});
|
|
381
386
|
}
|
|
382
|
-
const actualAmount = selectedSignature.args.amount
|
|
383
|
-
?
|
|
384
|
-
:
|
|
387
|
+
const actualAmount = selectedSignature.args.amount === expected.amount
|
|
388
|
+
? action.args.amount
|
|
389
|
+
: selectedSignature.args.amount;
|
|
385
390
|
if (actualAmount !== expected.amount) {
|
|
386
391
|
throw new BundlesPermitMismatchError({
|
|
387
392
|
field: "amount",
|
|
@@ -389,9 +394,9 @@ export const selectBundlesTokenRequirementSignature = (signatures, expected) =>
|
|
|
389
394
|
actual: String(actualAmount),
|
|
390
395
|
});
|
|
391
396
|
}
|
|
392
|
-
const actualDeadline = selectedSignature.args.deadline
|
|
393
|
-
?
|
|
394
|
-
:
|
|
397
|
+
const actualDeadline = selectedSignature.args.deadline === expected.deadline
|
|
398
|
+
? action.args.deadline
|
|
399
|
+
: selectedSignature.args.deadline;
|
|
395
400
|
if (actualDeadline !== expected.deadline) {
|
|
396
401
|
throw new BundlesPermitMismatchError({
|
|
397
402
|
field: "deadline",
|
|
@@ -427,8 +432,9 @@ export const selectBundlesTokenRequirementSignature = (signatures, expected) =>
|
|
|
427
432
|
*/
|
|
428
433
|
export const selectBundlesSharesPermitSignature = (signatures, expected) => {
|
|
429
434
|
const { permit } = selectRequirementSignatures(signatures, { permit: true });
|
|
430
|
-
if (permit == null)
|
|
435
|
+
if (permit == null) {
|
|
431
436
|
return undefined;
|
|
437
|
+
}
|
|
432
438
|
const { action } = permit;
|
|
433
439
|
if (action.type !== "permit") {
|
|
434
440
|
throw new BundlesPermitMismatchError({
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { Address } 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
|
/** Plain onchain state used by {@link resolveBundlesTokenRequirements}. */
|
|
4
4
|
export type BundlesTokenRequirementsState = {
|
|
5
5
|
readonly type: "approval";
|
|
@@ -31,7 +31,7 @@ export type BundlesTokenRequirementsState = {
|
|
|
31
31
|
* @param params.amount - Exact pull amount in the token's smallest unit; zero returns no requirements.
|
|
32
32
|
* @param params.deadline - Signature expiration as a Unix timestamp in seconds; in the
|
|
33
33
|
* SignatureTransfer branch it must be positive, within uint256, and in the future.
|
|
34
|
-
* @param params.now -
|
|
34
|
+
* @param params.now - See {@link ReferenceTimestampParams.now}.
|
|
35
35
|
* @param params.state - Prefetched state for either classic approval or Permit2 SignatureTransfer.
|
|
36
36
|
* @param params.state.type - `approval` for a direct allowance or `permit2SignatureTransfer` for a signed pull.
|
|
37
37
|
* @param params.state.allowance - In the approval branch, current token allowance from `owner` to `spender`.
|
|
@@ -74,6 +74,5 @@ export declare const resolveBundlesTokenRequirements: (params: {
|
|
|
74
74
|
readonly chainId: number;
|
|
75
75
|
readonly amount: bigint;
|
|
76
76
|
readonly deadline: bigint;
|
|
77
|
-
readonly now?: bigint;
|
|
78
77
|
readonly state: BundlesTokenRequirementsState;
|
|
79
|
-
}) => readonly (Readonly<Transaction<ERC20ApprovalAction>> | BundlesTokenSignatureRequirement)[];
|
|
78
|
+
} & ReferenceTimestampParams) => readonly (Readonly<Transaction<ERC20ApprovalAction>> | BundlesTokenSignatureRequirement)[];
|
|
@@ -24,7 +24,7 @@ import { getRequirementsApproval } from "../requirements/getRequirementsApproval
|
|
|
24
24
|
* @param params.amount - Exact pull amount in the token's smallest unit; zero returns no requirements.
|
|
25
25
|
* @param params.deadline - Signature expiration as a Unix timestamp in seconds; in the
|
|
26
26
|
* SignatureTransfer branch it must be positive, within uint256, and in the future.
|
|
27
|
-
* @param params.now -
|
|
27
|
+
* @param params.now - See {@link ReferenceTimestampParams.now}.
|
|
28
28
|
* @param params.state - Prefetched state for either classic approval or Permit2 SignatureTransfer.
|
|
29
29
|
* @param params.state.type - `approval` for a direct allowance or `permit2SignatureTransfer` for a signed pull.
|
|
30
30
|
* @param params.state.allowance - In the approval branch, current token allowance from `owner` to `spender`.
|
|
@@ -68,8 +68,9 @@ export const resolveBundlesTokenRequirements = (params) => {
|
|
|
68
68
|
});
|
|
69
69
|
// Reject invalid pulls before an approval encoder can cap the requested amount.
|
|
70
70
|
validateUint256Field("amount", params.amount);
|
|
71
|
-
if (params.amount === 0n)
|
|
71
|
+
if (params.amount === 0n) {
|
|
72
72
|
return [];
|
|
73
|
+
}
|
|
73
74
|
if (params.state.type === "approval") {
|
|
74
75
|
return getRequirementsApproval({
|
|
75
76
|
address: params.token,
|
|
@@ -5,7 +5,8 @@ export type { MidnightCancelAndMakeParams, MidnightMakeBorrowCollateral, Midnigh
|
|
|
5
5
|
* Encodes `MidnightBundlesV2.midnightBundlesV2CancelAndMake` for `msg.sender`: cancel previous
|
|
6
6
|
* groups under consumption guards, optionally park loan assets on Morpho Blue for the maker's
|
|
7
7
|
* `BlueBuyCallback` or supply collateral, activate `root`, and publish `payload`.
|
|
8
|
-
* Without `publication`, it only cancels groups (
|
|
8
|
+
* Without `publication`, it only cancels groups; `client.morpho.midnight(chainId).cancelOffers(...)`
|
|
9
|
+
* does not use this builder and calls Midnight directly through `midnightCancelOffers`.
|
|
9
10
|
* Execution reverts as a whole if any group's consumption exceeds its `maxConsumed` ceiling.
|
|
10
11
|
* The builder snapshots every input field once before validation and encoding. It checks root,
|
|
11
12
|
* groups, cancellation groups, Blue callback salt, and root-signature `r`/`s` as 32-byte hex and
|
|
@@ -23,7 +23,8 @@ const emptyMidnightMarket = {
|
|
|
23
23
|
* Encodes `MidnightBundlesV2.midnightBundlesV2CancelAndMake` for `msg.sender`: cancel previous
|
|
24
24
|
* groups under consumption guards, optionally park loan assets on Morpho Blue for the maker's
|
|
25
25
|
* `BlueBuyCallback` or supply collateral, activate `root`, and publish `payload`.
|
|
26
|
-
* Without `publication`, it only cancels groups (
|
|
26
|
+
* Without `publication`, it only cancels groups; `client.morpho.midnight(chainId).cancelOffers(...)`
|
|
27
|
+
* does not use this builder and calls Midnight directly through `midnightCancelOffers`.
|
|
27
28
|
* Execution reverts as a whole if any group's consumption exceeds its `maxConsumed` ceiling.
|
|
28
29
|
* The builder snapshots every input field once before validation and encoding. It checks root,
|
|
29
30
|
* groups, cancellation groups, Blue callback salt, and root-signature `r`/`s` as 32-byte hex and
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
import { type Address, type Hex } from "viem";
|
|
2
|
+
import { type Metadata, type MidnightCancelOffersAction, type Transaction } from "../../types/index.js";
|
|
3
|
+
/** Parameters for a direct Midnight cancellation of one or more offer groups. */
|
|
4
|
+
export interface MidnightCancelOffersParams {
|
|
5
|
+
readonly chainId: number;
|
|
6
|
+
readonly groups: readonly Hex[];
|
|
7
|
+
readonly onBehalf: Address;
|
|
8
|
+
readonly metadata?: Metadata;
|
|
9
|
+
}
|
|
10
|
+
/**
|
|
11
|
+
* Encodes a full cancellation of one or more offer groups as a direct call to Midnight.
|
|
12
|
+
*
|
|
13
|
+
* One group encodes a bare `setConsumed(group, maxUint128, onBehalf)`. Two or more groups encode
|
|
14
|
+
* one Midnight `multicall` holding one such `setConsumed` call per group, in list order; the batch
|
|
15
|
+
* cancels every group or none. Only the single-group encoding is matchable by a wallet policy that
|
|
16
|
+
* allows `setConsumed` by method name: a batch is a `multicall` call, so cancel one group per
|
|
17
|
+
* transaction when the signer's policy names `setConsumed`.
|
|
18
|
+
*
|
|
19
|
+
* The amount is always `maxUint128`, which Midnight never rejects, so cancelling a group again
|
|
20
|
+
* succeeds. Cancellation is per group: it does not unratify roots or revoke authorizations. The
|
|
21
|
+
* transaction never targets `MidnightBundlesV2` and needs no prior authorization or approval.
|
|
22
|
+
*
|
|
23
|
+
* @param params.chainId - Chain id used to resolve `Midnight`.
|
|
24
|
+
* @param params.groups - Nonempty list of distinct 32-byte offer groups to cancel.
|
|
25
|
+
* @param params.onBehalf - Maker whose groups are cancelled. `onBehalf`, or an operator it
|
|
26
|
+
* authorized on Midnight, must send the transaction; otherwise Midnight reverts
|
|
27
|
+
* `Unauthorized()` and no group changes.
|
|
28
|
+
* @param params.metadata - Optional analytics metadata appended to calldata.
|
|
29
|
+
* @returns A deep-frozen `Transaction<MidnightCancelOffersAction>` targeting `Midnight`.
|
|
30
|
+
* @throws {MidnightCalldataEncodingError} when `onBehalf` is not a valid address.
|
|
31
|
+
* @throws {MidnightZeroOnBehalfError} when `onBehalf` is the zero address.
|
|
32
|
+
* @throws {EmptyMidnightGroupCancellationsError} when `groups` is empty.
|
|
33
|
+
* @throws {InvalidMidnightHexInputError} when a group is not 32-byte hex.
|
|
34
|
+
* @throws {DuplicateMidnightGroupCancellationError} when a group appears more than once.
|
|
35
|
+
* @throws {UnsupportedChainIdError} when the chain is absent from the address registry.
|
|
36
|
+
* @throws {UnknownAddressError} when the chain has no `midnight` deployment.
|
|
37
|
+
* @example
|
|
38
|
+
* ```ts
|
|
39
|
+
* import { midnightCancelOffers } from "@morpho-org/morpho-sdk";
|
|
40
|
+
* import type { Address, Hex } from "viem";
|
|
41
|
+
*
|
|
42
|
+
* declare const maker: Address;
|
|
43
|
+
* declare const group: Hex;
|
|
44
|
+
*
|
|
45
|
+
* // One group: calldata is `setConsumed(group, maxUint128, maker)`.
|
|
46
|
+
* const tx = midnightCancelOffers({
|
|
47
|
+
* chainId: 8453,
|
|
48
|
+
* groups: [group],
|
|
49
|
+
* onBehalf: maker,
|
|
50
|
+
* });
|
|
51
|
+
* // tx.action => { type: "midnightCancelOffers", args: { groups: [group], onBehalf: maker } }
|
|
52
|
+
* ```
|
|
53
|
+
*/
|
|
54
|
+
export declare const midnightCancelOffers: (params: MidnightCancelOffersParams) => Readonly<Transaction<MidnightCancelOffersAction>>;
|
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
import { midnightAbi } from "@morpho-org/midnight-sdk";
|
|
2
|
+
import { deepFreeze, getChainAddress } from "@morpho-org/morpho-ts";
|
|
3
|
+
import { isAddressEqual, maxUint128, zeroAddress, } from "viem";
|
|
4
|
+
import { encodeMidnightCalldata } from "../../helpers/encodeMidnightCalldata.js";
|
|
5
|
+
import { addTransactionMetadata } from "../../helpers/index.js";
|
|
6
|
+
import { validateMidnightAddress } from "../../helpers/validateMidnightAccount.js";
|
|
7
|
+
import { validateMidnightBytes32 } from "../../helpers/validateMidnightPublication.js";
|
|
8
|
+
import { DuplicateMidnightGroupCancellationError, EmptyMidnightGroupCancellationsError, MidnightZeroOnBehalfError, } from "../../types/index.js";
|
|
9
|
+
/**
|
|
10
|
+
* Encodes a full cancellation of one or more offer groups as a direct call to Midnight.
|
|
11
|
+
*
|
|
12
|
+
* One group encodes a bare `setConsumed(group, maxUint128, onBehalf)`. Two or more groups encode
|
|
13
|
+
* one Midnight `multicall` holding one such `setConsumed` call per group, in list order; the batch
|
|
14
|
+
* cancels every group or none. Only the single-group encoding is matchable by a wallet policy that
|
|
15
|
+
* allows `setConsumed` by method name: a batch is a `multicall` call, so cancel one group per
|
|
16
|
+
* transaction when the signer's policy names `setConsumed`.
|
|
17
|
+
*
|
|
18
|
+
* The amount is always `maxUint128`, which Midnight never rejects, so cancelling a group again
|
|
19
|
+
* succeeds. Cancellation is per group: it does not unratify roots or revoke authorizations. The
|
|
20
|
+
* transaction never targets `MidnightBundlesV2` and needs no prior authorization or approval.
|
|
21
|
+
*
|
|
22
|
+
* @param params.chainId - Chain id used to resolve `Midnight`.
|
|
23
|
+
* @param params.groups - Nonempty list of distinct 32-byte offer groups to cancel.
|
|
24
|
+
* @param params.onBehalf - Maker whose groups are cancelled. `onBehalf`, or an operator it
|
|
25
|
+
* authorized on Midnight, must send the transaction; otherwise Midnight reverts
|
|
26
|
+
* `Unauthorized()` and no group changes.
|
|
27
|
+
* @param params.metadata - Optional analytics metadata appended to calldata.
|
|
28
|
+
* @returns A deep-frozen `Transaction<MidnightCancelOffersAction>` targeting `Midnight`.
|
|
29
|
+
* @throws {MidnightCalldataEncodingError} when `onBehalf` is not a valid address.
|
|
30
|
+
* @throws {MidnightZeroOnBehalfError} when `onBehalf` is the zero address.
|
|
31
|
+
* @throws {EmptyMidnightGroupCancellationsError} when `groups` is empty.
|
|
32
|
+
* @throws {InvalidMidnightHexInputError} when a group is not 32-byte hex.
|
|
33
|
+
* @throws {DuplicateMidnightGroupCancellationError} when a group appears more than once.
|
|
34
|
+
* @throws {UnsupportedChainIdError} when the chain is absent from the address registry.
|
|
35
|
+
* @throws {UnknownAddressError} when the chain has no `midnight` deployment.
|
|
36
|
+
* @example
|
|
37
|
+
* ```ts
|
|
38
|
+
* import { midnightCancelOffers } from "@morpho-org/morpho-sdk";
|
|
39
|
+
* import type { Address, Hex } from "viem";
|
|
40
|
+
*
|
|
41
|
+
* declare const maker: Address;
|
|
42
|
+
* declare const group: Hex;
|
|
43
|
+
*
|
|
44
|
+
* // One group: calldata is `setConsumed(group, maxUint128, maker)`.
|
|
45
|
+
* const tx = midnightCancelOffers({
|
|
46
|
+
* chainId: 8453,
|
|
47
|
+
* groups: [group],
|
|
48
|
+
* onBehalf: maker,
|
|
49
|
+
* });
|
|
50
|
+
* // tx.action => { type: "midnightCancelOffers", args: { groups: [group], onBehalf: maker } }
|
|
51
|
+
* ```
|
|
52
|
+
*/
|
|
53
|
+
export const midnightCancelOffers = (params) => {
|
|
54
|
+
const { chainId, onBehalf, metadata } = params;
|
|
55
|
+
// Copy the list so validation and encoding read one snapshot and the caller's array stays unfrozen.
|
|
56
|
+
const groups = [...params.groups];
|
|
57
|
+
// Reject a malformed account before comparing it with the zero address.
|
|
58
|
+
validateMidnightAddress("onBehalf", onBehalf);
|
|
59
|
+
if (isAddressEqual(onBehalf, zeroAddress)) {
|
|
60
|
+
throw new MidnightZeroOnBehalfError("onBehalf");
|
|
61
|
+
}
|
|
62
|
+
if (groups.length === 0) {
|
|
63
|
+
throw new EmptyMidnightGroupCancellationsError();
|
|
64
|
+
}
|
|
65
|
+
const seen = new Set();
|
|
66
|
+
for (const [index, group] of groups.entries()) {
|
|
67
|
+
// Validation only; rejects groups that are not 32-byte hex.
|
|
68
|
+
validateMidnightBytes32(`groups[${index}]`, group);
|
|
69
|
+
const key = group.toLowerCase();
|
|
70
|
+
if (seen.has(key)) {
|
|
71
|
+
throw new DuplicateMidnightGroupCancellationError({ index, group });
|
|
72
|
+
}
|
|
73
|
+
seen.add(key);
|
|
74
|
+
}
|
|
75
|
+
const midnight = getChainAddress(chainId, "midnight");
|
|
76
|
+
const calls = groups.map((group) => encodeMidnightCalldata({
|
|
77
|
+
abi: midnightAbi,
|
|
78
|
+
functionName: "setConsumed",
|
|
79
|
+
args: [group, maxUint128, onBehalf],
|
|
80
|
+
}));
|
|
81
|
+
const [single] = calls;
|
|
82
|
+
let tx = {
|
|
83
|
+
to: midnight,
|
|
84
|
+
value: 0n,
|
|
85
|
+
// A single cancellation stays a bare `setConsumed` so a method-name policy can match it.
|
|
86
|
+
data: calls.length === 1 && single !== undefined
|
|
87
|
+
? single
|
|
88
|
+
: encodeMidnightCalldata({
|
|
89
|
+
abi: midnightAbi,
|
|
90
|
+
functionName: "multicall",
|
|
91
|
+
args: [calls],
|
|
92
|
+
}),
|
|
93
|
+
};
|
|
94
|
+
if (metadata) {
|
|
95
|
+
tx = addTransactionMetadata(tx, metadata);
|
|
96
|
+
}
|
|
97
|
+
return deepFreeze({
|
|
98
|
+
...tx,
|
|
99
|
+
action: {
|
|
100
|
+
type: "midnightCancelOffers",
|
|
101
|
+
args: { groups, onBehalf },
|
|
102
|
+
},
|
|
103
|
+
});
|
|
104
|
+
};
|
|
@@ -46,8 +46,9 @@ export const midnightSupplyCollateralBatch = (params) => {
|
|
|
46
46
|
// Direct batches require one entry per index rather than summing duplicates.
|
|
47
47
|
validateMidnightCollateralBatch(params.collateralSupplies, new EmptyMidnightCollateralSuppliesError());
|
|
48
48
|
const calls = params.collateralSupplies.map(({ collateralIndex, assets }) => {
|
|
49
|
-
if (assets <= 0n)
|
|
49
|
+
if (assets <= 0n) {
|
|
50
50
|
throw new NonPositiveInputError("assets", assets);
|
|
51
|
+
}
|
|
51
52
|
validateMidnightUint128Field("assets", assets);
|
|
52
53
|
// Reject indexes not configured on the market.
|
|
53
54
|
MarketUtils.getCollateralByIndex(params.market, collateralIndex);
|
|
@@ -71,8 +72,9 @@ export const midnightSupplyCollateralBatch = (params) => {
|
|
|
71
72
|
args: [calls],
|
|
72
73
|
}),
|
|
73
74
|
};
|
|
74
|
-
if (params.metadata)
|
|
75
|
+
if (params.metadata) {
|
|
75
76
|
tx = addTransactionMetadata(tx, params.metadata);
|
|
77
|
+
}
|
|
76
78
|
return deepFreeze({
|
|
77
79
|
...tx,
|
|
78
80
|
action: {
|
|
@@ -86,7 +86,7 @@ export interface MidnightSupplyCollateralTakeBorrowParams extends MidnightTakeBo
|
|
|
86
86
|
* receiver: borrower,
|
|
87
87
|
* collateralSupplies: [{ collateralIndex: 0n, assets: 2_000_000n }],
|
|
88
88
|
* takeableOffers: quote.data.takeableOffers,
|
|
89
|
-
* deadline:
|
|
89
|
+
* deadline: (await client.getBlock()).timestamp + 600n,
|
|
90
90
|
* });
|
|
91
91
|
* ```
|
|
92
92
|
*/
|
|
@@ -87,7 +87,7 @@ import { EmptyMidnightCollateralSuppliesError, UnboundedMidnightTakeInputError,
|
|
|
87
87
|
* receiver: borrower,
|
|
88
88
|
* collateralSupplies: [{ collateralIndex: 0n, assets: 2_000_000n }],
|
|
89
89
|
* takeableOffers: quote.data.takeableOffers,
|
|
90
|
-
* deadline:
|
|
90
|
+
* deadline: (await client.getBlock()).timestamp + 600n,
|
|
91
91
|
* });
|
|
92
92
|
* ```
|
|
93
93
|
*/
|
|
@@ -147,8 +147,9 @@ export const midnightSupplyCollateralTakeBorrow = (params) => {
|
|
|
147
147
|
throw new UnboundedMidnightTakeInputError("deadline");
|
|
148
148
|
}
|
|
149
149
|
validateDeadline(params.deadline);
|
|
150
|
-
if (params.referralFeeRecipient !== undefined)
|
|
150
|
+
if (params.referralFeeRecipient !== undefined) {
|
|
151
151
|
validateMidnightAddress("referralFeeRecipient", params.referralFeeRecipient);
|
|
152
|
+
}
|
|
152
153
|
const { referralFeePct, referralFeeRecipient } = validateReferralFee(params);
|
|
153
154
|
validateMidnightReferralFeeCap(referralFeePct);
|
|
154
155
|
validateMidnightSellTargetBounds({ target, referralFeePct });
|
|
@@ -77,7 +77,7 @@ export interface MidnightTakeBorrowParams extends MidnightReferralFeeParams {
|
|
|
77
77
|
* target: { type: "assets", assets: 1_000_000n, maxUnits: 1_100_000n },
|
|
78
78
|
* receiver: borrower,
|
|
79
79
|
* takeableOffers: quote.data.takeableOffers,
|
|
80
|
-
* deadline:
|
|
80
|
+
* deadline: (await client.getBlock()).timestamp + 600n,
|
|
81
81
|
* });
|
|
82
82
|
* ```
|
|
83
83
|
*/
|
|
@@ -74,7 +74,7 @@ import { UnboundedMidnightTakeInputError, } from "../../types/index.js";
|
|
|
74
74
|
* target: { type: "assets", assets: 1_000_000n, maxUnits: 1_100_000n },
|
|
75
75
|
* receiver: borrower,
|
|
76
76
|
* takeableOffers: quote.data.takeableOffers,
|
|
77
|
-
* deadline:
|
|
77
|
+
* deadline: (await client.getBlock()).timestamp + 600n,
|
|
78
78
|
* });
|
|
79
79
|
* ```
|
|
80
80
|
*/
|
|
@@ -125,8 +125,9 @@ export const midnightTakeBorrow = (params) => {
|
|
|
125
125
|
throw new UnboundedMidnightTakeInputError("deadline");
|
|
126
126
|
}
|
|
127
127
|
validateDeadline(params.deadline);
|
|
128
|
-
if (params.referralFeeRecipient !== undefined)
|
|
128
|
+
if (params.referralFeeRecipient !== undefined) {
|
|
129
129
|
validateMidnightAddress("referralFeeRecipient", params.referralFeeRecipient);
|
|
130
|
+
}
|
|
130
131
|
const { referralFeePct, referralFeeRecipient } = validateReferralFee(params);
|
|
131
132
|
validateMidnightReferralFeeCap(referralFeePct);
|
|
132
133
|
validateMidnightSellTargetBounds({ target, referralFeePct });
|
|
@@ -81,7 +81,7 @@ export interface MidnightTakeLendParams extends MidnightReferralFeeParams {
|
|
|
81
81
|
* target: { type: "assets", assets: 1_000_000n, minUnits: 900_000n },
|
|
82
82
|
* takeableOffers: quote.data.takeableOffers,
|
|
83
83
|
* maxContinuousFee: maxUint256,
|
|
84
|
-
* deadline:
|
|
84
|
+
* deadline: (await client.getBlock()).timestamp + 600n,
|
|
85
85
|
* });
|
|
86
86
|
* ```
|
|
87
87
|
*/
|
|
@@ -71,7 +71,7 @@ import { UnboundedMidnightTakeInputError, } from "../../types/index.js";
|
|
|
71
71
|
* target: { type: "assets", assets: 1_000_000n, minUnits: 900_000n },
|
|
72
72
|
* takeableOffers: quote.data.takeableOffers,
|
|
73
73
|
* maxContinuousFee: maxUint256,
|
|
74
|
-
* deadline:
|
|
74
|
+
* deadline: (await client.getBlock()).timestamp + 600n,
|
|
75
75
|
* });
|
|
76
76
|
* ```
|
|
77
77
|
*/
|
|
@@ -116,8 +116,9 @@ export const midnightTakeLend = (params) => {
|
|
|
116
116
|
throw new UnboundedMidnightTakeInputError("deadline");
|
|
117
117
|
}
|
|
118
118
|
validateDeadline(params.deadline);
|
|
119
|
-
if (params.referralFeeRecipient !== undefined)
|
|
119
|
+
if (params.referralFeeRecipient !== undefined) {
|
|
120
120
|
validateMidnightAddress("referralFeeRecipient", params.referralFeeRecipient);
|
|
121
|
+
}
|
|
121
122
|
const { referralFeePct, referralFeeRecipient } = validateReferralFee(params);
|
|
122
123
|
validateMidnightReferralFeeCap(referralFeePct);
|
|
123
124
|
if (referralFeePct > 0n) {
|
|
@@ -107,7 +107,7 @@ export interface MidnightTakeRepayWithdrawCollateralParams extends MidnightRefer
|
|
|
107
107
|
* collateralWithdrawals: [{ collateralIndex: 0n, assets: maxUint256 }],
|
|
108
108
|
* collateralReceiver: borrower,
|
|
109
109
|
* maxContinuousFee: maxUint256,
|
|
110
|
-
* deadline:
|
|
110
|
+
* deadline: (await client.getBlock()).timestamp + 600n,
|
|
111
111
|
* });
|
|
112
112
|
* ```
|
|
113
113
|
*/
|
|
@@ -90,7 +90,7 @@ import { NonPositiveInputError, UnboundedMidnightTakeInputError, } from "../../t
|
|
|
90
90
|
* collateralWithdrawals: [{ collateralIndex: 0n, assets: maxUint256 }],
|
|
91
91
|
* collateralReceiver: borrower,
|
|
92
92
|
* maxContinuousFee: maxUint256,
|
|
93
|
-
* deadline:
|
|
93
|
+
* deadline: (await client.getBlock()).timestamp + 600n,
|
|
94
94
|
* });
|
|
95
95
|
* ```
|
|
96
96
|
*/
|
|
@@ -151,8 +151,9 @@ export const midnightTakeRepayWithdrawCollateral = (params) => {
|
|
|
151
151
|
throw new UnboundedMidnightTakeInputError("deadline");
|
|
152
152
|
}
|
|
153
153
|
validateDeadline(params.deadline);
|
|
154
|
-
if (params.referralFeeRecipient !== undefined)
|
|
154
|
+
if (params.referralFeeRecipient !== undefined) {
|
|
155
155
|
validateMidnightAddress("referralFeeRecipient", params.referralFeeRecipient);
|
|
156
|
+
}
|
|
156
157
|
const { referralFeePct, referralFeeRecipient } = validateReferralFee(params);
|
|
157
158
|
validateMidnightReferralFeeCap(referralFeePct);
|
|
158
159
|
if (referralFeePct > 0n) {
|
|
@@ -73,7 +73,7 @@ export interface MidnightTakeWithdrawParams extends MidnightReferralFeeParams {
|
|
|
73
73
|
* target: { type: "units", units: credit, minSellerAssets: 990_000n },
|
|
74
74
|
* receiver: lender,
|
|
75
75
|
* takeableOffers: quote.data.takeableOffers,
|
|
76
|
-
* deadline:
|
|
76
|
+
* deadline: (await client.getBlock()).timestamp + 600n,
|
|
77
77
|
* });
|
|
78
78
|
* ```
|
|
79
79
|
*/
|
|
@@ -60,8 +60,9 @@ const validateParams = (params) => {
|
|
|
60
60
|
throw new UnboundedMidnightTakeInputError("deadline");
|
|
61
61
|
}
|
|
62
62
|
validateDeadline(params.deadline);
|
|
63
|
-
if (params.referralFeeRecipient !== undefined)
|
|
63
|
+
if (params.referralFeeRecipient !== undefined) {
|
|
64
64
|
validateMidnightAddress("referralFeeRecipient", params.referralFeeRecipient);
|
|
65
|
+
}
|
|
65
66
|
const { referralFeePct, referralFeeRecipient } = validateReferralFee(params);
|
|
66
67
|
validateMidnightReferralFeeCap(referralFeePct);
|
|
67
68
|
validateMidnightSellTargetBounds({ target, referralFeePct });
|
|
@@ -134,7 +135,7 @@ const validateParams = (params) => {
|
|
|
134
135
|
* target: { type: "units", units: credit, minSellerAssets: 990_000n },
|
|
135
136
|
* receiver: lender,
|
|
136
137
|
* takeableOffers: quote.data.takeableOffers,
|
|
137
|
-
* deadline:
|
|
138
|
+
* deadline: (await client.getBlock()).timestamp + 600n,
|
|
138
139
|
* });
|
|
139
140
|
* ```
|
|
140
141
|
*/
|