@morpho-org/morpho-sdk 6.6.0 → 7.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/MIGRATION-v6-to-v7.md +291 -0
- package/README.md +26 -12
- package/lib/cjs/abis.d.ts +1 -1
- package/lib/cjs/abis.js +3 -2
- package/lib/cjs/actions/bundles/common.d.ts +9 -5
- package/lib/cjs/actions/bundles/common.js +22 -13
- package/lib/cjs/actions/midnight/authorization.d.ts +3 -2
- package/lib/cjs/actions/midnight/authorization.js +3 -2
- package/lib/cjs/actions/midnight/cancelAndMake.d.ts +153 -0
- package/lib/cjs/actions/midnight/cancelAndMake.js +292 -0
- package/lib/cjs/actions/midnight/index.d.ts +3 -3
- package/lib/cjs/actions/midnight/index.js +3 -3
- package/lib/cjs/actions/midnight/repayWithdrawCollateral.d.ts +40 -23
- package/lib/cjs/actions/midnight/repayWithdrawCollateral.js +105 -69
- package/lib/cjs/actions/midnight/supplyCollateralTakeBorrow.d.ts +52 -27
- package/lib/cjs/actions/midnight/supplyCollateralTakeBorrow.js +128 -71
- package/lib/cjs/actions/midnight/takeBorrow.d.ts +40 -28
- package/lib/cjs/actions/midnight/takeBorrow.js +95 -54
- package/lib/cjs/actions/midnight/takeLend.d.ts +51 -27
- package/lib/cjs/actions/midnight/takeLend.js +111 -54
- package/lib/cjs/actions/midnight/takeRepayWithdrawCollateral.d.ts +97 -0
- package/lib/cjs/actions/midnight/takeRepayWithdrawCollateral.js +201 -0
- package/lib/cjs/actions/midnight/takeWithdraw.d.ts +69 -0
- package/lib/cjs/actions/midnight/takeWithdraw.js +153 -0
- package/lib/cjs/actions/midnight/types.d.ts +7 -26
- package/lib/cjs/actions/midnight/types.js +0 -13
- package/lib/cjs/actions/requirements/encode/encodeErc20Approval.d.ts +2 -1
- package/lib/cjs/actions/requirements/encode/encodeErc20Approval.js +3 -2
- package/lib/cjs/actions/requirements/encode/encodeErc20Permit.d.ts +4 -4
- package/lib/cjs/actions/requirements/encode/encodeErc20Permit.js +5 -5
- package/lib/cjs/actions/requirements/getRequirementsApproval.d.ts +2 -2
- package/lib/cjs/actions/requirements/getRequirementsApproval.js +2 -2
- package/lib/cjs/actions/requirements/midnight/getMidnightApprovalRequirements.d.ts +24 -8
- package/lib/cjs/actions/requirements/midnight/getMidnightApprovalRequirements.js +24 -13
- package/lib/cjs/actions/requirements/midnight/getMidnightAuthorizationRequirement.d.ts +11 -7
- package/lib/cjs/actions/requirements/midnight/getMidnightAuthorizationRequirement.js +11 -7
- package/lib/cjs/actions/requirements/midnight/index.d.ts +0 -1
- package/lib/cjs/actions/requirements/midnight/index.js +0 -1
- package/lib/cjs/constants.d.ts +1 -1
- package/lib/cjs/constants.js +2 -1
- package/lib/cjs/entities/index.d.ts +2 -2
- package/lib/cjs/entities/midnight/midnight.d.ts +582 -108
- package/lib/cjs/entities/midnight/midnight.js +981 -509
- package/lib/cjs/entities/midnight/types.d.ts +142 -60
- package/lib/cjs/entities/vaultV1/vaultV1.d.ts +2 -1
- package/lib/cjs/entities/vaultV1/vaultV1.js +1 -0
- package/lib/cjs/entities/vaultV2/vaultV2.d.ts +2 -1
- package/lib/cjs/entities/vaultV2/vaultV2.js +1 -0
- package/lib/cjs/helpers/callback.d.ts +54 -0
- package/lib/cjs/helpers/callback.js +73 -0
- package/lib/cjs/helpers/constant.d.ts +2 -0
- package/lib/cjs/helpers/constant.js +3 -1
- package/lib/cjs/helpers/index.d.ts +3 -2
- package/lib/cjs/helpers/index.js +6 -1
- package/lib/cjs/helpers/signAndVerifyTypedData.d.ts +3 -3
- package/lib/cjs/helpers/signAndVerifyTypedData.js +3 -3
- package/lib/cjs/helpers/validate.d.ts +43 -2
- package/lib/cjs/helpers/validate.js +60 -3
- package/lib/cjs/helpers/validateMidnightAuthorizationTarget.d.ts +1 -1
- package/lib/cjs/helpers/validateMidnightAuthorizationTarget.js +3 -7
- package/lib/cjs/helpers/validateRequirementSpender.d.ts +3 -3
- package/lib/cjs/helpers/validateRequirementSpender.js +4 -5
- package/lib/cjs/midnight/abis.d.ts +1 -1
- package/lib/cjs/midnight/abis.js +3 -2
- package/lib/cjs/midnight/types.d.ts +1 -1
- package/lib/cjs/types/action.d.ts +117 -89
- package/lib/cjs/types/action.js +1 -19
- package/lib/cjs/types/error.d.ts +126 -40
- package/lib/cjs/types/error.js +154 -49
- package/lib/esm/abis.d.ts +1 -1
- package/lib/esm/abis.js +1 -1
- package/lib/esm/actions/bundles/common.d.ts +9 -5
- package/lib/esm/actions/bundles/common.js +22 -13
- package/lib/esm/actions/midnight/authorization.d.ts +3 -2
- package/lib/esm/actions/midnight/authorization.js +3 -2
- package/lib/esm/actions/midnight/cancelAndMake.d.ts +153 -0
- package/lib/esm/actions/midnight/cancelAndMake.js +288 -0
- package/lib/esm/actions/midnight/index.d.ts +3 -3
- package/lib/esm/actions/midnight/index.js +3 -3
- package/lib/esm/actions/midnight/repayWithdrawCollateral.d.ts +40 -23
- package/lib/esm/actions/midnight/repayWithdrawCollateral.js +108 -72
- package/lib/esm/actions/midnight/supplyCollateralTakeBorrow.d.ts +52 -27
- package/lib/esm/actions/midnight/supplyCollateralTakeBorrow.js +131 -74
- package/lib/esm/actions/midnight/takeBorrow.d.ts +40 -28
- package/lib/esm/actions/midnight/takeBorrow.js +98 -57
- package/lib/esm/actions/midnight/takeLend.d.ts +51 -27
- package/lib/esm/actions/midnight/takeLend.js +114 -57
- package/lib/esm/actions/midnight/takeRepayWithdrawCollateral.d.ts +97 -0
- package/lib/esm/actions/midnight/takeRepayWithdrawCollateral.js +197 -0
- package/lib/esm/actions/midnight/takeWithdraw.d.ts +69 -0
- package/lib/esm/actions/midnight/takeWithdraw.js +149 -0
- package/lib/esm/actions/midnight/types.d.ts +7 -26
- package/lib/esm/actions/midnight/types.js +1 -12
- package/lib/esm/actions/requirements/encode/encodeErc20Approval.d.ts +2 -1
- package/lib/esm/actions/requirements/encode/encodeErc20Approval.js +3 -2
- package/lib/esm/actions/requirements/encode/encodeErc20Permit.d.ts +4 -4
- package/lib/esm/actions/requirements/encode/encodeErc20Permit.js +5 -5
- package/lib/esm/actions/requirements/getRequirementsApproval.d.ts +2 -2
- package/lib/esm/actions/requirements/getRequirementsApproval.js +2 -2
- package/lib/esm/actions/requirements/midnight/getMidnightApprovalRequirements.d.ts +24 -8
- package/lib/esm/actions/requirements/midnight/getMidnightApprovalRequirements.js +25 -14
- package/lib/esm/actions/requirements/midnight/getMidnightAuthorizationRequirement.d.ts +11 -7
- package/lib/esm/actions/requirements/midnight/getMidnightAuthorizationRequirement.js +11 -7
- package/lib/esm/actions/requirements/midnight/index.d.ts +0 -1
- package/lib/esm/actions/requirements/midnight/index.js +0 -1
- package/lib/esm/constants.d.ts +1 -1
- package/lib/esm/constants.js +1 -1
- package/lib/esm/entities/index.d.ts +2 -2
- package/lib/esm/entities/midnight/midnight.d.ts +582 -108
- package/lib/esm/entities/midnight/midnight.js +987 -515
- package/lib/esm/entities/midnight/types.d.ts +142 -60
- package/lib/esm/entities/vaultV1/vaultV1.d.ts +2 -1
- package/lib/esm/entities/vaultV1/vaultV1.js +1 -0
- package/lib/esm/entities/vaultV2/vaultV2.d.ts +2 -1
- package/lib/esm/entities/vaultV2/vaultV2.js +1 -0
- package/lib/esm/helpers/callback.d.ts +54 -0
- package/lib/esm/helpers/callback.js +68 -0
- package/lib/esm/helpers/constant.d.ts +2 -0
- package/lib/esm/helpers/constant.js +2 -0
- package/lib/esm/helpers/index.d.ts +3 -2
- package/lib/esm/helpers/index.js +3 -2
- package/lib/esm/helpers/signAndVerifyTypedData.d.ts +3 -3
- package/lib/esm/helpers/signAndVerifyTypedData.js +3 -3
- package/lib/esm/helpers/validate.d.ts +43 -2
- package/lib/esm/helpers/validate.js +58 -2
- package/lib/esm/helpers/validateMidnightAuthorizationTarget.d.ts +1 -1
- package/lib/esm/helpers/validateMidnightAuthorizationTarget.js +3 -7
- package/lib/esm/helpers/validateRequirementSpender.d.ts +3 -3
- package/lib/esm/helpers/validateRequirementSpender.js +4 -5
- package/lib/esm/midnight/abis.d.ts +1 -1
- package/lib/esm/midnight/abis.js +1 -1
- package/lib/esm/midnight/types.d.ts +1 -1
- package/lib/esm/types/action.d.ts +117 -89
- package/lib/esm/types/action.js +1 -18
- package/lib/esm/types/error.d.ts +126 -40
- package/lib/esm/types/error.js +135 -38
- package/package.json +8 -7
- package/lib/cjs/actions/midnight/cancelOffer.d.ts +0 -38
- package/lib/cjs/actions/midnight/cancelOffer.js +0 -73
- package/lib/cjs/actions/midnight/mempoolSubmitOffers.d.ts +0 -52
- package/lib/cjs/actions/midnight/mempoolSubmitOffers.js +0 -72
- package/lib/cjs/actions/midnight/setterRatifierRatifyRoot.d.ts +0 -40
- package/lib/cjs/actions/midnight/setterRatifierRatifyRoot.js +0 -59
- package/lib/cjs/actions/requirements/midnight/getSetterRatifierRatifyRootRequirement.d.ts +0 -42
- package/lib/cjs/actions/requirements/midnight/getSetterRatifierRatifyRootRequirement.js +0 -70
- package/lib/esm/actions/midnight/cancelOffer.d.ts +0 -38
- package/lib/esm/actions/midnight/cancelOffer.js +0 -69
- package/lib/esm/actions/midnight/mempoolSubmitOffers.d.ts +0 -52
- package/lib/esm/actions/midnight/mempoolSubmitOffers.js +0 -68
- package/lib/esm/actions/midnight/setterRatifierRatifyRoot.d.ts +0 -40
- package/lib/esm/actions/midnight/setterRatifierRatifyRoot.js +0 -55
- package/lib/esm/actions/requirements/midnight/getSetterRatifierRatifyRootRequirement.d.ts +0 -42
- package/lib/esm/actions/requirements/midnight/getSetterRatifierRatifyRootRequirement.js +0 -66
package/lib/esm/types/error.d.ts
CHANGED
|
@@ -500,7 +500,8 @@ export declare class BundlesPermitMismatchError extends Error {
|
|
|
500
500
|
/**
|
|
501
501
|
* @param params - Permit mismatch values used to explain the rejection.
|
|
502
502
|
* @param params.field - Permit field that does not match the exit.
|
|
503
|
-
* @param params.expected - Value required by the exit.
|
|
503
|
+
* @param params.expected - Value required by the exit. For `field: "amount"` on an
|
|
504
|
+
* operation that accepts a range of permit amounts, an inclusive `"[min, max]"` range.
|
|
504
505
|
* @param params.actual - Value supplied by the signature.
|
|
505
506
|
* @param params.cause - Original parser failure when signature decoding is wrapped.
|
|
506
507
|
*/
|
|
@@ -632,7 +633,7 @@ export declare class MaxRepayAssetsBelowRepayAssetsError extends Error {
|
|
|
632
633
|
constructor(maxRepayAssets: bigint, repayAssets: bigint);
|
|
633
634
|
}
|
|
634
635
|
/** Requirement signature kind accepted by action-output transaction builders. */
|
|
635
|
-
export type RequirementSignatureKind = "permit" | "permit2SignatureTransfer" | "authorization"
|
|
636
|
+
export type RequirementSignatureKind = "permit" | "permit2SignatureTransfer" | "authorization";
|
|
636
637
|
/**
|
|
637
638
|
* Thrown when `buildTx` receives more than one requirement signature of the same kind.
|
|
638
639
|
*
|
|
@@ -709,11 +710,10 @@ export declare class UnsupportedErc20ApprovalSpenderError extends Error {
|
|
|
709
710
|
readonly chainId: number;
|
|
710
711
|
readonly permit2?: Address;
|
|
711
712
|
readonly midnight?: Address;
|
|
712
|
-
readonly midnightBundles?: Address;
|
|
713
713
|
readonly supportedSpenders?: readonly (Address | undefined)[];
|
|
714
714
|
});
|
|
715
715
|
}
|
|
716
|
-
/** Thrown when a Midnight authorization requirement
|
|
716
|
+
/** Thrown when a Midnight authorization target (a requirement operator, or the ratifier that `midnightCancelAndMake` activates and MidnightBundlesV2 authorizes) is not registered for the chain. */
|
|
717
717
|
export declare class UnsupportedMidnightAuthorizationTargetError extends Error {
|
|
718
718
|
constructor(params: {
|
|
719
719
|
readonly authorized: Address;
|
|
@@ -1027,12 +1027,19 @@ export declare class ReallocationAdapterSupplySharesUnderflowError extends Error
|
|
|
1027
1027
|
readonly withdrawnShares: bigint;
|
|
1028
1028
|
});
|
|
1029
1029
|
}
|
|
1030
|
-
/** Thrown when a Midnight
|
|
1031
|
-
export declare class
|
|
1030
|
+
/** Thrown when a Midnight batch cancellation has no offer groups. */
|
|
1031
|
+
export declare class EmptyMidnightGroupCancellationsError extends Error {
|
|
1032
|
+
constructor();
|
|
1033
|
+
}
|
|
1034
|
+
/** Thrown when a Midnight flow passes a collateral market with no collateral supplies. */
|
|
1035
|
+
export declare class EmptyMidnightCollateralSuppliesError extends Error {
|
|
1036
|
+
constructor();
|
|
1037
|
+
}
|
|
1038
|
+
/** Thrown when a Midnight batch cancellation lists the same offer group twice. */
|
|
1039
|
+
export declare class DuplicateMidnightGroupCancellationError extends Error {
|
|
1032
1040
|
constructor(params: {
|
|
1033
|
-
readonly
|
|
1034
|
-
readonly
|
|
1035
|
-
readonly maxOfferCap: bigint;
|
|
1041
|
+
readonly index: number;
|
|
1042
|
+
readonly group: Hex;
|
|
1036
1043
|
});
|
|
1037
1044
|
}
|
|
1038
1045
|
/** Thrown when a Midnight flow needs at least one takeable offer. */
|
|
@@ -1047,6 +1054,12 @@ export declare class MidnightOfferSideMismatchError extends Error {
|
|
|
1047
1054
|
actualBuy: boolean;
|
|
1048
1055
|
});
|
|
1049
1056
|
}
|
|
1057
|
+
/** Thrown when a Midnight maker method that is not a limit exit receives a reduce-only offer. */
|
|
1058
|
+
export declare class MidnightOfferReduceOnlyError extends Error {
|
|
1059
|
+
constructor(params: {
|
|
1060
|
+
readonly index: number;
|
|
1061
|
+
});
|
|
1062
|
+
}
|
|
1050
1063
|
/** Thrown when a Midnight maker offer belongs to a different account than the action flow. */
|
|
1051
1064
|
export declare class MidnightOfferMakerMismatchError extends Error {
|
|
1052
1065
|
constructor(params: {
|
|
@@ -1055,6 +1068,74 @@ export declare class MidnightOfferMakerMismatchError extends Error {
|
|
|
1055
1068
|
readonly actualMaker: Address;
|
|
1056
1069
|
});
|
|
1057
1070
|
}
|
|
1071
|
+
/** Thrown when a Midnight maker offer sets a nonzero continuous fee cap. */
|
|
1072
|
+
export declare class MidnightOfferContinuousFeeCapError extends Error {
|
|
1073
|
+
/** Offer index in the maker tree. */
|
|
1074
|
+
readonly index: number;
|
|
1075
|
+
/** Continuous fee cap supplied on the offer. */
|
|
1076
|
+
readonly continuousFeeCap: bigint;
|
|
1077
|
+
/**
|
|
1078
|
+
* @param params - Offer index and rejected fee cap.
|
|
1079
|
+
* @param params.index - Offer index in the maker tree.
|
|
1080
|
+
* @param params.continuousFeeCap - Continuous fee cap supplied on the offer.
|
|
1081
|
+
*/
|
|
1082
|
+
constructor(params: {
|
|
1083
|
+
readonly index: number;
|
|
1084
|
+
readonly continuousFeeCap: bigint;
|
|
1085
|
+
});
|
|
1086
|
+
}
|
|
1087
|
+
/** Thrown when a Midnight sell offer routes its seller proceeds to another address. */
|
|
1088
|
+
export declare class MidnightOfferSellerReceiverMismatchError extends Error {
|
|
1089
|
+
/** Offer index in the maker tree. */
|
|
1090
|
+
readonly index: number;
|
|
1091
|
+
/** Offer maker, which must receive seller proceeds. */
|
|
1092
|
+
readonly expectedReceiver: Address;
|
|
1093
|
+
/** Seller receiver supplied on the offer. */
|
|
1094
|
+
readonly actualReceiver: Address;
|
|
1095
|
+
/**
|
|
1096
|
+
* @param params - Offer index and expected and actual seller receivers.
|
|
1097
|
+
* @param params.index - Offer index in the maker tree.
|
|
1098
|
+
* @param params.expectedReceiver - Offer maker, which must receive seller proceeds.
|
|
1099
|
+
* @param params.actualReceiver - Seller receiver supplied on the offer.
|
|
1100
|
+
*/
|
|
1101
|
+
constructor(params: {
|
|
1102
|
+
readonly index: number;
|
|
1103
|
+
readonly expectedReceiver: Address;
|
|
1104
|
+
readonly actualReceiver: Address;
|
|
1105
|
+
});
|
|
1106
|
+
}
|
|
1107
|
+
/** Thrown when a Midnight taker flow uses an unbounded target or deadline. */
|
|
1108
|
+
export declare class UnboundedMidnightTakeInputError extends Error {
|
|
1109
|
+
readonly field: "target.units" | "target.maxBuyerAssets" | "target.maxUnits" | "deadline";
|
|
1110
|
+
/**
|
|
1111
|
+
* @param field - Target or deadline input set to `maxUint256`.
|
|
1112
|
+
*/
|
|
1113
|
+
constructor(field: "target.units" | "target.maxBuyerAssets" | "target.maxUnits" | "deadline");
|
|
1114
|
+
}
|
|
1115
|
+
/** Thrown when a Midnight taker flow uses a zero address as its receiver. */
|
|
1116
|
+
export declare class MidnightZeroReceiverError extends Error {
|
|
1117
|
+
readonly field: "receiver";
|
|
1118
|
+
/**
|
|
1119
|
+
* @param field - Receiver field containing the zero address.
|
|
1120
|
+
*/
|
|
1121
|
+
constructor(field: "receiver");
|
|
1122
|
+
}
|
|
1123
|
+
/** Thrown when a Midnight take deadline is more than one hour from the current time. */
|
|
1124
|
+
export declare class MidnightTakeDeadlineTooFarError extends Error {
|
|
1125
|
+
/** Deadline supplied by the caller. */
|
|
1126
|
+
readonly deadline: bigint;
|
|
1127
|
+
/** Accepted maximum deadline. */
|
|
1128
|
+
readonly maxDeadline: bigint;
|
|
1129
|
+
/**
|
|
1130
|
+
* @param params - Supplied deadline and accepted maximum.
|
|
1131
|
+
* @param params.deadline - Deadline supplied by the caller.
|
|
1132
|
+
* @param params.maxDeadline - Latest accepted deadline.
|
|
1133
|
+
*/
|
|
1134
|
+
constructor(params: {
|
|
1135
|
+
readonly deadline: bigint;
|
|
1136
|
+
readonly maxDeadline: bigint;
|
|
1137
|
+
});
|
|
1138
|
+
}
|
|
1058
1139
|
/** Thrown when a Midnight maker offer targets a different chain than the action flow. */
|
|
1059
1140
|
export declare class MidnightOfferMarketChainMismatchError extends Error {
|
|
1060
1141
|
constructor(params: {
|
|
@@ -1086,58 +1167,57 @@ export declare class MidnightOfferMarketLoanTokenMismatchError extends Error {
|
|
|
1086
1167
|
readonly actualLoanToken: Address;
|
|
1087
1168
|
});
|
|
1088
1169
|
}
|
|
1089
|
-
/** Thrown when a
|
|
1090
|
-
export declare class
|
|
1170
|
+
/** Thrown when a Blue-funded Midnight lend offer does not use the maker's derived `BlueBuyCallback`. */
|
|
1171
|
+
export declare class MidnightOfferCallbackMismatchError extends Error {
|
|
1091
1172
|
constructor(params: {
|
|
1092
|
-
index: number;
|
|
1093
|
-
|
|
1094
|
-
|
|
1173
|
+
readonly index: number;
|
|
1174
|
+
readonly expectedCallback: Address;
|
|
1175
|
+
readonly actualCallback: Address;
|
|
1095
1176
|
});
|
|
1096
1177
|
}
|
|
1097
|
-
/** Thrown when a Midnight offer
|
|
1098
|
-
export declare class
|
|
1178
|
+
/** Thrown when a Blue-funded Midnight lend offer's callback data is not the ABI-encoded Blue market. */
|
|
1179
|
+
export declare class MidnightOfferCallbackDataMismatchError extends Error {
|
|
1099
1180
|
constructor(params: {
|
|
1100
|
-
|
|
1101
|
-
|
|
1102
|
-
|
|
1181
|
+
readonly index: number;
|
|
1182
|
+
readonly expectedCallbackData: Hex;
|
|
1183
|
+
readonly actualCallbackData: Hex;
|
|
1103
1184
|
});
|
|
1104
1185
|
}
|
|
1105
|
-
/** Thrown when
|
|
1106
|
-
export declare class
|
|
1107
|
-
constructor(
|
|
1186
|
+
/** Thrown when loan assets would be parked in a Morpho Blue market with no existing supply. */
|
|
1187
|
+
export declare class EmptyBlueParkingMarketError extends Error {
|
|
1188
|
+
constructor(params: {
|
|
1189
|
+
readonly marketId: MarketId;
|
|
1190
|
+
});
|
|
1108
1191
|
}
|
|
1109
|
-
/** Thrown when
|
|
1110
|
-
export declare class
|
|
1192
|
+
/** Thrown when parked assets would mint no Morpho Blue supply shares. */
|
|
1193
|
+
export declare class ZeroBlueParkingSharesError extends Error {
|
|
1111
1194
|
constructor(params: {
|
|
1112
|
-
|
|
1113
|
-
|
|
1195
|
+
readonly marketId: MarketId;
|
|
1196
|
+
readonly assets: bigint;
|
|
1114
1197
|
});
|
|
1115
1198
|
}
|
|
1116
|
-
/** Thrown when a Midnight offer
|
|
1117
|
-
export declare class
|
|
1199
|
+
/** Thrown when a quoted Midnight takeable offer belongs to a different market than the requested flow. */
|
|
1200
|
+
export declare class MidnightTakeableOfferMarketMismatchError extends Error {
|
|
1118
1201
|
constructor(params: {
|
|
1119
|
-
|
|
1120
|
-
|
|
1202
|
+
index: number;
|
|
1203
|
+
expectedMarket: string;
|
|
1204
|
+
actualMarket: string;
|
|
1121
1205
|
});
|
|
1122
1206
|
}
|
|
1123
|
-
/** Thrown when a Midnight offer
|
|
1124
|
-
export declare class
|
|
1207
|
+
/** Thrown when a Midnight offer's ratifier does not match its tree's ratifier route. */
|
|
1208
|
+
export declare class MidnightOfferRatifierMismatchError extends Error {
|
|
1125
1209
|
constructor(params: {
|
|
1210
|
+
index: number;
|
|
1126
1211
|
expectedRatifier: Address;
|
|
1127
1212
|
actualRatifier: Address;
|
|
1128
1213
|
});
|
|
1129
1214
|
}
|
|
1130
|
-
/** Thrown when a Midnight
|
|
1131
|
-
export declare class
|
|
1215
|
+
/** Thrown when a Midnight repost cancels a group it also publishes. */
|
|
1216
|
+
export declare class MidnightReplacementGroupCancelledError extends Error {
|
|
1132
1217
|
constructor(params: {
|
|
1133
|
-
|
|
1134
|
-
actualOffers: number;
|
|
1218
|
+
readonly group: Hex;
|
|
1135
1219
|
});
|
|
1136
1220
|
}
|
|
1137
|
-
/** Thrown when a Midnight offer-root signature carries no encoded payload. */
|
|
1138
|
-
export declare class UnpreparedMidnightOfferRootSignatureError extends Error {
|
|
1139
|
-
constructor();
|
|
1140
|
-
}
|
|
1141
1221
|
/** Thrown when a Midnight redeem flow finds no credit units for the user. */
|
|
1142
1222
|
export declare class NoMidnightCreditToRedeemError extends Error {
|
|
1143
1223
|
constructor(market: string);
|
|
@@ -1209,3 +1289,9 @@ export declare class RefinanceSameMarketError extends Error {
|
|
|
1209
1289
|
export declare class RefinanceTokenMismatchError extends Error {
|
|
1210
1290
|
constructor(sourceMarket: string, targetMarket: string);
|
|
1211
1291
|
}
|
|
1292
|
+
/** Thrown when a maker limit-exit offer can increase or open a position. */
|
|
1293
|
+
export declare class MidnightOfferNotReduceOnlyError extends Error {
|
|
1294
|
+
constructor(params: {
|
|
1295
|
+
readonly index: number;
|
|
1296
|
+
});
|
|
1297
|
+
}
|
package/lib/esm/types/error.js
CHANGED
|
@@ -559,7 +559,8 @@ export class BundlesPermitMismatchError extends Error {
|
|
|
559
559
|
/**
|
|
560
560
|
* @param params - Permit mismatch values used to explain the rejection.
|
|
561
561
|
* @param params.field - Permit field that does not match the exit.
|
|
562
|
-
* @param params.expected - Value required by the exit.
|
|
562
|
+
* @param params.expected - Value required by the exit. For `field: "amount"` on an
|
|
563
|
+
* operation that accepts a range of permit amounts, an inclusive `"[min, max]"` range.
|
|
563
564
|
* @param params.actual - Value supplied by the signature.
|
|
564
565
|
* @param params.cause - Original parser failure when signature decoding is wrapped.
|
|
565
566
|
*/
|
|
@@ -836,17 +837,13 @@ export class ApprovalAmountLessThanSpendAmountError extends Error {
|
|
|
836
837
|
/** Thrown when a requirement encoder targets an unsupported spender. */
|
|
837
838
|
export class UnsupportedErc20ApprovalSpenderError extends Error {
|
|
838
839
|
constructor(params) {
|
|
839
|
-
const supported = (params.supportedSpenders ?? [
|
|
840
|
-
params.permit2,
|
|
841
|
-
params.midnight,
|
|
842
|
-
params.midnightBundles,
|
|
843
|
-
])
|
|
840
|
+
const supported = (params.supportedSpenders ?? [params.permit2, params.midnight])
|
|
844
841
|
.filter((address) => address != null)
|
|
845
842
|
.join('", "');
|
|
846
843
|
super(`Requirement spender "${params.spender}" is not supported on chain "${params.chainId}". Use "${supported}".`);
|
|
847
844
|
}
|
|
848
845
|
}
|
|
849
|
-
/** Thrown when a Midnight authorization requirement
|
|
846
|
+
/** Thrown when a Midnight authorization target (a requirement operator, or the ratifier that `midnightCancelAndMake` activates and MidnightBundlesV2 authorizes) is not registered for the chain. */
|
|
850
847
|
export class UnsupportedMidnightAuthorizationTargetError extends Error {
|
|
851
848
|
constructor(params) {
|
|
852
849
|
super(`Midnight authorization target "${params.authorized}" is not supported on chain "${params.chainId}". Use "${params.supportedTargets.join('", "')}".`);
|
|
@@ -1209,10 +1206,22 @@ export class ReallocationAdapterSupplySharesUnderflowError extends Error {
|
|
|
1209
1206
|
this.params = params;
|
|
1210
1207
|
}
|
|
1211
1208
|
}
|
|
1212
|
-
/** Thrown when a Midnight
|
|
1213
|
-
export class
|
|
1209
|
+
/** Thrown when a Midnight batch cancellation has no offer groups. */
|
|
1210
|
+
export class EmptyMidnightGroupCancellationsError extends Error {
|
|
1211
|
+
constructor() {
|
|
1212
|
+
super("Midnight group cancellations cannot be empty. Pass at least one offer group to cancel.");
|
|
1213
|
+
}
|
|
1214
|
+
}
|
|
1215
|
+
/** Thrown when a Midnight flow passes a collateral market with no collateral supplies. */
|
|
1216
|
+
export class EmptyMidnightCollateralSuppliesError extends Error {
|
|
1217
|
+
constructor() {
|
|
1218
|
+
super("Midnight collateral supplies cannot be empty. Pass at least one collateral supply, or use `makeBorrow` to publish without collateral.");
|
|
1219
|
+
}
|
|
1220
|
+
}
|
|
1221
|
+
/** Thrown when a Midnight batch cancellation lists the same offer group twice. */
|
|
1222
|
+
export class DuplicateMidnightGroupCancellationError extends Error {
|
|
1214
1223
|
constructor(params) {
|
|
1215
|
-
super(`Midnight
|
|
1224
|
+
super(`Midnight group cancellation "${params.index}" repeats group "${params.group}". Pass each offer group once.`);
|
|
1216
1225
|
}
|
|
1217
1226
|
}
|
|
1218
1227
|
/** Thrown when a Midnight flow needs at least one takeable offer. */
|
|
@@ -1227,12 +1236,100 @@ export class MidnightOfferSideMismatchError extends Error {
|
|
|
1227
1236
|
super(`Midnight offer "${params.index}" has buy="${params.actualBuy}", expected "${params.expectedBuy}". Use the matching flow or rebuild the offer list.`);
|
|
1228
1237
|
}
|
|
1229
1238
|
}
|
|
1239
|
+
/** Thrown when a Midnight maker method that is not a limit exit receives a reduce-only offer. */
|
|
1240
|
+
export class MidnightOfferReduceOnlyError extends Error {
|
|
1241
|
+
constructor(params) {
|
|
1242
|
+
super(`Midnight offer "${params.index}" is reduce-only. Rebuild the offer with reduceOnly=false; reduce-only exits need a dedicated exit flow.`);
|
|
1243
|
+
}
|
|
1244
|
+
}
|
|
1230
1245
|
/** Thrown when a Midnight maker offer belongs to a different account than the action flow. */
|
|
1231
1246
|
export class MidnightOfferMakerMismatchError extends Error {
|
|
1232
1247
|
constructor(params) {
|
|
1233
1248
|
super(`Midnight offer "${params.index}" belongs to maker "${params.actualMaker}", expected "${params.expectedMaker}". Rebuild the offer set for the active account.`);
|
|
1234
1249
|
}
|
|
1235
1250
|
}
|
|
1251
|
+
/** Thrown when a Midnight maker offer sets a nonzero continuous fee cap. */
|
|
1252
|
+
export class MidnightOfferContinuousFeeCapError extends Error {
|
|
1253
|
+
/** Offer index in the maker tree. */
|
|
1254
|
+
index;
|
|
1255
|
+
/** Continuous fee cap supplied on the offer. */
|
|
1256
|
+
continuousFeeCap;
|
|
1257
|
+
/**
|
|
1258
|
+
* @param params - Offer index and rejected fee cap.
|
|
1259
|
+
* @param params.index - Offer index in the maker tree.
|
|
1260
|
+
* @param params.continuousFeeCap - Continuous fee cap supplied on the offer.
|
|
1261
|
+
*/
|
|
1262
|
+
constructor(params) {
|
|
1263
|
+
super(`Midnight offer "${params.index}" has continuous fee cap "${params.continuousFeeCap}". Maker offers must use 0n; rebuild the offer with its fee cap set to zero.`);
|
|
1264
|
+
this.index = params.index;
|
|
1265
|
+
this.continuousFeeCap = params.continuousFeeCap;
|
|
1266
|
+
this.name = "MidnightOfferContinuousFeeCapError";
|
|
1267
|
+
}
|
|
1268
|
+
}
|
|
1269
|
+
/** Thrown when a Midnight sell offer routes its seller proceeds to another address. */
|
|
1270
|
+
export class MidnightOfferSellerReceiverMismatchError extends Error {
|
|
1271
|
+
/** Offer index in the maker tree. */
|
|
1272
|
+
index;
|
|
1273
|
+
/** Offer maker, which must receive seller proceeds. */
|
|
1274
|
+
expectedReceiver;
|
|
1275
|
+
/** Seller receiver supplied on the offer. */
|
|
1276
|
+
actualReceiver;
|
|
1277
|
+
/**
|
|
1278
|
+
* @param params - Offer index and expected and actual seller receivers.
|
|
1279
|
+
* @param params.index - Offer index in the maker tree.
|
|
1280
|
+
* @param params.expectedReceiver - Offer maker, which must receive seller proceeds.
|
|
1281
|
+
* @param params.actualReceiver - Seller receiver supplied on the offer.
|
|
1282
|
+
*/
|
|
1283
|
+
constructor(params) {
|
|
1284
|
+
super(`Midnight sell offer "${params.index}" routes seller proceeds to "${params.actualReceiver}", expected its maker "${params.expectedReceiver}". Set receiverIfMakerIsSeller to the maker address.`);
|
|
1285
|
+
this.index = params.index;
|
|
1286
|
+
this.expectedReceiver = params.expectedReceiver;
|
|
1287
|
+
this.actualReceiver = params.actualReceiver;
|
|
1288
|
+
this.name = "MidnightOfferSellerReceiverMismatchError";
|
|
1289
|
+
}
|
|
1290
|
+
}
|
|
1291
|
+
/** Thrown when a Midnight taker flow uses an unbounded target or deadline. */
|
|
1292
|
+
export class UnboundedMidnightTakeInputError extends Error {
|
|
1293
|
+
field;
|
|
1294
|
+
/**
|
|
1295
|
+
* @param field - Target or deadline input set to `maxUint256`.
|
|
1296
|
+
*/
|
|
1297
|
+
constructor(field) {
|
|
1298
|
+
super(`Midnight "${field}" cannot be maxUint256. Provide an explicit bounded value.`);
|
|
1299
|
+
this.field = field;
|
|
1300
|
+
this.name = "UnboundedMidnightTakeInputError";
|
|
1301
|
+
}
|
|
1302
|
+
}
|
|
1303
|
+
/** Thrown when a Midnight taker flow uses a zero address as its receiver. */
|
|
1304
|
+
export class MidnightZeroReceiverError extends Error {
|
|
1305
|
+
field;
|
|
1306
|
+
/**
|
|
1307
|
+
* @param field - Receiver field containing the zero address.
|
|
1308
|
+
*/
|
|
1309
|
+
constructor(field) {
|
|
1310
|
+
super(`Midnight "${field}" cannot be the zero address. Provide a valid recipient.`);
|
|
1311
|
+
this.field = field;
|
|
1312
|
+
this.name = "MidnightZeroReceiverError";
|
|
1313
|
+
}
|
|
1314
|
+
}
|
|
1315
|
+
/** Thrown when a Midnight take deadline is more than one hour from the current time. */
|
|
1316
|
+
export class MidnightTakeDeadlineTooFarError extends Error {
|
|
1317
|
+
/** Deadline supplied by the caller. */
|
|
1318
|
+
deadline;
|
|
1319
|
+
/** Accepted maximum deadline. */
|
|
1320
|
+
maxDeadline;
|
|
1321
|
+
/**
|
|
1322
|
+
* @param params - Supplied deadline and accepted maximum.
|
|
1323
|
+
* @param params.deadline - Deadline supplied by the caller.
|
|
1324
|
+
* @param params.maxDeadline - Latest accepted deadline.
|
|
1325
|
+
*/
|
|
1326
|
+
constructor(params) {
|
|
1327
|
+
super(`Midnight take deadline "${params.deadline}" is later than the one-hour limit "${params.maxDeadline}". Choose a deadline within the next hour.`);
|
|
1328
|
+
this.deadline = params.deadline;
|
|
1329
|
+
this.maxDeadline = params.maxDeadline;
|
|
1330
|
+
this.name = "MidnightTakeDeadlineTooFarError";
|
|
1331
|
+
}
|
|
1332
|
+
}
|
|
1236
1333
|
/** Thrown when a Midnight maker offer targets a different chain than the action flow. */
|
|
1237
1334
|
export class MidnightOfferMarketChainMismatchError extends Error {
|
|
1238
1335
|
constructor(params) {
|
|
@@ -1257,52 +1354,46 @@ export class MidnightOfferMarketLoanTokenMismatchError extends Error {
|
|
|
1257
1354
|
super(`Midnight offer "${params.index}" uses loan token "${params.actualLoanToken}", expected "${params.expectedLoanToken}". Rebuild the lend offer set for the approved loan token.`);
|
|
1258
1355
|
}
|
|
1259
1356
|
}
|
|
1260
|
-
/** Thrown when a
|
|
1261
|
-
export class
|
|
1357
|
+
/** Thrown when a Blue-funded Midnight lend offer does not use the maker's derived `BlueBuyCallback`. */
|
|
1358
|
+
export class MidnightOfferCallbackMismatchError extends Error {
|
|
1262
1359
|
constructor(params) {
|
|
1263
|
-
super(`Midnight
|
|
1360
|
+
super(`Midnight offer "${params.index}" uses callback "${params.actualCallback}", expected the maker's BlueBuyCallback "${params.expectedCallback}". Rebuild the offer with the derived callback.`);
|
|
1264
1361
|
}
|
|
1265
1362
|
}
|
|
1266
|
-
/** Thrown when a Midnight offer
|
|
1267
|
-
export class
|
|
1363
|
+
/** Thrown when a Blue-funded Midnight lend offer's callback data is not the ABI-encoded Blue market. */
|
|
1364
|
+
export class MidnightOfferCallbackDataMismatchError extends Error {
|
|
1268
1365
|
constructor(params) {
|
|
1269
|
-
super(`Midnight offer
|
|
1270
|
-
}
|
|
1271
|
-
}
|
|
1272
|
-
/** Thrown when a Midnight Ecrecover maker flow builds the submit transaction before signing. */
|
|
1273
|
-
export class MissingMidnightOfferRootSignatureError extends Error {
|
|
1274
|
-
constructor() {
|
|
1275
|
-
super("Midnight offer root signature is missing. Sign the offer-root requirement before building the submit transaction.");
|
|
1366
|
+
super(`Midnight offer "${params.index}" uses callback data "${params.actualCallbackData}", expected "${params.expectedCallbackData}". Set the callback data to the ABI-encoded Blue market the assets are parked in.`);
|
|
1276
1367
|
}
|
|
1277
1368
|
}
|
|
1278
|
-
/** Thrown when
|
|
1279
|
-
export class
|
|
1369
|
+
/** Thrown when loan assets would be parked in a Morpho Blue market with no existing supply. */
|
|
1370
|
+
export class EmptyBlueParkingMarketError extends Error {
|
|
1280
1371
|
constructor(params) {
|
|
1281
|
-
super(`
|
|
1372
|
+
super(`Morpho Blue market "${params.marketId}" has no supply shares. Parking assets in an empty market is exposed to supply-share-price inflation; choose a market with existing supply.`);
|
|
1282
1373
|
}
|
|
1283
1374
|
}
|
|
1284
|
-
/** Thrown when
|
|
1285
|
-
export class
|
|
1375
|
+
/** Thrown when parked assets would mint no Morpho Blue supply shares. */
|
|
1376
|
+
export class ZeroBlueParkingSharesError extends Error {
|
|
1286
1377
|
constructor(params) {
|
|
1287
|
-
super(`
|
|
1378
|
+
super(`Supplying "${params.assets}" assets to Morpho Blue market "${params.marketId}" mints zero supply shares at its current share price; park more assets or choose another market.`);
|
|
1288
1379
|
}
|
|
1289
1380
|
}
|
|
1290
|
-
/** Thrown when a Midnight offer
|
|
1291
|
-
export class
|
|
1381
|
+
/** Thrown when a quoted Midnight takeable offer belongs to a different market than the requested flow. */
|
|
1382
|
+
export class MidnightTakeableOfferMarketMismatchError extends Error {
|
|
1292
1383
|
constructor(params) {
|
|
1293
|
-
super(`Midnight offer
|
|
1384
|
+
super(`Midnight takeable offer "${params.index}" belongs to market "${params.actualMarket}", expected "${params.expectedMarket}". Refresh the quote and try again.`);
|
|
1294
1385
|
}
|
|
1295
1386
|
}
|
|
1296
|
-
/** Thrown when a Midnight offer
|
|
1297
|
-
export class
|
|
1387
|
+
/** Thrown when a Midnight offer's ratifier does not match its tree's ratifier route. */
|
|
1388
|
+
export class MidnightOfferRatifierMismatchError extends Error {
|
|
1298
1389
|
constructor(params) {
|
|
1299
|
-
super(`Midnight offer
|
|
1390
|
+
super(`Midnight offer "${params.index}" uses ratifier "${params.actualRatifier}", expected "${params.expectedRatifier}" for its tree type. Rebuild the offer with the tree's ratifier.`);
|
|
1300
1391
|
}
|
|
1301
1392
|
}
|
|
1302
|
-
/** Thrown when a Midnight
|
|
1303
|
-
export class
|
|
1304
|
-
constructor() {
|
|
1305
|
-
super(
|
|
1393
|
+
/** Thrown when a Midnight repost cancels a group it also publishes. */
|
|
1394
|
+
export class MidnightReplacementGroupCancelledError extends Error {
|
|
1395
|
+
constructor(params) {
|
|
1396
|
+
super(`Midnight offer group "${params.group}" is both published and cancelled. Give replacement offers a fresh group.`);
|
|
1306
1397
|
}
|
|
1307
1398
|
}
|
|
1308
1399
|
/** Thrown when a Midnight redeem flow finds no credit units for the user. */
|
|
@@ -1373,3 +1464,9 @@ export class RefinanceTokenMismatchError extends Error {
|
|
|
1373
1464
|
super(`Refinance source market ${sourceMarket} and target market ${targetMarket} must share the same loanToken and collateralToken.`);
|
|
1374
1465
|
}
|
|
1375
1466
|
}
|
|
1467
|
+
/** Thrown when a maker limit-exit offer can increase or open a position. */
|
|
1468
|
+
export class MidnightOfferNotReduceOnlyError extends Error {
|
|
1469
|
+
constructor(params) {
|
|
1470
|
+
super(`Midnight exit offer "${params.index}" must have reduceOnly=true. Rebuild the offer tree for the exit intent.`);
|
|
1471
|
+
}
|
|
1472
|
+
}
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@morpho-org/morpho-sdk",
|
|
3
3
|
"description": "Abstraction layer for Morpho's complexity.",
|
|
4
|
-
"version": "
|
|
4
|
+
"version": "7.0.0",
|
|
5
5
|
"author": "Morpho Association <contact@morpho.org>",
|
|
6
6
|
"repository": {
|
|
7
7
|
"type": "git",
|
|
@@ -147,13 +147,14 @@
|
|
|
147
147
|
],
|
|
148
148
|
"files": [
|
|
149
149
|
"lib",
|
|
150
|
-
"MIGRATION-v5-to-v6.md"
|
|
150
|
+
"MIGRATION-v5-to-v6.md",
|
|
151
|
+
"MIGRATION-v6-to-v7.md"
|
|
151
152
|
],
|
|
152
153
|
"dependencies": {
|
|
153
|
-
"@morpho-org/blue-sdk": "^
|
|
154
|
-
"@morpho-org/blue-sdk-viem": "^6.2.
|
|
155
|
-
"@morpho-org/midnight-sdk": "^
|
|
156
|
-
"@morpho-org/morpho-ts": "^
|
|
154
|
+
"@morpho-org/blue-sdk": "^8.0.0",
|
|
155
|
+
"@morpho-org/blue-sdk-viem": "^6.2.1",
|
|
156
|
+
"@morpho-org/midnight-sdk": "^2.0.0",
|
|
157
|
+
"@morpho-org/morpho-ts": "^4.0.0"
|
|
157
158
|
},
|
|
158
159
|
"peerDependencies": {
|
|
159
160
|
"viem": "^2.0.0"
|
|
@@ -165,7 +166,7 @@
|
|
|
165
166
|
"typescript": "7.0.2",
|
|
166
167
|
"viem": "^2.55.10",
|
|
167
168
|
"vitest": "^4.1.11",
|
|
168
|
-
"zod": "^4.
|
|
169
|
+
"zod": "^4.6.5"
|
|
169
170
|
},
|
|
170
171
|
"scripts": {
|
|
171
172
|
"prepublish": "pnpm build",
|
|
@@ -1,38 +0,0 @@
|
|
|
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>>;
|
|
@@ -1,73 +0,0 @@
|
|
|
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;
|