@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/errors.d.ts
CHANGED
|
@@ -4,4 +4,4 @@ UnsupportedPreLiquidationParamsError as UnsupportedBluePreLiquidationParamsError
|
|
|
4
4
|
export { getUnsupportedVaultV2Adapter as getBlueUnsupportedVaultV2Adapter, InvalidNumberError, InvalidPermitDomainChainIdError, InvalidPermitDomainVerifyingContractError, isUnknownOfFactoryError as isBlueUnknownOfFactoryError, MalformedTokenMetadataError, MarketParamsIdMismatchError as BlueMarketParamsIdMismatchError, MissingPermitDomainNameError, NonTupleReturnValueError, Permit2ExpirationOutOfRangeError, UnknownAbiFunctionError, UnnamedAbiOutputsError, UnsupportedPermitDomainExtensionsError, } from "@morpho-org/blue-sdk-viem";
|
|
5
5
|
export { ChainIdMismatchError as MidnightChainIdMismatchError, InvalidEcrecoverSignatureError as InvalidMidnightEcrecoverSignatureError, InvalidEcrecoverSignatureVError as InvalidMidnightEcrecoverSignatureVError, InvalidMarketParameterError as InvalidMidnightMarketParameterError, InvalidMidnightApiQuoteTargetError, InvalidMidnightApiResponseError, InvalidOfferGroupError as InvalidMidnightOfferGroupError, InvalidOfferParameterError as InvalidMidnightOfferParameterError, InvalidPositionAccrualStateError as InvalidMidnightPositionAccrualStateError, InvalidPositionAccrualTimestampError as InvalidMidnightPositionAccrualTimestampError, InvalidPositionLossFactorError as InvalidMidnightPositionLossFactorError, InvalidRateRatifierV1RateError as InvalidMidnightRateRatifierV1RateError, InvalidRateRatifierV1TickError as InvalidMidnightRateRatifierV1TickError, InvalidRateRatifierV1TimeError as InvalidMidnightRateRatifierV1TimeError, InvalidRatifierV1AddressError as InvalidMidnightRatifierV1AddressError, InvalidTickSpacingError as InvalidMidnightTickSpacingError, InvalidTreeError as InvalidMidnightTreeError, InvalidTreeHeightError as InvalidMidnightTreeHeightError, InvalidTypedDataSignatureError as InvalidMidnightTypedDataSignatureError, MidnightApiError, MidnightMempoolValidationError, PayloadDecodeError as MidnightPayloadDecodeError, PriceGreaterThanOneError as MidnightPriceGreaterThanOneError, RateRatifierV1BoundOverflowError as MidnightRateRatifierV1BoundOverflowError, RatifierV1TakerNotAllowedError as MidnightRatifierV1TakerNotAllowedError, SettlementFeeExceedsPriceError as MidnightSettlementFeeExceedsPriceError, TickOutOfRangeError as MidnightTickOutOfRangeError, UnknownCollateralIndexError as UnknownMidnightCollateralIndexError, } from "@morpho-org/midnight-sdk";
|
|
6
6
|
export type { ErrorClass } from "@morpho-org/morpho-ts";
|
|
7
|
-
export { _try, DivisionByZeroError, InvalidAddressError, InvalidBitLengthError, NegativeValueError, RegistryValueAlreadyRegisteredError, RetriesExhaustedError, RetryStoppedError, } from "@morpho-org/morpho-ts";
|
|
7
|
+
export { _try, DivisionByZeroError, InvalidAddressError, InvalidBitLengthError, MissingLocalePartError, NegativeValueError, RegistryValueAlreadyRegisteredError, RetriesExhaustedError, RetryStoppedError, } from "@morpho-org/morpho-ts";
|
package/lib/cjs/errors.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.MidnightApiError = exports.InvalidMidnightTypedDataSignatureError = exports.InvalidMidnightTreeHeightError = exports.InvalidMidnightTreeError = exports.InvalidMidnightTickSpacingError = exports.InvalidMidnightRatifierV1AddressError = exports.InvalidMidnightRateRatifierV1TimeError = exports.InvalidMidnightRateRatifierV1TickError = exports.InvalidMidnightRateRatifierV1RateError = exports.InvalidMidnightPositionLossFactorError = exports.InvalidMidnightPositionAccrualTimestampError = exports.InvalidMidnightPositionAccrualStateError = exports.InvalidMidnightOfferParameterError = exports.InvalidMidnightOfferGroupError = exports.InvalidMidnightApiResponseError = exports.InvalidMidnightApiQuoteTargetError = exports.InvalidMidnightMarketParameterError = exports.InvalidMidnightEcrecoverSignatureVError = exports.InvalidMidnightEcrecoverSignatureError = exports.MidnightChainIdMismatchError = exports.UnsupportedPermitDomainExtensionsError = exports.UnnamedAbiOutputsError = exports.UnknownAbiFunctionError = exports.Permit2ExpirationOutOfRangeError = exports.NonTupleReturnValueError = exports.MissingPermitDomainNameError = exports.BlueMarketParamsIdMismatchError = exports.MalformedTokenMetadataError = exports.isBlueUnknownOfFactoryError = exports.InvalidPermitDomainVerifyingContractError = exports.InvalidPermitDomainChainIdError = exports.InvalidNumberError = exports.getBlueUnsupportedVaultV2Adapter = exports.VaultV2Errors = exports.UnsupportedBlueVaultV2AdapterError = exports.UnsupportedBluePreLiquidationParamsError = exports.UnsupportedBlueMarketIrmError = exports.UnsupportedChainIdError = exports.UnknownBlueVaultConfigError = exports.UnknownBlueTokenPriceError = exports.UnknownBlueTokenError = exports.UnknownBlueOfFactory = exports.UnknownBlueMarketParamsError = exports.UnknownBlueMarketAllocationError = exports.UnknownBlueFactory = exports.UnknownBlueDataError = exports.UnknownAddressError = exports.InvalidBlueMarketParamsError = exports.IncompleteChainRegistryError = exports.BlueErrors = void 0;
|
|
4
|
-
exports.RetryStoppedError = exports.RetriesExhaustedError = exports.RegistryValueAlreadyRegisteredError = exports.NegativeValueError = exports.InvalidBitLengthError = exports.InvalidAddressError = exports.DivisionByZeroError = exports._try = exports.UnknownMidnightCollateralIndexError = exports.MidnightTickOutOfRangeError = exports.MidnightSettlementFeeExceedsPriceError = exports.MidnightRatifierV1TakerNotAllowedError = exports.MidnightRateRatifierV1BoundOverflowError = exports.MidnightPriceGreaterThanOneError = exports.MidnightPayloadDecodeError = exports.MidnightMempoolValidationError = void 0;
|
|
4
|
+
exports.RetryStoppedError = exports.RetriesExhaustedError = exports.RegistryValueAlreadyRegisteredError = exports.NegativeValueError = exports.MissingLocalePartError = exports.InvalidBitLengthError = exports.InvalidAddressError = exports.DivisionByZeroError = exports._try = exports.UnknownMidnightCollateralIndexError = exports.MidnightTickOutOfRangeError = exports.MidnightSettlementFeeExceedsPriceError = exports.MidnightRatifierV1TakerNotAllowedError = exports.MidnightRateRatifierV1BoundOverflowError = exports.MidnightPriceGreaterThanOneError = exports.MidnightPayloadDecodeError = exports.MidnightMempoolValidationError = void 0;
|
|
5
5
|
var blue_sdk_1 = require("@morpho-org/blue-sdk");
|
|
6
6
|
Object.defineProperty(exports, "BlueErrors", { enumerable: true, get: function () { return blue_sdk_1.BlueErrors; } });
|
|
7
7
|
Object.defineProperty(exports, "IncompleteChainRegistryError", { enumerable: true, get: function () { return blue_sdk_1.IncompleteChainRegistryError; } });
|
|
@@ -69,6 +69,7 @@ Object.defineProperty(exports, "_try", { enumerable: true, get: function () { re
|
|
|
69
69
|
Object.defineProperty(exports, "DivisionByZeroError", { enumerable: true, get: function () { return morpho_ts_1.DivisionByZeroError; } });
|
|
70
70
|
Object.defineProperty(exports, "InvalidAddressError", { enumerable: true, get: function () { return morpho_ts_1.InvalidAddressError; } });
|
|
71
71
|
Object.defineProperty(exports, "InvalidBitLengthError", { enumerable: true, get: function () { return morpho_ts_1.InvalidBitLengthError; } });
|
|
72
|
+
Object.defineProperty(exports, "MissingLocalePartError", { enumerable: true, get: function () { return morpho_ts_1.MissingLocalePartError; } });
|
|
72
73
|
Object.defineProperty(exports, "NegativeValueError", { enumerable: true, get: function () { return morpho_ts_1.NegativeValueError; } });
|
|
73
74
|
Object.defineProperty(exports, "RegistryValueAlreadyRegisteredError", { enumerable: true, get: function () { return morpho_ts_1.RegistryValueAlreadyRegisteredError; } });
|
|
74
75
|
Object.defineProperty(exports, "RetriesExhaustedError", { enumerable: true, get: function () { return morpho_ts_1.RetriesExhaustedError; } });
|
|
@@ -30,15 +30,17 @@ const constant_js_1 = require("./constant.js");
|
|
|
30
30
|
*/
|
|
31
31
|
function validateBlueMarketDeadShares(market, path = []) {
|
|
32
32
|
const entity = [...path, market.id];
|
|
33
|
-
if (market.deadSupplyShares == null)
|
|
33
|
+
if (market.deadSupplyShares == null) {
|
|
34
34
|
throw new error_js_1.MissingDeadSharesDataError({ entity, field: "deadSupplyShares" });
|
|
35
|
-
|
|
35
|
+
}
|
|
36
|
+
if (market.deadSupplyShares < constant_js_1.MIN_DEAD_SHARES) {
|
|
36
37
|
throw new error_js_1.InsufficientDeadSharesError({
|
|
37
38
|
entity,
|
|
38
39
|
reason: "deadShares",
|
|
39
40
|
observed: market.deadSupplyShares,
|
|
40
41
|
required: constant_js_1.MIN_DEAD_SHARES,
|
|
41
42
|
});
|
|
43
|
+
}
|
|
42
44
|
}
|
|
43
45
|
/**
|
|
44
46
|
* Checks that a Vault V1 holds at least `MIN_DEAD_SHARES` shares at `DEAD_ADDRESS` and that every
|
|
@@ -67,22 +69,25 @@ function validateBlueMarketDeadShares(market, path = []) {
|
|
|
67
69
|
*/
|
|
68
70
|
function validateVaultV1DeadShares(vault, path = []) {
|
|
69
71
|
const entity = [...path, vault.address];
|
|
70
|
-
if (vault.deadShares == null)
|
|
72
|
+
if (vault.deadShares == null) {
|
|
71
73
|
throw new error_js_1.MissingDeadSharesDataError({ entity, field: "deadShares" });
|
|
72
|
-
|
|
74
|
+
}
|
|
75
|
+
if (vault.deadShares < constant_js_1.MIN_DEAD_SHARES) {
|
|
73
76
|
throw new error_js_1.InsufficientDeadSharesError({
|
|
74
77
|
entity,
|
|
75
78
|
reason: "deadShares",
|
|
76
79
|
observed: vault.deadShares,
|
|
77
80
|
required: constant_js_1.MIN_DEAD_SHARES,
|
|
78
81
|
});
|
|
82
|
+
}
|
|
79
83
|
for (const marketId of vault.withdrawQueue) {
|
|
80
84
|
const allocation = vault.allocations.get(marketId);
|
|
81
|
-
if (allocation == null)
|
|
85
|
+
if (allocation == null) {
|
|
82
86
|
throw new error_js_1.MissingDeadSharesDataError({
|
|
83
87
|
entity: [...entity, marketId],
|
|
84
88
|
field: "allocation",
|
|
85
89
|
});
|
|
90
|
+
}
|
|
86
91
|
validateBlueMarketDeadShares(allocation.position.market, entity);
|
|
87
92
|
}
|
|
88
93
|
}
|
|
@@ -116,86 +121,117 @@ function validateVaultV1DeadShares(vault, path = []) {
|
|
|
116
121
|
function validateVaultV2DeadShares(vault, path = []) {
|
|
117
122
|
const entity = [...path, vault.address];
|
|
118
123
|
const { deadShares, deadAssets, absoluteCaps } = vault;
|
|
119
|
-
if (deadShares == null)
|
|
124
|
+
if (deadShares == null) {
|
|
120
125
|
throw new error_js_1.MissingDeadSharesDataError({ entity, field: "deadShares" });
|
|
121
|
-
|
|
126
|
+
}
|
|
127
|
+
if (deadAssets == null) {
|
|
122
128
|
throw new error_js_1.MissingDeadSharesDataError({ entity, field: "deadAssets" });
|
|
123
|
-
|
|
129
|
+
}
|
|
130
|
+
if (absoluteCaps == null) {
|
|
124
131
|
throw new error_js_1.MissingDeadSharesDataError({ entity, field: "absoluteCaps" });
|
|
125
|
-
|
|
132
|
+
}
|
|
133
|
+
if (deadShares < constant_js_1.MIN_DEAD_SHARES) {
|
|
126
134
|
throw new error_js_1.InsufficientDeadSharesError({
|
|
127
135
|
entity,
|
|
128
136
|
reason: "deadShares",
|
|
129
137
|
observed: deadShares,
|
|
130
138
|
required: constant_js_1.MIN_DEAD_SHARES,
|
|
131
139
|
});
|
|
132
|
-
|
|
140
|
+
}
|
|
141
|
+
if (deadAssets < constant_js_1.MIN_VAULT_V2_DEAD_ASSETS) {
|
|
133
142
|
throw new error_js_1.InsufficientDeadSharesError({
|
|
134
143
|
entity,
|
|
135
144
|
reason: "deadAssets",
|
|
136
145
|
observed: deadAssets,
|
|
137
146
|
required: constant_js_1.MIN_VAULT_V2_DEAD_ASSETS,
|
|
138
147
|
});
|
|
148
|
+
}
|
|
139
149
|
// Share price (totalAssets + 1) / (totalSupply + virtualShares) must exceed 1 / (10 * virtualShares).
|
|
140
150
|
const priceNumerator = (vault._totalAssets + 1n) * 10n * vault.virtualShares;
|
|
141
151
|
const priceDenominator = vault.totalSupply + vault.virtualShares;
|
|
142
|
-
if (priceNumerator <= priceDenominator)
|
|
152
|
+
if (priceNumerator <= priceDenominator) {
|
|
143
153
|
throw new error_js_1.InsufficientDeadSharesError({
|
|
144
154
|
entity,
|
|
145
155
|
reason: "sharePrice",
|
|
146
156
|
observed: priceNumerator,
|
|
147
157
|
required: priceDenominator + 1n,
|
|
148
158
|
});
|
|
149
|
-
|
|
150
|
-
const cap = absoluteCaps[id];
|
|
151
|
-
if (cap == null)
|
|
152
|
-
throw new error_js_1.MissingDeadSharesDataError({
|
|
153
|
-
entity: [...entity, adapter],
|
|
154
|
-
field: "absoluteCaps",
|
|
155
|
-
});
|
|
156
|
-
return cap;
|
|
157
|
-
};
|
|
159
|
+
}
|
|
158
160
|
for (const adapter of vault.accrualAdapters) {
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
if (capOf(id, adapter.address) > 0n)
|
|
162
|
-
validateVaultV1DeadShares(adapter.accrualVaultV1, entity);
|
|
163
|
-
}
|
|
164
|
-
else if (adapter instanceof blue_sdk_1.AccrualVaultV2MorphoMarketV1Adapter) {
|
|
165
|
-
for (const { market } of adapter.positions) {
|
|
166
|
-
const id = blue_sdk_1.VaultV2MorphoMarketV1Adapter.adapterMarketCapId(adapter.address, market.params);
|
|
167
|
-
if (capOf(id, adapter.address) > 0n)
|
|
168
|
-
validateBlueMarketDeadShares(market, entity);
|
|
169
|
-
}
|
|
170
|
-
}
|
|
171
|
-
else if (adapter instanceof blue_sdk_1.AccrualVaultV2MorphoMarketV1AdapterV2) {
|
|
172
|
-
for (const market of adapter.markets) {
|
|
173
|
-
const id = blue_sdk_1.VaultV2MorphoMarketV1AdapterV2.adapterMarketCapId(adapter.address, market.params);
|
|
174
|
-
if (capOf(id, adapter.address) > 0n)
|
|
175
|
-
validateBlueMarketDeadShares(market, entity);
|
|
176
|
-
}
|
|
177
|
-
}
|
|
178
|
-
else {
|
|
179
|
-
throw new error_js_1.MissingDeadSharesDataError({
|
|
180
|
-
entity: [...entity, adapter.address],
|
|
181
|
-
field: "adapter",
|
|
182
|
-
});
|
|
183
|
-
}
|
|
161
|
+
// Reject incomplete or underfunded adapter snapshots before checking liquidity.
|
|
162
|
+
assertAdapterDeadShares(adapter, { absoluteCaps, entity });
|
|
184
163
|
}
|
|
185
164
|
// Deposits are allocated to the liquidity market, so the snapshot must hold it even when it
|
|
186
165
|
// has no allocation yet (the adapters only list markets they currently supply to).
|
|
187
166
|
const liquidityAdapter = vault.accrualLiquidityAdapter;
|
|
188
167
|
if (vault.liquidityData === "0x" ||
|
|
189
168
|
!(liquidityAdapter instanceof blue_sdk_1.AccrualVaultV2MorphoMarketV1Adapter ||
|
|
190
|
-
liquidityAdapter instanceof blue_sdk_1.AccrualVaultV2MorphoMarketV1AdapterV2))
|
|
169
|
+
liquidityAdapter instanceof blue_sdk_1.AccrualVaultV2MorphoMarketV1AdapterV2)) {
|
|
191
170
|
return;
|
|
171
|
+
}
|
|
192
172
|
const liquidityMarketId = blue_sdk_1.MarketParams.fromHex(vault.liquidityData).id;
|
|
193
173
|
const markets = liquidityAdapter instanceof blue_sdk_1.AccrualVaultV2MorphoMarketV1Adapter
|
|
194
174
|
? liquidityAdapter.positions.map(({ market }) => market)
|
|
195
175
|
: liquidityAdapter.markets;
|
|
196
|
-
if (!markets.some(({ id }) => id === liquidityMarketId))
|
|
176
|
+
if (!markets.some(({ id }) => id === liquidityMarketId)) {
|
|
197
177
|
throw new error_js_1.MissingDeadSharesDataError({
|
|
198
178
|
entity: [...entity, liquidityAdapter.address, liquidityMarketId],
|
|
199
179
|
field: "liquidityMarket",
|
|
200
180
|
});
|
|
181
|
+
}
|
|
182
|
+
}
|
|
183
|
+
/** Reads a fetched adapter cap before applying the dead-share rule. @internal */
|
|
184
|
+
function getDeadSharesAbsoluteCap(id, { absoluteCaps, entity, adapter, }) {
|
|
185
|
+
const cap = absoluteCaps[id];
|
|
186
|
+
if (cap == null) {
|
|
187
|
+
throw new error_js_1.MissingDeadSharesDataError({
|
|
188
|
+
entity: [...entity, adapter],
|
|
189
|
+
field: "absoluteCaps",
|
|
190
|
+
});
|
|
191
|
+
}
|
|
192
|
+
return cap;
|
|
193
|
+
}
|
|
194
|
+
/** Checks the currently allocated positions of one supported adapter. @internal */
|
|
195
|
+
function assertAdapterDeadShares(adapter, { absoluteCaps, entity, }) {
|
|
196
|
+
if (adapter instanceof blue_sdk_1.AccrualVaultV2MorphoVaultV1Adapter) {
|
|
197
|
+
const id = blue_sdk_1.VaultV2MorphoVaultV1Adapter.adapterCapId(adapter.address);
|
|
198
|
+
if (getDeadSharesAbsoluteCap(id, {
|
|
199
|
+
absoluteCaps,
|
|
200
|
+
entity,
|
|
201
|
+
adapter: adapter.address,
|
|
202
|
+
}) > 0n) {
|
|
203
|
+
validateVaultV1DeadShares(adapter.accrualVaultV1, entity);
|
|
204
|
+
}
|
|
205
|
+
return;
|
|
206
|
+
}
|
|
207
|
+
if (adapter instanceof blue_sdk_1.AccrualVaultV2MorphoMarketV1Adapter) {
|
|
208
|
+
for (const { market } of adapter.positions) {
|
|
209
|
+
const id = blue_sdk_1.VaultV2MorphoMarketV1Adapter.adapterMarketCapId(adapter.address, market.params);
|
|
210
|
+
if (getDeadSharesAbsoluteCap(id, {
|
|
211
|
+
absoluteCaps,
|
|
212
|
+
entity,
|
|
213
|
+
adapter: adapter.address,
|
|
214
|
+
}) > 0n) {
|
|
215
|
+
validateBlueMarketDeadShares(market, entity);
|
|
216
|
+
}
|
|
217
|
+
}
|
|
218
|
+
return;
|
|
219
|
+
}
|
|
220
|
+
if (adapter instanceof blue_sdk_1.AccrualVaultV2MorphoMarketV1AdapterV2) {
|
|
221
|
+
for (const market of adapter.markets) {
|
|
222
|
+
const id = blue_sdk_1.VaultV2MorphoMarketV1AdapterV2.adapterMarketCapId(adapter.address, market.params);
|
|
223
|
+
if (getDeadSharesAbsoluteCap(id, {
|
|
224
|
+
absoluteCaps,
|
|
225
|
+
entity,
|
|
226
|
+
adapter: adapter.address,
|
|
227
|
+
}) > 0n) {
|
|
228
|
+
validateBlueMarketDeadShares(market, entity);
|
|
229
|
+
}
|
|
230
|
+
}
|
|
231
|
+
return;
|
|
232
|
+
}
|
|
233
|
+
throw new error_js_1.MissingDeadSharesDataError({
|
|
234
|
+
entity: [...entity, adapter.address],
|
|
235
|
+
field: "adapter",
|
|
236
|
+
});
|
|
201
237
|
}
|
|
@@ -29,8 +29,9 @@ function encodeMidnightCalldata(parameters) {
|
|
|
29
29
|
return (0, viem_1.encodeFunctionData)(parameters);
|
|
30
30
|
}
|
|
31
31
|
catch (error) {
|
|
32
|
-
if (!(error instanceof viem_1.BaseError))
|
|
32
|
+
if (!(error instanceof viem_1.BaseError)) {
|
|
33
33
|
throw error;
|
|
34
|
+
}
|
|
34
35
|
throw new index_js_1.MidnightCalldataEncodingError(String(parameters.functionName), error);
|
|
35
36
|
}
|
|
36
37
|
}
|
|
@@ -52,8 +53,9 @@ function wrapMidnightEncoding(name, encode) {
|
|
|
52
53
|
return encode();
|
|
53
54
|
}
|
|
54
55
|
catch (error) {
|
|
55
|
-
if (!(error instanceof viem_1.BaseError))
|
|
56
|
+
if (!(error instanceof viem_1.BaseError)) {
|
|
56
57
|
throw error;
|
|
58
|
+
}
|
|
57
59
|
throw new index_js_1.MidnightCalldataEncodingError(name, error);
|
|
58
60
|
}
|
|
59
61
|
}
|
|
@@ -1,5 +1,13 @@
|
|
|
1
1
|
import { type Address, type Hex } from "viem";
|
|
2
2
|
import type { Metadata } from "../types/index.js";
|
|
3
|
+
/**
|
|
4
|
+
* Replaces a device-clock metadata timestamp with the flow's explicit reference time.
|
|
5
|
+
* Returns the input unchanged when no replacement is needed; never mutates it.
|
|
6
|
+
* @throws {NegativeInputError} when the resolved bigint timestamp is negative.
|
|
7
|
+
* @throws {InputExceedsMaxError} when the resolved bigint timestamp exceeds uint32 seconds.
|
|
8
|
+
* @internal
|
|
9
|
+
*/
|
|
10
|
+
export declare function resolveTransactionMetadata(metadata: Metadata | undefined, now?: bigint): Metadata | undefined;
|
|
3
11
|
/**
|
|
4
12
|
* Adds metadata to a transaction object by concatenating additional
|
|
5
13
|
* hex-encoded data to the transaction's `data` field. The additional
|
|
@@ -29,17 +37,21 @@ import type { Metadata } from "../types/index.js";
|
|
|
29
37
|
* @returns The same `tx` object when `data` is missing, an empty string, or
|
|
30
38
|
* canonical empty calldata (`"0x"`); otherwise, a new transaction object
|
|
31
39
|
* with `data` containing any appended metadata. The input is never mutated.
|
|
40
|
+
* @throws {NegativeInputError} when an explicit bigint timestamp is negative.
|
|
41
|
+
* @throws {InputExceedsMaxError} when an explicit bigint timestamp exceeds uint32 seconds.
|
|
32
42
|
* @example
|
|
33
43
|
* ```ts
|
|
34
44
|
* import { addTransactionMetadata } from "@morpho-org/morpho-sdk";
|
|
35
45
|
* import { getChainAddresses } from "@morpho-org/morpho-sdk/addresses";
|
|
36
|
-
* import type
|
|
46
|
+
* import { type Address, createPublicClient, type Hex, http } from "viem";
|
|
37
47
|
* import { mainnet } from "viem/chains";
|
|
38
48
|
*
|
|
49
|
+
* const client = createPublicClient({ chain: mainnet, transport: http() });
|
|
39
50
|
* const { blue } = getChainAddresses(mainnet.id);
|
|
40
51
|
* const tx = { to: blue, value: 0n, data: "0x1234" as Hex };
|
|
52
|
+
* const { timestamp } = await client.getBlock();
|
|
41
53
|
* const result: { to: Address; value: bigint; data: Hex } =
|
|
42
|
-
* addTransactionMetadata(tx, { origin: "deadbeef", timestamp
|
|
54
|
+
* addTransactionMetadata(tx, { origin: "deadbeef", timestamp });
|
|
43
55
|
* // => { to: blue, value: 0n, data: "0x1234" + <4-byte timestamp> + "deadbeef" }
|
|
44
56
|
* ```
|
|
45
57
|
*/
|
|
@@ -1,8 +1,40 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.resolveTransactionMetadata = resolveTransactionMetadata;
|
|
3
4
|
exports.addTransactionMetadata = addTransactionMetadata;
|
|
4
5
|
const morpho_ts_1 = require("@morpho-org/morpho-ts");
|
|
5
6
|
const viem_1 = require("viem");
|
|
7
|
+
const error_js_1 = require("../types/error.js");
|
|
8
|
+
const MAX_METADATA_TIMESTAMP = (1n << 32n) - 1n;
|
|
9
|
+
function validateMetadataTimestamp(timestamp) {
|
|
10
|
+
if (typeof timestamp !== "bigint") {
|
|
11
|
+
return;
|
|
12
|
+
}
|
|
13
|
+
if (timestamp < 0n) {
|
|
14
|
+
throw new error_js_1.NegativeInputError("metadata.timestamp", timestamp);
|
|
15
|
+
}
|
|
16
|
+
if (timestamp > MAX_METADATA_TIMESTAMP) {
|
|
17
|
+
throw new error_js_1.InputExceedsMaxError({
|
|
18
|
+
field: "metadata.timestamp",
|
|
19
|
+
value: timestamp,
|
|
20
|
+
max: MAX_METADATA_TIMESTAMP,
|
|
21
|
+
});
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* Replaces a device-clock metadata timestamp with the flow's explicit reference time.
|
|
26
|
+
* Returns the input unchanged when no replacement is needed; never mutates it.
|
|
27
|
+
* @throws {NegativeInputError} when the resolved bigint timestamp is negative.
|
|
28
|
+
* @throws {InputExceedsMaxError} when the resolved bigint timestamp exceeds uint32 seconds.
|
|
29
|
+
* @internal
|
|
30
|
+
*/
|
|
31
|
+
function resolveTransactionMetadata(metadata, now) {
|
|
32
|
+
const resolved = metadata?.timestamp === true && now != null
|
|
33
|
+
? { ...metadata, timestamp: now }
|
|
34
|
+
: metadata;
|
|
35
|
+
validateMetadataTimestamp(resolved?.timestamp);
|
|
36
|
+
return resolved;
|
|
37
|
+
}
|
|
6
38
|
/**
|
|
7
39
|
* Adds metadata to a transaction object by concatenating additional
|
|
8
40
|
* hex-encoded data to the transaction's `data` field. The additional
|
|
@@ -32,27 +64,33 @@ const viem_1 = require("viem");
|
|
|
32
64
|
* @returns The same `tx` object when `data` is missing, an empty string, or
|
|
33
65
|
* canonical empty calldata (`"0x"`); otherwise, a new transaction object
|
|
34
66
|
* with `data` containing any appended metadata. The input is never mutated.
|
|
67
|
+
* @throws {NegativeInputError} when an explicit bigint timestamp is negative.
|
|
68
|
+
* @throws {InputExceedsMaxError} when an explicit bigint timestamp exceeds uint32 seconds.
|
|
35
69
|
* @example
|
|
36
70
|
* ```ts
|
|
37
71
|
* import { addTransactionMetadata } from "@morpho-org/morpho-sdk";
|
|
38
72
|
* import { getChainAddresses } from "@morpho-org/morpho-sdk/addresses";
|
|
39
|
-
* import type
|
|
73
|
+
* import { type Address, createPublicClient, type Hex, http } from "viem";
|
|
40
74
|
* import { mainnet } from "viem/chains";
|
|
41
75
|
*
|
|
76
|
+
* const client = createPublicClient({ chain: mainnet, transport: http() });
|
|
42
77
|
* const { blue } = getChainAddresses(mainnet.id);
|
|
43
78
|
* const tx = { to: blue, value: 0n, data: "0x1234" as Hex };
|
|
79
|
+
* const { timestamp } = await client.getBlock();
|
|
44
80
|
* const result: { to: Address; value: bigint; data: Hex } =
|
|
45
|
-
* addTransactionMetadata(tx, { origin: "deadbeef", timestamp
|
|
81
|
+
* addTransactionMetadata(tx, { origin: "deadbeef", timestamp });
|
|
46
82
|
* // => { to: blue, value: 0n, data: "0x1234" + <4-byte timestamp> + "deadbeef" }
|
|
47
83
|
* ```
|
|
48
84
|
*/
|
|
49
85
|
function addTransactionMetadata(tx, metadata) {
|
|
86
|
+
validateMetadataTimestamp(metadata.timestamp);
|
|
50
87
|
const { data, ..._tx } = tx;
|
|
51
|
-
if (!data || data === "0x")
|
|
88
|
+
if (!data || data === "0x") {
|
|
52
89
|
return tx;
|
|
90
|
+
}
|
|
53
91
|
const concatItems = [data];
|
|
54
|
-
if (metadata.timestamp) {
|
|
55
|
-
concatItems.push((0, viem_1.numberToHex)(morpho_ts_1.Time.timestamp(), { size: 4 }));
|
|
92
|
+
if (metadata.timestamp === true || typeof metadata.timestamp === "bigint") {
|
|
93
|
+
concatItems.push((0, viem_1.numberToHex)(metadata.timestamp === true ? morpho_ts_1.Time.timestamp() : metadata.timestamp, { size: 4 }));
|
|
56
94
|
}
|
|
57
95
|
try {
|
|
58
96
|
// Strip a leading "0x" / "0X" case-insensitively so callers can pass
|
|
@@ -60,15 +98,18 @@ function addTransactionMetadata(tx, metadata) {
|
|
|
60
98
|
// origin. The case-insensitive form prevents "0Xcafe" from falling
|
|
61
99
|
// through to `isHex("0x0Xcafe")` and being silently dropped.
|
|
62
100
|
const origin = metadata.origin.replace(/^0x/i, "");
|
|
63
|
-
if (!(0, viem_1.isHex)(`0x${origin}`))
|
|
101
|
+
if (!(0, viem_1.isHex)(`0x${origin}`)) {
|
|
64
102
|
throw Error("Calldata origin must consists of only hex characters");
|
|
65
|
-
|
|
103
|
+
}
|
|
104
|
+
if (origin.length > 8) {
|
|
66
105
|
throw Error("Calldata origin must be at most 8 characters long");
|
|
106
|
+
}
|
|
67
107
|
// Reject odd-length raw fragments. viem's `concatHex` would pad the
|
|
68
108
|
// stray nibble to a whole byte at broadcast, corrupting the trailing
|
|
69
109
|
// analytics byte on-chain.
|
|
70
|
-
if (origin.length % 2 !== 0)
|
|
110
|
+
if (origin.length % 2 !== 0) {
|
|
71
111
|
throw Error("Calldata origin must have an even number of hex characters");
|
|
112
|
+
}
|
|
72
113
|
concatItems.push(`0x${origin}`);
|
|
73
114
|
}
|
|
74
115
|
catch (error) {
|
|
@@ -59,20 +59,23 @@ const vaultV2ForceWithdrawPlan_js_1 = require("./vaultV2ForceWithdrawPlan.js");
|
|
|
59
59
|
*/
|
|
60
60
|
function previewVaultV2ForceWithdraw(vaultData, params) {
|
|
61
61
|
const { requestedExitAssets, timestamp, adapter: adapterOverride, userAddress, feeProjectionTimestamp = timestamp, referralFeePct = 0n, referralFeeRecipient, } = params;
|
|
62
|
-
if (requestedExitAssets <= 0n)
|
|
62
|
+
if (requestedExitAssets <= 0n) {
|
|
63
63
|
return undefined;
|
|
64
|
+
}
|
|
64
65
|
// Out of the range the action accepts, `netAssets` would quote a payout the contract can never
|
|
65
66
|
// deliver — above `withdrawnAssets` for a negative fee, non-positive at or beyond WAD.
|
|
66
|
-
if (referralFeePct < 0n || referralFeePct >= blue_sdk_1.MathLib.WAD)
|
|
67
|
+
if (referralFeePct < 0n || referralFeePct >= blue_sdk_1.MathLib.WAD) {
|
|
67
68
|
return undefined;
|
|
69
|
+
}
|
|
68
70
|
if (referralFeePct > 0n &&
|
|
69
71
|
(referralFeeRecipient == null ||
|
|
70
72
|
(0, viem_1.isAddressEqual)(referralFeeRecipient, viem_1.zeroAddress))) {
|
|
71
73
|
return undefined;
|
|
72
74
|
}
|
|
73
75
|
const eligibility = (0, vaultV2ForceWithdrawPlan_js_1.resolveVaultV2ForceWithdrawEligibility)(vaultData, adapterOverride);
|
|
74
|
-
if (eligibility.type !== "eligible")
|
|
76
|
+
if (eligibility.type !== "eligible") {
|
|
75
77
|
return undefined;
|
|
78
|
+
}
|
|
76
79
|
const capacity = (0, vaultV2ForceWithdrawPlan_js_1.computeVaultV2ForceWithdrawPlan)({
|
|
77
80
|
vaultData,
|
|
78
81
|
adapter: eligibility.adapter,
|
|
@@ -83,8 +86,9 @@ function previewVaultV2ForceWithdraw(vaultData, params) {
|
|
|
83
86
|
const exitAssets = blue_sdk_1.MathLib.min(requestedExitAssets, capacity.maxExitAssets);
|
|
84
87
|
// A vault with no exitable capacity caps `maxExitAssets` to `0`; the planner rejects a
|
|
85
88
|
// non-positive amount, so short-circuit to the "not previewable" verdict before re-planning.
|
|
86
|
-
if (exitAssets <= 0n)
|
|
89
|
+
if (exitAssets <= 0n) {
|
|
87
90
|
return undefined;
|
|
91
|
+
}
|
|
88
92
|
// Re-plan at the capped amount so every returned leg describes the same exit.
|
|
89
93
|
const plan = exitAssets === requestedExitAssets
|
|
90
94
|
? capacity
|
|
@@ -95,8 +99,42 @@ function previewVaultV2ForceWithdraw(vaultData, params) {
|
|
|
95
99
|
exitAssets,
|
|
96
100
|
timestamp,
|
|
97
101
|
});
|
|
98
|
-
if (plan.withdrawnAssets <= 0n)
|
|
102
|
+
if (plan.withdrawnAssets <= 0n) {
|
|
99
103
|
return undefined;
|
|
104
|
+
}
|
|
105
|
+
const defaultMinSharePriceE27 = computePreviewMinSharePrice(vaultData, {
|
|
106
|
+
timestamp,
|
|
107
|
+
feeProjectionTimestamp,
|
|
108
|
+
userAddress,
|
|
109
|
+
plan,
|
|
110
|
+
});
|
|
111
|
+
if (defaultMinSharePriceE27 == null ||
|
|
112
|
+
defaultMinSharePriceE27 <= 0n ||
|
|
113
|
+
defaultMinSharePriceE27 > viem_1.maxUint256) {
|
|
114
|
+
return undefined;
|
|
115
|
+
}
|
|
116
|
+
const referralFeeAssets = blue_sdk_1.MathLib.mulDivDown(plan.withdrawnAssets, referralFeePct, blue_sdk_1.MathLib.WAD);
|
|
117
|
+
const selfPaidReferralFee = userAddress != null &&
|
|
118
|
+
referralFeeRecipient != null &&
|
|
119
|
+
(0, viem_1.isAddressEqual)(userAddress, referralFeeRecipient);
|
|
120
|
+
return {
|
|
121
|
+
maxExitAssets: capacity.maxExitAssets,
|
|
122
|
+
exitAssets,
|
|
123
|
+
remainingExitAssets: requestedExitAssets - exitAssets,
|
|
124
|
+
assetsToWithdraw: plan.assetsToWithdraw,
|
|
125
|
+
assetsToDeallocate: plan.assetsToDeallocate,
|
|
126
|
+
// The tight per-leg charge `ceil(assetsToDeallocate × penalty)`, not `plan.penaltyAssets`: that
|
|
127
|
+
// bound carries a `+ (penaltyLegs - 1)` allowance slack, which would overstate the quote and
|
|
128
|
+
// break reconciliation with `exitAssets` for a multi-market exit.
|
|
129
|
+
penaltyAssets: blue_sdk_1.MathLib.wMulUp(plan.assetsToDeallocate, plan.penalty),
|
|
130
|
+
referralFeeAssets,
|
|
131
|
+
netAssets: selfPaidReferralFee
|
|
132
|
+
? plan.withdrawnAssets
|
|
133
|
+
: plan.withdrawnAssets - referralFeeAssets,
|
|
134
|
+
};
|
|
135
|
+
}
|
|
136
|
+
/** Computes the preview's fee-adjusted floor, excluding fee mints that consume the burn. @internal */
|
|
137
|
+
function computePreviewMinSharePrice(vaultData, { timestamp, feeProjectionTimestamp, userAddress, plan, }) {
|
|
100
138
|
// Mirror the entity's zero-floor guard. `forceWithdraw()` derives its slippage floor from
|
|
101
139
|
// `withdrawnAssets / sharesBurnt` and rejects an exit whose realized share price rounds down to
|
|
102
140
|
// zero (`VaultV2ForceWithdrawZeroSharePriceError`) — a degenerate vault (e.g. `totalSupply`
|
|
@@ -149,26 +187,5 @@ function previewVaultV2ForceWithdraw(vaultData, params) {
|
|
|
149
187
|
const defaultMinSharePriceE27 = sharesBurntForFloor > 0n
|
|
150
188
|
? blue_sdk_1.MathLib.mulDivDown(plan.withdrawnAssets, blue_sdk_1.MathLib.wToRay(blue_sdk_1.MathLib.WAD - blue_sdk_1.DEFAULT_SLIPPAGE_TOLERANCE), sharesBurntForFloor)
|
|
151
189
|
: 0n;
|
|
152
|
-
|
|
153
|
-
return undefined;
|
|
154
|
-
}
|
|
155
|
-
const referralFeeAssets = blue_sdk_1.MathLib.mulDivDown(plan.withdrawnAssets, referralFeePct, blue_sdk_1.MathLib.WAD);
|
|
156
|
-
const selfPaidReferralFee = userAddress != null &&
|
|
157
|
-
referralFeeRecipient != null &&
|
|
158
|
-
(0, viem_1.isAddressEqual)(userAddress, referralFeeRecipient);
|
|
159
|
-
return {
|
|
160
|
-
maxExitAssets: capacity.maxExitAssets,
|
|
161
|
-
exitAssets,
|
|
162
|
-
remainingExitAssets: requestedExitAssets - exitAssets,
|
|
163
|
-
assetsToWithdraw: plan.assetsToWithdraw,
|
|
164
|
-
assetsToDeallocate: plan.assetsToDeallocate,
|
|
165
|
-
// The tight per-leg charge `ceil(assetsToDeallocate × penalty)`, not `plan.penaltyAssets`: that
|
|
166
|
-
// bound carries a `+ (penaltyLegs - 1)` allowance slack, which would overstate the quote and
|
|
167
|
-
// break reconciliation with `exitAssets` for a multi-market exit.
|
|
168
|
-
penaltyAssets: blue_sdk_1.MathLib.wMulUp(plan.assetsToDeallocate, plan.penalty),
|
|
169
|
-
referralFeeAssets,
|
|
170
|
-
netAssets: selfPaidReferralFee
|
|
171
|
-
? plan.withdrawnAssets
|
|
172
|
-
: plan.withdrawnAssets - referralFeeAssets,
|
|
173
|
-
};
|
|
190
|
+
return defaultMinSharePriceE27;
|
|
174
191
|
}
|
|
@@ -49,7 +49,15 @@ function previewVaultV2InKindRedeem(vaultData, params) {
|
|
|
49
49
|
.toSupplyAssets(adapter.supplyShares[market.id] ?? 0n),
|
|
50
50
|
}))
|
|
51
51
|
.filter(({ allocationAssets }) => allocationAssets > 0n)
|
|
52
|
-
.toSorted(({ allocationAssets: a }, { allocationAssets: b }) =>
|
|
52
|
+
.toSorted(({ allocationAssets: a }, { allocationAssets: b }) => {
|
|
53
|
+
if (a === b) {
|
|
54
|
+
return 0;
|
|
55
|
+
}
|
|
56
|
+
if (a > b) {
|
|
57
|
+
return -1;
|
|
58
|
+
}
|
|
59
|
+
return 1;
|
|
60
|
+
});
|
|
53
61
|
return allocations.flatMap(({ market, allocationAssets }) => {
|
|
54
62
|
const maxExitAssets = availableIdleAssets +
|
|
55
63
|
blue_sdk_1.MathLib.wMulUp(allocationAssets + 1n, blue_sdk_1.MathLib.WAD + penalty) -
|
|
@@ -58,8 +66,9 @@ function previewVaultV2InKindRedeem(vaultData, params) {
|
|
|
58
66
|
const idleAssets = blue_sdk_1.MathLib.min(exitAssets, availableIdleAssets);
|
|
59
67
|
const inKindExitAssets = exitAssets - idleAssets;
|
|
60
68
|
const netAssets = blue_sdk_1.MathLib.wDivDown(inKindExitAssets, blue_sdk_1.MathLib.WAD + penalty);
|
|
61
|
-
if (idleAssets === 0n && netAssets === 0n)
|
|
69
|
+
if (idleAssets === 0n && netAssets === 0n) {
|
|
62
70
|
return [];
|
|
71
|
+
}
|
|
63
72
|
return [
|
|
64
73
|
{
|
|
65
74
|
marketParams: market.params,
|
|
@@ -17,8 +17,9 @@ const constant_js_1 = require("./constant.js");
|
|
|
17
17
|
*/
|
|
18
18
|
const resolveCapAccrualBuffer = (value) => {
|
|
19
19
|
const buffer = value == null ? constant_js_1.DEFAULT_CAP_ACCRUAL_BUFFER : BigInt(value);
|
|
20
|
-
if (buffer < 0n)
|
|
20
|
+
if (buffer < 0n) {
|
|
21
21
|
throw new index_js_1.NegativeInputError("capAccrualBuffer", buffer);
|
|
22
|
+
}
|
|
22
23
|
return buffer;
|
|
23
24
|
};
|
|
24
25
|
exports.resolveCapAccrualBuffer = resolveCapAccrualBuffer;
|
|
@@ -36,14 +37,16 @@ exports.resolveCapAccrualBuffer = resolveCapAccrualBuffer;
|
|
|
36
37
|
*/
|
|
37
38
|
const resolveAllocatorCapHeadroom = (value) => {
|
|
38
39
|
const headroom = value ?? constant_js_1.DEFAULT_ALLOCATOR_CAP_HEADROOM;
|
|
39
|
-
if (headroom < 0n)
|
|
40
|
+
if (headroom < 0n) {
|
|
40
41
|
throw new index_js_1.NegativeInputError("allocatorCapHeadroom", headroom);
|
|
41
|
-
|
|
42
|
+
}
|
|
43
|
+
if (headroom > blue_sdk_1.MathLib.WAD) {
|
|
42
44
|
throw new index_js_1.InputExceedsMaxError({
|
|
43
45
|
field: "allocatorCapHeadroom",
|
|
44
46
|
value: headroom,
|
|
45
47
|
max: blue_sdk_1.MathLib.WAD,
|
|
46
48
|
});
|
|
49
|
+
}
|
|
47
50
|
return headroom;
|
|
48
51
|
};
|
|
49
52
|
exports.resolveAllocatorCapHeadroom = resolveAllocatorCapHeadroom;
|
|
@@ -62,14 +65,16 @@ exports.resolveAllocatorCapHeadroom = resolveAllocatorCapHeadroom;
|
|
|
62
65
|
*/
|
|
63
66
|
const resolveMaxWithdrawalUtilization = (value, field = "maxWithdrawalUtilization") => {
|
|
64
67
|
const utilization = value ?? constant_js_1.DEFAULT_WITHDRAWAL_TARGET_UTILIZATION;
|
|
65
|
-
if (utilization < 0n)
|
|
68
|
+
if (utilization < 0n) {
|
|
66
69
|
throw new index_js_1.NegativeInputError(field, utilization);
|
|
67
|
-
|
|
70
|
+
}
|
|
71
|
+
if (utilization > blue_sdk_1.MathLib.WAD) {
|
|
68
72
|
throw new index_js_1.InputExceedsMaxError({
|
|
69
73
|
field,
|
|
70
74
|
value: utilization,
|
|
71
75
|
max: blue_sdk_1.MathLib.WAD,
|
|
72
76
|
});
|
|
77
|
+
}
|
|
73
78
|
return utilization;
|
|
74
79
|
};
|
|
75
80
|
exports.resolveMaxWithdrawalUtilization = resolveMaxWithdrawalUtilization;
|