@morpho-org/morpho-sdk 10.5.0-next.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 +793 -0
- package/lib/cjs/abis.js +811 -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/midnight/supplyCollateralTakeBorrow.js +16 -11
- package/lib/cjs/actions/midnight/takeBorrow.js +14 -8
- package/lib/cjs/actions/midnight/takeLend.js +15 -9
- package/lib/cjs/actions/midnight/takeRepayWithdrawCollateral.js +19 -13
- package/lib/cjs/actions/midnight/takeWithdraw.js +14 -8
- 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/addresses.d.ts +1 -1
- package/lib/cjs/blue/addresses.js +6 -1
- package/lib/cjs/constants.d.ts +1 -1
- package/lib/cjs/constants.js +7 -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 +1 -1
- package/lib/cjs/entities/midnight/midnight.d.ts +6 -0
- package/lib/cjs/entities/midnight/midnight.js +21 -2
- package/lib/cjs/entities/requirements/assertContractCode.d.ts +0 -23
- package/lib/cjs/entities/requirements/assertContractCode.js +3 -28
- package/lib/cjs/entities/vaultV2BlueReallocationData.d.ts +117 -0
- package/lib/cjs/entities/vaultV2BlueReallocationData.js +226 -2
- package/lib/cjs/helpers/constant.d.ts +41 -0
- package/lib/cjs/helpers/constant.js +42 -1
- 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 +29 -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/validate.d.ts +14 -0
- package/lib/cjs/helpers/validate.js +25 -1
- 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/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/transactionPlan/midnight/takeBorrow.d.ts +4 -0
- package/lib/cjs/transactionPlan/midnight/takeBorrow.js +8 -2
- package/lib/cjs/types/action.d.ts +130 -1
- package/lib/cjs/types/error.d.ts +84 -0
- package/lib/cjs/types/error.js +110 -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/version.d.ts +1 -1
- package/lib/cjs/version.js +1 -1
- package/lib/esm/abis.d.ts +793 -0
- package/lib/esm/abis.js +809 -0
- 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/midnight/supplyCollateralTakeBorrow.js +16 -11
- package/lib/esm/actions/midnight/takeBorrow.js +14 -8
- package/lib/esm/actions/midnight/takeLend.js +15 -9
- package/lib/esm/actions/midnight/takeRepayWithdrawCollateral.js +19 -13
- package/lib/esm/actions/midnight/takeWithdraw.js +14 -8
- 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/addresses.d.ts +1 -1
- package/lib/esm/blue/addresses.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 +1 -1
- package/lib/esm/entities/midnight/midnight.d.ts +6 -0
- package/lib/esm/entities/midnight/midnight.js +21 -2
- package/lib/esm/entities/requirements/assertContractCode.d.ts +0 -23
- package/lib/esm/entities/requirements/assertContractCode.js +1 -25
- package/lib/esm/entities/vaultV2BlueReallocationData.d.ts +117 -0
- package/lib/esm/entities/vaultV2BlueReallocationData.js +227 -3
- package/lib/esm/helpers/constant.d.ts +41 -0
- package/lib/esm/helpers/constant.js +41 -0
- 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/validate.d.ts +14 -0
- package/lib/esm/helpers/validate.js +25 -2
- 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/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/transactionPlan/midnight/takeBorrow.d.ts +4 -0
- package/lib/esm/transactionPlan/midnight/takeBorrow.js +9 -3
- package/lib/esm/types/action.d.ts +130 -1
- package/lib/esm/types/error.d.ts +84 -0
- package/lib/esm/types/error.js +103 -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/version.d.ts +1 -1
- package/lib/esm/version.js +1 -1
- package/package.json +7 -7
|
@@ -0,0 +1,472 @@
|
|
|
1
|
+
import { type AccrualPosition } from "@morpho-org/blue-sdk";
|
|
2
|
+
import { LEVERAGE_MAX_EXECUTION_LOSS } from "../constant.js";
|
|
3
|
+
/** Leverage action whose limits are computed. */
|
|
4
|
+
export type LeverageOperation = keyof typeof LEVERAGE_MAX_EXECUTION_LOSS;
|
|
5
|
+
/**
|
|
6
|
+
* Amounts of a 0x allowance-holder quote that the leverage limits read, in each token's smallest
|
|
7
|
+
* unit; a 0x quote of the same mode satisfies it. `exactInput` quotes (Delever)
|
|
8
|
+
* sell exactly `sellAmount` for an expected `buyAmount`, before slippage, and at least `minBuyAmount` after it. `exactOutput` quotes
|
|
9
|
+
* (Lever, Close) buy exactly `buyAmount` and spend at most `maxSellAmount`, which
|
|
10
|
+
* already includes the slippage the caller passed to 0x: the Settler pulls that whole amount and
|
|
11
|
+
* refunds the rest, so it is the swap's input cap as is. These amounts carry no slippage of their
|
|
12
|
+
* own, so the limits cannot tell a quote fetched with another tolerance: pass amounts from a quote
|
|
13
|
+
* fetched with the same `slippage`. The leverage builders check that on the full quote and throw
|
|
14
|
+
* `LeverageQuoteSlippageMismatchError`.
|
|
15
|
+
*/
|
|
16
|
+
export type LeverageQuoteAmounts = {
|
|
17
|
+
readonly mode: "exactInput";
|
|
18
|
+
readonly sellAmount: bigint;
|
|
19
|
+
readonly buyAmount: bigint;
|
|
20
|
+
readonly minBuyAmount: bigint;
|
|
21
|
+
} | {
|
|
22
|
+
readonly mode: "exactOutput";
|
|
23
|
+
readonly maxSellAmount: bigint;
|
|
24
|
+
readonly buyAmount: bigint;
|
|
25
|
+
};
|
|
26
|
+
/**
|
|
27
|
+
* One-block state the leverage limits read: the block timestamp, the user's position on the
|
|
28
|
+
* action's market as stored at that block, not accrued to its timestamp, with the market's own oracle price
|
|
29
|
+
* when it could be read (it may be absent), and the market's per-second
|
|
30
|
+
* borrow rate at that block (WAD-scaled). Read all three at the same block:
|
|
31
|
+
* `MorphoBlue.getLeverageData` returns a `BlueLeverageData`, which extends this type, or build
|
|
32
|
+
* it as below.
|
|
33
|
+
*
|
|
34
|
+
* @example
|
|
35
|
+
* ```ts
|
|
36
|
+
* import { fetchAccrualPosition } from "@morpho-org/blue-sdk-viem";
|
|
37
|
+
* import type { LeverageLimitsData } from "@morpho-org/morpho-sdk";
|
|
38
|
+
* import { createPublicClient, http } from "viem";
|
|
39
|
+
* import { base } from "viem/chains";
|
|
40
|
+
*
|
|
41
|
+
* // The funded WETH/USDC position every leverage limits example reads: `userAddress` holds 30 WETH of
|
|
42
|
+
* // collateral against 60,060 USDC of debt on the WETH/USDC market, at block timestamp 1_700_000_000n,
|
|
43
|
+
* // and the market oracle reads 3,000 USDC per WETH.
|
|
44
|
+
* const client = createPublicClient({ chain: base, transport: http() });
|
|
45
|
+
* const block = await client.getBlock();
|
|
46
|
+
* const fetched = await fetchAccrualPosition(
|
|
47
|
+
* userAddress,
|
|
48
|
+
* wethUsdcMarketParams.id,
|
|
49
|
+
* client,
|
|
50
|
+
* { blockNumber: block.number },
|
|
51
|
+
* );
|
|
52
|
+
* // Pass the position as stored, as `getLeverageData` does: the limits accrue it once from the market's last
|
|
53
|
+
* // update, as Blue does. The borrow rate is read from a copy accrued to the block.
|
|
54
|
+
* const leverageData: LeverageLimitsData = {
|
|
55
|
+
* block: { timestamp: block.timestamp },
|
|
56
|
+
* position: fetched,
|
|
57
|
+
* borrowRate: fetched.market
|
|
58
|
+
* .accrueInterest(block.timestamp)
|
|
59
|
+
* .getEndBorrowRate(block.timestamp),
|
|
60
|
+
* };
|
|
61
|
+
* ```
|
|
62
|
+
*/
|
|
63
|
+
export interface LeverageLimitsData {
|
|
64
|
+
readonly block: {
|
|
65
|
+
readonly timestamp: bigint;
|
|
66
|
+
};
|
|
67
|
+
readonly position: AccrualPosition;
|
|
68
|
+
readonly borrowRate: bigint;
|
|
69
|
+
}
|
|
70
|
+
/** Caller inputs shared by every leverage action. */
|
|
71
|
+
export interface LeverageLimitsInput {
|
|
72
|
+
readonly quote: LeverageQuoteAmounts;
|
|
73
|
+
readonly slippage: bigint;
|
|
74
|
+
readonly leverageData: LeverageLimitsData;
|
|
75
|
+
}
|
|
76
|
+
/** Caller inputs of {@link computeLeverLimits}. */
|
|
77
|
+
export interface LeverLimitsParams extends LeverageLimitsInput {
|
|
78
|
+
readonly intent: {
|
|
79
|
+
readonly collateralAssets: bigint;
|
|
80
|
+
readonly loanAssets: bigint;
|
|
81
|
+
};
|
|
82
|
+
readonly penaltyAssets: bigint;
|
|
83
|
+
}
|
|
84
|
+
/** Caller inputs of {@link computeDeleverLimits}: the quote's `sellAmount` is the collateral sold. */
|
|
85
|
+
export type DeleverLimitsParams = LeverageLimitsInput;
|
|
86
|
+
/** Caller inputs of {@link computeCloseLimits}: an exact-output quote buys the debt plus its interest buffer. */
|
|
87
|
+
export type CloseLimitsParams = LeverageLimitsInput;
|
|
88
|
+
/** Signed limits of a `zeroExLeverageBundlesV1Lever` call. */
|
|
89
|
+
export interface LeverLimits {
|
|
90
|
+
readonly minCollateralToBuy: bigint;
|
|
91
|
+
readonly maxBorrowAssets: bigint;
|
|
92
|
+
readonly maxSwapIn: bigint;
|
|
93
|
+
readonly penaltyAssets: bigint;
|
|
94
|
+
readonly maxLtv: bigint;
|
|
95
|
+
readonly deadline: bigint;
|
|
96
|
+
/** Worst price against the oracle, from {@link computeLeverageOracleDeviation}; at most 15% above it. */
|
|
97
|
+
readonly oracleDeviation: LeverageOracleDeviation;
|
|
98
|
+
}
|
|
99
|
+
/** Signed limits of a `zeroExLeverageBundlesV1Delever` call. */
|
|
100
|
+
export interface DeleverLimits {
|
|
101
|
+
readonly maxCollateralToSell: bigint;
|
|
102
|
+
readonly minRepayAssets: bigint;
|
|
103
|
+
readonly maxLtv: bigint;
|
|
104
|
+
readonly deadline: bigint;
|
|
105
|
+
/** Worst fill against the oracle, from {@link computeLeverageOracleDeviation}; reported, never refused. */
|
|
106
|
+
readonly oracleDeviation: LeverageOracleDeviation;
|
|
107
|
+
}
|
|
108
|
+
/** Signed limits of a `zeroExLeverageBundlesV1Close` call. */
|
|
109
|
+
export interface CloseLimits {
|
|
110
|
+
readonly maxCollateralIn: bigint;
|
|
111
|
+
readonly minLoanOut: bigint;
|
|
112
|
+
readonly deadline: bigint;
|
|
113
|
+
/** Worst fill against the oracle, from {@link computeLeverageOracleDeviation}; reported, never refused. */
|
|
114
|
+
readonly oracleDeviation: LeverageOracleDeviation;
|
|
115
|
+
}
|
|
116
|
+
/** A leverage action's worst signed price against the market oracle, from {@link computeLeverageOracleDeviation}. */
|
|
117
|
+
export interface LeverageOracleDeviation {
|
|
118
|
+
/** Worst price the action signs, loan-token units per collateral-token unit scaled by `ORACLE_PRICE_SCALE`, rounded down. */
|
|
119
|
+
readonly worstPrice: bigint;
|
|
120
|
+
/** Market oracle price at the data block, scaled by `ORACLE_PRICE_SCALE`. */
|
|
121
|
+
readonly oraclePrice: bigint;
|
|
122
|
+
/** Deviation from the oracle price, WAD-scaled, positive when it costs the user, rounded up. */
|
|
123
|
+
readonly deviation: bigint;
|
|
124
|
+
}
|
|
125
|
+
/**
|
|
126
|
+
* Oracle deviation a Lever, Delever or Close reports in its action metadata: `"measured"` with the worst price, the
|
|
127
|
+
* oracle price and the deviation. Every one of them swaps, so every one measures it: a Close without debt refuses
|
|
128
|
+
* with `LeverageCloseWithoutDebtError`.
|
|
129
|
+
*/
|
|
130
|
+
export type LeverageActionOracleDeviation = {
|
|
131
|
+
readonly status: "measured";
|
|
132
|
+
} & LeverageOracleDeviation;
|
|
133
|
+
/**
|
|
134
|
+
* Returns the deadline of a leverage action: the data block's timestamp plus
|
|
135
|
+
* `LEVERAGE_DEADLINE_WINDOW` (1 hour). The caller cannot set it. It is the `deadline` to pass to
|
|
136
|
+
* `fetchZeroExQuote` and `validateZeroExQuote`, so the quote's Settler permit carries the deadline the action signs.
|
|
137
|
+
*
|
|
138
|
+
* @param leverageData - One-block leverage data.
|
|
139
|
+
* @returns Deadline in Unix seconds.
|
|
140
|
+
* @throws {InvalidBigIntInputError} when the data block timestamp is not a bigint.
|
|
141
|
+
* @throws {NonPositiveInputError} when the deadline is zero or negative.
|
|
142
|
+
* @throws {InputExceedsMaxError} when the deadline exceeds `uint256`.
|
|
143
|
+
* @example
|
|
144
|
+
* ```ts
|
|
145
|
+
* import { leverageDeadline } from "@morpho-org/morpho-sdk";
|
|
146
|
+
*
|
|
147
|
+
* // `leverageData`: the funded WETH/USDC position of the `LeverageLimitsData` example.
|
|
148
|
+
* const deadline = leverageDeadline(leverageData);
|
|
149
|
+
* // leverageData.block.timestamp === 1_700_000_000n
|
|
150
|
+
* // deadline === 1_700_003_600n
|
|
151
|
+
* ```
|
|
152
|
+
*/
|
|
153
|
+
export declare const leverageDeadline: (leverageData: LeverageLimitsData) => bigint;
|
|
154
|
+
/**
|
|
155
|
+
* Validates the caller inputs shared by every leverage action and returns the position accrued to
|
|
156
|
+
* the data block. Slippage must be between zero and the action's
|
|
157
|
+
* `LEVERAGE_MAX_EXECUTION_LOSS`, and the quote must fix the side the action requires with positive
|
|
158
|
+
* amounts.
|
|
159
|
+
*
|
|
160
|
+
* @param params - Shared leverage inputs.
|
|
161
|
+
* @param params.operation - Leverage action.
|
|
162
|
+
* @param params.quote - Quote amounts.
|
|
163
|
+
* @param params.slippage - Caller slippage, WAD-scaled.
|
|
164
|
+
* @param params.leverageData - One-block leverage data.
|
|
165
|
+
* @returns The leverage data position accrued to the data block's timestamp.
|
|
166
|
+
* @throws {InvalidBigIntInputError} when `slippage`, `quote.buyAmount`, the quote's sell amount
|
|
167
|
+
* (`sellAmount`, or `maxSellAmount` for exact output), an exact-input quote's `minBuyAmount` or the data
|
|
168
|
+
* block timestamp is missing or not a bigint.
|
|
169
|
+
* @throws {InvalidLeverageOperationError} when `operation` is missing or not `lever`, `delever` or `close`.
|
|
170
|
+
* @throws {NegativeInputError} when `slippage` is negative.
|
|
171
|
+
* @throws {LeverageSlippageAboveLimitError} when `slippage` exceeds the action's limit.
|
|
172
|
+
* @throws {NonPositiveInputError} when the quote's sell amount or `buyAmount` is not positive.
|
|
173
|
+
* @throws {ZeroExQuoteMinBuyAmountBelowSlippageError} when an exact-input quote's `minBuyAmount` is zero or below
|
|
174
|
+
* `buyAmount × (1 − slippage)`, the slippage rounded down to whole parts per million.
|
|
175
|
+
* @throws {ZeroExQuoteRequiredError} when the quote is missing.
|
|
176
|
+
* @throws {ZeroExQuoteTypeMismatchError} when the quote fixes the wrong side.
|
|
177
|
+
* @throws {UnsupportedMarketIrmError} when accruing the position's debt needs an unsupported IRM.
|
|
178
|
+
* @throws {BlueErrors.TotalOverflow} when accruing the market's interest overflows.
|
|
179
|
+
* @example
|
|
180
|
+
* ```ts
|
|
181
|
+
* import { validateLeverageInputs } from "@morpho-org/morpho-sdk";
|
|
182
|
+
*
|
|
183
|
+
* // `leverageData`: the funded WETH/USDC position of the `LeverageLimitsData` example.
|
|
184
|
+
* const accrued = validateLeverageInputs({
|
|
185
|
+
* operation: "delever",
|
|
186
|
+
* quote: {
|
|
187
|
+
* mode: "exactInput",
|
|
188
|
+
* sellAmount: 10n ** 19n,
|
|
189
|
+
* buyAmount: 29_970_000_000n,
|
|
190
|
+
* minBuyAmount: 29_820_150_000n,
|
|
191
|
+
* },
|
|
192
|
+
* slippage: 5_000_000_000_000_000n,
|
|
193
|
+
* leverageData,
|
|
194
|
+
* });
|
|
195
|
+
* ```
|
|
196
|
+
*/
|
|
197
|
+
export declare const validateLeverageInputs: (params: LeverageLimitsInput & {
|
|
198
|
+
readonly operation: LeverageOperation;
|
|
199
|
+
}) => AccrualPosition;
|
|
200
|
+
/** Inputs of {@link computeLeverageOracleDeviation}: a leverage action's signed swap bounds and the oracle price. */
|
|
201
|
+
export type LeverageOracleDeviationParams = {
|
|
202
|
+
readonly oraclePrice: bigint;
|
|
203
|
+
} & ({
|
|
204
|
+
readonly operation: "lever";
|
|
205
|
+
readonly limits: Pick<LeverLimits, "maxSwapIn" | "minCollateralToBuy">;
|
|
206
|
+
} | {
|
|
207
|
+
readonly operation: "delever";
|
|
208
|
+
readonly limits: Pick<DeleverLimits, "maxCollateralToSell" | "minRepayAssets">;
|
|
209
|
+
} | {
|
|
210
|
+
readonly operation: "close";
|
|
211
|
+
readonly limits: Pick<CloseLimits, "maxCollateralIn" | "minLoanOut">;
|
|
212
|
+
});
|
|
213
|
+
/**
|
|
214
|
+
* Computes how far a leverage action's worst signed execution price is from the market's oracle price, relative to
|
|
215
|
+
* the oracle value of the collateral traded, WAD-scaled and signed so that a positive value costs the user.
|
|
216
|
+
*
|
|
217
|
+
* - Lever buys `minCollateralToBuy` for at most `maxSwapIn`: `(maxSwapIn × SCALE − minCollateralToBuy × price) /
|
|
218
|
+
* (minCollateralToBuy × price)`, positive when it pays more than the oracle value.
|
|
219
|
+
* - Delever sells `maxCollateralToSell` for at least `minRepayAssets`, and Close sells at most `maxCollateralIn` for at
|
|
220
|
+
* least `minLoanOut`: `(collateral × price − loan × SCALE) / (collateral × price)`, positive when the worst fill
|
|
221
|
+
* returns less than the oracle value.
|
|
222
|
+
*
|
|
223
|
+
* `SCALE` is `ORACLE_PRICE_SCALE` (1e36): a Morpho oracle price is loan-token units per collateral-token unit, so
|
|
224
|
+
* token decimals need no adjustment. The result is rounded up (towards the unfavourable side), so for any whole WAD
|
|
225
|
+
* bound `max`, `deviation > max` exactly when the unrounded deviation exceeds it. Pure: reads nothing on chain.
|
|
226
|
+
* Lever refuses a deviation above `LEVERAGE_MAX_ORACLE_DEVIATION` (15%); Delever and Close return it in their
|
|
227
|
+
* limits and never refuse on it, so an app can warn or ask for confirmation at its own thresholds.
|
|
228
|
+
*
|
|
229
|
+
* @param params - The action, its signed swap bounds and the oracle price.
|
|
230
|
+
* @param params.operation - `"lever"`, `"delever"` or `"close"`.
|
|
231
|
+
* @param params.limits - Signed swap bounds, such as the action's limits or its `action.args`.
|
|
232
|
+
* @param params.oraclePrice - Market oracle price, scaled by `ORACLE_PRICE_SCALE`.
|
|
233
|
+
* @returns The worst price (rounded down), the oracle price and the deviation, WAD-scaled and rounded up:
|
|
234
|
+
* `150_000_000_000_000_000n` is 15% worse than the oracle, a negative value better.
|
|
235
|
+
* @throws {InvalidBigIntInputError} when `oraclePrice` or a bound is missing or not a bigint.
|
|
236
|
+
* @throws {NonPositiveInputError} when `oraclePrice` or the collateral bound is not positive.
|
|
237
|
+
* @throws {NegativeInputError} when the loan-token bound is negative.
|
|
238
|
+
* @throws {InvalidLeverageOperationError} when `operation` is not `lever`, `delever` or `close`.
|
|
239
|
+
* @example
|
|
240
|
+
* ```ts
|
|
241
|
+
* import { computeLeverageOracleDeviation } from "@morpho-org/morpho-sdk";
|
|
242
|
+
*
|
|
243
|
+
* // Selling 10 WETH (18 decimals) for at least 27,000 USDC (6 decimals) with the oracle at 3,000 USDC per WETH.
|
|
244
|
+
* const { deviation } = computeLeverageOracleDeviation({
|
|
245
|
+
* operation: "delever",
|
|
246
|
+
* limits: { maxCollateralToSell: 10n * 10n ** 18n, minRepayAssets: 27_000n * 10n ** 6n },
|
|
247
|
+
* oraclePrice: 3_000n * 10n ** 24n,
|
|
248
|
+
* });
|
|
249
|
+
* // deviation === 100_000_000_000_000_000n: the worst fill is 10% below the oracle value
|
|
250
|
+
* ```
|
|
251
|
+
*/
|
|
252
|
+
export declare const computeLeverageOracleDeviation: (params: LeverageOracleDeviationParams) => LeverageOracleDeviation;
|
|
253
|
+
/**
|
|
254
|
+
* Computes the signed limits of a Lever from an exact-output 0x quote.
|
|
255
|
+
*
|
|
256
|
+
* - `minCollateralToBuy` is the quote's `buyAmount`; the swap input cap `maxSwapIn` is the quote's
|
|
257
|
+
* `maxSellAmount`, which already carries the caller's slippage: the bundle approves exactly
|
|
258
|
+
* `maxSwapIn` and the Settler pulls the whole `maxSellAmount` before refunding, so a smaller cap
|
|
259
|
+
* would revert. No oracle enters a bound.
|
|
260
|
+
* - The worst swap price, `maxSwapIn` per `minCollateralToBuy` scaled by `ORACLE_PRICE_SCALE`, must be at most
|
|
261
|
+
* `LEVERAGE_MAX_ORACLE_DEVIATION` (15%) above the market's oracle price at the data block; exactly 15% is
|
|
262
|
+
* accepted, and a price below the oracle, which favours the user, is never refused. The comparison is exact (cross-multiplied, no rounding). It refuses the Lever and changes no
|
|
263
|
+
* signed bound. The price and the debt are the data block's; until the deadline only the signed `maxLtv` and
|
|
264
|
+
* Blue's health check guard execution. The deviation compares `maxSwapIn` alone: reallocation penalties
|
|
265
|
+
* (`penaltyAssets`, at most 1% each) are paid on top.
|
|
266
|
+
* - `maxBorrowAssets = maxSwapIn + penaltyAssets − loanAssets`, so the contract's swap cap
|
|
267
|
+
* `loanAssets + maxBorrowAssets − penaltyAssets` equals the quote cap.
|
|
268
|
+
* - `maxLtv` is the LLTV minus `DEFAULT_LLTV_BUFFER`, never `type(uint256).max`. The worst fill is
|
|
269
|
+
* the full `maxBorrowAssets` borrowed with exactly `minCollateralToBuy` received, which is also the
|
|
270
|
+
* state Blue's health check sees mid-flow, before any surplus repays debt. It is checked with the
|
|
271
|
+
* contract's rounding (debt rounded up against collateral value, the bound rounded down), first
|
|
272
|
+
* against the LLTV (Blue's health check, `check: "health"`, also when `maxLtv` fails too, because
|
|
273
|
+
* the contract hits that check first), then against `maxLtv` (`check: "maxLtv"`). The debt is the position's
|
|
274
|
+
* debt at the data block; interest accrued before execution is not checked. `DEFAULT_LLTV_BUFFER` leaves room
|
|
275
|
+
* for it under the LLTV only: a worst fill at the signed `maxLtv` has none, so whether interest fits under
|
|
276
|
+
* `maxLtv` depends on the position and the fill, and a Lever that exceeds it reverts onchain.
|
|
277
|
+
* - The deadline is the leverage data timestamp plus `LEVERAGE_DEADLINE_WINDOW`.
|
|
278
|
+
*
|
|
279
|
+
* @param params - Lever inputs.
|
|
280
|
+
* @param params.intent - Collateral and loan assets the user deposits.
|
|
281
|
+
* @param params.quote - Exact-output quote amounts; `buyAmount` is the collateral to buy.
|
|
282
|
+
* @param params.slippage - Slippage the caller passed to 0x, WAD-scaled, at most 10%.
|
|
283
|
+
* @param params.leverageData - One-block leverage data.
|
|
284
|
+
* @param params.penaltyAssets - Total public-allocator penalty of the action's reallocations, summed
|
|
285
|
+
* per entry as the contract does (zero without reallocations).
|
|
286
|
+
* @returns The Lever's signed limits.
|
|
287
|
+
* @throws {InvalidBigIntInputError} when `slippage`, an intent amount, `penaltyAssets`, `quote.buyAmount`,
|
|
288
|
+
* `quote.maxSellAmount` or the data block timestamp is not a bigint.
|
|
289
|
+
* @throws {NegativeInputError} when an intent amount, `penaltyAssets` or `slippage` is negative.
|
|
290
|
+
* @throws {InputExceedsMaxError} when `loanAssets` exceeds `maxSwapIn + penaltyAssets`, which would
|
|
291
|
+
* lift the signed swap cap above the quote cap, or when an intent amount, `penaltyAssets`, a signed amount or
|
|
292
|
+
* the deadline exceeds the uint256 range.
|
|
293
|
+
* @throws {LeverageWorstFillLtvError} with `check: "health"` when the worst fill fails Blue's mid-flow
|
|
294
|
+
* health check at the LLTV, or `check: "maxLtv"` when it passes that check but exceeds `maxLtv`.
|
|
295
|
+
* @throws {LeverageSlippageAboveLimitError} when `slippage` exceeds 10%.
|
|
296
|
+
* @throws {ZeroExQuoteRequiredError} when the quote is missing.
|
|
297
|
+
* @throws {ZeroExQuoteTypeMismatchError} when the quote is not exact output.
|
|
298
|
+
* @throws {UnsupportedMarketIrmError} when accruing the position's debt needs an unsupported IRM.
|
|
299
|
+
* @throws {BlueErrors.TotalOverflow} when accruing the market's interest overflows.
|
|
300
|
+
* @throws {NonPositiveInputError} when a quote amount or the deadline is not positive.
|
|
301
|
+
* @throws {LeverageOraclePriceUnavailableError} when the market's oracle price is unknown or zero; a present price
|
|
302
|
+
* that is not a bigint throws `InvalidBigIntInputError`.
|
|
303
|
+
* @throws {LeverageOraclePriceDeviationError} when the worst swap price is more than
|
|
304
|
+
* `LEVERAGE_MAX_ORACLE_DEVIATION` (15%) above the oracle price.
|
|
305
|
+
* @example
|
|
306
|
+
* ```ts
|
|
307
|
+
* import { computeLeverLimits } from "@morpho-org/morpho-sdk";
|
|
308
|
+
*
|
|
309
|
+
* // `leverageData`: the funded WETH/USDC position of the `LeverageLimitsData` example.
|
|
310
|
+
* const limits = computeLeverLimits({
|
|
311
|
+
* intent: { collateralAssets: 10n ** 19n, loanAssets: 0n },
|
|
312
|
+
* quote: { mode: "exactOutput", maxSellAmount: 60_360_300_000n, buyAmount: 2n * 10n ** 19n },
|
|
313
|
+
* slippage: 5_000_000_000_000_000n,
|
|
314
|
+
* leverageData,
|
|
315
|
+
* penaltyAssets: 0n,
|
|
316
|
+
* });
|
|
317
|
+
* // limits.maxBorrowAssets === 60_360_300_000n: the 30 WETH position grows to 60 WETH
|
|
318
|
+
* ```
|
|
319
|
+
*/
|
|
320
|
+
export declare const computeLeverLimits: (params: LeverLimitsParams) => LeverLimits;
|
|
321
|
+
/**
|
|
322
|
+
* Computes the signed limits of a Delever (pay back with collateral) from an exact-input 0x quote
|
|
323
|
+
* and the caller's slippage.
|
|
324
|
+
*
|
|
325
|
+
* - `maxCollateralToSell` is the quote's `sellAmount`; `minRepayAssets` is the quote's `minBuyAmount` as is, so
|
|
326
|
+
* 0x's floor is the one source of truth and a fill at it passes the bundle's output check. It must be positive
|
|
327
|
+
* and at least `buyAmount × (1 − slippage)`. That bound uses the whole-ppm slippage sent to 0x, which rounds the
|
|
328
|
+
* caller's slippage down and so raises the bound in the user's favour, and rounds the amount down as 0x does,
|
|
329
|
+
* so every quote 0x builds for that slippage passes and one unit less is refused. No oracle enters a bound.
|
|
330
|
+
* - `maxLtv` is the position's LTV with its debt accrued to the deadline, at the data block's
|
|
331
|
+
* oracle price (rounded up, as Blue's `getLtv`): the LTV of doing nothing until the deadline. A
|
|
332
|
+
* position already past the LLTV buffer can still delever. The accrual is a projection from the leverage data
|
|
333
|
+
* block's market and IRM state, run once from the market's stored last update as Blue accrues it, so a
|
|
334
|
+
* fetched position must be passed unaccrued: interest that follows it does not make a small Delever revert, but a rate
|
|
335
|
+
* that rises before execution can. The worst fill withdraws all of
|
|
336
|
+
* `maxCollateralToSell` and repays only `minRepayAssets` of the debt accrued to the deadline, the latest
|
|
337
|
+
* and costliest moment the contract can run; Blue checks health on that state before any surplus
|
|
338
|
+
* is repaid, and the contract checks `maxLtv` after it. Refuses when it fails either, so a Delever
|
|
339
|
+
* never ends above the LTV projected from the data block. That cap is fixed when the Delever is built: an
|
|
340
|
+
* oracle price rise or new debt before inclusion can let a poor fill raise the live LTV and still pass it.
|
|
341
|
+
*
|
|
342
|
+
* @param params - Delever inputs.
|
|
343
|
+
* @param params.quote - Exact-input quote amounts; `sellAmount` is the collateral to sell.
|
|
344
|
+
* @param params.slippage - Caller slippage, WAD-scaled, at most 10%.
|
|
345
|
+
* @param params.leverageData - One-block leverage data.
|
|
346
|
+
* @returns The Delever's signed limits.
|
|
347
|
+
* @throws {ZeroExQuoteMinBuyAmountBelowSlippageError} when `quote.minBuyAmount` is zero or below
|
|
348
|
+
* `buyAmount × (1 − slippage)`, the slippage rounded down to whole parts per million: the quote allows more
|
|
349
|
+
* slippage than the caller's. Fetch a new quote with the caller's slippage.
|
|
350
|
+
* @throws {RepayExceedsDebtError} when `minRepayAssets` exceeds the debt; use Close instead.
|
|
351
|
+
* @throws {RepaySharesExceedDebtError} when `minRepayAssets`, repaid by assets as the contract
|
|
352
|
+
* does, would burn more borrow shares than the position holds; use Close instead.
|
|
353
|
+
* @throws {WithdrawExceedsCollateralError} when `maxCollateralToSell` exceeds the position's collateral.
|
|
354
|
+
* @throws {LeverageWorstFillLtvError} when the worst fill fails Blue's health check or `maxLtv`, or
|
|
355
|
+
* when the collateral is worth zero at the market price, which would make `maxLtv` unlimited.
|
|
356
|
+
* @throws {LeverageSlippageAboveLimitError} when `slippage` exceeds 10%.
|
|
357
|
+
* @throws {ZeroExQuoteRequiredError} when the quote is missing.
|
|
358
|
+
* @throws {ZeroExQuoteTypeMismatchError} when the quote is not exact input.
|
|
359
|
+
* @throws {UnsupportedMarketIrmError} when accruing the position's debt needs an unsupported IRM.
|
|
360
|
+
* @throws {BlueErrors.TotalOverflow} when accruing the market's interest overflows.
|
|
361
|
+
* @throws {InvalidBigIntInputError} when `slippage`, `quote.buyAmount`, `quote.minBuyAmount`, the quote's sell amount
|
|
362
|
+
* or the data block timestamp is not a bigint.
|
|
363
|
+
* @throws {NegativeInputError} when `slippage` is negative.
|
|
364
|
+
* @throws {NonPositiveInputError} when `quote.sellAmount`, `quote.buyAmount` or the deadline is not positive.
|
|
365
|
+
* @throws {InputExceedsMaxError} when the deadline exceeds the uint256 range.
|
|
366
|
+
* @throws {LeverageOraclePriceUnavailableError} when the market's oracle price is unknown or zero; a present price
|
|
367
|
+
* that is not a bigint throws `InvalidBigIntInputError`.
|
|
368
|
+
* @example
|
|
369
|
+
* ```ts
|
|
370
|
+
* import { computeDeleverLimits } from "@morpho-org/morpho-sdk";
|
|
371
|
+
*
|
|
372
|
+
* // `leverageData`: the funded WETH/USDC position of the `LeverageLimitsData` example.
|
|
373
|
+
* const limits = computeDeleverLimits({
|
|
374
|
+
* quote: {
|
|
375
|
+
* mode: "exactInput",
|
|
376
|
+
* sellAmount: 10n ** 19n,
|
|
377
|
+
* buyAmount: 29_970_000_000n,
|
|
378
|
+
* minBuyAmount: 29_820_150_000n,
|
|
379
|
+
* },
|
|
380
|
+
* slippage: 5_000_000_000_000_000n,
|
|
381
|
+
* leverageData,
|
|
382
|
+
* });
|
|
383
|
+
* // limits.minRepayAssets === 29_820_150_000n
|
|
384
|
+
* ```
|
|
385
|
+
*/
|
|
386
|
+
export declare const computeDeleverLimits: (params: DeleverLimitsParams) => DeleverLimits;
|
|
387
|
+
/**
|
|
388
|
+
* Computes the signed limits of a Close with debt, from an exact-output 0x quote and the caller's
|
|
389
|
+
* slippage. The Close keeps the collateral it does not sell.
|
|
390
|
+
*
|
|
391
|
+
* - `minLoanOut` is the quote's `buyAmount` and `maxCollateralIn` its `maxSellAmount`, which
|
|
392
|
+
* already carries the caller's slippage and must not exceed the position's collateral (the
|
|
393
|
+
* contract does not cap it). Unsold collateral returns to the wallet.
|
|
394
|
+
* - `minLoanOut` must cover the debt at the data block plus `computeCloseInterestBuffer` (at
|
|
395
|
+
* least 1 wei), as headroom for the interest that accrues before execution. It is not a minimum returned to the
|
|
396
|
+
* user: `maxCollateralIn` can be the whole collateral, so a fill at the floor can sell all of it, repay the debt
|
|
397
|
+
* and return nothing. The buffer is an estimate at the
|
|
398
|
+
* data block's borrow rate: it reduces interest-driven reverts of a fill at the floor but does not
|
|
399
|
+
* rule them out if the rate jumps before execution. The debt is never used as the floor.
|
|
400
|
+
* - Close has no `maxLtv`.
|
|
401
|
+
* - This helper only checks that `minLoanOut` covers at least the debt plus the buffer. `blueClose` accepts only that
|
|
402
|
+
* exact size and refuses a larger `buyAmount` with `LeverageCloseBuyAboveDebtError`, so a caller that uses this
|
|
403
|
+
* helper directly must enforce the exact size itself.
|
|
404
|
+
*
|
|
405
|
+
* A Close without debt has no limits: this function refuses it, and `blueClose` refuses it earlier with
|
|
406
|
+
* `LeverageCloseWithoutDebtError`.
|
|
407
|
+
*
|
|
408
|
+
* @param params - Close inputs.
|
|
409
|
+
* @param params.quote - Exact-output quote amounts.
|
|
410
|
+
* @param params.slippage - Caller slippage, WAD-scaled, at most 10%.
|
|
411
|
+
* @param params.leverageData - One-block leverage data.
|
|
412
|
+
* @returns The Close's signed limits.
|
|
413
|
+
* @throws {NonPositiveInputError} when the position has no debt, or a quote amount or the deadline is not positive.
|
|
414
|
+
* @throws {LeverageCloseInputExceedsCollateralError} when `maxCollateralIn` exceeds the collateral.
|
|
415
|
+
* @throws {LeverageCloseFloorBelowDebtPlusBufferError} when `minLoanOut` is below the debt plus the interest buffer.
|
|
416
|
+
* @throws {InputExceedsMaxError} when `minLoanOut` or the deadline exceeds the uint256 range.
|
|
417
|
+
* @throws {LeverageSlippageAboveLimitError} when `slippage` exceeds 10%.
|
|
418
|
+
* @throws {ZeroExQuoteRequiredError} when the quote is missing.
|
|
419
|
+
* @throws {ZeroExQuoteTypeMismatchError} when the quote is not an exact-output quote.
|
|
420
|
+
* @throws {UnsupportedMarketIrmError} when accruing the position's debt needs an unsupported IRM.
|
|
421
|
+
* @throws {BlueErrors.TotalOverflow} when accruing the market's interest overflows.
|
|
422
|
+
* @throws {InvalidBigIntInputError} when `slippage`, `quote.buyAmount`, the quote's sell amount or the data
|
|
423
|
+
* block timestamp is not a bigint, or when the position has debt and `leverageData.borrowRate` is not a bigint.
|
|
424
|
+
* @throws {NegativeInputError} when `slippage` is negative, or when the position has debt and `leverageData.borrowRate` is
|
|
425
|
+
* negative.
|
|
426
|
+
* @throws {LeverageOraclePriceUnavailableError} when the market's oracle price is unknown or zero; a present price
|
|
427
|
+
* that is not a bigint throws `InvalidBigIntInputError`.
|
|
428
|
+
* @example
|
|
429
|
+
* ```ts
|
|
430
|
+
* import { computeCloseInterestBuffer, computeCloseLimits } from "@morpho-org/morpho-sdk";
|
|
431
|
+
*
|
|
432
|
+
* // `leverageData`: the funded WETH/USDC position of the `LeverageLimitsData` example.
|
|
433
|
+
* // Size the exact-output quote from the same snapshot: the debt at the data block plus the interest buffer.
|
|
434
|
+
* const buyAmount =
|
|
435
|
+
* leverageData.position.accrueInterest(leverageData.block.timestamp).borrowAssets +
|
|
436
|
+
* computeCloseInterestBuffer(leverageData);
|
|
437
|
+
* const limits = computeCloseLimits({
|
|
438
|
+
* quote: { mode: "exactOutput", maxSellAmount: 205n * 10n ** 17n, buyAmount },
|
|
439
|
+
* slippage: 5_000_000_000_000_000n,
|
|
440
|
+
* leverageData,
|
|
441
|
+
* });
|
|
442
|
+
* // limits.minLoanOut === buyAmount: exactly the debt plus the buffer, the only size blueClose accepts
|
|
443
|
+
* ```
|
|
444
|
+
*/
|
|
445
|
+
export declare const computeCloseLimits: (params: CloseLimitsParams) => CloseLimits;
|
|
446
|
+
/**
|
|
447
|
+
* Computes the interest buffer a Close floor must cover above the debt; a keep-collateral Close adds it to the debt when it asks 0x for an
|
|
448
|
+
* exact output: `debt × borrowRate × LEVERAGE_DEADLINE_WINDOW × LEVERAGE_CLOSE_INTEREST_BUFFER_FACTOR`,
|
|
449
|
+
* rounded up and at least 1 wei when there is debt, so `debt + buffer` always passes the floor
|
|
450
|
+
* check of `computeCloseLimits` (a zero-rate market included), with the debt and the market's
|
|
451
|
+
* per-second borrow rate at the data block. Not a
|
|
452
|
+
* safety value: the contract returns any excess to the user as loan token, and a shortfall only
|
|
453
|
+
* makes Blue's repay pull revert.
|
|
454
|
+
*
|
|
455
|
+
* @param leverageData - One-block leverage data.
|
|
456
|
+
* @returns Interest buffer in loan-token assets.
|
|
457
|
+
* @throws {InvalidBigIntInputError} when `leverageData.block.timestamp` is missing or not a bigint, or when the position
|
|
458
|
+
* has debt and `leverageData.borrowRate` is missing or not a bigint.
|
|
459
|
+
* @throws {NegativeInputError} when the position has debt and `leverageData.borrowRate` is negative.
|
|
460
|
+
* @throws {UnsupportedMarketIrmError} when accruing a debt needs an unsupported IRM.
|
|
461
|
+
* @throws {BlueErrors.TotalOverflow} when accruing the market's interest overflows.
|
|
462
|
+
* @example
|
|
463
|
+
* ```ts
|
|
464
|
+
* import { computeCloseInterestBuffer } from "@morpho-org/morpho-sdk";
|
|
465
|
+
*
|
|
466
|
+
* // `leverageData`: the funded WETH/USDC position of the `LeverageLimitsData` example.
|
|
467
|
+
* const buffer = computeCloseInterestBuffer(leverageData);
|
|
468
|
+
* const buyAmount =
|
|
469
|
+
* leverageData.position.accrueInterest(leverageData.block.timestamp).borrowAssets + buffer;
|
|
470
|
+
* ```
|
|
471
|
+
*/
|
|
472
|
+
export declare const computeCloseInterestBuffer: (leverageData: LeverageLimitsData) => bigint;
|