@morpho-org/morpho-sdk 10.1.0-next.0 → 10.1.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/README.md +6 -2
- package/lib/cjs/abis.d.ts +1 -1
- package/lib/cjs/abis.js +1 -5
- package/lib/cjs/actions/blue/borrow.d.ts +2 -1
- package/lib/cjs/actions/blue/borrow.internal.d.ts +13 -0
- package/lib/cjs/actions/blue/borrow.internal.js +35 -0
- package/lib/cjs/actions/blue/borrow.js +4 -16
- package/lib/cjs/actions/blue/common.d.ts +50 -28
- package/lib/cjs/actions/blue/common.js +21 -34
- package/lib/cjs/actions/blue/encode.d.ts +23 -0
- package/lib/cjs/actions/blue/encode.js +171 -0
- package/lib/cjs/actions/blue/refinance.d.ts +3 -2
- package/lib/cjs/actions/blue/refinance.internal.d.ts +42 -0
- package/lib/cjs/actions/blue/refinance.internal.js +62 -0
- package/lib/cjs/actions/blue/refinance.js +5 -63
- package/lib/cjs/actions/blue/refinanceValidation.d.ts +4 -5
- package/lib/cjs/actions/blue/refinanceValidation.js +1 -3
- package/lib/cjs/actions/blue/repay.d.ts +1 -1
- package/lib/cjs/actions/blue/repay.internal.d.ts +13 -0
- package/lib/cjs/actions/blue/repay.internal.js +38 -0
- package/lib/cjs/actions/blue/repay.js +2 -17
- package/lib/cjs/actions/blue/repayWithdrawCollateral.d.ts +2 -2
- package/lib/cjs/actions/blue/repayWithdrawCollateral.internal.d.ts +61 -0
- package/lib/cjs/actions/blue/repayWithdrawCollateral.internal.js +112 -0
- package/lib/cjs/actions/blue/repayWithdrawCollateral.js +3 -116
- package/lib/cjs/actions/blue/signatures.d.ts +30 -0
- package/lib/cjs/actions/blue/signatures.js +90 -0
- package/lib/cjs/actions/blue/supply.d.ts +1 -1
- package/lib/cjs/actions/blue/supply.internal.d.ts +32 -0
- package/lib/cjs/actions/blue/supply.internal.js +101 -0
- package/lib/cjs/actions/blue/supply.js +2 -67
- package/lib/cjs/actions/blue/supplyCollateral.d.ts +1 -1
- package/lib/cjs/actions/blue/supplyCollateral.internal.d.ts +13 -0
- package/lib/cjs/actions/blue/supplyCollateral.internal.js +37 -0
- package/lib/cjs/actions/blue/supplyCollateral.js +2 -17
- package/lib/cjs/actions/blue/supplyCollateralBorrow.d.ts +4 -3
- package/lib/cjs/actions/blue/supplyCollateralBorrow.internal.d.ts +63 -0
- package/lib/cjs/actions/blue/supplyCollateralBorrow.internal.js +94 -0
- package/lib/cjs/actions/blue/supplyCollateralBorrow.js +5 -106
- package/lib/cjs/actions/blue/withdraw.d.ts +4 -3
- package/lib/cjs/actions/blue/withdraw.internal.d.ts +56 -0
- package/lib/cjs/actions/blue/withdraw.internal.js +84 -0
- package/lib/cjs/actions/blue/withdraw.js +5 -78
- package/lib/cjs/actions/blue/withdrawBuyCallback.d.ts +2 -2
- package/lib/cjs/actions/blue/withdrawBuyCallback.internal.d.ts +20 -0
- package/lib/cjs/actions/blue/withdrawBuyCallback.internal.js +58 -0
- package/lib/cjs/actions/blue/withdrawBuyCallback.js +2 -39
- package/lib/cjs/actions/blue/withdrawCollateral.internal.d.ts +16 -0
- package/lib/cjs/actions/blue/withdrawCollateral.internal.js +39 -0
- package/lib/cjs/actions/blue/withdrawCollateral.js +2 -17
- package/lib/cjs/actions/bundles/common.d.ts +9 -0
- package/lib/cjs/actions/bundles/common.js +18 -6
- package/lib/cjs/actions/bundles/index.d.ts +1 -1
- package/lib/cjs/actions/bundles/index.js +3 -16
- package/lib/cjs/actions/bundles/resolveBundlesTokenRequirements.d.ts +14 -0
- package/lib/cjs/actions/bundles/resolveBundlesTokenRequirements.js +59 -60
- package/lib/cjs/actions/midnight/cancelAndMake.d.ts +22 -1
- package/lib/cjs/actions/midnight/cancelAndMake.js +46 -87
- package/lib/cjs/actions/midnight/cancelOffers.d.ts +11 -0
- package/lib/cjs/actions/midnight/cancelOffers.js +22 -4
- package/lib/cjs/actions/midnight/encode.d.ts +36 -0
- package/lib/cjs/actions/midnight/encode.js +554 -0
- package/lib/cjs/actions/midnight/index.d.ts +14 -13
- package/lib/cjs/actions/midnight/index.js +29 -13
- package/lib/cjs/actions/midnight/parse.d.ts +35 -0
- package/lib/cjs/actions/midnight/parse.js +73 -0
- package/lib/cjs/actions/midnight/parseCollateralBatch.d.ts +58 -0
- package/lib/cjs/actions/midnight/parseCollateralBatch.js +216 -0
- package/lib/cjs/actions/midnight/redeem.d.ts +16 -3
- package/lib/cjs/actions/midnight/redeem.js +22 -51
- package/lib/cjs/actions/midnight/repayWithdrawCollateral.d.ts +13 -0
- package/lib/cjs/actions/midnight/repayWithdrawCollateral.js +42 -67
- package/lib/cjs/actions/midnight/supplyCollateral.d.ts +40 -5
- package/lib/cjs/actions/midnight/supplyCollateral.js +60 -54
- package/lib/cjs/actions/midnight/supplyCollateralBatch.d.ts +3 -3
- package/lib/cjs/actions/midnight/supplyCollateralBatch.js +3 -62
- package/lib/cjs/actions/midnight/supplyCollateralTakeBorrow.d.ts +24 -0
- package/lib/cjs/actions/midnight/supplyCollateralTakeBorrow.js +39 -66
- package/lib/cjs/actions/midnight/supplyCollateralWithNative.d.ts +77 -0
- package/lib/cjs/actions/midnight/supplyCollateralWithNative.js +142 -0
- package/lib/cjs/actions/midnight/takeBorrow.d.ts +17 -2
- package/lib/cjs/actions/midnight/takeBorrow.js +25 -55
- package/lib/cjs/actions/midnight/takeLend.d.ts +21 -1
- package/lib/cjs/actions/midnight/takeLend.js +30 -57
- package/lib/cjs/actions/midnight/takeRepayWithdrawCollateral.d.ts +22 -2
- package/lib/cjs/actions/midnight/takeRepayWithdrawCollateral.js +34 -61
- package/lib/cjs/actions/midnight/takeWithdraw.d.ts +17 -2
- package/lib/cjs/actions/midnight/takeWithdraw.js +78 -115
- package/lib/cjs/actions/midnight/withdrawCollateral.d.ts +16 -3
- package/lib/cjs/actions/midnight/withdrawCollateral.js +25 -56
- package/lib/cjs/actions/midnight/withdrawCollateralBatch.d.ts +3 -3
- package/lib/cjs/actions/midnight/withdrawCollateralBatch.js +3 -71
- package/lib/cjs/actions/requirements/blue/getBlueAuthorizationRequirement.d.ts +13 -0
- package/lib/cjs/actions/requirements/blue/getBlueAuthorizationRequirement.js +39 -19
- package/lib/cjs/actions/requirements/blue/index.d.ts +1 -1
- package/lib/cjs/actions/requirements/blue/index.js +3 -15
- package/lib/cjs/actions/requirements/chainCheck.d.ts +5 -0
- package/lib/cjs/actions/requirements/chainCheck.js +10 -0
- package/lib/cjs/actions/requirements/encode/encodeBlueSignatureAuthorization.d.ts +10 -0
- package/lib/cjs/actions/requirements/encode/encodeBlueSignatureAuthorization.js +40 -27
- package/lib/cjs/actions/requirements/encode/encodeErc20Approval.d.ts +11 -1
- package/lib/cjs/actions/requirements/encode/encodeErc20Approval.js +36 -17
- package/lib/cjs/actions/requirements/encode/encodeErc20Permit.d.ts +14 -1
- package/lib/cjs/actions/requirements/encode/encodeErc20Permit.js +44 -9
- package/lib/cjs/actions/requirements/encode/encodeErc20Permit2SignatureTransfer.d.ts +10 -0
- package/lib/cjs/actions/requirements/encode/encodeErc20Permit2SignatureTransfer.js +61 -24
- package/lib/cjs/actions/requirements/encode/encodeVaultSharesPermit.d.ts +10 -0
- package/lib/cjs/actions/requirements/encode/encodeVaultSharesPermit.js +25 -4
- package/lib/cjs/actions/requirements/encode/index.d.ts +5 -5
- package/lib/cjs/actions/requirements/encode/index.js +11 -19
- package/lib/cjs/actions/requirements/getRequirementsApproval.d.ts +26 -11
- package/lib/cjs/actions/requirements/getRequirementsApproval.js +40 -12
- package/lib/cjs/actions/requirements/index.d.ts +1 -1
- package/lib/cjs/actions/requirements/index.js +3 -1
- package/lib/cjs/actions/requirements/midnight/getMidnightApprovalRequirements.d.ts +11 -0
- package/lib/cjs/actions/requirements/midnight/getMidnightApprovalRequirements.js +34 -19
- package/lib/cjs/actions/requirements/midnight/getMidnightAuthorizationRequirement.d.ts +11 -0
- package/lib/cjs/actions/requirements/midnight/getMidnightAuthorizationRequirement.js +26 -12
- package/lib/cjs/actions/requirements/midnight/index.d.ts +2 -2
- package/lib/cjs/actions/requirements/midnight/index.js +5 -16
- package/lib/cjs/actions/vaultV1/deposit.d.ts +21 -0
- package/lib/cjs/actions/vaultV1/deposit.js +46 -10
- package/lib/cjs/actions/vaultV1/inKindRedeem.d.ts +18 -1
- package/lib/cjs/actions/vaultV1/inKindRedeem.js +36 -16
- package/lib/cjs/actions/vaultV1/index.d.ts +5 -5
- package/lib/cjs/actions/vaultV1/index.js +11 -19
- package/lib/cjs/actions/vaultV1/migrateToV2.d.ts +21 -0
- package/lib/cjs/actions/vaultV1/migrateToV2.js +49 -11
- package/lib/cjs/actions/vaultV1/redeem.d.ts +19 -0
- package/lib/cjs/actions/vaultV1/redeem.js +28 -7
- package/lib/cjs/actions/vaultV1/withdraw.d.ts +19 -0
- package/lib/cjs/actions/vaultV1/withdraw.js +28 -7
- package/lib/cjs/actions/vaultV2/deposit.d.ts +21 -0
- package/lib/cjs/actions/vaultV2/deposit.js +46 -10
- package/lib/cjs/actions/vaultV2/forceRedeem.d.ts +20 -2
- package/lib/cjs/actions/vaultV2/forceRedeem.js +39 -8
- package/lib/cjs/actions/vaultV2/forceWithdraw.d.ts +23 -1
- package/lib/cjs/actions/vaultV2/forceWithdraw.js +36 -14
- package/lib/cjs/actions/vaultV2/inKindRedeem.d.ts +18 -1
- package/lib/cjs/actions/vaultV2/inKindRedeem.js +35 -15
- package/lib/cjs/actions/vaultV2/index.d.ts +6 -6
- package/lib/cjs/actions/vaultV2/index.js +13 -20
- package/lib/cjs/actions/vaultV2/redeem.d.ts +19 -0
- package/lib/cjs/actions/vaultV2/redeem.js +28 -7
- package/lib/cjs/actions/vaultV2/withdraw.d.ts +19 -0
- package/lib/cjs/actions/vaultV2/withdraw.js +28 -7
- package/lib/cjs/blue/abis.d.ts +1 -1
- package/lib/cjs/blue/abis.js +1 -5
- package/lib/cjs/blue/entities.d.ts +4 -4
- package/lib/cjs/blue/entities.js +1 -3
- package/lib/cjs/blue/errors.d.ts +2 -2
- package/lib/cjs/blue/errors.js +1 -5
- package/lib/cjs/blue/fetch.d.ts +2 -2
- package/lib/cjs/blue/fetch.js +1 -3
- package/lib/cjs/blue/utils.d.ts +1 -1
- package/lib/cjs/blue/utils.js +1 -2
- package/lib/cjs/entities/blue/blue.d.ts +35 -8
- package/lib/cjs/entities/blue/blue.js +467 -406
- package/lib/cjs/entities/index.d.ts +4 -4
- package/lib/cjs/entities/index.js +1 -3
- package/lib/cjs/entities/midnight/midnight.d.ts +117 -41
- package/lib/cjs/entities/midnight/midnight.js +472 -843
- package/lib/cjs/entities/midnight/parse.d.ts +74 -0
- package/lib/cjs/entities/midnight/parse.js +336 -0
- package/lib/cjs/entities/midnight/prepare.d.ts +47 -0
- package/lib/cjs/entities/midnight/prepare.js +293 -0
- package/lib/cjs/entities/midnight/publication.d.ts +7 -3
- package/lib/cjs/entities/midnight/publication.js +10 -7
- package/lib/cjs/entities/midnight/types.d.ts +7 -0
- package/lib/cjs/entities/requirements/assertContractCode.d.ts +10 -5
- package/lib/cjs/entities/requirements/assertContractCode.js +24 -15
- package/lib/cjs/entities/requirements/getBundlesTokenRequirements.d.ts +15 -0
- package/lib/cjs/entities/requirements/getBundlesTokenRequirements.js +59 -51
- package/lib/cjs/entities/requirements/getErc2612Permit.d.ts +7 -3
- package/lib/cjs/entities/requirements/getErc2612Permit.js +20 -4
- package/lib/cjs/entities/requirements/getUnusedPermit2Nonce.d.ts +15 -0
- package/lib/cjs/entities/requirements/getUnusedPermit2Nonce.js +24 -7
- package/lib/cjs/entities/requirements/getVaultBundlesSharesRequirements.d.ts +14 -0
- package/lib/cjs/entities/requirements/getVaultBundlesSharesRequirements.js +27 -7
- package/lib/cjs/entities/requirements/getVaultV1InKindRedeemRequirements.js +4 -3
- package/lib/cjs/entities/requirements/getVaultV2ForceWithdrawRequirements.js +4 -3
- package/lib/cjs/entities/requirements/getVaultV2InKindRedeemRequirements.js +4 -3
- package/lib/cjs/entities/requirements/index.d.ts +2 -2
- package/lib/cjs/entities/requirements/index.js +5 -16
- package/lib/cjs/entities/requirements/validateNativeRequirements.d.ts +21 -0
- package/lib/cjs/entities/requirements/validateNativeRequirements.js +37 -0
- package/lib/cjs/entities/vaultV1/inKindRedeemQuote.d.ts +2 -2
- package/lib/cjs/entities/vaultV1/inKindRedeemQuote.js +1 -7
- package/lib/cjs/entities/vaultV1/vaultV1.d.ts +17 -40
- package/lib/cjs/entities/vaultV1/vaultV1.js +228 -159
- package/lib/cjs/entities/vaultV2/forceWithdrawQuote.d.ts +4 -0
- package/lib/cjs/entities/vaultV2/forceWithdrawQuote.js +9 -4
- package/lib/cjs/entities/vaultV2/inKindRedeemQuote.d.ts +2 -2
- package/lib/cjs/entities/vaultV2/inKindRedeemQuote.js +1 -7
- package/lib/cjs/entities/vaultV2/vaultV2.d.ts +29 -86
- package/lib/cjs/entities/vaultV2/vaultV2.js +226 -188
- package/lib/cjs/entities/vaultV2BlueReallocationData.d.ts +2 -3
- package/lib/cjs/entities/vaultV2BlueReallocationData.js +2 -6
- package/lib/cjs/errors.d.ts +4 -4
- package/lib/cjs/errors.js +5 -7
- package/lib/cjs/fetch.d.ts +2 -2
- package/lib/cjs/fetch.js +1 -3
- package/lib/cjs/helpers/deadShares.js +0 -3
- package/lib/cjs/helpers/parse.d.ts +33 -0
- package/lib/cjs/helpers/parse.js +71 -0
- package/lib/cjs/helpers/parseMidnight.d.ts +48 -0
- package/lib/cjs/helpers/parseMidnight.js +95 -0
- package/lib/cjs/helpers/parseMidnightMaker.d.ts +44 -0
- package/lib/cjs/helpers/parseMidnightMaker.js +154 -0
- package/lib/cjs/helpers/validate.d.ts +3 -2
- package/lib/cjs/helpers/validate.js +4 -0
- package/lib/cjs/helpers/validateMidnightCancelAndMakePublication.d.ts +8 -0
- package/lib/cjs/helpers/validateMidnightCancelAndMakePublication.js +4 -4
- package/lib/cjs/helpers/validateMidnightPublication.d.ts +17 -1
- package/lib/cjs/index.d.ts +1 -0
- package/lib/cjs/midnight/errors.d.ts +1 -2
- package/lib/cjs/midnight/errors.js +4 -5
- package/lib/cjs/transactionPlan/blue/refinance.js +17 -9
- package/lib/cjs/transactionPlan/blue/repay.js +2 -1
- package/lib/cjs/transactionPlan/blue/repayWithdrawCollateral.js +23 -4
- package/lib/cjs/transactionPlan/blue/supplyCollateralBorrow.js +2 -2
- package/lib/cjs/transactionPlan/blue/withdraw.d.ts +2 -2
- package/lib/cjs/transactionPlan/blue/withdraw.js +3 -3
- package/lib/cjs/transactionPlan/blue/withdrawCollateral.js +6 -2
- package/lib/cjs/transactionPlan/validation.d.ts +1 -1
- package/lib/cjs/transactionPlan/validation.js +3 -0
- package/lib/cjs/transactionPlan/vaultv1/deposit.d.ts +2 -2
- package/lib/cjs/transactionPlan/vaultv1/deposit.js +2 -2
- package/lib/cjs/types/action.d.ts +13 -2
- package/lib/cjs/types/error.d.ts +20 -2
- package/lib/cjs/types/error.js +32 -3
- package/lib/cjs/utils.d.ts +2 -2
- package/lib/cjs/utils.js +2 -4
- package/lib/cjs/version.d.ts +1 -1
- package/lib/cjs/version.js +1 -1
- package/lib/esm/abis.d.ts +1 -1
- package/lib/esm/abis.js +1 -1
- package/lib/esm/actions/blue/borrow.d.ts +2 -1
- package/lib/esm/actions/blue/borrow.internal.d.ts +13 -0
- package/lib/esm/actions/blue/borrow.internal.js +30 -0
- package/lib/esm/actions/blue/borrow.js +4 -16
- package/lib/esm/actions/blue/common.d.ts +50 -28
- package/lib/esm/actions/blue/common.js +21 -33
- package/lib/esm/actions/blue/encode.d.ts +23 -0
- package/lib/esm/actions/blue/encode.js +164 -0
- package/lib/esm/actions/blue/refinance.d.ts +3 -2
- package/lib/esm/actions/blue/refinance.internal.d.ts +42 -0
- package/lib/esm/actions/blue/refinance.internal.js +56 -0
- package/lib/esm/actions/blue/refinance.js +5 -63
- package/lib/esm/actions/blue/refinanceValidation.d.ts +4 -5
- package/lib/esm/actions/blue/refinanceValidation.js +2 -4
- package/lib/esm/actions/blue/repay.d.ts +1 -1
- package/lib/esm/actions/blue/repay.internal.d.ts +13 -0
- package/lib/esm/actions/blue/repay.internal.js +33 -0
- package/lib/esm/actions/blue/repay.js +2 -17
- package/lib/esm/actions/blue/repayWithdrawCollateral.d.ts +2 -2
- package/lib/esm/actions/blue/repayWithdrawCollateral.internal.d.ts +61 -0
- package/lib/esm/actions/blue/repayWithdrawCollateral.internal.js +104 -0
- package/lib/esm/actions/blue/repayWithdrawCollateral.js +3 -116
- package/lib/esm/actions/blue/signatures.d.ts +30 -0
- package/lib/esm/actions/blue/signatures.js +82 -0
- package/lib/esm/actions/blue/supply.d.ts +1 -1
- package/lib/esm/actions/blue/supply.internal.d.ts +32 -0
- package/lib/esm/actions/blue/supply.internal.js +95 -0
- package/lib/esm/actions/blue/supply.js +2 -67
- package/lib/esm/actions/blue/supplyCollateral.d.ts +1 -1
- package/lib/esm/actions/blue/supplyCollateral.internal.d.ts +13 -0
- package/lib/esm/actions/blue/supplyCollateral.internal.js +32 -0
- package/lib/esm/actions/blue/supplyCollateral.js +2 -17
- package/lib/esm/actions/blue/supplyCollateralBorrow.d.ts +4 -3
- package/lib/esm/actions/blue/supplyCollateralBorrow.internal.d.ts +63 -0
- package/lib/esm/actions/blue/supplyCollateralBorrow.internal.js +87 -0
- package/lib/esm/actions/blue/supplyCollateralBorrow.js +5 -106
- package/lib/esm/actions/blue/withdraw.d.ts +4 -3
- package/lib/esm/actions/blue/withdraw.internal.d.ts +56 -0
- package/lib/esm/actions/blue/withdraw.internal.js +77 -0
- package/lib/esm/actions/blue/withdraw.js +5 -78
- package/lib/esm/actions/blue/withdrawBuyCallback.d.ts +2 -2
- package/lib/esm/actions/blue/withdrawBuyCallback.internal.d.ts +20 -0
- package/lib/esm/actions/blue/withdrawBuyCallback.internal.js +53 -0
- package/lib/esm/actions/blue/withdrawBuyCallback.js +2 -39
- package/lib/esm/actions/blue/withdrawCollateral.internal.d.ts +16 -0
- package/lib/esm/actions/blue/withdrawCollateral.internal.js +34 -0
- package/lib/esm/actions/blue/withdrawCollateral.js +2 -17
- package/lib/esm/actions/bundles/common.d.ts +9 -0
- package/lib/esm/actions/bundles/common.js +15 -4
- package/lib/esm/actions/bundles/index.d.ts +1 -1
- package/lib/esm/actions/bundles/index.js +1 -1
- package/lib/esm/actions/bundles/resolveBundlesTokenRequirements.d.ts +14 -0
- package/lib/esm/actions/bundles/resolveBundlesTokenRequirements.js +58 -61
- package/lib/esm/actions/midnight/cancelAndMake.d.ts +22 -1
- package/lib/esm/actions/midnight/cancelAndMake.js +43 -85
- package/lib/esm/actions/midnight/cancelOffers.d.ts +11 -0
- package/lib/esm/actions/midnight/cancelOffers.js +18 -2
- package/lib/esm/actions/midnight/encode.d.ts +36 -0
- package/lib/esm/actions/midnight/encode.js +539 -0
- package/lib/esm/actions/midnight/index.d.ts +14 -13
- package/lib/esm/actions/midnight/index.js +14 -13
- package/lib/esm/actions/midnight/parse.d.ts +35 -0
- package/lib/esm/actions/midnight/parse.js +68 -0
- package/lib/esm/actions/midnight/parseCollateralBatch.d.ts +58 -0
- package/lib/esm/actions/midnight/parseCollateralBatch.js +209 -0
- package/lib/esm/actions/midnight/redeem.d.ts +16 -3
- package/lib/esm/actions/midnight/redeem.js +20 -50
- package/lib/esm/actions/midnight/repayWithdrawCollateral.d.ts +13 -0
- package/lib/esm/actions/midnight/repayWithdrawCollateral.js +38 -64
- package/lib/esm/actions/midnight/supplyCollateral.d.ts +40 -5
- package/lib/esm/actions/midnight/supplyCollateral.js +57 -53
- package/lib/esm/actions/midnight/supplyCollateralBatch.d.ts +3 -3
- package/lib/esm/actions/midnight/supplyCollateralBatch.js +3 -62
- package/lib/esm/actions/midnight/supplyCollateralTakeBorrow.d.ts +24 -0
- package/lib/esm/actions/midnight/supplyCollateralTakeBorrow.js +33 -61
- package/lib/esm/actions/midnight/supplyCollateralWithNative.d.ts +77 -0
- package/lib/esm/actions/midnight/supplyCollateralWithNative.js +137 -0
- package/lib/esm/actions/midnight/takeBorrow.d.ts +17 -2
- package/lib/esm/actions/midnight/takeBorrow.js +20 -51
- package/lib/esm/actions/midnight/takeLend.d.ts +21 -1
- package/lib/esm/actions/midnight/takeLend.js +26 -54
- package/lib/esm/actions/midnight/takeRepayWithdrawCollateral.d.ts +22 -2
- package/lib/esm/actions/midnight/takeRepayWithdrawCollateral.js +30 -58
- package/lib/esm/actions/midnight/takeWithdraw.d.ts +17 -2
- package/lib/esm/actions/midnight/takeWithdraw.js +76 -114
- package/lib/esm/actions/midnight/withdrawCollateral.d.ts +16 -3
- package/lib/esm/actions/midnight/withdrawCollateral.js +23 -55
- package/lib/esm/actions/midnight/withdrawCollateralBatch.d.ts +3 -3
- package/lib/esm/actions/midnight/withdrawCollateralBatch.js +3 -71
- package/lib/esm/actions/requirements/blue/getBlueAuthorizationRequirement.d.ts +13 -0
- package/lib/esm/actions/requirements/blue/getBlueAuthorizationRequirement.js +36 -18
- package/lib/esm/actions/requirements/blue/index.d.ts +1 -1
- package/lib/esm/actions/requirements/blue/index.js +1 -1
- package/lib/esm/actions/requirements/chainCheck.d.ts +5 -0
- package/lib/esm/actions/requirements/chainCheck.js +6 -0
- package/lib/esm/actions/requirements/encode/encodeBlueSignatureAuthorization.d.ts +10 -0
- package/lib/esm/actions/requirements/encode/encodeBlueSignatureAuthorization.js +36 -25
- package/lib/esm/actions/requirements/encode/encodeErc20Approval.d.ts +11 -1
- package/lib/esm/actions/requirements/encode/encodeErc20Approval.js +33 -16
- package/lib/esm/actions/requirements/encode/encodeErc20Permit.d.ts +14 -1
- package/lib/esm/actions/requirements/encode/encodeErc20Permit.js +41 -8
- package/lib/esm/actions/requirements/encode/encodeErc20Permit2SignatureTransfer.d.ts +10 -0
- package/lib/esm/actions/requirements/encode/encodeErc20Permit2SignatureTransfer.js +59 -24
- package/lib/esm/actions/requirements/encode/encodeVaultSharesPermit.d.ts +10 -0
- package/lib/esm/actions/requirements/encode/encodeVaultSharesPermit.js +21 -2
- package/lib/esm/actions/requirements/encode/index.d.ts +5 -5
- package/lib/esm/actions/requirements/encode/index.js +5 -5
- package/lib/esm/actions/requirements/getRequirementsApproval.d.ts +26 -11
- package/lib/esm/actions/requirements/getRequirementsApproval.js +38 -12
- package/lib/esm/actions/requirements/index.d.ts +1 -1
- package/lib/esm/actions/requirements/index.js +1 -1
- package/lib/esm/actions/requirements/midnight/getMidnightApprovalRequirements.d.ts +11 -0
- package/lib/esm/actions/requirements/midnight/getMidnightApprovalRequirements.js +31 -18
- package/lib/esm/actions/requirements/midnight/getMidnightAuthorizationRequirement.d.ts +11 -0
- package/lib/esm/actions/requirements/midnight/getMidnightAuthorizationRequirement.js +22 -10
- package/lib/esm/actions/requirements/midnight/index.d.ts +2 -2
- package/lib/esm/actions/requirements/midnight/index.js +2 -2
- package/lib/esm/actions/vaultV1/deposit.d.ts +21 -0
- package/lib/esm/actions/vaultV1/deposit.js +43 -9
- package/lib/esm/actions/vaultV1/inKindRedeem.d.ts +18 -1
- package/lib/esm/actions/vaultV1/inKindRedeem.js +33 -15
- package/lib/esm/actions/vaultV1/index.d.ts +5 -5
- package/lib/esm/actions/vaultV1/index.js +5 -5
- package/lib/esm/actions/vaultV1/migrateToV2.d.ts +21 -0
- package/lib/esm/actions/vaultV1/migrateToV2.js +47 -11
- package/lib/esm/actions/vaultV1/redeem.d.ts +19 -0
- package/lib/esm/actions/vaultV1/redeem.js +26 -7
- package/lib/esm/actions/vaultV1/withdraw.d.ts +19 -0
- package/lib/esm/actions/vaultV1/withdraw.js +26 -7
- package/lib/esm/actions/vaultV2/deposit.d.ts +21 -0
- package/lib/esm/actions/vaultV2/deposit.js +43 -9
- package/lib/esm/actions/vaultV2/forceRedeem.d.ts +20 -2
- package/lib/esm/actions/vaultV2/forceRedeem.js +35 -6
- package/lib/esm/actions/vaultV2/forceWithdraw.d.ts +23 -1
- package/lib/esm/actions/vaultV2/forceWithdraw.js +33 -13
- package/lib/esm/actions/vaultV2/inKindRedeem.d.ts +18 -1
- package/lib/esm/actions/vaultV2/inKindRedeem.js +32 -14
- package/lib/esm/actions/vaultV2/index.d.ts +6 -6
- package/lib/esm/actions/vaultV2/index.js +6 -6
- package/lib/esm/actions/vaultV2/redeem.d.ts +19 -0
- package/lib/esm/actions/vaultV2/redeem.js +26 -7
- package/lib/esm/actions/vaultV2/withdraw.d.ts +19 -0
- package/lib/esm/actions/vaultV2/withdraw.js +26 -7
- package/lib/esm/blue/abis.d.ts +1 -1
- package/lib/esm/blue/abis.js +1 -1
- package/lib/esm/blue/entities.d.ts +4 -4
- package/lib/esm/blue/entities.js +2 -2
- package/lib/esm/blue/errors.d.ts +2 -2
- package/lib/esm/blue/errors.js +2 -2
- package/lib/esm/blue/fetch.d.ts +2 -2
- package/lib/esm/blue/fetch.js +2 -2
- package/lib/esm/blue/utils.d.ts +1 -1
- package/lib/esm/blue/utils.js +1 -1
- package/lib/esm/entities/blue/blue.d.ts +35 -8
- package/lib/esm/entities/blue/blue.js +449 -388
- package/lib/esm/entities/index.d.ts +4 -4
- package/lib/esm/entities/index.js +2 -2
- package/lib/esm/entities/midnight/midnight.d.ts +117 -41
- package/lib/esm/entities/midnight/midnight.js +455 -826
- package/lib/esm/entities/midnight/parse.d.ts +74 -0
- package/lib/esm/entities/midnight/parse.js +320 -0
- package/lib/esm/entities/midnight/prepare.d.ts +47 -0
- package/lib/esm/entities/midnight/prepare.js +282 -0
- package/lib/esm/entities/midnight/publication.d.ts +7 -3
- package/lib/esm/entities/midnight/publication.js +7 -3
- package/lib/esm/entities/midnight/types.d.ts +7 -0
- package/lib/esm/entities/requirements/assertContractCode.d.ts +10 -5
- package/lib/esm/entities/requirements/assertContractCode.js +24 -15
- package/lib/esm/entities/requirements/getBundlesTokenRequirements.d.ts +15 -0
- package/lib/esm/entities/requirements/getBundlesTokenRequirements.js +53 -47
- package/lib/esm/entities/requirements/getErc2612Permit.d.ts +7 -3
- package/lib/esm/entities/requirements/getErc2612Permit.js +19 -4
- package/lib/esm/entities/requirements/getUnusedPermit2Nonce.d.ts +15 -0
- package/lib/esm/entities/requirements/getUnusedPermit2Nonce.js +20 -5
- package/lib/esm/entities/requirements/getVaultBundlesSharesRequirements.d.ts +14 -0
- package/lib/esm/entities/requirements/getVaultBundlesSharesRequirements.js +23 -5
- package/lib/esm/entities/requirements/getVaultV1InKindRedeemRequirements.js +4 -3
- package/lib/esm/entities/requirements/getVaultV2ForceWithdrawRequirements.js +4 -3
- package/lib/esm/entities/requirements/getVaultV2InKindRedeemRequirements.js +4 -3
- package/lib/esm/entities/requirements/index.d.ts +2 -2
- package/lib/esm/entities/requirements/index.js +2 -2
- package/lib/esm/entities/requirements/validateNativeRequirements.d.ts +21 -0
- package/lib/esm/entities/requirements/validateNativeRequirements.js +33 -0
- package/lib/esm/entities/vaultV1/inKindRedeemQuote.d.ts +2 -2
- package/lib/esm/entities/vaultV1/inKindRedeemQuote.js +1 -7
- package/lib/esm/entities/vaultV1/vaultV1.d.ts +17 -40
- package/lib/esm/entities/vaultV1/vaultV1.js +208 -139
- package/lib/esm/entities/vaultV2/forceWithdrawQuote.d.ts +4 -0
- package/lib/esm/entities/vaultV2/forceWithdrawQuote.js +10 -5
- package/lib/esm/entities/vaultV2/inKindRedeemQuote.d.ts +2 -2
- package/lib/esm/entities/vaultV2/inKindRedeemQuote.js +1 -7
- package/lib/esm/entities/vaultV2/vaultV2.d.ts +29 -86
- package/lib/esm/entities/vaultV2/vaultV2.js +210 -172
- package/lib/esm/entities/vaultV2BlueReallocationData.d.ts +2 -3
- package/lib/esm/entities/vaultV2BlueReallocationData.js +2 -6
- package/lib/esm/errors.d.ts +4 -4
- package/lib/esm/errors.js +4 -4
- package/lib/esm/fetch.d.ts +2 -2
- package/lib/esm/fetch.js +2 -2
- package/lib/esm/helpers/deadShares.js +1 -4
- package/lib/esm/helpers/parse.d.ts +33 -0
- package/lib/esm/helpers/parse.js +61 -0
- package/lib/esm/helpers/parseMidnight.d.ts +48 -0
- package/lib/esm/helpers/parseMidnight.js +80 -0
- package/lib/esm/helpers/parseMidnightMaker.d.ts +44 -0
- package/lib/esm/helpers/parseMidnightMaker.js +147 -0
- package/lib/esm/helpers/validate.d.ts +3 -2
- package/lib/esm/helpers/validate.js +5 -1
- package/lib/esm/helpers/validateMidnightCancelAndMakePublication.d.ts +8 -0
- package/lib/esm/helpers/validateMidnightCancelAndMakePublication.js +2 -2
- package/lib/esm/helpers/validateMidnightPublication.d.ts +17 -1
- package/lib/esm/index.d.ts +1 -0
- package/lib/esm/midnight/errors.d.ts +1 -2
- package/lib/esm/midnight/errors.js +1 -2
- package/lib/esm/transactionPlan/blue/refinance.js +18 -10
- package/lib/esm/transactionPlan/blue/repay.js +3 -2
- package/lib/esm/transactionPlan/blue/repayWithdrawCollateral.js +24 -5
- package/lib/esm/transactionPlan/blue/supplyCollateralBorrow.js +2 -2
- package/lib/esm/transactionPlan/blue/withdraw.d.ts +2 -2
- package/lib/esm/transactionPlan/blue/withdraw.js +3 -3
- package/lib/esm/transactionPlan/blue/withdrawCollateral.js +6 -2
- package/lib/esm/transactionPlan/validation.d.ts +1 -1
- package/lib/esm/transactionPlan/validation.js +3 -0
- package/lib/esm/transactionPlan/vaultv1/deposit.d.ts +2 -2
- package/lib/esm/transactionPlan/vaultv1/deposit.js +2 -2
- package/lib/esm/types/action.d.ts +13 -2
- package/lib/esm/types/error.d.ts +20 -2
- package/lib/esm/types/error.js +27 -0
- package/lib/esm/utils.d.ts +2 -2
- package/lib/esm/utils.js +2 -2
- package/lib/esm/version.d.ts +1 -1
- package/lib/esm/version.js +1 -1
- package/package.json +7 -7
|
@@ -1,12 +1,11 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.midnightSupplyCollateralTakeBorrow = void 0;
|
|
3
|
+
exports.parseMidnightSupplyCollateralTakeBorrow = exports.midnightSupplyCollateralTakeBorrow = void 0;
|
|
4
4
|
const midnight_sdk_1 = require("@morpho-org/midnight-sdk");
|
|
5
5
|
const morpho_ts_1 = require("@morpho-org/morpho-ts");
|
|
6
6
|
const viem_1 = require("viem");
|
|
7
|
-
const
|
|
8
|
-
const
|
|
9
|
-
const validate_js_1 = require("../../helpers/validate.js");
|
|
7
|
+
const parse_js_1 = require("../../helpers/parse.js");
|
|
8
|
+
const parseMidnight_js_1 = require("../../helpers/parseMidnight.js");
|
|
10
9
|
const validateMidnightAccount_js_1 = require("../../helpers/validateMidnightAccount.js");
|
|
11
10
|
const validateMidnightBounds_js_1 = require("../../helpers/validateMidnightBounds.js");
|
|
12
11
|
const validateMidnightCollateralSupplies_js_1 = require("../../helpers/validateMidnightCollateralSupplies.js");
|
|
@@ -15,7 +14,9 @@ const validateMidnightReceiver_js_1 = require("../../helpers/validateMidnightRec
|
|
|
15
14
|
const validateMidnightTakeFeasibility_js_1 = require("../../helpers/validateMidnightTakeFeasibility.js");
|
|
16
15
|
const validatePositiveInput_js_1 = require("../../helpers/validatePositiveInput.js");
|
|
17
16
|
const validateTakeableOffers_js_1 = require("../../helpers/validateTakeableOffers.js");
|
|
18
|
-
const
|
|
17
|
+
const index_js_1 = require("../../types/index.js");
|
|
18
|
+
const encode_js_1 = require("./encode.js");
|
|
19
|
+
const parse_js_2 = require("./parse.js");
|
|
19
20
|
/**
|
|
20
21
|
* Encodes a `MidnightBundlesV2` sell that supplies collateral and borrows from lend-side offers
|
|
21
22
|
* for `msg.sender` in one call.
|
|
@@ -64,6 +65,7 @@ const index_js_2 = require("../../types/index.js");
|
|
|
64
65
|
* bundle accepts `uint256`, but a higher ceiling gives no slippage protection), when `deadline`
|
|
65
66
|
* exceeds `uint256`, or when `nativeAmount` exceeds the maximum wNative collateral amount this
|
|
66
67
|
* call can pull.
|
|
68
|
+
* @throws {InvalidMidnightNativeAmountTypeError} when `nativeAmount` is supplied as a non-bigint.
|
|
67
69
|
* @throws {ChainWNativeMissingError} when wNative is not configured for the chain.
|
|
68
70
|
* @throws {NativeAmountOnNonWNativeAssetError} when no collateral pull uses wNative.
|
|
69
71
|
* @throws {UnboundedMidnightTakeInputError} when `target.units`, `target.maxUnits` or
|
|
@@ -94,13 +96,17 @@ const index_js_2 = require("../../types/index.js");
|
|
|
94
96
|
* });
|
|
95
97
|
* ```
|
|
96
98
|
*/
|
|
97
|
-
const midnightSupplyCollateralTakeBorrow = (params) =>
|
|
99
|
+
const midnightSupplyCollateralTakeBorrow = (params) => (0, encode_js_1.encodeMidnightSupplyCollateralTakeBorrow)((0, exports.parseMidnightSupplyCollateralTakeBorrow)(params));
|
|
100
|
+
exports.midnightSupplyCollateralTakeBorrow = midnightSupplyCollateralTakeBorrow;
|
|
101
|
+
const parsedSupplyCollateralTakeBorrow = Symbol();
|
|
102
|
+
/** Parses the static SupplyCollateralTakeBorrow constraints in the standalone builder's existing order. @internal */
|
|
103
|
+
const parseMidnightSupplyCollateralTakeBorrow = (params) => {
|
|
98
104
|
// Reject markets from another chain deployment before checking offers against them.
|
|
99
105
|
(0, validateMidnightMarket_js_1.validateMidnightMarket)({ market: params.market, chainId: params.chainId });
|
|
100
106
|
if (params.collateralSupplies.length === 0) {
|
|
101
|
-
throw new
|
|
107
|
+
throw new index_js_1.EmptyMidnightCollateralSuppliesError();
|
|
102
108
|
}
|
|
103
|
-
// Validation only;
|
|
109
|
+
// Validation only; retain main's canonical per-entry and per-index collateral checks.
|
|
104
110
|
(0, validateMidnightCollateralSupplies_js_1.validateMidnightCollateralSupplies)({
|
|
105
111
|
market: params.market,
|
|
106
112
|
field: "collateralSupplies",
|
|
@@ -125,7 +131,7 @@ const midnightSupplyCollateralTakeBorrow = (params) => {
|
|
|
125
131
|
// Validation only; rejects non-positive amounts.
|
|
126
132
|
(0, validatePositiveInput_js_1.validatePositiveInput)("target.assets", target.assets);
|
|
127
133
|
if (target.maxUnits === viem_1.maxUint256) {
|
|
128
|
-
throw new
|
|
134
|
+
throw new index_js_1.UnboundedMidnightTakeInputError("target.maxUnits");
|
|
129
135
|
}
|
|
130
136
|
// Validation only; rejects non-positive amounts.
|
|
131
137
|
(0, validatePositiveInput_js_1.validatePositiveInput)("target.maxUnits", target.maxUnits);
|
|
@@ -135,7 +141,7 @@ const midnightSupplyCollateralTakeBorrow = (params) => {
|
|
|
135
141
|
}
|
|
136
142
|
default: {
|
|
137
143
|
if (target.units === viem_1.maxUint256) {
|
|
138
|
-
throw new
|
|
144
|
+
throw new index_js_1.UnboundedMidnightTakeInputError("target.units");
|
|
139
145
|
}
|
|
140
146
|
// Validation only; rejects non-positive amounts.
|
|
141
147
|
(0, validatePositiveInput_js_1.validatePositiveInput)("target.units", target.units);
|
|
@@ -147,13 +153,13 @@ const midnightSupplyCollateralTakeBorrow = (params) => {
|
|
|
147
153
|
}
|
|
148
154
|
}
|
|
149
155
|
if (params.deadline === viem_1.maxUint256) {
|
|
150
|
-
throw new
|
|
156
|
+
throw new index_js_1.UnboundedMidnightTakeInputError("deadline");
|
|
151
157
|
}
|
|
152
|
-
(0,
|
|
158
|
+
const deadline = (0, parse_js_1.parseDeadline)(params.deadline);
|
|
153
159
|
if (params.referralFeeRecipient !== undefined) {
|
|
154
160
|
(0, validateMidnightAccount_js_1.validateMidnightAddress)("referralFeeRecipient", params.referralFeeRecipient);
|
|
155
161
|
}
|
|
156
|
-
const { referralFeePct, referralFeeRecipient } = (0,
|
|
162
|
+
const { referralFeePct, referralFeeRecipient } = (0, parse_js_1.parseReferralFee)(params);
|
|
157
163
|
(0, validateMidnightBounds_js_1.validateMidnightReferralFeeCap)(referralFeePct);
|
|
158
164
|
(0, validateMidnightTakeFeasibility_js_1.validateMidnightSellTargetBounds)({ target, referralFeePct });
|
|
159
165
|
if (referralFeePct > 0n) {
|
|
@@ -165,62 +171,29 @@ const midnightSupplyCollateralTakeBorrow = (params) => {
|
|
|
165
171
|
receiver: referralFeeRecipient,
|
|
166
172
|
});
|
|
167
173
|
}
|
|
168
|
-
const
|
|
174
|
+
const collateralSupplies = params.collateralSupplies.map(({ collateralIndex, assets }) => ({
|
|
175
|
+
collateralIndex,
|
|
176
|
+
assets,
|
|
177
|
+
token: midnight_sdk_1.MarketUtils.getCollateralByIndex(params.market, collateralIndex)
|
|
178
|
+
.token,
|
|
179
|
+
}));
|
|
180
|
+
const nativeFunding = (0, parseMidnight_js_1.parseMidnightNativeFunding)({
|
|
169
181
|
chainId: params.chainId,
|
|
170
182
|
nativeAmount: params.nativeAmount,
|
|
171
|
-
pulls:
|
|
172
|
-
token: midnight_sdk_1.MarketUtils.getCollateralByIndex(params.market, collateralIndex)
|
|
173
|
-
.token,
|
|
174
|
-
assets,
|
|
175
|
-
})),
|
|
183
|
+
pulls: collateralSupplies,
|
|
176
184
|
});
|
|
177
|
-
const
|
|
178
|
-
const args = [
|
|
179
|
-
false, // reduceOnly
|
|
180
|
-
params.receiver, // receiver
|
|
181
|
-
params.collateralSupplies.map(({ collateralIndex, assets }) => ({
|
|
182
|
-
collateralIndex,
|
|
183
|
-
assets,
|
|
184
|
-
})), // collateralSupplies
|
|
185
|
-
params.takeableOffers, // offerFills
|
|
186
|
-
referralFeePct, // referralFeePct
|
|
187
|
-
referralFeeRecipient, // referralFeeRecipient
|
|
188
|
-
params.deadline, // deadline
|
|
189
|
-
nativeFunding.wrappedNative, // wrappedNative
|
|
190
|
-
];
|
|
191
|
-
let tx = {
|
|
192
|
-
to: (0, morpho_ts_1.getChainAddress)(params.chainId, "midnightBundlesV2"),
|
|
193
|
-
value: nativeFunding.value,
|
|
194
|
-
data: target.type === "assets"
|
|
195
|
-
? (0, encodeMidnightCalldata_js_1.encodeMidnightCalldata)({
|
|
196
|
-
abi: midnight_sdk_1.midnightBundlesV2Abi,
|
|
197
|
-
functionName: "midnightBundlesV2SupplyCollateralAndSellWithAssetsTarget",
|
|
198
|
-
args: [market, target.assets, target.maxUnits, ...args],
|
|
199
|
-
})
|
|
200
|
-
: (0, encodeMidnightCalldata_js_1.encodeMidnightCalldata)({
|
|
201
|
-
abi: midnight_sdk_1.midnightBundlesV2Abi,
|
|
202
|
-
functionName: "midnightBundlesV2SupplyCollateralAndSellWithUnitsTarget",
|
|
203
|
-
args: [market, target.units, target.minSellerAssets, ...args],
|
|
204
|
-
}),
|
|
205
|
-
};
|
|
206
|
-
if (params.metadata) {
|
|
207
|
-
tx = (0, index_js_1.addTransactionMetadata)(tx, params.metadata);
|
|
208
|
-
}
|
|
185
|
+
const snapshot = (0, parse_js_2.snapshotMidnightTakeParams)({ ...params, direction: "sell" });
|
|
209
186
|
return (0, morpho_ts_1.deepFreeze)({
|
|
210
|
-
...
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
referralFeePct,
|
|
221
|
-
referralFeeRecipient,
|
|
222
|
-
},
|
|
223
|
-
},
|
|
187
|
+
...snapshot,
|
|
188
|
+
chainId: params.chainId,
|
|
189
|
+
receiver: params.receiver,
|
|
190
|
+
marketId,
|
|
191
|
+
deadline,
|
|
192
|
+
referralFeePct,
|
|
193
|
+
referralFeeRecipient,
|
|
194
|
+
nativeFunding,
|
|
195
|
+
collateralSupplies,
|
|
196
|
+
[parsedSupplyCollateralTakeBorrow]: true,
|
|
224
197
|
});
|
|
225
198
|
};
|
|
226
|
-
exports.
|
|
199
|
+
exports.parseMidnightSupplyCollateralTakeBorrow = parseMidnightSupplyCollateralTakeBorrow;
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
import { type MarketInput } from "@morpho-org/midnight-sdk";
|
|
2
|
+
import { type Address } from "viem";
|
|
3
|
+
import { type Metadata, type MidnightSupplyCollateralWithNativeAction, type Transaction } from "../../types/index.js";
|
|
4
|
+
/** Parameters for encoding a Midnight collateral supply. */
|
|
5
|
+
export interface MidnightSupplyCollateralWithNativeParams {
|
|
6
|
+
readonly chainId: number;
|
|
7
|
+
readonly market: MarketInput;
|
|
8
|
+
readonly collateralIndex?: bigint;
|
|
9
|
+
readonly assets: bigint;
|
|
10
|
+
readonly accountAddress: Address;
|
|
11
|
+
/** Native funding in wei, capped at the supplied wNative collateral. */
|
|
12
|
+
readonly nativeAmount: bigint;
|
|
13
|
+
/** Bundle execution deadline. */
|
|
14
|
+
readonly deadline: bigint;
|
|
15
|
+
readonly metadata?: Metadata;
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
* Encodes a payable MidnightBundlesV2 collateral supply without a borrow or offer.
|
|
19
|
+
* The bundle credits the sender, which must match `accountAddress`.
|
|
20
|
+
* Validates the account and market before checking the native funding and deadline.
|
|
21
|
+
*
|
|
22
|
+
* @param params.chainId - Chain containing the Midnight and MidnightBundlesV2 deployments.
|
|
23
|
+
* @param params.market - Midnight market receiving the collateral.
|
|
24
|
+
* @param params.collateralIndex - Optional index of the registered wNative collateral; defaults to `0n`.
|
|
25
|
+
* @param params.assets - Total collateral to supply, in wNative base units.
|
|
26
|
+
* @param params.accountAddress - Transaction sender and collateral beneficiary.
|
|
27
|
+
* @param params.nativeAmount - Positive amount to wrap in wei, at most `assets`.
|
|
28
|
+
* @param params.deadline - Positive Unix timestamp in seconds for bundle execution.
|
|
29
|
+
* @param params.metadata.origin - Hex origin tag of up to four bytes, when metadata is supplied.
|
|
30
|
+
* @param params.metadata.timestamp - Optional Unix timestamp in uint32 seconds; `false` or unset omits it.
|
|
31
|
+
* @returns A deep-frozen `Transaction<MidnightSupplyCollateralWithNativeAction>` with
|
|
32
|
+
* `to` set to MidnightBundlesV2 and `value` set to `nativeAmount`.
|
|
33
|
+
* @throws {MidnightCalldataEncodingError} when an address is malformed or a market or bundle argument cannot be ABI-encoded.
|
|
34
|
+
* @throws {InvalidBigIntInputError} when `assets` is not a bigint.
|
|
35
|
+
* @throws {NonPositiveInputError} when `assets` is not positive; also when subsequent funding or
|
|
36
|
+
* deadline validation finds zero `nativeAmount` or a non-positive `deadline`.
|
|
37
|
+
* @throws {InputExceedsMaxError} when `assets` exceeds `uint128`; also on subsequent checks
|
|
38
|
+
* when `nativeAmount` exceeds `assets`, `deadline` exceeds `uint256`, or a metadata
|
|
39
|
+
* timestamp exceeds `uint32`.
|
|
40
|
+
* @throws {MidnightZeroOnBehalfError} when `accountAddress` is the zero address.
|
|
41
|
+
* @throws {ChainIdMismatchError} when the market targets another chain.
|
|
42
|
+
* @throws {UnsupportedChainIdError} when the chain has no address registry.
|
|
43
|
+
* @throws {UnknownAddressError} when Midnight is not registered, or later when resolving MidnightBundlesV2.
|
|
44
|
+
* @throws {MidnightMarketAddressMismatchError} when the market targets another Midnight deployment.
|
|
45
|
+
* @throws {UnknownCollateralIndexError} when `collateralIndex` is not configured on the market.
|
|
46
|
+
* @throws {InvalidMidnightNativeAmountTypeError} when `nativeAmount` is supplied as a non-bigint.
|
|
47
|
+
* @throws {NegativeInputError} when `nativeAmount` is negative, or a later metadata check finds a negative timestamp.
|
|
48
|
+
* @throws {ChainWNativeMissingError} when the chain has no wrapped-native asset.
|
|
49
|
+
* @throws {NativeAmountOnNonWNativeAssetError} when the selected collateral is not wNative.
|
|
50
|
+
* @example
|
|
51
|
+
* ```ts
|
|
52
|
+
* import { maxUint256 } from "viem";
|
|
53
|
+
* import {
|
|
54
|
+
* midnightSupplyCollateralWithNative,
|
|
55
|
+
* type MidnightSupplyCollateralWithNativeParams,
|
|
56
|
+
* } from "@morpho-org/morpho-sdk";
|
|
57
|
+
*
|
|
58
|
+
* export function wrapAndSupply(
|
|
59
|
+
* inputs: Pick<MidnightSupplyCollateralWithNativeParams,
|
|
60
|
+
* "chainId" | "market" | "collateralIndex" | "accountAddress">,
|
|
61
|
+
* ) {
|
|
62
|
+
* const tx = midnightSupplyCollateralWithNative({
|
|
63
|
+
* ...inputs,
|
|
64
|
+
* assets: 1_000_000_000_000_000n,
|
|
65
|
+
* nativeAmount: 1_000_000_000_000_000n,
|
|
66
|
+
* deadline: maxUint256,
|
|
67
|
+
* });
|
|
68
|
+
* return tx; // Readonly<Transaction<MidnightSupplyCollateralWithNativeAction>>
|
|
69
|
+
* }
|
|
70
|
+
* ```
|
|
71
|
+
*/
|
|
72
|
+
export declare const midnightSupplyCollateralWithNative: (params: MidnightSupplyCollateralWithNativeParams) => Readonly<Transaction<MidnightSupplyCollateralWithNativeAction>>;
|
|
73
|
+
/** Returns the transaction and the token pulled by its encoded collateral slot. @internal */
|
|
74
|
+
export declare function prepareMidnightSupplyCollateralWithNative(params: MidnightSupplyCollateralWithNativeParams): {
|
|
75
|
+
token: `0x${string}`;
|
|
76
|
+
tx: Transaction<MidnightSupplyCollateralWithNativeAction>;
|
|
77
|
+
};
|
|
@@ -0,0 +1,142 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.midnightSupplyCollateralWithNative = void 0;
|
|
4
|
+
exports.prepareMidnightSupplyCollateralWithNative = prepareMidnightSupplyCollateralWithNative;
|
|
5
|
+
const midnight_sdk_1 = require("@morpho-org/midnight-sdk");
|
|
6
|
+
const morpho_ts_1 = require("@morpho-org/morpho-ts");
|
|
7
|
+
const viem_1 = require("viem");
|
|
8
|
+
const encodeMidnightCalldata_js_1 = require("../../helpers/encodeMidnightCalldata.js");
|
|
9
|
+
const index_js_1 = require("../../helpers/index.js");
|
|
10
|
+
const parseMidnight_js_1 = require("../../helpers/parseMidnight.js");
|
|
11
|
+
const validate_js_1 = require("../../helpers/validate.js");
|
|
12
|
+
const validateMidnightAccount_js_1 = require("../../helpers/validateMidnightAccount.js");
|
|
13
|
+
const validateMidnightCancelAndMakePublication_js_1 = require("../../helpers/validateMidnightCancelAndMakePublication.js");
|
|
14
|
+
const validateMidnightMarket_js_1 = require("../../helpers/validateMidnightMarket.js");
|
|
15
|
+
const index_js_2 = require("../../types/index.js");
|
|
16
|
+
/**
|
|
17
|
+
* Encodes a payable MidnightBundlesV2 collateral supply without a borrow or offer.
|
|
18
|
+
* The bundle credits the sender, which must match `accountAddress`.
|
|
19
|
+
* Validates the account and market before checking the native funding and deadline.
|
|
20
|
+
*
|
|
21
|
+
* @param params.chainId - Chain containing the Midnight and MidnightBundlesV2 deployments.
|
|
22
|
+
* @param params.market - Midnight market receiving the collateral.
|
|
23
|
+
* @param params.collateralIndex - Optional index of the registered wNative collateral; defaults to `0n`.
|
|
24
|
+
* @param params.assets - Total collateral to supply, in wNative base units.
|
|
25
|
+
* @param params.accountAddress - Transaction sender and collateral beneficiary.
|
|
26
|
+
* @param params.nativeAmount - Positive amount to wrap in wei, at most `assets`.
|
|
27
|
+
* @param params.deadline - Positive Unix timestamp in seconds for bundle execution.
|
|
28
|
+
* @param params.metadata.origin - Hex origin tag of up to four bytes, when metadata is supplied.
|
|
29
|
+
* @param params.metadata.timestamp - Optional Unix timestamp in uint32 seconds; `false` or unset omits it.
|
|
30
|
+
* @returns A deep-frozen `Transaction<MidnightSupplyCollateralWithNativeAction>` with
|
|
31
|
+
* `to` set to MidnightBundlesV2 and `value` set to `nativeAmount`.
|
|
32
|
+
* @throws {MidnightCalldataEncodingError} when an address is malformed or a market or bundle argument cannot be ABI-encoded.
|
|
33
|
+
* @throws {InvalidBigIntInputError} when `assets` is not a bigint.
|
|
34
|
+
* @throws {NonPositiveInputError} when `assets` is not positive; also when subsequent funding or
|
|
35
|
+
* deadline validation finds zero `nativeAmount` or a non-positive `deadline`.
|
|
36
|
+
* @throws {InputExceedsMaxError} when `assets` exceeds `uint128`; also on subsequent checks
|
|
37
|
+
* when `nativeAmount` exceeds `assets`, `deadline` exceeds `uint256`, or a metadata
|
|
38
|
+
* timestamp exceeds `uint32`.
|
|
39
|
+
* @throws {MidnightZeroOnBehalfError} when `accountAddress` is the zero address.
|
|
40
|
+
* @throws {ChainIdMismatchError} when the market targets another chain.
|
|
41
|
+
* @throws {UnsupportedChainIdError} when the chain has no address registry.
|
|
42
|
+
* @throws {UnknownAddressError} when Midnight is not registered, or later when resolving MidnightBundlesV2.
|
|
43
|
+
* @throws {MidnightMarketAddressMismatchError} when the market targets another Midnight deployment.
|
|
44
|
+
* @throws {UnknownCollateralIndexError} when `collateralIndex` is not configured on the market.
|
|
45
|
+
* @throws {InvalidMidnightNativeAmountTypeError} when `nativeAmount` is supplied as a non-bigint.
|
|
46
|
+
* @throws {NegativeInputError} when `nativeAmount` is negative, or a later metadata check finds a negative timestamp.
|
|
47
|
+
* @throws {ChainWNativeMissingError} when the chain has no wrapped-native asset.
|
|
48
|
+
* @throws {NativeAmountOnNonWNativeAssetError} when the selected collateral is not wNative.
|
|
49
|
+
* @example
|
|
50
|
+
* ```ts
|
|
51
|
+
* import { maxUint256 } from "viem";
|
|
52
|
+
* import {
|
|
53
|
+
* midnightSupplyCollateralWithNative,
|
|
54
|
+
* type MidnightSupplyCollateralWithNativeParams,
|
|
55
|
+
* } from "@morpho-org/morpho-sdk";
|
|
56
|
+
*
|
|
57
|
+
* export function wrapAndSupply(
|
|
58
|
+
* inputs: Pick<MidnightSupplyCollateralWithNativeParams,
|
|
59
|
+
* "chainId" | "market" | "collateralIndex" | "accountAddress">,
|
|
60
|
+
* ) {
|
|
61
|
+
* const tx = midnightSupplyCollateralWithNative({
|
|
62
|
+
* ...inputs,
|
|
63
|
+
* assets: 1_000_000_000_000_000n,
|
|
64
|
+
* nativeAmount: 1_000_000_000_000_000n,
|
|
65
|
+
* deadline: maxUint256,
|
|
66
|
+
* });
|
|
67
|
+
* return tx; // Readonly<Transaction<MidnightSupplyCollateralWithNativeAction>>
|
|
68
|
+
* }
|
|
69
|
+
* ```
|
|
70
|
+
*/
|
|
71
|
+
const midnightSupplyCollateralWithNative = (params) => prepareMidnightSupplyCollateralWithNative(params).tx;
|
|
72
|
+
exports.midnightSupplyCollateralWithNative = midnightSupplyCollateralWithNative;
|
|
73
|
+
/** Returns the transaction and the token pulled by its encoded collateral slot. @internal */
|
|
74
|
+
function prepareMidnightSupplyCollateralWithNative(params) {
|
|
75
|
+
(0, validateMidnightAccount_js_1.validateMidnightAddress)("accountAddress", params.accountAddress);
|
|
76
|
+
const assets = (0, parseMidnight_js_1.parseMidnightNativeCollateralAmount)("assets", params.assets);
|
|
77
|
+
if ((0, viem_1.isAddressEqual)(params.accountAddress, viem_1.zeroAddress)) {
|
|
78
|
+
throw new index_js_2.MidnightZeroOnBehalfError("accountAddress");
|
|
79
|
+
}
|
|
80
|
+
(0, validateMidnightMarket_js_1.validateMidnightMarket)({ market: params.market, chainId: params.chainId });
|
|
81
|
+
const market = (0, encodeMidnightCalldata_js_1.wrapMidnightEncoding)("marketId", () => midnight_sdk_1.MarketUtils.toStruct(params.market));
|
|
82
|
+
const marketId = (0, encodeMidnightCalldata_js_1.encodeMidnightMarketId)(market);
|
|
83
|
+
const collateralIndex = params.collateralIndex ?? 0n;
|
|
84
|
+
const { token } = midnight_sdk_1.MarketUtils.getCollateralByIndex(market, collateralIndex);
|
|
85
|
+
if (params.nativeAmount === 0n || params.nativeAmount === undefined) {
|
|
86
|
+
throw new index_js_2.NonPositiveInputError("nativeAmount", params.nativeAmount ?? 0n);
|
|
87
|
+
}
|
|
88
|
+
const { value, wrappedNative } = (0, validate_js_1.validateMidnightNativeAmount)({
|
|
89
|
+
chainId: params.chainId,
|
|
90
|
+
nativeAmount: params.nativeAmount,
|
|
91
|
+
pulls: [{ token, assets }],
|
|
92
|
+
});
|
|
93
|
+
const deadline = params.deadline ?? 0n;
|
|
94
|
+
(0, validate_js_1.validateDeadline)(deadline);
|
|
95
|
+
let tx = {
|
|
96
|
+
to: (0, morpho_ts_1.getChainAddress)(params.chainId, "midnightBundlesV2"),
|
|
97
|
+
value,
|
|
98
|
+
data: (0, encodeMidnightCalldata_js_1.encodeMidnightCalldata)({
|
|
99
|
+
abi: midnight_sdk_1.midnightBundlesV2Abi,
|
|
100
|
+
functionName: "midnightBundlesV2CancelAndMake",
|
|
101
|
+
args: [
|
|
102
|
+
validateMidnightCancelAndMakePublication_js_1.emptyBlueMarket, // blueMarket
|
|
103
|
+
0n, // assetsToPark
|
|
104
|
+
viem_1.zeroHash, // callbackSalt
|
|
105
|
+
market, // market
|
|
106
|
+
[{ collateralIndex, assets }], // collateralSupplies
|
|
107
|
+
viem_1.zeroAddress, // ratifier
|
|
108
|
+
viem_1.zeroHash, // newRoot
|
|
109
|
+
0n, // signatureHeight
|
|
110
|
+
0n, // signatureNonce
|
|
111
|
+
0n, // signatureDeadline
|
|
112
|
+
0, // v
|
|
113
|
+
viem_1.zeroHash, // r
|
|
114
|
+
viem_1.zeroHash, // s
|
|
115
|
+
[], // groupsToCancel
|
|
116
|
+
"0x", // payload
|
|
117
|
+
deadline, // deadline
|
|
118
|
+
wrappedNative, // wrappedNative
|
|
119
|
+
],
|
|
120
|
+
}),
|
|
121
|
+
};
|
|
122
|
+
if (params.metadata) {
|
|
123
|
+
tx = (0, index_js_1.addTransactionMetadata)(tx, params.metadata);
|
|
124
|
+
}
|
|
125
|
+
return {
|
|
126
|
+
token,
|
|
127
|
+
tx: (0, morpho_ts_1.deepFreeze)({
|
|
128
|
+
...tx,
|
|
129
|
+
action: {
|
|
130
|
+
type: "midnightSupplyCollateralWithNative",
|
|
131
|
+
args: {
|
|
132
|
+
market: marketId,
|
|
133
|
+
collateralIndex,
|
|
134
|
+
assets,
|
|
135
|
+
accountAddress: params.accountAddress,
|
|
136
|
+
nativeAmount: value,
|
|
137
|
+
deadline,
|
|
138
|
+
},
|
|
139
|
+
},
|
|
140
|
+
}),
|
|
141
|
+
};
|
|
142
|
+
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { type Address } from "viem";
|
|
1
|
+
import type { MarketInput, MarketUtils } from "@morpho-org/midnight-sdk";
|
|
2
|
+
import { type Address, type Hex } from "viem";
|
|
3
3
|
import { type Metadata, type MidnightSellTarget, type MidnightTakeBorrowAction, type Transaction } from "../../types/index.js";
|
|
4
4
|
import type { MidnightReferralFeeParams, MidnightTakeableOffer } from "./types.js";
|
|
5
5
|
/** Parameters for encoding a Midnight borrow take from already selected offers. */
|
|
@@ -82,3 +82,18 @@ export interface MidnightTakeBorrowParams extends MidnightReferralFeeParams {
|
|
|
82
82
|
* ```
|
|
83
83
|
*/
|
|
84
84
|
export declare const midnightTakeBorrow: (params: MidnightTakeBorrowParams) => Readonly<Transaction<MidnightTakeBorrowAction>>;
|
|
85
|
+
declare const parsedTakeBorrow: unique symbol;
|
|
86
|
+
/** Owned TakeBorrow constraints: side/market/caps, target sentinel rules, bounded deadline, referral, and fee-adjusted sell bounds. @internal */
|
|
87
|
+
export interface ParsedMidnightTakeBorrow extends Omit<MidnightTakeBorrowParams, "market" | "target" | "takeableOffers"> {
|
|
88
|
+
readonly market: ReturnType<typeof MarketUtils.toStruct>;
|
|
89
|
+
readonly marketId: Hex;
|
|
90
|
+
readonly target: MidnightTakeBorrowParams["target"];
|
|
91
|
+
readonly takeableOffers: readonly MidnightTakeableOffer[];
|
|
92
|
+
readonly deadline: bigint;
|
|
93
|
+
readonly referralFeePct: bigint;
|
|
94
|
+
readonly referralFeeRecipient: Address;
|
|
95
|
+
readonly [parsedTakeBorrow]: true;
|
|
96
|
+
}
|
|
97
|
+
/** Parses the static TakeBorrow constraints in the standalone builder's existing order. @internal */
|
|
98
|
+
export declare const parseMidnightTakeBorrow: (params: MidnightTakeBorrowParams) => ParsedMidnightTakeBorrow;
|
|
99
|
+
export {};
|
|
@@ -1,12 +1,9 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.midnightTakeBorrow = void 0;
|
|
4
|
-
const midnight_sdk_1 = require("@morpho-org/midnight-sdk");
|
|
3
|
+
exports.parseMidnightTakeBorrow = exports.midnightTakeBorrow = void 0;
|
|
5
4
|
const morpho_ts_1 = require("@morpho-org/morpho-ts");
|
|
6
5
|
const viem_1 = require("viem");
|
|
7
|
-
const
|
|
8
|
-
const index_js_1 = require("../../helpers/index.js");
|
|
9
|
-
const validate_js_1 = require("../../helpers/validate.js");
|
|
6
|
+
const parse_js_1 = require("../../helpers/parse.js");
|
|
10
7
|
const validateMidnightAccount_js_1 = require("../../helpers/validateMidnightAccount.js");
|
|
11
8
|
const validateMidnightBounds_js_1 = require("../../helpers/validateMidnightBounds.js");
|
|
12
9
|
const validateMidnightMarket_js_1 = require("../../helpers/validateMidnightMarket.js");
|
|
@@ -14,7 +11,9 @@ const validateMidnightReceiver_js_1 = require("../../helpers/validateMidnightRec
|
|
|
14
11
|
const validateMidnightTakeFeasibility_js_1 = require("../../helpers/validateMidnightTakeFeasibility.js");
|
|
15
12
|
const validatePositiveInput_js_1 = require("../../helpers/validatePositiveInput.js");
|
|
16
13
|
const validateTakeableOffers_js_1 = require("../../helpers/validateTakeableOffers.js");
|
|
17
|
-
const
|
|
14
|
+
const index_js_1 = require("../../types/index.js");
|
|
15
|
+
const encode_js_1 = require("./encode.js");
|
|
16
|
+
const parse_js_2 = require("./parse.js");
|
|
18
17
|
/**
|
|
19
18
|
* Encodes a `MidnightBundlesV2` sell that borrows from lend-side offers for `msg.sender`.
|
|
20
19
|
*
|
|
@@ -81,7 +80,11 @@ const index_js_2 = require("../../types/index.js");
|
|
|
81
80
|
* });
|
|
82
81
|
* ```
|
|
83
82
|
*/
|
|
84
|
-
const midnightTakeBorrow = (params) =>
|
|
83
|
+
const midnightTakeBorrow = (params) => (0, encode_js_1.encodeMidnightTakeBorrow)((0, exports.parseMidnightTakeBorrow)(params));
|
|
84
|
+
exports.midnightTakeBorrow = midnightTakeBorrow;
|
|
85
|
+
const parsedTakeBorrow = Symbol();
|
|
86
|
+
/** Parses the static TakeBorrow constraints in the standalone builder's existing order. @internal */
|
|
87
|
+
const parseMidnightTakeBorrow = (params) => {
|
|
85
88
|
// Reject markets from another chain deployment before checking offers against them.
|
|
86
89
|
(0, validateMidnightMarket_js_1.validateMidnightMarket)({ market: params.market, chainId: params.chainId });
|
|
87
90
|
const marketId = (0, validateTakeableOffers_js_1.validateTakeableOffers)({
|
|
@@ -103,7 +106,7 @@ const midnightTakeBorrow = (params) => {
|
|
|
103
106
|
// Validation only; rejects non-positive amounts.
|
|
104
107
|
(0, validatePositiveInput_js_1.validatePositiveInput)("target.assets", target.assets);
|
|
105
108
|
if (target.maxUnits === viem_1.maxUint256) {
|
|
106
|
-
throw new
|
|
109
|
+
throw new index_js_1.UnboundedMidnightTakeInputError("target.maxUnits");
|
|
107
110
|
}
|
|
108
111
|
// Validation only; rejects non-positive amounts.
|
|
109
112
|
(0, validatePositiveInput_js_1.validatePositiveInput)("target.maxUnits", target.maxUnits);
|
|
@@ -113,7 +116,7 @@ const midnightTakeBorrow = (params) => {
|
|
|
113
116
|
}
|
|
114
117
|
default: {
|
|
115
118
|
if (target.units === viem_1.maxUint256) {
|
|
116
|
-
throw new
|
|
119
|
+
throw new index_js_1.UnboundedMidnightTakeInputError("target.units");
|
|
117
120
|
}
|
|
118
121
|
// Validation only; rejects non-positive amounts.
|
|
119
122
|
(0, validatePositiveInput_js_1.validatePositiveInput)("target.units", target.units);
|
|
@@ -125,13 +128,13 @@ const midnightTakeBorrow = (params) => {
|
|
|
125
128
|
}
|
|
126
129
|
}
|
|
127
130
|
if (params.deadline === viem_1.maxUint256) {
|
|
128
|
-
throw new
|
|
131
|
+
throw new index_js_1.UnboundedMidnightTakeInputError("deadline");
|
|
129
132
|
}
|
|
130
|
-
(0,
|
|
133
|
+
const deadline = (0, parse_js_1.parseDeadline)(params.deadline);
|
|
131
134
|
if (params.referralFeeRecipient !== undefined) {
|
|
132
135
|
(0, validateMidnightAccount_js_1.validateMidnightAddress)("referralFeeRecipient", params.referralFeeRecipient);
|
|
133
136
|
}
|
|
134
|
-
const { referralFeePct, referralFeeRecipient } = (0,
|
|
137
|
+
const { referralFeePct, referralFeeRecipient } = (0, parse_js_1.parseReferralFee)(params);
|
|
135
138
|
(0, validateMidnightBounds_js_1.validateMidnightReferralFeeCap)(referralFeePct);
|
|
136
139
|
(0, validateMidnightTakeFeasibility_js_1.validateMidnightSellTargetBounds)({ target, referralFeePct });
|
|
137
140
|
if (referralFeePct > 0n) {
|
|
@@ -143,49 +146,16 @@ const midnightTakeBorrow = (params) => {
|
|
|
143
146
|
receiver: referralFeeRecipient,
|
|
144
147
|
});
|
|
145
148
|
}
|
|
146
|
-
const
|
|
147
|
-
const args = [
|
|
148
|
-
false, // reduceOnly
|
|
149
|
-
params.receiver, // receiver
|
|
150
|
-
[], // collateralSupplies
|
|
151
|
-
params.takeableOffers, // offerFills
|
|
152
|
-
referralFeePct, // referralFeePct
|
|
153
|
-
referralFeeRecipient, // referralFeeRecipient
|
|
154
|
-
params.deadline, // deadline
|
|
155
|
-
viem_1.zeroAddress,
|
|
156
|
-
];
|
|
157
|
-
let tx = {
|
|
158
|
-
to: (0, morpho_ts_1.getChainAddress)(params.chainId, "midnightBundlesV2"),
|
|
159
|
-
value: 0n,
|
|
160
|
-
data: target.type === "assets"
|
|
161
|
-
? (0, encodeMidnightCalldata_js_1.encodeMidnightCalldata)({
|
|
162
|
-
abi: midnight_sdk_1.midnightBundlesV2Abi,
|
|
163
|
-
functionName: "midnightBundlesV2SupplyCollateralAndSellWithAssetsTarget",
|
|
164
|
-
args: [market, target.assets, target.maxUnits, ...args],
|
|
165
|
-
})
|
|
166
|
-
: (0, encodeMidnightCalldata_js_1.encodeMidnightCalldata)({
|
|
167
|
-
abi: midnight_sdk_1.midnightBundlesV2Abi,
|
|
168
|
-
functionName: "midnightBundlesV2SupplyCollateralAndSellWithUnitsTarget",
|
|
169
|
-
args: [market, target.units, target.minSellerAssets, ...args],
|
|
170
|
-
}),
|
|
171
|
-
};
|
|
172
|
-
if (params.metadata) {
|
|
173
|
-
tx = (0, index_js_1.addTransactionMetadata)(tx, params.metadata);
|
|
174
|
-
}
|
|
149
|
+
const snapshot = (0, parse_js_2.snapshotMidnightTakeParams)({ ...params, direction: "sell" });
|
|
175
150
|
return (0, morpho_ts_1.deepFreeze)({
|
|
176
|
-
...
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
deadline: params.deadline,
|
|
185
|
-
referralFeePct,
|
|
186
|
-
referralFeeRecipient,
|
|
187
|
-
},
|
|
188
|
-
},
|
|
151
|
+
...snapshot,
|
|
152
|
+
chainId: params.chainId,
|
|
153
|
+
receiver: params.receiver,
|
|
154
|
+
marketId,
|
|
155
|
+
deadline,
|
|
156
|
+
referralFeePct,
|
|
157
|
+
referralFeeRecipient,
|
|
158
|
+
[parsedTakeBorrow]: true,
|
|
189
159
|
});
|
|
190
160
|
};
|
|
191
|
-
exports.
|
|
161
|
+
exports.parseMidnightTakeBorrow = parseMidnightTakeBorrow;
|
|
@@ -1,4 +1,6 @@
|
|
|
1
|
-
import { type MarketInput } from "@morpho-org/midnight-sdk";
|
|
1
|
+
import { type MarketInput, MarketUtils } from "@morpho-org/midnight-sdk";
|
|
2
|
+
import type { Address, Hex } from "viem";
|
|
3
|
+
import { parseMidnightNativeFunding } from "../../helpers/parseMidnight.js";
|
|
2
4
|
import { type Metadata, type MidnightBuyTarget, type MidnightTakeLendAction, type Transaction } from "../../types/index.js";
|
|
3
5
|
import type { MidnightReferralFeeParams, MidnightTakeableOffer } from "./types.js";
|
|
4
6
|
/** Parameters for encoding a Midnight lend take from already selected offers. */
|
|
@@ -55,6 +57,7 @@ export interface MidnightTakeLendParams extends MidnightReferralFeeParams {
|
|
|
55
57
|
* @throws {NonPositiveInputError} when the target amount, `minUnits`, `maxBuyerAssets` or `deadline` is not positive.
|
|
56
58
|
* @throws {NegativeInputError} when a takeable offer cap, `maxContinuousFee`,
|
|
57
59
|
* `referralFeePct` or `nativeAmount` is negative.
|
|
60
|
+
* @throws {InvalidMidnightNativeAmountTypeError} when `nativeAmount` is supplied as a non-bigint.
|
|
58
61
|
* @throws {ChainWNativeMissingError} when wNative is not configured for the chain.
|
|
59
62
|
* @throws {NativeAmountOnNonWNativeAssetError} when `market.loanToken` is not wNative.
|
|
60
63
|
* @throws {InputExceedsMaxError} when a target amount or offer cap exceeds `uint128`; when
|
|
@@ -86,3 +89,20 @@ export interface MidnightTakeLendParams extends MidnightReferralFeeParams {
|
|
|
86
89
|
* ```
|
|
87
90
|
*/
|
|
88
91
|
export declare const midnightTakeLend: (params: MidnightTakeLendParams) => Readonly<Transaction<MidnightTakeLendAction>>;
|
|
92
|
+
declare const parsedTakeLend: unique symbol;
|
|
93
|
+
/** Owned TakeLend constraints: side/market/caps, target sentinel rules, bounded deadline, referral. @internal */
|
|
94
|
+
export interface ParsedMidnightTakeLend extends Omit<MidnightTakeLendParams, "market" | "target" | "takeableOffers"> {
|
|
95
|
+
readonly market: ReturnType<typeof MarketUtils.toStruct>;
|
|
96
|
+
readonly marketId: Hex;
|
|
97
|
+
readonly target: MidnightTakeLendParams["target"];
|
|
98
|
+
readonly takeableOffers: readonly MidnightTakeableOffer[];
|
|
99
|
+
readonly deadline: bigint;
|
|
100
|
+
readonly referralFeePct: bigint;
|
|
101
|
+
readonly referralFeeRecipient: Address;
|
|
102
|
+
readonly maxContinuousFee: bigint;
|
|
103
|
+
readonly nativeFunding: ReturnType<typeof parseMidnightNativeFunding>;
|
|
104
|
+
readonly [parsedTakeLend]: true;
|
|
105
|
+
}
|
|
106
|
+
/** Parses the static TakeLend constraints in the standalone builder's existing order. @internal */
|
|
107
|
+
export declare const parseMidnightTakeLend: (params: MidnightTakeLendParams) => ParsedMidnightTakeLend;
|
|
108
|
+
export {};
|