@morpho-org/morpho-sdk 10.3.0 → 10.4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +172 -8
- package/lib/cjs/actions/midnight/redeem.d.ts +20 -3
- package/lib/cjs/actions/midnight/redeem.js +58 -1
- package/lib/cjs/actions/midnight/supplyCollateralWithNative.d.ts +24 -1
- package/lib/cjs/actions/midnight/supplyCollateralWithNative.js +41 -0
- package/lib/cjs/actions/midnight/withdrawCollateral.d.ts +16 -2
- package/lib/cjs/actions/midnight/withdrawCollateral.js +26 -1
- package/lib/cjs/helpers/callback.d.ts +3 -2
- package/lib/cjs/helpers/callback.js +4 -20
- package/lib/cjs/helpers/computeMidnightPostWithdrawalCollateral.d.ts +17 -0
- package/lib/cjs/helpers/computeMidnightPostWithdrawalCollateral.js +30 -0
- package/lib/cjs/helpers/parseMidnightMaker.d.ts +21 -0
- package/lib/cjs/helpers/parseMidnightMaker.js +41 -1
- package/lib/cjs/helpers/validate.d.ts +49 -1
- package/lib/cjs/helpers/validate.js +87 -1
- package/lib/cjs/helpers/validateMidnightPublication.d.ts +10 -0
- package/lib/cjs/helpers/validateMidnightPublication.js +18 -1
- package/lib/cjs/helpers/validateMidnightTakeableOfferFields.d.ts +28 -0
- package/lib/cjs/helpers/validateMidnightTakeableOfferFields.js +85 -0
- package/lib/cjs/index.d.ts +2 -2
- package/lib/cjs/index.js +23 -1
- package/lib/cjs/midnight/utils.d.ts +1 -1
- package/lib/cjs/midnight/utils.js +2 -1
- package/lib/cjs/transactionPlan/blue/withdrawBuyCallback.d.ts +101 -0
- package/lib/cjs/transactionPlan/blue/withdrawBuyCallback.js +264 -0
- package/lib/cjs/transactionPlan/error.d.ts +27 -0
- package/lib/cjs/transactionPlan/error.js +30 -1
- package/lib/cjs/transactionPlan/index.d.ts +40 -1
- package/lib/cjs/transactionPlan/index.js +46 -5
- package/lib/cjs/transactionPlan/midnight/authorization.d.ts +15 -0
- package/lib/cjs/transactionPlan/midnight/authorization.js +45 -0
- package/lib/cjs/transactionPlan/midnight/cancelOffers.d.ts +80 -0
- package/lib/cjs/transactionPlan/midnight/cancelOffers.js +125 -0
- package/lib/cjs/transactionPlan/midnight/makeBorrow.d.ts +104 -0
- package/lib/cjs/transactionPlan/midnight/makeBorrow.js +126 -0
- package/lib/cjs/transactionPlan/midnight/makeLend.d.ts +140 -0
- package/lib/cjs/transactionPlan/midnight/makeLend.js +176 -0
- package/lib/cjs/transactionPlan/midnight/makeRepay.d.ts +118 -0
- package/lib/cjs/transactionPlan/midnight/makeRepay.js +118 -0
- package/lib/cjs/transactionPlan/midnight/makeWithdraw.d.ts +104 -0
- package/lib/cjs/transactionPlan/midnight/makeWithdraw.js +126 -0
- package/lib/cjs/transactionPlan/midnight/makerPublication.d.ts +55 -0
- package/lib/cjs/transactionPlan/midnight/makerPublication.js +315 -0
- package/lib/cjs/transactionPlan/midnight/market.d.ts +49 -0
- package/lib/cjs/transactionPlan/midnight/market.js +120 -0
- package/lib/cjs/transactionPlan/midnight/prepare.d.ts +244 -0
- package/lib/cjs/transactionPlan/midnight/prepare.js +547 -0
- package/lib/cjs/transactionPlan/midnight/publicationState.d.ts +24 -0
- package/lib/cjs/transactionPlan/midnight/publicationState.js +50 -0
- package/lib/cjs/transactionPlan/midnight/redeem.d.ts +102 -0
- package/lib/cjs/transactionPlan/midnight/redeem.js +170 -0
- package/lib/cjs/transactionPlan/midnight/reduceOnlySellFeasibility.d.ts +25 -0
- package/lib/cjs/transactionPlan/midnight/reduceOnlySellFeasibility.js +51 -0
- package/lib/cjs/transactionPlan/midnight/repayWithdrawCollateral.d.ts +162 -0
- package/lib/cjs/transactionPlan/midnight/repayWithdrawCollateral.js +328 -0
- package/lib/cjs/transactionPlan/midnight/supplyBlueMakeLend.d.ts +155 -0
- package/lib/cjs/transactionPlan/midnight/supplyBlueMakeLend.js +199 -0
- package/lib/cjs/transactionPlan/midnight/supplyCollateral.d.ts +96 -0
- package/lib/cjs/transactionPlan/midnight/supplyCollateral.js +190 -0
- package/lib/cjs/transactionPlan/midnight/supplyCollateralBatch.d.ts +112 -0
- package/lib/cjs/transactionPlan/midnight/supplyCollateralBatch.js +221 -0
- package/lib/cjs/transactionPlan/midnight/supplyCollateralMakeBorrow.d.ts +129 -0
- package/lib/cjs/transactionPlan/midnight/supplyCollateralMakeBorrow.js +179 -0
- package/lib/cjs/transactionPlan/midnight/supplyCollateralWithNative.d.ts +115 -0
- package/lib/cjs/transactionPlan/midnight/supplyCollateralWithNative.js +259 -0
- package/lib/cjs/transactionPlan/midnight/takeBorrow.d.ts +304 -0
- package/lib/cjs/transactionPlan/midnight/takeBorrow.js +545 -0
- package/lib/cjs/transactionPlan/midnight/takeLend.d.ts +99 -0
- package/lib/cjs/transactionPlan/midnight/takeLend.js +263 -0
- package/lib/cjs/transactionPlan/midnight/takeRepayWithdrawCollateral.d.ts +175 -0
- package/lib/cjs/transactionPlan/midnight/takeRepayWithdrawCollateral.js +440 -0
- package/lib/cjs/transactionPlan/midnight/takeWithdraw.d.ts +139 -0
- package/lib/cjs/transactionPlan/midnight/takeWithdraw.js +240 -0
- package/lib/cjs/transactionPlan/midnight/validation.d.ts +22 -0
- package/lib/cjs/transactionPlan/midnight/validation.js +158 -0
- package/lib/cjs/transactionPlan/midnight/withdrawCollateral.d.ts +130 -0
- package/lib/cjs/transactionPlan/midnight/withdrawCollateral.js +228 -0
- package/lib/cjs/transactionPlan/midnight/withdrawCollateralBatch.d.ts +142 -0
- package/lib/cjs/transactionPlan/midnight/withdrawCollateralBatch.js +232 -0
- package/lib/cjs/transactionPlan/plan.d.ts +48 -14
- package/lib/cjs/transactionPlan/plan.js +103 -18
- package/lib/cjs/transactionPlan/requirements.d.ts +7 -4
- package/lib/cjs/transactionPlan/requirements.js +2 -2
- package/lib/cjs/transactionPlan/serde.d.ts +13 -2
- package/lib/cjs/transactionPlan/serde.js +68 -21
- package/lib/cjs/transactionPlan/types.d.ts +147 -0
- package/lib/cjs/transactionPlan/validateActions.d.ts +3 -1
- package/lib/cjs/transactionPlan/validateActions.js +31 -3
- package/lib/cjs/transactionPlan/validation.d.ts +1 -1
- package/lib/cjs/transactionPlan/validation.js +37 -1
- package/lib/cjs/types/error.d.ts +2 -0
- package/lib/cjs/types/error.js +2 -0
- package/lib/cjs/version.d.ts +1 -1
- package/lib/cjs/version.js +1 -1
- package/lib/esm/actions/midnight/redeem.d.ts +20 -3
- package/lib/esm/actions/midnight/redeem.js +56 -0
- package/lib/esm/actions/midnight/supplyCollateralWithNative.d.ts +24 -1
- package/lib/esm/actions/midnight/supplyCollateralWithNative.js +40 -0
- package/lib/esm/actions/midnight/withdrawCollateral.d.ts +16 -2
- package/lib/esm/actions/midnight/withdrawCollateral.js +25 -1
- package/lib/esm/helpers/callback.d.ts +3 -2
- package/lib/esm/helpers/callback.js +5 -21
- package/lib/esm/helpers/computeMidnightPostWithdrawalCollateral.d.ts +17 -0
- package/lib/esm/helpers/computeMidnightPostWithdrawalCollateral.js +27 -0
- package/lib/esm/helpers/parseMidnightMaker.d.ts +21 -0
- package/lib/esm/helpers/parseMidnightMaker.js +40 -1
- package/lib/esm/helpers/validate.d.ts +49 -1
- package/lib/esm/helpers/validate.js +84 -1
- package/lib/esm/helpers/validateMidnightPublication.d.ts +10 -0
- package/lib/esm/helpers/validateMidnightPublication.js +16 -0
- package/lib/esm/helpers/validateMidnightTakeableOfferFields.d.ts +28 -0
- package/lib/esm/helpers/validateMidnightTakeableOfferFields.js +81 -0
- package/lib/esm/index.d.ts +2 -2
- package/lib/esm/index.js +1 -1
- package/lib/esm/midnight/utils.d.ts +1 -1
- package/lib/esm/midnight/utils.js +1 -1
- package/lib/esm/transactionPlan/blue/withdrawBuyCallback.d.ts +101 -0
- package/lib/esm/transactionPlan/blue/withdrawBuyCallback.js +259 -0
- package/lib/esm/transactionPlan/error.d.ts +27 -0
- package/lib/esm/transactionPlan/error.js +28 -0
- package/lib/esm/transactionPlan/index.d.ts +40 -1
- package/lib/esm/transactionPlan/index.js +20 -1
- package/lib/esm/transactionPlan/midnight/authorization.d.ts +15 -0
- package/lib/esm/transactionPlan/midnight/authorization.js +40 -0
- package/lib/esm/transactionPlan/midnight/cancelOffers.d.ts +80 -0
- package/lib/esm/transactionPlan/midnight/cancelOffers.js +120 -0
- package/lib/esm/transactionPlan/midnight/makeBorrow.d.ts +104 -0
- package/lib/esm/transactionPlan/midnight/makeBorrow.js +123 -0
- package/lib/esm/transactionPlan/midnight/makeLend.d.ts +140 -0
- package/lib/esm/transactionPlan/midnight/makeLend.js +172 -0
- package/lib/esm/transactionPlan/midnight/makeRepay.d.ts +118 -0
- package/lib/esm/transactionPlan/midnight/makeRepay.js +115 -0
- package/lib/esm/transactionPlan/midnight/makeWithdraw.d.ts +104 -0
- package/lib/esm/transactionPlan/midnight/makeWithdraw.js +123 -0
- package/lib/esm/transactionPlan/midnight/makerPublication.d.ts +55 -0
- package/lib/esm/transactionPlan/midnight/makerPublication.js +310 -0
- package/lib/esm/transactionPlan/midnight/market.d.ts +49 -0
- package/lib/esm/transactionPlan/midnight/market.js +112 -0
- package/lib/esm/transactionPlan/midnight/prepare.d.ts +244 -0
- package/lib/esm/transactionPlan/midnight/prepare.js +536 -0
- package/lib/esm/transactionPlan/midnight/publicationState.d.ts +24 -0
- package/lib/esm/transactionPlan/midnight/publicationState.js +47 -0
- package/lib/esm/transactionPlan/midnight/redeem.d.ts +102 -0
- package/lib/esm/transactionPlan/midnight/redeem.js +165 -0
- package/lib/esm/transactionPlan/midnight/reduceOnlySellFeasibility.d.ts +25 -0
- package/lib/esm/transactionPlan/midnight/reduceOnlySellFeasibility.js +47 -0
- package/lib/esm/transactionPlan/midnight/repayWithdrawCollateral.d.ts +162 -0
- package/lib/esm/transactionPlan/midnight/repayWithdrawCollateral.js +323 -0
- package/lib/esm/transactionPlan/midnight/supplyBlueMakeLend.d.ts +155 -0
- package/lib/esm/transactionPlan/midnight/supplyBlueMakeLend.js +196 -0
- package/lib/esm/transactionPlan/midnight/supplyCollateral.d.ts +96 -0
- package/lib/esm/transactionPlan/midnight/supplyCollateral.js +185 -0
- package/lib/esm/transactionPlan/midnight/supplyCollateralBatch.d.ts +112 -0
- package/lib/esm/transactionPlan/midnight/supplyCollateralBatch.js +216 -0
- package/lib/esm/transactionPlan/midnight/supplyCollateralMakeBorrow.d.ts +129 -0
- package/lib/esm/transactionPlan/midnight/supplyCollateralMakeBorrow.js +176 -0
- package/lib/esm/transactionPlan/midnight/supplyCollateralWithNative.d.ts +115 -0
- package/lib/esm/transactionPlan/midnight/supplyCollateralWithNative.js +254 -0
- package/lib/esm/transactionPlan/midnight/takeBorrow.d.ts +304 -0
- package/lib/esm/transactionPlan/midnight/takeBorrow.js +539 -0
- package/lib/esm/transactionPlan/midnight/takeLend.d.ts +99 -0
- package/lib/esm/transactionPlan/midnight/takeLend.js +258 -0
- package/lib/esm/transactionPlan/midnight/takeRepayWithdrawCollateral.d.ts +175 -0
- package/lib/esm/transactionPlan/midnight/takeRepayWithdrawCollateral.js +435 -0
- package/lib/esm/transactionPlan/midnight/takeWithdraw.d.ts +139 -0
- package/lib/esm/transactionPlan/midnight/takeWithdraw.js +236 -0
- package/lib/esm/transactionPlan/midnight/validation.d.ts +22 -0
- package/lib/esm/transactionPlan/midnight/validation.js +151 -0
- package/lib/esm/transactionPlan/midnight/withdrawCollateral.d.ts +130 -0
- package/lib/esm/transactionPlan/midnight/withdrawCollateral.js +223 -0
- package/lib/esm/transactionPlan/midnight/withdrawCollateralBatch.d.ts +142 -0
- package/lib/esm/transactionPlan/midnight/withdrawCollateralBatch.js +227 -0
- package/lib/esm/transactionPlan/plan.d.ts +48 -14
- package/lib/esm/transactionPlan/plan.js +99 -14
- package/lib/esm/transactionPlan/requirements.d.ts +7 -4
- package/lib/esm/transactionPlan/requirements.js +2 -2
- package/lib/esm/transactionPlan/serde.d.ts +13 -2
- package/lib/esm/transactionPlan/serde.js +49 -2
- package/lib/esm/transactionPlan/types.d.ts +147 -0
- package/lib/esm/transactionPlan/validateActions.d.ts +3 -1
- package/lib/esm/transactionPlan/validateActions.js +31 -3
- package/lib/esm/transactionPlan/validation.d.ts +1 -1
- package/lib/esm/transactionPlan/validation.js +38 -2
- package/lib/esm/types/error.d.ts +2 -0
- package/lib/esm/types/error.js +2 -0
- package/lib/esm/version.d.ts +1 -1
- package/lib/esm/version.js +1 -1
- package/package.json +4 -4
|
@@ -0,0 +1,264 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.prepareBlueWithdrawBuyCallback = prepareBlueWithdrawBuyCallback;
|
|
4
|
+
exports.buildBlueWithdrawBuyCallback = buildBlueWithdrawBuyCallback;
|
|
5
|
+
exports.validateBlueWithdrawBuyCallbackPlanAction = validateBlueWithdrawBuyCallbackPlanAction;
|
|
6
|
+
const blue_sdk_1 = require("@morpho-org/blue-sdk");
|
|
7
|
+
const morpho_ts_1 = require("@morpho-org/morpho-ts");
|
|
8
|
+
const viem_1 = require("viem");
|
|
9
|
+
const actions_1 = require("viem/actions");
|
|
10
|
+
const abis_js_1 = require("../../abis.js");
|
|
11
|
+
const withdrawBuyCallback_internal_js_1 = require("../../actions/blue/withdrawBuyCallback.internal.js");
|
|
12
|
+
const withdrawBuyCallback_js_1 = require("../../actions/blue/withdrawBuyCallback.js");
|
|
13
|
+
const validateClientChainId_js_1 = require("../../actions/requirements/validateClientChainId.js");
|
|
14
|
+
const index_js_1 = require("../../helpers/index.js");
|
|
15
|
+
const validate_js_1 = require("../../helpers/validate.js");
|
|
16
|
+
const index_js_2 = require("../../types/index.js");
|
|
17
|
+
const error_js_1 = require("../error.js");
|
|
18
|
+
const intent_js_1 = require("../intent.js");
|
|
19
|
+
const validation_js_1 = require("../validation.js");
|
|
20
|
+
const prepare_js_1 = require("./prepare.js");
|
|
21
|
+
const MARKET_STATE_FIELDS = [
|
|
22
|
+
"totalSupplyAssets",
|
|
23
|
+
"totalSupplyShares",
|
|
24
|
+
"totalBorrowAssets",
|
|
25
|
+
"totalBorrowShares",
|
|
26
|
+
"lastUpdate",
|
|
27
|
+
"fee",
|
|
28
|
+
"price",
|
|
29
|
+
"rateAtTarget",
|
|
30
|
+
];
|
|
31
|
+
/**
|
|
32
|
+
* Prepares a direct Morpho Blue withdrawal of a BlueBuyCallback's whole supply position to its owner.
|
|
33
|
+
* The call is `withdraw(marketParams, 0, shares, callbackAddress, account)` on Morpho Blue, not
|
|
34
|
+
* BlueBundlesV1: the callback authorizes its owner on Blue at construction, so the plan has no
|
|
35
|
+
* approval, authorization step or signature request. Preparation reads the chain and rejects a
|
|
36
|
+
* callback the registered factory did not create, another owner, or a revoked Blue authorization.
|
|
37
|
+
* The plan carries no referral fee, and `expiresAt` is plan metadata, not an onchain deadline.
|
|
38
|
+
* @param client - Viem client on the requested chain.
|
|
39
|
+
* @param params.chainId - Chain containing Morpho Blue and the registered `midnightBlueBuyCallbackFactory`.
|
|
40
|
+
* @param params.account - Non-zero callback owner that sends the transaction and receives the loan assets.
|
|
41
|
+
* @param params.marketId - Market ID matching both snapshots and the market tuple.
|
|
42
|
+
* @param params.marketData.chainId - Chain on which the market snapshot was fetched; must equal `chainId`.
|
|
43
|
+
* @param params.marketData.market - Caller-fetched `Market` snapshot used to fix the market tuple; its state must equal the position snapshot's market. Never stored in the plan.
|
|
44
|
+
* @param params.callbackAddress - BlueBuyCallback whose supply position is withdrawn.
|
|
45
|
+
* @param params.positionData.chainId - Position snapshot's chain; must equal `chainId`.
|
|
46
|
+
* @param params.positionData.position - Caller-fetched `AccrualPosition` of `callbackAddress` on `marketId`; all its supply shares are withdrawn and their assets must not exceed that market's liquidity.
|
|
47
|
+
* @param params.now - Optional reference timestamp in seconds, normally the latest block timestamp; defaults to the device clock.
|
|
48
|
+
* @param params.expiresAt - Optional Unix expiry in safe-integer seconds, later than `now`; defaults to `now + 2h`. Plan metadata only.
|
|
49
|
+
* @param params.calldataOrigin - Optional non-empty, even-length hex bytes appended to the withdrawal calldata; omitted by default.
|
|
50
|
+
* @returns A deep-frozen, data-only `{ version, chainId, account, expiresAt, steps, signatureRequests, calldataOrigin? }` plan with one `blueWithdrawBuyCallback` step and no signature requests.
|
|
51
|
+
* @throws {BlueSnapshotChainMismatchError} when a market or position snapshot's chain differs from `chainId`.
|
|
52
|
+
* @throws {MarketIdMismatchError} when a snapshot's ID differs from `marketId` or does not hash from its market tuple.
|
|
53
|
+
* @throws {BlueSnapshotStateMismatchError} when the market snapshot's state differs from the position snapshot's market.
|
|
54
|
+
* @throws {MissingAccrualPositionError} when no position snapshot is provided.
|
|
55
|
+
* @throws {AccrualPositionUserMismatchError} when the position belongs to another address than `callbackAddress`.
|
|
56
|
+
* @throws {ZeroAccountError} when `account` is the zero address.
|
|
57
|
+
* @throws {InvalidTransactionPlanError} when `account` or `callbackAddress` is not a checksum-valid address, or `calldataOrigin` exceeds 1 MiB.
|
|
58
|
+
* @throws {NonIntegerInputError} when `expiresAt` is not a safe integer.
|
|
59
|
+
* @throws {NonPositiveInputError} when `expiresAt` is not positive.
|
|
60
|
+
* @throws {ExpiredDeadlineError} when `expiresAt` is at or before `now`.
|
|
61
|
+
* @throws {InvalidCalldataOriginError} when `calldataOrigin` is empty, malformed or has an odd number of hex digits.
|
|
62
|
+
* @throws {EmptyBlueSupplyPositionError} when the callback holds no supply shares.
|
|
63
|
+
* @throws {InsufficientBlueLiquidityError} when the position's supply assets exceed the snapshot market's liquidity.
|
|
64
|
+
* @throws {InputExceedsMaxError} when the supply shares exceed `uint256`.
|
|
65
|
+
* @throws {UnsupportedChainIdError} when `chainId` is absent from the registry.
|
|
66
|
+
* @throws {UnknownAddressError} when Morpho Blue or `midnightBlueBuyCallbackFactory` is not registered on `chainId`.
|
|
67
|
+
* @throws {ChainIdMismatchError} when the client declares another chain (checked before any snapshot) or its transport serves one.
|
|
68
|
+
* @throws {MissingContractCodeError} when Morpho Blue or the factory has no deployed code.
|
|
69
|
+
* @throws {NotBlueBuyCallbackError} when the factory did not create `callbackAddress`.
|
|
70
|
+
* @throws {BlueBuyCallbackOwnerMismatchError} when the callback's `OWNER()` is not `account`.
|
|
71
|
+
* @throws {BlueBuyCallbackUnauthorizedError} when Morpho Blue does not authorize `account` for the callback.
|
|
72
|
+
* @throws {viem.BaseError} when a chain, bytecode, factory, owner or authorization read fails.
|
|
73
|
+
* @example
|
|
74
|
+
* ```ts
|
|
75
|
+
* import { markets } from "@morpho-org/morpho-test";
|
|
76
|
+
* import { buildTransactions, prepareBlueWithdrawBuyCallback } from "@morpho-org/morpho-sdk";
|
|
77
|
+
* import { fetchBlueAccrualPosition } from "@morpho-org/morpho-sdk/fetch";
|
|
78
|
+
* import { createPublicClient, type Address, http } from "viem";
|
|
79
|
+
* import { mainnet } from "viem/chains";
|
|
80
|
+
*
|
|
81
|
+
* const client = createPublicClient({ chain: mainnet, transport: http() });
|
|
82
|
+
* declare const account: Address; // Owner of the BlueBuyCallback.
|
|
83
|
+
* declare const callbackAddress: Address; // BlueBuyCallback created by the registered factory.
|
|
84
|
+
* const position = await fetchBlueAccrualPosition(callbackAddress, markets[mainnet.id].usdc_wbtc.id, client);
|
|
85
|
+
* const plan = await prepareBlueWithdrawBuyCallback(client, {
|
|
86
|
+
* chainId: mainnet.id, account, callbackAddress, marketId: position.market.id,
|
|
87
|
+
* marketData: { chainId: mainnet.id, market: position.market },
|
|
88
|
+
* positionData: { chainId: mainnet.id, position },
|
|
89
|
+
* now: (await client.getBlock()).timestamp,
|
|
90
|
+
* });
|
|
91
|
+
* const [transaction] = buildTransactions(plan);
|
|
92
|
+
* // Submit transaction from account; it calls Morpho Blue directly.
|
|
93
|
+
* ```
|
|
94
|
+
* @experimental TransactionPlan is in beta; breaking changes may ship in minor releases.
|
|
95
|
+
*/
|
|
96
|
+
async function prepareBlueWithdrawBuyCallback(client, params) {
|
|
97
|
+
const { chainId, account, callbackAddress, marketId, marketData } = params;
|
|
98
|
+
const snapshot = params.positionData;
|
|
99
|
+
// Reject a client declaring another chain first, as the entity does.
|
|
100
|
+
(0, index_js_1.validateChainId)(client.chain?.id, chainId);
|
|
101
|
+
(0, validation_js_1.validatePlanField)(callbackAddress, {
|
|
102
|
+
path: "$.callbackAddress",
|
|
103
|
+
type: "address",
|
|
104
|
+
});
|
|
105
|
+
// Reject mismatched snapshots before deriving the withdrawal or reading chain state.
|
|
106
|
+
(0, prepare_js_1.validateBlueMarketSnapshot)(marketData, { chainId, marketId });
|
|
107
|
+
if (snapshot == null) {
|
|
108
|
+
throw new index_js_2.MissingAccrualPositionError(marketId);
|
|
109
|
+
}
|
|
110
|
+
if (snapshot.chainId !== chainId) {
|
|
111
|
+
throw new error_js_1.BlueSnapshotChainMismatchError(snapshot.chainId, chainId);
|
|
112
|
+
}
|
|
113
|
+
const { position } = snapshot;
|
|
114
|
+
if (!(0, morpho_ts_1.isHexEqual)(position.marketId, marketId)) {
|
|
115
|
+
throw new index_js_2.MarketIdMismatchError(position.marketId, marketId);
|
|
116
|
+
}
|
|
117
|
+
if (!(0, morpho_ts_1.isHexEqual)(position.market.id, marketId)) {
|
|
118
|
+
throw new index_js_2.MarketIdMismatchError(position.market.id, marketId);
|
|
119
|
+
}
|
|
120
|
+
(0, validate_js_1.validateMarketParamsId)(position.market.params);
|
|
121
|
+
if (!(0, viem_1.isAddressEqual)(position.user, callbackAddress)) {
|
|
122
|
+
throw new index_js_2.AccrualPositionUserMismatchError(position.user, callbackAddress);
|
|
123
|
+
}
|
|
124
|
+
// Bind the withdrawal to one market state: the position's market bounds the liquidity check.
|
|
125
|
+
for (const field of MARKET_STATE_FIELDS) {
|
|
126
|
+
if (position.market[field] !== marketData.market[field]) {
|
|
127
|
+
throw new error_js_1.BlueSnapshotStateMismatchError({
|
|
128
|
+
field,
|
|
129
|
+
positionValue: position.market[field],
|
|
130
|
+
marketValue: marketData.market[field],
|
|
131
|
+
});
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
const intent = (0, intent_js_1.resolveIntent)(params, params.now ?? morpho_ts_1.Time.timestamp());
|
|
135
|
+
const market = marketData.market.id;
|
|
136
|
+
const shares = position.supplyShares;
|
|
137
|
+
if (shares === 0n) {
|
|
138
|
+
throw new index_js_2.EmptyBlueSupplyPositionError({ market, user: callbackAddress });
|
|
139
|
+
}
|
|
140
|
+
const assets = position.supplyAssets;
|
|
141
|
+
const liquidity = position.market.liquidity;
|
|
142
|
+
if (assets > liquidity) {
|
|
143
|
+
throw new index_js_2.InsufficientBlueLiquidityError({ market, assets, liquidity });
|
|
144
|
+
}
|
|
145
|
+
const { loanToken, collateralToken, oracle, irm, lltv } = marketData.market.params;
|
|
146
|
+
// Validate shares, the market tuple and the Blue registration before any RPC read.
|
|
147
|
+
(0, withdrawBuyCallback_internal_js_1.parseBlueWithdrawBuyCallback)({
|
|
148
|
+
market: { chainId, marketParams: marketData.market.params },
|
|
149
|
+
args: { callbackAddress, userAddress: account, shares },
|
|
150
|
+
});
|
|
151
|
+
const blue = (0, morpho_ts_1.getChainAddress)(chainId, "blue");
|
|
152
|
+
const factory = (0, morpho_ts_1.getChainAddress)(chainId, "midnightBlueBuyCallbackFactory");
|
|
153
|
+
await (0, validateClientChainId_js_1.validateClientChainId)(client, chainId);
|
|
154
|
+
const targets = [
|
|
155
|
+
{ role: "blue", address: blue },
|
|
156
|
+
{ role: "midnightBlueBuyCallbackFactory", address: factory },
|
|
157
|
+
];
|
|
158
|
+
// Start every read, then consume them in target order so a stalled or failed
|
|
159
|
+
// later read cannot hide Blue's missing code, as `assertRegistryTargetsHaveCode` does.
|
|
160
|
+
const reads = targets.map(({ address }) => {
|
|
161
|
+
const read = (0, actions_1.getBytecode)(client, { address });
|
|
162
|
+
read.catch(() => undefined);
|
|
163
|
+
return read;
|
|
164
|
+
});
|
|
165
|
+
for (const [index, { role, address }] of targets.entries()) {
|
|
166
|
+
const bytecode = await reads[index];
|
|
167
|
+
if (bytecode === undefined || bytecode === "0x") {
|
|
168
|
+
throw new index_js_2.MissingContractCodeError(address, chainId, role);
|
|
169
|
+
}
|
|
170
|
+
}
|
|
171
|
+
// Check the factory first: OWNER() on an arbitrary address can revert or lie.
|
|
172
|
+
const isBlueBuyCallback = await (0, actions_1.readContract)(client, {
|
|
173
|
+
address: factory,
|
|
174
|
+
abi: abis_js_1.midnightBlueBuyCallbackFactoryAbi,
|
|
175
|
+
functionName: "isBlueBuyCallback",
|
|
176
|
+
args: [callbackAddress],
|
|
177
|
+
});
|
|
178
|
+
if (!isBlueBuyCallback) {
|
|
179
|
+
throw new index_js_2.NotBlueBuyCallbackError(callbackAddress);
|
|
180
|
+
}
|
|
181
|
+
const [owner, isAuthorized] = await Promise.all([
|
|
182
|
+
(0, actions_1.readContract)(client, {
|
|
183
|
+
address: callbackAddress,
|
|
184
|
+
abi: abis_js_1.midnightBlueBuyCallbackAbi,
|
|
185
|
+
functionName: "OWNER",
|
|
186
|
+
}),
|
|
187
|
+
(0, actions_1.readContract)(client, {
|
|
188
|
+
address: blue,
|
|
189
|
+
abi: abis_js_1.blueAbi,
|
|
190
|
+
functionName: "isAuthorized",
|
|
191
|
+
args: [callbackAddress, account],
|
|
192
|
+
}),
|
|
193
|
+
]);
|
|
194
|
+
if (!(0, viem_1.isAddressEqual)(owner, account)) {
|
|
195
|
+
throw new index_js_2.BlueBuyCallbackOwnerMismatchError({
|
|
196
|
+
callback: callbackAddress,
|
|
197
|
+
owner,
|
|
198
|
+
userAddress: account,
|
|
199
|
+
});
|
|
200
|
+
}
|
|
201
|
+
if (!isAuthorized) {
|
|
202
|
+
throw new index_js_2.BlueBuyCallbackUnauthorizedError({
|
|
203
|
+
callback: callbackAddress,
|
|
204
|
+
userAddress: account,
|
|
205
|
+
});
|
|
206
|
+
}
|
|
207
|
+
return (0, morpho_ts_1.deepFreeze)({
|
|
208
|
+
version: 2,
|
|
209
|
+
chainId,
|
|
210
|
+
account,
|
|
211
|
+
expiresAt: intent.expiresAt,
|
|
212
|
+
...(intent.calldataOrigin && { calldataOrigin: intent.calldataOrigin }),
|
|
213
|
+
steps: [
|
|
214
|
+
{
|
|
215
|
+
id: "blueWithdrawBuyCallback",
|
|
216
|
+
label: "Withdraw BlueBuyCallback supply from Blue",
|
|
217
|
+
action: {
|
|
218
|
+
type: "blueWithdrawBuyCallback",
|
|
219
|
+
inputs: {
|
|
220
|
+
chainId,
|
|
221
|
+
account,
|
|
222
|
+
marketParams: { loanToken, collateralToken, oracle, irm, lltv },
|
|
223
|
+
callbackAddress,
|
|
224
|
+
shares,
|
|
225
|
+
},
|
|
226
|
+
},
|
|
227
|
+
},
|
|
228
|
+
],
|
|
229
|
+
signatureRequests: [],
|
|
230
|
+
});
|
|
231
|
+
}
|
|
232
|
+
/** @internal Encodes the stored callback withdrawal through the same action as the entity handle. */
|
|
233
|
+
function buildBlueWithdrawBuyCallback(action) {
|
|
234
|
+
const { chainId, account, marketParams, callbackAddress, shares } = action.inputs;
|
|
235
|
+
return (0, withdrawBuyCallback_js_1.blueWithdrawBuyCallback)({
|
|
236
|
+
market: {
|
|
237
|
+
chainId,
|
|
238
|
+
marketParams: {
|
|
239
|
+
...marketParams,
|
|
240
|
+
id: blue_sdk_1.MarketUtils.getMarketId(marketParams),
|
|
241
|
+
liquidationIncentiveFactor: blue_sdk_1.MarketUtils.getLiquidationIncentiveFactor(marketParams),
|
|
242
|
+
},
|
|
243
|
+
},
|
|
244
|
+
args: { callbackAddress, userAddress: account, shares },
|
|
245
|
+
});
|
|
246
|
+
}
|
|
247
|
+
/** @internal Validates the stored callback withdrawal's structural inputs. */
|
|
248
|
+
function validateBlueWithdrawBuyCallbackPlanAction(action, path) {
|
|
249
|
+
const inputs = (0, validation_js_1.getPlanObject)(action.inputs, `${path}.inputs`);
|
|
250
|
+
(0, validation_js_1.validatePlanFields)(inputs, {
|
|
251
|
+
path: `${path}.inputs`,
|
|
252
|
+
fields: { callbackAddress: "address", shares: "uint256 bigint" },
|
|
253
|
+
});
|
|
254
|
+
(0, validation_js_1.validatePlanFields)((0, validation_js_1.getPlanObject)(inputs.marketParams, `${path}.inputs.marketParams`), {
|
|
255
|
+
path: `${path}.inputs.marketParams`,
|
|
256
|
+
fields: {
|
|
257
|
+
loanToken: "address",
|
|
258
|
+
collateralToken: "address",
|
|
259
|
+
oracle: "address",
|
|
260
|
+
irm: "address",
|
|
261
|
+
lltv: "uint256 bigint",
|
|
262
|
+
},
|
|
263
|
+
});
|
|
264
|
+
}
|
|
@@ -195,3 +195,30 @@ export declare class NonIntegerInputError extends Error {
|
|
|
195
195
|
*/
|
|
196
196
|
constructor(field: string, value: number);
|
|
197
197
|
}
|
|
198
|
+
/**
|
|
199
|
+
* @experimental TransactionPlan is in beta; breaking changes may ship in minor releases.
|
|
200
|
+
* A reduce-only Midnight withdrawal needs more credit units than the position's accrued credit
|
|
201
|
+
* holds, so no quote or market liquidity can reach the target.
|
|
202
|
+
*/
|
|
203
|
+
export declare class MidnightTakeCreditInsufficientError extends Error {
|
|
204
|
+
/** Position credit accrued to the reference timestamp. */
|
|
205
|
+
readonly credit: bigint;
|
|
206
|
+
/** Credit units the target needs. */
|
|
207
|
+
readonly requiredUnits: bigint;
|
|
208
|
+
/**
|
|
209
|
+
* @param params - Accrued credit, the units the target needs and optional underlying error.
|
|
210
|
+
* @param params.credit - Position credit accrued to the reference timestamp.
|
|
211
|
+
* @param params.requiredUnits - Credit units the target needs.
|
|
212
|
+
* @param params.cause - Offer-shortfall error that the credit shortfall replaces.
|
|
213
|
+
* @example
|
|
214
|
+
* ```ts
|
|
215
|
+
* import { MidnightTakeCreditInsufficientError } from "@morpho-org/morpho-sdk";
|
|
216
|
+
* const error = new MidnightTakeCreditInsufficientError({ credit: 40n, requiredUnits: 50n });
|
|
217
|
+
* ```
|
|
218
|
+
*/
|
|
219
|
+
constructor({ credit, requiredUnits, cause, }: {
|
|
220
|
+
readonly credit: bigint;
|
|
221
|
+
readonly requiredUnits: bigint;
|
|
222
|
+
readonly cause?: unknown;
|
|
223
|
+
});
|
|
224
|
+
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.NonIntegerInputError = exports.InvalidCalldataOriginError = exports.TransactionPlanSignatureMismatchError = exports.IncompleteTransactionPlanError = exports.InvalidTransactionPlanError = exports.UnsupportedTransactionPlanActionError = exports.UnsupportedTransactionPlanVersionError = exports.ZeroAccountError = exports.BlueSnapshotStateMismatchError = exports.BlueSnapshotChainMismatchError = void 0;
|
|
3
|
+
exports.MidnightTakeCreditInsufficientError = exports.NonIntegerInputError = exports.InvalidCalldataOriginError = exports.TransactionPlanSignatureMismatchError = exports.IncompleteTransactionPlanError = exports.InvalidTransactionPlanError = exports.UnsupportedTransactionPlanActionError = exports.UnsupportedTransactionPlanVersionError = exports.ZeroAccountError = exports.BlueSnapshotStateMismatchError = exports.BlueSnapshotChainMismatchError = void 0;
|
|
4
4
|
/**
|
|
5
5
|
* @experimental TransactionPlan is in beta; breaking changes may ship in minor releases.
|
|
6
6
|
* A caller-provided Blue market or position snapshot was read on a different chain.
|
|
@@ -245,3 +245,32 @@ class NonIntegerInputError extends Error {
|
|
|
245
245
|
}
|
|
246
246
|
}
|
|
247
247
|
exports.NonIntegerInputError = NonIntegerInputError;
|
|
248
|
+
/**
|
|
249
|
+
* @experimental TransactionPlan is in beta; breaking changes may ship in minor releases.
|
|
250
|
+
* A reduce-only Midnight withdrawal needs more credit units than the position's accrued credit
|
|
251
|
+
* holds, so no quote or market liquidity can reach the target.
|
|
252
|
+
*/
|
|
253
|
+
class MidnightTakeCreditInsufficientError extends Error {
|
|
254
|
+
/** Position credit accrued to the reference timestamp. */
|
|
255
|
+
credit;
|
|
256
|
+
/** Credit units the target needs. */
|
|
257
|
+
requiredUnits;
|
|
258
|
+
/**
|
|
259
|
+
* @param params - Accrued credit, the units the target needs and optional underlying error.
|
|
260
|
+
* @param params.credit - Position credit accrued to the reference timestamp.
|
|
261
|
+
* @param params.requiredUnits - Credit units the target needs.
|
|
262
|
+
* @param params.cause - Offer-shortfall error that the credit shortfall replaces.
|
|
263
|
+
* @example
|
|
264
|
+
* ```ts
|
|
265
|
+
* import { MidnightTakeCreditInsufficientError } from "@morpho-org/morpho-sdk";
|
|
266
|
+
* const error = new MidnightTakeCreditInsufficientError({ credit: 40n, requiredUnits: 50n });
|
|
267
|
+
* ```
|
|
268
|
+
*/
|
|
269
|
+
constructor({ credit, requiredUnits, cause, }) {
|
|
270
|
+
super(`Midnight position credit "${credit}" is below the "${requiredUnits}" units the target needs. Lower the target to at most the position's credit.`, { cause });
|
|
271
|
+
this.credit = credit;
|
|
272
|
+
this.requiredUnits = requiredUnits;
|
|
273
|
+
this.name = "MidnightTakeCreditInsufficientError";
|
|
274
|
+
}
|
|
275
|
+
}
|
|
276
|
+
exports.MidnightTakeCreditInsufficientError = MidnightTakeCreditInsufficientError;
|
|
@@ -16,10 +16,49 @@ export type { BlueSupplyCollateralBorrowPlanParams } from "./blue/supplyCollater
|
|
|
16
16
|
export { prepareBlueSupplyCollateralBorrow } from "./blue/supplyCollateralBorrow.js";
|
|
17
17
|
export type { BlueWithdrawPlanParams } from "./blue/withdraw.js";
|
|
18
18
|
export { prepareBlueWithdraw } from "./blue/withdraw.js";
|
|
19
|
+
export type { BlueWithdrawBuyCallbackPlanParams } from "./blue/withdrawBuyCallback.js";
|
|
20
|
+
export { prepareBlueWithdrawBuyCallback } from "./blue/withdrawBuyCallback.js";
|
|
19
21
|
export type { BlueWithdrawCollateralPlanParams } from "./blue/withdrawCollateral.js";
|
|
20
22
|
export { prepareBlueWithdrawCollateral } from "./blue/withdrawCollateral.js";
|
|
21
|
-
export { BlueSnapshotChainMismatchError, BlueSnapshotStateMismatchError, IncompleteTransactionPlanError, InvalidCalldataOriginError, InvalidTransactionPlanError, NonIntegerInputError, TransactionPlanSignatureMismatchError, UnsupportedTransactionPlanActionError, UnsupportedTransactionPlanVersionError, ZeroAccountError, } from "./error.js";
|
|
23
|
+
export { BlueSnapshotChainMismatchError, BlueSnapshotStateMismatchError, IncompleteTransactionPlanError, InvalidCalldataOriginError, InvalidTransactionPlanError, MidnightTakeCreditInsufficientError, NonIntegerInputError, TransactionPlanSignatureMismatchError, UnsupportedTransactionPlanActionError, UnsupportedTransactionPlanVersionError, ZeroAccountError, } from "./error.js";
|
|
22
24
|
export type { Funding, IntentParams, ReferralFee, } from "./intent.js";
|
|
25
|
+
export type { MidnightCancelOffersPlanParams } from "./midnight/cancelOffers.js";
|
|
26
|
+
export { prepareMidnightCancelOffers } from "./midnight/cancelOffers.js";
|
|
27
|
+
export type { MidnightMakeBorrowPlanParams } from "./midnight/makeBorrow.js";
|
|
28
|
+
export { prepareMidnightMakeBorrow } from "./midnight/makeBorrow.js";
|
|
29
|
+
export type { MidnightMakeLendPlanParams } from "./midnight/makeLend.js";
|
|
30
|
+
export { prepareMidnightMakeLend } from "./midnight/makeLend.js";
|
|
31
|
+
export type { MidnightMakeRepayPlanParams } from "./midnight/makeRepay.js";
|
|
32
|
+
export { prepareMidnightMakeRepay } from "./midnight/makeRepay.js";
|
|
33
|
+
export type { MidnightMakerPublicationPlanParams } from "./midnight/makerPublication.js";
|
|
34
|
+
export type { MidnightMakeWithdrawPlanParams } from "./midnight/makeWithdraw.js";
|
|
35
|
+
export { prepareMidnightMakeWithdraw } from "./midnight/makeWithdraw.js";
|
|
36
|
+
export type { MidnightRedeemPlanParams } from "./midnight/redeem.js";
|
|
37
|
+
export { prepareMidnightRedeem } from "./midnight/redeem.js";
|
|
38
|
+
export type { MidnightRepayWithdrawCollateralPlanParams } from "./midnight/repayWithdrawCollateral.js";
|
|
39
|
+
export { prepareMidnightRepayWithdrawCollateral } from "./midnight/repayWithdrawCollateral.js";
|
|
40
|
+
export type { MidnightSupplyBlueMakeLendPlanParams } from "./midnight/supplyBlueMakeLend.js";
|
|
41
|
+
export { prepareMidnightSupplyBlueMakeLend } from "./midnight/supplyBlueMakeLend.js";
|
|
42
|
+
export type { MidnightSupplyCollateralPlanParams } from "./midnight/supplyCollateral.js";
|
|
43
|
+
export { prepareMidnightSupplyCollateral } from "./midnight/supplyCollateral.js";
|
|
44
|
+
export type { MidnightSupplyCollateralBatchPlanParams } from "./midnight/supplyCollateralBatch.js";
|
|
45
|
+
export { prepareMidnightSupplyCollateralBatch } from "./midnight/supplyCollateralBatch.js";
|
|
46
|
+
export type { MidnightSupplyCollateralMakeBorrowPlanParams } from "./midnight/supplyCollateralMakeBorrow.js";
|
|
47
|
+
export { prepareMidnightSupplyCollateralMakeBorrow } from "./midnight/supplyCollateralMakeBorrow.js";
|
|
48
|
+
export type { MidnightSupplyCollateralWithNativePlanParams } from "./midnight/supplyCollateralWithNative.js";
|
|
49
|
+
export { prepareMidnightSupplyCollateralWithNative } from "./midnight/supplyCollateralWithNative.js";
|
|
50
|
+
export type { MidnightSupplyCollateralTakeBorrowPlanParams, MidnightTakeBorrowPlanParams, } from "./midnight/takeBorrow.js";
|
|
51
|
+
export { prepareMidnightSupplyCollateralTakeBorrow, prepareMidnightTakeBorrow, } from "./midnight/takeBorrow.js";
|
|
52
|
+
export type { MidnightTakeLendPlanParams } from "./midnight/takeLend.js";
|
|
53
|
+
export { prepareMidnightTakeLend } from "./midnight/takeLend.js";
|
|
54
|
+
export type { MidnightTakeRepayWithdrawCollateralPlanParams } from "./midnight/takeRepayWithdrawCollateral.js";
|
|
55
|
+
export { prepareMidnightTakeRepayWithdrawCollateral } from "./midnight/takeRepayWithdrawCollateral.js";
|
|
56
|
+
export type { MidnightTakeWithdrawPlanParams } from "./midnight/takeWithdraw.js";
|
|
57
|
+
export { prepareMidnightTakeWithdraw } from "./midnight/takeWithdraw.js";
|
|
58
|
+
export type { MidnightWithdrawCollateralPlanParams } from "./midnight/withdrawCollateral.js";
|
|
59
|
+
export { prepareMidnightWithdrawCollateral } from "./midnight/withdrawCollateral.js";
|
|
60
|
+
export type { MidnightWithdrawCollateralBatchPlanParams } from "./midnight/withdrawCollateralBatch.js";
|
|
61
|
+
export { prepareMidnightWithdrawCollateralBatch } from "./midnight/withdrawCollateralBatch.js";
|
|
23
62
|
export { applySignatures, buildTransaction, buildTransactions, getPendingSignatureRequests, } from "./plan.js";
|
|
24
63
|
export { parseTransactionPlan, serializeTransactionPlan } from "./serde.js";
|
|
25
64
|
export type { Action, SignatureRequest, Step, TransactionPlan, } from "./types.js";
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
3
|
+
exports.prepareVaultV1MigrateToV2 = exports.prepareVaultV1InKindRedeem = exports.prepareVaultV1Deposit = exports.serializeTransactionPlan = exports.parseTransactionPlan = exports.getPendingSignatureRequests = exports.buildTransactions = exports.buildTransaction = exports.applySignatures = exports.prepareMidnightWithdrawCollateralBatch = exports.prepareMidnightWithdrawCollateral = exports.prepareMidnightTakeWithdraw = exports.prepareMidnightTakeRepayWithdrawCollateral = exports.prepareMidnightTakeLend = exports.prepareMidnightTakeBorrow = exports.prepareMidnightSupplyCollateralTakeBorrow = exports.prepareMidnightSupplyCollateralWithNative = exports.prepareMidnightSupplyCollateralMakeBorrow = exports.prepareMidnightSupplyCollateralBatch = exports.prepareMidnightSupplyCollateral = exports.prepareMidnightSupplyBlueMakeLend = exports.prepareMidnightRepayWithdrawCollateral = exports.prepareMidnightRedeem = exports.prepareMidnightMakeWithdraw = exports.prepareMidnightMakeRepay = exports.prepareMidnightMakeLend = exports.prepareMidnightMakeBorrow = exports.prepareMidnightCancelOffers = exports.ZeroAccountError = exports.UnsupportedTransactionPlanVersionError = exports.UnsupportedTransactionPlanActionError = exports.TransactionPlanSignatureMismatchError = exports.NonIntegerInputError = exports.MidnightTakeCreditInsufficientError = exports.InvalidTransactionPlanError = exports.InvalidCalldataOriginError = exports.IncompleteTransactionPlanError = exports.BlueSnapshotStateMismatchError = exports.BlueSnapshotChainMismatchError = exports.prepareBlueWithdrawCollateral = exports.prepareBlueWithdrawBuyCallback = exports.prepareBlueWithdraw = exports.prepareBlueSupplyCollateralBorrow = exports.prepareBlueSupplyCollateral = exports.prepareBlueSupply = exports.prepareBlueRepayWithdrawCollateral = exports.prepareBlueRepay = exports.prepareBlueRefinance = exports.validateBlueMarketSnapshot = exports.prepareBlueBorrow = void 0;
|
|
4
|
+
exports.prepareVaultV2Withdraw = exports.prepareVaultV2Redeem = exports.prepareVaultV2InKindRedeem = exports.prepareVaultV2ForceWithdraw = exports.prepareVaultV2ForceRedeem = exports.prepareVaultV2Deposit = exports.prepareVaultV1Withdraw = exports.prepareVaultV1Redeem = void 0;
|
|
4
5
|
var borrow_js_1 = require("./blue/borrow.js");
|
|
5
6
|
Object.defineProperty(exports, "prepareBlueBorrow", { enumerable: true, get: function () { return borrow_js_1.prepareBlueBorrow; } });
|
|
6
7
|
var prepare_js_1 = require("./blue/prepare.js");
|
|
@@ -19,6 +20,8 @@ var supplyCollateralBorrow_js_1 = require("./blue/supplyCollateralBorrow.js");
|
|
|
19
20
|
Object.defineProperty(exports, "prepareBlueSupplyCollateralBorrow", { enumerable: true, get: function () { return supplyCollateralBorrow_js_1.prepareBlueSupplyCollateralBorrow; } });
|
|
20
21
|
var withdraw_js_1 = require("./blue/withdraw.js");
|
|
21
22
|
Object.defineProperty(exports, "prepareBlueWithdraw", { enumerable: true, get: function () { return withdraw_js_1.prepareBlueWithdraw; } });
|
|
23
|
+
var withdrawBuyCallback_js_1 = require("./blue/withdrawBuyCallback.js");
|
|
24
|
+
Object.defineProperty(exports, "prepareBlueWithdrawBuyCallback", { enumerable: true, get: function () { return withdrawBuyCallback_js_1.prepareBlueWithdrawBuyCallback; } });
|
|
22
25
|
var withdrawCollateral_js_1 = require("./blue/withdrawCollateral.js");
|
|
23
26
|
Object.defineProperty(exports, "prepareBlueWithdrawCollateral", { enumerable: true, get: function () { return withdrawCollateral_js_1.prepareBlueWithdrawCollateral; } });
|
|
24
27
|
var error_js_1 = require("./error.js");
|
|
@@ -27,11 +30,49 @@ Object.defineProperty(exports, "BlueSnapshotStateMismatchError", { enumerable: t
|
|
|
27
30
|
Object.defineProperty(exports, "IncompleteTransactionPlanError", { enumerable: true, get: function () { return error_js_1.IncompleteTransactionPlanError; } });
|
|
28
31
|
Object.defineProperty(exports, "InvalidCalldataOriginError", { enumerable: true, get: function () { return error_js_1.InvalidCalldataOriginError; } });
|
|
29
32
|
Object.defineProperty(exports, "InvalidTransactionPlanError", { enumerable: true, get: function () { return error_js_1.InvalidTransactionPlanError; } });
|
|
33
|
+
Object.defineProperty(exports, "MidnightTakeCreditInsufficientError", { enumerable: true, get: function () { return error_js_1.MidnightTakeCreditInsufficientError; } });
|
|
30
34
|
Object.defineProperty(exports, "NonIntegerInputError", { enumerable: true, get: function () { return error_js_1.NonIntegerInputError; } });
|
|
31
35
|
Object.defineProperty(exports, "TransactionPlanSignatureMismatchError", { enumerable: true, get: function () { return error_js_1.TransactionPlanSignatureMismatchError; } });
|
|
32
36
|
Object.defineProperty(exports, "UnsupportedTransactionPlanActionError", { enumerable: true, get: function () { return error_js_1.UnsupportedTransactionPlanActionError; } });
|
|
33
37
|
Object.defineProperty(exports, "UnsupportedTransactionPlanVersionError", { enumerable: true, get: function () { return error_js_1.UnsupportedTransactionPlanVersionError; } });
|
|
34
38
|
Object.defineProperty(exports, "ZeroAccountError", { enumerable: true, get: function () { return error_js_1.ZeroAccountError; } });
|
|
39
|
+
var cancelOffers_js_1 = require("./midnight/cancelOffers.js");
|
|
40
|
+
Object.defineProperty(exports, "prepareMidnightCancelOffers", { enumerable: true, get: function () { return cancelOffers_js_1.prepareMidnightCancelOffers; } });
|
|
41
|
+
var makeBorrow_js_1 = require("./midnight/makeBorrow.js");
|
|
42
|
+
Object.defineProperty(exports, "prepareMidnightMakeBorrow", { enumerable: true, get: function () { return makeBorrow_js_1.prepareMidnightMakeBorrow; } });
|
|
43
|
+
var makeLend_js_1 = require("./midnight/makeLend.js");
|
|
44
|
+
Object.defineProperty(exports, "prepareMidnightMakeLend", { enumerable: true, get: function () { return makeLend_js_1.prepareMidnightMakeLend; } });
|
|
45
|
+
var makeRepay_js_1 = require("./midnight/makeRepay.js");
|
|
46
|
+
Object.defineProperty(exports, "prepareMidnightMakeRepay", { enumerable: true, get: function () { return makeRepay_js_1.prepareMidnightMakeRepay; } });
|
|
47
|
+
var makeWithdraw_js_1 = require("./midnight/makeWithdraw.js");
|
|
48
|
+
Object.defineProperty(exports, "prepareMidnightMakeWithdraw", { enumerable: true, get: function () { return makeWithdraw_js_1.prepareMidnightMakeWithdraw; } });
|
|
49
|
+
var redeem_js_1 = require("./midnight/redeem.js");
|
|
50
|
+
Object.defineProperty(exports, "prepareMidnightRedeem", { enumerable: true, get: function () { return redeem_js_1.prepareMidnightRedeem; } });
|
|
51
|
+
var repayWithdrawCollateral_js_2 = require("./midnight/repayWithdrawCollateral.js");
|
|
52
|
+
Object.defineProperty(exports, "prepareMidnightRepayWithdrawCollateral", { enumerable: true, get: function () { return repayWithdrawCollateral_js_2.prepareMidnightRepayWithdrawCollateral; } });
|
|
53
|
+
var supplyBlueMakeLend_js_1 = require("./midnight/supplyBlueMakeLend.js");
|
|
54
|
+
Object.defineProperty(exports, "prepareMidnightSupplyBlueMakeLend", { enumerable: true, get: function () { return supplyBlueMakeLend_js_1.prepareMidnightSupplyBlueMakeLend; } });
|
|
55
|
+
var supplyCollateral_js_2 = require("./midnight/supplyCollateral.js");
|
|
56
|
+
Object.defineProperty(exports, "prepareMidnightSupplyCollateral", { enumerable: true, get: function () { return supplyCollateral_js_2.prepareMidnightSupplyCollateral; } });
|
|
57
|
+
var supplyCollateralBatch_js_1 = require("./midnight/supplyCollateralBatch.js");
|
|
58
|
+
Object.defineProperty(exports, "prepareMidnightSupplyCollateralBatch", { enumerable: true, get: function () { return supplyCollateralBatch_js_1.prepareMidnightSupplyCollateralBatch; } });
|
|
59
|
+
var supplyCollateralMakeBorrow_js_1 = require("./midnight/supplyCollateralMakeBorrow.js");
|
|
60
|
+
Object.defineProperty(exports, "prepareMidnightSupplyCollateralMakeBorrow", { enumerable: true, get: function () { return supplyCollateralMakeBorrow_js_1.prepareMidnightSupplyCollateralMakeBorrow; } });
|
|
61
|
+
var supplyCollateralWithNative_js_1 = require("./midnight/supplyCollateralWithNative.js");
|
|
62
|
+
Object.defineProperty(exports, "prepareMidnightSupplyCollateralWithNative", { enumerable: true, get: function () { return supplyCollateralWithNative_js_1.prepareMidnightSupplyCollateralWithNative; } });
|
|
63
|
+
var takeBorrow_js_1 = require("./midnight/takeBorrow.js");
|
|
64
|
+
Object.defineProperty(exports, "prepareMidnightSupplyCollateralTakeBorrow", { enumerable: true, get: function () { return takeBorrow_js_1.prepareMidnightSupplyCollateralTakeBorrow; } });
|
|
65
|
+
Object.defineProperty(exports, "prepareMidnightTakeBorrow", { enumerable: true, get: function () { return takeBorrow_js_1.prepareMidnightTakeBorrow; } });
|
|
66
|
+
var takeLend_js_1 = require("./midnight/takeLend.js");
|
|
67
|
+
Object.defineProperty(exports, "prepareMidnightTakeLend", { enumerable: true, get: function () { return takeLend_js_1.prepareMidnightTakeLend; } });
|
|
68
|
+
var takeRepayWithdrawCollateral_js_1 = require("./midnight/takeRepayWithdrawCollateral.js");
|
|
69
|
+
Object.defineProperty(exports, "prepareMidnightTakeRepayWithdrawCollateral", { enumerable: true, get: function () { return takeRepayWithdrawCollateral_js_1.prepareMidnightTakeRepayWithdrawCollateral; } });
|
|
70
|
+
var takeWithdraw_js_1 = require("./midnight/takeWithdraw.js");
|
|
71
|
+
Object.defineProperty(exports, "prepareMidnightTakeWithdraw", { enumerable: true, get: function () { return takeWithdraw_js_1.prepareMidnightTakeWithdraw; } });
|
|
72
|
+
var withdrawCollateral_js_2 = require("./midnight/withdrawCollateral.js");
|
|
73
|
+
Object.defineProperty(exports, "prepareMidnightWithdrawCollateral", { enumerable: true, get: function () { return withdrawCollateral_js_2.prepareMidnightWithdrawCollateral; } });
|
|
74
|
+
var withdrawCollateralBatch_js_1 = require("./midnight/withdrawCollateralBatch.js");
|
|
75
|
+
Object.defineProperty(exports, "prepareMidnightWithdrawCollateralBatch", { enumerable: true, get: function () { return withdrawCollateralBatch_js_1.prepareMidnightWithdrawCollateralBatch; } });
|
|
35
76
|
var plan_js_1 = require("./plan.js");
|
|
36
77
|
Object.defineProperty(exports, "applySignatures", { enumerable: true, get: function () { return plan_js_1.applySignatures; } });
|
|
37
78
|
Object.defineProperty(exports, "buildTransaction", { enumerable: true, get: function () { return plan_js_1.buildTransaction; } });
|
|
@@ -46,8 +87,8 @@ var inKindRedeem_js_1 = require("./vaultv1/inKindRedeem.js");
|
|
|
46
87
|
Object.defineProperty(exports, "prepareVaultV1InKindRedeem", { enumerable: true, get: function () { return inKindRedeem_js_1.prepareVaultV1InKindRedeem; } });
|
|
47
88
|
var migrateToV2_js_1 = require("./vaultv1/migrateToV2.js");
|
|
48
89
|
Object.defineProperty(exports, "prepareVaultV1MigrateToV2", { enumerable: true, get: function () { return migrateToV2_js_1.prepareVaultV1MigrateToV2; } });
|
|
49
|
-
var
|
|
50
|
-
Object.defineProperty(exports, "prepareVaultV1Redeem", { enumerable: true, get: function () { return
|
|
90
|
+
var redeem_js_2 = require("./vaultv1/redeem.js");
|
|
91
|
+
Object.defineProperty(exports, "prepareVaultV1Redeem", { enumerable: true, get: function () { return redeem_js_2.prepareVaultV1Redeem; } });
|
|
51
92
|
var withdraw_js_2 = require("./vaultv1/withdraw.js");
|
|
52
93
|
Object.defineProperty(exports, "prepareVaultV1Withdraw", { enumerable: true, get: function () { return withdraw_js_2.prepareVaultV1Withdraw; } });
|
|
53
94
|
var deposit_js_2 = require("./vaultv2/deposit.js");
|
|
@@ -58,7 +99,7 @@ var forceWithdraw_js_1 = require("./vaultv2/forceWithdraw.js");
|
|
|
58
99
|
Object.defineProperty(exports, "prepareVaultV2ForceWithdraw", { enumerable: true, get: function () { return forceWithdraw_js_1.prepareVaultV2ForceWithdraw; } });
|
|
59
100
|
var inKindRedeem_js_2 = require("./vaultv2/inKindRedeem.js");
|
|
60
101
|
Object.defineProperty(exports, "prepareVaultV2InKindRedeem", { enumerable: true, get: function () { return inKindRedeem_js_2.prepareVaultV2InKindRedeem; } });
|
|
61
|
-
var
|
|
62
|
-
Object.defineProperty(exports, "prepareVaultV2Redeem", { enumerable: true, get: function () { return
|
|
102
|
+
var redeem_js_3 = require("./vaultv2/redeem.js");
|
|
103
|
+
Object.defineProperty(exports, "prepareVaultV2Redeem", { enumerable: true, get: function () { return redeem_js_3.prepareVaultV2Redeem; } });
|
|
63
104
|
var withdraw_js_3 = require("./vaultv2/withdraw.js");
|
|
64
105
|
Object.defineProperty(exports, "prepareVaultV2Withdraw", { enumerable: true, get: function () { return withdraw_js_3.prepareVaultV2Withdraw; } });
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import type { Address, Client } from "viem";
|
|
2
|
+
import type { Action, Step } from "../types.js";
|
|
3
|
+
type Authorization = Extract<Action, {
|
|
4
|
+
type: "midnightAuthorization";
|
|
5
|
+
}>;
|
|
6
|
+
/** @internal Resolves the ordinary registry bundle grant after the RPC chain has been checked. */
|
|
7
|
+
export declare function prepareMidnightBundleAuthorization(client: Client, inputs: {
|
|
8
|
+
readonly chainId: number;
|
|
9
|
+
readonly account: Address;
|
|
10
|
+
}): Promise<Step<Authorization> | undefined>;
|
|
11
|
+
/** @internal Derives the authorization target from the chain, not from a stored operator. */
|
|
12
|
+
export declare function buildMidnightAuthorization({ inputs }: Authorization): Readonly<import("../../index.js").Transaction<import("../../index.js").MidnightAuthorizationAction>>;
|
|
13
|
+
/** @internal Midnight steps never use signature requests. */
|
|
14
|
+
export declare function validateSignaturelessMidnightAction(action: Record<string, unknown>, path: string): void;
|
|
15
|
+
export {};
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.prepareMidnightBundleAuthorization = prepareMidnightBundleAuthorization;
|
|
4
|
+
exports.buildMidnightAuthorization = buildMidnightAuthorization;
|
|
5
|
+
exports.validateSignaturelessMidnightAction = validateSignaturelessMidnightAction;
|
|
6
|
+
const midnight_sdk_1 = require("@morpho-org/midnight-sdk");
|
|
7
|
+
const morpho_ts_1 = require("@morpho-org/morpho-ts");
|
|
8
|
+
const actions_1 = require("viem/actions");
|
|
9
|
+
const authorization_js_1 = require("../../actions/midnight/authorization.js");
|
|
10
|
+
const error_js_1 = require("../error.js");
|
|
11
|
+
/** @internal Resolves the ordinary registry bundle grant after the RPC chain has been checked. */
|
|
12
|
+
async function prepareMidnightBundleAuthorization(client, inputs) {
|
|
13
|
+
const { chainId, account } = inputs;
|
|
14
|
+
const isAuthorized = await (0, actions_1.readContract)(client, {
|
|
15
|
+
address: (0, morpho_ts_1.getChainAddress)(chainId, "midnight"),
|
|
16
|
+
abi: midnight_sdk_1.midnightAbi,
|
|
17
|
+
functionName: "isAuthorized",
|
|
18
|
+
args: [account, (0, morpho_ts_1.getChainAddress)(chainId, "midnightBundlesV2")],
|
|
19
|
+
});
|
|
20
|
+
if (isAuthorized) {
|
|
21
|
+
return undefined;
|
|
22
|
+
}
|
|
23
|
+
return {
|
|
24
|
+
id: "midnightAuthorization",
|
|
25
|
+
label: "Authorize Midnight bundle",
|
|
26
|
+
action: { type: "midnightAuthorization", inputs },
|
|
27
|
+
};
|
|
28
|
+
}
|
|
29
|
+
/** @internal Derives the authorization target from the chain, not from a stored operator. */
|
|
30
|
+
function buildMidnightAuthorization({ inputs }) {
|
|
31
|
+
return (0, authorization_js_1.midnightSetIsAuthorized)({
|
|
32
|
+
chainId: inputs.chainId,
|
|
33
|
+
onBehalf: inputs.account,
|
|
34
|
+
authorized: (0, morpho_ts_1.getChainAddress)(inputs.chainId, "midnightBundlesV2"),
|
|
35
|
+
});
|
|
36
|
+
}
|
|
37
|
+
/** @internal Midnight steps never use signature requests. */
|
|
38
|
+
function validateSignaturelessMidnightAction(action, path) {
|
|
39
|
+
if ("signatureRequestIds" in action) {
|
|
40
|
+
throw new error_js_1.InvalidTransactionPlanError({
|
|
41
|
+
path: `${path}.signatureRequestIds`,
|
|
42
|
+
reason: "Midnight steps do not consume signatures",
|
|
43
|
+
});
|
|
44
|
+
}
|
|
45
|
+
}
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
import type { Client, Hex } from "viem";
|
|
2
|
+
import type { MidnightCancelOffersAction, ReferenceTimestampParams, Transaction } from "../../types/index.js";
|
|
3
|
+
import { type IntentParams } from "../intent.js";
|
|
4
|
+
import type { Action, TransactionPlan } from "../types.js";
|
|
5
|
+
/**
|
|
6
|
+
* @experimental TransactionPlan is in beta; breaking changes may ship in minor releases.
|
|
7
|
+
* Offer groups to cancel in full for `account` through a direct Midnight call.
|
|
8
|
+
* No authorization, approval or signature is needed.
|
|
9
|
+
* @example
|
|
10
|
+
* ```ts
|
|
11
|
+
* import type { MidnightCancelOffersPlanParams } from "@morpho-org/morpho-sdk";
|
|
12
|
+
* import type { Address, Hex } from "viem";
|
|
13
|
+
*
|
|
14
|
+
* declare const maker: Address;
|
|
15
|
+
* declare const group: Hex;
|
|
16
|
+
* const params: MidnightCancelOffersPlanParams = { chainId: 8453, account: maker, groups: [group] };
|
|
17
|
+
* ```
|
|
18
|
+
*/
|
|
19
|
+
export interface MidnightCancelOffersPlanParams extends Pick<IntentParams, "chainId" | "account" | "expiresAt" | "calldataOrigin">, ReferenceTimestampParams {
|
|
20
|
+
/** Nonempty list of distinct 32-byte offer groups, cancelled in list order. */
|
|
21
|
+
readonly groups: readonly Hex[];
|
|
22
|
+
}
|
|
23
|
+
/**
|
|
24
|
+
* @experimental TransactionPlan is in beta; breaking changes may ship in minor releases.
|
|
25
|
+
* Prepares a full cancellation of `account`'s offer groups as one direct Midnight transaction.
|
|
26
|
+
* One group builds a bare `setConsumed(group, maxUint128, account)`; two or more build one Midnight
|
|
27
|
+
* core `multicall` of those calls, which cancels every group or none. The transaction never targets
|
|
28
|
+
* MidnightBundlesV2, so it builds on every chain with a Midnight deployment. `account`, or an
|
|
29
|
+
* operator it authorized on Midnight, must send it. Validates the groups with the same parse
|
|
30
|
+
* constructor as the entity `cancelOffers`, in the same order. Expiry is plan metadata, not an
|
|
31
|
+
* onchain deadline.
|
|
32
|
+
* @param client - Client used to validate the chain and Midnight core code, not retained by the plan.
|
|
33
|
+
* @param params.chainId - Chain containing the Midnight deployment.
|
|
34
|
+
* @param params.account - Non-zero maker whose groups are cancelled.
|
|
35
|
+
* @param params.groups - Nonempty list of distinct 32-byte offer groups.
|
|
36
|
+
* @param params.now - Reference Unix timestamp in seconds; omitting it uses the device clock (an untyped JavaScript `null` does too).
|
|
37
|
+
* @param params.expiresAt - Expiry in Unix seconds, later than `now`; defaults to `now + 2h`.
|
|
38
|
+
* @param params.calldataOrigin - Optional non-empty hex bytes appended to the built transaction.
|
|
39
|
+
* @returns A deep-frozen plan with one `midnightCancelOffers` step and no signature requests.
|
|
40
|
+
* @throws {InvalidBigIntInputError} when a supplied non-null `now` is not a bigint.
|
|
41
|
+
* @throws {ZeroAccountError} when `account` is the zero address.
|
|
42
|
+
* @throws {InvalidTransactionPlanError} when `account` is malformed or `calldataOrigin` exceeds 1 MiB.
|
|
43
|
+
* @throws {NonIntegerInputError} when `expiresAt` is not a safe integer.
|
|
44
|
+
* @throws {NonPositiveInputError} when `expiresAt` is not positive.
|
|
45
|
+
* @throws {ExpiredDeadlineError} when `expiresAt` is at or before the reference time.
|
|
46
|
+
* @throws {InvalidCalldataOriginError} when attribution bytes are empty or malformed.
|
|
47
|
+
* @throws {EmptyMidnightGroupCancellationsError} when `groups` is empty.
|
|
48
|
+
* @throws {InvalidMidnightHexInputError} when a group is not 32-byte hex.
|
|
49
|
+
* @throws {DuplicateMidnightGroupCancellationError} when a group appears more than once.
|
|
50
|
+
* @throws {UnsupportedChainIdError} when the chain is absent from the address registry.
|
|
51
|
+
* @throws {UnknownAddressError} when the chain has no `midnight` deployment.
|
|
52
|
+
* @throws {ChainIdMismatchError} when the client declares or serves another chain.
|
|
53
|
+
* @throws {MissingContractCodeError} when the registered Midnight core has no deployed code.
|
|
54
|
+
* @throws {viem.BaseError} when the RPC chain ID or bytecode read fails.
|
|
55
|
+
* @example
|
|
56
|
+
* ```ts
|
|
57
|
+
* import { buildTransactions, prepareMidnightCancelOffers } from "@morpho-org/morpho-sdk";
|
|
58
|
+
* import { createPublicClient, http, type Address, type Hex } from "viem";
|
|
59
|
+
* import { base } from "viem/chains";
|
|
60
|
+
*
|
|
61
|
+
* declare const maker: Address;
|
|
62
|
+
* declare const group: Hex;
|
|
63
|
+
* const client = createPublicClient({ chain: base, transport: http() });
|
|
64
|
+
* const plan = await prepareMidnightCancelOffers(client, {
|
|
65
|
+
* chainId: base.id,
|
|
66
|
+
* account: maker,
|
|
67
|
+
* groups: [group],
|
|
68
|
+
* now: (await client.getBlock()).timestamp,
|
|
69
|
+
* });
|
|
70
|
+
* // One transaction: setConsumed(group, maxUint128, maker) on Midnight.
|
|
71
|
+
* const [tx] = buildTransactions(plan);
|
|
72
|
+
* ```
|
|
73
|
+
*/
|
|
74
|
+
export declare function prepareMidnightCancelOffers(client: Client, params: MidnightCancelOffersPlanParams): Promise<TransactionPlan>;
|
|
75
|
+
/** @internal Validates the stored cancellation's plain input shape. */
|
|
76
|
+
export declare function validateMidnightCancelOffersPlanAction(action: Record<string, unknown>, path: string): void;
|
|
77
|
+
/** @internal Encodes the stored cancellation through the same action as `cancelOffers`. */
|
|
78
|
+
export declare function buildMidnightCancelOffers(action: Extract<Action, {
|
|
79
|
+
type: "midnightCancelOffers";
|
|
80
|
+
}>): Readonly<Transaction<MidnightCancelOffersAction>>;
|