-
Notifications
You must be signed in to change notification settings - Fork 43
feat(morpho-sdk): support BluePublicAllocator reallocations #919
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
prd-carapulse
wants to merge
42
commits into
vault-v2-public-allocator-tib
from
hermes/public-allocator-v2-sdk
Open
Changes from all commits
Commits
Show all changes
42 commits
Select commit
Hold shift + click to select a range
1fa5ff2
feat(morpho-sdk): support Public Allocator V2 reallocations
prd-carapulse[bot] 77d49ac
docs(morpho-sdk): document allocator V2 overflow errors
prd-carapulse[bot] 77714ea
fix(morpho-sdk): validate allocator V2 source types
prd-carapulse[bot] bb5ce3e
fix: harden Public Allocator V2 support
Rubilmax 5ed0d27
refactor: align BluePublicAllocator naming
Rubilmax e75a1d8
feat: add Vault V2 shared liquidity support
Rubilmax 6122198
fix: simplify Vault V2 shared liquidity
Rubilmax 50a225e
fix: centralize market params ABI and preserve TIBs
Rubilmax f3cc8b3
feat: add Vault V2 liquidity loader
Rubilmax c2b6a5d
refactor: rename Vault V2 allocator options
Rubilmax 3abb520
feat: use REST data for Vault V2 liquidity
Rubilmax 6e52e15
fix: update BluePublicAllocator contract integration
Rubilmax a9433e9
fix: correct Vault V2 public allocator planning
Rubilmax fdce6c4
fix: harden Vault V2 reallocation planning
Rubilmax c2eddaa
fix: keep Vault V2 simulation state coherent
Rubilmax 6649e1c
refactor: split Vault V2 liquidity loader
Rubilmax bcbe0fc
refactor: normalize Vault V2 active adapters
Rubilmax 141f00a
refactor: simplify public allocator implementation
Rubilmax db7906a
refactor: accept iterable reallocation inputs
Rubilmax 4f1a196
feat: register Vault V2 public allocators by chain
Rubilmax 15112a8
refactor: clarify Vault V2 cap IDs
Rubilmax 6aa6be4
chore: drop unrelated PR changes
Rubilmax 25840c3
refactor: align Vault V2 Blue reallocation API
Rubilmax d625850
feat: configure Vault V2 withdrawal utilization
Rubilmax 93fbdea
test: use deployed BluePublicAllocator
Rubilmax 2bc9da8
refactor: align allocator reallocation names
Rubilmax fbe58b8
refactor: separate allocator reallocation versions
Rubilmax ead1aad
refactor: model vault v2 allocator penalties
Rubilmax c2e46d3
refactor: hydrate vault v2 market allocator config
Rubilmax 0c378fd
fix: harden Vault V2 allocator compatibility
Rubilmax a001917
fix: address Vault V2 allocator review findings
Rubilmax 82c9cee
Merge remote-tracking branch 'origin/vault-v2-public-allocator-tib' i…
Rubilmax 781059e
fix: handle Vault V2 allocator edge cases
Rubilmax 913f6ee
fix: address Vault V2 allocator review findings
Rubilmax f2119a6
fix: complete Vault V2 allocator review fixes
Rubilmax c7d9a57
fix: finish Vault V2 allocator review fixes
Rubilmax bb9bd15
fix(morpho-sdk): validate allocator penalty limits
Rubilmax 9037309
test(morpho-sdk): opt into allocator penalty
Rubilmax a8cd070
fix: clarify Vault V2 allocation IDs
Rubilmax fddb0d6
fix(morpho-sdk): validate reallocation snapshots
Rubilmax 3f0888c
fix: validate public allocator availability
Rubilmax a144423
fix(morpho-sdk): harden Vault V2 reallocation discovery
Rubilmax File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,20 @@ | ||
| --- | ||
| "@morpho-org/morpho-ts": minor | ||
| "@morpho-org/blue-sdk": minor | ||
|
Rubilmax marked this conversation as resolved.
|
||
| "@morpho-org/blue-sdk-viem": minor | ||
| "@morpho-org/liquidity-sdk-viem": patch | ||
| "@morpho-org/morpho-sdk": minor | ||
|
Rubilmax marked this conversation as resolved.
Rubilmax marked this conversation as resolved.
Rubilmax marked this conversation as resolved.
|
||
| "@morpho-org/wdk-protocol-lending-morpho-evm": minor | ||
| --- | ||
|
|
||
| Add canonical `vaultV1PublicAllocatorAbi` and `vaultV2BluePublicAllocatorAbi` exports plus per-chain `vaultV1PublicAllocator` and `vaultV2BluePublicAllocator` registry entries to `morpho-ts`, preserving `publicAllocatorAbi` and `publicAllocator` as deprecated V1 aliases. Move the shared `marketParamsAbi` source of truth there while preserving its `blue-sdk` re-export, and raise the `blue-sdk` peer range to the introducing `morpho-ts` minor. Add Vault V2 allocation-cap helpers and the updated `canPullFromIdle`/`canPullFromMarket`/WAD-scaled penalty config types to `blue-sdk`, accept iterable active-adapter, vault-allowlist, and reallocation-plan inputs while materializing them before repeated use, add chain-registry-backed deployless and fallback reads to `blue-sdk-viem`, and expose Vault V2 shared-liquidity discovery, planning, metrics, maximum-penalty filtering, and flat market/idle reallocations through `morpho-sdk` Blue flows. | ||
|
|
||
| V2 bundles now reject chains without a registered BluePublicAllocator before exposing requirements, pull the proportional loan-token penalty through GeneralAdapter1, grant the allocator an exact non-skippable allowance from Bundler3, pass the configured `uint64 penalty` in calldata, and keep the nonpayable allocator calls out of `tx.value`. `VaultV2BluePublicAllocatorConfig` is hydrated as a class with exact per-call penalty calculation, `VaultV2BlueMarketPublicAllocatorConfig` computes max-in capacity from its absolute cap, and plan totals stay local to their consumers. The planner mirrors contract execution order for penalties, source deallocation, first vault accrual (including zero-elapsed loss recognition), and target allocation; freezes the resulting relative-cap denominator across later calls for that vault; keeps every adapter coherent with one canonical simulated state per Morpho market; preserves supplied address casing while matching vaults and adapters case-insensitively; rejects incomplete allocator snapshots instead of silently reporting no liquidity; rejects non-positive operation amounts and same-market moves across adapters; and uses the latest timestamp in its complete input snapshot by default. | ||
|
|
||
| Use coherent protocol-specific names across the V1 and V2 reallocation APIs, including `VaultV1ReallocationData`, `VaultV2BlueReallocationData`, `computeVaultV1Reallocations`, `VaultV2BluePublicAllocatorOptions`, `VaultV2BluePublicAllocatorConfig`, its fetcher family, and Vault V2-prefixed Bundler actions. Add `MorphoBlue.getVaultV1ReallocationData`, `getVaultV1Reallocations`, `getVaultV2BlueReallocationData`, and `getVaultV2BlueReallocations`; preserve the published unversioned `getReallocationData` and `getReallocations` as deprecated V1 aliases. Both versioned planners reject reallocation snapshots from another chain. Keep V1's `defaultMaxWithdrawalUtilization` configurable, and add V2's scalar `maxWithdrawalUtilization` for its friendly phase while retaining the 100% adversarial fallback. | ||
|
|
||
| Compatibility note: this minor intentionally accepts four breaking changes. `VaultV2MorphoMarketV1Adapter.ids()` and `VaultV2MorphoMarketV1AdapterV2.ids()` now return the labeled readonly tuple `readonly [adapterCapId: Hash, collateralCapId: Hash, adapterMarketCapId: Hash]` instead of mutable `Hash[]`, while `VaultV2MorphoVaultV1Adapter.ids()` now returns `readonly [adapterCapId: Hash]`; `MorphoBlue.withdraw`, `borrow`, and `refinance` may now return `Transaction<ERC20ApprovalAction>` from `getRequirements()` for Vault V2 penalty funding; `BlueWithdrawAction`, `BlueBorrowAction`, `BlueSupplyCollateralBorrowAction`, and `BlueRefinanceAction` now require `reallocationPenaltyAssets`; and Vault V2 reallocation discovery now accepts only zero-penalty vaults by default. Runtime ordering for `ids()` is unchanged. Consumers should spread `ids()` when a mutable array is required, handle approval transactions in exhaustive requirement consumers, set `reallocationPenaltyAssets: 0n` in handwritten V1 or no-penalty action descriptors, and explicitly set `maxPenalty` when opting into a nonzero Vault V2 allocator penalty. Explicit and hand-built penalties remain supported up to WAD (100%), preserving the existing maximum. | ||
|
|
||
| Name allocation-cap helpers `adapterCapId`, `collateralCapId`, and `adapterMarketCapId`. Preserve the published `adapterId`, `collateralId`, and `marketParamsId` helpers as deprecated aliases. | ||
|
|
||
| Add an explicit `MorphoBorrowWithVaultV2ReallocationsOptions` WDK opt-in for Vault V2 reallocations and their possible approval requirement while preserving the legacy Vault V1-only `MorphoBorrowOptions` input and authorization-only requirement result type. Reallocation plans must use exactly one vault version per transaction. | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
76 changes: 76 additions & 0 deletions
76
packages/blue-sdk-viem/contracts/vault-v2/GetVaultV2BluePublicAllocatorConfig.sol
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,76 @@ | ||
| // SPDX-License-Identifier: UNLICENSED | ||
| pragma solidity ^0.8.0; | ||
|
|
||
| import {IBluePublicAllocator} from "./interfaces/IBluePublicAllocator.sol"; | ||
| import {IVaultV2} from "./interfaces/IVaultV2.sol"; | ||
|
|
||
| struct VaultV2BlueMarketPublicAllocatorRequest { | ||
| address adapter; | ||
| bytes32 adapterMarketCapId; | ||
| } | ||
|
|
||
| struct VaultV2BlueMarketPublicAllocatorResponse { | ||
| address adapter; | ||
| bytes32 adapterMarketCapId; | ||
| uint256 absoluteCap; | ||
| bool canPullFromMarket; | ||
| } | ||
|
|
||
| struct VaultV2AllocationResponse { | ||
| bytes32 id; | ||
| uint256 absoluteCap; | ||
| uint256 relativeCap; | ||
| uint256 allocation; | ||
| } | ||
|
|
||
| struct VaultV2BluePublicAllocatorResponse { | ||
| bool isAllocator; | ||
| bool canPullFromIdle; | ||
| uint64 penalty; | ||
| bool[] isActiveAdapters; | ||
| VaultV2BlueMarketPublicAllocatorResponse[] marketConfigs; | ||
| VaultV2AllocationResponse[] allocations; | ||
| } | ||
|
|
||
| contract GetVaultV2BluePublicAllocatorConfig { | ||
| function query( | ||
| IBluePublicAllocator allocator, | ||
| IVaultV2 vault, | ||
| address[] calldata adapters, | ||
| VaultV2BlueMarketPublicAllocatorRequest[] calldata marketRequests, | ||
| bytes32[] calldata allocationIds | ||
| ) external view returns (VaultV2BluePublicAllocatorResponse memory res) { | ||
| res.isAllocator = vault.isAllocator(address(allocator)); | ||
| (res.canPullFromIdle, res.penalty) = allocator.vaultData(address(vault)); | ||
|
|
||
| uint256 adaptersLength = adapters.length; | ||
| res.isActiveAdapters = new bool[](adaptersLength); | ||
| for (uint256 i; i < adaptersLength; ++i) { | ||
| res.isActiveAdapters[i] = allocator.isActiveAdapter(address(vault), adapters[i]); | ||
| } | ||
|
|
||
| uint256 marketRequestsLength = marketRequests.length; | ||
| res.marketConfigs = new VaultV2BlueMarketPublicAllocatorResponse[](marketRequestsLength); | ||
| for (uint256 i; i < marketRequestsLength; ++i) { | ||
| VaultV2BlueMarketPublicAllocatorRequest calldata request = marketRequests[i]; | ||
| res.marketConfigs[i] = VaultV2BlueMarketPublicAllocatorResponse({ | ||
| adapter: request.adapter, | ||
| adapterMarketCapId: request.adapterMarketCapId, | ||
| absoluteCap: allocator.absoluteCap(address(vault), request.adapterMarketCapId), | ||
| canPullFromMarket: allocator.canPullFromMarket(address(vault), request.adapterMarketCapId) | ||
| }); | ||
| } | ||
|
|
||
| uint256 allocationIdsLength = allocationIds.length; | ||
| res.allocations = new VaultV2AllocationResponse[](allocationIdsLength); | ||
| for (uint256 i; i < allocationIdsLength; ++i) { | ||
| bytes32 id = allocationIds[i]; | ||
| res.allocations[i] = VaultV2AllocationResponse({ | ||
| id: id, | ||
| absoluteCap: vault.absoluteCap(id), | ||
| relativeCap: vault.relativeCap(id), | ||
| allocation: vault.allocation(id) | ||
| }); | ||
| } | ||
| } | ||
| } |
10 changes: 10 additions & 0 deletions
10
packages/blue-sdk-viem/contracts/vault-v2/interfaces/IBluePublicAllocator.sol
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,10 @@ | ||
| // SPDX-License-Identifier: GPL-2.0-or-later | ||
| // Copyright (c) 2026 Morpho Association | ||
| pragma solidity ^0.8.0; | ||
|
|
||
| interface IBluePublicAllocator { | ||
| function absoluteCap(address vault, bytes32 id) external view returns (uint256); | ||
| function canPullFromMarket(address vault, bytes32 id) external view returns (bool); | ||
| function isActiveAdapter(address vault, address adapter) external view returns (bool); | ||
| function vaultData(address vault) external view returns (bool canPullFromIdle, uint64 penalty); | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
|
Rubilmax marked this conversation as resolved.
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.