@morpho-org/morpho-sdk 5.5.0 → 5.7.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 +11 -7
- package/lib/cjs/abis.d.ts +15 -3
- package/lib/cjs/abis.js +15 -1
- package/lib/cjs/actions/blue/borrow.d.ts +21 -15
- package/lib/cjs/actions/blue/borrow.js +25 -18
- package/lib/cjs/actions/blue/buildAssetFundingActions.d.ts +1 -1
- package/lib/cjs/actions/blue/buildAssetFundingActions.js +1 -1
- package/lib/cjs/actions/blue/buildReallocationActions.d.ts +62 -19
- package/lib/cjs/actions/blue/buildReallocationActions.js +123 -27
- package/lib/cjs/actions/blue/refinance.d.ts +14 -7
- package/lib/cjs/actions/blue/refinance.js +18 -10
- package/lib/cjs/actions/blue/supplyCollateralBorrow.d.ts +28 -19
- package/lib/cjs/actions/blue/supplyCollateralBorrow.js +39 -23
- package/lib/cjs/actions/blue/withdraw.d.ts +20 -13
- package/lib/cjs/actions/blue/withdraw.js +23 -18
- package/lib/cjs/actions/midnight/mempoolSubmitOffers.d.ts +2 -2
- package/lib/cjs/actions/midnight/mempoolSubmitOffers.js +2 -2
- package/lib/cjs/actions/requirements/generalAdapter/getGeneralAdapterRequirementsPermit2.d.ts +1 -1
- package/lib/cjs/actions/requirements/generalAdapter/getGeneralAdapterRequirementsPermit2.js +1 -1
- package/lib/cjs/actions/requirements/getRequirementsApproval.js +2 -1
- package/lib/cjs/blue/abis.d.ts +2 -0
- package/lib/cjs/blue/abis.js +33 -0
- package/lib/cjs/blue/addresses.d.ts +2 -0
- package/lib/cjs/blue/addresses.js +19 -0
- package/lib/cjs/blue/constants.d.ts +1 -0
- package/lib/cjs/blue/constants.js +13 -0
- package/lib/cjs/blue/entities.d.ts +2 -0
- package/lib/cjs/blue/entities.js +37 -0
- package/lib/cjs/blue/errors.d.ts +2 -0
- package/lib/cjs/blue/errors.js +29 -0
- package/lib/cjs/blue/fetch.d.ts +1 -0
- package/lib/cjs/blue/fetch.js +33 -0
- package/lib/cjs/blue/types.d.ts +2 -0
- package/lib/cjs/blue/types.js +2 -0
- package/lib/cjs/blue/utils.d.ts +3 -0
- package/lib/cjs/blue/utils.js +29 -0
- package/lib/cjs/bundler/actions.d.ts +122 -3
- package/lib/cjs/bundler/actions.js +216 -7
- package/lib/cjs/bundler/types.d.ts +20 -0
- package/lib/cjs/constants.d.ts +37 -3
- package/lib/cjs/constants.js +41 -1
- package/lib/cjs/entities/blue/blue.d.ts +362 -71
- package/lib/cjs/entities/blue/blue.js +286 -52
- package/lib/cjs/entities/index.d.ts +64 -4
- package/lib/cjs/entities/index.js +37 -22
- package/lib/cjs/entities/{reallocationData.d.ts → vaultV1ReallocationData.d.ts} +40 -15
- package/lib/cjs/entities/{reallocationData.js → vaultV1ReallocationData.js} +29 -16
- package/lib/cjs/entities/vaultV2/vaultV2.d.ts +1 -1
- package/lib/cjs/entities/vaultV2/vaultV2.js +1 -1
- package/lib/cjs/entities/vaultV2BlueReallocationData.d.ts +511 -0
- package/lib/cjs/entities/vaultV2BlueReallocationData.js +1300 -0
- package/lib/cjs/errors.d.ts +48 -3
- package/lib/cjs/errors.js +62 -1
- package/lib/cjs/fetch.d.ts +16 -1
- package/lib/cjs/fetch.js +24 -1
- package/lib/{esm/helpers/computeReallocations.d.ts → cjs/helpers/computeVaultV1Reallocations.d.ts} +14 -8
- package/lib/cjs/helpers/{computeReallocations.js → computeVaultV1Reallocations.js} +27 -13
- package/lib/cjs/helpers/constant.d.ts +5 -3
- package/lib/cjs/helpers/constant.js +6 -4
- package/lib/cjs/helpers/index.d.ts +2 -2
- package/lib/cjs/helpers/index.js +6 -3
- package/lib/cjs/helpers/validate.d.ts +32 -16
- package/lib/cjs/helpers/validate.js +142 -29
- package/lib/cjs/midnight/abis.d.ts +1 -0
- package/lib/cjs/midnight/abis.js +8 -0
- package/lib/cjs/midnight/constants.d.ts +1 -0
- package/lib/cjs/midnight/constants.js +19 -0
- package/lib/cjs/midnight/entities.d.ts +2 -0
- package/lib/cjs/midnight/entities.js +11 -0
- package/lib/cjs/midnight/errors.d.ts +1 -0
- package/lib/cjs/midnight/errors.js +24 -0
- package/lib/cjs/midnight/fetch.d.ts +1 -0
- package/lib/cjs/midnight/fetch.js +9 -0
- package/lib/cjs/midnight/types.d.ts +1 -0
- package/lib/cjs/midnight/types.js +2 -0
- package/lib/cjs/midnight/utils.d.ts +1 -0
- package/lib/cjs/midnight/utils.js +17 -0
- package/lib/cjs/types/action.d.ts +12 -0
- package/lib/cjs/types/error.d.ts +224 -5
- package/lib/cjs/types/error.js +269 -7
- package/lib/cjs/types/sharedLiquidity.d.ts +72 -8
- package/lib/cjs/types.d.ts +17 -2
- package/lib/cjs/utils.d.ts +31 -4
- package/lib/cjs/utils.js +44 -4
- package/lib/esm/abis.d.ts +15 -3
- package/lib/esm/abis.js +15 -3
- package/lib/esm/actions/blue/borrow.d.ts +21 -15
- package/lib/esm/actions/blue/borrow.js +26 -19
- package/lib/esm/actions/blue/buildAssetFundingActions.d.ts +1 -1
- package/lib/esm/actions/blue/buildAssetFundingActions.js +1 -1
- package/lib/esm/actions/blue/buildReallocationActions.d.ts +62 -19
- package/lib/esm/actions/blue/buildReallocationActions.js +119 -25
- package/lib/esm/actions/blue/refinance.d.ts +14 -7
- package/lib/esm/actions/blue/refinance.js +19 -11
- package/lib/esm/actions/blue/supplyCollateralBorrow.d.ts +28 -19
- package/lib/esm/actions/blue/supplyCollateralBorrow.js +40 -24
- package/lib/esm/actions/blue/withdraw.d.ts +20 -13
- package/lib/esm/actions/blue/withdraw.js +24 -19
- package/lib/esm/actions/midnight/mempoolSubmitOffers.d.ts +2 -2
- package/lib/esm/actions/midnight/mempoolSubmitOffers.js +2 -2
- package/lib/esm/actions/requirements/generalAdapter/getGeneralAdapterRequirementsPermit2.d.ts +1 -1
- package/lib/esm/actions/requirements/generalAdapter/getGeneralAdapterRequirementsPermit2.js +1 -1
- package/lib/esm/actions/requirements/getRequirementsApproval.js +2 -1
- package/lib/esm/blue/abis.d.ts +2 -0
- package/lib/esm/blue/abis.js +2 -0
- package/lib/esm/blue/addresses.d.ts +2 -0
- package/lib/esm/blue/addresses.js +1 -0
- package/lib/esm/blue/constants.d.ts +1 -0
- package/lib/esm/blue/constants.js +1 -0
- package/lib/esm/blue/entities.d.ts +2 -0
- package/lib/esm/blue/entities.js +1 -0
- package/lib/esm/blue/errors.d.ts +2 -0
- package/lib/esm/blue/errors.js +2 -0
- package/lib/esm/blue/fetch.d.ts +1 -0
- package/lib/esm/blue/fetch.js +1 -0
- package/lib/esm/blue/types.d.ts +2 -0
- package/lib/esm/blue/types.js +1 -0
- package/lib/esm/blue/utils.d.ts +3 -0
- package/lib/esm/blue/utils.js +2 -0
- package/lib/esm/bundler/actions.d.ts +122 -3
- package/lib/esm/bundler/actions.js +219 -10
- package/lib/esm/bundler/types.d.ts +20 -0
- package/lib/esm/constants.d.ts +37 -3
- package/lib/esm/constants.js +37 -3
- package/lib/esm/entities/blue/blue.d.ts +362 -71
- package/lib/esm/entities/blue/blue.js +289 -55
- package/lib/esm/entities/index.d.ts +64 -4
- package/lib/esm/entities/index.js +19 -3
- package/lib/esm/entities/{reallocationData.d.ts → vaultV1ReallocationData.d.ts} +40 -15
- package/lib/esm/entities/{reallocationData.js → vaultV1ReallocationData.js} +32 -14
- package/lib/esm/entities/vaultV2/vaultV2.d.ts +1 -1
- package/lib/esm/entities/vaultV2/vaultV2.js +1 -1
- package/lib/esm/entities/vaultV2BlueReallocationData.d.ts +511 -0
- package/lib/esm/entities/vaultV2BlueReallocationData.js +1296 -0
- package/lib/esm/errors.d.ts +48 -3
- package/lib/esm/errors.js +48 -3
- package/lib/esm/fetch.d.ts +16 -1
- package/lib/esm/fetch.js +16 -1
- package/lib/{cjs/helpers/computeReallocations.d.ts → esm/helpers/computeVaultV1Reallocations.d.ts} +14 -8
- package/lib/esm/helpers/{computeReallocations.js → computeVaultV1Reallocations.js} +25 -11
- package/lib/esm/helpers/constant.d.ts +5 -3
- package/lib/esm/helpers/constant.js +5 -3
- package/lib/esm/helpers/index.d.ts +2 -2
- package/lib/esm/helpers/index.js +2 -2
- package/lib/esm/helpers/validate.d.ts +32 -16
- package/lib/esm/helpers/validate.js +143 -32
- package/lib/esm/midnight/abis.d.ts +1 -0
- package/lib/esm/midnight/abis.js +1 -0
- package/lib/esm/midnight/constants.d.ts +1 -0
- package/lib/esm/midnight/constants.js +1 -0
- package/lib/esm/midnight/entities.d.ts +2 -0
- package/lib/esm/midnight/entities.js +1 -0
- package/lib/esm/midnight/errors.d.ts +1 -0
- package/lib/esm/midnight/errors.js +1 -0
- package/lib/esm/midnight/fetch.d.ts +1 -0
- package/lib/esm/midnight/fetch.js +1 -0
- package/lib/esm/midnight/types.d.ts +1 -0
- package/lib/esm/midnight/types.js +1 -0
- package/lib/esm/midnight/utils.d.ts +1 -0
- package/lib/esm/midnight/utils.js +1 -0
- package/lib/esm/types/action.d.ts +12 -0
- package/lib/esm/types/error.d.ts +224 -5
- package/lib/esm/types/error.js +253 -4
- package/lib/esm/types/sharedLiquidity.d.ts +72 -8
- package/lib/esm/types.d.ts +17 -2
- package/lib/esm/utils.d.ts +31 -4
- package/lib/esm/utils.js +31 -4
- package/package.json +23 -7
package/README.md
CHANGED
|
@@ -7,7 +7,7 @@
|
|
|
7
7
|
|
|
8
8
|
> 📖 **Full documentation → [docs.morpho.org/developers/sdks/morpho-sdk](https://docs.morpho.org/developers/sdks/morpho-sdk/)**
|
|
9
9
|
|
|
10
|
-
Build transactions for Morpho's **VaultV1** (MetaMorpho), **VaultV2**, **Blue**, and **Midnight** fixed-rate markets on every chain where Morpho is deployed. Custom deployments can be added with `registerCustomAddresses` from `@morpho-org/
|
|
10
|
+
Build transactions for Morpho's **VaultV1** (MetaMorpho), **VaultV2**, **Blue**, and **Midnight** fixed-rate markets on every chain where Morpho is deployed. Custom deployments can be added with `registerCustomAddresses` from `@morpho-org/morpho-sdk/addresses`.
|
|
11
11
|
|
|
12
12
|
## Installation
|
|
13
13
|
|
|
@@ -161,6 +161,8 @@ The LLTV buffer guards against instant liquidation.
|
|
|
161
161
|
|
|
162
162
|
### Midnight: take a fixed-rate offer
|
|
163
163
|
|
|
164
|
+
Protocol-specific names are qualified in shared facades, for example `fetchBluePosition` and `fetchMidnightPosition` from `@morpho-org/morpho-sdk/fetch`. Raw upstream names remain available under `/blue/{abis,addresses,constants,entities,errors,fetch,types,utils}` and `/midnight/{abis,constants,entities,errors,fetch,types,utils}`.
|
|
165
|
+
|
|
164
166
|
```typescript
|
|
165
167
|
const midnight = client.morpho.midnight(8453);
|
|
166
168
|
const marketData = await midnight.getMarketData(marketId);
|
|
@@ -234,12 +236,13 @@ graph LR
|
|
|
234
236
|
|
|
235
237
|
M1S -->|nativeWrap? + erc20TransferFrom + morphoSupply| B3[Bundler3]
|
|
236
238
|
M1SC -->|erc20TransferFrom + morphoSupplyCollateral| B3
|
|
237
|
-
M1B -->|
|
|
238
|
-
M1SCB -->|transfer + supplyCollateral +
|
|
239
|
-
M1W -->|
|
|
240
|
-
M1RF -->|
|
|
239
|
+
M1B -->|allocator reallocation? + morphoBorrow| B3
|
|
240
|
+
M1SCB -->|transfer + supplyCollateral + allocator reallocation? + borrow| B3
|
|
241
|
+
M1W -->|allocator reallocation? + morphoWithdraw| B3
|
|
242
|
+
M1RF -->|allocator reallocation? + supplyCollateral callback: borrow + repay + withdrawCollateral| B3
|
|
241
243
|
|
|
242
|
-
B3 -.->|reallocateTo|
|
|
244
|
+
B3 -.->|reallocateTo| PA1[PublicAllocator V1]
|
|
245
|
+
B3 -.->|reallocate / allocateFromIdle| BPA[Blue Public Allocator]
|
|
243
246
|
end
|
|
244
247
|
|
|
245
248
|
subgraph Midnight Flow
|
|
@@ -268,7 +271,8 @@ graph LR
|
|
|
268
271
|
style MM fill:#fff3e0,stroke:#ff9800
|
|
269
272
|
style V2C fill:#e3f2fd,stroke:#2196f3
|
|
270
273
|
style REQ fill:#f3e5f5,stroke:#9c27b0
|
|
271
|
-
style
|
|
274
|
+
style PA1 fill:#fff9c4,stroke:#f9a825
|
|
275
|
+
style BPA fill:#fff9c4,stroke:#f9a825
|
|
272
276
|
```
|
|
273
277
|
|
|
274
278
|
## Development
|
package/lib/cjs/abis.d.ts
CHANGED
|
@@ -1,6 +1,18 @@
|
|
|
1
|
-
export { marketParamsAbi
|
|
2
|
-
|
|
3
|
-
|
|
1
|
+
export { marketParamsAbi as blueMarketParamsAbi,
|
|
2
|
+
/** @deprecated Use `blueMarketParamsAbi` or the raw `/blue/abis` subpath. */
|
|
3
|
+
marketParamsAbi, } from "@morpho-org/blue-sdk";
|
|
4
|
+
export { adaptiveCurveIrmAbi as blueAdaptiveCurveIrmAbi,
|
|
5
|
+
/** @deprecated Use `blueAdaptiveCurveIrmAbi` or the raw `/blue/abis` subpath. */
|
|
6
|
+
adaptiveCurveIrmAbi, blueAbi, blueOracleAbi, erc2612Abi, erc5267Abi, metaMorphoAbi, metaMorphoFactoryAbi, morphoMarketV1AdapterAbi, morphoMarketV1AdapterFactoryAbi, morphoMarketV1AdapterV2Abi, morphoMarketV1AdapterV2FactoryAbi, morphoVaultV1AdapterAbi, morphoVaultV1AdapterFactoryAbi, permissionedErc20WrapperAbi, permit2Abi, preLiquidationAbi as bluePreLiquidationAbi,
|
|
7
|
+
/** @deprecated Use `bluePreLiquidationAbi` or the raw `/blue/abis` subpath. */
|
|
8
|
+
preLiquidationAbi, preLiquidationFactoryAbi as bluePreLiquidationFactoryAbi,
|
|
9
|
+
/** @deprecated Use `bluePreLiquidationFactoryAbi` or the raw `/blue/abis` subpath. */
|
|
10
|
+
preLiquidationFactoryAbi, publicAllocatorAbi, vaultV1AdapterAbi, vaultV1AdapterFactoryAbi, vaultV1PublicAllocatorAbi, vaultV2Abi, vaultV2BluePublicAllocatorAbi, vaultV2FactoryAbi, whitelistControllerAggregatorV2Abi, wrappedBackedTokenAbi, wstEthAbi, } from "@morpho-org/blue-sdk-viem";
|
|
11
|
+
export { ecrecoverRatifierAbi as midnightEcrecoverRatifierAbi,
|
|
12
|
+
/** @deprecated Use `midnightEcrecoverRatifierAbi` or the raw `/midnight/abis` subpath. */
|
|
13
|
+
ecrecoverRatifierAbi, midnightAbi, midnightBundlesAbi, setterRatifierAbi as midnightSetterRatifierAbi,
|
|
14
|
+
/** @deprecated Use `midnightSetterRatifierAbi` or the raw `/midnight/abis` subpath. */
|
|
15
|
+
setterRatifierAbi, } from "@morpho-org/midnight-sdk";
|
|
4
16
|
/** ABI for the VaultExitBundlesV1 periphery contract. */
|
|
5
17
|
export declare const vaultExitBundlesV1Abi: readonly [{
|
|
6
18
|
readonly type: "constructor";
|
package/lib/cjs/abis.js
CHANGED
|
@@ -1,9 +1,13 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.compoundV3MigrationAdapterAbi = exports.compoundV2MigrationAdapterAbi = exports.aaveV3OptimizerMigrationAdapterAbi = exports.aaveV3MigrationAdapterAbi = exports.aaveV2MigrationAdapterAbi = exports.erc20WrapperAdapterAbi = exports.paraswapAdapterAbi = exports.ethereumGeneralAdapter1Abi = exports.generalAdapter1Abi = exports.coreAdapterAbi = exports.bundler3Abi = exports.vaultExitBundlesV1Abi = exports.setterRatifierAbi = exports.midnightBundlesAbi = exports.midnightAbi = exports.ecrecoverRatifierAbi = exports.wstEthAbi = exports.wrappedBackedTokenAbi = exports.whitelistControllerAggregatorV2Abi = exports.vaultV2FactoryAbi = exports.vaultV2Abi = exports.vaultV1AdapterFactoryAbi = exports.vaultV1AdapterAbi = exports.publicAllocatorAbi = exports.preLiquidationFactoryAbi = exports.preLiquidationAbi = exports.permit2Abi = exports.permissionedErc20WrapperAbi = exports.morphoVaultV1AdapterFactoryAbi = exports.morphoVaultV1AdapterAbi = exports.morphoMarketV1AdapterV2FactoryAbi = exports.morphoMarketV1AdapterV2Abi = exports.morphoMarketV1AdapterFactoryAbi = exports.morphoMarketV1AdapterAbi = exports.metaMorphoFactoryAbi = exports.metaMorphoAbi = exports.erc5267Abi = exports.erc2612Abi = exports.blueOracleAbi = exports.blueAbi = exports.adaptiveCurveIrmAbi = exports.marketParamsAbi = void 0;
|
|
3
|
+
exports.compoundV3MigrationAdapterAbi = exports.compoundV2MigrationAdapterAbi = exports.aaveV3OptimizerMigrationAdapterAbi = exports.aaveV3MigrationAdapterAbi = exports.aaveV2MigrationAdapterAbi = exports.erc20WrapperAdapterAbi = exports.paraswapAdapterAbi = exports.ethereumGeneralAdapter1Abi = exports.generalAdapter1Abi = exports.coreAdapterAbi = exports.bundler3Abi = exports.vaultExitBundlesV1Abi = exports.setterRatifierAbi = exports.midnightSetterRatifierAbi = exports.midnightBundlesAbi = exports.midnightAbi = exports.ecrecoverRatifierAbi = exports.midnightEcrecoverRatifierAbi = exports.wstEthAbi = exports.wrappedBackedTokenAbi = exports.whitelistControllerAggregatorV2Abi = exports.vaultV2FactoryAbi = exports.vaultV2BluePublicAllocatorAbi = exports.vaultV2Abi = exports.vaultV1PublicAllocatorAbi = exports.vaultV1AdapterFactoryAbi = exports.vaultV1AdapterAbi = exports.publicAllocatorAbi = exports.preLiquidationFactoryAbi = exports.bluePreLiquidationFactoryAbi = exports.preLiquidationAbi = exports.bluePreLiquidationAbi = exports.permit2Abi = exports.permissionedErc20WrapperAbi = exports.morphoVaultV1AdapterFactoryAbi = exports.morphoVaultV1AdapterAbi = exports.morphoMarketV1AdapterV2FactoryAbi = exports.morphoMarketV1AdapterV2Abi = exports.morphoMarketV1AdapterFactoryAbi = exports.morphoMarketV1AdapterAbi = exports.metaMorphoFactoryAbi = exports.metaMorphoAbi = exports.erc5267Abi = exports.erc2612Abi = exports.blueOracleAbi = exports.blueAbi = exports.adaptiveCurveIrmAbi = exports.blueAdaptiveCurveIrmAbi = exports.marketParamsAbi = exports.blueMarketParamsAbi = void 0;
|
|
4
4
|
var blue_sdk_1 = require("@morpho-org/blue-sdk");
|
|
5
|
+
Object.defineProperty(exports, "blueMarketParamsAbi", { enumerable: true, get: function () { return blue_sdk_1.marketParamsAbi; } });
|
|
6
|
+
/** @deprecated Use `blueMarketParamsAbi` or the raw `/blue/abis` subpath. */
|
|
5
7
|
Object.defineProperty(exports, "marketParamsAbi", { enumerable: true, get: function () { return blue_sdk_1.marketParamsAbi; } });
|
|
6
8
|
var blue_sdk_viem_1 = require("@morpho-org/blue-sdk-viem");
|
|
9
|
+
Object.defineProperty(exports, "blueAdaptiveCurveIrmAbi", { enumerable: true, get: function () { return blue_sdk_viem_1.adaptiveCurveIrmAbi; } });
|
|
10
|
+
/** @deprecated Use `blueAdaptiveCurveIrmAbi` or the raw `/blue/abis` subpath. */
|
|
7
11
|
Object.defineProperty(exports, "adaptiveCurveIrmAbi", { enumerable: true, get: function () { return blue_sdk_viem_1.adaptiveCurveIrmAbi; } });
|
|
8
12
|
Object.defineProperty(exports, "blueAbi", { enumerable: true, get: function () { return blue_sdk_viem_1.blueAbi; } });
|
|
9
13
|
Object.defineProperty(exports, "blueOracleAbi", { enumerable: true, get: function () { return blue_sdk_viem_1.blueOracleAbi; } });
|
|
@@ -19,20 +23,30 @@ Object.defineProperty(exports, "morphoVaultV1AdapterAbi", { enumerable: true, ge
|
|
|
19
23
|
Object.defineProperty(exports, "morphoVaultV1AdapterFactoryAbi", { enumerable: true, get: function () { return blue_sdk_viem_1.morphoVaultV1AdapterFactoryAbi; } });
|
|
20
24
|
Object.defineProperty(exports, "permissionedErc20WrapperAbi", { enumerable: true, get: function () { return blue_sdk_viem_1.permissionedErc20WrapperAbi; } });
|
|
21
25
|
Object.defineProperty(exports, "permit2Abi", { enumerable: true, get: function () { return blue_sdk_viem_1.permit2Abi; } });
|
|
26
|
+
Object.defineProperty(exports, "bluePreLiquidationAbi", { enumerable: true, get: function () { return blue_sdk_viem_1.preLiquidationAbi; } });
|
|
27
|
+
/** @deprecated Use `bluePreLiquidationAbi` or the raw `/blue/abis` subpath. */
|
|
22
28
|
Object.defineProperty(exports, "preLiquidationAbi", { enumerable: true, get: function () { return blue_sdk_viem_1.preLiquidationAbi; } });
|
|
29
|
+
Object.defineProperty(exports, "bluePreLiquidationFactoryAbi", { enumerable: true, get: function () { return blue_sdk_viem_1.preLiquidationFactoryAbi; } });
|
|
30
|
+
/** @deprecated Use `bluePreLiquidationFactoryAbi` or the raw `/blue/abis` subpath. */
|
|
23
31
|
Object.defineProperty(exports, "preLiquidationFactoryAbi", { enumerable: true, get: function () { return blue_sdk_viem_1.preLiquidationFactoryAbi; } });
|
|
24
32
|
Object.defineProperty(exports, "publicAllocatorAbi", { enumerable: true, get: function () { return blue_sdk_viem_1.publicAllocatorAbi; } });
|
|
25
33
|
Object.defineProperty(exports, "vaultV1AdapterAbi", { enumerable: true, get: function () { return blue_sdk_viem_1.vaultV1AdapterAbi; } });
|
|
26
34
|
Object.defineProperty(exports, "vaultV1AdapterFactoryAbi", { enumerable: true, get: function () { return blue_sdk_viem_1.vaultV1AdapterFactoryAbi; } });
|
|
35
|
+
Object.defineProperty(exports, "vaultV1PublicAllocatorAbi", { enumerable: true, get: function () { return blue_sdk_viem_1.vaultV1PublicAllocatorAbi; } });
|
|
27
36
|
Object.defineProperty(exports, "vaultV2Abi", { enumerable: true, get: function () { return blue_sdk_viem_1.vaultV2Abi; } });
|
|
37
|
+
Object.defineProperty(exports, "vaultV2BluePublicAllocatorAbi", { enumerable: true, get: function () { return blue_sdk_viem_1.vaultV2BluePublicAllocatorAbi; } });
|
|
28
38
|
Object.defineProperty(exports, "vaultV2FactoryAbi", { enumerable: true, get: function () { return blue_sdk_viem_1.vaultV2FactoryAbi; } });
|
|
29
39
|
Object.defineProperty(exports, "whitelistControllerAggregatorV2Abi", { enumerable: true, get: function () { return blue_sdk_viem_1.whitelistControllerAggregatorV2Abi; } });
|
|
30
40
|
Object.defineProperty(exports, "wrappedBackedTokenAbi", { enumerable: true, get: function () { return blue_sdk_viem_1.wrappedBackedTokenAbi; } });
|
|
31
41
|
Object.defineProperty(exports, "wstEthAbi", { enumerable: true, get: function () { return blue_sdk_viem_1.wstEthAbi; } });
|
|
32
42
|
var midnight_sdk_1 = require("@morpho-org/midnight-sdk");
|
|
43
|
+
Object.defineProperty(exports, "midnightEcrecoverRatifierAbi", { enumerable: true, get: function () { return midnight_sdk_1.ecrecoverRatifierAbi; } });
|
|
44
|
+
/** @deprecated Use `midnightEcrecoverRatifierAbi` or the raw `/midnight/abis` subpath. */
|
|
33
45
|
Object.defineProperty(exports, "ecrecoverRatifierAbi", { enumerable: true, get: function () { return midnight_sdk_1.ecrecoverRatifierAbi; } });
|
|
34
46
|
Object.defineProperty(exports, "midnightAbi", { enumerable: true, get: function () { return midnight_sdk_1.midnightAbi; } });
|
|
35
47
|
Object.defineProperty(exports, "midnightBundlesAbi", { enumerable: true, get: function () { return midnight_sdk_1.midnightBundlesAbi; } });
|
|
48
|
+
Object.defineProperty(exports, "midnightSetterRatifierAbi", { enumerable: true, get: function () { return midnight_sdk_1.setterRatifierAbi; } });
|
|
49
|
+
/** @deprecated Use `midnightSetterRatifierAbi` or the raw `/midnight/abis` subpath. */
|
|
36
50
|
Object.defineProperty(exports, "setterRatifierAbi", { enumerable: true, get: function () { return midnight_sdk_1.setterRatifierAbi; } });
|
|
37
51
|
/** ABI for the VaultExitBundlesV1 periphery contract. */
|
|
38
52
|
exports.vaultExitBundlesV1Abi = [
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type { MarketParams } from "@morpho-org/blue-sdk";
|
|
2
2
|
import type { Address } from "viem";
|
|
3
|
-
import { type AuthorizationRequirementSignature, type BlueBorrowAction, type
|
|
3
|
+
import { type AuthorizationRequirementSignature, type BlueBorrowAction, type BlueReallocationPlan, type Metadata, type Transaction } from "../../types/index.js";
|
|
4
4
|
/** Parameters for {@link blueBorrow}. */
|
|
5
5
|
export interface BlueBorrowParams {
|
|
6
6
|
market: {
|
|
@@ -14,8 +14,8 @@ export interface BlueBorrowParams {
|
|
|
14
14
|
receiver: Address;
|
|
15
15
|
/** Minimum borrow share price (in ray). Protects against share price manipulation. */
|
|
16
16
|
minSharePrice: bigint;
|
|
17
|
-
/** Vault reallocations to execute before borrowing
|
|
18
|
-
reallocations?:
|
|
17
|
+
/** Homogeneous Vault V1 or Vault V2 reallocations to execute before borrowing. */
|
|
18
|
+
reallocations?: BlueReallocationPlan;
|
|
19
19
|
/**
|
|
20
20
|
* Optional signed Morpho authorization. When provided, a `setAuthorizationWithSig` call is
|
|
21
21
|
* prepended to the bundle so GeneralAdapter1 is authorized in-bundle instead of via a
|
|
@@ -32,17 +32,18 @@ export interface BlueBorrowParams {
|
|
|
32
32
|
* `onBehalf`. Uses `minSharePrice` to protect against share price manipulation between
|
|
33
33
|
* transaction construction and execution.
|
|
34
34
|
*
|
|
35
|
-
*
|
|
36
|
-
*
|
|
37
|
-
* accumulate in `tx.value
|
|
35
|
+
* A `reallocations` plan contains either PublicAllocator V1 entries or Vault V2
|
|
36
|
+
* BluePublicAllocator entries, never both. The calls run before the borrow.
|
|
37
|
+
* V1 fees accumulate in `tx.value`; V2 penalties are paid in the target loan
|
|
38
|
+
* token and donated directly to each vault.
|
|
38
39
|
*
|
|
39
40
|
* @param params.market.chainId - The chain the market lives on.
|
|
40
41
|
* @param params.market.marketParams - Market params (loanToken, collateralToken, oracle, irm, lltv).
|
|
41
42
|
* @param params.args.amount - Loan asset amount to borrow, in the loan token's smallest unit.
|
|
42
43
|
* @param params.args.receiver - Address that receives the borrowed assets.
|
|
43
44
|
* @param params.args.minSharePrice - Minimum borrow share price (in ray). Slippage protection.
|
|
44
|
-
* @param params.args.reallocations - Optional
|
|
45
|
-
*
|
|
45
|
+
* @param params.args.reallocations - Optional homogeneous Vault V1 or Vault V2 reallocations to
|
|
46
|
+
* execute before borrowing.
|
|
46
47
|
* @param params.args.authorizationSignature - Optional signed Morpho authorization; when present,
|
|
47
48
|
* a `setAuthorizationWithSig` call is prepended to the bundle.
|
|
48
49
|
* @param params.metadata - Optional analytics metadata attached to the bundle.
|
|
@@ -50,13 +51,18 @@ export interface BlueBorrowParams {
|
|
|
50
51
|
* typed `action` discriminator the simulation layer consumes.
|
|
51
52
|
* @throws {NonPositiveInputError} when `amount <= 0n` or any reallocation withdrawal amount
|
|
52
53
|
* is non-positive.
|
|
53
|
-
* @throws {
|
|
54
|
-
* @throws {
|
|
55
|
-
*
|
|
56
|
-
* @throws {
|
|
57
|
-
*
|
|
58
|
-
* @throws {
|
|
59
|
-
*
|
|
54
|
+
* @throws {InputExceedsMaxError} when a V2 reallocation asset amount exceeds `uint128` or its penalty exceeds WAD.
|
|
55
|
+
* @throws {InconsistentReallocationPenaltyError} when V2 entries for one vault use different penalties.
|
|
56
|
+
* @throws {InvalidReallocationAddressError} when a V2 vault or adapter address is malformed.
|
|
57
|
+
* @throws {InvalidReallocationSourceTypeError} when a V2 source is absent, incomplete, or has an unknown discriminator.
|
|
58
|
+
* @throws {InvalidReallocationShapeError} when an entry matches both or neither V1/V2 shape.
|
|
59
|
+
* @throws {MixedReallocationVersionsError} when one plan contains both V1 and V2 entries.
|
|
60
|
+
* @throws {NegativeInputError} when `minSharePrice < 0n`, a V1 fee, or a V2 penalty is negative.
|
|
61
|
+
* @throws {EmptyReallocationWithdrawalsError} when any `reallocation.withdrawals` is empty.
|
|
62
|
+
* @throws {ReallocationWithdrawalOnTargetMarketError} when any reallocation withdrawal references
|
|
63
|
+
* the target market.
|
|
64
|
+
* @throws {UnsortedReallocationWithdrawalsError} when reallocation withdrawals are not strictly
|
|
65
|
+
* sorted by market id.
|
|
60
66
|
* @example
|
|
61
67
|
* ```ts
|
|
62
68
|
* import { blueBorrow } from "@morpho-org/morpho-sdk";
|
|
@@ -14,17 +14,18 @@ const buildReallocationActions_js_1 = require("./buildReallocationActions.js");
|
|
|
14
14
|
* `onBehalf`. Uses `minSharePrice` to protect against share price manipulation between
|
|
15
15
|
* transaction construction and execution.
|
|
16
16
|
*
|
|
17
|
-
*
|
|
18
|
-
*
|
|
19
|
-
* accumulate in `tx.value
|
|
17
|
+
* A `reallocations` plan contains either PublicAllocator V1 entries or Vault V2
|
|
18
|
+
* BluePublicAllocator entries, never both. The calls run before the borrow.
|
|
19
|
+
* V1 fees accumulate in `tx.value`; V2 penalties are paid in the target loan
|
|
20
|
+
* token and donated directly to each vault.
|
|
20
21
|
*
|
|
21
22
|
* @param params.market.chainId - The chain the market lives on.
|
|
22
23
|
* @param params.market.marketParams - Market params (loanToken, collateralToken, oracle, irm, lltv).
|
|
23
24
|
* @param params.args.amount - Loan asset amount to borrow, in the loan token's smallest unit.
|
|
24
25
|
* @param params.args.receiver - Address that receives the borrowed assets.
|
|
25
26
|
* @param params.args.minSharePrice - Minimum borrow share price (in ray). Slippage protection.
|
|
26
|
-
* @param params.args.reallocations - Optional
|
|
27
|
-
*
|
|
27
|
+
* @param params.args.reallocations - Optional homogeneous Vault V1 or Vault V2 reallocations to
|
|
28
|
+
* execute before borrowing.
|
|
28
29
|
* @param params.args.authorizationSignature - Optional signed Morpho authorization; when present,
|
|
29
30
|
* a `setAuthorizationWithSig` call is prepended to the bundle.
|
|
30
31
|
* @param params.metadata - Optional analytics metadata attached to the bundle.
|
|
@@ -32,13 +33,18 @@ const buildReallocationActions_js_1 = require("./buildReallocationActions.js");
|
|
|
32
33
|
* typed `action` discriminator the simulation layer consumes.
|
|
33
34
|
* @throws {NonPositiveInputError} when `amount <= 0n` or any reallocation withdrawal amount
|
|
34
35
|
* is non-positive.
|
|
35
|
-
* @throws {
|
|
36
|
-
* @throws {
|
|
37
|
-
*
|
|
38
|
-
* @throws {
|
|
39
|
-
*
|
|
40
|
-
* @throws {
|
|
41
|
-
*
|
|
36
|
+
* @throws {InputExceedsMaxError} when a V2 reallocation asset amount exceeds `uint128` or its penalty exceeds WAD.
|
|
37
|
+
* @throws {InconsistentReallocationPenaltyError} when V2 entries for one vault use different penalties.
|
|
38
|
+
* @throws {InvalidReallocationAddressError} when a V2 vault or adapter address is malformed.
|
|
39
|
+
* @throws {InvalidReallocationSourceTypeError} when a V2 source is absent, incomplete, or has an unknown discriminator.
|
|
40
|
+
* @throws {InvalidReallocationShapeError} when an entry matches both or neither V1/V2 shape.
|
|
41
|
+
* @throws {MixedReallocationVersionsError} when one plan contains both V1 and V2 entries.
|
|
42
|
+
* @throws {NegativeInputError} when `minSharePrice < 0n`, a V1 fee, or a V2 penalty is negative.
|
|
43
|
+
* @throws {EmptyReallocationWithdrawalsError} when any `reallocation.withdrawals` is empty.
|
|
44
|
+
* @throws {ReallocationWithdrawalOnTargetMarketError} when any reallocation withdrawal references
|
|
45
|
+
* the target market.
|
|
46
|
+
* @throws {UnsortedReallocationWithdrawalsError} when reallocation withdrawals are not strictly
|
|
47
|
+
* sorted by market id.
|
|
42
48
|
* @example
|
|
43
49
|
* ```ts
|
|
44
50
|
* import { blueBorrow } from "@morpho-org/morpho-sdk";
|
|
@@ -62,15 +68,15 @@ const blueBorrow = ({ market: { chainId, marketParams }, args: { amount, receive
|
|
|
62
68
|
throw new index_js_3.NegativeInputError("minSharePrice", minSharePrice);
|
|
63
69
|
}
|
|
64
70
|
const actions = [];
|
|
65
|
-
let reallocationFee = 0n;
|
|
66
71
|
if (authorizationSignature) {
|
|
67
72
|
actions.push((0, getBlueAuthorizationAction_js_1.getBlueAuthorizationAction)(chainId, authorizationSignature));
|
|
68
73
|
}
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
}
|
|
74
|
+
const { actions: reallocationActions, fee: reallocationFee, penaltyAssets: reallocationPenaltyAssets, } = (0, buildReallocationActions_js_1.buildBlueReallocationActions)({
|
|
75
|
+
chainId,
|
|
76
|
+
reallocations,
|
|
77
|
+
targetMarketParams: marketParams,
|
|
78
|
+
});
|
|
79
|
+
actions.push(...reallocationActions);
|
|
74
80
|
actions.push({
|
|
75
81
|
type: "morphoBorrow",
|
|
76
82
|
args: [marketParams, amount, 0n, minSharePrice, receiver, false],
|
|
@@ -89,6 +95,7 @@ const blueBorrow = ({ market: { chainId, marketParams }, args: { amount, receive
|
|
|
89
95
|
receiver,
|
|
90
96
|
minSharePrice,
|
|
91
97
|
reallocationFee,
|
|
98
|
+
reallocationPenaltyAssets,
|
|
92
99
|
},
|
|
93
100
|
},
|
|
94
101
|
});
|
|
@@ -20,7 +20,7 @@ export interface BuildAssetFundingActionsParams {
|
|
|
20
20
|
* `blueSupplyCollateral`, `blueSupplyCollateralBorrow`, `blueRepay`, `blueRepayWithdrawCollateral`).
|
|
21
21
|
*
|
|
22
22
|
* Encode-only and synchronous: returns a fresh `Action[]` (never mutates its inputs, mirroring
|
|
23
|
-
* `
|
|
23
|
+
* `buildVaultV2BlueReallocationActions`) and reads no on-chain state. When `nativeAmount > 0n`, validates
|
|
24
24
|
* `asset` is the chain's wNative and emits `nativeTransfer → wrapNative`. When `erc20Amount > 0n`,
|
|
25
25
|
* pulls the ERC-20 via a signed permit/permit2 (`requirementSignature`) or a plain
|
|
26
26
|
* `erc20TransferFrom` — `getTokenRequirementActions` emits the latter itself when no signature is
|
|
@@ -10,7 +10,7 @@ const getTokenRequirementActions_js_1 = require("../signatures/getTokenRequireme
|
|
|
10
10
|
* `blueSupplyCollateral`, `blueSupplyCollateralBorrow`, `blueRepay`, `blueRepayWithdrawCollateral`).
|
|
11
11
|
*
|
|
12
12
|
* Encode-only and synchronous: returns a fresh `Action[]` (never mutates its inputs, mirroring
|
|
13
|
-
* `
|
|
13
|
+
* `buildVaultV2BlueReallocationActions`) and reads no on-chain state. When `nativeAmount > 0n`, validates
|
|
14
14
|
* `asset` is the chain's wNative and emits `nativeTransfer → wrapNative`. When `erc20Amount > 0n`,
|
|
15
15
|
* pulls the ERC-20 via a signed permit/permit2 (`requirementSignature`) or a plain
|
|
16
16
|
* `erc20TransferFrom` — `getTokenRequirementActions` emits the latter itself when no signature is
|
|
@@ -1,26 +1,69 @@
|
|
|
1
|
-
import type
|
|
1
|
+
import { type MarketParams } from "@morpho-org/blue-sdk";
|
|
2
2
|
import type { Action } from "../../bundler/index.js";
|
|
3
|
-
import type {
|
|
3
|
+
import type { BlueReallocationPlan, VaultV1Reallocation, VaultV2BlueReallocation } from "../../types/index.js";
|
|
4
4
|
/**
|
|
5
|
-
* Builds reallocation
|
|
5
|
+
* Builds PublicAllocator V1 reallocation actions for a Morpho Blue target market.
|
|
6
6
|
*
|
|
7
|
-
*
|
|
8
|
-
* market. Returns `{ actions: [], fee: 0n }` for an empty input — callers gate on
|
|
9
|
-
* `reallocations.length > 0` and skip the call entirely in that case. Internal helper —
|
|
10
|
-
* consumed by the Blue actions that accept reallocations; not re-exported on the public surface.
|
|
7
|
+
* Preserves the supplied reallocation order and aggregates each allocator call's native fee.
|
|
11
8
|
*
|
|
12
|
-
* @param reallocations -
|
|
13
|
-
* @param targetMarketParams -
|
|
14
|
-
* @returns The
|
|
15
|
-
* @throws {NegativeInputError} when any reallocation fee is negative.
|
|
16
|
-
* @throws {EmptyReallocationWithdrawalsError} when any reallocation has no withdrawals.
|
|
17
|
-
* @throws {NonPositiveInputError} when any withdrawal amount is non-positive.
|
|
18
|
-
* @throws {ReallocationWithdrawalOnTargetMarketError} when a withdrawal references the target market.
|
|
19
|
-
* @throws {UnsortedReallocationWithdrawalsError} when withdrawals within a reallocation are not
|
|
20
|
-
* strictly sorted by market id.
|
|
9
|
+
* @param params.reallocations - Validated Vault V1 reallocations to execute.
|
|
10
|
+
* @param params.targetMarketParams - Morpho Blue market receiving the reallocated liquidity.
|
|
11
|
+
* @returns The reallocation actions and aggregate native fee, with zero V2 penalty assets.
|
|
21
12
|
* @internal
|
|
22
13
|
*/
|
|
23
|
-
export declare const
|
|
24
|
-
readonly
|
|
25
|
-
readonly
|
|
14
|
+
export declare const buildVaultV1ReallocationActions: ({ reallocations, targetMarketParams, }: {
|
|
15
|
+
readonly reallocations: readonly VaultV1Reallocation[];
|
|
16
|
+
readonly targetMarketParams: MarketParams;
|
|
17
|
+
}) => {
|
|
18
|
+
actions: Action[];
|
|
19
|
+
fee: bigint;
|
|
20
|
+
penaltyAssets: bigint;
|
|
21
|
+
};
|
|
22
|
+
/**
|
|
23
|
+
* Builds BluePublicAllocator reallocation actions for a Morpho Blue target market.
|
|
24
|
+
*
|
|
25
|
+
* Prepends one aggregate loan-token funding action when penalties are non-zero, then builds one
|
|
26
|
+
* allocator action per validated Vault V2 reallocation.
|
|
27
|
+
*
|
|
28
|
+
* @param params.chainId - Chain whose registered Bundler3 and allocator addresses are used.
|
|
29
|
+
* @param params.reallocations - Validated Vault V2 Blue reallocations to execute.
|
|
30
|
+
* @param params.targetMarketParams - Morpho Blue market receiving the reallocated liquidity.
|
|
31
|
+
* @param params.penaltyFundingSource - Optional source of penalty assets. Defaults to the
|
|
32
|
+
* transaction initiator.
|
|
33
|
+
* @returns The funding and reallocation actions and aggregate penalty assets, with zero native fee.
|
|
34
|
+
* @internal
|
|
35
|
+
*/
|
|
36
|
+
export declare const buildVaultV2BlueReallocationActions: ({ chainId, reallocations, targetMarketParams, penaltyFundingSource, }: {
|
|
37
|
+
readonly chainId: number;
|
|
38
|
+
readonly reallocations: readonly VaultV2BlueReallocation[];
|
|
39
|
+
readonly targetMarketParams: MarketParams;
|
|
40
|
+
readonly penaltyFundingSource?: "initiator" | "generalAdapter1";
|
|
41
|
+
}) => {
|
|
42
|
+
actions: Action[];
|
|
43
|
+
fee: bigint;
|
|
44
|
+
penaltyAssets: bigint;
|
|
45
|
+
};
|
|
46
|
+
/**
|
|
47
|
+
* Validates a homogeneous Blue reallocation plan and builds its Bundler actions.
|
|
48
|
+
*
|
|
49
|
+
* Dispatches Vault V1 and Vault V2 plans to their version-specific builders. V1 plans aggregate
|
|
50
|
+
* native fees, while V2 plans aggregate loan-token penalties using the selected funding source.
|
|
51
|
+
*
|
|
52
|
+
* @param params.chainId - Chain whose registered Bundler3 and allocator addresses are used.
|
|
53
|
+
* @param params.reallocations - Optional homogeneous Vault V1 or Vault V2 reallocation plan.
|
|
54
|
+
* @param params.targetMarketParams - Morpho Blue market receiving the reallocated liquidity.
|
|
55
|
+
* @param params.penaltyFundingSource - Optional source of V2 penalty assets. Defaults to the
|
|
56
|
+
* transaction initiator.
|
|
57
|
+
* @returns The reallocation actions, aggregate V1 native fee, and aggregate V2 penalty assets.
|
|
58
|
+
* @internal
|
|
59
|
+
*/
|
|
60
|
+
export declare const buildBlueReallocationActions: ({ chainId, reallocations, targetMarketParams, penaltyFundingSource, }: {
|
|
61
|
+
readonly chainId: number;
|
|
62
|
+
readonly reallocations: BlueReallocationPlan | undefined;
|
|
63
|
+
readonly targetMarketParams: MarketParams;
|
|
64
|
+
readonly penaltyFundingSource?: "initiator" | "generalAdapter1";
|
|
65
|
+
}) => {
|
|
66
|
+
actions: Action[];
|
|
67
|
+
fee: bigint;
|
|
68
|
+
penaltyAssets: bigint;
|
|
26
69
|
};
|
|
@@ -1,45 +1,141 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
4
|
-
const
|
|
3
|
+
exports.buildBlueReallocationActions = exports.buildVaultV2BlueReallocationActions = exports.buildVaultV1ReallocationActions = void 0;
|
|
4
|
+
const blue_sdk_1 = require("@morpho-org/blue-sdk");
|
|
5
|
+
const validate_js_1 = require("../../helpers/validate.js");
|
|
5
6
|
/**
|
|
6
|
-
* Builds reallocation
|
|
7
|
+
* Builds PublicAllocator V1 reallocation actions for a Morpho Blue target market.
|
|
7
8
|
*
|
|
8
|
-
*
|
|
9
|
-
* market. Returns `{ actions: [], fee: 0n }` for an empty input — callers gate on
|
|
10
|
-
* `reallocations.length > 0` and skip the call entirely in that case. Internal helper —
|
|
11
|
-
* consumed by the Blue actions that accept reallocations; not re-exported on the public surface.
|
|
9
|
+
* Preserves the supplied reallocation order and aggregates each allocator call's native fee.
|
|
12
10
|
*
|
|
13
|
-
* @param reallocations -
|
|
14
|
-
* @param targetMarketParams -
|
|
15
|
-
* @returns The
|
|
16
|
-
* @throws {NegativeInputError} when any reallocation fee is negative.
|
|
17
|
-
* @throws {EmptyReallocationWithdrawalsError} when any reallocation has no withdrawals.
|
|
18
|
-
* @throws {NonPositiveInputError} when any withdrawal amount is non-positive.
|
|
19
|
-
* @throws {ReallocationWithdrawalOnTargetMarketError} when a withdrawal references the target market.
|
|
20
|
-
* @throws {UnsortedReallocationWithdrawalsError} when withdrawals within a reallocation are not
|
|
21
|
-
* strictly sorted by market id.
|
|
11
|
+
* @param params.reallocations - Validated Vault V1 reallocations to execute.
|
|
12
|
+
* @param params.targetMarketParams - Morpho Blue market receiving the reallocated liquidity.
|
|
13
|
+
* @returns The reallocation actions and aggregate native fee, with zero V2 penalty assets.
|
|
22
14
|
* @internal
|
|
23
15
|
*/
|
|
24
|
-
const
|
|
25
|
-
|
|
26
|
-
const fee = reallocations.reduce((sum, r) => sum + r.fee, 0n);
|
|
16
|
+
const buildVaultV1ReallocationActions = ({ reallocations, targetMarketParams, }) => {
|
|
17
|
+
let fee = 0n;
|
|
27
18
|
const actions = [];
|
|
28
|
-
for (const
|
|
19
|
+
for (const reallocation of reallocations) {
|
|
29
20
|
actions.push({
|
|
30
21
|
type: "reallocateTo",
|
|
31
22
|
args: [
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
marketParams:
|
|
36
|
-
amount:
|
|
23
|
+
reallocation.vault,
|
|
24
|
+
reallocation.fee,
|
|
25
|
+
reallocation.withdrawals.map((withdrawal) => ({
|
|
26
|
+
marketParams: withdrawal.marketParams,
|
|
27
|
+
amount: withdrawal.amount,
|
|
37
28
|
})),
|
|
38
29
|
targetMarketParams,
|
|
39
30
|
false,
|
|
40
31
|
],
|
|
41
32
|
});
|
|
33
|
+
fee += reallocation.fee;
|
|
42
34
|
}
|
|
43
|
-
return { actions, fee };
|
|
35
|
+
return { actions, fee, penaltyAssets: 0n };
|
|
44
36
|
};
|
|
45
|
-
exports.
|
|
37
|
+
exports.buildVaultV1ReallocationActions = buildVaultV1ReallocationActions;
|
|
38
|
+
/**
|
|
39
|
+
* Builds BluePublicAllocator reallocation actions for a Morpho Blue target market.
|
|
40
|
+
*
|
|
41
|
+
* Prepends one aggregate loan-token funding action when penalties are non-zero, then builds one
|
|
42
|
+
* allocator action per validated Vault V2 reallocation.
|
|
43
|
+
*
|
|
44
|
+
* @param params.chainId - Chain whose registered Bundler3 and allocator addresses are used.
|
|
45
|
+
* @param params.reallocations - Validated Vault V2 Blue reallocations to execute.
|
|
46
|
+
* @param params.targetMarketParams - Morpho Blue market receiving the reallocated liquidity.
|
|
47
|
+
* @param params.penaltyFundingSource - Optional source of penalty assets. Defaults to the
|
|
48
|
+
* transaction initiator.
|
|
49
|
+
* @returns The funding and reallocation actions and aggregate penalty assets, with zero native fee.
|
|
50
|
+
* @internal
|
|
51
|
+
*/
|
|
52
|
+
const buildVaultV2BlueReallocationActions = ({ chainId, reallocations, targetMarketParams, penaltyFundingSource = "initiator", }) => {
|
|
53
|
+
const actions = [];
|
|
54
|
+
const penaltyAssets = reallocations.reduce((total, reallocation) => total +
|
|
55
|
+
blue_sdk_1.VaultV2BluePublicAllocatorConfigUtils.getPenaltyAssets(reallocation, reallocation.assets), 0n);
|
|
56
|
+
if (penaltyAssets > 0n) {
|
|
57
|
+
const { bundler3: { bundler3, generalAdapter1 }, } = (0, blue_sdk_1.getChainAddresses)(chainId);
|
|
58
|
+
actions.push(penaltyFundingSource === "generalAdapter1"
|
|
59
|
+
? {
|
|
60
|
+
type: "erc20Transfer",
|
|
61
|
+
args: [
|
|
62
|
+
targetMarketParams.loanToken,
|
|
63
|
+
bundler3,
|
|
64
|
+
penaltyAssets,
|
|
65
|
+
generalAdapter1,
|
|
66
|
+
false,
|
|
67
|
+
],
|
|
68
|
+
}
|
|
69
|
+
: {
|
|
70
|
+
type: "erc20TransferFrom",
|
|
71
|
+
args: [
|
|
72
|
+
targetMarketParams.loanToken,
|
|
73
|
+
penaltyAssets,
|
|
74
|
+
bundler3,
|
|
75
|
+
false,
|
|
76
|
+
],
|
|
77
|
+
});
|
|
78
|
+
}
|
|
79
|
+
for (const reallocation of reallocations) {
|
|
80
|
+
actions.push(reallocation.from.type === "market"
|
|
81
|
+
? {
|
|
82
|
+
type: "vaultV2BluePublicAllocatorReallocate",
|
|
83
|
+
args: [
|
|
84
|
+
reallocation.vault,
|
|
85
|
+
reallocation.from.adapter,
|
|
86
|
+
reallocation.from.marketParams,
|
|
87
|
+
reallocation.to.adapter,
|
|
88
|
+
targetMarketParams,
|
|
89
|
+
reallocation.assets,
|
|
90
|
+
reallocation.penalty,
|
|
91
|
+
false,
|
|
92
|
+
],
|
|
93
|
+
}
|
|
94
|
+
: {
|
|
95
|
+
type: "vaultV2BluePublicAllocatorAllocateFromIdle",
|
|
96
|
+
args: [
|
|
97
|
+
reallocation.vault,
|
|
98
|
+
reallocation.to.adapter,
|
|
99
|
+
targetMarketParams,
|
|
100
|
+
reallocation.assets,
|
|
101
|
+
reallocation.penalty,
|
|
102
|
+
false,
|
|
103
|
+
],
|
|
104
|
+
});
|
|
105
|
+
}
|
|
106
|
+
return { actions, fee: 0n, penaltyAssets };
|
|
107
|
+
};
|
|
108
|
+
exports.buildVaultV2BlueReallocationActions = buildVaultV2BlueReallocationActions;
|
|
109
|
+
/**
|
|
110
|
+
* Validates a homogeneous Blue reallocation plan and builds its Bundler actions.
|
|
111
|
+
*
|
|
112
|
+
* Dispatches Vault V1 and Vault V2 plans to their version-specific builders. V1 plans aggregate
|
|
113
|
+
* native fees, while V2 plans aggregate loan-token penalties using the selected funding source.
|
|
114
|
+
*
|
|
115
|
+
* @param params.chainId - Chain whose registered Bundler3 and allocator addresses are used.
|
|
116
|
+
* @param params.reallocations - Optional homogeneous Vault V1 or Vault V2 reallocation plan.
|
|
117
|
+
* @param params.targetMarketParams - Morpho Blue market receiving the reallocated liquidity.
|
|
118
|
+
* @param params.penaltyFundingSource - Optional source of V2 penalty assets. Defaults to the
|
|
119
|
+
* transaction initiator.
|
|
120
|
+
* @returns The reallocation actions, aggregate V1 native fee, and aggregate V2 penalty assets.
|
|
121
|
+
* @internal
|
|
122
|
+
*/
|
|
123
|
+
const buildBlueReallocationActions = ({ chainId, reallocations, targetMarketParams, penaltyFundingSource, }) => {
|
|
124
|
+
const reallocationPlan = (0, validate_js_1.validateAndNormalizeReallocations)({
|
|
125
|
+
reallocations,
|
|
126
|
+
targetMarketId: targetMarketParams.id,
|
|
127
|
+
chainId,
|
|
128
|
+
});
|
|
129
|
+
return reallocationPlan.type === "vaultV1"
|
|
130
|
+
? (0, exports.buildVaultV1ReallocationActions)({
|
|
131
|
+
reallocations: reallocationPlan.reallocations,
|
|
132
|
+
targetMarketParams,
|
|
133
|
+
})
|
|
134
|
+
: (0, exports.buildVaultV2BlueReallocationActions)({
|
|
135
|
+
chainId,
|
|
136
|
+
reallocations: reallocationPlan.reallocations,
|
|
137
|
+
targetMarketParams,
|
|
138
|
+
penaltyFundingSource,
|
|
139
|
+
});
|
|
140
|
+
};
|
|
141
|
+
exports.buildBlueReallocationActions = buildBlueReallocationActions;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { type MarketParams } from "@morpho-org/blue-sdk";
|
|
2
2
|
import { type Address } from "viem";
|
|
3
|
-
import { type AuthorizationRequirementSignature, type
|
|
3
|
+
import { type AuthorizationRequirementSignature, type BlueReallocationPlan, type BlueRefinanceAction, type Metadata, type Transaction } from "../../types/index.js";
|
|
4
4
|
/** Parameters for {@link blueRefinance}. */
|
|
5
5
|
export interface BlueRefinanceParams {
|
|
6
6
|
source: {
|
|
@@ -27,8 +27,8 @@ export interface BlueRefinanceParams {
|
|
|
27
27
|
minBorrowSharePrice: bigint;
|
|
28
28
|
/** Maximum repay share price on the source market (in ray); must be > 0 when a repay leg exists. */
|
|
29
29
|
maxRepaySharePrice: bigint;
|
|
30
|
-
/**
|
|
31
|
-
targetReallocations?:
|
|
30
|
+
/** Homogeneous Vault V1 or Vault V2 reallocations into the target market. */
|
|
31
|
+
targetReallocations?: BlueReallocationPlan;
|
|
32
32
|
/**
|
|
33
33
|
* Optional signed Morpho authorization. When provided, a `setAuthorizationWithSig` call is
|
|
34
34
|
* prepended to the bundle so GeneralAdapter1 is authorized in-bundle instead of via a
|
|
@@ -49,8 +49,8 @@ export interface BlueRefinanceParams {
|
|
|
49
49
|
* Bundle shape (callback contents depend on borrow mode):
|
|
50
50
|
*
|
|
51
51
|
* ```text
|
|
52
|
-
* // optional
|
|
53
|
-
* reallocateTo(
|
|
52
|
+
* // optional targetReallocations run first:
|
|
53
|
+
* reallocateTo(...) | reallocate(...) | allocateFromIdle(...),
|
|
54
54
|
*
|
|
55
55
|
* morphoSupplyCollateral(target, collateralAmount, user, [
|
|
56
56
|
* // omitted in collat-only mode
|
|
@@ -84,7 +84,8 @@ export interface BlueRefinanceParams {
|
|
|
84
84
|
* @param params.args.borrowShares - Borrow shares to repay on the source; exclusive with `borrowAssets`. Defaults to `0n`.
|
|
85
85
|
* @param params.args.minBorrowSharePrice - Minimum borrow share price (ray) on the target.
|
|
86
86
|
* @param params.args.maxRepaySharePrice - Maximum repay share price (ray) on the source.
|
|
87
|
-
* @param params.args.targetReallocations -
|
|
87
|
+
* @param params.args.targetReallocations - Homogeneous Vault V1 or Vault V2 reallocations into the
|
|
88
|
+
* target, run before the supply leg. V1 fees add to `tx.value`; V2 penalties are paid in the target loan token.
|
|
88
89
|
* @param params.args.authorizationSignature - Optional signed Morpho authorization; when present,
|
|
89
90
|
* a `setAuthorizationWithSig` call is prepended to the bundle.
|
|
90
91
|
* @param params.metadata - Optional analytics metadata appended to `tx.data`.
|
|
@@ -93,8 +94,14 @@ export interface BlueRefinanceParams {
|
|
|
93
94
|
* repay); in shares mode the entity passes both. Caller-facing mutual exclusivity is enforced at the entity layer.
|
|
94
95
|
* @throws {NonPositiveInputError} when `collateralAmount <= 0n`, a repay leg has a non-positive
|
|
95
96
|
* `maxRepaySharePrice`, or any reallocation withdrawal amount is non-positive.
|
|
97
|
+
* @throws {InputExceedsMaxError} when a V2 reallocation asset amount exceeds `uint128` or its penalty exceeds WAD.
|
|
98
|
+
* @throws {InconsistentReallocationPenaltyError} when V2 entries for one vault use different penalties.
|
|
99
|
+
* @throws {InvalidReallocationAddressError} when a V2 vault or adapter address is malformed.
|
|
100
|
+
* @throws {InvalidReallocationSourceTypeError} when a V2 source is absent, incomplete, or has an unknown discriminator.
|
|
101
|
+
* @throws {InvalidReallocationShapeError} when an entry matches both or neither V1/V2 shape.
|
|
102
|
+
* @throws {MixedReallocationVersionsError} when one plan contains both V1 and V2 entries.
|
|
96
103
|
* @throws {NegativeInputError} when `borrowAssets`, `borrowShares`, `minBorrowSharePrice`,
|
|
97
|
-
* `maxRepaySharePrice`, or
|
|
104
|
+
* `maxRepaySharePrice`, a V1 fee, or a V2 penalty is negative.
|
|
98
105
|
* @throws {RefinanceSameMarketError} when source and target market ids are equal.
|
|
99
106
|
* @throws {RefinanceTokenMismatchError} when source and target do not share both tokens.
|
|
100
107
|
* @throws {RefinanceSharesMissingBorrowAssetsError} when `borrowShares > 0n` but `borrowAssets` is omitted or non-positive.
|