@morpho-org/morpho-sdk 5.5.0 → 5.6.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 +8 -6
- package/lib/cjs/abis.d.ts +1 -1
- package/lib/cjs/abis.js +3 -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/requirements/getRequirementsApproval.js +2 -1
- package/lib/cjs/bundler/actions.d.ts +117 -0
- package/lib/cjs/bundler/actions.js +211 -4
- package/lib/cjs/bundler/types.d.ts +20 -0
- package/lib/cjs/constants.d.ts +1 -1
- package/lib/cjs/constants.js +3 -1
- package/lib/cjs/entities/blue/blue.d.ts +360 -71
- package/lib/cjs/entities/blue/blue.js +285 -52
- package/lib/cjs/entities/index.d.ts +2 -1
- package/lib/cjs/entities/index.js +6 -3
- 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 +1311 -0
- 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 +30 -14
- package/lib/cjs/helpers/validate.js +140 -27
- 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/utils.d.ts +2 -2
- package/lib/cjs/utils.js +6 -4
- package/lib/esm/abis.d.ts +1 -1
- package/lib/esm/abis.js +1 -1
- 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/requirements/getRequirementsApproval.js +2 -1
- package/lib/esm/bundler/actions.d.ts +117 -0
- package/lib/esm/bundler/actions.js +214 -7
- package/lib/esm/bundler/types.d.ts +20 -0
- package/lib/esm/constants.d.ts +1 -1
- package/lib/esm/constants.js +1 -1
- package/lib/esm/entities/blue/blue.d.ts +360 -71
- package/lib/esm/entities/blue/blue.js +288 -55
- package/lib/esm/entities/index.d.ts +2 -1
- package/lib/esm/entities/index.js +2 -1
- 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 +1307 -0
- 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 +30 -14
- package/lib/esm/helpers/validate.js +141 -30
- 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/utils.d.ts +2 -2
- package/lib/esm/utils.js +2 -2
- package/package.json +5 -5
|
@@ -650,6 +650,123 @@ export declare namespace BundlerAction {
|
|
|
650
650
|
* ```
|
|
651
651
|
*/
|
|
652
652
|
function publicAllocatorReallocateTo(chainId: number, vault: Address, fee: bigint, withdrawals: InputReallocation[], supplyMarketParams: InputMarketParams, skipRevert?: boolean): BundlerCall[];
|
|
653
|
+
/**
|
|
654
|
+
* Encodes a Vault V2 Blue Public Allocator market-to-market reallocation.
|
|
655
|
+
*
|
|
656
|
+
* @remarks Bundler3 must already hold the computed penalty assets. The
|
|
657
|
+
* high-level Blue builders add the corresponding GeneralAdapter1 transfer.
|
|
658
|
+
*
|
|
659
|
+
* @param chainId - Chain whose canonical Blue Public Allocator is called.
|
|
660
|
+
* @param vault - Vault whose liquidity is reallocated.
|
|
661
|
+
* @param deallocateAdapter - Vault V2 adapter supplying the source market.
|
|
662
|
+
* @param deallocateMarket - Source Morpho Blue market parameters.
|
|
663
|
+
* @param allocateAdapter - Vault V2 adapter supplying the target market.
|
|
664
|
+
* @param allocateMarket - Target Morpho Blue market parameters.
|
|
665
|
+
* @param assets - Assets to reallocate, bounded by `uint128` by the high-level action.
|
|
666
|
+
* @param penalty - Vault-configured proportional penalty, scaled by WAD.
|
|
667
|
+
* @param skipRevert - Whether Bundler3 should tolerate a revert.
|
|
668
|
+
* @returns A zero reset and exact approval when needed, then the allocator call.
|
|
669
|
+
* @throws {BundlerErrors.UnexpectedAction} when the chain has no Blue Public Allocator deployment.
|
|
670
|
+
* @throws {BundlerErrors.SkippableAllocatorPenalty} when `skipRevert` is true and a token approval is required.
|
|
671
|
+
* @example
|
|
672
|
+
* ```ts
|
|
673
|
+
* import { ChainId, type InputMarketParams } from "@morpho-org/blue-sdk";
|
|
674
|
+
* import {
|
|
675
|
+
* BundlerAction,
|
|
676
|
+
* type BundlerCall,
|
|
677
|
+
* } from "@morpho-org/morpho-sdk/bundler";
|
|
678
|
+
* import type { Address } from "viem";
|
|
679
|
+
*
|
|
680
|
+
* const keyrockUsdcVault =
|
|
681
|
+
* "0x04422053aDDbc9bB2759b248B574e3FCA76Bc145" satisfies Address;
|
|
682
|
+
* const sourceAdapterFixture =
|
|
683
|
+
* "0x70997970C51812dc3A010C7d01b50e0d17dc79C8" satisfies Address;
|
|
684
|
+
* const targetAdapterFixture =
|
|
685
|
+
* "0x3C44CdDdB6a900fa2b585dd299e03d12FA4293BC" satisfies Address;
|
|
686
|
+
* const usdc = "0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48" satisfies Address;
|
|
687
|
+
* const weth = "0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2" satisfies Address;
|
|
688
|
+
* const wbtc = "0x2260FAC5E5542a773Aa44fBCfeDf7C193bc2C599" satisfies Address;
|
|
689
|
+
* const ethUsdOracle = "0x5f4eC3Df9cbd43714FE2740f5E3616155c5b8419" satisfies Address;
|
|
690
|
+
* const adaptiveCurveIrm = "0x870aC11D48B15DB9a138Cf899d20F13F79Ba00BC" satisfies Address;
|
|
691
|
+
* const sourceMarket = {
|
|
692
|
+
* loanToken: usdc,
|
|
693
|
+
* collateralToken: weth,
|
|
694
|
+
* oracle: ethUsdOracle,
|
|
695
|
+
* irm: adaptiveCurveIrm,
|
|
696
|
+
* lltv: 860_000_000_000_000_000n,
|
|
697
|
+
* } satisfies InputMarketParams;
|
|
698
|
+
* const targetMarket = {
|
|
699
|
+
* ...sourceMarket,
|
|
700
|
+
* collateralToken: wbtc,
|
|
701
|
+
* } satisfies InputMarketParams;
|
|
702
|
+
*
|
|
703
|
+
* const calls: BundlerCall[] = BundlerAction.vaultV2BluePublicAllocatorReallocate(
|
|
704
|
+
* ChainId.EthMainnet,
|
|
705
|
+
* keyrockUsdcVault,
|
|
706
|
+
* sourceAdapterFixture,
|
|
707
|
+
* sourceMarket,
|
|
708
|
+
* targetAdapterFixture,
|
|
709
|
+
* targetMarket,
|
|
710
|
+
* 1_000_000n,
|
|
711
|
+
* 1_000_000_000_000_000n,
|
|
712
|
+
* );
|
|
713
|
+
* // Bundler3 resets and approves 1_000 USDC units, then calls `reallocate` with zero native value.
|
|
714
|
+
* ```
|
|
715
|
+
*/
|
|
716
|
+
function vaultV2BluePublicAllocatorReallocate(chainId: number, vault: Address, deallocateAdapter: Address, deallocateMarket: InputMarketParams, allocateAdapter: Address, allocateMarket: InputMarketParams, assets: bigint, penalty: bigint, skipRevert?: boolean): BundlerCall[];
|
|
717
|
+
/**
|
|
718
|
+
* Encodes a Vault V2 Blue Public Allocator allocation from vault idle liquidity.
|
|
719
|
+
*
|
|
720
|
+
* @remarks Bundler3 must already hold the computed penalty assets. The
|
|
721
|
+
* high-level Blue builders add the corresponding GeneralAdapter1 transfer.
|
|
722
|
+
*
|
|
723
|
+
* @param chainId - Chain whose canonical Blue Public Allocator is called.
|
|
724
|
+
* @param vault - Vault whose idle liquidity is allocated.
|
|
725
|
+
* @param adapter - Vault V2 adapter supplying the target market.
|
|
726
|
+
* @param market - Target Morpho Blue market parameters.
|
|
727
|
+
* @param assets - Assets to allocate, bounded by `uint128` by the high-level action.
|
|
728
|
+
* @param penalty - Vault-configured proportional penalty, scaled by WAD.
|
|
729
|
+
* @param skipRevert - Whether Bundler3 should tolerate a revert.
|
|
730
|
+
* @returns A zero reset and exact approval when needed, then the allocator call.
|
|
731
|
+
* @throws {BundlerErrors.UnexpectedAction} when the chain has no Blue Public Allocator deployment.
|
|
732
|
+
* @throws {BundlerErrors.SkippableAllocatorPenalty} when `skipRevert` is true and a token approval is required.
|
|
733
|
+
* @example
|
|
734
|
+
* ```ts
|
|
735
|
+
* import { ChainId, type InputMarketParams } from "@morpho-org/blue-sdk";
|
|
736
|
+
* import {
|
|
737
|
+
* BundlerAction,
|
|
738
|
+
* type BundlerCall,
|
|
739
|
+
* } from "@morpho-org/morpho-sdk/bundler";
|
|
740
|
+
* import type { Address } from "viem";
|
|
741
|
+
*
|
|
742
|
+
* const keyrockUsdcVault =
|
|
743
|
+
* "0x04422053aDDbc9bB2759b248B574e3FCA76Bc145" satisfies Address;
|
|
744
|
+
* const targetAdapterFixture =
|
|
745
|
+
* "0x3C44CdDdB6a900fa2b585dd299e03d12FA4293BC" satisfies Address;
|
|
746
|
+
* const usdc = "0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48" satisfies Address;
|
|
747
|
+
* const weth = "0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2" satisfies Address;
|
|
748
|
+
* const ethUsdOracle = "0x5f4eC3Df9cbd43714FE2740f5E3616155c5b8419" satisfies Address;
|
|
749
|
+
* const adaptiveCurveIrm = "0x870aC11D48B15DB9a138Cf899d20F13F79Ba00BC" satisfies Address;
|
|
750
|
+
* const targetMarket = {
|
|
751
|
+
* loanToken: usdc,
|
|
752
|
+
* collateralToken: weth,
|
|
753
|
+
* oracle: ethUsdOracle,
|
|
754
|
+
* irm: adaptiveCurveIrm,
|
|
755
|
+
* lltv: 860_000_000_000_000_000n,
|
|
756
|
+
* } satisfies InputMarketParams;
|
|
757
|
+
*
|
|
758
|
+
* const calls: BundlerCall[] = BundlerAction.vaultV2BluePublicAllocatorAllocateFromIdle(
|
|
759
|
+
* ChainId.EthMainnet,
|
|
760
|
+
* keyrockUsdcVault,
|
|
761
|
+
* targetAdapterFixture,
|
|
762
|
+
* targetMarket,
|
|
763
|
+
* 1_000_000n,
|
|
764
|
+
* 1_000_000_000_000_000n,
|
|
765
|
+
* );
|
|
766
|
+
* // Bundler3 resets and approves 1_000 USDC units, then calls `allocateFromIdle` with zero native value.
|
|
767
|
+
* ```
|
|
768
|
+
*/
|
|
769
|
+
function vaultV2BluePublicAllocatorAllocateFromIdle(chainId: number, vault: Address, adapter: Address, market: InputMarketParams, assets: bigint, penalty: bigint, skipRevert?: boolean): BundlerCall[];
|
|
653
770
|
/**
|
|
654
771
|
* Encodes a GeneralAdapter1 native-token wrap call.
|
|
655
772
|
*
|
|
@@ -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;
|
|
@@ -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
|
}
|
|
@@ -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,207 @@ 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, type InputMarketParams } from "@morpho-org/blue-sdk";
|
|
1144
|
+
* import {
|
|
1145
|
+
* BundlerAction,
|
|
1146
|
+
* type BundlerCall,
|
|
1147
|
+
* } from "@morpho-org/morpho-sdk/bundler";
|
|
1148
|
+
* import type { Address } from "viem";
|
|
1149
|
+
*
|
|
1150
|
+
* const keyrockUsdcVault =
|
|
1151
|
+
* "0x04422053aDDbc9bB2759b248B574e3FCA76Bc145" satisfies Address;
|
|
1152
|
+
* const sourceAdapterFixture =
|
|
1153
|
+
* "0x70997970C51812dc3A010C7d01b50e0d17dc79C8" satisfies Address;
|
|
1154
|
+
* const targetAdapterFixture =
|
|
1155
|
+
* "0x3C44CdDdB6a900fa2b585dd299e03d12FA4293BC" satisfies Address;
|
|
1156
|
+
* const usdc = "0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48" satisfies Address;
|
|
1157
|
+
* const weth = "0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2" satisfies Address;
|
|
1158
|
+
* const wbtc = "0x2260FAC5E5542a773Aa44fBCfeDf7C193bc2C599" satisfies Address;
|
|
1159
|
+
* const ethUsdOracle = "0x5f4eC3Df9cbd43714FE2740f5E3616155c5b8419" satisfies Address;
|
|
1160
|
+
* const adaptiveCurveIrm = "0x870aC11D48B15DB9a138Cf899d20F13F79Ba00BC" satisfies Address;
|
|
1161
|
+
* const sourceMarket = {
|
|
1162
|
+
* loanToken: usdc,
|
|
1163
|
+
* collateralToken: weth,
|
|
1164
|
+
* oracle: ethUsdOracle,
|
|
1165
|
+
* irm: adaptiveCurveIrm,
|
|
1166
|
+
* lltv: 860_000_000_000_000_000n,
|
|
1167
|
+
* } satisfies InputMarketParams;
|
|
1168
|
+
* const targetMarket = {
|
|
1169
|
+
* ...sourceMarket,
|
|
1170
|
+
* collateralToken: wbtc,
|
|
1171
|
+
* } satisfies InputMarketParams;
|
|
1172
|
+
*
|
|
1173
|
+
* const calls: BundlerCall[] = BundlerAction.vaultV2BluePublicAllocatorReallocate(
|
|
1174
|
+
* ChainId.EthMainnet,
|
|
1175
|
+
* keyrockUsdcVault,
|
|
1176
|
+
* sourceAdapterFixture,
|
|
1177
|
+
* sourceMarket,
|
|
1178
|
+
* targetAdapterFixture,
|
|
1179
|
+
* targetMarket,
|
|
1180
|
+
* 1_000_000n,
|
|
1181
|
+
* 1_000_000_000_000_000n,
|
|
1182
|
+
* );
|
|
1183
|
+
* // Bundler3 resets and approves 1_000 USDC units, then calls `reallocate` with zero native value.
|
|
1184
|
+
* ```
|
|
1185
|
+
*/
|
|
1186
|
+
// biome-ignore lint/complexity/useMaxParams: mirrors the protocol call
|
|
1187
|
+
function vaultV2BluePublicAllocatorReallocate(chainId, vault, deallocateAdapter, deallocateMarket, allocateAdapter, allocateMarket, assets, penalty, skipRevert = false) {
|
|
1188
|
+
const { vaultV2BluePublicAllocator: allocator } = getChainAddresses(chainId);
|
|
1189
|
+
if (allocator == null) {
|
|
1190
|
+
throw new BundlerErrors.UnexpectedAction("vaultV2BluePublicAllocatorReallocate", chainId);
|
|
1191
|
+
}
|
|
1192
|
+
const calls = [];
|
|
1193
|
+
const penaltyAssets = VaultV2BluePublicAllocatorConfigUtils.getPenaltyAssets({ penalty }, assets);
|
|
1194
|
+
if (skipRevert && penaltyAssets > 0n) {
|
|
1195
|
+
throw new BundlerErrors.SkippableAllocatorPenalty(penaltyAssets);
|
|
1196
|
+
}
|
|
1197
|
+
if (penaltyAssets > 0n) {
|
|
1198
|
+
for (const amount of [0n, penaltyAssets])
|
|
1199
|
+
calls.push({
|
|
1200
|
+
to: allocateMarket.loanToken,
|
|
1201
|
+
data: encodeFunctionData({
|
|
1202
|
+
abi: erc20Abi,
|
|
1203
|
+
functionName: "approve",
|
|
1204
|
+
args: [allocator, amount],
|
|
1205
|
+
}),
|
|
1206
|
+
value: 0n,
|
|
1207
|
+
skipRevert,
|
|
1208
|
+
callbackHash: zeroHash,
|
|
1209
|
+
});
|
|
1210
|
+
}
|
|
1211
|
+
calls.push({
|
|
1212
|
+
to: allocator,
|
|
1213
|
+
data: encodeFunctionData({
|
|
1214
|
+
abi: vaultV2BluePublicAllocatorAbi,
|
|
1215
|
+
functionName: "reallocate",
|
|
1216
|
+
args: [
|
|
1217
|
+
vault,
|
|
1218
|
+
deallocateAdapter,
|
|
1219
|
+
deallocateMarket,
|
|
1220
|
+
allocateAdapter,
|
|
1221
|
+
allocateMarket,
|
|
1222
|
+
assets,
|
|
1223
|
+
penalty,
|
|
1224
|
+
],
|
|
1225
|
+
}),
|
|
1226
|
+
value: 0n,
|
|
1227
|
+
skipRevert,
|
|
1228
|
+
callbackHash: zeroHash,
|
|
1229
|
+
});
|
|
1230
|
+
return calls;
|
|
1231
|
+
}
|
|
1232
|
+
BundlerAction.vaultV2BluePublicAllocatorReallocate = vaultV2BluePublicAllocatorReallocate;
|
|
1233
|
+
/**
|
|
1234
|
+
* Encodes a Vault V2 Blue Public Allocator allocation from vault idle liquidity.
|
|
1235
|
+
*
|
|
1236
|
+
* @remarks Bundler3 must already hold the computed penalty assets. The
|
|
1237
|
+
* high-level Blue builders add the corresponding GeneralAdapter1 transfer.
|
|
1238
|
+
*
|
|
1239
|
+
* @param chainId - Chain whose canonical Blue Public Allocator is called.
|
|
1240
|
+
* @param vault - Vault whose idle liquidity is allocated.
|
|
1241
|
+
* @param adapter - Vault V2 adapter supplying the target market.
|
|
1242
|
+
* @param market - Target Morpho Blue market parameters.
|
|
1243
|
+
* @param assets - Assets to allocate, bounded by `uint128` by the high-level action.
|
|
1244
|
+
* @param penalty - Vault-configured proportional penalty, scaled by WAD.
|
|
1245
|
+
* @param skipRevert - Whether Bundler3 should tolerate a revert.
|
|
1246
|
+
* @returns A zero reset and exact approval when needed, then the allocator call.
|
|
1247
|
+
* @throws {BundlerErrors.UnexpectedAction} when the chain has no Blue Public Allocator deployment.
|
|
1248
|
+
* @throws {BundlerErrors.SkippableAllocatorPenalty} when `skipRevert` is true and a token approval is required.
|
|
1249
|
+
* @example
|
|
1250
|
+
* ```ts
|
|
1251
|
+
* import { ChainId, type InputMarketParams } from "@morpho-org/blue-sdk";
|
|
1252
|
+
* import {
|
|
1253
|
+
* BundlerAction,
|
|
1254
|
+
* type BundlerCall,
|
|
1255
|
+
* } from "@morpho-org/morpho-sdk/bundler";
|
|
1256
|
+
* import type { Address } from "viem";
|
|
1257
|
+
*
|
|
1258
|
+
* const keyrockUsdcVault =
|
|
1259
|
+
* "0x04422053aDDbc9bB2759b248B574e3FCA76Bc145" satisfies Address;
|
|
1260
|
+
* const targetAdapterFixture =
|
|
1261
|
+
* "0x3C44CdDdB6a900fa2b585dd299e03d12FA4293BC" satisfies Address;
|
|
1262
|
+
* const usdc = "0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48" satisfies Address;
|
|
1263
|
+
* const weth = "0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2" satisfies Address;
|
|
1264
|
+
* const ethUsdOracle = "0x5f4eC3Df9cbd43714FE2740f5E3616155c5b8419" satisfies Address;
|
|
1265
|
+
* const adaptiveCurveIrm = "0x870aC11D48B15DB9a138Cf899d20F13F79Ba00BC" satisfies Address;
|
|
1266
|
+
* const targetMarket = {
|
|
1267
|
+
* loanToken: usdc,
|
|
1268
|
+
* collateralToken: weth,
|
|
1269
|
+
* oracle: ethUsdOracle,
|
|
1270
|
+
* irm: adaptiveCurveIrm,
|
|
1271
|
+
* lltv: 860_000_000_000_000_000n,
|
|
1272
|
+
* } satisfies InputMarketParams;
|
|
1273
|
+
*
|
|
1274
|
+
* const calls: BundlerCall[] = BundlerAction.vaultV2BluePublicAllocatorAllocateFromIdle(
|
|
1275
|
+
* ChainId.EthMainnet,
|
|
1276
|
+
* keyrockUsdcVault,
|
|
1277
|
+
* targetAdapterFixture,
|
|
1278
|
+
* targetMarket,
|
|
1279
|
+
* 1_000_000n,
|
|
1280
|
+
* 1_000_000_000_000_000n,
|
|
1281
|
+
* );
|
|
1282
|
+
* // Bundler3 resets and approves 1_000 USDC units, then calls `allocateFromIdle` with zero native value.
|
|
1283
|
+
* ```
|
|
1284
|
+
*/
|
|
1285
|
+
// biome-ignore lint/complexity/useMaxParams: mirrors the protocol call
|
|
1286
|
+
function vaultV2BluePublicAllocatorAllocateFromIdle(chainId, vault, adapter, market, assets, penalty, skipRevert = false) {
|
|
1287
|
+
const { vaultV2BluePublicAllocator: allocator } = getChainAddresses(chainId);
|
|
1288
|
+
if (allocator == null) {
|
|
1289
|
+
throw new BundlerErrors.UnexpectedAction("vaultV2BluePublicAllocatorAllocateFromIdle", chainId);
|
|
1290
|
+
}
|
|
1291
|
+
const calls = [];
|
|
1292
|
+
const penaltyAssets = VaultV2BluePublicAllocatorConfigUtils.getPenaltyAssets({ penalty }, assets);
|
|
1293
|
+
if (skipRevert && penaltyAssets > 0n) {
|
|
1294
|
+
throw new BundlerErrors.SkippableAllocatorPenalty(penaltyAssets);
|
|
1295
|
+
}
|
|
1296
|
+
if (penaltyAssets > 0n) {
|
|
1297
|
+
for (const amount of [0n, penaltyAssets])
|
|
1298
|
+
calls.push({
|
|
1299
|
+
to: market.loanToken,
|
|
1300
|
+
data: encodeFunctionData({
|
|
1301
|
+
abi: erc20Abi,
|
|
1302
|
+
functionName: "approve",
|
|
1303
|
+
args: [allocator, amount],
|
|
1304
|
+
}),
|
|
1305
|
+
value: 0n,
|
|
1306
|
+
skipRevert,
|
|
1307
|
+
callbackHash: zeroHash,
|
|
1308
|
+
});
|
|
1309
|
+
}
|
|
1310
|
+
calls.push({
|
|
1311
|
+
to: allocator,
|
|
1312
|
+
data: encodeFunctionData({
|
|
1313
|
+
abi: vaultV2BluePublicAllocatorAbi,
|
|
1314
|
+
functionName: "allocateFromIdle",
|
|
1315
|
+
args: [vault, adapter, market, assets, penalty],
|
|
1316
|
+
}),
|
|
1317
|
+
value: 0n,
|
|
1318
|
+
skipRevert,
|
|
1319
|
+
callbackHash: zeroHash,
|
|
1320
|
+
});
|
|
1321
|
+
return calls;
|
|
1322
|
+
}
|
|
1323
|
+
BundlerAction.vaultV2BluePublicAllocatorAllocateFromIdle = vaultV2BluePublicAllocatorAllocateFromIdle;
|
|
1117
1324
|
/**
|
|
1118
1325
|
* Encodes a GeneralAdapter1 native-token wrap call.
|
|
1119
1326
|
*
|
|
@@ -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,4 @@
|
|
|
1
1
|
export { DEFAULT_SLIPPAGE_TOLERANCE, EIP_712_FIELDS, isMarketId, LIQUIDATION_CURSOR, MAX_LIQUIDATION_INCENTIVE_FACTOR, ORACLE_PRICE_SCALE, SECONDS_PER_YEAR, TransactionType, } from "@morpho-org/blue-sdk";
|
|
2
2
|
export { CBP, COLLATERAL_PARAMS_TYPEHASH, DEFAULT_TICK_SPACING, EIP712_DOMAIN_TYPEHASH, MARKET_TYPEHASH, MAX_COLLATERALS, MAX_COLLATERALS_PER_BORROWER, MAX_CONTINUOUS_FEE, MAX_SETTLEMENT_FEES, MAX_TICK, OFFER_TYPEHASH, PRICE_ROUNDING_STEP, SETTLEMENT_FEE_BREAKPOINTS, } from "@morpho-org/midnight-sdk";
|
|
3
3
|
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";
|
|
4
|
+
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,4 @@
|
|
|
1
1
|
export { DEFAULT_SLIPPAGE_TOLERANCE, EIP_712_FIELDS, isMarketId, LIQUIDATION_CURSOR, MAX_LIQUIDATION_INCENTIVE_FACTOR, ORACLE_PRICE_SCALE, SECONDS_PER_YEAR, TransactionType, } from "@morpho-org/blue-sdk";
|
|
2
2
|
export { CBP, COLLATERAL_PARAMS_TYPEHASH, DEFAULT_TICK_SPACING, EIP712_DOMAIN_TYPEHASH, MARKET_TYPEHASH, MAX_COLLATERALS, MAX_COLLATERALS_PER_BORROWER, MAX_CONTINUOUS_FEE, MAX_SETTLEMENT_FEES, MAX_TICK, OFFER_TYPEHASH, PRICE_ROUNDING_STEP, SETTLEMENT_FEE_BREAKPOINTS, } from "@morpho-org/midnight-sdk";
|
|
3
3
|
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";
|
|
4
|
+
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";
|