@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
|
@@ -40,11 +40,10 @@ const buildReallocationActions_js_1 = require("./buildReallocationActions.js");
|
|
|
40
40
|
* @param params.metadata - Optional analytics metadata attached to the bundle.
|
|
41
41
|
* @returns A deep-frozen `Transaction<BlueSupplyCollateralBorrowAction>` with `to`, `value`,
|
|
42
42
|
* `data`, and the typed `action` discriminator the simulation layer consumes.
|
|
43
|
-
* @throws {
|
|
44
|
-
*
|
|
45
|
-
* @throws {
|
|
46
|
-
*
|
|
47
|
-
* @throws {ZeroCollateralAmountError} when both `amount` and `nativeAmount` resolve to zero.
|
|
43
|
+
* @throws {NegativeInputError} when `amount`, `nativeAmount`, `minSharePrice`, or any reallocation
|
|
44
|
+
* fee is negative.
|
|
45
|
+
* @throws {NonPositiveInputError} when `borrowAmount <= 0n`, both collateral amounts resolve to
|
|
46
|
+
* zero, or any reallocation withdrawal amount is non-positive.
|
|
48
47
|
* @throws {ChainWNativeMissingError} when `nativeAmount > 0n` but the chain has no configured wNative.
|
|
49
48
|
* @throws {NativeAmountOnNonWNativeAssetError} when `nativeAmount > 0n` but the collateral
|
|
50
49
|
* token is not the chain's wNative.
|
|
@@ -54,12 +53,8 @@ const buildReallocationActions_js_1 = require("./buildReallocationActions.js");
|
|
|
54
53
|
* is provided and the signed amount differs from `args.amount`.
|
|
55
54
|
* @throws {Permit2ExpirationMissingError} from `getTokenRequirementActions` when a Permit2 requirement
|
|
56
55
|
* signature is missing its expiration.
|
|
57
|
-
* @throws {NegativeReallocationFeeError} from `buildReallocationActions` when
|
|
58
|
-
* `reallocations` is non-empty and any `reallocation.fee < 0n`.
|
|
59
56
|
* @throws {EmptyReallocationWithdrawalsError} from `buildReallocationActions` when any
|
|
60
57
|
* `reallocation.withdrawals` is empty.
|
|
61
|
-
* @throws {NonPositiveReallocationAmountError} from `buildReallocationActions` when any
|
|
62
|
-
* `reallocation.withdrawals[i].amount <= 0n`.
|
|
63
58
|
* @throws {ReallocationWithdrawalOnTargetMarketError} from `buildReallocationActions` when any
|
|
64
59
|
* reallocation withdrawal references the target market.
|
|
65
60
|
* @throws {UnsortedReallocationWithdrawalsError} from `buildReallocationActions` when
|
|
@@ -83,20 +78,20 @@ const buildReallocationActions_js_1 = require("./buildReallocationActions.js");
|
|
|
83
78
|
*/
|
|
84
79
|
const blueSupplyCollateralBorrow = ({ market: { chainId, marketParams }, args: { amount = 0n, borrowAmount, onBehalf, receiver, minSharePrice, requirementSignature, nativeAmount, reallocations, authorizationSignature, }, metadata, }) => {
|
|
85
80
|
if (amount < 0n) {
|
|
86
|
-
throw new index_js_3.
|
|
81
|
+
throw new index_js_3.NegativeInputError("amount", amount);
|
|
87
82
|
}
|
|
88
83
|
if (nativeAmount !== undefined && nativeAmount < 0n) {
|
|
89
|
-
throw new index_js_3.
|
|
84
|
+
throw new index_js_3.NegativeInputError("nativeAmount", nativeAmount);
|
|
90
85
|
}
|
|
91
86
|
if (borrowAmount <= 0n) {
|
|
92
|
-
throw new index_js_3.
|
|
87
|
+
throw new index_js_3.NonPositiveInputError("borrowAmount", borrowAmount);
|
|
93
88
|
}
|
|
94
89
|
if (minSharePrice < 0n) {
|
|
95
|
-
throw new index_js_3.
|
|
90
|
+
throw new index_js_3.NegativeInputError("minSharePrice", minSharePrice);
|
|
96
91
|
}
|
|
97
92
|
const totalCollateral = amount + (nativeAmount ?? 0n);
|
|
98
93
|
if (totalCollateral === 0n) {
|
|
99
|
-
throw new index_js_3.
|
|
94
|
+
throw new index_js_3.NonPositiveInputError("totalCollateral", totalCollateral);
|
|
100
95
|
}
|
|
101
96
|
const actions = [];
|
|
102
97
|
if (authorizationSignature) {
|
|
@@ -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";
|
|
@@ -40,14 +40,16 @@ const buildReallocationActions_js_1 = require("./buildReallocationActions.js");
|
|
|
40
40
|
* @param params.metadata - Optional analytics metadata attached to the bundle.
|
|
41
41
|
* @returns A deep-frozen `Transaction<BlueWithdrawAction>` with `to`, `value`, `data`, and
|
|
42
42
|
* the typed `action` discriminator the simulation layer consumes.
|
|
43
|
-
* @throws {
|
|
43
|
+
* @throws {NegativeInputError} when `assets`, `shares`, `minSharePrice`, or any reallocation fee
|
|
44
|
+
* is negative.
|
|
45
|
+
* @throws {NonPositiveInputError} when both `assets` and `shares` are zero or any reallocation
|
|
46
|
+
* withdrawal amount is non-positive.
|
|
44
47
|
* @throws {MutuallyExclusiveWithdrawAmountsError} when both `assets` and `shares` are non-zero.
|
|
45
|
-
* @throws {
|
|
46
|
-
*
|
|
47
|
-
*
|
|
48
|
-
*
|
|
49
|
-
*
|
|
50
|
-
* `UnsortedReallocationWithdrawalsError`).
|
|
48
|
+
* @throws {EmptyReallocationWithdrawalsError} when any reallocation has no withdrawals.
|
|
49
|
+
* @throws {ReallocationWithdrawalOnTargetMarketError} when a reallocation withdrawal references
|
|
50
|
+
* the target market.
|
|
51
|
+
* @throws {UnsortedReallocationWithdrawalsError} when reallocation withdrawals are not strictly
|
|
52
|
+
* sorted by market id.
|
|
51
53
|
* @example
|
|
52
54
|
* ```ts
|
|
53
55
|
* import { blueWithdraw } from "@morpho-org/morpho-sdk";
|
|
@@ -71,11 +73,17 @@ const blueWithdraw = ({ market: { chainId, marketParams }, args: { assets, share
|
|
|
71
73
|
if (assets !== 0n && shares !== 0n) {
|
|
72
74
|
throw new index_js_3.MutuallyExclusiveWithdrawAmountsError(marketParams.id);
|
|
73
75
|
}
|
|
74
|
-
if (assets < 0n
|
|
75
|
-
throw new index_js_3.
|
|
76
|
+
if (assets < 0n) {
|
|
77
|
+
throw new index_js_3.NegativeInputError("assets", assets);
|
|
78
|
+
}
|
|
79
|
+
if (shares < 0n) {
|
|
80
|
+
throw new index_js_3.NegativeInputError("shares", shares);
|
|
81
|
+
}
|
|
82
|
+
if (assets === 0n && shares === 0n) {
|
|
83
|
+
throw new index_js_3.NonPositiveInputError("assets or shares", 0n);
|
|
76
84
|
}
|
|
77
85
|
if (minSharePrice < 0n) {
|
|
78
|
-
throw new index_js_3.
|
|
86
|
+
throw new index_js_3.NegativeInputError("minSharePrice", minSharePrice);
|
|
79
87
|
}
|
|
80
88
|
const actions = [];
|
|
81
89
|
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";
|
|
@@ -23,7 +23,7 @@ const index_js_2 = require("../../types/index.js");
|
|
|
23
23
|
* @param params.metadata - Optional analytics metadata attached to the transaction.
|
|
24
24
|
* @returns A deep-frozen `Transaction<BlueWithdrawCollateralAction>` with `to`, `value`,
|
|
25
25
|
* `data`, and the typed `action` discriminator the simulation layer consumes.
|
|
26
|
-
* @throws {
|
|
26
|
+
* @throws {NonPositiveInputError} when `amount <= 0n`.
|
|
27
27
|
* @example
|
|
28
28
|
* ```ts
|
|
29
29
|
* import { blueWithdrawCollateral } from "@morpho-org/morpho-sdk";
|
|
@@ -41,7 +41,7 @@ const index_js_2 = require("../../types/index.js");
|
|
|
41
41
|
*/
|
|
42
42
|
const blueWithdrawCollateral = ({ market: { chainId, marketParams }, args: { amount, onBehalf, receiver }, metadata, }) => {
|
|
43
43
|
if (amount <= 0n) {
|
|
44
|
-
throw new index_js_2.
|
|
44
|
+
throw new index_js_2.NonPositiveInputError("amount", amount);
|
|
45
45
|
}
|
|
46
46
|
const { morpho } = (0, blue_sdk_1.getChainAddresses)(chainId);
|
|
47
47
|
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/cjs/actions/index.js
CHANGED
|
@@ -15,6 +15,7 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
|
15
15
|
};
|
|
16
16
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
17
|
__exportStar(require("./blue/index.js"), exports);
|
|
18
|
+
__exportStar(require("./midnight/index.js"), exports);
|
|
18
19
|
__exportStar(require("./requirements/index.js"), exports);
|
|
19
20
|
__exportStar(require("./signatures/index.js"), exports);
|
|
20
21
|
__exportStar(require("./vaultV1/index.js"), exports);
|
|
@@ -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,69 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.midnightSetIsAuthorized = void 0;
|
|
4
|
+
const midnight_sdk_1 = require("@morpho-org/midnight-sdk");
|
|
5
|
+
const morpho_ts_1 = require("@morpho-org/morpho-ts");
|
|
6
|
+
const viem_1 = require("viem");
|
|
7
|
+
const index_js_1 = require("../../helpers/index.js");
|
|
8
|
+
const validateMidnightAuthorizationTarget_js_1 = require("../../helpers/validateMidnightAuthorizationTarget.js");
|
|
9
|
+
/**
|
|
10
|
+
* Encodes `Midnight.setIsAuthorized` for a bundle spender or ratifier.
|
|
11
|
+
*
|
|
12
|
+
* Prefer requirement helpers or entity `getRequirements()` in app flows; they
|
|
13
|
+
* read `isAuthorized` first and return this transaction only when needed. Use
|
|
14
|
+
* this builder directly when the caller intentionally wants to set or revoke
|
|
15
|
+
* authorization without reading state.
|
|
16
|
+
*
|
|
17
|
+
* @param params.chainId - Chain id used to resolve `Midnight`.
|
|
18
|
+
* @param params.authorized - Supported operator receiving authorization, or any operator losing authorization.
|
|
19
|
+
* @param params.onBehalf - Owner whose authorization mapping is updated.
|
|
20
|
+
* @param params.isAuthorized - Optional target state; defaults to `true`.
|
|
21
|
+
* @param params.metadata - Optional analytics metadata appended to calldata.
|
|
22
|
+
* @returns A deep-frozen `Transaction<MidnightAuthorizationAction>` targeting `Midnight`.
|
|
23
|
+
* @throws {UnsupportedMidnightAuthorizationTargetError} when granting authorization to an unsupported operator.
|
|
24
|
+
* @example
|
|
25
|
+
* ```ts
|
|
26
|
+
* import { midnightSetIsAuthorized } from "@morpho-org/morpho-sdk";
|
|
27
|
+
*
|
|
28
|
+
* const tx = midnightSetIsAuthorized({
|
|
29
|
+
* chainId: 8453,
|
|
30
|
+
* authorized: midnightBundles,
|
|
31
|
+
* onBehalf: user,
|
|
32
|
+
* });
|
|
33
|
+
* ```
|
|
34
|
+
*/
|
|
35
|
+
const midnightSetIsAuthorized = (params) => {
|
|
36
|
+
const isAuthorized = params.isAuthorized ?? true;
|
|
37
|
+
if (isAuthorized) {
|
|
38
|
+
// Restrict grants to known protocol operators; revocations remain permissionless by target.
|
|
39
|
+
(0, validateMidnightAuthorizationTarget_js_1.validateMidnightAuthorizationTarget)({
|
|
40
|
+
chainId: params.chainId,
|
|
41
|
+
authorized: params.authorized,
|
|
42
|
+
});
|
|
43
|
+
}
|
|
44
|
+
const midnight = (0, morpho_ts_1.getChainAddress)(params.chainId, "midnight");
|
|
45
|
+
let tx = {
|
|
46
|
+
to: midnight,
|
|
47
|
+
value: 0n,
|
|
48
|
+
data: (0, viem_1.encodeFunctionData)({
|
|
49
|
+
abi: midnight_sdk_1.midnightAbi,
|
|
50
|
+
functionName: "setIsAuthorized",
|
|
51
|
+
args: [params.authorized, isAuthorized, params.onBehalf],
|
|
52
|
+
}),
|
|
53
|
+
};
|
|
54
|
+
if (params.metadata) {
|
|
55
|
+
tx = (0, index_js_1.addTransactionMetadata)(tx, params.metadata);
|
|
56
|
+
}
|
|
57
|
+
return (0, morpho_ts_1.deepFreeze)({
|
|
58
|
+
...tx,
|
|
59
|
+
action: {
|
|
60
|
+
type: "midnightAuthorization",
|
|
61
|
+
args: {
|
|
62
|
+
authorized: params.authorized,
|
|
63
|
+
isAuthorized,
|
|
64
|
+
onBehalf: params.onBehalf,
|
|
65
|
+
},
|
|
66
|
+
},
|
|
67
|
+
});
|
|
68
|
+
};
|
|
69
|
+
exports.midnightSetIsAuthorized = midnightSetIsAuthorized;
|
|
@@ -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,73 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.midnightCancelOffer = void 0;
|
|
4
|
+
const midnight_sdk_1 = require("@morpho-org/midnight-sdk");
|
|
5
|
+
const morpho_ts_1 = require("@morpho-org/morpho-ts");
|
|
6
|
+
const viem_1 = require("viem");
|
|
7
|
+
const index_js_1 = require("../../helpers/index.js");
|
|
8
|
+
const index_js_2 = require("../../types/index.js");
|
|
9
|
+
/**
|
|
10
|
+
* Encodes `Midnight.setConsumed` to cancel or partially consume an offer group.
|
|
11
|
+
*
|
|
12
|
+
* App flows should usually call `client.morpho.midnight(chainId).cancelOffer(...)`.
|
|
13
|
+
* Use this builder directly when the group id is already known and no
|
|
14
|
+
* additional requirements are needed. Omitting `amount` fully cancels the group
|
|
15
|
+
* by setting consumption to {@link MAX_OFFER_CAP}.
|
|
16
|
+
*
|
|
17
|
+
* @param params.chainId - Chain id used to resolve `Midnight`.
|
|
18
|
+
* @param params.group - Offer group id to mark consumed.
|
|
19
|
+
* @param params.onBehalf - Maker whose group consumption is updated.
|
|
20
|
+
* @param params.amount - Optional consumed amount; defaults to {@link MAX_OFFER_CAP} for full cancellation.
|
|
21
|
+
* @param params.metadata - Optional analytics metadata appended to calldata.
|
|
22
|
+
* @returns A deep-frozen `Transaction<MidnightCancelOfferAction>` targeting `Midnight`.
|
|
23
|
+
* @throws {NegativeInputError} when `amount` is negative.
|
|
24
|
+
* @throws {MidnightAmountExceedsMaxOfferCapError} when `amount` exceeds {@link MAX_OFFER_CAP}.
|
|
25
|
+
* @example
|
|
26
|
+
* ```ts
|
|
27
|
+
* import { midnightCancelOffer } from "@morpho-org/morpho-sdk";
|
|
28
|
+
*
|
|
29
|
+
* const tx = midnightCancelOffer({
|
|
30
|
+
* chainId: 8453,
|
|
31
|
+
* group,
|
|
32
|
+
* onBehalf: maker,
|
|
33
|
+
* });
|
|
34
|
+
* ```
|
|
35
|
+
*/
|
|
36
|
+
const midnightCancelOffer = (params) => {
|
|
37
|
+
const midnight = (0, morpho_ts_1.getChainAddress)(params.chainId, "midnight");
|
|
38
|
+
const amount = params.amount ?? midnight_sdk_1.MAX_OFFER_CAP;
|
|
39
|
+
if (amount < 0n) {
|
|
40
|
+
throw new index_js_2.NegativeInputError("amount", amount);
|
|
41
|
+
}
|
|
42
|
+
if (amount > midnight_sdk_1.MAX_OFFER_CAP) {
|
|
43
|
+
throw new index_js_2.MidnightAmountExceedsMaxOfferCapError({
|
|
44
|
+
label: "cancel amount",
|
|
45
|
+
amount,
|
|
46
|
+
maxOfferCap: midnight_sdk_1.MAX_OFFER_CAP,
|
|
47
|
+
});
|
|
48
|
+
}
|
|
49
|
+
let tx = {
|
|
50
|
+
to: midnight,
|
|
51
|
+
value: 0n,
|
|
52
|
+
data: (0, viem_1.encodeFunctionData)({
|
|
53
|
+
abi: midnight_sdk_1.midnightAbi,
|
|
54
|
+
functionName: "setConsumed",
|
|
55
|
+
args: [params.group, amount, params.onBehalf],
|
|
56
|
+
}),
|
|
57
|
+
};
|
|
58
|
+
if (params.metadata) {
|
|
59
|
+
tx = (0, index_js_1.addTransactionMetadata)(tx, params.metadata);
|
|
60
|
+
}
|
|
61
|
+
return (0, morpho_ts_1.deepFreeze)({
|
|
62
|
+
...tx,
|
|
63
|
+
action: {
|
|
64
|
+
type: "midnightCancelOffer",
|
|
65
|
+
args: {
|
|
66
|
+
group: params.group,
|
|
67
|
+
amount,
|
|
68
|
+
onBehalf: params.onBehalf,
|
|
69
|
+
},
|
|
70
|
+
},
|
|
71
|
+
});
|
|
72
|
+
};
|
|
73
|
+
exports.midnightCancelOffer = midnightCancelOffer;
|
|
@@ -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,27 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
__exportStar(require("./authorization.js"), exports);
|
|
18
|
+
__exportStar(require("./cancelOffer.js"), exports);
|
|
19
|
+
__exportStar(require("./mempoolSubmitOffers.js"), exports);
|
|
20
|
+
__exportStar(require("./redeem.js"), exports);
|
|
21
|
+
__exportStar(require("./repayWithdrawCollateral.js"), exports);
|
|
22
|
+
__exportStar(require("./setterRatifierRatifyRoot.js"), exports);
|
|
23
|
+
__exportStar(require("./supplyCollateral.js"), exports);
|
|
24
|
+
__exportStar(require("./supplyCollateralTakeBorrow.js"), exports);
|
|
25
|
+
__exportStar(require("./takeBorrow.js"), exports);
|
|
26
|
+
__exportStar(require("./takeLend.js"), exports);
|
|
27
|
+
__exportStar(require("./types.js"), exports);
|
|
@@ -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,72 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.mempoolSubmitOffers = void 0;
|
|
4
|
+
const midnight_sdk_1 = require("@morpho-org/midnight-sdk");
|
|
5
|
+
const morpho_ts_1 = require("@morpho-org/morpho-ts");
|
|
6
|
+
const index_js_1 = require("../../helpers/index.js");
|
|
7
|
+
/**
|
|
8
|
+
* Encodes a Midnight mempool payload submission transaction.
|
|
9
|
+
*
|
|
10
|
+
* App make-offer flows should call `getOffersData`, gather the returned
|
|
11
|
+
* requirements, then call the output `buildTx(signatures)`. Use this builder
|
|
12
|
+
* directly only when the payload has already been encoded with ratifier data
|
|
13
|
+
* and the caller wants to submit those bytes to the mempool contract.
|
|
14
|
+
*
|
|
15
|
+
* @param params.chainId - Chain id used to resolve `MidnightMempool`.
|
|
16
|
+
* @param params.groups - Group ids included in the payload.
|
|
17
|
+
* @param params.root - Offer tree root committed by the maker.
|
|
18
|
+
* @param params.maker - Maker whose offers are submitted.
|
|
19
|
+
* @param params.ratifier - Ratifier address shared by the offer tree.
|
|
20
|
+
* @param params.ratifierType - Ratifier route used to build the payload.
|
|
21
|
+
* @param params.offers - Number of non-padding offers in the payload.
|
|
22
|
+
* @param params.payload - Encoded mempool payload bytes.
|
|
23
|
+
* @param params.metadata - Optional analytics metadata appended to calldata.
|
|
24
|
+
* @returns A deep-frozen `Transaction<MempoolSubmitOffersAction>` targeting `MidnightMempool`.
|
|
25
|
+
* @throws {InvalidTreeError} when `offers <= 0`.
|
|
26
|
+
* @example
|
|
27
|
+
* ```ts
|
|
28
|
+
* import { Payload } from "@morpho-org/midnight-sdk";
|
|
29
|
+
* import { mempoolSubmitOffers } from "@morpho-org/morpho-sdk";
|
|
30
|
+
*
|
|
31
|
+
* const payload = await Payload.encode(items);
|
|
32
|
+
* const tx = mempoolSubmitOffers({
|
|
33
|
+
* chainId: 8453,
|
|
34
|
+
* groups,
|
|
35
|
+
* root: tree.root,
|
|
36
|
+
* maker,
|
|
37
|
+
* ratifier,
|
|
38
|
+
* ratifierType: "ecrecover",
|
|
39
|
+
* offers: tree.offers.length,
|
|
40
|
+
* payload,
|
|
41
|
+
* });
|
|
42
|
+
* ```
|
|
43
|
+
*/
|
|
44
|
+
const mempoolSubmitOffers = (params) => {
|
|
45
|
+
if (params.offers <= 0) {
|
|
46
|
+
throw new midnight_sdk_1.InvalidTreeError("Tree must contain at least one offer.");
|
|
47
|
+
}
|
|
48
|
+
const midnightMempool = (0, morpho_ts_1.getChainAddress)(params.chainId, "midnightMempool");
|
|
49
|
+
let tx = {
|
|
50
|
+
to: midnightMempool,
|
|
51
|
+
value: 0n,
|
|
52
|
+
data: params.payload,
|
|
53
|
+
};
|
|
54
|
+
if (params.metadata) {
|
|
55
|
+
tx = (0, index_js_1.addTransactionMetadata)(tx, params.metadata);
|
|
56
|
+
}
|
|
57
|
+
return (0, morpho_ts_1.deepFreeze)({
|
|
58
|
+
...tx,
|
|
59
|
+
action: {
|
|
60
|
+
type: "mempoolSubmitOffers",
|
|
61
|
+
args: {
|
|
62
|
+
groups: [...params.groups],
|
|
63
|
+
root: params.root,
|
|
64
|
+
maker: params.maker,
|
|
65
|
+
ratifier: params.ratifier,
|
|
66
|
+
ratifierType: params.ratifierType,
|
|
67
|
+
offers: params.offers,
|
|
68
|
+
},
|
|
69
|
+
},
|
|
70
|
+
});
|
|
71
|
+
};
|
|
72
|
+
exports.mempoolSubmitOffers = mempoolSubmitOffers;
|
|
@@ -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>>;
|