@morpho-org/morpho-sdk 10.5.0 → 10.6.0-next.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +44 -1
- package/lib/cjs/abis.d.ts +794 -1
- package/lib/cjs/abis.js +815 -1
- package/lib/cjs/actions/blue/close.d.ts +169 -0
- package/lib/cjs/actions/blue/close.js +270 -0
- package/lib/cjs/actions/blue/common.js +2 -2
- package/lib/cjs/actions/blue/delever.d.ts +156 -0
- package/lib/cjs/actions/blue/delever.js +223 -0
- package/lib/cjs/actions/blue/index.d.ts +3 -0
- package/lib/cjs/actions/blue/index.js +3 -0
- package/lib/cjs/actions/blue/lever.d.ts +184 -0
- package/lib/cjs/actions/blue/lever.js +272 -0
- package/lib/cjs/actions/blue/leverageIntent.d.ts +65 -0
- package/lib/cjs/actions/blue/leverageIntent.js +103 -0
- package/lib/cjs/actions/requirements/blue/encodeLeverageAuthorization.d.ts +39 -0
- package/lib/cjs/actions/requirements/blue/encodeLeverageAuthorization.js +59 -0
- package/lib/cjs/actions/requirements/blue/getLeverageRequirements.d.ts +104 -0
- package/lib/cjs/actions/requirements/blue/getLeverageRequirements.js +193 -0
- package/lib/cjs/actions/requirements/blue/getLeverageRequirementsApproval.d.ts +45 -0
- package/lib/cjs/actions/requirements/blue/getLeverageRequirementsApproval.js +66 -0
- package/lib/cjs/actions/requirements/blue/index.d.ts +3 -0
- package/lib/cjs/actions/requirements/blue/index.js +17 -0
- package/lib/cjs/actions/requirements/encode/encodeErc20Approval.d.ts +2 -2
- package/lib/cjs/actions/requirements/encode/encodeErc20Approval.js +3 -2
- package/lib/cjs/actions/requirements/getRequirementsApproval.d.ts +11 -6
- package/lib/cjs/actions/requirements/getRequirementsApproval.js +29 -5
- package/lib/cjs/addresses.d.ts +1 -1
- package/lib/cjs/addresses.js +6 -1
- package/lib/cjs/blue/abis.d.ts +1 -1
- package/lib/cjs/blue/abis.js +5 -1
- package/lib/cjs/blue/addresses.d.ts +1 -1
- package/lib/cjs/blue/addresses.js +6 -1
- package/lib/cjs/blue/entities.d.ts +4 -4
- package/lib/cjs/blue/entities.js +3 -1
- package/lib/cjs/blue/errors.d.ts +2 -2
- package/lib/cjs/blue/errors.js +5 -1
- package/lib/cjs/blue/fetch.d.ts +2 -2
- package/lib/cjs/blue/fetch.js +3 -1
- package/lib/cjs/blue/utils.d.ts +1 -1
- package/lib/cjs/blue/utils.js +2 -1
- package/lib/cjs/constants.d.ts +1 -1
- package/lib/cjs/constants.js +6 -2
- package/lib/cjs/entities/blue/blue.d.ts +486 -2
- package/lib/cjs/entities/blue/blue.js +529 -34
- package/lib/cjs/entities/index.d.ts +5 -5
- package/lib/cjs/entities/index.js +3 -1
- package/lib/cjs/entities/requirements/assertContractCode.d.ts +0 -23
- package/lib/cjs/entities/requirements/assertContractCode.js +3 -28
- package/lib/cjs/entities/vaultV2/vaultV2.d.ts +34 -8
- package/lib/cjs/entities/vaultV2/vaultV2.js +39 -1
- package/lib/cjs/entities/vaultV2BlueReallocationData.d.ts +120 -2
- package/lib/cjs/entities/vaultV2BlueReallocationData.js +232 -4
- package/lib/cjs/errors.d.ts +4 -4
- package/lib/cjs/errors.js +7 -5
- package/lib/cjs/fetch.d.ts +2 -2
- package/lib/cjs/fetch.js +3 -1
- package/lib/cjs/helpers/constant.d.ts +34 -0
- package/lib/cjs/helpers/constant.js +35 -1
- package/lib/cjs/helpers/deadShares.js +3 -0
- package/lib/cjs/helpers/getZeroExLeverageBundle.d.ts +13 -0
- package/lib/cjs/helpers/getZeroExLeverageBundle.js +27 -0
- package/lib/cjs/helpers/index.d.ts +4 -1
- package/lib/cjs/helpers/index.js +28 -1
- package/lib/cjs/helpers/leverage/index.d.ts +1 -0
- package/lib/cjs/helpers/leverage/index.js +11 -0
- package/lib/cjs/helpers/leverage/limits.d.ts +472 -0
- package/lib/cjs/helpers/leverage/limits.js +715 -0
- package/lib/cjs/helpers/leverage/positionMarket.d.ts +17 -0
- package/lib/cjs/helpers/leverage/positionMarket.js +28 -0
- package/lib/cjs/helpers/leverage/reallocations.d.ts +159 -0
- package/lib/cjs/helpers/leverage/reallocations.js +276 -0
- package/lib/cjs/helpers/validateRequirementSpender.d.ts +1 -1
- package/lib/cjs/helpers/validateRequirementSpender.js +4 -0
- package/lib/cjs/helpers/zeroExQuote.d.ts +250 -0
- package/lib/cjs/helpers/zeroExQuote.js +763 -0
- package/lib/cjs/index.d.ts +1 -0
- package/lib/cjs/index.js +5 -2
- package/lib/cjs/midnight/errors.d.ts +2 -1
- package/lib/cjs/midnight/errors.js +5 -4
- package/lib/cjs/reads/assertContractCode.d.ts +25 -0
- package/lib/cjs/reads/assertContractCode.js +30 -0
- package/lib/cjs/reads/fetchZeroExQuote.d.ts +123 -0
- package/lib/cjs/reads/fetchZeroExQuote.js +330 -0
- package/lib/cjs/types/action.d.ts +130 -1
- package/lib/cjs/types/error.d.ts +59 -0
- package/lib/cjs/types/error.js +82 -3
- package/lib/cjs/types/index.d.ts +2 -0
- package/lib/cjs/types/index.js +2 -0
- package/lib/cjs/types/leverageError.d.ts +1552 -0
- package/lib/cjs/types/leverageError.js +1711 -0
- package/lib/cjs/types/zeroEx.d.ts +171 -0
- package/lib/cjs/types/zeroEx.js +2 -0
- package/lib/cjs/utils.d.ts +2 -2
- package/lib/cjs/utils.js +4 -2
- package/lib/cjs/version.d.ts +1 -1
- package/lib/cjs/version.js +1 -1
- package/lib/esm/abis.d.ts +794 -1
- package/lib/esm/abis.js +810 -1
- package/lib/esm/actions/blue/close.d.ts +169 -0
- package/lib/esm/actions/blue/close.js +266 -0
- package/lib/esm/actions/blue/common.js +3 -3
- package/lib/esm/actions/blue/delever.d.ts +156 -0
- package/lib/esm/actions/blue/delever.js +219 -0
- package/lib/esm/actions/blue/index.d.ts +3 -0
- package/lib/esm/actions/blue/index.js +3 -0
- package/lib/esm/actions/blue/lever.d.ts +184 -0
- package/lib/esm/actions/blue/lever.js +268 -0
- package/lib/esm/actions/blue/leverageIntent.d.ts +65 -0
- package/lib/esm/actions/blue/leverageIntent.js +96 -0
- package/lib/esm/actions/requirements/blue/encodeLeverageAuthorization.d.ts +39 -0
- package/lib/esm/actions/requirements/blue/encodeLeverageAuthorization.js +55 -0
- package/lib/esm/actions/requirements/blue/getLeverageRequirements.d.ts +104 -0
- package/lib/esm/actions/requirements/blue/getLeverageRequirements.js +189 -0
- package/lib/esm/actions/requirements/blue/getLeverageRequirementsApproval.d.ts +45 -0
- package/lib/esm/actions/requirements/blue/getLeverageRequirementsApproval.js +62 -0
- package/lib/esm/actions/requirements/blue/index.d.ts +3 -0
- package/lib/esm/actions/requirements/blue/index.js +3 -0
- package/lib/esm/actions/requirements/encode/encodeErc20Approval.d.ts +2 -2
- package/lib/esm/actions/requirements/encode/encodeErc20Approval.js +3 -2
- package/lib/esm/actions/requirements/getRequirementsApproval.d.ts +11 -6
- package/lib/esm/actions/requirements/getRequirementsApproval.js +29 -5
- package/lib/esm/addresses.d.ts +1 -1
- package/lib/esm/addresses.js +1 -1
- package/lib/esm/blue/abis.d.ts +1 -1
- package/lib/esm/blue/abis.js +1 -1
- package/lib/esm/blue/addresses.d.ts +1 -1
- package/lib/esm/blue/addresses.js +1 -1
- package/lib/esm/blue/entities.d.ts +4 -4
- package/lib/esm/blue/entities.js +2 -2
- package/lib/esm/blue/errors.d.ts +2 -2
- package/lib/esm/blue/errors.js +2 -2
- package/lib/esm/blue/fetch.d.ts +2 -2
- package/lib/esm/blue/fetch.js +2 -2
- package/lib/esm/blue/utils.d.ts +1 -1
- package/lib/esm/blue/utils.js +1 -1
- package/lib/esm/constants.d.ts +1 -1
- package/lib/esm/constants.js +1 -1
- package/lib/esm/entities/blue/blue.d.ts +486 -2
- package/lib/esm/entities/blue/blue.js +501 -6
- package/lib/esm/entities/index.d.ts +5 -5
- package/lib/esm/entities/index.js +2 -2
- package/lib/esm/entities/requirements/assertContractCode.d.ts +0 -23
- package/lib/esm/entities/requirements/assertContractCode.js +1 -25
- package/lib/esm/entities/vaultV2/vaultV2.d.ts +34 -8
- package/lib/esm/entities/vaultV2/vaultV2.js +40 -2
- package/lib/esm/entities/vaultV2BlueReallocationData.d.ts +120 -2
- package/lib/esm/entities/vaultV2BlueReallocationData.js +233 -5
- 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 +34 -0
- package/lib/esm/helpers/constant.js +34 -0
- package/lib/esm/helpers/deadShares.js +4 -1
- package/lib/esm/helpers/getZeroExLeverageBundle.d.ts +13 -0
- package/lib/esm/helpers/getZeroExLeverageBundle.js +23 -0
- package/lib/esm/helpers/index.d.ts +4 -1
- package/lib/esm/helpers/index.js +4 -1
- package/lib/esm/helpers/leverage/index.d.ts +1 -0
- package/lib/esm/helpers/leverage/index.js +1 -0
- package/lib/esm/helpers/leverage/limits.d.ts +472 -0
- package/lib/esm/helpers/leverage/limits.js +705 -0
- package/lib/esm/helpers/leverage/positionMarket.d.ts +17 -0
- package/lib/esm/helpers/leverage/positionMarket.js +24 -0
- package/lib/esm/helpers/leverage/reallocations.d.ts +159 -0
- package/lib/esm/helpers/leverage/reallocations.js +271 -0
- package/lib/esm/helpers/validateRequirementSpender.d.ts +1 -1
- package/lib/esm/helpers/validateRequirementSpender.js +5 -1
- package/lib/esm/helpers/zeroExQuote.d.ts +250 -0
- package/lib/esm/helpers/zeroExQuote.js +754 -0
- package/lib/esm/index.d.ts +1 -0
- package/lib/esm/index.js +1 -0
- package/lib/esm/midnight/errors.d.ts +2 -1
- package/lib/esm/midnight/errors.js +2 -1
- package/lib/esm/reads/assertContractCode.d.ts +25 -0
- package/lib/esm/reads/assertContractCode.js +26 -0
- package/lib/esm/reads/fetchZeroExQuote.d.ts +123 -0
- package/lib/esm/reads/fetchZeroExQuote.js +326 -0
- package/lib/esm/types/action.d.ts +130 -1
- package/lib/esm/types/error.d.ts +59 -0
- package/lib/esm/types/error.js +76 -0
- package/lib/esm/types/index.d.ts +2 -0
- package/lib/esm/types/index.js +2 -0
- package/lib/esm/types/leverageError.d.ts +1552 -0
- package/lib/esm/types/leverageError.js +1660 -0
- package/lib/esm/types/zeroEx.d.ts +171 -0
- package/lib/esm/types/zeroEx.js +1 -0
- package/lib/esm/utils.d.ts +2 -2
- package/lib/esm/utils.js +2 -2
- package/lib/esm/version.d.ts +1 -1
- package/lib/esm/version.js +1 -1
- package/package.json +7 -7
package/lib/esm/fetch.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
export { fetchAccrualPosition as fetchBlueAccrualPosition, fetchAccrualVault, fetchAccrualVaultV2, fetchAccrualVaultV2Adapter, fetchAccrualVaultV2MorphoMarketV1Adapter, fetchAccrualVaultV2MorphoMarketV1AdapterV2, fetchAccrualVaultV2MorphoVaultV1Adapter, fetchHolding, fetchMarket as fetchBlueMarket, fetchMarketParams as fetchBlueMarketParams, fetchPosition as fetchBluePosition,
|
|
1
|
+
export { fetchAccrualPosition as fetchBlueAccrualPosition, fetchAccrualVault, fetchAccrualVaultV2, fetchAccrualVaultV2Adapter, fetchAccrualVaultV2MidnightAdapter, fetchAccrualVaultV2MorphoMarketV1Adapter, fetchAccrualVaultV2MorphoMarketV1AdapterV2, fetchAccrualVaultV2MorphoVaultV1Adapter, fetchHolding, fetchMarket as fetchBlueMarket, fetchMarketParams as fetchBlueMarketParams, fetchPosition as fetchBluePosition,
|
|
2
2
|
/** @deprecated Pre-liquidation support is deprecated and will be removed in the next major. */
|
|
3
3
|
fetchPreLiquidationParams as fetchBluePreLiquidationParams,
|
|
4
4
|
/** @deprecated Pre-liquidation support is deprecated and will be removed in the next major. */
|
|
5
|
-
fetchPreLiquidationPosition as fetchBluePreLiquidationPosition, fetchToken, fetchUser as fetchBlueUser, fetchVault, fetchVaultConfig, fetchVaultMarketAllocation, fetchVaultMarketConfig, fetchVaultUser, fetchVaultV2, fetchVaultV2Adapter, fetchVaultV2BlueMarketPublicAllocatorConfig, fetchVaultV2BluePublicAllocatorConfig, fetchVaultV2BluePublicAllocatorData, fetchVaultV2MorphoMarketV1Adapter, fetchVaultV2MorphoMarketV1AdapterV2, fetchVaultV2MorphoVaultV1Adapter, } from "@morpho-org/blue-sdk-viem";
|
|
5
|
+
fetchPreLiquidationPosition as fetchBluePreLiquidationPosition, fetchToken, fetchUser as fetchBlueUser, fetchVault, fetchVaultConfig, fetchVaultMarketAllocation, fetchVaultMarketConfig, fetchVaultUser, fetchVaultV2, fetchVaultV2Adapter, fetchVaultV2BlueMarketPublicAllocatorConfig, fetchVaultV2BluePublicAllocatorConfig, fetchVaultV2BluePublicAllocatorData, fetchVaultV2MidnightAdapter, fetchVaultV2MorphoMarketV1Adapter, fetchVaultV2MorphoMarketV1AdapterV2, fetchVaultV2MorphoVaultV1Adapter, } from "@morpho-org/blue-sdk-viem";
|
|
6
6
|
export { fetchAccrualPosition as fetchMidnightAccrualPosition, fetchMarket as fetchMidnightMarket, fetchMarketParams as fetchMidnightMarketParams, fetchPosition as fetchMidnightPosition, fetchRatifierInfo as fetchMidnightRatifierInfo, } from "@morpho-org/midnight-sdk";
|
package/lib/esm/fetch.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
export { fetchAccrualPosition as fetchBlueAccrualPosition, fetchAccrualVault, fetchAccrualVaultV2, fetchAccrualVaultV2Adapter, fetchAccrualVaultV2MorphoMarketV1Adapter, fetchAccrualVaultV2MorphoMarketV1AdapterV2, fetchAccrualVaultV2MorphoVaultV1Adapter, fetchHolding, fetchMarket as fetchBlueMarket, fetchMarketParams as fetchBlueMarketParams, fetchPosition as fetchBluePosition,
|
|
1
|
+
export { fetchAccrualPosition as fetchBlueAccrualPosition, fetchAccrualVault, fetchAccrualVaultV2, fetchAccrualVaultV2Adapter, fetchAccrualVaultV2MidnightAdapter, fetchAccrualVaultV2MorphoMarketV1Adapter, fetchAccrualVaultV2MorphoMarketV1AdapterV2, fetchAccrualVaultV2MorphoVaultV1Adapter, fetchHolding, fetchMarket as fetchBlueMarket, fetchMarketParams as fetchBlueMarketParams, fetchPosition as fetchBluePosition,
|
|
2
2
|
/** @deprecated Pre-liquidation support is deprecated and will be removed in the next major. */
|
|
3
3
|
fetchPreLiquidationParams as fetchBluePreLiquidationParams,
|
|
4
4
|
/** @deprecated Pre-liquidation support is deprecated and will be removed in the next major. */
|
|
5
|
-
fetchPreLiquidationPosition as fetchBluePreLiquidationPosition, fetchToken, fetchUser as fetchBlueUser, fetchVault, fetchVaultConfig, fetchVaultMarketAllocation, fetchVaultMarketConfig, fetchVaultUser, fetchVaultV2, fetchVaultV2Adapter, fetchVaultV2BlueMarketPublicAllocatorConfig, fetchVaultV2BluePublicAllocatorConfig, fetchVaultV2BluePublicAllocatorData, fetchVaultV2MorphoMarketV1Adapter, fetchVaultV2MorphoMarketV1AdapterV2, fetchVaultV2MorphoVaultV1Adapter, } from "@morpho-org/blue-sdk-viem";
|
|
5
|
+
fetchPreLiquidationPosition as fetchBluePreLiquidationPosition, fetchToken, fetchUser as fetchBlueUser, fetchVault, fetchVaultConfig, fetchVaultMarketAllocation, fetchVaultMarketConfig, fetchVaultUser, fetchVaultV2, fetchVaultV2Adapter, fetchVaultV2BlueMarketPublicAllocatorConfig, fetchVaultV2BluePublicAllocatorConfig, fetchVaultV2BluePublicAllocatorData, fetchVaultV2MidnightAdapter, fetchVaultV2MorphoMarketV1Adapter, fetchVaultV2MorphoMarketV1AdapterV2, fetchVaultV2MorphoVaultV1Adapter, } from "@morpho-org/blue-sdk-viem";
|
|
6
6
|
export { fetchAccrualPosition as fetchMidnightAccrualPosition, fetchMarket as fetchMidnightMarket, fetchMarketParams as fetchMidnightMarketParams, fetchPosition as fetchMidnightPosition, fetchRatifierInfo as fetchMidnightRatifierInfo, } from "@morpho-org/midnight-sdk";
|
|
@@ -21,8 +21,42 @@ export declare const MAX_SLIPPAGE_TOLERANCE: bigint;
|
|
|
21
21
|
export declare const DEFAULT_MAX_REALLOCATION_PENALTY = 0n;
|
|
22
22
|
/** Maximum Vault V2 reallocation penalty: 100%. */
|
|
23
23
|
export declare const MAX_REALLOCATION_PENALTY = 1000000000000000000n;
|
|
24
|
+
/**
|
|
25
|
+
* Maximum penalty rate a ZeroExLeverageBundlesV1 Lever accepts per public-allocator reallocation:
|
|
26
|
+
* 1%, WAD-scaled. Fixed; no caller option.
|
|
27
|
+
*/
|
|
28
|
+
export declare const LEVERAGE_MAX_REALLOCATION_PENALTY: bigint;
|
|
24
29
|
/** Default LLTV buffer: 0.5% below LLTV. Prevents instant liquidation on new positions. */
|
|
25
30
|
export declare const DEFAULT_LLTV_BUFFER: bigint;
|
|
31
|
+
/**
|
|
32
|
+
* SDK slippage ceiling per leverage action, WAD-scaled: `MAX_SLIPPAGE_TOLERANCE` (10%) for every action, the
|
|
33
|
+
* ceiling `fetchZeroExQuote` enforces, so the fetch and the builders cannot drift apart. Not configurable.
|
|
34
|
+
*/
|
|
35
|
+
export declare const LEVERAGE_MAX_EXECUTION_LOSS: Readonly<{
|
|
36
|
+
readonly lever: bigint;
|
|
37
|
+
readonly delever: bigint;
|
|
38
|
+
readonly close: bigint;
|
|
39
|
+
}>;
|
|
40
|
+
/**
|
|
41
|
+
* Largest amount a Lever's worst swap price (`maxSwapIn` per `minCollateralToBuy`) may be above the market's oracle
|
|
42
|
+
* price, WAD-scaled: 15%. Exactly 15% is accepted, and a price below the oracle, which favours the user, is never
|
|
43
|
+
* refused. Delever and Close are not checked. The worst price uses `maxSwapIn`, which already includes the caller's
|
|
44
|
+
* slippage, so the room left for a gap between 0x's price and the oracle is about 15% minus that slippage (5% at the
|
|
45
|
+
* 10% ceiling).
|
|
46
|
+
* Not configurable.
|
|
47
|
+
*/
|
|
48
|
+
export declare const LEVERAGE_MAX_ORACLE_DEVIATION: bigint;
|
|
49
|
+
/** Leverage deadline window after the data block, in seconds (1 hour). */
|
|
50
|
+
export declare const LEVERAGE_DEADLINE_WINDOW = 3600n;
|
|
51
|
+
/**
|
|
52
|
+
* Margin applied to the interest a Close's debt may accrue before its deadline: the buffer is the debt accrued for
|
|
53
|
+
* the one-hour deadline window at 4× the data block's borrow rate. The factor matches the AdaptiveCurveIrm curve
|
|
54
|
+
* steepness (`AdaptiveCurveIrmLib.CURVE_STEEPNESS` in blue-sdk), the most utilization can raise the rate over its
|
|
55
|
+
* rate at target, while that rate at target itself drifts by well under 1% in an hour (`ADJUSTMENT_SPEED` is 50 per
|
|
56
|
+
* year). It does not cover a rate that rises more than 4×, such as one quoted below target that jumps to full
|
|
57
|
+
* utilization; the Close then reverts instead of overpaying. Fixed; no caller option.
|
|
58
|
+
*/
|
|
59
|
+
export declare const LEVERAGE_CLOSE_INTEREST_BUFFER_FACTOR = 4n;
|
|
26
60
|
/**
|
|
27
61
|
* Forward interest-accrual window, in seconds (2 hours), reserved in target-market
|
|
28
62
|
* cap checks (BluePublicAllocator max-in, Vault V2 absolute and relative caps) when
|
|
@@ -23,8 +23,42 @@ export const MAX_SLIPPAGE_TOLERANCE = MathLib.WAD / 10n;
|
|
|
23
23
|
export const DEFAULT_MAX_REALLOCATION_PENALTY = 0n;
|
|
24
24
|
/** Maximum Vault V2 reallocation penalty: 100%. */
|
|
25
25
|
export const MAX_REALLOCATION_PENALTY = MathLib.WAD;
|
|
26
|
+
/**
|
|
27
|
+
* Maximum penalty rate a ZeroExLeverageBundlesV1 Lever accepts per public-allocator reallocation:
|
|
28
|
+
* 1%, WAD-scaled. Fixed; no caller option.
|
|
29
|
+
*/
|
|
30
|
+
export const LEVERAGE_MAX_REALLOCATION_PENALTY = MathLib.WAD / 100n;
|
|
26
31
|
/** Default LLTV buffer: 0.5% below LLTV. Prevents instant liquidation on new positions. */
|
|
27
32
|
export const DEFAULT_LLTV_BUFFER = MathLib.WAD / 200n;
|
|
33
|
+
/**
|
|
34
|
+
* SDK slippage ceiling per leverage action, WAD-scaled: `MAX_SLIPPAGE_TOLERANCE` (10%) for every action, the
|
|
35
|
+
* ceiling `fetchZeroExQuote` enforces, so the fetch and the builders cannot drift apart. Not configurable.
|
|
36
|
+
*/
|
|
37
|
+
export const LEVERAGE_MAX_EXECUTION_LOSS = Object.freeze({
|
|
38
|
+
lever: MAX_SLIPPAGE_TOLERANCE,
|
|
39
|
+
delever: MAX_SLIPPAGE_TOLERANCE,
|
|
40
|
+
close: MAX_SLIPPAGE_TOLERANCE,
|
|
41
|
+
});
|
|
42
|
+
/**
|
|
43
|
+
* Largest amount a Lever's worst swap price (`maxSwapIn` per `minCollateralToBuy`) may be above the market's oracle
|
|
44
|
+
* price, WAD-scaled: 15%. Exactly 15% is accepted, and a price below the oracle, which favours the user, is never
|
|
45
|
+
* refused. Delever and Close are not checked. The worst price uses `maxSwapIn`, which already includes the caller's
|
|
46
|
+
* slippage, so the room left for a gap between 0x's price and the oracle is about 15% minus that slippage (5% at the
|
|
47
|
+
* 10% ceiling).
|
|
48
|
+
* Not configurable.
|
|
49
|
+
*/
|
|
50
|
+
export const LEVERAGE_MAX_ORACLE_DEVIATION = (MathLib.WAD * 15n) / 100n;
|
|
51
|
+
/** Leverage deadline window after the data block, in seconds (1 hour). */
|
|
52
|
+
export const LEVERAGE_DEADLINE_WINDOW = 3600n;
|
|
53
|
+
/**
|
|
54
|
+
* Margin applied to the interest a Close's debt may accrue before its deadline: the buffer is the debt accrued for
|
|
55
|
+
* the one-hour deadline window at 4× the data block's borrow rate. The factor matches the AdaptiveCurveIrm curve
|
|
56
|
+
* steepness (`AdaptiveCurveIrmLib.CURVE_STEEPNESS` in blue-sdk), the most utilization can raise the rate over its
|
|
57
|
+
* rate at target, while that rate at target itself drifts by well under 1% in an hour (`ADJUSTMENT_SPEED` is 50 per
|
|
58
|
+
* year). It does not cover a rate that rises more than 4×, such as one quoted below target that jumps to full
|
|
59
|
+
* utilization; the Close then reverts instead of overpaying. Fixed; no caller option.
|
|
60
|
+
*/
|
|
61
|
+
export const LEVERAGE_CLOSE_INTEREST_BUFFER_FACTOR = 4n;
|
|
28
62
|
/**
|
|
29
63
|
* Forward interest-accrual window, in seconds (2 hours), reserved in target-market
|
|
30
64
|
* cap checks (BluePublicAllocator max-in, Vault V2 absolute and relative caps) when
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { AccrualVaultV2MorphoMarketV1Adapter, AccrualVaultV2MorphoMarketV1AdapterV2, AccrualVaultV2MorphoVaultV1Adapter, MarketParams, VaultV2MorphoMarketV1Adapter, VaultV2MorphoMarketV1AdapterV2, VaultV2MorphoVaultV1Adapter, } from "@morpho-org/blue-sdk";
|
|
1
|
+
import { AccrualVaultV2MidnightAdapter, AccrualVaultV2MorphoMarketV1Adapter, AccrualVaultV2MorphoMarketV1AdapterV2, AccrualVaultV2MorphoVaultV1Adapter, MarketParams, VaultV2MorphoMarketV1Adapter, VaultV2MorphoMarketV1AdapterV2, VaultV2MorphoVaultV1Adapter, } from "@morpho-org/blue-sdk";
|
|
2
2
|
import { InsufficientDeadSharesError, MissingDeadSharesDataError, } from "../types/error.js";
|
|
3
3
|
import { MIN_DEAD_SHARES, MIN_VAULT_V2_DEAD_ASSETS } from "./constant.js";
|
|
4
4
|
/**
|
|
@@ -188,6 +188,9 @@ function getDeadSharesAbsoluteCap(id, { absoluteCaps, entity, adapter, }) {
|
|
|
188
188
|
}
|
|
189
189
|
/** Checks the currently allocated positions of one supported adapter. @internal */
|
|
190
190
|
function assertAdapterDeadShares(adapter, { absoluteCaps, entity, }) {
|
|
191
|
+
if (adapter instanceof AccrualVaultV2MidnightAdapter) {
|
|
192
|
+
return;
|
|
193
|
+
}
|
|
191
194
|
if (adapter instanceof AccrualVaultV2MorphoVaultV1Adapter) {
|
|
192
195
|
const id = VaultV2MorphoVaultV1Adapter.adapterCapId(adapter.address);
|
|
193
196
|
if (getDeadSharesAbsoluteCap(id, {
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { type Address } from "viem";
|
|
2
|
+
/**
|
|
3
|
+
* Returns the ZeroExLeverageBundlesV1 address registered for `chainId`, whether or not the bundle
|
|
4
|
+
* can run there.
|
|
5
|
+
*
|
|
6
|
+
* @param chainId - Target chain id.
|
|
7
|
+
* @returns The registered ZeroExLeverageBundlesV1 address.
|
|
8
|
+
* @throws {UnsupportedChainIdError} when `chainId` is absent from the address registry.
|
|
9
|
+
* @throws {LeverageUnsupportedChainError} with reason `noBundle` when no bundle, the zero address or a value that
|
|
10
|
+
* is not an address is registered.
|
|
11
|
+
* @internal
|
|
12
|
+
*/
|
|
13
|
+
export declare const getRegisteredZeroExLeverageBundle: (chainId: number) => Address;
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { getChainAddresses } from "@morpho-org/blue-sdk";
|
|
2
|
+
import { isAddress, isAddressEqual, zeroAddress } from "viem";
|
|
3
|
+
import { LeverageUnsupportedChainError } from "../types/index.js";
|
|
4
|
+
/**
|
|
5
|
+
* Returns the ZeroExLeverageBundlesV1 address registered for `chainId`, whether or not the bundle
|
|
6
|
+
* can run there.
|
|
7
|
+
*
|
|
8
|
+
* @param chainId - Target chain id.
|
|
9
|
+
* @returns The registered ZeroExLeverageBundlesV1 address.
|
|
10
|
+
* @throws {UnsupportedChainIdError} when `chainId` is absent from the address registry.
|
|
11
|
+
* @throws {LeverageUnsupportedChainError} with reason `noBundle` when no bundle, the zero address or a value that
|
|
12
|
+
* is not an address is registered.
|
|
13
|
+
* @internal
|
|
14
|
+
*/
|
|
15
|
+
export const getRegisteredZeroExLeverageBundle = (chainId) => {
|
|
16
|
+
const bundle = getChainAddresses(chainId).bundles?.zeroExLeverageBundlesV1;
|
|
17
|
+
if (typeof bundle !== "string" ||
|
|
18
|
+
!isAddress(bundle, { strict: false }) ||
|
|
19
|
+
isAddressEqual(bundle, zeroAddress)) {
|
|
20
|
+
throw new LeverageUnsupportedChainError({ chainId, reason: "noBundle" });
|
|
21
|
+
}
|
|
22
|
+
return bundle;
|
|
23
|
+
};
|
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
export { getMidnightBlueBuyCallbackAddress, getMidnightBlueBuyCallbackData, } from "./callback.js";
|
|
2
|
-
export { APPROVE_ONLY_ONCE_TOKENS, DEFAULT_ALLOCATOR_CAP_HEADROOM, DEFAULT_CAP_ACCRUAL_BUFFER, DEFAULT_LLTV_BUFFER, DEFAULT_MAX_REALLOCATION_PENALTY, DEFAULT_SUPPLY_TARGET_UTILIZATION, DEFAULT_WITHDRAWAL_TARGET_UTILIZATION, MAX_ABSOLUTE_SHARE_PRICE, MAX_REALLOCATION_PENALTY, MAX_SLIPPAGE_TOLERANCE, MAX_TOKEN_APPROVALS, MIDNIGHT_MIN_BORROW_TIME_TO_MATURITY, MIDNIGHT_TAKE_MAX_DEADLINE_SECONDS, MIN_DEAD_SHARES, MIN_VAULT_V2_DEAD_ASSETS, VAULT_DEPOSIT_MAX_DEADLINE_SECONDS, } from "./constant.js";
|
|
2
|
+
export { APPROVE_ONLY_ONCE_TOKENS, DEFAULT_ALLOCATOR_CAP_HEADROOM, DEFAULT_CAP_ACCRUAL_BUFFER, DEFAULT_LLTV_BUFFER, DEFAULT_MAX_REALLOCATION_PENALTY, DEFAULT_SUPPLY_TARGET_UTILIZATION, DEFAULT_WITHDRAWAL_TARGET_UTILIZATION, LEVERAGE_CLOSE_INTEREST_BUFFER_FACTOR, LEVERAGE_DEADLINE_WINDOW, LEVERAGE_MAX_EXECUTION_LOSS, LEVERAGE_MAX_ORACLE_DEVIATION, LEVERAGE_MAX_REALLOCATION_PENALTY, MAX_ABSOLUTE_SHARE_PRICE, MAX_REALLOCATION_PENALTY, MAX_SLIPPAGE_TOLERANCE, MAX_TOKEN_APPROVALS, MIDNIGHT_MIN_BORROW_TIME_TO_MATURITY, MIDNIGHT_TAKE_MAX_DEADLINE_SECONDS, MIN_DEAD_SHARES, MIN_VAULT_V2_DEAD_ASSETS, VAULT_DEPOSIT_MAX_DEADLINE_SECONDS, } from "./constant.js";
|
|
3
3
|
export { validateBlueMarketDeadShares, validateVaultV1DeadShares, validateVaultV2DeadShares, } from "./deadShares.js";
|
|
4
|
+
export * from "./leverage/index.js";
|
|
5
|
+
export { computeLeveragePenaltyAssets, type LeverageAllocatorState, type LeverageReallocation, validateLeverageReallocations, } from "./leverage/reallocations.js";
|
|
4
6
|
export { addTransactionMetadata } from "./metadata.js";
|
|
5
7
|
export { type PreviewVaultV2ForceWithdrawParams, previewVaultV2ForceWithdraw, type VaultV2ForceWithdrawPreview, } from "./previewVaultV2ForceWithdraw.js";
|
|
6
8
|
export { type PreviewVaultV2InKindRedeemParams, previewVaultV2InKindRedeem, type VaultV2InKindRedeemMarketPreview, } from "./previewVaultV2InKindRedeem.js";
|
|
@@ -11,3 +13,4 @@ export { getMidnightMaxSafeDebt, validateAccrualPosition, validateChainId, valid
|
|
|
11
13
|
export { validateOfferSides } from "./validateOfferSides.js";
|
|
12
14
|
export { type RequirementSpenderKey, validateRequirementSpender, } from "./validateRequirementSpender.js";
|
|
13
15
|
export { computeVaultV2ForceWithdrawFeeSharesMinted, computeVaultV2ForceWithdrawMinSharesBurnt, computeVaultV2ForceWithdrawPlan, computeVaultV2ForceWithdrawSharesBurnt, resolveVaultV2ForceWithdrawEligibility, type VaultV2ForceWithdrawEligibility, type VaultV2ForceWithdrawPlan, } from "./vaultV2ForceWithdrawPlan.js";
|
|
16
|
+
export { getZeroExSwapRoute, validateZeroExQuote, type ZeroExSwapRoute, } from "./zeroExQuote.js";
|
package/lib/esm/helpers/index.js
CHANGED
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
export { getMidnightBlueBuyCallbackAddress, getMidnightBlueBuyCallbackData, } from "./callback.js";
|
|
2
|
-
export { APPROVE_ONLY_ONCE_TOKENS, DEFAULT_ALLOCATOR_CAP_HEADROOM, DEFAULT_CAP_ACCRUAL_BUFFER, DEFAULT_LLTV_BUFFER, DEFAULT_MAX_REALLOCATION_PENALTY, DEFAULT_SUPPLY_TARGET_UTILIZATION, DEFAULT_WITHDRAWAL_TARGET_UTILIZATION, MAX_ABSOLUTE_SHARE_PRICE, MAX_REALLOCATION_PENALTY, MAX_SLIPPAGE_TOLERANCE, MAX_TOKEN_APPROVALS, MIDNIGHT_MIN_BORROW_TIME_TO_MATURITY, MIDNIGHT_TAKE_MAX_DEADLINE_SECONDS, MIN_DEAD_SHARES, MIN_VAULT_V2_DEAD_ASSETS, VAULT_DEPOSIT_MAX_DEADLINE_SECONDS, } from "./constant.js";
|
|
2
|
+
export { APPROVE_ONLY_ONCE_TOKENS, DEFAULT_ALLOCATOR_CAP_HEADROOM, DEFAULT_CAP_ACCRUAL_BUFFER, DEFAULT_LLTV_BUFFER, DEFAULT_MAX_REALLOCATION_PENALTY, DEFAULT_SUPPLY_TARGET_UTILIZATION, DEFAULT_WITHDRAWAL_TARGET_UTILIZATION, LEVERAGE_CLOSE_INTEREST_BUFFER_FACTOR, LEVERAGE_DEADLINE_WINDOW, LEVERAGE_MAX_EXECUTION_LOSS, LEVERAGE_MAX_ORACLE_DEVIATION, LEVERAGE_MAX_REALLOCATION_PENALTY, MAX_ABSOLUTE_SHARE_PRICE, MAX_REALLOCATION_PENALTY, MAX_SLIPPAGE_TOLERANCE, MAX_TOKEN_APPROVALS, MIDNIGHT_MIN_BORROW_TIME_TO_MATURITY, MIDNIGHT_TAKE_MAX_DEADLINE_SECONDS, MIN_DEAD_SHARES, MIN_VAULT_V2_DEAD_ASSETS, VAULT_DEPOSIT_MAX_DEADLINE_SECONDS, } from "./constant.js";
|
|
3
3
|
export { validateBlueMarketDeadShares, validateVaultV1DeadShares, validateVaultV2DeadShares, } from "./deadShares.js";
|
|
4
|
+
export * from "./leverage/index.js";
|
|
5
|
+
export { computeLeveragePenaltyAssets, validateLeverageReallocations, } from "./leverage/reallocations.js";
|
|
4
6
|
export { addTransactionMetadata } from "./metadata.js";
|
|
5
7
|
export { previewVaultV2ForceWithdraw, } from "./previewVaultV2ForceWithdraw.js";
|
|
6
8
|
export { previewVaultV2InKindRedeem, } from "./previewVaultV2InKindRedeem.js";
|
|
@@ -11,3 +13,4 @@ export { getMidnightMaxSafeDebt, validateAccrualPosition, validateChainId, valid
|
|
|
11
13
|
export { validateOfferSides } from "./validateOfferSides.js";
|
|
12
14
|
export { validateRequirementSpender, } from "./validateRequirementSpender.js";
|
|
13
15
|
export { computeVaultV2ForceWithdrawFeeSharesMinted, computeVaultV2ForceWithdrawMinSharesBurnt, computeVaultV2ForceWithdrawPlan, computeVaultV2ForceWithdrawSharesBurnt, resolveVaultV2ForceWithdrawEligibility, } from "./vaultV2ForceWithdrawPlan.js";
|
|
16
|
+
export { getZeroExSwapRoute, validateZeroExQuote, } from "./zeroExQuote.js";
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { type CloseLimits, type CloseLimitsParams, computeCloseInterestBuffer, computeCloseLimits, computeDeleverLimits, computeLeverageOracleDeviation, computeLeverLimits, type DeleverLimits, type DeleverLimitsParams, type LeverageActionOracleDeviation, type LeverageLimitsData, type LeverageLimitsInput, type LeverageOperation, type LeverageOracleDeviation, type LeverageOracleDeviationParams, type LeverageQuoteAmounts, type LeverLimits, type LeverLimitsParams, leverageDeadline, validateLeverageInputs, } from "./limits.js";
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { computeCloseInterestBuffer, computeCloseLimits, computeDeleverLimits, computeLeverageOracleDeviation, computeLeverLimits, leverageDeadline, validateLeverageInputs, } from "./limits.js";
|