@morpho-org/morpho-sdk 5.2.0 → 5.3.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 +46 -2
- package/lib/cjs/abis.d.ts +1 -0
- package/lib/cjs/abis.js +6 -1
- package/lib/cjs/actions/blue/borrow.d.ts +3 -7
- package/lib/cjs/actions/blue/borrow.js +5 -9
- package/lib/cjs/actions/blue/buildReallocationActions.d.ts +3 -4
- package/lib/cjs/actions/blue/buildReallocationActions.js +3 -4
- package/lib/cjs/actions/blue/refinance.d.ts +4 -8
- package/lib/cjs/actions/blue/refinance.js +10 -14
- package/lib/cjs/actions/blue/repay.d.ts +2 -5
- package/lib/cjs/actions/blue/repay.js +2 -5
- package/lib/cjs/actions/blue/repayWithdrawCollateral.d.ts +3 -6
- package/lib/cjs/actions/blue/repayWithdrawCollateral.js +4 -7
- package/lib/cjs/actions/blue/resolveRepayFunding.d.ts +2 -5
- package/lib/cjs/actions/blue/resolveRepayFunding.js +15 -12
- package/lib/cjs/actions/blue/supply.d.ts +2 -4
- package/lib/cjs/actions/blue/supply.js +6 -8
- package/lib/cjs/actions/blue/supplyCollateral.d.ts +2 -3
- package/lib/cjs/actions/blue/supplyCollateral.js +5 -6
- package/lib/cjs/actions/blue/supplyCollateralBorrow.d.ts +4 -9
- package/lib/cjs/actions/blue/supplyCollateralBorrow.js +9 -14
- package/lib/cjs/actions/blue/withdraw.d.ts +9 -7
- package/lib/cjs/actions/blue/withdraw.js +18 -10
- package/lib/cjs/actions/blue/withdrawCollateral.d.ts +1 -1
- package/lib/cjs/actions/blue/withdrawCollateral.js +2 -2
- package/lib/cjs/actions/index.d.ts +2 -0
- package/lib/cjs/actions/index.js +1 -0
- package/lib/cjs/actions/midnight/authorization.d.ts +37 -0
- package/lib/cjs/actions/midnight/authorization.js +69 -0
- package/lib/cjs/actions/midnight/cancelOffer.d.ts +38 -0
- package/lib/cjs/actions/midnight/cancelOffer.js +73 -0
- package/lib/cjs/actions/midnight/index.d.ts +11 -0
- package/lib/cjs/actions/midnight/index.js +27 -0
- package/lib/cjs/actions/midnight/mempoolSubmitOffers.d.ts +52 -0
- package/lib/cjs/actions/midnight/mempoolSubmitOffers.js +72 -0
- package/lib/cjs/actions/midnight/redeem.d.ts +43 -0
- package/lib/cjs/actions/midnight/redeem.js +79 -0
- package/lib/cjs/actions/midnight/repayWithdrawCollateral.d.ts +53 -0
- package/lib/cjs/actions/midnight/repayWithdrawCollateral.js +121 -0
- package/lib/cjs/actions/midnight/setterRatifierRatifyRoot.d.ts +40 -0
- package/lib/cjs/actions/midnight/setterRatifierRatifyRoot.js +59 -0
- package/lib/cjs/actions/midnight/supplyCollateral.d.ts +45 -0
- package/lib/cjs/actions/midnight/supplyCollateral.js +83 -0
- package/lib/cjs/actions/midnight/supplyCollateralTakeBorrow.d.ts +51 -0
- package/lib/cjs/actions/midnight/supplyCollateralTakeBorrow.js +128 -0
- package/lib/cjs/actions/midnight/takeBorrow.d.ts +57 -0
- package/lib/cjs/actions/midnight/takeBorrow.js +110 -0
- package/lib/cjs/actions/midnight/takeLend.d.ts +57 -0
- package/lib/cjs/actions/midnight/takeLend.js +110 -0
- package/lib/cjs/actions/midnight/types.d.ts +39 -0
- package/lib/cjs/actions/midnight/types.js +15 -0
- package/lib/cjs/actions/requirements/encode/encodeBlueSignatureAuthorization.d.ts +1 -1
- package/lib/cjs/actions/requirements/encode/encodeBlueSignatureAuthorization.js +5 -16
- package/lib/cjs/actions/requirements/encode/encodeErc20Approval.d.ts +5 -4
- package/lib/cjs/actions/requirements/encode/encodeErc20Approval.js +10 -14
- package/lib/cjs/actions/requirements/encode/encodeErc20Permit.d.ts +2 -2
- package/lib/cjs/actions/requirements/encode/encodeErc20Permit.js +11 -28
- package/lib/cjs/actions/requirements/encode/encodeErc20Permit2Approve.d.ts +1 -1
- package/lib/cjs/actions/requirements/encode/encodeErc20Permit2Approve.js +5 -17
- package/lib/cjs/actions/requirements/generalAdapter/getGeneralAdapterRequirementsPermit.d.ts +1 -1
- package/lib/cjs/actions/requirements/getRequirementsApproval.d.ts +10 -4
- package/lib/cjs/actions/requirements/getRequirementsApproval.js +10 -4
- package/lib/cjs/actions/requirements/index.d.ts +1 -0
- package/lib/cjs/actions/requirements/index.js +1 -0
- package/lib/cjs/actions/requirements/midnight/getMidnightApprovalRequirements.d.ts +49 -0
- package/lib/cjs/actions/requirements/midnight/getMidnightApprovalRequirements.js +76 -0
- package/lib/cjs/actions/requirements/midnight/getMidnightAuthorizationRequirement.d.ts +44 -0
- package/lib/cjs/actions/requirements/midnight/getMidnightAuthorizationRequirement.js +78 -0
- package/lib/cjs/actions/requirements/midnight/getSetterRatifierRatifyRootRequirement.d.ts +42 -0
- package/lib/cjs/actions/requirements/midnight/getSetterRatifierRatifyRootRequirement.js +70 -0
- package/lib/cjs/actions/requirements/midnight/index.d.ts +3 -0
- package/lib/cjs/actions/requirements/midnight/index.js +19 -0
- package/lib/cjs/actions/vaultV1/deposit.d.ts +3 -4
- package/lib/cjs/actions/vaultV1/deposit.js +7 -8
- package/lib/cjs/actions/vaultV1/migrateToV2.d.ts +2 -3
- package/lib/cjs/actions/vaultV1/migrateToV2.js +5 -6
- package/lib/cjs/actions/vaultV1/redeem.d.ts +1 -1
- package/lib/cjs/actions/vaultV1/redeem.js +2 -2
- package/lib/cjs/actions/vaultV1/withdraw.d.ts +1 -1
- package/lib/cjs/actions/vaultV1/withdraw.js +2 -2
- package/lib/cjs/actions/vaultV2/deposit.d.ts +3 -4
- package/lib/cjs/actions/vaultV2/deposit.js +7 -8
- package/lib/cjs/actions/vaultV2/forceRedeem.d.ts +2 -3
- package/lib/cjs/actions/vaultV2/forceRedeem.js +3 -4
- package/lib/cjs/actions/vaultV2/forceWithdraw.d.ts +1 -1
- package/lib/cjs/actions/vaultV2/forceWithdraw.js +2 -2
- package/lib/cjs/actions/vaultV2/redeem.d.ts +1 -1
- package/lib/cjs/actions/vaultV2/redeem.js +2 -2
- package/lib/cjs/actions/vaultV2/withdraw.d.ts +1 -1
- package/lib/cjs/actions/vaultV2/withdraw.js +2 -2
- package/lib/cjs/client/morphoViemExtension.d.ts +1 -1
- package/lib/cjs/client/morphoViemExtension.js +5 -2
- package/lib/cjs/constants.d.ts +1 -0
- package/lib/cjs/constants.js +15 -1
- package/lib/cjs/entities/blue/blue.d.ts +5 -5
- package/lib/cjs/entities/blue/blue.js +93 -68
- package/lib/cjs/entities/index.d.ts +1 -0
- package/lib/cjs/entities/index.js +15 -0
- package/lib/cjs/entities/midnight/index.d.ts +2 -0
- package/lib/cjs/entities/midnight/index.js +18 -0
- package/lib/cjs/entities/midnight/midnight.d.ts +402 -0
- package/lib/cjs/entities/midnight/midnight.js +1036 -0
- package/lib/cjs/entities/midnight/types.d.ts +164 -0
- package/lib/cjs/entities/midnight/types.js +2 -0
- package/lib/cjs/entities/vaultV1/vaultV1.js +10 -17
- package/lib/cjs/entities/vaultV2/vaultV2.js +19 -21
- package/lib/cjs/errors.d.ts +1 -0
- package/lib/cjs/errors.js +17 -1
- package/lib/cjs/helpers/encodeDeallocation.d.ts +1 -0
- package/lib/cjs/helpers/encodeDeallocation.js +2 -1
- package/lib/cjs/helpers/index.d.ts +4 -1
- package/lib/cjs/helpers/index.js +8 -1
- package/lib/cjs/helpers/signAndVerifyTypedData.d.ts +34 -0
- package/lib/cjs/helpers/signAndVerifyTypedData.js +58 -0
- package/lib/cjs/helpers/validate.d.ts +40 -1
- package/lib/cjs/helpers/validate.js +47 -5
- package/lib/cjs/helpers/validateMidnightAuthorizationTarget.d.ts +15 -0
- package/lib/cjs/helpers/validateMidnightAuthorizationTarget.js +32 -0
- package/lib/cjs/helpers/validateMidnightMarket.d.ts +10 -0
- package/lib/cjs/helpers/validateMidnightMarket.js +24 -0
- package/lib/cjs/helpers/validateOfferSides.d.ts +21 -0
- package/lib/cjs/helpers/validateOfferSides.js +36 -0
- package/lib/cjs/helpers/validateRequirementSpender.d.ts +29 -0
- package/lib/cjs/helpers/validateRequirementSpender.js +49 -0
- package/lib/cjs/helpers/validateTakeableOffers.d.ts +18 -0
- package/lib/cjs/helpers/validateTakeableOffers.js +35 -0
- package/lib/cjs/midnight-api.d.ts +1 -0
- package/lib/cjs/midnight-api.js +17 -0
- package/lib/cjs/types/action.d.ts +189 -23
- package/lib/cjs/types/action.js +27 -7
- package/lib/cjs/types/client.d.ts +3 -2
- package/lib/cjs/types/error.d.ts +288 -119
- package/lib/cjs/types/error.js +259 -180
- package/lib/cjs/utils.d.ts +1 -0
- package/lib/cjs/utils.js +12 -2
- package/lib/esm/abis.d.ts +1 -0
- package/lib/esm/abis.js +1 -0
- package/lib/esm/actions/blue/borrow.d.ts +3 -7
- package/lib/esm/actions/blue/borrow.js +6 -10
- package/lib/esm/actions/blue/buildReallocationActions.d.ts +3 -4
- package/lib/esm/actions/blue/buildReallocationActions.js +3 -4
- package/lib/esm/actions/blue/refinance.d.ts +4 -8
- package/lib/esm/actions/blue/refinance.js +11 -15
- package/lib/esm/actions/blue/repay.d.ts +2 -5
- package/lib/esm/actions/blue/repay.js +2 -5
- package/lib/esm/actions/blue/repayWithdrawCollateral.d.ts +3 -6
- package/lib/esm/actions/blue/repayWithdrawCollateral.js +5 -8
- package/lib/esm/actions/blue/resolveRepayFunding.d.ts +2 -5
- package/lib/esm/actions/blue/resolveRepayFunding.js +16 -13
- package/lib/esm/actions/blue/supply.d.ts +2 -4
- package/lib/esm/actions/blue/supply.js +7 -9
- package/lib/esm/actions/blue/supplyCollateral.d.ts +2 -3
- package/lib/esm/actions/blue/supplyCollateral.js +6 -7
- package/lib/esm/actions/blue/supplyCollateralBorrow.d.ts +4 -9
- package/lib/esm/actions/blue/supplyCollateralBorrow.js +10 -15
- package/lib/esm/actions/blue/withdraw.d.ts +9 -7
- package/lib/esm/actions/blue/withdraw.js +19 -11
- package/lib/esm/actions/blue/withdrawCollateral.d.ts +1 -1
- package/lib/esm/actions/blue/withdrawCollateral.js +3 -3
- package/lib/esm/actions/index.d.ts +2 -0
- package/lib/esm/actions/index.js +1 -0
- package/lib/esm/actions/midnight/authorization.d.ts +37 -0
- package/lib/esm/actions/midnight/authorization.js +65 -0
- package/lib/esm/actions/midnight/cancelOffer.d.ts +38 -0
- package/lib/esm/actions/midnight/cancelOffer.js +69 -0
- package/lib/esm/actions/midnight/index.d.ts +11 -0
- package/lib/esm/actions/midnight/index.js +11 -0
- package/lib/esm/actions/midnight/mempoolSubmitOffers.d.ts +52 -0
- package/lib/esm/actions/midnight/mempoolSubmitOffers.js +68 -0
- package/lib/esm/actions/midnight/redeem.d.ts +43 -0
- package/lib/esm/actions/midnight/redeem.js +75 -0
- package/lib/esm/actions/midnight/repayWithdrawCollateral.d.ts +53 -0
- package/lib/esm/actions/midnight/repayWithdrawCollateral.js +117 -0
- package/lib/esm/actions/midnight/setterRatifierRatifyRoot.d.ts +40 -0
- package/lib/esm/actions/midnight/setterRatifierRatifyRoot.js +55 -0
- package/lib/esm/actions/midnight/supplyCollateral.d.ts +45 -0
- package/lib/esm/actions/midnight/supplyCollateral.js +79 -0
- package/lib/esm/actions/midnight/supplyCollateralTakeBorrow.d.ts +51 -0
- package/lib/esm/actions/midnight/supplyCollateralTakeBorrow.js +124 -0
- package/lib/esm/actions/midnight/takeBorrow.d.ts +57 -0
- package/lib/esm/actions/midnight/takeBorrow.js +106 -0
- package/lib/esm/actions/midnight/takeLend.d.ts +57 -0
- package/lib/esm/actions/midnight/takeLend.js +106 -0
- package/lib/esm/actions/midnight/types.d.ts +39 -0
- package/lib/esm/actions/midnight/types.js +12 -0
- package/lib/esm/actions/requirements/encode/encodeBlueSignatureAuthorization.d.ts +1 -1
- package/lib/esm/actions/requirements/encode/encodeBlueSignatureAuthorization.js +6 -17
- package/lib/esm/actions/requirements/encode/encodeErc20Approval.d.ts +5 -4
- package/lib/esm/actions/requirements/encode/encodeErc20Approval.js +12 -16
- package/lib/esm/actions/requirements/encode/encodeErc20Permit.d.ts +2 -2
- package/lib/esm/actions/requirements/encode/encodeErc20Permit.js +12 -29
- package/lib/esm/actions/requirements/encode/encodeErc20Permit2Approve.d.ts +1 -1
- package/lib/esm/actions/requirements/encode/encodeErc20Permit2Approve.js +5 -17
- package/lib/esm/actions/requirements/generalAdapter/getGeneralAdapterRequirementsPermit.d.ts +1 -1
- package/lib/esm/actions/requirements/getRequirementsApproval.d.ts +10 -4
- package/lib/esm/actions/requirements/getRequirementsApproval.js +10 -4
- package/lib/esm/actions/requirements/index.d.ts +1 -0
- package/lib/esm/actions/requirements/index.js +1 -0
- package/lib/esm/actions/requirements/midnight/getMidnightApprovalRequirements.d.ts +49 -0
- package/lib/esm/actions/requirements/midnight/getMidnightApprovalRequirements.js +72 -0
- package/lib/esm/actions/requirements/midnight/getMidnightAuthorizationRequirement.d.ts +44 -0
- package/lib/esm/actions/requirements/midnight/getMidnightAuthorizationRequirement.js +74 -0
- package/lib/esm/actions/requirements/midnight/getSetterRatifierRatifyRootRequirement.d.ts +42 -0
- package/lib/esm/actions/requirements/midnight/getSetterRatifierRatifyRootRequirement.js +66 -0
- package/lib/esm/actions/requirements/midnight/index.d.ts +3 -0
- package/lib/esm/actions/requirements/midnight/index.js +3 -0
- package/lib/esm/actions/vaultV1/deposit.d.ts +3 -4
- package/lib/esm/actions/vaultV1/deposit.js +8 -9
- package/lib/esm/actions/vaultV1/migrateToV2.d.ts +2 -3
- package/lib/esm/actions/vaultV1/migrateToV2.js +6 -7
- package/lib/esm/actions/vaultV1/redeem.d.ts +1 -1
- package/lib/esm/actions/vaultV1/redeem.js +3 -3
- package/lib/esm/actions/vaultV1/withdraw.d.ts +1 -1
- package/lib/esm/actions/vaultV1/withdraw.js +3 -3
- package/lib/esm/actions/vaultV2/deposit.d.ts +3 -4
- package/lib/esm/actions/vaultV2/deposit.js +8 -9
- package/lib/esm/actions/vaultV2/forceRedeem.d.ts +2 -3
- package/lib/esm/actions/vaultV2/forceRedeem.js +4 -5
- package/lib/esm/actions/vaultV2/forceWithdraw.d.ts +1 -1
- package/lib/esm/actions/vaultV2/forceWithdraw.js +3 -3
- package/lib/esm/actions/vaultV2/redeem.d.ts +1 -1
- package/lib/esm/actions/vaultV2/redeem.js +3 -3
- package/lib/esm/actions/vaultV2/withdraw.d.ts +1 -1
- package/lib/esm/actions/vaultV2/withdraw.js +3 -3
- package/lib/esm/client/morphoViemExtension.d.ts +1 -1
- package/lib/esm/client/morphoViemExtension.js +6 -3
- package/lib/esm/constants.d.ts +1 -0
- package/lib/esm/constants.js +1 -0
- package/lib/esm/entities/blue/blue.d.ts +5 -5
- package/lib/esm/entities/blue/blue.js +95 -70
- package/lib/esm/entities/index.d.ts +1 -0
- package/lib/esm/entities/index.js +1 -0
- package/lib/esm/entities/midnight/index.d.ts +2 -0
- package/lib/esm/entities/midnight/index.js +2 -0
- package/lib/esm/entities/midnight/midnight.d.ts +402 -0
- package/lib/esm/entities/midnight/midnight.js +1032 -0
- package/lib/esm/entities/midnight/types.d.ts +164 -0
- package/lib/esm/entities/midnight/types.js +1 -0
- package/lib/esm/entities/vaultV1/vaultV1.js +13 -20
- package/lib/esm/entities/vaultV2/vaultV2.js +9 -11
- package/lib/esm/errors.d.ts +1 -0
- package/lib/esm/errors.js +1 -0
- package/lib/esm/helpers/encodeDeallocation.d.ts +1 -0
- package/lib/esm/helpers/encodeDeallocation.js +3 -2
- package/lib/esm/helpers/index.d.ts +4 -1
- package/lib/esm/helpers/index.js +4 -1
- package/lib/esm/helpers/signAndVerifyTypedData.d.ts +34 -0
- package/lib/esm/helpers/signAndVerifyTypedData.js +54 -0
- package/lib/esm/helpers/validate.d.ts +40 -1
- package/lib/esm/helpers/validate.js +46 -5
- package/lib/esm/helpers/validateMidnightAuthorizationTarget.d.ts +15 -0
- package/lib/esm/helpers/validateMidnightAuthorizationTarget.js +28 -0
- package/lib/esm/helpers/validateMidnightMarket.d.ts +10 -0
- package/lib/esm/helpers/validateMidnightMarket.js +20 -0
- package/lib/esm/helpers/validateOfferSides.d.ts +21 -0
- package/lib/esm/helpers/validateOfferSides.js +32 -0
- package/lib/esm/helpers/validateRequirementSpender.d.ts +29 -0
- package/lib/esm/helpers/validateRequirementSpender.js +45 -0
- package/lib/esm/helpers/validateTakeableOffers.d.ts +18 -0
- package/lib/esm/helpers/validateTakeableOffers.js +31 -0
- package/lib/esm/midnight-api.d.ts +1 -0
- package/lib/esm/midnight-api.js +1 -0
- package/lib/esm/types/action.d.ts +189 -23
- package/lib/esm/types/action.js +26 -7
- package/lib/esm/types/client.d.ts +3 -2
- package/lib/esm/types/error.d.ts +288 -119
- package/lib/esm/types/error.js +232 -154
- package/lib/esm/utils.d.ts +1 -0
- package/lib/esm/utils.js +1 -0
- package/package.json +12 -3
|
@@ -64,14 +64,16 @@ export interface BlueWithdrawParams {
|
|
|
64
64
|
* @param params.metadata - Optional analytics metadata attached to the bundle.
|
|
65
65
|
* @returns A deep-frozen `Transaction<BlueWithdrawAction>` with `to`, `value`, `data`, and
|
|
66
66
|
* the typed `action` discriminator the simulation layer consumes.
|
|
67
|
-
* @throws {
|
|
67
|
+
* @throws {NegativeInputError} when `assets`, `shares`, `minSharePrice`, or any reallocation fee
|
|
68
|
+
* is negative.
|
|
69
|
+
* @throws {NonPositiveInputError} when both `assets` and `shares` are zero or any reallocation
|
|
70
|
+
* withdrawal amount is non-positive.
|
|
68
71
|
* @throws {MutuallyExclusiveWithdrawAmountsError} when both `assets` and `shares` are non-zero.
|
|
69
|
-
* @throws {
|
|
70
|
-
*
|
|
71
|
-
*
|
|
72
|
-
*
|
|
73
|
-
*
|
|
74
|
-
* `UnsortedReallocationWithdrawalsError`).
|
|
72
|
+
* @throws {EmptyReallocationWithdrawalsError} when any reallocation has no withdrawals.
|
|
73
|
+
* @throws {ReallocationWithdrawalOnTargetMarketError} when a reallocation withdrawal references
|
|
74
|
+
* the target market.
|
|
75
|
+
* @throws {UnsortedReallocationWithdrawalsError} when reallocation withdrawals are not strictly
|
|
76
|
+
* sorted by market id.
|
|
75
77
|
* @example
|
|
76
78
|
* ```ts
|
|
77
79
|
* import { blueWithdraw } from "@morpho-org/morpho-sdk";
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { deepFreeze } from "@morpho-org/morpho-ts";
|
|
2
2
|
import { BundlerAction } from "../../bundler/index.js";
|
|
3
3
|
import { addTransactionMetadata } from "../../helpers/index.js";
|
|
4
|
-
import { MutuallyExclusiveWithdrawAmountsError,
|
|
4
|
+
import { MutuallyExclusiveWithdrawAmountsError, NegativeInputError, NonPositiveInputError, } from "../../types/index.js";
|
|
5
5
|
import { getBlueAuthorizationAction } from "../signatures/getBlueAuthorizationAction.js";
|
|
6
6
|
import { buildReallocationActions } from "./buildReallocationActions.js";
|
|
7
7
|
/**
|
|
@@ -37,14 +37,16 @@ import { buildReallocationActions } from "./buildReallocationActions.js";
|
|
|
37
37
|
* @param params.metadata - Optional analytics metadata attached to the bundle.
|
|
38
38
|
* @returns A deep-frozen `Transaction<BlueWithdrawAction>` with `to`, `value`, `data`, and
|
|
39
39
|
* the typed `action` discriminator the simulation layer consumes.
|
|
40
|
-
* @throws {
|
|
40
|
+
* @throws {NegativeInputError} when `assets`, `shares`, `minSharePrice`, or any reallocation fee
|
|
41
|
+
* is negative.
|
|
42
|
+
* @throws {NonPositiveInputError} when both `assets` and `shares` are zero or any reallocation
|
|
43
|
+
* withdrawal amount is non-positive.
|
|
41
44
|
* @throws {MutuallyExclusiveWithdrawAmountsError} when both `assets` and `shares` are non-zero.
|
|
42
|
-
* @throws {
|
|
43
|
-
*
|
|
44
|
-
*
|
|
45
|
-
*
|
|
46
|
-
*
|
|
47
|
-
* `UnsortedReallocationWithdrawalsError`).
|
|
45
|
+
* @throws {EmptyReallocationWithdrawalsError} when any reallocation has no withdrawals.
|
|
46
|
+
* @throws {ReallocationWithdrawalOnTargetMarketError} when a reallocation withdrawal references
|
|
47
|
+
* the target market.
|
|
48
|
+
* @throws {UnsortedReallocationWithdrawalsError} when reallocation withdrawals are not strictly
|
|
49
|
+
* sorted by market id.
|
|
48
50
|
* @example
|
|
49
51
|
* ```ts
|
|
50
52
|
* import { blueWithdraw } from "@morpho-org/morpho-sdk";
|
|
@@ -68,11 +70,17 @@ export const blueWithdraw = ({ market: { chainId, marketParams }, args: { assets
|
|
|
68
70
|
if (assets !== 0n && shares !== 0n) {
|
|
69
71
|
throw new MutuallyExclusiveWithdrawAmountsError(marketParams.id);
|
|
70
72
|
}
|
|
71
|
-
if (assets < 0n
|
|
72
|
-
throw new
|
|
73
|
+
if (assets < 0n) {
|
|
74
|
+
throw new NegativeInputError("assets", assets);
|
|
75
|
+
}
|
|
76
|
+
if (shares < 0n) {
|
|
77
|
+
throw new NegativeInputError("shares", shares);
|
|
78
|
+
}
|
|
79
|
+
if (assets === 0n && shares === 0n) {
|
|
80
|
+
throw new NonPositiveInputError("assets or shares", 0n);
|
|
73
81
|
}
|
|
74
82
|
if (minSharePrice < 0n) {
|
|
75
|
-
throw new
|
|
83
|
+
throw new NegativeInputError("minSharePrice", minSharePrice);
|
|
76
84
|
}
|
|
77
85
|
const actions = [];
|
|
78
86
|
let reallocationFee = 0n;
|
|
@@ -30,7 +30,7 @@ export interface BlueWithdrawCollateralParams {
|
|
|
30
30
|
* @param params.metadata - Optional analytics metadata attached to the transaction.
|
|
31
31
|
* @returns A deep-frozen `Transaction<BlueWithdrawCollateralAction>` with `to`, `value`,
|
|
32
32
|
* `data`, and the typed `action` discriminator the simulation layer consumes.
|
|
33
|
-
* @throws {
|
|
33
|
+
* @throws {NonPositiveInputError} when `amount <= 0n`.
|
|
34
34
|
* @example
|
|
35
35
|
* ```ts
|
|
36
36
|
* import { blueWithdrawCollateral } from "@morpho-org/morpho-sdk";
|
|
@@ -3,7 +3,7 @@ import { blueAbi } from "@morpho-org/blue-sdk-viem";
|
|
|
3
3
|
import { deepFreeze } from "@morpho-org/morpho-ts";
|
|
4
4
|
import { encodeFunctionData } from "viem";
|
|
5
5
|
import { addTransactionMetadata } from "../../helpers/index.js";
|
|
6
|
-
import {
|
|
6
|
+
import { NonPositiveInputError, } from "../../types/index.js";
|
|
7
7
|
/**
|
|
8
8
|
* Prepares a withdraw-collateral transaction for a Morpho Blue market.
|
|
9
9
|
*
|
|
@@ -20,7 +20,7 @@ import { NonPositiveWithdrawCollateralAmountError, } from "../../types/index.js"
|
|
|
20
20
|
* @param params.metadata - Optional analytics metadata attached to the transaction.
|
|
21
21
|
* @returns A deep-frozen `Transaction<BlueWithdrawCollateralAction>` with `to`, `value`,
|
|
22
22
|
* `data`, and the typed `action` discriminator the simulation layer consumes.
|
|
23
|
-
* @throws {
|
|
23
|
+
* @throws {NonPositiveInputError} when `amount <= 0n`.
|
|
24
24
|
* @example
|
|
25
25
|
* ```ts
|
|
26
26
|
* import { blueWithdrawCollateral } from "@morpho-org/morpho-sdk";
|
|
@@ -38,7 +38,7 @@ import { NonPositiveWithdrawCollateralAmountError, } from "../../types/index.js"
|
|
|
38
38
|
*/
|
|
39
39
|
export const blueWithdrawCollateral = ({ market: { chainId, marketParams }, args: { amount, onBehalf, receiver }, metadata, }) => {
|
|
40
40
|
if (amount <= 0n) {
|
|
41
|
-
throw new
|
|
41
|
+
throw new NonPositiveInputError("amount", amount);
|
|
42
42
|
}
|
|
43
43
|
const { morpho } = getChainAddresses(chainId);
|
|
44
44
|
let tx = {
|
|
@@ -1,7 +1,9 @@
|
|
|
1
1
|
export type { BlueActions } from "../entities/blue/index.js";
|
|
2
|
+
export type { MidnightActions } from "../entities/midnight/index.js";
|
|
2
3
|
export type { VaultV1Actions } from "../entities/vaultV1/index.js";
|
|
3
4
|
export type { VaultV2Actions } from "../entities/vaultV2/index.js";
|
|
4
5
|
export * from "./blue/index.js";
|
|
6
|
+
export * from "./midnight/index.js";
|
|
5
7
|
export * from "./requirements/index.js";
|
|
6
8
|
export * from "./signatures/index.js";
|
|
7
9
|
export * from "./vaultV1/index.js";
|
package/lib/esm/actions/index.js
CHANGED
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import { type Address } from "viem";
|
|
2
|
+
import type { Metadata, MidnightAuthorizationAction, Transaction } from "../../types/index.js";
|
|
3
|
+
/** Parameters for encoding a direct Midnight `setIsAuthorized` call. */
|
|
4
|
+
export interface MidnightSetIsAuthorizedParams {
|
|
5
|
+
readonly chainId: number;
|
|
6
|
+
readonly authorized: Address;
|
|
7
|
+
readonly onBehalf: Address;
|
|
8
|
+
readonly isAuthorized?: boolean;
|
|
9
|
+
readonly metadata?: Metadata;
|
|
10
|
+
}
|
|
11
|
+
/**
|
|
12
|
+
* Encodes `Midnight.setIsAuthorized` for a bundle spender or ratifier.
|
|
13
|
+
*
|
|
14
|
+
* Prefer requirement helpers or entity `getRequirements()` in app flows; they
|
|
15
|
+
* read `isAuthorized` first and return this transaction only when needed. Use
|
|
16
|
+
* this builder directly when the caller intentionally wants to set or revoke
|
|
17
|
+
* authorization without reading state.
|
|
18
|
+
*
|
|
19
|
+
* @param params.chainId - Chain id used to resolve `Midnight`.
|
|
20
|
+
* @param params.authorized - Supported operator receiving authorization, or any operator losing authorization.
|
|
21
|
+
* @param params.onBehalf - Owner whose authorization mapping is updated.
|
|
22
|
+
* @param params.isAuthorized - Optional target state; defaults to `true`.
|
|
23
|
+
* @param params.metadata - Optional analytics metadata appended to calldata.
|
|
24
|
+
* @returns A deep-frozen `Transaction<MidnightAuthorizationAction>` targeting `Midnight`.
|
|
25
|
+
* @throws {UnsupportedMidnightAuthorizationTargetError} when granting authorization to an unsupported operator.
|
|
26
|
+
* @example
|
|
27
|
+
* ```ts
|
|
28
|
+
* import { midnightSetIsAuthorized } from "@morpho-org/morpho-sdk";
|
|
29
|
+
*
|
|
30
|
+
* const tx = midnightSetIsAuthorized({
|
|
31
|
+
* chainId: 8453,
|
|
32
|
+
* authorized: midnightBundles,
|
|
33
|
+
* onBehalf: user,
|
|
34
|
+
* });
|
|
35
|
+
* ```
|
|
36
|
+
*/
|
|
37
|
+
export declare const midnightSetIsAuthorized: (params: MidnightSetIsAuthorizedParams) => Readonly<Transaction<MidnightAuthorizationAction>>;
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
import { midnightAbi } from "@morpho-org/midnight-sdk";
|
|
2
|
+
import { deepFreeze, getChainAddress } from "@morpho-org/morpho-ts";
|
|
3
|
+
import { encodeFunctionData } from "viem";
|
|
4
|
+
import { addTransactionMetadata } from "../../helpers/index.js";
|
|
5
|
+
import { validateMidnightAuthorizationTarget } from "../../helpers/validateMidnightAuthorizationTarget.js";
|
|
6
|
+
/**
|
|
7
|
+
* Encodes `Midnight.setIsAuthorized` for a bundle spender or ratifier.
|
|
8
|
+
*
|
|
9
|
+
* Prefer requirement helpers or entity `getRequirements()` in app flows; they
|
|
10
|
+
* read `isAuthorized` first and return this transaction only when needed. Use
|
|
11
|
+
* this builder directly when the caller intentionally wants to set or revoke
|
|
12
|
+
* authorization without reading state.
|
|
13
|
+
*
|
|
14
|
+
* @param params.chainId - Chain id used to resolve `Midnight`.
|
|
15
|
+
* @param params.authorized - Supported operator receiving authorization, or any operator losing authorization.
|
|
16
|
+
* @param params.onBehalf - Owner whose authorization mapping is updated.
|
|
17
|
+
* @param params.isAuthorized - Optional target state; defaults to `true`.
|
|
18
|
+
* @param params.metadata - Optional analytics metadata appended to calldata.
|
|
19
|
+
* @returns A deep-frozen `Transaction<MidnightAuthorizationAction>` targeting `Midnight`.
|
|
20
|
+
* @throws {UnsupportedMidnightAuthorizationTargetError} when granting authorization to an unsupported operator.
|
|
21
|
+
* @example
|
|
22
|
+
* ```ts
|
|
23
|
+
* import { midnightSetIsAuthorized } from "@morpho-org/morpho-sdk";
|
|
24
|
+
*
|
|
25
|
+
* const tx = midnightSetIsAuthorized({
|
|
26
|
+
* chainId: 8453,
|
|
27
|
+
* authorized: midnightBundles,
|
|
28
|
+
* onBehalf: user,
|
|
29
|
+
* });
|
|
30
|
+
* ```
|
|
31
|
+
*/
|
|
32
|
+
export const midnightSetIsAuthorized = (params) => {
|
|
33
|
+
const isAuthorized = params.isAuthorized ?? true;
|
|
34
|
+
if (isAuthorized) {
|
|
35
|
+
// Restrict grants to known protocol operators; revocations remain permissionless by target.
|
|
36
|
+
validateMidnightAuthorizationTarget({
|
|
37
|
+
chainId: params.chainId,
|
|
38
|
+
authorized: params.authorized,
|
|
39
|
+
});
|
|
40
|
+
}
|
|
41
|
+
const midnight = getChainAddress(params.chainId, "midnight");
|
|
42
|
+
let tx = {
|
|
43
|
+
to: midnight,
|
|
44
|
+
value: 0n,
|
|
45
|
+
data: encodeFunctionData({
|
|
46
|
+
abi: midnightAbi,
|
|
47
|
+
functionName: "setIsAuthorized",
|
|
48
|
+
args: [params.authorized, isAuthorized, params.onBehalf],
|
|
49
|
+
}),
|
|
50
|
+
};
|
|
51
|
+
if (params.metadata) {
|
|
52
|
+
tx = addTransactionMetadata(tx, params.metadata);
|
|
53
|
+
}
|
|
54
|
+
return deepFreeze({
|
|
55
|
+
...tx,
|
|
56
|
+
action: {
|
|
57
|
+
type: "midnightAuthorization",
|
|
58
|
+
args: {
|
|
59
|
+
authorized: params.authorized,
|
|
60
|
+
isAuthorized,
|
|
61
|
+
onBehalf: params.onBehalf,
|
|
62
|
+
},
|
|
63
|
+
},
|
|
64
|
+
});
|
|
65
|
+
};
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import { type Address, type Hex } from "viem";
|
|
2
|
+
import type { Metadata, MidnightCancelOfferAction, Transaction } from "../../types/index.js";
|
|
3
|
+
/** Parameters for encoding a Midnight group consumption update. */
|
|
4
|
+
export interface MidnightCancelOfferParams {
|
|
5
|
+
readonly chainId: number;
|
|
6
|
+
readonly group: Hex;
|
|
7
|
+
readonly onBehalf: Address;
|
|
8
|
+
readonly amount?: bigint;
|
|
9
|
+
readonly metadata?: Metadata;
|
|
10
|
+
}
|
|
11
|
+
/**
|
|
12
|
+
* Encodes `Midnight.setConsumed` to cancel or partially consume an offer group.
|
|
13
|
+
*
|
|
14
|
+
* App flows should usually call `client.morpho.midnight(chainId).cancelOffer(...)`.
|
|
15
|
+
* Use this builder directly when the group id is already known and no
|
|
16
|
+
* additional requirements are needed. Omitting `amount` fully cancels the group
|
|
17
|
+
* by setting consumption to {@link MAX_OFFER_CAP}.
|
|
18
|
+
*
|
|
19
|
+
* @param params.chainId - Chain id used to resolve `Midnight`.
|
|
20
|
+
* @param params.group - Offer group id to mark consumed.
|
|
21
|
+
* @param params.onBehalf - Maker whose group consumption is updated.
|
|
22
|
+
* @param params.amount - Optional consumed amount; defaults to {@link MAX_OFFER_CAP} for full cancellation.
|
|
23
|
+
* @param params.metadata - Optional analytics metadata appended to calldata.
|
|
24
|
+
* @returns A deep-frozen `Transaction<MidnightCancelOfferAction>` targeting `Midnight`.
|
|
25
|
+
* @throws {NegativeInputError} when `amount` is negative.
|
|
26
|
+
* @throws {MidnightAmountExceedsMaxOfferCapError} when `amount` exceeds {@link MAX_OFFER_CAP}.
|
|
27
|
+
* @example
|
|
28
|
+
* ```ts
|
|
29
|
+
* import { midnightCancelOffer } from "@morpho-org/morpho-sdk";
|
|
30
|
+
*
|
|
31
|
+
* const tx = midnightCancelOffer({
|
|
32
|
+
* chainId: 8453,
|
|
33
|
+
* group,
|
|
34
|
+
* onBehalf: maker,
|
|
35
|
+
* });
|
|
36
|
+
* ```
|
|
37
|
+
*/
|
|
38
|
+
export declare const midnightCancelOffer: (params: MidnightCancelOfferParams) => Readonly<Transaction<MidnightCancelOfferAction>>;
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
import { MAX_OFFER_CAP, midnightAbi } from "@morpho-org/midnight-sdk";
|
|
2
|
+
import { deepFreeze, getChainAddress } from "@morpho-org/morpho-ts";
|
|
3
|
+
import { encodeFunctionData } from "viem";
|
|
4
|
+
import { addTransactionMetadata } from "../../helpers/index.js";
|
|
5
|
+
import { MidnightAmountExceedsMaxOfferCapError, NegativeInputError, } from "../../types/index.js";
|
|
6
|
+
/**
|
|
7
|
+
* Encodes `Midnight.setConsumed` to cancel or partially consume an offer group.
|
|
8
|
+
*
|
|
9
|
+
* App flows should usually call `client.morpho.midnight(chainId).cancelOffer(...)`.
|
|
10
|
+
* Use this builder directly when the group id is already known and no
|
|
11
|
+
* additional requirements are needed. Omitting `amount` fully cancels the group
|
|
12
|
+
* by setting consumption to {@link MAX_OFFER_CAP}.
|
|
13
|
+
*
|
|
14
|
+
* @param params.chainId - Chain id used to resolve `Midnight`.
|
|
15
|
+
* @param params.group - Offer group id to mark consumed.
|
|
16
|
+
* @param params.onBehalf - Maker whose group consumption is updated.
|
|
17
|
+
* @param params.amount - Optional consumed amount; defaults to {@link MAX_OFFER_CAP} for full cancellation.
|
|
18
|
+
* @param params.metadata - Optional analytics metadata appended to calldata.
|
|
19
|
+
* @returns A deep-frozen `Transaction<MidnightCancelOfferAction>` targeting `Midnight`.
|
|
20
|
+
* @throws {NegativeInputError} when `amount` is negative.
|
|
21
|
+
* @throws {MidnightAmountExceedsMaxOfferCapError} when `amount` exceeds {@link MAX_OFFER_CAP}.
|
|
22
|
+
* @example
|
|
23
|
+
* ```ts
|
|
24
|
+
* import { midnightCancelOffer } from "@morpho-org/morpho-sdk";
|
|
25
|
+
*
|
|
26
|
+
* const tx = midnightCancelOffer({
|
|
27
|
+
* chainId: 8453,
|
|
28
|
+
* group,
|
|
29
|
+
* onBehalf: maker,
|
|
30
|
+
* });
|
|
31
|
+
* ```
|
|
32
|
+
*/
|
|
33
|
+
export const midnightCancelOffer = (params) => {
|
|
34
|
+
const midnight = getChainAddress(params.chainId, "midnight");
|
|
35
|
+
const amount = params.amount ?? MAX_OFFER_CAP;
|
|
36
|
+
if (amount < 0n) {
|
|
37
|
+
throw new NegativeInputError("amount", amount);
|
|
38
|
+
}
|
|
39
|
+
if (amount > MAX_OFFER_CAP) {
|
|
40
|
+
throw new MidnightAmountExceedsMaxOfferCapError({
|
|
41
|
+
label: "cancel amount",
|
|
42
|
+
amount,
|
|
43
|
+
maxOfferCap: MAX_OFFER_CAP,
|
|
44
|
+
});
|
|
45
|
+
}
|
|
46
|
+
let tx = {
|
|
47
|
+
to: midnight,
|
|
48
|
+
value: 0n,
|
|
49
|
+
data: encodeFunctionData({
|
|
50
|
+
abi: midnightAbi,
|
|
51
|
+
functionName: "setConsumed",
|
|
52
|
+
args: [params.group, amount, params.onBehalf],
|
|
53
|
+
}),
|
|
54
|
+
};
|
|
55
|
+
if (params.metadata) {
|
|
56
|
+
tx = addTransactionMetadata(tx, params.metadata);
|
|
57
|
+
}
|
|
58
|
+
return deepFreeze({
|
|
59
|
+
...tx,
|
|
60
|
+
action: {
|
|
61
|
+
type: "midnightCancelOffer",
|
|
62
|
+
args: {
|
|
63
|
+
group: params.group,
|
|
64
|
+
amount,
|
|
65
|
+
onBehalf: params.onBehalf,
|
|
66
|
+
},
|
|
67
|
+
},
|
|
68
|
+
});
|
|
69
|
+
};
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
export * from "./authorization.js";
|
|
2
|
+
export * from "./cancelOffer.js";
|
|
3
|
+
export * from "./mempoolSubmitOffers.js";
|
|
4
|
+
export * from "./redeem.js";
|
|
5
|
+
export * from "./repayWithdrawCollateral.js";
|
|
6
|
+
export * from "./setterRatifierRatifyRoot.js";
|
|
7
|
+
export * from "./supplyCollateral.js";
|
|
8
|
+
export * from "./supplyCollateralTakeBorrow.js";
|
|
9
|
+
export * from "./takeBorrow.js";
|
|
10
|
+
export * from "./takeLend.js";
|
|
11
|
+
export * from "./types.js";
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
export * from "./authorization.js";
|
|
2
|
+
export * from "./cancelOffer.js";
|
|
3
|
+
export * from "./mempoolSubmitOffers.js";
|
|
4
|
+
export * from "./redeem.js";
|
|
5
|
+
export * from "./repayWithdrawCollateral.js";
|
|
6
|
+
export * from "./setterRatifierRatifyRoot.js";
|
|
7
|
+
export * from "./supplyCollateral.js";
|
|
8
|
+
export * from "./supplyCollateralTakeBorrow.js";
|
|
9
|
+
export * from "./takeBorrow.js";
|
|
10
|
+
export * from "./takeLend.js";
|
|
11
|
+
export * from "./types.js";
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import type { Address, Hex } from "viem";
|
|
2
|
+
import type { MempoolSubmitOffersAction, Metadata, Transaction } from "../../types/index.js";
|
|
3
|
+
/** Parameters for publishing an already ratified Midnight offer payload. */
|
|
4
|
+
export interface MempoolSubmitOffersParams {
|
|
5
|
+
readonly chainId: number;
|
|
6
|
+
readonly groups: readonly Hex[];
|
|
7
|
+
readonly root: Hex;
|
|
8
|
+
readonly maker: Address;
|
|
9
|
+
readonly ratifier: Address;
|
|
10
|
+
readonly ratifierType: "ecrecover" | "setter";
|
|
11
|
+
readonly offers: number;
|
|
12
|
+
readonly payload: Hex;
|
|
13
|
+
readonly metadata?: Metadata;
|
|
14
|
+
}
|
|
15
|
+
/**
|
|
16
|
+
* Encodes a Midnight mempool payload submission transaction.
|
|
17
|
+
*
|
|
18
|
+
* App make-offer flows should call `getOffersData`, gather the returned
|
|
19
|
+
* requirements, then call the output `buildTx(signatures)`. Use this builder
|
|
20
|
+
* directly only when the payload has already been encoded with ratifier data
|
|
21
|
+
* and the caller wants to submit those bytes to the mempool contract.
|
|
22
|
+
*
|
|
23
|
+
* @param params.chainId - Chain id used to resolve `MidnightMempool`.
|
|
24
|
+
* @param params.groups - Group ids included in the payload.
|
|
25
|
+
* @param params.root - Offer tree root committed by the maker.
|
|
26
|
+
* @param params.maker - Maker whose offers are submitted.
|
|
27
|
+
* @param params.ratifier - Ratifier address shared by the offer tree.
|
|
28
|
+
* @param params.ratifierType - Ratifier route used to build the payload.
|
|
29
|
+
* @param params.offers - Number of non-padding offers in the payload.
|
|
30
|
+
* @param params.payload - Encoded mempool payload bytes.
|
|
31
|
+
* @param params.metadata - Optional analytics metadata appended to calldata.
|
|
32
|
+
* @returns A deep-frozen `Transaction<MempoolSubmitOffersAction>` targeting `MidnightMempool`.
|
|
33
|
+
* @throws {InvalidTreeError} when `offers <= 0`.
|
|
34
|
+
* @example
|
|
35
|
+
* ```ts
|
|
36
|
+
* import { Payload } from "@morpho-org/midnight-sdk";
|
|
37
|
+
* import { mempoolSubmitOffers } from "@morpho-org/morpho-sdk";
|
|
38
|
+
*
|
|
39
|
+
* const payload = await Payload.encode(items);
|
|
40
|
+
* const tx = mempoolSubmitOffers({
|
|
41
|
+
* chainId: 8453,
|
|
42
|
+
* groups,
|
|
43
|
+
* root: tree.root,
|
|
44
|
+
* maker,
|
|
45
|
+
* ratifier,
|
|
46
|
+
* ratifierType: "ecrecover",
|
|
47
|
+
* offers: tree.offers.length,
|
|
48
|
+
* payload,
|
|
49
|
+
* });
|
|
50
|
+
* ```
|
|
51
|
+
*/
|
|
52
|
+
export declare const mempoolSubmitOffers: (params: MempoolSubmitOffersParams) => Readonly<Transaction<MempoolSubmitOffersAction>>;
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
import { InvalidTreeError } from "@morpho-org/midnight-sdk";
|
|
2
|
+
import { deepFreeze, getChainAddress } from "@morpho-org/morpho-ts";
|
|
3
|
+
import { addTransactionMetadata } from "../../helpers/index.js";
|
|
4
|
+
/**
|
|
5
|
+
* Encodes a Midnight mempool payload submission transaction.
|
|
6
|
+
*
|
|
7
|
+
* App make-offer flows should call `getOffersData`, gather the returned
|
|
8
|
+
* requirements, then call the output `buildTx(signatures)`. Use this builder
|
|
9
|
+
* directly only when the payload has already been encoded with ratifier data
|
|
10
|
+
* and the caller wants to submit those bytes to the mempool contract.
|
|
11
|
+
*
|
|
12
|
+
* @param params.chainId - Chain id used to resolve `MidnightMempool`.
|
|
13
|
+
* @param params.groups - Group ids included in the payload.
|
|
14
|
+
* @param params.root - Offer tree root committed by the maker.
|
|
15
|
+
* @param params.maker - Maker whose offers are submitted.
|
|
16
|
+
* @param params.ratifier - Ratifier address shared by the offer tree.
|
|
17
|
+
* @param params.ratifierType - Ratifier route used to build the payload.
|
|
18
|
+
* @param params.offers - Number of non-padding offers in the payload.
|
|
19
|
+
* @param params.payload - Encoded mempool payload bytes.
|
|
20
|
+
* @param params.metadata - Optional analytics metadata appended to calldata.
|
|
21
|
+
* @returns A deep-frozen `Transaction<MempoolSubmitOffersAction>` targeting `MidnightMempool`.
|
|
22
|
+
* @throws {InvalidTreeError} when `offers <= 0`.
|
|
23
|
+
* @example
|
|
24
|
+
* ```ts
|
|
25
|
+
* import { Payload } from "@morpho-org/midnight-sdk";
|
|
26
|
+
* import { mempoolSubmitOffers } from "@morpho-org/morpho-sdk";
|
|
27
|
+
*
|
|
28
|
+
* const payload = await Payload.encode(items);
|
|
29
|
+
* const tx = mempoolSubmitOffers({
|
|
30
|
+
* chainId: 8453,
|
|
31
|
+
* groups,
|
|
32
|
+
* root: tree.root,
|
|
33
|
+
* maker,
|
|
34
|
+
* ratifier,
|
|
35
|
+
* ratifierType: "ecrecover",
|
|
36
|
+
* offers: tree.offers.length,
|
|
37
|
+
* payload,
|
|
38
|
+
* });
|
|
39
|
+
* ```
|
|
40
|
+
*/
|
|
41
|
+
export const mempoolSubmitOffers = (params) => {
|
|
42
|
+
if (params.offers <= 0) {
|
|
43
|
+
throw new InvalidTreeError("Tree must contain at least one offer.");
|
|
44
|
+
}
|
|
45
|
+
const midnightMempool = getChainAddress(params.chainId, "midnightMempool");
|
|
46
|
+
let tx = {
|
|
47
|
+
to: midnightMempool,
|
|
48
|
+
value: 0n,
|
|
49
|
+
data: params.payload,
|
|
50
|
+
};
|
|
51
|
+
if (params.metadata) {
|
|
52
|
+
tx = addTransactionMetadata(tx, params.metadata);
|
|
53
|
+
}
|
|
54
|
+
return deepFreeze({
|
|
55
|
+
...tx,
|
|
56
|
+
action: {
|
|
57
|
+
type: "mempoolSubmitOffers",
|
|
58
|
+
args: {
|
|
59
|
+
groups: [...params.groups],
|
|
60
|
+
root: params.root,
|
|
61
|
+
maker: params.maker,
|
|
62
|
+
ratifier: params.ratifier,
|
|
63
|
+
ratifierType: params.ratifierType,
|
|
64
|
+
offers: params.offers,
|
|
65
|
+
},
|
|
66
|
+
},
|
|
67
|
+
});
|
|
68
|
+
};
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import { type MarketInput } from "@morpho-org/midnight-sdk";
|
|
2
|
+
import { type Address } from "viem";
|
|
3
|
+
import { type Metadata, type MidnightRedeemAction, type Transaction } from "../../types/index.js";
|
|
4
|
+
/** Parameters for encoding a direct Midnight credit redemption. */
|
|
5
|
+
export interface MidnightRedeemParams {
|
|
6
|
+
readonly chainId: number;
|
|
7
|
+
readonly market: MarketInput;
|
|
8
|
+
readonly units: bigint;
|
|
9
|
+
readonly onBehalf: Address;
|
|
10
|
+
readonly receiver?: Address;
|
|
11
|
+
readonly metadata?: Metadata;
|
|
12
|
+
}
|
|
13
|
+
/**
|
|
14
|
+
* Encodes a direct Midnight credit redemption.
|
|
15
|
+
*
|
|
16
|
+
* Use this low-level builder after the caller has fetched and checked position
|
|
17
|
+
* credit and market withdrawable liquidity. App flows should usually call
|
|
18
|
+
* `client.morpho.midnight(chainId).redeem(...)`, which performs those checks
|
|
19
|
+
* from the supplied `positionData` snapshot before exposing `buildTx`.
|
|
20
|
+
*
|
|
21
|
+
* @param params.chainId - Chain id used to resolve `Midnight`.
|
|
22
|
+
* @param params.market - Midnight market whose credit is redeemed.
|
|
23
|
+
* @param params.units - Credit units to withdraw.
|
|
24
|
+
* @param params.onBehalf - Account whose credit balance is reduced.
|
|
25
|
+
* @param params.receiver - Optional receiver for withdrawn loan assets; defaults to `onBehalf`.
|
|
26
|
+
* @param params.metadata - Optional analytics metadata appended to calldata.
|
|
27
|
+
* @returns A deep-frozen `Transaction<MidnightRedeemAction>` targeting `Midnight`.
|
|
28
|
+
* @throws {NonPositiveInputError} when `units <= 0n`.
|
|
29
|
+
* @throws {ChainIdMismatchError} when the market targets another chain.
|
|
30
|
+
* @throws {MidnightMarketAddressMismatchError} when the market targets another Midnight deployment.
|
|
31
|
+
* @example
|
|
32
|
+
* ```ts
|
|
33
|
+
* import { midnightRedeem } from "@morpho-org/morpho-sdk";
|
|
34
|
+
*
|
|
35
|
+
* const tx = midnightRedeem({
|
|
36
|
+
* chainId: 8453,
|
|
37
|
+
* market: marketData.params,
|
|
38
|
+
* units: positionData.faceValue,
|
|
39
|
+
* onBehalf: user,
|
|
40
|
+
* });
|
|
41
|
+
* ```
|
|
42
|
+
*/
|
|
43
|
+
export declare const midnightRedeem: (params: MidnightRedeemParams) => Readonly<Transaction<MidnightRedeemAction>>;
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
import { MarketUtils, midnightAbi, } from "@morpho-org/midnight-sdk";
|
|
2
|
+
import { deepFreeze, getChainAddress } from "@morpho-org/morpho-ts";
|
|
3
|
+
import { encodeFunctionData } from "viem";
|
|
4
|
+
import { addTransactionMetadata } from "../../helpers/index.js";
|
|
5
|
+
import { validateMidnightMarket } from "../../helpers/validateMidnightMarket.js";
|
|
6
|
+
import { NonPositiveInputError, } from "../../types/index.js";
|
|
7
|
+
/**
|
|
8
|
+
* Encodes a direct Midnight credit redemption.
|
|
9
|
+
*
|
|
10
|
+
* Use this low-level builder after the caller has fetched and checked position
|
|
11
|
+
* credit and market withdrawable liquidity. App flows should usually call
|
|
12
|
+
* `client.morpho.midnight(chainId).redeem(...)`, which performs those checks
|
|
13
|
+
* from the supplied `positionData` snapshot before exposing `buildTx`.
|
|
14
|
+
*
|
|
15
|
+
* @param params.chainId - Chain id used to resolve `Midnight`.
|
|
16
|
+
* @param params.market - Midnight market whose credit is redeemed.
|
|
17
|
+
* @param params.units - Credit units to withdraw.
|
|
18
|
+
* @param params.onBehalf - Account whose credit balance is reduced.
|
|
19
|
+
* @param params.receiver - Optional receiver for withdrawn loan assets; defaults to `onBehalf`.
|
|
20
|
+
* @param params.metadata - Optional analytics metadata appended to calldata.
|
|
21
|
+
* @returns A deep-frozen `Transaction<MidnightRedeemAction>` targeting `Midnight`.
|
|
22
|
+
* @throws {NonPositiveInputError} when `units <= 0n`.
|
|
23
|
+
* @throws {ChainIdMismatchError} when the market targets another chain.
|
|
24
|
+
* @throws {MidnightMarketAddressMismatchError} when the market targets another Midnight deployment.
|
|
25
|
+
* @example
|
|
26
|
+
* ```ts
|
|
27
|
+
* import { midnightRedeem } from "@morpho-org/morpho-sdk";
|
|
28
|
+
*
|
|
29
|
+
* const tx = midnightRedeem({
|
|
30
|
+
* chainId: 8453,
|
|
31
|
+
* market: marketData.params,
|
|
32
|
+
* units: positionData.faceValue,
|
|
33
|
+
* onBehalf: user,
|
|
34
|
+
* });
|
|
35
|
+
* ```
|
|
36
|
+
*/
|
|
37
|
+
export const midnightRedeem = (params) => {
|
|
38
|
+
if (params.units <= 0n) {
|
|
39
|
+
throw new NonPositiveInputError("units", params.units);
|
|
40
|
+
}
|
|
41
|
+
// Reject markets from another chain deployment before encoding the call.
|
|
42
|
+
validateMidnightMarket({ market: params.market, chainId: params.chainId });
|
|
43
|
+
const marketId = MarketUtils.toId(params.market);
|
|
44
|
+
const midnight = getChainAddress(params.chainId, "midnight");
|
|
45
|
+
const receiver = params.receiver ?? params.onBehalf;
|
|
46
|
+
let tx = {
|
|
47
|
+
to: midnight,
|
|
48
|
+
value: 0n,
|
|
49
|
+
data: encodeFunctionData({
|
|
50
|
+
abi: midnightAbi,
|
|
51
|
+
functionName: "withdraw",
|
|
52
|
+
args: [
|
|
53
|
+
MarketUtils.toStruct(params.market),
|
|
54
|
+
params.units,
|
|
55
|
+
params.onBehalf,
|
|
56
|
+
receiver,
|
|
57
|
+
],
|
|
58
|
+
}),
|
|
59
|
+
};
|
|
60
|
+
if (params.metadata) {
|
|
61
|
+
tx = addTransactionMetadata(tx, params.metadata);
|
|
62
|
+
}
|
|
63
|
+
return deepFreeze({
|
|
64
|
+
...tx,
|
|
65
|
+
action: {
|
|
66
|
+
type: "midnightRedeem",
|
|
67
|
+
args: {
|
|
68
|
+
market: marketId,
|
|
69
|
+
units: params.units,
|
|
70
|
+
onBehalf: params.onBehalf,
|
|
71
|
+
receiver,
|
|
72
|
+
},
|
|
73
|
+
},
|
|
74
|
+
});
|
|
75
|
+
};
|