Docs

Blue Public Allocator

Vault v2 repository

Introduction

The BluePublicAllocator lets anyone move Vault V2 assets between eligible Morpho Blue markets or allocate idle vault assets to an eligible market. The vault remains the owner of the assets throughout the operation. The caller only triggers the reallocation.

The vault's allocator role configures which adapters and markets can participate, whether idle assets can be used, the destination allocation caps, and the penalty. The penalty can be zero. If it is non-zero, the caller pays it in the vault's asset.

For the liquidity model and integration flow, see the Public Allocator concept page and Public Allocator tutorial.

Allocation IDs and caps

The Public Allocator identifies an adapter and Morpho Blue market pair with this allocation ID:

keccak256(abi.encode("this/marketParams", adapter, marketParams))

setAbsoluteCap stores a Public Allocator cap for this ID. During reallocate and allocateFromIdle, the contract allocates the requested assets and then reads the vault's resulting allocation for the destination ID. The full transaction reverts if that allocation exceeds the configured Public Allocator cap.

Structs

VaultData

struct VaultData {
    bool canPullFromIdle;
    uint64 penalty;
}

The contract stores one VaultData value for each Vault V2 address. Pass the vault address to vaultData(vault) to read the two fields below.

NameTypeDescription
canPullFromIdleboolWhether public calls can allocate the vault's idle assets.
penaltyuint64The WAD-scaled penalty paid by the caller. 0 means no penalty and 1e18 means 100%.

Allocator functions

setIsActiveAdapter

function setIsActiveAdapter(address vault, address adapter, bool newIsActiveAdapter) external

Allows or prevents an adapter from participating in public reallocations for vault.

Callable by: An allocator of vault

Parameters:

NameTypeDescription
vaultaddressThe Vault V2 to configure.
adapteraddressThe MorphoMarketV1AdapterV2 adapter to configure.
newIsActiveAdapterboolWhether the adapter can participate.

setAbsoluteCap

function setAbsoluteCap(
    address vault,
    address adapter,
    MarketParams calldata marketParams,
    uint256 newAbsoluteCap
) external

Sets the maximum resulting vault allocation for an adapter and Morpho Blue market pair. Public allocations to this destination require a non-zero cap. After the allocation, the contract reads the vault's allocation for the destination ID and reverts the full transaction if it exceeds newAbsoluteCap.

Callable by: An allocator of vault

Parameters:

NameTypeDescription
vaultaddressThe Vault V2 to configure.
adapteraddressThe destination MorphoMarketV1AdapterV2 adapter.
marketParamsMarketParamsThe destination Morpho Blue market parameters.
newAbsoluteCapuint256The maximum resulting allocation in vault asset units. Set to 0 to disable public allocations to this destination.

setCanPullFromMarket

function setCanPullFromMarket(
    address vault,
    address adapter,
    MarketParams calldata marketParams,
    bool newCanPullFromMarket
) external

Allows or prevents public reallocations from using an adapter and Morpho Blue market pair as a source.

Callable by: An allocator of vault

Parameters:

NameTypeDescription
vaultaddressThe Vault V2 to configure.
adapteraddressThe source MorphoMarketV1AdapterV2 adapter.
marketParamsMarketParamsThe source Morpho Blue market parameters.
newCanPullFromMarketboolWhether public reallocations can pull assets from this market.

setCanPullFromIdle

function setCanPullFromIdle(address vault, bool newCanPullFromIdle) external

Allows or prevents public calls from allocating assets held idle by the vault.

Callable by: An allocator of vault

Parameters:

NameTypeDescription
vaultaddressThe Vault V2 to configure.
newCanPullFromIdleboolWhether public calls can allocate idle assets.

setPenalty

function setPenalty(address vault, uint64 newPenalty) external

Sets the optional penalty for reallocate and allocateFromIdle. The contract rounds the payment up with MathLib.mulDivUp(assets, newPenalty, 1e18). It transfers a non-zero payment from the caller directly to the vault.

Callable by: An allocator of vault

Parameters:

NameTypeDescription
vaultaddressThe Vault V2 to configure.
newPenaltyuint64The WAD-scaled penalty. Must be at most 1e18. Set to 0 for no penalty.

Public functions

reallocate

function reallocate(
    address vault,
    address deallocateAdapter,
    MarketParams calldata deallocateMarketParams,
    address allocateAdapter,
    MarketParams calldata allocateMarketParams,
    uint128 assets,
    uint64 penalty
) external

Moves assets from one eligible Morpho Blue market to another. The source and destination adapters must be active, and the source market must allow public withdrawals. The destination must have a non-zero Public Allocator cap. The resulting allocation must remain within both the Public Allocator cap and the Vault V2 caps.

The penalty argument must equal the current configured penalty. This check protects the caller from a penalty change between transaction signing and execution. If the configured penalty is non-zero, the caller must approve the BluePublicAllocator to spend the vault asset.

Callable by: Anyone

Parameters:

NameTypeDescription
vaultaddressThe Vault V2 whose assets are reallocated.
deallocateAdapteraddressThe active adapter that supplies the source market.
deallocateMarketParamsMarketParamsThe source Morpho Blue market parameters.
allocateAdapteraddressThe active adapter that supplies the destination market.
allocateMarketParamsMarketParamsThe destination Morpho Blue market parameters.
assetsuint128The amount of vault assets to move.
penaltyuint64The expected WAD-scaled penalty. Must equal the configured value.

allocateFromIdle

function allocateFromIdle(
    address vault,
    address adapter,
    MarketParams calldata marketParams,
    uint128 assets,
    uint64 penalty
) external

Moves assets from the vault's idle balance into an eligible Morpho Blue market. Pulling from idle must be enabled, the destination adapter must be active, and the destination must have a non-zero Public Allocator cap. The resulting allocation must remain within both the Public Allocator cap and the Vault V2 caps.

The penalty argument must equal the current configured penalty. If the configured penalty is non-zero, the caller must approve the BluePublicAllocator to spend the vault asset.

Callable by: Anyone

Parameters:

NameTypeDescription
vaultaddressThe Vault V2 whose idle assets are allocated.
adapteraddressThe active destination MorphoMarketV1AdapterV2 adapter.
marketParamsMarketParamsThe destination Morpho Blue market parameters.
assetsuint128The amount of idle vault assets to allocate.
penaltyuint64The expected WAD-scaled penalty. Must equal the configured value.

Other functions

multicall

function multicall(bytes[] calldata data) external

Executes multiple Public Allocator calls in one transaction with delegatecall. Each call keeps its own authorization and configuration checks. If one call reverts, the full multicall reverts with the same error.

Callable by: Anyone

Parameters:

NameTypeDescription
databytes[]The ABI-encoded Public Allocator calls to execute.

View functions

vaultV2Factory

function vaultV2Factory() external view returns (address)

Returns the Vault V2 factory used to verify vaults in configuration calls.

Return values:

NameTypeDescription
vaultV2FactoryaddressThe Vault V2 factory address.

absoluteCap

function absoluteCap(address vault, bytes32 id) external view returns (uint256)

Returns the Public Allocator cap for a vault allocation ID.

Parameters:

NameTypeDescription
vaultaddressThe Vault V2 to query.
idbytes32The adapter and Morpho Blue market allocation ID.

Return values:

NameTypeDescription
absoluteCapuint256The maximum resulting allocation for public calls.

canPullFromMarket

function canPullFromMarket(address vault, bytes32 id) external view returns (bool)

Returns whether public reallocations can pull assets from a vault allocation ID.

Parameters:

NameTypeDescription
vaultaddressThe Vault V2 to query.
idbytes32The adapter and Morpho Blue market allocation ID.

Return values:

NameTypeDescription
canPullFromMarketboolWhether public reallocations can use the market as a source.

isActiveAdapter

function isActiveAdapter(address vault, address adapter) external view returns (bool)

Returns whether an adapter can participate in public allocations for a vault.

Parameters:

NameTypeDescription
vaultaddressThe Vault V2 to query.
adapteraddressThe adapter to query.

Return values:

NameTypeDescription
isActiveAdapterboolWhether the adapter is active.

vaultData

function vaultData(address vault) external view returns (bool canPullFromIdle, uint64 penalty)

Returns the idle-allocation permission and configured penalty for a vault.

Parameters:

NameTypeDescription
vaultaddressThe Vault V2 to query.

Return values:

NameTypeDescription
canPullFromIdleboolWhether public calls can allocate idle assets.
penaltyuint64The WAD-scaled penalty paid by public callers.

Events

EventDescription
SetAbsoluteCapEmitted when a vault allocator changes a destination cap.
SetCanPullFromMarketEmitted when a vault allocator changes a source-market permission.
SetCanPullFromIdleEmitted when a vault allocator changes the idle-assets permission.
SetIsActiveAdapterEmitted when a vault allocator activates or deactivates an adapter.
SetPenaltyEmitted when a vault allocator changes the penalty.
ReallocateEmitted after assets move between two Morpho Blue markets. Includes the paid penalty assets.
AllocateFromIdleEmitted after idle assets move into a Morpho Blue market. Includes the paid penalty assets.

Errors

ErrorCondition
UnauthorizedThe caller of a configuration function is not an allocator of the vault.
AbsoluteCapExceededThe destination allocation exceeds its Public Allocator cap.
ZeroAbsoluteCapThe destination has no Public Allocator cap.
CannotPullFromMarketThe source market does not allow public withdrawals.
CannotPullFromIdleThe vault does not allow public allocations from idle assets.
InactiveAdapterA source or destination adapter is not active.
PenaltyTooHighThe configured penalty is greater than 1e18.
IncorrectPenaltyThe caller's expected penalty does not equal the configured penalty.
NotVaultV2A configuration call targets an address that the factory does not recognize as a Vault V2.