@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
|
@@ -175,8 +175,9 @@ export function computeVaultV2ForceWithdrawPlan(params) {
|
|
|
175
175
|
// Guard the exported planner: a non-positive `exitAssets` would flow a negative through
|
|
176
176
|
// `min(exitAssets, withdrawable)` and return a plan with negative amounts. The entity and preview
|
|
177
177
|
// reject it upstream; this protects direct importers of the advertised helper.
|
|
178
|
-
if (exitAssets <= 0n)
|
|
178
|
+
if (exitAssets <= 0n) {
|
|
179
179
|
throw new NonPositiveInputError("exitAssets", exitAssets);
|
|
180
|
+
}
|
|
180
181
|
const penalty = vaultData.forceDeallocatePenalties[adapter.address] ?? 0n;
|
|
181
182
|
const idleAssets = vaultData.assetBalance;
|
|
182
183
|
// `min(adapterPosition, marketLiquidity)` per market, on interest-accrued market state — the
|
|
@@ -201,25 +202,7 @@ export function computeVaultV2ForceWithdrawPlan(params) {
|
|
|
201
202
|
if (liquidityMarketId != null && drainedFromLiquidityMarket > 0n) {
|
|
202
203
|
availableByMarket.set(liquidityMarketId, MathLib.zeroFloorSub(liquidityCapacity, drainedFromLiquidityMarket));
|
|
203
204
|
}
|
|
204
|
-
|
|
205
|
-
const nonEmpty = [];
|
|
206
|
-
for (const available of availableByMarket.values()) {
|
|
207
|
-
if (available <= 0n)
|
|
208
|
-
continue;
|
|
209
|
-
coveredAssets += available;
|
|
210
|
-
nonEmpty.push(available);
|
|
211
|
-
}
|
|
212
|
-
// `maxExitAssets` must not depend on the requested amount. At the ceiling the penalty-free leg
|
|
213
|
-
// always drains the liquidity market completely, so that market contributes nothing to the
|
|
214
|
-
// force-deallocation loop — whereas a small request leaves part of it, which would overstate the
|
|
215
|
-
// ceiling for callers using it to cap an input.
|
|
216
|
-
let saturatedCoveredAssets = 0n;
|
|
217
|
-
for (const [marketId, available] of availableByMarket) {
|
|
218
|
-
if (marketId === liquidityMarketId)
|
|
219
|
-
continue;
|
|
220
|
-
if (available > 0n)
|
|
221
|
-
saturatedCoveredAssets += available;
|
|
222
|
-
}
|
|
205
|
+
const { coveredAssets, nonEmpty, saturatedCoveredAssets } = summarizeMarketCoverage(availableByMarket, liquidityMarketId);
|
|
223
206
|
// Worst-case leg count is the ascending walk: the most markets the loop can touch is the number
|
|
224
207
|
// of smallest positions that together reach `assetsToDeallocate`. Deliberately an upper bound, not
|
|
225
208
|
// a replay of the contract's prefetched `marketIds` order (where an earlier market may cover the
|
|
@@ -232,9 +215,18 @@ export function computeVaultV2ForceWithdrawPlan(params) {
|
|
|
232
215
|
// coverage of the snapshot-vs-execution divergence.
|
|
233
216
|
let penaltyLegs = 0;
|
|
234
217
|
let remaining = assetsToDeallocate;
|
|
235
|
-
for (const available of nonEmpty.toSorted((a, b) =>
|
|
236
|
-
if (
|
|
218
|
+
for (const available of nonEmpty.toSorted((a, b) => {
|
|
219
|
+
if (a === b) {
|
|
220
|
+
return 0;
|
|
221
|
+
}
|
|
222
|
+
if (a > b) {
|
|
223
|
+
return 1;
|
|
224
|
+
}
|
|
225
|
+
return -1;
|
|
226
|
+
})) {
|
|
227
|
+
if (remaining <= 0n) {
|
|
237
228
|
break;
|
|
229
|
+
}
|
|
238
230
|
penaltyLegs += 1;
|
|
239
231
|
remaining -= MathLib.min(available, remaining);
|
|
240
232
|
}
|
|
@@ -428,3 +420,29 @@ export function computeVaultV2ForceWithdrawMinSharesBurnt(params) {
|
|
|
428
420
|
return vaultData.toShares(MathLib.min(plan.withdrawnAssets +
|
|
429
421
|
MathLib.wMulUp(plan.assetsToDeallocate, plan.penalty), MathLib.zeroFloorSub(plan.exitAssets, 1n)), "Down");
|
|
430
422
|
}
|
|
423
|
+
/** Sums usable market liquidity and the ceiling's non-liquidity-market coverage. @internal */
|
|
424
|
+
function summarizeMarketCoverage(availableByMarket, liquidityMarketId) {
|
|
425
|
+
let coveredAssets = 0n;
|
|
426
|
+
const nonEmpty = [];
|
|
427
|
+
for (const available of availableByMarket.values()) {
|
|
428
|
+
if (available <= 0n) {
|
|
429
|
+
continue;
|
|
430
|
+
}
|
|
431
|
+
coveredAssets += available;
|
|
432
|
+
nonEmpty.push(available);
|
|
433
|
+
}
|
|
434
|
+
// `maxExitAssets` must not depend on the requested amount. At the ceiling the penalty-free leg
|
|
435
|
+
// always drains the liquidity market completely, so that market contributes nothing to the
|
|
436
|
+
// force-deallocation loop — whereas a small request leaves part of it, which would overstate the
|
|
437
|
+
// ceiling for callers using it to cap an input.
|
|
438
|
+
let saturatedCoveredAssets = 0n;
|
|
439
|
+
for (const [marketId, available] of availableByMarket) {
|
|
440
|
+
if (marketId === liquidityMarketId) {
|
|
441
|
+
continue;
|
|
442
|
+
}
|
|
443
|
+
if (available > 0n) {
|
|
444
|
+
saturatedCoveredAssets += available;
|
|
445
|
+
}
|
|
446
|
+
}
|
|
447
|
+
return { coveredAssets, nonEmpty, saturatedCoveredAssets };
|
|
448
|
+
}
|
package/lib/esm/index.d.ts
CHANGED
|
@@ -3,7 +3,7 @@ export { validateClientChainId } from "./actions/requirements/validateClientChai
|
|
|
3
3
|
export * from "./client/index.js";
|
|
4
4
|
export * from "./entities/requirements/index.js";
|
|
5
5
|
export * from "./helpers/index.js";
|
|
6
|
-
export type { Action, Funding, IntentParams, ReferralFee, SignatureRequest, Step, TransactionPlan, VaultV2DepositPlanParams, VaultV2WithdrawPlanParams, } from "./transactionPlan/index.js";
|
|
7
|
-
export { applySignatures, buildTransaction, buildTransactions, getPendingSignatureRequests, IncompleteTransactionPlanError, InvalidCalldataOriginError, InvalidTransactionPlanError, NonIntegerInputError, parseTransactionPlan, prepareVaultV2Deposit, prepareVaultV2Withdraw, serializeTransactionPlan, TransactionPlanSignatureMismatchError, UnsupportedTransactionPlanActionError, UnsupportedTransactionPlanVersionError, ZeroAccountError, } from "./transactionPlan/index.js";
|
|
6
|
+
export type { Action, Funding, IntentParams, ReferralFee, SignatureRequest, Step, TransactionPlan, VaultV1DepositPlanParams, VaultV1InKindRedeemPlanParams, VaultV1MigrateToV2PlanParams, VaultV1RedeemPlanParams, VaultV1WithdrawPlanParams, VaultV2DepositPlanParams, VaultV2ForceRedeemPlanParams, VaultV2ForceWithdrawPlanParams, VaultV2InKindRedeemPlanParams, VaultV2RedeemPlanParams, VaultV2WithdrawPlanParams, } from "./transactionPlan/index.js";
|
|
7
|
+
export { applySignatures, buildTransaction, buildTransactions, getPendingSignatureRequests, IncompleteTransactionPlanError, InvalidCalldataOriginError, InvalidTransactionPlanError, NonIntegerInputError, parseTransactionPlan, prepareVaultV1Deposit, prepareVaultV1InKindRedeem, prepareVaultV1MigrateToV2, prepareVaultV1Redeem, prepareVaultV1Withdraw, prepareVaultV2Deposit, prepareVaultV2ForceRedeem, prepareVaultV2ForceWithdraw, prepareVaultV2InKindRedeem, prepareVaultV2Redeem, prepareVaultV2Withdraw, serializeTransactionPlan, TransactionPlanSignatureMismatchError, UnsupportedTransactionPlanActionError, UnsupportedTransactionPlanVersionError, ZeroAccountError, } from "./transactionPlan/index.js";
|
|
8
8
|
export * from "./types/index.js";
|
|
9
9
|
export { version } from "./version.js";
|
package/lib/esm/index.js
CHANGED
|
@@ -3,6 +3,6 @@ export { validateClientChainId } from "./actions/requirements/validateClientChai
|
|
|
3
3
|
export * from "./client/index.js";
|
|
4
4
|
export * from "./entities/requirements/index.js";
|
|
5
5
|
export * from "./helpers/index.js";
|
|
6
|
-
export { applySignatures, buildTransaction, buildTransactions, getPendingSignatureRequests, IncompleteTransactionPlanError, InvalidCalldataOriginError, InvalidTransactionPlanError, NonIntegerInputError, parseTransactionPlan, prepareVaultV2Deposit, prepareVaultV2Withdraw, serializeTransactionPlan, TransactionPlanSignatureMismatchError, UnsupportedTransactionPlanActionError, UnsupportedTransactionPlanVersionError, ZeroAccountError, } from "./transactionPlan/index.js";
|
|
6
|
+
export { applySignatures, buildTransaction, buildTransactions, getPendingSignatureRequests, IncompleteTransactionPlanError, InvalidCalldataOriginError, InvalidTransactionPlanError, NonIntegerInputError, parseTransactionPlan, prepareVaultV1Deposit, prepareVaultV1InKindRedeem, prepareVaultV1MigrateToV2, prepareVaultV1Redeem, prepareVaultV1Withdraw, prepareVaultV2Deposit, prepareVaultV2ForceRedeem, prepareVaultV2ForceWithdraw, prepareVaultV2InKindRedeem, prepareVaultV2Redeem, prepareVaultV2Withdraw, serializeTransactionPlan, TransactionPlanSignatureMismatchError, UnsupportedTransactionPlanActionError, UnsupportedTransactionPlanVersionError, ZeroAccountError, } from "./transactionPlan/index.js";
|
|
7
7
|
export * from "./types/index.js";
|
|
8
8
|
export { version } from "./version.js";
|
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { InvalidTransactionPlanError } from "./error.js";
|
|
2
|
+
import { getPlanObject, validatePlanField, validatePlanFields, } from "./validation.js";
|
|
2
3
|
/** @internal Validates the stored ERC-20 approval action's input shape. */
|
|
3
4
|
export function validateApprovalPlanAction(action, path) {
|
|
4
5
|
const inputs = getPlanObject(action.inputs, `${path}.inputs`);
|
|
@@ -7,7 +8,17 @@ export function validateApprovalPlanAction(action, path) {
|
|
|
7
8
|
fields: {
|
|
8
9
|
token: "address",
|
|
9
10
|
spender: "address",
|
|
10
|
-
amount: "uint256 bigint",
|
|
11
11
|
},
|
|
12
12
|
});
|
|
13
|
+
if ((inputs.assets === undefined) === (inputs.shares === undefined)) {
|
|
14
|
+
throw new InvalidTransactionPlanError({
|
|
15
|
+
path: `${path}.inputs`,
|
|
16
|
+
reason: "expected exactly one of assets or shares",
|
|
17
|
+
});
|
|
18
|
+
}
|
|
19
|
+
const field = inputs.assets === undefined ? "shares" : "assets";
|
|
20
|
+
validatePlanField(inputs[field], {
|
|
21
|
+
path: `${path}.inputs.${field}`,
|
|
22
|
+
type: "uint256 bigint",
|
|
23
|
+
});
|
|
13
24
|
}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { type AccrualVault, type AccrualVaultV2 } from "@morpho-org/blue-sdk";
|
|
2
|
+
import type { Client } from "viem";
|
|
3
|
+
import { type ReferenceTimestampParams } from "../types/index.js";
|
|
4
|
+
import { type Funding, type IntentParams } from "./intent.js";
|
|
5
|
+
import type { TransactionPlan } from "./types.js";
|
|
6
|
+
/** @internal Validates the stored Vault V1 or V2 deposit action's input shape. */
|
|
7
|
+
export declare function validateDepositPlanAction(action: Record<string, unknown>, path: string): void;
|
|
8
|
+
/** @internal Shared caller intent for a snapshot-quoted vault deposit. */
|
|
9
|
+
export interface DepositPlanParams<TSnapshot extends AccrualVault | AccrualVaultV2> extends IntentParams, ReferenceTimestampParams {
|
|
10
|
+
/** WAD-scaled tolerance for the share-price bound; defaults to `DEFAULT_SLIPPAGE_TOLERANCE`. */
|
|
11
|
+
readonly slippageTolerance?: bigint;
|
|
12
|
+
/** Caller-fetched accrual snapshot; only derived inputs are stored in the plan. */
|
|
13
|
+
readonly vault: TSnapshot;
|
|
14
|
+
/** Gross assets the account pays, before the referral fee. */
|
|
15
|
+
readonly assets: bigint;
|
|
16
|
+
/** Defaults to `{ type: "erc20" }`. */
|
|
17
|
+
readonly funding?: Funding;
|
|
18
|
+
}
|
|
19
|
+
/** @internal Prepares a deposit using its vault action and caller-supplied snapshot type. */
|
|
20
|
+
export declare function prepareVaultDeposit<TSnapshot extends AccrualVault | AccrualVaultV2>(client: Client, params: DepositPlanParams<TSnapshot> & {
|
|
21
|
+
readonly type: "vaultV1Deposit" | "vaultV2Deposit";
|
|
22
|
+
}): Promise<TransactionPlan>;
|
|
@@ -0,0 +1,135 @@
|
|
|
1
|
+
import { DEFAULT_SLIPPAGE_TOLERANCE, } from "@morpho-org/blue-sdk";
|
|
2
|
+
import { deepFreeze, getChainAddress, Time } from "@morpho-org/morpho-ts";
|
|
3
|
+
import { getBundlesReferralFeeAssets, normalizeBundlesCommonParams, } from "../actions/bundles/common.js";
|
|
4
|
+
import { validateClientChainId } from "../actions/requirements/validateClientChainId.js";
|
|
5
|
+
import { assertRegistryTargetsHaveCode } from "../entities/requirements/assertContractCode.js";
|
|
6
|
+
import { computeVaultMaxSharePrice } from "../helpers/index.js";
|
|
7
|
+
import { validateNativeVaultAsset, validateSlippageTolerance, validateUint256Field, } from "../helpers/validate.js";
|
|
8
|
+
import { NonPositiveInputError, } from "../types/index.js";
|
|
9
|
+
import { InvalidTransactionPlanError } from "./error.js";
|
|
10
|
+
import { resolveIntent } from "./intent.js";
|
|
11
|
+
import { buildApprovalStep, buildPermitSignatureRequest, getTokenRequirements, } from "./requirements.js";
|
|
12
|
+
import { validatePlanField, validatePlanFields, validateVaultPlanAction, } from "./validation.js";
|
|
13
|
+
/** @internal Validates the stored Vault V1 or V2 deposit action's input shape. */
|
|
14
|
+
export function validateDepositPlanAction(action, path) {
|
|
15
|
+
const inputs = validateVaultPlanAction(action, path);
|
|
16
|
+
validatePlanFields(inputs, {
|
|
17
|
+
path: `${path}.inputs`,
|
|
18
|
+
fields: { asset: "address", maxSharePrice: "uint256 bigint" },
|
|
19
|
+
});
|
|
20
|
+
if ((inputs.assets === undefined) === (inputs.nativeAssets === undefined)) {
|
|
21
|
+
throw new InvalidTransactionPlanError({
|
|
22
|
+
path: `${path}.inputs`,
|
|
23
|
+
reason: "expected exactly one of assets or nativeAssets",
|
|
24
|
+
});
|
|
25
|
+
}
|
|
26
|
+
const field = inputs.assets === undefined ? "nativeAssets" : "assets";
|
|
27
|
+
validatePlanField(inputs[field], {
|
|
28
|
+
path: `${path}.inputs.${field}`,
|
|
29
|
+
type: "uint256 bigint",
|
|
30
|
+
});
|
|
31
|
+
}
|
|
32
|
+
function resolveDepositInputs(params, now) {
|
|
33
|
+
const { vault, chainId, assets } = params;
|
|
34
|
+
const intent = resolveIntent(params, now);
|
|
35
|
+
const slippageTolerance = params.slippageTolerance ?? DEFAULT_SLIPPAGE_TOLERANCE;
|
|
36
|
+
validateSlippageTolerance(slippageTolerance);
|
|
37
|
+
const native = (params.funding ?? { type: "erc20" }).type === "native";
|
|
38
|
+
if (assets <= 0n) {
|
|
39
|
+
throw new NonPositiveInputError("assets", assets);
|
|
40
|
+
}
|
|
41
|
+
// Reject amounts that cannot be encoded as uint256 before making RPC requests.
|
|
42
|
+
validateUint256Field("assets", assets);
|
|
43
|
+
const common = normalizeBundlesCommonParams({
|
|
44
|
+
deadline: intent.deadline,
|
|
45
|
+
referralFeePct: intent.referralFeePct,
|
|
46
|
+
referralFeeRecipient: intent.referralFeeRecipient,
|
|
47
|
+
});
|
|
48
|
+
const { asset } = vault;
|
|
49
|
+
// Native funding must target the chain's wrapped-native vault asset.
|
|
50
|
+
if (native) {
|
|
51
|
+
validateNativeVaultAsset(chainId, asset);
|
|
52
|
+
}
|
|
53
|
+
// The quote depends only on the snapshot and the intent, so it is fixed before any read.
|
|
54
|
+
const maxSharePrice = computeVaultMaxSharePrice({
|
|
55
|
+
vaultData: vault,
|
|
56
|
+
deadline: intent.deadline,
|
|
57
|
+
assets: assets - getBundlesReferralFeeAssets(assets, common.referralFeePct),
|
|
58
|
+
slippageTolerance,
|
|
59
|
+
});
|
|
60
|
+
return { intent, native, common, asset, maxSharePrice };
|
|
61
|
+
}
|
|
62
|
+
/** @internal Prepares a deposit using its vault action and caller-supplied snapshot type. */
|
|
63
|
+
export async function prepareVaultDeposit(client, params) {
|
|
64
|
+
const { chainId, account, assets } = params;
|
|
65
|
+
const vault = params.vault.address;
|
|
66
|
+
const now = params.now ?? Time.timestamp();
|
|
67
|
+
const { intent, native, common, asset, maxSharePrice } = resolveDepositInputs(params, now);
|
|
68
|
+
const spender = getChainAddress(chainId, "bundles.vaultBundlesV1");
|
|
69
|
+
const [requirements] = await Promise.all([
|
|
70
|
+
validateClientChainId(client, chainId).then(() => native
|
|
71
|
+
? []
|
|
72
|
+
: getTokenRequirements(client, {
|
|
73
|
+
token: asset,
|
|
74
|
+
spender,
|
|
75
|
+
amount: assets,
|
|
76
|
+
owner: account,
|
|
77
|
+
chainId,
|
|
78
|
+
deadline: intent.deadline,
|
|
79
|
+
now,
|
|
80
|
+
supportSignature: intent.supportSignature,
|
|
81
|
+
deployless: intent.deployless,
|
|
82
|
+
})),
|
|
83
|
+
assertRegistryTargetsHaveCode(client, chainId, [
|
|
84
|
+
{ role: "bundles.vaultBundlesV1", address: spender },
|
|
85
|
+
]),
|
|
86
|
+
]);
|
|
87
|
+
const approvals = [];
|
|
88
|
+
const signatureRequests = [];
|
|
89
|
+
const tokenPermitRequestId = `${params.type}:tokenPermit`;
|
|
90
|
+
for (const requirement of requirements) {
|
|
91
|
+
if ("sign" in requirement) {
|
|
92
|
+
signatureRequests.push(buildPermitSignatureRequest(requirement, tokenPermitRequestId));
|
|
93
|
+
}
|
|
94
|
+
else {
|
|
95
|
+
approvals.push(buildApprovalStep(requirement, {
|
|
96
|
+
id: approvals.length === 0
|
|
97
|
+
? `${params.type}:approval`
|
|
98
|
+
: `${params.type}:approval:${approvals.length + 1}`,
|
|
99
|
+
chainId,
|
|
100
|
+
account,
|
|
101
|
+
denomination: "assets",
|
|
102
|
+
}));
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
return deepFreeze(structuredClone({
|
|
106
|
+
version: 2,
|
|
107
|
+
account,
|
|
108
|
+
chainId,
|
|
109
|
+
expiresAt: intent.expiresAt,
|
|
110
|
+
...(intent.calldataOrigin && { calldataOrigin: intent.calldataOrigin }),
|
|
111
|
+
steps: [
|
|
112
|
+
...approvals,
|
|
113
|
+
{
|
|
114
|
+
id: params.type,
|
|
115
|
+
label: "Deposit into vault",
|
|
116
|
+
action: {
|
|
117
|
+
type: params.type,
|
|
118
|
+
inputs: {
|
|
119
|
+
chainId,
|
|
120
|
+
account,
|
|
121
|
+
vault,
|
|
122
|
+
asset,
|
|
123
|
+
maxSharePrice,
|
|
124
|
+
...(native ? { nativeAssets: assets } : { assets }),
|
|
125
|
+
...common,
|
|
126
|
+
},
|
|
127
|
+
signatureRequestIds: signatureRequests.length > 0
|
|
128
|
+
? { tokenPermit: tokenPermitRequestId }
|
|
129
|
+
: {},
|
|
130
|
+
},
|
|
131
|
+
},
|
|
132
|
+
],
|
|
133
|
+
signatureRequests,
|
|
134
|
+
}));
|
|
135
|
+
}
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import type { Address } from "viem";
|
|
2
2
|
/**
|
|
3
|
+
* @experimental TransactionPlan is in beta; breaking changes may ship in minor releases.
|
|
3
4
|
* Thrown when an operation's account is the zero address.
|
|
4
5
|
* @example
|
|
5
6
|
* ```ts
|
|
@@ -7,7 +8,6 @@ import type { Address } from "viem";
|
|
|
7
8
|
* import { zeroAddress } from "viem";
|
|
8
9
|
* const error = new ZeroAccountError(zeroAddress);
|
|
9
10
|
* ```
|
|
10
|
-
* @experimental TransactionPlan is in beta; breaking changes may ship in minor releases.
|
|
11
11
|
*/
|
|
12
12
|
export declare class ZeroAccountError extends Error {
|
|
13
13
|
readonly account: Address;
|
|
@@ -15,8 +15,8 @@ export declare class ZeroAccountError extends Error {
|
|
|
15
15
|
constructor(account: Address);
|
|
16
16
|
}
|
|
17
17
|
/**
|
|
18
|
-
* A stored plan uses a format version this SDK cannot interpret.
|
|
19
18
|
* @experimental TransactionPlan is in beta; breaking changes may ship in minor releases.
|
|
19
|
+
* A stored plan uses a format version this SDK cannot interpret.
|
|
20
20
|
*/
|
|
21
21
|
export declare class UnsupportedTransactionPlanVersionError extends Error {
|
|
22
22
|
readonly version: number;
|
|
@@ -32,8 +32,8 @@ export declare class UnsupportedTransactionPlanVersionError extends Error {
|
|
|
32
32
|
constructor(version: number);
|
|
33
33
|
}
|
|
34
34
|
/**
|
|
35
|
-
* A selected plan step names an action this SDK cannot build.
|
|
36
35
|
* @experimental TransactionPlan is in beta; breaking changes may ship in minor releases.
|
|
36
|
+
* A selected plan step names an action this SDK cannot build.
|
|
37
37
|
*/
|
|
38
38
|
export declare class UnsupportedTransactionPlanActionError extends Error {
|
|
39
39
|
readonly actionType: string;
|
|
@@ -49,8 +49,8 @@ export declare class UnsupportedTransactionPlanActionError extends Error {
|
|
|
49
49
|
constructor(actionType: string);
|
|
50
50
|
}
|
|
51
51
|
/**
|
|
52
|
-
* Restored plan data has an invalid shape or inconsistent references.
|
|
53
52
|
* @experimental TransactionPlan is in beta; breaking changes may ship in minor releases.
|
|
53
|
+
* Restored plan data has an invalid shape or inconsistent references.
|
|
54
54
|
*/
|
|
55
55
|
export declare class InvalidTransactionPlanError extends Error {
|
|
56
56
|
/** JSON path of the first rejected value. */
|
|
@@ -73,11 +73,13 @@ export declare class InvalidTransactionPlanError extends Error {
|
|
|
73
73
|
});
|
|
74
74
|
}
|
|
75
75
|
/**
|
|
76
|
-
* A step references a signature request that is absent or has no signature yet.
|
|
77
76
|
* @experimental TransactionPlan is in beta; breaking changes may ship in minor releases.
|
|
77
|
+
* A step references a signature request that is absent or has no signature yet.
|
|
78
78
|
*/
|
|
79
79
|
export declare class IncompleteTransactionPlanError extends Error {
|
|
80
80
|
readonly id: string;
|
|
81
|
+
/** The missing dependency is a signature request. */
|
|
82
|
+
readonly kind = "signature";
|
|
81
83
|
/**
|
|
82
84
|
* Identifies the signature request needed to build the transaction.
|
|
83
85
|
* @param id - Plan-local signature request ID.
|
|
@@ -90,8 +92,8 @@ export declare class IncompleteTransactionPlanError extends Error {
|
|
|
90
92
|
constructor(id: string);
|
|
91
93
|
}
|
|
92
94
|
/**
|
|
93
|
-
* A plan's signature request disagrees with its referencing action or has no reference.
|
|
94
95
|
* @experimental TransactionPlan is in beta; breaking changes may ship in minor releases.
|
|
96
|
+
* A plan's signature request disagrees with its referencing action or has no reference.
|
|
95
97
|
*/
|
|
96
98
|
export declare class TransactionPlanSignatureMismatchError extends Error {
|
|
97
99
|
readonly id: string;
|
|
@@ -108,8 +110,8 @@ export declare class TransactionPlanSignatureMismatchError extends Error {
|
|
|
108
110
|
constructor(id: string, field: string);
|
|
109
111
|
}
|
|
110
112
|
/**
|
|
111
|
-
* `calldataOrigin` is not a 0x-prefixed hex string holding a whole number of bytes.
|
|
112
113
|
* @experimental TransactionPlan is in beta; breaking changes may ship in minor releases.
|
|
114
|
+
* `calldataOrigin` is not a 0x-prefixed hex string holding a whole number of bytes.
|
|
113
115
|
*/
|
|
114
116
|
export declare class InvalidCalldataOriginError extends Error {
|
|
115
117
|
readonly calldataOrigin: string;
|
|
@@ -125,8 +127,8 @@ export declare class InvalidCalldataOriginError extends Error {
|
|
|
125
127
|
constructor(calldataOrigin: string);
|
|
126
128
|
}
|
|
127
129
|
/**
|
|
128
|
-
* A number input that must be an integer is fractional, infinite or not a number.
|
|
129
130
|
* @experimental TransactionPlan is in beta; breaking changes may ship in minor releases.
|
|
131
|
+
* A number input that must be an integer is fractional, infinite or not a number.
|
|
130
132
|
*/
|
|
131
133
|
export declare class NonIntegerInputError extends Error {
|
|
132
134
|
readonly field: string;
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
/**
|
|
2
|
+
* @experimental TransactionPlan is in beta; breaking changes may ship in minor releases.
|
|
2
3
|
* Thrown when an operation's account is the zero address.
|
|
3
4
|
* @example
|
|
4
5
|
* ```ts
|
|
@@ -6,7 +7,6 @@
|
|
|
6
7
|
* import { zeroAddress } from "viem";
|
|
7
8
|
* const error = new ZeroAccountError(zeroAddress);
|
|
8
9
|
* ```
|
|
9
|
-
* @experimental TransactionPlan is in beta; breaking changes may ship in minor releases.
|
|
10
10
|
*/
|
|
11
11
|
export class ZeroAccountError extends Error {
|
|
12
12
|
account;
|
|
@@ -18,8 +18,8 @@ export class ZeroAccountError extends Error {
|
|
|
18
18
|
}
|
|
19
19
|
}
|
|
20
20
|
/**
|
|
21
|
-
* A stored plan uses a format version this SDK cannot interpret.
|
|
22
21
|
* @experimental TransactionPlan is in beta; breaking changes may ship in minor releases.
|
|
22
|
+
* A stored plan uses a format version this SDK cannot interpret.
|
|
23
23
|
*/
|
|
24
24
|
export class UnsupportedTransactionPlanVersionError extends Error {
|
|
25
25
|
version;
|
|
@@ -39,8 +39,8 @@ export class UnsupportedTransactionPlanVersionError extends Error {
|
|
|
39
39
|
}
|
|
40
40
|
}
|
|
41
41
|
/**
|
|
42
|
-
* A selected plan step names an action this SDK cannot build.
|
|
43
42
|
* @experimental TransactionPlan is in beta; breaking changes may ship in minor releases.
|
|
43
|
+
* A selected plan step names an action this SDK cannot build.
|
|
44
44
|
*/
|
|
45
45
|
export class UnsupportedTransactionPlanActionError extends Error {
|
|
46
46
|
actionType;
|
|
@@ -60,8 +60,8 @@ export class UnsupportedTransactionPlanActionError extends Error {
|
|
|
60
60
|
}
|
|
61
61
|
}
|
|
62
62
|
/**
|
|
63
|
-
* Restored plan data has an invalid shape or inconsistent references.
|
|
64
63
|
* @experimental TransactionPlan is in beta; breaking changes may ship in minor releases.
|
|
64
|
+
* Restored plan data has an invalid shape or inconsistent references.
|
|
65
65
|
*/
|
|
66
66
|
export class InvalidTransactionPlanError extends Error {
|
|
67
67
|
/** JSON path of the first rejected value. */
|
|
@@ -85,11 +85,13 @@ export class InvalidTransactionPlanError extends Error {
|
|
|
85
85
|
}
|
|
86
86
|
}
|
|
87
87
|
/**
|
|
88
|
-
* A step references a signature request that is absent or has no signature yet.
|
|
89
88
|
* @experimental TransactionPlan is in beta; breaking changes may ship in minor releases.
|
|
89
|
+
* A step references a signature request that is absent or has no signature yet.
|
|
90
90
|
*/
|
|
91
91
|
export class IncompleteTransactionPlanError extends Error {
|
|
92
92
|
id;
|
|
93
|
+
/** The missing dependency is a signature request. */
|
|
94
|
+
kind = "signature";
|
|
93
95
|
/**
|
|
94
96
|
* Identifies the signature request needed to build the transaction.
|
|
95
97
|
* @param id - Plan-local signature request ID.
|
|
@@ -106,8 +108,8 @@ export class IncompleteTransactionPlanError extends Error {
|
|
|
106
108
|
}
|
|
107
109
|
}
|
|
108
110
|
/**
|
|
109
|
-
* A plan's signature request disagrees with its referencing action or has no reference.
|
|
110
111
|
* @experimental TransactionPlan is in beta; breaking changes may ship in minor releases.
|
|
112
|
+
* A plan's signature request disagrees with its referencing action or has no reference.
|
|
111
113
|
*/
|
|
112
114
|
export class TransactionPlanSignatureMismatchError extends Error {
|
|
113
115
|
id;
|
|
@@ -129,8 +131,8 @@ export class TransactionPlanSignatureMismatchError extends Error {
|
|
|
129
131
|
}
|
|
130
132
|
}
|
|
131
133
|
/**
|
|
132
|
-
* `calldataOrigin` is not a 0x-prefixed hex string holding a whole number of bytes.
|
|
133
134
|
* @experimental TransactionPlan is in beta; breaking changes may ship in minor releases.
|
|
135
|
+
* `calldataOrigin` is not a 0x-prefixed hex string holding a whole number of bytes.
|
|
134
136
|
*/
|
|
135
137
|
export class InvalidCalldataOriginError extends Error {
|
|
136
138
|
calldataOrigin;
|
|
@@ -150,8 +152,8 @@ export class InvalidCalldataOriginError extends Error {
|
|
|
150
152
|
}
|
|
151
153
|
}
|
|
152
154
|
/**
|
|
153
|
-
* A number input that must be an integer is fractional, infinite or not a number.
|
|
154
155
|
* @experimental TransactionPlan is in beta; breaking changes may ship in minor releases.
|
|
156
|
+
* A number input that must be an integer is fractional, infinite or not a number.
|
|
155
157
|
*/
|
|
156
158
|
export class NonIntegerInputError extends Error {
|
|
157
159
|
field;
|
|
@@ -9,7 +9,8 @@ import { getErc2612Permit } from "../entities/requirements/getErc2612Permit.js";
|
|
|
9
9
|
*/
|
|
10
10
|
export async function getTokenPermit(client, params) {
|
|
11
11
|
const { dai } = getChainAddresses(params.chainId);
|
|
12
|
-
if (isDefined(dai) && isAddressEqual(params.token, dai))
|
|
12
|
+
if (isDefined(dai) && isAddressEqual(params.token, dai)) {
|
|
13
13
|
return undefined;
|
|
14
|
+
}
|
|
14
15
|
return getErc2612Permit(client, params);
|
|
15
16
|
}
|
|
@@ -3,7 +3,25 @@ export type { Funding, IntentParams, ReferralFee, } from "./intent.js";
|
|
|
3
3
|
export { applySignatures, buildTransaction, buildTransactions, getPendingSignatureRequests, } from "./plan.js";
|
|
4
4
|
export { parseTransactionPlan, serializeTransactionPlan } from "./serde.js";
|
|
5
5
|
export type { Action, SignatureRequest, Step, TransactionPlan, } from "./types.js";
|
|
6
|
+
export type { VaultV1DepositPlanParams } from "./vaultv1/deposit.js";
|
|
7
|
+
export { prepareVaultV1Deposit } from "./vaultv1/deposit.js";
|
|
8
|
+
export type { VaultV1InKindRedeemPlanParams } from "./vaultv1/inKindRedeem.js";
|
|
9
|
+
export { prepareVaultV1InKindRedeem } from "./vaultv1/inKindRedeem.js";
|
|
10
|
+
export type { VaultV1MigrateToV2PlanParams } from "./vaultv1/migrateToV2.js";
|
|
11
|
+
export { prepareVaultV1MigrateToV2 } from "./vaultv1/migrateToV2.js";
|
|
12
|
+
export type { VaultV1RedeemPlanParams } from "./vaultv1/redeem.js";
|
|
13
|
+
export { prepareVaultV1Redeem } from "./vaultv1/redeem.js";
|
|
14
|
+
export type { VaultV1WithdrawPlanParams } from "./vaultv1/withdraw.js";
|
|
15
|
+
export { prepareVaultV1Withdraw } from "./vaultv1/withdraw.js";
|
|
6
16
|
export type { VaultV2DepositPlanParams } from "./vaultv2/deposit.js";
|
|
7
17
|
export { prepareVaultV2Deposit } from "./vaultv2/deposit.js";
|
|
18
|
+
export type { VaultV2ForceRedeemPlanParams } from "./vaultv2/forceRedeem.js";
|
|
19
|
+
export { prepareVaultV2ForceRedeem } from "./vaultv2/forceRedeem.js";
|
|
20
|
+
export type { VaultV2ForceWithdrawPlanParams } from "./vaultv2/forceWithdraw.js";
|
|
21
|
+
export { prepareVaultV2ForceWithdraw } from "./vaultv2/forceWithdraw.js";
|
|
22
|
+
export type { VaultV2InKindRedeemPlanParams } from "./vaultv2/inKindRedeem.js";
|
|
23
|
+
export { prepareVaultV2InKindRedeem } from "./vaultv2/inKindRedeem.js";
|
|
24
|
+
export type { VaultV2RedeemPlanParams } from "./vaultv2/redeem.js";
|
|
25
|
+
export { prepareVaultV2Redeem } from "./vaultv2/redeem.js";
|
|
8
26
|
export type { VaultV2WithdrawPlanParams } from "./vaultv2/withdraw.js";
|
|
9
27
|
export { prepareVaultV2Withdraw } from "./vaultv2/withdraw.js";
|
|
@@ -1,5 +1,14 @@
|
|
|
1
1
|
export { IncompleteTransactionPlanError, InvalidCalldataOriginError, InvalidTransactionPlanError, NonIntegerInputError, TransactionPlanSignatureMismatchError, UnsupportedTransactionPlanActionError, UnsupportedTransactionPlanVersionError, ZeroAccountError, } from "./error.js";
|
|
2
2
|
export { applySignatures, buildTransaction, buildTransactions, getPendingSignatureRequests, } from "./plan.js";
|
|
3
3
|
export { parseTransactionPlan, serializeTransactionPlan } from "./serde.js";
|
|
4
|
+
export { prepareVaultV1Deposit } from "./vaultv1/deposit.js";
|
|
5
|
+
export { prepareVaultV1InKindRedeem } from "./vaultv1/inKindRedeem.js";
|
|
6
|
+
export { prepareVaultV1MigrateToV2 } from "./vaultv1/migrateToV2.js";
|
|
7
|
+
export { prepareVaultV1Redeem } from "./vaultv1/redeem.js";
|
|
8
|
+
export { prepareVaultV1Withdraw } from "./vaultv1/withdraw.js";
|
|
4
9
|
export { prepareVaultV2Deposit } from "./vaultv2/deposit.js";
|
|
10
|
+
export { prepareVaultV2ForceRedeem } from "./vaultv2/forceRedeem.js";
|
|
11
|
+
export { prepareVaultV2ForceWithdraw } from "./vaultv2/forceWithdraw.js";
|
|
12
|
+
export { prepareVaultV2InKindRedeem } from "./vaultv2/inKindRedeem.js";
|
|
13
|
+
export { prepareVaultV2Redeem } from "./vaultv2/redeem.js";
|
|
5
14
|
export { prepareVaultV2Withdraw } from "./vaultv2/withdraw.js";
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { type Address, type Hex } from "viem";
|
|
2
2
|
/**
|
|
3
|
-
* Which balance pays a deposit: the vault asset, or native currency the bundle wraps.
|
|
4
3
|
* @experimental TransactionPlan is in beta; breaking changes may ship in minor releases.
|
|
4
|
+
* Which balance pays a deposit: the vault asset, or native currency the bundle wraps.
|
|
5
5
|
*/
|
|
6
6
|
export type Funding = {
|
|
7
7
|
readonly type: "erc20";
|
|
@@ -9,16 +9,16 @@ export type Funding = {
|
|
|
9
9
|
readonly type: "native";
|
|
10
10
|
};
|
|
11
11
|
/**
|
|
12
|
-
* Referral fee in basis points of the gross amount, paid to `recipient`.
|
|
13
12
|
* @experimental TransactionPlan is in beta; breaking changes may ship in minor releases.
|
|
13
|
+
* Referral fee in basis points of the gross amount, paid to `recipient`.
|
|
14
14
|
*/
|
|
15
15
|
export interface ReferralFee {
|
|
16
16
|
readonly bps: number;
|
|
17
17
|
readonly recipient: Address;
|
|
18
18
|
}
|
|
19
19
|
/**
|
|
20
|
-
* Intent fields shared by every prepare function, mirroring the Actions API intent inputs.
|
|
21
20
|
* @experimental TransactionPlan is in beta; breaking changes may ship in minor releases.
|
|
21
|
+
* Intent fields shared by every prepare function, mirroring the Actions API intent inputs.
|
|
22
22
|
*/
|
|
23
23
|
export interface IntentParams {
|
|
24
24
|
readonly chainId: number;
|
|
@@ -5,8 +5,9 @@ import { InvalidCalldataOriginError, NonIntegerInputError, ZeroAccountError, } f
|
|
|
5
5
|
const BASIS_POINTS = 10000n;
|
|
6
6
|
const WAD_PER_BASIS_POINT = MathLib.WAD / BASIS_POINTS;
|
|
7
7
|
function toSafeInteger(field, value) {
|
|
8
|
-
if (!Number.isSafeInteger(value))
|
|
8
|
+
if (!Number.isSafeInteger(value)) {
|
|
9
9
|
throw new NonIntegerInputError(field, value);
|
|
10
|
+
}
|
|
10
11
|
return BigInt(value);
|
|
11
12
|
}
|
|
12
13
|
/**
|
|
@@ -14,31 +15,37 @@ function toSafeInteger(field, value) {
|
|
|
14
15
|
* signature support and calldata origin. Throws on invalid values so a plan never carries them.
|
|
15
16
|
*/
|
|
16
17
|
export function resolveIntent(params, now) {
|
|
17
|
-
if (params.account === zeroAddress)
|
|
18
|
+
if (params.account === zeroAddress) {
|
|
18
19
|
throw new ZeroAccountError(params.account);
|
|
20
|
+
}
|
|
19
21
|
const expiresAt = params.expiresAt ?? Number(now + Time.s.from.h(2n));
|
|
20
22
|
const deadline = toSafeInteger("expiresAt", expiresAt);
|
|
21
|
-
if (deadline <= 0n)
|
|
23
|
+
if (deadline <= 0n) {
|
|
22
24
|
throw new NonPositiveInputError("expiresAt", deadline);
|
|
23
|
-
|
|
25
|
+
}
|
|
26
|
+
if (deadline <= now) {
|
|
24
27
|
throw new ExpiredDeadlineError(deadline, now);
|
|
28
|
+
}
|
|
25
29
|
const bps = params.referralFee === undefined
|
|
26
30
|
? 0n
|
|
27
31
|
: toSafeInteger("referralFee.bps", params.referralFee.bps);
|
|
28
|
-
if (bps < 0n)
|
|
32
|
+
if (bps < 0n) {
|
|
29
33
|
throw new NegativeInputError("referralFee.bps", bps);
|
|
30
|
-
|
|
34
|
+
}
|
|
35
|
+
if (bps > BASIS_POINTS) {
|
|
31
36
|
throw new InputExceedsMaxError({
|
|
32
37
|
field: "referralFee.bps",
|
|
33
38
|
value: bps,
|
|
34
39
|
max: BASIS_POINTS,
|
|
35
40
|
});
|
|
41
|
+
}
|
|
36
42
|
const { calldataOrigin } = params;
|
|
37
43
|
if (calldataOrigin !== undefined &&
|
|
38
44
|
(!isHex(calldataOrigin, { strict: true }) ||
|
|
39
45
|
calldataOrigin.length <= 2 ||
|
|
40
|
-
calldataOrigin.length % 2 !== 0))
|
|
46
|
+
calldataOrigin.length % 2 !== 0)) {
|
|
41
47
|
throw new InvalidCalldataOriginError(calldataOrigin);
|
|
48
|
+
}
|
|
42
49
|
return {
|
|
43
50
|
expiresAt: Number(deadline),
|
|
44
51
|
deadline,
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type
|
|
1
|
+
import { type Address } from "viem";
|
|
2
2
|
import type { Erc2612RequirementSignature } from "../types/index.js";
|
|
3
3
|
import type { Action, SignatureRequest } from "./types.js";
|
|
4
4
|
/** @internal Validates the stored ERC-2612 request shape without verifying its signature. */
|