@morpho-org/morpho-sdk 7.1.0-next.1 → 8.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/MIGRATION-v7-to-v8.md +290 -0
- package/README.md +11 -6
- package/lib/cjs/abis.d.ts +1 -1
- package/lib/cjs/abis.js +1 -5
- package/lib/cjs/actions/bundles/resolveBundlesTokenRequirements.d.ts +2 -0
- package/lib/cjs/actions/bundles/resolveBundlesTokenRequirements.js +2 -0
- package/lib/cjs/actions/midnight/cancelAndMake.d.ts +17 -71
- package/lib/cjs/actions/midnight/cancelAndMake.js +41 -29
- package/lib/cjs/actions/midnight/redeem.d.ts +8 -1
- package/lib/cjs/actions/midnight/redeem.js +18 -1
- package/lib/cjs/actions/midnight/repayWithdrawCollateral.d.ts +19 -3
- package/lib/cjs/actions/midnight/repayWithdrawCollateral.js +24 -2
- package/lib/cjs/actions/midnight/supplyCollateral.d.ts +1 -0
- package/lib/cjs/actions/midnight/supplyCollateral.js +3 -0
- package/lib/cjs/actions/midnight/supplyCollateralTakeBorrow.d.ts +21 -6
- package/lib/cjs/actions/midnight/supplyCollateralTakeBorrow.js +49 -14
- package/lib/cjs/actions/midnight/takeBorrow.d.ts +18 -5
- package/lib/cjs/actions/midnight/takeBorrow.js +44 -12
- package/lib/cjs/actions/midnight/takeLend.d.ts +10 -5
- package/lib/cjs/actions/midnight/takeLend.js +27 -9
- package/lib/cjs/actions/midnight/takeRepayWithdrawCollateral.d.ts +22 -7
- package/lib/cjs/actions/midnight/takeRepayWithdrawCollateral.js +51 -27
- package/lib/cjs/actions/midnight/takeWithdraw.d.ts +14 -5
- package/lib/cjs/actions/midnight/takeWithdraw.js +40 -9
- package/lib/cjs/actions/requirements/blue/getBlueAuthorizationRequirement.d.ts +6 -2
- package/lib/cjs/actions/requirements/blue/getBlueAuthorizationRequirement.js +11 -6
- package/lib/cjs/actions/requirements/encode/encodeBlueSignatureAuthorization.d.ts +3 -0
- package/lib/cjs/actions/requirements/encode/encodeBlueSignatureAuthorization.js +2 -1
- package/lib/cjs/actions/requirements/encode/encodeErc20Permit.d.ts +13 -2
- package/lib/cjs/actions/requirements/encode/encodeErc20Permit.js +17 -6
- package/lib/cjs/actions/requirements/encode/encodeErc20Permit2SignatureTransfer.d.ts +3 -0
- package/lib/cjs/actions/requirements/encode/encodeErc20Permit2SignatureTransfer.js +2 -1
- package/lib/cjs/actions/requirements/encode/encodeVaultSharesPermit.d.ts +5 -0
- package/lib/cjs/actions/requirements/encode/encodeVaultSharesPermit.js +4 -1
- package/lib/cjs/actions/requirements/midnight/getMidnightApprovalRequirements.d.ts +3 -1
- package/lib/cjs/actions/requirements/midnight/getMidnightApprovalRequirements.js +5 -1
- package/lib/cjs/actions/requirements/midnight/getMidnightAuthorizationRequirement.d.ts +3 -1
- package/lib/cjs/actions/requirements/midnight/getMidnightAuthorizationRequirement.js +5 -1
- package/lib/cjs/actions/requirements/validateClientChainId.d.ts +26 -0
- package/lib/cjs/actions/requirements/validateClientChainId.js +34 -0
- package/lib/cjs/blue/abis.d.ts +1 -1
- package/lib/cjs/blue/abis.js +1 -5
- package/lib/cjs/blue/entities.d.ts +4 -4
- package/lib/cjs/blue/entities.js +1 -3
- package/lib/cjs/blue/errors.d.ts +2 -2
- package/lib/cjs/blue/errors.js +3 -5
- package/lib/cjs/blue/fetch.d.ts +2 -2
- package/lib/cjs/blue/fetch.js +1 -3
- package/lib/cjs/blue/types.d.ts +1 -1
- package/lib/cjs/blue/utils.d.ts +2 -2
- package/lib/cjs/blue/utils.js +5 -2
- package/lib/cjs/entities/blue/blue.d.ts +109 -27
- package/lib/cjs/entities/blue/blue.js +103 -28
- package/lib/cjs/entities/index.d.ts +5 -5
- package/lib/cjs/entities/index.js +1 -3
- package/lib/cjs/entities/midnight/deadline.d.ts +15 -0
- package/lib/cjs/entities/midnight/deadline.js +24 -0
- package/lib/cjs/entities/midnight/midnight.d.ts +427 -72
- package/lib/cjs/entities/midnight/midnight.js +864 -186
- package/lib/cjs/entities/midnight/publication.d.ts +134 -0
- package/lib/cjs/entities/midnight/publication.js +404 -0
- package/lib/cjs/entities/midnight/types.d.ts +26 -5
- package/lib/cjs/entities/requirements/assertContractCode.d.ts +49 -0
- package/lib/cjs/entities/requirements/assertContractCode.js +79 -0
- package/lib/cjs/entities/requirements/getBundlesTokenRequirements.d.ts +19 -4
- package/lib/cjs/entities/requirements/getBundlesTokenRequirements.js +45 -18
- package/lib/cjs/entities/requirements/getUnusedPermit2Nonce.d.ts +3 -2
- package/lib/cjs/entities/requirements/getUnusedPermit2Nonce.js +5 -2
- package/lib/cjs/entities/requirements/getVaultBundlesSharesRequirements.d.ts +5 -1
- package/lib/cjs/entities/requirements/getVaultBundlesSharesRequirements.js +8 -2
- package/lib/cjs/entities/vaultV1/vaultV1.d.ts +63 -11
- package/lib/cjs/entities/vaultV1/vaultV1.js +52 -15
- package/lib/cjs/entities/vaultV2/vaultV2.d.ts +62 -44
- package/lib/cjs/entities/vaultV2/vaultV2.js +53 -48
- package/lib/cjs/entities/vaultV2BlueReallocationData.d.ts +3 -5
- package/lib/cjs/entities/vaultV2BlueReallocationData.js +3 -9
- package/lib/cjs/errors.d.ts +4 -4
- package/lib/cjs/errors.js +7 -10
- package/lib/cjs/fetch.d.ts +2 -2
- package/lib/cjs/fetch.js +1 -3
- package/lib/cjs/helpers/constant.d.ts +5 -0
- package/lib/cjs/helpers/constant.js +6 -1
- package/lib/cjs/helpers/index.d.ts +1 -1
- package/lib/cjs/helpers/index.js +2 -1
- package/lib/cjs/helpers/validate.d.ts +163 -8
- package/lib/cjs/helpers/validate.js +179 -8
- package/lib/cjs/helpers/validateMidnightBounds.d.ts +47 -0
- package/lib/cjs/helpers/validateMidnightBounds.js +79 -0
- package/lib/cjs/helpers/validateMidnightPublication.d.ts +12 -0
- package/lib/cjs/helpers/validateMidnightPublication.js +144 -0
- package/lib/cjs/helpers/validateMidnightReceiver.d.ts +29 -0
- package/lib/cjs/helpers/validateMidnightReceiver.js +84 -0
- package/lib/cjs/helpers/validateMidnightTakeFeasibility.d.ts +102 -0
- package/lib/cjs/helpers/validateMidnightTakeFeasibility.js +231 -0
- package/lib/cjs/index.d.ts +1 -0
- package/lib/cjs/index.js +3 -0
- package/lib/cjs/midnight/errors.d.ts +1 -2
- package/lib/cjs/midnight/errors.js +4 -5
- package/lib/cjs/types/error.d.ts +197 -4
- package/lib/cjs/types/error.js +265 -5
- package/lib/cjs/types/index.d.ts +1 -0
- package/lib/cjs/types/index.js +1 -0
- package/lib/cjs/types/midnightCancelAndMake.d.ts +70 -0
- package/lib/cjs/types/midnightCancelAndMake.js +2 -0
- package/lib/cjs/types/midnightPublicationError.d.ts +332 -0
- package/lib/cjs/types/midnightPublicationError.js +376 -0
- package/lib/cjs/types.d.ts +1 -1
- package/lib/cjs/utils.d.ts +4 -3
- package/lib/cjs/utils.js +8 -4
- package/lib/esm/abis.d.ts +1 -1
- package/lib/esm/abis.js +1 -1
- package/lib/esm/actions/bundles/resolveBundlesTokenRequirements.d.ts +2 -0
- package/lib/esm/actions/bundles/resolveBundlesTokenRequirements.js +2 -0
- package/lib/esm/actions/midnight/cancelAndMake.d.ts +17 -71
- package/lib/esm/actions/midnight/cancelAndMake.js +42 -30
- package/lib/esm/actions/midnight/redeem.d.ts +8 -1
- package/lib/esm/actions/midnight/redeem.js +18 -1
- package/lib/esm/actions/midnight/repayWithdrawCollateral.d.ts +19 -3
- package/lib/esm/actions/midnight/repayWithdrawCollateral.js +24 -2
- package/lib/esm/actions/midnight/supplyCollateral.d.ts +1 -0
- package/lib/esm/actions/midnight/supplyCollateral.js +3 -0
- package/lib/esm/actions/midnight/supplyCollateralTakeBorrow.d.ts +21 -6
- package/lib/esm/actions/midnight/supplyCollateralTakeBorrow.js +52 -17
- package/lib/esm/actions/midnight/takeBorrow.d.ts +18 -5
- package/lib/esm/actions/midnight/takeBorrow.js +47 -15
- package/lib/esm/actions/midnight/takeLend.d.ts +10 -5
- package/lib/esm/actions/midnight/takeLend.js +27 -9
- package/lib/esm/actions/midnight/takeRepayWithdrawCollateral.d.ts +22 -7
- package/lib/esm/actions/midnight/takeRepayWithdrawCollateral.js +52 -28
- package/lib/esm/actions/midnight/takeWithdraw.d.ts +14 -5
- package/lib/esm/actions/midnight/takeWithdraw.js +41 -10
- package/lib/esm/actions/requirements/blue/getBlueAuthorizationRequirement.d.ts +6 -2
- package/lib/esm/actions/requirements/blue/getBlueAuthorizationRequirement.js +13 -8
- package/lib/esm/actions/requirements/encode/encodeBlueSignatureAuthorization.d.ts +3 -0
- package/lib/esm/actions/requirements/encode/encodeBlueSignatureAuthorization.js +2 -1
- package/lib/esm/actions/requirements/encode/encodeErc20Permit.d.ts +13 -2
- package/lib/esm/actions/requirements/encode/encodeErc20Permit.js +17 -6
- package/lib/esm/actions/requirements/encode/encodeErc20Permit2SignatureTransfer.d.ts +3 -0
- package/lib/esm/actions/requirements/encode/encodeErc20Permit2SignatureTransfer.js +2 -1
- package/lib/esm/actions/requirements/encode/encodeVaultSharesPermit.d.ts +5 -0
- package/lib/esm/actions/requirements/encode/encodeVaultSharesPermit.js +4 -1
- package/lib/esm/actions/requirements/midnight/getMidnightApprovalRequirements.d.ts +3 -1
- package/lib/esm/actions/requirements/midnight/getMidnightApprovalRequirements.js +5 -1
- package/lib/esm/actions/requirements/midnight/getMidnightAuthorizationRequirement.d.ts +3 -1
- package/lib/esm/actions/requirements/midnight/getMidnightAuthorizationRequirement.js +5 -1
- package/lib/esm/actions/requirements/validateClientChainId.d.ts +26 -0
- package/lib/esm/actions/requirements/validateClientChainId.js +30 -0
- package/lib/esm/blue/abis.d.ts +1 -1
- package/lib/esm/blue/abis.js +1 -1
- package/lib/esm/blue/entities.d.ts +4 -4
- package/lib/esm/blue/entities.js +2 -2
- package/lib/esm/blue/errors.d.ts +2 -2
- package/lib/esm/blue/errors.js +2 -2
- package/lib/esm/blue/fetch.d.ts +2 -2
- package/lib/esm/blue/fetch.js +2 -2
- package/lib/esm/blue/types.d.ts +1 -1
- package/lib/esm/blue/utils.d.ts +2 -2
- package/lib/esm/blue/utils.js +2 -2
- package/lib/esm/entities/blue/blue.d.ts +109 -27
- package/lib/esm/entities/blue/blue.js +104 -29
- package/lib/esm/entities/index.d.ts +5 -5
- package/lib/esm/entities/index.js +2 -2
- package/lib/esm/entities/midnight/deadline.d.ts +15 -0
- package/lib/esm/entities/midnight/deadline.js +20 -0
- package/lib/esm/entities/midnight/midnight.d.ts +427 -72
- package/lib/esm/entities/midnight/midnight.js +865 -187
- package/lib/esm/entities/midnight/publication.d.ts +134 -0
- package/lib/esm/entities/midnight/publication.js +397 -0
- package/lib/esm/entities/midnight/types.d.ts +26 -5
- package/lib/esm/entities/requirements/assertContractCode.d.ts +49 -0
- package/lib/esm/entities/requirements/assertContractCode.js +74 -0
- package/lib/esm/entities/requirements/getBundlesTokenRequirements.d.ts +19 -4
- package/lib/esm/entities/requirements/getBundlesTokenRequirements.js +47 -20
- package/lib/esm/entities/requirements/getUnusedPermit2Nonce.d.ts +3 -2
- package/lib/esm/entities/requirements/getUnusedPermit2Nonce.js +5 -2
- package/lib/esm/entities/requirements/getVaultBundlesSharesRequirements.d.ts +5 -1
- package/lib/esm/entities/requirements/getVaultBundlesSharesRequirements.js +8 -2
- package/lib/esm/entities/vaultV1/vaultV1.d.ts +63 -11
- package/lib/esm/entities/vaultV1/vaultV1.js +53 -16
- package/lib/esm/entities/vaultV2/vaultV2.d.ts +62 -44
- package/lib/esm/entities/vaultV2/vaultV2.js +54 -49
- package/lib/esm/entities/vaultV2BlueReallocationData.d.ts +3 -5
- package/lib/esm/entities/vaultV2BlueReallocationData.js +3 -9
- package/lib/esm/errors.d.ts +4 -4
- package/lib/esm/errors.js +4 -4
- package/lib/esm/fetch.d.ts +2 -2
- package/lib/esm/fetch.js +2 -2
- package/lib/esm/helpers/constant.d.ts +5 -0
- package/lib/esm/helpers/constant.js +5 -0
- package/lib/esm/helpers/index.d.ts +1 -1
- package/lib/esm/helpers/index.js +1 -1
- package/lib/esm/helpers/validate.d.ts +163 -8
- package/lib/esm/helpers/validate.js +177 -7
- package/lib/esm/helpers/validateMidnightBounds.d.ts +47 -0
- package/lib/esm/helpers/validateMidnightBounds.js +72 -0
- package/lib/esm/helpers/validateMidnightPublication.d.ts +12 -0
- package/lib/esm/helpers/validateMidnightPublication.js +139 -0
- package/lib/esm/helpers/validateMidnightReceiver.d.ts +29 -0
- package/lib/esm/helpers/validateMidnightReceiver.js +80 -0
- package/lib/esm/helpers/validateMidnightTakeFeasibility.d.ts +102 -0
- package/lib/esm/helpers/validateMidnightTakeFeasibility.js +226 -0
- package/lib/esm/index.d.ts +1 -0
- package/lib/esm/index.js +1 -0
- package/lib/esm/midnight/errors.d.ts +1 -2
- package/lib/esm/midnight/errors.js +1 -2
- package/lib/esm/types/error.d.ts +197 -4
- package/lib/esm/types/error.js +253 -2
- package/lib/esm/types/index.d.ts +1 -0
- package/lib/esm/types/index.js +1 -0
- package/lib/esm/types/midnightCancelAndMake.d.ts +70 -0
- package/lib/esm/types/midnightCancelAndMake.js +1 -0
- package/lib/esm/types/midnightPublicationError.d.ts +332 -0
- package/lib/esm/types/midnightPublicationError.js +359 -0
- package/lib/esm/types.d.ts +1 -1
- package/lib/esm/utils.d.ts +4 -3
- package/lib/esm/utils.js +4 -3
- package/package.json +9 -8
|
@@ -1,11 +1,13 @@
|
|
|
1
1
|
import { MathLib, } from "@morpho-org/blue-sdk";
|
|
2
2
|
import { fetchAccrualPosition, fetchAccrualVaultV2, fetchMarket, fetchVaultV2BluePublicAllocatorData, } from "@morpho-org/blue-sdk-viem";
|
|
3
|
-
import { getChainAddress, Time } from "@morpho-org/morpho-ts";
|
|
3
|
+
import { getChainAddress, getChainAddresses, Time, } from "@morpho-org/morpho-ts";
|
|
4
4
|
import { isAddressEqual, maxUint256 } from "viem";
|
|
5
5
|
import { getBlueBundlesV1PenaltyAssets, getBlueBundlesV1PublicAllocations, getBlueBundlesV1ReferralFeeAssets, normalizeBlueBundlesV1CommonParams, selectBlueBundlesV1RequirementSignatures, validateBlueBundlesV1NativeFunding, } from "../../actions/blue/common.js";
|
|
6
6
|
import { blueBorrow, blueRefinance, blueRepay, blueRepayWithdrawCollateral, blueSupply, blueSupplyCollateral, blueSupplyCollateralBorrow, blueWithdraw, blueWithdrawCollateral, getBlueAuthorizationRequirement, } from "../../actions/index.js";
|
|
7
|
+
import { validateClientChainId } from "../../actions/requirements/validateClientChainId.js";
|
|
7
8
|
import { DEFAULT_LLTV_BUFFER, validateAccrualPosition, validateChainId, validatePositionHealth, validatePositionHealthAfterWithdraw, validateRepayAmount, validateRepayShares, validateWithdrawAmount, validateWithdrawShares, } from "../../helpers/index.js";
|
|
8
9
|
import { ExpiredDeadlineError, InputExceedsMaxError, MaxRepayAssetsBelowRepayAssetsError, MissingAccrualPositionError, MutuallyExclusiveRepayAmountsError, MutuallyExclusiveWithdrawAmountsError, NegativeInputError, NonPositiveInputError, ReallocationsRequireBorrowError, RefinanceSameMarketError, RefinanceTokenMismatchError, } from "../../types/index.js";
|
|
10
|
+
import { assertRegistryTargetsHaveCode } from "../requirements/assertContractCode.js";
|
|
9
11
|
import { getBundlesTokenRequirements } from "../requirements/index.js";
|
|
10
12
|
import { VaultV2BlueReallocationData } from "../vaultV2BlueReallocationData.js";
|
|
11
13
|
/** Binds a viem client to a Morpho Blue market's action builders. */
|
|
@@ -19,10 +21,9 @@ export class MorphoBlue {
|
|
|
19
21
|
this.marketParams = marketParams;
|
|
20
22
|
this.chainId = chainId;
|
|
21
23
|
}
|
|
22
|
-
validateDeadline(deadline) {
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
throw new ExpiredDeadlineError(deadline, timestamp);
|
|
24
|
+
validateDeadline(deadline, now = Time.timestamp()) {
|
|
25
|
+
if (deadline <= now) {
|
|
26
|
+
throw new ExpiredDeadlineError(deadline, now);
|
|
26
27
|
}
|
|
27
28
|
}
|
|
28
29
|
validateWriteCommon(params) {
|
|
@@ -40,6 +41,30 @@ export class MorphoBlue {
|
|
|
40
41
|
referralFeeRecipient: params.referralFeeRecipient,
|
|
41
42
|
});
|
|
42
43
|
}
|
|
44
|
+
/**
|
|
45
|
+
* Asserts that every registry contract this flow's transaction targets or names as
|
|
46
|
+
* spender/authorized operator holds code, with one `eth_getCode` per distinct address
|
|
47
|
+
* before any other requirement read. Blue write flows probe `eth_chainId` only after a target
|
|
48
|
+
* has no code and report a chain mismatch when the RPC serves another chain.
|
|
49
|
+
*
|
|
50
|
+
* @param params.erc20Funding - Whether the flow resolves an ERC-20 funding leg, which
|
|
51
|
+
* may name canonical Permit2 when signatures are supported.
|
|
52
|
+
*/
|
|
53
|
+
async assertWriteTargets(params) {
|
|
54
|
+
const targets = [
|
|
55
|
+
{
|
|
56
|
+
role: "bundles.blueBundlesV1",
|
|
57
|
+
address: getChainAddress(this.chainId, "bundles.blueBundlesV1"),
|
|
58
|
+
},
|
|
59
|
+
{ role: "blue", address: getChainAddress(this.chainId, "blue") },
|
|
60
|
+
];
|
|
61
|
+
if (params?.erc20Funding && this.client.options.supportSignature) {
|
|
62
|
+
const permit2 = getChainAddresses(this.chainId).permit2;
|
|
63
|
+
if (permit2 != null)
|
|
64
|
+
targets.push({ role: "permit2", address: permit2 });
|
|
65
|
+
}
|
|
66
|
+
await assertRegistryTargetsHaveCode(this.client.viemClient, this.chainId, targets);
|
|
67
|
+
}
|
|
43
68
|
getMaxLtv(marketParams = this.marketParams) {
|
|
44
69
|
return MathLib.zeroFloorSub(marketParams.lltv, DEFAULT_LLTV_BUFFER);
|
|
45
70
|
}
|
|
@@ -47,7 +72,7 @@ export class MorphoBlue {
|
|
|
47
72
|
return MathLib.max(Time.timestamp(), lastUpdate) + Time.s.from.h(2n);
|
|
48
73
|
}
|
|
49
74
|
async getTokenRequirements(params) {
|
|
50
|
-
this.validateDeadline(params.deadline);
|
|
75
|
+
this.validateDeadline(params.deadline, params.now);
|
|
51
76
|
return getBundlesTokenRequirements(this.client.viemClient, {
|
|
52
77
|
token: params.token,
|
|
53
78
|
spender: getChainAddress(this.chainId, "bundles.blueBundlesV1"),
|
|
@@ -60,10 +85,11 @@ export class MorphoBlue {
|
|
|
60
85
|
useSimplePermit: params.useSimplePermit,
|
|
61
86
|
permit2Nonce: params.permit2Nonce,
|
|
62
87
|
approvalAmount: params.approvalAmount,
|
|
88
|
+
now: params.now,
|
|
63
89
|
});
|
|
64
90
|
}
|
|
65
91
|
async getAuthorizationRequirements(params) {
|
|
66
|
-
this.validateDeadline(params.deadline);
|
|
92
|
+
this.validateDeadline(params.deadline, params.now);
|
|
67
93
|
const requirement = await getBlueAuthorizationRequirement({
|
|
68
94
|
viemClient: this.client.viemClient,
|
|
69
95
|
chainId: this.chainId,
|
|
@@ -71,18 +97,19 @@ export class MorphoBlue {
|
|
|
71
97
|
supportSignature: this.client.options.supportSignature,
|
|
72
98
|
authorized: getChainAddress(this.chainId, "bundles.blueBundlesV1"),
|
|
73
99
|
deadline: params.deadline,
|
|
100
|
+
now: params.now,
|
|
74
101
|
});
|
|
75
102
|
return requirement == null ? [] : [requirement];
|
|
76
103
|
}
|
|
77
104
|
async getMarketData(parameters) {
|
|
78
|
-
|
|
105
|
+
await validateClientChainId(this.client.viemClient, this.chainId);
|
|
79
106
|
return fetchMarket(this.marketParams.id, this.client.viemClient, {
|
|
80
107
|
...parameters,
|
|
81
108
|
deployless: this.client.options.supportDeployless,
|
|
82
109
|
});
|
|
83
110
|
}
|
|
84
111
|
async getPositionData(userAddress, parameters) {
|
|
85
|
-
|
|
112
|
+
await validateClientChainId(this.client.viemClient, this.chainId);
|
|
86
113
|
return fetchAccrualPosition(userAddress, this.marketParams.id, this.client.viemClient, {
|
|
87
114
|
...parameters,
|
|
88
115
|
deployless: this.client.options.supportDeployless,
|
|
@@ -102,17 +129,23 @@ export class MorphoBlue {
|
|
|
102
129
|
});
|
|
103
130
|
return {
|
|
104
131
|
getRequirements: (requirementsParams) => {
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
132
|
+
const now = Time.timestamp();
|
|
133
|
+
this.validateDeadline(deadline, now);
|
|
134
|
+
return this.assertWriteTargets({
|
|
135
|
+
erc20Funding: nativeValue === 0n,
|
|
136
|
+
}).then(() => {
|
|
137
|
+
if (nativeValue > 0n)
|
|
138
|
+
return [];
|
|
139
|
+
return this.getTokenRequirements({
|
|
140
|
+
token: this.marketParams.loanToken,
|
|
141
|
+
amount: assets,
|
|
142
|
+
userAddress,
|
|
143
|
+
deadline,
|
|
144
|
+
now,
|
|
145
|
+
useSimplePermit: requirementsParams?.useSimplePermit,
|
|
146
|
+
permit2Nonce: requirementsParams?.permit2Nonce,
|
|
147
|
+
approvalAmount: requirementsParams?.approvalAmount,
|
|
148
|
+
});
|
|
116
149
|
});
|
|
117
150
|
},
|
|
118
151
|
buildTx: (signatures) => {
|
|
@@ -186,7 +219,16 @@ export class MorphoBlue {
|
|
|
186
219
|
});
|
|
187
220
|
}
|
|
188
221
|
return {
|
|
189
|
-
getRequirements: () =>
|
|
222
|
+
getRequirements: async () => {
|
|
223
|
+
const now = Time.timestamp();
|
|
224
|
+
this.validateDeadline(deadline, now);
|
|
225
|
+
await this.assertWriteTargets();
|
|
226
|
+
return this.getAuthorizationRequirements({
|
|
227
|
+
userAddress,
|
|
228
|
+
deadline,
|
|
229
|
+
now,
|
|
230
|
+
});
|
|
231
|
+
},
|
|
190
232
|
buildTx: (signatures) => {
|
|
191
233
|
const { authorization } = selectBlueBundlesV1RequirementSignatures(signatures, {
|
|
192
234
|
authorization: true,
|
|
@@ -430,7 +472,11 @@ export class MorphoBlue {
|
|
|
430
472
|
}
|
|
431
473
|
return {
|
|
432
474
|
getRequirements: async (requirementsParams) => {
|
|
433
|
-
|
|
475
|
+
const now = Time.timestamp();
|
|
476
|
+
this.validateDeadline(deadline, now);
|
|
477
|
+
await this.assertWriteTargets({
|
|
478
|
+
erc20Funding: hasRepay && nativeValue === 0n,
|
|
479
|
+
});
|
|
434
480
|
const [tokenRequirements, authorizationRequirements] = await Promise.all([
|
|
435
481
|
hasRepay && nativeValue === 0n
|
|
436
482
|
? this.getTokenRequirements({
|
|
@@ -439,12 +485,17 @@ export class MorphoBlue {
|
|
|
439
485
|
approvalAmount: requirementsParams?.approvalAmount,
|
|
440
486
|
userAddress,
|
|
441
487
|
deadline,
|
|
488
|
+
now,
|
|
442
489
|
useSimplePermit: requirementsParams?.useSimplePermit,
|
|
443
490
|
permit2Nonce: requirementsParams?.permit2Nonce,
|
|
444
491
|
})
|
|
445
492
|
: Promise.resolve([]),
|
|
446
493
|
collateralAssets > 0n
|
|
447
|
-
? this.getAuthorizationRequirements({
|
|
494
|
+
? this.getAuthorizationRequirements({
|
|
495
|
+
userAddress,
|
|
496
|
+
deadline,
|
|
497
|
+
now,
|
|
498
|
+
})
|
|
448
499
|
: Promise.resolve([]),
|
|
449
500
|
]);
|
|
450
501
|
return [...tokenRequirements, ...authorizationRequirements];
|
|
@@ -533,7 +584,11 @@ export class MorphoBlue {
|
|
|
533
584
|
});
|
|
534
585
|
return {
|
|
535
586
|
getRequirements: async (requirementsParams) => {
|
|
536
|
-
|
|
587
|
+
const now = Time.timestamp();
|
|
588
|
+
this.validateDeadline(deadline, now);
|
|
589
|
+
await this.assertWriteTargets({
|
|
590
|
+
erc20Funding: collateralAssets > 0n && nativeValue === 0n,
|
|
591
|
+
});
|
|
537
592
|
const [tokenRequirements, authorizationRequirements] = await Promise.all([
|
|
538
593
|
collateralAssets > 0n && nativeValue === 0n
|
|
539
594
|
? this.getTokenRequirements({
|
|
@@ -542,12 +597,17 @@ export class MorphoBlue {
|
|
|
542
597
|
approvalAmount: requirementsParams?.approvalAmount,
|
|
543
598
|
userAddress,
|
|
544
599
|
deadline,
|
|
600
|
+
now,
|
|
545
601
|
useSimplePermit: requirementsParams?.useSimplePermit,
|
|
546
602
|
permit2Nonce: requirementsParams?.permit2Nonce,
|
|
547
603
|
})
|
|
548
604
|
: Promise.resolve([]),
|
|
549
605
|
borrowAssets > 0n
|
|
550
|
-
? this.getAuthorizationRequirements({
|
|
606
|
+
? this.getAuthorizationRequirements({
|
|
607
|
+
userAddress,
|
|
608
|
+
deadline,
|
|
609
|
+
now,
|
|
610
|
+
})
|
|
551
611
|
: Promise.resolve([]),
|
|
552
612
|
]);
|
|
553
613
|
return [...tokenRequirements, ...authorizationRequirements];
|
|
@@ -625,7 +685,16 @@ export class MorphoBlue {
|
|
|
625
685
|
lltv: destination.marketParams.lltv,
|
|
626
686
|
});
|
|
627
687
|
return {
|
|
628
|
-
getRequirements: () =>
|
|
688
|
+
getRequirements: async () => {
|
|
689
|
+
const now = Time.timestamp();
|
|
690
|
+
this.validateDeadline(deadline, now);
|
|
691
|
+
await this.assertWriteTargets();
|
|
692
|
+
return this.getAuthorizationRequirements({
|
|
693
|
+
userAddress,
|
|
694
|
+
deadline,
|
|
695
|
+
now,
|
|
696
|
+
});
|
|
697
|
+
},
|
|
629
698
|
buildTx: (signatures) => {
|
|
630
699
|
const { authorization } = selectBlueBundlesV1RequirementSignatures(signatures, {
|
|
631
700
|
authorization: true,
|
|
@@ -660,13 +729,19 @@ export class MorphoBlue {
|
|
|
660
729
|
* @param params.block.number - Block number used for every RPC read.
|
|
661
730
|
* @param params.block.timestamp - Timestamp corresponding to the fetched block.
|
|
662
731
|
* @returns A `VaultV2BlueReallocationData` snapshot ready for {@link getVaultV2BlueReallocations}.
|
|
663
|
-
* @throws {ChainIdMismatchError} when the client chain
|
|
732
|
+
* @throws {ChainIdMismatchError} when the client declares another chain or its RPC reports another
|
|
733
|
+
* chain via `eth_chainId`.
|
|
664
734
|
* @throws {UnsupportedChainIdError} when the chain is absent from the address registry.
|
|
665
735
|
* @throws {UnknownAddressError} when the chain has no BluePublicAllocator deployment.
|
|
666
736
|
* @throws {UnknownBlueFactory} when the chain has no Vault V2 factory.
|
|
667
737
|
* @throws {UnknownBlueOfFactory} when a requested address is not a Vault V2 from that factory.
|
|
668
738
|
* @throws {UnsupportedBlueVaultV2AdapterError} when a vault contains an unsupported adapter.
|
|
669
|
-
* @throws {
|
|
739
|
+
* @throws {UnknownTokenError} when a vault's share token has unusable decimals.
|
|
740
|
+
* @throws {MalformedTokenMetadataError} when the share token's `eip712Domain()` or
|
|
741
|
+
* `bytes32` `name`/`symbol` retry returns non-empty data that does not decode, or when the
|
|
742
|
+
* deployless query reports malformed `name()`/`symbol()`/`eip712Domain()` returndata (no fallback).
|
|
743
|
+
* @throws {viem.BaseError} when the `eth_chainId` request fails or a later RPC or contract read
|
|
744
|
+
* fails with no fallback left.
|
|
670
745
|
* @example
|
|
671
746
|
* ```ts
|
|
672
747
|
* import { markets } from "@morpho-org/morpho-test";
|
|
@@ -688,7 +763,7 @@ export class MorphoBlue {
|
|
|
688
763
|
* ```
|
|
689
764
|
*/
|
|
690
765
|
async getVaultV2BlueReallocationData({ vaultAddresses, block, }) {
|
|
691
|
-
|
|
766
|
+
await validateClientChainId(this.client.viemClient, this.chainId);
|
|
692
767
|
const client = this.client.viemClient;
|
|
693
768
|
const fetchParams = {
|
|
694
769
|
blockNumber: block.number,
|
|
@@ -1,18 +1,18 @@
|
|
|
1
|
-
export type { IAccrualPosition as IBlueAccrualPosition, IAccrualVault, IAccrualVaultV2, IAccrualVaultV2Adapter,
|
|
1
|
+
export type { IAccrualPosition as IBlueAccrualPosition, IAccrualVault, IAccrualVaultV2, IAccrualVaultV2Adapter, IAccrualVaultV2MorphoMarketV1Adapter, IAccrualVaultV2MorphoMarketV1AdapterV2, IAccrualVaultV2MorphoVaultV1Adapter, IAssetBalances, IEip5267Domain, IHolding, IMarket as IBlueMarket, IMarketParams as IBlueMarketParams, IPosition as IBluePosition,
|
|
2
2
|
/** @deprecated Pre-liquidation support is deprecated and will be removed in the next major. */
|
|
3
3
|
IPreLiquidationParams as IBluePreLiquidationParams,
|
|
4
4
|
/** @deprecated Pre-liquidation support is deprecated and will be removed in the next major. */
|
|
5
|
-
IPreLiquidationPosition as IBluePreLiquidationPosition, IToken, IVault, IVaultConfig, IVaultMarketAllocation, IVaultMarketConfig, IVaultToken, IVaultUser, IVaultV2, IVaultV2Adapter, IVaultV2Allocation, IVaultV2BlueMarketPublicAllocatorConfig, IVaultV2BluePublicAllocatorConfig,
|
|
6
|
-
export { AccrualPosition as BlueAccrualPosition, AccrualVault, AccrualVaultV2,
|
|
5
|
+
IPreLiquidationPosition as IBluePreLiquidationPosition, IToken, IVault, IVaultConfig, IVaultMarketAllocation, IVaultMarketConfig, IVaultToken, IVaultUser, IVaultV2, IVaultV2Adapter, IVaultV2Allocation, IVaultV2BlueMarketPublicAllocatorConfig, IVaultV2BluePublicAllocatorConfig, IVaultV2MorphoMarketV1Adapter, IVaultV2MorphoMarketV1AdapterV2, IVaultV2MorphoVaultV1Adapter, PeripheralBalance, PeripheralBalanceType, } from "@morpho-org/blue-sdk";
|
|
6
|
+
export { AccrualPosition as BlueAccrualPosition, AccrualVault, AccrualVaultV2, AccrualVaultV2MorphoMarketV1Adapter, AccrualVaultV2MorphoMarketV1AdapterV2, AccrualVaultV2MorphoVaultV1Adapter, AssetBalances, ConstantWrappedToken, Eip5267Domain, ExchangeRateWrappedToken, Holding, Market as BlueMarket, MarketParams as BlueMarketParams, Position as BluePosition,
|
|
7
7
|
/** @deprecated Pre-liquidation support is deprecated and will be removed in the next major. */
|
|
8
8
|
PreLiquidationParams as BluePreLiquidationParams,
|
|
9
9
|
/** @deprecated Pre-liquidation support is deprecated and will be removed in the next major. */
|
|
10
|
-
PreLiquidationPosition as BluePreLiquidationPosition, Token, User as BlueUser, Vault, VaultConfig, VaultMarketAllocation, VaultMarketConfig, VaultToken, VaultUser, VaultV2, VaultV2Adapter, VaultV2BlueMarketPublicAllocatorConfig, VaultV2BluePublicAllocatorConfig,
|
|
10
|
+
PreLiquidationPosition as BluePreLiquidationPosition, Token, User as BlueUser, Vault, VaultConfig, VaultMarketAllocation, VaultMarketConfig, VaultToken, VaultUser, VaultV2, VaultV2Adapter, VaultV2BlueMarketPublicAllocatorConfig, VaultV2BluePublicAllocatorConfig, VaultV2MorphoMarketV1Adapter, VaultV2MorphoMarketV1AdapterV2, VaultV2MorphoVaultV1Adapter, WrappedToken, } from "@morpho-org/blue-sdk";
|
|
11
11
|
export type { AnyTree as MidnightAnyTree, AnyTreeSnapshot as MidnightAnyTreeSnapshot, BuildOfferParams as MidnightBuildOfferParams, CollateralParams as MidnightCollateralParams, EcrecoverTreeCreateRequest as MidnightEcrecoverTreeCreateRequest, GroupInput as MidnightGroupInput, IAccrualPosition as IMidnightAccrualPosition, ICollateralParams as IMidnightCollateralParams, IGroup as IMidnightGroup, IMarket as IMidnightMarket, IMarketParams as IMidnightMarketParams, IOffer as IMidnightOffer, IPosition as IMidnightPosition, MarketInput as MidnightMarketInput, OfferStruct as MidnightOfferStruct, PriceRatifierV1TreeCreateRequest as MidnightPriceRatifierV1TreeCreateRequest, RateRatifierV1TreeCreateRequest as MidnightRateRatifierV1TreeCreateRequest, RatifierKind as MidnightRatifierKind, RatifierTreeInput as MidnightRatifierTreeInput, RatifierTypes as MidnightRatifierTypes, SetterTreeCreateRequest as MidnightSetterTreeCreateRequest, SettlementFeeCbps as MidnightSettlementFeeCbps, TreeCreateParams as MidnightTreeCreateParams, TreeCreateRequest as MidnightTreeCreateRequest, TreeData as MidnightTreeData, TreeDescriptor as MidnightTreeDescriptor, TreeEntry as MidnightTreeEntry, TreeInput as MidnightTreeInput, TreeLike as MidnightTreeLike, TreeMempoolValidateParams as MidnightTreeMempoolValidateParams, TreeMempoolValidateRatification as MidnightTreeMempoolValidateRatification, TreeProof as MidnightTreeProof, TreeSnapshot as MidnightTreeSnapshot, TypedRatifierTreeInput as MidnightTypedRatifierTreeInput, TypedTreeMempoolValidateParams as MidnightTypedTreeMempoolValidateParams, } from "@morpho-org/midnight-sdk";
|
|
12
12
|
export { AccrualPosition as MidnightAccrualPosition, Group as MidnightGroup, Market as MidnightMarket, MarketParams as MidnightMarketParams, Offer as MidnightOffer, Position as MidnightPosition, Tree as MidnightTree, } from "@morpho-org/midnight-sdk";
|
|
13
13
|
export type { BlueActions, BlueTokenRequirementsParams, } from "./blue/index.js";
|
|
14
14
|
export { MorphoBlue } from "./blue/index.js";
|
|
15
|
-
export type { GetOffersDataParams as MidnightGetOffersDataParams, GetPositionDataParams as MidnightGetPositionDataParams, MakeLendParams as MidnightMakeLendParams, MakeOffersOutput as MidnightMakeOffersOutput, MakeOffersParams as MidnightMakeOffersParams, MarketActionParams as MidnightMarketActionParams, MidnightMakerTreeInput, OffersData as MidnightOffersData, OfferValidationParams as MidnightOfferValidationParams, RedeemParams as MidnightRedeemParams, RepayWithdrawCollateralParams as MidnightRepayWithdrawCollateralParams, SupplyBlueMakeLendParams as MidnightSupplyBlueMakeLendParams, SupplyCollateralMakeBorrowParams as MidnightSupplyCollateralMakeBorrowParams, SupplyCollateralParams as MidnightSupplyCollateralParams, SupplyCollateralTakeBorrowParams as MidnightSupplyCollateralTakeBorrowParams, TakeBorrowParams as MidnightTakeBorrowParams, TakeLendParams as MidnightTakeLendParams, TakeRepayWithdrawCollateralParams as MidnightTakeRepayWithdrawCollateralParams, TakeWithdrawParams as MidnightTakeWithdrawParams, } from "./midnight/index.js";
|
|
15
|
+
export type { GetOffersDataParams as MidnightGetOffersDataParams, GetPositionDataParams as MidnightGetPositionDataParams, MakeLendParams as MidnightMakeLendParams, MakeOffersOutput as MidnightMakeOffersOutput, MakeOffersParams as MidnightMakeOffersParams, MarketActionParams as MidnightMarketActionParams, MidnightMakerTreeInput, MidnightPositionHealthParams, OffersData as MidnightOffersData, OfferValidationParams as MidnightOfferValidationParams, RedeemParams as MidnightRedeemParams, RepayWithdrawCollateralParams as MidnightRepayWithdrawCollateralParams, SupplyBlueMakeLendParams as MidnightSupplyBlueMakeLendParams, SupplyCollateralMakeBorrowParams as MidnightSupplyCollateralMakeBorrowParams, SupplyCollateralParams as MidnightSupplyCollateralParams, SupplyCollateralTakeBorrowParams as MidnightSupplyCollateralTakeBorrowParams, TakeBorrowParams as MidnightTakeBorrowParams, TakeLendParams as MidnightTakeLendParams, TakeRepayWithdrawCollateralParams as MidnightTakeRepayWithdrawCollateralParams, TakeWithdrawParams as MidnightTakeWithdrawParams, } from "./midnight/index.js";
|
|
16
16
|
export { type MidnightActionOutput, type MidnightActions, type MidnightRequirementsParams, MorphoMidnight, } from "./midnight/index.js";
|
|
17
17
|
export * from "./requirements/index.js";
|
|
18
18
|
export { MorphoVaultV1 } from "./vaultV1/index.js";
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
export { AccrualPosition as BlueAccrualPosition, AccrualVault, AccrualVaultV2,
|
|
1
|
+
export { AccrualPosition as BlueAccrualPosition, AccrualVault, AccrualVaultV2, AccrualVaultV2MorphoMarketV1Adapter, AccrualVaultV2MorphoMarketV1AdapterV2, AccrualVaultV2MorphoVaultV1Adapter, AssetBalances, ConstantWrappedToken, Eip5267Domain, ExchangeRateWrappedToken, Holding, Market as BlueMarket, MarketParams as BlueMarketParams, Position as BluePosition,
|
|
2
2
|
/** @deprecated Pre-liquidation support is deprecated and will be removed in the next major. */
|
|
3
3
|
PreLiquidationParams as BluePreLiquidationParams,
|
|
4
4
|
/** @deprecated Pre-liquidation support is deprecated and will be removed in the next major. */
|
|
5
|
-
PreLiquidationPosition as BluePreLiquidationPosition, Token, User as BlueUser, Vault, VaultConfig, VaultMarketAllocation, VaultMarketConfig, VaultToken, VaultUser, VaultV2, VaultV2Adapter, VaultV2BlueMarketPublicAllocatorConfig, VaultV2BluePublicAllocatorConfig,
|
|
5
|
+
PreLiquidationPosition as BluePreLiquidationPosition, Token, User as BlueUser, Vault, VaultConfig, VaultMarketAllocation, VaultMarketConfig, VaultToken, VaultUser, VaultV2, VaultV2Adapter, VaultV2BlueMarketPublicAllocatorConfig, VaultV2BluePublicAllocatorConfig, VaultV2MorphoMarketV1Adapter, VaultV2MorphoMarketV1AdapterV2, VaultV2MorphoVaultV1Adapter, WrappedToken, } from "@morpho-org/blue-sdk";
|
|
6
6
|
export { AccrualPosition as MidnightAccrualPosition, Group as MidnightGroup, Market as MidnightMarket, MarketParams as MidnightMarketParams, Offer as MidnightOffer, Position as MidnightPosition, Tree as MidnightTree, } from "@morpho-org/midnight-sdk";
|
|
7
7
|
export { MorphoBlue } from "./blue/index.js";
|
|
8
8
|
export { MorphoMidnight, } from "./midnight/index.js";
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Rejects a Midnight bundle deadline that is not strictly after `now`.
|
|
3
|
+
*
|
|
4
|
+
* Midnight bundles revert with `DeadlinePassed()` once the deadline has passed, so a deadline at
|
|
5
|
+
* or before `now` builds a transaction that cannot succeed. `maxUint256` still means
|
|
6
|
+
* "no expiry". The check uses the local clock (`Time.timestamp()`), not chain time. Transaction
|
|
7
|
+
* builders stay clock-free and only check the deadline's `uint256` shape.
|
|
8
|
+
*
|
|
9
|
+
* @param deadline - Bundle execution deadline timestamp, in seconds.
|
|
10
|
+
* @param now - Reference timestamp, in seconds. Defaults to `Time.timestamp()`.
|
|
11
|
+
* @returns Nothing when `deadline` is after `now`.
|
|
12
|
+
* @throws {ExpiredDeadlineError} when `deadline` is at or before `now`.
|
|
13
|
+
* @internal
|
|
14
|
+
*/
|
|
15
|
+
export declare const validateMidnightDeadline: (deadline: bigint, now?: bigint) => void;
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { Time } from "@morpho-org/morpho-ts";
|
|
2
|
+
import { ExpiredDeadlineError } from "../../types/index.js";
|
|
3
|
+
/**
|
|
4
|
+
* Rejects a Midnight bundle deadline that is not strictly after `now`.
|
|
5
|
+
*
|
|
6
|
+
* Midnight bundles revert with `DeadlinePassed()` once the deadline has passed, so a deadline at
|
|
7
|
+
* or before `now` builds a transaction that cannot succeed. `maxUint256` still means
|
|
8
|
+
* "no expiry". The check uses the local clock (`Time.timestamp()`), not chain time. Transaction
|
|
9
|
+
* builders stay clock-free and only check the deadline's `uint256` shape.
|
|
10
|
+
*
|
|
11
|
+
* @param deadline - Bundle execution deadline timestamp, in seconds.
|
|
12
|
+
* @param now - Reference timestamp, in seconds. Defaults to `Time.timestamp()`.
|
|
13
|
+
* @returns Nothing when `deadline` is after `now`.
|
|
14
|
+
* @throws {ExpiredDeadlineError} when `deadline` is at or before `now`.
|
|
15
|
+
* @internal
|
|
16
|
+
*/
|
|
17
|
+
export const validateMidnightDeadline = (deadline, now = Time.timestamp()) => {
|
|
18
|
+
if (deadline <= now)
|
|
19
|
+
throw new ExpiredDeadlineError(deadline, now);
|
|
20
|
+
};
|