Skip to content
Open
Show file tree
Hide file tree
Changes from 22 commits
Commits
Show all changes
37 commits
Select commit Hold shift + click to select a range
1fa5ff2
feat(morpho-sdk): support Public Allocator V2 reallocations
prd-carapulse[bot] Aug 6, 2026
77d49ac
docs(morpho-sdk): document allocator V2 overflow errors
prd-carapulse[bot] Aug 6, 2026
77714ea
fix(morpho-sdk): validate allocator V2 source types
prd-carapulse[bot] Aug 6, 2026
bb5ce3e
fix: harden Public Allocator V2 support
Rubilmax Aug 6, 2026
5ed0d27
refactor: align BluePublicAllocator naming
Rubilmax Aug 6, 2026
e75a1d8
feat: add Vault V2 shared liquidity support
Rubilmax Aug 6, 2026
6122198
fix: simplify Vault V2 shared liquidity
Rubilmax Aug 7, 2026
50a225e
fix: centralize market params ABI and preserve TIBs
Rubilmax Aug 7, 2026
f3cc8b3
feat: add Vault V2 liquidity loader
Rubilmax Aug 7, 2026
c2b6a5d
refactor: rename Vault V2 allocator options
Rubilmax Aug 7, 2026
3abb520
feat: use REST data for Vault V2 liquidity
Rubilmax Aug 11, 2026
6e52e15
fix: update BluePublicAllocator contract integration
Rubilmax Aug 14, 2026
a9433e9
fix: correct Vault V2 public allocator planning
Rubilmax Aug 14, 2026
fdce6c4
fix: harden Vault V2 reallocation planning
Rubilmax Aug 14, 2026
c2eddaa
fix: keep Vault V2 simulation state coherent
Rubilmax Aug 14, 2026
6649e1c
refactor: split Vault V2 liquidity loader
Rubilmax Aug 17, 2026
bcbe0fc
refactor: normalize Vault V2 active adapters
Rubilmax Aug 17, 2026
141f00a
refactor: simplify public allocator implementation
Rubilmax Aug 17, 2026
db7906a
refactor: accept iterable reallocation inputs
Rubilmax Aug 17, 2026
4f1a196
feat: register Vault V2 public allocators by chain
Rubilmax Aug 17, 2026
15112a8
refactor: clarify Vault V2 cap IDs
Rubilmax Aug 18, 2026
6aa6be4
chore: drop unrelated PR changes
Rubilmax Aug 18, 2026
25840c3
refactor: align Vault V2 Blue reallocation API
Rubilmax Aug 18, 2026
d625850
feat: configure Vault V2 withdrawal utilization
Rubilmax Aug 18, 2026
93fbdea
test: use deployed BluePublicAllocator
Rubilmax Aug 19, 2026
2bc9da8
refactor: align allocator reallocation names
Rubilmax Aug 19, 2026
fbe58b8
refactor: separate allocator reallocation versions
Rubilmax Aug 19, 2026
ead1aad
refactor: model vault v2 allocator penalties
Rubilmax Aug 19, 2026
c2e46d3
refactor: hydrate vault v2 market allocator config
Rubilmax Aug 19, 2026
0c378fd
fix: harden Vault V2 allocator compatibility
Rubilmax Aug 19, 2026
a001917
fix: address Vault V2 allocator review findings
Rubilmax Aug 19, 2026
82c9cee
Merge remote-tracking branch 'origin/vault-v2-public-allocator-tib' i…
Rubilmax Aug 19, 2026
781059e
fix: handle Vault V2 allocator edge cases
Rubilmax Aug 19, 2026
913f6ee
fix: address Vault V2 allocator review findings
Rubilmax Aug 20, 2026
f2119a6
fix: complete Vault V2 allocator review fixes
Rubilmax Aug 20, 2026
c7d9a57
fix: finish Vault V2 allocator review fixes
Rubilmax Aug 21, 2026
bb9bd15
fix(morpho-sdk): validate allocator penalty limits
Rubilmax Aug 21, 2026
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions .changeset/brave-vaults-reallocate.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
---
"@morpho-org/morpho-ts": minor
"@morpho-org/blue-sdk": minor
Comment thread
Rubilmax marked this conversation as resolved.
"@morpho-org/blue-sdk-viem": minor
"@morpho-org/morpho-sdk": minor
Comment thread
Rubilmax marked this conversation as resolved.
Comment thread
Rubilmax marked this conversation as resolved.
Comment thread
Rubilmax marked this conversation as resolved.
"@morpho-org/wdk-protocol-lending-morpho-evm": minor
---

Add the canonical `vaultV2BluePublicAllocatorAbi` and per-chain `bluePublicAllocator` deployments to `morpho-ts`, 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 normalizing 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 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`. 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; 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 versioned names across the V1 and V2 reallocation APIs, including `VaultV1ReallocationData`, `VaultV2ReallocationData`, `computeVaultV1Reallocations`, `computeVaultV2Reallocations`, `VaultV2BluePublicAllocatorOptions`, and Vault V2-prefixed Bundler actions. Preserve the published V1 names as deprecated aliases.

Compatibility note: `VaultV2MorphoMarketV1AdapterV2.ids()` now declares its existing three-element result as `readonly [Hash, Hash, Hash]`. The runtime values and ordering are unchanged, and derived allocation identifiers are immutable descriptors. We intentionally accept this TypeScript assignability tightening in the minor release; callers that explicitly require a mutable `Hash[]` can copy the tuple with `[...adapter.ids(params)]`.

Name allocation-cap helpers `adapterCapId`, `collateralCapId`, and `adapterMarketCapId`. Preserve the published `adapterId`, `collateralId`, and `marketParamsId` helpers as deprecated aliases.

Add an explicit `MorphoBorrowWithV2ReallocationsOptions` WDK opt-in for the combined V1/V2 reallocation union and its possible approval requirement while preserving the legacy `MorphoBorrowOptions` input and authorization-only requirement result type.
1 change: 1 addition & 0 deletions AGENTS.md
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,7 @@ A scannable list of patterns reviewers reject. Most are review-only today (per t
- `@throws` for each typed error class an integrator may pattern-match on.
- One `@example` block with realistic working code: imports, client setup, the call, expected return.
- **AI-legibility is first-class.** Identical signatures across V1/V2 where protocols overlap. Discriminated unions with obvious `type` tags. Deterministic outputs verifiable byte-for-byte. Error messages read like instructions an agent can act on without guessing. Protocol-specific terms (`LLTV buffer`, `wNative`, `GeneralAdapter1`, `bundler3`, `PublicAllocator`, `MetaMorpho`, `Permit2`, `WAD`) live in the [`packages/morpho-sdk/AGENTS.md`](./packages/morpho-sdk/AGENTS.md) glossary.
- **Implemented TIBs are historical records.** Do not rewrite a TIB already present on the target branch to follow later code, symbol, or path changes. Keep the TIB's implementation-time names and examples intact. A changed decision gets a new superseding TIB; an operational clarification gets a dated addendum. Only a TIB introduced for the current implementation may be kept in sync with that implementation before it lands.
Comment thread
Rubilmax marked this conversation as resolved.
Comment thread
Rubilmax marked this conversation as resolved.
Comment thread
Rubilmax marked this conversation as resolved.
- **TypeDoc-generated reference** published per release.
- **Feedback loop:** if the same question is asked twice, the answer goes into the relevant `AGENTS.md` or JSDoc on the export it concerns.

Expand Down
918 changes: 402 additions & 516 deletions docs/tibs/TIB-2026-07-29-vault-v2-public-allocator-shared-liquidity.md

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions packages/blue-sdk-viem/AGENTS.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
- Normalize unsafe user addresses with `safeGetAddress`, not lowercasing alone.
- Typed-data helpers return `TypedDataDefinition`, e.g. `getPermitTypedData(...)`.
- Re-export ABI literals from `@morpho-org/morpho-ts` when they exist there; keep local ABI declarations only for Blue-specific viem surfaces absent from `morpho-ts`.
- Vault V2 BluePublicAllocator fetchers resolve the chain's single allocator from `bluePublicAllocator` in the address registry, using `parameters.chainId` or the client chain id. The hydrated-vault batch fetch derives supported adapter/market/allocation ids, returns active adapters as a set separate from market configs, defaults to one deployless read, and falls back to direct reads.

## Continuous Improvement

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
// SPDX-License-Identifier: UNLICENSED
pragma solidity ^0.8.0;

import {IBluePublicAllocator} from "./interfaces/IBluePublicAllocator.sol";
import {IVaultV2} from "./interfaces/IVaultV2.sol";

struct VaultV2MarketPublicAllocatorRequest {
address adapter;
bytes32 adapterMarketCapId;
}

struct VaultV2MarketPublicAllocatorResponse {
address adapter;
bytes32 adapterMarketCapId;
uint256 absoluteCap;
bool canPullFromMarket;
}

struct VaultV2AllocationResponse {
bytes32 id;
uint256 absoluteCap;
uint256 relativeCap;
uint256 allocation;
}

struct VaultV2PublicAllocatorResponse {
bool canPullFromIdle;
uint64 penalty;
bool[] isActiveAdapters;
VaultV2MarketPublicAllocatorResponse[] marketConfigs;
VaultV2AllocationResponse[] allocations;
}

contract GetVaultV2PublicAllocatorConfig {
function query(
IBluePublicAllocator allocator,
IVaultV2 vault,
address[] calldata adapters,
VaultV2MarketPublicAllocatorRequest[] calldata marketRequests,
bytes32[] calldata allocationIds
) external view returns (VaultV2PublicAllocatorResponse memory res) {
(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 VaultV2MarketPublicAllocatorResponse[](marketRequestsLength);
for (uint256 i; i < marketRequestsLength; ++i) {
VaultV2MarketPublicAllocatorRequest calldata request = marketRequests[i];
res.marketConfigs[i] = VaultV2MarketPublicAllocatorResponse({
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)
});
}
}
}
Comment thread
Rubilmax marked this conversation as resolved.
Outdated
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
// SPDX-License-Identifier: UNLICENSED
pragma solidity ^0.8.0;

struct VaultData {
bool canPullFromIdle;
uint64 penalty;
}

/// @dev Stateful EVM fixture for exercising BluePublicAllocator read paths on an Anvil fork.
contract BluePublicAllocatorReadFixture {
mapping(address vault => mapping(bytes32 id => uint256)) public absoluteCap;
mapping(address vault => mapping(bytes32 id => bool)) public canPullFromMarket;
mapping(address vault => mapping(address adapter => bool)) public isActiveAdapter;
mapping(address vault => VaultData) public vaultData;

function setAbsoluteCap(address vault, bytes32 id, uint256 value) external {
absoluteCap[vault][id] = value;
}

function setCanPullFromMarket(address vault, bytes32 id, bool value) external {
canPullFromMarket[vault][id] = value;
}

function setIsActiveAdapter(address vault, address adapter, bool value) external {
isActiveAdapter[vault][adapter] = value;
}

function setVaultData(address vault, bool canPullFromIdle, uint64 penalty) external {
vaultData[vault] = VaultData(canPullFromIdle, penalty);
}
}
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);
}
4 changes: 2 additions & 2 deletions packages/blue-sdk-viem/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,8 @@
"build:esm": "tsc --build tsconfig.build.esm.json && echo '{\"type\":\"module\"}' > lib/esm/package.json"
},
"peerDependencies": {
"@morpho-org/blue-sdk": "^6.4.0",
"@morpho-org/morpho-ts": "^2.7.0",
"@morpho-org/blue-sdk": "^6.5.0",
"@morpho-org/morpho-ts": "^2.9.0",
"viem": "^2.0.0"
},
"devDependencies": {
Expand Down
1 change: 1 addition & 0 deletions packages/blue-sdk-viem/src/abis.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ export {
vaultV1AdapterAbi,
vaultV1AdapterFactoryAbi,
vaultV2Abi,
vaultV2BluePublicAllocatorAbi,
vaultV2FactoryAbi,
whitelistControllerAggregatorV2Abi,
wrappedBackedTokenAbi,
Expand Down
10 changes: 6 additions & 4 deletions packages/blue-sdk-viem/src/fetch/vault-v2/VaultV2.ts
Comment thread
Rubilmax marked this conversation as resolved.
Original file line number Diff line number Diff line change
Expand Up @@ -325,14 +325,16 @@ export async function fetchVaultV2(
let liquidityAdapterIds: Hash[] | undefined;
if (hasMorphoVaultV1LiquidityAdapter)
liquidityAdapterIds = [
VaultV2MorphoVaultV1Adapter.adapterId(liquidityAdapter),
VaultV2MorphoVaultV1Adapter.adapterCapId(liquidityAdapter),
];
if (hasMorphoMarketV1AdapterV2LiquidityAdapter) {
const marketParams = MarketParams.fromHex(liquidityData);
liquidityAdapterIds = [
VaultV2MorphoMarketV1AdapterV2.adapterId(liquidityAdapter),
VaultV2MorphoMarketV1AdapterV2.collateralId(marketParams.collateralToken),
VaultV2MorphoMarketV1AdapterV2.marketParamsId(
VaultV2MorphoMarketV1AdapterV2.adapterCapId(liquidityAdapter),
VaultV2MorphoMarketV1AdapterV2.collateralCapId(
marketParams.collateralToken,
),
VaultV2MorphoMarketV1AdapterV2.adapterMarketCapId(
liquidityAdapter,
marketParams,
),
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,111 @@
import {
AccrualVaultV2MorphoMarketV1AdapterV2,
ChainId,
getChainAddress,
} from "@morpho-org/blue-sdk";
import { assert, describe, expect } from "vitest";
import {
abi as fixtureAbi,
code as fixtureCode,
} from "../../../test/fixtures/BluePublicAllocatorReadFixture.js";
import { vaultV2Test } from "../../../test/setup.js";
import { fetchAccrualVaultV2 } from "./VaultV2.js";
import { fetchVaultV2PublicAllocatorData } from "./VaultV2PublicAllocatorConfig.js";

describe("Vault V2 public allocator fetchers on fork", () => {
vaultV2Test(
"default: matches direct reads against the deployless query",
async ({ client }) => {
const forkVault = await fetchAccrualVaultV2(
"0x4C7b69b4a82e9E5D8ec60E96516f7A0E17CBC55C",
client,
);
const forkAdapter = forkVault.accrualAdapters.find(
(candidate) =>
candidate instanceof AccrualVaultV2MorphoMarketV1AdapterV2,
);
assert(forkAdapter instanceof AccrualVaultV2MorphoMarketV1AdapterV2);

const forkMarket = forkAdapter.markets[0];
assert(forkMarket != null);

const deploymentHash = await client.deployContract({
abi: fixtureAbi,
bytecode: fixtureCode,
});
const { contractAddress: fixture } =
await client.waitForTransactionReceipt({ hash: deploymentHash });
assert(fixture != null);
const fixtureBytecode = await client.getBytecode({ address: fixture });
assert(fixtureBytecode != null);
const allocator = getChainAddress(
ChainId.EthMainnet,
"bluePublicAllocator",
);
await client.setCode({ address: allocator, bytecode: fixtureBytecode });

const forkAdapterMarketCapId = forkAdapter.ids(forkMarket.params)[2];
await client.writeContract({
address: allocator,
abi: fixtureAbi,
functionName: "setVaultData",
args: [forkVault.address, true, 12n],
});
await client.writeContract({
address: allocator,
abi: fixtureAbi,
functionName: "setAbsoluteCap",
args: [forkVault.address, forkAdapterMarketCapId, 500n],
});
await client.writeContract({
address: allocator,
abi: fixtureAbi,
functionName: "setCanPullFromMarket",
args: [forkVault.address, forkAdapterMarketCapId, true],
});
await client.writeContract({
address: allocator,
abi: fixtureAbi,
functionName: "setIsActiveAdapter",
args: [forkVault.address, forkAdapter.address, true],
});

const [deployless, direct] = await Promise.all([
fetchVaultV2PublicAllocatorData(forkVault, client, {
deployless: "force",
}),
fetchVaultV2PublicAllocatorData(forkVault, client, {
deployless: false,
}),
]);

expect(deployless).toStrictEqual(direct);
expect(deployless.publicAllocatorConfig).toStrictEqual({
vault: forkVault.address,
canPullFromIdle: true,
penalty: 12n,
});
expect(deployless.activeAdapters).toStrictEqual(
new Set([forkAdapter.address]),
);
expect(
deployless.marketPublicAllocatorConfigs[forkAdapterMarketCapId],
).toStrictEqual({
vault: forkVault.address,
adapter: forkAdapter.address,
adapterMarketCapId: forkAdapterMarketCapId,
absoluteCap: 500n,
canPullFromMarket: true,
});
expect(
Object.values(deployless.allocations).some(
(allocation) =>
allocation != null &&
(allocation.absoluteCap > 0n ||
allocation.relativeCap > 0n ||
allocation.allocation > 0n),
),
).toBe(true);
},
);
});
Loading
Loading