@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
package/README.md
CHANGED
|
@@ -40,6 +40,9 @@ destination.
|
|
|
40
40
|
| | `makeLend`, `makeBorrow`, `makeWithdraw`, `makeRepay`, `supplyCollateralMakeBorrow`, `supplyBlueMakeLend` | MidnightBundlesV2 (every chain with a registered `midnightBundlesV2`) |
|
|
41
41
|
| **Blue** | `supply`, `withdraw`, `supplyCollateral`, `borrow`, `supplyCollateralBorrow`, `repay`, `withdrawCollateral`, `repayWithdrawCollateral`, `refinance` | BlueBundlesV1 |
|
|
42
42
|
| | `withdrawBuyCallback` | Morpho Blue (direct `withdraw` for a BlueBuyCallback's owner) |
|
|
43
|
+
| | `lever` | ZeroExLeverageBundlesV1 (borrow and buy collateral through a 0x swap) |
|
|
44
|
+
| | `delever` | ZeroExLeverageBundlesV1 (pay back with collateral through a 0x swap) |
|
|
45
|
+
| | `close` | ZeroExLeverageBundlesV1 (repay the whole debt with collateral through a 0x swap) |
|
|
43
46
|
| **VaultV2** | `deposit`, `withdraw`, `redeem` | VaultBundlesV1 |
|
|
44
47
|
| | `forceWithdraw` | VaultExitBundlesV1 |
|
|
45
48
|
| | `forceRedeem` | Vault multicall |
|
|
@@ -64,11 +67,49 @@ Robinhood Chain, Arc, X Layer, and Alpen. Alpen has no registered Vault V1 facto
|
|
|
64
67
|
token, or Permit2; native-token funding is not enabled there. Custom deployments can still be
|
|
65
68
|
configured with `registerCustomAddresses`.
|
|
66
69
|
|
|
70
|
+
### Leverage refusals and fallbacks
|
|
71
|
+
|
|
72
|
+
`lever`, `delever` and `close` refuse before building when a check fails. Check each specific error before
|
|
73
|
+
its base class, in the order of this table.
|
|
74
|
+
|
|
75
|
+
| Refusal | What to do |
|
|
76
|
+
| --- | --- |
|
|
77
|
+
| `ExpiredLeverageDeadlineError` (an `ExpiredDeadlineError`) | Read the leverage data again. Lever and Delever: fetch a new 0x quote and rebuild. Close: do the same if debt is left; if only collateral is left, use `withdrawCollateral`. |
|
|
78
|
+
| `ZeroExQuoteNoLiquidityError` | Offer a smaller amount, or a no-swap exit. |
|
|
79
|
+
| `ZeroExExactOutputUnsupportedError`, `ZeroExUnknownSwapKindError`, `ZeroExInvalidTxOriginError`, a `ZeroExQuoteRequestError` with a 4xx status other than 429 | Fix the request (pair, kind, `txOrigin`, API key); a new quote alone does not help. |
|
|
80
|
+
| `ZeroExQuoteShortTimeBoundError` | Fetch a new 0x quote once. If it refuses again on the same word, the flagged value may be your own amount: offer a different amount, retry later, or a no-swap exit (`repayWithdrawCollateral` to leave at once). |
|
|
81
|
+
| Any other `ZeroExQuoteError` | Fetch a new 0x quote and rebuild. |
|
|
82
|
+
| `LeverageSlippageAboveLimitError` | Lower the slippage to `error.max` or less, with a new quote if the action swaps. |
|
|
83
|
+
| `LeverageUnsupportedChainError` | Only the no-swap exits are available, where Blue is. |
|
|
84
|
+
| `LeverageCloseEmptyPositionError` | Nothing to close. |
|
|
85
|
+
| `LeverageCloseWithoutDebtError` | The position has collateral but no debt: withdraw it with `withdrawCollateral`. A Close would revert in its 0x swap. |
|
|
86
|
+
| `LeverageOraclePriceUnavailableError` | Lever: read the leverage data again once the oracle answers. Delever and Close: a no-swap exit. |
|
|
87
|
+
| `RepayExceedsDebtError` from `delever` | Repay the whole debt with `close`. |
|
|
88
|
+
| Any other `LeverageLimitError` | Offer a smaller action, or a no-swap exit. |
|
|
89
|
+
| `LeverageReallocationError` | Lever with other vaults, or without reallocations (`reallocationOptions`). |
|
|
90
|
+
|
|
91
|
+
The no-swap exits are the Blue methods `repay` and `supplyCollateral`, which reduce risk, and
|
|
92
|
+
`repayWithdrawCollateral`, which leaves the position.
|
|
93
|
+
|
|
94
|
+
Send each `lever`, `delever` or `close` in its own transaction: ZeroExLeverageBundlesV1 accepts one call per
|
|
95
|
+
transaction, so a smart-account batch or an ERC-4337 bundle with a second one reverts with `Reentrancy`.
|
|
96
|
+
|
|
97
|
+
Leverage swaps keep short-lived quotes out: `fetchZeroExQuote` asks 0x to exclude
|
|
98
|
+
`ZERO_EX_LEVERAGE_EXCLUDED_SOURCES`, and `validateZeroExQuote` refuses a quote in which it finds a
|
|
99
|
+
signed-order fill (`ZeroExQuoteSignedOrderActionError`), a time bound before the action's deadline
|
|
100
|
+
(`ZeroExQuoteShortTimeBoundError`), a Settler action it does not accept
|
|
101
|
+
(`ZeroExQuoteUnsupportedActionError`) or calldata that does not decode
|
|
102
|
+
(`ZeroExQuoteUndecodableCalldataError`). Each is a `ZeroExQuoteError`: fetch a new quote, except as the table says for
|
|
103
|
+
`ZeroExQuoteShortTimeBoundError`. A
|
|
104
|
+
`SELECT` that does not decode refuses with `ZeroExQuoteMalformedCalldataError`.
|
|
105
|
+
|
|
67
106
|
## How it works
|
|
68
107
|
|
|
69
108
|
Actions that pull tokens or touch a position return `{ buildTx, getRequirements }`. All Blue
|
|
70
109
|
writes use this lazy shape while still encoding one direct BlueBundlesV1 call, except
|
|
71
|
-
`withdrawBuyCallback`, which encodes one direct Morpho Blue `withdraw
|
|
110
|
+
`withdrawBuyCallback`, which encodes one direct Morpho Blue `withdraw`, and `lever`, `delever` and
|
|
111
|
+
`close`, which each encode one ZeroExLeverageBundlesV1 call; their Morpho authorization of that
|
|
112
|
+
bundle, which `lever` requests only when it borrows, persists after the action. Vault deposits,
|
|
72
113
|
`withdraw`, and `redeem` use the same shape for token or vault-share authorization to
|
|
73
114
|
VaultBundlesV1. Vault `inKindRedeem` and `forceWithdraw` use it so callers can await
|
|
74
115
|
`getRequirements()` to check share authorization to VaultExitBundlesV1 — and, for `inKindRedeem`,
|
|
@@ -91,6 +132,8 @@ for quote-based limits. For operations covered by `OperationInputs`, prefer
|
|
|
91
132
|
independently chosen `inputs` in `simulate()` limits rather than bounds derived
|
|
92
133
|
from action metadata. Refinance, in-kind redeems, force exits and Midnight
|
|
93
134
|
operations still require quotes.
|
|
135
|
+
Leverage actions get no automatic limits: `toSimulationLimits` throws
|
|
136
|
+
`UnsupportedLimitActionError` for `blueLever`, `blueDelever` and `blueClose`.
|
|
94
137
|
|
|
95
138
|
```typescript
|
|
96
139
|
const vaultData = await vault.getData();
|