> ## Documentation Index
> Fetch the complete documentation index at: https://docs.berachain.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Public Allocator

> Programmatically reallocate vault liquidity between Bend markets; just-in-time liquidity for borrowers.

The Public Allocator reallocates vault liquidity between Bend markets so borrows can succeed even when a market has insufficient supply. You call it to move liquidity from other markets into the target market in one transaction.

You get deep, unified liquidity while keeping Bend's isolated market risk. For concepts and flow, see [Public Allocator](/bend/learn/public-allocator).

<Note>For the contract interface, see the Public Allocator contract.</Note>

<Tip>
  Read [Public Allocator](/bend/learn/public-allocator) for an overview of how it works and curator
  controls.
</Tip>

## Core integration: `reallocateTo`

Call `reallocateTo` to withdraw from one or more source markets in a vault and supply the total to a single destination market in one atomic transaction.

### Function signature

```solidity theme={null}
function reallocateTo(
    address vault,
    Withdrawal[] calldata withdrawals,
    MarketParams calldata supplyMarketParams
) external payable;
```

### Parameters

```solidity theme={null}
struct MarketParams {
    address loanToken;
    address collateralToken;
    address oracle;
    address irm;
    uint256 lltv;
}
```

* **vault**: MetaMorpho vault to withdraw from.
* **withdrawals**: Array of `Withdrawal` (source market + amount). Must be **sorted by market ID ascending**.
  * `Withdrawal`: `marketParams` (MarketParams for source market), `amount` (uint128).
* **supplyMarketParams**: Destination market (single market) that receives the total withdrawn amount.

### Requirements

* **Sorted withdrawals**: `withdrawals` must be ordered by market ID ascending.
* **Fee**: Send the required ETH as `msg.value`. Query the fee with `fee(vaultAddress)` on the Public Allocator.
* **Flow caps**: Withdrawals and supply must not exceed the vault curator's `maxOut` and `maxIn` per market.
* **Enabled markets**: All source and destination markets must be enabled for the vault.
* **No self-supply**: The destination market must not appear in `withdrawals`.

### Example

```solidity theme={null}
// Example assumes IPublicAllocator and IMetaMorpho interfaces are imported and available
IPublicAllocator publicAllocator = IPublicAllocator(PA_ADDRESS);
IMetaMorpho vault = IMetaMorpho(VAULT_ADDRESS);

// Step 1: Confirm allocator is registered and get required fee
require(vault.isAllocator(address(publicAllocator)), "PA: Not an allocator");
uint256 requiredFee = publicAllocator.fee(address(vault));

// Step 2: Build withdrawals array (sorted by market ID ascending)
Withdrawal[] memory withdrawals = new Withdrawal[](2);
withdrawals[0] = Withdrawal({ marketParams: marketAParams, amount: 70 * 1e18 });
withdrawals[1] = Withdrawal({ marketParams: marketBParams, amount: 800 * 1e18 }); // Market B ID > Market A ID

// Step 3: Destination market
MarketParams memory supplyMarketParams = wBERAMarketParams;

// Step 4: Call reallocateTo with fee
publicAllocator.reallocateTo{value: requiredFee}(
    address(vault),
    withdrawals,
    supplyMarketParams
);
```
