StrategyManager
Inherits: IStrategyManager, IStrategyManagerRecovery
Title: StrategyManager
Author: Modified from Yearn V3 (https://github.com/yearn/yearn-vaults-v3/blob/master/contracts/VaultV3.vy)
Diamond facet managing yield strategy allocations for a single ERC-4626 vault.
All logic lives in StrategyManagerLib. This contract is a pure delegator.
Initialization order in the consumer's Diamond initializer:
- AccessControlLib.__AccessControl_init(admin)
- StrategyManagerLib.__StrategyManager_init()
- (Optional) StrategyManagerLib._setVault(vault)
The StrategyManager must be configured as the vault's strategy manager via
IVaultCore.setStrategyManager(address(this)) before calling rebalance().
allocateToStrategy is guarded by _checkManager() which checks the caller
address, not any role — granting DEFAULT_ADMIN_ROLE is neither necessary nor sufficient.
Each Lattice protocol adapter must name this diamond as its operator (setOperator): rebalance()
recalls through the adapter's withdraw and deploys its idle through deploy, both operator-gated.
A force removal latches the vault's deposits closed until the admin calls clearDepositLatch
(IStrategyManagerRecovery, a separate interface so IStrategyManager's ERC-165 id is unchanged).
Notes:
- lattice-version: 0.1.0
- lattice-source: Yearn V3
Functions
vault
Returns the address of the associated vault.
function vault() external view virtual override returns (address);Returns
| Name | Type | Description |
|---|---|---|
| <none> | address |
getStrategies
Returns the list of all registered strategy addresses.
function getStrategies() external view virtual override returns (address[] memory);Returns
| Name | Type | Description |
|---|---|---|
| <none> | address[] |
getStrategyTarget
Returns the target allocation in basis points for a given strategy.
function getStrategyTarget(address strategy) external view virtual override returns (uint16 targetBps);Parameters
| Name | Type | Description |
|---|---|---|
| strategy | address | Strategy address to query. |
Returns
| Name | Type | Description |
|---|---|---|
| targetBps | uint16 | Basis-point target (0–10 000); 0 if strategy is not registered. |
totalAllocated
Returns the sum of IStrategy.totalAssetsManaged() across all registered strategies.
Trust assumption: strategies are trusted to report accurate balances. Reverts if any strategy's
read reverts or the sum overflows, which makes a VaultCore vault's totalAssets() revert (fail closed).
function totalAllocated() external view virtual override returns (uint256);Returns
| Name | Type | Description |
|---|---|---|
| <none> | uint256 |
totalTargetBps
Returns the current sum of all registered strategy target allocations in basis points.
function totalTargetBps() external view virtual override returns (uint256);Returns
| Name | Type | Description |
|---|---|---|
| <none> | uint256 |
reentrancyGuardEntered
Returns true while a rebalance() is in progress (the reentrancy guard is held).
Consumed by VaultCore to reject share-price-sensitive operations (deposit/mint/ withdraw/redeem) mid-rebalance, defeating read-only reentrancy via a strategy callback. Deliberately NOT part of IStrategyManager, so the interface's ERC-165 id is unchanged.
function reentrancyGuardEntered() external view virtual returns (bool);Returns
| Name | Type | Description |
|---|---|---|
| <none> | bool |
depositsLatched
Returns true while a force removal keeps the vault's deposits closed.
Consumed by VaultCore, which closes deposit/mint and reports maxDeposit/maxMint as 0 while set.
function depositsLatched() external view virtual override returns (bool);Returns
| Name | Type | Description |
|---|---|---|
| <none> | bool |
setVault
Sets the vault address. Admin-only (DEFAULT_ADMIN_ROLE).
function setVault(address _vault) external virtual override;Parameters
| Name | Type | Description |
|---|---|---|
| _vault | address | Address of the ERC-4626 vault this manager serves. |
addStrategy
Registers a new strategy with a target allocation. Admin-only.
Reverts with StrategyManagerStrategyNotEmpty if the strategy already reports a balance, and bubbles
the revert if its totalAssetsManaged() read fails.
function addStrategy(address strategy, uint16 targetBps) external virtual override;Parameters
| Name | Type | Description |
|---|---|---|
| strategy | address | Address of the strategy to register. |
| targetBps | uint16 | Target allocation in basis points (0–10 000). |
removeStrategy
Removes a registered strategy. Admin-only.
Reverts with StrategyManagerStrategyStillAllocated while the strategy reports a balance. A strategy
whose totalAssetsManaged() read fails is force-removed instead, emitting StrategyForceRemoved;
any funds it still holds leave the vault's NAV. The force removal latches the vault's deposits
closed (IStrategyManagerRecovery): exits reopen, capped at idle, while deposit/mint stay closed
until the admin calls clearDepositLatch, so no new depositor shares in funds the strategy returns
in the meantime. Those funds accrue to whoever still holds shares when they return; a holder who
exits while latched is priced on the idle-only NAV and gives up their share of the stranded funds.
The strategy cannot be re-added while it reports a balance.
function removeStrategy(address strategy) external virtual override;Parameters
| Name | Type | Description |
|---|---|---|
| strategy | address | Address of the strategy to remove. |
clearDepositLatch
Clears the deposit latch, reopening the vault's deposits unless the vault's own manager-swap latch
(IVaultCoreRecovery) is also set. Admin-only (DEFAULT_ADMIN_ROLE, the role that gates
removeStrategy).
Clear it once the force-removed strategy's funds are back in the vault or written off: deposits then price on a NAV that no longer moves when those funds return. Reverts with StrategyManagerDepositLatchNotSet if the latch is not set.
function clearDepositLatch() external virtual override;updateStrategyTarget
Updates the target allocation for a registered strategy. Admin-only.
function updateStrategyTarget(address strategy, uint16 newBps) external virtual override;Parameters
| Name | Type | Description |
|---|---|---|
| strategy | address | Address of the registered strategy. |
| newBps | uint16 | New target allocation in basis points. |
harvest
Snapshots the current allocated balance across all strategies and emits Harvested.
Anyone can call; does not move funds. Useful for off-chain indexers.
function harvest() external virtual override;rebalance
Rebalances the vault's asset distribution to match strategy target allocations.
Pushes or recalls assets to/from strategies, then calls deploy() on each strategy that advertises
IProtocolAdapter and holds idle asset. Anyone can call. A recall that loses value beyond a fixed
rounding tolerance reverts with StrategyManagerWithdrawShortfall; an honest partial recall emits
StrategyPartiallyRecalled; a failing deploy emits StrategyDeployFailed. Allocations are capped
at the vault's actual idle balance.
function rebalance() external virtual override;exportSelectors
ERC-8153 selector export: this facet's cuttable selectors, tightly packed (4 bytes each).
Excludes exportSelectors() itself (0x0ef22643) - it is never cut into a diamond. Order matches
forge inspect StrategyManager methodIdentifiers (alphabetical by signature); kept in exact parity by
ExportSelectorsParityTest. Chunks:
addStrategy(address,uint16) 0xd11f519c
clearDepositLatch() 0x2d600e21
depositsLatched() 0xfe32d662
getStrategies() 0xb49a60bb
getStrategyTarget(address) 0x89355a28
harvest() 0x4641257d
rebalance() 0x7d7c2a1c
reentrancyGuardEntered() 0xd2c725e0
removeStrategy(address) 0x175188e8
setVault(address) 0x6817031b
totalAllocated() 0x45f7f249
totalTargetBps() 0x5e02d602
updateStrategyTarget(address,uint16) 0x8420bd02
vault() 0xfbfa77cf
function exportSelectors() external pure virtual returns (bytes memory selectors);Returns
| Name | Type | Description |
|---|---|---|
| selectors | bytes |