@morpho-org/morpho-sdk 5.1.2 → 5.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +46 -2
- package/lib/cjs/abis.d.ts +1 -0
- package/lib/cjs/abis.js +6 -1
- package/lib/cjs/actions/blue/borrow.d.ts +3 -7
- package/lib/cjs/actions/blue/borrow.js +5 -9
- package/lib/cjs/actions/blue/buildReallocationActions.d.ts +3 -4
- package/lib/cjs/actions/blue/buildReallocationActions.js +3 -4
- package/lib/cjs/actions/blue/refinance.d.ts +4 -8
- package/lib/cjs/actions/blue/refinance.js +10 -14
- package/lib/cjs/actions/blue/repay.d.ts +2 -5
- package/lib/cjs/actions/blue/repay.js +2 -5
- package/lib/cjs/actions/blue/repayWithdrawCollateral.d.ts +3 -6
- package/lib/cjs/actions/blue/repayWithdrawCollateral.js +4 -7
- package/lib/cjs/actions/blue/resolveRepayFunding.d.ts +2 -5
- package/lib/cjs/actions/blue/resolveRepayFunding.js +15 -12
- package/lib/cjs/actions/blue/supply.d.ts +2 -4
- package/lib/cjs/actions/blue/supply.js +6 -8
- package/lib/cjs/actions/blue/supplyCollateral.d.ts +2 -3
- package/lib/cjs/actions/blue/supplyCollateral.js +5 -6
- package/lib/cjs/actions/blue/supplyCollateralBorrow.d.ts +4 -9
- package/lib/cjs/actions/blue/supplyCollateralBorrow.js +9 -14
- package/lib/cjs/actions/blue/withdraw.d.ts +9 -7
- package/lib/cjs/actions/blue/withdraw.js +18 -10
- package/lib/cjs/actions/blue/withdrawCollateral.d.ts +1 -1
- package/lib/cjs/actions/blue/withdrawCollateral.js +2 -2
- package/lib/cjs/actions/index.d.ts +2 -0
- package/lib/cjs/actions/index.js +1 -0
- package/lib/cjs/actions/midnight/authorization.d.ts +37 -0
- package/lib/cjs/actions/midnight/authorization.js +69 -0
- package/lib/cjs/actions/midnight/cancelOffer.d.ts +38 -0
- package/lib/cjs/actions/midnight/cancelOffer.js +73 -0
- package/lib/cjs/actions/midnight/index.d.ts +11 -0
- package/lib/cjs/actions/midnight/index.js +27 -0
- package/lib/cjs/actions/midnight/mempoolSubmitOffers.d.ts +52 -0
- package/lib/cjs/actions/midnight/mempoolSubmitOffers.js +72 -0
- package/lib/cjs/actions/midnight/redeem.d.ts +43 -0
- package/lib/cjs/actions/midnight/redeem.js +79 -0
- package/lib/cjs/actions/midnight/repayWithdrawCollateral.d.ts +53 -0
- package/lib/cjs/actions/midnight/repayWithdrawCollateral.js +121 -0
- package/lib/cjs/actions/midnight/setterRatifierRatifyRoot.d.ts +40 -0
- package/lib/cjs/actions/midnight/setterRatifierRatifyRoot.js +59 -0
- package/lib/cjs/actions/midnight/supplyCollateral.d.ts +45 -0
- package/lib/cjs/actions/midnight/supplyCollateral.js +83 -0
- package/lib/cjs/actions/midnight/supplyCollateralTakeBorrow.d.ts +51 -0
- package/lib/cjs/actions/midnight/supplyCollateralTakeBorrow.js +128 -0
- package/lib/cjs/actions/midnight/takeBorrow.d.ts +57 -0
- package/lib/cjs/actions/midnight/takeBorrow.js +110 -0
- package/lib/cjs/actions/midnight/takeLend.d.ts +57 -0
- package/lib/cjs/actions/midnight/takeLend.js +110 -0
- package/lib/cjs/actions/midnight/types.d.ts +39 -0
- package/lib/cjs/actions/midnight/types.js +15 -0
- package/lib/cjs/actions/requirements/encode/encodeBlueSignatureAuthorization.d.ts +1 -1
- package/lib/cjs/actions/requirements/encode/encodeBlueSignatureAuthorization.js +5 -16
- package/lib/cjs/actions/requirements/encode/encodeErc20Approval.d.ts +5 -4
- package/lib/cjs/actions/requirements/encode/encodeErc20Approval.js +10 -14
- package/lib/cjs/actions/requirements/encode/encodeErc20Permit.d.ts +2 -2
- package/lib/cjs/actions/requirements/encode/encodeErc20Permit.js +11 -28
- package/lib/cjs/actions/requirements/encode/encodeErc20Permit2Approve.d.ts +1 -1
- package/lib/cjs/actions/requirements/encode/encodeErc20Permit2Approve.js +5 -17
- package/lib/cjs/actions/requirements/generalAdapter/getGeneralAdapterRequirementsPermit.d.ts +1 -1
- package/lib/cjs/actions/requirements/getRequirementsApproval.d.ts +10 -4
- package/lib/cjs/actions/requirements/getRequirementsApproval.js +10 -4
- package/lib/cjs/actions/requirements/index.d.ts +1 -0
- package/lib/cjs/actions/requirements/index.js +1 -0
- package/lib/cjs/actions/requirements/midnight/getMidnightApprovalRequirements.d.ts +49 -0
- package/lib/cjs/actions/requirements/midnight/getMidnightApprovalRequirements.js +76 -0
- package/lib/cjs/actions/requirements/midnight/getMidnightAuthorizationRequirement.d.ts +44 -0
- package/lib/cjs/actions/requirements/midnight/getMidnightAuthorizationRequirement.js +78 -0
- package/lib/cjs/actions/requirements/midnight/getSetterRatifierRatifyRootRequirement.d.ts +42 -0
- package/lib/cjs/actions/requirements/midnight/getSetterRatifierRatifyRootRequirement.js +70 -0
- package/lib/cjs/actions/requirements/midnight/index.d.ts +3 -0
- package/lib/cjs/actions/requirements/midnight/index.js +19 -0
- package/lib/cjs/actions/vaultV1/deposit.d.ts +3 -4
- package/lib/cjs/actions/vaultV1/deposit.js +7 -8
- package/lib/cjs/actions/vaultV1/migrateToV2.d.ts +2 -3
- package/lib/cjs/actions/vaultV1/migrateToV2.js +5 -6
- package/lib/cjs/actions/vaultV1/redeem.d.ts +1 -1
- package/lib/cjs/actions/vaultV1/redeem.js +2 -2
- package/lib/cjs/actions/vaultV1/withdraw.d.ts +1 -1
- package/lib/cjs/actions/vaultV1/withdraw.js +2 -2
- package/lib/cjs/actions/vaultV2/deposit.d.ts +3 -4
- package/lib/cjs/actions/vaultV2/deposit.js +7 -8
- package/lib/cjs/actions/vaultV2/forceRedeem.d.ts +2 -3
- package/lib/cjs/actions/vaultV2/forceRedeem.js +3 -4
- package/lib/cjs/actions/vaultV2/forceWithdraw.d.ts +1 -1
- package/lib/cjs/actions/vaultV2/forceWithdraw.js +2 -2
- package/lib/cjs/actions/vaultV2/redeem.d.ts +1 -1
- package/lib/cjs/actions/vaultV2/redeem.js +2 -2
- package/lib/cjs/actions/vaultV2/withdraw.d.ts +1 -1
- package/lib/cjs/actions/vaultV2/withdraw.js +2 -2
- package/lib/cjs/client/morphoViemExtension.d.ts +1 -1
- package/lib/cjs/client/morphoViemExtension.js +5 -2
- package/lib/cjs/constants.d.ts +1 -0
- package/lib/cjs/constants.js +15 -1
- package/lib/cjs/entities/blue/blue.d.ts +5 -5
- package/lib/cjs/entities/blue/blue.js +105 -86
- package/lib/cjs/entities/index.d.ts +1 -0
- package/lib/cjs/entities/index.js +15 -0
- package/lib/cjs/entities/midnight/index.d.ts +2 -0
- package/lib/cjs/entities/midnight/index.js +18 -0
- package/lib/cjs/entities/midnight/midnight.d.ts +402 -0
- package/lib/cjs/entities/midnight/midnight.js +1036 -0
- package/lib/cjs/entities/midnight/types.d.ts +164 -0
- package/lib/cjs/entities/midnight/types.js +2 -0
- package/lib/cjs/entities/vaultV1/vaultV1.js +10 -17
- package/lib/cjs/entities/vaultV2/vaultV2.js +19 -21
- package/lib/cjs/errors.d.ts +1 -0
- package/lib/cjs/errors.js +17 -1
- package/lib/cjs/helpers/encodeDeallocation.d.ts +1 -0
- package/lib/cjs/helpers/encodeDeallocation.js +2 -1
- package/lib/cjs/helpers/index.d.ts +4 -1
- package/lib/cjs/helpers/index.js +8 -1
- package/lib/cjs/helpers/signAndVerifyTypedData.d.ts +34 -0
- package/lib/cjs/helpers/signAndVerifyTypedData.js +58 -0
- package/lib/cjs/helpers/validate.d.ts +40 -1
- package/lib/cjs/helpers/validate.js +47 -5
- package/lib/cjs/helpers/validateMidnightAuthorizationTarget.d.ts +15 -0
- package/lib/cjs/helpers/validateMidnightAuthorizationTarget.js +32 -0
- package/lib/cjs/helpers/validateMidnightMarket.d.ts +10 -0
- package/lib/cjs/helpers/validateMidnightMarket.js +24 -0
- package/lib/cjs/helpers/validateOfferSides.d.ts +21 -0
- package/lib/cjs/helpers/validateOfferSides.js +36 -0
- package/lib/cjs/helpers/validateRequirementSpender.d.ts +29 -0
- package/lib/cjs/helpers/validateRequirementSpender.js +49 -0
- package/lib/cjs/helpers/validateTakeableOffers.d.ts +18 -0
- package/lib/cjs/helpers/validateTakeableOffers.js +35 -0
- package/lib/cjs/midnight-api.d.ts +1 -0
- package/lib/cjs/midnight-api.js +17 -0
- package/lib/cjs/types/action.d.ts +189 -23
- package/lib/cjs/types/action.js +27 -7
- package/lib/cjs/types/client.d.ts +3 -2
- package/lib/cjs/types/error.d.ts +288 -114
- package/lib/cjs/types/error.js +259 -175
- package/lib/cjs/utils.d.ts +1 -0
- package/lib/cjs/utils.js +12 -2
- package/lib/esm/abis.d.ts +1 -0
- package/lib/esm/abis.js +1 -0
- package/lib/esm/actions/blue/borrow.d.ts +3 -7
- package/lib/esm/actions/blue/borrow.js +6 -10
- package/lib/esm/actions/blue/buildReallocationActions.d.ts +3 -4
- package/lib/esm/actions/blue/buildReallocationActions.js +3 -4
- package/lib/esm/actions/blue/refinance.d.ts +4 -8
- package/lib/esm/actions/blue/refinance.js +11 -15
- package/lib/esm/actions/blue/repay.d.ts +2 -5
- package/lib/esm/actions/blue/repay.js +2 -5
- package/lib/esm/actions/blue/repayWithdrawCollateral.d.ts +3 -6
- package/lib/esm/actions/blue/repayWithdrawCollateral.js +5 -8
- package/lib/esm/actions/blue/resolveRepayFunding.d.ts +2 -5
- package/lib/esm/actions/blue/resolveRepayFunding.js +16 -13
- package/lib/esm/actions/blue/supply.d.ts +2 -4
- package/lib/esm/actions/blue/supply.js +7 -9
- package/lib/esm/actions/blue/supplyCollateral.d.ts +2 -3
- package/lib/esm/actions/blue/supplyCollateral.js +6 -7
- package/lib/esm/actions/blue/supplyCollateralBorrow.d.ts +4 -9
- package/lib/esm/actions/blue/supplyCollateralBorrow.js +10 -15
- package/lib/esm/actions/blue/withdraw.d.ts +9 -7
- package/lib/esm/actions/blue/withdraw.js +19 -11
- package/lib/esm/actions/blue/withdrawCollateral.d.ts +1 -1
- package/lib/esm/actions/blue/withdrawCollateral.js +3 -3
- package/lib/esm/actions/index.d.ts +2 -0
- package/lib/esm/actions/index.js +1 -0
- package/lib/esm/actions/midnight/authorization.d.ts +37 -0
- package/lib/esm/actions/midnight/authorization.js +65 -0
- package/lib/esm/actions/midnight/cancelOffer.d.ts +38 -0
- package/lib/esm/actions/midnight/cancelOffer.js +69 -0
- package/lib/esm/actions/midnight/index.d.ts +11 -0
- package/lib/esm/actions/midnight/index.js +11 -0
- package/lib/esm/actions/midnight/mempoolSubmitOffers.d.ts +52 -0
- package/lib/esm/actions/midnight/mempoolSubmitOffers.js +68 -0
- package/lib/esm/actions/midnight/redeem.d.ts +43 -0
- package/lib/esm/actions/midnight/redeem.js +75 -0
- package/lib/esm/actions/midnight/repayWithdrawCollateral.d.ts +53 -0
- package/lib/esm/actions/midnight/repayWithdrawCollateral.js +117 -0
- package/lib/esm/actions/midnight/setterRatifierRatifyRoot.d.ts +40 -0
- package/lib/esm/actions/midnight/setterRatifierRatifyRoot.js +55 -0
- package/lib/esm/actions/midnight/supplyCollateral.d.ts +45 -0
- package/lib/esm/actions/midnight/supplyCollateral.js +79 -0
- package/lib/esm/actions/midnight/supplyCollateralTakeBorrow.d.ts +51 -0
- package/lib/esm/actions/midnight/supplyCollateralTakeBorrow.js +124 -0
- package/lib/esm/actions/midnight/takeBorrow.d.ts +57 -0
- package/lib/esm/actions/midnight/takeBorrow.js +106 -0
- package/lib/esm/actions/midnight/takeLend.d.ts +57 -0
- package/lib/esm/actions/midnight/takeLend.js +106 -0
- package/lib/esm/actions/midnight/types.d.ts +39 -0
- package/lib/esm/actions/midnight/types.js +12 -0
- package/lib/esm/actions/requirements/encode/encodeBlueSignatureAuthorization.d.ts +1 -1
- package/lib/esm/actions/requirements/encode/encodeBlueSignatureAuthorization.js +6 -17
- package/lib/esm/actions/requirements/encode/encodeErc20Approval.d.ts +5 -4
- package/lib/esm/actions/requirements/encode/encodeErc20Approval.js +12 -16
- package/lib/esm/actions/requirements/encode/encodeErc20Permit.d.ts +2 -2
- package/lib/esm/actions/requirements/encode/encodeErc20Permit.js +12 -29
- package/lib/esm/actions/requirements/encode/encodeErc20Permit2Approve.d.ts +1 -1
- package/lib/esm/actions/requirements/encode/encodeErc20Permit2Approve.js +5 -17
- package/lib/esm/actions/requirements/generalAdapter/getGeneralAdapterRequirementsPermit.d.ts +1 -1
- package/lib/esm/actions/requirements/getRequirementsApproval.d.ts +10 -4
- package/lib/esm/actions/requirements/getRequirementsApproval.js +10 -4
- package/lib/esm/actions/requirements/index.d.ts +1 -0
- package/lib/esm/actions/requirements/index.js +1 -0
- package/lib/esm/actions/requirements/midnight/getMidnightApprovalRequirements.d.ts +49 -0
- package/lib/esm/actions/requirements/midnight/getMidnightApprovalRequirements.js +72 -0
- package/lib/esm/actions/requirements/midnight/getMidnightAuthorizationRequirement.d.ts +44 -0
- package/lib/esm/actions/requirements/midnight/getMidnightAuthorizationRequirement.js +74 -0
- package/lib/esm/actions/requirements/midnight/getSetterRatifierRatifyRootRequirement.d.ts +42 -0
- package/lib/esm/actions/requirements/midnight/getSetterRatifierRatifyRootRequirement.js +66 -0
- package/lib/esm/actions/requirements/midnight/index.d.ts +3 -0
- package/lib/esm/actions/requirements/midnight/index.js +3 -0
- package/lib/esm/actions/vaultV1/deposit.d.ts +3 -4
- package/lib/esm/actions/vaultV1/deposit.js +8 -9
- package/lib/esm/actions/vaultV1/migrateToV2.d.ts +2 -3
- package/lib/esm/actions/vaultV1/migrateToV2.js +6 -7
- package/lib/esm/actions/vaultV1/redeem.d.ts +1 -1
- package/lib/esm/actions/vaultV1/redeem.js +3 -3
- package/lib/esm/actions/vaultV1/withdraw.d.ts +1 -1
- package/lib/esm/actions/vaultV1/withdraw.js +3 -3
- package/lib/esm/actions/vaultV2/deposit.d.ts +3 -4
- package/lib/esm/actions/vaultV2/deposit.js +8 -9
- package/lib/esm/actions/vaultV2/forceRedeem.d.ts +2 -3
- package/lib/esm/actions/vaultV2/forceRedeem.js +4 -5
- package/lib/esm/actions/vaultV2/forceWithdraw.d.ts +1 -1
- package/lib/esm/actions/vaultV2/forceWithdraw.js +3 -3
- package/lib/esm/actions/vaultV2/redeem.d.ts +1 -1
- package/lib/esm/actions/vaultV2/redeem.js +3 -3
- package/lib/esm/actions/vaultV2/withdraw.d.ts +1 -1
- package/lib/esm/actions/vaultV2/withdraw.js +3 -3
- package/lib/esm/client/morphoViemExtension.d.ts +1 -1
- package/lib/esm/client/morphoViemExtension.js +6 -3
- package/lib/esm/constants.d.ts +1 -0
- package/lib/esm/constants.js +1 -0
- package/lib/esm/entities/blue/blue.d.ts +5 -5
- package/lib/esm/entities/blue/blue.js +107 -88
- package/lib/esm/entities/index.d.ts +1 -0
- package/lib/esm/entities/index.js +1 -0
- package/lib/esm/entities/midnight/index.d.ts +2 -0
- package/lib/esm/entities/midnight/index.js +2 -0
- package/lib/esm/entities/midnight/midnight.d.ts +402 -0
- package/lib/esm/entities/midnight/midnight.js +1032 -0
- package/lib/esm/entities/midnight/types.d.ts +164 -0
- package/lib/esm/entities/midnight/types.js +1 -0
- package/lib/esm/entities/vaultV1/vaultV1.js +13 -20
- package/lib/esm/entities/vaultV2/vaultV2.js +9 -11
- package/lib/esm/errors.d.ts +1 -0
- package/lib/esm/errors.js +1 -0
- package/lib/esm/helpers/encodeDeallocation.d.ts +1 -0
- package/lib/esm/helpers/encodeDeallocation.js +3 -2
- package/lib/esm/helpers/index.d.ts +4 -1
- package/lib/esm/helpers/index.js +4 -1
- package/lib/esm/helpers/signAndVerifyTypedData.d.ts +34 -0
- package/lib/esm/helpers/signAndVerifyTypedData.js +54 -0
- package/lib/esm/helpers/validate.d.ts +40 -1
- package/lib/esm/helpers/validate.js +46 -5
- package/lib/esm/helpers/validateMidnightAuthorizationTarget.d.ts +15 -0
- package/lib/esm/helpers/validateMidnightAuthorizationTarget.js +28 -0
- package/lib/esm/helpers/validateMidnightMarket.d.ts +10 -0
- package/lib/esm/helpers/validateMidnightMarket.js +20 -0
- package/lib/esm/helpers/validateOfferSides.d.ts +21 -0
- package/lib/esm/helpers/validateOfferSides.js +32 -0
- package/lib/esm/helpers/validateRequirementSpender.d.ts +29 -0
- package/lib/esm/helpers/validateRequirementSpender.js +45 -0
- package/lib/esm/helpers/validateTakeableOffers.d.ts +18 -0
- package/lib/esm/helpers/validateTakeableOffers.js +31 -0
- package/lib/esm/midnight-api.d.ts +1 -0
- package/lib/esm/midnight-api.js +1 -0
- package/lib/esm/types/action.d.ts +189 -23
- package/lib/esm/types/action.js +26 -7
- package/lib/esm/types/client.d.ts +3 -2
- package/lib/esm/types/error.d.ts +288 -114
- package/lib/esm/types/error.js +232 -149
- package/lib/esm/utils.d.ts +1 -0
- package/lib/esm/utils.js +1 -0
- package/package.json +13 -4
|
@@ -0,0 +1,402 @@
|
|
|
1
|
+
import { type AccrualPosition, type Market, type MidnightFetchParams } from "@morpho-org/midnight-sdk";
|
|
2
|
+
import { type Address, type Hex } from "viem";
|
|
3
|
+
import type { MorphoClientType } from "../../types/client.js";
|
|
4
|
+
import { type MidnightCancelOfferAction, type MidnightRedeemAction, type MidnightRepayWithdrawCollateralAction, type MidnightSupplyCollateralAction, type MidnightSupplyCollateralTakeBorrowAction, type MidnightTakeBorrowAction, type MidnightTakeLendAction } from "../../types/index.js";
|
|
5
|
+
import type { GetOffersDataParams, GetPositionDataParams, MakeLendParams, MakeOffersOutput, MakeOffersParams, MidnightActionOutput, OffersData, RedeemParams, RepayWithdrawCollateralParams, SupplyCollateralMakeBorrowParams, SupplyCollateralParams, SupplyCollateralTakeBorrowParams, TakeBorrowParams, TakeLendParams } from "./types.js";
|
|
6
|
+
/**
|
|
7
|
+
* Entity methods exposed by `client.morpho.midnight(chainId)`.
|
|
8
|
+
*
|
|
9
|
+
* Use this surface for app flows: fetch market or position data first when a
|
|
10
|
+
* method asks for it, call the flow method to receive lazy `getRequirements`
|
|
11
|
+
* and `buildTx` handles, collect requirements, then build the final
|
|
12
|
+
* transaction synchronously.
|
|
13
|
+
*
|
|
14
|
+
* @example
|
|
15
|
+
* ```ts
|
|
16
|
+
* import { maxUint256 } from "viem";
|
|
17
|
+
*
|
|
18
|
+
* const midnight = client.morpho.midnight(8453);
|
|
19
|
+
* const marketData = await midnight.getMarketData(marketId);
|
|
20
|
+
* const output = midnight.takeLend({
|
|
21
|
+
* accountAddress: lender,
|
|
22
|
+
* marketData,
|
|
23
|
+
* assets: BigInt(quote.data.availableAssets),
|
|
24
|
+
* minUnits: BigInt(quote.data.availableUnits),
|
|
25
|
+
* takeableOffers: quote.data.takeableOffers,
|
|
26
|
+
* deadline: maxUint256,
|
|
27
|
+
* });
|
|
28
|
+
* const requirements = await output.getRequirements();
|
|
29
|
+
* const tx = output.buildTx();
|
|
30
|
+
* ```
|
|
31
|
+
*/
|
|
32
|
+
export type MidnightActions = Pick<MorphoMidnight, "getMarketData" | "getPositionData" | "getOffersData" | "takeLend" | "takeBorrow" | "supplyCollateralTakeBorrow" | "supplyCollateral" | "makeLend" | "makeBorrow" | "supplyCollateralMakeBorrow" | "redeem" | "repayWithdrawCollateral" | "cancelOffer">;
|
|
33
|
+
/**
|
|
34
|
+
* Entity facade for Midnight fixed-rate action flows.
|
|
35
|
+
*
|
|
36
|
+
* `MorphoMidnight` keeps reads and transaction construction separated. Methods
|
|
37
|
+
* that need chain or API state fetch it up front, while returned `buildTx`
|
|
38
|
+
* callbacks are synchronous and only consume the data already passed in.
|
|
39
|
+
*
|
|
40
|
+
* @example
|
|
41
|
+
* ```ts
|
|
42
|
+
* const midnight = client.morpho.midnight(8453);
|
|
43
|
+
* const block = await client.getBlock();
|
|
44
|
+
* const positionData = (
|
|
45
|
+
* await midnight.getPositionData({
|
|
46
|
+
* marketId,
|
|
47
|
+
* accountAddress: user,
|
|
48
|
+
* parameters: { blockNumber: block.number },
|
|
49
|
+
* })
|
|
50
|
+
* ).accrueInterest(block.timestamp);
|
|
51
|
+
* const { buildTx } = midnight.redeem({
|
|
52
|
+
* accountAddress: user,
|
|
53
|
+
* positionData,
|
|
54
|
+
* });
|
|
55
|
+
* const tx = buildTx();
|
|
56
|
+
* ```
|
|
57
|
+
*/
|
|
58
|
+
export declare class MorphoMidnight {
|
|
59
|
+
private readonly client;
|
|
60
|
+
private readonly chainId;
|
|
61
|
+
constructor(client: MorphoClientType, chainId: number);
|
|
62
|
+
/**
|
|
63
|
+
* Fetches a hydrated Midnight market from `Midnight.toMarket` and `Midnight.marketState`.
|
|
64
|
+
*
|
|
65
|
+
* @param marketId - Market id to fetch.
|
|
66
|
+
* @param parameters - Optional block, account, and state-override parameters forwarded to every read.
|
|
67
|
+
* @returns The market parameters and current onchain market state.
|
|
68
|
+
* @throws {ChainIdMismatchError} when the client chain differs from this entity's chain.
|
|
69
|
+
* @example
|
|
70
|
+
* ```ts
|
|
71
|
+
* const midnight = client.morpho.midnight(8453);
|
|
72
|
+
* const marketData = await midnight.getMarketData(marketId, {
|
|
73
|
+
* blockNumber: 48_287_000n,
|
|
74
|
+
* });
|
|
75
|
+
* ```
|
|
76
|
+
*/
|
|
77
|
+
getMarketData(marketId: Hex, parameters?: MidnightFetchParams): Promise<Market>;
|
|
78
|
+
/**
|
|
79
|
+
* Fetches a Midnight position and its hydrated market from onchain state.
|
|
80
|
+
*
|
|
81
|
+
* Reads `Midnight.toMarket`, `Midnight.marketState`, and either the deployless
|
|
82
|
+
* position query or the direct position and collateral getters.
|
|
83
|
+
*
|
|
84
|
+
* @param params - Position owner, market id, and optional fetch parameters.
|
|
85
|
+
* @param params.marketId - Market id whose position is fetched.
|
|
86
|
+
* @param params.accountAddress - Position owner address.
|
|
87
|
+
* @param params.parameters - Optional block, account, and state-override parameters forwarded to every read.
|
|
88
|
+
* @returns The account's position paired with the fetched market.
|
|
89
|
+
* @throws {ChainIdMismatchError} when the client chain differs from this entity's chain.
|
|
90
|
+
* @example
|
|
91
|
+
* ```ts
|
|
92
|
+
* const positionData = await midnight.getPositionData({
|
|
93
|
+
* marketId,
|
|
94
|
+
* accountAddress: user,
|
|
95
|
+
* parameters: { blockNumber: 48_287_000n },
|
|
96
|
+
* });
|
|
97
|
+
* ```
|
|
98
|
+
*/
|
|
99
|
+
getPositionData(params: GetPositionDataParams): Promise<AccrualPosition>;
|
|
100
|
+
/**
|
|
101
|
+
* Builds and validates a maker offer tree against the Midnight mempool API.
|
|
102
|
+
*
|
|
103
|
+
* @param params - Maker account, raw offer or group inputs, and optional API validation controls.
|
|
104
|
+
* @param params.accountAddress - Maker expected on every offer.
|
|
105
|
+
* @param params.offers - Offer, group, tree, or list accepted by `Tree.create`.
|
|
106
|
+
* @param params.validation - Optional Midnight mempool API request controls.
|
|
107
|
+
* @returns Prepared tree data used by maker flows.
|
|
108
|
+
* @throws {ChainIdMismatchError} when the client chain differs from this entity's chain.
|
|
109
|
+
* @throws {InvalidTreeError} when the input does not form a non-empty valid tree.
|
|
110
|
+
* @throws {MidnightOfferMakerMismatchError} when an offer belongs to another maker.
|
|
111
|
+
* @throws {MidnightOfferMarketChainMismatchError} when an offer targets another chain.
|
|
112
|
+
* @throws {MidnightOfferMarketAddressMismatchError} when an offer targets another Midnight deployment.
|
|
113
|
+
* @throws {UnknownMidnightRatifierError} when the tree uses an unsupported ratifier.
|
|
114
|
+
* @example
|
|
115
|
+
* ```ts
|
|
116
|
+
* const offersData = await midnight.getOffersData({
|
|
117
|
+
* accountAddress: maker,
|
|
118
|
+
* offers: [offer],
|
|
119
|
+
* });
|
|
120
|
+
* ```
|
|
121
|
+
*/
|
|
122
|
+
getOffersData(params: GetOffersDataParams): Promise<OffersData>;
|
|
123
|
+
/**
|
|
124
|
+
* Prepares a lend-side take using caller-provided market data and API offers.
|
|
125
|
+
*
|
|
126
|
+
* @param params - Lender, market snapshot, target assets, units, offers, and deadline.
|
|
127
|
+
* @param params.accountAddress - Lender executing the take.
|
|
128
|
+
* @param params.marketData - Hydrated market snapshot used for validation and transaction construction.
|
|
129
|
+
* @param params.assets - Loan assets spent by the lender.
|
|
130
|
+
* @param params.minUnits - Minimum credit units accepted.
|
|
131
|
+
* @param params.takeableOffers - Borrow-side offers returned by the Midnight API.
|
|
132
|
+
* @param params.deadline - Bundle execution deadline timestamp.
|
|
133
|
+
* @returns Lazy approval/authorization requirements and a synchronous transaction builder.
|
|
134
|
+
* @throws {ChainIdMismatchError} when client or market data targets another chain.
|
|
135
|
+
* @throws {MidnightMarketAddressMismatchError} when market data targets another Midnight deployment.
|
|
136
|
+
* @throws {NonPositiveInputError} when `assets` is non-positive.
|
|
137
|
+
* @throws {NegativeInputError} when `minUnits` or `deadline` is negative.
|
|
138
|
+
* @throws {EmptyMidnightTakeableOffersError} when no offers are supplied.
|
|
139
|
+
* @throws {MidnightOfferSideMismatchError} when an offer has the wrong maker side.
|
|
140
|
+
* @throws {MidnightTakeableOfferMarketMismatchError} when an offer targets another market.
|
|
141
|
+
* @example
|
|
142
|
+
* ```ts
|
|
143
|
+
* const output = midnight.takeLend({
|
|
144
|
+
* accountAddress: lender,
|
|
145
|
+
* marketData,
|
|
146
|
+
* assets: 1_000_000n,
|
|
147
|
+
* minUnits: 900_000n,
|
|
148
|
+
* takeableOffers: quote.data.takeableOffers,
|
|
149
|
+
* deadline: maxUint256,
|
|
150
|
+
* });
|
|
151
|
+
* ```
|
|
152
|
+
*/
|
|
153
|
+
takeLend(params: TakeLendParams): MidnightActionOutput<MidnightTakeLendAction>;
|
|
154
|
+
/**
|
|
155
|
+
* Prepares a borrow-side take using caller-provided market data and API offers.
|
|
156
|
+
*
|
|
157
|
+
* @param params - Borrower, market snapshot, target assets, unit cap, offers, and deadline.
|
|
158
|
+
* @param params.accountAddress - Borrower executing the take.
|
|
159
|
+
* @param params.marketData - Hydrated market snapshot used for validation and transaction construction.
|
|
160
|
+
* @param params.loanAssets - Loan assets received by the borrower.
|
|
161
|
+
* @param params.maxUnits - Maximum debt units accepted.
|
|
162
|
+
* @param params.takeableOffers - Lend-side offers returned by the Midnight API.
|
|
163
|
+
* @param params.deadline - Bundle execution deadline timestamp.
|
|
164
|
+
* @returns Lazy authorization requirements and a synchronous transaction builder.
|
|
165
|
+
* @throws {ChainIdMismatchError} when client or market data targets another chain.
|
|
166
|
+
* @throws {MidnightMarketAddressMismatchError} when market data targets another Midnight deployment.
|
|
167
|
+
* @throws {NonPositiveInputError} when `loanAssets` or `maxUnits` is non-positive.
|
|
168
|
+
* @throws {NegativeInputError} when `deadline` is negative.
|
|
169
|
+
* @throws {EmptyMidnightTakeableOffersError} when no offers are supplied.
|
|
170
|
+
* @throws {MidnightOfferSideMismatchError} when an offer has the wrong maker side.
|
|
171
|
+
* @throws {MidnightTakeableOfferMarketMismatchError} when an offer targets another market.
|
|
172
|
+
* @example
|
|
173
|
+
* ```ts
|
|
174
|
+
* const output = midnight.takeBorrow({
|
|
175
|
+
* accountAddress: borrower,
|
|
176
|
+
* marketData,
|
|
177
|
+
* loanAssets: 1_000_000n,
|
|
178
|
+
* maxUnits: 1_100_000n,
|
|
179
|
+
* takeableOffers: quote.data.takeableOffers,
|
|
180
|
+
* deadline: maxUint256,
|
|
181
|
+
* });
|
|
182
|
+
* ```
|
|
183
|
+
*/
|
|
184
|
+
takeBorrow(params: TakeBorrowParams): MidnightActionOutput<MidnightTakeBorrowAction>;
|
|
185
|
+
/**
|
|
186
|
+
* Prepares one bundle that supplies collateral and takes borrow-side offers.
|
|
187
|
+
*
|
|
188
|
+
* @param params - Borrower, market snapshot, collateral and loan amounts, unit cap, offers, and deadline.
|
|
189
|
+
* @param params.accountAddress - Borrower executing the bundle.
|
|
190
|
+
* @param params.marketData - Hydrated market snapshot used for validation and transaction construction.
|
|
191
|
+
* @param params.collateralAssets - Collateral assets supplied before borrowing.
|
|
192
|
+
* @param params.collateralIndex - Optional collateral index; defaults to `0n`.
|
|
193
|
+
* @param params.loanAssets - Loan assets received by the borrower.
|
|
194
|
+
* @param params.maxUnits - Maximum debt units accepted.
|
|
195
|
+
* @param params.takeableOffers - Lend-side offers returned by the Midnight API.
|
|
196
|
+
* @param params.deadline - Bundle execution deadline timestamp.
|
|
197
|
+
* @returns Lazy collateral approval/authorization requirements and a synchronous transaction builder.
|
|
198
|
+
* @throws {ChainIdMismatchError} when client or market data targets another chain.
|
|
199
|
+
* @throws {MidnightMarketAddressMismatchError} when market data targets another Midnight deployment.
|
|
200
|
+
* @throws {NonPositiveInputError} when collateral, loan assets, or `maxUnits` is non-positive.
|
|
201
|
+
* @throws {NegativeInputError} when `deadline` is negative.
|
|
202
|
+
* @throws {UnknownCollateralIndexError} when the selected collateral is not configured.
|
|
203
|
+
* @throws {EmptyMidnightTakeableOffersError} when no offers are supplied.
|
|
204
|
+
* @throws {MidnightOfferSideMismatchError} when an offer has the wrong maker side.
|
|
205
|
+
* @throws {MidnightTakeableOfferMarketMismatchError} when an offer targets another market.
|
|
206
|
+
* @example
|
|
207
|
+
* ```ts
|
|
208
|
+
* const output = midnight.supplyCollateralTakeBorrow({
|
|
209
|
+
* accountAddress: borrower,
|
|
210
|
+
* marketData,
|
|
211
|
+
* collateralAssets: 2_000_000n,
|
|
212
|
+
* loanAssets: 1_000_000n,
|
|
213
|
+
* maxUnits: 1_100_000n,
|
|
214
|
+
* takeableOffers: quote.data.takeableOffers,
|
|
215
|
+
* deadline: maxUint256,
|
|
216
|
+
* });
|
|
217
|
+
* ```
|
|
218
|
+
*/
|
|
219
|
+
supplyCollateralTakeBorrow(params: SupplyCollateralTakeBorrowParams): MidnightActionOutput<MidnightSupplyCollateralTakeBorrowAction>;
|
|
220
|
+
/**
|
|
221
|
+
* Prepares a direct collateral supply using a caller-provided market snapshot.
|
|
222
|
+
*
|
|
223
|
+
* @param params - Supplier, market snapshot, collateral amount, reserve, and optional collateral index.
|
|
224
|
+
* @param params.accountAddress - Account receiving the supplied collateral position.
|
|
225
|
+
* @param params.marketData - Hydrated market snapshot used for validation and transaction construction.
|
|
226
|
+
* @param params.collateralAssets - Collateral assets supplied in this transaction.
|
|
227
|
+
* @param params.reservedCollateralAssets - Existing collateral reserved by other open maker groups.
|
|
228
|
+
* @param params.collateralIndex - Optional collateral index; defaults to `0n`.
|
|
229
|
+
* @returns Lazy token-approval requirements and a synchronous transaction builder.
|
|
230
|
+
* @throws {ChainIdMismatchError} when client or market data targets another chain.
|
|
231
|
+
* @throws {MidnightMarketAddressMismatchError} when market data targets another Midnight deployment.
|
|
232
|
+
* @throws {NonPositiveInputError} when `collateralAssets` is non-positive.
|
|
233
|
+
* @throws {NegativeInputError} when `reservedCollateralAssets` is negative.
|
|
234
|
+
* @throws {UnknownCollateralIndexError} when the selected collateral is not configured.
|
|
235
|
+
* @example
|
|
236
|
+
* ```ts
|
|
237
|
+
* const output = midnight.supplyCollateral({
|
|
238
|
+
* accountAddress: borrower,
|
|
239
|
+
* marketData,
|
|
240
|
+
* collateralAssets: 2_000_000n,
|
|
241
|
+
* });
|
|
242
|
+
* ```
|
|
243
|
+
*/
|
|
244
|
+
supplyCollateral(params: SupplyCollateralParams): MidnightActionOutput<MidnightSupplyCollateralAction>;
|
|
245
|
+
/**
|
|
246
|
+
* Validates lend-side maker offers and prepares their reserve and ratifier requirements.
|
|
247
|
+
*
|
|
248
|
+
* Calls the Midnight mempool validation API while preparing the offer tree;
|
|
249
|
+
* allowance and ratifier state are read lazily by `getRequirements()`.
|
|
250
|
+
*
|
|
251
|
+
* @param params - Maker, raw offers, loan token, reserve amounts, and validation controls.
|
|
252
|
+
* @param params.accountAddress - Maker expected on every offer.
|
|
253
|
+
* @param params.offers - Raw lend-side offers or groups.
|
|
254
|
+
* @param params.validation - Optional Midnight mempool API request controls.
|
|
255
|
+
* @param params.loanToken - Loan token shared by every offer market.
|
|
256
|
+
* @param params.loanAssets - New loan reserve assigned to the submitted groups.
|
|
257
|
+
* @param params.reservedLoanAssets - Existing loan assets reserved by other open groups.
|
|
258
|
+
* @returns Prepared group metadata, lazy requirements, and a synchronous mempool transaction builder.
|
|
259
|
+
* @throws {ChainIdMismatchError} when the client targets another chain.
|
|
260
|
+
* @throws {MidnightOfferMarketAddressMismatchError} when an offer targets another Midnight deployment.
|
|
261
|
+
* @throws {NonPositiveInputError} when `loanAssets` is non-positive.
|
|
262
|
+
* @throws {NegativeInputError} when `reservedLoanAssets` is negative.
|
|
263
|
+
* @throws {MidnightOfferSideMismatchError} when an offer is not lend-side.
|
|
264
|
+
* @throws {MidnightOfferMarketLoanTokenMismatchError} when an offer uses another loan token.
|
|
265
|
+
* @example
|
|
266
|
+
* ```ts
|
|
267
|
+
* const output = await midnight.makeLend({
|
|
268
|
+
* accountAddress: maker,
|
|
269
|
+
* offers: [offer],
|
|
270
|
+
* loanToken,
|
|
271
|
+
* loanAssets: 1_000_000n,
|
|
272
|
+
* });
|
|
273
|
+
* ```
|
|
274
|
+
*/
|
|
275
|
+
makeLend(params: MakeLendParams): Promise<MakeOffersOutput>;
|
|
276
|
+
/**
|
|
277
|
+
* Validates borrow-side maker offers and prepares their ratifier requirements.
|
|
278
|
+
*
|
|
279
|
+
* @param params - Maker, raw borrow-side offers, and optional mempool validation controls.
|
|
280
|
+
* @param params.accountAddress - Maker expected on every offer.
|
|
281
|
+
* @param params.offers - Raw borrow-side offers or groups.
|
|
282
|
+
* @param params.validation - Optional Midnight mempool API request controls.
|
|
283
|
+
* @returns Prepared group metadata, lazy ratifier requirements, and a synchronous mempool transaction builder.
|
|
284
|
+
* @throws {ChainIdMismatchError} when the client targets another chain.
|
|
285
|
+
* @throws {MidnightOfferMarketAddressMismatchError} when an offer targets another Midnight deployment.
|
|
286
|
+
* @throws {MidnightOfferSideMismatchError} when an offer is not borrow-side.
|
|
287
|
+
* @example
|
|
288
|
+
* ```ts
|
|
289
|
+
* const output = await midnight.makeBorrow({
|
|
290
|
+
* accountAddress: maker,
|
|
291
|
+
* offers: [offer],
|
|
292
|
+
* });
|
|
293
|
+
* ```
|
|
294
|
+
*/
|
|
295
|
+
makeBorrow(params: MakeOffersParams): Promise<MakeOffersOutput>;
|
|
296
|
+
/**
|
|
297
|
+
* Prepares collateral supply followed by borrow-side maker-offer submission.
|
|
298
|
+
*
|
|
299
|
+
* @param params - Maker, market, collateral reserve, raw offers, and validation controls.
|
|
300
|
+
* @param params.accountAddress - Maker expected on every offer.
|
|
301
|
+
* @param params.offers - Raw borrow-side offers or groups.
|
|
302
|
+
* @param params.validation - Optional Midnight mempool API request controls.
|
|
303
|
+
* @param params.market - Market shared by every submitted offer.
|
|
304
|
+
* @param params.collateralAssets - Collateral supplied before offer submission.
|
|
305
|
+
* @param params.reservedCollateralAssets - Existing collateral reserved by other open groups.
|
|
306
|
+
* @param params.collateralIndex - Optional collateral index; defaults to `0n`.
|
|
307
|
+
* @returns Prepared group metadata, lazy supply/ratifier requirements, and a synchronous mempool transaction builder.
|
|
308
|
+
* @throws {ChainIdMismatchError} when the client targets another chain.
|
|
309
|
+
* @throws {MidnightMarketAddressMismatchError} when the market targets another Midnight deployment.
|
|
310
|
+
* @throws {NonPositiveInputError} when `collateralAssets` is non-positive.
|
|
311
|
+
* @throws {NegativeInputError} when `reservedCollateralAssets` is negative.
|
|
312
|
+
* @throws {UnknownCollateralIndexError} when the selected collateral is not configured.
|
|
313
|
+
* @throws {MidnightOfferSideMismatchError} when an offer is not borrow-side.
|
|
314
|
+
* @throws {MarketIdMismatchError} when an offer targets another market.
|
|
315
|
+
* @example
|
|
316
|
+
* ```ts
|
|
317
|
+
* const output = await midnight.supplyCollateralMakeBorrow({
|
|
318
|
+
* accountAddress: maker,
|
|
319
|
+
* market: marketData.params,
|
|
320
|
+
* collateralAssets: 2_000_000n,
|
|
321
|
+
* offers: [offer],
|
|
322
|
+
* });
|
|
323
|
+
* ```
|
|
324
|
+
*/
|
|
325
|
+
supplyCollateralMakeBorrow(params: SupplyCollateralMakeBorrowParams): Promise<MakeOffersOutput>;
|
|
326
|
+
/**
|
|
327
|
+
* Prepares redemption of accrued Midnight credit from a position snapshot.
|
|
328
|
+
*
|
|
329
|
+
* @param params - Position owner, accrued position, optional unit amount, and receiver.
|
|
330
|
+
* @param params.accountAddress - Position owner whose credit is redeemed.
|
|
331
|
+
* @param params.positionData - Accrued position and hydrated market snapshot.
|
|
332
|
+
* @param params.receiver - Optional credit receiver; defaults to the position owner.
|
|
333
|
+
* @param params.units - Optional credit units to redeem; defaults to the position face value.
|
|
334
|
+
* @returns No requirements and a synchronous redemption transaction builder.
|
|
335
|
+
* @throws {ChainIdMismatchError} when the position market targets another chain.
|
|
336
|
+
* @throws {MidnightMarketAddressMismatchError} when the position market targets another Midnight deployment.
|
|
337
|
+
* @throws {MissingAccrualPositionError} when no position snapshot is supplied.
|
|
338
|
+
* @throws {AccrualPositionUserMismatchError} when the position snapshot belongs to another account.
|
|
339
|
+
* @throws {NoMidnightCreditToRedeemError} when the selected unit amount is non-positive.
|
|
340
|
+
* @throws {MidnightRedeemExceedsCreditError} when the selected amount exceeds position credit.
|
|
341
|
+
* @throws {InsufficientMidnightWithdrawableLiquidityError} when market liquidity cannot cover the redemption.
|
|
342
|
+
* @example
|
|
343
|
+
* ```ts
|
|
344
|
+
* const output = midnight.redeem({
|
|
345
|
+
* accountAddress: lender,
|
|
346
|
+
* positionData,
|
|
347
|
+
* receiver: lender,
|
|
348
|
+
* });
|
|
349
|
+
* ```
|
|
350
|
+
*/
|
|
351
|
+
redeem(params: RedeemParams): MidnightActionOutput<MidnightRedeemAction>;
|
|
352
|
+
/**
|
|
353
|
+
* Prepares a bundle that repays debt, withdraws collateral, or performs both.
|
|
354
|
+
*
|
|
355
|
+
* @param params - Account, market snapshot, repay and withdrawal amounts, collateral index, and deadline.
|
|
356
|
+
* @param params.accountAddress - Position owner whose debt or collateral is updated.
|
|
357
|
+
* @param params.marketData - Hydrated market snapshot used for validation and transaction construction.
|
|
358
|
+
* @param params.repayAssets - Loan assets repaid; may be zero for withdrawal-only flows.
|
|
359
|
+
* @param params.withdrawCollateralAssets - Collateral assets withdrawn; may be zero for repay-only flows.
|
|
360
|
+
* @param params.collateralIndex - Optional collateral index; defaults to `0n`.
|
|
361
|
+
* @param params.deadline - Bundle execution deadline timestamp.
|
|
362
|
+
* @returns Lazy loan approval/authorization requirements and a synchronous transaction builder.
|
|
363
|
+
* @throws {ChainIdMismatchError} when client or market data targets another chain.
|
|
364
|
+
* @throws {MidnightMarketAddressMismatchError} when market data targets another Midnight deployment.
|
|
365
|
+
* @throws {NegativeInputError} when an amount, index, or deadline is negative.
|
|
366
|
+
* @throws {NonPositiveInputError} when both repay and withdrawal amounts are zero.
|
|
367
|
+
* @throws {UnknownCollateralIndexError} when a positive withdrawal selects an unconfigured collateral.
|
|
368
|
+
* @example
|
|
369
|
+
* ```ts
|
|
370
|
+
* const output = midnight.repayWithdrawCollateral({
|
|
371
|
+
* accountAddress: borrower,
|
|
372
|
+
* marketData,
|
|
373
|
+
* repayAssets: 1_000_000n,
|
|
374
|
+
* withdrawCollateralAssets: 2_000_000n,
|
|
375
|
+
* deadline: maxUint256,
|
|
376
|
+
* });
|
|
377
|
+
* ```
|
|
378
|
+
*/
|
|
379
|
+
repayWithdrawCollateral(params: RepayWithdrawCollateralParams): MidnightActionOutput<MidnightRepayWithdrawCollateralAction>;
|
|
380
|
+
/**
|
|
381
|
+
* Prepares full cancellation of a maker offer group.
|
|
382
|
+
*
|
|
383
|
+
* @param params - Group id and maker account whose consumption is updated.
|
|
384
|
+
* @param params.group - Offer group id to fully consume.
|
|
385
|
+
* @param params.accountAddress - Maker whose group consumption is updated.
|
|
386
|
+
* @returns No requirements and a synchronous cancellation transaction builder.
|
|
387
|
+
* @throws {ChainIdMismatchError} when the client targets another chain.
|
|
388
|
+
* @example
|
|
389
|
+
* ```ts
|
|
390
|
+
* const output = midnight.cancelOffer({
|
|
391
|
+
* group,
|
|
392
|
+
* accountAddress: maker,
|
|
393
|
+
* });
|
|
394
|
+
* ```
|
|
395
|
+
*/
|
|
396
|
+
cancelOffer(params: {
|
|
397
|
+
readonly group: Hex;
|
|
398
|
+
readonly accountAddress: Address;
|
|
399
|
+
}): MidnightActionOutput<MidnightCancelOfferAction>;
|
|
400
|
+
private getRatifierRequirements;
|
|
401
|
+
private buildSubmitOffersTx;
|
|
402
|
+
}
|