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.
For the contract interface, see the Public Allocator contract.
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
function reallocateTo(
address vault,
Withdrawal[] calldata withdrawals,
MarketParams calldata supplyMarketParams
) external payable;
Parameters
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
// 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
);