@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,171 @@
|
|
|
1
|
+
import type { Address, Hex } from "viem";
|
|
2
|
+
/**
|
|
3
|
+
* Swap a ZeroExLeverageBundlesV1 action needs from 0x, which fixes the direction of the tokens and the quote mode.
|
|
4
|
+
*
|
|
5
|
+
* - `lever`: buy exactly the collateral to buy with loan tokens (exact output).
|
|
6
|
+
* - `delever`: sell exactly the collateral to sell for loan tokens (exact input).
|
|
7
|
+
* - `closeKeepCollateral`: buy exactly the debt plus its interest buffer with collateral (exact output).
|
|
8
|
+
*
|
|
9
|
+
* @see https://github.com/morpho-org/bundles/blob/3bf53141455051f8fc7a85cd00cc15bd89459238/src/leverage/ZeroExLeverageBundlesV1.sol#L60
|
|
10
|
+
* @example
|
|
11
|
+
* ```ts
|
|
12
|
+
* import type { ZeroExLeverageSwapKind } from "@morpho-org/morpho-sdk";
|
|
13
|
+
*
|
|
14
|
+
* const kind: ZeroExLeverageSwapKind = "lever";
|
|
15
|
+
* ```
|
|
16
|
+
*/
|
|
17
|
+
export type ZeroExLeverageSwapKind = "lever" | "delever" | "closeKeepCollateral";
|
|
18
|
+
/**
|
|
19
|
+
* 0x quote mode: `exactInput` sells exactly the requested amount (0x `sellAmount`), `exactOutput` buys exactly
|
|
20
|
+
* the requested amount (0x `buyAmount`).
|
|
21
|
+
*
|
|
22
|
+
* @example
|
|
23
|
+
* ```ts
|
|
24
|
+
* import type { ZeroExQuoteMode } from "@morpho-org/morpho-sdk";
|
|
25
|
+
*
|
|
26
|
+
* const mode: ZeroExQuoteMode = "exactOutput";
|
|
27
|
+
* ```
|
|
28
|
+
*/
|
|
29
|
+
export type ZeroExQuoteMode = "exactInput" | "exactOutput";
|
|
30
|
+
/**
|
|
31
|
+
* Transaction a 0x allowance-holder quote asks the taker to send: an AllowanceHolder `exec` call.
|
|
32
|
+
*
|
|
33
|
+
* @example
|
|
34
|
+
* ```ts
|
|
35
|
+
* import type { ZeroExQuoteTransaction } from "@morpho-org/morpho-sdk";
|
|
36
|
+
*
|
|
37
|
+
* const transaction: ZeroExQuoteTransaction = {
|
|
38
|
+
* to: "0x0000000000001fF3684f28c67538d4D072C22734",
|
|
39
|
+
* data: "0x",
|
|
40
|
+
* value: 0n,
|
|
41
|
+
* };
|
|
42
|
+
* ```
|
|
43
|
+
*/
|
|
44
|
+
export interface ZeroExQuoteTransaction {
|
|
45
|
+
/** Contract the quote calls; must be AllowanceHolder. */
|
|
46
|
+
readonly to: Address;
|
|
47
|
+
/** AllowanceHolder `exec` calldata: the bundle's `swapData`. */
|
|
48
|
+
readonly data: Hex;
|
|
49
|
+
/** Native value the quote sends; must be zero, because the bundle's entry points are not payable. */
|
|
50
|
+
readonly value: bigint;
|
|
51
|
+
}
|
|
52
|
+
interface ZeroExQuoteBase {
|
|
53
|
+
/** Chain the quote was requested for, copied from the request rather than read from the calldata. */
|
|
54
|
+
readonly chainId: number;
|
|
55
|
+
/** Taker the quote was requested for, the leverage bundle, copied from the request rather than read from the calldata. */
|
|
56
|
+
readonly taker: Address;
|
|
57
|
+
/** txOrigin the quote was requested for, the action's `txOrigin` or the user by default, copied from the request rather than read from the calldata. */
|
|
58
|
+
readonly txOrigin: Address;
|
|
59
|
+
/** Slippage tolerance passed to 0x, WAD-scaled. */
|
|
60
|
+
readonly slippage: bigint;
|
|
61
|
+
/** Token the swap sells. */
|
|
62
|
+
readonly sellToken: Address;
|
|
63
|
+
/** Token the swap buys. */
|
|
64
|
+
readonly buyToken: Address;
|
|
65
|
+
/** Block at which 0x sampled liquidity. */
|
|
66
|
+
readonly blockNumber: bigint;
|
|
67
|
+
/** 0x request identifier. */
|
|
68
|
+
readonly zid: string;
|
|
69
|
+
/** Transaction the quote asks the taker to send. */
|
|
70
|
+
readonly transaction: ZeroExQuoteTransaction;
|
|
71
|
+
}
|
|
72
|
+
/**
|
|
73
|
+
* 0x exact-input allowance-holder quote for exactly `sellAmount`. `validateZeroExQuote` checks the calldata against
|
|
74
|
+
* two of its amounts: the AllowanceHolder `exec` amount must equal `sellAmount`, and the Settler's decoded minimum
|
|
75
|
+
* must be at least `minBuyAmount` unless the slippage struct is all zero. `buyAmount` is 0x's estimate and is not
|
|
76
|
+
* checked. The checked limits, each when its call decodes, are `swapInput` and `settlerMinAmountOut` on
|
|
77
|
+
* {@link ValidatedZeroExSwap}.
|
|
78
|
+
*
|
|
79
|
+
* @example
|
|
80
|
+
* ```ts
|
|
81
|
+
* import type { ZeroExExactInputQuote } from "@morpho-org/morpho-sdk";
|
|
82
|
+
*
|
|
83
|
+
* declare const quote: ZeroExExactInputQuote;
|
|
84
|
+
* console.log(quote.minBuyAmount);
|
|
85
|
+
* ```
|
|
86
|
+
*/
|
|
87
|
+
export interface ZeroExExactInputQuote extends ZeroExQuoteBase {
|
|
88
|
+
readonly mode: "exactInput";
|
|
89
|
+
/** Exact amount of `sellToken` sold. */
|
|
90
|
+
readonly sellAmount: bigint;
|
|
91
|
+
/** Expected amount of `buyToken` bought, as reported by 0x; an estimate, not checked against the calldata. */
|
|
92
|
+
readonly buyAmount: bigint;
|
|
93
|
+
/**
|
|
94
|
+
* Smallest amount of `buyToken` after slippage, as reported by 0x. `validateZeroExQuote` requires the Settler's
|
|
95
|
+
* decoded minimum to be at least this amount, unless the slippage struct is all zero.
|
|
96
|
+
*/
|
|
97
|
+
readonly minBuyAmount: bigint;
|
|
98
|
+
}
|
|
99
|
+
/**
|
|
100
|
+
* 0x exact-output allowance-holder quote for exactly `buyAmount`. `validateZeroExQuote` checks the calldata against
|
|
101
|
+
* two of its amounts: the AllowanceHolder `exec` amount must equal `maxSellAmount`, and the Settler's decoded minimum
|
|
102
|
+
* must be at least `buyAmount` unless the slippage struct is all zero. `estimatedNetSellAmount` is 0x's estimate
|
|
103
|
+
* and is not checked. The checked limits, each when its call decodes, are `swapInput` and `settlerMinAmountOut` on
|
|
104
|
+
* {@link ValidatedZeroExSwap}.
|
|
105
|
+
*
|
|
106
|
+
* @see https://docs.0x.org/evm/0x-swap-api/additional-topics/exact-buy
|
|
107
|
+
* @example
|
|
108
|
+
* ```ts
|
|
109
|
+
* import type { ZeroExExactOutputQuote } from "@morpho-org/morpho-sdk";
|
|
110
|
+
*
|
|
111
|
+
* declare const quote: ZeroExExactOutputQuote;
|
|
112
|
+
* console.log(quote.maxSellAmount);
|
|
113
|
+
* ```
|
|
114
|
+
*/
|
|
115
|
+
export interface ZeroExExactOutputQuote extends ZeroExQuoteBase {
|
|
116
|
+
readonly mode: "exactOutput";
|
|
117
|
+
/**
|
|
118
|
+
* Exact amount of `buyToken` bought. `validateZeroExQuote` requires the Settler's decoded minimum to be at least this
|
|
119
|
+
* amount, unless the slippage struct is all zero.
|
|
120
|
+
*/
|
|
121
|
+
readonly buyAmount: bigint;
|
|
122
|
+
/**
|
|
123
|
+
* Largest amount of `sellToken` the swap may spend, as reported by 0x. `validateZeroExQuote` requires the
|
|
124
|
+
* AllowanceHolder `exec` amount to equal it.
|
|
125
|
+
*/
|
|
126
|
+
readonly maxSellAmount: bigint;
|
|
127
|
+
/** Expected amount of `sellToken` spent after the refund route, as reported by 0x; an estimate, not checked. */
|
|
128
|
+
readonly estimatedNetSellAmount: bigint;
|
|
129
|
+
}
|
|
130
|
+
/**
|
|
131
|
+
* 0x allowance-holder quote as returned by `fetchZeroExQuote`, with the request that produced it. It is
|
|
132
|
+
* untrusted until `validateZeroExQuote` turns it into a {@link ValidatedZeroExSwap}.
|
|
133
|
+
*
|
|
134
|
+
* @example
|
|
135
|
+
* ```ts
|
|
136
|
+
* import type { ZeroExQuote } from "@morpho-org/morpho-sdk";
|
|
137
|
+
*
|
|
138
|
+
* declare const quote: ZeroExQuote;
|
|
139
|
+
* const exactAmount = quote.mode === "exactOutput" ? quote.buyAmount : quote.sellAmount;
|
|
140
|
+
* ```
|
|
141
|
+
*/
|
|
142
|
+
export type ZeroExQuote = ZeroExExactInputQuote | ZeroExExactOutputQuote;
|
|
143
|
+
declare const validatedZeroExSwapBrand: unique symbol;
|
|
144
|
+
/**
|
|
145
|
+
* 0x quote that `validateZeroExQuote` checked: its envelope, its AllowanceHolder `exec` call against the market's
|
|
146
|
+
* tokens, the action's swap input cap and the quote's sell amount, and its Settler `execute` call and actions against
|
|
147
|
+
* the leverage deadline. A Settler slippage's recipient (the leverage bundle), buy token and output floor are checked
|
|
148
|
+
* only when the struct is nonzero; an all-zero struct, which 0x sends for single-pool routes, relies on the bundle's
|
|
149
|
+
* onchain `minOut` check alone. Its user and chain checks are request-context checks on fields the fetch copies from
|
|
150
|
+
* its request; nothing in the calldata ties the swap to the user. Only `validateZeroExQuote` creates one.
|
|
151
|
+
*
|
|
152
|
+
* @example
|
|
153
|
+
* ```ts
|
|
154
|
+
* import type { ValidatedZeroExSwap } from "@morpho-org/morpho-sdk";
|
|
155
|
+
*
|
|
156
|
+
* declare const swap: ValidatedZeroExSwap;
|
|
157
|
+
* console.log(swap.settler, swap.swapInput, swap.swapData);
|
|
158
|
+
* ```
|
|
159
|
+
*/
|
|
160
|
+
export type ValidatedZeroExSwap = ZeroExQuote & {
|
|
161
|
+
/** Transaction data to pass to the bundle as `swapData`: the quote's AllowanceHolder call. */
|
|
162
|
+
readonly swapData: Hex;
|
|
163
|
+
/** Settler the swap runs through: the operator and target of the AllowanceHolder `exec` call. */
|
|
164
|
+
readonly settler: Address;
|
|
165
|
+
/** Amount of `sellToken` the AllowanceHolder `exec` call lets Settler pull from the bundle. */
|
|
166
|
+
readonly swapInput: bigint;
|
|
167
|
+
/** Smallest amount of `buyToken` Settler accepts: its `AllowedSlippage.minAmountOut`. */
|
|
168
|
+
readonly settlerMinAmountOut: bigint;
|
|
169
|
+
readonly [validatedZeroExSwapBrand]: true;
|
|
170
|
+
};
|
|
171
|
+
export {};
|
package/lib/cjs/version.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
/** Installed @morpho-org/morpho-sdk package version. */
|
|
2
|
-
export declare const version = "10.
|
|
2
|
+
export declare const version = "10.6.0-next.0";
|
package/lib/cjs/version.js
CHANGED