@morpho-org/morpho-sdk 9.7.0 → 10.0.0-next.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/MIGRATION-v9-to-v10.md +114 -0
- package/README.md +5 -1
- package/lib/cjs/abis.d.ts +1 -1
- package/lib/cjs/abis.js +5 -1
- package/lib/cjs/actions/bundles/resolveBundlesTokenRequirements.d.ts +3 -4
- package/lib/cjs/actions/bundles/resolveBundlesTokenRequirements.js +1 -1
- package/lib/cjs/actions/midnight/cancelAndMake.d.ts +2 -1
- package/lib/cjs/actions/midnight/cancelAndMake.js +2 -1
- package/lib/cjs/actions/midnight/cancelOffers.d.ts +54 -0
- package/lib/cjs/actions/midnight/cancelOffers.js +107 -0
- package/lib/cjs/actions/midnight/index.d.ts +1 -0
- package/lib/cjs/actions/midnight/index.js +1 -0
- package/lib/cjs/actions/midnight/supplyCollateralTakeBorrow.d.ts +1 -1
- package/lib/cjs/actions/midnight/supplyCollateralTakeBorrow.js +1 -1
- package/lib/cjs/actions/midnight/takeBorrow.d.ts +1 -1
- package/lib/cjs/actions/midnight/takeBorrow.js +1 -1
- package/lib/cjs/actions/midnight/takeLend.d.ts +1 -1
- package/lib/cjs/actions/midnight/takeLend.js +1 -1
- package/lib/cjs/actions/midnight/takeRepayWithdrawCollateral.d.ts +1 -1
- package/lib/cjs/actions/midnight/takeRepayWithdrawCollateral.js +1 -1
- package/lib/cjs/actions/midnight/takeWithdraw.d.ts +1 -1
- package/lib/cjs/actions/midnight/takeWithdraw.js +1 -1
- package/lib/cjs/actions/requirements/blue/getBlueAuthorizationRequirement.d.ts +3 -4
- package/lib/cjs/actions/requirements/blue/getBlueAuthorizationRequirement.js +1 -1
- package/lib/cjs/actions/requirements/encode/encodeBlueSignatureAuthorization.d.ts +4 -6
- package/lib/cjs/actions/requirements/encode/encodeBlueSignatureAuthorization.js +3 -3
- package/lib/cjs/actions/requirements/encode/encodeErc20Permit.d.ts +4 -6
- package/lib/cjs/actions/requirements/encode/encodeErc20Permit.js +3 -3
- package/lib/cjs/actions/requirements/encode/encodeErc20Permit2SignatureTransfer.d.ts +5 -6
- package/lib/cjs/actions/requirements/encode/encodeErc20Permit2SignatureTransfer.js +3 -2
- package/lib/cjs/actions/requirements/encode/encodeVaultSharesPermit.d.ts +3 -5
- package/lib/cjs/actions/requirements/encode/encodeVaultSharesPermit.js +26 -23
- package/lib/cjs/blue/abis.d.ts +1 -1
- package/lib/cjs/blue/abis.js +5 -1
- package/lib/cjs/blue/entities.d.ts +4 -4
- package/lib/cjs/blue/entities.js +3 -1
- package/lib/cjs/blue/errors.d.ts +2 -2
- package/lib/cjs/blue/errors.js +5 -1
- package/lib/cjs/blue/fetch.d.ts +2 -2
- package/lib/cjs/blue/fetch.js +3 -1
- package/lib/cjs/blue/utils.d.ts +1 -1
- package/lib/cjs/blue/utils.js +2 -1
- package/lib/cjs/entities/blue/blue.d.ts +34 -28
- package/lib/cjs/entities/blue/blue.js +99 -73
- package/lib/cjs/entities/index.d.ts +4 -4
- package/lib/cjs/entities/index.js +3 -1
- package/lib/cjs/entities/midnight/deadline.d.ts +2 -2
- package/lib/cjs/entities/midnight/deadline.js +2 -2
- package/lib/cjs/entities/midnight/midnight.d.ts +49 -51
- package/lib/cjs/entities/midnight/midnight.js +144 -131
- package/lib/cjs/entities/midnight/publication.d.ts +2 -0
- package/lib/cjs/entities/midnight/publication.js +126 -100
- package/lib/cjs/entities/midnight/types.d.ts +4 -4
- package/lib/cjs/entities/requirements/getBundlesTokenRequirements.d.ts +3 -5
- package/lib/cjs/entities/requirements/getBundlesTokenRequirements.js +17 -17
- package/lib/cjs/entities/requirements/getVaultBundlesSharesRequirements.d.ts +3 -4
- package/lib/cjs/entities/requirements/getVaultBundlesSharesRequirements.js +1 -1
- package/lib/cjs/entities/vaultV1/vaultV1.d.ts +12 -12
- package/lib/cjs/entities/vaultV1/vaultV1.js +83 -57
- package/lib/cjs/entities/vaultV2/vaultV2.d.ts +50 -24
- package/lib/cjs/entities/vaultV2/vaultV2.js +166 -90
- package/lib/cjs/entities/vaultV2BlueReallocationData.d.ts +17 -2
- package/lib/cjs/entities/vaultV2BlueReallocationData.js +1410 -806
- package/lib/cjs/errors.d.ts +4 -4
- package/lib/cjs/errors.js +7 -5
- package/lib/cjs/fetch.d.ts +2 -2
- package/lib/cjs/fetch.js +3 -1
- package/lib/cjs/helpers/deadShares.js +55 -34
- package/lib/cjs/helpers/metadata.d.ts +14 -2
- package/lib/cjs/helpers/metadata.js +39 -4
- package/lib/cjs/helpers/previewVaultV2ForceWithdraw.js +34 -22
- package/lib/cjs/helpers/previewVaultV2InKindRedeem.js +7 -1
- package/lib/cjs/helpers/validate.js +76 -61
- package/lib/cjs/helpers/validateMidnightTakeFeasibility.js +154 -103
- package/lib/cjs/helpers/vaultV2ForceWithdrawPlan.js +31 -20
- package/lib/cjs/index.d.ts +1 -0
- package/lib/cjs/index.js +3 -1
- package/lib/cjs/midnight/errors.d.ts +2 -1
- package/lib/cjs/midnight/errors.js +5 -4
- package/lib/cjs/transactionPlan/plan.js +6 -3
- package/lib/cjs/transactionPlan/serde.js +7 -7
- package/lib/cjs/transactionPlan/vaultv2/deposit.d.ts +6 -4
- package/lib/cjs/transactionPlan/vaultv2/deposit.js +5 -3
- package/lib/cjs/transactionPlan/vaultv2/withdraw.d.ts +6 -4
- package/lib/cjs/transactionPlan/vaultv2/withdraw.js +5 -3
- package/lib/cjs/types/action.d.ts +26 -2
- package/lib/cjs/types/action.js +1 -1
- package/lib/cjs/types/error.js +11 -5
- package/lib/cjs/types/metadata.d.ts +12 -2
- package/lib/cjs/utils.d.ts +2 -2
- package/lib/cjs/utils.js +4 -2
- package/lib/cjs/version.d.ts +2 -0
- package/lib/cjs/version.js +6 -0
- package/lib/esm/abis.d.ts +1 -1
- package/lib/esm/abis.js +1 -1
- package/lib/esm/actions/bundles/resolveBundlesTokenRequirements.d.ts +3 -4
- package/lib/esm/actions/bundles/resolveBundlesTokenRequirements.js +1 -1
- package/lib/esm/actions/midnight/cancelAndMake.d.ts +2 -1
- package/lib/esm/actions/midnight/cancelAndMake.js +2 -1
- package/lib/esm/actions/midnight/cancelOffers.d.ts +54 -0
- package/lib/esm/actions/midnight/cancelOffers.js +103 -0
- package/lib/esm/actions/midnight/index.d.ts +1 -0
- package/lib/esm/actions/midnight/index.js +1 -0
- package/lib/esm/actions/midnight/supplyCollateralTakeBorrow.d.ts +1 -1
- package/lib/esm/actions/midnight/supplyCollateralTakeBorrow.js +1 -1
- package/lib/esm/actions/midnight/takeBorrow.d.ts +1 -1
- package/lib/esm/actions/midnight/takeBorrow.js +1 -1
- package/lib/esm/actions/midnight/takeLend.d.ts +1 -1
- package/lib/esm/actions/midnight/takeLend.js +1 -1
- package/lib/esm/actions/midnight/takeRepayWithdrawCollateral.d.ts +1 -1
- package/lib/esm/actions/midnight/takeRepayWithdrawCollateral.js +1 -1
- package/lib/esm/actions/midnight/takeWithdraw.d.ts +1 -1
- package/lib/esm/actions/midnight/takeWithdraw.js +1 -1
- package/lib/esm/actions/requirements/blue/getBlueAuthorizationRequirement.d.ts +3 -4
- package/lib/esm/actions/requirements/blue/getBlueAuthorizationRequirement.js +1 -1
- package/lib/esm/actions/requirements/encode/encodeBlueSignatureAuthorization.d.ts +4 -6
- package/lib/esm/actions/requirements/encode/encodeBlueSignatureAuthorization.js +3 -3
- package/lib/esm/actions/requirements/encode/encodeErc20Permit.d.ts +4 -6
- package/lib/esm/actions/requirements/encode/encodeErc20Permit.js +3 -3
- package/lib/esm/actions/requirements/encode/encodeErc20Permit2SignatureTransfer.d.ts +5 -6
- package/lib/esm/actions/requirements/encode/encodeErc20Permit2SignatureTransfer.js +3 -2
- package/lib/esm/actions/requirements/encode/encodeVaultSharesPermit.d.ts +3 -5
- package/lib/esm/actions/requirements/encode/encodeVaultSharesPermit.js +26 -23
- package/lib/esm/blue/abis.d.ts +1 -1
- package/lib/esm/blue/abis.js +1 -1
- package/lib/esm/blue/entities.d.ts +4 -4
- package/lib/esm/blue/entities.js +2 -2
- package/lib/esm/blue/errors.d.ts +2 -2
- package/lib/esm/blue/errors.js +2 -2
- package/lib/esm/blue/fetch.d.ts +2 -2
- package/lib/esm/blue/fetch.js +2 -2
- package/lib/esm/blue/utils.d.ts +1 -1
- package/lib/esm/blue/utils.js +1 -1
- package/lib/esm/entities/blue/blue.d.ts +34 -28
- package/lib/esm/entities/blue/blue.js +99 -73
- package/lib/esm/entities/index.d.ts +4 -4
- package/lib/esm/entities/index.js +2 -2
- package/lib/esm/entities/midnight/deadline.d.ts +2 -2
- package/lib/esm/entities/midnight/deadline.js +2 -2
- package/lib/esm/entities/midnight/midnight.d.ts +49 -51
- package/lib/esm/entities/midnight/midnight.js +145 -132
- package/lib/esm/entities/midnight/publication.d.ts +2 -0
- package/lib/esm/entities/midnight/publication.js +126 -100
- package/lib/esm/entities/midnight/types.d.ts +4 -4
- package/lib/esm/entities/requirements/getBundlesTokenRequirements.d.ts +3 -5
- package/lib/esm/entities/requirements/getBundlesTokenRequirements.js +17 -17
- package/lib/esm/entities/requirements/getVaultBundlesSharesRequirements.d.ts +3 -4
- package/lib/esm/entities/requirements/getVaultBundlesSharesRequirements.js +1 -1
- package/lib/esm/entities/vaultV1/vaultV1.d.ts +12 -12
- package/lib/esm/entities/vaultV1/vaultV1.js +83 -57
- package/lib/esm/entities/vaultV2/vaultV2.d.ts +50 -24
- package/lib/esm/entities/vaultV2/vaultV2.js +166 -90
- package/lib/esm/entities/vaultV2BlueReallocationData.d.ts +17 -2
- package/lib/esm/entities/vaultV2BlueReallocationData.js +1410 -806
- package/lib/esm/errors.d.ts +4 -4
- package/lib/esm/errors.js +4 -4
- package/lib/esm/fetch.d.ts +2 -2
- package/lib/esm/fetch.js +2 -2
- package/lib/esm/helpers/deadShares.js +56 -35
- package/lib/esm/helpers/metadata.d.ts +14 -2
- package/lib/esm/helpers/metadata.js +38 -4
- package/lib/esm/helpers/previewVaultV2ForceWithdraw.js +34 -22
- package/lib/esm/helpers/previewVaultV2InKindRedeem.js +7 -1
- package/lib/esm/helpers/validate.js +76 -61
- package/lib/esm/helpers/validateMidnightTakeFeasibility.js +153 -102
- package/lib/esm/helpers/vaultV2ForceWithdrawPlan.js +31 -20
- package/lib/esm/index.d.ts +1 -0
- package/lib/esm/index.js +1 -0
- package/lib/esm/midnight/errors.d.ts +2 -1
- package/lib/esm/midnight/errors.js +2 -1
- package/lib/esm/transactionPlan/plan.js +6 -3
- package/lib/esm/transactionPlan/serde.js +7 -7
- package/lib/esm/transactionPlan/vaultv2/deposit.d.ts +6 -4
- package/lib/esm/transactionPlan/vaultv2/deposit.js +5 -3
- package/lib/esm/transactionPlan/vaultv2/withdraw.d.ts +6 -4
- package/lib/esm/transactionPlan/vaultv2/withdraw.js +5 -3
- package/lib/esm/types/action.d.ts +26 -2
- package/lib/esm/types/action.js +1 -1
- package/lib/esm/types/error.js +11 -5
- package/lib/esm/types/metadata.d.ts +12 -2
- package/lib/esm/utils.d.ts +2 -2
- package/lib/esm/utils.js +2 -2
- package/lib/esm/version.d.ts +2 -0
- package/lib/esm/version.js +3 -0
- package/package.json +8 -7
|
@@ -534,12 +534,23 @@ export interface MidnightCancelAndMakeAction extends BaseAction<"midnightCancelA
|
|
|
534
534
|
readonly deadline: bigint;
|
|
535
535
|
}> {
|
|
536
536
|
}
|
|
537
|
+
/**
|
|
538
|
+
* Metadata for a direct Midnight cancellation of offer groups. One group is a bare
|
|
539
|
+
* `setConsumed` call; two or more are one Midnight `multicall` of `setConsumed` calls.
|
|
540
|
+
*/
|
|
541
|
+
export interface MidnightCancelOffersAction extends BaseAction<"midnightCancelOffers", {
|
|
542
|
+
/** Offer groups cancelled in full, in encoded order. */
|
|
543
|
+
readonly groups: readonly Hex[];
|
|
544
|
+
/** Maker whose groups are cancelled. */
|
|
545
|
+
readonly onBehalf: Address;
|
|
546
|
+
}> {
|
|
547
|
+
}
|
|
537
548
|
/**
|
|
538
549
|
* Enumerates every action a {@link Transaction} can describe across the VaultV1,
|
|
539
550
|
* VaultV2, Blue, and Midnight flows. The `type` tag discriminates the union so
|
|
540
551
|
* consumers can `switch` exhaustively on it.
|
|
541
552
|
*/
|
|
542
|
-
export type TransactionAction = ERC20ApprovalAction | VaultV2DepositAction | VaultV2WithdrawAction | VaultV2RedeemAction | VaultV2InKindRedeemAction | VaultV2ForceWithdrawAction | VaultV2ForceRedeemAction | VaultV1DepositAction | VaultV1WithdrawAction | VaultV1RedeemAction | VaultV1InKindRedeemAction | VaultV1MigrateToV2Action | BlueSupplyAction | BlueSupplyCollateralAction | BlueBorrowAction | BlueSupplyCollateralBorrowAction | BlueRepayAction | BlueWithdrawCollateralAction | BlueRepayWithdrawCollateralAction | BlueWithdrawAction | BlueWithdrawBuyCallbackAction | BlueRefinanceAction | BlueAuthorizationAction | MidnightAuthorizationAction | MidnightTakeLendAction | MidnightTakeBorrowAction | MidnightTakeWithdrawAction | MidnightSupplyCollateralTakeBorrowAction | MidnightSupplyCollateralAction | MidnightSupplyCollateralBatchAction | MidnightWithdrawCollateralAction | MidnightWithdrawCollateralBatchAction | MidnightRedeemAction | MidnightTakeRepayWithdrawCollateralAction | MidnightRepayWithdrawCollateralAction | MidnightCancelAndMakeAction;
|
|
553
|
+
export type TransactionAction = ERC20ApprovalAction | VaultV2DepositAction | VaultV2WithdrawAction | VaultV2RedeemAction | VaultV2InKindRedeemAction | VaultV2ForceWithdrawAction | VaultV2ForceRedeemAction | VaultV1DepositAction | VaultV1WithdrawAction | VaultV1RedeemAction | VaultV1InKindRedeemAction | VaultV1MigrateToV2Action | BlueSupplyAction | BlueSupplyCollateralAction | BlueBorrowAction | BlueSupplyCollateralBorrowAction | BlueRepayAction | BlueWithdrawCollateralAction | BlueRepayWithdrawCollateralAction | BlueWithdrawAction | BlueWithdrawBuyCallbackAction | BlueRefinanceAction | BlueAuthorizationAction | MidnightAuthorizationAction | MidnightTakeLendAction | MidnightTakeBorrowAction | MidnightTakeWithdrawAction | MidnightSupplyCollateralTakeBorrowAction | MidnightSupplyCollateralAction | MidnightSupplyCollateralBatchAction | MidnightWithdrawCollateralAction | MidnightWithdrawCollateralBatchAction | MidnightRedeemAction | MidnightTakeRepayWithdrawCollateralAction | MidnightRepayWithdrawCollateralAction | MidnightCancelAndMakeAction | MidnightCancelOffersAction;
|
|
543
554
|
/**
|
|
544
555
|
* Describes a single, immutable, deep-frozen transaction to submit on-chain:
|
|
545
556
|
* the target `to`, native `value`, encoded call `data`, and the originating
|
|
@@ -731,6 +742,18 @@ export type CallRequirementAction = ERC20ApprovalAction | BlueAuthorizationActio
|
|
|
731
742
|
export type CallRequirement = Readonly<Transaction<CallRequirementAction>>;
|
|
732
743
|
/** Onchain call or signature prerequisite returned by an entity action output. */
|
|
733
744
|
export type ActionRequirement = CallRequirement | SignatureRequirement;
|
|
745
|
+
/** Optional reference time for preparing a transaction flow. */
|
|
746
|
+
export interface ReferenceTimestampParams {
|
|
747
|
+
/**
|
|
748
|
+
* Reference timestamp in seconds, normally the latest block's `timestamp`
|
|
749
|
+
* (e.g. `(await client.getBlock()).timestamp`). Omitting it falls back to the
|
|
750
|
+
* device clock; this fallback is deprecated and `now` becomes required in the
|
|
751
|
+
* next major. Entity `getRequirements()` calls reuse a supplied `now` rather
|
|
752
|
+
* than re-reading time. If collecting requirements later, create a new handle
|
|
753
|
+
* using a newer block's timestamp.
|
|
754
|
+
*/
|
|
755
|
+
readonly now?: bigint;
|
|
756
|
+
}
|
|
734
757
|
/** Optional controls used while resolving action prerequisites. */
|
|
735
758
|
interface ActionRequirementsParams {
|
|
736
759
|
/**
|
|
@@ -743,6 +766,7 @@ interface ActionRequirementsParams {
|
|
|
743
766
|
/** Lazy entity result exposing prerequisite resolution and synchronous transaction building. */
|
|
744
767
|
export interface ActionOutput<TAction extends BaseAction = TransactionAction, TSignatures = RequirementSignature, TRequirementsParams = ActionRequirementsParams> {
|
|
745
768
|
readonly buildTx: (signatures?: TSignatures) => Readonly<Transaction<TAction>>;
|
|
769
|
+
/** Resolves prerequisites using the flow's {@link ReferenceTimestampParams.now | reference timestamp}. */
|
|
746
770
|
readonly getRequirements: (params?: TRequirementsParams) => Promise<readonly ActionRequirement[]>;
|
|
747
771
|
}
|
|
748
772
|
/**
|
|
@@ -827,7 +851,7 @@ export declare function isRequirementApproval(requirement: unknown): requirement
|
|
|
827
851
|
* userAddress: zeroAddress,
|
|
828
852
|
* borrowAssets: 1_000_000n,
|
|
829
853
|
* positionData,
|
|
830
|
-
* deadline:
|
|
854
|
+
* deadline: (await client.getBlock()).timestamp + 600n,
|
|
831
855
|
* });
|
|
832
856
|
*
|
|
833
857
|
* for (const requirement of await handle.getRequirements()) {
|
package/lib/cjs/types/action.js
CHANGED
|
@@ -101,7 +101,7 @@ function isRequirementApproval(requirement) {
|
|
|
101
101
|
* userAddress: zeroAddress,
|
|
102
102
|
* borrowAssets: 1_000_000n,
|
|
103
103
|
* positionData,
|
|
104
|
-
* deadline:
|
|
104
|
+
* deadline: (await client.getBlock()).timestamp + 600n,
|
|
105
105
|
* });
|
|
106
106
|
*
|
|
107
107
|
* for (const requirement of await handle.getRequirements()) {
|
package/lib/cjs/types/error.js
CHANGED
|
@@ -1126,11 +1126,17 @@ class InvalidReallocationSourceTypeError extends Error {
|
|
|
1126
1126
|
* @param missingField - Required market-source field that is absent or malformed.
|
|
1127
1127
|
*/
|
|
1128
1128
|
constructor(sourceType, missingField) {
|
|
1129
|
-
|
|
1130
|
-
|
|
1131
|
-
|
|
1132
|
-
|
|
1133
|
-
|
|
1129
|
+
let message;
|
|
1130
|
+
if (missingField != null) {
|
|
1131
|
+
message = `Reallocation market source must include a valid "${missingField}".`;
|
|
1132
|
+
}
|
|
1133
|
+
else if (sourceType === undefined) {
|
|
1134
|
+
message = 'Reallocation source must specify type "market" or "idle".';
|
|
1135
|
+
}
|
|
1136
|
+
else {
|
|
1137
|
+
message = `Reallocation source type must be "market" or "idle", got "${sourceType}".`;
|
|
1138
|
+
}
|
|
1139
|
+
super(message);
|
|
1134
1140
|
this.sourceType = sourceType;
|
|
1135
1141
|
this.missingField = missingField;
|
|
1136
1142
|
this.name = "InvalidReallocationSourceTypeError";
|
|
@@ -5,6 +5,16 @@ export interface Metadata {
|
|
|
5
5
|
* Invalid values are dropped with a console warning.
|
|
6
6
|
*/
|
|
7
7
|
origin: string;
|
|
8
|
-
/**
|
|
9
|
-
|
|
8
|
+
/**
|
|
9
|
+
* Append a four-byte Unix timestamp before the origin. For entity flows, set
|
|
10
|
+
* `timestamp: true` in the client options and pass a fresh `now` to each flow
|
|
11
|
+
* to record that flow's reference timestamp. `true` without a flow `now` uses
|
|
12
|
+
* the device clock; only this fallback is deprecated.
|
|
13
|
+
*
|
|
14
|
+
* For direct action or `addTransactionMetadata` calls, pass a bigint per
|
|
15
|
+
* transaction, normally the latest block's `timestamp`. A bigint must be
|
|
16
|
+
* uint32 seconds (0 through 2^32 - 1, inclusive). Do not store a per-transaction
|
|
17
|
+
* block timestamp in long-lived client options. `false` or unset omits it.
|
|
18
|
+
*/
|
|
19
|
+
timestamp?: boolean | bigint;
|
|
10
20
|
}
|
package/lib/cjs/utils.d.ts
CHANGED
|
@@ -3,7 +3,7 @@ export { AdaptiveCurveIrmLib as BlueAdaptiveCurveIrmLib, CapacityLimitReason,
|
|
|
3
3
|
/** @deprecated Pre-liquidation support is deprecated and will be removed in the next major. */
|
|
4
4
|
defaultPreLiquidationParamsRegistry as blueDefaultPreLiquidationParamsRegistry,
|
|
5
5
|
/** @deprecated Pre-liquidation support is deprecated and will be removed in the next major. */
|
|
6
|
-
getDefaultPreLiquidationParams as getBlueDefaultPreLiquidationParams, MarketUtils as BlueMarketUtils, MathLib, SharesMath as BlueSharesMath, VaultUtils, VaultV2BlueMarketPublicAllocatorConfigUtils, VaultV2BluePublicAllocatorConfigUtils, VaultV2Utils, } from "@morpho-org/blue-sdk";
|
|
6
|
+
getDefaultPreLiquidationParams as getBlueDefaultPreLiquidationParams, MarketUtils as BlueMarketUtils, MathLib, SharesMath as BlueSharesMath, VaultUtils, VaultV2BlueMarketPublicAllocatorConfigUtils, VaultV2BluePublicAllocatorConfigUtils, VaultV2MidnightAdapterUtils, VaultV2Utils, } from "@morpho-org/blue-sdk";
|
|
7
7
|
export { catchRevertOnly, decodeBytes32String, getAuthorizationTypedData as getBlueAuthorizationTypedData, getPermit2PermitTypedData, getPermit2TransferFromTypedData, getPermitTypedData, isContractRevertError, isTransportError, isUndecodableResultError, MetaMorphoAction as BlueMetaMorphoAction, optionalBoolean, readContractRestructured, restructure, safeGetAddress, safeParseNumber, safeParseUnits, } from "@morpho-org/blue-sdk-viem";
|
|
8
8
|
export { EcrecoverRatifier as MidnightEcrecoverRatifier,
|
|
9
9
|
/** @deprecated Use MidnightEcrecoverRatifier with a tagged tree. */
|
|
@@ -17,7 +17,7 @@ RatifierUtils as MidnightRatifierUtils, SetterRatifier as MidnightSetterRatifier
|
|
|
17
17
|
/** @deprecated Use MidnightSetterRatifier with a tagged tree. */
|
|
18
18
|
SetterRatifierUtils as MidnightSetterRatifierUtils, TakeAmountsLib as MidnightTakeAmountsLib, TickLib as MidnightTickLib, TreeUtils as MidnightTreeUtils, } from "@morpho-org/midnight-sdk";
|
|
19
19
|
export type { ArrayElementType, DeepPartial, DottedKeys, FieldType, PartialDottedKeys, } from "@morpho-org/morpho-ts";
|
|
20
|
-
export { bigIntComparator, createGetValue, createHasValue, deepFreeze, entries, filterDefined, fromEntries, getLast, getLastDefined, getSubdomainBaseUrl, getValue, hasValue, isDefined, isNotNull, isNotUndefined, keys, mergeEntries, retryPromiseLinearBackoff, Time, transformValue, values, } from "@morpho-org/morpho-ts";
|
|
20
|
+
export { bigIntComparator, createGetValue, createHasValue, deepFreeze, entries, filterDefined, fromEntries, getLast, getLastDefined, getSubdomainBaseUrl, getValue, hasValue, isDefined, isNotNull, isNotUndefined, keys, MidnightPositionLib, mergeEntries, retryPromiseLinearBackoff, Time, transformValue, values, } from "@morpho-org/morpho-ts";
|
|
21
21
|
export { validateClientChainId } from "./actions/requirements/validateClientChainId.js";
|
|
22
22
|
export { addTransactionMetadata } from "./helpers/metadata.js";
|
|
23
23
|
export { type PreviewVaultV2ForceWithdrawParams, previewVaultV2ForceWithdraw, type VaultV2ForceWithdrawPreview, } from "./helpers/previewVaultV2ForceWithdraw.js";
|
package/lib/cjs/utils.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
4
|
-
exports.resolveVaultV2ForceWithdrawEligibility = exports.computeVaultV2ForceWithdrawSharesBurnt = exports.computeVaultV2ForceWithdrawPlan = exports.computeVaultV2ForceWithdrawMinSharesBurnt = exports.computeVaultV2ForceWithdrawFeeSharesMinted = exports.validateUserAddress = exports.validateSlippageTolerance = exports.validateRepayShares = exports.validateRepayAmount = exports.validatePositionHealthAfterWithdraw = exports.validatePositionHealth = exports.validateNativeAsset = exports.validateChainId = exports.validateAccrualPosition = exports.computeMinForceWithdrawSharePrice = exports.previewVaultV2InKindRedeem = exports.previewVaultV2ForceWithdraw = exports.addTransactionMetadata = exports.validateClientChainId = exports.values = exports.transformValue = exports.Time = exports.retryPromiseLinearBackoff = exports.mergeEntries = exports.keys = exports.isNotUndefined = exports.isNotNull = exports.isDefined = exports.hasValue = exports.getValue = exports.getSubdomainBaseUrl = exports.getLastDefined = exports.getLast = exports.fromEntries = exports.filterDefined = exports.entries = exports.deepFreeze = void 0;
|
|
3
|
+
exports.createGetValue = exports.bigIntComparator = exports.MidnightTreeUtils = exports.MidnightTickLib = exports.MidnightTakeAmountsLib = exports.MidnightSetterRatifierUtils = exports.MidnightSetterRatifier = exports.MidnightRatifierUtils = exports.MidnightRatifier = exports.MidnightRateRatifierV1Utils = exports.MidnightRateRatifierV1 = exports.MidnightPriceRatifierV1Utils = exports.MidnightPriceRatifierV1 = exports.MidnightPositionUtils = exports.MidnightPayload = exports.MidnightOfferUtils = exports.MidnightOfferChainUtils = exports.MidnightMarketUtils = exports.MidnightGroupUtils = exports.eip712Digest = exports.MidnightEcrecoverRatifierUtils = exports.MidnightEcrecoverRatifier = exports.safeParseUnits = exports.safeParseNumber = exports.safeGetAddress = exports.restructure = exports.readContractRestructured = exports.optionalBoolean = exports.BlueMetaMorphoAction = exports.isUndecodableResultError = exports.isTransportError = exports.isContractRevertError = exports.getPermitTypedData = exports.getPermit2TransferFromTypedData = exports.getPermit2PermitTypedData = exports.getBlueAuthorizationTypedData = exports.decodeBytes32String = exports.catchRevertOnly = exports.VaultV2Utils = exports.VaultV2MidnightAdapterUtils = exports.VaultV2BluePublicAllocatorConfigUtils = exports.VaultV2BlueMarketPublicAllocatorConfigUtils = exports.VaultUtils = exports.BlueSharesMath = exports.MathLib = exports.BlueMarketUtils = exports.getBlueDefaultPreLiquidationParams = exports.blueDefaultPreLiquidationParamsRegistry = exports.CapacityLimitReason = exports.BlueAdaptiveCurveIrmLib = void 0;
|
|
4
|
+
exports.resolveVaultV2ForceWithdrawEligibility = exports.computeVaultV2ForceWithdrawSharesBurnt = exports.computeVaultV2ForceWithdrawPlan = exports.computeVaultV2ForceWithdrawMinSharesBurnt = exports.computeVaultV2ForceWithdrawFeeSharesMinted = exports.validateUserAddress = exports.validateSlippageTolerance = exports.validateRepayShares = exports.validateRepayAmount = exports.validatePositionHealthAfterWithdraw = exports.validatePositionHealth = exports.validateNativeAsset = exports.validateChainId = exports.validateAccrualPosition = exports.computeMinForceWithdrawSharePrice = exports.previewVaultV2InKindRedeem = exports.previewVaultV2ForceWithdraw = exports.addTransactionMetadata = exports.validateClientChainId = exports.values = exports.transformValue = exports.Time = exports.retryPromiseLinearBackoff = exports.mergeEntries = exports.MidnightPositionLib = exports.keys = exports.isNotUndefined = exports.isNotNull = exports.isDefined = exports.hasValue = exports.getValue = exports.getSubdomainBaseUrl = exports.getLastDefined = exports.getLast = exports.fromEntries = exports.filterDefined = exports.entries = exports.deepFreeze = exports.createHasValue = void 0;
|
|
5
5
|
var blue_sdk_1 = require("@morpho-org/blue-sdk");
|
|
6
6
|
Object.defineProperty(exports, "BlueAdaptiveCurveIrmLib", { enumerable: true, get: function () { return blue_sdk_1.AdaptiveCurveIrmLib; } });
|
|
7
7
|
Object.defineProperty(exports, "CapacityLimitReason", { enumerable: true, get: function () { return blue_sdk_1.CapacityLimitReason; } });
|
|
@@ -15,6 +15,7 @@ Object.defineProperty(exports, "BlueSharesMath", { enumerable: true, get: functi
|
|
|
15
15
|
Object.defineProperty(exports, "VaultUtils", { enumerable: true, get: function () { return blue_sdk_1.VaultUtils; } });
|
|
16
16
|
Object.defineProperty(exports, "VaultV2BlueMarketPublicAllocatorConfigUtils", { enumerable: true, get: function () { return blue_sdk_1.VaultV2BlueMarketPublicAllocatorConfigUtils; } });
|
|
17
17
|
Object.defineProperty(exports, "VaultV2BluePublicAllocatorConfigUtils", { enumerable: true, get: function () { return blue_sdk_1.VaultV2BluePublicAllocatorConfigUtils; } });
|
|
18
|
+
Object.defineProperty(exports, "VaultV2MidnightAdapterUtils", { enumerable: true, get: function () { return blue_sdk_1.VaultV2MidnightAdapterUtils; } });
|
|
18
19
|
Object.defineProperty(exports, "VaultV2Utils", { enumerable: true, get: function () { return blue_sdk_1.VaultV2Utils; } });
|
|
19
20
|
var blue_sdk_viem_1 = require("@morpho-org/blue-sdk-viem");
|
|
20
21
|
Object.defineProperty(exports, "catchRevertOnly", { enumerable: true, get: function () { return blue_sdk_viem_1.catchRevertOnly; } });
|
|
@@ -76,6 +77,7 @@ Object.defineProperty(exports, "isDefined", { enumerable: true, get: function ()
|
|
|
76
77
|
Object.defineProperty(exports, "isNotNull", { enumerable: true, get: function () { return morpho_ts_1.isNotNull; } });
|
|
77
78
|
Object.defineProperty(exports, "isNotUndefined", { enumerable: true, get: function () { return morpho_ts_1.isNotUndefined; } });
|
|
78
79
|
Object.defineProperty(exports, "keys", { enumerable: true, get: function () { return morpho_ts_1.keys; } });
|
|
80
|
+
Object.defineProperty(exports, "MidnightPositionLib", { enumerable: true, get: function () { return morpho_ts_1.MidnightPositionLib; } });
|
|
79
81
|
Object.defineProperty(exports, "mergeEntries", { enumerable: true, get: function () { return morpho_ts_1.mergeEntries; } });
|
|
80
82
|
Object.defineProperty(exports, "retryPromiseLinearBackoff", { enumerable: true, get: function () { return morpho_ts_1.retryPromiseLinearBackoff; } });
|
|
81
83
|
Object.defineProperty(exports, "Time", { enumerable: true, get: function () { return morpho_ts_1.Time; } });
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
// Generated by scripts/generate-package-versions.ts. Do not edit.
|
|
3
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
|
+
exports.version = void 0;
|
|
5
|
+
/** Installed @morpho-org/morpho-sdk package version. */
|
|
6
|
+
exports.version = "10.0.0-next.0";
|
package/lib/esm/abis.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
export { marketParamsAbi as blueMarketParamsAbi } from "@morpho-org/blue-sdk";
|
|
2
|
-
export { adaptiveCurveIrmAbi as blueAdaptiveCurveIrmAbi, blueAbi, blueOracleAbi, erc2612Abi, erc3643Abi, erc3643IdentityRegistryAbi, erc5267Abi, metaMorphoAbi, metaMorphoFactoryAbi, morphoMarketV1AdapterAbi, morphoMarketV1AdapterFactoryAbi, morphoMarketV1AdapterV2Abi, morphoMarketV1AdapterV2FactoryAbi, morphoVaultV1AdapterAbi, morphoVaultV1AdapterFactoryAbi, permissionedErc20WrapperAbi, permit2Abi,
|
|
2
|
+
export { adaptiveCurveIrmAbi as blueAdaptiveCurveIrmAbi, blueAbi, blueOracleAbi, erc2612Abi, erc3643Abi, erc3643IdentityRegistryAbi, erc5267Abi, metaMorphoAbi, metaMorphoFactoryAbi, midnightAdapterAbi, midnightAdapterFactoryAbi, midnightAdapterPriceRatifierV1Abi, midnightAdapterRateRatifierV1Abi, morphoMarketV1AdapterAbi, morphoMarketV1AdapterFactoryAbi, morphoMarketV1AdapterV2Abi, morphoMarketV1AdapterV2FactoryAbi, morphoVaultV1AdapterAbi, morphoVaultV1AdapterFactoryAbi, permissionedErc20WrapperAbi, permit2Abi,
|
|
3
3
|
/** @deprecated Pre-liquidation support is deprecated and will be removed in the next major. */
|
|
4
4
|
preLiquidationAbi as bluePreLiquidationAbi,
|
|
5
5
|
/** @deprecated Pre-liquidation support is deprecated and will be removed in the next major. */
|
package/lib/esm/abis.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
export { marketParamsAbi as blueMarketParamsAbi } from "@morpho-org/blue-sdk";
|
|
2
|
-
export { adaptiveCurveIrmAbi as blueAdaptiveCurveIrmAbi, blueAbi, blueOracleAbi, erc2612Abi, erc3643Abi, erc3643IdentityRegistryAbi, erc5267Abi, metaMorphoAbi, metaMorphoFactoryAbi, morphoMarketV1AdapterAbi, morphoMarketV1AdapterFactoryAbi, morphoMarketV1AdapterV2Abi, morphoMarketV1AdapterV2FactoryAbi, morphoVaultV1AdapterAbi, morphoVaultV1AdapterFactoryAbi, permissionedErc20WrapperAbi, permit2Abi,
|
|
2
|
+
export { adaptiveCurveIrmAbi as blueAdaptiveCurveIrmAbi, blueAbi, blueOracleAbi, erc2612Abi, erc3643Abi, erc3643IdentityRegistryAbi, erc5267Abi, metaMorphoAbi, metaMorphoFactoryAbi, midnightAdapterAbi, midnightAdapterFactoryAbi, midnightAdapterPriceRatifierV1Abi, midnightAdapterRateRatifierV1Abi, morphoMarketV1AdapterAbi, morphoMarketV1AdapterFactoryAbi, morphoMarketV1AdapterV2Abi, morphoMarketV1AdapterV2FactoryAbi, morphoVaultV1AdapterAbi, morphoVaultV1AdapterFactoryAbi, permissionedErc20WrapperAbi, permit2Abi,
|
|
3
3
|
/** @deprecated Pre-liquidation support is deprecated and will be removed in the next major. */
|
|
4
4
|
preLiquidationAbi as bluePreLiquidationAbi,
|
|
5
5
|
/** @deprecated Pre-liquidation support is deprecated and will be removed in the next major. */
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { Address } from "viem";
|
|
2
|
-
import { type BundlesTokenSignatureRequirement, type ERC20ApprovalAction, type Transaction } from "../../types/index.js";
|
|
2
|
+
import { type BundlesTokenSignatureRequirement, type ERC20ApprovalAction, type ReferenceTimestampParams, type Transaction } from "../../types/index.js";
|
|
3
3
|
/** Plain onchain state used by {@link resolveBundlesTokenRequirements}. */
|
|
4
4
|
export type BundlesTokenRequirementsState = {
|
|
5
5
|
readonly type: "approval";
|
|
@@ -31,7 +31,7 @@ export type BundlesTokenRequirementsState = {
|
|
|
31
31
|
* @param params.amount - Exact pull amount in the token's smallest unit; zero returns no requirements.
|
|
32
32
|
* @param params.deadline - Signature expiration as a Unix timestamp in seconds; in the
|
|
33
33
|
* SignatureTransfer branch it must be positive, within uint256, and in the future.
|
|
34
|
-
* @param params.now -
|
|
34
|
+
* @param params.now - See {@link ReferenceTimestampParams.now}.
|
|
35
35
|
* @param params.state - Prefetched state for either classic approval or Permit2 SignatureTransfer.
|
|
36
36
|
* @param params.state.type - `approval` for a direct allowance or `permit2SignatureTransfer` for a signed pull.
|
|
37
37
|
* @param params.state.allowance - In the approval branch, current token allowance from `owner` to `spender`.
|
|
@@ -74,6 +74,5 @@ export declare const resolveBundlesTokenRequirements: (params: {
|
|
|
74
74
|
readonly chainId: number;
|
|
75
75
|
readonly amount: bigint;
|
|
76
76
|
readonly deadline: bigint;
|
|
77
|
-
readonly now?: bigint;
|
|
78
77
|
readonly state: BundlesTokenRequirementsState;
|
|
79
|
-
}) => readonly (Readonly<Transaction<ERC20ApprovalAction>> | BundlesTokenSignatureRequirement)[];
|
|
78
|
+
} & ReferenceTimestampParams) => readonly (Readonly<Transaction<ERC20ApprovalAction>> | BundlesTokenSignatureRequirement)[];
|
|
@@ -24,7 +24,7 @@ import { getRequirementsApproval } from "../requirements/getRequirementsApproval
|
|
|
24
24
|
* @param params.amount - Exact pull amount in the token's smallest unit; zero returns no requirements.
|
|
25
25
|
* @param params.deadline - Signature expiration as a Unix timestamp in seconds; in the
|
|
26
26
|
* SignatureTransfer branch it must be positive, within uint256, and in the future.
|
|
27
|
-
* @param params.now -
|
|
27
|
+
* @param params.now - See {@link ReferenceTimestampParams.now}.
|
|
28
28
|
* @param params.state - Prefetched state for either classic approval or Permit2 SignatureTransfer.
|
|
29
29
|
* @param params.state.type - `approval` for a direct allowance or `permit2SignatureTransfer` for a signed pull.
|
|
30
30
|
* @param params.state.allowance - In the approval branch, current token allowance from `owner` to `spender`.
|
|
@@ -5,7 +5,8 @@ export type { MidnightCancelAndMakeParams, MidnightMakeBorrowCollateral, Midnigh
|
|
|
5
5
|
* Encodes `MidnightBundlesV2.midnightBundlesV2CancelAndMake` for `msg.sender`: cancel previous
|
|
6
6
|
* groups under consumption guards, optionally park loan assets on Morpho Blue for the maker's
|
|
7
7
|
* `BlueBuyCallback` or supply collateral, activate `root`, and publish `payload`.
|
|
8
|
-
* Without `publication`, it only cancels groups (
|
|
8
|
+
* Without `publication`, it only cancels groups; `client.morpho.midnight(chainId).cancelOffers(...)`
|
|
9
|
+
* does not use this builder and calls Midnight directly through `midnightCancelOffers`.
|
|
9
10
|
* Execution reverts as a whole if any group's consumption exceeds its `maxConsumed` ceiling.
|
|
10
11
|
* The builder snapshots every input field once before validation and encoding. It checks root,
|
|
11
12
|
* groups, cancellation groups, Blue callback salt, and root-signature `r`/`s` as 32-byte hex and
|
|
@@ -23,7 +23,8 @@ const emptyMidnightMarket = {
|
|
|
23
23
|
* Encodes `MidnightBundlesV2.midnightBundlesV2CancelAndMake` for `msg.sender`: cancel previous
|
|
24
24
|
* groups under consumption guards, optionally park loan assets on Morpho Blue for the maker's
|
|
25
25
|
* `BlueBuyCallback` or supply collateral, activate `root`, and publish `payload`.
|
|
26
|
-
* Without `publication`, it only cancels groups (
|
|
26
|
+
* Without `publication`, it only cancels groups; `client.morpho.midnight(chainId).cancelOffers(...)`
|
|
27
|
+
* does not use this builder and calls Midnight directly through `midnightCancelOffers`.
|
|
27
28
|
* Execution reverts as a whole if any group's consumption exceeds its `maxConsumed` ceiling.
|
|
28
29
|
* The builder snapshots every input field once before validation and encoding. It checks root,
|
|
29
30
|
* groups, cancellation groups, Blue callback salt, and root-signature `r`/`s` as 32-byte hex and
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
import { type Address, type Hex } from "viem";
|
|
2
|
+
import { type Metadata, type MidnightCancelOffersAction, type Transaction } from "../../types/index.js";
|
|
3
|
+
/** Parameters for a direct Midnight cancellation of one or more offer groups. */
|
|
4
|
+
export interface MidnightCancelOffersParams {
|
|
5
|
+
readonly chainId: number;
|
|
6
|
+
readonly groups: readonly Hex[];
|
|
7
|
+
readonly onBehalf: Address;
|
|
8
|
+
readonly metadata?: Metadata;
|
|
9
|
+
}
|
|
10
|
+
/**
|
|
11
|
+
* Encodes a full cancellation of one or more offer groups as a direct call to Midnight.
|
|
12
|
+
*
|
|
13
|
+
* One group encodes a bare `setConsumed(group, maxUint128, onBehalf)`. Two or more groups encode
|
|
14
|
+
* one Midnight `multicall` holding one such `setConsumed` call per group, in list order; the batch
|
|
15
|
+
* cancels every group or none. Only the single-group encoding is matchable by a wallet policy that
|
|
16
|
+
* allows `setConsumed` by method name: a batch is a `multicall` call, so cancel one group per
|
|
17
|
+
* transaction when the signer's policy names `setConsumed`.
|
|
18
|
+
*
|
|
19
|
+
* The amount is always `maxUint128`, which Midnight never rejects, so cancelling a group again
|
|
20
|
+
* succeeds. Cancellation is per group: it does not unratify roots or revoke authorizations. The
|
|
21
|
+
* transaction never targets `MidnightBundlesV2` and needs no prior authorization or approval.
|
|
22
|
+
*
|
|
23
|
+
* @param params.chainId - Chain id used to resolve `Midnight`.
|
|
24
|
+
* @param params.groups - Nonempty list of distinct 32-byte offer groups to cancel.
|
|
25
|
+
* @param params.onBehalf - Maker whose groups are cancelled. `onBehalf`, or an operator it
|
|
26
|
+
* authorized on Midnight, must send the transaction; otherwise Midnight reverts
|
|
27
|
+
* `Unauthorized()` and no group changes.
|
|
28
|
+
* @param params.metadata - Optional analytics metadata appended to calldata.
|
|
29
|
+
* @returns A deep-frozen `Transaction<MidnightCancelOffersAction>` targeting `Midnight`.
|
|
30
|
+
* @throws {MidnightCalldataEncodingError} when `onBehalf` is not a valid address.
|
|
31
|
+
* @throws {MidnightZeroOnBehalfError} when `onBehalf` is the zero address.
|
|
32
|
+
* @throws {EmptyMidnightGroupCancellationsError} when `groups` is empty.
|
|
33
|
+
* @throws {InvalidMidnightHexInputError} when a group is not 32-byte hex.
|
|
34
|
+
* @throws {DuplicateMidnightGroupCancellationError} when a group appears more than once.
|
|
35
|
+
* @throws {UnsupportedChainIdError} when the chain is absent from the address registry.
|
|
36
|
+
* @throws {UnknownAddressError} when the chain has no `midnight` deployment.
|
|
37
|
+
* @example
|
|
38
|
+
* ```ts
|
|
39
|
+
* import { midnightCancelOffers } from "@morpho-org/morpho-sdk";
|
|
40
|
+
* import type { Address, Hex } from "viem";
|
|
41
|
+
*
|
|
42
|
+
* declare const maker: Address;
|
|
43
|
+
* declare const group: Hex;
|
|
44
|
+
*
|
|
45
|
+
* // One group: calldata is `setConsumed(group, maxUint128, maker)`.
|
|
46
|
+
* const tx = midnightCancelOffers({
|
|
47
|
+
* chainId: 8453,
|
|
48
|
+
* groups: [group],
|
|
49
|
+
* onBehalf: maker,
|
|
50
|
+
* });
|
|
51
|
+
* // tx.action => { type: "midnightCancelOffers", args: { groups: [group], onBehalf: maker } }
|
|
52
|
+
* ```
|
|
53
|
+
*/
|
|
54
|
+
export declare const midnightCancelOffers: (params: MidnightCancelOffersParams) => Readonly<Transaction<MidnightCancelOffersAction>>;
|
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
import { midnightAbi } from "@morpho-org/midnight-sdk";
|
|
2
|
+
import { deepFreeze, getChainAddress } from "@morpho-org/morpho-ts";
|
|
3
|
+
import { isAddressEqual, maxUint128, zeroAddress, } from "viem";
|
|
4
|
+
import { encodeMidnightCalldata } from "../../helpers/encodeMidnightCalldata.js";
|
|
5
|
+
import { addTransactionMetadata } from "../../helpers/index.js";
|
|
6
|
+
import { validateMidnightAddress } from "../../helpers/validateMidnightAccount.js";
|
|
7
|
+
import { validateMidnightBytes32 } from "../../helpers/validateMidnightPublication.js";
|
|
8
|
+
import { DuplicateMidnightGroupCancellationError, EmptyMidnightGroupCancellationsError, MidnightZeroOnBehalfError, } from "../../types/index.js";
|
|
9
|
+
/**
|
|
10
|
+
* Encodes a full cancellation of one or more offer groups as a direct call to Midnight.
|
|
11
|
+
*
|
|
12
|
+
* One group encodes a bare `setConsumed(group, maxUint128, onBehalf)`. Two or more groups encode
|
|
13
|
+
* one Midnight `multicall` holding one such `setConsumed` call per group, in list order; the batch
|
|
14
|
+
* cancels every group or none. Only the single-group encoding is matchable by a wallet policy that
|
|
15
|
+
* allows `setConsumed` by method name: a batch is a `multicall` call, so cancel one group per
|
|
16
|
+
* transaction when the signer's policy names `setConsumed`.
|
|
17
|
+
*
|
|
18
|
+
* The amount is always `maxUint128`, which Midnight never rejects, so cancelling a group again
|
|
19
|
+
* succeeds. Cancellation is per group: it does not unratify roots or revoke authorizations. The
|
|
20
|
+
* transaction never targets `MidnightBundlesV2` and needs no prior authorization or approval.
|
|
21
|
+
*
|
|
22
|
+
* @param params.chainId - Chain id used to resolve `Midnight`.
|
|
23
|
+
* @param params.groups - Nonempty list of distinct 32-byte offer groups to cancel.
|
|
24
|
+
* @param params.onBehalf - Maker whose groups are cancelled. `onBehalf`, or an operator it
|
|
25
|
+
* authorized on Midnight, must send the transaction; otherwise Midnight reverts
|
|
26
|
+
* `Unauthorized()` and no group changes.
|
|
27
|
+
* @param params.metadata - Optional analytics metadata appended to calldata.
|
|
28
|
+
* @returns A deep-frozen `Transaction<MidnightCancelOffersAction>` targeting `Midnight`.
|
|
29
|
+
* @throws {MidnightCalldataEncodingError} when `onBehalf` is not a valid address.
|
|
30
|
+
* @throws {MidnightZeroOnBehalfError} when `onBehalf` is the zero address.
|
|
31
|
+
* @throws {EmptyMidnightGroupCancellationsError} when `groups` is empty.
|
|
32
|
+
* @throws {InvalidMidnightHexInputError} when a group is not 32-byte hex.
|
|
33
|
+
* @throws {DuplicateMidnightGroupCancellationError} when a group appears more than once.
|
|
34
|
+
* @throws {UnsupportedChainIdError} when the chain is absent from the address registry.
|
|
35
|
+
* @throws {UnknownAddressError} when the chain has no `midnight` deployment.
|
|
36
|
+
* @example
|
|
37
|
+
* ```ts
|
|
38
|
+
* import { midnightCancelOffers } from "@morpho-org/morpho-sdk";
|
|
39
|
+
* import type { Address, Hex } from "viem";
|
|
40
|
+
*
|
|
41
|
+
* declare const maker: Address;
|
|
42
|
+
* declare const group: Hex;
|
|
43
|
+
*
|
|
44
|
+
* // One group: calldata is `setConsumed(group, maxUint128, maker)`.
|
|
45
|
+
* const tx = midnightCancelOffers({
|
|
46
|
+
* chainId: 8453,
|
|
47
|
+
* groups: [group],
|
|
48
|
+
* onBehalf: maker,
|
|
49
|
+
* });
|
|
50
|
+
* // tx.action => { type: "midnightCancelOffers", args: { groups: [group], onBehalf: maker } }
|
|
51
|
+
* ```
|
|
52
|
+
*/
|
|
53
|
+
export const midnightCancelOffers = (params) => {
|
|
54
|
+
const { chainId, onBehalf, metadata } = params;
|
|
55
|
+
// Copy the list so validation and encoding read one snapshot and the caller's array stays unfrozen.
|
|
56
|
+
const groups = [...params.groups];
|
|
57
|
+
// Reject a malformed account before comparing it with the zero address.
|
|
58
|
+
validateMidnightAddress("onBehalf", onBehalf);
|
|
59
|
+
if (isAddressEqual(onBehalf, zeroAddress)) {
|
|
60
|
+
throw new MidnightZeroOnBehalfError("onBehalf");
|
|
61
|
+
}
|
|
62
|
+
if (groups.length === 0)
|
|
63
|
+
throw new EmptyMidnightGroupCancellationsError();
|
|
64
|
+
const seen = new Set();
|
|
65
|
+
for (const [index, group] of groups.entries()) {
|
|
66
|
+
// Validation only; rejects groups that are not 32-byte hex.
|
|
67
|
+
validateMidnightBytes32(`groups[${index}]`, group);
|
|
68
|
+
const key = group.toLowerCase();
|
|
69
|
+
if (seen.has(key)) {
|
|
70
|
+
throw new DuplicateMidnightGroupCancellationError({ index, group });
|
|
71
|
+
}
|
|
72
|
+
seen.add(key);
|
|
73
|
+
}
|
|
74
|
+
const midnight = getChainAddress(chainId, "midnight");
|
|
75
|
+
const calls = groups.map((group) => encodeMidnightCalldata({
|
|
76
|
+
abi: midnightAbi,
|
|
77
|
+
functionName: "setConsumed",
|
|
78
|
+
args: [group, maxUint128, onBehalf],
|
|
79
|
+
}));
|
|
80
|
+
const [single] = calls;
|
|
81
|
+
let tx = {
|
|
82
|
+
to: midnight,
|
|
83
|
+
value: 0n,
|
|
84
|
+
// A single cancellation stays a bare `setConsumed` so a method-name policy can match it.
|
|
85
|
+
data: calls.length === 1 && single !== undefined
|
|
86
|
+
? single
|
|
87
|
+
: encodeMidnightCalldata({
|
|
88
|
+
abi: midnightAbi,
|
|
89
|
+
functionName: "multicall",
|
|
90
|
+
args: [calls],
|
|
91
|
+
}),
|
|
92
|
+
};
|
|
93
|
+
if (metadata) {
|
|
94
|
+
tx = addTransactionMetadata(tx, metadata);
|
|
95
|
+
}
|
|
96
|
+
return deepFreeze({
|
|
97
|
+
...tx,
|
|
98
|
+
action: {
|
|
99
|
+
type: "midnightCancelOffers",
|
|
100
|
+
args: { groups, onBehalf },
|
|
101
|
+
},
|
|
102
|
+
});
|
|
103
|
+
};
|
|
@@ -86,7 +86,7 @@ export interface MidnightSupplyCollateralTakeBorrowParams extends MidnightTakeBo
|
|
|
86
86
|
* receiver: borrower,
|
|
87
87
|
* collateralSupplies: [{ collateralIndex: 0n, assets: 2_000_000n }],
|
|
88
88
|
* takeableOffers: quote.data.takeableOffers,
|
|
89
|
-
* deadline:
|
|
89
|
+
* deadline: (await client.getBlock()).timestamp + 600n,
|
|
90
90
|
* });
|
|
91
91
|
* ```
|
|
92
92
|
*/
|
|
@@ -87,7 +87,7 @@ import { EmptyMidnightCollateralSuppliesError, UnboundedMidnightTakeInputError,
|
|
|
87
87
|
* receiver: borrower,
|
|
88
88
|
* collateralSupplies: [{ collateralIndex: 0n, assets: 2_000_000n }],
|
|
89
89
|
* takeableOffers: quote.data.takeableOffers,
|
|
90
|
-
* deadline:
|
|
90
|
+
* deadline: (await client.getBlock()).timestamp + 600n,
|
|
91
91
|
* });
|
|
92
92
|
* ```
|
|
93
93
|
*/
|
|
@@ -77,7 +77,7 @@ export interface MidnightTakeBorrowParams extends MidnightReferralFeeParams {
|
|
|
77
77
|
* target: { type: "assets", assets: 1_000_000n, maxUnits: 1_100_000n },
|
|
78
78
|
* receiver: borrower,
|
|
79
79
|
* takeableOffers: quote.data.takeableOffers,
|
|
80
|
-
* deadline:
|
|
80
|
+
* deadline: (await client.getBlock()).timestamp + 600n,
|
|
81
81
|
* });
|
|
82
82
|
* ```
|
|
83
83
|
*/
|
|
@@ -74,7 +74,7 @@ import { UnboundedMidnightTakeInputError, } from "../../types/index.js";
|
|
|
74
74
|
* target: { type: "assets", assets: 1_000_000n, maxUnits: 1_100_000n },
|
|
75
75
|
* receiver: borrower,
|
|
76
76
|
* takeableOffers: quote.data.takeableOffers,
|
|
77
|
-
* deadline:
|
|
77
|
+
* deadline: (await client.getBlock()).timestamp + 600n,
|
|
78
78
|
* });
|
|
79
79
|
* ```
|
|
80
80
|
*/
|
|
@@ -81,7 +81,7 @@ export interface MidnightTakeLendParams extends MidnightReferralFeeParams {
|
|
|
81
81
|
* target: { type: "assets", assets: 1_000_000n, minUnits: 900_000n },
|
|
82
82
|
* takeableOffers: quote.data.takeableOffers,
|
|
83
83
|
* maxContinuousFee: maxUint256,
|
|
84
|
-
* deadline:
|
|
84
|
+
* deadline: (await client.getBlock()).timestamp + 600n,
|
|
85
85
|
* });
|
|
86
86
|
* ```
|
|
87
87
|
*/
|
|
@@ -71,7 +71,7 @@ import { UnboundedMidnightTakeInputError, } from "../../types/index.js";
|
|
|
71
71
|
* target: { type: "assets", assets: 1_000_000n, minUnits: 900_000n },
|
|
72
72
|
* takeableOffers: quote.data.takeableOffers,
|
|
73
73
|
* maxContinuousFee: maxUint256,
|
|
74
|
-
* deadline:
|
|
74
|
+
* deadline: (await client.getBlock()).timestamp + 600n,
|
|
75
75
|
* });
|
|
76
76
|
* ```
|
|
77
77
|
*/
|
|
@@ -107,7 +107,7 @@ export interface MidnightTakeRepayWithdrawCollateralParams extends MidnightRefer
|
|
|
107
107
|
* collateralWithdrawals: [{ collateralIndex: 0n, assets: maxUint256 }],
|
|
108
108
|
* collateralReceiver: borrower,
|
|
109
109
|
* maxContinuousFee: maxUint256,
|
|
110
|
-
* deadline:
|
|
110
|
+
* deadline: (await client.getBlock()).timestamp + 600n,
|
|
111
111
|
* });
|
|
112
112
|
* ```
|
|
113
113
|
*/
|
|
@@ -90,7 +90,7 @@ import { NonPositiveInputError, UnboundedMidnightTakeInputError, } from "../../t
|
|
|
90
90
|
* collateralWithdrawals: [{ collateralIndex: 0n, assets: maxUint256 }],
|
|
91
91
|
* collateralReceiver: borrower,
|
|
92
92
|
* maxContinuousFee: maxUint256,
|
|
93
|
-
* deadline:
|
|
93
|
+
* deadline: (await client.getBlock()).timestamp + 600n,
|
|
94
94
|
* });
|
|
95
95
|
* ```
|
|
96
96
|
*/
|
|
@@ -73,7 +73,7 @@ export interface MidnightTakeWithdrawParams extends MidnightReferralFeeParams {
|
|
|
73
73
|
* target: { type: "units", units: credit, minSellerAssets: 990_000n },
|
|
74
74
|
* receiver: lender,
|
|
75
75
|
* takeableOffers: quote.data.takeableOffers,
|
|
76
|
-
* deadline:
|
|
76
|
+
* deadline: (await client.getBlock()).timestamp + 600n,
|
|
77
77
|
* });
|
|
78
78
|
* ```
|
|
79
79
|
*/
|
|
@@ -134,7 +134,7 @@ const validateParams = (params) => {
|
|
|
134
134
|
* target: { type: "units", units: credit, minSellerAssets: 990_000n },
|
|
135
135
|
* receiver: lender,
|
|
136
136
|
* takeableOffers: quote.data.takeableOffers,
|
|
137
|
-
* deadline:
|
|
137
|
+
* deadline: (await client.getBlock()).timestamp + 600n,
|
|
138
138
|
* });
|
|
139
139
|
* ```
|
|
140
140
|
*/
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type { Client } from "viem";
|
|
2
2
|
import { type Address } from "viem";
|
|
3
|
-
import { type AuthorizationRequirementSignature, type BlueAuthorizationAction, type Requirement, type Transaction } from "../../../types/index.js";
|
|
3
|
+
import { type AuthorizationRequirementSignature, type BlueAuthorizationAction, type ReferenceTimestampParams, type Requirement, type Transaction } from "../../../types/index.js";
|
|
4
4
|
/**
|
|
5
5
|
* Resolves whether a supported operator needs Blue authorization for the given user, and returns
|
|
6
6
|
* the requirement to satisfy it when it does.
|
|
@@ -18,7 +18,7 @@ import { type AuthorizationRequirementSignature, type BlueAuthorizationAction, t
|
|
|
18
18
|
* @param params.authorized - Operator to authorize. Defaults to the chain's registered
|
|
19
19
|
* BlueBundlesV1 deployment and must match it.
|
|
20
20
|
* @param params.deadline - Optional signature deadline forwarded to the authorization encoder.
|
|
21
|
-
* @param params.now -
|
|
21
|
+
* @param params.now - See {@link ReferenceTimestampParams.now}.
|
|
22
22
|
* @param params.supportSignature - When `true`, return a signable `Requirement` instead of a
|
|
23
23
|
* transaction so the destination route can consume the signed authorization.
|
|
24
24
|
* @returns A deep-frozen `Transaction<BlueAuthorizationAction>`, a signable authorization
|
|
@@ -63,5 +63,4 @@ export declare const getBlueAuthorizationRequirement: (params: {
|
|
|
63
63
|
readonly supportSignature?: boolean;
|
|
64
64
|
readonly authorized?: Address;
|
|
65
65
|
readonly deadline?: bigint;
|
|
66
|
-
|
|
67
|
-
}) => Promise<Readonly<Transaction<BlueAuthorizationAction>> | Requirement<AuthorizationRequirementSignature> | null>;
|
|
66
|
+
} & ReferenceTimestampParams) => Promise<Readonly<Transaction<BlueAuthorizationAction>> | Requirement<AuthorizationRequirementSignature> | null>;
|
|
@@ -23,7 +23,7 @@ import { validateClientChainId } from "../validateClientChainId.js";
|
|
|
23
23
|
* @param params.authorized - Operator to authorize. Defaults to the chain's registered
|
|
24
24
|
* BlueBundlesV1 deployment and must match it.
|
|
25
25
|
* @param params.deadline - Optional signature deadline forwarded to the authorization encoder.
|
|
26
|
-
* @param params.now -
|
|
26
|
+
* @param params.now - See {@link ReferenceTimestampParams.now}.
|
|
27
27
|
* @param params.supportSignature - When `true`, return a signable `Requirement` instead of a
|
|
28
28
|
* transaction so the destination route can consume the signed authorization.
|
|
29
29
|
* @returns A deep-frozen `Transaction<BlueAuthorizationAction>`, a signable authorization
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import type { Address } from "@morpho-org/blue-sdk";
|
|
2
2
|
import { type Client } from "viem";
|
|
3
|
-
import { type AuthorizationRequirementSignature, type Requirement } from "../../../types/index.js";
|
|
3
|
+
import { type AuthorizationRequirementSignature, type ReferenceTimestampParams, type Requirement } from "../../../types/index.js";
|
|
4
4
|
/** Parameters for {@link encodeBlueSignatureAuthorization}. */
|
|
5
|
-
interface EncodeBlueSignatureAuthorizationParams {
|
|
5
|
+
interface EncodeBlueSignatureAuthorizationParams extends ReferenceTimestampParams {
|
|
6
6
|
/** Account granting the authorization and signing it (the Morpho `authorizer`). */
|
|
7
7
|
owner: Address;
|
|
8
8
|
/** BlueBundlesV1 operator to authorize on Morpho; must be the chain's registered deployment. */
|
|
@@ -15,8 +15,6 @@ interface EncodeBlueSignatureAuthorizationParams {
|
|
|
15
15
|
isAuthorized?: boolean;
|
|
16
16
|
/** Signature deadline in seconds. Defaults to two hours from now. */
|
|
17
17
|
deadline?: bigint;
|
|
18
|
-
/** Timestamp the deadline is validated against; defaults to the current time. */
|
|
19
|
-
now?: bigint;
|
|
20
18
|
}
|
|
21
19
|
/**
|
|
22
20
|
* Builds a Morpho authorization `Requirement` that, once signed, lets BlueBundlesV1 operate on
|
|
@@ -26,7 +24,7 @@ interface EncodeBlueSignatureAuthorizationParams {
|
|
|
26
24
|
* typed data, verifies it against the connected account, and returns a deep-frozen
|
|
27
25
|
* `RequirementSignature` the selected transaction route consumes. The requirement's
|
|
28
26
|
* `action.typedData` holds that EIP-712 payload so it can be inspected or displayed before signing.
|
|
29
|
-
* Deadline defaults to two hours from `
|
|
27
|
+
* Deadline defaults to two hours from `params.now` (the deprecated fallback uses the device clock).
|
|
30
28
|
* The operator pin applies to grants and revocations alike: revoking a previously registered
|
|
31
29
|
* operator is outside this helper's scope.
|
|
32
30
|
*
|
|
@@ -40,7 +38,7 @@ interface EncodeBlueSignatureAuthorizationParams {
|
|
|
40
38
|
* @param params.nonce - The owner's current Morpho authorization nonce.
|
|
41
39
|
* @param params.isAuthorized - Grant (`true`, default) or revoke (`false`).
|
|
42
40
|
* @param params.deadline - Optional signature deadline in seconds.
|
|
43
|
-
* @param params.now -
|
|
41
|
+
* @param params.now - See {@link ReferenceTimestampParams.now}.
|
|
44
42
|
* @returns A `Requirement` whose `action.typedData` is the EIP-712 payload and whose
|
|
45
43
|
* `sign(client, userAddress)` produces the deep-frozen signature.
|
|
46
44
|
* @throws {ChainIdMismatchError} when `viemClient.chain?.id !== params.chainId`.
|