ERC4626Adapter
Inherits: IStrategy, IProtocolAdapter, IAdapterOperator, IERC4626Adapter
Title: ERC4626Adapter
Author: David Dada <daveproxy80@gmail.com> (https://github.com/dadadave80)
Diamond facet wrapping any ERC4626 vault (Yearn v3 / MetaMorpho) as a Lattice strategy.
Implements IStrategy (funds routing), IProtocolAdapter (sidecar), and
IERC4626Adapter (wrap config). NAV via convertToAssets (no oracle); supply-only
(no leverage). All logic lives in ERC4626AdapterLib.
Notes:
- lattice-version: 0.1.0
- lattice-source: Lattice original
Functions
asset
Returns the address of the underlying asset this strategy manages.
function asset() external view virtual override returns (address);Returns
| Name | Type | Description |
|---|---|---|
| <none> | address |
totalAssetsManaged
Returns the current total asset balance managed by this strategy.
This value is trusted by the StrategyManager and VaultCore for accounting. Strategy implementations MUST report accurate balances to avoid mispricing vault shares.
function totalAssetsManaged() external view virtual override returns (uint256);Returns
| Name | Type | Description |
|---|---|---|
| <none> | uint256 |
withdraw
Withdraws amount of the underlying asset to to.
Called by the StrategyManager during rebalancing to recall excess allocations. The strategy is responsible for executing the ERC-20 transfer.
function withdraw(uint256 amount, address to) external virtual override returns (uint256 withdrawn);Parameters
| Name | Type | Description |
|---|---|---|
| amount | uint256 | Amount of underlying asset to withdraw. |
| to | address | Recipient address (typically the vault). |
Returns
| Name | Type | Description |
|---|---|---|
| withdrawn | uint256 | Actual amount transferred (may be less if strategy has slippage). |
deploy
Sweeps the adapter's idle asset balance into the external protocol.
Required because the vault PUSHES funds via a bare ERC-20 transfer (no callback).
Reverts ProtocolAdapterNothingToDeploy if the idle balance is zero.
function deploy() external virtual override returns (uint256 deployed);Returns
| Name | Type | Description |
|---|---|---|
| deployed | uint256 | The amount swept into the protocol. |
harvest
Claims reward tokens from the protocol and forwards them RAW (no swap) to the configured recipient.
Safe against zero-claim and fee-on-transfer reward tokens; never reverts withdraw.
function harvest() external virtual override;emergencyWithdraw
Fully exits the protocol position and returns all recovered assets to the vault.
Intended for the emergency path; callable by an authorized guardian/admin even when the adapter is paused.
function emergencyWithdraw() external virtual override returns (uint256 recovered);Returns
| Name | Type | Description |
|---|---|---|
| recovered | uint256 | The amount returned to the vault. |
isPaused
Returns true when the adapter is paused or emergency-stopped, or the external
protocol reports the asset paused/frozen. When true, deploy() must be a no-op
path (revert), so a paused protocol cannot brick rebalance().
function isPaused() external view virtual override returns (bool);Returns
| Name | Type | Description |
|---|---|---|
| <none> | bool |
healthFactor
Returns the current health factor (WAD, 1e18 == 1.0) of the adapter's position.
Supply-only adapters return type(uint256).max (no debt). Leverage adapters return
collateralValue * liquidationThreshold / debtValue.
function healthFactor() external view virtual override returns (uint256);Returns
| Name | Type | Description |
|---|---|---|
| <none> | uint256 |
minHealthFactor
Returns the configured minimum health factor (WAD) the adapter must not breach.
function minHealthFactor() external view virtual override returns (uint256);Returns
| Name | Type | Description |
|---|---|---|
| <none> | uint256 |
rewardRecipient
Returns the address rewards are forwarded to.
function rewardRecipient() external view virtual override returns (address);Returns
| Name | Type | Description |
|---|---|---|
| <none> | address |
setOperator
Sets the authorized operator permitted to call deploy/withdraw/harvest.
Admin-gated (DEFAULT_ADMIN_ROLE). Rejects address(0); emits
IProtocolAdapter.OperatorSet.
function setOperator(address operator_) external virtual override;Parameters
| Name | Type | Description |
|---|---|---|
| operator_ | address | The new operator (typically the StrategyManager diamond). |
operator
Returns the authorized operator (zero until wired).
function operator() external view virtual override returns (address);Returns
| Name | Type | Description |
|---|---|---|
| <none> | address |
reentrancyGuardEntered
True while a guarded op is executing — mirrors StrategyManager so VaultCore can reject share-price-sensitive ops mid-deploy/withdraw (read-only reentrancy guard).
function reentrancyGuardEntered() external view virtual returns (bool);Returns
| Name | Type | Description |
|---|---|---|
| <none> | bool |
targetVault
Returns the target ERC4626 vault this adapter deposits into.
function targetVault() external view virtual override returns (address);Returns
| Name | Type | Description |
|---|---|---|
| <none> | address |
vault
Returns the Lattice vault funds are returned to.
function vault() external view virtual override returns (address);Returns
| Name | Type | Description |
|---|---|---|
| <none> | address |
sideRewardToken
Optional side-reward token (address(0) if none). Forwarded raw on harvest().
function sideRewardToken() external view virtual override returns (address);Returns
| Name | Type | Description |
|---|---|---|
| <none> | address |
setSideRewardToken
Sets an optional side-reward token to forward on harvest (admin only). address(0) clears it. Rejects the asset and the target vault's share token.
function setSideRewardToken(address token) external virtual override;Parameters
| Name | Type | Description |
|---|---|---|
| token | address |
setRewardRecipient
Sets the reward recipient (admin only).
function setRewardRecipient(address recipient) external virtual override;Parameters
| Name | Type | Description |
|---|---|---|
| recipient | address |
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 ERC4626Adapter methodIdentifiers (alphabetical by signature); kept in exact parity by
ExportSelectorsParityTest. Chunks:
asset() 0x38d52e0f
deploy() 0x775c300c
emergencyWithdraw() 0xdb2e21bc
harvest() 0x4641257d
healthFactor() 0x22841f01
isPaused() 0xb187bd26
minHealthFactor() 0xe1b4264c
operator() 0x570ca735
reentrancyGuardEntered() 0xd2c725e0
rewardRecipient() 0x17f33340
setOperator(address) 0xb3ab15fb
setRewardRecipient(address) 0xe521136f
setSideRewardToken(address) 0xe5d9f14b
sideRewardToken() 0x8519da85
targetVault() 0x1f92db45
totalAssetsManaged() 0x613c822b
vault() 0xfbfa77cf
withdraw(uint256,address) 0x00f714ce
function exportSelectors() external pure virtual returns (bytes memory selectors);Returns
| Name | Type | Description |
|---|---|---|
| selectors | bytes |