@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
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { getChainAddresses, } from "@morpho-org/blue-sdk";
|
|
2
|
-
import { blueAbi, erc2612Abi, permit2Abi,
|
|
3
|
-
import { encodeAbiParameters, encodeFunctionData, isAddressEqual, keccak256, parseSignature, serializeSignature, zeroHash, } from "viem";
|
|
1
|
+
import { getChainAddresses, VaultV2BluePublicAllocatorConfigUtils, } from "@morpho-org/blue-sdk";
|
|
2
|
+
import { blueAbi, erc2612Abi, permit2Abi, vaultV1PublicAllocatorAbi, vaultV2BluePublicAllocatorAbi, } from "@morpho-org/blue-sdk-viem";
|
|
3
|
+
import { encodeAbiParameters, encodeFunctionData, erc20Abi, isAddressEqual, keccak256, parseSignature, serializeSignature, zeroHash, } from "viem";
|
|
4
4
|
import { bundler3Abi, coreAdapterAbi, generalAdapter1Abi } from "../abis.js";
|
|
5
5
|
import { BundlerErrors } from "../types/error.js";
|
|
6
6
|
const reenterAbiInputs = bundler3Abi.find((item) => item.type === "function" && item.name === "reenter").inputs;
|
|
@@ -71,7 +71,7 @@ export var BundlerAction;
|
|
|
71
71
|
*
|
|
72
72
|
* @example
|
|
73
73
|
* ```ts
|
|
74
|
-
* import { getChainAddresses } from "@morpho-org/
|
|
74
|
+
* import { getChainAddresses } from "@morpho-org/morpho-sdk/addresses";
|
|
75
75
|
* import { BundlerAction } from "@morpho-org/morpho-sdk/bundler";
|
|
76
76
|
*
|
|
77
77
|
* const { generalAdapter1 } = getChainAddresses(1).bundler3;
|
|
@@ -193,6 +193,12 @@ export var BundlerAction;
|
|
|
193
193
|
case "reallocateTo": {
|
|
194
194
|
return BundlerAction.publicAllocatorReallocateTo(chainId, ...args);
|
|
195
195
|
}
|
|
196
|
+
case "vaultV2BluePublicAllocatorReallocate": {
|
|
197
|
+
return BundlerAction.vaultV2BluePublicAllocatorReallocate(chainId, ...args);
|
|
198
|
+
}
|
|
199
|
+
case "vaultV2BluePublicAllocatorAllocateFromIdle": {
|
|
200
|
+
return BundlerAction.vaultV2BluePublicAllocatorAllocateFromIdle(chainId, ...args);
|
|
201
|
+
}
|
|
196
202
|
case "wrapNative": {
|
|
197
203
|
return BundlerAction.wrapNative(chainId, ...args);
|
|
198
204
|
}
|
|
@@ -326,7 +332,7 @@ export var BundlerAction;
|
|
|
326
332
|
*
|
|
327
333
|
* @example
|
|
328
334
|
* ```ts
|
|
329
|
-
* import { getChainAddresses } from "@morpho-org/
|
|
335
|
+
* import { getChainAddresses } from "@morpho-org/morpho-sdk/addresses";
|
|
330
336
|
* import { BundlerAction } from "@morpho-org/morpho-sdk/bundler";
|
|
331
337
|
*
|
|
332
338
|
* const adapter = getChainAddresses(1).bundler3.generalAdapter1;
|
|
@@ -669,7 +675,7 @@ export var BundlerAction;
|
|
|
669
675
|
*
|
|
670
676
|
* @example
|
|
671
677
|
* ```ts
|
|
672
|
-
* import { getChainAddresses } from "@morpho-org/
|
|
678
|
+
* import { getChainAddresses } from "@morpho-org/morpho-sdk/addresses";
|
|
673
679
|
* import { BundlerAction } from "@morpho-org/morpho-sdk/bundler";
|
|
674
680
|
*
|
|
675
681
|
* const { generalAdapter1 } = getChainAddresses(1).bundler3;
|
|
@@ -1095,15 +1101,15 @@ export var BundlerAction;
|
|
|
1095
1101
|
*/
|
|
1096
1102
|
// biome-ignore lint/complexity/useMaxParams: TODO refactor to ≤2 params
|
|
1097
1103
|
function publicAllocatorReallocateTo(chainId, vault, fee, withdrawals, supplyMarketParams, skipRevert = false) {
|
|
1098
|
-
const {
|
|
1099
|
-
if (
|
|
1104
|
+
const { vaultV1PublicAllocator } = getChainAddresses(chainId);
|
|
1105
|
+
if (vaultV1PublicAllocator == null) {
|
|
1100
1106
|
throw new BundlerErrors.UnexpectedAction("reallocateTo", chainId);
|
|
1101
1107
|
}
|
|
1102
1108
|
return [
|
|
1103
1109
|
{
|
|
1104
|
-
to:
|
|
1110
|
+
to: vaultV1PublicAllocator,
|
|
1105
1111
|
data: encodeFunctionData({
|
|
1106
|
-
abi:
|
|
1112
|
+
abi: vaultV1PublicAllocatorAbi,
|
|
1107
1113
|
functionName: "reallocateTo",
|
|
1108
1114
|
args: [vault, withdrawals, supplyMarketParams],
|
|
1109
1115
|
}),
|
|
@@ -1114,6 +1120,209 @@ export var BundlerAction;
|
|
|
1114
1120
|
];
|
|
1115
1121
|
}
|
|
1116
1122
|
BundlerAction.publicAllocatorReallocateTo = publicAllocatorReallocateTo;
|
|
1123
|
+
/**
|
|
1124
|
+
* Encodes a Vault V2 Blue Public Allocator market-to-market reallocation.
|
|
1125
|
+
*
|
|
1126
|
+
* @remarks Bundler3 must already hold the computed penalty assets. The
|
|
1127
|
+
* high-level Blue builders add the corresponding GeneralAdapter1 transfer.
|
|
1128
|
+
*
|
|
1129
|
+
* @param chainId - Chain whose canonical Blue Public Allocator is called.
|
|
1130
|
+
* @param vault - Vault whose liquidity is reallocated.
|
|
1131
|
+
* @param deallocateAdapter - Vault V2 adapter supplying the source market.
|
|
1132
|
+
* @param deallocateMarket - Source Morpho Blue market parameters.
|
|
1133
|
+
* @param allocateAdapter - Vault V2 adapter supplying the target market.
|
|
1134
|
+
* @param allocateMarket - Target Morpho Blue market parameters.
|
|
1135
|
+
* @param assets - Assets to reallocate, bounded by `uint128` by the high-level action.
|
|
1136
|
+
* @param penalty - Vault-configured proportional penalty, scaled by WAD.
|
|
1137
|
+
* @param skipRevert - Whether Bundler3 should tolerate a revert.
|
|
1138
|
+
* @returns A zero reset and exact approval when needed, then the allocator call.
|
|
1139
|
+
* @throws {BundlerErrors.UnexpectedAction} when the chain has no Blue Public Allocator deployment.
|
|
1140
|
+
* @throws {BundlerErrors.SkippableAllocatorPenalty} when `skipRevert` is true and a token approval is required.
|
|
1141
|
+
* @example
|
|
1142
|
+
* ```ts
|
|
1143
|
+
* import { ChainId } from "@morpho-org/morpho-sdk/constants";
|
|
1144
|
+
* import type { BlueInputMarketParams } from "@morpho-org/morpho-sdk/types";
|
|
1145
|
+
* import {
|
|
1146
|
+
* BundlerAction,
|
|
1147
|
+
* type BundlerCall,
|
|
1148
|
+
* } from "@morpho-org/morpho-sdk/bundler";
|
|
1149
|
+
* import type { Address } from "viem";
|
|
1150
|
+
*
|
|
1151
|
+
* const keyrockUsdcVault =
|
|
1152
|
+
* "0x04422053aDDbc9bB2759b248B574e3FCA76Bc145" satisfies Address;
|
|
1153
|
+
* const sourceAdapterFixture =
|
|
1154
|
+
* "0x70997970C51812dc3A010C7d01b50e0d17dc79C8" satisfies Address;
|
|
1155
|
+
* const targetAdapterFixture =
|
|
1156
|
+
* "0x3C44CdDdB6a900fa2b585dd299e03d12FA4293BC" satisfies Address;
|
|
1157
|
+
* const usdc = "0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48" satisfies Address;
|
|
1158
|
+
* const weth = "0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2" satisfies Address;
|
|
1159
|
+
* const wbtc = "0x2260FAC5E5542a773Aa44fBCfeDf7C193bc2C599" satisfies Address;
|
|
1160
|
+
* const ethUsdOracle = "0x5f4eC3Df9cbd43714FE2740f5E3616155c5b8419" satisfies Address;
|
|
1161
|
+
* const adaptiveCurveIrm = "0x870aC11D48B15DB9a138Cf899d20F13F79Ba00BC" satisfies Address;
|
|
1162
|
+
* const sourceMarket = {
|
|
1163
|
+
* loanToken: usdc,
|
|
1164
|
+
* collateralToken: weth,
|
|
1165
|
+
* oracle: ethUsdOracle,
|
|
1166
|
+
* irm: adaptiveCurveIrm,
|
|
1167
|
+
* lltv: 860_000_000_000_000_000n,
|
|
1168
|
+
* } satisfies BlueInputMarketParams;
|
|
1169
|
+
* const targetMarket = {
|
|
1170
|
+
* ...sourceMarket,
|
|
1171
|
+
* collateralToken: wbtc,
|
|
1172
|
+
* } satisfies BlueInputMarketParams;
|
|
1173
|
+
*
|
|
1174
|
+
* const calls: BundlerCall[] = BundlerAction.vaultV2BluePublicAllocatorReallocate(
|
|
1175
|
+
* ChainId.EthMainnet,
|
|
1176
|
+
* keyrockUsdcVault,
|
|
1177
|
+
* sourceAdapterFixture,
|
|
1178
|
+
* sourceMarket,
|
|
1179
|
+
* targetAdapterFixture,
|
|
1180
|
+
* targetMarket,
|
|
1181
|
+
* 1_000_000n,
|
|
1182
|
+
* 1_000_000_000_000_000n,
|
|
1183
|
+
* );
|
|
1184
|
+
* // Bundler3 resets and approves 1_000 USDC units, then calls `reallocate` with zero native value.
|
|
1185
|
+
* ```
|
|
1186
|
+
*/
|
|
1187
|
+
// biome-ignore lint/complexity/useMaxParams: mirrors the protocol call
|
|
1188
|
+
function vaultV2BluePublicAllocatorReallocate(chainId, vault, deallocateAdapter, deallocateMarket, allocateAdapter, allocateMarket, assets, penalty, skipRevert = false) {
|
|
1189
|
+
const { vaultV2BluePublicAllocator: allocator } = getChainAddresses(chainId);
|
|
1190
|
+
if (allocator == null) {
|
|
1191
|
+
throw new BundlerErrors.UnexpectedAction("vaultV2BluePublicAllocatorReallocate", chainId);
|
|
1192
|
+
}
|
|
1193
|
+
const calls = [];
|
|
1194
|
+
const penaltyAssets = VaultV2BluePublicAllocatorConfigUtils.getPenaltyAssets({ penalty }, assets);
|
|
1195
|
+
if (skipRevert && penaltyAssets > 0n) {
|
|
1196
|
+
throw new BundlerErrors.SkippableAllocatorPenalty(penaltyAssets);
|
|
1197
|
+
}
|
|
1198
|
+
if (penaltyAssets > 0n) {
|
|
1199
|
+
for (const amount of [0n, penaltyAssets])
|
|
1200
|
+
calls.push({
|
|
1201
|
+
to: allocateMarket.loanToken,
|
|
1202
|
+
data: encodeFunctionData({
|
|
1203
|
+
abi: erc20Abi,
|
|
1204
|
+
functionName: "approve",
|
|
1205
|
+
args: [allocator, amount],
|
|
1206
|
+
}),
|
|
1207
|
+
value: 0n,
|
|
1208
|
+
skipRevert,
|
|
1209
|
+
callbackHash: zeroHash,
|
|
1210
|
+
});
|
|
1211
|
+
}
|
|
1212
|
+
calls.push({
|
|
1213
|
+
to: allocator,
|
|
1214
|
+
data: encodeFunctionData({
|
|
1215
|
+
abi: vaultV2BluePublicAllocatorAbi,
|
|
1216
|
+
functionName: "reallocate",
|
|
1217
|
+
args: [
|
|
1218
|
+
vault,
|
|
1219
|
+
deallocateAdapter,
|
|
1220
|
+
deallocateMarket,
|
|
1221
|
+
allocateAdapter,
|
|
1222
|
+
allocateMarket,
|
|
1223
|
+
assets,
|
|
1224
|
+
penalty,
|
|
1225
|
+
],
|
|
1226
|
+
}),
|
|
1227
|
+
value: 0n,
|
|
1228
|
+
skipRevert,
|
|
1229
|
+
callbackHash: zeroHash,
|
|
1230
|
+
});
|
|
1231
|
+
return calls;
|
|
1232
|
+
}
|
|
1233
|
+
BundlerAction.vaultV2BluePublicAllocatorReallocate = vaultV2BluePublicAllocatorReallocate;
|
|
1234
|
+
/**
|
|
1235
|
+
* Encodes a Vault V2 Blue Public Allocator allocation from vault idle liquidity.
|
|
1236
|
+
*
|
|
1237
|
+
* @remarks Bundler3 must already hold the computed penalty assets. The
|
|
1238
|
+
* high-level Blue builders add the corresponding GeneralAdapter1 transfer.
|
|
1239
|
+
*
|
|
1240
|
+
* @param chainId - Chain whose canonical Blue Public Allocator is called.
|
|
1241
|
+
* @param vault - Vault whose idle liquidity is allocated.
|
|
1242
|
+
* @param adapter - Vault V2 adapter supplying the target market.
|
|
1243
|
+
* @param market - Target Morpho Blue market parameters.
|
|
1244
|
+
* @param assets - Assets to allocate, bounded by `uint128` by the high-level action.
|
|
1245
|
+
* @param penalty - Vault-configured proportional penalty, scaled by WAD.
|
|
1246
|
+
* @param skipRevert - Whether Bundler3 should tolerate a revert.
|
|
1247
|
+
* @returns A zero reset and exact approval when needed, then the allocator call.
|
|
1248
|
+
* @throws {BundlerErrors.UnexpectedAction} when the chain has no Blue Public Allocator deployment.
|
|
1249
|
+
* @throws {BundlerErrors.SkippableAllocatorPenalty} when `skipRevert` is true and a token approval is required.
|
|
1250
|
+
* @example
|
|
1251
|
+
* ```ts
|
|
1252
|
+
* import { ChainId } from "@morpho-org/morpho-sdk/constants";
|
|
1253
|
+
* import type { BlueInputMarketParams } from "@morpho-org/morpho-sdk/types";
|
|
1254
|
+
* import {
|
|
1255
|
+
* BundlerAction,
|
|
1256
|
+
* type BundlerCall,
|
|
1257
|
+
* } from "@morpho-org/morpho-sdk/bundler";
|
|
1258
|
+
* import type { Address } from "viem";
|
|
1259
|
+
*
|
|
1260
|
+
* const keyrockUsdcVault =
|
|
1261
|
+
* "0x04422053aDDbc9bB2759b248B574e3FCA76Bc145" satisfies Address;
|
|
1262
|
+
* const targetAdapterFixture =
|
|
1263
|
+
* "0x3C44CdDdB6a900fa2b585dd299e03d12FA4293BC" satisfies Address;
|
|
1264
|
+
* const usdc = "0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48" satisfies Address;
|
|
1265
|
+
* const weth = "0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2" satisfies Address;
|
|
1266
|
+
* const ethUsdOracle = "0x5f4eC3Df9cbd43714FE2740f5E3616155c5b8419" satisfies Address;
|
|
1267
|
+
* const adaptiveCurveIrm = "0x870aC11D48B15DB9a138Cf899d20F13F79Ba00BC" satisfies Address;
|
|
1268
|
+
* const targetMarket = {
|
|
1269
|
+
* loanToken: usdc,
|
|
1270
|
+
* collateralToken: weth,
|
|
1271
|
+
* oracle: ethUsdOracle,
|
|
1272
|
+
* irm: adaptiveCurveIrm,
|
|
1273
|
+
* lltv: 860_000_000_000_000_000n,
|
|
1274
|
+
* } satisfies BlueInputMarketParams;
|
|
1275
|
+
*
|
|
1276
|
+
* const calls: BundlerCall[] = BundlerAction.vaultV2BluePublicAllocatorAllocateFromIdle(
|
|
1277
|
+
* ChainId.EthMainnet,
|
|
1278
|
+
* keyrockUsdcVault,
|
|
1279
|
+
* targetAdapterFixture,
|
|
1280
|
+
* targetMarket,
|
|
1281
|
+
* 1_000_000n,
|
|
1282
|
+
* 1_000_000_000_000_000n,
|
|
1283
|
+
* );
|
|
1284
|
+
* // Bundler3 resets and approves 1_000 USDC units, then calls `allocateFromIdle` with zero native value.
|
|
1285
|
+
* ```
|
|
1286
|
+
*/
|
|
1287
|
+
// biome-ignore lint/complexity/useMaxParams: mirrors the protocol call
|
|
1288
|
+
function vaultV2BluePublicAllocatorAllocateFromIdle(chainId, vault, adapter, market, assets, penalty, skipRevert = false) {
|
|
1289
|
+
const { vaultV2BluePublicAllocator: allocator } = getChainAddresses(chainId);
|
|
1290
|
+
if (allocator == null) {
|
|
1291
|
+
throw new BundlerErrors.UnexpectedAction("vaultV2BluePublicAllocatorAllocateFromIdle", chainId);
|
|
1292
|
+
}
|
|
1293
|
+
const calls = [];
|
|
1294
|
+
const penaltyAssets = VaultV2BluePublicAllocatorConfigUtils.getPenaltyAssets({ penalty }, assets);
|
|
1295
|
+
if (skipRevert && penaltyAssets > 0n) {
|
|
1296
|
+
throw new BundlerErrors.SkippableAllocatorPenalty(penaltyAssets);
|
|
1297
|
+
}
|
|
1298
|
+
if (penaltyAssets > 0n) {
|
|
1299
|
+
for (const amount of [0n, penaltyAssets])
|
|
1300
|
+
calls.push({
|
|
1301
|
+
to: market.loanToken,
|
|
1302
|
+
data: encodeFunctionData({
|
|
1303
|
+
abi: erc20Abi,
|
|
1304
|
+
functionName: "approve",
|
|
1305
|
+
args: [allocator, amount],
|
|
1306
|
+
}),
|
|
1307
|
+
value: 0n,
|
|
1308
|
+
skipRevert,
|
|
1309
|
+
callbackHash: zeroHash,
|
|
1310
|
+
});
|
|
1311
|
+
}
|
|
1312
|
+
calls.push({
|
|
1313
|
+
to: allocator,
|
|
1314
|
+
data: encodeFunctionData({
|
|
1315
|
+
abi: vaultV2BluePublicAllocatorAbi,
|
|
1316
|
+
functionName: "allocateFromIdle",
|
|
1317
|
+
args: [vault, adapter, market, assets, penalty],
|
|
1318
|
+
}),
|
|
1319
|
+
value: 0n,
|
|
1320
|
+
skipRevert,
|
|
1321
|
+
callbackHash: zeroHash,
|
|
1322
|
+
});
|
|
1323
|
+
return calls;
|
|
1324
|
+
}
|
|
1325
|
+
BundlerAction.vaultV2BluePublicAllocatorAllocateFromIdle = vaultV2BluePublicAllocatorAllocateFromIdle;
|
|
1117
1326
|
/**
|
|
1118
1327
|
* Encodes a GeneralAdapter1 native-token wrap call.
|
|
1119
1328
|
*
|
|
@@ -180,6 +180,26 @@ export interface ActionArgs {
|
|
|
180
180
|
supplyMarket: InputMarketParams,
|
|
181
181
|
skipRevert?: boolean
|
|
182
182
|
];
|
|
183
|
+
/** Vault V2 Blue Public Allocator market-to-market reallocation with a WAD-scaled penalty. */
|
|
184
|
+
readonly vaultV2BluePublicAllocatorReallocate: [
|
|
185
|
+
vault: Address,
|
|
186
|
+
deallocateAdapter: Address,
|
|
187
|
+
deallocateMarket: InputMarketParams,
|
|
188
|
+
allocateAdapter: Address,
|
|
189
|
+
allocateMarket: InputMarketParams,
|
|
190
|
+
assets: bigint,
|
|
191
|
+
penalty: bigint,
|
|
192
|
+
skipRevert?: boolean
|
|
193
|
+
];
|
|
194
|
+
/** Vault V2 Blue Public Allocator idle-to-market allocation with a WAD-scaled penalty. */
|
|
195
|
+
readonly vaultV2BluePublicAllocatorAllocateFromIdle: [
|
|
196
|
+
vault: Address,
|
|
197
|
+
adapter: Address,
|
|
198
|
+
market: InputMarketParams,
|
|
199
|
+
assets: bigint,
|
|
200
|
+
penalty: bigint,
|
|
201
|
+
skipRevert?: boolean
|
|
202
|
+
];
|
|
183
203
|
/** GeneralAdapter1 native wrap of `amount` to `recipient`; `skipRevert` controls Bundler3 revert handling. */
|
|
184
204
|
readonly wrapNative: [
|
|
185
205
|
amount: bigint,
|
package/lib/esm/constants.d.ts
CHANGED
|
@@ -1,4 +1,38 @@
|
|
|
1
|
-
export { DEFAULT_SLIPPAGE_TOLERANCE, EIP_712_FIELDS,
|
|
2
|
-
|
|
1
|
+
export { DEFAULT_SLIPPAGE_TOLERANCE, EIP_712_FIELDS, ERC20_ALLOWANCE_RECIPIENTS, isMarketId as isBlueMarketId,
|
|
2
|
+
/** @deprecated Use `isBlueMarketId` or the raw `/blue/constants` subpath. */
|
|
3
|
+
isMarketId, LIQUIDATION_CURSOR as BLUE_LIQUIDATION_CURSOR,
|
|
4
|
+
/** @deprecated Use `BLUE_LIQUIDATION_CURSOR` or the raw `/blue/constants` subpath. */
|
|
5
|
+
LIQUIDATION_CURSOR, MAX_LIQUIDATION_INCENTIVE_FACTOR as BLUE_MAX_LIQUIDATION_INCENTIVE_FACTOR,
|
|
6
|
+
/** @deprecated Use `BLUE_MAX_LIQUIDATION_INCENTIVE_FACTOR` or the raw `/blue/constants` subpath. */
|
|
7
|
+
MAX_LIQUIDATION_INCENTIVE_FACTOR, ORACLE_PRICE_SCALE, SECONDS_PER_YEAR, TransactionType as BlueTransactionType,
|
|
8
|
+
/** @deprecated Use `BlueTransactionType` or the raw `/blue/constants` subpath. */
|
|
9
|
+
TransactionType, } from "@morpho-org/blue-sdk";
|
|
10
|
+
export { CBP as MIDNIGHT_CBP,
|
|
11
|
+
/** @deprecated Use `MIDNIGHT_CBP` or the raw `/midnight/constants` subpath. */
|
|
12
|
+
CBP, COLLATERAL_PARAMS_TYPEHASH as MIDNIGHT_COLLATERAL_PARAMS_TYPEHASH,
|
|
13
|
+
/** @deprecated Use `MIDNIGHT_COLLATERAL_PARAMS_TYPEHASH` or the raw `/midnight/constants` subpath. */
|
|
14
|
+
COLLATERAL_PARAMS_TYPEHASH, DEFAULT_TICK_SPACING as MIDNIGHT_DEFAULT_TICK_SPACING,
|
|
15
|
+
/** @deprecated Use `MIDNIGHT_DEFAULT_TICK_SPACING` or the raw `/midnight/constants` subpath. */
|
|
16
|
+
DEFAULT_TICK_SPACING, EIP712_DOMAIN_TYPEHASH as MIDNIGHT_EIP712_DOMAIN_TYPEHASH,
|
|
17
|
+
/** @deprecated Use `MIDNIGHT_EIP712_DOMAIN_TYPEHASH` or the raw `/midnight/constants` subpath. */
|
|
18
|
+
EIP712_DOMAIN_TYPEHASH, MARKET_TYPEHASH as MIDNIGHT_MARKET_TYPEHASH,
|
|
19
|
+
/** @deprecated Use `MIDNIGHT_MARKET_TYPEHASH` or the raw `/midnight/constants` subpath. */
|
|
20
|
+
MARKET_TYPEHASH, MAX_COLLATERALS as MIDNIGHT_MAX_COLLATERALS,
|
|
21
|
+
/** @deprecated Use `MIDNIGHT_MAX_COLLATERALS` or the raw `/midnight/constants` subpath. */
|
|
22
|
+
MAX_COLLATERALS, MAX_COLLATERALS_PER_BORROWER as MIDNIGHT_MAX_COLLATERALS_PER_BORROWER,
|
|
23
|
+
/** @deprecated Use `MIDNIGHT_MAX_COLLATERALS_PER_BORROWER` or the raw `/midnight/constants` subpath. */
|
|
24
|
+
MAX_COLLATERALS_PER_BORROWER, MAX_CONTINUOUS_FEE as MIDNIGHT_MAX_CONTINUOUS_FEE,
|
|
25
|
+
/** @deprecated Use `MIDNIGHT_MAX_CONTINUOUS_FEE` or the raw `/midnight/constants` subpath. */
|
|
26
|
+
MAX_CONTINUOUS_FEE, MAX_OFFER_CAP as MIDNIGHT_MAX_OFFER_CAP, MAX_SETTLEMENT_FEES as MIDNIGHT_MAX_SETTLEMENT_FEES,
|
|
27
|
+
/** @deprecated Use `MIDNIGHT_MAX_SETTLEMENT_FEES` or the raw `/midnight/constants` subpath. */
|
|
28
|
+
MAX_SETTLEMENT_FEES, MAX_TICK as MIDNIGHT_MAX_TICK,
|
|
29
|
+
/** @deprecated Use `MIDNIGHT_MAX_TICK` or the raw `/midnight/constants` subpath. */
|
|
30
|
+
MAX_TICK, OFFER_TYPEHASH as MIDNIGHT_OFFER_TYPEHASH,
|
|
31
|
+
/** @deprecated Use `MIDNIGHT_OFFER_TYPEHASH` or the raw `/midnight/constants` subpath. */
|
|
32
|
+
OFFER_TYPEHASH, PRICE_ROUNDING_STEP as MIDNIGHT_PRICE_ROUNDING_STEP,
|
|
33
|
+
/** @deprecated Use `MIDNIGHT_PRICE_ROUNDING_STEP` or the raw `/midnight/constants` subpath. */
|
|
34
|
+
PRICE_ROUNDING_STEP, SETTLEMENT_FEE_BREAKPOINTS as MIDNIGHT_SETTLEMENT_FEE_BREAKPOINTS,
|
|
35
|
+
/** @deprecated Use `MIDNIGHT_SETTLEMENT_FEE_BREAKPOINTS` or the raw `/midnight/constants` subpath. */
|
|
36
|
+
SETTLEMENT_FEE_BREAKPOINTS, TIME_TO_MAX_LIF as MIDNIGHT_TIME_TO_MAX_LIF, } from "@morpho-org/midnight-sdk";
|
|
3
37
|
export { BLUE_API_BASE_URL, BLUE_API_GRAPHQL_URL, CDN_BASE_URL, ChainId, ChainUtils, DOCS_BASE_URL, MORPHO_DOMAIN, OPTIMIZERS_API_BASE_URL, OPTIMIZERS_BASE_URL, REWARDS_BASE_URL, ZERO_ADDRESS, } from "@morpho-org/morpho-ts";
|
|
4
|
-
export { APPROVE_ONLY_ONCE_TOKENS, DEFAULT_LLTV_BUFFER, DEFAULT_SUPPLY_TARGET_UTILIZATION, DEFAULT_WITHDRAWAL_TARGET_UTILIZATION, MAX_ABSOLUTE_SHARE_PRICE, MAX_SLIPPAGE_TOLERANCE, MAX_TOKEN_APPROVALS, } from "./helpers/constant.js";
|
|
38
|
+
export { APPROVE_ONLY_ONCE_TOKENS, DEFAULT_LLTV_BUFFER, DEFAULT_MAX_REALLOCATION_PENALTY, DEFAULT_SUPPLY_TARGET_UTILIZATION, DEFAULT_WITHDRAWAL_TARGET_UTILIZATION, MAX_ABSOLUTE_SHARE_PRICE, MAX_REALLOCATION_PENALTY, MAX_SLIPPAGE_TOLERANCE, MAX_TOKEN_APPROVALS, } from "./helpers/constant.js";
|
package/lib/esm/constants.js
CHANGED
|
@@ -1,4 +1,38 @@
|
|
|
1
|
-
export { DEFAULT_SLIPPAGE_TOLERANCE, EIP_712_FIELDS,
|
|
2
|
-
|
|
1
|
+
export { DEFAULT_SLIPPAGE_TOLERANCE, EIP_712_FIELDS, ERC20_ALLOWANCE_RECIPIENTS, isMarketId as isBlueMarketId,
|
|
2
|
+
/** @deprecated Use `isBlueMarketId` or the raw `/blue/constants` subpath. */
|
|
3
|
+
isMarketId, LIQUIDATION_CURSOR as BLUE_LIQUIDATION_CURSOR,
|
|
4
|
+
/** @deprecated Use `BLUE_LIQUIDATION_CURSOR` or the raw `/blue/constants` subpath. */
|
|
5
|
+
LIQUIDATION_CURSOR, MAX_LIQUIDATION_INCENTIVE_FACTOR as BLUE_MAX_LIQUIDATION_INCENTIVE_FACTOR,
|
|
6
|
+
/** @deprecated Use `BLUE_MAX_LIQUIDATION_INCENTIVE_FACTOR` or the raw `/blue/constants` subpath. */
|
|
7
|
+
MAX_LIQUIDATION_INCENTIVE_FACTOR, ORACLE_PRICE_SCALE, SECONDS_PER_YEAR, TransactionType as BlueTransactionType,
|
|
8
|
+
/** @deprecated Use `BlueTransactionType` or the raw `/blue/constants` subpath. */
|
|
9
|
+
TransactionType, } from "@morpho-org/blue-sdk";
|
|
10
|
+
export { CBP as MIDNIGHT_CBP,
|
|
11
|
+
/** @deprecated Use `MIDNIGHT_CBP` or the raw `/midnight/constants` subpath. */
|
|
12
|
+
CBP, COLLATERAL_PARAMS_TYPEHASH as MIDNIGHT_COLLATERAL_PARAMS_TYPEHASH,
|
|
13
|
+
/** @deprecated Use `MIDNIGHT_COLLATERAL_PARAMS_TYPEHASH` or the raw `/midnight/constants` subpath. */
|
|
14
|
+
COLLATERAL_PARAMS_TYPEHASH, DEFAULT_TICK_SPACING as MIDNIGHT_DEFAULT_TICK_SPACING,
|
|
15
|
+
/** @deprecated Use `MIDNIGHT_DEFAULT_TICK_SPACING` or the raw `/midnight/constants` subpath. */
|
|
16
|
+
DEFAULT_TICK_SPACING, EIP712_DOMAIN_TYPEHASH as MIDNIGHT_EIP712_DOMAIN_TYPEHASH,
|
|
17
|
+
/** @deprecated Use `MIDNIGHT_EIP712_DOMAIN_TYPEHASH` or the raw `/midnight/constants` subpath. */
|
|
18
|
+
EIP712_DOMAIN_TYPEHASH, MARKET_TYPEHASH as MIDNIGHT_MARKET_TYPEHASH,
|
|
19
|
+
/** @deprecated Use `MIDNIGHT_MARKET_TYPEHASH` or the raw `/midnight/constants` subpath. */
|
|
20
|
+
MARKET_TYPEHASH, MAX_COLLATERALS as MIDNIGHT_MAX_COLLATERALS,
|
|
21
|
+
/** @deprecated Use `MIDNIGHT_MAX_COLLATERALS` or the raw `/midnight/constants` subpath. */
|
|
22
|
+
MAX_COLLATERALS, MAX_COLLATERALS_PER_BORROWER as MIDNIGHT_MAX_COLLATERALS_PER_BORROWER,
|
|
23
|
+
/** @deprecated Use `MIDNIGHT_MAX_COLLATERALS_PER_BORROWER` or the raw `/midnight/constants` subpath. */
|
|
24
|
+
MAX_COLLATERALS_PER_BORROWER, MAX_CONTINUOUS_FEE as MIDNIGHT_MAX_CONTINUOUS_FEE,
|
|
25
|
+
/** @deprecated Use `MIDNIGHT_MAX_CONTINUOUS_FEE` or the raw `/midnight/constants` subpath. */
|
|
26
|
+
MAX_CONTINUOUS_FEE, MAX_OFFER_CAP as MIDNIGHT_MAX_OFFER_CAP, MAX_SETTLEMENT_FEES as MIDNIGHT_MAX_SETTLEMENT_FEES,
|
|
27
|
+
/** @deprecated Use `MIDNIGHT_MAX_SETTLEMENT_FEES` or the raw `/midnight/constants` subpath. */
|
|
28
|
+
MAX_SETTLEMENT_FEES, MAX_TICK as MIDNIGHT_MAX_TICK,
|
|
29
|
+
/** @deprecated Use `MIDNIGHT_MAX_TICK` or the raw `/midnight/constants` subpath. */
|
|
30
|
+
MAX_TICK, OFFER_TYPEHASH as MIDNIGHT_OFFER_TYPEHASH,
|
|
31
|
+
/** @deprecated Use `MIDNIGHT_OFFER_TYPEHASH` or the raw `/midnight/constants` subpath. */
|
|
32
|
+
OFFER_TYPEHASH, PRICE_ROUNDING_STEP as MIDNIGHT_PRICE_ROUNDING_STEP,
|
|
33
|
+
/** @deprecated Use `MIDNIGHT_PRICE_ROUNDING_STEP` or the raw `/midnight/constants` subpath. */
|
|
34
|
+
PRICE_ROUNDING_STEP, SETTLEMENT_FEE_BREAKPOINTS as MIDNIGHT_SETTLEMENT_FEE_BREAKPOINTS,
|
|
35
|
+
/** @deprecated Use `MIDNIGHT_SETTLEMENT_FEE_BREAKPOINTS` or the raw `/midnight/constants` subpath. */
|
|
36
|
+
SETTLEMENT_FEE_BREAKPOINTS, TIME_TO_MAX_LIF as MIDNIGHT_TIME_TO_MAX_LIF, } from "@morpho-org/midnight-sdk";
|
|
3
37
|
export { BLUE_API_BASE_URL, BLUE_API_GRAPHQL_URL, CDN_BASE_URL, ChainId, ChainUtils, DOCS_BASE_URL, MORPHO_DOMAIN, OPTIMIZERS_API_BASE_URL, OPTIMIZERS_BASE_URL, REWARDS_BASE_URL, ZERO_ADDRESS, } from "@morpho-org/morpho-ts";
|
|
4
|
-
export { APPROVE_ONLY_ONCE_TOKENS, DEFAULT_LLTV_BUFFER, DEFAULT_SUPPLY_TARGET_UTILIZATION, DEFAULT_WITHDRAWAL_TARGET_UTILIZATION, MAX_ABSOLUTE_SHARE_PRICE, MAX_SLIPPAGE_TOLERANCE, MAX_TOKEN_APPROVALS, } from "./helpers/constant.js";
|
|
38
|
+
export { APPROVE_ONLY_ONCE_TOKENS, DEFAULT_LLTV_BUFFER, DEFAULT_MAX_REALLOCATION_PENALTY, DEFAULT_SUPPLY_TARGET_UTILIZATION, DEFAULT_WITHDRAWAL_TARGET_UTILIZATION, MAX_ABSOLUTE_SHARE_PRICE, MAX_REALLOCATION_PENALTY, MAX_SLIPPAGE_TOLERANCE, MAX_TOKEN_APPROVALS, } from "./helpers/constant.js";
|